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