1 /////////////////////////////////////////////////////////////////////////////
8 // Copyright: (c) AUTHOR
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
13 #pragma implementation "choice.h"
16 // For compilers that support precompilation, includes "wx.h".
17 #include "wx/choice.h"
18 #include "wx/mac/uma.h"
20 #if !USE_SHARED_LIBRARY
21 IMPLEMENT_DYNAMIC_CLASS(wxChoice
, wxControl
)
24 bool wxChoice::Create(wxWindow
*parent
, wxWindowID id
,
27 int n
, const wxString choices
[],
29 const wxValidator
& validator
,
36 MacPreControlCreate( parent
, id
, "" , pos
, size
,style
, validator
, name
, &bounds
, title
) ;
38 m_macControl
= UMANewControl( parent
->GetMacRootWindow() , &bounds
, title
, true , 0 , -12345 , 0 ,
39 kControlPopupButtonProc
+ kControlPopupFixedWidthVariant
, (long) this ) ;
41 m_macPopUpMenuHandle
= NewMenu( 1 , "\pPopUp Menu" ) ;
42 SetControlData( m_macControl
, kControlNoPart
, kControlPopupButtonMenuHandleTag
, sizeof( MenuHandle
) , (char*) &m_macPopUpMenuHandle
) ;
43 for ( int i
= 0 ; i
< n
; i
++ )
46 wxMenuItem::MacBuildMenuString( label
, NULL
, NULL
, choices
[i
] ,false);
47 AppendMenu( m_macPopUpMenuHandle
, label
) ;
48 m_strings
.Add( choices
[i
] ) ;
50 SetControlMinimum( m_macControl
, 0 ) ;
51 SetControlMaximum( m_macControl
, Number()) ;
53 SetControlValue( m_macControl
, 1 ) ;
55 MacPostControlCreate() ;
60 void wxChoice::Append(const wxString
& item
)
63 wxMenuItem::MacBuildMenuString( label
, NULL
, NULL
, item
,false);
64 AppendMenu( m_macPopUpMenuHandle
, label
) ;
65 m_strings
.Add( item
) ;
66 SetControlMaximum( m_macControl
, Number()) ;
69 void wxChoice::Delete(int n
)
71 ::DeleteMenuItem( m_macPopUpMenuHandle
, n
+ 1) ;
72 m_strings
.Remove( n
) ;
73 SetControlMaximum( m_macControl
, Number()) ;
76 void wxChoice::Clear()
78 for ( int i
= 0 ; i
< Number() ; i
++ )
80 ::DeleteMenuItem( m_macPopUpMenuHandle
, 1 ) ;
83 SetControlMaximum( m_macControl
, Number()) ;
86 int wxChoice::GetSelection() const
88 return GetControlValue( m_macControl
) -1 ;
91 void wxChoice::MacHandleControlClick( ControlHandle control
, SInt16 controlpart
)
93 wxCommandEvent
event(wxEVT_COMMAND_CHOICE_SELECTED
, m_windowId
);
94 event
.SetInt(GetSelection());
95 event
.SetEventObject(this);
96 event
.SetString(GetStringSelection());
97 ProcessCommand(event
);
101 void wxChoice::SetSelection(int n
)
103 SetControlValue( m_macControl
, n
+ 1 ) ;
106 int wxChoice::FindString(const wxString
& s
) const
108 for( int i
= 0 ; i
< Number() ; i
++ )
110 if ( GetString( i
) == s
)
116 wxString
wxChoice::GetString(int n
) const
118 return m_strings
[n
] ;
121 void wxChoice::SetSize(int x
, int y
, int width
, int height
, int sizeFlags
)
123 wxControl::SetSize( x
,y
,width
,height
,sizeFlags
) ;
126 wxString
wxChoice::GetStringSelection () const
128 int sel
= GetSelection ();
130 return wxString(this->GetString (sel
));
135 bool wxChoice::SetStringSelection (const wxString
& s
)
137 int sel
= FindString (s
);
147 void wxChoice::Command(wxCommandEvent
& event
)
149 SetSelection (event
.GetInt());
150 ProcessCommand (event
);