X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/e1aae5288576cd0066d2cbbf92935a969110bcea..a83ea9c15a7ac7bbdc6686164cfcbbc21ae5031a:/src/motif/combobox_native.cpp diff --git a/src/motif/combobox_native.cpp b/src/motif/combobox_native.cpp index aa8eac0f0d..f610a3bfab 100644 --- a/src/motif/combobox_native.cpp +++ b/src/motif/combobox_native.cpp @@ -9,11 +9,15 @@ // Licence: wxWindows licence ///////////////////////////////////////////////////////////////////////////// +// For compilers that support precompilation, includes "wx.h". +#include "wx/wxprec.h" + #include "wx/setup.h" #if wxUSE_COMBOBOX #include "wx/combobox.h" +#include "wx/arrstr.h" #ifdef __VMS__ #pragma message disable nosimpint @@ -114,7 +118,6 @@ bool wxComboBox::Create(wxWindow *parent, wxWindowID id, if( size.x != -1 ) best.x = size.x; if( size.y != -1 ) best.y = size.y; - SetCanAddEventHandler(true); AttachWidget (parent, m_mainWidget, (WXWidget) NULL, pos.x, pos.y, best.x, best.y); @@ -123,6 +126,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); +} + void wxComboBox::AdjustDropDownListSize() { int newListCount = -1, itemCount = GetCount(); @@ -179,8 +196,10 @@ void wxComboBox::SetValue(const wxString& value) { m_inSetValue = true; + // Fix crash; probably an OpenMotif bug + const char* val = value.c_str() ? value.c_str() : ""; XtVaSetValues( GetXmText(this), - XmNvalue, (char *)value.c_str(), + XmNvalue, wxConstCast(val, char), NULL); m_inSetValue = false; @@ -196,6 +215,22 @@ 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, False); + m_noStrings ++; + AdjustDropDownListSize(); + + return GetCount() - 1; +} + void wxComboBox::Delete(int n) { #ifdef LESSTIF_VERSION @@ -229,19 +264,22 @@ void wxComboBox::Clear() void wxComboBox::SetSelection (int n) { -#ifdef LESSTIF_VERSION + m_inSetSelection = true; + +#if wxCHECK_LESSTIF() XmListSelectPos (GetXmList(this), n + 1, false); SetValue(GetString(n)); #else +#if 0 wxXmString str( GetString(n).c_str() ); XmComboBoxSelectItem((Widget) m_mainWidget, str()); -#if 0 - // does it work for Motif +#endif XtVaSetValues( (Widget)m_mainWidget, - XmNselectedPosition, n + 1, + XmNselectedPosition, n, NULL ); #endif -#endif + + m_inSetSelection = false; } int wxComboBox::GetSelection (void) const @@ -304,7 +342,7 @@ long wxComboBox::GetLastPosition() const void wxComboBox::Replace(long from, long to, const wxString& value) { XmTextReplace( GetXmText(this), (XmTextPosition)from, (XmTextPosition)to, - (char*)value.c_str() ); + wxConstCast(value.c_str(), char) ); } void wxComboBox::Remove(long from, long to) @@ -327,6 +365,8 @@ void wxComboBoxCallback (Widget WXUNUSED(w), XtPointer clientData, { wxComboBox *item = (wxComboBox *) clientData; + if( item->m_inSetSelection ) return; + switch (cbs->reason) { case XmCR_SELECT: @@ -337,7 +377,7 @@ void wxComboBoxCallback (Widget WXUNUSED(w), XtPointer clientData, { wxCommandEvent event (wxEVT_COMMAND_COMBOBOX_SELECTED, item->GetId()); - int idx = cbs->item_position - 1; + int idx = cbs->item_position; event.m_commandInt = idx; event.m_commandString = item->GetString (idx); if ( item->HasClientObjectData() ) @@ -346,7 +386,7 @@ void wxComboBoxCallback (Widget WXUNUSED(w), XtPointer clientData, event.SetClientData( item->GetClientData(idx) ); event.m_extraLong = true; event.SetEventObject(item); - item->ProcessCommand (event); + item->GetEventHandler()->ProcessEvent(event); break; } case XmCR_VALUE_CHANGED: @@ -356,7 +396,7 @@ void wxComboBoxCallback (Widget WXUNUSED(w), XtPointer clientData, event.m_commandString = item->GetValue(); event.m_extraLong = true; event.SetEventObject(item); - item->ProcessCommand (event); + item->GetEventHandler()->ProcessEvent(event); break; } default: