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
,
37 MacPreControlCreate( parent
, id
, "" , pos
, size
,style
, validator
, name
, &bounds
, title
) ;
39 m_macControl
= UMANewControl( parent
->GetMacRootWindow() , &bounds
, title
, true , 0 , -12345 , 0,
40 kControlPopupButtonProc
, (long) this ) ;
42 m_macPopUpMenuHandle
= NewMenu( 1 , "\pPopUp Menu" ) ;
43 SetControlData( m_macControl
, kControlNoPart
, kControlPopupButtonMenuHandleTag
, sizeof( MenuHandle
) , (char*) &m_macPopUpMenuHandle
) ;
44 for ( int i
= 0 ; i
< n
; i
++ )
46 appendmenu( m_macPopUpMenuHandle
, choices
[i
] ) ;
48 SetControlMinimum( m_macControl
, 0 ) ;
49 SetControlMaximum( m_macControl
, m_noStrings
) ;
50 SetControlValue( m_macControl
, 1 ) ;
52 MacPostControlCreate() ;
57 void wxChoice::Append(const wxString
& item
)
59 appendmenu( m_macPopUpMenuHandle
, item
) ;
61 SetControlMaximum( m_macControl
, m_noStrings
) ;
64 void wxChoice::Delete(int n
)
66 wxASSERT( n
< m_noStrings
) ;
67 ::DeleteMenuItem( m_macPopUpMenuHandle
, n
+ 1) ;
69 SetControlMaximum( m_macControl
, m_noStrings
) ;
72 void wxChoice::Clear()
74 for ( int i
= 0 ; i
< m_noStrings
; i
++ )
76 ::DeleteMenuItem( m_macPopUpMenuHandle
, 1 ) ;
79 SetControlMaximum( m_macControl
, m_noStrings
) ;
82 int wxChoice::GetSelection() const
84 return GetControlValue( m_macControl
) -1 ;
87 void wxChoice::MacHandleControlClick( ControlHandle control
, SInt16 controlpart
)
89 wxCommandEvent
event(wxEVT_COMMAND_CHOICE_SELECTED
, m_windowId
);
90 event
.SetInt(GetSelection());
91 event
.SetEventObject(this);
92 event
.SetString(GetStringSelection());
93 ProcessCommand(event
);
97 void wxChoice::SetSelection(int n
)
99 SetControlValue( m_macControl
, n
+ 1 ) ;
102 int wxChoice::FindString(const wxString
& s
) const
104 for( int i
= 0 ; i
< m_noStrings
; i
++ )
106 if ( GetString( i
) == s
)
112 wxString
wxChoice::GetString(int n
) const
115 ::GetMenuItemText( m_macPopUpMenuHandle
, n
+1 , text
) ;
117 return wxString( text
);
120 void wxChoice::SetSize(int x
, int y
, int width
, int height
, int sizeFlags
)
122 wxControl::SetSize( x
,y
,width
,height
,sizeFlags
) ;
125 wxString
wxChoice::GetStringSelection () const
127 int sel
= GetSelection ();
129 return wxString(this->GetString (sel
));
134 bool wxChoice::SetStringSelection (const wxString
& s
)
136 int sel
= FindString (s
);
146 void wxChoice::Command(wxCommandEvent
& event
)
148 SetSelection (event
.GetInt());
149 ProcessCommand (event
);