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(copystring(GetStringSelection()));
93 ProcessCommand(event
);
94 delete[] event
.GetString();
98 void wxChoice::SetSelection(int n
)
100 SetControlValue( m_macControl
, n
+ 1 ) ;
103 int wxChoice::FindString(const wxString
& s
) const
105 for( int i
= 0 ; i
< m_noStrings
; i
++ )
107 if ( GetString( i
) == s
)
113 wxString
wxChoice::GetString(int n
) const
116 ::GetMenuItemText( m_macPopUpMenuHandle
, n
+1 , text
) ;
118 return wxString( text
);
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
);