1 /*
2  * This file is part of gtkD.
3  *
4  * gtkD is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU Lesser General Public License
6  * as published by the Free Software Foundation; either version 3
7  * of the License, or (at your option) any later version, with
8  * some exceptions, please read the COPYING file.
9  *
10  * gtkD is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public License
16  * along with gtkD; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA
18  */
19 
20 // generated automatically - do not change
21 // find conversion definition on APILookup.txt
22 // implement new conversion functionalities on the wrap.utils pakage
23 
24 
25 module gtk.CellRendererCombo;
26 
27 private import glib.ConstructionException;
28 private import glib.Str;
29 private import gobject.ObjectG;
30 private import gobject.Signals;
31 private import gtk.CellRenderer;
32 private import gtk.CellRendererText;
33 private import gtk.TreeIter;
34 private import gtkc.gtk;
35 public  import gtkc.gtktypes;
36 private import std.algorithm;
37 
38 
39 /**
40  * #GtkCellRendererCombo renders text in a cell like #GtkCellRendererText from
41  * which it is derived. But while #GtkCellRendererText offers a simple entry to
42  * edit the text, #GtkCellRendererCombo offers a #GtkComboBox
43  * widget to edit the text. The values to display in the combo box are taken from
44  * the tree model specified in the #GtkCellRendererCombo:model property.
45  * 
46  * The combo cell renderer takes care of adding a text cell renderer to the combo
47  * box and sets it to display the column specified by its
48  * #GtkCellRendererCombo:text-column property. Further properties of the combo box
49  * can be set in a handler for the #GtkCellRenderer::editing-started signal.
50  * 
51  * The #GtkCellRendererCombo cell renderer was added in GTK+ 2.6.
52  */
53 public class CellRendererCombo : CellRendererText
54 {
55 	/** the main Gtk struct */
56 	protected GtkCellRendererCombo* gtkCellRendererCombo;
57 
58 	/** Get the main Gtk struct */
59 	public GtkCellRendererCombo* getCellRendererComboStruct()
60 	{
61 		return gtkCellRendererCombo;
62 	}
63 
64 	/** the main Gtk struct as a void* */
65 	protected override void* getStruct()
66 	{
67 		return cast(void*)gtkCellRendererCombo;
68 	}
69 
70 	protected override void setStruct(GObject* obj)
71 	{
72 		gtkCellRendererCombo = cast(GtkCellRendererCombo*)obj;
73 		super.setStruct(obj);
74 	}
75 
76 	/**
77 	 * Sets our main struct and passes it to the parent class.
78 	 */
79 	public this (GtkCellRendererCombo* gtkCellRendererCombo, bool ownedRef = false)
80 	{
81 		this.gtkCellRendererCombo = gtkCellRendererCombo;
82 		super(cast(GtkCellRendererText*)gtkCellRendererCombo, ownedRef);
83 	}
84 
85 
86 	/** */
87 	public static GType getType()
88 	{
89 		return gtk_cell_renderer_combo_get_type();
90 	}
91 
92 	/**
93 	 * Creates a new #GtkCellRendererCombo.
94 	 * Adjust how text is drawn using object properties.
95 	 * Object properties can be set globally (with g_object_set()).
96 	 * Also, with #GtkTreeViewColumn, you can bind a property to a value
97 	 * in a #GtkTreeModel. For example, you can bind the “text” property
98 	 * on the cell renderer to a string value in the model, thus rendering
99 	 * a different string in each row of the #GtkTreeView.
100 	 *
101 	 * Returns: the new cell renderer
102 	 *
103 	 * Since: 2.6
104 	 *
105 	 * Throws: ConstructionException GTK+ fails to create the object.
106 	 */
107 	public this()
108 	{
109 		auto p = gtk_cell_renderer_combo_new();
110 		
111 		if(p is null)
112 		{
113 			throw new ConstructionException("null returned by new");
114 		}
115 		
116 		this(cast(GtkCellRendererCombo*) p);
117 	}
118 
119 	protected class OnChangedDelegateWrapper
120 	{
121 		static OnChangedDelegateWrapper[] listeners;
122 		void delegate(string, TreeIter, CellRendererCombo) dlg;
123 		gulong handlerId;
124 		
125 		this(void delegate(string, TreeIter, CellRendererCombo) dlg)
126 		{
127 			this.dlg = dlg;
128 			this.listeners ~= this;
129 		}
130 		
131 		void remove(OnChangedDelegateWrapper source)
132 		{
133 			foreach(index, wrapper; listeners)
134 			{
135 				if (wrapper.handlerId == source.handlerId)
136 				{
137 					listeners[index] = null;
138 					listeners = std.algorithm.remove(listeners, index);
139 					break;
140 				}
141 			}
142 		}
143 	}
144 
145 	/**
146 	 * This signal is emitted each time after the user selected an item in
147 	 * the combo box, either by using the mouse or the arrow keys.  Contrary
148 	 * to GtkComboBox, GtkCellRendererCombo::changed is not emitted for
149 	 * changes made to a selected item in the entry.  The argument @new_iter
150 	 * corresponds to the newly selected item in the combo box and it is relative
151 	 * to the GtkTreeModel set via the model property on GtkCellRendererCombo.
152 	 *
153 	 * Note that as soon as you change the model displayed in the tree view,
154 	 * the tree view will immediately cease the editing operating.  This
155 	 * means that you most probably want to refrain from changing the model
156 	 * until the combo cell renderer emits the edited or editing_canceled signal.
157 	 *
158 	 * Params:
159 	 *     pathString = a string of the path identifying the edited cell
160 	 *         (relative to the tree view model)
161 	 *     newIter = the new iter selected in the combo box
162 	 *         (relative to the combo box model)
163 	 *
164 	 * Since: 2.14
165 	 */
166 	gulong addOnChanged(void delegate(string, TreeIter, CellRendererCombo) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
167 	{
168 		auto wrapper = new OnChangedDelegateWrapper(dlg);
169 		wrapper.handlerId = Signals.connectData(
170 			this,
171 			"changed",
172 			cast(GCallback)&callBackChanged,
173 			cast(void*)wrapper,
174 			cast(GClosureNotify)&callBackChangedDestroy,
175 			connectFlags);
176 		return wrapper.handlerId;
177 	}
178 	
179 	extern(C) static void callBackChanged(GtkCellRendererCombo* cellrenderercomboStruct, char* pathString, GtkTreeIter* newIter, OnChangedDelegateWrapper wrapper)
180 	{
181 		wrapper.dlg(Str.toString(pathString), ObjectG.getDObject!(TreeIter)(newIter), wrapper.outer);
182 	}
183 	
184 	extern(C) static void callBackChangedDestroy(OnChangedDelegateWrapper wrapper, GClosure* closure)
185 	{
186 		wrapper.remove(wrapper);
187 	}
188 }