]> git.saurik.com Git - wxWidgets.git/blame - src/mac/choice.cpp
use GetText() instead of GetText(wxString&), made some methods inline
[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 ) ;
e7b596fb 30 // DisposeMenu( m_macPopUpMenuHandle ) ;
5b781a67
SC
31}
32
e9576ca5
SC
33bool wxChoice::Create(wxWindow *parent, wxWindowID id,
34 const wxPoint& pos,
35 const wxSize& size,
03e11df5
GD
36 int n, const wxString choices[],
37 long style,
e9576ca5
SC
38 const wxValidator& validator,
39 const wxString& name)
40{
e9576ca5 41
519cb848
SC
42 Rect bounds ;
43 Str255 title ;
44
45 MacPreControlCreate( parent , id , "" , pos , size ,style, validator , name , &bounds , title ) ;
2f1ae414 46
fdaf613a 47 m_macControl = UMANewControl( parent->GetMacRootWindow() , &bounds , title , false , 0 , -12345 , 0 ,
8208e181 48 kControlPopupButtonProc + kControlPopupFixedWidthVariant , (long) this ) ;
519cb848
SC
49
50 m_macPopUpMenuHandle = NewMenu( 1 , "\pPopUp Menu" ) ;
51 SetControlData( m_macControl , kControlNoPart , kControlPopupButtonMenuHandleTag , sizeof( MenuHandle ) , (char*) &m_macPopUpMenuHandle) ;
b668a735
SC
52 SetControlMinimum( m_macControl , 0 ) ;
53 SetControlMaximum( m_macControl , 0) ;
2f1ae414
SC
54 if ( n > 0 )
55 SetControlValue( m_macControl , 1 ) ;
519cb848
SC
56
57 MacPostControlCreate() ;
58
b668a735
SC
59 for ( int i = 0; i < n; i++ )
60 {
61 Append(choices[i]);
62 }
519cb848 63 return TRUE;
e9576ca5
SC
64}
65
b668a735
SC
66// ----------------------------------------------------------------------------
67// adding/deleting items to/from the list
68// ----------------------------------------------------------------------------
69
2597135a 70int wxChoice::DoAppend(const wxString& item)
e9576ca5 71{
2f1ae414
SC
72 Str255 label;
73 wxMenuItem::MacBuildMenuString( label , NULL , NULL , item ,false);
74 AppendMenu( m_macPopUpMenuHandle , label ) ;
75 m_strings.Add( item ) ;
b668a735
SC
76 m_datas.Add( NULL ) ;
77 int index = m_strings.GetCount() - 1 ;
78 DoSetItemClientData( index , NULL ) ;
79 SetControlMaximum( m_macControl , Number()) ;
80 return index ;
2597135a
SC
81}
82
b668a735 83void wxChoice::Delete(int n)
2597135a 84{
b668a735 85 wxCHECK_RET( n < GetCount(), wxT("invalid item index in wxChoice::Delete") );
e9576ca5 86
b668a735 87 if ( HasClientObjectData() )
2597135a 88 {
b668a735 89 delete GetClientObject(n);
2597135a 90 }
03e11df5 91
519cb848 92 ::DeleteMenuItem( m_macPopUpMenuHandle , n + 1) ;
2f1ae414 93 m_strings.Remove( n ) ;
9dd11f90
SC
94 m_datas.Remove( n ) ;
95 SetControlMaximum( m_macControl , Number()) ;
e9576ca5
SC
96}
97
98void wxChoice::Clear()
99{
b668a735
SC
100 Free();
101
102 for ( int i = 0 ; i < GetCount() ; i++ )
519cb848
SC
103 {
104 ::DeleteMenuItem( m_macPopUpMenuHandle , 1 ) ;
b668a735
SC
105 }
106 m_strings.Empty() ;
107 m_datas.Empty() ;
9dd11f90 108 SetControlMaximum( m_macControl , 0 ) ;
e9576ca5
SC
109}
110
b668a735
SC
111void wxChoice::Free()
112{
113 if ( HasClientObjectData() )
114 {
115 size_t count = GetCount();
116 for ( size_t n = 0; n < count; n++ )
117 {
118 delete GetClientObject(n);
119 }
120 }
121}
122
123// ----------------------------------------------------------------------------
124// selection
125// ----------------------------------------------------------------------------
126
e9576ca5
SC
127int wxChoice::GetSelection() const
128{
519cb848 129 return GetControlValue( m_macControl ) -1 ;
e9576ca5
SC
130}
131
b668a735 132void wxChoice::SetSelection(int n)
519cb848 133{
b668a735 134 SetControlValue( m_macControl , n + 1 ) ;
519cb848
SC
135}
136
b668a735
SC
137// ----------------------------------------------------------------------------
138// string list functions
139// ----------------------------------------------------------------------------
519cb848 140
b668a735 141int wxChoice::GetCount() const
e9576ca5 142{
b668a735 143 return m_strings.GetCount() ;
e9576ca5
SC
144}
145
146int wxChoice::FindString(const wxString& s) const
147{
b668a735 148 for( int i = 0 ; i < GetCount() ; i++ )
519cb848 149 {
b668a735 150 if ( GetString( i ).IsSameAs(s, FALSE) )
519cb848
SC
151 return i ;
152 }
b668a735
SC
153 return wxNOT_FOUND ;
154}
155
156void wxChoice::SetString(int n, const wxString& s)
157{
158 wxFAIL_MSG(wxT("not implemented"));
159
160#if 0 // should do this, but no Insert() so far
161 Delete(n);
162 Insert(n + 1, s);
163#endif
e9576ca5
SC
164}
165
b668a735 166
e9576ca5
SC
167wxString wxChoice::GetString(int n) const
168{
2f1ae414 169 return m_strings[n] ;
e9576ca5
SC
170}
171
b668a735
SC
172// ----------------------------------------------------------------------------
173// client data
174// ----------------------------------------------------------------------------
175
176void wxChoice::DoSetItemClientData( int n, void* clientData )
177{
178 wxCHECK_RET( n >= 0 && n < m_datas.GetCount(),
179 "invalid index in wxChoice::SetClientData" );
180 wxASSERT_MSG( m_datas.GetCount() >= n , "invalid client_data array" ) ;
181
182 if ( m_datas.GetCount() > n )
183 {
184 m_datas[n] = (char*) clientData ;
185 }
186 else
187 {
188 m_datas.Add( (char*) clientData ) ;
189 }
190}
191
192void *wxChoice::DoGetItemClientData(int N) const
193{
194 wxCHECK_MSG( N >= 0 && N < m_datas.GetCount(), NULL,
195 "invalid index in wxChoice::GetClientData" );
196
197 return (void *)m_datas[N];
198}
199
200void wxChoice::DoSetItemClientObject( int n, wxClientData* clientData )
201{
202 DoSetItemClientData(n, clientData);
203}
204
205wxClientData* wxChoice::DoGetItemClientObject( int n ) const
e9576ca5 206{
b668a735 207 return (wxClientData *)DoGetItemClientData(n);
e9576ca5
SC
208}
209
b668a735
SC
210void wxChoice::MacHandleControlClick( ControlHandle control , SInt16 controlpart )
211{
212 wxCommandEvent event(wxEVT_COMMAND_CHOICE_SELECTED, m_windowId );
213 event.SetInt(GetSelection());
214 event.SetEventObject(this);
215 event.SetString(GetStringSelection());
216 ProcessCommand(event);
217}
218/*
219void wxChoice::Command(wxCommandEvent & event)
220{
221 SetSelection (event.GetInt());
222 ProcessCommand (event);
223}
224*/