]> git.saurik.com Git - wxWidgets.git/blame - src/mac/choice.cpp
corrected an superfluous initfloatingwindows call in carbon
[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
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
5b781a67 47 m_macPopUpMenuHandle = NewMenu( 1 , "\pPopUp Menu" ) ;
8208e181
SC
48 m_macControl = UMANewControl( parent->GetMacRootWindow() , &bounds , title , true , 0 , -12345 , 0 ,
49 kControlPopupButtonProc + kControlPopupFixedWidthVariant , (long) this ) ;
519cb848
SC
50
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++ )
54 {
2f1ae414
SC
55 Str255 label;
56 wxMenuItem::MacBuildMenuString( label , NULL , NULL , choices[i] ,false);
57 AppendMenu( m_macPopUpMenuHandle , label ) ;
58 m_strings.Add( choices[i] ) ;
519cb848
SC
59 }
60 SetControlMinimum( m_macControl , 0 ) ;
2f1ae414
SC
61 SetControlMaximum( m_macControl , Number()) ;
62 if ( n > 0 )
63 SetControlValue( m_macControl , 1 ) ;
519cb848
SC
64
65 MacPostControlCreate() ;
66
67 return TRUE;
e9576ca5
SC
68}
69
70void wxChoice::Append(const wxString& item)
71{
2f1ae414
SC
72 Str255 label;
73 wxMenuItem::MacBuildMenuString( label , NULL , NULL , item ,false);
74 AppendMenu( m_macPopUpMenuHandle , label ) ;
75 m_strings.Add( item ) ;
76 SetControlMaximum( m_macControl , Number()) ;
e9576ca5
SC
77}
78
03e11df5
GD
79void wxChoice::Append(const wxString &item, void *client_data)
80{
81}
82
83void *wxChoice::GetClientData(int index) const
84{
85 return NULL;
86}
87
e9576ca5
SC
88void wxChoice::Delete(int n)
89{
519cb848 90 ::DeleteMenuItem( m_macPopUpMenuHandle , n + 1) ;
2f1ae414
SC
91 m_strings.Remove( n ) ;
92 SetControlMaximum( m_macControl , Number()) ;
e9576ca5
SC
93}
94
95void wxChoice::Clear()
96{
2f1ae414 97 for ( int i = 0 ; i < Number() ; i++ )
519cb848
SC
98 {
99 ::DeleteMenuItem( m_macPopUpMenuHandle , 1 ) ;
100 }
2f1ae414
SC
101 m_strings.Clear() ;
102 SetControlMaximum( m_macControl , Number()) ;
e9576ca5
SC
103}
104
105int wxChoice::GetSelection() const
106{
519cb848 107 return GetControlValue( m_macControl ) -1 ;
e9576ca5
SC
108}
109
519cb848
SC
110void wxChoice::MacHandleControlClick( ControlHandle control , SInt16 controlpart )
111{
112 wxCommandEvent event(wxEVT_COMMAND_CHOICE_SELECTED, m_windowId );
113 event.SetInt(GetSelection());
114 event.SetEventObject(this);
7c551d95 115 event.SetString(GetStringSelection());
519cb848 116 ProcessCommand(event);
519cb848
SC
117}
118
119
e9576ca5
SC
120void wxChoice::SetSelection(int n)
121{
519cb848 122 SetControlValue( m_macControl , n + 1 ) ;
e9576ca5
SC
123}
124
125int wxChoice::FindString(const wxString& s) const
126{
2f1ae414 127 for( int i = 0 ; i < Number() ; i++ )
519cb848
SC
128 {
129 if ( GetString( i ) == s )
130 return i ;
131 }
132 return -1;
e9576ca5
SC
133}
134
135wxString wxChoice::GetString(int n) const
136{
2f1ae414 137 return m_strings[n] ;
e9576ca5
SC
138}
139
140void wxChoice::SetSize(int x, int y, int width, int height, int sizeFlags)
141{
519cb848 142 wxControl::SetSize( x,y,width,height,sizeFlags ) ;
e9576ca5
SC
143}
144
145wxString wxChoice::GetStringSelection () const
146{
147 int sel = GetSelection ();
148 if (sel > -1)
149 return wxString(this->GetString (sel));
150 else
151 return wxString("");
152}
153
154bool wxChoice::SetStringSelection (const wxString& s)
155{
156 int sel = FindString (s);
157 if (sel > -1)
158 {
159 SetSelection (sel);
160 return TRUE;
161 }
162 else
163 return FALSE;
164}
165
166void wxChoice::Command(wxCommandEvent & event)
167{
168 SetSelection (event.GetInt());
169 ProcessCommand (event);
170}
171