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"
33 #include "wx/settings.h"
36 #include "wx/mac/uma.h"
38 #include "wx/imaglist.h"
39 #include "wx/sysopt.h"
42 #include "wx/hashmap.h"
44 #if wxUSE_EXTENDED_RTTI
45 WX_DEFINE_FLAGS( wxListCtrlStyle
)
47 wxBEGIN_FLAGS( wxListCtrlStyle
)
48 // new style border flags, we put them first to
49 // use them for streaming out
50 wxFLAGS_MEMBER(wxBORDER_SIMPLE
)
51 wxFLAGS_MEMBER(wxBORDER_SUNKEN
)
52 wxFLAGS_MEMBER(wxBORDER_DOUBLE
)
53 wxFLAGS_MEMBER(wxBORDER_RAISED
)
54 wxFLAGS_MEMBER(wxBORDER_STATIC
)
55 wxFLAGS_MEMBER(wxBORDER_NONE
)
57 // old style border flags
58 wxFLAGS_MEMBER(wxSIMPLE_BORDER
)
59 wxFLAGS_MEMBER(wxSUNKEN_BORDER
)
60 wxFLAGS_MEMBER(wxDOUBLE_BORDER
)
61 wxFLAGS_MEMBER(wxRAISED_BORDER
)
62 wxFLAGS_MEMBER(wxSTATIC_BORDER
)
63 wxFLAGS_MEMBER(wxBORDER
)
65 // standard window styles
66 wxFLAGS_MEMBER(wxTAB_TRAVERSAL
)
67 wxFLAGS_MEMBER(wxCLIP_CHILDREN
)
68 wxFLAGS_MEMBER(wxTRANSPARENT_WINDOW
)
69 wxFLAGS_MEMBER(wxWANTS_CHARS
)
70 wxFLAGS_MEMBER(wxFULL_REPAINT_ON_RESIZE
)
71 wxFLAGS_MEMBER(wxALWAYS_SHOW_SB
)
72 wxFLAGS_MEMBER(wxVSCROLL
)
73 wxFLAGS_MEMBER(wxHSCROLL
)
75 wxFLAGS_MEMBER(wxLC_LIST
)
76 wxFLAGS_MEMBER(wxLC_REPORT
)
77 wxFLAGS_MEMBER(wxLC_ICON
)
78 wxFLAGS_MEMBER(wxLC_SMALL_ICON
)
79 wxFLAGS_MEMBER(wxLC_ALIGN_TOP
)
80 wxFLAGS_MEMBER(wxLC_ALIGN_LEFT
)
81 wxFLAGS_MEMBER(wxLC_AUTOARRANGE
)
82 wxFLAGS_MEMBER(wxLC_USER_TEXT
)
83 wxFLAGS_MEMBER(wxLC_EDIT_LABELS
)
84 wxFLAGS_MEMBER(wxLC_NO_HEADER
)
85 wxFLAGS_MEMBER(wxLC_SINGLE_SEL
)
86 wxFLAGS_MEMBER(wxLC_SORT_ASCENDING
)
87 wxFLAGS_MEMBER(wxLC_SORT_DESCENDING
)
88 wxFLAGS_MEMBER(wxLC_VIRTUAL
)
90 wxEND_FLAGS( wxListCtrlStyle
)
92 IMPLEMENT_DYNAMIC_CLASS_XTI(wxListCtrl
, wxControl
,"wx/listctrl.h")
94 wxBEGIN_PROPERTIES_TABLE(wxListCtrl
)
95 wxEVENT_PROPERTY( TextUpdated
, wxEVT_COMMAND_TEXT_UPDATED
, wxCommandEvent
)
97 wxPROPERTY_FLAGS( WindowStyle
, wxListCtrlStyle
, long , SetWindowStyleFlag
, GetWindowStyleFlag
, EMPTY_MACROVALUE
, 0 /*flags*/ , wxT("Helpstring") , wxT("group")) // style
98 wxEND_PROPERTIES_TABLE()
100 wxBEGIN_HANDLERS_TABLE(wxListCtrl
)
101 wxEND_HANDLERS_TABLE()
103 wxCONSTRUCTOR_5( wxListCtrl
, wxWindow
* , Parent
, wxWindowID
, Id
, wxPoint
, Position
, wxSize
, Size
, long , WindowStyle
)
106 TODO : Expose more information of a list's layout etc. via appropriate objects (¢ la NotebookPageInfo)
109 IMPLEMENT_DYNAMIC_CLASS(wxListCtrl
, wxControl
)
112 IMPLEMENT_DYNAMIC_CLASS(wxListView
, wxListCtrl
)
113 IMPLEMENT_DYNAMIC_CLASS(wxListItem
, wxObject
)
115 IMPLEMENT_DYNAMIC_CLASS(wxListEvent
, wxNotifyEvent
)
117 WX_DECLARE_HASH_MAP( int, wxListItem
*, wxIntegerHash
, wxIntegerEqual
, wxListItemList
);
119 #include "wx/listimpl.cpp"
120 WX_DEFINE_LIST(wxColumnList
)
122 // so we can check for column clicks
123 static const EventTypeSpec eventList
[] =
125 { kEventClassControl
, kEventControlHit
},
126 { kEventClassControl
, kEventControlDraw
}
129 static pascal OSStatus
wxMacListCtrlEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
131 OSStatus result
= eventNotHandledErr
;
133 wxMacCarbonEvent
cEvent( event
) ;
135 ControlRef controlRef
;
136 cEvent
.GetParameter( kEventParamDirectObject
, &controlRef
) ;
138 wxListCtrl
*window
= (wxListCtrl
*) data
;
139 wxListEvent
le( wxEVT_COMMAND_LIST_COL_CLICK
, window
->GetId() );
140 le
.SetEventObject( window
);
142 switch ( GetEventKind( event
) )
144 // check if the column was clicked on and fire an event if so
145 case kEventControlHit
:
147 ControlPartCode result
= cEvent
.GetParameter
<ControlPartCode
>(kEventParamControlPart
, typeControlPartCode
) ;
148 if (result
== kControlButtonPart
){
149 DataBrowserPropertyID col
;
150 GetDataBrowserSortProperty(controlRef
, &col
);
151 int column
= col
- kMinColumnId
;
153 // FIXME: we can't use the sort property for virtual listctrls
154 // so we need to find a better way to determine which column was clicked...
155 if (!window
->IsVirtual())
156 window
->HandleWindowEvent( le
);
158 result
= CallNextEventHandler(handler
, event
);
161 case kEventControlDraw
:
163 CGContextRef context
= cEvent
.GetParameter
<CGContextRef
>(kEventParamCGContextRef
, typeCGContextRef
) ;
164 window
->MacSetDrawingContext(context
);
165 result
= CallNextEventHandler(handler
, event
);
166 window
->MacSetDrawingContext(NULL
);
177 DEFINE_ONE_SHOT_HANDLER_GETTER( wxMacListCtrlEventHandler
)
179 class wxMacListCtrlItem
: public wxMacListBoxItem
184 virtual void Notification(wxMacDataItemBrowserControl
*owner
,
185 DataBrowserItemNotification message
,
186 DataBrowserItemDataRef itemData
) const;
188 virtual void SetColumnInfo( unsigned int column
, wxListItem
* item
);
189 virtual wxListItem
* GetColumnInfo( unsigned int column
);
190 virtual bool HasColumnInfo( unsigned int column
);
192 virtual void SetColumnTextValue( unsigned int column
, const wxString
& text
);
193 virtual wxString
GetColumnTextValue( unsigned int column
);
195 virtual int GetColumnImageValue( unsigned int column
);
196 virtual void SetColumnImageValue( unsigned int column
, int imageIndex
);
198 virtual ~wxMacListCtrlItem();
200 wxListItemList m_rowItems
;
203 DataBrowserDrawItemUPP gDataBrowserDrawItemUPP
= NULL
;
204 //DataBrowserEditItemUPP gDataBrowserEditItemUPP = NULL;
205 DataBrowserHitTestUPP gDataBrowserHitTestUPP
= NULL
;
207 // TODO: Make a better name!!
208 class wxMacDataBrowserListCtrlControl
: public wxMacDataItemBrowserControl
211 wxMacDataBrowserListCtrlControl( wxWindow
*peer
, const wxPoint
& pos
, const wxSize
& size
, long style
);
212 wxMacDataBrowserListCtrlControl() {}
213 virtual ~wxMacDataBrowserListCtrlControl();
215 // create a list item (can be a subclass of wxMacListBoxItem)
217 virtual wxMacDataItem
* CreateItem();
219 virtual void MacInsertItem( unsigned int n
, wxListItem
* item
);
220 virtual void MacSetColumnInfo( unsigned int row
, unsigned int column
, wxListItem
* item
);
221 virtual void MacGetColumnInfo( unsigned int row
, unsigned int column
, wxListItem
& item
);
222 virtual void UpdateState(wxMacDataItem
* dataItem
, wxListItem
* item
);
223 int GetFlags() { return m_flags
; }
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
WXUNUSED(browser
),
264 DataBrowserItemID
WXUNUSED(itemID
),
265 DataBrowserPropertyID
WXUNUSED(property
),
266 const Rect
*WXUNUSED(theRect
),
267 const Rect
*WXUNUSED(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
;
280 DECLARE_DYNAMIC_CLASS_NO_COPY(wxMacDataBrowserListCtrlControl
)
283 class wxMacListCtrlEventDelegate
: public wxEvtHandler
286 wxMacListCtrlEventDelegate( wxListCtrl
* list
, int id
);
287 virtual bool ProcessEvent( wxEvent
& event
);
294 wxMacListCtrlEventDelegate::wxMacListCtrlEventDelegate( wxListCtrl
* list
, int id
)
300 bool wxMacListCtrlEventDelegate::ProcessEvent( wxEvent
& event
)
302 // even though we use a generic list ctrl underneath, make sure
303 // we present ourselves as wxListCtrl.
304 event
.SetEventObject( m_list
);
307 if ( !event
.IsKindOf( CLASSINFO( wxCommandEvent
) ) )
309 if (m_list
->HandleWindowEvent( event
))
312 return wxEvtHandler::ProcessEvent(event
);
315 //-----------------------------------------------------------------------------
316 // wxListCtrlRenameTimer (internal)
317 //-----------------------------------------------------------------------------
319 class wxListCtrlRenameTimer
: public wxTimer
325 wxListCtrlRenameTimer( wxListCtrl
*owner
);
329 //-----------------------------------------------------------------------------
330 // wxListCtrlTextCtrlWrapper: wraps a wxTextCtrl to make it work for inline editing
331 //-----------------------------------------------------------------------------
333 class wxListCtrlTextCtrlWrapper
: public wxEvtHandler
336 // NB: text must be a valid object but not Create()d yet
337 wxListCtrlTextCtrlWrapper(wxListCtrl
*owner
,
341 wxTextCtrl
*GetText() const { return m_text
; }
343 void AcceptChangesAndFinish();
346 void OnChar( wxKeyEvent
&event
);
347 void OnKeyUp( wxKeyEvent
&event
);
348 void OnKillFocus( wxFocusEvent
&event
);
350 bool AcceptChanges();
356 wxString m_startValue
;
359 bool m_aboutToFinish
;
361 DECLARE_EVENT_TABLE()
364 //-----------------------------------------------------------------------------
365 // wxListCtrlRenameTimer (internal)
366 //-----------------------------------------------------------------------------
368 wxListCtrlRenameTimer::wxListCtrlRenameTimer( wxListCtrl
*owner
)
373 void wxListCtrlRenameTimer::Notify()
375 m_owner
->OnRenameTimer();
378 //-----------------------------------------------------------------------------
379 // wxListCtrlTextCtrlWrapper (internal)
380 //-----------------------------------------------------------------------------
382 BEGIN_EVENT_TABLE(wxListCtrlTextCtrlWrapper
, wxEvtHandler
)
383 EVT_CHAR (wxListCtrlTextCtrlWrapper::OnChar
)
384 EVT_KEY_UP (wxListCtrlTextCtrlWrapper::OnKeyUp
)
385 EVT_KILL_FOCUS (wxListCtrlTextCtrlWrapper::OnKillFocus
)
388 wxListCtrlTextCtrlWrapper::wxListCtrlTextCtrlWrapper(wxListCtrl
*owner
,
391 : m_startValue(owner
->GetItemText(itemEdit
)),
392 m_itemEdited(itemEdit
)
397 m_aboutToFinish
= false;
401 owner
->GetItemRect(itemEdit
, rectLabel
);
403 m_text
->Create(owner
, wxID_ANY
, m_startValue
,
404 wxPoint(rectLabel
.x
+offset
,rectLabel
.y
),
405 wxSize(rectLabel
.width
-offset
,rectLabel
.height
));
408 m_text
->PushEventHandler(this);
411 void wxListCtrlTextCtrlWrapper::Finish()
417 m_text
->RemoveEventHandler(this);
418 m_owner
->FinishEditing(m_text
);
420 wxPendingDelete
.Append( this );
424 bool wxListCtrlTextCtrlWrapper::AcceptChanges()
426 const wxString value
= m_text
->GetValue();
428 if ( value
== m_startValue
)
429 // nothing changed, always accept
432 if ( !m_owner
->OnRenameAccept(m_itemEdited
, value
) )
433 // vetoed by the user
436 // accepted, do rename the item
437 m_owner
->SetItemText(m_itemEdited
, value
);
442 void wxListCtrlTextCtrlWrapper::AcceptChangesAndFinish()
444 m_aboutToFinish
= true;
446 // Notify the owner about the changes
449 // Even if vetoed, close the control (consistent with MSW)
453 void wxListCtrlTextCtrlWrapper::OnChar( wxKeyEvent
&event
)
455 switch ( event
.m_keyCode
)
458 AcceptChangesAndFinish();
462 m_owner
->OnRenameCancelled( m_itemEdited
);
471 void wxListCtrlTextCtrlWrapper::OnKeyUp( wxKeyEvent
&event
)
479 // auto-grow the textctrl:
480 wxSize parentSize
= m_owner
->GetSize();
481 wxPoint myPos
= m_text
->GetPosition();
482 wxSize mySize
= m_text
->GetSize();
484 m_text
->GetTextExtent(m_text
->GetValue() + _T("MM"), &sx
, &sy
);
485 if (myPos
.x
+ sx
> parentSize
.x
)
486 sx
= parentSize
.x
- myPos
.x
;
489 m_text
->SetSize(sx
, wxDefaultCoord
);
494 void wxListCtrlTextCtrlWrapper::OnKillFocus( wxFocusEvent
&event
)
496 if ( !m_finished
&& !m_aboutToFinish
)
498 if ( !AcceptChanges() )
499 m_owner
->OnRenameCancelled( m_itemEdited
);
504 // We must let the native text control handle focus
508 BEGIN_EVENT_TABLE(wxListCtrl
, wxControl
)
509 EVT_LEFT_DOWN(wxListCtrl::OnLeftDown
)
510 EVT_LEFT_DCLICK(wxListCtrl::OnDblClick
)
511 EVT_MIDDLE_DOWN(wxListCtrl::OnMiddleDown
)
512 EVT_RIGHT_DOWN(wxListCtrl::OnRightDown
)
513 EVT_CHAR(wxListCtrl::OnChar
)
516 // ============================================================================
518 // ============================================================================
520 wxMacListControl
* wxListCtrl::GetPeer() const
522 wxMacDataBrowserListCtrlControl
*lb
= wxDynamicCast(m_peer
,wxMacDataBrowserListCtrlControl
);
523 return lb
? wx_static_cast(wxMacListControl
*,lb
) : 0 ;
526 // ----------------------------------------------------------------------------
527 // wxListCtrl construction
528 // ----------------------------------------------------------------------------
530 void wxListCtrl::Init()
532 m_imageListNormal
= NULL
;
533 m_imageListSmall
= NULL
;
534 m_imageListState
= NULL
;
536 // keep track of if we created our own image lists, or if they were assigned
538 m_ownsImageListNormal
= m_ownsImageListSmall
= m_ownsImageListState
= false;
542 m_genericImpl
= NULL
;
544 m_compareFunc
= NULL
;
545 m_compareFuncData
= 0;
546 m_colsInfo
= wxColumnList();
547 m_textColor
= wxNullColour
;
548 m_bgColor
= wxNullColour
;
549 m_textctrlWrapper
= NULL
;
551 m_renameTimer
= new wxListCtrlRenameTimer( this );
554 class wxGenericListCtrlHook
: public wxGenericListCtrl
557 wxGenericListCtrlHook(wxListCtrl
* parent
,
562 const wxValidator
& validator
,
563 const wxString
& name
)
564 : wxGenericListCtrl(parent
, id
, pos
, size
, style
, validator
, name
),
565 m_nativeListCtrl(parent
)
570 virtual wxListItemAttr
* OnGetItemAttr(long item
) const
572 return m_nativeListCtrl
->OnGetItemAttr(item
);
575 virtual int OnGetItemImage(long item
) const
577 return m_nativeListCtrl
->OnGetItemImage(item
);
580 virtual int OnGetItemColumnImage(long item
, long column
) const
582 return m_nativeListCtrl
->OnGetItemColumnImage(item
, column
);
585 virtual wxString
OnGetItemText(long item
, long column
) const
587 return m_nativeListCtrl
->OnGetItemText(item
, column
);
590 wxListCtrl
* m_nativeListCtrl
;
594 void wxListCtrl::OnLeftDown(wxMouseEvent
& event
)
596 if ( m_textctrlWrapper
)
599 m_textctrlWrapper
->AcceptChangesAndFinish();
603 long current
= HitTest(event
.GetPosition(), hitResult
);
604 if ((current
== m_current
) &&
605 (hitResult
== wxLIST_HITTEST_ONITEM
) &&
606 HasFlag(wxLC_EDIT_LABELS
) )
608 m_renameTimer
->Start( 100, true );
617 void wxListCtrl::OnDblClick(wxMouseEvent
& event
)
623 #if wxABI_VERSION >= 20801
624 void wxListCtrl::OnRightDown(wxMouseEvent
& event
)
627 FireMouseEvent(wxEVT_COMMAND_LIST_ITEM_RIGHT_CLICK
, event
.GetPosition());
631 void wxListCtrl::OnMiddleDown(wxMouseEvent
& event
)
634 FireMouseEvent(wxEVT_COMMAND_LIST_ITEM_MIDDLE_CLICK
, event
.GetPosition());
638 void wxListCtrl::FireMouseEvent(wxEventType eventType
, wxPoint position
)
640 wxListEvent
le( eventType
, GetId() );
641 le
.SetEventObject(this);
642 le
.m_pointDrag
= position
;
646 long item
= HitTest(position
, flags
);
647 if (flags
& wxLIST_HITTEST_ONITEM
)
649 le
.m_itemIndex
= item
;
650 le
.m_item
.m_itemId
= item
;
652 HandleWindowEvent(le
);
656 void wxListCtrl::OnChar(wxKeyEvent
& event
)
662 wxListEvent
le( wxEVT_COMMAND_LIST_KEY_DOWN
, GetId() );
663 le
.SetEventObject(this);
664 le
.m_code
= event
.GetKeyCode();
669 // if m_current isn't set, check if there's been a selection
670 // made before continuing
671 m_current
= GetNextItem(-1, wxLIST_NEXT_BELOW
, wxLIST_STATE_SELECTED
);
674 // We need to determine m_current ourselves when navigation keys
675 // are used. Note that PAGEUP and PAGEDOWN do not alter the current
676 // item on native Mac ListCtrl, so we only handle up and down keys.
677 switch ( event
.GetKeyCode() )
688 if ( m_current
< GetItemCount() - 1 )
691 m_current
= GetItemCount() - 1;
698 le
.m_itemIndex
= m_current
;
699 le
.m_item
.m_itemId
= m_current
;
701 HandleWindowEvent(le
);
708 bool wxListCtrl::Create(wxWindow
*parent
,
713 const wxValidator
& validator
,
714 const wxString
& name
)
717 // for now, we'll always use the generic list control for ICON and LIST views,
718 // because they dynamically change the number of columns on resize.
719 // Also, allow the user to set it to use the list ctrl as well.
720 if ( (wxSystemOptions::HasOption( wxMAC_ALWAYS_USE_GENERIC_LISTCTRL
)
721 && (wxSystemOptions::GetOptionInt( wxMAC_ALWAYS_USE_GENERIC_LISTCTRL
) == 1)) ||
722 (style
& wxLC_ICON
) || (style
& wxLC_SMALL_ICON
) || (style
& wxLC_LIST
) )
724 m_macIsUserPane
= true;
726 long paneStyle
= style
;
727 paneStyle
&= ~wxSIMPLE_BORDER
;
728 paneStyle
&= ~wxDOUBLE_BORDER
;
729 paneStyle
&= ~wxSUNKEN_BORDER
;
730 paneStyle
&= ~wxRAISED_BORDER
;
731 paneStyle
&= ~wxSTATIC_BORDER
;
732 if ( !wxWindow::Create(parent
, id
, pos
, size
, paneStyle
| wxNO_BORDER
, name
) )
735 // since the generic control is a child, make sure we position it at 0, 0
736 m_genericImpl
= new wxGenericListCtrlHook(this, id
, wxPoint(0, 0), size
, style
, validator
, name
);
737 m_genericImpl
->PushEventHandler( new wxMacListCtrlEventDelegate( this, GetId() ) );
743 m_macIsUserPane
= false;
744 if ( !wxWindow::Create(parent
, id
, pos
, size
, style
& ~(wxHSCROLL
| wxVSCROLL
), name
) )
746 m_dbImpl
= new wxMacDataBrowserListCtrlControl( this, pos
, size
, style
);
749 MacPostControlCreate( pos
, size
);
751 InstallControlEventHandler( m_peer
->GetControlRef() , GetwxMacListCtrlEventHandlerUPP(),
752 GetEventTypeCount(eventList
), eventList
, this,
753 (EventHandlerRef
*)&m_macListCtrlEventHandler
);
759 wxListCtrl::~wxListCtrl()
763 m_genericImpl
->PopEventHandler(/* deleteHandler = */ true);
766 if (m_ownsImageListNormal
)
767 delete m_imageListNormal
;
768 if (m_ownsImageListSmall
)
769 delete m_imageListSmall
;
770 if (m_ownsImageListState
)
771 delete m_imageListState
;
773 delete m_renameTimer
;
778 wxListCtrl::GetClassDefaultAttributes(wxWindowVariant
WXUNUSED(variant
))
780 wxVisualAttributes attr
;
782 attr
.colFg
= wxSystemSettings::GetColour( wxSYS_COLOUR_WINDOWTEXT
);
783 attr
.colBg
= wxSystemSettings::GetColour( wxSYS_COLOUR_LISTBOX
);
784 attr
.font
.MacCreateFromThemeFont(kThemeViewsFont
);
789 // ----------------------------------------------------------------------------
790 // set/get/change style
791 // ----------------------------------------------------------------------------
793 // Add or remove a single window style
794 void wxListCtrl::SetSingleStyle(long style
, bool add
)
796 long flag
= GetWindowStyleFlag();
798 // Get rid of conflicting styles
801 if ( style
& wxLC_MASK_TYPE
)
802 flag
= flag
& ~wxLC_MASK_TYPE
;
803 if ( style
& wxLC_MASK_ALIGN
)
804 flag
= flag
& ~wxLC_MASK_ALIGN
;
805 if ( style
& wxLC_MASK_SORT
)
806 flag
= flag
& ~wxLC_MASK_SORT
;
814 SetWindowStyleFlag(flag
);
817 // Set the whole window style
818 void wxListCtrl::SetWindowStyleFlag(long flag
)
820 if ( flag
!= m_windowStyle
)
822 m_windowStyle
= flag
;
826 m_genericImpl
->SetWindowStyleFlag(flag
);
833 void wxListCtrl::DoSetSize( int x
, int y
, int width
, int height
, int sizeFlags
)
835 wxControl::DoSetSize(x
, y
, width
, height
, sizeFlags
);
838 m_genericImpl
->SetSize(0, 0, width
, height
, sizeFlags
);
840 // determine if we need a horizontal scrollbar, and add it if so
844 for (int column
= 0; column
< GetColumnCount(); column
++)
846 totalWidth
+= m_dbImpl
->GetColumnWidth( column
);
849 if ( !(m_dbImpl
->GetFlags() & wxHSCROLL
) )
851 Boolean vertScrollBar
;
852 GetDataBrowserHasScrollBars( m_dbImpl
->GetControlRef(), NULL
, &vertScrollBar
);
853 if (totalWidth
> width
)
854 SetDataBrowserHasScrollBars( m_dbImpl
->GetControlRef(), true, vertScrollBar
);
856 SetDataBrowserHasScrollBars( m_dbImpl
->GetControlRef(), false, vertScrollBar
);
861 wxSize
wxListCtrl::DoGetBestSize() const
863 return wxWindow::DoGetBestSize();
866 bool wxListCtrl::SetFont(const wxFont
& font
)
869 rv
= wxControl::SetFont(font
);
871 rv
= m_genericImpl
->SetFont(font
);
875 bool wxListCtrl::SetForegroundColour(const wxColour
& colour
)
879 rv
= m_genericImpl
->SetForegroundColour(colour
);
881 SetTextColour(colour
);
885 bool wxListCtrl::SetBackgroundColour(const wxColour
& colour
)
889 rv
= m_genericImpl
->SetBackgroundColour(colour
);
895 wxColour
wxListCtrl::GetBackgroundColour()
898 return m_genericImpl
->GetBackgroundColour();
905 // ----------------------------------------------------------------------------
907 // ----------------------------------------------------------------------------
909 // Gets information about this column
910 bool wxListCtrl::GetColumn(int col
, wxListItem
& item
) const
913 return m_genericImpl
->GetColumn(col
, item
);
919 wxColumnList::compatibility_iterator node
= m_colsInfo
.Item( col
);
920 wxASSERT_MSG( node
, _T("invalid column index in wxMacListCtrlItem") );
921 wxListItem
* column
= node
->GetData();
923 long mask
= column
->GetMask();
924 if (mask
& wxLIST_MASK_TEXT
)
925 item
.SetText(column
->GetText());
926 if (mask
& wxLIST_MASK_DATA
)
927 item
.SetData(column
->GetData());
928 if (mask
& wxLIST_MASK_IMAGE
)
929 item
.SetImage(column
->GetImage());
930 if (mask
& wxLIST_MASK_STATE
)
931 item
.SetState(column
->GetState());
932 if (mask
& wxLIST_MASK_FORMAT
)
933 item
.SetAlign(column
->GetAlign());
934 if (mask
& wxLIST_MASK_WIDTH
)
935 item
.SetWidth(column
->GetWidth());
941 // Sets information about this column
942 bool wxListCtrl::SetColumn(int col
, wxListItem
& item
)
945 return m_genericImpl
->SetColumn(col
, item
);
949 long mask
= item
.GetMask();
950 if ( col
>= (int)m_colsInfo
.GetCount() )
952 wxListItem
* listItem
= new wxListItem(item
);
953 m_colsInfo
.Append( listItem
);
958 GetColumn( col
, listItem
);
960 if (mask
& wxLIST_MASK_TEXT
)
961 listItem
.SetText(item
.GetText());
962 if (mask
& wxLIST_MASK_DATA
)
963 listItem
.SetData(item
.GetData());
964 if (mask
& wxLIST_MASK_IMAGE
)
965 listItem
.SetImage(item
.GetImage());
966 if (mask
& wxLIST_MASK_STATE
)
967 listItem
.SetState(item
.GetState());
968 if (mask
& wxLIST_MASK_FORMAT
)
969 listItem
.SetAlign(item
.GetAlign());
970 if (mask
& wxLIST_MASK_WIDTH
)
971 listItem
.SetWidth(item
.GetWidth());
974 // change the appearance in the databrowser.
975 DataBrowserListViewHeaderDesc columnDesc
;
976 columnDesc
.version
=kDataBrowserListViewLatestHeaderDesc
;
977 verify_noerr( m_dbImpl
->GetHeaderDesc( kMinColumnId
+ col
, &columnDesc
) );
980 if (item.GetMask() & wxLIST_MASK_TEXT)
984 enc = GetFont().GetEncoding();
986 enc = wxLocale::GetSystemEncoding();
987 wxCFStringRef cfTitle;
988 cfTitle.Assign( item.GetText() , enc );
989 if(columnDesc.titleString)
990 CFRelease(columnDesc.titleString);
991 columnDesc.titleString = cfTitle;
995 if (item
.GetMask() & wxLIST_MASK_IMAGE
&& item
.GetImage() != -1 )
997 wxImageList
* imageList
= GetImageList(wxIMAGE_LIST_SMALL
);
998 if (imageList
&& imageList
->GetImageCount() > 0 )
1000 wxBitmap bmp
= imageList
->GetBitmap( item
.GetImage() );
1001 IconRef icon
= bmp
.GetIconRef();
1002 columnDesc
.btnContentInfo
.u
.iconRef
= icon
;
1003 columnDesc
.btnContentInfo
.contentType
= kControlContentIconRef
;
1007 verify_noerr( m_dbImpl
->SetHeaderDesc( kMinColumnId
+ col
, &columnDesc
) );
1013 int wxListCtrl::GetColumnCount() const
1016 return m_genericImpl
->GetColumnCount();
1021 m_dbImpl
->GetColumnCount(&count
);
1028 // Gets the column width
1029 int wxListCtrl::GetColumnWidth(int col
) const
1032 return m_genericImpl
->GetColumnWidth(col
);
1036 return m_dbImpl
->GetColumnWidth(col
);
1042 // Sets the column width
1043 bool wxListCtrl::SetColumnWidth(int col
, int width
)
1046 return m_genericImpl
->SetColumnWidth(col
, width
);
1050 int mywidth
= width
;
1051 if (width
== wxLIST_AUTOSIZE
|| width
== wxLIST_AUTOSIZE_USEHEADER
)
1056 for (int column
= 0; column
< GetColumnCount(); column
++)
1059 GetColumn(col
, colInfo
);
1061 colInfo
.SetWidth(width
);
1062 SetColumn(col
, colInfo
);
1064 m_dbImpl
->SetColumnWidth(col
, mywidth
);
1070 GetColumn(col
, colInfo
);
1072 colInfo
.SetWidth(width
);
1073 SetColumn(col
, colInfo
);
1074 m_dbImpl
->SetColumnWidth(col
, mywidth
);
1082 // Gets the number of items that can fit vertically in the
1083 // visible area of the list control (list or report view)
1084 // or the total number of items in the list control (icon
1085 // or small icon view)
1086 int wxListCtrl::GetCountPerPage() const
1089 return m_genericImpl
->GetCountPerPage();
1094 m_dbImpl
->GetDefaultRowHeight( &height
);
1096 return GetClientSize().y
/ height
;
1102 // Gets the edit control for editing labels.
1103 wxTextCtrl
* wxListCtrl::GetEditControl() const
1106 return m_genericImpl
->GetEditControl();
1111 // Gets information about the item
1112 bool wxListCtrl::GetItem(wxListItem
& info
) const
1115 return m_genericImpl
->GetItem(info
);
1121 if (info
.m_itemId
>= 0 && info
.m_itemId
< GetItemCount())
1123 m_dbImpl
->MacGetColumnInfo(info
.m_itemId
, info
.m_col
, info
);
1124 if (info
.GetMask() & wxLIST_MASK_STATE
)
1126 DataBrowserItemID id
= (DataBrowserItemID
)m_dbImpl
->GetItemFromLine(info
.m_itemId
);
1127 if (IsDataBrowserItemSelected( m_dbImpl
->GetControlRef(), id
))
1128 info
.SetState(info
.GetState() | wxLIST_STATE_SELECTED
);
1134 if (info
.m_itemId
>= 0 && info
.m_itemId
< GetItemCount())
1136 info
.SetText( OnGetItemText(info
.m_itemId
, info
.m_col
) );
1137 info
.SetImage( OnGetItemColumnImage(info
.m_itemId
, info
.m_col
) );
1138 if (info
.GetMask() & wxLIST_MASK_STATE
)
1140 if (IsDataBrowserItemSelected( m_dbImpl
->GetControlRef(), info
.m_itemId
+1 ))
1141 info
.SetState(info
.GetState() | wxLIST_STATE_SELECTED
);
1144 wxListItemAttr
* attrs
= OnGetItemAttr( info
.m_itemId
);
1147 info
.SetFont( attrs
->GetFont() );
1148 info
.SetBackgroundColour( attrs
->GetBackgroundColour() );
1149 info
.SetTextColour( attrs
->GetTextColour() );
1154 bool success
= true;
1158 // Sets information about the item
1159 bool wxListCtrl::SetItem(wxListItem
& info
)
1162 return m_genericImpl
->SetItem(info
);
1165 m_dbImpl
->MacSetColumnInfo( info
.m_itemId
, info
.m_col
, &info
);
1170 long wxListCtrl::SetItem(long index
, int col
, const wxString
& label
, int imageId
)
1173 return m_genericImpl
->SetItem(index
, col
, label
, imageId
);
1176 info
.m_text
= label
;
1177 info
.m_mask
= wxLIST_MASK_TEXT
;
1178 info
.m_itemId
= index
;
1182 info
.m_image
= imageId
;
1183 info
.m_mask
|= wxLIST_MASK_IMAGE
;
1185 return SetItem(info
);
1189 // Gets the item state
1190 int wxListCtrl::GetItemState(long item
, long stateMask
) const
1193 return m_genericImpl
->GetItemState(item
, stateMask
);
1197 if ( HasFlag(wxLC_VIRTUAL
) )
1199 if (stateMask
== wxLIST_STATE_SELECTED
)
1201 if (IsDataBrowserItemSelected( m_dbImpl
->GetControlRef(), item
+1 ))
1202 return wxLIST_STATE_SELECTED
;
1211 info
.m_mask
= wxLIST_MASK_STATE
;
1212 info
.m_stateMask
= stateMask
;
1213 info
.m_itemId
= item
;
1218 return info
.m_state
;
1225 // Sets the item state
1226 bool wxListCtrl::SetItemState(long item
, long state
, long stateMask
)
1229 return m_genericImpl
->SetItemState(item
, state
, stateMask
);
1233 DataBrowserSetOption option
= kDataBrowserItemsAdd
;
1234 if ( (stateMask
& wxLIST_STATE_SELECTED
) && state
== 0 )
1235 option
= kDataBrowserItemsRemove
;
1239 if ( HasFlag(wxLC_VIRTUAL
) )
1241 wxMacDataItemBrowserSelectionSuppressor
suppressor(m_dbImpl
);
1242 m_dbImpl
->SetSelectedAllItems(option
);
1246 for(int i
= 0; i
< GetItemCount();i
++)
1250 info
.m_mask
= wxLIST_MASK_STATE
;
1251 info
.m_stateMask
= stateMask
;
1252 info
.m_state
= state
;
1259 if ( HasFlag(wxLC_VIRTUAL
) )
1261 long itemID
= item
+1;
1262 bool isSelected
= IsDataBrowserItemSelected(m_dbImpl
->GetControlRef(), (DataBrowserItemID
)itemID
);
1263 bool isSelectedState
= (state
== wxLIST_STATE_SELECTED
);
1265 // toggle the selection state if wxListInfo state and actual state don't match.
1266 if ( (stateMask
& wxLIST_STATE_SELECTED
) && isSelected
!= isSelectedState
)
1268 SetDataBrowserSelectedItems(m_dbImpl
->GetControlRef(), 1, (DataBrowserItemID
*)&itemID
, option
);
1274 info
.m_itemId
= item
;
1275 info
.m_mask
= wxLIST_MASK_STATE
;
1276 info
.m_stateMask
= stateMask
;
1277 info
.m_state
= state
;
1278 return SetItem(info
);
1285 // Sets the item image
1286 bool wxListCtrl::SetItemImage(long item
, int image
, int WXUNUSED(selImage
))
1288 return SetItemColumnImage(item
, 0, image
);
1291 // Sets the item image
1292 bool wxListCtrl::SetItemColumnImage(long item
, long column
, int image
)
1295 return m_genericImpl
->SetItemColumnImage(item
, column
, image
);
1299 info
.m_mask
= wxLIST_MASK_IMAGE
;
1300 info
.m_image
= image
;
1301 info
.m_itemId
= item
;
1302 info
.m_col
= column
;
1304 return SetItem(info
);
1307 // Gets the item text
1308 wxString
wxListCtrl::GetItemText(long item
) const
1311 return m_genericImpl
->GetItemText(item
);
1315 info
.m_mask
= wxLIST_MASK_TEXT
;
1316 info
.m_itemId
= item
;
1319 return wxEmptyString
;
1323 // Sets the item text
1324 void wxListCtrl::SetItemText(long item
, const wxString
& str
)
1327 return m_genericImpl
->SetItemText(item
, str
);
1331 info
.m_mask
= wxLIST_MASK_TEXT
;
1332 info
.m_itemId
= item
;
1338 // Gets the item data
1339 long wxListCtrl::GetItemData(long item
) const
1342 return m_genericImpl
->GetItemData(item
);
1346 info
.m_mask
= wxLIST_MASK_DATA
;
1347 info
.m_itemId
= item
;
1354 // Sets the item data
1355 bool wxListCtrl::SetItemPtrData(long item
, wxUIntPtr data
)
1358 return m_genericImpl
->SetItemData(item
, data
);
1362 info
.m_mask
= wxLIST_MASK_DATA
;
1363 info
.m_itemId
= item
;
1366 return SetItem(info
);
1369 wxRect
wxListCtrl::GetViewRect() const
1371 wxASSERT_MSG( !HasFlag(wxLC_REPORT
| wxLC_LIST
),
1372 _T("wxListCtrl::GetViewRect() only works in icon mode") );
1375 return m_genericImpl
->GetViewRect();
1381 // Gets the item rectangle
1382 bool wxListCtrl::GetItemRect(long item
, wxRect
& rect
, int code
) const
1385 return m_genericImpl
->GetItemRect(item
, rect
, code
);
1390 DataBrowserItemID id
;
1391 DataBrowserPropertyID col
= kMinColumnId
;
1393 DataBrowserPropertyPart part
= kDataBrowserPropertyEnclosingPart
;
1394 if ( code
== wxLIST_RECT_LABEL
)
1395 part
= kDataBrowserPropertyTextPart
;
1396 else if ( code
== wxLIST_RECT_ICON
)
1397 part
= kDataBrowserPropertyIconPart
;
1399 if ( !(GetWindowStyleFlag() & wxLC_VIRTUAL
) )
1401 wxMacDataItem
* thisItem
= m_dbImpl
->GetItemFromLine(item
);
1402 id
= (DataBrowserItemID
) thisItem
;
1407 GetDataBrowserItemPartBounds( m_dbImpl
->GetControlRef(), id
, col
, part
, &bounds
);
1409 rect
.x
= bounds
.left
;
1410 rect
.y
= bounds
.top
;
1411 rect
.width
= bounds
.right
- bounds
.left
; //GetClientSize().x; // we need the width of the whole row, not just the item.
1412 rect
.height
= bounds
.bottom
- bounds
.top
;
1413 //fprintf("id = %d, bounds = %d, %d, %d, %d\n", id, rect.x, rect.y, rect.width, rect.height);
1418 // Gets the item position
1419 bool wxListCtrl::GetItemPosition(long item
, wxPoint
& pos
) const
1422 return m_genericImpl
->GetItemPosition(item
, pos
);
1424 bool success
= false;
1429 GetItemRect(item
, itemRect
);
1430 pos
= itemRect
.GetPosition();
1437 // Sets the item position.
1438 bool wxListCtrl::SetItemPosition(long item
, const wxPoint
& pos
)
1441 return m_genericImpl
->SetItemPosition(item
, pos
);
1446 // Gets the number of items in the list control
1447 int wxListCtrl::GetItemCount() const
1450 return m_genericImpl
->GetItemCount();
1453 return m_dbImpl
->MacGetCount();
1458 void wxListCtrl::SetItemSpacing( int spacing
, bool isSmall
)
1461 m_genericImpl
->SetItemSpacing(spacing
, isSmall
);
1464 wxSize
wxListCtrl::GetItemSpacing() const
1467 return m_genericImpl
->GetItemSpacing();
1469 return wxSize(0, 0);
1472 void wxListCtrl::SetItemTextColour( long item
, const wxColour
&col
)
1476 m_genericImpl
->SetItemTextColour(item
, col
);
1481 info
.m_itemId
= item
;
1482 info
.SetTextColour( col
);
1486 wxColour
wxListCtrl::GetItemTextColour( long item
) const
1489 return m_genericImpl
->GetItemTextColour(item
);
1495 return info
.GetTextColour();
1497 return wxNullColour
;
1500 void wxListCtrl::SetItemBackgroundColour( long item
, const wxColour
&col
)
1504 m_genericImpl
->SetItemBackgroundColour(item
, col
);
1509 info
.m_itemId
= item
;
1510 info
.SetBackgroundColour( col
);
1514 wxColour
wxListCtrl::GetItemBackgroundColour( long item
) const
1517 return m_genericImpl
->GetItemBackgroundColour(item
);
1523 return info
.GetBackgroundColour();
1525 return wxNullColour
;
1528 void wxListCtrl::SetItemFont( long item
, const wxFont
&f
)
1532 m_genericImpl
->SetItemFont(item
, f
);
1537 info
.m_itemId
= item
;
1542 wxFont
wxListCtrl::GetItemFont( long item
) const
1545 return m_genericImpl
->GetItemFont(item
);
1551 return info
.GetFont();
1557 // Gets the number of selected items in the list control
1558 int wxListCtrl::GetSelectedItemCount() const
1561 return m_genericImpl
->GetSelectedItemCount();
1564 return m_dbImpl
->GetSelectedItemCount(NULL
, true);
1569 // Gets the text colour of the listview
1570 wxColour
wxListCtrl::GetTextColour() const
1573 return m_genericImpl
->GetTextColour();
1575 // TODO: we need owner drawn list items to customize text color.
1579 return wxNullColour
;
1582 // Sets the text colour of the listview
1583 void wxListCtrl::SetTextColour(const wxColour
& col
)
1587 m_genericImpl
->SetTextColour(col
);
1595 // Gets the index of the topmost visible item when in
1596 // list or report view
1597 long wxListCtrl::GetTopItem() const
1600 return m_genericImpl
->GetTopItem();
1605 long item
= HitTest( wxPoint(1, 1), flags
);
1606 if (flags
== wxLIST_HITTEST_ONITEM
)
1613 // Searches for an item, starting from 'item'.
1614 // 'geometry' is one of
1615 // wxLIST_NEXT_ABOVE/ALL/BELOW/LEFT/RIGHT.
1616 // 'state' is a state bit flag, one or more of
1617 // wxLIST_STATE_DROPHILITED/FOCUSED/SELECTED/CUT.
1618 // item can be -1 to find the first item that matches the
1620 // Returns the item or -1 if unsuccessful.
1621 long wxListCtrl::GetNextItem(long item
, int geom
, int state
) const
1624 return m_genericImpl
->GetNextItem(item
, geom
, state
);
1626 // TODO: implement all geometry and state options?
1629 if ( geom
== wxLIST_NEXT_ALL
|| geom
== wxLIST_NEXT_BELOW
)
1631 long count
= m_dbImpl
->MacGetCount() ;
1632 for ( long line
= item
+ 1 ; line
< count
; line
++ )
1634 DataBrowserItemID id
= line
+ 1;
1636 id
= (DataBrowserItemID
)m_dbImpl
->GetItemFromLine(line
);
1638 if ( (state
== wxLIST_STATE_DONTCARE
) )
1641 if ( (state
& wxLIST_STATE_SELECTED
) && IsDataBrowserItemSelected(m_dbImpl
->GetControlRef(), id
) )
1646 if ( geom
== wxLIST_NEXT_ABOVE
)
1650 item2
= m_dbImpl
->MacGetCount();
1652 for ( long line
= item2
- 1 ; line
>= 0; line
-- )
1654 DataBrowserItemID id
= line
+ 1;
1656 id
= (DataBrowserItemID
)m_dbImpl
->GetItemFromLine(line
);
1658 if ( (state
== wxLIST_STATE_DONTCARE
) )
1661 if ( (state
& wxLIST_STATE_SELECTED
) && IsDataBrowserItemSelected(m_dbImpl
->GetControlRef(), id
) )
1671 wxImageList
*wxListCtrl::GetImageList(int which
) const
1674 return m_genericImpl
->GetImageList(which
);
1676 if ( which
== wxIMAGE_LIST_NORMAL
)
1678 return m_imageListNormal
;
1680 else if ( which
== wxIMAGE_LIST_SMALL
)
1682 return m_imageListSmall
;
1684 else if ( which
== wxIMAGE_LIST_STATE
)
1686 return m_imageListState
;
1691 void wxListCtrl::SetImageList(wxImageList
*imageList
, int which
)
1695 m_genericImpl
->SetImageList(imageList
, which
);
1699 if ( which
== wxIMAGE_LIST_NORMAL
)
1701 if (m_ownsImageListNormal
) delete m_imageListNormal
;
1702 m_imageListNormal
= imageList
;
1703 m_ownsImageListNormal
= false;
1705 else if ( which
== wxIMAGE_LIST_SMALL
)
1707 if (m_ownsImageListSmall
) delete m_imageListSmall
;
1708 m_imageListSmall
= imageList
;
1709 m_ownsImageListSmall
= false;
1711 else if ( which
== wxIMAGE_LIST_STATE
)
1713 if (m_ownsImageListState
) delete m_imageListState
;
1714 m_imageListState
= imageList
;
1715 m_ownsImageListState
= false;
1719 void wxListCtrl::AssignImageList(wxImageList
*imageList
, int which
)
1723 m_genericImpl
->AssignImageList(imageList
, which
);
1727 SetImageList(imageList
, which
);
1728 if ( which
== wxIMAGE_LIST_NORMAL
)
1729 m_ownsImageListNormal
= true;
1730 else if ( which
== wxIMAGE_LIST_SMALL
)
1731 m_ownsImageListSmall
= true;
1732 else if ( which
== wxIMAGE_LIST_STATE
)
1733 m_ownsImageListState
= true;
1736 // ----------------------------------------------------------------------------
1738 // ----------------------------------------------------------------------------
1740 // Arranges the items
1741 bool wxListCtrl::Arrange(int flag
)
1744 return m_genericImpl
->Arrange(flag
);
1749 bool wxListCtrl::DeleteItem(long item
)
1752 return m_genericImpl
->DeleteItem(item
);
1756 m_dbImpl
->MacDelete(item
);
1757 wxListEvent
event( wxEVT_COMMAND_LIST_DELETE_ITEM
, GetId() );
1758 event
.SetEventObject( this );
1759 event
.m_itemIndex
= item
;
1760 HandleWindowEvent( event
);
1766 // Deletes all items
1767 bool wxListCtrl::DeleteAllItems()
1770 return m_genericImpl
->DeleteAllItems();
1774 m_dbImpl
->MacClear();
1775 wxListEvent
event( wxEVT_COMMAND_LIST_DELETE_ALL_ITEMS
, GetId() );
1776 event
.SetEventObject( this );
1777 HandleWindowEvent( event
);
1782 // Deletes all items
1783 bool wxListCtrl::DeleteAllColumns()
1786 return m_genericImpl
->DeleteAllColumns();
1791 m_dbImpl
->GetColumnCount(&cols
);
1792 for (UInt32 col
= 0; col
< cols
; col
++)
1802 bool wxListCtrl::DeleteColumn(int col
)
1805 return m_genericImpl
->DeleteColumn(col
);
1809 OSStatus err
= m_dbImpl
->RemoveColumn(col
);
1810 return err
== noErr
;
1816 // Clears items, and columns if there are any.
1817 void wxListCtrl::ClearAll()
1821 m_genericImpl
->ClearAll();
1832 wxTextCtrl
* wxListCtrl::EditLabel(long item
, wxClassInfo
* textControlClass
)
1835 return m_genericImpl
->EditLabel(item
, textControlClass
);
1839 wxCHECK_MSG( (item
>= 0) && ((long)item
< GetItemCount()), NULL
,
1840 wxT("wrong index in wxListCtrl::EditLabel()") );
1842 wxASSERT_MSG( textControlClass
->IsKindOf(CLASSINFO(wxTextCtrl
)),
1843 wxT("EditLabel() needs a text control") );
1845 wxListEvent
le( wxEVT_COMMAND_LIST_BEGIN_LABEL_EDIT
, GetParent()->GetId() );
1846 le
.SetEventObject( this );
1847 le
.m_itemIndex
= item
;
1849 GetItem( le
.m_item
);
1851 if ( GetParent()->HandleWindowEvent( le
) && !le
.IsAllowed() )
1853 // vetoed by user code
1857 wxTextCtrl
* const text
= (wxTextCtrl
*)textControlClass
->CreateObject();
1858 m_textctrlWrapper
= new wxListCtrlTextCtrlWrapper(this, text
, item
);
1859 return m_textctrlWrapper
->GetText();
1864 // End label editing, optionally cancelling the edit
1865 bool wxListCtrl::EndEditLabel(bool WXUNUSED(cancel
))
1867 // TODO: generic impl. doesn't have this method - is it needed for us?
1869 return true; // m_genericImpl->EndEditLabel(cancel);
1872 verify_noerr( SetDataBrowserEditItem(m_dbImpl
->GetControlRef(), kDataBrowserNoItem
, kMinColumnId
) );
1876 // Ensures this item is visible
1877 bool wxListCtrl::EnsureVisible(long item
)
1880 return m_genericImpl
->EnsureVisible(item
);
1884 wxMacDataItem
* dataItem
= m_dbImpl
->GetItemFromLine(item
);
1885 m_dbImpl
->RevealItem(dataItem
, kDataBrowserRevealWithoutSelecting
);
1891 // Find an item whose label matches this string, starting from the item after 'start'
1892 // or the beginning if 'start' is -1.
1893 long wxListCtrl::FindItem(long start
, const wxString
& str
, bool partial
)
1896 return m_genericImpl
->FindItem(start
, str
, partial
);
1898 wxString str_upper
= str
.Upper();
1903 long count
= GetItemCount();
1907 wxString line_upper
= GetItemText(idx
).Upper();
1910 if (line_upper
== str_upper
)
1915 if (line_upper
.find(str_upper
) == 0)
1925 // Find an item whose data matches this data, starting from the item after 'start'
1926 // or the beginning if 'start' is -1.
1927 long wxListCtrl::FindItem(long start
, long data
)
1930 return m_genericImpl
->FindItem(start
, data
);
1935 long count
= GetItemCount();
1939 if (GetItemData(idx
) == data
)
1947 // Find an item nearest this position in the specified direction, starting from
1948 // the item after 'start' or the beginning if 'start' is -1.
1949 long wxListCtrl::FindItem(long start
, const wxPoint
& pt
, int direction
)
1952 return m_genericImpl
->FindItem(start
, pt
, direction
);
1956 // Determines which item (if any) is at the specified point,
1957 // giving details in 'flags' (see wxLIST_HITTEST_... flags above)
1959 wxListCtrl::HitTest(const wxPoint
& point
, int& flags
, long *ptrSubItem
) const
1962 return m_genericImpl
->HitTest(point
, flags
, ptrSubItem
);
1964 flags
= wxLIST_HITTEST_NOWHERE
;
1967 int colHeaderHeight
= 22; // TODO: Find a way to get this value from the db control?
1968 UInt16 rowHeight
= 0;
1969 m_dbImpl
->GetDefaultRowHeight(&rowHeight
);
1972 // get the actual row by taking scroll position into account
1973 UInt32 offsetX
, offsetY
;
1974 m_dbImpl
->GetScrollPosition( &offsetY
, &offsetX
);
1977 if ( !(GetWindowStyleFlag() & wxLC_NO_HEADER
) )
1978 y
-= colHeaderHeight
;
1983 int row
= y
/ rowHeight
;
1984 DataBrowserItemID id
;
1985 m_dbImpl
->GetItemID( (DataBrowserTableViewRowIndex
) row
, &id
);
1987 // TODO: Use GetDataBrowserItemPartBounds to return if we are in icon or label
1988 if ( !(GetWindowStyleFlag() & wxLC_VIRTUAL
) )
1990 wxMacListCtrlItem
* lcItem
;
1991 lcItem
= (wxMacListCtrlItem
*) id
;
1994 flags
= wxLIST_HITTEST_ONITEM
;
2000 if (row
< GetItemCount() )
2002 flags
= wxLIST_HITTEST_ONITEM
;
2011 int wxListCtrl::GetScrollPos(int orient
) const
2014 return m_genericImpl
->GetScrollPos(orient
);
2018 UInt32 offsetX
, offsetY
;
2019 m_dbImpl
->GetScrollPosition( &offsetY
, &offsetX
);
2020 if ( orient
== wxHORIZONTAL
)
2029 // Inserts an item, returning the index of the new item if successful,
2031 long wxListCtrl::InsertItem(wxListItem
& info
)
2033 wxASSERT_MSG( !IsVirtual(), _T("can't be used with virtual controls") );
2036 return m_genericImpl
->InsertItem(info
);
2038 if (m_dbImpl
&& !IsVirtual())
2040 int count
= GetItemCount();
2042 if (info
.m_itemId
> count
)
2043 info
.m_itemId
= count
;
2045 m_dbImpl
->MacInsertItem(info
.m_itemId
, &info
);
2047 wxListEvent
event( wxEVT_COMMAND_LIST_INSERT_ITEM
, GetId() );
2048 event
.SetEventObject( this );
2049 event
.m_itemIndex
= info
.m_itemId
;
2050 HandleWindowEvent( event
);
2051 return info
.m_itemId
;
2056 long wxListCtrl::InsertItem(long index
, const wxString
& label
)
2059 return m_genericImpl
->InsertItem(index
, label
);
2062 info
.m_text
= label
;
2063 info
.m_mask
= wxLIST_MASK_TEXT
;
2064 info
.m_itemId
= index
;
2065 return InsertItem(info
);
2068 // Inserts an image item
2069 long wxListCtrl::InsertItem(long index
, int imageIndex
)
2072 return m_genericImpl
->InsertItem(index
, imageIndex
);
2075 info
.m_image
= imageIndex
;
2076 info
.m_mask
= wxLIST_MASK_IMAGE
;
2077 info
.m_itemId
= index
;
2078 return InsertItem(info
);
2081 // Inserts an image/string item
2082 long wxListCtrl::InsertItem(long index
, const wxString
& label
, int imageIndex
)
2085 return m_genericImpl
->InsertItem(index
, label
, imageIndex
);
2088 info
.m_image
= imageIndex
;
2089 info
.m_text
= label
;
2090 info
.m_mask
= wxLIST_MASK_IMAGE
| wxLIST_MASK_TEXT
;
2091 info
.m_itemId
= index
;
2092 return InsertItem(info
);
2095 // For list view mode (only), inserts a column.
2096 long wxListCtrl::InsertColumn(long col
, wxListItem
& item
)
2099 return m_genericImpl
->InsertColumn(col
, item
);
2103 int width
= item
.GetWidth();
2104 if ( !(item
.GetMask() & wxLIST_MASK_WIDTH
) )
2107 DataBrowserPropertyType type
= kDataBrowserCustomType
; //kDataBrowserTextType;
2108 wxImageList
* imageList
= GetImageList(wxIMAGE_LIST_SMALL
);
2109 if (imageList
&& imageList
->GetImageCount() > 0)
2111 wxBitmap bmp
= imageList
->GetBitmap(0);
2113 // type = kDataBrowserIconAndTextType;
2116 SInt16 just
= teFlushDefault
;
2117 if (item
.GetMask() & wxLIST_MASK_FORMAT
)
2119 if (item
.GetAlign() == wxLIST_FORMAT_LEFT
)
2121 else if (item
.GetAlign() == wxLIST_FORMAT_CENTER
)
2123 else if (item
.GetAlign() == wxLIST_FORMAT_RIGHT
)
2124 just
= teFlushRight
;
2126 m_dbImpl
->InsertColumn(col
, type
, item
.GetText(), just
, width
);
2127 SetColumn(col
, item
);
2129 // set/remove options based on the wxListCtrl type.
2130 DataBrowserTableViewColumnID id
;
2131 m_dbImpl
->GetColumnIDFromIndex(col
, &id
);
2132 DataBrowserPropertyFlags flags
;
2133 verify_noerr(m_dbImpl
->GetPropertyFlags(id
, &flags
));
2134 if (GetWindowStyleFlag() & wxLC_EDIT_LABELS
)
2135 flags
|= kDataBrowserPropertyIsEditable
;
2137 if (GetWindowStyleFlag() & wxLC_VIRTUAL
){
2138 flags
&= ~kDataBrowserListViewSortableColumn
;
2140 verify_noerr(m_dbImpl
->SetPropertyFlags(id
, flags
));
2146 long wxListCtrl::InsertColumn(long col
,
2147 const wxString
& heading
,
2152 return m_genericImpl
->InsertColumn(col
, heading
, format
, width
);
2155 item
.m_mask
= wxLIST_MASK_TEXT
| wxLIST_MASK_FORMAT
;
2156 item
.m_text
= heading
;
2159 item
.m_mask
|= wxLIST_MASK_WIDTH
;
2160 item
.m_width
= width
;
2162 item
.m_format
= format
;
2164 return InsertColumn(col
, item
);
2167 // scroll the control by the given number of pixels (exception: in list view,
2168 // dx is interpreted as number of columns)
2169 bool wxListCtrl::ScrollList(int dx
, int dy
)
2172 return m_genericImpl
->ScrollList(dx
, dy
);
2176 m_dbImpl
->SetScrollPosition(dx
, dy
);
2182 bool wxListCtrl::SortItems(wxListCtrlCompare fn
, long data
)
2185 return m_genericImpl
->SortItems(fn
, data
);
2190 m_compareFuncData
= data
;
2191 SortDataBrowserContainer( m_dbImpl
->GetControlRef(), kDataBrowserNoItem
, true);
2193 // we need to do this after each call, else we get a crash from wxPython when
2194 // SortItems is called the second time.
2195 m_compareFunc
= NULL
;
2196 m_compareFuncData
= 0;
2202 void wxListCtrl::OnRenameTimer()
2204 wxCHECK_RET( HasCurrent(), wxT("unexpected rename timer") );
2206 EditLabel( m_current
);
2209 bool wxListCtrl::OnRenameAccept(long itemEdit
, const wxString
& value
)
2211 wxListEvent
le( wxEVT_COMMAND_LIST_END_LABEL_EDIT
, GetId() );
2212 le
.SetEventObject( this );
2213 le
.m_itemIndex
= itemEdit
;
2215 GetItem( le
.m_item
);
2216 le
.m_item
.m_text
= value
;
2217 return !HandleWindowEvent( le
) ||
2221 void wxListCtrl::OnRenameCancelled(long itemEdit
)
2223 // let owner know that the edit was cancelled
2224 wxListEvent
le( wxEVT_COMMAND_LIST_END_LABEL_EDIT
, GetParent()->GetId() );
2226 le
.SetEditCanceled(true);
2228 le
.SetEventObject( this );
2229 le
.m_itemIndex
= itemEdit
;
2231 GetItem( le
.m_item
);
2232 HandleWindowEvent( le
);
2235 // ----------------------------------------------------------------------------
2236 // virtual list controls
2237 // ----------------------------------------------------------------------------
2239 wxString
wxListCtrl::OnGetItemText(long WXUNUSED(item
), long WXUNUSED(col
)) const
2241 // this is a pure virtual function, in fact - which is not really pure
2242 // because the controls which are not virtual don't need to implement it
2243 wxFAIL_MSG( _T("wxListCtrl::OnGetItemText not supposed to be called") );
2245 return wxEmptyString
;
2248 int wxListCtrl::OnGetItemImage(long WXUNUSED(item
)) const
2250 wxCHECK_MSG(!GetImageList(wxIMAGE_LIST_SMALL
),
2252 wxT("List control has an image list, OnGetItemImage or OnGetItemColumnImage should be overridden."));
2256 int wxListCtrl::OnGetItemColumnImage(long item
, long column
) const
2259 return OnGetItemImage(item
);
2264 wxListItemAttr
*wxListCtrl::OnGetItemAttr(long WXUNUSED_UNLESS_DEBUG(item
)) const
2266 wxASSERT_MSG( item
>= 0 && item
< GetItemCount(),
2267 _T("invalid item index in OnGetItemAttr()") );
2269 // no attributes by default
2273 void wxListCtrl::SetItemCount(long count
)
2275 wxASSERT_MSG( IsVirtual(), _T("this is for virtual controls only") );
2279 m_genericImpl
->SetItemCount(count
);
2285 // we need to temporarily disable the new item creation notification
2286 // procedure to speed things up
2287 // FIXME: Even this doesn't seem to help much...
2289 // FIXME: Find a more efficient way to do this.
2290 m_dbImpl
->MacClear();
2292 DataBrowserCallbacks callbacks
;
2293 DataBrowserItemNotificationUPP itemUPP
;
2294 GetDataBrowserCallbacks(m_dbImpl
->GetControlRef(), &callbacks
);
2295 itemUPP
= callbacks
.u
.v1
.itemNotificationCallback
;
2296 callbacks
.u
.v1
.itemNotificationCallback
= 0;
2297 m_dbImpl
->SetCallbacks(&callbacks
);
2298 ::AddDataBrowserItems(m_dbImpl
->GetControlRef(), kDataBrowserNoItem
,
2299 count
, NULL
, kDataBrowserItemNoProperty
);
2300 callbacks
.u
.v1
.itemNotificationCallback
= itemUPP
;
2301 m_dbImpl
->SetCallbacks(&callbacks
);
2306 void wxListCtrl::RefreshItem(long item
)
2310 m_genericImpl
->RefreshItem(item
);
2316 DataBrowserItemID id
;
2320 wxMacDataItem
* thisItem
= m_dbImpl
->GetItemFromLine(item
);
2321 id
= (DataBrowserItemID
) thisItem
;
2326 m_dbImpl
->wxMacDataBrowserControl::UpdateItems
2330 kDataBrowserItemNoProperty
, // preSortProperty
2331 kDataBrowserNoItem
// update all columns
2336 void wxListCtrl::RefreshItems(long itemFrom
, long itemTo
)
2340 m_genericImpl
->RefreshItems(itemFrom
, itemTo
);
2346 const long count
= itemTo
- itemFrom
+ 1;
2347 DataBrowserItemID
*ids
= new DataBrowserItemID
[count
];
2351 for ( long i
= 0; i
< count
; i
++ )
2353 wxMacDataItem
* thisItem
= m_dbImpl
->GetItemFromLine(itemFrom
+i
);
2354 ids
[i
] = (DataBrowserItemID
) thisItem
;
2359 for ( long i
= 0; i
< count
; i
++ )
2360 ids
[i
] = itemFrom
+i
+1;
2363 m_dbImpl
->wxMacDataBrowserControl::UpdateItems
2367 kDataBrowserItemNoProperty
, // preSortProperty
2368 kDataBrowserNoItem
// update all columns
2375 void wxListCtrl::SetDropTarget( wxDropTarget
*dropTarget
)
2377 #if wxUSE_DRAG_AND_DROP
2379 m_genericImpl
->SetDropTarget( dropTarget
);
2382 wxWindow::SetDropTarget( dropTarget
);
2386 wxDropTarget
*wxListCtrl::GetDropTarget() const
2388 #if wxUSE_DRAG_AND_DROP
2390 return m_genericImpl
->GetDropTarget();
2393 return wxWindow::GetDropTarget();
2398 #if wxABI_VERSION >= 20801
2399 void wxListCtrl::SetFocus()
2403 m_genericImpl
->SetFocus();
2407 wxWindow::SetFocus();
2411 // wxMac internal data structures
2413 wxMacListCtrlItem::~wxMacListCtrlItem()
2417 void wxMacListCtrlItem::Notification(wxMacDataItemBrowserControl
*owner
,
2418 DataBrowserItemNotification message
,
2419 DataBrowserItemDataRef
WXUNUSED(itemData
) ) const
2422 wxMacDataBrowserListCtrlControl
*lb
= wxDynamicCast(owner
, wxMacDataBrowserListCtrlControl
);
2424 // we want to depend on as little as possible to make sure tear-down of controls is safe
2425 if ( message
== kDataBrowserItemRemoved
)
2427 if ( lb
!= NULL
&& lb
->GetClientDataType() == wxClientData_Object
)
2429 delete (wxClientData
*) (m_data
);
2435 else if ( message
== kDataBrowserItemAdded
)
2437 // we don't issue events on adding, the item is not really stored in the list yet, so we
2438 // avoid asserts by gettting out now
2442 wxListCtrl
*list
= wxDynamicCast( owner
->GetPeer() , wxListCtrl
);
2445 bool trigger
= false;
2447 wxListEvent
event( wxEVT_COMMAND_LIST_ITEM_SELECTED
, list
->GetId() );
2448 bool isSingle
= (list
->GetWindowStyle() & wxLC_SINGLE_SEL
) != 0;
2450 event
.SetEventObject( list
);
2451 event
.m_itemIndex
= owner
->GetLineFromItem( this ) ;
2452 event
.m_item
.m_itemId
= event
.m_itemIndex
;
2453 list
->GetItem(event
.m_item
);
2457 case kDataBrowserItemDeselected
:
2458 event
.SetEventType(wxEVT_COMMAND_LIST_ITEM_DESELECTED
);
2460 trigger
= !lb
->IsSelectionSuppressed();
2463 case kDataBrowserItemSelected
:
2464 trigger
= !lb
->IsSelectionSuppressed();
2467 case kDataBrowserItemDoubleClicked
:
2468 event
.SetEventType( wxEVT_COMMAND_LIST_ITEM_ACTIVATED
);
2472 case kDataBrowserEditStarted
:
2473 // TODO : how to veto ?
2474 event
.SetEventType( wxEVT_COMMAND_LIST_BEGIN_LABEL_EDIT
) ;
2478 case kDataBrowserEditStopped
:
2479 // TODO probably trigger only upon the value store callback, because
2480 // here IIRC we cannot veto
2481 event
.SetEventType( wxEVT_COMMAND_LIST_END_LABEL_EDIT
) ;
2491 // direct notification is not always having the listbox GetSelection() having in synch with event
2492 wxPostEvent( list
->GetEventHandler(), event
);
2498 IMPLEMENT_DYNAMIC_CLASS(wxMacDataBrowserListCtrlControl
, wxMacDataItemBrowserControl
)
2500 wxMacDataBrowserListCtrlControl::wxMacDataBrowserListCtrlControl( wxWindow
*peer
, const wxPoint
& pos
, const wxSize
& size
, long style
)
2501 : wxMacDataItemBrowserControl( peer
, pos
, size
, style
)
2503 OSStatus err
= noErr
;
2504 m_clientDataItemsType
= wxClientData_None
;
2505 m_isVirtual
= false;
2508 if ( style
& wxLC_VIRTUAL
)
2511 DataBrowserSelectionFlags options
= kDataBrowserDragSelect
;
2512 if ( style
& wxLC_SINGLE_SEL
)
2514 options
|= kDataBrowserSelectOnlyOne
;
2518 options
|= kDataBrowserCmdTogglesSelection
;
2521 err
= SetSelectionFlags( options
);
2522 verify_noerr( err
);
2524 DataBrowserCustomCallbacks callbacks
;
2525 InitializeDataBrowserCustomCallbacks( &callbacks
, kDataBrowserLatestCustomCallbacks
);
2527 if ( gDataBrowserDrawItemUPP
== NULL
)
2528 gDataBrowserDrawItemUPP
= NewDataBrowserDrawItemUPP(DataBrowserDrawItemProc
);
2530 if ( gDataBrowserHitTestUPP
== NULL
)
2531 gDataBrowserHitTestUPP
= NewDataBrowserHitTestUPP(DataBrowserHitTestProc
);
2533 callbacks
.u
.v1
.drawItemCallback
= gDataBrowserDrawItemUPP
;
2534 callbacks
.u
.v1
.hitTestCallback
= gDataBrowserHitTestUPP
;
2536 SetDataBrowserCustomCallbacks( GetControlRef(), &callbacks
);
2538 if ( style
& wxLC_LIST
)
2540 InsertColumn(0, kDataBrowserIconAndTextType
, wxEmptyString
, -1, -1);
2541 verify_noerr( AutoSizeColumns() );
2544 if ( style
& wxLC_LIST
|| style
& wxLC_NO_HEADER
)
2545 verify_noerr( SetHeaderButtonHeight( 0 ) );
2548 SetSortProperty( kMinColumnId
- 1 );
2550 SetSortProperty( kMinColumnId
);
2552 m_sortOrder
= SortOrder_None
;
2554 if ( style
& wxLC_SORT_DESCENDING
)
2556 SetSortOrder( kDataBrowserOrderDecreasing
);
2558 else if ( style
& wxLC_SORT_ASCENDING
)
2560 SetSortOrder( kDataBrowserOrderIncreasing
);
2563 if ( style
& wxLC_VRULES
)
2565 verify_noerr( DataBrowserChangeAttributes(m_controlRef
, kDataBrowserAttributeListViewDrawColumnDividers
, kDataBrowserAttributeNone
) );
2568 verify_noerr( SetHiliteStyle(kDataBrowserTableViewFillHilite
) );
2569 verify_noerr( SetHasScrollBars( (style
& wxHSCROLL
) != 0 , true ) );
2572 pascal Boolean
wxMacDataBrowserListCtrlControl::DataBrowserEditTextProc(
2574 DataBrowserItemID itemID
,
2575 DataBrowserPropertyID property
,
2576 CFStringRef theString
,
2577 Rect
*maxEditTextRect
,
2578 Boolean
*shrinkToFit
)
2580 Boolean result
= false;
2581 wxMacDataBrowserListCtrlControl
* ctl
= wxDynamicCast(wxMacControl::GetReferenceFromNativeControl( browser
), wxMacDataBrowserListCtrlControl
);
2584 result
= ctl
->ConfirmEditText(itemID
, property
, theString
, maxEditTextRect
, shrinkToFit
);
2585 theString
= CFSTR("Hello!");
2590 bool wxMacDataBrowserListCtrlControl::ConfirmEditText(
2591 DataBrowserItemID
WXUNUSED(itemID
),
2592 DataBrowserPropertyID
WXUNUSED(property
),
2593 CFStringRef
WXUNUSED(theString
),
2594 Rect
*WXUNUSED(maxEditTextRect
),
2595 Boolean
*WXUNUSED(shrinkToFit
))
2600 pascal void wxMacDataBrowserListCtrlControl::DataBrowserDrawItemProc(
2602 DataBrowserItemID itemID
,
2603 DataBrowserPropertyID property
,
2604 DataBrowserItemState itemState
,
2605 const Rect
*itemRect
,
2607 Boolean colorDevice
)
2609 wxMacDataBrowserListCtrlControl
* ctl
= wxDynamicCast(wxMacControl::GetReferenceFromNativeControl( browser
), wxMacDataBrowserListCtrlControl
);
2612 ctl
->DrawItem(itemID
, property
, itemState
, itemRect
, gdDepth
, colorDevice
);
2616 // routines needed for DrawItem
2621 kTextBoxHeight
= 14,
2622 kIconTextSpacingV
= 2,
2624 kContentHeight
= kIconHeight
+ kTextBoxHeight
+ kIconTextSpacingV
2627 static void calculateCGDrawingBounds(CGRect inItemRect
, CGRect
*outIconRect
, CGRect
*outTextRect
, bool hasIcon
= false)
2630 float iconH
, iconW
= 0;
2631 float padding
= kItemPadding
;
2634 iconH
= kIconHeight
;
2636 padding
= padding
*2;
2639 textBottom
= inItemRect
.origin
.y
;
2641 *outIconRect
= CGRectMake(inItemRect
.origin
.x
+ kItemPadding
,
2642 textBottom
+ kIconTextSpacingV
, kIconWidth
,
2645 *outTextRect
= CGRectMake(inItemRect
.origin
.x
+ padding
+ iconW
,
2646 textBottom
+ kIconTextSpacingV
, inItemRect
.size
.width
- padding
- iconW
,
2647 inItemRect
.size
.height
- kIconTextSpacingV
);
2650 void wxMacDataBrowserListCtrlControl::DrawItem(
2651 DataBrowserItemID itemID
,
2652 DataBrowserPropertyID property
,
2653 DataBrowserItemState itemState
,
2654 const Rect
*WXUNUSED(itemRect
),
2656 Boolean colorDevice
)
2659 wxFont font
= wxNullFont
;
2661 short listColumn
= property
- kMinColumnId
;
2663 wxListCtrl
* list
= wxDynamicCast( GetPeer() , wxListCtrl
);
2664 wxMacListCtrlItem
* lcItem
;
2665 wxColour color
= *wxBLACK
;
2666 wxColour bgColor
= wxNullColour
;
2668 if (listColumn
>= 0)
2672 lcItem
= (wxMacListCtrlItem
*) itemID
;
2673 if (lcItem
->HasColumnInfo(listColumn
)){
2674 wxListItem
* item
= lcItem
->GetColumnInfo(listColumn
);
2676 // we always use the 0 column to get font and text/background colors.
2677 if (lcItem
->HasColumnInfo(0))
2679 wxListItem
* firstItem
= lcItem
->GetColumnInfo(0);
2680 color
= firstItem
->GetTextColour();
2681 bgColor
= firstItem
->GetBackgroundColour();
2682 font
= firstItem
->GetFont();
2685 if (item
->GetMask() & wxLIST_MASK_TEXT
)
2686 text
= item
->GetText();
2687 if (item
->GetMask() & wxLIST_MASK_IMAGE
)
2688 imgIndex
= item
->GetImage();
2694 long itemNum
= (long)itemID
-1;
2695 if (itemNum
>= 0 && itemNum
< list
->GetItemCount())
2697 text
= list
->OnGetItemText( itemNum
, listColumn
);
2698 imgIndex
= list
->OnGetItemColumnImage( itemNum
, listColumn
);
2699 wxListItemAttr
* attrs
= list
->OnGetItemAttr( itemNum
);
2702 if (attrs
->HasBackgroundColour())
2703 bgColor
= attrs
->GetBackgroundColour();
2704 if (attrs
->HasTextColour())
2705 color
= attrs
->GetTextColour();
2706 if (attrs
->HasFont())
2707 font
= attrs
->GetFont();
2713 wxColour listBgColor
= list
->GetBackgroundColour();
2714 if (bgColor
== wxNullColour
)
2715 bgColor
= listBgColor
;
2718 font
= list
->GetFont();
2720 wxCFStringRef
cfString( text
, wxLocale::GetSystemEncoding() );
2723 CGRect enclosingCGRect
, iconCGRect
, textCGRect
;
2725 ThemeDrawingState savedState
= NULL
;
2726 CGContextRef context
= (CGContextRef
)list
->MacGetDrawingContext();
2727 RGBColor labelColor
;
2729 labelColor
.green
= 0;
2730 labelColor
.blue
= 0;
2732 RGBColor backgroundColor
;
2733 backgroundColor
.red
= 255;
2734 backgroundColor
.green
= 255;
2735 backgroundColor
.blue
= 255;
2737 GetDataBrowserItemPartBounds(GetControlRef(), itemID
, property
, kDataBrowserPropertyEnclosingPart
,
2740 enclosingCGRect
= CGRectMake(enclosingRect
.left
,
2742 enclosingRect
.right
- enclosingRect
.left
,
2743 enclosingRect
.bottom
- enclosingRect
.top
);
2745 bool hasFocus
= (wxWindow::FindFocus() == list
);
2746 active
= IsControlActive(GetControlRef());
2748 // don't paint the background over the vertical rule line
2749 if ( list
->GetWindowStyleFlag() & wxLC_VRULES
)
2751 enclosingCGRect
.origin
.x
+= 1;
2752 enclosingCGRect
.size
.width
-= 1;
2754 if (itemState
== kDataBrowserItemIsSelected
)
2757 GetThemeDrawingState(&savedState
);
2759 if (active
&& hasFocus
)
2761 GetThemeBrushAsColor(kThemeBrushAlternatePrimaryHighlightColor
, 32, true, &backgroundColor
);
2762 GetThemeTextColor(kThemeTextColorWhite
, gdDepth
, colorDevice
, &labelColor
);
2766 GetThemeBrushAsColor(kThemeBrushSecondaryHighlightColor
, 32, true, &backgroundColor
);
2767 GetThemeTextColor(kThemeTextColorBlack
, gdDepth
, colorDevice
, &labelColor
);
2769 CGContextSaveGState(context
);
2771 CGContextSetRGBFillColor(context
, (CGFloat
)backgroundColor
.red
/ (CGFloat
)USHRT_MAX
,
2772 (CGFloat
)backgroundColor
.green
/ (CGFloat
)USHRT_MAX
,
2773 (CGFloat
)backgroundColor
.blue
/ (CGFloat
)USHRT_MAX
, (CGFloat
) 1.0);
2774 CGContextFillRect(context
, enclosingCGRect
);
2776 CGContextRestoreGState(context
);
2782 color
.GetRGBColor(&labelColor
);
2783 else if (list
->GetTextColour().Ok())
2784 list
->GetTextColour().GetRGBColor(&labelColor
);
2788 bgColor
.GetRGBColor(&backgroundColor
);
2789 CGContextSaveGState(context
);
2791 CGContextSetRGBFillColor(context
, (CGFloat
)backgroundColor
.red
/ (CGFloat
)USHRT_MAX
,
2792 (CGFloat
)backgroundColor
.green
/ (CGFloat
)USHRT_MAX
,
2793 (CGFloat
)backgroundColor
.blue
/ (CGFloat
)USHRT_MAX
, (CGFloat
) 1.0);
2794 CGContextFillRect(context
, enclosingCGRect
);
2796 CGContextRestoreGState(context
);
2800 calculateCGDrawingBounds(enclosingCGRect
, &iconCGRect
, &textCGRect
, (imgIndex
!= -1) );
2804 wxImageList
* imageList
= list
->GetImageList(wxIMAGE_LIST_SMALL
);
2805 if (imageList
&& imageList
->GetImageCount() > 0){
2806 wxBitmap bmp
= imageList
->GetBitmap(imgIndex
);
2807 IconRef icon
= bmp
.GetIconRef();
2809 CGContextSaveGState(context
);
2810 CGContextTranslateCTM(context
, 0,iconCGRect
.origin
.y
+ CGRectGetMaxY(iconCGRect
));
2811 CGContextScaleCTM(context
,1.0f
,-1.0f
);
2812 PlotIconRefInContext(context
, &iconCGRect
, kAlignNone
,
2813 active
? kTransformNone
: kTransformDisabled
, NULL
,
2814 kPlotIconRefNormalFlags
, icon
);
2816 CGContextRestoreGState(context
);
2820 HIThemeTextHorizontalFlush hFlush
= kHIThemeTextHorizontalFlushLeft
;
2821 HIThemeTextInfo info
;
2823 #if wxMAC_USE_CORE_TEXT
2824 if ( UMAGetSystemVersion() >= 0x1050 )
2826 info
.version
= kHIThemeTextInfoVersionOne
;
2827 info
.fontID
= kThemeViewsFont
;
2830 info
.fontID
= kThemeSpecifiedFont
;
2831 info
.font
= (CTFontRef
) font
.MacGetCTFont();
2836 #if wxMAC_USE_ATSU_TEXT
2839 info
.version
= kHIThemeTextInfoVersionZero
;
2840 info
.fontID
= kThemeViewsFont
;
2844 info
.fontID
= font
.MacGetThemeFontID();
2846 ::TextSize( (short)(font
.MacGetFontSize()) ) ;
2847 ::TextFace( font
.MacGetFontStyle() ) ;
2853 list
->GetColumn(listColumn
, item
);
2854 if (item
.GetMask() & wxLIST_MASK_FORMAT
)
2856 if (item
.GetAlign() == wxLIST_FORMAT_LEFT
)
2857 hFlush
= kHIThemeTextHorizontalFlushLeft
;
2858 else if (item
.GetAlign() == wxLIST_FORMAT_CENTER
)
2859 hFlush
= kHIThemeTextHorizontalFlushCenter
;
2860 else if (item
.GetAlign() == wxLIST_FORMAT_RIGHT
)
2862 hFlush
= kHIThemeTextHorizontalFlushRight
;
2863 textCGRect
.origin
.x
-= kItemPadding
; // give a little extra paddding
2867 info
.state
= active
? kThemeStateActive
: kThemeStateInactive
;
2868 info
.horizontalFlushness
= hFlush
;
2869 info
.verticalFlushness
= kHIThemeTextVerticalFlushCenter
;
2870 info
.options
= kHIThemeTextBoxOptionNone
;
2871 info
.truncationPosition
= kHIThemeTextTruncationEnd
;
2872 info
.truncationMaxLines
= 1;
2874 CGContextSaveGState(context
);
2875 CGContextSetRGBFillColor (context
, (CGFloat
)labelColor
.red
/ (CGFloat
)USHRT_MAX
,
2876 (CGFloat
)labelColor
.green
/ (CGFloat
)USHRT_MAX
,
2877 (CGFloat
)labelColor
.blue
/ (CGFloat
)USHRT_MAX
, (CGFloat
) 1.0);
2879 HIThemeDrawTextBox(cfString
, &textCGRect
, &info
, context
, kHIThemeOrientationNormal
);
2881 CGContextRestoreGState(context
);
2884 if (savedState
!= NULL
)
2885 SetThemeDrawingState(savedState
, true);
2889 OSStatus
wxMacDataBrowserListCtrlControl::GetSetItemData(DataBrowserItemID itemID
,
2890 DataBrowserPropertyID property
,
2891 DataBrowserItemDataRef itemData
,
2892 Boolean changeValue
)
2896 short listColumn
= property
- kMinColumnId
;
2898 OSStatus err
= errDataBrowserPropertyNotSupported
;
2899 wxListCtrl
* list
= wxDynamicCast( GetPeer() , wxListCtrl
);
2900 wxMacListCtrlItem
* lcItem
= NULL
;
2902 if (listColumn
>= 0)
2906 lcItem
= (wxMacListCtrlItem
*) itemID
;
2907 if (lcItem
&& lcItem
->HasColumnInfo(listColumn
)){
2908 wxListItem
* item
= lcItem
->GetColumnInfo(listColumn
);
2909 if (item
->GetMask() & wxLIST_MASK_TEXT
)
2910 text
= item
->GetText();
2911 if (item
->GetMask() & wxLIST_MASK_IMAGE
)
2912 imgIndex
= item
->GetImage();
2917 long itemNum
= (long)itemID
-1;
2918 if (itemNum
>= 0 && itemNum
< list
->GetItemCount())
2920 text
= list
->OnGetItemText( itemNum
, listColumn
);
2921 imgIndex
= list
->OnGetItemColumnImage( itemNum
, listColumn
);
2930 case kDataBrowserItemIsEditableProperty
:
2931 if ( list
&& list
->HasFlag( wxLC_EDIT_LABELS
) )
2933 verify_noerr(SetDataBrowserItemDataBooleanValue( itemData
, true ));
2938 if ( property
>= kMinColumnId
)
2940 if (!text
.IsEmpty()){
2941 wxCFStringRef
cfStr( text
, wxLocale::GetSystemEncoding() );
2942 err
= ::SetDataBrowserItemDataText( itemData
, cfStr
);
2948 if ( imgIndex
!= -1 )
2950 wxImageList
* imageList
= list
->GetImageList(wxIMAGE_LIST_SMALL
);
2951 if (imageList
&& imageList
->GetImageCount() > 0){
2952 wxBitmap bmp
= imageList
->GetBitmap(imgIndex
);
2953 IconRef icon
= bmp
.GetIconRef();
2954 ::SetDataBrowserItemDataIcon(itemData
, icon
);
2968 if ( property
>= kMinColumnId
)
2970 short listColumn
= property
- kMinColumnId
;
2972 // TODO probably send the 'end edit' from here, as we
2973 // can then deal with the veto
2975 verify_noerr( GetDataBrowserItemDataText( itemData
, &sr
) ) ;
2976 wxCFStringRef
cfStr(sr
) ;;
2978 list
->SetItem( (long)itemData
-1 , listColumn
, cfStr
.AsString() ) ;
2982 lcItem
->SetColumnTextValue( listColumn
, cfStr
.AsString() );
2992 void wxMacDataBrowserListCtrlControl::ItemNotification(DataBrowserItemID itemID
,
2993 DataBrowserItemNotification message
,
2994 DataBrowserItemDataRef
WXUNUSED(itemData
) )
2996 // we want to depend on as little as possible to make sure tear-down of controls is safe
2997 if ( message
== kDataBrowserItemRemoved
)
2999 // make sure MacDelete does the proper teardown.
3002 else if ( message
== kDataBrowserItemAdded
)
3004 // we don't issue events on adding, the item is not really stored in the list yet, so we
3005 // avoid asserts by getting out now
3009 wxListCtrl
*list
= wxDynamicCast( GetPeer() , wxListCtrl
);
3012 bool trigger
= false;
3014 wxListEvent
event( wxEVT_COMMAND_LIST_ITEM_SELECTED
, list
->GetId() );
3016 event
.SetEventObject( list
);
3017 if ( !list
->IsVirtual() )
3019 DataBrowserTableViewRowIndex result
= 0;
3020 verify_noerr( GetItemRow( itemID
, &result
) ) ;
3021 event
.m_itemIndex
= result
;
3025 event
.m_itemIndex
= (long)itemID
-1;
3027 event
.m_item
.m_itemId
= event
.m_itemIndex
;
3028 list
->GetItem(event
.m_item
);
3032 case kDataBrowserItemDeselected
:
3033 event
.SetEventType(wxEVT_COMMAND_LIST_ITEM_DESELECTED
);
3034 // as the generic implementation is also triggering this
3035 // event for single selection, we do the same (different than listbox)
3036 trigger
= !IsSelectionSuppressed();
3039 case kDataBrowserItemSelected
:
3040 trigger
= !IsSelectionSuppressed();
3044 case kDataBrowserItemDoubleClicked
:
3045 event
.SetEventType( wxEVT_COMMAND_LIST_ITEM_ACTIVATED
);
3049 case kDataBrowserEditStarted
:
3050 // TODO : how to veto ?
3051 event
.SetEventType( wxEVT_COMMAND_LIST_BEGIN_LABEL_EDIT
) ;
3055 case kDataBrowserEditStopped
:
3056 // TODO probably trigger only upon the value store callback, because
3057 // here IIRC we cannot veto
3058 event
.SetEventType( wxEVT_COMMAND_LIST_END_LABEL_EDIT
) ;
3068 // direct notification is not always having the listbox GetSelection() having in synch with event
3069 wxPostEvent( list
->GetEventHandler(), event
);
3074 Boolean
wxMacDataBrowserListCtrlControl::CompareItems(DataBrowserItemID itemOneID
,
3075 DataBrowserItemID itemTwoID
,
3076 DataBrowserPropertyID sortProperty
)
3079 bool retval
= false;
3081 wxString otherItemText
;
3083 long otherItemOrder
;
3085 int colId
= sortProperty
- kMinColumnId
;
3087 wxListCtrl
* list
= wxDynamicCast( GetPeer() , wxListCtrl
);
3089 DataBrowserSortOrder sort
;
3090 verify_noerr(GetSortOrder(&sort
));
3096 wxMacListCtrlItem
* item
= (wxMacListCtrlItem
*)itemOneID
;
3097 wxMacListCtrlItem
* otherItem
= (wxMacListCtrlItem
*)itemTwoID
;
3099 itemOrder
= item
->GetOrder();
3100 otherItemOrder
= item
->GetOrder();
3102 wxListCtrlCompare func
= list
->GetCompareFunc();
3107 if (item
&& item
->HasColumnInfo(0))
3108 item1
= item
->GetColumnInfo(0)->GetData();
3109 if (otherItem
&& otherItem
->HasColumnInfo(0))
3110 item2
= otherItem
->GetColumnInfo(0)->GetData();
3112 if (item1
> -1 && item2
> -1)
3114 int result
= func(item1
, item2
, list
->GetCompareFuncData());
3115 if (sort
== kDataBrowserOrderIncreasing
)
3122 // we can't use the native control's sorting abilities, so just
3124 return itemOrder
< otherItemOrder
;
3129 long itemNum
= (long)itemOneID
;
3130 long otherItemNum
= (long)itemTwoID
;
3132 // virtual listctrls don't support sorting
3133 return itemNum
< otherItemNum
;
3137 // fallback for undefined cases
3138 retval
= itemOneID
< itemTwoID
;
3144 wxMacDataBrowserListCtrlControl::~wxMacDataBrowserListCtrlControl()
3148 void wxMacDataBrowserListCtrlControl::MacSetColumnInfo( unsigned int row
, unsigned int column
, wxListItem
* item
)
3150 wxMacDataItem
* dataItem
= GetItemFromLine(row
);
3151 wxASSERT_MSG( dataItem
, _T("could not obtain wxMacDataItem for row in MacSetColumnInfo. Is row a valid wxListCtrl row?") );
3154 wxMacListCtrlItem
* listItem
= wx_static_cast(wxMacListCtrlItem
*,dataItem
);
3155 bool hasInfo
= listItem
->HasColumnInfo( column
);
3156 listItem
->SetColumnInfo( column
, item
);
3157 listItem
->SetOrder(row
);
3158 UpdateState(dataItem
, item
);
3160 wxListCtrl
* list
= wxDynamicCast( GetPeer() , wxListCtrl
);
3162 // NB: When this call was made before a control was completely shown, it would
3163 // update the item prematurely (i.e. no text would be listed) and, on show,
3164 // only the sorted column would be refreshed, meaning only first column text labels
3165 // would be shown. Making sure not to update items until the control is visible
3166 // seems to fix this issue.
3167 if (hasInfo
&& list
->IsShown())
3168 UpdateItem( wxMacDataBrowserRootContainer
, listItem
, kMinColumnId
+ column
);
3172 // apply changes that need to happen immediately, rather than when the
3173 // databrowser control fires a callback.
3174 void wxMacDataBrowserListCtrlControl::UpdateState(wxMacDataItem
* dataItem
, wxListItem
* listItem
)
3176 bool isSelected
= IsItemSelected( dataItem
);
3177 bool isSelectedState
= (listItem
->GetState() == wxLIST_STATE_SELECTED
);
3179 // toggle the selection state if wxListInfo state and actual state don't match.
3180 if ( listItem
->GetMask() & wxLIST_MASK_STATE
&& isSelected
!= isSelectedState
)
3182 DataBrowserSetOption options
= kDataBrowserItemsAdd
;
3183 if (!isSelectedState
)
3184 options
= kDataBrowserItemsRemove
;
3185 SetSelectedItem(dataItem
, options
);
3187 // TODO: Set column width if item width > than current column width
3190 void wxMacDataBrowserListCtrlControl::MacGetColumnInfo( unsigned int row
, unsigned int column
, wxListItem
& item
)
3192 wxMacDataItem
* dataItem
= GetItemFromLine(row
);
3193 wxASSERT_MSG( dataItem
, _T("could not obtain wxMacDataItem in MacGetColumnInfo. Is row a valid wxListCtrl row?") );
3194 // CS should this guard against dataItem = 0 ? , as item is not a pointer if (item) is not appropriate
3197 wxMacListCtrlItem
* listItem
=wx_static_cast(wxMacListCtrlItem
*,dataItem
);
3199 if (!listItem
->HasColumnInfo( column
))
3202 wxListItem
* oldItem
= listItem
->GetColumnInfo( column
);
3206 long mask
= item
.GetMask();
3208 // by default, get everything for backwards compatibility
3211 if ( mask
& wxLIST_MASK_TEXT
)
3212 item
.SetText(oldItem
->GetText());
3213 if ( mask
& wxLIST_MASK_IMAGE
)
3214 item
.SetImage(oldItem
->GetImage());
3215 if ( mask
& wxLIST_MASK_DATA
)
3216 item
.SetData(oldItem
->GetData());
3217 if ( mask
& wxLIST_MASK_STATE
)
3218 item
.SetState(oldItem
->GetState());
3219 if ( mask
& wxLIST_MASK_WIDTH
)
3220 item
.SetWidth(oldItem
->GetWidth());
3221 if ( mask
& wxLIST_MASK_FORMAT
)
3222 item
.SetAlign(oldItem
->GetAlign());
3224 item
.SetTextColour(oldItem
->GetTextColour());
3225 item
.SetBackgroundColour(oldItem
->GetBackgroundColour());
3226 item
.SetFont(oldItem
->GetFont());
3231 void wxMacDataBrowserListCtrlControl::MacInsertItem( unsigned int n
, wxListItem
* item
)
3233 wxMacDataItemBrowserControl::MacInsert(n
, item
->GetText());
3234 MacSetColumnInfo(n
, 0, item
);
3237 wxMacDataItem
* wxMacDataBrowserListCtrlControl::CreateItem()
3239 return new wxMacListCtrlItem();
3242 wxMacListCtrlItem::wxMacListCtrlItem()
3244 m_rowItems
= wxListItemList();
3247 int wxMacListCtrlItem::GetColumnImageValue( unsigned int column
)
3249 if ( HasColumnInfo(column
) )
3250 return GetColumnInfo(column
)->GetImage();
3255 void wxMacListCtrlItem::SetColumnImageValue( unsigned int column
, int imageIndex
)
3257 if ( HasColumnInfo(column
) )
3258 GetColumnInfo(column
)->SetImage(imageIndex
);
3261 wxString
wxMacListCtrlItem::GetColumnTextValue( unsigned int column
)
3266 if ( HasColumnInfo(column
) )
3267 return GetColumnInfo(column
)->GetText();
3269 return wxEmptyString
;
3272 void wxMacListCtrlItem::SetColumnTextValue( unsigned int column
, const wxString
& text
)
3274 if ( HasColumnInfo(column
) )
3275 GetColumnInfo(column
)->SetText(text
);
3277 // for compatibility with superclass APIs
3282 wxListItem
* wxMacListCtrlItem::GetColumnInfo( unsigned int column
)
3284 wxASSERT_MSG( HasColumnInfo(column
), _T("invalid column index in wxMacListCtrlItem") );
3285 return m_rowItems
[column
];
3288 bool wxMacListCtrlItem::HasColumnInfo( unsigned int column
)
3290 return !(m_rowItems
.find( column
) == m_rowItems
.end());
3293 void wxMacListCtrlItem::SetColumnInfo( unsigned int column
, wxListItem
* item
)
3296 if ( !HasColumnInfo(column
) )
3298 wxListItem
* listItem
= new wxListItem(*item
);
3299 m_rowItems
[column
] = listItem
;
3303 wxListItem
* listItem
= GetColumnInfo( column
);
3304 long mask
= item
->GetMask();
3305 if (mask
& wxLIST_MASK_TEXT
)
3306 listItem
->SetText(item
->GetText());
3307 if (mask
& wxLIST_MASK_DATA
)
3308 listItem
->SetData(item
->GetData());
3309 if (mask
& wxLIST_MASK_IMAGE
)
3310 listItem
->SetImage(item
->GetImage());
3311 if (mask
& wxLIST_MASK_STATE
)
3312 listItem
->SetState(item
->GetState());
3313 if (mask
& wxLIST_MASK_FORMAT
)
3314 listItem
->SetAlign(item
->GetAlign());
3315 if (mask
& wxLIST_MASK_WIDTH
)
3316 listItem
->SetWidth(item
->GetWidth());
3318 if ( item
->HasAttributes() )
3320 if ( listItem
->HasAttributes() )
3321 listItem
->GetAttributes()->AssignFrom(*item
->GetAttributes());
3324 listItem
->SetTextColour(item
->GetTextColour());
3325 listItem
->SetBackgroundColour(item
->GetBackgroundColour());
3326 listItem
->SetFont(item
->GetFont());
3332 #endif // wxUSE_LISTCTRL