// 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 ) ;
+}
+
bool wxChoice::Create(wxWindow *parent, wxWindowID id,
const wxPoint& pos,
const wxSize& size,
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] ) ;
+ }
+ 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;
+void wxChoice::Append(const wxString& item)
+{
+ Str255 label;
+ wxMenuItem::MacBuildMenuString( label , NULL , NULL , item ,false);
+ AppendMenu( m_macPopUpMenuHandle , label ) ;
+ m_strings.Add( item ) ;
+ SetControlMaximum( m_macControl , Number()) ;
+}
- // TODO: create choice control
- return FALSE;
+void wxChoice::Append(const wxString &item, void *client_data)
+{
}
-void wxChoice::Append(const wxString& item)
+void *wxChoice::GetClientData(int index) const
{
- // TODO
- m_noStrings ++;
+ return NULL;
}
void wxChoice::Delete(int n)
{
- // TODO
- m_noStrings --;
+ ::DeleteMenuItem( m_macPopUpMenuHandle , n + 1) ;
+ m_strings.Remove( n ) ;
+ SetControlMaximum( m_macControl , Number()) ;
}
void wxChoice::Clear()
{
- // TODO
- m_noStrings = 0;
+ for ( int i = 0 ; i < Number() ; i++ )
+ {
+ ::DeleteMenuItem( m_macPopUpMenuHandle , 1 ) ;
+ }
+ m_strings.Clear() ;
+ SetControlMaximum( m_macControl , Number()) ;
}
int wxChoice::GetSelection() const
{
- // TODO
- return 0;
+ return GetControlValue( m_macControl ) -1 ;
}
+void wxChoice::MacHandleControlClick( ControlHandle control , SInt16 controlpart )
+{
+ wxCommandEvent event(wxEVT_COMMAND_CHOICE_SELECTED, m_windowId );
+ event.SetInt(GetSelection());
+ event.SetEventObject(this);
+ event.SetString(GetStringSelection());
+ ProcessCommand(event);
+}
+
+
void wxChoice::SetSelection(int n)
{
- // TODO
+ SetControlValue( m_macControl , n + 1 ) ;
}
int wxChoice::FindString(const wxString& s) const
{
- // TODO
- return 0;
+ for( int i = 0 ; i < Number() ; i++ )
+ {
+ if ( GetString( i ) == s )
+ return i ;
+ }
+ return -1;
}
wxString wxChoice::GetString(int n) const
{
- // TODO
- return wxString("");
+ return m_strings[n] ;
}
void wxChoice::SetSize(int x, int y, int width, int height, int sizeFlags)
{
- // TODO
+ wxControl::SetSize( x,y,width,height,sizeFlags ) ;
}
wxString wxChoice::GetStringSelection () const