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