]> git.saurik.com Git - wxWidgets.git/blame - src/mac/carbon/combobox.cpp
Added wxWakeUpIdle() for MSW and empty stubs for Motif, OS2, and Mac
[wxWidgets.git] / src / mac / carbon / 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"
519cb848 17#include "wx/mac/uma.h"
e9576ca5
SC
18
19#if !USE_SHARED_LIBRARY
20IMPLEMENT_DYNAMIC_CLASS(wxComboBox, wxControl)
21#endif
22
519cb848
SC
23// right now we don't support editable comboboxes
24
25
e9576ca5
SC
26bool 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{
e9576ca5 35 m_noStrings = n;
e9576ca5 36
519cb848
SC
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;
e9576ca5
SC
58}
59
60wxString wxComboBox::GetValue() const
61{
519cb848 62 return GetStringSelection() ;
e9576ca5
SC
63}
64
65void wxComboBox::SetValue(const wxString& value)
66{
519cb848 67 SetStringSelection( value ) ;
e9576ca5
SC
68}
69
70// Clipboard operations
71void wxComboBox::Copy()
72{
73 // TODO
74}
75
76void wxComboBox::Cut()
77{
78 // TODO
79}
80
81void wxComboBox::Paste()
82{
83 // TODO
84}
85
86void wxComboBox::SetEditable(bool editable)
87{
88 // TODO
89}
90
91void wxComboBox::SetInsertionPoint(long pos)
92{
93 // TODO
94}
95
96void wxComboBox::SetInsertionPointEnd()
97{
98 // TODO
99}
100
101long wxComboBox::GetInsertionPoint() const
102{
103 // TODO
104 return 0;
105}
106
107long wxComboBox::GetLastPosition() const
108{
109 // TODO
110 return 0;
111}
112
113void wxComboBox::Replace(long from, long to, const wxString& value)
114{
115 // TODO
116}
117
118void wxComboBox::Remove(long from, long to)
119{
120 // TODO
121}
122
123void wxComboBox::SetSelection(long from, long to)
124{
125 // TODO
126}
127
128void wxComboBox::Append(const wxString& item)
129{
519cb848
SC
130 appendmenu( m_macPopUpMenuHandle , item ) ;
131 m_noStrings ++;
132 SetControlMaximum( m_macControl , m_noStrings) ;
e9576ca5
SC
133}
134
135void wxComboBox::Delete(int n)
136{
519cb848
SC
137 wxASSERT( n < m_noStrings ) ;
138 ::DeleteMenuItem( m_macPopUpMenuHandle , n + 1) ;
139 m_noStrings --;
140 SetControlMaximum( m_macControl , m_noStrings) ;
e9576ca5
SC
141}
142
143void wxComboBox::Clear()
144{
519cb848
SC
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) ;
e9576ca5
SC
151}
152
153int wxComboBox::GetSelection() const
154{
519cb848 155 return GetControlValue( m_macControl ) -1 ;
e9576ca5
SC
156}
157
158void wxComboBox::SetSelection(int n)
159{
519cb848 160 SetControlValue( m_macControl , n + 1 ) ;
e9576ca5
SC
161}
162
163int wxComboBox::FindString(const wxString& s) const
164{
519cb848
SC
165 for( int i = 0 ; i < m_noStrings ; i++ )
166 {
167 if ( GetString( i ) == s )
168 return i ;
169 }
e9576ca5
SC
170 return -1;
171}
172
173wxString wxComboBox::GetString(int n) const
174{
519cb848
SC
175 Str255 text ;
176 ::GetMenuItemText( m_macPopUpMenuHandle , n+1 , text ) ;
177 p2cstr( text ) ;
178 return wxString( text );
e9576ca5
SC
179}
180
181wxString wxComboBox::GetStringSelection() const
182{
519cb848
SC
183 int sel = GetSelection ();
184 if (sel > -1)
185 return wxString(this->GetString (sel));
186 else
187 return wxString("");
e9576ca5
SC
188}
189
190bool wxComboBox::SetStringSelection(const wxString& sel)
191{
519cb848
SC
192 int s = FindString (sel);
193 if (s > -1)
194 {
195 SetSelection (s);
196 return TRUE;
197 }
198 else
199 return FALSE;
200}
201
202void 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();
e9576ca5 210}
519cb848 211