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 #if !USE_SHARED_LIBRARY
33 IMPLEMENT_DYNAMIC_CLASS(wxComboBox
, wxControl
)
36 bool wxComboBox::Create(wxWindow
*parent
, wxWindowID id
,
37 const wxString
& value
,
40 int n
, const wxString choices
[],
42 const wxValidator
& validator
,
46 SetValidator(validator
);
48 m_windowStyle
= style
;
49 // m_backgroundColour = parent->GetBackgroundColour();
50 m_backgroundColour
= * wxWHITE
;
51 m_foregroundColour
= parent
->GetForegroundColour();
53 if (parent
) parent
->AddChild(this);
56 m_windowId
= (int)NewControlId();
60 Widget parentWidget
= (Widget
) parent
->GetClientWidget();
62 Widget buttonWidget
= XtVaCreateManagedWidget(name
.c_str(),
63 xmComboBoxWidgetClass
, parentWidget
,
67 XmNeditable
, ((style
& wxCB_READONLY
) != wxCB_READONLY
),
68 XmNsorted
, ((style
& wxCB_SORT
) == wxCB_SORT
),
69 XmNstaticList
, ((style
& wxCB_SIMPLE
) == wxCB_SIMPLE
),
72 XtAddCallback (buttonWidget
, XmNselectionCallback
, (XtCallbackProc
) wxComboBoxCallback
,
74 XtAddCallback (buttonWidget
, XmNvalueChangedCallback
, (XtCallbackProc
) wxComboBoxCallback
,
78 for (i
= 0; i
< n
; i
++)
80 XmString str
= XmStringCreateLtoR((char*) (const char*) choices
[i
], XmSTRING_DEFAULT_CHARSET
);
81 XmComboBoxAddItem(buttonWidget
, str
, 0);
83 m_stringList
.Add(choices
[i
]);
87 m_mainWidget
= (Widget
) buttonWidget
;
89 XtManageChild (buttonWidget
);
93 m_font
= parent
->GetFont();
96 SetCanAddEventHandler(TRUE
);
97 AttachWidget (parent
, m_mainWidget
, (WXWidget
) NULL
, pos
.x
, pos
.y
, size
.x
, size
.y
);
99 ChangeBackgroundColour();
104 wxComboBox::~wxComboBox()
106 DetachWidget((Widget
) m_mainWidget
); // Removes event handlers
107 XtDestroyWidget((Widget
) m_mainWidget
);
108 m_mainWidget
= (WXWidget
) 0;
111 void wxComboBox::DoSetSize(int x
, int y
, int width
, int height
, int sizeFlags
)
113 // Necessary so it doesn't call wxChoice::SetSize
114 wxWindow::DoSetSize(x
, y
, width
, height
, sizeFlags
);
117 wxString
wxComboBox::GetValue() const
119 char *s
= XmComboBoxGetString ((Widget
) m_mainWidget
);
127 return wxEmptyString
;
130 void wxComboBox::SetValue(const wxString
& value
)
134 XmComboBoxSetString ((Widget
) m_mainWidget
, (char*) (const char*) value
);
135 m_inSetValue
= FALSE
;
138 void wxComboBox::Append(const wxString
& item
)
140 XmString str
= XmStringCreateLtoR((char*) (const char*) item
, XmSTRING_DEFAULT_CHARSET
);
141 XmComboBoxAddItem((Widget
) m_mainWidget
, str
, 0);
142 m_stringList
.Add(item
);
147 void wxComboBox::Delete(int n
)
149 XmComboBoxDeletePos((Widget
) m_mainWidget
, n
-1);
150 wxNode
*node
= m_stringList
.Nth(n
);
153 delete[] (char *)node
->Data();
159 void wxComboBox::Clear()
161 XmComboBoxDeleteAllItems((Widget
) m_mainWidget
);
162 m_stringList
.Clear();
165 void wxComboBox::SetSelection (int n
)
167 XmComboBoxSelectPos((Widget
) m_mainWidget
, n
+1, False
);
170 int wxComboBox::GetSelection (void) const
172 int sel
= XmComboBoxGetSelectedPos((Widget
) m_mainWidget
);
179 wxString
wxComboBox::GetString(int n
) const
181 wxNode
*node
= m_stringList
.Nth (n
);
183 return wxString((char *) node
->Data ());
185 return wxEmptyString
;
188 wxString
wxComboBox::GetStringSelection() const
190 int sel
= GetSelection();
192 return wxEmptyString
;
194 return GetString(sel
);
197 bool wxComboBox::SetStringSelection(const wxString
& sel
)
199 int n
= FindString(sel
);
209 int wxComboBox::FindString(const wxString
& s
) const
211 int *pos_list
= NULL
;
213 XmString text
= XmStringCreateSimple ((char*) (const char*) s
);
214 bool found
= (XmComboBoxGetMatchPos((Widget
) m_mainWidget
,
215 text
, &pos_list
, &count
) != 0);
219 if (found
&& count
> 0)
221 int pos
= pos_list
[0] - 1;
229 // Clipboard operations
230 void wxComboBox::Copy()
232 XmComboBoxCopy((Widget
) m_mainWidget
, CurrentTime
);
235 void wxComboBox::Cut()
237 XmComboBoxCut((Widget
) m_mainWidget
, CurrentTime
);
240 void wxComboBox::Paste()
242 XmComboBoxPaste((Widget
) m_mainWidget
);
245 void wxComboBox::SetEditable(bool WXUNUSED(editable
))
250 void wxComboBox::SetInsertionPoint(long pos
)
252 XmComboBoxSetInsertionPosition ((Widget
) m_mainWidget
, (XmTextPosition
) pos
);
255 void wxComboBox::SetInsertionPointEnd()
257 XmTextPosition pos
= XmComboBoxGetLastPosition ((Widget
) m_mainWidget
);
258 XmComboBoxSetInsertionPosition ((Widget
) m_mainWidget
, (XmTextPosition
) (pos
+ 1));
261 long wxComboBox::GetInsertionPoint() const
263 return (long) XmComboBoxGetInsertionPosition ((Widget
) m_mainWidget
);
266 long wxComboBox::GetLastPosition() const
268 return (long) XmComboBoxGetLastPosition ((Widget
) m_mainWidget
);
271 void wxComboBox::Replace(long from
, long to
, const wxString
& value
)
273 XmComboBoxReplace ((Widget
) m_mainWidget
, (XmTextPosition
) from
, (XmTextPosition
) to
,
274 (char*) (const char*) value
);
277 void wxComboBox::Remove(long from
, long to
)
279 XmComboBoxSetSelection ((Widget
) m_mainWidget
, (XmTextPosition
) from
, (XmTextPosition
) to
,
281 XmComboBoxRemove ((Widget
) m_mainWidget
);
284 void wxComboBox::SetSelection(long from
, long to
)
286 XmComboBoxSetSelection ((Widget
) m_mainWidget
, (XmTextPosition
) from
, (XmTextPosition
) to
,
290 void wxComboBoxCallback (Widget
WXUNUSED(w
), XtPointer clientData
,
291 XmComboBoxSelectionCallbackStruct
* cbs
)
293 wxComboBox
*item
= (wxComboBox
*) clientData
;
297 case XmCR_SINGLE_SELECT
:
298 case XmCR_BROWSE_SELECT
:
300 wxCommandEvent
event (wxEVT_COMMAND_COMBOBOX_SELECTED
, item
->GetId());
301 event
.m_commandInt
= cbs
->index
- 1;
302 // event.m_commandString = item->GetString (event.m_commandInt);
303 event
.m_extraLong
= TRUE
;
304 event
.SetEventObject(item
);
305 item
->ProcessCommand (event
);
308 case XmCR_VALUE_CHANGED
:
310 wxCommandEvent
event (wxEVT_COMMAND_TEXT_UPDATED
, item
->GetId());
311 event
.m_commandInt
= -1;
312 // event.m_commandString = item->GetValue();
313 event
.m_extraLong
= TRUE
;
314 event
.SetEventObject(item
);
315 item
->ProcessCommand (event
);
323 void wxComboBox::ChangeFont(bool keepOriginalSize
)
325 // Don't use the base class wxChoice's ChangeFont
326 wxWindow::ChangeFont(keepOriginalSize
);
329 void wxComboBox::ChangeBackgroundColour()
331 wxWindow::ChangeBackgroundColour();
334 void wxComboBox::ChangeForegroundColour()
336 wxWindow::ChangeBackgroundColour();