]>
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; | |
43 | ||
44 | if (parent) parent->AddChild(this); | |
45 | ||
46 | if ( id == -1 ) | |
47 | m_windowId = (int)NewControlId(); | |
48 | else | |
49 | m_windowId = id; | |
50 | ||
89c7e962 JS |
51 | Widget parentWidget = (Widget) parent->GetClientWidget(); |
52 | ||
53 | Widget buttonWidget = XtVaCreateManagedWidget((char*) (const char*) name, | |
54 | xmComboBoxWidgetClass, parentWidget, | |
55 | XmNmarginHeight, 0, | |
56 | XmNmarginWidth, 0, | |
57 | XmNshowLabel, False, | |
58 | XmNeditable, ((style & wxCB_READONLY) != wxCB_READONLY), | |
59 | XmNsorted, ((style & wxCB_SORT) == wxCB_SORT), | |
60 | XmNstaticList, ((style & wxCB_SIMPLE) == wxCB_SIMPLE), | |
61 | NULL); | |
62 | ||
63 | XtAddCallback (buttonWidget, XmNselectionCallback, (XtCallbackProc) wxComboBoxCallback, | |
64 | (XtPointer) this); | |
65 | XtAddCallback (buttonWidget, XmNvalueChangedCallback, (XtCallbackProc) wxComboBoxCallback, | |
66 | (XtPointer) this); | |
67 | ||
68 | int i; | |
69 | for (i = 0; i < n; i++) | |
70 | { | |
71 | XmString str = XmStringCreateLtoR((char*) (const char*) choices[i], XmSTRING_DEFAULT_CHARSET); | |
72 | XmComboBoxAddItem(buttonWidget, str, 0); | |
73 | XmStringFree(str); | |
74 | m_stringList.Add(choices[i]); | |
75 | } | |
76 | m_noStrings = n; | |
77 | ||
78 | m_mainWidget = (Widget) buttonWidget; | |
79 | ||
80 | XtManageChild (buttonWidget); | |
81 | ||
82 | SetValue(value); | |
83 | ||
84 | SetCanAddEventHandler(TRUE); | |
85 | AttachWidget (parent, m_mainWidget, (WXWidget) NULL, pos.x, pos.y, size.x, size.y); | |
86 | ||
87 | SetFont(* parent->GetFont()); | |
88 | ChangeColour(m_mainWidget); | |
4bb6408c JS |
89 | |
90 | return TRUE; | |
91 | } | |
92 | ||
93 | wxString wxComboBox::GetValue() const | |
94 | { | |
89c7e962 JS |
95 | char *s = XmComboBoxGetString ((Widget) m_mainWidget); |
96 | if (s) | |
97 | { | |
98 | wxString str(s); | |
99 | XtFree (s); | |
100 | return str; | |
101 | } | |
102 | else | |
103 | return wxEmptyString; | |
4bb6408c JS |
104 | } |
105 | ||
106 | void wxComboBox::SetValue(const wxString& value) | |
107 | { | |
89c7e962 JS |
108 | m_inSetValue = TRUE; |
109 | if (!value.IsNull()) | |
110 | XmComboBoxSetString ((Widget) m_mainWidget, (char*) (const char*) value); | |
111 | m_inSetValue = FALSE; | |
4bb6408c JS |
112 | } |
113 | ||
114 | // Clipboard operations | |
115 | void wxComboBox::Copy() | |
116 | { | |
89c7e962 | 117 | XmComboBoxCopy((Widget) m_mainWidget, CurrentTime); |
4bb6408c JS |
118 | } |
119 | ||
120 | void wxComboBox::Cut() | |
121 | { | |
89c7e962 | 122 | XmComboBoxCut((Widget) m_mainWidget, CurrentTime); |
4bb6408c JS |
123 | } |
124 | ||
125 | void wxComboBox::Paste() | |
126 | { | |
89c7e962 | 127 | XmComboBoxPaste((Widget) m_mainWidget); |
4bb6408c JS |
128 | } |
129 | ||
130 | void wxComboBox::SetEditable(bool editable) | |
131 | { | |
132 | // TODO | |
133 | } | |
134 | ||
135 | void wxComboBox::SetInsertionPoint(long pos) | |
136 | { | |
89c7e962 | 137 | XmComboBoxSetInsertionPosition ((Widget) m_mainWidget, (XmTextPosition) pos); |
4bb6408c JS |
138 | } |
139 | ||
140 | void wxComboBox::SetInsertionPointEnd() | |
141 | { | |
89c7e962 JS |
142 | XmTextPosition pos = XmComboBoxGetLastPosition ((Widget) m_mainWidget); |
143 | XmComboBoxSetInsertionPosition ((Widget) m_mainWidget, (XmTextPosition) (pos + 1)); | |
4bb6408c JS |
144 | } |
145 | ||
146 | long wxComboBox::GetInsertionPoint() const | |
147 | { | |
89c7e962 | 148 | return (long) XmComboBoxGetInsertionPosition ((Widget) m_mainWidget); |
4bb6408c JS |
149 | } |
150 | ||
151 | long wxComboBox::GetLastPosition() const | |
152 | { | |
89c7e962 | 153 | return (long) XmComboBoxGetLastPosition ((Widget) m_mainWidget); |
4bb6408c JS |
154 | } |
155 | ||
156 | void wxComboBox::Replace(long from, long to, const wxString& value) | |
157 | { | |
89c7e962 JS |
158 | XmComboBoxReplace ((Widget) m_mainWidget, (XmTextPosition) from, (XmTextPosition) to, |
159 | (char*) (const char*) value); | |
4bb6408c JS |
160 | } |
161 | ||
162 | void wxComboBox::Remove(long from, long to) | |
163 | { | |
89c7e962 JS |
164 | XmComboBoxSetSelection ((Widget) m_mainWidget, (XmTextPosition) from, (XmTextPosition) to, |
165 | (Time) 0); | |
166 | XmComboBoxRemove ((Widget) m_mainWidget); | |
4bb6408c JS |
167 | } |
168 | ||
169 | void wxComboBox::SetSelection(long from, long to) | |
170 | { | |
89c7e962 JS |
171 | XmComboBoxSetSelection ((Widget) m_mainWidget, (XmTextPosition) from, (XmTextPosition) to, |
172 | (Time) 0); | |
173 | } | |
174 | ||
175 | void wxComboBoxCallback (Widget w, XtPointer clientData, | |
176 | XmComboBoxSelectionCallbackStruct * cbs) | |
177 | { | |
178 | wxComboBox *item = (wxComboBox *) clientData; | |
179 | ||
180 | switch (cbs->reason) | |
181 | { | |
182 | case XmCR_SINGLE_SELECT: | |
183 | case XmCR_BROWSE_SELECT: | |
184 | { | |
185 | wxCommandEvent event (wxEVT_COMMAND_COMBOBOX_SELECTED, item->GetId()); | |
186 | event.m_commandInt = cbs->index - 1; | |
187 | // event.m_commandString = item->GetString (event.m_commandInt); | |
188 | event.m_extraLong = TRUE; | |
189 | event.SetEventObject(item); | |
190 | item->ProcessCommand (event); | |
191 | break; | |
192 | } | |
193 | case XmCR_VALUE_CHANGED: | |
194 | { | |
195 | wxCommandEvent event (wxEVT_COMMAND_TEXT_UPDATED, item->GetId()); | |
196 | event.m_commandInt = -1; | |
197 | // event.m_commandString = item->GetValue(); | |
198 | event.m_extraLong = TRUE; | |
199 | event.SetEventObject(item); | |
200 | item->ProcessCommand (event); | |
201 | break; | |
202 | } | |
203 | default: | |
204 | break; | |
205 | } | |
4bb6408c JS |
206 | } |
207 | ||
89c7e962 JS |
208 | #endif |
209 |