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
++ )
50 wxMenuItem::MacBuildMenuString( label
, NULL
, NULL
, choices
[i
] ,false);
51 AppendMenu( m_macPopUpMenuHandle
, label
) ;
53 SetControlMinimum( m_macControl
, 0 ) ;
54 SetControlMaximum( m_macControl
, m_noStrings
) ;
55 SetControlValue( m_macControl
, 1 ) ;
57 MacPostControlCreate() ;
62 wxString
wxComboBox::GetValue() const
64 return GetStringSelection() ;
67 void wxComboBox::SetValue(const wxString
& value
)
69 SetStringSelection( value
) ;
72 // Clipboard operations
73 void wxComboBox::Copy()
78 void wxComboBox::Cut()
83 void wxComboBox::Paste()
88 void wxComboBox::SetEditable(bool editable
)
93 void wxComboBox::SetInsertionPoint(long pos
)
98 void wxComboBox::SetInsertionPointEnd()
103 long wxComboBox::GetInsertionPoint() const
109 long wxComboBox::GetLastPosition() const
115 void wxComboBox::Replace(long from
, long to
, const wxString
& value
)
120 void wxComboBox::Remove(long from
, long to
)
125 void wxComboBox::SetSelection(long from
, long to
)
130 void wxComboBox::Append(const wxString
& item
)
133 wxMenuItem::MacBuildMenuString( label
, NULL
, NULL
, item
,false);
134 AppendMenu( m_macPopUpMenuHandle
, label
) ;
136 SetControlMaximum( m_macControl
, m_noStrings
) ;
139 void wxComboBox::Delete(int n
)
141 wxASSERT( n
< m_noStrings
) ;
142 ::DeleteMenuItem( m_macPopUpMenuHandle
, n
+ 1) ;
144 SetControlMaximum( m_macControl
, m_noStrings
) ;
147 void wxComboBox::Clear()
149 for ( int i
= 0 ; i
< m_noStrings
; i
++ )
151 ::DeleteMenuItem( m_macPopUpMenuHandle
, 1 ) ;
154 SetControlMaximum( m_macControl
, m_noStrings
) ;
157 int wxComboBox::GetSelection() const
159 return GetControlValue( m_macControl
) -1 ;
162 void wxComboBox::SetSelection(int n
)
164 SetControlValue( m_macControl
, n
+ 1 ) ;
167 int wxComboBox::FindString(const wxString
& s
) const
169 for( int i
= 0 ; i
< m_noStrings
; i
++ )
171 if ( GetString( i
) == s
)
177 wxString
wxComboBox::GetString(int n
) const
180 ::GetMenuItemText( m_macPopUpMenuHandle
, n
+1 , text
) ;
182 return wxString( text
);
185 wxString
wxComboBox::GetStringSelection() const
187 int sel
= GetSelection ();
189 return wxString(this->GetString (sel
));
194 bool wxComboBox::SetStringSelection(const wxString
& sel
)
196 int s
= FindString (sel
);
206 void wxComboBox::MacHandleControlClick( ControlHandle control
, SInt16 controlpart
)
208 wxCommandEvent
event(wxEVT_COMMAND_COMBOBOX_SELECTED
, m_windowId
);
209 event
.SetInt(GetSelection());
210 event
.SetEventObject(this);
211 event
.SetString(copystring(GetStringSelection()));
212 ProcessCommand(event
);
213 delete[] event
.GetString();