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