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.CellRenderer;
26 
27 private import cairo.Context;
28 private import gdk.Event;
29 private import glib.MemorySlice;
30 private import glib.Str;
31 private import gobject.ObjectG;
32 private import gobject.Signals;
33 private import gtk.CellEditableIF;
34 private import gtk.Requisition;
35 private import gtk.Widget;
36 private import gtk.c.functions;
37 public  import gtk.c.types;
38 public  import gtkc.gtktypes;
39 private import std.algorithm;
40 
41 
42 /**
43  * The #GtkCellRenderer is a base class of a set of objects used for
44  * rendering a cell to a #cairo_t.  These objects are used primarily by
45  * the #GtkTreeView widget, though they aren’t tied to them in any
46  * specific way.  It is worth noting that #GtkCellRenderer is not a
47  * #GtkWidget and cannot be treated as such.
48  * 
49  * The primary use of a #GtkCellRenderer is for drawing a certain graphical
50  * elements on a #cairo_t. Typically, one cell renderer is used to
51  * draw many cells on the screen.  To this extent, it isn’t expected that a
52  * CellRenderer keep any permanent state around.  Instead, any state is set
53  * just prior to use using #GObjects property system.  Then, the
54  * cell is measured using gtk_cell_renderer_get_size(). Finally, the cell
55  * is rendered in the correct location using gtk_cell_renderer_render().
56  * 
57  * There are a number of rules that must be followed when writing a new
58  * #GtkCellRenderer.  First and foremost, it’s important that a certain set
59  * of properties will always yield a cell renderer of the same size,
60  * barring a #GtkStyle change.  The #GtkCellRenderer also has a number of
61  * generic properties that are expected to be honored by all children.
62  * 
63  * Beyond merely rendering a cell, cell renderers can optionally
64  * provide active user interface elements. A cell renderer can be
65  * “activatable” like #GtkCellRendererToggle,
66  * which toggles when it gets activated by a mouse click, or it can be
67  * “editable” like #GtkCellRendererText, which
68  * allows the user to edit the text using a #GtkEntry.
69  * To make a cell renderer activatable or editable, you have to
70  * implement the #GtkCellRendererClass.activate or
71  * #GtkCellRendererClass.start_editing virtual functions, respectively.
72  * 
73  * Many properties of #GtkCellRenderer and its subclasses have a
74  * corresponding “set” property, e.g. “cell-background-set” corresponds
75  * to “cell-background”. These “set” properties reflect whether a property
76  * has been set or not. You should not set them independently.
77  */
78 public class CellRenderer : ObjectG
79 {
80 	/** the main Gtk struct */
81 	protected GtkCellRenderer* gtkCellRenderer;
82 
83 	/** Get the main Gtk struct */
84 	public GtkCellRenderer* getCellRendererStruct(bool transferOwnership = false)
85 	{
86 		if (transferOwnership)
87 			ownedRef = false;
88 		return gtkCellRenderer;
89 	}
90 
91 	/** the main Gtk struct as a void* */
92 	protected override void* getStruct()
93 	{
94 		return cast(void*)gtkCellRenderer;
95 	}
96 
97 	/**
98 	 * Sets our main struct and passes it to the parent class.
99 	 */
100 	public this (GtkCellRenderer* gtkCellRenderer, bool ownedRef = false)
101 	{
102 		this.gtkCellRenderer = gtkCellRenderer;
103 		super(cast(GObject*)gtkCellRenderer, ownedRef);
104 	}
105 
106 
107 	/** */
108 	public static GType getType()
109 	{
110 		return gtk_cell_renderer_get_type();
111 	}
112 
113 	/**
114 	 * Passes an activate event to the cell renderer for possible processing.
115 	 * Some cell renderers may use events; for example, #GtkCellRendererToggle
116 	 * toggles when it gets a mouse click.
117 	 *
118 	 * Params:
119 	 *     event = a #GdkEvent
120 	 *     widget = widget that received the event
121 	 *     path = widget-dependent string representation of the event location;
122 	 *         e.g. for #GtkTreeView, a string representation of #GtkTreePath
123 	 *     backgroundArea = background area as passed to gtk_cell_renderer_render()
124 	 *     cellArea = cell area as passed to gtk_cell_renderer_render()
125 	 *     flags = render flags
126 	 *
127 	 * Returns: %TRUE if the event was consumed/handled
128 	 */
129 	public bool activate(Event event, Widget widget, string path, GdkRectangle* backgroundArea, GdkRectangle* cellArea, GtkCellRendererState flags)
130 	{
131 		return gtk_cell_renderer_activate(gtkCellRenderer, (event is null) ? null : event.getEventStruct(), (widget is null) ? null : widget.getWidgetStruct(), Str.toStringz(path), backgroundArea, cellArea, flags) != 0;
132 	}
133 
134 	/**
135 	 * Gets the aligned area used by @cell inside @cell_area. Used for finding
136 	 * the appropriate edit and focus rectangle.
137 	 *
138 	 * Params:
139 	 *     widget = the #GtkWidget this cell will be rendering to
140 	 *     flags = render flags
141 	 *     cellArea = cell area which would be passed to gtk_cell_renderer_render()
142 	 *     alignedArea = the return location for the space inside @cell_area
143 	 *         that would acually be used to render.
144 	 *
145 	 * Since: 3.0
146 	 */
147 	public void getAlignedArea(Widget widget, GtkCellRendererState flags, GdkRectangle* cellArea, out GdkRectangle alignedArea)
148 	{
149 		gtk_cell_renderer_get_aligned_area(gtkCellRenderer, (widget is null) ? null : widget.getWidgetStruct(), flags, cellArea, &alignedArea);
150 	}
151 
152 	/**
153 	 * Fills in @xalign and @yalign with the appropriate values of @cell.
154 	 *
155 	 * Params:
156 	 *     xalign = location to fill in with the x alignment of the cell, or %NULL
157 	 *     yalign = location to fill in with the y alignment of the cell, or %NULL
158 	 *
159 	 * Since: 2.18
160 	 */
161 	public void getAlignment(out float xalign, out float yalign)
162 	{
163 		gtk_cell_renderer_get_alignment(gtkCellRenderer, &xalign, &yalign);
164 	}
165 
166 	/**
167 	 * Fills in @width and @height with the appropriate size of @cell.
168 	 *
169 	 * Params:
170 	 *     width = location to fill in with the fixed width of the cell, or %NULL
171 	 *     height = location to fill in with the fixed height of the cell, or %NULL
172 	 */
173 	public void getFixedSize(out int width, out int height)
174 	{
175 		gtk_cell_renderer_get_fixed_size(gtkCellRenderer, &width, &height);
176 	}
177 
178 	/**
179 	 * Fills in @xpad and @ypad with the appropriate values of @cell.
180 	 *
181 	 * Params:
182 	 *     xpad = location to fill in with the x padding of the cell, or %NULL
183 	 *     ypad = location to fill in with the y padding of the cell, or %NULL
184 	 *
185 	 * Since: 2.18
186 	 */
187 	public void getPadding(out int xpad, out int ypad)
188 	{
189 		gtk_cell_renderer_get_padding(gtkCellRenderer, &xpad, &ypad);
190 	}
191 
192 	/**
193 	 * Retreives a renderer’s natural size when rendered to @widget.
194 	 *
195 	 * Params:
196 	 *     widget = the #GtkWidget this cell will be rendering to
197 	 *     minimumSize = location to store the minimum size, or %NULL
198 	 *     naturalSize = location to store the natural size, or %NULL
199 	 *
200 	 * Since: 3.0
201 	 */
202 	public void getPreferredHeight(Widget widget, out int minimumSize, out int naturalSize)
203 	{
204 		gtk_cell_renderer_get_preferred_height(gtkCellRenderer, (widget is null) ? null : widget.getWidgetStruct(), &minimumSize, &naturalSize);
205 	}
206 
207 	/**
208 	 * Retreives a cell renderers’s minimum and natural height if it were rendered to
209 	 * @widget with the specified @width.
210 	 *
211 	 * Params:
212 	 *     widget = the #GtkWidget this cell will be rendering to
213 	 *     width = the size which is available for allocation
214 	 *     minimumHeight = location for storing the minimum size, or %NULL
215 	 *     naturalHeight = location for storing the preferred size, or %NULL
216 	 *
217 	 * Since: 3.0
218 	 */
219 	public void getPreferredHeightForWidth(Widget widget, int width, out int minimumHeight, out int naturalHeight)
220 	{
221 		gtk_cell_renderer_get_preferred_height_for_width(gtkCellRenderer, (widget is null) ? null : widget.getWidgetStruct(), width, &minimumHeight, &naturalHeight);
222 	}
223 
224 	/**
225 	 * Retrieves the minimum and natural size of a cell taking
226 	 * into account the widget’s preference for height-for-width management.
227 	 *
228 	 * Params:
229 	 *     widget = the #GtkWidget this cell will be rendering to
230 	 *     minimumSize = location for storing the minimum size, or %NULL
231 	 *     naturalSize = location for storing the natural size, or %NULL
232 	 *
233 	 * Since: 3.0
234 	 */
235 	public void getPreferredSize(Widget widget, out Requisition minimumSize, out Requisition naturalSize)
236 	{
237 		GtkRequisition* outminimumSize = sliceNew!GtkRequisition();
238 		GtkRequisition* outnaturalSize = sliceNew!GtkRequisition();
239 
240 		gtk_cell_renderer_get_preferred_size(gtkCellRenderer, (widget is null) ? null : widget.getWidgetStruct(), outminimumSize, outnaturalSize);
241 
242 		minimumSize = ObjectG.getDObject!(Requisition)(outminimumSize, true);
243 		naturalSize = ObjectG.getDObject!(Requisition)(outnaturalSize, true);
244 	}
245 
246 	/**
247 	 * Retreives a renderer’s natural size when rendered to @widget.
248 	 *
249 	 * Params:
250 	 *     widget = the #GtkWidget this cell will be rendering to
251 	 *     minimumSize = location to store the minimum size, or %NULL
252 	 *     naturalSize = location to store the natural size, or %NULL
253 	 *
254 	 * Since: 3.0
255 	 */
256 	public void getPreferredWidth(Widget widget, out int minimumSize, out int naturalSize)
257 	{
258 		gtk_cell_renderer_get_preferred_width(gtkCellRenderer, (widget is null) ? null : widget.getWidgetStruct(), &minimumSize, &naturalSize);
259 	}
260 
261 	/**
262 	 * Retreives a cell renderers’s minimum and natural width if it were rendered to
263 	 * @widget with the specified @height.
264 	 *
265 	 * Params:
266 	 *     widget = the #GtkWidget this cell will be rendering to
267 	 *     height = the size which is available for allocation
268 	 *     minimumWidth = location for storing the minimum size, or %NULL
269 	 *     naturalWidth = location for storing the preferred size, or %NULL
270 	 *
271 	 * Since: 3.0
272 	 */
273 	public void getPreferredWidthForHeight(Widget widget, int height, out int minimumWidth, out int naturalWidth)
274 	{
275 		gtk_cell_renderer_get_preferred_width_for_height(gtkCellRenderer, (widget is null) ? null : widget.getWidgetStruct(), height, &minimumWidth, &naturalWidth);
276 	}
277 
278 	/**
279 	 * Gets whether the cell renderer prefers a height-for-width layout
280 	 * or a width-for-height layout.
281 	 *
282 	 * Returns: The #GtkSizeRequestMode preferred by this renderer.
283 	 *
284 	 * Since: 3.0
285 	 */
286 	public GtkSizeRequestMode getRequestMode()
287 	{
288 		return gtk_cell_renderer_get_request_mode(gtkCellRenderer);
289 	}
290 
291 	/**
292 	 * Returns the cell renderer’s sensitivity.
293 	 *
294 	 * Returns: %TRUE if the cell renderer is sensitive
295 	 *
296 	 * Since: 2.18
297 	 */
298 	public bool getSensitive()
299 	{
300 		return gtk_cell_renderer_get_sensitive(gtkCellRenderer) != 0;
301 	}
302 
303 	/**
304 	 * Obtains the width and height needed to render the cell. Used by view
305 	 * widgets to determine the appropriate size for the cell_area passed to
306 	 * gtk_cell_renderer_render().  If @cell_area is not %NULL, fills in the
307 	 * x and y offsets (if set) of the cell relative to this location.
308 	 *
309 	 * Please note that the values set in @width and @height, as well as those
310 	 * in @x_offset and @y_offset are inclusive of the xpad and ypad properties.
311 	 *
312 	 * Deprecated: Use gtk_cell_renderer_get_preferred_size() instead.
313 	 *
314 	 * Params:
315 	 *     widget = the widget the renderer is rendering to
316 	 *     cellArea = The area a cell will be allocated, or %NULL
317 	 *     xOffset = location to return x offset of cell relative to @cell_area, or %NULL
318 	 *     yOffset = location to return y offset of cell relative to @cell_area, or %NULL
319 	 *     width = location to return width needed to render a cell, or %NULL
320 	 *     height = location to return height needed to render a cell, or %NULL
321 	 */
322 	public void getSize(Widget widget, GdkRectangle* cellArea, out int xOffset, out int yOffset, out int width, out int height)
323 	{
324 		gtk_cell_renderer_get_size(gtkCellRenderer, (widget is null) ? null : widget.getWidgetStruct(), cellArea, &xOffset, &yOffset, &width, &height);
325 	}
326 
327 	/**
328 	 * Translates the cell renderer state to #GtkStateFlags,
329 	 * based on the cell renderer and widget sensitivity, and
330 	 * the given #GtkCellRendererState.
331 	 *
332 	 * Params:
333 	 *     widget = a #GtkWidget, or %NULL
334 	 *     cellState = cell renderer state
335 	 *
336 	 * Returns: the widget state flags applying to @cell
337 	 *
338 	 * Since: 3.0
339 	 */
340 	public GtkStateFlags getState(Widget widget, GtkCellRendererState cellState)
341 	{
342 		return gtk_cell_renderer_get_state(gtkCellRenderer, (widget is null) ? null : widget.getWidgetStruct(), cellState);
343 	}
344 
345 	/**
346 	 * Returns the cell renderer’s visibility.
347 	 *
348 	 * Returns: %TRUE if the cell renderer is visible
349 	 *
350 	 * Since: 2.18
351 	 */
352 	public bool getVisible()
353 	{
354 		return gtk_cell_renderer_get_visible(gtkCellRenderer) != 0;
355 	}
356 
357 	/**
358 	 * Checks whether the cell renderer can do something when activated.
359 	 *
360 	 * Returns: %TRUE if the cell renderer can do anything when activated
361 	 *
362 	 * Since: 3.0
363 	 */
364 	public bool isActivatable()
365 	{
366 		return gtk_cell_renderer_is_activatable(gtkCellRenderer) != 0;
367 	}
368 
369 	/**
370 	 * Invokes the virtual render function of the #GtkCellRenderer. The three
371 	 * passed-in rectangles are areas in @cr. Most renderers will draw within
372 	 * @cell_area; the xalign, yalign, xpad, and ypad fields of the #GtkCellRenderer
373 	 * should be honored with respect to @cell_area. @background_area includes the
374 	 * blank space around the cell, and also the area containing the tree expander;
375 	 * so the @background_area rectangles for all cells tile to cover the entire
376 	 * @window.
377 	 *
378 	 * Params:
379 	 *     cr = a cairo context to draw to
380 	 *     widget = the widget owning @window
381 	 *     backgroundArea = entire cell area (including tree expanders and maybe
382 	 *         padding on the sides)
383 	 *     cellArea = area normally rendered by a cell renderer
384 	 *     flags = flags that affect rendering
385 	 */
386 	public void render(Context cr, Widget widget, GdkRectangle* backgroundArea, GdkRectangle* cellArea, GtkCellRendererState flags)
387 	{
388 		gtk_cell_renderer_render(gtkCellRenderer, (cr is null) ? null : cr.getContextStruct(), (widget is null) ? null : widget.getWidgetStruct(), backgroundArea, cellArea, flags);
389 	}
390 
391 	/**
392 	 * Sets the renderer’s alignment within its available space.
393 	 *
394 	 * Params:
395 	 *     xalign = the x alignment of the cell renderer
396 	 *     yalign = the y alignment of the cell renderer
397 	 *
398 	 * Since: 2.18
399 	 */
400 	public void setAlignment(float xalign, float yalign)
401 	{
402 		gtk_cell_renderer_set_alignment(gtkCellRenderer, xalign, yalign);
403 	}
404 
405 	/**
406 	 * Sets the renderer size to be explicit, independent of the properties set.
407 	 *
408 	 * Params:
409 	 *     width = the width of the cell renderer, or -1
410 	 *     height = the height of the cell renderer, or -1
411 	 */
412 	public void setFixedSize(int width, int height)
413 	{
414 		gtk_cell_renderer_set_fixed_size(gtkCellRenderer, width, height);
415 	}
416 
417 	/**
418 	 * Sets the renderer’s padding.
419 	 *
420 	 * Params:
421 	 *     xpad = the x padding of the cell renderer
422 	 *     ypad = the y padding of the cell renderer
423 	 *
424 	 * Since: 2.18
425 	 */
426 	public void setPadding(int xpad, int ypad)
427 	{
428 		gtk_cell_renderer_set_padding(gtkCellRenderer, xpad, ypad);
429 	}
430 
431 	/**
432 	 * Sets the cell renderer’s sensitivity.
433 	 *
434 	 * Params:
435 	 *     sensitive = the sensitivity of the cell
436 	 *
437 	 * Since: 2.18
438 	 */
439 	public void setSensitive(bool sensitive)
440 	{
441 		gtk_cell_renderer_set_sensitive(gtkCellRenderer, sensitive);
442 	}
443 
444 	/**
445 	 * Sets the cell renderer’s visibility.
446 	 *
447 	 * Params:
448 	 *     visible = the visibility of the cell
449 	 *
450 	 * Since: 2.18
451 	 */
452 	public void setVisible(bool visible)
453 	{
454 		gtk_cell_renderer_set_visible(gtkCellRenderer, visible);
455 	}
456 
457 	/**
458 	 * Passes an activate event to the cell renderer for possible processing.
459 	 *
460 	 * Params:
461 	 *     event = a #GdkEvent
462 	 *     widget = widget that received the event
463 	 *     path = widget-dependent string representation of the event location;
464 	 *         e.g. for #GtkTreeView, a string representation of #GtkTreePath
465 	 *     backgroundArea = background area as passed to gtk_cell_renderer_render()
466 	 *     cellArea = cell area as passed to gtk_cell_renderer_render()
467 	 *     flags = render flags
468 	 *
469 	 * Returns: A new #GtkCellEditable, or %NULL
470 	 */
471 	public CellEditableIF startEditing(Event event, Widget widget, string path, GdkRectangle* backgroundArea, GdkRectangle* cellArea, GtkCellRendererState flags)
472 	{
473 		auto p = gtk_cell_renderer_start_editing(gtkCellRenderer, (event is null) ? null : event.getEventStruct(), (widget is null) ? null : widget.getWidgetStruct(), Str.toStringz(path), backgroundArea, cellArea, flags);
474 
475 		if(p is null)
476 		{
477 			return null;
478 		}
479 
480 		return ObjectG.getDObject!(CellEditableIF)(cast(GtkCellEditable*) p);
481 	}
482 
483 	/**
484 	 * Informs the cell renderer that the editing is stopped.
485 	 * If @canceled is %TRUE, the cell renderer will emit the
486 	 * #GtkCellRenderer::editing-canceled signal.
487 	 *
488 	 * This function should be called by cell renderer implementations
489 	 * in response to the #GtkCellEditable::editing-done signal of
490 	 * #GtkCellEditable.
491 	 *
492 	 * Params:
493 	 *     canceled = %TRUE if the editing has been canceled
494 	 *
495 	 * Since: 2.6
496 	 */
497 	public void stopEditing(bool canceled)
498 	{
499 		gtk_cell_renderer_stop_editing(gtkCellRenderer, canceled);
500 	}
501 
502 	/**
503 	 * This signal gets emitted when the user cancels the process of editing a
504 	 * cell.  For example, an editable cell renderer could be written to cancel
505 	 * editing when the user presses Escape.
506 	 *
507 	 * See also: gtk_cell_renderer_stop_editing().
508 	 *
509 	 * Since: 2.4
510 	 */
511 	gulong addOnEditingCanceled(void delegate(CellRenderer) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
512 	{
513 		return Signals.connect(this, "editing-canceled", dlg, connectFlags ^ ConnectFlags.SWAPPED);
514 	}
515 
516 	/**
517 	 * This signal gets emitted when a cell starts to be edited.
518 	 * The intended use of this signal is to do special setup
519 	 * on @editable, e.g. adding a #GtkEntryCompletion or setting
520 	 * up additional columns in a #GtkComboBox.
521 	 *
522 	 * Note that GTK+ doesn't guarantee that cell renderers will
523 	 * continue to use the same kind of widget for editing in future
524 	 * releases, therefore you should check the type of @editable
525 	 * before doing any specific setup, as in the following example:
526 	 * |[<!-- language="C" -->
527 	 * static void
528 	 * text_editing_started (GtkCellRenderer *cell,
529 	 * GtkCellEditable *editable,
530 	 * const gchar     *path,
531 	 * gpointer         data)
532 	 * {
533 	 * if (GTK_IS_ENTRY (editable))
534 	 * {
535 	 * GtkEntry *entry = GTK_ENTRY (editable);
536 	 *
537 	 * // ... create a GtkEntryCompletion
538 	 *
539 	 * gtk_entry_set_completion (entry, completion);
540 	 * }
541 	 * }
542 	 * ]|
543 	 *
544 	 * Params:
545 	 *     editable = the #GtkCellEditable
546 	 *     path = the path identifying the edited cell
547 	 *
548 	 * Since: 2.6
549 	 */
550 	gulong addOnEditingStarted(void delegate(CellEditableIF, string, CellRenderer) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
551 	{
552 		return Signals.connect(this, "editing-started", dlg, connectFlags ^ ConnectFlags.SWAPPED);
553 	}
554 }