1 //
2 // ComboBoxWidget.cs
3 //
4 // Author:
5 //       Olivier Dufour <olivier.duff@gmail.com>
6 //
7 // Copyright (c) 2010 Olivier Dufour
8 //
9 // Permission is hereby granted, free of charge, to any person obtaining a copy
10 // of this software and associated documentation files (the "Software"), to deal
11 // in the Software without restriction, including without limitation the rights
12 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 // copies of the Software, and to permit persons to whom the Software is
14 // furnished to do so, subject to the following conditions:
15 //
16 // The above copyright notice and this permission notice shall be included in
17 // all copies or substantial portions of the Software.
18 //
19 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25 // THE SOFTWARE.
26 
27 using System;
28 using Gtk;
29 
30 namespace Pinta.Gui.Widgets
31 {
32 	[System.ComponentModel.ToolboxItem(true)]
33 	public class ComboBoxWidget : FilledAreaBin
34 	{
35         private Label label;
36         private ComboBox combobox;
37 
38         public string Label {
39 			get { return label.Text; }
40 			set { label.Text = value; }
41 		}
42 
43 		public int Active {
44 			get { return combobox.Active; }
45 			set { combobox.Active = value; }
46 		}
47 
48 		public string ActiveText {
49 			get { return combobox.ActiveText; }
50 		}
51 
ComboBoxWidget(string[] entries)52 		public ComboBoxWidget (string[] entries)
53 		{
54 			this.Build ();
55 			foreach (string s in entries)
56 				combobox.AppendText (s);
57 
58 			combobox.Changed += delegate {
59 				OnChanged ();
60 			};
61 		}
62 
63 		#region Protected Methods
OnChanged()64 		protected void OnChanged ()
65 		{
66 			if (Changed != null)
67 				Changed (this, EventArgs.Empty);
68 		}
69 		#endregion
70 
71 		#region Public Events
72 		public event EventHandler Changed;
73 		#endregion
74 
Build()75         private void Build ()
76         {
77             // Section label + line
78             var hbox1 = new HBox (false, 6);
79 
80             label = new Label ();
81             hbox1.PackStart (label, false, false, 0);
82             hbox1.PackStart (new HSeparator (), true, true, 0);
83 
84             // Combobox
85             combobox = ComboBox.NewText ();
86 
87             // Main layout
88             var vbox = new VBox (false, 6);
89 
90             vbox.Add (hbox1);
91             vbox.Add (combobox);
92 
93             Add (vbox);
94 
95             vbox.ShowAll ();
96         }
97     }
98 }
99