X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/e9576ca53db96b462ed4c0b4bdf47d64c40203e4..adebd2d72c8897f30bd9e673d1e16ef2794d72ab:/src/mac/choice.cpp diff --git a/src/mac/choice.cpp b/src/mac/choice.cpp index a584d5303f..bac3579f34 100644 --- a/src/mac/choice.cpp +++ b/src/mac/choice.cpp @@ -15,11 +15,29 @@ // For compilers that support precompilation, includes "wx.h". #include "wx/choice.h" +#include "wx/menu.h" +#include "wx/mac/uma.h" #if !USE_SHARED_LIBRARY IMPLEMENT_DYNAMIC_CLASS(wxChoice, wxControl) #endif +short nextMenuId = 100 ; // wxMenu takes the lower ids + +wxChoice::~wxChoice() +{ + // DeleteMenu( m_macPopUpMenuId ) ; + DisposeMenu( m_macPopUpMenuHandle ) ; +} + +int wxChoice::GetCount() const { + return m_strings.Count() ; +} + +void wxChoice::SetString( int n , const wxString& s ) { + m_strings[n] = s ; +} + bool wxChoice::Create(wxWindow *parent, wxWindowID id, const wxPoint& pos, const wxSize& size, @@ -28,92 +46,131 @@ bool wxChoice::Create(wxWindow *parent, wxWindowID id, const wxValidator& validator, const wxString& name) { - SetName(name); - SetValidator(validator); - m_noStrings = n; - m_windowStyle = style; - if (parent) parent->AddChild(this); + Rect bounds ; + Str255 title ; + + MacPreControlCreate( parent , id , "" , pos , size ,style, validator , name , &bounds , title ) ; + + m_macPopUpMenuHandle = NewMenu( 1 , "\pPopUp Menu" ) ; + m_macControl = UMANewControl( parent->GetMacRootWindow() , &bounds , title , true , 0 , -12345 , 0 , + kControlPopupButtonProc + kControlPopupFixedWidthVariant , (long) this ) ; + + m_macPopUpMenuHandle = NewMenu( 1 , "\pPopUp Menu" ) ; + SetControlData( m_macControl , kControlNoPart , kControlPopupButtonMenuHandleTag , sizeof( MenuHandle ) , (char*) &m_macPopUpMenuHandle) ; + for ( int i = 0 ; i < n ; i++ ) + { + Str255 label; + wxMenuItem::MacBuildMenuString( label , NULL , NULL , choices[i] ,false); + AppendMenu( m_macPopUpMenuHandle , label ) ; + m_strings.Add( choices[i] ) ; + m_dataArray.Add( NULL ); + } + SetControlMinimum( m_macControl , 0 ) ; + SetControlMaximum( m_macControl , Number()) ; + if ( n > 0 ) + SetControlValue( m_macControl , 1 ) ; + + MacPostControlCreate() ; + + return TRUE; +} - if ( id == -1 ) - m_windowId = (int)NewControlId(); - else - m_windowId = id; +int wxChoice::DoAppend(const wxString& item) +{ + Str255 label; + wxMenuItem::MacBuildMenuString( label , NULL , NULL , item ,false); + AppendMenu( m_macPopUpMenuHandle , label ) ; + m_strings.Add( item ) ; + m_dataArray.Add( NULL ); + return m_strings.Count() ; +} - // TODO: create choice control - return FALSE; +void *wxChoice::DoGetItemClientData(int N) const +{ + return (void *)m_dataArray[N]; } -void wxChoice::Append(const wxString& item) +void wxChoice::DoSetItemClientData( int N, void* Client_data ) { - // TODO - m_noStrings ++; + wxASSERT_MSG( m_dataArray.GetCount() >= N , "invalid client_data array" ) ; + + if ( m_dataArray.GetCount() > N ) + { + m_dataArray[N] = (char*) Client_data ; + } + else + { + m_dataArray.Add( (char*) Client_data ) ; + } } -void wxChoice::Delete(int n) +void wxChoice::DoSetItemClientObject( int n, wxClientData* clientData ) { - // TODO - m_noStrings --; + DoSetItemClientData(n, clientData); } -void wxChoice::Clear() +wxClientData* wxChoice::DoGetItemClientObject( int N ) const { - // TODO - m_noStrings = 0; + return (wxClientData *) DoGetItemClientData( N ) ; } -int wxChoice::GetSelection() const +void wxChoice::Delete(int n) { - // TODO - return 0; + ::DeleteMenuItem( m_macPopUpMenuHandle , n + 1) ; + m_strings.Remove( n ) ; + m_dataArray.Remove( n ) ; + SetControlMaximum( m_macControl , Number()) ; } -void wxChoice::SetSelection(int n) +void wxChoice::Clear() { - // TODO + for ( int i = 0 ; i < Number() ; i++ ) + { + ::DeleteMenuItem( m_macPopUpMenuHandle , 1 ) ; + } + m_strings.Clear() ; + m_dataArray.Empty() ; + SetControlMaximum( m_macControl , Number()) ; } -int wxChoice::FindString(const wxString& s) const +int wxChoice::GetSelection() const { - // TODO - return 0; + return GetControlValue( m_macControl ) -1 ; } -wxString wxChoice::GetString(int n) const +void wxChoice::MacHandleControlClick( ControlHandle control , SInt16 controlpart ) { - // TODO - return wxString(""); + wxCommandEvent event(wxEVT_COMMAND_CHOICE_SELECTED, m_windowId ); + event.SetInt(GetSelection()); + event.SetEventObject(this); + event.SetString(GetStringSelection()); + ProcessCommand(event); } -void wxChoice::SetSize(int x, int y, int width, int height, int sizeFlags) + +void wxChoice::SetSelection(int n) { - // TODO + SetControlValue( m_macControl , n + 1 ) ; } -wxString wxChoice::GetStringSelection () const +int wxChoice::FindString(const wxString& s) const { - int sel = GetSelection (); - if (sel > -1) - return wxString(this->GetString (sel)); - else - return wxString(""); + for( int i = 0 ; i < Number() ; i++ ) + { + if ( GetString( i ) == s ) + return i ; + } + return -1; } -bool wxChoice::SetStringSelection (const wxString& s) +wxString wxChoice::GetString(int n) const { - int sel = FindString (s); - if (sel > -1) - { - SetSelection (sel); - return TRUE; - } - else - return FALSE; + return m_strings[n] ; } -void wxChoice::Command(wxCommandEvent & event) +void wxChoice::DoSetSize(int x, int y, int width, int height, int sizeFlags) { - SetSelection (event.GetInt()); - ProcessCommand (event); + wxControl::SetSize( x,y,width,height,sizeFlags ) ; }