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