X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/77ffb5937e89927b621128789401db8921fe580f..3f4a2351e4c677c88c18ea812b609477adee7380:/src/mac/classic/choice.cpp diff --git a/src/mac/classic/choice.cpp b/src/mac/classic/choice.cpp index 62b1685ca2..8371e99ad9 100644 --- a/src/mac/classic/choice.cpp +++ b/src/mac/classic/choice.cpp @@ -1,26 +1,27 @@ ///////////////////////////////////////////////////////////////////////////// -// Name: choice.cpp +// Name: src/mac/classic/choice.cpp // Purpose: wxChoice // Author: Stefan Csomor // Modified by: // Created: 1998-01-01 // RCS-ID: $Id$ // Copyright: (c) Stefan Csomor -// Licence: wxWidgets licence +// Licence: wxWindows licence ///////////////////////////////////////////////////////////////////////////// -#ifdef __GNUG__ -#pragma implementation "choice.h" -#endif +#include "wx/wxprec.h" + +#if wxUSE_CHOICE -#include "wx/defs.h" #include "wx/choice.h" -#include "wx/menu.h" + +#ifndef WX_PRECOMP + #include "wx/menu.h" +#endif + #include "wx/mac/uma.h" -#if !USE_SHARED_LIBRARY IMPLEMENT_DYNAMIC_CLASS(wxChoice, wxControl) -#endif extern MenuHandle NewUniqueMenu() ; @@ -28,7 +29,7 @@ wxChoice::~wxChoice() { if ( HasClientObjectData() ) { - size_t i, max = GetCount(); + unsigned int i, max = GetCount(); for ( i = 0; i < max; ++i ) delete GetClientObject(i); @@ -67,7 +68,7 @@ bool wxChoice::Create(wxWindow *parent, wxWindowID id, Str255 title ; MacPreControlCreate( parent , id , wxEmptyString , pos , size ,style, validator , name , &bounds , title ) ; - m_macControl = ::NewControl( MAC_WXHWND(parent->MacGetRootWindow()) , &bounds , title , false , 0 , -12345 , 0 , + m_macControl = (WXWidget) ::NewControl( MAC_WXHWND(parent->MacGetRootWindow()) , &bounds , title , false , 0 , -12345 , 0 , kControlPopupButtonProc + kControlPopupFixedWidthVariant , (long) this ) ; m_macPopUpMenuHandle = NewUniqueMenu() ; @@ -82,7 +83,7 @@ bool wxChoice::Create(wxWindow *parent, wxWindowID id, { Append(choices[i]); } - return TRUE; + return true; } // ---------------------------------------------------------------------------- @@ -99,10 +100,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("can't insert into sorted list")); - wxCHECK_MSG((pos>=0) && (pos<=GetCount()), -1, wxT("invalid index")); + wxCHECK_MSG(IsValidInsert(pos), -1, wxT("invalid index")); if (pos == GetCount()) return DoAppend(item); @@ -115,9 +116,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("invalid item index in wxChoice::Delete") ); + wxCHECK_RET( IsValid(n), wxT("invalid item index in wxChoice::Delete") ); if ( HasClientObjectData() ) { delete GetClientObject(n); @@ -131,7 +132,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 ) ; } @@ -144,8 +145,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); } @@ -169,22 +170,12 @@ 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) const -{ - for( int i = 0 ; i < GetCount() ; i++ ) - { - if ( GetString( i ).IsSameAs(s, FALSE) ) - return i ; - } - return wxNOT_FOUND ; -} - -void wxChoice::SetString(int n, const wxString& s) +void wxChoice::SetString(unsigned int n, const wxString& s) { wxFAIL_MSG(wxT("wxChoice::SetString() not yet implemented")); #if 0 // should do this, but no Insert() so far @@ -193,9 +184,9 @@ void wxChoice::SetString(int n, const wxString& s) #endif } -wxString wxChoice::GetString(int n) const +wxString wxChoice::GetString(unsigned int n) const { - wxCHECK_MSG( n >= 0 && (size_t)n < m_strings.GetCount(), _T(""), + wxCHECK_MSG( IsValid(n), wxEmptyString, _T("wxChoice::GetString(): invalid index") ); return m_strings[n] ; @@ -204,32 +195,32 @@ 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(), + wxCHECK_RET( n >= 0 && (unsigned int)n < m_datas.GetCount(), wxT("invalid index in wxChoice::SetClientData") ); 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, + wxCHECK_MSG( n >= 0 && (unsigned int)n < m_datas.GetCount(), NULL, wxT("invalid index in wxChoice::GetClientData") ); return (void *)m_datas[n]; } -void wxChoice::DoSetItemClientObject( int n, wxClientData* clientData ) +void wxChoice::DoSetItemClientObject(unsigned int n, wxClientData* clientData) { DoSetItemClientData(n, clientData); } -wxClientData* wxChoice::DoGetItemClientObject( int n ) const +wxClientData* wxChoice::DoGetItemClientObject(unsigned int n) const { return (wxClientData *)DoGetItemClientData(n); } -void wxChoice::MacHandleControlClick( WXWidget control , wxInt16 controlpart , bool WXUNUSED(mouseStillDown)) +void wxChoice::MacHandleControlClick( WXWidget control , wxInt16 controlpart , bool WXUNUSED(mouseStillDown)) { wxCommandEvent event(wxEVT_COMMAND_CHOICE_SELECTED, m_windowId ); int n = GetSelection(); @@ -272,7 +263,7 @@ wxSize wxChoice::DoGetBestSize() const ::TextFace( 0 ) ; } // Find the widest line - for(int i = 0; i < GetCount(); i++) { + for(unsigned int i = 0; i < GetCount(); i++) { wxString str(GetString(i)); #if wxUSE_UNICODE Point bounds={0,0} ; @@ -285,7 +276,7 @@ wxSize wxChoice::DoGetBestSize() const &baseline ); wLine = bounds.h ; #else - wLine = ::TextWidth( str.c_str() , 0 , str.Length() ) ; + wLine = ::TextWidth( str.c_str() , 0 , str.length() ) ; #endif lbWidth = wxMax(lbWidth, wLine); } @@ -298,3 +289,5 @@ wxSize wxChoice::DoGetBestSize() const } return wxSize(lbWidth, lbHeight); } + +#endif // wxUSE_CHOICE