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 #if !USE_SHARED_LIBRARY
20 IMPLEMENT_DYNAMIC_CLASS(wxComboBox
, wxControl
)
23 // right now we don't support editable comboboxes
26 bool wxComboBox::Create(wxWindow
*parent
, wxWindowID id
,
27 const wxString
& value
,
30 int n
, const wxString choices
[],
32 const wxValidator
& validator
,
40 MacPreControlCreate( parent
, id
, "" , pos
, size
,style
, validator
, name
, &bounds
, title
) ;
42 m_macControl
= UMANewControl( parent
->GetMacRootWindow() , &bounds
, title
, true , 0 , -12345 , 0,
43 kControlPopupButtonProc
, (long) this ) ;
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
++ )
49 appendmenu( m_macPopUpMenuHandle
, choices
[i
] ) ;
51 SetControlMinimum( m_macControl
, 0 ) ;
52 SetControlMaximum( m_macControl
, m_noStrings
) ;
53 SetControlValue( m_macControl
, 1 ) ;
55 MacPostControlCreate() ;
60 wxString
wxComboBox::GetValue() const
62 return GetStringSelection() ;
65 void wxComboBox::SetValue(const wxString
& value
)
67 SetStringSelection( value
) ;
70 // Clipboard operations
71 void wxComboBox::Copy()
76 void wxComboBox::Cut()
81 void wxComboBox::Paste()
86 void wxComboBox::SetEditable(bool editable
)
91 void wxComboBox::SetInsertionPoint(long pos
)
96 void wxComboBox::SetInsertionPointEnd()
101 long wxComboBox::GetInsertionPoint() const
107 long wxComboBox::GetLastPosition() const
113 void wxComboBox::Replace(long from
, long to
, const wxString
& value
)
118 void wxComboBox::Remove(long from
, long to
)
123 void wxComboBox::SetSelection(long from
, long to
)
128 void wxComboBox::Append(const wxString
& item
)
130 appendmenu( m_macPopUpMenuHandle
, item
) ;
132 SetControlMaximum( m_macControl
, m_noStrings
) ;
135 void wxComboBox::Delete(int n
)
137 wxASSERT( n
< m_noStrings
) ;
138 ::DeleteMenuItem( m_macPopUpMenuHandle
, n
+ 1) ;
140 SetControlMaximum( m_macControl
, m_noStrings
) ;
143 void wxComboBox::Clear()
145 for ( int i
= 0 ; i
< m_noStrings
; i
++ )
147 ::DeleteMenuItem( m_macPopUpMenuHandle
, 1 ) ;
150 SetControlMaximum( m_macControl
, m_noStrings
) ;
153 int wxComboBox::GetSelection() const
155 return GetControlValue( m_macControl
) -1 ;
158 void wxComboBox::SetSelection(int n
)
160 SetControlValue( m_macControl
, n
+ 1 ) ;
163 int wxComboBox::FindString(const wxString
& s
) const
165 for( int i
= 0 ; i
< m_noStrings
; i
++ )
167 if ( GetString( i
) == s
)
173 wxString
wxComboBox::GetString(int n
) const
176 ::GetMenuItemText( m_macPopUpMenuHandle
, n
+1 , text
) ;
178 return wxString( text
);
181 wxString
wxComboBox::GetStringSelection() const
183 int sel
= GetSelection ();
185 return wxString(this->GetString (sel
));
190 bool wxComboBox::SetStringSelection(const wxString
& sel
)
192 int s
= FindString (sel
);
202 void wxComboBox::MacHandleControlClick( ControlHandle control
, SInt16 controlpart
)
204 wxCommandEvent
event(wxEVT_COMMAND_COMBOBOX_SELECTED
, m_windowId
);
205 event
.SetInt(GetSelection());
206 event
.SetEventObject(this);
207 event
.SetString(copystring(GetStringSelection()));
208 ProcessCommand(event
);
209 delete[] event
.GetString();