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 short nextMenuId
= 100 ; // wxMenu takes the lower ids
28 // DeleteMenu( m_macPopUpMenuId ) ;
29 DisposeMenu( m_macPopUpMenuHandle
) ;
32 bool wxChoice::Create(wxWindow
*parent
, wxWindowID id
,
35 int n
, const wxString choices
[],
37 const wxValidator
& validator
,
44 MacPreControlCreate( parent
, id
, "" , pos
, size
,style
, validator
, name
, &bounds
, title
) ;
46 m_macPopUpMenuHandle
= NewMenu( 1 , "\pPopUp Menu" ) ;
47 m_macControl
= UMANewControl( parent
->GetMacRootWindow() , &bounds
, title
, true , 0 , -12345 , 0 ,
48 kControlPopupButtonProc
+ kControlPopupFixedWidthVariant
, (long) this ) ;
50 m_macPopUpMenuHandle
= NewMenu( 1 , "\pPopUp Menu" ) ;
51 SetControlData( m_macControl
, kControlNoPart
, kControlPopupButtonMenuHandleTag
, sizeof( MenuHandle
) , (char*) &m_macPopUpMenuHandle
) ;
52 for ( int i
= 0 ; i
< n
; i
++ )
55 wxMenuItem::MacBuildMenuString( label
, NULL
, NULL
, choices
[i
] ,false);
56 AppendMenu( m_macPopUpMenuHandle
, label
) ;
57 m_strings
.Add( choices
[i
] ) ;
59 SetControlMinimum( m_macControl
, 0 ) ;
60 SetControlMaximum( m_macControl
, Number()) ;
62 SetControlValue( m_macControl
, 1 ) ;
64 MacPostControlCreate() ;
69 void wxChoice::Append(const wxString
& item
)
72 wxMenuItem::MacBuildMenuString( label
, NULL
, NULL
, item
,false);
73 AppendMenu( m_macPopUpMenuHandle
, label
) ;
74 m_strings
.Add( item
) ;
75 SetControlMaximum( m_macControl
, Number()) ;
78 void wxChoice::Delete(int n
)
80 ::DeleteMenuItem( m_macPopUpMenuHandle
, n
+ 1) ;
81 m_strings
.Remove( n
) ;
82 SetControlMaximum( m_macControl
, Number()) ;
85 void wxChoice::Clear()
87 for ( int i
= 0 ; i
< Number() ; i
++ )
89 ::DeleteMenuItem( m_macPopUpMenuHandle
, 1 ) ;
92 SetControlMaximum( m_macControl
, Number()) ;
95 int wxChoice::GetSelection() const
97 return GetControlValue( m_macControl
) -1 ;
100 void wxChoice::MacHandleControlClick( ControlHandle control
, SInt16 controlpart
)
102 wxCommandEvent
event(wxEVT_COMMAND_CHOICE_SELECTED
, m_windowId
);
103 event
.SetInt(GetSelection());
104 event
.SetEventObject(this);
105 event
.SetString(GetStringSelection());
106 ProcessCommand(event
);
110 void wxChoice::SetSelection(int n
)
112 SetControlValue( m_macControl
, n
+ 1 ) ;
115 int wxChoice::FindString(const wxString
& s
) const
117 for( int i
= 0 ; i
< Number() ; i
++ )
119 if ( GetString( i
) == s
)
125 wxString
wxChoice::GetString(int n
) const
127 return m_strings
[n
] ;
130 void wxChoice::SetSize(int x
, int y
, int width
, int height
, int sizeFlags
)
132 wxControl::SetSize( x
,y
,width
,height
,sizeFlags
) ;
135 wxString
wxChoice::GetStringSelection () const
137 int sel
= GetSelection ();
139 return wxString(this->GetString (sel
));
144 bool wxChoice::SetStringSelection (const wxString
& s
)
146 int sel
= FindString (s
);
156 void wxChoice::Command(wxCommandEvent
& event
)
158 SetSelection (event
.GetInt());
159 ProcessCommand (event
);