X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/aa61d3525370a9b9fa8c797d9b7f89d96994db5f..5cdcb78775c94667cc827acd4eaa39900026ba19:/src/motif/combobox.cpp diff --git a/src/motif/combobox.cpp b/src/motif/combobox.cpp index 956dfd7339..4083a88ebd 100644 --- a/src/motif/combobox.cpp +++ b/src/motif/combobox.cpp @@ -15,7 +15,10 @@ #if wxUSE_COMBOBOX #include "wx/combobox.h" -#include "wx/arrstr.h" + +#ifndef WX_PRECOMP + #include "wx/arrstr.h" +#endif #ifdef __VMS__ #pragma message disable nosimpint @@ -48,6 +51,7 @@ bool wxComboBox::Create(wxWindow *parent, wxWindowID id, { if( !CreateControl( parent, id, pos, size, style, validator, name ) ) return false; + PreCreation(); m_noStrings = n; @@ -77,17 +81,14 @@ bool wxComboBox::Create(wxWindow *parent, wxWindowID id, SetValue(value); - ChangeFont(false); - XtAddCallback (buttonWidget, XmNselectionCallback, (XtCallbackProc) wxComboBoxCallback, (XtPointer) this); XtAddCallback (buttonWidget, XmNvalueChangedCallback, (XtCallbackProc) wxComboBoxCallback, (XtPointer) this); + PostCreation(); AttachWidget (parent, m_mainWidget, (WXWidget) NULL, pos.x, pos.y, size.x, size.y); - ChangeBackgroundColour(); - return true; } @@ -110,8 +111,6 @@ wxComboBox::~wxComboBox() DetachWidget((Widget) m_mainWidget); // Removes event handlers XtDestroyWidget((Widget) m_mainWidget); m_mainWidget = (WXWidget) 0; - if ( HasClientObjectData() ) - m_clientDataDict.DestroyData(); } void wxComboBox::DoSetSize(int x, int y, @@ -137,11 +136,12 @@ wxString wxComboBox::GetValue() const void wxComboBox::SetValue(const wxString& value) { - m_inSetValue = true; if( !value.empty() ) - XmComboBoxSetString( (Widget)m_mainWidget, - wxConstCast(value.c_str(), char) ); - m_inSetValue = false; + { + m_inSetValue = true; + XmComboBoxSetString((Widget)m_mainWidget, value.char_str()); + m_inSetValue = false; + } } void wxComboBox::SetString(unsigned int WXUNUSED(n), const wxString& WXUNUSED(s)) @@ -149,34 +149,29 @@ void wxComboBox::SetString(unsigned int WXUNUSED(n), const wxString& WXUNUSED(s) wxFAIL_MSG( wxT("wxComboBox::SetString only implemented for Motif 2.0") ); } -int wxComboBox::DoAppend(const wxString& item) +// TODO auto-sorting is not supported by the code +int wxComboBox::DoInsertItems(const wxArrayStringsAdapter& items, + unsigned int pos, + void **clientData, + wxClientDataType type) { - wxXmString str( item.c_str() ); - XmComboBoxAddItem((Widget) m_mainWidget, str(), 0); - m_stringList.Add(item); - m_noStrings ++; + const unsigned int numItems = items.GetCount(); - return GetCount() - 1; -} - -int wxComboBox::DoInsert(const wxString& item, unsigned int pos) -{ - wxCHECK_MSG(!(GetWindowStyle() & wxCB_SORT), -1, wxT("can't insert into sorted list")); - wxCHECK_MSG(IsValidInsert(pos), -1, wxT("invalid index")); - - if (pos == GetCount()) - return DoAppend(item); - - wxXmString str( item.c_str() ); - XmComboBoxAddItem((Widget) m_mainWidget, str(), pos+1); - wxChar* copy = wxStrcpy(new wxChar[item.length() + 1], item.c_str()); - m_stringList.Insert(pos, copy); - m_noStrings ++; + AllocClientData(numItems); + for( unsigned int i = 0; i < numItems; ++i, ++pos ) + { + wxXmString str( items[i].c_str() ); + XmComboBoxAddItem((Widget) m_mainWidget, str(), GetMotifPosition(pos)); + wxChar* copy = wxStrcpy(new wxChar[items[i].length() + 1], items[i].c_str()); + m_stringList.Insert(pos, copy); + m_noStrings ++; + InsertNewItemClientData(pos, clientData, i, type); + } - return pos; + return pos - 1; } -void wxComboBox::Delete(unsigned int n) +void wxComboBox::DoDeleteOneItem(unsigned int n) { XmComboBoxDeletePos((Widget) m_mainWidget, n+1); wxStringList::Node *node = m_stringList.Item(n); @@ -185,17 +180,16 @@ void wxComboBox::Delete(unsigned int n) delete[] node->GetData(); delete node; } - m_clientDataDict.Delete(n, HasClientObjectData()); + wxControlWithItems::DoDeleteOneItem(n); m_noStrings--; } -void wxComboBox::Clear() +void wxComboBox::DoClear() { XmComboBoxDeleteAllItems((Widget) m_mainWidget); m_stringList.Clear(); - if ( HasClientObjectData() ) - m_clientDataDict.DestroyData(); + wxControlWithItems::DoClear(); m_noStrings = 0; } @@ -288,7 +282,7 @@ void wxComboBox::Replace(long from, long to, const wxString& value) { XmComboBoxReplace ((Widget) m_mainWidget, (XmTextPosition) from, (XmTextPosition) to, - wxConstCast(value.c_str(), char)); + value.char_str()); } void wxComboBox::Remove(long from, long to)