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
;
649 le
.m_item
.m_itemId
= item
;
651 GetEventHandler()->ProcessEvent(le
);
655 void wxListCtrl::OnChar(wxKeyEvent
& event
)
661 wxListEvent
le( wxEVT_COMMAND_LIST_KEY_DOWN
, GetId() );
662 le
.SetEventObject(this);
663 le
.m_code
= event
.GetKeyCode();
668 // if m_current isn't set, check if there's been a selection
669 // made before continuing
670 m_current
= GetNextItem(-1, wxLIST_NEXT_BELOW
, wxLIST_STATE_SELECTED
);
673 // We need to determine m_current ourselves when navigation keys
674 // are used. Note that PAGEUP and PAGEDOWN do not alter the current
675 // item on native Mac ListCtrl, so we only handle up and down keys.
676 switch ( event
.GetKeyCode() )
687 if ( m_current
< GetItemCount() - 1 )
690 m_current
= GetItemCount() - 1;
697 le
.m_itemIndex
= m_current
;
698 le
.m_item
.m_itemId
= m_current
;
700 GetEventHandler()->ProcessEvent(le
);
707 bool wxListCtrl::Create(wxWindow
*parent
,
712 const wxValidator
& validator
,
713 const wxString
& name
)
716 // for now, we'll always use the generic list control for ICON and LIST views,
717 // because they dynamically change the number of columns on resize.
718 // Also, allow the user to set it to use the list ctrl as well.
719 if ( (wxSystemOptions::HasOption( wxMAC_ALWAYS_USE_GENERIC_LISTCTRL
)
720 && (wxSystemOptions::GetOptionInt( wxMAC_ALWAYS_USE_GENERIC_LISTCTRL
) == 1)) ||
721 (style
& wxLC_ICON
) || (style
& wxLC_SMALL_ICON
) || (style
& wxLC_LIST
) )
723 m_macIsUserPane
= true;
725 long paneStyle
= style
;
726 paneStyle
&= ~wxSIMPLE_BORDER
;
727 paneStyle
&= ~wxDOUBLE_BORDER
;
728 paneStyle
&= ~wxSUNKEN_BORDER
;
729 paneStyle
&= ~wxRAISED_BORDER
;
730 paneStyle
&= ~wxSTATIC_BORDER
;
731 if ( !wxWindow::Create(parent
, id
, pos
, size
, paneStyle
| wxNO_BORDER
, name
) )
734 // since the generic control is a child, make sure we position it at 0, 0
735 m_genericImpl
= new wxGenericListCtrlHook(this, id
, wxPoint(0, 0), size
, style
, validator
, name
);
736 m_genericImpl
->PushEventHandler( new wxMacListCtrlEventDelegate( this, GetId() ) );
742 m_macIsUserPane
= false;
743 if ( !wxWindow::Create(parent
, id
, pos
, size
, style
& ~(wxHSCROLL
| wxVSCROLL
), name
) )
745 m_dbImpl
= new wxMacDataBrowserListCtrlControl( this, pos
, size
, style
);
748 MacPostControlCreate( pos
, size
);
750 InstallControlEventHandler( m_peer
->GetControlRef() , GetwxMacListCtrlEventHandlerUPP(),
751 GetEventTypeCount(eventList
), eventList
, this,
752 (EventHandlerRef
*)&m_macListCtrlEventHandler
);
758 wxListCtrl::~wxListCtrl()
762 m_genericImpl
->PopEventHandler(/* deleteHandler = */ true);
765 if (m_ownsImageListNormal
)
766 delete m_imageListNormal
;
767 if (m_ownsImageListSmall
)
768 delete m_imageListSmall
;
769 if (m_ownsImageListState
)
770 delete m_imageListState
;
772 delete m_renameTimer
;
775 // ----------------------------------------------------------------------------
776 // set/get/change style
777 // ----------------------------------------------------------------------------
779 // Add or remove a single window style
780 void wxListCtrl::SetSingleStyle(long style
, bool add
)
782 long flag
= GetWindowStyleFlag();
784 // Get rid of conflicting styles
787 if ( style
& wxLC_MASK_TYPE
)
788 flag
= flag
& ~wxLC_MASK_TYPE
;
789 if ( style
& wxLC_MASK_ALIGN
)
790 flag
= flag
& ~wxLC_MASK_ALIGN
;
791 if ( style
& wxLC_MASK_SORT
)
792 flag
= flag
& ~wxLC_MASK_SORT
;
800 SetWindowStyleFlag(flag
);
803 // Set the whole window style
804 void wxListCtrl::SetWindowStyleFlag(long flag
)
806 if ( flag
!= m_windowStyle
)
808 m_windowStyle
= flag
;
812 m_genericImpl
->SetWindowStyleFlag(flag
);
819 void wxListCtrl::DoSetSize( int x
, int y
, int width
, int height
, int sizeFlags
)
821 wxControl::DoSetSize(x
, y
, width
, height
, sizeFlags
);
824 m_genericImpl
->SetSize(0, 0, width
, height
, sizeFlags
);
826 // determine if we need a horizontal scrollbar, and add it if so
830 for (int column
= 0; column
< GetColumnCount(); column
++)
832 totalWidth
+= m_dbImpl
->GetColumnWidth( column
);
835 if ( !(m_dbImpl
->GetFlags() & wxHSCROLL
) )
837 Boolean vertScrollBar
;
838 GetDataBrowserHasScrollBars( m_dbImpl
->GetControlRef(), NULL
, &vertScrollBar
);
839 if (totalWidth
> width
)
840 SetDataBrowserHasScrollBars( m_dbImpl
->GetControlRef(), true, vertScrollBar
);
842 SetDataBrowserHasScrollBars( m_dbImpl
->GetControlRef(), false, vertScrollBar
);
847 wxSize
wxListCtrl::DoGetBestSize() const
849 return wxWindow::DoGetBestSize();
852 bool wxListCtrl::SetFont(const wxFont
& font
)
855 rv
= wxControl::SetFont(font
);
857 rv
= m_genericImpl
->SetFont(font
);
861 bool wxListCtrl::SetForegroundColour(const wxColour
& colour
)
865 rv
= m_genericImpl
->SetForegroundColour(colour
);
867 SetTextColour(colour
);
871 bool wxListCtrl::SetBackgroundColour(const wxColour
& colour
)
875 rv
= m_genericImpl
->SetBackgroundColour(colour
);
881 wxColour
wxListCtrl::GetBackgroundColour()
884 return m_genericImpl
->GetBackgroundColour();
891 // ----------------------------------------------------------------------------
893 // ----------------------------------------------------------------------------
895 // Gets information about this column
896 bool wxListCtrl::GetColumn(int col
, wxListItem
& item
) const
899 return m_genericImpl
->GetColumn(col
, item
);
905 wxColumnList::compatibility_iterator node
= m_colsInfo
.Item( col
);
906 wxASSERT_MSG( node
, _T("invalid column index in wxMacListCtrlItem") );
907 wxListItem
* column
= node
->GetData();
909 long mask
= column
->GetMask();
910 if (mask
& wxLIST_MASK_TEXT
)
911 item
.SetText(column
->GetText());
912 if (mask
& wxLIST_MASK_DATA
)
913 item
.SetData(column
->GetData());
914 if (mask
& wxLIST_MASK_IMAGE
)
915 item
.SetImage(column
->GetImage());
916 if (mask
& wxLIST_MASK_STATE
)
917 item
.SetState(column
->GetState());
918 if (mask
& wxLIST_MASK_FORMAT
)
919 item
.SetAlign(column
->GetAlign());
920 if (mask
& wxLIST_MASK_WIDTH
)
921 item
.SetWidth(column
->GetWidth());
927 // Sets information about this column
928 bool wxListCtrl::SetColumn(int col
, wxListItem
& item
)
931 return m_genericImpl
->SetColumn(col
, item
);
935 long mask
= item
.GetMask();
936 if ( col
>= (int)m_colsInfo
.GetCount() )
938 wxListItem
* listItem
= new wxListItem(item
);
939 m_colsInfo
.Append( listItem
);
944 GetColumn( col
, listItem
);
946 if (mask
& wxLIST_MASK_TEXT
)
947 listItem
.SetText(item
.GetText());
948 if (mask
& wxLIST_MASK_DATA
)
949 listItem
.SetData(item
.GetData());
950 if (mask
& wxLIST_MASK_IMAGE
)
951 listItem
.SetImage(item
.GetImage());
952 if (mask
& wxLIST_MASK_STATE
)
953 listItem
.SetState(item
.GetState());
954 if (mask
& wxLIST_MASK_FORMAT
)
955 listItem
.SetAlign(item
.GetAlign());
956 if (mask
& wxLIST_MASK_WIDTH
)
957 listItem
.SetWidth(item
.GetWidth());
960 // change the appearance in the databrowser.
961 DataBrowserListViewHeaderDesc columnDesc
;
962 columnDesc
.version
=kDataBrowserListViewLatestHeaderDesc
;
963 verify_noerr( m_dbImpl
->GetHeaderDesc( kMinColumnId
+ col
, &columnDesc
) );
966 if (item.GetMask() & wxLIST_MASK_TEXT)
970 enc = m_font.GetEncoding();
972 enc = wxLocale::GetSystemEncoding();
973 wxMacCFStringHolder cfTitle;
974 cfTitle.Assign( item.GetText() , enc );
975 if(columnDesc.titleString)
976 CFRelease(columnDesc.titleString);
977 columnDesc.titleString = cfTitle;
981 if (item
.GetMask() & wxLIST_MASK_IMAGE
&& item
.GetImage() != -1 )
983 columnDesc
.btnContentInfo
.contentType
= kControlContentIconRef
;
984 wxImageList
* imageList
= GetImageList(wxIMAGE_LIST_SMALL
);
985 if (imageList
&& imageList
->GetImageCount() > 0 )
987 wxBitmap bmp
= imageList
->GetBitmap( item
.GetImage() );
988 IconRef icon
= bmp
.GetBitmapData()->GetIconRef();
989 columnDesc
.btnContentInfo
.u
.iconRef
= icon
;
993 verify_noerr( m_dbImpl
->SetHeaderDesc( kMinColumnId
+ col
, &columnDesc
) );
999 int wxListCtrl::GetColumnCount() const
1002 return m_genericImpl
->GetColumnCount();
1007 m_dbImpl
->GetColumnCount(&count
);
1014 // Gets the column width
1015 int wxListCtrl::GetColumnWidth(int col
) const
1018 return m_genericImpl
->GetColumnWidth(col
);
1022 return m_dbImpl
->GetColumnWidth(col
);
1028 // Sets the column width
1029 bool wxListCtrl::SetColumnWidth(int col
, int width
)
1032 return m_genericImpl
->SetColumnWidth(col
, width
);
1036 int mywidth
= width
;
1037 if (width
== wxLIST_AUTOSIZE
|| width
== wxLIST_AUTOSIZE_USEHEADER
)
1042 for (int column
= 0; column
< GetColumnCount(); column
++)
1045 GetColumn(col
, colInfo
);
1047 colInfo
.SetWidth(width
);
1048 SetColumn(col
, colInfo
);
1050 m_dbImpl
->SetColumnWidth(col
, mywidth
);
1056 GetColumn(col
, colInfo
);
1058 colInfo
.SetWidth(width
);
1059 SetColumn(col
, colInfo
);
1060 m_dbImpl
->SetColumnWidth(col
, mywidth
);
1068 // Gets the number of items that can fit vertically in the
1069 // visible area of the list control (list or report view)
1070 // or the total number of items in the list control (icon
1071 // or small icon view)
1072 int wxListCtrl::GetCountPerPage() const
1075 return m_genericImpl
->GetCountPerPage();
1084 // Gets the edit control for editing labels.
1085 wxTextCtrl
* wxListCtrl::GetEditControl() const
1088 return m_genericImpl
->GetEditControl();
1093 // Gets information about the item
1094 bool wxListCtrl::GetItem(wxListItem
& info
) const
1097 return m_genericImpl
->GetItem(info
);
1103 if (info
.m_itemId
>= 0 && info
.m_itemId
< GetItemCount())
1104 m_dbImpl
->MacGetColumnInfo(info
.m_itemId
, info
.m_col
, info
);
1108 if (info
.m_itemId
>= 0 && info
.m_itemId
< GetItemCount())
1110 info
.SetText( OnGetItemText(info
.m_itemId
, info
.m_col
) );
1111 info
.SetImage( OnGetItemColumnImage(info
.m_itemId
, info
.m_col
) );
1112 if (info
.GetMask() & wxLIST_MASK_STATE
)
1114 if (IsDataBrowserItemSelected( m_dbImpl
->GetControlRef(), info
.m_itemId
+1 ))
1115 info
.SetState(info
.GetState() | wxLIST_STATE_SELECTED
);
1118 wxListItemAttr
* attrs
= OnGetItemAttr( info
.m_itemId
);
1121 info
.SetFont( attrs
->GetFont() );
1122 info
.SetBackgroundColour( attrs
->GetBackgroundColour() );
1123 info
.SetTextColour( attrs
->GetTextColour() );
1128 bool success
= true;
1132 // Sets information about the item
1133 bool wxListCtrl::SetItem(wxListItem
& info
)
1136 return m_genericImpl
->SetItem(info
);
1139 m_dbImpl
->MacSetColumnInfo( info
.m_itemId
, info
.m_col
, &info
);
1144 long wxListCtrl::SetItem(long index
, int col
, const wxString
& label
, int imageId
)
1147 return m_genericImpl
->SetItem(index
, col
, label
, imageId
);
1150 info
.m_text
= label
;
1151 info
.m_mask
= wxLIST_MASK_TEXT
;
1152 info
.m_itemId
= index
;
1156 info
.m_image
= imageId
;
1157 info
.m_mask
|= wxLIST_MASK_IMAGE
;
1159 return SetItem(info
);
1163 // Gets the item state
1164 int wxListCtrl::GetItemState(long item
, long stateMask
) const
1167 return m_genericImpl
->GetItemState(item
, stateMask
);
1171 if ( HasFlag(wxLC_VIRTUAL
) )
1173 if (stateMask
== wxLIST_STATE_SELECTED
)
1175 if (IsDataBrowserItemSelected( m_dbImpl
->GetControlRef(), item
+1 ))
1176 return wxLIST_STATE_SELECTED
;
1185 info
.m_mask
= wxLIST_MASK_STATE
;
1186 info
.m_stateMask
= stateMask
;
1187 info
.m_itemId
= item
;
1192 return info
.m_state
;
1199 // Sets the item state
1200 bool wxListCtrl::SetItemState(long item
, long state
, long stateMask
)
1203 return m_genericImpl
->SetItemState(item
, state
, stateMask
);
1207 DataBrowserSetOption option
= kDataBrowserItemsAdd
;
1208 if ( (stateMask
& wxLIST_STATE_SELECTED
) && state
== 0 )
1209 option
= kDataBrowserItemsRemove
;
1213 if ( HasFlag(wxLC_VIRTUAL
) )
1215 wxMacDataItemBrowserSelectionSuppressor
suppressor(m_dbImpl
);
1216 m_dbImpl
->SetSelectedAllItems(option
);
1220 for(int i
= 0; i
< GetItemCount();i
++)
1224 info
.m_mask
= wxLIST_MASK_STATE
;
1225 info
.m_stateMask
= stateMask
;
1226 info
.m_state
= state
;
1233 if ( HasFlag(wxLC_VIRTUAL
) )
1235 long itemID
= item
+1;
1236 bool isSelected
= IsDataBrowserItemSelected(m_dbImpl
->GetControlRef(), (DataBrowserItemID
)itemID
);
1237 bool isSelectedState
= (state
== wxLIST_STATE_SELECTED
);
1239 // toggle the selection state if wxListInfo state and actual state don't match.
1240 if ( (stateMask
& wxLIST_STATE_SELECTED
) && isSelected
!= isSelectedState
)
1242 SetDataBrowserSelectedItems(m_dbImpl
->GetControlRef(), 1, (DataBrowserItemID
*)&itemID
, option
);
1248 info
.m_itemId
= item
;
1249 info
.m_mask
= wxLIST_MASK_STATE
;
1250 info
.m_stateMask
= stateMask
;
1251 info
.m_state
= state
;
1252 return SetItem(info
);
1259 // Sets the item image
1260 bool wxListCtrl::SetItemImage(long item
, int image
, int WXUNUSED(selImage
))
1262 return SetItemColumnImage(item
, 0, image
);
1265 // Sets the item image
1266 bool wxListCtrl::SetItemColumnImage(long item
, long column
, int image
)
1269 return m_genericImpl
->SetItemColumnImage(item
, column
, image
);
1273 info
.m_mask
= wxLIST_MASK_IMAGE
;
1274 info
.m_image
= image
;
1275 info
.m_itemId
= item
;
1276 info
.m_col
= column
;
1278 return SetItem(info
);
1281 // Gets the item text
1282 wxString
wxListCtrl::GetItemText(long item
) const
1285 return m_genericImpl
->GetItemText(item
);
1289 info
.m_mask
= wxLIST_MASK_TEXT
;
1290 info
.m_itemId
= item
;
1293 return wxEmptyString
;
1297 // Sets the item text
1298 void wxListCtrl::SetItemText(long item
, const wxString
& str
)
1301 return m_genericImpl
->SetItemText(item
, str
);
1305 info
.m_mask
= wxLIST_MASK_TEXT
;
1306 info
.m_itemId
= item
;
1312 // Gets the item data
1313 long wxListCtrl::GetItemData(long item
) const
1316 return m_genericImpl
->GetItemData(item
);
1320 info
.m_mask
= wxLIST_MASK_DATA
;
1321 info
.m_itemId
= item
;
1328 // Sets the item data
1329 bool wxListCtrl::SetItemPtrData(long item
, wxUIntPtr data
)
1332 return m_genericImpl
->SetItemData(item
, data
);
1336 info
.m_mask
= wxLIST_MASK_DATA
;
1337 info
.m_itemId
= item
;
1340 return SetItem(info
);
1343 wxRect
wxListCtrl::GetViewRect() const
1345 wxASSERT_MSG( !HasFlag(wxLC_REPORT
| wxLC_LIST
),
1346 _T("wxListCtrl::GetViewRect() only works in icon mode") );
1349 return m_genericImpl
->GetViewRect();
1355 // Gets the item rectangle
1356 bool wxListCtrl::GetItemRect(long item
, wxRect
& rect
, int code
) const
1359 return m_genericImpl
->GetItemRect(item
, rect
, code
);
1364 DataBrowserItemID id
;
1365 DataBrowserPropertyID col
= kMinColumnId
;
1367 DataBrowserPropertyPart part
= kDataBrowserPropertyEnclosingPart
;
1368 if ( code
== wxLIST_RECT_LABEL
)
1369 part
= kDataBrowserPropertyTextPart
;
1370 else if ( code
== wxLIST_RECT_ICON
)
1371 part
= kDataBrowserPropertyIconPart
;
1373 if ( !(GetWindowStyleFlag() & wxLC_VIRTUAL
) )
1375 wxMacDataItem
* thisItem
= m_dbImpl
->GetItemFromLine(item
);
1376 id
= (DataBrowserItemID
) thisItem
;
1381 GetDataBrowserItemPartBounds( m_dbImpl
->GetControlRef(), id
, col
, part
, &bounds
);
1383 rect
.x
= bounds
.left
;
1384 rect
.y
= bounds
.top
;
1385 rect
.width
= bounds
.right
- bounds
.left
; //GetClientSize().x; // we need the width of the whole row, not just the item.
1386 rect
.height
= bounds
.bottom
- bounds
.top
;
1387 //fprintf("id = %d, bounds = %d, %d, %d, %d\n", id, rect.x, rect.y, rect.width, rect.height);
1392 // Gets the item position
1393 bool wxListCtrl::GetItemPosition(long item
, wxPoint
& pos
) const
1396 return m_genericImpl
->GetItemPosition(item
, pos
);
1398 bool success
= false;
1403 GetItemRect(item
, itemRect
);
1404 pos
= itemRect
.GetPosition();
1411 // Sets the item position.
1412 bool wxListCtrl::SetItemPosition(long item
, const wxPoint
& pos
)
1415 return m_genericImpl
->SetItemPosition(item
, pos
);
1420 // Gets the number of items in the list control
1421 int wxListCtrl::GetItemCount() const
1424 return m_genericImpl
->GetItemCount();
1427 return m_dbImpl
->MacGetCount();
1432 void wxListCtrl::SetItemSpacing( int spacing
, bool isSmall
)
1435 m_genericImpl
->SetItemSpacing(spacing
, isSmall
);
1438 wxSize
wxListCtrl::GetItemSpacing() const
1441 return m_genericImpl
->GetItemSpacing();
1443 return wxSize(0, 0);
1446 void wxListCtrl::SetItemTextColour( long item
, const wxColour
&col
)
1450 m_genericImpl
->SetItemTextColour(item
, col
);
1455 info
.m_itemId
= item
;
1456 info
.SetTextColour( col
);
1460 wxColour
wxListCtrl::GetItemTextColour( long item
) const
1463 return m_genericImpl
->GetItemTextColour(item
);
1469 return info
.GetTextColour();
1471 return wxNullColour
;
1474 void wxListCtrl::SetItemBackgroundColour( long item
, const wxColour
&col
)
1478 m_genericImpl
->SetItemBackgroundColour(item
, col
);
1483 info
.m_itemId
= item
;
1484 info
.SetBackgroundColour( col
);
1488 wxColour
wxListCtrl::GetItemBackgroundColour( long item
) const
1491 return m_genericImpl
->GetItemBackgroundColour(item
);
1497 return info
.GetBackgroundColour();
1499 return wxNullColour
;
1502 void wxListCtrl::SetItemFont( long item
, const wxFont
&f
)
1506 m_genericImpl
->SetItemFont(item
, f
);
1511 info
.m_itemId
= item
;
1516 wxFont
wxListCtrl::GetItemFont( long item
) const
1519 return m_genericImpl
->GetItemFont(item
);
1525 return info
.GetFont();
1531 // Gets the number of selected items in the list control
1532 int wxListCtrl::GetSelectedItemCount() const
1535 return m_genericImpl
->GetSelectedItemCount();
1538 return m_dbImpl
->GetSelectedItemCount(NULL
, true);
1543 // Gets the text colour of the listview
1544 wxColour
wxListCtrl::GetTextColour() const
1547 return m_genericImpl
->GetTextColour();
1549 // TODO: we need owner drawn list items to customize text color.
1553 return wxNullColour
;
1556 // Sets the text colour of the listview
1557 void wxListCtrl::SetTextColour(const wxColour
& col
)
1561 m_genericImpl
->SetTextColour(col
);
1569 // Gets the index of the topmost visible item when in
1570 // list or report view
1571 long wxListCtrl::GetTopItem() const
1574 return m_genericImpl
->GetTopItem();
1579 long item
= HitTest( wxPoint(1, 1), flags
);
1580 if (flags
== wxLIST_HITTEST_ONITEM
)
1587 // Searches for an item, starting from 'item'.
1588 // 'geometry' is one of
1589 // wxLIST_NEXT_ABOVE/ALL/BELOW/LEFT/RIGHT.
1590 // 'state' is a state bit flag, one or more of
1591 // wxLIST_STATE_DROPHILITED/FOCUSED/SELECTED/CUT.
1592 // item can be -1 to find the first item that matches the
1594 // Returns the item or -1 if unsuccessful.
1595 long wxListCtrl::GetNextItem(long item
, int geom
, int state
) const
1598 return m_genericImpl
->GetNextItem(item
, geom
, state
);
1600 // TODO: implement all geometry and state options?
1603 if ( geom
== wxLIST_NEXT_ALL
|| geom
== wxLIST_NEXT_BELOW
)
1605 long count
= m_dbImpl
->MacGetCount() ;
1606 for ( long line
= item
+ 1 ; line
< count
; line
++ )
1608 DataBrowserItemID id
= line
+ 1;
1610 id
= (DataBrowserItemID
)m_dbImpl
->GetItemFromLine(line
);
1612 if ( (state
== wxLIST_STATE_DONTCARE
) )
1615 if ( (state
& wxLIST_STATE_SELECTED
) && IsDataBrowserItemSelected(m_dbImpl
->GetControlRef(), id
) )
1620 if ( geom
== wxLIST_NEXT_ABOVE
)
1624 item2
= m_dbImpl
->MacGetCount();
1626 for ( long line
= item2
- 1 ; line
>= 0; line
-- )
1628 DataBrowserItemID id
= line
+ 1;
1630 id
= (DataBrowserItemID
)m_dbImpl
->GetItemFromLine(line
);
1632 if ( (state
== wxLIST_STATE_DONTCARE
) )
1635 if ( (state
& wxLIST_STATE_SELECTED
) && IsDataBrowserItemSelected(m_dbImpl
->GetControlRef(), id
) )
1645 wxImageList
*wxListCtrl::GetImageList(int which
) const
1648 return m_genericImpl
->GetImageList(which
);
1650 if ( which
== wxIMAGE_LIST_NORMAL
)
1652 return m_imageListNormal
;
1654 else if ( which
== wxIMAGE_LIST_SMALL
)
1656 return m_imageListSmall
;
1658 else if ( which
== wxIMAGE_LIST_STATE
)
1660 return m_imageListState
;
1665 void wxListCtrl::SetImageList(wxImageList
*imageList
, int which
)
1669 m_genericImpl
->SetImageList(imageList
, which
);
1673 if ( which
== wxIMAGE_LIST_NORMAL
)
1675 if (m_ownsImageListNormal
) delete m_imageListNormal
;
1676 m_imageListNormal
= imageList
;
1677 m_ownsImageListNormal
= false;
1679 else if ( which
== wxIMAGE_LIST_SMALL
)
1681 if (m_ownsImageListSmall
) delete m_imageListSmall
;
1682 m_imageListSmall
= imageList
;
1683 m_ownsImageListSmall
= false;
1685 else if ( which
== wxIMAGE_LIST_STATE
)
1687 if (m_ownsImageListState
) delete m_imageListState
;
1688 m_imageListState
= imageList
;
1689 m_ownsImageListState
= false;
1693 void wxListCtrl::AssignImageList(wxImageList
*imageList
, int which
)
1697 m_genericImpl
->AssignImageList(imageList
, which
);
1701 SetImageList(imageList
, which
);
1702 if ( which
== wxIMAGE_LIST_NORMAL
)
1703 m_ownsImageListNormal
= true;
1704 else if ( which
== wxIMAGE_LIST_SMALL
)
1705 m_ownsImageListSmall
= true;
1706 else if ( which
== wxIMAGE_LIST_STATE
)
1707 m_ownsImageListState
= true;
1710 // ----------------------------------------------------------------------------
1712 // ----------------------------------------------------------------------------
1714 // Arranges the items
1715 bool wxListCtrl::Arrange(int flag
)
1718 return m_genericImpl
->Arrange(flag
);
1723 bool wxListCtrl::DeleteItem(long item
)
1726 return m_genericImpl
->DeleteItem(item
);
1730 m_dbImpl
->MacDelete(item
);
1731 wxListEvent
event( wxEVT_COMMAND_LIST_DELETE_ITEM
, GetId() );
1732 event
.SetEventObject( this );
1733 event
.m_itemIndex
= item
;
1734 GetEventHandler()->ProcessEvent( event
);
1740 // Deletes all items
1741 bool wxListCtrl::DeleteAllItems()
1744 return m_genericImpl
->DeleteAllItems();
1748 m_dbImpl
->MacClear();
1749 wxListEvent
event( wxEVT_COMMAND_LIST_DELETE_ALL_ITEMS
, GetId() );
1750 event
.SetEventObject( this );
1751 GetEventHandler()->ProcessEvent( event
);
1756 // Deletes all items
1757 bool wxListCtrl::DeleteAllColumns()
1760 return m_genericImpl
->DeleteAllColumns();
1765 m_dbImpl
->GetColumnCount(&cols
);
1766 for (UInt32 col
= 0; col
< cols
; col
++)
1776 bool wxListCtrl::DeleteColumn(int col
)
1779 return m_genericImpl
->DeleteColumn(col
);
1783 OSStatus err
= m_dbImpl
->RemoveColumn(col
);
1784 return err
== noErr
;
1790 // Clears items, and columns if there are any.
1791 void wxListCtrl::ClearAll()
1795 m_genericImpl
->ClearAll();
1806 wxTextCtrl
* wxListCtrl::EditLabel(long item
, wxClassInfo
* textControlClass
)
1809 return m_genericImpl
->EditLabel(item
, textControlClass
);
1813 wxCHECK_MSG( (item
>= 0) && ((long)item
< GetItemCount()), NULL
,
1814 wxT("wrong index in wxListCtrl::EditLabel()") );
1816 wxASSERT_MSG( textControlClass
->IsKindOf(CLASSINFO(wxTextCtrl
)),
1817 wxT("EditLabel() needs a text control") );
1819 wxListEvent
le( wxEVT_COMMAND_LIST_BEGIN_LABEL_EDIT
, GetParent()->GetId() );
1820 le
.SetEventObject( this );
1821 le
.m_itemIndex
= item
;
1823 GetItem( le
.m_item
);
1825 if ( GetParent()->GetEventHandler()->ProcessEvent( le
) && !le
.IsAllowed() )
1827 // vetoed by user code
1831 wxTextCtrl
* const text
= (wxTextCtrl
*)textControlClass
->CreateObject();
1832 m_textctrlWrapper
= new wxListCtrlTextCtrlWrapper(this, text
, item
);
1833 return m_textctrlWrapper
->GetText();
1838 // End label editing, optionally cancelling the edit
1839 bool wxListCtrl::EndEditLabel(bool cancel
)
1841 // TODO: generic impl. doesn't have this method - is it needed for us?
1843 return true; // m_genericImpl->EndEditLabel(cancel);
1846 verify_noerr( SetDataBrowserEditItem(m_dbImpl
->GetControlRef(), kDataBrowserNoItem
, kMinColumnId
) );
1850 // Ensures this item is visible
1851 bool wxListCtrl::EnsureVisible(long item
)
1854 return m_genericImpl
->EnsureVisible(item
);
1858 wxMacDataItem
* dataItem
= m_dbImpl
->GetItemFromLine(item
);
1859 m_dbImpl
->RevealItem(dataItem
, kDataBrowserRevealWithoutSelecting
);
1865 // Find an item whose label matches this string, starting from the item after 'start'
1866 // or the beginning if 'start' is -1.
1867 long wxListCtrl::FindItem(long start
, const wxString
& str
, bool partial
)
1870 return m_genericImpl
->FindItem(start
, str
, partial
);
1872 wxString str_upper
= str
.Upper();
1877 long count
= GetItemCount();
1881 wxString line_upper
= GetItemText(idx
).Upper();
1884 if (line_upper
== str_upper
)
1889 if (line_upper
.find(str_upper
) == 0)
1899 // Find an item whose data matches this data, starting from the item after 'start'
1900 // or the beginning if 'start' is -1.
1901 long wxListCtrl::FindItem(long start
, long data
)
1904 return m_genericImpl
->FindItem(start
, data
);
1909 long count
= GetItemCount();
1913 if (GetItemData(idx
) == data
)
1921 // Find an item nearest this position in the specified direction, starting from
1922 // the item after 'start' or the beginning if 'start' is -1.
1923 long wxListCtrl::FindItem(long start
, const wxPoint
& pt
, int direction
)
1926 return m_genericImpl
->FindItem(start
, pt
, direction
);
1930 // Determines which item (if any) is at the specified point,
1931 // giving details in 'flags' (see wxLIST_HITTEST_... flags above)
1933 wxListCtrl::HitTest(const wxPoint
& point
, int& flags
, long *ptrSubItem
) const
1936 return m_genericImpl
->HitTest(point
, flags
, ptrSubItem
);
1938 flags
= wxLIST_HITTEST_NOWHERE
;
1941 int colHeaderHeight
= 22; // TODO: Find a way to get this value from the db control?
1942 UInt16 rowHeight
= 0;
1943 m_dbImpl
->GetDefaultRowHeight(&rowHeight
);
1946 // get the actual row by taking scroll position into account
1947 UInt32 offsetX
, offsetY
;
1948 m_dbImpl
->GetScrollPosition( &offsetY
, &offsetX
);
1951 if ( !(GetWindowStyleFlag() & wxLC_NO_HEADER
) )
1952 y
-= colHeaderHeight
;
1957 int row
= y
/ rowHeight
;
1958 DataBrowserItemID id
;
1959 m_dbImpl
->GetItemID( (DataBrowserTableViewRowIndex
) row
, &id
);
1961 // TODO: Use GetDataBrowserItemPartBounds to return if we are in icon or label
1962 if ( !(GetWindowStyleFlag() & wxLC_VIRTUAL
) )
1964 wxMacListCtrlItem
* lcItem
;
1965 lcItem
= (wxMacListCtrlItem
*) id
;
1968 flags
= wxLIST_HITTEST_ONITEM
;
1974 if (row
< GetItemCount() )
1976 flags
= wxLIST_HITTEST_ONITEM
;
1985 int wxListCtrl::GetScrollPos(int orient
) const
1988 return m_genericImpl
->GetScrollPos(orient
);
1992 UInt32 offsetX
, offsetY
;
1993 m_dbImpl
->GetScrollPosition( &offsetY
, &offsetX
);
1994 if ( orient
== wxHORIZONTAL
)
2003 // Inserts an item, returning the index of the new item if successful,
2005 long wxListCtrl::InsertItem(wxListItem
& info
)
2007 wxASSERT_MSG( !IsVirtual(), _T("can't be used with virtual controls") );
2010 return m_genericImpl
->InsertItem(info
);
2012 if (m_dbImpl
&& !IsVirtual())
2014 int count
= GetItemCount();
2016 if (info
.m_itemId
> count
)
2017 info
.m_itemId
= count
;
2019 m_dbImpl
->MacInsertItem(info
.m_itemId
, &info
);
2021 wxListEvent
event( wxEVT_COMMAND_LIST_INSERT_ITEM
, GetId() );
2022 event
.SetEventObject( this );
2023 event
.m_itemIndex
= info
.m_itemId
;
2024 GetEventHandler()->ProcessEvent( event
);
2025 return info
.m_itemId
;
2030 long wxListCtrl::InsertItem(long index
, const wxString
& label
)
2033 return m_genericImpl
->InsertItem(index
, label
);
2036 info
.m_text
= label
;
2037 info
.m_mask
= wxLIST_MASK_TEXT
;
2038 info
.m_itemId
= index
;
2039 return InsertItem(info
);
2042 // Inserts an image item
2043 long wxListCtrl::InsertItem(long index
, int imageIndex
)
2046 return m_genericImpl
->InsertItem(index
, imageIndex
);
2049 info
.m_image
= imageIndex
;
2050 info
.m_mask
= wxLIST_MASK_IMAGE
;
2051 info
.m_itemId
= index
;
2052 return InsertItem(info
);
2055 // Inserts an image/string item
2056 long wxListCtrl::InsertItem(long index
, const wxString
& label
, int imageIndex
)
2059 return m_genericImpl
->InsertItem(index
, label
, imageIndex
);
2062 info
.m_image
= imageIndex
;
2063 info
.m_text
= label
;
2064 info
.m_mask
= wxLIST_MASK_IMAGE
| wxLIST_MASK_TEXT
;
2065 info
.m_itemId
= index
;
2066 return InsertItem(info
);
2069 // For list view mode (only), inserts a column.
2070 long wxListCtrl::InsertColumn(long col
, wxListItem
& item
)
2073 return m_genericImpl
->InsertColumn(col
, item
);
2077 int width
= item
.GetWidth();
2078 if ( !(item
.GetMask() & wxLIST_MASK_WIDTH
) )
2081 DataBrowserPropertyType type
= kDataBrowserCustomType
; //kDataBrowserTextType;
2082 wxImageList
* imageList
= GetImageList(wxIMAGE_LIST_SMALL
);
2083 if (imageList
&& imageList
->GetImageCount() > 0)
2085 wxBitmap bmp
= imageList
->GetBitmap(0);
2087 // type = kDataBrowserIconAndTextType;
2090 SInt16 just
= teFlushDefault
;
2091 if (item
.GetMask() & wxLIST_MASK_FORMAT
)
2093 if (item
.GetAlign() == wxLIST_FORMAT_LEFT
)
2095 else if (item
.GetAlign() == wxLIST_FORMAT_CENTER
)
2097 else if (item
.GetAlign() == wxLIST_FORMAT_RIGHT
)
2098 just
= teFlushRight
;
2100 m_dbImpl
->InsertColumn(col
, type
, item
.GetText(), just
, width
);
2101 SetColumn(col
, item
);
2103 // set/remove options based on the wxListCtrl type.
2104 DataBrowserTableViewColumnID id
;
2105 m_dbImpl
->GetColumnIDFromIndex(col
, &id
);
2106 DataBrowserPropertyFlags flags
;
2107 verify_noerr(m_dbImpl
->GetPropertyFlags(id
, &flags
));
2108 if (GetWindowStyleFlag() & wxLC_EDIT_LABELS
)
2109 flags
|= kDataBrowserPropertyIsEditable
;
2111 if (GetWindowStyleFlag() & wxLC_VIRTUAL
){
2112 flags
&= ~kDataBrowserListViewSortableColumn
;
2114 verify_noerr(m_dbImpl
->SetPropertyFlags(id
, flags
));
2120 long wxListCtrl::InsertColumn(long col
,
2121 const wxString
& heading
,
2126 return m_genericImpl
->InsertColumn(col
, heading
, format
, width
);
2129 item
.m_mask
= wxLIST_MASK_TEXT
| wxLIST_MASK_FORMAT
;
2130 item
.m_text
= heading
;
2133 item
.m_mask
|= wxLIST_MASK_WIDTH
;
2134 item
.m_width
= width
;
2136 item
.m_format
= format
;
2138 return InsertColumn(col
, item
);
2141 // scroll the control by the given number of pixels (exception: in list view,
2142 // dx is interpreted as number of columns)
2143 bool wxListCtrl::ScrollList(int dx
, int dy
)
2146 return m_genericImpl
->ScrollList(dx
, dy
);
2150 m_dbImpl
->SetScrollPosition(dx
, dy
);
2156 bool wxListCtrl::SortItems(wxListCtrlCompare fn
, long data
)
2159 return m_genericImpl
->SortItems(fn
, data
);
2164 m_compareFuncData
= data
;
2165 SortDataBrowserContainer( m_dbImpl
->GetControlRef(), kDataBrowserNoItem
, true);
2167 // we need to do this after each call, else we get a crash from wxPython when
2168 // SortItems is called the second time.
2169 m_compareFunc
= NULL
;
2170 m_compareFuncData
= 0;
2176 void wxListCtrl::OnRenameTimer()
2178 wxCHECK_RET( HasCurrent(), wxT("unexpected rename timer") );
2180 EditLabel( m_current
);
2183 bool wxListCtrl::OnRenameAccept(long itemEdit
, const wxString
& value
)
2185 wxListEvent
le( wxEVT_COMMAND_LIST_END_LABEL_EDIT
, GetId() );
2186 le
.SetEventObject( this );
2187 le
.m_itemIndex
= itemEdit
;
2189 GetItem( le
.m_item
);
2190 le
.m_item
.m_text
= value
;
2191 return !GetEventHandler()->ProcessEvent( le
) ||
2195 void wxListCtrl::OnRenameCancelled(long itemEdit
)
2197 // let owner know that the edit was cancelled
2198 wxListEvent
le( wxEVT_COMMAND_LIST_END_LABEL_EDIT
, GetParent()->GetId() );
2200 le
.SetEditCanceled(true);
2202 le
.SetEventObject( this );
2203 le
.m_itemIndex
= itemEdit
;
2205 GetItem( le
.m_item
);
2206 GetEventHandler()->ProcessEvent( le
);
2209 // ----------------------------------------------------------------------------
2210 // virtual list controls
2211 // ----------------------------------------------------------------------------
2213 wxString
wxListCtrl::OnGetItemText(long WXUNUSED(item
), long WXUNUSED(col
)) const
2215 // this is a pure virtual function, in fact - which is not really pure
2216 // because the controls which are not virtual don't need to implement it
2217 wxFAIL_MSG( _T("wxListCtrl::OnGetItemText not supposed to be called") );
2219 return wxEmptyString
;
2222 int wxListCtrl::OnGetItemImage(long WXUNUSED(item
)) const
2224 wxCHECK_MSG(!GetImageList(wxIMAGE_LIST_SMALL
),
2226 wxT("List control has an image list, OnGetItemImage or OnGetItemColumnImage should be overridden."));
2230 int wxListCtrl::OnGetItemColumnImage(long item
, long column
) const
2233 return OnGetItemImage(item
);
2238 wxListItemAttr
*wxListCtrl::OnGetItemAttr(long WXUNUSED_UNLESS_DEBUG(item
)) const
2240 wxASSERT_MSG( item
>= 0 && item
< GetItemCount(),
2241 _T("invalid item index in OnGetItemAttr()") );
2243 // no attributes by default
2247 void wxListCtrl::SetItemCount(long count
)
2249 wxASSERT_MSG( IsVirtual(), _T("this is for virtual controls only") );
2253 m_genericImpl
->SetItemCount(count
);
2259 // we need to temporarily disable the new item creation notification
2260 // procedure to speed things up
2261 // FIXME: Even this doesn't seem to help much...
2263 // FIXME: Find a more efficient way to do this.
2264 m_dbImpl
->MacClear();
2266 DataBrowserCallbacks callbacks
;
2267 DataBrowserItemNotificationUPP itemUPP
;
2268 GetDataBrowserCallbacks(m_dbImpl
->GetControlRef(), &callbacks
);
2269 itemUPP
= callbacks
.u
.v1
.itemNotificationCallback
;
2270 callbacks
.u
.v1
.itemNotificationCallback
= 0;
2271 m_dbImpl
->SetCallbacks(&callbacks
);
2272 ::AddDataBrowserItems(m_dbImpl
->GetControlRef(), kDataBrowserNoItem
,
2273 count
, NULL
, kDataBrowserItemNoProperty
);
2274 callbacks
.u
.v1
.itemNotificationCallback
= itemUPP
;
2275 m_dbImpl
->SetCallbacks(&callbacks
);
2280 void wxListCtrl::RefreshItem(long item
)
2284 m_genericImpl
->RefreshItem(item
);
2289 GetItemRect(item
, rect
);
2293 void wxListCtrl::RefreshItems(long itemFrom
, long itemTo
)
2297 m_genericImpl
->RefreshItems(itemFrom
, itemTo
);
2301 wxRect rect1
, rect2
;
2302 GetItemRect(itemFrom
, rect1
);
2303 GetItemRect(itemTo
, rect2
);
2305 wxRect rect
= rect1
;
2306 rect
.height
= rect2
.GetBottom() - rect1
.GetTop();
2311 void wxListCtrl::SetDropTarget( wxDropTarget
*dropTarget
)
2313 #if wxUSE_DRAG_AND_DROP
2315 m_genericImpl
->SetDropTarget( dropTarget
);
2318 wxWindow::SetDropTarget( dropTarget
);
2322 wxDropTarget
*wxListCtrl::GetDropTarget() const
2324 #if wxUSE_DRAG_AND_DROP
2326 return m_genericImpl
->GetDropTarget();
2329 return wxWindow::GetDropTarget();
2334 #if wxABI_VERSION >= 20801
2335 void wxListCtrl::SetFocus()
2339 m_genericImpl
->SetFocus();
2343 wxWindow::SetFocus();
2347 // wxMac internal data structures
2349 wxMacListCtrlItem::~wxMacListCtrlItem()
2353 void wxMacListCtrlItem::Notification(wxMacDataItemBrowserControl
*owner
,
2354 DataBrowserItemNotification message
,
2355 DataBrowserItemDataRef itemData
) const
2358 wxMacDataBrowserListCtrlControl
*lb
= wxDynamicCast(owner
, wxMacDataBrowserListCtrlControl
);
2360 // we want to depend on as little as possible to make sure tear-down of controls is safe
2361 if ( message
== kDataBrowserItemRemoved
)
2363 if ( lb
!= NULL
&& lb
->GetClientDataType() == wxClientData_Object
)
2365 delete (wxClientData
*) (m_data
);
2371 else if ( message
== kDataBrowserItemAdded
)
2373 // we don't issue events on adding, the item is not really stored in the list yet, so we
2374 // avoid asserts by gettting out now
2378 wxListCtrl
*list
= wxDynamicCast( owner
->GetPeer() , wxListCtrl
);
2381 bool trigger
= false;
2383 wxListEvent
event( wxEVT_COMMAND_LIST_ITEM_SELECTED
, list
->GetId() );
2384 bool isSingle
= (list
->GetWindowStyle() & wxLC_SINGLE_SEL
) != 0;
2386 event
.SetEventObject( list
);
2387 event
.m_itemIndex
= owner
->GetLineFromItem( this ) ;
2388 event
.m_item
.m_itemId
= event
.m_itemIndex
;
2389 list
->GetItem(event
.m_item
);
2393 case kDataBrowserItemDeselected
:
2394 event
.SetEventType(wxEVT_COMMAND_LIST_ITEM_DESELECTED
);
2396 trigger
= !lb
->IsSelectionSuppressed();
2399 case kDataBrowserItemSelected
:
2400 trigger
= !lb
->IsSelectionSuppressed();
2403 case kDataBrowserItemDoubleClicked
:
2404 event
.SetEventType( wxEVT_COMMAND_LIST_ITEM_ACTIVATED
);
2408 case kDataBrowserEditStarted
:
2409 // TODO : how to veto ?
2410 event
.SetEventType( wxEVT_COMMAND_LIST_BEGIN_LABEL_EDIT
) ;
2414 case kDataBrowserEditStopped
:
2415 // TODO probably trigger only upon the value store callback, because
2416 // here IIRC we cannot veto
2417 event
.SetEventType( wxEVT_COMMAND_LIST_END_LABEL_EDIT
) ;
2427 // direct notification is not always having the listbox GetSelection() having in synch with event
2428 wxPostEvent( list
->GetEventHandler(), event
);
2434 IMPLEMENT_DYNAMIC_CLASS(wxMacDataBrowserListCtrlControl
, wxMacDataItemBrowserControl
)
2436 wxMacDataBrowserListCtrlControl::wxMacDataBrowserListCtrlControl( wxWindow
*peer
, const wxPoint
& pos
, const wxSize
& size
, long style
)
2437 : wxMacDataItemBrowserControl( peer
, pos
, size
, style
)
2439 OSStatus err
= noErr
;
2440 m_clientDataItemsType
= wxClientData_None
;
2441 m_isVirtual
= false;
2444 if ( style
& wxLC_VIRTUAL
)
2447 DataBrowserSelectionFlags options
= kDataBrowserDragSelect
;
2448 if ( style
& wxLC_SINGLE_SEL
)
2450 options
|= kDataBrowserSelectOnlyOne
;
2454 options
|= kDataBrowserCmdTogglesSelection
;
2457 err
= SetSelectionFlags( options
);
2458 verify_noerr( err
);
2460 DataBrowserCustomCallbacks callbacks
;
2461 InitializeDataBrowserCustomCallbacks( &callbacks
, kDataBrowserLatestCustomCallbacks
);
2463 if ( gDataBrowserDrawItemUPP
== NULL
)
2464 gDataBrowserDrawItemUPP
= NewDataBrowserDrawItemUPP(DataBrowserDrawItemProc
);
2466 if ( gDataBrowserHitTestUPP
== NULL
)
2467 gDataBrowserHitTestUPP
= NewDataBrowserHitTestUPP(DataBrowserHitTestProc
);
2469 callbacks
.u
.v1
.drawItemCallback
= gDataBrowserDrawItemUPP
;
2470 callbacks
.u
.v1
.hitTestCallback
= gDataBrowserHitTestUPP
;
2472 SetDataBrowserCustomCallbacks( GetControlRef(), &callbacks
);
2474 if ( style
& wxLC_LIST
)
2476 InsertColumn(0, kDataBrowserIconAndTextType
, wxEmptyString
, -1, -1);
2477 verify_noerr( AutoSizeColumns() );
2480 if ( style
& wxLC_LIST
|| style
& wxLC_NO_HEADER
)
2481 verify_noerr( SetHeaderButtonHeight( 0 ) );
2484 SetSortProperty( kMinColumnId
- 1 );
2486 SetSortProperty( kMinColumnId
);
2488 m_sortOrder
= SortOrder_None
;
2490 if ( style
& wxLC_SORT_DESCENDING
)
2492 SetSortOrder( kDataBrowserOrderDecreasing
);
2494 else if ( style
& wxLC_SORT_ASCENDING
)
2496 SetSortOrder( kDataBrowserOrderIncreasing
);
2499 if ( style
& wxLC_VRULES
)
2501 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4
2502 verify_noerr( DataBrowserChangeAttributes(m_controlRef
, kDataBrowserAttributeListViewDrawColumnDividers
, kDataBrowserAttributeNone
) );
2506 verify_noerr( SetHiliteStyle(kDataBrowserTableViewFillHilite
) );
2507 verify_noerr( SetHasScrollBars( (style
& wxHSCROLL
) != 0 , true ) );
2510 pascal Boolean
wxMacDataBrowserListCtrlControl::DataBrowserEditTextProc(
2512 DataBrowserItemID itemID
,
2513 DataBrowserPropertyID property
,
2514 CFStringRef theString
,
2515 Rect
*maxEditTextRect
,
2516 Boolean
*shrinkToFit
)
2518 Boolean result
= false;
2519 wxMacDataBrowserListCtrlControl
* ctl
= wxDynamicCast(wxMacControl::GetReferenceFromNativeControl( browser
), wxMacDataBrowserListCtrlControl
);
2522 result
= ctl
->ConfirmEditText(itemID
, property
, theString
, maxEditTextRect
, shrinkToFit
);
2523 theString
= CFSTR("Hello!");
2528 bool wxMacDataBrowserListCtrlControl::ConfirmEditText(
2529 DataBrowserItemID itemID
,
2530 DataBrowserPropertyID property
,
2531 CFStringRef theString
,
2532 Rect
*maxEditTextRect
,
2533 Boolean
*shrinkToFit
)
2538 pascal void wxMacDataBrowserListCtrlControl::DataBrowserDrawItemProc(
2540 DataBrowserItemID itemID
,
2541 DataBrowserPropertyID property
,
2542 DataBrowserItemState itemState
,
2543 const Rect
*itemRect
,
2545 Boolean colorDevice
)
2547 wxMacDataBrowserListCtrlControl
* ctl
= wxDynamicCast(wxMacControl::GetReferenceFromNativeControl( browser
), wxMacDataBrowserListCtrlControl
);
2550 ctl
->DrawItem(itemID
, property
, itemState
, itemRect
, gdDepth
, colorDevice
);
2554 // routines needed for DrawItem
2559 kTextBoxHeight
= 14,
2560 kIconTextSpacingV
= 2,
2562 kContentHeight
= kIconHeight
+ kTextBoxHeight
+ kIconTextSpacingV
2565 static void calculateCGDrawingBounds(CGRect inItemRect
, CGRect
*outIconRect
, CGRect
*outTextRect
, bool hasIcon
= false)
2568 float iconH
, iconW
= 0;
2569 float padding
= kItemPadding
;
2572 iconH
= kIconHeight
;
2574 padding
= padding
*2;
2577 textBottom
= inItemRect
.origin
.y
;
2579 *outIconRect
= CGRectMake(inItemRect
.origin
.x
+ kItemPadding
,
2580 textBottom
+ kIconTextSpacingV
, kIconWidth
,
2583 *outTextRect
= CGRectMake(inItemRect
.origin
.x
+ padding
+ iconW
,
2584 textBottom
+ kIconTextSpacingV
, inItemRect
.size
.width
- padding
- iconW
,
2585 inItemRect
.size
.height
- kIconTextSpacingV
);
2588 void wxMacDataBrowserListCtrlControl::DrawItem(
2589 DataBrowserItemID itemID
,
2590 DataBrowserPropertyID property
,
2591 DataBrowserItemState itemState
,
2592 const Rect
*itemRect
,
2594 Boolean colorDevice
)
2597 wxFont font
= wxNullFont
;
2599 short listColumn
= property
- kMinColumnId
;
2601 wxListCtrl
* list
= wxDynamicCast( GetPeer() , wxListCtrl
);
2602 wxMacListCtrlItem
* lcItem
;
2603 wxColour color
= *wxBLACK
;
2604 wxColour bgColor
= wxNullColour
;
2606 if (listColumn
>= 0)
2610 lcItem
= (wxMacListCtrlItem
*) itemID
;
2611 if (lcItem
->HasColumnInfo(listColumn
)){
2612 wxListItem
* item
= lcItem
->GetColumnInfo(listColumn
);
2614 // we always use the 0 column to get font and text/background colors.
2615 if (lcItem
->HasColumnInfo(0))
2617 wxListItem
* firstItem
= lcItem
->GetColumnInfo(0);
2618 color
= firstItem
->GetTextColour();
2619 bgColor
= firstItem
->GetBackgroundColour();
2620 font
= firstItem
->GetFont();
2623 if (item
->GetMask() & wxLIST_MASK_TEXT
)
2624 text
= item
->GetText();
2625 if (item
->GetMask() & wxLIST_MASK_IMAGE
)
2626 imgIndex
= item
->GetImage();
2632 long itemNum
= (long)itemID
-1;
2633 if (itemNum
>= 0 && itemNum
< list
->GetItemCount())
2635 text
= list
->OnGetItemText( itemNum
, listColumn
);
2636 imgIndex
= list
->OnGetItemColumnImage( itemNum
, listColumn
);
2637 wxListItemAttr
* attrs
= list
->OnGetItemAttr( itemNum
);
2640 if (attrs
->HasBackgroundColour())
2641 bgColor
= attrs
->GetBackgroundColour();
2642 if (attrs
->HasTextColour())
2643 color
= attrs
->GetTextColour();
2644 if (attrs
->HasFont())
2645 font
= attrs
->GetFont();
2651 wxColour listBgColor
= list
->GetBackgroundColour();
2652 if (bgColor
== wxNullColour
)
2653 bgColor
= listBgColor
;
2655 wxFont listFont
= list
->GetFont();
2656 if (font
== wxNullFont
)
2659 wxMacCFStringHolder cfString
;
2660 cfString
.Assign( text
, wxLocale::GetSystemEncoding() );
2663 CGRect enclosingCGRect
, iconCGRect
, textCGRect
;
2665 ThemeDrawingState savedState
= NULL
;
2666 CGContextRef context
= (CGContextRef
)list
->MacGetDrawingContext();
2667 RGBColor labelColor
;
2669 labelColor
.green
= 0;
2670 labelColor
.blue
= 0;
2672 RGBColor backgroundColor
;
2673 backgroundColor
.red
= 255;
2674 backgroundColor
.green
= 255;
2675 backgroundColor
.blue
= 255;
2677 GetDataBrowserItemPartBounds(GetControlRef(), itemID
, property
, kDataBrowserPropertyEnclosingPart
,
2680 enclosingCGRect
= CGRectMake(enclosingRect
.left
,
2682 enclosingRect
.right
- enclosingRect
.left
,
2683 enclosingRect
.bottom
- enclosingRect
.top
);
2685 bool hasFocus
= (wxWindow::FindFocus() == list
);
2686 active
= IsControlActive(GetControlRef());
2688 // don't paint the background over the vertical rule line
2689 if ( list
->GetWindowStyleFlag() & wxLC_VRULES
)
2691 enclosingCGRect
.origin
.x
+= 1;
2692 enclosingCGRect
.size
.width
-= 1;
2694 if (itemState
== kDataBrowserItemIsSelected
)
2697 GetThemeDrawingState(&savedState
);
2699 if (active
&& hasFocus
)
2701 GetThemeBrushAsColor(kThemeBrushAlternatePrimaryHighlightColor
, 32, true, &backgroundColor
);
2702 GetThemeTextColor(kThemeTextColorWhite
, gdDepth
, colorDevice
, &labelColor
);
2706 GetThemeBrushAsColor(kThemeBrushSecondaryHighlightColor
, 32, true, &backgroundColor
);
2707 GetThemeTextColor(kThemeTextColorBlack
, gdDepth
, colorDevice
, &labelColor
);
2709 CGContextSaveGState(context
);
2711 CGContextSetRGBFillColor(context
, (float)backgroundColor
.red
/ (float)USHRT_MAX
,
2712 (float)backgroundColor
.green
/ (float)USHRT_MAX
,
2713 (float)backgroundColor
.blue
/ (float)USHRT_MAX
, 1.0);
2714 CGContextFillRect(context
, enclosingCGRect
);
2716 CGContextRestoreGState(context
);
2722 labelColor
= MAC_WXCOLORREF( color
.GetPixel() );
2723 else if (list
->GetTextColour().Ok())
2724 labelColor
= MAC_WXCOLORREF( list
->GetTextColour().GetPixel() );
2728 backgroundColor
= MAC_WXCOLORREF( bgColor
.GetPixel() );
2729 CGContextSaveGState(context
);
2731 CGContextSetRGBFillColor(context
, (float)backgroundColor
.red
/ (float)USHRT_MAX
,
2732 (float)backgroundColor
.green
/ (float)USHRT_MAX
,
2733 (float)backgroundColor
.blue
/ (float)USHRT_MAX
, 1.0);
2734 CGContextFillRect(context
, enclosingCGRect
);
2736 CGContextRestoreGState(context
);
2740 calculateCGDrawingBounds(enclosingCGRect
, &iconCGRect
, &textCGRect
, (imgIndex
!= -1) );
2744 wxImageList
* imageList
= list
->GetImageList(wxIMAGE_LIST_SMALL
);
2745 if (imageList
&& imageList
->GetImageCount() > 0){
2746 wxBitmap bmp
= imageList
->GetBitmap(imgIndex
);
2747 IconRef icon
= bmp
.GetBitmapData()->GetIconRef();
2749 CGContextSaveGState(context
);
2750 CGContextTranslateCTM(context
, 0,iconCGRect
.origin
.y
+ CGRectGetMaxY(iconCGRect
));
2751 CGContextScaleCTM(context
,1.0f
,-1.0f
);
2752 PlotIconRefInContext(context
, &iconCGRect
, kAlignNone
,
2753 active
? kTransformNone
: kTransformDisabled
, NULL
,
2754 kPlotIconRefNormalFlags
, icon
);
2756 CGContextRestoreGState(context
);
2760 HIThemeTextHorizontalFlush hFlush
= kHIThemeTextHorizontalFlushLeft
;
2761 UInt16 fontID
= kThemeViewsFont
;
2765 if (font
.GetFamily() != wxFONTFAMILY_DEFAULT
)
2766 fontID
= font
.MacGetThemeFontID();
2768 // FIXME: replace these with CG or ATSUI calls so we can remove this #ifndef.
2770 ::TextSize( (short)(font
.MacGetFontSize()) ) ;
2771 ::TextFace( font
.MacGetFontStyle() ) ;
2776 list
->GetColumn(listColumn
, item
);
2777 if (item
.GetMask() & wxLIST_MASK_FORMAT
)
2779 if (item
.GetAlign() == wxLIST_FORMAT_LEFT
)
2780 hFlush
= kHIThemeTextHorizontalFlushLeft
;
2781 else if (item
.GetAlign() == wxLIST_FORMAT_CENTER
)
2782 hFlush
= kHIThemeTextHorizontalFlushCenter
;
2783 else if (item
.GetAlign() == wxLIST_FORMAT_RIGHT
)
2785 hFlush
= kHIThemeTextHorizontalFlushRight
;
2786 textCGRect
.origin
.x
-= kItemPadding
; // give a little extra paddding
2790 HIThemeTextInfo info
;
2791 info
.version
= kHIThemeTextInfoVersionZero
;
2792 info
.state
= active
? kThemeStateActive
: kThemeStateInactive
;
2793 info
.fontID
= fontID
;
2794 info
.horizontalFlushness
= hFlush
;
2795 info
.verticalFlushness
= kHIThemeTextVerticalFlushCenter
;
2796 info
.options
= kHIThemeTextBoxOptionNone
;
2797 info
.truncationPosition
= kHIThemeTextTruncationEnd
;
2798 info
.truncationMaxLines
= 1;
2800 CGContextSaveGState(context
);
2801 CGContextSetRGBFillColor (context
, (float)labelColor
.red
/ (float)USHRT_MAX
,
2802 (float)labelColor
.green
/ (float)USHRT_MAX
,
2803 (float)labelColor
.blue
/ (float)USHRT_MAX
, 1.0);
2805 HIThemeDrawTextBox(cfString
, &textCGRect
, &info
, context
, kHIThemeOrientationNormal
);
2807 CGContextRestoreGState(context
);
2809 if (savedState
!= NULL
)
2810 SetThemeDrawingState(savedState
, true);
2813 OSStatus
wxMacDataBrowserListCtrlControl::GetSetItemData(DataBrowserItemID itemID
,
2814 DataBrowserPropertyID property
,
2815 DataBrowserItemDataRef itemData
,
2816 Boolean changeValue
)
2820 short listColumn
= property
- kMinColumnId
;
2822 OSStatus err
= errDataBrowserPropertyNotSupported
;
2823 wxListCtrl
* list
= wxDynamicCast( GetPeer() , wxListCtrl
);
2824 wxMacListCtrlItem
* lcItem
;
2826 if (listColumn
>= 0)
2830 lcItem
= (wxMacListCtrlItem
*) itemID
;
2831 if (lcItem
&& lcItem
->HasColumnInfo(listColumn
)){
2832 wxListItem
* item
= lcItem
->GetColumnInfo(listColumn
);
2833 if (item
->GetMask() & wxLIST_MASK_TEXT
)
2834 text
= item
->GetText();
2835 if (item
->GetMask() & wxLIST_MASK_IMAGE
)
2836 imgIndex
= item
->GetImage();
2841 long itemNum
= (long)itemID
-1;
2842 if (itemNum
>= 0 && itemNum
< list
->GetItemCount())
2844 text
= list
->OnGetItemText( itemNum
, listColumn
);
2845 imgIndex
= list
->OnGetItemColumnImage( itemNum
, listColumn
);
2854 case kDataBrowserItemIsEditableProperty
:
2855 if ( list
&& list
->HasFlag( wxLC_EDIT_LABELS
) )
2857 verify_noerr(SetDataBrowserItemDataBooleanValue( itemData
, true ));
2861 if ( property
>= kMinColumnId
)
2863 wxMacCFStringHolder
cfStr(text
);
2864 verify_noerr( ::SetDataBrowserItemDataText( itemData
, cfStr
) );
2868 if ( imgIndex
!= -1 )
2870 wxImageList
* imageList
= list
->GetImageList(wxIMAGE_LIST_SMALL
);
2871 if (imageList
&& imageList
->GetImageCount() > 0){
2872 wxBitmap bmp
= imageList
->GetBitmap(imgIndex
);
2873 IconRef icon
= bmp
.GetBitmapData()->GetIconRef();
2874 ::SetDataBrowserItemDataIcon(itemData
, icon
);
2888 if ( property
>= kMinColumnId
)
2890 short listColumn
= property
- kMinColumnId
;
2892 // TODO probably send the 'end edit' from here, as we
2893 // can then deal with the veto
2895 verify_noerr( GetDataBrowserItemDataText( itemData
, &sr
) ) ;
2896 wxMacCFStringHolder
cfStr(sr
) ;;
2898 list
->SetItem( (long)itemData
-1 , listColumn
, cfStr
.AsString() ) ;
2902 lcItem
->SetColumnTextValue( listColumn
, cfStr
.AsString() );
2912 void wxMacDataBrowserListCtrlControl::ItemNotification(DataBrowserItemID itemID
,
2913 DataBrowserItemNotification message
,
2914 DataBrowserItemDataRef itemData
)
2916 // we want to depend on as little as possible to make sure tear-down of controls is safe
2917 if ( message
== kDataBrowserItemRemoved
)
2919 // make sure MacDelete does the proper teardown.
2922 else if ( message
== kDataBrowserItemAdded
)
2924 // we don't issue events on adding, the item is not really stored in the list yet, so we
2925 // avoid asserts by getting out now
2929 wxListCtrl
*list
= wxDynamicCast( GetPeer() , wxListCtrl
);
2932 bool trigger
= false;
2934 wxListEvent
event( wxEVT_COMMAND_LIST_ITEM_SELECTED
, list
->GetId() );
2935 bool isSingle
= (list
->GetWindowStyle() & wxLC_SINGLE_SEL
) != 0;
2937 event
.SetEventObject( list
);
2938 if ( !list
->IsVirtual() )
2940 DataBrowserTableViewRowIndex result
= 0;
2941 verify_noerr( GetItemRow( itemID
, &result
) ) ;
2942 event
.m_itemIndex
= result
;
2946 event
.m_itemIndex
= (long)itemID
-1;
2948 event
.m_item
.m_itemId
= event
.m_itemIndex
;
2949 list
->GetItem(event
.m_item
);
2953 case kDataBrowserItemDeselected
:
2954 event
.SetEventType(wxEVT_COMMAND_LIST_ITEM_DESELECTED
);
2956 trigger
= !IsSelectionSuppressed();
2959 case kDataBrowserItemSelected
:
2960 trigger
= !IsSelectionSuppressed();
2964 case kDataBrowserItemDoubleClicked
:
2965 event
.SetEventType( wxEVT_COMMAND_LIST_ITEM_ACTIVATED
);
2969 case kDataBrowserEditStarted
:
2970 // TODO : how to veto ?
2971 event
.SetEventType( wxEVT_COMMAND_LIST_BEGIN_LABEL_EDIT
) ;
2975 case kDataBrowserEditStopped
:
2976 // TODO probably trigger only upon the value store callback, because
2977 // here IIRC we cannot veto
2978 event
.SetEventType( wxEVT_COMMAND_LIST_END_LABEL_EDIT
) ;
2988 // direct notification is not always having the listbox GetSelection() having in synch with event
2989 wxPostEvent( list
->GetEventHandler(), event
);
2994 Boolean
wxMacDataBrowserListCtrlControl::CompareItems(DataBrowserItemID itemOneID
,
2995 DataBrowserItemID itemTwoID
,
2996 DataBrowserPropertyID sortProperty
)
2999 bool retval
= false;
3001 wxString otherItemText
;
3003 long otherItemOrder
;
3005 int colId
= sortProperty
- kMinColumnId
;
3007 wxListCtrl
* list
= wxDynamicCast( GetPeer() , wxListCtrl
);
3009 DataBrowserSortOrder sort
;
3010 verify_noerr(GetSortOrder(&sort
));
3016 wxMacListCtrlItem
* item
= (wxMacListCtrlItem
*)itemOneID
;
3017 wxMacListCtrlItem
* otherItem
= (wxMacListCtrlItem
*)itemTwoID
;
3019 itemOrder
= item
->GetOrder();
3020 otherItemOrder
= item
->GetOrder();
3022 wxListCtrlCompare func
= list
->GetCompareFunc();
3027 if (item
&& item
->HasColumnInfo(0))
3028 item1
= item
->GetColumnInfo(0)->GetData();
3029 if (otherItem
&& otherItem
->HasColumnInfo(0))
3030 item2
= otherItem
->GetColumnInfo(0)->GetData();
3032 if (item1
> -1 && item2
> -1)
3034 int result
= func(item1
, item2
, list
->GetCompareFuncData());
3035 if (sort
== kDataBrowserOrderIncreasing
)
3042 // we can't use the native control's sorting abilities, so just
3044 return itemOrder
< otherItemOrder
;
3049 long itemNum
= (long)itemOneID
;
3050 long otherItemNum
= (long)itemTwoID
;
3052 // virtual listctrls don't support sorting
3053 return itemNum
< otherItemNum
;
3057 // fallback for undefined cases
3058 retval
= itemOneID
< itemTwoID
;
3064 wxMacDataBrowserListCtrlControl::~wxMacDataBrowserListCtrlControl()
3068 void wxMacDataBrowserListCtrlControl::MacSetColumnInfo( unsigned int row
, unsigned int column
, wxListItem
* item
)
3070 wxMacDataItem
* dataItem
= GetItemFromLine(row
);
3071 wxASSERT_MSG( dataItem
, _T("could not obtain wxMacDataItem for row in MacSetColumnInfo. Is row a valid wxListCtrl row?") );
3074 wxMacListCtrlItem
* listItem
= wx_static_cast(wxMacListCtrlItem
*,dataItem
);
3075 bool hasInfo
= listItem
->HasColumnInfo( column
);
3076 listItem
->SetColumnInfo( column
, item
);
3077 listItem
->SetOrder(row
);
3078 UpdateState(dataItem
, item
);
3080 wxListCtrl
* list
= wxDynamicCast( GetPeer() , wxListCtrl
);
3082 // NB: When this call was made before a control was completely shown, it would
3083 // update the item prematurely (i.e. no text would be listed) and, on show,
3084 // only the sorted column would be refreshed, meaning only first column text labels
3085 // would be shown. Making sure not to update items until the control is visible
3086 // seems to fix this issue.
3087 if (hasInfo
&& list
->IsShown())
3088 UpdateItem( wxMacDataBrowserRootContainer
, listItem
, kMinColumnId
+ column
);
3092 // apply changes that need to happen immediately, rather than when the
3093 // databrowser control fires a callback.
3094 void wxMacDataBrowserListCtrlControl::UpdateState(wxMacDataItem
* dataItem
, wxListItem
* listItem
)
3096 bool isSelected
= IsItemSelected( dataItem
);
3097 bool isSelectedState
= (listItem
->GetState() == wxLIST_STATE_SELECTED
);
3099 // toggle the selection state if wxListInfo state and actual state don't match.
3100 if ( isSelected
!= isSelectedState
)
3102 DataBrowserSetOption options
= kDataBrowserItemsAdd
;
3103 if (!isSelectedState
)
3104 options
= kDataBrowserItemsRemove
;
3105 SetSelectedItem(dataItem
, options
);
3107 // TODO: Set column width if item width > than current column width
3110 void wxMacDataBrowserListCtrlControl::MacGetColumnInfo( unsigned int row
, unsigned int column
, wxListItem
& item
)
3112 wxMacDataItem
* dataItem
= GetItemFromLine(row
);
3113 wxASSERT_MSG( dataItem
, _T("could not obtain wxMacDataItem in MacGetColumnInfo. Is row a valid wxListCtrl row?") );
3114 // CS should this guard against dataItem = 0 ? , as item is not a pointer if (item) is not appropriate
3117 wxMacListCtrlItem
* listItem
=wx_static_cast(wxMacListCtrlItem
*,dataItem
);
3119 if (!listItem
->HasColumnInfo( column
))
3122 wxListItem
* oldItem
= listItem
->GetColumnInfo( column
);
3126 long mask
= item
.GetMask();
3128 // by default, get everything for backwards compatibility
3131 if ( mask
& wxLIST_MASK_TEXT
)
3132 item
.SetText(oldItem
->GetText());
3133 if ( mask
& wxLIST_MASK_IMAGE
)
3134 item
.SetImage(oldItem
->GetImage());
3135 if ( mask
& wxLIST_MASK_DATA
)
3136 item
.SetData(oldItem
->GetData());
3137 if ( mask
& wxLIST_MASK_STATE
)
3138 item
.SetState(oldItem
->GetState());
3139 if ( mask
& wxLIST_MASK_WIDTH
)
3140 item
.SetWidth(oldItem
->GetWidth());
3141 if ( mask
& wxLIST_MASK_FORMAT
)
3142 item
.SetAlign(oldItem
->GetAlign());
3144 item
.SetTextColour(oldItem
->GetTextColour());
3145 item
.SetBackgroundColour(oldItem
->GetBackgroundColour());
3146 item
.SetFont(oldItem
->GetFont());
3151 void wxMacDataBrowserListCtrlControl::MacInsertItem( unsigned int n
, wxListItem
* item
)
3153 wxMacDataItemBrowserControl::MacInsert(n
, item
->GetText());
3154 MacSetColumnInfo(n
, 0, item
);
3157 wxMacDataItem
* wxMacDataBrowserListCtrlControl::CreateItem()
3159 return new wxMacListCtrlItem();
3162 wxMacListCtrlItem::wxMacListCtrlItem()
3164 m_rowItems
= wxListItemList();
3167 int wxMacListCtrlItem::GetColumnImageValue( unsigned int column
)
3169 if ( HasColumnInfo(column
) )
3170 return GetColumnInfo(column
)->GetImage();
3175 void wxMacListCtrlItem::SetColumnImageValue( unsigned int column
, int imageIndex
)
3177 if ( HasColumnInfo(column
) )
3178 GetColumnInfo(column
)->SetImage(imageIndex
);
3181 wxString
wxMacListCtrlItem::GetColumnTextValue( unsigned int column
)
3186 if ( HasColumnInfo(column
) )
3187 return GetColumnInfo(column
)->GetText();
3189 return wxEmptyString
;
3192 void wxMacListCtrlItem::SetColumnTextValue( unsigned int column
, const wxString
& text
)
3194 if ( HasColumnInfo(column
) )
3195 GetColumnInfo(column
)->SetText(text
);
3197 // for compatibility with superclass APIs
3202 wxListItem
* wxMacListCtrlItem::GetColumnInfo( unsigned int column
)
3204 wxASSERT_MSG( HasColumnInfo(column
), _T("invalid column index in wxMacListCtrlItem") );
3205 return m_rowItems
[column
];
3208 bool wxMacListCtrlItem::HasColumnInfo( unsigned int column
)
3210 return !(m_rowItems
.find( column
) == m_rowItems
.end());
3213 void wxMacListCtrlItem::SetColumnInfo( unsigned int column
, wxListItem
* item
)
3216 if ( !HasColumnInfo(column
) )
3218 wxListItem
* listItem
= new wxListItem(*item
);
3219 m_rowItems
[column
] = listItem
;
3223 wxListItem
* listItem
= GetColumnInfo( column
);
3224 long mask
= item
->GetMask();
3225 if (mask
& wxLIST_MASK_TEXT
)
3226 listItem
->SetText(item
->GetText());
3227 if (mask
& wxLIST_MASK_DATA
)
3228 listItem
->SetData(item
->GetData());
3229 if (mask
& wxLIST_MASK_IMAGE
)
3230 listItem
->SetImage(item
->GetImage());
3231 if (mask
& wxLIST_MASK_STATE
)
3232 listItem
->SetState(item
->GetState());
3233 if (mask
& wxLIST_MASK_FORMAT
)
3234 listItem
->SetAlign(item
->GetAlign());
3235 if (mask
& wxLIST_MASK_WIDTH
)
3236 listItem
->SetWidth(item
->GetWidth());
3238 if ( item
->HasAttributes() )
3240 if ( listItem
->HasAttributes() )
3241 listItem
->GetAttributes()->AssignFrom(*item
->GetAttributes());
3244 listItem
->SetTextColour(item
->GetTextColour());
3245 listItem
->SetBackgroundColour(item
->GetBackgroundColour());
3246 listItem
->SetFont(item
->GetFont());
3252 #endif // wxUSE_LISTCTRL