]> git.saurik.com Git - wxWidgets.git/blob - src/motif/combobox.cpp
Compile and build fixes for wxGTK and wxMotif
[wxWidgets.git] / src / motif / combobox.cpp
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
18 #if wxUSE_COMBOBOX
19
20 #include <Xm/Xm.h>
21 #include "xmcombo/xmcombo.h"
22
23 void wxComboBoxCallback (Widget w, XtPointer clientData,
24 XmComboBoxSelectionCallbackStruct * cbs);
25
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 m_backgroundColour = parent->GetBackgroundColour();
44 m_foregroundColour = parent->GetForegroundColour();
45
46 if (parent) parent->AddChild(this);
47
48 if ( id == -1 )
49 m_windowId = (int)NewControlId();
50 else
51 m_windowId = id;
52
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
86 m_windowFont = parent->GetFont();
87 ChangeFont(FALSE);
88
89 SetCanAddEventHandler(TRUE);
90 AttachWidget (parent, m_mainWidget, (WXWidget) NULL, pos.x, pos.y, size.x, size.y);
91
92 ChangeBackgroundColour();
93
94 return TRUE;
95 }
96
97 wxString wxComboBox::GetValue() const
98 {
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;
108 }
109
110 void wxComboBox::SetValue(const wxString& value)
111 {
112 m_inSetValue = TRUE;
113 if (!value.IsNull())
114 XmComboBoxSetString ((Widget) m_mainWidget, (char*) (const char*) value);
115 m_inSetValue = FALSE;
116 }
117
118 // Clipboard operations
119 void wxComboBox::Copy()
120 {
121 XmComboBoxCopy((Widget) m_mainWidget, CurrentTime);
122 }
123
124 void wxComboBox::Cut()
125 {
126 XmComboBoxCut((Widget) m_mainWidget, CurrentTime);
127 }
128
129 void wxComboBox::Paste()
130 {
131 XmComboBoxPaste((Widget) m_mainWidget);
132 }
133
134 void wxComboBox::SetEditable(bool editable)
135 {
136 // TODO
137 }
138
139 void wxComboBox::SetInsertionPoint(long pos)
140 {
141 XmComboBoxSetInsertionPosition ((Widget) m_mainWidget, (XmTextPosition) pos);
142 }
143
144 void wxComboBox::SetInsertionPointEnd()
145 {
146 XmTextPosition pos = XmComboBoxGetLastPosition ((Widget) m_mainWidget);
147 XmComboBoxSetInsertionPosition ((Widget) m_mainWidget, (XmTextPosition) (pos + 1));
148 }
149
150 long wxComboBox::GetInsertionPoint() const
151 {
152 return (long) XmComboBoxGetInsertionPosition ((Widget) m_mainWidget);
153 }
154
155 long wxComboBox::GetLastPosition() const
156 {
157 return (long) XmComboBoxGetLastPosition ((Widget) m_mainWidget);
158 }
159
160 void wxComboBox::Replace(long from, long to, const wxString& value)
161 {
162 XmComboBoxReplace ((Widget) m_mainWidget, (XmTextPosition) from, (XmTextPosition) to,
163 (char*) (const char*) value);
164 }
165
166 void wxComboBox::Remove(long from, long to)
167 {
168 XmComboBoxSetSelection ((Widget) m_mainWidget, (XmTextPosition) from, (XmTextPosition) to,
169 (Time) 0);
170 XmComboBoxRemove ((Widget) m_mainWidget);
171 }
172
173 void wxComboBox::SetSelection(long from, long to)
174 {
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 }
210 }
211
212 void wxComboBox::ChangeFont(bool keepOriginalSize)
213 {
214 // Don't use the base class wxChoice's ChangeFont
215 wxWindow::ChangeFont(keepOriginalSize);
216 }
217
218 void wxComboBox::ChangeBackgroundColour()
219 {
220 wxWindow::ChangeBackgroundColour();
221 }
222
223 void wxComboBox::ChangeForegroundColour()
224 {
225 wxWindow::ChangeBackgroundColour();
226 }
227
228 #endif
229