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