1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/osx/combobox_osx.cpp
3 // Purpose: wxComboBox class using HIView ComboBox
4 // Author: Stefan Csomor
7 // RCS-ID: $Id: combobox_osx.cpp 58318 2009-01-23 08:36:16Z RR $
8 // Copyright: (c) Stefan Csomor
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 #include "wx/wxprec.h"
14 #if wxUSE_COMBOBOX && wxOSX_USE_COCOA
16 #include "wx/combobox.h"
17 #include "wx/osx/private.h"
24 IMPLEMENT_DYNAMIC_CLASS(wxComboBox
, wxControl
)
26 wxComboBox::~wxComboBox()
30 void wxComboBox::Init()
34 bool wxComboBox::Create(wxWindow
*parent
, wxWindowID id
,
35 const wxString
& value
,
38 const wxArrayString
& choices
,
40 const wxValidator
& validator
,
43 wxCArrayString
chs( choices
);
45 return Create( parent
, id
, value
, pos
, size
, chs
.GetCount(),
46 chs
.GetStrings(), style
, validator
, name
);
49 bool wxComboBox::Create(wxWindow
*parent
, wxWindowID id
,
50 const wxString
& value
,
53 int n
, const wxString choices
[],
55 const wxValidator
& validator
,
61 m_macIsUserPane
= false;
63 if ( !wxControl::Create( parent
, id
, pos
, size
, style
, validator
, name
) )
66 wxASSERT_MSG( !(style
& wxCB_SORT
),
67 "wxCB_SORT not currently supported by wxOSX/Cocoa");
69 m_peer
= wxWidgetImpl::CreateComboBox( this, parent
, id
, NULL
, pos
, size
, style
, GetExtraStyle() );
71 MacPostControlCreate( pos
, size
);
75 // Set the first item as being selected
79 // Needed because it is a wxControlWithItems
80 SetInitialSize( size
);
85 void wxComboBox::DelegateTextChanged( const wxString
& value
)
87 SetStringSelection( value
);
90 void wxComboBox::DelegateChoice( const wxString
& value
)
92 SetStringSelection( value
);
95 int wxComboBox::DoInsertItems(const wxArrayStringsAdapter
& items
,
97 void **clientData
, wxClientDataType type
)
99 const unsigned int numItems
= items
.GetCount();
100 for( unsigned int i
= 0; i
< numItems
; ++i
, ++pos
)
105 GetComboPeer()->InsertItem( idx
, items
[i
] );
107 if (idx
> m_datas
.GetCount())
108 m_datas
.SetCount(idx
);
109 m_datas
.Insert( NULL
, idx
);
110 AssignNewItemClientData(idx
, clientData
, i
, type
);
113 m_peer
->SetMaximum( GetCount() );
118 // ----------------------------------------------------------------------------
120 // ----------------------------------------------------------------------------
121 void wxComboBox::DoSetItemClientData(unsigned int n
, void* clientData
)
123 wxCHECK_RET( IsValid(n
), "invalid index" );
125 m_datas
[n
] = (char*)clientData
;
128 void * wxComboBox::DoGetItemClientData(unsigned int n
) const
130 wxCHECK_MSG( IsValid(n
), NULL
, "invalid index" );
132 return (void *)m_datas
[n
];
135 unsigned int wxComboBox::GetCount() const
137 return GetComboPeer()->GetNumberOfItems();
140 void wxComboBox::DoDeleteOneItem(unsigned int n
)
142 GetComboPeer()->RemoveItem(n
);
145 void wxComboBox::DoClear()
147 GetComboPeer()->Clear();
148 SetValue(wxEmptyString
);
151 void wxComboBox::GetSelection(long *from
, long *to
) const
153 wxTextEntry::GetSelection(from
, to
);
156 int wxComboBox::GetSelection() const
158 return GetComboPeer()->GetSelectedItem();
161 void wxComboBox::SetSelection(int n
)
163 GetComboPeer()->SetSelectedItem(n
);
166 void wxComboBox::SetSelection(long from
, long to
)
168 wxTextEntry::SetSelection(from
, to
);
171 int wxComboBox::FindString(const wxString
& s
, bool bCase
) const
175 for (int i
= 0; i
< GetCount(); i
++)
177 if (s
.IsSameAs(GetString(i
), false))
183 return GetComboPeer()->FindString(s
);
186 wxString
wxComboBox::GetString(unsigned int n
) const
188 return GetComboPeer()->GetStringAtIndex(n
);
191 wxString
wxComboBox::GetStringSelection() const
193 return GetString(GetSelection());
196 void wxComboBox::SetString(unsigned int n
, const wxString
& s
)
200 SetValue(s
); // changing the item in the list won't update the display item
203 void wxComboBox::EnableTextChangedEvents(bool enable
)
205 wxFAIL_MSG("Method Not Implemented.");
208 bool wxComboBox::OSXHandleClicked( double timestampsec
)
210 wxCommandEvent
event(wxEVT_COMMAND_COMBOBOX_SELECTED
, m_windowId
);
211 event
.SetInt(GetSelection());
212 event
.SetEventObject(this);
213 event
.SetString(GetStringSelection());
214 ProcessCommand(event
);
218 wxTextWidgetImpl
* wxComboBox::GetTextPeer() const
220 return dynamic_cast<wxTextWidgetImpl
*> (m_peer
);
223 wxComboWidgetImpl
* wxComboBox::GetComboPeer() const
225 return dynamic_cast<wxComboWidgetImpl
*> (m_peer
);
228 #endif // wxUSE_COMBOBOX && wxOSX_USE_COCOA