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