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
.CreateSystemFont(wxOSX_SYSTEM_FONT_VIEWS
);
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 // MacGetColumnInfo returns erroneous information in the state field, so zero it.
1133 if (info
.GetMask() & wxLIST_MASK_STATE
)
1135 DataBrowserItemID id
= (DataBrowserItemID
)m_dbImpl
->GetItemFromLine(info
.m_itemId
);
1136 if (IsDataBrowserItemSelected( m_dbImpl
->GetControlRef(), id
))
1137 info
.SetState(info
.GetState() | wxLIST_STATE_SELECTED
);
1143 if (info
.m_itemId
>= 0 && info
.m_itemId
< GetItemCount())
1145 info
.SetText( OnGetItemText(info
.m_itemId
, info
.m_col
) );
1146 info
.SetImage( OnGetItemColumnImage(info
.m_itemId
, info
.m_col
) );
1147 if (info
.GetMask() & wxLIST_MASK_STATE
)
1149 if (IsDataBrowserItemSelected( m_dbImpl
->GetControlRef(), info
.m_itemId
+1 ))
1150 info
.SetState(info
.GetState() | wxLIST_STATE_SELECTED
);
1153 wxListItemAttr
* attrs
= OnGetItemAttr( info
.m_itemId
);
1156 info
.SetFont( attrs
->GetFont() );
1157 info
.SetBackgroundColour( attrs
->GetBackgroundColour() );
1158 info
.SetTextColour( attrs
->GetTextColour() );
1163 bool success
= true;
1167 // Sets information about the item
1168 bool wxListCtrl::SetItem(wxListItem
& info
)
1171 return m_genericImpl
->SetItem(info
);
1174 m_dbImpl
->MacSetColumnInfo( info
.m_itemId
, info
.m_col
, &info
);
1179 long wxListCtrl::SetItem(long index
, int col
, const wxString
& label
, int imageId
)
1182 return m_genericImpl
->SetItem(index
, col
, label
, imageId
);
1185 info
.m_text
= label
;
1186 info
.m_mask
= wxLIST_MASK_TEXT
;
1187 info
.m_itemId
= index
;
1191 info
.m_image
= imageId
;
1192 info
.m_mask
|= wxLIST_MASK_IMAGE
;
1194 return SetItem(info
);
1198 // Gets the item state
1199 int wxListCtrl::GetItemState(long item
, long stateMask
) const
1202 return m_genericImpl
->GetItemState(item
, stateMask
);
1206 if ( HasFlag(wxLC_VIRTUAL
) )
1208 if (stateMask
== wxLIST_STATE_SELECTED
)
1210 if (IsDataBrowserItemSelected( m_dbImpl
->GetControlRef(), item
+1 ))
1211 return wxLIST_STATE_SELECTED
;
1220 info
.m_mask
= wxLIST_MASK_STATE
;
1221 info
.m_stateMask
= stateMask
;
1222 info
.m_itemId
= item
;
1227 return info
.m_state
;
1234 // Sets the item state
1235 bool wxListCtrl::SetItemState(long item
, long state
, long stateMask
)
1238 return m_genericImpl
->SetItemState(item
, state
, stateMask
);
1242 DataBrowserSetOption option
= kDataBrowserItemsAdd
;
1243 if ( (stateMask
& wxLIST_STATE_SELECTED
) && state
== 0 )
1244 option
= kDataBrowserItemsRemove
;
1248 if ( HasFlag(wxLC_VIRTUAL
) )
1250 wxMacDataItemBrowserSelectionSuppressor
suppressor(m_dbImpl
);
1251 m_dbImpl
->SetSelectedAllItems(option
);
1255 for(int i
= 0; i
< GetItemCount();i
++)
1259 info
.m_mask
= wxLIST_MASK_STATE
;
1260 info
.m_stateMask
= stateMask
;
1261 info
.m_state
= state
;
1268 if ( HasFlag(wxLC_VIRTUAL
) )
1270 long itemID
= item
+1;
1271 bool isSelected
= IsDataBrowserItemSelected(m_dbImpl
->GetControlRef(), (DataBrowserItemID
)itemID
);
1272 bool isSelectedState
= (state
== wxLIST_STATE_SELECTED
);
1274 // toggle the selection state if wxListInfo state and actual state don't match.
1275 if ( (stateMask
& wxLIST_STATE_SELECTED
) && isSelected
!= isSelectedState
)
1277 SetDataBrowserSelectedItems(m_dbImpl
->GetControlRef(), 1, (DataBrowserItemID
*)&itemID
, option
);
1283 info
.m_itemId
= item
;
1284 info
.m_mask
= wxLIST_MASK_STATE
;
1285 info
.m_stateMask
= stateMask
;
1286 info
.m_state
= state
;
1287 return SetItem(info
);
1294 // Sets the item image
1295 bool wxListCtrl::SetItemImage(long item
, int image
, int WXUNUSED(selImage
))
1297 return SetItemColumnImage(item
, 0, image
);
1300 // Sets the item image
1301 bool wxListCtrl::SetItemColumnImage(long item
, long column
, int image
)
1304 return m_genericImpl
->SetItemColumnImage(item
, column
, image
);
1308 info
.m_mask
= wxLIST_MASK_IMAGE
;
1309 info
.m_image
= image
;
1310 info
.m_itemId
= item
;
1311 info
.m_col
= column
;
1313 return SetItem(info
);
1316 // Gets the item text
1317 wxString
wxListCtrl::GetItemText(long item
) const
1320 return m_genericImpl
->GetItemText(item
);
1324 info
.m_mask
= wxLIST_MASK_TEXT
;
1325 info
.m_itemId
= item
;
1328 return wxEmptyString
;
1332 // Sets the item text
1333 void wxListCtrl::SetItemText(long item
, const wxString
& str
)
1336 return m_genericImpl
->SetItemText(item
, str
);
1340 info
.m_mask
= wxLIST_MASK_TEXT
;
1341 info
.m_itemId
= item
;
1347 // Gets the item data
1348 long wxListCtrl::GetItemData(long item
) const
1351 return m_genericImpl
->GetItemData(item
);
1355 info
.m_mask
= wxLIST_MASK_DATA
;
1356 info
.m_itemId
= item
;
1363 // Sets the item data
1364 bool wxListCtrl::SetItemPtrData(long item
, wxUIntPtr data
)
1367 return m_genericImpl
->SetItemData(item
, data
);
1371 info
.m_mask
= wxLIST_MASK_DATA
;
1372 info
.m_itemId
= item
;
1375 return SetItem(info
);
1378 wxRect
wxListCtrl::GetViewRect() const
1380 wxASSERT_MSG( !HasFlag(wxLC_REPORT
| wxLC_LIST
),
1381 _T("wxListCtrl::GetViewRect() only works in icon mode") );
1384 return m_genericImpl
->GetViewRect();
1390 bool wxListCtrl::GetSubItemRect( long item
, long subItem
, wxRect
& rect
, int code
) const
1393 return m_genericImpl
->GetSubItemRect(item
, subItem
, rect
, code
);
1395 // TODO: implement for DataBrowser implementation
1399 // Gets the item rectangle
1400 bool wxListCtrl::GetItemRect(long item
, wxRect
& rect
, int code
) const
1403 return m_genericImpl
->GetItemRect(item
, rect
, code
);
1408 DataBrowserItemID id
;
1410 DataBrowserTableViewColumnID col
= 0;
1411 verify_noerr( m_dbImpl
->GetColumnIDFromIndex( 0, &col
) );
1414 DataBrowserPropertyPart part
= kDataBrowserPropertyEnclosingPart
;
1415 if ( code
== wxLIST_RECT_LABEL
)
1416 part
= kDataBrowserPropertyTextPart
;
1417 else if ( code
== wxLIST_RECT_ICON
)
1418 part
= kDataBrowserPropertyIconPart
;
1420 if ( !(GetWindowStyleFlag() & wxLC_VIRTUAL
) )
1422 wxMacDataItem
* thisItem
= m_dbImpl
->GetItemFromLine(item
);
1423 id
= (DataBrowserItemID
) thisItem
;
1428 GetDataBrowserItemPartBounds( m_dbImpl
->GetControlRef(), id
, col
, part
, &bounds
);
1430 rect
.x
= bounds
.left
;
1431 rect
.y
= bounds
.top
;
1432 rect
.width
= bounds
.right
- bounds
.left
; //GetClientSize().x; // we need the width of the whole row, not just the item.
1433 rect
.height
= bounds
.bottom
- bounds
.top
;
1434 //fprintf("id = %d, bounds = %d, %d, %d, %d\n", id, rect.x, rect.y, rect.width, rect.height);
1439 // Gets the item position
1440 bool wxListCtrl::GetItemPosition(long item
, wxPoint
& pos
) const
1443 return m_genericImpl
->GetItemPosition(item
, pos
);
1445 bool success
= false;
1450 GetItemRect(item
, itemRect
);
1451 pos
= itemRect
.GetPosition();
1458 // Sets the item position.
1459 bool wxListCtrl::SetItemPosition(long item
, const wxPoint
& pos
)
1462 return m_genericImpl
->SetItemPosition(item
, pos
);
1467 // Gets the number of items in the list control
1468 int wxListCtrl::GetItemCount() const
1471 return m_genericImpl
->GetItemCount();
1474 return m_dbImpl
->MacGetCount();
1479 void wxListCtrl::SetItemSpacing( int spacing
, bool isSmall
)
1482 m_genericImpl
->SetItemSpacing(spacing
, isSmall
);
1485 wxSize
wxListCtrl::GetItemSpacing() const
1488 return m_genericImpl
->GetItemSpacing();
1490 return wxSize(0, 0);
1493 void wxListCtrl::SetItemTextColour( long item
, const wxColour
&col
)
1497 m_genericImpl
->SetItemTextColour(item
, col
);
1502 info
.m_itemId
= item
;
1503 info
.SetTextColour( col
);
1507 wxColour
wxListCtrl::GetItemTextColour( long item
) const
1510 return m_genericImpl
->GetItemTextColour(item
);
1516 return info
.GetTextColour();
1518 return wxNullColour
;
1521 void wxListCtrl::SetItemBackgroundColour( long item
, const wxColour
&col
)
1525 m_genericImpl
->SetItemBackgroundColour(item
, col
);
1530 info
.m_itemId
= item
;
1531 info
.SetBackgroundColour( col
);
1535 wxColour
wxListCtrl::GetItemBackgroundColour( long item
) const
1538 return m_genericImpl
->GetItemBackgroundColour(item
);
1544 return info
.GetBackgroundColour();
1546 return wxNullColour
;
1549 void wxListCtrl::SetItemFont( long item
, const wxFont
&f
)
1553 m_genericImpl
->SetItemFont(item
, f
);
1558 info
.m_itemId
= item
;
1563 wxFont
wxListCtrl::GetItemFont( long item
) const
1566 return m_genericImpl
->GetItemFont(item
);
1572 return info
.GetFont();
1578 // Gets the number of selected items in the list control
1579 int wxListCtrl::GetSelectedItemCount() const
1582 return m_genericImpl
->GetSelectedItemCount();
1585 return m_dbImpl
->GetSelectedItemCount(NULL
, true);
1590 // Gets the text colour of the listview
1591 wxColour
wxListCtrl::GetTextColour() const
1594 return m_genericImpl
->GetTextColour();
1596 // TODO: we need owner drawn list items to customize text color.
1600 return wxNullColour
;
1603 // Sets the text colour of the listview
1604 void wxListCtrl::SetTextColour(const wxColour
& col
)
1608 m_genericImpl
->SetTextColour(col
);
1616 // Gets the index of the topmost visible item when in
1617 // list or report view
1618 long wxListCtrl::GetTopItem() const
1621 return m_genericImpl
->GetTopItem();
1626 long item
= HitTest( wxPoint(1, 1), flags
);
1627 if (flags
== wxLIST_HITTEST_ONITEM
)
1634 // Searches for an item, starting from 'item'.
1635 // 'geometry' is one of
1636 // wxLIST_NEXT_ABOVE/ALL/BELOW/LEFT/RIGHT.
1637 // 'state' is a state bit flag, one or more of
1638 // wxLIST_STATE_DROPHILITED/FOCUSED/SELECTED/CUT.
1639 // item can be -1 to find the first item that matches the
1641 // Returns the item or -1 if unsuccessful.
1642 long wxListCtrl::GetNextItem(long item
, int geom
, int state
) const
1645 return m_genericImpl
->GetNextItem(item
, geom
, state
);
1647 // TODO: implement all geometry and state options?
1650 if ( geom
== wxLIST_NEXT_ALL
|| geom
== wxLIST_NEXT_BELOW
)
1652 long count
= m_dbImpl
->MacGetCount() ;
1653 for ( long line
= item
+ 1 ; line
< count
; line
++ )
1655 DataBrowserItemID id
= line
+ 1;
1657 id
= (DataBrowserItemID
)m_dbImpl
->GetItemFromLine(line
);
1659 if ( (state
== wxLIST_STATE_DONTCARE
) )
1662 if ( (state
& wxLIST_STATE_SELECTED
) && IsDataBrowserItemSelected(m_dbImpl
->GetControlRef(), id
) )
1667 if ( geom
== wxLIST_NEXT_ABOVE
)
1671 item2
= m_dbImpl
->MacGetCount();
1673 for ( long line
= item2
- 1 ; line
>= 0; line
-- )
1675 DataBrowserItemID id
= line
+ 1;
1677 id
= (DataBrowserItemID
)m_dbImpl
->GetItemFromLine(line
);
1679 if ( (state
== wxLIST_STATE_DONTCARE
) )
1682 if ( (state
& wxLIST_STATE_SELECTED
) && IsDataBrowserItemSelected(m_dbImpl
->GetControlRef(), id
) )
1692 wxImageList
*wxListCtrl::GetImageList(int which
) const
1695 return m_genericImpl
->GetImageList(which
);
1697 if ( which
== wxIMAGE_LIST_NORMAL
)
1699 return m_imageListNormal
;
1701 else if ( which
== wxIMAGE_LIST_SMALL
)
1703 return m_imageListSmall
;
1705 else if ( which
== wxIMAGE_LIST_STATE
)
1707 return m_imageListState
;
1712 void wxListCtrl::SetImageList(wxImageList
*imageList
, int which
)
1716 m_genericImpl
->SetImageList(imageList
, which
);
1720 if ( which
== wxIMAGE_LIST_NORMAL
)
1722 if (m_ownsImageListNormal
) delete m_imageListNormal
;
1723 m_imageListNormal
= imageList
;
1724 m_ownsImageListNormal
= false;
1726 else if ( which
== wxIMAGE_LIST_SMALL
)
1728 if (m_ownsImageListSmall
) delete m_imageListSmall
;
1729 m_imageListSmall
= imageList
;
1730 m_ownsImageListSmall
= false;
1732 else if ( which
== wxIMAGE_LIST_STATE
)
1734 if (m_ownsImageListState
) delete m_imageListState
;
1735 m_imageListState
= imageList
;
1736 m_ownsImageListState
= false;
1740 void wxListCtrl::AssignImageList(wxImageList
*imageList
, int which
)
1744 m_genericImpl
->AssignImageList(imageList
, which
);
1748 SetImageList(imageList
, which
);
1749 if ( which
== wxIMAGE_LIST_NORMAL
)
1750 m_ownsImageListNormal
= true;
1751 else if ( which
== wxIMAGE_LIST_SMALL
)
1752 m_ownsImageListSmall
= true;
1753 else if ( which
== wxIMAGE_LIST_STATE
)
1754 m_ownsImageListState
= true;
1757 // ----------------------------------------------------------------------------
1759 // ----------------------------------------------------------------------------
1761 // Arranges the items
1762 bool wxListCtrl::Arrange(int flag
)
1765 return m_genericImpl
->Arrange(flag
);
1770 bool wxListCtrl::DeleteItem(long item
)
1773 return m_genericImpl
->DeleteItem(item
);
1777 m_dbImpl
->MacDelete(item
);
1778 wxListEvent
event( wxEVT_COMMAND_LIST_DELETE_ITEM
, GetId() );
1779 event
.SetEventObject( this );
1780 event
.m_itemIndex
= item
;
1781 HandleWindowEvent( event
);
1787 // Deletes all items
1788 bool wxListCtrl::DeleteAllItems()
1791 return m_genericImpl
->DeleteAllItems();
1795 m_dbImpl
->MacClear();
1796 wxListEvent
event( wxEVT_COMMAND_LIST_DELETE_ALL_ITEMS
, GetId() );
1797 event
.SetEventObject( this );
1798 HandleWindowEvent( event
);
1803 // Deletes all items
1804 bool wxListCtrl::DeleteAllColumns()
1807 return m_genericImpl
->DeleteAllColumns();
1812 m_dbImpl
->GetColumnCount(&cols
);
1813 for (UInt32 col
= 0; col
< cols
; col
++)
1823 bool wxListCtrl::DeleteColumn(int col
)
1826 return m_genericImpl
->DeleteColumn(col
);
1830 OSStatus err
= m_dbImpl
->RemoveColumn(col
);
1831 return err
== noErr
;
1837 // Clears items, and columns if there are any.
1838 void wxListCtrl::ClearAll()
1842 m_genericImpl
->ClearAll();
1853 wxTextCtrl
* wxListCtrl::EditLabel(long item
, wxClassInfo
* textControlClass
)
1856 return m_genericImpl
->EditLabel(item
, textControlClass
);
1860 wxCHECK_MSG( (item
>= 0) && ((long)item
< GetItemCount()), NULL
,
1861 wxT("wrong index in wxListCtrl::EditLabel()") );
1863 wxASSERT_MSG( textControlClass
->IsKindOf(CLASSINFO(wxTextCtrl
)),
1864 wxT("EditLabel() needs a text control") );
1866 wxListEvent
le( wxEVT_COMMAND_LIST_BEGIN_LABEL_EDIT
, GetParent()->GetId() );
1867 le
.SetEventObject( this );
1868 le
.m_itemIndex
= item
;
1870 GetItem( le
.m_item
);
1872 if ( GetParent()->HandleWindowEvent( le
) && !le
.IsAllowed() )
1874 // vetoed by user code
1878 wxTextCtrl
* const text
= (wxTextCtrl
*)textControlClass
->CreateObject();
1879 m_textctrlWrapper
= new wxListCtrlTextCtrlWrapper(this, text
, item
);
1880 return m_textctrlWrapper
->GetText();
1885 // End label editing, optionally cancelling the edit
1886 bool wxListCtrl::EndEditLabel(bool WXUNUSED(cancel
))
1888 // TODO: generic impl. doesn't have this method - is it needed for us?
1890 return true; // m_genericImpl->EndEditLabel(cancel);
1894 DataBrowserTableViewColumnID id
= 0;
1895 verify_noerr( m_dbImpl
->GetColumnIDFromIndex( 0, &id
) );
1896 verify_noerr( SetDataBrowserEditItem(m_dbImpl
->GetControlRef(), kDataBrowserNoItem
, id
) );
1901 // Ensures this item is visible
1902 bool wxListCtrl::EnsureVisible(long item
)
1905 return m_genericImpl
->EnsureVisible(item
);
1909 wxMacDataItem
* dataItem
= m_dbImpl
->GetItemFromLine(item
);
1910 m_dbImpl
->RevealItem(dataItem
, kDataBrowserRevealWithoutSelecting
);
1916 // Find an item whose label matches this string, starting from the item after 'start'
1917 // or the beginning if 'start' is -1.
1918 long wxListCtrl::FindItem(long start
, const wxString
& str
, bool partial
)
1921 return m_genericImpl
->FindItem(start
, str
, partial
);
1923 wxString str_upper
= str
.Upper();
1928 long count
= GetItemCount();
1932 wxString line_upper
= GetItemText(idx
).Upper();
1935 if (line_upper
== str_upper
)
1940 if (line_upper
.find(str_upper
) == 0)
1950 // Find an item whose data matches this data, starting from the item after 'start'
1951 // or the beginning if 'start' is -1.
1952 long wxListCtrl::FindItem(long start
, long data
)
1955 return m_genericImpl
->FindItem(start
, data
);
1960 long count
= GetItemCount();
1964 if (GetItemData(idx
) == data
)
1972 // Find an item nearest this position in the specified direction, starting from
1973 // the item after 'start' or the beginning if 'start' is -1.
1974 long wxListCtrl::FindItem(long start
, const wxPoint
& pt
, int direction
)
1977 return m_genericImpl
->FindItem(start
, pt
, direction
);
1981 // Determines which item (if any) is at the specified point,
1982 // giving details in 'flags' (see wxLIST_HITTEST_... flags above)
1984 wxListCtrl::HitTest(const wxPoint
& point
, int& flags
, long *ptrSubItem
) const
1987 return m_genericImpl
->HitTest(point
, flags
, ptrSubItem
);
1989 flags
= wxLIST_HITTEST_NOWHERE
;
1992 int colHeaderHeight
= 22; // TODO: Find a way to get this value from the db control?
1993 UInt16 rowHeight
= 0;
1994 m_dbImpl
->GetDefaultRowHeight(&rowHeight
);
1997 // get the actual row by taking scroll position into account
1998 UInt32 offsetX
, offsetY
;
1999 m_dbImpl
->GetScrollPosition( &offsetY
, &offsetX
);
2002 if ( !(GetWindowStyleFlag() & wxLC_NO_HEADER
) )
2003 y
-= colHeaderHeight
;
2008 int row
= y
/ rowHeight
;
2009 DataBrowserItemID id
;
2010 m_dbImpl
->GetItemID( (DataBrowserTableViewRowIndex
) row
, &id
);
2012 // TODO: Use GetDataBrowserItemPartBounds to return if we are in icon or label
2013 if ( !(GetWindowStyleFlag() & wxLC_VIRTUAL
) )
2015 wxMacListCtrlItem
* lcItem
;
2016 lcItem
= (wxMacListCtrlItem
*) id
;
2019 flags
= wxLIST_HITTEST_ONITEM
;
2025 if (row
< GetItemCount() )
2027 flags
= wxLIST_HITTEST_ONITEM
;
2036 int wxListCtrl::GetScrollPos(int orient
) const
2039 return m_genericImpl
->GetScrollPos(orient
);
2043 UInt32 offsetX
, offsetY
;
2044 m_dbImpl
->GetScrollPosition( &offsetY
, &offsetX
);
2045 if ( orient
== wxHORIZONTAL
)
2054 // Inserts an item, returning the index of the new item if successful,
2056 long wxListCtrl::InsertItem(wxListItem
& info
)
2058 wxASSERT_MSG( !IsVirtual(), _T("can't be used with virtual controls") );
2061 return m_genericImpl
->InsertItem(info
);
2063 if (m_dbImpl
&& !IsVirtual())
2065 int count
= GetItemCount();
2067 if (info
.m_itemId
> count
)
2068 info
.m_itemId
= count
;
2070 m_dbImpl
->MacInsertItem(info
.m_itemId
, &info
);
2072 wxListEvent
event( wxEVT_COMMAND_LIST_INSERT_ITEM
, GetId() );
2073 event
.SetEventObject( this );
2074 event
.m_itemIndex
= info
.m_itemId
;
2075 HandleWindowEvent( event
);
2076 return info
.m_itemId
;
2081 long wxListCtrl::InsertItem(long index
, const wxString
& label
)
2084 return m_genericImpl
->InsertItem(index
, label
);
2087 info
.m_text
= label
;
2088 info
.m_mask
= wxLIST_MASK_TEXT
;
2089 info
.m_itemId
= index
;
2090 return InsertItem(info
);
2093 // Inserts an image item
2094 long wxListCtrl::InsertItem(long index
, int imageIndex
)
2097 return m_genericImpl
->InsertItem(index
, imageIndex
);
2100 info
.m_image
= imageIndex
;
2101 info
.m_mask
= wxLIST_MASK_IMAGE
;
2102 info
.m_itemId
= index
;
2103 return InsertItem(info
);
2106 // Inserts an image/string item
2107 long wxListCtrl::InsertItem(long index
, const wxString
& label
, int imageIndex
)
2110 return m_genericImpl
->InsertItem(index
, label
, imageIndex
);
2113 info
.m_image
= imageIndex
;
2114 info
.m_text
= label
;
2115 info
.m_mask
= wxLIST_MASK_IMAGE
| wxLIST_MASK_TEXT
;
2116 info
.m_itemId
= index
;
2117 return InsertItem(info
);
2120 // For list view mode (only), inserts a column.
2121 long wxListCtrl::InsertColumn(long col
, wxListItem
& item
)
2124 return m_genericImpl
->InsertColumn(col
, item
);
2128 int width
= item
.GetWidth();
2129 if ( !(item
.GetMask() & wxLIST_MASK_WIDTH
) )
2132 DataBrowserPropertyType type
= kDataBrowserCustomType
; //kDataBrowserTextType;
2133 wxImageList
* imageList
= GetImageList(wxIMAGE_LIST_SMALL
);
2134 if (imageList
&& imageList
->GetImageCount() > 0)
2136 wxBitmap bmp
= imageList
->GetBitmap(0);
2138 // type = kDataBrowserIconAndTextType;
2141 SInt16 just
= teFlushDefault
;
2142 if (item
.GetMask() & wxLIST_MASK_FORMAT
)
2144 if (item
.GetAlign() == wxLIST_FORMAT_LEFT
)
2146 else if (item
.GetAlign() == wxLIST_FORMAT_CENTER
)
2148 else if (item
.GetAlign() == wxLIST_FORMAT_RIGHT
)
2149 just
= teFlushRight
;
2151 m_dbImpl
->InsertColumn(col
, type
, item
.GetText(), just
, width
);
2153 wxListItem
* listItem
= new wxListItem(item
);
2154 m_colsInfo
.Insert( col
, listItem
);
2155 SetColumn(col
, item
);
2157 // set/remove options based on the wxListCtrl type.
2158 DataBrowserTableViewColumnID id
;
2159 m_dbImpl
->GetColumnIDFromIndex(col
, &id
);
2160 DataBrowserPropertyFlags flags
;
2161 verify_noerr(m_dbImpl
->GetPropertyFlags(id
, &flags
));
2162 if (GetWindowStyleFlag() & wxLC_EDIT_LABELS
)
2163 flags
|= kDataBrowserPropertyIsEditable
;
2165 if (GetWindowStyleFlag() & wxLC_VIRTUAL
){
2166 flags
&= ~kDataBrowserListViewSortableColumn
;
2168 verify_noerr(m_dbImpl
->SetPropertyFlags(id
, flags
));
2174 long wxListCtrl::InsertColumn(long col
,
2175 const wxString
& heading
,
2180 return m_genericImpl
->InsertColumn(col
, heading
, format
, width
);
2183 item
.m_mask
= wxLIST_MASK_TEXT
| wxLIST_MASK_FORMAT
;
2184 item
.m_text
= heading
;
2187 item
.m_mask
|= wxLIST_MASK_WIDTH
;
2188 item
.m_width
= width
;
2190 item
.m_format
= format
;
2192 return InsertColumn(col
, item
);
2195 // scroll the control by the given number of pixels (exception: in list view,
2196 // dx is interpreted as number of columns)
2197 bool wxListCtrl::ScrollList(int dx
, int dy
)
2200 return m_genericImpl
->ScrollList(dx
, dy
);
2204 m_dbImpl
->SetScrollPosition(dx
, dy
);
2210 bool wxListCtrl::SortItems(wxListCtrlCompare fn
, wxIntPtr data
)
2213 return m_genericImpl
->SortItems(fn
, data
);
2218 m_compareFuncData
= data
;
2219 SortDataBrowserContainer( m_dbImpl
->GetControlRef(), kDataBrowserNoItem
, true);
2221 // we need to do this after each call, else we get a crash from wxPython when
2222 // SortItems is called the second time.
2223 m_compareFunc
= NULL
;
2224 m_compareFuncData
= 0;
2230 void wxListCtrl::OnRenameTimer()
2232 wxCHECK_RET( HasCurrent(), wxT("unexpected rename timer") );
2234 EditLabel( m_current
);
2237 bool wxListCtrl::OnRenameAccept(long itemEdit
, const wxString
& value
)
2239 wxListEvent
le( wxEVT_COMMAND_LIST_END_LABEL_EDIT
, GetId() );
2240 le
.SetEventObject( this );
2241 le
.m_itemIndex
= itemEdit
;
2243 GetItem( le
.m_item
);
2244 le
.m_item
.m_text
= value
;
2245 return !HandleWindowEvent( le
) ||
2249 void wxListCtrl::OnRenameCancelled(long itemEdit
)
2251 // let owner know that the edit was cancelled
2252 wxListEvent
le( wxEVT_COMMAND_LIST_END_LABEL_EDIT
, GetParent()->GetId() );
2254 le
.SetEditCanceled(true);
2256 le
.SetEventObject( this );
2257 le
.m_itemIndex
= itemEdit
;
2259 GetItem( le
.m_item
);
2260 HandleWindowEvent( le
);
2263 // ----------------------------------------------------------------------------
2264 // virtual list controls
2265 // ----------------------------------------------------------------------------
2267 wxString
wxListCtrl::OnGetItemText(long WXUNUSED(item
), long WXUNUSED(col
)) const
2269 // this is a pure virtual function, in fact - which is not really pure
2270 // because the controls which are not virtual don't need to implement it
2271 wxFAIL_MSG( _T("wxListCtrl::OnGetItemText not supposed to be called") );
2273 return wxEmptyString
;
2276 int wxListCtrl::OnGetItemImage(long WXUNUSED(item
)) const
2278 wxCHECK_MSG(!GetImageList(wxIMAGE_LIST_SMALL
),
2280 wxT("List control has an image list, OnGetItemImage or OnGetItemColumnImage should be overridden."));
2284 int wxListCtrl::OnGetItemColumnImage(long item
, long column
) const
2287 return OnGetItemImage(item
);
2292 wxListItemAttr
*wxListCtrl::OnGetItemAttr(long WXUNUSED_UNLESS_DEBUG(item
)) const
2294 wxASSERT_MSG( item
>= 0 && item
< GetItemCount(),
2295 _T("invalid item index in OnGetItemAttr()") );
2297 // no attributes by default
2301 void wxListCtrl::SetItemCount(long count
)
2303 wxASSERT_MSG( IsVirtual(), _T("this is for virtual controls only") );
2307 m_genericImpl
->SetItemCount(count
);
2313 // we need to temporarily disable the new item creation notification
2314 // procedure to speed things up
2315 // FIXME: Even this doesn't seem to help much...
2317 // FIXME: Find a more efficient way to do this.
2318 m_dbImpl
->MacClear();
2320 DataBrowserCallbacks callbacks
;
2321 DataBrowserItemNotificationUPP itemUPP
;
2322 GetDataBrowserCallbacks(m_dbImpl
->GetControlRef(), &callbacks
);
2323 itemUPP
= callbacks
.u
.v1
.itemNotificationCallback
;
2324 callbacks
.u
.v1
.itemNotificationCallback
= 0;
2325 m_dbImpl
->SetCallbacks(&callbacks
);
2326 ::AddDataBrowserItems(m_dbImpl
->GetControlRef(), kDataBrowserNoItem
,
2327 count
, NULL
, kDataBrowserItemNoProperty
);
2328 callbacks
.u
.v1
.itemNotificationCallback
= itemUPP
;
2329 m_dbImpl
->SetCallbacks(&callbacks
);
2334 void wxListCtrl::RefreshItem(long item
)
2338 m_genericImpl
->RefreshItem(item
);
2344 DataBrowserItemID id
;
2348 wxMacDataItem
* thisItem
= m_dbImpl
->GetItemFromLine(item
);
2349 id
= (DataBrowserItemID
) thisItem
;
2354 m_dbImpl
->wxMacDataBrowserControl::UpdateItems
2358 kDataBrowserItemNoProperty
, // preSortProperty
2359 kDataBrowserNoItem
// update all columns
2364 void wxListCtrl::RefreshItems(long itemFrom
, long itemTo
)
2368 m_genericImpl
->RefreshItems(itemFrom
, itemTo
);
2374 const long count
= itemTo
- itemFrom
+ 1;
2375 DataBrowserItemID
*ids
= new DataBrowserItemID
[count
];
2379 for ( long i
= 0; i
< count
; i
++ )
2381 wxMacDataItem
* thisItem
= m_dbImpl
->GetItemFromLine(itemFrom
+i
);
2382 ids
[i
] = (DataBrowserItemID
) thisItem
;
2387 for ( long i
= 0; i
< count
; i
++ )
2388 ids
[i
] = itemFrom
+i
+1;
2391 m_dbImpl
->wxMacDataBrowserControl::UpdateItems
2395 kDataBrowserItemNoProperty
, // preSortProperty
2396 kDataBrowserNoItem
// update all columns
2403 void wxListCtrl::SetDropTarget( wxDropTarget
*dropTarget
)
2405 #if wxUSE_DRAG_AND_DROP
2407 m_genericImpl
->SetDropTarget( dropTarget
);
2410 wxWindow::SetDropTarget( dropTarget
);
2414 wxDropTarget
*wxListCtrl::GetDropTarget() const
2416 #if wxUSE_DRAG_AND_DROP
2418 return m_genericImpl
->GetDropTarget();
2421 return wxWindow::GetDropTarget();
2426 #if wxABI_VERSION >= 20801
2427 void wxListCtrl::SetFocus()
2431 m_genericImpl
->SetFocus();
2435 wxWindow::SetFocus();
2439 // wxMac internal data structures
2441 wxMacListCtrlItem::~wxMacListCtrlItem()
2443 WX_CLEAR_HASH_MAP( wxListItemList
, m_rowItems
);
2446 void wxMacListCtrlItem::Notification(wxMacDataItemBrowserControl
*owner
,
2447 DataBrowserItemNotification message
,
2448 DataBrowserItemDataRef
WXUNUSED(itemData
) ) const
2451 wxMacDataBrowserListCtrlControl
*lb
= wxDynamicCast(owner
, wxMacDataBrowserListCtrlControl
);
2453 // we want to depend on as little as possible to make sure tear-down of controls is safe
2454 if ( message
== kDataBrowserItemRemoved
)
2459 else if ( message
== kDataBrowserItemAdded
)
2461 // we don't issue events on adding, the item is not really stored in the list yet, so we
2462 // avoid asserts by gettting out now
2466 wxListCtrl
*list
= wxDynamicCast( owner
->GetWXPeer() , wxListCtrl
);
2469 bool trigger
= false;
2471 wxListEvent
event( wxEVT_COMMAND_LIST_ITEM_SELECTED
, list
->GetId() );
2472 bool isSingle
= (list
->GetWindowStyle() & wxLC_SINGLE_SEL
) != 0;
2474 event
.SetEventObject( list
);
2475 event
.m_itemIndex
= owner
->GetLineFromItem( this ) ;
2476 event
.m_item
.m_itemId
= event
.m_itemIndex
;
2477 list
->GetItem(event
.m_item
);
2481 case kDataBrowserItemDeselected
:
2482 event
.SetEventType(wxEVT_COMMAND_LIST_ITEM_DESELECTED
);
2484 trigger
= !lb
->IsSelectionSuppressed();
2487 case kDataBrowserItemSelected
:
2488 trigger
= !lb
->IsSelectionSuppressed();
2491 case kDataBrowserItemDoubleClicked
:
2492 event
.SetEventType( wxEVT_COMMAND_LIST_ITEM_ACTIVATED
);
2496 case kDataBrowserEditStarted
:
2497 // TODO : how to veto ?
2498 event
.SetEventType( wxEVT_COMMAND_LIST_BEGIN_LABEL_EDIT
) ;
2502 case kDataBrowserEditStopped
:
2503 // TODO probably trigger only upon the value store callback, because
2504 // here IIRC we cannot veto
2505 event
.SetEventType( wxEVT_COMMAND_LIST_END_LABEL_EDIT
) ;
2515 // direct notification is not always having the listbox GetSelection() having in synch with event
2516 wxPostEvent( list
->GetEventHandler(), event
);
2522 IMPLEMENT_DYNAMIC_CLASS(wxMacDataBrowserListCtrlControl
, wxMacDataItemBrowserControl
)
2524 wxMacDataBrowserListCtrlControl::wxMacDataBrowserListCtrlControl( wxWindow
*peer
, const wxPoint
& pos
, const wxSize
& size
, long style
)
2525 : wxMacDataItemBrowserControl( peer
, pos
, size
, style
)
2527 OSStatus err
= noErr
;
2528 m_clientDataItemsType
= wxClientData_None
;
2529 m_isVirtual
= false;
2532 if ( style
& wxLC_VIRTUAL
)
2535 DataBrowserSelectionFlags options
= kDataBrowserDragSelect
;
2536 if ( style
& wxLC_SINGLE_SEL
)
2538 options
|= kDataBrowserSelectOnlyOne
;
2542 options
|= kDataBrowserCmdTogglesSelection
;
2545 err
= SetSelectionFlags( options
);
2546 verify_noerr( err
);
2548 DataBrowserCustomCallbacks callbacks
;
2549 InitializeDataBrowserCustomCallbacks( &callbacks
, kDataBrowserLatestCustomCallbacks
);
2551 if ( gDataBrowserDrawItemUPP
== NULL
)
2552 gDataBrowserDrawItemUPP
= NewDataBrowserDrawItemUPP(DataBrowserDrawItemProc
);
2554 if ( gDataBrowserHitTestUPP
== NULL
)
2555 gDataBrowserHitTestUPP
= NewDataBrowserHitTestUPP(DataBrowserHitTestProc
);
2557 callbacks
.u
.v1
.drawItemCallback
= gDataBrowserDrawItemUPP
;
2558 callbacks
.u
.v1
.hitTestCallback
= gDataBrowserHitTestUPP
;
2560 SetDataBrowserCustomCallbacks( GetControlRef(), &callbacks
);
2562 if ( style
& wxLC_LIST
)
2564 InsertColumn(0, kDataBrowserIconAndTextType
, wxEmptyString
, -1, -1);
2565 verify_noerr( AutoSizeColumns() );
2568 if ( style
& wxLC_LIST
|| style
& wxLC_NO_HEADER
)
2569 verify_noerr( SetHeaderButtonHeight( 0 ) );
2572 SetSortProperty( kMinColumnId
- 1 );
2574 SetSortProperty( kMinColumnId
);
2576 m_sortOrder
= SortOrder_None
;
2578 if ( style
& wxLC_SORT_DESCENDING
)
2580 SetSortOrder( kDataBrowserOrderDecreasing
);
2582 else if ( style
& wxLC_SORT_ASCENDING
)
2584 SetSortOrder( kDataBrowserOrderIncreasing
);
2587 if ( style
& wxLC_VRULES
)
2589 verify_noerr( DataBrowserChangeAttributes(m_controlRef
, kDataBrowserAttributeListViewDrawColumnDividers
, kDataBrowserAttributeNone
) );
2592 verify_noerr( SetHiliteStyle(kDataBrowserTableViewFillHilite
) );
2593 verify_noerr( SetHasScrollBars( (style
& wxHSCROLL
) != 0 , true ) );
2596 pascal Boolean
wxMacDataBrowserListCtrlControl::DataBrowserEditTextProc(
2598 DataBrowserItemID itemID
,
2599 DataBrowserPropertyID property
,
2600 CFStringRef theString
,
2601 Rect
*maxEditTextRect
,
2602 Boolean
*shrinkToFit
)
2604 Boolean result
= false;
2605 wxMacDataBrowserListCtrlControl
* ctl
= wxDynamicCast(wxMacControl::GetReferenceFromNativeControl( browser
), wxMacDataBrowserListCtrlControl
);
2608 result
= ctl
->ConfirmEditText(itemID
, property
, theString
, maxEditTextRect
, shrinkToFit
);
2609 theString
= CFSTR("Hello!");
2614 bool wxMacDataBrowserListCtrlControl::ConfirmEditText(
2615 DataBrowserItemID
WXUNUSED(itemID
),
2616 DataBrowserPropertyID
WXUNUSED(property
),
2617 CFStringRef
WXUNUSED(theString
),
2618 Rect
*WXUNUSED(maxEditTextRect
),
2619 Boolean
*WXUNUSED(shrinkToFit
))
2624 pascal void wxMacDataBrowserListCtrlControl::DataBrowserDrawItemProc(
2626 DataBrowserItemID itemID
,
2627 DataBrowserPropertyID property
,
2628 DataBrowserItemState itemState
,
2629 const Rect
*itemRect
,
2631 Boolean colorDevice
)
2633 wxMacDataBrowserListCtrlControl
* ctl
= wxDynamicCast(wxMacControl::GetReferenceFromNativeControl( browser
), wxMacDataBrowserListCtrlControl
);
2636 ctl
->DrawItem(itemID
, property
, itemState
, itemRect
, gdDepth
, colorDevice
);
2640 // routines needed for DrawItem
2645 kTextBoxHeight
= 14,
2646 kIconTextSpacingV
= 2,
2648 kContentHeight
= kIconHeight
+ kTextBoxHeight
+ kIconTextSpacingV
2651 static void calculateCGDrawingBounds(CGRect inItemRect
, CGRect
*outIconRect
, CGRect
*outTextRect
, bool hasIcon
= false)
2654 float iconH
, iconW
= 0;
2655 float padding
= kItemPadding
;
2658 iconH
= kIconHeight
;
2660 padding
= padding
*2;
2663 textBottom
= inItemRect
.origin
.y
;
2665 *outIconRect
= CGRectMake(inItemRect
.origin
.x
+ kItemPadding
,
2666 textBottom
+ kIconTextSpacingV
, kIconWidth
,
2669 *outTextRect
= CGRectMake(inItemRect
.origin
.x
+ padding
+ iconW
,
2670 textBottom
+ kIconTextSpacingV
, inItemRect
.size
.width
- padding
- iconW
,
2671 inItemRect
.size
.height
- kIconTextSpacingV
);
2674 void wxMacDataBrowserListCtrlControl::DrawItem(
2675 DataBrowserItemID itemID
,
2676 DataBrowserPropertyID property
,
2677 DataBrowserItemState itemState
,
2678 const Rect
*WXUNUSED(itemRect
),
2680 Boolean colorDevice
)
2683 wxFont font
= wxNullFont
;
2686 DataBrowserTableViewColumnIndex listColumn
= 0;
2687 GetColumnPosition( property
, &listColumn
);
2689 wxListCtrl
* list
= wxDynamicCast( GetWXPeer() , wxListCtrl
);
2690 wxMacListCtrlItem
* lcItem
;
2691 wxColour color
= *wxBLACK
;
2692 wxColour bgColor
= wxNullColour
;
2694 if (listColumn
>= 0)
2698 lcItem
= (wxMacListCtrlItem
*) itemID
;
2699 if (lcItem
->HasColumnInfo(listColumn
))
2701 wxListItem
* item
= lcItem
->GetColumnInfo(listColumn
);
2703 // we always use the 0 column to get font and text/background colors.
2704 if (lcItem
->HasColumnInfo(0))
2706 wxListItem
* firstItem
= lcItem
->GetColumnInfo(0);
2707 color
= firstItem
->GetTextColour();
2708 bgColor
= firstItem
->GetBackgroundColour();
2709 font
= firstItem
->GetFont();
2712 if (item
->GetMask() & wxLIST_MASK_TEXT
)
2713 text
= item
->GetText();
2714 if (item
->GetMask() & wxLIST_MASK_IMAGE
)
2715 imgIndex
= item
->GetImage();
2721 long itemNum
= (long)itemID
-1;
2722 if (itemNum
>= 0 && itemNum
< list
->GetItemCount())
2724 text
= list
->OnGetItemText( itemNum
, listColumn
);
2725 imgIndex
= list
->OnGetItemColumnImage( itemNum
, listColumn
);
2726 wxListItemAttr
* attrs
= list
->OnGetItemAttr( itemNum
);
2729 if (attrs
->HasBackgroundColour())
2730 bgColor
= attrs
->GetBackgroundColour();
2731 if (attrs
->HasTextColour())
2732 color
= attrs
->GetTextColour();
2733 if (attrs
->HasFont())
2734 font
= attrs
->GetFont();
2740 wxColour listBgColor
= list
->GetBackgroundColour();
2741 if (bgColor
== wxNullColour
)
2742 bgColor
= listBgColor
;
2745 font
= list
->GetFont();
2747 wxCFStringRef
cfString( text
, wxLocale::GetSystemEncoding() );
2750 CGRect enclosingCGRect
, iconCGRect
, textCGRect
;
2752 ThemeDrawingState savedState
= NULL
;
2753 CGContextRef context
= (CGContextRef
)list
->MacGetDrawingContext();
2754 RGBColor labelColor
;
2756 labelColor
.green
= 0;
2757 labelColor
.blue
= 0;
2759 RGBColor backgroundColor
;
2760 backgroundColor
.red
= 255;
2761 backgroundColor
.green
= 255;
2762 backgroundColor
.blue
= 255;
2764 GetDataBrowserItemPartBounds(GetControlRef(), itemID
, property
, kDataBrowserPropertyEnclosingPart
,
2767 enclosingCGRect
= CGRectMake(enclosingRect
.left
,
2769 enclosingRect
.right
- enclosingRect
.left
,
2770 enclosingRect
.bottom
- enclosingRect
.top
);
2772 bool hasFocus
= (wxWindow::FindFocus() == list
);
2773 active
= IsControlActive(GetControlRef());
2775 // don't paint the background over the vertical rule line
2776 if ( list
->GetWindowStyleFlag() & wxLC_VRULES
)
2778 enclosingCGRect
.origin
.x
+= 1;
2779 enclosingCGRect
.size
.width
-= 1;
2781 if (itemState
== kDataBrowserItemIsSelected
)
2784 GetThemeDrawingState(&savedState
);
2786 if (active
&& hasFocus
)
2788 GetThemeBrushAsColor(kThemeBrushAlternatePrimaryHighlightColor
, 32, true, &backgroundColor
);
2789 GetThemeTextColor(kThemeTextColorWhite
, gdDepth
, colorDevice
, &labelColor
);
2793 GetThemeBrushAsColor(kThemeBrushSecondaryHighlightColor
, 32, true, &backgroundColor
);
2794 GetThemeTextColor(kThemeTextColorBlack
, gdDepth
, colorDevice
, &labelColor
);
2796 CGContextSaveGState(context
);
2798 CGContextSetRGBFillColor(context
, (CGFloat
)backgroundColor
.red
/ (CGFloat
)USHRT_MAX
,
2799 (CGFloat
)backgroundColor
.green
/ (CGFloat
)USHRT_MAX
,
2800 (CGFloat
)backgroundColor
.blue
/ (CGFloat
)USHRT_MAX
, (CGFloat
) 1.0);
2801 CGContextFillRect(context
, enclosingCGRect
);
2803 CGContextRestoreGState(context
);
2809 color
.GetRGBColor(&labelColor
);
2810 else if (list
->GetTextColour().Ok())
2811 list
->GetTextColour().GetRGBColor(&labelColor
);
2815 bgColor
.GetRGBColor(&backgroundColor
);
2816 CGContextSaveGState(context
);
2818 CGContextSetRGBFillColor(context
, (CGFloat
)backgroundColor
.red
/ (CGFloat
)USHRT_MAX
,
2819 (CGFloat
)backgroundColor
.green
/ (CGFloat
)USHRT_MAX
,
2820 (CGFloat
)backgroundColor
.blue
/ (CGFloat
)USHRT_MAX
, (CGFloat
) 1.0);
2821 CGContextFillRect(context
, enclosingCGRect
);
2823 CGContextRestoreGState(context
);
2827 calculateCGDrawingBounds(enclosingCGRect
, &iconCGRect
, &textCGRect
, (imgIndex
!= -1) );
2831 wxImageList
* imageList
= list
->GetImageList(wxIMAGE_LIST_SMALL
);
2832 if (imageList
&& imageList
->GetImageCount() > 0){
2833 wxBitmap bmp
= imageList
->GetBitmap(imgIndex
);
2834 IconRef icon
= bmp
.GetIconRef();
2836 CGContextSaveGState(context
);
2837 CGContextTranslateCTM(context
, 0,iconCGRect
.origin
.y
+ CGRectGetMaxY(iconCGRect
));
2838 CGContextScaleCTM(context
,1.0f
,-1.0f
);
2839 PlotIconRefInContext(context
, &iconCGRect
, kAlignNone
,
2840 active
? kTransformNone
: kTransformDisabled
, NULL
,
2841 kPlotIconRefNormalFlags
, icon
);
2843 CGContextRestoreGState(context
);
2847 HIThemeTextHorizontalFlush hFlush
= kHIThemeTextHorizontalFlushLeft
;
2848 HIThemeTextInfo info
;
2850 #if wxOSX_USE_CORE_TEXT
2851 if ( UMAGetSystemVersion() >= 0x1050 )
2853 info
.version
= kHIThemeTextInfoVersionOne
;
2854 info
.fontID
= kThemeViewsFont
;
2857 info
.fontID
= kThemeSpecifiedFont
;
2858 info
.font
= (CTFontRef
) font
.OSXGetCTFont();
2863 #if wxOSX_USE_ATSU_TEXT
2866 info
.version
= kHIThemeTextInfoVersionZero
;
2867 info
.fontID
= kThemeViewsFont
;
2871 info
.fontID
= font
.MacGetThemeFontID();
2873 ::TextSize( (short)(font
.GetPointSize()) ) ;
2874 ::TextFace( font
.MacGetFontStyle() ) ;
2880 list
->GetColumn(listColumn
, item
);
2881 if (item
.GetMask() & wxLIST_MASK_FORMAT
)
2883 if (item
.GetAlign() == wxLIST_FORMAT_LEFT
)
2884 hFlush
= kHIThemeTextHorizontalFlushLeft
;
2885 else if (item
.GetAlign() == wxLIST_FORMAT_CENTER
)
2886 hFlush
= kHIThemeTextHorizontalFlushCenter
;
2887 else if (item
.GetAlign() == wxLIST_FORMAT_RIGHT
)
2889 hFlush
= kHIThemeTextHorizontalFlushRight
;
2890 textCGRect
.origin
.x
-= kItemPadding
; // give a little extra paddding
2894 info
.state
= active
? kThemeStateActive
: kThemeStateInactive
;
2895 info
.horizontalFlushness
= hFlush
;
2896 info
.verticalFlushness
= kHIThemeTextVerticalFlushCenter
;
2897 info
.options
= kHIThemeTextBoxOptionNone
;
2898 info
.truncationPosition
= kHIThemeTextTruncationEnd
;
2899 info
.truncationMaxLines
= 1;
2901 CGContextSaveGState(context
);
2902 CGContextSetRGBFillColor (context
, (CGFloat
)labelColor
.red
/ (CGFloat
)USHRT_MAX
,
2903 (CGFloat
)labelColor
.green
/ (CGFloat
)USHRT_MAX
,
2904 (CGFloat
)labelColor
.blue
/ (CGFloat
)USHRT_MAX
, (CGFloat
) 1.0);
2906 HIThemeDrawTextBox(cfString
, &textCGRect
, &info
, context
, kHIThemeOrientationNormal
);
2908 CGContextRestoreGState(context
);
2911 if (savedState
!= NULL
)
2912 SetThemeDrawingState(savedState
, true);
2916 OSStatus
wxMacDataBrowserListCtrlControl::GetSetItemData(DataBrowserItemID itemID
,
2917 DataBrowserPropertyID property
,
2918 DataBrowserItemDataRef itemData
,
2919 Boolean changeValue
)
2924 DataBrowserTableViewColumnIndex listColumn
= 0;
2925 verify_noerr( GetColumnPosition( property
, &listColumn
) );
2927 OSStatus err
= errDataBrowserPropertyNotSupported
;
2928 wxListCtrl
* list
= wxDynamicCast( GetWXPeer() , wxListCtrl
);
2929 wxMacListCtrlItem
* lcItem
= NULL
;
2931 if (listColumn
>= 0)
2935 lcItem
= (wxMacListCtrlItem
*) itemID
;
2936 if (lcItem
&& lcItem
->HasColumnInfo(listColumn
)){
2937 wxListItem
* item
= lcItem
->GetColumnInfo(listColumn
);
2938 if (item
->GetMask() & wxLIST_MASK_TEXT
)
2939 text
= item
->GetText();
2940 if (item
->GetMask() & wxLIST_MASK_IMAGE
)
2941 imgIndex
= item
->GetImage();
2946 long itemNum
= (long)itemID
-1;
2947 if (itemNum
>= 0 && itemNum
< list
->GetItemCount())
2949 text
= list
->OnGetItemText( itemNum
, listColumn
);
2950 imgIndex
= list
->OnGetItemColumnImage( itemNum
, listColumn
);
2959 case kDataBrowserItemIsEditableProperty
:
2960 if ( list
&& list
->HasFlag( wxLC_EDIT_LABELS
) )
2962 verify_noerr(SetDataBrowserItemDataBooleanValue( itemData
, true ));
2967 if ( property
>= kMinColumnId
)
2969 if (!text
.IsEmpty()){
2970 wxCFStringRef
cfStr( text
, wxLocale::GetSystemEncoding() );
2971 err
= ::SetDataBrowserItemDataText( itemData
, cfStr
);
2977 if ( imgIndex
!= -1 )
2979 wxImageList
* imageList
= list
->GetImageList(wxIMAGE_LIST_SMALL
);
2980 if (imageList
&& imageList
->GetImageCount() > 0){
2981 wxBitmap bmp
= imageList
->GetBitmap(imgIndex
);
2982 IconRef icon
= bmp
.GetIconRef();
2983 ::SetDataBrowserItemDataIcon(itemData
, icon
);
2997 if ( property
>= kMinColumnId
)
2999 DataBrowserTableViewColumnIndex listColumn
= 0;
3000 verify_noerr( GetColumnPosition( property
, &listColumn
) );
3002 // TODO probably send the 'end edit' from here, as we
3003 // can then deal with the veto
3005 verify_noerr( GetDataBrowserItemDataText( itemData
, &sr
) ) ;
3006 wxCFStringRef
cfStr(sr
) ;;
3008 list
->SetItem( (long)itemData
-1 , listColumn
, cfStr
.AsString() ) ;
3012 lcItem
->SetColumnTextValue( listColumn
, cfStr
.AsString() );
3022 void wxMacDataBrowserListCtrlControl::ItemNotification(DataBrowserItemID itemID
,
3023 DataBrowserItemNotification message
,
3024 DataBrowserItemDataRef itemData
)
3026 wxMacListCtrlItem
*item
= NULL
;
3029 item
= (wxMacListCtrlItem
*) itemID
;
3032 // we want to depend on as little as possible to make sure tear-down of controls is safe
3033 if ( message
== kDataBrowserItemRemoved
)
3036 item
->Notification(this, message
, itemData
);
3039 else if ( message
== kDataBrowserItemAdded
)
3041 // we don't issue events on adding, the item is not really stored in the list yet, so we
3042 // avoid asserts by getting out now
3044 item
->Notification(this, message
, itemData
);
3048 wxListCtrl
*list
= wxDynamicCast( GetWXPeer() , wxListCtrl
);
3051 bool trigger
= false;
3053 wxListEvent
event( wxEVT_COMMAND_LIST_ITEM_SELECTED
, list
->GetId() );
3055 event
.SetEventObject( list
);
3056 if ( !list
->IsVirtual() )
3058 DataBrowserTableViewRowIndex result
= 0;
3059 verify_noerr( GetItemRow( itemID
, &result
) ) ;
3060 event
.m_itemIndex
= result
;
3064 event
.m_itemIndex
= (long)itemID
-1;
3066 event
.m_item
.m_itemId
= event
.m_itemIndex
;
3067 list
->GetItem(event
.m_item
);
3071 case kDataBrowserItemDeselected
:
3072 event
.SetEventType(wxEVT_COMMAND_LIST_ITEM_DESELECTED
);
3073 // as the generic implementation is also triggering this
3074 // event for single selection, we do the same (different than listbox)
3075 trigger
= !IsSelectionSuppressed();
3078 case kDataBrowserItemSelected
:
3079 trigger
= !IsSelectionSuppressed();
3083 case kDataBrowserItemDoubleClicked
:
3084 event
.SetEventType( wxEVT_COMMAND_LIST_ITEM_ACTIVATED
);
3088 case kDataBrowserEditStarted
:
3089 // TODO : how to veto ?
3090 event
.SetEventType( wxEVT_COMMAND_LIST_BEGIN_LABEL_EDIT
) ;
3094 case kDataBrowserEditStopped
:
3095 // TODO probably trigger only upon the value store callback, because
3096 // here IIRC we cannot veto
3097 event
.SetEventType( wxEVT_COMMAND_LIST_END_LABEL_EDIT
) ;
3107 // direct notification is not always having the listbox GetSelection() having in synch with event
3108 wxPostEvent( list
->GetEventHandler(), event
);
3113 Boolean
wxMacDataBrowserListCtrlControl::CompareItems(DataBrowserItemID itemOneID
,
3114 DataBrowserItemID itemTwoID
,
3115 DataBrowserPropertyID sortProperty
)
3118 bool retval
= false;
3120 wxString otherItemText
;
3122 long otherItemOrder
;
3124 DataBrowserTableViewColumnIndex colId
= 0;
3125 verify_noerr( GetColumnPosition( sortProperty
, &colId
) );
3127 wxListCtrl
* list
= wxDynamicCast( GetWXPeer() , wxListCtrl
);
3129 DataBrowserSortOrder sort
;
3130 verify_noerr(GetSortOrder(&sort
));
3136 wxMacListCtrlItem
* item
= (wxMacListCtrlItem
*)itemOneID
;
3137 wxMacListCtrlItem
* otherItem
= (wxMacListCtrlItem
*)itemTwoID
;
3139 itemOrder
= item
->GetOrder();
3140 otherItemOrder
= otherItem
->GetOrder();
3142 wxListCtrlCompare func
= list
->GetCompareFunc();
3148 if (item
&& item
->HasColumnInfo(0))
3149 item1
= item
->GetColumnInfo(0)->GetData();
3150 if (otherItem
&& otherItem
->HasColumnInfo(0))
3151 item2
= otherItem
->GetColumnInfo(0)->GetData();
3153 if (item1
> -1 && item2
> -1)
3155 int result
= func(item1
, item2
, list
->GetCompareFuncData());
3156 if (sort
== kDataBrowserOrderIncreasing
)
3163 // we can't use the native control's sorting abilities, so just
3165 return itemOrder
< otherItemOrder
;
3170 long itemNum
= (long)itemOneID
;
3171 long otherItemNum
= (long)itemTwoID
;
3173 // virtual listctrls don't support sorting
3174 return itemNum
< otherItemNum
;
3178 // fallback for undefined cases
3179 retval
= itemOneID
< itemTwoID
;
3185 wxMacDataBrowserListCtrlControl::~wxMacDataBrowserListCtrlControl()
3189 void wxMacDataBrowserListCtrlControl::MacSetColumnInfo( unsigned int row
, unsigned int column
, wxListItem
* item
)
3191 wxMacDataItem
* dataItem
= GetItemFromLine(row
);
3192 wxASSERT_MSG( dataItem
, _T("could not obtain wxMacDataItem for row in MacSetColumnInfo. Is row a valid wxListCtrl row?") );
3195 wxMacListCtrlItem
* listItem
= static_cast<wxMacListCtrlItem
*>(dataItem
);
3196 bool hasInfo
= listItem
->HasColumnInfo( column
);
3197 listItem
->SetColumnInfo( column
, item
);
3198 listItem
->SetOrder(row
);
3199 UpdateState(dataItem
, item
);
3201 wxListCtrl
* list
= wxDynamicCast( GetWXPeer() , wxListCtrl
);
3203 // NB: When this call was made before a control was completely shown, it would
3204 // update the item prematurely (i.e. no text would be listed) and, on show,
3205 // only the sorted column would be refreshed, meaning only first column text labels
3206 // would be shown. Making sure not to update items until the control is visible
3207 // seems to fix this issue.
3208 if (hasInfo
&& list
->IsShown())
3210 DataBrowserTableViewColumnID id
= 0;
3211 verify_noerr( GetColumnIDFromIndex( column
, &id
) );
3212 UpdateItem( wxMacDataBrowserRootContainer
, listItem
, id
);
3217 // apply changes that need to happen immediately, rather than when the
3218 // databrowser control fires a callback.
3219 void wxMacDataBrowserListCtrlControl::UpdateState(wxMacDataItem
* dataItem
, wxListItem
* listItem
)
3221 bool isSelected
= IsItemSelected( dataItem
);
3222 bool isSelectedState
= (listItem
->GetState() == wxLIST_STATE_SELECTED
);
3224 // toggle the selection state if wxListInfo state and actual state don't match.
3225 if ( listItem
->GetMask() & wxLIST_MASK_STATE
&& isSelected
!= isSelectedState
)
3227 DataBrowserSetOption options
= kDataBrowserItemsAdd
;
3228 if (!isSelectedState
)
3229 options
= kDataBrowserItemsRemove
;
3230 SetSelectedItem(dataItem
, options
);
3232 // TODO: Set column width if item width > than current column width
3235 void wxMacDataBrowserListCtrlControl::MacGetColumnInfo( unsigned int row
, unsigned int column
, wxListItem
& item
)
3237 wxMacDataItem
* dataItem
= GetItemFromLine(row
);
3238 wxASSERT_MSG( dataItem
, _T("could not obtain wxMacDataItem in MacGetColumnInfo. Is row a valid wxListCtrl row?") );
3239 // CS should this guard against dataItem = 0 ? , as item is not a pointer if (item) is not appropriate
3242 wxMacListCtrlItem
* listItem
= static_cast<wxMacListCtrlItem
*>(dataItem
);
3244 if (!listItem
->HasColumnInfo( column
))
3247 wxListItem
* oldItem
= listItem
->GetColumnInfo( column
);
3251 long mask
= item
.GetMask();
3253 // by default, get everything for backwards compatibility
3256 if ( mask
& wxLIST_MASK_TEXT
)
3257 item
.SetText(oldItem
->GetText());
3258 if ( mask
& wxLIST_MASK_IMAGE
)
3259 item
.SetImage(oldItem
->GetImage());
3260 if ( mask
& wxLIST_MASK_DATA
)
3261 item
.SetData(oldItem
->GetData());
3262 if ( mask
& wxLIST_MASK_STATE
)
3263 item
.SetState(oldItem
->GetState());
3264 if ( mask
& wxLIST_MASK_WIDTH
)
3265 item
.SetWidth(oldItem
->GetWidth());
3266 if ( mask
& wxLIST_MASK_FORMAT
)
3267 item
.SetAlign(oldItem
->GetAlign());
3269 item
.SetTextColour(oldItem
->GetTextColour());
3270 item
.SetBackgroundColour(oldItem
->GetBackgroundColour());
3271 item
.SetFont(oldItem
->GetFont());
3276 void wxMacDataBrowserListCtrlControl::MacInsertItem( unsigned int n
, wxListItem
* item
)
3279 wxMacDataItemBrowserControl::MacInsert(n
, new wxMacListCtrlItem() );
3280 MacSetColumnInfo(n
, 0, item
);
3283 wxMacListCtrlItem::wxMacListCtrlItem()
3285 m_rowItems
= wxListItemList();
3288 int wxMacListCtrlItem::GetColumnImageValue( unsigned int column
)
3290 if ( HasColumnInfo(column
) )
3291 return GetColumnInfo(column
)->GetImage();
3296 void wxMacListCtrlItem::SetColumnImageValue( unsigned int column
, int imageIndex
)
3298 if ( HasColumnInfo(column
) )
3299 GetColumnInfo(column
)->SetImage(imageIndex
);
3302 wxString
wxMacListCtrlItem::GetColumnTextValue( unsigned int column
)
3304 /* TODO CHECK REMOVE
3308 if ( HasColumnInfo(column
) )
3309 return GetColumnInfo(column
)->GetText();
3311 return wxEmptyString
;
3314 void wxMacListCtrlItem::SetColumnTextValue( unsigned int column
, const wxString
& text
)
3316 if ( HasColumnInfo(column
) )
3317 GetColumnInfo(column
)->SetText(text
);
3319 /* TODO CHECK REMOVE
3320 // for compatibility with superclass APIs
3326 wxListItem
* wxMacListCtrlItem::GetColumnInfo( unsigned int column
)
3328 wxASSERT_MSG( HasColumnInfo(column
), _T("invalid column index in wxMacListCtrlItem") );
3329 return m_rowItems
[column
];
3332 bool wxMacListCtrlItem::HasColumnInfo( unsigned int column
)
3334 return !(m_rowItems
.find( column
) == m_rowItems
.end());
3337 void wxMacListCtrlItem::SetColumnInfo( unsigned int column
, wxListItem
* item
)
3340 if ( !HasColumnInfo(column
) )
3342 wxListItem
* listItem
= new wxListItem(*item
);
3343 m_rowItems
[column
] = listItem
;
3347 wxListItem
* listItem
= GetColumnInfo( column
);
3348 long mask
= item
->GetMask();
3349 if (mask
& wxLIST_MASK_TEXT
)
3350 listItem
->SetText(item
->GetText());
3351 if (mask
& wxLIST_MASK_DATA
)
3352 listItem
->SetData(item
->GetData());
3353 if (mask
& wxLIST_MASK_IMAGE
)
3354 listItem
->SetImage(item
->GetImage());
3355 if (mask
& wxLIST_MASK_STATE
)
3356 listItem
->SetState(item
->GetState());
3357 if (mask
& wxLIST_MASK_FORMAT
)
3358 listItem
->SetAlign(item
->GetAlign());
3359 if (mask
& wxLIST_MASK_WIDTH
)
3360 listItem
->SetWidth(item
->GetWidth());
3362 if ( item
->HasAttributes() )
3364 if ( listItem
->HasAttributes() )
3365 listItem
->GetAttributes()->AssignFrom(*item
->GetAttributes());
3368 listItem
->SetTextColour(item
->GetTextColour());
3369 listItem
->SetBackgroundColour(item
->GetBackgroundColour());
3370 listItem
->SetFont(item
->GetFont());
3376 int wxListCtrl::CalcColumnAutoWidth(int col
) const
3380 for ( int i
= 0; i
< GetItemCount(); i
++ )
3383 info
.SetMask(wxLIST_MASK_TEXT
| wxLIST_MASK_IMAGE
);
3385 info
.SetColumn(col
);
3388 const wxFont font
= info
.GetFont();
3392 GetTextExtent(info
.GetText(), &w
, NULL
, NULL
, NULL
, &font
);
3394 GetTextExtent(info
.GetText(), &w
, NULL
);
3396 w
+= 2 * kItemPadding
;
3398 if ( info
.GetImage() != -1 )
3401 width
= wxMax(width
, w
);
3407 #endif // wxUSE_LISTCTRL