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 #define wxMAC_ALWAYS_USE_GENERIC_LISTCTRL wxT("mac.listctrl.always_use_generic")
45 #if wxUSE_EXTENDED_RTTI
46 WX_DEFINE_FLAGS( wxListCtrlStyle
)
48 wxBEGIN_FLAGS( wxListCtrlStyle
)
49 // new style border flags, we put them first to
50 // use them for streaming out
51 wxFLAGS_MEMBER(wxBORDER_SIMPLE
)
52 wxFLAGS_MEMBER(wxBORDER_SUNKEN
)
53 wxFLAGS_MEMBER(wxBORDER_DOUBLE
)
54 wxFLAGS_MEMBER(wxBORDER_RAISED
)
55 wxFLAGS_MEMBER(wxBORDER_STATIC
)
56 wxFLAGS_MEMBER(wxBORDER_NONE
)
58 // old style border flags
59 wxFLAGS_MEMBER(wxSIMPLE_BORDER
)
60 wxFLAGS_MEMBER(wxSUNKEN_BORDER
)
61 wxFLAGS_MEMBER(wxDOUBLE_BORDER
)
62 wxFLAGS_MEMBER(wxRAISED_BORDER
)
63 wxFLAGS_MEMBER(wxSTATIC_BORDER
)
64 wxFLAGS_MEMBER(wxBORDER
)
66 // standard window styles
67 wxFLAGS_MEMBER(wxTAB_TRAVERSAL
)
68 wxFLAGS_MEMBER(wxCLIP_CHILDREN
)
69 wxFLAGS_MEMBER(wxTRANSPARENT_WINDOW
)
70 wxFLAGS_MEMBER(wxWANTS_CHARS
)
71 wxFLAGS_MEMBER(wxFULL_REPAINT_ON_RESIZE
)
72 wxFLAGS_MEMBER(wxALWAYS_SHOW_SB
)
73 wxFLAGS_MEMBER(wxVSCROLL
)
74 wxFLAGS_MEMBER(wxHSCROLL
)
76 wxFLAGS_MEMBER(wxLC_LIST
)
77 wxFLAGS_MEMBER(wxLC_REPORT
)
78 wxFLAGS_MEMBER(wxLC_ICON
)
79 wxFLAGS_MEMBER(wxLC_SMALL_ICON
)
80 wxFLAGS_MEMBER(wxLC_ALIGN_TOP
)
81 wxFLAGS_MEMBER(wxLC_ALIGN_LEFT
)
82 wxFLAGS_MEMBER(wxLC_AUTOARRANGE
)
83 wxFLAGS_MEMBER(wxLC_USER_TEXT
)
84 wxFLAGS_MEMBER(wxLC_EDIT_LABELS
)
85 wxFLAGS_MEMBER(wxLC_NO_HEADER
)
86 wxFLAGS_MEMBER(wxLC_SINGLE_SEL
)
87 wxFLAGS_MEMBER(wxLC_SORT_ASCENDING
)
88 wxFLAGS_MEMBER(wxLC_SORT_DESCENDING
)
89 wxFLAGS_MEMBER(wxLC_VIRTUAL
)
91 wxEND_FLAGS( wxListCtrlStyle
)
93 IMPLEMENT_DYNAMIC_CLASS_XTI(wxListCtrl
, wxControl
,"wx/listctrl.h")
95 wxBEGIN_PROPERTIES_TABLE(wxListCtrl
)
96 wxEVENT_PROPERTY( TextUpdated
, wxEVT_COMMAND_TEXT_UPDATED
, wxCommandEvent
)
98 wxPROPERTY_FLAGS( WindowStyle
, wxListCtrlStyle
, long , SetWindowStyleFlag
, GetWindowStyleFlag
, EMPTY_MACROVALUE
, 0 /*flags*/ , wxT("Helpstring") , wxT("group")) // style
99 wxEND_PROPERTIES_TABLE()
101 wxBEGIN_HANDLERS_TABLE(wxListCtrl
)
102 wxEND_HANDLERS_TABLE()
104 wxCONSTRUCTOR_5( wxListCtrl
, wxWindow
* , Parent
, wxWindowID
, Id
, wxPoint
, Position
, wxSize
, Size
, long , WindowStyle
)
107 TODO : Expose more information of a list's layout etc. via appropriate objects (à la NotebookPageInfo)
110 IMPLEMENT_DYNAMIC_CLASS(wxListCtrl
, wxControl
)
113 IMPLEMENT_DYNAMIC_CLASS(wxListView
, wxListCtrl
)
114 IMPLEMENT_DYNAMIC_CLASS(wxListItem
, wxObject
)
116 IMPLEMENT_DYNAMIC_CLASS(wxListEvent
, wxNotifyEvent
)
118 WX_DECLARE_HASH_MAP( int, wxListItem
*, wxIntegerHash
, wxIntegerEqual
, wxListItemList
);
120 #include "wx/listimpl.cpp"
121 WX_DEFINE_LIST(wxColumnList
)
123 // so we can check for column clicks
124 static const EventTypeSpec eventList
[] =
126 { kEventClassControl
, kEventControlHit
},
127 { kEventClassControl
, kEventControlDraw
}
130 static pascal OSStatus
wxMacListCtrlEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
132 OSStatus result
= eventNotHandledErr
;
134 wxMacCarbonEvent
cEvent( event
) ;
136 ControlRef controlRef
;
137 cEvent
.GetParameter( kEventParamDirectObject
, &controlRef
) ;
139 wxListCtrl
*window
= (wxListCtrl
*) data
;
140 wxListEvent
le( wxEVT_COMMAND_LIST_COL_CLICK
, window
->GetId() );
141 le
.SetEventObject( window
);
143 switch ( GetEventKind( event
) )
145 // check if the column was clicked on and fire an event if so
146 case kEventControlHit
:
148 ControlPartCode result
= cEvent
.GetParameter
<ControlPartCode
>(kEventParamControlPart
, typeControlPartCode
) ;
149 if (result
== kControlButtonPart
){
150 DataBrowserPropertyID col
;
151 GetDataBrowserSortProperty(controlRef
, &col
);
152 int column
= col
- kMinColumnId
;
154 // FIXME: we can't use the sort property for virtual listctrls
155 // so we need to find a better way to determine which column was clicked...
156 if (!window
->IsVirtual())
157 window
->GetEventHandler()->ProcessEvent( le
);
159 result
= CallNextEventHandler(handler
, event
);
162 case kEventControlDraw
:
164 CGContextRef context
= cEvent
.GetParameter
<CGContextRef
>(kEventParamCGContextRef
, typeCGContextRef
) ;
165 window
->MacSetDrawingContext(context
);
166 result
= CallNextEventHandler(handler
, event
);
167 window
->MacSetDrawingContext(NULL
);
178 DEFINE_ONE_SHOT_HANDLER_GETTER( wxMacListCtrlEventHandler
)
180 class wxMacListCtrlItem
: public wxMacListBoxItem
185 virtual void Notification(wxMacDataItemBrowserControl
*owner
,
186 DataBrowserItemNotification message
,
187 DataBrowserItemDataRef itemData
) const;
189 virtual void SetColumnInfo( unsigned int column
, wxListItem
* item
);
190 virtual wxListItem
* GetColumnInfo( unsigned int column
);
191 virtual bool HasColumnInfo( unsigned int column
);
193 virtual void SetColumnTextValue( unsigned int column
, const wxString
& text
);
194 virtual wxString
GetColumnTextValue( unsigned int column
);
196 virtual int GetColumnImageValue( unsigned int column
);
197 virtual void SetColumnImageValue( unsigned int column
, int imageIndex
);
199 virtual ~wxMacListCtrlItem();
201 wxListItemList m_rowItems
;
204 DataBrowserDrawItemUPP gDataBrowserDrawItemUPP
= NULL
;
205 //DataBrowserEditItemUPP gDataBrowserEditItemUPP = NULL;
206 DataBrowserHitTestUPP gDataBrowserHitTestUPP
= NULL
;
208 // TODO: Make a better name!!
209 class wxMacDataBrowserListCtrlControl
: public wxMacDataItemBrowserControl
212 wxMacDataBrowserListCtrlControl( wxWindow
*peer
, const wxPoint
& pos
, const wxSize
& size
, long style
);
213 wxMacDataBrowserListCtrlControl() {}
214 virtual ~wxMacDataBrowserListCtrlControl();
216 // create a list item (can be a subclass of wxMacListBoxItem)
218 virtual wxMacDataItem
* CreateItem();
220 virtual void MacInsertItem( unsigned int n
, wxListItem
* item
);
221 virtual void MacSetColumnInfo( unsigned int row
, unsigned int column
, wxListItem
* item
);
222 virtual void MacGetColumnInfo( unsigned int row
, unsigned int column
, wxListItem
& item
);
223 virtual void UpdateState(wxMacDataItem
* dataItem
, wxListItem
* item
);
226 // we need to override to provide specialized handling for virtual wxListCtrls
227 virtual OSStatus
GetSetItemData(DataBrowserItemID itemID
,
228 DataBrowserPropertyID property
,
229 DataBrowserItemDataRef itemData
,
230 Boolean changeValue
);
232 virtual void ItemNotification(
233 DataBrowserItemID itemID
,
234 DataBrowserItemNotification message
,
235 DataBrowserItemDataRef itemData
);
237 virtual Boolean
CompareItems(DataBrowserItemID itemOneID
,
238 DataBrowserItemID itemTwoID
,
239 DataBrowserPropertyID sortProperty
);
241 static pascal void DataBrowserDrawItemProc(ControlRef browser
,
242 DataBrowserItemID item
,
243 DataBrowserPropertyID property
,
244 DataBrowserItemState itemState
,
247 Boolean colorDevice
);
249 virtual void DrawItem(DataBrowserItemID itemID
,
250 DataBrowserPropertyID property
,
251 DataBrowserItemState itemState
,
252 const Rect
*itemRect
,
254 Boolean colorDevice
);
256 static pascal Boolean
DataBrowserEditTextProc(ControlRef browser
,
257 DataBrowserItemID item
,
258 DataBrowserPropertyID property
,
259 CFStringRef theString
,
260 Rect
*maxEditTextRect
,
261 Boolean
*shrinkToFit
);
263 static pascal Boolean
DataBrowserHitTestProc(ControlRef browser
,
264 DataBrowserItemID itemID
,
265 DataBrowserPropertyID property
,
267 const Rect
*mouseRect
) { return true; }
269 virtual bool ConfirmEditText(DataBrowserItemID item
,
270 DataBrowserPropertyID property
,
271 CFStringRef theString
,
272 Rect
*maxEditTextRect
,
273 Boolean
*shrinkToFit
);
277 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_RIGHT_DOWN(wxListCtrl::OnRightDown
)
511 EVT_CHAR(wxListCtrl::OnChar
)
514 // ============================================================================
516 // ============================================================================
518 wxMacListControl
* wxListCtrl::GetPeer() const
520 wxMacDataBrowserListCtrlControl
*lb
= wxDynamicCast(m_peer
,wxMacDataBrowserListCtrlControl
);
521 return lb
? wx_static_cast(wxMacListControl
*,lb
) : 0 ;
524 // ----------------------------------------------------------------------------
525 // wxListCtrl construction
526 // ----------------------------------------------------------------------------
528 void wxListCtrl::Init()
530 m_imageListNormal
= NULL
;
531 m_imageListSmall
= NULL
;
532 m_imageListState
= NULL
;
534 // keep track of if we created our own image lists, or if they were assigned
536 m_ownsImageListNormal
= m_ownsImageListSmall
= m_ownsImageListState
= false;
540 m_genericImpl
= NULL
;
542 m_compareFunc
= NULL
;
543 m_compareFuncData
= 0;
544 m_colsInfo
= wxColumnList();
545 m_textColor
= wxNullColour
;
546 m_bgColor
= wxNullColour
;
547 m_textctrlWrapper
= NULL
;
549 m_renameTimer
= new wxListCtrlRenameTimer( this );
552 class wxGenericListCtrlHook
: public wxGenericListCtrl
555 wxGenericListCtrlHook(wxListCtrl
* parent
,
560 const wxValidator
& validator
,
561 const wxString
& name
)
562 : wxGenericListCtrl(parent
, id
, pos
, size
, style
, validator
, name
),
563 m_nativeListCtrl(parent
)
568 virtual wxListItemAttr
* OnGetItemAttr(long item
) const
570 return m_nativeListCtrl
->OnGetItemAttr(item
);
573 virtual int OnGetItemImage(long item
) const
575 return m_nativeListCtrl
->OnGetItemImage(item
);
578 virtual int OnGetItemColumnImage(long item
, long column
) const
580 return m_nativeListCtrl
->OnGetItemColumnImage(item
, column
);
583 virtual wxString
OnGetItemText(long item
, long column
) const
585 return m_nativeListCtrl
->OnGetItemText(item
, column
);
588 wxListCtrl
* m_nativeListCtrl
;
592 void wxListCtrl::OnLeftDown(wxMouseEvent
& event
)
594 if ( m_textctrlWrapper
)
597 m_textctrlWrapper
->AcceptChangesAndFinish();
601 long current
= HitTest(event
.GetPosition(), hitResult
);
602 if ((current
== m_current
) &&
603 (hitResult
== wxLIST_HITTEST_ONITEM
) &&
604 HasFlag(wxLC_EDIT_LABELS
) )
606 m_renameTimer
->Start( 100, true );
615 void wxListCtrl::OnDblClick(wxMouseEvent
& event
)
621 #if wxABI_VERSION >= 20801
622 void wxListCtrl::OnRightDown(wxMouseEvent
& event
)
624 wxListEvent
le( wxEVT_COMMAND_LIST_ITEM_RIGHT_CLICK
, GetId() );
625 le
.SetEventObject(this);
626 le
.m_pointDrag
= event
.GetPosition();
630 long item
= HitTest(event
.GetPosition(), flags
);
631 if (flags
& wxLIST_HITTEST_ONITEM
)
633 le
.m_itemIndex
= item
;
637 le
.m_item
.m_itemId
= item
;
640 GetEventHandler()->ProcessEvent(le
);
646 void wxListCtrl::OnChar(wxKeyEvent
& event
)
648 wxListEvent
le( wxEVT_COMMAND_LIST_KEY_DOWN
, GetId() );
649 le
.SetEventObject(this);
650 le
.m_code
= event
.GetKeyCode();
655 le
.m_itemIndex
= m_current
;
658 le
.m_item
.m_itemId
= m_current
;
661 GetEventHandler()->ProcessEvent(le
);
666 bool wxListCtrl::Create(wxWindow
*parent
,
671 const wxValidator
& validator
,
672 const wxString
& name
)
675 // for now, we'll always use the generic list control for ICON and LIST views,
676 // because they dynamically change the number of columns on resize.
677 // Also, allow the user to set it to use the list ctrl as well.
678 if ( (wxSystemOptions::HasOption( wxMAC_ALWAYS_USE_GENERIC_LISTCTRL
)
679 && (wxSystemOptions::GetOptionInt( wxMAC_ALWAYS_USE_GENERIC_LISTCTRL
) == 1)) ||
680 (style
& wxLC_ICON
) || (style
& wxLC_SMALL_ICON
) || (style
& wxLC_LIST
) )
682 m_macIsUserPane
= true;
684 long paneStyle
= style
;
685 paneStyle
&= ~wxSIMPLE_BORDER
;
686 paneStyle
&= ~wxDOUBLE_BORDER
;
687 paneStyle
&= ~wxSUNKEN_BORDER
;
688 paneStyle
&= ~wxRAISED_BORDER
;
689 paneStyle
&= ~wxSTATIC_BORDER
;
690 if ( !wxWindow::Create(parent
, id
, pos
, size
, paneStyle
| wxNO_BORDER
, name
) )
693 // since the generic control is a child, make sure we position it at 0, 0
694 m_genericImpl
= new wxGenericListCtrlHook(this, id
, wxPoint(0, 0), size
, style
, validator
, name
);
695 m_genericImpl
->PushEventHandler( new wxMacListCtrlEventDelegate( this, GetId() ) );
701 m_macIsUserPane
= false;
703 if ( !wxWindow::Create(parent
, id
, pos
, size
, style
, name
) )
705 m_dbImpl
= new wxMacDataBrowserListCtrlControl( this, pos
, size
, style
);
708 MacPostControlCreate( pos
, size
);
710 InstallControlEventHandler( m_peer
->GetControlRef() , GetwxMacListCtrlEventHandlerUPP(),
711 GetEventTypeCount(eventList
), eventList
, this,
712 (EventHandlerRef
*)&m_macListCtrlEventHandler
);
718 wxListCtrl::~wxListCtrl()
722 m_genericImpl
->PopEventHandler(/* deleteHandler = */ true);
725 if (m_ownsImageListNormal
)
726 delete m_imageListNormal
;
727 if (m_ownsImageListSmall
)
728 delete m_imageListSmall
;
729 if (m_ownsImageListState
)
730 delete m_imageListState
;
732 delete m_renameTimer
;
735 // ----------------------------------------------------------------------------
736 // set/get/change style
737 // ----------------------------------------------------------------------------
739 // Add or remove a single window style
740 void wxListCtrl::SetSingleStyle(long style
, bool add
)
742 long flag
= GetWindowStyleFlag();
744 // Get rid of conflicting styles
747 if ( style
& wxLC_MASK_TYPE
)
748 flag
= flag
& ~wxLC_MASK_TYPE
;
749 if ( style
& wxLC_MASK_ALIGN
)
750 flag
= flag
& ~wxLC_MASK_ALIGN
;
751 if ( style
& wxLC_MASK_SORT
)
752 flag
= flag
& ~wxLC_MASK_SORT
;
760 SetWindowStyleFlag(flag
);
763 // Set the whole window style
764 void wxListCtrl::SetWindowStyleFlag(long flag
)
766 if ( flag
!= m_windowStyle
)
768 m_windowStyle
= flag
;
772 m_genericImpl
->SetWindowStyleFlag(flag
);
779 void wxListCtrl::DoSetSize( int x
, int y
, int width
, int height
, int sizeFlags
)
781 wxControl::DoSetSize(x
, y
, width
, height
, sizeFlags
);
784 m_genericImpl
->SetSize(0, 0, width
, height
, sizeFlags
);
786 // determine if we need a horizontal scrollbar, and add it if so
790 for (int column
= 0; column
< GetColumnCount(); column
++)
792 totalWidth
+= m_dbImpl
->GetColumnWidth( column
);
795 Boolean vertScrollBar
;
796 GetDataBrowserHasScrollBars( m_dbImpl
->GetControlRef(), NULL
, &vertScrollBar
);
797 if (totalWidth
> width
)
798 SetDataBrowserHasScrollBars( m_dbImpl
->GetControlRef(), true, vertScrollBar
);
800 SetDataBrowserHasScrollBars( m_dbImpl
->GetControlRef(), false, vertScrollBar
);
804 wxSize
wxListCtrl::DoGetBestSize() const
806 return wxWindow::DoGetBestSize();
809 bool wxListCtrl::SetFont(const wxFont
& font
)
812 rv
= wxControl::SetFont(font
);
814 rv
= m_genericImpl
->SetFont(font
);
818 bool wxListCtrl::SetForegroundColour(const wxColour
& colour
)
822 rv
= m_genericImpl
->SetForegroundColour(colour
);
824 SetTextColour(colour
);
828 bool wxListCtrl::SetBackgroundColour(const wxColour
& colour
)
832 rv
= m_genericImpl
->SetBackgroundColour(colour
);
838 wxColour
wxListCtrl::GetBackgroundColour()
841 return m_genericImpl
->GetBackgroundColour();
848 // ----------------------------------------------------------------------------
850 // ----------------------------------------------------------------------------
852 // Gets information about this column
853 bool wxListCtrl::GetColumn(int col
, wxListItem
& item
) const
856 return m_genericImpl
->GetColumn(col
, item
);
862 wxColumnList::compatibility_iterator node
= m_colsInfo
.Item( col
);
863 wxASSERT_MSG( node
, _T("invalid column index in wxMacListCtrlItem") );
864 wxListItem
* column
= node
->GetData();
866 long mask
= column
->GetMask();
867 if (mask
& wxLIST_MASK_TEXT
)
868 item
.SetText(column
->GetText());
869 if (mask
& wxLIST_MASK_DATA
)
870 item
.SetData(column
->GetData());
871 if (mask
& wxLIST_MASK_IMAGE
)
872 item
.SetImage(column
->GetImage());
873 if (mask
& wxLIST_MASK_STATE
)
874 item
.SetState(column
->GetState());
875 if (mask
& wxLIST_MASK_FORMAT
)
876 item
.SetAlign(column
->GetAlign());
877 if (mask
& wxLIST_MASK_WIDTH
)
878 item
.SetWidth(column
->GetWidth());
884 // Sets information about this column
885 bool wxListCtrl::SetColumn(int col
, wxListItem
& item
)
888 return m_genericImpl
->SetColumn(col
, item
);
892 long mask
= item
.GetMask();
893 if ( col
>= (int)m_colsInfo
.GetCount() )
895 wxListItem
* listItem
= new wxListItem(item
);
896 m_colsInfo
.Append( listItem
);
901 GetColumn( col
, listItem
);
903 if (mask
& wxLIST_MASK_TEXT
)
904 listItem
.SetText(item
.GetText());
905 if (mask
& wxLIST_MASK_DATA
)
906 listItem
.SetData(item
.GetData());
907 if (mask
& wxLIST_MASK_IMAGE
)
908 listItem
.SetImage(item
.GetImage());
909 if (mask
& wxLIST_MASK_STATE
)
910 listItem
.SetState(item
.GetState());
911 if (mask
& wxLIST_MASK_FORMAT
)
912 listItem
.SetAlign(item
.GetAlign());
913 if (mask
& wxLIST_MASK_WIDTH
)
914 listItem
.SetWidth(item
.GetWidth());
917 // change the appearance in the databrowser.
918 DataBrowserListViewHeaderDesc columnDesc
;
919 columnDesc
.version
=kDataBrowserListViewLatestHeaderDesc
;
920 verify_noerr( m_dbImpl
->GetHeaderDesc( kMinColumnId
+ col
, &columnDesc
) );
923 if (item.GetMask() & wxLIST_MASK_TEXT)
927 enc = m_font.GetEncoding();
929 enc = wxLocale::GetSystemEncoding();
930 wxMacCFStringHolder cfTitle;
931 cfTitle.Assign( item.GetText() , enc );
932 if(columnDesc.titleString)
933 CFRelease(columnDesc.titleString);
934 columnDesc.titleString = cfTitle;
938 if (item
.GetMask() & wxLIST_MASK_IMAGE
&& item
.GetImage() != -1 )
940 columnDesc
.btnContentInfo
.contentType
= kControlContentIconRef
;
941 wxImageList
* imageList
= GetImageList(wxIMAGE_LIST_SMALL
);
942 if (imageList
&& imageList
->GetImageCount() > 0 )
944 wxBitmap bmp
= imageList
->GetBitmap( item
.GetImage() );
945 IconRef icon
= bmp
.GetBitmapData()->GetIconRef();
946 columnDesc
.btnContentInfo
.u
.iconRef
= icon
;
950 verify_noerr( m_dbImpl
->SetHeaderDesc( kMinColumnId
+ col
, &columnDesc
) );
956 int wxListCtrl::GetColumnCount() const
959 return m_genericImpl
->GetColumnCount();
964 m_dbImpl
->GetColumnCount(&count
);
971 // Gets the column width
972 int wxListCtrl::GetColumnWidth(int col
) const
975 return m_genericImpl
->GetColumnWidth(col
);
979 return m_dbImpl
->GetColumnWidth(col
);
985 // Sets the column width
986 bool wxListCtrl::SetColumnWidth(int col
, int width
)
989 return m_genericImpl
->SetColumnWidth(col
, width
);
994 if (width
== wxLIST_AUTOSIZE
|| width
== wxLIST_AUTOSIZE_USEHEADER
)
999 for (int column
= 0; column
< GetColumnCount(); column
++)
1002 GetColumn(col
, colInfo
);
1004 colInfo
.SetWidth(width
);
1005 SetColumn(col
, colInfo
);
1007 m_dbImpl
->SetColumnWidth(col
, mywidth
);
1013 GetColumn(col
, colInfo
);
1015 colInfo
.SetWidth(width
);
1016 SetColumn(col
, colInfo
);
1017 m_dbImpl
->SetColumnWidth(col
, mywidth
);
1025 // Gets the number of items that can fit vertically in the
1026 // visible area of the list control (list or report view)
1027 // or the total number of items in the list control (icon
1028 // or small icon view)
1029 int wxListCtrl::GetCountPerPage() const
1032 return m_genericImpl
->GetCountPerPage();
1041 // Gets the edit control for editing labels.
1042 wxTextCtrl
* wxListCtrl::GetEditControl() const
1045 return m_genericImpl
->GetEditControl();
1050 // Gets information about the item
1051 bool wxListCtrl::GetItem(wxListItem
& info
) const
1054 return m_genericImpl
->GetItem(info
);
1059 m_dbImpl
->MacGetColumnInfo(info
.m_itemId
, info
.m_col
, info
);
1062 info
.SetText( OnGetItemText(info
.m_itemId
, info
.m_col
) );
1063 info
.SetImage( OnGetItemColumnImage(info
.m_itemId
, info
.m_col
) );
1064 if (info
.GetMask() & wxLIST_MASK_STATE
)
1066 if (IsDataBrowserItemSelected( m_dbImpl
->GetControlRef(), info
.m_itemId
+1 ))
1067 info
.SetState(info
.GetState() | wxLIST_STATE_SELECTED
);
1070 wxListItemAttr
* attrs
= OnGetItemAttr( info
.m_itemId
);
1073 info
.SetFont( attrs
->GetFont() );
1074 info
.SetBackgroundColour( attrs
->GetBackgroundColour() );
1075 info
.SetTextColour( attrs
->GetTextColour() );
1079 bool success
= true;
1083 // Sets information about the item
1084 bool wxListCtrl::SetItem(wxListItem
& info
)
1087 return m_genericImpl
->SetItem(info
);
1090 m_dbImpl
->MacSetColumnInfo( info
.m_itemId
, info
.m_col
, &info
);
1095 long wxListCtrl::SetItem(long index
, int col
, const wxString
& label
, int imageId
)
1098 return m_genericImpl
->SetItem(index
, col
, label
, imageId
);
1101 info
.m_text
= label
;
1102 info
.m_mask
= wxLIST_MASK_TEXT
;
1103 info
.m_itemId
= index
;
1107 info
.m_image
= imageId
;
1108 info
.m_mask
|= wxLIST_MASK_IMAGE
;
1110 return SetItem(info
);
1114 // Gets the item state
1115 int wxListCtrl::GetItemState(long item
, long stateMask
) const
1118 return m_genericImpl
->GetItemState(item
, stateMask
);
1122 if ( HasFlag(wxLC_VIRTUAL
) )
1124 if (stateMask
== wxLIST_STATE_SELECTED
)
1126 if (IsDataBrowserItemSelected( m_dbImpl
->GetControlRef(), item
+1 ))
1127 return wxLIST_STATE_SELECTED
;
1136 info
.m_mask
= wxLIST_MASK_STATE
;
1137 info
.m_stateMask
= stateMask
;
1138 info
.m_itemId
= item
;
1143 return info
.m_state
;
1150 // Sets the item state
1151 bool wxListCtrl::SetItemState(long item
, long state
, long stateMask
)
1154 return m_genericImpl
->SetItemState(item
, state
, stateMask
);
1158 DataBrowserSetOption option
= kDataBrowserItemsAdd
;
1159 if ( stateMask
== wxLIST_STATE_SELECTED
&& state
== 0 )
1160 option
= kDataBrowserItemsRemove
;
1164 if ( HasFlag(wxLC_VIRTUAL
) )
1166 wxMacDataItemBrowserSelectionSuppressor
suppressor(m_dbImpl
);
1167 m_dbImpl
->SetSelectedAllItems(option
);
1171 for(int i
= 0; i
< GetItemCount();i
++)
1175 info
.m_mask
= wxLIST_MASK_STATE
;
1176 info
.m_stateMask
= stateMask
;
1177 info
.m_state
= state
;
1184 if ( HasFlag(wxLC_VIRTUAL
) )
1186 long itemID
= item
+1;
1187 SetDataBrowserSelectedItems(m_dbImpl
->GetControlRef(), 1, (DataBrowserItemID
*)&itemID
, option
);
1192 info
.m_itemId
= item
;
1193 info
.m_mask
= wxLIST_MASK_STATE
;
1194 info
.m_stateMask
= stateMask
;
1195 info
.m_state
= state
;
1196 return SetItem(info
);
1203 // Sets the item image
1204 bool wxListCtrl::SetItemImage(long item
, int image
, int WXUNUSED(selImage
))
1206 return SetItemColumnImage(item
, 0, image
);
1209 // Sets the item image
1210 bool wxListCtrl::SetItemColumnImage(long item
, long column
, int image
)
1213 return m_genericImpl
->SetItemColumnImage(item
, column
, image
);
1217 info
.m_mask
= wxLIST_MASK_IMAGE
;
1218 info
.m_image
= image
;
1219 info
.m_itemId
= item
;
1220 info
.m_col
= column
;
1222 return SetItem(info
);
1225 // Gets the item text
1226 wxString
wxListCtrl::GetItemText(long item
) const
1229 return m_genericImpl
->GetItemText(item
);
1233 info
.m_mask
= wxLIST_MASK_TEXT
;
1234 info
.m_itemId
= item
;
1237 return wxEmptyString
;
1241 // Sets the item text
1242 void wxListCtrl::SetItemText(long item
, const wxString
& str
)
1245 return m_genericImpl
->SetItemText(item
, str
);
1249 info
.m_mask
= wxLIST_MASK_TEXT
;
1250 info
.m_itemId
= item
;
1256 // Gets the item data
1257 long wxListCtrl::GetItemData(long item
) const
1260 return m_genericImpl
->GetItemData(item
);
1264 info
.m_mask
= wxLIST_MASK_DATA
;
1265 info
.m_itemId
= item
;
1272 // Sets the item data
1273 bool wxListCtrl::SetItemData(long item
, long data
)
1276 return m_genericImpl
->SetItemData(item
, data
);
1280 info
.m_mask
= wxLIST_MASK_DATA
;
1281 info
.m_itemId
= item
;
1284 return SetItem(info
);
1287 wxRect
wxListCtrl::GetViewRect() const
1289 wxASSERT_MSG( !HasFlag(wxLC_REPORT
| wxLC_LIST
),
1290 _T("wxListCtrl::GetViewRect() only works in icon mode") );
1293 return m_genericImpl
->GetViewRect();
1299 // Gets the item rectangle
1300 bool wxListCtrl::GetItemRect(long item
, wxRect
& rect
, int code
) const
1303 return m_genericImpl
->GetItemRect(item
, rect
, code
);
1308 DataBrowserItemID id
;
1309 DataBrowserPropertyID col
= kMinColumnId
;
1311 DataBrowserPropertyPart part
= kDataBrowserPropertyEnclosingPart
;
1312 if ( code
== wxLIST_RECT_LABEL
)
1313 part
= kDataBrowserPropertyTextPart
;
1314 else if ( code
== wxLIST_RECT_ICON
)
1315 part
= kDataBrowserPropertyIconPart
;
1317 if ( !(GetWindowStyleFlag() & wxLC_VIRTUAL
) )
1319 wxMacDataItem
* thisItem
= m_dbImpl
->GetItemFromLine(item
);
1320 id
= (DataBrowserItemID
) thisItem
;
1325 GetDataBrowserItemPartBounds( m_dbImpl
->GetControlRef(), id
, col
, part
, &bounds
);
1327 rect
.x
= bounds
.left
;
1328 rect
.y
= bounds
.top
;
1329 rect
.width
= bounds
.right
- bounds
.left
; //GetClientSize().x; // we need the width of the whole row, not just the item.
1330 rect
.height
= bounds
.bottom
- bounds
.top
;
1331 //fprintf("id = %d, bounds = %d, %d, %d, %d\n", id, rect.x, rect.y, rect.width, rect.height);
1336 // Gets the item position
1337 bool wxListCtrl::GetItemPosition(long item
, wxPoint
& pos
) const
1340 return m_genericImpl
->GetItemPosition(item
, pos
);
1342 bool success
= false;
1347 GetItemRect(item
, itemRect
);
1348 pos
= itemRect
.GetPosition();
1355 // Sets the item position.
1356 bool wxListCtrl::SetItemPosition(long item
, const wxPoint
& pos
)
1359 return m_genericImpl
->SetItemPosition(item
, pos
);
1364 // Gets the number of items in the list control
1365 int wxListCtrl::GetItemCount() const
1368 return m_genericImpl
->GetItemCount();
1371 return m_dbImpl
->MacGetCount();
1376 void wxListCtrl::SetItemSpacing( int spacing
, bool isSmall
)
1379 m_genericImpl
->SetItemSpacing(spacing
, isSmall
);
1382 wxSize
wxListCtrl::GetItemSpacing() const
1385 return m_genericImpl
->GetItemSpacing();
1387 return wxSize(0, 0);
1390 void wxListCtrl::SetItemTextColour( long item
, const wxColour
&col
)
1394 m_genericImpl
->SetItemTextColour(item
, col
);
1399 info
.m_itemId
= item
;
1400 info
.SetTextColour( col
);
1404 wxColour
wxListCtrl::GetItemTextColour( long item
) const
1407 return m_genericImpl
->GetItemTextColour(item
);
1413 return info
.GetTextColour();
1415 return wxNullColour
;
1418 void wxListCtrl::SetItemBackgroundColour( long item
, const wxColour
&col
)
1422 m_genericImpl
->SetItemBackgroundColour(item
, col
);
1427 info
.m_itemId
= item
;
1428 info
.SetBackgroundColour( col
);
1432 wxColour
wxListCtrl::GetItemBackgroundColour( long item
) const
1435 return m_genericImpl
->GetItemBackgroundColour(item
);
1441 return info
.GetBackgroundColour();
1443 return wxNullColour
;
1446 void wxListCtrl::SetItemFont( long item
, const wxFont
&f
)
1450 m_genericImpl
->SetItemFont(item
, f
);
1455 info
.m_itemId
= item
;
1460 wxFont
wxListCtrl::GetItemFont( long item
) const
1463 return m_genericImpl
->GetItemFont(item
);
1469 return info
.GetFont();
1475 // Gets the number of selected items in the list control
1476 int wxListCtrl::GetSelectedItemCount() const
1479 return m_genericImpl
->GetSelectedItemCount();
1482 return m_dbImpl
->GetSelectedItemCount(NULL
, true);
1487 // Gets the text colour of the listview
1488 wxColour
wxListCtrl::GetTextColour() const
1491 return m_genericImpl
->GetTextColour();
1493 // TODO: we need owner drawn list items to customize text color.
1497 return wxNullColour
;
1500 // Sets the text colour of the listview
1501 void wxListCtrl::SetTextColour(const wxColour
& col
)
1505 m_genericImpl
->SetTextColour(col
);
1513 // Gets the index of the topmost visible item when in
1514 // list or report view
1515 long wxListCtrl::GetTopItem() const
1518 return m_genericImpl
->GetTopItem();
1523 long item
= HitTest( wxPoint(1, 1), flags
);
1524 if (flags
== wxLIST_HITTEST_ONITEM
)
1531 // Searches for an item, starting from 'item'.
1532 // 'geometry' is one of
1533 // wxLIST_NEXT_ABOVE/ALL/BELOW/LEFT/RIGHT.
1534 // 'state' is a state bit flag, one or more of
1535 // wxLIST_STATE_DROPHILITED/FOCUSED/SELECTED/CUT.
1536 // item can be -1 to find the first item that matches the
1538 // Returns the item or -1 if unsuccessful.
1539 long wxListCtrl::GetNextItem(long item
, int geom
, int state
) const
1542 return m_genericImpl
->GetNextItem(item
, geom
, state
);
1544 if (m_dbImpl
&& geom
== wxLIST_NEXT_ALL
&& state
== wxLIST_STATE_SELECTED
)
1546 long count
= m_dbImpl
->MacGetCount() ;
1547 for ( long line
= item
+ 1 ; line
< count
; line
++ )
1549 wxMacDataItem
* id
= m_dbImpl
->GetItemFromLine(line
);
1550 if ( m_dbImpl
->IsItemSelected(id
) )
1560 wxImageList
*wxListCtrl::GetImageList(int which
) const
1563 return m_genericImpl
->GetImageList(which
);
1565 if ( which
== wxIMAGE_LIST_NORMAL
)
1567 return m_imageListNormal
;
1569 else if ( which
== wxIMAGE_LIST_SMALL
)
1571 return m_imageListSmall
;
1573 else if ( which
== wxIMAGE_LIST_STATE
)
1575 return m_imageListState
;
1580 void wxListCtrl::SetImageList(wxImageList
*imageList
, int which
)
1584 m_genericImpl
->SetImageList(imageList
, which
);
1588 if ( which
== wxIMAGE_LIST_NORMAL
)
1590 if (m_ownsImageListNormal
) delete m_imageListNormal
;
1591 m_imageListNormal
= imageList
;
1592 m_ownsImageListNormal
= false;
1594 else if ( which
== wxIMAGE_LIST_SMALL
)
1596 if (m_ownsImageListSmall
) delete m_imageListSmall
;
1597 m_imageListSmall
= imageList
;
1598 m_ownsImageListSmall
= false;
1600 else if ( which
== wxIMAGE_LIST_STATE
)
1602 if (m_ownsImageListState
) delete m_imageListState
;
1603 m_imageListState
= imageList
;
1604 m_ownsImageListState
= false;
1608 void wxListCtrl::AssignImageList(wxImageList
*imageList
, int which
)
1612 m_genericImpl
->AssignImageList(imageList
, which
);
1616 SetImageList(imageList
, which
);
1617 if ( which
== wxIMAGE_LIST_NORMAL
)
1618 m_ownsImageListNormal
= true;
1619 else if ( which
== wxIMAGE_LIST_SMALL
)
1620 m_ownsImageListSmall
= true;
1621 else if ( which
== wxIMAGE_LIST_STATE
)
1622 m_ownsImageListState
= true;
1625 // ----------------------------------------------------------------------------
1627 // ----------------------------------------------------------------------------
1629 // Arranges the items
1630 bool wxListCtrl::Arrange(int flag
)
1633 return m_genericImpl
->Arrange(flag
);
1638 bool wxListCtrl::DeleteItem(long item
)
1641 return m_genericImpl
->DeleteItem(item
);
1645 m_dbImpl
->MacDelete(item
);
1646 wxListEvent
event( wxEVT_COMMAND_LIST_DELETE_ITEM
, GetId() );
1647 event
.SetEventObject( this );
1648 event
.m_itemIndex
= item
;
1649 GetEventHandler()->ProcessEvent( event
);
1655 // Deletes all items
1656 bool wxListCtrl::DeleteAllItems()
1659 return m_genericImpl
->DeleteAllItems();
1663 m_dbImpl
->MacClear();
1664 wxListEvent
event( wxEVT_COMMAND_LIST_DELETE_ALL_ITEMS
, GetId() );
1665 event
.SetEventObject( this );
1666 GetEventHandler()->ProcessEvent( event
);
1671 // Deletes all items
1672 bool wxListCtrl::DeleteAllColumns()
1675 return m_genericImpl
->DeleteAllColumns();
1680 m_dbImpl
->GetColumnCount(&cols
);
1681 for (UInt32 col
= 0; col
< cols
; col
++)
1691 bool wxListCtrl::DeleteColumn(int col
)
1694 return m_genericImpl
->DeleteColumn(col
);
1698 OSStatus err
= m_dbImpl
->RemoveColumn(col
);
1699 return err
== noErr
;
1705 // Clears items, and columns if there are any.
1706 void wxListCtrl::ClearAll()
1710 m_genericImpl
->ClearAll();
1721 wxTextCtrl
* wxListCtrl::EditLabel(long item
, wxClassInfo
* textControlClass
)
1724 return m_genericImpl
->EditLabel(item
, textControlClass
);
1728 wxCHECK_MSG( (item
>= 0) && ((long)item
< GetItemCount()), NULL
,
1729 wxT("wrong index in wxListCtrl::EditLabel()") );
1731 wxASSERT_MSG( textControlClass
->IsKindOf(CLASSINFO(wxTextCtrl
)),
1732 wxT("EditLabel() needs a text control") );
1734 wxListEvent
le( wxEVT_COMMAND_LIST_BEGIN_LABEL_EDIT
, GetParent()->GetId() );
1735 le
.SetEventObject( this );
1736 le
.m_itemIndex
= item
;
1738 GetItem( le
.m_item
);
1740 if ( GetParent()->GetEventHandler()->ProcessEvent( le
) && !le
.IsAllowed() )
1742 // vetoed by user code
1746 wxTextCtrl
* const text
= (wxTextCtrl
*)textControlClass
->CreateObject();
1747 m_textctrlWrapper
= new wxListCtrlTextCtrlWrapper(this, text
, item
);
1748 return m_textctrlWrapper
->GetText();
1753 // End label editing, optionally cancelling the edit
1754 bool wxListCtrl::EndEditLabel(bool cancel
)
1756 // TODO: generic impl. doesn't have this method - is it needed for us?
1758 return true; // m_genericImpl->EndEditLabel(cancel);
1761 verify_noerr( SetDataBrowserEditItem(m_dbImpl
->GetControlRef(), kDataBrowserNoItem
, kMinColumnId
) );
1765 // Ensures this item is visible
1766 bool wxListCtrl::EnsureVisible(long item
)
1769 return m_genericImpl
->EnsureVisible(item
);
1773 wxMacDataItem
* dataItem
= m_dbImpl
->GetItemFromLine(item
);
1774 m_dbImpl
->RevealItem(dataItem
, kDataBrowserRevealWithoutSelecting
);
1780 // Find an item whose label matches this string, starting from the item after 'start'
1781 // or the beginning if 'start' is -1.
1782 long wxListCtrl::FindItem(long start
, const wxString
& str
, bool partial
)
1785 return m_genericImpl
->FindItem(start
, str
, partial
);
1787 wxString str_upper
= str
.Upper();
1792 long count
= GetItemCount();
1796 wxString line_upper
= GetItemText(idx
).Upper();
1799 if (line_upper
== str_upper
)
1804 if (line_upper
.find(str_upper
) == 0)
1814 // Find an item whose data matches this data, starting from the item after 'start'
1815 // or the beginning if 'start' is -1.
1816 long wxListCtrl::FindItem(long start
, long data
)
1819 return m_genericImpl
->FindItem(start
, data
);
1824 long count
= GetItemCount();
1828 if (GetItemData(idx
) == data
)
1836 // Find an item nearest this position in the specified direction, starting from
1837 // the item after 'start' or the beginning if 'start' is -1.
1838 long wxListCtrl::FindItem(long start
, const wxPoint
& pt
, int direction
)
1841 return m_genericImpl
->FindItem(start
, pt
, direction
);
1845 // Determines which item (if any) is at the specified point,
1846 // giving details in 'flags' (see wxLIST_HITTEST_... flags above)
1848 wxListCtrl::HitTest(const wxPoint
& point
, int& flags
, long *ptrSubItem
) const
1851 return m_genericImpl
->HitTest(point
, flags
, ptrSubItem
);
1853 flags
= wxLIST_HITTEST_NOWHERE
;
1856 int colHeaderHeight
= 22; // TODO: Find a way to get this value from the db control?
1857 UInt16 rowHeight
= 0;
1858 m_dbImpl
->GetDefaultRowHeight(&rowHeight
);
1861 // get the actual row by taking scroll position into account
1862 UInt32 offsetX
, offsetY
;
1863 m_dbImpl
->GetScrollPosition( &offsetY
, &offsetX
);
1866 if ( !(GetWindowStyleFlag() & wxLC_NO_HEADER
) )
1867 y
-= colHeaderHeight
;
1872 int row
= y
/ rowHeight
;
1873 DataBrowserItemID id
;
1874 m_dbImpl
->GetItemID( (DataBrowserTableViewRowIndex
) row
, &id
);
1876 // TODO: Use GetDataBrowserItemPartBounds to return if we are in icon or label
1877 if ( !(GetWindowStyleFlag() & wxLC_VIRTUAL
) )
1879 wxMacListCtrlItem
* lcItem
;
1880 lcItem
= (wxMacListCtrlItem
*) id
;
1883 flags
= wxLIST_HITTEST_ONITEM
;
1889 if (row
< GetItemCount() )
1891 flags
= wxLIST_HITTEST_ONITEM
;
1900 int wxListCtrl::GetScrollPos(int orient
) const
1903 return m_genericImpl
->GetScrollPos(orient
);
1907 UInt32 offsetX
, offsetY
;
1908 m_dbImpl
->GetScrollPosition( &offsetY
, &offsetX
);
1909 if ( orient
== wxHORIZONTAL
)
1918 // Inserts an item, returning the index of the new item if successful,
1920 long wxListCtrl::InsertItem(wxListItem
& info
)
1922 wxASSERT_MSG( !IsVirtual(), _T("can't be used with virtual controls") );
1925 return m_genericImpl
->InsertItem(info
);
1927 if (m_dbImpl
&& !IsVirtual())
1929 int count
= GetItemCount();
1931 if (info
.m_itemId
> count
)
1932 info
.m_itemId
= count
;
1934 m_dbImpl
->MacInsertItem(info
.m_itemId
, &info
);
1935 wxMacDataItem
* dataItem
= m_dbImpl
->GetItemFromLine(info
.m_itemId
);
1937 wxListEvent
event( wxEVT_COMMAND_LIST_INSERT_ITEM
, GetId() );
1938 event
.SetEventObject( this );
1939 event
.m_itemIndex
= info
.m_itemId
;
1940 GetEventHandler()->ProcessEvent( event
);
1941 return info
.m_itemId
;
1946 long wxListCtrl::InsertItem(long index
, const wxString
& label
)
1949 return m_genericImpl
->InsertItem(index
, label
);
1952 info
.m_text
= label
;
1953 info
.m_mask
= wxLIST_MASK_TEXT
;
1954 info
.m_itemId
= index
;
1955 return InsertItem(info
);
1958 // Inserts an image item
1959 long wxListCtrl::InsertItem(long index
, int imageIndex
)
1962 return m_genericImpl
->InsertItem(index
, imageIndex
);
1965 info
.m_image
= imageIndex
;
1966 info
.m_mask
= wxLIST_MASK_IMAGE
;
1967 info
.m_itemId
= index
;
1968 return InsertItem(info
);
1971 // Inserts an image/string item
1972 long wxListCtrl::InsertItem(long index
, const wxString
& label
, int imageIndex
)
1975 return m_genericImpl
->InsertItem(index
, label
, imageIndex
);
1978 info
.m_image
= imageIndex
;
1979 info
.m_text
= label
;
1980 info
.m_mask
= wxLIST_MASK_IMAGE
| wxLIST_MASK_TEXT
;
1981 info
.m_itemId
= index
;
1982 return InsertItem(info
);
1985 // For list view mode (only), inserts a column.
1986 long wxListCtrl::InsertColumn(long col
, wxListItem
& item
)
1989 return m_genericImpl
->InsertColumn(col
, item
);
1993 int width
= item
.GetWidth();
1994 if ( !(item
.GetMask() & wxLIST_MASK_WIDTH
) )
1997 DataBrowserPropertyType type
= kDataBrowserCustomType
; //kDataBrowserTextType;
1998 wxImageList
* imageList
= GetImageList(wxIMAGE_LIST_SMALL
);
1999 if (imageList
&& imageList
->GetImageCount() > 0)
2001 wxBitmap bmp
= imageList
->GetBitmap(0);
2003 // type = kDataBrowserIconAndTextType;
2006 SInt16 just
= teFlushDefault
;
2007 if (item
.GetMask() & wxLIST_MASK_FORMAT
)
2009 if (item
.GetAlign() == wxLIST_FORMAT_LEFT
)
2011 else if (item
.GetAlign() == wxLIST_FORMAT_CENTER
)
2013 else if (item
.GetAlign() == wxLIST_FORMAT_RIGHT
)
2014 just
= teFlushRight
;
2016 m_dbImpl
->InsertColumn(col
, type
, item
.GetText(), just
, width
);
2017 SetColumn(col
, item
);
2019 // set/remove options based on the wxListCtrl type.
2020 DataBrowserTableViewColumnID id
;
2021 m_dbImpl
->GetColumnIDFromIndex(col
, &id
);
2022 DataBrowserPropertyFlags flags
;
2023 verify_noerr(m_dbImpl
->GetPropertyFlags(id
, &flags
));
2024 if (GetWindowStyleFlag() & wxLC_EDIT_LABELS
)
2025 flags
|= kDataBrowserPropertyIsEditable
;
2027 if (GetWindowStyleFlag() & wxLC_VIRTUAL
){
2028 flags
&= ~kDataBrowserListViewSortableColumn
;
2030 verify_noerr(m_dbImpl
->SetPropertyFlags(id
, flags
));
2036 long wxListCtrl::InsertColumn(long col
,
2037 const wxString
& heading
,
2042 return m_genericImpl
->InsertColumn(col
, heading
, format
, width
);
2045 item
.m_mask
= wxLIST_MASK_TEXT
| wxLIST_MASK_FORMAT
;
2046 item
.m_text
= heading
;
2049 item
.m_mask
|= wxLIST_MASK_WIDTH
;
2050 item
.m_width
= width
;
2052 item
.m_format
= format
;
2054 return InsertColumn(col
, item
);
2057 // scroll the control by the given number of pixels (exception: in list view,
2058 // dx is interpreted as number of columns)
2059 bool wxListCtrl::ScrollList(int dx
, int dy
)
2062 return m_genericImpl
->ScrollList(dx
, dy
);
2066 m_dbImpl
->SetScrollPosition(dx
, dy
);
2072 bool wxListCtrl::SortItems(wxListCtrlCompare fn
, long data
)
2075 return m_genericImpl
->SortItems(fn
, data
);
2080 m_compareFuncData
= data
;
2081 SortDataBrowserContainer( m_dbImpl
->GetControlRef(), kDataBrowserNoItem
, true);
2083 // we need to do this after each call, else we get a crash from wxPython when
2084 // SortItems is called the second time.
2085 m_compareFunc
= NULL
;
2086 m_compareFuncData
= 0;
2092 void wxListCtrl::OnRenameTimer()
2094 wxCHECK_RET( HasCurrent(), wxT("unexpected rename timer") );
2096 EditLabel( m_current
);
2099 bool wxListCtrl::OnRenameAccept(long itemEdit
, const wxString
& value
)
2101 wxListEvent
le( wxEVT_COMMAND_LIST_END_LABEL_EDIT
, GetId() );
2102 le
.SetEventObject( this );
2103 le
.m_itemIndex
= itemEdit
;
2105 GetItem( le
.m_item
);
2106 le
.m_item
.m_text
= value
;
2107 return !GetEventHandler()->ProcessEvent( le
) ||
2111 void wxListCtrl::OnRenameCancelled(long itemEdit
)
2113 // let owner know that the edit was cancelled
2114 wxListEvent
le( wxEVT_COMMAND_LIST_END_LABEL_EDIT
, GetParent()->GetId() );
2116 le
.SetEditCanceled(true);
2118 le
.SetEventObject( this );
2119 le
.m_itemIndex
= itemEdit
;
2121 GetItem( le
.m_item
);
2122 GetEventHandler()->ProcessEvent( le
);
2125 // ----------------------------------------------------------------------------
2126 // virtual list controls
2127 // ----------------------------------------------------------------------------
2129 wxString
wxListCtrl::OnGetItemText(long WXUNUSED(item
), long WXUNUSED(col
)) const
2131 // this is a pure virtual function, in fact - which is not really pure
2132 // because the controls which are not virtual don't need to implement it
2133 wxFAIL_MSG( _T("wxListCtrl::OnGetItemText not supposed to be called") );
2135 return wxEmptyString
;
2138 int wxListCtrl::OnGetItemImage(long WXUNUSED(item
)) const
2140 wxCHECK_MSG(!GetImageList(wxIMAGE_LIST_SMALL
),
2142 wxT("List control has an image list, OnGetItemImage or OnGetItemColumnImage should be overridden."));
2146 int wxListCtrl::OnGetItemColumnImage(long item
, long column
) const
2149 return OnGetItemImage(item
);
2154 wxListItemAttr
*wxListCtrl::OnGetItemAttr(long WXUNUSED_UNLESS_DEBUG(item
)) const
2156 wxASSERT_MSG( item
>= 0 && item
< GetItemCount(),
2157 _T("invalid item index in OnGetItemAttr()") );
2159 // no attributes by default
2163 void wxListCtrl::SetItemCount(long count
)
2165 wxASSERT_MSG( IsVirtual(), _T("this is for virtual controls only") );
2169 m_genericImpl
->SetItemCount(count
);
2175 // we need to temporarily disable the new item creation notification
2176 // procedure to speed things up
2177 // FIXME: Even this doesn't seem to help much...
2179 // FIXME: Find a more efficient way to do this.
2180 m_dbImpl
->MacClear();
2182 DataBrowserCallbacks callbacks
;
2183 DataBrowserItemNotificationUPP itemUPP
;
2184 GetDataBrowserCallbacks(m_dbImpl
->GetControlRef(), &callbacks
);
2185 itemUPP
= callbacks
.u
.v1
.itemNotificationCallback
;
2186 callbacks
.u
.v1
.itemNotificationCallback
= 0;
2187 m_dbImpl
->SetCallbacks(&callbacks
);
2188 ::AddDataBrowserItems(m_dbImpl
->GetControlRef(), kDataBrowserNoItem
,
2189 count
, NULL
, kDataBrowserItemNoProperty
);
2190 callbacks
.u
.v1
.itemNotificationCallback
= itemUPP
;
2191 m_dbImpl
->SetCallbacks(&callbacks
);
2196 void wxListCtrl::RefreshItem(long item
)
2200 m_genericImpl
->RefreshItem(item
);
2205 GetItemRect(item
, rect
);
2209 void wxListCtrl::RefreshItems(long itemFrom
, long itemTo
)
2213 m_genericImpl
->RefreshItems(itemFrom
, itemTo
);
2217 wxRect rect1
, rect2
;
2218 GetItemRect(itemFrom
, rect1
);
2219 GetItemRect(itemTo
, rect2
);
2221 wxRect rect
= rect1
;
2222 rect
.height
= rect2
.GetBottom() - rect1
.GetTop();
2227 void wxListCtrl::SetDropTarget( wxDropTarget
*dropTarget
)
2229 #if wxUSE_DRAG_AND_DROP
2231 m_genericImpl
->SetDropTarget( dropTarget
);
2234 wxWindow::SetDropTarget( dropTarget
);
2238 wxDropTarget
*wxListCtrl::GetDropTarget() const
2240 #if wxUSE_DRAG_AND_DROP
2242 return m_genericImpl
->GetDropTarget();
2245 return wxWindow::GetDropTarget();
2250 #if wxABI_VERSION >= 20801
2251 void wxListCtrl::SetFocus()
2255 m_genericImpl
->SetFocus();
2259 wxWindow::SetFocus();
2263 // wxMac internal data structures
2265 wxMacListCtrlItem::~wxMacListCtrlItem()
2269 void wxMacListCtrlItem::Notification(wxMacDataItemBrowserControl
*owner
,
2270 DataBrowserItemNotification message
,
2271 DataBrowserItemDataRef itemData
) const
2274 wxMacDataBrowserListCtrlControl
*lb
= wxDynamicCast(owner
, wxMacDataBrowserListCtrlControl
);
2276 // we want to depend on as little as possible to make sure tear-down of controls is safe
2277 if ( message
== kDataBrowserItemRemoved
)
2279 if ( lb
!= NULL
&& lb
->GetClientDataType() == wxClientData_Object
)
2281 delete (wxClientData
*) (m_data
);
2287 else if ( message
== kDataBrowserItemAdded
)
2289 // we don't issue events on adding, the item is not really stored in the list yet, so we
2290 // avoid asserts by gettting out now
2294 wxListCtrl
*list
= wxDynamicCast( owner
->GetPeer() , wxListCtrl
);
2297 bool trigger
= false;
2299 wxListEvent
event( wxEVT_COMMAND_LIST_ITEM_SELECTED
, list
->GetId() );
2300 bool isSingle
= (list
->GetWindowStyle() & wxLC_SINGLE_SEL
) != 0;
2302 event
.SetEventObject( list
);
2303 event
.m_itemIndex
= owner
->GetLineFromItem( this ) ;
2304 if ( !list
->IsVirtual() )
2306 lb
->MacGetColumnInfo(event
.m_itemIndex
,0,event
.m_item
);
2311 case kDataBrowserItemDeselected
:
2312 event
.SetEventType(wxEVT_COMMAND_LIST_ITEM_DESELECTED
);
2314 trigger
= !lb
->IsSelectionSuppressed();
2317 case kDataBrowserItemSelected
:
2318 trigger
= !lb
->IsSelectionSuppressed();
2321 case kDataBrowserItemDoubleClicked
:
2322 event
.SetEventType( wxEVT_COMMAND_LIST_ITEM_ACTIVATED
);
2326 case kDataBrowserEditStarted
:
2327 // TODO : how to veto ?
2328 event
.SetEventType( wxEVT_COMMAND_LIST_BEGIN_LABEL_EDIT
) ;
2332 case kDataBrowserEditStopped
:
2333 // TODO probably trigger only upon the value store callback, because
2334 // here IIRC we cannot veto
2335 event
.SetEventType( wxEVT_COMMAND_LIST_END_LABEL_EDIT
) ;
2345 // direct notification is not always having the listbox GetSelection() having in synch with event
2346 wxPostEvent( list
->GetEventHandler(), event
);
2352 IMPLEMENT_DYNAMIC_CLASS(wxMacDataBrowserListCtrlControl
, wxMacDataItemBrowserControl
)
2354 wxMacDataBrowserListCtrlControl::wxMacDataBrowserListCtrlControl( wxWindow
*peer
, const wxPoint
& pos
, const wxSize
& size
, long style
)
2355 : wxMacDataItemBrowserControl( peer
, pos
, size
, style
)
2357 OSStatus err
= noErr
;
2358 m_clientDataItemsType
= wxClientData_None
;
2359 m_isVirtual
= false;
2361 if ( style
& wxLC_VIRTUAL
)
2364 DataBrowserSelectionFlags options
= kDataBrowserDragSelect
;
2365 if ( style
& wxLC_SINGLE_SEL
)
2367 options
|= kDataBrowserSelectOnlyOne
;
2371 options
|= kDataBrowserCmdTogglesSelection
;
2374 err
= SetSelectionFlags( options
);
2375 verify_noerr( err
);
2377 DataBrowserCustomCallbacks callbacks
;
2378 InitializeDataBrowserCustomCallbacks( &callbacks
, kDataBrowserLatestCustomCallbacks
);
2380 if ( gDataBrowserDrawItemUPP
== NULL
)
2381 gDataBrowserDrawItemUPP
= NewDataBrowserDrawItemUPP(DataBrowserDrawItemProc
);
2383 if ( gDataBrowserHitTestUPP
== NULL
)
2384 gDataBrowserHitTestUPP
= NewDataBrowserHitTestUPP(DataBrowserHitTestProc
);
2386 callbacks
.u
.v1
.drawItemCallback
= gDataBrowserDrawItemUPP
;
2387 callbacks
.u
.v1
.hitTestCallback
= gDataBrowserHitTestUPP
;
2389 SetDataBrowserCustomCallbacks( GetControlRef(), &callbacks
);
2391 if ( style
& wxLC_LIST
)
2393 InsertColumn(0, kDataBrowserIconAndTextType
, wxEmptyString
, -1, -1);
2394 verify_noerr( AutoSizeColumns() );
2397 if ( style
& wxLC_LIST
|| style
& wxLC_NO_HEADER
)
2398 verify_noerr( SetHeaderButtonHeight( 0 ) );
2401 SetSortProperty( kMinColumnId
- 1 );
2403 SetSortProperty( kMinColumnId
);
2405 m_sortOrder
= SortOrder_None
;
2407 if ( style
& wxLC_SORT_DESCENDING
)
2409 SetSortOrder( kDataBrowserOrderDecreasing
);
2411 else if ( style
& wxLC_SORT_ASCENDING
)
2413 SetSortOrder( kDataBrowserOrderIncreasing
);
2416 if ( style
& wxLC_VRULES
)
2418 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4
2419 verify_noerr( DataBrowserChangeAttributes(m_controlRef
, kDataBrowserAttributeListViewDrawColumnDividers
, kDataBrowserAttributeNone
) );
2423 verify_noerr( SetHiliteStyle(kDataBrowserTableViewFillHilite
) );
2424 err
= SetHasScrollBars( (style
& wxHSCROLL
) != 0 , true );
2427 pascal Boolean
wxMacDataBrowserListCtrlControl::DataBrowserEditTextProc(
2429 DataBrowserItemID itemID
,
2430 DataBrowserPropertyID property
,
2431 CFStringRef theString
,
2432 Rect
*maxEditTextRect
,
2433 Boolean
*shrinkToFit
)
2435 Boolean result
= false;
2436 wxMacDataBrowserListCtrlControl
* ctl
= wxDynamicCast(wxMacControl::GetReferenceFromNativeControl( browser
), wxMacDataBrowserListCtrlControl
);
2439 result
= ctl
->ConfirmEditText(itemID
, property
, theString
, maxEditTextRect
, shrinkToFit
);
2440 theString
= CFSTR("Hello!");
2445 bool wxMacDataBrowserListCtrlControl::ConfirmEditText(
2446 DataBrowserItemID itemID
,
2447 DataBrowserPropertyID property
,
2448 CFStringRef theString
,
2449 Rect
*maxEditTextRect
,
2450 Boolean
*shrinkToFit
)
2455 pascal void wxMacDataBrowserListCtrlControl::DataBrowserDrawItemProc(
2457 DataBrowserItemID itemID
,
2458 DataBrowserPropertyID property
,
2459 DataBrowserItemState itemState
,
2460 const Rect
*itemRect
,
2462 Boolean colorDevice
)
2464 wxMacDataBrowserListCtrlControl
* ctl
= wxDynamicCast(wxMacControl::GetReferenceFromNativeControl( browser
), wxMacDataBrowserListCtrlControl
);
2467 ctl
->DrawItem(itemID
, property
, itemState
, itemRect
, gdDepth
, colorDevice
);
2471 // routines needed for DrawItem
2476 kTextBoxHeight
= 14,
2477 kIconTextSpacingV
= 2,
2479 kContentHeight
= kIconHeight
+ kTextBoxHeight
+ kIconTextSpacingV
2482 static void calculateCGDrawingBounds(CGRect inItemRect
, CGRect
*outIconRect
, CGRect
*outTextRect
, bool hasIcon
= false)
2485 float iconH
, iconW
= 0;
2486 float padding
= kItemPadding
;
2489 iconH
= kIconHeight
;
2491 padding
= padding
*2;
2494 textBottom
= inItemRect
.origin
.y
;
2496 *outIconRect
= CGRectMake(inItemRect
.origin
.x
+ kItemPadding
,
2497 textBottom
+ kIconTextSpacingV
, kIconWidth
,
2500 *outTextRect
= CGRectMake(inItemRect
.origin
.x
+ padding
+ iconW
,
2501 textBottom
+ kIconTextSpacingV
, inItemRect
.size
.width
- padding
- iconW
,
2502 inItemRect
.size
.height
- kIconTextSpacingV
);
2505 void wxMacDataBrowserListCtrlControl::DrawItem(
2506 DataBrowserItemID itemID
,
2507 DataBrowserPropertyID property
,
2508 DataBrowserItemState itemState
,
2509 const Rect
*itemRect
,
2511 Boolean colorDevice
)
2514 wxFont font
= wxNullFont
;
2516 short listColumn
= property
- kMinColumnId
;
2518 wxListCtrl
* list
= wxDynamicCast( GetPeer() , wxListCtrl
);
2519 wxMacListCtrlItem
* lcItem
;
2520 wxColour color
= *wxBLACK
;
2521 wxColour bgColor
= wxNullColour
;
2523 if (listColumn
>= 0)
2527 lcItem
= (wxMacListCtrlItem
*) itemID
;
2528 if (lcItem
->HasColumnInfo(listColumn
)){
2529 wxListItem
* item
= lcItem
->GetColumnInfo(listColumn
);
2531 // we always use the 0 column to get font and text/background colors.
2532 if (lcItem
->HasColumnInfo(0))
2534 wxListItem
* firstItem
= lcItem
->GetColumnInfo(0);
2535 color
= firstItem
->GetTextColour();
2536 bgColor
= firstItem
->GetBackgroundColour();
2537 font
= firstItem
->GetFont();
2540 if (item
->GetMask() & wxLIST_MASK_TEXT
)
2541 text
= item
->GetText();
2542 if (item
->GetMask() & wxLIST_MASK_IMAGE
)
2543 imgIndex
= item
->GetImage();
2549 text
= list
->OnGetItemText( (long)itemID
-1, listColumn
);
2550 imgIndex
= list
->OnGetItemColumnImage( (long)itemID
-1, listColumn
);
2551 wxListItemAttr
* attrs
= list
->OnGetItemAttr( (long)itemID
-1 );
2554 if (attrs
->HasBackgroundColour())
2555 bgColor
= attrs
->GetBackgroundColour();
2556 if (attrs
->HasTextColour())
2557 color
= attrs
->GetTextColour();
2558 if (attrs
->HasFont())
2559 font
= attrs
->GetFont();
2564 wxColour listBgColor
= list
->GetBackgroundColour();
2565 if (bgColor
== wxNullColour
)
2566 bgColor
= listBgColor
;
2568 wxFont listFont
= list
->GetFont();
2569 if (font
== wxNullFont
)
2572 wxMacCFStringHolder cfString
;
2573 cfString
.Assign( text
, wxLocale::GetSystemEncoding() );
2576 CGRect enclosingCGRect
, iconCGRect
, textCGRect
;
2578 ThemeDrawingState savedState
= NULL
;
2579 CGContextRef context
= (CGContextRef
)list
->MacGetDrawingContext();
2580 RGBColor labelColor
;
2582 labelColor
.green
= 0;
2583 labelColor
.blue
= 0;
2585 RGBColor backgroundColor
;
2586 backgroundColor
.red
= 255;
2587 backgroundColor
.green
= 255;
2588 backgroundColor
.blue
= 255;
2590 GetDataBrowserItemPartBounds(GetControlRef(), itemID
, property
, kDataBrowserPropertyEnclosingPart
,
2593 enclosingCGRect
= CGRectMake(enclosingRect
.left
,
2595 enclosingRect
.right
- enclosingRect
.left
,
2596 enclosingRect
.bottom
- enclosingRect
.top
);
2598 active
= IsControlActive(GetControlRef());
2600 // don't paint the background over the vertical rule line
2601 if ( list
->GetWindowStyleFlag() & wxLC_VRULES
)
2603 enclosingCGRect
.origin
.x
+= 1;
2604 enclosingCGRect
.size
.width
-= 1;
2606 if (itemState
== kDataBrowserItemIsSelected
)
2609 GetThemeDrawingState(&savedState
);
2611 GetThemeBrushAsColor(kThemeBrushAlternatePrimaryHighlightColor
, 32, true, &backgroundColor
);
2612 GetThemeTextColor(kThemeTextColorWhite
, gdDepth
, colorDevice
, &labelColor
);
2614 CGContextSaveGState(context
);
2616 CGContextSetRGBFillColor(context
, (float)backgroundColor
.red
/ (float)USHRT_MAX
,
2617 (float)backgroundColor
.green
/ (float)USHRT_MAX
,
2618 (float)backgroundColor
.blue
/ (float)USHRT_MAX
, 1.0);
2619 CGContextFillRect(context
, enclosingCGRect
);
2621 CGContextRestoreGState(context
);
2627 labelColor
= MAC_WXCOLORREF( color
.GetPixel() );
2628 else if (list
->GetTextColour().Ok())
2629 labelColor
= MAC_WXCOLORREF( list
->GetTextColour().GetPixel() );
2633 backgroundColor
= MAC_WXCOLORREF( bgColor
.GetPixel() );
2634 CGContextSaveGState(context
);
2636 CGContextSetRGBFillColor(context
, (float)backgroundColor
.red
/ (float)USHRT_MAX
,
2637 (float)backgroundColor
.green
/ (float)USHRT_MAX
,
2638 (float)backgroundColor
.blue
/ (float)USHRT_MAX
, 1.0);
2639 CGContextFillRect(context
, enclosingCGRect
);
2641 CGContextRestoreGState(context
);
2645 calculateCGDrawingBounds(enclosingCGRect
, &iconCGRect
, &textCGRect
, (imgIndex
!= -1) );
2649 wxImageList
* imageList
= list
->GetImageList(wxIMAGE_LIST_SMALL
);
2650 if (imageList
&& imageList
->GetImageCount() > 0){
2651 wxBitmap bmp
= imageList
->GetBitmap(imgIndex
);
2652 IconRef icon
= bmp
.GetBitmapData()->GetIconRef();
2654 CGContextSaveGState(context
);
2655 CGContextTranslateCTM(context
, 0,iconCGRect
.origin
.y
+ CGRectGetMaxY(iconCGRect
));
2656 CGContextScaleCTM(context
,1.0f
,-1.0f
);
2657 PlotIconRefInContext(context
, &iconCGRect
, kAlignNone
,
2658 active
? kTransformNone
: kTransformDisabled
, NULL
,
2659 kPlotIconRefNormalFlags
, icon
);
2661 CGContextRestoreGState(context
);
2665 HIThemeTextHorizontalFlush hFlush
= kHIThemeTextHorizontalFlushLeft
;
2666 UInt16 fontID
= kThemeViewsFont
;
2670 if (font
.GetFamily() != wxFONTFAMILY_DEFAULT
)
2671 fontID
= font
.MacGetThemeFontID();
2673 // FIXME: replace these with CG or ATSUI calls so we can remove this #ifndef.
2675 ::TextSize( (short)(font
.MacGetFontSize()) ) ;
2676 ::TextFace( font
.MacGetFontStyle() ) ;
2681 list
->GetColumn(listColumn
, item
);
2682 if (item
.GetMask() & wxLIST_MASK_FORMAT
)
2684 if (item
.GetAlign() == wxLIST_FORMAT_LEFT
)
2685 hFlush
= kHIThemeTextHorizontalFlushLeft
;
2686 else if (item
.GetAlign() == wxLIST_FORMAT_CENTER
)
2687 hFlush
= kHIThemeTextHorizontalFlushCenter
;
2688 else if (item
.GetAlign() == wxLIST_FORMAT_RIGHT
)
2690 hFlush
= kHIThemeTextHorizontalFlushRight
;
2691 textCGRect
.origin
.x
-= kItemPadding
; // give a little extra paddding
2695 HIThemeTextInfo info
;
2696 info
.version
= kHIThemeTextInfoVersionZero
;
2697 info
.state
= active
? kThemeStateActive
: kThemeStateInactive
;
2698 info
.fontID
= fontID
;
2699 info
.horizontalFlushness
= hFlush
;
2700 info
.verticalFlushness
= kHIThemeTextVerticalFlushCenter
;
2701 info
.options
= kHIThemeTextBoxOptionNone
;
2702 info
.truncationPosition
= kHIThemeTextTruncationEnd
;
2703 info
.truncationMaxLines
= 1;
2705 CGContextSaveGState(context
);
2706 CGContextSetRGBFillColor (context
, (float)labelColor
.red
/ (float)USHRT_MAX
,
2707 (float)labelColor
.green
/ (float)USHRT_MAX
,
2708 (float)labelColor
.blue
/ (float)USHRT_MAX
, 1.0);
2710 HIThemeDrawTextBox(cfString
, &textCGRect
, &info
, context
, kHIThemeOrientationNormal
);
2712 CGContextRestoreGState(context
);
2714 if (savedState
!= NULL
)
2715 SetThemeDrawingState(savedState
, true);
2718 OSStatus
wxMacDataBrowserListCtrlControl::GetSetItemData(DataBrowserItemID itemID
,
2719 DataBrowserPropertyID property
,
2720 DataBrowserItemDataRef itemData
,
2721 Boolean changeValue
)
2725 short listColumn
= property
- kMinColumnId
;
2727 OSStatus err
= errDataBrowserPropertyNotSupported
;
2728 wxListCtrl
* list
= wxDynamicCast( GetPeer() , wxListCtrl
);
2729 wxMacListCtrlItem
* lcItem
;
2731 if (listColumn
>= 0)
2735 lcItem
= (wxMacListCtrlItem
*) itemID
;
2736 if (lcItem
&& lcItem
->HasColumnInfo(listColumn
)){
2737 wxListItem
* item
= lcItem
->GetColumnInfo(listColumn
);
2738 if (item
->GetMask() & wxLIST_MASK_TEXT
)
2739 text
= item
->GetText();
2740 if (item
->GetMask() & wxLIST_MASK_IMAGE
)
2741 imgIndex
= item
->GetImage();
2746 text
= list
->OnGetItemText( (long)itemID
-1, listColumn
);
2747 imgIndex
= list
->OnGetItemColumnImage( (long)itemID
-1, listColumn
);
2755 case kDataBrowserItemIsEditableProperty
:
2756 if ( list
&& list
->HasFlag( wxLC_EDIT_LABELS
) )
2758 verify_noerr(SetDataBrowserItemDataBooleanValue( itemData
, true ));
2763 if ( property
>= kMinColumnId
)
2765 wxMacCFStringHolder cfStr
;
2768 cfStr
.Assign( text
, wxLocale::GetSystemEncoding() );
2769 err
= ::SetDataBrowserItemDataText( itemData
, cfStr
);
2775 if ( imgIndex
!= -1 )
2777 wxImageList
* imageList
= list
->GetImageList(wxIMAGE_LIST_SMALL
);
2778 if (imageList
&& imageList
->GetImageCount() > 0){
2779 wxBitmap bmp
= imageList
->GetBitmap(imgIndex
);
2780 IconRef icon
= bmp
.GetBitmapData()->GetIconRef();
2781 ::SetDataBrowserItemDataIcon(itemData
, icon
);
2795 if ( property
>= kMinColumnId
)
2797 short listColumn
= property
- kMinColumnId
;
2799 // TODO probably send the 'end edit' from here, as we
2800 // can then deal with the veto
2802 verify_noerr( GetDataBrowserItemDataText( itemData
, &sr
) ) ;
2803 wxMacCFStringHolder
cfStr(sr
) ;;
2805 list
->SetItem( (long)itemData
-1 , listColumn
, cfStr
.AsString() ) ;
2809 lcItem
->SetColumnTextValue( listColumn
, cfStr
.AsString() );
2819 void wxMacDataBrowserListCtrlControl::ItemNotification(DataBrowserItemID itemID
,
2820 DataBrowserItemNotification message
,
2821 DataBrowserItemDataRef itemData
)
2823 // we want to depend on as little as possible to make sure tear-down of controls is safe
2824 if ( message
== kDataBrowserItemRemoved
)
2826 // make sure MacDelete does the proper teardown.
2829 else if ( message
== kDataBrowserItemAdded
)
2831 // we don't issue events on adding, the item is not really stored in the list yet, so we
2832 // avoid asserts by getting out now
2836 wxListCtrl
*list
= wxDynamicCast( GetPeer() , wxListCtrl
);
2839 bool trigger
= false;
2841 wxListEvent
event( wxEVT_COMMAND_LIST_ITEM_SELECTED
, list
->GetId() );
2842 bool isSingle
= (list
->GetWindowStyle() & wxLC_SINGLE_SEL
) != 0;
2844 event
.SetEventObject( list
);
2845 if ( !list
->IsVirtual() )
2847 DataBrowserTableViewRowIndex result
= 0;
2848 verify_noerr( GetItemRow( itemID
, &result
) ) ;
2849 event
.m_itemIndex
= result
;
2851 if (event
.m_itemIndex
>= 0)
2852 MacGetColumnInfo(event
.m_itemIndex
,0,event
.m_item
);
2856 event
.m_itemIndex
= (long)itemID
-1;
2861 case kDataBrowserItemDeselected
:
2862 event
.SetEventType(wxEVT_COMMAND_LIST_ITEM_DESELECTED
);
2864 trigger
= !IsSelectionSuppressed();
2867 case kDataBrowserItemSelected
:
2868 trigger
= !IsSelectionSuppressed();
2872 case kDataBrowserItemDoubleClicked
:
2873 event
.SetEventType( wxEVT_COMMAND_LIST_ITEM_ACTIVATED
);
2877 case kDataBrowserEditStarted
:
2878 // TODO : how to veto ?
2879 event
.SetEventType( wxEVT_COMMAND_LIST_BEGIN_LABEL_EDIT
) ;
2883 case kDataBrowserEditStopped
:
2884 // TODO probably trigger only upon the value store callback, because
2885 // here IIRC we cannot veto
2886 event
.SetEventType( wxEVT_COMMAND_LIST_END_LABEL_EDIT
) ;
2896 // direct notification is not always having the listbox GetSelection() having in synch with event
2897 wxPostEvent( list
->GetEventHandler(), event
);
2902 Boolean
wxMacDataBrowserListCtrlControl::CompareItems(DataBrowserItemID itemOneID
,
2903 DataBrowserItemID itemTwoID
,
2904 DataBrowserPropertyID sortProperty
)
2907 bool retval
= false;
2909 wxString otherItemText
;
2911 long otherItemOrder
;
2913 int colId
= sortProperty
- kMinColumnId
;
2915 wxListCtrl
* list
= wxDynamicCast( GetPeer() , wxListCtrl
);
2917 DataBrowserSortOrder sort
;
2918 verify_noerr(GetSortOrder(&sort
));
2924 wxMacListCtrlItem
* item
= (wxMacListCtrlItem
*)itemOneID
;
2925 wxMacListCtrlItem
* otherItem
= (wxMacListCtrlItem
*)itemTwoID
;
2927 itemOrder
= item
->GetOrder();
2928 otherItemOrder
= item
->GetOrder();
2930 wxListCtrlCompare func
= list
->GetCompareFunc();
2935 if (item
&& item
->HasColumnInfo(0))
2936 item1
= item
->GetColumnInfo(0)->GetData();
2937 if (otherItem
&& otherItem
->HasColumnInfo(0))
2938 item2
= otherItem
->GetColumnInfo(0)->GetData();
2940 if (item1
> -1 && item2
> -1)
2942 int result
= func(item1
, item2
, list
->GetCompareFuncData());
2943 if (sort
== kDataBrowserOrderIncreasing
)
2950 // we can't use the native control's sorting abilities, so just
2952 return itemOrder
< otherItemOrder
;
2957 long itemNum
= (long)itemOneID
;
2958 long otherItemNum
= (long)itemTwoID
;
2959 itemText
= list
->OnGetItemText( itemNum
-1, colId
);
2960 otherItemText
= list
->OnGetItemText( otherItemNum
-1, colId
);
2962 // virtual listctrls don't support sorting
2963 return itemNum
< otherItemNum
;
2967 // fallback for undefined cases
2968 retval
= itemOneID
< itemTwoID
;
2974 wxMacDataBrowserListCtrlControl::~wxMacDataBrowserListCtrlControl()
2978 void wxMacDataBrowserListCtrlControl::MacSetColumnInfo( unsigned int row
, unsigned int column
, wxListItem
* item
)
2980 wxMacDataItem
* dataItem
= GetItemFromLine(row
);
2981 wxASSERT_MSG( dataItem
, _T("could not obtain wxMacDataItem for row in MacSetColumnInfo. Is row a valid wxListCtrl row?") );
2984 wxMacListCtrlItem
* listItem
= wx_static_cast(wxMacListCtrlItem
*,dataItem
);
2985 bool hasInfo
= listItem
->HasColumnInfo( column
);
2986 listItem
->SetColumnInfo( column
, item
);
2987 listItem
->SetOrder(row
);
2988 UpdateState(dataItem
, item
);
2990 wxListCtrl
* list
= wxDynamicCast( GetPeer() , wxListCtrl
);
2992 // NB: When this call was made before a control was completely shown, it would
2993 // update the item prematurely (i.e. no text would be listed) and, on show,
2994 // only the sorted column would be refreshed, meaning only first column text labels
2995 // would be shown. Making sure not to update items until the control is visible
2996 // seems to fix this issue.
2997 if (hasInfo
&& list
->IsShown())
2998 UpdateItem( wxMacDataBrowserRootContainer
, listItem
, kMinColumnId
+ column
);
3002 // apply changes that need to happen immediately, rather than when the
3003 // databrowser control fires a callback.
3004 void wxMacDataBrowserListCtrlControl::UpdateState(wxMacDataItem
* dataItem
, wxListItem
* listItem
)
3006 bool isSelected
= IsItemSelected( dataItem
);
3007 bool isSelectedState
= (listItem
->GetState() == wxLIST_STATE_SELECTED
);
3009 // toggle the selection state if wxListInfo state and actual state don't match.
3010 if ( isSelected
!= isSelectedState
)
3012 DataBrowserSetOption options
= kDataBrowserItemsAdd
;
3013 if (!isSelectedState
)
3014 options
= kDataBrowserItemsRemove
;
3015 SetSelectedItem(dataItem
, options
);
3017 // TODO: Set column width if item width > than current column width
3020 void wxMacDataBrowserListCtrlControl::MacGetColumnInfo( unsigned int row
, unsigned int column
, wxListItem
& item
)
3022 wxMacDataItem
* dataItem
= GetItemFromLine(row
);
3023 wxASSERT_MSG( dataItem
, _T("could not obtain wxMacDataItem in MacGetColumnInfo. Is row a valid wxListCtrl row?") );
3024 // CS should this guard against dataItem = 0 ? , as item is not a pointer if (item) is not appropriate
3027 wxMacListCtrlItem
* listItem
=wx_static_cast(wxMacListCtrlItem
*,dataItem
);
3029 if (!listItem
->HasColumnInfo( column
))
3032 wxListItem
* oldItem
= listItem
->GetColumnInfo( column
);
3036 long mask
= item
.GetMask();
3038 // by default, get everything for backwards compatibility
3041 if ( mask
& wxLIST_MASK_TEXT
)
3042 item
.SetText(oldItem
->GetText());
3043 if ( mask
& wxLIST_MASK_IMAGE
)
3044 item
.SetImage(oldItem
->GetImage());
3045 if ( mask
& wxLIST_MASK_DATA
)
3046 item
.SetData(oldItem
->GetData());
3047 if ( mask
& wxLIST_MASK_STATE
)
3048 item
.SetState(oldItem
->GetState());
3049 if ( mask
& wxLIST_MASK_WIDTH
)
3050 item
.SetWidth(oldItem
->GetWidth());
3051 if ( mask
& wxLIST_MASK_FORMAT
)
3052 item
.SetAlign(oldItem
->GetAlign());
3054 item
.SetTextColour(oldItem
->GetTextColour());
3055 item
.SetBackgroundColour(oldItem
->GetBackgroundColour());
3056 item
.SetFont(oldItem
->GetFont());
3061 void wxMacDataBrowserListCtrlControl::MacInsertItem( unsigned int n
, wxListItem
* item
)
3063 wxMacDataItemBrowserControl::MacInsert(n
, item
->GetText());
3064 MacSetColumnInfo(n
, 0, item
);
3067 wxMacDataItem
* wxMacDataBrowserListCtrlControl::CreateItem()
3069 return new wxMacListCtrlItem();
3072 wxMacListCtrlItem::wxMacListCtrlItem()
3074 m_rowItems
= wxListItemList();
3077 int wxMacListCtrlItem::GetColumnImageValue( unsigned int column
)
3079 if ( HasColumnInfo(column
) )
3080 return GetColumnInfo(column
)->GetImage();
3085 void wxMacListCtrlItem::SetColumnImageValue( unsigned int column
, int imageIndex
)
3087 if ( HasColumnInfo(column
) )
3088 GetColumnInfo(column
)->SetImage(imageIndex
);
3091 wxString
wxMacListCtrlItem::GetColumnTextValue( unsigned int column
)
3096 if ( HasColumnInfo(column
) )
3097 return GetColumnInfo(column
)->GetText();
3099 return wxEmptyString
;
3102 void wxMacListCtrlItem::SetColumnTextValue( unsigned int column
, const wxString
& text
)
3104 if ( HasColumnInfo(column
) )
3105 GetColumnInfo(column
)->SetText(text
);
3107 // for compatibility with superclass APIs
3112 wxListItem
* wxMacListCtrlItem::GetColumnInfo( unsigned int column
)
3114 wxASSERT_MSG( HasColumnInfo(column
), _T("invalid column index in wxMacListCtrlItem") );
3115 return m_rowItems
[column
];
3118 bool wxMacListCtrlItem::HasColumnInfo( unsigned int column
)
3120 return !(m_rowItems
.find( column
) == m_rowItems
.end());
3123 void wxMacListCtrlItem::SetColumnInfo( unsigned int column
, wxListItem
* item
)
3126 if ( !HasColumnInfo(column
) )
3128 wxListItem
* listItem
= new wxListItem(*item
);
3129 m_rowItems
[column
] = listItem
;
3133 wxListItem
* listItem
= GetColumnInfo( column
);
3134 long mask
= item
->GetMask();
3135 if (mask
& wxLIST_MASK_TEXT
)
3136 listItem
->SetText(item
->GetText());
3137 if (mask
& wxLIST_MASK_DATA
)
3138 listItem
->SetData(item
->GetData());
3139 if (mask
& wxLIST_MASK_IMAGE
)
3140 listItem
->SetImage(item
->GetImage());
3141 if (mask
& wxLIST_MASK_STATE
)
3142 listItem
->SetState(item
->GetState());
3143 if (mask
& wxLIST_MASK_FORMAT
)
3144 listItem
->SetAlign(item
->GetAlign());
3145 if (mask
& wxLIST_MASK_WIDTH
)
3146 listItem
->SetWidth(item
->GetWidth());
3148 if ( item
->HasAttributes() )
3150 if ( listItem
->HasAttributes() )
3151 listItem
->GetAttributes()->AssignFrom(*item
->GetAttributes());
3154 listItem
->SetTextColour(item
->GetTextColour());
3155 listItem
->SetBackgroundColour(item
->GetBackgroundColour());
3156 listItem
->SetFont(item
->GetFont());
3162 #endif // wxUSE_LISTCTRL