1Gtk2::ComboBox(3)     User Contributed Perl Documentation    Gtk2::ComboBox(3)
2
3
4

NAME

6       Gtk2::ComboBox - A widget used to choose from a list of items
7

SYNOPSIS

9         # the easy way:
10         $combobox = Gtk2::ComboBox->new_text;
11         foreach (@strings) {
12             $combobox->append_text ($_);
13         }
14         $combobox->prepend_text ($another_string);
15         $combobox->insert_text ($index, $yet_another_string);
16         $combobox->remove_text ($index);
17         $text = $combobox->get_active_text;
18
19         # the full-featured way.
20         # a combo box that shows stock ids and their images:
21         use constant ID_COLUMN => 0;
22         $model = Gtk2::ListStore->new ('Glib::String');
23         foreach (qw(gtk-ok gtk-cancel gtk-yes gtk-no gtk-save gtk-open)) {
24             $model->set ($model->append, ID_COLUMN, $_);
25         }
26         $combo_box = Gtk2::ComboBox->new ($model);
27         # to display anything, you must pack cell renderers into
28         # the combobox, which implements the Gtk2::CellLayout interface.
29         $renderer = Gtk2::CellRendererPixbuf->new;
30         $combo_box->pack_start ($renderer, FALSE);
31         $combo_box->add_attribute ($renderer, stock_id => ID_COLUMN);
32         $renderer = Gtk2::CellRendererText->new;
33         $combo_box->pack_start ($renderer, TRUE);
34         $combo_box->add_attribute ($renderer, text => ID_COLUMN);
35
36         # select by index
37         $combo_box->set_active ($index);
38         $active_index = $combo_box->get_active;
39
40         # or by iter
41         $combo_box->set_active_iter ($iter);
42         $active_iter = $combo_box->get_active_iter;
43

DESCRIPTION

45       Gtk2::ComboBox is a widget that allows the user to choose from a list
46       of valid choices.  The ComboBox displays the selected choice.  When
47       activated, the ComboBox displays a popup which allows the user to make
48       a new choice.
49
50       Unlike its predecessors Gtk2::Combo and Gtk2::OptionMenu, the
51       Gtk2::ComboBox uses the model-view pattern; the list of valid choices
52       is specified in the form of a tree model, and the display of the
53       choices can be adapted to the data in the model by using cell render‐
54       ers, as you would in a tree view.  This is possible since ComboBox
55       implements the Gtk2::CellLayout interface.  The tree model holding the
56       valid choices is not restricted to a flat list; it can be a real tree,
57       and the popup will reflect the tree structure.
58
59       In addition to the model-view API, ComboBox offers a simple API which
60       is suitable for text-only combo boxes, and hides the complexity of man‐
61       aging the data in a model.  It consists of the methods "new_text",
62       "append_text", "insert_text", "prepend_text", "remove_text" and
63       "get_active_text".
64

HIERARCHY

66         Glib::Object
67         +----Glib::InitiallyUnowned
68              +----Gtk2::Object
69                   +----Gtk2::Widget
70                        +----Gtk2::Container
71                             +----Gtk2::Bin
72                                  +----Gtk2::ComboBox
73

INTERFACES

75         Glib::Object::_Unregistered::AtkImplementorIface
76         Gtk2::CellEditable
77         Gtk2::CellLayout
78

METHODS

80       widget = Gtk2::ComboBox->new ($model=undef)
81
82           * $model (Gtk2::TreeModel)
83
84       widget = Gtk2::ComboBox->new_text
85
86       widget = Gtk2::ComboBox->new_with_model ($model=undef)
87
88           * $model (Gtk2::TreeModel)
89
90       integer = $combo_box->get_active
91
92       treeiter = $combo_box->get_active_iter
93
94       $combo_box->set_active_iter ($iter)
95
96           * $iter (Gtk2::TreeIter)
97
98       $combo_box->set_active ($index)
99
100           * $index (integer)
101
102       string = $combo_box->get_active_text
103
104       boolean = $combo_box->get_add_tearoffs
105
106       $combo_box->set_add_tearoffs ($add_tearoffs)
107
108           * $add_tearoffs (boolean)
109
110       $combo_box->append_text ($text)
111
112           * $text (string)
113
114       integer = $combo_box->get_column_span_column
115
116       $combo_box->set_column_span_column ($column_span)
117
118           * $column_span (integer)
119
120       boolean = $combo_box->get_focus_on_click
121
122       $combo_box->set_focus_on_click ($focus_on_click)
123
124           * $focus_on_click (boolean)
125
126       $combo_box->insert_text ($position, $text)
127
128           * $position (integer)
129           * $text (string)
130
131       treemodel = $combo_box->get_model
132
133       $combo_box->set_model ($model)
134
135           * $model (Gtk2::TreeModel)
136
137       $combo_box->popdown
138
139       $combo_box->popup
140
141       $combo_box->prepend_text ($text)
142
143           * $text (string)
144
145       $combo_box->remove_text ($position)
146
147           * $position (integer)
148
149       $combo_box->set_row_separator_func ($func, $data=undef)
150
151           * $func (scalar)
152           * $data (scalar)
153
154       integer = $combo_box->get_row_span_column
155
156       $combo_box->set_row_span_column ($row_span)
157
158           * $row_span (integer)
159
160       string = $combo_box->get_title
161
162       $combo_box->set_title ($title)
163
164           * $title (string)
165
166       integer = $combo_box->get_wrap_width
167
168       $combo_box->set_wrap_width ($width)
169
170           * $width (integer)
171

PROPERTIES

173       'active' (integer : readable / writable / private)
174           The item which is currently active
175
176       'add-tearoffs' (boolean : readable / writable / private)
177           Whether dropdowns should have a tearoff menu item
178
179       'column-span-column' (integer : readable / writable / private)
180           TreeModel column containing the column span values
181
182       'focus-on-click' (boolean : readable / writable / private)
183           Whether the combo box grabs focus when it is clicked with the mouse
184
185       'has-frame' (boolean : readable / writable / private)
186           Whether the combo box draws a frame around the child
187
188       'model' (Gtk2::TreeModel : readable / writable / private)
189           The model for the combo box
190
191       'popup-shown' (boolean : readable / private)
192           Whether the combo's dropdown is shown
193
194       'row-span-column' (integer : readable / writable / private)
195           TreeModel column containing the row span values
196
197       'tearoff-title' (string : readable / writable / private)
198           A title that may be displayed by the window manager when the popup
199           is torn-off
200
201       'wrap-width' (integer : readable / writable / private)
202           Wrap width for laying out the items in a grid
203

SIGNALS

205       changed (Gtk2::ComboBox)
206

SEE ALSO

208       Gtk2, Glib::Object, Glib::InitiallyUnowned, Gtk2::Object, Gtk2::Widget,
209       Gtk2::Container, Gtk2::Bin
210
212       Copyright (C) 2003-2007 by the gtk2-perl team.
213
214       This software is licensed under the LGPL.  See Gtk2 for a full notice.
215
216
217
218perl v5.8.8                       2007-03-18                 Gtk2::ComboBox(3)
Impressum