]>
Commit | Line | Data |
---|---|---|
4bb6408c JS |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: combobox.cpp | |
3 | // Purpose: wxComboBox class | |
4 | // Author: Julian Smart | |
5 | // Modified by: | |
6 | // Created: 17/09/98 | |
7 | // RCS-ID: $Id$ | |
8 | // Copyright: (c) Julian Smart | |
9 | // Licence: wxWindows licence | |
10 | ///////////////////////////////////////////////////////////////////////////// | |
11 | ||
12 | #ifdef __GNUG__ | |
13 | #pragma implementation "combobox.h" | |
14 | #endif | |
15 | ||
16 | #include "wx/combobox.h" | |
17 | ||
89c7e962 JS |
18 | #if wxUSE_COMBOBOX |
19 | ||
20 | #include <Xm/Xm.h> | |
8704bf74 | 21 | #include "xmcombo/xmcombo.h" |
89c7e962 JS |
22 | |
23 | void wxComboBoxCallback (Widget w, XtPointer clientData, | |
24 | XmComboBoxSelectionCallbackStruct * cbs); | |
25 | ||
4bb6408c JS |
26 | #if !USE_SHARED_LIBRARY |
27 | IMPLEMENT_DYNAMIC_CLASS(wxComboBox, wxControl) | |
28 | #endif | |
29 | ||
30 | bool wxComboBox::Create(wxWindow *parent, wxWindowID id, | |
31 | const wxString& value, | |
32 | const wxPoint& pos, | |
33 | const wxSize& size, | |
34 | int n, const wxString choices[], | |
35 | long style, | |
36 | const wxValidator& validator, | |
37 | const wxString& name) | |
38 | { | |
39 | SetName(name); | |
40 | SetValidator(validator); | |
41 | m_noStrings = n; | |
42 | m_windowStyle = style; | |
0d57be45 JS |
43 | m_backgroundColour = parent->GetBackgroundColour(); |
44 | m_foregroundColour = parent->GetForegroundColour(); | |
4bb6408c JS |
45 | |
46 | if (parent) parent->AddChild(this); | |
47 | ||
48 | if ( id == -1 ) | |
49 | m_windowId = (int)NewControlId(); | |
50 | else | |
51 | m_windowId = id; | |
52 | ||
89c7e962 JS |
53 | Widget parentWidget = (Widget) parent->GetClientWidget(); |
54 | ||
55 | Widget buttonWidget = XtVaCreateManagedWidget((char*) (const char*) name, | |
56 | xmComboBoxWidgetClass, parentWidget, | |
57 | XmNmarginHeight, 0, | |
58 | XmNmarginWidth, 0, | |
59 | XmNshowLabel, False, | |
60 | XmNeditable, ((style & wxCB_READONLY) != wxCB_READONLY), | |
61 | XmNsorted, ((style & wxCB_SORT) == wxCB_SORT), | |
62 | XmNstaticList, ((style & wxCB_SIMPLE) == wxCB_SIMPLE), | |
63 | NULL); | |
64 | ||
65 | XtAddCallback (buttonWidget, XmNselectionCallback, (XtCallbackProc) wxComboBoxCallback, | |
66 | (XtPointer) this); | |
67 | XtAddCallback (buttonWidget, XmNvalueChangedCallback, (XtCallbackProc) wxComboBoxCallback, | |
68 | (XtPointer) this); | |
69 | ||
70 | int i; | |
71 | for (i = 0; i < n; i++) | |
72 | { | |
73 | XmString str = XmStringCreateLtoR((char*) (const char*) choices[i], XmSTRING_DEFAULT_CHARSET); | |
74 | XmComboBoxAddItem(buttonWidget, str, 0); | |
75 | XmStringFree(str); | |
76 | m_stringList.Add(choices[i]); | |
77 | } | |
78 | m_noStrings = n; | |
79 | ||
80 | m_mainWidget = (Widget) buttonWidget; | |
81 | ||
82 | XtManageChild (buttonWidget); | |
83 | ||
84 | SetValue(value); | |
85 | ||
4b5f3fe6 JS |
86 | m_windowFont = parent->GetFont(); |
87 | ChangeFont(FALSE); | |
88 | ||
89c7e962 JS |
89 | SetCanAddEventHandler(TRUE); |
90 | AttachWidget (parent, m_mainWidget, (WXWidget) NULL, pos.x, pos.y, size.x, size.y); | |
91 | ||
0d57be45 | 92 | ChangeBackgroundColour(); |
4bb6408c JS |
93 | |
94 | return TRUE; | |
95 | } | |
96 | ||
97 | wxString wxComboBox::GetValue() const | |
98 | { | |
89c7e962 JS |
99 | char *s = XmComboBoxGetString ((Widget) m_mainWidget); |
100 | if (s) | |
101 | { | |
102 | wxString str(s); | |
103 | XtFree (s); | |
104 | return str; | |
105 | } | |
106 | else | |
107 | return wxEmptyString; | |
4bb6408c JS |
108 | } |
109 | ||
110 | void wxComboBox::SetValue(const wxString& value) | |
111 | { | |
89c7e962 JS |
112 | m_inSetValue = TRUE; |
113 | if (!value.IsNull()) | |
114 | XmComboBoxSetString ((Widget) m_mainWidget, (char*) (const char*) value); | |
115 | m_inSetValue = FALSE; | |
4bb6408c JS |
116 | } |
117 | ||
118 | // Clipboard operations | |
119 | void wxComboBox::Copy() | |
120 | { | |
89c7e962 | 121 | XmComboBoxCopy((Widget) m_mainWidget, CurrentTime); |
4bb6408c JS |
122 | } |
123 | ||
124 | void wxComboBox::Cut() | |
125 | { | |
89c7e962 | 126 | XmComboBoxCut((Widget) m_mainWidget, CurrentTime); |
4bb6408c JS |
127 | } |
128 | ||
129 | void wxComboBox::Paste() | |
130 | { | |
89c7e962 | 131 | XmComboBoxPaste((Widget) m_mainWidget); |
4bb6408c JS |
132 | } |
133 | ||
134 | void wxComboBox::SetEditable(bool editable) | |
135 | { | |
136 | // TODO | |
137 | } | |
138 | ||
139 | void wxComboBox::SetInsertionPoint(long pos) | |
140 | { | |
89c7e962 | 141 | XmComboBoxSetInsertionPosition ((Widget) m_mainWidget, (XmTextPosition) pos); |
4bb6408c JS |
142 | } |
143 | ||
144 | void wxComboBox::SetInsertionPointEnd() | |
145 | { | |
89c7e962 JS |
146 | XmTextPosition pos = XmComboBoxGetLastPosition ((Widget) m_mainWidget); |
147 | XmComboBoxSetInsertionPosition ((Widget) m_mainWidget, (XmTextPosition) (pos + 1)); | |
4bb6408c JS |
148 | } |
149 | ||
150 | long wxComboBox::GetInsertionPoint() const | |
151 | { | |
89c7e962 | 152 | return (long) XmComboBoxGetInsertionPosition ((Widget) m_mainWidget); |
4bb6408c JS |
153 | } |
154 | ||
155 | long wxComboBox::GetLastPosition() const | |
156 | { | |
89c7e962 | 157 | return (long) XmComboBoxGetLastPosition ((Widget) m_mainWidget); |
4bb6408c JS |
158 | } |
159 | ||
160 | void wxComboBox::Replace(long from, long to, const wxString& value) | |
161 | { | |
89c7e962 JS |
162 | XmComboBoxReplace ((Widget) m_mainWidget, (XmTextPosition) from, (XmTextPosition) to, |
163 | (char*) (const char*) value); | |
4bb6408c JS |
164 | } |
165 | ||
166 | void wxComboBox::Remove(long from, long to) | |
167 | { | |
89c7e962 JS |
168 | XmComboBoxSetSelection ((Widget) m_mainWidget, (XmTextPosition) from, (XmTextPosition) to, |
169 | (Time) 0); | |
170 | XmComboBoxRemove ((Widget) m_mainWidget); | |
4bb6408c JS |
171 | } |
172 | ||
173 | void wxComboBox::SetSelection(long from, long to) | |
174 | { | |
89c7e962 JS |
175 | XmComboBoxSetSelection ((Widget) m_mainWidget, (XmTextPosition) from, (XmTextPosition) to, |
176 | (Time) 0); | |
177 | } | |
178 | ||
179 | void wxComboBoxCallback (Widget w, XtPointer clientData, | |
180 | XmComboBoxSelectionCallbackStruct * cbs) | |
181 | { | |
182 | wxComboBox *item = (wxComboBox *) clientData; | |
183 | ||
184 | switch (cbs->reason) | |
185 | { | |
186 | case XmCR_SINGLE_SELECT: | |
187 | case XmCR_BROWSE_SELECT: | |
188 | { | |
189 | wxCommandEvent event (wxEVT_COMMAND_COMBOBOX_SELECTED, item->GetId()); | |
190 | event.m_commandInt = cbs->index - 1; | |
191 | // event.m_commandString = item->GetString (event.m_commandInt); | |
192 | event.m_extraLong = TRUE; | |
193 | event.SetEventObject(item); | |
194 | item->ProcessCommand (event); | |
195 | break; | |
196 | } | |
197 | case XmCR_VALUE_CHANGED: | |
198 | { | |
199 | wxCommandEvent event (wxEVT_COMMAND_TEXT_UPDATED, item->GetId()); | |
200 | event.m_commandInt = -1; | |
201 | // event.m_commandString = item->GetValue(); | |
202 | event.m_extraLong = TRUE; | |
203 | event.SetEventObject(item); | |
204 | item->ProcessCommand (event); | |
205 | break; | |
206 | } | |
207 | default: | |
208 | break; | |
209 | } | |
4bb6408c JS |
210 | } |
211 | ||
4b5f3fe6 | 212 | void wxComboBox::ChangeFont(bool keepOriginalSize) |
0d57be45 | 213 | { |
321db4b6 | 214 | // Don't use the base class wxChoice's ChangeFont |
4b5f3fe6 | 215 | wxWindow::ChangeFont(keepOriginalSize); |
0d57be45 JS |
216 | } |
217 | ||
218 | void wxComboBox::ChangeBackgroundColour() | |
219 | { | |
321db4b6 | 220 | wxWindow::ChangeBackgroundColour(); |
0d57be45 JS |
221 | } |
222 | ||
223 | void wxComboBox::ChangeForegroundColour() | |
224 | { | |
321db4b6 | 225 | wxWindow::ChangeBackgroundColour(); |
0d57be45 JS |
226 | } |
227 | ||
89c7e962 JS |
228 | #endif |
229 |