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