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 if (style
& wxCB_READONLY
)
67 wxLogWarning("wxCB_READONLY style not supported by OS X Cocoa. Use wxChoice instead.");
69 if (style
& wxCB_SORT
)
70 wxLogWarning("wxCB_SORT style not currently supported by OS X Cocoa.");
72 m_peer
= wxWidgetImpl::CreateComboBox( this, parent
, id
, NULL
, pos
, size
, style
, GetExtraStyle() );
74 MacPostControlCreate( pos
, size
);
78 // Set the first item as being selected
82 // Needed because it is a wxControlWithItems
83 SetInitialSize( size
);
88 void wxComboBox::DelegateTextChanged( const wxString
& value
)
90 SetStringSelection( value
);
93 void wxComboBox::DelegateChoice( const wxString
& value
)
95 SetStringSelection( value
);
98 int wxComboBox::DoInsertItems(const wxArrayStringsAdapter
& items
,
100 void **clientData
, wxClientDataType type
)
102 const unsigned int numItems
= items
.GetCount();
103 for( unsigned int i
= 0; i
< numItems
; ++i
, ++pos
)
108 GetComboPeer()->InsertItem( idx
, items
[i
] );
110 if (idx
> m_datas
.GetCount())
111 m_datas
.SetCount(idx
);
112 m_datas
.Insert( NULL
, idx
);
113 AssignNewItemClientData(idx
, clientData
, i
, type
);
116 m_peer
->SetMaximum( GetCount() );
121 // ----------------------------------------------------------------------------
123 // ----------------------------------------------------------------------------
124 void wxComboBox::DoSetItemClientData(unsigned int n
, void* clientData
)
126 wxCHECK_RET( IsValid(n
), wxT("wxChoice::DoSetItemClientData: invalid index") );
128 m_datas
[n
] = (char*)clientData
;
131 void * wxComboBox::DoGetItemClientData(unsigned int n
) const
133 wxCHECK_MSG( IsValid(n
), NULL
, wxT("wxChoice::DoGetClientData: invalid index") );
135 return (void *)m_datas
[n
];
138 unsigned int wxComboBox::GetCount() const
140 return GetComboPeer()->GetNumberOfItems();
143 void wxComboBox::DoDeleteOneItem(unsigned int n
)
145 GetComboPeer()->RemoveItem(n
);
148 void wxComboBox::DoClear()
150 GetComboPeer()->Clear();
151 SetValue(wxEmptyString
);
154 void wxComboBox::GetSelection(long *from
, long *to
) const
156 wxTextEntry::GetSelection(from
, to
);
159 int wxComboBox::GetSelection() const
161 return GetComboPeer()->GetSelectedItem();
164 void wxComboBox::SetSelection(int n
)
166 GetComboPeer()->SetSelectedItem(n
);
169 void wxComboBox::SetSelection(long from
, long to
)
171 wxTextEntry::SetSelection(from
, to
);
174 int wxComboBox::FindString(const wxString
& s
, bool bCase
) const
177 wxLogWarning("wxComboBox::FindString on Mac doesn't currently support case insensitive search.");
179 return GetComboPeer()->FindString(s
);
182 wxString
wxComboBox::GetString(unsigned int n
) const
184 return GetComboPeer()->GetStringAtIndex(n
);
187 wxString
wxComboBox::GetStringSelection() const
189 return GetString(GetSelection());
192 void wxComboBox::SetString(unsigned int n
, const wxString
& s
)
196 SetValue(s
); // changing the item in the list won't update the display item
199 void wxComboBox::EnableTextChangedEvents(bool enable
)
201 wxFAIL_MSG("Method Not Implemented.");
204 bool wxComboBox::OSXHandleClicked( double timestampsec
)
206 wxCommandEvent
event(wxEVT_COMMAND_COMBOBOX_SELECTED
, m_windowId
);
207 event
.SetInt(GetSelection());
208 event
.SetEventObject(this);
209 event
.SetString(GetStringSelection());
210 ProcessCommand(event
);
214 wxTextWidgetImpl
* wxComboBox::GetTextPeer() const
216 return dynamic_cast<wxTextWidgetImpl
*> (m_peer
);
219 wxComboWidgetImpl
* wxComboBox::GetComboPeer() const
221 return dynamic_cast<wxComboWidgetImpl
*> (m_peer
);
224 #endif // wxUSE_COMBOBOX && wxOSX_USE_COCOA