1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/osx/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/osx/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
);
152 DataBrowserTableViewColumnIndex column
= 0;
153 verify_noerr( GetDataBrowserTableViewColumnPosition( controlRef
, col
, &column
) );
156 // FIXME: we can't use the sort property for virtual listctrls
157 // so we need to find a better way to determine which column was clicked...
158 if (!window
->IsVirtual())
159 window
->HandleWindowEvent( le
);
161 result
= CallNextEventHandler(handler
, event
);
164 case kEventControlDraw
:
166 CGContextRef context
= cEvent
.GetParameter
<CGContextRef
>(kEventParamCGContextRef
, typeCGContextRef
) ;
167 window
->MacSetDrawingContext(context
);
168 result
= CallNextEventHandler(handler
, event
);
169 window
->MacSetDrawingContext(NULL
);
180 DEFINE_ONE_SHOT_HANDLER_GETTER( wxMacListCtrlEventHandler
)
182 class wxMacListCtrlItem
: public wxMacDataItem
187 virtual void Notification(wxMacDataItemBrowserControl
*owner
,
188 DataBrowserItemNotification message
,
189 DataBrowserItemDataRef itemData
) const;
191 virtual void SetColumnInfo( unsigned int column
, wxListItem
* item
);
192 virtual wxListItem
* GetColumnInfo( unsigned int column
);
193 virtual bool HasColumnInfo( unsigned int column
);
195 virtual void SetColumnTextValue( unsigned int column
, const wxString
& text
);
196 virtual wxString
GetColumnTextValue( unsigned int column
);
198 virtual int GetColumnImageValue( unsigned int column
);
199 virtual void SetColumnImageValue( unsigned int column
, int imageIndex
);
201 virtual ~wxMacListCtrlItem();
203 wxListItemList m_rowItems
;
206 DataBrowserDrawItemUPP gDataBrowserDrawItemUPP
= NULL
;
207 //DataBrowserEditItemUPP gDataBrowserEditItemUPP = NULL;
208 DataBrowserHitTestUPP gDataBrowserHitTestUPP
= NULL
;
210 // TODO: Make a better name!!
211 class wxMacDataBrowserListCtrlControl
: public wxMacDataItemBrowserControl
214 wxMacDataBrowserListCtrlControl( wxWindow
*peer
, const wxPoint
& pos
, const wxSize
& size
, long style
);
215 wxMacDataBrowserListCtrlControl() {}
216 virtual ~wxMacDataBrowserListCtrlControl();
218 // create a list item (can be a subclass of wxMacListBoxItem)
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
);
224 int GetFlags() { return m_flags
; }
227 // we need to override to provide specialized handling for virtual wxListCtrls
228 virtual OSStatus
GetSetItemData(DataBrowserItemID itemID
,
229 DataBrowserPropertyID property
,
230 DataBrowserItemDataRef itemData
,
231 Boolean changeValue
);
233 virtual void ItemNotification(
234 DataBrowserItemID itemID
,
235 DataBrowserItemNotification message
,
236 DataBrowserItemDataRef itemData
);
238 virtual Boolean
CompareItems(DataBrowserItemID itemOneID
,
239 DataBrowserItemID itemTwoID
,
240 DataBrowserPropertyID sortProperty
);
242 static pascal void DataBrowserDrawItemProc(ControlRef browser
,
243 DataBrowserItemID item
,
244 DataBrowserPropertyID property
,
245 DataBrowserItemState itemState
,
248 Boolean colorDevice
);
250 virtual void DrawItem(DataBrowserItemID itemID
,
251 DataBrowserPropertyID property
,
252 DataBrowserItemState itemState
,
253 const Rect
*itemRect
,
255 Boolean colorDevice
);
257 static pascal Boolean
DataBrowserEditTextProc(ControlRef browser
,
258 DataBrowserItemID item
,
259 DataBrowserPropertyID property
,
260 CFStringRef theString
,
261 Rect
*maxEditTextRect
,
262 Boolean
*shrinkToFit
);
264 static pascal Boolean
DataBrowserHitTestProc(ControlRef
WXUNUSED(browser
),
265 DataBrowserItemID
WXUNUSED(itemID
),
266 DataBrowserPropertyID
WXUNUSED(property
),
267 const Rect
*WXUNUSED(theRect
),
268 const Rect
*WXUNUSED(mouseRect
)) { return true; }
270 virtual bool ConfirmEditText(DataBrowserItemID item
,
271 DataBrowserPropertyID property
,
272 CFStringRef theString
,
273 Rect
*maxEditTextRect
,
274 Boolean
*shrinkToFit
);
278 wxClientDataType m_clientDataItemsType
;
281 DECLARE_DYNAMIC_CLASS_NO_COPY(wxMacDataBrowserListCtrlControl
)
284 class wxMacListCtrlEventDelegate
: public wxEvtHandler
287 wxMacListCtrlEventDelegate( wxListCtrl
* list
, int id
);
288 virtual bool ProcessEvent( wxEvent
& event
);
295 wxMacListCtrlEventDelegate::wxMacListCtrlEventDelegate( wxListCtrl
* list
, int id
)
301 bool wxMacListCtrlEventDelegate::ProcessEvent( wxEvent
& event
)
303 // even though we use a generic list ctrl underneath, make sure
304 // we present ourselves as wxListCtrl.
305 event
.SetEventObject( m_list
);
308 if ( !event
.IsKindOf( CLASSINFO( wxCommandEvent
) ) )
310 if (m_list
->HandleWindowEvent( event
))
313 return wxEvtHandler::ProcessEvent(event
);
316 //-----------------------------------------------------------------------------
317 // wxListCtrlRenameTimer (internal)
318 //-----------------------------------------------------------------------------
320 class wxListCtrlRenameTimer
: public wxTimer
326 wxListCtrlRenameTimer( wxListCtrl
*owner
);
330 //-----------------------------------------------------------------------------
331 // wxListCtrlTextCtrlWrapper: wraps a wxTextCtrl to make it work for inline editing
332 //-----------------------------------------------------------------------------
334 class wxListCtrlTextCtrlWrapper
: public wxEvtHandler
337 // NB: text must be a valid object but not Create()d yet
338 wxListCtrlTextCtrlWrapper(wxListCtrl
*owner
,
342 wxTextCtrl
*GetText() const { return m_text
; }
344 void AcceptChangesAndFinish();
347 void OnChar( wxKeyEvent
&event
);
348 void OnKeyUp( wxKeyEvent
&event
);
349 void OnKillFocus( wxFocusEvent
&event
);
351 bool AcceptChanges();
357 wxString m_startValue
;
360 bool m_aboutToFinish
;
362 DECLARE_EVENT_TABLE()
365 //-----------------------------------------------------------------------------
366 // wxListCtrlRenameTimer (internal)
367 //-----------------------------------------------------------------------------
369 wxListCtrlRenameTimer::wxListCtrlRenameTimer( wxListCtrl
*owner
)
374 void wxListCtrlRenameTimer::Notify()
376 m_owner
->OnRenameTimer();
379 //-----------------------------------------------------------------------------
380 // wxListCtrlTextCtrlWrapper (internal)
381 //-----------------------------------------------------------------------------
383 BEGIN_EVENT_TABLE(wxListCtrlTextCtrlWrapper
, wxEvtHandler
)
384 EVT_CHAR (wxListCtrlTextCtrlWrapper::OnChar
)
385 EVT_KEY_UP (wxListCtrlTextCtrlWrapper::OnKeyUp
)
386 EVT_KILL_FOCUS (wxListCtrlTextCtrlWrapper::OnKillFocus
)
389 wxListCtrlTextCtrlWrapper::wxListCtrlTextCtrlWrapper(wxListCtrl
*owner
,
392 : m_startValue(owner
->GetItemText(itemEdit
)),
393 m_itemEdited(itemEdit
)
398 m_aboutToFinish
= false;
402 owner
->GetItemRect(itemEdit
, rectLabel
);
404 m_text
->Create(owner
, wxID_ANY
, m_startValue
,
405 wxPoint(rectLabel
.x
+offset
,rectLabel
.y
),
406 wxSize(rectLabel
.width
-offset
,rectLabel
.height
));
409 m_text
->PushEventHandler(this);
412 void wxListCtrlTextCtrlWrapper::Finish()
418 m_text
->RemoveEventHandler(this);
419 m_owner
->FinishEditing(m_text
);
421 wxPendingDelete
.Append( this );
425 bool wxListCtrlTextCtrlWrapper::AcceptChanges()
427 const wxString value
= m_text
->GetValue();
429 if ( value
== m_startValue
)
430 // nothing changed, always accept
433 if ( !m_owner
->OnRenameAccept(m_itemEdited
, value
) )
434 // vetoed by the user
437 // accepted, do rename the item
438 m_owner
->SetItemText(m_itemEdited
, value
);
443 void wxListCtrlTextCtrlWrapper::AcceptChangesAndFinish()
445 m_aboutToFinish
= true;
447 // Notify the owner about the changes
450 // Even if vetoed, close the control (consistent with MSW)
454 void wxListCtrlTextCtrlWrapper::OnChar( wxKeyEvent
&event
)
456 switch ( event
.m_keyCode
)
459 AcceptChangesAndFinish();
463 m_owner
->OnRenameCancelled( m_itemEdited
);
472 void wxListCtrlTextCtrlWrapper::OnKeyUp( wxKeyEvent
&event
)
480 // auto-grow the textctrl:
481 wxSize parentSize
= m_owner
->GetSize();
482 wxPoint myPos
= m_text
->GetPosition();
483 wxSize mySize
= m_text
->GetSize();
485 m_text
->GetTextExtent(m_text
->GetValue() + _T("MM"), &sx
, &sy
);
486 if (myPos
.x
+ sx
> parentSize
.x
)
487 sx
= parentSize
.x
- myPos
.x
;
490 m_text
->SetSize(sx
, wxDefaultCoord
);
495 void wxListCtrlTextCtrlWrapper::OnKillFocus( wxFocusEvent
&event
)
497 if ( !m_finished
&& !m_aboutToFinish
)
499 if ( !AcceptChanges() )
500 m_owner
->OnRenameCancelled( m_itemEdited
);
505 // We must let the native text control handle focus
509 BEGIN_EVENT_TABLE(wxListCtrl
, wxControl
)
510 EVT_LEFT_DOWN(wxListCtrl::OnLeftDown
)
511 EVT_LEFT_DCLICK(wxListCtrl::OnDblClick
)
512 EVT_MIDDLE_DOWN(wxListCtrl::OnMiddleDown
)
513 EVT_RIGHT_DOWN(wxListCtrl::OnRightDown
)
514 EVT_CHAR(wxListCtrl::OnChar
)
517 // ============================================================================
519 // ============================================================================
521 wxMacDataBrowserListCtrlControl
* wxListCtrl::GetListPeer() const
523 return dynamic_cast<wxMacDataBrowserListCtrlControl
*> ( GetPeer() );
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
;
775 WX_CLEAR_LIST(wxColumnList
, m_colsInfo
);
780 wxListCtrl::GetClassDefaultAttributes(wxWindowVariant
WXUNUSED(variant
))
782 wxVisualAttributes attr
;
784 attr
.colFg
= wxSystemSettings::GetColour( wxSYS_COLOUR_WINDOWTEXT
);
785 attr
.colBg
= wxSystemSettings::GetColour( wxSYS_COLOUR_LISTBOX
);
786 attr
.font
.MacCreateFromThemeFont(kThemeViewsFont
);
791 // ----------------------------------------------------------------------------
792 // set/get/change style
793 // ----------------------------------------------------------------------------
795 // Add or remove a single window style
796 void wxListCtrl::SetSingleStyle(long style
, bool add
)
798 long flag
= GetWindowStyleFlag();
800 // Get rid of conflicting styles
803 if ( style
& wxLC_MASK_TYPE
)
804 flag
= flag
& ~wxLC_MASK_TYPE
;
805 if ( style
& wxLC_MASK_ALIGN
)
806 flag
= flag
& ~wxLC_MASK_ALIGN
;
807 if ( style
& wxLC_MASK_SORT
)
808 flag
= flag
& ~wxLC_MASK_SORT
;
816 SetWindowStyleFlag(flag
);
819 // Set the whole window style
820 void wxListCtrl::SetWindowStyleFlag(long flag
)
822 if ( flag
!= m_windowStyle
)
824 m_windowStyle
= flag
;
828 m_genericImpl
->SetWindowStyleFlag(flag
);
835 void wxListCtrl::DoSetSize( int x
, int y
, int width
, int height
, int sizeFlags
)
837 wxControl::DoSetSize(x
, y
, width
, height
, sizeFlags
);
840 m_genericImpl
->SetSize(0, 0, width
, height
, sizeFlags
);
842 // determine if we need a horizontal scrollbar, and add it if so
846 for (int column
= 0; column
< GetColumnCount(); column
++)
848 totalWidth
+= m_dbImpl
->GetColumnWidth( column
);
851 if ( !(m_dbImpl
->GetFlags() & wxHSCROLL
) )
853 Boolean vertScrollBar
;
854 GetDataBrowserHasScrollBars( m_dbImpl
->GetControlRef(), NULL
, &vertScrollBar
);
855 if (totalWidth
> width
)
856 SetDataBrowserHasScrollBars( m_dbImpl
->GetControlRef(), true, vertScrollBar
);
858 SetDataBrowserHasScrollBars( m_dbImpl
->GetControlRef(), false, vertScrollBar
);
863 wxSize
wxListCtrl::DoGetBestSize() const
865 return wxWindow::DoGetBestSize();
868 bool wxListCtrl::SetFont(const wxFont
& font
)
871 rv
= wxControl::SetFont(font
);
873 rv
= m_genericImpl
->SetFont(font
);
877 bool wxListCtrl::SetForegroundColour(const wxColour
& colour
)
881 rv
= m_genericImpl
->SetForegroundColour(colour
);
883 SetTextColour(colour
);
887 bool wxListCtrl::SetBackgroundColour(const wxColour
& colour
)
891 rv
= m_genericImpl
->SetBackgroundColour(colour
);
897 wxColour
wxListCtrl::GetBackgroundColour() const
900 return m_genericImpl
->GetBackgroundColour();
907 // ----------------------------------------------------------------------------
909 // ----------------------------------------------------------------------------
911 // Gets information about this column
912 bool wxListCtrl::GetColumn(int col
, wxListItem
& item
) const
915 return m_genericImpl
->GetColumn(col
, item
);
921 wxColumnList::compatibility_iterator node
= m_colsInfo
.Item( col
);
922 wxASSERT_MSG( node
, _T("invalid column index in wxMacListCtrlItem") );
923 wxListItem
* column
= node
->GetData();
925 long mask
= column
->GetMask();
926 if (mask
& wxLIST_MASK_TEXT
)
927 item
.SetText(column
->GetText());
928 if (mask
& wxLIST_MASK_DATA
)
929 item
.SetData(column
->GetData());
930 if (mask
& wxLIST_MASK_IMAGE
)
931 item
.SetImage(column
->GetImage());
932 if (mask
& wxLIST_MASK_STATE
)
933 item
.SetState(column
->GetState());
934 if (mask
& wxLIST_MASK_FORMAT
)
935 item
.SetAlign(column
->GetAlign());
936 if (mask
& wxLIST_MASK_WIDTH
)
937 item
.SetWidth(column
->GetWidth());
943 // Sets information about this column
944 bool wxListCtrl::SetColumn(int col
, wxListItem
& item
)
947 return m_genericImpl
->SetColumn(col
, item
);
951 wxASSERT_MSG( col
< (int)m_colsInfo
.GetCount(), _T("invalid column index in wxMacListCtrlItem") );
953 long mask
= item
.GetMask();
956 GetColumn( col
, listItem
);
958 if (mask
& wxLIST_MASK_TEXT
)
959 listItem
.SetText(item
.GetText());
960 if (mask
& wxLIST_MASK_DATA
)
961 listItem
.SetData(item
.GetData());
962 if (mask
& wxLIST_MASK_IMAGE
)
963 listItem
.SetImage(item
.GetImage());
964 if (mask
& wxLIST_MASK_STATE
)
965 listItem
.SetState(item
.GetState());
966 if (mask
& wxLIST_MASK_FORMAT
)
967 listItem
.SetAlign(item
.GetAlign());
968 if (mask
& wxLIST_MASK_WIDTH
)
969 listItem
.SetWidth(item
.GetWidth());
972 // change the appearance in the databrowser.
973 DataBrowserListViewHeaderDesc columnDesc
;
974 columnDesc
.version
=kDataBrowserListViewLatestHeaderDesc
;
976 DataBrowserTableViewColumnID id
= 0;
977 verify_noerr( m_dbImpl
->GetColumnIDFromIndex( col
, &id
) );
978 verify_noerr( m_dbImpl
->GetHeaderDesc( id
, &columnDesc
) );
981 if (item.GetMask() & wxLIST_MASK_TEXT)
985 enc = GetFont().GetEncoding();
987 enc = wxLocale::GetSystemEncoding();
988 wxCFStringRef cfTitle;
989 cfTitle.Assign( item.GetText() , enc );
990 if(columnDesc.titleString)
991 CFRelease(columnDesc.titleString);
992 columnDesc.titleString = cfTitle;
996 if (item
.GetMask() & wxLIST_MASK_IMAGE
&& item
.GetImage() != -1 )
998 wxImageList
* imageList
= GetImageList(wxIMAGE_LIST_SMALL
);
999 if (imageList
&& imageList
->GetImageCount() > 0 )
1001 wxBitmap bmp
= imageList
->GetBitmap( item
.GetImage() );
1002 IconRef icon
= bmp
.GetIconRef();
1003 columnDesc
.btnContentInfo
.u
.iconRef
= icon
;
1004 columnDesc
.btnContentInfo
.contentType
= kControlContentIconRef
;
1008 verify_noerr( m_dbImpl
->SetHeaderDesc( id
, &columnDesc
) );
1014 int wxListCtrl::GetColumnCount() const
1017 return m_genericImpl
->GetColumnCount();
1022 m_dbImpl
->GetColumnCount(&count
);
1029 // Gets the column width
1030 int wxListCtrl::GetColumnWidth(int col
) const
1033 return m_genericImpl
->GetColumnWidth(col
);
1037 return m_dbImpl
->GetColumnWidth(col
);
1043 // Sets the column width
1044 bool wxListCtrl::SetColumnWidth(int col
, int width
)
1047 return m_genericImpl
->SetColumnWidth(col
, width
);
1051 if ( width
== wxLIST_AUTOSIZE_USEHEADER
)
1053 width
= 150; // FIXME
1058 for (int column
= 0; column
< GetColumnCount(); column
++)
1061 GetColumn(column
, colInfo
);
1063 colInfo
.SetWidth(width
);
1064 SetColumn(column
, colInfo
);
1066 const int mywidth
= (width
== wxLIST_AUTOSIZE
)
1067 ? CalcColumnAutoWidth(column
) : width
;
1068 m_dbImpl
->SetColumnWidth(column
, mywidth
);
1073 if ( width
== wxLIST_AUTOSIZE
)
1074 width
= CalcColumnAutoWidth(col
);
1077 GetColumn(col
, colInfo
);
1079 colInfo
.SetWidth(width
);
1080 SetColumn(col
, colInfo
);
1081 m_dbImpl
->SetColumnWidth(col
, width
);
1089 // Gets the number of items that can fit vertically in the
1090 // visible area of the list control (list or report view)
1091 // or the total number of items in the list control (icon
1092 // or small icon view)
1093 int wxListCtrl::GetCountPerPage() const
1096 return m_genericImpl
->GetCountPerPage();
1101 m_dbImpl
->GetDefaultRowHeight( &height
);
1103 return GetClientSize().y
/ height
;
1109 // Gets the edit control for editing labels.
1110 wxTextCtrl
* wxListCtrl::GetEditControl() const
1113 return m_genericImpl
->GetEditControl();
1118 // Gets information about the item
1119 bool wxListCtrl::GetItem(wxListItem
& info
) const
1122 return m_genericImpl
->GetItem(info
);
1128 if (info
.m_itemId
>= 0 && info
.m_itemId
< GetItemCount())
1130 m_dbImpl
->MacGetColumnInfo(info
.m_itemId
, info
.m_col
, info
);
1131 if (info
.GetMask() & wxLIST_MASK_STATE
)
1133 DataBrowserItemID id
= (DataBrowserItemID
)m_dbImpl
->GetItemFromLine(info
.m_itemId
);
1134 if (IsDataBrowserItemSelected( m_dbImpl
->GetControlRef(), id
))
1135 info
.SetState(info
.GetState() | wxLIST_STATE_SELECTED
);
1141 if (info
.m_itemId
>= 0 && info
.m_itemId
< GetItemCount())
1143 info
.SetText( OnGetItemText(info
.m_itemId
, info
.m_col
) );
1144 info
.SetImage( OnGetItemColumnImage(info
.m_itemId
, info
.m_col
) );
1145 if (info
.GetMask() & wxLIST_MASK_STATE
)
1147 if (IsDataBrowserItemSelected( m_dbImpl
->GetControlRef(), info
.m_itemId
+1 ))
1148 info
.SetState(info
.GetState() | wxLIST_STATE_SELECTED
);
1151 wxListItemAttr
* attrs
= OnGetItemAttr( info
.m_itemId
);
1154 info
.SetFont( attrs
->GetFont() );
1155 info
.SetBackgroundColour( attrs
->GetBackgroundColour() );
1156 info
.SetTextColour( attrs
->GetTextColour() );
1161 bool success
= true;
1165 // Sets information about the item
1166 bool wxListCtrl::SetItem(wxListItem
& info
)
1169 return m_genericImpl
->SetItem(info
);
1172 m_dbImpl
->MacSetColumnInfo( info
.m_itemId
, info
.m_col
, &info
);
1177 long wxListCtrl::SetItem(long index
, int col
, const wxString
& label
, int imageId
)
1180 return m_genericImpl
->SetItem(index
, col
, label
, imageId
);
1183 info
.m_text
= label
;
1184 info
.m_mask
= wxLIST_MASK_TEXT
;
1185 info
.m_itemId
= index
;
1189 info
.m_image
= imageId
;
1190 info
.m_mask
|= wxLIST_MASK_IMAGE
;
1192 return SetItem(info
);
1196 // Gets the item state
1197 int wxListCtrl::GetItemState(long item
, long stateMask
) const
1200 return m_genericImpl
->GetItemState(item
, stateMask
);
1204 if ( HasFlag(wxLC_VIRTUAL
) )
1206 if (stateMask
== wxLIST_STATE_SELECTED
)
1208 if (IsDataBrowserItemSelected( m_dbImpl
->GetControlRef(), item
+1 ))
1209 return wxLIST_STATE_SELECTED
;
1218 info
.m_mask
= wxLIST_MASK_STATE
;
1219 info
.m_stateMask
= stateMask
;
1220 info
.m_itemId
= item
;
1225 return info
.m_state
;
1232 // Sets the item state
1233 bool wxListCtrl::SetItemState(long item
, long state
, long stateMask
)
1236 return m_genericImpl
->SetItemState(item
, state
, stateMask
);
1240 DataBrowserSetOption option
= kDataBrowserItemsAdd
;
1241 if ( (stateMask
& wxLIST_STATE_SELECTED
) && state
== 0 )
1242 option
= kDataBrowserItemsRemove
;
1246 if ( HasFlag(wxLC_VIRTUAL
) )
1248 wxMacDataItemBrowserSelectionSuppressor
suppressor(m_dbImpl
);
1249 m_dbImpl
->SetSelectedAllItems(option
);
1253 for(int i
= 0; i
< GetItemCount();i
++)
1257 info
.m_mask
= wxLIST_MASK_STATE
;
1258 info
.m_stateMask
= stateMask
;
1259 info
.m_state
= state
;
1266 if ( HasFlag(wxLC_VIRTUAL
) )
1268 long itemID
= item
+1;
1269 bool isSelected
= IsDataBrowserItemSelected(m_dbImpl
->GetControlRef(), (DataBrowserItemID
)itemID
);
1270 bool isSelectedState
= (state
== wxLIST_STATE_SELECTED
);
1272 // toggle the selection state if wxListInfo state and actual state don't match.
1273 if ( (stateMask
& wxLIST_STATE_SELECTED
) && isSelected
!= isSelectedState
)
1275 SetDataBrowserSelectedItems(m_dbImpl
->GetControlRef(), 1, (DataBrowserItemID
*)&itemID
, option
);
1281 info
.m_itemId
= item
;
1282 info
.m_mask
= wxLIST_MASK_STATE
;
1283 info
.m_stateMask
= stateMask
;
1284 info
.m_state
= state
;
1285 return SetItem(info
);
1292 // Sets the item image
1293 bool wxListCtrl::SetItemImage(long item
, int image
, int WXUNUSED(selImage
))
1295 return SetItemColumnImage(item
, 0, image
);
1298 // Sets the item image
1299 bool wxListCtrl::SetItemColumnImage(long item
, long column
, int image
)
1302 return m_genericImpl
->SetItemColumnImage(item
, column
, image
);
1306 info
.m_mask
= wxLIST_MASK_IMAGE
;
1307 info
.m_image
= image
;
1308 info
.m_itemId
= item
;
1309 info
.m_col
= column
;
1311 return SetItem(info
);
1314 // Gets the item text
1315 wxString
wxListCtrl::GetItemText(long item
) const
1318 return m_genericImpl
->GetItemText(item
);
1322 info
.m_mask
= wxLIST_MASK_TEXT
;
1323 info
.m_itemId
= item
;
1326 return wxEmptyString
;
1330 // Sets the item text
1331 void wxListCtrl::SetItemText(long item
, const wxString
& str
)
1334 return m_genericImpl
->SetItemText(item
, str
);
1338 info
.m_mask
= wxLIST_MASK_TEXT
;
1339 info
.m_itemId
= item
;
1345 // Gets the item data
1346 long wxListCtrl::GetItemData(long item
) const
1349 return m_genericImpl
->GetItemData(item
);
1353 info
.m_mask
= wxLIST_MASK_DATA
;
1354 info
.m_itemId
= item
;
1361 // Sets the item data
1362 bool wxListCtrl::SetItemPtrData(long item
, wxUIntPtr data
)
1365 return m_genericImpl
->SetItemData(item
, data
);
1369 info
.m_mask
= wxLIST_MASK_DATA
;
1370 info
.m_itemId
= item
;
1373 return SetItem(info
);
1376 wxRect
wxListCtrl::GetViewRect() const
1378 wxASSERT_MSG( !HasFlag(wxLC_REPORT
| wxLC_LIST
),
1379 _T("wxListCtrl::GetViewRect() only works in icon mode") );
1382 return m_genericImpl
->GetViewRect();
1388 bool wxListCtrl::GetSubItemRect( long item
, long subItem
, wxRect
& rect
, int code
) const
1391 return m_genericImpl
->GetItemRect(item
, rect
, code
);
1393 // TODO: implement for DataBrowser implementation
1397 // Gets the item rectangle
1398 bool wxListCtrl::GetItemRect(long item
, wxRect
& rect
, int code
) const
1401 return m_genericImpl
->GetItemRect(item
, rect
, code
);
1406 DataBrowserItemID id
;
1408 DataBrowserTableViewColumnID col
= 0;
1409 verify_noerr( m_dbImpl
->GetColumnIDFromIndex( 0, &col
) );
1412 DataBrowserPropertyPart part
= kDataBrowserPropertyEnclosingPart
;
1413 if ( code
== wxLIST_RECT_LABEL
)
1414 part
= kDataBrowserPropertyTextPart
;
1415 else if ( code
== wxLIST_RECT_ICON
)
1416 part
= kDataBrowserPropertyIconPart
;
1418 if ( !(GetWindowStyleFlag() & wxLC_VIRTUAL
) )
1420 wxMacDataItem
* thisItem
= m_dbImpl
->GetItemFromLine(item
);
1421 id
= (DataBrowserItemID
) thisItem
;
1426 GetDataBrowserItemPartBounds( m_dbImpl
->GetControlRef(), id
, col
, part
, &bounds
);
1428 rect
.x
= bounds
.left
;
1429 rect
.y
= bounds
.top
;
1430 rect
.width
= bounds
.right
- bounds
.left
; //GetClientSize().x; // we need the width of the whole row, not just the item.
1431 rect
.height
= bounds
.bottom
- bounds
.top
;
1432 //fprintf("id = %d, bounds = %d, %d, %d, %d\n", id, rect.x, rect.y, rect.width, rect.height);
1437 // Gets the item position
1438 bool wxListCtrl::GetItemPosition(long item
, wxPoint
& pos
) const
1441 return m_genericImpl
->GetItemPosition(item
, pos
);
1443 bool success
= false;
1448 GetItemRect(item
, itemRect
);
1449 pos
= itemRect
.GetPosition();
1456 // Sets the item position.
1457 bool wxListCtrl::SetItemPosition(long item
, const wxPoint
& pos
)
1460 return m_genericImpl
->SetItemPosition(item
, pos
);
1465 // Gets the number of items in the list control
1466 int wxListCtrl::GetItemCount() const
1469 return m_genericImpl
->GetItemCount();
1472 return m_dbImpl
->MacGetCount();
1477 void wxListCtrl::SetItemSpacing( int spacing
, bool isSmall
)
1480 m_genericImpl
->SetItemSpacing(spacing
, isSmall
);
1483 wxSize
wxListCtrl::GetItemSpacing() const
1486 return m_genericImpl
->GetItemSpacing();
1488 return wxSize(0, 0);
1491 void wxListCtrl::SetItemTextColour( long item
, const wxColour
&col
)
1495 m_genericImpl
->SetItemTextColour(item
, col
);
1500 info
.m_itemId
= item
;
1501 info
.SetTextColour( col
);
1505 wxColour
wxListCtrl::GetItemTextColour( long item
) const
1508 return m_genericImpl
->GetItemTextColour(item
);
1514 return info
.GetTextColour();
1516 return wxNullColour
;
1519 void wxListCtrl::SetItemBackgroundColour( long item
, const wxColour
&col
)
1523 m_genericImpl
->SetItemBackgroundColour(item
, col
);
1528 info
.m_itemId
= item
;
1529 info
.SetBackgroundColour( col
);
1533 wxColour
wxListCtrl::GetItemBackgroundColour( long item
) const
1536 return m_genericImpl
->GetItemBackgroundColour(item
);
1542 return info
.GetBackgroundColour();
1544 return wxNullColour
;
1547 void wxListCtrl::SetItemFont( long item
, const wxFont
&f
)
1551 m_genericImpl
->SetItemFont(item
, f
);
1556 info
.m_itemId
= item
;
1561 wxFont
wxListCtrl::GetItemFont( long item
) const
1564 return m_genericImpl
->GetItemFont(item
);
1570 return info
.GetFont();
1576 // Gets the number of selected items in the list control
1577 int wxListCtrl::GetSelectedItemCount() const
1580 return m_genericImpl
->GetSelectedItemCount();
1583 return m_dbImpl
->GetSelectedItemCount(NULL
, true);
1588 // Gets the text colour of the listview
1589 wxColour
wxListCtrl::GetTextColour() const
1592 return m_genericImpl
->GetTextColour();
1594 // TODO: we need owner drawn list items to customize text color.
1598 return wxNullColour
;
1601 // Sets the text colour of the listview
1602 void wxListCtrl::SetTextColour(const wxColour
& col
)
1606 m_genericImpl
->SetTextColour(col
);
1614 // Gets the index of the topmost visible item when in
1615 // list or report view
1616 long wxListCtrl::GetTopItem() const
1619 return m_genericImpl
->GetTopItem();
1624 long item
= HitTest( wxPoint(1, 1), flags
);
1625 if (flags
== wxLIST_HITTEST_ONITEM
)
1632 // Searches for an item, starting from 'item'.
1633 // 'geometry' is one of
1634 // wxLIST_NEXT_ABOVE/ALL/BELOW/LEFT/RIGHT.
1635 // 'state' is a state bit flag, one or more of
1636 // wxLIST_STATE_DROPHILITED/FOCUSED/SELECTED/CUT.
1637 // item can be -1 to find the first item that matches the
1639 // Returns the item or -1 if unsuccessful.
1640 long wxListCtrl::GetNextItem(long item
, int geom
, int state
) const
1643 return m_genericImpl
->GetNextItem(item
, geom
, state
);
1645 // TODO: implement all geometry and state options?
1648 if ( geom
== wxLIST_NEXT_ALL
|| geom
== wxLIST_NEXT_BELOW
)
1650 long count
= m_dbImpl
->MacGetCount() ;
1651 for ( long line
= item
+ 1 ; line
< count
; line
++ )
1653 DataBrowserItemID id
= line
+ 1;
1655 id
= (DataBrowserItemID
)m_dbImpl
->GetItemFromLine(line
);
1657 if ( (state
== wxLIST_STATE_DONTCARE
) )
1660 if ( (state
& wxLIST_STATE_SELECTED
) && IsDataBrowserItemSelected(m_dbImpl
->GetControlRef(), id
) )
1665 if ( geom
== wxLIST_NEXT_ABOVE
)
1669 item2
= m_dbImpl
->MacGetCount();
1671 for ( long line
= item2
- 1 ; line
>= 0; line
-- )
1673 DataBrowserItemID id
= line
+ 1;
1675 id
= (DataBrowserItemID
)m_dbImpl
->GetItemFromLine(line
);
1677 if ( (state
== wxLIST_STATE_DONTCARE
) )
1680 if ( (state
& wxLIST_STATE_SELECTED
) && IsDataBrowserItemSelected(m_dbImpl
->GetControlRef(), id
) )
1690 wxImageList
*wxListCtrl::GetImageList(int which
) const
1693 return m_genericImpl
->GetImageList(which
);
1695 if ( which
== wxIMAGE_LIST_NORMAL
)
1697 return m_imageListNormal
;
1699 else if ( which
== wxIMAGE_LIST_SMALL
)
1701 return m_imageListSmall
;
1703 else if ( which
== wxIMAGE_LIST_STATE
)
1705 return m_imageListState
;
1710 void wxListCtrl::SetImageList(wxImageList
*imageList
, int which
)
1714 m_genericImpl
->SetImageList(imageList
, which
);
1718 if ( which
== wxIMAGE_LIST_NORMAL
)
1720 if (m_ownsImageListNormal
) delete m_imageListNormal
;
1721 m_imageListNormal
= imageList
;
1722 m_ownsImageListNormal
= false;
1724 else if ( which
== wxIMAGE_LIST_SMALL
)
1726 if (m_ownsImageListSmall
) delete m_imageListSmall
;
1727 m_imageListSmall
= imageList
;
1728 m_ownsImageListSmall
= false;
1730 else if ( which
== wxIMAGE_LIST_STATE
)
1732 if (m_ownsImageListState
) delete m_imageListState
;
1733 m_imageListState
= imageList
;
1734 m_ownsImageListState
= false;
1738 void wxListCtrl::AssignImageList(wxImageList
*imageList
, int which
)
1742 m_genericImpl
->AssignImageList(imageList
, which
);
1746 SetImageList(imageList
, which
);
1747 if ( which
== wxIMAGE_LIST_NORMAL
)
1748 m_ownsImageListNormal
= true;
1749 else if ( which
== wxIMAGE_LIST_SMALL
)
1750 m_ownsImageListSmall
= true;
1751 else if ( which
== wxIMAGE_LIST_STATE
)
1752 m_ownsImageListState
= true;
1755 // ----------------------------------------------------------------------------
1757 // ----------------------------------------------------------------------------
1759 // Arranges the items
1760 bool wxListCtrl::Arrange(int flag
)
1763 return m_genericImpl
->Arrange(flag
);
1768 bool wxListCtrl::DeleteItem(long item
)
1771 return m_genericImpl
->DeleteItem(item
);
1775 m_dbImpl
->MacDelete(item
);
1776 wxListEvent
event( wxEVT_COMMAND_LIST_DELETE_ITEM
, GetId() );
1777 event
.SetEventObject( this );
1778 event
.m_itemIndex
= item
;
1779 HandleWindowEvent( event
);
1785 // Deletes all items
1786 bool wxListCtrl::DeleteAllItems()
1789 return m_genericImpl
->DeleteAllItems();
1793 m_dbImpl
->MacClear();
1794 wxListEvent
event( wxEVT_COMMAND_LIST_DELETE_ALL_ITEMS
, GetId() );
1795 event
.SetEventObject( this );
1796 HandleWindowEvent( event
);
1801 // Deletes all items
1802 bool wxListCtrl::DeleteAllColumns()
1805 return m_genericImpl
->DeleteAllColumns();
1810 m_dbImpl
->GetColumnCount(&cols
);
1811 for (UInt32 col
= 0; col
< cols
; col
++)
1821 bool wxListCtrl::DeleteColumn(int col
)
1824 return m_genericImpl
->DeleteColumn(col
);
1828 OSStatus err
= m_dbImpl
->RemoveColumn(col
);
1829 return err
== noErr
;
1835 // Clears items, and columns if there are any.
1836 void wxListCtrl::ClearAll()
1840 m_genericImpl
->ClearAll();
1851 wxTextCtrl
* wxListCtrl::EditLabel(long item
, wxClassInfo
* textControlClass
)
1854 return m_genericImpl
->EditLabel(item
, textControlClass
);
1858 wxCHECK_MSG( (item
>= 0) && ((long)item
< GetItemCount()), NULL
,
1859 wxT("wrong index in wxListCtrl::EditLabel()") );
1861 wxASSERT_MSG( textControlClass
->IsKindOf(CLASSINFO(wxTextCtrl
)),
1862 wxT("EditLabel() needs a text control") );
1864 wxListEvent
le( wxEVT_COMMAND_LIST_BEGIN_LABEL_EDIT
, GetParent()->GetId() );
1865 le
.SetEventObject( this );
1866 le
.m_itemIndex
= item
;
1868 GetItem( le
.m_item
);
1870 if ( GetParent()->HandleWindowEvent( le
) && !le
.IsAllowed() )
1872 // vetoed by user code
1876 wxTextCtrl
* const text
= (wxTextCtrl
*)textControlClass
->CreateObject();
1877 m_textctrlWrapper
= new wxListCtrlTextCtrlWrapper(this, text
, item
);
1878 return m_textctrlWrapper
->GetText();
1883 // End label editing, optionally cancelling the edit
1884 bool wxListCtrl::EndEditLabel(bool WXUNUSED(cancel
))
1886 // TODO: generic impl. doesn't have this method - is it needed for us?
1888 return true; // m_genericImpl->EndEditLabel(cancel);
1892 DataBrowserTableViewColumnID id
= 0;
1893 verify_noerr( m_dbImpl
->GetColumnIDFromIndex( 0, &id
) );
1894 verify_noerr( SetDataBrowserEditItem(m_dbImpl
->GetControlRef(), kDataBrowserNoItem
, id
) );
1899 // Ensures this item is visible
1900 bool wxListCtrl::EnsureVisible(long item
)
1903 return m_genericImpl
->EnsureVisible(item
);
1907 wxMacDataItem
* dataItem
= m_dbImpl
->GetItemFromLine(item
);
1908 m_dbImpl
->RevealItem(dataItem
, kDataBrowserRevealWithoutSelecting
);
1914 // Find an item whose label matches this string, starting from the item after 'start'
1915 // or the beginning if 'start' is -1.
1916 long wxListCtrl::FindItem(long start
, const wxString
& str
, bool partial
)
1919 return m_genericImpl
->FindItem(start
, str
, partial
);
1921 wxString str_upper
= str
.Upper();
1926 long count
= GetItemCount();
1930 wxString line_upper
= GetItemText(idx
).Upper();
1933 if (line_upper
== str_upper
)
1938 if (line_upper
.find(str_upper
) == 0)
1948 // Find an item whose data matches this data, starting from the item after 'start'
1949 // or the beginning if 'start' is -1.
1950 long wxListCtrl::FindItem(long start
, long data
)
1953 return m_genericImpl
->FindItem(start
, data
);
1958 long count
= GetItemCount();
1962 if (GetItemData(idx
) == data
)
1970 // Find an item nearest this position in the specified direction, starting from
1971 // the item after 'start' or the beginning if 'start' is -1.
1972 long wxListCtrl::FindItem(long start
, const wxPoint
& pt
, int direction
)
1975 return m_genericImpl
->FindItem(start
, pt
, direction
);
1979 // Determines which item (if any) is at the specified point,
1980 // giving details in 'flags' (see wxLIST_HITTEST_... flags above)
1982 wxListCtrl::HitTest(const wxPoint
& point
, int& flags
, long *ptrSubItem
) const
1985 return m_genericImpl
->HitTest(point
, flags
, ptrSubItem
);
1987 flags
= wxLIST_HITTEST_NOWHERE
;
1990 int colHeaderHeight
= 22; // TODO: Find a way to get this value from the db control?
1991 UInt16 rowHeight
= 0;
1992 m_dbImpl
->GetDefaultRowHeight(&rowHeight
);
1995 // get the actual row by taking scroll position into account
1996 UInt32 offsetX
, offsetY
;
1997 m_dbImpl
->GetScrollPosition( &offsetY
, &offsetX
);
2000 if ( !(GetWindowStyleFlag() & wxLC_NO_HEADER
) )
2001 y
-= colHeaderHeight
;
2006 int row
= y
/ rowHeight
;
2007 DataBrowserItemID id
;
2008 m_dbImpl
->GetItemID( (DataBrowserTableViewRowIndex
) row
, &id
);
2010 // TODO: Use GetDataBrowserItemPartBounds to return if we are in icon or label
2011 if ( !(GetWindowStyleFlag() & wxLC_VIRTUAL
) )
2013 wxMacListCtrlItem
* lcItem
;
2014 lcItem
= (wxMacListCtrlItem
*) id
;
2017 flags
= wxLIST_HITTEST_ONITEM
;
2023 if (row
< GetItemCount() )
2025 flags
= wxLIST_HITTEST_ONITEM
;
2034 int wxListCtrl::GetScrollPos(int orient
) const
2037 return m_genericImpl
->GetScrollPos(orient
);
2041 UInt32 offsetX
, offsetY
;
2042 m_dbImpl
->GetScrollPosition( &offsetY
, &offsetX
);
2043 if ( orient
== wxHORIZONTAL
)
2052 // Inserts an item, returning the index of the new item if successful,
2054 long wxListCtrl::InsertItem(wxListItem
& info
)
2056 wxASSERT_MSG( !IsVirtual(), _T("can't be used with virtual controls") );
2059 return m_genericImpl
->InsertItem(info
);
2061 if (m_dbImpl
&& !IsVirtual())
2063 int count
= GetItemCount();
2065 if (info
.m_itemId
> count
)
2066 info
.m_itemId
= count
;
2068 m_dbImpl
->MacInsertItem(info
.m_itemId
, &info
);
2070 wxListEvent
event( wxEVT_COMMAND_LIST_INSERT_ITEM
, GetId() );
2071 event
.SetEventObject( this );
2072 event
.m_itemIndex
= info
.m_itemId
;
2073 HandleWindowEvent( event
);
2074 return info
.m_itemId
;
2079 long wxListCtrl::InsertItem(long index
, const wxString
& label
)
2082 return m_genericImpl
->InsertItem(index
, label
);
2085 info
.m_text
= label
;
2086 info
.m_mask
= wxLIST_MASK_TEXT
;
2087 info
.m_itemId
= index
;
2088 return InsertItem(info
);
2091 // Inserts an image item
2092 long wxListCtrl::InsertItem(long index
, int imageIndex
)
2095 return m_genericImpl
->InsertItem(index
, imageIndex
);
2098 info
.m_image
= imageIndex
;
2099 info
.m_mask
= wxLIST_MASK_IMAGE
;
2100 info
.m_itemId
= index
;
2101 return InsertItem(info
);
2104 // Inserts an image/string item
2105 long wxListCtrl::InsertItem(long index
, const wxString
& label
, int imageIndex
)
2108 return m_genericImpl
->InsertItem(index
, label
, imageIndex
);
2111 info
.m_image
= imageIndex
;
2112 info
.m_text
= label
;
2113 info
.m_mask
= wxLIST_MASK_IMAGE
| wxLIST_MASK_TEXT
;
2114 info
.m_itemId
= index
;
2115 return InsertItem(info
);
2118 // For list view mode (only), inserts a column.
2119 long wxListCtrl::InsertColumn(long col
, wxListItem
& item
)
2122 return m_genericImpl
->InsertColumn(col
, item
);
2126 int width
= item
.GetWidth();
2127 if ( !(item
.GetMask() & wxLIST_MASK_WIDTH
) )
2130 DataBrowserPropertyType type
= kDataBrowserCustomType
; //kDataBrowserTextType;
2131 wxImageList
* imageList
= GetImageList(wxIMAGE_LIST_SMALL
);
2132 if (imageList
&& imageList
->GetImageCount() > 0)
2134 wxBitmap bmp
= imageList
->GetBitmap(0);
2136 // type = kDataBrowserIconAndTextType;
2139 SInt16 just
= teFlushDefault
;
2140 if (item
.GetMask() & wxLIST_MASK_FORMAT
)
2142 if (item
.GetAlign() == wxLIST_FORMAT_LEFT
)
2144 else if (item
.GetAlign() == wxLIST_FORMAT_CENTER
)
2146 else if (item
.GetAlign() == wxLIST_FORMAT_RIGHT
)
2147 just
= teFlushRight
;
2149 m_dbImpl
->InsertColumn(col
, type
, item
.GetText(), just
, width
);
2151 wxListItem
* listItem
= new wxListItem(item
);
2152 m_colsInfo
.Insert( col
, listItem
);
2153 SetColumn(col
, item
);
2155 // set/remove options based on the wxListCtrl type.
2156 DataBrowserTableViewColumnID id
;
2157 m_dbImpl
->GetColumnIDFromIndex(col
, &id
);
2158 DataBrowserPropertyFlags flags
;
2159 verify_noerr(m_dbImpl
->GetPropertyFlags(id
, &flags
));
2160 if (GetWindowStyleFlag() & wxLC_EDIT_LABELS
)
2161 flags
|= kDataBrowserPropertyIsEditable
;
2163 if (GetWindowStyleFlag() & wxLC_VIRTUAL
){
2164 flags
&= ~kDataBrowserListViewSortableColumn
;
2166 verify_noerr(m_dbImpl
->SetPropertyFlags(id
, flags
));
2172 long wxListCtrl::InsertColumn(long col
,
2173 const wxString
& heading
,
2178 return m_genericImpl
->InsertColumn(col
, heading
, format
, width
);
2181 item
.m_mask
= wxLIST_MASK_TEXT
| wxLIST_MASK_FORMAT
;
2182 item
.m_text
= heading
;
2185 item
.m_mask
|= wxLIST_MASK_WIDTH
;
2186 item
.m_width
= width
;
2188 item
.m_format
= format
;
2190 return InsertColumn(col
, item
);
2193 // scroll the control by the given number of pixels (exception: in list view,
2194 // dx is interpreted as number of columns)
2195 bool wxListCtrl::ScrollList(int dx
, int dy
)
2198 return m_genericImpl
->ScrollList(dx
, dy
);
2202 m_dbImpl
->SetScrollPosition(dx
, dy
);
2208 bool wxListCtrl::SortItems(wxListCtrlCompare fn
, long data
)
2211 return m_genericImpl
->SortItems(fn
, data
);
2216 m_compareFuncData
= data
;
2217 SortDataBrowserContainer( m_dbImpl
->GetControlRef(), kDataBrowserNoItem
, true);
2219 // we need to do this after each call, else we get a crash from wxPython when
2220 // SortItems is called the second time.
2221 m_compareFunc
= NULL
;
2222 m_compareFuncData
= 0;
2228 void wxListCtrl::OnRenameTimer()
2230 wxCHECK_RET( HasCurrent(), wxT("unexpected rename timer") );
2232 EditLabel( m_current
);
2235 bool wxListCtrl::OnRenameAccept(long itemEdit
, const wxString
& value
)
2237 wxListEvent
le( wxEVT_COMMAND_LIST_END_LABEL_EDIT
, GetId() );
2238 le
.SetEventObject( this );
2239 le
.m_itemIndex
= itemEdit
;
2241 GetItem( le
.m_item
);
2242 le
.m_item
.m_text
= value
;
2243 return !HandleWindowEvent( le
) ||
2247 void wxListCtrl::OnRenameCancelled(long itemEdit
)
2249 // let owner know that the edit was cancelled
2250 wxListEvent
le( wxEVT_COMMAND_LIST_END_LABEL_EDIT
, GetParent()->GetId() );
2252 le
.SetEditCanceled(true);
2254 le
.SetEventObject( this );
2255 le
.m_itemIndex
= itemEdit
;
2257 GetItem( le
.m_item
);
2258 HandleWindowEvent( le
);
2261 // ----------------------------------------------------------------------------
2262 // virtual list controls
2263 // ----------------------------------------------------------------------------
2265 wxString
wxListCtrl::OnGetItemText(long WXUNUSED(item
), long WXUNUSED(col
)) const
2267 // this is a pure virtual function, in fact - which is not really pure
2268 // because the controls which are not virtual don't need to implement it
2269 wxFAIL_MSG( _T("wxListCtrl::OnGetItemText not supposed to be called") );
2271 return wxEmptyString
;
2274 int wxListCtrl::OnGetItemImage(long WXUNUSED(item
)) const
2276 wxCHECK_MSG(!GetImageList(wxIMAGE_LIST_SMALL
),
2278 wxT("List control has an image list, OnGetItemImage or OnGetItemColumnImage should be overridden."));
2282 int wxListCtrl::OnGetItemColumnImage(long item
, long column
) const
2285 return OnGetItemImage(item
);
2290 wxListItemAttr
*wxListCtrl::OnGetItemAttr(long WXUNUSED_UNLESS_DEBUG(item
)) const
2292 wxASSERT_MSG( item
>= 0 && item
< GetItemCount(),
2293 _T("invalid item index in OnGetItemAttr()") );
2295 // no attributes by default
2299 void wxListCtrl::SetItemCount(long count
)
2301 wxASSERT_MSG( IsVirtual(), _T("this is for virtual controls only") );
2305 m_genericImpl
->SetItemCount(count
);
2311 // we need to temporarily disable the new item creation notification
2312 // procedure to speed things up
2313 // FIXME: Even this doesn't seem to help much...
2315 // FIXME: Find a more efficient way to do this.
2316 m_dbImpl
->MacClear();
2318 DataBrowserCallbacks callbacks
;
2319 DataBrowserItemNotificationUPP itemUPP
;
2320 GetDataBrowserCallbacks(m_dbImpl
->GetControlRef(), &callbacks
);
2321 itemUPP
= callbacks
.u
.v1
.itemNotificationCallback
;
2322 callbacks
.u
.v1
.itemNotificationCallback
= 0;
2323 m_dbImpl
->SetCallbacks(&callbacks
);
2324 ::AddDataBrowserItems(m_dbImpl
->GetControlRef(), kDataBrowserNoItem
,
2325 count
, NULL
, kDataBrowserItemNoProperty
);
2326 callbacks
.u
.v1
.itemNotificationCallback
= itemUPP
;
2327 m_dbImpl
->SetCallbacks(&callbacks
);
2332 void wxListCtrl::RefreshItem(long item
)
2336 m_genericImpl
->RefreshItem(item
);
2342 DataBrowserItemID id
;
2346 wxMacDataItem
* thisItem
= m_dbImpl
->GetItemFromLine(item
);
2347 id
= (DataBrowserItemID
) thisItem
;
2352 m_dbImpl
->wxMacDataBrowserControl::UpdateItems
2356 kDataBrowserItemNoProperty
, // preSortProperty
2357 kDataBrowserNoItem
// update all columns
2362 void wxListCtrl::RefreshItems(long itemFrom
, long itemTo
)
2366 m_genericImpl
->RefreshItems(itemFrom
, itemTo
);
2372 const long count
= itemTo
- itemFrom
+ 1;
2373 DataBrowserItemID
*ids
= new DataBrowserItemID
[count
];
2377 for ( long i
= 0; i
< count
; i
++ )
2379 wxMacDataItem
* thisItem
= m_dbImpl
->GetItemFromLine(itemFrom
+i
);
2380 ids
[i
] = (DataBrowserItemID
) thisItem
;
2385 for ( long i
= 0; i
< count
; i
++ )
2386 ids
[i
] = itemFrom
+i
+1;
2389 m_dbImpl
->wxMacDataBrowserControl::UpdateItems
2393 kDataBrowserItemNoProperty
, // preSortProperty
2394 kDataBrowserNoItem
// update all columns
2401 void wxListCtrl::SetDropTarget( wxDropTarget
*dropTarget
)
2403 #if wxUSE_DRAG_AND_DROP
2405 m_genericImpl
->SetDropTarget( dropTarget
);
2408 wxWindow::SetDropTarget( dropTarget
);
2412 wxDropTarget
*wxListCtrl::GetDropTarget() const
2414 #if wxUSE_DRAG_AND_DROP
2416 return m_genericImpl
->GetDropTarget();
2419 return wxWindow::GetDropTarget();
2424 #if wxABI_VERSION >= 20801
2425 void wxListCtrl::SetFocus()
2429 m_genericImpl
->SetFocus();
2433 wxWindow::SetFocus();
2437 // wxMac internal data structures
2439 wxMacListCtrlItem::~wxMacListCtrlItem()
2441 WX_CLEAR_HASH_MAP( wxListItemList
, m_rowItems
);
2444 void wxMacListCtrlItem::Notification(wxMacDataItemBrowserControl
*owner
,
2445 DataBrowserItemNotification message
,
2446 DataBrowserItemDataRef
WXUNUSED(itemData
) ) const
2449 wxMacDataBrowserListCtrlControl
*lb
= wxDynamicCast(owner
, wxMacDataBrowserListCtrlControl
);
2451 // we want to depend on as little as possible to make sure tear-down of controls is safe
2452 if ( message
== kDataBrowserItemRemoved
)
2457 else if ( message
== kDataBrowserItemAdded
)
2459 // we don't issue events on adding, the item is not really stored in the list yet, so we
2460 // avoid asserts by gettting out now
2464 wxListCtrl
*list
= wxDynamicCast( owner
->GetWXPeer() , wxListCtrl
);
2467 bool trigger
= false;
2469 wxListEvent
event( wxEVT_COMMAND_LIST_ITEM_SELECTED
, list
->GetId() );
2470 bool isSingle
= (list
->GetWindowStyle() & wxLC_SINGLE_SEL
) != 0;
2472 event
.SetEventObject( list
);
2473 event
.m_itemIndex
= owner
->GetLineFromItem( this ) ;
2474 event
.m_item
.m_itemId
= event
.m_itemIndex
;
2475 list
->GetItem(event
.m_item
);
2479 case kDataBrowserItemDeselected
:
2480 event
.SetEventType(wxEVT_COMMAND_LIST_ITEM_DESELECTED
);
2482 trigger
= !lb
->IsSelectionSuppressed();
2485 case kDataBrowserItemSelected
:
2486 trigger
= !lb
->IsSelectionSuppressed();
2489 case kDataBrowserItemDoubleClicked
:
2490 event
.SetEventType( wxEVT_COMMAND_LIST_ITEM_ACTIVATED
);
2494 case kDataBrowserEditStarted
:
2495 // TODO : how to veto ?
2496 event
.SetEventType( wxEVT_COMMAND_LIST_BEGIN_LABEL_EDIT
) ;
2500 case kDataBrowserEditStopped
:
2501 // TODO probably trigger only upon the value store callback, because
2502 // here IIRC we cannot veto
2503 event
.SetEventType( wxEVT_COMMAND_LIST_END_LABEL_EDIT
) ;
2513 // direct notification is not always having the listbox GetSelection() having in synch with event
2514 wxPostEvent( list
->GetEventHandler(), event
);
2520 IMPLEMENT_DYNAMIC_CLASS(wxMacDataBrowserListCtrlControl
, wxMacDataItemBrowserControl
)
2522 wxMacDataBrowserListCtrlControl::wxMacDataBrowserListCtrlControl( wxWindow
*peer
, const wxPoint
& pos
, const wxSize
& size
, long style
)
2523 : wxMacDataItemBrowserControl( peer
, pos
, size
, style
)
2525 OSStatus err
= noErr
;
2526 m_clientDataItemsType
= wxClientData_None
;
2527 m_isVirtual
= false;
2530 if ( style
& wxLC_VIRTUAL
)
2533 DataBrowserSelectionFlags options
= kDataBrowserDragSelect
;
2534 if ( style
& wxLC_SINGLE_SEL
)
2536 options
|= kDataBrowserSelectOnlyOne
;
2540 options
|= kDataBrowserCmdTogglesSelection
;
2543 err
= SetSelectionFlags( options
);
2544 verify_noerr( err
);
2546 DataBrowserCustomCallbacks callbacks
;
2547 InitializeDataBrowserCustomCallbacks( &callbacks
, kDataBrowserLatestCustomCallbacks
);
2549 if ( gDataBrowserDrawItemUPP
== NULL
)
2550 gDataBrowserDrawItemUPP
= NewDataBrowserDrawItemUPP(DataBrowserDrawItemProc
);
2552 if ( gDataBrowserHitTestUPP
== NULL
)
2553 gDataBrowserHitTestUPP
= NewDataBrowserHitTestUPP(DataBrowserHitTestProc
);
2555 callbacks
.u
.v1
.drawItemCallback
= gDataBrowserDrawItemUPP
;
2556 callbacks
.u
.v1
.hitTestCallback
= gDataBrowserHitTestUPP
;
2558 SetDataBrowserCustomCallbacks( GetControlRef(), &callbacks
);
2560 if ( style
& wxLC_LIST
)
2562 InsertColumn(0, kDataBrowserIconAndTextType
, wxEmptyString
, -1, -1);
2563 verify_noerr( AutoSizeColumns() );
2566 if ( style
& wxLC_LIST
|| style
& wxLC_NO_HEADER
)
2567 verify_noerr( SetHeaderButtonHeight( 0 ) );
2570 SetSortProperty( kMinColumnId
- 1 );
2572 SetSortProperty( kMinColumnId
);
2574 m_sortOrder
= SortOrder_None
;
2576 if ( style
& wxLC_SORT_DESCENDING
)
2578 SetSortOrder( kDataBrowserOrderDecreasing
);
2580 else if ( style
& wxLC_SORT_ASCENDING
)
2582 SetSortOrder( kDataBrowserOrderIncreasing
);
2585 if ( style
& wxLC_VRULES
)
2587 verify_noerr( DataBrowserChangeAttributes(m_controlRef
, kDataBrowserAttributeListViewDrawColumnDividers
, kDataBrowserAttributeNone
) );
2590 verify_noerr( SetHiliteStyle(kDataBrowserTableViewFillHilite
) );
2591 verify_noerr( SetHasScrollBars( (style
& wxHSCROLL
) != 0 , true ) );
2594 pascal Boolean
wxMacDataBrowserListCtrlControl::DataBrowserEditTextProc(
2596 DataBrowserItemID itemID
,
2597 DataBrowserPropertyID property
,
2598 CFStringRef theString
,
2599 Rect
*maxEditTextRect
,
2600 Boolean
*shrinkToFit
)
2602 Boolean result
= false;
2603 wxMacDataBrowserListCtrlControl
* ctl
= wxDynamicCast(wxMacControl::GetReferenceFromNativeControl( browser
), wxMacDataBrowserListCtrlControl
);
2606 result
= ctl
->ConfirmEditText(itemID
, property
, theString
, maxEditTextRect
, shrinkToFit
);
2607 theString
= CFSTR("Hello!");
2612 bool wxMacDataBrowserListCtrlControl::ConfirmEditText(
2613 DataBrowserItemID
WXUNUSED(itemID
),
2614 DataBrowserPropertyID
WXUNUSED(property
),
2615 CFStringRef
WXUNUSED(theString
),
2616 Rect
*WXUNUSED(maxEditTextRect
),
2617 Boolean
*WXUNUSED(shrinkToFit
))
2622 pascal void wxMacDataBrowserListCtrlControl::DataBrowserDrawItemProc(
2624 DataBrowserItemID itemID
,
2625 DataBrowserPropertyID property
,
2626 DataBrowserItemState itemState
,
2627 const Rect
*itemRect
,
2629 Boolean colorDevice
)
2631 wxMacDataBrowserListCtrlControl
* ctl
= wxDynamicCast(wxMacControl::GetReferenceFromNativeControl( browser
), wxMacDataBrowserListCtrlControl
);
2634 ctl
->DrawItem(itemID
, property
, itemState
, itemRect
, gdDepth
, colorDevice
);
2638 // routines needed for DrawItem
2643 kTextBoxHeight
= 14,
2644 kIconTextSpacingV
= 2,
2646 kContentHeight
= kIconHeight
+ kTextBoxHeight
+ kIconTextSpacingV
2649 static void calculateCGDrawingBounds(CGRect inItemRect
, CGRect
*outIconRect
, CGRect
*outTextRect
, bool hasIcon
= false)
2652 float iconH
, iconW
= 0;
2653 float padding
= kItemPadding
;
2656 iconH
= kIconHeight
;
2658 padding
= padding
*2;
2661 textBottom
= inItemRect
.origin
.y
;
2663 *outIconRect
= CGRectMake(inItemRect
.origin
.x
+ kItemPadding
,
2664 textBottom
+ kIconTextSpacingV
, kIconWidth
,
2667 *outTextRect
= CGRectMake(inItemRect
.origin
.x
+ padding
+ iconW
,
2668 textBottom
+ kIconTextSpacingV
, inItemRect
.size
.width
- padding
- iconW
,
2669 inItemRect
.size
.height
- kIconTextSpacingV
);
2672 void wxMacDataBrowserListCtrlControl::DrawItem(
2673 DataBrowserItemID itemID
,
2674 DataBrowserPropertyID property
,
2675 DataBrowserItemState itemState
,
2676 const Rect
*WXUNUSED(itemRect
),
2678 Boolean colorDevice
)
2681 wxFont font
= wxNullFont
;
2684 DataBrowserTableViewColumnIndex listColumn
= 0;
2685 OSStatus err
= GetColumnPosition( property
, &listColumn
);
2687 wxListCtrl
* list
= wxDynamicCast( GetWXPeer() , wxListCtrl
);
2688 wxMacListCtrlItem
* lcItem
;
2689 wxColour color
= *wxBLACK
;
2690 wxColour bgColor
= wxNullColour
;
2692 if (listColumn
>= 0)
2696 lcItem
= (wxMacListCtrlItem
*) itemID
;
2697 if (lcItem
->HasColumnInfo(listColumn
))
2699 wxListItem
* item
= lcItem
->GetColumnInfo(listColumn
);
2701 // we always use the 0 column to get font and text/background colors.
2702 if (lcItem
->HasColumnInfo(0))
2704 wxListItem
* firstItem
= lcItem
->GetColumnInfo(0);
2705 color
= firstItem
->GetTextColour();
2706 bgColor
= firstItem
->GetBackgroundColour();
2707 font
= firstItem
->GetFont();
2710 if (item
->GetMask() & wxLIST_MASK_TEXT
)
2711 text
= item
->GetText();
2712 if (item
->GetMask() & wxLIST_MASK_IMAGE
)
2713 imgIndex
= item
->GetImage();
2719 long itemNum
= (long)itemID
-1;
2720 if (itemNum
>= 0 && itemNum
< list
->GetItemCount())
2722 text
= list
->OnGetItemText( itemNum
, listColumn
);
2723 imgIndex
= list
->OnGetItemColumnImage( itemNum
, listColumn
);
2724 wxListItemAttr
* attrs
= list
->OnGetItemAttr( itemNum
);
2727 if (attrs
->HasBackgroundColour())
2728 bgColor
= attrs
->GetBackgroundColour();
2729 if (attrs
->HasTextColour())
2730 color
= attrs
->GetTextColour();
2731 if (attrs
->HasFont())
2732 font
= attrs
->GetFont();
2738 wxColour listBgColor
= list
->GetBackgroundColour();
2739 if (bgColor
== wxNullColour
)
2740 bgColor
= listBgColor
;
2743 font
= list
->GetFont();
2745 wxCFStringRef
cfString( text
, wxLocale::GetSystemEncoding() );
2748 CGRect enclosingCGRect
, iconCGRect
, textCGRect
;
2750 ThemeDrawingState savedState
= NULL
;
2751 CGContextRef context
= (CGContextRef
)list
->MacGetDrawingContext();
2752 RGBColor labelColor
;
2754 labelColor
.green
= 0;
2755 labelColor
.blue
= 0;
2757 RGBColor backgroundColor
;
2758 backgroundColor
.red
= 255;
2759 backgroundColor
.green
= 255;
2760 backgroundColor
.blue
= 255;
2762 GetDataBrowserItemPartBounds(GetControlRef(), itemID
, property
, kDataBrowserPropertyEnclosingPart
,
2765 enclosingCGRect
= CGRectMake(enclosingRect
.left
,
2767 enclosingRect
.right
- enclosingRect
.left
,
2768 enclosingRect
.bottom
- enclosingRect
.top
);
2770 bool hasFocus
= (wxWindow::FindFocus() == list
);
2771 active
= IsControlActive(GetControlRef());
2773 // don't paint the background over the vertical rule line
2774 if ( list
->GetWindowStyleFlag() & wxLC_VRULES
)
2776 enclosingCGRect
.origin
.x
+= 1;
2777 enclosingCGRect
.size
.width
-= 1;
2779 if (itemState
== kDataBrowserItemIsSelected
)
2782 GetThemeDrawingState(&savedState
);
2784 if (active
&& hasFocus
)
2786 GetThemeBrushAsColor(kThemeBrushAlternatePrimaryHighlightColor
, 32, true, &backgroundColor
);
2787 GetThemeTextColor(kThemeTextColorWhite
, gdDepth
, colorDevice
, &labelColor
);
2791 GetThemeBrushAsColor(kThemeBrushSecondaryHighlightColor
, 32, true, &backgroundColor
);
2792 GetThemeTextColor(kThemeTextColorBlack
, gdDepth
, colorDevice
, &labelColor
);
2794 CGContextSaveGState(context
);
2796 CGContextSetRGBFillColor(context
, (CGFloat
)backgroundColor
.red
/ (CGFloat
)USHRT_MAX
,
2797 (CGFloat
)backgroundColor
.green
/ (CGFloat
)USHRT_MAX
,
2798 (CGFloat
)backgroundColor
.blue
/ (CGFloat
)USHRT_MAX
, (CGFloat
) 1.0);
2799 CGContextFillRect(context
, enclosingCGRect
);
2801 CGContextRestoreGState(context
);
2807 color
.GetRGBColor(&labelColor
);
2808 else if (list
->GetTextColour().Ok())
2809 list
->GetTextColour().GetRGBColor(&labelColor
);
2813 bgColor
.GetRGBColor(&backgroundColor
);
2814 CGContextSaveGState(context
);
2816 CGContextSetRGBFillColor(context
, (CGFloat
)backgroundColor
.red
/ (CGFloat
)USHRT_MAX
,
2817 (CGFloat
)backgroundColor
.green
/ (CGFloat
)USHRT_MAX
,
2818 (CGFloat
)backgroundColor
.blue
/ (CGFloat
)USHRT_MAX
, (CGFloat
) 1.0);
2819 CGContextFillRect(context
, enclosingCGRect
);
2821 CGContextRestoreGState(context
);
2825 calculateCGDrawingBounds(enclosingCGRect
, &iconCGRect
, &textCGRect
, (imgIndex
!= -1) );
2829 wxImageList
* imageList
= list
->GetImageList(wxIMAGE_LIST_SMALL
);
2830 if (imageList
&& imageList
->GetImageCount() > 0){
2831 wxBitmap bmp
= imageList
->GetBitmap(imgIndex
);
2832 IconRef icon
= bmp
.GetIconRef();
2834 CGContextSaveGState(context
);
2835 CGContextTranslateCTM(context
, 0,iconCGRect
.origin
.y
+ CGRectGetMaxY(iconCGRect
));
2836 CGContextScaleCTM(context
,1.0f
,-1.0f
);
2837 PlotIconRefInContext(context
, &iconCGRect
, kAlignNone
,
2838 active
? kTransformNone
: kTransformDisabled
, NULL
,
2839 kPlotIconRefNormalFlags
, icon
);
2841 CGContextRestoreGState(context
);
2845 HIThemeTextHorizontalFlush hFlush
= kHIThemeTextHorizontalFlushLeft
;
2846 HIThemeTextInfo info
;
2848 #if wxOSX_USE_CORE_TEXT
2849 if ( UMAGetSystemVersion() >= 0x1050 )
2851 info
.version
= kHIThemeTextInfoVersionOne
;
2852 info
.fontID
= kThemeViewsFont
;
2855 info
.fontID
= kThemeSpecifiedFont
;
2856 info
.font
= (CTFontRef
) font
.MacGetCTFont();
2861 #if wxOSX_USE_ATSU_TEXT
2864 info
.version
= kHIThemeTextInfoVersionZero
;
2865 info
.fontID
= kThemeViewsFont
;
2869 info
.fontID
= font
.MacGetThemeFontID();
2871 ::TextSize( (short)(font
.MacGetFontSize()) ) ;
2872 ::TextFace( font
.MacGetFontStyle() ) ;
2878 list
->GetColumn(listColumn
, item
);
2879 if (item
.GetMask() & wxLIST_MASK_FORMAT
)
2881 if (item
.GetAlign() == wxLIST_FORMAT_LEFT
)
2882 hFlush
= kHIThemeTextHorizontalFlushLeft
;
2883 else if (item
.GetAlign() == wxLIST_FORMAT_CENTER
)
2884 hFlush
= kHIThemeTextHorizontalFlushCenter
;
2885 else if (item
.GetAlign() == wxLIST_FORMAT_RIGHT
)
2887 hFlush
= kHIThemeTextHorizontalFlushRight
;
2888 textCGRect
.origin
.x
-= kItemPadding
; // give a little extra paddding
2892 info
.state
= active
? kThemeStateActive
: kThemeStateInactive
;
2893 info
.horizontalFlushness
= hFlush
;
2894 info
.verticalFlushness
= kHIThemeTextVerticalFlushCenter
;
2895 info
.options
= kHIThemeTextBoxOptionNone
;
2896 info
.truncationPosition
= kHIThemeTextTruncationEnd
;
2897 info
.truncationMaxLines
= 1;
2899 CGContextSaveGState(context
);
2900 CGContextSetRGBFillColor (context
, (CGFloat
)labelColor
.red
/ (CGFloat
)USHRT_MAX
,
2901 (CGFloat
)labelColor
.green
/ (CGFloat
)USHRT_MAX
,
2902 (CGFloat
)labelColor
.blue
/ (CGFloat
)USHRT_MAX
, (CGFloat
) 1.0);
2904 HIThemeDrawTextBox(cfString
, &textCGRect
, &info
, context
, kHIThemeOrientationNormal
);
2906 CGContextRestoreGState(context
);
2909 if (savedState
!= NULL
)
2910 SetThemeDrawingState(savedState
, true);
2914 OSStatus
wxMacDataBrowserListCtrlControl::GetSetItemData(DataBrowserItemID itemID
,
2915 DataBrowserPropertyID property
,
2916 DataBrowserItemDataRef itemData
,
2917 Boolean changeValue
)
2922 DataBrowserTableViewColumnIndex listColumn
= 0;
2923 verify_noerr( GetColumnPosition( property
, &listColumn
) );
2925 OSStatus err
= errDataBrowserPropertyNotSupported
;
2926 wxListCtrl
* list
= wxDynamicCast( GetWXPeer() , wxListCtrl
);
2927 wxMacListCtrlItem
* lcItem
= NULL
;
2929 if (listColumn
>= 0)
2933 lcItem
= (wxMacListCtrlItem
*) itemID
;
2934 if (lcItem
&& lcItem
->HasColumnInfo(listColumn
)){
2935 wxListItem
* item
= lcItem
->GetColumnInfo(listColumn
);
2936 if (item
->GetMask() & wxLIST_MASK_TEXT
)
2937 text
= item
->GetText();
2938 if (item
->GetMask() & wxLIST_MASK_IMAGE
)
2939 imgIndex
= item
->GetImage();
2944 long itemNum
= (long)itemID
-1;
2945 if (itemNum
>= 0 && itemNum
< list
->GetItemCount())
2947 text
= list
->OnGetItemText( itemNum
, listColumn
);
2948 imgIndex
= list
->OnGetItemColumnImage( itemNum
, listColumn
);
2957 case kDataBrowserItemIsEditableProperty
:
2958 if ( list
&& list
->HasFlag( wxLC_EDIT_LABELS
) )
2960 verify_noerr(SetDataBrowserItemDataBooleanValue( itemData
, true ));
2965 if ( property
>= kMinColumnId
)
2967 if (!text
.IsEmpty()){
2968 wxCFStringRef
cfStr( text
, wxLocale::GetSystemEncoding() );
2969 err
= ::SetDataBrowserItemDataText( itemData
, cfStr
);
2975 if ( imgIndex
!= -1 )
2977 wxImageList
* imageList
= list
->GetImageList(wxIMAGE_LIST_SMALL
);
2978 if (imageList
&& imageList
->GetImageCount() > 0){
2979 wxBitmap bmp
= imageList
->GetBitmap(imgIndex
);
2980 IconRef icon
= bmp
.GetIconRef();
2981 ::SetDataBrowserItemDataIcon(itemData
, icon
);
2995 if ( property
>= kMinColumnId
)
2997 DataBrowserTableViewColumnIndex listColumn
= 0;
2998 verify_noerr( GetColumnPosition( property
, &listColumn
) );
3000 // TODO probably send the 'end edit' from here, as we
3001 // can then deal with the veto
3003 verify_noerr( GetDataBrowserItemDataText( itemData
, &sr
) ) ;
3004 wxCFStringRef
cfStr(sr
) ;;
3006 list
->SetItem( (long)itemData
-1 , listColumn
, cfStr
.AsString() ) ;
3010 lcItem
->SetColumnTextValue( listColumn
, cfStr
.AsString() );
3020 void wxMacDataBrowserListCtrlControl::ItemNotification(DataBrowserItemID itemID
,
3021 DataBrowserItemNotification message
,
3022 DataBrowserItemDataRef itemData
)
3024 wxMacListCtrlItem
*item
= NULL
;
3027 item
= (wxMacListCtrlItem
*) itemID
;
3030 // we want to depend on as little as possible to make sure tear-down of controls is safe
3031 if ( message
== kDataBrowserItemRemoved
)
3034 item
->Notification(this, message
, itemData
);
3037 else if ( message
== kDataBrowserItemAdded
)
3039 // we don't issue events on adding, the item is not really stored in the list yet, so we
3040 // avoid asserts by getting out now
3042 item
->Notification(this, message
, itemData
);
3046 wxListCtrl
*list
= wxDynamicCast( GetWXPeer() , wxListCtrl
);
3049 bool trigger
= false;
3051 wxListEvent
event( wxEVT_COMMAND_LIST_ITEM_SELECTED
, list
->GetId() );
3053 event
.SetEventObject( list
);
3054 if ( !list
->IsVirtual() )
3056 DataBrowserTableViewRowIndex result
= 0;
3057 verify_noerr( GetItemRow( itemID
, &result
) ) ;
3058 event
.m_itemIndex
= result
;
3062 event
.m_itemIndex
= (long)itemID
-1;
3064 event
.m_item
.m_itemId
= event
.m_itemIndex
;
3065 list
->GetItem(event
.m_item
);
3069 case kDataBrowserItemDeselected
:
3070 event
.SetEventType(wxEVT_COMMAND_LIST_ITEM_DESELECTED
);
3071 // as the generic implementation is also triggering this
3072 // event for single selection, we do the same (different than listbox)
3073 trigger
= !IsSelectionSuppressed();
3076 case kDataBrowserItemSelected
:
3077 trigger
= !IsSelectionSuppressed();
3081 case kDataBrowserItemDoubleClicked
:
3082 event
.SetEventType( wxEVT_COMMAND_LIST_ITEM_ACTIVATED
);
3086 case kDataBrowserEditStarted
:
3087 // TODO : how to veto ?
3088 event
.SetEventType( wxEVT_COMMAND_LIST_BEGIN_LABEL_EDIT
) ;
3092 case kDataBrowserEditStopped
:
3093 // TODO probably trigger only upon the value store callback, because
3094 // here IIRC we cannot veto
3095 event
.SetEventType( wxEVT_COMMAND_LIST_END_LABEL_EDIT
) ;
3105 // direct notification is not always having the listbox GetSelection() having in synch with event
3106 wxPostEvent( list
->GetEventHandler(), event
);
3111 Boolean
wxMacDataBrowserListCtrlControl::CompareItems(DataBrowserItemID itemOneID
,
3112 DataBrowserItemID itemTwoID
,
3113 DataBrowserPropertyID sortProperty
)
3116 bool retval
= false;
3118 wxString otherItemText
;
3120 long otherItemOrder
;
3122 DataBrowserTableViewColumnIndex colId
= 0;
3123 verify_noerr( GetColumnPosition( sortProperty
, &colId
) );
3125 wxListCtrl
* list
= wxDynamicCast( GetWXPeer() , wxListCtrl
);
3127 DataBrowserSortOrder sort
;
3128 verify_noerr(GetSortOrder(&sort
));
3134 wxMacListCtrlItem
* item
= (wxMacListCtrlItem
*)itemOneID
;
3135 wxMacListCtrlItem
* otherItem
= (wxMacListCtrlItem
*)itemTwoID
;
3137 itemOrder
= item
->GetOrder();
3138 otherItemOrder
= otherItem
->GetOrder();
3140 wxListCtrlCompare func
= list
->GetCompareFunc();
3146 if (item
&& item
->HasColumnInfo(0))
3147 item1
= item
->GetColumnInfo(0)->GetData();
3148 if (otherItem
&& otherItem
->HasColumnInfo(0))
3149 item2
= otherItem
->GetColumnInfo(0)->GetData();
3151 if (item1
> -1 && item2
> -1)
3153 int result
= func(item1
, item2
, list
->GetCompareFuncData());
3154 if (sort
== kDataBrowserOrderIncreasing
)
3161 // we can't use the native control's sorting abilities, so just
3163 return itemOrder
< otherItemOrder
;
3168 long itemNum
= (long)itemOneID
;
3169 long otherItemNum
= (long)itemTwoID
;
3171 // virtual listctrls don't support sorting
3172 return itemNum
< otherItemNum
;
3176 // fallback for undefined cases
3177 retval
= itemOneID
< itemTwoID
;
3183 wxMacDataBrowserListCtrlControl::~wxMacDataBrowserListCtrlControl()
3187 void wxMacDataBrowserListCtrlControl::MacSetColumnInfo( unsigned int row
, unsigned int column
, wxListItem
* item
)
3189 wxMacDataItem
* dataItem
= GetItemFromLine(row
);
3190 wxASSERT_MSG( dataItem
, _T("could not obtain wxMacDataItem for row in MacSetColumnInfo. Is row a valid wxListCtrl row?") );
3193 wxMacListCtrlItem
* listItem
= static_cast<wxMacListCtrlItem
*>(dataItem
);
3194 bool hasInfo
= listItem
->HasColumnInfo( column
);
3195 listItem
->SetColumnInfo( column
, item
);
3196 listItem
->SetOrder(row
);
3197 UpdateState(dataItem
, item
);
3199 wxListCtrl
* list
= wxDynamicCast( GetWXPeer() , wxListCtrl
);
3201 // NB: When this call was made before a control was completely shown, it would
3202 // update the item prematurely (i.e. no text would be listed) and, on show,
3203 // only the sorted column would be refreshed, meaning only first column text labels
3204 // would be shown. Making sure not to update items until the control is visible
3205 // seems to fix this issue.
3206 if (hasInfo
&& list
->IsShown())
3208 DataBrowserTableViewColumnID id
= 0;
3209 verify_noerr( GetColumnIDFromIndex( column
, &id
) );
3210 UpdateItem( wxMacDataBrowserRootContainer
, listItem
, id
);
3215 // apply changes that need to happen immediately, rather than when the
3216 // databrowser control fires a callback.
3217 void wxMacDataBrowserListCtrlControl::UpdateState(wxMacDataItem
* dataItem
, wxListItem
* listItem
)
3219 bool isSelected
= IsItemSelected( dataItem
);
3220 bool isSelectedState
= (listItem
->GetState() == wxLIST_STATE_SELECTED
);
3222 // toggle the selection state if wxListInfo state and actual state don't match.
3223 if ( listItem
->GetMask() & wxLIST_MASK_STATE
&& isSelected
!= isSelectedState
)
3225 DataBrowserSetOption options
= kDataBrowserItemsAdd
;
3226 if (!isSelectedState
)
3227 options
= kDataBrowserItemsRemove
;
3228 SetSelectedItem(dataItem
, options
);
3230 // TODO: Set column width if item width > than current column width
3233 void wxMacDataBrowserListCtrlControl::MacGetColumnInfo( unsigned int row
, unsigned int column
, wxListItem
& item
)
3235 wxMacDataItem
* dataItem
= GetItemFromLine(row
);
3236 wxASSERT_MSG( dataItem
, _T("could not obtain wxMacDataItem in MacGetColumnInfo. Is row a valid wxListCtrl row?") );
3237 // CS should this guard against dataItem = 0 ? , as item is not a pointer if (item) is not appropriate
3240 wxMacListCtrlItem
* listItem
= static_cast<wxMacListCtrlItem
*>(dataItem
);
3242 if (!listItem
->HasColumnInfo( column
))
3245 wxListItem
* oldItem
= listItem
->GetColumnInfo( column
);
3249 long mask
= item
.GetMask();
3251 // by default, get everything for backwards compatibility
3254 if ( mask
& wxLIST_MASK_TEXT
)
3255 item
.SetText(oldItem
->GetText());
3256 if ( mask
& wxLIST_MASK_IMAGE
)
3257 item
.SetImage(oldItem
->GetImage());
3258 if ( mask
& wxLIST_MASK_DATA
)
3259 item
.SetData(oldItem
->GetData());
3260 if ( mask
& wxLIST_MASK_STATE
)
3261 item
.SetState(oldItem
->GetState());
3262 if ( mask
& wxLIST_MASK_WIDTH
)
3263 item
.SetWidth(oldItem
->GetWidth());
3264 if ( mask
& wxLIST_MASK_FORMAT
)
3265 item
.SetAlign(oldItem
->GetAlign());
3267 item
.SetTextColour(oldItem
->GetTextColour());
3268 item
.SetBackgroundColour(oldItem
->GetBackgroundColour());
3269 item
.SetFont(oldItem
->GetFont());
3274 void wxMacDataBrowserListCtrlControl::MacInsertItem( unsigned int n
, wxListItem
* item
)
3277 wxMacDataItemBrowserControl::MacInsert(n
, new wxMacListCtrlItem() );
3278 MacSetColumnInfo(n
, 0, item
);
3281 wxMacListCtrlItem::wxMacListCtrlItem()
3283 m_rowItems
= wxListItemList();
3286 int wxMacListCtrlItem::GetColumnImageValue( unsigned int column
)
3288 if ( HasColumnInfo(column
) )
3289 return GetColumnInfo(column
)->GetImage();
3294 void wxMacListCtrlItem::SetColumnImageValue( unsigned int column
, int imageIndex
)
3296 if ( HasColumnInfo(column
) )
3297 GetColumnInfo(column
)->SetImage(imageIndex
);
3300 wxString
wxMacListCtrlItem::GetColumnTextValue( unsigned int column
)
3302 /* TODO CHECK REMOVE
3306 if ( HasColumnInfo(column
) )
3307 return GetColumnInfo(column
)->GetText();
3309 return wxEmptyString
;
3312 void wxMacListCtrlItem::SetColumnTextValue( unsigned int column
, const wxString
& text
)
3314 if ( HasColumnInfo(column
) )
3315 GetColumnInfo(column
)->SetText(text
);
3317 /* TODO CHECK REMOVE
3318 // for compatibility with superclass APIs
3324 wxListItem
* wxMacListCtrlItem::GetColumnInfo( unsigned int column
)
3326 wxASSERT_MSG( HasColumnInfo(column
), _T("invalid column index in wxMacListCtrlItem") );
3327 return m_rowItems
[column
];
3330 bool wxMacListCtrlItem::HasColumnInfo( unsigned int column
)
3332 return !(m_rowItems
.find( column
) == m_rowItems
.end());
3335 void wxMacListCtrlItem::SetColumnInfo( unsigned int column
, wxListItem
* item
)
3338 if ( !HasColumnInfo(column
) )
3340 wxListItem
* listItem
= new wxListItem(*item
);
3341 m_rowItems
[column
] = listItem
;
3345 wxListItem
* listItem
= GetColumnInfo( column
);
3346 long mask
= item
->GetMask();
3347 if (mask
& wxLIST_MASK_TEXT
)
3348 listItem
->SetText(item
->GetText());
3349 if (mask
& wxLIST_MASK_DATA
)
3350 listItem
->SetData(item
->GetData());
3351 if (mask
& wxLIST_MASK_IMAGE
)
3352 listItem
->SetImage(item
->GetImage());
3353 if (mask
& wxLIST_MASK_STATE
)
3354 listItem
->SetState(item
->GetState());
3355 if (mask
& wxLIST_MASK_FORMAT
)
3356 listItem
->SetAlign(item
->GetAlign());
3357 if (mask
& wxLIST_MASK_WIDTH
)
3358 listItem
->SetWidth(item
->GetWidth());
3360 if ( item
->HasAttributes() )
3362 if ( listItem
->HasAttributes() )
3363 listItem
->GetAttributes()->AssignFrom(*item
->GetAttributes());
3366 listItem
->SetTextColour(item
->GetTextColour());
3367 listItem
->SetBackgroundColour(item
->GetBackgroundColour());
3368 listItem
->SetFont(item
->GetFont());
3374 int wxListCtrl::CalcColumnAutoWidth(int col
) const
3378 for ( int i
= 0; i
< GetItemCount(); i
++ )
3381 info
.SetMask(wxLIST_MASK_TEXT
| wxLIST_MASK_IMAGE
);
3383 info
.SetColumn(col
);
3386 const wxFont font
= info
.GetFont();
3390 GetTextExtent(info
.GetText(), &w
, NULL
, NULL
, NULL
, &font
);
3392 GetTextExtent(info
.GetText(), &w
, NULL
);
3394 w
+= 2 * kItemPadding
;
3396 if ( info
.GetImage() != -1 )
3399 width
= wxMax(width
, w
);
3405 #endif // wxUSE_LISTCTRL