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.CellView;
26 
27 private import gdk.Color;
28 private import gdk.RGBA;
29 private import gdkpixbuf.Pixbuf;
30 private import glib.ConstructionException;
31 private import glib.MemorySlice;
32 private import gobject.ObjectG;
33 private import gtk.CellArea;
34 private import gtk.CellAreaContext;
35 private import gtk.CellLayoutIF;
36 private import gtk.CellLayoutT;
37 private import gtk.OrientableIF;
38 private import gtk.OrientableT;
39 private import gtk.Requisition;
40 private import gtk.TreeModelIF;
41 private import gtk.TreePath;
42 private import gtk.Widget;
43 private import gtk.c.functions;
44 public  import gtk.c.types;
45 public  import gtkc.gtktypes;
46 
47 
48 /**
49  * A #GtkCellView displays a single row of a #GtkTreeModel using a #GtkCellArea
50  * and #GtkCellAreaContext. A #GtkCellAreaContext can be provided to the
51  * #GtkCellView at construction time in order to keep the cellview in context
52  * of a group of cell views, this ensures that the renderers displayed will
53  * be properly aligned with eachother (like the aligned cells in the menus
54  * of #GtkComboBox).
55  * 
56  * #GtkCellView is #GtkOrientable in order to decide in which orientation
57  * the underlying #GtkCellAreaContext should be allocated. Taking the #GtkComboBox
58  * menu as an example, cellviews should be oriented horizontally if the menus are
59  * listed top-to-bottom and thus all share the same width but may have separate
60  * individual heights (left-to-right menus should be allocated vertically since
61  * they all share the same height but may have variable widths).
62  * 
63  * # CSS nodes
64  * 
65  * GtkCellView has a single CSS node with name cellview.
66  */
67 public class CellView : Widget, CellLayoutIF, OrientableIF
68 {
69 	/** the main Gtk struct */
70 	protected GtkCellView* gtkCellView;
71 
72 	/** Get the main Gtk struct */
73 	public GtkCellView* getCellViewStruct(bool transferOwnership = false)
74 	{
75 		if (transferOwnership)
76 			ownedRef = false;
77 		return gtkCellView;
78 	}
79 
80 	/** the main Gtk struct as a void* */
81 	protected override void* getStruct()
82 	{
83 		return cast(void*)gtkCellView;
84 	}
85 
86 	protected override void setStruct(GObject* obj)
87 	{
88 		gtkCellView = cast(GtkCellView*)obj;
89 		super.setStruct(obj);
90 	}
91 
92 	/**
93 	 * Sets our main struct and passes it to the parent class.
94 	 */
95 	public this (GtkCellView* gtkCellView, bool ownedRef = false)
96 	{
97 		this.gtkCellView = gtkCellView;
98 		super(cast(GtkWidget*)gtkCellView, ownedRef);
99 	}
100 
101 	// add the CellLayout capabilities
102 	mixin CellLayoutT!(GtkCellView);
103 
104 	// add the Orientable capabilities
105 	mixin OrientableT!(GtkCellView);
106 
107 	/**
108 	 * Creates a new GtkCellView widget, adds a GtkCellRendererText
109 	 * to it, and makes its show text.
110 	 * If markup is true the text can be marked up with the Pango text
111 	 * markup language.
112 	 * Since: 2.6
113 	 * Params:
114 	 *  text = the text to display in the cell view
115 	 * Returns:
116 	 *  A newly created GtkCellView widget.
117 	 * Throws: ConstructionException GTK+ fails to create the object.
118 	 */
119 	public this (string text, bool markup=true)
120 	{
121 		GtkCellView* p;
122 
123 		if ( markup )
124 		{
125 			// GtkWidget* gtk_cell_view_new_with_markup (const gchar *markup);
126 			p = cast(GtkCellView*)gtk_cell_view_new_with_markup(Str.toStringz(text));
127 		}
128 		else
129 		{
130 			// GtkWidget* gtk_cell_view_new_with_text (const gchar *text);
131 			p = cast(GtkCellView*)gtk_cell_view_new_with_text(Str.toStringz(text));
132 		}
133 
134 		if(p is null)
135 		{
136 			throw new ConstructionException("null returned by gtk_cell_view_new_with_");
137 		}
138 
139 		this(p);
140 	}
141 
142 	/**
143 	 */
144 
145 	/** */
146 	public static GType getType()
147 	{
148 		return gtk_cell_view_get_type();
149 	}
150 
151 	/**
152 	 * Creates a new #GtkCellView widget.
153 	 *
154 	 * Returns: A newly created #GtkCellView widget.
155 	 *
156 	 * Since: 2.6
157 	 *
158 	 * Throws: ConstructionException GTK+ fails to create the object.
159 	 */
160 	public this()
161 	{
162 		auto p = gtk_cell_view_new();
163 
164 		if(p is null)
165 		{
166 			throw new ConstructionException("null returned by new");
167 		}
168 
169 		this(cast(GtkCellView*) p);
170 	}
171 
172 	/**
173 	 * Creates a new #GtkCellView widget with a specific #GtkCellArea
174 	 * to layout cells and a specific #GtkCellAreaContext.
175 	 *
176 	 * Specifying the same context for a handfull of cells lets
177 	 * the underlying area synchronize the geometry for those cells,
178 	 * in this way alignments with cellviews for other rows are
179 	 * possible.
180 	 *
181 	 * Params:
182 	 *     area = the #GtkCellArea to layout cells
183 	 *     context = the #GtkCellAreaContext in which to calculate cell geometry
184 	 *
185 	 * Returns: A newly created #GtkCellView widget.
186 	 *
187 	 * Since: 2.6
188 	 *
189 	 * Throws: ConstructionException GTK+ fails to create the object.
190 	 */
191 	public this(CellArea area, CellAreaContext context)
192 	{
193 		auto p = gtk_cell_view_new_with_context((area is null) ? null : area.getCellAreaStruct(), (context is null) ? null : context.getCellAreaContextStruct());
194 
195 		if(p is null)
196 		{
197 			throw new ConstructionException("null returned by new_with_context");
198 		}
199 
200 		this(cast(GtkCellView*) p);
201 	}
202 
203 	/**
204 	 * Creates a new #GtkCellView widget, adds a #GtkCellRendererPixbuf
205 	 * to it, and makes it show @pixbuf.
206 	 *
207 	 * Params:
208 	 *     pixbuf = the image to display in the cell view
209 	 *
210 	 * Returns: A newly created #GtkCellView widget.
211 	 *
212 	 * Since: 2.6
213 	 *
214 	 * Throws: ConstructionException GTK+ fails to create the object.
215 	 */
216 	public this(Pixbuf pixbuf)
217 	{
218 		auto p = gtk_cell_view_new_with_pixbuf((pixbuf is null) ? null : pixbuf.getPixbufStruct());
219 
220 		if(p is null)
221 		{
222 			throw new ConstructionException("null returned by new_with_pixbuf");
223 		}
224 
225 		this(cast(GtkCellView*) p);
226 	}
227 
228 	/**
229 	 * Returns a #GtkTreePath referring to the currently
230 	 * displayed row. If no row is currently displayed,
231 	 * %NULL is returned.
232 	 *
233 	 * Returns: the currently displayed row or %NULL
234 	 *
235 	 * Since: 2.6
236 	 */
237 	public TreePath getDisplayedRow()
238 	{
239 		auto p = gtk_cell_view_get_displayed_row(gtkCellView);
240 
241 		if(p is null)
242 		{
243 			return null;
244 		}
245 
246 		return ObjectG.getDObject!(TreePath)(cast(GtkTreePath*) p, true);
247 	}
248 
249 	/**
250 	 * Gets whether @cell_view is configured to draw all of its
251 	 * cells in a sensitive state.
252 	 *
253 	 * Returns: whether @cell_view draws all of its
254 	 *     cells in a sensitive state
255 	 *
256 	 * Since: 3.0
257 	 */
258 	public bool getDrawSensitive()
259 	{
260 		return gtk_cell_view_get_draw_sensitive(gtkCellView) != 0;
261 	}
262 
263 	/**
264 	 * Gets whether @cell_view is configured to request space
265 	 * to fit the entire #GtkTreeModel.
266 	 *
267 	 * Returns: whether @cell_view requests space to fit
268 	 *     the entire #GtkTreeModel.
269 	 *
270 	 * Since: 3.0
271 	 */
272 	public bool getFitModel()
273 	{
274 		return gtk_cell_view_get_fit_model(gtkCellView) != 0;
275 	}
276 
277 	/**
278 	 * Returns the model for @cell_view. If no model is used %NULL is
279 	 * returned.
280 	 *
281 	 * Returns: a #GtkTreeModel used or %NULL
282 	 *
283 	 * Since: 2.16
284 	 */
285 	public TreeModelIF getModel()
286 	{
287 		auto p = gtk_cell_view_get_model(gtkCellView);
288 
289 		if(p is null)
290 		{
291 			return null;
292 		}
293 
294 		return ObjectG.getDObject!(TreeModelIF)(cast(GtkTreeModel*) p);
295 	}
296 
297 	/**
298 	 * Sets @requisition to the size needed by @cell_view to display
299 	 * the model row pointed to by @path.
300 	 *
301 	 * Deprecated: Combo box formerly used this to calculate the
302 	 * sizes for cellviews, now you can achieve this by either using
303 	 * the #GtkCellView:fit-model property or by setting the currently
304 	 * displayed row of the #GtkCellView and using gtk_widget_get_preferred_size().
305 	 *
306 	 * Params:
307 	 *     path = a #GtkTreePath
308 	 *     requisition = return location for the size
309 	 *
310 	 * Returns: %TRUE
311 	 *
312 	 * Since: 2.6
313 	 */
314 	public bool getSizeOfRow(TreePath path, out Requisition requisition)
315 	{
316 		GtkRequisition* outrequisition = sliceNew!GtkRequisition();
317 
318 		auto p = gtk_cell_view_get_size_of_row(gtkCellView, (path is null) ? null : path.getTreePathStruct(), outrequisition) != 0;
319 
320 		requisition = ObjectG.getDObject!(Requisition)(outrequisition, true);
321 
322 		return p;
323 	}
324 
325 	/**
326 	 * Sets the background color of @view.
327 	 *
328 	 * Deprecated: Use gtk_cell_view_set_background_rgba() instead.
329 	 *
330 	 * Params:
331 	 *     color = the new background color
332 	 *
333 	 * Since: 2.6
334 	 */
335 	public void setBackgroundColor(Color color)
336 	{
337 		gtk_cell_view_set_background_color(gtkCellView, (color is null) ? null : color.getColorStruct());
338 	}
339 
340 	/**
341 	 * Sets the background color of @cell_view.
342 	 *
343 	 * Params:
344 	 *     rgba = the new background color
345 	 *
346 	 * Since: 3.0
347 	 */
348 	public void setBackgroundRgba(RGBA rgba)
349 	{
350 		gtk_cell_view_set_background_rgba(gtkCellView, (rgba is null) ? null : rgba.getRGBAStruct());
351 	}
352 
353 	/**
354 	 * Sets the row of the model that is currently displayed
355 	 * by the #GtkCellView. If the path is unset, then the
356 	 * contents of the cellview “stick” at their last value;
357 	 * this is not normally a desired result, but may be
358 	 * a needed intermediate state if say, the model for
359 	 * the #GtkCellView becomes temporarily empty.
360 	 *
361 	 * Params:
362 	 *     path = a #GtkTreePath or %NULL to unset.
363 	 *
364 	 * Since: 2.6
365 	 */
366 	public void setDisplayedRow(TreePath path)
367 	{
368 		gtk_cell_view_set_displayed_row(gtkCellView, (path is null) ? null : path.getTreePathStruct());
369 	}
370 
371 	/**
372 	 * Sets whether @cell_view should draw all of its
373 	 * cells in a sensitive state, this is used by #GtkComboBox menus
374 	 * to ensure that rows with insensitive cells that contain
375 	 * children appear sensitive in the parent menu item.
376 	 *
377 	 * Params:
378 	 *     drawSensitive = whether to draw all cells in a sensitive state.
379 	 *
380 	 * Since: 3.0
381 	 */
382 	public void setDrawSensitive(bool drawSensitive)
383 	{
384 		gtk_cell_view_set_draw_sensitive(gtkCellView, drawSensitive);
385 	}
386 
387 	/**
388 	 * Sets whether @cell_view should request space to fit the entire #GtkTreeModel.
389 	 *
390 	 * This is used by #GtkComboBox to ensure that the cell view displayed on
391 	 * the combo box’s button always gets enough space and does not resize
392 	 * when selection changes.
393 	 *
394 	 * Params:
395 	 *     fitModel = whether @cell_view should request space for the whole model.
396 	 *
397 	 * Since: 3.0
398 	 */
399 	public void setFitModel(bool fitModel)
400 	{
401 		gtk_cell_view_set_fit_model(gtkCellView, fitModel);
402 	}
403 
404 	/**
405 	 * Sets the model for @cell_view.  If @cell_view already has a model
406 	 * set, it will remove it before setting the new model.  If @model is
407 	 * %NULL, then it will unset the old model.
408 	 *
409 	 * Params:
410 	 *     model = a #GtkTreeModel
411 	 *
412 	 * Since: 2.6
413 	 */
414 	public void setModel(TreeModelIF model)
415 	{
416 		gtk_cell_view_set_model(gtkCellView, (model is null) ? null : model.getTreeModelStruct());
417 	}
418 }