]> git.saurik.com Git - wxWidgets.git/blame_incremental - src/mac/choice.cpp
1. added range checks in wxGridStringTable
[wxWidgets.git] / src / mac / choice.cpp
... / ...
CommitLineData
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"
18#include "wx/mac/uma.h"
19
20IMPLEMENT_DYNAMIC_CLASS(wxChoice, wxControl)
21
22bool wxChoice::Create(wxWindow *parent, wxWindowID id,
23 const wxPoint& pos,
24 const wxSize& size,
25 int n, const wxString choices[],
26 long style,
27 const wxValidator& validator,
28 const wxString& name)
29{
30 m_noStrings = n;
31
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 + kControlPopupFixedWidthVariant , (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;
53}
54
55void wxChoice::Append(const wxString& item)
56{
57 appendmenu( m_macPopUpMenuHandle , item ) ;
58 m_noStrings ++;
59 SetControlMaximum( m_macControl , m_noStrings) ;
60}
61
62void wxChoice::Delete(int n)
63{
64 wxASSERT( n < m_noStrings ) ;
65 ::DeleteMenuItem( m_macPopUpMenuHandle , n + 1) ;
66 m_noStrings --;
67 SetControlMaximum( m_macControl , m_noStrings) ;
68}
69
70void wxChoice::Clear()
71{
72 for ( int i = 0 ; i < m_noStrings ; i++ )
73 {
74 ::DeleteMenuItem( m_macPopUpMenuHandle , 1 ) ;
75 }
76 m_noStrings = 0;
77 SetControlMaximum( m_macControl , m_noStrings) ;
78}
79
80int wxChoice::GetSelection() const
81{
82 return GetControlValue( m_macControl ) -1 ;
83}
84
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);
90 event.SetString(GetStringSelection());
91 ProcessCommand(event);
92}
93
94
95void wxChoice::SetSelection(int n)
96{
97 SetControlValue( m_macControl , n + 1 ) ;
98}
99
100int wxChoice::FindString(const wxString& s) const
101{
102 for( int i = 0 ; i < m_noStrings ; i++ )
103 {
104 if ( GetString( i ) == s )
105 return i ;
106 }
107 return -1;
108}
109
110wxString wxChoice::GetString(int n) const
111{
112 Str255 text ;
113 ::GetMenuItemText( m_macPopUpMenuHandle , n+1 , text ) ;
114 p2cstr( text ) ;
115 return wxString( text );
116}
117
118void wxChoice::SetSize(int x, int y, int width, int height, int sizeFlags)
119{
120 wxControl::SetSize( x,y,width,height,sizeFlags ) ;
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