]> git.saurik.com Git - wxWidgets.git/blame - src/gtk1/combobox.cpp
fixed appending of '/' to empty string
[wxWidgets.git] / src / gtk1 / combobox.cpp
CommitLineData
53010e52
RR
1/////////////////////////////////////////////////////////////////////////////
2// Name: combobox.cpp
3// Purpose:
4// Author: Robert Roebling
5// Created: 01/02/97
6// Id:
7// Copyright: (c) 1998 Robert Roebling, Julian Smart and Markus Holzem
8// Licence: wxWindows licence
9/////////////////////////////////////////////////////////////////////////////
10
11#ifdef __GNUG__
12#pragma implementation "combobox.h"
13#endif
14
15#include "wx/combobox.h"
16
17//-----------------------------------------------------------------------------
18// wxComboBox
19//-----------------------------------------------------------------------------
20
21void gtk_combo_clicked_callback( GtkWidget *WXUNUSED(widget), wxComboBox *combo )
22{
23 wxCommandEvent event(wxEVT_COMMAND_CHOICE_SELECTED, combo->GetId());
24 event.SetInt( combo->GetSelection() );
25 wxString tmp( combo->GetStringSelection() );
26 event.SetString( WXSTRINGCAST(tmp) );
27 event.SetEventObject(combo);
28 combo->ProcessEvent(event);
29};
30
31//-----------------------------------------------------------------------------
32
33IMPLEMENT_DYNAMIC_CLASS(wxComboBox,wxControl)
34
debe6624 35bool wxComboBox::Create(wxWindow *parent, wxWindowID id, const wxString& value,
53010e52 36 const wxPoint& pos, const wxSize& size,
debe6624
JS
37 int n, const wxString choices[],
38 long style, const wxString& name )
53010e52
RR
39{
40 m_needParent = TRUE;
41
42 PreCreation( parent, id, pos, size, style, name );
43
44 m_widget = gtk_combo_new();
45
46 wxSize newSize = size;
47 if (newSize.x == -1) newSize.x = 100;
48 if (newSize.y == -1) newSize.y = 26;
49 SetSize( newSize.x, newSize.y );
50
51 GtkWidget *list = GTK_COMBO(m_widget)->list;
52
53 for (int i = 0; i < n; i++)
54 {
55 GtkWidget *list_item;
56 list_item = gtk_list_item_new_with_label( choices[i] );
57
58 gtk_signal_connect( GTK_OBJECT(list_item), "select",
59 GTK_SIGNAL_FUNC(gtk_combo_clicked_callback), (gpointer)this );
60
61 gtk_container_add( GTK_CONTAINER(list), list_item );
62
63 gtk_widget_show( list_item );
64 };
65
66 PostCreation();
67
68 if (!value.IsNull()) SetValue( value );
69
70 Show( TRUE );
71
72 return TRUE;
73};
74
75void wxComboBox::Clear(void)
76{
77 GtkWidget *list = GTK_COMBO(m_widget)->list;
78 gtk_list_clear_items( GTK_LIST(list), 0, Number() );
79};
80
81void wxComboBox::Append( const wxString &item )
82{
83 GtkWidget *list = GTK_COMBO(m_widget)->list;
84
85 GtkWidget *list_item;
86 list_item = gtk_list_item_new_with_label( item );
87
88 gtk_signal_connect( GTK_OBJECT(list_item), "select",
89 GTK_SIGNAL_FUNC(gtk_combo_clicked_callback), (gpointer)this );
90
91 gtk_container_add( GTK_CONTAINER(list), list_item );
92
93 gtk_widget_show( list_item );
94};
95
96void wxComboBox::Append( const wxString &WXUNUSED(item), char* WXUNUSED(clientData) )
97{
98};
99
debe6624 100void wxComboBox::Delete( int n )
53010e52
RR
101{
102 GtkWidget *list = GTK_COMBO(m_widget)->list;
103 gtk_list_clear_items( GTK_LIST(list), n, n );
104};
105
106int wxComboBox::FindString( const wxString &item )
107{
108 GtkWidget *list = GTK_COMBO(m_widget)->list;
109
110 GList *child = GTK_LIST(list)->children;
111 int count = 0;
112 while (child)
113 {
114 GtkBin *bin = GTK_BIN( child->data );
115 GtkLabel *label = GTK_LABEL( bin->child );
116 if (item == label->label) return count;
117 count++;
118 child = child->next;
119 };
120 return -1;
121};
122
debe6624 123char* wxComboBox::GetClientData( int n )
53010e52
RR
124{
125 wxNode *node = m_clientData.Nth( n );
126 if (node) return (char*)node->Data();
127 return NULL;
128};
129
debe6624 130void wxComboBox::SetClientData( int n, char * clientData )
53010e52
RR
131{
132 wxNode *node = m_clientData.Nth( n );
133 if (node) node->SetData( (wxObject*) clientData );
134};
135
136int wxComboBox::GetSelection(void) const
137{
138 GtkWidget *list = GTK_COMBO(m_widget)->list;
139
140 GList *selection = GTK_LIST(list)->selection;
141 if (selection)
142 {
143 GList *child = GTK_LIST(list)->children;
144 int count = 0;
145 while (child)
146 {
147 if (child->data == selection->data) return count;
148 count++;
149 child = child->next;
150 };
151 };
152 return -1;
153};
154
debe6624 155wxString wxComboBox::GetString( int n ) const
53010e52
RR
156{
157 GtkWidget *list = GTK_COMBO(m_widget)->list;
158
159 GList *child = g_list_nth( GTK_LIST(list)->children, n );
160 if (child)
161 {
162 GtkBin *bin = GTK_BIN( child->data );
163 GtkLabel *label = GTK_LABEL( bin->child );
164 return label->label;
165 };
166 return "";
167};
168
169wxString wxComboBox::GetStringSelection(void) const
170{
171 GtkWidget *list = GTK_COMBO(m_widget)->list;
172
173 GList *selection = GTK_LIST(list)->selection;
174 if (selection)
175 {
176 GtkBin *bin = GTK_BIN( selection->data );
177 wxString tmp = GTK_LABEL( bin->child )->label;
178 return tmp;
179 };
180 return "";
181};
182
183int wxComboBox::Number(void) const
184{
185 GtkWidget *list = GTK_COMBO(m_widget)->list;
186
187 GList *child = GTK_LIST(list)->children;
188 int count = 0;
189 while (child) { count++; child = child->next; };
190 return count;
191};
192
debe6624 193void wxComboBox::SetSelection( int n )
53010e52
RR
194{
195 GtkWidget *list = GTK_COMBO(m_widget)->list;
196 gtk_list_select_item( GTK_LIST(list), n );
197};
198
199wxString wxComboBox::GetValue(void) const
200{
201 GtkWidget *entry = GTK_COMBO(m_widget)->entry;
202 wxString tmp = gtk_entry_get_text( GTK_ENTRY(entry) );
203 return tmp;
204};
205
206void wxComboBox::SetValue( const wxString& value )
207{
208 GtkWidget *entry = GTK_COMBO(m_widget)->entry;
209 wxString tmp = "";
210 if (!value.IsNull()) tmp = value;
211 gtk_entry_set_text( GTK_ENTRY(entry), tmp );
212};
213
214void wxComboBox::Copy(void)
215{
216 GtkWidget *entry = GTK_COMBO(m_widget)->entry;
217 gtk_editable_copy_clipboard( GTK_EDITABLE(entry), 0 );
218};
219
220void wxComboBox::Cut(void)
221{
222 GtkWidget *entry = GTK_COMBO(m_widget)->entry;
223 gtk_editable_cut_clipboard( GTK_EDITABLE(entry), 0 );
224};
225
226void wxComboBox::Paste(void)
227{
228 GtkWidget *entry = GTK_COMBO(m_widget)->entry;
229 gtk_editable_paste_clipboard( GTK_EDITABLE(entry), 0 );
230};
231
debe6624 232void wxComboBox::SetInsertionPoint( long pos )
53010e52
RR
233{
234 GtkWidget *entry = GTK_COMBO(m_widget)->entry;
235 int tmp = (int) pos;
236 gtk_entry_set_position( GTK_ENTRY(entry), tmp );
237};
238
239void wxComboBox::SetInsertionPointEnd(void)
240{
241 GtkWidget *entry = GTK_COMBO(m_widget)->entry;
242 int pos = GTK_ENTRY(entry)->text_length;
243 SetInsertionPoint( pos-1 );
244};
245
246long wxComboBox::GetInsertionPoint(void) const
247{
248 GtkWidget *entry = GTK_COMBO(m_widget)->entry;
249 return (long) GTK_EDITABLE(entry)->current_pos;
250};
251
252long wxComboBox::GetLastPosition(void) const
253{
254 GtkWidget *entry = GTK_COMBO(m_widget)->entry;
255 int pos = GTK_ENTRY(entry)->text_length;
256 return (long) pos-1;
257};
258
debe6624 259void wxComboBox::Replace( long from, long to, const wxString& value )
53010e52
RR
260{
261 GtkWidget *entry = GTK_COMBO(m_widget)->entry;
262 gtk_editable_delete_text( GTK_EDITABLE(entry), (gint)from, (gint)to );
263 if (value.IsNull()) return;
264 gint pos = (gint)to;
265 gtk_editable_insert_text( GTK_EDITABLE(entry), value, value.Length(), &pos );
266};
267
debe6624 268void wxComboBox::Remove(long from, long to)
53010e52
RR
269{
270 GtkWidget *entry = GTK_COMBO(m_widget)->entry;
271 gtk_editable_delete_text( GTK_EDITABLE(entry), (gint)from, (gint)to );
272};
273
debe6624 274void wxComboBox::SetSelection( long WXUNUSED(from), long WXUNUSED(to) )
53010e52
RR
275{
276};
277
debe6624 278void wxComboBox::SetEditable( bool WXUNUSED(editable) )
53010e52
RR
279{
280};
281
282