]> git.saurik.com Git - wxWidgets.git/blame - src/mac/carbon/listbox.cpp
no real changes, just some cleanup: add wxIsAltDown() in addition to the existing...
[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 // get column property ID (req. for call to itempartbounds)
330 DataBrowserTableViewColumnID colId = 0;
331 err = GetDataBrowserTableViewColumnProperty(m_peer->GetControlRef(), 0, &colId);
332 wxCHECK_MSG(err == noErr, wxNOT_FOUND, wxT("Unexpected error from GetDataBrowserTableViewColumnProperty"));
b4726a58 333
6cce68ea
SC
334 // OK, first we need to find the first visible item we have -
335 // this will be the "low" for our binary search. There is no real
336 // easy way around this, as we will need to do a SLOW linear search
337 // until we find a visible item, but we can do a cheap calculation
338 // via the row height to speed things up a bit
339 UInt32 scrollx, scrolly;
340 err = GetDataBrowserScrollPosition(m_peer->GetControlRef(), &scrollx, &scrolly);
341 wxCHECK_MSG(err == noErr, wxNOT_FOUND, wxT("Unexpected error from GetDataBrowserScrollPosition"));
b4726a58 342
6cce68ea
SC
343 UInt16 height;
344 err = GetDataBrowserTableViewRowHeight(m_peer->GetControlRef(), &height);
345 wxCHECK_MSG(err == noErr, wxNOT_FOUND, wxT("Unexpected error from GetDataBrowserTableViewRowHeight"));
b4726a58 346
6cce68ea
SC
347 // these indices are 0-based, as usual, so we need to add 1 to them when
348 // passing them to data browser functions which use 1-based indices
349 int low = scrolly / height,
350 high = GetCount() - 1;
b4726a58 351
6cce68ea
SC
352 // search for the first visible item (note that the scroll guess above
353 // is the low bounds of where the item might lie so we only use that as a
354 // starting point - we should reach it within 1 or 2 iterations of the loop)
355 while ( low <= high )
356 {
357 Rect bounds;
358 err = GetDataBrowserItemPartBounds(
359 m_peer->GetControlRef(), low + 1, colId,
360 kDataBrowserPropertyEnclosingPart,
361 &bounds); // note +1 to translate to Mac ID
362 if ( err == noErr )
363 break;
b4726a58 364
6cce68ea
SC
365 // errDataBrowserItemNotFound is expected as it simply means that the
366 // item is not currently visible -- but other errors are not
367 wxCHECK_MSG( err == errDataBrowserItemNotFound, wxNOT_FOUND,
368 wxT("Unexpected error from GetDataBrowserItemPartBounds") );
789ae0cf 369
6cce68ea
SC
370 low++;
371 }
de1b0aeb 372
6cce68ea
SC
373 // NOW do a binary search for where the item lies, searching low again if
374 // we hit an item that isn't visible
375 while ( low <= high )
789ae0cf 376 {
6cce68ea 377 int mid = (low + high) / 2;
fdd4e6cc 378
6cce68ea
SC
379 Rect bounds;
380 err = GetDataBrowserItemPartBounds(
381 m_peer->GetControlRef(), mid + 1, colId,
382 kDataBrowserPropertyEnclosingPart,
383 &bounds); //note +1 to trans to mac id
384 wxCHECK_MSG( err == noErr || err == errDataBrowserItemNotFound,
385 wxNOT_FOUND,
386 wxT("Unexpected error from GetDataBrowserItemPartBounds") );
789ae0cf 387
6cce68ea
SC
388 if ( err == errDataBrowserItemNotFound )
389 {
390 // item not visible, attempt to find a visible one
391 // search lower
392 high = mid - 1;
393 }
394 else // visible item, do actual hitttest
395 {
396 // if point is within the bounds, return this item (since we assume
397 // all x coords of items are equal we only test the x coord in
398 // equality)
399 if ((point.x >= bounds.left && point.x <= bounds.right) &&
400 (point.y >= bounds.top && point.y <= bounds.bottom) )
401 {
402 // found!
403 return mid;
404 }
fdd4e6cc 405
6cce68ea
SC
406 if ( point.y < bounds.top )
407 // index(bounds) greater then key(point)
408 high = mid - 1;
409 else
410 // index(bounds) less then key(point)
411 low = mid + 1;
412 }
413 }
fdd4e6cc 414
6cce68ea 415 return wxNOT_FOUND;
789ae0cf 416}
b4726a58 417
b4726a58 418// ============================================================================
6cce68ea 419// data browser based implementation
b4726a58 420// ============================================================================
fe3dc505 421
6cce68ea 422wxMacListBoxItem::wxMacListBoxItem()
e2bc1d69 423 :wxMacDataItem()
fe3dc505 424{
fe3dc505
SC
425}
426
6cce68ea 427wxMacListBoxItem::~wxMacListBoxItem()
fe3dc505 428{
fe3dc505
SC
429}
430
ad9835c9 431void wxMacListBoxItem::Notification(wxMacDataItemBrowserControl *owner ,
6cce68ea 432 DataBrowserItemNotification message,
89954433 433 DataBrowserItemDataRef WXUNUSED(itemData) ) const
6cce68ea 434{
bf9a1615 435 wxMacDataBrowserListControl *lb = wxDynamicCast(owner,wxMacDataBrowserListControl);
b4726a58 436
6cce68ea 437 // we want to depend on as little as possible to make sure tear-down of controls is safe
ad9835c9 438
6cce68ea
SC
439 if ( message == kDataBrowserItemRemoved)
440 {
441 if ( lb != NULL && lb->GetClientDataType() == wxClientData_Object )
cee24bf7 442 {
6cce68ea 443 delete (wxClientData*) (m_data);
b4726a58 444 }
6cce68ea
SC
445
446 delete this;
447 return;
b4726a58 448 }
ad9835c9 449
6cce68ea
SC
450 wxListBox *list = wxDynamicCast( owner->GetPeer() , wxListBox );
451 wxCHECK_RET( list != NULL , wxT("Listbox expected"));
facd6764 452
6cce68ea
SC
453 bool trigger = false;
454 wxCommandEvent event( wxEVT_COMMAND_LISTBOX_SELECTED, list->GetId() );
455 switch (message)
facd6764 456 {
6cce68ea
SC
457 case kDataBrowserItemDeselected:
458 if ( list->HasMultipleSelection() )
459 trigger = !lb->IsSelectionSuppressed();
460 break;
fdd4e6cc 461
6cce68ea
SC
462 case kDataBrowserItemSelected:
463 trigger = !lb->IsSelectionSuppressed();
464 break;
facd6764 465
6cce68ea
SC
466 case kDataBrowserItemDoubleClicked:
467 event.SetEventType( wxEVT_COMMAND_LISTBOX_DOUBLECLICKED );
468 trigger = true;
469 break;
facd6764 470
6cce68ea
SC
471 default:
472 break;
473 }
c6179a84 474
6cce68ea
SC
475 if ( trigger )
476 {
477 event.SetEventObject( list );
478 if ( list->HasClientObjectData() )
479 event.SetClientObject( (wxClientData*) m_data );
480 else if ( list->HasClientUntypedData() )
481 event.SetClientData( m_data );
482 event.SetString( m_label );
483 event.SetInt( owner->GetLineFromItem( this ) );
484 event.SetExtraLong( list->HasMultipleSelection() ? message == kDataBrowserItemSelected : true );
6cce68ea 485
e6fd62dd
RD
486 // direct notification is not always having the listbox GetSelection()
487 // having in synch with event, so use wxPostEvent instead
6cce68ea 488 // list->GetEventHandler()->ProcessEvent(event);
e6fd62dd
RD
489
490 wxPostEvent( list->GetEventHandler(), event );
6cce68ea 491 }
facd6764
SC
492}
493
bf9a1615
SC
494IMPLEMENT_DYNAMIC_CLASS( wxMacDataBrowserListControl , wxMacDataItemBrowserControl )
495
e2bc1d69 496wxMacDataBrowserListControl::wxMacDataBrowserListControl( wxWindow *peer, const wxPoint& pos, const wxSize& size, long style)
6cce68ea 497 : wxMacDataItemBrowserControl( peer, pos, size, style )
facd6764 498{
6cce68ea
SC
499 OSStatus err = noErr;
500 m_clientDataItemsType = wxClientData_None;
e2bc1d69
KO
501 if ( style & wxLB_SORT )
502 m_sortOrder = SortOrder_Text_Ascending;
ad9835c9 503
6cce68ea
SC
504 DataBrowserSelectionFlags options = kDataBrowserDragSelect;
505 if ( style & wxLB_MULTIPLE )
506 {
507 options |= kDataBrowserAlwaysExtendSelection | kDataBrowserCmdTogglesSelection;
508 }
509 else if ( style & wxLB_EXTENDED )
510 {
464b15e1 511 options |= kDataBrowserCmdTogglesSelection;
6cce68ea
SC
512 }
513 else
514 {
515 options |= kDataBrowserSelectOnlyOne;
516 }
517 err = SetSelectionFlags( options );
518 verify_noerr( err );
ad9835c9 519
6cce68ea
SC
520 DataBrowserListViewColumnDesc columnDesc;
521 columnDesc.headerBtnDesc.titleOffset = 0;
522 columnDesc.headerBtnDesc.version = kDataBrowserListViewLatestHeaderDesc;
facd6764 523
6cce68ea
SC
524 columnDesc.headerBtnDesc.btnFontStyle.flags =
525 kControlUseFontMask | kControlUseJustMask;
8228b893 526
6cce68ea
SC
527 columnDesc.headerBtnDesc.btnContentInfo.contentType = kControlNoContent;
528 columnDesc.headerBtnDesc.btnFontStyle.just = teFlushDefault;
529 columnDesc.headerBtnDesc.btnFontStyle.font = kControlFontViewSystemFont;
530 columnDesc.headerBtnDesc.btnFontStyle.style = normal;
531 columnDesc.headerBtnDesc.titleString = NULL;
c6179a84 532
6cce68ea
SC
533 columnDesc.headerBtnDesc.minimumWidth = 0;
534 columnDesc.headerBtnDesc.maximumWidth = 10000;
facd6764 535
6cce68ea
SC
536 columnDesc.propertyDesc.propertyID = kTextColumnId;
537 columnDesc.propertyDesc.propertyType = kDataBrowserTextType;
538 columnDesc.propertyDesc.propertyFlags = kDataBrowserTableViewSelectionColumn;
6cce68ea 539 columnDesc.propertyDesc.propertyFlags |= kDataBrowserListViewTypeSelectColumn;
facd6764 540
6cce68ea 541 verify_noerr( AddColumn( &columnDesc, kDataBrowserListViewAppendColumn ) );
c6179a84 542
6cce68ea
SC
543 columnDesc.headerBtnDesc.minimumWidth = 0;
544 columnDesc.headerBtnDesc.maximumWidth = 0;
545 columnDesc.propertyDesc.propertyID = kNumericOrderColumnId;
546 columnDesc.propertyDesc.propertyType = kDataBrowserPropertyRelevanceRankPart;
547 columnDesc.propertyDesc.propertyFlags = kDataBrowserTableViewSelectionColumn;
6cce68ea 548 columnDesc.propertyDesc.propertyFlags |= kDataBrowserListViewTypeSelectColumn;
cee24bf7 549
6cce68ea 550 verify_noerr( AddColumn( &columnDesc, kDataBrowserListViewAppendColumn ) );
c6179a84 551
6cce68ea 552 SetDataBrowserSortProperty( m_controlRef , kTextColumnId);
e2bc1d69 553 if ( m_sortOrder == SortOrder_Text_Ascending )
6cce68ea
SC
554 {
555 SetDataBrowserSortProperty( m_controlRef , kTextColumnId);
556 SetDataBrowserSortOrder( m_controlRef , kDataBrowserOrderIncreasing);
557 }
facd6764 558 else
6cce68ea
SC
559 {
560 SetDataBrowserSortProperty( m_controlRef , kNumericOrderColumnId);
561 SetDataBrowserSortOrder( m_controlRef , kDataBrowserOrderIncreasing);
562 }
facd6764 563
6cce68ea
SC
564 verify_noerr( AutoSizeColumns() );
565 verify_noerr( SetHiliteStyle(kDataBrowserTableViewFillHilite ) );
566 verify_noerr( SetHeaderButtonHeight( 0 ) );
567 err = SetHasScrollBars( (style & wxHSCROLL) != 0 , true );
568#if 0
569 // shouldn't be necessary anymore under 10.2
570 m_peer->SetData( kControlNoPart, kControlDataBrowserIncludesFrameAndFocusTag, (Boolean)false );
571 m_peer->SetNeedsFocusRect( true );
572#endif
facd6764
SC
573}
574
6cce68ea 575wxMacDataBrowserListControl::~wxMacDataBrowserListControl()
facd6764 576{
facd6764
SC
577}
578
e2bc1d69 579wxWindow * wxMacDataBrowserListControl::GetPeer() const
6cce68ea 580{
e2bc1d69 581 return wxDynamicCast( wxMacControl::GetPeer() , wxWindow );
6cce68ea 582}
443e2f09 583
e6fd62dd
RD
584wxMacDataItem* wxMacDataBrowserListControl::CreateItem()
585{
586 return new wxMacListBoxItem();
587}
588
6cce68ea 589#if 0
443e2f09 590
6cce68ea 591// in case we need that one day
443e2f09 592
6cce68ea
SC
593// ============================================================================
594// HIView owner-draw-based implementation
595// ============================================================================
443e2f09 596
6cce68ea
SC
597static pascal void ListBoxDrawProc(
598 ControlRef browser, DataBrowserItemID item, DataBrowserPropertyID property,
599 DataBrowserItemState itemState, const Rect *itemRect, SInt16 depth, Boolean isColorDevice )
600{
601 CFStringRef cfString;
602 ThemeDrawingState themeState;
603 long systemVersion;
443e2f09 604
6cce68ea
SC
605 GetThemeDrawingState( &themeState );
606 cfString = CFStringCreateWithFormat( NULL, NULL, CFSTR("Row %d"), item );
c00fed0e 607
6cce68ea
SC
608 // In this sample we handle the "selected" state; all others fall through to our "active" state
609 if ( itemState == kDataBrowserItemIsSelected )
c00fed0e 610 {
6cce68ea 611 ThemeBrush colorBrushID;
443e2f09 612
6cce68ea
SC
613 // TODO: switch over to wxSystemSettingsNative::GetColour() when kThemeBrushSecondaryHighlightColor
614 // is incorporated Panther DB starts using kThemeBrushSecondaryHighlightColor
615 // for inactive browser highlighting
616 Gestalt( gestaltSystemVersion, &systemVersion );
617 if ( (systemVersion >= 0x00001030) && !IsControlActive( browser ) )
618 colorBrushID = kThemeBrushSecondaryHighlightColor;
619 else
620 colorBrushID = kThemeBrushPrimaryHighlightColor;
443e2f09 621
6cce68ea
SC
622 // First paint the hilite rect, then the text on top
623 SetThemePen( colorBrushID, 32, true );
624 PaintRect( itemRect );
625 SetThemeDrawingState( themeState, false );
c00fed0e 626 }
443e2f09 627
6cce68ea
SC
628 DrawThemeTextBox( cfString, kThemeApplicationFont, kThemeStateActive, true, itemRect, teFlushDefault, NULL );
629 SetThemeDrawingState( themeState, true );
630
631 if ( cfString != NULL )
632 CFRelease( cfString );
c00fed0e
VZ
633}
634
179e085f 635#endif
6cce68ea
SC
636
637
987e9419 638#endif // wxUSE_LISTBOX