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
27 bool wxComboBox::Create(wxWindow
*parent
, wxWindowID id
,
28 const wxString
& value
,
31 int n
, const wxString choices
[],
33 const wxValidator
& validator
,
41 MacPreControlCreate( parent
, id
, "" , pos
, size
,style
, validator
, name
, &bounds
, title
) ;
43 m_macControl
= UMANewControl( parent
->GetMacRootWindow() , &bounds
, title
, true , 0 , -12345 , 0,
44 kControlPopupButtonProc
, (long) this ) ;
46 m_macPopUpMenuHandle
= NewMenu( 1 , "\pPopUp Menu" ) ;
47 SetControlData( m_macControl
, kControlNoPart
, kControlPopupButtonMenuHandleTag
, sizeof( MenuHandle
) , (char*) &m_macPopUpMenuHandle
) ;
48 for ( int i
= 0 ; i
< n
; i
++ )
51 wxMenuItem::MacBuildMenuString( label
, NULL
, NULL
, choices
[i
] ,false);
52 AppendMenu( m_macPopUpMenuHandle
, label
) ;
54 SetControlMinimum( m_macControl
, 0 ) ;
55 SetControlMaximum( m_macControl
, m_noStrings
) ;
56 SetControlValue( m_macControl
, 1 ) ;
58 MacPostControlCreate() ;
63 wxString
wxComboBox::GetValue() const
65 return GetStringSelection() ;
68 void wxComboBox::SetValue(const wxString
& value
)
70 SetStringSelection( value
) ;
73 // Clipboard operations
74 void wxComboBox::Copy()
79 void wxComboBox::Cut()
84 void wxComboBox::Paste()
89 void wxComboBox::SetEditable(bool editable
)
94 void wxComboBox::SetInsertionPoint(long pos
)
99 void wxComboBox::SetInsertionPointEnd()
104 long wxComboBox::GetInsertionPoint() const
110 long wxComboBox::GetLastPosition() const
116 void wxComboBox::Replace(long from
, long to
, const wxString
& value
)
121 void wxComboBox::Remove(long from
, long to
)
126 void wxComboBox::SetSelection(long from
, long to
)
131 void wxComboBox::Append(const wxString
& item
)
134 wxMenuItem::MacBuildMenuString( label
, NULL
, NULL
, item
,false);
135 AppendMenu( m_macPopUpMenuHandle
, label
) ;
137 SetControlMaximum( m_macControl
, m_noStrings
) ;
140 void wxComboBox::Delete(int n
)
142 wxASSERT( n
< m_noStrings
) ;
143 ::DeleteMenuItem( m_macPopUpMenuHandle
, n
+ 1) ;
145 SetControlMaximum( m_macControl
, m_noStrings
) ;
148 void wxComboBox::Clear()
150 for ( int i
= 0 ; i
< m_noStrings
; i
++ )
152 ::DeleteMenuItem( m_macPopUpMenuHandle
, 1 ) ;
155 SetControlMaximum( m_macControl
, m_noStrings
) ;
158 int wxComboBox::GetSelection() const
160 return GetControlValue( m_macControl
) -1 ;
163 void wxComboBox::SetSelection(int n
)
165 SetControlValue( m_macControl
, n
+ 1 ) ;
168 int wxComboBox::FindString(const wxString
& s
) const
170 for( int i
= 0 ; i
< m_noStrings
; i
++ )
172 if ( GetString( i
) == s
)
178 wxString
wxComboBox::GetString(int n
) const
182 ::GetMenuItemText( m_macPopUpMenuHandle
, n
+1 , p_text
) ;
184 p2cstrcpy( c_text
, p_text
) ;
187 strcpy( c_text
, (char *) p_text
) ;
189 return wxString( c_text
);
192 wxString
wxComboBox::GetStringSelection() const
194 int sel
= GetSelection ();
196 return wxString(this->GetString (sel
));
201 bool wxComboBox::SetStringSelection(const wxString
& sel
)
203 int s
= FindString (sel
);
213 void wxComboBox::MacHandleControlClick( ControlHandle control
, SInt16 controlpart
)
215 wxCommandEvent
event(wxEVT_COMMAND_COMBOBOX_SELECTED
, m_windowId
);
216 event
.SetInt(GetSelection());
217 event
.SetEventObject(this);
218 event
.SetString(GetStringSelection());
219 ProcessCommand(event
);