]> git.saurik.com Git - wxWidgets.git/blame - src/mac/choice.cpp
Added wxChoice::GetCount() and Select()
[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"
519cb848 18#include "wx/mac/uma.h"
e9576ca5 19
2f1ae414 20#if !USE_SHARED_LIBRARY
e9576ca5 21IMPLEMENT_DYNAMIC_CLASS(wxChoice, wxControl)
2f1ae414 22#endif
e9576ca5
SC
23
24bool wxChoice::Create(wxWindow *parent, wxWindowID id,
25 const wxPoint& pos,
26 const wxSize& size,
519cb848
SC
27 int n, const wxString choices[],
28 long style,
e9576ca5
SC
29 const wxValidator& validator,
30 const wxString& name)
31{
e9576ca5 32
519cb848
SC
33 Rect bounds ;
34 Str255 title ;
35
36 MacPreControlCreate( parent , id , "" , pos , size ,style, validator , name , &bounds , title ) ;
2f1ae414 37
8208e181
SC
38 m_macControl = UMANewControl( parent->GetMacRootWindow() , &bounds , title , true , 0 , -12345 , 0 ,
39 kControlPopupButtonProc + kControlPopupFixedWidthVariant , (long) this ) ;
519cb848
SC
40
41 m_macPopUpMenuHandle = NewMenu( 1 , "\pPopUp Menu" ) ;
42 SetControlData( m_macControl , kControlNoPart , kControlPopupButtonMenuHandleTag , sizeof( MenuHandle ) , (char*) &m_macPopUpMenuHandle) ;
43 for ( int i = 0 ; i < n ; i++ )
44 {
2f1ae414
SC
45 Str255 label;
46 wxMenuItem::MacBuildMenuString( label , NULL , NULL , choices[i] ,false);
47 AppendMenu( m_macPopUpMenuHandle , label ) ;
48 m_strings.Add( choices[i] ) ;
519cb848
SC
49 }
50 SetControlMinimum( m_macControl , 0 ) ;
2f1ae414
SC
51 SetControlMaximum( m_macControl , Number()) ;
52 if ( n > 0 )
53 SetControlValue( m_macControl , 1 ) ;
519cb848
SC
54
55 MacPostControlCreate() ;
56
57 return TRUE;
e9576ca5
SC
58}
59
60void wxChoice::Append(const wxString& item)
61{
2f1ae414
SC
62 Str255 label;
63 wxMenuItem::MacBuildMenuString( label , NULL , NULL , item ,false);
64 AppendMenu( m_macPopUpMenuHandle , label ) ;
65 m_strings.Add( item ) ;
66 SetControlMaximum( m_macControl , Number()) ;
e9576ca5
SC
67}
68
69void wxChoice::Delete(int n)
70{
519cb848 71 ::DeleteMenuItem( m_macPopUpMenuHandle , n + 1) ;
2f1ae414
SC
72 m_strings.Remove( n ) ;
73 SetControlMaximum( m_macControl , Number()) ;
e9576ca5
SC
74}
75
76void wxChoice::Clear()
77{
2f1ae414 78 for ( int i = 0 ; i < Number() ; i++ )
519cb848
SC
79 {
80 ::DeleteMenuItem( m_macPopUpMenuHandle , 1 ) ;
81 }
2f1ae414
SC
82 m_strings.Clear() ;
83 SetControlMaximum( m_macControl , Number()) ;
e9576ca5
SC
84}
85
86int wxChoice::GetSelection() const
87{
519cb848 88 return GetControlValue( m_macControl ) -1 ;
e9576ca5
SC
89}
90
519cb848
SC
91void wxChoice::MacHandleControlClick( ControlHandle control , SInt16 controlpart )
92{
93 wxCommandEvent event(wxEVT_COMMAND_CHOICE_SELECTED, m_windowId );
94 event.SetInt(GetSelection());
95 event.SetEventObject(this);
7c551d95 96 event.SetString(GetStringSelection());
519cb848 97 ProcessCommand(event);
519cb848
SC
98}
99
100
e9576ca5
SC
101void wxChoice::SetSelection(int n)
102{
519cb848 103 SetControlValue( m_macControl , n + 1 ) ;
e9576ca5
SC
104}
105
106int wxChoice::FindString(const wxString& s) const
107{
2f1ae414 108 for( int i = 0 ; i < Number() ; i++ )
519cb848
SC
109 {
110 if ( GetString( i ) == s )
111 return i ;
112 }
113 return -1;
e9576ca5
SC
114}
115
116wxString wxChoice::GetString(int n) const
117{
2f1ae414 118 return m_strings[n] ;
e9576ca5
SC
119}
120
121void wxChoice::SetSize(int x, int y, int width, int height, int sizeFlags)
122{
519cb848 123 wxControl::SetSize( x,y,width,height,sizeFlags ) ;
e9576ca5
SC
124}
125
126wxString wxChoice::GetStringSelection () const
127{
128 int sel = GetSelection ();
129 if (sel > -1)
130 return wxString(this->GetString (sel));
131 else
132 return wxString("");
133}
134
135bool wxChoice::SetStringSelection (const wxString& s)
136{
137 int sel = FindString (s);
138 if (sel > -1)
139 {
140 SetSelection (sel);
141 return TRUE;
142 }
143 else
144 return FALSE;
145}
146
147void wxChoice::Command(wxCommandEvent & event)
148{
149 SetSelection (event.GetInt());
150 ProcessCommand (event);
151}
152