1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxComboBox class
8 // Copyright: (c) AUTHOR
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
13 #pragma implementation "combobox.h"
16 #include "wx/combobox.h"
18 #include "wx/mac/uma.h"
20 #if !USE_SHARED_LIBRARY
21 IMPLEMENT_DYNAMIC_CLASS(wxComboBox
, wxControl
)
24 // right now we don't support editable comboboxes
26 static int nextPopUpMenuId
= 1000 ;
27 MenuHandle
NewUniqueMenu()
29 MenuHandle handle
= NewMenu( nextPopUpMenuId
, "\pMenu" ) ;
34 bool wxComboBox::Create(wxWindow
*parent
, wxWindowID id
,
35 const wxString
& value
,
38 int n
, const wxString choices
[],
40 const wxValidator
& validator
,
48 MacPreControlCreate( parent
, id
, "" , pos
, size
,style
, validator
, name
, &bounds
, title
) ;
50 m_macControl
= ::NewControl( parent
->GetMacRootWindow() , &bounds
, title
, false , 0 , -12345 , 0,
51 kControlPopupButtonProc
, (long) this ) ;
53 m_macPopUpMenuHandle
= NewUniqueMenu() ;
54 SetControlData( m_macControl
, kControlNoPart
, kControlPopupButtonMenuHandleTag
, sizeof( MenuHandle
) , (char*) &m_macPopUpMenuHandle
) ;
55 for ( int i
= 0 ; i
< n
; i
++ )
58 wxMenuItem::MacBuildMenuString( label
, NULL
, NULL
, choices
[i
] ,false);
59 AppendMenu( m_macPopUpMenuHandle
, label
) ;
61 SetControlMinimum( m_macControl
, 0 ) ;
62 SetControlMaximum( m_macControl
, m_noStrings
) ;
63 SetControlValue( m_macControl
, 1 ) ;
65 MacPostControlCreate() ;
70 wxString
wxComboBox::GetValue() const
72 return GetStringSelection() ;
75 void wxComboBox::SetValue(const wxString
& value
)
77 SetStringSelection( value
) ;
80 // Clipboard operations
81 void wxComboBox::Copy()
86 void wxComboBox::Cut()
91 void wxComboBox::Paste()
96 void wxComboBox::SetEditable(bool editable
)
101 void wxComboBox::SetInsertionPoint(long pos
)
106 void wxComboBox::SetInsertionPointEnd()
111 long wxComboBox::GetInsertionPoint() const
117 long wxComboBox::GetLastPosition() const
123 void wxComboBox::Replace(long from
, long to
, const wxString
& value
)
128 void wxComboBox::Remove(long from
, long to
)
133 void wxComboBox::SetSelection(long from
, long to
)
138 void wxComboBox::Append(const wxString
& item
)
141 wxMenuItem::MacBuildMenuString( label
, NULL
, NULL
, item
,false);
142 AppendMenu( m_macPopUpMenuHandle
, label
) ;
144 SetControlMaximum( m_macControl
, m_noStrings
) ;
147 void wxComboBox::Delete(int n
)
149 wxASSERT( n
< m_noStrings
) ;
150 ::DeleteMenuItem( m_macPopUpMenuHandle
, n
+ 1) ;
152 SetControlMaximum( m_macControl
, m_noStrings
) ;
155 void wxComboBox::Clear()
157 for ( int i
= 0 ; i
< m_noStrings
; i
++ )
159 ::DeleteMenuItem( m_macPopUpMenuHandle
, 1 ) ;
162 SetControlMaximum( m_macControl
, m_noStrings
) ;
165 int wxComboBox::GetSelection() const
167 return GetControlValue( m_macControl
) -1 ;
170 void wxComboBox::SetSelection(int n
)
172 SetControlValue( m_macControl
, n
+ 1 ) ;
175 int wxComboBox::FindString(const wxString
& s
) const
177 for( int i
= 0 ; i
< m_noStrings
; i
++ )
179 if ( GetString( i
) == s
)
185 wxString
wxComboBox::GetString(int n
) const
189 ::GetMenuItemText( m_macPopUpMenuHandle
, n
+1 , p_text
) ;
191 p2cstrcpy( c_text
, p_text
) ;
194 strcpy( c_text
, (char *) p_text
) ;
196 return wxString( c_text
);
199 wxString
wxComboBox::GetStringSelection() const
201 int sel
= GetSelection ();
203 return wxString(this->GetString (sel
));
208 bool wxComboBox::SetStringSelection(const wxString
& sel
)
210 int s
= FindString (sel
);
220 void wxComboBox::MacHandleControlClick( ControlHandle control
, SInt16 controlpart
)
222 wxCommandEvent
event(wxEVT_COMMAND_COMBOBOX_SELECTED
, m_windowId
);
223 event
.SetInt(GetSelection());
224 event
.SetEventObject(this);
225 event
.SetString(GetStringSelection());
226 ProcessCommand(event
);