]> git.saurik.com Git - wxWidgets.git/blob - src/mac/carbon/listctrl_mac.cpp
changed wxHAS_NATIVE_OVERLAY and wxHAS_CARET_USING_OVERLAYS to use #ifdef instead...
[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 m_dbImpl->MacGetColumnInfo(info.m_itemId, info.m_col, info);
722 bool success = true;
723 return success;
724 }
725
726 // Sets information about the item
727 bool wxListCtrl::SetItem(wxListItem& info)
728 {
729 if (m_genericImpl)
730 return m_genericImpl->SetItem(info);
731
732 if (m_dbImpl)
733 m_dbImpl->MacSetColumnInfo( info.m_itemId, info.m_col, &info );
734
735 return true;
736 }
737
738 long wxListCtrl::SetItem(long index, int col, const wxString& label, int imageId)
739 {
740 if (m_genericImpl)
741 return m_genericImpl->SetItem(index, col, label, imageId);
742
743 wxListItem info;
744 info.m_text = label;
745 info.m_mask = wxLIST_MASK_TEXT;
746 info.m_itemId = index;
747 info.m_col = col;
748 if ( imageId > -1 )
749 {
750 info.m_image = imageId;
751 info.m_mask |= wxLIST_MASK_IMAGE;
752 }
753 return SetItem(info);
754 }
755
756
757 // Gets the item state
758 int wxListCtrl::GetItemState(long item, long stateMask) const
759 {
760 if (m_genericImpl)
761 return m_genericImpl->GetItemState(item, stateMask);
762
763 wxListItem info;
764
765 info.m_mask = wxLIST_MASK_STATE;
766 info.m_stateMask = stateMask;
767 info.m_itemId = item;
768
769 if (!GetItem(info))
770 return 0;
771
772 return info.m_state;
773 }
774
775 // Sets the item state
776 bool wxListCtrl::SetItemState(long item, long state, long stateMask)
777 {
778 if (m_genericImpl)
779 return m_genericImpl->SetItemState(item, state, stateMask);
780
781 wxListItem info;
782 info.m_mask = wxLIST_MASK_STATE;
783 info.m_stateMask = stateMask;
784 info.m_state = state;
785 info.m_itemId = item;
786 return SetItem(info);
787 }
788
789 // Sets the item image
790 bool wxListCtrl::SetItemImage(long item, int image, int WXUNUSED(selImage))
791 {
792 return SetItemColumnImage(item, 0, image);
793 }
794
795 // Sets the item image
796 bool wxListCtrl::SetItemColumnImage(long item, long column, int image)
797 {
798 if (m_genericImpl)
799 return m_genericImpl->SetItemColumnImage(item, column, image);
800
801 wxListItem info;
802
803 info.m_mask = wxLIST_MASK_IMAGE;
804 info.m_image = image;
805 info.m_itemId = item;
806 info.m_col = column;
807
808 return SetItem(info);
809 }
810
811 // Gets the item text
812 wxString wxListCtrl::GetItemText(long item) const
813 {
814 if (m_genericImpl)
815 return m_genericImpl->GetItemText(item);
816
817 wxListItem info;
818
819 info.m_mask = wxLIST_MASK_TEXT;
820 info.m_itemId = item;
821
822 if (!GetItem(info))
823 return wxEmptyString;
824 return info.m_text;
825 }
826
827 // Sets the item text
828 void wxListCtrl::SetItemText(long item, const wxString& str)
829 {
830 if (m_genericImpl)
831 return m_genericImpl->SetItemText(item, str);
832
833 wxListItem info;
834
835 info.m_mask = wxLIST_MASK_TEXT;
836 info.m_itemId = item;
837 info.m_text = str;
838
839 SetItem(info);
840 }
841
842 // Gets the item data
843 long wxListCtrl::GetItemData(long item) const
844 {
845 if (m_genericImpl)
846 return m_genericImpl->GetItemData(item);
847
848 wxListItem info;
849
850 info.m_mask = wxLIST_MASK_DATA;
851 info.m_itemId = item;
852
853 if (!GetItem(info))
854 return 0;
855 return info.m_data;
856 }
857
858 // Sets the item data
859 bool wxListCtrl::SetItemData(long item, long data)
860 {
861 if (m_genericImpl)
862 return m_genericImpl->SetItemData(item, data);
863
864 wxListItem info;
865
866 info.m_mask = wxLIST_MASK_DATA;
867 info.m_itemId = item;
868 info.m_data = data;
869
870 return SetItem(info);
871 }
872
873 wxRect wxListCtrl::GetViewRect() const
874 {
875 wxASSERT_MSG( !HasFlag(wxLC_REPORT | wxLC_LIST),
876 _T("wxListCtrl::GetViewRect() only works in icon mode") );
877
878 if (m_genericImpl)
879 return m_genericImpl->GetViewRect();
880
881 wxRect rect;
882 return rect;
883 }
884
885 // Gets the item rectangle
886 bool wxListCtrl::GetItemRect(long item, wxRect& rect, int code) const
887 {
888 if (m_genericImpl)
889 return m_genericImpl->GetItemRect(item, rect, code);
890
891 return true;
892 }
893
894 // Gets the item position
895 bool wxListCtrl::GetItemPosition(long item, wxPoint& pos) const
896 {
897 if (m_genericImpl)
898 return m_genericImpl->GetItemPosition(item, pos);
899
900 bool success = false;
901
902 return success;
903 }
904
905 // Sets the item position.
906 bool wxListCtrl::SetItemPosition(long item, const wxPoint& pos)
907 {
908 if (m_genericImpl)
909 return m_genericImpl->SetItemPosition(item, pos);
910
911 return false;
912 }
913
914 // Gets the number of items in the list control
915 int wxListCtrl::GetItemCount() const
916 {
917 if (m_genericImpl)
918 return m_genericImpl->GetItemCount();
919
920 if (m_dbImpl)
921 return m_dbImpl->MacGetCount();
922
923 return m_count;
924 }
925
926 void wxListCtrl::SetItemSpacing( int spacing, bool isSmall )
927 {
928 if (m_genericImpl)
929 m_genericImpl->SetItemSpacing(spacing, isSmall);
930 }
931
932 wxSize wxListCtrl::GetItemSpacing() const
933 {
934 if (m_genericImpl)
935 return m_genericImpl->GetItemSpacing();
936
937 return wxSize(0, 0);
938 }
939
940 void wxListCtrl::SetItemTextColour( long item, const wxColour &col )
941 {
942 if (m_genericImpl)
943 {
944 m_genericImpl->SetItemTextColour(item, col);
945 return;
946 }
947
948 wxListItem info;
949 info.m_itemId = item;
950 info.SetTextColour( col );
951 SetItem( info );
952 }
953
954 wxColour wxListCtrl::GetItemTextColour( long item ) const
955 {
956 if (m_genericImpl)
957 return m_genericImpl->GetItemTextColour(item);
958
959 if (m_dbImpl)
960 {
961 wxListItem info;
962 if (GetItem(info))
963 return info.GetTextColour();
964 }
965 return wxNullColour;
966 }
967
968 void wxListCtrl::SetItemBackgroundColour( long item, const wxColour &col )
969 {
970 if (m_genericImpl)
971 {
972 m_genericImpl->SetItemBackgroundColour(item, col);
973 return;
974 }
975
976 wxListItem info;
977 info.m_itemId = item;
978 info.SetBackgroundColour( col );
979 SetItem( info );
980 }
981
982 wxColour wxListCtrl::GetItemBackgroundColour( long item ) const
983 {
984 if (m_genericImpl)
985 return m_genericImpl->GetItemBackgroundColour(item);
986
987 if (m_dbImpl)
988 {
989 wxListItem info;
990 if (GetItem(info))
991 return info.GetBackgroundColour();
992 }
993 return wxNullColour;
994 }
995
996 void wxListCtrl::SetItemFont( long item, const wxFont &f )
997 {
998 if (m_genericImpl)
999 {
1000 m_genericImpl->SetItemFont(item, f);
1001 return;
1002 }
1003
1004 wxListItem info;
1005 info.m_itemId = item;
1006 info.SetFont( f );
1007 SetItem( info );
1008 }
1009
1010 wxFont wxListCtrl::GetItemFont( long item ) const
1011 {
1012 if (m_genericImpl)
1013 return m_genericImpl->GetItemFont(item);
1014
1015 if (m_dbImpl)
1016 {
1017 wxListItem info;
1018 if (GetItem(info))
1019 return info.GetFont();
1020 }
1021
1022 return wxNullFont;
1023 }
1024
1025 // Gets the number of selected items in the list control
1026 int wxListCtrl::GetSelectedItemCount() const
1027 {
1028 if (m_genericImpl)
1029 return m_genericImpl->GetSelectedItemCount();
1030
1031 if (m_dbImpl)
1032 return m_dbImpl->GetSelectedItemCount(NULL, true);
1033
1034 return 0;
1035 }
1036
1037 // Gets the text colour of the listview
1038 wxColour wxListCtrl::GetTextColour() const
1039 {
1040 if (m_genericImpl)
1041 return m_genericImpl->GetTextColour();
1042
1043 // TODO: we need owner drawn list items to customize text color.
1044 if (m_dbImpl)
1045 return m_textColor;
1046
1047 return wxNullColour;
1048 }
1049
1050 // Sets the text colour of the listview
1051 void wxListCtrl::SetTextColour(const wxColour& col)
1052 {
1053 if (m_genericImpl)
1054 {
1055 m_genericImpl->SetTextColour(col);
1056 return;
1057 }
1058
1059 if (m_dbImpl)
1060 m_textColor = col;
1061 }
1062
1063 // Gets the index of the topmost visible item when in
1064 // list or report view
1065 long wxListCtrl::GetTopItem() const
1066 {
1067 if (m_genericImpl)
1068 return m_genericImpl->GetTopItem();
1069
1070 return 0;
1071 }
1072
1073 // Searches for an item, starting from 'item'.
1074 // 'geometry' is one of
1075 // wxLIST_NEXT_ABOVE/ALL/BELOW/LEFT/RIGHT.
1076 // 'state' is a state bit flag, one or more of
1077 // wxLIST_STATE_DROPHILITED/FOCUSED/SELECTED/CUT.
1078 // item can be -1 to find the first item that matches the
1079 // specified flags.
1080 // Returns the item or -1 if unsuccessful.
1081 long wxListCtrl::GetNextItem(long item, int geom, int state) const
1082 {
1083 if (m_genericImpl)
1084 return m_genericImpl->GetNextItem(item, geom, state);
1085
1086 if (m_dbImpl && geom == wxLIST_NEXT_ALL && state == wxLIST_STATE_SELECTED )
1087 {
1088 long count = m_dbImpl->MacGetCount() ;
1089 for ( long line = item + 1 ; line < count; line++ )
1090 {
1091 wxMacDataItem* id = m_dbImpl->GetItemFromLine(line);
1092 if ( m_dbImpl->IsItemSelected(id ) )
1093 return line;
1094 }
1095 return -1;
1096 }
1097
1098 return 0;
1099 }
1100
1101
1102 wxImageList *wxListCtrl::GetImageList(int which) const
1103 {
1104 if (m_genericImpl)
1105 return m_genericImpl->GetImageList(which);
1106
1107 if ( which == wxIMAGE_LIST_NORMAL )
1108 {
1109 return m_imageListNormal;
1110 }
1111 else if ( which == wxIMAGE_LIST_SMALL )
1112 {
1113 return m_imageListSmall;
1114 }
1115 else if ( which == wxIMAGE_LIST_STATE )
1116 {
1117 return m_imageListState;
1118 }
1119 return NULL;
1120 }
1121
1122 void wxListCtrl::SetImageList(wxImageList *imageList, int which)
1123 {
1124 if (m_genericImpl)
1125 {
1126 m_genericImpl->SetImageList(imageList, which);
1127 return;
1128 }
1129
1130 if ( which == wxIMAGE_LIST_NORMAL )
1131 {
1132 if (m_ownsImageListNormal) delete m_imageListNormal;
1133 m_imageListNormal = imageList;
1134 m_ownsImageListNormal = false;
1135 }
1136 else if ( which == wxIMAGE_LIST_SMALL )
1137 {
1138 if (m_ownsImageListSmall) delete m_imageListSmall;
1139 m_imageListSmall = imageList;
1140 m_ownsImageListSmall = false;
1141 }
1142 else if ( which == wxIMAGE_LIST_STATE )
1143 {
1144 if (m_ownsImageListState) delete m_imageListState;
1145 m_imageListState = imageList;
1146 m_ownsImageListState = false;
1147 }
1148 }
1149
1150 void wxListCtrl::AssignImageList(wxImageList *imageList, int which)
1151 {
1152 if (m_genericImpl)
1153 {
1154 m_genericImpl->AssignImageList(imageList, which);
1155 return;
1156 }
1157
1158 SetImageList(imageList, which);
1159 if ( which == wxIMAGE_LIST_NORMAL )
1160 m_ownsImageListNormal = true;
1161 else if ( which == wxIMAGE_LIST_SMALL )
1162 m_ownsImageListSmall = true;
1163 else if ( which == wxIMAGE_LIST_STATE )
1164 m_ownsImageListState = true;
1165 }
1166
1167 // ----------------------------------------------------------------------------
1168 // Operations
1169 // ----------------------------------------------------------------------------
1170
1171 // Arranges the items
1172 bool wxListCtrl::Arrange(int flag)
1173 {
1174 if (m_genericImpl)
1175 return m_genericImpl->Arrange(flag);
1176 return false;
1177 }
1178
1179 // Deletes an item
1180 bool wxListCtrl::DeleteItem(long item)
1181 {
1182 if (m_genericImpl)
1183 return m_genericImpl->DeleteItem(item);
1184
1185 if (m_dbImpl)
1186 {
1187 m_dbImpl->MacDelete(item);
1188 wxListEvent event( wxEVT_COMMAND_LIST_DELETE_ITEM, GetId() );
1189 event.SetEventObject( this );
1190 event.m_itemIndex = item;
1191 GetEventHandler()->ProcessEvent( event );
1192
1193 }
1194 return true;
1195 }
1196
1197 // Deletes all items
1198 bool wxListCtrl::DeleteAllItems()
1199 {
1200 if (m_genericImpl)
1201 return m_genericImpl->DeleteAllItems();
1202
1203 if (m_dbImpl)
1204 {
1205 m_dbImpl->MacClear();
1206 wxListEvent event( wxEVT_COMMAND_LIST_DELETE_ALL_ITEMS, GetId() );
1207 event.SetEventObject( this );
1208 GetEventHandler()->ProcessEvent( event );
1209 }
1210 return true;
1211 }
1212
1213 // Deletes all items
1214 bool wxListCtrl::DeleteAllColumns()
1215 {
1216 if (m_genericImpl)
1217 return m_genericImpl->DeleteAllColumns();
1218
1219 if (m_dbImpl)
1220 {
1221 UInt32 cols;
1222 m_dbImpl->GetColumnCount(&cols);
1223 for (UInt32 col = 0; col < cols; col++)
1224 {
1225 DeleteColumn(col);
1226 }
1227 }
1228
1229 return true;
1230 }
1231
1232 // Deletes a column
1233 bool wxListCtrl::DeleteColumn(int col)
1234 {
1235 if (m_genericImpl)
1236 return m_genericImpl->DeleteColumn(col);
1237
1238 if (m_dbImpl)
1239 {
1240 OSStatus err = m_dbImpl->RemoveColumn(col);
1241 return err == noErr;
1242 }
1243
1244 return true;
1245 }
1246
1247 // Clears items, and columns if there are any.
1248 void wxListCtrl::ClearAll()
1249 {
1250 if (m_genericImpl)
1251 {
1252 m_genericImpl->ClearAll();
1253 return;
1254 }
1255
1256 if (m_dbImpl)
1257 {
1258 DeleteAllItems();
1259 DeleteAllColumns();
1260 }
1261 }
1262
1263 wxTextCtrl* wxListCtrl::EditLabel(long item, wxClassInfo* textControlClass)
1264 {
1265 if (m_genericImpl)
1266 return m_genericImpl->EditLabel(item, textControlClass);
1267
1268 if (m_dbImpl)
1269 {
1270 wxMacDataItem* id = m_dbImpl->GetItemFromLine(item);
1271 verify_noerr( SetDataBrowserEditItem(m_dbImpl->GetControlRef(), (DataBrowserItemID)id, kMinColumnId) );
1272 }
1273 return NULL;
1274 }
1275
1276 // End label editing, optionally cancelling the edit
1277 bool wxListCtrl::EndEditLabel(bool cancel)
1278 {
1279 // TODO: generic impl. doesn't have this method - is it needed for us?
1280 if (m_genericImpl)
1281 return true; // m_genericImpl->EndEditLabel(cancel);
1282
1283 if (m_dbImpl)
1284 verify_noerr( SetDataBrowserEditItem(m_dbImpl->GetControlRef(), kDataBrowserNoItem, kMinColumnId) );
1285 return true;
1286 }
1287
1288 // Ensures this item is visible
1289 bool wxListCtrl::EnsureVisible(long item)
1290 {
1291 if (m_genericImpl)
1292 return m_genericImpl->EnsureVisible(item);
1293
1294 if (m_dbImpl)
1295 {
1296 wxMacDataItem* dataItem = m_dbImpl->GetItemFromLine(item);
1297 m_dbImpl->RevealItem(dataItem, kDataBrowserRevealWithoutSelecting);
1298 }
1299
1300 return true;
1301 }
1302
1303 // Find an item whose label matches this string, starting from the item after 'start'
1304 // or the beginning if 'start' is -1.
1305 long wxListCtrl::FindItem(long start, const wxString& str, bool partial)
1306 {
1307 if (m_genericImpl)
1308 return m_genericImpl->FindItem(start, str, partial);
1309
1310 return -1;
1311 }
1312
1313 // Find an item whose data matches this data, starting from the item after 'start'
1314 // or the beginning if 'start' is -1.
1315 long wxListCtrl::FindItem(long start, long data)
1316 {
1317 if (m_genericImpl)
1318 return m_genericImpl->FindItem(start, data);
1319
1320 long idx = start + 1;
1321 long count = GetItemCount();
1322
1323 while (idx < count)
1324 {
1325 if (GetItemData(idx) == data)
1326 return idx;
1327 idx++;
1328 };
1329
1330 return -1;
1331 }
1332
1333 // Find an item nearest this position in the specified direction, starting from
1334 // the item after 'start' or the beginning if 'start' is -1.
1335 long wxListCtrl::FindItem(long start, const wxPoint& pt, int direction)
1336 {
1337 if (m_genericImpl)
1338 return m_genericImpl->FindItem(start, pt, direction);
1339 return -1;
1340 }
1341
1342 // Determines which item (if any) is at the specified point,
1343 // giving details in 'flags' (see wxLIST_HITTEST_... flags above)
1344 long
1345 wxListCtrl::HitTest(const wxPoint& point, int& flags, long *ptrSubItem) const
1346 {
1347 if (m_genericImpl)
1348 return m_genericImpl->HitTest(point, flags, ptrSubItem);
1349
1350 return -1;
1351 }
1352
1353
1354 // Inserts an item, returning the index of the new item if successful,
1355 // -1 otherwise.
1356 long wxListCtrl::InsertItem(wxListItem& info)
1357 {
1358 wxASSERT_MSG( !IsVirtual(), _T("can't be used with virtual controls") );
1359
1360 if (m_genericImpl)
1361 return m_genericImpl->InsertItem(info);
1362
1363 if (m_dbImpl)
1364 {
1365 int count = GetItemCount();
1366
1367 if (info.m_itemId > count)
1368 info.m_itemId = count;
1369
1370 m_dbImpl->MacInsertItem(info.m_itemId, &info );
1371 wxListEvent event( wxEVT_COMMAND_LIST_INSERT_ITEM, GetId() );
1372 event.SetEventObject( this );
1373 event.m_itemIndex = info.m_itemId;
1374 GetEventHandler()->ProcessEvent( event );
1375 }
1376
1377 return info.m_itemId;
1378 }
1379
1380 long wxListCtrl::InsertItem(long index, const wxString& label)
1381 {
1382 if (m_genericImpl)
1383 return m_genericImpl->InsertItem(index, label);
1384
1385 wxListItem info;
1386 info.m_text = label;
1387 info.m_mask = wxLIST_MASK_TEXT;
1388 info.m_itemId = index;
1389 return InsertItem(info);
1390 }
1391
1392 // Inserts an image item
1393 long wxListCtrl::InsertItem(long index, int imageIndex)
1394 {
1395 if (m_genericImpl)
1396 return m_genericImpl->InsertItem(index, imageIndex);
1397
1398 wxListItem info;
1399 info.m_image = imageIndex;
1400 info.m_mask = wxLIST_MASK_IMAGE;
1401 info.m_itemId = index;
1402 return InsertItem(info);
1403 }
1404
1405 // Inserts an image/string item
1406 long wxListCtrl::InsertItem(long index, const wxString& label, int imageIndex)
1407 {
1408 if (m_genericImpl)
1409 return m_genericImpl->InsertItem(index, label, imageIndex);
1410
1411 wxListItem info;
1412 info.m_image = imageIndex;
1413 info.m_text = label;
1414 info.m_mask = wxLIST_MASK_IMAGE | wxLIST_MASK_TEXT;
1415 info.m_itemId = index;
1416 return InsertItem(info);
1417 }
1418
1419 // For list view mode (only), inserts a column.
1420 long wxListCtrl::InsertColumn(long col, wxListItem& item)
1421 {
1422 if (m_genericImpl)
1423 return m_genericImpl->InsertColumn(col, item);
1424
1425 if (m_dbImpl)
1426 {
1427 int width = item.GetWidth();
1428 if ( !(item.GetMask() & wxLIST_MASK_WIDTH) )
1429 width = 150;
1430
1431 DataBrowserPropertyType type = kDataBrowserCustomType; //kDataBrowserTextType;
1432 wxImageList* imageList = GetImageList(wxIMAGE_LIST_SMALL);
1433 if (imageList && imageList->GetImageCount() > 0)
1434 {
1435 wxBitmap bmp = imageList->GetBitmap(0);
1436 //if (bmp.Ok())
1437 // type = kDataBrowserIconAndTextType;
1438 }
1439
1440 SInt16 just = teFlushDefault;
1441 if (item.GetMask() & wxLIST_MASK_FORMAT)
1442 {
1443 if (item.GetAlign() == wxLIST_FORMAT_LEFT)
1444 just = teFlushLeft;
1445 else if (item.GetAlign() == wxLIST_FORMAT_CENTER)
1446 just = teCenter;
1447 else if (item.GetAlign() == wxLIST_FORMAT_RIGHT)
1448 just = teFlushRight;
1449 }
1450 m_dbImpl->InsertColumn(col, type, item.GetText(), just, width);
1451 SetColumn(col, item);
1452
1453 // set/remove options based on the wxListCtrl type.
1454 DataBrowserTableViewColumnID id;
1455 m_dbImpl->GetColumnIDFromIndex(col, &id);
1456 DataBrowserPropertyFlags flags;
1457 verify_noerr(m_dbImpl->GetPropertyFlags(id, &flags));
1458 if (GetWindowStyleFlag() & wxLC_EDIT_LABELS)
1459 flags |= kDataBrowserPropertyIsEditable;
1460
1461 if (GetWindowStyleFlag() & wxLC_VIRTUAL){
1462 flags &= ~kDataBrowserListViewSortableColumn;
1463 }
1464 verify_noerr(m_dbImpl->SetPropertyFlags(id, flags));
1465 }
1466
1467 return col;
1468 }
1469
1470 long wxListCtrl::InsertColumn(long col,
1471 const wxString& heading,
1472 int format,
1473 int width)
1474 {
1475 if (m_genericImpl)
1476 return m_genericImpl->InsertColumn(col, heading, format, width);
1477
1478 wxListItem item;
1479 item.m_mask = wxLIST_MASK_TEXT | wxLIST_MASK_FORMAT;
1480 item.m_text = heading;
1481 if ( width > -1 )
1482 {
1483 item.m_mask |= wxLIST_MASK_WIDTH;
1484 item.m_width = width;
1485 }
1486 item.m_format = format;
1487
1488 return InsertColumn(col, item);
1489 }
1490
1491 // scroll the control by the given number of pixels (exception: in list view,
1492 // dx is interpreted as number of columns)
1493 bool wxListCtrl::ScrollList(int dx, int dy)
1494 {
1495 if (m_genericImpl)
1496 return m_genericImpl->ScrollList(dx, dy);
1497
1498 if (m_dbImpl)
1499 {
1500 m_dbImpl->SetScrollPosition(dx, dy);
1501 }
1502 return true;
1503 }
1504
1505
1506 bool wxListCtrl::SortItems(wxListCtrlCompare fn, long data)
1507 {
1508 if (m_genericImpl)
1509 return m_genericImpl->SortItems(fn, data);
1510
1511 if (m_dbImpl)
1512 {
1513 m_compareFunc = fn;
1514 m_compareFuncData = data;
1515 }
1516
1517 return true;
1518 }
1519
1520 // ----------------------------------------------------------------------------
1521 // virtual list controls
1522 // ----------------------------------------------------------------------------
1523
1524 wxString wxListCtrl::OnGetItemText(long WXUNUSED(item), long WXUNUSED(col)) const
1525 {
1526 // this is a pure virtual function, in fact - which is not really pure
1527 // because the controls which are not virtual don't need to implement it
1528 wxFAIL_MSG( _T("wxListCtrl::OnGetItemText not supposed to be called") );
1529
1530 return wxEmptyString;
1531 }
1532
1533 int wxListCtrl::OnGetItemImage(long WXUNUSED(item)) const
1534 {
1535 wxCHECK_MSG(!GetImageList(wxIMAGE_LIST_SMALL),
1536 -1,
1537 wxT("List control has an image list, OnGetItemImage or OnGetItemColumnImage should be overridden."));
1538 return -1;
1539 }
1540
1541 int wxListCtrl::OnGetItemColumnImage(long item, long column) const
1542 {
1543 if (!column)
1544 return OnGetItemImage(item);
1545
1546 return -1;
1547 }
1548
1549 wxListItemAttr *wxListCtrl::OnGetItemAttr(long WXUNUSED_UNLESS_DEBUG(item)) const
1550 {
1551 wxASSERT_MSG( item >= 0 && item < GetItemCount(),
1552 _T("invalid item index in OnGetItemAttr()") );
1553
1554 // no attributes by default
1555 return NULL;
1556 }
1557
1558 void wxListCtrl::SetItemCount(long count)
1559 {
1560 wxASSERT_MSG( IsVirtual(), _T("this is for virtual controls only") );
1561
1562 if (m_genericImpl)
1563 {
1564 m_genericImpl->SetItemCount(count);
1565 return;
1566 }
1567
1568 if (m_dbImpl)
1569 {
1570 // we need to temporarily disable the new item creation notification
1571 // procedure to speed things up
1572 // FIXME: Even this doesn't seem to help much...
1573 DataBrowserCallbacks callbacks;
1574 DataBrowserItemNotificationUPP itemUPP;
1575 GetDataBrowserCallbacks(m_dbImpl->GetControlRef(), &callbacks);
1576 itemUPP = callbacks.u.v1.itemNotificationCallback;
1577 callbacks.u.v1.itemNotificationCallback = 0;
1578 m_dbImpl->SetCallbacks(&callbacks);
1579 ::AddDataBrowserItems(m_dbImpl->GetControlRef(), kDataBrowserNoItem,
1580 count, NULL, kDataBrowserItemNoProperty);
1581 callbacks.u.v1.itemNotificationCallback = itemUPP;
1582 m_dbImpl->SetCallbacks(&callbacks);
1583 }
1584 m_count = count;
1585 }
1586
1587 void wxListCtrl::RefreshItem(long item)
1588 {
1589 if (m_genericImpl)
1590 {
1591 m_genericImpl->RefreshItem(item);
1592 return;
1593 }
1594
1595 wxRect rect;
1596 GetItemRect(item, rect);
1597 RefreshRect(rect);
1598 }
1599
1600 void wxListCtrl::RefreshItems(long itemFrom, long itemTo)
1601 {
1602 if (m_genericImpl)
1603 {
1604 m_genericImpl->RefreshItems(itemFrom, itemTo);
1605 return;
1606 }
1607
1608 wxRect rect1, rect2;
1609 GetItemRect(itemFrom, rect1);
1610 GetItemRect(itemTo, rect2);
1611
1612 wxRect rect = rect1;
1613 rect.height = rect2.GetBottom() - rect1.GetTop();
1614
1615 RefreshRect(rect);
1616 }
1617
1618
1619 // wxMac internal data structures
1620
1621 wxMacListCtrlItem::~wxMacListCtrlItem()
1622 {
1623 }
1624
1625 void wxMacListCtrlItem::Notification(wxMacDataItemBrowserControl *owner ,
1626 DataBrowserItemNotification message,
1627 DataBrowserItemDataRef itemData ) const
1628 {
1629
1630 wxMacDataBrowserListCtrlControl *lb = dynamic_cast<wxMacDataBrowserListCtrlControl*>(owner);
1631
1632 // we want to depend on as little as possible to make sure tear-down of controls is safe
1633 if ( message == kDataBrowserItemRemoved)
1634 {
1635 if ( lb != NULL && lb->GetClientDataType() == wxClientData_Object )
1636 {
1637 delete (wxClientData*) (m_data);
1638 }
1639
1640 delete this;
1641 return;
1642 }
1643 else if ( message == kDataBrowserItemAdded )
1644 {
1645 // we don't issue events on adding, the item is not really stored in the list yet, so we
1646 // avoid asserts by gettting out now
1647 return ;
1648 }
1649
1650 wxListCtrl *list = wxDynamicCast( owner->GetPeer() , wxListCtrl );
1651 if ( list )
1652 {
1653 bool trigger = false;
1654
1655 wxListEvent event( wxEVT_COMMAND_LIST_ITEM_SELECTED, list->GetId() );
1656 bool isSingle = (list->GetWindowStyle() & wxLC_SINGLE_SEL) != 0;
1657
1658 event.SetEventObject( list );
1659 event.m_itemIndex = owner->GetLineFromItem( this ) ;
1660 if ( !list->IsVirtual() )
1661 {
1662 lb->MacGetColumnInfo(event.m_itemIndex,0,event.m_item);
1663 }
1664
1665 switch (message)
1666 {
1667 case kDataBrowserItemDeselected:
1668 event.SetEventType(wxEVT_COMMAND_LIST_ITEM_DESELECTED);
1669 if ( !isSingle )
1670 trigger = !lb->IsSelectionSuppressed();
1671 break;
1672
1673 case kDataBrowserItemSelected:
1674 trigger = !lb->IsSelectionSuppressed();
1675 break;
1676
1677 case kDataBrowserItemDoubleClicked:
1678 event.SetEventType( wxEVT_COMMAND_LIST_ITEM_ACTIVATED );
1679 trigger = true;
1680 break;
1681
1682 case kDataBrowserEditStarted :
1683 // TODO : how to veto ?
1684 event.SetEventType( wxEVT_COMMAND_LIST_BEGIN_LABEL_EDIT ) ;
1685 trigger = true ;
1686 break ;
1687
1688 case kDataBrowserEditStopped :
1689 // TODO probably trigger only upon the value store callback, because
1690 // here IIRC we cannot veto
1691 event.SetEventType( wxEVT_COMMAND_LIST_END_LABEL_EDIT ) ;
1692 trigger = true ;
1693 break ;
1694
1695 default:
1696 break;
1697 }
1698
1699 if ( trigger )
1700 {
1701 // direct notification is not always having the listbox GetSelection() having in synch with event
1702 wxPostEvent( list->GetEventHandler(), event );
1703 }
1704 }
1705
1706 }
1707
1708 wxMacDataBrowserListCtrlControl::wxMacDataBrowserListCtrlControl( wxWindow *peer, const wxPoint& pos, const wxSize& size, long style)
1709 : wxMacDataItemBrowserControl( peer, pos, size, style )
1710 {
1711 OSStatus err = noErr;
1712 m_clientDataItemsType = wxClientData_None;
1713 m_isVirtual = false;
1714
1715 if ( style & wxLC_VIRTUAL )
1716 m_isVirtual = true;
1717
1718 DataBrowserSelectionFlags options = kDataBrowserDragSelect;
1719 if ( style & wxLC_SINGLE_SEL )
1720 {
1721 options |= kDataBrowserSelectOnlyOne;
1722 }
1723 else
1724 {
1725 options |= kDataBrowserCmdTogglesSelection;
1726 }
1727
1728 err = SetSelectionFlags( options );
1729 verify_noerr( err );
1730
1731 DataBrowserCustomCallbacks callbacks;
1732 InitializeDataBrowserCustomCallbacks( &callbacks, kDataBrowserLatestCustomCallbacks );
1733
1734 if ( gDataBrowserDrawItemUPP == NULL )
1735 gDataBrowserDrawItemUPP = NewDataBrowserDrawItemUPP(DataBrowserDrawItemProc);
1736
1737 // if ( gDataBrowserEditItemUPP == NULL )
1738 // gDataBrowserEditItemUPP = NewDataBrowserEditItemUPP(DataBrowserEditTextProc);
1739
1740 if ( gDataBrowserHitTestUPP == NULL )
1741 gDataBrowserHitTestUPP = NewDataBrowserHitTestUPP(DataBrowserHitTestProc);
1742
1743 callbacks.u.v1.drawItemCallback = gDataBrowserDrawItemUPP;
1744 // callbacks.u.v1.editTextCallback = gDataBrowserEditItemUPP;
1745 callbacks.u.v1.hitTestCallback = gDataBrowserHitTestUPP;
1746
1747 SetDataBrowserCustomCallbacks( GetControlRef(), &callbacks );
1748
1749 if ( style & wxLC_LIST )
1750 {
1751 InsertColumn(0, kDataBrowserIconAndTextType, wxEmptyString, -1, -1);
1752 verify_noerr( AutoSizeColumns() );
1753 }
1754
1755 if ( style & wxLC_LIST || style & wxLC_NO_HEADER )
1756 verify_noerr( SetHeaderButtonHeight( 0 ) );
1757
1758 if ( m_isVirtual )
1759 SetSortProperty( kMinColumnId - 1 );
1760 else
1761 SetSortProperty( kMinColumnId );
1762 if ( style & wxLC_SORT_ASCENDING )
1763 {
1764 m_sortOrder = SortOrder_Text_Ascending;
1765 SetSortOrder( kDataBrowserOrderIncreasing );
1766 }
1767 else if ( style & wxLC_SORT_DESCENDING )
1768 {
1769 m_sortOrder = SortOrder_Text_Descending;
1770 SetSortOrder( kDataBrowserOrderDecreasing );
1771 }
1772 else
1773 {
1774 m_sortOrder = SortOrder_None;
1775 }
1776
1777 if ( style & wxLC_VRULES )
1778 {
1779 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4
1780 verify_noerr( DataBrowserChangeAttributes(m_controlRef, kDataBrowserAttributeListViewDrawColumnDividers, kDataBrowserAttributeNone) );
1781 #endif
1782 }
1783
1784 verify_noerr( SetHiliteStyle(kDataBrowserTableViewFillHilite ) );
1785 err = SetHasScrollBars( (style & wxHSCROLL) != 0 , true );
1786 }
1787
1788 pascal Boolean wxMacDataBrowserListCtrlControl::DataBrowserEditTextProc(
1789 ControlRef browser,
1790 DataBrowserItemID itemID,
1791 DataBrowserPropertyID property,
1792 CFStringRef theString,
1793 Rect *maxEditTextRect,
1794 Boolean *shrinkToFit)
1795 {
1796 Boolean result = false;
1797 wxMacDataBrowserListCtrlControl* ctl = dynamic_cast<wxMacDataBrowserListCtrlControl*>( wxMacControl::GetReferenceFromNativeControl( browser ) );
1798 if ( ctl != 0 )
1799 {
1800 result = ctl->ConfirmEditText(itemID, property, theString, maxEditTextRect, shrinkToFit);
1801 theString = CFSTR("Hello!");
1802 }
1803 return result;
1804 }
1805
1806 bool wxMacDataBrowserListCtrlControl::ConfirmEditText(
1807 DataBrowserItemID itemID,
1808 DataBrowserPropertyID property,
1809 CFStringRef theString,
1810 Rect *maxEditTextRect,
1811 Boolean *shrinkToFit)
1812 {
1813 //wxListCtrl* list = wxDynamicCast( GetPeer() , wxListCtrl );
1814 return false;
1815 }
1816
1817 pascal void wxMacDataBrowserListCtrlControl::DataBrowserDrawItemProc(
1818 ControlRef browser,
1819 DataBrowserItemID itemID,
1820 DataBrowserPropertyID property,
1821 DataBrowserItemState itemState,
1822 const Rect *itemRect,
1823 SInt16 gdDepth,
1824 Boolean colorDevice)
1825 {
1826 wxMacDataBrowserListCtrlControl* ctl = dynamic_cast<wxMacDataBrowserListCtrlControl*>( wxMacControl::GetReferenceFromNativeControl( browser ) );
1827 if ( ctl != 0 )
1828 {
1829 ctl->DrawItem(itemID, property, itemState, itemRect, gdDepth, colorDevice);
1830 }
1831 }
1832
1833 // routines needed for DrawItem
1834 enum
1835 {
1836 kIconWidth = 16,
1837 kIconHeight = 16,
1838 kTextBoxHeight = 14,
1839 kIconTextSpacingV = 2,
1840 kItemPadding = 4,
1841 kContentHeight = kIconHeight + kTextBoxHeight + kIconTextSpacingV
1842 };
1843
1844 static void calculateCGDrawingBounds(CGRect inItemRect, CGRect *outIconRect, CGRect *outTextRect, bool hasIcon = false)
1845 {
1846 float textBottom;
1847 float iconH, iconW = 0;
1848 float padding = kItemPadding;
1849 if (hasIcon)
1850 {
1851 iconH = kIconHeight;
1852 iconW = kIconWidth;
1853 padding = padding*2;
1854 }
1855
1856 textBottom = inItemRect.origin.y;
1857
1858 *outIconRect = CGRectMake(inItemRect.origin.x + kItemPadding,
1859 textBottom + kIconTextSpacingV, kIconWidth,
1860 kIconHeight);
1861
1862 *outTextRect = CGRectMake(inItemRect.origin.x + padding + iconW,
1863 textBottom + kIconTextSpacingV, inItemRect.size.width - padding - iconW,
1864 inItemRect.size.height - kIconTextSpacingV);
1865 }
1866
1867 void wxMacDataBrowserListCtrlControl::DrawItem(
1868 DataBrowserItemID itemID,
1869 DataBrowserPropertyID property,
1870 DataBrowserItemState itemState,
1871 const Rect *itemRect,
1872 SInt16 gdDepth,
1873 Boolean colorDevice)
1874 {
1875 wxString text;
1876 wxFont font = wxNullFont;
1877 int imgIndex = -1;
1878 short listColumn = property - kMinColumnId;
1879
1880 wxListCtrl* list = wxDynamicCast( GetPeer() , wxListCtrl );
1881 wxMacListCtrlItem* lcItem;
1882 wxColour color = *wxBLACK;
1883 wxColour bgColor = wxNullColour;
1884
1885 if (listColumn >= 0)
1886 {
1887 if (!m_isVirtual)
1888 {
1889 lcItem = (wxMacListCtrlItem*) itemID;
1890 if (lcItem->HasColumnInfo(listColumn)){
1891 wxListItem* item = lcItem->GetColumnInfo(listColumn);
1892
1893 // we always use the 0 column to get font and text/background colors.
1894 if (lcItem->HasColumnInfo(0))
1895 {
1896 wxListItem* firstItem = lcItem->GetColumnInfo(0);
1897 color = firstItem->GetTextColour();
1898 bgColor = firstItem->GetBackgroundColour();
1899 font = firstItem->GetFont();
1900 }
1901
1902 if (item->GetMask() & wxLIST_MASK_TEXT)
1903 text = item->GetText();
1904 if (item->GetMask() & wxLIST_MASK_IMAGE)
1905 imgIndex = item->GetImage();
1906 }
1907
1908 }
1909 else
1910 {
1911 text = list->OnGetItemText( (long)itemID-1, listColumn );
1912 imgIndex = list->OnGetItemColumnImage( (long)itemID-1, listColumn );
1913 wxListItemAttr* attrs = list->OnGetItemAttr( (long)itemID-1 );
1914 if (attrs)
1915 {
1916 if (attrs->HasBackgroundColour())
1917 bgColor = attrs->GetBackgroundColour();
1918 if (attrs->HasTextColour())
1919 color = attrs->GetTextColour();
1920 if (attrs->HasFont())
1921 font = attrs->GetFont();
1922 }
1923 }
1924 }
1925
1926 wxColour listBgColor = list->GetBackgroundColour();
1927 if (bgColor == wxNullColour)
1928 bgColor = listBgColor;
1929
1930 wxFont listFont = list->GetFont();
1931 if (font == wxNullFont)
1932 font = listFont;
1933
1934 wxMacCFStringHolder cfString;
1935 cfString.Assign( text, wxLocale::GetSystemEncoding() );
1936
1937 Rect enclosingRect;
1938 CGRect enclosingCGRect, iconCGRect, textCGRect;
1939 Boolean active;
1940 ThemeDrawingState savedState = NULL;
1941 CGContextRef context = (CGContextRef)list->MacGetDrawingContext();
1942 RGBColor labelColor;
1943
1944 GetDataBrowserItemPartBounds(GetControlRef(), itemID, property, kDataBrowserPropertyEnclosingPart,
1945 &enclosingRect);
1946
1947 enclosingCGRect = CGRectMake(enclosingRect.left,
1948 enclosingRect.top,
1949 enclosingRect.right - enclosingRect.left,
1950 enclosingRect.bottom - enclosingRect.top);
1951
1952 active = IsControlActive(GetControlRef());
1953
1954 if (itemState == kDataBrowserItemIsSelected)
1955 {
1956 RGBColor foregroundColor;
1957
1958 GetThemeDrawingState(&savedState);
1959
1960 GetThemeBrushAsColor(kThemeBrushAlternatePrimaryHighlightColor, 32, true, &foregroundColor);
1961 GetThemeTextColor(kThemeTextColorWhite, gdDepth, colorDevice, &labelColor);
1962
1963 CGContextSaveGState(context);
1964
1965 CGContextSetRGBFillColor(context, (float)foregroundColor.red / (float)USHRT_MAX,
1966 (float)foregroundColor.green / (float)USHRT_MAX,
1967 (float)foregroundColor.blue / (float)USHRT_MAX, 1.0);
1968 CGContextFillRect(context, enclosingCGRect);
1969
1970 CGContextRestoreGState(context);
1971 }
1972 else
1973 {
1974
1975 if (color.Ok())
1976 labelColor = MAC_WXCOLORREF( color.GetPixel() );
1977 else if (list->GetTextColour().Ok())
1978 labelColor = MAC_WXCOLORREF( list->GetTextColour().GetPixel() );
1979 else
1980 {
1981 labelColor.red = 0;
1982 labelColor.green = 0;
1983 labelColor.blue = 0;
1984 }
1985
1986 if (bgColor.Ok())
1987 {
1988 RGBColor foregroundColor = MAC_WXCOLORREF( bgColor.GetPixel() );
1989 CGContextSaveGState(context);
1990
1991 CGContextSetRGBFillColor(context, (float)foregroundColor.red / (float)USHRT_MAX,
1992 (float)foregroundColor.green / (float)USHRT_MAX,
1993 (float)foregroundColor.blue / (float)USHRT_MAX, 1.0);
1994 CGContextFillRect(context, enclosingCGRect);
1995
1996 CGContextRestoreGState(context);
1997 }
1998 }
1999
2000 calculateCGDrawingBounds(enclosingCGRect, &iconCGRect, &textCGRect, (imgIndex != -1) );
2001
2002 if (imgIndex != -1)
2003 {
2004 wxImageList* imageList = list->GetImageList(wxIMAGE_LIST_SMALL);
2005 if (imageList && imageList->GetImageCount() > 0){
2006 wxBitmap bmp = imageList->GetBitmap(imgIndex);
2007 IconRef icon = bmp.GetBitmapData()->GetIconRef();
2008
2009 RGBColor iconLabel;
2010 iconLabel.red = 0;
2011 iconLabel.green = 0;
2012 iconLabel.blue = 0;
2013
2014 PlotIconRefInContext(context, &iconCGRect, kAlignNone,
2015 active ? kTransformNone : kTransformDisabled, &iconLabel,
2016 kPlotIconRefNormalFlags, icon);
2017 }
2018 }
2019
2020 HIThemeTextHorizontalFlush hFlush = kHIThemeTextHorizontalFlushLeft;
2021 UInt16 fontID = kThemeViewsFont;
2022
2023 if (font.Ok())
2024 {
2025 if (font.GetFamily() != wxFONTFAMILY_DEFAULT)
2026 fontID = font.MacGetThemeFontID();
2027
2028 // FIXME: replace these with CG or ATSUI calls so we can remove this #ifndef.
2029 #ifndef __LP64__
2030 ::TextSize( (short)(font.MacGetFontSize()) ) ;
2031 ::TextFace( font.MacGetFontStyle() ) ;
2032 #endif
2033 }
2034
2035 wxListItem item;
2036 list->GetColumn(listColumn, item);
2037 if (item.GetMask() & wxLIST_MASK_FORMAT)
2038 {
2039 if (item.GetAlign() == wxLIST_FORMAT_LEFT)
2040 hFlush = kHIThemeTextHorizontalFlushLeft;
2041 else if (item.GetAlign() == wxLIST_FORMAT_CENTER)
2042 hFlush = kHIThemeTextHorizontalFlushCenter;
2043 else if (item.GetAlign() == wxLIST_FORMAT_RIGHT)
2044 {
2045 hFlush = kHIThemeTextHorizontalFlushRight;
2046 textCGRect.origin.x -= kItemPadding; // give a little extra paddding
2047 }
2048 }
2049
2050 HIThemeTextInfo info;
2051 info.version = kHIThemeTextInfoVersionZero;
2052 info.state = active ? kThemeStateActive : kThemeStateInactive;
2053 info.fontID = fontID;
2054 info.horizontalFlushness = hFlush;
2055 info.verticalFlushness = kHIThemeTextVerticalFlushCenter;
2056 info.options = kHIThemeTextBoxOptionNone;
2057 info.truncationPosition = kHIThemeTextTruncationEnd;
2058 info.truncationMaxLines = 1;
2059
2060 CGContextSaveGState(context);
2061 CGContextSetRGBFillColor (context, (float)labelColor.red / (float)USHRT_MAX,
2062 (float)labelColor.green / (float)USHRT_MAX,
2063 (float)labelColor.blue / (float)USHRT_MAX, 1.0);
2064
2065 HIThemeDrawTextBox(cfString, &textCGRect, &info, context, kHIThemeOrientationNormal);
2066
2067 CGContextRestoreGState(context);
2068
2069 if (savedState != NULL)
2070 SetThemeDrawingState(savedState, true);
2071 }
2072
2073 OSStatus wxMacDataBrowserListCtrlControl::GetSetItemData(DataBrowserItemID itemID,
2074 DataBrowserPropertyID property,
2075 DataBrowserItemDataRef itemData,
2076 Boolean changeValue )
2077 {
2078 wxString text;
2079 int imgIndex = -1;
2080 short listColumn = property - kMinColumnId;
2081
2082 OSStatus err = errDataBrowserPropertyNotSupported;
2083 wxListCtrl* list = wxDynamicCast( GetPeer() , wxListCtrl );
2084 wxMacListCtrlItem* lcItem;
2085
2086 if (listColumn >= 0)
2087 {
2088 if (!m_isVirtual)
2089 {
2090 lcItem = (wxMacListCtrlItem*) itemID;
2091 if (lcItem->HasColumnInfo(listColumn)){
2092 wxListItem* item = lcItem->GetColumnInfo(listColumn);
2093 if (item->GetMask() & wxLIST_MASK_TEXT)
2094 text = item->GetText();
2095 if (item->GetMask() & wxLIST_MASK_IMAGE)
2096 imgIndex = item->GetImage();
2097 }
2098 }
2099 else
2100 {
2101 text = list->OnGetItemText( (long)itemID-1, listColumn );
2102 imgIndex = list->OnGetItemColumnImage( (long)itemID-1, listColumn );
2103 }
2104 }
2105
2106 if ( !changeValue )
2107 {
2108 switch (property)
2109 {
2110 case kDataBrowserItemIsEditableProperty :
2111 if ( list && list->HasFlag( wxLC_EDIT_LABELS ) )
2112 {
2113 verify_noerr(SetDataBrowserItemDataBooleanValue( itemData, true ));
2114 err = noErr ;
2115 }
2116 break ;
2117 default :
2118 if ( property >= kMinColumnId )
2119 {
2120 wxMacCFStringHolder cfStr;
2121
2122 if (text){
2123 cfStr.Assign( text, wxLocale::GetSystemEncoding() );
2124 err = ::SetDataBrowserItemDataText( itemData, cfStr );
2125 err = noErr;
2126 }
2127
2128
2129
2130 if ( imgIndex != -1 )
2131 {
2132 wxImageList* imageList = list->GetImageList(wxIMAGE_LIST_SMALL);
2133 if (imageList && imageList->GetImageCount() > 0){
2134 wxBitmap bmp = imageList->GetBitmap(imgIndex);
2135 IconRef icon = bmp.GetBitmapData()->GetIconRef();
2136 ::SetDataBrowserItemDataIcon(itemData, icon);
2137 }
2138 }
2139
2140 }
2141 break ;
2142 }
2143
2144 }
2145 else
2146 {
2147 switch (property)
2148 {
2149 default:
2150 if ( property >= kMinColumnId )
2151 {
2152 short listColumn = property - kMinColumnId;
2153
2154 // TODO probably send the 'end edit' from here, as we
2155 // can then deal with the veto
2156 CFStringRef sr ;
2157 verify_noerr( GetDataBrowserItemDataText( itemData , &sr ) ) ;
2158 wxMacCFStringHolder cfStr(sr) ;;
2159 if (m_isVirtual)
2160 list->SetItem( (long)itemData-1 , listColumn, cfStr.AsString() ) ;
2161 else
2162 {
2163 if (lcItem)
2164 lcItem->SetColumnTextValue( listColumn, cfStr.AsString() );
2165 }
2166 err = noErr ;
2167 }
2168 break;
2169 }
2170 }
2171 return err;
2172 }
2173
2174 void wxMacDataBrowserListCtrlControl::ItemNotification(DataBrowserItemID itemID,
2175 DataBrowserItemNotification message,
2176 DataBrowserItemDataRef itemData )
2177 {
2178 // we want to depend on as little as possible to make sure tear-down of controls is safe
2179 if ( message == kDataBrowserItemRemoved)
2180 {
2181 // make sure MacDelete does the proper teardown.
2182 return;
2183 }
2184 else if ( message == kDataBrowserItemAdded )
2185 {
2186 // we don't issue events on adding, the item is not really stored in the list yet, so we
2187 // avoid asserts by getting out now
2188 return ;
2189 }
2190
2191 wxListCtrl *list = wxDynamicCast( GetPeer() , wxListCtrl );
2192 if ( list )
2193 {
2194 bool trigger = false;
2195
2196 wxListEvent event( wxEVT_COMMAND_LIST_ITEM_SELECTED, list->GetId() );
2197 bool isSingle = (list->GetWindowStyle() & wxLC_SINGLE_SEL) != 0;
2198
2199 event.SetEventObject( list );
2200 if ( !list->IsVirtual() )
2201 {
2202 DataBrowserTableViewRowIndex result = 0;
2203 verify_noerr( GetItemRow( itemID, &result ) ) ;
2204 event.m_itemIndex = result;
2205
2206 if (event.m_itemIndex >= 0)
2207 MacGetColumnInfo(event.m_itemIndex,0,event.m_item);
2208 }
2209 else
2210 {
2211 event.m_itemIndex = (long)itemID;
2212 }
2213
2214 switch (message)
2215 {
2216 case kDataBrowserItemDeselected:
2217 event.SetEventType(wxEVT_COMMAND_LIST_ITEM_DESELECTED);
2218 if ( !isSingle )
2219 trigger = !IsSelectionSuppressed();
2220 break;
2221
2222 case kDataBrowserItemSelected:
2223 trigger = !IsSelectionSuppressed();
2224
2225 break;
2226
2227 case kDataBrowserItemDoubleClicked:
2228 event.SetEventType( wxEVT_COMMAND_LIST_ITEM_ACTIVATED );
2229 trigger = true;
2230 break;
2231
2232 case kDataBrowserEditStarted :
2233 // TODO : how to veto ?
2234 event.SetEventType( wxEVT_COMMAND_LIST_BEGIN_LABEL_EDIT ) ;
2235 trigger = true ;
2236 break ;
2237
2238 case kDataBrowserEditStopped :
2239 // TODO probably trigger only upon the value store callback, because
2240 // here IIRC we cannot veto
2241 event.SetEventType( wxEVT_COMMAND_LIST_END_LABEL_EDIT ) ;
2242 trigger = true ;
2243 break ;
2244
2245 default:
2246 break;
2247 }
2248
2249 if ( trigger )
2250 {
2251 // direct notification is not always having the listbox GetSelection() having in synch with event
2252 wxPostEvent( list->GetEventHandler(), event );
2253 }
2254 }
2255 }
2256
2257 Boolean wxMacDataBrowserListCtrlControl::CompareItems(DataBrowserItemID itemOneID,
2258 DataBrowserItemID itemTwoID,
2259 DataBrowserPropertyID sortProperty)
2260 {
2261
2262 bool retval = false;
2263 wxString itemText;
2264 wxString otherItemText;
2265 int colId = sortProperty - kMinColumnId;
2266 long itemNum = 0;
2267 long otherItemNum = 0;
2268
2269 wxListCtrl* list = wxDynamicCast( GetPeer() , wxListCtrl );
2270
2271 // means we need to
2272 if (colId >= 0)
2273 {
2274 if (!m_isVirtual)
2275 {
2276 wxMacListCtrlItem* item = (wxMacListCtrlItem*)itemOneID;
2277 wxMacListCtrlItem* otherItem = (wxMacListCtrlItem*)itemTwoID;
2278 wxListCtrlCompare func = list->GetCompareFunc();
2279 if (func != NULL && item->HasColumnInfo(colId) && otherItem->HasColumnInfo(colId))
2280 return func(item->GetColumnInfo(colId)->GetData(), otherItem->GetColumnInfo(colId)->GetData(), list->GetCompareFuncData()) >= 0;
2281
2282 itemNum = item->GetOrder();
2283 otherItemNum = otherItem->GetOrder();
2284 if (item->HasColumnInfo(colId))
2285 itemText = item->GetColumnInfo(colId)->GetText();
2286 if (otherItem->HasColumnInfo(colId))
2287 otherItemText = otherItem->GetColumnInfo(colId)->GetText();
2288 }
2289 else
2290 {
2291 itemNum = (long)itemOneID;
2292 otherItemNum = (long)itemTwoID;
2293 itemText = list->OnGetItemText( itemNum-1, colId );
2294 otherItemText = list->OnGetItemText( otherItemNum-1, colId );
2295
2296 }
2297
2298 DataBrowserSortOrder sort;
2299 verify_noerr(GetSortOrder(&sort));
2300
2301 if ( sort == kDataBrowserOrderIncreasing )
2302 {
2303 retval = itemText.CmpNoCase( otherItemText ) > 0;
2304 }
2305 else if ( sort == kDataBrowserOrderDecreasing )
2306 {
2307 retval = itemText.CmpNoCase( otherItemText ) < 0;
2308 }
2309 }
2310 else{
2311 // fallback for undefined cases
2312 retval = itemOneID < itemTwoID;
2313 }
2314
2315 return retval;
2316 }
2317
2318 wxMacDataBrowserListCtrlControl::~wxMacDataBrowserListCtrlControl()
2319 {
2320 }
2321
2322 void wxMacDataBrowserListCtrlControl::MacSetColumnInfo( unsigned int row, unsigned int column, wxListItem* item )
2323 {
2324 wxMacDataItem* dataItem = GetItemFromLine(row);
2325 if (item)
2326 {
2327 wxMacListCtrlItem* listItem = dynamic_cast<wxMacListCtrlItem*>(dataItem);
2328 listItem->SetColumnInfo( column, item );
2329 UpdateState(dataItem, item);
2330 }
2331 }
2332
2333 // apply changes that need to happen immediately, rather than when the
2334 // databrowser control fires a callback.
2335 void wxMacDataBrowserListCtrlControl::UpdateState(wxMacDataItem* dataItem, wxListItem* listItem)
2336 {
2337 bool isSelected = IsItemSelected( dataItem );
2338 bool isSelectedState = (listItem->GetState() == wxLIST_STATE_SELECTED);
2339
2340 // toggle the selection state if wxListInfo state and actual state don't match.
2341 if ( isSelected != isSelectedState )
2342 {
2343 DataBrowserSetOption options = kDataBrowserItemsAdd;
2344 if (!isSelectedState)
2345 options = kDataBrowserItemsRemove;
2346 SetSelectedItem(dataItem, options);
2347 }
2348 // TODO: Set column width if item width > than current column width
2349 }
2350
2351 void wxMacDataBrowserListCtrlControl::MacGetColumnInfo( unsigned int row, unsigned int column, wxListItem& item )
2352 {
2353 wxMacDataItem* dataItem = GetItemFromLine(row);
2354 // CS should this guard against dataItem = 0 ? , as item is not a pointer if (item) is not appropriate
2355 //if (item)
2356 {
2357 wxMacListCtrlItem* listItem = dynamic_cast<wxMacListCtrlItem*>(dataItem);
2358 wxListItem* oldItem = listItem->GetColumnInfo( column );
2359
2360 long mask = item.GetMask();
2361 if ( !mask )
2362 // by default, get everything for backwards compatibility
2363 mask = -1;
2364
2365 if ( mask & wxLIST_MASK_TEXT )
2366 item.SetText(oldItem->GetText());
2367 if ( mask & wxLIST_MASK_IMAGE )
2368 item.SetImage(oldItem->GetImage());
2369 if ( mask & wxLIST_MASK_DATA )
2370 item.SetData(oldItem->GetData());
2371 if ( mask & wxLIST_MASK_STATE )
2372 item.SetState(oldItem->GetState());
2373 if ( mask & wxLIST_MASK_WIDTH )
2374 item.SetWidth(oldItem->GetWidth());
2375 if ( mask & wxLIST_MASK_FORMAT )
2376 item.SetAlign(oldItem->GetAlign());
2377
2378 item.SetTextColour(oldItem->GetTextColour());
2379 item.SetBackgroundColour(oldItem->GetBackgroundColour());
2380 item.SetFont(oldItem->GetFont());
2381 }
2382 }
2383
2384 void wxMacDataBrowserListCtrlControl::MacInsertItem( unsigned int n, wxListItem* item )
2385 {
2386 wxMacDataItemBrowserControl::MacInsert(n, item->GetText());
2387 MacSetColumnInfo(n, 0, item);
2388 }
2389
2390 wxMacDataItem* wxMacDataBrowserListCtrlControl::CreateItem()
2391 {
2392 return new wxMacListCtrlItem();
2393 }
2394
2395 wxMacListCtrlItem::wxMacListCtrlItem()
2396 {
2397 m_rowItems = wxListItemList();
2398 }
2399
2400 int wxMacListCtrlItem::GetColumnImageValue( unsigned int column )
2401 {
2402 return GetColumnInfo(column)->GetImage();
2403 }
2404
2405 void wxMacListCtrlItem::SetColumnImageValue( unsigned int column, int imageIndex )
2406 {
2407 GetColumnInfo(column)->SetImage(imageIndex);
2408 }
2409
2410 const wxString& wxMacListCtrlItem::GetColumnTextValue( unsigned int column )
2411 {
2412 if ( column == 0 )
2413 return GetLabel();
2414
2415 return GetColumnInfo(column)->GetText();
2416 }
2417
2418 void wxMacListCtrlItem::SetColumnTextValue( unsigned int column, const wxString& text )
2419 {
2420 GetColumnInfo(column)->SetText(text);
2421
2422 // for compatibility with superclass APIs
2423 if ( column == 0 )
2424 SetLabel(text);
2425 }
2426
2427 wxListItem* wxMacListCtrlItem::GetColumnInfo( unsigned int column )
2428 {
2429 wxListItemList::compatibility_iterator node = m_rowItems.Item( column );
2430 wxASSERT_MSG( node, _T("invalid column index in wxMacListCtrlItem") );
2431
2432 return node->GetData();
2433 }
2434
2435 bool wxMacListCtrlItem::HasColumnInfo( unsigned int column )
2436 {
2437 return m_rowItems.GetCount() > column;
2438 }
2439
2440 void wxMacListCtrlItem::SetColumnInfo( unsigned int column, wxListItem* item )
2441 {
2442
2443 if ( column >= m_rowItems.GetCount() )
2444 {
2445 wxListItem* listItem = new wxListItem(*item);
2446 m_rowItems.Append( listItem );
2447 }
2448 else
2449 {
2450 wxListItem* listItem = GetColumnInfo( column );
2451 long mask = item->GetMask();
2452 if (mask & wxLIST_MASK_TEXT)
2453 listItem->SetText(item->GetText());
2454 if (mask & wxLIST_MASK_DATA)
2455 listItem->SetData(item->GetData());
2456 if (mask & wxLIST_MASK_IMAGE)
2457 listItem->SetImage(item->GetImage());
2458 if (mask & wxLIST_MASK_STATE)
2459 listItem->SetState(item->GetState());
2460 if (mask & wxLIST_MASK_FORMAT)
2461 listItem->SetAlign(item->GetAlign());
2462 if (mask & wxLIST_MASK_WIDTH)
2463 listItem->SetWidth(item->GetWidth());
2464
2465 listItem->SetTextColour(item->GetTextColour());
2466 listItem->SetBackgroundColour(item->GetBackgroundColour());
2467 listItem->SetFont(item->GetFont());
2468 }
2469 }
2470
2471 #endif // wxUSE_LISTCTRL