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