]>
Commit | Line | Data |
---|---|---|
53010e52 | 1 | ///////////////////////////////////////////////////////////////////////////// |
3cbab641 | 2 | // Name: src/gtk1/combobox.cpp |
53010e52 RR |
3 | // Purpose: |
4 | // Author: Robert Roebling | |
dbf858b5 | 5 | // Id: $Id$ |
01111366 | 6 | // Copyright: (c) 1998 Robert Roebling |
65571936 | 7 | // Licence: wxWindows licence |
53010e52 RR |
8 | ///////////////////////////////////////////////////////////////////////////// |
9 | ||
14f355c2 VS |
10 | // For compilers that support precompilation, includes "wx.h". |
11 | #include "wx/wxprec.h" | |
12 | ||
dcf924a3 RR |
13 | #if wxUSE_COMBOBOX |
14 | ||
8228b893 WS |
15 | #include "wx/combobox.h" |
16 | ||
88a7a4e1 WS |
17 | #ifndef WX_PRECOMP |
18 | #include "wx/intl.h" | |
9eddec69 | 19 | #include "wx/settings.h" |
fec9cc08 | 20 | #include "wx/textctrl.h" // for wxEVT_COMMAND_TEXT_UPDATED |
88a7a4e1 WS |
21 | #endif |
22 | ||
584ad2a3 | 23 | #include "wx/arrstr.h" |
53010e52 | 24 | |
3cbab641 | 25 | #include "wx/gtk1/private.h" |
83624f79 | 26 | |
acfd422a RR |
27 | //----------------------------------------------------------------------------- |
28 | // idle system | |
29 | //----------------------------------------------------------------------------- | |
30 | ||
31 | extern void wxapp_install_idle_handler(); | |
32 | extern bool g_isIdle; | |
33 | ||
47908e25 RR |
34 | //----------------------------------------------------------------------------- |
35 | // data | |
36 | //----------------------------------------------------------------------------- | |
37 | ||
38 | extern bool g_blockEventsOnDrag; | |
40eb3606 VZ |
39 | static int g_SelectionBeforePopup = wxID_NONE; // this means the popup is hidden |
40 | ||
78b3b018 RR |
41 | //----------------------------------------------------------------------------- |
42 | // "changed" - typing and list item matches get changed, select-child | |
43 | // if it doesn't match an item then just get a single changed | |
44 | //----------------------------------------------------------------------------- | |
45 | ||
865bb325 | 46 | extern "C" { |
78b3b018 RR |
47 | static void |
48 | gtk_text_changed_callback( GtkWidget *WXUNUSED(widget), wxComboBox *combo ) | |
49 | { | |
50 | if (g_isIdle) wxapp_install_idle_handler(); | |
51 | ||
52 | if (combo->m_ignoreNextUpdate) | |
150e31d2 | 53 | { |
7d8268a1 | 54 | combo->m_ignoreNextUpdate = false; |
78b3b018 RR |
55 | return; |
56 | } | |
57 | ||
58 | if (!combo->m_hasVMT) return; | |
59 | ||
60 | wxCommandEvent event( wxEVT_COMMAND_TEXT_UPDATED, combo->GetId() ); | |
61 | event.SetString( combo->GetValue() ); | |
62 | event.SetEventObject( combo ); | |
63 | combo->GetEventHandler()->ProcessEvent( event ); | |
64 | } | |
865bb325 | 65 | } |
78b3b018 | 66 | |
865bb325 | 67 | extern "C" { |
78b3b018 RR |
68 | static void |
69 | gtk_dummy_callback(GtkEntry *WXUNUSED(entry), GtkCombo *WXUNUSED(combo)) | |
70 | { | |
71 | } | |
865bb325 | 72 | } |
78b3b018 | 73 | |
865bb325 | 74 | extern "C" { |
9d6a9fdd RR |
75 | static void |
76 | gtk_popup_hide_callback(GtkCombo *WXUNUSED(gtk_combo), wxComboBox *combo) | |
7d8268a1 | 77 | { |
9d6a9fdd RR |
78 | // when the popup is hidden, throw a SELECTED event only if the combobox |
79 | // selection changed. | |
3dbfe8f4 VZ |
80 | const int curSelection = combo->GetCurrentSelection(); |
81 | ||
82 | const bool hasChanged = curSelection != g_SelectionBeforePopup; | |
83 | ||
84 | // reset the selection flag to value meaning that it is hidden and do it | |
85 | // now, before generating the events, so that GetSelection() returns the | |
86 | // new value from the event handler | |
87 | g_SelectionBeforePopup = wxID_NONE; | |
88 | ||
89 | if ( hasChanged ) | |
9d6a9fdd RR |
90 | { |
91 | wxCommandEvent event( wxEVT_COMMAND_COMBOBOX_SELECTED, combo->GetId() ); | |
92 | event.SetInt( curSelection ); | |
93 | event.SetString( combo->GetStringSelection() ); | |
94 | event.SetEventObject( combo ); | |
95 | combo->GetEventHandler()->ProcessEvent( event ); | |
345bdf13 KH |
96 | |
97 | // for consistency with the other ports, send TEXT event | |
98 | wxCommandEvent event2( wxEVT_COMMAND_TEXT_UPDATED, combo->GetId() ); | |
99 | event2.SetString( combo->GetStringSelection() ); | |
100 | event2.SetEventObject( combo ); | |
101 | combo->GetEventHandler()->ProcessEvent( event2 ); | |
9d6a9fdd | 102 | } |
9d6a9fdd | 103 | } |
865bb325 | 104 | } |
9d6a9fdd | 105 | |
865bb325 | 106 | extern "C" { |
9d6a9fdd RR |
107 | static void |
108 | gtk_popup_show_callback(GtkCombo *WXUNUSED(gtk_combo), wxComboBox *combo) | |
109 | { | |
110 | // store the combobox selection value before the popup is shown | |
40eb3606 | 111 | g_SelectionBeforePopup = combo->GetCurrentSelection(); |
9d6a9fdd | 112 | } |
865bb325 | 113 | } |
9d6a9fdd | 114 | |
53010e52 | 115 | //----------------------------------------------------------------------------- |
461573cc | 116 | // "select-child" - click/cursor get select-child, changed, select-child |
47908e25 | 117 | //----------------------------------------------------------------------------- |
47908e25 | 118 | |
865bb325 | 119 | extern "C" { |
8a85884a | 120 | static void |
461573cc | 121 | gtk_combo_select_child_callback( GtkList *WXUNUSED(list), GtkWidget *WXUNUSED(widget), wxComboBox *combo ) |
53010e52 | 122 | { |
acfd422a | 123 | if (g_isIdle) wxapp_install_idle_handler(); |
8a85884a | 124 | |
a2053b27 | 125 | if (!combo->m_hasVMT) return; |
30ed6e5c | 126 | |
acfd422a | 127 | if (g_blockEventsOnDrag) return; |
805dd538 | 128 | |
40eb3606 | 129 | int curSelection = combo->GetCurrentSelection(); |
30ed6e5c | 130 | |
3c4e4af6 RR |
131 | if (combo->m_prevSelection == curSelection) return; |
132 | ||
133 | GtkWidget *list = GTK_COMBO(combo->m_widget)->list; | |
134 | gtk_list_unselect_item( GTK_LIST(list), combo->m_prevSelection ); | |
150e31d2 | 135 | |
159b66c0 RR |
136 | combo->m_prevSelection = curSelection; |
137 | ||
78b3b018 RR |
138 | // Quickly set the value of the combo box |
139 | // as GTK+ does that only AFTER the event | |
140 | // is sent. | |
141 | gtk_signal_disconnect_by_func( GTK_OBJECT(GTK_COMBO(combo->GetHandle())->entry), | |
142 | GTK_SIGNAL_FUNC(gtk_text_changed_callback), (gpointer)combo ); | |
143 | combo->SetValue( combo->GetStringSelection() ); | |
58b907f6 | 144 | gtk_signal_connect_after( GTK_OBJECT(GTK_COMBO(combo->GetHandle())->entry), "changed", |
78b3b018 RR |
145 | GTK_SIGNAL_FUNC(gtk_text_changed_callback), (gpointer)combo ); |
146 | ||
40eb3606 | 147 | // throw a SELECTED event only if the combobox popup is hidden (wxID_NONE) |
9d6a9fdd RR |
148 | // because when combobox popup is shown, gtk_combo_select_child_callback is |
149 | // called each times the mouse is over an item with a pressed button so a lot | |
150 | // of SELECTED event could be generated if the user keep the mouse button down | |
151 | // and select other items ... | |
40eb3606 | 152 | if (g_SelectionBeforePopup == wxID_NONE) |
9d6a9fdd RR |
153 | { |
154 | wxCommandEvent event( wxEVT_COMMAND_COMBOBOX_SELECTED, combo->GetId() ); | |
155 | event.SetInt( curSelection ); | |
156 | event.SetString( combo->GetStringSelection() ); | |
157 | event.SetEventObject( combo ); | |
158 | combo->GetEventHandler()->ProcessEvent( event ); | |
0c77152e | 159 | |
345bdf13 | 160 | // for consistency with the other ports, don't generate text update |
40eb3606 VZ |
161 | // events while the user is browsing the combobox neither |
162 | wxCommandEvent event2( wxEVT_COMMAND_TEXT_UPDATED, combo->GetId() ); | |
163 | event2.SetString( combo->GetValue() ); | |
164 | event2.SetEventObject( combo ); | |
165 | combo->GetEventHandler()->ProcessEvent( event2 ); | |
166 | } | |
461573cc | 167 | } |
865bb325 | 168 | } |
461573cc | 169 | |
e1e955e1 RR |
170 | //----------------------------------------------------------------------------- |
171 | // wxComboBox | |
53010e52 RR |
172 | //----------------------------------------------------------------------------- |
173 | ||
174 | IMPLEMENT_DYNAMIC_CLASS(wxComboBox,wxControl) | |
175 | ||
b4071e91 | 176 | BEGIN_EVENT_TABLE(wxComboBox, wxControl) |
fd0eed64 | 177 | EVT_SIZE(wxComboBox::OnSize) |
8a85884a | 178 | EVT_CHAR(wxComboBox::OnChar) |
150e31d2 JS |
179 | |
180 | EVT_MENU(wxID_CUT, wxComboBox::OnCut) | |
181 | EVT_MENU(wxID_COPY, wxComboBox::OnCopy) | |
182 | EVT_MENU(wxID_PASTE, wxComboBox::OnPaste) | |
183 | EVT_MENU(wxID_UNDO, wxComboBox::OnUndo) | |
184 | EVT_MENU(wxID_REDO, wxComboBox::OnRedo) | |
185 | EVT_MENU(wxID_CLEAR, wxComboBox::OnDelete) | |
186 | EVT_MENU(wxID_SELECTALL, wxComboBox::OnSelectAll) | |
187 | ||
188 | EVT_UPDATE_UI(wxID_CUT, wxComboBox::OnUpdateCut) | |
189 | EVT_UPDATE_UI(wxID_COPY, wxComboBox::OnUpdateCopy) | |
190 | EVT_UPDATE_UI(wxID_PASTE, wxComboBox::OnUpdatePaste) | |
191 | EVT_UPDATE_UI(wxID_UNDO, wxComboBox::OnUpdateUndo) | |
192 | EVT_UPDATE_UI(wxID_REDO, wxComboBox::OnUpdateRedo) | |
193 | EVT_UPDATE_UI(wxID_CLEAR, wxComboBox::OnUpdateDelete) | |
194 | EVT_UPDATE_UI(wxID_SELECTALL, wxComboBox::OnUpdateSelectAll) | |
b4071e91 RR |
195 | END_EVENT_TABLE() |
196 | ||
584ad2a3 MB |
197 | bool wxComboBox::Create( wxWindow *parent, wxWindowID id, |
198 | const wxString& value, | |
199 | const wxPoint& pos, const wxSize& size, | |
200 | const wxArrayString& choices, | |
201 | long style, const wxValidator& validator, | |
202 | const wxString& name ) | |
203 | { | |
204 | wxCArrayString chs(choices); | |
205 | ||
206 | return Create( parent, id, value, pos, size, chs.GetCount(), | |
207 | chs.GetStrings(), style, validator, name ); | |
208 | } | |
209 | ||
fd0eed64 RR |
210 | bool wxComboBox::Create( wxWindow *parent, wxWindowID id, const wxString& value, |
211 | const wxPoint& pos, const wxSize& size, | |
212 | int n, const wxString choices[], | |
805dd538 VZ |
213 | long style, const wxValidator& validator, |
214 | const wxString& name ) | |
53010e52 | 215 | { |
7d8268a1 WS |
216 | m_ignoreNextUpdate = false; |
217 | m_needParent = true; | |
218 | m_acceptsFocus = true; | |
159b66c0 | 219 | m_prevSelection = 0; |
805dd538 | 220 | |
db434467 | 221 | if (!PreCreation( parent, pos, size ) || |
4dcaf11a RR |
222 | !CreateBase( parent, id, pos, size, style, validator, name )) |
223 | { | |
223d09f6 | 224 | wxFAIL_MSG( wxT("wxComboBox creation failed") ); |
7d8268a1 | 225 | return false; |
4dcaf11a | 226 | } |
6de97a3b | 227 | |
fd0eed64 | 228 | m_widget = gtk_combo_new(); |
461573cc | 229 | GtkCombo *combo = GTK_COMBO(m_widget); |
30ed6e5c | 230 | |
461573cc RR |
231 | // Disable GTK's broken events ... |
232 | gtk_signal_disconnect( GTK_OBJECT(combo->entry), combo->entry_change_id ); | |
90e572f1 | 233 | // ... and add surrogate handler. |
461573cc | 234 | combo->entry_change_id = gtk_signal_connect (GTK_OBJECT (combo->entry), "changed", |
7d8268a1 | 235 | (GtkSignalFunc) gtk_dummy_callback, combo); |
805dd538 | 236 | |
8a85884a | 237 | // make it more useable |
3ca6a5f0 | 238 | gtk_combo_set_use_arrows_always( GTK_COMBO(m_widget), TRUE ); |
30ed6e5c | 239 | |
3ca6a5f0 BP |
240 | // and case-sensitive |
241 | gtk_combo_set_case_sensitive( GTK_COMBO(m_widget), TRUE ); | |
242 | ||
fd0eed64 | 243 | GtkWidget *list = GTK_COMBO(m_widget)->list; |
805dd538 | 244 | |
81a0614b | 245 | // gtk_list_set_selection_mode( GTK_LIST(list), GTK_SELECTION_MULTIPLE ); |
159b66c0 | 246 | |
fd0eed64 RR |
247 | for (int i = 0; i < n; i++) |
248 | { | |
fab591c5 | 249 | GtkWidget *list_item = gtk_list_item_new_with_label( wxGTK_CONV( choices[i] ) ); |
805dd538 | 250 | |
fd0eed64 | 251 | m_clientDataList.Append( (wxObject*)NULL ); |
f5e27805 | 252 | m_clientObjectList.Append( (wxObject*)NULL ); |
805dd538 | 253 | |
fd0eed64 | 254 | gtk_container_add( GTK_CONTAINER(list), list_item ); |
805dd538 | 255 | |
19da4326 | 256 | gtk_widget_show( list_item ); |
fd0eed64 | 257 | } |
805dd538 | 258 | |
f03fc89f | 259 | m_parent->DoAddChild( this ); |
30ed6e5c | 260 | |
461573cc | 261 | m_focusWidget = combo->entry; |
805dd538 | 262 | |
abdeb9e7 | 263 | PostCreation(size); |
53010e52 | 264 | |
461573cc | 265 | ConnectWidget( combo->button ); |
805dd538 | 266 | |
461573cc RR |
267 | // MSW's combo box shows the value and the selection is -1 |
268 | gtk_entry_set_text( GTK_ENTRY(combo->entry), wxGTK_CONV(value) ); | |
269 | gtk_list_unselect_all( GTK_LIST(combo->list) ); | |
805dd538 | 270 | |
a260fe6a | 271 | if (style & wxCB_READONLY) |
461573cc | 272 | gtk_entry_set_editable( GTK_ENTRY( combo->entry ), FALSE ); |
a260fe6a | 273 | |
9d6a9fdd RR |
274 | // "show" and "hide" events are generated when user click on the combobox button which popups a list |
275 | // this list is the "popwin" gtk widget | |
276 | gtk_signal_connect( GTK_OBJECT(GTK_COMBO(combo)->popwin), "hide", | |
7d8268a1 | 277 | GTK_SIGNAL_FUNC(gtk_popup_hide_callback), (gpointer)this ); |
9d6a9fdd | 278 | gtk_signal_connect( GTK_OBJECT(GTK_COMBO(combo)->popwin), "show", |
7d8268a1 | 279 | GTK_SIGNAL_FUNC(gtk_popup_show_callback), (gpointer)this ); |
9d6a9fdd | 280 | |
58b907f6 | 281 | gtk_signal_connect_after( GTK_OBJECT(combo->entry), "changed", |
461573cc RR |
282 | GTK_SIGNAL_FUNC(gtk_text_changed_callback), (gpointer)this ); |
283 | ||
58b907f6 | 284 | gtk_signal_connect_after( GTK_OBJECT(combo->list), "select-child", |
461573cc | 285 | GTK_SIGNAL_FUNC(gtk_combo_select_child_callback), (gpointer)this ); |
805dd538 | 286 | |
abdeb9e7 | 287 | SetBestSize(size); // need this too because this is a wxControlWithItems |
805dd538 | 288 | |
abdeb9e7 | 289 | // This is required for tool bar support |
024e9a4c RR |
290 | // wxSize setsize = GetSize(); |
291 | // gtk_widget_set_usize( m_widget, setsize.x, setsize.y ); | |
150e31d2 | 292 | |
7d8268a1 | 293 | return true; |
fd0eed64 RR |
294 | } |
295 | ||
296 | wxComboBox::~wxComboBox() | |
297 | { | |
222ed1d6 | 298 | wxList::compatibility_iterator node = m_clientObjectList.GetFirst(); |
fd0eed64 RR |
299 | while (node) |
300 | { | |
b1d4dd7a | 301 | wxClientData *cd = (wxClientData*)node->GetData(); |
fd0eed64 | 302 | if (cd) delete cd; |
b1d4dd7a | 303 | node = node->GetNext(); |
fd0eed64 | 304 | } |
7d6d2cd4 RR |
305 | m_clientObjectList.Clear(); |
306 | ||
fd0eed64 | 307 | m_clientDataList.Clear(); |
6de97a3b | 308 | } |
53010e52 | 309 | |
2b5f62a0 VZ |
310 | void wxComboBox::SetFocus() |
311 | { | |
312 | if ( m_hasFocus ) | |
313 | { | |
314 | // don't do anything if we already have focus | |
315 | return; | |
316 | } | |
317 | ||
318 | gtk_widget_grab_focus( m_focusWidget ); | |
319 | } | |
320 | ||
6f6f938f | 321 | int wxComboBox::DoAppend( const wxString &item ) |
53010e52 | 322 | { |
2a68b7a0 | 323 | wxCHECK_MSG( m_widget != NULL, -1, wxT("invalid combobox") ); |
805dd538 | 324 | |
461573cc | 325 | DisableEvents(); |
30ed6e5c | 326 | |
fd0eed64 | 327 | GtkWidget *list = GTK_COMBO(m_widget)->list; |
805dd538 | 328 | |
fab591c5 | 329 | GtkWidget *list_item = gtk_list_item_new_with_label( wxGTK_CONV( item ) ); |
805dd538 | 330 | |
ec5d85fb RR |
331 | gtk_container_add( GTK_CONTAINER(list), list_item ); |
332 | ||
2b07d713 RR |
333 | if (GTK_WIDGET_REALIZED(m_widget)) |
334 | { | |
335 | gtk_widget_realize( list_item ); | |
336 | gtk_widget_realize( GTK_BIN(list_item)->child ); | |
631a05be | 337 | } |
2b07d713 | 338 | |
631a05be RL |
339 | // Apply current widget style to the new list_item |
340 | GtkRcStyle *style = CreateWidgetStyle(); | |
341 | if (style) | |
342 | { | |
343 | gtk_widget_modify_style( GTK_WIDGET( list_item ), style ); | |
344 | GtkBin *bin = GTK_BIN( list_item ); | |
345 | GtkWidget *label = GTK_WIDGET( bin->child ); | |
346 | gtk_widget_modify_style( label, style ); | |
347 | gtk_rc_style_unref( style ); | |
2b07d713 | 348 | } |
805dd538 | 349 | |
fd0eed64 | 350 | gtk_widget_show( list_item ); |
30ed6e5c | 351 | |
aa61d352 | 352 | const unsigned int count = GetCount(); |
53010e52 | 353 | |
8228b893 | 354 | if ( m_clientDataList.GetCount() < count ) |
0a164d4c | 355 | m_clientDataList.Append( (wxObject*) NULL ); |
8228b893 | 356 | if ( m_clientObjectList.GetCount() < count ) |
0a164d4c | 357 | m_clientObjectList.Append( (wxObject*) NULL ); |
805dd538 | 358 | |
6f6f938f | 359 | EnableEvents(); |
805dd538 | 360 | |
b0021947 VS |
361 | InvalidateBestSize(); |
362 | ||
6f6f938f | 363 | return count - 1; |
fd0eed64 RR |
364 | } |
365 | ||
aa61d352 | 366 | int wxComboBox::DoInsert( const wxString &item, unsigned int pos ) |
243dbf1a | 367 | { |
708c45a6 VZ |
368 | wxCHECK_MSG( !(GetWindowStyle() & wxCB_SORT), -1, |
369 | wxT("can't insert into sorted list")); | |
370 | ||
371 | wxCHECK_MSG( m_widget != NULL, -1, wxT("invalid combobox") ); | |
243dbf1a | 372 | |
8228b893 | 373 | wxCHECK_MSG( IsValidInsert(pos), -1, wxT("invalid index") ); |
6f6f938f | 374 | |
aa61d352 | 375 | if (pos == GetCount()) |
6f6f938f | 376 | return Append(item); |
243dbf1a VZ |
377 | |
378 | DisableEvents(); | |
379 | ||
380 | GtkWidget *list = GTK_COMBO(m_widget)->list; | |
381 | ||
382 | GtkWidget *list_item = gtk_list_item_new_with_label( wxGTK_CONV( item ) ); | |
383 | ||
384 | GList *gitem_list = g_list_alloc (); | |
385 | gitem_list->data = list_item; | |
386 | gtk_list_insert_items( GTK_LIST (list), gitem_list, pos ); | |
387 | ||
388 | if (GTK_WIDGET_REALIZED(m_widget)) | |
389 | { | |
390 | gtk_widget_realize( list_item ); | |
391 | gtk_widget_realize( GTK_BIN(list_item)->child ); | |
392 | ||
f40fdaa3 | 393 | ApplyWidgetStyle(); |
243dbf1a VZ |
394 | } |
395 | ||
396 | gtk_widget_show( list_item ); | |
397 | ||
aa61d352 | 398 | const unsigned int count = GetCount(); |
243dbf1a | 399 | |
8228b893 | 400 | if ( m_clientDataList.GetCount() < count ) |
0a164d4c | 401 | m_clientDataList.Insert( pos, (wxObject*) NULL ); |
8228b893 | 402 | if ( m_clientObjectList.GetCount() < count ) |
0a164d4c | 403 | m_clientObjectList.Insert( pos, (wxObject*) NULL ); |
243dbf1a | 404 | |
6f6f938f | 405 | EnableEvents(); |
150e31d2 | 406 | |
b0021947 | 407 | InvalidateBestSize(); |
243dbf1a | 408 | |
6f6f938f | 409 | return pos; |
243dbf1a VZ |
410 | } |
411 | ||
aa61d352 | 412 | void wxComboBox::DoSetItemClientData(unsigned int n, void* clientData) |
fd0eed64 | 413 | { |
223d09f6 | 414 | wxCHECK_RET( m_widget != NULL, wxT("invalid combobox") ); |
805dd538 | 415 | |
222ed1d6 | 416 | wxList::compatibility_iterator node = m_clientDataList.Item( n ); |
fd0eed64 | 417 | if (!node) return; |
805dd538 | 418 | |
f5e27805 | 419 | node->SetData( (wxObject*) clientData ); |
6de97a3b | 420 | } |
53010e52 | 421 | |
aa61d352 | 422 | void* wxComboBox::DoGetItemClientData(unsigned int n) const |
53010e52 | 423 | { |
223d09f6 | 424 | wxCHECK_MSG( m_widget != NULL, NULL, wxT("invalid combobox") ); |
805dd538 | 425 | |
222ed1d6 | 426 | wxList::compatibility_iterator node = m_clientDataList.Item( n ); |
805dd538 | 427 | |
30ed6e5c | 428 | return node ? node->GetData() : NULL; |
fd0eed64 RR |
429 | } |
430 | ||
aa61d352 | 431 | void wxComboBox::DoSetItemClientObject(unsigned int n, wxClientData* clientData) |
fd0eed64 | 432 | { |
223d09f6 | 433 | wxCHECK_RET( m_widget != NULL, wxT("invalid combobox") ); |
805dd538 | 434 | |
222ed1d6 | 435 | wxList::compatibility_iterator node = m_clientObjectList.Item( n ); |
fd0eed64 | 436 | if (!node) return; |
805dd538 | 437 | |
e94e2e95 | 438 | // wxItemContainer already deletes data for us |
805dd538 | 439 | |
fd0eed64 | 440 | node->SetData( (wxObject*) clientData ); |
6de97a3b | 441 | } |
53010e52 | 442 | |
aa61d352 | 443 | wxClientData* wxComboBox::DoGetItemClientObject(unsigned int n) const |
53010e52 | 444 | { |
223d09f6 | 445 | wxCHECK_MSG( m_widget != NULL, (wxClientData*)NULL, wxT("invalid combobox") ); |
805dd538 | 446 | |
222ed1d6 | 447 | wxList::compatibility_iterator node = m_clientObjectList.Item( n ); |
805dd538 | 448 | |
30ed6e5c | 449 | return node ? (wxClientData*) node->GetData() : NULL; |
fd0eed64 RR |
450 | } |
451 | ||
452 | void wxComboBox::Clear() | |
453 | { | |
223d09f6 | 454 | wxCHECK_RET( m_widget != NULL, wxT("invalid combobox") ); |
805dd538 | 455 | |
461573cc | 456 | DisableEvents(); |
30ed6e5c | 457 | |
fd0eed64 | 458 | GtkWidget *list = GTK_COMBO(m_widget)->list; |
8228b893 | 459 | gtk_list_clear_items( GTK_LIST(list), 0, (int)GetCount() ); |
805dd538 | 460 | |
222ed1d6 | 461 | wxList::compatibility_iterator node = m_clientObjectList.GetFirst(); |
fd0eed64 RR |
462 | while (node) |
463 | { | |
b1d4dd7a | 464 | wxClientData *cd = (wxClientData*)node->GetData(); |
fd0eed64 | 465 | if (cd) delete cd; |
b1d4dd7a | 466 | node = node->GetNext(); |
fd0eed64 | 467 | } |
f5e27805 | 468 | m_clientObjectList.Clear(); |
805dd538 | 469 | |
fd0eed64 | 470 | m_clientDataList.Clear(); |
30ed6e5c | 471 | |
461573cc | 472 | EnableEvents(); |
b0021947 VS |
473 | |
474 | InvalidateBestSize(); | |
6de97a3b | 475 | } |
53010e52 | 476 | |
aa61d352 | 477 | void wxComboBox::Delete(unsigned int n) |
53010e52 | 478 | { |
223d09f6 | 479 | wxCHECK_RET( m_widget != NULL, wxT("invalid combobox") ); |
805dd538 | 480 | |
fd0eed64 | 481 | GtkList *listbox = GTK_LIST( GTK_COMBO(m_widget)->list ); |
805dd538 | 482 | |
fd0eed64 | 483 | GList *child = g_list_nth( listbox->children, n ); |
805dd538 | 484 | |
fd0eed64 RR |
485 | if (!child) |
486 | { | |
223d09f6 | 487 | wxFAIL_MSG(wxT("wrong index")); |
fd0eed64 RR |
488 | return; |
489 | } | |
805dd538 | 490 | |
461573cc | 491 | DisableEvents(); |
30ed6e5c | 492 | |
bbe0af5b | 493 | GList *list = g_list_append( (GList*) NULL, child->data ); |
fd0eed64 RR |
494 | gtk_list_remove_items( listbox, list ); |
495 | g_list_free( list ); | |
805dd538 | 496 | |
222ed1d6 | 497 | wxList::compatibility_iterator node = m_clientObjectList.Item( n ); |
f5e27805 | 498 | if (node) |
fd0eed64 | 499 | { |
b1d4dd7a | 500 | wxClientData *cd = (wxClientData*)node->GetData(); |
fd0eed64 | 501 | if (cd) delete cd; |
222ed1d6 | 502 | m_clientObjectList.Erase( node ); |
f5e27805 | 503 | } |
805dd538 | 504 | |
b1d4dd7a | 505 | node = m_clientDataList.Item( n ); |
f5e27805 | 506 | if (node) |
222ed1d6 | 507 | m_clientDataList.Erase( node ); |
150e31d2 | 508 | |
461573cc | 509 | EnableEvents(); |
150e31d2 | 510 | |
b0021947 | 511 | InvalidateBestSize(); |
461573cc RR |
512 | } |
513 | ||
aa61d352 | 514 | void wxComboBox::SetString(unsigned int n, const wxString &text) |
461573cc RR |
515 | { |
516 | wxCHECK_RET( m_widget != NULL, wxT("invalid combobox") ); | |
517 | ||
518 | GtkWidget *list = GTK_COMBO(m_widget)->list; | |
519 | ||
520 | GList *child = g_list_nth( GTK_LIST(list)->children, n ); | |
521 | if (child) | |
522 | { | |
523 | GtkBin *bin = GTK_BIN( child->data ); | |
524 | GtkLabel *label = GTK_LABEL( bin->child ); | |
525 | gtk_label_set_text(label, wxGTK_CONV(text)); | |
526 | } | |
527 | else | |
528 | { | |
529 | wxFAIL_MSG( wxT("wxComboBox: wrong index") ); | |
fd0eed64 | 530 | } |
150e31d2 | 531 | |
b0021947 | 532 | InvalidateBestSize(); |
6de97a3b | 533 | } |
53010e52 | 534 | |
11e62fe6 | 535 | int wxComboBox::FindString( const wxString &item, bool bCase ) const |
53010e52 | 536 | { |
0a164d4c | 537 | wxCHECK_MSG( m_widget != NULL, wxNOT_FOUND, wxT("invalid combobox") ); |
805dd538 | 538 | |
fd0eed64 | 539 | GtkWidget *list = GTK_COMBO(m_widget)->list; |
805dd538 | 540 | |
53010e52 RR |
541 | GList *child = GTK_LIST(list)->children; |
542 | int count = 0; | |
543 | while (child) | |
544 | { | |
fd0eed64 RR |
545 | GtkBin *bin = GTK_BIN( child->data ); |
546 | GtkLabel *label = GTK_LABEL( bin->child ); | |
2b5f62a0 | 547 | wxString str( label->label ); |
11e62fe6 | 548 | if (item.IsSameAs( str , bCase ) ) |
7cf8cb48 | 549 | return count; |
30ed6e5c | 550 | |
fd0eed64 RR |
551 | count++; |
552 | child = child->next; | |
553 | } | |
805dd538 | 554 | |
7cf8cb48 | 555 | return wxNOT_FOUND; |
fd0eed64 RR |
556 | } |
557 | ||
558 | int wxComboBox::GetSelection() const | |
40eb3606 VZ |
559 | { |
560 | // if the popup is currently opened, use the selection as it had been | |
561 | // before it dropped down | |
562 | return g_SelectionBeforePopup == wxID_NONE ? GetCurrentSelection() | |
563 | : g_SelectionBeforePopup; | |
564 | } | |
565 | ||
566 | int wxComboBox::GetCurrentSelection() const | |
fd0eed64 | 567 | { |
223d09f6 | 568 | wxCHECK_MSG( m_widget != NULL, -1, wxT("invalid combobox") ); |
805dd538 | 569 | |
fd0eed64 | 570 | GtkWidget *list = GTK_COMBO(m_widget)->list; |
805dd538 | 571 | |
fd0eed64 RR |
572 | GList *selection = GTK_LIST(list)->selection; |
573 | if (selection) | |
574 | { | |
575 | GList *child = GTK_LIST(list)->children; | |
576 | int count = 0; | |
577 | while (child) | |
578 | { | |
579 | if (child->data == selection->data) return count; | |
580 | count++; | |
581 | child = child->next; | |
582 | } | |
6de97a3b | 583 | } |
805dd538 | 584 | |
8228b893 | 585 | return wxNOT_FOUND; |
6de97a3b | 586 | } |
53010e52 | 587 | |
aa61d352 | 588 | wxString wxComboBox::GetString(unsigned int n) const |
53010e52 | 589 | { |
0a164d4c | 590 | wxCHECK_MSG( m_widget != NULL, wxEmptyString, wxT("invalid combobox") ); |
805dd538 | 591 | |
fd0eed64 | 592 | GtkWidget *list = GTK_COMBO(m_widget)->list; |
805dd538 | 593 | |
7cf8cb48 | 594 | wxString str; |
fd0eed64 RR |
595 | GList *child = g_list_nth( GTK_LIST(list)->children, n ); |
596 | if (child) | |
597 | { | |
598 | GtkBin *bin = GTK_BIN( child->data ); | |
599 | GtkLabel *label = GTK_LABEL( bin->child ); | |
2e1d7104 | 600 | str = wxString( label->label ); |
7cf8cb48 VZ |
601 | } |
602 | else | |
603 | { | |
223d09f6 | 604 | wxFAIL_MSG( wxT("wxComboBox: wrong index") ); |
fd0eed64 | 605 | } |
805dd538 | 606 | |
7cf8cb48 | 607 | return str; |
6de97a3b | 608 | } |
53010e52 | 609 | |
fd0eed64 | 610 | wxString wxComboBox::GetStringSelection() const |
53010e52 | 611 | { |
0a164d4c | 612 | wxCHECK_MSG( m_widget != NULL, wxEmptyString, wxT("invalid combobox") ); |
805dd538 | 613 | |
fd0eed64 | 614 | GtkWidget *list = GTK_COMBO(m_widget)->list; |
805dd538 | 615 | |
fd0eed64 RR |
616 | GList *selection = GTK_LIST(list)->selection; |
617 | if (selection) | |
618 | { | |
619 | GtkBin *bin = GTK_BIN( selection->data ); | |
2b5f62a0 | 620 | GtkLabel *label = GTK_LABEL( bin->child ); |
2b5f62a0 | 621 | wxString tmp( label->label ); |
fd0eed64 RR |
622 | return tmp; |
623 | } | |
805dd538 | 624 | |
223d09f6 | 625 | wxFAIL_MSG( wxT("wxComboBox: no selection") ); |
805dd538 | 626 | |
0a164d4c | 627 | return wxEmptyString; |
6de97a3b | 628 | } |
53010e52 | 629 | |
aa61d352 | 630 | unsigned int wxComboBox::GetCount() const |
53010e52 | 631 | { |
223d09f6 | 632 | wxCHECK_MSG( m_widget != NULL, 0, wxT("invalid combobox") ); |
805dd538 | 633 | |
fd0eed64 | 634 | GtkWidget *list = GTK_COMBO(m_widget)->list; |
805dd538 | 635 | |
fd0eed64 | 636 | GList *child = GTK_LIST(list)->children; |
aa61d352 | 637 | unsigned int count = 0; |
fd0eed64 RR |
638 | while (child) { count++; child = child->next; } |
639 | return count; | |
6de97a3b | 640 | } |
53010e52 | 641 | |
debe6624 | 642 | void wxComboBox::SetSelection( int n ) |
53010e52 | 643 | { |
223d09f6 | 644 | wxCHECK_RET( m_widget != NULL, wxT("invalid combobox") ); |
805dd538 | 645 | |
953704c1 RR |
646 | DisableEvents(); |
647 | ||
fd0eed64 | 648 | GtkWidget *list = GTK_COMBO(m_widget)->list; |
159b66c0 | 649 | gtk_list_unselect_item( GTK_LIST(list), m_prevSelection ); |
fd0eed64 | 650 | gtk_list_select_item( GTK_LIST(list), n ); |
159b66c0 | 651 | m_prevSelection = n; |
953704c1 RR |
652 | |
653 | EnableEvents(); | |
6de97a3b | 654 | } |
53010e52 | 655 | |
fd0eed64 | 656 | wxString wxComboBox::GetValue() const |
53010e52 | 657 | { |
2e1d7104 RR |
658 | GtkEntry *entry = GTK_ENTRY( GTK_COMBO(m_widget)->entry ); |
659 | wxString tmp( wxGTK_CONV_BACK( gtk_entry_get_text( entry ) ) ); | |
660 | ||
30ed6e5c | 661 | #if 0 |
2e1d7104 RR |
662 | for (int i = 0; i < wxStrlen(tmp.c_str()) +1; i++) |
663 | { | |
664 | wxChar c = tmp[i]; | |
665 | printf( "%d ", (int) (c) ); | |
666 | } | |
667 | printf( "\n" ); | |
668 | #endif | |
30ed6e5c | 669 | |
fd0eed64 | 670 | return tmp; |
6de97a3b | 671 | } |
53010e52 RR |
672 | |
673 | void wxComboBox::SetValue( const wxString& value ) | |
674 | { | |
223d09f6 | 675 | wxCHECK_RET( m_widget != NULL, wxT("invalid combobox") ); |
805dd538 | 676 | |
fd0eed64 | 677 | GtkWidget *entry = GTK_COMBO(m_widget)->entry; |
0a164d4c | 678 | wxString tmp; |
fd0eed64 | 679 | if (!value.IsNull()) tmp = value; |
fab591c5 | 680 | gtk_entry_set_text( GTK_ENTRY(entry), wxGTK_CONV( tmp ) ); |
150e31d2 | 681 | |
b0021947 | 682 | InvalidateBestSize(); |
6de97a3b | 683 | } |
53010e52 | 684 | |
fd0eed64 | 685 | void wxComboBox::Copy() |
53010e52 | 686 | { |
223d09f6 | 687 | wxCHECK_RET( m_widget != NULL, wxT("invalid combobox") ); |
805dd538 | 688 | |
fd0eed64 | 689 | GtkWidget *entry = GTK_COMBO(m_widget)->entry; |
9e691f46 | 690 | gtk_editable_copy_clipboard( GTK_EDITABLE(entry) DUMMY_CLIPBOARD_ARG ); |
6de97a3b | 691 | } |
53010e52 | 692 | |
fd0eed64 | 693 | void wxComboBox::Cut() |
53010e52 | 694 | { |
223d09f6 | 695 | wxCHECK_RET( m_widget != NULL, wxT("invalid combobox") ); |
805dd538 | 696 | |
fd0eed64 | 697 | GtkWidget *entry = GTK_COMBO(m_widget)->entry; |
9e691f46 | 698 | gtk_editable_cut_clipboard( GTK_EDITABLE(entry) DUMMY_CLIPBOARD_ARG ); |
6de97a3b | 699 | } |
53010e52 | 700 | |
fd0eed64 | 701 | void wxComboBox::Paste() |
53010e52 | 702 | { |
223d09f6 | 703 | wxCHECK_RET( m_widget != NULL, wxT("invalid combobox") ); |
805dd538 | 704 | |
fd0eed64 | 705 | GtkWidget *entry = GTK_COMBO(m_widget)->entry; |
9e691f46 | 706 | gtk_editable_paste_clipboard( GTK_EDITABLE(entry) DUMMY_CLIPBOARD_ARG); |
6de97a3b | 707 | } |
53010e52 | 708 | |
150e31d2 JS |
709 | void wxComboBox::Undo() |
710 | { | |
711 | // TODO | |
712 | } | |
713 | ||
714 | void wxComboBox::Redo() | |
715 | { | |
716 | // TODO | |
717 | } | |
718 | ||
719 | void wxComboBox::SelectAll() | |
720 | { | |
4e324a3f | 721 | SetSelection(0, GetLastPosition()); |
150e31d2 JS |
722 | } |
723 | ||
724 | bool wxComboBox::CanUndo() const | |
725 | { | |
726 | // TODO | |
727 | return false; | |
728 | } | |
729 | ||
730 | bool wxComboBox::CanRedo() const | |
731 | { | |
732 | // TODO | |
733 | return false; | |
734 | } | |
735 | ||
736 | bool wxComboBox::HasSelection() const | |
737 | { | |
738 | long from, to; | |
739 | GetSelection(&from, &to); | |
740 | return from != to; | |
741 | } | |
742 | ||
743 | bool wxComboBox::CanCopy() const | |
744 | { | |
745 | // Can copy if there's a selection | |
746 | return HasSelection(); | |
747 | } | |
748 | ||
749 | bool wxComboBox::CanCut() const | |
750 | { | |
751 | return CanCopy() && IsEditable(); | |
752 | } | |
753 | ||
754 | bool wxComboBox::CanPaste() const | |
755 | { | |
756 | // TODO: check for text on the clipboard | |
757 | return IsEditable() ; | |
758 | } | |
759 | ||
760 | bool wxComboBox::IsEditable() const | |
761 | { | |
762 | return !HasFlag(wxCB_READONLY); | |
763 | } | |
764 | ||
765 | ||
debe6624 | 766 | void wxComboBox::SetInsertionPoint( long pos ) |
53010e52 | 767 | { |
223d09f6 | 768 | wxCHECK_RET( m_widget != NULL, wxT("invalid combobox") ); |
805dd538 | 769 | |
6f6f938f VZ |
770 | if ( pos == GetLastPosition() ) |
771 | pos = -1; | |
772 | ||
fd0eed64 | 773 | GtkWidget *entry = GTK_COMBO(m_widget)->entry; |
073c8fe9 | 774 | gtk_entry_set_position( GTK_ENTRY(entry), (int)pos ); |
6de97a3b | 775 | } |
53010e52 | 776 | |
fd0eed64 | 777 | long wxComboBox::GetInsertionPoint() const |
53010e52 | 778 | { |
9e691f46 | 779 | return (long) GET_EDITABLE_POS( GTK_COMBO(m_widget)->entry ); |
6de97a3b | 780 | } |
53010e52 | 781 | |
7d8268a1 | 782 | wxTextPos wxComboBox::GetLastPosition() const |
53010e52 | 783 | { |
fd0eed64 RR |
784 | GtkWidget *entry = GTK_COMBO(m_widget)->entry; |
785 | int pos = GTK_ENTRY(entry)->text_length; | |
786 | return (long) pos-1; | |
6de97a3b | 787 | } |
53010e52 | 788 | |
debe6624 | 789 | void wxComboBox::Replace( long from, long to, const wxString& value ) |
53010e52 | 790 | { |
223d09f6 | 791 | wxCHECK_RET( m_widget != NULL, wxT("invalid combobox") ); |
805dd538 | 792 | |
fd0eed64 RR |
793 | GtkWidget *entry = GTK_COMBO(m_widget)->entry; |
794 | gtk_editable_delete_text( GTK_EDITABLE(entry), (gint)from, (gint)to ); | |
795 | if (value.IsNull()) return; | |
796 | gint pos = (gint)to; | |
30ed6e5c | 797 | |
2e1d7104 RR |
798 | #if wxUSE_UNICODE |
799 | wxCharBuffer buffer = wxConvUTF8.cWX2MB( value ); | |
800 | gtk_editable_insert_text( GTK_EDITABLE(entry), (const char*) buffer, strlen( (const char*) buffer ), &pos ); | |
801 | #else | |
8228b893 | 802 | gtk_editable_insert_text( GTK_EDITABLE(entry), value.c_str(), value.length(), &pos ); |
2e1d7104 | 803 | #endif |
6de97a3b | 804 | } |
53010e52 | 805 | |
20d10ee1 | 806 | void wxComboBox::SetSelection( long from, long to ) |
53010e52 | 807 | { |
20d10ee1 VZ |
808 | GtkWidget *entry = GTK_COMBO(m_widget)->entry; |
809 | gtk_editable_select_region( GTK_EDITABLE(entry), (gint)from, (gint)to ); | |
6de97a3b | 810 | } |
53010e52 | 811 | |
150e31d2 JS |
812 | void wxComboBox::GetSelection( long* from, long* to ) const |
813 | { | |
814 | if (IsEditable()) | |
815 | { | |
816 | GtkEditable *editable = GTK_EDITABLE(GTK_COMBO(m_widget)->entry); | |
817 | *from = (long) editable->selection_start_pos; | |
818 | *to = (long) editable->selection_end_pos; | |
819 | } | |
820 | } | |
821 | ||
20d10ee1 | 822 | void wxComboBox::SetEditable( bool editable ) |
53010e52 | 823 | { |
20d10ee1 VZ |
824 | GtkWidget *entry = GTK_COMBO(m_widget)->entry; |
825 | gtk_entry_set_editable( GTK_ENTRY(entry), editable ); | |
b4071e91 RR |
826 | } |
827 | ||
8a85884a VZ |
828 | void wxComboBox::OnChar( wxKeyEvent &event ) |
829 | { | |
12a3f227 | 830 | if ( event.GetKeyCode() == WXK_RETURN ) |
8a85884a | 831 | { |
461573cc | 832 | // GTK automatically selects an item if its in the list |
17a1ebd1 VZ |
833 | wxCommandEvent eventEnter(wxEVT_COMMAND_TEXT_ENTER, GetId()); |
834 | eventEnter.SetString( GetValue() ); | |
835 | eventEnter.SetInt( GetSelection() ); | |
836 | eventEnter.SetEventObject( this ); | |
3352cfff | 837 | |
17a1ebd1 | 838 | if (!GetEventHandler()->ProcessEvent( eventEnter )) |
3352cfff RR |
839 | { |
840 | // This will invoke the dialog default action, such | |
841 | // as the clicking the default button. | |
842 | ||
843 | wxWindow *top_frame = m_parent; | |
844 | while (top_frame->GetParent() && !(top_frame->IsTopLevel())) | |
845 | top_frame = top_frame->GetParent(); | |
846 | ||
847 | if (top_frame && GTK_IS_WINDOW(top_frame->m_widget)) | |
848 | { | |
849 | GtkWindow *window = GTK_WINDOW(top_frame->m_widget); | |
850 | ||
851 | if (window->default_widget) | |
150e31d2 | 852 | gtk_widget_activate (window->default_widget); |
3352cfff RR |
853 | } |
854 | } | |
30ed6e5c | 855 | |
461573cc RR |
856 | // Catch GTK event so that GTK doesn't open the drop |
857 | // down list upon RETURN. | |
0878fb4c | 858 | return; |
8a85884a | 859 | } |
30ed6e5c | 860 | |
7cf8cb48 | 861 | event.Skip(); |
8a85884a VZ |
862 | } |
863 | ||
953704c1 RR |
864 | void wxComboBox::DisableEvents() |
865 | { | |
461573cc RR |
866 | gtk_signal_disconnect_by_func( GTK_OBJECT(GTK_COMBO(m_widget)->list), |
867 | GTK_SIGNAL_FUNC(gtk_combo_select_child_callback), (gpointer)this ); | |
868 | gtk_signal_disconnect_by_func( GTK_OBJECT(GTK_COMBO(m_widget)->entry), | |
869 | GTK_SIGNAL_FUNC(gtk_text_changed_callback), (gpointer)this ); | |
953704c1 RR |
870 | } |
871 | ||
872 | void wxComboBox::EnableEvents() | |
873 | { | |
58b907f6 | 874 | gtk_signal_connect_after( GTK_OBJECT(GTK_COMBO(m_widget)->list), "select-child", |
461573cc | 875 | GTK_SIGNAL_FUNC(gtk_combo_select_child_callback), (gpointer)this ); |
58b907f6 | 876 | gtk_signal_connect_after( GTK_OBJECT(GTK_COMBO(m_widget)->entry), "changed", |
461573cc | 877 | GTK_SIGNAL_FUNC(gtk_text_changed_callback), (gpointer)this ); |
953704c1 RR |
878 | } |
879 | ||
b4071e91 RR |
880 | void wxComboBox::OnSize( wxSizeEvent &event ) |
881 | { | |
260a67b7 VS |
882 | // NB: In some situations (e.g. on non-first page of a wizard, if the |
883 | // size used is default size), GtkCombo widget is resized correctly, | |
884 | // but it's look is not updated, it's rendered as if it was much wider. | |
885 | // No other widgets are affected, so it looks like a bug in GTK+. | |
886 | // Manually requesting resize calculation (as gtk_pizza_set_size does) | |
887 | // fixes it. | |
888 | if (GTK_WIDGET_VISIBLE(m_widget)) | |
889 | gtk_widget_queue_resize(m_widget); | |
890 | ||
f03fc89f | 891 | event.Skip(); |
6de97a3b | 892 | } |
53010e52 | 893 | |
f40fdaa3 | 894 | void wxComboBox::DoApplyWidgetStyle(GtkRcStyle *style) |
868a2826 | 895 | { |
f40fdaa3 | 896 | // gtk_widget_modify_style( GTK_COMBO(m_widget)->button, syle ); |
ea2d542c | 897 | |
f40fdaa3 VS |
898 | gtk_widget_modify_style( GTK_COMBO(m_widget)->entry, style ); |
899 | gtk_widget_modify_style( GTK_COMBO(m_widget)->list, style ); | |
805dd538 | 900 | |
fd0eed64 RR |
901 | GtkList *list = GTK_LIST( GTK_COMBO(m_widget)->list ); |
902 | GList *child = list->children; | |
903 | while (child) | |
904 | { | |
f40fdaa3 | 905 | gtk_widget_modify_style( GTK_WIDGET(child->data), style ); |
805dd538 | 906 | |
fd0eed64 | 907 | GtkBin *bin = GTK_BIN(child->data); |
f40fdaa3 | 908 | gtk_widget_modify_style( bin->child, style ); |
805dd538 | 909 | |
fd0eed64 RR |
910 | child = child->next; |
911 | } | |
868a2826 | 912 | } |
b4071e91 | 913 | |
fd0eed64 | 914 | GtkWidget* wxComboBox::GetConnectWidget() |
97b3455a | 915 | { |
fd0eed64 | 916 | return GTK_COMBO(m_widget)->entry; |
97b3455a RR |
917 | } |
918 | ||
b4071e91 RR |
919 | bool wxComboBox::IsOwnGtkWindow( GdkWindow *window ) |
920 | { | |
fd0eed64 RR |
921 | return ( (window == GTK_ENTRY( GTK_COMBO(m_widget)->entry )->text_area) || |
922 | (window == GTK_COMBO(m_widget)->button->window ) ); | |
b4071e91 | 923 | } |
ac57418f | 924 | |
f68586e5 VZ |
925 | wxSize wxComboBox::DoGetBestSize() const |
926 | { | |
db434467 | 927 | wxSize ret( wxControl::DoGetBestSize() ); |
a6fc8ae3 VZ |
928 | |
929 | // we know better our horizontal extent: it depends on the longest string | |
930 | // in the combobox | |
a6fc8ae3 VZ |
931 | if ( m_widget ) |
932 | { | |
60d85ccb | 933 | int width; |
aa61d352 VZ |
934 | unsigned int count = GetCount(); |
935 | for ( unsigned int n = 0; n < count; n++ ) | |
a6fc8ae3 | 936 | { |
aa61d352 | 937 | GetTextExtent(GetString(n), &width, NULL, NULL, NULL ); |
a6fc8ae3 VZ |
938 | if ( width > ret.x ) |
939 | ret.x = width; | |
940 | } | |
941 | } | |
942 | ||
943 | // empty combobox should have some reasonable default size too | |
944 | if ( ret.x < 100 ) | |
945 | ret.x = 100; | |
9f884528 RD |
946 | |
947 | CacheBestSize(ret); | |
db434467 | 948 | return ret; |
f68586e5 VZ |
949 | } |
950 | ||
9d522606 RD |
951 | // static |
952 | wxVisualAttributes | |
953 | wxComboBox::GetClassDefaultAttributes(wxWindowVariant WXUNUSED(variant)) | |
954 | { | |
955 | return GetDefaultAttributesFromGTKWidget(gtk_combo_new, true); | |
956 | } | |
957 | ||
150e31d2 JS |
958 | // ---------------------------------------------------------------------------- |
959 | // standard event handling | |
960 | // ---------------------------------------------------------------------------- | |
961 | ||
962 | void wxComboBox::OnCut(wxCommandEvent& WXUNUSED(event)) | |
963 | { | |
964 | Cut(); | |
965 | } | |
966 | ||
967 | void wxComboBox::OnCopy(wxCommandEvent& WXUNUSED(event)) | |
968 | { | |
969 | Copy(); | |
970 | } | |
971 | ||
972 | void wxComboBox::OnPaste(wxCommandEvent& WXUNUSED(event)) | |
973 | { | |
974 | Paste(); | |
975 | } | |
976 | ||
977 | void wxComboBox::OnUndo(wxCommandEvent& WXUNUSED(event)) | |
978 | { | |
979 | Undo(); | |
980 | } | |
981 | ||
982 | void wxComboBox::OnRedo(wxCommandEvent& WXUNUSED(event)) | |
983 | { | |
984 | Redo(); | |
985 | } | |
986 | ||
987 | void wxComboBox::OnDelete(wxCommandEvent& WXUNUSED(event)) | |
988 | { | |
989 | long from, to; | |
990 | GetSelection(& from, & to); | |
991 | if (from != -1 && to != -1) | |
992 | Remove(from, to); | |
993 | } | |
994 | ||
995 | void wxComboBox::OnSelectAll(wxCommandEvent& WXUNUSED(event)) | |
996 | { | |
997 | SetSelection(-1, -1); | |
998 | } | |
999 | ||
1000 | void wxComboBox::OnUpdateCut(wxUpdateUIEvent& event) | |
1001 | { | |
1002 | event.Enable( CanCut() ); | |
1003 | } | |
1004 | ||
1005 | void wxComboBox::OnUpdateCopy(wxUpdateUIEvent& event) | |
1006 | { | |
1007 | event.Enable( CanCopy() ); | |
1008 | } | |
1009 | ||
1010 | void wxComboBox::OnUpdatePaste(wxUpdateUIEvent& event) | |
1011 | { | |
1012 | event.Enable( CanPaste() ); | |
1013 | } | |
1014 | ||
1015 | void wxComboBox::OnUpdateUndo(wxUpdateUIEvent& event) | |
1016 | { | |
1017 | event.Enable( CanUndo() ); | |
1018 | } | |
1019 | ||
1020 | void wxComboBox::OnUpdateRedo(wxUpdateUIEvent& event) | |
1021 | { | |
1022 | event.Enable( CanRedo() ); | |
1023 | } | |
1024 | ||
1025 | void wxComboBox::OnUpdateDelete(wxUpdateUIEvent& event) | |
1026 | { | |
1027 | event.Enable(HasSelection() && IsEditable()) ; | |
1028 | } | |
1029 | ||
1030 | void wxComboBox::OnUpdateSelectAll(wxUpdateUIEvent& event) | |
1031 | { | |
1032 | event.Enable(GetLastPosition() > 0); | |
1033 | } | |
1034 | ||
dcf924a3 | 1035 | #endif |