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
);
1949 wxMacDataItem
* dataItem
= m_dbImpl
->GetItemFromLine(info
.m_itemId
);
1951 wxListEvent
event( wxEVT_COMMAND_LIST_INSERT_ITEM
, GetId() );
1952 event
.SetEventObject( this );
1953 event
.m_itemIndex
= info
.m_itemId
;
1954 GetEventHandler()->ProcessEvent( event
);
1955 return info
.m_itemId
;
1960 long wxListCtrl::InsertItem(long index
, const wxString
& label
)
1963 return m_genericImpl
->InsertItem(index
, label
);
1966 info
.m_text
= label
;
1967 info
.m_mask
= wxLIST_MASK_TEXT
;
1968 info
.m_itemId
= index
;
1969 return InsertItem(info
);
1972 // Inserts an image item
1973 long wxListCtrl::InsertItem(long index
, int imageIndex
)
1976 return m_genericImpl
->InsertItem(index
, imageIndex
);
1979 info
.m_image
= imageIndex
;
1980 info
.m_mask
= wxLIST_MASK_IMAGE
;
1981 info
.m_itemId
= index
;
1982 return InsertItem(info
);
1985 // Inserts an image/string item
1986 long wxListCtrl::InsertItem(long index
, const wxString
& label
, int imageIndex
)
1989 return m_genericImpl
->InsertItem(index
, label
, imageIndex
);
1992 info
.m_image
= imageIndex
;
1993 info
.m_text
= label
;
1994 info
.m_mask
= wxLIST_MASK_IMAGE
| wxLIST_MASK_TEXT
;
1995 info
.m_itemId
= index
;
1996 return InsertItem(info
);
1999 // For list view mode (only), inserts a column.
2000 long wxListCtrl::InsertColumn(long col
, wxListItem
& item
)
2003 return m_genericImpl
->InsertColumn(col
, item
);
2007 int width
= item
.GetWidth();
2008 if ( !(item
.GetMask() & wxLIST_MASK_WIDTH
) )
2011 DataBrowserPropertyType type
= kDataBrowserCustomType
; //kDataBrowserTextType;
2012 wxImageList
* imageList
= GetImageList(wxIMAGE_LIST_SMALL
);
2013 if (imageList
&& imageList
->GetImageCount() > 0)
2015 wxBitmap bmp
= imageList
->GetBitmap(0);
2017 // type = kDataBrowserIconAndTextType;
2020 SInt16 just
= teFlushDefault
;
2021 if (item
.GetMask() & wxLIST_MASK_FORMAT
)
2023 if (item
.GetAlign() == wxLIST_FORMAT_LEFT
)
2025 else if (item
.GetAlign() == wxLIST_FORMAT_CENTER
)
2027 else if (item
.GetAlign() == wxLIST_FORMAT_RIGHT
)
2028 just
= teFlushRight
;
2030 m_dbImpl
->InsertColumn(col
, type
, item
.GetText(), just
, width
);
2031 SetColumn(col
, item
);
2033 // set/remove options based on the wxListCtrl type.
2034 DataBrowserTableViewColumnID id
;
2035 m_dbImpl
->GetColumnIDFromIndex(col
, &id
);
2036 DataBrowserPropertyFlags flags
;
2037 verify_noerr(m_dbImpl
->GetPropertyFlags(id
, &flags
));
2038 if (GetWindowStyleFlag() & wxLC_EDIT_LABELS
)
2039 flags
|= kDataBrowserPropertyIsEditable
;
2041 if (GetWindowStyleFlag() & wxLC_VIRTUAL
){
2042 flags
&= ~kDataBrowserListViewSortableColumn
;
2044 verify_noerr(m_dbImpl
->SetPropertyFlags(id
, flags
));
2050 long wxListCtrl::InsertColumn(long col
,
2051 const wxString
& heading
,
2056 return m_genericImpl
->InsertColumn(col
, heading
, format
, width
);
2059 item
.m_mask
= wxLIST_MASK_TEXT
| wxLIST_MASK_FORMAT
;
2060 item
.m_text
= heading
;
2063 item
.m_mask
|= wxLIST_MASK_WIDTH
;
2064 item
.m_width
= width
;
2066 item
.m_format
= format
;
2068 return InsertColumn(col
, item
);
2071 // scroll the control by the given number of pixels (exception: in list view,
2072 // dx is interpreted as number of columns)
2073 bool wxListCtrl::ScrollList(int dx
, int dy
)
2076 return m_genericImpl
->ScrollList(dx
, dy
);
2080 m_dbImpl
->SetScrollPosition(dx
, dy
);
2086 bool wxListCtrl::SortItems(wxListCtrlCompare fn
, long data
)
2089 return m_genericImpl
->SortItems(fn
, data
);
2094 m_compareFuncData
= data
;
2095 SortDataBrowserContainer( m_dbImpl
->GetControlRef(), kDataBrowserNoItem
, true);
2097 // we need to do this after each call, else we get a crash from wxPython when
2098 // SortItems is called the second time.
2099 m_compareFunc
= NULL
;
2100 m_compareFuncData
= 0;
2106 void wxListCtrl::OnRenameTimer()
2108 wxCHECK_RET( HasCurrent(), wxT("unexpected rename timer") );
2110 EditLabel( m_current
);
2113 bool wxListCtrl::OnRenameAccept(long itemEdit
, const wxString
& value
)
2115 wxListEvent
le( wxEVT_COMMAND_LIST_END_LABEL_EDIT
, GetId() );
2116 le
.SetEventObject( this );
2117 le
.m_itemIndex
= itemEdit
;
2119 GetItem( le
.m_item
);
2120 le
.m_item
.m_text
= value
;
2121 return !GetEventHandler()->ProcessEvent( le
) ||
2125 void wxListCtrl::OnRenameCancelled(long itemEdit
)
2127 // let owner know that the edit was cancelled
2128 wxListEvent
le( wxEVT_COMMAND_LIST_END_LABEL_EDIT
, GetParent()->GetId() );
2130 le
.SetEditCanceled(true);
2132 le
.SetEventObject( this );
2133 le
.m_itemIndex
= itemEdit
;
2135 GetItem( le
.m_item
);
2136 GetEventHandler()->ProcessEvent( le
);
2139 // ----------------------------------------------------------------------------
2140 // virtual list controls
2141 // ----------------------------------------------------------------------------
2143 wxString
wxListCtrl::OnGetItemText(long WXUNUSED(item
), long WXUNUSED(col
)) const
2145 // this is a pure virtual function, in fact - which is not really pure
2146 // because the controls which are not virtual don't need to implement it
2147 wxFAIL_MSG( _T("wxListCtrl::OnGetItemText not supposed to be called") );
2149 return wxEmptyString
;
2152 int wxListCtrl::OnGetItemImage(long WXUNUSED(item
)) const
2154 wxCHECK_MSG(!GetImageList(wxIMAGE_LIST_SMALL
),
2156 wxT("List control has an image list, OnGetItemImage or OnGetItemColumnImage should be overridden."));
2160 int wxListCtrl::OnGetItemColumnImage(long item
, long column
) const
2163 return OnGetItemImage(item
);
2168 wxListItemAttr
*wxListCtrl::OnGetItemAttr(long WXUNUSED_UNLESS_DEBUG(item
)) const
2170 wxASSERT_MSG( item
>= 0 && item
< GetItemCount(),
2171 _T("invalid item index in OnGetItemAttr()") );
2173 // no attributes by default
2177 void wxListCtrl::SetItemCount(long count
)
2179 wxASSERT_MSG( IsVirtual(), _T("this is for virtual controls only") );
2183 m_genericImpl
->SetItemCount(count
);
2189 // we need to temporarily disable the new item creation notification
2190 // procedure to speed things up
2191 // FIXME: Even this doesn't seem to help much...
2193 // FIXME: Find a more efficient way to do this.
2194 m_dbImpl
->MacClear();
2196 DataBrowserCallbacks callbacks
;
2197 DataBrowserItemNotificationUPP itemUPP
;
2198 GetDataBrowserCallbacks(m_dbImpl
->GetControlRef(), &callbacks
);
2199 itemUPP
= callbacks
.u
.v1
.itemNotificationCallback
;
2200 callbacks
.u
.v1
.itemNotificationCallback
= 0;
2201 m_dbImpl
->SetCallbacks(&callbacks
);
2202 ::AddDataBrowserItems(m_dbImpl
->GetControlRef(), kDataBrowserNoItem
,
2203 count
, NULL
, kDataBrowserItemNoProperty
);
2204 callbacks
.u
.v1
.itemNotificationCallback
= itemUPP
;
2205 m_dbImpl
->SetCallbacks(&callbacks
);
2210 void wxListCtrl::RefreshItem(long item
)
2214 m_genericImpl
->RefreshItem(item
);
2219 GetItemRect(item
, rect
);
2223 void wxListCtrl::RefreshItems(long itemFrom
, long itemTo
)
2227 m_genericImpl
->RefreshItems(itemFrom
, itemTo
);
2231 wxRect rect1
, rect2
;
2232 GetItemRect(itemFrom
, rect1
);
2233 GetItemRect(itemTo
, rect2
);
2235 wxRect rect
= rect1
;
2236 rect
.height
= rect2
.GetBottom() - rect1
.GetTop();
2241 void wxListCtrl::SetDropTarget( wxDropTarget
*dropTarget
)
2243 #if wxUSE_DRAG_AND_DROP
2245 m_genericImpl
->SetDropTarget( dropTarget
);
2248 wxWindow::SetDropTarget( dropTarget
);
2252 wxDropTarget
*wxListCtrl::GetDropTarget() const
2254 #if wxUSE_DRAG_AND_DROP
2256 return m_genericImpl
->GetDropTarget();
2259 return wxWindow::GetDropTarget();
2264 #if wxABI_VERSION >= 20801
2265 void wxListCtrl::SetFocus()
2269 m_genericImpl
->SetFocus();
2273 wxWindow::SetFocus();
2277 // wxMac internal data structures
2279 wxMacListCtrlItem::~wxMacListCtrlItem()
2283 void wxMacListCtrlItem::Notification(wxMacDataItemBrowserControl
*owner
,
2284 DataBrowserItemNotification message
,
2285 DataBrowserItemDataRef itemData
) const
2288 wxMacDataBrowserListCtrlControl
*lb
= wxDynamicCast(owner
, wxMacDataBrowserListCtrlControl
);
2290 // we want to depend on as little as possible to make sure tear-down of controls is safe
2291 if ( message
== kDataBrowserItemRemoved
)
2293 if ( lb
!= NULL
&& lb
->GetClientDataType() == wxClientData_Object
)
2295 delete (wxClientData
*) (m_data
);
2301 else if ( message
== kDataBrowserItemAdded
)
2303 // we don't issue events on adding, the item is not really stored in the list yet, so we
2304 // avoid asserts by gettting out now
2308 wxListCtrl
*list
= wxDynamicCast( owner
->GetPeer() , wxListCtrl
);
2311 bool trigger
= false;
2313 wxListEvent
event( wxEVT_COMMAND_LIST_ITEM_SELECTED
, list
->GetId() );
2314 bool isSingle
= (list
->GetWindowStyle() & wxLC_SINGLE_SEL
) != 0;
2316 event
.SetEventObject( list
);
2317 event
.m_itemIndex
= owner
->GetLineFromItem( this ) ;
2318 if ( !list
->IsVirtual() )
2320 lb
->MacGetColumnInfo(event
.m_itemIndex
,0,event
.m_item
);
2325 case kDataBrowserItemDeselected
:
2326 event
.SetEventType(wxEVT_COMMAND_LIST_ITEM_DESELECTED
);
2328 trigger
= !lb
->IsSelectionSuppressed();
2331 case kDataBrowserItemSelected
:
2332 trigger
= !lb
->IsSelectionSuppressed();
2335 case kDataBrowserItemDoubleClicked
:
2336 event
.SetEventType( wxEVT_COMMAND_LIST_ITEM_ACTIVATED
);
2340 case kDataBrowserEditStarted
:
2341 // TODO : how to veto ?
2342 event
.SetEventType( wxEVT_COMMAND_LIST_BEGIN_LABEL_EDIT
) ;
2346 case kDataBrowserEditStopped
:
2347 // TODO probably trigger only upon the value store callback, because
2348 // here IIRC we cannot veto
2349 event
.SetEventType( wxEVT_COMMAND_LIST_END_LABEL_EDIT
) ;
2359 // direct notification is not always having the listbox GetSelection() having in synch with event
2360 wxPostEvent( list
->GetEventHandler(), event
);
2366 IMPLEMENT_DYNAMIC_CLASS(wxMacDataBrowserListCtrlControl
, wxMacDataItemBrowserControl
)
2368 wxMacDataBrowserListCtrlControl::wxMacDataBrowserListCtrlControl( wxWindow
*peer
, const wxPoint
& pos
, const wxSize
& size
, long style
)
2369 : wxMacDataItemBrowserControl( peer
, pos
, size
, style
)
2371 OSStatus err
= noErr
;
2372 m_clientDataItemsType
= wxClientData_None
;
2373 m_isVirtual
= false;
2376 if ( style
& wxLC_VIRTUAL
)
2379 DataBrowserSelectionFlags options
= kDataBrowserDragSelect
;
2380 if ( style
& wxLC_SINGLE_SEL
)
2382 options
|= kDataBrowserSelectOnlyOne
;
2386 options
|= kDataBrowserCmdTogglesSelection
;
2389 err
= SetSelectionFlags( options
);
2390 verify_noerr( err
);
2392 DataBrowserCustomCallbacks callbacks
;
2393 InitializeDataBrowserCustomCallbacks( &callbacks
, kDataBrowserLatestCustomCallbacks
);
2395 if ( gDataBrowserDrawItemUPP
== NULL
)
2396 gDataBrowserDrawItemUPP
= NewDataBrowserDrawItemUPP(DataBrowserDrawItemProc
);
2398 if ( gDataBrowserHitTestUPP
== NULL
)
2399 gDataBrowserHitTestUPP
= NewDataBrowserHitTestUPP(DataBrowserHitTestProc
);
2401 callbacks
.u
.v1
.drawItemCallback
= gDataBrowserDrawItemUPP
;
2402 callbacks
.u
.v1
.hitTestCallback
= gDataBrowserHitTestUPP
;
2404 SetDataBrowserCustomCallbacks( GetControlRef(), &callbacks
);
2406 if ( style
& wxLC_LIST
)
2408 InsertColumn(0, kDataBrowserIconAndTextType
, wxEmptyString
, -1, -1);
2409 verify_noerr( AutoSizeColumns() );
2412 if ( style
& wxLC_LIST
|| style
& wxLC_NO_HEADER
)
2413 verify_noerr( SetHeaderButtonHeight( 0 ) );
2416 SetSortProperty( kMinColumnId
- 1 );
2418 SetSortProperty( kMinColumnId
);
2420 m_sortOrder
= SortOrder_None
;
2422 if ( style
& wxLC_SORT_DESCENDING
)
2424 SetSortOrder( kDataBrowserOrderDecreasing
);
2426 else if ( style
& wxLC_SORT_ASCENDING
)
2428 SetSortOrder( kDataBrowserOrderIncreasing
);
2431 if ( style
& wxLC_VRULES
)
2433 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4
2434 verify_noerr( DataBrowserChangeAttributes(m_controlRef
, kDataBrowserAttributeListViewDrawColumnDividers
, kDataBrowserAttributeNone
) );
2438 verify_noerr( SetHiliteStyle(kDataBrowserTableViewFillHilite
) );
2439 verify_noerr( SetHasScrollBars( (style
& wxHSCROLL
) != 0 , true ) );
2442 pascal Boolean
wxMacDataBrowserListCtrlControl::DataBrowserEditTextProc(
2444 DataBrowserItemID itemID
,
2445 DataBrowserPropertyID property
,
2446 CFStringRef theString
,
2447 Rect
*maxEditTextRect
,
2448 Boolean
*shrinkToFit
)
2450 Boolean result
= false;
2451 wxMacDataBrowserListCtrlControl
* ctl
= wxDynamicCast(wxMacControl::GetReferenceFromNativeControl( browser
), wxMacDataBrowserListCtrlControl
);
2454 result
= ctl
->ConfirmEditText(itemID
, property
, theString
, maxEditTextRect
, shrinkToFit
);
2455 theString
= CFSTR("Hello!");
2460 bool wxMacDataBrowserListCtrlControl::ConfirmEditText(
2461 DataBrowserItemID itemID
,
2462 DataBrowserPropertyID property
,
2463 CFStringRef theString
,
2464 Rect
*maxEditTextRect
,
2465 Boolean
*shrinkToFit
)
2470 pascal void wxMacDataBrowserListCtrlControl::DataBrowserDrawItemProc(
2472 DataBrowserItemID itemID
,
2473 DataBrowserPropertyID property
,
2474 DataBrowserItemState itemState
,
2475 const Rect
*itemRect
,
2477 Boolean colorDevice
)
2479 wxMacDataBrowserListCtrlControl
* ctl
= wxDynamicCast(wxMacControl::GetReferenceFromNativeControl( browser
), wxMacDataBrowserListCtrlControl
);
2482 ctl
->DrawItem(itemID
, property
, itemState
, itemRect
, gdDepth
, colorDevice
);
2486 // routines needed for DrawItem
2491 kTextBoxHeight
= 14,
2492 kIconTextSpacingV
= 2,
2494 kContentHeight
= kIconHeight
+ kTextBoxHeight
+ kIconTextSpacingV
2497 static void calculateCGDrawingBounds(CGRect inItemRect
, CGRect
*outIconRect
, CGRect
*outTextRect
, bool hasIcon
= false)
2500 float iconH
, iconW
= 0;
2501 float padding
= kItemPadding
;
2504 iconH
= kIconHeight
;
2506 padding
= padding
*2;
2509 textBottom
= inItemRect
.origin
.y
;
2511 *outIconRect
= CGRectMake(inItemRect
.origin
.x
+ kItemPadding
,
2512 textBottom
+ kIconTextSpacingV
, kIconWidth
,
2515 *outTextRect
= CGRectMake(inItemRect
.origin
.x
+ padding
+ iconW
,
2516 textBottom
+ kIconTextSpacingV
, inItemRect
.size
.width
- padding
- iconW
,
2517 inItemRect
.size
.height
- kIconTextSpacingV
);
2520 void wxMacDataBrowserListCtrlControl::DrawItem(
2521 DataBrowserItemID itemID
,
2522 DataBrowserPropertyID property
,
2523 DataBrowserItemState itemState
,
2524 const Rect
*itemRect
,
2526 Boolean colorDevice
)
2529 wxFont font
= wxNullFont
;
2531 short listColumn
= property
- kMinColumnId
;
2533 wxListCtrl
* list
= wxDynamicCast( GetPeer() , wxListCtrl
);
2534 wxMacListCtrlItem
* lcItem
;
2535 wxColour color
= *wxBLACK
;
2536 wxColour bgColor
= wxNullColour
;
2538 if (listColumn
>= 0)
2542 lcItem
= (wxMacListCtrlItem
*) itemID
;
2543 if (lcItem
->HasColumnInfo(listColumn
)){
2544 wxListItem
* item
= lcItem
->GetColumnInfo(listColumn
);
2546 // we always use the 0 column to get font and text/background colors.
2547 if (lcItem
->HasColumnInfo(0))
2549 wxListItem
* firstItem
= lcItem
->GetColumnInfo(0);
2550 color
= firstItem
->GetTextColour();
2551 bgColor
= firstItem
->GetBackgroundColour();
2552 font
= firstItem
->GetFont();
2555 if (item
->GetMask() & wxLIST_MASK_TEXT
)
2556 text
= item
->GetText();
2557 if (item
->GetMask() & wxLIST_MASK_IMAGE
)
2558 imgIndex
= item
->GetImage();
2564 text
= list
->OnGetItemText( (long)itemID
-1, listColumn
);
2565 imgIndex
= list
->OnGetItemColumnImage( (long)itemID
-1, listColumn
);
2566 wxListItemAttr
* attrs
= list
->OnGetItemAttr( (long)itemID
-1 );
2569 if (attrs
->HasBackgroundColour())
2570 bgColor
= attrs
->GetBackgroundColour();
2571 if (attrs
->HasTextColour())
2572 color
= attrs
->GetTextColour();
2573 if (attrs
->HasFont())
2574 font
= attrs
->GetFont();
2579 wxColour listBgColor
= list
->GetBackgroundColour();
2580 if (bgColor
== wxNullColour
)
2581 bgColor
= listBgColor
;
2583 wxFont listFont
= list
->GetFont();
2584 if (font
== wxNullFont
)
2587 wxMacCFStringHolder cfString
;
2588 cfString
.Assign( text
, wxLocale::GetSystemEncoding() );
2591 CGRect enclosingCGRect
, iconCGRect
, textCGRect
;
2593 ThemeDrawingState savedState
= NULL
;
2594 CGContextRef context
= (CGContextRef
)list
->MacGetDrawingContext();
2595 RGBColor labelColor
;
2597 labelColor
.green
= 0;
2598 labelColor
.blue
= 0;
2600 RGBColor backgroundColor
;
2601 backgroundColor
.red
= 255;
2602 backgroundColor
.green
= 255;
2603 backgroundColor
.blue
= 255;
2605 GetDataBrowserItemPartBounds(GetControlRef(), itemID
, property
, kDataBrowserPropertyEnclosingPart
,
2608 enclosingCGRect
= CGRectMake(enclosingRect
.left
,
2610 enclosingRect
.right
- enclosingRect
.left
,
2611 enclosingRect
.bottom
- enclosingRect
.top
);
2613 active
= IsControlActive(GetControlRef());
2615 // don't paint the background over the vertical rule line
2616 if ( list
->GetWindowStyleFlag() & wxLC_VRULES
)
2618 enclosingCGRect
.origin
.x
+= 1;
2619 enclosingCGRect
.size
.width
-= 1;
2621 if (itemState
== kDataBrowserItemIsSelected
)
2624 GetThemeDrawingState(&savedState
);
2626 GetThemeBrushAsColor(kThemeBrushAlternatePrimaryHighlightColor
, 32, true, &backgroundColor
);
2627 GetThemeTextColor(kThemeTextColorWhite
, gdDepth
, colorDevice
, &labelColor
);
2629 CGContextSaveGState(context
);
2631 CGContextSetRGBFillColor(context
, (float)backgroundColor
.red
/ (float)USHRT_MAX
,
2632 (float)backgroundColor
.green
/ (float)USHRT_MAX
,
2633 (float)backgroundColor
.blue
/ (float)USHRT_MAX
, 1.0);
2634 CGContextFillRect(context
, enclosingCGRect
);
2636 CGContextRestoreGState(context
);
2642 labelColor
= MAC_WXCOLORREF( color
.GetPixel() );
2643 else if (list
->GetTextColour().Ok())
2644 labelColor
= MAC_WXCOLORREF( list
->GetTextColour().GetPixel() );
2648 backgroundColor
= MAC_WXCOLORREF( bgColor
.GetPixel() );
2649 CGContextSaveGState(context
);
2651 CGContextSetRGBFillColor(context
, (float)backgroundColor
.red
/ (float)USHRT_MAX
,
2652 (float)backgroundColor
.green
/ (float)USHRT_MAX
,
2653 (float)backgroundColor
.blue
/ (float)USHRT_MAX
, 1.0);
2654 CGContextFillRect(context
, enclosingCGRect
);
2656 CGContextRestoreGState(context
);
2660 calculateCGDrawingBounds(enclosingCGRect
, &iconCGRect
, &textCGRect
, (imgIndex
!= -1) );
2664 wxImageList
* imageList
= list
->GetImageList(wxIMAGE_LIST_SMALL
);
2665 if (imageList
&& imageList
->GetImageCount() > 0){
2666 wxBitmap bmp
= imageList
->GetBitmap(imgIndex
);
2667 IconRef icon
= bmp
.GetBitmapData()->GetIconRef();
2669 CGContextSaveGState(context
);
2670 CGContextTranslateCTM(context
, 0,iconCGRect
.origin
.y
+ CGRectGetMaxY(iconCGRect
));
2671 CGContextScaleCTM(context
,1.0f
,-1.0f
);
2672 PlotIconRefInContext(context
, &iconCGRect
, kAlignNone
,
2673 active
? kTransformNone
: kTransformDisabled
, NULL
,
2674 kPlotIconRefNormalFlags
, icon
);
2676 CGContextRestoreGState(context
);
2680 HIThemeTextHorizontalFlush hFlush
= kHIThemeTextHorizontalFlushLeft
;
2681 UInt16 fontID
= kThemeViewsFont
;
2685 if (font
.GetFamily() != wxFONTFAMILY_DEFAULT
)
2686 fontID
= font
.MacGetThemeFontID();
2688 // FIXME: replace these with CG or ATSUI calls so we can remove this #ifndef.
2690 ::TextSize( (short)(font
.MacGetFontSize()) ) ;
2691 ::TextFace( font
.MacGetFontStyle() ) ;
2696 list
->GetColumn(listColumn
, item
);
2697 if (item
.GetMask() & wxLIST_MASK_FORMAT
)
2699 if (item
.GetAlign() == wxLIST_FORMAT_LEFT
)
2700 hFlush
= kHIThemeTextHorizontalFlushLeft
;
2701 else if (item
.GetAlign() == wxLIST_FORMAT_CENTER
)
2702 hFlush
= kHIThemeTextHorizontalFlushCenter
;
2703 else if (item
.GetAlign() == wxLIST_FORMAT_RIGHT
)
2705 hFlush
= kHIThemeTextHorizontalFlushRight
;
2706 textCGRect
.origin
.x
-= kItemPadding
; // give a little extra paddding
2710 HIThemeTextInfo info
;
2711 info
.version
= kHIThemeTextInfoVersionZero
;
2712 info
.state
= active
? kThemeStateActive
: kThemeStateInactive
;
2713 info
.fontID
= fontID
;
2714 info
.horizontalFlushness
= hFlush
;
2715 info
.verticalFlushness
= kHIThemeTextVerticalFlushCenter
;
2716 info
.options
= kHIThemeTextBoxOptionNone
;
2717 info
.truncationPosition
= kHIThemeTextTruncationEnd
;
2718 info
.truncationMaxLines
= 1;
2720 CGContextSaveGState(context
);
2721 CGContextSetRGBFillColor (context
, (float)labelColor
.red
/ (float)USHRT_MAX
,
2722 (float)labelColor
.green
/ (float)USHRT_MAX
,
2723 (float)labelColor
.blue
/ (float)USHRT_MAX
, 1.0);
2725 HIThemeDrawTextBox(cfString
, &textCGRect
, &info
, context
, kHIThemeOrientationNormal
);
2727 CGContextRestoreGState(context
);
2729 if (savedState
!= NULL
)
2730 SetThemeDrawingState(savedState
, true);
2733 OSStatus
wxMacDataBrowserListCtrlControl::GetSetItemData(DataBrowserItemID itemID
,
2734 DataBrowserPropertyID property
,
2735 DataBrowserItemDataRef itemData
,
2736 Boolean changeValue
)
2740 short listColumn
= property
- kMinColumnId
;
2742 OSStatus err
= errDataBrowserPropertyNotSupported
;
2743 wxListCtrl
* list
= wxDynamicCast( GetPeer() , wxListCtrl
);
2744 wxMacListCtrlItem
* lcItem
;
2746 if (listColumn
>= 0)
2750 lcItem
= (wxMacListCtrlItem
*) itemID
;
2751 if (lcItem
&& lcItem
->HasColumnInfo(listColumn
)){
2752 wxListItem
* item
= lcItem
->GetColumnInfo(listColumn
);
2753 if (item
->GetMask() & wxLIST_MASK_TEXT
)
2754 text
= item
->GetText();
2755 if (item
->GetMask() & wxLIST_MASK_IMAGE
)
2756 imgIndex
= item
->GetImage();
2761 text
= list
->OnGetItemText( (long)itemID
-1, listColumn
);
2762 imgIndex
= list
->OnGetItemColumnImage( (long)itemID
-1, listColumn
);
2770 case kDataBrowserItemIsEditableProperty
:
2771 if ( list
&& list
->HasFlag( wxLC_EDIT_LABELS
) )
2773 verify_noerr(SetDataBrowserItemDataBooleanValue( itemData
, true ));
2778 if ( property
>= kMinColumnId
)
2780 wxMacCFStringHolder cfStr
;
2783 cfStr
.Assign( text
, wxLocale::GetSystemEncoding() );
2784 err
= ::SetDataBrowserItemDataText( itemData
, cfStr
);
2790 if ( imgIndex
!= -1 )
2792 wxImageList
* imageList
= list
->GetImageList(wxIMAGE_LIST_SMALL
);
2793 if (imageList
&& imageList
->GetImageCount() > 0){
2794 wxBitmap bmp
= imageList
->GetBitmap(imgIndex
);
2795 IconRef icon
= bmp
.GetBitmapData()->GetIconRef();
2796 ::SetDataBrowserItemDataIcon(itemData
, icon
);
2810 if ( property
>= kMinColumnId
)
2812 short listColumn
= property
- kMinColumnId
;
2814 // TODO probably send the 'end edit' from here, as we
2815 // can then deal with the veto
2817 verify_noerr( GetDataBrowserItemDataText( itemData
, &sr
) ) ;
2818 wxMacCFStringHolder
cfStr(sr
) ;;
2820 list
->SetItem( (long)itemData
-1 , listColumn
, cfStr
.AsString() ) ;
2824 lcItem
->SetColumnTextValue( listColumn
, cfStr
.AsString() );
2834 void wxMacDataBrowserListCtrlControl::ItemNotification(DataBrowserItemID itemID
,
2835 DataBrowserItemNotification message
,
2836 DataBrowserItemDataRef itemData
)
2838 // we want to depend on as little as possible to make sure tear-down of controls is safe
2839 if ( message
== kDataBrowserItemRemoved
)
2841 // make sure MacDelete does the proper teardown.
2844 else if ( message
== kDataBrowserItemAdded
)
2846 // we don't issue events on adding, the item is not really stored in the list yet, so we
2847 // avoid asserts by getting out now
2851 wxListCtrl
*list
= wxDynamicCast( GetPeer() , wxListCtrl
);
2854 bool trigger
= false;
2856 wxListEvent
event( wxEVT_COMMAND_LIST_ITEM_SELECTED
, list
->GetId() );
2857 bool isSingle
= (list
->GetWindowStyle() & wxLC_SINGLE_SEL
) != 0;
2859 event
.SetEventObject( list
);
2860 if ( !list
->IsVirtual() )
2862 DataBrowserTableViewRowIndex result
= 0;
2863 verify_noerr( GetItemRow( itemID
, &result
) ) ;
2864 event
.m_itemIndex
= result
;
2866 if (event
.m_itemIndex
>= 0)
2867 MacGetColumnInfo(event
.m_itemIndex
,0,event
.m_item
);
2871 event
.m_itemIndex
= (long)itemID
-1;
2876 case kDataBrowserItemDeselected
:
2877 event
.SetEventType(wxEVT_COMMAND_LIST_ITEM_DESELECTED
);
2879 trigger
= !IsSelectionSuppressed();
2882 case kDataBrowserItemSelected
:
2883 trigger
= !IsSelectionSuppressed();
2887 case kDataBrowserItemDoubleClicked
:
2888 event
.SetEventType( wxEVT_COMMAND_LIST_ITEM_ACTIVATED
);
2892 case kDataBrowserEditStarted
:
2893 // TODO : how to veto ?
2894 event
.SetEventType( wxEVT_COMMAND_LIST_BEGIN_LABEL_EDIT
) ;
2898 case kDataBrowserEditStopped
:
2899 // TODO probably trigger only upon the value store callback, because
2900 // here IIRC we cannot veto
2901 event
.SetEventType( wxEVT_COMMAND_LIST_END_LABEL_EDIT
) ;
2911 // direct notification is not always having the listbox GetSelection() having in synch with event
2912 wxPostEvent( list
->GetEventHandler(), event
);
2917 Boolean
wxMacDataBrowserListCtrlControl::CompareItems(DataBrowserItemID itemOneID
,
2918 DataBrowserItemID itemTwoID
,
2919 DataBrowserPropertyID sortProperty
)
2922 bool retval
= false;
2924 wxString otherItemText
;
2926 long otherItemOrder
;
2928 int colId
= sortProperty
- kMinColumnId
;
2930 wxListCtrl
* list
= wxDynamicCast( GetPeer() , wxListCtrl
);
2932 DataBrowserSortOrder sort
;
2933 verify_noerr(GetSortOrder(&sort
));
2939 wxMacListCtrlItem
* item
= (wxMacListCtrlItem
*)itemOneID
;
2940 wxMacListCtrlItem
* otherItem
= (wxMacListCtrlItem
*)itemTwoID
;
2942 itemOrder
= item
->GetOrder();
2943 otherItemOrder
= item
->GetOrder();
2945 wxListCtrlCompare func
= list
->GetCompareFunc();
2950 if (item
&& item
->HasColumnInfo(0))
2951 item1
= item
->GetColumnInfo(0)->GetData();
2952 if (otherItem
&& otherItem
->HasColumnInfo(0))
2953 item2
= otherItem
->GetColumnInfo(0)->GetData();
2955 if (item1
> -1 && item2
> -1)
2957 int result
= func(item1
, item2
, list
->GetCompareFuncData());
2958 if (sort
== kDataBrowserOrderIncreasing
)
2965 // we can't use the native control's sorting abilities, so just
2967 return itemOrder
< otherItemOrder
;
2972 long itemNum
= (long)itemOneID
;
2973 long otherItemNum
= (long)itemTwoID
;
2974 itemText
= list
->OnGetItemText( itemNum
-1, colId
);
2975 otherItemText
= list
->OnGetItemText( otherItemNum
-1, colId
);
2977 // virtual listctrls don't support sorting
2978 return itemNum
< otherItemNum
;
2982 // fallback for undefined cases
2983 retval
= itemOneID
< itemTwoID
;
2989 wxMacDataBrowserListCtrlControl::~wxMacDataBrowserListCtrlControl()
2993 void wxMacDataBrowserListCtrlControl::MacSetColumnInfo( unsigned int row
, unsigned int column
, wxListItem
* item
)
2995 wxMacDataItem
* dataItem
= GetItemFromLine(row
);
2996 wxASSERT_MSG( dataItem
, _T("could not obtain wxMacDataItem for row in MacSetColumnInfo. Is row a valid wxListCtrl row?") );
2999 wxMacListCtrlItem
* listItem
= wx_static_cast(wxMacListCtrlItem
*,dataItem
);
3000 bool hasInfo
= listItem
->HasColumnInfo( column
);
3001 listItem
->SetColumnInfo( column
, item
);
3002 listItem
->SetOrder(row
);
3003 UpdateState(dataItem
, item
);
3005 wxListCtrl
* list
= wxDynamicCast( GetPeer() , wxListCtrl
);
3007 // NB: When this call was made before a control was completely shown, it would
3008 // update the item prematurely (i.e. no text would be listed) and, on show,
3009 // only the sorted column would be refreshed, meaning only first column text labels
3010 // would be shown. Making sure not to update items until the control is visible
3011 // seems to fix this issue.
3012 if (hasInfo
&& list
->IsShown())
3013 UpdateItem( wxMacDataBrowserRootContainer
, listItem
, kMinColumnId
+ column
);
3017 // apply changes that need to happen immediately, rather than when the
3018 // databrowser control fires a callback.
3019 void wxMacDataBrowserListCtrlControl::UpdateState(wxMacDataItem
* dataItem
, wxListItem
* listItem
)
3021 bool isSelected
= IsItemSelected( dataItem
);
3022 bool isSelectedState
= (listItem
->GetState() == wxLIST_STATE_SELECTED
);
3024 // toggle the selection state if wxListInfo state and actual state don't match.
3025 if ( isSelected
!= isSelectedState
)
3027 DataBrowserSetOption options
= kDataBrowserItemsAdd
;
3028 if (!isSelectedState
)
3029 options
= kDataBrowserItemsRemove
;
3030 SetSelectedItem(dataItem
, options
);
3032 // TODO: Set column width if item width > than current column width
3035 void wxMacDataBrowserListCtrlControl::MacGetColumnInfo( unsigned int row
, unsigned int column
, wxListItem
& item
)
3037 wxMacDataItem
* dataItem
= GetItemFromLine(row
);
3038 wxASSERT_MSG( dataItem
, _T("could not obtain wxMacDataItem in MacGetColumnInfo. Is row a valid wxListCtrl row?") );
3039 // CS should this guard against dataItem = 0 ? , as item is not a pointer if (item) is not appropriate
3042 wxMacListCtrlItem
* listItem
=wx_static_cast(wxMacListCtrlItem
*,dataItem
);
3044 if (!listItem
->HasColumnInfo( column
))
3047 wxListItem
* oldItem
= listItem
->GetColumnInfo( column
);
3051 long mask
= item
.GetMask();
3053 // by default, get everything for backwards compatibility
3056 if ( mask
& wxLIST_MASK_TEXT
)
3057 item
.SetText(oldItem
->GetText());
3058 if ( mask
& wxLIST_MASK_IMAGE
)
3059 item
.SetImage(oldItem
->GetImage());
3060 if ( mask
& wxLIST_MASK_DATA
)
3061 item
.SetData(oldItem
->GetData());
3062 if ( mask
& wxLIST_MASK_STATE
)
3063 item
.SetState(oldItem
->GetState());
3064 if ( mask
& wxLIST_MASK_WIDTH
)
3065 item
.SetWidth(oldItem
->GetWidth());
3066 if ( mask
& wxLIST_MASK_FORMAT
)
3067 item
.SetAlign(oldItem
->GetAlign());
3069 item
.SetTextColour(oldItem
->GetTextColour());
3070 item
.SetBackgroundColour(oldItem
->GetBackgroundColour());
3071 item
.SetFont(oldItem
->GetFont());
3076 void wxMacDataBrowserListCtrlControl::MacInsertItem( unsigned int n
, wxListItem
* item
)
3078 wxMacDataItemBrowserControl::MacInsert(n
, item
->GetText());
3079 MacSetColumnInfo(n
, 0, item
);
3082 wxMacDataItem
* wxMacDataBrowserListCtrlControl::CreateItem()
3084 return new wxMacListCtrlItem();
3087 wxMacListCtrlItem::wxMacListCtrlItem()
3089 m_rowItems
= wxListItemList();
3092 int wxMacListCtrlItem::GetColumnImageValue( unsigned int column
)
3094 if ( HasColumnInfo(column
) )
3095 return GetColumnInfo(column
)->GetImage();
3100 void wxMacListCtrlItem::SetColumnImageValue( unsigned int column
, int imageIndex
)
3102 if ( HasColumnInfo(column
) )
3103 GetColumnInfo(column
)->SetImage(imageIndex
);
3106 wxString
wxMacListCtrlItem::GetColumnTextValue( unsigned int column
)
3111 if ( HasColumnInfo(column
) )
3112 return GetColumnInfo(column
)->GetText();
3114 return wxEmptyString
;
3117 void wxMacListCtrlItem::SetColumnTextValue( unsigned int column
, const wxString
& text
)
3119 if ( HasColumnInfo(column
) )
3120 GetColumnInfo(column
)->SetText(text
);
3122 // for compatibility with superclass APIs
3127 wxListItem
* wxMacListCtrlItem::GetColumnInfo( unsigned int column
)
3129 wxASSERT_MSG( HasColumnInfo(column
), _T("invalid column index in wxMacListCtrlItem") );
3130 return m_rowItems
[column
];
3133 bool wxMacListCtrlItem::HasColumnInfo( unsigned int column
)
3135 return !(m_rowItems
.find( column
) == m_rowItems
.end());
3138 void wxMacListCtrlItem::SetColumnInfo( unsigned int column
, wxListItem
* item
)
3141 if ( !HasColumnInfo(column
) )
3143 wxListItem
* listItem
= new wxListItem(*item
);
3144 m_rowItems
[column
] = listItem
;
3148 wxListItem
* listItem
= GetColumnInfo( column
);
3149 long mask
= item
->GetMask();
3150 if (mask
& wxLIST_MASK_TEXT
)
3151 listItem
->SetText(item
->GetText());
3152 if (mask
& wxLIST_MASK_DATA
)
3153 listItem
->SetData(item
->GetData());
3154 if (mask
& wxLIST_MASK_IMAGE
)
3155 listItem
->SetImage(item
->GetImage());
3156 if (mask
& wxLIST_MASK_STATE
)
3157 listItem
->SetState(item
->GetState());
3158 if (mask
& wxLIST_MASK_FORMAT
)
3159 listItem
->SetAlign(item
->GetAlign());
3160 if (mask
& wxLIST_MASK_WIDTH
)
3161 listItem
->SetWidth(item
->GetWidth());
3163 if ( item
->HasAttributes() )
3165 if ( listItem
->HasAttributes() )
3166 listItem
->GetAttributes()->AssignFrom(*item
->GetAttributes());
3169 listItem
->SetTextColour(item
->GetTextColour());
3170 listItem
->SetBackgroundColour(item
->GetBackgroundColour());
3171 listItem
->SetFont(item
->GetFont());
3177 #endif // wxUSE_LISTCTRL