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 int wxChoice::GetCount() const {
34 return m_strings
.Count() ;
37 void wxChoice::SetString( int n
, const wxString
& s
) {
41 bool wxChoice::Create(wxWindow
*parent
, wxWindowID id
,
44 int n
, const wxString choices
[],
46 const wxValidator
& validator
,
53 MacPreControlCreate( parent
, id
, "" , pos
, size
,style
, validator
, name
, &bounds
, title
) ;
55 m_macPopUpMenuHandle
= NewMenu( 1 , "\pPopUp Menu" ) ;
56 m_macControl
= UMANewControl( parent
->GetMacRootWindow() , &bounds
, title
, true , 0 , -12345 , 0 ,
57 kControlPopupButtonProc
+ kControlPopupFixedWidthVariant
, (long) this ) ;
59 m_macPopUpMenuHandle
= NewMenu( 1 , "\pPopUp Menu" ) ;
60 SetControlData( m_macControl
, kControlNoPart
, kControlPopupButtonMenuHandleTag
, sizeof( MenuHandle
) , (char*) &m_macPopUpMenuHandle
) ;
61 for ( int i
= 0 ; i
< n
; i
++ )
64 wxMenuItem::MacBuildMenuString( label
, NULL
, NULL
, choices
[i
] ,false);
65 AppendMenu( m_macPopUpMenuHandle
, label
) ;
66 m_strings
.Add( choices
[i
] ) ;
67 m_dataArray
.Add( NULL
);
69 SetControlMinimum( m_macControl
, 0 ) ;
70 SetControlMaximum( m_macControl
, Number()) ;
72 SetControlValue( m_macControl
, 1 ) ;
74 MacPostControlCreate() ;
79 int wxChoice::DoAppend(const wxString
& item
)
82 wxMenuItem::MacBuildMenuString( label
, NULL
, NULL
, item
,false);
83 AppendMenu( m_macPopUpMenuHandle
, label
) ;
84 m_strings
.Add( item
) ;
85 m_dataArray
.Add( NULL
);
86 return m_strings
.Count() ;
89 void *wxChoice::DoGetItemClientData(int N
) const
91 return (void *)m_dataArray
[N
];
94 void wxChoice::DoSetItemClientData( int N
, void* Client_data
)
96 wxASSERT_MSG( m_dataArray
.GetCount() >= N
, "invalid client_data array" ) ;
98 if ( m_dataArray
.GetCount() > N
)
100 m_dataArray
[N
] = (char*) Client_data
;
104 m_dataArray
.Add( (char*) Client_data
) ;
108 void wxChoice::DoSetItemClientObject( int n
, wxClientData
* clientData
)
110 DoSetItemClientData(n
, clientData
);
113 wxClientData
* wxChoice::DoGetItemClientObject( int N
) const
115 return (wxClientData
*) DoGetItemClientData( N
) ;
118 void wxChoice::Delete(int n
)
120 ::DeleteMenuItem( m_macPopUpMenuHandle
, n
+ 1) ;
121 m_strings
.Remove( n
) ;
122 m_dataArray
.Remove( n
) ;
123 SetControlMaximum( m_macControl
, Number()) ;
126 void wxChoice::Clear()
128 for ( int i
= 0 ; i
< Number() ; i
++ )
130 ::DeleteMenuItem( m_macPopUpMenuHandle
, 1 ) ;
133 m_dataArray
.Empty() ;
134 SetControlMaximum( m_macControl
, Number()) ;
137 int wxChoice::GetSelection() const
139 return GetControlValue( m_macControl
) -1 ;
142 void wxChoice::MacHandleControlClick( ControlHandle control
, SInt16 controlpart
)
144 wxCommandEvent
event(wxEVT_COMMAND_CHOICE_SELECTED
, m_windowId
);
145 event
.SetInt(GetSelection());
146 event
.SetEventObject(this);
147 event
.SetString(GetStringSelection());
148 ProcessCommand(event
);
152 void wxChoice::SetSelection(int n
)
154 SetControlValue( m_macControl
, n
+ 1 ) ;
157 int wxChoice::FindString(const wxString
& s
) const
159 for( int i
= 0 ; i
< Number() ; i
++ )
161 if ( GetString( i
) == s
)
167 wxString
wxChoice::GetString(int n
) const
169 return m_strings
[n
] ;
172 void wxChoice::DoSetSize(int x
, int y
, int width
, int height
, int sizeFlags
)
174 wxControl::SetSize( x
,y
,width
,height
,sizeFlags
) ;