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