1 /*
2  * This file is part of d-handy.
3  *
4  * d-handy 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  * d-handy 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 d-handy; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA
18  */
19 module handy.ComboRow;
20 
21 private import gio.ListModelIF;
22 private import glib.ConstructionException;
23 private import gobject.ObjectG;
24 private import gtk.Widget;
25 private import handy.ActionRow;
26 private import handy.c.functions;
27 public  import handy.c.types;
28 
29 
30 /** */
31 public class ComboRow : ActionRow
32 {
33 	/** the main Gtk struct */
34 	protected HdyComboRow* hdyComboRow;
35 
36 	/** Get the main Gtk struct */
37 	public HdyComboRow* getComboRowStruct(bool transferOwnership = false)
38 	{
39 		if (transferOwnership)
40 			ownedRef = false;
41 		return hdyComboRow;
42 	}
43 
44 	/** the main Gtk struct as a void* */
45 	protected override void* getStruct()
46 	{
47 		return cast(void*)hdyComboRow;
48 	}
49 
50 	/**
51 	 * Sets our main struct and passes it to the parent class.
52 	 */
53 	public this (HdyComboRow* hdyComboRow, bool ownedRef = false)
54 	{
55 		this.hdyComboRow = hdyComboRow;
56 		super(cast(HdyActionRow*)hdyComboRow, ownedRef);
57 	}
58 
59 
60 	/** */
61 	public static GType getType()
62 	{
63 		return hdy_combo_row_get_type();
64 	}
65 
66 	/**
67 	 * Creates a new #HdyComboRow.
68 	 *
69 	 * Returns: a new #HdyComboRow
70 	 *
71 	 * Since: 0.0.6
72 	 *
73 	 * Throws: ConstructionException GTK+ fails to create the object.
74 	 */
75 	public this()
76 	{
77 		auto __p = hdy_combo_row_new();
78 
79 		if(__p is null)
80 		{
81 			throw new ConstructionException("null returned by new");
82 		}
83 
84 		this(cast(HdyComboRow*) __p);
85 	}
86 
87 	/**
88 	 * Binds @model to @self.
89 	 *
90 	 * If @self was already bound to a model, that previous binding is destroyed.
91 	 *
92 	 * The contents of @self are cleared and then filled with widgets that represent
93 	 * items from @model. @self is updated whenever @model changes. If @model is
94 	 * %NULL, @self is left empty.
95 	 *
96 	 * Params:
97 	 *     model = the #GListModel to be bound to @self
98 	 *     createListWidgetFunc = a function that creates
99 	 *         widgets for items to display in the list, or %NULL in case you also passed
100 	 *         %NULL as @model
101 	 *     createCurrentWidgetFunc = a function that creates
102 	 *         widgets for items to display as the selected item, or %NULL in case you
103 	 *         also passed %NULL as @model
104 	 *     userData = user data passed to @create_list_widget_func and
105 	 *         @create_current_widget_func
106 	 *     userDataFreeFunc = function for freeing @user_data
107 	 *
108 	 * Since: 0.0.6
109 	 */
110 	public void bindModel(ListModelIF model, GtkListBoxCreateWidgetFunc createListWidgetFunc, GtkListBoxCreateWidgetFunc createCurrentWidgetFunc, void* userData, GDestroyNotify userDataFreeFunc)
111 	{
112 		hdy_combo_row_bind_model(hdyComboRow, (model is null) ? null : model.getListModelStruct(), createListWidgetFunc, createCurrentWidgetFunc, userData, userDataFreeFunc);
113 	}
114 
115 	/**
116 	 * Binds @model to @self.
117 	 *
118 	 * If @self was already bound to a model, that previous binding is destroyed.
119 	 *
120 	 * The contents of @self are cleared and then filled with widgets that represent
121 	 * items from @model. @self is updated whenever @model changes. If @model is
122 	 * %NULL, @self is left empty.
123 	 *
124 	 * This is more convenient to use than hdy_combo_row_bind_model() if you want to
125 	 * represent items of the model with names.
126 	 *
127 	 * Params:
128 	 *     model = the #GListModel to be bound to @self
129 	 *     getNameFunc = a function that creates names for items, or %NULL
130 	 *         in case you also passed %NULL as @model
131 	 *     userData = user data passed to @get_name_func
132 	 *     userDataFreeFunc = function for freeing @user_data
133 	 *
134 	 * Since: 0.0.6
135 	 */
136 	public void bindNameModel(ListModelIF model, HdyComboRowGetNameFunc getNameFunc, void* userData, GDestroyNotify userDataFreeFunc)
137 	{
138 		hdy_combo_row_bind_name_model(hdyComboRow, (model is null) ? null : model.getListModelStruct(), getNameFunc, userData, userDataFreeFunc);
139 	}
140 
141 	/**
142 	 * Gets the model bound to @self, or %NULL if none is bound.
143 	 *
144 	 * Returns: the #GListModel bound to @self or %NULL
145 	 *
146 	 * Since: 0.0.6
147 	 */
148 	public ListModelIF getModel()
149 	{
150 		auto __p = hdy_combo_row_get_model(hdyComboRow);
151 
152 		if(__p is null)
153 		{
154 			return null;
155 		}
156 
157 		return ObjectG.getDObject!(ListModelIF)(cast(GListModel*) __p);
158 	}
159 
160 	/**
161 	 * Gets the index of the selected item in its #GListModel.
162 	 *
163 	 * Returns: the index of the selected item, or -1 if no item is selected
164 	 *
165 	 * Since: 0.0.7
166 	 */
167 	public int getSelectedIndex()
168 	{
169 		return hdy_combo_row_get_selected_index(hdyComboRow);
170 	}
171 
172 	/**
173 	 * Gets whether the current value of @self should be displayed as its subtitle.
174 	 *
175 	 * Returns: whether the current value of @self should be displayed as its subtitle
176 	 *
177 	 * Since: 0.0.10
178 	 */
179 	public bool getUseSubtitle()
180 	{
181 		return hdy_combo_row_get_use_subtitle(hdyComboRow) != 0;
182 	}
183 
184 	/**
185 	 * Creates a model for @enum_type and binds it to @self. The items of the model
186 	 * will be #HdyEnumValueObject objects.
187 	 *
188 	 * If @self was already bound to a model, that previous binding is destroyed.
189 	 *
190 	 * The contents of @self are cleared and then filled with widgets that represent
191 	 * items from @model. @self is updated whenever @model changes. If @model is
192 	 * %NULL, @self is left empty.
193 	 *
194 	 * This is more convenient to use than hdy_combo_row_bind_name_model() if you
195 	 * want to represent values of an enumeration with names.
196 	 *
197 	 * See hdy_enum_value_row_name().
198 	 *
199 	 * Params:
200 	 *     enumType = the enumeration #GType to be bound to @self
201 	 *     getNameFunc = a function that creates names for items, or %NULL
202 	 *         in case you also passed %NULL as @model
203 	 *     userData = user data passed to @get_name_func
204 	 *     userDataFreeFunc = function for freeing @user_data
205 	 *
206 	 * Since: 0.0.6
207 	 */
208 	public void setForEnum(GType enumType, HdyComboRowGetEnumValueNameFunc getNameFunc, void* userData, GDestroyNotify userDataFreeFunc)
209 	{
210 		hdy_combo_row_set_for_enum(hdyComboRow, enumType, getNameFunc, userData, userDataFreeFunc);
211 	}
212 
213 	/**
214 	 * Sets a closure to convert items into names. See HdyComboRow:use-subtitle.
215 	 *
216 	 * Params:
217 	 *     getNameFunc = a function that creates names for items, or %NULL
218 	 *         in case you also passed %NULL as @model
219 	 *     userData = user data passed to @get_name_func
220 	 *     userDataFreeFunc = function for freeing @user_data
221 	 *
222 	 * Since: 0.0.10
223 	 */
224 	public void setGetNameFunc(HdyComboRowGetNameFunc getNameFunc, void* userData, GDestroyNotify userDataFreeFunc)
225 	{
226 		hdy_combo_row_set_get_name_func(hdyComboRow, getNameFunc, userData, userDataFreeFunc);
227 	}
228 
229 	/**
230 	 * Sets the index of the selected item in its #GListModel.
231 	 *
232 	 * Params:
233 	 *     selectedIndex = the index of the selected item
234 	 *
235 	 * Since: 0.0.7
236 	 */
237 	public void setSelectedIndex(int selectedIndex)
238 	{
239 		hdy_combo_row_set_selected_index(hdyComboRow, selectedIndex);
240 	}
241 
242 	/**
243 	 * Sets whether the current value of @self should be displayed as its subtitle.
244 	 *
245 	 * If %TRUE, you should not access HdyActionRow:subtitle.
246 	 *
247 	 * Params:
248 	 *     useSubtitle = %TRUE to set the current value as the subtitle
249 	 *
250 	 * Since: 0.0.10
251 	 */
252 	public void setUseSubtitle(bool useSubtitle)
253 	{
254 		hdy_combo_row_set_use_subtitle(hdyComboRow, useSubtitle);
255 	}
256 }