X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/6c8a980fc412792e64256724e02e9d387ee38e21..89c831801467203372b6964a785823f19e8063dd:/src/common/ctrlsub.cpp diff --git a/src/common/ctrlsub.cpp b/src/common/ctrlsub.cpp index 09cff4de8e..7f294c3f5d 100644 --- a/src/common/ctrlsub.cpp +++ b/src/common/ctrlsub.cpp @@ -1,11 +1,11 @@ /////////////////////////////////////////////////////////////////////////////// // Name: common/ctrlsub.cpp -// Purpose: wxControlWithItems implementation +// Purpose: wxItemContainer implementation // Author: Vadim Zeitlin // Modified by: // Created: 22.10.99 // RCS-ID: $Id$ -// Copyright: (c) wxWindows team +// Copyright: (c) wxWidgets team // Licence: wxWindows licence /////////////////////////////////////////////////////////////////////////////// @@ -17,10 +17,6 @@ // headers // ---------------------------------------------------------------------------- -#ifdef __GNUG__ - #pragma implementation "controlwithitems.h" -#endif - // For compilers that support precompilation, includes "wx.h". #include "wx/wxprec.h" @@ -28,19 +24,27 @@ #pragma hdrstop #endif +#if wxUSE_CONTROLS + #ifndef WX_PRECOMP #include "wx/ctrlsub.h" + #include "wx/arrstr.h" #endif // ============================================================================ -// implementation +// wxItemContainerImmutable implementation // ============================================================================ +wxItemContainerImmutable::~wxItemContainerImmutable() +{ + // this destructor is required for Darwin +} + // ---------------------------------------------------------------------------- // selection // ---------------------------------------------------------------------------- -wxString wxControlWithItems::GetStringSelection() const +wxString wxItemContainerImmutable::GetStringSelection() const { wxString s; int sel = GetSelection(); @@ -50,45 +54,125 @@ wxString wxControlWithItems::GetStringSelection() const return s; } +bool wxItemContainerImmutable::SetStringSelection(const wxString& s) +{ + const int sel = FindString(s); + if ( sel == wxNOT_FOUND ) + return false; + + SetSelection(sel); + + return true; +} + +wxArrayString wxItemContainerImmutable::GetStrings() const +{ + wxArrayString result; + + const size_t count = GetCount(); + result.Alloc(count); + for ( size_t n = 0; n < count; n++ ) + result.Add(GetString(n)); + + return result; +} + +// ============================================================================ +// wxItemContainer implementation +// ============================================================================ + +wxItemContainer::~wxItemContainer() +{ + // this destructor is required for Darwin +} + +// ---------------------------------------------------------------------------- +// appending items +// ---------------------------------------------------------------------------- + +void wxItemContainer::Append(const wxArrayString& strings) +{ + size_t count = strings.GetCount(); + for ( size_t n = 0; n < count; n++ ) + { + Append(strings[n]); + } +} + +int wxItemContainer::Insert(const wxString& item, int pos, void *clientData) +{ + int n = DoInsert(item, pos); + if ( n != wxNOT_FOUND ) + SetClientData(n, clientData); + + return n; +} + +int +wxItemContainer::Insert(const wxString& item, int pos, wxClientData *clientData) +{ + int n = DoInsert(item, pos); + if ( n != wxNOT_FOUND ) + SetClientObject(n, clientData); + + return n; +} + // ---------------------------------------------------------------------------- // client data // ---------------------------------------------------------------------------- -void wxControlWithItems::SetClientObject(int n, wxClientData *data) +void wxItemContainer::SetClientObject(int n, wxClientData *data) { - wxASSERT_MSG( m_clientDataItemsType != ClientData_Void, + wxASSERT_MSG( m_clientDataItemsType != wxClientData_Void, wxT("can't have both object and void client data") ); - wxClientData *clientDataOld = DoGetItemClientObject(n); - if ( clientDataOld ) - delete clientDataOld; + // when we call SetClientObject() for the first time, m_clientDataItemsType + // is still wxClientData_None and so calling DoGetItemClientObject() would + // fail (in addition to being useless) - don't do it + if ( m_clientDataItemsType == wxClientData_Object ) + { + wxClientData *clientDataOld = DoGetItemClientObject(n); + if ( clientDataOld ) + delete clientDataOld; + } + else // m_clientDataItemsType == wxClientData_None + { + // now we have object client data + m_clientDataItemsType = wxClientData_Object; + } DoSetItemClientObject(n, data); - m_clientDataItemsType = ClientData_Object; } -wxClientData *wxControlWithItems::GetClientObject(int n) const +wxClientData *wxItemContainer::GetClientObject(int n) const { - wxASSERT_MSG( m_clientDataItemsType == ClientData_Object, + wxASSERT_MSG( m_clientDataItemsType == wxClientData_Object, wxT("this window doesn't have object client data") ); return DoGetItemClientObject(n); } -void wxControlWithItems::SetClientData(int n, void *data) +void wxItemContainer::SetClientData(int n, void *data) { - wxASSERT_MSG( m_clientDataItemsType != ClientData_Object, + wxASSERT_MSG( m_clientDataItemsType != wxClientData_Object, wxT("can't have both object and void client data") ); DoSetItemClientData(n, data); - m_clientDataItemsType = ClientData_Void; + m_clientDataItemsType = wxClientData_Void; } -void *wxControlWithItems::GetClientData(int n) const +void *wxItemContainer::GetClientData(int n) const { - wxASSERT_MSG( m_clientDataItemsType == ClientData_Void, + wxASSERT_MSG( m_clientDataItemsType == wxClientData_Void, wxT("this window doesn't have void client data") ); return DoGetItemClientData(n); } +wxControlWithItems::~wxControlWithItems() +{ + // this destructor is required for Darwin +} + +#endif // wxUSE_CONTROLS