]> git.saurik.com Git - wxWidgets.git/blame - src/mac/choice.cpp
changed choice to properly inherit from wxChoiceBase , added msg compatible calls...
[wxWidgets.git] / src / mac / choice.cpp
CommitLineData
e9576ca5
SC
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"
03e11df5 18#include "wx/menu.h"
519cb848 19#include "wx/mac/uma.h"
e9576ca5 20
2f1ae414 21#if !USE_SHARED_LIBRARY
e9576ca5 22IMPLEMENT_DYNAMIC_CLASS(wxChoice, wxControl)
2f1ae414 23#endif
e9576ca5 24
5b781a67
SC
25short nextMenuId = 100 ; // wxMenu takes the lower ids
26
27wxChoice::~wxChoice()
28{
29 // DeleteMenu( m_macPopUpMenuId ) ;
30 DisposeMenu( m_macPopUpMenuHandle ) ;
31}
32
2597135a
SC
33int wxChoice::GetCount() const {
34 return m_strings.Count() ;
35}
36
37void wxChoice::SetString( int n , const wxString& s ) {
38 m_strings[n] = s ;
39}
40
e9576ca5
SC
41bool wxChoice::Create(wxWindow *parent, wxWindowID id,
42 const wxPoint& pos,
43 const wxSize& size,
03e11df5
GD
44 int n, const wxString choices[],
45 long style,
e9576ca5
SC
46 const wxValidator& validator,
47 const wxString& name)
48{
e9576ca5 49
519cb848
SC
50 Rect bounds ;
51 Str255 title ;
52
53 MacPreControlCreate( parent , id , "" , pos , size ,style, validator , name , &bounds , title ) ;
2f1ae414 54
5b781a67 55 m_macPopUpMenuHandle = NewMenu( 1 , "\pPopUp Menu" ) ;
8208e181
SC
56 m_macControl = UMANewControl( parent->GetMacRootWindow() , &bounds , title , true , 0 , -12345 , 0 ,
57 kControlPopupButtonProc + kControlPopupFixedWidthVariant , (long) this ) ;
519cb848
SC
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 {
2f1ae414
SC
63 Str255 label;
64 wxMenuItem::MacBuildMenuString( label , NULL , NULL , choices[i] ,false);
65 AppendMenu( m_macPopUpMenuHandle , label ) ;
66 m_strings.Add( choices[i] ) ;
2597135a 67 m_dataArray.Add( NULL );
519cb848
SC
68 }
69 SetControlMinimum( m_macControl , 0 ) ;
2f1ae414
SC
70 SetControlMaximum( m_macControl , Number()) ;
71 if ( n > 0 )
72 SetControlValue( m_macControl , 1 ) ;
519cb848
SC
73
74 MacPostControlCreate() ;
75
76 return TRUE;
e9576ca5
SC
77}
78
2597135a 79int wxChoice::DoAppend(const wxString& item)
e9576ca5 80{
2f1ae414
SC
81 Str255 label;
82 wxMenuItem::MacBuildMenuString( label , NULL , NULL , item ,false);
83 AppendMenu( m_macPopUpMenuHandle , label ) ;
84 m_strings.Add( item ) ;
2597135a
SC
85 m_dataArray.Add( NULL );
86 return m_strings.Count() ;
87}
88
89void *wxChoice::DoGetItemClientData(int N) const
90{
91 return (void *)m_dataArray[N];
e9576ca5
SC
92}
93
2597135a 94void wxChoice::DoSetItemClientData( int N, void* Client_data )
03e11df5 95{
2597135a
SC
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 }
03e11df5
GD
106}
107
2597135a 108void wxChoice::DoSetItemClientObject( int n, wxClientData* clientData )
03e11df5 109{
2597135a
SC
110 DoSetItemClientData(n, clientData);
111}
112
113wxClientData* wxChoice::DoGetItemClientObject( int N ) const
114{
115 return (wxClientData *) DoGetItemClientData( N ) ;
03e11df5
GD
116}
117
e9576ca5
SC
118void wxChoice::Delete(int n)
119{
519cb848 120 ::DeleteMenuItem( m_macPopUpMenuHandle , n + 1) ;
2f1ae414 121 m_strings.Remove( n ) ;
2597135a 122 m_dataArray.Remove( n ) ;
2f1ae414 123 SetControlMaximum( m_macControl , Number()) ;
e9576ca5
SC
124}
125
126void wxChoice::Clear()
127{
2f1ae414 128 for ( int i = 0 ; i < Number() ; i++ )
519cb848
SC
129 {
130 ::DeleteMenuItem( m_macPopUpMenuHandle , 1 ) ;
131 }
2f1ae414 132 m_strings.Clear() ;
2597135a 133 m_dataArray.Empty() ;
2f1ae414 134 SetControlMaximum( m_macControl , Number()) ;
e9576ca5
SC
135}
136
137int wxChoice::GetSelection() const
138{
519cb848 139 return GetControlValue( m_macControl ) -1 ;
e9576ca5
SC
140}
141
519cb848
SC
142void wxChoice::MacHandleControlClick( ControlHandle control , SInt16 controlpart )
143{
144 wxCommandEvent event(wxEVT_COMMAND_CHOICE_SELECTED, m_windowId );
145 event.SetInt(GetSelection());
146 event.SetEventObject(this);
7c551d95 147 event.SetString(GetStringSelection());
519cb848 148 ProcessCommand(event);
519cb848
SC
149}
150
151
e9576ca5
SC
152void wxChoice::SetSelection(int n)
153{
519cb848 154 SetControlValue( m_macControl , n + 1 ) ;
e9576ca5
SC
155}
156
157int wxChoice::FindString(const wxString& s) const
158{
2f1ae414 159 for( int i = 0 ; i < Number() ; i++ )
519cb848
SC
160 {
161 if ( GetString( i ) == s )
162 return i ;
163 }
164 return -1;
e9576ca5
SC
165}
166
167wxString wxChoice::GetString(int n) const
168{
2f1ae414 169 return m_strings[n] ;
e9576ca5
SC
170}
171
2597135a 172void wxChoice::DoSetSize(int x, int y, int width, int height, int sizeFlags)
e9576ca5 173{
519cb848 174 wxControl::SetSize( x,y,width,height,sizeFlags ) ;
e9576ca5
SC
175}
176