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