]> git.saurik.com Git - wxWidgets.git/blame - src/osx/combobox_osx.cpp
Added missing wxBitmapComboBox::Insert() implementation
[wxWidgets.git] / src / osx / combobox_osx.cpp
CommitLineData
4ddfa282
SC
1/////////////////////////////////////////////////////////////////////////////
2// Name: src/osx/combobox_osx.cpp
3// Purpose: wxComboBox class using HIView ComboBox
4// Author: Stefan Csomor
5// Modified by:
6// Created: 1998-01-01
b5b208a1 7// RCS-ID: $Id$
4ddfa282
SC
8// Copyright: (c) Stefan Csomor
9// Licence: wxWindows licence
10/////////////////////////////////////////////////////////////////////////////
11
12#include "wx/wxprec.h"
13
c84030e0 14#if wxUSE_COMBOBOX && wxOSX_USE_COCOA
4ddfa282
SC
15
16#include "wx/combobox.h"
f941a30b 17#include "wx/osx/private.h"
4ddfa282
SC
18
19#ifndef WX_PRECOMP
20#endif
21
22// work in progress
23
4ddfa282
SC
24wxComboBox::~wxComboBox()
25{
26}
27
f941a30b
KO
28void wxComboBox::Init()
29{
30}
31
4ddfa282
SC
32bool wxComboBox::Create(wxWindow *parent, wxWindowID id,
33 const wxString& value,
34 const wxPoint& pos,
35 const wxSize& size,
36 const wxArrayString& choices,
37 long style,
38 const wxValidator& validator,
39 const wxString& name)
40{
41 wxCArrayString chs( choices );
42
43 return Create( parent, id, value, pos, size, chs.GetCount(),
44 chs.GetStrings(), style, validator, name );
45}
46
47bool wxComboBox::Create(wxWindow *parent, wxWindowID id,
48 const wxString& value,
49 const wxPoint& pos,
50 const wxSize& size,
51 int n, const wxString choices[],
52 long style,
53 const wxValidator& validator,
54 const wxString& name)
55{
56 m_text = NULL;
57 m_choice = NULL;
58
59 m_macIsUserPane = false;
60
61 if ( !wxControl::Create( parent, id, pos, size, style, validator, name ) )
62 return false;
8e7262fc 63
8e7262fc
VZ
64 wxASSERT_MSG( !(style & wxCB_SORT),
65 "wxCB_SORT not currently supported by wxOSX/Cocoa");
66
f941a30b 67 m_peer = wxWidgetImpl::CreateComboBox( this, parent, id, NULL, pos, size, style, GetExtraStyle() );
4ddfa282
SC
68
69 MacPostControlCreate( pos, size );
70
4ddfa282
SC
71 Append(n, choices);
72
f25cb0af
VZ
73 // Set up the initial value, by default the first item is selected.
74 if ( !value.empty() )
75 SetValue(value);
76 else if (n > 0)
4ddfa282
SC
77 SetSelection( 0 );
78
79 // Needed because it is a wxControlWithItems
80 SetInitialSize( size );
81
82 return true;
83}
84
4ddfa282
SC
85void wxComboBox::DelegateTextChanged( const wxString& value )
86{
87 SetStringSelection( value );
88}
89
4ddfa282
SC
90void wxComboBox::DelegateChoice( const wxString& value )
91{
92 SetStringSelection( value );
93}
94
c84030e0
KO
95int wxComboBox::DoInsertItems(const wxArrayStringsAdapter& items,
96 unsigned int pos,
97 void **clientData, wxClientDataType type)
4ddfa282 98{
c84030e0
KO
99 const unsigned int numItems = items.GetCount();
100 for( unsigned int i = 0; i < numItems; ++i, ++pos )
101 {
102 unsigned int idx;
4ddfa282 103
c84030e0
KO
104 idx = pos;
105 GetComboPeer()->InsertItem( idx, items[i] );
4ddfa282 106
c84030e0
KO
107 if (idx > m_datas.GetCount())
108 m_datas.SetCount(idx);
109 m_datas.Insert( NULL, idx );
110 AssignNewItemClientData(idx, clientData, i, type);
111 }
4ddfa282 112
c84030e0 113 m_peer->SetMaximum( GetCount() );
4ddfa282 114
c84030e0 115 return pos - 1;
4ddfa282
SC
116}
117
c84030e0
KO
118// ----------------------------------------------------------------------------
119// client data
120// ----------------------------------------------------------------------------
121void wxComboBox::DoSetItemClientData(unsigned int n, void* clientData)
4ddfa282 122{
c84030e0 123 m_datas[n] = (char*)clientData ;
4ddfa282
SC
124}
125
c84030e0 126void * wxComboBox::DoGetItemClientData(unsigned int n) const
4ddfa282 127{
c84030e0 128 return (void *)m_datas[n];
4ddfa282
SC
129}
130
8e7262fc 131unsigned int wxComboBox::GetCount() const
f941a30b 132{
c84030e0 133 return GetComboPeer()->GetNumberOfItems();
4ddfa282
SC
134}
135
136void wxComboBox::DoDeleteOneItem(unsigned int n)
137{
c84030e0 138 GetComboPeer()->RemoveItem(n);
4ddfa282
SC
139}
140
141void wxComboBox::DoClear()
142{
c84030e0 143 GetComboPeer()->Clear();
4ddfa282
SC
144}
145
c84030e0
KO
146void wxComboBox::GetSelection(long *from, long *to) const
147{
148 wxTextEntry::GetSelection(from, to);
149}
8e7262fc 150
4ddfa282
SC
151int wxComboBox::GetSelection() const
152{
c84030e0 153 return GetComboPeer()->GetSelectedItem();
4ddfa282
SC
154}
155
c84030e0 156void wxComboBox::SetSelection(int n)
4ddfa282 157{
c84030e0 158 GetComboPeer()->SetSelectedItem(n);
f941a30b 159}
4ddfa282 160
c84030e0 161void wxComboBox::SetSelection(long from, long to)
f941a30b 162{
c84030e0 163 wxTextEntry::SetSelection(from, to);
4ddfa282
SC
164}
165
166int wxComboBox::FindString(const wxString& s, bool bCase) const
167{
ec073e73
KO
168 if (!bCase)
169 {
96dfe757 170 for (unsigned i = 0; i < GetCount(); i++)
ec073e73
KO
171 {
172 if (s.IsSameAs(GetString(i), false))
173 return i;
174 }
175 return wxNOT_FOUND;
176 }
8e7262fc 177
c84030e0 178 return GetComboPeer()->FindString(s);
4ddfa282
SC
179}
180
181wxString wxComboBox::GetString(unsigned int n) const
182{
6f07c007
VZ
183 wxCHECK_MSG( n < GetCount(), wxString(), "Invalid combobox index" );
184
c84030e0 185 return GetComboPeer()->GetStringAtIndex(n);
4ddfa282
SC
186}
187
188wxString wxComboBox::GetStringSelection() const
189{
6f07c007
VZ
190 const int sel = GetSelection();
191 return sel == wxNOT_FOUND ? wxString() : GetString(sel);
4ddfa282
SC
192}
193
194void wxComboBox::SetString(unsigned int n, const wxString& s)
195{
c84030e0
KO
196 Delete(n);
197 Insert(s, n);
198 SetValue(s); // changing the item in the list won't update the display item
f941a30b
KO
199}
200
de5361fa 201void wxComboBox::EnableTextChangedEvents(bool WXUNUSED(enable))
f941a30b 202{
e567904a
VZ
203 // nothing to do here, events are never generated when we change the
204 // control value programmatically anyhow by Cocoa
f941a30b
KO
205}
206
de5361fa 207bool wxComboBox::OSXHandleClicked( double WXUNUSED(timestampsec) )
4ddfa282
SC
208{
209 wxCommandEvent event(wxEVT_COMMAND_COMBOBOX_SELECTED, m_windowId );
210 event.SetInt(GetSelection());
211 event.SetEventObject(this);
212 event.SetString(GetStringSelection());
213 ProcessCommand(event);
214 return true;
215}
216
c84030e0
KO
217wxComboWidgetImpl* wxComboBox::GetComboPeer() const
218{
219 return dynamic_cast<wxComboWidgetImpl*> (m_peer);
220}
221
222#endif // wxUSE_COMBOBOX && wxOSX_USE_COCOA