]>
Commit | Line | Data |
---|---|---|
53010e52 | 1 | ///////////////////////////////////////////////////////////////////////////// |
11e62fe6 | 2 | // Name: src/gtk/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 |
aaa6d89a | 21 | #include "wx/arrstr.h" |
88a7a4e1 WS |
22 | #endif |
23 | ||
1efb5db8 MR |
24 | // We use GtkCombo which has been deprecated since GTK+ 2.3.0 |
25 | // in favour of GtkComboBox for <GTK2.4 runtime | |
5b008dd7 MR |
26 | // We also use GtkList |
27 | #ifdef GTK_DISABLE_DEPRECATED | |
1efb5db8 MR |
28 | #undef GTK_DISABLE_DEPRECATED |
29 | #endif | |
9e691f46 | 30 | #include "wx/gtk/private.h" |
83624f79 | 31 | |
47908e25 RR |
32 | //----------------------------------------------------------------------------- |
33 | // data | |
34 | //----------------------------------------------------------------------------- | |
35 | ||
36 | extern bool g_blockEventsOnDrag; | |
40eb3606 VZ |
37 | static int g_SelectionBeforePopup = wxID_NONE; // this means the popup is hidden |
38 | ||
78b3b018 RR |
39 | //----------------------------------------------------------------------------- |
40 | // "changed" - typing and list item matches get changed, select-child | |
41 | // if it doesn't match an item then just get a single changed | |
42 | //----------------------------------------------------------------------------- | |
43 | ||
865bb325 | 44 | extern "C" { |
78b3b018 | 45 | static void |
1fb33bdb | 46 | gtkcombo_text_changed_callback( GtkWidget *WXUNUSED(widget), wxComboBox *combo ) |
78b3b018 | 47 | { |
78b3b018 | 48 | if (combo->m_ignoreNextUpdate) |
150e31d2 | 49 | { |
7d8268a1 | 50 | combo->m_ignoreNextUpdate = false; |
78b3b018 RR |
51 | return; |
52 | } | |
53 | ||
54 | if (!combo->m_hasVMT) return; | |
55 | ||
56 | wxCommandEvent event( wxEVT_COMMAND_TEXT_UPDATED, combo->GetId() ); | |
57 | event.SetString( combo->GetValue() ); | |
58 | event.SetEventObject( combo ); | |
59 | combo->GetEventHandler()->ProcessEvent( event ); | |
60 | } | |
865bb325 | 61 | } |
78b3b018 | 62 | |
865bb325 | 63 | extern "C" { |
78b3b018 | 64 | static void |
1fb33bdb | 65 | gtkcombo_dummy_callback(GtkEntry *WXUNUSED(entry), GtkCombo *WXUNUSED(combo)) |
78b3b018 RR |
66 | { |
67 | } | |
865bb325 | 68 | } |
78b3b018 | 69 | |
865bb325 | 70 | extern "C" { |
9d6a9fdd | 71 | static void |
1fb33bdb | 72 | gtkcombo_popup_hide_callback(GtkCombo *WXUNUSED(gtk_combo), wxComboBox *combo) |
7d8268a1 | 73 | { |
9d6a9fdd RR |
74 | // when the popup is hidden, throw a SELECTED event only if the combobox |
75 | // selection changed. | |
3dbfe8f4 VZ |
76 | const int curSelection = combo->GetCurrentSelection(); |
77 | ||
78 | const bool hasChanged = curSelection != g_SelectionBeforePopup; | |
79 | ||
80 | // reset the selection flag to value meaning that it is hidden and do it | |
81 | // now, before generating the events, so that GetSelection() returns the | |
82 | // new value from the event handler | |
83 | g_SelectionBeforePopup = wxID_NONE; | |
84 | ||
85 | if ( hasChanged ) | |
9d6a9fdd RR |
86 | { |
87 | wxCommandEvent event( wxEVT_COMMAND_COMBOBOX_SELECTED, combo->GetId() ); | |
88 | event.SetInt( curSelection ); | |
89 | event.SetString( combo->GetStringSelection() ); | |
90 | event.SetEventObject( combo ); | |
91 | combo->GetEventHandler()->ProcessEvent( event ); | |
345bdf13 KH |
92 | |
93 | // for consistency with the other ports, send TEXT event | |
94 | wxCommandEvent event2( wxEVT_COMMAND_TEXT_UPDATED, combo->GetId() ); | |
95 | event2.SetString( combo->GetStringSelection() ); | |
96 | event2.SetEventObject( combo ); | |
97 | combo->GetEventHandler()->ProcessEvent( event2 ); | |
9d6a9fdd | 98 | } |
9d6a9fdd | 99 | } |
865bb325 | 100 | } |
9d6a9fdd | 101 | |
865bb325 | 102 | extern "C" { |
9d6a9fdd | 103 | static void |
1fb33bdb | 104 | gtkcombo_popup_show_callback(GtkCombo *WXUNUSED(gtk_combo), wxComboBox *combo) |
9d6a9fdd RR |
105 | { |
106 | // store the combobox selection value before the popup is shown | |
40eb3606 | 107 | g_SelectionBeforePopup = combo->GetCurrentSelection(); |
9d6a9fdd | 108 | } |
865bb325 | 109 | } |
9d6a9fdd | 110 | |
53010e52 | 111 | //----------------------------------------------------------------------------- |
461573cc | 112 | // "select-child" - click/cursor get select-child, changed, select-child |
47908e25 | 113 | //----------------------------------------------------------------------------- |
47908e25 | 114 | |
865bb325 | 115 | extern "C" { |
8a85884a | 116 | static void |
1fb33bdb | 117 | gtkcombo_combo_select_child_callback( GtkList *WXUNUSED(list), GtkWidget *WXUNUSED(widget), wxComboBox *combo ) |
53010e52 | 118 | { |
a2053b27 | 119 | if (!combo->m_hasVMT) return; |
30ed6e5c | 120 | |
acfd422a | 121 | if (g_blockEventsOnDrag) return; |
805dd538 | 122 | |
40eb3606 | 123 | int curSelection = combo->GetCurrentSelection(); |
30ed6e5c | 124 | |
3c4e4af6 RR |
125 | if (combo->m_prevSelection == curSelection) return; |
126 | ||
127 | GtkWidget *list = GTK_COMBO(combo->m_widget)->list; | |
128 | gtk_list_unselect_item( GTK_LIST(list), combo->m_prevSelection ); | |
150e31d2 | 129 | |
159b66c0 RR |
130 | combo->m_prevSelection = curSelection; |
131 | ||
78b3b018 RR |
132 | // Quickly set the value of the combo box |
133 | // as GTK+ does that only AFTER the event | |
134 | // is sent. | |
9fa72bd2 | 135 | g_signal_handlers_disconnect_by_func (GTK_COMBO (combo->GetHandle())->entry, |
1fb33bdb | 136 | (gpointer) gtkcombo_text_changed_callback, |
9fa72bd2 | 137 | combo); |
78b3b018 | 138 | combo->SetValue( combo->GetStringSelection() ); |
9fa72bd2 | 139 | g_signal_connect_after (GTK_COMBO (combo->GetHandle())->entry, "changed", |
1fb33bdb | 140 | G_CALLBACK (gtkcombo_text_changed_callback), combo); |
78b3b018 | 141 | |
40eb3606 | 142 | // throw a SELECTED event only if the combobox popup is hidden (wxID_NONE) |
1fb33bdb | 143 | // because when combobox popup is shown, gtkcombo_combo_select_child_callback is |
9d6a9fdd RR |
144 | // called each times the mouse is over an item with a pressed button so a lot |
145 | // of SELECTED event could be generated if the user keep the mouse button down | |
146 | // and select other items ... | |
40eb3606 | 147 | if (g_SelectionBeforePopup == wxID_NONE) |
9d6a9fdd RR |
148 | { |
149 | wxCommandEvent event( wxEVT_COMMAND_COMBOBOX_SELECTED, combo->GetId() ); | |
150 | event.SetInt( curSelection ); | |
151 | event.SetString( combo->GetStringSelection() ); | |
152 | event.SetEventObject( combo ); | |
153 | combo->GetEventHandler()->ProcessEvent( event ); | |
0c77152e | 154 | |
345bdf13 | 155 | // for consistency with the other ports, don't generate text update |
40eb3606 VZ |
156 | // events while the user is browsing the combobox neither |
157 | wxCommandEvent event2( wxEVT_COMMAND_TEXT_UPDATED, combo->GetId() ); | |
158 | event2.SetString( combo->GetValue() ); | |
159 | event2.SetEventObject( combo ); | |
160 | combo->GetEventHandler()->ProcessEvent( event2 ); | |
161 | } | |
461573cc | 162 | } |
865bb325 | 163 | } |
461573cc | 164 | |
590f50d6 RR |
165 | #ifdef __WXGTK24__ |
166 | extern "C" { | |
167 | static void | |
168 | gtkcombobox_text_changed_callback( GtkWidget *WXUNUSED(widget), wxComboBox *combo ) | |
169 | { | |
590f50d6 RR |
170 | if (!combo->m_hasVMT) return; |
171 | ||
172 | wxCommandEvent event( wxEVT_COMMAND_TEXT_UPDATED, combo->GetId() ); | |
173 | event.SetString( combo->GetValue() ); | |
174 | event.SetEventObject( combo ); | |
175 | combo->GetEventHandler()->ProcessEvent( event ); | |
176 | } | |
177 | } | |
178 | ||
179 | extern "C" { | |
180 | static void | |
181 | gtkcombobox_changed_callback( GtkWidget *WXUNUSED(widget), wxComboBox *combo ) | |
182 | { | |
590f50d6 | 183 | if (!combo->m_hasVMT) return; |
ddd53873 RR |
184 | |
185 | if (combo->GetSelection() == -1) | |
186 | return; | |
590f50d6 RR |
187 | |
188 | wxCommandEvent event( wxEVT_COMMAND_COMBOBOX_SELECTED, combo->GetId() ); | |
189 | event.SetInt( combo->GetSelection() ); | |
190 | event.SetString( combo->GetStringSelection() ); | |
191 | event.SetEventObject( combo ); | |
192 | combo->GetEventHandler()->ProcessEvent( event ); | |
193 | } | |
194 | } | |
a73ae836 | 195 | |
590f50d6 RR |
196 | #endif |
197 | ||
e1e955e1 RR |
198 | //----------------------------------------------------------------------------- |
199 | // wxComboBox | |
53010e52 RR |
200 | //----------------------------------------------------------------------------- |
201 | ||
202 | IMPLEMENT_DYNAMIC_CLASS(wxComboBox,wxControl) | |
203 | ||
b4071e91 | 204 | BEGIN_EVENT_TABLE(wxComboBox, wxControl) |
fd0eed64 | 205 | EVT_SIZE(wxComboBox::OnSize) |
8a85884a | 206 | EVT_CHAR(wxComboBox::OnChar) |
150e31d2 JS |
207 | |
208 | EVT_MENU(wxID_CUT, wxComboBox::OnCut) | |
209 | EVT_MENU(wxID_COPY, wxComboBox::OnCopy) | |
210 | EVT_MENU(wxID_PASTE, wxComboBox::OnPaste) | |
211 | EVT_MENU(wxID_UNDO, wxComboBox::OnUndo) | |
212 | EVT_MENU(wxID_REDO, wxComboBox::OnRedo) | |
213 | EVT_MENU(wxID_CLEAR, wxComboBox::OnDelete) | |
214 | EVT_MENU(wxID_SELECTALL, wxComboBox::OnSelectAll) | |
215 | ||
216 | EVT_UPDATE_UI(wxID_CUT, wxComboBox::OnUpdateCut) | |
217 | EVT_UPDATE_UI(wxID_COPY, wxComboBox::OnUpdateCopy) | |
218 | EVT_UPDATE_UI(wxID_PASTE, wxComboBox::OnUpdatePaste) | |
219 | EVT_UPDATE_UI(wxID_UNDO, wxComboBox::OnUpdateUndo) | |
220 | EVT_UPDATE_UI(wxID_REDO, wxComboBox::OnUpdateRedo) | |
221 | EVT_UPDATE_UI(wxID_CLEAR, wxComboBox::OnUpdateDelete) | |
222 | EVT_UPDATE_UI(wxID_SELECTALL, wxComboBox::OnUpdateSelectAll) | |
b4071e91 RR |
223 | END_EVENT_TABLE() |
224 | ||
584ad2a3 MB |
225 | bool wxComboBox::Create( wxWindow *parent, wxWindowID id, |
226 | const wxString& value, | |
227 | const wxPoint& pos, const wxSize& size, | |
228 | const wxArrayString& choices, | |
229 | long style, const wxValidator& validator, | |
230 | const wxString& name ) | |
231 | { | |
232 | wxCArrayString chs(choices); | |
233 | ||
234 | return Create( parent, id, value, pos, size, chs.GetCount(), | |
235 | chs.GetStrings(), style, validator, name ); | |
236 | } | |
237 | ||
fd0eed64 RR |
238 | bool wxComboBox::Create( wxWindow *parent, wxWindowID id, const wxString& value, |
239 | const wxPoint& pos, const wxSize& size, | |
240 | int n, const wxString choices[], | |
805dd538 VZ |
241 | long style, const wxValidator& validator, |
242 | const wxString& name ) | |
53010e52 | 243 | { |
7d8268a1 | 244 | m_ignoreNextUpdate = false; |
159b66c0 | 245 | m_prevSelection = 0; |
805dd538 | 246 | |
db434467 | 247 | if (!PreCreation( parent, pos, size ) || |
4dcaf11a RR |
248 | !CreateBase( parent, id, pos, size, style, validator, name )) |
249 | { | |
223d09f6 | 250 | wxFAIL_MSG( wxT("wxComboBox creation failed") ); |
7d8268a1 | 251 | return false; |
4dcaf11a | 252 | } |
6de97a3b | 253 | |
590f50d6 RR |
254 | #ifdef __WXGTK24__ |
255 | if (!gtk_check_version(2,4,0)) | |
256 | { | |
257 | m_widget = gtk_combo_box_entry_new_text(); | |
258 | GtkComboBox* combobox = GTK_COMBO_BOX( m_widget ); | |
8228b893 | 259 | |
590f50d6 | 260 | gtk_entry_set_editable( GTK_ENTRY( GTK_BIN(m_widget)->child ), TRUE ); |
8228b893 | 261 | |
590f50d6 RR |
262 | for (int i = 0; i < n; i++) |
263 | { | |
264 | gtk_combo_box_append_text( combobox, wxGTK_CONV( choices[i] ) ); | |
30ed6e5c | 265 | |
590f50d6 RR |
266 | m_clientDataList.Append( (wxObject*)NULL ); |
267 | m_clientObjectList.Append( (wxObject*)NULL ); | |
268 | } | |
269 | } | |
270 | else | |
271 | #endif | |
272 | { | |
273 | m_widget = gtk_combo_new(); | |
274 | GtkCombo* combo = GTK_COMBO(m_widget); | |
8228b893 | 275 | |
590f50d6 RR |
276 | // Disable GTK's broken events ... |
277 | g_signal_handler_disconnect (combo->entry, combo->entry_change_id); | |
278 | // ... and add surrogate handler. | |
279 | combo->entry_change_id = g_signal_connect (combo->entry, "changed", | |
1fb33bdb | 280 | G_CALLBACK (gtkcombo_dummy_callback), |
9fa72bd2 | 281 | combo); |
805dd538 | 282 | |
590f50d6 RR |
283 | // make it more useable |
284 | gtk_combo_set_use_arrows_always( GTK_COMBO(m_widget), TRUE ); | |
30ed6e5c | 285 | |
590f50d6 RR |
286 | // and case-sensitive |
287 | gtk_combo_set_case_sensitive( GTK_COMBO(m_widget), TRUE ); | |
3ca6a5f0 | 288 | |
590f50d6 | 289 | if (style & wxNO_BORDER) |
7d1fea10 | 290 | g_object_set (combo->entry, "has-frame", FALSE, NULL ); |
8228b893 | 291 | |
590f50d6 | 292 | GtkWidget *list = combo->list; |
7d8268a1 | 293 | |
590f50d6 RR |
294 | for (int i = 0; i < n; i++) |
295 | { | |
296 | GtkWidget *list_item = gtk_list_item_new_with_label( wxGTK_CONV( choices[i] ) ); | |
805dd538 | 297 | |
590f50d6 RR |
298 | m_clientDataList.Append( (wxObject*)NULL ); |
299 | m_clientObjectList.Append( (wxObject*)NULL ); | |
805dd538 | 300 | |
590f50d6 | 301 | gtk_container_add( GTK_CONTAINER(list), list_item ); |
805dd538 | 302 | |
590f50d6 RR |
303 | gtk_widget_show( list_item ); |
304 | } | |
fd0eed64 | 305 | } |
805dd538 | 306 | |
590f50d6 | 307 | |
f03fc89f | 308 | m_parent->DoAddChild( this ); |
30ed6e5c | 309 | |
590f50d6 RR |
310 | GtkEntry *entry = NULL; |
311 | #ifdef __WXGTK24__ | |
312 | if (!gtk_check_version(2,4,0)) | |
313 | entry = GTK_ENTRY( GTK_BIN(m_widget)->child ); | |
314 | else | |
8228b893 | 315 | #endif |
590f50d6 | 316 | entry = GTK_ENTRY( GTK_COMBO(m_widget)->entry ); |
8228b893 | 317 | |
590f50d6 | 318 | m_focusWidget = GTK_WIDGET( entry ); |
805dd538 | 319 | |
abdeb9e7 | 320 | PostCreation(size); |
53010e52 | 321 | |
590f50d6 RR |
322 | #ifdef __WXGTK24__ |
323 | if (!gtk_check_version(2,4,0)) | |
324 | ConnectWidget( m_widget ); | |
325 | else | |
326 | #endif | |
327 | ConnectWidget( GTK_COMBO(m_widget)->button ); | |
805dd538 | 328 | |
590f50d6 RR |
329 | #ifdef __WXGTK24__ |
330 | if (!gtk_check_version(2,4,0)) | |
331 | { | |
332 | gtk_entry_set_text( entry, wxGTK_CONV(value) ); | |
8228b893 | 333 | |
590f50d6 RR |
334 | if (style & wxCB_READONLY) |
335 | gtk_entry_set_editable( entry, FALSE ); | |
8228b893 | 336 | |
590f50d6 RR |
337 | g_signal_connect_after (entry, "changed", |
338 | G_CALLBACK (gtkcombobox_text_changed_callback), this); | |
8228b893 | 339 | |
590f50d6 RR |
340 | g_signal_connect_after (m_widget, "changed", |
341 | G_CALLBACK (gtkcombobox_changed_callback), this); | |
f4322df6 | 342 | |
590f50d6 RR |
343 | } |
344 | else | |
345 | #endif | |
346 | { | |
347 | GtkCombo *combo = GTK_COMBO(m_widget); | |
348 | // MSW's combo box shows the value and the selection is -1 | |
349 | gtk_entry_set_text( entry, wxGTK_CONV(value) ); | |
350 | gtk_list_unselect_all( GTK_LIST(combo->list) ); | |
805dd538 | 351 | |
590f50d6 RR |
352 | if (style & wxCB_READONLY) |
353 | gtk_entry_set_editable( entry, FALSE ); | |
a260fe6a | 354 | |
590f50d6 RR |
355 | // "show" and "hide" events are generated when user click on the combobox button which popups a list |
356 | // this list is the "popwin" gtk widget | |
357 | g_signal_connect (GTK_COMBO(combo)->popwin, "hide", | |
1fb33bdb | 358 | G_CALLBACK (gtkcombo_popup_hide_callback), this); |
590f50d6 | 359 | g_signal_connect (GTK_COMBO(combo)->popwin, "show", |
1fb33bdb | 360 | G_CALLBACK (gtkcombo_popup_show_callback), this); |
590f50d6 | 361 | g_signal_connect_after (combo->list, "select-child", |
1fb33bdb | 362 | G_CALLBACK (gtkcombo_combo_select_child_callback), |
9fa72bd2 | 363 | this); |
590f50d6 RR |
364 | g_signal_connect_after (entry, "changed", |
365 | G_CALLBACK (gtkcombo_text_changed_callback), this); | |
590f50d6 | 366 | } |
805dd538 | 367 | |
170acdc9 | 368 | SetInitialSize(size); // need this too because this is a wxControlWithItems |
805dd538 | 369 | |
7d8268a1 | 370 | return true; |
fd0eed64 RR |
371 | } |
372 | ||
373 | wxComboBox::~wxComboBox() | |
374 | { | |
222ed1d6 | 375 | wxList::compatibility_iterator node = m_clientObjectList.GetFirst(); |
fd0eed64 RR |
376 | while (node) |
377 | { | |
b1d4dd7a | 378 | wxClientData *cd = (wxClientData*)node->GetData(); |
fd0eed64 | 379 | if (cd) delete cd; |
b1d4dd7a | 380 | node = node->GetNext(); |
fd0eed64 | 381 | } |
7d6d2cd4 RR |
382 | m_clientObjectList.Clear(); |
383 | ||
fd0eed64 | 384 | m_clientDataList.Clear(); |
6de97a3b | 385 | } |
53010e52 | 386 | |
2b5f62a0 VZ |
387 | void wxComboBox::SetFocus() |
388 | { | |
389 | if ( m_hasFocus ) | |
390 | { | |
391 | // don't do anything if we already have focus | |
392 | return; | |
393 | } | |
394 | ||
395 | gtk_widget_grab_focus( m_focusWidget ); | |
396 | } | |
397 | ||
6f6f938f | 398 | int wxComboBox::DoAppend( const wxString &item ) |
53010e52 | 399 | { |
2a68b7a0 | 400 | wxCHECK_MSG( m_widget != NULL, -1, wxT("invalid combobox") ); |
805dd538 | 401 | |
590f50d6 RR |
402 | #ifdef __WXGTK24__ |
403 | if (!gtk_check_version(2,4,0)) | |
404 | { | |
405 | GtkComboBox* combobox = GTK_COMBO_BOX( m_widget ); | |
406 | gtk_combo_box_append_text( combobox, wxGTK_CONV( item ) ); | |
407 | } | |
408 | else | |
409 | #endif | |
410 | { | |
411 | DisableEvents(); | |
805dd538 | 412 | |
590f50d6 RR |
413 | GtkWidget *list = GTK_COMBO(m_widget)->list; |
414 | GtkWidget *list_item = gtk_list_item_new_with_label( wxGTK_CONV( item ) ); | |
805dd538 | 415 | |
590f50d6 | 416 | gtk_container_add( GTK_CONTAINER(list), list_item ); |
ec5d85fb | 417 | |
590f50d6 RR |
418 | if (GTK_WIDGET_REALIZED(m_widget)) |
419 | { | |
420 | gtk_widget_realize( list_item ); | |
421 | gtk_widget_realize( GTK_BIN(list_item)->child ); | |
422 | } | |
2b07d713 | 423 | |
590f50d6 RR |
424 | // Apply current widget style to the new list_item |
425 | GtkRcStyle *style = CreateWidgetStyle(); | |
426 | if (style) | |
427 | { | |
10bd1f7d | 428 | gtk_widget_modify_style(list_item, style); |
590f50d6 | 429 | GtkBin *bin = GTK_BIN( list_item ); |
10bd1f7d | 430 | GtkWidget *label = bin->child; |
590f50d6 RR |
431 | gtk_widget_modify_style( label, style ); |
432 | gtk_rc_style_unref( style ); | |
433 | } | |
805dd538 | 434 | |
590f50d6 | 435 | gtk_widget_show( list_item ); |
30ed6e5c | 436 | |
590f50d6 RR |
437 | EnableEvents(); |
438 | } | |
53010e52 | 439 | |
aa61d352 | 440 | const unsigned int count = GetCount(); |
8228b893 WS |
441 | |
442 | if ( m_clientDataList.GetCount() < count ) | |
0a164d4c | 443 | m_clientDataList.Append( (wxObject*) NULL ); |
8228b893 | 444 | if ( m_clientObjectList.GetCount() < count ) |
0a164d4c | 445 | m_clientObjectList.Append( (wxObject*) NULL ); |
805dd538 | 446 | |
b0021947 VS |
447 | InvalidateBestSize(); |
448 | ||
6f6f938f | 449 | return count - 1; |
fd0eed64 RR |
450 | } |
451 | ||
aa61d352 | 452 | int wxComboBox::DoInsert(const wxString &item, unsigned int pos) |
243dbf1a | 453 | { |
708c45a6 VZ |
454 | wxCHECK_MSG( !(GetWindowStyle() & wxCB_SORT), -1, |
455 | wxT("can't insert into sorted list")); | |
456 | ||
457 | wxCHECK_MSG( m_widget != NULL, -1, wxT("invalid combobox") ); | |
8228b893 | 458 | wxCHECK_MSG( IsValidInsert(pos), -1, wxT("invalid index") ); |
243dbf1a | 459 | |
aa61d352 | 460 | unsigned int count = GetCount(); |
6f6f938f | 461 | |
aa61d352 | 462 | if (pos == count) |
6f6f938f | 463 | return Append(item); |
243dbf1a | 464 | |
590f50d6 RR |
465 | #ifdef __WXGTK24__ |
466 | if (!gtk_check_version(2,4,0)) | |
467 | { | |
468 | GtkComboBox* combobox = GTK_COMBO_BOX( m_widget ); | |
469 | gtk_combo_box_insert_text( combobox, pos, wxGTK_CONV( item ) ); | |
470 | } | |
471 | else | |
472 | #endif | |
473 | { | |
474 | DisableEvents(); | |
243dbf1a | 475 | |
590f50d6 RR |
476 | GtkWidget *list = GTK_COMBO(m_widget)->list; |
477 | GtkWidget *list_item = gtk_list_item_new_with_label( wxGTK_CONV( item ) ); | |
243dbf1a | 478 | |
590f50d6 RR |
479 | GList *gitem_list = g_list_alloc (); |
480 | gitem_list->data = list_item; | |
481 | gtk_list_insert_items( GTK_LIST (list), gitem_list, pos ); | |
243dbf1a | 482 | |
590f50d6 RR |
483 | if (GTK_WIDGET_REALIZED(m_widget)) |
484 | { | |
485 | gtk_widget_realize( list_item ); | |
486 | gtk_widget_realize( GTK_BIN(list_item)->child ); | |
243dbf1a | 487 | |
590f50d6 RR |
488 | ApplyWidgetStyle(); |
489 | } | |
243dbf1a | 490 | |
590f50d6 | 491 | gtk_widget_show( list_item ); |
243dbf1a | 492 | |
590f50d6 RR |
493 | EnableEvents(); |
494 | } | |
8228b893 | 495 | |
6f6f938f | 496 | count = GetCount(); |
243dbf1a | 497 | |
8228b893 | 498 | if ( m_clientDataList.GetCount() < count ) |
0a164d4c | 499 | m_clientDataList.Insert( pos, (wxObject*) NULL ); |
8228b893 | 500 | if ( m_clientObjectList.GetCount() < count ) |
0a164d4c | 501 | m_clientObjectList.Insert( pos, (wxObject*) NULL ); |
243dbf1a | 502 | |
b0021947 | 503 | InvalidateBestSize(); |
243dbf1a | 504 | |
6f6f938f | 505 | return pos; |
243dbf1a VZ |
506 | } |
507 | ||
aa61d352 | 508 | void wxComboBox::DoSetItemClientData(unsigned int n, void* clientData) |
fd0eed64 | 509 | { |
223d09f6 | 510 | wxCHECK_RET( m_widget != NULL, wxT("invalid combobox") ); |
805dd538 | 511 | |
222ed1d6 | 512 | wxList::compatibility_iterator node = m_clientDataList.Item( n ); |
fd0eed64 | 513 | if (!node) return; |
805dd538 | 514 | |
f5e27805 | 515 | node->SetData( (wxObject*) clientData ); |
6de97a3b | 516 | } |
53010e52 | 517 | |
aa61d352 | 518 | void* wxComboBox::DoGetItemClientData(unsigned int n) const |
53010e52 | 519 | { |
223d09f6 | 520 | wxCHECK_MSG( m_widget != NULL, NULL, wxT("invalid combobox") ); |
805dd538 | 521 | |
222ed1d6 | 522 | wxList::compatibility_iterator node = m_clientDataList.Item( n ); |
805dd538 | 523 | |
30ed6e5c | 524 | return node ? node->GetData() : NULL; |
fd0eed64 RR |
525 | } |
526 | ||
aa61d352 | 527 | void wxComboBox::DoSetItemClientObject(unsigned int n, wxClientData* clientData) |
fd0eed64 | 528 | { |
223d09f6 | 529 | wxCHECK_RET( m_widget != NULL, wxT("invalid combobox") ); |
805dd538 | 530 | |
222ed1d6 | 531 | wxList::compatibility_iterator node = m_clientObjectList.Item( n ); |
fd0eed64 | 532 | if (!node) return; |
805dd538 | 533 | |
e94e2e95 | 534 | // wxItemContainer already deletes data for us |
805dd538 | 535 | |
fd0eed64 | 536 | node->SetData( (wxObject*) clientData ); |
6de97a3b | 537 | } |
53010e52 | 538 | |
aa61d352 | 539 | wxClientData* wxComboBox::DoGetItemClientObject(unsigned int n) const |
53010e52 | 540 | { |
223d09f6 | 541 | wxCHECK_MSG( m_widget != NULL, (wxClientData*)NULL, wxT("invalid combobox") ); |
805dd538 | 542 | |
222ed1d6 | 543 | wxList::compatibility_iterator node = m_clientObjectList.Item( n ); |
805dd538 | 544 | |
30ed6e5c | 545 | return node ? (wxClientData*) node->GetData() : NULL; |
fd0eed64 RR |
546 | } |
547 | ||
548 | void wxComboBox::Clear() | |
549 | { | |
223d09f6 | 550 | wxCHECK_RET( m_widget != NULL, wxT("invalid combobox") ); |
805dd538 | 551 | |
461573cc | 552 | DisableEvents(); |
30ed6e5c | 553 | |
590f50d6 RR |
554 | #ifdef __WXGTK24__ |
555 | if (!gtk_check_version(2,4,0)) | |
556 | { | |
557 | GtkComboBox* combobox = GTK_COMBO_BOX( m_widget ); | |
aa61d352 VZ |
558 | const unsigned int count = GetCount(); |
559 | for (unsigned int i = 0; i < count; i++) | |
590f50d6 RR |
560 | gtk_combo_box_remove_text( combobox, 0 ); |
561 | } | |
c1a3ff25 VZ |
562 | else // GTK+ < 2.4.0 |
563 | #endif // __WXGTK24__ | |
590f50d6 RR |
564 | { |
565 | GtkWidget *list = GTK_COMBO(m_widget)->list; | |
566 | gtk_list_clear_items( GTK_LIST(list), 0, GetCount() ); | |
567 | } | |
8228b893 | 568 | |
222ed1d6 | 569 | wxList::compatibility_iterator node = m_clientObjectList.GetFirst(); |
fd0eed64 RR |
570 | while (node) |
571 | { | |
b1d4dd7a | 572 | wxClientData *cd = (wxClientData*)node->GetData(); |
c1a3ff25 | 573 | delete cd; |
b1d4dd7a | 574 | node = node->GetNext(); |
fd0eed64 | 575 | } |
f5e27805 | 576 | m_clientObjectList.Clear(); |
805dd538 | 577 | |
fd0eed64 | 578 | m_clientDataList.Clear(); |
30ed6e5c | 579 | |
461573cc | 580 | EnableEvents(); |
b0021947 VS |
581 | |
582 | InvalidateBestSize(); | |
6de97a3b | 583 | } |
53010e52 | 584 | |
aa61d352 | 585 | void wxComboBox::Delete(unsigned int n) |
53010e52 | 586 | { |
223d09f6 | 587 | wxCHECK_RET( m_widget != NULL, wxT("invalid combobox") ); |
805dd538 | 588 | |
590f50d6 RR |
589 | #ifdef __WXGTK24__ |
590 | if (!gtk_check_version(2,4,0)) | |
fd0eed64 | 591 | { |
8228b893 WS |
592 | wxCHECK_RET( IsValid(n), wxT("invalid index") ); |
593 | ||
590f50d6 RR |
594 | GtkComboBox* combobox = GTK_COMBO_BOX( m_widget ); |
595 | gtk_combo_box_remove_text( combobox, n ); | |
fd0eed64 | 596 | } |
590f50d6 RR |
597 | else |
598 | #endif | |
599 | { | |
600 | GtkList *listbox = GTK_LIST( GTK_COMBO(m_widget)->list ); | |
805dd538 | 601 | |
590f50d6 RR |
602 | GList *child = g_list_nth( listbox->children, n ); |
603 | ||
604 | if (!child) | |
605 | { | |
606 | wxFAIL_MSG(wxT("wrong index")); | |
607 | return; | |
608 | } | |
30ed6e5c | 609 | |
590f50d6 | 610 | DisableEvents(); |
805dd538 | 611 | |
590f50d6 RR |
612 | GList *list = g_list_append( (GList*) NULL, child->data ); |
613 | gtk_list_remove_items( listbox, list ); | |
614 | g_list_free( list ); | |
615 | ||
616 | EnableEvents(); | |
617 | } | |
8228b893 | 618 | |
222ed1d6 | 619 | wxList::compatibility_iterator node = m_clientObjectList.Item( n ); |
f5e27805 | 620 | if (node) |
fd0eed64 | 621 | { |
b1d4dd7a | 622 | wxClientData *cd = (wxClientData*)node->GetData(); |
fd0eed64 | 623 | if (cd) delete cd; |
222ed1d6 | 624 | m_clientObjectList.Erase( node ); |
f5e27805 | 625 | } |
805dd538 | 626 | |
b1d4dd7a | 627 | node = m_clientDataList.Item( n ); |
f5e27805 | 628 | if (node) |
222ed1d6 | 629 | m_clientDataList.Erase( node ); |
150e31d2 | 630 | |
b0021947 | 631 | InvalidateBestSize(); |
461573cc RR |
632 | } |
633 | ||
aa61d352 | 634 | void wxComboBox::SetString(unsigned int n, const wxString &text) |
461573cc RR |
635 | { |
636 | wxCHECK_RET( m_widget != NULL, wxT("invalid combobox") ); | |
637 | ||
590f50d6 RR |
638 | #ifdef __WXGTK24__ |
639 | if (!gtk_check_version(2,4,0)) | |
461573cc | 640 | { |
590f50d6 | 641 | GtkComboBox* combobox = GTK_COMBO_BOX( m_widget ); |
8228b893 WS |
642 | wxCHECK_RET( IsValid(n), wxT("invalid index") ); |
643 | ||
590f50d6 RR |
644 | GtkTreeModel *model = gtk_combo_box_get_model( combobox ); |
645 | GtkTreeIter iter; | |
646 | if (gtk_tree_model_iter_nth_child (model, &iter, NULL, n)) | |
647 | { | |
648 | GValue value = { 0, }; | |
649 | g_value_init( &value, G_TYPE_STRING ); | |
650 | g_value_set_string( &value, wxGTK_CONV( text ) ); | |
651 | gtk_list_store_set_value( GTK_LIST_STORE(model), &iter, 0, &value ); | |
652 | g_value_unset( &value ); | |
653 | } | |
461573cc RR |
654 | } |
655 | else | |
590f50d6 | 656 | #endif |
461573cc | 657 | { |
590f50d6 | 658 | GtkWidget *list = GTK_COMBO(m_widget)->list; |
150e31d2 | 659 | |
590f50d6 RR |
660 | GList *child = g_list_nth( GTK_LIST(list)->children, n ); |
661 | if (child) | |
662 | { | |
663 | GtkBin *bin = GTK_BIN( child->data ); | |
664 | GtkLabel *label = GTK_LABEL( bin->child ); | |
665 | gtk_label_set_text(label, wxGTK_CONV(text)); | |
666 | } | |
667 | else | |
668 | { | |
669 | wxFAIL_MSG( wxT("wxComboBox: wrong index") ); | |
670 | } | |
671 | } | |
8228b893 | 672 | |
b0021947 | 673 | InvalidateBestSize(); |
6de97a3b | 674 | } |
53010e52 | 675 | |
11e62fe6 | 676 | int wxComboBox::FindString( const wxString &item, bool bCase ) const |
53010e52 | 677 | { |
0a164d4c | 678 | wxCHECK_MSG( m_widget != NULL, wxNOT_FOUND, wxT("invalid combobox") ); |
805dd538 | 679 | |
590f50d6 RR |
680 | #ifdef __WXGTK24__ |
681 | if (!gtk_check_version(2,4,0)) | |
53010e52 | 682 | { |
590f50d6 RR |
683 | GtkComboBox* combobox = GTK_COMBO_BOX( m_widget ); |
684 | GtkTreeModel* model = gtk_combo_box_get_model( combobox ); | |
685 | GtkTreeIter iter; | |
686 | gtk_tree_model_get_iter_first( model, &iter ); | |
687 | if (!gtk_list_store_iter_is_valid(GTK_LIST_STORE(model), &iter )) | |
688 | return -1; | |
689 | int count = 0; | |
8228b893 | 690 | do |
590f50d6 RR |
691 | { |
692 | GValue value = { 0, }; | |
693 | gtk_tree_model_get_value( model, &iter, 0, &value ); | |
694 | wxString str = wxGTK_CONV_BACK( g_value_get_string( &value ) ); | |
695 | g_value_unset( &value ); | |
8228b893 | 696 | |
590f50d6 RR |
697 | if (item.IsSameAs( str, bCase ) ) |
698 | return count; | |
8228b893 | 699 | |
590f50d6 | 700 | count++; |
8228b893 | 701 | |
590f50d6 RR |
702 | } while (gtk_tree_model_iter_next( model, &iter )); |
703 | } | |
704 | else | |
705 | #endif | |
706 | { | |
707 | GtkWidget *list = GTK_COMBO(m_widget)->list; | |
68567a96 | 708 | |
590f50d6 RR |
709 | GList *child = GTK_LIST(list)->children; |
710 | int count = 0; | |
711 | while (child) | |
712 | { | |
713 | GtkBin *bin = GTK_BIN( child->data ); | |
714 | GtkLabel *label = GTK_LABEL( bin->child ); | |
715 | wxString str( wxGTK_CONV_BACK( gtk_label_get_text(label) ) ); | |
716 | ||
717 | if (item.IsSameAs( str , bCase ) ) | |
718 | return count; | |
30ed6e5c | 719 | |
590f50d6 RR |
720 | count++; |
721 | child = child->next; | |
722 | } | |
fd0eed64 | 723 | } |
805dd538 | 724 | |
7cf8cb48 | 725 | return wxNOT_FOUND; |
fd0eed64 RR |
726 | } |
727 | ||
728 | int wxComboBox::GetSelection() const | |
40eb3606 | 729 | { |
590f50d6 RR |
730 | #ifdef __WXGTK24__ |
731 | if (!gtk_check_version(2,4,0)) | |
732 | { | |
733 | GtkComboBox* combobox = GTK_COMBO_BOX( m_widget ); | |
734 | return gtk_combo_box_get_active( combobox ); | |
735 | } | |
736 | else | |
737 | #endif | |
738 | // if the popup is currently opened, use the selection as it had been | |
739 | // before it dropped down | |
740 | return g_SelectionBeforePopup == wxID_NONE ? GetCurrentSelection() | |
40eb3606 VZ |
741 | : g_SelectionBeforePopup; |
742 | } | |
743 | ||
744 | int wxComboBox::GetCurrentSelection() const | |
fd0eed64 | 745 | { |
223d09f6 | 746 | wxCHECK_MSG( m_widget != NULL, -1, wxT("invalid combobox") ); |
805dd538 | 747 | |
590f50d6 RR |
748 | #ifdef __WXGTK24__ |
749 | if (!gtk_check_version(2,4,0)) | |
fd0eed64 | 750 | { |
590f50d6 RR |
751 | GtkComboBox* combobox = GTK_COMBO_BOX( m_widget ); |
752 | return gtk_combo_box_get_active( combobox ); | |
753 | } | |
754 | else | |
755 | #endif | |
756 | { | |
757 | GtkWidget *list = GTK_COMBO(m_widget)->list; | |
758 | ||
759 | GList *selection = GTK_LIST(list)->selection; | |
760 | if (selection) | |
fd0eed64 | 761 | { |
590f50d6 RR |
762 | GList *child = GTK_LIST(list)->children; |
763 | int count = 0; | |
764 | while (child) | |
765 | { | |
766 | if (child->data == selection->data) return count; | |
767 | count++; | |
768 | child = child->next; | |
769 | } | |
fd0eed64 | 770 | } |
6de97a3b | 771 | } |
805dd538 | 772 | |
fd0eed64 | 773 | return -1; |
6de97a3b | 774 | } |
53010e52 | 775 | |
aa61d352 | 776 | wxString wxComboBox::GetString(unsigned int n) const |
53010e52 | 777 | { |
0a164d4c | 778 | wxCHECK_MSG( m_widget != NULL, wxEmptyString, wxT("invalid combobox") ); |
805dd538 | 779 | |
7cf8cb48 | 780 | wxString str; |
8228b893 | 781 | |
590f50d6 RR |
782 | #ifdef __WXGTK24__ |
783 | if (!gtk_check_version(2,4,0)) | |
fd0eed64 | 784 | { |
590f50d6 RR |
785 | GtkComboBox* combobox = GTK_COMBO_BOX( m_widget ); |
786 | GtkTreeModel *model = gtk_combo_box_get_model( combobox ); | |
787 | GtkTreeIter iter; | |
788 | if (gtk_tree_model_iter_nth_child (model, &iter, NULL, n)) | |
789 | { | |
790 | GValue value = { 0, }; | |
791 | gtk_tree_model_get_value( model, &iter, 0, &value ); | |
792 | wxString tmp = wxGTK_CONV_BACK( g_value_get_string( &value ) ); | |
793 | g_value_unset( &value ); | |
794 | return tmp; | |
795 | } | |
7cf8cb48 VZ |
796 | } |
797 | else | |
590f50d6 | 798 | #endif |
8228b893 | 799 | { |
590f50d6 RR |
800 | GtkWidget *list = GTK_COMBO(m_widget)->list; |
801 | ||
802 | GList *child = g_list_nth( GTK_LIST(list)->children, n ); | |
803 | if (child) | |
804 | { | |
805 | GtkBin *bin = GTK_BIN( child->data ); | |
806 | GtkLabel *label = GTK_LABEL( bin->child ); | |
807 | str = wxGTK_CONV_BACK( gtk_label_get_text(label) ); | |
808 | } | |
809 | else | |
810 | { | |
811 | wxFAIL_MSG( wxT("wxComboBox: wrong index") ); | |
812 | } | |
fd0eed64 | 813 | } |
805dd538 | 814 | |
7cf8cb48 | 815 | return str; |
6de97a3b | 816 | } |
53010e52 | 817 | |
fd0eed64 | 818 | wxString wxComboBox::GetStringSelection() const |
53010e52 | 819 | { |
0a164d4c | 820 | wxCHECK_MSG( m_widget != NULL, wxEmptyString, wxT("invalid combobox") ); |
805dd538 | 821 | |
590f50d6 RR |
822 | #ifdef __WXGTK24__ |
823 | if (!gtk_check_version(2,4,0)) | |
fd0eed64 | 824 | { |
590f50d6 RR |
825 | GtkComboBox* combobox = GTK_COMBO_BOX( m_widget ); |
826 | int sel = gtk_combo_box_get_active( combobox ); | |
827 | if (sel == -1) | |
828 | return wxEmptyString; | |
aa61d352 | 829 | return GetString(sel); |
fd0eed64 | 830 | } |
590f50d6 RR |
831 | else |
832 | #endif | |
8228b893 | 833 | { |
590f50d6 RR |
834 | GtkWidget *list = GTK_COMBO(m_widget)->list; |
835 | ||
836 | GList *selection = GTK_LIST(list)->selection; | |
837 | if (selection) | |
838 | { | |
839 | GtkBin *bin = GTK_BIN( selection->data ); | |
840 | GtkLabel *label = GTK_LABEL( bin->child ); | |
841 | wxString tmp( wxGTK_CONV_BACK( gtk_label_get_text(label) ) ); | |
842 | return tmp; | |
843 | } | |
805dd538 | 844 | |
590f50d6 RR |
845 | wxFAIL_MSG( wxT("wxComboBox: no selection") ); |
846 | } | |
805dd538 | 847 | |
0a164d4c | 848 | return wxEmptyString; |
6de97a3b | 849 | } |
53010e52 | 850 | |
aa61d352 | 851 | unsigned int wxComboBox::GetCount() const |
53010e52 | 852 | { |
223d09f6 | 853 | wxCHECK_MSG( m_widget != NULL, 0, wxT("invalid combobox") ); |
805dd538 | 854 | |
590f50d6 RR |
855 | #ifdef __WXGTK24__ |
856 | if (!gtk_check_version(2,4,0)) | |
857 | { | |
858 | GtkComboBox* combobox = GTK_COMBO_BOX( m_widget ); | |
859 | GtkTreeModel* model = gtk_combo_box_get_model( combobox ); | |
860 | GtkTreeIter iter; | |
861 | gtk_tree_model_get_iter_first( model, &iter ); | |
862 | if (!gtk_list_store_iter_is_valid(GTK_LIST_STORE(model), &iter )) | |
863 | return 0; | |
aa61d352 | 864 | unsigned int ret = 1; |
590f50d6 RR |
865 | while (gtk_tree_model_iter_next( model, &iter )) |
866 | ret++; | |
867 | return ret; | |
868 | } | |
869 | else | |
870 | #endif | |
8228b893 | 871 | { |
590f50d6 | 872 | GtkWidget *list = GTK_COMBO(m_widget)->list; |
805dd538 | 873 | |
590f50d6 | 874 | GList *child = GTK_LIST(list)->children; |
aa61d352 VZ |
875 | unsigned int count = 0; |
876 | while (child) | |
877 | { | |
878 | count++; | |
879 | child = child->next; | |
880 | } | |
590f50d6 RR |
881 | return count; |
882 | } | |
8228b893 | 883 | |
590f50d6 | 884 | return 0; |
6de97a3b | 885 | } |
53010e52 | 886 | |
debe6624 | 887 | void wxComboBox::SetSelection( int n ) |
53010e52 | 888 | { |
223d09f6 | 889 | wxCHECK_RET( m_widget != NULL, wxT("invalid combobox") ); |
805dd538 | 890 | |
953704c1 RR |
891 | DisableEvents(); |
892 | ||
590f50d6 RR |
893 | #ifdef __WXGTK24__ |
894 | if (!gtk_check_version(2,4,0)) | |
895 | { | |
896 | GtkComboBox* combobox = GTK_COMBO_BOX( m_widget ); | |
897 | gtk_combo_box_set_active( combobox, n ); | |
898 | } | |
899 | else | |
900 | #endif | |
901 | { | |
902 | GtkWidget *list = GTK_COMBO(m_widget)->list; | |
903 | gtk_list_unselect_item( GTK_LIST(list), m_prevSelection ); | |
904 | gtk_list_select_item( GTK_LIST(list), n ); | |
905 | m_prevSelection = n; | |
906 | } | |
8228b893 | 907 | |
953704c1 | 908 | EnableEvents(); |
6de97a3b | 909 | } |
53010e52 | 910 | |
fd0eed64 | 911 | wxString wxComboBox::GetValue() const |
53010e52 | 912 | { |
590f50d6 RR |
913 | GtkEntry *entry = NULL; |
914 | #ifdef __WXGTK24__ | |
915 | if (!gtk_check_version(2,4,0)) | |
916 | entry = GTK_ENTRY( GTK_BIN(m_widget)->child ); | |
917 | else | |
8228b893 | 918 | #endif |
590f50d6 | 919 | entry = GTK_ENTRY( GTK_COMBO(m_widget)->entry ); |
8228b893 | 920 | |
2e1d7104 RR |
921 | wxString tmp( wxGTK_CONV_BACK( gtk_entry_get_text( entry ) ) ); |
922 | ||
30ed6e5c | 923 | #if 0 |
2e1d7104 RR |
924 | for (int i = 0; i < wxStrlen(tmp.c_str()) +1; i++) |
925 | { | |
926 | wxChar c = tmp[i]; | |
927 | printf( "%d ", (int) (c) ); | |
928 | } | |
929 | printf( "\n" ); | |
930 | #endif | |
30ed6e5c | 931 | |
fd0eed64 | 932 | return tmp; |
6de97a3b | 933 | } |
53010e52 RR |
934 | |
935 | void wxComboBox::SetValue( const wxString& value ) | |
936 | { | |
223d09f6 | 937 | wxCHECK_RET( m_widget != NULL, wxT("invalid combobox") ); |
805dd538 | 938 | |
590f50d6 RR |
939 | GtkEntry *entry = NULL; |
940 | #ifdef __WXGTK24__ | |
941 | if (!gtk_check_version(2,4,0)) | |
942 | entry = GTK_ENTRY( GTK_BIN(m_widget)->child ); | |
943 | else | |
8228b893 | 944 | #endif |
590f50d6 | 945 | entry = GTK_ENTRY( GTK_COMBO(m_widget)->entry ); |
8228b893 | 946 | |
0a164d4c | 947 | wxString tmp; |
fd0eed64 | 948 | if (!value.IsNull()) tmp = value; |
21dd7c5b RR |
949 | |
950 | DisableEvents(); | |
590f50d6 | 951 | gtk_entry_set_text( entry, wxGTK_CONV( tmp ) ); |
21dd7c5b | 952 | EnableEvents(); |
150e31d2 | 953 | |
b0021947 | 954 | InvalidateBestSize(); |
6de97a3b | 955 | } |
53010e52 | 956 | |
fd0eed64 | 957 | void wxComboBox::Copy() |
53010e52 | 958 | { |
223d09f6 | 959 | wxCHECK_RET( m_widget != NULL, wxT("invalid combobox") ); |
805dd538 | 960 | |
590f50d6 RR |
961 | GtkEntry *entry = NULL; |
962 | #ifdef __WXGTK24__ | |
963 | if (!gtk_check_version(2,4,0)) | |
964 | entry = GTK_ENTRY( GTK_BIN(m_widget)->child ); | |
965 | else | |
8228b893 | 966 | #endif |
590f50d6 | 967 | entry = GTK_ENTRY( GTK_COMBO(m_widget)->entry ); |
8228b893 | 968 | |
afa7bd1e | 969 | gtk_editable_copy_clipboard(GTK_EDITABLE(entry)); |
6de97a3b | 970 | } |
53010e52 | 971 | |
fd0eed64 | 972 | void wxComboBox::Cut() |
53010e52 | 973 | { |
223d09f6 | 974 | wxCHECK_RET( m_widget != NULL, wxT("invalid combobox") ); |
805dd538 | 975 | |
590f50d6 RR |
976 | GtkEntry *entry = NULL; |
977 | #ifdef __WXGTK24__ | |
978 | if (!gtk_check_version(2,4,0)) | |
979 | entry = GTK_ENTRY( GTK_BIN(m_widget)->child ); | |
980 | else | |
8228b893 | 981 | #endif |
590f50d6 | 982 | entry = GTK_ENTRY( GTK_COMBO(m_widget)->entry ); |
8228b893 | 983 | |
afa7bd1e | 984 | gtk_editable_cut_clipboard(GTK_EDITABLE(entry)); |
6de97a3b | 985 | } |
53010e52 | 986 | |
fd0eed64 | 987 | void wxComboBox::Paste() |
53010e52 | 988 | { |
223d09f6 | 989 | wxCHECK_RET( m_widget != NULL, wxT("invalid combobox") ); |
805dd538 | 990 | |
590f50d6 RR |
991 | GtkEntry *entry = NULL; |
992 | #ifdef __WXGTK24__ | |
993 | if (!gtk_check_version(2,4,0)) | |
994 | entry = GTK_ENTRY( GTK_BIN(m_widget)->child ); | |
995 | else | |
8228b893 | 996 | #endif |
590f50d6 | 997 | entry = GTK_ENTRY( GTK_COMBO(m_widget)->entry ); |
8228b893 | 998 | |
afa7bd1e | 999 | gtk_editable_paste_clipboard(GTK_EDITABLE(entry)); |
6de97a3b | 1000 | } |
53010e52 | 1001 | |
150e31d2 JS |
1002 | void wxComboBox::Undo() |
1003 | { | |
1004 | // TODO | |
1005 | } | |
1006 | ||
1007 | void wxComboBox::Redo() | |
1008 | { | |
1009 | // TODO | |
1010 | } | |
1011 | ||
1012 | void wxComboBox::SelectAll() | |
1013 | { | |
4e324a3f | 1014 | SetSelection(0, GetLastPosition()); |
150e31d2 JS |
1015 | } |
1016 | ||
1017 | bool wxComboBox::CanUndo() const | |
1018 | { | |
1019 | // TODO | |
1020 | return false; | |
1021 | } | |
1022 | ||
1023 | bool wxComboBox::CanRedo() const | |
1024 | { | |
1025 | // TODO | |
1026 | return false; | |
1027 | } | |
1028 | ||
1029 | bool wxComboBox::HasSelection() const | |
1030 | { | |
1031 | long from, to; | |
1032 | GetSelection(&from, &to); | |
1033 | return from != to; | |
1034 | } | |
1035 | ||
1036 | bool wxComboBox::CanCopy() const | |
1037 | { | |
1038 | // Can copy if there's a selection | |
1039 | return HasSelection(); | |
1040 | } | |
1041 | ||
1042 | bool wxComboBox::CanCut() const | |
1043 | { | |
1044 | return CanCopy() && IsEditable(); | |
1045 | } | |
1046 | ||
1047 | bool wxComboBox::CanPaste() const | |
1048 | { | |
1049 | // TODO: check for text on the clipboard | |
1050 | return IsEditable() ; | |
1051 | } | |
1052 | ||
1053 | bool wxComboBox::IsEditable() const | |
1054 | { | |
1055 | return !HasFlag(wxCB_READONLY); | |
1056 | } | |
1057 | ||
1058 | ||
debe6624 | 1059 | void wxComboBox::SetInsertionPoint( long pos ) |
53010e52 | 1060 | { |
223d09f6 | 1061 | wxCHECK_RET( m_widget != NULL, wxT("invalid combobox") ); |
805dd538 | 1062 | |
6f6f938f VZ |
1063 | if ( pos == GetLastPosition() ) |
1064 | pos = -1; | |
1065 | ||
590f50d6 RR |
1066 | GtkEntry *entry = NULL; |
1067 | #ifdef __WXGTK24__ | |
1068 | if (!gtk_check_version(2,4,0)) | |
1069 | entry = GTK_ENTRY( GTK_BIN(m_widget)->child ); | |
1070 | else | |
8228b893 | 1071 | #endif |
590f50d6 | 1072 | entry = GTK_ENTRY( GTK_COMBO(m_widget)->entry ); |
8228b893 | 1073 | |
590f50d6 | 1074 | gtk_entry_set_position( entry, (int)pos ); |
6de97a3b | 1075 | } |
53010e52 | 1076 | |
fd0eed64 | 1077 | long wxComboBox::GetInsertionPoint() const |
53010e52 | 1078 | { |
590f50d6 RR |
1079 | GtkEntry *entry = NULL; |
1080 | #ifdef __WXGTK24__ | |
1081 | if (!gtk_check_version(2,4,0)) | |
1082 | entry = GTK_ENTRY( GTK_BIN(m_widget)->child ); | |
1083 | else | |
8228b893 | 1084 | #endif |
590f50d6 | 1085 | entry = GTK_ENTRY( GTK_COMBO(m_widget)->entry ); |
8228b893 | 1086 | |
590f50d6 | 1087 | return (long) gtk_editable_get_position(GTK_EDITABLE(entry)); |
6de97a3b | 1088 | } |
53010e52 | 1089 | |
7d8268a1 | 1090 | wxTextPos wxComboBox::GetLastPosition() const |
53010e52 | 1091 | { |
590f50d6 RR |
1092 | GtkEntry *entry = NULL; |
1093 | #ifdef __WXGTK24__ | |
1094 | if (!gtk_check_version(2,4,0)) | |
1095 | entry = GTK_ENTRY( GTK_BIN(m_widget)->child ); | |
1096 | else | |
8228b893 | 1097 | #endif |
590f50d6 | 1098 | entry = GTK_ENTRY( GTK_COMBO(m_widget)->entry ); |
8228b893 | 1099 | |
590f50d6 | 1100 | int pos = entry->text_length; |
fd0eed64 | 1101 | return (long) pos-1; |
6de97a3b | 1102 | } |
53010e52 | 1103 | |
debe6624 | 1104 | void wxComboBox::Replace( long from, long to, const wxString& value ) |
53010e52 | 1105 | { |
223d09f6 | 1106 | wxCHECK_RET( m_widget != NULL, wxT("invalid combobox") ); |
805dd538 | 1107 | |
590f50d6 RR |
1108 | GtkEntry *entry = NULL; |
1109 | #ifdef __WXGTK24__ | |
1110 | if (!gtk_check_version(2,4,0)) | |
1111 | entry = GTK_ENTRY( GTK_BIN(m_widget)->child ); | |
1112 | else | |
8228b893 | 1113 | #endif |
590f50d6 | 1114 | entry = GTK_ENTRY( GTK_COMBO(m_widget)->entry ); |
8228b893 | 1115 | |
fd0eed64 RR |
1116 | gtk_editable_delete_text( GTK_EDITABLE(entry), (gint)from, (gint)to ); |
1117 | if (value.IsNull()) return; | |
1118 | gint pos = (gint)to; | |
30ed6e5c | 1119 | |
37a4076e VS |
1120 | #if wxUSE_UNICODE_UTF8 |
1121 | const char *utf8 = value.utf8_str(); | |
2e1d7104 | 1122 | #else |
37a4076e | 1123 | wxCharBuffer buffer(value.utf8_str()); |
056b067f | 1124 | const char *utf8 = buffer; |
2e1d7104 | 1125 | #endif |
37a4076e | 1126 | gtk_editable_insert_text(GTK_EDITABLE(entry), utf8, strlen(utf8), &pos); |
6de97a3b | 1127 | } |
53010e52 | 1128 | |
20d10ee1 | 1129 | void wxComboBox::SetSelection( long from, long to ) |
53010e52 | 1130 | { |
590f50d6 RR |
1131 | GtkEntry *entry = NULL; |
1132 | #ifdef __WXGTK24__ | |
1133 | if (!gtk_check_version(2,4,0)) | |
1134 | entry = GTK_ENTRY( GTK_BIN(m_widget)->child ); | |
1135 | else | |
8228b893 | 1136 | #endif |
590f50d6 | 1137 | entry = GTK_ENTRY( GTK_COMBO(m_widget)->entry ); |
8228b893 | 1138 | |
20d10ee1 | 1139 | gtk_editable_select_region( GTK_EDITABLE(entry), (gint)from, (gint)to ); |
6de97a3b | 1140 | } |
53010e52 | 1141 | |
150e31d2 JS |
1142 | void wxComboBox::GetSelection( long* from, long* to ) const |
1143 | { | |
590f50d6 RR |
1144 | GtkEntry *entry = NULL; |
1145 | #ifdef __WXGTK24__ | |
1146 | if (!gtk_check_version(2,4,0)) | |
1147 | entry = GTK_ENTRY( GTK_BIN(m_widget)->child ); | |
1148 | else | |
8228b893 | 1149 | #endif |
590f50d6 | 1150 | entry = GTK_ENTRY( GTK_COMBO(m_widget)->entry ); |
8228b893 | 1151 | |
150e31d2 JS |
1152 | if (IsEditable()) |
1153 | { | |
590f50d6 | 1154 | GtkEditable *editable = GTK_EDITABLE(entry); |
4e324a3f JS |
1155 | gint start, end; |
1156 | gtk_editable_get_selection_bounds(editable, & start, & end); | |
1157 | *from = start; | |
1158 | *to = end; | |
150e31d2 JS |
1159 | } |
1160 | } | |
1161 | ||
20d10ee1 | 1162 | void wxComboBox::SetEditable( bool editable ) |
53010e52 | 1163 | { |
590f50d6 RR |
1164 | GtkEntry *entry = NULL; |
1165 | #ifdef __WXGTK24__ | |
1166 | if (!gtk_check_version(2,4,0)) | |
1167 | entry = GTK_ENTRY( GTK_BIN(m_widget)->child ); | |
1168 | else | |
8228b893 | 1169 | #endif |
590f50d6 | 1170 | entry = GTK_ENTRY( GTK_COMBO(m_widget)->entry ); |
8228b893 | 1171 | |
20d10ee1 | 1172 | gtk_entry_set_editable( GTK_ENTRY(entry), editable ); |
b4071e91 RR |
1173 | } |
1174 | ||
8a85884a VZ |
1175 | void wxComboBox::OnChar( wxKeyEvent &event ) |
1176 | { | |
12a3f227 | 1177 | if ( event.GetKeyCode() == WXK_RETURN ) |
8a85884a | 1178 | { |
461573cc | 1179 | // GTK automatically selects an item if its in the list |
17a1ebd1 VZ |
1180 | wxCommandEvent eventEnter(wxEVT_COMMAND_TEXT_ENTER, GetId()); |
1181 | eventEnter.SetString( GetValue() ); | |
1182 | eventEnter.SetInt( GetSelection() ); | |
1183 | eventEnter.SetEventObject( this ); | |
3352cfff | 1184 | |
17a1ebd1 | 1185 | if (!GetEventHandler()->ProcessEvent( eventEnter )) |
3352cfff RR |
1186 | { |
1187 | // This will invoke the dialog default action, such | |
1188 | // as the clicking the default button. | |
1189 | ||
1190 | wxWindow *top_frame = m_parent; | |
1191 | while (top_frame->GetParent() && !(top_frame->IsTopLevel())) | |
1192 | top_frame = top_frame->GetParent(); | |
1193 | ||
1194 | if (top_frame && GTK_IS_WINDOW(top_frame->m_widget)) | |
1195 | { | |
1196 | GtkWindow *window = GTK_WINDOW(top_frame->m_widget); | |
1197 | ||
1198 | if (window->default_widget) | |
150e31d2 | 1199 | gtk_widget_activate (window->default_widget); |
3352cfff RR |
1200 | } |
1201 | } | |
30ed6e5c | 1202 | |
461573cc RR |
1203 | // Catch GTK event so that GTK doesn't open the drop |
1204 | // down list upon RETURN. | |
0878fb4c | 1205 | return; |
8a85884a | 1206 | } |
30ed6e5c | 1207 | |
7cf8cb48 | 1208 | event.Skip(); |
8a85884a VZ |
1209 | } |
1210 | ||
953704c1 RR |
1211 | void wxComboBox::DisableEvents() |
1212 | { | |
590f50d6 RR |
1213 | #ifdef __WXGTK24__ |
1214 | if (!gtk_check_version(2,4,0)) | |
1215 | { | |
8228b893 | 1216 | g_signal_handlers_disconnect_by_func (GTK_BIN(m_widget)->child, |
590f50d6 | 1217 | (gpointer)gtkcombobox_text_changed_callback, this); |
8228b893 | 1218 | |
590f50d6 RR |
1219 | g_signal_handlers_disconnect_by_func (m_widget, |
1220 | (gpointer)gtkcombobox_changed_callback, this); | |
1221 | } | |
1222 | else | |
8228b893 | 1223 | #endif |
590f50d6 RR |
1224 | { |
1225 | g_signal_handlers_disconnect_by_func (GTK_COMBO(m_widget)->list, | |
1226 | (gpointer) gtkcombo_combo_select_child_callback, this); | |
8228b893 | 1227 | |
590f50d6 RR |
1228 | g_signal_handlers_disconnect_by_func (GTK_COMBO(m_widget)->entry, |
1229 | (gpointer) gtkcombo_text_changed_callback, this); | |
1230 | } | |
953704c1 RR |
1231 | } |
1232 | ||
1233 | void wxComboBox::EnableEvents() | |
1234 | { | |
590f50d6 RR |
1235 | #ifdef __WXGTK24__ |
1236 | if (!gtk_check_version(2,4,0)) | |
1237 | { | |
1238 | g_signal_connect_after (GTK_BIN(m_widget)->child, "changed", | |
1239 | G_CALLBACK (gtkcombobox_text_changed_callback), this); | |
8228b893 | 1240 | |
590f50d6 RR |
1241 | g_signal_connect_after (m_widget, "changed", |
1242 | G_CALLBACK (gtkcombobox_changed_callback), this); | |
1243 | } | |
1244 | else | |
8228b893 | 1245 | #endif |
590f50d6 RR |
1246 | { |
1247 | g_signal_connect_after (GTK_COMBO(m_widget)->list, "select-child", | |
1fb33bdb | 1248 | G_CALLBACK (gtkcombo_combo_select_child_callback), |
9fa72bd2 | 1249 | this); |
590f50d6 | 1250 | g_signal_connect_after (GTK_COMBO(m_widget)->entry, "changed", |
1fb33bdb | 1251 | G_CALLBACK (gtkcombo_text_changed_callback), |
9fa72bd2 | 1252 | this ); |
590f50d6 | 1253 | } |
953704c1 RR |
1254 | } |
1255 | ||
b4071e91 RR |
1256 | void wxComboBox::OnSize( wxSizeEvent &event ) |
1257 | { | |
590f50d6 RR |
1258 | #ifdef __WXGTK24__ |
1259 | if (!gtk_check_version(2,4,0)) | |
1260 | { | |
1261 | // Do nothing | |
1262 | } | |
1263 | else | |
1264 | #endif | |
1265 | { | |
1266 | // NB: In some situations (e.g. on non-first page of a wizard, if the | |
1267 | // size used is default size), GtkCombo widget is resized correctly, | |
1268 | // but it's look is not updated, it's rendered as if it was much wider. | |
1269 | // No other widgets are affected, so it looks like a bug in GTK+. | |
1270 | // Manually requesting resize calculation (as gtk_pizza_set_size does) | |
1271 | // fixes it. | |
1272 | if (GTK_WIDGET_VISIBLE(m_widget)) | |
1273 | gtk_widget_queue_resize(m_widget); | |
1274 | } | |
260a67b7 | 1275 | |
f03fc89f | 1276 | event.Skip(); |
6de97a3b | 1277 | } |
53010e52 | 1278 | |
f40fdaa3 | 1279 | void wxComboBox::DoApplyWidgetStyle(GtkRcStyle *style) |
868a2826 | 1280 | { |
590f50d6 RR |
1281 | #ifdef __WXGTK24__ |
1282 | if (!gtk_check_version(2,4,0)) | |
1283 | { | |
1284 | // Do nothing | |
1285 | } | |
1286 | else | |
1287 | #endif | |
1288 | { | |
f40fdaa3 | 1289 | // gtk_widget_modify_style( GTK_COMBO(m_widget)->button, syle ); |
ea2d542c | 1290 | |
590f50d6 RR |
1291 | gtk_widget_modify_style( GTK_COMBO(m_widget)->entry, style ); |
1292 | gtk_widget_modify_style( GTK_COMBO(m_widget)->list, style ); | |
805dd538 | 1293 | |
590f50d6 RR |
1294 | GtkList *list = GTK_LIST( GTK_COMBO(m_widget)->list ); |
1295 | GList *child = list->children; | |
1296 | while (child) | |
1297 | { | |
1298 | gtk_widget_modify_style( GTK_WIDGET(child->data), style ); | |
805dd538 | 1299 | |
590f50d6 RR |
1300 | GtkBin *bin = GTK_BIN(child->data); |
1301 | gtk_widget_modify_style( bin->child, style ); | |
805dd538 | 1302 | |
590f50d6 RR |
1303 | child = child->next; |
1304 | } | |
fd0eed64 | 1305 | } |
868a2826 | 1306 | } |
b4071e91 | 1307 | |
fd0eed64 | 1308 | GtkWidget* wxComboBox::GetConnectWidget() |
97b3455a | 1309 | { |
590f50d6 RR |
1310 | GtkEntry *entry = NULL; |
1311 | #ifdef __WXGTK24__ | |
1312 | if (!gtk_check_version(2,4,0)) | |
1313 | entry = GTK_ENTRY( GTK_BIN(m_widget)->child ); | |
1314 | else | |
8228b893 | 1315 | #endif |
590f50d6 | 1316 | entry = GTK_ENTRY( GTK_COMBO(m_widget)->entry ); |
8228b893 | 1317 | |
590f50d6 | 1318 | return GTK_WIDGET( entry ); |
97b3455a RR |
1319 | } |
1320 | ||
ef5c70f9 | 1321 | GdkWindow *wxComboBox::GTKGetWindow(wxArrayGdkWindows& windows) const |
b4071e91 | 1322 | { |
590f50d6 RR |
1323 | #ifdef __WXGTK24__ |
1324 | if (!gtk_check_version(2,4,0)) | |
1325 | { | |
ef5c70f9 VZ |
1326 | wxUnusedVar(windows); |
1327 | ||
1328 | return GTK_ENTRY(GTK_BIN(m_widget)->child)->text_area; | |
590f50d6 RR |
1329 | } |
1330 | else | |
ef5c70f9 | 1331 | #endif // GTK+ 2.4 |
590f50d6 | 1332 | { |
ef5c70f9 VZ |
1333 | windows.push_back(GTK_ENTRY(GTK_COMBO(m_widget)->entry)->text_area); |
1334 | windows.push_back(GTK_COMBO(m_widget)->button->window); | |
1335 | ||
1336 | // indicate that we return multiple windows in the windows array | |
1337 | return NULL; | |
590f50d6 | 1338 | } |
b4071e91 | 1339 | } |
ac57418f | 1340 | |
f68586e5 VZ |
1341 | wxSize wxComboBox::DoGetBestSize() const |
1342 | { | |
db434467 | 1343 | wxSize ret( wxControl::DoGetBestSize() ); |
a6fc8ae3 VZ |
1344 | |
1345 | // we know better our horizontal extent: it depends on the longest string | |
1346 | // in the combobox | |
a6fc8ae3 VZ |
1347 | if ( m_widget ) |
1348 | { | |
60d85ccb | 1349 | int width; |
aa61d352 VZ |
1350 | unsigned int count = GetCount(); |
1351 | for ( unsigned int n = 0; n < count; n++ ) | |
a6fc8ae3 | 1352 | { |
aa61d352 | 1353 | GetTextExtent(GetString(n), &width, NULL, NULL, NULL ); |
a6fc8ae3 VZ |
1354 | if ( width > ret.x ) |
1355 | ret.x = width; | |
1356 | } | |
1357 | } | |
1358 | ||
1359 | // empty combobox should have some reasonable default size too | |
1360 | if ( ret.x < 100 ) | |
1361 | ret.x = 100; | |
9f884528 RD |
1362 | |
1363 | CacheBestSize(ret); | |
db434467 | 1364 | return ret; |
f68586e5 VZ |
1365 | } |
1366 | ||
9d522606 RD |
1367 | // static |
1368 | wxVisualAttributes | |
1369 | wxComboBox::GetClassDefaultAttributes(wxWindowVariant WXUNUSED(variant)) | |
1370 | { | |
590f50d6 RR |
1371 | #ifdef __WXGTK24__ |
1372 | if (!gtk_check_version(2,4,0)) | |
1373 | return GetDefaultAttributesFromGTKWidget(gtk_combo_box_entry_new, true); | |
1374 | else | |
1375 | #endif | |
1376 | return GetDefaultAttributesFromGTKWidget(gtk_combo_new, true); | |
9d522606 RD |
1377 | } |
1378 | ||
150e31d2 JS |
1379 | // ---------------------------------------------------------------------------- |
1380 | // standard event handling | |
1381 | // ---------------------------------------------------------------------------- | |
1382 | ||
1383 | void wxComboBox::OnCut(wxCommandEvent& WXUNUSED(event)) | |
1384 | { | |
1385 | Cut(); | |
1386 | } | |
1387 | ||
1388 | void wxComboBox::OnCopy(wxCommandEvent& WXUNUSED(event)) | |
1389 | { | |
1390 | Copy(); | |
1391 | } | |
1392 | ||
1393 | void wxComboBox::OnPaste(wxCommandEvent& WXUNUSED(event)) | |
1394 | { | |
1395 | Paste(); | |
1396 | } | |
1397 | ||
1398 | void wxComboBox::OnUndo(wxCommandEvent& WXUNUSED(event)) | |
1399 | { | |
1400 | Undo(); | |
1401 | } | |
1402 | ||
1403 | void wxComboBox::OnRedo(wxCommandEvent& WXUNUSED(event)) | |
1404 | { | |
1405 | Redo(); | |
1406 | } | |
1407 | ||
1408 | void wxComboBox::OnDelete(wxCommandEvent& WXUNUSED(event)) | |
1409 | { | |
1410 | long from, to; | |
1411 | GetSelection(& from, & to); | |
1412 | if (from != -1 && to != -1) | |
1413 | Remove(from, to); | |
1414 | } | |
1415 | ||
1416 | void wxComboBox::OnSelectAll(wxCommandEvent& WXUNUSED(event)) | |
1417 | { | |
1418 | SetSelection(-1, -1); | |
1419 | } | |
1420 | ||
1421 | void wxComboBox::OnUpdateCut(wxUpdateUIEvent& event) | |
1422 | { | |
1423 | event.Enable( CanCut() ); | |
1424 | } | |
1425 | ||
1426 | void wxComboBox::OnUpdateCopy(wxUpdateUIEvent& event) | |
1427 | { | |
1428 | event.Enable( CanCopy() ); | |
1429 | } | |
1430 | ||
1431 | void wxComboBox::OnUpdatePaste(wxUpdateUIEvent& event) | |
1432 | { | |
1433 | event.Enable( CanPaste() ); | |
1434 | } | |
1435 | ||
1436 | void wxComboBox::OnUpdateUndo(wxUpdateUIEvent& event) | |
1437 | { | |
1438 | event.Enable( CanUndo() ); | |
1439 | } | |
1440 | ||
1441 | void wxComboBox::OnUpdateRedo(wxUpdateUIEvent& event) | |
1442 | { | |
1443 | event.Enable( CanRedo() ); | |
1444 | } | |
1445 | ||
1446 | void wxComboBox::OnUpdateDelete(wxUpdateUIEvent& event) | |
1447 | { | |
1448 | event.Enable(HasSelection() && IsEditable()) ; | |
1449 | } | |
1450 | ||
1451 | void wxComboBox::OnUpdateSelectAll(wxUpdateUIEvent& event) | |
1452 | { | |
1453 | event.Enable(GetLastPosition() > 0); | |
1454 | } | |
1455 | ||
dcf924a3 | 1456 | #endif |