]>
Commit | Line | Data |
---|---|---|
53010e52 RR |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: combobox.cpp | |
3 | // Purpose: | |
4 | // Author: Robert Roebling | |
dbf858b5 | 5 | // Id: $Id$ |
01111366 | 6 | // Copyright: (c) 1998 Robert Roebling |
805dd538 | 7 | // Licence: wxWindows licence |
53010e52 RR |
8 | ///////////////////////////////////////////////////////////////////////////// |
9 | ||
10 | #ifdef __GNUG__ | |
11 | #pragma implementation "combobox.h" | |
12 | #endif | |
13 | ||
14 | #include "wx/combobox.h" | |
72a16063 | 15 | #include "wx/settings.h" |
ac57418f | 16 | |
1a5a8367 | 17 | #include <wx/intl.h> |
53010e52 | 18 | |
83624f79 RR |
19 | #include "gdk/gdk.h" |
20 | #include "gtk/gtk.h" | |
21 | ||
acfd422a RR |
22 | //----------------------------------------------------------------------------- |
23 | // idle system | |
24 | //----------------------------------------------------------------------------- | |
25 | ||
26 | extern void wxapp_install_idle_handler(); | |
27 | extern bool g_isIdle; | |
28 | ||
47908e25 RR |
29 | //----------------------------------------------------------------------------- |
30 | // data | |
31 | //----------------------------------------------------------------------------- | |
32 | ||
33 | extern bool g_blockEventsOnDrag; | |
34 | ||
53010e52 | 35 | //----------------------------------------------------------------------------- |
e1e955e1 | 36 | // "select" |
47908e25 | 37 | //----------------------------------------------------------------------------- |
47908e25 | 38 | |
8a85884a VZ |
39 | static void |
40 | gtk_combo_clicked_callback( GtkWidget *WXUNUSED(widget), wxComboBox *combo ) | |
53010e52 | 41 | { |
acfd422a | 42 | if (g_isIdle) wxapp_install_idle_handler(); |
8a85884a | 43 | |
acfd422a RR |
44 | if (!combo->HasVMT()) return; |
45 | ||
46 | if (g_blockEventsOnDrag) return; | |
805dd538 | 47 | |
fd0eed64 RR |
48 | if (combo->m_alreadySent) |
49 | { | |
50 | combo->m_alreadySent = FALSE; | |
51 | return; | |
52 | } | |
47908e25 | 53 | |
fd0eed64 | 54 | combo->m_alreadySent = TRUE; |
805dd538 | 55 | |
8a85884a | 56 | wxCommandEvent event( wxEVT_COMMAND_COMBOBOX_SELECTED, combo->GetId() ); |
fd0eed64 | 57 | event.SetInt( combo->GetSelection() ); |
29006414 | 58 | event.SetString( combo->GetStringSelection() ); |
8a85884a | 59 | event.SetEventObject( combo ); |
ec5d85fb | 60 | |
8a85884a | 61 | combo->GetEventHandler()->ProcessEvent( event ); |
6de97a3b | 62 | } |
47908e25 | 63 | |
0c77152e RR |
64 | //----------------------------------------------------------------------------- |
65 | // "changed" | |
66 | //----------------------------------------------------------------------------- | |
67 | ||
eeccd5d9 | 68 | static void |
0c77152e RR |
69 | gtk_text_changed_callback( GtkWidget *WXUNUSED(widget), wxComboBox *combo ) |
70 | { | |
acfd422a RR |
71 | if (g_isIdle) wxapp_install_idle_handler(); |
72 | ||
8a85884a | 73 | wxCommandEvent event( wxEVT_COMMAND_TEXT_UPDATED, combo->GetId() ); |
29006414 | 74 | event.SetString( combo->GetValue() ); |
0c77152e RR |
75 | event.SetEventObject( combo ); |
76 | combo->GetEventHandler()->ProcessEvent( event ); | |
0c77152e RR |
77 | } |
78 | ||
e1e955e1 RR |
79 | //----------------------------------------------------------------------------- |
80 | // wxComboBox | |
53010e52 RR |
81 | //----------------------------------------------------------------------------- |
82 | ||
83 | IMPLEMENT_DYNAMIC_CLASS(wxComboBox,wxControl) | |
84 | ||
b4071e91 | 85 | BEGIN_EVENT_TABLE(wxComboBox, wxControl) |
fd0eed64 | 86 | EVT_SIZE(wxComboBox::OnSize) |
8a85884a | 87 | EVT_CHAR(wxComboBox::OnChar) |
b4071e91 RR |
88 | END_EVENT_TABLE() |
89 | ||
fd0eed64 RR |
90 | bool wxComboBox::Create( wxWindow *parent, wxWindowID id, const wxString& value, |
91 | const wxPoint& pos, const wxSize& size, | |
92 | int n, const wxString choices[], | |
805dd538 VZ |
93 | long style, const wxValidator& validator, |
94 | const wxString& name ) | |
53010e52 | 95 | { |
fd0eed64 RR |
96 | m_alreadySent = FALSE; |
97 | m_needParent = TRUE; | |
b292e2f5 | 98 | m_acceptsFocus = TRUE; |
805dd538 | 99 | |
fd0eed64 | 100 | PreCreation( parent, id, pos, size, style, name ); |
805dd538 | 101 | |
fd0eed64 | 102 | SetValidator( validator ); |
6de97a3b | 103 | |
fd0eed64 | 104 | m_widget = gtk_combo_new(); |
805dd538 | 105 | |
8a85884a VZ |
106 | // make it more useable |
107 | gtk_combo_set_use_arrows_always(GTK_COMBO(m_widget), TRUE); | |
108 | ||
fd0eed64 | 109 | wxSize newSize = size; |
8a85884a VZ |
110 | if (newSize.x == -1) |
111 | newSize.x = 100; | |
112 | if (newSize.y == -1) | |
113 | newSize.y = 26; | |
fd0eed64 | 114 | SetSize( newSize.x, newSize.y ); |
805dd538 | 115 | |
fd0eed64 | 116 | GtkWidget *list = GTK_COMBO(m_widget)->list; |
805dd538 | 117 | |
fd0eed64 RR |
118 | for (int i = 0; i < n; i++) |
119 | { | |
93c5dd39 | 120 | GtkWidget *list_item = gtk_list_item_new_with_label( choices[i].mbc_str() ); |
805dd538 | 121 | |
fd0eed64 | 122 | m_clientDataList.Append( (wxObject*)NULL ); |
f5e27805 | 123 | m_clientObjectList.Append( (wxObject*)NULL ); |
805dd538 | 124 | |
fd0eed64 | 125 | gtk_container_add( GTK_CONTAINER(list), list_item ); |
805dd538 | 126 | |
fd0eed64 | 127 | gtk_widget_show( list_item ); |
805dd538 VZ |
128 | |
129 | gtk_signal_connect( GTK_OBJECT(list_item), "select", | |
fd0eed64 RR |
130 | GTK_SIGNAL_FUNC(gtk_combo_clicked_callback), (gpointer)this ); |
131 | } | |
805dd538 | 132 | |
fd0eed64 | 133 | m_parent->AddChild( this ); |
6ca41e57 | 134 | |
fd0eed64 | 135 | (m_parent->m_insertCallback)( m_parent, this ); |
805dd538 | 136 | |
fd0eed64 | 137 | PostCreation(); |
53010e52 | 138 | |
fd0eed64 | 139 | ConnectWidget( GTK_COMBO(m_widget)->button ); |
805dd538 | 140 | |
fd0eed64 | 141 | if (!value.IsNull()) SetValue( value ); |
805dd538 | 142 | |
a260fe6a RR |
143 | if (style & wxCB_READONLY) |
144 | gtk_entry_set_editable( GTK_ENTRY( GTK_COMBO(m_widget)->entry ), FALSE ); | |
145 | ||
0c77152e RR |
146 | gtk_signal_connect( GTK_OBJECT(GTK_COMBO(m_widget)->entry), "changed", |
147 | GTK_SIGNAL_FUNC(gtk_text_changed_callback), (gpointer)this); | |
805dd538 | 148 | |
72a16063 | 149 | SetBackgroundColour( wxSystemSettings::GetSystemColour( wxSYS_COLOUR_WINDOW ) ); |
fd0eed64 | 150 | SetForegroundColour( parent->GetForegroundColour() ); |
a7ac4461 | 151 | SetFont( parent->GetFont() ); |
f96aa4d9 | 152 | |
fd0eed64 | 153 | Show( TRUE ); |
805dd538 | 154 | |
fd0eed64 RR |
155 | return TRUE; |
156 | } | |
157 | ||
158 | wxComboBox::~wxComboBox() | |
159 | { | |
160 | wxNode *node = m_clientDataList.First(); | |
161 | while (node) | |
162 | { | |
163 | wxClientData *cd = (wxClientData*)node->Data(); | |
164 | if (cd) delete cd; | |
165 | node = node->Next(); | |
166 | } | |
167 | m_clientDataList.Clear(); | |
6de97a3b | 168 | } |
53010e52 | 169 | |
fd0eed64 | 170 | void wxComboBox::AppendCommon( const wxString &item ) |
53010e52 | 171 | { |
93c5dd39 | 172 | wxCHECK_RET( m_widget != NULL, _T("invalid combobox") ); |
805dd538 | 173 | |
fd0eed64 | 174 | GtkWidget *list = GTK_COMBO(m_widget)->list; |
805dd538 | 175 | |
93c5dd39 | 176 | GtkWidget *list_item = gtk_list_item_new_with_label( item.mbc_str() ); |
805dd538 | 177 | |
ec5d85fb RR |
178 | gtk_container_add( GTK_CONTAINER(list), list_item ); |
179 | ||
805dd538 | 180 | gtk_signal_connect( GTK_OBJECT(list_item), "select", |
fd0eed64 | 181 | GTK_SIGNAL_FUNC(gtk_combo_clicked_callback), (gpointer)this ); |
805dd538 | 182 | |
2b07d713 RR |
183 | if (GTK_WIDGET_REALIZED(m_widget)) |
184 | { | |
185 | gtk_widget_realize( list_item ); | |
186 | gtk_widget_realize( GTK_BIN(list_item)->child ); | |
187 | ||
188 | if (m_widgetStyle) ApplyWidgetStyle(); | |
189 | } | |
805dd538 | 190 | |
fd0eed64 | 191 | gtk_widget_show( list_item ); |
6de97a3b | 192 | } |
53010e52 RR |
193 | |
194 | void wxComboBox::Append( const wxString &item ) | |
47908e25 | 195 | { |
f5e27805 RR |
196 | m_clientDataList.Append( (wxObject*) NULL ); |
197 | m_clientObjectList.Append( (wxObject*) NULL ); | |
805dd538 | 198 | |
fd0eed64 | 199 | AppendCommon( item ); |
6de97a3b | 200 | } |
47908e25 | 201 | |
fd0eed64 | 202 | void wxComboBox::Append( const wxString &item, void *clientData ) |
53010e52 | 203 | { |
f5e27805 RR |
204 | m_clientDataList.Append( (wxObject*) clientData ); |
205 | m_clientObjectList.Append( (wxObject*)NULL ); | |
805dd538 | 206 | |
fd0eed64 | 207 | AppendCommon( item ); |
6de97a3b | 208 | } |
53010e52 | 209 | |
fd0eed64 | 210 | void wxComboBox::Append( const wxString &item, wxClientData *clientData ) |
53010e52 | 211 | { |
f5e27805 RR |
212 | m_clientDataList.Append( (wxObject*) NULL ); |
213 | m_clientObjectList.Append( (wxObject*) clientData ); | |
805dd538 | 214 | |
fd0eed64 RR |
215 | AppendCommon( item ); |
216 | } | |
217 | ||
218 | void wxComboBox::SetClientData( int n, void* clientData ) | |
219 | { | |
93c5dd39 | 220 | wxCHECK_RET( m_widget != NULL, _T("invalid combobox") ); |
805dd538 | 221 | |
fd0eed64 RR |
222 | wxNode *node = m_clientDataList.Nth( n ); |
223 | if (!node) return; | |
805dd538 | 224 | |
f5e27805 | 225 | node->SetData( (wxObject*) clientData ); |
6de97a3b | 226 | } |
53010e52 | 227 | |
fd0eed64 | 228 | void* wxComboBox::GetClientData( int n ) |
53010e52 | 229 | { |
93c5dd39 | 230 | wxCHECK_MSG( m_widget != NULL, NULL, _T("invalid combobox") ); |
805dd538 | 231 | |
fd0eed64 RR |
232 | wxNode *node = m_clientDataList.Nth( n ); |
233 | if (!node) return NULL; | |
805dd538 | 234 | |
f5e27805 | 235 | return node->Data(); |
fd0eed64 RR |
236 | } |
237 | ||
238 | void wxComboBox::SetClientObject( int n, wxClientData* clientData ) | |
239 | { | |
93c5dd39 | 240 | wxCHECK_RET( m_widget != NULL, _T("invalid combobox") ); |
805dd538 | 241 | |
f5e27805 | 242 | wxNode *node = m_clientObjectList.Nth( n ); |
fd0eed64 | 243 | if (!node) return; |
805dd538 | 244 | |
fd0eed64 RR |
245 | wxClientData *cd = (wxClientData*) node->Data(); |
246 | if (cd) delete cd; | |
805dd538 | 247 | |
fd0eed64 | 248 | node->SetData( (wxObject*) clientData ); |
6de97a3b | 249 | } |
53010e52 | 250 | |
fd0eed64 | 251 | wxClientData* wxComboBox::GetClientObject( int n ) |
53010e52 | 252 | { |
93c5dd39 | 253 | wxCHECK_MSG( m_widget != NULL, (wxClientData*)NULL, _T("invalid combobox") ); |
805dd538 | 254 | |
fd0eed64 RR |
255 | wxNode *node = m_clientDataList.Nth( n ); |
256 | if (!node) return (wxClientData*) NULL; | |
805dd538 | 257 | |
fd0eed64 RR |
258 | return (wxClientData*) node->Data(); |
259 | } | |
260 | ||
261 | void wxComboBox::Clear() | |
262 | { | |
93c5dd39 | 263 | wxCHECK_RET( m_widget != NULL, _T("invalid combobox") ); |
805dd538 | 264 | |
fd0eed64 RR |
265 | GtkWidget *list = GTK_COMBO(m_widget)->list; |
266 | gtk_list_clear_items( GTK_LIST(list), 0, Number() ); | |
805dd538 | 267 | |
f5e27805 | 268 | wxNode *node = m_clientObjectList.First(); |
fd0eed64 RR |
269 | while (node) |
270 | { | |
271 | wxClientData *cd = (wxClientData*)node->Data(); | |
272 | if (cd) delete cd; | |
273 | node = node->Next(); | |
274 | } | |
f5e27805 | 275 | m_clientObjectList.Clear(); |
805dd538 | 276 | |
fd0eed64 | 277 | m_clientDataList.Clear(); |
6de97a3b | 278 | } |
53010e52 | 279 | |
fd0eed64 | 280 | void wxComboBox::Delete( int n ) |
53010e52 | 281 | { |
93c5dd39 | 282 | wxCHECK_RET( m_widget != NULL, _T("invalid combobox") ); |
805dd538 | 283 | |
fd0eed64 | 284 | GtkList *listbox = GTK_LIST( GTK_COMBO(m_widget)->list ); |
805dd538 | 285 | |
fd0eed64 | 286 | GList *child = g_list_nth( listbox->children, n ); |
805dd538 | 287 | |
fd0eed64 RR |
288 | if (!child) |
289 | { | |
93c5dd39 | 290 | wxFAIL_MSG(_T("wrong index")); |
fd0eed64 RR |
291 | return; |
292 | } | |
805dd538 | 293 | |
bbe0af5b | 294 | GList *list = g_list_append( (GList*) NULL, child->data ); |
fd0eed64 RR |
295 | gtk_list_remove_items( listbox, list ); |
296 | g_list_free( list ); | |
805dd538 | 297 | |
f5e27805 RR |
298 | wxNode *node = m_clientObjectList.Nth( n ); |
299 | if (node) | |
fd0eed64 RR |
300 | { |
301 | wxClientData *cd = (wxClientData*)node->Data(); | |
302 | if (cd) delete cd; | |
f5e27805 RR |
303 | m_clientObjectList.DeleteNode( node ); |
304 | } | |
805dd538 | 305 | |
f5e27805 RR |
306 | node = m_clientDataList.Nth( n ); |
307 | if (node) | |
308 | { | |
fd0eed64 RR |
309 | m_clientDataList.DeleteNode( node ); |
310 | } | |
6de97a3b | 311 | } |
53010e52 | 312 | |
fd0eed64 | 313 | int wxComboBox::FindString( const wxString &item ) |
53010e52 | 314 | { |
93c5dd39 | 315 | wxCHECK_MSG( m_widget != NULL, -1, _T("invalid combobox") ); |
805dd538 | 316 | |
fd0eed64 | 317 | GtkWidget *list = GTK_COMBO(m_widget)->list; |
805dd538 | 318 | |
53010e52 RR |
319 | GList *child = GTK_LIST(list)->children; |
320 | int count = 0; | |
321 | while (child) | |
322 | { | |
fd0eed64 RR |
323 | GtkBin *bin = GTK_BIN( child->data ); |
324 | GtkLabel *label = GTK_LABEL( bin->child ); | |
7cf8cb48 VZ |
325 | if (item == label->label) |
326 | return count; | |
fd0eed64 RR |
327 | count++; |
328 | child = child->next; | |
329 | } | |
805dd538 | 330 | |
7cf8cb48 | 331 | return wxNOT_FOUND; |
fd0eed64 RR |
332 | } |
333 | ||
334 | int wxComboBox::GetSelection() const | |
335 | { | |
93c5dd39 | 336 | wxCHECK_MSG( m_widget != NULL, -1, _T("invalid combobox") ); |
805dd538 | 337 | |
fd0eed64 | 338 | GtkWidget *list = GTK_COMBO(m_widget)->list; |
805dd538 | 339 | |
fd0eed64 RR |
340 | GList *selection = GTK_LIST(list)->selection; |
341 | if (selection) | |
342 | { | |
343 | GList *child = GTK_LIST(list)->children; | |
344 | int count = 0; | |
345 | while (child) | |
346 | { | |
347 | if (child->data == selection->data) return count; | |
348 | count++; | |
349 | child = child->next; | |
350 | } | |
6de97a3b | 351 | } |
805dd538 | 352 | |
93c5dd39 | 353 | wxFAIL_MSG( _T("wxComboBox: no selection") ); |
805dd538 | 354 | |
fd0eed64 | 355 | return -1; |
6de97a3b | 356 | } |
53010e52 | 357 | |
debe6624 | 358 | wxString wxComboBox::GetString( int n ) const |
53010e52 | 359 | { |
93c5dd39 | 360 | wxCHECK_MSG( m_widget != NULL, _T(""), _T("invalid combobox") ); |
805dd538 | 361 | |
fd0eed64 | 362 | GtkWidget *list = GTK_COMBO(m_widget)->list; |
805dd538 | 363 | |
7cf8cb48 | 364 | wxString str; |
fd0eed64 RR |
365 | GList *child = g_list_nth( GTK_LIST(list)->children, n ); |
366 | if (child) | |
367 | { | |
368 | GtkBin *bin = GTK_BIN( child->data ); | |
369 | GtkLabel *label = GTK_LABEL( bin->child ); | |
7cf8cb48 VZ |
370 | str = label->label; |
371 | } | |
372 | else | |
373 | { | |
93c5dd39 | 374 | wxFAIL_MSG( _T("wxComboBox: wrong index") ); |
fd0eed64 | 375 | } |
805dd538 | 376 | |
7cf8cb48 | 377 | return str; |
6de97a3b | 378 | } |
53010e52 | 379 | |
fd0eed64 | 380 | wxString wxComboBox::GetStringSelection() const |
53010e52 | 381 | { |
93c5dd39 | 382 | wxCHECK_MSG( m_widget != NULL, _T(""), _T("invalid combobox") ); |
805dd538 | 383 | |
fd0eed64 | 384 | GtkWidget *list = GTK_COMBO(m_widget)->list; |
805dd538 | 385 | |
fd0eed64 RR |
386 | GList *selection = GTK_LIST(list)->selection; |
387 | if (selection) | |
388 | { | |
389 | GtkBin *bin = GTK_BIN( selection->data ); | |
390 | wxString tmp = GTK_LABEL( bin->child )->label; | |
391 | return tmp; | |
392 | } | |
805dd538 | 393 | |
93c5dd39 | 394 | wxFAIL_MSG( _T("wxComboBox: no selection") ); |
805dd538 | 395 | |
93c5dd39 | 396 | return _T(""); |
6de97a3b | 397 | } |
53010e52 | 398 | |
fd0eed64 | 399 | int wxComboBox::Number() const |
53010e52 | 400 | { |
93c5dd39 | 401 | wxCHECK_MSG( m_widget != NULL, 0, _T("invalid combobox") ); |
805dd538 | 402 | |
fd0eed64 | 403 | GtkWidget *list = GTK_COMBO(m_widget)->list; |
805dd538 | 404 | |
fd0eed64 RR |
405 | GList *child = GTK_LIST(list)->children; |
406 | int count = 0; | |
407 | while (child) { count++; child = child->next; } | |
408 | return count; | |
6de97a3b | 409 | } |
53010e52 | 410 | |
debe6624 | 411 | void wxComboBox::SetSelection( int n ) |
53010e52 | 412 | { |
93c5dd39 | 413 | wxCHECK_RET( m_widget != NULL, _T("invalid combobox") ); |
805dd538 | 414 | |
fd0eed64 RR |
415 | GtkWidget *list = GTK_COMBO(m_widget)->list; |
416 | gtk_list_select_item( GTK_LIST(list), n ); | |
6de97a3b | 417 | } |
53010e52 | 418 | |
47908e25 RR |
419 | void wxComboBox::SetStringSelection( const wxString &string ) |
420 | { | |
93c5dd39 | 421 | wxCHECK_RET( m_widget != NULL, _T("invalid combobox") ); |
805dd538 | 422 | |
fd0eed64 RR |
423 | int res = FindString( string ); |
424 | if (res == -1) return; | |
425 | SetSelection( res ); | |
6de97a3b | 426 | } |
47908e25 | 427 | |
fd0eed64 | 428 | wxString wxComboBox::GetValue() const |
53010e52 | 429 | { |
fd0eed64 RR |
430 | GtkWidget *entry = GTK_COMBO(m_widget)->entry; |
431 | wxString tmp = gtk_entry_get_text( GTK_ENTRY(entry) ); | |
432 | return tmp; | |
6de97a3b | 433 | } |
53010e52 RR |
434 | |
435 | void wxComboBox::SetValue( const wxString& value ) | |
436 | { | |
93c5dd39 | 437 | wxCHECK_RET( m_widget != NULL, _T("invalid combobox") ); |
805dd538 | 438 | |
fd0eed64 | 439 | GtkWidget *entry = GTK_COMBO(m_widget)->entry; |
93c5dd39 | 440 | wxString tmp = _T(""); |
fd0eed64 | 441 | if (!value.IsNull()) tmp = value; |
93c5dd39 | 442 | gtk_entry_set_text( GTK_ENTRY(entry), tmp.mbc_str() ); |
6de97a3b | 443 | } |
53010e52 | 444 | |
fd0eed64 | 445 | void wxComboBox::Copy() |
53010e52 | 446 | { |
93c5dd39 | 447 | wxCHECK_RET( m_widget != NULL, _T("invalid combobox") ); |
805dd538 | 448 | |
fd0eed64 | 449 | GtkWidget *entry = GTK_COMBO(m_widget)->entry; |
d345e841 | 450 | #if (GTK_MINOR_VERSION > 0) |
fd0eed64 | 451 | gtk_editable_copy_clipboard( GTK_EDITABLE(entry) ); |
75ed1d15 | 452 | #else |
fd0eed64 | 453 | gtk_editable_copy_clipboard( GTK_EDITABLE(entry), 0 ); |
75ed1d15 | 454 | #endif |
6de97a3b | 455 | } |
53010e52 | 456 | |
fd0eed64 | 457 | void wxComboBox::Cut() |
53010e52 | 458 | { |
93c5dd39 | 459 | wxCHECK_RET( m_widget != NULL, _T("invalid combobox") ); |
805dd538 | 460 | |
fd0eed64 | 461 | GtkWidget *entry = GTK_COMBO(m_widget)->entry; |
d345e841 | 462 | #if (GTK_MINOR_VERSION > 0) |
fd0eed64 | 463 | gtk_editable_cut_clipboard( GTK_EDITABLE(entry) ); |
75ed1d15 | 464 | #else |
fd0eed64 | 465 | gtk_editable_cut_clipboard( GTK_EDITABLE(entry), 0 ); |
75ed1d15 | 466 | #endif |
6de97a3b | 467 | } |
53010e52 | 468 | |
fd0eed64 | 469 | void wxComboBox::Paste() |
53010e52 | 470 | { |
93c5dd39 | 471 | wxCHECK_RET( m_widget != NULL, _T("invalid combobox") ); |
805dd538 | 472 | |
fd0eed64 | 473 | GtkWidget *entry = GTK_COMBO(m_widget)->entry; |
d345e841 | 474 | #if (GTK_MINOR_VERSION > 0) |
fd0eed64 | 475 | gtk_editable_paste_clipboard( GTK_EDITABLE(entry) ); |
75ed1d15 | 476 | #else |
fd0eed64 | 477 | gtk_editable_paste_clipboard( GTK_EDITABLE(entry), 0 ); |
75ed1d15 | 478 | #endif |
6de97a3b | 479 | } |
53010e52 | 480 | |
debe6624 | 481 | void wxComboBox::SetInsertionPoint( long pos ) |
53010e52 | 482 | { |
93c5dd39 | 483 | wxCHECK_RET( m_widget != NULL, _T("invalid combobox") ); |
805dd538 | 484 | |
fd0eed64 | 485 | GtkWidget *entry = GTK_COMBO(m_widget)->entry; |
073c8fe9 | 486 | gtk_entry_set_position( GTK_ENTRY(entry), (int)pos ); |
6de97a3b | 487 | } |
53010e52 | 488 | |
fd0eed64 | 489 | void wxComboBox::SetInsertionPointEnd() |
53010e52 | 490 | { |
93c5dd39 | 491 | wxCHECK_RET( m_widget != NULL, _T("invalid combobox") ); |
805dd538 VZ |
492 | |
493 | SetInsertionPoint( -1 ); | |
6de97a3b | 494 | } |
53010e52 | 495 | |
fd0eed64 | 496 | long wxComboBox::GetInsertionPoint() const |
53010e52 | 497 | { |
fd0eed64 RR |
498 | GtkWidget *entry = GTK_COMBO(m_widget)->entry; |
499 | return (long) GTK_EDITABLE(entry)->current_pos; | |
6de97a3b | 500 | } |
53010e52 | 501 | |
fd0eed64 | 502 | long wxComboBox::GetLastPosition() const |
53010e52 | 503 | { |
fd0eed64 RR |
504 | GtkWidget *entry = GTK_COMBO(m_widget)->entry; |
505 | int pos = GTK_ENTRY(entry)->text_length; | |
506 | return (long) pos-1; | |
6de97a3b | 507 | } |
53010e52 | 508 | |
debe6624 | 509 | void wxComboBox::Replace( long from, long to, const wxString& value ) |
53010e52 | 510 | { |
93c5dd39 OK |
511 | wxCHECK_RET( m_widget != NULL, _T("invalid combobox") ); |
512 | // FIXME: not quite sure how to do this method right in multibyte mode | |
805dd538 | 513 | |
fd0eed64 RR |
514 | GtkWidget *entry = GTK_COMBO(m_widget)->entry; |
515 | gtk_editable_delete_text( GTK_EDITABLE(entry), (gint)from, (gint)to ); | |
516 | if (value.IsNull()) return; | |
517 | gint pos = (gint)to; | |
93c5dd39 | 518 | gtk_editable_insert_text( GTK_EDITABLE(entry), value.mbc_str(), value.Length(), &pos ); |
6de97a3b | 519 | } |
53010e52 | 520 | |
debe6624 | 521 | void wxComboBox::Remove(long from, long to) |
53010e52 | 522 | { |
93c5dd39 | 523 | wxCHECK_RET( m_widget != NULL, _T("invalid combobox") ); |
805dd538 | 524 | |
fd0eed64 RR |
525 | GtkWidget *entry = GTK_COMBO(m_widget)->entry; |
526 | gtk_editable_delete_text( GTK_EDITABLE(entry), (gint)from, (gint)to ); | |
6de97a3b | 527 | } |
53010e52 | 528 | |
20d10ee1 | 529 | void wxComboBox::SetSelection( long from, long to ) |
53010e52 | 530 | { |
20d10ee1 VZ |
531 | GtkWidget *entry = GTK_COMBO(m_widget)->entry; |
532 | gtk_editable_select_region( GTK_EDITABLE(entry), (gint)from, (gint)to ); | |
6de97a3b | 533 | } |
53010e52 | 534 | |
20d10ee1 | 535 | void wxComboBox::SetEditable( bool editable ) |
53010e52 | 536 | { |
20d10ee1 VZ |
537 | GtkWidget *entry = GTK_COMBO(m_widget)->entry; |
538 | gtk_entry_set_editable( GTK_ENTRY(entry), editable ); | |
b4071e91 RR |
539 | } |
540 | ||
8a85884a VZ |
541 | void wxComboBox::OnChar( wxKeyEvent &event ) |
542 | { | |
7cf8cb48 | 543 | if ( event.KeyCode() == WXK_RETURN ) |
8a85884a | 544 | { |
7cf8cb48 | 545 | wxString value = GetValue(); |
8a85884a | 546 | |
7cf8cb48 VZ |
547 | if ( Number() == 0 ) |
548 | { | |
549 | // make Enter generate "selected" event if there is only one item | |
550 | // in the combobox - without it, it's impossible to select it at | |
551 | // all! | |
552 | wxCommandEvent event( wxEVT_COMMAND_COMBOBOX_SELECTED, GetId() ); | |
553 | event.SetInt( 0 ); | |
29006414 | 554 | event.SetString( value ); |
7cf8cb48 VZ |
555 | event.SetEventObject( this ); |
556 | GetEventHandler()->ProcessEvent( event ); | |
557 | } | |
558 | else | |
559 | { | |
560 | // add the item to the list if it's not there yet | |
561 | if ( FindString(value) == wxNOT_FOUND ) | |
562 | { | |
563 | Append(value); | |
564 | ||
565 | // and generate the selected event for it | |
566 | wxCommandEvent event( wxEVT_COMMAND_COMBOBOX_SELECTED, GetId() ); | |
567 | event.SetInt( Number() - 1 ); | |
29006414 | 568 | event.SetString( value ); |
7cf8cb48 VZ |
569 | event.SetEventObject( this ); |
570 | GetEventHandler()->ProcessEvent( event ); | |
571 | } | |
572 | //else: do nothing, this will open the listbox | |
573 | } | |
8a85884a | 574 | } |
7cf8cb48 VZ |
575 | |
576 | event.Skip(); | |
8a85884a VZ |
577 | } |
578 | ||
b4071e91 RR |
579 | void wxComboBox::OnSize( wxSizeEvent &event ) |
580 | { | |
fd0eed64 | 581 | wxControl::OnSize( event ); |
805dd538 | 582 | |
fd0eed64 RR |
583 | int w = 21; |
584 | gtk_widget_set_usize( GTK_COMBO(m_widget)->entry, m_width-w-1, m_height ); | |
805dd538 | 585 | |
fd0eed64 RR |
586 | gtk_widget_set_uposition( GTK_COMBO(m_widget)->button, m_x+m_width-w, m_y ); |
587 | gtk_widget_set_usize( GTK_COMBO(m_widget)->button, w, m_height ); | |
6de97a3b | 588 | } |
53010e52 | 589 | |
58614078 | 590 | void wxComboBox::ApplyWidgetStyle() |
868a2826 | 591 | { |
fd0eed64 | 592 | SetWidgetStyle(); |
805dd538 | 593 | |
72a16063 | 594 | // gtk_widget_set_style( GTK_COMBO(m_widget)->button, m_widgetStyle ); |
fd0eed64 RR |
595 | gtk_widget_set_style( GTK_COMBO(m_widget)->entry, m_widgetStyle ); |
596 | gtk_widget_set_style( GTK_COMBO(m_widget)->list, m_widgetStyle ); | |
805dd538 | 597 | |
fd0eed64 RR |
598 | GtkList *list = GTK_LIST( GTK_COMBO(m_widget)->list ); |
599 | GList *child = list->children; | |
600 | while (child) | |
601 | { | |
602 | gtk_widget_set_style( GTK_WIDGET(child->data), m_widgetStyle ); | |
805dd538 | 603 | |
fd0eed64 RR |
604 | GtkBin *bin = GTK_BIN(child->data); |
605 | gtk_widget_set_style( bin->child, m_widgetStyle ); | |
805dd538 | 606 | |
fd0eed64 RR |
607 | child = child->next; |
608 | } | |
868a2826 | 609 | } |
b4071e91 | 610 | |
fd0eed64 | 611 | GtkWidget* wxComboBox::GetConnectWidget() |
97b3455a | 612 | { |
fd0eed64 | 613 | return GTK_COMBO(m_widget)->entry; |
97b3455a RR |
614 | } |
615 | ||
b4071e91 RR |
616 | bool wxComboBox::IsOwnGtkWindow( GdkWindow *window ) |
617 | { | |
fd0eed64 RR |
618 | return ( (window == GTK_ENTRY( GTK_COMBO(m_widget)->entry )->text_area) || |
619 | (window == GTK_COMBO(m_widget)->button->window ) ); | |
b4071e91 | 620 | } |
ac57418f | 621 |