]> git.saurik.com Git - wxWidgets.git/blame - src/motif/combobox.cpp
More-or-less finished reasonably cool wxToolBar class with tooltips.
[wxWidgets.git] / src / motif / combobox.cpp
CommitLineData
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
23void wxComboBoxCallback (Widget w, XtPointer clientData,
24 XmComboBoxSelectionCallbackStruct * cbs);
25
4bb6408c
JS
26#if !USE_SHARED_LIBRARY
27IMPLEMENT_DYNAMIC_CLASS(wxComboBox, wxControl)
28#endif
29
30bool 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
86 SetCanAddEventHandler(TRUE);
87 AttachWidget (parent, m_mainWidget, (WXWidget) NULL, pos.x, pos.y, size.x, size.y);
88
89 SetFont(* parent->GetFont());
0d57be45 90 ChangeBackgroundColour();
4bb6408c
JS
91
92 return TRUE;
93}
94
95wxString wxComboBox::GetValue() const
96{
89c7e962
JS
97 char *s = XmComboBoxGetString ((Widget) m_mainWidget);
98 if (s)
99 {
100 wxString str(s);
101 XtFree (s);
102 return str;
103 }
104 else
105 return wxEmptyString;
4bb6408c
JS
106}
107
108void wxComboBox::SetValue(const wxString& value)
109{
89c7e962
JS
110 m_inSetValue = TRUE;
111 if (!value.IsNull())
112 XmComboBoxSetString ((Widget) m_mainWidget, (char*) (const char*) value);
113 m_inSetValue = FALSE;
4bb6408c
JS
114}
115
116// Clipboard operations
117void wxComboBox::Copy()
118{
89c7e962 119 XmComboBoxCopy((Widget) m_mainWidget, CurrentTime);
4bb6408c
JS
120}
121
122void wxComboBox::Cut()
123{
89c7e962 124 XmComboBoxCut((Widget) m_mainWidget, CurrentTime);
4bb6408c
JS
125}
126
127void wxComboBox::Paste()
128{
89c7e962 129 XmComboBoxPaste((Widget) m_mainWidget);
4bb6408c
JS
130}
131
132void wxComboBox::SetEditable(bool editable)
133{
134 // TODO
135}
136
137void wxComboBox::SetInsertionPoint(long pos)
138{
89c7e962 139 XmComboBoxSetInsertionPosition ((Widget) m_mainWidget, (XmTextPosition) pos);
4bb6408c
JS
140}
141
142void wxComboBox::SetInsertionPointEnd()
143{
89c7e962
JS
144 XmTextPosition pos = XmComboBoxGetLastPosition ((Widget) m_mainWidget);
145 XmComboBoxSetInsertionPosition ((Widget) m_mainWidget, (XmTextPosition) (pos + 1));
4bb6408c
JS
146}
147
148long wxComboBox::GetInsertionPoint() const
149{
89c7e962 150 return (long) XmComboBoxGetInsertionPosition ((Widget) m_mainWidget);
4bb6408c
JS
151}
152
153long wxComboBox::GetLastPosition() const
154{
89c7e962 155 return (long) XmComboBoxGetLastPosition ((Widget) m_mainWidget);
4bb6408c
JS
156}
157
158void wxComboBox::Replace(long from, long to, const wxString& value)
159{
89c7e962
JS
160 XmComboBoxReplace ((Widget) m_mainWidget, (XmTextPosition) from, (XmTextPosition) to,
161 (char*) (const char*) value);
4bb6408c
JS
162}
163
164void wxComboBox::Remove(long from, long to)
165{
89c7e962
JS
166 XmComboBoxSetSelection ((Widget) m_mainWidget, (XmTextPosition) from, (XmTextPosition) to,
167 (Time) 0);
168 XmComboBoxRemove ((Widget) m_mainWidget);
4bb6408c
JS
169}
170
171void wxComboBox::SetSelection(long from, long to)
172{
89c7e962
JS
173 XmComboBoxSetSelection ((Widget) m_mainWidget, (XmTextPosition) from, (XmTextPosition) to,
174 (Time) 0);
175}
176
177void wxComboBoxCallback (Widget w, XtPointer clientData,
178 XmComboBoxSelectionCallbackStruct * cbs)
179{
180 wxComboBox *item = (wxComboBox *) clientData;
181
182 switch (cbs->reason)
183 {
184 case XmCR_SINGLE_SELECT:
185 case XmCR_BROWSE_SELECT:
186 {
187 wxCommandEvent event (wxEVT_COMMAND_COMBOBOX_SELECTED, item->GetId());
188 event.m_commandInt = cbs->index - 1;
189 // event.m_commandString = item->GetString (event.m_commandInt);
190 event.m_extraLong = TRUE;
191 event.SetEventObject(item);
192 item->ProcessCommand (event);
193 break;
194 }
195 case XmCR_VALUE_CHANGED:
196 {
197 wxCommandEvent event (wxEVT_COMMAND_TEXT_UPDATED, item->GetId());
198 event.m_commandInt = -1;
199 // event.m_commandString = item->GetValue();
200 event.m_extraLong = TRUE;
201 event.SetEventObject(item);
202 item->ProcessCommand (event);
203 break;
204 }
205 default:
206 break;
207 }
4bb6408c
JS
208}
209
0d57be45
JS
210void wxComboBox::ChangeFont()
211{
212 // TODO
213}
214
215void wxComboBox::ChangeBackgroundColour()
216{
217 // TODO
218}
219
220void wxComboBox::ChangeForegroundColour()
221{
222 // TODO
223}
224
89c7e962
JS
225#endif
226