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