]> git.saurik.com Git - wxWidgets.git/blame - src/mac/carbon/listbox.cpp
1945421 applied
[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 221 wxClientDC dc(const_cast<wxListBox*>(this));
7749035c 222 dc.SetFont(GetFont());
6cce68ea 223
6cce68ea
SC
224 // Find the widest line
225 for (unsigned int i = 0; i < GetCount(); i++)
226 {
227 wxString str( GetString( i ) );
e1673e52 228
7cd7bc23
SC
229 wxCoord width, height ;
230 dc.GetTextExtent( str , &width, &height);
231 wLine = width ;
7749035c 232 lbWidth = wxMax( lbWidth, wLine );
6cce68ea 233 }
b4726a58 234
6cce68ea
SC
235 // Add room for the scrollbar
236 lbWidth += wxSystemSettings::GetMetric( wxSYS_VSCROLL_X );
b4726a58 237
6cce68ea
SC
238 // And just a bit more
239 int cy = 12;
e1673e52 240
7cd7bc23 241 wxCoord width, height ;
7749035c 242 dc.GetTextExtent( wxT("XX") , &width, &height);
7cd7bc23 243 int cx = width ;
6cce68ea 244 lbWidth += cx;
b4726a58 245
6cce68ea
SC
246 // don't make the listbox too tall (limit height to around 10 items)
247 // but don't make it too small neither
248 lbHeight = wxMax( (cy + 4) * wxMin( wxMax( GetCount(), 3 ), 10 ), 70 );
249 }
b4726a58 250
6cce68ea 251 return wxSize( lbWidth, lbHeight );
b4726a58
SC
252}
253
6cce68ea 254unsigned int wxListBox::GetCount() const
b4726a58 255{
6cce68ea 256 return GetPeer()->MacGetCount();
b4726a58
SC
257}
258
6cce68ea 259void wxListBox::Refresh(bool eraseBack, const wxRect *rect)
b4726a58 260{
6cce68ea 261 wxControl::Refresh( eraseBack, rect );
b4726a58
SC
262}
263
6cce68ea
SC
264// Some custom controls depend on this
265/* static */ wxVisualAttributes
266wxListBox::GetClassDefaultAttributes(wxWindowVariant WXUNUSED(variant))
b4726a58 267{
6cce68ea 268 wxVisualAttributes attr;
b4726a58 269
6cce68ea
SC
270 attr.colFg = wxSystemSettings::GetColour( wxSYS_COLOUR_WINDOWTEXT );
271 attr.colBg = wxSystemSettings::GetColour( wxSYS_COLOUR_LISTBOX );
4bff335a 272 attr.font.MacCreateFromThemeFont(kThemeViewsFont);
b4726a58 273
6cce68ea 274 return attr;
b4726a58
SC
275}
276
6cce68ea 277int wxListBox::DoListHitTest(const wxPoint& inpoint) const
b4726a58 278{
6cce68ea 279 OSStatus err;
b4726a58 280
6cce68ea
SC
281 // There are few reasons why this is complicated:
282 // 1) There is no native HitTest function for Mac
283 // 2) GetDataBrowserItemPartBounds only works on visible items
284 // 3) We can't do it through GetDataBrowserTableView[Item]RowHeight
285 // because what it returns is basically inaccurate in the context
286 // of the coordinates we want here, but we use this as a guess
287 // for where the first visible item lies
b4726a58 288
6cce68ea 289 wxPoint point = inpoint;
b4726a58 290
6cce68ea
SC
291 // get column property ID (req. for call to itempartbounds)
292 DataBrowserTableViewColumnID colId = 0;
293 err = GetDataBrowserTableViewColumnProperty(m_peer->GetControlRef(), 0, &colId);
294 wxCHECK_MSG(err == noErr, wxNOT_FOUND, wxT("Unexpected error from GetDataBrowserTableViewColumnProperty"));
b4726a58 295
6cce68ea
SC
296 // OK, first we need to find the first visible item we have -
297 // this will be the "low" for our binary search. There is no real
298 // easy way around this, as we will need to do a SLOW linear search
299 // until we find a visible item, but we can do a cheap calculation
300 // via the row height to speed things up a bit
301 UInt32 scrollx, scrolly;
302 err = GetDataBrowserScrollPosition(m_peer->GetControlRef(), &scrollx, &scrolly);
303 wxCHECK_MSG(err == noErr, wxNOT_FOUND, wxT("Unexpected error from GetDataBrowserScrollPosition"));
b4726a58 304
6cce68ea
SC
305 UInt16 height;
306 err = GetDataBrowserTableViewRowHeight(m_peer->GetControlRef(), &height);
307 wxCHECK_MSG(err == noErr, wxNOT_FOUND, wxT("Unexpected error from GetDataBrowserTableViewRowHeight"));
b4726a58 308
6cce68ea
SC
309 // these indices are 0-based, as usual, so we need to add 1 to them when
310 // passing them to data browser functions which use 1-based indices
311 int low = scrolly / height,
312 high = GetCount() - 1;
b4726a58 313
6cce68ea
SC
314 // search for the first visible item (note that the scroll guess above
315 // is the low bounds of where the item might lie so we only use that as a
316 // starting point - we should reach it within 1 or 2 iterations of the loop)
317 while ( low <= high )
318 {
319 Rect bounds;
320 err = GetDataBrowserItemPartBounds(
321 m_peer->GetControlRef(), low + 1, colId,
322 kDataBrowserPropertyEnclosingPart,
323 &bounds); // note +1 to translate to Mac ID
324 if ( err == noErr )
325 break;
b4726a58 326
6cce68ea
SC
327 // errDataBrowserItemNotFound is expected as it simply means that the
328 // item is not currently visible -- but other errors are not
329 wxCHECK_MSG( err == errDataBrowserItemNotFound, wxNOT_FOUND,
330 wxT("Unexpected error from GetDataBrowserItemPartBounds") );
789ae0cf 331
6cce68ea
SC
332 low++;
333 }
de1b0aeb 334
6cce68ea
SC
335 // NOW do a binary search for where the item lies, searching low again if
336 // we hit an item that isn't visible
337 while ( low <= high )
789ae0cf 338 {
6cce68ea 339 int mid = (low + high) / 2;
fdd4e6cc 340
6cce68ea
SC
341 Rect bounds;
342 err = GetDataBrowserItemPartBounds(
343 m_peer->GetControlRef(), mid + 1, colId,
344 kDataBrowserPropertyEnclosingPart,
345 &bounds); //note +1 to trans to mac id
346 wxCHECK_MSG( err == noErr || err == errDataBrowserItemNotFound,
347 wxNOT_FOUND,
348 wxT("Unexpected error from GetDataBrowserItemPartBounds") );
789ae0cf 349
6cce68ea
SC
350 if ( err == errDataBrowserItemNotFound )
351 {
352 // item not visible, attempt to find a visible one
353 // search lower
354 high = mid - 1;
355 }
356 else // visible item, do actual hitttest
357 {
358 // if point is within the bounds, return this item (since we assume
359 // all x coords of items are equal we only test the x coord in
360 // equality)
361 if ((point.x >= bounds.left && point.x <= bounds.right) &&
362 (point.y >= bounds.top && point.y <= bounds.bottom) )
363 {
364 // found!
365 return mid;
366 }
fdd4e6cc 367
6cce68ea
SC
368 if ( point.y < bounds.top )
369 // index(bounds) greater then key(point)
370 high = mid - 1;
371 else
372 // index(bounds) less then key(point)
373 low = mid + 1;
374 }
375 }
fdd4e6cc 376
6cce68ea 377 return wxNOT_FOUND;
789ae0cf 378}
b4726a58 379
b4726a58 380// ============================================================================
6cce68ea 381// data browser based implementation
b4726a58 382// ============================================================================
fe3dc505 383
6cce68ea 384wxMacListBoxItem::wxMacListBoxItem()
e2bc1d69 385 :wxMacDataItem()
fe3dc505 386{
fe3dc505
SC
387}
388
6cce68ea 389wxMacListBoxItem::~wxMacListBoxItem()
fe3dc505 390{
fe3dc505
SC
391}
392
ad9835c9 393void wxMacListBoxItem::Notification(wxMacDataItemBrowserControl *owner ,
6cce68ea 394 DataBrowserItemNotification message,
89954433 395 DataBrowserItemDataRef WXUNUSED(itemData) ) const
6cce68ea 396{
bf9a1615 397 wxMacDataBrowserListControl *lb = wxDynamicCast(owner,wxMacDataBrowserListControl);
b4726a58 398
6cce68ea 399 // we want to depend on as little as possible to make sure tear-down of controls is safe
ad9835c9 400
6cce68ea
SC
401 if ( message == kDataBrowserItemRemoved)
402 {
403 if ( lb != NULL && lb->GetClientDataType() == wxClientData_Object )
cee24bf7 404 {
6cce68ea 405 delete (wxClientData*) (m_data);
b4726a58 406 }
6cce68ea
SC
407
408 delete this;
409 return;
b4726a58 410 }
ad9835c9 411
6cce68ea
SC
412 wxListBox *list = wxDynamicCast( owner->GetPeer() , wxListBox );
413 wxCHECK_RET( list != NULL , wxT("Listbox expected"));
facd6764 414
6cce68ea
SC
415 bool trigger = false;
416 wxCommandEvent event( wxEVT_COMMAND_LISTBOX_SELECTED, list->GetId() );
417 switch (message)
facd6764 418 {
6cce68ea
SC
419 case kDataBrowserItemDeselected:
420 if ( list->HasMultipleSelection() )
421 trigger = !lb->IsSelectionSuppressed();
422 break;
fdd4e6cc 423
6cce68ea
SC
424 case kDataBrowserItemSelected:
425 trigger = !lb->IsSelectionSuppressed();
426 break;
facd6764 427
6cce68ea
SC
428 case kDataBrowserItemDoubleClicked:
429 event.SetEventType( wxEVT_COMMAND_LISTBOX_DOUBLECLICKED );
430 trigger = true;
431 break;
facd6764 432
6cce68ea
SC
433 default:
434 break;
435 }
c6179a84 436
6cce68ea
SC
437 if ( trigger )
438 {
439 event.SetEventObject( list );
440 if ( list->HasClientObjectData() )
441 event.SetClientObject( (wxClientData*) m_data );
442 else if ( list->HasClientUntypedData() )
443 event.SetClientData( m_data );
444 event.SetString( m_label );
445 event.SetInt( owner->GetLineFromItem( this ) );
446 event.SetExtraLong( list->HasMultipleSelection() ? message == kDataBrowserItemSelected : true );
6cce68ea 447
e6fd62dd
RD
448 // direct notification is not always having the listbox GetSelection()
449 // having in synch with event, so use wxPostEvent instead
937013e0 450 // list->HandleWindowEvent(event);
e6fd62dd
RD
451
452 wxPostEvent( list->GetEventHandler(), event );
6cce68ea 453 }
facd6764
SC
454}
455
bf9a1615
SC
456IMPLEMENT_DYNAMIC_CLASS( wxMacDataBrowserListControl , wxMacDataItemBrowserControl )
457
e2bc1d69 458wxMacDataBrowserListControl::wxMacDataBrowserListControl( wxWindow *peer, const wxPoint& pos, const wxSize& size, long style)
6cce68ea 459 : wxMacDataItemBrowserControl( peer, pos, size, style )
facd6764 460{
6cce68ea
SC
461 OSStatus err = noErr;
462 m_clientDataItemsType = wxClientData_None;
e2bc1d69
KO
463 if ( style & wxLB_SORT )
464 m_sortOrder = SortOrder_Text_Ascending;
ad9835c9 465
6cce68ea
SC
466 DataBrowserSelectionFlags options = kDataBrowserDragSelect;
467 if ( style & wxLB_MULTIPLE )
468 {
469 options |= kDataBrowserAlwaysExtendSelection | kDataBrowserCmdTogglesSelection;
470 }
471 else if ( style & wxLB_EXTENDED )
472 {
464b15e1 473 options |= kDataBrowserCmdTogglesSelection;
6cce68ea
SC
474 }
475 else
476 {
477 options |= kDataBrowserSelectOnlyOne;
478 }
479 err = SetSelectionFlags( options );
480 verify_noerr( err );
ad9835c9 481
6cce68ea
SC
482 DataBrowserListViewColumnDesc columnDesc;
483 columnDesc.headerBtnDesc.titleOffset = 0;
484 columnDesc.headerBtnDesc.version = kDataBrowserListViewLatestHeaderDesc;
facd6764 485
6cce68ea
SC
486 columnDesc.headerBtnDesc.btnFontStyle.flags =
487 kControlUseFontMask | kControlUseJustMask;
8228b893 488
6cce68ea
SC
489 columnDesc.headerBtnDesc.btnContentInfo.contentType = kControlNoContent;
490 columnDesc.headerBtnDesc.btnFontStyle.just = teFlushDefault;
491 columnDesc.headerBtnDesc.btnFontStyle.font = kControlFontViewSystemFont;
492 columnDesc.headerBtnDesc.btnFontStyle.style = normal;
493 columnDesc.headerBtnDesc.titleString = NULL;
c6179a84 494
6cce68ea
SC
495 columnDesc.headerBtnDesc.minimumWidth = 0;
496 columnDesc.headerBtnDesc.maximumWidth = 10000;
facd6764 497
6cce68ea
SC
498 columnDesc.propertyDesc.propertyID = kTextColumnId;
499 columnDesc.propertyDesc.propertyType = kDataBrowserTextType;
500 columnDesc.propertyDesc.propertyFlags = kDataBrowserTableViewSelectionColumn;
6cce68ea 501 columnDesc.propertyDesc.propertyFlags |= kDataBrowserListViewTypeSelectColumn;
facd6764 502
6cce68ea 503 verify_noerr( AddColumn( &columnDesc, kDataBrowserListViewAppendColumn ) );
c6179a84 504
6cce68ea
SC
505 columnDesc.headerBtnDesc.minimumWidth = 0;
506 columnDesc.headerBtnDesc.maximumWidth = 0;
507 columnDesc.propertyDesc.propertyID = kNumericOrderColumnId;
508 columnDesc.propertyDesc.propertyType = kDataBrowserPropertyRelevanceRankPart;
509 columnDesc.propertyDesc.propertyFlags = kDataBrowserTableViewSelectionColumn;
6cce68ea 510 columnDesc.propertyDesc.propertyFlags |= kDataBrowserListViewTypeSelectColumn;
cee24bf7 511
6cce68ea 512 verify_noerr( AddColumn( &columnDesc, kDataBrowserListViewAppendColumn ) );
c6179a84 513
6cce68ea 514 SetDataBrowserSortProperty( m_controlRef , kTextColumnId);
e2bc1d69 515 if ( m_sortOrder == SortOrder_Text_Ascending )
6cce68ea
SC
516 {
517 SetDataBrowserSortProperty( m_controlRef , kTextColumnId);
518 SetDataBrowserSortOrder( m_controlRef , kDataBrowserOrderIncreasing);
519 }
facd6764 520 else
6cce68ea
SC
521 {
522 SetDataBrowserSortProperty( m_controlRef , kNumericOrderColumnId);
523 SetDataBrowserSortOrder( m_controlRef , kDataBrowserOrderIncreasing);
524 }
facd6764 525
6cce68ea
SC
526 verify_noerr( AutoSizeColumns() );
527 verify_noerr( SetHiliteStyle(kDataBrowserTableViewFillHilite ) );
528 verify_noerr( SetHeaderButtonHeight( 0 ) );
529 err = SetHasScrollBars( (style & wxHSCROLL) != 0 , true );
530#if 0
531 // shouldn't be necessary anymore under 10.2
532 m_peer->SetData( kControlNoPart, kControlDataBrowserIncludesFrameAndFocusTag, (Boolean)false );
533 m_peer->SetNeedsFocusRect( true );
534#endif
facd6764
SC
535}
536
6cce68ea 537wxMacDataBrowserListControl::~wxMacDataBrowserListControl()
facd6764 538{
facd6764
SC
539}
540
e2bc1d69 541wxWindow * wxMacDataBrowserListControl::GetPeer() const
6cce68ea 542{
e2bc1d69 543 return wxDynamicCast( wxMacControl::GetPeer() , wxWindow );
6cce68ea 544}
443e2f09 545
e6fd62dd
RD
546wxMacDataItem* wxMacDataBrowserListControl::CreateItem()
547{
548 return new wxMacListBoxItem();
549}
550
6cce68ea 551#if 0
443e2f09 552
6cce68ea 553// in case we need that one day
443e2f09 554
6cce68ea
SC
555// ============================================================================
556// HIView owner-draw-based implementation
557// ============================================================================
443e2f09 558
6cce68ea
SC
559static pascal void ListBoxDrawProc(
560 ControlRef browser, DataBrowserItemID item, DataBrowserPropertyID property,
561 DataBrowserItemState itemState, const Rect *itemRect, SInt16 depth, Boolean isColorDevice )
562{
563 CFStringRef cfString;
564 ThemeDrawingState themeState;
565 long systemVersion;
443e2f09 566
6cce68ea
SC
567 GetThemeDrawingState( &themeState );
568 cfString = CFStringCreateWithFormat( NULL, NULL, CFSTR("Row %d"), item );
c00fed0e 569
6cce68ea
SC
570 // In this sample we handle the "selected" state; all others fall through to our "active" state
571 if ( itemState == kDataBrowserItemIsSelected )
c00fed0e 572 {
6cce68ea 573 ThemeBrush colorBrushID;
443e2f09 574
6cce68ea
SC
575 // TODO: switch over to wxSystemSettingsNative::GetColour() when kThemeBrushSecondaryHighlightColor
576 // is incorporated Panther DB starts using kThemeBrushSecondaryHighlightColor
577 // for inactive browser highlighting
03561a3c 578 if ( !IsControlActive( browser ) )
6cce68ea
SC
579 colorBrushID = kThemeBrushSecondaryHighlightColor;
580 else
581 colorBrushID = kThemeBrushPrimaryHighlightColor;
443e2f09 582
6cce68ea
SC
583 // First paint the hilite rect, then the text on top
584 SetThemePen( colorBrushID, 32, true );
585 PaintRect( itemRect );
586 SetThemeDrawingState( themeState, false );
c00fed0e 587 }
443e2f09 588
6cce68ea
SC
589 DrawThemeTextBox( cfString, kThemeApplicationFont, kThemeStateActive, true, itemRect, teFlushDefault, NULL );
590 SetThemeDrawingState( themeState, true );
591
592 if ( cfString != NULL )
593 CFRelease( cfString );
c00fed0e
VZ
594}
595
179e085f 596#endif
6cce68ea
SC
597
598
987e9419 599#endif // wxUSE_LISTBOX