1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/mac/listctrl_mac.cpp
4 // Author: Julian Smart
5 // Modified by: Agron Selimaj
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 // ============================================================================
14 // ============================================================================
16 // ----------------------------------------------------------------------------
18 // ----------------------------------------------------------------------------
20 // For compilers that support precompilation, includes "wx.h".
21 #include "wx/wxprec.h"
29 #include "wx/listctrl.h"
35 #include "wx/mac/uma.h"
37 #include "wx/imaglist.h"
38 #include "wx/sysopt.h"
41 #include "wx/hashmap.h"
43 #if wxUSE_EXTENDED_RTTI
44 WX_DEFINE_FLAGS( wxListCtrlStyle
)
46 wxBEGIN_FLAGS( wxListCtrlStyle
)
47 // new style border flags, we put them first to
48 // use them for streaming out
49 wxFLAGS_MEMBER(wxBORDER_SIMPLE
)
50 wxFLAGS_MEMBER(wxBORDER_SUNKEN
)
51 wxFLAGS_MEMBER(wxBORDER_DOUBLE
)
52 wxFLAGS_MEMBER(wxBORDER_RAISED
)
53 wxFLAGS_MEMBER(wxBORDER_STATIC
)
54 wxFLAGS_MEMBER(wxBORDER_NONE
)
56 // old style border flags
57 wxFLAGS_MEMBER(wxSIMPLE_BORDER
)
58 wxFLAGS_MEMBER(wxSUNKEN_BORDER
)
59 wxFLAGS_MEMBER(wxDOUBLE_BORDER
)
60 wxFLAGS_MEMBER(wxRAISED_BORDER
)
61 wxFLAGS_MEMBER(wxSTATIC_BORDER
)
62 wxFLAGS_MEMBER(wxBORDER
)
64 // standard window styles
65 wxFLAGS_MEMBER(wxTAB_TRAVERSAL
)
66 wxFLAGS_MEMBER(wxCLIP_CHILDREN
)
67 wxFLAGS_MEMBER(wxTRANSPARENT_WINDOW
)
68 wxFLAGS_MEMBER(wxWANTS_CHARS
)
69 wxFLAGS_MEMBER(wxFULL_REPAINT_ON_RESIZE
)
70 wxFLAGS_MEMBER(wxALWAYS_SHOW_SB
)
71 wxFLAGS_MEMBER(wxVSCROLL
)
72 wxFLAGS_MEMBER(wxHSCROLL
)
74 wxFLAGS_MEMBER(wxLC_LIST
)
75 wxFLAGS_MEMBER(wxLC_REPORT
)
76 wxFLAGS_MEMBER(wxLC_ICON
)
77 wxFLAGS_MEMBER(wxLC_SMALL_ICON
)
78 wxFLAGS_MEMBER(wxLC_ALIGN_TOP
)
79 wxFLAGS_MEMBER(wxLC_ALIGN_LEFT
)
80 wxFLAGS_MEMBER(wxLC_AUTOARRANGE
)
81 wxFLAGS_MEMBER(wxLC_USER_TEXT
)
82 wxFLAGS_MEMBER(wxLC_EDIT_LABELS
)
83 wxFLAGS_MEMBER(wxLC_NO_HEADER
)
84 wxFLAGS_MEMBER(wxLC_SINGLE_SEL
)
85 wxFLAGS_MEMBER(wxLC_SORT_ASCENDING
)
86 wxFLAGS_MEMBER(wxLC_SORT_DESCENDING
)
87 wxFLAGS_MEMBER(wxLC_VIRTUAL
)
89 wxEND_FLAGS( wxListCtrlStyle
)
91 IMPLEMENT_DYNAMIC_CLASS_XTI(wxListCtrl
, wxControl
,"wx/listctrl.h")
93 wxBEGIN_PROPERTIES_TABLE(wxListCtrl
)
94 wxEVENT_PROPERTY( TextUpdated
, wxEVT_COMMAND_TEXT_UPDATED
, wxCommandEvent
)
96 wxPROPERTY_FLAGS( WindowStyle
, wxListCtrlStyle
, long , SetWindowStyleFlag
, GetWindowStyleFlag
, EMPTY_MACROVALUE
, 0 /*flags*/ , wxT("Helpstring") , wxT("group")) // style
97 wxEND_PROPERTIES_TABLE()
99 wxBEGIN_HANDLERS_TABLE(wxListCtrl
)
100 wxEND_HANDLERS_TABLE()
102 wxCONSTRUCTOR_5( wxListCtrl
, wxWindow
* , Parent
, wxWindowID
, Id
, wxPoint
, Position
, wxSize
, Size
, long , WindowStyle
)
105 TODO : Expose more information of a list's layout etc. via appropriate objects (à la NotebookPageInfo)
108 IMPLEMENT_DYNAMIC_CLASS(wxListCtrl
, wxControl
)
111 IMPLEMENT_DYNAMIC_CLASS(wxListView
, wxListCtrl
)
112 IMPLEMENT_DYNAMIC_CLASS(wxListItem
, wxObject
)
114 IMPLEMENT_DYNAMIC_CLASS(wxListEvent
, wxNotifyEvent
)
116 WX_DECLARE_HASH_MAP( int, wxListItem
*, wxIntegerHash
, wxIntegerEqual
, wxListItemList
);
118 #include "wx/listimpl.cpp"
119 WX_DEFINE_LIST(wxColumnList
)
121 // so we can check for column clicks
122 static const EventTypeSpec eventList
[] =
124 { kEventClassControl
, kEventControlHit
},
125 { kEventClassControl
, kEventControlDraw
}
128 static pascal OSStatus
wxMacListCtrlEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
130 OSStatus result
= eventNotHandledErr
;
132 wxMacCarbonEvent
cEvent( event
) ;
134 ControlRef controlRef
;
135 cEvent
.GetParameter( kEventParamDirectObject
, &controlRef
) ;
137 wxListCtrl
*window
= (wxListCtrl
*) data
;
138 wxListEvent
le( wxEVT_COMMAND_LIST_COL_CLICK
, window
->GetId() );
139 le
.SetEventObject( window
);
141 switch ( GetEventKind( event
) )
143 // check if the column was clicked on and fire an event if so
144 case kEventControlHit
:
146 ControlPartCode result
= cEvent
.GetParameter
<ControlPartCode
>(kEventParamControlPart
, typeControlPartCode
) ;
147 if (result
== kControlButtonPart
){
148 DataBrowserPropertyID col
;
149 GetDataBrowserSortProperty(controlRef
, &col
);
150 int column
= col
- kMinColumnId
;
152 // FIXME: we can't use the sort property for virtual listctrls
153 // so we need to find a better way to determine which column was clicked...
154 if (!window
->IsVirtual())
155 window
->GetEventHandler()->ProcessEvent( le
);
157 result
= CallNextEventHandler(handler
, event
);
160 case kEventControlDraw
:
162 CGContextRef context
= cEvent
.GetParameter
<CGContextRef
>(kEventParamCGContextRef
, typeCGContextRef
) ;
163 window
->MacSetDrawingContext(context
);
164 result
= CallNextEventHandler(handler
, event
);
165 window
->MacSetDrawingContext(NULL
);
176 DEFINE_ONE_SHOT_HANDLER_GETTER( wxMacListCtrlEventHandler
)
178 class wxMacListCtrlItem
: public wxMacListBoxItem
183 virtual void Notification(wxMacDataItemBrowserControl
*owner
,
184 DataBrowserItemNotification message
,
185 DataBrowserItemDataRef itemData
) const;
187 virtual void SetColumnInfo( unsigned int column
, wxListItem
* item
);
188 virtual wxListItem
* GetColumnInfo( unsigned int column
);
189 virtual bool HasColumnInfo( unsigned int column
);
191 virtual void SetColumnTextValue( unsigned int column
, const wxString
& text
);
192 virtual wxString
GetColumnTextValue( unsigned int column
);
194 virtual int GetColumnImageValue( unsigned int column
);
195 virtual void SetColumnImageValue( unsigned int column
, int imageIndex
);
197 virtual ~wxMacListCtrlItem();
199 wxListItemList m_rowItems
;
202 DataBrowserDrawItemUPP gDataBrowserDrawItemUPP
= NULL
;
203 //DataBrowserEditItemUPP gDataBrowserEditItemUPP = NULL;
204 DataBrowserHitTestUPP gDataBrowserHitTestUPP
= NULL
;
206 // TODO: Make a better name!!
207 class wxMacDataBrowserListCtrlControl
: public wxMacDataItemBrowserControl
210 wxMacDataBrowserListCtrlControl( wxWindow
*peer
, const wxPoint
& pos
, const wxSize
& size
, long style
);
211 wxMacDataBrowserListCtrlControl() {}
212 virtual ~wxMacDataBrowserListCtrlControl();
214 // create a list item (can be a subclass of wxMacListBoxItem)
216 virtual wxMacDataItem
* CreateItem();
218 virtual void MacInsertItem( unsigned int n
, wxListItem
* item
);
219 virtual void MacSetColumnInfo( unsigned int row
, unsigned int column
, wxListItem
* item
);
220 virtual void MacGetColumnInfo( unsigned int row
, unsigned int column
, wxListItem
& item
);
221 virtual void UpdateState(wxMacDataItem
* dataItem
, wxListItem
* item
);
222 int GetFlags() { return m_flags
; }
225 // we need to override to provide specialized handling for virtual wxListCtrls
226 virtual OSStatus
GetSetItemData(DataBrowserItemID itemID
,
227 DataBrowserPropertyID property
,
228 DataBrowserItemDataRef itemData
,
229 Boolean changeValue
);
231 virtual void ItemNotification(
232 DataBrowserItemID itemID
,
233 DataBrowserItemNotification message
,
234 DataBrowserItemDataRef itemData
);
236 virtual Boolean
CompareItems(DataBrowserItemID itemOneID
,
237 DataBrowserItemID itemTwoID
,
238 DataBrowserPropertyID sortProperty
);
240 static pascal void DataBrowserDrawItemProc(ControlRef browser
,
241 DataBrowserItemID item
,
242 DataBrowserPropertyID property
,
243 DataBrowserItemState itemState
,
246 Boolean colorDevice
);
248 virtual void DrawItem(DataBrowserItemID itemID
,
249 DataBrowserPropertyID property
,
250 DataBrowserItemState itemState
,
251 const Rect
*itemRect
,
253 Boolean colorDevice
);
255 static pascal Boolean
DataBrowserEditTextProc(ControlRef browser
,
256 DataBrowserItemID item
,
257 DataBrowserPropertyID property
,
258 CFStringRef theString
,
259 Rect
*maxEditTextRect
,
260 Boolean
*shrinkToFit
);
262 static pascal Boolean
DataBrowserHitTestProc(ControlRef browser
,
263 DataBrowserItemID itemID
,
264 DataBrowserPropertyID property
,
266 const Rect
*mouseRect
) { return true; }
268 virtual bool ConfirmEditText(DataBrowserItemID item
,
269 DataBrowserPropertyID property
,
270 CFStringRef theString
,
271 Rect
*maxEditTextRect
,
272 Boolean
*shrinkToFit
);
276 wxClientDataType m_clientDataItemsType
;
279 DECLARE_DYNAMIC_CLASS_NO_COPY(wxMacDataBrowserListCtrlControl
)
282 class wxMacListCtrlEventDelegate
: public wxEvtHandler
285 wxMacListCtrlEventDelegate( wxListCtrl
* list
, int id
);
286 virtual bool ProcessEvent( wxEvent
& event
);
293 wxMacListCtrlEventDelegate::wxMacListCtrlEventDelegate( wxListCtrl
* list
, int id
)
299 bool wxMacListCtrlEventDelegate::ProcessEvent( wxEvent
& event
)
301 // even though we use a generic list ctrl underneath, make sure
302 // we present ourselves as wxListCtrl.
303 event
.SetEventObject( m_list
);
306 if ( !event
.IsKindOf( CLASSINFO( wxCommandEvent
) ) )
308 if (m_list
->GetEventHandler()->ProcessEvent( event
))
311 return wxEvtHandler::ProcessEvent(event
);
314 //-----------------------------------------------------------------------------
315 // wxListCtrlRenameTimer (internal)
316 //-----------------------------------------------------------------------------
318 class wxListCtrlRenameTimer
: public wxTimer
324 wxListCtrlRenameTimer( wxListCtrl
*owner
);
328 //-----------------------------------------------------------------------------
329 // wxListCtrlTextCtrlWrapper: wraps a wxTextCtrl to make it work for inline editing
330 //-----------------------------------------------------------------------------
332 class wxListCtrlTextCtrlWrapper
: public wxEvtHandler
335 // NB: text must be a valid object but not Create()d yet
336 wxListCtrlTextCtrlWrapper(wxListCtrl
*owner
,
340 wxTextCtrl
*GetText() const { return m_text
; }
342 void AcceptChangesAndFinish();
345 void OnChar( wxKeyEvent
&event
);
346 void OnKeyUp( wxKeyEvent
&event
);
347 void OnKillFocus( wxFocusEvent
&event
);
349 bool AcceptChanges();
355 wxString m_startValue
;
358 bool m_aboutToFinish
;
360 DECLARE_EVENT_TABLE()
363 //-----------------------------------------------------------------------------
364 // wxListCtrlRenameTimer (internal)
365 //-----------------------------------------------------------------------------
367 wxListCtrlRenameTimer::wxListCtrlRenameTimer( wxListCtrl
*owner
)
372 void wxListCtrlRenameTimer::Notify()
374 m_owner
->OnRenameTimer();
377 //-----------------------------------------------------------------------------
378 // wxListCtrlTextCtrlWrapper (internal)
379 //-----------------------------------------------------------------------------
381 BEGIN_EVENT_TABLE(wxListCtrlTextCtrlWrapper
, wxEvtHandler
)
382 EVT_CHAR (wxListCtrlTextCtrlWrapper::OnChar
)
383 EVT_KEY_UP (wxListCtrlTextCtrlWrapper::OnKeyUp
)
384 EVT_KILL_FOCUS (wxListCtrlTextCtrlWrapper::OnKillFocus
)
387 wxListCtrlTextCtrlWrapper::wxListCtrlTextCtrlWrapper(wxListCtrl
*owner
,
390 : m_startValue(owner
->GetItemText(itemEdit
)),
391 m_itemEdited(itemEdit
)
396 m_aboutToFinish
= false;
400 owner
->GetItemRect(itemEdit
, rectLabel
);
402 m_text
->Create(owner
, wxID_ANY
, m_startValue
,
403 wxPoint(rectLabel
.x
+offset
,rectLabel
.y
),
404 wxSize(rectLabel
.width
-offset
,rectLabel
.height
));
407 m_text
->PushEventHandler(this);
410 void wxListCtrlTextCtrlWrapper::Finish()
416 m_text
->RemoveEventHandler(this);
417 m_owner
->FinishEditing(m_text
);
419 wxPendingDelete
.Append( this );
423 bool wxListCtrlTextCtrlWrapper::AcceptChanges()
425 const wxString value
= m_text
->GetValue();
427 if ( value
== m_startValue
)
428 // nothing changed, always accept
431 if ( !m_owner
->OnRenameAccept(m_itemEdited
, value
) )
432 // vetoed by the user
435 // accepted, do rename the item
436 m_owner
->SetItemText(m_itemEdited
, value
);
441 void wxListCtrlTextCtrlWrapper::AcceptChangesAndFinish()
443 m_aboutToFinish
= true;
445 // Notify the owner about the changes
448 // Even if vetoed, close the control (consistent with MSW)
452 void wxListCtrlTextCtrlWrapper::OnChar( wxKeyEvent
&event
)
454 switch ( event
.m_keyCode
)
457 AcceptChangesAndFinish();
461 m_owner
->OnRenameCancelled( m_itemEdited
);
470 void wxListCtrlTextCtrlWrapper::OnKeyUp( wxKeyEvent
&event
)
478 // auto-grow the textctrl:
479 wxSize parentSize
= m_owner
->GetSize();
480 wxPoint myPos
= m_text
->GetPosition();
481 wxSize mySize
= m_text
->GetSize();
483 m_text
->GetTextExtent(m_text
->GetValue() + _T("MM"), &sx
, &sy
);
484 if (myPos
.x
+ sx
> parentSize
.x
)
485 sx
= parentSize
.x
- myPos
.x
;
488 m_text
->SetSize(sx
, wxDefaultCoord
);
493 void wxListCtrlTextCtrlWrapper::OnKillFocus( wxFocusEvent
&event
)
495 if ( !m_finished
&& !m_aboutToFinish
)
497 if ( !AcceptChanges() )
498 m_owner
->OnRenameCancelled( m_itemEdited
);
503 // We must let the native text control handle focus
507 BEGIN_EVENT_TABLE(wxListCtrl
, wxControl
)
508 EVT_LEFT_DOWN(wxListCtrl::OnLeftDown
)
509 EVT_LEFT_DCLICK(wxListCtrl::OnDblClick
)
510 EVT_MIDDLE_DOWN(wxListCtrl::OnMiddleDown
)
511 EVT_RIGHT_DOWN(wxListCtrl::OnRightDown
)
512 EVT_CHAR(wxListCtrl::OnChar
)
515 // ============================================================================
517 // ============================================================================
519 wxMacListControl
* wxListCtrl::GetPeer() const
521 wxMacDataBrowserListCtrlControl
*lb
= wxDynamicCast(m_peer
,wxMacDataBrowserListCtrlControl
);
522 return lb
? wx_static_cast(wxMacListControl
*,lb
) : 0 ;
525 // ----------------------------------------------------------------------------
526 // wxListCtrl construction
527 // ----------------------------------------------------------------------------
529 void wxListCtrl::Init()
531 m_imageListNormal
= NULL
;
532 m_imageListSmall
= NULL
;
533 m_imageListState
= NULL
;
535 // keep track of if we created our own image lists, or if they were assigned
537 m_ownsImageListNormal
= m_ownsImageListSmall
= m_ownsImageListState
= false;
541 m_genericImpl
= NULL
;
543 m_compareFunc
= NULL
;
544 m_compareFuncData
= 0;
545 m_colsInfo
= wxColumnList();
546 m_textColor
= wxNullColour
;
547 m_bgColor
= wxNullColour
;
548 m_textctrlWrapper
= NULL
;
550 m_renameTimer
= new wxListCtrlRenameTimer( this );
553 class wxGenericListCtrlHook
: public wxGenericListCtrl
556 wxGenericListCtrlHook(wxListCtrl
* parent
,
561 const wxValidator
& validator
,
562 const wxString
& name
)
563 : wxGenericListCtrl(parent
, id
, pos
, size
, style
, validator
, name
),
564 m_nativeListCtrl(parent
)
569 virtual wxListItemAttr
* OnGetItemAttr(long item
) const
571 return m_nativeListCtrl
->OnGetItemAttr(item
);
574 virtual int OnGetItemImage(long item
) const
576 return m_nativeListCtrl
->OnGetItemImage(item
);
579 virtual int OnGetItemColumnImage(long item
, long column
) const
581 return m_nativeListCtrl
->OnGetItemColumnImage(item
, column
);
584 virtual wxString
OnGetItemText(long item
, long column
) const
586 return m_nativeListCtrl
->OnGetItemText(item
, column
);
589 wxListCtrl
* m_nativeListCtrl
;
593 void wxListCtrl::OnLeftDown(wxMouseEvent
& event
)
595 if ( m_textctrlWrapper
)
598 m_textctrlWrapper
->AcceptChangesAndFinish();
602 long current
= HitTest(event
.GetPosition(), hitResult
);
603 if ((current
== m_current
) &&
604 (hitResult
== wxLIST_HITTEST_ONITEM
) &&
605 HasFlag(wxLC_EDIT_LABELS
) )
607 m_renameTimer
->Start( 100, true );
616 void wxListCtrl::OnDblClick(wxMouseEvent
& event
)
622 #if wxABI_VERSION >= 20801
623 void wxListCtrl::OnRightDown(wxMouseEvent
& event
)
626 FireMouseEvent(wxEVT_COMMAND_LIST_ITEM_RIGHT_CLICK
, event
.GetPosition());
630 void wxListCtrl::OnMiddleDown(wxMouseEvent
& event
)
633 FireMouseEvent(wxEVT_COMMAND_LIST_ITEM_MIDDLE_CLICK
, event
.GetPosition());
637 void wxListCtrl::FireMouseEvent(wxEventType eventType
, wxPoint position
)
639 wxListEvent
le( eventType
, GetId() );
640 le
.SetEventObject(this);
641 le
.m_pointDrag
= position
;
645 long item
= HitTest(position
, flags
);
646 if (flags
& wxLIST_HITTEST_ONITEM
)
648 le
.m_itemIndex
= item
;
652 le
.m_item
.m_itemId
= item
;
655 GetEventHandler()->ProcessEvent(le
);
659 void wxListCtrl::OnChar(wxKeyEvent
& event
)
663 wxListEvent
le( wxEVT_COMMAND_LIST_KEY_DOWN
, GetId() );
664 le
.SetEventObject(this);
665 le
.m_code
= event
.GetKeyCode();
670 le
.m_itemIndex
= m_current
;
673 le
.m_item
.m_itemId
= m_current
;
676 GetEventHandler()->ProcessEvent(le
);
683 bool wxListCtrl::Create(wxWindow
*parent
,
688 const wxValidator
& validator
,
689 const wxString
& name
)
692 // for now, we'll always use the generic list control for ICON and LIST views,
693 // because they dynamically change the number of columns on resize.
694 // Also, allow the user to set it to use the list ctrl as well.
695 if ( (wxSystemOptions::HasOption( wxMAC_ALWAYS_USE_GENERIC_LISTCTRL
)
696 && (wxSystemOptions::GetOptionInt( wxMAC_ALWAYS_USE_GENERIC_LISTCTRL
) == 1)) ||
697 (style
& wxLC_ICON
) || (style
& wxLC_SMALL_ICON
) || (style
& wxLC_LIST
) )
699 m_macIsUserPane
= true;
701 long paneStyle
= style
;
702 paneStyle
&= ~wxSIMPLE_BORDER
;
703 paneStyle
&= ~wxDOUBLE_BORDER
;
704 paneStyle
&= ~wxSUNKEN_BORDER
;
705 paneStyle
&= ~wxRAISED_BORDER
;
706 paneStyle
&= ~wxSTATIC_BORDER
;
707 if ( !wxWindow::Create(parent
, id
, pos
, size
, paneStyle
| wxNO_BORDER
, name
) )
710 // since the generic control is a child, make sure we position it at 0, 0
711 m_genericImpl
= new wxGenericListCtrlHook(this, id
, wxPoint(0, 0), size
, style
, validator
, name
);
712 m_genericImpl
->PushEventHandler( new wxMacListCtrlEventDelegate( this, GetId() ) );
718 m_macIsUserPane
= false;
719 if ( !wxWindow::Create(parent
, id
, pos
, size
, style
& ~(wxHSCROLL
| wxVSCROLL
), name
) )
721 m_dbImpl
= new wxMacDataBrowserListCtrlControl( this, pos
, size
, style
);
724 MacPostControlCreate( pos
, size
);
726 InstallControlEventHandler( m_peer
->GetControlRef() , GetwxMacListCtrlEventHandlerUPP(),
727 GetEventTypeCount(eventList
), eventList
, this,
728 (EventHandlerRef
*)&m_macListCtrlEventHandler
);
734 wxListCtrl::~wxListCtrl()
738 m_genericImpl
->PopEventHandler(/* deleteHandler = */ true);
741 if (m_ownsImageListNormal
)
742 delete m_imageListNormal
;
743 if (m_ownsImageListSmall
)
744 delete m_imageListSmall
;
745 if (m_ownsImageListState
)
746 delete m_imageListState
;
748 delete m_renameTimer
;
751 // ----------------------------------------------------------------------------
752 // set/get/change style
753 // ----------------------------------------------------------------------------
755 // Add or remove a single window style
756 void wxListCtrl::SetSingleStyle(long style
, bool add
)
758 long flag
= GetWindowStyleFlag();
760 // Get rid of conflicting styles
763 if ( style
& wxLC_MASK_TYPE
)
764 flag
= flag
& ~wxLC_MASK_TYPE
;
765 if ( style
& wxLC_MASK_ALIGN
)
766 flag
= flag
& ~wxLC_MASK_ALIGN
;
767 if ( style
& wxLC_MASK_SORT
)
768 flag
= flag
& ~wxLC_MASK_SORT
;
776 SetWindowStyleFlag(flag
);
779 // Set the whole window style
780 void wxListCtrl::SetWindowStyleFlag(long flag
)
782 if ( flag
!= m_windowStyle
)
784 m_windowStyle
= flag
;
788 m_genericImpl
->SetWindowStyleFlag(flag
);
795 void wxListCtrl::DoSetSize( int x
, int y
, int width
, int height
, int sizeFlags
)
797 wxControl::DoSetSize(x
, y
, width
, height
, sizeFlags
);
800 m_genericImpl
->SetSize(0, 0, width
, height
, sizeFlags
);
802 // determine if we need a horizontal scrollbar, and add it if so
806 for (int column
= 0; column
< GetColumnCount(); column
++)
808 totalWidth
+= m_dbImpl
->GetColumnWidth( column
);
811 if ( !(m_dbImpl
->GetFlags() & wxHSCROLL
) )
813 Boolean vertScrollBar
;
814 GetDataBrowserHasScrollBars( m_dbImpl
->GetControlRef(), NULL
, &vertScrollBar
);
815 if (totalWidth
> width
)
816 SetDataBrowserHasScrollBars( m_dbImpl
->GetControlRef(), true, vertScrollBar
);
818 SetDataBrowserHasScrollBars( m_dbImpl
->GetControlRef(), false, vertScrollBar
);
823 wxSize
wxListCtrl::DoGetBestSize() const
825 return wxWindow::DoGetBestSize();
828 bool wxListCtrl::SetFont(const wxFont
& font
)
831 rv
= wxControl::SetFont(font
);
833 rv
= m_genericImpl
->SetFont(font
);
837 bool wxListCtrl::SetForegroundColour(const wxColour
& colour
)
841 rv
= m_genericImpl
->SetForegroundColour(colour
);
843 SetTextColour(colour
);
847 bool wxListCtrl::SetBackgroundColour(const wxColour
& colour
)
851 rv
= m_genericImpl
->SetBackgroundColour(colour
);
857 wxColour
wxListCtrl::GetBackgroundColour()
860 return m_genericImpl
->GetBackgroundColour();
867 // ----------------------------------------------------------------------------
869 // ----------------------------------------------------------------------------
871 // Gets information about this column
872 bool wxListCtrl::GetColumn(int col
, wxListItem
& item
) const
875 return m_genericImpl
->GetColumn(col
, item
);
881 wxColumnList::compatibility_iterator node
= m_colsInfo
.Item( col
);
882 wxASSERT_MSG( node
, _T("invalid column index in wxMacListCtrlItem") );
883 wxListItem
* column
= node
->GetData();
885 long mask
= column
->GetMask();
886 if (mask
& wxLIST_MASK_TEXT
)
887 item
.SetText(column
->GetText());
888 if (mask
& wxLIST_MASK_DATA
)
889 item
.SetData(column
->GetData());
890 if (mask
& wxLIST_MASK_IMAGE
)
891 item
.SetImage(column
->GetImage());
892 if (mask
& wxLIST_MASK_STATE
)
893 item
.SetState(column
->GetState());
894 if (mask
& wxLIST_MASK_FORMAT
)
895 item
.SetAlign(column
->GetAlign());
896 if (mask
& wxLIST_MASK_WIDTH
)
897 item
.SetWidth(column
->GetWidth());
903 // Sets information about this column
904 bool wxListCtrl::SetColumn(int col
, wxListItem
& item
)
907 return m_genericImpl
->SetColumn(col
, item
);
911 long mask
= item
.GetMask();
912 if ( col
>= (int)m_colsInfo
.GetCount() )
914 wxListItem
* listItem
= new wxListItem(item
);
915 m_colsInfo
.Append( listItem
);
920 GetColumn( col
, listItem
);
922 if (mask
& wxLIST_MASK_TEXT
)
923 listItem
.SetText(item
.GetText());
924 if (mask
& wxLIST_MASK_DATA
)
925 listItem
.SetData(item
.GetData());
926 if (mask
& wxLIST_MASK_IMAGE
)
927 listItem
.SetImage(item
.GetImage());
928 if (mask
& wxLIST_MASK_STATE
)
929 listItem
.SetState(item
.GetState());
930 if (mask
& wxLIST_MASK_FORMAT
)
931 listItem
.SetAlign(item
.GetAlign());
932 if (mask
& wxLIST_MASK_WIDTH
)
933 listItem
.SetWidth(item
.GetWidth());
936 // change the appearance in the databrowser.
937 DataBrowserListViewHeaderDesc columnDesc
;
938 columnDesc
.version
=kDataBrowserListViewLatestHeaderDesc
;
939 verify_noerr( m_dbImpl
->GetHeaderDesc( kMinColumnId
+ col
, &columnDesc
) );
942 if (item.GetMask() & wxLIST_MASK_TEXT)
946 enc = m_font.GetEncoding();
948 enc = wxLocale::GetSystemEncoding();
949 wxMacCFStringHolder cfTitle;
950 cfTitle.Assign( item.GetText() , enc );
951 if(columnDesc.titleString)
952 CFRelease(columnDesc.titleString);
953 columnDesc.titleString = cfTitle;
957 if (item
.GetMask() & wxLIST_MASK_IMAGE
&& item
.GetImage() != -1 )
959 columnDesc
.btnContentInfo
.contentType
= kControlContentIconRef
;
960 wxImageList
* imageList
= GetImageList(wxIMAGE_LIST_SMALL
);
961 if (imageList
&& imageList
->GetImageCount() > 0 )
963 wxBitmap bmp
= imageList
->GetBitmap( item
.GetImage() );
964 IconRef icon
= bmp
.GetBitmapData()->GetIconRef();
965 columnDesc
.btnContentInfo
.u
.iconRef
= icon
;
969 verify_noerr( m_dbImpl
->SetHeaderDesc( kMinColumnId
+ col
, &columnDesc
) );
975 int wxListCtrl::GetColumnCount() const
978 return m_genericImpl
->GetColumnCount();
983 m_dbImpl
->GetColumnCount(&count
);
990 // Gets the column width
991 int wxListCtrl::GetColumnWidth(int col
) const
994 return m_genericImpl
->GetColumnWidth(col
);
998 return m_dbImpl
->GetColumnWidth(col
);
1004 // Sets the column width
1005 bool wxListCtrl::SetColumnWidth(int col
, int width
)
1008 return m_genericImpl
->SetColumnWidth(col
, width
);
1012 int mywidth
= width
;
1013 if (width
== wxLIST_AUTOSIZE
|| width
== wxLIST_AUTOSIZE_USEHEADER
)
1018 for (int column
= 0; column
< GetColumnCount(); column
++)
1021 GetColumn(col
, colInfo
);
1023 colInfo
.SetWidth(width
);
1024 SetColumn(col
, colInfo
);
1026 m_dbImpl
->SetColumnWidth(col
, mywidth
);
1032 GetColumn(col
, colInfo
);
1034 colInfo
.SetWidth(width
);
1035 SetColumn(col
, colInfo
);
1036 m_dbImpl
->SetColumnWidth(col
, mywidth
);
1044 // Gets the number of items that can fit vertically in the
1045 // visible area of the list control (list or report view)
1046 // or the total number of items in the list control (icon
1047 // or small icon view)
1048 int wxListCtrl::GetCountPerPage() const
1051 return m_genericImpl
->GetCountPerPage();
1060 // Gets the edit control for editing labels.
1061 wxTextCtrl
* wxListCtrl::GetEditControl() const
1064 return m_genericImpl
->GetEditControl();
1069 // Gets information about the item
1070 bool wxListCtrl::GetItem(wxListItem
& info
) const
1073 return m_genericImpl
->GetItem(info
);
1078 m_dbImpl
->MacGetColumnInfo(info
.m_itemId
, info
.m_col
, info
);
1081 info
.SetText( OnGetItemText(info
.m_itemId
, info
.m_col
) );
1082 info
.SetImage( OnGetItemColumnImage(info
.m_itemId
, info
.m_col
) );
1083 if (info
.GetMask() & wxLIST_MASK_STATE
)
1085 if (IsDataBrowserItemSelected( m_dbImpl
->GetControlRef(), info
.m_itemId
+1 ))
1086 info
.SetState(info
.GetState() | wxLIST_STATE_SELECTED
);
1089 wxListItemAttr
* attrs
= OnGetItemAttr( info
.m_itemId
);
1092 info
.SetFont( attrs
->GetFont() );
1093 info
.SetBackgroundColour( attrs
->GetBackgroundColour() );
1094 info
.SetTextColour( attrs
->GetTextColour() );
1098 bool success
= true;
1102 // Sets information about the item
1103 bool wxListCtrl::SetItem(wxListItem
& info
)
1106 return m_genericImpl
->SetItem(info
);
1109 m_dbImpl
->MacSetColumnInfo( info
.m_itemId
, info
.m_col
, &info
);
1114 long wxListCtrl::SetItem(long index
, int col
, const wxString
& label
, int imageId
)
1117 return m_genericImpl
->SetItem(index
, col
, label
, imageId
);
1120 info
.m_text
= label
;
1121 info
.m_mask
= wxLIST_MASK_TEXT
;
1122 info
.m_itemId
= index
;
1126 info
.m_image
= imageId
;
1127 info
.m_mask
|= wxLIST_MASK_IMAGE
;
1129 return SetItem(info
);
1133 // Gets the item state
1134 int wxListCtrl::GetItemState(long item
, long stateMask
) const
1137 return m_genericImpl
->GetItemState(item
, stateMask
);
1141 if ( HasFlag(wxLC_VIRTUAL
) )
1143 if (stateMask
== wxLIST_STATE_SELECTED
)
1145 if (IsDataBrowserItemSelected( m_dbImpl
->GetControlRef(), item
+1 ))
1146 return wxLIST_STATE_SELECTED
;
1155 info
.m_mask
= wxLIST_MASK_STATE
;
1156 info
.m_stateMask
= stateMask
;
1157 info
.m_itemId
= item
;
1162 return info
.m_state
;
1169 // Sets the item state
1170 bool wxListCtrl::SetItemState(long item
, long state
, long stateMask
)
1173 return m_genericImpl
->SetItemState(item
, state
, stateMask
);
1177 DataBrowserSetOption option
= kDataBrowserItemsAdd
;
1178 if ( stateMask
== wxLIST_STATE_SELECTED
&& state
== 0 )
1179 option
= kDataBrowserItemsRemove
;
1183 if ( HasFlag(wxLC_VIRTUAL
) )
1185 wxMacDataItemBrowserSelectionSuppressor
suppressor(m_dbImpl
);
1186 m_dbImpl
->SetSelectedAllItems(option
);
1190 for(int i
= 0; i
< GetItemCount();i
++)
1194 info
.m_mask
= wxLIST_MASK_STATE
;
1195 info
.m_stateMask
= stateMask
;
1196 info
.m_state
= state
;
1203 if ( HasFlag(wxLC_VIRTUAL
) )
1205 long itemID
= item
+1;
1206 SetDataBrowserSelectedItems(m_dbImpl
->GetControlRef(), 1, (DataBrowserItemID
*)&itemID
, option
);
1211 info
.m_itemId
= item
;
1212 info
.m_mask
= wxLIST_MASK_STATE
;
1213 info
.m_stateMask
= stateMask
;
1214 info
.m_state
= state
;
1215 return SetItem(info
);
1222 // Sets the item image
1223 bool wxListCtrl::SetItemImage(long item
, int image
, int WXUNUSED(selImage
))
1225 return SetItemColumnImage(item
, 0, image
);
1228 // Sets the item image
1229 bool wxListCtrl::SetItemColumnImage(long item
, long column
, int image
)
1232 return m_genericImpl
->SetItemColumnImage(item
, column
, image
);
1236 info
.m_mask
= wxLIST_MASK_IMAGE
;
1237 info
.m_image
= image
;
1238 info
.m_itemId
= item
;
1239 info
.m_col
= column
;
1241 return SetItem(info
);
1244 // Gets the item text
1245 wxString
wxListCtrl::GetItemText(long item
) const
1248 return m_genericImpl
->GetItemText(item
);
1252 info
.m_mask
= wxLIST_MASK_TEXT
;
1253 info
.m_itemId
= item
;
1256 return wxEmptyString
;
1260 // Sets the item text
1261 void wxListCtrl::SetItemText(long item
, const wxString
& str
)
1264 return m_genericImpl
->SetItemText(item
, str
);
1268 info
.m_mask
= wxLIST_MASK_TEXT
;
1269 info
.m_itemId
= item
;
1275 // Gets the item data
1276 long wxListCtrl::GetItemData(long item
) const
1279 return m_genericImpl
->GetItemData(item
);
1283 info
.m_mask
= wxLIST_MASK_DATA
;
1284 info
.m_itemId
= item
;
1291 // Sets the item data
1292 bool wxListCtrl::SetItemData(long item
, long data
)
1295 return m_genericImpl
->SetItemData(item
, data
);
1299 info
.m_mask
= wxLIST_MASK_DATA
;
1300 info
.m_itemId
= item
;
1303 return SetItem(info
);
1306 wxRect
wxListCtrl::GetViewRect() const
1308 wxASSERT_MSG( !HasFlag(wxLC_REPORT
| wxLC_LIST
),
1309 _T("wxListCtrl::GetViewRect() only works in icon mode") );
1312 return m_genericImpl
->GetViewRect();
1318 // Gets the item rectangle
1319 bool wxListCtrl::GetItemRect(long item
, wxRect
& rect
, int code
) const
1322 return m_genericImpl
->GetItemRect(item
, rect
, code
);
1327 DataBrowserItemID id
;
1328 DataBrowserPropertyID col
= kMinColumnId
;
1330 DataBrowserPropertyPart part
= kDataBrowserPropertyEnclosingPart
;
1331 if ( code
== wxLIST_RECT_LABEL
)
1332 part
= kDataBrowserPropertyTextPart
;
1333 else if ( code
== wxLIST_RECT_ICON
)
1334 part
= kDataBrowserPropertyIconPart
;
1336 if ( !(GetWindowStyleFlag() & wxLC_VIRTUAL
) )
1338 wxMacDataItem
* thisItem
= m_dbImpl
->GetItemFromLine(item
);
1339 id
= (DataBrowserItemID
) thisItem
;
1344 GetDataBrowserItemPartBounds( m_dbImpl
->GetControlRef(), id
, col
, part
, &bounds
);
1346 rect
.x
= bounds
.left
;
1347 rect
.y
= bounds
.top
;
1348 rect
.width
= bounds
.right
- bounds
.left
; //GetClientSize().x; // we need the width of the whole row, not just the item.
1349 rect
.height
= bounds
.bottom
- bounds
.top
;
1350 //fprintf("id = %d, bounds = %d, %d, %d, %d\n", id, rect.x, rect.y, rect.width, rect.height);
1355 // Gets the item position
1356 bool wxListCtrl::GetItemPosition(long item
, wxPoint
& pos
) const
1359 return m_genericImpl
->GetItemPosition(item
, pos
);
1361 bool success
= false;
1366 GetItemRect(item
, itemRect
);
1367 pos
= itemRect
.GetPosition();
1374 // Sets the item position.
1375 bool wxListCtrl::SetItemPosition(long item
, const wxPoint
& pos
)
1378 return m_genericImpl
->SetItemPosition(item
, pos
);
1383 // Gets the number of items in the list control
1384 int wxListCtrl::GetItemCount() const
1387 return m_genericImpl
->GetItemCount();
1390 return m_dbImpl
->MacGetCount();
1395 void wxListCtrl::SetItemSpacing( int spacing
, bool isSmall
)
1398 m_genericImpl
->SetItemSpacing(spacing
, isSmall
);
1401 wxSize
wxListCtrl::GetItemSpacing() const
1404 return m_genericImpl
->GetItemSpacing();
1406 return wxSize(0, 0);
1409 void wxListCtrl::SetItemTextColour( long item
, const wxColour
&col
)
1413 m_genericImpl
->SetItemTextColour(item
, col
);
1418 info
.m_itemId
= item
;
1419 info
.SetTextColour( col
);
1423 wxColour
wxListCtrl::GetItemTextColour( long item
) const
1426 return m_genericImpl
->GetItemTextColour(item
);
1432 return info
.GetTextColour();
1434 return wxNullColour
;
1437 void wxListCtrl::SetItemBackgroundColour( long item
, const wxColour
&col
)
1441 m_genericImpl
->SetItemBackgroundColour(item
, col
);
1446 info
.m_itemId
= item
;
1447 info
.SetBackgroundColour( col
);
1451 wxColour
wxListCtrl::GetItemBackgroundColour( long item
) const
1454 return m_genericImpl
->GetItemBackgroundColour(item
);
1460 return info
.GetBackgroundColour();
1462 return wxNullColour
;
1465 void wxListCtrl::SetItemFont( long item
, const wxFont
&f
)
1469 m_genericImpl
->SetItemFont(item
, f
);
1474 info
.m_itemId
= item
;
1479 wxFont
wxListCtrl::GetItemFont( long item
) const
1482 return m_genericImpl
->GetItemFont(item
);
1488 return info
.GetFont();
1494 // Gets the number of selected items in the list control
1495 int wxListCtrl::GetSelectedItemCount() const
1498 return m_genericImpl
->GetSelectedItemCount();
1501 return m_dbImpl
->GetSelectedItemCount(NULL
, true);
1506 // Gets the text colour of the listview
1507 wxColour
wxListCtrl::GetTextColour() const
1510 return m_genericImpl
->GetTextColour();
1512 // TODO: we need owner drawn list items to customize text color.
1516 return wxNullColour
;
1519 // Sets the text colour of the listview
1520 void wxListCtrl::SetTextColour(const wxColour
& col
)
1524 m_genericImpl
->SetTextColour(col
);
1532 // Gets the index of the topmost visible item when in
1533 // list or report view
1534 long wxListCtrl::GetTopItem() const
1537 return m_genericImpl
->GetTopItem();
1542 long item
= HitTest( wxPoint(1, 1), flags
);
1543 if (flags
== wxLIST_HITTEST_ONITEM
)
1550 // Searches for an item, starting from 'item'.
1551 // 'geometry' is one of
1552 // wxLIST_NEXT_ABOVE/ALL/BELOW/LEFT/RIGHT.
1553 // 'state' is a state bit flag, one or more of
1554 // wxLIST_STATE_DROPHILITED/FOCUSED/SELECTED/CUT.
1555 // item can be -1 to find the first item that matches the
1557 // Returns the item or -1 if unsuccessful.
1558 long wxListCtrl::GetNextItem(long item
, int geom
, int state
) const
1561 return m_genericImpl
->GetNextItem(item
, geom
, state
);
1563 // TODO: implement all geometry and state options?
1566 if ( geom
== wxLIST_NEXT_ALL
|| geom
== wxLIST_NEXT_BELOW
)
1568 long count
= m_dbImpl
->MacGetCount() ;
1569 for ( long line
= item
+ 1 ; line
< count
; line
++ )
1571 wxMacDataItem
* id
= m_dbImpl
->GetItemFromLine(line
);
1573 if ( (state
== wxLIST_STATE_DONTCARE
) )
1576 if ( (state
& wxLIST_STATE_SELECTED
) && m_dbImpl
->IsItemSelected( id
) )
1580 else if ( geom
== wxLIST_NEXT_ABOVE
)
1584 item2
= m_dbImpl
->MacGetCount();
1586 for ( long line
= item2
- 1 ; line
>= 0; line
-- )
1588 wxMacDataItem
* id
= m_dbImpl
->GetItemFromLine(line
);
1590 if ( (state
== wxLIST_STATE_DONTCARE
) )
1593 if ( (state
& wxLIST_STATE_SELECTED
) && m_dbImpl
->IsItemSelected( id
) )
1603 wxImageList
*wxListCtrl::GetImageList(int which
) const
1606 return m_genericImpl
->GetImageList(which
);
1608 if ( which
== wxIMAGE_LIST_NORMAL
)
1610 return m_imageListNormal
;
1612 else if ( which
== wxIMAGE_LIST_SMALL
)
1614 return m_imageListSmall
;
1616 else if ( which
== wxIMAGE_LIST_STATE
)
1618 return m_imageListState
;
1623 void wxListCtrl::SetImageList(wxImageList
*imageList
, int which
)
1627 m_genericImpl
->SetImageList(imageList
, which
);
1631 if ( which
== wxIMAGE_LIST_NORMAL
)
1633 if (m_ownsImageListNormal
) delete m_imageListNormal
;
1634 m_imageListNormal
= imageList
;
1635 m_ownsImageListNormal
= false;
1637 else if ( which
== wxIMAGE_LIST_SMALL
)
1639 if (m_ownsImageListSmall
) delete m_imageListSmall
;
1640 m_imageListSmall
= imageList
;
1641 m_ownsImageListSmall
= false;
1643 else if ( which
== wxIMAGE_LIST_STATE
)
1645 if (m_ownsImageListState
) delete m_imageListState
;
1646 m_imageListState
= imageList
;
1647 m_ownsImageListState
= false;
1651 void wxListCtrl::AssignImageList(wxImageList
*imageList
, int which
)
1655 m_genericImpl
->AssignImageList(imageList
, which
);
1659 SetImageList(imageList
, which
);
1660 if ( which
== wxIMAGE_LIST_NORMAL
)
1661 m_ownsImageListNormal
= true;
1662 else if ( which
== wxIMAGE_LIST_SMALL
)
1663 m_ownsImageListSmall
= true;
1664 else if ( which
== wxIMAGE_LIST_STATE
)
1665 m_ownsImageListState
= true;
1668 // ----------------------------------------------------------------------------
1670 // ----------------------------------------------------------------------------
1672 // Arranges the items
1673 bool wxListCtrl::Arrange(int flag
)
1676 return m_genericImpl
->Arrange(flag
);
1681 bool wxListCtrl::DeleteItem(long item
)
1684 return m_genericImpl
->DeleteItem(item
);
1688 m_dbImpl
->MacDelete(item
);
1689 wxListEvent
event( wxEVT_COMMAND_LIST_DELETE_ITEM
, GetId() );
1690 event
.SetEventObject( this );
1691 event
.m_itemIndex
= item
;
1692 GetEventHandler()->ProcessEvent( event
);
1698 // Deletes all items
1699 bool wxListCtrl::DeleteAllItems()
1702 return m_genericImpl
->DeleteAllItems();
1706 m_dbImpl
->MacClear();
1707 wxListEvent
event( wxEVT_COMMAND_LIST_DELETE_ALL_ITEMS
, GetId() );
1708 event
.SetEventObject( this );
1709 GetEventHandler()->ProcessEvent( event
);
1714 // Deletes all items
1715 bool wxListCtrl::DeleteAllColumns()
1718 return m_genericImpl
->DeleteAllColumns();
1723 m_dbImpl
->GetColumnCount(&cols
);
1724 for (UInt32 col
= 0; col
< cols
; col
++)
1734 bool wxListCtrl::DeleteColumn(int col
)
1737 return m_genericImpl
->DeleteColumn(col
);
1741 OSStatus err
= m_dbImpl
->RemoveColumn(col
);
1742 return err
== noErr
;
1748 // Clears items, and columns if there are any.
1749 void wxListCtrl::ClearAll()
1753 m_genericImpl
->ClearAll();
1764 wxTextCtrl
* wxListCtrl::EditLabel(long item
, wxClassInfo
* textControlClass
)
1767 return m_genericImpl
->EditLabel(item
, textControlClass
);
1771 wxCHECK_MSG( (item
>= 0) && ((long)item
< GetItemCount()), NULL
,
1772 wxT("wrong index in wxListCtrl::EditLabel()") );
1774 wxASSERT_MSG( textControlClass
->IsKindOf(CLASSINFO(wxTextCtrl
)),
1775 wxT("EditLabel() needs a text control") );
1777 wxListEvent
le( wxEVT_COMMAND_LIST_BEGIN_LABEL_EDIT
, GetParent()->GetId() );
1778 le
.SetEventObject( this );
1779 le
.m_itemIndex
= item
;
1781 GetItem( le
.m_item
);
1783 if ( GetParent()->GetEventHandler()->ProcessEvent( le
) && !le
.IsAllowed() )
1785 // vetoed by user code
1789 wxTextCtrl
* const text
= (wxTextCtrl
*)textControlClass
->CreateObject();
1790 m_textctrlWrapper
= new wxListCtrlTextCtrlWrapper(this, text
, item
);
1791 return m_textctrlWrapper
->GetText();
1796 // End label editing, optionally cancelling the edit
1797 bool wxListCtrl::EndEditLabel(bool cancel
)
1799 // TODO: generic impl. doesn't have this method - is it needed for us?
1801 return true; // m_genericImpl->EndEditLabel(cancel);
1804 verify_noerr( SetDataBrowserEditItem(m_dbImpl
->GetControlRef(), kDataBrowserNoItem
, kMinColumnId
) );
1808 // Ensures this item is visible
1809 bool wxListCtrl::EnsureVisible(long item
)
1812 return m_genericImpl
->EnsureVisible(item
);
1816 wxMacDataItem
* dataItem
= m_dbImpl
->GetItemFromLine(item
);
1817 m_dbImpl
->RevealItem(dataItem
, kDataBrowserRevealWithoutSelecting
);
1823 // Find an item whose label matches this string, starting from the item after 'start'
1824 // or the beginning if 'start' is -1.
1825 long wxListCtrl::FindItem(long start
, const wxString
& str
, bool partial
)
1828 return m_genericImpl
->FindItem(start
, str
, partial
);
1830 wxString str_upper
= str
.Upper();
1835 long count
= GetItemCount();
1839 wxString line_upper
= GetItemText(idx
).Upper();
1842 if (line_upper
== str_upper
)
1847 if (line_upper
.find(str_upper
) == 0)
1857 // Find an item whose data matches this data, starting from the item after 'start'
1858 // or the beginning if 'start' is -1.
1859 long wxListCtrl::FindItem(long start
, long data
)
1862 return m_genericImpl
->FindItem(start
, data
);
1867 long count
= GetItemCount();
1871 if (GetItemData(idx
) == data
)
1879 // Find an item nearest this position in the specified direction, starting from
1880 // the item after 'start' or the beginning if 'start' is -1.
1881 long wxListCtrl::FindItem(long start
, const wxPoint
& pt
, int direction
)
1884 return m_genericImpl
->FindItem(start
, pt
, direction
);
1888 // Determines which item (if any) is at the specified point,
1889 // giving details in 'flags' (see wxLIST_HITTEST_... flags above)
1891 wxListCtrl::HitTest(const wxPoint
& point
, int& flags
, long *ptrSubItem
) const
1894 return m_genericImpl
->HitTest(point
, flags
, ptrSubItem
);
1896 flags
= wxLIST_HITTEST_NOWHERE
;
1899 int colHeaderHeight
= 22; // TODO: Find a way to get this value from the db control?
1900 UInt16 rowHeight
= 0;
1901 m_dbImpl
->GetDefaultRowHeight(&rowHeight
);
1904 // get the actual row by taking scroll position into account
1905 UInt32 offsetX
, offsetY
;
1906 m_dbImpl
->GetScrollPosition( &offsetY
, &offsetX
);
1909 if ( !(GetWindowStyleFlag() & wxLC_NO_HEADER
) )
1910 y
-= colHeaderHeight
;
1915 int row
= y
/ rowHeight
;
1916 DataBrowserItemID id
;
1917 m_dbImpl
->GetItemID( (DataBrowserTableViewRowIndex
) row
, &id
);
1919 // TODO: Use GetDataBrowserItemPartBounds to return if we are in icon or label
1920 if ( !(GetWindowStyleFlag() & wxLC_VIRTUAL
) )
1922 wxMacListCtrlItem
* lcItem
;
1923 lcItem
= (wxMacListCtrlItem
*) id
;
1926 flags
= wxLIST_HITTEST_ONITEM
;
1932 if (row
< GetItemCount() )
1934 flags
= wxLIST_HITTEST_ONITEM
;
1943 int wxListCtrl::GetScrollPos(int orient
) const
1946 return m_genericImpl
->GetScrollPos(orient
);
1950 UInt32 offsetX
, offsetY
;
1951 m_dbImpl
->GetScrollPosition( &offsetY
, &offsetX
);
1952 if ( orient
== wxHORIZONTAL
)
1961 // Inserts an item, returning the index of the new item if successful,
1963 long wxListCtrl::InsertItem(wxListItem
& info
)
1965 wxASSERT_MSG( !IsVirtual(), _T("can't be used with virtual controls") );
1968 return m_genericImpl
->InsertItem(info
);
1970 if (m_dbImpl
&& !IsVirtual())
1972 int count
= GetItemCount();
1974 if (info
.m_itemId
> count
)
1975 info
.m_itemId
= count
;
1977 m_dbImpl
->MacInsertItem(info
.m_itemId
, &info
);
1979 wxListEvent
event( wxEVT_COMMAND_LIST_INSERT_ITEM
, GetId() );
1980 event
.SetEventObject( this );
1981 event
.m_itemIndex
= info
.m_itemId
;
1982 GetEventHandler()->ProcessEvent( event
);
1983 return info
.m_itemId
;
1988 long wxListCtrl::InsertItem(long index
, const wxString
& label
)
1991 return m_genericImpl
->InsertItem(index
, label
);
1994 info
.m_text
= label
;
1995 info
.m_mask
= wxLIST_MASK_TEXT
;
1996 info
.m_itemId
= index
;
1997 return InsertItem(info
);
2000 // Inserts an image item
2001 long wxListCtrl::InsertItem(long index
, int imageIndex
)
2004 return m_genericImpl
->InsertItem(index
, imageIndex
);
2007 info
.m_image
= imageIndex
;
2008 info
.m_mask
= wxLIST_MASK_IMAGE
;
2009 info
.m_itemId
= index
;
2010 return InsertItem(info
);
2013 // Inserts an image/string item
2014 long wxListCtrl::InsertItem(long index
, const wxString
& label
, int imageIndex
)
2017 return m_genericImpl
->InsertItem(index
, label
, imageIndex
);
2020 info
.m_image
= imageIndex
;
2021 info
.m_text
= label
;
2022 info
.m_mask
= wxLIST_MASK_IMAGE
| wxLIST_MASK_TEXT
;
2023 info
.m_itemId
= index
;
2024 return InsertItem(info
);
2027 // For list view mode (only), inserts a column.
2028 long wxListCtrl::InsertColumn(long col
, wxListItem
& item
)
2031 return m_genericImpl
->InsertColumn(col
, item
);
2035 int width
= item
.GetWidth();
2036 if ( !(item
.GetMask() & wxLIST_MASK_WIDTH
) )
2039 DataBrowserPropertyType type
= kDataBrowserCustomType
; //kDataBrowserTextType;
2040 wxImageList
* imageList
= GetImageList(wxIMAGE_LIST_SMALL
);
2041 if (imageList
&& imageList
->GetImageCount() > 0)
2043 wxBitmap bmp
= imageList
->GetBitmap(0);
2045 // type = kDataBrowserIconAndTextType;
2048 SInt16 just
= teFlushDefault
;
2049 if (item
.GetMask() & wxLIST_MASK_FORMAT
)
2051 if (item
.GetAlign() == wxLIST_FORMAT_LEFT
)
2053 else if (item
.GetAlign() == wxLIST_FORMAT_CENTER
)
2055 else if (item
.GetAlign() == wxLIST_FORMAT_RIGHT
)
2056 just
= teFlushRight
;
2058 m_dbImpl
->InsertColumn(col
, type
, item
.GetText(), just
, width
);
2059 SetColumn(col
, item
);
2061 // set/remove options based on the wxListCtrl type.
2062 DataBrowserTableViewColumnID id
;
2063 m_dbImpl
->GetColumnIDFromIndex(col
, &id
);
2064 DataBrowserPropertyFlags flags
;
2065 verify_noerr(m_dbImpl
->GetPropertyFlags(id
, &flags
));
2066 if (GetWindowStyleFlag() & wxLC_EDIT_LABELS
)
2067 flags
|= kDataBrowserPropertyIsEditable
;
2069 if (GetWindowStyleFlag() & wxLC_VIRTUAL
){
2070 flags
&= ~kDataBrowserListViewSortableColumn
;
2072 verify_noerr(m_dbImpl
->SetPropertyFlags(id
, flags
));
2078 long wxListCtrl::InsertColumn(long col
,
2079 const wxString
& heading
,
2084 return m_genericImpl
->InsertColumn(col
, heading
, format
, width
);
2087 item
.m_mask
= wxLIST_MASK_TEXT
| wxLIST_MASK_FORMAT
;
2088 item
.m_text
= heading
;
2091 item
.m_mask
|= wxLIST_MASK_WIDTH
;
2092 item
.m_width
= width
;
2094 item
.m_format
= format
;
2096 return InsertColumn(col
, item
);
2099 // scroll the control by the given number of pixels (exception: in list view,
2100 // dx is interpreted as number of columns)
2101 bool wxListCtrl::ScrollList(int dx
, int dy
)
2104 return m_genericImpl
->ScrollList(dx
, dy
);
2108 m_dbImpl
->SetScrollPosition(dx
, dy
);
2114 bool wxListCtrl::SortItems(wxListCtrlCompare fn
, long data
)
2117 return m_genericImpl
->SortItems(fn
, data
);
2122 m_compareFuncData
= data
;
2123 SortDataBrowserContainer( m_dbImpl
->GetControlRef(), kDataBrowserNoItem
, true);
2125 // we need to do this after each call, else we get a crash from wxPython when
2126 // SortItems is called the second time.
2127 m_compareFunc
= NULL
;
2128 m_compareFuncData
= 0;
2134 void wxListCtrl::OnRenameTimer()
2136 wxCHECK_RET( HasCurrent(), wxT("unexpected rename timer") );
2138 EditLabel( m_current
);
2141 bool wxListCtrl::OnRenameAccept(long itemEdit
, const wxString
& value
)
2143 wxListEvent
le( wxEVT_COMMAND_LIST_END_LABEL_EDIT
, GetId() );
2144 le
.SetEventObject( this );
2145 le
.m_itemIndex
= itemEdit
;
2147 GetItem( le
.m_item
);
2148 le
.m_item
.m_text
= value
;
2149 return !GetEventHandler()->ProcessEvent( le
) ||
2153 void wxListCtrl::OnRenameCancelled(long itemEdit
)
2155 // let owner know that the edit was cancelled
2156 wxListEvent
le( wxEVT_COMMAND_LIST_END_LABEL_EDIT
, GetParent()->GetId() );
2158 le
.SetEditCanceled(true);
2160 le
.SetEventObject( this );
2161 le
.m_itemIndex
= itemEdit
;
2163 GetItem( le
.m_item
);
2164 GetEventHandler()->ProcessEvent( le
);
2167 // ----------------------------------------------------------------------------
2168 // virtual list controls
2169 // ----------------------------------------------------------------------------
2171 wxString
wxListCtrl::OnGetItemText(long WXUNUSED(item
), long WXUNUSED(col
)) const
2173 // this is a pure virtual function, in fact - which is not really pure
2174 // because the controls which are not virtual don't need to implement it
2175 wxFAIL_MSG( _T("wxListCtrl::OnGetItemText not supposed to be called") );
2177 return wxEmptyString
;
2180 int wxListCtrl::OnGetItemImage(long WXUNUSED(item
)) const
2182 wxCHECK_MSG(!GetImageList(wxIMAGE_LIST_SMALL
),
2184 wxT("List control has an image list, OnGetItemImage or OnGetItemColumnImage should be overridden."));
2188 int wxListCtrl::OnGetItemColumnImage(long item
, long column
) const
2191 return OnGetItemImage(item
);
2196 wxListItemAttr
*wxListCtrl::OnGetItemAttr(long WXUNUSED_UNLESS_DEBUG(item
)) const
2198 wxASSERT_MSG( item
>= 0 && item
< GetItemCount(),
2199 _T("invalid item index in OnGetItemAttr()") );
2201 // no attributes by default
2205 void wxListCtrl::SetItemCount(long count
)
2207 wxASSERT_MSG( IsVirtual(), _T("this is for virtual controls only") );
2211 m_genericImpl
->SetItemCount(count
);
2217 // we need to temporarily disable the new item creation notification
2218 // procedure to speed things up
2219 // FIXME: Even this doesn't seem to help much...
2221 // FIXME: Find a more efficient way to do this.
2222 m_dbImpl
->MacClear();
2224 DataBrowserCallbacks callbacks
;
2225 DataBrowserItemNotificationUPP itemUPP
;
2226 GetDataBrowserCallbacks(m_dbImpl
->GetControlRef(), &callbacks
);
2227 itemUPP
= callbacks
.u
.v1
.itemNotificationCallback
;
2228 callbacks
.u
.v1
.itemNotificationCallback
= 0;
2229 m_dbImpl
->SetCallbacks(&callbacks
);
2230 ::AddDataBrowserItems(m_dbImpl
->GetControlRef(), kDataBrowserNoItem
,
2231 count
, NULL
, kDataBrowserItemNoProperty
);
2232 callbacks
.u
.v1
.itemNotificationCallback
= itemUPP
;
2233 m_dbImpl
->SetCallbacks(&callbacks
);
2238 void wxListCtrl::RefreshItem(long item
)
2242 m_genericImpl
->RefreshItem(item
);
2247 GetItemRect(item
, rect
);
2251 void wxListCtrl::RefreshItems(long itemFrom
, long itemTo
)
2255 m_genericImpl
->RefreshItems(itemFrom
, itemTo
);
2259 wxRect rect1
, rect2
;
2260 GetItemRect(itemFrom
, rect1
);
2261 GetItemRect(itemTo
, rect2
);
2263 wxRect rect
= rect1
;
2264 rect
.height
= rect2
.GetBottom() - rect1
.GetTop();
2269 void wxListCtrl::SetDropTarget( wxDropTarget
*dropTarget
)
2271 #if wxUSE_DRAG_AND_DROP
2273 m_genericImpl
->SetDropTarget( dropTarget
);
2276 wxWindow::SetDropTarget( dropTarget
);
2280 wxDropTarget
*wxListCtrl::GetDropTarget() const
2282 #if wxUSE_DRAG_AND_DROP
2284 return m_genericImpl
->GetDropTarget();
2287 return wxWindow::GetDropTarget();
2292 #if wxABI_VERSION >= 20801
2293 void wxListCtrl::SetFocus()
2297 m_genericImpl
->SetFocus();
2301 wxWindow::SetFocus();
2305 // wxMac internal data structures
2307 wxMacListCtrlItem::~wxMacListCtrlItem()
2311 void wxMacListCtrlItem::Notification(wxMacDataItemBrowserControl
*owner
,
2312 DataBrowserItemNotification message
,
2313 DataBrowserItemDataRef itemData
) const
2316 wxMacDataBrowserListCtrlControl
*lb
= wxDynamicCast(owner
, wxMacDataBrowserListCtrlControl
);
2318 // we want to depend on as little as possible to make sure tear-down of controls is safe
2319 if ( message
== kDataBrowserItemRemoved
)
2321 if ( lb
!= NULL
&& lb
->GetClientDataType() == wxClientData_Object
)
2323 delete (wxClientData
*) (m_data
);
2329 else if ( message
== kDataBrowserItemAdded
)
2331 // we don't issue events on adding, the item is not really stored in the list yet, so we
2332 // avoid asserts by gettting out now
2336 wxListCtrl
*list
= wxDynamicCast( owner
->GetPeer() , wxListCtrl
);
2339 bool trigger
= false;
2341 wxListEvent
event( wxEVT_COMMAND_LIST_ITEM_SELECTED
, list
->GetId() );
2342 bool isSingle
= (list
->GetWindowStyle() & wxLC_SINGLE_SEL
) != 0;
2344 event
.SetEventObject( list
);
2345 event
.m_itemIndex
= owner
->GetLineFromItem( this ) ;
2346 if ( !list
->IsVirtual() )
2348 lb
->MacGetColumnInfo(event
.m_itemIndex
,0,event
.m_item
);
2353 case kDataBrowserItemDeselected
:
2354 event
.SetEventType(wxEVT_COMMAND_LIST_ITEM_DESELECTED
);
2356 trigger
= !lb
->IsSelectionSuppressed();
2359 case kDataBrowserItemSelected
:
2360 trigger
= !lb
->IsSelectionSuppressed();
2363 case kDataBrowserItemDoubleClicked
:
2364 event
.SetEventType( wxEVT_COMMAND_LIST_ITEM_ACTIVATED
);
2368 case kDataBrowserEditStarted
:
2369 // TODO : how to veto ?
2370 event
.SetEventType( wxEVT_COMMAND_LIST_BEGIN_LABEL_EDIT
) ;
2374 case kDataBrowserEditStopped
:
2375 // TODO probably trigger only upon the value store callback, because
2376 // here IIRC we cannot veto
2377 event
.SetEventType( wxEVT_COMMAND_LIST_END_LABEL_EDIT
) ;
2387 // direct notification is not always having the listbox GetSelection() having in synch with event
2388 wxPostEvent( list
->GetEventHandler(), event
);
2394 IMPLEMENT_DYNAMIC_CLASS(wxMacDataBrowserListCtrlControl
, wxMacDataItemBrowserControl
)
2396 wxMacDataBrowserListCtrlControl::wxMacDataBrowserListCtrlControl( wxWindow
*peer
, const wxPoint
& pos
, const wxSize
& size
, long style
)
2397 : wxMacDataItemBrowserControl( peer
, pos
, size
, style
)
2399 OSStatus err
= noErr
;
2400 m_clientDataItemsType
= wxClientData_None
;
2401 m_isVirtual
= false;
2404 if ( style
& wxLC_VIRTUAL
)
2407 DataBrowserSelectionFlags options
= kDataBrowserDragSelect
;
2408 if ( style
& wxLC_SINGLE_SEL
)
2410 options
|= kDataBrowserSelectOnlyOne
;
2414 options
|= kDataBrowserCmdTogglesSelection
;
2417 err
= SetSelectionFlags( options
);
2418 verify_noerr( err
);
2420 DataBrowserCustomCallbacks callbacks
;
2421 InitializeDataBrowserCustomCallbacks( &callbacks
, kDataBrowserLatestCustomCallbacks
);
2423 if ( gDataBrowserDrawItemUPP
== NULL
)
2424 gDataBrowserDrawItemUPP
= NewDataBrowserDrawItemUPP(DataBrowserDrawItemProc
);
2426 if ( gDataBrowserHitTestUPP
== NULL
)
2427 gDataBrowserHitTestUPP
= NewDataBrowserHitTestUPP(DataBrowserHitTestProc
);
2429 callbacks
.u
.v1
.drawItemCallback
= gDataBrowserDrawItemUPP
;
2430 callbacks
.u
.v1
.hitTestCallback
= gDataBrowserHitTestUPP
;
2432 SetDataBrowserCustomCallbacks( GetControlRef(), &callbacks
);
2434 if ( style
& wxLC_LIST
)
2436 InsertColumn(0, kDataBrowserIconAndTextType
, wxEmptyString
, -1, -1);
2437 verify_noerr( AutoSizeColumns() );
2440 if ( style
& wxLC_LIST
|| style
& wxLC_NO_HEADER
)
2441 verify_noerr( SetHeaderButtonHeight( 0 ) );
2444 SetSortProperty( kMinColumnId
- 1 );
2446 SetSortProperty( kMinColumnId
);
2448 m_sortOrder
= SortOrder_None
;
2450 if ( style
& wxLC_SORT_DESCENDING
)
2452 SetSortOrder( kDataBrowserOrderDecreasing
);
2454 else if ( style
& wxLC_SORT_ASCENDING
)
2456 SetSortOrder( kDataBrowserOrderIncreasing
);
2459 if ( style
& wxLC_VRULES
)
2461 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4
2462 verify_noerr( DataBrowserChangeAttributes(m_controlRef
, kDataBrowserAttributeListViewDrawColumnDividers
, kDataBrowserAttributeNone
) );
2466 verify_noerr( SetHiliteStyle(kDataBrowserTableViewFillHilite
) );
2467 verify_noerr( SetHasScrollBars( (style
& wxHSCROLL
) != 0 , true ) );
2470 pascal Boolean
wxMacDataBrowserListCtrlControl::DataBrowserEditTextProc(
2472 DataBrowserItemID itemID
,
2473 DataBrowserPropertyID property
,
2474 CFStringRef theString
,
2475 Rect
*maxEditTextRect
,
2476 Boolean
*shrinkToFit
)
2478 Boolean result
= false;
2479 wxMacDataBrowserListCtrlControl
* ctl
= wxDynamicCast(wxMacControl::GetReferenceFromNativeControl( browser
), wxMacDataBrowserListCtrlControl
);
2482 result
= ctl
->ConfirmEditText(itemID
, property
, theString
, maxEditTextRect
, shrinkToFit
);
2483 theString
= CFSTR("Hello!");
2488 bool wxMacDataBrowserListCtrlControl::ConfirmEditText(
2489 DataBrowserItemID itemID
,
2490 DataBrowserPropertyID property
,
2491 CFStringRef theString
,
2492 Rect
*maxEditTextRect
,
2493 Boolean
*shrinkToFit
)
2498 pascal void wxMacDataBrowserListCtrlControl::DataBrowserDrawItemProc(
2500 DataBrowserItemID itemID
,
2501 DataBrowserPropertyID property
,
2502 DataBrowserItemState itemState
,
2503 const Rect
*itemRect
,
2505 Boolean colorDevice
)
2507 wxMacDataBrowserListCtrlControl
* ctl
= wxDynamicCast(wxMacControl::GetReferenceFromNativeControl( browser
), wxMacDataBrowserListCtrlControl
);
2510 ctl
->DrawItem(itemID
, property
, itemState
, itemRect
, gdDepth
, colorDevice
);
2514 // routines needed for DrawItem
2519 kTextBoxHeight
= 14,
2520 kIconTextSpacingV
= 2,
2522 kContentHeight
= kIconHeight
+ kTextBoxHeight
+ kIconTextSpacingV
2525 static void calculateCGDrawingBounds(CGRect inItemRect
, CGRect
*outIconRect
, CGRect
*outTextRect
, bool hasIcon
= false)
2528 float iconH
, iconW
= 0;
2529 float padding
= kItemPadding
;
2532 iconH
= kIconHeight
;
2534 padding
= padding
*2;
2537 textBottom
= inItemRect
.origin
.y
;
2539 *outIconRect
= CGRectMake(inItemRect
.origin
.x
+ kItemPadding
,
2540 textBottom
+ kIconTextSpacingV
, kIconWidth
,
2543 *outTextRect
= CGRectMake(inItemRect
.origin
.x
+ padding
+ iconW
,
2544 textBottom
+ kIconTextSpacingV
, inItemRect
.size
.width
- padding
- iconW
,
2545 inItemRect
.size
.height
- kIconTextSpacingV
);
2548 void wxMacDataBrowserListCtrlControl::DrawItem(
2549 DataBrowserItemID itemID
,
2550 DataBrowserPropertyID property
,
2551 DataBrowserItemState itemState
,
2552 const Rect
*itemRect
,
2554 Boolean colorDevice
)
2557 wxFont font
= wxNullFont
;
2559 short listColumn
= property
- kMinColumnId
;
2561 wxListCtrl
* list
= wxDynamicCast( GetPeer() , wxListCtrl
);
2562 wxMacListCtrlItem
* lcItem
;
2563 wxColour color
= *wxBLACK
;
2564 wxColour bgColor
= wxNullColour
;
2566 if (listColumn
>= 0)
2570 lcItem
= (wxMacListCtrlItem
*) itemID
;
2571 if (lcItem
->HasColumnInfo(listColumn
)){
2572 wxListItem
* item
= lcItem
->GetColumnInfo(listColumn
);
2574 // we always use the 0 column to get font and text/background colors.
2575 if (lcItem
->HasColumnInfo(0))
2577 wxListItem
* firstItem
= lcItem
->GetColumnInfo(0);
2578 color
= firstItem
->GetTextColour();
2579 bgColor
= firstItem
->GetBackgroundColour();
2580 font
= firstItem
->GetFont();
2583 if (item
->GetMask() & wxLIST_MASK_TEXT
)
2584 text
= item
->GetText();
2585 if (item
->GetMask() & wxLIST_MASK_IMAGE
)
2586 imgIndex
= item
->GetImage();
2592 text
= list
->OnGetItemText( (long)itemID
-1, listColumn
);
2593 imgIndex
= list
->OnGetItemColumnImage( (long)itemID
-1, listColumn
);
2594 wxListItemAttr
* attrs
= list
->OnGetItemAttr( (long)itemID
-1 );
2597 if (attrs
->HasBackgroundColour())
2598 bgColor
= attrs
->GetBackgroundColour();
2599 if (attrs
->HasTextColour())
2600 color
= attrs
->GetTextColour();
2601 if (attrs
->HasFont())
2602 font
= attrs
->GetFont();
2607 wxColour listBgColor
= list
->GetBackgroundColour();
2608 if (bgColor
== wxNullColour
)
2609 bgColor
= listBgColor
;
2611 wxFont listFont
= list
->GetFont();
2612 if (font
== wxNullFont
)
2615 wxMacCFStringHolder cfString
;
2616 cfString
.Assign( text
, wxLocale::GetSystemEncoding() );
2619 CGRect enclosingCGRect
, iconCGRect
, textCGRect
;
2621 ThemeDrawingState savedState
= NULL
;
2622 CGContextRef context
= (CGContextRef
)list
->MacGetDrawingContext();
2623 RGBColor labelColor
;
2625 labelColor
.green
= 0;
2626 labelColor
.blue
= 0;
2628 RGBColor backgroundColor
;
2629 backgroundColor
.red
= 255;
2630 backgroundColor
.green
= 255;
2631 backgroundColor
.blue
= 255;
2633 GetDataBrowserItemPartBounds(GetControlRef(), itemID
, property
, kDataBrowserPropertyEnclosingPart
,
2636 enclosingCGRect
= CGRectMake(enclosingRect
.left
,
2638 enclosingRect
.right
- enclosingRect
.left
,
2639 enclosingRect
.bottom
- enclosingRect
.top
);
2641 active
= IsControlActive(GetControlRef());
2643 // don't paint the background over the vertical rule line
2644 if ( list
->GetWindowStyleFlag() & wxLC_VRULES
)
2646 enclosingCGRect
.origin
.x
+= 1;
2647 enclosingCGRect
.size
.width
-= 1;
2649 if (itemState
== kDataBrowserItemIsSelected
)
2652 GetThemeDrawingState(&savedState
);
2656 GetThemeBrushAsColor(kThemeBrushAlternatePrimaryHighlightColor
, 32, true, &backgroundColor
);
2657 GetThemeTextColor(kThemeTextColorWhite
, gdDepth
, colorDevice
, &labelColor
);
2661 GetThemeBrushAsColor(kThemeBrushSecondaryHighlightColor
, 32, true, &backgroundColor
);
2662 GetThemeTextColor(kThemeTextColorBlack
, gdDepth
, colorDevice
, &labelColor
);
2664 CGContextSaveGState(context
);
2666 CGContextSetRGBFillColor(context
, (float)backgroundColor
.red
/ (float)USHRT_MAX
,
2667 (float)backgroundColor
.green
/ (float)USHRT_MAX
,
2668 (float)backgroundColor
.blue
/ (float)USHRT_MAX
, 1.0);
2669 CGContextFillRect(context
, enclosingCGRect
);
2671 CGContextRestoreGState(context
);
2677 labelColor
= MAC_WXCOLORREF( color
.GetPixel() );
2678 else if (list
->GetTextColour().Ok())
2679 labelColor
= MAC_WXCOLORREF( list
->GetTextColour().GetPixel() );
2683 backgroundColor
= MAC_WXCOLORREF( bgColor
.GetPixel() );
2684 CGContextSaveGState(context
);
2686 CGContextSetRGBFillColor(context
, (float)backgroundColor
.red
/ (float)USHRT_MAX
,
2687 (float)backgroundColor
.green
/ (float)USHRT_MAX
,
2688 (float)backgroundColor
.blue
/ (float)USHRT_MAX
, 1.0);
2689 CGContextFillRect(context
, enclosingCGRect
);
2691 CGContextRestoreGState(context
);
2695 calculateCGDrawingBounds(enclosingCGRect
, &iconCGRect
, &textCGRect
, (imgIndex
!= -1) );
2699 wxImageList
* imageList
= list
->GetImageList(wxIMAGE_LIST_SMALL
);
2700 if (imageList
&& imageList
->GetImageCount() > 0){
2701 wxBitmap bmp
= imageList
->GetBitmap(imgIndex
);
2702 IconRef icon
= bmp
.GetBitmapData()->GetIconRef();
2704 CGContextSaveGState(context
);
2705 CGContextTranslateCTM(context
, 0,iconCGRect
.origin
.y
+ CGRectGetMaxY(iconCGRect
));
2706 CGContextScaleCTM(context
,1.0f
,-1.0f
);
2707 PlotIconRefInContext(context
, &iconCGRect
, kAlignNone
,
2708 active
? kTransformNone
: kTransformDisabled
, NULL
,
2709 kPlotIconRefNormalFlags
, icon
);
2711 CGContextRestoreGState(context
);
2715 HIThemeTextHorizontalFlush hFlush
= kHIThemeTextHorizontalFlushLeft
;
2716 UInt16 fontID
= kThemeViewsFont
;
2720 if (font
.GetFamily() != wxFONTFAMILY_DEFAULT
)
2721 fontID
= font
.MacGetThemeFontID();
2723 // FIXME: replace these with CG or ATSUI calls so we can remove this #ifndef.
2725 ::TextSize( (short)(font
.MacGetFontSize()) ) ;
2726 ::TextFace( font
.MacGetFontStyle() ) ;
2731 list
->GetColumn(listColumn
, item
);
2732 if (item
.GetMask() & wxLIST_MASK_FORMAT
)
2734 if (item
.GetAlign() == wxLIST_FORMAT_LEFT
)
2735 hFlush
= kHIThemeTextHorizontalFlushLeft
;
2736 else if (item
.GetAlign() == wxLIST_FORMAT_CENTER
)
2737 hFlush
= kHIThemeTextHorizontalFlushCenter
;
2738 else if (item
.GetAlign() == wxLIST_FORMAT_RIGHT
)
2740 hFlush
= kHIThemeTextHorizontalFlushRight
;
2741 textCGRect
.origin
.x
-= kItemPadding
; // give a little extra paddding
2745 HIThemeTextInfo info
;
2746 info
.version
= kHIThemeTextInfoVersionZero
;
2747 info
.state
= active
? kThemeStateActive
: kThemeStateInactive
;
2748 info
.fontID
= fontID
;
2749 info
.horizontalFlushness
= hFlush
;
2750 info
.verticalFlushness
= kHIThemeTextVerticalFlushCenter
;
2751 info
.options
= kHIThemeTextBoxOptionNone
;
2752 info
.truncationPosition
= kHIThemeTextTruncationEnd
;
2753 info
.truncationMaxLines
= 1;
2755 CGContextSaveGState(context
);
2756 CGContextSetRGBFillColor (context
, (float)labelColor
.red
/ (float)USHRT_MAX
,
2757 (float)labelColor
.green
/ (float)USHRT_MAX
,
2758 (float)labelColor
.blue
/ (float)USHRT_MAX
, 1.0);
2760 HIThemeDrawTextBox(cfString
, &textCGRect
, &info
, context
, kHIThemeOrientationNormal
);
2762 CGContextRestoreGState(context
);
2764 if (savedState
!= NULL
)
2765 SetThemeDrawingState(savedState
, true);
2768 OSStatus
wxMacDataBrowserListCtrlControl::GetSetItemData(DataBrowserItemID itemID
,
2769 DataBrowserPropertyID property
,
2770 DataBrowserItemDataRef itemData
,
2771 Boolean changeValue
)
2775 short listColumn
= property
- kMinColumnId
;
2777 OSStatus err
= errDataBrowserPropertyNotSupported
;
2778 wxListCtrl
* list
= wxDynamicCast( GetPeer() , wxListCtrl
);
2779 wxMacListCtrlItem
* lcItem
;
2781 if (listColumn
>= 0)
2785 lcItem
= (wxMacListCtrlItem
*) itemID
;
2786 if (lcItem
&& lcItem
->HasColumnInfo(listColumn
)){
2787 wxListItem
* item
= lcItem
->GetColumnInfo(listColumn
);
2788 if (item
->GetMask() & wxLIST_MASK_TEXT
)
2789 text
= item
->GetText();
2790 if (item
->GetMask() & wxLIST_MASK_IMAGE
)
2791 imgIndex
= item
->GetImage();
2796 text
= list
->OnGetItemText( (long)itemID
-1, listColumn
);
2797 imgIndex
= list
->OnGetItemColumnImage( (long)itemID
-1, listColumn
);
2805 case kDataBrowserItemIsEditableProperty
:
2806 if ( list
&& list
->HasFlag( wxLC_EDIT_LABELS
) )
2808 verify_noerr(SetDataBrowserItemDataBooleanValue( itemData
, true ));
2813 if ( property
>= kMinColumnId
)
2815 wxMacCFStringHolder cfStr
;
2818 cfStr
.Assign( text
, wxLocale::GetSystemEncoding() );
2819 err
= ::SetDataBrowserItemDataText( itemData
, cfStr
);
2825 if ( imgIndex
!= -1 )
2827 wxImageList
* imageList
= list
->GetImageList(wxIMAGE_LIST_SMALL
);
2828 if (imageList
&& imageList
->GetImageCount() > 0){
2829 wxBitmap bmp
= imageList
->GetBitmap(imgIndex
);
2830 IconRef icon
= bmp
.GetBitmapData()->GetIconRef();
2831 ::SetDataBrowserItemDataIcon(itemData
, icon
);
2845 if ( property
>= kMinColumnId
)
2847 short listColumn
= property
- kMinColumnId
;
2849 // TODO probably send the 'end edit' from here, as we
2850 // can then deal with the veto
2852 verify_noerr( GetDataBrowserItemDataText( itemData
, &sr
) ) ;
2853 wxMacCFStringHolder
cfStr(sr
) ;;
2855 list
->SetItem( (long)itemData
-1 , listColumn
, cfStr
.AsString() ) ;
2859 lcItem
->SetColumnTextValue( listColumn
, cfStr
.AsString() );
2869 void wxMacDataBrowserListCtrlControl::ItemNotification(DataBrowserItemID itemID
,
2870 DataBrowserItemNotification message
,
2871 DataBrowserItemDataRef itemData
)
2873 // we want to depend on as little as possible to make sure tear-down of controls is safe
2874 if ( message
== kDataBrowserItemRemoved
)
2876 // make sure MacDelete does the proper teardown.
2879 else if ( message
== kDataBrowserItemAdded
)
2881 // we don't issue events on adding, the item is not really stored in the list yet, so we
2882 // avoid asserts by getting out now
2886 wxListCtrl
*list
= wxDynamicCast( GetPeer() , wxListCtrl
);
2889 bool trigger
= false;
2891 wxListEvent
event( wxEVT_COMMAND_LIST_ITEM_SELECTED
, list
->GetId() );
2892 bool isSingle
= (list
->GetWindowStyle() & wxLC_SINGLE_SEL
) != 0;
2894 event
.SetEventObject( list
);
2895 if ( !list
->IsVirtual() )
2897 DataBrowserTableViewRowIndex result
= 0;
2898 verify_noerr( GetItemRow( itemID
, &result
) ) ;
2899 event
.m_itemIndex
= result
;
2901 if (event
.m_itemIndex
>= 0)
2902 MacGetColumnInfo(event
.m_itemIndex
,0,event
.m_item
);
2906 event
.m_itemIndex
= (long)itemID
-1;
2911 case kDataBrowserItemDeselected
:
2912 event
.SetEventType(wxEVT_COMMAND_LIST_ITEM_DESELECTED
);
2914 trigger
= !IsSelectionSuppressed();
2917 case kDataBrowserItemSelected
:
2918 trigger
= !IsSelectionSuppressed();
2922 case kDataBrowserItemDoubleClicked
:
2923 event
.SetEventType( wxEVT_COMMAND_LIST_ITEM_ACTIVATED
);
2927 case kDataBrowserEditStarted
:
2928 // TODO : how to veto ?
2929 event
.SetEventType( wxEVT_COMMAND_LIST_BEGIN_LABEL_EDIT
) ;
2933 case kDataBrowserEditStopped
:
2934 // TODO probably trigger only upon the value store callback, because
2935 // here IIRC we cannot veto
2936 event
.SetEventType( wxEVT_COMMAND_LIST_END_LABEL_EDIT
) ;
2946 // direct notification is not always having the listbox GetSelection() having in synch with event
2947 wxPostEvent( list
->GetEventHandler(), event
);
2952 Boolean
wxMacDataBrowserListCtrlControl::CompareItems(DataBrowserItemID itemOneID
,
2953 DataBrowserItemID itemTwoID
,
2954 DataBrowserPropertyID sortProperty
)
2957 bool retval
= false;
2959 wxString otherItemText
;
2961 long otherItemOrder
;
2963 int colId
= sortProperty
- kMinColumnId
;
2965 wxListCtrl
* list
= wxDynamicCast( GetPeer() , wxListCtrl
);
2967 DataBrowserSortOrder sort
;
2968 verify_noerr(GetSortOrder(&sort
));
2974 wxMacListCtrlItem
* item
= (wxMacListCtrlItem
*)itemOneID
;
2975 wxMacListCtrlItem
* otherItem
= (wxMacListCtrlItem
*)itemTwoID
;
2977 itemOrder
= item
->GetOrder();
2978 otherItemOrder
= item
->GetOrder();
2980 wxListCtrlCompare func
= list
->GetCompareFunc();
2985 if (item
&& item
->HasColumnInfo(0))
2986 item1
= item
->GetColumnInfo(0)->GetData();
2987 if (otherItem
&& otherItem
->HasColumnInfo(0))
2988 item2
= otherItem
->GetColumnInfo(0)->GetData();
2990 if (item1
> -1 && item2
> -1)
2992 int result
= func(item1
, item2
, list
->GetCompareFuncData());
2993 if (sort
== kDataBrowserOrderIncreasing
)
3000 // we can't use the native control's sorting abilities, so just
3002 return itemOrder
< otherItemOrder
;
3007 long itemNum
= (long)itemOneID
;
3008 long otherItemNum
= (long)itemTwoID
;
3009 itemText
= list
->OnGetItemText( itemNum
-1, colId
);
3010 otherItemText
= list
->OnGetItemText( otherItemNum
-1, colId
);
3012 // virtual listctrls don't support sorting
3013 return itemNum
< otherItemNum
;
3017 // fallback for undefined cases
3018 retval
= itemOneID
< itemTwoID
;
3024 wxMacDataBrowserListCtrlControl::~wxMacDataBrowserListCtrlControl()
3028 void wxMacDataBrowserListCtrlControl::MacSetColumnInfo( unsigned int row
, unsigned int column
, wxListItem
* item
)
3030 wxMacDataItem
* dataItem
= GetItemFromLine(row
);
3031 wxASSERT_MSG( dataItem
, _T("could not obtain wxMacDataItem for row in MacSetColumnInfo. Is row a valid wxListCtrl row?") );
3034 wxMacListCtrlItem
* listItem
= wx_static_cast(wxMacListCtrlItem
*,dataItem
);
3035 bool hasInfo
= listItem
->HasColumnInfo( column
);
3036 listItem
->SetColumnInfo( column
, item
);
3037 listItem
->SetOrder(row
);
3038 UpdateState(dataItem
, item
);
3040 wxListCtrl
* list
= wxDynamicCast( GetPeer() , wxListCtrl
);
3042 // NB: When this call was made before a control was completely shown, it would
3043 // update the item prematurely (i.e. no text would be listed) and, on show,
3044 // only the sorted column would be refreshed, meaning only first column text labels
3045 // would be shown. Making sure not to update items until the control is visible
3046 // seems to fix this issue.
3047 if (hasInfo
&& list
->IsShown())
3048 UpdateItem( wxMacDataBrowserRootContainer
, listItem
, kMinColumnId
+ column
);
3052 // apply changes that need to happen immediately, rather than when the
3053 // databrowser control fires a callback.
3054 void wxMacDataBrowserListCtrlControl::UpdateState(wxMacDataItem
* dataItem
, wxListItem
* listItem
)
3056 bool isSelected
= IsItemSelected( dataItem
);
3057 bool isSelectedState
= (listItem
->GetState() == wxLIST_STATE_SELECTED
);
3059 // toggle the selection state if wxListInfo state and actual state don't match.
3060 if ( isSelected
!= isSelectedState
)
3062 DataBrowserSetOption options
= kDataBrowserItemsAdd
;
3063 if (!isSelectedState
)
3064 options
= kDataBrowserItemsRemove
;
3065 SetSelectedItem(dataItem
, options
);
3067 // TODO: Set column width if item width > than current column width
3070 void wxMacDataBrowserListCtrlControl::MacGetColumnInfo( unsigned int row
, unsigned int column
, wxListItem
& item
)
3072 wxMacDataItem
* dataItem
= GetItemFromLine(row
);
3073 wxASSERT_MSG( dataItem
, _T("could not obtain wxMacDataItem in MacGetColumnInfo. Is row a valid wxListCtrl row?") );
3074 // CS should this guard against dataItem = 0 ? , as item is not a pointer if (item) is not appropriate
3077 wxMacListCtrlItem
* listItem
=wx_static_cast(wxMacListCtrlItem
*,dataItem
);
3079 if (!listItem
->HasColumnInfo( column
))
3082 wxListItem
* oldItem
= listItem
->GetColumnInfo( column
);
3086 long mask
= item
.GetMask();
3088 // by default, get everything for backwards compatibility
3091 if ( mask
& wxLIST_MASK_TEXT
)
3092 item
.SetText(oldItem
->GetText());
3093 if ( mask
& wxLIST_MASK_IMAGE
)
3094 item
.SetImage(oldItem
->GetImage());
3095 if ( mask
& wxLIST_MASK_DATA
)
3096 item
.SetData(oldItem
->GetData());
3097 if ( mask
& wxLIST_MASK_STATE
)
3098 item
.SetState(oldItem
->GetState());
3099 if ( mask
& wxLIST_MASK_WIDTH
)
3100 item
.SetWidth(oldItem
->GetWidth());
3101 if ( mask
& wxLIST_MASK_FORMAT
)
3102 item
.SetAlign(oldItem
->GetAlign());
3104 item
.SetTextColour(oldItem
->GetTextColour());
3105 item
.SetBackgroundColour(oldItem
->GetBackgroundColour());
3106 item
.SetFont(oldItem
->GetFont());
3111 void wxMacDataBrowserListCtrlControl::MacInsertItem( unsigned int n
, wxListItem
* item
)
3113 wxMacDataItemBrowserControl::MacInsert(n
, item
->GetText());
3114 MacSetColumnInfo(n
, 0, item
);
3117 wxMacDataItem
* wxMacDataBrowserListCtrlControl::CreateItem()
3119 return new wxMacListCtrlItem();
3122 wxMacListCtrlItem::wxMacListCtrlItem()
3124 m_rowItems
= wxListItemList();
3127 int wxMacListCtrlItem::GetColumnImageValue( unsigned int column
)
3129 if ( HasColumnInfo(column
) )
3130 return GetColumnInfo(column
)->GetImage();
3135 void wxMacListCtrlItem::SetColumnImageValue( unsigned int column
, int imageIndex
)
3137 if ( HasColumnInfo(column
) )
3138 GetColumnInfo(column
)->SetImage(imageIndex
);
3141 wxString
wxMacListCtrlItem::GetColumnTextValue( unsigned int column
)
3146 if ( HasColumnInfo(column
) )
3147 return GetColumnInfo(column
)->GetText();
3149 return wxEmptyString
;
3152 void wxMacListCtrlItem::SetColumnTextValue( unsigned int column
, const wxString
& text
)
3154 if ( HasColumnInfo(column
) )
3155 GetColumnInfo(column
)->SetText(text
);
3157 // for compatibility with superclass APIs
3162 wxListItem
* wxMacListCtrlItem::GetColumnInfo( unsigned int column
)
3164 wxASSERT_MSG( HasColumnInfo(column
), _T("invalid column index in wxMacListCtrlItem") );
3165 return m_rowItems
[column
];
3168 bool wxMacListCtrlItem::HasColumnInfo( unsigned int column
)
3170 return !(m_rowItems
.find( column
) == m_rowItems
.end());
3173 void wxMacListCtrlItem::SetColumnInfo( unsigned int column
, wxListItem
* item
)
3176 if ( !HasColumnInfo(column
) )
3178 wxListItem
* listItem
= new wxListItem(*item
);
3179 m_rowItems
[column
] = listItem
;
3183 wxListItem
* listItem
= GetColumnInfo( column
);
3184 long mask
= item
->GetMask();
3185 if (mask
& wxLIST_MASK_TEXT
)
3186 listItem
->SetText(item
->GetText());
3187 if (mask
& wxLIST_MASK_DATA
)
3188 listItem
->SetData(item
->GetData());
3189 if (mask
& wxLIST_MASK_IMAGE
)
3190 listItem
->SetImage(item
->GetImage());
3191 if (mask
& wxLIST_MASK_STATE
)
3192 listItem
->SetState(item
->GetState());
3193 if (mask
& wxLIST_MASK_FORMAT
)
3194 listItem
->SetAlign(item
->GetAlign());
3195 if (mask
& wxLIST_MASK_WIDTH
)
3196 listItem
->SetWidth(item
->GetWidth());
3198 if ( item
->HasAttributes() )
3200 if ( listItem
->HasAttributes() )
3201 listItem
->GetAttributes()->AssignFrom(*item
->GetAttributes());
3204 listItem
->SetTextColour(item
->GetTextColour());
3205 listItem
->SetBackgroundColour(item
->GetBackgroundColour());
3206 listItem
->SetFont(item
->GetFont());
3212 #endif // wxUSE_LISTCTRL