]> git.saurik.com Git - wxWidgets.git/blame_incremental - src/mac/combobox.cpp
more MSDOS fixes (config file location)
[wxWidgets.git] / src / mac / combobox.cpp
... / ...
CommitLineData
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"
17#include "wx/menu.h"
18#include "wx/mac/uma.h"
19
20#if !USE_SHARED_LIBRARY
21IMPLEMENT_DYNAMIC_CLASS(wxComboBox, wxControl)
22#endif
23
24// right now we don't support editable comboboxes
25
26static int nextPopUpMenuId = 1000 ;
27MenuHandle NewUniqueMenu()
28{
29 MenuHandle handle = NewMenu( nextPopUpMenuId , "\pMenu" ) ;
30 nextPopUpMenuId++ ;
31 return handle ;
32}
33
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{
43 m_noStrings = n;
44
45 Rect bounds ;
46 Str255 title ;
47
48 MacPreControlCreate( parent , id , "" , pos , size ,style, validator , name , &bounds , title ) ;
49
50 m_macControl = ::NewControl( parent->GetMacRootWindow() , &bounds , title , false , 0 , -12345 , 0,
51 kControlPopupButtonProc , (long) this ) ;
52
53 m_macPopUpMenuHandle = NewUniqueMenu() ;
54 SetControlData( m_macControl , kControlNoPart , kControlPopupButtonMenuHandleTag , sizeof( MenuHandle ) , (char*) &m_macPopUpMenuHandle) ;
55 for ( int i = 0 ; i < n ; i++ )
56 {
57 Str255 label;
58 wxMenuItem::MacBuildMenuString( label , NULL , NULL , choices[i] ,false);
59 AppendMenu( m_macPopUpMenuHandle , label ) ;
60 }
61 SetControlMinimum( m_macControl , 0 ) ;
62 SetControlMaximum( m_macControl , m_noStrings) ;
63 SetControlValue( m_macControl , 1 ) ;
64
65 MacPostControlCreate() ;
66
67 return TRUE;
68}
69
70wxString wxComboBox::GetValue() const
71{
72 return GetStringSelection() ;
73}
74
75void wxComboBox::SetValue(const wxString& value)
76{
77 SetStringSelection( value ) ;
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{
140 Str255 label;
141 wxMenuItem::MacBuildMenuString( label , NULL , NULL , item ,false);
142 AppendMenu( m_macPopUpMenuHandle , label ) ;
143 m_noStrings ++;
144 SetControlMaximum( m_macControl , m_noStrings) ;
145}
146
147void wxComboBox::Delete(int n)
148{
149 wxASSERT( n < m_noStrings ) ;
150 ::DeleteMenuItem( m_macPopUpMenuHandle , n + 1) ;
151 m_noStrings --;
152 SetControlMaximum( m_macControl , m_noStrings) ;
153}
154
155void wxComboBox::Clear()
156{
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) ;
163}
164
165int wxComboBox::GetSelection() const
166{
167 return GetControlValue( m_macControl ) -1 ;
168}
169
170void wxComboBox::SetSelection(int n)
171{
172 SetControlValue( m_macControl , n + 1 ) ;
173}
174
175int wxComboBox::FindString(const wxString& s) const
176{
177 for( int i = 0 ; i < m_noStrings ; i++ )
178 {
179 if ( GetString( i ) == s )
180 return i ;
181 }
182 return -1;
183}
184
185wxString wxComboBox::GetString(int n) const
186{
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 );
197}
198
199wxString wxComboBox::GetStringSelection() const
200{
201 int sel = GetSelection ();
202 if (sel > -1)
203 return wxString(this->GetString (sel));
204 else
205 return wxString("");
206}
207
208bool wxComboBox::SetStringSelection(const wxString& sel)
209{
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);
225 event.SetString(GetStringSelection());
226 ProcessCommand(event);
227}
228