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"
19 #include "wx/mac/uma.h"
21 #if !USE_SHARED_LIBRARY
22 IMPLEMENT_DYNAMIC_CLASS(wxChoice
, wxControl
)
25 short nextMenuId
= 100 ; // wxMenu takes the lower ids
29 // DeleteMenu( m_macPopUpMenuId ) ;
30 DisposeMenu( m_macPopUpMenuHandle
) ;
33 bool wxChoice::Create(wxWindow
*parent
, wxWindowID id
,
36 int n
, const wxString choices
[],
38 const wxValidator
& validator
,
45 MacPreControlCreate( parent
, id
, "" , pos
, size
,style
, validator
, name
, &bounds
, title
) ;
47 m_macPopUpMenuHandle
= NewMenu( 1 , "\pPopUp Menu" ) ;
48 m_macControl
= UMANewControl( parent
->GetMacRootWindow() , &bounds
, title
, true , 0 , -12345 , 0 ,
49 kControlPopupButtonProc
+ kControlPopupFixedWidthVariant
, (long) this ) ;
51 m_macPopUpMenuHandle
= NewMenu( 1 , "\pPopUp Menu" ) ;
52 SetControlData( m_macControl
, kControlNoPart
, kControlPopupButtonMenuHandleTag
, sizeof( MenuHandle
) , (char*) &m_macPopUpMenuHandle
) ;
53 for ( int i
= 0 ; i
< n
; i
++ )
56 wxMenuItem::MacBuildMenuString( label
, NULL
, NULL
, choices
[i
] ,false);
57 AppendMenu( m_macPopUpMenuHandle
, label
) ;
58 m_strings
.Add( choices
[i
] ) ;
60 SetControlMinimum( m_macControl
, 0 ) ;
61 SetControlMaximum( m_macControl
, Number()) ;
63 SetControlValue( m_macControl
, 1 ) ;
65 MacPostControlCreate() ;
70 void wxChoice::Append(const wxString
& item
)
73 wxMenuItem::MacBuildMenuString( label
, NULL
, NULL
, item
,false);
74 AppendMenu( m_macPopUpMenuHandle
, label
) ;
75 m_strings
.Add( item
) ;
76 SetControlMaximum( m_macControl
, Number()) ;
79 void wxChoice::Append(const wxString
&item
, void *client_data
)
83 void *wxChoice::GetClientData(int index
) const
88 void wxChoice::Delete(int n
)
90 ::DeleteMenuItem( m_macPopUpMenuHandle
, n
+ 1) ;
91 m_strings
.Remove( n
) ;
92 SetControlMaximum( m_macControl
, Number()) ;
95 void wxChoice::Clear()
97 for ( int i
= 0 ; i
< Number() ; i
++ )
99 ::DeleteMenuItem( m_macPopUpMenuHandle
, 1 ) ;
102 SetControlMaximum( m_macControl
, Number()) ;
105 int wxChoice::GetSelection() const
107 return GetControlValue( m_macControl
) -1 ;
110 void wxChoice::MacHandleControlClick( ControlHandle control
, SInt16 controlpart
)
112 wxCommandEvent
event(wxEVT_COMMAND_CHOICE_SELECTED
, m_windowId
);
113 event
.SetInt(GetSelection());
114 event
.SetEventObject(this);
115 event
.SetString(GetStringSelection());
116 ProcessCommand(event
);
120 void wxChoice::SetSelection(int n
)
122 SetControlValue( m_macControl
, n
+ 1 ) ;
125 int wxChoice::FindString(const wxString
& s
) const
127 for( int i
= 0 ; i
< Number() ; i
++ )
129 if ( GetString( i
) == s
)
135 wxString
wxChoice::GetString(int n
) const
137 return m_strings
[n
] ;
140 void wxChoice::SetSize(int x
, int y
, int width
, int height
, int sizeFlags
)
142 wxControl::SetSize( x
,y
,width
,height
,sizeFlags
) ;
145 wxString
wxChoice::GetStringSelection () const
147 int sel
= GetSelection ();
149 return wxString(this->GetString (sel
));
154 bool wxChoice::SetStringSelection (const wxString
& s
)
156 int sel
= FindString (s
);
166 void wxChoice::Command(wxCommandEvent
& event
)
168 SetSelection (event
.GetInt());
169 ProcessCommand (event
);