]> git.saurik.com Git - wxWidgets.git/blob - src/mac/choice.cpp
bac3579f34d1a7d6822065b6f561612cac20b802
[wxWidgets.git] / src / mac / choice.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: choice.cpp
3 // Purpose: wxChoice
4 // Author: AUTHOR
5 // Modified by:
6 // Created: ??/??/98
7 // RCS-ID: $Id$
8 // Copyright: (c) AUTHOR
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 #ifdef __GNUG__
13 #pragma implementation "choice.h"
14 #endif
15
16 // For compilers that support precompilation, includes "wx.h".
17 #include "wx/choice.h"
18 #include "wx/menu.h"
19 #include "wx/mac/uma.h"
20
21 #if !USE_SHARED_LIBRARY
22 IMPLEMENT_DYNAMIC_CLASS(wxChoice, wxControl)
23 #endif
24
25 short nextMenuId = 100 ; // wxMenu takes the lower ids
26
27 wxChoice::~wxChoice()
28 {
29 // DeleteMenu( m_macPopUpMenuId ) ;
30 DisposeMenu( m_macPopUpMenuHandle ) ;
31 }
32
33 int wxChoice::GetCount() const {
34 return m_strings.Count() ;
35 }
36
37 void wxChoice::SetString( int n , const wxString& s ) {
38 m_strings[n] = s ;
39 }
40
41 bool wxChoice::Create(wxWindow *parent, wxWindowID id,
42 const wxPoint& pos,
43 const wxSize& size,
44 int n, const wxString choices[],
45 long style,
46 const wxValidator& validator,
47 const wxString& name)
48 {
49
50 Rect bounds ;
51 Str255 title ;
52
53 MacPreControlCreate( parent , id , "" , pos , size ,style, validator , name , &bounds , title ) ;
54
55 m_macPopUpMenuHandle = NewMenu( 1 , "\pPopUp Menu" ) ;
56 m_macControl = UMANewControl( parent->GetMacRootWindow() , &bounds , title , true , 0 , -12345 , 0 ,
57 kControlPopupButtonProc + kControlPopupFixedWidthVariant , (long) this ) ;
58
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++ )
62 {
63 Str255 label;
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 );
68 }
69 SetControlMinimum( m_macControl , 0 ) ;
70 SetControlMaximum( m_macControl , Number()) ;
71 if ( n > 0 )
72 SetControlValue( m_macControl , 1 ) ;
73
74 MacPostControlCreate() ;
75
76 return TRUE;
77 }
78
79 int wxChoice::DoAppend(const wxString& item)
80 {
81 Str255 label;
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() ;
87 }
88
89 void *wxChoice::DoGetItemClientData(int N) const
90 {
91 return (void *)m_dataArray[N];
92 }
93
94 void wxChoice::DoSetItemClientData( int N, void* Client_data )
95 {
96 wxASSERT_MSG( m_dataArray.GetCount() >= N , "invalid client_data array" ) ;
97
98 if ( m_dataArray.GetCount() > N )
99 {
100 m_dataArray[N] = (char*) Client_data ;
101 }
102 else
103 {
104 m_dataArray.Add( (char*) Client_data ) ;
105 }
106 }
107
108 void wxChoice::DoSetItemClientObject( int n, wxClientData* clientData )
109 {
110 DoSetItemClientData(n, clientData);
111 }
112
113 wxClientData* wxChoice::DoGetItemClientObject( int N ) const
114 {
115 return (wxClientData *) DoGetItemClientData( N ) ;
116 }
117
118 void wxChoice::Delete(int n)
119 {
120 ::DeleteMenuItem( m_macPopUpMenuHandle , n + 1) ;
121 m_strings.Remove( n ) ;
122 m_dataArray.Remove( n ) ;
123 SetControlMaximum( m_macControl , Number()) ;
124 }
125
126 void wxChoice::Clear()
127 {
128 for ( int i = 0 ; i < Number() ; i++ )
129 {
130 ::DeleteMenuItem( m_macPopUpMenuHandle , 1 ) ;
131 }
132 m_strings.Clear() ;
133 m_dataArray.Empty() ;
134 SetControlMaximum( m_macControl , Number()) ;
135 }
136
137 int wxChoice::GetSelection() const
138 {
139 return GetControlValue( m_macControl ) -1 ;
140 }
141
142 void wxChoice::MacHandleControlClick( ControlHandle control , SInt16 controlpart )
143 {
144 wxCommandEvent event(wxEVT_COMMAND_CHOICE_SELECTED, m_windowId );
145 event.SetInt(GetSelection());
146 event.SetEventObject(this);
147 event.SetString(GetStringSelection());
148 ProcessCommand(event);
149 }
150
151
152 void wxChoice::SetSelection(int n)
153 {
154 SetControlValue( m_macControl , n + 1 ) ;
155 }
156
157 int wxChoice::FindString(const wxString& s) const
158 {
159 for( int i = 0 ; i < Number() ; i++ )
160 {
161 if ( GetString( i ) == s )
162 return i ;
163 }
164 return -1;
165 }
166
167 wxString wxChoice::GetString(int n) const
168 {
169 return m_strings[n] ;
170 }
171
172 void wxChoice::DoSetSize(int x, int y, int width, int height, int sizeFlags)
173 {
174 wxControl::SetSize( x,y,width,height,sizeFlags ) ;
175 }
176