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