X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/ec75d791f043b3b43cac9825a2c62e9d5321e616..18dbdd3c2785b504c02ebf3739503a0183cae39b:/src/motif/combobox.cpp diff --git a/src/motif/combobox.cpp b/src/motif/combobox.cpp index 72d2836507..e4ec22c7da 100644 --- a/src/motif/combobox.cpp +++ b/src/motif/combobox.cpp @@ -9,14 +9,16 @@ // 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" + #ifdef __VMS__ #pragma message disable nosimpint #endif @@ -24,6 +26,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 +86,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(); @@ -120,10 +125,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 +145,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 +201,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 +270,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 +298,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 +356,6 @@ wxSize wxComboBox::DoGetBestSize() const return wxWindow::DoGetBestSize(); } -#endif +#endif // XmVersion < 2000 +#endif // wxUSE_COMBOBOX