]> git.saurik.com Git - wxWidgets.git/blob - src/mac/carbon/listctrl_mac.cpp
new renderer architecture
[wxWidgets.git] / src / mac / carbon / listctrl_mac.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/mac/listctrl_mac.cpp
3 // Purpose: wxListCtrl
4 // Author: Julian Smart
5 // Modified by: Agron Selimaj
6 // Created: 04/01/98
7 // RCS-ID: $Id$
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 // ============================================================================
13 // declarations
14 // ============================================================================
15
16 // ----------------------------------------------------------------------------
17 // headers
18 // ----------------------------------------------------------------------------
19
20 // For compilers that support precompilation, includes "wx.h".
21 #include "wx/wxprec.h"
22
23 #ifdef __BORLANDC__
24 #pragma hdrstop
25 #endif
26
27 #if wxUSE_LISTCTRL
28
29 #include "wx/listctrl.h"
30
31 #ifndef WX_PRECOMP
32 #include "wx/intl.h"
33 #endif
34
35 #include "wx/mac/uma.h"
36
37 #include "wx/imaglist.h"
38 #include "wx/sysopt.h"
39
40 #define wxMAC_ALWAYS_USE_GENERIC_LISTCTRL wxT("mac.listctrl.always_use_generic")
41
42 #if wxUSE_EXTENDED_RTTI
43 WX_DEFINE_FLAGS( wxListCtrlStyle )
44
45 wxBEGIN_FLAGS( wxListCtrlStyle )
46 // new style border flags, we put them first to
47 // use them for streaming out
48 wxFLAGS_MEMBER(wxBORDER_SIMPLE)
49 wxFLAGS_MEMBER(wxBORDER_SUNKEN)
50 wxFLAGS_MEMBER(wxBORDER_DOUBLE)
51 wxFLAGS_MEMBER(wxBORDER_RAISED)
52 wxFLAGS_MEMBER(wxBORDER_STATIC)
53 wxFLAGS_MEMBER(wxBORDER_NONE)
54
55 // old style border flags
56 wxFLAGS_MEMBER(wxSIMPLE_BORDER)
57 wxFLAGS_MEMBER(wxSUNKEN_BORDER)
58 wxFLAGS_MEMBER(wxDOUBLE_BORDER)
59 wxFLAGS_MEMBER(wxRAISED_BORDER)
60 wxFLAGS_MEMBER(wxSTATIC_BORDER)
61 wxFLAGS_MEMBER(wxBORDER)
62
63 // standard window styles
64 wxFLAGS_MEMBER(wxTAB_TRAVERSAL)
65 wxFLAGS_MEMBER(wxCLIP_CHILDREN)
66 wxFLAGS_MEMBER(wxTRANSPARENT_WINDOW)
67 wxFLAGS_MEMBER(wxWANTS_CHARS)
68 wxFLAGS_MEMBER(wxFULL_REPAINT_ON_RESIZE)
69 wxFLAGS_MEMBER(wxALWAYS_SHOW_SB )
70 wxFLAGS_MEMBER(wxVSCROLL)
71 wxFLAGS_MEMBER(wxHSCROLL)
72
73 wxFLAGS_MEMBER(wxLC_LIST)
74 wxFLAGS_MEMBER(wxLC_REPORT)
75 wxFLAGS_MEMBER(wxLC_ICON)
76 wxFLAGS_MEMBER(wxLC_SMALL_ICON)
77 wxFLAGS_MEMBER(wxLC_ALIGN_TOP)
78 wxFLAGS_MEMBER(wxLC_ALIGN_LEFT)
79 wxFLAGS_MEMBER(wxLC_AUTOARRANGE)
80 wxFLAGS_MEMBER(wxLC_USER_TEXT)
81 wxFLAGS_MEMBER(wxLC_EDIT_LABELS)
82 wxFLAGS_MEMBER(wxLC_NO_HEADER)
83 wxFLAGS_MEMBER(wxLC_SINGLE_SEL)
84 wxFLAGS_MEMBER(wxLC_SORT_ASCENDING)
85 wxFLAGS_MEMBER(wxLC_SORT_DESCENDING)
86 wxFLAGS_MEMBER(wxLC_VIRTUAL)
87
88 wxEND_FLAGS( wxListCtrlStyle )
89
90 IMPLEMENT_DYNAMIC_CLASS_XTI(wxListCtrl, wxControl,"wx/listctrl.h")
91
92 wxBEGIN_PROPERTIES_TABLE(wxListCtrl)
93 wxEVENT_PROPERTY( TextUpdated , wxEVT_COMMAND_TEXT_UPDATED , wxCommandEvent )
94
95 wxPROPERTY_FLAGS( WindowStyle , wxListCtrlStyle , long , SetWindowStyleFlag , GetWindowStyleFlag , EMPTY_MACROVALUE , 0 /*flags*/ , wxT("Helpstring") , wxT("group")) // style
96 wxEND_PROPERTIES_TABLE()
97
98 wxBEGIN_HANDLERS_TABLE(wxListCtrl)
99 wxEND_HANDLERS_TABLE()
100
101 wxCONSTRUCTOR_5( wxListCtrl , wxWindow* , Parent , wxWindowID , Id , wxPoint , Position , wxSize , Size , long , WindowStyle )
102
103 /*
104 TODO : Expose more information of a list's layout etc. via appropriate objects (à la NotebookPageInfo)
105 */
106 #else
107 IMPLEMENT_DYNAMIC_CLASS(wxListCtrl, wxControl)
108 #endif
109
110 IMPLEMENT_DYNAMIC_CLASS(wxListView, wxListCtrl)
111 IMPLEMENT_DYNAMIC_CLASS(wxListItem, wxObject)
112
113 IMPLEMENT_DYNAMIC_CLASS(wxListEvent, wxNotifyEvent)
114
115 WX_DECLARE_EXPORTED_LIST(wxListItem, wxListItemList);
116 #include "wx/listimpl.cpp"
117 WX_DEFINE_LIST(wxListItemList)
118 WX_DEFINE_LIST(wxColumnList)
119
120 // so we can check for column clicks
121 static const EventTypeSpec eventList[] =
122 {
123 { kEventClassControl, kEventControlHit },
124 { kEventClassControl, kEventControlDraw }
125 };
126
127 static pascal OSStatus wxMacListCtrlEventHandler( EventHandlerCallRef handler , EventRef event , void *data )
128 {
129 OSStatus result = eventNotHandledErr ;
130
131 wxMacCarbonEvent cEvent( event ) ;
132
133 ControlRef controlRef ;
134 cEvent.GetParameter( kEventParamDirectObject , &controlRef ) ;
135
136 wxListCtrl *window = (wxListCtrl*) data ;
137 wxListEvent le( wxEVT_COMMAND_LIST_COL_CLICK, window->GetId() );
138 le.SetEventObject( window );
139
140 switch ( GetEventKind( event ) )
141 {
142 // check if the column was clicked on and fire an event if so
143 case kEventControlHit :
144 {
145 ControlPartCode result = cEvent.GetParameter<ControlPartCode>(kEventParamControlPart, typeControlPartCode) ;
146 if (result == kControlButtonPart){
147 DataBrowserPropertyID col;
148 GetDataBrowserSortProperty(controlRef, &col);
149 int column = col - kMinColumnId;
150 le.m_col = column;
151 window->GetEventHandler()->ProcessEvent( le );
152 }
153 result = CallNextEventHandler(handler, event);
154 break;
155 }
156 case kEventControlDraw:
157 CGContextRef context = cEvent.GetParameter<CGContextRef>(kEventParamCGContextRef, typeCGContextRef) ;
158 window->MacSetDrawingContext(context);
159 result = CallNextEventHandler(handler, event);
160 window->MacSetDrawingContext(NULL);
161 default :
162 break ;
163 }
164
165
166 return result ;
167 }
168
169 DEFINE_ONE_SHOT_HANDLER_GETTER( wxMacListCtrlEventHandler )
170
171 class wxMacListCtrlItem : public wxMacListBoxItem
172 {
173 public:
174 wxMacListCtrlItem();
175
176 virtual void Notification(wxMacDataItemBrowserControl *owner ,
177 DataBrowserItemNotification message,
178 DataBrowserItemDataRef itemData ) const;
179
180 virtual void SetColumnInfo( unsigned int column, wxListItem* item );
181 virtual wxListItem* GetColumnInfo( unsigned int column );
182 virtual bool HasColumnInfo( unsigned int column );
183
184 virtual void SetColumnTextValue( unsigned int column, const wxString& text );
185 virtual const wxString& GetColumnTextValue( unsigned int column );
186
187 virtual int GetColumnImageValue( unsigned int column );
188 virtual void SetColumnImageValue( unsigned int column, int imageIndex );
189
190 virtual ~wxMacListCtrlItem();
191 protected:
192 wxListItemList m_rowItems;
193 };
194
195 DataBrowserDrawItemUPP gDataBrowserDrawItemUPP = NULL;
196 //DataBrowserEditItemUPP gDataBrowserEditItemUPP = NULL;
197 DataBrowserHitTestUPP gDataBrowserHitTestUPP = NULL;
198
199 // TODO: Make a better name!!
200 class wxMacDataBrowserListCtrlControl : public wxMacDataItemBrowserControl
201 {
202 public:
203 wxMacDataBrowserListCtrlControl( wxWindow *peer, const wxPoint& pos, const wxSize& size, long style );
204 virtual ~wxMacDataBrowserListCtrlControl();
205
206 // create a list item (can be a subclass of wxMacListBoxItem)
207
208 virtual wxMacDataItem* CreateItem();
209
210 virtual void MacInsertItem( unsigned int n, wxListItem* item );
211 virtual void MacSetColumnInfo( unsigned int row, unsigned int column, wxListItem* item );
212 virtual void MacGetColumnInfo( unsigned int row, unsigned int column, wxListItem& item );
213 virtual void UpdateState(wxMacDataItem* dataItem, wxListItem* item);
214
215 protected:
216 // we need to override to provide specialized handling for virtual wxListCtrls
217 virtual OSStatus GetSetItemData(DataBrowserItemID itemID,
218 DataBrowserPropertyID property,
219 DataBrowserItemDataRef itemData,
220 Boolean changeValue );
221
222 virtual void ItemNotification(
223 DataBrowserItemID itemID,
224 DataBrowserItemNotification message,
225 DataBrowserItemDataRef itemData);
226
227 virtual Boolean CompareItems(DataBrowserItemID itemOneID,
228 DataBrowserItemID itemTwoID,
229 DataBrowserPropertyID sortProperty);
230
231 static pascal void DataBrowserDrawItemProc(ControlRef browser,
232 DataBrowserItemID item,
233 DataBrowserPropertyID property,
234 DataBrowserItemState itemState,
235 const Rect *theRect,
236 SInt16 gdDepth,
237 Boolean colorDevice);
238
239 virtual void DrawItem(DataBrowserItemID itemID,
240 DataBrowserPropertyID property,
241 DataBrowserItemState itemState,
242 const Rect *itemRect,
243 SInt16 gdDepth,
244 Boolean colorDevice);
245
246 static pascal Boolean DataBrowserEditTextProc(ControlRef browser,
247 DataBrowserItemID item,
248 DataBrowserPropertyID property,
249 CFStringRef theString,
250 Rect *maxEditTextRect,
251 Boolean *shrinkToFit);
252
253 static pascal Boolean DataBrowserHitTestProc(ControlRef browser,
254 DataBrowserItemID itemID,
255 DataBrowserPropertyID property,
256 const Rect *theRect,
257 const Rect *mouseRect) { return true; }
258
259 virtual bool ConfirmEditText(DataBrowserItemID item,
260 DataBrowserPropertyID property,
261 CFStringRef theString,
262 Rect *maxEditTextRect,
263 Boolean *shrinkToFit);
264
265
266
267 wxClientDataType m_clientDataItemsType;
268 bool m_isVirtual;
269
270 };
271
272 class wxMacListCtrlEventDelegate : public wxEvtHandler
273 {
274 public:
275 wxMacListCtrlEventDelegate( wxListCtrl* list, int id );
276 virtual bool ProcessEvent( wxEvent& event );
277
278 private:
279 wxListCtrl* m_list;
280 int m_id;
281 };
282
283 wxMacListCtrlEventDelegate::wxMacListCtrlEventDelegate( wxListCtrl* list, int id )
284 {
285 m_list = list;
286 m_id = id;
287 }
288
289 bool wxMacListCtrlEventDelegate::ProcessEvent( wxEvent& event )
290 {
291 // even though we use a generic list ctrl underneath, make sure
292 // we present ourselves as wxListCtrl.
293 event.SetEventObject( m_list );
294 event.SetId( m_id );
295
296 return wxEvtHandler::ProcessEvent(event);
297 }
298
299 // ============================================================================
300 // implementation
301 // ============================================================================
302
303 wxMacListControl* wxListCtrl::GetPeer() const
304 {
305 return dynamic_cast<wxMacListControl*>(m_peer);
306 }
307
308 // ----------------------------------------------------------------------------
309 // wxListCtrl construction
310 // ----------------------------------------------------------------------------
311
312 void wxListCtrl::Init()
313 {
314 m_imageListNormal = NULL;
315 m_imageListSmall = NULL;
316 m_imageListState = NULL;
317
318 // keep track of if we created our own image lists, or if they were assigned
319 // to us.
320 m_ownsImageListNormal = m_ownsImageListSmall = m_ownsImageListState = false;
321 m_colCount = 0;
322 m_count = 0;
323 m_textCtrl = NULL;
324 m_genericImpl = NULL;
325 m_dbImpl = NULL;
326 m_compareFunc = NULL;
327 m_compareFuncData = 0;
328 m_colsInfo = wxColumnList();
329 m_textColor = wxNullColour;
330 m_bgColor = wxNullColour;
331 }
332
333 class wxGenericListCtrlHook : public wxGenericListCtrl
334 {
335 public:
336 wxGenericListCtrlHook(wxListCtrl* parent,
337 wxWindowID id,
338 const wxPoint& pos,
339 const wxSize& size,
340 long style,
341 const wxValidator& validator,
342 const wxString& name)
343 : wxGenericListCtrl(parent, id, pos, size, style, validator, name),
344 m_nativeListCtrl(parent)
345 {
346 }
347
348 protected:
349 virtual wxListItemAttr * OnGetItemAttr(long item) const
350 {
351 return m_nativeListCtrl->OnGetItemAttr(item);
352 }
353
354 virtual int OnGetItemImage(long item) const
355 {
356 return m_nativeListCtrl->OnGetItemImage(item);
357 }
358
359 virtual int OnGetItemColumnImage(long item, long column) const
360 {
361 return m_nativeListCtrl->OnGetItemColumnImage(item, column);
362 }
363
364 virtual wxString OnGetItemText(long item, long column) const
365 {
366 return m_nativeListCtrl->OnGetItemText(item, column);
367 }
368
369 wxListCtrl* m_nativeListCtrl;
370
371 };
372
373 bool wxListCtrl::Create(wxWindow *parent,
374 wxWindowID id,
375 const wxPoint& pos,
376 const wxSize& size,
377 long style,
378 const wxValidator& validator,
379 const wxString& name)
380 {
381
382 // for now, we'll always use the generic list control for ICON and LIST views,
383 // because they dynamically change the number of columns on resize.
384 // Also, allow the user to set it to use the list ctrl as well.
385 // Also, use generic list control in VIRTUAL mode.
386 if ( (wxSystemOptions::HasOption( wxMAC_ALWAYS_USE_GENERIC_LISTCTRL )
387 && (wxSystemOptions::GetOptionInt( wxMAC_ALWAYS_USE_GENERIC_LISTCTRL ) == 1)) ||
388 (style & wxLC_ICON) || (style & wxLC_SMALL_ICON) || (style & wxLC_LIST) || (style & wxLC_EDIT_LABELS) )
389 {
390 m_macIsUserPane = true;
391
392 if ( !wxWindow::Create(parent, id, pos, size, style, name) )
393 return false;
394 m_genericImpl = new wxGenericListCtrlHook(this, id, pos, size, style, validator, name);
395 m_genericImpl->PushEventHandler( new wxMacListCtrlEventDelegate( this, GetId() ) );
396 return true;
397 }
398
399 else
400 {
401 m_macIsUserPane = false;
402
403 if ( !wxWindow::Create(parent, id, pos, size, style, name) )
404 return false;
405 m_dbImpl = new wxMacDataBrowserListCtrlControl( this, pos, size, style );
406 m_peer = m_dbImpl;
407
408 MacPostControlCreate( pos, size );
409
410 InstallControlEventHandler( m_peer->GetControlRef() , GetwxMacListCtrlEventHandlerUPP(),
411 GetEventTypeCount(eventList), eventList, this,
412 (EventHandlerRef *)&m_macListCtrlEventHandler);
413 }
414
415 return true;
416 }
417
418 wxListCtrl::~wxListCtrl()
419 {
420 if (m_genericImpl)
421 {
422 m_genericImpl->PopEventHandler(/* deleteHandler = */ true);
423 }
424
425 if (m_ownsImageListNormal)
426 delete m_imageListNormal;
427 if (m_ownsImageListSmall)
428 delete m_imageListSmall;
429 if (m_ownsImageListState)
430 delete m_imageListState;
431 }
432
433 // ----------------------------------------------------------------------------
434 // set/get/change style
435 // ----------------------------------------------------------------------------
436
437 // Add or remove a single window style
438 void wxListCtrl::SetSingleStyle(long style, bool add)
439 {
440 long flag = GetWindowStyleFlag();
441
442 // Get rid of conflicting styles
443 if ( add )
444 {
445 if ( style & wxLC_MASK_TYPE)
446 flag = flag & ~wxLC_MASK_TYPE;
447 if ( style & wxLC_MASK_ALIGN )
448 flag = flag & ~wxLC_MASK_ALIGN;
449 if ( style & wxLC_MASK_SORT )
450 flag = flag & ~wxLC_MASK_SORT;
451 }
452
453 if ( add )
454 flag |= style;
455 else
456 flag &= ~style;
457
458 SetWindowStyleFlag(flag);
459 }
460
461 // Set the whole window style
462 void wxListCtrl::SetWindowStyleFlag(long flag)
463 {
464 if ( flag != m_windowStyle )
465 {
466 m_windowStyle = flag;
467
468 if (m_genericImpl)
469 {
470 m_genericImpl->SetWindowStyleFlag(flag);
471 }
472
473 Refresh();
474 }
475 }
476
477 void wxListCtrl::DoSetSize( int x, int y, int width, int height, int sizeFlags )
478 {
479 wxControl::DoSetSize(x, y, width, height, sizeFlags);
480
481 if (m_genericImpl)
482 m_genericImpl->SetSize(x, y, width, height, sizeFlags);
483 }
484
485 bool wxListCtrl::SetFont(const wxFont& font)
486 {
487 bool rv = true;
488 rv = wxControl::SetFont(font);
489 if (m_genericImpl)
490 rv = m_genericImpl->SetFont(font);
491 return rv;
492 }
493
494 bool wxListCtrl::SetForegroundColour(const wxColour& colour)
495 {
496 bool rv = true;
497 if (m_genericImpl)
498 rv = m_genericImpl->SetForegroundColour(colour);
499 if (m_dbImpl)
500 SetTextColour(colour);
501 return rv;
502 }
503
504 bool wxListCtrl::SetBackgroundColour(const wxColour& colour)
505 {
506 bool rv = true;
507 if (m_genericImpl)
508 rv = m_genericImpl->SetBackgroundColour(colour);
509 if (m_dbImpl)
510 m_bgColor = colour;
511 return rv;
512 }
513
514 wxColour wxListCtrl::GetBackgroundColour()
515 {
516 if (m_genericImpl)
517 return m_genericImpl->GetBackgroundColour();
518 if (m_dbImpl)
519 return m_bgColor;
520
521 return wxNullColour;
522 }
523
524 // ----------------------------------------------------------------------------
525 // accessors
526 // ----------------------------------------------------------------------------
527
528 // Gets information about this column
529 bool wxListCtrl::GetColumn(int col, wxListItem& item) const
530 {
531 if (m_genericImpl)
532 return m_genericImpl->GetColumn(col, item);
533
534 bool success = true;
535
536 if (m_dbImpl)
537 {
538
539 wxColumnList::compatibility_iterator node = m_colsInfo.Item( col );
540 wxASSERT_MSG( node, _T("invalid column index in wxMacListCtrlItem") );
541 wxListItem* column = node->GetData();
542
543 long mask = column->GetMask();
544 if (mask & wxLIST_MASK_TEXT)
545 item.SetText(column->GetText());
546 if (mask & wxLIST_MASK_DATA)
547 item.SetData(column->GetData());
548 if (mask & wxLIST_MASK_IMAGE)
549 item.SetImage(column->GetImage());
550 if (mask & wxLIST_MASK_STATE)
551 item.SetState(column->GetState());
552 if (mask & wxLIST_MASK_FORMAT)
553 item.SetAlign(column->GetAlign());
554 if (mask & wxLIST_MASK_WIDTH)
555 item.SetWidth(column->GetWidth());
556 }
557
558 return success;
559 }
560
561 // Sets information about this column
562 bool wxListCtrl::SetColumn(int col, wxListItem& item)
563 {
564 if (m_genericImpl)
565 return m_genericImpl->SetColumn(col, item);
566
567 if (m_dbImpl)
568 {
569 if ( col >= (int)m_colsInfo.GetCount() )
570 {
571 wxListItem* listItem = new wxListItem(item);
572 m_colsInfo.Append( listItem );
573 }
574 else
575 {
576 wxListItem listItem;
577 GetColumn( col, listItem );
578 long mask = item.GetMask();
579 if (mask & wxLIST_MASK_TEXT)
580 listItem.SetText(item.GetText());
581 if (mask & wxLIST_MASK_DATA)
582 listItem.SetData(item.GetData());
583 if (mask & wxLIST_MASK_IMAGE)
584 listItem.SetImage(item.GetImage());
585 if (mask & wxLIST_MASK_STATE)
586 listItem.SetState(item.GetState());
587 if (mask & wxLIST_MASK_FORMAT)
588 listItem.SetAlign(item.GetAlign());
589 if (mask & wxLIST_MASK_WIDTH)
590 listItem.SetWidth(item.GetWidth());
591 }
592
593 // change the appearance in the databrowser.
594 DataBrowserListViewHeaderDesc columnDesc;
595 columnDesc.version=kDataBrowserListViewLatestHeaderDesc;
596 verify_noerr( m_dbImpl->GetHeaderDesc( kMinColumnId + col, &columnDesc ) );
597
598 /*
599 if (item.GetMask() & wxLIST_MASK_TEXT)
600 {
601 wxFontEncoding enc;
602 if ( m_font.Ok() )
603 enc = m_font.GetEncoding();
604 else
605 enc = wxLocale::GetSystemEncoding();
606 wxMacCFStringHolder cfTitle;
607 cfTitle.Assign( item.GetText() , enc );
608 if(columnDesc.titleString)
609 CFRelease(columnDesc.titleString);
610 columnDesc.titleString = cfTitle;
611 }
612 */
613
614 if (item.GetMask() & wxLIST_MASK_IMAGE && item.GetImage() != -1 )
615 {
616 columnDesc.btnContentInfo.contentType = kControlContentIconRef;
617 wxImageList* imageList = GetImageList(wxIMAGE_LIST_SMALL);
618 if (imageList && imageList->GetImageCount() > 0 )
619 {
620 wxBitmap bmp = imageList->GetBitmap( item.GetImage() );
621 IconRef icon = bmp.GetBitmapData()->GetIconRef();
622 columnDesc.btnContentInfo.u.iconRef = icon;
623 }
624 }
625
626 verify_noerr( m_dbImpl->SetHeaderDesc( kMinColumnId + col, &columnDesc ) );
627
628 }
629 return true;
630 }
631
632 int wxListCtrl::GetColumnCount() const
633 {
634 if (m_genericImpl)
635 return m_genericImpl->GetColumnCount();
636
637 if (m_dbImpl)
638 {
639 UInt32 count;
640 m_dbImpl->GetColumnCount(&count);
641 return count;
642 }
643
644 return m_colCount;
645 }
646
647 // Gets the column width
648 int wxListCtrl::GetColumnWidth(int col) const
649 {
650 if (m_genericImpl)
651 return m_genericImpl->GetColumnWidth(col);
652
653 if (m_dbImpl)
654 {
655 return m_dbImpl->GetColumnWidth(col);
656 }
657
658 return 0;
659 }
660
661 // Sets the column width
662 bool wxListCtrl::SetColumnWidth(int col, int width)
663 {
664 if (m_genericImpl)
665 return m_genericImpl->SetColumnWidth(col, width);
666
667 if (m_dbImpl)
668 {
669 int mywidth = width;
670 if (width == wxLIST_AUTOSIZE || width == wxLIST_AUTOSIZE_USEHEADER)
671 mywidth = 150;
672
673 if (col == -1)
674 {
675 for (int column = 0; column < GetColumnCount(); column++)
676 {
677 m_dbImpl->SetColumnWidth(col, mywidth);
678 }
679 }
680 else{
681 m_dbImpl->SetColumnWidth(col, mywidth);
682 }
683 return true;
684 }
685
686 return false;
687 }
688
689 // Gets the number of items that can fit vertically in the
690 // visible area of the list control (list or report view)
691 // or the total number of items in the list control (icon
692 // or small icon view)
693 int wxListCtrl::GetCountPerPage() const
694 {
695 if (m_genericImpl)
696 return m_genericImpl->GetCountPerPage();
697
698 if (m_dbImpl)
699 {
700 }
701
702 return 1;
703 }
704
705 // Gets the edit control for editing labels.
706 wxTextCtrl* wxListCtrl::GetEditControl() const
707 {
708 if (m_genericImpl)
709 return m_genericImpl->GetEditControl();
710
711 return NULL;
712 }
713
714 // Gets information about the item
715 bool wxListCtrl::GetItem(wxListItem& info) const
716 {
717 if (m_genericImpl)
718 return m_genericImpl->GetItem(info);
719
720 if (m_dbImpl)
721 {
722 if (!IsVirtual())
723 m_dbImpl->MacGetColumnInfo(info.m_itemId, info.m_col, info);
724 else
725 {
726 info.SetText( OnGetItemText(info.m_itemId, info.m_col) );
727 info.SetImage( OnGetItemColumnImage(info.m_itemId, info.m_col) );
728 wxListItemAttr* attrs = OnGetItemAttr( info.m_itemId );
729 if (attrs)
730 {
731 info.SetFont( attrs->GetFont() );
732 info.SetBackgroundColour( attrs->GetBackgroundColour() );
733 info.SetTextColour( attrs->GetTextColour() );
734 }
735 }
736 }
737 bool success = true;
738 return success;
739 }
740
741 // Sets information about the item
742 bool wxListCtrl::SetItem(wxListItem& info)
743 {
744 if (m_genericImpl)
745 return m_genericImpl->SetItem(info);
746
747 if (m_dbImpl)
748 m_dbImpl->MacSetColumnInfo( info.m_itemId, info.m_col, &info );
749
750 return true;
751 }
752
753 long wxListCtrl::SetItem(long index, int col, const wxString& label, int imageId)
754 {
755 if (m_genericImpl)
756 return m_genericImpl->SetItem(index, col, label, imageId);
757
758 wxListItem info;
759 info.m_text = label;
760 info.m_mask = wxLIST_MASK_TEXT;
761 info.m_itemId = index;
762 info.m_col = col;
763 if ( imageId > -1 )
764 {
765 info.m_image = imageId;
766 info.m_mask |= wxLIST_MASK_IMAGE;
767 }
768 return SetItem(info);
769 }
770
771
772 // Gets the item state
773 int wxListCtrl::GetItemState(long item, long stateMask) const
774 {
775 if (m_genericImpl)
776 return m_genericImpl->GetItemState(item, stateMask);
777
778 wxListItem info;
779
780 info.m_mask = wxLIST_MASK_STATE;
781 info.m_stateMask = stateMask;
782 info.m_itemId = item;
783
784 if (!GetItem(info))
785 return 0;
786
787 return info.m_state;
788 }
789
790 // Sets the item state
791 bool wxListCtrl::SetItemState(long item, long state, long stateMask)
792 {
793 if (m_genericImpl)
794 return m_genericImpl->SetItemState(item, state, stateMask);
795
796 wxListItem info;
797 info.m_mask = wxLIST_MASK_STATE;
798 info.m_stateMask = stateMask;
799 info.m_state = state;
800 info.m_itemId = item;
801 return SetItem(info);
802 }
803
804 // Sets the item image
805 bool wxListCtrl::SetItemImage(long item, int image, int WXUNUSED(selImage))
806 {
807 return SetItemColumnImage(item, 0, image);
808 }
809
810 // Sets the item image
811 bool wxListCtrl::SetItemColumnImage(long item, long column, int image)
812 {
813 if (m_genericImpl)
814 return m_genericImpl->SetItemColumnImage(item, column, image);
815
816 wxListItem info;
817
818 info.m_mask = wxLIST_MASK_IMAGE;
819 info.m_image = image;
820 info.m_itemId = item;
821 info.m_col = column;
822
823 return SetItem(info);
824 }
825
826 // Gets the item text
827 wxString wxListCtrl::GetItemText(long item) const
828 {
829 if (m_genericImpl)
830 return m_genericImpl->GetItemText(item);
831
832 wxListItem info;
833
834 info.m_mask = wxLIST_MASK_TEXT;
835 info.m_itemId = item;
836
837 if (!GetItem(info))
838 return wxEmptyString;
839 return info.m_text;
840 }
841
842 // Sets the item text
843 void wxListCtrl::SetItemText(long item, const wxString& str)
844 {
845 if (m_genericImpl)
846 return m_genericImpl->SetItemText(item, str);
847
848 wxListItem info;
849
850 info.m_mask = wxLIST_MASK_TEXT;
851 info.m_itemId = item;
852 info.m_text = str;
853
854 SetItem(info);
855 }
856
857 // Gets the item data
858 long wxListCtrl::GetItemData(long item) const
859 {
860 if (m_genericImpl)
861 return m_genericImpl->GetItemData(item);
862
863 wxListItem info;
864
865 info.m_mask = wxLIST_MASK_DATA;
866 info.m_itemId = item;
867
868 if (!GetItem(info))
869 return 0;
870 return info.m_data;
871 }
872
873 // Sets the item data
874 bool wxListCtrl::SetItemData(long item, long data)
875 {
876 if (m_genericImpl)
877 return m_genericImpl->SetItemData(item, data);
878
879 wxListItem info;
880
881 info.m_mask = wxLIST_MASK_DATA;
882 info.m_itemId = item;
883 info.m_data = data;
884
885 return SetItem(info);
886 }
887
888 wxRect wxListCtrl::GetViewRect() const
889 {
890 wxASSERT_MSG( !HasFlag(wxLC_REPORT | wxLC_LIST),
891 _T("wxListCtrl::GetViewRect() only works in icon mode") );
892
893 if (m_genericImpl)
894 return m_genericImpl->GetViewRect();
895
896 wxRect rect;
897 return rect;
898 }
899
900 // Gets the item rectangle
901 bool wxListCtrl::GetItemRect(long item, wxRect& rect, int code) const
902 {
903 if (m_genericImpl)
904 return m_genericImpl->GetItemRect(item, rect, code);
905
906 return true;
907 }
908
909 // Gets the item position
910 bool wxListCtrl::GetItemPosition(long item, wxPoint& pos) const
911 {
912 if (m_genericImpl)
913 return m_genericImpl->GetItemPosition(item, pos);
914
915 bool success = false;
916
917 return success;
918 }
919
920 // Sets the item position.
921 bool wxListCtrl::SetItemPosition(long item, const wxPoint& pos)
922 {
923 if (m_genericImpl)
924 return m_genericImpl->SetItemPosition(item, pos);
925
926 return false;
927 }
928
929 // Gets the number of items in the list control
930 int wxListCtrl::GetItemCount() const
931 {
932 if (m_genericImpl)
933 return m_genericImpl->GetItemCount();
934
935 if (m_dbImpl)
936 return m_dbImpl->MacGetCount();
937
938 return m_count;
939 }
940
941 void wxListCtrl::SetItemSpacing( int spacing, bool isSmall )
942 {
943 if (m_genericImpl)
944 m_genericImpl->SetItemSpacing(spacing, isSmall);
945 }
946
947 wxSize wxListCtrl::GetItemSpacing() const
948 {
949 if (m_genericImpl)
950 return m_genericImpl->GetItemSpacing();
951
952 return wxSize(0, 0);
953 }
954
955 void wxListCtrl::SetItemTextColour( long item, const wxColour &col )
956 {
957 if (m_genericImpl)
958 {
959 m_genericImpl->SetItemTextColour(item, col);
960 return;
961 }
962
963 wxListItem info;
964 info.m_itemId = item;
965 info.SetTextColour( col );
966 SetItem( info );
967 }
968
969 wxColour wxListCtrl::GetItemTextColour( long item ) const
970 {
971 if (m_genericImpl)
972 return m_genericImpl->GetItemTextColour(item);
973
974 if (m_dbImpl)
975 {
976 wxListItem info;
977 if (GetItem(info))
978 return info.GetTextColour();
979 }
980 return wxNullColour;
981 }
982
983 void wxListCtrl::SetItemBackgroundColour( long item, const wxColour &col )
984 {
985 if (m_genericImpl)
986 {
987 m_genericImpl->SetItemBackgroundColour(item, col);
988 return;
989 }
990
991 wxListItem info;
992 info.m_itemId = item;
993 info.SetBackgroundColour( col );
994 SetItem( info );
995 }
996
997 wxColour wxListCtrl::GetItemBackgroundColour( long item ) const
998 {
999 if (m_genericImpl)
1000 return m_genericImpl->GetItemBackgroundColour(item);
1001
1002 if (m_dbImpl)
1003 {
1004 wxListItem info;
1005 if (GetItem(info))
1006 return info.GetBackgroundColour();
1007 }
1008 return wxNullColour;
1009 }
1010
1011 void wxListCtrl::SetItemFont( long item, const wxFont &f )
1012 {
1013 if (m_genericImpl)
1014 {
1015 m_genericImpl->SetItemFont(item, f);
1016 return;
1017 }
1018
1019 wxListItem info;
1020 info.m_itemId = item;
1021 info.SetFont( f );
1022 SetItem( info );
1023 }
1024
1025 wxFont wxListCtrl::GetItemFont( long item ) const
1026 {
1027 if (m_genericImpl)
1028 return m_genericImpl->GetItemFont(item);
1029
1030 if (m_dbImpl)
1031 {
1032 wxListItem info;
1033 if (GetItem(info))
1034 return info.GetFont();
1035 }
1036
1037 return wxNullFont;
1038 }
1039
1040 // Gets the number of selected items in the list control
1041 int wxListCtrl::GetSelectedItemCount() const
1042 {
1043 if (m_genericImpl)
1044 return m_genericImpl->GetSelectedItemCount();
1045
1046 if (m_dbImpl)
1047 return m_dbImpl->GetSelectedItemCount(NULL, true);
1048
1049 return 0;
1050 }
1051
1052 // Gets the text colour of the listview
1053 wxColour wxListCtrl::GetTextColour() const
1054 {
1055 if (m_genericImpl)
1056 return m_genericImpl->GetTextColour();
1057
1058 // TODO: we need owner drawn list items to customize text color.
1059 if (m_dbImpl)
1060 return m_textColor;
1061
1062 return wxNullColour;
1063 }
1064
1065 // Sets the text colour of the listview
1066 void wxListCtrl::SetTextColour(const wxColour& col)
1067 {
1068 if (m_genericImpl)
1069 {
1070 m_genericImpl->SetTextColour(col);
1071 return;
1072 }
1073
1074 if (m_dbImpl)
1075 m_textColor = col;
1076 }
1077
1078 // Gets the index of the topmost visible item when in
1079 // list or report view
1080 long wxListCtrl::GetTopItem() const
1081 {
1082 if (m_genericImpl)
1083 return m_genericImpl->GetTopItem();
1084
1085 return 0;
1086 }
1087
1088 // Searches for an item, starting from 'item'.
1089 // 'geometry' is one of
1090 // wxLIST_NEXT_ABOVE/ALL/BELOW/LEFT/RIGHT.
1091 // 'state' is a state bit flag, one or more of
1092 // wxLIST_STATE_DROPHILITED/FOCUSED/SELECTED/CUT.
1093 // item can be -1 to find the first item that matches the
1094 // specified flags.
1095 // Returns the item or -1 if unsuccessful.
1096 long wxListCtrl::GetNextItem(long item, int geom, int state) const
1097 {
1098 if (m_genericImpl)
1099 return m_genericImpl->GetNextItem(item, geom, state);
1100
1101 if (m_dbImpl && geom == wxLIST_NEXT_ALL && state == wxLIST_STATE_SELECTED )
1102 {
1103 long count = m_dbImpl->MacGetCount() ;
1104 for ( long line = item + 1 ; line < count; line++ )
1105 {
1106 wxMacDataItem* id = m_dbImpl->GetItemFromLine(line);
1107 if ( m_dbImpl->IsItemSelected(id ) )
1108 return line;
1109 }
1110 return -1;
1111 }
1112
1113 return 0;
1114 }
1115
1116
1117 wxImageList *wxListCtrl::GetImageList(int which) const
1118 {
1119 if (m_genericImpl)
1120 return m_genericImpl->GetImageList(which);
1121
1122 if ( which == wxIMAGE_LIST_NORMAL )
1123 {
1124 return m_imageListNormal;
1125 }
1126 else if ( which == wxIMAGE_LIST_SMALL )
1127 {
1128 return m_imageListSmall;
1129 }
1130 else if ( which == wxIMAGE_LIST_STATE )
1131 {
1132 return m_imageListState;
1133 }
1134 return NULL;
1135 }
1136
1137 void wxListCtrl::SetImageList(wxImageList *imageList, int which)
1138 {
1139 if (m_genericImpl)
1140 {
1141 m_genericImpl->SetImageList(imageList, which);
1142 return;
1143 }
1144
1145 if ( which == wxIMAGE_LIST_NORMAL )
1146 {
1147 if (m_ownsImageListNormal) delete m_imageListNormal;
1148 m_imageListNormal = imageList;
1149 m_ownsImageListNormal = false;
1150 }
1151 else if ( which == wxIMAGE_LIST_SMALL )
1152 {
1153 if (m_ownsImageListSmall) delete m_imageListSmall;
1154 m_imageListSmall = imageList;
1155 m_ownsImageListSmall = false;
1156 }
1157 else if ( which == wxIMAGE_LIST_STATE )
1158 {
1159 if (m_ownsImageListState) delete m_imageListState;
1160 m_imageListState = imageList;
1161 m_ownsImageListState = false;
1162 }
1163 }
1164
1165 void wxListCtrl::AssignImageList(wxImageList *imageList, int which)
1166 {
1167 if (m_genericImpl)
1168 {
1169 m_genericImpl->AssignImageList(imageList, which);
1170 return;
1171 }
1172
1173 SetImageList(imageList, which);
1174 if ( which == wxIMAGE_LIST_NORMAL )
1175 m_ownsImageListNormal = true;
1176 else if ( which == wxIMAGE_LIST_SMALL )
1177 m_ownsImageListSmall = true;
1178 else if ( which == wxIMAGE_LIST_STATE )
1179 m_ownsImageListState = true;
1180 }
1181
1182 // ----------------------------------------------------------------------------
1183 // Operations
1184 // ----------------------------------------------------------------------------
1185
1186 // Arranges the items
1187 bool wxListCtrl::Arrange(int flag)
1188 {
1189 if (m_genericImpl)
1190 return m_genericImpl->Arrange(flag);
1191 return false;
1192 }
1193
1194 // Deletes an item
1195 bool wxListCtrl::DeleteItem(long item)
1196 {
1197 if (m_genericImpl)
1198 return m_genericImpl->DeleteItem(item);
1199
1200 if (m_dbImpl)
1201 {
1202 m_dbImpl->MacDelete(item);
1203 wxListEvent event( wxEVT_COMMAND_LIST_DELETE_ITEM, GetId() );
1204 event.SetEventObject( this );
1205 event.m_itemIndex = item;
1206 GetEventHandler()->ProcessEvent( event );
1207
1208 }
1209 return true;
1210 }
1211
1212 // Deletes all items
1213 bool wxListCtrl::DeleteAllItems()
1214 {
1215 if (m_genericImpl)
1216 return m_genericImpl->DeleteAllItems();
1217
1218 if (m_dbImpl)
1219 {
1220 m_dbImpl->MacClear();
1221 wxListEvent event( wxEVT_COMMAND_LIST_DELETE_ALL_ITEMS, GetId() );
1222 event.SetEventObject( this );
1223 GetEventHandler()->ProcessEvent( event );
1224 }
1225 return true;
1226 }
1227
1228 // Deletes all items
1229 bool wxListCtrl::DeleteAllColumns()
1230 {
1231 if (m_genericImpl)
1232 return m_genericImpl->DeleteAllColumns();
1233
1234 if (m_dbImpl)
1235 {
1236 UInt32 cols;
1237 m_dbImpl->GetColumnCount(&cols);
1238 for (UInt32 col = 0; col < cols; col++)
1239 {
1240 DeleteColumn(col);
1241 }
1242 }
1243
1244 return true;
1245 }
1246
1247 // Deletes a column
1248 bool wxListCtrl::DeleteColumn(int col)
1249 {
1250 if (m_genericImpl)
1251 return m_genericImpl->DeleteColumn(col);
1252
1253 if (m_dbImpl)
1254 {
1255 OSStatus err = m_dbImpl->RemoveColumn(col);
1256 return err == noErr;
1257 }
1258
1259 return true;
1260 }
1261
1262 // Clears items, and columns if there are any.
1263 void wxListCtrl::ClearAll()
1264 {
1265 if (m_genericImpl)
1266 {
1267 m_genericImpl->ClearAll();
1268 return;
1269 }
1270
1271 if (m_dbImpl)
1272 {
1273 DeleteAllItems();
1274 DeleteAllColumns();
1275 }
1276 }
1277
1278 wxTextCtrl* wxListCtrl::EditLabel(long item, wxClassInfo* textControlClass)
1279 {
1280 if (m_genericImpl)
1281 return m_genericImpl->EditLabel(item, textControlClass);
1282
1283 if (m_dbImpl)
1284 {
1285 wxMacDataItem* id = m_dbImpl->GetItemFromLine(item);
1286 verify_noerr( SetDataBrowserEditItem(m_dbImpl->GetControlRef(), (DataBrowserItemID)id, kMinColumnId) );
1287 }
1288 return NULL;
1289 }
1290
1291 // End label editing, optionally cancelling the edit
1292 bool wxListCtrl::EndEditLabel(bool cancel)
1293 {
1294 // TODO: generic impl. doesn't have this method - is it needed for us?
1295 if (m_genericImpl)
1296 return true; // m_genericImpl->EndEditLabel(cancel);
1297
1298 if (m_dbImpl)
1299 verify_noerr( SetDataBrowserEditItem(m_dbImpl->GetControlRef(), kDataBrowserNoItem, kMinColumnId) );
1300 return true;
1301 }
1302
1303 // Ensures this item is visible
1304 bool wxListCtrl::EnsureVisible(long item)
1305 {
1306 if (m_genericImpl)
1307 return m_genericImpl->EnsureVisible(item);
1308
1309 if (m_dbImpl)
1310 {
1311 wxMacDataItem* dataItem = m_dbImpl->GetItemFromLine(item);
1312 m_dbImpl->RevealItem(dataItem, kDataBrowserRevealWithoutSelecting);
1313 }
1314
1315 return true;
1316 }
1317
1318 // Find an item whose label matches this string, starting from the item after 'start'
1319 // or the beginning if 'start' is -1.
1320 long wxListCtrl::FindItem(long start, const wxString& str, bool partial)
1321 {
1322 if (m_genericImpl)
1323 return m_genericImpl->FindItem(start, str, partial);
1324
1325 return -1;
1326 }
1327
1328 // Find an item whose data matches this data, starting from the item after 'start'
1329 // or the beginning if 'start' is -1.
1330 long wxListCtrl::FindItem(long start, long data)
1331 {
1332 if (m_genericImpl)
1333 return m_genericImpl->FindItem(start, data);
1334
1335 long idx = start + 1;
1336 long count = GetItemCount();
1337
1338 while (idx < count)
1339 {
1340 if (GetItemData(idx) == data)
1341 return idx;
1342 idx++;
1343 };
1344
1345 return -1;
1346 }
1347
1348 // Find an item nearest this position in the specified direction, starting from
1349 // the item after 'start' or the beginning if 'start' is -1.
1350 long wxListCtrl::FindItem(long start, const wxPoint& pt, int direction)
1351 {
1352 if (m_genericImpl)
1353 return m_genericImpl->FindItem(start, pt, direction);
1354 return -1;
1355 }
1356
1357 // Determines which item (if any) is at the specified point,
1358 // giving details in 'flags' (see wxLIST_HITTEST_... flags above)
1359 long
1360 wxListCtrl::HitTest(const wxPoint& point, int& flags, long *ptrSubItem) const
1361 {
1362 if (m_genericImpl)
1363 return m_genericImpl->HitTest(point, flags, ptrSubItem);
1364
1365 return -1;
1366 }
1367
1368
1369 // Inserts an item, returning the index of the new item if successful,
1370 // -1 otherwise.
1371 long wxListCtrl::InsertItem(wxListItem& info)
1372 {
1373 wxASSERT_MSG( !IsVirtual(), _T("can't be used with virtual controls") );
1374
1375 if (m_genericImpl)
1376 return m_genericImpl->InsertItem(info);
1377
1378 if (m_dbImpl)
1379 {
1380 int count = GetItemCount();
1381
1382 if (info.m_itemId > count)
1383 info.m_itemId = count;
1384
1385 m_dbImpl->MacInsertItem(info.m_itemId, &info );
1386 wxListEvent event( wxEVT_COMMAND_LIST_INSERT_ITEM, GetId() );
1387 event.SetEventObject( this );
1388 event.m_itemIndex = info.m_itemId;
1389 GetEventHandler()->ProcessEvent( event );
1390 }
1391
1392 return info.m_itemId;
1393 }
1394
1395 long wxListCtrl::InsertItem(long index, const wxString& label)
1396 {
1397 if (m_genericImpl)
1398 return m_genericImpl->InsertItem(index, label);
1399
1400 wxListItem info;
1401 info.m_text = label;
1402 info.m_mask = wxLIST_MASK_TEXT;
1403 info.m_itemId = index;
1404 return InsertItem(info);
1405 }
1406
1407 // Inserts an image item
1408 long wxListCtrl::InsertItem(long index, int imageIndex)
1409 {
1410 if (m_genericImpl)
1411 return m_genericImpl->InsertItem(index, imageIndex);
1412
1413 wxListItem info;
1414 info.m_image = imageIndex;
1415 info.m_mask = wxLIST_MASK_IMAGE;
1416 info.m_itemId = index;
1417 return InsertItem(info);
1418 }
1419
1420 // Inserts an image/string item
1421 long wxListCtrl::InsertItem(long index, const wxString& label, int imageIndex)
1422 {
1423 if (m_genericImpl)
1424 return m_genericImpl->InsertItem(index, label, imageIndex);
1425
1426 wxListItem info;
1427 info.m_image = imageIndex;
1428 info.m_text = label;
1429 info.m_mask = wxLIST_MASK_IMAGE | wxLIST_MASK_TEXT;
1430 info.m_itemId = index;
1431 return InsertItem(info);
1432 }
1433
1434 // For list view mode (only), inserts a column.
1435 long wxListCtrl::InsertColumn(long col, wxListItem& item)
1436 {
1437 if (m_genericImpl)
1438 return m_genericImpl->InsertColumn(col, item);
1439
1440 if (m_dbImpl)
1441 {
1442 int width = item.GetWidth();
1443 if ( !(item.GetMask() & wxLIST_MASK_WIDTH) )
1444 width = 150;
1445
1446 DataBrowserPropertyType type = kDataBrowserCustomType; //kDataBrowserTextType;
1447 wxImageList* imageList = GetImageList(wxIMAGE_LIST_SMALL);
1448 if (imageList && imageList->GetImageCount() > 0)
1449 {
1450 wxBitmap bmp = imageList->GetBitmap(0);
1451 //if (bmp.Ok())
1452 // type = kDataBrowserIconAndTextType;
1453 }
1454
1455 SInt16 just = teFlushDefault;
1456 if (item.GetMask() & wxLIST_MASK_FORMAT)
1457 {
1458 if (item.GetAlign() == wxLIST_FORMAT_LEFT)
1459 just = teFlushLeft;
1460 else if (item.GetAlign() == wxLIST_FORMAT_CENTER)
1461 just = teCenter;
1462 else if (item.GetAlign() == wxLIST_FORMAT_RIGHT)
1463 just = teFlushRight;
1464 }
1465 m_dbImpl->InsertColumn(col, type, item.GetText(), just, width);
1466 SetColumn(col, item);
1467
1468 // set/remove options based on the wxListCtrl type.
1469 DataBrowserTableViewColumnID id;
1470 m_dbImpl->GetColumnIDFromIndex(col, &id);
1471 DataBrowserPropertyFlags flags;
1472 verify_noerr(m_dbImpl->GetPropertyFlags(id, &flags));
1473 if (GetWindowStyleFlag() & wxLC_EDIT_LABELS)
1474 flags |= kDataBrowserPropertyIsEditable;
1475
1476 if (GetWindowStyleFlag() & wxLC_VIRTUAL){
1477 flags &= ~kDataBrowserListViewSortableColumn;
1478 }
1479 verify_noerr(m_dbImpl->SetPropertyFlags(id, flags));
1480 }
1481
1482 return col;
1483 }
1484
1485 long wxListCtrl::InsertColumn(long col,
1486 const wxString& heading,
1487 int format,
1488 int width)
1489 {
1490 if (m_genericImpl)
1491 return m_genericImpl->InsertColumn(col, heading, format, width);
1492
1493 wxListItem item;
1494 item.m_mask = wxLIST_MASK_TEXT | wxLIST_MASK_FORMAT;
1495 item.m_text = heading;
1496 if ( width > -1 )
1497 {
1498 item.m_mask |= wxLIST_MASK_WIDTH;
1499 item.m_width = width;
1500 }
1501 item.m_format = format;
1502
1503 return InsertColumn(col, item);
1504 }
1505
1506 // scroll the control by the given number of pixels (exception: in list view,
1507 // dx is interpreted as number of columns)
1508 bool wxListCtrl::ScrollList(int dx, int dy)
1509 {
1510 if (m_genericImpl)
1511 return m_genericImpl->ScrollList(dx, dy);
1512
1513 if (m_dbImpl)
1514 {
1515 m_dbImpl->SetScrollPosition(dx, dy);
1516 }
1517 return true;
1518 }
1519
1520
1521 bool wxListCtrl::SortItems(wxListCtrlCompare fn, long data)
1522 {
1523 if (m_genericImpl)
1524 return m_genericImpl->SortItems(fn, data);
1525
1526 if (m_dbImpl)
1527 {
1528 m_compareFunc = fn;
1529 m_compareFuncData = data;
1530 }
1531
1532 return true;
1533 }
1534
1535 // ----------------------------------------------------------------------------
1536 // virtual list controls
1537 // ----------------------------------------------------------------------------
1538
1539 wxString wxListCtrl::OnGetItemText(long WXUNUSED(item), long WXUNUSED(col)) const
1540 {
1541 // this is a pure virtual function, in fact - which is not really pure
1542 // because the controls which are not virtual don't need to implement it
1543 wxFAIL_MSG( _T("wxListCtrl::OnGetItemText not supposed to be called") );
1544
1545 return wxEmptyString;
1546 }
1547
1548 int wxListCtrl::OnGetItemImage(long WXUNUSED(item)) const
1549 {
1550 wxCHECK_MSG(!GetImageList(wxIMAGE_LIST_SMALL),
1551 -1,
1552 wxT("List control has an image list, OnGetItemImage or OnGetItemColumnImage should be overridden."));
1553 return -1;
1554 }
1555
1556 int wxListCtrl::OnGetItemColumnImage(long item, long column) const
1557 {
1558 if (!column)
1559 return OnGetItemImage(item);
1560
1561 return -1;
1562 }
1563
1564 wxListItemAttr *wxListCtrl::OnGetItemAttr(long WXUNUSED_UNLESS_DEBUG(item)) const
1565 {
1566 wxASSERT_MSG( item >= 0 && item < GetItemCount(),
1567 _T("invalid item index in OnGetItemAttr()") );
1568
1569 // no attributes by default
1570 return NULL;
1571 }
1572
1573 void wxListCtrl::SetItemCount(long count)
1574 {
1575 wxASSERT_MSG( IsVirtual(), _T("this is for virtual controls only") );
1576
1577 if (m_genericImpl)
1578 {
1579 m_genericImpl->SetItemCount(count);
1580 return;
1581 }
1582
1583 if (m_dbImpl)
1584 {
1585 // we need to temporarily disable the new item creation notification
1586 // procedure to speed things up
1587 // FIXME: Even this doesn't seem to help much...
1588 DataBrowserCallbacks callbacks;
1589 DataBrowserItemNotificationUPP itemUPP;
1590 GetDataBrowserCallbacks(m_dbImpl->GetControlRef(), &callbacks);
1591 itemUPP = callbacks.u.v1.itemNotificationCallback;
1592 callbacks.u.v1.itemNotificationCallback = 0;
1593 m_dbImpl->SetCallbacks(&callbacks);
1594 ::AddDataBrowserItems(m_dbImpl->GetControlRef(), kDataBrowserNoItem,
1595 count, NULL, kDataBrowserItemNoProperty);
1596 callbacks.u.v1.itemNotificationCallback = itemUPP;
1597 m_dbImpl->SetCallbacks(&callbacks);
1598 }
1599 m_count = count;
1600 }
1601
1602 void wxListCtrl::RefreshItem(long item)
1603 {
1604 if (m_genericImpl)
1605 {
1606 m_genericImpl->RefreshItem(item);
1607 return;
1608 }
1609
1610 wxRect rect;
1611 GetItemRect(item, rect);
1612 RefreshRect(rect);
1613 }
1614
1615 void wxListCtrl::RefreshItems(long itemFrom, long itemTo)
1616 {
1617 if (m_genericImpl)
1618 {
1619 m_genericImpl->RefreshItems(itemFrom, itemTo);
1620 return;
1621 }
1622
1623 wxRect rect1, rect2;
1624 GetItemRect(itemFrom, rect1);
1625 GetItemRect(itemTo, rect2);
1626
1627 wxRect rect = rect1;
1628 rect.height = rect2.GetBottom() - rect1.GetTop();
1629
1630 RefreshRect(rect);
1631 }
1632
1633
1634 // wxMac internal data structures
1635
1636 wxMacListCtrlItem::~wxMacListCtrlItem()
1637 {
1638 }
1639
1640 void wxMacListCtrlItem::Notification(wxMacDataItemBrowserControl *owner ,
1641 DataBrowserItemNotification message,
1642 DataBrowserItemDataRef itemData ) const
1643 {
1644
1645 wxMacDataBrowserListCtrlControl *lb = dynamic_cast<wxMacDataBrowserListCtrlControl*>(owner);
1646
1647 // we want to depend on as little as possible to make sure tear-down of controls is safe
1648 if ( message == kDataBrowserItemRemoved)
1649 {
1650 if ( lb != NULL && lb->GetClientDataType() == wxClientData_Object )
1651 {
1652 delete (wxClientData*) (m_data);
1653 }
1654
1655 delete this;
1656 return;
1657 }
1658 else if ( message == kDataBrowserItemAdded )
1659 {
1660 // we don't issue events on adding, the item is not really stored in the list yet, so we
1661 // avoid asserts by gettting out now
1662 return ;
1663 }
1664
1665 wxListCtrl *list = wxDynamicCast( owner->GetPeer() , wxListCtrl );
1666 if ( list )
1667 {
1668 bool trigger = false;
1669
1670 wxListEvent event( wxEVT_COMMAND_LIST_ITEM_SELECTED, list->GetId() );
1671 bool isSingle = (list->GetWindowStyle() & wxLC_SINGLE_SEL) != 0;
1672
1673 event.SetEventObject( list );
1674 event.m_itemIndex = owner->GetLineFromItem( this ) ;
1675 if ( !list->IsVirtual() )
1676 {
1677 lb->MacGetColumnInfo(event.m_itemIndex,0,event.m_item);
1678 }
1679
1680 switch (message)
1681 {
1682 case kDataBrowserItemDeselected:
1683 event.SetEventType(wxEVT_COMMAND_LIST_ITEM_DESELECTED);
1684 if ( !isSingle )
1685 trigger = !lb->IsSelectionSuppressed();
1686 break;
1687
1688 case kDataBrowserItemSelected:
1689 trigger = !lb->IsSelectionSuppressed();
1690 break;
1691
1692 case kDataBrowserItemDoubleClicked:
1693 event.SetEventType( wxEVT_COMMAND_LIST_ITEM_ACTIVATED );
1694 trigger = true;
1695 break;
1696
1697 case kDataBrowserEditStarted :
1698 // TODO : how to veto ?
1699 event.SetEventType( wxEVT_COMMAND_LIST_BEGIN_LABEL_EDIT ) ;
1700 trigger = true ;
1701 break ;
1702
1703 case kDataBrowserEditStopped :
1704 // TODO probably trigger only upon the value store callback, because
1705 // here IIRC we cannot veto
1706 event.SetEventType( wxEVT_COMMAND_LIST_END_LABEL_EDIT ) ;
1707 trigger = true ;
1708 break ;
1709
1710 default:
1711 break;
1712 }
1713
1714 if ( trigger )
1715 {
1716 // direct notification is not always having the listbox GetSelection() having in synch with event
1717 wxPostEvent( list->GetEventHandler(), event );
1718 }
1719 }
1720
1721 }
1722
1723 wxMacDataBrowserListCtrlControl::wxMacDataBrowserListCtrlControl( wxWindow *peer, const wxPoint& pos, const wxSize& size, long style)
1724 : wxMacDataItemBrowserControl( peer, pos, size, style )
1725 {
1726 OSStatus err = noErr;
1727 m_clientDataItemsType = wxClientData_None;
1728 m_isVirtual = false;
1729
1730 if ( style & wxLC_VIRTUAL )
1731 m_isVirtual = true;
1732
1733 DataBrowserSelectionFlags options = kDataBrowserDragSelect;
1734 if ( style & wxLC_SINGLE_SEL )
1735 {
1736 options |= kDataBrowserSelectOnlyOne;
1737 }
1738 else
1739 {
1740 options |= kDataBrowserCmdTogglesSelection;
1741 }
1742
1743 err = SetSelectionFlags( options );
1744 verify_noerr( err );
1745
1746 DataBrowserCustomCallbacks callbacks;
1747 InitializeDataBrowserCustomCallbacks( &callbacks, kDataBrowserLatestCustomCallbacks );
1748
1749 if ( gDataBrowserDrawItemUPP == NULL )
1750 gDataBrowserDrawItemUPP = NewDataBrowserDrawItemUPP(DataBrowserDrawItemProc);
1751
1752 // if ( gDataBrowserEditItemUPP == NULL )
1753 // gDataBrowserEditItemUPP = NewDataBrowserEditItemUPP(DataBrowserEditTextProc);
1754
1755 if ( gDataBrowserHitTestUPP == NULL )
1756 gDataBrowserHitTestUPP = NewDataBrowserHitTestUPP(DataBrowserHitTestProc);
1757
1758 callbacks.u.v1.drawItemCallback = gDataBrowserDrawItemUPP;
1759 // callbacks.u.v1.editTextCallback = gDataBrowserEditItemUPP;
1760 callbacks.u.v1.hitTestCallback = gDataBrowserHitTestUPP;
1761
1762 SetDataBrowserCustomCallbacks( GetControlRef(), &callbacks );
1763
1764 if ( style & wxLC_LIST )
1765 {
1766 InsertColumn(0, kDataBrowserIconAndTextType, wxEmptyString, -1, -1);
1767 verify_noerr( AutoSizeColumns() );
1768 }
1769
1770 if ( style & wxLC_LIST || style & wxLC_NO_HEADER )
1771 verify_noerr( SetHeaderButtonHeight( 0 ) );
1772
1773 if ( m_isVirtual )
1774 SetSortProperty( kMinColumnId - 1 );
1775 else
1776 SetSortProperty( kMinColumnId );
1777 if ( style & wxLC_SORT_ASCENDING )
1778 {
1779 m_sortOrder = SortOrder_Text_Ascending;
1780 SetSortOrder( kDataBrowserOrderIncreasing );
1781 }
1782 else if ( style & wxLC_SORT_DESCENDING )
1783 {
1784 m_sortOrder = SortOrder_Text_Descending;
1785 SetSortOrder( kDataBrowserOrderDecreasing );
1786 }
1787 else
1788 {
1789 m_sortOrder = SortOrder_None;
1790 }
1791
1792 if ( style & wxLC_VRULES )
1793 {
1794 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4
1795 verify_noerr( DataBrowserChangeAttributes(m_controlRef, kDataBrowserAttributeListViewDrawColumnDividers, kDataBrowserAttributeNone) );
1796 #endif
1797 }
1798
1799 verify_noerr( SetHiliteStyle(kDataBrowserTableViewFillHilite ) );
1800 err = SetHasScrollBars( (style & wxHSCROLL) != 0 , true );
1801 }
1802
1803 pascal Boolean wxMacDataBrowserListCtrlControl::DataBrowserEditTextProc(
1804 ControlRef browser,
1805 DataBrowserItemID itemID,
1806 DataBrowserPropertyID property,
1807 CFStringRef theString,
1808 Rect *maxEditTextRect,
1809 Boolean *shrinkToFit)
1810 {
1811 Boolean result = false;
1812 wxMacDataBrowserListCtrlControl* ctl = dynamic_cast<wxMacDataBrowserListCtrlControl*>( wxMacControl::GetReferenceFromNativeControl( browser ) );
1813 if ( ctl != 0 )
1814 {
1815 result = ctl->ConfirmEditText(itemID, property, theString, maxEditTextRect, shrinkToFit);
1816 theString = CFSTR("Hello!");
1817 }
1818 return result;
1819 }
1820
1821 bool wxMacDataBrowserListCtrlControl::ConfirmEditText(
1822 DataBrowserItemID itemID,
1823 DataBrowserPropertyID property,
1824 CFStringRef theString,
1825 Rect *maxEditTextRect,
1826 Boolean *shrinkToFit)
1827 {
1828 //wxListCtrl* list = wxDynamicCast( GetPeer() , wxListCtrl );
1829 return false;
1830 }
1831
1832 pascal void wxMacDataBrowserListCtrlControl::DataBrowserDrawItemProc(
1833 ControlRef browser,
1834 DataBrowserItemID itemID,
1835 DataBrowserPropertyID property,
1836 DataBrowserItemState itemState,
1837 const Rect *itemRect,
1838 SInt16 gdDepth,
1839 Boolean colorDevice)
1840 {
1841 wxMacDataBrowserListCtrlControl* ctl = dynamic_cast<wxMacDataBrowserListCtrlControl*>( wxMacControl::GetReferenceFromNativeControl( browser ) );
1842 if ( ctl != 0 )
1843 {
1844 ctl->DrawItem(itemID, property, itemState, itemRect, gdDepth, colorDevice);
1845 }
1846 }
1847
1848 // routines needed for DrawItem
1849 enum
1850 {
1851 kIconWidth = 16,
1852 kIconHeight = 16,
1853 kTextBoxHeight = 14,
1854 kIconTextSpacingV = 2,
1855 kItemPadding = 4,
1856 kContentHeight = kIconHeight + kTextBoxHeight + kIconTextSpacingV
1857 };
1858
1859 static void calculateCGDrawingBounds(CGRect inItemRect, CGRect *outIconRect, CGRect *outTextRect, bool hasIcon = false)
1860 {
1861 float textBottom;
1862 float iconH, iconW = 0;
1863 float padding = kItemPadding;
1864 if (hasIcon)
1865 {
1866 iconH = kIconHeight;
1867 iconW = kIconWidth;
1868 padding = padding*2;
1869 }
1870
1871 textBottom = inItemRect.origin.y;
1872
1873 *outIconRect = CGRectMake(inItemRect.origin.x + kItemPadding,
1874 textBottom + kIconTextSpacingV, kIconWidth,
1875 kIconHeight);
1876
1877 *outTextRect = CGRectMake(inItemRect.origin.x + padding + iconW,
1878 textBottom + kIconTextSpacingV, inItemRect.size.width - padding - iconW,
1879 inItemRect.size.height - kIconTextSpacingV);
1880 }
1881
1882 void wxMacDataBrowserListCtrlControl::DrawItem(
1883 DataBrowserItemID itemID,
1884 DataBrowserPropertyID property,
1885 DataBrowserItemState itemState,
1886 const Rect *itemRect,
1887 SInt16 gdDepth,
1888 Boolean colorDevice)
1889 {
1890 wxString text;
1891 wxFont font = wxNullFont;
1892 int imgIndex = -1;
1893 short listColumn = property - kMinColumnId;
1894
1895 wxListCtrl* list = wxDynamicCast( GetPeer() , wxListCtrl );
1896 wxMacListCtrlItem* lcItem;
1897 wxColour color = *wxBLACK;
1898 wxColour bgColor = wxNullColour;
1899
1900 if (listColumn >= 0)
1901 {
1902 if (!m_isVirtual)
1903 {
1904 lcItem = (wxMacListCtrlItem*) itemID;
1905 if (lcItem->HasColumnInfo(listColumn)){
1906 wxListItem* item = lcItem->GetColumnInfo(listColumn);
1907
1908 // we always use the 0 column to get font and text/background colors.
1909 if (lcItem->HasColumnInfo(0))
1910 {
1911 wxListItem* firstItem = lcItem->GetColumnInfo(0);
1912 color = firstItem->GetTextColour();
1913 bgColor = firstItem->GetBackgroundColour();
1914 font = firstItem->GetFont();
1915 }
1916
1917 if (item->GetMask() & wxLIST_MASK_TEXT)
1918 text = item->GetText();
1919 if (item->GetMask() & wxLIST_MASK_IMAGE)
1920 imgIndex = item->GetImage();
1921 }
1922
1923 }
1924 else
1925 {
1926 text = list->OnGetItemText( (long)itemID-1, listColumn );
1927 imgIndex = list->OnGetItemColumnImage( (long)itemID-1, listColumn );
1928 wxListItemAttr* attrs = list->OnGetItemAttr( (long)itemID-1 );
1929 if (attrs)
1930 {
1931 if (attrs->HasBackgroundColour())
1932 bgColor = attrs->GetBackgroundColour();
1933 if (attrs->HasTextColour())
1934 color = attrs->GetTextColour();
1935 if (attrs->HasFont())
1936 font = attrs->GetFont();
1937 }
1938 }
1939 }
1940
1941 wxColour listBgColor = list->GetBackgroundColour();
1942 if (bgColor == wxNullColour)
1943 bgColor = listBgColor;
1944
1945 wxFont listFont = list->GetFont();
1946 if (font == wxNullFont)
1947 font = listFont;
1948
1949 wxMacCFStringHolder cfString;
1950 cfString.Assign( text, wxLocale::GetSystemEncoding() );
1951
1952 Rect enclosingRect;
1953 CGRect enclosingCGRect, iconCGRect, textCGRect;
1954 Boolean active;
1955 ThemeDrawingState savedState = NULL;
1956 CGContextRef context = (CGContextRef)list->MacGetDrawingContext();
1957 RGBColor labelColor;
1958
1959 GetDataBrowserItemPartBounds(GetControlRef(), itemID, property, kDataBrowserPropertyEnclosingPart,
1960 &enclosingRect);
1961
1962 enclosingCGRect = CGRectMake(enclosingRect.left,
1963 enclosingRect.top,
1964 enclosingRect.right - enclosingRect.left,
1965 enclosingRect.bottom - enclosingRect.top);
1966
1967 active = IsControlActive(GetControlRef());
1968
1969 if (itemState == kDataBrowserItemIsSelected)
1970 {
1971 RGBColor foregroundColor;
1972
1973 GetThemeDrawingState(&savedState);
1974
1975 GetThemeBrushAsColor(kThemeBrushAlternatePrimaryHighlightColor, 32, true, &foregroundColor);
1976 GetThemeTextColor(kThemeTextColorWhite, gdDepth, colorDevice, &labelColor);
1977
1978 CGContextSaveGState(context);
1979
1980 CGContextSetRGBFillColor(context, (float)foregroundColor.red / (float)USHRT_MAX,
1981 (float)foregroundColor.green / (float)USHRT_MAX,
1982 (float)foregroundColor.blue / (float)USHRT_MAX, 1.0);
1983 CGContextFillRect(context, enclosingCGRect);
1984
1985 CGContextRestoreGState(context);
1986 }
1987 else
1988 {
1989
1990 if (color.Ok())
1991 labelColor = MAC_WXCOLORREF( color.GetPixel() );
1992 else if (list->GetTextColour().Ok())
1993 labelColor = MAC_WXCOLORREF( list->GetTextColour().GetPixel() );
1994 else
1995 {
1996 labelColor.red = 0;
1997 labelColor.green = 0;
1998 labelColor.blue = 0;
1999 }
2000
2001 if (bgColor.Ok())
2002 {
2003 RGBColor foregroundColor = MAC_WXCOLORREF( bgColor.GetPixel() );
2004 CGContextSaveGState(context);
2005
2006 CGContextSetRGBFillColor(context, (float)foregroundColor.red / (float)USHRT_MAX,
2007 (float)foregroundColor.green / (float)USHRT_MAX,
2008 (float)foregroundColor.blue / (float)USHRT_MAX, 1.0);
2009 CGContextFillRect(context, enclosingCGRect);
2010
2011 CGContextRestoreGState(context);
2012 }
2013 }
2014
2015 calculateCGDrawingBounds(enclosingCGRect, &iconCGRect, &textCGRect, (imgIndex != -1) );
2016
2017 if (imgIndex != -1)
2018 {
2019 wxImageList* imageList = list->GetImageList(wxIMAGE_LIST_SMALL);
2020 if (imageList && imageList->GetImageCount() > 0){
2021 wxBitmap bmp = imageList->GetBitmap(imgIndex);
2022 IconRef icon = bmp.GetBitmapData()->GetIconRef();
2023
2024 RGBColor iconLabel;
2025 iconLabel.red = 0;
2026 iconLabel.green = 0;
2027 iconLabel.blue = 0;
2028
2029 PlotIconRefInContext(context, &iconCGRect, kAlignNone,
2030 active ? kTransformNone : kTransformDisabled, &iconLabel,
2031 kPlotIconRefNormalFlags, icon);
2032 }
2033 }
2034
2035 HIThemeTextHorizontalFlush hFlush = kHIThemeTextHorizontalFlushLeft;
2036 UInt16 fontID = kThemeViewsFont;
2037
2038 if (font.Ok())
2039 {
2040 if (font.GetFamily() != wxFONTFAMILY_DEFAULT)
2041 fontID = font.MacGetThemeFontID();
2042
2043 // FIXME: replace these with CG or ATSUI calls so we can remove this #ifndef.
2044 #ifndef __LP64__
2045 ::TextSize( (short)(font.MacGetFontSize()) ) ;
2046 ::TextFace( font.MacGetFontStyle() ) ;
2047 #endif
2048 }
2049
2050 wxListItem item;
2051 list->GetColumn(listColumn, item);
2052 if (item.GetMask() & wxLIST_MASK_FORMAT)
2053 {
2054 if (item.GetAlign() == wxLIST_FORMAT_LEFT)
2055 hFlush = kHIThemeTextHorizontalFlushLeft;
2056 else if (item.GetAlign() == wxLIST_FORMAT_CENTER)
2057 hFlush = kHIThemeTextHorizontalFlushCenter;
2058 else if (item.GetAlign() == wxLIST_FORMAT_RIGHT)
2059 {
2060 hFlush = kHIThemeTextHorizontalFlushRight;
2061 textCGRect.origin.x -= kItemPadding; // give a little extra paddding
2062 }
2063 }
2064
2065 HIThemeTextInfo info;
2066 info.version = kHIThemeTextInfoVersionZero;
2067 info.state = active ? kThemeStateActive : kThemeStateInactive;
2068 info.fontID = fontID;
2069 info.horizontalFlushness = hFlush;
2070 info.verticalFlushness = kHIThemeTextVerticalFlushCenter;
2071 info.options = kHIThemeTextBoxOptionNone;
2072 info.truncationPosition = kHIThemeTextTruncationEnd;
2073 info.truncationMaxLines = 1;
2074
2075 CGContextSaveGState(context);
2076 CGContextSetRGBFillColor (context, (float)labelColor.red / (float)USHRT_MAX,
2077 (float)labelColor.green / (float)USHRT_MAX,
2078 (float)labelColor.blue / (float)USHRT_MAX, 1.0);
2079
2080 HIThemeDrawTextBox(cfString, &textCGRect, &info, context, kHIThemeOrientationNormal);
2081
2082 CGContextRestoreGState(context);
2083
2084 if (savedState != NULL)
2085 SetThemeDrawingState(savedState, true);
2086 }
2087
2088 OSStatus wxMacDataBrowserListCtrlControl::GetSetItemData(DataBrowserItemID itemID,
2089 DataBrowserPropertyID property,
2090 DataBrowserItemDataRef itemData,
2091 Boolean changeValue )
2092 {
2093 wxString text;
2094 int imgIndex = -1;
2095 short listColumn = property - kMinColumnId;
2096
2097 OSStatus err = errDataBrowserPropertyNotSupported;
2098 wxListCtrl* list = wxDynamicCast( GetPeer() , wxListCtrl );
2099 wxMacListCtrlItem* lcItem;
2100
2101 if (listColumn >= 0)
2102 {
2103 if (!m_isVirtual)
2104 {
2105 lcItem = (wxMacListCtrlItem*) itemID;
2106 if (lcItem->HasColumnInfo(listColumn)){
2107 wxListItem* item = lcItem->GetColumnInfo(listColumn);
2108 if (item->GetMask() & wxLIST_MASK_TEXT)
2109 text = item->GetText();
2110 if (item->GetMask() & wxLIST_MASK_IMAGE)
2111 imgIndex = item->GetImage();
2112 }
2113 }
2114 else
2115 {
2116 text = list->OnGetItemText( (long)itemID-1, listColumn );
2117 imgIndex = list->OnGetItemColumnImage( (long)itemID-1, listColumn );
2118 }
2119 }
2120
2121 if ( !changeValue )
2122 {
2123 switch (property)
2124 {
2125 case kDataBrowserItemIsEditableProperty :
2126 if ( list && list->HasFlag( wxLC_EDIT_LABELS ) )
2127 {
2128 verify_noerr(SetDataBrowserItemDataBooleanValue( itemData, true ));
2129 err = noErr ;
2130 }
2131 break ;
2132 default :
2133 if ( property >= kMinColumnId )
2134 {
2135 wxMacCFStringHolder cfStr;
2136
2137 if (text){
2138 cfStr.Assign( text, wxLocale::GetSystemEncoding() );
2139 err = ::SetDataBrowserItemDataText( itemData, cfStr );
2140 err = noErr;
2141 }
2142
2143
2144
2145 if ( imgIndex != -1 )
2146 {
2147 wxImageList* imageList = list->GetImageList(wxIMAGE_LIST_SMALL);
2148 if (imageList && imageList->GetImageCount() > 0){
2149 wxBitmap bmp = imageList->GetBitmap(imgIndex);
2150 IconRef icon = bmp.GetBitmapData()->GetIconRef();
2151 ::SetDataBrowserItemDataIcon(itemData, icon);
2152 }
2153 }
2154
2155 }
2156 break ;
2157 }
2158
2159 }
2160 else
2161 {
2162 switch (property)
2163 {
2164 default:
2165 if ( property >= kMinColumnId )
2166 {
2167 short listColumn = property - kMinColumnId;
2168
2169 // TODO probably send the 'end edit' from here, as we
2170 // can then deal with the veto
2171 CFStringRef sr ;
2172 verify_noerr( GetDataBrowserItemDataText( itemData , &sr ) ) ;
2173 wxMacCFStringHolder cfStr(sr) ;;
2174 if (m_isVirtual)
2175 list->SetItem( (long)itemData-1 , listColumn, cfStr.AsString() ) ;
2176 else
2177 {
2178 if (lcItem)
2179 lcItem->SetColumnTextValue( listColumn, cfStr.AsString() );
2180 }
2181 err = noErr ;
2182 }
2183 break;
2184 }
2185 }
2186 return err;
2187 }
2188
2189 void wxMacDataBrowserListCtrlControl::ItemNotification(DataBrowserItemID itemID,
2190 DataBrowserItemNotification message,
2191 DataBrowserItemDataRef itemData )
2192 {
2193 // we want to depend on as little as possible to make sure tear-down of controls is safe
2194 if ( message == kDataBrowserItemRemoved)
2195 {
2196 // make sure MacDelete does the proper teardown.
2197 return;
2198 }
2199 else if ( message == kDataBrowserItemAdded )
2200 {
2201 // we don't issue events on adding, the item is not really stored in the list yet, so we
2202 // avoid asserts by getting out now
2203 return ;
2204 }
2205
2206 wxListCtrl *list = wxDynamicCast( GetPeer() , wxListCtrl );
2207 if ( list )
2208 {
2209 bool trigger = false;
2210
2211 wxListEvent event( wxEVT_COMMAND_LIST_ITEM_SELECTED, list->GetId() );
2212 bool isSingle = (list->GetWindowStyle() & wxLC_SINGLE_SEL) != 0;
2213
2214 event.SetEventObject( list );
2215 if ( !list->IsVirtual() )
2216 {
2217 DataBrowserTableViewRowIndex result = 0;
2218 verify_noerr( GetItemRow( itemID, &result ) ) ;
2219 event.m_itemIndex = result;
2220
2221 if (event.m_itemIndex >= 0)
2222 MacGetColumnInfo(event.m_itemIndex,0,event.m_item);
2223 }
2224 else
2225 {
2226 event.m_itemIndex = (long)itemID;
2227 }
2228
2229 switch (message)
2230 {
2231 case kDataBrowserItemDeselected:
2232 event.SetEventType(wxEVT_COMMAND_LIST_ITEM_DESELECTED);
2233 if ( !isSingle )
2234 trigger = !IsSelectionSuppressed();
2235 break;
2236
2237 case kDataBrowserItemSelected:
2238 trigger = !IsSelectionSuppressed();
2239
2240 break;
2241
2242 case kDataBrowserItemDoubleClicked:
2243 event.SetEventType( wxEVT_COMMAND_LIST_ITEM_ACTIVATED );
2244 trigger = true;
2245 break;
2246
2247 case kDataBrowserEditStarted :
2248 // TODO : how to veto ?
2249 event.SetEventType( wxEVT_COMMAND_LIST_BEGIN_LABEL_EDIT ) ;
2250 trigger = true ;
2251 break ;
2252
2253 case kDataBrowserEditStopped :
2254 // TODO probably trigger only upon the value store callback, because
2255 // here IIRC we cannot veto
2256 event.SetEventType( wxEVT_COMMAND_LIST_END_LABEL_EDIT ) ;
2257 trigger = true ;
2258 break ;
2259
2260 default:
2261 break;
2262 }
2263
2264 if ( trigger )
2265 {
2266 // direct notification is not always having the listbox GetSelection() having in synch with event
2267 wxPostEvent( list->GetEventHandler(), event );
2268 }
2269 }
2270 }
2271
2272 Boolean wxMacDataBrowserListCtrlControl::CompareItems(DataBrowserItemID itemOneID,
2273 DataBrowserItemID itemTwoID,
2274 DataBrowserPropertyID sortProperty)
2275 {
2276
2277 bool retval = false;
2278 wxString itemText;
2279 wxString otherItemText;
2280 int colId = sortProperty - kMinColumnId;
2281 long itemNum = 0;
2282 long otherItemNum = 0;
2283
2284 wxListCtrl* list = wxDynamicCast( GetPeer() , wxListCtrl );
2285
2286 // means we need to
2287 if (colId >= 0)
2288 {
2289 if (!m_isVirtual)
2290 {
2291 wxMacListCtrlItem* item = (wxMacListCtrlItem*)itemOneID;
2292 wxMacListCtrlItem* otherItem = (wxMacListCtrlItem*)itemTwoID;
2293 wxListCtrlCompare func = list->GetCompareFunc();
2294 if (func != NULL && item->HasColumnInfo(colId) && otherItem->HasColumnInfo(colId))
2295 return func(item->GetColumnInfo(colId)->GetData(), otherItem->GetColumnInfo(colId)->GetData(), list->GetCompareFuncData()) >= 0;
2296
2297 itemNum = item->GetOrder();
2298 otherItemNum = otherItem->GetOrder();
2299 if (item->HasColumnInfo(colId))
2300 itemText = item->GetColumnInfo(colId)->GetText();
2301 if (otherItem->HasColumnInfo(colId))
2302 otherItemText = otherItem->GetColumnInfo(colId)->GetText();
2303 }
2304 else
2305 {
2306 itemNum = (long)itemOneID;
2307 otherItemNum = (long)itemTwoID;
2308 itemText = list->OnGetItemText( itemNum-1, colId );
2309 otherItemText = list->OnGetItemText( otherItemNum-1, colId );
2310
2311 }
2312
2313 DataBrowserSortOrder sort;
2314 verify_noerr(GetSortOrder(&sort));
2315
2316 if ( sort == kDataBrowserOrderIncreasing )
2317 {
2318 retval = itemText.CmpNoCase( otherItemText ) > 0;
2319 }
2320 else if ( sort == kDataBrowserOrderDecreasing )
2321 {
2322 retval = itemText.CmpNoCase( otherItemText ) < 0;
2323 }
2324 }
2325 else{
2326 // fallback for undefined cases
2327 retval = itemOneID < itemTwoID;
2328 }
2329
2330 return retval;
2331 }
2332
2333 wxMacDataBrowserListCtrlControl::~wxMacDataBrowserListCtrlControl()
2334 {
2335 }
2336
2337 void wxMacDataBrowserListCtrlControl::MacSetColumnInfo( unsigned int row, unsigned int column, wxListItem* item )
2338 {
2339 wxMacDataItem* dataItem = GetItemFromLine(row);
2340 if (item)
2341 {
2342 wxMacListCtrlItem* listItem = dynamic_cast<wxMacListCtrlItem*>(dataItem);
2343 listItem->SetColumnInfo( column, item );
2344 UpdateState(dataItem, item);
2345 }
2346 }
2347
2348 // apply changes that need to happen immediately, rather than when the
2349 // databrowser control fires a callback.
2350 void wxMacDataBrowserListCtrlControl::UpdateState(wxMacDataItem* dataItem, wxListItem* listItem)
2351 {
2352 bool isSelected = IsItemSelected( dataItem );
2353 bool isSelectedState = (listItem->GetState() == wxLIST_STATE_SELECTED);
2354
2355 // toggle the selection state if wxListInfo state and actual state don't match.
2356 if ( isSelected != isSelectedState )
2357 {
2358 DataBrowserSetOption options = kDataBrowserItemsAdd;
2359 if (!isSelectedState)
2360 options = kDataBrowserItemsRemove;
2361 SetSelectedItem(dataItem, options);
2362 }
2363 // TODO: Set column width if item width > than current column width
2364 }
2365
2366 void wxMacDataBrowserListCtrlControl::MacGetColumnInfo( unsigned int row, unsigned int column, wxListItem& item )
2367 {
2368 wxMacDataItem* dataItem = GetItemFromLine(row);
2369 // CS should this guard against dataItem = 0 ? , as item is not a pointer if (item) is not appropriate
2370 //if (item)
2371 {
2372 wxMacListCtrlItem* listItem = dynamic_cast<wxMacListCtrlItem*>(dataItem);
2373 wxListItem* oldItem = listItem->GetColumnInfo( column );
2374
2375 long mask = item.GetMask();
2376 if ( !mask )
2377 // by default, get everything for backwards compatibility
2378 mask = -1;
2379
2380 if ( mask & wxLIST_MASK_TEXT )
2381 item.SetText(oldItem->GetText());
2382 if ( mask & wxLIST_MASK_IMAGE )
2383 item.SetImage(oldItem->GetImage());
2384 if ( mask & wxLIST_MASK_DATA )
2385 item.SetData(oldItem->GetData());
2386 if ( mask & wxLIST_MASK_STATE )
2387 item.SetState(oldItem->GetState());
2388 if ( mask & wxLIST_MASK_WIDTH )
2389 item.SetWidth(oldItem->GetWidth());
2390 if ( mask & wxLIST_MASK_FORMAT )
2391 item.SetAlign(oldItem->GetAlign());
2392
2393 item.SetTextColour(oldItem->GetTextColour());
2394 item.SetBackgroundColour(oldItem->GetBackgroundColour());
2395 item.SetFont(oldItem->GetFont());
2396 }
2397 }
2398
2399 void wxMacDataBrowserListCtrlControl::MacInsertItem( unsigned int n, wxListItem* item )
2400 {
2401 wxMacDataItemBrowserControl::MacInsert(n, item->GetText());
2402 MacSetColumnInfo(n, 0, item);
2403 }
2404
2405 wxMacDataItem* wxMacDataBrowserListCtrlControl::CreateItem()
2406 {
2407 return new wxMacListCtrlItem();
2408 }
2409
2410 wxMacListCtrlItem::wxMacListCtrlItem()
2411 {
2412 m_rowItems = wxListItemList();
2413 }
2414
2415 int wxMacListCtrlItem::GetColumnImageValue( unsigned int column )
2416 {
2417 return GetColumnInfo(column)->GetImage();
2418 }
2419
2420 void wxMacListCtrlItem::SetColumnImageValue( unsigned int column, int imageIndex )
2421 {
2422 GetColumnInfo(column)->SetImage(imageIndex);
2423 }
2424
2425 const wxString& wxMacListCtrlItem::GetColumnTextValue( unsigned int column )
2426 {
2427 if ( column == 0 )
2428 return GetLabel();
2429
2430 return GetColumnInfo(column)->GetText();
2431 }
2432
2433 void wxMacListCtrlItem::SetColumnTextValue( unsigned int column, const wxString& text )
2434 {
2435 GetColumnInfo(column)->SetText(text);
2436
2437 // for compatibility with superclass APIs
2438 if ( column == 0 )
2439 SetLabel(text);
2440 }
2441
2442 wxListItem* wxMacListCtrlItem::GetColumnInfo( unsigned int column )
2443 {
2444 wxListItemList::compatibility_iterator node = m_rowItems.Item( column );
2445 wxASSERT_MSG( node, _T("invalid column index in wxMacListCtrlItem") );
2446
2447 return node->GetData();
2448 }
2449
2450 bool wxMacListCtrlItem::HasColumnInfo( unsigned int column )
2451 {
2452 return m_rowItems.GetCount() > column;
2453 }
2454
2455 void wxMacListCtrlItem::SetColumnInfo( unsigned int column, wxListItem* item )
2456 {
2457
2458 if ( column >= m_rowItems.GetCount() )
2459 {
2460 wxListItem* listItem = new wxListItem(*item);
2461 m_rowItems.Append( listItem );
2462 }
2463 else
2464 {
2465 wxListItem* listItem = GetColumnInfo( column );
2466 long mask = item->GetMask();
2467 if (mask & wxLIST_MASK_TEXT)
2468 listItem->SetText(item->GetText());
2469 if (mask & wxLIST_MASK_DATA)
2470 listItem->SetData(item->GetData());
2471 if (mask & wxLIST_MASK_IMAGE)
2472 listItem->SetImage(item->GetImage());
2473 if (mask & wxLIST_MASK_STATE)
2474 listItem->SetState(item->GetState());
2475 if (mask & wxLIST_MASK_FORMAT)
2476 listItem->SetAlign(item->GetAlign());
2477 if (mask & wxLIST_MASK_WIDTH)
2478 listItem->SetWidth(item->GetWidth());
2479
2480 listItem->SetTextColour(item->GetTextColour());
2481 listItem->SetBackgroundColour(item->GetBackgroundColour());
2482 listItem->SetFont(item->GetFont());
2483 }
2484 }
2485
2486 #endif // wxUSE_LISTCTRL