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
;
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 wxCFStringRef 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 wxImageList
* imageList
= GetImageList(wxIMAGE_LIST_SMALL
);
984 if (imageList
&& imageList
->GetImageCount() > 0 )
986 wxBitmap bmp
= imageList
->GetBitmap( item
.GetImage() );
987 IconRef icon
= bmp
.GetIconRef();
988 columnDesc
.btnContentInfo
.u
.iconRef
= icon
;
989 columnDesc
.btnContentInfo
.contentType
= kControlContentIconRef
;
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();
1080 m_dbImpl
->GetDefaultRowHeight( &height
);
1082 return GetClientSize().y
/ height
;
1088 // Gets the edit control for editing labels.
1089 wxTextCtrl
* wxListCtrl::GetEditControl() const
1092 return m_genericImpl
->GetEditControl();
1097 // Gets information about the item
1098 bool wxListCtrl::GetItem(wxListItem
& info
) const
1101 return m_genericImpl
->GetItem(info
);
1107 if (info
.m_itemId
>= 0 && info
.m_itemId
< GetItemCount())
1109 m_dbImpl
->MacGetColumnInfo(info
.m_itemId
, info
.m_col
, info
);
1110 if (info
.GetMask() & wxLIST_MASK_STATE
)
1112 DataBrowserItemID id
= (DataBrowserItemID
)m_dbImpl
->GetItemFromLine(info
.m_itemId
);
1113 if (IsDataBrowserItemSelected( m_dbImpl
->GetControlRef(), id
))
1114 info
.SetState(info
.GetState() | wxLIST_STATE_SELECTED
);
1120 if (info
.m_itemId
>= 0 && info
.m_itemId
< GetItemCount())
1122 info
.SetText( OnGetItemText(info
.m_itemId
, info
.m_col
) );
1123 info
.SetImage( OnGetItemColumnImage(info
.m_itemId
, info
.m_col
) );
1124 if (info
.GetMask() & wxLIST_MASK_STATE
)
1126 if (IsDataBrowserItemSelected( m_dbImpl
->GetControlRef(), info
.m_itemId
+1 ))
1127 info
.SetState(info
.GetState() | wxLIST_STATE_SELECTED
);
1130 wxListItemAttr
* attrs
= OnGetItemAttr( info
.m_itemId
);
1133 info
.SetFont( attrs
->GetFont() );
1134 info
.SetBackgroundColour( attrs
->GetBackgroundColour() );
1135 info
.SetTextColour( attrs
->GetTextColour() );
1140 bool success
= true;
1144 // Sets information about the item
1145 bool wxListCtrl::SetItem(wxListItem
& info
)
1148 return m_genericImpl
->SetItem(info
);
1151 m_dbImpl
->MacSetColumnInfo( info
.m_itemId
, info
.m_col
, &info
);
1156 long wxListCtrl::SetItem(long index
, int col
, const wxString
& label
, int imageId
)
1159 return m_genericImpl
->SetItem(index
, col
, label
, imageId
);
1162 info
.m_text
= label
;
1163 info
.m_mask
= wxLIST_MASK_TEXT
;
1164 info
.m_itemId
= index
;
1168 info
.m_image
= imageId
;
1169 info
.m_mask
|= wxLIST_MASK_IMAGE
;
1171 return SetItem(info
);
1175 // Gets the item state
1176 int wxListCtrl::GetItemState(long item
, long stateMask
) const
1179 return m_genericImpl
->GetItemState(item
, stateMask
);
1183 if ( HasFlag(wxLC_VIRTUAL
) )
1185 if (stateMask
== wxLIST_STATE_SELECTED
)
1187 if (IsDataBrowserItemSelected( m_dbImpl
->GetControlRef(), item
+1 ))
1188 return wxLIST_STATE_SELECTED
;
1197 info
.m_mask
= wxLIST_MASK_STATE
;
1198 info
.m_stateMask
= stateMask
;
1199 info
.m_itemId
= item
;
1204 return info
.m_state
;
1211 // Sets the item state
1212 bool wxListCtrl::SetItemState(long item
, long state
, long stateMask
)
1215 return m_genericImpl
->SetItemState(item
, state
, stateMask
);
1219 DataBrowserSetOption option
= kDataBrowserItemsAdd
;
1220 if ( (stateMask
& wxLIST_STATE_SELECTED
) && state
== 0 )
1221 option
= kDataBrowserItemsRemove
;
1225 if ( HasFlag(wxLC_VIRTUAL
) )
1227 wxMacDataItemBrowserSelectionSuppressor
suppressor(m_dbImpl
);
1228 m_dbImpl
->SetSelectedAllItems(option
);
1232 for(int i
= 0; i
< GetItemCount();i
++)
1236 info
.m_mask
= wxLIST_MASK_STATE
;
1237 info
.m_stateMask
= stateMask
;
1238 info
.m_state
= state
;
1245 if ( HasFlag(wxLC_VIRTUAL
) )
1247 long itemID
= item
+1;
1248 bool isSelected
= IsDataBrowserItemSelected(m_dbImpl
->GetControlRef(), (DataBrowserItemID
)itemID
);
1249 bool isSelectedState
= (state
== wxLIST_STATE_SELECTED
);
1251 // toggle the selection state if wxListInfo state and actual state don't match.
1252 if ( (stateMask
& wxLIST_STATE_SELECTED
) && isSelected
!= isSelectedState
)
1254 SetDataBrowserSelectedItems(m_dbImpl
->GetControlRef(), 1, (DataBrowserItemID
*)&itemID
, option
);
1260 info
.m_itemId
= item
;
1261 info
.m_mask
= wxLIST_MASK_STATE
;
1262 info
.m_stateMask
= stateMask
;
1263 info
.m_state
= state
;
1264 return SetItem(info
);
1271 // Sets the item image
1272 bool wxListCtrl::SetItemImage(long item
, int image
, int WXUNUSED(selImage
))
1274 return SetItemColumnImage(item
, 0, image
);
1277 // Sets the item image
1278 bool wxListCtrl::SetItemColumnImage(long item
, long column
, int image
)
1281 return m_genericImpl
->SetItemColumnImage(item
, column
, image
);
1285 info
.m_mask
= wxLIST_MASK_IMAGE
;
1286 info
.m_image
= image
;
1287 info
.m_itemId
= item
;
1288 info
.m_col
= column
;
1290 return SetItem(info
);
1293 // Gets the item text
1294 wxString
wxListCtrl::GetItemText(long item
) const
1297 return m_genericImpl
->GetItemText(item
);
1301 info
.m_mask
= wxLIST_MASK_TEXT
;
1302 info
.m_itemId
= item
;
1305 return wxEmptyString
;
1309 // Sets the item text
1310 void wxListCtrl::SetItemText(long item
, const wxString
& str
)
1313 return m_genericImpl
->SetItemText(item
, str
);
1317 info
.m_mask
= wxLIST_MASK_TEXT
;
1318 info
.m_itemId
= item
;
1324 // Gets the item data
1325 long wxListCtrl::GetItemData(long item
) const
1328 return m_genericImpl
->GetItemData(item
);
1332 info
.m_mask
= wxLIST_MASK_DATA
;
1333 info
.m_itemId
= item
;
1340 // Sets the item data
1341 bool wxListCtrl::SetItemPtrData(long item
, wxUIntPtr data
)
1344 return m_genericImpl
->SetItemData(item
, data
);
1348 info
.m_mask
= wxLIST_MASK_DATA
;
1349 info
.m_itemId
= item
;
1352 return SetItem(info
);
1355 wxRect
wxListCtrl::GetViewRect() const
1357 wxASSERT_MSG( !HasFlag(wxLC_REPORT
| wxLC_LIST
),
1358 _T("wxListCtrl::GetViewRect() only works in icon mode") );
1361 return m_genericImpl
->GetViewRect();
1367 // Gets the item rectangle
1368 bool wxListCtrl::GetItemRect(long item
, wxRect
& rect
, int code
) const
1371 return m_genericImpl
->GetItemRect(item
, rect
, code
);
1376 DataBrowserItemID id
;
1377 DataBrowserPropertyID col
= kMinColumnId
;
1379 DataBrowserPropertyPart part
= kDataBrowserPropertyEnclosingPart
;
1380 if ( code
== wxLIST_RECT_LABEL
)
1381 part
= kDataBrowserPropertyTextPart
;
1382 else if ( code
== wxLIST_RECT_ICON
)
1383 part
= kDataBrowserPropertyIconPart
;
1385 if ( !(GetWindowStyleFlag() & wxLC_VIRTUAL
) )
1387 wxMacDataItem
* thisItem
= m_dbImpl
->GetItemFromLine(item
);
1388 id
= (DataBrowserItemID
) thisItem
;
1393 GetDataBrowserItemPartBounds( m_dbImpl
->GetControlRef(), id
, col
, part
, &bounds
);
1395 rect
.x
= bounds
.left
;
1396 rect
.y
= bounds
.top
;
1397 rect
.width
= bounds
.right
- bounds
.left
; //GetClientSize().x; // we need the width of the whole row, not just the item.
1398 rect
.height
= bounds
.bottom
- bounds
.top
;
1399 //fprintf("id = %d, bounds = %d, %d, %d, %d\n", id, rect.x, rect.y, rect.width, rect.height);
1404 // Gets the item position
1405 bool wxListCtrl::GetItemPosition(long item
, wxPoint
& pos
) const
1408 return m_genericImpl
->GetItemPosition(item
, pos
);
1410 bool success
= false;
1415 GetItemRect(item
, itemRect
);
1416 pos
= itemRect
.GetPosition();
1423 // Sets the item position.
1424 bool wxListCtrl::SetItemPosition(long item
, const wxPoint
& pos
)
1427 return m_genericImpl
->SetItemPosition(item
, pos
);
1432 // Gets the number of items in the list control
1433 int wxListCtrl::GetItemCount() const
1436 return m_genericImpl
->GetItemCount();
1439 return m_dbImpl
->MacGetCount();
1444 void wxListCtrl::SetItemSpacing( int spacing
, bool isSmall
)
1447 m_genericImpl
->SetItemSpacing(spacing
, isSmall
);
1450 wxSize
wxListCtrl::GetItemSpacing() const
1453 return m_genericImpl
->GetItemSpacing();
1455 return wxSize(0, 0);
1458 void wxListCtrl::SetItemTextColour( long item
, const wxColour
&col
)
1462 m_genericImpl
->SetItemTextColour(item
, col
);
1467 info
.m_itemId
= item
;
1468 info
.SetTextColour( col
);
1472 wxColour
wxListCtrl::GetItemTextColour( long item
) const
1475 return m_genericImpl
->GetItemTextColour(item
);
1481 return info
.GetTextColour();
1483 return wxNullColour
;
1486 void wxListCtrl::SetItemBackgroundColour( long item
, const wxColour
&col
)
1490 m_genericImpl
->SetItemBackgroundColour(item
, col
);
1495 info
.m_itemId
= item
;
1496 info
.SetBackgroundColour( col
);
1500 wxColour
wxListCtrl::GetItemBackgroundColour( long item
) const
1503 return m_genericImpl
->GetItemBackgroundColour(item
);
1509 return info
.GetBackgroundColour();
1511 return wxNullColour
;
1514 void wxListCtrl::SetItemFont( long item
, const wxFont
&f
)
1518 m_genericImpl
->SetItemFont(item
, f
);
1523 info
.m_itemId
= item
;
1528 wxFont
wxListCtrl::GetItemFont( long item
) const
1531 return m_genericImpl
->GetItemFont(item
);
1537 return info
.GetFont();
1543 // Gets the number of selected items in the list control
1544 int wxListCtrl::GetSelectedItemCount() const
1547 return m_genericImpl
->GetSelectedItemCount();
1550 return m_dbImpl
->GetSelectedItemCount(NULL
, true);
1555 // Gets the text colour of the listview
1556 wxColour
wxListCtrl::GetTextColour() const
1559 return m_genericImpl
->GetTextColour();
1561 // TODO: we need owner drawn list items to customize text color.
1565 return wxNullColour
;
1568 // Sets the text colour of the listview
1569 void wxListCtrl::SetTextColour(const wxColour
& col
)
1573 m_genericImpl
->SetTextColour(col
);
1581 // Gets the index of the topmost visible item when in
1582 // list or report view
1583 long wxListCtrl::GetTopItem() const
1586 return m_genericImpl
->GetTopItem();
1591 long item
= HitTest( wxPoint(1, 1), flags
);
1592 if (flags
== wxLIST_HITTEST_ONITEM
)
1599 // Searches for an item, starting from 'item'.
1600 // 'geometry' is one of
1601 // wxLIST_NEXT_ABOVE/ALL/BELOW/LEFT/RIGHT.
1602 // 'state' is a state bit flag, one or more of
1603 // wxLIST_STATE_DROPHILITED/FOCUSED/SELECTED/CUT.
1604 // item can be -1 to find the first item that matches the
1606 // Returns the item or -1 if unsuccessful.
1607 long wxListCtrl::GetNextItem(long item
, int geom
, int state
) const
1610 return m_genericImpl
->GetNextItem(item
, geom
, state
);
1612 // TODO: implement all geometry and state options?
1615 if ( geom
== wxLIST_NEXT_ALL
|| geom
== wxLIST_NEXT_BELOW
)
1617 long count
= m_dbImpl
->MacGetCount() ;
1618 for ( long line
= item
+ 1 ; line
< count
; line
++ )
1620 DataBrowserItemID id
= line
+ 1;
1622 id
= (DataBrowserItemID
)m_dbImpl
->GetItemFromLine(line
);
1624 if ( (state
== wxLIST_STATE_DONTCARE
) )
1627 if ( (state
& wxLIST_STATE_SELECTED
) && IsDataBrowserItemSelected(m_dbImpl
->GetControlRef(), id
) )
1632 if ( geom
== wxLIST_NEXT_ABOVE
)
1636 item2
= m_dbImpl
->MacGetCount();
1638 for ( long line
= item2
- 1 ; line
>= 0; line
-- )
1640 DataBrowserItemID id
= line
+ 1;
1642 id
= (DataBrowserItemID
)m_dbImpl
->GetItemFromLine(line
);
1644 if ( (state
== wxLIST_STATE_DONTCARE
) )
1647 if ( (state
& wxLIST_STATE_SELECTED
) && IsDataBrowserItemSelected(m_dbImpl
->GetControlRef(), id
) )
1657 wxImageList
*wxListCtrl::GetImageList(int which
) const
1660 return m_genericImpl
->GetImageList(which
);
1662 if ( which
== wxIMAGE_LIST_NORMAL
)
1664 return m_imageListNormal
;
1666 else if ( which
== wxIMAGE_LIST_SMALL
)
1668 return m_imageListSmall
;
1670 else if ( which
== wxIMAGE_LIST_STATE
)
1672 return m_imageListState
;
1677 void wxListCtrl::SetImageList(wxImageList
*imageList
, int which
)
1681 m_genericImpl
->SetImageList(imageList
, which
);
1685 if ( which
== wxIMAGE_LIST_NORMAL
)
1687 if (m_ownsImageListNormal
) delete m_imageListNormal
;
1688 m_imageListNormal
= imageList
;
1689 m_ownsImageListNormal
= false;
1691 else if ( which
== wxIMAGE_LIST_SMALL
)
1693 if (m_ownsImageListSmall
) delete m_imageListSmall
;
1694 m_imageListSmall
= imageList
;
1695 m_ownsImageListSmall
= false;
1697 else if ( which
== wxIMAGE_LIST_STATE
)
1699 if (m_ownsImageListState
) delete m_imageListState
;
1700 m_imageListState
= imageList
;
1701 m_ownsImageListState
= false;
1705 void wxListCtrl::AssignImageList(wxImageList
*imageList
, int which
)
1709 m_genericImpl
->AssignImageList(imageList
, which
);
1713 SetImageList(imageList
, which
);
1714 if ( which
== wxIMAGE_LIST_NORMAL
)
1715 m_ownsImageListNormal
= true;
1716 else if ( which
== wxIMAGE_LIST_SMALL
)
1717 m_ownsImageListSmall
= true;
1718 else if ( which
== wxIMAGE_LIST_STATE
)
1719 m_ownsImageListState
= true;
1722 // ----------------------------------------------------------------------------
1724 // ----------------------------------------------------------------------------
1726 // Arranges the items
1727 bool wxListCtrl::Arrange(int flag
)
1730 return m_genericImpl
->Arrange(flag
);
1735 bool wxListCtrl::DeleteItem(long item
)
1738 return m_genericImpl
->DeleteItem(item
);
1742 m_dbImpl
->MacDelete(item
);
1743 wxListEvent
event( wxEVT_COMMAND_LIST_DELETE_ITEM
, GetId() );
1744 event
.SetEventObject( this );
1745 event
.m_itemIndex
= item
;
1746 HandleWindowEvent( event
);
1752 // Deletes all items
1753 bool wxListCtrl::DeleteAllItems()
1756 return m_genericImpl
->DeleteAllItems();
1760 m_dbImpl
->MacClear();
1761 wxListEvent
event( wxEVT_COMMAND_LIST_DELETE_ALL_ITEMS
, GetId() );
1762 event
.SetEventObject( this );
1763 HandleWindowEvent( event
);
1768 // Deletes all items
1769 bool wxListCtrl::DeleteAllColumns()
1772 return m_genericImpl
->DeleteAllColumns();
1777 m_dbImpl
->GetColumnCount(&cols
);
1778 for (UInt32 col
= 0; col
< cols
; col
++)
1788 bool wxListCtrl::DeleteColumn(int col
)
1791 return m_genericImpl
->DeleteColumn(col
);
1795 OSStatus err
= m_dbImpl
->RemoveColumn(col
);
1796 return err
== noErr
;
1802 // Clears items, and columns if there are any.
1803 void wxListCtrl::ClearAll()
1807 m_genericImpl
->ClearAll();
1818 wxTextCtrl
* wxListCtrl::EditLabel(long item
, wxClassInfo
* textControlClass
)
1821 return m_genericImpl
->EditLabel(item
, textControlClass
);
1825 wxCHECK_MSG( (item
>= 0) && ((long)item
< GetItemCount()), NULL
,
1826 wxT("wrong index in wxListCtrl::EditLabel()") );
1828 wxASSERT_MSG( textControlClass
->IsKindOf(CLASSINFO(wxTextCtrl
)),
1829 wxT("EditLabel() needs a text control") );
1831 wxListEvent
le( wxEVT_COMMAND_LIST_BEGIN_LABEL_EDIT
, GetParent()->GetId() );
1832 le
.SetEventObject( this );
1833 le
.m_itemIndex
= item
;
1835 GetItem( le
.m_item
);
1837 if ( GetParent()->HandleWindowEvent( le
) && !le
.IsAllowed() )
1839 // vetoed by user code
1843 wxTextCtrl
* const text
= (wxTextCtrl
*)textControlClass
->CreateObject();
1844 m_textctrlWrapper
= new wxListCtrlTextCtrlWrapper(this, text
, item
);
1845 return m_textctrlWrapper
->GetText();
1850 // End label editing, optionally cancelling the edit
1851 bool wxListCtrl::EndEditLabel(bool WXUNUSED(cancel
))
1853 // TODO: generic impl. doesn't have this method - is it needed for us?
1855 return true; // m_genericImpl->EndEditLabel(cancel);
1858 verify_noerr( SetDataBrowserEditItem(m_dbImpl
->GetControlRef(), kDataBrowserNoItem
, kMinColumnId
) );
1862 // Ensures this item is visible
1863 bool wxListCtrl::EnsureVisible(long item
)
1866 return m_genericImpl
->EnsureVisible(item
);
1870 wxMacDataItem
* dataItem
= m_dbImpl
->GetItemFromLine(item
);
1871 m_dbImpl
->RevealItem(dataItem
, kDataBrowserRevealWithoutSelecting
);
1877 // Find an item whose label matches this string, starting from the item after 'start'
1878 // or the beginning if 'start' is -1.
1879 long wxListCtrl::FindItem(long start
, const wxString
& str
, bool partial
)
1882 return m_genericImpl
->FindItem(start
, str
, partial
);
1884 wxString str_upper
= str
.Upper();
1889 long count
= GetItemCount();
1893 wxString line_upper
= GetItemText(idx
).Upper();
1896 if (line_upper
== str_upper
)
1901 if (line_upper
.find(str_upper
) == 0)
1911 // Find an item whose data matches this data, starting from the item after 'start'
1912 // or the beginning if 'start' is -1.
1913 long wxListCtrl::FindItem(long start
, long data
)
1916 return m_genericImpl
->FindItem(start
, data
);
1921 long count
= GetItemCount();
1925 if (GetItemData(idx
) == data
)
1933 // Find an item nearest this position in the specified direction, starting from
1934 // the item after 'start' or the beginning if 'start' is -1.
1935 long wxListCtrl::FindItem(long start
, const wxPoint
& pt
, int direction
)
1938 return m_genericImpl
->FindItem(start
, pt
, direction
);
1942 // Determines which item (if any) is at the specified point,
1943 // giving details in 'flags' (see wxLIST_HITTEST_... flags above)
1945 wxListCtrl::HitTest(const wxPoint
& point
, int& flags
, long *ptrSubItem
) const
1948 return m_genericImpl
->HitTest(point
, flags
, ptrSubItem
);
1950 flags
= wxLIST_HITTEST_NOWHERE
;
1953 int colHeaderHeight
= 22; // TODO: Find a way to get this value from the db control?
1954 UInt16 rowHeight
= 0;
1955 m_dbImpl
->GetDefaultRowHeight(&rowHeight
);
1958 // get the actual row by taking scroll position into account
1959 UInt32 offsetX
, offsetY
;
1960 m_dbImpl
->GetScrollPosition( &offsetY
, &offsetX
);
1963 if ( !(GetWindowStyleFlag() & wxLC_NO_HEADER
) )
1964 y
-= colHeaderHeight
;
1969 int row
= y
/ rowHeight
;
1970 DataBrowserItemID id
;
1971 m_dbImpl
->GetItemID( (DataBrowserTableViewRowIndex
) row
, &id
);
1973 // TODO: Use GetDataBrowserItemPartBounds to return if we are in icon or label
1974 if ( !(GetWindowStyleFlag() & wxLC_VIRTUAL
) )
1976 wxMacListCtrlItem
* lcItem
;
1977 lcItem
= (wxMacListCtrlItem
*) id
;
1980 flags
= wxLIST_HITTEST_ONITEM
;
1986 if (row
< GetItemCount() )
1988 flags
= wxLIST_HITTEST_ONITEM
;
1997 int wxListCtrl::GetScrollPos(int orient
) const
2000 return m_genericImpl
->GetScrollPos(orient
);
2004 UInt32 offsetX
, offsetY
;
2005 m_dbImpl
->GetScrollPosition( &offsetY
, &offsetX
);
2006 if ( orient
== wxHORIZONTAL
)
2015 // Inserts an item, returning the index of the new item if successful,
2017 long wxListCtrl::InsertItem(wxListItem
& info
)
2019 wxASSERT_MSG( !IsVirtual(), _T("can't be used with virtual controls") );
2022 return m_genericImpl
->InsertItem(info
);
2024 if (m_dbImpl
&& !IsVirtual())
2026 int count
= GetItemCount();
2028 if (info
.m_itemId
> count
)
2029 info
.m_itemId
= count
;
2031 m_dbImpl
->MacInsertItem(info
.m_itemId
, &info
);
2033 wxListEvent
event( wxEVT_COMMAND_LIST_INSERT_ITEM
, GetId() );
2034 event
.SetEventObject( this );
2035 event
.m_itemIndex
= info
.m_itemId
;
2036 HandleWindowEvent( event
);
2037 return info
.m_itemId
;
2042 long wxListCtrl::InsertItem(long index
, const wxString
& label
)
2045 return m_genericImpl
->InsertItem(index
, label
);
2048 info
.m_text
= label
;
2049 info
.m_mask
= wxLIST_MASK_TEXT
;
2050 info
.m_itemId
= index
;
2051 return InsertItem(info
);
2054 // Inserts an image item
2055 long wxListCtrl::InsertItem(long index
, int imageIndex
)
2058 return m_genericImpl
->InsertItem(index
, imageIndex
);
2061 info
.m_image
= imageIndex
;
2062 info
.m_mask
= wxLIST_MASK_IMAGE
;
2063 info
.m_itemId
= index
;
2064 return InsertItem(info
);
2067 // Inserts an image/string item
2068 long wxListCtrl::InsertItem(long index
, const wxString
& label
, int imageIndex
)
2071 return m_genericImpl
->InsertItem(index
, label
, imageIndex
);
2074 info
.m_image
= imageIndex
;
2075 info
.m_text
= label
;
2076 info
.m_mask
= wxLIST_MASK_IMAGE
| wxLIST_MASK_TEXT
;
2077 info
.m_itemId
= index
;
2078 return InsertItem(info
);
2081 // For list view mode (only), inserts a column.
2082 long wxListCtrl::InsertColumn(long col
, wxListItem
& item
)
2085 return m_genericImpl
->InsertColumn(col
, item
);
2089 int width
= item
.GetWidth();
2090 if ( !(item
.GetMask() & wxLIST_MASK_WIDTH
) )
2093 DataBrowserPropertyType type
= kDataBrowserCustomType
; //kDataBrowserTextType;
2094 wxImageList
* imageList
= GetImageList(wxIMAGE_LIST_SMALL
);
2095 if (imageList
&& imageList
->GetImageCount() > 0)
2097 wxBitmap bmp
= imageList
->GetBitmap(0);
2099 // type = kDataBrowserIconAndTextType;
2102 SInt16 just
= teFlushDefault
;
2103 if (item
.GetMask() & wxLIST_MASK_FORMAT
)
2105 if (item
.GetAlign() == wxLIST_FORMAT_LEFT
)
2107 else if (item
.GetAlign() == wxLIST_FORMAT_CENTER
)
2109 else if (item
.GetAlign() == wxLIST_FORMAT_RIGHT
)
2110 just
= teFlushRight
;
2112 m_dbImpl
->InsertColumn(col
, type
, item
.GetText(), just
, width
);
2113 SetColumn(col
, item
);
2115 // set/remove options based on the wxListCtrl type.
2116 DataBrowserTableViewColumnID id
;
2117 m_dbImpl
->GetColumnIDFromIndex(col
, &id
);
2118 DataBrowserPropertyFlags flags
;
2119 verify_noerr(m_dbImpl
->GetPropertyFlags(id
, &flags
));
2120 if (GetWindowStyleFlag() & wxLC_EDIT_LABELS
)
2121 flags
|= kDataBrowserPropertyIsEditable
;
2123 if (GetWindowStyleFlag() & wxLC_VIRTUAL
){
2124 flags
&= ~kDataBrowserListViewSortableColumn
;
2126 verify_noerr(m_dbImpl
->SetPropertyFlags(id
, flags
));
2132 long wxListCtrl::InsertColumn(long col
,
2133 const wxString
& heading
,
2138 return m_genericImpl
->InsertColumn(col
, heading
, format
, width
);
2141 item
.m_mask
= wxLIST_MASK_TEXT
| wxLIST_MASK_FORMAT
;
2142 item
.m_text
= heading
;
2145 item
.m_mask
|= wxLIST_MASK_WIDTH
;
2146 item
.m_width
= width
;
2148 item
.m_format
= format
;
2150 return InsertColumn(col
, item
);
2153 // scroll the control by the given number of pixels (exception: in list view,
2154 // dx is interpreted as number of columns)
2155 bool wxListCtrl::ScrollList(int dx
, int dy
)
2158 return m_genericImpl
->ScrollList(dx
, dy
);
2162 m_dbImpl
->SetScrollPosition(dx
, dy
);
2168 bool wxListCtrl::SortItems(wxListCtrlCompare fn
, long data
)
2171 return m_genericImpl
->SortItems(fn
, data
);
2176 m_compareFuncData
= data
;
2177 SortDataBrowserContainer( m_dbImpl
->GetControlRef(), kDataBrowserNoItem
, true);
2179 // we need to do this after each call, else we get a crash from wxPython when
2180 // SortItems is called the second time.
2181 m_compareFunc
= NULL
;
2182 m_compareFuncData
= 0;
2188 void wxListCtrl::OnRenameTimer()
2190 wxCHECK_RET( HasCurrent(), wxT("unexpected rename timer") );
2192 EditLabel( m_current
);
2195 bool wxListCtrl::OnRenameAccept(long itemEdit
, const wxString
& value
)
2197 wxListEvent
le( wxEVT_COMMAND_LIST_END_LABEL_EDIT
, GetId() );
2198 le
.SetEventObject( this );
2199 le
.m_itemIndex
= itemEdit
;
2201 GetItem( le
.m_item
);
2202 le
.m_item
.m_text
= value
;
2203 return !HandleWindowEvent( le
) ||
2207 void wxListCtrl::OnRenameCancelled(long itemEdit
)
2209 // let owner know that the edit was cancelled
2210 wxListEvent
le( wxEVT_COMMAND_LIST_END_LABEL_EDIT
, GetParent()->GetId() );
2212 le
.SetEditCanceled(true);
2214 le
.SetEventObject( this );
2215 le
.m_itemIndex
= itemEdit
;
2217 GetItem( le
.m_item
);
2218 HandleWindowEvent( le
);
2221 // ----------------------------------------------------------------------------
2222 // virtual list controls
2223 // ----------------------------------------------------------------------------
2225 wxString
wxListCtrl::OnGetItemText(long WXUNUSED(item
), long WXUNUSED(col
)) const
2227 // this is a pure virtual function, in fact - which is not really pure
2228 // because the controls which are not virtual don't need to implement it
2229 wxFAIL_MSG( _T("wxListCtrl::OnGetItemText not supposed to be called") );
2231 return wxEmptyString
;
2234 int wxListCtrl::OnGetItemImage(long WXUNUSED(item
)) const
2236 wxCHECK_MSG(!GetImageList(wxIMAGE_LIST_SMALL
),
2238 wxT("List control has an image list, OnGetItemImage or OnGetItemColumnImage should be overridden."));
2242 int wxListCtrl::OnGetItemColumnImage(long item
, long column
) const
2245 return OnGetItemImage(item
);
2250 wxListItemAttr
*wxListCtrl::OnGetItemAttr(long WXUNUSED_UNLESS_DEBUG(item
)) const
2252 wxASSERT_MSG( item
>= 0 && item
< GetItemCount(),
2253 _T("invalid item index in OnGetItemAttr()") );
2255 // no attributes by default
2259 void wxListCtrl::SetItemCount(long count
)
2261 wxASSERT_MSG( IsVirtual(), _T("this is for virtual controls only") );
2265 m_genericImpl
->SetItemCount(count
);
2271 // we need to temporarily disable the new item creation notification
2272 // procedure to speed things up
2273 // FIXME: Even this doesn't seem to help much...
2275 // FIXME: Find a more efficient way to do this.
2276 m_dbImpl
->MacClear();
2278 DataBrowserCallbacks callbacks
;
2279 DataBrowserItemNotificationUPP itemUPP
;
2280 GetDataBrowserCallbacks(m_dbImpl
->GetControlRef(), &callbacks
);
2281 itemUPP
= callbacks
.u
.v1
.itemNotificationCallback
;
2282 callbacks
.u
.v1
.itemNotificationCallback
= 0;
2283 m_dbImpl
->SetCallbacks(&callbacks
);
2284 ::AddDataBrowserItems(m_dbImpl
->GetControlRef(), kDataBrowserNoItem
,
2285 count
, NULL
, kDataBrowserItemNoProperty
);
2286 callbacks
.u
.v1
.itemNotificationCallback
= itemUPP
;
2287 m_dbImpl
->SetCallbacks(&callbacks
);
2292 void wxListCtrl::RefreshItem(long item
)
2296 m_genericImpl
->RefreshItem(item
);
2302 DataBrowserItemID id
;
2306 wxMacDataItem
* thisItem
= m_dbImpl
->GetItemFromLine(item
);
2307 id
= (DataBrowserItemID
) thisItem
;
2312 m_dbImpl
->wxMacDataBrowserControl::UpdateItems
2316 kDataBrowserItemNoProperty
, // preSortProperty
2317 kDataBrowserNoItem
// update all columns
2322 void wxListCtrl::RefreshItems(long itemFrom
, long itemTo
)
2326 m_genericImpl
->RefreshItems(itemFrom
, itemTo
);
2332 const long count
= itemTo
- itemFrom
+ 1;
2333 DataBrowserItemID
*ids
= new DataBrowserItemID
[count
];
2337 for ( long i
= 0; i
< count
; i
++ )
2339 wxMacDataItem
* thisItem
= m_dbImpl
->GetItemFromLine(itemFrom
+i
);
2340 ids
[i
] = (DataBrowserItemID
) thisItem
;
2345 for ( long i
= 0; i
< count
; i
++ )
2346 ids
[i
] = itemFrom
+i
+1;
2349 m_dbImpl
->wxMacDataBrowserControl::UpdateItems
2353 kDataBrowserItemNoProperty
, // preSortProperty
2354 kDataBrowserNoItem
// update all columns
2361 void wxListCtrl::SetDropTarget( wxDropTarget
*dropTarget
)
2363 #if wxUSE_DRAG_AND_DROP
2365 m_genericImpl
->SetDropTarget( dropTarget
);
2368 wxWindow::SetDropTarget( dropTarget
);
2372 wxDropTarget
*wxListCtrl::GetDropTarget() const
2374 #if wxUSE_DRAG_AND_DROP
2376 return m_genericImpl
->GetDropTarget();
2379 return wxWindow::GetDropTarget();
2384 #if wxABI_VERSION >= 20801
2385 void wxListCtrl::SetFocus()
2389 m_genericImpl
->SetFocus();
2393 wxWindow::SetFocus();
2397 // wxMac internal data structures
2399 wxMacListCtrlItem::~wxMacListCtrlItem()
2403 void wxMacListCtrlItem::Notification(wxMacDataItemBrowserControl
*owner
,
2404 DataBrowserItemNotification message
,
2405 DataBrowserItemDataRef
WXUNUSED(itemData
) ) const
2408 wxMacDataBrowserListCtrlControl
*lb
= wxDynamicCast(owner
, wxMacDataBrowserListCtrlControl
);
2410 // we want to depend on as little as possible to make sure tear-down of controls is safe
2411 if ( message
== kDataBrowserItemRemoved
)
2413 if ( lb
!= NULL
&& lb
->GetClientDataType() == wxClientData_Object
)
2415 delete (wxClientData
*) (m_data
);
2421 else if ( message
== kDataBrowserItemAdded
)
2423 // we don't issue events on adding, the item is not really stored in the list yet, so we
2424 // avoid asserts by gettting out now
2428 wxListCtrl
*list
= wxDynamicCast( owner
->GetPeer() , wxListCtrl
);
2431 bool trigger
= false;
2433 wxListEvent
event( wxEVT_COMMAND_LIST_ITEM_SELECTED
, list
->GetId() );
2434 bool isSingle
= (list
->GetWindowStyle() & wxLC_SINGLE_SEL
) != 0;
2436 event
.SetEventObject( list
);
2437 event
.m_itemIndex
= owner
->GetLineFromItem( this ) ;
2438 event
.m_item
.m_itemId
= event
.m_itemIndex
;
2439 list
->GetItem(event
.m_item
);
2443 case kDataBrowserItemDeselected
:
2444 event
.SetEventType(wxEVT_COMMAND_LIST_ITEM_DESELECTED
);
2446 trigger
= !lb
->IsSelectionSuppressed();
2449 case kDataBrowserItemSelected
:
2450 trigger
= !lb
->IsSelectionSuppressed();
2453 case kDataBrowserItemDoubleClicked
:
2454 event
.SetEventType( wxEVT_COMMAND_LIST_ITEM_ACTIVATED
);
2458 case kDataBrowserEditStarted
:
2459 // TODO : how to veto ?
2460 event
.SetEventType( wxEVT_COMMAND_LIST_BEGIN_LABEL_EDIT
) ;
2464 case kDataBrowserEditStopped
:
2465 // TODO probably trigger only upon the value store callback, because
2466 // here IIRC we cannot veto
2467 event
.SetEventType( wxEVT_COMMAND_LIST_END_LABEL_EDIT
) ;
2477 // direct notification is not always having the listbox GetSelection() having in synch with event
2478 wxPostEvent( list
->GetEventHandler(), event
);
2484 IMPLEMENT_DYNAMIC_CLASS(wxMacDataBrowserListCtrlControl
, wxMacDataItemBrowserControl
)
2486 wxMacDataBrowserListCtrlControl::wxMacDataBrowserListCtrlControl( wxWindow
*peer
, const wxPoint
& pos
, const wxSize
& size
, long style
)
2487 : wxMacDataItemBrowserControl( peer
, pos
, size
, style
)
2489 OSStatus err
= noErr
;
2490 m_clientDataItemsType
= wxClientData_None
;
2491 m_isVirtual
= false;
2494 if ( style
& wxLC_VIRTUAL
)
2497 DataBrowserSelectionFlags options
= kDataBrowserDragSelect
;
2498 if ( style
& wxLC_SINGLE_SEL
)
2500 options
|= kDataBrowserSelectOnlyOne
;
2504 options
|= kDataBrowserCmdTogglesSelection
;
2507 err
= SetSelectionFlags( options
);
2508 verify_noerr( err
);
2510 DataBrowserCustomCallbacks callbacks
;
2511 InitializeDataBrowserCustomCallbacks( &callbacks
, kDataBrowserLatestCustomCallbacks
);
2513 if ( gDataBrowserDrawItemUPP
== NULL
)
2514 gDataBrowserDrawItemUPP
= NewDataBrowserDrawItemUPP(DataBrowserDrawItemProc
);
2516 if ( gDataBrowserHitTestUPP
== NULL
)
2517 gDataBrowserHitTestUPP
= NewDataBrowserHitTestUPP(DataBrowserHitTestProc
);
2519 callbacks
.u
.v1
.drawItemCallback
= gDataBrowserDrawItemUPP
;
2520 callbacks
.u
.v1
.hitTestCallback
= gDataBrowserHitTestUPP
;
2522 SetDataBrowserCustomCallbacks( GetControlRef(), &callbacks
);
2524 if ( style
& wxLC_LIST
)
2526 InsertColumn(0, kDataBrowserIconAndTextType
, wxEmptyString
, -1, -1);
2527 verify_noerr( AutoSizeColumns() );
2530 if ( style
& wxLC_LIST
|| style
& wxLC_NO_HEADER
)
2531 verify_noerr( SetHeaderButtonHeight( 0 ) );
2534 SetSortProperty( kMinColumnId
- 1 );
2536 SetSortProperty( kMinColumnId
);
2538 m_sortOrder
= SortOrder_None
;
2540 if ( style
& wxLC_SORT_DESCENDING
)
2542 SetSortOrder( kDataBrowserOrderDecreasing
);
2544 else if ( style
& wxLC_SORT_ASCENDING
)
2546 SetSortOrder( kDataBrowserOrderIncreasing
);
2549 if ( style
& wxLC_VRULES
)
2551 verify_noerr( DataBrowserChangeAttributes(m_controlRef
, kDataBrowserAttributeListViewDrawColumnDividers
, kDataBrowserAttributeNone
) );
2554 verify_noerr( SetHiliteStyle(kDataBrowserTableViewFillHilite
) );
2555 verify_noerr( SetHasScrollBars( (style
& wxHSCROLL
) != 0 , true ) );
2558 pascal Boolean
wxMacDataBrowserListCtrlControl::DataBrowserEditTextProc(
2560 DataBrowserItemID itemID
,
2561 DataBrowserPropertyID property
,
2562 CFStringRef theString
,
2563 Rect
*maxEditTextRect
,
2564 Boolean
*shrinkToFit
)
2566 Boolean result
= false;
2567 wxMacDataBrowserListCtrlControl
* ctl
= wxDynamicCast(wxMacControl::GetReferenceFromNativeControl( browser
), wxMacDataBrowserListCtrlControl
);
2570 result
= ctl
->ConfirmEditText(itemID
, property
, theString
, maxEditTextRect
, shrinkToFit
);
2571 theString
= CFSTR("Hello!");
2576 bool wxMacDataBrowserListCtrlControl::ConfirmEditText(
2577 DataBrowserItemID
WXUNUSED(itemID
),
2578 DataBrowserPropertyID
WXUNUSED(property
),
2579 CFStringRef
WXUNUSED(theString
),
2580 Rect
*WXUNUSED(maxEditTextRect
),
2581 Boolean
*WXUNUSED(shrinkToFit
))
2586 pascal void wxMacDataBrowserListCtrlControl::DataBrowserDrawItemProc(
2588 DataBrowserItemID itemID
,
2589 DataBrowserPropertyID property
,
2590 DataBrowserItemState itemState
,
2591 const Rect
*itemRect
,
2593 Boolean colorDevice
)
2595 wxMacDataBrowserListCtrlControl
* ctl
= wxDynamicCast(wxMacControl::GetReferenceFromNativeControl( browser
), wxMacDataBrowserListCtrlControl
);
2598 ctl
->DrawItem(itemID
, property
, itemState
, itemRect
, gdDepth
, colorDevice
);
2602 // routines needed for DrawItem
2607 kTextBoxHeight
= 14,
2608 kIconTextSpacingV
= 2,
2610 kContentHeight
= kIconHeight
+ kTextBoxHeight
+ kIconTextSpacingV
2613 static void calculateCGDrawingBounds(CGRect inItemRect
, CGRect
*outIconRect
, CGRect
*outTextRect
, bool hasIcon
= false)
2616 float iconH
, iconW
= 0;
2617 float padding
= kItemPadding
;
2620 iconH
= kIconHeight
;
2622 padding
= padding
*2;
2625 textBottom
= inItemRect
.origin
.y
;
2627 *outIconRect
= CGRectMake(inItemRect
.origin
.x
+ kItemPadding
,
2628 textBottom
+ kIconTextSpacingV
, kIconWidth
,
2631 *outTextRect
= CGRectMake(inItemRect
.origin
.x
+ padding
+ iconW
,
2632 textBottom
+ kIconTextSpacingV
, inItemRect
.size
.width
- padding
- iconW
,
2633 inItemRect
.size
.height
- kIconTextSpacingV
);
2636 void wxMacDataBrowserListCtrlControl::DrawItem(
2637 DataBrowserItemID itemID
,
2638 DataBrowserPropertyID property
,
2639 DataBrowserItemState itemState
,
2640 const Rect
*WXUNUSED(itemRect
),
2642 Boolean colorDevice
)
2645 wxFont font
= wxNullFont
;
2647 short listColumn
= property
- kMinColumnId
;
2649 wxListCtrl
* list
= wxDynamicCast( GetPeer() , wxListCtrl
);
2650 wxMacListCtrlItem
* lcItem
;
2651 wxColour color
= *wxBLACK
;
2652 wxColour bgColor
= wxNullColour
;
2654 if (listColumn
>= 0)
2658 lcItem
= (wxMacListCtrlItem
*) itemID
;
2659 if (lcItem
->HasColumnInfo(listColumn
)){
2660 wxListItem
* item
= lcItem
->GetColumnInfo(listColumn
);
2662 // we always use the 0 column to get font and text/background colors.
2663 if (lcItem
->HasColumnInfo(0))
2665 wxListItem
* firstItem
= lcItem
->GetColumnInfo(0);
2666 color
= firstItem
->GetTextColour();
2667 bgColor
= firstItem
->GetBackgroundColour();
2668 font
= firstItem
->GetFont();
2671 if (item
->GetMask() & wxLIST_MASK_TEXT
)
2672 text
= item
->GetText();
2673 if (item
->GetMask() & wxLIST_MASK_IMAGE
)
2674 imgIndex
= item
->GetImage();
2680 long itemNum
= (long)itemID
-1;
2681 if (itemNum
>= 0 && itemNum
< list
->GetItemCount())
2683 text
= list
->OnGetItemText( itemNum
, listColumn
);
2684 imgIndex
= list
->OnGetItemColumnImage( itemNum
, listColumn
);
2685 wxListItemAttr
* attrs
= list
->OnGetItemAttr( itemNum
);
2688 if (attrs
->HasBackgroundColour())
2689 bgColor
= attrs
->GetBackgroundColour();
2690 if (attrs
->HasTextColour())
2691 color
= attrs
->GetTextColour();
2692 if (attrs
->HasFont())
2693 font
= attrs
->GetFont();
2699 wxColour listBgColor
= list
->GetBackgroundColour();
2700 if (bgColor
== wxNullColour
)
2701 bgColor
= listBgColor
;
2703 wxFont listFont
= list
->GetFont();
2704 if (font
== wxNullFont
)
2707 wxCFStringRef
cfString( text
, wxLocale::GetSystemEncoding() );
2710 CGRect enclosingCGRect
, iconCGRect
, textCGRect
;
2712 ThemeDrawingState savedState
= NULL
;
2713 CGContextRef context
= (CGContextRef
)list
->MacGetDrawingContext();
2714 RGBColor labelColor
;
2716 labelColor
.green
= 0;
2717 labelColor
.blue
= 0;
2719 RGBColor backgroundColor
;
2720 backgroundColor
.red
= 255;
2721 backgroundColor
.green
= 255;
2722 backgroundColor
.blue
= 255;
2724 GetDataBrowserItemPartBounds(GetControlRef(), itemID
, property
, kDataBrowserPropertyEnclosingPart
,
2727 enclosingCGRect
= CGRectMake(enclosingRect
.left
,
2729 enclosingRect
.right
- enclosingRect
.left
,
2730 enclosingRect
.bottom
- enclosingRect
.top
);
2732 bool hasFocus
= (wxWindow::FindFocus() == list
);
2733 active
= IsControlActive(GetControlRef());
2735 // don't paint the background over the vertical rule line
2736 if ( list
->GetWindowStyleFlag() & wxLC_VRULES
)
2738 enclosingCGRect
.origin
.x
+= 1;
2739 enclosingCGRect
.size
.width
-= 1;
2741 if (itemState
== kDataBrowserItemIsSelected
)
2744 GetThemeDrawingState(&savedState
);
2746 if (active
&& hasFocus
)
2748 GetThemeBrushAsColor(kThemeBrushAlternatePrimaryHighlightColor
, 32, true, &backgroundColor
);
2749 GetThemeTextColor(kThemeTextColorWhite
, gdDepth
, colorDevice
, &labelColor
);
2753 GetThemeBrushAsColor(kThemeBrushSecondaryHighlightColor
, 32, true, &backgroundColor
);
2754 GetThemeTextColor(kThemeTextColorBlack
, gdDepth
, colorDevice
, &labelColor
);
2756 CGContextSaveGState(context
);
2758 CGContextSetRGBFillColor(context
, (float)backgroundColor
.red
/ (float)USHRT_MAX
,
2759 (float)backgroundColor
.green
/ (float)USHRT_MAX
,
2760 (float)backgroundColor
.blue
/ (float)USHRT_MAX
, 1.0);
2761 CGContextFillRect(context
, enclosingCGRect
);
2763 CGContextRestoreGState(context
);
2769 color
.GetRGBColor(&labelColor
);
2770 else if (list
->GetTextColour().Ok())
2771 list
->GetTextColour().GetRGBColor(&labelColor
);
2775 bgColor
.GetRGBColor(&backgroundColor
);
2776 CGContextSaveGState(context
);
2778 CGContextSetRGBFillColor(context
, (float)backgroundColor
.red
/ (float)USHRT_MAX
,
2779 (float)backgroundColor
.green
/ (float)USHRT_MAX
,
2780 (float)backgroundColor
.blue
/ (float)USHRT_MAX
, 1.0);
2781 CGContextFillRect(context
, enclosingCGRect
);
2783 CGContextRestoreGState(context
);
2787 calculateCGDrawingBounds(enclosingCGRect
, &iconCGRect
, &textCGRect
, (imgIndex
!= -1) );
2791 wxImageList
* imageList
= list
->GetImageList(wxIMAGE_LIST_SMALL
);
2792 if (imageList
&& imageList
->GetImageCount() > 0){
2793 wxBitmap bmp
= imageList
->GetBitmap(imgIndex
);
2794 IconRef icon
= bmp
.GetIconRef();
2796 CGContextSaveGState(context
);
2797 CGContextTranslateCTM(context
, 0,iconCGRect
.origin
.y
+ CGRectGetMaxY(iconCGRect
));
2798 CGContextScaleCTM(context
,1.0f
,-1.0f
);
2799 PlotIconRefInContext(context
, &iconCGRect
, kAlignNone
,
2800 active
? kTransformNone
: kTransformDisabled
, NULL
,
2801 kPlotIconRefNormalFlags
, icon
);
2803 CGContextRestoreGState(context
);
2807 HIThemeTextHorizontalFlush hFlush
= kHIThemeTextHorizontalFlushLeft
;
2808 HIThemeTextInfo info
;
2810 #if wxMAC_USE_CORE_TEXT
2811 if ( UMAGetSystemVersion() >= 0x1050 )
2813 info
.version
= kHIThemeTextInfoVersionOne
;
2814 info
.fontID
= kThemeViewsFont
;
2817 info
.fontID
= kThemeSpecifiedFont
;
2818 info
.font
= (CTFontRef
) font
.MacGetCTFont();
2823 #if wxMAC_USE_ATSU_TEXT
2826 info
.version
= kHIThemeTextInfoVersionZero
;
2827 info
.fontID
= kThemeViewsFont
;
2831 if (font
.GetFamily() != wxFONTFAMILY_DEFAULT
)
2832 info
.fontID
= font
.MacGetThemeFontID();
2834 ::TextSize( (short)(font
.MacGetFontSize()) ) ;
2835 ::TextFace( font
.MacGetFontStyle() ) ;
2841 list
->GetColumn(listColumn
, item
);
2842 if (item
.GetMask() & wxLIST_MASK_FORMAT
)
2844 if (item
.GetAlign() == wxLIST_FORMAT_LEFT
)
2845 hFlush
= kHIThemeTextHorizontalFlushLeft
;
2846 else if (item
.GetAlign() == wxLIST_FORMAT_CENTER
)
2847 hFlush
= kHIThemeTextHorizontalFlushCenter
;
2848 else if (item
.GetAlign() == wxLIST_FORMAT_RIGHT
)
2850 hFlush
= kHIThemeTextHorizontalFlushRight
;
2851 textCGRect
.origin
.x
-= kItemPadding
; // give a little extra paddding
2855 info
.state
= active
? kThemeStateActive
: kThemeStateInactive
;
2856 info
.horizontalFlushness
= hFlush
;
2857 info
.verticalFlushness
= kHIThemeTextVerticalFlushCenter
;
2858 info
.options
= kHIThemeTextBoxOptionNone
;
2859 info
.truncationPosition
= kHIThemeTextTruncationEnd
;
2860 info
.truncationMaxLines
= 1;
2862 CGContextSaveGState(context
);
2863 CGContextSetRGBFillColor (context
, (float)labelColor
.red
/ (float)USHRT_MAX
,
2864 (float)labelColor
.green
/ (float)USHRT_MAX
,
2865 (float)labelColor
.blue
/ (float)USHRT_MAX
, 1.0);
2867 HIThemeDrawTextBox(cfString
, &textCGRect
, &info
, context
, kHIThemeOrientationNormal
);
2869 CGContextRestoreGState(context
);
2872 if (savedState
!= NULL
)
2873 SetThemeDrawingState(savedState
, true);
2877 OSStatus
wxMacDataBrowserListCtrlControl::GetSetItemData(DataBrowserItemID itemID
,
2878 DataBrowserPropertyID property
,
2879 DataBrowserItemDataRef itemData
,
2880 Boolean changeValue
)
2884 short listColumn
= property
- kMinColumnId
;
2886 OSStatus err
= errDataBrowserPropertyNotSupported
;
2887 wxListCtrl
* list
= wxDynamicCast( GetPeer() , wxListCtrl
);
2888 wxMacListCtrlItem
* lcItem
;
2890 if (listColumn
>= 0)
2894 lcItem
= (wxMacListCtrlItem
*) itemID
;
2895 if (lcItem
&& lcItem
->HasColumnInfo(listColumn
)){
2896 wxListItem
* item
= lcItem
->GetColumnInfo(listColumn
);
2897 if (item
->GetMask() & wxLIST_MASK_TEXT
)
2898 text
= item
->GetText();
2899 if (item
->GetMask() & wxLIST_MASK_IMAGE
)
2900 imgIndex
= item
->GetImage();
2905 long itemNum
= (long)itemID
-1;
2906 if (itemNum
>= 0 && itemNum
< list
->GetItemCount())
2908 text
= list
->OnGetItemText( itemNum
, listColumn
);
2909 imgIndex
= list
->OnGetItemColumnImage( itemNum
, listColumn
);
2918 case kDataBrowserItemIsEditableProperty
:
2919 if ( list
&& list
->HasFlag( wxLC_EDIT_LABELS
) )
2921 verify_noerr(SetDataBrowserItemDataBooleanValue( itemData
, true ));
2926 if ( property
>= kMinColumnId
)
2928 if (!text
.IsEmpty()){
2929 wxCFStringRef
cfStr( text
, wxLocale::GetSystemEncoding() );
2930 err
= ::SetDataBrowserItemDataText( itemData
, cfStr
);
2936 if ( imgIndex
!= -1 )
2938 wxImageList
* imageList
= list
->GetImageList(wxIMAGE_LIST_SMALL
);
2939 if (imageList
&& imageList
->GetImageCount() > 0){
2940 wxBitmap bmp
= imageList
->GetBitmap(imgIndex
);
2941 IconRef icon
= bmp
.GetIconRef();
2942 ::SetDataBrowserItemDataIcon(itemData
, icon
);
2956 if ( property
>= kMinColumnId
)
2958 short listColumn
= property
- kMinColumnId
;
2960 // TODO probably send the 'end edit' from here, as we
2961 // can then deal with the veto
2963 verify_noerr( GetDataBrowserItemDataText( itemData
, &sr
) ) ;
2964 wxCFStringRef
cfStr(sr
) ;;
2966 list
->SetItem( (long)itemData
-1 , listColumn
, cfStr
.AsString() ) ;
2970 lcItem
->SetColumnTextValue( listColumn
, cfStr
.AsString() );
2980 void wxMacDataBrowserListCtrlControl::ItemNotification(DataBrowserItemID itemID
,
2981 DataBrowserItemNotification message
,
2982 DataBrowserItemDataRef
WXUNUSED(itemData
) )
2984 // we want to depend on as little as possible to make sure tear-down of controls is safe
2985 if ( message
== kDataBrowserItemRemoved
)
2987 // make sure MacDelete does the proper teardown.
2990 else if ( message
== kDataBrowserItemAdded
)
2992 // we don't issue events on adding, the item is not really stored in the list yet, so we
2993 // avoid asserts by getting out now
2997 wxListCtrl
*list
= wxDynamicCast( GetPeer() , wxListCtrl
);
3000 bool trigger
= false;
3002 wxListEvent
event( wxEVT_COMMAND_LIST_ITEM_SELECTED
, list
->GetId() );
3004 event
.SetEventObject( list
);
3005 if ( !list
->IsVirtual() )
3007 DataBrowserTableViewRowIndex result
= 0;
3008 verify_noerr( GetItemRow( itemID
, &result
) ) ;
3009 event
.m_itemIndex
= result
;
3013 event
.m_itemIndex
= (long)itemID
-1;
3015 event
.m_item
.m_itemId
= event
.m_itemIndex
;
3016 list
->GetItem(event
.m_item
);
3020 case kDataBrowserItemDeselected
:
3021 event
.SetEventType(wxEVT_COMMAND_LIST_ITEM_DESELECTED
);
3022 // as the generic implementation is also triggering this
3023 // event for single selection, we do the same (different than listbox)
3024 trigger
= !IsSelectionSuppressed();
3027 case kDataBrowserItemSelected
:
3028 trigger
= !IsSelectionSuppressed();
3032 case kDataBrowserItemDoubleClicked
:
3033 event
.SetEventType( wxEVT_COMMAND_LIST_ITEM_ACTIVATED
);
3037 case kDataBrowserEditStarted
:
3038 // TODO : how to veto ?
3039 event
.SetEventType( wxEVT_COMMAND_LIST_BEGIN_LABEL_EDIT
) ;
3043 case kDataBrowserEditStopped
:
3044 // TODO probably trigger only upon the value store callback, because
3045 // here IIRC we cannot veto
3046 event
.SetEventType( wxEVT_COMMAND_LIST_END_LABEL_EDIT
) ;
3056 // direct notification is not always having the listbox GetSelection() having in synch with event
3057 wxPostEvent( list
->GetEventHandler(), event
);
3062 Boolean
wxMacDataBrowserListCtrlControl::CompareItems(DataBrowserItemID itemOneID
,
3063 DataBrowserItemID itemTwoID
,
3064 DataBrowserPropertyID sortProperty
)
3067 bool retval
= false;
3069 wxString otherItemText
;
3071 long otherItemOrder
;
3073 int colId
= sortProperty
- kMinColumnId
;
3075 wxListCtrl
* list
= wxDynamicCast( GetPeer() , wxListCtrl
);
3077 DataBrowserSortOrder sort
;
3078 verify_noerr(GetSortOrder(&sort
));
3084 wxMacListCtrlItem
* item
= (wxMacListCtrlItem
*)itemOneID
;
3085 wxMacListCtrlItem
* otherItem
= (wxMacListCtrlItem
*)itemTwoID
;
3087 itemOrder
= item
->GetOrder();
3088 otherItemOrder
= item
->GetOrder();
3090 wxListCtrlCompare func
= list
->GetCompareFunc();
3095 if (item
&& item
->HasColumnInfo(0))
3096 item1
= item
->GetColumnInfo(0)->GetData();
3097 if (otherItem
&& otherItem
->HasColumnInfo(0))
3098 item2
= otherItem
->GetColumnInfo(0)->GetData();
3100 if (item1
> -1 && item2
> -1)
3102 int result
= func(item1
, item2
, list
->GetCompareFuncData());
3103 if (sort
== kDataBrowserOrderIncreasing
)
3110 // we can't use the native control's sorting abilities, so just
3112 return itemOrder
< otherItemOrder
;
3117 long itemNum
= (long)itemOneID
;
3118 long otherItemNum
= (long)itemTwoID
;
3120 // virtual listctrls don't support sorting
3121 return itemNum
< otherItemNum
;
3125 // fallback for undefined cases
3126 retval
= itemOneID
< itemTwoID
;
3132 wxMacDataBrowserListCtrlControl::~wxMacDataBrowserListCtrlControl()
3136 void wxMacDataBrowserListCtrlControl::MacSetColumnInfo( unsigned int row
, unsigned int column
, wxListItem
* item
)
3138 wxMacDataItem
* dataItem
= GetItemFromLine(row
);
3139 wxASSERT_MSG( dataItem
, _T("could not obtain wxMacDataItem for row in MacSetColumnInfo. Is row a valid wxListCtrl row?") );
3142 wxMacListCtrlItem
* listItem
= wx_static_cast(wxMacListCtrlItem
*,dataItem
);
3143 bool hasInfo
= listItem
->HasColumnInfo( column
);
3144 listItem
->SetColumnInfo( column
, item
);
3145 listItem
->SetOrder(row
);
3146 UpdateState(dataItem
, item
);
3148 wxListCtrl
* list
= wxDynamicCast( GetPeer() , wxListCtrl
);
3150 // NB: When this call was made before a control was completely shown, it would
3151 // update the item prematurely (i.e. no text would be listed) and, on show,
3152 // only the sorted column would be refreshed, meaning only first column text labels
3153 // would be shown. Making sure not to update items until the control is visible
3154 // seems to fix this issue.
3155 if (hasInfo
&& list
->IsShown())
3156 UpdateItem( wxMacDataBrowserRootContainer
, listItem
, kMinColumnId
+ column
);
3160 // apply changes that need to happen immediately, rather than when the
3161 // databrowser control fires a callback.
3162 void wxMacDataBrowserListCtrlControl::UpdateState(wxMacDataItem
* dataItem
, wxListItem
* listItem
)
3164 bool isSelected
= IsItemSelected( dataItem
);
3165 bool isSelectedState
= (listItem
->GetState() == wxLIST_STATE_SELECTED
);
3167 // toggle the selection state if wxListInfo state and actual state don't match.
3168 if ( listItem
->GetMask() & wxLIST_MASK_STATE
&& isSelected
!= isSelectedState
)
3170 DataBrowserSetOption options
= kDataBrowserItemsAdd
;
3171 if (!isSelectedState
)
3172 options
= kDataBrowserItemsRemove
;
3173 SetSelectedItem(dataItem
, options
);
3175 // TODO: Set column width if item width > than current column width
3178 void wxMacDataBrowserListCtrlControl::MacGetColumnInfo( unsigned int row
, unsigned int column
, wxListItem
& item
)
3180 wxMacDataItem
* dataItem
= GetItemFromLine(row
);
3181 wxASSERT_MSG( dataItem
, _T("could not obtain wxMacDataItem in MacGetColumnInfo. Is row a valid wxListCtrl row?") );
3182 // CS should this guard against dataItem = 0 ? , as item is not a pointer if (item) is not appropriate
3185 wxMacListCtrlItem
* listItem
=wx_static_cast(wxMacListCtrlItem
*,dataItem
);
3187 if (!listItem
->HasColumnInfo( column
))
3190 wxListItem
* oldItem
= listItem
->GetColumnInfo( column
);
3194 long mask
= item
.GetMask();
3196 // by default, get everything for backwards compatibility
3199 if ( mask
& wxLIST_MASK_TEXT
)
3200 item
.SetText(oldItem
->GetText());
3201 if ( mask
& wxLIST_MASK_IMAGE
)
3202 item
.SetImage(oldItem
->GetImage());
3203 if ( mask
& wxLIST_MASK_DATA
)
3204 item
.SetData(oldItem
->GetData());
3205 if ( mask
& wxLIST_MASK_STATE
)
3206 item
.SetState(oldItem
->GetState());
3207 if ( mask
& wxLIST_MASK_WIDTH
)
3208 item
.SetWidth(oldItem
->GetWidth());
3209 if ( mask
& wxLIST_MASK_FORMAT
)
3210 item
.SetAlign(oldItem
->GetAlign());
3212 item
.SetTextColour(oldItem
->GetTextColour());
3213 item
.SetBackgroundColour(oldItem
->GetBackgroundColour());
3214 item
.SetFont(oldItem
->GetFont());
3219 void wxMacDataBrowserListCtrlControl::MacInsertItem( unsigned int n
, wxListItem
* item
)
3221 wxMacDataItemBrowserControl::MacInsert(n
, item
->GetText());
3222 MacSetColumnInfo(n
, 0, item
);
3225 wxMacDataItem
* wxMacDataBrowserListCtrlControl::CreateItem()
3227 return new wxMacListCtrlItem();
3230 wxMacListCtrlItem::wxMacListCtrlItem()
3232 m_rowItems
= wxListItemList();
3235 int wxMacListCtrlItem::GetColumnImageValue( unsigned int column
)
3237 if ( HasColumnInfo(column
) )
3238 return GetColumnInfo(column
)->GetImage();
3243 void wxMacListCtrlItem::SetColumnImageValue( unsigned int column
, int imageIndex
)
3245 if ( HasColumnInfo(column
) )
3246 GetColumnInfo(column
)->SetImage(imageIndex
);
3249 wxString
wxMacListCtrlItem::GetColumnTextValue( unsigned int column
)
3254 if ( HasColumnInfo(column
) )
3255 return GetColumnInfo(column
)->GetText();
3257 return wxEmptyString
;
3260 void wxMacListCtrlItem::SetColumnTextValue( unsigned int column
, const wxString
& text
)
3262 if ( HasColumnInfo(column
) )
3263 GetColumnInfo(column
)->SetText(text
);
3265 // for compatibility with superclass APIs
3270 wxListItem
* wxMacListCtrlItem::GetColumnInfo( unsigned int column
)
3272 wxASSERT_MSG( HasColumnInfo(column
), _T("invalid column index in wxMacListCtrlItem") );
3273 return m_rowItems
[column
];
3276 bool wxMacListCtrlItem::HasColumnInfo( unsigned int column
)
3278 return !(m_rowItems
.find( column
) == m_rowItems
.end());
3281 void wxMacListCtrlItem::SetColumnInfo( unsigned int column
, wxListItem
* item
)
3284 if ( !HasColumnInfo(column
) )
3286 wxListItem
* listItem
= new wxListItem(*item
);
3287 m_rowItems
[column
] = listItem
;
3291 wxListItem
* listItem
= GetColumnInfo( column
);
3292 long mask
= item
->GetMask();
3293 if (mask
& wxLIST_MASK_TEXT
)
3294 listItem
->SetText(item
->GetText());
3295 if (mask
& wxLIST_MASK_DATA
)
3296 listItem
->SetData(item
->GetData());
3297 if (mask
& wxLIST_MASK_IMAGE
)
3298 listItem
->SetImage(item
->GetImage());
3299 if (mask
& wxLIST_MASK_STATE
)
3300 listItem
->SetState(item
->GetState());
3301 if (mask
& wxLIST_MASK_FORMAT
)
3302 listItem
->SetAlign(item
->GetAlign());
3303 if (mask
& wxLIST_MASK_WIDTH
)
3304 listItem
->SetWidth(item
->GetWidth());
3306 if ( item
->HasAttributes() )
3308 if ( listItem
->HasAttributes() )
3309 listItem
->GetAttributes()->AssignFrom(*item
->GetAttributes());
3312 listItem
->SetTextColour(item
->GetTextColour());
3313 listItem
->SetBackgroundColour(item
->GetBackgroundColour());
3314 listItem
->SetFont(item
->GetFont());
3320 #endif // wxUSE_LISTCTRL