1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/mac/listctrl_mac.cpp
4 // Author: Julian Smart
5 // Modified by: Agron Selimaj
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 // ============================================================================
14 // ============================================================================
16 // ----------------------------------------------------------------------------
18 // ----------------------------------------------------------------------------
20 // For compilers that support precompilation, includes "wx.h".
21 #include "wx/wxprec.h"
29 #include "wx/listctrl.h"
35 #include "wx/mac/uma.h"
37 #include "wx/imaglist.h"
38 #include "wx/sysopt.h"
41 #include "wx/hashmap.h"
43 #if wxUSE_EXTENDED_RTTI
44 WX_DEFINE_FLAGS( wxListCtrlStyle
)
46 wxBEGIN_FLAGS( wxListCtrlStyle
)
47 // new style border flags, we put them first to
48 // use them for streaming out
49 wxFLAGS_MEMBER(wxBORDER_SIMPLE
)
50 wxFLAGS_MEMBER(wxBORDER_SUNKEN
)
51 wxFLAGS_MEMBER(wxBORDER_DOUBLE
)
52 wxFLAGS_MEMBER(wxBORDER_RAISED
)
53 wxFLAGS_MEMBER(wxBORDER_STATIC
)
54 wxFLAGS_MEMBER(wxBORDER_NONE
)
56 // old style border flags
57 wxFLAGS_MEMBER(wxSIMPLE_BORDER
)
58 wxFLAGS_MEMBER(wxSUNKEN_BORDER
)
59 wxFLAGS_MEMBER(wxDOUBLE_BORDER
)
60 wxFLAGS_MEMBER(wxRAISED_BORDER
)
61 wxFLAGS_MEMBER(wxSTATIC_BORDER
)
62 wxFLAGS_MEMBER(wxBORDER
)
64 // standard window styles
65 wxFLAGS_MEMBER(wxTAB_TRAVERSAL
)
66 wxFLAGS_MEMBER(wxCLIP_CHILDREN
)
67 wxFLAGS_MEMBER(wxTRANSPARENT_WINDOW
)
68 wxFLAGS_MEMBER(wxWANTS_CHARS
)
69 wxFLAGS_MEMBER(wxFULL_REPAINT_ON_RESIZE
)
70 wxFLAGS_MEMBER(wxALWAYS_SHOW_SB
)
71 wxFLAGS_MEMBER(wxVSCROLL
)
72 wxFLAGS_MEMBER(wxHSCROLL
)
74 wxFLAGS_MEMBER(wxLC_LIST
)
75 wxFLAGS_MEMBER(wxLC_REPORT
)
76 wxFLAGS_MEMBER(wxLC_ICON
)
77 wxFLAGS_MEMBER(wxLC_SMALL_ICON
)
78 wxFLAGS_MEMBER(wxLC_ALIGN_TOP
)
79 wxFLAGS_MEMBER(wxLC_ALIGN_LEFT
)
80 wxFLAGS_MEMBER(wxLC_AUTOARRANGE
)
81 wxFLAGS_MEMBER(wxLC_USER_TEXT
)
82 wxFLAGS_MEMBER(wxLC_EDIT_LABELS
)
83 wxFLAGS_MEMBER(wxLC_NO_HEADER
)
84 wxFLAGS_MEMBER(wxLC_SINGLE_SEL
)
85 wxFLAGS_MEMBER(wxLC_SORT_ASCENDING
)
86 wxFLAGS_MEMBER(wxLC_SORT_DESCENDING
)
87 wxFLAGS_MEMBER(wxLC_VIRTUAL
)
89 wxEND_FLAGS( wxListCtrlStyle
)
91 IMPLEMENT_DYNAMIC_CLASS_XTI(wxListCtrl
, wxControl
,"wx/listctrl.h")
93 wxBEGIN_PROPERTIES_TABLE(wxListCtrl
)
94 wxEVENT_PROPERTY( TextUpdated
, wxEVT_COMMAND_TEXT_UPDATED
, wxCommandEvent
)
96 wxPROPERTY_FLAGS( WindowStyle
, wxListCtrlStyle
, long , SetWindowStyleFlag
, GetWindowStyleFlag
, EMPTY_MACROVALUE
, 0 /*flags*/ , wxT("Helpstring") , wxT("group")) // style
97 wxEND_PROPERTIES_TABLE()
99 wxBEGIN_HANDLERS_TABLE(wxListCtrl
)
100 wxEND_HANDLERS_TABLE()
102 wxCONSTRUCTOR_5( wxListCtrl
, wxWindow
* , Parent
, wxWindowID
, Id
, wxPoint
, Position
, wxSize
, Size
, long , WindowStyle
)
105 TODO : Expose more information of a list's layout etc. via appropriate objects (à la NotebookPageInfo)
108 IMPLEMENT_DYNAMIC_CLASS(wxListCtrl
, wxControl
)
111 IMPLEMENT_DYNAMIC_CLASS(wxListView
, wxListCtrl
)
112 IMPLEMENT_DYNAMIC_CLASS(wxListItem
, wxObject
)
114 IMPLEMENT_DYNAMIC_CLASS(wxListEvent
, wxNotifyEvent
)
116 WX_DECLARE_HASH_MAP( int, wxListItem
*, wxIntegerHash
, wxIntegerEqual
, wxListItemList
);
118 #include "wx/listimpl.cpp"
119 WX_DEFINE_LIST(wxColumnList
)
121 // so we can check for column clicks
122 static const EventTypeSpec eventList
[] =
124 { kEventClassControl
, kEventControlHit
},
125 { kEventClassControl
, kEventControlDraw
}
128 static pascal OSStatus
wxMacListCtrlEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
130 OSStatus result
= eventNotHandledErr
;
132 wxMacCarbonEvent
cEvent( event
) ;
134 ControlRef controlRef
;
135 cEvent
.GetParameter( kEventParamDirectObject
, &controlRef
) ;
137 wxListCtrl
*window
= (wxListCtrl
*) data
;
138 wxListEvent
le( wxEVT_COMMAND_LIST_COL_CLICK
, window
->GetId() );
139 le
.SetEventObject( window
);
141 switch ( GetEventKind( event
) )
143 // check if the column was clicked on and fire an event if so
144 case kEventControlHit
:
146 ControlPartCode result
= cEvent
.GetParameter
<ControlPartCode
>(kEventParamControlPart
, typeControlPartCode
) ;
147 if (result
== kControlButtonPart
){
148 DataBrowserPropertyID col
;
149 GetDataBrowserSortProperty(controlRef
, &col
);
150 int column
= col
- kMinColumnId
;
152 // FIXME: we can't use the sort property for virtual listctrls
153 // so we need to find a better way to determine which column was clicked...
154 if (!window
->IsVirtual())
155 window
->GetEventHandler()->ProcessEvent( le
);
157 result
= CallNextEventHandler(handler
, event
);
160 case kEventControlDraw
:
162 CGContextRef context
= cEvent
.GetParameter
<CGContextRef
>(kEventParamCGContextRef
, typeCGContextRef
) ;
163 window
->MacSetDrawingContext(context
);
164 result
= CallNextEventHandler(handler
, event
);
165 window
->MacSetDrawingContext(NULL
);
176 DEFINE_ONE_SHOT_HANDLER_GETTER( wxMacListCtrlEventHandler
)
178 class wxMacListCtrlItem
: public wxMacListBoxItem
183 virtual void Notification(wxMacDataItemBrowserControl
*owner
,
184 DataBrowserItemNotification message
,
185 DataBrowserItemDataRef itemData
) const;
187 virtual void SetColumnInfo( unsigned int column
, wxListItem
* item
);
188 virtual wxListItem
* GetColumnInfo( unsigned int column
);
189 virtual bool HasColumnInfo( unsigned int column
);
191 virtual void SetColumnTextValue( unsigned int column
, const wxString
& text
);
192 virtual wxString
GetColumnTextValue( unsigned int column
);
194 virtual int GetColumnImageValue( unsigned int column
);
195 virtual void SetColumnImageValue( unsigned int column
, int imageIndex
);
197 virtual ~wxMacListCtrlItem();
199 wxListItemList m_rowItems
;
202 DataBrowserDrawItemUPP gDataBrowserDrawItemUPP
= NULL
;
203 //DataBrowserEditItemUPP gDataBrowserEditItemUPP = NULL;
204 DataBrowserHitTestUPP gDataBrowserHitTestUPP
= NULL
;
206 // TODO: Make a better name!!
207 class wxMacDataBrowserListCtrlControl
: public wxMacDataItemBrowserControl
210 wxMacDataBrowserListCtrlControl( wxWindow
*peer
, const wxPoint
& pos
, const wxSize
& size
, long style
);
211 wxMacDataBrowserListCtrlControl() {}
212 virtual ~wxMacDataBrowserListCtrlControl();
214 // create a list item (can be a subclass of wxMacListBoxItem)
216 virtual wxMacDataItem
* CreateItem();
218 virtual void MacInsertItem( unsigned int n
, wxListItem
* item
);
219 virtual void MacSetColumnInfo( unsigned int row
, unsigned int column
, wxListItem
* item
);
220 virtual void MacGetColumnInfo( unsigned int row
, unsigned int column
, wxListItem
& item
);
221 virtual void UpdateState(wxMacDataItem
* dataItem
, wxListItem
* item
);
222 int GetFlags() { return m_flags
; }
225 // we need to override to provide specialized handling for virtual wxListCtrls
226 virtual OSStatus
GetSetItemData(DataBrowserItemID itemID
,
227 DataBrowserPropertyID property
,
228 DataBrowserItemDataRef itemData
,
229 Boolean changeValue
);
231 virtual void ItemNotification(
232 DataBrowserItemID itemID
,
233 DataBrowserItemNotification message
,
234 DataBrowserItemDataRef itemData
);
236 virtual Boolean
CompareItems(DataBrowserItemID itemOneID
,
237 DataBrowserItemID itemTwoID
,
238 DataBrowserPropertyID sortProperty
);
240 static pascal void DataBrowserDrawItemProc(ControlRef browser
,
241 DataBrowserItemID item
,
242 DataBrowserPropertyID property
,
243 DataBrowserItemState itemState
,
246 Boolean colorDevice
);
248 virtual void DrawItem(DataBrowserItemID itemID
,
249 DataBrowserPropertyID property
,
250 DataBrowserItemState itemState
,
251 const Rect
*itemRect
,
253 Boolean colorDevice
);
255 static pascal Boolean
DataBrowserEditTextProc(ControlRef browser
,
256 DataBrowserItemID item
,
257 DataBrowserPropertyID property
,
258 CFStringRef theString
,
259 Rect
*maxEditTextRect
,
260 Boolean
*shrinkToFit
);
262 static pascal Boolean
DataBrowserHitTestProc(ControlRef browser
,
263 DataBrowserItemID itemID
,
264 DataBrowserPropertyID property
,
266 const Rect
*mouseRect
) { return true; }
268 virtual bool ConfirmEditText(DataBrowserItemID item
,
269 DataBrowserPropertyID property
,
270 CFStringRef theString
,
271 Rect
*maxEditTextRect
,
272 Boolean
*shrinkToFit
);
276 wxClientDataType m_clientDataItemsType
;
279 DECLARE_DYNAMIC_CLASS_NO_COPY(wxMacDataBrowserListCtrlControl
)
282 class wxMacListCtrlEventDelegate
: public wxEvtHandler
285 wxMacListCtrlEventDelegate( wxListCtrl
* list
, int id
);
286 virtual bool ProcessEvent( wxEvent
& event
);
293 wxMacListCtrlEventDelegate::wxMacListCtrlEventDelegate( wxListCtrl
* list
, int id
)
299 bool wxMacListCtrlEventDelegate::ProcessEvent( wxEvent
& event
)
301 // even though we use a generic list ctrl underneath, make sure
302 // we present ourselves as wxListCtrl.
303 event
.SetEventObject( m_list
);
306 if ( !event
.IsKindOf( CLASSINFO( wxCommandEvent
) ) )
308 if (m_list
->GetEventHandler()->ProcessEvent( event
))
311 return wxEvtHandler::ProcessEvent(event
);
314 //-----------------------------------------------------------------------------
315 // wxListCtrlRenameTimer (internal)
316 //-----------------------------------------------------------------------------
318 class wxListCtrlRenameTimer
: public wxTimer
324 wxListCtrlRenameTimer( wxListCtrl
*owner
);
328 //-----------------------------------------------------------------------------
329 // wxListCtrlTextCtrlWrapper: wraps a wxTextCtrl to make it work for inline editing
330 //-----------------------------------------------------------------------------
332 class wxListCtrlTextCtrlWrapper
: public wxEvtHandler
335 // NB: text must be a valid object but not Create()d yet
336 wxListCtrlTextCtrlWrapper(wxListCtrl
*owner
,
340 wxTextCtrl
*GetText() const { return m_text
; }
342 void AcceptChangesAndFinish();
345 void OnChar( wxKeyEvent
&event
);
346 void OnKeyUp( wxKeyEvent
&event
);
347 void OnKillFocus( wxFocusEvent
&event
);
349 bool AcceptChanges();
355 wxString m_startValue
;
358 bool m_aboutToFinish
;
360 DECLARE_EVENT_TABLE()
363 //-----------------------------------------------------------------------------
364 // wxListCtrlRenameTimer (internal)
365 //-----------------------------------------------------------------------------
367 wxListCtrlRenameTimer::wxListCtrlRenameTimer( wxListCtrl
*owner
)
372 void wxListCtrlRenameTimer::Notify()
374 m_owner
->OnRenameTimer();
377 //-----------------------------------------------------------------------------
378 // wxListCtrlTextCtrlWrapper (internal)
379 //-----------------------------------------------------------------------------
381 BEGIN_EVENT_TABLE(wxListCtrlTextCtrlWrapper
, wxEvtHandler
)
382 EVT_CHAR (wxListCtrlTextCtrlWrapper::OnChar
)
383 EVT_KEY_UP (wxListCtrlTextCtrlWrapper::OnKeyUp
)
384 EVT_KILL_FOCUS (wxListCtrlTextCtrlWrapper::OnKillFocus
)
387 wxListCtrlTextCtrlWrapper::wxListCtrlTextCtrlWrapper(wxListCtrl
*owner
,
390 : m_startValue(owner
->GetItemText(itemEdit
)),
391 m_itemEdited(itemEdit
)
396 m_aboutToFinish
= false;
400 owner
->GetItemRect(itemEdit
, rectLabel
);
402 m_text
->Create(owner
, wxID_ANY
, m_startValue
,
403 wxPoint(rectLabel
.x
+offset
,rectLabel
.y
),
404 wxSize(rectLabel
.width
-offset
,rectLabel
.height
));
407 m_text
->PushEventHandler(this);
410 void wxListCtrlTextCtrlWrapper::Finish()
416 m_text
->RemoveEventHandler(this);
417 m_owner
->FinishEditing(m_text
);
419 wxPendingDelete
.Append( this );
423 bool wxListCtrlTextCtrlWrapper::AcceptChanges()
425 const wxString value
= m_text
->GetValue();
427 if ( value
== m_startValue
)
428 // nothing changed, always accept
431 if ( !m_owner
->OnRenameAccept(m_itemEdited
, value
) )
432 // vetoed by the user
435 // accepted, do rename the item
436 m_owner
->SetItemText(m_itemEdited
, value
);
441 void wxListCtrlTextCtrlWrapper::AcceptChangesAndFinish()
443 m_aboutToFinish
= true;
445 // Notify the owner about the changes
448 // Even if vetoed, close the control (consistent with MSW)
452 void wxListCtrlTextCtrlWrapper::OnChar( wxKeyEvent
&event
)
454 switch ( event
.m_keyCode
)
457 AcceptChangesAndFinish();
461 m_owner
->OnRenameCancelled( m_itemEdited
);
470 void wxListCtrlTextCtrlWrapper::OnKeyUp( wxKeyEvent
&event
)
478 // auto-grow the textctrl:
479 wxSize parentSize
= m_owner
->GetSize();
480 wxPoint myPos
= m_text
->GetPosition();
481 wxSize mySize
= m_text
->GetSize();
483 m_text
->GetTextExtent(m_text
->GetValue() + _T("MM"), &sx
, &sy
);
484 if (myPos
.x
+ sx
> parentSize
.x
)
485 sx
= parentSize
.x
- myPos
.x
;
488 m_text
->SetSize(sx
, wxDefaultCoord
);
493 void wxListCtrlTextCtrlWrapper::OnKillFocus( wxFocusEvent
&event
)
495 if ( !m_finished
&& !m_aboutToFinish
)
497 if ( !AcceptChanges() )
498 m_owner
->OnRenameCancelled( m_itemEdited
);
503 // We must let the native text control handle focus
507 BEGIN_EVENT_TABLE(wxListCtrl
, wxControl
)
508 EVT_LEFT_DOWN(wxListCtrl::OnLeftDown
)
509 EVT_LEFT_DCLICK(wxListCtrl::OnDblClick
)
510 EVT_MIDDLE_DOWN(wxListCtrl::OnMiddleDown
)
511 EVT_RIGHT_DOWN(wxListCtrl::OnRightDown
)
512 EVT_CHAR(wxListCtrl::OnChar
)
515 // ============================================================================
517 // ============================================================================
519 wxMacListControl
* wxListCtrl::GetPeer() const
521 wxMacDataBrowserListCtrlControl
*lb
= wxDynamicCast(m_peer
,wxMacDataBrowserListCtrlControl
);
522 return lb
? wx_static_cast(wxMacListControl
*,lb
) : 0 ;
525 // ----------------------------------------------------------------------------
526 // wxListCtrl construction
527 // ----------------------------------------------------------------------------
529 void wxListCtrl::Init()
531 m_imageListNormal
= NULL
;
532 m_imageListSmall
= NULL
;
533 m_imageListState
= NULL
;
535 // keep track of if we created our own image lists, or if they were assigned
537 m_ownsImageListNormal
= m_ownsImageListSmall
= m_ownsImageListState
= false;
541 m_genericImpl
= NULL
;
543 m_compareFunc
= NULL
;
544 m_compareFuncData
= 0;
545 m_colsInfo
= wxColumnList();
546 m_textColor
= wxNullColour
;
547 m_bgColor
= wxNullColour
;
548 m_textctrlWrapper
= NULL
;
550 m_renameTimer
= new wxListCtrlRenameTimer( this );
553 class wxGenericListCtrlHook
: public wxGenericListCtrl
556 wxGenericListCtrlHook(wxListCtrl
* parent
,
561 const wxValidator
& validator
,
562 const wxString
& name
)
563 : wxGenericListCtrl(parent
, id
, pos
, size
, style
, validator
, name
),
564 m_nativeListCtrl(parent
)
569 virtual wxListItemAttr
* OnGetItemAttr(long item
) const
571 return m_nativeListCtrl
->OnGetItemAttr(item
);
574 virtual int OnGetItemImage(long item
) const
576 return m_nativeListCtrl
->OnGetItemImage(item
);
579 virtual int OnGetItemColumnImage(long item
, long column
) const
581 return m_nativeListCtrl
->OnGetItemColumnImage(item
, column
);
584 virtual wxString
OnGetItemText(long item
, long column
) const
586 return m_nativeListCtrl
->OnGetItemText(item
, column
);
589 wxListCtrl
* m_nativeListCtrl
;
593 void wxListCtrl::OnLeftDown(wxMouseEvent
& event
)
595 if ( m_textctrlWrapper
)
598 m_textctrlWrapper
->AcceptChangesAndFinish();
602 long current
= HitTest(event
.GetPosition(), hitResult
);
603 if ((current
== m_current
) &&
604 (hitResult
== wxLIST_HITTEST_ONITEM
) &&
605 HasFlag(wxLC_EDIT_LABELS
) )
607 m_renameTimer
->Start( 100, true );
616 void wxListCtrl::OnDblClick(wxMouseEvent
& event
)
622 #if wxABI_VERSION >= 20801
623 void wxListCtrl::OnRightDown(wxMouseEvent
& event
)
625 FireMouseEvent(wxEVT_COMMAND_LIST_ITEM_RIGHT_CLICK
, event
.GetPosition());
629 void wxListCtrl::OnMiddleDown(wxMouseEvent
& event
)
631 FireMouseEvent(wxEVT_COMMAND_LIST_ITEM_MIDDLE_CLICK
, event
.GetPosition());
635 void wxListCtrl::FireMouseEvent(wxEventType eventType
, wxPoint position
)
637 wxListEvent
le( eventType
, GetId() );
638 le
.SetEventObject(this);
639 le
.m_pointDrag
= position
;
643 long item
= HitTest(position
, flags
);
644 if (flags
& wxLIST_HITTEST_ONITEM
)
646 le
.m_itemIndex
= item
;
650 le
.m_item
.m_itemId
= item
;
653 GetEventHandler()->ProcessEvent(le
);
657 void wxListCtrl::OnChar(wxKeyEvent
& event
)
659 wxListEvent
le( wxEVT_COMMAND_LIST_KEY_DOWN
, GetId() );
660 le
.SetEventObject(this);
661 le
.m_code
= event
.GetKeyCode();
666 le
.m_itemIndex
= m_current
;
669 le
.m_item
.m_itemId
= m_current
;
672 GetEventHandler()->ProcessEvent(le
);
678 bool wxListCtrl::Create(wxWindow
*parent
,
683 const wxValidator
& validator
,
684 const wxString
& name
)
687 // for now, we'll always use the generic list control for ICON and LIST views,
688 // because they dynamically change the number of columns on resize.
689 // Also, allow the user to set it to use the list ctrl as well.
690 if ( (wxSystemOptions::HasOption( wxMAC_ALWAYS_USE_GENERIC_LISTCTRL
)
691 && (wxSystemOptions::GetOptionInt( wxMAC_ALWAYS_USE_GENERIC_LISTCTRL
) == 1)) ||
692 (style
& wxLC_ICON
) || (style
& wxLC_SMALL_ICON
) || (style
& wxLC_LIST
) )
694 m_macIsUserPane
= true;
696 long paneStyle
= style
;
697 paneStyle
&= ~wxSIMPLE_BORDER
;
698 paneStyle
&= ~wxDOUBLE_BORDER
;
699 paneStyle
&= ~wxSUNKEN_BORDER
;
700 paneStyle
&= ~wxRAISED_BORDER
;
701 paneStyle
&= ~wxSTATIC_BORDER
;
702 if ( !wxWindow::Create(parent
, id
, pos
, size
, paneStyle
| wxNO_BORDER
, name
) )
705 // since the generic control is a child, make sure we position it at 0, 0
706 m_genericImpl
= new wxGenericListCtrlHook(this, id
, wxPoint(0, 0), size
, style
, validator
, name
);
707 m_genericImpl
->PushEventHandler( new wxMacListCtrlEventDelegate( this, GetId() ) );
713 m_macIsUserPane
= false;
714 if ( !wxWindow::Create(parent
, id
, pos
, size
, style
& ~(wxHSCROLL
| wxVSCROLL
), name
) )
716 m_dbImpl
= new wxMacDataBrowserListCtrlControl( this, pos
, size
, style
);
719 MacPostControlCreate( pos
, size
);
721 InstallControlEventHandler( m_peer
->GetControlRef() , GetwxMacListCtrlEventHandlerUPP(),
722 GetEventTypeCount(eventList
), eventList
, this,
723 (EventHandlerRef
*)&m_macListCtrlEventHandler
);
729 wxListCtrl::~wxListCtrl()
733 m_genericImpl
->PopEventHandler(/* deleteHandler = */ true);
736 if (m_ownsImageListNormal
)
737 delete m_imageListNormal
;
738 if (m_ownsImageListSmall
)
739 delete m_imageListSmall
;
740 if (m_ownsImageListState
)
741 delete m_imageListState
;
743 delete m_renameTimer
;
746 // ----------------------------------------------------------------------------
747 // set/get/change style
748 // ----------------------------------------------------------------------------
750 // Add or remove a single window style
751 void wxListCtrl::SetSingleStyle(long style
, bool add
)
753 long flag
= GetWindowStyleFlag();
755 // Get rid of conflicting styles
758 if ( style
& wxLC_MASK_TYPE
)
759 flag
= flag
& ~wxLC_MASK_TYPE
;
760 if ( style
& wxLC_MASK_ALIGN
)
761 flag
= flag
& ~wxLC_MASK_ALIGN
;
762 if ( style
& wxLC_MASK_SORT
)
763 flag
= flag
& ~wxLC_MASK_SORT
;
771 SetWindowStyleFlag(flag
);
774 // Set the whole window style
775 void wxListCtrl::SetWindowStyleFlag(long flag
)
777 if ( flag
!= m_windowStyle
)
779 m_windowStyle
= flag
;
783 m_genericImpl
->SetWindowStyleFlag(flag
);
790 void wxListCtrl::DoSetSize( int x
, int y
, int width
, int height
, int sizeFlags
)
792 wxControl::DoSetSize(x
, y
, width
, height
, sizeFlags
);
795 m_genericImpl
->SetSize(0, 0, width
, height
, sizeFlags
);
797 // determine if we need a horizontal scrollbar, and add it if so
801 for (int column
= 0; column
< GetColumnCount(); column
++)
803 totalWidth
+= m_dbImpl
->GetColumnWidth( column
);
806 if ( !(m_dbImpl
->GetFlags() & wxHSCROLL
) )
808 Boolean vertScrollBar
;
809 GetDataBrowserHasScrollBars( m_dbImpl
->GetControlRef(), NULL
, &vertScrollBar
);
810 if (totalWidth
> width
)
811 SetDataBrowserHasScrollBars( m_dbImpl
->GetControlRef(), true, vertScrollBar
);
813 SetDataBrowserHasScrollBars( m_dbImpl
->GetControlRef(), false, vertScrollBar
);
818 wxSize
wxListCtrl::DoGetBestSize() const
820 return wxWindow::DoGetBestSize();
823 bool wxListCtrl::SetFont(const wxFont
& font
)
826 rv
= wxControl::SetFont(font
);
828 rv
= m_genericImpl
->SetFont(font
);
832 bool wxListCtrl::SetForegroundColour(const wxColour
& colour
)
836 rv
= m_genericImpl
->SetForegroundColour(colour
);
838 SetTextColour(colour
);
842 bool wxListCtrl::SetBackgroundColour(const wxColour
& colour
)
846 rv
= m_genericImpl
->SetBackgroundColour(colour
);
852 wxColour
wxListCtrl::GetBackgroundColour()
855 return m_genericImpl
->GetBackgroundColour();
862 // ----------------------------------------------------------------------------
864 // ----------------------------------------------------------------------------
866 // Gets information about this column
867 bool wxListCtrl::GetColumn(int col
, wxListItem
& item
) const
870 return m_genericImpl
->GetColumn(col
, item
);
876 wxColumnList::compatibility_iterator node
= m_colsInfo
.Item( col
);
877 wxASSERT_MSG( node
, _T("invalid column index in wxMacListCtrlItem") );
878 wxListItem
* column
= node
->GetData();
880 long mask
= column
->GetMask();
881 if (mask
& wxLIST_MASK_TEXT
)
882 item
.SetText(column
->GetText());
883 if (mask
& wxLIST_MASK_DATA
)
884 item
.SetData(column
->GetData());
885 if (mask
& wxLIST_MASK_IMAGE
)
886 item
.SetImage(column
->GetImage());
887 if (mask
& wxLIST_MASK_STATE
)
888 item
.SetState(column
->GetState());
889 if (mask
& wxLIST_MASK_FORMAT
)
890 item
.SetAlign(column
->GetAlign());
891 if (mask
& wxLIST_MASK_WIDTH
)
892 item
.SetWidth(column
->GetWidth());
898 // Sets information about this column
899 bool wxListCtrl::SetColumn(int col
, wxListItem
& item
)
902 return m_genericImpl
->SetColumn(col
, item
);
906 long mask
= item
.GetMask();
907 if ( col
>= (int)m_colsInfo
.GetCount() )
909 wxListItem
* listItem
= new wxListItem(item
);
910 m_colsInfo
.Append( listItem
);
915 GetColumn( col
, listItem
);
917 if (mask
& wxLIST_MASK_TEXT
)
918 listItem
.SetText(item
.GetText());
919 if (mask
& wxLIST_MASK_DATA
)
920 listItem
.SetData(item
.GetData());
921 if (mask
& wxLIST_MASK_IMAGE
)
922 listItem
.SetImage(item
.GetImage());
923 if (mask
& wxLIST_MASK_STATE
)
924 listItem
.SetState(item
.GetState());
925 if (mask
& wxLIST_MASK_FORMAT
)
926 listItem
.SetAlign(item
.GetAlign());
927 if (mask
& wxLIST_MASK_WIDTH
)
928 listItem
.SetWidth(item
.GetWidth());
931 // change the appearance in the databrowser.
932 DataBrowserListViewHeaderDesc columnDesc
;
933 columnDesc
.version
=kDataBrowserListViewLatestHeaderDesc
;
934 verify_noerr( m_dbImpl
->GetHeaderDesc( kMinColumnId
+ col
, &columnDesc
) );
937 if (item.GetMask() & wxLIST_MASK_TEXT)
941 enc = m_font.GetEncoding();
943 enc = wxLocale::GetSystemEncoding();
944 wxMacCFStringHolder cfTitle;
945 cfTitle.Assign( item.GetText() , enc );
946 if(columnDesc.titleString)
947 CFRelease(columnDesc.titleString);
948 columnDesc.titleString = cfTitle;
952 if (item
.GetMask() & wxLIST_MASK_IMAGE
&& item
.GetImage() != -1 )
954 columnDesc
.btnContentInfo
.contentType
= kControlContentIconRef
;
955 wxImageList
* imageList
= GetImageList(wxIMAGE_LIST_SMALL
);
956 if (imageList
&& imageList
->GetImageCount() > 0 )
958 wxBitmap bmp
= imageList
->GetBitmap( item
.GetImage() );
959 IconRef icon
= bmp
.GetBitmapData()->GetIconRef();
960 columnDesc
.btnContentInfo
.u
.iconRef
= icon
;
964 verify_noerr( m_dbImpl
->SetHeaderDesc( kMinColumnId
+ col
, &columnDesc
) );
970 int wxListCtrl::GetColumnCount() const
973 return m_genericImpl
->GetColumnCount();
978 m_dbImpl
->GetColumnCount(&count
);
985 // Gets the column width
986 int wxListCtrl::GetColumnWidth(int col
) const
989 return m_genericImpl
->GetColumnWidth(col
);
993 return m_dbImpl
->GetColumnWidth(col
);
999 // Sets the column width
1000 bool wxListCtrl::SetColumnWidth(int col
, int width
)
1003 return m_genericImpl
->SetColumnWidth(col
, width
);
1007 int mywidth
= width
;
1008 if (width
== wxLIST_AUTOSIZE
|| width
== wxLIST_AUTOSIZE_USEHEADER
)
1013 for (int column
= 0; column
< GetColumnCount(); column
++)
1016 GetColumn(col
, colInfo
);
1018 colInfo
.SetWidth(width
);
1019 SetColumn(col
, colInfo
);
1021 m_dbImpl
->SetColumnWidth(col
, mywidth
);
1027 GetColumn(col
, colInfo
);
1029 colInfo
.SetWidth(width
);
1030 SetColumn(col
, colInfo
);
1031 m_dbImpl
->SetColumnWidth(col
, mywidth
);
1039 // Gets the number of items that can fit vertically in the
1040 // visible area of the list control (list or report view)
1041 // or the total number of items in the list control (icon
1042 // or small icon view)
1043 int wxListCtrl::GetCountPerPage() const
1046 return m_genericImpl
->GetCountPerPage();
1055 // Gets the edit control for editing labels.
1056 wxTextCtrl
* wxListCtrl::GetEditControl() const
1059 return m_genericImpl
->GetEditControl();
1064 // Gets information about the item
1065 bool wxListCtrl::GetItem(wxListItem
& info
) const
1068 return m_genericImpl
->GetItem(info
);
1073 m_dbImpl
->MacGetColumnInfo(info
.m_itemId
, info
.m_col
, info
);
1076 info
.SetText( OnGetItemText(info
.m_itemId
, info
.m_col
) );
1077 info
.SetImage( OnGetItemColumnImage(info
.m_itemId
, info
.m_col
) );
1078 if (info
.GetMask() & wxLIST_MASK_STATE
)
1080 if (IsDataBrowserItemSelected( m_dbImpl
->GetControlRef(), info
.m_itemId
+1 ))
1081 info
.SetState(info
.GetState() | wxLIST_STATE_SELECTED
);
1084 wxListItemAttr
* attrs
= OnGetItemAttr( info
.m_itemId
);
1087 info
.SetFont( attrs
->GetFont() );
1088 info
.SetBackgroundColour( attrs
->GetBackgroundColour() );
1089 info
.SetTextColour( attrs
->GetTextColour() );
1093 bool success
= true;
1097 // Sets information about the item
1098 bool wxListCtrl::SetItem(wxListItem
& info
)
1101 return m_genericImpl
->SetItem(info
);
1104 m_dbImpl
->MacSetColumnInfo( info
.m_itemId
, info
.m_col
, &info
);
1109 long wxListCtrl::SetItem(long index
, int col
, const wxString
& label
, int imageId
)
1112 return m_genericImpl
->SetItem(index
, col
, label
, imageId
);
1115 info
.m_text
= label
;
1116 info
.m_mask
= wxLIST_MASK_TEXT
;
1117 info
.m_itemId
= index
;
1121 info
.m_image
= imageId
;
1122 info
.m_mask
|= wxLIST_MASK_IMAGE
;
1124 return SetItem(info
);
1128 // Gets the item state
1129 int wxListCtrl::GetItemState(long item
, long stateMask
) const
1132 return m_genericImpl
->GetItemState(item
, stateMask
);
1136 if ( HasFlag(wxLC_VIRTUAL
) )
1138 if (stateMask
== wxLIST_STATE_SELECTED
)
1140 if (IsDataBrowserItemSelected( m_dbImpl
->GetControlRef(), item
+1 ))
1141 return wxLIST_STATE_SELECTED
;
1150 info
.m_mask
= wxLIST_MASK_STATE
;
1151 info
.m_stateMask
= stateMask
;
1152 info
.m_itemId
= item
;
1157 return info
.m_state
;
1164 // Sets the item state
1165 bool wxListCtrl::SetItemState(long item
, long state
, long stateMask
)
1168 return m_genericImpl
->SetItemState(item
, state
, stateMask
);
1172 DataBrowserSetOption option
= kDataBrowserItemsAdd
;
1173 if ( stateMask
== wxLIST_STATE_SELECTED
&& state
== 0 )
1174 option
= kDataBrowserItemsRemove
;
1178 if ( HasFlag(wxLC_VIRTUAL
) )
1180 wxMacDataItemBrowserSelectionSuppressor
suppressor(m_dbImpl
);
1181 m_dbImpl
->SetSelectedAllItems(option
);
1185 for(int i
= 0; i
< GetItemCount();i
++)
1189 info
.m_mask
= wxLIST_MASK_STATE
;
1190 info
.m_stateMask
= stateMask
;
1191 info
.m_state
= state
;
1198 if ( HasFlag(wxLC_VIRTUAL
) )
1200 long itemID
= item
+1;
1201 SetDataBrowserSelectedItems(m_dbImpl
->GetControlRef(), 1, (DataBrowserItemID
*)&itemID
, option
);
1206 info
.m_itemId
= item
;
1207 info
.m_mask
= wxLIST_MASK_STATE
;
1208 info
.m_stateMask
= stateMask
;
1209 info
.m_state
= state
;
1210 return SetItem(info
);
1217 // Sets the item image
1218 bool wxListCtrl::SetItemImage(long item
, int image
, int WXUNUSED(selImage
))
1220 return SetItemColumnImage(item
, 0, image
);
1223 // Sets the item image
1224 bool wxListCtrl::SetItemColumnImage(long item
, long column
, int image
)
1227 return m_genericImpl
->SetItemColumnImage(item
, column
, image
);
1231 info
.m_mask
= wxLIST_MASK_IMAGE
;
1232 info
.m_image
= image
;
1233 info
.m_itemId
= item
;
1234 info
.m_col
= column
;
1236 return SetItem(info
);
1239 // Gets the item text
1240 wxString
wxListCtrl::GetItemText(long item
) const
1243 return m_genericImpl
->GetItemText(item
);
1247 info
.m_mask
= wxLIST_MASK_TEXT
;
1248 info
.m_itemId
= item
;
1251 return wxEmptyString
;
1255 // Sets the item text
1256 void wxListCtrl::SetItemText(long item
, const wxString
& str
)
1259 return m_genericImpl
->SetItemText(item
, str
);
1263 info
.m_mask
= wxLIST_MASK_TEXT
;
1264 info
.m_itemId
= item
;
1270 // Gets the item data
1271 long wxListCtrl::GetItemData(long item
) const
1274 return m_genericImpl
->GetItemData(item
);
1278 info
.m_mask
= wxLIST_MASK_DATA
;
1279 info
.m_itemId
= item
;
1286 // Sets the item data
1287 bool wxListCtrl::SetItemData(long item
, long data
)
1290 return m_genericImpl
->SetItemData(item
, data
);
1294 info
.m_mask
= wxLIST_MASK_DATA
;
1295 info
.m_itemId
= item
;
1298 return SetItem(info
);
1301 wxRect
wxListCtrl::GetViewRect() const
1303 wxASSERT_MSG( !HasFlag(wxLC_REPORT
| wxLC_LIST
),
1304 _T("wxListCtrl::GetViewRect() only works in icon mode") );
1307 return m_genericImpl
->GetViewRect();
1313 // Gets the item rectangle
1314 bool wxListCtrl::GetItemRect(long item
, wxRect
& rect
, int code
) const
1317 return m_genericImpl
->GetItemRect(item
, rect
, code
);
1322 DataBrowserItemID id
;
1323 DataBrowserPropertyID col
= kMinColumnId
;
1325 DataBrowserPropertyPart part
= kDataBrowserPropertyEnclosingPart
;
1326 if ( code
== wxLIST_RECT_LABEL
)
1327 part
= kDataBrowserPropertyTextPart
;
1328 else if ( code
== wxLIST_RECT_ICON
)
1329 part
= kDataBrowserPropertyIconPart
;
1331 if ( !(GetWindowStyleFlag() & wxLC_VIRTUAL
) )
1333 wxMacDataItem
* thisItem
= m_dbImpl
->GetItemFromLine(item
);
1334 id
= (DataBrowserItemID
) thisItem
;
1339 GetDataBrowserItemPartBounds( m_dbImpl
->GetControlRef(), id
, col
, part
, &bounds
);
1341 rect
.x
= bounds
.left
;
1342 rect
.y
= bounds
.top
;
1343 rect
.width
= bounds
.right
- bounds
.left
; //GetClientSize().x; // we need the width of the whole row, not just the item.
1344 rect
.height
= bounds
.bottom
- bounds
.top
;
1345 //fprintf("id = %d, bounds = %d, %d, %d, %d\n", id, rect.x, rect.y, rect.width, rect.height);
1350 // Gets the item position
1351 bool wxListCtrl::GetItemPosition(long item
, wxPoint
& pos
) const
1354 return m_genericImpl
->GetItemPosition(item
, pos
);
1356 bool success
= false;
1361 GetItemRect(item
, itemRect
);
1362 pos
= itemRect
.GetPosition();
1369 // Sets the item position.
1370 bool wxListCtrl::SetItemPosition(long item
, const wxPoint
& pos
)
1373 return m_genericImpl
->SetItemPosition(item
, pos
);
1378 // Gets the number of items in the list control
1379 int wxListCtrl::GetItemCount() const
1382 return m_genericImpl
->GetItemCount();
1385 return m_dbImpl
->MacGetCount();
1390 void wxListCtrl::SetItemSpacing( int spacing
, bool isSmall
)
1393 m_genericImpl
->SetItemSpacing(spacing
, isSmall
);
1396 wxSize
wxListCtrl::GetItemSpacing() const
1399 return m_genericImpl
->GetItemSpacing();
1401 return wxSize(0, 0);
1404 void wxListCtrl::SetItemTextColour( long item
, const wxColour
&col
)
1408 m_genericImpl
->SetItemTextColour(item
, col
);
1413 info
.m_itemId
= item
;
1414 info
.SetTextColour( col
);
1418 wxColour
wxListCtrl::GetItemTextColour( long item
) const
1421 return m_genericImpl
->GetItemTextColour(item
);
1427 return info
.GetTextColour();
1429 return wxNullColour
;
1432 void wxListCtrl::SetItemBackgroundColour( long item
, const wxColour
&col
)
1436 m_genericImpl
->SetItemBackgroundColour(item
, col
);
1441 info
.m_itemId
= item
;
1442 info
.SetBackgroundColour( col
);
1446 wxColour
wxListCtrl::GetItemBackgroundColour( long item
) const
1449 return m_genericImpl
->GetItemBackgroundColour(item
);
1455 return info
.GetBackgroundColour();
1457 return wxNullColour
;
1460 void wxListCtrl::SetItemFont( long item
, const wxFont
&f
)
1464 m_genericImpl
->SetItemFont(item
, f
);
1469 info
.m_itemId
= item
;
1474 wxFont
wxListCtrl::GetItemFont( long item
) const
1477 return m_genericImpl
->GetItemFont(item
);
1483 return info
.GetFont();
1489 // Gets the number of selected items in the list control
1490 int wxListCtrl::GetSelectedItemCount() const
1493 return m_genericImpl
->GetSelectedItemCount();
1496 return m_dbImpl
->GetSelectedItemCount(NULL
, true);
1501 // Gets the text colour of the listview
1502 wxColour
wxListCtrl::GetTextColour() const
1505 return m_genericImpl
->GetTextColour();
1507 // TODO: we need owner drawn list items to customize text color.
1511 return wxNullColour
;
1514 // Sets the text colour of the listview
1515 void wxListCtrl::SetTextColour(const wxColour
& col
)
1519 m_genericImpl
->SetTextColour(col
);
1527 // Gets the index of the topmost visible item when in
1528 // list or report view
1529 long wxListCtrl::GetTopItem() const
1532 return m_genericImpl
->GetTopItem();
1537 long item
= HitTest( wxPoint(1, 1), flags
);
1538 if (flags
== wxLIST_HITTEST_ONITEM
)
1545 // Searches for an item, starting from 'item'.
1546 // 'geometry' is one of
1547 // wxLIST_NEXT_ABOVE/ALL/BELOW/LEFT/RIGHT.
1548 // 'state' is a state bit flag, one or more of
1549 // wxLIST_STATE_DROPHILITED/FOCUSED/SELECTED/CUT.
1550 // item can be -1 to find the first item that matches the
1552 // Returns the item or -1 if unsuccessful.
1553 long wxListCtrl::GetNextItem(long item
, int geom
, int state
) const
1556 return m_genericImpl
->GetNextItem(item
, geom
, state
);
1558 if (m_dbImpl
&& geom
== wxLIST_NEXT_ALL
&& state
== wxLIST_STATE_SELECTED
)
1560 long count
= m_dbImpl
->MacGetCount() ;
1561 for ( long line
= item
+ 1 ; line
< count
; line
++ )
1563 wxMacDataItem
* id
= m_dbImpl
->GetItemFromLine(line
);
1564 if ( m_dbImpl
->IsItemSelected(id
) )
1574 wxImageList
*wxListCtrl::GetImageList(int which
) const
1577 return m_genericImpl
->GetImageList(which
);
1579 if ( which
== wxIMAGE_LIST_NORMAL
)
1581 return m_imageListNormal
;
1583 else if ( which
== wxIMAGE_LIST_SMALL
)
1585 return m_imageListSmall
;
1587 else if ( which
== wxIMAGE_LIST_STATE
)
1589 return m_imageListState
;
1594 void wxListCtrl::SetImageList(wxImageList
*imageList
, int which
)
1598 m_genericImpl
->SetImageList(imageList
, which
);
1602 if ( which
== wxIMAGE_LIST_NORMAL
)
1604 if (m_ownsImageListNormal
) delete m_imageListNormal
;
1605 m_imageListNormal
= imageList
;
1606 m_ownsImageListNormal
= false;
1608 else if ( which
== wxIMAGE_LIST_SMALL
)
1610 if (m_ownsImageListSmall
) delete m_imageListSmall
;
1611 m_imageListSmall
= imageList
;
1612 m_ownsImageListSmall
= false;
1614 else if ( which
== wxIMAGE_LIST_STATE
)
1616 if (m_ownsImageListState
) delete m_imageListState
;
1617 m_imageListState
= imageList
;
1618 m_ownsImageListState
= false;
1622 void wxListCtrl::AssignImageList(wxImageList
*imageList
, int which
)
1626 m_genericImpl
->AssignImageList(imageList
, which
);
1630 SetImageList(imageList
, which
);
1631 if ( which
== wxIMAGE_LIST_NORMAL
)
1632 m_ownsImageListNormal
= true;
1633 else if ( which
== wxIMAGE_LIST_SMALL
)
1634 m_ownsImageListSmall
= true;
1635 else if ( which
== wxIMAGE_LIST_STATE
)
1636 m_ownsImageListState
= true;
1639 // ----------------------------------------------------------------------------
1641 // ----------------------------------------------------------------------------
1643 // Arranges the items
1644 bool wxListCtrl::Arrange(int flag
)
1647 return m_genericImpl
->Arrange(flag
);
1652 bool wxListCtrl::DeleteItem(long item
)
1655 return m_genericImpl
->DeleteItem(item
);
1659 m_dbImpl
->MacDelete(item
);
1660 wxListEvent
event( wxEVT_COMMAND_LIST_DELETE_ITEM
, GetId() );
1661 event
.SetEventObject( this );
1662 event
.m_itemIndex
= item
;
1663 GetEventHandler()->ProcessEvent( event
);
1669 // Deletes all items
1670 bool wxListCtrl::DeleteAllItems()
1673 return m_genericImpl
->DeleteAllItems();
1677 m_dbImpl
->MacClear();
1678 wxListEvent
event( wxEVT_COMMAND_LIST_DELETE_ALL_ITEMS
, GetId() );
1679 event
.SetEventObject( this );
1680 GetEventHandler()->ProcessEvent( event
);
1685 // Deletes all items
1686 bool wxListCtrl::DeleteAllColumns()
1689 return m_genericImpl
->DeleteAllColumns();
1694 m_dbImpl
->GetColumnCount(&cols
);
1695 for (UInt32 col
= 0; col
< cols
; col
++)
1705 bool wxListCtrl::DeleteColumn(int col
)
1708 return m_genericImpl
->DeleteColumn(col
);
1712 OSStatus err
= m_dbImpl
->RemoveColumn(col
);
1713 return err
== noErr
;
1719 // Clears items, and columns if there are any.
1720 void wxListCtrl::ClearAll()
1724 m_genericImpl
->ClearAll();
1735 wxTextCtrl
* wxListCtrl::EditLabel(long item
, wxClassInfo
* textControlClass
)
1738 return m_genericImpl
->EditLabel(item
, textControlClass
);
1742 wxCHECK_MSG( (item
>= 0) && ((long)item
< GetItemCount()), NULL
,
1743 wxT("wrong index in wxListCtrl::EditLabel()") );
1745 wxASSERT_MSG( textControlClass
->IsKindOf(CLASSINFO(wxTextCtrl
)),
1746 wxT("EditLabel() needs a text control") );
1748 wxListEvent
le( wxEVT_COMMAND_LIST_BEGIN_LABEL_EDIT
, GetParent()->GetId() );
1749 le
.SetEventObject( this );
1750 le
.m_itemIndex
= item
;
1752 GetItem( le
.m_item
);
1754 if ( GetParent()->GetEventHandler()->ProcessEvent( le
) && !le
.IsAllowed() )
1756 // vetoed by user code
1760 wxTextCtrl
* const text
= (wxTextCtrl
*)textControlClass
->CreateObject();
1761 m_textctrlWrapper
= new wxListCtrlTextCtrlWrapper(this, text
, item
);
1762 return m_textctrlWrapper
->GetText();
1767 // End label editing, optionally cancelling the edit
1768 bool wxListCtrl::EndEditLabel(bool cancel
)
1770 // TODO: generic impl. doesn't have this method - is it needed for us?
1772 return true; // m_genericImpl->EndEditLabel(cancel);
1775 verify_noerr( SetDataBrowserEditItem(m_dbImpl
->GetControlRef(), kDataBrowserNoItem
, kMinColumnId
) );
1779 // Ensures this item is visible
1780 bool wxListCtrl::EnsureVisible(long item
)
1783 return m_genericImpl
->EnsureVisible(item
);
1787 wxMacDataItem
* dataItem
= m_dbImpl
->GetItemFromLine(item
);
1788 m_dbImpl
->RevealItem(dataItem
, kDataBrowserRevealWithoutSelecting
);
1794 // Find an item whose label matches this string, starting from the item after 'start'
1795 // or the beginning if 'start' is -1.
1796 long wxListCtrl::FindItem(long start
, const wxString
& str
, bool partial
)
1799 return m_genericImpl
->FindItem(start
, str
, partial
);
1801 wxString str_upper
= str
.Upper();
1806 long count
= GetItemCount();
1810 wxString line_upper
= GetItemText(idx
).Upper();
1813 if (line_upper
== str_upper
)
1818 if (line_upper
.find(str_upper
) == 0)
1828 // Find an item whose data matches this data, starting from the item after 'start'
1829 // or the beginning if 'start' is -1.
1830 long wxListCtrl::FindItem(long start
, long data
)
1833 return m_genericImpl
->FindItem(start
, data
);
1838 long count
= GetItemCount();
1842 if (GetItemData(idx
) == data
)
1850 // Find an item nearest this position in the specified direction, starting from
1851 // the item after 'start' or the beginning if 'start' is -1.
1852 long wxListCtrl::FindItem(long start
, const wxPoint
& pt
, int direction
)
1855 return m_genericImpl
->FindItem(start
, pt
, direction
);
1859 // Determines which item (if any) is at the specified point,
1860 // giving details in 'flags' (see wxLIST_HITTEST_... flags above)
1862 wxListCtrl::HitTest(const wxPoint
& point
, int& flags
, long *ptrSubItem
) const
1865 return m_genericImpl
->HitTest(point
, flags
, ptrSubItem
);
1867 flags
= wxLIST_HITTEST_NOWHERE
;
1870 int colHeaderHeight
= 22; // TODO: Find a way to get this value from the db control?
1871 UInt16 rowHeight
= 0;
1872 m_dbImpl
->GetDefaultRowHeight(&rowHeight
);
1875 // get the actual row by taking scroll position into account
1876 UInt32 offsetX
, offsetY
;
1877 m_dbImpl
->GetScrollPosition( &offsetY
, &offsetX
);
1880 if ( !(GetWindowStyleFlag() & wxLC_NO_HEADER
) )
1881 y
-= colHeaderHeight
;
1886 int row
= y
/ rowHeight
;
1887 DataBrowserItemID id
;
1888 m_dbImpl
->GetItemID( (DataBrowserTableViewRowIndex
) row
, &id
);
1890 // TODO: Use GetDataBrowserItemPartBounds to return if we are in icon or label
1891 if ( !(GetWindowStyleFlag() & wxLC_VIRTUAL
) )
1893 wxMacListCtrlItem
* lcItem
;
1894 lcItem
= (wxMacListCtrlItem
*) id
;
1897 flags
= wxLIST_HITTEST_ONITEM
;
1903 if (row
< GetItemCount() )
1905 flags
= wxLIST_HITTEST_ONITEM
;
1914 int wxListCtrl::GetScrollPos(int orient
) const
1917 return m_genericImpl
->GetScrollPos(orient
);
1921 UInt32 offsetX
, offsetY
;
1922 m_dbImpl
->GetScrollPosition( &offsetY
, &offsetX
);
1923 if ( orient
== wxHORIZONTAL
)
1932 // Inserts an item, returning the index of the new item if successful,
1934 long wxListCtrl::InsertItem(wxListItem
& info
)
1936 wxASSERT_MSG( !IsVirtual(), _T("can't be used with virtual controls") );
1939 return m_genericImpl
->InsertItem(info
);
1941 if (m_dbImpl
&& !IsVirtual())
1943 int count
= GetItemCount();
1945 if (info
.m_itemId
> count
)
1946 info
.m_itemId
= count
;
1948 m_dbImpl
->MacInsertItem(info
.m_itemId
, &info
);
1950 wxListEvent
event( wxEVT_COMMAND_LIST_INSERT_ITEM
, GetId() );
1951 event
.SetEventObject( this );
1952 event
.m_itemIndex
= info
.m_itemId
;
1953 GetEventHandler()->ProcessEvent( event
);
1954 return info
.m_itemId
;
1959 long wxListCtrl::InsertItem(long index
, const wxString
& label
)
1962 return m_genericImpl
->InsertItem(index
, label
);
1965 info
.m_text
= label
;
1966 info
.m_mask
= wxLIST_MASK_TEXT
;
1967 info
.m_itemId
= index
;
1968 return InsertItem(info
);
1971 // Inserts an image item
1972 long wxListCtrl::InsertItem(long index
, int imageIndex
)
1975 return m_genericImpl
->InsertItem(index
, imageIndex
);
1978 info
.m_image
= imageIndex
;
1979 info
.m_mask
= wxLIST_MASK_IMAGE
;
1980 info
.m_itemId
= index
;
1981 return InsertItem(info
);
1984 // Inserts an image/string item
1985 long wxListCtrl::InsertItem(long index
, const wxString
& label
, int imageIndex
)
1988 return m_genericImpl
->InsertItem(index
, label
, imageIndex
);
1991 info
.m_image
= imageIndex
;
1992 info
.m_text
= label
;
1993 info
.m_mask
= wxLIST_MASK_IMAGE
| wxLIST_MASK_TEXT
;
1994 info
.m_itemId
= index
;
1995 return InsertItem(info
);
1998 // For list view mode (only), inserts a column.
1999 long wxListCtrl::InsertColumn(long col
, wxListItem
& item
)
2002 return m_genericImpl
->InsertColumn(col
, item
);
2006 int width
= item
.GetWidth();
2007 if ( !(item
.GetMask() & wxLIST_MASK_WIDTH
) )
2010 DataBrowserPropertyType type
= kDataBrowserCustomType
; //kDataBrowserTextType;
2011 wxImageList
* imageList
= GetImageList(wxIMAGE_LIST_SMALL
);
2012 if (imageList
&& imageList
->GetImageCount() > 0)
2014 wxBitmap bmp
= imageList
->GetBitmap(0);
2016 // type = kDataBrowserIconAndTextType;
2019 SInt16 just
= teFlushDefault
;
2020 if (item
.GetMask() & wxLIST_MASK_FORMAT
)
2022 if (item
.GetAlign() == wxLIST_FORMAT_LEFT
)
2024 else if (item
.GetAlign() == wxLIST_FORMAT_CENTER
)
2026 else if (item
.GetAlign() == wxLIST_FORMAT_RIGHT
)
2027 just
= teFlushRight
;
2029 m_dbImpl
->InsertColumn(col
, type
, item
.GetText(), just
, width
);
2030 SetColumn(col
, item
);
2032 // set/remove options based on the wxListCtrl type.
2033 DataBrowserTableViewColumnID id
;
2034 m_dbImpl
->GetColumnIDFromIndex(col
, &id
);
2035 DataBrowserPropertyFlags flags
;
2036 verify_noerr(m_dbImpl
->GetPropertyFlags(id
, &flags
));
2037 if (GetWindowStyleFlag() & wxLC_EDIT_LABELS
)
2038 flags
|= kDataBrowserPropertyIsEditable
;
2040 if (GetWindowStyleFlag() & wxLC_VIRTUAL
){
2041 flags
&= ~kDataBrowserListViewSortableColumn
;
2043 verify_noerr(m_dbImpl
->SetPropertyFlags(id
, flags
));
2049 long wxListCtrl::InsertColumn(long col
,
2050 const wxString
& heading
,
2055 return m_genericImpl
->InsertColumn(col
, heading
, format
, width
);
2058 item
.m_mask
= wxLIST_MASK_TEXT
| wxLIST_MASK_FORMAT
;
2059 item
.m_text
= heading
;
2062 item
.m_mask
|= wxLIST_MASK_WIDTH
;
2063 item
.m_width
= width
;
2065 item
.m_format
= format
;
2067 return InsertColumn(col
, item
);
2070 // scroll the control by the given number of pixels (exception: in list view,
2071 // dx is interpreted as number of columns)
2072 bool wxListCtrl::ScrollList(int dx
, int dy
)
2075 return m_genericImpl
->ScrollList(dx
, dy
);
2079 m_dbImpl
->SetScrollPosition(dx
, dy
);
2085 bool wxListCtrl::SortItems(wxListCtrlCompare fn
, long data
)
2088 return m_genericImpl
->SortItems(fn
, data
);
2093 m_compareFuncData
= data
;
2094 SortDataBrowserContainer( m_dbImpl
->GetControlRef(), kDataBrowserNoItem
, true);
2096 // we need to do this after each call, else we get a crash from wxPython when
2097 // SortItems is called the second time.
2098 m_compareFunc
= NULL
;
2099 m_compareFuncData
= 0;
2105 void wxListCtrl::OnRenameTimer()
2107 wxCHECK_RET( HasCurrent(), wxT("unexpected rename timer") );
2109 EditLabel( m_current
);
2112 bool wxListCtrl::OnRenameAccept(long itemEdit
, const wxString
& value
)
2114 wxListEvent
le( wxEVT_COMMAND_LIST_END_LABEL_EDIT
, GetId() );
2115 le
.SetEventObject( this );
2116 le
.m_itemIndex
= itemEdit
;
2118 GetItem( le
.m_item
);
2119 le
.m_item
.m_text
= value
;
2120 return !GetEventHandler()->ProcessEvent( le
) ||
2124 void wxListCtrl::OnRenameCancelled(long itemEdit
)
2126 // let owner know that the edit was cancelled
2127 wxListEvent
le( wxEVT_COMMAND_LIST_END_LABEL_EDIT
, GetParent()->GetId() );
2129 le
.SetEditCanceled(true);
2131 le
.SetEventObject( this );
2132 le
.m_itemIndex
= itemEdit
;
2134 GetItem( le
.m_item
);
2135 GetEventHandler()->ProcessEvent( le
);
2138 // ----------------------------------------------------------------------------
2139 // virtual list controls
2140 // ----------------------------------------------------------------------------
2142 wxString
wxListCtrl::OnGetItemText(long WXUNUSED(item
), long WXUNUSED(col
)) const
2144 // this is a pure virtual function, in fact - which is not really pure
2145 // because the controls which are not virtual don't need to implement it
2146 wxFAIL_MSG( _T("wxListCtrl::OnGetItemText not supposed to be called") );
2148 return wxEmptyString
;
2151 int wxListCtrl::OnGetItemImage(long WXUNUSED(item
)) const
2153 wxCHECK_MSG(!GetImageList(wxIMAGE_LIST_SMALL
),
2155 wxT("List control has an image list, OnGetItemImage or OnGetItemColumnImage should be overridden."));
2159 int wxListCtrl::OnGetItemColumnImage(long item
, long column
) const
2162 return OnGetItemImage(item
);
2167 wxListItemAttr
*wxListCtrl::OnGetItemAttr(long WXUNUSED_UNLESS_DEBUG(item
)) const
2169 wxASSERT_MSG( item
>= 0 && item
< GetItemCount(),
2170 _T("invalid item index in OnGetItemAttr()") );
2172 // no attributes by default
2176 void wxListCtrl::SetItemCount(long count
)
2178 wxASSERT_MSG( IsVirtual(), _T("this is for virtual controls only") );
2182 m_genericImpl
->SetItemCount(count
);
2188 // we need to temporarily disable the new item creation notification
2189 // procedure to speed things up
2190 // FIXME: Even this doesn't seem to help much...
2192 // FIXME: Find a more efficient way to do this.
2193 m_dbImpl
->MacClear();
2195 DataBrowserCallbacks callbacks
;
2196 DataBrowserItemNotificationUPP itemUPP
;
2197 GetDataBrowserCallbacks(m_dbImpl
->GetControlRef(), &callbacks
);
2198 itemUPP
= callbacks
.u
.v1
.itemNotificationCallback
;
2199 callbacks
.u
.v1
.itemNotificationCallback
= 0;
2200 m_dbImpl
->SetCallbacks(&callbacks
);
2201 ::AddDataBrowserItems(m_dbImpl
->GetControlRef(), kDataBrowserNoItem
,
2202 count
, NULL
, kDataBrowserItemNoProperty
);
2203 callbacks
.u
.v1
.itemNotificationCallback
= itemUPP
;
2204 m_dbImpl
->SetCallbacks(&callbacks
);
2209 void wxListCtrl::RefreshItem(long item
)
2213 m_genericImpl
->RefreshItem(item
);
2218 GetItemRect(item
, rect
);
2222 void wxListCtrl::RefreshItems(long itemFrom
, long itemTo
)
2226 m_genericImpl
->RefreshItems(itemFrom
, itemTo
);
2230 wxRect rect1
, rect2
;
2231 GetItemRect(itemFrom
, rect1
);
2232 GetItemRect(itemTo
, rect2
);
2234 wxRect rect
= rect1
;
2235 rect
.height
= rect2
.GetBottom() - rect1
.GetTop();
2240 void wxListCtrl::SetDropTarget( wxDropTarget
*dropTarget
)
2242 #if wxUSE_DRAG_AND_DROP
2244 m_genericImpl
->SetDropTarget( dropTarget
);
2247 wxWindow::SetDropTarget( dropTarget
);
2251 wxDropTarget
*wxListCtrl::GetDropTarget() const
2253 #if wxUSE_DRAG_AND_DROP
2255 return m_genericImpl
->GetDropTarget();
2258 return wxWindow::GetDropTarget();
2263 #if wxABI_VERSION >= 20801
2264 void wxListCtrl::SetFocus()
2268 m_genericImpl
->SetFocus();
2272 wxWindow::SetFocus();
2276 // wxMac internal data structures
2278 wxMacListCtrlItem::~wxMacListCtrlItem()
2282 void wxMacListCtrlItem::Notification(wxMacDataItemBrowserControl
*owner
,
2283 DataBrowserItemNotification message
,
2284 DataBrowserItemDataRef itemData
) const
2287 wxMacDataBrowserListCtrlControl
*lb
= wxDynamicCast(owner
, wxMacDataBrowserListCtrlControl
);
2289 // we want to depend on as little as possible to make sure tear-down of controls is safe
2290 if ( message
== kDataBrowserItemRemoved
)
2292 if ( lb
!= NULL
&& lb
->GetClientDataType() == wxClientData_Object
)
2294 delete (wxClientData
*) (m_data
);
2300 else if ( message
== kDataBrowserItemAdded
)
2302 // we don't issue events on adding, the item is not really stored in the list yet, so we
2303 // avoid asserts by gettting out now
2307 wxListCtrl
*list
= wxDynamicCast( owner
->GetPeer() , wxListCtrl
);
2310 bool trigger
= false;
2312 wxListEvent
event( wxEVT_COMMAND_LIST_ITEM_SELECTED
, list
->GetId() );
2313 bool isSingle
= (list
->GetWindowStyle() & wxLC_SINGLE_SEL
) != 0;
2315 event
.SetEventObject( list
);
2316 event
.m_itemIndex
= owner
->GetLineFromItem( this ) ;
2317 if ( !list
->IsVirtual() )
2319 lb
->MacGetColumnInfo(event
.m_itemIndex
,0,event
.m_item
);
2324 case kDataBrowserItemDeselected
:
2325 event
.SetEventType(wxEVT_COMMAND_LIST_ITEM_DESELECTED
);
2327 trigger
= !lb
->IsSelectionSuppressed();
2330 case kDataBrowserItemSelected
:
2331 trigger
= !lb
->IsSelectionSuppressed();
2334 case kDataBrowserItemDoubleClicked
:
2335 event
.SetEventType( wxEVT_COMMAND_LIST_ITEM_ACTIVATED
);
2339 case kDataBrowserEditStarted
:
2340 // TODO : how to veto ?
2341 event
.SetEventType( wxEVT_COMMAND_LIST_BEGIN_LABEL_EDIT
) ;
2345 case kDataBrowserEditStopped
:
2346 // TODO probably trigger only upon the value store callback, because
2347 // here IIRC we cannot veto
2348 event
.SetEventType( wxEVT_COMMAND_LIST_END_LABEL_EDIT
) ;
2358 // direct notification is not always having the listbox GetSelection() having in synch with event
2359 wxPostEvent( list
->GetEventHandler(), event
);
2365 IMPLEMENT_DYNAMIC_CLASS(wxMacDataBrowserListCtrlControl
, wxMacDataItemBrowserControl
)
2367 wxMacDataBrowserListCtrlControl::wxMacDataBrowserListCtrlControl( wxWindow
*peer
, const wxPoint
& pos
, const wxSize
& size
, long style
)
2368 : wxMacDataItemBrowserControl( peer
, pos
, size
, style
)
2370 OSStatus err
= noErr
;
2371 m_clientDataItemsType
= wxClientData_None
;
2372 m_isVirtual
= false;
2375 if ( style
& wxLC_VIRTUAL
)
2378 DataBrowserSelectionFlags options
= kDataBrowserDragSelect
;
2379 if ( style
& wxLC_SINGLE_SEL
)
2381 options
|= kDataBrowserSelectOnlyOne
;
2385 options
|= kDataBrowserCmdTogglesSelection
;
2388 err
= SetSelectionFlags( options
);
2389 verify_noerr( err
);
2391 DataBrowserCustomCallbacks callbacks
;
2392 InitializeDataBrowserCustomCallbacks( &callbacks
, kDataBrowserLatestCustomCallbacks
);
2394 if ( gDataBrowserDrawItemUPP
== NULL
)
2395 gDataBrowserDrawItemUPP
= NewDataBrowserDrawItemUPP(DataBrowserDrawItemProc
);
2397 if ( gDataBrowserHitTestUPP
== NULL
)
2398 gDataBrowserHitTestUPP
= NewDataBrowserHitTestUPP(DataBrowserHitTestProc
);
2400 callbacks
.u
.v1
.drawItemCallback
= gDataBrowserDrawItemUPP
;
2401 callbacks
.u
.v1
.hitTestCallback
= gDataBrowserHitTestUPP
;
2403 SetDataBrowserCustomCallbacks( GetControlRef(), &callbacks
);
2405 if ( style
& wxLC_LIST
)
2407 InsertColumn(0, kDataBrowserIconAndTextType
, wxEmptyString
, -1, -1);
2408 verify_noerr( AutoSizeColumns() );
2411 if ( style
& wxLC_LIST
|| style
& wxLC_NO_HEADER
)
2412 verify_noerr( SetHeaderButtonHeight( 0 ) );
2415 SetSortProperty( kMinColumnId
- 1 );
2417 SetSortProperty( kMinColumnId
);
2419 m_sortOrder
= SortOrder_None
;
2421 if ( style
& wxLC_SORT_DESCENDING
)
2423 SetSortOrder( kDataBrowserOrderDecreasing
);
2425 else if ( style
& wxLC_SORT_ASCENDING
)
2427 SetSortOrder( kDataBrowserOrderIncreasing
);
2430 if ( style
& wxLC_VRULES
)
2432 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4
2433 verify_noerr( DataBrowserChangeAttributes(m_controlRef
, kDataBrowserAttributeListViewDrawColumnDividers
, kDataBrowserAttributeNone
) );
2437 verify_noerr( SetHiliteStyle(kDataBrowserTableViewFillHilite
) );
2438 verify_noerr( SetHasScrollBars( (style
& wxHSCROLL
) != 0 , true ) );
2441 pascal Boolean
wxMacDataBrowserListCtrlControl::DataBrowserEditTextProc(
2443 DataBrowserItemID itemID
,
2444 DataBrowserPropertyID property
,
2445 CFStringRef theString
,
2446 Rect
*maxEditTextRect
,
2447 Boolean
*shrinkToFit
)
2449 Boolean result
= false;
2450 wxMacDataBrowserListCtrlControl
* ctl
= wxDynamicCast(wxMacControl::GetReferenceFromNativeControl( browser
), wxMacDataBrowserListCtrlControl
);
2453 result
= ctl
->ConfirmEditText(itemID
, property
, theString
, maxEditTextRect
, shrinkToFit
);
2454 theString
= CFSTR("Hello!");
2459 bool wxMacDataBrowserListCtrlControl::ConfirmEditText(
2460 DataBrowserItemID itemID
,
2461 DataBrowserPropertyID property
,
2462 CFStringRef theString
,
2463 Rect
*maxEditTextRect
,
2464 Boolean
*shrinkToFit
)
2469 pascal void wxMacDataBrowserListCtrlControl::DataBrowserDrawItemProc(
2471 DataBrowserItemID itemID
,
2472 DataBrowserPropertyID property
,
2473 DataBrowserItemState itemState
,
2474 const Rect
*itemRect
,
2476 Boolean colorDevice
)
2478 wxMacDataBrowserListCtrlControl
* ctl
= wxDynamicCast(wxMacControl::GetReferenceFromNativeControl( browser
), wxMacDataBrowserListCtrlControl
);
2481 ctl
->DrawItem(itemID
, property
, itemState
, itemRect
, gdDepth
, colorDevice
);
2485 // routines needed for DrawItem
2490 kTextBoxHeight
= 14,
2491 kIconTextSpacingV
= 2,
2493 kContentHeight
= kIconHeight
+ kTextBoxHeight
+ kIconTextSpacingV
2496 static void calculateCGDrawingBounds(CGRect inItemRect
, CGRect
*outIconRect
, CGRect
*outTextRect
, bool hasIcon
= false)
2499 float iconH
, iconW
= 0;
2500 float padding
= kItemPadding
;
2503 iconH
= kIconHeight
;
2505 padding
= padding
*2;
2508 textBottom
= inItemRect
.origin
.y
;
2510 *outIconRect
= CGRectMake(inItemRect
.origin
.x
+ kItemPadding
,
2511 textBottom
+ kIconTextSpacingV
, kIconWidth
,
2514 *outTextRect
= CGRectMake(inItemRect
.origin
.x
+ padding
+ iconW
,
2515 textBottom
+ kIconTextSpacingV
, inItemRect
.size
.width
- padding
- iconW
,
2516 inItemRect
.size
.height
- kIconTextSpacingV
);
2519 void wxMacDataBrowserListCtrlControl::DrawItem(
2520 DataBrowserItemID itemID
,
2521 DataBrowserPropertyID property
,
2522 DataBrowserItemState itemState
,
2523 const Rect
*itemRect
,
2525 Boolean colorDevice
)
2528 wxFont font
= wxNullFont
;
2530 short listColumn
= property
- kMinColumnId
;
2532 wxListCtrl
* list
= wxDynamicCast( GetPeer() , wxListCtrl
);
2533 wxMacListCtrlItem
* lcItem
;
2534 wxColour color
= *wxBLACK
;
2535 wxColour bgColor
= wxNullColour
;
2537 if (listColumn
>= 0)
2541 lcItem
= (wxMacListCtrlItem
*) itemID
;
2542 if (lcItem
->HasColumnInfo(listColumn
)){
2543 wxListItem
* item
= lcItem
->GetColumnInfo(listColumn
);
2545 // we always use the 0 column to get font and text/background colors.
2546 if (lcItem
->HasColumnInfo(0))
2548 wxListItem
* firstItem
= lcItem
->GetColumnInfo(0);
2549 color
= firstItem
->GetTextColour();
2550 bgColor
= firstItem
->GetBackgroundColour();
2551 font
= firstItem
->GetFont();
2554 if (item
->GetMask() & wxLIST_MASK_TEXT
)
2555 text
= item
->GetText();
2556 if (item
->GetMask() & wxLIST_MASK_IMAGE
)
2557 imgIndex
= item
->GetImage();
2563 text
= list
->OnGetItemText( (long)itemID
-1, listColumn
);
2564 imgIndex
= list
->OnGetItemColumnImage( (long)itemID
-1, listColumn
);
2565 wxListItemAttr
* attrs
= list
->OnGetItemAttr( (long)itemID
-1 );
2568 if (attrs
->HasBackgroundColour())
2569 bgColor
= attrs
->GetBackgroundColour();
2570 if (attrs
->HasTextColour())
2571 color
= attrs
->GetTextColour();
2572 if (attrs
->HasFont())
2573 font
= attrs
->GetFont();
2578 wxColour listBgColor
= list
->GetBackgroundColour();
2579 if (bgColor
== wxNullColour
)
2580 bgColor
= listBgColor
;
2582 wxFont listFont
= list
->GetFont();
2583 if (font
== wxNullFont
)
2586 wxMacCFStringHolder cfString
;
2587 cfString
.Assign( text
, wxLocale::GetSystemEncoding() );
2590 CGRect enclosingCGRect
, iconCGRect
, textCGRect
;
2592 ThemeDrawingState savedState
= NULL
;
2593 CGContextRef context
= (CGContextRef
)list
->MacGetDrawingContext();
2594 RGBColor labelColor
;
2596 labelColor
.green
= 0;
2597 labelColor
.blue
= 0;
2599 RGBColor backgroundColor
;
2600 backgroundColor
.red
= 255;
2601 backgroundColor
.green
= 255;
2602 backgroundColor
.blue
= 255;
2604 GetDataBrowserItemPartBounds(GetControlRef(), itemID
, property
, kDataBrowserPropertyEnclosingPart
,
2607 enclosingCGRect
= CGRectMake(enclosingRect
.left
,
2609 enclosingRect
.right
- enclosingRect
.left
,
2610 enclosingRect
.bottom
- enclosingRect
.top
);
2612 active
= IsControlActive(GetControlRef());
2614 // don't paint the background over the vertical rule line
2615 if ( list
->GetWindowStyleFlag() & wxLC_VRULES
)
2617 enclosingCGRect
.origin
.x
+= 1;
2618 enclosingCGRect
.size
.width
-= 1;
2620 if (itemState
== kDataBrowserItemIsSelected
)
2623 GetThemeDrawingState(&savedState
);
2627 GetThemeBrushAsColor(kThemeBrushAlternatePrimaryHighlightColor
, 32, true, &backgroundColor
);
2628 GetThemeTextColor(kThemeTextColorWhite
, gdDepth
, colorDevice
, &labelColor
);
2632 GetThemeBrushAsColor(kThemeBrushSecondaryHighlightColor
, 32, true, &backgroundColor
);
2633 GetThemeTextColor(kThemeTextColorBlack
, gdDepth
, colorDevice
, &labelColor
);
2635 CGContextSaveGState(context
);
2637 CGContextSetRGBFillColor(context
, (float)backgroundColor
.red
/ (float)USHRT_MAX
,
2638 (float)backgroundColor
.green
/ (float)USHRT_MAX
,
2639 (float)backgroundColor
.blue
/ (float)USHRT_MAX
, 1.0);
2640 CGContextFillRect(context
, enclosingCGRect
);
2642 CGContextRestoreGState(context
);
2648 labelColor
= MAC_WXCOLORREF( color
.GetPixel() );
2649 else if (list
->GetTextColour().Ok())
2650 labelColor
= MAC_WXCOLORREF( list
->GetTextColour().GetPixel() );
2654 backgroundColor
= MAC_WXCOLORREF( bgColor
.GetPixel() );
2655 CGContextSaveGState(context
);
2657 CGContextSetRGBFillColor(context
, (float)backgroundColor
.red
/ (float)USHRT_MAX
,
2658 (float)backgroundColor
.green
/ (float)USHRT_MAX
,
2659 (float)backgroundColor
.blue
/ (float)USHRT_MAX
, 1.0);
2660 CGContextFillRect(context
, enclosingCGRect
);
2662 CGContextRestoreGState(context
);
2666 calculateCGDrawingBounds(enclosingCGRect
, &iconCGRect
, &textCGRect
, (imgIndex
!= -1) );
2670 wxImageList
* imageList
= list
->GetImageList(wxIMAGE_LIST_SMALL
);
2671 if (imageList
&& imageList
->GetImageCount() > 0){
2672 wxBitmap bmp
= imageList
->GetBitmap(imgIndex
);
2673 IconRef icon
= bmp
.GetBitmapData()->GetIconRef();
2675 CGContextSaveGState(context
);
2676 CGContextTranslateCTM(context
, 0,iconCGRect
.origin
.y
+ CGRectGetMaxY(iconCGRect
));
2677 CGContextScaleCTM(context
,1.0f
,-1.0f
);
2678 PlotIconRefInContext(context
, &iconCGRect
, kAlignNone
,
2679 active
? kTransformNone
: kTransformDisabled
, NULL
,
2680 kPlotIconRefNormalFlags
, icon
);
2682 CGContextRestoreGState(context
);
2686 HIThemeTextHorizontalFlush hFlush
= kHIThemeTextHorizontalFlushLeft
;
2687 UInt16 fontID
= kThemeViewsFont
;
2691 if (font
.GetFamily() != wxFONTFAMILY_DEFAULT
)
2692 fontID
= font
.MacGetThemeFontID();
2694 // FIXME: replace these with CG or ATSUI calls so we can remove this #ifndef.
2696 ::TextSize( (short)(font
.MacGetFontSize()) ) ;
2697 ::TextFace( font
.MacGetFontStyle() ) ;
2702 list
->GetColumn(listColumn
, item
);
2703 if (item
.GetMask() & wxLIST_MASK_FORMAT
)
2705 if (item
.GetAlign() == wxLIST_FORMAT_LEFT
)
2706 hFlush
= kHIThemeTextHorizontalFlushLeft
;
2707 else if (item
.GetAlign() == wxLIST_FORMAT_CENTER
)
2708 hFlush
= kHIThemeTextHorizontalFlushCenter
;
2709 else if (item
.GetAlign() == wxLIST_FORMAT_RIGHT
)
2711 hFlush
= kHIThemeTextHorizontalFlushRight
;
2712 textCGRect
.origin
.x
-= kItemPadding
; // give a little extra paddding
2716 HIThemeTextInfo info
;
2717 info
.version
= kHIThemeTextInfoVersionZero
;
2718 info
.state
= active
? kThemeStateActive
: kThemeStateInactive
;
2719 info
.fontID
= fontID
;
2720 info
.horizontalFlushness
= hFlush
;
2721 info
.verticalFlushness
= kHIThemeTextVerticalFlushCenter
;
2722 info
.options
= kHIThemeTextBoxOptionNone
;
2723 info
.truncationPosition
= kHIThemeTextTruncationEnd
;
2724 info
.truncationMaxLines
= 1;
2726 CGContextSaveGState(context
);
2727 CGContextSetRGBFillColor (context
, (float)labelColor
.red
/ (float)USHRT_MAX
,
2728 (float)labelColor
.green
/ (float)USHRT_MAX
,
2729 (float)labelColor
.blue
/ (float)USHRT_MAX
, 1.0);
2731 HIThemeDrawTextBox(cfString
, &textCGRect
, &info
, context
, kHIThemeOrientationNormal
);
2733 CGContextRestoreGState(context
);
2735 if (savedState
!= NULL
)
2736 SetThemeDrawingState(savedState
, true);
2739 OSStatus
wxMacDataBrowserListCtrlControl::GetSetItemData(DataBrowserItemID itemID
,
2740 DataBrowserPropertyID property
,
2741 DataBrowserItemDataRef itemData
,
2742 Boolean changeValue
)
2746 short listColumn
= property
- kMinColumnId
;
2748 OSStatus err
= errDataBrowserPropertyNotSupported
;
2749 wxListCtrl
* list
= wxDynamicCast( GetPeer() , wxListCtrl
);
2750 wxMacListCtrlItem
* lcItem
;
2752 if (listColumn
>= 0)
2756 lcItem
= (wxMacListCtrlItem
*) itemID
;
2757 if (lcItem
&& lcItem
->HasColumnInfo(listColumn
)){
2758 wxListItem
* item
= lcItem
->GetColumnInfo(listColumn
);
2759 if (item
->GetMask() & wxLIST_MASK_TEXT
)
2760 text
= item
->GetText();
2761 if (item
->GetMask() & wxLIST_MASK_IMAGE
)
2762 imgIndex
= item
->GetImage();
2767 text
= list
->OnGetItemText( (long)itemID
-1, listColumn
);
2768 imgIndex
= list
->OnGetItemColumnImage( (long)itemID
-1, listColumn
);
2776 case kDataBrowserItemIsEditableProperty
:
2777 if ( list
&& list
->HasFlag( wxLC_EDIT_LABELS
) )
2779 verify_noerr(SetDataBrowserItemDataBooleanValue( itemData
, true ));
2784 if ( property
>= kMinColumnId
)
2786 wxMacCFStringHolder cfStr
;
2789 cfStr
.Assign( text
, wxLocale::GetSystemEncoding() );
2790 err
= ::SetDataBrowserItemDataText( itemData
, cfStr
);
2796 if ( imgIndex
!= -1 )
2798 wxImageList
* imageList
= list
->GetImageList(wxIMAGE_LIST_SMALL
);
2799 if (imageList
&& imageList
->GetImageCount() > 0){
2800 wxBitmap bmp
= imageList
->GetBitmap(imgIndex
);
2801 IconRef icon
= bmp
.GetBitmapData()->GetIconRef();
2802 ::SetDataBrowserItemDataIcon(itemData
, icon
);
2816 if ( property
>= kMinColumnId
)
2818 short listColumn
= property
- kMinColumnId
;
2820 // TODO probably send the 'end edit' from here, as we
2821 // can then deal with the veto
2823 verify_noerr( GetDataBrowserItemDataText( itemData
, &sr
) ) ;
2824 wxMacCFStringHolder
cfStr(sr
) ;;
2826 list
->SetItem( (long)itemData
-1 , listColumn
, cfStr
.AsString() ) ;
2830 lcItem
->SetColumnTextValue( listColumn
, cfStr
.AsString() );
2840 void wxMacDataBrowserListCtrlControl::ItemNotification(DataBrowserItemID itemID
,
2841 DataBrowserItemNotification message
,
2842 DataBrowserItemDataRef itemData
)
2844 // we want to depend on as little as possible to make sure tear-down of controls is safe
2845 if ( message
== kDataBrowserItemRemoved
)
2847 // make sure MacDelete does the proper teardown.
2850 else if ( message
== kDataBrowserItemAdded
)
2852 // we don't issue events on adding, the item is not really stored in the list yet, so we
2853 // avoid asserts by getting out now
2857 wxListCtrl
*list
= wxDynamicCast( GetPeer() , wxListCtrl
);
2860 bool trigger
= false;
2862 wxListEvent
event( wxEVT_COMMAND_LIST_ITEM_SELECTED
, list
->GetId() );
2863 bool isSingle
= (list
->GetWindowStyle() & wxLC_SINGLE_SEL
) != 0;
2865 event
.SetEventObject( list
);
2866 if ( !list
->IsVirtual() )
2868 DataBrowserTableViewRowIndex result
= 0;
2869 verify_noerr( GetItemRow( itemID
, &result
) ) ;
2870 event
.m_itemIndex
= result
;
2872 if (event
.m_itemIndex
>= 0)
2873 MacGetColumnInfo(event
.m_itemIndex
,0,event
.m_item
);
2877 event
.m_itemIndex
= (long)itemID
-1;
2882 case kDataBrowserItemDeselected
:
2883 event
.SetEventType(wxEVT_COMMAND_LIST_ITEM_DESELECTED
);
2885 trigger
= !IsSelectionSuppressed();
2888 case kDataBrowserItemSelected
:
2889 trigger
= !IsSelectionSuppressed();
2893 case kDataBrowserItemDoubleClicked
:
2894 event
.SetEventType( wxEVT_COMMAND_LIST_ITEM_ACTIVATED
);
2898 case kDataBrowserEditStarted
:
2899 // TODO : how to veto ?
2900 event
.SetEventType( wxEVT_COMMAND_LIST_BEGIN_LABEL_EDIT
) ;
2904 case kDataBrowserEditStopped
:
2905 // TODO probably trigger only upon the value store callback, because
2906 // here IIRC we cannot veto
2907 event
.SetEventType( wxEVT_COMMAND_LIST_END_LABEL_EDIT
) ;
2917 // direct notification is not always having the listbox GetSelection() having in synch with event
2918 wxPostEvent( list
->GetEventHandler(), event
);
2923 Boolean
wxMacDataBrowserListCtrlControl::CompareItems(DataBrowserItemID itemOneID
,
2924 DataBrowserItemID itemTwoID
,
2925 DataBrowserPropertyID sortProperty
)
2928 bool retval
= false;
2930 wxString otherItemText
;
2932 long otherItemOrder
;
2934 int colId
= sortProperty
- kMinColumnId
;
2936 wxListCtrl
* list
= wxDynamicCast( GetPeer() , wxListCtrl
);
2938 DataBrowserSortOrder sort
;
2939 verify_noerr(GetSortOrder(&sort
));
2945 wxMacListCtrlItem
* item
= (wxMacListCtrlItem
*)itemOneID
;
2946 wxMacListCtrlItem
* otherItem
= (wxMacListCtrlItem
*)itemTwoID
;
2948 itemOrder
= item
->GetOrder();
2949 otherItemOrder
= item
->GetOrder();
2951 wxListCtrlCompare func
= list
->GetCompareFunc();
2956 if (item
&& item
->HasColumnInfo(0))
2957 item1
= item
->GetColumnInfo(0)->GetData();
2958 if (otherItem
&& otherItem
->HasColumnInfo(0))
2959 item2
= otherItem
->GetColumnInfo(0)->GetData();
2961 if (item1
> -1 && item2
> -1)
2963 int result
= func(item1
, item2
, list
->GetCompareFuncData());
2964 if (sort
== kDataBrowserOrderIncreasing
)
2971 // we can't use the native control's sorting abilities, so just
2973 return itemOrder
< otherItemOrder
;
2978 long itemNum
= (long)itemOneID
;
2979 long otherItemNum
= (long)itemTwoID
;
2980 itemText
= list
->OnGetItemText( itemNum
-1, colId
);
2981 otherItemText
= list
->OnGetItemText( otherItemNum
-1, colId
);
2983 // virtual listctrls don't support sorting
2984 return itemNum
< otherItemNum
;
2988 // fallback for undefined cases
2989 retval
= itemOneID
< itemTwoID
;
2995 wxMacDataBrowserListCtrlControl::~wxMacDataBrowserListCtrlControl()
2999 void wxMacDataBrowserListCtrlControl::MacSetColumnInfo( unsigned int row
, unsigned int column
, wxListItem
* item
)
3001 wxMacDataItem
* dataItem
= GetItemFromLine(row
);
3002 wxASSERT_MSG( dataItem
, _T("could not obtain wxMacDataItem for row in MacSetColumnInfo. Is row a valid wxListCtrl row?") );
3005 wxMacListCtrlItem
* listItem
= wx_static_cast(wxMacListCtrlItem
*,dataItem
);
3006 bool hasInfo
= listItem
->HasColumnInfo( column
);
3007 listItem
->SetColumnInfo( column
, item
);
3008 listItem
->SetOrder(row
);
3009 UpdateState(dataItem
, item
);
3011 wxListCtrl
* list
= wxDynamicCast( GetPeer() , wxListCtrl
);
3013 // NB: When this call was made before a control was completely shown, it would
3014 // update the item prematurely (i.e. no text would be listed) and, on show,
3015 // only the sorted column would be refreshed, meaning only first column text labels
3016 // would be shown. Making sure not to update items until the control is visible
3017 // seems to fix this issue.
3018 if (hasInfo
&& list
->IsShown())
3019 UpdateItem( wxMacDataBrowserRootContainer
, listItem
, kMinColumnId
+ column
);
3023 // apply changes that need to happen immediately, rather than when the
3024 // databrowser control fires a callback.
3025 void wxMacDataBrowserListCtrlControl::UpdateState(wxMacDataItem
* dataItem
, wxListItem
* listItem
)
3027 bool isSelected
= IsItemSelected( dataItem
);
3028 bool isSelectedState
= (listItem
->GetState() == wxLIST_STATE_SELECTED
);
3030 // toggle the selection state if wxListInfo state and actual state don't match.
3031 if ( isSelected
!= isSelectedState
)
3033 DataBrowserSetOption options
= kDataBrowserItemsAdd
;
3034 if (!isSelectedState
)
3035 options
= kDataBrowserItemsRemove
;
3036 SetSelectedItem(dataItem
, options
);
3038 // TODO: Set column width if item width > than current column width
3041 void wxMacDataBrowserListCtrlControl::MacGetColumnInfo( unsigned int row
, unsigned int column
, wxListItem
& item
)
3043 wxMacDataItem
* dataItem
= GetItemFromLine(row
);
3044 wxASSERT_MSG( dataItem
, _T("could not obtain wxMacDataItem in MacGetColumnInfo. Is row a valid wxListCtrl row?") );
3045 // CS should this guard against dataItem = 0 ? , as item is not a pointer if (item) is not appropriate
3048 wxMacListCtrlItem
* listItem
=wx_static_cast(wxMacListCtrlItem
*,dataItem
);
3050 if (!listItem
->HasColumnInfo( column
))
3053 wxListItem
* oldItem
= listItem
->GetColumnInfo( column
);
3057 long mask
= item
.GetMask();
3059 // by default, get everything for backwards compatibility
3062 if ( mask
& wxLIST_MASK_TEXT
)
3063 item
.SetText(oldItem
->GetText());
3064 if ( mask
& wxLIST_MASK_IMAGE
)
3065 item
.SetImage(oldItem
->GetImage());
3066 if ( mask
& wxLIST_MASK_DATA
)
3067 item
.SetData(oldItem
->GetData());
3068 if ( mask
& wxLIST_MASK_STATE
)
3069 item
.SetState(oldItem
->GetState());
3070 if ( mask
& wxLIST_MASK_WIDTH
)
3071 item
.SetWidth(oldItem
->GetWidth());
3072 if ( mask
& wxLIST_MASK_FORMAT
)
3073 item
.SetAlign(oldItem
->GetAlign());
3075 item
.SetTextColour(oldItem
->GetTextColour());
3076 item
.SetBackgroundColour(oldItem
->GetBackgroundColour());
3077 item
.SetFont(oldItem
->GetFont());
3082 void wxMacDataBrowserListCtrlControl::MacInsertItem( unsigned int n
, wxListItem
* item
)
3084 wxMacDataItemBrowserControl::MacInsert(n
, item
->GetText());
3085 MacSetColumnInfo(n
, 0, item
);
3088 wxMacDataItem
* wxMacDataBrowserListCtrlControl::CreateItem()
3090 return new wxMacListCtrlItem();
3093 wxMacListCtrlItem::wxMacListCtrlItem()
3095 m_rowItems
= wxListItemList();
3098 int wxMacListCtrlItem::GetColumnImageValue( unsigned int column
)
3100 if ( HasColumnInfo(column
) )
3101 return GetColumnInfo(column
)->GetImage();
3106 void wxMacListCtrlItem::SetColumnImageValue( unsigned int column
, int imageIndex
)
3108 if ( HasColumnInfo(column
) )
3109 GetColumnInfo(column
)->SetImage(imageIndex
);
3112 wxString
wxMacListCtrlItem::GetColumnTextValue( unsigned int column
)
3117 if ( HasColumnInfo(column
) )
3118 return GetColumnInfo(column
)->GetText();
3120 return wxEmptyString
;
3123 void wxMacListCtrlItem::SetColumnTextValue( unsigned int column
, const wxString
& text
)
3125 if ( HasColumnInfo(column
) )
3126 GetColumnInfo(column
)->SetText(text
);
3128 // for compatibility with superclass APIs
3133 wxListItem
* wxMacListCtrlItem::GetColumnInfo( unsigned int column
)
3135 wxASSERT_MSG( HasColumnInfo(column
), _T("invalid column index in wxMacListCtrlItem") );
3136 return m_rowItems
[column
];
3139 bool wxMacListCtrlItem::HasColumnInfo( unsigned int column
)
3141 return !(m_rowItems
.find( column
) == m_rowItems
.end());
3144 void wxMacListCtrlItem::SetColumnInfo( unsigned int column
, wxListItem
* item
)
3147 if ( !HasColumnInfo(column
) )
3149 wxListItem
* listItem
= new wxListItem(*item
);
3150 m_rowItems
[column
] = listItem
;
3154 wxListItem
* listItem
= GetColumnInfo( column
);
3155 long mask
= item
->GetMask();
3156 if (mask
& wxLIST_MASK_TEXT
)
3157 listItem
->SetText(item
->GetText());
3158 if (mask
& wxLIST_MASK_DATA
)
3159 listItem
->SetData(item
->GetData());
3160 if (mask
& wxLIST_MASK_IMAGE
)
3161 listItem
->SetImage(item
->GetImage());
3162 if (mask
& wxLIST_MASK_STATE
)
3163 listItem
->SetState(item
->GetState());
3164 if (mask
& wxLIST_MASK_FORMAT
)
3165 listItem
->SetAlign(item
->GetAlign());
3166 if (mask
& wxLIST_MASK_WIDTH
)
3167 listItem
->SetWidth(item
->GetWidth());
3169 if ( item
->HasAttributes() )
3171 if ( listItem
->HasAttributes() )
3172 listItem
->GetAttributes()->AssignFrom(*item
->GetAttributes());
3175 listItem
->SetTextColour(item
->GetTextColour());
3176 listItem
->SetBackgroundColour(item
->GetBackgroundColour());
3177 listItem
->SetFont(item
->GetFont());
3183 #endif // wxUSE_LISTCTRL