1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/msw/listctrl.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"
33 #include "wx/settings.h"
34 #include "wx/dcclient.h"
35 #include "wx/textctrl.h"
38 #include "wx/mac/uma.h"
40 #include "wx/imaglist.h"
41 #include "wx/listctrl.h"
42 #include "wx/sysopt.h"
44 #define wxMAC_ALWAYS_USE_GENERIC_LISTCTRL wxT("mac.listctrl.always_use_generic")
46 #if wxUSE_EXTENDED_RTTI
47 WX_DEFINE_FLAGS( wxListCtrlStyle
)
49 wxBEGIN_FLAGS( wxListCtrlStyle
)
50 // new style border flags, we put them first to
51 // use them for streaming out
52 wxFLAGS_MEMBER(wxBORDER_SIMPLE
)
53 wxFLAGS_MEMBER(wxBORDER_SUNKEN
)
54 wxFLAGS_MEMBER(wxBORDER_DOUBLE
)
55 wxFLAGS_MEMBER(wxBORDER_RAISED
)
56 wxFLAGS_MEMBER(wxBORDER_STATIC
)
57 wxFLAGS_MEMBER(wxBORDER_NONE
)
59 // old style border flags
60 wxFLAGS_MEMBER(wxSIMPLE_BORDER
)
61 wxFLAGS_MEMBER(wxSUNKEN_BORDER
)
62 wxFLAGS_MEMBER(wxDOUBLE_BORDER
)
63 wxFLAGS_MEMBER(wxRAISED_BORDER
)
64 wxFLAGS_MEMBER(wxSTATIC_BORDER
)
65 wxFLAGS_MEMBER(wxBORDER
)
67 // standard window styles
68 wxFLAGS_MEMBER(wxTAB_TRAVERSAL
)
69 wxFLAGS_MEMBER(wxCLIP_CHILDREN
)
70 wxFLAGS_MEMBER(wxTRANSPARENT_WINDOW
)
71 wxFLAGS_MEMBER(wxWANTS_CHARS
)
72 wxFLAGS_MEMBER(wxFULL_REPAINT_ON_RESIZE
)
73 wxFLAGS_MEMBER(wxALWAYS_SHOW_SB
)
74 wxFLAGS_MEMBER(wxVSCROLL
)
75 wxFLAGS_MEMBER(wxHSCROLL
)
77 wxFLAGS_MEMBER(wxLC_LIST
)
78 wxFLAGS_MEMBER(wxLC_REPORT
)
79 wxFLAGS_MEMBER(wxLC_ICON
)
80 wxFLAGS_MEMBER(wxLC_SMALL_ICON
)
81 wxFLAGS_MEMBER(wxLC_ALIGN_TOP
)
82 wxFLAGS_MEMBER(wxLC_ALIGN_LEFT
)
83 wxFLAGS_MEMBER(wxLC_AUTOARRANGE
)
84 wxFLAGS_MEMBER(wxLC_USER_TEXT
)
85 wxFLAGS_MEMBER(wxLC_EDIT_LABELS
)
86 wxFLAGS_MEMBER(wxLC_NO_HEADER
)
87 wxFLAGS_MEMBER(wxLC_SINGLE_SEL
)
88 wxFLAGS_MEMBER(wxLC_SORT_ASCENDING
)
89 wxFLAGS_MEMBER(wxLC_SORT_DESCENDING
)
90 wxFLAGS_MEMBER(wxLC_VIRTUAL
)
92 wxEND_FLAGS( wxListCtrlStyle
)
94 IMPLEMENT_DYNAMIC_CLASS_XTI(wxListCtrl
, wxControl
,"wx/listctrl.h")
96 wxBEGIN_PROPERTIES_TABLE(wxListCtrl
)
97 wxEVENT_PROPERTY( TextUpdated
, wxEVT_COMMAND_TEXT_UPDATED
, wxCommandEvent
)
99 wxPROPERTY_FLAGS( WindowStyle
, wxListCtrlStyle
, long , SetWindowStyleFlag
, GetWindowStyleFlag
, EMPTY_MACROVALUE
, 0 /*flags*/ , wxT("Helpstring") , wxT("group")) // style
100 wxEND_PROPERTIES_TABLE()
102 wxBEGIN_HANDLERS_TABLE(wxListCtrl
)
103 wxEND_HANDLERS_TABLE()
105 wxCONSTRUCTOR_5( wxListCtrl
, wxWindow
* , Parent
, wxWindowID
, Id
, wxPoint
, Position
, wxSize
, Size
, long , WindowStyle
)
108 TODO : Expose more information of a list's layout etc. via appropriate objects (à la NotebookPageInfo)
111 IMPLEMENT_DYNAMIC_CLASS(wxListCtrl
, wxControl
)
114 IMPLEMENT_DYNAMIC_CLASS(wxListView
, wxListCtrl
)
115 IMPLEMENT_DYNAMIC_CLASS(wxListItem
, wxObject
)
117 IMPLEMENT_DYNAMIC_CLASS(wxListEvent
, wxNotifyEvent
)
119 WX_DECLARE_EXPORTED_LIST(wxListItem
, wxListItemList
);
120 #include "wx/listimpl.cpp"
121 WX_DEFINE_LIST(wxListItemList
)
123 class wxMacListCtrlItem
: public wxMacListBoxItem
128 virtual void Notification(wxMacDataItemBrowserControl
*owner
,
129 DataBrowserItemNotification message
,
130 DataBrowserItemDataRef itemData
) const;
132 virtual void SetColumnInfo( unsigned int column
, wxListItem
* item
);
133 virtual wxListItem
* GetColumnInfo( unsigned int column
);
134 virtual bool HasColumnInfo( unsigned int column
);
136 virtual void SetColumnTextValue( unsigned int column
, const wxString
& text
);
137 virtual const wxString
& GetColumnTextValue( unsigned int column
);
139 virtual int GetColumnImageValue( unsigned int column
);
140 virtual void SetColumnImageValue( unsigned int column
, int imageIndex
);
142 virtual OSStatus
GetSetData( wxMacDataItemBrowserControl
*owner
,
143 DataBrowserPropertyID property
,
144 DataBrowserItemDataRef itemData
,
148 virtual ~wxMacListCtrlItem();
150 wxListItemList m_rowItems
;
153 // TODO: Make a better name!!
154 class wxMacDataBrowserListCtrlControl
: public wxMacDataItemBrowserControl
157 wxMacDataBrowserListCtrlControl( wxWindow
*peer
, const wxPoint
& pos
, const wxSize
& size
, long style
);
158 virtual ~wxMacDataBrowserListCtrlControl();
160 // create a list item (can be a subclass of wxMacListBoxItem)
162 virtual wxMacListCtrlItem
* CreateItem();
164 virtual void MacInsertItem( unsigned int n
, wxListItem
* item
);
165 virtual void MacSetColumnInfo( unsigned int row
, unsigned int column
, wxListItem
* item
);
166 virtual void MacGetColumnInfo( unsigned int row
, unsigned int column
, wxListItem
& item
);
167 virtual void UpdateState(wxMacDataItem
* dataItem
, wxListItem
* item
);
170 wxClientDataType m_clientDataItemsType
;
174 // TODO: This gives errors, find out why.
175 //BEGIN_EVENT_TABLE(wxListCtrl, wxControl)
176 // EVT_PAINT(wxListCtrl::OnPaint)
179 // ============================================================================
181 // ============================================================================
183 wxMacListControl
* wxListCtrl::GetPeer() const
185 return dynamic_cast<wxMacListControl
*>(m_peer
);
188 // ----------------------------------------------------------------------------
189 // wxListCtrl construction
190 // ----------------------------------------------------------------------------
192 void wxListCtrl::Init()
194 m_imageListNormal
= NULL
;
195 m_imageListSmall
= NULL
;
196 m_imageListState
= NULL
;
198 // keep track of if we created our own image lists, or if they were assigned
200 m_ownsImageListNormal
= m_ownsImageListSmall
= m_ownsImageListState
= false;
204 m_genericImpl
= NULL
;
208 class wxGenericListCtrlHook
: public wxGenericListCtrl
211 wxGenericListCtrlHook(wxListCtrl
* parent
,
216 const wxValidator
& validator
,
217 const wxString
& name
)
218 : wxGenericListCtrl(parent
, id
, pos
, size
, style
, validator
, name
),
219 m_nativeListCtrl(parent
)
223 virtual wxListItemAttr
* OnGetItemAttr(long item
) const
225 return m_nativeListCtrl
->OnGetItemAttr(item
);
228 virtual int OnGetItemImage(long item
) const
230 return m_nativeListCtrl
->OnGetItemImage(item
);
233 virtual int OnGetItemColumnImage(long item
, long column
) const
235 return m_nativeListCtrl
->OnGetItemColumnImage(item
, column
);
238 virtual wxString
OnGetItemText(long item
, long column
) const
240 return m_nativeListCtrl
->OnGetItemText(item
, column
);
244 wxListCtrl
* m_nativeListCtrl
;
248 bool wxListCtrl::Create(wxWindow
*parent
,
253 const wxValidator
& validator
,
254 const wxString
& name
)
257 // for now, we'll always use the generic list control for ICON and LIST views,
258 // because they dynamically change the number of columns on resize.
259 // Also, allow the user to set it to use the list ctrl as well.
260 // Also, use generic list control in VIRTUAL mode.
261 if ( (wxSystemOptions::HasOption( wxMAC_ALWAYS_USE_GENERIC_LISTCTRL
)
262 && (wxSystemOptions::GetOptionInt( wxMAC_ALWAYS_USE_GENERIC_LISTCTRL
) == 1)) ||
263 (style
& wxLC_ICON
) || (style
& wxLC_SMALL_ICON
) || (style
& wxLC_LIST
) || (style
& wxLC_VIRTUAL
))
265 m_macIsUserPane
= true;
267 if ( !wxWindow::Create(parent
, id
, pos
, size
, style
, name
) )
269 m_genericImpl
= new wxGenericListCtrlHook(this, id
, pos
, size
, style
, validator
, name
);
275 m_macIsUserPane
= false;
277 if ( !wxWindow::Create(parent
, id
, pos
, size
, style
, name
) )
279 m_dbImpl
= new wxMacDataBrowserListCtrlControl( this, pos
, size
, style
);
282 MacPostControlCreate( pos
, size
);
288 wxListCtrl::~wxListCtrl()
290 if (m_ownsImageListNormal
)
291 delete m_imageListNormal
;
292 if (m_ownsImageListSmall
)
293 delete m_imageListSmall
;
294 if (m_ownsImageListState
)
295 delete m_imageListState
;
298 // ----------------------------------------------------------------------------
299 // set/get/change style
300 // ----------------------------------------------------------------------------
302 // Add or remove a single window style
303 void wxListCtrl::SetSingleStyle(long style
, bool add
)
305 long flag
= GetWindowStyleFlag();
307 // Get rid of conflicting styles
310 if ( style
& wxLC_MASK_TYPE
)
311 flag
= flag
& ~wxLC_MASK_TYPE
;
312 if ( style
& wxLC_MASK_ALIGN
)
313 flag
= flag
& ~wxLC_MASK_ALIGN
;
314 if ( style
& wxLC_MASK_SORT
)
315 flag
= flag
& ~wxLC_MASK_SORT
;
323 SetWindowStyleFlag(flag
);
326 // Set the whole window style
327 void wxListCtrl::SetWindowStyleFlag(long flag
)
329 if ( flag
!= m_windowStyle
)
331 m_windowStyle
= flag
;
334 m_genericImpl
->SetWindowStyleFlag(flag
);
341 void wxListCtrl::DoSetSize( int x
, int y
, int width
, int height
, int sizeFlags
){
342 wxControl::DoSetSize(x
, y
, width
, height
, sizeFlags
);
345 m_genericImpl
->SetSize(x
, y
, width
, height
, sizeFlags
);
348 // ----------------------------------------------------------------------------
350 // ----------------------------------------------------------------------------
352 // Gets information about this column
353 bool wxListCtrl::GetColumn(int col
, wxListItem
& item
) const
356 return m_genericImpl
->GetColumn(col
, item
);
360 if ( item
.m_mask
& wxLIST_MASK_TEXT
)
364 if ( item
.m_mask
& wxLIST_MASK_FORMAT
)
368 if ( item
.m_mask
& wxLIST_MASK_IMAGE
)
372 if ( (item
.m_mask
& wxLIST_MASK_TEXT
) )
380 // Sets information about this column
381 bool wxListCtrl::SetColumn(int col
, wxListItem
& item
)
384 return m_genericImpl
->SetColumn(col
, item
);
389 int wxListCtrl::GetColumnCount() const
392 return m_genericImpl
->GetColumnCount();
396 m_dbImpl
->GetColumnCount(&count
);
403 // Gets the column width
404 int wxListCtrl::GetColumnWidth(int col
) const
407 return m_genericImpl
->GetColumnWidth(col
);
410 return m_dbImpl
->GetColumnWidth(col
);
416 // Sets the column width
417 bool wxListCtrl::SetColumnWidth(int col
, int width
)
420 return m_genericImpl
->SetColumnWidth(col
, width
);
422 // TODO: This is setting the width of the first column
423 // to the entire window width; investigate why
428 if (width
== wxLIST_AUTOSIZE
|| width
== wxLIST_AUTOSIZE_USEHEADER
)
432 for (int column
= 0; column
< GetColumnCount(); column
++){
433 m_dbImpl
->SetColumnWidth(col
, mywidth
);
437 m_dbImpl
->SetColumnWidth(col
, mywidth
);
445 // Gets the number of items that can fit vertically in the
446 // visible area of the list control (list or report view)
447 // or the total number of items in the list control (icon
448 // or small icon view)
449 int wxListCtrl::GetCountPerPage() const
452 return m_genericImpl
->GetCountPerPage();
460 // Gets the edit control for editing labels.
461 wxTextCtrl
* wxListCtrl::GetEditControl() const
464 return m_genericImpl
->GetEditControl();
469 // Gets information about the item
470 bool wxListCtrl::GetItem(wxListItem
& info
) const
473 return m_genericImpl
->GetItem(info
);
476 m_dbImpl
->MacGetColumnInfo(info
.m_itemId
, info
.m_col
, info
);
481 // Sets information about the item
482 bool wxListCtrl::SetItem(wxListItem
& info
)
485 return m_genericImpl
->SetItem(info
);
488 m_dbImpl
->MacSetColumnInfo( info
.m_itemId
, info
.m_col
, &info
);
493 long wxListCtrl::SetItem(long index
, int col
, const wxString
& label
, int imageId
)
496 return m_genericImpl
->SetItem(index
, col
, label
, imageId
);
500 info
.m_mask
= wxLIST_MASK_TEXT
;
501 info
.m_itemId
= index
;
505 info
.m_image
= imageId
;
506 info
.m_mask
|= wxLIST_MASK_IMAGE
;
508 return SetItem(info
);
512 // Gets the item state
513 int wxListCtrl::GetItemState(long item
, long stateMask
) const
516 return m_genericImpl
->GetItemState(item
, stateMask
);
520 info
.m_mask
= wxLIST_MASK_STATE
;
521 info
.m_stateMask
= stateMask
;
522 info
.m_itemId
= item
;
530 // Sets the item state
531 bool wxListCtrl::SetItemState(long item
, long state
, long stateMask
)
534 return m_genericImpl
->SetItemState(item
, state
, stateMask
);
537 info
.m_mask
= wxLIST_MASK_STATE
;
538 info
.m_stateMask
= stateMask
;
539 info
.m_state
= state
;
540 info
.m_itemId
= item
;
541 return SetItem(info
);
544 // Sets the item image
545 bool wxListCtrl::SetItemImage(long item
, int image
, int WXUNUSED(selImage
))
547 return SetItemColumnImage(item
, 0, image
);
550 // Sets the item image
551 bool wxListCtrl::SetItemColumnImage(long item
, long column
, int image
)
554 return m_genericImpl
->SetItemColumnImage(item
, column
, image
);
558 info
.m_mask
= wxLIST_MASK_IMAGE
;
559 info
.m_image
= image
;
560 info
.m_itemId
= item
;
563 return SetItem(info
);
566 // Gets the item text
567 wxString
wxListCtrl::GetItemText(long item
) const
570 return m_genericImpl
->GetItemText(item
);
574 info
.m_mask
= wxLIST_MASK_TEXT
;
575 info
.m_itemId
= item
;
578 return wxEmptyString
;
582 // Sets the item text
583 void wxListCtrl::SetItemText(long item
, const wxString
& str
)
586 return m_genericImpl
->SetItemText(item
, str
);
590 info
.m_mask
= wxLIST_MASK_TEXT
;
591 info
.m_itemId
= item
;
597 // Gets the item data
598 long wxListCtrl::GetItemData(long item
) const
601 return m_genericImpl
->GetItemData(item
);
605 info
.m_mask
= wxLIST_MASK_DATA
;
606 info
.m_itemId
= item
;
613 // Sets the item data
614 bool wxListCtrl::SetItemData(long item
, long data
)
617 return m_genericImpl
->SetItemData(item
, data
);
621 info
.m_mask
= wxLIST_MASK_DATA
;
622 info
.m_itemId
= item
;
625 return SetItem(info
);
628 wxRect
wxListCtrl::GetViewRect() const
630 wxASSERT_MSG( !HasFlag(wxLC_REPORT
| wxLC_LIST
),
631 _T("wxListCtrl::GetViewRect() only works in icon mode") );
634 return m_genericImpl
->GetViewRect();
640 // Gets the item rectangle
641 bool wxListCtrl::GetItemRect(long item
, wxRect
& rect
, int code
) const
644 return m_genericImpl
->GetItemRect(item
, rect
, code
);
649 // Gets the item position
650 bool wxListCtrl::GetItemPosition(long item
, wxPoint
& pos
) const
653 return m_genericImpl
->GetItemPosition(item
, pos
);
655 bool success
= false;
660 // Sets the item position.
661 bool wxListCtrl::SetItemPosition(long item
, const wxPoint
& pos
)
664 return m_genericImpl
->SetItemPosition(item
, pos
);
669 // Gets the number of items in the list control
670 int wxListCtrl::GetItemCount() const
673 return m_genericImpl
->GetItemCount();
676 return m_dbImpl
->MacGetCount();
681 void wxListCtrl::SetItemSpacing( int spacing
, bool isSmall
)
684 m_genericImpl
->SetItemSpacing(spacing
, isSmall
);
687 wxSize
wxListCtrl::GetItemSpacing() const
690 return m_genericImpl
->GetItemSpacing();
695 void wxListCtrl::SetItemTextColour( long item
, const wxColour
&col
)
698 m_genericImpl
->SetItemTextColour(item
, col
);
702 info
.m_itemId
= item
;
703 info
.SetTextColour( col
);
707 wxColour
wxListCtrl::GetItemTextColour( long item
) const
710 return m_genericImpl
->GetItemTextColour(item
);
715 return info
.GetTextColour();
720 void wxListCtrl::SetItemBackgroundColour( long item
, const wxColour
&col
)
723 m_genericImpl
->SetItemBackgroundColour(item
, col
);
728 info
.m_itemId
= item
;
729 info
.SetBackgroundColour( col
);
733 wxColour
wxListCtrl::GetItemBackgroundColour( long item
) const
736 return m_genericImpl
->GetItemBackgroundColour(item
);
741 return info
.GetBackgroundColour();
746 void wxListCtrl::SetItemFont( long item
, const wxFont
&f
)
749 m_genericImpl
->SetItemFont(item
, f
);
754 info
.m_itemId
= item
;
759 wxFont
wxListCtrl::GetItemFont( long item
) const
762 return m_genericImpl
->GetItemFont(item
);
767 return info
.GetFont();
773 // Gets the number of selected items in the list control
774 int wxListCtrl::GetSelectedItemCount() const
777 return m_genericImpl
->GetSelectedItemCount();
780 return m_dbImpl
->GetSelectedItemCount(NULL
, true);
785 // Gets the text colour of the listview
786 wxColour
wxListCtrl::GetTextColour() const
789 return m_genericImpl
->GetTextColour();
791 // TODO: we need owner drawn list items to customize text color.
796 // Sets the text colour of the listview
797 void wxListCtrl::SetTextColour(const wxColour
& col
)
800 m_genericImpl
->SetTextColour(col
);
804 // TODO: if we add owner-drawn item support for DataBrowser,
805 // consider supporting this property
808 // Gets the index of the topmost visible item when in
809 // list or report view
810 long wxListCtrl::GetTopItem() const
813 return m_genericImpl
->GetTopItem();
818 // Searches for an item, starting from 'item'.
819 // 'geometry' is one of
820 // wxLIST_NEXT_ABOVE/ALL/BELOW/LEFT/RIGHT.
821 // 'state' is a state bit flag, one or more of
822 // wxLIST_STATE_DROPHILITED/FOCUSED/SELECTED/CUT.
823 // item can be -1 to find the first item that matches the
825 // Returns the item or -1 if unsuccessful.
826 long wxListCtrl::GetNextItem(long item
, int geom
, int state
) const
829 return m_genericImpl
->GetNextItem(item
, geom
, state
);
835 wxImageList
*wxListCtrl::GetImageList(int which
) const
838 return m_genericImpl
->GetImageList(which
);
840 if ( which
== wxIMAGE_LIST_NORMAL
)
842 return m_imageListNormal
;
844 else if ( which
== wxIMAGE_LIST_SMALL
)
846 return m_imageListSmall
;
848 else if ( which
== wxIMAGE_LIST_STATE
)
850 return m_imageListState
;
855 void wxListCtrl::SetImageList(wxImageList
*imageList
, int which
)
858 m_genericImpl
->SetImageList(imageList
, which
);
863 if ( which
== wxIMAGE_LIST_NORMAL
)
865 if (m_ownsImageListNormal
) delete m_imageListNormal
;
866 m_imageListNormal
= imageList
;
867 m_ownsImageListNormal
= false;
869 else if ( which
== wxIMAGE_LIST_SMALL
)
871 if (m_ownsImageListSmall
) delete m_imageListSmall
;
872 m_imageListSmall
= imageList
;
873 m_ownsImageListSmall
= false;
875 else if ( which
== wxIMAGE_LIST_STATE
)
877 if (m_ownsImageListState
) delete m_imageListState
;
878 m_imageListState
= imageList
;
879 m_ownsImageListState
= false;
883 void wxListCtrl::AssignImageList(wxImageList
*imageList
, int which
)
886 m_genericImpl
->AssignImageList(imageList
, which
);
890 SetImageList(imageList
, which
);
891 if ( which
== wxIMAGE_LIST_NORMAL
)
892 m_ownsImageListNormal
= true;
893 else if ( which
== wxIMAGE_LIST_SMALL
)
894 m_ownsImageListSmall
= true;
895 else if ( which
== wxIMAGE_LIST_STATE
)
896 m_ownsImageListState
= true;
899 // ----------------------------------------------------------------------------
901 // ----------------------------------------------------------------------------
903 // Arranges the items
904 bool wxListCtrl::Arrange(int flag
)
907 return m_genericImpl
->Arrange(flag
);
912 bool wxListCtrl::DeleteItem(long item
)
915 return m_genericImpl
->DeleteItem(item
);
918 m_dbImpl
->MacDelete(item
);
919 wxListEvent
event( wxEVT_COMMAND_LIST_DELETE_ITEM
, GetId() );
920 event
.SetEventObject( this );
921 event
.m_itemIndex
= item
;
922 GetEventHandler()->ProcessEvent( event
);
929 bool wxListCtrl::DeleteAllItems()
932 return m_genericImpl
->DeleteAllItems();
935 m_dbImpl
->MacClear();
936 wxListEvent
event( wxEVT_COMMAND_LIST_DELETE_ALL_ITEMS
, GetId() );
937 event
.SetEventObject( this );
938 GetEventHandler()->ProcessEvent( event
);
944 bool wxListCtrl::DeleteAllColumns()
947 return m_genericImpl
->DeleteAllColumns();
951 m_dbImpl
->GetColumnCount(&cols
);
952 for (UInt32 col
= 0; col
< cols
; col
++){
961 bool wxListCtrl::DeleteColumn(int col
)
964 return m_genericImpl
->DeleteColumn(col
);
967 OSStatus err
= m_dbImpl
->RemoveColumn(col
);
974 // Clears items, and columns if there are any.
975 void wxListCtrl::ClearAll()
978 m_genericImpl
->ClearAll();
988 wxTextCtrl
* wxListCtrl::EditLabel(long item
, wxClassInfo
* textControlClass
)
991 return m_genericImpl
->EditLabel(item
, textControlClass
);
994 wxMacDataItem
* id
= m_dbImpl
->GetItemFromLine(item
);
995 verify_noerr( SetDataBrowserEditItem(m_dbImpl
->GetControlRef(), (DataBrowserItemID
)id
, kMinColumnId
) );
1000 // End label editing, optionally cancelling the edit
1001 bool wxListCtrl::EndEditLabel(bool cancel
)
1003 // TODO: generic impl. doesn't have this method - is it needed for us?
1005 return true; // m_genericImpl->EndEditLabel(cancel);
1008 verify_noerr( SetDataBrowserEditItem(m_dbImpl
->GetControlRef(), kDataBrowserNoItem
, kMinColumnId
) );
1012 // Ensures this item is visible
1013 bool wxListCtrl::EnsureVisible(long item
)
1016 return m_genericImpl
->EnsureVisible(item
);
1019 wxMacDataItem
* dataItem
= m_dbImpl
->GetItemFromLine(item
);
1020 m_dbImpl
->RevealItem(dataItem
, kDataBrowserRevealWithoutSelecting
);
1024 // Find an item whose label matches this string, starting from the item after 'start'
1025 // or the beginning if 'start' is -1.
1026 long wxListCtrl::FindItem(long start
, const wxString
& str
, bool partial
)
1029 return m_genericImpl
->FindItem(start
, str
, partial
);
1034 // Find an item whose data matches this data, starting from the item after 'start'
1035 // or the beginning if 'start' is -1.
1036 long wxListCtrl::FindItem(long start
, long data
)
1039 return m_genericImpl
->FindItem(start
, data
);
1041 long idx
= start
+ 1;
1042 long count
= GetItemCount();
1046 if (GetItemData(idx
) == data
)
1054 // Find an item nearest this position in the specified direction, starting from
1055 // the item after 'start' or the beginning if 'start' is -1.
1056 long wxListCtrl::FindItem(long start
, const wxPoint
& pt
, int direction
)
1059 return m_genericImpl
->FindItem(start
, pt
, direction
);
1063 // Determines which item (if any) is at the specified point,
1064 // giving details in 'flags' (see wxLIST_HITTEST_... flags above)
1066 wxListCtrl::HitTest(const wxPoint
& point
, int& flags
, long *ptrSubItem
) const
1069 return m_genericImpl
->HitTest(point
, flags
, ptrSubItem
);
1075 // Inserts an item, returning the index of the new item if successful,
1077 long wxListCtrl::InsertItem(wxListItem
& info
)
1079 wxASSERT_MSG( !IsVirtual(), _T("can't be used with virtual controls") );
1082 return m_genericImpl
->InsertItem(info
);
1085 int count
= GetItemCount();
1087 if (info
.m_itemId
> count
)
1088 info
.m_itemId
= count
;
1090 m_dbImpl
->MacInsertItem(info
.m_itemId
, &info
);
1091 wxListEvent
event( wxEVT_COMMAND_LIST_INSERT_ITEM
, GetId() );
1092 event
.SetEventObject( this );
1093 event
.m_itemIndex
= info
.m_itemId
;
1094 GetEventHandler()->ProcessEvent( event
);
1097 return info
.m_itemId
;
1100 long wxListCtrl::InsertItem(long index
, const wxString
& label
)
1103 return m_genericImpl
->InsertItem(index
, label
);
1106 info
.m_text
= label
;
1107 info
.m_mask
= wxLIST_MASK_TEXT
;
1108 info
.m_itemId
= index
;
1109 return InsertItem(info
);
1112 // Inserts an image item
1113 long wxListCtrl::InsertItem(long index
, int imageIndex
)
1116 return m_genericImpl
->InsertItem(index
, imageIndex
);
1119 info
.m_image
= imageIndex
;
1120 info
.m_mask
= wxLIST_MASK_IMAGE
;
1121 info
.m_itemId
= index
;
1122 return InsertItem(info
);
1125 // Inserts an image/string item
1126 long wxListCtrl::InsertItem(long index
, const wxString
& label
, int imageIndex
)
1129 return m_genericImpl
->InsertItem(index
, label
, imageIndex
);
1132 info
.m_image
= imageIndex
;
1133 info
.m_text
= label
;
1134 info
.m_mask
= wxLIST_MASK_IMAGE
| wxLIST_MASK_TEXT
;
1135 info
.m_itemId
= index
;
1136 return InsertItem(info
);
1139 // For list view mode (only), inserts a column.
1140 long wxListCtrl::InsertColumn(long col
, wxListItem
& item
)
1143 return m_genericImpl
->InsertColumn(col
, item
);
1146 if ( !(item
.GetMask() & wxLIST_MASK_WIDTH
) )
1149 DataBrowserPropertyType type
= kDataBrowserTextType
;
1150 wxImageList
* imageList
= GetImageList(wxIMAGE_LIST_SMALL
);
1151 if (imageList
&& imageList
->GetImageCount() > 0){
1152 wxBitmap bmp
= imageList
->GetBitmap(0);
1154 type
= kDataBrowserIconAndTextType
;
1157 fprintf(stderr
, "Flush is %d\n", item
.GetAlign());
1158 SInt16 just
= teFlushDefault
;
1159 if (item
.GetMask() & wxLIST_MASK_FORMAT
){
1160 if (item
.GetAlign() == wxLIST_FORMAT_LEFT
)
1162 else if (item
.GetAlign() == wxLIST_FORMAT_CENTER
)
1164 else if (item
.GetAlign() == wxLIST_FORMAT_RIGHT
)
1165 just
= teFlushRight
;
1167 m_dbImpl
->InsertColumn(col
, type
, item
.GetText(), just
, item
.GetWidth());
1169 if (GetWindowStyleFlag() & wxLC_EDIT_LABELS
)
1171 DataBrowserTableViewColumnID id
;
1172 m_dbImpl
->GetColumnIDFromIndex(col
, &id
);
1173 DataBrowserPropertyFlags flags
;
1174 verify_noerr(m_dbImpl
->GetPropertyFlags(id
, &flags
));
1175 flags
|= kDataBrowserPropertyIsEditable
;
1176 verify_noerr(m_dbImpl
->SetPropertyFlags(id
, flags
));
1183 long wxListCtrl::InsertColumn(long col
,
1184 const wxString
& heading
,
1189 return m_genericImpl
->InsertColumn(col
, heading
, format
, width
);
1192 item
.m_mask
= wxLIST_MASK_TEXT
| wxLIST_MASK_FORMAT
;
1193 item
.m_text
= heading
;
1196 item
.m_mask
|= wxLIST_MASK_WIDTH
;
1197 item
.m_width
= width
;
1199 item
.m_format
= format
;
1201 return InsertColumn(col
, item
);
1204 // scroll the control by the given number of pixels (exception: in list view,
1205 // dx is interpreted as number of columns)
1206 bool wxListCtrl::ScrollList(int dx
, int dy
)
1209 return m_genericImpl
->ScrollList(dx
, dy
);
1212 m_dbImpl
->SetScrollPosition(dx
, dy
);
1218 bool wxListCtrl::SortItems(wxListCtrlCompare fn
, long data
)
1221 return m_genericImpl
->SortItems(fn
, data
);
1226 // ----------------------------------------------------------------------------
1227 // virtual list controls
1228 // ----------------------------------------------------------------------------
1230 wxString
wxListCtrl::OnGetItemText(long WXUNUSED(item
), long WXUNUSED(col
)) const
1232 // this is a pure virtual function, in fact - which is not really pure
1233 // because the controls which are not virtual don't need to implement it
1234 wxFAIL_MSG( _T("wxListCtrl::OnGetItemText not supposed to be called") );
1236 return wxEmptyString
;
1239 int wxListCtrl::OnGetItemImage(long WXUNUSED(item
)) const
1241 wxCHECK_MSG(!GetImageList(wxIMAGE_LIST_SMALL
),
1243 wxT("List control has an image list, OnGetItemImage or OnGetItemColumnImage should be overridden."));
1247 int wxListCtrl::OnGetItemColumnImage(long item
, long column
) const
1250 return OnGetItemImage(item
);
1255 wxListItemAttr
*wxListCtrl::OnGetItemAttr(long WXUNUSED_UNLESS_DEBUG(item
)) const
1257 wxASSERT_MSG( item
>= 0 && item
< GetItemCount(),
1258 _T("invalid item index in OnGetItemAttr()") );
1260 // no attributes by default
1264 void wxListCtrl::SetItemCount(long count
)
1266 wxASSERT_MSG( IsVirtual(), _T("this is for virtual controls only") );
1269 m_genericImpl
->SetItemCount(count
);
1276 void wxListCtrl::RefreshItem(long item
)
1279 m_genericImpl
->RefreshItem(item
);
1284 GetItemRect(item
, rect
);
1288 void wxListCtrl::RefreshItems(long itemFrom
, long itemTo
)
1291 m_genericImpl
->RefreshItems(itemFrom
, itemTo
);
1295 wxRect rect1
, rect2
;
1296 GetItemRect(itemFrom
, rect1
);
1297 GetItemRect(itemTo
, rect2
);
1299 wxRect rect
= rect1
;
1300 rect
.height
= rect2
.GetBottom() - rect1
.GetTop();
1306 // wxMac internal data structures
1308 wxMacListCtrlItem::~wxMacListCtrlItem()
1312 void wxMacListCtrlItem::Notification(wxMacDataItemBrowserControl
*owner
,
1313 DataBrowserItemNotification message
,
1314 DataBrowserItemDataRef itemData
) const
1317 wxMacDataBrowserListCtrlControl
*lb
= dynamic_cast<wxMacDataBrowserListCtrlControl
*>(owner
);
1319 // we want to depend on as little as possible to make sure tear-down of controls is safe
1320 if ( message
== kDataBrowserItemRemoved
)
1322 if ( lb
!= NULL
&& lb
->GetClientDataType() == wxClientData_Object
)
1324 delete (wxClientData
*) (m_data
);
1330 else if ( message
== kDataBrowserItemAdded
)
1332 // we don't issue events on adding, the item is not really stored in the list yet, so we
1333 // avoid asserts by gettting out now
1337 wxListCtrl
*list
= wxDynamicCast( owner
->GetPeer() , wxListCtrl
);
1339 bool trigger
= false;
1341 wxListEvent
event( wxEVT_COMMAND_LIST_ITEM_SELECTED
, list
->GetId() );
1342 bool isSingle
= list
->GetWindowStyle() | wxLC_SINGLE_SEL
;
1344 event
.SetEventObject( list
);
1345 event
.m_itemIndex
= owner
->GetLineFromItem( this ) ;
1346 if ( !list
->IsVirtual() )
1348 lb
->MacGetColumnInfo(event
.m_itemIndex
,0,event
.m_item
);
1353 case kDataBrowserItemDeselected
:
1354 event
.SetEventType(wxEVT_COMMAND_LIST_ITEM_DESELECTED
);
1356 trigger
= !lb
->IsSelectionSuppressed();
1359 case kDataBrowserItemSelected
:
1360 trigger
= !lb
->IsSelectionSuppressed();
1363 case kDataBrowserItemDoubleClicked
:
1364 event
.SetEventType( wxEVT_LEFT_DCLICK
);
1368 case kDataBrowserEditStarted
:
1369 // TODO : how to veto ?
1370 event
.SetEventType( wxEVT_COMMAND_LIST_BEGIN_LABEL_EDIT
) ;
1374 case kDataBrowserEditStopped
:
1375 // TODO probably trigger only upon the value store callback, because
1376 // here IIRC we cannot veto
1377 event
.SetEventType( wxEVT_COMMAND_LIST_END_LABEL_EDIT
) ;
1387 // direct notification is not always having the listbox GetSelection() having in synch with event
1388 wxPostEvent( list
->GetEventHandler(), event
);
1394 wxMacDataBrowserListCtrlControl::wxMacDataBrowserListCtrlControl( wxWindow
*peer
, const wxPoint
& pos
, const wxSize
& size
, long style
)
1395 : wxMacDataItemBrowserControl( peer
, pos
, size
, style
)
1397 OSStatus err
= noErr
;
1398 m_clientDataItemsType
= wxClientData_None
;
1400 DataBrowserSelectionFlags options
= kDataBrowserDragSelect
;
1401 if ( style
& wxLC_SINGLE_SEL
)
1403 options
|= kDataBrowserSelectOnlyOne
;
1407 options
|= kDataBrowserCmdTogglesSelection
;
1410 err
= SetSelectionFlags( options
);
1411 verify_noerr( err
);
1413 if ( style
& wxLC_LIST
){
1414 InsertColumn(0, kDataBrowserIconAndTextType
, wxEmptyString
, -1, -1);
1415 verify_noerr( AutoSizeColumns() );
1418 if ( style
& wxLC_LIST
|| style
& wxLC_NO_HEADER
)
1419 verify_noerr( SetHeaderButtonHeight( 0 ) );
1421 SetDataBrowserSortProperty( m_controlRef
, kMinColumnId
);
1422 if ( style
& wxLC_SORT_ASCENDING
)
1424 m_sortOrder
= SortOrder_Text_Ascending
;
1425 SetDataBrowserSortProperty( m_controlRef
, kMinColumnId
);
1426 SetDataBrowserSortOrder( m_controlRef
, kDataBrowserOrderIncreasing
);
1428 else if ( style
& wxLC_SORT_DESCENDING
)
1430 m_sortOrder
= SortOrder_Text_Descending
;
1431 SetDataBrowserSortProperty( m_controlRef
, kMinColumnId
);
1432 SetDataBrowserSortOrder( m_controlRef
, kDataBrowserOrderDecreasing
);
1436 m_sortOrder
= SortOrder_None
;
1437 SetDataBrowserSortProperty( m_controlRef
, kMinColumnId
);
1438 SetDataBrowserSortOrder( m_controlRef
, kDataBrowserOrderIncreasing
);
1441 if ( style
& wxLC_VRULES
){
1442 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4
1443 verify_noerr( DataBrowserChangeAttributes(m_controlRef
, kDataBrowserAttributeListViewDrawColumnDividers
, kDataBrowserAttributeNone
) );
1447 verify_noerr( AutoSizeColumns() );
1448 verify_noerr( SetHiliteStyle(kDataBrowserTableViewFillHilite
) );
1449 err
= SetHasScrollBars( (style
& wxHSCROLL
) != 0 , true );
1452 wxMacDataBrowserListCtrlControl::~wxMacDataBrowserListCtrlControl()
1456 void wxMacDataBrowserListCtrlControl::MacSetColumnInfo( unsigned int row
, unsigned int column
, wxListItem
* item
)
1458 wxMacDataItem
* dataItem
= GetItemFromLine(row
);
1460 wxMacListCtrlItem
* listItem
= dynamic_cast<wxMacListCtrlItem
*>(dataItem
);
1461 listItem
->SetColumnInfo( column
, item
);
1462 UpdateState(dataItem
, item
);
1466 // apply changes that need to happen immediately, rather than when the
1467 // databrowser control fires a callback.
1468 void wxMacDataBrowserListCtrlControl::UpdateState(wxMacDataItem
* dataItem
, wxListItem
* listItem
)
1470 bool isSelected
= IsItemSelected( dataItem
);
1471 bool isSelectedState
= (listItem
->GetState() == wxLIST_STATE_SELECTED
);
1473 // toggle the selection state if wxListInfo state and actual state don't match.
1474 if ( isSelected
!= isSelectedState
){
1475 DataBrowserSetOption options
= kDataBrowserItemsAdd
;
1476 if (!isSelectedState
)
1477 options
= kDataBrowserItemsRemove
;
1478 fprintf(stderr
, "state = %d, db options = %d\n", isSelectedState
, options
);
1479 SetSelectedItem(dataItem
, options
);
1481 // TODO: Set column width if item width > than current column width
1484 void wxMacDataBrowserListCtrlControl::MacGetColumnInfo( unsigned int row
, unsigned int column
, wxListItem
& item
)
1486 wxMacDataItem
* dataItem
= GetItemFromLine(row
);
1487 // CS should this guard against dataItem = 0 ? , as item is not a pointer if (item) is not appropriate
1490 wxMacListCtrlItem
* listItem
= dynamic_cast<wxMacListCtrlItem
*>(dataItem
);
1491 wxListItem
* oldItem
= listItem
->GetColumnInfo( column
);
1493 long mask
= item
.GetMask();
1495 // by default, get everything for backwards compatibility
1498 if ( mask
& wxLIST_MASK_TEXT
)
1499 item
.SetText(oldItem
->GetText());
1500 if ( mask
& wxLIST_MASK_IMAGE
)
1501 item
.SetImage(oldItem
->GetImage());
1502 if ( mask
& wxLIST_MASK_DATA
)
1503 item
.SetData(oldItem
->GetData());
1504 if ( mask
& wxLIST_MASK_STATE
)
1505 item
.SetState(oldItem
->GetState());
1506 if ( mask
& wxLIST_MASK_WIDTH
)
1507 item
.SetWidth(oldItem
->GetWidth());
1508 if ( mask
& wxLIST_MASK_FORMAT
)
1509 item
.SetAlign(oldItem
->GetAlign());
1511 item
.SetTextColour(oldItem
->GetTextColour());
1512 item
.SetBackgroundColour(oldItem
->GetBackgroundColour());
1513 item
.SetFont(oldItem
->GetFont());
1517 void wxMacDataBrowserListCtrlControl::MacInsertItem( unsigned int n
, wxListItem
* item
)
1519 wxMacDataItemBrowserControl::MacInsert(n
, item
->GetText());
1520 MacSetColumnInfo(n
, 0, item
);
1523 wxMacListCtrlItem
* wxMacDataBrowserListCtrlControl::CreateItem()
1525 return new wxMacListCtrlItem();
1528 wxMacListCtrlItem::wxMacListCtrlItem()
1530 m_rowItems
= wxListItemList();
1533 int wxMacListCtrlItem::GetColumnImageValue( unsigned int column
)
1535 return GetColumnInfo(column
)->GetImage();
1538 void wxMacListCtrlItem::SetColumnImageValue( unsigned int column
, int imageIndex
)
1540 GetColumnInfo(column
)->SetImage(imageIndex
);
1543 const wxString
& wxMacListCtrlItem::GetColumnTextValue( unsigned int column
)
1548 return GetColumnInfo(column
)->GetText();
1551 void wxMacListCtrlItem::SetColumnTextValue( unsigned int column
, const wxString
& text
)
1553 GetColumnInfo(column
)->SetText(text
);
1555 // for compatibility with superclass APIs
1560 wxListItem
* wxMacListCtrlItem::GetColumnInfo( unsigned int column
)
1562 wxListItemList::compatibility_iterator node
= m_rowItems
.Item( column
);
1563 wxASSERT_MSG( node
, _T("invalid column index in wxMacListCtrlItem") );
1565 return node
->GetData();
1568 bool wxMacListCtrlItem::HasColumnInfo( unsigned int column
)
1570 return m_rowItems
.GetCount() > column
;
1573 void wxMacListCtrlItem::SetColumnInfo( unsigned int column
, wxListItem
* item
)
1576 if ( column
>= m_rowItems
.GetCount() ){
1577 wxListItem
* listItem
= new wxListItem(*item
);
1578 //listItem->SetAlign(item->GetAlign());
1579 //listItem->SetBackgroundColour(item->GetBackgroundColour());
1580 //listItem->SetColumn(item->GetColumn());
1581 //listItem->SetData(item->GetData());
1582 //listItem->SetFont(item->GetFont());
1583 //listItem->SetId(GetOrder());
1584 //listItem->SetImage(item->GetImage());
1585 //listItem->SetMask(item->GetMask());
1587 //listItem->SetText(item->GetText());
1588 m_rowItems
.Append( listItem
);
1591 wxListItem
* listItem
= GetColumnInfo( column
);
1592 long mask
= item
->GetMask();
1593 if (mask
& wxLIST_MASK_TEXT
)
1594 listItem
->SetText(item
->GetText());
1595 if (mask
& wxLIST_MASK_DATA
)
1596 listItem
->SetData(item
->GetData());
1597 if (mask
& wxLIST_MASK_IMAGE
)
1598 listItem
->SetImage(item
->GetImage());
1599 if (mask
& wxLIST_MASK_STATE
)
1600 listItem
->SetState(item
->GetState());
1601 if (mask
& wxLIST_MASK_FORMAT
)
1602 listItem
->SetAlign(item
->GetAlign());
1603 if (mask
& wxLIST_MASK_WIDTH
)
1604 listItem
->SetWidth(item
->GetWidth());
1608 OSStatus
wxMacListCtrlItem::GetSetData( wxMacDataItemBrowserControl
*owner
,
1609 DataBrowserPropertyID property
,
1610 DataBrowserItemDataRef itemData
,
1614 OSStatus err
= errDataBrowserPropertyNotSupported
;
1615 wxListCtrl
* list
= wxDynamicCast( owner
->GetPeer() , wxListCtrl
);
1620 case kDataBrowserItemIsEditableProperty
:
1621 if ( list
&& list
->HasFlag( wxLC_EDIT_LABELS
) )
1623 verify_noerr(SetDataBrowserItemDataBooleanValue( itemData
, true ));
1628 if ( property
>= kMinColumnId
){
1629 short listColumn
= property
- kMinColumnId
;
1631 if (HasColumnInfo(listColumn
)){
1632 wxListItem
* item
= GetColumnInfo(listColumn
);
1633 wxMacCFStringHolder cfStr
;
1635 if (item
->GetText()){
1636 cfStr
.Assign( item
->GetText(), wxLocale::GetSystemEncoding() );
1637 err
= ::SetDataBrowserItemDataText( itemData
, cfStr
);
1641 int imgIndex
= item
->GetImage();
1642 if ( (item
->GetMask() & wxLIST_MASK_IMAGE
) ){
1643 wxImageList
* imageList
= list
->GetImageList(wxIMAGE_LIST_SMALL
);
1644 if (imageList
&& imageList
->GetImageCount() > 0){
1645 wxBitmap bmp
= imageList
->GetBitmap(imgIndex
);
1646 IconRef icon
= bmp
.GetBitmapData()->GetIconRef();
1647 ::SetDataBrowserItemDataIcon(itemData
, icon
);
1661 if ( property
>= kMinColumnId
){
1662 short listColumn
= property
- kMinColumnId
;
1664 if (HasColumnInfo(listColumn
)){
1665 // TODO probably send the 'end edit' from here, as we
1666 // can then deal with the veto
1668 verify_noerr( GetDataBrowserItemDataText( itemData
, &sr
) ) ;
1669 wxMacCFStringHolder
cfStr(sr
) ;;
1670 list
->SetItem( owner
->GetLineFromItem(this) , listColumn
, cfStr
.AsString() ) ;
1678 // don't duplicate the numeric order column handling
1679 if (err
== errDataBrowserPropertyNotSupported
)
1680 err
= wxMacDataItem::GetSetData(owner
, property
, itemData
, changeValue
);
1685 #endif // wxUSE_LISTCTRL