]> git.saurik.com Git - wxWidgets.git/blob - src/mac/combobox.cpp
added alignment style to wxStaticText handler
[wxWidgets.git] / src / mac / combobox.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: combobox.cpp
3 // Purpose: wxComboBox class
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 "combobox.h"
14 #endif
15
16 #include "wx/combobox.h"
17 #include "wx/menu.h"
18 #include "wx/mac/uma.h"
19
20 #if !USE_SHARED_LIBRARY
21 IMPLEMENT_DYNAMIC_CLASS(wxComboBox, wxControl)
22 #endif
23
24 // right now we don't support editable comboboxes
25
26
27 bool wxComboBox::Create(wxWindow *parent, wxWindowID id,
28 const wxString& value,
29 const wxPoint& pos,
30 const wxSize& size,
31 int n, const wxString choices[],
32 long style,
33 const wxValidator& validator,
34 const wxString& name)
35 {
36 m_noStrings = n;
37
38 Rect bounds ;
39 Str255 title ;
40
41 MacPreControlCreate( parent , id , "" , pos , size ,style, validator , name , &bounds , title ) ;
42
43 m_macControl = UMANewControl( parent->GetMacRootWindow() , &bounds , title , false , 0 , -12345 , 0,
44 kControlPopupButtonProc , (long) this ) ;
45
46 m_macPopUpMenuHandle = NewMenu( 1 , "\pPopUp Menu" ) ;
47 SetControlData( m_macControl , kControlNoPart , kControlPopupButtonMenuHandleTag , sizeof( MenuHandle ) , (char*) &m_macPopUpMenuHandle) ;
48 for ( int i = 0 ; i < n ; i++ )
49 {
50 Str255 label;
51 wxMenuItem::MacBuildMenuString( label , NULL , NULL , choices[i] ,false);
52 AppendMenu( m_macPopUpMenuHandle , label ) ;
53 }
54 SetControlMinimum( m_macControl , 0 ) ;
55 SetControlMaximum( m_macControl , m_noStrings) ;
56 SetControlValue( m_macControl , 1 ) ;
57
58 MacPostControlCreate() ;
59
60 return TRUE;
61 }
62
63 wxString wxComboBox::GetValue() const
64 {
65 return GetStringSelection() ;
66 }
67
68 void wxComboBox::SetValue(const wxString& value)
69 {
70 SetStringSelection( value ) ;
71 }
72
73 // Clipboard operations
74 void wxComboBox::Copy()
75 {
76 // TODO
77 }
78
79 void wxComboBox::Cut()
80 {
81 // TODO
82 }
83
84 void wxComboBox::Paste()
85 {
86 // TODO
87 }
88
89 void wxComboBox::SetEditable(bool editable)
90 {
91 // TODO
92 }
93
94 void wxComboBox::SetInsertionPoint(long pos)
95 {
96 // TODO
97 }
98
99 void wxComboBox::SetInsertionPointEnd()
100 {
101 // TODO
102 }
103
104 long wxComboBox::GetInsertionPoint() const
105 {
106 // TODO
107 return 0;
108 }
109
110 long wxComboBox::GetLastPosition() const
111 {
112 // TODO
113 return 0;
114 }
115
116 void wxComboBox::Replace(long from, long to, const wxString& value)
117 {
118 // TODO
119 }
120
121 void wxComboBox::Remove(long from, long to)
122 {
123 // TODO
124 }
125
126 void wxComboBox::SetSelection(long from, long to)
127 {
128 // TODO
129 }
130
131 void wxComboBox::Append(const wxString& item)
132 {
133 Str255 label;
134 wxMenuItem::MacBuildMenuString( label , NULL , NULL , item ,false);
135 AppendMenu( m_macPopUpMenuHandle , label ) ;
136 m_noStrings ++;
137 SetControlMaximum( m_macControl , m_noStrings) ;
138 }
139
140 void wxComboBox::Delete(int n)
141 {
142 wxASSERT( n < m_noStrings ) ;
143 ::DeleteMenuItem( m_macPopUpMenuHandle , n + 1) ;
144 m_noStrings --;
145 SetControlMaximum( m_macControl , m_noStrings) ;
146 }
147
148 void wxComboBox::Clear()
149 {
150 for ( int i = 0 ; i < m_noStrings ; i++ )
151 {
152 ::DeleteMenuItem( m_macPopUpMenuHandle , 1 ) ;
153 }
154 m_noStrings = 0;
155 SetControlMaximum( m_macControl , m_noStrings) ;
156 }
157
158 int wxComboBox::GetSelection() const
159 {
160 return GetControlValue( m_macControl ) -1 ;
161 }
162
163 void wxComboBox::SetSelection(int n)
164 {
165 SetControlValue( m_macControl , n + 1 ) ;
166 }
167
168 int wxComboBox::FindString(const wxString& s) const
169 {
170 for( int i = 0 ; i < m_noStrings ; i++ )
171 {
172 if ( GetString( i ) == s )
173 return i ;
174 }
175 return -1;
176 }
177
178 wxString wxComboBox::GetString(int n) const
179 {
180 Str255 p_text ;
181 char c_text[255];
182 ::GetMenuItemText( m_macPopUpMenuHandle , n+1 , p_text ) ;
183 #if TARGET_CARBON
184 p2cstrcpy( c_text, p_text ) ;
185 #else
186 p2cstr( p_text ) ;
187 strcpy( c_text, (char *) p_text ) ;
188 #endif
189 return wxString( c_text );
190 }
191
192 wxString wxComboBox::GetStringSelection() const
193 {
194 int sel = GetSelection ();
195 if (sel > -1)
196 return wxString(this->GetString (sel));
197 else
198 return wxString("");
199 }
200
201 bool wxComboBox::SetStringSelection(const wxString& sel)
202 {
203 int s = FindString (sel);
204 if (s > -1)
205 {
206 SetSelection (s);
207 return TRUE;
208 }
209 else
210 return FALSE;
211 }
212
213 void wxComboBox::MacHandleControlClick( ControlHandle control , SInt16 controlpart )
214 {
215 wxCommandEvent event(wxEVT_COMMAND_COMBOBOX_SELECTED, m_windowId );
216 event.SetInt(GetSelection());
217 event.SetEventObject(this);
218 event.SetString(GetStringSelection());
219 ProcessCommand(event);
220 }
221