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