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
;
43 m_backgroundColour
= parent
->GetBackgroundColour();
44 m_foregroundColour
= parent
->GetForegroundColour();
46 if (parent
) parent
->AddChild(this);
49 m_windowId
= (int)NewControlId();
53 Widget parentWidget
= (Widget
) parent
->GetClientWidget();
55 Widget buttonWidget
= XtVaCreateManagedWidget((char*) (const char*) name
,
56 xmComboBoxWidgetClass
, parentWidget
,
60 XmNeditable
, ((style
& wxCB_READONLY
) != wxCB_READONLY
),
61 XmNsorted
, ((style
& wxCB_SORT
) == wxCB_SORT
),
62 XmNstaticList
, ((style
& wxCB_SIMPLE
) == wxCB_SIMPLE
),
65 XtAddCallback (buttonWidget
, XmNselectionCallback
, (XtCallbackProc
) wxComboBoxCallback
,
67 XtAddCallback (buttonWidget
, XmNvalueChangedCallback
, (XtCallbackProc
) wxComboBoxCallback
,
71 for (i
= 0; i
< n
; i
++)
73 XmString str
= XmStringCreateLtoR((char*) (const char*) choices
[i
], XmSTRING_DEFAULT_CHARSET
);
74 XmComboBoxAddItem(buttonWidget
, str
, 0);
76 m_stringList
.Add(choices
[i
]);
80 m_mainWidget
= (Widget
) buttonWidget
;
82 XtManageChild (buttonWidget
);
86 SetCanAddEventHandler(TRUE
);
87 AttachWidget (parent
, m_mainWidget
, (WXWidget
) NULL
, pos
.x
, pos
.y
, size
.x
, size
.y
);
89 SetFont(* parent
->GetFont());
90 ChangeBackgroundColour();
95 wxString
wxComboBox::GetValue() const
97 char *s
= XmComboBoxGetString ((Widget
) m_mainWidget
);
105 return wxEmptyString
;
108 void wxComboBox::SetValue(const wxString
& value
)
112 XmComboBoxSetString ((Widget
) m_mainWidget
, (char*) (const char*) value
);
113 m_inSetValue
= FALSE
;
116 // Clipboard operations
117 void wxComboBox::Copy()
119 XmComboBoxCopy((Widget
) m_mainWidget
, CurrentTime
);
122 void wxComboBox::Cut()
124 XmComboBoxCut((Widget
) m_mainWidget
, CurrentTime
);
127 void wxComboBox::Paste()
129 XmComboBoxPaste((Widget
) m_mainWidget
);
132 void wxComboBox::SetEditable(bool editable
)
137 void wxComboBox::SetInsertionPoint(long pos
)
139 XmComboBoxSetInsertionPosition ((Widget
) m_mainWidget
, (XmTextPosition
) pos
);
142 void wxComboBox::SetInsertionPointEnd()
144 XmTextPosition pos
= XmComboBoxGetLastPosition ((Widget
) m_mainWidget
);
145 XmComboBoxSetInsertionPosition ((Widget
) m_mainWidget
, (XmTextPosition
) (pos
+ 1));
148 long wxComboBox::GetInsertionPoint() const
150 return (long) XmComboBoxGetInsertionPosition ((Widget
) m_mainWidget
);
153 long wxComboBox::GetLastPosition() const
155 return (long) XmComboBoxGetLastPosition ((Widget
) m_mainWidget
);
158 void wxComboBox::Replace(long from
, long to
, const wxString
& value
)
160 XmComboBoxReplace ((Widget
) m_mainWidget
, (XmTextPosition
) from
, (XmTextPosition
) to
,
161 (char*) (const char*) value
);
164 void wxComboBox::Remove(long from
, long to
)
166 XmComboBoxSetSelection ((Widget
) m_mainWidget
, (XmTextPosition
) from
, (XmTextPosition
) to
,
168 XmComboBoxRemove ((Widget
) m_mainWidget
);
171 void wxComboBox::SetSelection(long from
, long to
)
173 XmComboBoxSetSelection ((Widget
) m_mainWidget
, (XmTextPosition
) from
, (XmTextPosition
) to
,
177 void wxComboBoxCallback (Widget w
, XtPointer clientData
,
178 XmComboBoxSelectionCallbackStruct
* cbs
)
180 wxComboBox
*item
= (wxComboBox
*) clientData
;
184 case XmCR_SINGLE_SELECT
:
185 case XmCR_BROWSE_SELECT
:
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
);
195 case XmCR_VALUE_CHANGED
:
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
);
210 void wxComboBox::ChangeFont()
215 void wxComboBox::ChangeBackgroundColour()
220 void wxComboBox::ChangeForegroundColour()