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 (a 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() + wxT("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 // ============================================================================
524 // ============================================================================
526 wxMacDataBrowserListCtrlControl
* wxListCtrl::GetListPeer() const
528 return dynamic_cast<wxMacDataBrowserListCtrlControl
*> ( GetPeer() );
531 // ----------------------------------------------------------------------------
532 // wxListCtrl construction
533 // ----------------------------------------------------------------------------
535 void wxListCtrl::Init()
537 m_imageListNormal
= NULL
;
538 m_imageListSmall
= NULL
;
539 m_imageListState
= NULL
;
541 // keep track of if we created our own image lists, or if they were assigned
543 m_ownsImageListNormal
= m_ownsImageListSmall
= m_ownsImageListState
= false;
547 m_genericImpl
= NULL
;
549 m_compareFunc
= NULL
;
550 m_compareFuncData
= 0;
551 m_colsInfo
= wxColumnList();
552 m_textColor
= wxNullColour
;
553 m_bgColor
= wxNullColour
;
554 m_textctrlWrapper
= NULL
;
556 m_renameTimer
= NULL
;
559 class wxGenericListCtrlHook
: public wxGenericListCtrl
562 wxGenericListCtrlHook(wxListCtrl
* parent
,
567 const wxValidator
& validator
,
568 const wxString
& name
)
569 : wxGenericListCtrl(parent
, id
, pos
, size
, style
, validator
, name
),
570 m_nativeListCtrl(parent
)
575 virtual wxListItemAttr
* OnGetItemAttr(long item
) const
577 return m_nativeListCtrl
->OnGetItemAttr(item
);
580 virtual int OnGetItemImage(long item
) const
582 return m_nativeListCtrl
->OnGetItemImage(item
);
585 virtual int OnGetItemColumnImage(long item
, long column
) const
587 return m_nativeListCtrl
->OnGetItemColumnImage(item
, column
);
590 virtual wxString
OnGetItemText(long item
, long column
) const
592 return m_nativeListCtrl
->OnGetItemText(item
, column
);
595 wxListCtrl
* m_nativeListCtrl
;
599 void wxListCtrl::OnLeftDown(wxMouseEvent
& event
)
601 if ( m_textctrlWrapper
)
604 m_textctrlWrapper
->AcceptChangesAndFinish();
608 long current
= HitTest(event
.GetPosition(), hitResult
);
609 if ((current
== m_current
) &&
610 (hitResult
& wxLIST_HITTEST_ONITEMLABEL
) &&
611 HasFlag(wxLC_EDIT_LABELS
) )
614 m_renameTimer
->Start( 250, true );
623 void wxListCtrl::OnDblClick(wxMouseEvent
& event
)
625 if ( m_renameTimer
&& m_renameTimer
->IsRunning() )
626 m_renameTimer
->Stop();
630 #if wxABI_VERSION >= 20801
631 void wxListCtrl::OnRightDown(wxMouseEvent
& event
)
634 FireMouseEvent(wxEVT_COMMAND_LIST_ITEM_RIGHT_CLICK
, event
.GetPosition());
638 void wxListCtrl::OnMiddleDown(wxMouseEvent
& event
)
641 FireMouseEvent(wxEVT_COMMAND_LIST_ITEM_MIDDLE_CLICK
, event
.GetPosition());
645 void wxListCtrl::FireMouseEvent(wxEventType eventType
, wxPoint position
)
647 wxListEvent
le( eventType
, GetId() );
648 le
.SetEventObject(this);
649 le
.m_pointDrag
= position
;
653 long item
= HitTest(position
, flags
);
654 if (flags
& wxLIST_HITTEST_ONITEM
)
656 le
.m_itemIndex
= item
;
657 le
.m_item
.m_itemId
= item
;
659 HandleWindowEvent(le
);
663 void wxListCtrl::OnChar(wxKeyEvent
& event
)
669 wxListEvent
le( wxEVT_COMMAND_LIST_KEY_DOWN
, GetId() );
670 le
.SetEventObject(this);
671 le
.m_code
= event
.GetKeyCode();
676 // if m_current isn't set, check if there's been a selection
677 // made before continuing
678 m_current
= GetNextItem(-1, wxLIST_NEXT_BELOW
, wxLIST_STATE_SELECTED
);
681 // We need to determine m_current ourselves when navigation keys
682 // are used. Note that PAGEUP and PAGEDOWN do not alter the current
683 // item on native Mac ListCtrl, so we only handle up and down keys.
684 switch ( event
.GetKeyCode() )
695 if ( m_current
< GetItemCount() - 1 )
698 m_current
= GetItemCount() - 1;
705 le
.m_itemIndex
= m_current
;
706 le
.m_item
.m_itemId
= m_current
;
708 HandleWindowEvent(le
);
715 bool wxListCtrl::Create(wxWindow
*parent
,
720 const wxValidator
& validator
,
721 const wxString
& name
)
724 // for now, we'll always use the generic list control for ICON and LIST views,
725 // because they dynamically change the number of columns on resize.
726 // Also, allow the user to set it to use the list ctrl as well.
727 if ( (wxSystemOptions::HasOption( wxMAC_ALWAYS_USE_GENERIC_LISTCTRL
)
728 && (wxSystemOptions::GetOptionInt( wxMAC_ALWAYS_USE_GENERIC_LISTCTRL
) == 1)) ||
729 (style
& wxLC_ICON
) || (style
& wxLC_SMALL_ICON
) || (style
& wxLC_LIST
) )
731 m_macIsUserPane
= true;
733 long paneStyle
= style
;
734 paneStyle
&= ~wxSIMPLE_BORDER
;
735 paneStyle
&= ~wxDOUBLE_BORDER
;
736 paneStyle
&= ~wxSUNKEN_BORDER
;
737 paneStyle
&= ~wxRAISED_BORDER
;
738 paneStyle
&= ~wxSTATIC_BORDER
;
739 if ( !wxWindow::Create(parent
, id
, pos
, size
, paneStyle
| wxNO_BORDER
, name
) )
742 // since the generic control is a child, make sure we position it at 0, 0
743 m_genericImpl
= new wxGenericListCtrlHook(this, id
, wxPoint(0, 0), size
, style
, validator
, name
);
744 m_genericImpl
->PushEventHandler( new wxMacListCtrlEventDelegate( this, GetId() ) );
750 m_macIsUserPane
= false;
751 if ( !wxWindow::Create(parent
, id
, pos
, size
, style
& ~(wxHSCROLL
| wxVSCROLL
), name
) )
753 m_dbImpl
= new wxMacDataBrowserListCtrlControl( this, pos
, size
, style
);
756 MacPostControlCreate( pos
, size
);
758 InstallControlEventHandler( m_peer
->GetControlRef() , GetwxMacListCtrlEventHandlerUPP(),
759 GetEventTypeCount(eventList
), eventList
, this,
760 (EventHandlerRef
*)&m_macListCtrlEventHandler
);
762 m_renameTimer
= new wxListCtrlRenameTimer( this );
764 Connect( wxID_ANY
, wxEVT_CHAR
, wxCharEventHandler(wxListCtrl::OnChar
), NULL
, this );
765 Connect( wxID_ANY
, wxEVT_LEFT_DOWN
, wxMouseEventHandler(wxListCtrl::OnLeftDown
), NULL
, this );
766 Connect( wxID_ANY
, wxEVT_LEFT_DCLICK
, wxMouseEventHandler(wxListCtrl::OnDblClick
), NULL
, this );
767 Connect( wxID_ANY
, wxEVT_MIDDLE_DOWN
, wxMouseEventHandler(wxListCtrl::OnMiddleDown
), NULL
, this );
768 Connect( wxID_ANY
, wxEVT_RIGHT_DOWN
, wxMouseEventHandler(wxListCtrl::OnRightDown
), NULL
, this );
774 wxListCtrl::~wxListCtrl()
778 m_genericImpl
->PopEventHandler(/* deleteHandler = */ true);
781 if (m_ownsImageListNormal
)
782 delete m_imageListNormal
;
783 if (m_ownsImageListSmall
)
784 delete m_imageListSmall
;
785 if (m_ownsImageListState
)
786 delete m_imageListState
;
788 delete m_renameTimer
;
790 WX_CLEAR_LIST(wxColumnList
, m_colsInfo
);
795 wxListCtrl::GetClassDefaultAttributes(wxWindowVariant
WXUNUSED(variant
))
797 wxVisualAttributes attr
;
799 attr
.colFg
= wxSystemSettings::GetColour( wxSYS_COLOUR_WINDOWTEXT
);
800 attr
.colBg
= wxSystemSettings::GetColour( wxSYS_COLOUR_LISTBOX
);
801 static wxFont font
= wxFont(wxOSX_SYSTEM_FONT_VIEWS
);
807 // ----------------------------------------------------------------------------
808 // set/get/change style
809 // ----------------------------------------------------------------------------
811 // Add or remove a single window style
812 void wxListCtrl::SetSingleStyle(long style
, bool add
)
814 long flag
= GetWindowStyleFlag();
816 // Get rid of conflicting styles
819 if ( style
& wxLC_MASK_TYPE
)
820 flag
= flag
& ~wxLC_MASK_TYPE
;
821 if ( style
& wxLC_MASK_ALIGN
)
822 flag
= flag
& ~wxLC_MASK_ALIGN
;
823 if ( style
& wxLC_MASK_SORT
)
824 flag
= flag
& ~wxLC_MASK_SORT
;
832 SetWindowStyleFlag(flag
);
835 // Set the whole window style
836 void wxListCtrl::SetWindowStyleFlag(long flag
)
838 if ( flag
!= m_windowStyle
)
840 m_windowStyle
= flag
;
844 m_genericImpl
->SetWindowStyleFlag(flag
);
851 void wxListCtrl::DoSetSize( int x
, int y
, int width
, int height
, int sizeFlags
)
853 wxControl::DoSetSize(x
, y
, width
, height
, sizeFlags
);
856 m_genericImpl
->SetSize(0, 0, width
, height
, sizeFlags
);
858 // determine if we need a horizontal scrollbar, and add it if so
862 for (int column
= 0; column
< GetColumnCount(); column
++)
864 totalWidth
+= m_dbImpl
->GetColumnWidth( column
);
867 if ( !(m_dbImpl
->GetFlags() & wxHSCROLL
) )
869 Boolean vertScrollBar
;
870 GetDataBrowserHasScrollBars( m_dbImpl
->GetControlRef(), NULL
, &vertScrollBar
);
871 if (totalWidth
> width
)
872 SetDataBrowserHasScrollBars( m_dbImpl
->GetControlRef(), true, vertScrollBar
);
874 SetDataBrowserHasScrollBars( m_dbImpl
->GetControlRef(), false, vertScrollBar
);
879 wxSize
wxListCtrl::DoGetBestSize() const
881 return wxWindow::DoGetBestSize();
884 bool wxListCtrl::SetFont(const wxFont
& font
)
887 rv
= wxControl::SetFont(font
);
889 rv
= m_genericImpl
->SetFont(font
);
893 bool wxListCtrl::SetForegroundColour(const wxColour
& colour
)
897 rv
= m_genericImpl
->SetForegroundColour(colour
);
899 SetTextColour(colour
);
903 bool wxListCtrl::SetBackgroundColour(const wxColour
& colour
)
907 rv
= m_genericImpl
->SetBackgroundColour(colour
);
913 wxColour
wxListCtrl::GetBackgroundColour() const
916 return m_genericImpl
->GetBackgroundColour();
923 void wxListCtrl::Freeze ()
926 m_genericImpl
->Freeze();
930 void wxListCtrl::Thaw ()
933 m_genericImpl
->Thaw();
937 void wxListCtrl::Update ()
940 m_genericImpl
->Update();
944 // ----------------------------------------------------------------------------
946 // ----------------------------------------------------------------------------
948 // Gets information about this column
949 bool wxListCtrl::GetColumn(int col
, wxListItem
& item
) const
952 return m_genericImpl
->GetColumn(col
, item
);
958 wxColumnList::compatibility_iterator node
= m_colsInfo
.Item( col
);
959 wxASSERT_MSG( node
, wxT("invalid column index in wxMacListCtrlItem") );
960 wxListItem
* column
= node
->GetData();
962 long mask
= column
->GetMask();
963 if (mask
& wxLIST_MASK_TEXT
)
964 item
.SetText(column
->GetText());
965 if (mask
& wxLIST_MASK_DATA
)
966 item
.SetData(column
->GetData());
967 if (mask
& wxLIST_MASK_IMAGE
)
968 item
.SetImage(column
->GetImage());
969 if (mask
& wxLIST_MASK_STATE
)
970 item
.SetState(column
->GetState());
971 if (mask
& wxLIST_MASK_FORMAT
)
972 item
.SetAlign(column
->GetAlign());
973 if (mask
& wxLIST_MASK_WIDTH
)
974 item
.SetWidth(column
->GetWidth());
980 // Sets information about this column
981 bool wxListCtrl::SetColumn(int col
, wxListItem
& item
)
984 return m_genericImpl
->SetColumn(col
, item
);
988 wxASSERT_MSG( col
< (int)m_colsInfo
.GetCount(), wxT("invalid column index in wxMacListCtrlItem") );
990 long mask
= item
.GetMask();
993 GetColumn( col
, listItem
);
995 if (mask
& wxLIST_MASK_TEXT
)
996 listItem
.SetText(item
.GetText());
997 if (mask
& wxLIST_MASK_DATA
)
998 listItem
.SetData(item
.GetData());
999 if (mask
& wxLIST_MASK_IMAGE
)
1000 listItem
.SetImage(item
.GetImage());
1001 if (mask
& wxLIST_MASK_STATE
)
1002 listItem
.SetState(item
.GetState());
1003 if (mask
& wxLIST_MASK_FORMAT
)
1004 listItem
.SetAlign(item
.GetAlign());
1005 if (mask
& wxLIST_MASK_WIDTH
)
1006 listItem
.SetWidth(item
.GetWidth());
1009 // change the appearance in the databrowser.
1010 DataBrowserListViewHeaderDesc columnDesc
;
1011 columnDesc
.version
=kDataBrowserListViewLatestHeaderDesc
;
1013 DataBrowserTableViewColumnID id
= 0;
1014 verify_noerr( m_dbImpl
->GetColumnIDFromIndex( col
, &id
) );
1015 verify_noerr( m_dbImpl
->GetHeaderDesc( id
, &columnDesc
) );
1018 if (item.GetMask() & wxLIST_MASK_TEXT)
1022 enc = GetFont().GetEncoding();
1024 enc = wxLocale::GetSystemEncoding();
1025 wxCFStringRef cfTitle;
1026 cfTitle.Assign( item.GetText() , enc );
1027 if(columnDesc.titleString)
1028 CFRelease(columnDesc.titleString);
1029 columnDesc.titleString = cfTitle;
1033 if (item
.GetMask() & wxLIST_MASK_IMAGE
&& item
.GetImage() != -1 )
1035 wxImageList
* imageList
= GetImageList(wxIMAGE_LIST_SMALL
);
1036 if (imageList
&& imageList
->GetImageCount() > 0 )
1038 wxBitmap bmp
= imageList
->GetBitmap( item
.GetImage() );
1039 IconRef icon
= bmp
.GetIconRef();
1040 columnDesc
.btnContentInfo
.u
.iconRef
= icon
;
1041 columnDesc
.btnContentInfo
.contentType
= kControlContentIconRef
;
1045 verify_noerr( m_dbImpl
->SetHeaderDesc( id
, &columnDesc
) );
1051 int wxListCtrl::GetColumnCount() const
1054 return m_genericImpl
->GetColumnCount();
1059 m_dbImpl
->GetColumnCount(&count
);
1066 // Gets the column width
1067 int wxListCtrl::GetColumnWidth(int col
) const
1070 return m_genericImpl
->GetColumnWidth(col
);
1074 return m_dbImpl
->GetColumnWidth(col
);
1080 // Sets the column width
1081 bool wxListCtrl::SetColumnWidth(int col
, int width
)
1084 return m_genericImpl
->SetColumnWidth(col
, width
);
1088 if ( width
== wxLIST_AUTOSIZE_USEHEADER
)
1090 width
= 150; // FIXME
1095 for (int column
= 0; column
< GetColumnCount(); column
++)
1098 GetColumn(column
, colInfo
);
1100 colInfo
.SetWidth(width
);
1101 SetColumn(column
, colInfo
);
1103 const int mywidth
= (width
== wxLIST_AUTOSIZE
)
1104 ? CalcColumnAutoWidth(column
) : width
;
1105 m_dbImpl
->SetColumnWidth(column
, mywidth
);
1110 if ( width
== wxLIST_AUTOSIZE
)
1111 width
= CalcColumnAutoWidth(col
);
1114 GetColumn(col
, colInfo
);
1116 colInfo
.SetWidth(width
);
1117 SetColumn(col
, colInfo
);
1118 m_dbImpl
->SetColumnWidth(col
, width
);
1126 // Gets the number of items that can fit vertically in the
1127 // visible area of the list control (list or report view)
1128 // or the total number of items in the list control (icon
1129 // or small icon view)
1130 int wxListCtrl::GetCountPerPage() const
1133 return m_genericImpl
->GetCountPerPage();
1138 m_dbImpl
->GetDefaultRowHeight( &height
);
1140 return GetClientSize().y
/ height
;
1146 // Gets the edit control for editing labels.
1147 wxTextCtrl
* wxListCtrl::GetEditControl() const
1150 return m_genericImpl
->GetEditControl();
1155 // Gets information about the item
1156 bool wxListCtrl::GetItem(wxListItem
& info
) const
1159 return m_genericImpl
->GetItem(info
);
1165 if (info
.m_itemId
>= 0 && info
.m_itemId
< GetItemCount())
1167 m_dbImpl
->MacGetColumnInfo(info
.m_itemId
, info
.m_col
, info
);
1168 // MacGetColumnInfo returns erroneous information in the state field, so zero it.
1170 if (info
.GetMask() & wxLIST_MASK_STATE
)
1172 DataBrowserItemID id
= (DataBrowserItemID
)m_dbImpl
->GetItemFromLine(info
.m_itemId
);
1173 if (IsDataBrowserItemSelected( m_dbImpl
->GetControlRef(), id
))
1174 info
.SetState(info
.GetState() | wxLIST_STATE_SELECTED
);
1180 if (info
.m_itemId
>= 0 && info
.m_itemId
< GetItemCount())
1182 info
.SetText( OnGetItemText(info
.m_itemId
, info
.m_col
) );
1183 info
.SetImage( OnGetItemColumnImage(info
.m_itemId
, info
.m_col
) );
1184 if (info
.GetMask() & wxLIST_MASK_STATE
)
1186 if (IsDataBrowserItemSelected( m_dbImpl
->GetControlRef(), info
.m_itemId
+1 ))
1187 info
.SetState(info
.GetState() | wxLIST_STATE_SELECTED
);
1190 wxListItemAttr
* attrs
= OnGetItemAttr( info
.m_itemId
);
1193 info
.SetFont( attrs
->GetFont() );
1194 info
.SetBackgroundColour( attrs
->GetBackgroundColour() );
1195 info
.SetTextColour( attrs
->GetTextColour() );
1200 bool success
= true;
1204 // Sets information about the item
1205 bool wxListCtrl::SetItem(wxListItem
& info
)
1208 return m_genericImpl
->SetItem(info
);
1211 m_dbImpl
->MacSetColumnInfo( info
.m_itemId
, info
.m_col
, &info
);
1216 long wxListCtrl::SetItem(long index
, int col
, const wxString
& label
, int imageId
)
1219 return m_genericImpl
->SetItem(index
, col
, label
, imageId
);
1222 info
.m_text
= label
;
1223 info
.m_mask
= wxLIST_MASK_TEXT
;
1224 info
.m_itemId
= index
;
1228 info
.m_image
= imageId
;
1229 info
.m_mask
|= wxLIST_MASK_IMAGE
;
1231 return SetItem(info
);
1235 // Gets the item state
1236 int wxListCtrl::GetItemState(long item
, long stateMask
) const
1239 return m_genericImpl
->GetItemState(item
, stateMask
);
1243 if ( HasFlag(wxLC_VIRTUAL
) )
1245 if (stateMask
== wxLIST_STATE_SELECTED
)
1247 if (IsDataBrowserItemSelected( m_dbImpl
->GetControlRef(), item
+1 ))
1248 return wxLIST_STATE_SELECTED
;
1257 info
.m_mask
= wxLIST_MASK_STATE
;
1258 info
.m_stateMask
= stateMask
;
1259 info
.m_itemId
= item
;
1264 return info
.m_state
;
1271 // Sets the item state
1272 bool wxListCtrl::SetItemState(long item
, long state
, long stateMask
)
1275 return m_genericImpl
->SetItemState(item
, state
, stateMask
);
1279 DataBrowserSetOption option
= kDataBrowserItemsAdd
;
1280 if ( (stateMask
& wxLIST_STATE_SELECTED
) && state
== 0 )
1281 option
= kDataBrowserItemsRemove
;
1285 if ( HasFlag(wxLC_VIRTUAL
) )
1287 wxMacDataItemBrowserSelectionSuppressor
suppressor(m_dbImpl
);
1288 m_dbImpl
->SetSelectedAllItems(option
);
1292 for(int i
= 0; i
< GetItemCount();i
++)
1296 info
.m_mask
= wxLIST_MASK_STATE
;
1297 info
.m_stateMask
= stateMask
;
1298 info
.m_state
= state
;
1305 if ( HasFlag(wxLC_VIRTUAL
) )
1307 long itemID
= item
+1;
1308 bool isSelected
= IsDataBrowserItemSelected(m_dbImpl
->GetControlRef(), (DataBrowserItemID
)itemID
);
1309 bool isSelectedState
= (state
== wxLIST_STATE_SELECTED
);
1311 // toggle the selection state if wxListInfo state and actual state don't match.
1312 if ( (stateMask
& wxLIST_STATE_SELECTED
) && isSelected
!= isSelectedState
)
1314 SetDataBrowserSelectedItems(m_dbImpl
->GetControlRef(), 1, (DataBrowserItemID
*)&itemID
, option
);
1320 info
.m_itemId
= item
;
1321 info
.m_mask
= wxLIST_MASK_STATE
;
1322 info
.m_stateMask
= stateMask
;
1323 info
.m_state
= state
;
1324 return SetItem(info
);
1331 // Sets the item image
1332 bool wxListCtrl::SetItemImage(long item
, int image
, int WXUNUSED(selImage
))
1334 return SetItemColumnImage(item
, 0, image
);
1337 // Sets the item image
1338 bool wxListCtrl::SetItemColumnImage(long item
, long column
, int image
)
1341 return m_genericImpl
->SetItemColumnImage(item
, column
, image
);
1345 info
.m_mask
= wxLIST_MASK_IMAGE
;
1346 info
.m_image
= image
;
1347 info
.m_itemId
= item
;
1348 info
.m_col
= column
;
1350 return SetItem(info
);
1353 // Gets the item text
1354 wxString
wxListCtrl::GetItemText(long item
, int column
) const
1357 return m_genericImpl
->GetItemText(item
, column
);
1361 info
.m_mask
= wxLIST_MASK_TEXT
;
1362 info
.m_itemId
= item
;
1363 info
.m_col
= column
;
1366 return wxEmptyString
;
1370 // Sets the item text
1371 void wxListCtrl::SetItemText(long item
, const wxString
& str
)
1374 return m_genericImpl
->SetItemText(item
, str
);
1378 info
.m_mask
= wxLIST_MASK_TEXT
;
1379 info
.m_itemId
= item
;
1385 // Gets the item data
1386 long wxListCtrl::GetItemData(long item
) const
1389 return m_genericImpl
->GetItemData(item
);
1393 info
.m_mask
= wxLIST_MASK_DATA
;
1394 info
.m_itemId
= item
;
1401 // Sets the item data
1402 bool wxListCtrl::SetItemPtrData(long item
, wxUIntPtr data
)
1405 return m_genericImpl
->SetItemData(item
, data
);
1409 info
.m_mask
= wxLIST_MASK_DATA
;
1410 info
.m_itemId
= item
;
1413 return SetItem(info
);
1416 wxRect
wxListCtrl::GetViewRect() const
1418 wxASSERT_MSG( !HasFlag(wxLC_REPORT
| wxLC_LIST
),
1419 wxT("wxListCtrl::GetViewRect() only works in icon mode") );
1422 return m_genericImpl
->GetViewRect();
1428 bool wxListCtrl::GetSubItemRect( long item
, long subItem
, wxRect
& rect
, int code
) const
1431 return m_genericImpl
->GetSubItemRect(item
, subItem
, rect
, code
);
1433 // TODO: implement for DataBrowser implementation
1437 // Gets the item rectangle
1438 bool wxListCtrl::GetItemRect(long item
, wxRect
& rect
, int code
) const
1441 return m_genericImpl
->GetItemRect(item
, rect
, code
);
1446 DataBrowserItemID id
;
1448 DataBrowserTableViewColumnID col
= 0;
1449 verify_noerr( m_dbImpl
->GetColumnIDFromIndex( 0, &col
) );
1452 DataBrowserPropertyPart part
= kDataBrowserPropertyEnclosingPart
;
1453 if ( code
== wxLIST_RECT_LABEL
)
1454 part
= kDataBrowserPropertyTextPart
;
1455 else if ( code
== wxLIST_RECT_ICON
)
1456 part
= kDataBrowserPropertyIconPart
;
1458 if ( !(GetWindowStyleFlag() & wxLC_VIRTUAL
) )
1460 wxMacDataItem
* thisItem
= m_dbImpl
->GetItemFromLine(item
);
1461 id
= (DataBrowserItemID
) thisItem
;
1466 GetDataBrowserItemPartBounds( m_dbImpl
->GetControlRef(), id
, col
, part
, &bounds
);
1468 rect
.x
= bounds
.left
;
1469 rect
.y
= bounds
.top
;
1470 rect
.width
= bounds
.right
- bounds
.left
; //GetClientSize().x; // we need the width of the whole row, not just the item.
1471 rect
.height
= bounds
.bottom
- bounds
.top
;
1472 //fprintf("id = %d, bounds = %d, %d, %d, %d\n", id, rect.x, rect.y, rect.width, rect.height);
1477 // Gets the item position
1478 bool wxListCtrl::GetItemPosition(long item
, wxPoint
& pos
) const
1481 return m_genericImpl
->GetItemPosition(item
, pos
);
1483 bool success
= false;
1488 GetItemRect(item
, itemRect
);
1489 pos
= itemRect
.GetPosition();
1496 // Sets the item position.
1497 bool wxListCtrl::SetItemPosition(long item
, const wxPoint
& pos
)
1500 return m_genericImpl
->SetItemPosition(item
, pos
);
1505 // Gets the number of items in the list control
1506 int wxListCtrl::GetItemCount() const
1509 return m_genericImpl
->GetItemCount();
1512 return m_dbImpl
->MacGetCount();
1517 void wxListCtrl::SetItemSpacing( int spacing
, bool isSmall
)
1520 m_genericImpl
->SetItemSpacing(spacing
, isSmall
);
1523 wxSize
wxListCtrl::GetItemSpacing() const
1526 return m_genericImpl
->GetItemSpacing();
1528 return wxSize(0, 0);
1531 void wxListCtrl::SetItemTextColour( long item
, const wxColour
&col
)
1535 m_genericImpl
->SetItemTextColour(item
, col
);
1540 info
.m_itemId
= item
;
1541 info
.SetTextColour( col
);
1545 wxColour
wxListCtrl::GetItemTextColour( long item
) const
1548 return m_genericImpl
->GetItemTextColour(item
);
1554 return info
.GetTextColour();
1556 return wxNullColour
;
1559 void wxListCtrl::SetItemBackgroundColour( long item
, const wxColour
&col
)
1563 m_genericImpl
->SetItemBackgroundColour(item
, col
);
1568 info
.m_itemId
= item
;
1569 info
.SetBackgroundColour( col
);
1573 wxColour
wxListCtrl::GetItemBackgroundColour( long item
) const
1576 return m_genericImpl
->GetItemBackgroundColour(item
);
1582 return info
.GetBackgroundColour();
1584 return wxNullColour
;
1587 void wxListCtrl::SetItemFont( long item
, const wxFont
&f
)
1591 m_genericImpl
->SetItemFont(item
, f
);
1596 info
.m_itemId
= item
;
1601 wxFont
wxListCtrl::GetItemFont( long item
) const
1604 return m_genericImpl
->GetItemFont(item
);
1610 return info
.GetFont();
1616 // Gets the number of selected items in the list control
1617 int wxListCtrl::GetSelectedItemCount() const
1620 return m_genericImpl
->GetSelectedItemCount();
1623 return m_dbImpl
->GetSelectedItemCount(NULL
, true);
1628 // Gets the text colour of the listview
1629 wxColour
wxListCtrl::GetTextColour() const
1632 return m_genericImpl
->GetTextColour();
1634 // TODO: we need owner drawn list items to customize text color.
1638 return wxNullColour
;
1641 // Sets the text colour of the listview
1642 void wxListCtrl::SetTextColour(const wxColour
& col
)
1646 m_genericImpl
->SetTextColour(col
);
1654 // Gets the index of the topmost visible item when in
1655 // list or report view
1656 long wxListCtrl::GetTopItem() const
1659 return m_genericImpl
->GetTopItem();
1664 long item
= HitTest( wxPoint(1, 1), flags
);
1665 if (flags
== wxLIST_HITTEST_ONITEM
)
1672 // Searches for an item, starting from 'item'.
1673 // 'geometry' is one of
1674 // wxLIST_NEXT_ABOVE/ALL/BELOW/LEFT/RIGHT.
1675 // 'state' is a state bit flag, one or more of
1676 // wxLIST_STATE_DROPHILITED/FOCUSED/SELECTED/CUT.
1677 // item can be -1 to find the first item that matches the
1679 // Returns the item or -1 if unsuccessful.
1680 long wxListCtrl::GetNextItem(long item
, int geom
, int state
) const
1683 return m_genericImpl
->GetNextItem(item
, geom
, state
);
1685 // TODO: implement all geometry and state options?
1688 if ( geom
== wxLIST_NEXT_ALL
|| geom
== wxLIST_NEXT_BELOW
)
1690 long count
= m_dbImpl
->MacGetCount() ;
1691 for ( long line
= item
+ 1 ; line
< count
; line
++ )
1693 DataBrowserItemID id
= line
+ 1;
1695 id
= (DataBrowserItemID
)m_dbImpl
->GetItemFromLine(line
);
1697 if ( (state
& wxLIST_STATE_FOCUSED
) && (m_current
== line
))
1700 if ( (state
== wxLIST_STATE_DONTCARE
) )
1703 if ( (state
& wxLIST_STATE_SELECTED
) && IsDataBrowserItemSelected(m_dbImpl
->GetControlRef(), id
) )
1708 if ( geom
== wxLIST_NEXT_ABOVE
)
1712 item2
= m_dbImpl
->MacGetCount();
1714 for ( long line
= item2
- 1 ; line
>= 0; line
-- )
1716 DataBrowserItemID id
= line
+ 1;
1718 id
= (DataBrowserItemID
)m_dbImpl
->GetItemFromLine(line
);
1720 if ( (state
& wxLIST_STATE_FOCUSED
) && (m_current
== line
))
1723 if ( (state
== wxLIST_STATE_DONTCARE
) )
1726 if ( (state
& wxLIST_STATE_SELECTED
) && IsDataBrowserItemSelected(m_dbImpl
->GetControlRef(), id
) )
1736 wxImageList
*wxListCtrl::GetImageList(int which
) const
1739 return m_genericImpl
->GetImageList(which
);
1741 if ( which
== wxIMAGE_LIST_NORMAL
)
1743 return m_imageListNormal
;
1745 else if ( which
== wxIMAGE_LIST_SMALL
)
1747 return m_imageListSmall
;
1749 else if ( which
== wxIMAGE_LIST_STATE
)
1751 return m_imageListState
;
1756 void wxListCtrl::SetImageList(wxImageList
*imageList
, int which
)
1760 m_genericImpl
->SetImageList(imageList
, which
);
1764 if ( which
== wxIMAGE_LIST_NORMAL
)
1766 if (m_ownsImageListNormal
) delete m_imageListNormal
;
1767 m_imageListNormal
= imageList
;
1768 m_ownsImageListNormal
= false;
1770 else if ( which
== wxIMAGE_LIST_SMALL
)
1772 if (m_ownsImageListSmall
) delete m_imageListSmall
;
1773 m_imageListSmall
= imageList
;
1774 m_ownsImageListSmall
= false;
1776 else if ( which
== wxIMAGE_LIST_STATE
)
1778 if (m_ownsImageListState
) delete m_imageListState
;
1779 m_imageListState
= imageList
;
1780 m_ownsImageListState
= false;
1784 void wxListCtrl::AssignImageList(wxImageList
*imageList
, int which
)
1788 m_genericImpl
->AssignImageList(imageList
, which
);
1792 SetImageList(imageList
, which
);
1793 if ( which
== wxIMAGE_LIST_NORMAL
)
1794 m_ownsImageListNormal
= true;
1795 else if ( which
== wxIMAGE_LIST_SMALL
)
1796 m_ownsImageListSmall
= true;
1797 else if ( which
== wxIMAGE_LIST_STATE
)
1798 m_ownsImageListState
= true;
1801 // ----------------------------------------------------------------------------
1803 // ----------------------------------------------------------------------------
1805 // Arranges the items
1806 bool wxListCtrl::Arrange(int flag
)
1809 return m_genericImpl
->Arrange(flag
);
1814 bool wxListCtrl::DeleteItem(long item
)
1817 return m_genericImpl
->DeleteItem(item
);
1821 m_dbImpl
->MacDelete(item
);
1822 wxListEvent
event( wxEVT_COMMAND_LIST_DELETE_ITEM
, GetId() );
1823 event
.SetEventObject( this );
1824 event
.m_itemIndex
= item
;
1825 HandleWindowEvent( event
);
1831 // Deletes all items
1832 bool wxListCtrl::DeleteAllItems()
1836 return m_genericImpl
->DeleteAllItems();
1840 m_dbImpl
->MacClear();
1841 wxListEvent
event( wxEVT_COMMAND_LIST_DELETE_ALL_ITEMS
, GetId() );
1842 event
.SetEventObject( this );
1843 HandleWindowEvent( event
);
1848 // Deletes all items
1849 bool wxListCtrl::DeleteAllColumns()
1852 return m_genericImpl
->DeleteAllColumns();
1857 m_dbImpl
->GetColumnCount(&cols
);
1858 for (UInt32 col
= 0; col
< cols
; col
++)
1868 bool wxListCtrl::DeleteColumn(int col
)
1871 return m_genericImpl
->DeleteColumn(col
);
1875 OSStatus err
= m_dbImpl
->RemoveColumn(col
);
1876 return err
== noErr
;
1882 // Clears items, and columns if there are any.
1883 void wxListCtrl::ClearAll()
1887 m_genericImpl
->ClearAll();
1898 wxTextCtrl
* wxListCtrl::EditLabel(long item
, wxClassInfo
* textControlClass
)
1901 return m_genericImpl
->EditLabel(item
, textControlClass
);
1905 wxCHECK_MSG( (item
>= 0) && ((long)item
< GetItemCount()), NULL
,
1906 wxT("wrong index in wxListCtrl::EditLabel()") );
1908 wxASSERT_MSG( textControlClass
->IsKindOf(CLASSINFO(wxTextCtrl
)),
1909 wxT("EditLabel() needs a text control") );
1911 wxListEvent
le( wxEVT_COMMAND_LIST_BEGIN_LABEL_EDIT
, GetParent()->GetId() );
1912 le
.SetEventObject( this );
1913 le
.m_itemIndex
= item
;
1915 GetItem( le
.m_item
);
1917 if ( GetParent()->HandleWindowEvent( le
) && !le
.IsAllowed() )
1919 // vetoed by user code
1923 wxTextCtrl
* const text
= (wxTextCtrl
*)textControlClass
->CreateObject();
1924 m_textctrlWrapper
= new wxListCtrlTextCtrlWrapper(this, text
, item
);
1925 return m_textctrlWrapper
->GetText();
1930 // End label editing, optionally cancelling the edit
1931 bool wxListCtrl::EndEditLabel(bool WXUNUSED(cancel
))
1933 // TODO: generic impl. doesn't have this method - is it needed for us?
1935 return true; // m_genericImpl->EndEditLabel(cancel);
1939 DataBrowserTableViewColumnID id
= 0;
1940 verify_noerr( m_dbImpl
->GetColumnIDFromIndex( 0, &id
) );
1941 verify_noerr( SetDataBrowserEditItem(m_dbImpl
->GetControlRef(), kDataBrowserNoItem
, id
) );
1946 // Ensures this item is visible
1947 bool wxListCtrl::EnsureVisible(long item
)
1950 return m_genericImpl
->EnsureVisible(item
);
1954 wxMacDataItem
* dataItem
= m_dbImpl
->GetItemFromLine(item
);
1955 m_dbImpl
->RevealItem(dataItem
, kDataBrowserRevealWithoutSelecting
);
1961 // Find an item whose label matches this string, starting from the item after 'start'
1962 // or the beginning if 'start' is -1.
1963 long wxListCtrl::FindItem(long start
, const wxString
& str
, bool partial
)
1966 return m_genericImpl
->FindItem(start
, str
, partial
);
1968 wxString str_upper
= str
.Upper();
1973 long count
= GetItemCount();
1977 wxString line_upper
= GetItemText(idx
).Upper();
1980 if (line_upper
== str_upper
)
1985 if (line_upper
.find(str_upper
) == 0)
1995 // Find an item whose data matches this data, starting from the item after 'start'
1996 // or the beginning if 'start' is -1.
1997 long wxListCtrl::FindItem(long start
, long data
)
2000 return m_genericImpl
->FindItem(start
, data
);
2005 long count
= GetItemCount();
2009 if (GetItemData(idx
) == data
)
2017 // Find an item nearest this position in the specified direction, starting from
2018 // the item after 'start' or the beginning if 'start' is -1.
2019 long wxListCtrl::FindItem(long start
, const wxPoint
& pt
, int direction
)
2022 return m_genericImpl
->FindItem(start
, pt
, direction
);
2026 static void calculateCGDrawingBounds(CGRect inItemRect
, CGRect
*outIconRect
, CGRect
*outTextRect
, bool hasIcon
);
2028 // Determines which item (if any) is at the specified point,
2029 // giving details in 'flags' (see wxLIST_HITTEST_... flags above)
2031 wxListCtrl::HitTest(const wxPoint
& point
, int& flags
, long *ptrSubItem
) const
2037 return m_genericImpl
->HitTest(point
, flags
, ptrSubItem
);
2039 flags
= wxLIST_HITTEST_NOWHERE
;
2042 int colHeaderHeight
= 22; // TODO: Find a way to get this value from the db control?
2043 UInt16 rowHeight
= 0;
2044 m_dbImpl
->GetDefaultRowHeight(&rowHeight
);
2047 // get the actual row by taking scroll position into account
2048 UInt32 offsetX
, offsetY
;
2049 m_dbImpl
->GetScrollPosition( &offsetY
, &offsetX
);
2052 if ( !(GetWindowStyleFlag() & wxLC_NO_HEADER
) )
2053 y
-= colHeaderHeight
;
2058 int row
= y
/ rowHeight
;
2059 DataBrowserItemID id
;
2060 m_dbImpl
->GetItemID( (DataBrowserTableViewRowIndex
) row
, &id
);
2062 CGPoint click_point
= CGPointMake( point
.x
, point
.y
);
2063 if (row
< GetItemCount() )
2066 for( column
= 0; column
< GetColumnCount(); column
++ )
2069 CGRect enclosingCGRect
, iconCGRect
, textCGRect
;
2071 wxMacListCtrlItem
* lcItem
;
2073 WXUNUSED_UNLESS_DEBUG( OSStatus status
= ) m_dbImpl
->GetItemPartBounds( id
, kMinColumnId
+ column
, kDataBrowserPropertyEnclosingPart
, &enclosingRect
);
2074 wxASSERT( status
== noErr
);
2076 enclosingCGRect
= CGRectMake(enclosingRect
.left
,
2078 enclosingRect
.right
- enclosingRect
.left
,
2079 enclosingRect
.bottom
- enclosingRect
.top
);
2083 if ( !(GetWindowStyleFlag() & wxLC_VIRTUAL
) )
2085 lcItem
= (wxMacListCtrlItem
*) id
;
2086 if (lcItem
->HasColumnInfo(column
))
2088 wxListItem
* item
= lcItem
->GetColumnInfo(column
);
2090 if (item
->GetMask() & wxLIST_MASK_IMAGE
)
2092 imgIndex
= item
->GetImage();
2098 long itemNum
= (long)id
-1;
2099 if (itemNum
>= 0 && itemNum
< GetItemCount())
2101 imgIndex
= OnGetItemColumnImage( itemNum
, column
);
2106 calculateCGDrawingBounds(enclosingCGRect
, &iconCGRect
, &textCGRect
, (imgIndex
!= -1) );
2108 if ( CGRectContainsPoint( iconCGRect
, click_point
) )
2110 flags
= wxLIST_HITTEST_ONITEMICON
;
2112 *ptrSubItem
= column
;
2115 else if ( CGRectContainsPoint( textCGRect
, click_point
) )
2117 flags
= wxLIST_HITTEST_ONITEMLABEL
;
2119 *ptrSubItem
= column
;
2124 if ( !(GetWindowStyleFlag() & wxLC_VIRTUAL
) )
2126 wxMacListCtrlItem
* lcItem
;
2127 lcItem
= (wxMacListCtrlItem
*) id
;
2130 flags
= wxLIST_HITTEST_ONITEM
;
2132 *ptrSubItem
= column
;
2138 flags
= wxLIST_HITTEST_ONITEM
;
2140 *ptrSubItem
= column
;
2146 if ( wxControl::HitTest( point
) )
2147 flags
= wxLIST_HITTEST_NOWHERE
;
2154 int wxListCtrl::GetScrollPos(int orient
) const
2157 return m_genericImpl
->GetScrollPos(orient
);
2161 UInt32 offsetX
, offsetY
;
2162 m_dbImpl
->GetScrollPosition( &offsetY
, &offsetX
);
2163 if ( orient
== wxHORIZONTAL
)
2172 // Inserts an item, returning the index of the new item if successful,
2174 long wxListCtrl::InsertItem(wxListItem
& info
)
2176 wxASSERT_MSG( !IsVirtual(), wxT("can't be used with virtual controls") );
2179 return m_genericImpl
->InsertItem(info
);
2181 if (m_dbImpl
&& !IsVirtual())
2183 int count
= GetItemCount();
2185 if (info
.m_itemId
> count
)
2186 info
.m_itemId
= count
;
2188 m_dbImpl
->MacInsertItem(info
.m_itemId
, &info
);
2190 wxListEvent
event( wxEVT_COMMAND_LIST_INSERT_ITEM
, GetId() );
2191 event
.SetEventObject( this );
2192 event
.m_itemIndex
= info
.m_itemId
;
2193 HandleWindowEvent( event
);
2194 return info
.m_itemId
;
2199 long wxListCtrl::InsertItem(long index
, const wxString
& label
)
2202 return m_genericImpl
->InsertItem(index
, label
);
2205 info
.m_text
= label
;
2206 info
.m_mask
= wxLIST_MASK_TEXT
;
2207 info
.m_itemId
= index
;
2208 return InsertItem(info
);
2211 // Inserts an image item
2212 long wxListCtrl::InsertItem(long index
, int imageIndex
)
2215 return m_genericImpl
->InsertItem(index
, imageIndex
);
2218 info
.m_image
= imageIndex
;
2219 info
.m_mask
= wxLIST_MASK_IMAGE
;
2220 info
.m_itemId
= index
;
2221 return InsertItem(info
);
2224 // Inserts an image/string item
2225 long wxListCtrl::InsertItem(long index
, const wxString
& label
, int imageIndex
)
2228 return m_genericImpl
->InsertItem(index
, label
, imageIndex
);
2231 info
.m_image
= imageIndex
;
2232 info
.m_text
= label
;
2233 info
.m_mask
= wxLIST_MASK_IMAGE
| wxLIST_MASK_TEXT
;
2234 info
.m_itemId
= index
;
2235 return InsertItem(info
);
2238 // For list view mode (only), inserts a column.
2239 long wxListCtrl::InsertColumn(long col
, wxListItem
& item
)
2242 return m_genericImpl
->InsertColumn(col
, item
);
2246 int width
= item
.GetWidth();
2247 if ( !(item
.GetMask() & wxLIST_MASK_WIDTH
) )
2250 DataBrowserPropertyType type
= kDataBrowserCustomType
; //kDataBrowserTextType;
2251 wxImageList
* imageList
= GetImageList(wxIMAGE_LIST_SMALL
);
2252 if (imageList
&& imageList
->GetImageCount() > 0)
2254 wxBitmap bmp
= imageList
->GetBitmap(0);
2256 // type = kDataBrowserIconAndTextType;
2259 SInt16 just
= teFlushDefault
;
2260 if (item
.GetMask() & wxLIST_MASK_FORMAT
)
2262 if (item
.GetAlign() == wxLIST_FORMAT_LEFT
)
2264 else if (item
.GetAlign() == wxLIST_FORMAT_CENTER
)
2266 else if (item
.GetAlign() == wxLIST_FORMAT_RIGHT
)
2267 just
= teFlushRight
;
2269 m_dbImpl
->InsertColumn(col
, type
, item
.GetText(), just
, width
);
2271 wxListItem
* listItem
= new wxListItem(item
);
2272 m_colsInfo
.Insert( col
, listItem
);
2273 SetColumn(col
, item
);
2275 // set/remove options based on the wxListCtrl type.
2276 DataBrowserTableViewColumnID id
;
2277 m_dbImpl
->GetColumnIDFromIndex(col
, &id
);
2278 DataBrowserPropertyFlags flags
;
2279 verify_noerr(m_dbImpl
->GetPropertyFlags(id
, &flags
));
2280 if (GetWindowStyleFlag() & wxLC_EDIT_LABELS
)
2281 flags
|= kDataBrowserPropertyIsEditable
;
2283 if (GetWindowStyleFlag() & wxLC_VIRTUAL
){
2284 flags
&= ~kDataBrowserListViewSortableColumn
;
2286 verify_noerr(m_dbImpl
->SetPropertyFlags(id
, flags
));
2292 long wxListCtrl::InsertColumn(long col
,
2293 const wxString
& heading
,
2298 return m_genericImpl
->InsertColumn(col
, heading
, format
, width
);
2301 item
.m_mask
= wxLIST_MASK_TEXT
| wxLIST_MASK_FORMAT
;
2302 item
.m_text
= heading
;
2305 item
.m_mask
|= wxLIST_MASK_WIDTH
;
2306 item
.m_width
= width
;
2308 item
.m_format
= format
;
2310 return InsertColumn(col
, item
);
2313 // scroll the control by the given number of pixels (exception: in list view,
2314 // dx is interpreted as number of columns)
2315 bool wxListCtrl::ScrollList(int dx
, int dy
)
2318 return m_genericImpl
->ScrollList(dx
, dy
);
2322 m_dbImpl
->SetScrollPosition(dx
, dy
);
2328 bool wxListCtrl::SortItems(wxListCtrlCompare fn
, wxIntPtr data
)
2331 return m_genericImpl
->SortItems(fn
, data
);
2336 m_compareFuncData
= data
;
2337 SortDataBrowserContainer( m_dbImpl
->GetControlRef(), kDataBrowserNoItem
, true);
2339 // we need to do this after each call, else we get a crash from wxPython when
2340 // SortItems is called the second time.
2341 m_compareFunc
= NULL
;
2342 m_compareFuncData
= 0;
2348 void wxListCtrl::OnRenameTimer()
2350 wxCHECK_RET( HasCurrent(), wxT("unexpected rename timer") );
2352 EditLabel( m_current
);
2355 bool wxListCtrl::OnRenameAccept(long itemEdit
, const wxString
& value
)
2357 wxListEvent
le( wxEVT_COMMAND_LIST_END_LABEL_EDIT
, GetId() );
2358 le
.SetEventObject( this );
2359 le
.m_itemIndex
= itemEdit
;
2361 GetItem( le
.m_item
);
2362 le
.m_item
.m_text
= value
;
2363 return !HandleWindowEvent( le
) ||
2367 void wxListCtrl::OnRenameCancelled(long itemEdit
)
2369 // let owner know that the edit was cancelled
2370 wxListEvent
le( wxEVT_COMMAND_LIST_END_LABEL_EDIT
, GetParent()->GetId() );
2372 le
.SetEditCanceled(true);
2374 le
.SetEventObject( this );
2375 le
.m_itemIndex
= itemEdit
;
2377 GetItem( le
.m_item
);
2378 HandleWindowEvent( le
);
2381 // ----------------------------------------------------------------------------
2382 // virtual list controls
2383 // ----------------------------------------------------------------------------
2385 wxString
wxListCtrl::OnGetItemText(long WXUNUSED(item
), long WXUNUSED(col
)) const
2387 // this is a pure virtual function, in fact - which is not really pure
2388 // because the controls which are not virtual don't need to implement it
2389 wxFAIL_MSG( wxT("wxListCtrl::OnGetItemText not supposed to be called") );
2391 return wxEmptyString
;
2394 int wxListCtrl::OnGetItemImage(long WXUNUSED(item
)) const
2396 wxCHECK_MSG(!GetImageList(wxIMAGE_LIST_SMALL
),
2398 wxT("List control has an image list, OnGetItemImage or OnGetItemColumnImage should be overridden."));
2402 int wxListCtrl::OnGetItemColumnImage(long item
, long column
) const
2405 return OnGetItemImage(item
);
2410 wxListItemAttr
*wxListCtrl::OnGetItemAttr(long WXUNUSED_UNLESS_DEBUG(item
)) const
2412 wxASSERT_MSG( item
>= 0 && item
< GetItemCount(),
2413 wxT("invalid item index in OnGetItemAttr()") );
2415 // no attributes by default
2419 void wxListCtrl::SetItemCount(long count
)
2421 wxASSERT_MSG( IsVirtual(), wxT("this is for virtual controls only") );
2425 m_genericImpl
->SetItemCount(count
);
2431 // we need to temporarily disable the new item creation notification
2432 // procedure to speed things up
2433 // FIXME: Even this doesn't seem to help much...
2435 // FIXME: Find a more efficient way to do this.
2436 m_dbImpl
->MacClear();
2438 DataBrowserCallbacks callbacks
;
2439 DataBrowserItemNotificationUPP itemUPP
;
2440 GetDataBrowserCallbacks(m_dbImpl
->GetControlRef(), &callbacks
);
2441 itemUPP
= callbacks
.u
.v1
.itemNotificationCallback
;
2442 callbacks
.u
.v1
.itemNotificationCallback
= 0;
2443 m_dbImpl
->SetCallbacks(&callbacks
);
2444 ::AddDataBrowserItems(m_dbImpl
->GetControlRef(), kDataBrowserNoItem
,
2445 count
, NULL
, kDataBrowserItemNoProperty
);
2446 callbacks
.u
.v1
.itemNotificationCallback
= itemUPP
;
2447 m_dbImpl
->SetCallbacks(&callbacks
);
2452 void wxListCtrl::RefreshItem(long item
)
2456 m_genericImpl
->RefreshItem(item
);
2462 DataBrowserItemID id
;
2466 wxMacDataItem
* thisItem
= m_dbImpl
->GetItemFromLine(item
);
2467 id
= (DataBrowserItemID
) thisItem
;
2472 m_dbImpl
->wxMacDataBrowserControl::UpdateItems
2476 kDataBrowserItemNoProperty
, // preSortProperty
2477 kDataBrowserNoItem
// update all columns
2482 void wxListCtrl::RefreshItems(long itemFrom
, long itemTo
)
2486 m_genericImpl
->RefreshItems(itemFrom
, itemTo
);
2492 const long count
= itemTo
- itemFrom
+ 1;
2493 DataBrowserItemID
*ids
= new DataBrowserItemID
[count
];
2497 for ( long i
= 0; i
< count
; i
++ )
2499 wxMacDataItem
* thisItem
= m_dbImpl
->GetItemFromLine(itemFrom
+i
);
2500 ids
[i
] = (DataBrowserItemID
) thisItem
;
2505 for ( long i
= 0; i
< count
; i
++ )
2506 ids
[i
] = itemFrom
+i
+1;
2509 m_dbImpl
->wxMacDataBrowserControl::UpdateItems
2513 kDataBrowserItemNoProperty
, // preSortProperty
2514 kDataBrowserNoItem
// update all columns
2521 void wxListCtrl::SetDropTarget( wxDropTarget
*dropTarget
)
2523 #if wxUSE_DRAG_AND_DROP
2525 m_genericImpl
->SetDropTarget( dropTarget
);
2528 wxWindow::SetDropTarget( dropTarget
);
2532 wxDropTarget
*wxListCtrl::GetDropTarget() const
2534 #if wxUSE_DRAG_AND_DROP
2536 return m_genericImpl
->GetDropTarget();
2539 return wxWindow::GetDropTarget();
2544 #if wxABI_VERSION >= 20801
2545 void wxListCtrl::SetFocus()
2549 m_genericImpl
->SetFocus();
2553 wxWindow::SetFocus();
2557 // wxMac internal data structures
2559 wxMacListCtrlItem::~wxMacListCtrlItem()
2561 WX_CLEAR_HASH_MAP( wxListItemList
, m_rowItems
);
2564 void wxMacListCtrlItem::Notification(wxMacDataItemBrowserControl
*owner
,
2565 DataBrowserItemNotification message
,
2566 DataBrowserItemDataRef
WXUNUSED(itemData
) ) const
2569 wxMacDataBrowserListCtrlControl
*lb
= wxDynamicCast(owner
, wxMacDataBrowserListCtrlControl
);
2571 // we want to depend on as little as possible to make sure tear-down of controls is safe
2572 if ( message
== kDataBrowserItemRemoved
)
2577 else if ( message
== kDataBrowserItemAdded
)
2579 // we don't issue events on adding, the item is not really stored in the list yet, so we
2580 // avoid asserts by gettting out now
2584 wxListCtrl
*list
= wxDynamicCast( owner
->GetWXPeer() , wxListCtrl
);
2587 bool trigger
= false;
2589 wxListEvent
event( wxEVT_COMMAND_LIST_ITEM_SELECTED
, list
->GetId() );
2590 bool isSingle
= (list
->GetWindowStyle() & wxLC_SINGLE_SEL
) != 0;
2592 event
.SetEventObject( list
);
2593 event
.m_itemIndex
= owner
->GetLineFromItem( this ) ;
2594 event
.m_item
.m_itemId
= event
.m_itemIndex
;
2595 list
->GetItem(event
.m_item
);
2599 case kDataBrowserItemDeselected
:
2600 event
.SetEventType(wxEVT_COMMAND_LIST_ITEM_DESELECTED
);
2602 trigger
= !lb
->IsSelectionSuppressed();
2605 case kDataBrowserItemSelected
:
2606 trigger
= !lb
->IsSelectionSuppressed();
2609 case kDataBrowserItemDoubleClicked
:
2610 event
.SetEventType( wxEVT_COMMAND_LIST_ITEM_ACTIVATED
);
2614 case kDataBrowserEditStarted
:
2615 // TODO : how to veto ?
2616 event
.SetEventType( wxEVT_COMMAND_LIST_BEGIN_LABEL_EDIT
) ;
2620 case kDataBrowserEditStopped
:
2621 // TODO probably trigger only upon the value store callback, because
2622 // here IIRC we cannot veto
2623 event
.SetEventType( wxEVT_COMMAND_LIST_END_LABEL_EDIT
) ;
2633 // direct notification is not always having the listbox GetSelection() having in synch with event
2634 wxPostEvent( list
->GetEventHandler(), event
);
2640 IMPLEMENT_DYNAMIC_CLASS(wxMacDataBrowserListCtrlControl
, wxMacDataItemBrowserControl
)
2642 wxMacDataBrowserListCtrlControl::wxMacDataBrowserListCtrlControl( wxWindow
*peer
, const wxPoint
& pos
, const wxSize
& size
, long style
)
2643 : wxMacDataItemBrowserControl( peer
, pos
, size
, style
)
2645 OSStatus err
= noErr
;
2646 m_clientDataItemsType
= wxClientData_None
;
2647 m_isVirtual
= false;
2650 if ( style
& wxLC_VIRTUAL
)
2653 DataBrowserSelectionFlags options
= kDataBrowserDragSelect
;
2654 if ( style
& wxLC_SINGLE_SEL
)
2656 options
|= kDataBrowserSelectOnlyOne
;
2660 options
|= kDataBrowserCmdTogglesSelection
;
2663 err
= SetSelectionFlags( options
);
2664 verify_noerr( err
);
2666 DataBrowserCustomCallbacks callbacks
;
2667 InitializeDataBrowserCustomCallbacks( &callbacks
, kDataBrowserLatestCustomCallbacks
);
2669 if ( gDataBrowserDrawItemUPP
== NULL
)
2670 gDataBrowserDrawItemUPP
= NewDataBrowserDrawItemUPP(DataBrowserDrawItemProc
);
2672 if ( gDataBrowserHitTestUPP
== NULL
)
2673 gDataBrowserHitTestUPP
= NewDataBrowserHitTestUPP(DataBrowserHitTestProc
);
2675 callbacks
.u
.v1
.drawItemCallback
= gDataBrowserDrawItemUPP
;
2676 callbacks
.u
.v1
.hitTestCallback
= gDataBrowserHitTestUPP
;
2678 SetDataBrowserCustomCallbacks( GetControlRef(), &callbacks
);
2680 if ( style
& wxLC_LIST
)
2682 InsertColumn(0, kDataBrowserIconAndTextType
, wxEmptyString
, -1, -1);
2683 verify_noerr( AutoSizeColumns() );
2686 if ( style
& wxLC_LIST
|| style
& wxLC_NO_HEADER
)
2687 verify_noerr( SetHeaderButtonHeight( 0 ) );
2690 SetSortProperty( kMinColumnId
- 1 );
2692 SetSortProperty( kMinColumnId
);
2694 m_sortOrder
= SortOrder_None
;
2696 if ( style
& wxLC_SORT_DESCENDING
)
2698 SetSortOrder( kDataBrowserOrderDecreasing
);
2700 else if ( style
& wxLC_SORT_ASCENDING
)
2702 SetSortOrder( kDataBrowserOrderIncreasing
);
2705 if ( style
& wxLC_VRULES
)
2707 verify_noerr( DataBrowserChangeAttributes(m_controlRef
, kDataBrowserAttributeListViewDrawColumnDividers
, kDataBrowserAttributeNone
) );
2710 verify_noerr( SetHiliteStyle(kDataBrowserTableViewFillHilite
) );
2711 verify_noerr( SetHasScrollBars( (style
& wxHSCROLL
) != 0 , true ) );
2714 pascal Boolean
wxMacDataBrowserListCtrlControl::DataBrowserEditTextProc(
2716 DataBrowserItemID itemID
,
2717 DataBrowserPropertyID property
,
2718 CFStringRef theString
,
2719 Rect
*maxEditTextRect
,
2720 Boolean
*shrinkToFit
)
2722 Boolean result
= false;
2723 wxMacDataBrowserListCtrlControl
* ctl
= wxDynamicCast(wxMacControl::GetReferenceFromNativeControl( browser
), wxMacDataBrowserListCtrlControl
);
2726 result
= ctl
->ConfirmEditText(itemID
, property
, theString
, maxEditTextRect
, shrinkToFit
);
2727 theString
= CFSTR("Hello!");
2732 bool wxMacDataBrowserListCtrlControl::ConfirmEditText(
2733 DataBrowserItemID
WXUNUSED(itemID
),
2734 DataBrowserPropertyID
WXUNUSED(property
),
2735 CFStringRef
WXUNUSED(theString
),
2736 Rect
*WXUNUSED(maxEditTextRect
),
2737 Boolean
*WXUNUSED(shrinkToFit
))
2742 pascal void wxMacDataBrowserListCtrlControl::DataBrowserDrawItemProc(
2744 DataBrowserItemID itemID
,
2745 DataBrowserPropertyID property
,
2746 DataBrowserItemState itemState
,
2747 const Rect
*itemRect
,
2749 Boolean colorDevice
)
2751 wxMacDataBrowserListCtrlControl
* ctl
= wxDynamicCast(wxMacControl::GetReferenceFromNativeControl( browser
), wxMacDataBrowserListCtrlControl
);
2754 ctl
->DrawItem(itemID
, property
, itemState
, itemRect
, gdDepth
, colorDevice
);
2758 // routines needed for DrawItem
2763 kTextBoxHeight
= 14,
2764 kIconTextSpacingV
= 2,
2766 kContentHeight
= kIconHeight
+ kTextBoxHeight
+ kIconTextSpacingV
2769 static void calculateCGDrawingBounds(CGRect inItemRect
, CGRect
*outIconRect
, CGRect
*outTextRect
, bool hasIcon
= false)
2772 float iconH
, iconW
= 0;
2773 float padding
= kItemPadding
;
2776 iconH
= kIconHeight
;
2778 padding
= padding
*2;
2781 textBottom
= inItemRect
.origin
.y
;
2783 *outIconRect
= CGRectMake(inItemRect
.origin
.x
+ kItemPadding
,
2784 textBottom
+ kIconTextSpacingV
, kIconWidth
,
2787 *outTextRect
= CGRectMake(inItemRect
.origin
.x
+ padding
+ iconW
,
2788 textBottom
+ kIconTextSpacingV
, inItemRect
.size
.width
- padding
- iconW
,
2789 inItemRect
.size
.height
- kIconTextSpacingV
);
2792 void wxMacDataBrowserListCtrlControl::DrawItem(
2793 DataBrowserItemID itemID
,
2794 DataBrowserPropertyID property
,
2795 DataBrowserItemState itemState
,
2796 const Rect
*WXUNUSED(itemRect
),
2798 Boolean colorDevice
)
2801 wxFont font
= wxNullFont
;
2804 DataBrowserTableViewColumnIndex listColumn
= 0;
2805 GetColumnPosition( property
, &listColumn
);
2807 wxListCtrl
* list
= wxDynamicCast( GetWXPeer() , wxListCtrl
);
2808 wxMacListCtrlItem
* lcItem
;
2809 wxColour color
= *wxBLACK
;
2810 wxColour bgColor
= wxNullColour
;
2812 if (listColumn
>= 0)
2816 lcItem
= (wxMacListCtrlItem
*) itemID
;
2817 if (lcItem
->HasColumnInfo(listColumn
))
2819 wxListItem
* item
= lcItem
->GetColumnInfo(listColumn
);
2821 // we always use the 0 column to get font and text/background colors.
2822 if (lcItem
->HasColumnInfo(0))
2824 wxListItem
* firstItem
= lcItem
->GetColumnInfo(0);
2825 color
= firstItem
->GetTextColour();
2826 bgColor
= firstItem
->GetBackgroundColour();
2827 font
= firstItem
->GetFont();
2830 if (item
->GetMask() & wxLIST_MASK_TEXT
)
2831 text
= item
->GetText();
2832 if (item
->GetMask() & wxLIST_MASK_IMAGE
)
2833 imgIndex
= item
->GetImage();
2839 long itemNum
= (long)itemID
-1;
2840 if (itemNum
>= 0 && itemNum
< list
->GetItemCount())
2842 text
= list
->OnGetItemText( itemNum
, listColumn
);
2843 imgIndex
= list
->OnGetItemColumnImage( itemNum
, listColumn
);
2844 wxListItemAttr
* attrs
= list
->OnGetItemAttr( itemNum
);
2847 if (attrs
->HasBackgroundColour())
2848 bgColor
= attrs
->GetBackgroundColour();
2849 if (attrs
->HasTextColour())
2850 color
= attrs
->GetTextColour();
2851 if (attrs
->HasFont())
2852 font
= attrs
->GetFont();
2858 wxColour listBgColor
= list
->GetBackgroundColour();
2859 if (bgColor
== wxNullColour
)
2860 bgColor
= listBgColor
;
2863 font
= list
->GetFont();
2865 wxCFStringRef
cfString( text
, wxLocale::GetSystemEncoding() );
2868 CGRect enclosingCGRect
, iconCGRect
, textCGRect
;
2870 ThemeDrawingState savedState
= NULL
;
2871 CGContextRef context
= (CGContextRef
)list
->MacGetDrawingContext();
2872 wxMacCGContextStateSaver
top_saver_cg( context
);
2874 RGBColor labelColor
;
2876 labelColor
.green
= 0;
2877 labelColor
.blue
= 0;
2879 RGBColor backgroundColor
;
2880 backgroundColor
.red
= 255;
2881 backgroundColor
.green
= 255;
2882 backgroundColor
.blue
= 255;
2884 GetDataBrowserItemPartBounds(GetControlRef(), itemID
, property
, kDataBrowserPropertyEnclosingPart
,
2887 enclosingCGRect
= CGRectMake(enclosingRect
.left
,
2889 enclosingRect
.right
- enclosingRect
.left
,
2890 enclosingRect
.bottom
- enclosingRect
.top
);
2892 bool hasFocus
= (wxWindow::FindFocus() == list
);
2893 active
= IsControlActive(GetControlRef());
2895 // don't paint the background over the vertical rule line
2896 if ( list
->GetWindowStyleFlag() & wxLC_VRULES
)
2898 enclosingCGRect
.origin
.x
+= 1;
2899 enclosingCGRect
.size
.width
-= 1;
2901 if (itemState
== kDataBrowserItemIsSelected
)
2904 GetThemeDrawingState(&savedState
);
2906 if (active
&& hasFocus
)
2908 GetThemeBrushAsColor(kThemeBrushAlternatePrimaryHighlightColor
, 32, true, &backgroundColor
);
2909 GetThemeTextColor(kThemeTextColorWhite
, gdDepth
, colorDevice
, &labelColor
);
2913 GetThemeBrushAsColor(kThemeBrushSecondaryHighlightColor
, 32, true, &backgroundColor
);
2914 GetThemeTextColor(kThemeTextColorBlack
, gdDepth
, colorDevice
, &labelColor
);
2916 wxMacCGContextStateSaver
cg( context
);
2918 CGContextSetRGBFillColor(context
, (CGFloat
)backgroundColor
.red
/ (CGFloat
)USHRT_MAX
,
2919 (CGFloat
)backgroundColor
.green
/ (CGFloat
)USHRT_MAX
,
2920 (CGFloat
)backgroundColor
.blue
/ (CGFloat
)USHRT_MAX
, (CGFloat
) 1.0);
2921 CGContextFillRect(context
, enclosingCGRect
);
2927 color
.GetRGBColor(&labelColor
);
2928 else if (list
->GetTextColour().Ok())
2929 list
->GetTextColour().GetRGBColor(&labelColor
);
2933 bgColor
.GetRGBColor(&backgroundColor
);
2934 CGContextSaveGState(context
);
2936 CGContextSetRGBFillColor(context
, (CGFloat
)backgroundColor
.red
/ (CGFloat
)USHRT_MAX
,
2937 (CGFloat
)backgroundColor
.green
/ (CGFloat
)USHRT_MAX
,
2938 (CGFloat
)backgroundColor
.blue
/ (CGFloat
)USHRT_MAX
, (CGFloat
) 1.0);
2939 CGContextFillRect(context
, enclosingCGRect
);
2941 CGContextRestoreGState(context
);
2945 calculateCGDrawingBounds(enclosingCGRect
, &iconCGRect
, &textCGRect
, (imgIndex
!= -1) );
2949 wxImageList
* imageList
= list
->GetImageList(wxIMAGE_LIST_SMALL
);
2950 if (imageList
&& imageList
->GetImageCount() > 0)
2952 wxBitmap bmp
= imageList
->GetBitmap(imgIndex
);
2953 IconRef icon
= bmp
.GetIconRef();
2955 wxMacCGContextStateSaver
cg( context
);
2957 CGContextTranslateCTM(context
, 0,iconCGRect
.origin
.y
+ CGRectGetMaxY(iconCGRect
));
2958 CGContextScaleCTM(context
,1.0f
,-1.0f
);
2959 PlotIconRefInContext(context
, &iconCGRect
, kAlignNone
,
2960 active
? kTransformNone
: kTransformDisabled
, NULL
,
2961 kPlotIconRefNormalFlags
, icon
);
2965 HIThemeTextHorizontalFlush hFlush
= kHIThemeTextHorizontalFlushLeft
;
2966 HIThemeTextInfo info
;
2968 #if wxOSX_USE_CORE_TEXT
2969 if ( UMAGetSystemVersion() >= 0x1050 )
2971 info
.version
= kHIThemeTextInfoVersionOne
;
2972 info
.fontID
= kThemeViewsFont
;
2975 info
.fontID
= kThemeSpecifiedFont
;
2976 info
.font
= (CTFontRef
) font
.OSXGetCTFont();
2981 #if wxOSX_USE_ATSU_TEXT
2984 info
.version
= kHIThemeTextInfoVersionZero
;
2985 info
.fontID
= kThemeViewsFont
;
2989 info
.fontID
= font
.MacGetThemeFontID();
2991 ::TextSize( (short)(font
.GetPointSize()) ) ;
2992 ::TextFace( font
.MacGetFontStyle() ) ;
2998 list
->GetColumn(listColumn
, item
);
2999 if (item
.GetMask() & wxLIST_MASK_FORMAT
)
3001 if (item
.GetAlign() == wxLIST_FORMAT_LEFT
)
3002 hFlush
= kHIThemeTextHorizontalFlushLeft
;
3003 else if (item
.GetAlign() == wxLIST_FORMAT_CENTER
)
3004 hFlush
= kHIThemeTextHorizontalFlushCenter
;
3005 else if (item
.GetAlign() == wxLIST_FORMAT_RIGHT
)
3007 hFlush
= kHIThemeTextHorizontalFlushRight
;
3008 textCGRect
.origin
.x
-= kItemPadding
; // give a little extra paddding
3012 info
.state
= active
? kThemeStateActive
: kThemeStateInactive
;
3013 info
.horizontalFlushness
= hFlush
;
3014 info
.verticalFlushness
= kHIThemeTextVerticalFlushCenter
;
3015 info
.options
= kHIThemeTextBoxOptionNone
;
3016 info
.truncationPosition
= kHIThemeTextTruncationEnd
;
3017 info
.truncationMaxLines
= 1;
3020 wxMacCGContextStateSaver
cg( context
);
3021 CGContextSetRGBFillColor (context
, (CGFloat
)labelColor
.red
/ (CGFloat
)USHRT_MAX
,
3022 (CGFloat
)labelColor
.green
/ (CGFloat
)USHRT_MAX
,
3023 (CGFloat
)labelColor
.blue
/ (CGFloat
)USHRT_MAX
, (CGFloat
) 1.0);
3025 HIThemeDrawTextBox(cfString
, &textCGRect
, &info
, context
, kHIThemeOrientationNormal
);
3029 if (savedState
!= NULL
)
3030 SetThemeDrawingState(savedState
, true);
3034 OSStatus
wxMacDataBrowserListCtrlControl::GetSetItemData(DataBrowserItemID itemID
,
3035 DataBrowserPropertyID property
,
3036 DataBrowserItemDataRef itemData
,
3037 Boolean changeValue
)
3042 DataBrowserTableViewColumnIndex listColumn
= 0;
3043 verify_noerr( GetColumnPosition( property
, &listColumn
) );
3045 OSStatus err
= errDataBrowserPropertyNotSupported
;
3046 wxListCtrl
* list
= wxDynamicCast( GetWXPeer() , wxListCtrl
);
3047 wxMacListCtrlItem
* lcItem
= NULL
;
3049 if (listColumn
>= 0)
3053 lcItem
= (wxMacListCtrlItem
*) itemID
;
3054 if (lcItem
&& lcItem
->HasColumnInfo(listColumn
)){
3055 wxListItem
* item
= lcItem
->GetColumnInfo(listColumn
);
3056 if (item
->GetMask() & wxLIST_MASK_TEXT
)
3057 text
= item
->GetText();
3058 if (item
->GetMask() & wxLIST_MASK_IMAGE
)
3059 imgIndex
= item
->GetImage();
3064 long itemNum
= (long)itemID
-1;
3065 if (itemNum
>= 0 && itemNum
< list
->GetItemCount())
3067 text
= list
->OnGetItemText( itemNum
, listColumn
);
3068 imgIndex
= list
->OnGetItemColumnImage( itemNum
, listColumn
);
3077 case kDataBrowserItemIsEditableProperty
:
3078 if ( list
&& list
->HasFlag( wxLC_EDIT_LABELS
) )
3080 verify_noerr(SetDataBrowserItemDataBooleanValue( itemData
, true ));
3085 if ( property
>= kMinColumnId
)
3087 if (!text
.IsEmpty()){
3088 wxCFStringRef
cfStr( text
, wxLocale::GetSystemEncoding() );
3089 err
= ::SetDataBrowserItemDataText( itemData
, cfStr
);
3095 if ( imgIndex
!= -1 )
3097 wxImageList
* imageList
= list
->GetImageList(wxIMAGE_LIST_SMALL
);
3098 if (imageList
&& imageList
->GetImageCount() > 0){
3099 wxBitmap bmp
= imageList
->GetBitmap(imgIndex
);
3100 IconRef icon
= bmp
.GetIconRef();
3101 ::SetDataBrowserItemDataIcon(itemData
, icon
);
3115 if ( property
>= kMinColumnId
)
3117 DataBrowserTableViewColumnIndex listColumn
= 0;
3118 verify_noerr( GetColumnPosition( property
, &listColumn
) );
3120 // TODO probably send the 'end edit' from here, as we
3121 // can then deal with the veto
3123 verify_noerr( GetDataBrowserItemDataText( itemData
, &sr
) ) ;
3124 wxCFStringRef
cfStr(sr
) ;;
3126 list
->SetItem( (long)itemData
-1 , listColumn
, cfStr
.AsString() ) ;
3130 lcItem
->SetColumnTextValue( listColumn
, cfStr
.AsString() );
3140 void wxMacDataBrowserListCtrlControl::ItemNotification(DataBrowserItemID itemID
,
3141 DataBrowserItemNotification message
,
3142 DataBrowserItemDataRef itemData
)
3144 wxMacListCtrlItem
*item
= NULL
;
3147 item
= (wxMacListCtrlItem
*) itemID
;
3150 // we want to depend on as little as possible to make sure tear-down of controls is safe
3151 if ( message
== kDataBrowserItemRemoved
)
3154 item
->Notification(this, message
, itemData
);
3157 else if ( message
== kDataBrowserItemAdded
)
3159 // we don't issue events on adding, the item is not really stored in the list yet, so we
3160 // avoid asserts by getting out now
3162 item
->Notification(this, message
, itemData
);
3166 wxListCtrl
*list
= wxDynamicCast( GetWXPeer() , wxListCtrl
);
3169 bool trigger
= false;
3171 wxListEvent
event( wxEVT_COMMAND_LIST_ITEM_SELECTED
, list
->GetId() );
3173 event
.SetEventObject( list
);
3174 if ( !list
->IsVirtual() )
3176 DataBrowserTableViewRowIndex result
= 0;
3177 verify_noerr( GetItemRow( itemID
, &result
) ) ;
3178 event
.m_itemIndex
= result
;
3182 event
.m_itemIndex
= (long)itemID
-1;
3184 event
.m_item
.m_itemId
= event
.m_itemIndex
;
3185 list
->GetItem(event
.m_item
);
3189 case kDataBrowserItemDeselected
:
3190 event
.SetEventType(wxEVT_COMMAND_LIST_ITEM_DESELECTED
);
3191 // as the generic implementation is also triggering this
3192 // event for single selection, we do the same (different than listbox)
3193 trigger
= !IsSelectionSuppressed();
3196 case kDataBrowserItemSelected
:
3197 trigger
= !IsSelectionSuppressed();
3201 case kDataBrowserItemDoubleClicked
:
3202 event
.SetEventType( wxEVT_COMMAND_LIST_ITEM_ACTIVATED
);
3206 case kDataBrowserEditStarted
:
3207 // TODO : how to veto ?
3208 event
.SetEventType( wxEVT_COMMAND_LIST_BEGIN_LABEL_EDIT
) ;
3212 case kDataBrowserEditStopped
:
3213 // TODO probably trigger only upon the value store callback, because
3214 // here IIRC we cannot veto
3215 event
.SetEventType( wxEVT_COMMAND_LIST_END_LABEL_EDIT
) ;
3225 // direct notification is not always having the listbox GetSelection() having in synch with event
3226 wxPostEvent( list
->GetEventHandler(), event
);
3231 Boolean
wxMacDataBrowserListCtrlControl::CompareItems(DataBrowserItemID itemOneID
,
3232 DataBrowserItemID itemTwoID
,
3233 DataBrowserPropertyID sortProperty
)
3236 bool retval
= false;
3238 wxString otherItemText
;
3240 long otherItemOrder
;
3242 DataBrowserTableViewColumnIndex colId
= 0;
3243 verify_noerr( GetColumnPosition( sortProperty
, &colId
) );
3245 wxListCtrl
* list
= wxDynamicCast( GetWXPeer() , wxListCtrl
);
3247 DataBrowserSortOrder sort
;
3248 verify_noerr(GetSortOrder(&sort
));
3254 wxMacListCtrlItem
* item
= (wxMacListCtrlItem
*)itemOneID
;
3255 wxMacListCtrlItem
* otherItem
= (wxMacListCtrlItem
*)itemTwoID
;
3257 itemOrder
= item
->GetOrder();
3258 otherItemOrder
= otherItem
->GetOrder();
3260 wxListCtrlCompare func
= list
->GetCompareFunc();
3266 if (item
&& item
->HasColumnInfo(0))
3267 item1
= item
->GetColumnInfo(0)->GetData();
3268 if (otherItem
&& otherItem
->HasColumnInfo(0))
3269 item2
= otherItem
->GetColumnInfo(0)->GetData();
3271 if (item1
> -1 && item2
> -1)
3273 int result
= func(item1
, item2
, list
->GetCompareFuncData());
3274 if (sort
== kDataBrowserOrderIncreasing
)
3281 // we can't use the native control's sorting abilities, so just
3283 return itemOrder
< otherItemOrder
;
3288 long itemNum
= (long)itemOneID
;
3289 long otherItemNum
= (long)itemTwoID
;
3291 // virtual listctrls don't support sorting
3292 return itemNum
< otherItemNum
;
3296 // fallback for undefined cases
3297 retval
= itemOneID
< itemTwoID
;
3303 wxMacDataBrowserListCtrlControl::~wxMacDataBrowserListCtrlControl()
3307 void wxMacDataBrowserListCtrlControl::MacSetColumnInfo( unsigned int row
, unsigned int column
, wxListItem
* item
)
3309 wxMacDataItem
* dataItem
= GetItemFromLine(row
);
3310 wxASSERT_MSG( dataItem
, wxT("could not obtain wxMacDataItem for row in MacSetColumnInfo. Is row a valid wxListCtrl row?") );
3313 wxMacListCtrlItem
* listItem
= static_cast<wxMacListCtrlItem
*>(dataItem
);
3314 bool hasInfo
= listItem
->HasColumnInfo( column
);
3315 listItem
->SetColumnInfo( column
, item
);
3316 listItem
->SetOrder(row
);
3317 UpdateState(dataItem
, item
);
3319 wxListCtrl
* list
= wxDynamicCast( GetWXPeer() , wxListCtrl
);
3321 // NB: When this call was made before a control was completely shown, it would
3322 // update the item prematurely (i.e. no text would be listed) and, on show,
3323 // only the sorted column would be refreshed, meaning only first column text labels
3324 // would be shown. Making sure not to update items until the control is visible
3325 // seems to fix this issue.
3326 if (hasInfo
&& list
->IsShown())
3328 DataBrowserTableViewColumnID id
= 0;
3329 verify_noerr( GetColumnIDFromIndex( column
, &id
) );
3330 UpdateItem( wxMacDataBrowserRootContainer
, listItem
, id
);
3335 // apply changes that need to happen immediately, rather than when the
3336 // databrowser control fires a callback.
3337 void wxMacDataBrowserListCtrlControl::UpdateState(wxMacDataItem
* dataItem
, wxListItem
* listItem
)
3339 bool isSelected
= IsItemSelected( dataItem
);
3340 bool isSelectedState
= (listItem
->GetState() == wxLIST_STATE_SELECTED
);
3342 // toggle the selection state if wxListInfo state and actual state don't match.
3343 if ( listItem
->GetMask() & wxLIST_MASK_STATE
&& isSelected
!= isSelectedState
)
3345 DataBrowserSetOption options
= kDataBrowserItemsAdd
;
3346 if (!isSelectedState
)
3347 options
= kDataBrowserItemsRemove
;
3348 SetSelectedItem(dataItem
, options
);
3350 // TODO: Set column width if item width > than current column width
3353 void wxMacDataBrowserListCtrlControl::MacGetColumnInfo( unsigned int row
, unsigned int column
, wxListItem
& item
)
3355 wxMacDataItem
* dataItem
= GetItemFromLine(row
);
3356 wxASSERT_MSG( dataItem
, wxT("could not obtain wxMacDataItem in MacGetColumnInfo. Is row a valid wxListCtrl row?") );
3357 // CS should this guard against dataItem = 0 ? , as item is not a pointer if (item) is not appropriate
3360 wxMacListCtrlItem
* listItem
= static_cast<wxMacListCtrlItem
*>(dataItem
);
3362 if (!listItem
->HasColumnInfo( column
))
3365 wxListItem
* oldItem
= listItem
->GetColumnInfo( column
);
3369 long mask
= item
.GetMask();
3371 // by default, get everything for backwards compatibility
3374 if ( mask
& wxLIST_MASK_TEXT
)
3375 item
.SetText(oldItem
->GetText());
3376 if ( mask
& wxLIST_MASK_IMAGE
)
3377 item
.SetImage(oldItem
->GetImage());
3378 if ( mask
& wxLIST_MASK_DATA
)
3379 item
.SetData(oldItem
->GetData());
3380 if ( mask
& wxLIST_MASK_STATE
)
3381 item
.SetState(oldItem
->GetState());
3382 if ( mask
& wxLIST_MASK_WIDTH
)
3383 item
.SetWidth(oldItem
->GetWidth());
3384 if ( mask
& wxLIST_MASK_FORMAT
)
3385 item
.SetAlign(oldItem
->GetAlign());
3387 item
.SetTextColour(oldItem
->GetTextColour());
3388 item
.SetBackgroundColour(oldItem
->GetBackgroundColour());
3389 item
.SetFont(oldItem
->GetFont());
3394 void wxMacDataBrowserListCtrlControl::MacInsertItem( unsigned int n
, wxListItem
* item
)
3397 wxMacDataItemBrowserControl::MacInsert(n
, new wxMacListCtrlItem() );
3398 MacSetColumnInfo(n
, 0, item
);
3401 wxMacListCtrlItem::wxMacListCtrlItem()
3403 m_rowItems
= wxListItemList();
3406 int wxMacListCtrlItem::GetColumnImageValue( unsigned int column
)
3408 if ( HasColumnInfo(column
) )
3409 return GetColumnInfo(column
)->GetImage();
3414 void wxMacListCtrlItem::SetColumnImageValue( unsigned int column
, int imageIndex
)
3416 if ( HasColumnInfo(column
) )
3417 GetColumnInfo(column
)->SetImage(imageIndex
);
3420 wxString
wxMacListCtrlItem::GetColumnTextValue( unsigned int column
)
3422 /* TODO CHECK REMOVE
3426 if ( HasColumnInfo(column
) )
3427 return GetColumnInfo(column
)->GetText();
3429 return wxEmptyString
;
3432 void wxMacListCtrlItem::SetColumnTextValue( unsigned int column
, const wxString
& text
)
3434 if ( HasColumnInfo(column
) )
3435 GetColumnInfo(column
)->SetText(text
);
3437 /* TODO CHECK REMOVE
3438 // for compatibility with superclass APIs
3444 wxListItem
* wxMacListCtrlItem::GetColumnInfo( unsigned int column
)
3446 wxASSERT_MSG( HasColumnInfo(column
), wxT("invalid column index in wxMacListCtrlItem") );
3447 return m_rowItems
[column
];
3450 bool wxMacListCtrlItem::HasColumnInfo( unsigned int column
)
3452 return !(m_rowItems
.find( column
) == m_rowItems
.end());
3455 void wxMacListCtrlItem::SetColumnInfo( unsigned int column
, wxListItem
* item
)
3458 if ( !HasColumnInfo(column
) )
3460 wxListItem
* listItem
= new wxListItem(*item
);
3461 m_rowItems
[column
] = listItem
;
3465 wxListItem
* listItem
= GetColumnInfo( column
);
3466 long mask
= item
->GetMask();
3467 if (mask
& wxLIST_MASK_TEXT
)
3468 listItem
->SetText(item
->GetText());
3469 if (mask
& wxLIST_MASK_DATA
)
3470 listItem
->SetData(item
->GetData());
3471 if (mask
& wxLIST_MASK_IMAGE
)
3472 listItem
->SetImage(item
->GetImage());
3473 if (mask
& wxLIST_MASK_STATE
)
3474 listItem
->SetState(item
->GetState());
3475 if (mask
& wxLIST_MASK_FORMAT
)
3476 listItem
->SetAlign(item
->GetAlign());
3477 if (mask
& wxLIST_MASK_WIDTH
)
3478 listItem
->SetWidth(item
->GetWidth());
3480 if ( item
->HasAttributes() )
3482 if ( listItem
->HasAttributes() )
3483 listItem
->GetAttributes()->AssignFrom(*item
->GetAttributes());
3486 listItem
->SetTextColour(item
->GetTextColour());
3487 listItem
->SetBackgroundColour(item
->GetBackgroundColour());
3488 listItem
->SetFont(item
->GetFont());
3494 int wxListCtrl::CalcColumnAutoWidth(int col
) const
3498 for ( int i
= 0; i
< GetItemCount(); i
++ )
3501 info
.SetMask(wxLIST_MASK_TEXT
| wxLIST_MASK_IMAGE
);
3503 info
.SetColumn(col
);
3506 const wxFont font
= info
.GetFont();
3510 GetTextExtent(info
.GetText(), &w
, NULL
, NULL
, NULL
, &font
);
3512 GetTextExtent(info
.GetText(), &w
, NULL
);
3514 w
+= 2 * kItemPadding
;
3516 if ( info
.GetImage() != -1 )
3519 width
= wxMax(width
, w
);
3525 #endif // wxUSE_LISTCTRL