X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/ec75d791f043b3b43cac9825a2c62e9d5321e616..73fe67bd60b57f95dc63809f7843ed2a15928436:/src/motif/combobox.cpp diff --git a/src/motif/combobox.cpp b/src/motif/combobox.cpp index 72d2836507..4389cc1f00 100644 --- a/src/motif/combobox.cpp +++ b/src/motif/combobox.cpp @@ -9,14 +9,17 @@ // Licence: wxWindows licence ///////////////////////////////////////////////////////////////////////////// -#ifdef __GNUG__ +#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA) #pragma implementation "combobox.h" #endif -#include "wx/combobox.h" +#include "wx/setup.h" #if wxUSE_COMBOBOX +#include "wx/combobox.h" +#include "wx/arrstr.h" + #ifdef __VMS__ #pragma message disable nosimpint #endif @@ -24,6 +27,10 @@ #ifdef __VMS__ #pragma message enable nosimpint #endif + +// use the old, GPL'd combobox +#if (XmVersion < 2000) + #include "xmcombo/xmcombo.h" #include "wx/motif/private.h" @@ -80,7 +87,6 @@ bool wxComboBox::Create(wxWindow *parent, wxWindowID id, XtAddCallback (buttonWidget, XmNvalueChangedCallback, (XtCallbackProc) wxComboBoxCallback, (XtPointer) this); - SetCanAddEventHandler(TRUE); AttachWidget (parent, m_mainWidget, (WXWidget) NULL, pos.x, pos.y, size.x, size.y); ChangeBackgroundColour(); @@ -88,6 +94,20 @@ bool wxComboBox::Create(wxWindow *parent, wxWindowID id, return TRUE; } +bool wxComboBox::Create(wxWindow *parent, wxWindowID id, + const wxString& value, + const wxPoint& pos, + const wxSize& size, + const wxArrayString& choices, + long style, + const wxValidator& validator, + const wxString& name) +{ + wxCArrayString chs(choices); + return Create(parent, id, value, pos, size, chs.GetCount(), + chs.GetStrings(), style, validator, name); +} + wxComboBox::~wxComboBox() { DetachWidget((Widget) m_mainWidget); // Removes event handlers @@ -120,10 +140,16 @@ void wxComboBox::SetValue(const wxString& value) { m_inSetValue = TRUE; if( !value.empty() ) - XmComboBoxSetString( (Widget)m_mainWidget, (char*)value.c_str() ); + XmComboBoxSetString( (Widget)m_mainWidget, + wxConstCast(value.c_str(), char) ); m_inSetValue = FALSE; } +void wxComboBox::SetString(int n, const wxString& s) +{ + wxFAIL_MSG( wxT("wxComboBox::SetString only implemented for Motif 2.0") ); +} + int wxComboBox::DoAppend(const wxString& item) { wxXmString str( item.c_str() ); @@ -134,13 +160,30 @@ int wxComboBox::DoAppend(const wxString& item) return GetCount() - 1; } +int wxComboBox::DoInsert(const wxString& item, int pos) +{ + wxCHECK_MSG(!(GetWindowStyle() & wxCB_SORT), -1, wxT("can't insert into sorted list")); + wxCHECK_MSG((pos>=0) && (pos<=GetCount()), -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 ++; + + return pos; +} + void wxComboBox::Delete(int n) { XmComboBoxDeletePos((Widget) m_mainWidget, n+1); - wxNode *node = m_stringList.Nth(n); + wxStringList::Node *node = m_stringList.Item(n); if (node) { - delete[] (char *)node->Data(); + delete[] node->GetData(); delete node; } m_clientDataDict.Delete(n, HasClientObjectData()); @@ -173,9 +216,9 @@ int wxComboBox::GetSelection (void) const wxString wxComboBox::GetString(int n) const { - wxNode *node = m_stringList.Nth(n); + wxStringList::Node *node = m_stringList.Item(n); if (node) - return wxString((char *) node->Data ()); + return wxString(node->GetData ()); else return wxEmptyString; } @@ -242,8 +285,9 @@ long wxComboBox::GetLastPosition() const void wxComboBox::Replace(long from, long to, const wxString& value) { - XmComboBoxReplace ((Widget) m_mainWidget, (XmTextPosition) from, (XmTextPosition) to, - (char*) (const char*) value); + XmComboBoxReplace ((Widget) m_mainWidget, (XmTextPosition) from, + (XmTextPosition) to, + wxConstCast(value.c_str(), char)); } void wxComboBox::Remove(long from, long to) @@ -269,7 +313,8 @@ void wxComboBoxCallback (Widget WXUNUSED(w), XtPointer clientData, case XmCR_SINGLE_SELECT: case XmCR_BROWSE_SELECT: { - wxCommandEvent event (wxEVT_COMMAND_COMBOBOX_SELECTED, item->GetId()); + wxCommandEvent event (wxEVT_COMMAND_COMBOBOX_SELECTED, + item->GetId()); event.m_commandInt = cbs->index - 1; event.m_commandString = item->GetString (event.m_commandInt); if ( item->HasClientObjectData() ) @@ -326,5 +371,6 @@ wxSize wxComboBox::DoGetBestSize() const return wxWindow::DoGetBestSize(); } -#endif +#endif // XmVersion < 2000 +#endif // wxUSE_COMBOBOX