]>
Commit | Line | Data |
---|---|---|
e9576ca5 | 1 | /////////////////////////////////////////////////////////////////////////////// |
11e62fe6 | 2 | // Name: src/mac/carbon/listbox.cpp |
e9576ca5 | 3 | // Purpose: wxListBox |
a31a5f85 | 4 | // Author: Stefan Csomor |
e9576ca5 | 5 | // Modified by: |
a31a5f85 | 6 | // Created: 1998-01-01 |
e9576ca5 | 7 | // RCS-ID: $Id$ |
a31a5f85 | 8 | // Copyright: (c) Stefan Csomor |
65571936 | 9 | // Licence: wxWindows licence |
e9576ca5 SC |
10 | /////////////////////////////////////////////////////////////////////////////// |
11 | ||
3d1a4878 SC |
12 | #include "wx/wxprec.h" |
13 | ||
179e085f RN |
14 | #if wxUSE_LISTBOX |
15 | ||
e4db172a WS |
16 | #include "wx/listbox.h" |
17 | ||
ad9835c9 | 18 | #ifndef WX_PRECOMP |
e4db172a | 19 | #include "wx/log.h" |
987e9419 | 20 | #include "wx/intl.h" |
de6185e2 | 21 | #include "wx/utils.h" |
9eddec69 | 22 | #include "wx/settings.h" |
aaa6d89a | 23 | #include "wx/arrstr.h" |
ad002397 | 24 | #include "wx/dcclient.h" |
ad9835c9 WS |
25 | #endif |
26 | ||
b1294ada | 27 | IMPLEMENT_DYNAMIC_CLASS(wxListBox, wxControlWithItems) |
b4726a58 SC |
28 | |
29 | BEGIN_EVENT_TABLE(wxListBox, wxControl) | |
30 | END_EVENT_TABLE() | |
31 | ||
fdd4e6cc | 32 | #include "wx/mac/uma.h" |
b4726a58 SC |
33 | |
34 | // ============================================================================ | |
6cce68ea | 35 | // list box control implementation |
b4726a58 | 36 | // ============================================================================ |
e9576ca5 | 37 | |
6cce68ea | 38 | wxListBox::wxListBox() |
83ce5634 | 39 | { |
83ce5634 SC |
40 | } |
41 | ||
6cce68ea SC |
42 | bool wxListBox::Create( |
43 | wxWindow *parent, | |
44 | wxWindowID id, | |
45 | const wxPoint& pos, | |
46 | const wxSize& size, | |
47 | const wxArrayString& choices, | |
48 | long style, | |
49 | const wxValidator& validator, | |
50 | const wxString& name ) | |
facd6764 | 51 | { |
6cce68ea | 52 | wxCArrayString chs(choices); |
cee24bf7 | 53 | |
6cce68ea SC |
54 | return Create( |
55 | parent, id, pos, size, chs.GetCount(), chs.GetStrings(), | |
56 | style, validator, name ); | |
57 | } | |
c6179a84 | 58 | |
ad9835c9 WS |
59 | wxMacListControl* wxListBox::GetPeer() const |
60 | { | |
bf9a1615 SC |
61 | wxMacDataBrowserListControl *lb = wxDynamicCast(m_peer,wxMacDataBrowserListControl); |
62 | return lb ? wx_static_cast(wxMacListControl*,lb) : 0 ; | |
facd6764 | 63 | } |
fe3dc505 | 64 | |
6cce68ea SC |
65 | bool wxListBox::Create( |
66 | wxWindow *parent, | |
67 | wxWindowID id, | |
68 | const wxPoint& pos, | |
69 | const wxSize& size, | |
70 | int n, | |
71 | const wxString choices[], | |
72 | long style, | |
73 | const wxValidator& validator, | |
74 | const wxString& name ) | |
b4726a58 | 75 | { |
6cce68ea | 76 | m_macIsUserPane = false; |
b4726a58 | 77 | |
6cce68ea SC |
78 | wxASSERT_MSG( !(style & wxLB_MULTIPLE) || !(style & wxLB_EXTENDED), |
79 | wxT("only a single listbox selection mode can be specified") ); | |
b4726a58 | 80 | |
6cce68ea SC |
81 | if ( !wxListBoxBase::Create( parent, id, pos, size, style & ~(wxHSCROLL | wxVSCROLL), validator, name ) ) |
82 | return false; | |
ad9835c9 | 83 | |
6cce68ea | 84 | wxMacDataBrowserListControl* control = new wxMacDataBrowserListControl( this, pos, size, style ); |
6cce68ea | 85 | m_peer = control; |
cee24bf7 | 86 | |
6cce68ea | 87 | MacPostControlCreate( pos, size ); |
b4726a58 | 88 | |
a236aa20 | 89 | Append(n, choices); |
b4726a58 | 90 | |
6cce68ea | 91 | // Needed because it is a wxControlWithItems |
170acdc9 | 92 | SetInitialSize( size ); |
b4726a58 | 93 | |
6cce68ea SC |
94 | return true; |
95 | } | |
cee24bf7 | 96 | |
6cce68ea SC |
97 | wxListBox::~wxListBox() |
98 | { | |
99 | FreeData(); | |
100 | m_peer->SetReference( 0 ); | |
101 | } | |
b4726a58 | 102 | |
6cce68ea SC |
103 | void wxListBox::FreeData() |
104 | { | |
105 | GetPeer()->MacClear(); | |
106 | } | |
b4726a58 | 107 | |
6cce68ea SC |
108 | void wxListBox::DoSetFirstItem(int n) |
109 | { | |
110 | GetPeer()->MacScrollTo( n ); | |
111 | } | |
b4726a58 | 112 | |
6cce68ea SC |
113 | void wxListBox::EnsureVisible(int n) |
114 | { | |
115 | GetPeer()->MacScrollTo( n ); | |
b4726a58 | 116 | } |
cee24bf7 | 117 | |
a236aa20 | 118 | void wxListBox::DoDeleteOneItem(unsigned int n) |
b4726a58 | 119 | { |
6cce68ea SC |
120 | wxCHECK_RET( IsValid(n), wxT("invalid index in wxListBox::Delete") ); |
121 | ||
122 | GetPeer()->MacDelete( n ); | |
b4726a58 SC |
123 | } |
124 | ||
a236aa20 VZ |
125 | int wxListBox::DoInsertItems(const wxArrayStringsAdapter& items, |
126 | unsigned int pos, | |
127 | void **clientData, | |
128 | wxClientDataType type) | |
b4726a58 | 129 | { |
6cce68ea | 130 | InvalidateBestSize(); |
b4726a58 | 131 | |
a236aa20 VZ |
132 | GetPeer()->MacInsert( pos, items ); |
133 | const unsigned int count = items.GetCount(); | |
134 | if ( clientData ) | |
b4726a58 | 135 | { |
a236aa20 VZ |
136 | for (unsigned int i = 0; i < count; ++i) |
137 | AssignNewItemClientData( pos + i, clientData, i, type ); | |
b4726a58 | 138 | } |
cee24bf7 | 139 | |
a236aa20 | 140 | return pos + count - 1; |
b4726a58 SC |
141 | } |
142 | ||
6cce68ea | 143 | int wxListBox::FindString(const wxString& s, bool bCase) const |
b4726a58 | 144 | { |
6cce68ea | 145 | for ( size_t i = 0; i < GetCount(); ++ i ) |
b4726a58 | 146 | { |
6cce68ea SC |
147 | if (s.IsSameAs( GetString( i ), bCase) ) |
148 | return (int)i; | |
b4726a58 SC |
149 | } |
150 | ||
6cce68ea | 151 | return wxNOT_FOUND; |
b4726a58 SC |
152 | } |
153 | ||
a236aa20 | 154 | void wxListBox::DoClear() |
b4726a58 | 155 | { |
6cce68ea SC |
156 | FreeData(); |
157 | } | |
b4726a58 | 158 | |
6cce68ea SC |
159 | void wxListBox::DoSetSelection(int n, bool select) |
160 | { | |
161 | wxCHECK_RET( n == wxNOT_FOUND || IsValid(n), | |
162 | wxT("invalid index in wxListBox::SetSelection") ); | |
b4726a58 | 163 | |
6cce68ea SC |
164 | if ( n == wxNOT_FOUND ) |
165 | GetPeer()->MacDeselectAll(); | |
166 | else | |
e2bc1d69 | 167 | GetPeer()->MacSetSelection( n, select, HasMultipleSelection() ); |
6cce68ea | 168 | } |
b4726a58 | 169 | |
6cce68ea SC |
170 | bool wxListBox::IsSelected(int n) const |
171 | { | |
172 | wxCHECK_MSG( IsValid(n), false, wxT("invalid index in wxListBox::Selected") ); | |
cee24bf7 | 173 | |
6cce68ea | 174 | return GetPeer()->MacIsSelected( n ); |
b4726a58 SC |
175 | } |
176 | ||
6cce68ea | 177 | void *wxListBox::DoGetItemClientData(unsigned int n) const |
b4726a58 | 178 | { |
6cce68ea SC |
179 | wxCHECK_MSG( IsValid(n), NULL, wxT("invalid index in wxListBox::GetClientData")); |
180 | return GetPeer()->MacGetClientData( n ); | |
b4726a58 SC |
181 | } |
182 | ||
6cce68ea | 183 | void wxListBox::DoSetItemClientData(unsigned int n, void *clientData) |
b4726a58 | 184 | { |
6cce68ea SC |
185 | wxCHECK_RET( IsValid(n), wxT("invalid index in wxListBox::SetClientData") ); |
186 | GetPeer()->MacSetClientData( n , clientData); | |
b4726a58 SC |
187 | } |
188 | ||
6cce68ea SC |
189 | // Return number of selections and an array of selected integers |
190 | int wxListBox::GetSelections(wxArrayInt& aSelections) const | |
b4726a58 | 191 | { |
6cce68ea SC |
192 | return GetPeer()->MacGetSelections( aSelections ); |
193 | } | |
cee24bf7 | 194 | |
6cce68ea SC |
195 | // Get single selection, for single choice list items |
196 | int wxListBox::GetSelection() const | |
197 | { | |
198 | return GetPeer()->MacGetSelection(); | |
b4726a58 SC |
199 | } |
200 | ||
6cce68ea SC |
201 | // Find string for position |
202 | wxString wxListBox::GetString(unsigned int n) const | |
b4726a58 | 203 | { |
6cce68ea SC |
204 | wxCHECK_MSG( IsValid(n), wxEmptyString, wxT("invalid index in wxListBox::GetString") ); |
205 | return GetPeer()->MacGetString(n); | |
b4726a58 SC |
206 | } |
207 | ||
6cce68ea | 208 | void wxListBox::SetString(unsigned int n, const wxString& s) |
b4726a58 | 209 | { |
6cce68ea SC |
210 | GetPeer()->MacSetString( n, s ); |
211 | } | |
b4726a58 | 212 | |
6cce68ea SC |
213 | wxSize wxListBox::DoGetBestSize() const |
214 | { | |
215 | int lbWidth = 100; // some defaults | |
216 | int lbHeight = 110; | |
217 | int wLine; | |
b4726a58 | 218 | |
b4726a58 | 219 | { |
7cd7bc23 SC |
220 | #if wxMAC_USE_CORE_GRAPHICS |
221 | wxClientDC dc(const_cast<wxListBox*>(this)); | |
7749035c | 222 | dc.SetFont(GetFont()); |
7cd7bc23 | 223 | #else |
6cce68ea SC |
224 | wxMacPortStateHelper st( UMAGetWindowPort( (WindowRef)MacGetTopLevelWindowRef() ) ); |
225 | ||
226 | // TODO: clean this up | |
227 | if ( m_font.Ok() ) | |
b4726a58 | 228 | { |
6cce68ea SC |
229 | ::TextFont( m_font.MacGetFontNum() ); |
230 | ::TextSize( m_font.MacGetFontSize() ); | |
231 | ::TextFace( m_font.MacGetFontStyle() ); | |
232 | } | |
233 | else | |
234 | { | |
235 | ::TextFont( kFontIDMonaco ); | |
236 | ::TextSize( 9 ); | |
237 | ::TextFace( 0 ); | |
b4726a58 | 238 | } |
7cd7bc23 | 239 | #endif |
6cce68ea SC |
240 | // Find the widest line |
241 | for (unsigned int i = 0; i < GetCount(); i++) | |
242 | { | |
243 | wxString str( GetString( i ) ); | |
7cd7bc23 SC |
244 | #if wxMAC_USE_CORE_GRAPHICS |
245 | wxCoord width, height ; | |
246 | dc.GetTextExtent( str , &width, &height); | |
247 | wLine = width ; | |
248 | #else | |
6cce68ea SC |
249 | #if wxUSE_UNICODE |
250 | Point bounds = {0, 0}; | |
251 | SInt16 baseline; | |
b4726a58 | 252 | |
6cce68ea SC |
253 | // NB: what if m_font.Ok() == false ??? |
254 | ::GetThemeTextDimensions( | |
255 | wxMacCFStringHolder( str, m_font.GetEncoding() ), | |
256 | kThemeCurrentPortFont, | |
257 | kThemeStateActive, | |
258 | false, | |
259 | &bounds, | |
260 | &baseline ); | |
261 | wLine = bounds.h; | |
262 | #else | |
263 | wLine = ::TextWidth( str.c_str(), 0, str.length() ); | |
264 | #endif | |
7cd7bc23 | 265 | #endif |
7749035c | 266 | lbWidth = wxMax( lbWidth, wLine ); |
6cce68ea | 267 | } |
b4726a58 | 268 | |
6cce68ea SC |
269 | // Add room for the scrollbar |
270 | lbWidth += wxSystemSettings::GetMetric( wxSYS_VSCROLL_X ); | |
b4726a58 | 271 | |
6cce68ea SC |
272 | // And just a bit more |
273 | int cy = 12; | |
7cd7bc23 SC |
274 | #if wxMAC_USE_CORE_GRAPHICS |
275 | wxCoord width, height ; | |
7749035c | 276 | dc.GetTextExtent( wxT("XX") , &width, &height); |
7cd7bc23 SC |
277 | int cx = width ; |
278 | #else | |
7749035c | 279 | int cx = ::TextWidth( "XX", 0, 1 ); |
7cd7bc23 | 280 | #endif |
6cce68ea | 281 | lbWidth += cx; |
b4726a58 | 282 | |
6cce68ea SC |
283 | // don't make the listbox too tall (limit height to around 10 items) |
284 | // but don't make it too small neither | |
285 | lbHeight = wxMax( (cy + 4) * wxMin( wxMax( GetCount(), 3 ), 10 ), 70 ); | |
286 | } | |
b4726a58 | 287 | |
6cce68ea | 288 | return wxSize( lbWidth, lbHeight ); |
b4726a58 SC |
289 | } |
290 | ||
6cce68ea | 291 | unsigned int wxListBox::GetCount() const |
b4726a58 | 292 | { |
6cce68ea | 293 | return GetPeer()->MacGetCount(); |
b4726a58 SC |
294 | } |
295 | ||
6cce68ea | 296 | void wxListBox::Refresh(bool eraseBack, const wxRect *rect) |
b4726a58 | 297 | { |
6cce68ea | 298 | wxControl::Refresh( eraseBack, rect ); |
b4726a58 SC |
299 | } |
300 | ||
6cce68ea SC |
301 | // Some custom controls depend on this |
302 | /* static */ wxVisualAttributes | |
303 | wxListBox::GetClassDefaultAttributes(wxWindowVariant WXUNUSED(variant)) | |
b4726a58 | 304 | { |
6cce68ea | 305 | wxVisualAttributes attr; |
b4726a58 | 306 | |
6cce68ea SC |
307 | attr.colFg = wxSystemSettings::GetColour( wxSYS_COLOUR_WINDOWTEXT ); |
308 | attr.colBg = wxSystemSettings::GetColour( wxSYS_COLOUR_LISTBOX ); | |
309 | attr.font = wxSystemSettings::GetFont( wxSYS_DEFAULT_GUI_FONT ); | |
b4726a58 | 310 | |
6cce68ea | 311 | return attr; |
b4726a58 SC |
312 | } |
313 | ||
6cce68ea | 314 | int wxListBox::DoListHitTest(const wxPoint& inpoint) const |
b4726a58 | 315 | { |
6cce68ea | 316 | OSStatus err; |
b4726a58 | 317 | |
6cce68ea SC |
318 | // There are few reasons why this is complicated: |
319 | // 1) There is no native HitTest function for Mac | |
320 | // 2) GetDataBrowserItemPartBounds only works on visible items | |
321 | // 3) We can't do it through GetDataBrowserTableView[Item]RowHeight | |
322 | // because what it returns is basically inaccurate in the context | |
323 | // of the coordinates we want here, but we use this as a guess | |
324 | // for where the first visible item lies | |
b4726a58 | 325 | |
6cce68ea | 326 | wxPoint point = inpoint; |
b4726a58 | 327 | |
6cce68ea SC |
328 | // interestingly enough 10.2 (and below?) have GetDataBrowserItemPartBounds |
329 | // giving root window coordinates but 10.3 and above give client coordinates | |
330 | // so we only compare using root window coordinates on 10.3 and up | |
331 | if ( UMAGetSystemVersion() < 0x1030 ) | |
332 | MacClientToRootWindow(&point.x, &point.y); | |
b4726a58 | 333 | |
6cce68ea SC |
334 | // get column property ID (req. for call to itempartbounds) |
335 | DataBrowserTableViewColumnID colId = 0; | |
336 | err = GetDataBrowserTableViewColumnProperty(m_peer->GetControlRef(), 0, &colId); | |
337 | wxCHECK_MSG(err == noErr, wxNOT_FOUND, wxT("Unexpected error from GetDataBrowserTableViewColumnProperty")); | |
b4726a58 | 338 | |
6cce68ea SC |
339 | // OK, first we need to find the first visible item we have - |
340 | // this will be the "low" for our binary search. There is no real | |
341 | // easy way around this, as we will need to do a SLOW linear search | |
342 | // until we find a visible item, but we can do a cheap calculation | |
343 | // via the row height to speed things up a bit | |
344 | UInt32 scrollx, scrolly; | |
345 | err = GetDataBrowserScrollPosition(m_peer->GetControlRef(), &scrollx, &scrolly); | |
346 | wxCHECK_MSG(err == noErr, wxNOT_FOUND, wxT("Unexpected error from GetDataBrowserScrollPosition")); | |
b4726a58 | 347 | |
6cce68ea SC |
348 | UInt16 height; |
349 | err = GetDataBrowserTableViewRowHeight(m_peer->GetControlRef(), &height); | |
350 | wxCHECK_MSG(err == noErr, wxNOT_FOUND, wxT("Unexpected error from GetDataBrowserTableViewRowHeight")); | |
b4726a58 | 351 | |
6cce68ea SC |
352 | // these indices are 0-based, as usual, so we need to add 1 to them when |
353 | // passing them to data browser functions which use 1-based indices | |
354 | int low = scrolly / height, | |
355 | high = GetCount() - 1; | |
b4726a58 | 356 | |
6cce68ea SC |
357 | // search for the first visible item (note that the scroll guess above |
358 | // is the low bounds of where the item might lie so we only use that as a | |
359 | // starting point - we should reach it within 1 or 2 iterations of the loop) | |
360 | while ( low <= high ) | |
361 | { | |
362 | Rect bounds; | |
363 | err = GetDataBrowserItemPartBounds( | |
364 | m_peer->GetControlRef(), low + 1, colId, | |
365 | kDataBrowserPropertyEnclosingPart, | |
366 | &bounds); // note +1 to translate to Mac ID | |
367 | if ( err == noErr ) | |
368 | break; | |
b4726a58 | 369 | |
6cce68ea SC |
370 | // errDataBrowserItemNotFound is expected as it simply means that the |
371 | // item is not currently visible -- but other errors are not | |
372 | wxCHECK_MSG( err == errDataBrowserItemNotFound, wxNOT_FOUND, | |
373 | wxT("Unexpected error from GetDataBrowserItemPartBounds") ); | |
789ae0cf | 374 | |
6cce68ea SC |
375 | low++; |
376 | } | |
de1b0aeb | 377 | |
6cce68ea SC |
378 | // NOW do a binary search for where the item lies, searching low again if |
379 | // we hit an item that isn't visible | |
380 | while ( low <= high ) | |
789ae0cf | 381 | { |
6cce68ea | 382 | int mid = (low + high) / 2; |
fdd4e6cc | 383 | |
6cce68ea SC |
384 | Rect bounds; |
385 | err = GetDataBrowserItemPartBounds( | |
386 | m_peer->GetControlRef(), mid + 1, colId, | |
387 | kDataBrowserPropertyEnclosingPart, | |
388 | &bounds); //note +1 to trans to mac id | |
389 | wxCHECK_MSG( err == noErr || err == errDataBrowserItemNotFound, | |
390 | wxNOT_FOUND, | |
391 | wxT("Unexpected error from GetDataBrowserItemPartBounds") ); | |
789ae0cf | 392 | |
6cce68ea SC |
393 | if ( err == errDataBrowserItemNotFound ) |
394 | { | |
395 | // item not visible, attempt to find a visible one | |
396 | // search lower | |
397 | high = mid - 1; | |
398 | } | |
399 | else // visible item, do actual hitttest | |
400 | { | |
401 | // if point is within the bounds, return this item (since we assume | |
402 | // all x coords of items are equal we only test the x coord in | |
403 | // equality) | |
404 | if ((point.x >= bounds.left && point.x <= bounds.right) && | |
405 | (point.y >= bounds.top && point.y <= bounds.bottom) ) | |
406 | { | |
407 | // found! | |
408 | return mid; | |
409 | } | |
fdd4e6cc | 410 | |
6cce68ea SC |
411 | if ( point.y < bounds.top ) |
412 | // index(bounds) greater then key(point) | |
413 | high = mid - 1; | |
414 | else | |
415 | // index(bounds) less then key(point) | |
416 | low = mid + 1; | |
417 | } | |
418 | } | |
fdd4e6cc | 419 | |
6cce68ea | 420 | return wxNOT_FOUND; |
789ae0cf | 421 | } |
b4726a58 | 422 | |
b4726a58 | 423 | // ============================================================================ |
6cce68ea | 424 | // data browser based implementation |
b4726a58 | 425 | // ============================================================================ |
fe3dc505 | 426 | |
6cce68ea | 427 | wxMacListBoxItem::wxMacListBoxItem() |
e2bc1d69 | 428 | :wxMacDataItem() |
fe3dc505 | 429 | { |
fe3dc505 SC |
430 | } |
431 | ||
6cce68ea | 432 | wxMacListBoxItem::~wxMacListBoxItem() |
fe3dc505 | 433 | { |
fe3dc505 SC |
434 | } |
435 | ||
ad9835c9 | 436 | void wxMacListBoxItem::Notification(wxMacDataItemBrowserControl *owner , |
6cce68ea | 437 | DataBrowserItemNotification message, |
89954433 | 438 | DataBrowserItemDataRef WXUNUSED(itemData) ) const |
6cce68ea | 439 | { |
bf9a1615 | 440 | wxMacDataBrowserListControl *lb = wxDynamicCast(owner,wxMacDataBrowserListControl); |
b4726a58 | 441 | |
6cce68ea | 442 | // we want to depend on as little as possible to make sure tear-down of controls is safe |
ad9835c9 | 443 | |
6cce68ea SC |
444 | if ( message == kDataBrowserItemRemoved) |
445 | { | |
446 | if ( lb != NULL && lb->GetClientDataType() == wxClientData_Object ) | |
cee24bf7 | 447 | { |
6cce68ea | 448 | delete (wxClientData*) (m_data); |
b4726a58 | 449 | } |
6cce68ea SC |
450 | |
451 | delete this; | |
452 | return; | |
b4726a58 | 453 | } |
ad9835c9 | 454 | |
6cce68ea SC |
455 | wxListBox *list = wxDynamicCast( owner->GetPeer() , wxListBox ); |
456 | wxCHECK_RET( list != NULL , wxT("Listbox expected")); | |
facd6764 | 457 | |
6cce68ea SC |
458 | bool trigger = false; |
459 | wxCommandEvent event( wxEVT_COMMAND_LISTBOX_SELECTED, list->GetId() ); | |
460 | switch (message) | |
facd6764 | 461 | { |
6cce68ea SC |
462 | case kDataBrowserItemDeselected: |
463 | if ( list->HasMultipleSelection() ) | |
464 | trigger = !lb->IsSelectionSuppressed(); | |
465 | break; | |
fdd4e6cc | 466 | |
6cce68ea SC |
467 | case kDataBrowserItemSelected: |
468 | trigger = !lb->IsSelectionSuppressed(); | |
469 | break; | |
facd6764 | 470 | |
6cce68ea SC |
471 | case kDataBrowserItemDoubleClicked: |
472 | event.SetEventType( wxEVT_COMMAND_LISTBOX_DOUBLECLICKED ); | |
473 | trigger = true; | |
474 | break; | |
facd6764 | 475 | |
6cce68ea SC |
476 | default: |
477 | break; | |
478 | } | |
c6179a84 | 479 | |
6cce68ea SC |
480 | if ( trigger ) |
481 | { | |
482 | event.SetEventObject( list ); | |
483 | if ( list->HasClientObjectData() ) | |
484 | event.SetClientObject( (wxClientData*) m_data ); | |
485 | else if ( list->HasClientUntypedData() ) | |
486 | event.SetClientData( m_data ); | |
487 | event.SetString( m_label ); | |
488 | event.SetInt( owner->GetLineFromItem( this ) ); | |
489 | event.SetExtraLong( list->HasMultipleSelection() ? message == kDataBrowserItemSelected : true ); | |
6cce68ea | 490 | |
e6fd62dd RD |
491 | // direct notification is not always having the listbox GetSelection() |
492 | // having in synch with event, so use wxPostEvent instead | |
6cce68ea | 493 | // list->GetEventHandler()->ProcessEvent(event); |
e6fd62dd RD |
494 | |
495 | wxPostEvent( list->GetEventHandler(), event ); | |
6cce68ea | 496 | } |
facd6764 SC |
497 | } |
498 | ||
bf9a1615 SC |
499 | IMPLEMENT_DYNAMIC_CLASS( wxMacDataBrowserListControl , wxMacDataItemBrowserControl ) |
500 | ||
e2bc1d69 | 501 | wxMacDataBrowserListControl::wxMacDataBrowserListControl( wxWindow *peer, const wxPoint& pos, const wxSize& size, long style) |
6cce68ea | 502 | : wxMacDataItemBrowserControl( peer, pos, size, style ) |
facd6764 | 503 | { |
6cce68ea SC |
504 | OSStatus err = noErr; |
505 | m_clientDataItemsType = wxClientData_None; | |
e2bc1d69 KO |
506 | if ( style & wxLB_SORT ) |
507 | m_sortOrder = SortOrder_Text_Ascending; | |
ad9835c9 | 508 | |
6cce68ea SC |
509 | DataBrowserSelectionFlags options = kDataBrowserDragSelect; |
510 | if ( style & wxLB_MULTIPLE ) | |
511 | { | |
512 | options |= kDataBrowserAlwaysExtendSelection | kDataBrowserCmdTogglesSelection; | |
513 | } | |
514 | else if ( style & wxLB_EXTENDED ) | |
515 | { | |
464b15e1 | 516 | options |= kDataBrowserCmdTogglesSelection; |
6cce68ea SC |
517 | } |
518 | else | |
519 | { | |
520 | options |= kDataBrowserSelectOnlyOne; | |
521 | } | |
522 | err = SetSelectionFlags( options ); | |
523 | verify_noerr( err ); | |
ad9835c9 | 524 | |
6cce68ea SC |
525 | DataBrowserListViewColumnDesc columnDesc; |
526 | columnDesc.headerBtnDesc.titleOffset = 0; | |
527 | columnDesc.headerBtnDesc.version = kDataBrowserListViewLatestHeaderDesc; | |
facd6764 | 528 | |
6cce68ea SC |
529 | columnDesc.headerBtnDesc.btnFontStyle.flags = |
530 | kControlUseFontMask | kControlUseJustMask; | |
8228b893 | 531 | |
6cce68ea SC |
532 | columnDesc.headerBtnDesc.btnContentInfo.contentType = kControlNoContent; |
533 | columnDesc.headerBtnDesc.btnFontStyle.just = teFlushDefault; | |
534 | columnDesc.headerBtnDesc.btnFontStyle.font = kControlFontViewSystemFont; | |
535 | columnDesc.headerBtnDesc.btnFontStyle.style = normal; | |
536 | columnDesc.headerBtnDesc.titleString = NULL; | |
c6179a84 | 537 | |
6cce68ea SC |
538 | columnDesc.headerBtnDesc.minimumWidth = 0; |
539 | columnDesc.headerBtnDesc.maximumWidth = 10000; | |
facd6764 | 540 | |
6cce68ea SC |
541 | columnDesc.propertyDesc.propertyID = kTextColumnId; |
542 | columnDesc.propertyDesc.propertyType = kDataBrowserTextType; | |
543 | columnDesc.propertyDesc.propertyFlags = kDataBrowserTableViewSelectionColumn; | |
544 | #if MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_2 | |
545 | columnDesc.propertyDesc.propertyFlags |= kDataBrowserListViewTypeSelectColumn; | |
546 | #endif | |
facd6764 | 547 | |
6cce68ea | 548 | verify_noerr( AddColumn( &columnDesc, kDataBrowserListViewAppendColumn ) ); |
c6179a84 | 549 | |
6cce68ea SC |
550 | columnDesc.headerBtnDesc.minimumWidth = 0; |
551 | columnDesc.headerBtnDesc.maximumWidth = 0; | |
552 | columnDesc.propertyDesc.propertyID = kNumericOrderColumnId; | |
553 | columnDesc.propertyDesc.propertyType = kDataBrowserPropertyRelevanceRankPart; | |
554 | columnDesc.propertyDesc.propertyFlags = kDataBrowserTableViewSelectionColumn; | |
555 | #if MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_2 | |
556 | columnDesc.propertyDesc.propertyFlags |= kDataBrowserListViewTypeSelectColumn; | |
cee24bf7 DS |
557 | #endif |
558 | ||
6cce68ea | 559 | verify_noerr( AddColumn( &columnDesc, kDataBrowserListViewAppendColumn ) ); |
c6179a84 | 560 | |
6cce68ea | 561 | SetDataBrowserSortProperty( m_controlRef , kTextColumnId); |
e2bc1d69 | 562 | if ( m_sortOrder == SortOrder_Text_Ascending ) |
6cce68ea SC |
563 | { |
564 | SetDataBrowserSortProperty( m_controlRef , kTextColumnId); | |
565 | SetDataBrowserSortOrder( m_controlRef , kDataBrowserOrderIncreasing); | |
566 | } | |
facd6764 | 567 | else |
6cce68ea SC |
568 | { |
569 | SetDataBrowserSortProperty( m_controlRef , kNumericOrderColumnId); | |
570 | SetDataBrowserSortOrder( m_controlRef , kDataBrowserOrderIncreasing); | |
571 | } | |
facd6764 | 572 | |
6cce68ea SC |
573 | verify_noerr( AutoSizeColumns() ); |
574 | verify_noerr( SetHiliteStyle(kDataBrowserTableViewFillHilite ) ); | |
575 | verify_noerr( SetHeaderButtonHeight( 0 ) ); | |
576 | err = SetHasScrollBars( (style & wxHSCROLL) != 0 , true ); | |
577 | #if 0 | |
578 | // shouldn't be necessary anymore under 10.2 | |
579 | m_peer->SetData( kControlNoPart, kControlDataBrowserIncludesFrameAndFocusTag, (Boolean)false ); | |
580 | m_peer->SetNeedsFocusRect( true ); | |
581 | #endif | |
facd6764 SC |
582 | } |
583 | ||
6cce68ea | 584 | wxMacDataBrowserListControl::~wxMacDataBrowserListControl() |
facd6764 | 585 | { |
facd6764 SC |
586 | } |
587 | ||
e2bc1d69 | 588 | wxWindow * wxMacDataBrowserListControl::GetPeer() const |
6cce68ea | 589 | { |
e2bc1d69 | 590 | return wxDynamicCast( wxMacControl::GetPeer() , wxWindow ); |
6cce68ea | 591 | } |
443e2f09 | 592 | |
e6fd62dd RD |
593 | wxMacDataItem* wxMacDataBrowserListControl::CreateItem() |
594 | { | |
595 | return new wxMacListBoxItem(); | |
596 | } | |
597 | ||
6cce68ea | 598 | #if 0 |
443e2f09 | 599 | |
6cce68ea | 600 | // in case we need that one day |
443e2f09 | 601 | |
6cce68ea SC |
602 | // ============================================================================ |
603 | // HIView owner-draw-based implementation | |
604 | // ============================================================================ | |
443e2f09 | 605 | |
6cce68ea SC |
606 | static pascal void ListBoxDrawProc( |
607 | ControlRef browser, DataBrowserItemID item, DataBrowserPropertyID property, | |
608 | DataBrowserItemState itemState, const Rect *itemRect, SInt16 depth, Boolean isColorDevice ) | |
609 | { | |
610 | CFStringRef cfString; | |
611 | ThemeDrawingState themeState; | |
612 | long systemVersion; | |
443e2f09 | 613 | |
6cce68ea SC |
614 | GetThemeDrawingState( &themeState ); |
615 | cfString = CFStringCreateWithFormat( NULL, NULL, CFSTR("Row %d"), item ); | |
c00fed0e | 616 | |
6cce68ea SC |
617 | // In this sample we handle the "selected" state; all others fall through to our "active" state |
618 | if ( itemState == kDataBrowserItemIsSelected ) | |
c00fed0e | 619 | { |
6cce68ea | 620 | ThemeBrush colorBrushID; |
443e2f09 | 621 | |
6cce68ea SC |
622 | // TODO: switch over to wxSystemSettingsNative::GetColour() when kThemeBrushSecondaryHighlightColor |
623 | // is incorporated Panther DB starts using kThemeBrushSecondaryHighlightColor | |
624 | // for inactive browser highlighting | |
625 | Gestalt( gestaltSystemVersion, &systemVersion ); | |
626 | if ( (systemVersion >= 0x00001030) && !IsControlActive( browser ) ) | |
627 | colorBrushID = kThemeBrushSecondaryHighlightColor; | |
628 | else | |
629 | colorBrushID = kThemeBrushPrimaryHighlightColor; | |
443e2f09 | 630 | |
6cce68ea SC |
631 | // First paint the hilite rect, then the text on top |
632 | SetThemePen( colorBrushID, 32, true ); | |
633 | PaintRect( itemRect ); | |
634 | SetThemeDrawingState( themeState, false ); | |
c00fed0e | 635 | } |
443e2f09 | 636 | |
6cce68ea SC |
637 | DrawThemeTextBox( cfString, kThemeApplicationFont, kThemeStateActive, true, itemRect, teFlushDefault, NULL ); |
638 | SetThemeDrawingState( themeState, true ); | |
639 | ||
640 | if ( cfString != NULL ) | |
641 | CFRelease( cfString ); | |
c00fed0e VZ |
642 | } |
643 | ||
179e085f | 644 | #endif |
6cce68ea SC |
645 | |
646 | ||
987e9419 | 647 | #endif // wxUSE_LISTBOX |