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