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