X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/d34cca534cde8acf4406c0276ad6b5f76e7b1ce7..513b47e9b7faf61ed20bb00541c793d163ac307b:/src/mac/carbon/choice.cpp diff --git a/src/mac/carbon/choice.cpp b/src/mac/carbon/choice.cpp index 09edb09274..ff814d8561 100644 --- a/src/mac/carbon/choice.cpp +++ b/src/mac/carbon/choice.cpp @@ -6,7 +6,7 @@ // Created: 1998-01-01 // RCS-ID: $Id$ // Copyright: (c) Stefan Csomor -// Licence: wxWindows licence +// Licence: wxWindows licence ///////////////////////////////////////////////////////////////////////////// #include "wx/wxprec.h" @@ -14,7 +14,12 @@ #if wxUSE_CHOICE #include "wx/choice.h" -#include "wx/menu.h" + +#ifndef WX_PRECOMP + #include "wx/menu.h" + #include "wx/dcclient.h" +#endif + #include "wx/mac/uma.h" extern MenuHandle NewUniqueMenu() ; @@ -26,7 +31,7 @@ wxChoice::~wxChoice() { if ( HasClientObjectData() ) { - size_t i, max = GetCount(); + unsigned int i, max = GetCount(); for ( i = 0; i < max; ++i ) delete GetClientObject( i ); @@ -108,7 +113,7 @@ int wxChoice::DoAppend( const wxString& item ) { #if wxUSE_STL wxArrayString::iterator insertPoint; - size_t index; + unsigned int index; if (GetWindowStyle() & wxCB_SORT) { @@ -123,7 +128,7 @@ int wxChoice::DoAppend( const wxString& item ) m_strings.insert( insertPoint, item ); #else - size_t index = m_strings.Add( item ); + unsigned int index = m_strings.Add( item ); #endif m_datas.Insert( NULL , index ); @@ -134,10 +139,10 @@ int wxChoice::DoAppend( const wxString& item ) return index; } -int wxChoice::DoInsert( const wxString& item, int pos ) +int wxChoice::DoInsert( const wxString& item, unsigned int pos ) { wxCHECK_MSG( !(GetWindowStyle() & wxCB_SORT), -1, wxT("wxChoice::DoInsert: can't insert into sorted list") ); - wxCHECK_MSG( (pos >= 0) && (pos <= GetCount()), -1, wxT("wxChoice::DoInsert: invalid index") ); + wxCHECK_MSG( IsValidInsert(pos), -1, wxT("wxChoice::DoInsert: invalid index") ); if (pos == GetCount()) return DoAppend( item ); @@ -151,9 +156,9 @@ int wxChoice::DoInsert( const wxString& item, int pos ) return pos; } -void wxChoice::Delete( int n ) +void wxChoice::Delete(unsigned int n) { - wxCHECK_RET( n < GetCount(), wxT("wxChoice::Delete: invalid index") ); + wxCHECK_RET( IsValid(n) , wxT("wxChoice::Delete: invalid index") ); if ( HasClientObjectData() ) delete GetClientObject( n ); @@ -167,7 +172,7 @@ void wxChoice::Delete( int n ) void wxChoice::Clear() { FreeData(); - for ( int i = 0 ; i < GetCount() ; i++ ) + for ( unsigned int i = 0 ; i < GetCount() ; i++ ) { ::DeleteMenuItem( MAC_WXHMENU(m_macPopUpMenuHandle) , 1 ) ; } @@ -181,8 +186,8 @@ void wxChoice::FreeData() { if ( HasClientObjectData() ) { - size_t count = GetCount(); - for ( size_t n = 0; n < count; n++ ) + unsigned int count = GetCount(); + for ( unsigned int n = 0; n < count; n++ ) { delete GetClientObject( n ); } @@ -206,20 +211,25 @@ void wxChoice::SetSelection( int n ) // string list functions // ---------------------------------------------------------------------------- -int wxChoice::GetCount() const +unsigned int wxChoice::GetCount() const { return m_strings.GetCount() ; } int wxChoice::FindString( const wxString& s, bool bCase ) const { +#if !wxUSE_STL + // Avoid assert for non-default args passed to sorted array Index + if ( HasFlag(wxCB_SORT) ) + bCase = true; +#endif + return m_strings.Index( s , bCase ) ; } -void wxChoice::SetString( int n, const wxString& s ) +void wxChoice::SetString(unsigned int n, const wxString& s) { - wxCHECK_RET( n >= 0 && (size_t)n < m_strings.GetCount(), - wxT("wxChoice::SetString(): invalid index") ); + wxCHECK_RET( IsValid(n), wxT("wxChoice::SetString(): invalid index") ); m_strings[n] = s ; @@ -227,10 +237,9 @@ void wxChoice::SetString( int n, const wxString& s ) UMASetMenuItemText( MAC_WXHMENU(m_macPopUpMenuHandle) , n + 1 , s , wxFont::GetDefaultEncoding() ) ; } -wxString wxChoice::GetString( int n ) const +wxString wxChoice::GetString(unsigned int n) const { - wxCHECK_MSG( n >= 0 && (size_t)n < m_strings.GetCount(), wxEmptyString, - wxT("wxChoice::GetString(): invalid index") ); + wxCHECK_MSG( IsValid(n), wxEmptyString, wxT("wxChoice::GetString(): invalid index") ); return m_strings[n] ; } @@ -238,28 +247,26 @@ wxString wxChoice::GetString( int n ) const // ---------------------------------------------------------------------------- // client data // ---------------------------------------------------------------------------- -void wxChoice::DoSetItemClientData( int n, void* clientData ) +void wxChoice::DoSetItemClientData(unsigned int n, void* clientData) { - wxCHECK_RET( n >= 0 && (size_t)n < m_datas.GetCount(), - wxT("wxChoice::DoSetItemClientData: invalid index") ); + wxCHECK_RET( IsValid(n), wxT("wxChoice::DoSetItemClientData: invalid index") ); m_datas[n] = (char*)clientData ; } -void * wxChoice::DoGetItemClientData( int n ) const +void * wxChoice::DoGetItemClientData(unsigned int n) const { - wxCHECK_MSG( n >= 0 && (size_t)n < m_datas.GetCount(), NULL, - wxT("wxChoice::DoGetClientData: invalid index") ); + wxCHECK_MSG( IsValid(n), NULL, wxT("wxChoice::DoGetClientData: invalid index") ); return (void *)m_datas[n]; } -void wxChoice::DoSetItemClientObject( int n, wxClientData* clientData ) +void wxChoice::DoSetItemClientObject(unsigned int n, wxClientData* clientData) { - DoSetItemClientData( n, clientData ) ; + DoSetItemClientData(n, clientData); } -wxClientData* wxChoice::DoGetItemClientObject( int n ) const +wxClientData* wxChoice::DoGetItemClientObject(unsigned int n) const { return (wxClientData*)DoGetItemClientData( n ) ; } @@ -294,13 +301,16 @@ wxSize wxChoice::DoGetBestSize() const int wLine; #if TARGET_CARBON - long metric ; + SInt32 metric ; GetThemeMetric( kThemeMetricPopupButtonHeight , &metric ); lbHeight = metric ; #endif { +#if wxMAC_USE_CORE_GRAPHICS + wxClientDC dc(const_cast(this)); +#else wxMacPortStateHelper st( UMAGetWindowPort( (WindowRef) MacGetTopLevelWindowRef() ) ) ; if ( m_font.Ok() ) { @@ -314,12 +324,16 @@ wxSize wxChoice::DoGetBestSize() const ::TextSize( 9 ) ; ::TextFace( 0 ) ; } - +#endif // Find the widest line - for(int i = 0; i < GetCount(); i++) + for(unsigned int i = 0; i < GetCount(); i++) { - wxString str( GetString( i ) ); - + wxString str(GetString(i)); +#if wxMAC_USE_CORE_GRAPHICS + wxCoord width, height ; + dc.GetTextExtent( str , &width, &height); + wLine = width ; +#else #if wxUSE_UNICODE Point bounds = { 0, 0 } ; SInt16 baseline ; @@ -333,17 +347,22 @@ wxSize wxChoice::DoGetBestSize() const wLine = bounds.h ; #else - wLine = ::TextWidth( str.c_str() , 0 , str.Length() ) ; + wLine = ::TextWidth( str.c_str() , 0 , str.length() ) ; +#endif #endif - lbWidth = wxMax( lbWidth, wLine ) ; } // Add room for the popup arrow lbWidth += 2 * lbHeight ; - +#if wxMAC_USE_CORE_GRAPHICS + wxCoord width, height ; + dc.GetTextExtent( wxT("X"), &width, &height); + int cx = width ; +#else // And just a bit more int cx = ::TextWidth( "X" , 0 , 1 ) ; +#endif lbWidth += cx ; }