1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/mac/listctrl_mac.cpp
4 // Author: Julian Smart
5 // Modified by: Agron Selimaj
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 // ============================================================================
14 // ============================================================================
16 // ----------------------------------------------------------------------------
18 // ----------------------------------------------------------------------------
20 // For compilers that support precompilation, includes "wx.h".
21 #include "wx/wxprec.h"
29 #include "wx/listctrl.h"
35 #include "wx/mac/uma.h"
37 #include "wx/imaglist.h"
38 #include "wx/sysopt.h"
40 #define wxMAC_ALWAYS_USE_GENERIC_LISTCTRL wxT("mac.listctrl.always_use_generic")
42 #if wxUSE_EXTENDED_RTTI
43 WX_DEFINE_FLAGS( wxListCtrlStyle
)
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
)
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
)
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
)
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
)
88 wxEND_FLAGS( wxListCtrlStyle
)
90 IMPLEMENT_DYNAMIC_CLASS_XTI(wxListCtrl
, wxControl
,"wx/listctrl.h")
92 wxBEGIN_PROPERTIES_TABLE(wxListCtrl
)
93 wxEVENT_PROPERTY( TextUpdated
, wxEVT_COMMAND_TEXT_UPDATED
, wxCommandEvent
)
95 wxPROPERTY_FLAGS( WindowStyle
, wxListCtrlStyle
, long , SetWindowStyleFlag
, GetWindowStyleFlag
, EMPTY_MACROVALUE
, 0 /*flags*/ , wxT("Helpstring") , wxT("group")) // style
96 wxEND_PROPERTIES_TABLE()
98 wxBEGIN_HANDLERS_TABLE(wxListCtrl
)
99 wxEND_HANDLERS_TABLE()
101 wxCONSTRUCTOR_5( wxListCtrl
, wxWindow
* , Parent
, wxWindowID
, Id
, wxPoint
, Position
, wxSize
, Size
, long , WindowStyle
)
104 TODO : Expose more information of a list's layout etc. via appropriate objects (à la NotebookPageInfo)
107 IMPLEMENT_DYNAMIC_CLASS(wxListCtrl
, wxControl
)
110 IMPLEMENT_DYNAMIC_CLASS(wxListView
, wxListCtrl
)
111 IMPLEMENT_DYNAMIC_CLASS(wxListItem
, wxObject
)
113 IMPLEMENT_DYNAMIC_CLASS(wxListEvent
, wxNotifyEvent
)
115 WX_DECLARE_EXPORTED_LIST(wxListItem
, wxListItemList
);
116 #include "wx/listimpl.cpp"
117 WX_DEFINE_LIST(wxListItemList
)
118 WX_DEFINE_LIST(wxColumnList
)
120 // so we can check for column clicks
121 static const EventTypeSpec eventList
[] =
123 { kEventClassControl
, kEventControlHit
},
124 { kEventClassControl
, kEventControlDraw
}
127 static pascal OSStatus
wxMacListCtrlEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
129 OSStatus result
= eventNotHandledErr
;
131 wxMacCarbonEvent
cEvent( event
) ;
133 ControlRef controlRef
;
134 cEvent
.GetParameter( kEventParamDirectObject
, &controlRef
) ;
136 wxListCtrl
*window
= (wxListCtrl
*) data
;
137 wxListEvent
le( wxEVT_COMMAND_LIST_COL_CLICK
, window
->GetId() );
138 le
.SetEventObject( window
);
140 switch ( GetEventKind( event
) )
142 // check if the column was clicked on and fire an event if so
143 case kEventControlHit
:
145 ControlPartCode result
= cEvent
.GetParameter
<ControlPartCode
>(kEventParamControlPart
, typeControlPartCode
) ;
146 if (result
== kControlButtonPart
){
147 DataBrowserPropertyID col
;
148 GetDataBrowserSortProperty(controlRef
, &col
);
149 int column
= col
- kMinColumnId
;
151 window
->GetEventHandler()->ProcessEvent( le
);
153 result
= CallNextEventHandler(handler
, event
);
156 case kEventControlDraw
:
157 CGContextRef context
= cEvent
.GetParameter
<CGContextRef
>(kEventParamCGContextRef
, typeCGContextRef
) ;
158 window
->MacSetDrawingContext(context
);
159 result
= CallNextEventHandler(handler
, event
);
160 window
->MacSetDrawingContext(NULL
);
169 DEFINE_ONE_SHOT_HANDLER_GETTER( wxMacListCtrlEventHandler
)
171 class wxMacListCtrlItem
: public wxMacListBoxItem
176 virtual void Notification(wxMacDataItemBrowserControl
*owner
,
177 DataBrowserItemNotification message
,
178 DataBrowserItemDataRef itemData
) const;
180 virtual void SetColumnInfo( unsigned int column
, wxListItem
* item
);
181 virtual wxListItem
* GetColumnInfo( unsigned int column
);
182 virtual bool HasColumnInfo( unsigned int column
);
184 virtual void SetColumnTextValue( unsigned int column
, const wxString
& text
);
185 virtual const wxString
& GetColumnTextValue( unsigned int column
);
187 virtual int GetColumnImageValue( unsigned int column
);
188 virtual void SetColumnImageValue( unsigned int column
, int imageIndex
);
190 virtual ~wxMacListCtrlItem();
192 wxListItemList m_rowItems
;
195 DataBrowserDrawItemUPP gDataBrowserDrawItemUPP
= NULL
;
196 //DataBrowserEditItemUPP gDataBrowserEditItemUPP = NULL;
197 DataBrowserHitTestUPP gDataBrowserHitTestUPP
= NULL
;
199 // TODO: Make a better name!!
200 class wxMacDataBrowserListCtrlControl
: public wxMacDataItemBrowserControl
203 wxMacDataBrowserListCtrlControl( wxWindow
*peer
, const wxPoint
& pos
, const wxSize
& size
, long style
);
204 virtual ~wxMacDataBrowserListCtrlControl();
206 // create a list item (can be a subclass of wxMacListBoxItem)
208 virtual wxMacDataItem
* CreateItem();
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
);
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
);
222 virtual void ItemNotification(
223 DataBrowserItemID itemID
,
224 DataBrowserItemNotification message
,
225 DataBrowserItemDataRef itemData
);
227 virtual Boolean
CompareItems(DataBrowserItemID itemOneID
,
228 DataBrowserItemID itemTwoID
,
229 DataBrowserPropertyID sortProperty
);
231 static pascal void DataBrowserDrawItemProc(ControlRef browser
,
232 DataBrowserItemID item
,
233 DataBrowserPropertyID property
,
234 DataBrowserItemState itemState
,
237 Boolean colorDevice
);
239 virtual void DrawItem(DataBrowserItemID itemID
,
240 DataBrowserPropertyID property
,
241 DataBrowserItemState itemState
,
242 const Rect
*itemRect
,
244 Boolean colorDevice
);
246 static pascal Boolean
DataBrowserEditTextProc(ControlRef browser
,
247 DataBrowserItemID item
,
248 DataBrowserPropertyID property
,
249 CFStringRef theString
,
250 Rect
*maxEditTextRect
,
251 Boolean
*shrinkToFit
);
253 static pascal Boolean
DataBrowserHitTestProc(ControlRef browser
,
254 DataBrowserItemID itemID
,
255 DataBrowserPropertyID property
,
257 const Rect
*mouseRect
) { return true; }
259 virtual bool ConfirmEditText(DataBrowserItemID item
,
260 DataBrowserPropertyID property
,
261 CFStringRef theString
,
262 Rect
*maxEditTextRect
,
263 Boolean
*shrinkToFit
);
267 wxClientDataType m_clientDataItemsType
;
272 class wxMacListCtrlEventDelegate
: public wxEvtHandler
275 wxMacListCtrlEventDelegate( wxListCtrl
* list
, int id
);
276 virtual bool ProcessEvent( wxEvent
& event
);
283 wxMacListCtrlEventDelegate::wxMacListCtrlEventDelegate( wxListCtrl
* list
, int id
)
289 bool wxMacListCtrlEventDelegate::ProcessEvent( wxEvent
& event
)
291 // even though we use a generic list ctrl underneath, make sure
292 // we present ourselves as wxListCtrl.
293 event
.SetEventObject( m_list
);
296 return wxEvtHandler::ProcessEvent(event
);
299 // ============================================================================
301 // ============================================================================
303 wxMacListControl
* wxListCtrl::GetPeer() const
305 return dynamic_cast<wxMacListControl
*>(m_peer
);
308 // ----------------------------------------------------------------------------
309 // wxListCtrl construction
310 // ----------------------------------------------------------------------------
312 void wxListCtrl::Init()
314 m_imageListNormal
= NULL
;
315 m_imageListSmall
= NULL
;
316 m_imageListState
= NULL
;
318 // keep track of if we created our own image lists, or if they were assigned
320 m_ownsImageListNormal
= m_ownsImageListSmall
= m_ownsImageListState
= false;
324 m_genericImpl
= NULL
;
326 m_compareFunc
= NULL
;
327 m_compareFuncData
= 0;
328 m_colsInfo
= wxColumnList();
329 m_textColor
= wxNullColour
;
330 m_bgColor
= wxNullColour
;
333 class wxGenericListCtrlHook
: public wxGenericListCtrl
336 wxGenericListCtrlHook(wxListCtrl
* parent
,
341 const wxValidator
& validator
,
342 const wxString
& name
)
343 : wxGenericListCtrl(parent
, id
, pos
, size
, style
, validator
, name
),
344 m_nativeListCtrl(parent
)
349 virtual wxListItemAttr
* OnGetItemAttr(long item
) const
351 return m_nativeListCtrl
->OnGetItemAttr(item
);
354 virtual int OnGetItemImage(long item
) const
356 return m_nativeListCtrl
->OnGetItemImage(item
);
359 virtual int OnGetItemColumnImage(long item
, long column
) const
361 return m_nativeListCtrl
->OnGetItemColumnImage(item
, column
);
364 virtual wxString
OnGetItemText(long item
, long column
) const
366 return m_nativeListCtrl
->OnGetItemText(item
, column
);
369 wxListCtrl
* m_nativeListCtrl
;
373 bool wxListCtrl::Create(wxWindow
*parent
,
378 const wxValidator
& validator
,
379 const wxString
& name
)
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
) )
390 m_macIsUserPane
= true;
392 if ( !wxWindow::Create(parent
, id
, pos
, size
, style
, name
) )
394 m_genericImpl
= new wxGenericListCtrlHook(this, id
, pos
, size
, style
, validator
, name
);
395 m_genericImpl
->PushEventHandler( new wxMacListCtrlEventDelegate( this, GetId() ) );
401 m_macIsUserPane
= false;
403 if ( !wxWindow::Create(parent
, id
, pos
, size
, style
, name
) )
405 m_dbImpl
= new wxMacDataBrowserListCtrlControl( this, pos
, size
, style
);
408 MacPostControlCreate( pos
, size
);
410 InstallControlEventHandler( m_peer
->GetControlRef() , GetwxMacListCtrlEventHandlerUPP(),
411 GetEventTypeCount(eventList
), eventList
, this,
412 (EventHandlerRef
*)&m_macListCtrlEventHandler
);
418 wxListCtrl::~wxListCtrl()
422 m_genericImpl
->PopEventHandler(/* deleteHandler = */ true);
425 if (m_ownsImageListNormal
)
426 delete m_imageListNormal
;
427 if (m_ownsImageListSmall
)
428 delete m_imageListSmall
;
429 if (m_ownsImageListState
)
430 delete m_imageListState
;
433 // ----------------------------------------------------------------------------
434 // set/get/change style
435 // ----------------------------------------------------------------------------
437 // Add or remove a single window style
438 void wxListCtrl::SetSingleStyle(long style
, bool add
)
440 long flag
= GetWindowStyleFlag();
442 // Get rid of conflicting styles
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
;
458 SetWindowStyleFlag(flag
);
461 // Set the whole window style
462 void wxListCtrl::SetWindowStyleFlag(long flag
)
464 if ( flag
!= m_windowStyle
)
466 m_windowStyle
= flag
;
470 m_genericImpl
->SetWindowStyleFlag(flag
);
477 void wxListCtrl::DoSetSize( int x
, int y
, int width
, int height
, int sizeFlags
)
479 wxControl::DoSetSize(x
, y
, width
, height
, sizeFlags
);
482 m_genericImpl
->SetSize(x
, y
, width
, height
, sizeFlags
);
485 bool wxListCtrl::SetFont(const wxFont
& font
)
488 rv
= wxControl::SetFont(font
);
490 rv
= m_genericImpl
->SetFont(font
);
494 bool wxListCtrl::SetForegroundColour(const wxColour
& colour
)
498 rv
= m_genericImpl
->SetForegroundColour(colour
);
500 SetTextColour(colour
);
504 bool wxListCtrl::SetBackgroundColour(const wxColour
& colour
)
508 rv
= m_genericImpl
->SetBackgroundColour(colour
);
514 wxColour
wxListCtrl::GetBackgroundColour()
517 return m_genericImpl
->GetBackgroundColour();
524 // ----------------------------------------------------------------------------
526 // ----------------------------------------------------------------------------
528 // Gets information about this column
529 bool wxListCtrl::GetColumn(int col
, wxListItem
& item
) const
532 return m_genericImpl
->GetColumn(col
, item
);
539 wxColumnList::compatibility_iterator node
= m_colsInfo
.Item( col
);
540 wxASSERT_MSG( node
, _T("invalid column index in wxMacListCtrlItem") );
541 wxListItem
* column
= node
->GetData();
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());
561 // Sets information about this column
562 bool wxListCtrl::SetColumn(int col
, wxListItem
& item
)
565 return m_genericImpl
->SetColumn(col
, item
);
569 if ( col
>= (int)m_colsInfo
.GetCount() )
571 wxListItem
* listItem
= new wxListItem(item
);
572 m_colsInfo
.Append( 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());
593 // change the appearance in the databrowser.
594 DataBrowserListViewHeaderDesc columnDesc
;
595 columnDesc
.version
=kDataBrowserListViewLatestHeaderDesc
;
596 verify_noerr( m_dbImpl
->GetHeaderDesc( kMinColumnId
+ col
, &columnDesc
) );
599 if (item.GetMask() & wxLIST_MASK_TEXT)
603 enc = m_font.GetEncoding();
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;
614 if (item
.GetMask() & wxLIST_MASK_IMAGE
&& item
.GetImage() != -1 )
616 columnDesc
.btnContentInfo
.contentType
= kControlContentIconRef
;
617 wxImageList
* imageList
= GetImageList(wxIMAGE_LIST_SMALL
);
618 if (imageList
&& imageList
->GetImageCount() > 0 )
620 wxBitmap bmp
= imageList
->GetBitmap( item
.GetImage() );
621 IconRef icon
= bmp
.GetBitmapData()->GetIconRef();
622 columnDesc
.btnContentInfo
.u
.iconRef
= icon
;
626 verify_noerr( m_dbImpl
->SetHeaderDesc( kMinColumnId
+ col
, &columnDesc
) );
632 int wxListCtrl::GetColumnCount() const
635 return m_genericImpl
->GetColumnCount();
640 m_dbImpl
->GetColumnCount(&count
);
647 // Gets the column width
648 int wxListCtrl::GetColumnWidth(int col
) const
651 return m_genericImpl
->GetColumnWidth(col
);
655 return m_dbImpl
->GetColumnWidth(col
);
661 // Sets the column width
662 bool wxListCtrl::SetColumnWidth(int col
, int width
)
665 return m_genericImpl
->SetColumnWidth(col
, width
);
670 if (width
== wxLIST_AUTOSIZE
|| width
== wxLIST_AUTOSIZE_USEHEADER
)
675 for (int column
= 0; column
< GetColumnCount(); column
++)
677 m_dbImpl
->SetColumnWidth(col
, mywidth
);
681 m_dbImpl
->SetColumnWidth(col
, mywidth
);
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
696 return m_genericImpl
->GetCountPerPage();
705 // Gets the edit control for editing labels.
706 wxTextCtrl
* wxListCtrl::GetEditControl() const
709 return m_genericImpl
->GetEditControl();
714 // Gets information about the item
715 bool wxListCtrl::GetItem(wxListItem
& info
) const
718 return m_genericImpl
->GetItem(info
);
721 m_dbImpl
->MacGetColumnInfo(info
.m_itemId
, info
.m_col
, info
);
726 // Sets information about the item
727 bool wxListCtrl::SetItem(wxListItem
& info
)
730 return m_genericImpl
->SetItem(info
);
733 m_dbImpl
->MacSetColumnInfo( info
.m_itemId
, info
.m_col
, &info
);
738 long wxListCtrl::SetItem(long index
, int col
, const wxString
& label
, int imageId
)
741 return m_genericImpl
->SetItem(index
, col
, label
, imageId
);
745 info
.m_mask
= wxLIST_MASK_TEXT
;
746 info
.m_itemId
= index
;
750 info
.m_image
= imageId
;
751 info
.m_mask
|= wxLIST_MASK_IMAGE
;
753 return SetItem(info
);
757 // Gets the item state
758 int wxListCtrl::GetItemState(long item
, long stateMask
) const
761 return m_genericImpl
->GetItemState(item
, stateMask
);
765 info
.m_mask
= wxLIST_MASK_STATE
;
766 info
.m_stateMask
= stateMask
;
767 info
.m_itemId
= item
;
775 // Sets the item state
776 bool wxListCtrl::SetItemState(long item
, long state
, long stateMask
)
779 return m_genericImpl
->SetItemState(item
, state
, stateMask
);
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
);
789 // Sets the item image
790 bool wxListCtrl::SetItemImage(long item
, int image
, int WXUNUSED(selImage
))
792 return SetItemColumnImage(item
, 0, image
);
795 // Sets the item image
796 bool wxListCtrl::SetItemColumnImage(long item
, long column
, int image
)
799 return m_genericImpl
->SetItemColumnImage(item
, column
, image
);
803 info
.m_mask
= wxLIST_MASK_IMAGE
;
804 info
.m_image
= image
;
805 info
.m_itemId
= item
;
808 return SetItem(info
);
811 // Gets the item text
812 wxString
wxListCtrl::GetItemText(long item
) const
815 return m_genericImpl
->GetItemText(item
);
819 info
.m_mask
= wxLIST_MASK_TEXT
;
820 info
.m_itemId
= item
;
823 return wxEmptyString
;
827 // Sets the item text
828 void wxListCtrl::SetItemText(long item
, const wxString
& str
)
831 return m_genericImpl
->SetItemText(item
, str
);
835 info
.m_mask
= wxLIST_MASK_TEXT
;
836 info
.m_itemId
= item
;
842 // Gets the item data
843 long wxListCtrl::GetItemData(long item
) const
846 return m_genericImpl
->GetItemData(item
);
850 info
.m_mask
= wxLIST_MASK_DATA
;
851 info
.m_itemId
= item
;
858 // Sets the item data
859 bool wxListCtrl::SetItemData(long item
, long data
)
862 return m_genericImpl
->SetItemData(item
, data
);
866 info
.m_mask
= wxLIST_MASK_DATA
;
867 info
.m_itemId
= item
;
870 return SetItem(info
);
873 wxRect
wxListCtrl::GetViewRect() const
875 wxASSERT_MSG( !HasFlag(wxLC_REPORT
| wxLC_LIST
),
876 _T("wxListCtrl::GetViewRect() only works in icon mode") );
879 return m_genericImpl
->GetViewRect();
885 // Gets the item rectangle
886 bool wxListCtrl::GetItemRect(long item
, wxRect
& rect
, int code
) const
889 return m_genericImpl
->GetItemRect(item
, rect
, code
);
894 // Gets the item position
895 bool wxListCtrl::GetItemPosition(long item
, wxPoint
& pos
) const
898 return m_genericImpl
->GetItemPosition(item
, pos
);
900 bool success
= false;
905 // Sets the item position.
906 bool wxListCtrl::SetItemPosition(long item
, const wxPoint
& pos
)
909 return m_genericImpl
->SetItemPosition(item
, pos
);
914 // Gets the number of items in the list control
915 int wxListCtrl::GetItemCount() const
918 return m_genericImpl
->GetItemCount();
921 return m_dbImpl
->MacGetCount();
926 void wxListCtrl::SetItemSpacing( int spacing
, bool isSmall
)
929 m_genericImpl
->SetItemSpacing(spacing
, isSmall
);
932 wxSize
wxListCtrl::GetItemSpacing() const
935 return m_genericImpl
->GetItemSpacing();
940 void wxListCtrl::SetItemTextColour( long item
, const wxColour
&col
)
944 m_genericImpl
->SetItemTextColour(item
, col
);
949 info
.m_itemId
= item
;
950 info
.SetTextColour( col
);
954 wxColour
wxListCtrl::GetItemTextColour( long item
) const
957 return m_genericImpl
->GetItemTextColour(item
);
963 return info
.GetTextColour();
968 void wxListCtrl::SetItemBackgroundColour( long item
, const wxColour
&col
)
972 m_genericImpl
->SetItemBackgroundColour(item
, col
);
977 info
.m_itemId
= item
;
978 info
.SetBackgroundColour( col
);
982 wxColour
wxListCtrl::GetItemBackgroundColour( long item
) const
985 return m_genericImpl
->GetItemBackgroundColour(item
);
991 return info
.GetBackgroundColour();
996 void wxListCtrl::SetItemFont( long item
, const wxFont
&f
)
1000 m_genericImpl
->SetItemFont(item
, f
);
1005 info
.m_itemId
= item
;
1010 wxFont
wxListCtrl::GetItemFont( long item
) const
1013 return m_genericImpl
->GetItemFont(item
);
1019 return info
.GetFont();
1025 // Gets the number of selected items in the list control
1026 int wxListCtrl::GetSelectedItemCount() const
1029 return m_genericImpl
->GetSelectedItemCount();
1032 return m_dbImpl
->GetSelectedItemCount(NULL
, true);
1037 // Gets the text colour of the listview
1038 wxColour
wxListCtrl::GetTextColour() const
1041 return m_genericImpl
->GetTextColour();
1043 // TODO: we need owner drawn list items to customize text color.
1047 return wxNullColour
;
1050 // Sets the text colour of the listview
1051 void wxListCtrl::SetTextColour(const wxColour
& col
)
1055 m_genericImpl
->SetTextColour(col
);
1063 // Gets the index of the topmost visible item when in
1064 // list or report view
1065 long wxListCtrl::GetTopItem() const
1068 return m_genericImpl
->GetTopItem();
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
1080 // Returns the item or -1 if unsuccessful.
1081 long wxListCtrl::GetNextItem(long item
, int geom
, int state
) const
1084 return m_genericImpl
->GetNextItem(item
, geom
, state
);
1086 if (m_dbImpl
&& geom
== wxLIST_NEXT_ALL
&& state
== wxLIST_STATE_SELECTED
)
1088 long count
= m_dbImpl
->MacGetCount() ;
1089 for ( long line
= item
+ 1 ; line
< count
; line
++ )
1091 wxMacDataItem
* id
= m_dbImpl
->GetItemFromLine(line
);
1092 if ( m_dbImpl
->IsItemSelected(id
) )
1102 wxImageList
*wxListCtrl::GetImageList(int which
) const
1105 return m_genericImpl
->GetImageList(which
);
1107 if ( which
== wxIMAGE_LIST_NORMAL
)
1109 return m_imageListNormal
;
1111 else if ( which
== wxIMAGE_LIST_SMALL
)
1113 return m_imageListSmall
;
1115 else if ( which
== wxIMAGE_LIST_STATE
)
1117 return m_imageListState
;
1122 void wxListCtrl::SetImageList(wxImageList
*imageList
, int which
)
1126 m_genericImpl
->SetImageList(imageList
, which
);
1130 if ( which
== wxIMAGE_LIST_NORMAL
)
1132 if (m_ownsImageListNormal
) delete m_imageListNormal
;
1133 m_imageListNormal
= imageList
;
1134 m_ownsImageListNormal
= false;
1136 else if ( which
== wxIMAGE_LIST_SMALL
)
1138 if (m_ownsImageListSmall
) delete m_imageListSmall
;
1139 m_imageListSmall
= imageList
;
1140 m_ownsImageListSmall
= false;
1142 else if ( which
== wxIMAGE_LIST_STATE
)
1144 if (m_ownsImageListState
) delete m_imageListState
;
1145 m_imageListState
= imageList
;
1146 m_ownsImageListState
= false;
1150 void wxListCtrl::AssignImageList(wxImageList
*imageList
, int which
)
1154 m_genericImpl
->AssignImageList(imageList
, which
);
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;
1167 // ----------------------------------------------------------------------------
1169 // ----------------------------------------------------------------------------
1171 // Arranges the items
1172 bool wxListCtrl::Arrange(int flag
)
1175 return m_genericImpl
->Arrange(flag
);
1180 bool wxListCtrl::DeleteItem(long item
)
1183 return m_genericImpl
->DeleteItem(item
);
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
);
1197 // Deletes all items
1198 bool wxListCtrl::DeleteAllItems()
1201 return m_genericImpl
->DeleteAllItems();
1205 m_dbImpl
->MacClear();
1206 wxListEvent
event( wxEVT_COMMAND_LIST_DELETE_ALL_ITEMS
, GetId() );
1207 event
.SetEventObject( this );
1208 GetEventHandler()->ProcessEvent( event
);
1213 // Deletes all items
1214 bool wxListCtrl::DeleteAllColumns()
1217 return m_genericImpl
->DeleteAllColumns();
1222 m_dbImpl
->GetColumnCount(&cols
);
1223 for (UInt32 col
= 0; col
< cols
; col
++)
1233 bool wxListCtrl::DeleteColumn(int col
)
1236 return m_genericImpl
->DeleteColumn(col
);
1240 OSStatus err
= m_dbImpl
->RemoveColumn(col
);
1241 return err
== noErr
;
1247 // Clears items, and columns if there are any.
1248 void wxListCtrl::ClearAll()
1252 m_genericImpl
->ClearAll();
1263 wxTextCtrl
* wxListCtrl::EditLabel(long item
, wxClassInfo
* textControlClass
)
1266 return m_genericImpl
->EditLabel(item
, textControlClass
);
1270 wxMacDataItem
* id
= m_dbImpl
->GetItemFromLine(item
);
1271 verify_noerr( SetDataBrowserEditItem(m_dbImpl
->GetControlRef(), (DataBrowserItemID
)id
, kMinColumnId
) );
1276 // End label editing, optionally cancelling the edit
1277 bool wxListCtrl::EndEditLabel(bool cancel
)
1279 // TODO: generic impl. doesn't have this method - is it needed for us?
1281 return true; // m_genericImpl->EndEditLabel(cancel);
1284 verify_noerr( SetDataBrowserEditItem(m_dbImpl
->GetControlRef(), kDataBrowserNoItem
, kMinColumnId
) );
1288 // Ensures this item is visible
1289 bool wxListCtrl::EnsureVisible(long item
)
1292 return m_genericImpl
->EnsureVisible(item
);
1296 wxMacDataItem
* dataItem
= m_dbImpl
->GetItemFromLine(item
);
1297 m_dbImpl
->RevealItem(dataItem
, kDataBrowserRevealWithoutSelecting
);
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
)
1308 return m_genericImpl
->FindItem(start
, str
, partial
);
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
)
1318 return m_genericImpl
->FindItem(start
, data
);
1320 long idx
= start
+ 1;
1321 long count
= GetItemCount();
1325 if (GetItemData(idx
) == data
)
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
)
1338 return m_genericImpl
->FindItem(start
, pt
, direction
);
1342 // Determines which item (if any) is at the specified point,
1343 // giving details in 'flags' (see wxLIST_HITTEST_... flags above)
1345 wxListCtrl::HitTest(const wxPoint
& point
, int& flags
, long *ptrSubItem
) const
1348 return m_genericImpl
->HitTest(point
, flags
, ptrSubItem
);
1354 // Inserts an item, returning the index of the new item if successful,
1356 long wxListCtrl::InsertItem(wxListItem
& info
)
1358 wxASSERT_MSG( !IsVirtual(), _T("can't be used with virtual controls") );
1361 return m_genericImpl
->InsertItem(info
);
1365 int count
= GetItemCount();
1367 if (info
.m_itemId
> count
)
1368 info
.m_itemId
= count
;
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
);
1377 return info
.m_itemId
;
1380 long wxListCtrl::InsertItem(long index
, const wxString
& label
)
1383 return m_genericImpl
->InsertItem(index
, label
);
1386 info
.m_text
= label
;
1387 info
.m_mask
= wxLIST_MASK_TEXT
;
1388 info
.m_itemId
= index
;
1389 return InsertItem(info
);
1392 // Inserts an image item
1393 long wxListCtrl::InsertItem(long index
, int imageIndex
)
1396 return m_genericImpl
->InsertItem(index
, imageIndex
);
1399 info
.m_image
= imageIndex
;
1400 info
.m_mask
= wxLIST_MASK_IMAGE
;
1401 info
.m_itemId
= index
;
1402 return InsertItem(info
);
1405 // Inserts an image/string item
1406 long wxListCtrl::InsertItem(long index
, const wxString
& label
, int imageIndex
)
1409 return m_genericImpl
->InsertItem(index
, label
, imageIndex
);
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
);
1419 // For list view mode (only), inserts a column.
1420 long wxListCtrl::InsertColumn(long col
, wxListItem
& item
)
1423 return m_genericImpl
->InsertColumn(col
, item
);
1427 int width
= item
.GetWidth();
1428 if ( !(item
.GetMask() & wxLIST_MASK_WIDTH
) )
1431 DataBrowserPropertyType type
= kDataBrowserCustomType
; //kDataBrowserTextType;
1432 wxImageList
* imageList
= GetImageList(wxIMAGE_LIST_SMALL
);
1433 if (imageList
&& imageList
->GetImageCount() > 0)
1435 wxBitmap bmp
= imageList
->GetBitmap(0);
1437 // type = kDataBrowserIconAndTextType;
1440 SInt16 just
= teFlushDefault
;
1441 if (item
.GetMask() & wxLIST_MASK_FORMAT
)
1443 if (item
.GetAlign() == wxLIST_FORMAT_LEFT
)
1445 else if (item
.GetAlign() == wxLIST_FORMAT_CENTER
)
1447 else if (item
.GetAlign() == wxLIST_FORMAT_RIGHT
)
1448 just
= teFlushRight
;
1450 m_dbImpl
->InsertColumn(col
, type
, item
.GetText(), just
, width
);
1451 SetColumn(col
, item
);
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
;
1461 if (GetWindowStyleFlag() & wxLC_VIRTUAL
){
1462 flags
&= ~kDataBrowserListViewSortableColumn
;
1464 verify_noerr(m_dbImpl
->SetPropertyFlags(id
, flags
));
1470 long wxListCtrl::InsertColumn(long col
,
1471 const wxString
& heading
,
1476 return m_genericImpl
->InsertColumn(col
, heading
, format
, width
);
1479 item
.m_mask
= wxLIST_MASK_TEXT
| wxLIST_MASK_FORMAT
;
1480 item
.m_text
= heading
;
1483 item
.m_mask
|= wxLIST_MASK_WIDTH
;
1484 item
.m_width
= width
;
1486 item
.m_format
= format
;
1488 return InsertColumn(col
, item
);
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
)
1496 return m_genericImpl
->ScrollList(dx
, dy
);
1500 m_dbImpl
->SetScrollPosition(dx
, dy
);
1506 bool wxListCtrl::SortItems(wxListCtrlCompare fn
, long data
)
1509 return m_genericImpl
->SortItems(fn
, data
);
1514 m_compareFuncData
= data
;
1520 // ----------------------------------------------------------------------------
1521 // virtual list controls
1522 // ----------------------------------------------------------------------------
1524 wxString
wxListCtrl::OnGetItemText(long WXUNUSED(item
), long WXUNUSED(col
)) const
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") );
1530 return wxEmptyString
;
1533 int wxListCtrl::OnGetItemImage(long WXUNUSED(item
)) const
1535 wxCHECK_MSG(!GetImageList(wxIMAGE_LIST_SMALL
),
1537 wxT("List control has an image list, OnGetItemImage or OnGetItemColumnImage should be overridden."));
1541 int wxListCtrl::OnGetItemColumnImage(long item
, long column
) const
1544 return OnGetItemImage(item
);
1549 wxListItemAttr
*wxListCtrl::OnGetItemAttr(long WXUNUSED_UNLESS_DEBUG(item
)) const
1551 wxASSERT_MSG( item
>= 0 && item
< GetItemCount(),
1552 _T("invalid item index in OnGetItemAttr()") );
1554 // no attributes by default
1558 void wxListCtrl::SetItemCount(long count
)
1560 wxASSERT_MSG( IsVirtual(), _T("this is for virtual controls only") );
1564 m_genericImpl
->SetItemCount(count
);
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
);
1587 void wxListCtrl::RefreshItem(long item
)
1591 m_genericImpl
->RefreshItem(item
);
1596 GetItemRect(item
, rect
);
1600 void wxListCtrl::RefreshItems(long itemFrom
, long itemTo
)
1604 m_genericImpl
->RefreshItems(itemFrom
, itemTo
);
1608 wxRect rect1
, rect2
;
1609 GetItemRect(itemFrom
, rect1
);
1610 GetItemRect(itemTo
, rect2
);
1612 wxRect rect
= rect1
;
1613 rect
.height
= rect2
.GetBottom() - rect1
.GetTop();
1619 // wxMac internal data structures
1621 wxMacListCtrlItem::~wxMacListCtrlItem()
1625 void wxMacListCtrlItem::Notification(wxMacDataItemBrowserControl
*owner
,
1626 DataBrowserItemNotification message
,
1627 DataBrowserItemDataRef itemData
) const
1630 wxMacDataBrowserListCtrlControl
*lb
= dynamic_cast<wxMacDataBrowserListCtrlControl
*>(owner
);
1632 // we want to depend on as little as possible to make sure tear-down of controls is safe
1633 if ( message
== kDataBrowserItemRemoved
)
1635 if ( lb
!= NULL
&& lb
->GetClientDataType() == wxClientData_Object
)
1637 delete (wxClientData
*) (m_data
);
1643 else if ( message
== kDataBrowserItemAdded
)
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
1650 wxListCtrl
*list
= wxDynamicCast( owner
->GetPeer() , wxListCtrl
);
1653 bool trigger
= false;
1655 wxListEvent
event( wxEVT_COMMAND_LIST_ITEM_SELECTED
, list
->GetId() );
1656 bool isSingle
= (list
->GetWindowStyle() & wxLC_SINGLE_SEL
) != 0;
1658 event
.SetEventObject( list
);
1659 event
.m_itemIndex
= owner
->GetLineFromItem( this ) ;
1660 if ( !list
->IsVirtual() )
1662 lb
->MacGetColumnInfo(event
.m_itemIndex
,0,event
.m_item
);
1667 case kDataBrowserItemDeselected
:
1668 event
.SetEventType(wxEVT_COMMAND_LIST_ITEM_DESELECTED
);
1670 trigger
= !lb
->IsSelectionSuppressed();
1673 case kDataBrowserItemSelected
:
1674 trigger
= !lb
->IsSelectionSuppressed();
1677 case kDataBrowserItemDoubleClicked
:
1678 event
.SetEventType( wxEVT_COMMAND_LIST_ITEM_ACTIVATED
);
1682 case kDataBrowserEditStarted
:
1683 // TODO : how to veto ?
1684 event
.SetEventType( wxEVT_COMMAND_LIST_BEGIN_LABEL_EDIT
) ;
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
) ;
1701 // direct notification is not always having the listbox GetSelection() having in synch with event
1702 wxPostEvent( list
->GetEventHandler(), event
);
1708 wxMacDataBrowserListCtrlControl::wxMacDataBrowserListCtrlControl( wxWindow
*peer
, const wxPoint
& pos
, const wxSize
& size
, long style
)
1709 : wxMacDataItemBrowserControl( peer
, pos
, size
, style
)
1711 OSStatus err
= noErr
;
1712 m_clientDataItemsType
= wxClientData_None
;
1713 m_isVirtual
= false;
1715 if ( style
& wxLC_VIRTUAL
)
1718 DataBrowserSelectionFlags options
= kDataBrowserDragSelect
;
1719 if ( style
& wxLC_SINGLE_SEL
)
1721 options
|= kDataBrowserSelectOnlyOne
;
1725 options
|= kDataBrowserCmdTogglesSelection
;
1728 err
= SetSelectionFlags( options
);
1729 verify_noerr( err
);
1731 DataBrowserCustomCallbacks callbacks
;
1732 InitializeDataBrowserCustomCallbacks( &callbacks
, kDataBrowserLatestCustomCallbacks
);
1734 if ( gDataBrowserDrawItemUPP
== NULL
)
1735 gDataBrowserDrawItemUPP
= NewDataBrowserDrawItemUPP(DataBrowserDrawItemProc
);
1737 // if ( gDataBrowserEditItemUPP == NULL )
1738 // gDataBrowserEditItemUPP = NewDataBrowserEditItemUPP(DataBrowserEditTextProc);
1740 if ( gDataBrowserHitTestUPP
== NULL
)
1741 gDataBrowserHitTestUPP
= NewDataBrowserHitTestUPP(DataBrowserHitTestProc
);
1743 callbacks
.u
.v1
.drawItemCallback
= gDataBrowserDrawItemUPP
;
1744 // callbacks.u.v1.editTextCallback = gDataBrowserEditItemUPP;
1745 callbacks
.u
.v1
.hitTestCallback
= gDataBrowserHitTestUPP
;
1747 SetDataBrowserCustomCallbacks( GetControlRef(), &callbacks
);
1749 if ( style
& wxLC_LIST
)
1751 InsertColumn(0, kDataBrowserIconAndTextType
, wxEmptyString
, -1, -1);
1752 verify_noerr( AutoSizeColumns() );
1755 if ( style
& wxLC_LIST
|| style
& wxLC_NO_HEADER
)
1756 verify_noerr( SetHeaderButtonHeight( 0 ) );
1759 SetSortProperty( kMinColumnId
- 1 );
1761 SetSortProperty( kMinColumnId
);
1762 if ( style
& wxLC_SORT_ASCENDING
)
1764 m_sortOrder
= SortOrder_Text_Ascending
;
1765 SetSortOrder( kDataBrowserOrderIncreasing
);
1767 else if ( style
& wxLC_SORT_DESCENDING
)
1769 m_sortOrder
= SortOrder_Text_Descending
;
1770 SetSortOrder( kDataBrowserOrderDecreasing
);
1774 m_sortOrder
= SortOrder_None
;
1777 if ( style
& wxLC_VRULES
)
1779 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4
1780 verify_noerr( DataBrowserChangeAttributes(m_controlRef
, kDataBrowserAttributeListViewDrawColumnDividers
, kDataBrowserAttributeNone
) );
1784 verify_noerr( SetHiliteStyle(kDataBrowserTableViewFillHilite
) );
1785 err
= SetHasScrollBars( (style
& wxHSCROLL
) != 0 , true );
1788 pascal Boolean
wxMacDataBrowserListCtrlControl::DataBrowserEditTextProc(
1790 DataBrowserItemID itemID
,
1791 DataBrowserPropertyID property
,
1792 CFStringRef theString
,
1793 Rect
*maxEditTextRect
,
1794 Boolean
*shrinkToFit
)
1796 Boolean result
= false;
1797 wxMacDataBrowserListCtrlControl
* ctl
= dynamic_cast<wxMacDataBrowserListCtrlControl
*>( wxMacControl::GetReferenceFromNativeControl( browser
) );
1800 result
= ctl
->ConfirmEditText(itemID
, property
, theString
, maxEditTextRect
, shrinkToFit
);
1801 theString
= CFSTR("Hello!");
1806 bool wxMacDataBrowserListCtrlControl::ConfirmEditText(
1807 DataBrowserItemID itemID
,
1808 DataBrowserPropertyID property
,
1809 CFStringRef theString
,
1810 Rect
*maxEditTextRect
,
1811 Boolean
*shrinkToFit
)
1813 //wxListCtrl* list = wxDynamicCast( GetPeer() , wxListCtrl );
1817 pascal void wxMacDataBrowserListCtrlControl::DataBrowserDrawItemProc(
1819 DataBrowserItemID itemID
,
1820 DataBrowserPropertyID property
,
1821 DataBrowserItemState itemState
,
1822 const Rect
*itemRect
,
1824 Boolean colorDevice
)
1826 wxMacDataBrowserListCtrlControl
* ctl
= dynamic_cast<wxMacDataBrowserListCtrlControl
*>( wxMacControl::GetReferenceFromNativeControl( browser
) );
1829 ctl
->DrawItem(itemID
, property
, itemState
, itemRect
, gdDepth
, colorDevice
);
1833 // routines needed for DrawItem
1838 kTextBoxHeight
= 14,
1839 kIconTextSpacingV
= 2,
1841 kContentHeight
= kIconHeight
+ kTextBoxHeight
+ kIconTextSpacingV
1844 static void calculateCGDrawingBounds(CGRect inItemRect
, CGRect
*outIconRect
, CGRect
*outTextRect
, bool hasIcon
= false)
1847 float iconH
, iconW
= 0;
1848 float padding
= kItemPadding
;
1851 iconH
= kIconHeight
;
1853 padding
= padding
*2;
1856 textBottom
= inItemRect
.origin
.y
;
1858 *outIconRect
= CGRectMake(inItemRect
.origin
.x
+ kItemPadding
,
1859 textBottom
+ kIconTextSpacingV
, kIconWidth
,
1862 *outTextRect
= CGRectMake(inItemRect
.origin
.x
+ padding
+ iconW
,
1863 textBottom
+ kIconTextSpacingV
, inItemRect
.size
.width
- padding
- iconW
,
1864 inItemRect
.size
.height
- kIconTextSpacingV
);
1867 void wxMacDataBrowserListCtrlControl::DrawItem(
1868 DataBrowserItemID itemID
,
1869 DataBrowserPropertyID property
,
1870 DataBrowserItemState itemState
,
1871 const Rect
*itemRect
,
1873 Boolean colorDevice
)
1876 wxFont font
= wxNullFont
;
1878 short listColumn
= property
- kMinColumnId
;
1880 wxListCtrl
* list
= wxDynamicCast( GetPeer() , wxListCtrl
);
1881 wxMacListCtrlItem
* lcItem
;
1882 wxColour color
= *wxBLACK
;
1883 wxColour bgColor
= wxNullColour
;
1885 if (listColumn
>= 0)
1889 lcItem
= (wxMacListCtrlItem
*) itemID
;
1890 if (lcItem
->HasColumnInfo(listColumn
)){
1891 wxListItem
* item
= lcItem
->GetColumnInfo(listColumn
);
1893 // we always use the 0 column to get font and text/background colors.
1894 if (lcItem
->HasColumnInfo(0))
1896 wxListItem
* firstItem
= lcItem
->GetColumnInfo(0);
1897 color
= firstItem
->GetTextColour();
1898 bgColor
= firstItem
->GetBackgroundColour();
1899 font
= firstItem
->GetFont();
1902 if (item
->GetMask() & wxLIST_MASK_TEXT
)
1903 text
= item
->GetText();
1904 if (item
->GetMask() & wxLIST_MASK_IMAGE
)
1905 imgIndex
= item
->GetImage();
1911 text
= list
->OnGetItemText( (long)itemID
-1, listColumn
);
1912 imgIndex
= list
->OnGetItemColumnImage( (long)itemID
-1, listColumn
);
1913 wxListItemAttr
* attrs
= list
->OnGetItemAttr( (long)itemID
-1 );
1916 if (attrs
->HasBackgroundColour())
1917 bgColor
= attrs
->GetBackgroundColour();
1918 if (attrs
->HasTextColour())
1919 color
= attrs
->GetTextColour();
1920 if (attrs
->HasFont())
1921 font
= attrs
->GetFont();
1926 wxColour listBgColor
= list
->GetBackgroundColour();
1927 if (bgColor
== wxNullColour
)
1928 bgColor
= listBgColor
;
1930 wxFont listFont
= list
->GetFont();
1931 if (font
== wxNullFont
)
1934 wxMacCFStringHolder cfString
;
1935 cfString
.Assign( text
, wxLocale::GetSystemEncoding() );
1938 CGRect enclosingCGRect
, iconCGRect
, textCGRect
;
1940 ThemeDrawingState savedState
= NULL
;
1941 CGContextRef context
= (CGContextRef
)list
->MacGetDrawingContext();
1942 RGBColor labelColor
;
1944 GetDataBrowserItemPartBounds(GetControlRef(), itemID
, property
, kDataBrowserPropertyEnclosingPart
,
1947 enclosingCGRect
= CGRectMake(enclosingRect
.left
,
1949 enclosingRect
.right
- enclosingRect
.left
,
1950 enclosingRect
.bottom
- enclosingRect
.top
);
1952 active
= IsControlActive(GetControlRef());
1954 if (itemState
== kDataBrowserItemIsSelected
)
1956 RGBColor foregroundColor
;
1958 GetThemeDrawingState(&savedState
);
1960 GetThemeBrushAsColor(kThemeBrushAlternatePrimaryHighlightColor
, 32, true, &foregroundColor
);
1961 GetThemeTextColor(kThemeTextColorWhite
, gdDepth
, colorDevice
, &labelColor
);
1963 CGContextSaveGState(context
);
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
);
1970 CGContextRestoreGState(context
);
1976 labelColor
= MAC_WXCOLORREF( color
.GetPixel() );
1977 else if (list
->GetTextColour().Ok())
1978 labelColor
= MAC_WXCOLORREF( list
->GetTextColour().GetPixel() );
1982 labelColor
.green
= 0;
1983 labelColor
.blue
= 0;
1988 RGBColor foregroundColor
= MAC_WXCOLORREF( bgColor
.GetPixel() );
1989 CGContextSaveGState(context
);
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
);
1996 CGContextRestoreGState(context
);
2000 calculateCGDrawingBounds(enclosingCGRect
, &iconCGRect
, &textCGRect
, (imgIndex
!= -1) );
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();
2011 iconLabel
.green
= 0;
2014 PlotIconRefInContext(context
, &iconCGRect
, kAlignNone
,
2015 active
? kTransformNone
: kTransformDisabled
, &iconLabel
,
2016 kPlotIconRefNormalFlags
, icon
);
2020 HIThemeTextHorizontalFlush hFlush
= kHIThemeTextHorizontalFlushLeft
;
2021 UInt16 fontID
= kThemeViewsFont
;
2025 if (font
.GetFamily() != wxFONTFAMILY_DEFAULT
)
2026 fontID
= font
.MacGetThemeFontID();
2028 // FIXME: replace these with CG or ATSUI calls so we can remove this #ifndef.
2030 ::TextSize( (short)(font
.MacGetFontSize()) ) ;
2031 ::TextFace( font
.MacGetFontStyle() ) ;
2036 list
->GetColumn(listColumn
, item
);
2037 if (item
.GetMask() & wxLIST_MASK_FORMAT
)
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
)
2045 hFlush
= kHIThemeTextHorizontalFlushRight
;
2046 textCGRect
.origin
.x
-= kItemPadding
; // give a little extra paddding
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;
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);
2065 HIThemeDrawTextBox(cfString
, &textCGRect
, &info
, context
, kHIThemeOrientationNormal
);
2067 CGContextRestoreGState(context
);
2069 if (savedState
!= NULL
)
2070 SetThemeDrawingState(savedState
, true);
2073 OSStatus
wxMacDataBrowserListCtrlControl::GetSetItemData(DataBrowserItemID itemID
,
2074 DataBrowserPropertyID property
,
2075 DataBrowserItemDataRef itemData
,
2076 Boolean changeValue
)
2080 short listColumn
= property
- kMinColumnId
;
2082 OSStatus err
= errDataBrowserPropertyNotSupported
;
2083 wxListCtrl
* list
= wxDynamicCast( GetPeer() , wxListCtrl
);
2084 wxMacListCtrlItem
* lcItem
;
2086 if (listColumn
>= 0)
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();
2101 text
= list
->OnGetItemText( (long)itemID
-1, listColumn
);
2102 imgIndex
= list
->OnGetItemColumnImage( (long)itemID
-1, listColumn
);
2110 case kDataBrowserItemIsEditableProperty
:
2111 if ( list
&& list
->HasFlag( wxLC_EDIT_LABELS
) )
2113 verify_noerr(SetDataBrowserItemDataBooleanValue( itemData
, true ));
2118 if ( property
>= kMinColumnId
)
2120 wxMacCFStringHolder cfStr
;
2123 cfStr
.Assign( text
, wxLocale::GetSystemEncoding() );
2124 err
= ::SetDataBrowserItemDataText( itemData
, cfStr
);
2130 if ( imgIndex
!= -1 )
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
);
2150 if ( property
>= kMinColumnId
)
2152 short listColumn
= property
- kMinColumnId
;
2154 // TODO probably send the 'end edit' from here, as we
2155 // can then deal with the veto
2157 verify_noerr( GetDataBrowserItemDataText( itemData
, &sr
) ) ;
2158 wxMacCFStringHolder
cfStr(sr
) ;;
2160 list
->SetItem( (long)itemData
-1 , listColumn
, cfStr
.AsString() ) ;
2164 lcItem
->SetColumnTextValue( listColumn
, cfStr
.AsString() );
2174 void wxMacDataBrowserListCtrlControl::ItemNotification(DataBrowserItemID itemID
,
2175 DataBrowserItemNotification message
,
2176 DataBrowserItemDataRef itemData
)
2178 // we want to depend on as little as possible to make sure tear-down of controls is safe
2179 if ( message
== kDataBrowserItemRemoved
)
2181 // make sure MacDelete does the proper teardown.
2184 else if ( message
== kDataBrowserItemAdded
)
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
2191 wxListCtrl
*list
= wxDynamicCast( GetPeer() , wxListCtrl
);
2194 bool trigger
= false;
2196 wxListEvent
event( wxEVT_COMMAND_LIST_ITEM_SELECTED
, list
->GetId() );
2197 bool isSingle
= (list
->GetWindowStyle() & wxLC_SINGLE_SEL
) != 0;
2199 event
.SetEventObject( list
);
2200 if ( !list
->IsVirtual() )
2202 DataBrowserTableViewRowIndex result
= 0;
2203 verify_noerr( GetItemRow( itemID
, &result
) ) ;
2204 event
.m_itemIndex
= result
;
2206 if (event
.m_itemIndex
>= 0)
2207 MacGetColumnInfo(event
.m_itemIndex
,0,event
.m_item
);
2211 event
.m_itemIndex
= (long)itemID
;
2216 case kDataBrowserItemDeselected
:
2217 event
.SetEventType(wxEVT_COMMAND_LIST_ITEM_DESELECTED
);
2219 trigger
= !IsSelectionSuppressed();
2222 case kDataBrowserItemSelected
:
2223 trigger
= !IsSelectionSuppressed();
2227 case kDataBrowserItemDoubleClicked
:
2228 event
.SetEventType( wxEVT_COMMAND_LIST_ITEM_ACTIVATED
);
2232 case kDataBrowserEditStarted
:
2233 // TODO : how to veto ?
2234 event
.SetEventType( wxEVT_COMMAND_LIST_BEGIN_LABEL_EDIT
) ;
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
) ;
2251 // direct notification is not always having the listbox GetSelection() having in synch with event
2252 wxPostEvent( list
->GetEventHandler(), event
);
2257 Boolean
wxMacDataBrowserListCtrlControl::CompareItems(DataBrowserItemID itemOneID
,
2258 DataBrowserItemID itemTwoID
,
2259 DataBrowserPropertyID sortProperty
)
2262 bool retval
= false;
2264 wxString otherItemText
;
2265 int colId
= sortProperty
- kMinColumnId
;
2267 long otherItemNum
= 0;
2269 wxListCtrl
* list
= wxDynamicCast( GetPeer() , wxListCtrl
);
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;
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();
2291 itemNum
= (long)itemOneID
;
2292 otherItemNum
= (long)itemTwoID
;
2293 itemText
= list
->OnGetItemText( itemNum
-1, colId
);
2294 otherItemText
= list
->OnGetItemText( otherItemNum
-1, colId
);
2298 DataBrowserSortOrder sort
;
2299 verify_noerr(GetSortOrder(&sort
));
2301 if ( sort
== kDataBrowserOrderIncreasing
)
2303 retval
= itemText
.CmpNoCase( otherItemText
) > 0;
2305 else if ( sort
== kDataBrowserOrderDecreasing
)
2307 retval
= itemText
.CmpNoCase( otherItemText
) < 0;
2311 // fallback for undefined cases
2312 retval
= itemOneID
< itemTwoID
;
2318 wxMacDataBrowserListCtrlControl::~wxMacDataBrowserListCtrlControl()
2322 void wxMacDataBrowserListCtrlControl::MacSetColumnInfo( unsigned int row
, unsigned int column
, wxListItem
* item
)
2324 wxMacDataItem
* dataItem
= GetItemFromLine(row
);
2327 wxMacListCtrlItem
* listItem
= dynamic_cast<wxMacListCtrlItem
*>(dataItem
);
2328 listItem
->SetColumnInfo( column
, item
);
2329 UpdateState(dataItem
, item
);
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
)
2337 bool isSelected
= IsItemSelected( dataItem
);
2338 bool isSelectedState
= (listItem
->GetState() == wxLIST_STATE_SELECTED
);
2340 // toggle the selection state if wxListInfo state and actual state don't match.
2341 if ( isSelected
!= isSelectedState
)
2343 DataBrowserSetOption options
= kDataBrowserItemsAdd
;
2344 if (!isSelectedState
)
2345 options
= kDataBrowserItemsRemove
;
2346 SetSelectedItem(dataItem
, options
);
2348 // TODO: Set column width if item width > than current column width
2351 void wxMacDataBrowserListCtrlControl::MacGetColumnInfo( unsigned int row
, unsigned int column
, wxListItem
& item
)
2353 wxMacDataItem
* dataItem
= GetItemFromLine(row
);
2354 // CS should this guard against dataItem = 0 ? , as item is not a pointer if (item) is not appropriate
2357 wxMacListCtrlItem
* listItem
= dynamic_cast<wxMacListCtrlItem
*>(dataItem
);
2358 wxListItem
* oldItem
= listItem
->GetColumnInfo( column
);
2360 long mask
= item
.GetMask();
2362 // by default, get everything for backwards compatibility
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());
2378 item
.SetTextColour(oldItem
->GetTextColour());
2379 item
.SetBackgroundColour(oldItem
->GetBackgroundColour());
2380 item
.SetFont(oldItem
->GetFont());
2384 void wxMacDataBrowserListCtrlControl::MacInsertItem( unsigned int n
, wxListItem
* item
)
2386 wxMacDataItemBrowserControl::MacInsert(n
, item
->GetText());
2387 MacSetColumnInfo(n
, 0, item
);
2390 wxMacDataItem
* wxMacDataBrowserListCtrlControl::CreateItem()
2392 return new wxMacListCtrlItem();
2395 wxMacListCtrlItem::wxMacListCtrlItem()
2397 m_rowItems
= wxListItemList();
2400 int wxMacListCtrlItem::GetColumnImageValue( unsigned int column
)
2402 return GetColumnInfo(column
)->GetImage();
2405 void wxMacListCtrlItem::SetColumnImageValue( unsigned int column
, int imageIndex
)
2407 GetColumnInfo(column
)->SetImage(imageIndex
);
2410 const wxString
& wxMacListCtrlItem::GetColumnTextValue( unsigned int column
)
2415 return GetColumnInfo(column
)->GetText();
2418 void wxMacListCtrlItem::SetColumnTextValue( unsigned int column
, const wxString
& text
)
2420 GetColumnInfo(column
)->SetText(text
);
2422 // for compatibility with superclass APIs
2427 wxListItem
* wxMacListCtrlItem::GetColumnInfo( unsigned int column
)
2429 wxListItemList::compatibility_iterator node
= m_rowItems
.Item( column
);
2430 wxASSERT_MSG( node
, _T("invalid column index in wxMacListCtrlItem") );
2432 return node
->GetData();
2435 bool wxMacListCtrlItem::HasColumnInfo( unsigned int column
)
2437 return m_rowItems
.GetCount() > column
;
2440 void wxMacListCtrlItem::SetColumnInfo( unsigned int column
, wxListItem
* item
)
2443 if ( column
>= m_rowItems
.GetCount() )
2445 wxListItem
* listItem
= new wxListItem(*item
);
2446 m_rowItems
.Append( listItem
);
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());
2465 listItem
->SetTextColour(item
->GetTextColour());
2466 listItem
->SetBackgroundColour(item
->GetBackgroundColour());
2467 listItem
->SetFont(item
->GetFont());
2471 #endif // wxUSE_LISTCTRL