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