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 int id
= event
.GetId();
304 wxObject
* obj
= event
.GetEventObject();
306 // even though we use a generic list ctrl underneath, make sure
307 // we present ourselves as wxListCtrl.
308 event
.SetEventObject( m_list
);
311 if ( !event
.IsKindOf( CLASSINFO( wxCommandEvent
) ) )
313 if (m_list
->GetEventHandler()->ProcessEvent( event
))
316 event
.SetEventObject(obj
);
320 // Also try with the original id
321 bool success
= wxEvtHandler::ProcessEvent(event
);
323 event
.SetEventObject(obj
);
324 if (!success
&& id
!= m_id
)
325 success
= wxEvtHandler::ProcessEvent(event
);
329 //-----------------------------------------------------------------------------
330 // wxListCtrlRenameTimer (internal)
331 //-----------------------------------------------------------------------------
333 class wxListCtrlRenameTimer
: public wxTimer
339 wxListCtrlRenameTimer( wxListCtrl
*owner
);
343 //-----------------------------------------------------------------------------
344 // wxListCtrlTextCtrlWrapper: wraps a wxTextCtrl to make it work for inline editing
345 //-----------------------------------------------------------------------------
347 class wxListCtrlTextCtrlWrapper
: public wxEvtHandler
350 // NB: text must be a valid object but not Create()d yet
351 wxListCtrlTextCtrlWrapper(wxListCtrl
*owner
,
355 wxTextCtrl
*GetText() const { return m_text
; }
357 void AcceptChangesAndFinish();
360 void OnChar( wxKeyEvent
&event
);
361 void OnKeyUp( wxKeyEvent
&event
);
362 void OnKillFocus( wxFocusEvent
&event
);
364 bool AcceptChanges();
370 wxString m_startValue
;
373 bool m_aboutToFinish
;
375 DECLARE_EVENT_TABLE()
378 //-----------------------------------------------------------------------------
379 // wxListCtrlRenameTimer (internal)
380 //-----------------------------------------------------------------------------
382 wxListCtrlRenameTimer::wxListCtrlRenameTimer( wxListCtrl
*owner
)
387 void wxListCtrlRenameTimer::Notify()
389 m_owner
->OnRenameTimer();
392 //-----------------------------------------------------------------------------
393 // wxListCtrlTextCtrlWrapper (internal)
394 //-----------------------------------------------------------------------------
396 BEGIN_EVENT_TABLE(wxListCtrlTextCtrlWrapper
, wxEvtHandler
)
397 EVT_CHAR (wxListCtrlTextCtrlWrapper::OnChar
)
398 EVT_KEY_UP (wxListCtrlTextCtrlWrapper::OnKeyUp
)
399 EVT_KILL_FOCUS (wxListCtrlTextCtrlWrapper::OnKillFocus
)
402 wxListCtrlTextCtrlWrapper::wxListCtrlTextCtrlWrapper(wxListCtrl
*owner
,
405 : m_startValue(owner
->GetItemText(itemEdit
)),
406 m_itemEdited(itemEdit
)
411 m_aboutToFinish
= false;
415 owner
->GetItemRect(itemEdit
, rectLabel
);
417 m_text
->Create(owner
, wxID_ANY
, m_startValue
,
418 wxPoint(rectLabel
.x
+offset
,rectLabel
.y
),
419 wxSize(rectLabel
.width
-offset
,rectLabel
.height
));
422 m_text
->PushEventHandler(this);
425 void wxListCtrlTextCtrlWrapper::Finish()
431 m_text
->RemoveEventHandler(this);
432 m_owner
->FinishEditing(m_text
);
434 wxPendingDelete
.Append( this );
438 bool wxListCtrlTextCtrlWrapper::AcceptChanges()
440 const wxString value
= m_text
->GetValue();
442 if ( value
== m_startValue
)
443 // nothing changed, always accept
446 if ( !m_owner
->OnRenameAccept(m_itemEdited
, value
) )
447 // vetoed by the user
450 // accepted, do rename the item
451 m_owner
->SetItemText(m_itemEdited
, value
);
456 void wxListCtrlTextCtrlWrapper::AcceptChangesAndFinish()
458 m_aboutToFinish
= true;
460 // Notify the owner about the changes
463 // Even if vetoed, close the control (consistent with MSW)
467 void wxListCtrlTextCtrlWrapper::OnChar( wxKeyEvent
&event
)
469 switch ( event
.m_keyCode
)
472 AcceptChangesAndFinish();
476 m_owner
->OnRenameCancelled( m_itemEdited
);
485 void wxListCtrlTextCtrlWrapper::OnKeyUp( wxKeyEvent
&event
)
493 // auto-grow the textctrl:
494 wxSize parentSize
= m_owner
->GetSize();
495 wxPoint myPos
= m_text
->GetPosition();
496 wxSize mySize
= m_text
->GetSize();
498 m_text
->GetTextExtent(m_text
->GetValue() + _T("MM"), &sx
, &sy
);
499 if (myPos
.x
+ sx
> parentSize
.x
)
500 sx
= parentSize
.x
- myPos
.x
;
503 m_text
->SetSize(sx
, wxDefaultCoord
);
508 void wxListCtrlTextCtrlWrapper::OnKillFocus( wxFocusEvent
&event
)
510 if ( !m_finished
&& !m_aboutToFinish
)
512 if ( !AcceptChanges() )
513 m_owner
->OnRenameCancelled( m_itemEdited
);
518 // We must let the native text control handle focus
522 BEGIN_EVENT_TABLE(wxListCtrl
, wxControl
)
523 EVT_LEFT_DOWN(wxListCtrl::OnLeftDown
)
524 EVT_LEFT_DCLICK(wxListCtrl::OnDblClick
)
525 EVT_MIDDLE_DOWN(wxListCtrl::OnMiddleDown
)
526 EVT_RIGHT_DOWN(wxListCtrl::OnRightDown
)
527 EVT_CHAR(wxListCtrl::OnChar
)
530 // ============================================================================
532 // ============================================================================
534 wxMacDataBrowserListCtrlControl
* wxListCtrl::GetListPeer() const
536 return dynamic_cast<wxMacDataBrowserListCtrlControl
*> ( GetPeer() );
539 // ----------------------------------------------------------------------------
540 // wxListCtrl construction
541 // ----------------------------------------------------------------------------
543 void wxListCtrl::Init()
545 m_imageListNormal
= NULL
;
546 m_imageListSmall
= NULL
;
547 m_imageListState
= NULL
;
549 // keep track of if we created our own image lists, or if they were assigned
551 m_ownsImageListNormal
= m_ownsImageListSmall
= m_ownsImageListState
= false;
555 m_genericImpl
= NULL
;
557 m_compareFunc
= NULL
;
558 m_compareFuncData
= 0;
559 m_colsInfo
= wxColumnList();
560 m_textColor
= wxNullColour
;
561 m_bgColor
= wxNullColour
;
562 m_textctrlWrapper
= NULL
;
564 m_renameTimer
= new wxListCtrlRenameTimer( this );
567 class wxGenericListCtrlHook
: public wxGenericListCtrl
570 wxGenericListCtrlHook(wxListCtrl
* parent
,
575 const wxValidator
& validator
,
576 const wxString
& name
)
577 : wxGenericListCtrl(parent
, id
, pos
, size
, style
, validator
, name
),
578 m_nativeListCtrl(parent
)
583 virtual wxListItemAttr
* OnGetItemAttr(long item
) const
585 return m_nativeListCtrl
->OnGetItemAttr(item
);
588 virtual int OnGetItemImage(long item
) const
590 return m_nativeListCtrl
->OnGetItemImage(item
);
593 virtual int OnGetItemColumnImage(long item
, long column
) const
595 return m_nativeListCtrl
->OnGetItemColumnImage(item
, column
);
598 virtual wxString
OnGetItemText(long item
, long column
) const
600 return m_nativeListCtrl
->OnGetItemText(item
, column
);
603 wxListCtrl
* m_nativeListCtrl
;
607 void wxListCtrl::OnLeftDown(wxMouseEvent
& event
)
609 if ( m_textctrlWrapper
)
612 m_textctrlWrapper
->AcceptChangesAndFinish();
616 long current
= HitTest(event
.GetPosition(), hitResult
);
617 if ((current
== m_current
) &&
618 (hitResult
== wxLIST_HITTEST_ONITEM
) &&
619 HasFlag(wxLC_EDIT_LABELS
) )
621 m_renameTimer
->Start( 100, true );
630 void wxListCtrl::OnDblClick(wxMouseEvent
& event
)
632 if ( m_renameTimer
->IsRunning() )
633 m_renameTimer
->Stop();
637 #if wxABI_VERSION >= 20801
638 void wxListCtrl::OnRightDown(wxMouseEvent
& event
)
641 FireMouseEvent(wxEVT_COMMAND_LIST_ITEM_RIGHT_CLICK
, event
.GetPosition());
645 void wxListCtrl::OnMiddleDown(wxMouseEvent
& event
)
648 FireMouseEvent(wxEVT_COMMAND_LIST_ITEM_MIDDLE_CLICK
, event
.GetPosition());
652 void wxListCtrl::FireMouseEvent(wxEventType eventType
, wxPoint position
)
654 wxListEvent
le( eventType
, GetId() );
655 le
.SetEventObject(this);
656 le
.m_pointDrag
= position
;
660 long item
= HitTest(position
, flags
);
661 if (flags
& wxLIST_HITTEST_ONITEM
)
663 le
.m_itemIndex
= item
;
664 le
.m_item
.m_itemId
= item
;
666 HandleWindowEvent(le
);
670 void wxListCtrl::OnChar(wxKeyEvent
& event
)
676 wxListEvent
le( wxEVT_COMMAND_LIST_KEY_DOWN
, GetId() );
677 le
.SetEventObject(this);
678 le
.m_code
= event
.GetKeyCode();
683 // if m_current isn't set, check if there's been a selection
684 // made before continuing
685 m_current
= GetNextItem(-1, wxLIST_NEXT_BELOW
, wxLIST_STATE_SELECTED
);
688 // We need to determine m_current ourselves when navigation keys
689 // are used. Note that PAGEUP and PAGEDOWN do not alter the current
690 // item on native Mac ListCtrl, so we only handle up and down keys.
691 switch ( event
.GetKeyCode() )
702 if ( m_current
< GetItemCount() - 1 )
705 m_current
= GetItemCount() - 1;
712 le
.m_itemIndex
= m_current
;
713 le
.m_item
.m_itemId
= m_current
;
715 HandleWindowEvent(le
);
722 bool wxListCtrl::Create(wxWindow
*parent
,
727 const wxValidator
& validator
,
728 const wxString
& name
)
731 // for now, we'll always use the generic list control for ICON and LIST views,
732 // because they dynamically change the number of columns on resize.
733 // Also, allow the user to set it to use the list ctrl as well.
734 if ( (wxSystemOptions::HasOption( wxMAC_ALWAYS_USE_GENERIC_LISTCTRL
)
735 && (wxSystemOptions::GetOptionInt( wxMAC_ALWAYS_USE_GENERIC_LISTCTRL
) == 1)) ||
736 (style
& wxLC_ICON
) || (style
& wxLC_SMALL_ICON
) || (style
& wxLC_LIST
) )
738 m_macIsUserPane
= true;
740 long paneStyle
= style
;
741 paneStyle
&= ~wxSIMPLE_BORDER
;
742 paneStyle
&= ~wxDOUBLE_BORDER
;
743 paneStyle
&= ~wxSUNKEN_BORDER
;
744 paneStyle
&= ~wxRAISED_BORDER
;
745 paneStyle
&= ~wxSTATIC_BORDER
;
746 if ( !wxWindow::Create(parent
, id
, pos
, size
, paneStyle
| wxNO_BORDER
, name
) )
749 // since the generic control is a child, make sure we position it at 0, 0
750 m_genericImpl
= new wxGenericListCtrlHook(this, id
, wxPoint(0, 0), size
, style
, validator
, name
);
751 m_genericImpl
->PushEventHandler( new wxMacListCtrlEventDelegate( this, GetId() ) );
757 m_macIsUserPane
= false;
758 if ( !wxWindow::Create(parent
, id
, pos
, size
, style
& ~(wxHSCROLL
| wxVSCROLL
), name
) )
760 m_dbImpl
= new wxMacDataBrowserListCtrlControl( this, pos
, size
, style
);
763 MacPostControlCreate( pos
, size
);
765 InstallControlEventHandler( m_peer
->GetControlRef() , GetwxMacListCtrlEventHandlerUPP(),
766 GetEventTypeCount(eventList
), eventList
, this,
767 (EventHandlerRef
*)&m_macListCtrlEventHandler
);
773 wxListCtrl::~wxListCtrl()
777 m_genericImpl
->PopEventHandler(/* deleteHandler = */ true);
780 if (m_ownsImageListNormal
)
781 delete m_imageListNormal
;
782 if (m_ownsImageListSmall
)
783 delete m_imageListSmall
;
784 if (m_ownsImageListState
)
785 delete m_imageListState
;
787 delete m_renameTimer
;
789 WX_CLEAR_LIST(wxColumnList
, m_colsInfo
);
794 wxListCtrl::GetClassDefaultAttributes(wxWindowVariant
WXUNUSED(variant
))
796 wxVisualAttributes attr
;
798 attr
.colFg
= wxSystemSettings::GetColour( wxSYS_COLOUR_WINDOWTEXT
);
799 attr
.colBg
= wxSystemSettings::GetColour( wxSYS_COLOUR_LISTBOX
);
800 attr
.font
.CreateSystemFont(wxOSX_SYSTEM_FONT_VIEWS
);
805 // ----------------------------------------------------------------------------
806 // set/get/change style
807 // ----------------------------------------------------------------------------
809 // Add or remove a single window style
810 void wxListCtrl::SetSingleStyle(long style
, bool add
)
812 long flag
= GetWindowStyleFlag();
814 // Get rid of conflicting styles
817 if ( style
& wxLC_MASK_TYPE
)
818 flag
= flag
& ~wxLC_MASK_TYPE
;
819 if ( style
& wxLC_MASK_ALIGN
)
820 flag
= flag
& ~wxLC_MASK_ALIGN
;
821 if ( style
& wxLC_MASK_SORT
)
822 flag
= flag
& ~wxLC_MASK_SORT
;
830 SetWindowStyleFlag(flag
);
833 // Set the whole window style
834 void wxListCtrl::SetWindowStyleFlag(long flag
)
836 if ( flag
!= m_windowStyle
)
838 m_windowStyle
= flag
;
842 m_genericImpl
->SetWindowStyleFlag(flag
);
849 void wxListCtrl::DoSetSize( int x
, int y
, int width
, int height
, int sizeFlags
)
851 wxControl::DoSetSize(x
, y
, width
, height
, sizeFlags
);
854 m_genericImpl
->SetSize(0, 0, width
, height
, sizeFlags
);
856 // determine if we need a horizontal scrollbar, and add it if so
860 for (int column
= 0; column
< GetColumnCount(); column
++)
862 totalWidth
+= m_dbImpl
->GetColumnWidth( column
);
865 if ( !(m_dbImpl
->GetFlags() & wxHSCROLL
) )
867 Boolean vertScrollBar
;
868 GetDataBrowserHasScrollBars( m_dbImpl
->GetControlRef(), NULL
, &vertScrollBar
);
869 if (totalWidth
> width
)
870 SetDataBrowserHasScrollBars( m_dbImpl
->GetControlRef(), true, vertScrollBar
);
872 SetDataBrowserHasScrollBars( m_dbImpl
->GetControlRef(), false, vertScrollBar
);
877 wxSize
wxListCtrl::DoGetBestSize() const
879 return wxWindow::DoGetBestSize();
882 bool wxListCtrl::SetFont(const wxFont
& font
)
885 rv
= wxControl::SetFont(font
);
887 rv
= m_genericImpl
->SetFont(font
);
891 bool wxListCtrl::SetForegroundColour(const wxColour
& colour
)
895 rv
= m_genericImpl
->SetForegroundColour(colour
);
897 SetTextColour(colour
);
901 bool wxListCtrl::SetBackgroundColour(const wxColour
& colour
)
905 rv
= m_genericImpl
->SetBackgroundColour(colour
);
911 wxColour
wxListCtrl::GetBackgroundColour() const
914 return m_genericImpl
->GetBackgroundColour();
921 // ----------------------------------------------------------------------------
923 // ----------------------------------------------------------------------------
925 // Gets information about this column
926 bool wxListCtrl::GetColumn(int col
, wxListItem
& item
) const
929 return m_genericImpl
->GetColumn(col
, item
);
935 wxColumnList::compatibility_iterator node
= m_colsInfo
.Item( col
);
936 wxASSERT_MSG( node
, _T("invalid column index in wxMacListCtrlItem") );
937 wxListItem
* column
= node
->GetData();
939 long mask
= column
->GetMask();
940 if (mask
& wxLIST_MASK_TEXT
)
941 item
.SetText(column
->GetText());
942 if (mask
& wxLIST_MASK_DATA
)
943 item
.SetData(column
->GetData());
944 if (mask
& wxLIST_MASK_IMAGE
)
945 item
.SetImage(column
->GetImage());
946 if (mask
& wxLIST_MASK_STATE
)
947 item
.SetState(column
->GetState());
948 if (mask
& wxLIST_MASK_FORMAT
)
949 item
.SetAlign(column
->GetAlign());
950 if (mask
& wxLIST_MASK_WIDTH
)
951 item
.SetWidth(column
->GetWidth());
957 // Sets information about this column
958 bool wxListCtrl::SetColumn(int col
, wxListItem
& item
)
961 return m_genericImpl
->SetColumn(col
, item
);
965 wxASSERT_MSG( col
< (int)m_colsInfo
.GetCount(), _T("invalid column index in wxMacListCtrlItem") );
967 long mask
= item
.GetMask();
970 GetColumn( col
, listItem
);
972 if (mask
& wxLIST_MASK_TEXT
)
973 listItem
.SetText(item
.GetText());
974 if (mask
& wxLIST_MASK_DATA
)
975 listItem
.SetData(item
.GetData());
976 if (mask
& wxLIST_MASK_IMAGE
)
977 listItem
.SetImage(item
.GetImage());
978 if (mask
& wxLIST_MASK_STATE
)
979 listItem
.SetState(item
.GetState());
980 if (mask
& wxLIST_MASK_FORMAT
)
981 listItem
.SetAlign(item
.GetAlign());
982 if (mask
& wxLIST_MASK_WIDTH
)
983 listItem
.SetWidth(item
.GetWidth());
986 // change the appearance in the databrowser.
987 DataBrowserListViewHeaderDesc columnDesc
;
988 columnDesc
.version
=kDataBrowserListViewLatestHeaderDesc
;
990 DataBrowserTableViewColumnID id
= 0;
991 verify_noerr( m_dbImpl
->GetColumnIDFromIndex( col
, &id
) );
992 verify_noerr( m_dbImpl
->GetHeaderDesc( id
, &columnDesc
) );
995 if (item.GetMask() & wxLIST_MASK_TEXT)
999 enc = GetFont().GetEncoding();
1001 enc = wxLocale::GetSystemEncoding();
1002 wxCFStringRef cfTitle;
1003 cfTitle.Assign( item.GetText() , enc );
1004 if(columnDesc.titleString)
1005 CFRelease(columnDesc.titleString);
1006 columnDesc.titleString = cfTitle;
1010 if (item
.GetMask() & wxLIST_MASK_IMAGE
&& item
.GetImage() != -1 )
1012 wxImageList
* imageList
= GetImageList(wxIMAGE_LIST_SMALL
);
1013 if (imageList
&& imageList
->GetImageCount() > 0 )
1015 wxBitmap bmp
= imageList
->GetBitmap( item
.GetImage() );
1016 IconRef icon
= bmp
.GetIconRef();
1017 columnDesc
.btnContentInfo
.u
.iconRef
= icon
;
1018 columnDesc
.btnContentInfo
.contentType
= kControlContentIconRef
;
1022 verify_noerr( m_dbImpl
->SetHeaderDesc( id
, &columnDesc
) );
1028 int wxListCtrl::GetColumnCount() const
1031 return m_genericImpl
->GetColumnCount();
1036 m_dbImpl
->GetColumnCount(&count
);
1043 // Gets the column width
1044 int wxListCtrl::GetColumnWidth(int col
) const
1047 return m_genericImpl
->GetColumnWidth(col
);
1051 return m_dbImpl
->GetColumnWidth(col
);
1057 // Sets the column width
1058 bool wxListCtrl::SetColumnWidth(int col
, int width
)
1061 return m_genericImpl
->SetColumnWidth(col
, width
);
1065 if ( width
== wxLIST_AUTOSIZE_USEHEADER
)
1067 width
= 150; // FIXME
1072 for (int column
= 0; column
< GetColumnCount(); column
++)
1075 GetColumn(column
, colInfo
);
1077 colInfo
.SetWidth(width
);
1078 SetColumn(column
, colInfo
);
1080 const int mywidth
= (width
== wxLIST_AUTOSIZE
)
1081 ? CalcColumnAutoWidth(column
) : width
;
1082 m_dbImpl
->SetColumnWidth(column
, mywidth
);
1087 if ( width
== wxLIST_AUTOSIZE
)
1088 width
= CalcColumnAutoWidth(col
);
1091 GetColumn(col
, colInfo
);
1093 colInfo
.SetWidth(width
);
1094 SetColumn(col
, colInfo
);
1095 m_dbImpl
->SetColumnWidth(col
, width
);
1103 // Gets the number of items that can fit vertically in the
1104 // visible area of the list control (list or report view)
1105 // or the total number of items in the list control (icon
1106 // or small icon view)
1107 int wxListCtrl::GetCountPerPage() const
1110 return m_genericImpl
->GetCountPerPage();
1115 m_dbImpl
->GetDefaultRowHeight( &height
);
1117 return GetClientSize().y
/ height
;
1123 // Gets the edit control for editing labels.
1124 wxTextCtrl
* wxListCtrl::GetEditControl() const
1127 return m_genericImpl
->GetEditControl();
1132 // Gets information about the item
1133 bool wxListCtrl::GetItem(wxListItem
& info
) const
1136 return m_genericImpl
->GetItem(info
);
1142 if (info
.m_itemId
>= 0 && info
.m_itemId
< GetItemCount())
1144 m_dbImpl
->MacGetColumnInfo(info
.m_itemId
, info
.m_col
, info
);
1145 // MacGetColumnInfo returns erroneous information in the state field, so zero it.
1147 if (info
.GetMask() & wxLIST_MASK_STATE
)
1149 DataBrowserItemID id
= (DataBrowserItemID
)m_dbImpl
->GetItemFromLine(info
.m_itemId
);
1150 if (IsDataBrowserItemSelected( m_dbImpl
->GetControlRef(), id
))
1151 info
.SetState(info
.GetState() | wxLIST_STATE_SELECTED
);
1157 if (info
.m_itemId
>= 0 && info
.m_itemId
< GetItemCount())
1159 info
.SetText( OnGetItemText(info
.m_itemId
, info
.m_col
) );
1160 info
.SetImage( OnGetItemColumnImage(info
.m_itemId
, info
.m_col
) );
1161 if (info
.GetMask() & wxLIST_MASK_STATE
)
1163 if (IsDataBrowserItemSelected( m_dbImpl
->GetControlRef(), info
.m_itemId
+1 ))
1164 info
.SetState(info
.GetState() | wxLIST_STATE_SELECTED
);
1167 wxListItemAttr
* attrs
= OnGetItemAttr( info
.m_itemId
);
1170 info
.SetFont( attrs
->GetFont() );
1171 info
.SetBackgroundColour( attrs
->GetBackgroundColour() );
1172 info
.SetTextColour( attrs
->GetTextColour() );
1177 bool success
= true;
1181 // Sets information about the item
1182 bool wxListCtrl::SetItem(wxListItem
& info
)
1185 return m_genericImpl
->SetItem(info
);
1188 m_dbImpl
->MacSetColumnInfo( info
.m_itemId
, info
.m_col
, &info
);
1193 long wxListCtrl::SetItem(long index
, int col
, const wxString
& label
, int imageId
)
1196 return m_genericImpl
->SetItem(index
, col
, label
, imageId
);
1199 info
.m_text
= label
;
1200 info
.m_mask
= wxLIST_MASK_TEXT
;
1201 info
.m_itemId
= index
;
1205 info
.m_image
= imageId
;
1206 info
.m_mask
|= wxLIST_MASK_IMAGE
;
1208 return SetItem(info
);
1212 // Gets the item state
1213 int wxListCtrl::GetItemState(long item
, long stateMask
) const
1216 return m_genericImpl
->GetItemState(item
, stateMask
);
1220 if ( HasFlag(wxLC_VIRTUAL
) )
1222 if (stateMask
== wxLIST_STATE_SELECTED
)
1224 if (IsDataBrowserItemSelected( m_dbImpl
->GetControlRef(), item
+1 ))
1225 return wxLIST_STATE_SELECTED
;
1234 info
.m_mask
= wxLIST_MASK_STATE
;
1235 info
.m_stateMask
= stateMask
;
1236 info
.m_itemId
= item
;
1241 return info
.m_state
;
1248 // Sets the item state
1249 bool wxListCtrl::SetItemState(long item
, long state
, long stateMask
)
1252 return m_genericImpl
->SetItemState(item
, state
, stateMask
);
1256 DataBrowserSetOption option
= kDataBrowserItemsAdd
;
1257 if ( (stateMask
& wxLIST_STATE_SELECTED
) && state
== 0 )
1258 option
= kDataBrowserItemsRemove
;
1262 if ( HasFlag(wxLC_VIRTUAL
) )
1264 wxMacDataItemBrowserSelectionSuppressor
suppressor(m_dbImpl
);
1265 m_dbImpl
->SetSelectedAllItems(option
);
1269 for(int i
= 0; i
< GetItemCount();i
++)
1273 info
.m_mask
= wxLIST_MASK_STATE
;
1274 info
.m_stateMask
= stateMask
;
1275 info
.m_state
= state
;
1282 if ( HasFlag(wxLC_VIRTUAL
) )
1284 long itemID
= item
+1;
1285 bool isSelected
= IsDataBrowserItemSelected(m_dbImpl
->GetControlRef(), (DataBrowserItemID
)itemID
);
1286 bool isSelectedState
= (state
== wxLIST_STATE_SELECTED
);
1288 // toggle the selection state if wxListInfo state and actual state don't match.
1289 if ( (stateMask
& wxLIST_STATE_SELECTED
) && isSelected
!= isSelectedState
)
1291 SetDataBrowserSelectedItems(m_dbImpl
->GetControlRef(), 1, (DataBrowserItemID
*)&itemID
, option
);
1297 info
.m_itemId
= item
;
1298 info
.m_mask
= wxLIST_MASK_STATE
;
1299 info
.m_stateMask
= stateMask
;
1300 info
.m_state
= state
;
1301 return SetItem(info
);
1308 // Sets the item image
1309 bool wxListCtrl::SetItemImage(long item
, int image
, int WXUNUSED(selImage
))
1311 return SetItemColumnImage(item
, 0, image
);
1314 // Sets the item image
1315 bool wxListCtrl::SetItemColumnImage(long item
, long column
, int image
)
1318 return m_genericImpl
->SetItemColumnImage(item
, column
, image
);
1322 info
.m_mask
= wxLIST_MASK_IMAGE
;
1323 info
.m_image
= image
;
1324 info
.m_itemId
= item
;
1325 info
.m_col
= column
;
1327 return SetItem(info
);
1330 // Gets the item text
1331 wxString
wxListCtrl::GetItemText(long item
) const
1334 return m_genericImpl
->GetItemText(item
);
1338 info
.m_mask
= wxLIST_MASK_TEXT
;
1339 info
.m_itemId
= item
;
1342 return wxEmptyString
;
1346 // Sets the item text
1347 void wxListCtrl::SetItemText(long item
, const wxString
& str
)
1350 return m_genericImpl
->SetItemText(item
, str
);
1354 info
.m_mask
= wxLIST_MASK_TEXT
;
1355 info
.m_itemId
= item
;
1361 // Gets the item data
1362 long wxListCtrl::GetItemData(long item
) const
1365 return m_genericImpl
->GetItemData(item
);
1369 info
.m_mask
= wxLIST_MASK_DATA
;
1370 info
.m_itemId
= item
;
1377 // Sets the item data
1378 bool wxListCtrl::SetItemPtrData(long item
, wxUIntPtr data
)
1381 return m_genericImpl
->SetItemData(item
, data
);
1385 info
.m_mask
= wxLIST_MASK_DATA
;
1386 info
.m_itemId
= item
;
1389 return SetItem(info
);
1392 wxRect
wxListCtrl::GetViewRect() const
1394 wxASSERT_MSG( !HasFlag(wxLC_REPORT
| wxLC_LIST
),
1395 _T("wxListCtrl::GetViewRect() only works in icon mode") );
1398 return m_genericImpl
->GetViewRect();
1404 bool wxListCtrl::GetSubItemRect( long item
, long subItem
, wxRect
& rect
, int code
) const
1407 return m_genericImpl
->GetSubItemRect(item
, subItem
, rect
, code
);
1409 // TODO: implement for DataBrowser implementation
1413 // Gets the item rectangle
1414 bool wxListCtrl::GetItemRect(long item
, wxRect
& rect
, int code
) const
1417 return m_genericImpl
->GetItemRect(item
, rect
, code
);
1422 DataBrowserItemID id
;
1424 DataBrowserTableViewColumnID col
= 0;
1425 verify_noerr( m_dbImpl
->GetColumnIDFromIndex( 0, &col
) );
1428 DataBrowserPropertyPart part
= kDataBrowserPropertyEnclosingPart
;
1429 if ( code
== wxLIST_RECT_LABEL
)
1430 part
= kDataBrowserPropertyTextPart
;
1431 else if ( code
== wxLIST_RECT_ICON
)
1432 part
= kDataBrowserPropertyIconPart
;
1434 if ( !(GetWindowStyleFlag() & wxLC_VIRTUAL
) )
1436 wxMacDataItem
* thisItem
= m_dbImpl
->GetItemFromLine(item
);
1437 id
= (DataBrowserItemID
) thisItem
;
1442 GetDataBrowserItemPartBounds( m_dbImpl
->GetControlRef(), id
, col
, part
, &bounds
);
1444 rect
.x
= bounds
.left
;
1445 rect
.y
= bounds
.top
;
1446 rect
.width
= bounds
.right
- bounds
.left
; //GetClientSize().x; // we need the width of the whole row, not just the item.
1447 rect
.height
= bounds
.bottom
- bounds
.top
;
1448 //fprintf("id = %d, bounds = %d, %d, %d, %d\n", id, rect.x, rect.y, rect.width, rect.height);
1453 // Gets the item position
1454 bool wxListCtrl::GetItemPosition(long item
, wxPoint
& pos
) const
1457 return m_genericImpl
->GetItemPosition(item
, pos
);
1459 bool success
= false;
1464 GetItemRect(item
, itemRect
);
1465 pos
= itemRect
.GetPosition();
1472 // Sets the item position.
1473 bool wxListCtrl::SetItemPosition(long item
, const wxPoint
& pos
)
1476 return m_genericImpl
->SetItemPosition(item
, pos
);
1481 // Gets the number of items in the list control
1482 int wxListCtrl::GetItemCount() const
1485 return m_genericImpl
->GetItemCount();
1488 return m_dbImpl
->MacGetCount();
1493 void wxListCtrl::SetItemSpacing( int spacing
, bool isSmall
)
1496 m_genericImpl
->SetItemSpacing(spacing
, isSmall
);
1499 wxSize
wxListCtrl::GetItemSpacing() const
1502 return m_genericImpl
->GetItemSpacing();
1504 return wxSize(0, 0);
1507 void wxListCtrl::SetItemTextColour( long item
, const wxColour
&col
)
1511 m_genericImpl
->SetItemTextColour(item
, col
);
1516 info
.m_itemId
= item
;
1517 info
.SetTextColour( col
);
1521 wxColour
wxListCtrl::GetItemTextColour( long item
) const
1524 return m_genericImpl
->GetItemTextColour(item
);
1530 return info
.GetTextColour();
1532 return wxNullColour
;
1535 void wxListCtrl::SetItemBackgroundColour( long item
, const wxColour
&col
)
1539 m_genericImpl
->SetItemBackgroundColour(item
, col
);
1544 info
.m_itemId
= item
;
1545 info
.SetBackgroundColour( col
);
1549 wxColour
wxListCtrl::GetItemBackgroundColour( long item
) const
1552 return m_genericImpl
->GetItemBackgroundColour(item
);
1558 return info
.GetBackgroundColour();
1560 return wxNullColour
;
1563 void wxListCtrl::SetItemFont( long item
, const wxFont
&f
)
1567 m_genericImpl
->SetItemFont(item
, f
);
1572 info
.m_itemId
= item
;
1577 wxFont
wxListCtrl::GetItemFont( long item
) const
1580 return m_genericImpl
->GetItemFont(item
);
1586 return info
.GetFont();
1592 // Gets the number of selected items in the list control
1593 int wxListCtrl::GetSelectedItemCount() const
1596 return m_genericImpl
->GetSelectedItemCount();
1599 return m_dbImpl
->GetSelectedItemCount(NULL
, true);
1604 // Gets the text colour of the listview
1605 wxColour
wxListCtrl::GetTextColour() const
1608 return m_genericImpl
->GetTextColour();
1610 // TODO: we need owner drawn list items to customize text color.
1614 return wxNullColour
;
1617 // Sets the text colour of the listview
1618 void wxListCtrl::SetTextColour(const wxColour
& col
)
1622 m_genericImpl
->SetTextColour(col
);
1630 // Gets the index of the topmost visible item when in
1631 // list or report view
1632 long wxListCtrl::GetTopItem() const
1635 return m_genericImpl
->GetTopItem();
1640 long item
= HitTest( wxPoint(1, 1), flags
);
1641 if (flags
== wxLIST_HITTEST_ONITEM
)
1648 // Searches for an item, starting from 'item'.
1649 // 'geometry' is one of
1650 // wxLIST_NEXT_ABOVE/ALL/BELOW/LEFT/RIGHT.
1651 // 'state' is a state bit flag, one or more of
1652 // wxLIST_STATE_DROPHILITED/FOCUSED/SELECTED/CUT.
1653 // item can be -1 to find the first item that matches the
1655 // Returns the item or -1 if unsuccessful.
1656 long wxListCtrl::GetNextItem(long item
, int geom
, int state
) const
1659 return m_genericImpl
->GetNextItem(item
, geom
, state
);
1661 // TODO: implement all geometry and state options?
1664 if ( geom
== wxLIST_NEXT_ALL
|| geom
== wxLIST_NEXT_BELOW
)
1666 long count
= m_dbImpl
->MacGetCount() ;
1667 for ( long line
= item
+ 1 ; line
< count
; line
++ )
1669 DataBrowserItemID id
= line
+ 1;
1671 id
= (DataBrowserItemID
)m_dbImpl
->GetItemFromLine(line
);
1673 if ( (state
& wxLIST_STATE_FOCUSED
) && (m_current
== line
))
1676 if ( (state
== wxLIST_STATE_DONTCARE
) )
1679 if ( (state
& wxLIST_STATE_SELECTED
) && IsDataBrowserItemSelected(m_dbImpl
->GetControlRef(), id
) )
1684 if ( geom
== wxLIST_NEXT_ABOVE
)
1688 item2
= m_dbImpl
->MacGetCount();
1690 for ( long line
= item2
- 1 ; line
>= 0; line
-- )
1692 DataBrowserItemID id
= line
+ 1;
1694 id
= (DataBrowserItemID
)m_dbImpl
->GetItemFromLine(line
);
1696 if ( (state
& wxLIST_STATE_FOCUSED
) && (m_current
== line
))
1699 if ( (state
== wxLIST_STATE_DONTCARE
) )
1702 if ( (state
& wxLIST_STATE_SELECTED
) && IsDataBrowserItemSelected(m_dbImpl
->GetControlRef(), id
) )
1712 wxImageList
*wxListCtrl::GetImageList(int which
) const
1715 return m_genericImpl
->GetImageList(which
);
1717 if ( which
== wxIMAGE_LIST_NORMAL
)
1719 return m_imageListNormal
;
1721 else if ( which
== wxIMAGE_LIST_SMALL
)
1723 return m_imageListSmall
;
1725 else if ( which
== wxIMAGE_LIST_STATE
)
1727 return m_imageListState
;
1732 void wxListCtrl::SetImageList(wxImageList
*imageList
, int which
)
1736 m_genericImpl
->SetImageList(imageList
, which
);
1740 if ( which
== wxIMAGE_LIST_NORMAL
)
1742 if (m_ownsImageListNormal
) delete m_imageListNormal
;
1743 m_imageListNormal
= imageList
;
1744 m_ownsImageListNormal
= false;
1746 else if ( which
== wxIMAGE_LIST_SMALL
)
1748 if (m_ownsImageListSmall
) delete m_imageListSmall
;
1749 m_imageListSmall
= imageList
;
1750 m_ownsImageListSmall
= false;
1752 else if ( which
== wxIMAGE_LIST_STATE
)
1754 if (m_ownsImageListState
) delete m_imageListState
;
1755 m_imageListState
= imageList
;
1756 m_ownsImageListState
= false;
1760 void wxListCtrl::AssignImageList(wxImageList
*imageList
, int which
)
1764 m_genericImpl
->AssignImageList(imageList
, which
);
1768 SetImageList(imageList
, which
);
1769 if ( which
== wxIMAGE_LIST_NORMAL
)
1770 m_ownsImageListNormal
= true;
1771 else if ( which
== wxIMAGE_LIST_SMALL
)
1772 m_ownsImageListSmall
= true;
1773 else if ( which
== wxIMAGE_LIST_STATE
)
1774 m_ownsImageListState
= true;
1777 // ----------------------------------------------------------------------------
1779 // ----------------------------------------------------------------------------
1781 // Arranges the items
1782 bool wxListCtrl::Arrange(int flag
)
1785 return m_genericImpl
->Arrange(flag
);
1790 bool wxListCtrl::DeleteItem(long item
)
1793 return m_genericImpl
->DeleteItem(item
);
1797 m_dbImpl
->MacDelete(item
);
1798 wxListEvent
event( wxEVT_COMMAND_LIST_DELETE_ITEM
, GetId() );
1799 event
.SetEventObject( this );
1800 event
.m_itemIndex
= item
;
1801 HandleWindowEvent( event
);
1807 // Deletes all items
1808 bool wxListCtrl::DeleteAllItems()
1812 return m_genericImpl
->DeleteAllItems();
1816 m_dbImpl
->MacClear();
1817 wxListEvent
event( wxEVT_COMMAND_LIST_DELETE_ALL_ITEMS
, GetId() );
1818 event
.SetEventObject( this );
1819 HandleWindowEvent( event
);
1824 // Deletes all items
1825 bool wxListCtrl::DeleteAllColumns()
1828 return m_genericImpl
->DeleteAllColumns();
1833 m_dbImpl
->GetColumnCount(&cols
);
1834 for (UInt32 col
= 0; col
< cols
; col
++)
1844 bool wxListCtrl::DeleteColumn(int col
)
1847 return m_genericImpl
->DeleteColumn(col
);
1851 OSStatus err
= m_dbImpl
->RemoveColumn(col
);
1852 return err
== noErr
;
1858 // Clears items, and columns if there are any.
1859 void wxListCtrl::ClearAll()
1863 m_genericImpl
->ClearAll();
1874 wxTextCtrl
* wxListCtrl::EditLabel(long item
, wxClassInfo
* textControlClass
)
1877 return m_genericImpl
->EditLabel(item
, textControlClass
);
1881 wxCHECK_MSG( (item
>= 0) && ((long)item
< GetItemCount()), NULL
,
1882 wxT("wrong index in wxListCtrl::EditLabel()") );
1884 wxASSERT_MSG( textControlClass
->IsKindOf(CLASSINFO(wxTextCtrl
)),
1885 wxT("EditLabel() needs a text control") );
1887 wxListEvent
le( wxEVT_COMMAND_LIST_BEGIN_LABEL_EDIT
, GetParent()->GetId() );
1888 le
.SetEventObject( this );
1889 le
.m_itemIndex
= item
;
1891 GetItem( le
.m_item
);
1893 if ( GetParent()->HandleWindowEvent( le
) && !le
.IsAllowed() )
1895 // vetoed by user code
1899 wxTextCtrl
* const text
= (wxTextCtrl
*)textControlClass
->CreateObject();
1900 m_textctrlWrapper
= new wxListCtrlTextCtrlWrapper(this, text
, item
);
1901 return m_textctrlWrapper
->GetText();
1906 // End label editing, optionally cancelling the edit
1907 bool wxListCtrl::EndEditLabel(bool WXUNUSED(cancel
))
1909 // TODO: generic impl. doesn't have this method - is it needed for us?
1911 return true; // m_genericImpl->EndEditLabel(cancel);
1915 DataBrowserTableViewColumnID id
= 0;
1916 verify_noerr( m_dbImpl
->GetColumnIDFromIndex( 0, &id
) );
1917 verify_noerr( SetDataBrowserEditItem(m_dbImpl
->GetControlRef(), kDataBrowserNoItem
, id
) );
1922 // Ensures this item is visible
1923 bool wxListCtrl::EnsureVisible(long item
)
1926 return m_genericImpl
->EnsureVisible(item
);
1930 wxMacDataItem
* dataItem
= m_dbImpl
->GetItemFromLine(item
);
1931 m_dbImpl
->RevealItem(dataItem
, kDataBrowserRevealWithoutSelecting
);
1937 // Find an item whose label matches this string, starting from the item after 'start'
1938 // or the beginning if 'start' is -1.
1939 long wxListCtrl::FindItem(long start
, const wxString
& str
, bool partial
)
1942 return m_genericImpl
->FindItem(start
, str
, partial
);
1944 wxString str_upper
= str
.Upper();
1949 long count
= GetItemCount();
1953 wxString line_upper
= GetItemText(idx
).Upper();
1956 if (line_upper
== str_upper
)
1961 if (line_upper
.find(str_upper
) == 0)
1971 // Find an item whose data matches this data, starting from the item after 'start'
1972 // or the beginning if 'start' is -1.
1973 long wxListCtrl::FindItem(long start
, long data
)
1976 return m_genericImpl
->FindItem(start
, data
);
1981 long count
= GetItemCount();
1985 if (GetItemData(idx
) == data
)
1993 // Find an item nearest this position in the specified direction, starting from
1994 // the item after 'start' or the beginning if 'start' is -1.
1995 long wxListCtrl::FindItem(long start
, const wxPoint
& pt
, int direction
)
1998 return m_genericImpl
->FindItem(start
, pt
, direction
);
2002 // Determines which item (if any) is at the specified point,
2003 // giving details in 'flags' (see wxLIST_HITTEST_... flags above)
2005 wxListCtrl::HitTest(const wxPoint
& point
, int& flags
, long *ptrSubItem
) const
2008 return m_genericImpl
->HitTest(point
, flags
, ptrSubItem
);
2010 flags
= wxLIST_HITTEST_NOWHERE
;
2013 int colHeaderHeight
= 22; // TODO: Find a way to get this value from the db control?
2014 UInt16 rowHeight
= 0;
2015 m_dbImpl
->GetDefaultRowHeight(&rowHeight
);
2018 // get the actual row by taking scroll position into account
2019 UInt32 offsetX
, offsetY
;
2020 m_dbImpl
->GetScrollPosition( &offsetY
, &offsetX
);
2023 if ( !(GetWindowStyleFlag() & wxLC_NO_HEADER
) )
2024 y
-= colHeaderHeight
;
2029 int row
= y
/ rowHeight
;
2030 DataBrowserItemID id
;
2031 m_dbImpl
->GetItemID( (DataBrowserTableViewRowIndex
) row
, &id
);
2033 // TODO: Use GetDataBrowserItemPartBounds to return if we are in icon or label
2034 if ( !(GetWindowStyleFlag() & wxLC_VIRTUAL
) )
2036 wxMacListCtrlItem
* lcItem
;
2037 lcItem
= (wxMacListCtrlItem
*) id
;
2040 flags
= wxLIST_HITTEST_ONITEM
;
2046 if (row
< GetItemCount() )
2048 flags
= wxLIST_HITTEST_ONITEM
;
2057 int wxListCtrl::GetScrollPos(int orient
) const
2060 return m_genericImpl
->GetScrollPos(orient
);
2064 UInt32 offsetX
, offsetY
;
2065 m_dbImpl
->GetScrollPosition( &offsetY
, &offsetX
);
2066 if ( orient
== wxHORIZONTAL
)
2075 // Inserts an item, returning the index of the new item if successful,
2077 long wxListCtrl::InsertItem(wxListItem
& info
)
2079 wxASSERT_MSG( !IsVirtual(), _T("can't be used with virtual controls") );
2082 return m_genericImpl
->InsertItem(info
);
2084 if (m_dbImpl
&& !IsVirtual())
2086 int count
= GetItemCount();
2088 if (info
.m_itemId
> count
)
2089 info
.m_itemId
= count
;
2091 m_dbImpl
->MacInsertItem(info
.m_itemId
, &info
);
2093 wxListEvent
event( wxEVT_COMMAND_LIST_INSERT_ITEM
, GetId() );
2094 event
.SetEventObject( this );
2095 event
.m_itemIndex
= info
.m_itemId
;
2096 HandleWindowEvent( event
);
2097 return info
.m_itemId
;
2102 long wxListCtrl::InsertItem(long index
, const wxString
& label
)
2105 return m_genericImpl
->InsertItem(index
, label
);
2108 info
.m_text
= label
;
2109 info
.m_mask
= wxLIST_MASK_TEXT
;
2110 info
.m_itemId
= index
;
2111 return InsertItem(info
);
2114 // Inserts an image item
2115 long wxListCtrl::InsertItem(long index
, int imageIndex
)
2118 return m_genericImpl
->InsertItem(index
, imageIndex
);
2121 info
.m_image
= imageIndex
;
2122 info
.m_mask
= wxLIST_MASK_IMAGE
;
2123 info
.m_itemId
= index
;
2124 return InsertItem(info
);
2127 // Inserts an image/string item
2128 long wxListCtrl::InsertItem(long index
, const wxString
& label
, int imageIndex
)
2131 return m_genericImpl
->InsertItem(index
, label
, imageIndex
);
2134 info
.m_image
= imageIndex
;
2135 info
.m_text
= label
;
2136 info
.m_mask
= wxLIST_MASK_IMAGE
| wxLIST_MASK_TEXT
;
2137 info
.m_itemId
= index
;
2138 return InsertItem(info
);
2141 // For list view mode (only), inserts a column.
2142 long wxListCtrl::InsertColumn(long col
, wxListItem
& item
)
2145 return m_genericImpl
->InsertColumn(col
, item
);
2149 int width
= item
.GetWidth();
2150 if ( !(item
.GetMask() & wxLIST_MASK_WIDTH
) )
2153 DataBrowserPropertyType type
= kDataBrowserCustomType
; //kDataBrowserTextType;
2154 wxImageList
* imageList
= GetImageList(wxIMAGE_LIST_SMALL
);
2155 if (imageList
&& imageList
->GetImageCount() > 0)
2157 wxBitmap bmp
= imageList
->GetBitmap(0);
2159 // type = kDataBrowserIconAndTextType;
2162 SInt16 just
= teFlushDefault
;
2163 if (item
.GetMask() & wxLIST_MASK_FORMAT
)
2165 if (item
.GetAlign() == wxLIST_FORMAT_LEFT
)
2167 else if (item
.GetAlign() == wxLIST_FORMAT_CENTER
)
2169 else if (item
.GetAlign() == wxLIST_FORMAT_RIGHT
)
2170 just
= teFlushRight
;
2172 m_dbImpl
->InsertColumn(col
, type
, item
.GetText(), just
, width
);
2174 wxListItem
* listItem
= new wxListItem(item
);
2175 m_colsInfo
.Insert( col
, listItem
);
2176 SetColumn(col
, item
);
2178 // set/remove options based on the wxListCtrl type.
2179 DataBrowserTableViewColumnID id
;
2180 m_dbImpl
->GetColumnIDFromIndex(col
, &id
);
2181 DataBrowserPropertyFlags flags
;
2182 verify_noerr(m_dbImpl
->GetPropertyFlags(id
, &flags
));
2183 if (GetWindowStyleFlag() & wxLC_EDIT_LABELS
)
2184 flags
|= kDataBrowserPropertyIsEditable
;
2186 if (GetWindowStyleFlag() & wxLC_VIRTUAL
){
2187 flags
&= ~kDataBrowserListViewSortableColumn
;
2189 verify_noerr(m_dbImpl
->SetPropertyFlags(id
, flags
));
2195 long wxListCtrl::InsertColumn(long col
,
2196 const wxString
& heading
,
2201 return m_genericImpl
->InsertColumn(col
, heading
, format
, width
);
2204 item
.m_mask
= wxLIST_MASK_TEXT
| wxLIST_MASK_FORMAT
;
2205 item
.m_text
= heading
;
2208 item
.m_mask
|= wxLIST_MASK_WIDTH
;
2209 item
.m_width
= width
;
2211 item
.m_format
= format
;
2213 return InsertColumn(col
, item
);
2216 // scroll the control by the given number of pixels (exception: in list view,
2217 // dx is interpreted as number of columns)
2218 bool wxListCtrl::ScrollList(int dx
, int dy
)
2221 return m_genericImpl
->ScrollList(dx
, dy
);
2225 m_dbImpl
->SetScrollPosition(dx
, dy
);
2231 bool wxListCtrl::SortItems(wxListCtrlCompare fn
, wxIntPtr data
)
2234 return m_genericImpl
->SortItems(fn
, data
);
2239 m_compareFuncData
= data
;
2240 SortDataBrowserContainer( m_dbImpl
->GetControlRef(), kDataBrowserNoItem
, true);
2242 // we need to do this after each call, else we get a crash from wxPython when
2243 // SortItems is called the second time.
2244 m_compareFunc
= NULL
;
2245 m_compareFuncData
= 0;
2251 void wxListCtrl::OnRenameTimer()
2253 wxCHECK_RET( HasCurrent(), wxT("unexpected rename timer") );
2255 EditLabel( m_current
);
2258 bool wxListCtrl::OnRenameAccept(long itemEdit
, const wxString
& value
)
2260 wxListEvent
le( wxEVT_COMMAND_LIST_END_LABEL_EDIT
, GetId() );
2261 le
.SetEventObject( this );
2262 le
.m_itemIndex
= itemEdit
;
2264 GetItem( le
.m_item
);
2265 le
.m_item
.m_text
= value
;
2266 return !HandleWindowEvent( le
) ||
2270 void wxListCtrl::OnRenameCancelled(long itemEdit
)
2272 // let owner know that the edit was cancelled
2273 wxListEvent
le( wxEVT_COMMAND_LIST_END_LABEL_EDIT
, GetParent()->GetId() );
2275 le
.SetEditCanceled(true);
2277 le
.SetEventObject( this );
2278 le
.m_itemIndex
= itemEdit
;
2280 GetItem( le
.m_item
);
2281 HandleWindowEvent( le
);
2284 // ----------------------------------------------------------------------------
2285 // virtual list controls
2286 // ----------------------------------------------------------------------------
2288 wxString
wxListCtrl::OnGetItemText(long WXUNUSED(item
), long WXUNUSED(col
)) const
2290 // this is a pure virtual function, in fact - which is not really pure
2291 // because the controls which are not virtual don't need to implement it
2292 wxFAIL_MSG( _T("wxListCtrl::OnGetItemText not supposed to be called") );
2294 return wxEmptyString
;
2297 int wxListCtrl::OnGetItemImage(long WXUNUSED(item
)) const
2299 wxCHECK_MSG(!GetImageList(wxIMAGE_LIST_SMALL
),
2301 wxT("List control has an image list, OnGetItemImage or OnGetItemColumnImage should be overridden."));
2305 int wxListCtrl::OnGetItemColumnImage(long item
, long column
) const
2308 return OnGetItemImage(item
);
2313 wxListItemAttr
*wxListCtrl::OnGetItemAttr(long WXUNUSED_UNLESS_DEBUG(item
)) const
2315 wxASSERT_MSG( item
>= 0 && item
< GetItemCount(),
2316 _T("invalid item index in OnGetItemAttr()") );
2318 // no attributes by default
2322 void wxListCtrl::SetItemCount(long count
)
2324 wxASSERT_MSG( IsVirtual(), _T("this is for virtual controls only") );
2328 m_genericImpl
->SetItemCount(count
);
2334 // we need to temporarily disable the new item creation notification
2335 // procedure to speed things up
2336 // FIXME: Even this doesn't seem to help much...
2338 // FIXME: Find a more efficient way to do this.
2339 m_dbImpl
->MacClear();
2341 DataBrowserCallbacks callbacks
;
2342 DataBrowserItemNotificationUPP itemUPP
;
2343 GetDataBrowserCallbacks(m_dbImpl
->GetControlRef(), &callbacks
);
2344 itemUPP
= callbacks
.u
.v1
.itemNotificationCallback
;
2345 callbacks
.u
.v1
.itemNotificationCallback
= 0;
2346 m_dbImpl
->SetCallbacks(&callbacks
);
2347 ::AddDataBrowserItems(m_dbImpl
->GetControlRef(), kDataBrowserNoItem
,
2348 count
, NULL
, kDataBrowserItemNoProperty
);
2349 callbacks
.u
.v1
.itemNotificationCallback
= itemUPP
;
2350 m_dbImpl
->SetCallbacks(&callbacks
);
2355 void wxListCtrl::RefreshItem(long item
)
2359 m_genericImpl
->RefreshItem(item
);
2365 DataBrowserItemID id
;
2369 wxMacDataItem
* thisItem
= m_dbImpl
->GetItemFromLine(item
);
2370 id
= (DataBrowserItemID
) thisItem
;
2375 m_dbImpl
->wxMacDataBrowserControl::UpdateItems
2379 kDataBrowserItemNoProperty
, // preSortProperty
2380 kDataBrowserNoItem
// update all columns
2385 void wxListCtrl::RefreshItems(long itemFrom
, long itemTo
)
2389 m_genericImpl
->RefreshItems(itemFrom
, itemTo
);
2395 const long count
= itemTo
- itemFrom
+ 1;
2396 DataBrowserItemID
*ids
= new DataBrowserItemID
[count
];
2400 for ( long i
= 0; i
< count
; i
++ )
2402 wxMacDataItem
* thisItem
= m_dbImpl
->GetItemFromLine(itemFrom
+i
);
2403 ids
[i
] = (DataBrowserItemID
) thisItem
;
2408 for ( long i
= 0; i
< count
; i
++ )
2409 ids
[i
] = itemFrom
+i
+1;
2412 m_dbImpl
->wxMacDataBrowserControl::UpdateItems
2416 kDataBrowserItemNoProperty
, // preSortProperty
2417 kDataBrowserNoItem
// update all columns
2424 void wxListCtrl::SetDropTarget( wxDropTarget
*dropTarget
)
2426 #if wxUSE_DRAG_AND_DROP
2428 m_genericImpl
->SetDropTarget( dropTarget
);
2431 wxWindow::SetDropTarget( dropTarget
);
2435 wxDropTarget
*wxListCtrl::GetDropTarget() const
2437 #if wxUSE_DRAG_AND_DROP
2439 return m_genericImpl
->GetDropTarget();
2442 return wxWindow::GetDropTarget();
2447 #if wxABI_VERSION >= 20801
2448 void wxListCtrl::SetFocus()
2452 m_genericImpl
->SetFocus();
2456 wxWindow::SetFocus();
2460 // wxMac internal data structures
2462 wxMacListCtrlItem::~wxMacListCtrlItem()
2464 WX_CLEAR_HASH_MAP( wxListItemList
, m_rowItems
);
2467 void wxMacListCtrlItem::Notification(wxMacDataItemBrowserControl
*owner
,
2468 DataBrowserItemNotification message
,
2469 DataBrowserItemDataRef
WXUNUSED(itemData
) ) const
2472 wxMacDataBrowserListCtrlControl
*lb
= wxDynamicCast(owner
, wxMacDataBrowserListCtrlControl
);
2474 // we want to depend on as little as possible to make sure tear-down of controls is safe
2475 if ( message
== kDataBrowserItemRemoved
)
2480 else if ( message
== kDataBrowserItemAdded
)
2482 // we don't issue events on adding, the item is not really stored in the list yet, so we
2483 // avoid asserts by gettting out now
2487 wxListCtrl
*list
= wxDynamicCast( owner
->GetWXPeer() , wxListCtrl
);
2490 bool trigger
= false;
2492 wxListEvent
event( wxEVT_COMMAND_LIST_ITEM_SELECTED
, list
->GetId() );
2493 bool isSingle
= (list
->GetWindowStyle() & wxLC_SINGLE_SEL
) != 0;
2495 event
.SetEventObject( list
);
2496 event
.m_itemIndex
= owner
->GetLineFromItem( this ) ;
2497 event
.m_item
.m_itemId
= event
.m_itemIndex
;
2498 list
->GetItem(event
.m_item
);
2502 case kDataBrowserItemDeselected
:
2503 event
.SetEventType(wxEVT_COMMAND_LIST_ITEM_DESELECTED
);
2505 trigger
= !lb
->IsSelectionSuppressed();
2508 case kDataBrowserItemSelected
:
2509 trigger
= !lb
->IsSelectionSuppressed();
2512 case kDataBrowserItemDoubleClicked
:
2513 event
.SetEventType( wxEVT_COMMAND_LIST_ITEM_ACTIVATED
);
2517 case kDataBrowserEditStarted
:
2518 // TODO : how to veto ?
2519 event
.SetEventType( wxEVT_COMMAND_LIST_BEGIN_LABEL_EDIT
) ;
2523 case kDataBrowserEditStopped
:
2524 // TODO probably trigger only upon the value store callback, because
2525 // here IIRC we cannot veto
2526 event
.SetEventType( wxEVT_COMMAND_LIST_END_LABEL_EDIT
) ;
2536 // direct notification is not always having the listbox GetSelection() having in synch with event
2537 wxPostEvent( list
->GetEventHandler(), event
);
2543 IMPLEMENT_DYNAMIC_CLASS(wxMacDataBrowserListCtrlControl
, wxMacDataItemBrowserControl
)
2545 wxMacDataBrowserListCtrlControl::wxMacDataBrowserListCtrlControl( wxWindow
*peer
, const wxPoint
& pos
, const wxSize
& size
, long style
)
2546 : wxMacDataItemBrowserControl( peer
, pos
, size
, style
)
2548 OSStatus err
= noErr
;
2549 m_clientDataItemsType
= wxClientData_None
;
2550 m_isVirtual
= false;
2553 if ( style
& wxLC_VIRTUAL
)
2556 DataBrowserSelectionFlags options
= kDataBrowserDragSelect
;
2557 if ( style
& wxLC_SINGLE_SEL
)
2559 options
|= kDataBrowserSelectOnlyOne
;
2563 options
|= kDataBrowserCmdTogglesSelection
;
2566 err
= SetSelectionFlags( options
);
2567 verify_noerr( err
);
2569 DataBrowserCustomCallbacks callbacks
;
2570 InitializeDataBrowserCustomCallbacks( &callbacks
, kDataBrowserLatestCustomCallbacks
);
2572 if ( gDataBrowserDrawItemUPP
== NULL
)
2573 gDataBrowserDrawItemUPP
= NewDataBrowserDrawItemUPP(DataBrowserDrawItemProc
);
2575 if ( gDataBrowserHitTestUPP
== NULL
)
2576 gDataBrowserHitTestUPP
= NewDataBrowserHitTestUPP(DataBrowserHitTestProc
);
2578 callbacks
.u
.v1
.drawItemCallback
= gDataBrowserDrawItemUPP
;
2579 callbacks
.u
.v1
.hitTestCallback
= gDataBrowserHitTestUPP
;
2581 SetDataBrowserCustomCallbacks( GetControlRef(), &callbacks
);
2583 if ( style
& wxLC_LIST
)
2585 InsertColumn(0, kDataBrowserIconAndTextType
, wxEmptyString
, -1, -1);
2586 verify_noerr( AutoSizeColumns() );
2589 if ( style
& wxLC_LIST
|| style
& wxLC_NO_HEADER
)
2590 verify_noerr( SetHeaderButtonHeight( 0 ) );
2593 SetSortProperty( kMinColumnId
- 1 );
2595 SetSortProperty( kMinColumnId
);
2597 m_sortOrder
= SortOrder_None
;
2599 if ( style
& wxLC_SORT_DESCENDING
)
2601 SetSortOrder( kDataBrowserOrderDecreasing
);
2603 else if ( style
& wxLC_SORT_ASCENDING
)
2605 SetSortOrder( kDataBrowserOrderIncreasing
);
2608 if ( style
& wxLC_VRULES
)
2610 verify_noerr( DataBrowserChangeAttributes(m_controlRef
, kDataBrowserAttributeListViewDrawColumnDividers
, kDataBrowserAttributeNone
) );
2613 verify_noerr( SetHiliteStyle(kDataBrowserTableViewFillHilite
) );
2614 verify_noerr( SetHasScrollBars( (style
& wxHSCROLL
) != 0 , true ) );
2617 pascal Boolean
wxMacDataBrowserListCtrlControl::DataBrowserEditTextProc(
2619 DataBrowserItemID itemID
,
2620 DataBrowserPropertyID property
,
2621 CFStringRef theString
,
2622 Rect
*maxEditTextRect
,
2623 Boolean
*shrinkToFit
)
2625 Boolean result
= false;
2626 wxMacDataBrowserListCtrlControl
* ctl
= wxDynamicCast(wxMacControl::GetReferenceFromNativeControl( browser
), wxMacDataBrowserListCtrlControl
);
2629 result
= ctl
->ConfirmEditText(itemID
, property
, theString
, maxEditTextRect
, shrinkToFit
);
2630 theString
= CFSTR("Hello!");
2635 bool wxMacDataBrowserListCtrlControl::ConfirmEditText(
2636 DataBrowserItemID
WXUNUSED(itemID
),
2637 DataBrowserPropertyID
WXUNUSED(property
),
2638 CFStringRef
WXUNUSED(theString
),
2639 Rect
*WXUNUSED(maxEditTextRect
),
2640 Boolean
*WXUNUSED(shrinkToFit
))
2645 pascal void wxMacDataBrowserListCtrlControl::DataBrowserDrawItemProc(
2647 DataBrowserItemID itemID
,
2648 DataBrowserPropertyID property
,
2649 DataBrowserItemState itemState
,
2650 const Rect
*itemRect
,
2652 Boolean colorDevice
)
2654 wxMacDataBrowserListCtrlControl
* ctl
= wxDynamicCast(wxMacControl::GetReferenceFromNativeControl( browser
), wxMacDataBrowserListCtrlControl
);
2657 ctl
->DrawItem(itemID
, property
, itemState
, itemRect
, gdDepth
, colorDevice
);
2661 // routines needed for DrawItem
2666 kTextBoxHeight
= 14,
2667 kIconTextSpacingV
= 2,
2669 kContentHeight
= kIconHeight
+ kTextBoxHeight
+ kIconTextSpacingV
2672 static void calculateCGDrawingBounds(CGRect inItemRect
, CGRect
*outIconRect
, CGRect
*outTextRect
, bool hasIcon
= false)
2675 float iconH
, iconW
= 0;
2676 float padding
= kItemPadding
;
2679 iconH
= kIconHeight
;
2681 padding
= padding
*2;
2684 textBottom
= inItemRect
.origin
.y
;
2686 *outIconRect
= CGRectMake(inItemRect
.origin
.x
+ kItemPadding
,
2687 textBottom
+ kIconTextSpacingV
, kIconWidth
,
2690 *outTextRect
= CGRectMake(inItemRect
.origin
.x
+ padding
+ iconW
,
2691 textBottom
+ kIconTextSpacingV
, inItemRect
.size
.width
- padding
- iconW
,
2692 inItemRect
.size
.height
- kIconTextSpacingV
);
2695 void wxMacDataBrowserListCtrlControl::DrawItem(
2696 DataBrowserItemID itemID
,
2697 DataBrowserPropertyID property
,
2698 DataBrowserItemState itemState
,
2699 const Rect
*WXUNUSED(itemRect
),
2701 Boolean colorDevice
)
2704 wxFont font
= wxNullFont
;
2707 DataBrowserTableViewColumnIndex listColumn
= 0;
2708 GetColumnPosition( property
, &listColumn
);
2710 wxListCtrl
* list
= wxDynamicCast( GetWXPeer() , wxListCtrl
);
2711 wxMacListCtrlItem
* lcItem
;
2712 wxColour color
= *wxBLACK
;
2713 wxColour bgColor
= wxNullColour
;
2715 if (listColumn
>= 0)
2719 lcItem
= (wxMacListCtrlItem
*) itemID
;
2720 if (lcItem
->HasColumnInfo(listColumn
))
2722 wxListItem
* item
= lcItem
->GetColumnInfo(listColumn
);
2724 // we always use the 0 column to get font and text/background colors.
2725 if (lcItem
->HasColumnInfo(0))
2727 wxListItem
* firstItem
= lcItem
->GetColumnInfo(0);
2728 color
= firstItem
->GetTextColour();
2729 bgColor
= firstItem
->GetBackgroundColour();
2730 font
= firstItem
->GetFont();
2733 if (item
->GetMask() & wxLIST_MASK_TEXT
)
2734 text
= item
->GetText();
2735 if (item
->GetMask() & wxLIST_MASK_IMAGE
)
2736 imgIndex
= item
->GetImage();
2742 long itemNum
= (long)itemID
-1;
2743 if (itemNum
>= 0 && itemNum
< list
->GetItemCount())
2745 text
= list
->OnGetItemText( itemNum
, listColumn
);
2746 imgIndex
= list
->OnGetItemColumnImage( itemNum
, listColumn
);
2747 wxListItemAttr
* attrs
= list
->OnGetItemAttr( itemNum
);
2750 if (attrs
->HasBackgroundColour())
2751 bgColor
= attrs
->GetBackgroundColour();
2752 if (attrs
->HasTextColour())
2753 color
= attrs
->GetTextColour();
2754 if (attrs
->HasFont())
2755 font
= attrs
->GetFont();
2761 wxColour listBgColor
= list
->GetBackgroundColour();
2762 if (bgColor
== wxNullColour
)
2763 bgColor
= listBgColor
;
2766 font
= list
->GetFont();
2768 wxCFStringRef
cfString( text
, wxLocale::GetSystemEncoding() );
2771 CGRect enclosingCGRect
, iconCGRect
, textCGRect
;
2773 ThemeDrawingState savedState
= NULL
;
2774 CGContextRef context
= (CGContextRef
)list
->MacGetDrawingContext();
2775 RGBColor labelColor
;
2777 labelColor
.green
= 0;
2778 labelColor
.blue
= 0;
2780 RGBColor backgroundColor
;
2781 backgroundColor
.red
= 255;
2782 backgroundColor
.green
= 255;
2783 backgroundColor
.blue
= 255;
2785 GetDataBrowserItemPartBounds(GetControlRef(), itemID
, property
, kDataBrowserPropertyEnclosingPart
,
2788 enclosingCGRect
= CGRectMake(enclosingRect
.left
,
2790 enclosingRect
.right
- enclosingRect
.left
,
2791 enclosingRect
.bottom
- enclosingRect
.top
);
2793 bool hasFocus
= (wxWindow::FindFocus() == list
);
2794 active
= IsControlActive(GetControlRef());
2796 // don't paint the background over the vertical rule line
2797 if ( list
->GetWindowStyleFlag() & wxLC_VRULES
)
2799 enclosingCGRect
.origin
.x
+= 1;
2800 enclosingCGRect
.size
.width
-= 1;
2802 if (itemState
== kDataBrowserItemIsSelected
)
2805 GetThemeDrawingState(&savedState
);
2807 if (active
&& hasFocus
)
2809 GetThemeBrushAsColor(kThemeBrushAlternatePrimaryHighlightColor
, 32, true, &backgroundColor
);
2810 GetThemeTextColor(kThemeTextColorWhite
, gdDepth
, colorDevice
, &labelColor
);
2814 GetThemeBrushAsColor(kThemeBrushSecondaryHighlightColor
, 32, true, &backgroundColor
);
2815 GetThemeTextColor(kThemeTextColorBlack
, gdDepth
, colorDevice
, &labelColor
);
2817 CGContextSaveGState(context
);
2819 CGContextSetRGBFillColor(context
, (CGFloat
)backgroundColor
.red
/ (CGFloat
)USHRT_MAX
,
2820 (CGFloat
)backgroundColor
.green
/ (CGFloat
)USHRT_MAX
,
2821 (CGFloat
)backgroundColor
.blue
/ (CGFloat
)USHRT_MAX
, (CGFloat
) 1.0);
2822 CGContextFillRect(context
, enclosingCGRect
);
2824 CGContextRestoreGState(context
);
2830 color
.GetRGBColor(&labelColor
);
2831 else if (list
->GetTextColour().Ok())
2832 list
->GetTextColour().GetRGBColor(&labelColor
);
2836 bgColor
.GetRGBColor(&backgroundColor
);
2837 CGContextSaveGState(context
);
2839 CGContextSetRGBFillColor(context
, (CGFloat
)backgroundColor
.red
/ (CGFloat
)USHRT_MAX
,
2840 (CGFloat
)backgroundColor
.green
/ (CGFloat
)USHRT_MAX
,
2841 (CGFloat
)backgroundColor
.blue
/ (CGFloat
)USHRT_MAX
, (CGFloat
) 1.0);
2842 CGContextFillRect(context
, enclosingCGRect
);
2844 CGContextRestoreGState(context
);
2848 calculateCGDrawingBounds(enclosingCGRect
, &iconCGRect
, &textCGRect
, (imgIndex
!= -1) );
2852 wxImageList
* imageList
= list
->GetImageList(wxIMAGE_LIST_SMALL
);
2853 if (imageList
&& imageList
->GetImageCount() > 0){
2854 wxBitmap bmp
= imageList
->GetBitmap(imgIndex
);
2855 IconRef icon
= bmp
.GetIconRef();
2857 CGContextSaveGState(context
);
2858 CGContextTranslateCTM(context
, 0,iconCGRect
.origin
.y
+ CGRectGetMaxY(iconCGRect
));
2859 CGContextScaleCTM(context
,1.0f
,-1.0f
);
2860 PlotIconRefInContext(context
, &iconCGRect
, kAlignNone
,
2861 active
? kTransformNone
: kTransformDisabled
, NULL
,
2862 kPlotIconRefNormalFlags
, icon
);
2864 CGContextRestoreGState(context
);
2868 HIThemeTextHorizontalFlush hFlush
= kHIThemeTextHorizontalFlushLeft
;
2869 HIThemeTextInfo info
;
2871 #if wxOSX_USE_CORE_TEXT
2872 if ( UMAGetSystemVersion() >= 0x1050 )
2874 info
.version
= kHIThemeTextInfoVersionOne
;
2875 info
.fontID
= kThemeViewsFont
;
2878 info
.fontID
= kThemeSpecifiedFont
;
2879 info
.font
= (CTFontRef
) font
.OSXGetCTFont();
2884 #if wxOSX_USE_ATSU_TEXT
2887 info
.version
= kHIThemeTextInfoVersionZero
;
2888 info
.fontID
= kThemeViewsFont
;
2892 info
.fontID
= font
.MacGetThemeFontID();
2894 ::TextSize( (short)(font
.GetPointSize()) ) ;
2895 ::TextFace( font
.MacGetFontStyle() ) ;
2901 list
->GetColumn(listColumn
, item
);
2902 if (item
.GetMask() & wxLIST_MASK_FORMAT
)
2904 if (item
.GetAlign() == wxLIST_FORMAT_LEFT
)
2905 hFlush
= kHIThemeTextHorizontalFlushLeft
;
2906 else if (item
.GetAlign() == wxLIST_FORMAT_CENTER
)
2907 hFlush
= kHIThemeTextHorizontalFlushCenter
;
2908 else if (item
.GetAlign() == wxLIST_FORMAT_RIGHT
)
2910 hFlush
= kHIThemeTextHorizontalFlushRight
;
2911 textCGRect
.origin
.x
-= kItemPadding
; // give a little extra paddding
2915 info
.state
= active
? kThemeStateActive
: kThemeStateInactive
;
2916 info
.horizontalFlushness
= hFlush
;
2917 info
.verticalFlushness
= kHIThemeTextVerticalFlushCenter
;
2918 info
.options
= kHIThemeTextBoxOptionNone
;
2919 info
.truncationPosition
= kHIThemeTextTruncationEnd
;
2920 info
.truncationMaxLines
= 1;
2922 CGContextSaveGState(context
);
2923 CGContextSetRGBFillColor (context
, (CGFloat
)labelColor
.red
/ (CGFloat
)USHRT_MAX
,
2924 (CGFloat
)labelColor
.green
/ (CGFloat
)USHRT_MAX
,
2925 (CGFloat
)labelColor
.blue
/ (CGFloat
)USHRT_MAX
, (CGFloat
) 1.0);
2927 HIThemeDrawTextBox(cfString
, &textCGRect
, &info
, context
, kHIThemeOrientationNormal
);
2929 CGContextRestoreGState(context
);
2932 if (savedState
!= NULL
)
2933 SetThemeDrawingState(savedState
, true);
2937 OSStatus
wxMacDataBrowserListCtrlControl::GetSetItemData(DataBrowserItemID itemID
,
2938 DataBrowserPropertyID property
,
2939 DataBrowserItemDataRef itemData
,
2940 Boolean changeValue
)
2945 DataBrowserTableViewColumnIndex listColumn
= 0;
2946 verify_noerr( GetColumnPosition( property
, &listColumn
) );
2948 OSStatus err
= errDataBrowserPropertyNotSupported
;
2949 wxListCtrl
* list
= wxDynamicCast( GetWXPeer() , wxListCtrl
);
2950 wxMacListCtrlItem
* lcItem
= NULL
;
2952 if (listColumn
>= 0)
2956 lcItem
= (wxMacListCtrlItem
*) itemID
;
2957 if (lcItem
&& lcItem
->HasColumnInfo(listColumn
)){
2958 wxListItem
* item
= lcItem
->GetColumnInfo(listColumn
);
2959 if (item
->GetMask() & wxLIST_MASK_TEXT
)
2960 text
= item
->GetText();
2961 if (item
->GetMask() & wxLIST_MASK_IMAGE
)
2962 imgIndex
= item
->GetImage();
2967 long itemNum
= (long)itemID
-1;
2968 if (itemNum
>= 0 && itemNum
< list
->GetItemCount())
2970 text
= list
->OnGetItemText( itemNum
, listColumn
);
2971 imgIndex
= list
->OnGetItemColumnImage( itemNum
, listColumn
);
2980 case kDataBrowserItemIsEditableProperty
:
2981 if ( list
&& list
->HasFlag( wxLC_EDIT_LABELS
) )
2983 verify_noerr(SetDataBrowserItemDataBooleanValue( itemData
, true ));
2988 if ( property
>= kMinColumnId
)
2990 if (!text
.IsEmpty()){
2991 wxCFStringRef
cfStr( text
, wxLocale::GetSystemEncoding() );
2992 err
= ::SetDataBrowserItemDataText( itemData
, cfStr
);
2998 if ( imgIndex
!= -1 )
3000 wxImageList
* imageList
= list
->GetImageList(wxIMAGE_LIST_SMALL
);
3001 if (imageList
&& imageList
->GetImageCount() > 0){
3002 wxBitmap bmp
= imageList
->GetBitmap(imgIndex
);
3003 IconRef icon
= bmp
.GetIconRef();
3004 ::SetDataBrowserItemDataIcon(itemData
, icon
);
3018 if ( property
>= kMinColumnId
)
3020 DataBrowserTableViewColumnIndex listColumn
= 0;
3021 verify_noerr( GetColumnPosition( property
, &listColumn
) );
3023 // TODO probably send the 'end edit' from here, as we
3024 // can then deal with the veto
3026 verify_noerr( GetDataBrowserItemDataText( itemData
, &sr
) ) ;
3027 wxCFStringRef
cfStr(sr
) ;;
3029 list
->SetItem( (long)itemData
-1 , listColumn
, cfStr
.AsString() ) ;
3033 lcItem
->SetColumnTextValue( listColumn
, cfStr
.AsString() );
3043 void wxMacDataBrowserListCtrlControl::ItemNotification(DataBrowserItemID itemID
,
3044 DataBrowserItemNotification message
,
3045 DataBrowserItemDataRef itemData
)
3047 wxMacListCtrlItem
*item
= NULL
;
3050 item
= (wxMacListCtrlItem
*) itemID
;
3053 // we want to depend on as little as possible to make sure tear-down of controls is safe
3054 if ( message
== kDataBrowserItemRemoved
)
3057 item
->Notification(this, message
, itemData
);
3060 else if ( message
== kDataBrowserItemAdded
)
3062 // we don't issue events on adding, the item is not really stored in the list yet, so we
3063 // avoid asserts by getting out now
3065 item
->Notification(this, message
, itemData
);
3069 wxListCtrl
*list
= wxDynamicCast( GetWXPeer() , wxListCtrl
);
3072 bool trigger
= false;
3074 wxListEvent
event( wxEVT_COMMAND_LIST_ITEM_SELECTED
, list
->GetId() );
3076 event
.SetEventObject( list
);
3077 if ( !list
->IsVirtual() )
3079 DataBrowserTableViewRowIndex result
= 0;
3080 verify_noerr( GetItemRow( itemID
, &result
) ) ;
3081 event
.m_itemIndex
= result
;
3085 event
.m_itemIndex
= (long)itemID
-1;
3087 event
.m_item
.m_itemId
= event
.m_itemIndex
;
3088 list
->GetItem(event
.m_item
);
3092 case kDataBrowserItemDeselected
:
3093 event
.SetEventType(wxEVT_COMMAND_LIST_ITEM_DESELECTED
);
3094 // as the generic implementation is also triggering this
3095 // event for single selection, we do the same (different than listbox)
3096 trigger
= !IsSelectionSuppressed();
3099 case kDataBrowserItemSelected
:
3100 trigger
= !IsSelectionSuppressed();
3104 case kDataBrowserItemDoubleClicked
:
3105 event
.SetEventType( wxEVT_COMMAND_LIST_ITEM_ACTIVATED
);
3109 case kDataBrowserEditStarted
:
3110 // TODO : how to veto ?
3111 event
.SetEventType( wxEVT_COMMAND_LIST_BEGIN_LABEL_EDIT
) ;
3115 case kDataBrowserEditStopped
:
3116 // TODO probably trigger only upon the value store callback, because
3117 // here IIRC we cannot veto
3118 event
.SetEventType( wxEVT_COMMAND_LIST_END_LABEL_EDIT
) ;
3128 // direct notification is not always having the listbox GetSelection() having in synch with event
3129 wxPostEvent( list
->GetEventHandler(), event
);
3134 Boolean
wxMacDataBrowserListCtrlControl::CompareItems(DataBrowserItemID itemOneID
,
3135 DataBrowserItemID itemTwoID
,
3136 DataBrowserPropertyID sortProperty
)
3139 bool retval
= false;
3141 wxString otherItemText
;
3143 long otherItemOrder
;
3145 DataBrowserTableViewColumnIndex colId
= 0;
3146 verify_noerr( GetColumnPosition( sortProperty
, &colId
) );
3148 wxListCtrl
* list
= wxDynamicCast( GetWXPeer() , wxListCtrl
);
3150 DataBrowserSortOrder sort
;
3151 verify_noerr(GetSortOrder(&sort
));
3157 wxMacListCtrlItem
* item
= (wxMacListCtrlItem
*)itemOneID
;
3158 wxMacListCtrlItem
* otherItem
= (wxMacListCtrlItem
*)itemTwoID
;
3160 itemOrder
= item
->GetOrder();
3161 otherItemOrder
= otherItem
->GetOrder();
3163 wxListCtrlCompare func
= list
->GetCompareFunc();
3169 if (item
&& item
->HasColumnInfo(0))
3170 item1
= item
->GetColumnInfo(0)->GetData();
3171 if (otherItem
&& otherItem
->HasColumnInfo(0))
3172 item2
= otherItem
->GetColumnInfo(0)->GetData();
3174 if (item1
> -1 && item2
> -1)
3176 int result
= func(item1
, item2
, list
->GetCompareFuncData());
3177 if (sort
== kDataBrowserOrderIncreasing
)
3184 // we can't use the native control's sorting abilities, so just
3186 return itemOrder
< otherItemOrder
;
3191 long itemNum
= (long)itemOneID
;
3192 long otherItemNum
= (long)itemTwoID
;
3194 // virtual listctrls don't support sorting
3195 return itemNum
< otherItemNum
;
3199 // fallback for undefined cases
3200 retval
= itemOneID
< itemTwoID
;
3206 wxMacDataBrowserListCtrlControl::~wxMacDataBrowserListCtrlControl()
3210 void wxMacDataBrowserListCtrlControl::MacSetColumnInfo( unsigned int row
, unsigned int column
, wxListItem
* item
)
3212 wxMacDataItem
* dataItem
= GetItemFromLine(row
);
3213 wxASSERT_MSG( dataItem
, _T("could not obtain wxMacDataItem for row in MacSetColumnInfo. Is row a valid wxListCtrl row?") );
3216 wxMacListCtrlItem
* listItem
= static_cast<wxMacListCtrlItem
*>(dataItem
);
3217 bool hasInfo
= listItem
->HasColumnInfo( column
);
3218 listItem
->SetColumnInfo( column
, item
);
3219 listItem
->SetOrder(row
);
3220 UpdateState(dataItem
, item
);
3222 wxListCtrl
* list
= wxDynamicCast( GetWXPeer() , wxListCtrl
);
3224 // NB: When this call was made before a control was completely shown, it would
3225 // update the item prematurely (i.e. no text would be listed) and, on show,
3226 // only the sorted column would be refreshed, meaning only first column text labels
3227 // would be shown. Making sure not to update items until the control is visible
3228 // seems to fix this issue.
3229 if (hasInfo
&& list
->IsShown())
3231 DataBrowserTableViewColumnID id
= 0;
3232 verify_noerr( GetColumnIDFromIndex( column
, &id
) );
3233 UpdateItem( wxMacDataBrowserRootContainer
, listItem
, id
);
3238 // apply changes that need to happen immediately, rather than when the
3239 // databrowser control fires a callback.
3240 void wxMacDataBrowserListCtrlControl::UpdateState(wxMacDataItem
* dataItem
, wxListItem
* listItem
)
3242 bool isSelected
= IsItemSelected( dataItem
);
3243 bool isSelectedState
= (listItem
->GetState() == wxLIST_STATE_SELECTED
);
3245 // toggle the selection state if wxListInfo state and actual state don't match.
3246 if ( listItem
->GetMask() & wxLIST_MASK_STATE
&& isSelected
!= isSelectedState
)
3248 DataBrowserSetOption options
= kDataBrowserItemsAdd
;
3249 if (!isSelectedState
)
3250 options
= kDataBrowserItemsRemove
;
3251 SetSelectedItem(dataItem
, options
);
3253 // TODO: Set column width if item width > than current column width
3256 void wxMacDataBrowserListCtrlControl::MacGetColumnInfo( unsigned int row
, unsigned int column
, wxListItem
& item
)
3258 wxMacDataItem
* dataItem
= GetItemFromLine(row
);
3259 wxASSERT_MSG( dataItem
, _T("could not obtain wxMacDataItem in MacGetColumnInfo. Is row a valid wxListCtrl row?") );
3260 // CS should this guard against dataItem = 0 ? , as item is not a pointer if (item) is not appropriate
3263 wxMacListCtrlItem
* listItem
= static_cast<wxMacListCtrlItem
*>(dataItem
);
3265 if (!listItem
->HasColumnInfo( column
))
3268 wxListItem
* oldItem
= listItem
->GetColumnInfo( column
);
3272 long mask
= item
.GetMask();
3274 // by default, get everything for backwards compatibility
3277 if ( mask
& wxLIST_MASK_TEXT
)
3278 item
.SetText(oldItem
->GetText());
3279 if ( mask
& wxLIST_MASK_IMAGE
)
3280 item
.SetImage(oldItem
->GetImage());
3281 if ( mask
& wxLIST_MASK_DATA
)
3282 item
.SetData(oldItem
->GetData());
3283 if ( mask
& wxLIST_MASK_STATE
)
3284 item
.SetState(oldItem
->GetState());
3285 if ( mask
& wxLIST_MASK_WIDTH
)
3286 item
.SetWidth(oldItem
->GetWidth());
3287 if ( mask
& wxLIST_MASK_FORMAT
)
3288 item
.SetAlign(oldItem
->GetAlign());
3290 item
.SetTextColour(oldItem
->GetTextColour());
3291 item
.SetBackgroundColour(oldItem
->GetBackgroundColour());
3292 item
.SetFont(oldItem
->GetFont());
3297 void wxMacDataBrowserListCtrlControl::MacInsertItem( unsigned int n
, wxListItem
* item
)
3300 wxMacDataItemBrowserControl::MacInsert(n
, new wxMacListCtrlItem() );
3301 MacSetColumnInfo(n
, 0, item
);
3304 wxMacListCtrlItem::wxMacListCtrlItem()
3306 m_rowItems
= wxListItemList();
3309 int wxMacListCtrlItem::GetColumnImageValue( unsigned int column
)
3311 if ( HasColumnInfo(column
) )
3312 return GetColumnInfo(column
)->GetImage();
3317 void wxMacListCtrlItem::SetColumnImageValue( unsigned int column
, int imageIndex
)
3319 if ( HasColumnInfo(column
) )
3320 GetColumnInfo(column
)->SetImage(imageIndex
);
3323 wxString
wxMacListCtrlItem::GetColumnTextValue( unsigned int column
)
3325 /* TODO CHECK REMOVE
3329 if ( HasColumnInfo(column
) )
3330 return GetColumnInfo(column
)->GetText();
3332 return wxEmptyString
;
3335 void wxMacListCtrlItem::SetColumnTextValue( unsigned int column
, const wxString
& text
)
3337 if ( HasColumnInfo(column
) )
3338 GetColumnInfo(column
)->SetText(text
);
3340 /* TODO CHECK REMOVE
3341 // for compatibility with superclass APIs
3347 wxListItem
* wxMacListCtrlItem::GetColumnInfo( unsigned int column
)
3349 wxASSERT_MSG( HasColumnInfo(column
), _T("invalid column index in wxMacListCtrlItem") );
3350 return m_rowItems
[column
];
3353 bool wxMacListCtrlItem::HasColumnInfo( unsigned int column
)
3355 return !(m_rowItems
.find( column
) == m_rowItems
.end());
3358 void wxMacListCtrlItem::SetColumnInfo( unsigned int column
, wxListItem
* item
)
3361 if ( !HasColumnInfo(column
) )
3363 wxListItem
* listItem
= new wxListItem(*item
);
3364 m_rowItems
[column
] = listItem
;
3368 wxListItem
* listItem
= GetColumnInfo( column
);
3369 long mask
= item
->GetMask();
3370 if (mask
& wxLIST_MASK_TEXT
)
3371 listItem
->SetText(item
->GetText());
3372 if (mask
& wxLIST_MASK_DATA
)
3373 listItem
->SetData(item
->GetData());
3374 if (mask
& wxLIST_MASK_IMAGE
)
3375 listItem
->SetImage(item
->GetImage());
3376 if (mask
& wxLIST_MASK_STATE
)
3377 listItem
->SetState(item
->GetState());
3378 if (mask
& wxLIST_MASK_FORMAT
)
3379 listItem
->SetAlign(item
->GetAlign());
3380 if (mask
& wxLIST_MASK_WIDTH
)
3381 listItem
->SetWidth(item
->GetWidth());
3383 if ( item
->HasAttributes() )
3385 if ( listItem
->HasAttributes() )
3386 listItem
->GetAttributes()->AssignFrom(*item
->GetAttributes());
3389 listItem
->SetTextColour(item
->GetTextColour());
3390 listItem
->SetBackgroundColour(item
->GetBackgroundColour());
3391 listItem
->SetFont(item
->GetFont());
3397 int wxListCtrl::CalcColumnAutoWidth(int col
) const
3401 for ( int i
= 0; i
< GetItemCount(); i
++ )
3404 info
.SetMask(wxLIST_MASK_TEXT
| wxLIST_MASK_IMAGE
);
3406 info
.SetColumn(col
);
3409 const wxFont font
= info
.GetFont();
3413 GetTextExtent(info
.GetText(), &w
, NULL
, NULL
, NULL
, &font
);
3415 GetTextExtent(info
.GetText(), &w
, NULL
);
3417 w
+= 2 * kItemPadding
;
3419 if ( info
.GetImage() != -1 )
3422 width
= wxMax(width
, w
);
3428 #endif // wxUSE_LISTCTRL