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