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 m_windowFont
= parent
->GetFont();
89 SetCanAddEventHandler(TRUE
);
90 AttachWidget (parent
, m_mainWidget
, (WXWidget
) NULL
, pos
.x
, pos
.y
, size
.x
, size
.y
);
92 ChangeBackgroundColour();
97 wxString
wxComboBox::GetValue() const
99 char *s
= XmComboBoxGetString ((Widget
) m_mainWidget
);
107 return wxEmptyString
;
110 void wxComboBox::SetValue(const wxString
& value
)
114 XmComboBoxSetString ((Widget
) m_mainWidget
, (char*) (const char*) value
);
115 m_inSetValue
= FALSE
;
118 // Clipboard operations
119 void wxComboBox::Copy()
121 XmComboBoxCopy((Widget
) m_mainWidget
, CurrentTime
);
124 void wxComboBox::Cut()
126 XmComboBoxCut((Widget
) m_mainWidget
, CurrentTime
);
129 void wxComboBox::Paste()
131 XmComboBoxPaste((Widget
) m_mainWidget
);
134 void wxComboBox::SetEditable(bool editable
)
139 void wxComboBox::SetInsertionPoint(long pos
)
141 XmComboBoxSetInsertionPosition ((Widget
) m_mainWidget
, (XmTextPosition
) pos
);
144 void wxComboBox::SetInsertionPointEnd()
146 XmTextPosition pos
= XmComboBoxGetLastPosition ((Widget
) m_mainWidget
);
147 XmComboBoxSetInsertionPosition ((Widget
) m_mainWidget
, (XmTextPosition
) (pos
+ 1));
150 long wxComboBox::GetInsertionPoint() const
152 return (long) XmComboBoxGetInsertionPosition ((Widget
) m_mainWidget
);
155 long wxComboBox::GetLastPosition() const
157 return (long) XmComboBoxGetLastPosition ((Widget
) m_mainWidget
);
160 void wxComboBox::Replace(long from
, long to
, const wxString
& value
)
162 XmComboBoxReplace ((Widget
) m_mainWidget
, (XmTextPosition
) from
, (XmTextPosition
) to
,
163 (char*) (const char*) value
);
166 void wxComboBox::Remove(long from
, long to
)
168 XmComboBoxSetSelection ((Widget
) m_mainWidget
, (XmTextPosition
) from
, (XmTextPosition
) to
,
170 XmComboBoxRemove ((Widget
) m_mainWidget
);
173 void wxComboBox::SetSelection(long from
, long to
)
175 XmComboBoxSetSelection ((Widget
) m_mainWidget
, (XmTextPosition
) from
, (XmTextPosition
) to
,
179 void wxComboBoxCallback (Widget w
, XtPointer clientData
,
180 XmComboBoxSelectionCallbackStruct
* cbs
)
182 wxComboBox
*item
= (wxComboBox
*) clientData
;
186 case XmCR_SINGLE_SELECT
:
187 case XmCR_BROWSE_SELECT
:
189 wxCommandEvent
event (wxEVT_COMMAND_COMBOBOX_SELECTED
, item
->GetId());
190 event
.m_commandInt
= cbs
->index
- 1;
191 // event.m_commandString = item->GetString (event.m_commandInt);
192 event
.m_extraLong
= TRUE
;
193 event
.SetEventObject(item
);
194 item
->ProcessCommand (event
);
197 case XmCR_VALUE_CHANGED
:
199 wxCommandEvent
event (wxEVT_COMMAND_TEXT_UPDATED
, item
->GetId());
200 event
.m_commandInt
= -1;
201 // event.m_commandString = item->GetValue();
202 event
.m_extraLong
= TRUE
;
203 event
.SetEventObject(item
);
204 item
->ProcessCommand (event
);
212 void wxComboBox::ChangeFont(bool keepOriginalSize
)
214 // Don't use the base class wxChoice's ChangeFont
215 wxWindow::ChangeFont(keepOriginalSize
);
218 void wxComboBox::ChangeBackgroundColour()
220 wxWindow::ChangeBackgroundColour();
223 void wxComboBox::ChangeForegroundColour()
225 wxWindow::ChangeBackgroundColour();