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"
41 #include "wx/hashmap.h"
43 #if wxUSE_EXTENDED_RTTI
44 WX_DEFINE_FLAGS( wxListCtrlStyle
)
46 wxBEGIN_FLAGS( wxListCtrlStyle
)
47 // new style border flags, we put them first to
48 // use them for streaming out
49 wxFLAGS_MEMBER(wxBORDER_SIMPLE
)
50 wxFLAGS_MEMBER(wxBORDER_SUNKEN
)
51 wxFLAGS_MEMBER(wxBORDER_DOUBLE
)
52 wxFLAGS_MEMBER(wxBORDER_RAISED
)
53 wxFLAGS_MEMBER(wxBORDER_STATIC
)
54 wxFLAGS_MEMBER(wxBORDER_NONE
)
56 // old style border flags
57 wxFLAGS_MEMBER(wxSIMPLE_BORDER
)
58 wxFLAGS_MEMBER(wxSUNKEN_BORDER
)
59 wxFLAGS_MEMBER(wxDOUBLE_BORDER
)
60 wxFLAGS_MEMBER(wxRAISED_BORDER
)
61 wxFLAGS_MEMBER(wxSTATIC_BORDER
)
62 wxFLAGS_MEMBER(wxBORDER
)
64 // standard window styles
65 wxFLAGS_MEMBER(wxTAB_TRAVERSAL
)
66 wxFLAGS_MEMBER(wxCLIP_CHILDREN
)
67 wxFLAGS_MEMBER(wxTRANSPARENT_WINDOW
)
68 wxFLAGS_MEMBER(wxWANTS_CHARS
)
69 wxFLAGS_MEMBER(wxFULL_REPAINT_ON_RESIZE
)
70 wxFLAGS_MEMBER(wxALWAYS_SHOW_SB
)
71 wxFLAGS_MEMBER(wxVSCROLL
)
72 wxFLAGS_MEMBER(wxHSCROLL
)
74 wxFLAGS_MEMBER(wxLC_LIST
)
75 wxFLAGS_MEMBER(wxLC_REPORT
)
76 wxFLAGS_MEMBER(wxLC_ICON
)
77 wxFLAGS_MEMBER(wxLC_SMALL_ICON
)
78 wxFLAGS_MEMBER(wxLC_ALIGN_TOP
)
79 wxFLAGS_MEMBER(wxLC_ALIGN_LEFT
)
80 wxFLAGS_MEMBER(wxLC_AUTOARRANGE
)
81 wxFLAGS_MEMBER(wxLC_USER_TEXT
)
82 wxFLAGS_MEMBER(wxLC_EDIT_LABELS
)
83 wxFLAGS_MEMBER(wxLC_NO_HEADER
)
84 wxFLAGS_MEMBER(wxLC_SINGLE_SEL
)
85 wxFLAGS_MEMBER(wxLC_SORT_ASCENDING
)
86 wxFLAGS_MEMBER(wxLC_SORT_DESCENDING
)
87 wxFLAGS_MEMBER(wxLC_VIRTUAL
)
89 wxEND_FLAGS( wxListCtrlStyle
)
91 IMPLEMENT_DYNAMIC_CLASS_XTI(wxListCtrl
, wxControl
,"wx/listctrl.h")
93 wxBEGIN_PROPERTIES_TABLE(wxListCtrl
)
94 wxEVENT_PROPERTY( TextUpdated
, wxEVT_COMMAND_TEXT_UPDATED
, wxCommandEvent
)
96 wxPROPERTY_FLAGS( WindowStyle
, wxListCtrlStyle
, long , SetWindowStyleFlag
, GetWindowStyleFlag
, EMPTY_MACROVALUE
, 0 /*flags*/ , wxT("Helpstring") , wxT("group")) // style
97 wxEND_PROPERTIES_TABLE()
99 wxBEGIN_HANDLERS_TABLE(wxListCtrl
)
100 wxEND_HANDLERS_TABLE()
102 wxCONSTRUCTOR_5( wxListCtrl
, wxWindow
* , Parent
, wxWindowID
, Id
, wxPoint
, Position
, wxSize
, Size
, long , WindowStyle
)
105 TODO : Expose more information of a list's layout etc. via appropriate objects (à la NotebookPageInfo)
108 IMPLEMENT_DYNAMIC_CLASS(wxListCtrl
, wxControl
)
111 IMPLEMENT_DYNAMIC_CLASS(wxListView
, wxListCtrl
)
112 IMPLEMENT_DYNAMIC_CLASS(wxListItem
, wxObject
)
114 IMPLEMENT_DYNAMIC_CLASS(wxListEvent
, wxNotifyEvent
)
116 WX_DECLARE_HASH_MAP( int, wxListItem
*, wxIntegerHash
, wxIntegerEqual
, wxListItemList
);
118 #include "wx/listimpl.cpp"
119 WX_DEFINE_LIST(wxColumnList
)
121 // so we can check for column clicks
122 static const EventTypeSpec eventList
[] =
124 { kEventClassControl
, kEventControlHit
},
125 { kEventClassControl
, kEventControlDraw
}
128 static pascal OSStatus
wxMacListCtrlEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
130 OSStatus result
= eventNotHandledErr
;
132 wxMacCarbonEvent
cEvent( event
) ;
134 ControlRef controlRef
;
135 cEvent
.GetParameter( kEventParamDirectObject
, &controlRef
) ;
137 wxListCtrl
*window
= (wxListCtrl
*) data
;
138 wxListEvent
le( wxEVT_COMMAND_LIST_COL_CLICK
, window
->GetId() );
139 le
.SetEventObject( window
);
141 switch ( GetEventKind( event
) )
143 // check if the column was clicked on and fire an event if so
144 case kEventControlHit
:
146 ControlPartCode result
= cEvent
.GetParameter
<ControlPartCode
>(kEventParamControlPart
, typeControlPartCode
) ;
147 if (result
== kControlButtonPart
){
148 DataBrowserPropertyID col
;
149 GetDataBrowserSortProperty(controlRef
, &col
);
150 int column
= col
- kMinColumnId
;
152 // FIXME: we can't use the sort property for virtual listctrls
153 // so we need to find a better way to determine which column was clicked...
154 if (!window
->IsVirtual())
155 window
->GetEventHandler()->ProcessEvent( le
);
157 result
= CallNextEventHandler(handler
, event
);
160 case kEventControlDraw
:
162 CGContextRef context
= cEvent
.GetParameter
<CGContextRef
>(kEventParamCGContextRef
, typeCGContextRef
) ;
163 window
->MacSetDrawingContext(context
);
164 result
= CallNextEventHandler(handler
, event
);
165 window
->MacSetDrawingContext(NULL
);
176 DEFINE_ONE_SHOT_HANDLER_GETTER( wxMacListCtrlEventHandler
)
178 class wxMacListCtrlItem
: public wxMacListBoxItem
183 virtual void Notification(wxMacDataItemBrowserControl
*owner
,
184 DataBrowserItemNotification message
,
185 DataBrowserItemDataRef itemData
) const;
187 virtual void SetColumnInfo( unsigned int column
, wxListItem
* item
);
188 virtual wxListItem
* GetColumnInfo( unsigned int column
);
189 virtual bool HasColumnInfo( unsigned int column
);
191 virtual void SetColumnTextValue( unsigned int column
, const wxString
& text
);
192 virtual wxString
GetColumnTextValue( unsigned int column
);
194 virtual int GetColumnImageValue( unsigned int column
);
195 virtual void SetColumnImageValue( unsigned int column
, int imageIndex
);
197 virtual ~wxMacListCtrlItem();
199 wxListItemList m_rowItems
;
202 DataBrowserDrawItemUPP gDataBrowserDrawItemUPP
= NULL
;
203 //DataBrowserEditItemUPP gDataBrowserEditItemUPP = NULL;
204 DataBrowserHitTestUPP gDataBrowserHitTestUPP
= NULL
;
206 // TODO: Make a better name!!
207 class wxMacDataBrowserListCtrlControl
: public wxMacDataItemBrowserControl
210 wxMacDataBrowserListCtrlControl( wxWindow
*peer
, const wxPoint
& pos
, const wxSize
& size
, long style
);
211 wxMacDataBrowserListCtrlControl() {}
212 virtual ~wxMacDataBrowserListCtrlControl();
214 // create a list item (can be a subclass of wxMacListBoxItem)
216 virtual wxMacDataItem
* CreateItem();
218 virtual void MacInsertItem( unsigned int n
, wxListItem
* item
);
219 virtual void MacSetColumnInfo( unsigned int row
, unsigned int column
, wxListItem
* item
);
220 virtual void MacGetColumnInfo( unsigned int row
, unsigned int column
, wxListItem
& item
);
221 virtual void UpdateState(wxMacDataItem
* dataItem
, wxListItem
* item
);
222 int GetFlags() { return m_flags
; }
225 // we need to override to provide specialized handling for virtual wxListCtrls
226 virtual OSStatus
GetSetItemData(DataBrowserItemID itemID
,
227 DataBrowserPropertyID property
,
228 DataBrowserItemDataRef itemData
,
229 Boolean changeValue
);
231 virtual void ItemNotification(
232 DataBrowserItemID itemID
,
233 DataBrowserItemNotification message
,
234 DataBrowserItemDataRef itemData
);
236 virtual Boolean
CompareItems(DataBrowserItemID itemOneID
,
237 DataBrowserItemID itemTwoID
,
238 DataBrowserPropertyID sortProperty
);
240 static pascal void DataBrowserDrawItemProc(ControlRef browser
,
241 DataBrowserItemID item
,
242 DataBrowserPropertyID property
,
243 DataBrowserItemState itemState
,
246 Boolean colorDevice
);
248 virtual void DrawItem(DataBrowserItemID itemID
,
249 DataBrowserPropertyID property
,
250 DataBrowserItemState itemState
,
251 const Rect
*itemRect
,
253 Boolean colorDevice
);
255 static pascal Boolean
DataBrowserEditTextProc(ControlRef browser
,
256 DataBrowserItemID item
,
257 DataBrowserPropertyID property
,
258 CFStringRef theString
,
259 Rect
*maxEditTextRect
,
260 Boolean
*shrinkToFit
);
262 static pascal Boolean
DataBrowserHitTestProc(ControlRef browser
,
263 DataBrowserItemID itemID
,
264 DataBrowserPropertyID property
,
266 const Rect
*mouseRect
) { return true; }
268 virtual bool ConfirmEditText(DataBrowserItemID item
,
269 DataBrowserPropertyID property
,
270 CFStringRef theString
,
271 Rect
*maxEditTextRect
,
272 Boolean
*shrinkToFit
);
276 wxClientDataType m_clientDataItemsType
;
279 DECLARE_DYNAMIC_CLASS_NO_COPY(wxMacDataBrowserListCtrlControl
)
282 class wxMacListCtrlEventDelegate
: public wxEvtHandler
285 wxMacListCtrlEventDelegate( wxListCtrl
* list
, int id
);
286 virtual bool ProcessEvent( wxEvent
& event
);
293 wxMacListCtrlEventDelegate::wxMacListCtrlEventDelegate( wxListCtrl
* list
, int id
)
299 bool wxMacListCtrlEventDelegate::ProcessEvent( wxEvent
& event
)
301 // even though we use a generic list ctrl underneath, make sure
302 // we present ourselves as wxListCtrl.
303 event
.SetEventObject( m_list
);
306 if ( !event
.IsKindOf( CLASSINFO( wxCommandEvent
) ) )
308 if (m_list
->GetEventHandler()->ProcessEvent( event
))
311 return wxEvtHandler::ProcessEvent(event
);
314 //-----------------------------------------------------------------------------
315 // wxListCtrlRenameTimer (internal)
316 //-----------------------------------------------------------------------------
318 class wxListCtrlRenameTimer
: public wxTimer
324 wxListCtrlRenameTimer( wxListCtrl
*owner
);
328 //-----------------------------------------------------------------------------
329 // wxListCtrlTextCtrlWrapper: wraps a wxTextCtrl to make it work for inline editing
330 //-----------------------------------------------------------------------------
332 class wxListCtrlTextCtrlWrapper
: public wxEvtHandler
335 // NB: text must be a valid object but not Create()d yet
336 wxListCtrlTextCtrlWrapper(wxListCtrl
*owner
,
340 wxTextCtrl
*GetText() const { return m_text
; }
342 void AcceptChangesAndFinish();
345 void OnChar( wxKeyEvent
&event
);
346 void OnKeyUp( wxKeyEvent
&event
);
347 void OnKillFocus( wxFocusEvent
&event
);
349 bool AcceptChanges();
355 wxString m_startValue
;
358 bool m_aboutToFinish
;
360 DECLARE_EVENT_TABLE()
363 //-----------------------------------------------------------------------------
364 // wxListCtrlRenameTimer (internal)
365 //-----------------------------------------------------------------------------
367 wxListCtrlRenameTimer::wxListCtrlRenameTimer( wxListCtrl
*owner
)
372 void wxListCtrlRenameTimer::Notify()
374 m_owner
->OnRenameTimer();
377 //-----------------------------------------------------------------------------
378 // wxListCtrlTextCtrlWrapper (internal)
379 //-----------------------------------------------------------------------------
381 BEGIN_EVENT_TABLE(wxListCtrlTextCtrlWrapper
, wxEvtHandler
)
382 EVT_CHAR (wxListCtrlTextCtrlWrapper::OnChar
)
383 EVT_KEY_UP (wxListCtrlTextCtrlWrapper::OnKeyUp
)
384 EVT_KILL_FOCUS (wxListCtrlTextCtrlWrapper::OnKillFocus
)
387 wxListCtrlTextCtrlWrapper::wxListCtrlTextCtrlWrapper(wxListCtrl
*owner
,
390 : m_startValue(owner
->GetItemText(itemEdit
)),
391 m_itemEdited(itemEdit
)
396 m_aboutToFinish
= false;
400 owner
->GetItemRect(itemEdit
, rectLabel
);
402 m_text
->Create(owner
, wxID_ANY
, m_startValue
,
403 wxPoint(rectLabel
.x
+offset
,rectLabel
.y
),
404 wxSize(rectLabel
.width
-offset
,rectLabel
.height
));
407 m_text
->PushEventHandler(this);
410 void wxListCtrlTextCtrlWrapper::Finish()
416 m_text
->RemoveEventHandler(this);
417 m_owner
->FinishEditing(m_text
);
419 wxPendingDelete
.Append( this );
423 bool wxListCtrlTextCtrlWrapper::AcceptChanges()
425 const wxString value
= m_text
->GetValue();
427 if ( value
== m_startValue
)
428 // nothing changed, always accept
431 if ( !m_owner
->OnRenameAccept(m_itemEdited
, value
) )
432 // vetoed by the user
435 // accepted, do rename the item
436 m_owner
->SetItemText(m_itemEdited
, value
);
441 void wxListCtrlTextCtrlWrapper::AcceptChangesAndFinish()
443 m_aboutToFinish
= true;
445 // Notify the owner about the changes
448 // Even if vetoed, close the control (consistent with MSW)
452 void wxListCtrlTextCtrlWrapper::OnChar( wxKeyEvent
&event
)
454 switch ( event
.m_keyCode
)
457 AcceptChangesAndFinish();
461 m_owner
->OnRenameCancelled( m_itemEdited
);
470 void wxListCtrlTextCtrlWrapper::OnKeyUp( wxKeyEvent
&event
)
478 // auto-grow the textctrl:
479 wxSize parentSize
= m_owner
->GetSize();
480 wxPoint myPos
= m_text
->GetPosition();
481 wxSize mySize
= m_text
->GetSize();
483 m_text
->GetTextExtent(m_text
->GetValue() + _T("MM"), &sx
, &sy
);
484 if (myPos
.x
+ sx
> parentSize
.x
)
485 sx
= parentSize
.x
- myPos
.x
;
488 m_text
->SetSize(sx
, wxDefaultCoord
);
493 void wxListCtrlTextCtrlWrapper::OnKillFocus( wxFocusEvent
&event
)
495 if ( !m_finished
&& !m_aboutToFinish
)
497 if ( !AcceptChanges() )
498 m_owner
->OnRenameCancelled( m_itemEdited
);
503 // We must let the native text control handle focus
507 BEGIN_EVENT_TABLE(wxListCtrl
, wxControl
)
508 EVT_LEFT_DOWN(wxListCtrl::OnLeftDown
)
509 EVT_LEFT_DCLICK(wxListCtrl::OnDblClick
)
510 EVT_MIDDLE_DOWN(wxListCtrl::OnMiddleDown
)
511 EVT_RIGHT_DOWN(wxListCtrl::OnRightDown
)
512 EVT_CHAR(wxListCtrl::OnChar
)
515 // ============================================================================
517 // ============================================================================
519 wxMacListControl
* wxListCtrl::GetPeer() const
521 wxMacDataBrowserListCtrlControl
*lb
= wxDynamicCast(m_peer
,wxMacDataBrowserListCtrlControl
);
522 return lb
? wx_static_cast(wxMacListControl
*,lb
) : 0 ;
525 // ----------------------------------------------------------------------------
526 // wxListCtrl construction
527 // ----------------------------------------------------------------------------
529 void wxListCtrl::Init()
531 m_imageListNormal
= NULL
;
532 m_imageListSmall
= NULL
;
533 m_imageListState
= NULL
;
535 // keep track of if we created our own image lists, or if they were assigned
537 m_ownsImageListNormal
= m_ownsImageListSmall
= m_ownsImageListState
= false;
541 m_genericImpl
= NULL
;
543 m_compareFunc
= NULL
;
544 m_compareFuncData
= 0;
545 m_colsInfo
= wxColumnList();
546 m_textColor
= wxNullColour
;
547 m_bgColor
= wxNullColour
;
548 m_textctrlWrapper
= NULL
;
550 m_renameTimer
= new wxListCtrlRenameTimer( this );
553 class wxGenericListCtrlHook
: public wxGenericListCtrl
556 wxGenericListCtrlHook(wxListCtrl
* parent
,
561 const wxValidator
& validator
,
562 const wxString
& name
)
563 : wxGenericListCtrl(parent
, id
, pos
, size
, style
, validator
, name
),
564 m_nativeListCtrl(parent
)
569 virtual wxListItemAttr
* OnGetItemAttr(long item
) const
571 return m_nativeListCtrl
->OnGetItemAttr(item
);
574 virtual int OnGetItemImage(long item
) const
576 return m_nativeListCtrl
->OnGetItemImage(item
);
579 virtual int OnGetItemColumnImage(long item
, long column
) const
581 return m_nativeListCtrl
->OnGetItemColumnImage(item
, column
);
584 virtual wxString
OnGetItemText(long item
, long column
) const
586 return m_nativeListCtrl
->OnGetItemText(item
, column
);
589 wxListCtrl
* m_nativeListCtrl
;
593 void wxListCtrl::OnLeftDown(wxMouseEvent
& event
)
595 if ( m_textctrlWrapper
)
598 m_textctrlWrapper
->AcceptChangesAndFinish();
602 long current
= HitTest(event
.GetPosition(), hitResult
);
603 if ((current
== m_current
) &&
604 (hitResult
== wxLIST_HITTEST_ONITEM
) &&
605 HasFlag(wxLC_EDIT_LABELS
) )
607 m_renameTimer
->Start( 100, true );
616 void wxListCtrl::OnDblClick(wxMouseEvent
& event
)
622 #if wxABI_VERSION >= 20801
623 void wxListCtrl::OnRightDown(wxMouseEvent
& event
)
626 FireMouseEvent(wxEVT_COMMAND_LIST_ITEM_RIGHT_CLICK
, event
.GetPosition());
630 void wxListCtrl::OnMiddleDown(wxMouseEvent
& event
)
633 FireMouseEvent(wxEVT_COMMAND_LIST_ITEM_MIDDLE_CLICK
, event
.GetPosition());
637 void wxListCtrl::FireMouseEvent(wxEventType eventType
, wxPoint position
)
639 wxListEvent
le( eventType
, GetId() );
640 le
.SetEventObject(this);
641 le
.m_pointDrag
= position
;
645 long item
= HitTest(position
, flags
);
646 if (flags
& wxLIST_HITTEST_ONITEM
)
648 le
.m_itemIndex
= item
;
652 le
.m_item
.m_itemId
= item
;
655 GetEventHandler()->ProcessEvent(le
);
659 void wxListCtrl::OnChar(wxKeyEvent
& event
)
663 wxListEvent
le( wxEVT_COMMAND_LIST_KEY_DOWN
, GetId() );
664 le
.SetEventObject(this);
665 le
.m_code
= event
.GetKeyCode();
670 le
.m_itemIndex
= m_current
;
673 le
.m_item
.m_itemId
= m_current
;
676 GetEventHandler()->ProcessEvent(le
);
683 bool wxListCtrl::Create(wxWindow
*parent
,
688 const wxValidator
& validator
,
689 const wxString
& name
)
692 // for now, we'll always use the generic list control for ICON and LIST views,
693 // because they dynamically change the number of columns on resize.
694 // Also, allow the user to set it to use the list ctrl as well.
695 if ( (wxSystemOptions::HasOption( wxMAC_ALWAYS_USE_GENERIC_LISTCTRL
)
696 && (wxSystemOptions::GetOptionInt( wxMAC_ALWAYS_USE_GENERIC_LISTCTRL
) == 1)) ||
697 (style
& wxLC_ICON
) || (style
& wxLC_SMALL_ICON
) || (style
& wxLC_LIST
) )
699 m_macIsUserPane
= true;
701 long paneStyle
= style
;
702 paneStyle
&= ~wxSIMPLE_BORDER
;
703 paneStyle
&= ~wxDOUBLE_BORDER
;
704 paneStyle
&= ~wxSUNKEN_BORDER
;
705 paneStyle
&= ~wxRAISED_BORDER
;
706 paneStyle
&= ~wxSTATIC_BORDER
;
707 if ( !wxWindow::Create(parent
, id
, pos
, size
, paneStyle
| wxNO_BORDER
, name
) )
710 // since the generic control is a child, make sure we position it at 0, 0
711 m_genericImpl
= new wxGenericListCtrlHook(this, id
, wxPoint(0, 0), size
, style
, validator
, name
);
712 m_genericImpl
->PushEventHandler( new wxMacListCtrlEventDelegate( this, GetId() ) );
718 m_macIsUserPane
= false;
719 if ( !wxWindow::Create(parent
, id
, pos
, size
, style
& ~(wxHSCROLL
| wxVSCROLL
), name
) )
721 m_dbImpl
= new wxMacDataBrowserListCtrlControl( this, pos
, size
, style
);
724 MacPostControlCreate( pos
, size
);
726 InstallControlEventHandler( m_peer
->GetControlRef() , GetwxMacListCtrlEventHandlerUPP(),
727 GetEventTypeCount(eventList
), eventList
, this,
728 (EventHandlerRef
*)&m_macListCtrlEventHandler
);
734 wxListCtrl::~wxListCtrl()
738 m_genericImpl
->PopEventHandler(/* deleteHandler = */ true);
741 if (m_ownsImageListNormal
)
742 delete m_imageListNormal
;
743 if (m_ownsImageListSmall
)
744 delete m_imageListSmall
;
745 if (m_ownsImageListState
)
746 delete m_imageListState
;
748 delete m_renameTimer
;
751 // ----------------------------------------------------------------------------
752 // set/get/change style
753 // ----------------------------------------------------------------------------
755 // Add or remove a single window style
756 void wxListCtrl::SetSingleStyle(long style
, bool add
)
758 long flag
= GetWindowStyleFlag();
760 // Get rid of conflicting styles
763 if ( style
& wxLC_MASK_TYPE
)
764 flag
= flag
& ~wxLC_MASK_TYPE
;
765 if ( style
& wxLC_MASK_ALIGN
)
766 flag
= flag
& ~wxLC_MASK_ALIGN
;
767 if ( style
& wxLC_MASK_SORT
)
768 flag
= flag
& ~wxLC_MASK_SORT
;
776 SetWindowStyleFlag(flag
);
779 // Set the whole window style
780 void wxListCtrl::SetWindowStyleFlag(long flag
)
782 if ( flag
!= m_windowStyle
)
784 m_windowStyle
= flag
;
788 m_genericImpl
->SetWindowStyleFlag(flag
);
795 void wxListCtrl::DoSetSize( int x
, int y
, int width
, int height
, int sizeFlags
)
797 wxControl::DoSetSize(x
, y
, width
, height
, sizeFlags
);
800 m_genericImpl
->SetSize(0, 0, width
, height
, sizeFlags
);
802 // determine if we need a horizontal scrollbar, and add it if so
806 for (int column
= 0; column
< GetColumnCount(); column
++)
808 totalWidth
+= m_dbImpl
->GetColumnWidth( column
);
811 if ( !(m_dbImpl
->GetFlags() & wxHSCROLL
) )
813 Boolean vertScrollBar
;
814 GetDataBrowserHasScrollBars( m_dbImpl
->GetControlRef(), NULL
, &vertScrollBar
);
815 if (totalWidth
> width
)
816 SetDataBrowserHasScrollBars( m_dbImpl
->GetControlRef(), true, vertScrollBar
);
818 SetDataBrowserHasScrollBars( m_dbImpl
->GetControlRef(), false, vertScrollBar
);
823 wxSize
wxListCtrl::DoGetBestSize() const
825 return wxWindow::DoGetBestSize();
828 bool wxListCtrl::SetFont(const wxFont
& font
)
831 rv
= wxControl::SetFont(font
);
833 rv
= m_genericImpl
->SetFont(font
);
837 bool wxListCtrl::SetForegroundColour(const wxColour
& colour
)
841 rv
= m_genericImpl
->SetForegroundColour(colour
);
843 SetTextColour(colour
);
847 bool wxListCtrl::SetBackgroundColour(const wxColour
& colour
)
851 rv
= m_genericImpl
->SetBackgroundColour(colour
);
857 wxColour
wxListCtrl::GetBackgroundColour()
860 return m_genericImpl
->GetBackgroundColour();
867 // ----------------------------------------------------------------------------
869 // ----------------------------------------------------------------------------
871 // Gets information about this column
872 bool wxListCtrl::GetColumn(int col
, wxListItem
& item
) const
875 return m_genericImpl
->GetColumn(col
, item
);
881 wxColumnList::compatibility_iterator node
= m_colsInfo
.Item( col
);
882 wxASSERT_MSG( node
, _T("invalid column index in wxMacListCtrlItem") );
883 wxListItem
* column
= node
->GetData();
885 long mask
= column
->GetMask();
886 if (mask
& wxLIST_MASK_TEXT
)
887 item
.SetText(column
->GetText());
888 if (mask
& wxLIST_MASK_DATA
)
889 item
.SetData(column
->GetData());
890 if (mask
& wxLIST_MASK_IMAGE
)
891 item
.SetImage(column
->GetImage());
892 if (mask
& wxLIST_MASK_STATE
)
893 item
.SetState(column
->GetState());
894 if (mask
& wxLIST_MASK_FORMAT
)
895 item
.SetAlign(column
->GetAlign());
896 if (mask
& wxLIST_MASK_WIDTH
)
897 item
.SetWidth(column
->GetWidth());
903 // Sets information about this column
904 bool wxListCtrl::SetColumn(int col
, wxListItem
& item
)
907 return m_genericImpl
->SetColumn(col
, item
);
911 long mask
= item
.GetMask();
912 if ( col
>= (int)m_colsInfo
.GetCount() )
914 wxListItem
* listItem
= new wxListItem(item
);
915 m_colsInfo
.Append( listItem
);
920 GetColumn( col
, listItem
);
922 if (mask
& wxLIST_MASK_TEXT
)
923 listItem
.SetText(item
.GetText());
924 if (mask
& wxLIST_MASK_DATA
)
925 listItem
.SetData(item
.GetData());
926 if (mask
& wxLIST_MASK_IMAGE
)
927 listItem
.SetImage(item
.GetImage());
928 if (mask
& wxLIST_MASK_STATE
)
929 listItem
.SetState(item
.GetState());
930 if (mask
& wxLIST_MASK_FORMAT
)
931 listItem
.SetAlign(item
.GetAlign());
932 if (mask
& wxLIST_MASK_WIDTH
)
933 listItem
.SetWidth(item
.GetWidth());
936 // change the appearance in the databrowser.
937 DataBrowserListViewHeaderDesc columnDesc
;
938 columnDesc
.version
=kDataBrowserListViewLatestHeaderDesc
;
939 verify_noerr( m_dbImpl
->GetHeaderDesc( kMinColumnId
+ col
, &columnDesc
) );
942 if (item.GetMask() & wxLIST_MASK_TEXT)
946 enc = m_font.GetEncoding();
948 enc = wxLocale::GetSystemEncoding();
949 wxMacCFStringHolder cfTitle;
950 cfTitle.Assign( item.GetText() , enc );
951 if(columnDesc.titleString)
952 CFRelease(columnDesc.titleString);
953 columnDesc.titleString = cfTitle;
957 if (item
.GetMask() & wxLIST_MASK_IMAGE
&& item
.GetImage() != -1 )
959 columnDesc
.btnContentInfo
.contentType
= kControlContentIconRef
;
960 wxImageList
* imageList
= GetImageList(wxIMAGE_LIST_SMALL
);
961 if (imageList
&& imageList
->GetImageCount() > 0 )
963 wxBitmap bmp
= imageList
->GetBitmap( item
.GetImage() );
964 IconRef icon
= bmp
.GetBitmapData()->GetIconRef();
965 columnDesc
.btnContentInfo
.u
.iconRef
= icon
;
969 verify_noerr( m_dbImpl
->SetHeaderDesc( kMinColumnId
+ col
, &columnDesc
) );
975 int wxListCtrl::GetColumnCount() const
978 return m_genericImpl
->GetColumnCount();
983 m_dbImpl
->GetColumnCount(&count
);
990 // Gets the column width
991 int wxListCtrl::GetColumnWidth(int col
) const
994 return m_genericImpl
->GetColumnWidth(col
);
998 return m_dbImpl
->GetColumnWidth(col
);
1004 // Sets the column width
1005 bool wxListCtrl::SetColumnWidth(int col
, int width
)
1008 return m_genericImpl
->SetColumnWidth(col
, width
);
1012 int mywidth
= width
;
1013 if (width
== wxLIST_AUTOSIZE
|| width
== wxLIST_AUTOSIZE_USEHEADER
)
1018 for (int column
= 0; column
< GetColumnCount(); column
++)
1021 GetColumn(col
, colInfo
);
1023 colInfo
.SetWidth(width
);
1024 SetColumn(col
, colInfo
);
1026 m_dbImpl
->SetColumnWidth(col
, mywidth
);
1032 GetColumn(col
, colInfo
);
1034 colInfo
.SetWidth(width
);
1035 SetColumn(col
, colInfo
);
1036 m_dbImpl
->SetColumnWidth(col
, mywidth
);
1044 // Gets the number of items that can fit vertically in the
1045 // visible area of the list control (list or report view)
1046 // or the total number of items in the list control (icon
1047 // or small icon view)
1048 int wxListCtrl::GetCountPerPage() const
1051 return m_genericImpl
->GetCountPerPage();
1060 // Gets the edit control for editing labels.
1061 wxTextCtrl
* wxListCtrl::GetEditControl() const
1064 return m_genericImpl
->GetEditControl();
1069 // Gets information about the item
1070 bool wxListCtrl::GetItem(wxListItem
& info
) const
1073 return m_genericImpl
->GetItem(info
);
1078 m_dbImpl
->MacGetColumnInfo(info
.m_itemId
, info
.m_col
, info
);
1081 info
.SetText( OnGetItemText(info
.m_itemId
, info
.m_col
) );
1082 info
.SetImage( OnGetItemColumnImage(info
.m_itemId
, info
.m_col
) );
1083 if (info
.GetMask() & wxLIST_MASK_STATE
)
1085 if (IsDataBrowserItemSelected( m_dbImpl
->GetControlRef(), info
.m_itemId
+1 ))
1086 info
.SetState(info
.GetState() | wxLIST_STATE_SELECTED
);
1089 wxListItemAttr
* attrs
= OnGetItemAttr( info
.m_itemId
);
1092 info
.SetFont( attrs
->GetFont() );
1093 info
.SetBackgroundColour( attrs
->GetBackgroundColour() );
1094 info
.SetTextColour( attrs
->GetTextColour() );
1098 bool success
= true;
1102 // Sets information about the item
1103 bool wxListCtrl::SetItem(wxListItem
& info
)
1106 return m_genericImpl
->SetItem(info
);
1109 m_dbImpl
->MacSetColumnInfo( info
.m_itemId
, info
.m_col
, &info
);
1114 long wxListCtrl::SetItem(long index
, int col
, const wxString
& label
, int imageId
)
1117 return m_genericImpl
->SetItem(index
, col
, label
, imageId
);
1120 info
.m_text
= label
;
1121 info
.m_mask
= wxLIST_MASK_TEXT
;
1122 info
.m_itemId
= index
;
1126 info
.m_image
= imageId
;
1127 info
.m_mask
|= wxLIST_MASK_IMAGE
;
1129 return SetItem(info
);
1133 // Gets the item state
1134 int wxListCtrl::GetItemState(long item
, long stateMask
) const
1137 return m_genericImpl
->GetItemState(item
, stateMask
);
1141 if ( HasFlag(wxLC_VIRTUAL
) )
1143 if (stateMask
== wxLIST_STATE_SELECTED
)
1145 if (IsDataBrowserItemSelected( m_dbImpl
->GetControlRef(), item
+1 ))
1146 return wxLIST_STATE_SELECTED
;
1155 info
.m_mask
= wxLIST_MASK_STATE
;
1156 info
.m_stateMask
= stateMask
;
1157 info
.m_itemId
= item
;
1162 return info
.m_state
;
1169 // Sets the item state
1170 bool wxListCtrl::SetItemState(long item
, long state
, long stateMask
)
1173 return m_genericImpl
->SetItemState(item
, state
, stateMask
);
1177 DataBrowserSetOption option
= kDataBrowserItemsAdd
;
1178 if ( stateMask
== wxLIST_STATE_SELECTED
&& state
== 0 )
1179 option
= kDataBrowserItemsRemove
;
1183 if ( HasFlag(wxLC_VIRTUAL
) )
1185 wxMacDataItemBrowserSelectionSuppressor
suppressor(m_dbImpl
);
1186 m_dbImpl
->SetSelectedAllItems(option
);
1190 for(int i
= 0; i
< GetItemCount();i
++)
1194 info
.m_mask
= wxLIST_MASK_STATE
;
1195 info
.m_stateMask
= stateMask
;
1196 info
.m_state
= state
;
1203 if ( HasFlag(wxLC_VIRTUAL
) )
1205 long itemID
= item
+1;
1206 SetDataBrowserSelectedItems(m_dbImpl
->GetControlRef(), 1, (DataBrowserItemID
*)&itemID
, option
);
1211 info
.m_itemId
= item
;
1212 info
.m_mask
= wxLIST_MASK_STATE
;
1213 info
.m_stateMask
= stateMask
;
1214 info
.m_state
= state
;
1215 return SetItem(info
);
1222 // Sets the item image
1223 bool wxListCtrl::SetItemImage(long item
, int image
, int WXUNUSED(selImage
))
1225 return SetItemColumnImage(item
, 0, image
);
1228 // Sets the item image
1229 bool wxListCtrl::SetItemColumnImage(long item
, long column
, int image
)
1232 return m_genericImpl
->SetItemColumnImage(item
, column
, image
);
1236 info
.m_mask
= wxLIST_MASK_IMAGE
;
1237 info
.m_image
= image
;
1238 info
.m_itemId
= item
;
1239 info
.m_col
= column
;
1241 return SetItem(info
);
1244 // Gets the item text
1245 wxString
wxListCtrl::GetItemText(long item
) const
1248 return m_genericImpl
->GetItemText(item
);
1252 info
.m_mask
= wxLIST_MASK_TEXT
;
1253 info
.m_itemId
= item
;
1256 return wxEmptyString
;
1260 // Sets the item text
1261 void wxListCtrl::SetItemText(long item
, const wxString
& str
)
1264 return m_genericImpl
->SetItemText(item
, str
);
1268 info
.m_mask
= wxLIST_MASK_TEXT
;
1269 info
.m_itemId
= item
;
1275 // Gets the item data
1276 long wxListCtrl::GetItemData(long item
) const
1279 return m_genericImpl
->GetItemData(item
);
1283 info
.m_mask
= wxLIST_MASK_DATA
;
1284 info
.m_itemId
= item
;
1291 // Sets the item data
1292 bool wxListCtrl::SetItemData(long item
, long data
)
1295 return m_genericImpl
->SetItemData(item
, data
);
1299 info
.m_mask
= wxLIST_MASK_DATA
;
1300 info
.m_itemId
= item
;
1303 return SetItem(info
);
1306 wxRect
wxListCtrl::GetViewRect() const
1308 wxASSERT_MSG( !HasFlag(wxLC_REPORT
| wxLC_LIST
),
1309 _T("wxListCtrl::GetViewRect() only works in icon mode") );
1312 return m_genericImpl
->GetViewRect();
1318 // Gets the item rectangle
1319 bool wxListCtrl::GetItemRect(long item
, wxRect
& rect
, int code
) const
1322 return m_genericImpl
->GetItemRect(item
, rect
, code
);
1327 DataBrowserItemID id
;
1328 DataBrowserPropertyID col
= kMinColumnId
;
1330 DataBrowserPropertyPart part
= kDataBrowserPropertyEnclosingPart
;
1331 if ( code
== wxLIST_RECT_LABEL
)
1332 part
= kDataBrowserPropertyTextPart
;
1333 else if ( code
== wxLIST_RECT_ICON
)
1334 part
= kDataBrowserPropertyIconPart
;
1336 if ( !(GetWindowStyleFlag() & wxLC_VIRTUAL
) )
1338 wxMacDataItem
* thisItem
= m_dbImpl
->GetItemFromLine(item
);
1339 id
= (DataBrowserItemID
) thisItem
;
1344 GetDataBrowserItemPartBounds( m_dbImpl
->GetControlRef(), id
, col
, part
, &bounds
);
1346 rect
.x
= bounds
.left
;
1347 rect
.y
= bounds
.top
;
1348 rect
.width
= bounds
.right
- bounds
.left
; //GetClientSize().x; // we need the width of the whole row, not just the item.
1349 rect
.height
= bounds
.bottom
- bounds
.top
;
1350 //fprintf("id = %d, bounds = %d, %d, %d, %d\n", id, rect.x, rect.y, rect.width, rect.height);
1355 // Gets the item position
1356 bool wxListCtrl::GetItemPosition(long item
, wxPoint
& pos
) const
1359 return m_genericImpl
->GetItemPosition(item
, pos
);
1361 bool success
= false;
1366 GetItemRect(item
, itemRect
);
1367 pos
= itemRect
.GetPosition();
1374 // Sets the item position.
1375 bool wxListCtrl::SetItemPosition(long item
, const wxPoint
& pos
)
1378 return m_genericImpl
->SetItemPosition(item
, pos
);
1383 // Gets the number of items in the list control
1384 int wxListCtrl::GetItemCount() const
1387 return m_genericImpl
->GetItemCount();
1390 return m_dbImpl
->MacGetCount();
1395 void wxListCtrl::SetItemSpacing( int spacing
, bool isSmall
)
1398 m_genericImpl
->SetItemSpacing(spacing
, isSmall
);
1401 wxSize
wxListCtrl::GetItemSpacing() const
1404 return m_genericImpl
->GetItemSpacing();
1406 return wxSize(0, 0);
1409 void wxListCtrl::SetItemTextColour( long item
, const wxColour
&col
)
1413 m_genericImpl
->SetItemTextColour(item
, col
);
1418 info
.m_itemId
= item
;
1419 info
.SetTextColour( col
);
1423 wxColour
wxListCtrl::GetItemTextColour( long item
) const
1426 return m_genericImpl
->GetItemTextColour(item
);
1432 return info
.GetTextColour();
1434 return wxNullColour
;
1437 void wxListCtrl::SetItemBackgroundColour( long item
, const wxColour
&col
)
1441 m_genericImpl
->SetItemBackgroundColour(item
, col
);
1446 info
.m_itemId
= item
;
1447 info
.SetBackgroundColour( col
);
1451 wxColour
wxListCtrl::GetItemBackgroundColour( long item
) const
1454 return m_genericImpl
->GetItemBackgroundColour(item
);
1460 return info
.GetBackgroundColour();
1462 return wxNullColour
;
1465 void wxListCtrl::SetItemFont( long item
, const wxFont
&f
)
1469 m_genericImpl
->SetItemFont(item
, f
);
1474 info
.m_itemId
= item
;
1479 wxFont
wxListCtrl::GetItemFont( long item
) const
1482 return m_genericImpl
->GetItemFont(item
);
1488 return info
.GetFont();
1494 // Gets the number of selected items in the list control
1495 int wxListCtrl::GetSelectedItemCount() const
1498 return m_genericImpl
->GetSelectedItemCount();
1501 return m_dbImpl
->GetSelectedItemCount(NULL
, true);
1506 // Gets the text colour of the listview
1507 wxColour
wxListCtrl::GetTextColour() const
1510 return m_genericImpl
->GetTextColour();
1512 // TODO: we need owner drawn list items to customize text color.
1516 return wxNullColour
;
1519 // Sets the text colour of the listview
1520 void wxListCtrl::SetTextColour(const wxColour
& col
)
1524 m_genericImpl
->SetTextColour(col
);
1532 // Gets the index of the topmost visible item when in
1533 // list or report view
1534 long wxListCtrl::GetTopItem() const
1537 return m_genericImpl
->GetTopItem();
1542 long item
= HitTest( wxPoint(1, 1), flags
);
1543 if (flags
== wxLIST_HITTEST_ONITEM
)
1550 // Searches for an item, starting from 'item'.
1551 // 'geometry' is one of
1552 // wxLIST_NEXT_ABOVE/ALL/BELOW/LEFT/RIGHT.
1553 // 'state' is a state bit flag, one or more of
1554 // wxLIST_STATE_DROPHILITED/FOCUSED/SELECTED/CUT.
1555 // item can be -1 to find the first item that matches the
1557 // Returns the item or -1 if unsuccessful.
1558 long wxListCtrl::GetNextItem(long item
, int geom
, int state
) const
1561 return m_genericImpl
->GetNextItem(item
, geom
, state
);
1563 // TODO: implement all geometry and state options?
1566 if ( geom
== wxLIST_NEXT_ALL
|| geom
== wxLIST_NEXT_BELOW
)
1568 long count
= m_dbImpl
->MacGetCount() ;
1569 for ( long line
= item
+ 1 ; line
< count
; line
++ )
1571 wxMacDataItem
* id
= m_dbImpl
->GetItemFromLine(line
);
1573 if ( (state
== wxLIST_STATE_DONTCARE
) )
1576 if ( (state
& wxLIST_STATE_SELECTED
) && m_dbImpl
->IsItemSelected( id
) )
1580 else if ( geom
== wxLIST_NEXT_ABOVE
)
1584 item2
= m_dbImpl
->MacGetCount();
1586 for ( long line
= item2
- 1 ; line
>= 0; line
-- )
1588 wxMacDataItem
* id
= m_dbImpl
->GetItemFromLine(line
);
1590 if ( (state
== wxLIST_STATE_DONTCARE
) )
1593 if ( (state
& wxLIST_STATE_SELECTED
) && m_dbImpl
->IsItemSelected( id
) )
1603 wxImageList
*wxListCtrl::GetImageList(int which
) const
1606 return m_genericImpl
->GetImageList(which
);
1608 if ( which
== wxIMAGE_LIST_NORMAL
)
1610 return m_imageListNormal
;
1612 else if ( which
== wxIMAGE_LIST_SMALL
)
1614 return m_imageListSmall
;
1616 else if ( which
== wxIMAGE_LIST_STATE
)
1618 return m_imageListState
;
1623 void wxListCtrl::SetImageList(wxImageList
*imageList
, int which
)
1627 m_genericImpl
->SetImageList(imageList
, which
);
1631 if ( which
== wxIMAGE_LIST_NORMAL
)
1633 if (m_ownsImageListNormal
) delete m_imageListNormal
;
1634 m_imageListNormal
= imageList
;
1635 m_ownsImageListNormal
= false;
1637 else if ( which
== wxIMAGE_LIST_SMALL
)
1639 if (m_ownsImageListSmall
) delete m_imageListSmall
;
1640 m_imageListSmall
= imageList
;
1641 m_ownsImageListSmall
= false;
1643 else if ( which
== wxIMAGE_LIST_STATE
)
1645 if (m_ownsImageListState
) delete m_imageListState
;
1646 m_imageListState
= imageList
;
1647 m_ownsImageListState
= false;
1651 void wxListCtrl::AssignImageList(wxImageList
*imageList
, int which
)
1655 m_genericImpl
->AssignImageList(imageList
, which
);
1659 SetImageList(imageList
, which
);
1660 if ( which
== wxIMAGE_LIST_NORMAL
)
1661 m_ownsImageListNormal
= true;
1662 else if ( which
== wxIMAGE_LIST_SMALL
)
1663 m_ownsImageListSmall
= true;
1664 else if ( which
== wxIMAGE_LIST_STATE
)
1665 m_ownsImageListState
= true;
1668 // ----------------------------------------------------------------------------
1670 // ----------------------------------------------------------------------------
1672 // Arranges the items
1673 bool wxListCtrl::Arrange(int flag
)
1676 return m_genericImpl
->Arrange(flag
);
1681 bool wxListCtrl::DeleteItem(long item
)
1684 return m_genericImpl
->DeleteItem(item
);
1688 m_dbImpl
->MacDelete(item
);
1689 wxListEvent
event( wxEVT_COMMAND_LIST_DELETE_ITEM
, GetId() );
1690 event
.SetEventObject( this );
1691 event
.m_itemIndex
= item
;
1692 GetEventHandler()->ProcessEvent( event
);
1698 // Deletes all items
1699 bool wxListCtrl::DeleteAllItems()
1702 return m_genericImpl
->DeleteAllItems();
1706 m_dbImpl
->MacClear();
1707 wxListEvent
event( wxEVT_COMMAND_LIST_DELETE_ALL_ITEMS
, GetId() );
1708 event
.SetEventObject( this );
1709 GetEventHandler()->ProcessEvent( event
);
1714 // Deletes all items
1715 bool wxListCtrl::DeleteAllColumns()
1718 return m_genericImpl
->DeleteAllColumns();
1723 m_dbImpl
->GetColumnCount(&cols
);
1724 for (UInt32 col
= 0; col
< cols
; col
++)
1734 bool wxListCtrl::DeleteColumn(int col
)
1737 return m_genericImpl
->DeleteColumn(col
);
1741 OSStatus err
= m_dbImpl
->RemoveColumn(col
);
1742 return err
== noErr
;
1748 // Clears items, and columns if there are any.
1749 void wxListCtrl::ClearAll()
1753 m_genericImpl
->ClearAll();
1764 wxTextCtrl
* wxListCtrl::EditLabel(long item
, wxClassInfo
* textControlClass
)
1767 return m_genericImpl
->EditLabel(item
, textControlClass
);
1771 wxCHECK_MSG( (item
>= 0) && ((long)item
< GetItemCount()), NULL
,
1772 wxT("wrong index in wxListCtrl::EditLabel()") );
1774 wxASSERT_MSG( textControlClass
->IsKindOf(CLASSINFO(wxTextCtrl
)),
1775 wxT("EditLabel() needs a text control") );
1777 wxListEvent
le( wxEVT_COMMAND_LIST_BEGIN_LABEL_EDIT
, GetParent()->GetId() );
1778 le
.SetEventObject( this );
1779 le
.m_itemIndex
= item
;
1781 GetItem( le
.m_item
);
1783 if ( GetParent()->GetEventHandler()->ProcessEvent( le
) && !le
.IsAllowed() )
1785 // vetoed by user code
1789 wxTextCtrl
* const text
= (wxTextCtrl
*)textControlClass
->CreateObject();
1790 m_textctrlWrapper
= new wxListCtrlTextCtrlWrapper(this, text
, item
);
1791 return m_textctrlWrapper
->GetText();
1796 // End label editing, optionally cancelling the edit
1797 bool wxListCtrl::EndEditLabel(bool cancel
)
1799 // TODO: generic impl. doesn't have this method - is it needed for us?
1801 return true; // m_genericImpl->EndEditLabel(cancel);
1804 verify_noerr( SetDataBrowserEditItem(m_dbImpl
->GetControlRef(), kDataBrowserNoItem
, kMinColumnId
) );
1808 // Ensures this item is visible
1809 bool wxListCtrl::EnsureVisible(long item
)
1812 return m_genericImpl
->EnsureVisible(item
);
1816 wxMacDataItem
* dataItem
= m_dbImpl
->GetItemFromLine(item
);
1817 m_dbImpl
->RevealItem(dataItem
, kDataBrowserRevealWithoutSelecting
);
1823 // Find an item whose label matches this string, starting from the item after 'start'
1824 // or the beginning if 'start' is -1.
1825 long wxListCtrl::FindItem(long start
, const wxString
& str
, bool partial
)
1828 return m_genericImpl
->FindItem(start
, str
, partial
);
1830 wxString str_upper
= str
.Upper();
1835 long count
= GetItemCount();
1839 wxString line_upper
= GetItemText(idx
).Upper();
1842 if (line_upper
== str_upper
)
1847 if (line_upper
.find(str_upper
) == 0)
1857 // Find an item whose data matches this data, starting from the item after 'start'
1858 // or the beginning if 'start' is -1.
1859 long wxListCtrl::FindItem(long start
, long data
)
1862 return m_genericImpl
->FindItem(start
, data
);
1867 long count
= GetItemCount();
1871 if (GetItemData(idx
) == data
)
1879 // Find an item nearest this position in the specified direction, starting from
1880 // the item after 'start' or the beginning if 'start' is -1.
1881 long wxListCtrl::FindItem(long start
, const wxPoint
& pt
, int direction
)
1884 return m_genericImpl
->FindItem(start
, pt
, direction
);
1888 // Determines which item (if any) is at the specified point,
1889 // giving details in 'flags' (see wxLIST_HITTEST_... flags above)
1891 wxListCtrl::HitTest(const wxPoint
& point
, int& flags
, long *ptrSubItem
) const
1894 return m_genericImpl
->HitTest(point
, flags
, ptrSubItem
);
1896 flags
= wxLIST_HITTEST_NOWHERE
;
1899 int colHeaderHeight
= 22; // TODO: Find a way to get this value from the db control?
1900 UInt16 rowHeight
= 0;
1901 m_dbImpl
->GetDefaultRowHeight(&rowHeight
);
1904 // get the actual row by taking scroll position into account
1905 UInt32 offsetX
, offsetY
;
1906 m_dbImpl
->GetScrollPosition( &offsetY
, &offsetX
);
1909 if ( !(GetWindowStyleFlag() & wxLC_NO_HEADER
) )
1910 y
-= colHeaderHeight
;
1915 int row
= y
/ rowHeight
;
1916 DataBrowserItemID id
;
1917 m_dbImpl
->GetItemID( (DataBrowserTableViewRowIndex
) row
, &id
);
1919 // TODO: Use GetDataBrowserItemPartBounds to return if we are in icon or label
1920 if ( !(GetWindowStyleFlag() & wxLC_VIRTUAL
) )
1922 wxMacListCtrlItem
* lcItem
;
1923 lcItem
= (wxMacListCtrlItem
*) id
;
1926 flags
= wxLIST_HITTEST_ONITEM
;
1932 if (row
< GetItemCount() )
1934 flags
= wxLIST_HITTEST_ONITEM
;
1943 int wxListCtrl::GetScrollPos(int orient
) const
1946 return m_genericImpl
->GetScrollPos(orient
);
1950 UInt32 offsetX
, offsetY
;
1951 m_dbImpl
->GetScrollPosition( &offsetY
, &offsetX
);
1952 if ( orient
== wxHORIZONTAL
)
1961 // Inserts an item, returning the index of the new item if successful,
1963 long wxListCtrl::InsertItem(wxListItem
& info
)
1965 wxASSERT_MSG( !IsVirtual(), _T("can't be used with virtual controls") );
1968 return m_genericImpl
->InsertItem(info
);
1970 if (m_dbImpl
&& !IsVirtual())
1972 int count
= GetItemCount();
1974 if (info
.m_itemId
> count
)
1975 info
.m_itemId
= count
;
1977 m_dbImpl
->MacInsertItem(info
.m_itemId
, &info
);
1979 wxListEvent
event( wxEVT_COMMAND_LIST_INSERT_ITEM
, GetId() );
1980 event
.SetEventObject( this );
1981 event
.m_itemIndex
= info
.m_itemId
;
1982 GetEventHandler()->ProcessEvent( event
);
1983 return info
.m_itemId
;
1988 long wxListCtrl::InsertItem(long index
, const wxString
& label
)
1991 return m_genericImpl
->InsertItem(index
, label
);
1994 info
.m_text
= label
;
1995 info
.m_mask
= wxLIST_MASK_TEXT
;
1996 info
.m_itemId
= index
;
1997 return InsertItem(info
);
2000 // Inserts an image item
2001 long wxListCtrl::InsertItem(long index
, int imageIndex
)
2004 return m_genericImpl
->InsertItem(index
, imageIndex
);
2007 info
.m_image
= imageIndex
;
2008 info
.m_mask
= wxLIST_MASK_IMAGE
;
2009 info
.m_itemId
= index
;
2010 return InsertItem(info
);
2013 // Inserts an image/string item
2014 long wxListCtrl::InsertItem(long index
, const wxString
& label
, int imageIndex
)
2017 return m_genericImpl
->InsertItem(index
, label
, imageIndex
);
2020 info
.m_image
= imageIndex
;
2021 info
.m_text
= label
;
2022 info
.m_mask
= wxLIST_MASK_IMAGE
| wxLIST_MASK_TEXT
;
2023 info
.m_itemId
= index
;
2024 return InsertItem(info
);
2027 // For list view mode (only), inserts a column.
2028 long wxListCtrl::InsertColumn(long col
, wxListItem
& item
)
2031 return m_genericImpl
->InsertColumn(col
, item
);
2035 int width
= item
.GetWidth();
2036 if ( !(item
.GetMask() & wxLIST_MASK_WIDTH
) )
2039 DataBrowserPropertyType type
= kDataBrowserCustomType
; //kDataBrowserTextType;
2040 wxImageList
* imageList
= GetImageList(wxIMAGE_LIST_SMALL
);
2041 if (imageList
&& imageList
->GetImageCount() > 0)
2043 wxBitmap bmp
= imageList
->GetBitmap(0);
2045 // type = kDataBrowserIconAndTextType;
2048 SInt16 just
= teFlushDefault
;
2049 if (item
.GetMask() & wxLIST_MASK_FORMAT
)
2051 if (item
.GetAlign() == wxLIST_FORMAT_LEFT
)
2053 else if (item
.GetAlign() == wxLIST_FORMAT_CENTER
)
2055 else if (item
.GetAlign() == wxLIST_FORMAT_RIGHT
)
2056 just
= teFlushRight
;
2058 m_dbImpl
->InsertColumn(col
, type
, item
.GetText(), just
, width
);
2059 SetColumn(col
, item
);
2061 // set/remove options based on the wxListCtrl type.
2062 DataBrowserTableViewColumnID id
;
2063 m_dbImpl
->GetColumnIDFromIndex(col
, &id
);
2064 DataBrowserPropertyFlags flags
;
2065 verify_noerr(m_dbImpl
->GetPropertyFlags(id
, &flags
));
2066 if (GetWindowStyleFlag() & wxLC_EDIT_LABELS
)
2067 flags
|= kDataBrowserPropertyIsEditable
;
2069 if (GetWindowStyleFlag() & wxLC_VIRTUAL
){
2070 flags
&= ~kDataBrowserListViewSortableColumn
;
2072 verify_noerr(m_dbImpl
->SetPropertyFlags(id
, flags
));
2078 long wxListCtrl::InsertColumn(long col
,
2079 const wxString
& heading
,
2084 return m_genericImpl
->InsertColumn(col
, heading
, format
, width
);
2087 item
.m_mask
= wxLIST_MASK_TEXT
| wxLIST_MASK_FORMAT
;
2088 item
.m_text
= heading
;
2091 item
.m_mask
|= wxLIST_MASK_WIDTH
;
2092 item
.m_width
= width
;
2094 item
.m_format
= format
;
2096 return InsertColumn(col
, item
);
2099 // scroll the control by the given number of pixels (exception: in list view,
2100 // dx is interpreted as number of columns)
2101 bool wxListCtrl::ScrollList(int dx
, int dy
)
2104 return m_genericImpl
->ScrollList(dx
, dy
);
2108 m_dbImpl
->SetScrollPosition(dx
, dy
);
2114 bool wxListCtrl::SortItems(wxListCtrlCompare fn
, long data
)
2117 return m_genericImpl
->SortItems(fn
, data
);
2122 m_compareFuncData
= data
;
2123 SortDataBrowserContainer( m_dbImpl
->GetControlRef(), kDataBrowserNoItem
, true);
2125 // we need to do this after each call, else we get a crash from wxPython when
2126 // SortItems is called the second time.
2127 m_compareFunc
= NULL
;
2128 m_compareFuncData
= 0;
2134 void wxListCtrl::OnRenameTimer()
2136 wxCHECK_RET( HasCurrent(), wxT("unexpected rename timer") );
2138 EditLabel( m_current
);
2141 bool wxListCtrl::OnRenameAccept(long itemEdit
, const wxString
& value
)
2143 wxListEvent
le( wxEVT_COMMAND_LIST_END_LABEL_EDIT
, GetId() );
2144 le
.SetEventObject( this );
2145 le
.m_itemIndex
= itemEdit
;
2147 GetItem( le
.m_item
);
2148 le
.m_item
.m_text
= value
;
2149 return !GetEventHandler()->ProcessEvent( le
) ||
2153 void wxListCtrl::OnRenameCancelled(long itemEdit
)
2155 // let owner know that the edit was cancelled
2156 wxListEvent
le( wxEVT_COMMAND_LIST_END_LABEL_EDIT
, GetParent()->GetId() );
2158 le
.SetEditCanceled(true);
2160 le
.SetEventObject( this );
2161 le
.m_itemIndex
= itemEdit
;
2163 GetItem( le
.m_item
);
2164 GetEventHandler()->ProcessEvent( le
);
2167 // ----------------------------------------------------------------------------
2168 // virtual list controls
2169 // ----------------------------------------------------------------------------
2171 wxString
wxListCtrl::OnGetItemText(long WXUNUSED(item
), long WXUNUSED(col
)) const
2173 // this is a pure virtual function, in fact - which is not really pure
2174 // because the controls which are not virtual don't need to implement it
2175 wxFAIL_MSG( _T("wxListCtrl::OnGetItemText not supposed to be called") );
2177 return wxEmptyString
;
2180 int wxListCtrl::OnGetItemImage(long WXUNUSED(item
)) const
2182 wxCHECK_MSG(!GetImageList(wxIMAGE_LIST_SMALL
),
2184 wxT("List control has an image list, OnGetItemImage or OnGetItemColumnImage should be overridden."));
2188 int wxListCtrl::OnGetItemColumnImage(long item
, long column
) const
2191 return OnGetItemImage(item
);
2196 wxListItemAttr
*wxListCtrl::OnGetItemAttr(long WXUNUSED_UNLESS_DEBUG(item
)) const
2198 wxASSERT_MSG( item
>= 0 && item
< GetItemCount(),
2199 _T("invalid item index in OnGetItemAttr()") );
2201 // no attributes by default
2205 void wxListCtrl::SetItemCount(long count
)
2207 wxASSERT_MSG( IsVirtual(), _T("this is for virtual controls only") );
2211 m_genericImpl
->SetItemCount(count
);
2217 // we need to temporarily disable the new item creation notification
2218 // procedure to speed things up
2219 // FIXME: Even this doesn't seem to help much...
2221 // FIXME: Find a more efficient way to do this.
2222 m_dbImpl
->MacClear();
2224 DataBrowserCallbacks callbacks
;
2225 DataBrowserItemNotificationUPP itemUPP
;
2226 GetDataBrowserCallbacks(m_dbImpl
->GetControlRef(), &callbacks
);
2227 itemUPP
= callbacks
.u
.v1
.itemNotificationCallback
;
2228 callbacks
.u
.v1
.itemNotificationCallback
= 0;
2229 m_dbImpl
->SetCallbacks(&callbacks
);
2230 ::AddDataBrowserItems(m_dbImpl
->GetControlRef(), kDataBrowserNoItem
,
2231 count
, NULL
, kDataBrowserItemNoProperty
);
2232 callbacks
.u
.v1
.itemNotificationCallback
= itemUPP
;
2233 m_dbImpl
->SetCallbacks(&callbacks
);
2238 void wxListCtrl::RefreshItem(long item
)
2242 m_genericImpl
->RefreshItem(item
);
2247 GetItemRect(item
, rect
);
2251 void wxListCtrl::RefreshItems(long itemFrom
, long itemTo
)
2255 m_genericImpl
->RefreshItems(itemFrom
, itemTo
);
2259 wxRect rect1
, rect2
;
2260 GetItemRect(itemFrom
, rect1
);
2261 GetItemRect(itemTo
, rect2
);
2263 wxRect rect
= rect1
;
2264 rect
.height
= rect2
.GetBottom() - rect1
.GetTop();
2269 void wxListCtrl::SetDropTarget( wxDropTarget
*dropTarget
)
2271 #if wxUSE_DRAG_AND_DROP
2273 m_genericImpl
->SetDropTarget( dropTarget
);
2276 wxWindow::SetDropTarget( dropTarget
);
2280 wxDropTarget
*wxListCtrl::GetDropTarget() const
2282 #if wxUSE_DRAG_AND_DROP
2284 return m_genericImpl
->GetDropTarget();
2287 return wxWindow::GetDropTarget();
2292 #if wxABI_VERSION >= 20801
2293 void wxListCtrl::SetFocus()
2297 m_genericImpl
->SetFocus();
2301 wxWindow::SetFocus();
2305 // wxMac internal data structures
2307 wxMacListCtrlItem::~wxMacListCtrlItem()
2311 void wxMacListCtrlItem::Notification(wxMacDataItemBrowserControl
*owner
,
2312 DataBrowserItemNotification message
,
2313 DataBrowserItemDataRef itemData
) const
2316 wxMacDataBrowserListCtrlControl
*lb
= wxDynamicCast(owner
, wxMacDataBrowserListCtrlControl
);
2318 // we want to depend on as little as possible to make sure tear-down of controls is safe
2319 if ( message
== kDataBrowserItemRemoved
)
2321 if ( lb
!= NULL
&& lb
->GetClientDataType() == wxClientData_Object
)
2323 delete (wxClientData
*) (m_data
);
2329 else if ( message
== kDataBrowserItemAdded
)
2331 // we don't issue events on adding, the item is not really stored in the list yet, so we
2332 // avoid asserts by gettting out now
2336 wxListCtrl
*list
= wxDynamicCast( owner
->GetPeer() , wxListCtrl
);
2339 bool trigger
= false;
2341 wxListEvent
event( wxEVT_COMMAND_LIST_ITEM_SELECTED
, list
->GetId() );
2342 bool isSingle
= (list
->GetWindowStyle() & wxLC_SINGLE_SEL
) != 0;
2344 event
.SetEventObject( list
);
2345 event
.m_itemIndex
= owner
->GetLineFromItem( this ) ;
2346 if ( !list
->IsVirtual() )
2348 lb
->MacGetColumnInfo(event
.m_itemIndex
,0,event
.m_item
);
2353 case kDataBrowserItemDeselected
:
2354 event
.SetEventType(wxEVT_COMMAND_LIST_ITEM_DESELECTED
);
2356 trigger
= !lb
->IsSelectionSuppressed();
2359 case kDataBrowserItemSelected
:
2360 trigger
= !lb
->IsSelectionSuppressed();
2363 case kDataBrowserItemDoubleClicked
:
2364 event
.SetEventType( wxEVT_COMMAND_LIST_ITEM_ACTIVATED
);
2368 case kDataBrowserEditStarted
:
2369 // TODO : how to veto ?
2370 event
.SetEventType( wxEVT_COMMAND_LIST_BEGIN_LABEL_EDIT
) ;
2374 case kDataBrowserEditStopped
:
2375 // TODO probably trigger only upon the value store callback, because
2376 // here IIRC we cannot veto
2377 event
.SetEventType( wxEVT_COMMAND_LIST_END_LABEL_EDIT
) ;
2387 // direct notification is not always having the listbox GetSelection() having in synch with event
2388 wxPostEvent( list
->GetEventHandler(), event
);
2394 IMPLEMENT_DYNAMIC_CLASS(wxMacDataBrowserListCtrlControl
, wxMacDataItemBrowserControl
)
2396 wxMacDataBrowserListCtrlControl::wxMacDataBrowserListCtrlControl( wxWindow
*peer
, const wxPoint
& pos
, const wxSize
& size
, long style
)
2397 : wxMacDataItemBrowserControl( peer
, pos
, size
, style
)
2399 OSStatus err
= noErr
;
2400 m_clientDataItemsType
= wxClientData_None
;
2401 m_isVirtual
= false;
2404 if ( style
& wxLC_VIRTUAL
)
2407 DataBrowserSelectionFlags options
= kDataBrowserDragSelect
;
2408 if ( style
& wxLC_SINGLE_SEL
)
2410 options
|= kDataBrowserSelectOnlyOne
;
2414 options
|= kDataBrowserCmdTogglesSelection
;
2417 err
= SetSelectionFlags( options
);
2418 verify_noerr( err
);
2420 DataBrowserCustomCallbacks callbacks
;
2421 InitializeDataBrowserCustomCallbacks( &callbacks
, kDataBrowserLatestCustomCallbacks
);
2423 if ( gDataBrowserDrawItemUPP
== NULL
)
2424 gDataBrowserDrawItemUPP
= NewDataBrowserDrawItemUPP(DataBrowserDrawItemProc
);
2426 if ( gDataBrowserHitTestUPP
== NULL
)
2427 gDataBrowserHitTestUPP
= NewDataBrowserHitTestUPP(DataBrowserHitTestProc
);
2429 callbacks
.u
.v1
.drawItemCallback
= gDataBrowserDrawItemUPP
;
2430 callbacks
.u
.v1
.hitTestCallback
= gDataBrowserHitTestUPP
;
2432 SetDataBrowserCustomCallbacks( GetControlRef(), &callbacks
);
2434 if ( style
& wxLC_LIST
)
2436 InsertColumn(0, kDataBrowserIconAndTextType
, wxEmptyString
, -1, -1);
2437 verify_noerr( AutoSizeColumns() );
2440 if ( style
& wxLC_LIST
|| style
& wxLC_NO_HEADER
)
2441 verify_noerr( SetHeaderButtonHeight( 0 ) );
2444 SetSortProperty( kMinColumnId
- 1 );
2446 SetSortProperty( kMinColumnId
);
2448 m_sortOrder
= SortOrder_None
;
2450 if ( style
& wxLC_SORT_DESCENDING
)
2452 SetSortOrder( kDataBrowserOrderDecreasing
);
2454 else if ( style
& wxLC_SORT_ASCENDING
)
2456 SetSortOrder( kDataBrowserOrderIncreasing
);
2459 if ( style
& wxLC_VRULES
)
2461 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4
2462 verify_noerr( DataBrowserChangeAttributes(m_controlRef
, kDataBrowserAttributeListViewDrawColumnDividers
, kDataBrowserAttributeNone
) );
2466 verify_noerr( SetHiliteStyle(kDataBrowserTableViewFillHilite
) );
2467 verify_noerr( SetHasScrollBars( (style
& wxHSCROLL
) != 0 , true ) );
2470 pascal Boolean
wxMacDataBrowserListCtrlControl::DataBrowserEditTextProc(
2472 DataBrowserItemID itemID
,
2473 DataBrowserPropertyID property
,
2474 CFStringRef theString
,
2475 Rect
*maxEditTextRect
,
2476 Boolean
*shrinkToFit
)
2478 Boolean result
= false;
2479 wxMacDataBrowserListCtrlControl
* ctl
= wxDynamicCast(wxMacControl::GetReferenceFromNativeControl( browser
), wxMacDataBrowserListCtrlControl
);
2482 result
= ctl
->ConfirmEditText(itemID
, property
, theString
, maxEditTextRect
, shrinkToFit
);
2483 theString
= CFSTR("Hello!");
2488 bool wxMacDataBrowserListCtrlControl::ConfirmEditText(
2489 DataBrowserItemID itemID
,
2490 DataBrowserPropertyID property
,
2491 CFStringRef theString
,
2492 Rect
*maxEditTextRect
,
2493 Boolean
*shrinkToFit
)
2498 pascal void wxMacDataBrowserListCtrlControl::DataBrowserDrawItemProc(
2500 DataBrowserItemID itemID
,
2501 DataBrowserPropertyID property
,
2502 DataBrowserItemState itemState
,
2503 const Rect
*itemRect
,
2505 Boolean colorDevice
)
2507 wxMacDataBrowserListCtrlControl
* ctl
= wxDynamicCast(wxMacControl::GetReferenceFromNativeControl( browser
), wxMacDataBrowserListCtrlControl
);
2510 ctl
->DrawItem(itemID
, property
, itemState
, itemRect
, gdDepth
, colorDevice
);
2514 // routines needed for DrawItem
2519 kTextBoxHeight
= 14,
2520 kIconTextSpacingV
= 2,
2522 kContentHeight
= kIconHeight
+ kTextBoxHeight
+ kIconTextSpacingV
2525 static void calculateCGDrawingBounds(CGRect inItemRect
, CGRect
*outIconRect
, CGRect
*outTextRect
, bool hasIcon
= false)
2528 float iconH
, iconW
= 0;
2529 float padding
= kItemPadding
;
2532 iconH
= kIconHeight
;
2534 padding
= padding
*2;
2537 textBottom
= inItemRect
.origin
.y
;
2539 *outIconRect
= CGRectMake(inItemRect
.origin
.x
+ kItemPadding
,
2540 textBottom
+ kIconTextSpacingV
, kIconWidth
,
2543 *outTextRect
= CGRectMake(inItemRect
.origin
.x
+ padding
+ iconW
,
2544 textBottom
+ kIconTextSpacingV
, inItemRect
.size
.width
- padding
- iconW
,
2545 inItemRect
.size
.height
- kIconTextSpacingV
);
2548 void wxMacDataBrowserListCtrlControl::DrawItem(
2549 DataBrowserItemID itemID
,
2550 DataBrowserPropertyID property
,
2551 DataBrowserItemState itemState
,
2552 const Rect
*itemRect
,
2554 Boolean colorDevice
)
2557 wxFont font
= wxNullFont
;
2559 short listColumn
= property
- kMinColumnId
;
2561 wxListCtrl
* list
= wxDynamicCast( GetPeer() , wxListCtrl
);
2562 wxMacListCtrlItem
* lcItem
;
2563 wxColour color
= *wxBLACK
;
2564 wxColour bgColor
= wxNullColour
;
2566 if (listColumn
>= 0)
2570 lcItem
= (wxMacListCtrlItem
*) itemID
;
2571 if (lcItem
->HasColumnInfo(listColumn
)){
2572 wxListItem
* item
= lcItem
->GetColumnInfo(listColumn
);
2574 // we always use the 0 column to get font and text/background colors.
2575 if (lcItem
->HasColumnInfo(0))
2577 wxListItem
* firstItem
= lcItem
->GetColumnInfo(0);
2578 color
= firstItem
->GetTextColour();
2579 bgColor
= firstItem
->GetBackgroundColour();
2580 font
= firstItem
->GetFont();
2583 if (item
->GetMask() & wxLIST_MASK_TEXT
)
2584 text
= item
->GetText();
2585 if (item
->GetMask() & wxLIST_MASK_IMAGE
)
2586 imgIndex
= item
->GetImage();
2592 text
= list
->OnGetItemText( (long)itemID
-1, listColumn
);
2593 imgIndex
= list
->OnGetItemColumnImage( (long)itemID
-1, listColumn
);
2594 wxListItemAttr
* attrs
= list
->OnGetItemAttr( (long)itemID
-1 );
2597 if (attrs
->HasBackgroundColour())
2598 bgColor
= attrs
->GetBackgroundColour();
2599 if (attrs
->HasTextColour())
2600 color
= attrs
->GetTextColour();
2601 if (attrs
->HasFont())
2602 font
= attrs
->GetFont();
2607 wxColour listBgColor
= list
->GetBackgroundColour();
2608 if (bgColor
== wxNullColour
)
2609 bgColor
= listBgColor
;
2611 wxFont listFont
= list
->GetFont();
2612 if (font
== wxNullFont
)
2615 wxMacCFStringHolder cfString
;
2616 cfString
.Assign( text
, wxLocale::GetSystemEncoding() );
2619 CGRect enclosingCGRect
, iconCGRect
, textCGRect
;
2621 ThemeDrawingState savedState
= NULL
;
2622 CGContextRef context
= (CGContextRef
)list
->MacGetDrawingContext();
2623 RGBColor labelColor
;
2625 labelColor
.green
= 0;
2626 labelColor
.blue
= 0;
2628 RGBColor backgroundColor
;
2629 backgroundColor
.red
= 255;
2630 backgroundColor
.green
= 255;
2631 backgroundColor
.blue
= 255;
2633 GetDataBrowserItemPartBounds(GetControlRef(), itemID
, property
, kDataBrowserPropertyEnclosingPart
,
2636 enclosingCGRect
= CGRectMake(enclosingRect
.left
,
2638 enclosingRect
.right
- enclosingRect
.left
,
2639 enclosingRect
.bottom
- enclosingRect
.top
);
2641 bool hasFocus
= (wxWindow::FindFocus() == list
);
2642 active
= IsControlActive(GetControlRef());
2644 // don't paint the background over the vertical rule line
2645 if ( list
->GetWindowStyleFlag() & wxLC_VRULES
)
2647 enclosingCGRect
.origin
.x
+= 1;
2648 enclosingCGRect
.size
.width
-= 1;
2650 if (itemState
== kDataBrowserItemIsSelected
)
2653 GetThemeDrawingState(&savedState
);
2655 if (active
&& hasFocus
)
2657 GetThemeBrushAsColor(kThemeBrushAlternatePrimaryHighlightColor
, 32, true, &backgroundColor
);
2658 GetThemeTextColor(kThemeTextColorWhite
, gdDepth
, colorDevice
, &labelColor
);
2662 GetThemeBrushAsColor(kThemeBrushSecondaryHighlightColor
, 32, true, &backgroundColor
);
2663 GetThemeTextColor(kThemeTextColorBlack
, gdDepth
, colorDevice
, &labelColor
);
2665 CGContextSaveGState(context
);
2667 CGContextSetRGBFillColor(context
, (float)backgroundColor
.red
/ (float)USHRT_MAX
,
2668 (float)backgroundColor
.green
/ (float)USHRT_MAX
,
2669 (float)backgroundColor
.blue
/ (float)USHRT_MAX
, 1.0);
2670 CGContextFillRect(context
, enclosingCGRect
);
2672 CGContextRestoreGState(context
);
2678 labelColor
= MAC_WXCOLORREF( color
.GetPixel() );
2679 else if (list
->GetTextColour().Ok())
2680 labelColor
= MAC_WXCOLORREF( list
->GetTextColour().GetPixel() );
2684 backgroundColor
= MAC_WXCOLORREF( bgColor
.GetPixel() );
2685 CGContextSaveGState(context
);
2687 CGContextSetRGBFillColor(context
, (float)backgroundColor
.red
/ (float)USHRT_MAX
,
2688 (float)backgroundColor
.green
/ (float)USHRT_MAX
,
2689 (float)backgroundColor
.blue
/ (float)USHRT_MAX
, 1.0);
2690 CGContextFillRect(context
, enclosingCGRect
);
2692 CGContextRestoreGState(context
);
2696 calculateCGDrawingBounds(enclosingCGRect
, &iconCGRect
, &textCGRect
, (imgIndex
!= -1) );
2700 wxImageList
* imageList
= list
->GetImageList(wxIMAGE_LIST_SMALL
);
2701 if (imageList
&& imageList
->GetImageCount() > 0){
2702 wxBitmap bmp
= imageList
->GetBitmap(imgIndex
);
2703 IconRef icon
= bmp
.GetBitmapData()->GetIconRef();
2705 CGContextSaveGState(context
);
2706 CGContextTranslateCTM(context
, 0,iconCGRect
.origin
.y
+ CGRectGetMaxY(iconCGRect
));
2707 CGContextScaleCTM(context
,1.0f
,-1.0f
);
2708 PlotIconRefInContext(context
, &iconCGRect
, kAlignNone
,
2709 active
? kTransformNone
: kTransformDisabled
, NULL
,
2710 kPlotIconRefNormalFlags
, icon
);
2712 CGContextRestoreGState(context
);
2716 HIThemeTextHorizontalFlush hFlush
= kHIThemeTextHorizontalFlushLeft
;
2717 UInt16 fontID
= kThemeViewsFont
;
2721 if (font
.GetFamily() != wxFONTFAMILY_DEFAULT
)
2722 fontID
= font
.MacGetThemeFontID();
2724 // FIXME: replace these with CG or ATSUI calls so we can remove this #ifndef.
2726 ::TextSize( (short)(font
.MacGetFontSize()) ) ;
2727 ::TextFace( font
.MacGetFontStyle() ) ;
2732 list
->GetColumn(listColumn
, item
);
2733 if (item
.GetMask() & wxLIST_MASK_FORMAT
)
2735 if (item
.GetAlign() == wxLIST_FORMAT_LEFT
)
2736 hFlush
= kHIThemeTextHorizontalFlushLeft
;
2737 else if (item
.GetAlign() == wxLIST_FORMAT_CENTER
)
2738 hFlush
= kHIThemeTextHorizontalFlushCenter
;
2739 else if (item
.GetAlign() == wxLIST_FORMAT_RIGHT
)
2741 hFlush
= kHIThemeTextHorizontalFlushRight
;
2742 textCGRect
.origin
.x
-= kItemPadding
; // give a little extra paddding
2746 HIThemeTextInfo info
;
2747 info
.version
= kHIThemeTextInfoVersionZero
;
2748 info
.state
= active
? kThemeStateActive
: kThemeStateInactive
;
2749 info
.fontID
= fontID
;
2750 info
.horizontalFlushness
= hFlush
;
2751 info
.verticalFlushness
= kHIThemeTextVerticalFlushCenter
;
2752 info
.options
= kHIThemeTextBoxOptionNone
;
2753 info
.truncationPosition
= kHIThemeTextTruncationEnd
;
2754 info
.truncationMaxLines
= 1;
2756 CGContextSaveGState(context
);
2757 CGContextSetRGBFillColor (context
, (float)labelColor
.red
/ (float)USHRT_MAX
,
2758 (float)labelColor
.green
/ (float)USHRT_MAX
,
2759 (float)labelColor
.blue
/ (float)USHRT_MAX
, 1.0);
2761 HIThemeDrawTextBox(cfString
, &textCGRect
, &info
, context
, kHIThemeOrientationNormal
);
2763 CGContextRestoreGState(context
);
2765 if (savedState
!= NULL
)
2766 SetThemeDrawingState(savedState
, true);
2769 OSStatus
wxMacDataBrowserListCtrlControl::GetSetItemData(DataBrowserItemID itemID
,
2770 DataBrowserPropertyID property
,
2771 DataBrowserItemDataRef itemData
,
2772 Boolean changeValue
)
2776 short listColumn
= property
- kMinColumnId
;
2778 OSStatus err
= errDataBrowserPropertyNotSupported
;
2779 wxListCtrl
* list
= wxDynamicCast( GetPeer() , wxListCtrl
);
2780 wxMacListCtrlItem
* lcItem
;
2782 if (listColumn
>= 0)
2786 lcItem
= (wxMacListCtrlItem
*) itemID
;
2787 if (lcItem
&& lcItem
->HasColumnInfo(listColumn
)){
2788 wxListItem
* item
= lcItem
->GetColumnInfo(listColumn
);
2789 if (item
->GetMask() & wxLIST_MASK_TEXT
)
2790 text
= item
->GetText();
2791 if (item
->GetMask() & wxLIST_MASK_IMAGE
)
2792 imgIndex
= item
->GetImage();
2797 text
= list
->OnGetItemText( (long)itemID
-1, listColumn
);
2798 imgIndex
= list
->OnGetItemColumnImage( (long)itemID
-1, listColumn
);
2806 case kDataBrowserItemIsEditableProperty
:
2807 if ( list
&& list
->HasFlag( wxLC_EDIT_LABELS
) )
2809 verify_noerr(SetDataBrowserItemDataBooleanValue( itemData
, true ));
2814 if ( property
>= kMinColumnId
)
2816 wxMacCFStringHolder cfStr
;
2819 cfStr
.Assign( text
, wxLocale::GetSystemEncoding() );
2820 err
= ::SetDataBrowserItemDataText( itemData
, cfStr
);
2826 if ( imgIndex
!= -1 )
2828 wxImageList
* imageList
= list
->GetImageList(wxIMAGE_LIST_SMALL
);
2829 if (imageList
&& imageList
->GetImageCount() > 0){
2830 wxBitmap bmp
= imageList
->GetBitmap(imgIndex
);
2831 IconRef icon
= bmp
.GetBitmapData()->GetIconRef();
2832 ::SetDataBrowserItemDataIcon(itemData
, icon
);
2846 if ( property
>= kMinColumnId
)
2848 short listColumn
= property
- kMinColumnId
;
2850 // TODO probably send the 'end edit' from here, as we
2851 // can then deal with the veto
2853 verify_noerr( GetDataBrowserItemDataText( itemData
, &sr
) ) ;
2854 wxMacCFStringHolder
cfStr(sr
) ;;
2856 list
->SetItem( (long)itemData
-1 , listColumn
, cfStr
.AsString() ) ;
2860 lcItem
->SetColumnTextValue( listColumn
, cfStr
.AsString() );
2870 void wxMacDataBrowserListCtrlControl::ItemNotification(DataBrowserItemID itemID
,
2871 DataBrowserItemNotification message
,
2872 DataBrowserItemDataRef itemData
)
2874 // we want to depend on as little as possible to make sure tear-down of controls is safe
2875 if ( message
== kDataBrowserItemRemoved
)
2877 // make sure MacDelete does the proper teardown.
2880 else if ( message
== kDataBrowserItemAdded
)
2882 // we don't issue events on adding, the item is not really stored in the list yet, so we
2883 // avoid asserts by getting out now
2887 wxListCtrl
*list
= wxDynamicCast( GetPeer() , wxListCtrl
);
2890 bool trigger
= false;
2892 wxListEvent
event( wxEVT_COMMAND_LIST_ITEM_SELECTED
, list
->GetId() );
2893 bool isSingle
= (list
->GetWindowStyle() & wxLC_SINGLE_SEL
) != 0;
2895 event
.SetEventObject( list
);
2896 if ( !list
->IsVirtual() )
2898 DataBrowserTableViewRowIndex result
= 0;
2899 verify_noerr( GetItemRow( itemID
, &result
) ) ;
2900 event
.m_itemIndex
= result
;
2902 if (event
.m_itemIndex
>= 0)
2903 MacGetColumnInfo(event
.m_itemIndex
,0,event
.m_item
);
2907 event
.m_itemIndex
= (long)itemID
-1;
2912 case kDataBrowserItemDeselected
:
2913 event
.SetEventType(wxEVT_COMMAND_LIST_ITEM_DESELECTED
);
2915 trigger
= !IsSelectionSuppressed();
2918 case kDataBrowserItemSelected
:
2919 trigger
= !IsSelectionSuppressed();
2923 case kDataBrowserItemDoubleClicked
:
2924 event
.SetEventType( wxEVT_COMMAND_LIST_ITEM_ACTIVATED
);
2928 case kDataBrowserEditStarted
:
2929 // TODO : how to veto ?
2930 event
.SetEventType( wxEVT_COMMAND_LIST_BEGIN_LABEL_EDIT
) ;
2934 case kDataBrowserEditStopped
:
2935 // TODO probably trigger only upon the value store callback, because
2936 // here IIRC we cannot veto
2937 event
.SetEventType( wxEVT_COMMAND_LIST_END_LABEL_EDIT
) ;
2947 // direct notification is not always having the listbox GetSelection() having in synch with event
2948 wxPostEvent( list
->GetEventHandler(), event
);
2953 Boolean
wxMacDataBrowserListCtrlControl::CompareItems(DataBrowserItemID itemOneID
,
2954 DataBrowserItemID itemTwoID
,
2955 DataBrowserPropertyID sortProperty
)
2958 bool retval
= false;
2960 wxString otherItemText
;
2962 long otherItemOrder
;
2964 int colId
= sortProperty
- kMinColumnId
;
2966 wxListCtrl
* list
= wxDynamicCast( GetPeer() , wxListCtrl
);
2968 DataBrowserSortOrder sort
;
2969 verify_noerr(GetSortOrder(&sort
));
2975 wxMacListCtrlItem
* item
= (wxMacListCtrlItem
*)itemOneID
;
2976 wxMacListCtrlItem
* otherItem
= (wxMacListCtrlItem
*)itemTwoID
;
2978 itemOrder
= item
->GetOrder();
2979 otherItemOrder
= item
->GetOrder();
2981 wxListCtrlCompare func
= list
->GetCompareFunc();
2986 if (item
&& item
->HasColumnInfo(0))
2987 item1
= item
->GetColumnInfo(0)->GetData();
2988 if (otherItem
&& otherItem
->HasColumnInfo(0))
2989 item2
= otherItem
->GetColumnInfo(0)->GetData();
2991 if (item1
> -1 && item2
> -1)
2993 int result
= func(item1
, item2
, list
->GetCompareFuncData());
2994 if (sort
== kDataBrowserOrderIncreasing
)
3001 // we can't use the native control's sorting abilities, so just
3003 return itemOrder
< otherItemOrder
;
3008 long itemNum
= (long)itemOneID
;
3009 long otherItemNum
= (long)itemTwoID
;
3010 itemText
= list
->OnGetItemText( itemNum
-1, colId
);
3011 otherItemText
= list
->OnGetItemText( otherItemNum
-1, colId
);
3013 // virtual listctrls don't support sorting
3014 return itemNum
< otherItemNum
;
3018 // fallback for undefined cases
3019 retval
= itemOneID
< itemTwoID
;
3025 wxMacDataBrowserListCtrlControl::~wxMacDataBrowserListCtrlControl()
3029 void wxMacDataBrowserListCtrlControl::MacSetColumnInfo( unsigned int row
, unsigned int column
, wxListItem
* item
)
3031 wxMacDataItem
* dataItem
= GetItemFromLine(row
);
3032 wxASSERT_MSG( dataItem
, _T("could not obtain wxMacDataItem for row in MacSetColumnInfo. Is row a valid wxListCtrl row?") );
3035 wxMacListCtrlItem
* listItem
= wx_static_cast(wxMacListCtrlItem
*,dataItem
);
3036 bool hasInfo
= listItem
->HasColumnInfo( column
);
3037 listItem
->SetColumnInfo( column
, item
);
3038 listItem
->SetOrder(row
);
3039 UpdateState(dataItem
, item
);
3041 wxListCtrl
* list
= wxDynamicCast( GetPeer() , wxListCtrl
);
3043 // NB: When this call was made before a control was completely shown, it would
3044 // update the item prematurely (i.e. no text would be listed) and, on show,
3045 // only the sorted column would be refreshed, meaning only first column text labels
3046 // would be shown. Making sure not to update items until the control is visible
3047 // seems to fix this issue.
3048 if (hasInfo
&& list
->IsShown())
3049 UpdateItem( wxMacDataBrowserRootContainer
, listItem
, kMinColumnId
+ column
);
3053 // apply changes that need to happen immediately, rather than when the
3054 // databrowser control fires a callback.
3055 void wxMacDataBrowserListCtrlControl::UpdateState(wxMacDataItem
* dataItem
, wxListItem
* listItem
)
3057 bool isSelected
= IsItemSelected( dataItem
);
3058 bool isSelectedState
= (listItem
->GetState() == wxLIST_STATE_SELECTED
);
3060 // toggle the selection state if wxListInfo state and actual state don't match.
3061 if ( isSelected
!= isSelectedState
)
3063 DataBrowserSetOption options
= kDataBrowserItemsAdd
;
3064 if (!isSelectedState
)
3065 options
= kDataBrowserItemsRemove
;
3066 SetSelectedItem(dataItem
, options
);
3068 // TODO: Set column width if item width > than current column width
3071 void wxMacDataBrowserListCtrlControl::MacGetColumnInfo( unsigned int row
, unsigned int column
, wxListItem
& item
)
3073 wxMacDataItem
* dataItem
= GetItemFromLine(row
);
3074 wxASSERT_MSG( dataItem
, _T("could not obtain wxMacDataItem in MacGetColumnInfo. Is row a valid wxListCtrl row?") );
3075 // CS should this guard against dataItem = 0 ? , as item is not a pointer if (item) is not appropriate
3078 wxMacListCtrlItem
* listItem
=wx_static_cast(wxMacListCtrlItem
*,dataItem
);
3080 if (!listItem
->HasColumnInfo( column
))
3083 wxListItem
* oldItem
= listItem
->GetColumnInfo( column
);
3087 long mask
= item
.GetMask();
3089 // by default, get everything for backwards compatibility
3092 if ( mask
& wxLIST_MASK_TEXT
)
3093 item
.SetText(oldItem
->GetText());
3094 if ( mask
& wxLIST_MASK_IMAGE
)
3095 item
.SetImage(oldItem
->GetImage());
3096 if ( mask
& wxLIST_MASK_DATA
)
3097 item
.SetData(oldItem
->GetData());
3098 if ( mask
& wxLIST_MASK_STATE
)
3099 item
.SetState(oldItem
->GetState());
3100 if ( mask
& wxLIST_MASK_WIDTH
)
3101 item
.SetWidth(oldItem
->GetWidth());
3102 if ( mask
& wxLIST_MASK_FORMAT
)
3103 item
.SetAlign(oldItem
->GetAlign());
3105 item
.SetTextColour(oldItem
->GetTextColour());
3106 item
.SetBackgroundColour(oldItem
->GetBackgroundColour());
3107 item
.SetFont(oldItem
->GetFont());
3112 void wxMacDataBrowserListCtrlControl::MacInsertItem( unsigned int n
, wxListItem
* item
)
3114 wxMacDataItemBrowserControl::MacInsert(n
, item
->GetText());
3115 MacSetColumnInfo(n
, 0, item
);
3118 wxMacDataItem
* wxMacDataBrowserListCtrlControl::CreateItem()
3120 return new wxMacListCtrlItem();
3123 wxMacListCtrlItem::wxMacListCtrlItem()
3125 m_rowItems
= wxListItemList();
3128 int wxMacListCtrlItem::GetColumnImageValue( unsigned int column
)
3130 if ( HasColumnInfo(column
) )
3131 return GetColumnInfo(column
)->GetImage();
3136 void wxMacListCtrlItem::SetColumnImageValue( unsigned int column
, int imageIndex
)
3138 if ( HasColumnInfo(column
) )
3139 GetColumnInfo(column
)->SetImage(imageIndex
);
3142 wxString
wxMacListCtrlItem::GetColumnTextValue( unsigned int column
)
3147 if ( HasColumnInfo(column
) )
3148 return GetColumnInfo(column
)->GetText();
3150 return wxEmptyString
;
3153 void wxMacListCtrlItem::SetColumnTextValue( unsigned int column
, const wxString
& text
)
3155 if ( HasColumnInfo(column
) )
3156 GetColumnInfo(column
)->SetText(text
);
3158 // for compatibility with superclass APIs
3163 wxListItem
* wxMacListCtrlItem::GetColumnInfo( unsigned int column
)
3165 wxASSERT_MSG( HasColumnInfo(column
), _T("invalid column index in wxMacListCtrlItem") );
3166 return m_rowItems
[column
];
3169 bool wxMacListCtrlItem::HasColumnInfo( unsigned int column
)
3171 return !(m_rowItems
.find( column
) == m_rowItems
.end());
3174 void wxMacListCtrlItem::SetColumnInfo( unsigned int column
, wxListItem
* item
)
3177 if ( !HasColumnInfo(column
) )
3179 wxListItem
* listItem
= new wxListItem(*item
);
3180 m_rowItems
[column
] = listItem
;
3184 wxListItem
* listItem
= GetColumnInfo( column
);
3185 long mask
= item
->GetMask();
3186 if (mask
& wxLIST_MASK_TEXT
)
3187 listItem
->SetText(item
->GetText());
3188 if (mask
& wxLIST_MASK_DATA
)
3189 listItem
->SetData(item
->GetData());
3190 if (mask
& wxLIST_MASK_IMAGE
)
3191 listItem
->SetImage(item
->GetImage());
3192 if (mask
& wxLIST_MASK_STATE
)
3193 listItem
->SetState(item
->GetState());
3194 if (mask
& wxLIST_MASK_FORMAT
)
3195 listItem
->SetAlign(item
->GetAlign());
3196 if (mask
& wxLIST_MASK_WIDTH
)
3197 listItem
->SetWidth(item
->GetWidth());
3199 if ( item
->HasAttributes() )
3201 if ( listItem
->HasAttributes() )
3202 listItem
->GetAttributes()->AssignFrom(*item
->GetAttributes());
3205 listItem
->SetTextColour(item
->GetTextColour());
3206 listItem
->SetBackgroundColour(item
->GetBackgroundColour());
3207 listItem
->SetFont(item
->GetFont());
3213 #endif // wxUSE_LISTCTRL