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 public  import gtkc.gdktypes;
35 private import gtkc.gtk;
36 public  import gtkc.gtktypes;
37 private import std.algorithm;
38 
39 
40 /**
41  * #GtkCellRendererCombo renders text in a cell like #GtkCellRendererText from
42  * which it is derived. But while #GtkCellRendererText offers a simple entry to
43  * edit the text, #GtkCellRendererCombo offers a #GtkComboBox
44  * widget to edit the text. The values to display in the combo box are taken from
45  * the tree model specified in the #GtkCellRendererCombo:model property.
46  * 
47  * The combo cell renderer takes care of adding a text cell renderer to the combo
48  * box and sets it to display the column specified by its
49  * #GtkCellRendererCombo:text-column property. Further properties of the combo box
50  * can be set in a handler for the #GtkCellRenderer::editing-started signal.
51  * 
52  * The #GtkCellRendererCombo cell renderer was added in GTK+ 2.6.
53  */
54 public class CellRendererCombo : CellRendererText
55 {
56 	/** the main Gtk struct */
57 	protected GtkCellRendererCombo* gtkCellRendererCombo;
58 
59 	/** Get the main Gtk struct */
60 	public GtkCellRendererCombo* getCellRendererComboStruct()
61 	{
62 		return gtkCellRendererCombo;
63 	}
64 
65 	/** the main Gtk struct as a void* */
66 	protected override void* getStruct()
67 	{
68 		return cast(void*)gtkCellRendererCombo;
69 	}
70 
71 	protected override void setStruct(GObject* obj)
72 	{
73 		gtkCellRendererCombo = cast(GtkCellRendererCombo*)obj;
74 		super.setStruct(obj);
75 	}
76 
77 	/**
78 	 * Sets our main struct and passes it to the parent class.
79 	 */
80 	public this (GtkCellRendererCombo* gtkCellRendererCombo, bool ownedRef = false)
81 	{
82 		this.gtkCellRendererCombo = gtkCellRendererCombo;
83 		super(cast(GtkCellRendererText*)gtkCellRendererCombo, ownedRef);
84 	}
85 
86 
87 	/** */
88 	public static GType getType()
89 	{
90 		return gtk_cell_renderer_combo_get_type();
91 	}
92 
93 	/**
94 	 * Creates a new #GtkCellRendererCombo.
95 	 * Adjust how text is drawn using object properties.
96 	 * Object properties can be set globally (with g_object_set()).
97 	 * Also, with #GtkTreeViewColumn, you can bind a property to a value
98 	 * in a #GtkTreeModel. For example, you can bind the “text” property
99 	 * on the cell renderer to a string value in the model, thus rendering
100 	 * a different string in each row of the #GtkTreeView.
101 	 *
102 	 * Return: the new cell renderer
103 	 *
104 	 * Since: 2.6
105 	 *
106 	 * Throws: ConstructionException GTK+ fails to create the object.
107 	 */
108 	public this()
109 	{
110 		auto p = gtk_cell_renderer_combo_new();
111 		
112 		if(p is null)
113 		{
114 			throw new ConstructionException("null returned by new");
115 		}
116 		
117 		this(cast(GtkCellRendererCombo*) p);
118 	}
119 
120 	protected class OnChangedDelegateWrapper
121 	{
122 		void delegate(string, TreeIter, CellRendererCombo) dlg;
123 		gulong handlerId;
124 		ConnectFlags flags;
125 		this(void delegate(string, TreeIter, CellRendererCombo) dlg, gulong handlerId, ConnectFlags flags)
126 		{
127 			this.dlg = dlg;
128 			this.handlerId = handlerId;
129 			this.flags = flags;
130 		}
131 	}
132 	protected OnChangedDelegateWrapper[] onChangedListeners;
133 
134 	/**
135 	 * This signal is emitted each time after the user selected an item in
136 	 * the combo box, either by using the mouse or the arrow keys.  Contrary
137 	 * to GtkComboBox, GtkCellRendererCombo::changed is not emitted for
138 	 * changes made to a selected item in the entry.  The argument @new_iter
139 	 * corresponds to the newly selected item in the combo box and it is relative
140 	 * to the GtkTreeModel set via the model property on GtkCellRendererCombo.
141 	 *
142 	 * Note that as soon as you change the model displayed in the tree view,
143 	 * the tree view will immediately cease the editing operating.  This
144 	 * means that you most probably want to refrain from changing the model
145 	 * until the combo cell renderer emits the edited or editing_canceled signal.
146 	 *
147 	 * Params:
148 	 *     pathString = a string of the path identifying the edited cell
149 	 *         (relative to the tree view model)
150 	 *     newIter = the new iter selected in the combo box
151 	 *         (relative to the combo box model)
152 	 *
153 	 * Since: 2.14
154 	 */
155 	gulong addOnChanged(void delegate(string, TreeIter, CellRendererCombo) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
156 	{
157 		onChangedListeners ~= new OnChangedDelegateWrapper(dlg, 0, connectFlags);
158 		onChangedListeners[onChangedListeners.length - 1].handlerId = Signals.connectData(
159 			this,
160 			"changed",
161 			cast(GCallback)&callBackChanged,
162 			cast(void*)onChangedListeners[onChangedListeners.length - 1],
163 			cast(GClosureNotify)&callBackChangedDestroy,
164 			connectFlags);
165 		return onChangedListeners[onChangedListeners.length - 1].handlerId;
166 	}
167 	
168 	extern(C) static void callBackChanged(GtkCellRendererCombo* cellrenderercomboStruct, char* pathString, GtkTreeIter* newIter,OnChangedDelegateWrapper wrapper)
169 	{
170 		wrapper.dlg(Str.toString(pathString), ObjectG.getDObject!(TreeIter)(newIter), wrapper.outer);
171 	}
172 	
173 	extern(C) static void callBackChangedDestroy(OnChangedDelegateWrapper wrapper, GClosure* closure)
174 	{
175 		wrapper.outer.internalRemoveOnChanged(wrapper);
176 	}
177 
178 	protected void internalRemoveOnChanged(OnChangedDelegateWrapper source)
179 	{
180 		foreach(index, wrapper; onChangedListeners)
181 		{
182 			if (wrapper.dlg == source.dlg && wrapper.flags == source.flags && wrapper.handlerId == source.handlerId)
183 			{
184 				onChangedListeners[index] = null;
185 				onChangedListeners = std.algorithm.remove(onChangedListeners, index);
186 				break;
187 			}
188 		}
189 	}
190 	
191 }