1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxComboBox class
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
13 #pragma implementation "combobox.h"
16 #include "wx/combobox.h"
21 #pragma message disable nosimpint
25 #pragma message enable nosimpint
27 #include "xmcombo/xmcombo.h"
29 void wxComboBoxCallback (Widget w
, XtPointer clientData
,
30 XmComboBoxSelectionCallbackStruct
* cbs
);
32 IMPLEMENT_DYNAMIC_CLASS(wxComboBox
, wxControl
)
34 bool wxComboBox::Create(wxWindow
*parent
, wxWindowID id
,
35 const wxString
& value
,
38 int n
, const wxString choices
[],
40 const wxValidator
& validator
,
44 SetValidator(validator
);
46 m_windowStyle
= style
;
47 // m_backgroundColour = parent->GetBackgroundColour();
48 m_backgroundColour
= * wxWHITE
;
49 m_foregroundColour
= parent
->GetForegroundColour();
51 if (parent
) parent
->AddChild(this);
54 m_windowId
= (int)NewControlId();
58 Widget parentWidget
= (Widget
) parent
->GetClientWidget();
60 Widget buttonWidget
= XtVaCreateManagedWidget(name
.c_str(),
61 xmComboBoxWidgetClass
, parentWidget
,
65 XmNeditable
, ((style
& wxCB_READONLY
) != wxCB_READONLY
),
66 XmNsorted
, ((style
& wxCB_SORT
) == wxCB_SORT
),
67 XmNstaticList
, ((style
& wxCB_SIMPLE
) == wxCB_SIMPLE
),
70 XtAddCallback (buttonWidget
, XmNselectionCallback
, (XtCallbackProc
) wxComboBoxCallback
,
72 XtAddCallback (buttonWidget
, XmNvalueChangedCallback
, (XtCallbackProc
) wxComboBoxCallback
,
76 for (i
= 0; i
< n
; i
++)
78 XmString str
= XmStringCreateLtoR((char*) (const char*) choices
[i
], XmSTRING_DEFAULT_CHARSET
);
79 XmComboBoxAddItem(buttonWidget
, str
, 0);
81 m_stringList
.Add(choices
[i
]);
85 m_mainWidget
= (Widget
) buttonWidget
;
87 XtManageChild (buttonWidget
);
91 m_font
= parent
->GetFont();
94 SetCanAddEventHandler(TRUE
);
95 AttachWidget (parent
, m_mainWidget
, (WXWidget
) NULL
, pos
.x
, pos
.y
, size
.x
, size
.y
);
97 ChangeBackgroundColour();
102 wxComboBox::~wxComboBox()
104 DetachWidget((Widget
) m_mainWidget
); // Removes event handlers
105 XtDestroyWidget((Widget
) m_mainWidget
);
106 m_mainWidget
= (WXWidget
) 0;
109 void wxComboBox::DoSetSize(int x
, int y
, int width
, int height
, int sizeFlags
)
111 // Necessary so it doesn't call wxChoice::SetSize
112 wxWindow::DoSetSize(x
, y
, width
, height
, sizeFlags
);
115 wxString
wxComboBox::GetValue() const
117 char *s
= XmComboBoxGetString ((Widget
) m_mainWidget
);
125 return wxEmptyString
;
128 void wxComboBox::SetValue(const wxString
& value
)
132 XmComboBoxSetString ((Widget
) m_mainWidget
, (char*) (const char*) value
);
133 m_inSetValue
= FALSE
;
136 void wxComboBox::Append(const wxString
& item
)
138 XmString str
= XmStringCreateLtoR((char*) (const char*) item
, XmSTRING_DEFAULT_CHARSET
);
139 XmComboBoxAddItem((Widget
) m_mainWidget
, str
, 0);
140 m_stringList
.Add(item
);
145 void wxComboBox::Delete(int n
)
147 XmComboBoxDeletePos((Widget
) m_mainWidget
, n
-1);
148 wxNode
*node
= m_stringList
.Nth(n
);
151 delete[] (char *)node
->Data();
157 void wxComboBox::Clear()
159 XmComboBoxDeleteAllItems((Widget
) m_mainWidget
);
160 m_stringList
.Clear();
163 void wxComboBox::SetSelection (int n
)
165 XmComboBoxSelectPos((Widget
) m_mainWidget
, n
+1, False
);
168 int wxComboBox::GetSelection (void) const
170 int sel
= XmComboBoxGetSelectedPos((Widget
) m_mainWidget
);
177 wxString
wxComboBox::GetString(int n
) const
179 wxNode
*node
= m_stringList
.Nth (n
);
181 return wxString((char *) node
->Data ());
183 return wxEmptyString
;
186 wxString
wxComboBox::GetStringSelection() const
188 int sel
= GetSelection();
190 return wxEmptyString
;
192 return GetString(sel
);
195 bool wxComboBox::SetStringSelection(const wxString
& sel
)
197 int n
= FindString(sel
);
207 int wxComboBox::FindString(const wxString
& s
) const
209 int *pos_list
= NULL
;
211 XmString text
= XmStringCreateSimple ((char*) (const char*) s
);
212 bool found
= (XmComboBoxGetMatchPos((Widget
) m_mainWidget
,
213 text
, &pos_list
, &count
) != 0);
217 if (found
&& count
> 0)
219 int pos
= pos_list
[0] - 1;
227 // Clipboard operations
228 void wxComboBox::Copy()
230 XmComboBoxCopy((Widget
) m_mainWidget
, CurrentTime
);
233 void wxComboBox::Cut()
235 XmComboBoxCut((Widget
) m_mainWidget
, CurrentTime
);
238 void wxComboBox::Paste()
240 XmComboBoxPaste((Widget
) m_mainWidget
);
243 void wxComboBox::SetEditable(bool WXUNUSED(editable
))
248 void wxComboBox::SetInsertionPoint(long pos
)
250 XmComboBoxSetInsertionPosition ((Widget
) m_mainWidget
, (XmTextPosition
) pos
);
253 void wxComboBox::SetInsertionPointEnd()
255 XmTextPosition pos
= XmComboBoxGetLastPosition ((Widget
) m_mainWidget
);
256 XmComboBoxSetInsertionPosition ((Widget
) m_mainWidget
, (XmTextPosition
) (pos
+ 1));
259 long wxComboBox::GetInsertionPoint() const
261 return (long) XmComboBoxGetInsertionPosition ((Widget
) m_mainWidget
);
264 long wxComboBox::GetLastPosition() const
266 return (long) XmComboBoxGetLastPosition ((Widget
) m_mainWidget
);
269 void wxComboBox::Replace(long from
, long to
, const wxString
& value
)
271 XmComboBoxReplace ((Widget
) m_mainWidget
, (XmTextPosition
) from
, (XmTextPosition
) to
,
272 (char*) (const char*) value
);
275 void wxComboBox::Remove(long from
, long to
)
277 XmComboBoxSetSelection ((Widget
) m_mainWidget
, (XmTextPosition
) from
, (XmTextPosition
) to
,
279 XmComboBoxRemove ((Widget
) m_mainWidget
);
282 void wxComboBox::SetSelection(long from
, long to
)
284 XmComboBoxSetSelection ((Widget
) m_mainWidget
, (XmTextPosition
) from
, (XmTextPosition
) to
,
288 void wxComboBoxCallback (Widget
WXUNUSED(w
), XtPointer clientData
,
289 XmComboBoxSelectionCallbackStruct
* cbs
)
291 wxComboBox
*item
= (wxComboBox
*) clientData
;
295 case XmCR_SINGLE_SELECT
:
296 case XmCR_BROWSE_SELECT
:
298 wxCommandEvent
event (wxEVT_COMMAND_COMBOBOX_SELECTED
, item
->GetId());
299 event
.m_commandInt
= cbs
->index
- 1;
300 // event.m_commandString = item->GetString (event.m_commandInt);
301 event
.m_extraLong
= TRUE
;
302 event
.SetEventObject(item
);
303 item
->ProcessCommand (event
);
306 case XmCR_VALUE_CHANGED
:
308 wxCommandEvent
event (wxEVT_COMMAND_TEXT_UPDATED
, item
->GetId());
309 event
.m_commandInt
= -1;
310 // event.m_commandString = item->GetValue();
311 event
.m_extraLong
= TRUE
;
312 event
.SetEventObject(item
);
313 item
->ProcessCommand (event
);
321 void wxComboBox::ChangeFont(bool keepOriginalSize
)
323 // Don't use the base class wxChoice's ChangeFont
324 wxWindow::ChangeFont(keepOriginalSize
);
327 void wxComboBox::ChangeBackgroundColour()
329 wxWindow::ChangeBackgroundColour();
332 void wxComboBox::ChangeForegroundColour()
334 wxWindow::ChangeBackgroundColour();