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