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