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 * Conversion parameters: 26 * inFile = GtkListBox.html 27 * outPack = gtk 28 * outFile = ListBox 29 * strct = GtkListBox 30 * realStrct= 31 * ctorStrct= 32 * clss = ListBox 33 * interf = 34 * class Code: No 35 * interface Code: No 36 * template for: 37 * extend = 38 * implements: 39 * prefixes: 40 * - gtk_list_box_ 41 * omit structs: 42 * omit prefixes: 43 * - gtk_list_box_row_ 44 * omit code: 45 * omit signals: 46 * - activate 47 * imports: 48 * - gtk.Adjustment 49 * - gtk.ListBoxRow 50 * - gtk.Widget 51 * structWrap: 52 * - GtkAdjustment* -> Adjustment 53 * - GtkListBoxRow* -> ListBoxRow 54 * - GtkWidget* -> Widget 55 * module aliases: 56 * local aliases: 57 * overrides: 58 */ 59 60 module gtk.ListBox; 61 62 public import gtkc.gtktypes; 63 64 private import gtkc.gtk; 65 private import glib.ConstructionException; 66 private import gobject.ObjectG; 67 68 private import gobject.Signals; 69 public import gtkc.gdktypes; 70 71 private import gtk.Adjustment; 72 private import gtk.ListBoxRow; 73 private import gtk.Widget; 74 75 76 77 private import gtk.Container; 78 79 /** 80 * A GtkListBox is a vertical container that contains GtkListBoxRow 81 * children. These rows can by dynamically sorted and filtered, and 82 * headers can be added dynamically depending on the row content. 83 * It also allows keyboard and mouse navigation and selection like 84 * a typical list. 85 * 86 * Using GtkListBox is often an alternative to GtkTreeView, especially 87 * when the list contents has a more complicated layout than what is allowed 88 * by a GtkCellRenderer, or when the contents is interactive (i.e. has a 89 * button in it). 90 * 91 * Although a GtkListBox must have only GtkListBoxRow children you can 92 * add any kind of widget to it via gtk_container_add(), and a GtkListBoxRow 93 * widget will automatically be inserted between the list and the widget. 94 * 95 * The GtkListBox widget was added in GTK+ 3.10. 96 */ 97 public class ListBox : Container 98 { 99 100 /** the main Gtk struct */ 101 protected GtkListBox* gtkListBox; 102 103 104 public GtkListBox* getListBoxStruct() 105 { 106 return gtkListBox; 107 } 108 109 110 /** the main Gtk struct as a void* */ 111 protected override void* getStruct() 112 { 113 return cast(void*)gtkListBox; 114 } 115 116 /** 117 * Sets our main struct and passes it to the parent class 118 */ 119 public this (GtkListBox* gtkListBox) 120 { 121 super(cast(GtkContainer*)gtkListBox); 122 this.gtkListBox = gtkListBox; 123 } 124 125 protected override void setStruct(GObject* obj) 126 { 127 super.setStruct(obj); 128 gtkListBox = cast(GtkListBox*)obj; 129 } 130 131 /** 132 */ 133 int[string] connectedSignals; 134 135 void delegate(ListBox)[] onActivateCursorRowListeners; 136 /** 137 */ 138 void addOnActivateCursorRow(void delegate(ListBox) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 139 { 140 if ( !("activate-cursor-row" in connectedSignals) ) 141 { 142 Signals.connectData( 143 getStruct(), 144 "activate-cursor-row", 145 cast(GCallback)&callBackActivateCursorRow, 146 cast(void*)this, 147 null, 148 connectFlags); 149 connectedSignals["activate-cursor-row"] = 1; 150 } 151 onActivateCursorRowListeners ~= dlg; 152 } 153 extern(C) static void callBackActivateCursorRow(GtkListBox* listboxStruct, ListBox _listBox) 154 { 155 foreach ( void delegate(ListBox) dlg ; _listBox.onActivateCursorRowListeners ) 156 { 157 dlg(_listBox); 158 } 159 } 160 161 void delegate(GtkMovementStep, gint, ListBox)[] onMoveCursorListeners; 162 /** 163 */ 164 void addOnMoveCursor(void delegate(GtkMovementStep, gint, ListBox) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 165 { 166 if ( !("move-cursor" in connectedSignals) ) 167 { 168 Signals.connectData( 169 getStruct(), 170 "move-cursor", 171 cast(GCallback)&callBackMoveCursor, 172 cast(void*)this, 173 null, 174 connectFlags); 175 connectedSignals["move-cursor"] = 1; 176 } 177 onMoveCursorListeners ~= dlg; 178 } 179 extern(C) static void callBackMoveCursor(GtkListBox* listboxStruct, GtkMovementStep arg1, gint arg2, ListBox _listBox) 180 { 181 foreach ( void delegate(GtkMovementStep, gint, ListBox) dlg ; _listBox.onMoveCursorListeners ) 182 { 183 dlg(arg1, arg2, _listBox); 184 } 185 } 186 187 void delegate(ListBoxRow, ListBox)[] onRowActivatedListeners; 188 /** 189 * The ::row-activated signal is emitted when a row has been activated by 190 * the user. 191 * Since 3.10 192 */ 193 void addOnRowActivated(void delegate(ListBoxRow, ListBox) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 194 { 195 if ( !("row-activated" in connectedSignals) ) 196 { 197 Signals.connectData( 198 getStruct(), 199 "row-activated", 200 cast(GCallback)&callBackRowActivated, 201 cast(void*)this, 202 null, 203 connectFlags); 204 connectedSignals["row-activated"] = 1; 205 } 206 onRowActivatedListeners ~= dlg; 207 } 208 extern(C) static void callBackRowActivated(GtkListBox* listBoxStruct, GtkListBoxRow* row, ListBox _listBox) 209 { 210 foreach ( void delegate(ListBoxRow, ListBox) dlg ; _listBox.onRowActivatedListeners ) 211 { 212 dlg(ObjectG.getDObject!(ListBoxRow)(row), _listBox); 213 } 214 } 215 216 void delegate(ListBoxRow, ListBox)[] onRowSelectedListeners; 217 /** 218 * The ::row-selected signal is emitted when a new row is selected, or 219 * (with a NULL row) when the selection is cleared. 220 * Since 3.10 221 */ 222 void addOnRowSelected(void delegate(ListBoxRow, ListBox) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 223 { 224 if ( !("row-selected" in connectedSignals) ) 225 { 226 Signals.connectData( 227 getStruct(), 228 "row-selected", 229 cast(GCallback)&callBackRowSelected, 230 cast(void*)this, 231 null, 232 connectFlags); 233 connectedSignals["row-selected"] = 1; 234 } 235 onRowSelectedListeners ~= dlg; 236 } 237 extern(C) static void callBackRowSelected(GtkListBox* listBoxStruct, GtkListBoxRow* row, ListBox _listBox) 238 { 239 foreach ( void delegate(ListBoxRow, ListBox) dlg ; _listBox.onRowSelectedListeners ) 240 { 241 dlg(ObjectG.getDObject!(ListBoxRow)(row), _listBox); 242 } 243 } 244 245 void delegate(ListBox)[] onToggleCursorRowListeners; 246 /** 247 */ 248 void addOnToggleCursorRow(void delegate(ListBox) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 249 { 250 if ( !("toggle-cursor-row" in connectedSignals) ) 251 { 252 Signals.connectData( 253 getStruct(), 254 "toggle-cursor-row", 255 cast(GCallback)&callBackToggleCursorRow, 256 cast(void*)this, 257 null, 258 connectFlags); 259 connectedSignals["toggle-cursor-row"] = 1; 260 } 261 onToggleCursorRowListeners ~= dlg; 262 } 263 extern(C) static void callBackToggleCursorRow(GtkListBox* listboxStruct, ListBox _listBox) 264 { 265 foreach ( void delegate(ListBox) dlg ; _listBox.onToggleCursorRowListeners ) 266 { 267 dlg(_listBox); 268 } 269 } 270 271 272 /** 273 * Creates a new GtkListBox container. 274 * Throws: ConstructionException GTK+ fails to create the object. 275 */ 276 public this () 277 { 278 // GtkWidget * gtk_list_box_new (void); 279 auto p = gtk_list_box_new(); 280 if(p is null) 281 { 282 throw new ConstructionException("null returned by gtk_list_box_new()"); 283 } 284 this(cast(GtkListBox*) p); 285 } 286 287 /** 288 * Prepend a widget to the list. If a sort function is set, the widget will 289 * actually be inserted at the calculated position and this function has the 290 * same effect of gtk_container_add(). 291 * Params: 292 * child = the GtkWidget to add 293 * Since 3.10 294 */ 295 public void prepend(Widget child) 296 { 297 // void gtk_list_box_prepend (GtkListBox *list_box, GtkWidget *child); 298 gtk_list_box_prepend(gtkListBox, (child is null) ? null : child.getWidgetStruct()); 299 } 300 301 /** 302 * Insert the child into the list_box at position. If a sort function is 303 * set, the widget will actually be inserted at the calculated position and 304 * this function has the same effect of gtk_container_add(). 305 * If position is -1, or larger than the total number of items in the 306 * list_box, then the child will be appended to the end. 307 * Params: 308 * child = the GtkWidget to add 309 * position = the position to insert child in 310 * Since 3.10 311 */ 312 public void insert(Widget child, int position) 313 { 314 // void gtk_list_box_insert (GtkListBox *list_box, GtkWidget *child, gint position); 315 gtk_list_box_insert(gtkListBox, (child is null) ? null : child.getWidgetStruct(), position); 316 } 317 318 /** 319 * Make row the currently selected row. 320 * Params: 321 * row = The row to select or NULL. [allow-none] 322 * Since 3.10 323 */ 324 public void selectRow(ListBoxRow row) 325 { 326 // void gtk_list_box_select_row (GtkListBox *list_box, GtkListBoxRow *row); 327 gtk_list_box_select_row(gtkListBox, (row is null) ? null : row.getListBoxRowStruct()); 328 } 329 330 /** 331 * Gets the selected row. 332 * Returns: the selected GtkWidget. [transfer none] Since 3.10 333 */ 334 public ListBoxRow getSelectedRow() 335 { 336 // GtkListBoxRow * gtk_list_box_get_selected_row (GtkListBox *list_box); 337 auto p = gtk_list_box_get_selected_row(gtkListBox); 338 339 if(p is null) 340 { 341 return null; 342 } 343 344 return ObjectG.getDObject!(ListBoxRow)(cast(GtkListBoxRow*) p); 345 } 346 347 /** 348 * Sets how selection works in the listbox. 349 * See GtkSelectionMode for details. 350 * Note: GtkListBox does not support GTK_SELECTION_MULTIPLE. 351 * Params: 352 * mode = The GtkSelectionMode 353 * Since 3.10 354 */ 355 public void setSelectionMode(GtkSelectionMode mode) 356 { 357 // void gtk_list_box_set_selection_mode (GtkListBox *list_box, GtkSelectionMode mode); 358 gtk_list_box_set_selection_mode(gtkListBox, mode); 359 } 360 361 /** 362 * Gets the selection mode of the listbox. 363 * Returns: a GtkSelectionMode Since 3.10 364 */ 365 public GtkSelectionMode getSelectionMode() 366 { 367 // GtkSelectionMode gtk_list_box_get_selection_mode (GtkListBox *list_box); 368 return gtk_list_box_get_selection_mode(gtkListBox); 369 } 370 371 /** 372 * If single is TRUE, rows will be activated when you click on them, 373 * otherwise you need to double-click. 374 * Params: 375 * single = a boolean 376 * Since 3.10 377 */ 378 public void setActivateOnSingleClick(int single) 379 { 380 // void gtk_list_box_set_activate_on_single_click (GtkListBox *list_box, gboolean single); 381 gtk_list_box_set_activate_on_single_click(gtkListBox, single); 382 } 383 384 /** 385 * Returns whether rows activate on single clicks. 386 * Returns: TRUE if rows are activated on single click, FALSE otherwise Since 3.10 387 */ 388 public int getActivateOnSingleClick() 389 { 390 // gboolean gtk_list_box_get_activate_on_single_click (GtkListBox *list_box); 391 return gtk_list_box_get_activate_on_single_click(gtkListBox); 392 } 393 394 /** 395 * Gets the adjustment (if any) that the widget uses to 396 * for vertical scrolling. 397 * Returns: the adjustment. [transfer none] Since 3.10 398 */ 399 public Adjustment getAdjustment() 400 { 401 // GtkAdjustment * gtk_list_box_get_adjustment (GtkListBox *list_box); 402 auto p = gtk_list_box_get_adjustment(gtkListBox); 403 404 if(p is null) 405 { 406 return null; 407 } 408 409 return ObjectG.getDObject!(Adjustment)(cast(GtkAdjustment*) p); 410 } 411 412 /** 413 * Sets the adjustment (if any) that the widget uses to 414 * for vertical scrolling. For instance, this is used 415 * to get the page size for PageUp/Down key handling. 416 * In the normal case when the list_box is packed inside 417 * a GtkScrolledWindow the adjustment from that will 418 * be picked up automatically, so there is no need 419 * to manually do that. 420 * Params: 421 * adjustment = the adjustment, or NULL. [allow-none] 422 * Since 3.10 423 */ 424 public void setAdjustment(Adjustment adjustment) 425 { 426 // void gtk_list_box_set_adjustment (GtkListBox *list_box, GtkAdjustment *adjustment); 427 gtk_list_box_set_adjustment(gtkListBox, (adjustment is null) ? null : adjustment.getAdjustmentStruct()); 428 } 429 430 /** 431 * Sets the placeholder widget that is shown in the list when 432 * it doesn't display any visible children. 433 * Params: 434 * placeholder = a GtkWidget or NULL. [allow-none] 435 * Since 3.10 436 */ 437 public void setPlaceholder(Widget placeholder) 438 { 439 // void gtk_list_box_set_placeholder (GtkListBox *list_box, GtkWidget *placeholder); 440 gtk_list_box_set_placeholder(gtkListBox, (placeholder is null) ? null : placeholder.getWidgetStruct()); 441 } 442 443 /** 444 * Gets the n:th child in the list (not counting headers). 445 * Params: 446 * index = the index of the row 447 * Returns: the child GtkWidget. [transfer none] Since 3.10 448 */ 449 public ListBoxRow getRowAtIndex(int index) 450 { 451 // GtkListBoxRow * gtk_list_box_get_row_at_index (GtkListBox *list_box, gint index_); 452 auto p = gtk_list_box_get_row_at_index(gtkListBox, index); 453 454 if(p is null) 455 { 456 return null; 457 } 458 459 return ObjectG.getDObject!(ListBoxRow)(cast(GtkListBoxRow*) p); 460 } 461 462 /** 463 * Gets the row at the y position. 464 * Params: 465 * y = position 466 * Returns: the row. [transfer none] Since 3.10 467 */ 468 public ListBoxRow getRowAtY(int y) 469 { 470 // GtkListBoxRow * gtk_list_box_get_row_at_y (GtkListBox *list_box, gint y); 471 auto p = gtk_list_box_get_row_at_y(gtkListBox, y); 472 473 if(p is null) 474 { 475 return null; 476 } 477 478 return ObjectG.getDObject!(ListBoxRow)(cast(GtkListBoxRow*) p); 479 } 480 481 /** 482 * Update the filtering for all rows. Call this when result 483 * of the filter function on the list_box is changed due 484 * to an external factor. For instance, this would be used 485 * if the filter function just looked for a specific search 486 * string and the entry with the search string has changed. 487 */ 488 public void invalidateFilter() 489 { 490 // void gtk_list_box_invalidate_filter (GtkListBox *list_box); 491 gtk_list_box_invalidate_filter(gtkListBox); 492 } 493 494 /** 495 * Update the separators for all rows. Call this when result 496 * of the header function on the list_box is changed due 497 * to an external factor. 498 */ 499 public void invalidateHeaders() 500 { 501 // void gtk_list_box_invalidate_headers (GtkListBox *list_box); 502 gtk_list_box_invalidate_headers(gtkListBox); 503 } 504 505 /** 506 * Update the sorting for all rows. Call this when result 507 * of the sort function on the list_box is changed due 508 * to an external factor. 509 */ 510 public void invalidateSort() 511 { 512 // void gtk_list_box_invalidate_sort (GtkListBox *list_box); 513 gtk_list_box_invalidate_sort(gtkListBox); 514 } 515 516 /** 517 * By setting a filter function on the list_box one can decide dynamically which 518 * of the rows to show. For instance, to implement a search function on a list that 519 * filters the original list to only show the matching rows. 520 * The filter_func will be called for each row after the call, and it will 521 * continue to be called each time a row changes (via gtk_list_box_row_changed()) or 522 * when gtk_list_box_invalidate_filter() is called. 523 * Params: 524 * filterFunc = callback that lets you filter which rows to show. [closure user_data][allow-none] 525 * userData = user data passed to filter_func 526 * destroy = destroy notifier for user_data 527 * Since 3.10 528 */ 529 public void setFilterFunc(GtkListBoxFilterFunc filterFunc, void* userData, GDestroyNotify destroy) 530 { 531 // void gtk_list_box_set_filter_func (GtkListBox *list_box, GtkListBoxFilterFunc filter_func, gpointer user_data, GDestroyNotify destroy); 532 gtk_list_box_set_filter_func(gtkListBox, filterFunc, userData, destroy); 533 } 534 535 /** 536 * By setting a header function on the list_box one can dynamically add headers 537 * in front of rows, depending on the contents of the row and its position in the list. 538 * For instance, one could use it to add headers in front of the first item of a 539 * new kind, in a list sorted by the kind. 540 * The update_header can look at the current header widget using gtk_list_box_row_get_header() 541 * and either update the state of the widget as needed, or set a new one using 542 * gtk_list_box_row_set_header(). If no header is needed, set the header to NULL. 543 * Note that you may get many calls update_header to this for a particular row when e.g. 544 * changing things that don't affect the header. In this case it is important for performance 545 * to not blindly replace an exisiting header widh an identical one. 546 * The update_header function will be called for each row after the call, and it will 547 * continue to be called each time a row changes (via gtk_list_box_row_changed()) and when 548 * the row before changes (either by gtk_list_box_row_changed() on the previous row, or when 549 * the previous row becomes a different row). It is also called for all rows when 550 * gtk_list_box_invalidate_headers() is called. 551 * Params: 552 * updateHeader = callback that lets you add row headers. [closure user_data][allow-none] 553 * userData = user data passed to update_header 554 * destroy = destroy notifier for user_data 555 * Since 3.10 556 */ 557 public void setHeaderFunc(GtkListBoxUpdateHeaderFunc updateHeader, void* userData, GDestroyNotify destroy) 558 { 559 // void gtk_list_box_set_header_func (GtkListBox *list_box, GtkListBoxUpdateHeaderFunc update_header, gpointer user_data, GDestroyNotify destroy); 560 gtk_list_box_set_header_func(gtkListBox, updateHeader, userData, destroy); 561 } 562 563 /** 564 * By setting a sort function on the list_box one can dynamically reorder the rows 565 * of the list, based on the contents of the rows. 566 * The sort_func will be called for each row after the call, and will continue to 567 * be called each time a row changes (via gtk_list_box_row_changed()) and when 568 * gtk_list_box_invalidate_sort() is called. 569 * Params: 570 * sortFunc = the sort function. [closure user_data][allow-none] 571 * userData = user data passed to sort_func 572 * destroy = destroy notifier for user_data 573 * Since 3.10 574 */ 575 public void setSortFunc(GtkListBoxSortFunc sortFunc, void* userData, GDestroyNotify destroy) 576 { 577 // void gtk_list_box_set_sort_func (GtkListBox *list_box, GtkListBoxSortFunc sort_func, gpointer user_data, GDestroyNotify destroy); 578 gtk_list_box_set_sort_func(gtkListBox, sortFunc, userData, destroy); 579 } 580 581 /** 582 * This is a helper function for implementing DnD onto a GtkListBox. 583 * The passed in row will be highlighted via gtk_drag_highlight(), 584 * and any previously highlighted row will be unhighlighted. 585 * The row will also be unhighlighted when the widget gets 586 * a drag leave event. 587 * Params: 588 * row = a GtkListBoxRow 589 * Since 3.10 590 */ 591 public void dragHighlightRow(ListBoxRow row) 592 { 593 // void gtk_list_box_drag_highlight_row (GtkListBox *list_box, GtkListBoxRow *row); 594 gtk_list_box_drag_highlight_row(gtkListBox, (row is null) ? null : row.getListBoxRowStruct()); 595 } 596 597 /** 598 * If a row has previously been highlighted via gtk_list_box_drag_highlight_row() 599 * it will have the highlight removed. 600 */ 601 public void dragUnhighlightRow() 602 { 603 // void gtk_list_box_drag_unhighlight_row (GtkListBox *list_box); 604 gtk_list_box_drag_unhighlight_row(gtkListBox); 605 } 606 }