1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/gtk/combobox.cpp
4 // Author: Robert Roebling
6 // Copyright: (c) 1998 Robert Roebling
7 // Licence: wxWindows licence
8 /////////////////////////////////////////////////////////////////////////////
10 // For compilers that support precompilation, includes "wx.h".
11 #include "wx/wxprec.h"
15 #include "wx/combobox.h"
19 #include "wx/settings.h"
20 #include "wx/textctrl.h" // for wxEVT_COMMAND_TEXT_UPDATED
21 #include "wx/arrstr.h"
24 // We use GtkCombo which has been deprecated since GTK+ 2.3.0
25 // in favour of GtkComboBox for <GTK2.4 runtime
26 // We also use GtkList
27 #ifdef GTK_DISABLE_DEPRECATED
28 #undef GTK_DISABLE_DEPRECATED
30 #include "wx/gtk/private.h"
32 //-----------------------------------------------------------------------------
34 //-----------------------------------------------------------------------------
36 extern bool g_blockEventsOnDrag
;
37 static int g_SelectionBeforePopup
= wxID_NONE
; // this means the popup is hidden
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 //-----------------------------------------------------------------------------
46 gtkcombo_text_changed_callback( GtkWidget
*WXUNUSED(widget
), wxComboBox
*combo
)
48 if (combo
->m_ignoreNextUpdate
)
50 combo
->m_ignoreNextUpdate
= false;
54 if (!combo
->m_hasVMT
) return;
56 wxCommandEvent
event( wxEVT_COMMAND_TEXT_UPDATED
, combo
->GetId() );
57 event
.SetString( combo
->GetValue() );
58 event
.SetEventObject( combo
);
59 combo
->GetEventHandler()->ProcessEvent( event
);
65 gtkcombo_dummy_callback(GtkEntry
*WXUNUSED(entry
), GtkCombo
*WXUNUSED(combo
))
72 gtkcombo_popup_hide_callback(GtkCombo
*WXUNUSED(gtk_combo
), wxComboBox
*combo
)
74 // when the popup is hidden, throw a SELECTED event only if the combobox
76 const int curSelection
= combo
->GetCurrentSelection();
78 const bool hasChanged
= curSelection
!= g_SelectionBeforePopup
;
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
;
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
);
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
);
104 gtkcombo_popup_show_callback(GtkCombo
*WXUNUSED(gtk_combo
), wxComboBox
*combo
)
106 // store the combobox selection value before the popup is shown
107 g_SelectionBeforePopup
= combo
->GetCurrentSelection();
111 //-----------------------------------------------------------------------------
112 // "select-child" - click/cursor get select-child, changed, select-child
113 //-----------------------------------------------------------------------------
117 gtkcombo_combo_select_child_callback( GtkList
*WXUNUSED(list
), GtkWidget
*WXUNUSED(widget
), wxComboBox
*combo
)
119 if (!combo
->m_hasVMT
) return;
121 if (g_blockEventsOnDrag
) return;
123 int curSelection
= combo
->GetCurrentSelection();
125 if (combo
->m_prevSelection
== curSelection
) return;
127 GtkWidget
*list
= GTK_COMBO(combo
->m_widget
)->list
;
128 gtk_list_unselect_item( GTK_LIST(list
), combo
->m_prevSelection
);
130 combo
->m_prevSelection
= curSelection
;
132 // Quickly set the value of the combo box
133 // as GTK+ does that only AFTER the event
135 GtkWidget
* entry
= GTK_COMBO(combo
->GetHandle())->entry
;
136 g_signal_handlers_block_by_func(
137 entry
, (gpointer
)gtkcombo_text_changed_callback
, combo
);
138 combo
->SetValue( combo
->GetStringSelection() );
139 g_signal_handlers_unblock_by_func(
140 entry
, (gpointer
)gtkcombo_text_changed_callback
, combo
);
142 // throw a SELECTED event only if the combobox popup is hidden (wxID_NONE)
143 // because when combobox popup is shown, gtkcombo_combo_select_child_callback is
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 ...
147 if (g_SelectionBeforePopup
== wxID_NONE
)
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
);
155 // for consistency with the other ports, don't generate text update
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
);
168 gtkcombobox_text_changed_callback( GtkWidget
*WXUNUSED(widget
), wxComboBox
*combo
)
170 if (!combo
->m_hasVMT
) return;
172 wxCommandEvent
event( wxEVT_COMMAND_TEXT_UPDATED
, combo
->GetId() );
173 event
.SetString( combo
->GetValue() );
174 event
.SetEventObject( combo
);
175 combo
->GetEventHandler()->ProcessEvent( event
);
181 gtkcombobox_changed_callback( GtkWidget
*WXUNUSED(widget
), wxComboBox
*combo
)
183 if (!combo
->m_hasVMT
) return;
185 if (combo
->GetSelection() == -1)
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
);
198 //-----------------------------------------------------------------------------
200 //-----------------------------------------------------------------------------
202 IMPLEMENT_DYNAMIC_CLASS(wxComboBox
,wxControl
)
204 BEGIN_EVENT_TABLE(wxComboBox
, wxControl
)
205 EVT_SIZE(wxComboBox::OnSize
)
206 EVT_CHAR(wxComboBox::OnChar
)
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
)
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
)
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
)
232 wxCArrayString
chs(choices
);
234 return Create( parent
, id
, value
, pos
, size
, chs
.GetCount(),
235 chs
.GetStrings(), style
, validator
, name
);
238 bool wxComboBox::Create( wxWindow
*parent
, wxWindowID id
, const wxString
& value
,
239 const wxPoint
& pos
, const wxSize
& size
,
240 int n
, const wxString choices
[],
241 long style
, const wxValidator
& validator
,
242 const wxString
& name
)
245 m_ignoreNextUpdate
= false;
248 if (!PreCreation( parent
, pos
, size
) ||
249 !CreateBase( parent
, id
, pos
, size
, style
, validator
, name
))
251 wxFAIL_MSG( wxT("wxComboBox creation failed") );
255 if(HasFlag(wxCB_SORT
))
256 m_strings
= new wxSortedArrayString();
259 if (!gtk_check_version(2,4,0))
261 m_widget
= gtk_combo_box_entry_new_text();
263 gtk_entry_set_editable( GTK_ENTRY( GTK_BIN(m_widget
)->child
), TRUE
);
268 m_widget
= gtk_combo_new();
269 GtkCombo
* combo
= GTK_COMBO(m_widget
);
271 // Disable GTK's broken events ...
272 g_signal_handler_disconnect (combo
->entry
, combo
->entry_change_id
);
273 // ... and add surrogate handler.
274 combo
->entry_change_id
= g_signal_connect (combo
->entry
, "changed",
275 G_CALLBACK (gtkcombo_dummy_callback
),
278 // make it more useable
279 gtk_combo_set_use_arrows_always( GTK_COMBO(m_widget
), TRUE
);
281 // and case-sensitive
282 gtk_combo_set_case_sensitive( GTK_COMBO(m_widget
), TRUE
);
284 if (style
& wxNO_BORDER
)
285 g_object_set (combo
->entry
, "has-frame", FALSE
, NULL
);
290 m_parent
->DoAddChild( this );
292 GtkEntry
*entry
= NULL
;
294 if (!gtk_check_version(2,4,0))
295 entry
= GTK_ENTRY( GTK_BIN(m_widget
)->child
);
298 entry
= GTK_ENTRY( GTK_COMBO(m_widget
)->entry
);
300 m_focusWidget
= GTK_WIDGET( entry
);
305 if (!gtk_check_version(2,4,0))
306 ConnectWidget( m_widget
);
309 ConnectWidget( GTK_COMBO(m_widget
)->button
);
312 if (!gtk_check_version(2,4,0))
314 gtk_entry_set_text( entry
, wxGTK_CONV(value
) );
316 if (style
& wxCB_READONLY
)
317 gtk_entry_set_editable( entry
, FALSE
);
319 g_signal_connect_after (entry
, "changed",
320 G_CALLBACK (gtkcombobox_text_changed_callback
), this);
322 g_signal_connect_after (m_widget
, "changed",
323 G_CALLBACK (gtkcombobox_changed_callback
), this);
329 GtkCombo
*combo
= GTK_COMBO(m_widget
);
330 // MSW's combo box shows the value and the selection is -1
331 gtk_entry_set_text( entry
, wxGTK_CONV(value
) );
332 gtk_list_unselect_all( GTK_LIST(combo
->list
) );
334 if (style
& wxCB_READONLY
)
335 gtk_entry_set_editable( entry
, FALSE
);
337 // "show" and "hide" events are generated when user click on the combobox button which popups a list
338 // this list is the "popwin" gtk widget
339 g_signal_connect (GTK_COMBO(combo
)->popwin
, "hide",
340 G_CALLBACK (gtkcombo_popup_hide_callback
), this);
341 g_signal_connect (GTK_COMBO(combo
)->popwin
, "show",
342 G_CALLBACK (gtkcombo_popup_show_callback
), this);
343 g_signal_connect_after (combo
->list
, "select-child",
344 G_CALLBACK (gtkcombo_combo_select_child_callback
),
346 g_signal_connect_after (entry
, "changed",
347 G_CALLBACK (gtkcombo_text_changed_callback
), this);
350 SetInitialSize(size
); // need this too because this is a wxControlWithItems
355 GtkEditable
*wxComboBox::GetEditable() const
358 if ( !gtk_check_version(2,4,0) )
359 return GTK_EDITABLE( GTK_BIN(m_widget
)->child
);
362 return GTK_EDITABLE( GTK_COMBO(m_widget
)->entry
);
365 wxComboBox::~wxComboBox()
372 void wxComboBox::SetFocus()
376 // don't do anything if we already have focus
380 gtk_widget_grab_focus( m_focusWidget
);
383 int wxComboBox::DoInsertItems(const wxArrayStringsAdapter
& items
,
385 void **clientData
, wxClientDataType type
)
387 wxCHECK_MSG( m_widget
!= NULL
, -1, wxT("invalid combobox") );
389 wxASSERT_MSG( !IsSorted() || (pos
== GetCount()),
390 _T("In a sorted combobox data could only be appended"));
392 const int count
= items
.GetCount();
397 if (!gtk_check_version(2,4,0))
399 GtkComboBox
* combobox
= GTK_COMBO_BOX( m_widget
);
400 for( int i
= 0; i
< count
; ++i
)
403 // If sorted, use this wxSortedArrayStrings to determine
404 // the right insertion point
406 n
= m_strings
->Add(items
[i
]);
408 gtk_combo_box_insert_text( combobox
, n
, wxGTK_CONV( items
[i
] ) );
410 m_clientData
.Insert( NULL
, n
);
411 AssignNewItemClientData(n
, clientData
, i
, type
);
419 GtkWidget
*list
= GTK_COMBO(m_widget
)->list
;
420 for( int i
= 0; i
< count
; ++i
)
423 // If sorted, use this wxSortedArrayStrings to determine
424 // the right insertion point
426 n
= m_strings
->Add(items
[i
]);
428 GtkWidget
*list_item
= gtk_list_item_new_with_label( wxGTK_CONV( items
[i
] ) );
430 // TODO construct a list with all items and call gtk_list_insert_items once?
431 GList
*gitem_list
= g_list_alloc ();
432 gitem_list
->data
= list_item
;
433 gtk_list_insert_items( GTK_LIST (list
), gitem_list
, n
);
435 m_clientData
.Insert( NULL
, n
);
436 AssignNewItemClientData(n
, clientData
, i
, type
);
438 if (GTK_WIDGET_REALIZED(m_widget
))
440 gtk_widget_realize( list_item
);
441 gtk_widget_realize( GTK_BIN(list_item
)->child
);
446 gtk_widget_show( list_item
);
452 InvalidateBestSize();
457 void wxComboBox::DoSetItemClientData(unsigned int n
, void* clientData
)
459 m_clientData
[n
] = clientData
;
462 void* wxComboBox::DoGetItemClientData(unsigned int n
) const
464 return m_clientData
[n
];
467 void wxComboBox::DoClear()
469 wxCHECK_RET( m_widget
!= NULL
, wxT("invalid combobox") );
474 if (!gtk_check_version(2,4,0))
476 GtkComboBox
* combobox
= GTK_COMBO_BOX( m_widget
);
477 const unsigned int count
= GetCount();
478 for (unsigned int i
= 0; i
< count
; i
++)
479 gtk_combo_box_remove_text( combobox
, 0 );
482 #endif // __WXGTK24__
484 GtkWidget
*list
= GTK_COMBO(m_widget
)->list
;
485 gtk_list_clear_items( GTK_LIST(list
), 0, GetCount() );
488 m_clientData
.Clear();
495 InvalidateBestSize();
498 void wxComboBox::DoDeleteOneItem(unsigned int n
)
500 wxCHECK_RET( m_widget
!= NULL
, wxT("invalid combobox") );
503 if (!gtk_check_version(2,4,0))
505 wxCHECK_RET( IsValid(n
), wxT("invalid index") );
507 GtkComboBox
* combobox
= GTK_COMBO_BOX( m_widget
);
508 gtk_combo_box_remove_text( combobox
, n
);
513 GtkList
*listbox
= GTK_LIST( GTK_COMBO(m_widget
)->list
);
515 GList
*child
= g_list_nth( listbox
->children
, n
);
519 wxFAIL_MSG(wxT("wrong index"));
525 GList
*list
= g_list_append( (GList
*) NULL
, child
->data
);
526 gtk_list_remove_items( listbox
, list
);
532 m_clientData
.RemoveAt( n
);
534 m_strings
->RemoveAt( n
);
536 InvalidateBestSize();
539 void wxComboBox::SetString(unsigned int n
, const wxString
&text
)
541 wxCHECK_RET( m_widget
!= NULL
, wxT("invalid combobox") );
544 if (!gtk_check_version(2,4,0))
546 GtkComboBox
* combobox
= GTK_COMBO_BOX( m_widget
);
547 wxCHECK_RET( IsValid(n
), wxT("invalid index") );
549 GtkTreeModel
*model
= gtk_combo_box_get_model( combobox
);
551 if (gtk_tree_model_iter_nth_child (model
, &iter
, NULL
, n
))
553 GValue value
= { 0, };
554 g_value_init( &value
, G_TYPE_STRING
);
555 g_value_set_string( &value
, wxGTK_CONV( text
) );
556 gtk_list_store_set_value( GTK_LIST_STORE(model
), &iter
, 0, &value
);
557 g_value_unset( &value
);
563 GtkWidget
*list
= GTK_COMBO(m_widget
)->list
;
565 GList
*child
= g_list_nth( GTK_LIST(list
)->children
, n
);
568 GtkBin
*bin
= GTK_BIN( child
->data
);
569 GtkLabel
*label
= GTK_LABEL( bin
->child
);
570 gtk_label_set_text(label
, wxGTK_CONV(text
));
574 wxFAIL_MSG( wxT("wxComboBox: wrong index") );
578 InvalidateBestSize();
581 int wxComboBox::FindString( const wxString
&item
, bool bCase
) const
583 wxCHECK_MSG( m_widget
!= NULL
, wxNOT_FOUND
, wxT("invalid combobox") );
586 if (!gtk_check_version(2,4,0))
588 GtkComboBox
* combobox
= GTK_COMBO_BOX( m_widget
);
589 GtkTreeModel
* model
= gtk_combo_box_get_model( combobox
);
591 gtk_tree_model_get_iter_first( model
, &iter
);
592 if (!gtk_list_store_iter_is_valid(GTK_LIST_STORE(model
), &iter
))
597 GValue value
= { 0, };
598 gtk_tree_model_get_value( model
, &iter
, 0, &value
);
599 wxString str
= wxGTK_CONV_BACK( g_value_get_string( &value
) );
600 g_value_unset( &value
);
602 if (item
.IsSameAs( str
, bCase
) )
607 } while (gtk_tree_model_iter_next( model
, &iter
));
612 GtkWidget
*list
= GTK_COMBO(m_widget
)->list
;
614 GList
*child
= GTK_LIST(list
)->children
;
618 GtkBin
*bin
= GTK_BIN( child
->data
);
619 GtkLabel
*label
= GTK_LABEL( bin
->child
);
620 wxString
str( wxGTK_CONV_BACK( gtk_label_get_text(label
) ) );
622 if (item
.IsSameAs( str
, bCase
) )
633 int wxComboBox::GetSelection() const
636 if (!gtk_check_version(2,4,0))
638 GtkComboBox
* combobox
= GTK_COMBO_BOX( m_widget
);
639 return gtk_combo_box_get_active( combobox
);
643 // if the popup is currently opened, use the selection as it had been
644 // before it dropped down
645 return g_SelectionBeforePopup
== wxID_NONE
? GetCurrentSelection()
646 : g_SelectionBeforePopup
;
649 int wxComboBox::GetCurrentSelection() const
651 wxCHECK_MSG( m_widget
!= NULL
, -1, wxT("invalid combobox") );
654 if (!gtk_check_version(2,4,0))
656 GtkComboBox
* combobox
= GTK_COMBO_BOX( m_widget
);
657 return gtk_combo_box_get_active( combobox
);
662 GtkWidget
*list
= GTK_COMBO(m_widget
)->list
;
664 GList
*selection
= GTK_LIST(list
)->selection
;
667 GList
*child
= GTK_LIST(list
)->children
;
671 if (child
->data
== selection
->data
) return count
;
681 wxString
wxComboBox::GetString(unsigned int n
) const
683 wxCHECK_MSG( m_widget
!= NULL
, wxEmptyString
, wxT("invalid combobox") );
688 if (!gtk_check_version(2,4,0))
690 GtkComboBox
* combobox
= GTK_COMBO_BOX( m_widget
);
691 GtkTreeModel
*model
= gtk_combo_box_get_model( combobox
);
693 if (gtk_tree_model_iter_nth_child (model
, &iter
, NULL
, n
))
695 GValue value
= { 0, };
696 gtk_tree_model_get_value( model
, &iter
, 0, &value
);
697 wxString tmp
= wxGTK_CONV_BACK( g_value_get_string( &value
) );
698 g_value_unset( &value
);
705 GtkWidget
*list
= GTK_COMBO(m_widget
)->list
;
707 GList
*child
= g_list_nth( GTK_LIST(list
)->children
, n
);
710 GtkBin
*bin
= GTK_BIN( child
->data
);
711 GtkLabel
*label
= GTK_LABEL( bin
->child
);
712 str
= wxGTK_CONV_BACK( gtk_label_get_text(label
) );
716 wxFAIL_MSG( wxT("wxComboBox: wrong index") );
723 unsigned int wxComboBox::GetCount() const
725 wxCHECK_MSG( m_widget
!= NULL
, 0, wxT("invalid combobox") );
728 if (!gtk_check_version(2,4,0))
730 GtkComboBox
* combobox
= GTK_COMBO_BOX( m_widget
);
731 GtkTreeModel
* model
= gtk_combo_box_get_model( combobox
);
733 gtk_tree_model_get_iter_first( model
, &iter
);
734 if (!gtk_list_store_iter_is_valid(GTK_LIST_STORE(model
), &iter
))
736 unsigned int ret
= 1;
737 while (gtk_tree_model_iter_next( model
, &iter
))
744 GtkWidget
*list
= GTK_COMBO(m_widget
)->list
;
746 GList
*child
= GTK_LIST(list
)->children
;
747 unsigned int count
= 0;
757 void wxComboBox::SetSelection( int n
)
759 wxCHECK_RET( m_widget
!= NULL
, wxT("invalid combobox") );
764 if (!gtk_check_version(2,4,0))
766 GtkComboBox
* combobox
= GTK_COMBO_BOX( m_widget
);
767 gtk_combo_box_set_active( combobox
, n
);
772 GtkWidget
*list
= GTK_COMBO(m_widget
)->list
;
773 gtk_list_unselect_item( GTK_LIST(list
), m_prevSelection
);
774 gtk_list_select_item( GTK_LIST(list
), n
);
781 void wxComboBox::OnChar( wxKeyEvent
&event
)
783 if ( event
.GetKeyCode() == WXK_RETURN
)
785 // GTK automatically selects an item if its in the list
786 wxCommandEvent
eventEnter(wxEVT_COMMAND_TEXT_ENTER
, GetId());
787 eventEnter
.SetString( GetValue() );
788 eventEnter
.SetInt( GetSelection() );
789 eventEnter
.SetEventObject( this );
791 if (!GetEventHandler()->ProcessEvent( eventEnter
))
793 // This will invoke the dialog default action, such
794 // as the clicking the default button.
796 wxWindow
*top_frame
= m_parent
;
797 while (top_frame
->GetParent() && !(top_frame
->IsTopLevel()))
798 top_frame
= top_frame
->GetParent();
800 if (top_frame
&& GTK_IS_WINDOW(top_frame
->m_widget
))
802 GtkWindow
*window
= GTK_WINDOW(top_frame
->m_widget
);
804 if (window
->default_widget
)
805 gtk_widget_activate (window
->default_widget
);
809 // Catch GTK event so that GTK doesn't open the drop
810 // down list upon RETURN.
817 void wxComboBox::DisableEvents()
820 if (!gtk_check_version(2,4,0))
822 g_signal_handlers_block_by_func(GTK_BIN(m_widget
)->child
,
823 (gpointer
)gtkcombobox_text_changed_callback
, this);
825 g_signal_handlers_block_by_func(m_widget
,
826 (gpointer
)gtkcombobox_changed_callback
, this);
831 g_signal_handlers_block_by_func(GTK_COMBO(m_widget
)->list
,
832 (gpointer
) gtkcombo_combo_select_child_callback
, this);
834 g_signal_handlers_block_by_func(GTK_COMBO(m_widget
)->entry
,
835 (gpointer
) gtkcombo_text_changed_callback
, this);
839 void wxComboBox::EnableEvents()
842 if (!gtk_check_version(2,4,0))
844 g_signal_handlers_unblock_by_func(GTK_BIN(m_widget
)->child
,
845 (gpointer
)gtkcombobox_text_changed_callback
, this);
847 g_signal_handlers_unblock_by_func(m_widget
,
848 (gpointer
)gtkcombobox_changed_callback
, this);
853 g_signal_handlers_unblock_by_func(GTK_COMBO(m_widget
)->list
,
854 (gpointer
) gtkcombo_combo_select_child_callback
, this);
856 g_signal_handlers_unblock_by_func(GTK_COMBO(m_widget
)->entry
,
857 (gpointer
) gtkcombo_text_changed_callback
, this);
861 void wxComboBox::OnSize( wxSizeEvent
&event
)
864 if (!gtk_check_version(2,4,0))
871 // NB: In some situations (e.g. on non-first page of a wizard, if the
872 // size used is default size), GtkCombo widget is resized correctly,
873 // but it's look is not updated, it's rendered as if it was much wider.
874 // No other widgets are affected, so it looks like a bug in GTK+.
875 // Manually requesting resize calculation (as gtk_pizza_set_size does)
877 if (GTK_WIDGET_VISIBLE(m_widget
))
878 gtk_widget_queue_resize(m_widget
);
884 void wxComboBox::DoApplyWidgetStyle(GtkRcStyle
*style
)
887 if (!gtk_check_version(2,4,0))
894 // gtk_widget_modify_style( GTK_COMBO(m_widget)->button, syle );
896 gtk_widget_modify_style( GTK_COMBO(m_widget
)->entry
, style
);
897 gtk_widget_modify_style( GTK_COMBO(m_widget
)->list
, style
);
899 GtkList
*list
= GTK_LIST( GTK_COMBO(m_widget
)->list
);
900 GList
*child
= list
->children
;
903 gtk_widget_modify_style( GTK_WIDGET(child
->data
), style
);
905 GtkBin
*bin
= GTK_BIN(child
->data
);
906 gtk_widget_modify_style( bin
->child
, style
);
913 GtkWidget
* wxComboBox::GetConnectWidget()
915 GtkEntry
*entry
= NULL
;
917 if (!gtk_check_version(2,4,0))
918 entry
= GTK_ENTRY( GTK_BIN(m_widget
)->child
);
921 entry
= GTK_ENTRY( GTK_COMBO(m_widget
)->entry
);
923 return GTK_WIDGET( entry
);
926 GdkWindow
*wxComboBox::GTKGetWindow(wxArrayGdkWindows
& windows
) const
929 if (!gtk_check_version(2,4,0))
931 wxUnusedVar(windows
);
933 return GTK_ENTRY(GTK_BIN(m_widget
)->child
)->text_area
;
938 windows
.push_back(GTK_ENTRY(GTK_COMBO(m_widget
)->entry
)->text_area
);
939 windows
.push_back(GTK_COMBO(m_widget
)->button
->window
);
941 // indicate that we return multiple windows in the windows array
946 wxSize
wxComboBox::DoGetBestSize() const
948 wxSize
ret( wxControl::DoGetBestSize() );
950 // we know better our horizontal extent: it depends on the longest string
955 unsigned int count
= GetCount();
956 for ( unsigned int n
= 0; n
< count
; n
++ )
958 GetTextExtent(GetString(n
), &width
, NULL
, NULL
, NULL
);
964 // empty combobox should have some reasonable default size too
974 wxComboBox::GetClassDefaultAttributes(wxWindowVariant
WXUNUSED(variant
))
977 if (!gtk_check_version(2,4,0))
978 return GetDefaultAttributesFromGTKWidget(gtk_combo_box_entry_new
, true);
981 return GetDefaultAttributesFromGTKWidget(gtk_combo_new
, true);
984 // ----------------------------------------------------------------------------
985 // standard event handling
986 // ----------------------------------------------------------------------------
988 void wxComboBox::OnCut(wxCommandEvent
& WXUNUSED(event
))
993 void wxComboBox::OnCopy(wxCommandEvent
& WXUNUSED(event
))
998 void wxComboBox::OnPaste(wxCommandEvent
& WXUNUSED(event
))
1003 void wxComboBox::OnUndo(wxCommandEvent
& WXUNUSED(event
))
1008 void wxComboBox::OnRedo(wxCommandEvent
& WXUNUSED(event
))
1013 void wxComboBox::OnDelete(wxCommandEvent
& WXUNUSED(event
))
1016 GetSelection(& from
, & to
);
1017 if (from
!= -1 && to
!= -1)
1021 void wxComboBox::OnSelectAll(wxCommandEvent
& WXUNUSED(event
))
1023 SetSelection(-1, -1);
1026 void wxComboBox::OnUpdateCut(wxUpdateUIEvent
& event
)
1028 event
.Enable( CanCut() );
1031 void wxComboBox::OnUpdateCopy(wxUpdateUIEvent
& event
)
1033 event
.Enable( CanCopy() );
1036 void wxComboBox::OnUpdatePaste(wxUpdateUIEvent
& event
)
1038 event
.Enable( CanPaste() );
1041 void wxComboBox::OnUpdateUndo(wxUpdateUIEvent
& event
)
1043 event
.Enable( CanUndo() );
1046 void wxComboBox::OnUpdateRedo(wxUpdateUIEvent
& event
)
1048 event
.Enable( CanRedo() );
1051 void wxComboBox::OnUpdateDelete(wxUpdateUIEvent
& event
)
1053 event
.Enable(HasSelection() && IsEditable()) ;
1056 void wxComboBox::OnUpdateSelectAll(wxUpdateUIEvent
& event
)
1058 event
.Enable(GetLastPosition() > 0);
1061 #endif // wxUSE_COMBOBOX