]> git.saurik.com Git - wxWidgets.git/blame - src/mac/combobox.cpp
fixed wxTaskBarIcon compilation
[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
0e03d1fa 26static int nextPopUpMenuId = 1000 ;
892e461e
SC
27MenuHandle NewUniqueMenu()
28{
29 MenuHandle handle = NewMenu( nextPopUpMenuId , "\pMenu" ) ;
30 nextPopUpMenuId++ ;
31 return handle ;
32}
519cb848 33
e9576ca5
SC
34bool wxComboBox::Create(wxWindow *parent, wxWindowID id,
35 const wxString& value,
36 const wxPoint& pos,
37 const wxSize& size,
38 int n, const wxString choices[],
39 long style,
40 const wxValidator& validator,
41 const wxString& name)
42{
e9576ca5 43 m_noStrings = n;
e9576ca5 44
519cb848
SC
45 Rect bounds ;
46 Str255 title ;
47
48 MacPreControlCreate( parent , id , "" , pos , size ,style, validator , name , &bounds , title ) ;
49
72055702 50 m_macControl = ::NewControl( parent->GetMacRootWindow() , &bounds , title , false , 0 , -12345 , 0,
519cb848
SC
51 kControlPopupButtonProc , (long) this ) ;
52
892e461e 53 m_macPopUpMenuHandle = NewUniqueMenu() ;
519cb848
SC
54 SetControlData( m_macControl , kControlNoPart , kControlPopupButtonMenuHandleTag , sizeof( MenuHandle ) , (char*) &m_macPopUpMenuHandle) ;
55 for ( int i = 0 ; i < n ; i++ )
56 {
2f1ae414
SC
57 Str255 label;
58 wxMenuItem::MacBuildMenuString( label , NULL , NULL , choices[i] ,false);
59 AppendMenu( m_macPopUpMenuHandle , label ) ;
519cb848
SC
60 }
61 SetControlMinimum( m_macControl , 0 ) ;
62 SetControlMaximum( m_macControl , m_noStrings) ;
63 SetControlValue( m_macControl , 1 ) ;
64
65 MacPostControlCreate() ;
66
67 return TRUE;
e9576ca5
SC
68}
69
70wxString wxComboBox::GetValue() const
71{
519cb848 72 return GetStringSelection() ;
e9576ca5
SC
73}
74
75void wxComboBox::SetValue(const wxString& value)
76{
519cb848 77 SetStringSelection( value ) ;
e9576ca5
SC
78}
79
80// Clipboard operations
81void wxComboBox::Copy()
82{
83 // TODO
84}
85
86void wxComboBox::Cut()
87{
88 // TODO
89}
90
91void wxComboBox::Paste()
92{
93 // TODO
94}
95
96void wxComboBox::SetEditable(bool editable)
97{
98 // TODO
99}
100
101void wxComboBox::SetInsertionPoint(long pos)
102{
103 // TODO
104}
105
106void wxComboBox::SetInsertionPointEnd()
107{
108 // TODO
109}
110
111long wxComboBox::GetInsertionPoint() const
112{
113 // TODO
114 return 0;
115}
116
117long wxComboBox::GetLastPosition() const
118{
119 // TODO
120 return 0;
121}
122
123void wxComboBox::Replace(long from, long to, const wxString& value)
124{
125 // TODO
126}
127
128void wxComboBox::Remove(long from, long to)
129{
130 // TODO
131}
132
133void wxComboBox::SetSelection(long from, long to)
134{
135 // TODO
136}
137
138void wxComboBox::Append(const wxString& item)
139{
2f1ae414
SC
140 Str255 label;
141 wxMenuItem::MacBuildMenuString( label , NULL , NULL , item ,false);
142 AppendMenu( m_macPopUpMenuHandle , label ) ;
519cb848
SC
143 m_noStrings ++;
144 SetControlMaximum( m_macControl , m_noStrings) ;
e9576ca5
SC
145}
146
147void wxComboBox::Delete(int n)
148{
519cb848
SC
149 wxASSERT( n < m_noStrings ) ;
150 ::DeleteMenuItem( m_macPopUpMenuHandle , n + 1) ;
151 m_noStrings --;
152 SetControlMaximum( m_macControl , m_noStrings) ;
e9576ca5
SC
153}
154
155void wxComboBox::Clear()
156{
519cb848
SC
157 for ( int i = 0 ; i < m_noStrings ; i++ )
158 {
159 ::DeleteMenuItem( m_macPopUpMenuHandle , 1 ) ;
160 }
161 m_noStrings = 0;
162 SetControlMaximum( m_macControl , m_noStrings) ;
e9576ca5
SC
163}
164
165int wxComboBox::GetSelection() const
166{
519cb848 167 return GetControlValue( m_macControl ) -1 ;
e9576ca5
SC
168}
169
170void wxComboBox::SetSelection(int n)
171{
519cb848 172 SetControlValue( m_macControl , n + 1 ) ;
e9576ca5
SC
173}
174
175int wxComboBox::FindString(const wxString& s) const
176{
519cb848
SC
177 for( int i = 0 ; i < m_noStrings ; i++ )
178 {
179 if ( GetString( i ) == s )
180 return i ;
181 }
e9576ca5
SC
182 return -1;
183}
184
185wxString wxComboBox::GetString(int n) const
186{
03e11df5
GD
187 Str255 p_text ;
188 char c_text[255];
189 ::GetMenuItemText( m_macPopUpMenuHandle , n+1 , p_text ) ;
190#if TARGET_CARBON
191 p2cstrcpy( c_text, p_text ) ;
192#else
193 p2cstr( p_text ) ;
194 strcpy( c_text, (char *) p_text ) ;
195#endif
196 return wxString( c_text );
e9576ca5
SC
197}
198
199wxString wxComboBox::GetStringSelection() const
200{
519cb848
SC
201 int sel = GetSelection ();
202 if (sel > -1)
203 return wxString(this->GetString (sel));
204 else
205 return wxString("");
e9576ca5
SC
206}
207
208bool wxComboBox::SetStringSelection(const wxString& sel)
209{
519cb848
SC
210 int s = FindString (sel);
211 if (s > -1)
212 {
213 SetSelection (s);
214 return TRUE;
215 }
216 else
217 return FALSE;
218}
219
220void wxComboBox::MacHandleControlClick( ControlHandle control , SInt16 controlpart )
221{
222 wxCommandEvent event(wxEVT_COMMAND_COMBOBOX_SELECTED, m_windowId );
223 event.SetInt(GetSelection());
224 event.SetEventObject(this);
0a67a93b 225 event.SetString(GetStringSelection());
519cb848 226 ProcessCommand(event);
e9576ca5 227}
519cb848 228