X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/d8d1818419134415331bfe9f6d4703a8f0742caa..64ea838d8f4d1853b7d850db93ee565e901d099a:/src/motif/combobox_native.cpp diff --git a/src/motif/combobox_native.cpp b/src/motif/combobox_native.cpp index 846d4e10f3..9fbb5241a2 100644 --- a/src/motif/combobox_native.cpp +++ b/src/motif/combobox_native.cpp @@ -1,5 +1,5 @@ ///////////////////////////////////////////////////////////////////////////// -// Name: combobox_native.cpp +// Name: src/motif/combobox_native.cpp // Purpose: wxComboBox class // Author: Julian Smart, Ian Brown // Modified by: @@ -9,12 +9,17 @@ // Licence: wxWindows licence ///////////////////////////////////////////////////////////////////////////// -#include "wx/setup.h" +// For compilers that support precompilation, includes "wx.h". +#include "wx/wxprec.h" #if wxUSE_COMBOBOX #include "wx/combobox.h" +#ifndef WX_PRECOMP + #include "wx/arrstr.h" +#endif + #ifdef __VMS__ #pragma message disable nosimpint #endif @@ -75,6 +80,7 @@ bool wxComboBox::Create(wxWindow *parent, wxWindowID id, { if( !CreateControl( parent, id, pos, size, style, validator, name ) ) return false; + PreCreation(); Widget parentWidget = (Widget) parent->GetClientWidget(); @@ -88,7 +94,7 @@ bool wxComboBox::Create(wxWindow *parent, wxWindowID id, Widget buttonWidget= XtVaCreateManagedWidget(name.c_str(), xmComboBoxWidgetClass, parentWidget, - XmNcomboBoxType, cb_type, + XmNcomboBoxType, cb_type, NULL); m_mainWidget = (Widget) buttonWidget; @@ -101,8 +107,6 @@ bool wxComboBox::Create(wxWindow *parent, wxWindowID id, SetValue(value); - ChangeFont(false); - XtAddCallback (buttonWidget, XmNselectionCallback, (XtCallbackProc) wxComboBoxCallback, (XtPointer) this); @@ -111,18 +115,30 @@ bool wxComboBox::Create(wxWindow *parent, wxWindowID id, (XtPointer) this); wxSize best = GetBestSize(); - if( size.x != -1 ) best.x = size.x; - if( size.y != -1 ) best.y = size.y; + if( size.x != wxDefaultCoord ) best.x = size.x; + if( size.y != wxDefaultCoord ) best.y = size.y; - SetCanAddEventHandler(true); + PostCreation(); AttachWidget (parent, m_mainWidget, (WXWidget) NULL, pos.x, pos.y, best.x, best.y); - ChangeBackgroundColour(); - 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(); @@ -145,26 +161,15 @@ 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, int width, int height, int sizeFlags) +void wxComboBox::DoSetSize(int x, int y, int width, int WXUNUSED(height), int sizeFlags) { // Necessary so it doesn't call wxChoice::SetSize wxWindow::DoSetSize(x, y, width, DoGetBestSize().y, sizeFlags); } -wxString wxComboBox::GetValue() const -{ - char* s = XmTextGetString (GetXmText (this)); - wxString str(s); - if (s) - XtFree (s); - return str; -} - -void wxComboBox::SetString(int n, const wxString& s) +void wxComboBox::SetString(unsigned int n, const wxString& s) { wxXmString text(s); Widget listBox = GetXmList(this); @@ -179,26 +184,35 @@ 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, wxConstCast(val, char), + XmNvalue, (const char*)value.mb_str(), NULL); m_inSetValue = false; } -int wxComboBox::DoAppend(const wxString& item) +int wxComboBox::DoInsertItems(const wxArrayStringsAdapter & items, + unsigned int pos, + void **clientData, wxClientDataType type) { - wxXmString str( item.c_str() ); - XmComboBoxAddItem((Widget) m_mainWidget, str(), 0, False); - m_noStrings ++; + const unsigned int numItems = items.GetCount(); + + AllocClientData(numItems); + for ( unsigned int i = 0; i < numItems; ++i, ++pos ) + { + wxXmString str( items[i].c_str() ); + XmComboBoxAddItem((Widget) m_mainWidget, str(), + GetMotifPosition(pos), False); + + InsertNewItemClientData(pos, clientData, i, type); + } + AdjustDropDownListSize(); - return GetCount() - 1; + return pos - 1; } -void wxComboBox::Delete(int n) +void wxComboBox::DoDeleteOneItem(unsigned int n) { #ifdef LESSTIF_VERSION XmListDeletePos (GetXmList(this), n + 1); @@ -206,8 +220,8 @@ void wxComboBox::Delete(int n) XmComboBoxDeletePos((Widget) m_mainWidget, n+1); #endif - m_clientDataDict.Delete(n, HasClientObjectData()); - m_noStrings--; + wxControlWithItems::DoDeleteOneItem(n); + m_stringArray.RemoveAt(size_t(n)); AdjustDropDownListSize(); } @@ -217,16 +231,17 @@ void wxComboBox::Clear() #ifdef LESSTIF_VERSION XmListDeleteAllItems (GetXmList(this)); #else - while(m_noStrings > 0) + size_t n = m_stringArray.GetCount(); + while(n > 0) { - XmComboBoxDeletePos((Widget) m_mainWidget, m_noStrings--); + XmComboBoxDeletePos((Widget) m_mainWidget, n--); } #endif - if ( HasClientObjectData() ) - m_clientDataDict.DestroyData(); - m_noStrings = 0; + m_stringArray.Clear(); AdjustDropDownListSize(); + + wxTextEntry::Clear(); } void wxComboBox::SetSelection (int n) @@ -238,7 +253,7 @@ void wxComboBox::SetSelection (int n) SetValue(GetString(n)); #else #if 0 - wxXmString str( GetString(n).c_str() ); + wxXmString str(GetString(n).c_str()); XmComboBoxSelectItem((Widget) m_mainWidget, str()); #endif XtVaSetValues( (Widget)m_mainWidget, @@ -249,82 +264,21 @@ void wxComboBox::SetSelection (int n) m_inSetSelection = false; } -int wxComboBox::GetSelection (void) const +int wxComboBox::GetSelection() const { return wxDoGetSelectionInList( GetXmList( this ) ); } -wxString wxComboBox::GetString(int n) const +wxString wxComboBox::GetString(unsigned int n) const { return wxDoGetStringInList( GetXmList(this), n ); } -int wxComboBox::FindString(const wxString& s) const +int wxComboBox::FindString(const wxString& s, bool WXUNUSED(bCase)) const { - return wxDoFindStringInList( GetXmList( this ), s ); -} - -// Clipboard operations -void wxComboBox::Copy() -{ - XmTextCopy( GetXmText(this), CurrentTime ); -} - -void wxComboBox::Cut() -{ - XmTextCut( GetXmText(this), CurrentTime ); -} + // FIXME: back to base class for not supported value of bCase -void wxComboBox::Paste() -{ - XmTextPaste( GetXmText(this) ); -} - -void wxComboBox::SetEditable(bool WXUNUSED(editable)) -{ - // TODO -} - -void wxComboBox::SetInsertionPoint(long pos) -{ - XmTextSetInsertionPosition( GetXmText(this), (XmTextPosition)pos ); -} - -void wxComboBox::SetInsertionPointEnd() -{ - SetInsertionPoint( GetLastPosition() ); -} - -long wxComboBox::GetInsertionPoint() const -{ - return (long)XmTextGetInsertionPosition( GetXmText(this) ); -} - -long wxComboBox::GetLastPosition() const -{ - XmTextPosition pos = XmTextGetLastPosition( GetXmText(this) ); - return (long)pos; -} - -void wxComboBox::Replace(long from, long to, const wxString& value) -{ - XmTextReplace( GetXmText(this), (XmTextPosition)from, (XmTextPosition)to, - wxConstCast(value.c_str(), char) ); -} - -void wxComboBox::Remove(long from, long to) -{ - SetSelection( from, to ); - XmTextRemove( GetXmText(this) ); -} - -void wxComboBox::SetSelection(long from, long to) -{ - if( to == -1 ) - to = GetLastPosition(); - - XmTextSetSelection( GetXmText(this), (XmTextPosition)from, - (XmTextPosition)to, (Time)0 ); + return wxDoFindStringInList( GetXmList( this ), s ); } void wxComboBoxCallback (Widget WXUNUSED(w), XtPointer clientData, @@ -345,25 +299,25 @@ void wxComboBoxCallback (Widget WXUNUSED(w), XtPointer clientData, wxCommandEvent event (wxEVT_COMMAND_COMBOBOX_SELECTED, item->GetId()); int idx = cbs->item_position; - event.m_commandInt = idx; - event.m_commandString = item->GetString (idx); + event.SetInt(idx); + event.SetString( item->GetString (idx) ); if ( item->HasClientObjectData() ) event.SetClientObject( item->GetClientObject(idx) ); else if ( item->HasClientUntypedData() ) event.SetClientData( item->GetClientData(idx) ); - event.m_extraLong = true; + event.SetExtraLong(true); event.SetEventObject(item); - item->GetEventHandler()->ProcessEvent(event); + item->HandleWindowEvent(event); break; } case XmCR_VALUE_CHANGED: { wxCommandEvent event (wxEVT_COMMAND_TEXT_UPDATED, item->GetId()); - event.m_commandInt = -1; - event.m_commandString = item->GetValue(); - event.m_extraLong = true; + event.SetInt(-1); + event.SetString( item->GetValue() ); + event.SetExtraLong(true); event.SetEventObject(item); - item->GetEventHandler()->ProcessEvent(event); + item->HandleWindowEvent(event); break; } default: @@ -373,7 +327,7 @@ void wxComboBoxCallback (Widget WXUNUSED(w), XtPointer clientData, void wxComboBox::ChangeFont(bool keepOriginalSize) { - if( m_font.Ok() ) + if( m_font.IsOk() && m_mainWidget != NULL ) { wxDoChangeFont( GetXmText(this), m_font ); wxDoChangeFont( GetXmList(this), m_font ); @@ -422,6 +376,11 @@ wxSize wxComboBox::DoGetBestSize() const return wxWindow::DoGetBestSize(); } +WXWidget wxComboBox::GetTextWidget() const +{ + return (WXWidget)GetXmText(this); +} + #endif // XmVersion >= 2000 #endif // wxUSE_COMBOBOX