X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/2d67974d248156678a45aded725f5b92c69f502a..ce7208d49d5ce2ca1dc0b3b83f14f1d04f29c4bf:/src/common/ctrlsub.cpp diff --git a/src/common/ctrlsub.cpp b/src/common/ctrlsub.cpp index cf913548e0..c94e8f2ca3 100644 --- a/src/common/ctrlsub.cpp +++ b/src/common/ctrlsub.cpp @@ -1,5 +1,5 @@ /////////////////////////////////////////////////////////////////////////////// -// Name: common/ctrlsub.cpp +// Name: src/common/ctrlsub.cpp // Purpose: wxItemContainer implementation // Author: Vadim Zeitlin // Modified by: @@ -17,10 +17,6 @@ // headers // ---------------------------------------------------------------------------- -#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA) - #pragma implementation "controlwithitems.h" -#endif - // For compilers that support precompilation, includes "wx.h". #include "wx/wxprec.h" @@ -35,11 +31,13 @@ #include "wx/arrstr.h" #endif +IMPLEMENT_ABSTRACT_CLASS(wxControlWithItems, wxControl) + // ============================================================================ -// implementation +// wxItemContainerImmutable implementation // ============================================================================ -wxItemContainer::~wxItemContainer() +wxItemContainerImmutable::~wxItemContainerImmutable() { // this destructor is required for Darwin } @@ -48,23 +46,47 @@ wxItemContainer::~wxItemContainer() // selection // ---------------------------------------------------------------------------- -wxString wxItemContainer::GetStringSelection() const +wxString wxItemContainerImmutable::GetStringSelection() const { wxString s; + int sel = GetSelection(); - if ( sel != -1 ) - s = GetString(sel); + if ( sel != wxNOT_FOUND ) + s = GetString((unsigned int)sel); return s; } -wxArrayString wxItemContainer::GetStrings() const +bool wxItemContainerImmutable::SetStringSelection(const wxString& s) { - wxArrayString result ; - size_t count = GetCount() ; - for ( size_t n = 0 ; n < count ; n++ ) + const int sel = FindString(s); + if ( sel == wxNOT_FOUND ) + return false; + + SetSelection(sel); + + return true; +} + +wxArrayString wxItemContainerImmutable::GetStrings() const +{ + wxArrayString result; + + const unsigned int count = GetCount(); + result.Alloc(count); + for ( unsigned int n = 0; n < count; n++ ) result.Add(GetString(n)); - return result ; + + return result; +} + +// ============================================================================ +// wxItemContainer implementation +// ============================================================================ + +wxItemContainer::~wxItemContainer() +{ + // this destructor is required for Darwin } // ---------------------------------------------------------------------------- @@ -73,14 +95,14 @@ wxArrayString wxItemContainer::GetStrings() const void wxItemContainer::Append(const wxArrayString& strings) { - size_t count = strings.GetCount(); + const 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 wxItemContainer::Insert(const wxString& item, unsigned int pos, void *clientData) { int n = DoInsert(item, pos); if ( n != wxNOT_FOUND ) @@ -89,8 +111,7 @@ int wxItemContainer::Insert(const wxString& item, int pos, void *clientData) return n; } -int -wxItemContainer::Insert(const wxString& item, int pos, wxClientData *clientData) +int wxItemContainer::Insert(const wxString& item, unsigned int pos, wxClientData *clientData) { int n = DoInsert(item, pos); if ( n != wxNOT_FOUND ) @@ -103,7 +124,7 @@ wxItemContainer::Insert(const wxString& item, int pos, wxClientData *clientData) // client data // ---------------------------------------------------------------------------- -void wxItemContainer::SetClientObject(int n, wxClientData *data) +void wxItemContainer::SetClientObject(unsigned int n, wxClientData *data) { wxASSERT_MSG( m_clientDataItemsType != wxClientData_Void, wxT("can't have both object and void client data") ); @@ -126,7 +147,7 @@ void wxItemContainer::SetClientObject(int n, wxClientData *data) DoSetItemClientObject(n, data); } -wxClientData *wxItemContainer::GetClientObject(int n) const +wxClientData *wxItemContainer::GetClientObject(unsigned int n) const { wxASSERT_MSG( m_clientDataItemsType == wxClientData_Object, wxT("this window doesn't have object client data") ); @@ -134,7 +155,7 @@ wxClientData *wxItemContainer::GetClientObject(int n) const return DoGetItemClientObject(n); } -void wxItemContainer::SetClientData(int n, void *data) +void wxItemContainer::SetClientData(unsigned int n, void *data) { wxASSERT_MSG( m_clientDataItemsType != wxClientData_Object, wxT("can't have both object and void client data") ); @@ -143,7 +164,7 @@ void wxItemContainer::SetClientData(int n, void *data) m_clientDataItemsType = wxClientData_Void; } -void *wxItemContainer::GetClientData(int n) const +void *wxItemContainer::GetClientData(unsigned int n) const { wxASSERT_MSG( m_clientDataItemsType == wxClientData_Void, wxT("this window doesn't have void client data") ); @@ -151,18 +172,26 @@ void *wxItemContainer::GetClientData(int n) const return DoGetItemClientData(n); } -wxControlWithItems::~wxControlWithItems() +// ============================================================================ +// wxControlWithItems implementation +// ============================================================================ + +void wxControlWithItems::InitCommandEventWithItems(wxCommandEvent& event, int n) { - // this destructor is required for Darwin -} + InitCommandEvent(event); -#if WXWIN_COMPATIBILITY_2_2 + if ( n != wxNOT_FOUND ) + { + if ( HasClientObjectData() ) + event.SetClientObject(GetClientObject(n)); + else if ( HasClientUntypedData() ) + event.SetClientData(GetClientData(n)); + } +} -int wxItemContainer::Number() const +wxControlWithItems::~wxControlWithItems() { - return GetCount(); + // this destructor is required for Darwin } -#endif // WXWIN_COMPATIBILITY_2_2 - #endif // wxUSE_CONTROLS