]> git.saurik.com Git - wxWidgets.git/blob - src/mac/combobox.cpp
Added wxDbTable::SetOrderByColNums() function
[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/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 Str255 label;
50 wxMenuItem::MacBuildMenuString( label , NULL , NULL , choices[i] ,false);
51 AppendMenu( m_macPopUpMenuHandle , label ) ;
52 }
53 SetControlMinimum( m_macControl , 0 ) ;
54 SetControlMaximum( m_macControl , m_noStrings) ;
55 SetControlValue( m_macControl , 1 ) ;
56
57 MacPostControlCreate() ;
58
59 return TRUE;
60 }
61
62 wxString wxComboBox::GetValue() const
63 {
64 return GetStringSelection() ;
65 }
66
67 void wxComboBox::SetValue(const wxString& value)
68 {
69 SetStringSelection( value ) ;
70 }
71
72 // Clipboard operations
73 void wxComboBox::Copy()
74 {
75 // TODO
76 }
77
78 void wxComboBox::Cut()
79 {
80 // TODO
81 }
82
83 void wxComboBox::Paste()
84 {
85 // TODO
86 }
87
88 void wxComboBox::SetEditable(bool editable)
89 {
90 // TODO
91 }
92
93 void wxComboBox::SetInsertionPoint(long pos)
94 {
95 // TODO
96 }
97
98 void wxComboBox::SetInsertionPointEnd()
99 {
100 // TODO
101 }
102
103 long wxComboBox::GetInsertionPoint() const
104 {
105 // TODO
106 return 0;
107 }
108
109 long wxComboBox::GetLastPosition() const
110 {
111 // TODO
112 return 0;
113 }
114
115 void wxComboBox::Replace(long from, long to, const wxString& value)
116 {
117 // TODO
118 }
119
120 void wxComboBox::Remove(long from, long to)
121 {
122 // TODO
123 }
124
125 void wxComboBox::SetSelection(long from, long to)
126 {
127 // TODO
128 }
129
130 void wxComboBox::Append(const wxString& item)
131 {
132 Str255 label;
133 wxMenuItem::MacBuildMenuString( label , NULL , NULL , item ,false);
134 AppendMenu( m_macPopUpMenuHandle , label ) ;
135 m_noStrings ++;
136 SetControlMaximum( m_macControl , m_noStrings) ;
137 }
138
139 void wxComboBox::Delete(int n)
140 {
141 wxASSERT( n < m_noStrings ) ;
142 ::DeleteMenuItem( m_macPopUpMenuHandle , n + 1) ;
143 m_noStrings --;
144 SetControlMaximum( m_macControl , m_noStrings) ;
145 }
146
147 void wxComboBox::Clear()
148 {
149 for ( int i = 0 ; i < m_noStrings ; i++ )
150 {
151 ::DeleteMenuItem( m_macPopUpMenuHandle , 1 ) ;
152 }
153 m_noStrings = 0;
154 SetControlMaximum( m_macControl , m_noStrings) ;
155 }
156
157 int wxComboBox::GetSelection() const
158 {
159 return GetControlValue( m_macControl ) -1 ;
160 }
161
162 void wxComboBox::SetSelection(int n)
163 {
164 SetControlValue( m_macControl , n + 1 ) ;
165 }
166
167 int wxComboBox::FindString(const wxString& s) const
168 {
169 for( int i = 0 ; i < m_noStrings ; i++ )
170 {
171 if ( GetString( i ) == s )
172 return i ;
173 }
174 return -1;
175 }
176
177 wxString wxComboBox::GetString(int n) const
178 {
179 Str255 text ;
180 ::GetMenuItemText( m_macPopUpMenuHandle , n+1 , text ) ;
181 p2cstr( text ) ;
182 return wxString( text );
183 }
184
185 wxString wxComboBox::GetStringSelection() const
186 {
187 int sel = GetSelection ();
188 if (sel > -1)
189 return wxString(this->GetString (sel));
190 else
191 return wxString("");
192 }
193
194 bool wxComboBox::SetStringSelection(const wxString& sel)
195 {
196 int s = FindString (sel);
197 if (s > -1)
198 {
199 SetSelection (s);
200 return TRUE;
201 }
202 else
203 return FALSE;
204 }
205
206 void wxComboBox::MacHandleControlClick( ControlHandle control , SInt16 controlpart )
207 {
208 wxCommandEvent event(wxEVT_COMMAND_COMBOBOX_SELECTED, m_windowId );
209 event.SetInt(GetSelection());
210 event.SetEventObject(this);
211 event.SetString(copystring(GetStringSelection()));
212 ProcessCommand(event);
213 delete[] event.GetString();
214 }
215