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