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.ComboBox; 26 27 private import atk.ObjectAtk; 28 private import gdk.Device; 29 private import glib.ConstructionException; 30 private import glib.Str; 31 private import gobject.ObjectG; 32 private import gobject.Signals; 33 private import gtk.Bin; 34 private import gtk.CellEditableIF; 35 private import gtk.CellEditableT; 36 private import gtk.CellLayoutIF; 37 private import gtk.CellLayoutT; 38 private import gtk.TreeIter; 39 private import gtk.TreeModelIF; 40 private import gtk.c.functions; 41 public import gtk.c.types; 42 public import gtkc.gtktypes; 43 private import std.algorithm; 44 45 46 /** 47 * A GtkComboBox is a widget that allows the user to choose from a list of 48 * valid choices. The GtkComboBox displays the selected choice. When 49 * activated, the GtkComboBox displays a popup which allows the user to 50 * make a new choice. The style in which the selected value is displayed, 51 * and the style of the popup is determined by the current theme. It may 52 * be similar to a Windows-style combo box. 53 * 54 * The GtkComboBox uses the model-view pattern; the list of valid choices 55 * is specified in the form of a tree model, and the display of the choices 56 * can be adapted to the data in the model by using cell renderers, as you 57 * would in a tree view. This is possible since GtkComboBox implements the 58 * #GtkCellLayout interface. The tree model holding the valid choices is 59 * not restricted to a flat list, it can be a real tree, and the popup will 60 * reflect the tree structure. 61 * 62 * To allow the user to enter values not in the model, the “has-entry” 63 * property allows the GtkComboBox to contain a #GtkEntry. This entry 64 * can be accessed by calling gtk_bin_get_child() on the combo box. 65 * 66 * For a simple list of textual choices, the model-view API of GtkComboBox 67 * can be a bit overwhelming. In this case, #GtkComboBoxText offers a 68 * simple alternative. Both GtkComboBox and #GtkComboBoxText can contain 69 * an entry. 70 * 71 * # CSS nodes 72 * 73 * |[<!-- language="plain" --> 74 * combobox 75 * ├── box.linked 76 * │ ╰── button.combo 77 * │ ╰── box 78 * │ ├── cellview 79 * │ ╰── arrow 80 * ╰── window.popup 81 * ]| 82 * 83 * A normal combobox contains a box with the .linked class, a button 84 * with the .combo class and inside those buttons, there are a cellview and 85 * an arrow. 86 * 87 * |[<!-- language="plain" --> 88 * combobox 89 * ├── box.linked 90 * │ ├── entry.combo 91 * │ ╰── button.combo 92 * │ ╰── box 93 * │ ╰── arrow 94 * ╰── window.popup 95 * ]| 96 * 97 * A GtkComboBox with an entry has a single CSS node with name combobox. It 98 * contains a box with the .linked class. That box contains an entry and a 99 * button, both with the .combo class added. 100 * The button also contains another node with name arrow. 101 */ 102 public class ComboBox : Bin, CellEditableIF, CellLayoutIF 103 { 104 /** the main Gtk struct */ 105 protected GtkComboBox* gtkComboBox; 106 107 /** Get the main Gtk struct */ 108 public GtkComboBox* getComboBoxStruct(bool transferOwnership = false) 109 { 110 if (transferOwnership) 111 ownedRef = false; 112 return gtkComboBox; 113 } 114 115 /** the main Gtk struct as a void* */ 116 protected override void* getStruct() 117 { 118 return cast(void*)gtkComboBox; 119 } 120 121 /** 122 * Sets our main struct and passes it to the parent class. 123 */ 124 public this (GtkComboBox* gtkComboBox, bool ownedRef = false) 125 { 126 this.gtkComboBox = gtkComboBox; 127 super(cast(GtkBin*)gtkComboBox, ownedRef); 128 } 129 130 // add the CellEditable capabilities 131 mixin CellEditableT!(GtkComboBox); 132 133 // add the CellLayout capabilities 134 mixin CellLayoutT!(GtkComboBox); 135 136 /** 137 * Creates a new empty GtkComboBox. 138 * Params: 139 * entry = If true, create an empty ComboBox with an entry. 140 * Throws: ConstructionException GTK+ fails to create the object. 141 */ 142 public this (bool entry=true) 143 { 144 GtkComboBox* p; 145 if ( entry ) 146 { 147 // GtkWidget* gtk_combo_box_new_text (void); 148 p = cast(GtkComboBox*)gtk_combo_box_new_with_entry(); 149 } 150 else 151 { 152 // GtkWidget* gtk_combo_box_new (void); 153 p = cast(GtkComboBox*)gtk_combo_box_new(); 154 } 155 156 if(p is null) 157 { 158 throw new ConstructionException("null returned by gtk_combo_box_new"); 159 } 160 161 this(p); 162 } 163 164 /** 165 * Creates a new GtkComboBox with the model initialized to model. 166 * Params: 167 * model = A GtkTreeModel. 168 * entry = If true, create an empty ComboBox with an entry. 169 * Throws: ConstructionException GTK+ fails to create the object. 170 */ 171 public this (TreeModelIF model, bool entry=true) 172 { 173 GtkComboBox* p; 174 if ( entry ) 175 { 176 // GtkWidget* gtk_combo_box_new_with_model_and_entry (GtkTreeModel *model); 177 p = cast(GtkComboBox*)gtk_combo_box_new_with_model_and_entry((model is null) ? null : model.getTreeModelStruct()); 178 } 179 else 180 { 181 // GtkWidget* gtk_combo_box_new_with_model (GtkTreeModel *model); 182 p = cast(GtkComboBox*)gtk_combo_box_new_with_model((model is null) ? null : model.getTreeModelStruct()); 183 } 184 185 if(p is null) 186 { 187 throw new ConstructionException("null returned by gtk_combo_box_new"); 188 } 189 190 this(p); 191 } 192 193 /** 194 * Creates a new empty GtkComboBox using area to layout cells. 195 * Params: 196 * area = the GtkCellArea to use to layout cell renderers. 197 * entry = If true, create an empty ComboBox with an entry. 198 * Throws: ConstructionException GTK+ fails to create the object. 199 */ 200 public this (CellArea area, bool entry=true) 201 { 202 GtkComboBox* p; 203 if ( entry ) 204 { 205 // GtkWidget* gtk_combo_box_new_with_area_and_entry (GtkCellArea *area); 206 p = cast(GtkComboBox*)gtk_combo_box_new_with_area_and_entry((area is null) ? null : area.getCellAreaStruct()); 207 } 208 else 209 { 210 // GtkWidget* gtk_combo_box_new_with_area (GtkCellArea* area); 211 p = cast(GtkComboBox*)gtk_combo_box_new_with_area((area is null) ? null : area.getCellAreaStruct()); 212 } 213 214 if(p is null) 215 { 216 throw new ConstructionException("null returned by gtk_combo_box_new"); 217 } 218 219 this(p); 220 } 221 222 /** 223 */ 224 225 /** */ 226 public static GType getType() 227 { 228 return gtk_combo_box_get_type(); 229 } 230 231 /** 232 * Returns the index of the currently active item, or -1 if there’s no 233 * active item. If the model is a non-flat treemodel, and the active item 234 * is not an immediate child of the root of the tree, this function returns 235 * `gtk_tree_path_get_indices (path)[0]`, where 236 * `path` is the #GtkTreePath of the active item. 237 * 238 * Returns: An integer which is the index of the currently active item, 239 * or -1 if there’s no active item. 240 * 241 * Since: 2.4 242 */ 243 public int getActive() 244 { 245 return gtk_combo_box_get_active(gtkComboBox); 246 } 247 248 /** 249 * Returns the ID of the active row of @combo_box. This value is taken 250 * from the active row and the column specified by the #GtkComboBox:id-column 251 * property of @combo_box (see gtk_combo_box_set_id_column()). 252 * 253 * The returned value is an interned string which means that you can 254 * compare the pointer by value to other interned strings and that you 255 * must not free it. 256 * 257 * If the #GtkComboBox:id-column property of @combo_box is not set, or if 258 * no row is active, or if the active row has a %NULL ID value, then %NULL 259 * is returned. 260 * 261 * Returns: the ID of the active row, or %NULL 262 * 263 * Since: 3.0 264 */ 265 public string getActiveId() 266 { 267 return Str.toString(gtk_combo_box_get_active_id(gtkComboBox)); 268 } 269 270 /** 271 * Sets @iter to point to the currently active item, if any item is active. 272 * Otherwise, @iter is left unchanged. 273 * 274 * Params: 275 * iter = A #GtkTreeIter 276 * 277 * Returns: %TRUE if @iter was set, %FALSE otherwise 278 * 279 * Since: 2.4 280 */ 281 public bool getActiveIter(out TreeIter iter) 282 { 283 GtkTreeIter* outiter = gMalloc!GtkTreeIter(); 284 285 auto p = gtk_combo_box_get_active_iter(gtkComboBox, outiter) != 0; 286 287 iter = ObjectG.getDObject!(TreeIter)(outiter, true); 288 289 return p; 290 } 291 292 /** 293 * Gets the current value of the :add-tearoffs property. 294 * 295 * Returns: the current value of the :add-tearoffs property. 296 */ 297 public bool getAddTearoffs() 298 { 299 return gtk_combo_box_get_add_tearoffs(gtkComboBox) != 0; 300 } 301 302 /** 303 * Returns whether the combo box sets the dropdown button 304 * sensitive or not when there are no items in the model. 305 * 306 * Returns: %GTK_SENSITIVITY_ON if the dropdown button 307 * is sensitive when the model is empty, %GTK_SENSITIVITY_OFF 308 * if the button is always insensitive or 309 * %GTK_SENSITIVITY_AUTO if it is only sensitive as long as 310 * the model has one item to be selected. 311 * 312 * Since: 2.14 313 */ 314 public GtkSensitivityType getButtonSensitivity() 315 { 316 return gtk_combo_box_get_button_sensitivity(gtkComboBox); 317 } 318 319 /** 320 * Returns the column with column span information for @combo_box. 321 * 322 * Returns: the column span column. 323 * 324 * Since: 2.6 325 */ 326 public int getColumnSpanColumn() 327 { 328 return gtk_combo_box_get_column_span_column(gtkComboBox); 329 } 330 331 /** 332 * Returns the column which @combo_box is using to get the strings 333 * from to display in the internal entry. 334 * 335 * Returns: A column in the data source model of @combo_box. 336 * 337 * Since: 2.24 338 */ 339 public int getEntryTextColumn() 340 { 341 return gtk_combo_box_get_entry_text_column(gtkComboBox); 342 } 343 344 /** 345 * Returns whether the combo box grabs focus when it is clicked 346 * with the mouse. See gtk_combo_box_set_focus_on_click(). 347 * 348 * Deprecated: Use gtk_widget_get_focus_on_click() instead 349 * 350 * Returns: %TRUE if the combo box grabs focus when it is 351 * clicked with the mouse. 352 * 353 * Since: 2.6 354 */ 355 public override bool getFocusOnClick() 356 { 357 return gtk_combo_box_get_focus_on_click(gtkComboBox) != 0; 358 } 359 360 /** 361 * Returns whether the combo box has an entry. 362 * 363 * Returns: whether there is an entry in @combo_box. 364 * 365 * Since: 2.24 366 */ 367 public bool getHasEntry() 368 { 369 return gtk_combo_box_get_has_entry(gtkComboBox) != 0; 370 } 371 372 /** 373 * Returns the column which @combo_box is using to get string IDs 374 * for values from. 375 * 376 * Returns: A column in the data source model of @combo_box. 377 * 378 * Since: 3.0 379 */ 380 public int getIdColumn() 381 { 382 return gtk_combo_box_get_id_column(gtkComboBox); 383 } 384 385 /** 386 * Returns the #GtkTreeModel which is acting as data source for @combo_box. 387 * 388 * Returns: A #GtkTreeModel which was passed 389 * during construction. 390 * 391 * Since: 2.4 392 */ 393 public TreeModelIF getModel() 394 { 395 auto p = gtk_combo_box_get_model(gtkComboBox); 396 397 if(p is null) 398 { 399 return null; 400 } 401 402 return ObjectG.getDObject!(TreeModelIF)(cast(GtkTreeModel*) p); 403 } 404 405 /** 406 * Gets the accessible object corresponding to the combo box’s popup. 407 * 408 * This function is mostly intended for use by accessibility technologies; 409 * applications should have little use for it. 410 * 411 * Returns: the accessible object corresponding 412 * to the combo box’s popup. 413 * 414 * Since: 2.6 415 */ 416 public ObjectAtk getPopupAccessible() 417 { 418 auto p = gtk_combo_box_get_popup_accessible(gtkComboBox); 419 420 if(p is null) 421 { 422 return null; 423 } 424 425 return ObjectG.getDObject!(ObjectAtk)(cast(AtkObject*) p); 426 } 427 428 /** 429 * Gets whether the popup uses a fixed width matching 430 * the allocated width of the combo box. 431 * 432 * Returns: %TRUE if the popup uses a fixed width 433 * 434 * Since: 3.0 435 */ 436 public bool getPopupFixedWidth() 437 { 438 return gtk_combo_box_get_popup_fixed_width(gtkComboBox) != 0; 439 } 440 441 /** 442 * Returns the current row separator function. 443 * 444 * Returns: the current row separator function. 445 * 446 * Since: 2.6 447 */ 448 public GtkTreeViewRowSeparatorFunc getRowSeparatorFunc() 449 { 450 return gtk_combo_box_get_row_separator_func(gtkComboBox); 451 } 452 453 /** 454 * Returns the column with row span information for @combo_box. 455 * 456 * Returns: the row span column. 457 * 458 * Since: 2.6 459 */ 460 public int getRowSpanColumn() 461 { 462 return gtk_combo_box_get_row_span_column(gtkComboBox); 463 } 464 465 /** 466 * Gets the current title of the menu in tearoff mode. See 467 * gtk_combo_box_set_add_tearoffs(). 468 * 469 * Returns: the menu’s title in tearoff mode. This is an internal copy of the 470 * string which must not be freed. 471 * 472 * Since: 2.10 473 */ 474 public string getTitle() 475 { 476 return Str.toString(gtk_combo_box_get_title(gtkComboBox)); 477 } 478 479 /** 480 * Returns the wrap width which is used to determine the number of columns 481 * for the popup menu. If the wrap width is larger than 1, the combo box 482 * is in table mode. 483 * 484 * Returns: the wrap width. 485 * 486 * Since: 2.6 487 */ 488 public int getWrapWidth() 489 { 490 return gtk_combo_box_get_wrap_width(gtkComboBox); 491 } 492 493 /** 494 * Hides the menu or dropdown list of @combo_box. 495 * 496 * This function is mostly intended for use by accessibility technologies; 497 * applications should have little use for it. 498 * 499 * Since: 2.4 500 */ 501 public void popdown() 502 { 503 gtk_combo_box_popdown(gtkComboBox); 504 } 505 506 /** 507 * Pops up the menu or dropdown list of @combo_box. 508 * 509 * This function is mostly intended for use by accessibility technologies; 510 * applications should have little use for it. 511 * 512 * Before calling this, @combo_box must be mapped, or nothing will happen. 513 * 514 * Since: 2.4 515 */ 516 public void popup() 517 { 518 gtk_combo_box_popup(gtkComboBox); 519 } 520 521 /** 522 * Pops up the menu or dropdown list of @combo_box, the popup window 523 * will be grabbed so only @device and its associated pointer/keyboard 524 * are the only #GdkDevices able to send events to it. 525 * 526 * Params: 527 * device = a #GdkDevice 528 * 529 * Since: 3.0 530 */ 531 public void popupForDevice(Device device) 532 { 533 gtk_combo_box_popup_for_device(gtkComboBox, (device is null) ? null : device.getDeviceStruct()); 534 } 535 536 /** 537 * Sets the active item of @combo_box to be the item at @index. 538 * 539 * Params: 540 * index = An index in the model passed during construction, or -1 to have 541 * no active item 542 * 543 * Since: 2.4 544 */ 545 public void setActive(int index) 546 { 547 gtk_combo_box_set_active(gtkComboBox, index); 548 } 549 550 /** 551 * Changes the active row of @combo_box to the one that has an ID equal to 552 * @active_id, or unsets the active row if @active_id is %NULL. Rows having 553 * a %NULL ID string cannot be made active by this function. 554 * 555 * If the #GtkComboBox:id-column property of @combo_box is unset or if no 556 * row has the given ID then the function does nothing and returns %FALSE. 557 * 558 * Params: 559 * activeId = the ID of the row to select, or %NULL 560 * 561 * Returns: %TRUE if a row with a matching ID was found. If a %NULL 562 * @active_id was given to unset the active row, the function 563 * always returns %TRUE. 564 * 565 * Since: 3.0 566 */ 567 public bool setActiveId(string activeId) 568 { 569 return gtk_combo_box_set_active_id(gtkComboBox, Str.toStringz(activeId)) != 0; 570 } 571 572 /** 573 * Sets the current active item to be the one referenced by @iter, or 574 * unsets the active item if @iter is %NULL. 575 * 576 * Params: 577 * iter = The #GtkTreeIter, or %NULL 578 * 579 * Since: 2.4 580 */ 581 public void setActiveIter(TreeIter iter) 582 { 583 gtk_combo_box_set_active_iter(gtkComboBox, (iter is null) ? null : iter.getTreeIterStruct()); 584 } 585 586 /** 587 * Sets whether the popup menu should have a tearoff 588 * menu item. 589 * 590 * Params: 591 * addTearoffs = %TRUE to add tearoff menu items 592 * 593 * Since: 2.6 594 */ 595 public void setAddTearoffs(bool addTearoffs) 596 { 597 gtk_combo_box_set_add_tearoffs(gtkComboBox, addTearoffs); 598 } 599 600 /** 601 * Sets whether the dropdown button of the combo box should be 602 * always sensitive (%GTK_SENSITIVITY_ON), never sensitive (%GTK_SENSITIVITY_OFF) 603 * or only if there is at least one item to display (%GTK_SENSITIVITY_AUTO). 604 * 605 * Params: 606 * sensitivity = specify the sensitivity of the dropdown button 607 * 608 * Since: 2.14 609 */ 610 public void setButtonSensitivity(GtkSensitivityType sensitivity) 611 { 612 gtk_combo_box_set_button_sensitivity(gtkComboBox, sensitivity); 613 } 614 615 /** 616 * Sets the column with column span information for @combo_box to be 617 * @column_span. The column span column contains integers which indicate 618 * how many columns an item should span. 619 * 620 * Params: 621 * columnSpan = A column in the model passed during construction 622 * 623 * Since: 2.4 624 */ 625 public void setColumnSpanColumn(int columnSpan) 626 { 627 gtk_combo_box_set_column_span_column(gtkComboBox, columnSpan); 628 } 629 630 /** 631 * Sets the model column which @combo_box should use to get strings from 632 * to be @text_column. The column @text_column in the model of @combo_box 633 * must be of type %G_TYPE_STRING. 634 * 635 * This is only relevant if @combo_box has been created with 636 * #GtkComboBox:has-entry as %TRUE. 637 * 638 * Params: 639 * textColumn = A column in @model to get the strings from for 640 * the internal entry 641 * 642 * Since: 2.24 643 */ 644 public void setEntryTextColumn(int textColumn) 645 { 646 gtk_combo_box_set_entry_text_column(gtkComboBox, textColumn); 647 } 648 649 /** 650 * Sets whether the combo box will grab focus when it is clicked with 651 * the mouse. Making mouse clicks not grab focus is useful in places 652 * like toolbars where you don’t want the keyboard focus removed from 653 * the main area of the application. 654 * 655 * Deprecated: Use gtk_widget_set_focus_on_click() instead 656 * 657 * Params: 658 * focusOnClick = whether the combo box grabs focus when clicked 659 * with the mouse 660 * 661 * Since: 2.6 662 */ 663 public override void setFocusOnClick(bool focusOnClick) 664 { 665 gtk_combo_box_set_focus_on_click(gtkComboBox, focusOnClick); 666 } 667 668 /** 669 * Sets the model column which @combo_box should use to get string IDs 670 * for values from. The column @id_column in the model of @combo_box 671 * must be of type %G_TYPE_STRING. 672 * 673 * Params: 674 * idColumn = A column in @model to get string IDs for values from 675 * 676 * Since: 3.0 677 */ 678 public void setIdColumn(int idColumn) 679 { 680 gtk_combo_box_set_id_column(gtkComboBox, idColumn); 681 } 682 683 /** 684 * Sets the model used by @combo_box to be @model. Will unset a previously set 685 * model (if applicable). If model is %NULL, then it will unset the model. 686 * 687 * Note that this function does not clear the cell renderers, you have to 688 * call gtk_cell_layout_clear() yourself if you need to set up different 689 * cell renderers for the new model. 690 * 691 * Params: 692 * model = A #GtkTreeModel 693 * 694 * Since: 2.4 695 */ 696 public void setModel(TreeModelIF model) 697 { 698 gtk_combo_box_set_model(gtkComboBox, (model is null) ? null : model.getTreeModelStruct()); 699 } 700 701 /** 702 * Specifies whether the popup’s width should be a fixed width 703 * matching the allocated width of the combo box. 704 * 705 * Params: 706 * fixed = whether to use a fixed popup width 707 * 708 * Since: 3.0 709 */ 710 public void setPopupFixedWidth(bool fixed) 711 { 712 gtk_combo_box_set_popup_fixed_width(gtkComboBox, fixed); 713 } 714 715 /** 716 * Sets the row separator function, which is used to determine 717 * whether a row should be drawn as a separator. If the row separator 718 * function is %NULL, no separators are drawn. This is the default value. 719 * 720 * Params: 721 * func = a #GtkTreeViewRowSeparatorFunc 722 * data = user data to pass to @func, or %NULL 723 * destroy = destroy notifier for @data, or %NULL 724 * 725 * Since: 2.6 726 */ 727 public void setRowSeparatorFunc(GtkTreeViewRowSeparatorFunc func, void* data, GDestroyNotify destroy) 728 { 729 gtk_combo_box_set_row_separator_func(gtkComboBox, func, data, destroy); 730 } 731 732 /** 733 * Sets the column with row span information for @combo_box to be @row_span. 734 * The row span column contains integers which indicate how many rows 735 * an item should span. 736 * 737 * Params: 738 * rowSpan = A column in the model passed during construction. 739 * 740 * Since: 2.4 741 */ 742 public void setRowSpanColumn(int rowSpan) 743 { 744 gtk_combo_box_set_row_span_column(gtkComboBox, rowSpan); 745 } 746 747 /** 748 * Sets the menu’s title in tearoff mode. 749 * 750 * Params: 751 * title = a title for the menu in tearoff mode 752 * 753 * Since: 2.10 754 */ 755 public void setTitle(string title) 756 { 757 gtk_combo_box_set_title(gtkComboBox, Str.toStringz(title)); 758 } 759 760 /** 761 * Sets the wrap width of @combo_box to be @width. The wrap width is basically 762 * the preferred number of columns when you want the popup to be layed out 763 * in a table. 764 * 765 * Params: 766 * width = Preferred number of columns 767 * 768 * Since: 2.4 769 */ 770 public void setWrapWidth(int width) 771 { 772 gtk_combo_box_set_wrap_width(gtkComboBox, width); 773 } 774 775 protected class OnChangedDelegateWrapper 776 { 777 void delegate(ComboBox) dlg; 778 gulong handlerId; 779 780 this(void delegate(ComboBox) dlg) 781 { 782 this.dlg = dlg; 783 onChangedListeners ~= this; 784 } 785 786 void remove(OnChangedDelegateWrapper source) 787 { 788 foreach(index, wrapper; onChangedListeners) 789 { 790 if (wrapper.handlerId == source.handlerId) 791 { 792 onChangedListeners[index] = null; 793 onChangedListeners = std.algorithm.remove(onChangedListeners, index); 794 break; 795 } 796 } 797 } 798 } 799 OnChangedDelegateWrapper[] onChangedListeners; 800 801 /** 802 * The changed signal is emitted when the active 803 * item is changed. The can be due to the user selecting 804 * a different item from the list, or due to a 805 * call to gtk_combo_box_set_active_iter(). 806 * It will also be emitted while typing into the entry of a combo box 807 * with an entry. 808 * 809 * Since: 2.4 810 */ 811 gulong addOnChanged(void delegate(ComboBox) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 812 { 813 auto wrapper = new OnChangedDelegateWrapper(dlg); 814 wrapper.handlerId = Signals.connectData( 815 this, 816 "changed", 817 cast(GCallback)&callBackChanged, 818 cast(void*)wrapper, 819 cast(GClosureNotify)&callBackChangedDestroy, 820 connectFlags); 821 return wrapper.handlerId; 822 } 823 824 extern(C) static void callBackChanged(GtkComboBox* comboboxStruct, OnChangedDelegateWrapper wrapper) 825 { 826 wrapper.dlg(wrapper.outer); 827 } 828 829 extern(C) static void callBackChangedDestroy(OnChangedDelegateWrapper wrapper, GClosure* closure) 830 { 831 wrapper.remove(wrapper); 832 } 833 834 protected class OnFormatEntryTextDelegateWrapper 835 { 836 string delegate(string, ComboBox) dlg; 837 gulong handlerId; 838 839 this(string delegate(string, ComboBox) dlg) 840 { 841 this.dlg = dlg; 842 onFormatEntryTextListeners ~= this; 843 } 844 845 void remove(OnFormatEntryTextDelegateWrapper source) 846 { 847 foreach(index, wrapper; onFormatEntryTextListeners) 848 { 849 if (wrapper.handlerId == source.handlerId) 850 { 851 onFormatEntryTextListeners[index] = null; 852 onFormatEntryTextListeners = std.algorithm.remove(onFormatEntryTextListeners, index); 853 break; 854 } 855 } 856 } 857 } 858 OnFormatEntryTextDelegateWrapper[] onFormatEntryTextListeners; 859 860 /** 861 * For combo boxes that are created with an entry (See GtkComboBox:has-entry). 862 * 863 * A signal which allows you to change how the text displayed in a combo box's 864 * entry is displayed. 865 * 866 * Connect a signal handler which returns an allocated string representing 867 * @path. That string will then be used to set the text in the combo box's entry. 868 * The default signal handler uses the text from the GtkComboBox::entry-text-column 869 * model column. 870 * 871 * Here's an example signal handler which fetches data from the model and 872 * displays it in the entry. 873 * |[<!-- language="C" --> 874 * static gchar* 875 * format_entry_text_callback (GtkComboBox *combo, 876 * const gchar *path, 877 * gpointer user_data) 878 * { 879 * GtkTreeIter iter; 880 * GtkTreeModel model; 881 * gdouble value; 882 * 883 * model = gtk_combo_box_get_model (combo); 884 * 885 * gtk_tree_model_get_iter_from_string (model, &iter, path); 886 * gtk_tree_model_get (model, &iter, 887 * THE_DOUBLE_VALUE_COLUMN, &value, 888 * -1); 889 * 890 * return g_strdup_printf ("%g", value); 891 * } 892 * ]| 893 * 894 * Params: 895 * path = the GtkTreePath string from the combo box's current model to format text for 896 * 897 * Returns: a newly allocated string representing @path 898 * for the current GtkComboBox model. 899 * 900 * Since: 3.4 901 */ 902 gulong addOnFormatEntryText(string delegate(string, ComboBox) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 903 { 904 auto wrapper = new OnFormatEntryTextDelegateWrapper(dlg); 905 wrapper.handlerId = Signals.connectData( 906 this, 907 "format-entry-text", 908 cast(GCallback)&callBackFormatEntryText, 909 cast(void*)wrapper, 910 cast(GClosureNotify)&callBackFormatEntryTextDestroy, 911 connectFlags); 912 return wrapper.handlerId; 913 } 914 915 extern(C) static string callBackFormatEntryText(GtkComboBox* comboboxStruct, char* path, OnFormatEntryTextDelegateWrapper wrapper) 916 { 917 return wrapper.dlg(Str.toString(path), wrapper.outer); 918 } 919 920 extern(C) static void callBackFormatEntryTextDestroy(OnFormatEntryTextDelegateWrapper wrapper, GClosure* closure) 921 { 922 wrapper.remove(wrapper); 923 } 924 925 protected class OnMoveActiveDelegateWrapper 926 { 927 void delegate(GtkScrollType, ComboBox) dlg; 928 gulong handlerId; 929 930 this(void delegate(GtkScrollType, ComboBox) dlg) 931 { 932 this.dlg = dlg; 933 onMoveActiveListeners ~= this; 934 } 935 936 void remove(OnMoveActiveDelegateWrapper source) 937 { 938 foreach(index, wrapper; onMoveActiveListeners) 939 { 940 if (wrapper.handlerId == source.handlerId) 941 { 942 onMoveActiveListeners[index] = null; 943 onMoveActiveListeners = std.algorithm.remove(onMoveActiveListeners, index); 944 break; 945 } 946 } 947 } 948 } 949 OnMoveActiveDelegateWrapper[] onMoveActiveListeners; 950 951 /** 952 * The ::move-active signal is a 953 * [keybinding signal][GtkBindingSignal] 954 * which gets emitted to move the active selection. 955 * 956 * Params: 957 * scrollType = a #GtkScrollType 958 * 959 * Since: 2.12 960 */ 961 gulong addOnMoveActive(void delegate(GtkScrollType, ComboBox) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 962 { 963 auto wrapper = new OnMoveActiveDelegateWrapper(dlg); 964 wrapper.handlerId = Signals.connectData( 965 this, 966 "move-active", 967 cast(GCallback)&callBackMoveActive, 968 cast(void*)wrapper, 969 cast(GClosureNotify)&callBackMoveActiveDestroy, 970 connectFlags); 971 return wrapper.handlerId; 972 } 973 974 extern(C) static void callBackMoveActive(GtkComboBox* comboboxStruct, GtkScrollType scrollType, OnMoveActiveDelegateWrapper wrapper) 975 { 976 wrapper.dlg(scrollType, wrapper.outer); 977 } 978 979 extern(C) static void callBackMoveActiveDestroy(OnMoveActiveDelegateWrapper wrapper, GClosure* closure) 980 { 981 wrapper.remove(wrapper); 982 } 983 984 protected class OnPopdownDelegateWrapper 985 { 986 bool delegate(ComboBox) dlg; 987 gulong handlerId; 988 989 this(bool delegate(ComboBox) dlg) 990 { 991 this.dlg = dlg; 992 onPopdownListeners ~= this; 993 } 994 995 void remove(OnPopdownDelegateWrapper source) 996 { 997 foreach(index, wrapper; onPopdownListeners) 998 { 999 if (wrapper.handlerId == source.handlerId) 1000 { 1001 onPopdownListeners[index] = null; 1002 onPopdownListeners = std.algorithm.remove(onPopdownListeners, index); 1003 break; 1004 } 1005 } 1006 } 1007 } 1008 OnPopdownDelegateWrapper[] onPopdownListeners; 1009 1010 /** 1011 * The ::popdown signal is a 1012 * [keybinding signal][GtkBindingSignal] 1013 * which gets emitted to popdown the combo box list. 1014 * 1015 * The default bindings for this signal are Alt+Up and Escape. 1016 * 1017 * Since: 2.12 1018 */ 1019 gulong addOnPopdown(bool delegate(ComboBox) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 1020 { 1021 auto wrapper = new OnPopdownDelegateWrapper(dlg); 1022 wrapper.handlerId = Signals.connectData( 1023 this, 1024 "popdown", 1025 cast(GCallback)&callBackPopdown, 1026 cast(void*)wrapper, 1027 cast(GClosureNotify)&callBackPopdownDestroy, 1028 connectFlags); 1029 return wrapper.handlerId; 1030 } 1031 1032 extern(C) static int callBackPopdown(GtkComboBox* comboboxStruct, OnPopdownDelegateWrapper wrapper) 1033 { 1034 return wrapper.dlg(wrapper.outer); 1035 } 1036 1037 extern(C) static void callBackPopdownDestroy(OnPopdownDelegateWrapper wrapper, GClosure* closure) 1038 { 1039 wrapper.remove(wrapper); 1040 } 1041 1042 protected class OnPopupDelegateWrapper 1043 { 1044 void delegate(ComboBox) dlg; 1045 gulong handlerId; 1046 1047 this(void delegate(ComboBox) dlg) 1048 { 1049 this.dlg = dlg; 1050 onPopupListeners ~= this; 1051 } 1052 1053 void remove(OnPopupDelegateWrapper source) 1054 { 1055 foreach(index, wrapper; onPopupListeners) 1056 { 1057 if (wrapper.handlerId == source.handlerId) 1058 { 1059 onPopupListeners[index] = null; 1060 onPopupListeners = std.algorithm.remove(onPopupListeners, index); 1061 break; 1062 } 1063 } 1064 } 1065 } 1066 OnPopupDelegateWrapper[] onPopupListeners; 1067 1068 /** 1069 * The ::popup signal is a 1070 * [keybinding signal][GtkBindingSignal] 1071 * which gets emitted to popup the combo box list. 1072 * 1073 * The default binding for this signal is Alt+Down. 1074 * 1075 * Since: 2.12 1076 */ 1077 gulong addOnPopup(void delegate(ComboBox) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 1078 { 1079 auto wrapper = new OnPopupDelegateWrapper(dlg); 1080 wrapper.handlerId = Signals.connectData( 1081 this, 1082 "popup", 1083 cast(GCallback)&callBackPopup, 1084 cast(void*)wrapper, 1085 cast(GClosureNotify)&callBackPopupDestroy, 1086 connectFlags); 1087 return wrapper.handlerId; 1088 } 1089 1090 extern(C) static void callBackPopup(GtkComboBox* comboboxStruct, OnPopupDelegateWrapper wrapper) 1091 { 1092 wrapper.dlg(wrapper.outer); 1093 } 1094 1095 extern(C) static void callBackPopupDestroy(OnPopupDelegateWrapper wrapper, GClosure* closure) 1096 { 1097 wrapper.remove(wrapper); 1098 } 1099 }