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