]> git.saurik.com Git - wxWidgets.git/blame - src/mac/combobox.cpp
corrected an superfluous initfloatingwindows call in carbon
[wxWidgets.git] / src / mac / combobox.cpp
CommitLineData
e9576ca5
SC
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"
03e11df5 17#include "wx/menu.h"
519cb848 18#include "wx/mac/uma.h"
e9576ca5 19
2f1ae414 20#if !USE_SHARED_LIBRARY
e9576ca5 21IMPLEMENT_DYNAMIC_CLASS(wxComboBox, wxControl)
2f1ae414 22#endif
e9576ca5 23
519cb848
SC
24// right now we don't support editable comboboxes
25
26
e9576ca5
SC
27bool 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{
e9576ca5 36 m_noStrings = n;
e9576ca5 37
519cb848
SC
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 , true , 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 {
2f1ae414
SC
50 Str255 label;
51 wxMenuItem::MacBuildMenuString( label , NULL , NULL , choices[i] ,false);
52 AppendMenu( m_macPopUpMenuHandle , label ) ;
519cb848
SC
53 }
54 SetControlMinimum( m_macControl , 0 ) ;
55 SetControlMaximum( m_macControl , m_noStrings) ;
56 SetControlValue( m_macControl , 1 ) ;
57
58 MacPostControlCreate() ;
59
60 return TRUE;
e9576ca5
SC
61}
62
63wxString wxComboBox::GetValue() const
64{
519cb848 65 return GetStringSelection() ;
e9576ca5
SC
66}
67
68void wxComboBox::SetValue(const wxString& value)
69{
519cb848 70 SetStringSelection( value ) ;
e9576ca5
SC
71}
72
73// Clipboard operations
74void wxComboBox::Copy()
75{
76 // TODO
77}
78
79void wxComboBox::Cut()
80{
81 // TODO
82}
83
84void wxComboBox::Paste()
85{
86 // TODO
87}
88
89void wxComboBox::SetEditable(bool editable)
90{
91 // TODO
92}
93
94void wxComboBox::SetInsertionPoint(long pos)
95{
96 // TODO
97}
98
99void wxComboBox::SetInsertionPointEnd()
100{
101 // TODO
102}
103
104long wxComboBox::GetInsertionPoint() const
105{
106 // TODO
107 return 0;
108}
109
110long wxComboBox::GetLastPosition() const
111{
112 // TODO
113 return 0;
114}
115
116void wxComboBox::Replace(long from, long to, const wxString& value)
117{
118 // TODO
119}
120
121void wxComboBox::Remove(long from, long to)
122{
123 // TODO
124}
125
126void wxComboBox::SetSelection(long from, long to)
127{
128 // TODO
129}
130
131void wxComboBox::Append(const wxString& item)
132{
2f1ae414
SC
133 Str255 label;
134 wxMenuItem::MacBuildMenuString( label , NULL , NULL , item ,false);
135 AppendMenu( m_macPopUpMenuHandle , label ) ;
519cb848
SC
136 m_noStrings ++;
137 SetControlMaximum( m_macControl , m_noStrings) ;
e9576ca5
SC
138}
139
140void wxComboBox::Delete(int n)
141{
519cb848
SC
142 wxASSERT( n < m_noStrings ) ;
143 ::DeleteMenuItem( m_macPopUpMenuHandle , n + 1) ;
144 m_noStrings --;
145 SetControlMaximum( m_macControl , m_noStrings) ;
e9576ca5
SC
146}
147
148void wxComboBox::Clear()
149{
519cb848
SC
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) ;
e9576ca5
SC
156}
157
158int wxComboBox::GetSelection() const
159{
519cb848 160 return GetControlValue( m_macControl ) -1 ;
e9576ca5
SC
161}
162
163void wxComboBox::SetSelection(int n)
164{
519cb848 165 SetControlValue( m_macControl , n + 1 ) ;
e9576ca5
SC
166}
167
168int wxComboBox::FindString(const wxString& s) const
169{
519cb848
SC
170 for( int i = 0 ; i < m_noStrings ; i++ )
171 {
172 if ( GetString( i ) == s )
173 return i ;
174 }
e9576ca5
SC
175 return -1;
176}
177
178wxString wxComboBox::GetString(int n) const
179{
03e11df5
GD
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 );
e9576ca5
SC
190}
191
192wxString wxComboBox::GetStringSelection() const
193{
519cb848
SC
194 int sel = GetSelection ();
195 if (sel > -1)
196 return wxString(this->GetString (sel));
197 else
198 return wxString("");
e9576ca5
SC
199}
200
201bool wxComboBox::SetStringSelection(const wxString& sel)
202{
519cb848
SC
203 int s = FindString (sel);
204 if (s > -1)
205 {
206 SetSelection (s);
207 return TRUE;
208 }
209 else
210 return FALSE;
211}
212
213void 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(copystring(GetStringSelection()));
219 ProcessCommand(event);
220 delete[] event.GetString();
e9576ca5 221}
519cb848 222