1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxComboBox class
8 // Copyright: (c) AUTHOR
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
13 #pragma implementation "combobox.h"
16 #include "wx/combobox.h"
17 #include "wx/mac/uma.h"
19 IMPLEMENT_DYNAMIC_CLASS(wxComboBox
, wxControl
)
21 // right now we don't support editable comboboxes
24 bool wxComboBox::Create(wxWindow
*parent
, wxWindowID id
,
25 const wxString
& value
,
28 int n
, const wxString choices
[],
30 const wxValidator
& validator
,
38 MacPreControlCreate( parent
, id
, "" , pos
, size
,style
, validator
, name
, &bounds
, title
) ;
40 m_macControl
= UMANewControl( parent
->GetMacRootWindow() , &bounds
, title
, true , 0 , -12345 , 0,
41 kControlPopupButtonProc
, (long) this ) ;
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
++ )
47 appendmenu( m_macPopUpMenuHandle
, choices
[i
] ) ;
49 SetControlMinimum( m_macControl
, 0 ) ;
50 SetControlMaximum( m_macControl
, m_noStrings
) ;
51 SetControlValue( m_macControl
, 1 ) ;
53 MacPostControlCreate() ;
58 wxString
wxComboBox::GetValue() const
60 return GetStringSelection() ;
63 void wxComboBox::SetValue(const wxString
& value
)
65 SetStringSelection( value
) ;
68 // Clipboard operations
69 void wxComboBox::Copy()
74 void wxComboBox::Cut()
79 void wxComboBox::Paste()
84 void wxComboBox::SetEditable(bool editable
)
89 void wxComboBox::SetInsertionPoint(long pos
)
94 void wxComboBox::SetInsertionPointEnd()
99 long wxComboBox::GetInsertionPoint() const
105 long wxComboBox::GetLastPosition() const
111 void wxComboBox::Replace(long from
, long to
, const wxString
& value
)
116 void wxComboBox::Remove(long from
, long to
)
121 void wxComboBox::SetSelection(long from
, long to
)
126 void wxComboBox::Append(const wxString
& item
)
128 appendmenu( m_macPopUpMenuHandle
, item
) ;
130 SetControlMaximum( m_macControl
, m_noStrings
) ;
133 void wxComboBox::Delete(int n
)
135 wxASSERT( n
< m_noStrings
) ;
136 ::DeleteMenuItem( m_macPopUpMenuHandle
, n
+ 1) ;
138 SetControlMaximum( m_macControl
, m_noStrings
) ;
141 void wxComboBox::Clear()
143 for ( int i
= 0 ; i
< m_noStrings
; i
++ )
145 ::DeleteMenuItem( m_macPopUpMenuHandle
, 1 ) ;
148 SetControlMaximum( m_macControl
, m_noStrings
) ;
151 int wxComboBox::GetSelection() const
153 return GetControlValue( m_macControl
) -1 ;
156 void wxComboBox::SetSelection(int n
)
158 SetControlValue( m_macControl
, n
+ 1 ) ;
161 int wxComboBox::FindString(const wxString
& s
) const
163 for( int i
= 0 ; i
< m_noStrings
; i
++ )
165 if ( GetString( i
) == s
)
171 wxString
wxComboBox::GetString(int n
) const
174 ::GetMenuItemText( m_macPopUpMenuHandle
, n
+1 , text
) ;
176 return wxString( text
);
179 wxString
wxComboBox::GetStringSelection() const
181 int sel
= GetSelection ();
183 return wxString(this->GetString (sel
));
188 bool wxComboBox::SetStringSelection(const wxString
& sel
)
190 int s
= FindString (sel
);
200 void wxComboBox::MacHandleControlClick( ControlHandle control
, SInt16 controlpart
)
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();