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
->HandleWindowEvent( 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
WXUNUSED(browser
),
263 DataBrowserItemID
WXUNUSED(itemID
),
264 DataBrowserPropertyID
WXUNUSED(property
),
265 const Rect
*WXUNUSED(theRect
),
266 const Rect
*WXUNUSED(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
->HandleWindowEvent( 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 HandleWindowEvent(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 HandleWindowEvent(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
;
776 wxVisualAttributes
wxListCtrl::GetClassDefaultAttributes(wxWindowVariant variant
)
778 wxVisualAttributes attr
;
780 attr
.colFg
= wxSystemSettings::GetColour( wxSYS_COLOUR_WINDOWTEXT
);
781 attr
.colBg
= wxSystemSettings::GetColour( wxSYS_COLOUR_LISTBOX
);
782 attr
.font
.MacCreateFromThemeFont(kThemeViewsFont
);
787 // ----------------------------------------------------------------------------
788 // set/get/change style
789 // ----------------------------------------------------------------------------
791 // Add or remove a single window style
792 void wxListCtrl::SetSingleStyle(long style
, bool add
)
794 long flag
= GetWindowStyleFlag();
796 // Get rid of conflicting styles
799 if ( style
& wxLC_MASK_TYPE
)
800 flag
= flag
& ~wxLC_MASK_TYPE
;
801 if ( style
& wxLC_MASK_ALIGN
)
802 flag
= flag
& ~wxLC_MASK_ALIGN
;
803 if ( style
& wxLC_MASK_SORT
)
804 flag
= flag
& ~wxLC_MASK_SORT
;
812 SetWindowStyleFlag(flag
);
815 // Set the whole window style
816 void wxListCtrl::SetWindowStyleFlag(long flag
)
818 if ( flag
!= m_windowStyle
)
820 m_windowStyle
= flag
;
824 m_genericImpl
->SetWindowStyleFlag(flag
);
831 void wxListCtrl::DoSetSize( int x
, int y
, int width
, int height
, int sizeFlags
)
833 wxControl::DoSetSize(x
, y
, width
, height
, sizeFlags
);
836 m_genericImpl
->SetSize(0, 0, width
, height
, sizeFlags
);
838 // determine if we need a horizontal scrollbar, and add it if so
842 for (int column
= 0; column
< GetColumnCount(); column
++)
844 totalWidth
+= m_dbImpl
->GetColumnWidth( column
);
847 if ( !(m_dbImpl
->GetFlags() & wxHSCROLL
) )
849 Boolean vertScrollBar
;
850 GetDataBrowserHasScrollBars( m_dbImpl
->GetControlRef(), NULL
, &vertScrollBar
);
851 if (totalWidth
> width
)
852 SetDataBrowserHasScrollBars( m_dbImpl
->GetControlRef(), true, vertScrollBar
);
854 SetDataBrowserHasScrollBars( m_dbImpl
->GetControlRef(), false, vertScrollBar
);
859 wxSize
wxListCtrl::DoGetBestSize() const
861 return wxWindow::DoGetBestSize();
864 bool wxListCtrl::SetFont(const wxFont
& font
)
867 rv
= wxControl::SetFont(font
);
869 rv
= m_genericImpl
->SetFont(font
);
873 bool wxListCtrl::SetForegroundColour(const wxColour
& colour
)
877 rv
= m_genericImpl
->SetForegroundColour(colour
);
879 SetTextColour(colour
);
883 bool wxListCtrl::SetBackgroundColour(const wxColour
& colour
)
887 rv
= m_genericImpl
->SetBackgroundColour(colour
);
893 wxColour
wxListCtrl::GetBackgroundColour()
896 return m_genericImpl
->GetBackgroundColour();
903 // ----------------------------------------------------------------------------
905 // ----------------------------------------------------------------------------
907 // Gets information about this column
908 bool wxListCtrl::GetColumn(int col
, wxListItem
& item
) const
911 return m_genericImpl
->GetColumn(col
, item
);
917 wxColumnList::compatibility_iterator node
= m_colsInfo
.Item( col
);
918 wxASSERT_MSG( node
, _T("invalid column index in wxMacListCtrlItem") );
919 wxListItem
* column
= node
->GetData();
921 long mask
= column
->GetMask();
922 if (mask
& wxLIST_MASK_TEXT
)
923 item
.SetText(column
->GetText());
924 if (mask
& wxLIST_MASK_DATA
)
925 item
.SetData(column
->GetData());
926 if (mask
& wxLIST_MASK_IMAGE
)
927 item
.SetImage(column
->GetImage());
928 if (mask
& wxLIST_MASK_STATE
)
929 item
.SetState(column
->GetState());
930 if (mask
& wxLIST_MASK_FORMAT
)
931 item
.SetAlign(column
->GetAlign());
932 if (mask
& wxLIST_MASK_WIDTH
)
933 item
.SetWidth(column
->GetWidth());
939 // Sets information about this column
940 bool wxListCtrl::SetColumn(int col
, wxListItem
& item
)
943 return m_genericImpl
->SetColumn(col
, item
);
947 long mask
= item
.GetMask();
948 if ( col
>= (int)m_colsInfo
.GetCount() )
950 wxListItem
* listItem
= new wxListItem(item
);
951 m_colsInfo
.Append( listItem
);
956 GetColumn( col
, listItem
);
958 if (mask
& wxLIST_MASK_TEXT
)
959 listItem
.SetText(item
.GetText());
960 if (mask
& wxLIST_MASK_DATA
)
961 listItem
.SetData(item
.GetData());
962 if (mask
& wxLIST_MASK_IMAGE
)
963 listItem
.SetImage(item
.GetImage());
964 if (mask
& wxLIST_MASK_STATE
)
965 listItem
.SetState(item
.GetState());
966 if (mask
& wxLIST_MASK_FORMAT
)
967 listItem
.SetAlign(item
.GetAlign());
968 if (mask
& wxLIST_MASK_WIDTH
)
969 listItem
.SetWidth(item
.GetWidth());
972 // change the appearance in the databrowser.
973 DataBrowserListViewHeaderDesc columnDesc
;
974 columnDesc
.version
=kDataBrowserListViewLatestHeaderDesc
;
975 verify_noerr( m_dbImpl
->GetHeaderDesc( kMinColumnId
+ col
, &columnDesc
) );
978 if (item.GetMask() & wxLIST_MASK_TEXT)
982 enc = GetFont().GetEncoding();
984 enc = wxLocale::GetSystemEncoding();
985 wxCFStringRef cfTitle;
986 cfTitle.Assign( item.GetText() , enc );
987 if(columnDesc.titleString)
988 CFRelease(columnDesc.titleString);
989 columnDesc.titleString = cfTitle;
993 if (item
.GetMask() & wxLIST_MASK_IMAGE
&& item
.GetImage() != -1 )
995 wxImageList
* imageList
= GetImageList(wxIMAGE_LIST_SMALL
);
996 if (imageList
&& imageList
->GetImageCount() > 0 )
998 wxBitmap bmp
= imageList
->GetBitmap( item
.GetImage() );
999 IconRef icon
= bmp
.GetIconRef();
1000 columnDesc
.btnContentInfo
.u
.iconRef
= icon
;
1001 columnDesc
.btnContentInfo
.contentType
= kControlContentIconRef
;
1005 verify_noerr( m_dbImpl
->SetHeaderDesc( kMinColumnId
+ col
, &columnDesc
) );
1011 int wxListCtrl::GetColumnCount() const
1014 return m_genericImpl
->GetColumnCount();
1019 m_dbImpl
->GetColumnCount(&count
);
1026 // Gets the column width
1027 int wxListCtrl::GetColumnWidth(int col
) const
1030 return m_genericImpl
->GetColumnWidth(col
);
1034 return m_dbImpl
->GetColumnWidth(col
);
1040 // Sets the column width
1041 bool wxListCtrl::SetColumnWidth(int col
, int width
)
1044 return m_genericImpl
->SetColumnWidth(col
, width
);
1048 int mywidth
= width
;
1049 if (width
== wxLIST_AUTOSIZE
|| width
== wxLIST_AUTOSIZE_USEHEADER
)
1054 for (int column
= 0; column
< GetColumnCount(); column
++)
1057 GetColumn(col
, colInfo
);
1059 colInfo
.SetWidth(width
);
1060 SetColumn(col
, colInfo
);
1062 m_dbImpl
->SetColumnWidth(col
, mywidth
);
1068 GetColumn(col
, colInfo
);
1070 colInfo
.SetWidth(width
);
1071 SetColumn(col
, colInfo
);
1072 m_dbImpl
->SetColumnWidth(col
, mywidth
);
1080 // Gets the number of items that can fit vertically in the
1081 // visible area of the list control (list or report view)
1082 // or the total number of items in the list control (icon
1083 // or small icon view)
1084 int wxListCtrl::GetCountPerPage() const
1087 return m_genericImpl
->GetCountPerPage();
1092 m_dbImpl
->GetDefaultRowHeight( &height
);
1094 return GetClientSize().y
/ height
;
1100 // Gets the edit control for editing labels.
1101 wxTextCtrl
* wxListCtrl::GetEditControl() const
1104 return m_genericImpl
->GetEditControl();
1109 // Gets information about the item
1110 bool wxListCtrl::GetItem(wxListItem
& info
) const
1113 return m_genericImpl
->GetItem(info
);
1119 if (info
.m_itemId
>= 0 && info
.m_itemId
< GetItemCount())
1121 m_dbImpl
->MacGetColumnInfo(info
.m_itemId
, info
.m_col
, info
);
1122 if (info
.GetMask() & wxLIST_MASK_STATE
)
1124 DataBrowserItemID id
= (DataBrowserItemID
)m_dbImpl
->GetItemFromLine(info
.m_itemId
);
1125 if (IsDataBrowserItemSelected( m_dbImpl
->GetControlRef(), id
))
1126 info
.SetState(info
.GetState() | wxLIST_STATE_SELECTED
);
1132 if (info
.m_itemId
>= 0 && info
.m_itemId
< GetItemCount())
1134 info
.SetText( OnGetItemText(info
.m_itemId
, info
.m_col
) );
1135 info
.SetImage( OnGetItemColumnImage(info
.m_itemId
, info
.m_col
) );
1136 if (info
.GetMask() & wxLIST_MASK_STATE
)
1138 if (IsDataBrowserItemSelected( m_dbImpl
->GetControlRef(), info
.m_itemId
+1 ))
1139 info
.SetState(info
.GetState() | wxLIST_STATE_SELECTED
);
1142 wxListItemAttr
* attrs
= OnGetItemAttr( info
.m_itemId
);
1145 info
.SetFont( attrs
->GetFont() );
1146 info
.SetBackgroundColour( attrs
->GetBackgroundColour() );
1147 info
.SetTextColour( attrs
->GetTextColour() );
1152 bool success
= true;
1156 // Sets information about the item
1157 bool wxListCtrl::SetItem(wxListItem
& info
)
1160 return m_genericImpl
->SetItem(info
);
1163 m_dbImpl
->MacSetColumnInfo( info
.m_itemId
, info
.m_col
, &info
);
1168 long wxListCtrl::SetItem(long index
, int col
, const wxString
& label
, int imageId
)
1171 return m_genericImpl
->SetItem(index
, col
, label
, imageId
);
1174 info
.m_text
= label
;
1175 info
.m_mask
= wxLIST_MASK_TEXT
;
1176 info
.m_itemId
= index
;
1180 info
.m_image
= imageId
;
1181 info
.m_mask
|= wxLIST_MASK_IMAGE
;
1183 return SetItem(info
);
1187 // Gets the item state
1188 int wxListCtrl::GetItemState(long item
, long stateMask
) const
1191 return m_genericImpl
->GetItemState(item
, stateMask
);
1195 if ( HasFlag(wxLC_VIRTUAL
) )
1197 if (stateMask
== wxLIST_STATE_SELECTED
)
1199 if (IsDataBrowserItemSelected( m_dbImpl
->GetControlRef(), item
+1 ))
1200 return wxLIST_STATE_SELECTED
;
1209 info
.m_mask
= wxLIST_MASK_STATE
;
1210 info
.m_stateMask
= stateMask
;
1211 info
.m_itemId
= item
;
1216 return info
.m_state
;
1223 // Sets the item state
1224 bool wxListCtrl::SetItemState(long item
, long state
, long stateMask
)
1227 return m_genericImpl
->SetItemState(item
, state
, stateMask
);
1231 DataBrowserSetOption option
= kDataBrowserItemsAdd
;
1232 if ( (stateMask
& wxLIST_STATE_SELECTED
) && state
== 0 )
1233 option
= kDataBrowserItemsRemove
;
1237 if ( HasFlag(wxLC_VIRTUAL
) )
1239 wxMacDataItemBrowserSelectionSuppressor
suppressor(m_dbImpl
);
1240 m_dbImpl
->SetSelectedAllItems(option
);
1244 for(int i
= 0; i
< GetItemCount();i
++)
1248 info
.m_mask
= wxLIST_MASK_STATE
;
1249 info
.m_stateMask
= stateMask
;
1250 info
.m_state
= state
;
1257 if ( HasFlag(wxLC_VIRTUAL
) )
1259 long itemID
= item
+1;
1260 bool isSelected
= IsDataBrowserItemSelected(m_dbImpl
->GetControlRef(), (DataBrowserItemID
)itemID
);
1261 bool isSelectedState
= (state
== wxLIST_STATE_SELECTED
);
1263 // toggle the selection state if wxListInfo state and actual state don't match.
1264 if ( (stateMask
& wxLIST_STATE_SELECTED
) && isSelected
!= isSelectedState
)
1266 SetDataBrowserSelectedItems(m_dbImpl
->GetControlRef(), 1, (DataBrowserItemID
*)&itemID
, option
);
1272 info
.m_itemId
= item
;
1273 info
.m_mask
= wxLIST_MASK_STATE
;
1274 info
.m_stateMask
= stateMask
;
1275 info
.m_state
= state
;
1276 return SetItem(info
);
1283 // Sets the item image
1284 bool wxListCtrl::SetItemImage(long item
, int image
, int WXUNUSED(selImage
))
1286 return SetItemColumnImage(item
, 0, image
);
1289 // Sets the item image
1290 bool wxListCtrl::SetItemColumnImage(long item
, long column
, int image
)
1293 return m_genericImpl
->SetItemColumnImage(item
, column
, image
);
1297 info
.m_mask
= wxLIST_MASK_IMAGE
;
1298 info
.m_image
= image
;
1299 info
.m_itemId
= item
;
1300 info
.m_col
= column
;
1302 return SetItem(info
);
1305 // Gets the item text
1306 wxString
wxListCtrl::GetItemText(long item
) const
1309 return m_genericImpl
->GetItemText(item
);
1313 info
.m_mask
= wxLIST_MASK_TEXT
;
1314 info
.m_itemId
= item
;
1317 return wxEmptyString
;
1321 // Sets the item text
1322 void wxListCtrl::SetItemText(long item
, const wxString
& str
)
1325 return m_genericImpl
->SetItemText(item
, str
);
1329 info
.m_mask
= wxLIST_MASK_TEXT
;
1330 info
.m_itemId
= item
;
1336 // Gets the item data
1337 long wxListCtrl::GetItemData(long item
) const
1340 return m_genericImpl
->GetItemData(item
);
1344 info
.m_mask
= wxLIST_MASK_DATA
;
1345 info
.m_itemId
= item
;
1352 // Sets the item data
1353 bool wxListCtrl::SetItemPtrData(long item
, wxUIntPtr data
)
1356 return m_genericImpl
->SetItemData(item
, data
);
1360 info
.m_mask
= wxLIST_MASK_DATA
;
1361 info
.m_itemId
= item
;
1364 return SetItem(info
);
1367 wxRect
wxListCtrl::GetViewRect() const
1369 wxASSERT_MSG( !HasFlag(wxLC_REPORT
| wxLC_LIST
),
1370 _T("wxListCtrl::GetViewRect() only works in icon mode") );
1373 return m_genericImpl
->GetViewRect();
1379 // Gets the item rectangle
1380 bool wxListCtrl::GetItemRect(long item
, wxRect
& rect
, int code
) const
1383 return m_genericImpl
->GetItemRect(item
, rect
, code
);
1388 DataBrowserItemID id
;
1389 DataBrowserPropertyID col
= kMinColumnId
;
1391 DataBrowserPropertyPart part
= kDataBrowserPropertyEnclosingPart
;
1392 if ( code
== wxLIST_RECT_LABEL
)
1393 part
= kDataBrowserPropertyTextPart
;
1394 else if ( code
== wxLIST_RECT_ICON
)
1395 part
= kDataBrowserPropertyIconPart
;
1397 if ( !(GetWindowStyleFlag() & wxLC_VIRTUAL
) )
1399 wxMacDataItem
* thisItem
= m_dbImpl
->GetItemFromLine(item
);
1400 id
= (DataBrowserItemID
) thisItem
;
1405 GetDataBrowserItemPartBounds( m_dbImpl
->GetControlRef(), id
, col
, part
, &bounds
);
1407 rect
.x
= bounds
.left
;
1408 rect
.y
= bounds
.top
;
1409 rect
.width
= bounds
.right
- bounds
.left
; //GetClientSize().x; // we need the width of the whole row, not just the item.
1410 rect
.height
= bounds
.bottom
- bounds
.top
;
1411 //fprintf("id = %d, bounds = %d, %d, %d, %d\n", id, rect.x, rect.y, rect.width, rect.height);
1416 // Gets the item position
1417 bool wxListCtrl::GetItemPosition(long item
, wxPoint
& pos
) const
1420 return m_genericImpl
->GetItemPosition(item
, pos
);
1422 bool success
= false;
1427 GetItemRect(item
, itemRect
);
1428 pos
= itemRect
.GetPosition();
1435 // Sets the item position.
1436 bool wxListCtrl::SetItemPosition(long item
, const wxPoint
& pos
)
1439 return m_genericImpl
->SetItemPosition(item
, pos
);
1444 // Gets the number of items in the list control
1445 int wxListCtrl::GetItemCount() const
1448 return m_genericImpl
->GetItemCount();
1451 return m_dbImpl
->MacGetCount();
1456 void wxListCtrl::SetItemSpacing( int spacing
, bool isSmall
)
1459 m_genericImpl
->SetItemSpacing(spacing
, isSmall
);
1462 wxSize
wxListCtrl::GetItemSpacing() const
1465 return m_genericImpl
->GetItemSpacing();
1467 return wxSize(0, 0);
1470 void wxListCtrl::SetItemTextColour( long item
, const wxColour
&col
)
1474 m_genericImpl
->SetItemTextColour(item
, col
);
1479 info
.m_itemId
= item
;
1480 info
.SetTextColour( col
);
1484 wxColour
wxListCtrl::GetItemTextColour( long item
) const
1487 return m_genericImpl
->GetItemTextColour(item
);
1493 return info
.GetTextColour();
1495 return wxNullColour
;
1498 void wxListCtrl::SetItemBackgroundColour( long item
, const wxColour
&col
)
1502 m_genericImpl
->SetItemBackgroundColour(item
, col
);
1507 info
.m_itemId
= item
;
1508 info
.SetBackgroundColour( col
);
1512 wxColour
wxListCtrl::GetItemBackgroundColour( long item
) const
1515 return m_genericImpl
->GetItemBackgroundColour(item
);
1521 return info
.GetBackgroundColour();
1523 return wxNullColour
;
1526 void wxListCtrl::SetItemFont( long item
, const wxFont
&f
)
1530 m_genericImpl
->SetItemFont(item
, f
);
1535 info
.m_itemId
= item
;
1540 wxFont
wxListCtrl::GetItemFont( long item
) const
1543 return m_genericImpl
->GetItemFont(item
);
1549 return info
.GetFont();
1555 // Gets the number of selected items in the list control
1556 int wxListCtrl::GetSelectedItemCount() const
1559 return m_genericImpl
->GetSelectedItemCount();
1562 return m_dbImpl
->GetSelectedItemCount(NULL
, true);
1567 // Gets the text colour of the listview
1568 wxColour
wxListCtrl::GetTextColour() const
1571 return m_genericImpl
->GetTextColour();
1573 // TODO: we need owner drawn list items to customize text color.
1577 return wxNullColour
;
1580 // Sets the text colour of the listview
1581 void wxListCtrl::SetTextColour(const wxColour
& col
)
1585 m_genericImpl
->SetTextColour(col
);
1593 // Gets the index of the topmost visible item when in
1594 // list or report view
1595 long wxListCtrl::GetTopItem() const
1598 return m_genericImpl
->GetTopItem();
1603 long item
= HitTest( wxPoint(1, 1), flags
);
1604 if (flags
== wxLIST_HITTEST_ONITEM
)
1611 // Searches for an item, starting from 'item'.
1612 // 'geometry' is one of
1613 // wxLIST_NEXT_ABOVE/ALL/BELOW/LEFT/RIGHT.
1614 // 'state' is a state bit flag, one or more of
1615 // wxLIST_STATE_DROPHILITED/FOCUSED/SELECTED/CUT.
1616 // item can be -1 to find the first item that matches the
1618 // Returns the item or -1 if unsuccessful.
1619 long wxListCtrl::GetNextItem(long item
, int geom
, int state
) const
1622 return m_genericImpl
->GetNextItem(item
, geom
, state
);
1624 // TODO: implement all geometry and state options?
1627 if ( geom
== wxLIST_NEXT_ALL
|| geom
== wxLIST_NEXT_BELOW
)
1629 long count
= m_dbImpl
->MacGetCount() ;
1630 for ( long line
= item
+ 1 ; line
< count
; line
++ )
1632 DataBrowserItemID id
= line
+ 1;
1634 id
= (DataBrowserItemID
)m_dbImpl
->GetItemFromLine(line
);
1636 if ( (state
== wxLIST_STATE_DONTCARE
) )
1639 if ( (state
& wxLIST_STATE_SELECTED
) && IsDataBrowserItemSelected(m_dbImpl
->GetControlRef(), id
) )
1644 if ( geom
== wxLIST_NEXT_ABOVE
)
1648 item2
= m_dbImpl
->MacGetCount();
1650 for ( long line
= item2
- 1 ; line
>= 0; line
-- )
1652 DataBrowserItemID id
= line
+ 1;
1654 id
= (DataBrowserItemID
)m_dbImpl
->GetItemFromLine(line
);
1656 if ( (state
== wxLIST_STATE_DONTCARE
) )
1659 if ( (state
& wxLIST_STATE_SELECTED
) && IsDataBrowserItemSelected(m_dbImpl
->GetControlRef(), id
) )
1669 wxImageList
*wxListCtrl::GetImageList(int which
) const
1672 return m_genericImpl
->GetImageList(which
);
1674 if ( which
== wxIMAGE_LIST_NORMAL
)
1676 return m_imageListNormal
;
1678 else if ( which
== wxIMAGE_LIST_SMALL
)
1680 return m_imageListSmall
;
1682 else if ( which
== wxIMAGE_LIST_STATE
)
1684 return m_imageListState
;
1689 void wxListCtrl::SetImageList(wxImageList
*imageList
, int which
)
1693 m_genericImpl
->SetImageList(imageList
, which
);
1697 if ( which
== wxIMAGE_LIST_NORMAL
)
1699 if (m_ownsImageListNormal
) delete m_imageListNormal
;
1700 m_imageListNormal
= imageList
;
1701 m_ownsImageListNormal
= false;
1703 else if ( which
== wxIMAGE_LIST_SMALL
)
1705 if (m_ownsImageListSmall
) delete m_imageListSmall
;
1706 m_imageListSmall
= imageList
;
1707 m_ownsImageListSmall
= false;
1709 else if ( which
== wxIMAGE_LIST_STATE
)
1711 if (m_ownsImageListState
) delete m_imageListState
;
1712 m_imageListState
= imageList
;
1713 m_ownsImageListState
= false;
1717 void wxListCtrl::AssignImageList(wxImageList
*imageList
, int which
)
1721 m_genericImpl
->AssignImageList(imageList
, which
);
1725 SetImageList(imageList
, which
);
1726 if ( which
== wxIMAGE_LIST_NORMAL
)
1727 m_ownsImageListNormal
= true;
1728 else if ( which
== wxIMAGE_LIST_SMALL
)
1729 m_ownsImageListSmall
= true;
1730 else if ( which
== wxIMAGE_LIST_STATE
)
1731 m_ownsImageListState
= true;
1734 // ----------------------------------------------------------------------------
1736 // ----------------------------------------------------------------------------
1738 // Arranges the items
1739 bool wxListCtrl::Arrange(int flag
)
1742 return m_genericImpl
->Arrange(flag
);
1747 bool wxListCtrl::DeleteItem(long item
)
1750 return m_genericImpl
->DeleteItem(item
);
1754 m_dbImpl
->MacDelete(item
);
1755 wxListEvent
event( wxEVT_COMMAND_LIST_DELETE_ITEM
, GetId() );
1756 event
.SetEventObject( this );
1757 event
.m_itemIndex
= item
;
1758 HandleWindowEvent( event
);
1764 // Deletes all items
1765 bool wxListCtrl::DeleteAllItems()
1768 return m_genericImpl
->DeleteAllItems();
1772 m_dbImpl
->MacClear();
1773 wxListEvent
event( wxEVT_COMMAND_LIST_DELETE_ALL_ITEMS
, GetId() );
1774 event
.SetEventObject( this );
1775 HandleWindowEvent( event
);
1780 // Deletes all items
1781 bool wxListCtrl::DeleteAllColumns()
1784 return m_genericImpl
->DeleteAllColumns();
1789 m_dbImpl
->GetColumnCount(&cols
);
1790 for (UInt32 col
= 0; col
< cols
; col
++)
1800 bool wxListCtrl::DeleteColumn(int col
)
1803 return m_genericImpl
->DeleteColumn(col
);
1807 OSStatus err
= m_dbImpl
->RemoveColumn(col
);
1808 return err
== noErr
;
1814 // Clears items, and columns if there are any.
1815 void wxListCtrl::ClearAll()
1819 m_genericImpl
->ClearAll();
1830 wxTextCtrl
* wxListCtrl::EditLabel(long item
, wxClassInfo
* textControlClass
)
1833 return m_genericImpl
->EditLabel(item
, textControlClass
);
1837 wxCHECK_MSG( (item
>= 0) && ((long)item
< GetItemCount()), NULL
,
1838 wxT("wrong index in wxListCtrl::EditLabel()") );
1840 wxASSERT_MSG( textControlClass
->IsKindOf(CLASSINFO(wxTextCtrl
)),
1841 wxT("EditLabel() needs a text control") );
1843 wxListEvent
le( wxEVT_COMMAND_LIST_BEGIN_LABEL_EDIT
, GetParent()->GetId() );
1844 le
.SetEventObject( this );
1845 le
.m_itemIndex
= item
;
1847 GetItem( le
.m_item
);
1849 if ( GetParent()->HandleWindowEvent( le
) && !le
.IsAllowed() )
1851 // vetoed by user code
1855 wxTextCtrl
* const text
= (wxTextCtrl
*)textControlClass
->CreateObject();
1856 m_textctrlWrapper
= new wxListCtrlTextCtrlWrapper(this, text
, item
);
1857 return m_textctrlWrapper
->GetText();
1862 // End label editing, optionally cancelling the edit
1863 bool wxListCtrl::EndEditLabel(bool WXUNUSED(cancel
))
1865 // TODO: generic impl. doesn't have this method - is it needed for us?
1867 return true; // m_genericImpl->EndEditLabel(cancel);
1870 verify_noerr( SetDataBrowserEditItem(m_dbImpl
->GetControlRef(), kDataBrowserNoItem
, kMinColumnId
) );
1874 // Ensures this item is visible
1875 bool wxListCtrl::EnsureVisible(long item
)
1878 return m_genericImpl
->EnsureVisible(item
);
1882 wxMacDataItem
* dataItem
= m_dbImpl
->GetItemFromLine(item
);
1883 m_dbImpl
->RevealItem(dataItem
, kDataBrowserRevealWithoutSelecting
);
1889 // Find an item whose label matches this string, starting from the item after 'start'
1890 // or the beginning if 'start' is -1.
1891 long wxListCtrl::FindItem(long start
, const wxString
& str
, bool partial
)
1894 return m_genericImpl
->FindItem(start
, str
, partial
);
1896 wxString str_upper
= str
.Upper();
1901 long count
= GetItemCount();
1905 wxString line_upper
= GetItemText(idx
).Upper();
1908 if (line_upper
== str_upper
)
1913 if (line_upper
.find(str_upper
) == 0)
1923 // Find an item whose data matches this data, starting from the item after 'start'
1924 // or the beginning if 'start' is -1.
1925 long wxListCtrl::FindItem(long start
, long data
)
1928 return m_genericImpl
->FindItem(start
, data
);
1933 long count
= GetItemCount();
1937 if (GetItemData(idx
) == data
)
1945 // Find an item nearest this position in the specified direction, starting from
1946 // the item after 'start' or the beginning if 'start' is -1.
1947 long wxListCtrl::FindItem(long start
, const wxPoint
& pt
, int direction
)
1950 return m_genericImpl
->FindItem(start
, pt
, direction
);
1954 // Determines which item (if any) is at the specified point,
1955 // giving details in 'flags' (see wxLIST_HITTEST_... flags above)
1957 wxListCtrl::HitTest(const wxPoint
& point
, int& flags
, long *ptrSubItem
) const
1960 return m_genericImpl
->HitTest(point
, flags
, ptrSubItem
);
1962 flags
= wxLIST_HITTEST_NOWHERE
;
1965 int colHeaderHeight
= 22; // TODO: Find a way to get this value from the db control?
1966 UInt16 rowHeight
= 0;
1967 m_dbImpl
->GetDefaultRowHeight(&rowHeight
);
1970 // get the actual row by taking scroll position into account
1971 UInt32 offsetX
, offsetY
;
1972 m_dbImpl
->GetScrollPosition( &offsetY
, &offsetX
);
1975 if ( !(GetWindowStyleFlag() & wxLC_NO_HEADER
) )
1976 y
-= colHeaderHeight
;
1981 int row
= y
/ rowHeight
;
1982 DataBrowserItemID id
;
1983 m_dbImpl
->GetItemID( (DataBrowserTableViewRowIndex
) row
, &id
);
1985 // TODO: Use GetDataBrowserItemPartBounds to return if we are in icon or label
1986 if ( !(GetWindowStyleFlag() & wxLC_VIRTUAL
) )
1988 wxMacListCtrlItem
* lcItem
;
1989 lcItem
= (wxMacListCtrlItem
*) id
;
1992 flags
= wxLIST_HITTEST_ONITEM
;
1998 if (row
< GetItemCount() )
2000 flags
= wxLIST_HITTEST_ONITEM
;
2009 int wxListCtrl::GetScrollPos(int orient
) const
2012 return m_genericImpl
->GetScrollPos(orient
);
2016 UInt32 offsetX
, offsetY
;
2017 m_dbImpl
->GetScrollPosition( &offsetY
, &offsetX
);
2018 if ( orient
== wxHORIZONTAL
)
2027 // Inserts an item, returning the index of the new item if successful,
2029 long wxListCtrl::InsertItem(wxListItem
& info
)
2031 wxASSERT_MSG( !IsVirtual(), _T("can't be used with virtual controls") );
2034 return m_genericImpl
->InsertItem(info
);
2036 if (m_dbImpl
&& !IsVirtual())
2038 int count
= GetItemCount();
2040 if (info
.m_itemId
> count
)
2041 info
.m_itemId
= count
;
2043 m_dbImpl
->MacInsertItem(info
.m_itemId
, &info
);
2045 wxListEvent
event( wxEVT_COMMAND_LIST_INSERT_ITEM
, GetId() );
2046 event
.SetEventObject( this );
2047 event
.m_itemIndex
= info
.m_itemId
;
2048 HandleWindowEvent( event
);
2049 return info
.m_itemId
;
2054 long wxListCtrl::InsertItem(long index
, const wxString
& label
)
2057 return m_genericImpl
->InsertItem(index
, label
);
2060 info
.m_text
= label
;
2061 info
.m_mask
= wxLIST_MASK_TEXT
;
2062 info
.m_itemId
= index
;
2063 return InsertItem(info
);
2066 // Inserts an image item
2067 long wxListCtrl::InsertItem(long index
, int imageIndex
)
2070 return m_genericImpl
->InsertItem(index
, imageIndex
);
2073 info
.m_image
= imageIndex
;
2074 info
.m_mask
= wxLIST_MASK_IMAGE
;
2075 info
.m_itemId
= index
;
2076 return InsertItem(info
);
2079 // Inserts an image/string item
2080 long wxListCtrl::InsertItem(long index
, const wxString
& label
, int imageIndex
)
2083 return m_genericImpl
->InsertItem(index
, label
, imageIndex
);
2086 info
.m_image
= imageIndex
;
2087 info
.m_text
= label
;
2088 info
.m_mask
= wxLIST_MASK_IMAGE
| wxLIST_MASK_TEXT
;
2089 info
.m_itemId
= index
;
2090 return InsertItem(info
);
2093 // For list view mode (only), inserts a column.
2094 long wxListCtrl::InsertColumn(long col
, wxListItem
& item
)
2097 return m_genericImpl
->InsertColumn(col
, item
);
2101 int width
= item
.GetWidth();
2102 if ( !(item
.GetMask() & wxLIST_MASK_WIDTH
) )
2105 DataBrowserPropertyType type
= kDataBrowserCustomType
; //kDataBrowserTextType;
2106 wxImageList
* imageList
= GetImageList(wxIMAGE_LIST_SMALL
);
2107 if (imageList
&& imageList
->GetImageCount() > 0)
2109 wxBitmap bmp
= imageList
->GetBitmap(0);
2111 // type = kDataBrowserIconAndTextType;
2114 SInt16 just
= teFlushDefault
;
2115 if (item
.GetMask() & wxLIST_MASK_FORMAT
)
2117 if (item
.GetAlign() == wxLIST_FORMAT_LEFT
)
2119 else if (item
.GetAlign() == wxLIST_FORMAT_CENTER
)
2121 else if (item
.GetAlign() == wxLIST_FORMAT_RIGHT
)
2122 just
= teFlushRight
;
2124 m_dbImpl
->InsertColumn(col
, type
, item
.GetText(), just
, width
);
2125 SetColumn(col
, item
);
2127 // set/remove options based on the wxListCtrl type.
2128 DataBrowserTableViewColumnID id
;
2129 m_dbImpl
->GetColumnIDFromIndex(col
, &id
);
2130 DataBrowserPropertyFlags flags
;
2131 verify_noerr(m_dbImpl
->GetPropertyFlags(id
, &flags
));
2132 if (GetWindowStyleFlag() & wxLC_EDIT_LABELS
)
2133 flags
|= kDataBrowserPropertyIsEditable
;
2135 if (GetWindowStyleFlag() & wxLC_VIRTUAL
){
2136 flags
&= ~kDataBrowserListViewSortableColumn
;
2138 verify_noerr(m_dbImpl
->SetPropertyFlags(id
, flags
));
2144 long wxListCtrl::InsertColumn(long col
,
2145 const wxString
& heading
,
2150 return m_genericImpl
->InsertColumn(col
, heading
, format
, width
);
2153 item
.m_mask
= wxLIST_MASK_TEXT
| wxLIST_MASK_FORMAT
;
2154 item
.m_text
= heading
;
2157 item
.m_mask
|= wxLIST_MASK_WIDTH
;
2158 item
.m_width
= width
;
2160 item
.m_format
= format
;
2162 return InsertColumn(col
, item
);
2165 // scroll the control by the given number of pixels (exception: in list view,
2166 // dx is interpreted as number of columns)
2167 bool wxListCtrl::ScrollList(int dx
, int dy
)
2170 return m_genericImpl
->ScrollList(dx
, dy
);
2174 m_dbImpl
->SetScrollPosition(dx
, dy
);
2180 bool wxListCtrl::SortItems(wxListCtrlCompare fn
, long data
)
2183 return m_genericImpl
->SortItems(fn
, data
);
2188 m_compareFuncData
= data
;
2189 SortDataBrowserContainer( m_dbImpl
->GetControlRef(), kDataBrowserNoItem
, true);
2191 // we need to do this after each call, else we get a crash from wxPython when
2192 // SortItems is called the second time.
2193 m_compareFunc
= NULL
;
2194 m_compareFuncData
= 0;
2200 void wxListCtrl::OnRenameTimer()
2202 wxCHECK_RET( HasCurrent(), wxT("unexpected rename timer") );
2204 EditLabel( m_current
);
2207 bool wxListCtrl::OnRenameAccept(long itemEdit
, const wxString
& value
)
2209 wxListEvent
le( wxEVT_COMMAND_LIST_END_LABEL_EDIT
, GetId() );
2210 le
.SetEventObject( this );
2211 le
.m_itemIndex
= itemEdit
;
2213 GetItem( le
.m_item
);
2214 le
.m_item
.m_text
= value
;
2215 return !HandleWindowEvent( le
) ||
2219 void wxListCtrl::OnRenameCancelled(long itemEdit
)
2221 // let owner know that the edit was cancelled
2222 wxListEvent
le( wxEVT_COMMAND_LIST_END_LABEL_EDIT
, GetParent()->GetId() );
2224 le
.SetEditCanceled(true);
2226 le
.SetEventObject( this );
2227 le
.m_itemIndex
= itemEdit
;
2229 GetItem( le
.m_item
);
2230 HandleWindowEvent( le
);
2233 // ----------------------------------------------------------------------------
2234 // virtual list controls
2235 // ----------------------------------------------------------------------------
2237 wxString
wxListCtrl::OnGetItemText(long WXUNUSED(item
), long WXUNUSED(col
)) const
2239 // this is a pure virtual function, in fact - which is not really pure
2240 // because the controls which are not virtual don't need to implement it
2241 wxFAIL_MSG( _T("wxListCtrl::OnGetItemText not supposed to be called") );
2243 return wxEmptyString
;
2246 int wxListCtrl::OnGetItemImage(long WXUNUSED(item
)) const
2248 wxCHECK_MSG(!GetImageList(wxIMAGE_LIST_SMALL
),
2250 wxT("List control has an image list, OnGetItemImage or OnGetItemColumnImage should be overridden."));
2254 int wxListCtrl::OnGetItemColumnImage(long item
, long column
) const
2257 return OnGetItemImage(item
);
2262 wxListItemAttr
*wxListCtrl::OnGetItemAttr(long WXUNUSED_UNLESS_DEBUG(item
)) const
2264 wxASSERT_MSG( item
>= 0 && item
< GetItemCount(),
2265 _T("invalid item index in OnGetItemAttr()") );
2267 // no attributes by default
2271 void wxListCtrl::SetItemCount(long count
)
2273 wxASSERT_MSG( IsVirtual(), _T("this is for virtual controls only") );
2277 m_genericImpl
->SetItemCount(count
);
2283 // we need to temporarily disable the new item creation notification
2284 // procedure to speed things up
2285 // FIXME: Even this doesn't seem to help much...
2287 // FIXME: Find a more efficient way to do this.
2288 m_dbImpl
->MacClear();
2290 DataBrowserCallbacks callbacks
;
2291 DataBrowserItemNotificationUPP itemUPP
;
2292 GetDataBrowserCallbacks(m_dbImpl
->GetControlRef(), &callbacks
);
2293 itemUPP
= callbacks
.u
.v1
.itemNotificationCallback
;
2294 callbacks
.u
.v1
.itemNotificationCallback
= 0;
2295 m_dbImpl
->SetCallbacks(&callbacks
);
2296 ::AddDataBrowserItems(m_dbImpl
->GetControlRef(), kDataBrowserNoItem
,
2297 count
, NULL
, kDataBrowserItemNoProperty
);
2298 callbacks
.u
.v1
.itemNotificationCallback
= itemUPP
;
2299 m_dbImpl
->SetCallbacks(&callbacks
);
2304 void wxListCtrl::RefreshItem(long item
)
2308 m_genericImpl
->RefreshItem(item
);
2314 DataBrowserItemID id
;
2318 wxMacDataItem
* thisItem
= m_dbImpl
->GetItemFromLine(item
);
2319 id
= (DataBrowserItemID
) thisItem
;
2324 m_dbImpl
->wxMacDataBrowserControl::UpdateItems
2328 kDataBrowserItemNoProperty
, // preSortProperty
2329 kDataBrowserNoItem
// update all columns
2334 void wxListCtrl::RefreshItems(long itemFrom
, long itemTo
)
2338 m_genericImpl
->RefreshItems(itemFrom
, itemTo
);
2344 const long count
= itemTo
- itemFrom
+ 1;
2345 DataBrowserItemID
*ids
= new DataBrowserItemID
[count
];
2349 for ( long i
= 0; i
< count
; i
++ )
2351 wxMacDataItem
* thisItem
= m_dbImpl
->GetItemFromLine(itemFrom
+i
);
2352 ids
[i
] = (DataBrowserItemID
) thisItem
;
2357 for ( long i
= 0; i
< count
; i
++ )
2358 ids
[i
] = itemFrom
+i
+1;
2361 m_dbImpl
->wxMacDataBrowserControl::UpdateItems
2365 kDataBrowserItemNoProperty
, // preSortProperty
2366 kDataBrowserNoItem
// update all columns
2373 void wxListCtrl::SetDropTarget( wxDropTarget
*dropTarget
)
2375 #if wxUSE_DRAG_AND_DROP
2377 m_genericImpl
->SetDropTarget( dropTarget
);
2380 wxWindow::SetDropTarget( dropTarget
);
2384 wxDropTarget
*wxListCtrl::GetDropTarget() const
2386 #if wxUSE_DRAG_AND_DROP
2388 return m_genericImpl
->GetDropTarget();
2391 return wxWindow::GetDropTarget();
2396 #if wxABI_VERSION >= 20801
2397 void wxListCtrl::SetFocus()
2401 m_genericImpl
->SetFocus();
2405 wxWindow::SetFocus();
2409 // wxMac internal data structures
2411 wxMacListCtrlItem::~wxMacListCtrlItem()
2415 void wxMacListCtrlItem::Notification(wxMacDataItemBrowserControl
*owner
,
2416 DataBrowserItemNotification message
,
2417 DataBrowserItemDataRef
WXUNUSED(itemData
) ) const
2420 wxMacDataBrowserListCtrlControl
*lb
= wxDynamicCast(owner
, wxMacDataBrowserListCtrlControl
);
2422 // we want to depend on as little as possible to make sure tear-down of controls is safe
2423 if ( message
== kDataBrowserItemRemoved
)
2425 if ( lb
!= NULL
&& lb
->GetClientDataType() == wxClientData_Object
)
2427 delete (wxClientData
*) (m_data
);
2433 else if ( message
== kDataBrowserItemAdded
)
2435 // we don't issue events on adding, the item is not really stored in the list yet, so we
2436 // avoid asserts by gettting out now
2440 wxListCtrl
*list
= wxDynamicCast( owner
->GetPeer() , wxListCtrl
);
2443 bool trigger
= false;
2445 wxListEvent
event( wxEVT_COMMAND_LIST_ITEM_SELECTED
, list
->GetId() );
2446 bool isSingle
= (list
->GetWindowStyle() & wxLC_SINGLE_SEL
) != 0;
2448 event
.SetEventObject( list
);
2449 event
.m_itemIndex
= owner
->GetLineFromItem( this ) ;
2450 event
.m_item
.m_itemId
= event
.m_itemIndex
;
2451 list
->GetItem(event
.m_item
);
2455 case kDataBrowserItemDeselected
:
2456 event
.SetEventType(wxEVT_COMMAND_LIST_ITEM_DESELECTED
);
2458 trigger
= !lb
->IsSelectionSuppressed();
2461 case kDataBrowserItemSelected
:
2462 trigger
= !lb
->IsSelectionSuppressed();
2465 case kDataBrowserItemDoubleClicked
:
2466 event
.SetEventType( wxEVT_COMMAND_LIST_ITEM_ACTIVATED
);
2470 case kDataBrowserEditStarted
:
2471 // TODO : how to veto ?
2472 event
.SetEventType( wxEVT_COMMAND_LIST_BEGIN_LABEL_EDIT
) ;
2476 case kDataBrowserEditStopped
:
2477 // TODO probably trigger only upon the value store callback, because
2478 // here IIRC we cannot veto
2479 event
.SetEventType( wxEVT_COMMAND_LIST_END_LABEL_EDIT
) ;
2489 // direct notification is not always having the listbox GetSelection() having in synch with event
2490 wxPostEvent( list
->GetEventHandler(), event
);
2496 IMPLEMENT_DYNAMIC_CLASS(wxMacDataBrowserListCtrlControl
, wxMacDataItemBrowserControl
)
2498 wxMacDataBrowserListCtrlControl::wxMacDataBrowserListCtrlControl( wxWindow
*peer
, const wxPoint
& pos
, const wxSize
& size
, long style
)
2499 : wxMacDataItemBrowserControl( peer
, pos
, size
, style
)
2501 OSStatus err
= noErr
;
2502 m_clientDataItemsType
= wxClientData_None
;
2503 m_isVirtual
= false;
2506 if ( style
& wxLC_VIRTUAL
)
2509 DataBrowserSelectionFlags options
= kDataBrowserDragSelect
;
2510 if ( style
& wxLC_SINGLE_SEL
)
2512 options
|= kDataBrowserSelectOnlyOne
;
2516 options
|= kDataBrowserCmdTogglesSelection
;
2519 err
= SetSelectionFlags( options
);
2520 verify_noerr( err
);
2522 DataBrowserCustomCallbacks callbacks
;
2523 InitializeDataBrowserCustomCallbacks( &callbacks
, kDataBrowserLatestCustomCallbacks
);
2525 if ( gDataBrowserDrawItemUPP
== NULL
)
2526 gDataBrowserDrawItemUPP
= NewDataBrowserDrawItemUPP(DataBrowserDrawItemProc
);
2528 if ( gDataBrowserHitTestUPP
== NULL
)
2529 gDataBrowserHitTestUPP
= NewDataBrowserHitTestUPP(DataBrowserHitTestProc
);
2531 callbacks
.u
.v1
.drawItemCallback
= gDataBrowserDrawItemUPP
;
2532 callbacks
.u
.v1
.hitTestCallback
= gDataBrowserHitTestUPP
;
2534 SetDataBrowserCustomCallbacks( GetControlRef(), &callbacks
);
2536 if ( style
& wxLC_LIST
)
2538 InsertColumn(0, kDataBrowserIconAndTextType
, wxEmptyString
, -1, -1);
2539 verify_noerr( AutoSizeColumns() );
2542 if ( style
& wxLC_LIST
|| style
& wxLC_NO_HEADER
)
2543 verify_noerr( SetHeaderButtonHeight( 0 ) );
2546 SetSortProperty( kMinColumnId
- 1 );
2548 SetSortProperty( kMinColumnId
);
2550 m_sortOrder
= SortOrder_None
;
2552 if ( style
& wxLC_SORT_DESCENDING
)
2554 SetSortOrder( kDataBrowserOrderDecreasing
);
2556 else if ( style
& wxLC_SORT_ASCENDING
)
2558 SetSortOrder( kDataBrowserOrderIncreasing
);
2561 if ( style
& wxLC_VRULES
)
2563 verify_noerr( DataBrowserChangeAttributes(m_controlRef
, kDataBrowserAttributeListViewDrawColumnDividers
, kDataBrowserAttributeNone
) );
2566 verify_noerr( SetHiliteStyle(kDataBrowserTableViewFillHilite
) );
2567 verify_noerr( SetHasScrollBars( (style
& wxHSCROLL
) != 0 , true ) );
2570 pascal Boolean
wxMacDataBrowserListCtrlControl::DataBrowserEditTextProc(
2572 DataBrowserItemID itemID
,
2573 DataBrowserPropertyID property
,
2574 CFStringRef theString
,
2575 Rect
*maxEditTextRect
,
2576 Boolean
*shrinkToFit
)
2578 Boolean result
= false;
2579 wxMacDataBrowserListCtrlControl
* ctl
= wxDynamicCast(wxMacControl::GetReferenceFromNativeControl( browser
), wxMacDataBrowserListCtrlControl
);
2582 result
= ctl
->ConfirmEditText(itemID
, property
, theString
, maxEditTextRect
, shrinkToFit
);
2583 theString
= CFSTR("Hello!");
2588 bool wxMacDataBrowserListCtrlControl::ConfirmEditText(
2589 DataBrowserItemID
WXUNUSED(itemID
),
2590 DataBrowserPropertyID
WXUNUSED(property
),
2591 CFStringRef
WXUNUSED(theString
),
2592 Rect
*WXUNUSED(maxEditTextRect
),
2593 Boolean
*WXUNUSED(shrinkToFit
))
2598 pascal void wxMacDataBrowserListCtrlControl::DataBrowserDrawItemProc(
2600 DataBrowserItemID itemID
,
2601 DataBrowserPropertyID property
,
2602 DataBrowserItemState itemState
,
2603 const Rect
*itemRect
,
2605 Boolean colorDevice
)
2607 wxMacDataBrowserListCtrlControl
* ctl
= wxDynamicCast(wxMacControl::GetReferenceFromNativeControl( browser
), wxMacDataBrowserListCtrlControl
);
2610 ctl
->DrawItem(itemID
, property
, itemState
, itemRect
, gdDepth
, colorDevice
);
2614 // routines needed for DrawItem
2619 kTextBoxHeight
= 14,
2620 kIconTextSpacingV
= 2,
2622 kContentHeight
= kIconHeight
+ kTextBoxHeight
+ kIconTextSpacingV
2625 static void calculateCGDrawingBounds(CGRect inItemRect
, CGRect
*outIconRect
, CGRect
*outTextRect
, bool hasIcon
= false)
2628 float iconH
, iconW
= 0;
2629 float padding
= kItemPadding
;
2632 iconH
= kIconHeight
;
2634 padding
= padding
*2;
2637 textBottom
= inItemRect
.origin
.y
;
2639 *outIconRect
= CGRectMake(inItemRect
.origin
.x
+ kItemPadding
,
2640 textBottom
+ kIconTextSpacingV
, kIconWidth
,
2643 *outTextRect
= CGRectMake(inItemRect
.origin
.x
+ padding
+ iconW
,
2644 textBottom
+ kIconTextSpacingV
, inItemRect
.size
.width
- padding
- iconW
,
2645 inItemRect
.size
.height
- kIconTextSpacingV
);
2648 void wxMacDataBrowserListCtrlControl::DrawItem(
2649 DataBrowserItemID itemID
,
2650 DataBrowserPropertyID property
,
2651 DataBrowserItemState itemState
,
2652 const Rect
*WXUNUSED(itemRect
),
2654 Boolean colorDevice
)
2657 wxFont font
= wxNullFont
;
2659 short listColumn
= property
- kMinColumnId
;
2661 wxListCtrl
* list
= wxDynamicCast( GetPeer() , wxListCtrl
);
2662 wxMacListCtrlItem
* lcItem
;
2663 wxColour color
= *wxBLACK
;
2664 wxColour bgColor
= wxNullColour
;
2666 if (listColumn
>= 0)
2670 lcItem
= (wxMacListCtrlItem
*) itemID
;
2671 if (lcItem
->HasColumnInfo(listColumn
)){
2672 wxListItem
* item
= lcItem
->GetColumnInfo(listColumn
);
2674 // we always use the 0 column to get font and text/background colors.
2675 if (lcItem
->HasColumnInfo(0))
2677 wxListItem
* firstItem
= lcItem
->GetColumnInfo(0);
2678 color
= firstItem
->GetTextColour();
2679 bgColor
= firstItem
->GetBackgroundColour();
2680 font
= firstItem
->GetFont();
2683 if (item
->GetMask() & wxLIST_MASK_TEXT
)
2684 text
= item
->GetText();
2685 if (item
->GetMask() & wxLIST_MASK_IMAGE
)
2686 imgIndex
= item
->GetImage();
2692 long itemNum
= (long)itemID
-1;
2693 if (itemNum
>= 0 && itemNum
< list
->GetItemCount())
2695 text
= list
->OnGetItemText( itemNum
, listColumn
);
2696 imgIndex
= list
->OnGetItemColumnImage( itemNum
, listColumn
);
2697 wxListItemAttr
* attrs
= list
->OnGetItemAttr( itemNum
);
2700 if (attrs
->HasBackgroundColour())
2701 bgColor
= attrs
->GetBackgroundColour();
2702 if (attrs
->HasTextColour())
2703 color
= attrs
->GetTextColour();
2704 if (attrs
->HasFont())
2705 font
= attrs
->GetFont();
2711 wxColour listBgColor
= list
->GetBackgroundColour();
2712 if (bgColor
== wxNullColour
)
2713 bgColor
= listBgColor
;
2716 font
= list
->GetFont();
2718 wxCFStringRef
cfString( text
, wxLocale::GetSystemEncoding() );
2721 CGRect enclosingCGRect
, iconCGRect
, textCGRect
;
2723 ThemeDrawingState savedState
= NULL
;
2724 CGContextRef context
= (CGContextRef
)list
->MacGetDrawingContext();
2725 RGBColor labelColor
;
2727 labelColor
.green
= 0;
2728 labelColor
.blue
= 0;
2730 RGBColor backgroundColor
;
2731 backgroundColor
.red
= 255;
2732 backgroundColor
.green
= 255;
2733 backgroundColor
.blue
= 255;
2735 GetDataBrowserItemPartBounds(GetControlRef(), itemID
, property
, kDataBrowserPropertyEnclosingPart
,
2738 enclosingCGRect
= CGRectMake(enclosingRect
.left
,
2740 enclosingRect
.right
- enclosingRect
.left
,
2741 enclosingRect
.bottom
- enclosingRect
.top
);
2743 bool hasFocus
= (wxWindow::FindFocus() == list
);
2744 active
= IsControlActive(GetControlRef());
2746 // don't paint the background over the vertical rule line
2747 if ( list
->GetWindowStyleFlag() & wxLC_VRULES
)
2749 enclosingCGRect
.origin
.x
+= 1;
2750 enclosingCGRect
.size
.width
-= 1;
2752 if (itemState
== kDataBrowserItemIsSelected
)
2755 GetThemeDrawingState(&savedState
);
2757 if (active
&& hasFocus
)
2759 GetThemeBrushAsColor(kThemeBrushAlternatePrimaryHighlightColor
, 32, true, &backgroundColor
);
2760 GetThemeTextColor(kThemeTextColorWhite
, gdDepth
, colorDevice
, &labelColor
);
2764 GetThemeBrushAsColor(kThemeBrushSecondaryHighlightColor
, 32, true, &backgroundColor
);
2765 GetThemeTextColor(kThemeTextColorBlack
, gdDepth
, colorDevice
, &labelColor
);
2767 CGContextSaveGState(context
);
2769 CGContextSetRGBFillColor(context
, (float)backgroundColor
.red
/ (float)USHRT_MAX
,
2770 (float)backgroundColor
.green
/ (float)USHRT_MAX
,
2771 (float)backgroundColor
.blue
/ (float)USHRT_MAX
, 1.0);
2772 CGContextFillRect(context
, enclosingCGRect
);
2774 CGContextRestoreGState(context
);
2780 color
.GetRGBColor(&labelColor
);
2781 else if (list
->GetTextColour().Ok())
2782 list
->GetTextColour().GetRGBColor(&labelColor
);
2786 bgColor
.GetRGBColor(&backgroundColor
);
2787 CGContextSaveGState(context
);
2789 CGContextSetRGBFillColor(context
, (float)backgroundColor
.red
/ (float)USHRT_MAX
,
2790 (float)backgroundColor
.green
/ (float)USHRT_MAX
,
2791 (float)backgroundColor
.blue
/ (float)USHRT_MAX
, 1.0);
2792 CGContextFillRect(context
, enclosingCGRect
);
2794 CGContextRestoreGState(context
);
2798 calculateCGDrawingBounds(enclosingCGRect
, &iconCGRect
, &textCGRect
, (imgIndex
!= -1) );
2802 wxImageList
* imageList
= list
->GetImageList(wxIMAGE_LIST_SMALL
);
2803 if (imageList
&& imageList
->GetImageCount() > 0){
2804 wxBitmap bmp
= imageList
->GetBitmap(imgIndex
);
2805 IconRef icon
= bmp
.GetIconRef();
2807 CGContextSaveGState(context
);
2808 CGContextTranslateCTM(context
, 0,iconCGRect
.origin
.y
+ CGRectGetMaxY(iconCGRect
));
2809 CGContextScaleCTM(context
,1.0f
,-1.0f
);
2810 PlotIconRefInContext(context
, &iconCGRect
, kAlignNone
,
2811 active
? kTransformNone
: kTransformDisabled
, NULL
,
2812 kPlotIconRefNormalFlags
, icon
);
2814 CGContextRestoreGState(context
);
2818 HIThemeTextHorizontalFlush hFlush
= kHIThemeTextHorizontalFlushLeft
;
2819 HIThemeTextInfo info
;
2821 #if wxMAC_USE_CORE_TEXT
2822 if ( UMAGetSystemVersion() >= 0x1050 )
2824 info
.version
= kHIThemeTextInfoVersionOne
;
2825 info
.fontID
= kThemeViewsFont
;
2828 info
.fontID
= kThemeSpecifiedFont
;
2829 info
.font
= (CTFontRef
) font
.MacGetCTFont();
2834 #if wxMAC_USE_ATSU_TEXT
2837 info
.version
= kHIThemeTextInfoVersionZero
;
2838 info
.fontID
= kThemeViewsFont
;
2842 info
.fontID
= font
.MacGetThemeFontID();
2844 ::TextSize( (short)(font
.MacGetFontSize()) ) ;
2845 ::TextFace( font
.MacGetFontStyle() ) ;
2851 list
->GetColumn(listColumn
, item
);
2852 if (item
.GetMask() & wxLIST_MASK_FORMAT
)
2854 if (item
.GetAlign() == wxLIST_FORMAT_LEFT
)
2855 hFlush
= kHIThemeTextHorizontalFlushLeft
;
2856 else if (item
.GetAlign() == wxLIST_FORMAT_CENTER
)
2857 hFlush
= kHIThemeTextHorizontalFlushCenter
;
2858 else if (item
.GetAlign() == wxLIST_FORMAT_RIGHT
)
2860 hFlush
= kHIThemeTextHorizontalFlushRight
;
2861 textCGRect
.origin
.x
-= kItemPadding
; // give a little extra paddding
2865 info
.state
= active
? kThemeStateActive
: kThemeStateInactive
;
2866 info
.horizontalFlushness
= hFlush
;
2867 info
.verticalFlushness
= kHIThemeTextVerticalFlushCenter
;
2868 info
.options
= kHIThemeTextBoxOptionNone
;
2869 info
.truncationPosition
= kHIThemeTextTruncationEnd
;
2870 info
.truncationMaxLines
= 1;
2872 CGContextSaveGState(context
);
2873 CGContextSetRGBFillColor (context
, (float)labelColor
.red
/ (float)USHRT_MAX
,
2874 (float)labelColor
.green
/ (float)USHRT_MAX
,
2875 (float)labelColor
.blue
/ (float)USHRT_MAX
, 1.0);
2877 HIThemeDrawTextBox(cfString
, &textCGRect
, &info
, context
, kHIThemeOrientationNormal
);
2879 CGContextRestoreGState(context
);
2882 if (savedState
!= NULL
)
2883 SetThemeDrawingState(savedState
, true);
2887 OSStatus
wxMacDataBrowserListCtrlControl::GetSetItemData(DataBrowserItemID itemID
,
2888 DataBrowserPropertyID property
,
2889 DataBrowserItemDataRef itemData
,
2890 Boolean changeValue
)
2894 short listColumn
= property
- kMinColumnId
;
2896 OSStatus err
= errDataBrowserPropertyNotSupported
;
2897 wxListCtrl
* list
= wxDynamicCast( GetPeer() , wxListCtrl
);
2898 wxMacListCtrlItem
* lcItem
;
2900 if (listColumn
>= 0)
2904 lcItem
= (wxMacListCtrlItem
*) itemID
;
2905 if (lcItem
&& lcItem
->HasColumnInfo(listColumn
)){
2906 wxListItem
* item
= lcItem
->GetColumnInfo(listColumn
);
2907 if (item
->GetMask() & wxLIST_MASK_TEXT
)
2908 text
= item
->GetText();
2909 if (item
->GetMask() & wxLIST_MASK_IMAGE
)
2910 imgIndex
= item
->GetImage();
2915 long itemNum
= (long)itemID
-1;
2916 if (itemNum
>= 0 && itemNum
< list
->GetItemCount())
2918 text
= list
->OnGetItemText( itemNum
, listColumn
);
2919 imgIndex
= list
->OnGetItemColumnImage( itemNum
, listColumn
);
2928 case kDataBrowserItemIsEditableProperty
:
2929 if ( list
&& list
->HasFlag( wxLC_EDIT_LABELS
) )
2931 verify_noerr(SetDataBrowserItemDataBooleanValue( itemData
, true ));
2936 if ( property
>= kMinColumnId
)
2938 if (!text
.IsEmpty()){
2939 wxCFStringRef
cfStr( text
, wxLocale::GetSystemEncoding() );
2940 err
= ::SetDataBrowserItemDataText( itemData
, cfStr
);
2946 if ( imgIndex
!= -1 )
2948 wxImageList
* imageList
= list
->GetImageList(wxIMAGE_LIST_SMALL
);
2949 if (imageList
&& imageList
->GetImageCount() > 0){
2950 wxBitmap bmp
= imageList
->GetBitmap(imgIndex
);
2951 IconRef icon
= bmp
.GetIconRef();
2952 ::SetDataBrowserItemDataIcon(itemData
, icon
);
2966 if ( property
>= kMinColumnId
)
2968 short listColumn
= property
- kMinColumnId
;
2970 // TODO probably send the 'end edit' from here, as we
2971 // can then deal with the veto
2973 verify_noerr( GetDataBrowserItemDataText( itemData
, &sr
) ) ;
2974 wxCFStringRef
cfStr(sr
) ;;
2976 list
->SetItem( (long)itemData
-1 , listColumn
, cfStr
.AsString() ) ;
2980 lcItem
->SetColumnTextValue( listColumn
, cfStr
.AsString() );
2990 void wxMacDataBrowserListCtrlControl::ItemNotification(DataBrowserItemID itemID
,
2991 DataBrowserItemNotification message
,
2992 DataBrowserItemDataRef
WXUNUSED(itemData
) )
2994 // we want to depend on as little as possible to make sure tear-down of controls is safe
2995 if ( message
== kDataBrowserItemRemoved
)
2997 // make sure MacDelete does the proper teardown.
3000 else if ( message
== kDataBrowserItemAdded
)
3002 // we don't issue events on adding, the item is not really stored in the list yet, so we
3003 // avoid asserts by getting out now
3007 wxListCtrl
*list
= wxDynamicCast( GetPeer() , wxListCtrl
);
3010 bool trigger
= false;
3012 wxListEvent
event( wxEVT_COMMAND_LIST_ITEM_SELECTED
, list
->GetId() );
3014 event
.SetEventObject( list
);
3015 if ( !list
->IsVirtual() )
3017 DataBrowserTableViewRowIndex result
= 0;
3018 verify_noerr( GetItemRow( itemID
, &result
) ) ;
3019 event
.m_itemIndex
= result
;
3023 event
.m_itemIndex
= (long)itemID
-1;
3025 event
.m_item
.m_itemId
= event
.m_itemIndex
;
3026 list
->GetItem(event
.m_item
);
3030 case kDataBrowserItemDeselected
:
3031 event
.SetEventType(wxEVT_COMMAND_LIST_ITEM_DESELECTED
);
3032 // as the generic implementation is also triggering this
3033 // event for single selection, we do the same (different than listbox)
3034 trigger
= !IsSelectionSuppressed();
3037 case kDataBrowserItemSelected
:
3038 trigger
= !IsSelectionSuppressed();
3042 case kDataBrowserItemDoubleClicked
:
3043 event
.SetEventType( wxEVT_COMMAND_LIST_ITEM_ACTIVATED
);
3047 case kDataBrowserEditStarted
:
3048 // TODO : how to veto ?
3049 event
.SetEventType( wxEVT_COMMAND_LIST_BEGIN_LABEL_EDIT
) ;
3053 case kDataBrowserEditStopped
:
3054 // TODO probably trigger only upon the value store callback, because
3055 // here IIRC we cannot veto
3056 event
.SetEventType( wxEVT_COMMAND_LIST_END_LABEL_EDIT
) ;
3066 // direct notification is not always having the listbox GetSelection() having in synch with event
3067 wxPostEvent( list
->GetEventHandler(), event
);
3072 Boolean
wxMacDataBrowserListCtrlControl::CompareItems(DataBrowserItemID itemOneID
,
3073 DataBrowserItemID itemTwoID
,
3074 DataBrowserPropertyID sortProperty
)
3077 bool retval
= false;
3079 wxString otherItemText
;
3081 long otherItemOrder
;
3083 int colId
= sortProperty
- kMinColumnId
;
3085 wxListCtrl
* list
= wxDynamicCast( GetPeer() , wxListCtrl
);
3087 DataBrowserSortOrder sort
;
3088 verify_noerr(GetSortOrder(&sort
));
3094 wxMacListCtrlItem
* item
= (wxMacListCtrlItem
*)itemOneID
;
3095 wxMacListCtrlItem
* otherItem
= (wxMacListCtrlItem
*)itemTwoID
;
3097 itemOrder
= item
->GetOrder();
3098 otherItemOrder
= item
->GetOrder();
3100 wxListCtrlCompare func
= list
->GetCompareFunc();
3105 if (item
&& item
->HasColumnInfo(0))
3106 item1
= item
->GetColumnInfo(0)->GetData();
3107 if (otherItem
&& otherItem
->HasColumnInfo(0))
3108 item2
= otherItem
->GetColumnInfo(0)->GetData();
3110 if (item1
> -1 && item2
> -1)
3112 int result
= func(item1
, item2
, list
->GetCompareFuncData());
3113 if (sort
== kDataBrowserOrderIncreasing
)
3120 // we can't use the native control's sorting abilities, so just
3122 return itemOrder
< otherItemOrder
;
3127 long itemNum
= (long)itemOneID
;
3128 long otherItemNum
= (long)itemTwoID
;
3130 // virtual listctrls don't support sorting
3131 return itemNum
< otherItemNum
;
3135 // fallback for undefined cases
3136 retval
= itemOneID
< itemTwoID
;
3142 wxMacDataBrowserListCtrlControl::~wxMacDataBrowserListCtrlControl()
3146 void wxMacDataBrowserListCtrlControl::MacSetColumnInfo( unsigned int row
, unsigned int column
, wxListItem
* item
)
3148 wxMacDataItem
* dataItem
= GetItemFromLine(row
);
3149 wxASSERT_MSG( dataItem
, _T("could not obtain wxMacDataItem for row in MacSetColumnInfo. Is row a valid wxListCtrl row?") );
3152 wxMacListCtrlItem
* listItem
= wx_static_cast(wxMacListCtrlItem
*,dataItem
);
3153 bool hasInfo
= listItem
->HasColumnInfo( column
);
3154 listItem
->SetColumnInfo( column
, item
);
3155 listItem
->SetOrder(row
);
3156 UpdateState(dataItem
, item
);
3158 wxListCtrl
* list
= wxDynamicCast( GetPeer() , wxListCtrl
);
3160 // NB: When this call was made before a control was completely shown, it would
3161 // update the item prematurely (i.e. no text would be listed) and, on show,
3162 // only the sorted column would be refreshed, meaning only first column text labels
3163 // would be shown. Making sure not to update items until the control is visible
3164 // seems to fix this issue.
3165 if (hasInfo
&& list
->IsShown())
3166 UpdateItem( wxMacDataBrowserRootContainer
, listItem
, kMinColumnId
+ column
);
3170 // apply changes that need to happen immediately, rather than when the
3171 // databrowser control fires a callback.
3172 void wxMacDataBrowserListCtrlControl::UpdateState(wxMacDataItem
* dataItem
, wxListItem
* listItem
)
3174 bool isSelected
= IsItemSelected( dataItem
);
3175 bool isSelectedState
= (listItem
->GetState() == wxLIST_STATE_SELECTED
);
3177 // toggle the selection state if wxListInfo state and actual state don't match.
3178 if ( listItem
->GetMask() & wxLIST_MASK_STATE
&& isSelected
!= isSelectedState
)
3180 DataBrowserSetOption options
= kDataBrowserItemsAdd
;
3181 if (!isSelectedState
)
3182 options
= kDataBrowserItemsRemove
;
3183 SetSelectedItem(dataItem
, options
);
3185 // TODO: Set column width if item width > than current column width
3188 void wxMacDataBrowserListCtrlControl::MacGetColumnInfo( unsigned int row
, unsigned int column
, wxListItem
& item
)
3190 wxMacDataItem
* dataItem
= GetItemFromLine(row
);
3191 wxASSERT_MSG( dataItem
, _T("could not obtain wxMacDataItem in MacGetColumnInfo. Is row a valid wxListCtrl row?") );
3192 // CS should this guard against dataItem = 0 ? , as item is not a pointer if (item) is not appropriate
3195 wxMacListCtrlItem
* listItem
=wx_static_cast(wxMacListCtrlItem
*,dataItem
);
3197 if (!listItem
->HasColumnInfo( column
))
3200 wxListItem
* oldItem
= listItem
->GetColumnInfo( column
);
3204 long mask
= item
.GetMask();
3206 // by default, get everything for backwards compatibility
3209 if ( mask
& wxLIST_MASK_TEXT
)
3210 item
.SetText(oldItem
->GetText());
3211 if ( mask
& wxLIST_MASK_IMAGE
)
3212 item
.SetImage(oldItem
->GetImage());
3213 if ( mask
& wxLIST_MASK_DATA
)
3214 item
.SetData(oldItem
->GetData());
3215 if ( mask
& wxLIST_MASK_STATE
)
3216 item
.SetState(oldItem
->GetState());
3217 if ( mask
& wxLIST_MASK_WIDTH
)
3218 item
.SetWidth(oldItem
->GetWidth());
3219 if ( mask
& wxLIST_MASK_FORMAT
)
3220 item
.SetAlign(oldItem
->GetAlign());
3222 item
.SetTextColour(oldItem
->GetTextColour());
3223 item
.SetBackgroundColour(oldItem
->GetBackgroundColour());
3224 item
.SetFont(oldItem
->GetFont());
3229 void wxMacDataBrowserListCtrlControl::MacInsertItem( unsigned int n
, wxListItem
* item
)
3231 wxMacDataItemBrowserControl::MacInsert(n
, item
->GetText());
3232 MacSetColumnInfo(n
, 0, item
);
3235 wxMacDataItem
* wxMacDataBrowserListCtrlControl::CreateItem()
3237 return new wxMacListCtrlItem();
3240 wxMacListCtrlItem::wxMacListCtrlItem()
3242 m_rowItems
= wxListItemList();
3245 int wxMacListCtrlItem::GetColumnImageValue( unsigned int column
)
3247 if ( HasColumnInfo(column
) )
3248 return GetColumnInfo(column
)->GetImage();
3253 void wxMacListCtrlItem::SetColumnImageValue( unsigned int column
, int imageIndex
)
3255 if ( HasColumnInfo(column
) )
3256 GetColumnInfo(column
)->SetImage(imageIndex
);
3259 wxString
wxMacListCtrlItem::GetColumnTextValue( unsigned int column
)
3264 if ( HasColumnInfo(column
) )
3265 return GetColumnInfo(column
)->GetText();
3267 return wxEmptyString
;
3270 void wxMacListCtrlItem::SetColumnTextValue( unsigned int column
, const wxString
& text
)
3272 if ( HasColumnInfo(column
) )
3273 GetColumnInfo(column
)->SetText(text
);
3275 // for compatibility with superclass APIs
3280 wxListItem
* wxMacListCtrlItem::GetColumnInfo( unsigned int column
)
3282 wxASSERT_MSG( HasColumnInfo(column
), _T("invalid column index in wxMacListCtrlItem") );
3283 return m_rowItems
[column
];
3286 bool wxMacListCtrlItem::HasColumnInfo( unsigned int column
)
3288 return !(m_rowItems
.find( column
) == m_rowItems
.end());
3291 void wxMacListCtrlItem::SetColumnInfo( unsigned int column
, wxListItem
* item
)
3294 if ( !HasColumnInfo(column
) )
3296 wxListItem
* listItem
= new wxListItem(*item
);
3297 m_rowItems
[column
] = listItem
;
3301 wxListItem
* listItem
= GetColumnInfo( column
);
3302 long mask
= item
->GetMask();
3303 if (mask
& wxLIST_MASK_TEXT
)
3304 listItem
->SetText(item
->GetText());
3305 if (mask
& wxLIST_MASK_DATA
)
3306 listItem
->SetData(item
->GetData());
3307 if (mask
& wxLIST_MASK_IMAGE
)
3308 listItem
->SetImage(item
->GetImage());
3309 if (mask
& wxLIST_MASK_STATE
)
3310 listItem
->SetState(item
->GetState());
3311 if (mask
& wxLIST_MASK_FORMAT
)
3312 listItem
->SetAlign(item
->GetAlign());
3313 if (mask
& wxLIST_MASK_WIDTH
)
3314 listItem
->SetWidth(item
->GetWidth());
3316 if ( item
->HasAttributes() )
3318 if ( listItem
->HasAttributes() )
3319 listItem
->GetAttributes()->AssignFrom(*item
->GetAttributes());
3322 listItem
->SetTextColour(item
->GetTextColour());
3323 listItem
->SetBackgroundColour(item
->GetBackgroundColour());
3324 listItem
->SetFont(item
->GetFont());
3330 #endif // wxUSE_LISTCTRL