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 IMPLEMENT_DYNAMIC_CLASS(wxChoice
, wxControl
)
22 bool wxChoice::Create(wxWindow
*parent
, wxWindowID id
,
25 int n
, const wxString choices
[],
27 const wxValidator
& validator
,
35 MacPreControlCreate( parent
, id
, "" , pos
, size
,style
, validator
, name
, &bounds
, title
) ;
37 m_macControl
= UMANewControl( parent
->GetMacRootWindow() , &bounds
, title
, true , 0 , -12345 , 0,
38 kControlPopupButtonProc
, (long) this ) ;
40 m_macPopUpMenuHandle
= NewMenu( 1 , "\pPopUp Menu" ) ;
41 SetControlData( m_macControl
, kControlNoPart
, kControlPopupButtonMenuHandleTag
, sizeof( MenuHandle
) , (char*) &m_macPopUpMenuHandle
) ;
42 for ( int i
= 0 ; i
< n
; i
++ )
44 appendmenu( m_macPopUpMenuHandle
, choices
[i
] ) ;
46 SetControlMinimum( m_macControl
, 0 ) ;
47 SetControlMaximum( m_macControl
, m_noStrings
) ;
48 SetControlValue( m_macControl
, 1 ) ;
50 MacPostControlCreate() ;
55 void wxChoice::Append(const wxString
& item
)
57 appendmenu( m_macPopUpMenuHandle
, item
) ;
59 SetControlMaximum( m_macControl
, m_noStrings
) ;
62 void wxChoice::Delete(int n
)
64 wxASSERT( n
< m_noStrings
) ;
65 ::DeleteMenuItem( m_macPopUpMenuHandle
, n
+ 1) ;
67 SetControlMaximum( m_macControl
, m_noStrings
) ;
70 void wxChoice::Clear()
72 for ( int i
= 0 ; i
< m_noStrings
; i
++ )
74 ::DeleteMenuItem( m_macPopUpMenuHandle
, 1 ) ;
77 SetControlMaximum( m_macControl
, m_noStrings
) ;
80 int wxChoice::GetSelection() const
82 return GetControlValue( m_macControl
) -1 ;
85 void wxChoice::MacHandleControlClick( ControlHandle control
, SInt16 controlpart
)
87 wxCommandEvent
event(wxEVT_COMMAND_CHOICE_SELECTED
, m_windowId
);
88 event
.SetInt(GetSelection());
89 event
.SetEventObject(this);
90 event
.SetString(GetStringSelection());
91 ProcessCommand(event
);
95 void wxChoice::SetSelection(int n
)
97 SetControlValue( m_macControl
, n
+ 1 ) ;
100 int wxChoice::FindString(const wxString
& s
) const
102 for( int i
= 0 ; i
< m_noStrings
; i
++ )
104 if ( GetString( i
) == s
)
110 wxString
wxChoice::GetString(int n
) const
113 ::GetMenuItemText( m_macPopUpMenuHandle
, n
+1 , text
) ;
115 return wxString( text
);
118 void wxChoice::SetSize(int x
, int y
, int width
, int height
, int sizeFlags
)
120 wxControl::SetSize( x
,y
,width
,height
,sizeFlags
) ;
123 wxString
wxChoice::GetStringSelection () const
125 int sel
= GetSelection ();
127 return wxString(this->GetString (sel
));
132 bool wxChoice::SetStringSelection (const wxString
& s
)
134 int sel
= FindString (s
);
144 void wxChoice::Command(wxCommandEvent
& event
)
146 SetSelection (event
.GetInt());
147 ProcessCommand (event
);