]> git.saurik.com Git - wxWidgets.git/blame - src/osx/carbon/listbox.cpp
Store HTML "id" parameter value in wxHtmlCell.
[wxWidgets.git] / src / osx / carbon / listbox.cpp
CommitLineData
489468fe 1///////////////////////////////////////////////////////////////////////////////
524c47aa 2// Name: src/osx/carbon/listbox.cpp
489468fe
SC
3// Purpose: wxListBox
4// Author: Stefan Csomor
5// Modified by:
6// Created: 1998-01-01
489468fe
SC
7// Copyright: (c) Stefan Csomor
8// Licence: wxWindows licence
9///////////////////////////////////////////////////////////////////////////////
10
11#include "wx/wxprec.h"
12
13#if wxUSE_LISTBOX
14
15#include "wx/listbox.h"
16
17#ifndef WX_PRECOMP
18 #include "wx/log.h"
19 #include "wx/intl.h"
20 #include "wx/utils.h"
21 #include "wx/settings.h"
22 #include "wx/arrstr.h"
23 #include "wx/dcclient.h"
24#endif
25
524c47aa 26#include "wx/osx/private.h"
489468fe
SC
27
28// ============================================================================
29// list box control implementation
30// ============================================================================
31
03647350
VZ
32wxWidgetImplType* wxWidgetImpl::CreateListBox( wxWindowMac* wxpeer,
33 wxWindowMac* WXUNUSED(parent),
34 wxWindowID WXUNUSED(id),
35 const wxPoint& pos,
524c47aa 36 const wxSize& size,
03647350 37 long style,
a4fec5b4 38 long WXUNUSED(extraStyle))
489468fe 39{
524c47aa 40 wxMacDataBrowserListControl* control = new wxMacDataBrowserListControl( wxpeer, pos, size, style );
489468fe 41 // TODO CHECK control->SetClientDataType( m_clientDataItemsType );
524c47aa 42 return control;
489468fe
SC
43}
44
20196e15 45int wxMacDataBrowserListControl::DoListHitTest(const wxPoint& inpoint) const
489468fe
SC
46{
47 OSStatus err;
48
49 // There are few reasons why this is complicated:
50 // 1) There is no native HitTest function for Mac
51 // 2) GetDataBrowserItemPartBounds only works on visible items
52 // 3) We can't do it through GetDataBrowserTableView[Item]RowHeight
53 // because what it returns is basically inaccurate in the context
54 // of the coordinates we want here, but we use this as a guess
55 // for where the first visible item lies
56
57 wxPoint point = inpoint;
58
59 // get column property ID (req. for call to itempartbounds)
60 DataBrowserTableViewColumnID colId = 0;
20196e15 61 err = GetDataBrowserTableViewColumnProperty(GetControlRef(), 0, &colId);
489468fe
SC
62 wxCHECK_MSG(err == noErr, wxNOT_FOUND, wxT("Unexpected error from GetDataBrowserTableViewColumnProperty"));
63
64 // OK, first we need to find the first visible item we have -
65 // this will be the "low" for our binary search. There is no real
66 // easy way around this, as we will need to do a SLOW linear search
67 // until we find a visible item, but we can do a cheap calculation
68 // via the row height to speed things up a bit
69 UInt32 scrollx, scrolly;
20196e15 70 err = GetDataBrowserScrollPosition(GetControlRef(), &scrollx, &scrolly);
489468fe
SC
71 wxCHECK_MSG(err == noErr, wxNOT_FOUND, wxT("Unexpected error from GetDataBrowserScrollPosition"));
72
73 UInt16 height;
20196e15 74 err = GetDataBrowserTableViewRowHeight(GetControlRef(), &height);
489468fe
SC
75 wxCHECK_MSG(err == noErr, wxNOT_FOUND, wxT("Unexpected error from GetDataBrowserTableViewRowHeight"));
76
20196e15
SC
77 wxListBox *list = wxDynamicCast( GetWXPeer() , wxListBox );
78
489468fe
SC
79 // these indices are 0-based, as usual, so we need to add 1 to them when
80 // passing them to data browser functions which use 1-based indices
81 int low = scrolly / height,
20196e15 82 high = list->GetCount() - 1;
489468fe
SC
83
84 // search for the first visible item (note that the scroll guess above
85 // is the low bounds of where the item might lie so we only use that as a
86 // starting point - we should reach it within 1 or 2 iterations of the loop)
87 while ( low <= high )
88 {
89 Rect bounds;
90 err = GetDataBrowserItemPartBounds(
20196e15 91 GetControlRef(), low + 1, colId,
489468fe
SC
92 kDataBrowserPropertyEnclosingPart,
93 &bounds); // note +1 to translate to Mac ID
94 if ( err == noErr )
95 break;
96
97 // errDataBrowserItemNotFound is expected as it simply means that the
98 // item is not currently visible -- but other errors are not
99 wxCHECK_MSG( err == errDataBrowserItemNotFound, wxNOT_FOUND,
100 wxT("Unexpected error from GetDataBrowserItemPartBounds") );
101
102 low++;
103 }
104
105 // NOW do a binary search for where the item lies, searching low again if
106 // we hit an item that isn't visible
107 while ( low <= high )
108 {
109 int mid = (low + high) / 2;
110
111 Rect bounds;
112 err = GetDataBrowserItemPartBounds(
20196e15 113 GetControlRef(), mid + 1, colId,
489468fe
SC
114 kDataBrowserPropertyEnclosingPart,
115 &bounds); //note +1 to trans to mac id
116 wxCHECK_MSG( err == noErr || err == errDataBrowserItemNotFound,
117 wxNOT_FOUND,
118 wxT("Unexpected error from GetDataBrowserItemPartBounds") );
119
120 if ( err == errDataBrowserItemNotFound )
121 {
122 // item not visible, attempt to find a visible one
123 // search lower
124 high = mid - 1;
125 }
126 else // visible item, do actual hitttest
127 {
128 // if point is within the bounds, return this item (since we assume
129 // all x coords of items are equal we only test the x coord in
130 // equality)
131 if ((point.x >= bounds.left && point.x <= bounds.right) &&
132 (point.y >= bounds.top && point.y <= bounds.bottom) )
133 {
134 // found!
135 return mid;
136 }
137
138 if ( point.y < bounds.top )
d13b34d3 139 // index(bounds) greater than key(point)
489468fe
SC
140 high = mid - 1;
141 else
4c51a665 142 // index(bounds) less than key(point)
489468fe
SC
143 low = mid + 1;
144 }
145 }
146
147 return wxNOT_FOUND;
148}
149
150// ============================================================================
151// data browser based implementation
152// ============================================================================
153
154wxMacListBoxItem::wxMacListBoxItem()
155 :wxMacDataItem()
156{
157}
158
159wxMacListBoxItem::~wxMacListBoxItem()
160{
161}
162
524c47aa
SC
163OSStatus wxMacListBoxItem::GetSetData(wxMacDataItemBrowserControl *owner ,
164 DataBrowserPropertyID property,
165 DataBrowserItemDataRef itemData,
166 bool changeValue )
167{
168 wxMacDataBrowserListControl *lb = wxDynamicCast(owner,wxMacDataBrowserListControl);
169 OSStatus err = errDataBrowserPropertyNotSupported;
170 if ( !changeValue )
171 {
172 if ( property >= kMinColumnId )
173 {
174 wxMacDataBrowserColumn* col = lb->GetColumnFromProperty( property );
175 unsigned int n = owner->GetLineFromItem( this );
176 wxListBox *list = wxDynamicCast( owner->GetWXPeer() , wxListBox );
177 wxMacDataBrowserCellValue valueholder(itemData);
178 list->GetValueCallback( n , col, valueholder );
03647350 179
524c47aa
SC
180 err = noErr;
181 }
182 else
183 {
184 if ( property == kDataBrowserItemIsEditableProperty )
185 {
186 DataBrowserPropertyID propertyToEdit ;
187 GetDataBrowserItemDataProperty( itemData, &propertyToEdit );
188 wxMacDataBrowserColumn* col = lb->GetColumnFromProperty( propertyToEdit );
189
190 verify_noerr(SetDataBrowserItemDataBooleanValue( itemData, col->IsEditable() ));
191 err = noErr;
192 }
193
194 }
03647350 195
524c47aa
SC
196 }
197 else
198 {
199 if ( property >= kMinColumnId )
200 {
201 wxMacDataBrowserColumn* col = lb->GetColumnFromProperty( property );
202
203 unsigned int n = owner->GetLineFromItem( this );
204 wxListBox *list = wxDynamicCast( owner->GetWXPeer() , wxListBox );
205 wxMacDataBrowserCellValue valueholder(itemData);
206 list->SetValueCallback( n , col, valueholder );
207
208 /*
209 // we have to change this behind the back, since Check() would be triggering another update round
210 bool newVal = !m_isChecked;
211 verify_noerr(SetDataBrowserItemDataButtonValue( itemData, newVal ? kThemeButtonOn : kThemeButtonOff ));
212 m_isChecked = newVal;
213 err = noErr;
214
ce7fe42e 215 wxCommandEvent event( wxEVT_CHECKLISTBOX, checklist->GetId() );
524c47aa
SC
216 event.SetInt( owner->GetLineFromItem( this ) );
217 event.SetEventObject( checklist );
218 checklist->HandleWindowEvent( event );
219
220 */
221 err = noErr;
222 }
223 }
224
225 // call inherited if not ours
226 if ( err == errDataBrowserPropertyNotSupported )
227 {
228 err = wxMacDataItem::GetSetData(owner, property, itemData, changeValue);
229 }
03647350 230
524c47aa
SC
231 return err;
232}
233
489468fe
SC
234void wxMacListBoxItem::Notification(wxMacDataItemBrowserControl *owner ,
235 DataBrowserItemNotification message,
236 DataBrowserItemDataRef WXUNUSED(itemData) ) const
237{
238 wxMacDataBrowserListControl *lb = wxDynamicCast(owner,wxMacDataBrowserListControl);
239
240 // we want to depend on as little as possible to make sure tear-down of controls is safe
241
242 if ( message == kDataBrowserItemRemoved)
243 {
489468fe
SC
244 delete this;
245 return;
246 }
247
524c47aa 248 wxListBox *list = wxDynamicCast( lb->GetWXPeer() , wxListBox );
489468fe
SC
249 wxCHECK_RET( list != NULL , wxT("Listbox expected"));
250
251 if (message == kDataBrowserItemDoubleClicked)
252 {
524c47aa 253 unsigned int n = owner->GetLineFromItem( this );
21267321 254 list->HandleLineEvent( n, true );
489468fe
SC
255 return;
256 }
257}
258
259IMPLEMENT_DYNAMIC_CLASS( wxMacDataBrowserListControl , wxMacDataItemBrowserControl )
260
261wxMacDataBrowserListControl::wxMacDataBrowserListControl( wxWindow *peer, const wxPoint& pos, const wxSize& size, long style)
262 : wxMacDataItemBrowserControl( peer, pos, size, style )
263{
524c47aa 264 m_nextColumnId = 0 ;
03647350 265
489468fe
SC
266 OSStatus err = noErr;
267 m_clientDataItemsType = wxClientData_None;
268 if ( style & wxLB_SORT )
269 m_sortOrder = SortOrder_Text_Ascending;
270
271 DataBrowserSelectionFlags options = kDataBrowserDragSelect;
272 if ( style & wxLB_MULTIPLE )
273 {
274 options |= kDataBrowserAlwaysExtendSelection | kDataBrowserCmdTogglesSelection;
275 }
276 else if ( style & wxLB_EXTENDED )
277 {
278 options |= kDataBrowserCmdTogglesSelection;
279 }
280 else
281 {
282 options |= kDataBrowserSelectOnlyOne;
283 }
284 err = SetSelectionFlags( options );
285 verify_noerr( err );
286
287 DataBrowserListViewColumnDesc columnDesc;
288 columnDesc.headerBtnDesc.titleOffset = 0;
289 columnDesc.headerBtnDesc.version = kDataBrowserListViewLatestHeaderDesc;
290
291 columnDesc.headerBtnDesc.btnFontStyle.flags =
292 kControlUseFontMask | kControlUseJustMask;
293
294 columnDesc.headerBtnDesc.btnContentInfo.contentType = kControlNoContent;
295 columnDesc.headerBtnDesc.btnFontStyle.just = teFlushDefault;
296 columnDesc.headerBtnDesc.btnFontStyle.font = kControlFontViewSystemFont;
297 columnDesc.headerBtnDesc.btnFontStyle.style = normal;
298 columnDesc.headerBtnDesc.titleString = NULL;
524c47aa 299/*
489468fe
SC
300 columnDesc.headerBtnDesc.minimumWidth = 0;
301 columnDesc.headerBtnDesc.maximumWidth = 10000;
302
303 columnDesc.propertyDesc.propertyID = kTextColumnId;
304 columnDesc.propertyDesc.propertyType = kDataBrowserTextType;
305 columnDesc.propertyDesc.propertyFlags = kDataBrowserTableViewSelectionColumn;
306 columnDesc.propertyDesc.propertyFlags |= kDataBrowserListViewTypeSelectColumn;
307
308 verify_noerr( AddColumn( &columnDesc, kDataBrowserListViewAppendColumn ) );
524c47aa 309*/
489468fe
SC
310 columnDesc.headerBtnDesc.minimumWidth = 0;
311 columnDesc.headerBtnDesc.maximumWidth = 0;
312 columnDesc.propertyDesc.propertyID = kNumericOrderColumnId;
313 columnDesc.propertyDesc.propertyType = kDataBrowserPropertyRelevanceRankPart;
314 columnDesc.propertyDesc.propertyFlags = kDataBrowserTableViewSelectionColumn;
315 columnDesc.propertyDesc.propertyFlags |= kDataBrowserListViewTypeSelectColumn;
316
317 verify_noerr( AddColumn( &columnDesc, kDataBrowserListViewAppendColumn ) );
318
524c47aa 319/*
489468fe
SC
320 SetDataBrowserSortProperty( m_controlRef , kTextColumnId);
321 if ( m_sortOrder == SortOrder_Text_Ascending )
322 {
323 SetDataBrowserSortProperty( m_controlRef , kTextColumnId);
324 SetDataBrowserSortOrder( m_controlRef , kDataBrowserOrderIncreasing);
325 }
326 else
524c47aa 327*/
489468fe
SC
328 {
329 SetDataBrowserSortProperty( m_controlRef , kNumericOrderColumnId);
330 SetDataBrowserSortOrder( m_controlRef , kDataBrowserOrderIncreasing);
331 }
332
333 verify_noerr( AutoSizeColumns() );
334 verify_noerr( SetHiliteStyle(kDataBrowserTableViewFillHilite ) );
335 verify_noerr( SetHeaderButtonHeight( 0 ) );
336 err = SetHasScrollBars( (style & wxHSCROLL) != 0 , true );
337#if 0
338 // shouldn't be necessary anymore under 10.2
22756322
SC
339 GetPeer()->SetData( kControlNoPart, kControlDataBrowserIncludesFrameAndFocusTag, (Boolean)false );
340 GetPeer()->SetNeedsFocusRect( true );
489468fe
SC
341#endif
342}
343
344wxMacDataBrowserListControl::~wxMacDataBrowserListControl()
345{
346}
347
348void wxMacDataBrowserListControl::ItemNotification(
0698ed3c 349 DataBrowserItemID itemID,
489468fe
SC
350 DataBrowserItemNotification message,
351 DataBrowserItemDataRef itemData)
352{
b2680ced 353 wxListBox *list = wxDynamicCast( GetWXPeer() , wxListBox );
489468fe 354 wxCHECK_RET( list != NULL , wxT("Listbox expected"));
03647350 355
489468fe
SC
356 if (list->HasMultipleSelection() && (message == kDataBrowserSelectionSetChanged) && (!list->MacGetBlockEvents()))
357 {
358 list->CalcAndSendEvent();
359 return;
360 }
361
362 if ((message == kDataBrowserSelectionSetChanged) && (!list->MacGetBlockEvents()))
363 {
ce7fe42e 364 wxCommandEvent event( wxEVT_LISTBOX, list->GetId() );
03647350 365
489468fe 366 int sel = list->GetSelection();
b2680ced 367 if ((sel < 0) || (sel > (int) list->GetCount())) // OS X can select an item below the last item (why?)
489468fe 368 return;
21267321 369 list->HandleLineEvent( sel, false );
489468fe
SC
370 return;
371 }
03647350 372
489468fe
SC
373 // call super for item level(wxMacDataItem->Notification) callback processing
374 wxMacDataItemBrowserControl::ItemNotification( itemID, message, itemData);
375}
524c47aa
SC
376
377
b2680ced 378/*
489468fe
SC
379wxWindow * wxMacDataBrowserListControl::GetPeer() const
380{
b2680ced 381 return wxDynamicCast( wxMacControl::GetWX() , wxWindow );
489468fe 382}
b2680ced 383*/
524c47aa
SC
384
385//
386// List Methods
387//
388
03647350 389wxMacDataBrowserColumn* wxMacDataBrowserListControl::DoInsertColumn( unsigned int pos, DataBrowserPropertyID property,
524c47aa
SC
390 const wxString& title, bool editable,
391 DataBrowserPropertyType colType, SInt16 just, int width )
392{
393 DataBrowserListViewColumnDesc columnDesc;
394 columnDesc.headerBtnDesc.titleOffset = 0;
395 columnDesc.headerBtnDesc.version = kDataBrowserListViewLatestHeaderDesc;
396
397 columnDesc.headerBtnDesc.btnFontStyle.flags =
398 kControlUseFontMask | kControlUseJustMask;
399
400 columnDesc.headerBtnDesc.btnContentInfo.contentType = kControlContentTextOnly;
401 columnDesc.headerBtnDesc.btnFontStyle.just = just;
402 columnDesc.headerBtnDesc.btnFontStyle.font = kControlFontViewSystemFont;
403 columnDesc.headerBtnDesc.btnFontStyle.style = normal;
404
405 // TODO: Why is m_font not defined when we enter wxLC_LIST mode, but is
406 // defined for other modes?
407 wxFontEncoding enc;
a1b806b9 408 if ( m_font.IsOk() )
524c47aa
SC
409 enc = m_font.GetEncoding();
410 else
411 enc = wxLocale::GetSystemEncoding();
412 wxCFStringRef cfTitle( title, enc );
413 columnDesc.headerBtnDesc.titleString = cfTitle;
414
415 columnDesc.headerBtnDesc.minimumWidth = 0;
416 columnDesc.headerBtnDesc.maximumWidth = 30000;
417
418 columnDesc.propertyDesc.propertyID = property;
419 columnDesc.propertyDesc.propertyType = colType;
420 columnDesc.propertyDesc.propertyFlags = kDataBrowserListViewSortableColumn;
421 columnDesc.propertyDesc.propertyFlags |= kDataBrowserListViewTypeSelectColumn;
422 columnDesc.propertyDesc.propertyFlags |= kDataBrowserListViewNoGapForIconInHeaderButton;
03647350 423
524c47aa
SC
424 if ( editable )
425 columnDesc.propertyDesc.propertyFlags |= kDataBrowserPropertyIsMutable;
426
427 verify_noerr( AddColumn( &columnDesc, pos ) );
428
429 if (width > 0)
430 {
431 wxMacDataBrowserControl::SetColumnWidth(property, width);
432 }
433
434 wxMacDataBrowserColumn *col = new wxMacDataBrowserColumn( property, colType, editable );
03647350 435
524c47aa 436 m_columns.Insert( col, pos );
03647350 437
524c47aa
SC
438 return col;
439}
440
03647350
VZ
441wxListWidgetColumn* wxMacDataBrowserListControl::InsertTextColumn( unsigned pos, const wxString& title, bool editable,
442 wxAlignment just, int defaultWidth)
524c47aa
SC
443{
444 DataBrowserPropertyID property = kMinColumnId + m_nextColumnId++;
03647350 445
524c47aa
SC
446 SInt16 j = teFlushLeft;
447 if ( just & wxALIGN_RIGHT )
448 j = teFlushRight;
449 else if ( just & wxALIGN_CENTER_HORIZONTAL )
450 j = teCenter;
03647350
VZ
451
452 return DoInsertColumn( pos, property, title, editable, kDataBrowserTextType, just, defaultWidth );
524c47aa
SC
453}
454
03647350
VZ
455wxListWidgetColumn* wxMacDataBrowserListControl::InsertCheckColumn( unsigned pos , const wxString& title, bool editable,
456 wxAlignment just, int defaultWidth )
524c47aa
SC
457{
458 DataBrowserPropertyID property = kMinColumnId + m_nextColumnId++;
03647350 459
524c47aa
SC
460 SInt16 j = teFlushLeft;
461 if ( just & wxALIGN_RIGHT )
462 j = teFlushRight;
463 else if ( just & wxALIGN_CENTER_HORIZONTAL )
464 j = teCenter;
03647350
VZ
465
466 return DoInsertColumn( pos, property, title, editable, kDataBrowserCheckboxType, just, defaultWidth );
524c47aa
SC
467}
468
469wxMacDataBrowserColumn* wxMacDataBrowserListControl::GetColumnFromProperty( DataBrowserPropertyID property)
470{
471 for ( unsigned int i = 0; i < m_columns.size() ; ++ i )
472 if ( m_columns[i]->GetProperty() == property )
473 return m_columns[i];
03647350 474
524c47aa
SC
475 return NULL;
476}
477
478/*
479wxMacDataItem* wxMacDataBrowserListControl::ListGetLineItem( unsigned int n )
480{
481 return (wxMacDataItem*) GetItemFromLine(n);
482}
483*/
484
485unsigned int wxMacDataBrowserListControl::ListGetCount() const
486{
487 return MacGetCount();
488}
489
490void wxMacDataBrowserListControl::ListDelete( unsigned int n )
491{
492 MacDelete( n );
493}
494
495void wxMacDataBrowserListControl::ListInsert( unsigned int n )
496{
497 MacInsert( n , new wxMacListBoxItem() );
498}
499
500void wxMacDataBrowserListControl::ListClear()
501{
502 MacClear();
503}
504
505void wxMacDataBrowserListControl::ListDeselectAll()
506{
507 wxMacDataItemBrowserSelectionSuppressor suppressor(this);
508 SetSelectedAllItems( kDataBrowserItemsRemove );
509}
510
511void wxMacDataBrowserListControl::ListSetSelection( unsigned int n, bool select, bool multi )
512{
513 wxMacDataItem* item = (wxMacDataItem*) GetItemFromLine(n);
514 wxMacDataItemBrowserSelectionSuppressor suppressor(this);
515
516 if ( IsItemSelected( item ) != select )
517 {
518 if ( select )
519 SetSelectedItem( item, multi ? kDataBrowserItemsAdd : kDataBrowserItemsAssign );
520 else
521 SetSelectedItem( item, kDataBrowserItemsRemove );
522 }
523
524 ListScrollTo( n );
525}
526
527bool wxMacDataBrowserListControl::ListIsSelected( unsigned int n ) const
528{
529 wxMacDataItem* item = (wxMacDataItem*) GetItemFromLine(n);
530 return IsItemSelected( item );
531}
532
533int wxMacDataBrowserListControl::ListGetSelection() const
534{
535 wxMacDataItemPtr first, last;
536 GetSelectionAnchor( &first, &last );
537
538 if ( first != NULL )
539 {
540 return GetLineFromItem( first );
541 }
542
543 return -1;
544}
545
546int wxMacDataBrowserListControl::ListGetSelections( wxArrayInt& aSelections ) const
547{
548 aSelections.Empty();
549 wxArrayMacDataItemPtr selectedItems;
550 GetItems( wxMacDataBrowserRootContainer, false , kDataBrowserItemIsSelected, selectedItems);
551
552 int count = selectedItems.GetCount();
553
554 for ( int i = 0; i < count; ++i)
555 {
556 aSelections.Add(GetLineFromItem(selectedItems[i]));
557 }
558
559 return count;
560}
561
562void wxMacDataBrowserListControl::ListScrollTo( unsigned int n )
563{
564 UInt32 top , left ;
565 GetScrollPosition( &top , &left ) ;
566 wxMacDataItem * item = (wxMacDataItem*) GetItemFromLine( n );
567
568 // there is a bug in RevealItem that leads to situations
569 // in large lists, where the item does not get scrolled
570 // into sight, so we do a pre-scroll if necessary
571 UInt16 height ;
572 GetRowHeight( (DataBrowserItemID) item , &height ) ;
573 UInt32 linetop = n * ((UInt32) height );
574 UInt32 linebottom = linetop + height;
575 Rect rect ;
576 GetControlBounds( m_controlRef, &rect );
577
578 if ( linetop < top || linebottom > (top + rect.bottom - rect.top ) )
579 SetScrollPosition( wxMax( n-2, 0 ) * ((UInt32)height) , left ) ;
580
581 RevealItem( item , kDataBrowserRevealWithoutSelecting );
582}
03647350
VZ
583
584void wxMacDataBrowserListControl::UpdateLine( unsigned int n, wxListWidgetColumn* col )
524c47aa
SC
585{
586 wxMacDataBrowserColumn* dbcol = dynamic_cast<wxMacDataBrowserColumn*> (col);
587 wxMacDataItem * item = (wxMacDataItem*) GetItemFromLine( n );
588 UpdateItem(wxMacDataBrowserRootContainer, item, dbcol ? dbcol->GetProperty() : kDataBrowserNoItem );
589}
590
03647350 591void wxMacDataBrowserListControl::UpdateLineToEnd( unsigned int n)
524c47aa
SC
592{
593 // with databrowser inserting does not need updating the entire model, it's done by databrowser itself
594 wxMacDataItem * item = (wxMacDataItem*) GetItemFromLine( n );
595 UpdateItem(wxMacDataBrowserRootContainer, item, kDataBrowserNoItem );
596}
597
598// value setters
599
600void wxMacDataBrowserCellValue::Set( CFStringRef value )
601{
602 SetDataBrowserItemDataText( m_data, value );
603}
604
605void wxMacDataBrowserCellValue::Set( const wxString& value )
606{
607 wxCFStringRef cf(value);
608 SetDataBrowserItemDataText( m_data, (CFStringRef) cf);
609}
610
03647350
VZ
611void wxMacDataBrowserCellValue::Set( int value )
612{
524c47aa 613 SetDataBrowserItemDataValue( m_data, value );
60ebcb8a
SC
614}
615
616void wxMacDataBrowserCellValue::Check( bool check )
617{
618 SetDataBrowserItemDataButtonValue( m_data, check ? kThemeButtonOn : kThemeButtonOff);
524c47aa 619}
03647350
VZ
620
621int wxMacDataBrowserCellValue::GetIntValue() const
524c47aa
SC
622{
623 SInt32 value;
624 GetDataBrowserItemDataValue( m_data, &value );
625 return value;
626}
627
03647350 628wxString wxMacDataBrowserCellValue::GetStringValue() const
489468fe 629{
524c47aa
SC
630 CFStringRef value;
631 GetDataBrowserItemDataText ( m_data, &value );
632 wxCFStringRef cf(value);
633 return cf.AsString();
489468fe
SC
634}
635
636#if 0
637
638// in case we need that one day
639
640// ============================================================================
641// HIView owner-draw-based implementation
642// ============================================================================
643
644static pascal void ListBoxDrawProc(
645 ControlRef browser, DataBrowserItemID item, DataBrowserPropertyID property,
646 DataBrowserItemState itemState, const Rect *itemRect, SInt16 depth, Boolean isColorDevice )
647{
648 CFStringRef cfString;
649 ThemeDrawingState themeState;
650 long systemVersion;
651
652 GetThemeDrawingState( &themeState );
653 cfString = CFStringCreateWithFormat( NULL, NULL, CFSTR("Row %d"), item );
654
655 // In this sample we handle the "selected" state; all others fall through to our "active" state
656 if ( itemState == kDataBrowserItemIsSelected )
657 {
658 ThemeBrush colorBrushID;
659
660 // TODO: switch over to wxSystemSettingsNative::GetColour() when kThemeBrushSecondaryHighlightColor
661 // is incorporated Panther DB starts using kThemeBrushSecondaryHighlightColor
662 // for inactive browser highlighting
663 if ( !IsControlActive( browser ) )
664 colorBrushID = kThemeBrushSecondaryHighlightColor;
665 else
666 colorBrushID = kThemeBrushPrimaryHighlightColor;
667
668 // First paint the hilite rect, then the text on top
669 SetThemePen( colorBrushID, 32, true );
670 PaintRect( itemRect );
671 SetThemeDrawingState( themeState, false );
672 }
673
674 DrawThemeTextBox( cfString, kThemeApplicationFont, kThemeStateActive, true, itemRect, teFlushDefault, NULL );
675 SetThemeDrawingState( themeState, true );
676
677 if ( cfString != NULL )
678 CFRelease( cfString );
679}
680
681#endif
682
683
684#endif // wxUSE_LISTBOX