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