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