]>
Commit | Line | Data |
---|---|---|
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 | |
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 | ///////////////////////////////////////////////////////////////////////////// | |
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 | ||
24 | IMPLEMENT_DYNAMIC_CLASS(wxComboBox, wxControl) | |
25 | ||
26 | wxComboBox::~wxComboBox() | |
27 | { | |
28 | } | |
29 | ||
f941a30b KO |
30 | void wxComboBox::Init() |
31 | { | |
32 | } | |
33 | ||
4ddfa282 SC |
34 | bool wxComboBox::Create(wxWindow *parent, wxWindowID id, |
35 | const wxString& value, | |
36 | const wxPoint& pos, | |
37 | const wxSize& size, | |
38 | const wxArrayString& choices, | |
39 | long style, | |
40 | const wxValidator& validator, | |
41 | const wxString& name) | |
42 | { | |
43 | wxCArrayString chs( choices ); | |
44 | ||
45 | return Create( parent, id, value, pos, size, chs.GetCount(), | |
46 | chs.GetStrings(), style, validator, name ); | |
47 | } | |
48 | ||
49 | bool wxComboBox::Create(wxWindow *parent, wxWindowID id, | |
50 | const wxString& value, | |
51 | const wxPoint& pos, | |
52 | const wxSize& size, | |
53 | int n, const wxString choices[], | |
54 | long style, | |
55 | const wxValidator& validator, | |
56 | const wxString& name) | |
57 | { | |
58 | m_text = NULL; | |
59 | m_choice = NULL; | |
60 | ||
61 | m_macIsUserPane = false; | |
62 | ||
63 | if ( !wxControl::Create( parent, id, pos, size, style, validator, name ) ) | |
64 | return false; | |
65 | ||
c84030e0 KO |
66 | if (style & wxCB_READONLY) |
67 | wxLogWarning("wxCB_READONLY style not supported by OS X Cocoa. Use wxChoice instead."); | |
68 | ||
69 | if (style & wxCB_SORT) | |
70 | wxLogWarning("wxCB_SORT style not currently supported by OS X Cocoa."); | |
71 | ||
f941a30b | 72 | m_peer = wxWidgetImpl::CreateComboBox( this, parent, id, NULL, pos, size, style, GetExtraStyle() ); |
4ddfa282 SC |
73 | |
74 | MacPostControlCreate( pos, size ); | |
75 | ||
4ddfa282 SC |
76 | Append(n, choices); |
77 | ||
78 | // Set the first item as being selected | |
79 | if (n > 0) | |
80 | SetSelection( 0 ); | |
81 | ||
82 | // Needed because it is a wxControlWithItems | |
83 | SetInitialSize( size ); | |
84 | ||
85 | return true; | |
86 | } | |
87 | ||
4ddfa282 SC |
88 | void wxComboBox::DelegateTextChanged( const wxString& value ) |
89 | { | |
90 | SetStringSelection( value ); | |
91 | } | |
92 | ||
4ddfa282 SC |
93 | void wxComboBox::DelegateChoice( const wxString& value ) |
94 | { | |
95 | SetStringSelection( value ); | |
96 | } | |
97 | ||
c84030e0 KO |
98 | int wxComboBox::DoInsertItems(const wxArrayStringsAdapter& items, |
99 | unsigned int pos, | |
100 | void **clientData, wxClientDataType type) | |
4ddfa282 | 101 | { |
c84030e0 KO |
102 | const unsigned int numItems = items.GetCount(); |
103 | for( unsigned int i = 0; i < numItems; ++i, ++pos ) | |
104 | { | |
105 | unsigned int idx; | |
4ddfa282 | 106 | |
c84030e0 KO |
107 | idx = pos; |
108 | GetComboPeer()->InsertItem( idx, items[i] ); | |
4ddfa282 | 109 | |
c84030e0 KO |
110 | if (idx > m_datas.GetCount()) |
111 | m_datas.SetCount(idx); | |
112 | m_datas.Insert( NULL, idx ); | |
113 | AssignNewItemClientData(idx, clientData, i, type); | |
114 | } | |
4ddfa282 | 115 | |
c84030e0 | 116 | m_peer->SetMaximum( GetCount() ); |
4ddfa282 | 117 | |
c84030e0 | 118 | return pos - 1; |
4ddfa282 SC |
119 | } |
120 | ||
c84030e0 KO |
121 | // ---------------------------------------------------------------------------- |
122 | // client data | |
123 | // ---------------------------------------------------------------------------- | |
124 | void wxComboBox::DoSetItemClientData(unsigned int n, void* clientData) | |
4ddfa282 | 125 | { |
c84030e0 | 126 | wxCHECK_RET( IsValid(n), wxT("wxChoice::DoSetItemClientData: invalid index") ); |
4ddfa282 | 127 | |
c84030e0 | 128 | m_datas[n] = (char*)clientData ; |
4ddfa282 SC |
129 | } |
130 | ||
c84030e0 | 131 | void * wxComboBox::DoGetItemClientData(unsigned int n) const |
4ddfa282 | 132 | { |
c84030e0 | 133 | wxCHECK_MSG( IsValid(n), NULL, wxT("wxChoice::DoGetClientData: invalid index") ); |
4ddfa282 | 134 | |
c84030e0 | 135 | return (void *)m_datas[n]; |
4ddfa282 SC |
136 | } |
137 | ||
f941a30b KO |
138 | unsigned int wxComboBox::GetCount() const |
139 | { | |
c84030e0 | 140 | return GetComboPeer()->GetNumberOfItems(); |
4ddfa282 SC |
141 | } |
142 | ||
143 | void wxComboBox::DoDeleteOneItem(unsigned int n) | |
144 | { | |
c84030e0 | 145 | GetComboPeer()->RemoveItem(n); |
4ddfa282 SC |
146 | } |
147 | ||
148 | void wxComboBox::DoClear() | |
149 | { | |
c84030e0 KO |
150 | GetComboPeer()->Clear(); |
151 | SetValue(wxEmptyString); | |
4ddfa282 SC |
152 | } |
153 | ||
c84030e0 KO |
154 | void wxComboBox::GetSelection(long *from, long *to) const |
155 | { | |
156 | wxTextEntry::GetSelection(from, to); | |
157 | } | |
158 | ||
4ddfa282 SC |
159 | int wxComboBox::GetSelection() const |
160 | { | |
c84030e0 | 161 | return GetComboPeer()->GetSelectedItem(); |
4ddfa282 SC |
162 | } |
163 | ||
c84030e0 | 164 | void wxComboBox::SetSelection(int n) |
4ddfa282 | 165 | { |
c84030e0 | 166 | GetComboPeer()->SetSelectedItem(n); |
f941a30b | 167 | } |
4ddfa282 | 168 | |
c84030e0 | 169 | void wxComboBox::SetSelection(long from, long to) |
f941a30b | 170 | { |
c84030e0 | 171 | wxTextEntry::SetSelection(from, to); |
4ddfa282 SC |
172 | } |
173 | ||
174 | int wxComboBox::FindString(const wxString& s, bool bCase) const | |
175 | { | |
c84030e0 KO |
176 | if (!bCase) |
177 | wxLogWarning("wxComboBox::FindString on Mac doesn't currently support case insensitive search."); | |
178 | ||
179 | return GetComboPeer()->FindString(s); | |
4ddfa282 SC |
180 | } |
181 | ||
182 | wxString wxComboBox::GetString(unsigned int n) const | |
183 | { | |
c84030e0 | 184 | return GetComboPeer()->GetStringAtIndex(n); |
4ddfa282 SC |
185 | } |
186 | ||
187 | wxString wxComboBox::GetStringSelection() const | |
188 | { | |
c84030e0 | 189 | return GetString(GetSelection()); |
4ddfa282 SC |
190 | } |
191 | ||
192 | void wxComboBox::SetString(unsigned int n, const wxString& s) | |
193 | { | |
c84030e0 KO |
194 | Delete(n); |
195 | Insert(s, n); | |
196 | SetValue(s); // changing the item in the list won't update the display item | |
f941a30b KO |
197 | } |
198 | ||
199 | void wxComboBox::EnableTextChangedEvents(bool enable) | |
200 | { | |
201 | wxFAIL_MSG("Method Not Implemented."); | |
202 | } | |
203 | ||
4ddfa282 SC |
204 | bool wxComboBox::OSXHandleClicked( double timestampsec ) |
205 | { | |
206 | wxCommandEvent event(wxEVT_COMMAND_COMBOBOX_SELECTED, m_windowId ); | |
207 | event.SetInt(GetSelection()); | |
208 | event.SetEventObject(this); | |
209 | event.SetString(GetStringSelection()); | |
210 | ProcessCommand(event); | |
211 | return true; | |
212 | } | |
213 | ||
c84030e0 KO |
214 | wxTextWidgetImpl* wxComboBox::GetTextPeer() const |
215 | { | |
216 | return dynamic_cast<wxTextWidgetImpl*> (m_peer); | |
217 | } | |
218 | ||
219 | wxComboWidgetImpl* wxComboBox::GetComboPeer() const | |
220 | { | |
221 | return dynamic_cast<wxComboWidgetImpl*> (m_peer); | |
222 | } | |
223 | ||
224 | #endif // wxUSE_COMBOBOX && wxOSX_USE_COCOA |