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