alternative to assert
[gtkD.git] / src / gtk / ComboBox.d
blob193ddbc7cb698aa53957fa72678b4260d1de43a9
1 /*
2 * This file is part of duit.
4 * duit is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU Lesser General Public License as published by
6 * the Free Software Foundation; either version 2.1 of the License, or
7 * (at your option) any later version.
9 * duit is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public License
15 * along with duit; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 // generated automatically - do not change
20 // find conversion definition on APILookup.txt
21 // implement new conversion functionalities on the wrap.utils pakage
24 * Conversion parameters:
25 * inFile = GtkComboBox.html
26 * outPack = gtk
27 * outFile = ComboBox
28 * strct = GtkComboBox
29 * realStrct=
30 * ctorStrct=
31 * clss = ComboBox
32 * interf =
33 * class Code: Yes
34 * interface Code: No
35 * template for:
36 * extend =
37 * implements:
38 * - CellLayoutIF
39 * prefixes:
40 * - gtk_combo_box_
41 * - gtk_
42 * omit structs:
43 * omit prefixes:
44 * omit code:
45 * - gtk_combo_box_new
46 * - gtk_combo_box_new_text
47 * imports:
48 * - atk.ObjectAtk
49 * - glib.Str
50 * - gtk.TreeModel
51 * - gtk.TreeIter
52 * - gtk.CellRenderer
53 * - gtk.CellLayoutIF
54 * - gtk.CellLayoutT
55 * structWrap:
56 * - AtkObject* -> ObjectAtk
57 * - GtkTreeIter* -> TreeIter
58 * - GtkTreeModel* -> TreeModel
59 * local aliases:
62 module gtk.ComboBox;
64 private import gtk.gtktypes;
66 private import lib.gtk;
68 private import atk.ObjectAtk;
69 private import glib.Str;
70 private import gtk.TreeModel;
71 private import gtk.TreeIter;
72 private import gtk.CellRenderer;
73 private import gtk.CellLayoutIF;
74 private import gtk.CellLayoutT;
76 /**
77 * Description
78 * A GtkComboBox is a widget that allows the user to choose from a
79 * list of valid choices. The GtkComboBox displays the selected
80 * choice. When activated, the GtkComboBox displays a popup
81 * which allows the user to make a new choice. The style in which
82 * the selected value is displayed, and the style of the popup is
83 * determined by the current theme. It may be similar to a GtkOptionMenu,
84 * or similar to a Windows-style combo box.
85 * Unlike its predecessors GtkCombo and GtkOptionMenu, the GtkComboBox
86 * uses the model-view pattern; the list of valid choices is specified in the
87 * form of a tree model, and the display of the choices can be adapted to
88 * the data in the model by using cell renderers, as you would in a tree view.
89 * This is possible since GtkComboBox implements the GtkCellLayout interface.
90 * The tree model holding the valid choices is not restricted to a flat list,
91 * it can be a real tree, and the popup will reflect the tree structure.
92 * In addition to the model-view API, GtkComboBox offers a simple API which
93 * is suitable for text-only combo boxes, and hides the complexity of managing
94 * the data in a model. It consists of the functions gtk_combo_box_new_text(),
95 * gtk_combo_box_append_text(), gtk_combo_box_insert_text(),
96 * gtk_combo_box_prepend_text(), gtk_combo_box_remove_text() and
97 * gtk_combo_box_get_active_text().
99 private import gtk.Bin;
100 public class ComboBox : Bin, CellLayoutIF
103 /** the main Gtk struct */
104 protected GtkComboBox* gtkComboBox;
107 public GtkComboBox* getComboBoxStruct()
109 return gtkComboBox;
113 /** the main Gtk struct as a void* */
114 protected void* getStruct()
116 return cast(void*)gtkComboBox;
120 * Sets our main struct and passes it to the parent class
122 public this (GtkComboBox* gtkComboBox)
124 super(cast(GtkBin*)gtkComboBox);
125 this.gtkComboBox = gtkComboBox;
128 private int count = 0;
129 public int maxCount = 0;
132 // add the CellLayout capabilities
133 mixin CellLayoutT!(GtkComboBox);
136 * Creates a new empty GtkComboBox.
137 * If text is true then
138 * constructs a new text combo box, which is a
139 * GtkComboBox just displaying strings. If you use this function to create
140 * a text combo box, you should only manipulate its data source with the
141 * following convenience functions: gtk_combo_box_append_text(),
142 * gtk_combo_box_insert_text(), gtk_combo_box_prepend_text() and
143 * gtk_combo_box_remove_text().
144 * Returns:
145 * A new GtkComboBox.
146 * Since 2.4
148 public this (bit text=true)
150 if ( text )
152 // GtkWidget* gtk_combo_box_new_text (void);
153 this(cast(GtkComboBox*)gtk_combo_box_new_text() );
155 else
157 // GtkWidget* gtk_combo_box_new (void);
158 this(cast(GtkComboBox*)gtk_combo_box_new() );
162 public void setActiveText(char[] text, bool insert=false)
164 int currActive = getActive();
165 int active = 0;
166 setActive(active);
167 bool found = false;
168 while ( !found && active==getActive)
170 found = text==getActiveText();
171 ++active;
173 if ( !found )
175 if ( insert )
177 appendText(text);
178 setActive(active);
180 else
182 //setActive(currActive);
183 setActive(-1);
189 int getIndex(char[] text)
191 TreeIter iter = new TreeIter();
192 TreeModel model = getModel();
193 iter.setModel(model);
194 int index = 0;
195 bit found = false;
196 bit end = false;
197 if ( model.getIterFirst(iter) )
199 while ( !end && iter !is null && !found )
201 found = iter.getValueString(0) == text;
202 if ( !found )
204 end = !model.iterNext(iter);
205 ++index;
209 else
211 end = true;
213 return end ? -1 : index;
216 void prependOrReplaceText(char[] text)
218 int index = getIndex(text);
219 if ( index > 0 )
221 removeText(index);
222 prependText(text);
224 else if ( index == -1 )
226 prependText(text);
234 // imports for the signal processing
235 private import gobject.Signals;
236 private import gdk.gdktypes;
237 int[char[]] connectedSignals;
239 void delegate(ComboBox)[] onChangedListeners;
240 void addOnChanged(void delegate(ComboBox) dlg)
242 if ( !("changed" in connectedSignals) )
244 Signals.connectData(
245 getStruct(),
246 "changed",
247 cast(GCallback)&callBackChanged,
248 this,
249 null,
250 cast(ConnectFlags)0);
251 connectedSignals["changed"] = 1;
253 onChangedListeners ~= dlg;
255 extern(C) static void callBackChanged(GtkComboBox* widgetStruct, ComboBox comboBox)
257 bit consumed = false;
259 foreach ( void delegate(ComboBox) dlg ; comboBox.onChangedListeners )
261 dlg(comboBox);
264 return consumed;
271 * Creates a new GtkComboBox with the model initialized to model.
272 * model:
273 * A GtkTreeModel.
274 * Returns:
275 * A new GtkComboBox.
276 * Since 2.4
278 public this (TreeModel model)
280 // GtkWidget* gtk_combo_box_new_with_model (GtkTreeModel *model);
281 this(cast(GtkComboBox*)gtk_combo_box_new_with_model((model is null) ? null : model.getTreeModelStruct()) );
285 * Returns the wrap width which is used to determine the number
286 * of columns for the popup menu. If the wrap width is larger than
287 * 1, the combo box is in table mode.
288 * combo_box:
289 * A GtkComboBox.
290 * Returns:
291 * the wrap width.
292 * Since 2.6
294 public int getWrapWidth()
296 // gint gtk_combo_box_get_wrap_width (GtkComboBox *combo_box);
297 return gtk_combo_box_get_wrap_width(gtkComboBox);
301 * Sets the wrap width of combo_box to be width. The wrap width is basically
302 * the preferred number of columns when you want the popup to be layed out
303 * in a table.
304 * combo_box:
305 * A GtkComboBox.
306 * width:
307 * Preferred number of columns.
308 * Since 2.4
310 public void setWrapWidth(int width)
312 // void gtk_combo_box_set_wrap_width (GtkComboBox *combo_box, gint width);
313 gtk_combo_box_set_wrap_width(gtkComboBox, width);
317 * Returns the column with row span information for combo_box.
318 * combo_box:
319 * A GtkComboBox.
320 * Returns:
321 * the row span column.
322 * Since 2.6
324 public int getRowSpanColumn()
326 // gint gtk_combo_box_get_row_span_column (GtkComboBox *combo_box);
327 return gtk_combo_box_get_row_span_column(gtkComboBox);
331 * Sets the column with row span information for combo_box to be row_span.
332 * The row span column contains integers which indicate how many rows
333 * an item should span.
334 * combo_box:
335 * A GtkComboBox.
336 * row_span:
337 * A column in the model passed during construction.
338 * Since 2.4
340 public void setRowSpanColumn(int rowSpan)
342 // void gtk_combo_box_set_row_span_column (GtkComboBox *combo_box, gint row_span);
343 gtk_combo_box_set_row_span_column(gtkComboBox, rowSpan);
347 * Returns the column with column span information for combo_box.
348 * combo_box:
349 * A GtkComboBox.
350 * Returns:
351 * the column span column.
352 * Since 2.6
354 public int getColumnSpanColumn()
356 // gint gtk_combo_box_get_column_span_column (GtkComboBox *combo_box);
357 return gtk_combo_box_get_column_span_column(gtkComboBox);
361 * Sets the column with column span information for combo_box to be
362 * column_span. The column span column contains integers which indicate
363 * how many columns an item should span.
364 * combo_box:
365 * A GtkComboBox.
366 * column_span:
367 * A column in the model passed during construction.
368 * Since 2.4
370 public void setColumnSpanColumn(int columnSpan)
372 // void gtk_combo_box_set_column_span_column (GtkComboBox *combo_box, gint column_span);
373 gtk_combo_box_set_column_span_column(gtkComboBox, columnSpan);
377 * Returns the index of the currently active item, or -1 if there's no
378 * active item. If the model is a non-flat treemodel, and the active item
379 * is not an immediate child of the root of the tree, this function returns
380 * gtk_tree_path_get_indices (path)[0], where
381 * path is the GtkTreePath of the active item.
382 * combo_box:
383 * A GtkComboBox.
384 * Returns:
385 * An integer which is the index of the currently active item, or
386 * -1 if there's no active item.
387 * Since 2.4
389 public int getActive()
391 // gint gtk_combo_box_get_active (GtkComboBox *combo_box);
392 return gtk_combo_box_get_active(gtkComboBox);
396 * Sets the active item of combo_box to be the item at index.
397 * combo_box:
398 * A GtkComboBox.
399 * index_:
400 * An index in the model passed during construction, or -1 to have
401 * no active item.
402 * Since 2.4
404 public void setActive(int index)
406 // void gtk_combo_box_set_active (GtkComboBox *combo_box, gint index_);
407 gtk_combo_box_set_active(gtkComboBox, index);
411 * Sets iter to point to the current active item, if it exists.
412 * combo_box:
413 * A GtkComboBox
414 * iter:
415 * The uninitialized GtkTreeIter.
416 * Returns:
417 * TRUE, if iter was set
418 * Since 2.4
420 public int getActiveIter(TreeIter iter)
422 // gboolean gtk_combo_box_get_active_iter (GtkComboBox *combo_box, GtkTreeIter *iter);
423 return gtk_combo_box_get_active_iter(gtkComboBox, (iter is null) ? null : iter.getTreeIterStruct());
427 * Sets the current active item to be the one referenced by iter.
428 * iter must correspond to a path of depth one.
429 * combo_box:
430 * A GtkComboBox
431 * iter:
432 * The GtkTreeIter.
433 * Since 2.4
435 public void setActiveIter(TreeIter iter)
437 // void gtk_combo_box_set_active_iter (GtkComboBox *combo_box, GtkTreeIter *iter);
438 gtk_combo_box_set_active_iter(gtkComboBox, (iter is null) ? null : iter.getTreeIterStruct());
442 * Returns the GtkTreeModel which is acting as data source for combo_box.
443 * combo_box:
444 * A GtkComboBox.
445 * Returns:
446 * A GtkTreeModel which was passed during construction.
447 * Since 2.4
449 public TreeModel getModel()
451 // GtkTreeModel* gtk_combo_box_get_model (GtkComboBox *combo_box);
452 return new TreeModel( gtk_combo_box_get_model(gtkComboBox) );
456 * Sets the model used by combo_box to be model. Will unset a previously set
457 * model (if applicable). If model is NULL, then it will unset the model.
458 * Note that this function does not clear the cell renderers, you have to
459 * call gtk_combo_box_cell_layout_clear() yourself if you need to set up
460 * different cell renderers for the new model.
461 * combo_box:
462 * A GtkComboBox.
463 * model:
464 * A GtkTreeModel.
465 * Since 2.4
467 public void setModel(TreeModel model)
469 // void gtk_combo_box_set_model (GtkComboBox *combo_box, GtkTreeModel *model);
470 gtk_combo_box_set_model(gtkComboBox, (model is null) ? null : model.getTreeModelStruct());
475 * Appends string to the list of strings stored in combo_box. Note that
476 * you can only use this function with combo boxes constructed with
477 * gtk_combo_box_new_text().
478 * combo_box:
479 * A GtkComboBox constructed using gtk_combo_box_new_text().
480 * text:
481 * A string.
482 * Since 2.4
484 public void appendText(char[] text)
486 // void gtk_combo_box_append_text (GtkComboBox *combo_box, const gchar *text);
487 gtk_combo_box_append_text(gtkComboBox, Str.toStringz(text));
491 * Inserts string at position in the list of strings stored in combo_box.
492 * Note that you can only use this function with combo boxes constructed
493 * with gtk_combo_box_new_text().
494 * combo_box:
495 * A GtkComboBox constructed using gtk_combo_box_new_text().
496 * position:
497 * An index to insert text.
498 * text:
499 * A string.
500 * Since 2.4
502 public void insertText(int position, char[] text)
504 // void gtk_combo_box_insert_text (GtkComboBox *combo_box, gint position, const gchar *text);
505 gtk_combo_box_insert_text(gtkComboBox, position, Str.toStringz(text));
509 * Prepends string to the list of strings stored in combo_box. Note that
510 * you can only use this function with combo boxes constructed with
511 * gtk_combo_box_new_text().
512 * combo_box:
513 * A GtkComboBox constructed with gtk_combo_box_new_text().
514 * text:
515 * A string.
516 * Since 2.4
518 public void prependText(char[] text)
520 // void gtk_combo_box_prepend_text (GtkComboBox *combo_box, const gchar *text);
521 gtk_combo_box_prepend_text(gtkComboBox, Str.toStringz(text));
525 * Removes the string at position from combo_box. Note that you can only use
526 * this function with combo boxes constructed with gtk_combo_box_new_text().
527 * combo_box:
528 * A GtkComboBox constructed with gtk_combo_box_new_text().
529 * position:
530 * Index of the item to remove.
531 * Since 2.4
533 public void removeText(int position)
535 // void gtk_combo_box_remove_text (GtkComboBox *combo_box, gint position);
536 gtk_combo_box_remove_text(gtkComboBox, position);
540 * Returns the currently active string in combo_box or NULL if none
541 * is selected. Note that you can only use this function with combo
542 * boxes constructed with gtk_combo_box_new_text() and with
543 * GtkComboBoxEntrys.
544 * combo_box:
545 * A GtkComboBox constructed with gtk_combo_box_new_text().
546 * Returns:
547 * a newly allocated string containing the currently active text.
548 * Since 2.6
550 public char[] getActiveText()
552 // gchar* gtk_combo_box_get_active_text (GtkComboBox *combo_box);
553 return Str.toString(gtk_combo_box_get_active_text(gtkComboBox) );
557 * Pops up the menu or dropdown list of combo_box.
558 * This function is mostly intended for use by accessibility technologies;
559 * applications should have little use for it.
560 * combo_box:
561 * a GtkComboBox
562 * Since 2.4
564 public void popup()
566 // void gtk_combo_box_popup (GtkComboBox *combo_box);
567 gtk_combo_box_popup(gtkComboBox);
571 * Hides the menu or dropdown list of combo_box.
572 * This function is mostly intended for use by accessibility technologies;
573 * applications should have little use for it.
574 * combo_box:
575 * a GtkComboBox
576 * Since 2.4
578 public void popdown()
580 // void gtk_combo_box_popdown (GtkComboBox *combo_box);
581 gtk_combo_box_popdown(gtkComboBox);
585 * Gets the accessible object corresponding to the combo box's popup.
586 * This function is mostly intended for use by accessibility technologies;
587 * applications should have little use for it.
588 * combo_box:
589 * a GtkComboBox
590 * Returns:
591 * the accessible object corresponding to the combo box's popup.
592 * Since 2.6
594 public ObjectAtk getPopupAccessible()
596 // AtkObject* gtk_combo_box_get_popup_accessible (GtkComboBox *combo_box);
597 return new ObjectAtk( gtk_combo_box_get_popup_accessible(gtkComboBox) );
601 * Returns the current row separator function.
602 * combo_box:
603 * a GtkComboBox
604 * Returns:
605 * the current row separator function.
606 * Since 2.6
608 public GtkTreeViewRowSeparatorFunc getRowSeparatorFunc()
610 // GtkTreeViewRowSeparatorFunc gtk_combo_box_get_row_separator_func (GtkComboBox *combo_box);
611 return gtk_combo_box_get_row_separator_func(gtkComboBox);
615 * Sets the row separator function, which is used to determine
616 * whether a row should be drawn as a separator. If the row separator
617 * function is NULL, no separators are drawn. This is the default value.
618 * combo_box:
619 * a GtkComboBox
620 * func:
621 * a GtkTreeViewRowSeparatorFunc
622 * data:
623 * user data to pass to func, or NULL
624 * destroy:
625 * destroy notifier for data, or NULL
626 * Since 2.6
628 public void setRowSeparatorFunc(GtkTreeViewRowSeparatorFunc func, void* data, GtkDestroyNotify destroy)
630 // void gtk_combo_box_set_row_separator_func (GtkComboBox *combo_box, GtkTreeViewRowSeparatorFunc func, gpointer data, GtkDestroyNotify destroy);
631 gtk_combo_box_set_row_separator_func(gtkComboBox, func, data, destroy);
635 * Sets whether the popup menu should have a tearoff
636 * menu item.
637 * combo_box:
638 * a GtkComboBox
639 * add_tearoffs:
640 * TRUE to add tearoff menu items
641 * Since 2.6
643 public void setAddTearoffs(int addTearoffs)
645 // void gtk_combo_box_set_add_tearoffs (GtkComboBox *combo_box, gboolean add_tearoffs);
646 gtk_combo_box_set_add_tearoffs(gtkComboBox, addTearoffs);
650 * Gets the current value of the :add-tearoffs property.
651 * combo_box:
652 * a GtkComboBox
653 * Returns:
654 * the current value of the :add-tearoffs property.
656 public int getAddTearoffs()
658 // gboolean gtk_combo_box_get_add_tearoffs (GtkComboBox *combo_box);
659 return gtk_combo_box_get_add_tearoffs(gtkComboBox);
663 * Sets the menu's title in tearoff mode.
664 * combo_box:
665 * a GtkComboBox
666 * title:
667 * a title for the menu in tearoff mode.
668 * Since 2.10
670 public void setTitle(char[] title)
672 // void gtk_combo_box_set_title (GtkComboBox *combo_box, const gchar *title);
673 gtk_combo_box_set_title(gtkComboBox, Str.toStringz(title));
677 * Gets the current title of the menu in tearoff mode. See
678 * gtk_combo_box_set_add_tearoffs().
679 * combo_box:
680 * a GtkComboBox
681 * Returns:
682 * the menu's title in tearoff mode. This is an internal copy of the
683 * string which must not be freed.
684 * Since 2.10
686 public char[] getTitle()
688 // const gchar* gtk_combo_box_get_title (GtkComboBox *combo_box);
689 return Str.toString(gtk_combo_box_get_title(gtkComboBox) );
693 * Sets whether the combo box will grab focus when it is clicked with
694 * the mouse. Making mouse clicks not grab focus is useful in places
695 * like toolbars where you don't want the keyboard focus removed from
696 * the main area of the application.
697 * combo:
698 * a GtkComboBox
699 * focus_on_click:
700 * whether the combo box grabs focus when clicked
701 * with the mouse
702 * Since 2.6
704 public void setFocusOnClick(int focusOnClick)
706 // void gtk_combo_box_set_focus_on_click (GtkComboBox *combo, gboolean focus_on_click);
707 gtk_combo_box_set_focus_on_click(gtkComboBox, focusOnClick);
711 * Returns whether the combo box grabs focus when it is clicked
712 * with the mouse. See gtk_combo_box_set_focus_on_click().
713 * combo:
714 * a GtkComboBox
715 * Returns:
716 * TRUE if the combo box grabs focus when it is
717 * clicked with the mouse.
718 * Since 2.6
719 * Property Details
720 * The "active" property
721 * "active" gint : Read / Write
722 * The item which is currently active. If the model is a non-flat treemodel,
723 * and the active item is not an immediate child of the root of the tree,
724 * this property has the value gtk_tree_path_get_indices (path)[0],
725 * where path is the GtkTreePath of the active item.
726 * Allowed values: >= -1
727 * Default value: -1
728 * Since 2.4
730 public int getFocusOnClick()
732 // gboolean gtk_combo_box_get_focus_on_click (GtkComboBox *combo);
733 return gtk_combo_box_get_focus_on_click(gtkComboBox);