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 #include "xmcombo/xmcombo.h"
23 void wxComboBoxCallback (Widget w
, XtPointer clientData
,
24 XmComboBoxSelectionCallbackStruct
* cbs
);
26 #if !USE_SHARED_LIBRARY
27 IMPLEMENT_DYNAMIC_CLASS(wxComboBox
, wxControl
)
30 bool wxComboBox::Create(wxWindow
*parent
, wxWindowID id
,
31 const wxString
& value
,
34 int n
, const wxString choices
[],
36 const wxValidator
& validator
,
40 SetValidator(validator
);
42 m_windowStyle
= style
;
44 if (parent
) parent
->AddChild(this);
47 m_windowId
= (int)NewControlId();
51 Widget parentWidget
= (Widget
) parent
->GetClientWidget();
53 Widget buttonWidget
= XtVaCreateManagedWidget((char*) (const char*) name
,
54 xmComboBoxWidgetClass
, parentWidget
,
58 XmNeditable
, ((style
& wxCB_READONLY
) != wxCB_READONLY
),
59 XmNsorted
, ((style
& wxCB_SORT
) == wxCB_SORT
),
60 XmNstaticList
, ((style
& wxCB_SIMPLE
) == wxCB_SIMPLE
),
63 XtAddCallback (buttonWidget
, XmNselectionCallback
, (XtCallbackProc
) wxComboBoxCallback
,
65 XtAddCallback (buttonWidget
, XmNvalueChangedCallback
, (XtCallbackProc
) wxComboBoxCallback
,
69 for (i
= 0; i
< n
; i
++)
71 XmString str
= XmStringCreateLtoR((char*) (const char*) choices
[i
], XmSTRING_DEFAULT_CHARSET
);
72 XmComboBoxAddItem(buttonWidget
, str
, 0);
74 m_stringList
.Add(choices
[i
]);
78 m_mainWidget
= (Widget
) buttonWidget
;
80 XtManageChild (buttonWidget
);
84 SetCanAddEventHandler(TRUE
);
85 AttachWidget (parent
, m_mainWidget
, (WXWidget
) NULL
, pos
.x
, pos
.y
, size
.x
, size
.y
);
87 SetFont(* parent
->GetFont());
88 ChangeColour(m_mainWidget
);
93 wxString
wxComboBox::GetValue() const
95 char *s
= XmComboBoxGetString ((Widget
) m_mainWidget
);
103 return wxEmptyString
;
106 void wxComboBox::SetValue(const wxString
& value
)
110 XmComboBoxSetString ((Widget
) m_mainWidget
, (char*) (const char*) value
);
111 m_inSetValue
= FALSE
;
114 // Clipboard operations
115 void wxComboBox::Copy()
117 XmComboBoxCopy((Widget
) m_mainWidget
, CurrentTime
);
120 void wxComboBox::Cut()
122 XmComboBoxCut((Widget
) m_mainWidget
, CurrentTime
);
125 void wxComboBox::Paste()
127 XmComboBoxPaste((Widget
) m_mainWidget
);
130 void wxComboBox::SetEditable(bool editable
)
135 void wxComboBox::SetInsertionPoint(long pos
)
137 XmComboBoxSetInsertionPosition ((Widget
) m_mainWidget
, (XmTextPosition
) pos
);
140 void wxComboBox::SetInsertionPointEnd()
142 XmTextPosition pos
= XmComboBoxGetLastPosition ((Widget
) m_mainWidget
);
143 XmComboBoxSetInsertionPosition ((Widget
) m_mainWidget
, (XmTextPosition
) (pos
+ 1));
146 long wxComboBox::GetInsertionPoint() const
148 return (long) XmComboBoxGetInsertionPosition ((Widget
) m_mainWidget
);
151 long wxComboBox::GetLastPosition() const
153 return (long) XmComboBoxGetLastPosition ((Widget
) m_mainWidget
);
156 void wxComboBox::Replace(long from
, long to
, const wxString
& value
)
158 XmComboBoxReplace ((Widget
) m_mainWidget
, (XmTextPosition
) from
, (XmTextPosition
) to
,
159 (char*) (const char*) value
);
162 void wxComboBox::Remove(long from
, long to
)
164 XmComboBoxSetSelection ((Widget
) m_mainWidget
, (XmTextPosition
) from
, (XmTextPosition
) to
,
166 XmComboBoxRemove ((Widget
) m_mainWidget
);
169 void wxComboBox::SetSelection(long from
, long to
)
171 XmComboBoxSetSelection ((Widget
) m_mainWidget
, (XmTextPosition
) from
, (XmTextPosition
) to
,
175 void wxComboBoxCallback (Widget w
, XtPointer clientData
,
176 XmComboBoxSelectionCallbackStruct
* cbs
)
178 wxComboBox
*item
= (wxComboBox
*) clientData
;
182 case XmCR_SINGLE_SELECT
:
183 case XmCR_BROWSE_SELECT
:
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
);
193 case XmCR_VALUE_CHANGED
:
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
);