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