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 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_ONITEMLABEL
) &&
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 static wxFont font
= wxFont(wxOSX_SYSTEM_FONT_VIEWS
);
806 // ----------------------------------------------------------------------------
807 // set/get/change style
808 // ----------------------------------------------------------------------------
810 // Add or remove a single window style
811 void wxListCtrl::SetSingleStyle(long style
, bool add
)
813 long flag
= GetWindowStyleFlag();
815 // Get rid of conflicting styles
818 if ( style
& wxLC_MASK_TYPE
)
819 flag
= flag
& ~wxLC_MASK_TYPE
;
820 if ( style
& wxLC_MASK_ALIGN
)
821 flag
= flag
& ~wxLC_MASK_ALIGN
;
822 if ( style
& wxLC_MASK_SORT
)
823 flag
= flag
& ~wxLC_MASK_SORT
;
831 SetWindowStyleFlag(flag
);
834 // Set the whole window style
835 void wxListCtrl::SetWindowStyleFlag(long flag
)
837 if ( flag
!= m_windowStyle
)
839 m_windowStyle
= flag
;
843 m_genericImpl
->SetWindowStyleFlag(flag
);
850 void wxListCtrl::DoSetSize( int x
, int y
, int width
, int height
, int sizeFlags
)
852 wxControl::DoSetSize(x
, y
, width
, height
, sizeFlags
);
855 m_genericImpl
->SetSize(0, 0, width
, height
, sizeFlags
);
857 // determine if we need a horizontal scrollbar, and add it if so
861 for (int column
= 0; column
< GetColumnCount(); column
++)
863 totalWidth
+= m_dbImpl
->GetColumnWidth( column
);
866 if ( !(m_dbImpl
->GetFlags() & wxHSCROLL
) )
868 Boolean vertScrollBar
;
869 GetDataBrowserHasScrollBars( m_dbImpl
->GetControlRef(), NULL
, &vertScrollBar
);
870 if (totalWidth
> width
)
871 SetDataBrowserHasScrollBars( m_dbImpl
->GetControlRef(), true, vertScrollBar
);
873 SetDataBrowserHasScrollBars( m_dbImpl
->GetControlRef(), false, vertScrollBar
);
878 wxSize
wxListCtrl::DoGetBestSize() const
880 return wxWindow::DoGetBestSize();
883 bool wxListCtrl::SetFont(const wxFont
& font
)
886 rv
= wxControl::SetFont(font
);
888 rv
= m_genericImpl
->SetFont(font
);
892 bool wxListCtrl::SetForegroundColour(const wxColour
& colour
)
896 rv
= m_genericImpl
->SetForegroundColour(colour
);
898 SetTextColour(colour
);
902 bool wxListCtrl::SetBackgroundColour(const wxColour
& colour
)
906 rv
= m_genericImpl
->SetBackgroundColour(colour
);
912 wxColour
wxListCtrl::GetBackgroundColour() const
915 return m_genericImpl
->GetBackgroundColour();
922 void wxListCtrl::Freeze ()
925 m_genericImpl
->Freeze();
929 void wxListCtrl::Thaw ()
932 m_genericImpl
->Thaw();
936 void wxListCtrl::Update ()
939 m_genericImpl
->Update();
943 // ----------------------------------------------------------------------------
945 // ----------------------------------------------------------------------------
947 // Gets information about this column
948 bool wxListCtrl::GetColumn(int col
, wxListItem
& item
) const
951 return m_genericImpl
->GetColumn(col
, item
);
957 wxColumnList::compatibility_iterator node
= m_colsInfo
.Item( col
);
958 wxASSERT_MSG( node
, wxT("invalid column index in wxMacListCtrlItem") );
959 wxListItem
* column
= node
->GetData();
961 long mask
= column
->GetMask();
962 if (mask
& wxLIST_MASK_TEXT
)
963 item
.SetText(column
->GetText());
964 if (mask
& wxLIST_MASK_DATA
)
965 item
.SetData(column
->GetData());
966 if (mask
& wxLIST_MASK_IMAGE
)
967 item
.SetImage(column
->GetImage());
968 if (mask
& wxLIST_MASK_STATE
)
969 item
.SetState(column
->GetState());
970 if (mask
& wxLIST_MASK_FORMAT
)
971 item
.SetAlign(column
->GetAlign());
972 if (mask
& wxLIST_MASK_WIDTH
)
973 item
.SetWidth(column
->GetWidth());
979 // Sets information about this column
980 bool wxListCtrl::SetColumn(int col
, wxListItem
& item
)
983 return m_genericImpl
->SetColumn(col
, item
);
987 wxASSERT_MSG( col
< (int)m_colsInfo
.GetCount(), wxT("invalid column index in wxMacListCtrlItem") );
989 long mask
= item
.GetMask();
992 GetColumn( col
, listItem
);
994 if (mask
& wxLIST_MASK_TEXT
)
995 listItem
.SetText(item
.GetText());
996 if (mask
& wxLIST_MASK_DATA
)
997 listItem
.SetData(item
.GetData());
998 if (mask
& wxLIST_MASK_IMAGE
)
999 listItem
.SetImage(item
.GetImage());
1000 if (mask
& wxLIST_MASK_STATE
)
1001 listItem
.SetState(item
.GetState());
1002 if (mask
& wxLIST_MASK_FORMAT
)
1003 listItem
.SetAlign(item
.GetAlign());
1004 if (mask
& wxLIST_MASK_WIDTH
)
1005 listItem
.SetWidth(item
.GetWidth());
1008 // change the appearance in the databrowser.
1009 DataBrowserListViewHeaderDesc columnDesc
;
1010 columnDesc
.version
=kDataBrowserListViewLatestHeaderDesc
;
1012 DataBrowserTableViewColumnID id
= 0;
1013 verify_noerr( m_dbImpl
->GetColumnIDFromIndex( col
, &id
) );
1014 verify_noerr( m_dbImpl
->GetHeaderDesc( id
, &columnDesc
) );
1017 if (item.GetMask() & wxLIST_MASK_TEXT)
1021 enc = GetFont().GetEncoding();
1023 enc = wxLocale::GetSystemEncoding();
1024 wxCFStringRef cfTitle;
1025 cfTitle.Assign( item.GetText() , enc );
1026 if(columnDesc.titleString)
1027 CFRelease(columnDesc.titleString);
1028 columnDesc.titleString = cfTitle;
1032 if (item
.GetMask() & wxLIST_MASK_IMAGE
&& item
.GetImage() != -1 )
1034 wxImageList
* imageList
= GetImageList(wxIMAGE_LIST_SMALL
);
1035 if (imageList
&& imageList
->GetImageCount() > 0 )
1037 wxBitmap bmp
= imageList
->GetBitmap( item
.GetImage() );
1038 IconRef icon
= bmp
.GetIconRef();
1039 columnDesc
.btnContentInfo
.u
.iconRef
= icon
;
1040 columnDesc
.btnContentInfo
.contentType
= kControlContentIconRef
;
1044 verify_noerr( m_dbImpl
->SetHeaderDesc( id
, &columnDesc
) );
1050 int wxListCtrl::GetColumnCount() const
1053 return m_genericImpl
->GetColumnCount();
1058 m_dbImpl
->GetColumnCount(&count
);
1065 // Gets the column width
1066 int wxListCtrl::GetColumnWidth(int col
) const
1069 return m_genericImpl
->GetColumnWidth(col
);
1073 return m_dbImpl
->GetColumnWidth(col
);
1079 // Sets the column width
1080 bool wxListCtrl::SetColumnWidth(int col
, int width
)
1083 return m_genericImpl
->SetColumnWidth(col
, width
);
1087 if ( width
== wxLIST_AUTOSIZE_USEHEADER
)
1089 width
= 150; // FIXME
1094 for (int column
= 0; column
< GetColumnCount(); column
++)
1097 GetColumn(column
, colInfo
);
1099 colInfo
.SetWidth(width
);
1100 SetColumn(column
, colInfo
);
1102 const int mywidth
= (width
== wxLIST_AUTOSIZE
)
1103 ? CalcColumnAutoWidth(column
) : width
;
1104 m_dbImpl
->SetColumnWidth(column
, mywidth
);
1109 if ( width
== wxLIST_AUTOSIZE
)
1110 width
= CalcColumnAutoWidth(col
);
1113 GetColumn(col
, colInfo
);
1115 colInfo
.SetWidth(width
);
1116 SetColumn(col
, colInfo
);
1117 m_dbImpl
->SetColumnWidth(col
, width
);
1125 // Gets the number of items that can fit vertically in the
1126 // visible area of the list control (list or report view)
1127 // or the total number of items in the list control (icon
1128 // or small icon view)
1129 int wxListCtrl::GetCountPerPage() const
1132 return m_genericImpl
->GetCountPerPage();
1137 m_dbImpl
->GetDefaultRowHeight( &height
);
1139 return GetClientSize().y
/ height
;
1145 // Gets the edit control for editing labels.
1146 wxTextCtrl
* wxListCtrl::GetEditControl() const
1149 return m_genericImpl
->GetEditControl();
1154 // Gets information about the item
1155 bool wxListCtrl::GetItem(wxListItem
& info
) const
1158 return m_genericImpl
->GetItem(info
);
1164 if (info
.m_itemId
>= 0 && info
.m_itemId
< GetItemCount())
1166 m_dbImpl
->MacGetColumnInfo(info
.m_itemId
, info
.m_col
, info
);
1167 // MacGetColumnInfo returns erroneous information in the state field, so zero it.
1169 if (info
.GetMask() & wxLIST_MASK_STATE
)
1171 DataBrowserItemID id
= (DataBrowserItemID
)m_dbImpl
->GetItemFromLine(info
.m_itemId
);
1172 if (IsDataBrowserItemSelected( m_dbImpl
->GetControlRef(), id
))
1173 info
.SetState(info
.GetState() | wxLIST_STATE_SELECTED
);
1179 if (info
.m_itemId
>= 0 && info
.m_itemId
< GetItemCount())
1181 info
.SetText( OnGetItemText(info
.m_itemId
, info
.m_col
) );
1182 info
.SetImage( OnGetItemColumnImage(info
.m_itemId
, info
.m_col
) );
1183 if (info
.GetMask() & wxLIST_MASK_STATE
)
1185 if (IsDataBrowserItemSelected( m_dbImpl
->GetControlRef(), info
.m_itemId
+1 ))
1186 info
.SetState(info
.GetState() | wxLIST_STATE_SELECTED
);
1189 wxListItemAttr
* attrs
= OnGetItemAttr( info
.m_itemId
);
1192 info
.SetFont( attrs
->GetFont() );
1193 info
.SetBackgroundColour( attrs
->GetBackgroundColour() );
1194 info
.SetTextColour( attrs
->GetTextColour() );
1199 bool success
= true;
1203 // Sets information about the item
1204 bool wxListCtrl::SetItem(wxListItem
& info
)
1207 return m_genericImpl
->SetItem(info
);
1210 m_dbImpl
->MacSetColumnInfo( info
.m_itemId
, info
.m_col
, &info
);
1215 long wxListCtrl::SetItem(long index
, int col
, const wxString
& label
, int imageId
)
1218 return m_genericImpl
->SetItem(index
, col
, label
, imageId
);
1221 info
.m_text
= label
;
1222 info
.m_mask
= wxLIST_MASK_TEXT
;
1223 info
.m_itemId
= index
;
1227 info
.m_image
= imageId
;
1228 info
.m_mask
|= wxLIST_MASK_IMAGE
;
1230 return SetItem(info
);
1234 // Gets the item state
1235 int wxListCtrl::GetItemState(long item
, long stateMask
) const
1238 return m_genericImpl
->GetItemState(item
, stateMask
);
1242 if ( HasFlag(wxLC_VIRTUAL
) )
1244 if (stateMask
== wxLIST_STATE_SELECTED
)
1246 if (IsDataBrowserItemSelected( m_dbImpl
->GetControlRef(), item
+1 ))
1247 return wxLIST_STATE_SELECTED
;
1256 info
.m_mask
= wxLIST_MASK_STATE
;
1257 info
.m_stateMask
= stateMask
;
1258 info
.m_itemId
= item
;
1263 return info
.m_state
;
1270 // Sets the item state
1271 bool wxListCtrl::SetItemState(long item
, long state
, long stateMask
)
1274 return m_genericImpl
->SetItemState(item
, state
, stateMask
);
1278 DataBrowserSetOption option
= kDataBrowserItemsAdd
;
1279 if ( (stateMask
& wxLIST_STATE_SELECTED
) && state
== 0 )
1280 option
= kDataBrowserItemsRemove
;
1284 if ( HasFlag(wxLC_VIRTUAL
) )
1286 wxMacDataItemBrowserSelectionSuppressor
suppressor(m_dbImpl
);
1287 m_dbImpl
->SetSelectedAllItems(option
);
1291 for(int i
= 0; i
< GetItemCount();i
++)
1295 info
.m_mask
= wxLIST_MASK_STATE
;
1296 info
.m_stateMask
= stateMask
;
1297 info
.m_state
= state
;
1304 if ( HasFlag(wxLC_VIRTUAL
) )
1306 long itemID
= item
+1;
1307 bool isSelected
= IsDataBrowserItemSelected(m_dbImpl
->GetControlRef(), (DataBrowserItemID
)itemID
);
1308 bool isSelectedState
= (state
== wxLIST_STATE_SELECTED
);
1310 // toggle the selection state if wxListInfo state and actual state don't match.
1311 if ( (stateMask
& wxLIST_STATE_SELECTED
) && isSelected
!= isSelectedState
)
1313 SetDataBrowserSelectedItems(m_dbImpl
->GetControlRef(), 1, (DataBrowserItemID
*)&itemID
, option
);
1319 info
.m_itemId
= item
;
1320 info
.m_mask
= wxLIST_MASK_STATE
;
1321 info
.m_stateMask
= stateMask
;
1322 info
.m_state
= state
;
1323 return SetItem(info
);
1330 // Sets the item image
1331 bool wxListCtrl::SetItemImage(long item
, int image
, int WXUNUSED(selImage
))
1333 return SetItemColumnImage(item
, 0, image
);
1336 // Sets the item image
1337 bool wxListCtrl::SetItemColumnImage(long item
, long column
, int image
)
1340 return m_genericImpl
->SetItemColumnImage(item
, column
, image
);
1344 info
.m_mask
= wxLIST_MASK_IMAGE
;
1345 info
.m_image
= image
;
1346 info
.m_itemId
= item
;
1347 info
.m_col
= column
;
1349 return SetItem(info
);
1352 // Gets the item text
1353 wxString
wxListCtrl::GetItemText(long item
, int column
) const
1356 return m_genericImpl
->GetItemText(item
, column
);
1360 info
.m_mask
= wxLIST_MASK_TEXT
;
1361 info
.m_itemId
= item
;
1362 info
.m_col
= column
;
1365 return wxEmptyString
;
1369 // Sets the item text
1370 void wxListCtrl::SetItemText(long item
, const wxString
& str
)
1373 return m_genericImpl
->SetItemText(item
, str
);
1377 info
.m_mask
= wxLIST_MASK_TEXT
;
1378 info
.m_itemId
= item
;
1384 // Gets the item data
1385 long wxListCtrl::GetItemData(long item
) const
1388 return m_genericImpl
->GetItemData(item
);
1392 info
.m_mask
= wxLIST_MASK_DATA
;
1393 info
.m_itemId
= item
;
1400 // Sets the item data
1401 bool wxListCtrl::SetItemPtrData(long item
, wxUIntPtr data
)
1404 return m_genericImpl
->SetItemData(item
, data
);
1408 info
.m_mask
= wxLIST_MASK_DATA
;
1409 info
.m_itemId
= item
;
1412 return SetItem(info
);
1415 wxRect
wxListCtrl::GetViewRect() const
1417 wxASSERT_MSG( !HasFlag(wxLC_REPORT
| wxLC_LIST
),
1418 wxT("wxListCtrl::GetViewRect() only works in icon mode") );
1421 return m_genericImpl
->GetViewRect();
1427 bool wxListCtrl::GetSubItemRect( long item
, long subItem
, wxRect
& rect
, int code
) const
1430 return m_genericImpl
->GetSubItemRect(item
, subItem
, rect
, code
);
1432 // TODO: implement for DataBrowser implementation
1436 // Gets the item rectangle
1437 bool wxListCtrl::GetItemRect(long item
, wxRect
& rect
, int code
) const
1440 return m_genericImpl
->GetItemRect(item
, rect
, code
);
1445 DataBrowserItemID id
;
1447 DataBrowserTableViewColumnID col
= 0;
1448 verify_noerr( m_dbImpl
->GetColumnIDFromIndex( 0, &col
) );
1451 DataBrowserPropertyPart part
= kDataBrowserPropertyEnclosingPart
;
1452 if ( code
== wxLIST_RECT_LABEL
)
1453 part
= kDataBrowserPropertyTextPart
;
1454 else if ( code
== wxLIST_RECT_ICON
)
1455 part
= kDataBrowserPropertyIconPart
;
1457 if ( !(GetWindowStyleFlag() & wxLC_VIRTUAL
) )
1459 wxMacDataItem
* thisItem
= m_dbImpl
->GetItemFromLine(item
);
1460 id
= (DataBrowserItemID
) thisItem
;
1465 GetDataBrowserItemPartBounds( m_dbImpl
->GetControlRef(), id
, col
, part
, &bounds
);
1467 rect
.x
= bounds
.left
;
1468 rect
.y
= bounds
.top
;
1469 rect
.width
= bounds
.right
- bounds
.left
; //GetClientSize().x; // we need the width of the whole row, not just the item.
1470 rect
.height
= bounds
.bottom
- bounds
.top
;
1471 //fprintf("id = %d, bounds = %d, %d, %d, %d\n", id, rect.x, rect.y, rect.width, rect.height);
1476 // Gets the item position
1477 bool wxListCtrl::GetItemPosition(long item
, wxPoint
& pos
) const
1480 return m_genericImpl
->GetItemPosition(item
, pos
);
1482 bool success
= false;
1487 GetItemRect(item
, itemRect
);
1488 pos
= itemRect
.GetPosition();
1495 // Sets the item position.
1496 bool wxListCtrl::SetItemPosition(long item
, const wxPoint
& pos
)
1499 return m_genericImpl
->SetItemPosition(item
, pos
);
1504 // Gets the number of items in the list control
1505 int wxListCtrl::GetItemCount() const
1508 return m_genericImpl
->GetItemCount();
1511 return m_dbImpl
->MacGetCount();
1516 void wxListCtrl::SetItemSpacing( int spacing
, bool isSmall
)
1519 m_genericImpl
->SetItemSpacing(spacing
, isSmall
);
1522 wxSize
wxListCtrl::GetItemSpacing() const
1525 return m_genericImpl
->GetItemSpacing();
1527 return wxSize(0, 0);
1530 void wxListCtrl::SetItemTextColour( long item
, const wxColour
&col
)
1534 m_genericImpl
->SetItemTextColour(item
, col
);
1539 info
.m_itemId
= item
;
1540 info
.SetTextColour( col
);
1544 wxColour
wxListCtrl::GetItemTextColour( long item
) const
1547 return m_genericImpl
->GetItemTextColour(item
);
1553 return info
.GetTextColour();
1555 return wxNullColour
;
1558 void wxListCtrl::SetItemBackgroundColour( long item
, const wxColour
&col
)
1562 m_genericImpl
->SetItemBackgroundColour(item
, col
);
1567 info
.m_itemId
= item
;
1568 info
.SetBackgroundColour( col
);
1572 wxColour
wxListCtrl::GetItemBackgroundColour( long item
) const
1575 return m_genericImpl
->GetItemBackgroundColour(item
);
1581 return info
.GetBackgroundColour();
1583 return wxNullColour
;
1586 void wxListCtrl::SetItemFont( long item
, const wxFont
&f
)
1590 m_genericImpl
->SetItemFont(item
, f
);
1595 info
.m_itemId
= item
;
1600 wxFont
wxListCtrl::GetItemFont( long item
) const
1603 return m_genericImpl
->GetItemFont(item
);
1609 return info
.GetFont();
1615 // Gets the number of selected items in the list control
1616 int wxListCtrl::GetSelectedItemCount() const
1619 return m_genericImpl
->GetSelectedItemCount();
1622 return m_dbImpl
->GetSelectedItemCount(NULL
, true);
1627 // Gets the text colour of the listview
1628 wxColour
wxListCtrl::GetTextColour() const
1631 return m_genericImpl
->GetTextColour();
1633 // TODO: we need owner drawn list items to customize text color.
1637 return wxNullColour
;
1640 // Sets the text colour of the listview
1641 void wxListCtrl::SetTextColour(const wxColour
& col
)
1645 m_genericImpl
->SetTextColour(col
);
1653 // Gets the index of the topmost visible item when in
1654 // list or report view
1655 long wxListCtrl::GetTopItem() const
1658 return m_genericImpl
->GetTopItem();
1663 long item
= HitTest( wxPoint(1, 1), flags
);
1664 if (flags
== wxLIST_HITTEST_ONITEM
)
1671 // Searches for an item, starting from 'item'.
1672 // 'geometry' is one of
1673 // wxLIST_NEXT_ABOVE/ALL/BELOW/LEFT/RIGHT.
1674 // 'state' is a state bit flag, one or more of
1675 // wxLIST_STATE_DROPHILITED/FOCUSED/SELECTED/CUT.
1676 // item can be -1 to find the first item that matches the
1678 // Returns the item or -1 if unsuccessful.
1679 long wxListCtrl::GetNextItem(long item
, int geom
, int state
) const
1682 return m_genericImpl
->GetNextItem(item
, geom
, state
);
1684 // TODO: implement all geometry and state options?
1687 if ( geom
== wxLIST_NEXT_ALL
|| geom
== wxLIST_NEXT_BELOW
)
1689 long count
= m_dbImpl
->MacGetCount() ;
1690 for ( long line
= item
+ 1 ; line
< count
; 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
) )
1707 if ( geom
== wxLIST_NEXT_ABOVE
)
1711 item2
= m_dbImpl
->MacGetCount();
1713 for ( long line
= item2
- 1 ; line
>= 0; line
-- )
1715 DataBrowserItemID id
= line
+ 1;
1717 id
= (DataBrowserItemID
)m_dbImpl
->GetItemFromLine(line
);
1719 if ( (state
& wxLIST_STATE_FOCUSED
) && (m_current
== line
))
1722 if ( (state
== wxLIST_STATE_DONTCARE
) )
1725 if ( (state
& wxLIST_STATE_SELECTED
) && IsDataBrowserItemSelected(m_dbImpl
->GetControlRef(), id
) )
1735 wxImageList
*wxListCtrl::GetImageList(int which
) const
1738 return m_genericImpl
->GetImageList(which
);
1740 if ( which
== wxIMAGE_LIST_NORMAL
)
1742 return m_imageListNormal
;
1744 else if ( which
== wxIMAGE_LIST_SMALL
)
1746 return m_imageListSmall
;
1748 else if ( which
== wxIMAGE_LIST_STATE
)
1750 return m_imageListState
;
1755 void wxListCtrl::SetImageList(wxImageList
*imageList
, int which
)
1759 m_genericImpl
->SetImageList(imageList
, which
);
1763 if ( which
== wxIMAGE_LIST_NORMAL
)
1765 if (m_ownsImageListNormal
) delete m_imageListNormal
;
1766 m_imageListNormal
= imageList
;
1767 m_ownsImageListNormal
= false;
1769 else if ( which
== wxIMAGE_LIST_SMALL
)
1771 if (m_ownsImageListSmall
) delete m_imageListSmall
;
1772 m_imageListSmall
= imageList
;
1773 m_ownsImageListSmall
= false;
1775 else if ( which
== wxIMAGE_LIST_STATE
)
1777 if (m_ownsImageListState
) delete m_imageListState
;
1778 m_imageListState
= imageList
;
1779 m_ownsImageListState
= false;
1783 void wxListCtrl::AssignImageList(wxImageList
*imageList
, int which
)
1787 m_genericImpl
->AssignImageList(imageList
, which
);
1791 SetImageList(imageList
, which
);
1792 if ( which
== wxIMAGE_LIST_NORMAL
)
1793 m_ownsImageListNormal
= true;
1794 else if ( which
== wxIMAGE_LIST_SMALL
)
1795 m_ownsImageListSmall
= true;
1796 else if ( which
== wxIMAGE_LIST_STATE
)
1797 m_ownsImageListState
= true;
1800 // ----------------------------------------------------------------------------
1802 // ----------------------------------------------------------------------------
1804 // Arranges the items
1805 bool wxListCtrl::Arrange(int flag
)
1808 return m_genericImpl
->Arrange(flag
);
1813 bool wxListCtrl::DeleteItem(long item
)
1816 return m_genericImpl
->DeleteItem(item
);
1820 m_dbImpl
->MacDelete(item
);
1821 wxListEvent
event( wxEVT_COMMAND_LIST_DELETE_ITEM
, GetId() );
1822 event
.SetEventObject( this );
1823 event
.m_itemIndex
= item
;
1824 HandleWindowEvent( event
);
1830 // Deletes all items
1831 bool wxListCtrl::DeleteAllItems()
1835 return m_genericImpl
->DeleteAllItems();
1839 m_dbImpl
->MacClear();
1840 wxListEvent
event( wxEVT_COMMAND_LIST_DELETE_ALL_ITEMS
, GetId() );
1841 event
.SetEventObject( this );
1842 HandleWindowEvent( event
);
1847 // Deletes all items
1848 bool wxListCtrl::DeleteAllColumns()
1851 return m_genericImpl
->DeleteAllColumns();
1856 m_dbImpl
->GetColumnCount(&cols
);
1857 for (UInt32 col
= 0; col
< cols
; col
++)
1867 bool wxListCtrl::DeleteColumn(int col
)
1870 return m_genericImpl
->DeleteColumn(col
);
1874 OSStatus err
= m_dbImpl
->RemoveColumn(col
);
1875 return err
== noErr
;
1881 // Clears items, and columns if there are any.
1882 void wxListCtrl::ClearAll()
1886 m_genericImpl
->ClearAll();
1897 wxTextCtrl
* wxListCtrl::EditLabel(long item
, wxClassInfo
* textControlClass
)
1900 return m_genericImpl
->EditLabel(item
, textControlClass
);
1904 wxCHECK_MSG( (item
>= 0) && ((long)item
< GetItemCount()), NULL
,
1905 wxT("wrong index in wxListCtrl::EditLabel()") );
1907 wxASSERT_MSG( textControlClass
->IsKindOf(CLASSINFO(wxTextCtrl
)),
1908 wxT("EditLabel() needs a text control") );
1910 wxListEvent
le( wxEVT_COMMAND_LIST_BEGIN_LABEL_EDIT
, GetParent()->GetId() );
1911 le
.SetEventObject( this );
1912 le
.m_itemIndex
= item
;
1914 GetItem( le
.m_item
);
1916 if ( GetParent()->HandleWindowEvent( le
) && !le
.IsAllowed() )
1918 // vetoed by user code
1922 wxTextCtrl
* const text
= (wxTextCtrl
*)textControlClass
->CreateObject();
1923 m_textctrlWrapper
= new wxListCtrlTextCtrlWrapper(this, text
, item
);
1924 return m_textctrlWrapper
->GetText();
1929 // End label editing, optionally cancelling the edit
1930 bool wxListCtrl::EndEditLabel(bool WXUNUSED(cancel
))
1932 // TODO: generic impl. doesn't have this method - is it needed for us?
1934 return true; // m_genericImpl->EndEditLabel(cancel);
1938 DataBrowserTableViewColumnID id
= 0;
1939 verify_noerr( m_dbImpl
->GetColumnIDFromIndex( 0, &id
) );
1940 verify_noerr( SetDataBrowserEditItem(m_dbImpl
->GetControlRef(), kDataBrowserNoItem
, id
) );
1945 // Ensures this item is visible
1946 bool wxListCtrl::EnsureVisible(long item
)
1949 return m_genericImpl
->EnsureVisible(item
);
1953 wxMacDataItem
* dataItem
= m_dbImpl
->GetItemFromLine(item
);
1954 m_dbImpl
->RevealItem(dataItem
, kDataBrowserRevealWithoutSelecting
);
1960 // Find an item whose label matches this string, starting from the item after 'start'
1961 // or the beginning if 'start' is -1.
1962 long wxListCtrl::FindItem(long start
, const wxString
& str
, bool partial
)
1965 return m_genericImpl
->FindItem(start
, str
, partial
);
1967 wxString str_upper
= str
.Upper();
1972 long count
= GetItemCount();
1976 wxString line_upper
= GetItemText(idx
).Upper();
1979 if (line_upper
== str_upper
)
1984 if (line_upper
.find(str_upper
) == 0)
1994 // Find an item whose data matches this data, starting from the item after 'start'
1995 // or the beginning if 'start' is -1.
1996 long wxListCtrl::FindItem(long start
, long data
)
1999 return m_genericImpl
->FindItem(start
, data
);
2004 long count
= GetItemCount();
2008 if (GetItemData(idx
) == data
)
2016 // Find an item nearest this position in the specified direction, starting from
2017 // the item after 'start' or the beginning if 'start' is -1.
2018 long wxListCtrl::FindItem(long start
, const wxPoint
& pt
, int direction
)
2021 return m_genericImpl
->FindItem(start
, pt
, direction
);
2025 static void calculateCGDrawingBounds(CGRect inItemRect
, CGRect
*outIconRect
, CGRect
*outTextRect
, bool hasIcon
);
2027 // Determines which item (if any) is at the specified point,
2028 // giving details in 'flags' (see wxLIST_HITTEST_... flags above)
2030 wxListCtrl::HitTest(const wxPoint
& point
, int& flags
, long *ptrSubItem
) const
2036 return m_genericImpl
->HitTest(point
, flags
, ptrSubItem
);
2038 flags
= wxLIST_HITTEST_NOWHERE
;
2041 int colHeaderHeight
= 22; // TODO: Find a way to get this value from the db control?
2042 UInt16 rowHeight
= 0;
2043 m_dbImpl
->GetDefaultRowHeight(&rowHeight
);
2046 // get the actual row by taking scroll position into account
2047 UInt32 offsetX
, offsetY
;
2048 m_dbImpl
->GetScrollPosition( &offsetY
, &offsetX
);
2051 if ( !(GetWindowStyleFlag() & wxLC_NO_HEADER
) )
2052 y
-= colHeaderHeight
;
2057 int row
= y
/ rowHeight
;
2058 DataBrowserItemID id
;
2059 m_dbImpl
->GetItemID( (DataBrowserTableViewRowIndex
) row
, &id
);
2061 CGPoint click_point
= CGPointMake( point
.x
, point
.y
);
2062 if (row
< GetItemCount() )
2065 for( column
= 0; column
< GetColumnCount(); column
++ )
2068 CGRect enclosingCGRect
, iconCGRect
, textCGRect
;
2070 wxMacListCtrlItem
* lcItem
;
2072 WXUNUSED_UNLESS_DEBUG( OSStatus status
= ) m_dbImpl
->GetItemPartBounds( id
, kMinColumnId
+ column
, kDataBrowserPropertyEnclosingPart
, &enclosingRect
);
2073 wxASSERT( status
== noErr
);
2075 enclosingCGRect
= CGRectMake(enclosingRect
.left
,
2077 enclosingRect
.right
- enclosingRect
.left
,
2078 enclosingRect
.bottom
- enclosingRect
.top
);
2082 if ( !(GetWindowStyleFlag() & wxLC_VIRTUAL
) )
2084 lcItem
= (wxMacListCtrlItem
*) id
;
2085 if (lcItem
->HasColumnInfo(column
))
2087 wxListItem
* item
= lcItem
->GetColumnInfo(column
);
2089 if (item
->GetMask() & wxLIST_MASK_IMAGE
)
2091 imgIndex
= item
->GetImage();
2097 long itemNum
= (long)id
-1;
2098 if (itemNum
>= 0 && itemNum
< GetItemCount())
2100 imgIndex
= OnGetItemColumnImage( itemNum
, column
);
2105 calculateCGDrawingBounds(enclosingCGRect
, &iconCGRect
, &textCGRect
, (imgIndex
!= -1) );
2107 if ( CGRectContainsPoint( iconCGRect
, click_point
) )
2109 flags
= wxLIST_HITTEST_ONITEMICON
;
2111 *ptrSubItem
= column
;
2114 else if ( CGRectContainsPoint( textCGRect
, click_point
) )
2116 flags
= wxLIST_HITTEST_ONITEMLABEL
;
2118 *ptrSubItem
= column
;
2123 if ( !(GetWindowStyleFlag() & wxLC_VIRTUAL
) )
2125 wxMacListCtrlItem
* lcItem
;
2126 lcItem
= (wxMacListCtrlItem
*) id
;
2129 flags
= wxLIST_HITTEST_ONITEM
;
2131 *ptrSubItem
= column
;
2137 flags
= wxLIST_HITTEST_ONITEM
;
2139 *ptrSubItem
= column
;
2145 if ( wxControl::HitTest( point
) )
2146 flags
= wxLIST_HITTEST_NOWHERE
;
2153 int wxListCtrl::GetScrollPos(int orient
) const
2156 return m_genericImpl
->GetScrollPos(orient
);
2160 UInt32 offsetX
, offsetY
;
2161 m_dbImpl
->GetScrollPosition( &offsetY
, &offsetX
);
2162 if ( orient
== wxHORIZONTAL
)
2171 // Inserts an item, returning the index of the new item if successful,
2173 long wxListCtrl::InsertItem(wxListItem
& info
)
2175 wxASSERT_MSG( !IsVirtual(), wxT("can't be used with virtual controls") );
2178 return m_genericImpl
->InsertItem(info
);
2180 if (m_dbImpl
&& !IsVirtual())
2182 int count
= GetItemCount();
2184 if (info
.m_itemId
> count
)
2185 info
.m_itemId
= count
;
2187 m_dbImpl
->MacInsertItem(info
.m_itemId
, &info
);
2189 wxListEvent
event( wxEVT_COMMAND_LIST_INSERT_ITEM
, GetId() );
2190 event
.SetEventObject( this );
2191 event
.m_itemIndex
= info
.m_itemId
;
2192 HandleWindowEvent( event
);
2193 return info
.m_itemId
;
2198 long wxListCtrl::InsertItem(long index
, const wxString
& label
)
2201 return m_genericImpl
->InsertItem(index
, label
);
2204 info
.m_text
= label
;
2205 info
.m_mask
= wxLIST_MASK_TEXT
;
2206 info
.m_itemId
= index
;
2207 return InsertItem(info
);
2210 // Inserts an image item
2211 long wxListCtrl::InsertItem(long index
, int imageIndex
)
2214 return m_genericImpl
->InsertItem(index
, imageIndex
);
2217 info
.m_image
= imageIndex
;
2218 info
.m_mask
= wxLIST_MASK_IMAGE
;
2219 info
.m_itemId
= index
;
2220 return InsertItem(info
);
2223 // Inserts an image/string item
2224 long wxListCtrl::InsertItem(long index
, const wxString
& label
, int imageIndex
)
2227 return m_genericImpl
->InsertItem(index
, label
, imageIndex
);
2230 info
.m_image
= imageIndex
;
2231 info
.m_text
= label
;
2232 info
.m_mask
= wxLIST_MASK_IMAGE
| wxLIST_MASK_TEXT
;
2233 info
.m_itemId
= index
;
2234 return InsertItem(info
);
2237 // For list view mode (only), inserts a column.
2238 long wxListCtrl::InsertColumn(long col
, wxListItem
& item
)
2241 return m_genericImpl
->InsertColumn(col
, item
);
2245 int width
= item
.GetWidth();
2246 if ( !(item
.GetMask() & wxLIST_MASK_WIDTH
) )
2249 DataBrowserPropertyType type
= kDataBrowserCustomType
; //kDataBrowserTextType;
2250 wxImageList
* imageList
= GetImageList(wxIMAGE_LIST_SMALL
);
2251 if (imageList
&& imageList
->GetImageCount() > 0)
2253 wxBitmap bmp
= imageList
->GetBitmap(0);
2255 // type = kDataBrowserIconAndTextType;
2258 SInt16 just
= teFlushDefault
;
2259 if (item
.GetMask() & wxLIST_MASK_FORMAT
)
2261 if (item
.GetAlign() == wxLIST_FORMAT_LEFT
)
2263 else if (item
.GetAlign() == wxLIST_FORMAT_CENTER
)
2265 else if (item
.GetAlign() == wxLIST_FORMAT_RIGHT
)
2266 just
= teFlushRight
;
2268 m_dbImpl
->InsertColumn(col
, type
, item
.GetText(), just
, width
);
2270 wxListItem
* listItem
= new wxListItem(item
);
2271 m_colsInfo
.Insert( col
, listItem
);
2272 SetColumn(col
, item
);
2274 // set/remove options based on the wxListCtrl type.
2275 DataBrowserTableViewColumnID id
;
2276 m_dbImpl
->GetColumnIDFromIndex(col
, &id
);
2277 DataBrowserPropertyFlags flags
;
2278 verify_noerr(m_dbImpl
->GetPropertyFlags(id
, &flags
));
2279 if (GetWindowStyleFlag() & wxLC_EDIT_LABELS
)
2280 flags
|= kDataBrowserPropertyIsEditable
;
2282 if (GetWindowStyleFlag() & wxLC_VIRTUAL
){
2283 flags
&= ~kDataBrowserListViewSortableColumn
;
2285 verify_noerr(m_dbImpl
->SetPropertyFlags(id
, flags
));
2291 long wxListCtrl::InsertColumn(long col
,
2292 const wxString
& heading
,
2297 return m_genericImpl
->InsertColumn(col
, heading
, format
, width
);
2300 item
.m_mask
= wxLIST_MASK_TEXT
| wxLIST_MASK_FORMAT
;
2301 item
.m_text
= heading
;
2304 item
.m_mask
|= wxLIST_MASK_WIDTH
;
2305 item
.m_width
= width
;
2307 item
.m_format
= format
;
2309 return InsertColumn(col
, item
);
2312 // scroll the control by the given number of pixels (exception: in list view,
2313 // dx is interpreted as number of columns)
2314 bool wxListCtrl::ScrollList(int dx
, int dy
)
2317 return m_genericImpl
->ScrollList(dx
, dy
);
2321 m_dbImpl
->SetScrollPosition(dx
, dy
);
2327 bool wxListCtrl::SortItems(wxListCtrlCompare fn
, wxIntPtr data
)
2330 return m_genericImpl
->SortItems(fn
, data
);
2335 m_compareFuncData
= data
;
2336 SortDataBrowserContainer( m_dbImpl
->GetControlRef(), kDataBrowserNoItem
, true);
2338 // we need to do this after each call, else we get a crash from wxPython when
2339 // SortItems is called the second time.
2340 m_compareFunc
= NULL
;
2341 m_compareFuncData
= 0;
2347 void wxListCtrl::OnRenameTimer()
2349 wxCHECK_RET( HasCurrent(), wxT("unexpected rename timer") );
2351 EditLabel( m_current
);
2354 bool wxListCtrl::OnRenameAccept(long itemEdit
, const wxString
& value
)
2356 wxListEvent
le( wxEVT_COMMAND_LIST_END_LABEL_EDIT
, GetId() );
2357 le
.SetEventObject( this );
2358 le
.m_itemIndex
= itemEdit
;
2360 GetItem( le
.m_item
);
2361 le
.m_item
.m_text
= value
;
2362 return !HandleWindowEvent( le
) ||
2366 void wxListCtrl::OnRenameCancelled(long itemEdit
)
2368 // let owner know that the edit was cancelled
2369 wxListEvent
le( wxEVT_COMMAND_LIST_END_LABEL_EDIT
, GetParent()->GetId() );
2371 le
.SetEditCanceled(true);
2373 le
.SetEventObject( this );
2374 le
.m_itemIndex
= itemEdit
;
2376 GetItem( le
.m_item
);
2377 HandleWindowEvent( le
);
2380 // ----------------------------------------------------------------------------
2381 // virtual list controls
2382 // ----------------------------------------------------------------------------
2384 wxString
wxListCtrl::OnGetItemText(long WXUNUSED(item
), long WXUNUSED(col
)) const
2386 // this is a pure virtual function, in fact - which is not really pure
2387 // because the controls which are not virtual don't need to implement it
2388 wxFAIL_MSG( wxT("wxListCtrl::OnGetItemText not supposed to be called") );
2390 return wxEmptyString
;
2393 int wxListCtrl::OnGetItemImage(long WXUNUSED(item
)) const
2395 wxCHECK_MSG(!GetImageList(wxIMAGE_LIST_SMALL
),
2397 wxT("List control has an image list, OnGetItemImage or OnGetItemColumnImage should be overridden."));
2401 int wxListCtrl::OnGetItemColumnImage(long item
, long column
) const
2404 return OnGetItemImage(item
);
2409 wxListItemAttr
*wxListCtrl::OnGetItemAttr(long WXUNUSED_UNLESS_DEBUG(item
)) const
2411 wxASSERT_MSG( item
>= 0 && item
< GetItemCount(),
2412 wxT("invalid item index in OnGetItemAttr()") );
2414 // no attributes by default
2418 void wxListCtrl::SetItemCount(long count
)
2420 wxASSERT_MSG( IsVirtual(), wxT("this is for virtual controls only") );
2424 m_genericImpl
->SetItemCount(count
);
2430 // we need to temporarily disable the new item creation notification
2431 // procedure to speed things up
2432 // FIXME: Even this doesn't seem to help much...
2434 // FIXME: Find a more efficient way to do this.
2435 m_dbImpl
->MacClear();
2437 DataBrowserCallbacks callbacks
;
2438 DataBrowserItemNotificationUPP itemUPP
;
2439 GetDataBrowserCallbacks(m_dbImpl
->GetControlRef(), &callbacks
);
2440 itemUPP
= callbacks
.u
.v1
.itemNotificationCallback
;
2441 callbacks
.u
.v1
.itemNotificationCallback
= 0;
2442 m_dbImpl
->SetCallbacks(&callbacks
);
2443 ::AddDataBrowserItems(m_dbImpl
->GetControlRef(), kDataBrowserNoItem
,
2444 count
, NULL
, kDataBrowserItemNoProperty
);
2445 callbacks
.u
.v1
.itemNotificationCallback
= itemUPP
;
2446 m_dbImpl
->SetCallbacks(&callbacks
);
2451 void wxListCtrl::RefreshItem(long item
)
2455 m_genericImpl
->RefreshItem(item
);
2461 DataBrowserItemID id
;
2465 wxMacDataItem
* thisItem
= m_dbImpl
->GetItemFromLine(item
);
2466 id
= (DataBrowserItemID
) thisItem
;
2471 m_dbImpl
->wxMacDataBrowserControl::UpdateItems
2475 kDataBrowserItemNoProperty
, // preSortProperty
2476 kDataBrowserNoItem
// update all columns
2481 void wxListCtrl::RefreshItems(long itemFrom
, long itemTo
)
2485 m_genericImpl
->RefreshItems(itemFrom
, itemTo
);
2491 const long count
= itemTo
- itemFrom
+ 1;
2492 DataBrowserItemID
*ids
= new DataBrowserItemID
[count
];
2496 for ( long i
= 0; i
< count
; i
++ )
2498 wxMacDataItem
* thisItem
= m_dbImpl
->GetItemFromLine(itemFrom
+i
);
2499 ids
[i
] = (DataBrowserItemID
) thisItem
;
2504 for ( long i
= 0; i
< count
; i
++ )
2505 ids
[i
] = itemFrom
+i
+1;
2508 m_dbImpl
->wxMacDataBrowserControl::UpdateItems
2512 kDataBrowserItemNoProperty
, // preSortProperty
2513 kDataBrowserNoItem
// update all columns
2520 void wxListCtrl::SetDropTarget( wxDropTarget
*dropTarget
)
2522 #if wxUSE_DRAG_AND_DROP
2524 m_genericImpl
->SetDropTarget( dropTarget
);
2527 wxWindow::SetDropTarget( dropTarget
);
2531 wxDropTarget
*wxListCtrl::GetDropTarget() const
2533 #if wxUSE_DRAG_AND_DROP
2535 return m_genericImpl
->GetDropTarget();
2538 return wxWindow::GetDropTarget();
2543 #if wxABI_VERSION >= 20801
2544 void wxListCtrl::SetFocus()
2548 m_genericImpl
->SetFocus();
2552 wxWindow::SetFocus();
2556 // wxMac internal data structures
2558 wxMacListCtrlItem::~wxMacListCtrlItem()
2560 WX_CLEAR_HASH_MAP( wxListItemList
, m_rowItems
);
2563 void wxMacListCtrlItem::Notification(wxMacDataItemBrowserControl
*owner
,
2564 DataBrowserItemNotification message
,
2565 DataBrowserItemDataRef
WXUNUSED(itemData
) ) const
2568 wxMacDataBrowserListCtrlControl
*lb
= wxDynamicCast(owner
, wxMacDataBrowserListCtrlControl
);
2570 // we want to depend on as little as possible to make sure tear-down of controls is safe
2571 if ( message
== kDataBrowserItemRemoved
)
2576 else if ( message
== kDataBrowserItemAdded
)
2578 // we don't issue events on adding, the item is not really stored in the list yet, so we
2579 // avoid asserts by gettting out now
2583 wxListCtrl
*list
= wxDynamicCast( owner
->GetWXPeer() , wxListCtrl
);
2586 bool trigger
= false;
2588 wxListEvent
event( wxEVT_COMMAND_LIST_ITEM_SELECTED
, list
->GetId() );
2589 bool isSingle
= (list
->GetWindowStyle() & wxLC_SINGLE_SEL
) != 0;
2591 event
.SetEventObject( list
);
2592 event
.m_itemIndex
= owner
->GetLineFromItem( this ) ;
2593 event
.m_item
.m_itemId
= event
.m_itemIndex
;
2594 list
->GetItem(event
.m_item
);
2598 case kDataBrowserItemDeselected
:
2599 event
.SetEventType(wxEVT_COMMAND_LIST_ITEM_DESELECTED
);
2601 trigger
= !lb
->IsSelectionSuppressed();
2604 case kDataBrowserItemSelected
:
2605 trigger
= !lb
->IsSelectionSuppressed();
2608 case kDataBrowserItemDoubleClicked
:
2609 event
.SetEventType( wxEVT_COMMAND_LIST_ITEM_ACTIVATED
);
2613 case kDataBrowserEditStarted
:
2614 // TODO : how to veto ?
2615 event
.SetEventType( wxEVT_COMMAND_LIST_BEGIN_LABEL_EDIT
) ;
2619 case kDataBrowserEditStopped
:
2620 // TODO probably trigger only upon the value store callback, because
2621 // here IIRC we cannot veto
2622 event
.SetEventType( wxEVT_COMMAND_LIST_END_LABEL_EDIT
) ;
2632 // direct notification is not always having the listbox GetSelection() having in synch with event
2633 wxPostEvent( list
->GetEventHandler(), event
);
2639 IMPLEMENT_DYNAMIC_CLASS(wxMacDataBrowserListCtrlControl
, wxMacDataItemBrowserControl
)
2641 wxMacDataBrowserListCtrlControl::wxMacDataBrowserListCtrlControl( wxWindow
*peer
, const wxPoint
& pos
, const wxSize
& size
, long style
)
2642 : wxMacDataItemBrowserControl( peer
, pos
, size
, style
)
2644 OSStatus err
= noErr
;
2645 m_clientDataItemsType
= wxClientData_None
;
2646 m_isVirtual
= false;
2649 if ( style
& wxLC_VIRTUAL
)
2652 DataBrowserSelectionFlags options
= kDataBrowserDragSelect
;
2653 if ( style
& wxLC_SINGLE_SEL
)
2655 options
|= kDataBrowserSelectOnlyOne
;
2659 options
|= kDataBrowserCmdTogglesSelection
;
2662 err
= SetSelectionFlags( options
);
2663 verify_noerr( err
);
2665 DataBrowserCustomCallbacks callbacks
;
2666 InitializeDataBrowserCustomCallbacks( &callbacks
, kDataBrowserLatestCustomCallbacks
);
2668 if ( gDataBrowserDrawItemUPP
== NULL
)
2669 gDataBrowserDrawItemUPP
= NewDataBrowserDrawItemUPP(DataBrowserDrawItemProc
);
2671 if ( gDataBrowserHitTestUPP
== NULL
)
2672 gDataBrowserHitTestUPP
= NewDataBrowserHitTestUPP(DataBrowserHitTestProc
);
2674 callbacks
.u
.v1
.drawItemCallback
= gDataBrowserDrawItemUPP
;
2675 callbacks
.u
.v1
.hitTestCallback
= gDataBrowserHitTestUPP
;
2677 SetDataBrowserCustomCallbacks( GetControlRef(), &callbacks
);
2679 if ( style
& wxLC_LIST
)
2681 InsertColumn(0, kDataBrowserIconAndTextType
, wxEmptyString
, -1, -1);
2682 verify_noerr( AutoSizeColumns() );
2685 if ( style
& wxLC_LIST
|| style
& wxLC_NO_HEADER
)
2686 verify_noerr( SetHeaderButtonHeight( 0 ) );
2689 SetSortProperty( kMinColumnId
- 1 );
2691 SetSortProperty( kMinColumnId
);
2693 m_sortOrder
= SortOrder_None
;
2695 if ( style
& wxLC_SORT_DESCENDING
)
2697 SetSortOrder( kDataBrowserOrderDecreasing
);
2699 else if ( style
& wxLC_SORT_ASCENDING
)
2701 SetSortOrder( kDataBrowserOrderIncreasing
);
2704 if ( style
& wxLC_VRULES
)
2706 verify_noerr( DataBrowserChangeAttributes(m_controlRef
, kDataBrowserAttributeListViewDrawColumnDividers
, kDataBrowserAttributeNone
) );
2709 verify_noerr( SetHiliteStyle(kDataBrowserTableViewFillHilite
) );
2710 verify_noerr( SetHasScrollBars( (style
& wxHSCROLL
) != 0 , true ) );
2713 pascal Boolean
wxMacDataBrowserListCtrlControl::DataBrowserEditTextProc(
2715 DataBrowserItemID itemID
,
2716 DataBrowserPropertyID property
,
2717 CFStringRef theString
,
2718 Rect
*maxEditTextRect
,
2719 Boolean
*shrinkToFit
)
2721 Boolean result
= false;
2722 wxMacDataBrowserListCtrlControl
* ctl
= wxDynamicCast(wxMacControl::GetReferenceFromNativeControl( browser
), wxMacDataBrowserListCtrlControl
);
2725 result
= ctl
->ConfirmEditText(itemID
, property
, theString
, maxEditTextRect
, shrinkToFit
);
2726 theString
= CFSTR("Hello!");
2731 bool wxMacDataBrowserListCtrlControl::ConfirmEditText(
2732 DataBrowserItemID
WXUNUSED(itemID
),
2733 DataBrowserPropertyID
WXUNUSED(property
),
2734 CFStringRef
WXUNUSED(theString
),
2735 Rect
*WXUNUSED(maxEditTextRect
),
2736 Boolean
*WXUNUSED(shrinkToFit
))
2741 pascal void wxMacDataBrowserListCtrlControl::DataBrowserDrawItemProc(
2743 DataBrowserItemID itemID
,
2744 DataBrowserPropertyID property
,
2745 DataBrowserItemState itemState
,
2746 const Rect
*itemRect
,
2748 Boolean colorDevice
)
2750 wxMacDataBrowserListCtrlControl
* ctl
= wxDynamicCast(wxMacControl::GetReferenceFromNativeControl( browser
), wxMacDataBrowserListCtrlControl
);
2753 ctl
->DrawItem(itemID
, property
, itemState
, itemRect
, gdDepth
, colorDevice
);
2757 // routines needed for DrawItem
2762 kTextBoxHeight
= 14,
2763 kIconTextSpacingV
= 2,
2765 kContentHeight
= kIconHeight
+ kTextBoxHeight
+ kIconTextSpacingV
2768 static void calculateCGDrawingBounds(CGRect inItemRect
, CGRect
*outIconRect
, CGRect
*outTextRect
, bool hasIcon
= false)
2771 float iconH
, iconW
= 0;
2772 float padding
= kItemPadding
;
2775 iconH
= kIconHeight
;
2777 padding
= padding
*2;
2780 textBottom
= inItemRect
.origin
.y
;
2782 *outIconRect
= CGRectMake(inItemRect
.origin
.x
+ kItemPadding
,
2783 textBottom
+ kIconTextSpacingV
, kIconWidth
,
2786 *outTextRect
= CGRectMake(inItemRect
.origin
.x
+ padding
+ iconW
,
2787 textBottom
+ kIconTextSpacingV
, inItemRect
.size
.width
- padding
- iconW
,
2788 inItemRect
.size
.height
- kIconTextSpacingV
);
2791 void wxMacDataBrowserListCtrlControl::DrawItem(
2792 DataBrowserItemID itemID
,
2793 DataBrowserPropertyID property
,
2794 DataBrowserItemState itemState
,
2795 const Rect
*WXUNUSED(itemRect
),
2797 Boolean colorDevice
)
2800 wxFont font
= wxNullFont
;
2803 DataBrowserTableViewColumnIndex listColumn
= 0;
2804 GetColumnPosition( property
, &listColumn
);
2806 wxListCtrl
* list
= wxDynamicCast( GetWXPeer() , wxListCtrl
);
2807 wxMacListCtrlItem
* lcItem
;
2808 wxColour color
= *wxBLACK
;
2809 wxColour bgColor
= wxNullColour
;
2811 if (listColumn
>= 0)
2815 lcItem
= (wxMacListCtrlItem
*) itemID
;
2816 if (lcItem
->HasColumnInfo(listColumn
))
2818 wxListItem
* item
= lcItem
->GetColumnInfo(listColumn
);
2820 // we always use the 0 column to get font and text/background colors.
2821 if (lcItem
->HasColumnInfo(0))
2823 wxListItem
* firstItem
= lcItem
->GetColumnInfo(0);
2824 color
= firstItem
->GetTextColour();
2825 bgColor
= firstItem
->GetBackgroundColour();
2826 font
= firstItem
->GetFont();
2829 if (item
->GetMask() & wxLIST_MASK_TEXT
)
2830 text
= item
->GetText();
2831 if (item
->GetMask() & wxLIST_MASK_IMAGE
)
2832 imgIndex
= item
->GetImage();
2838 long itemNum
= (long)itemID
-1;
2839 if (itemNum
>= 0 && itemNum
< list
->GetItemCount())
2841 text
= list
->OnGetItemText( itemNum
, listColumn
);
2842 imgIndex
= list
->OnGetItemColumnImage( itemNum
, listColumn
);
2843 wxListItemAttr
* attrs
= list
->OnGetItemAttr( itemNum
);
2846 if (attrs
->HasBackgroundColour())
2847 bgColor
= attrs
->GetBackgroundColour();
2848 if (attrs
->HasTextColour())
2849 color
= attrs
->GetTextColour();
2850 if (attrs
->HasFont())
2851 font
= attrs
->GetFont();
2857 wxColour listBgColor
= list
->GetBackgroundColour();
2858 if (bgColor
== wxNullColour
)
2859 bgColor
= listBgColor
;
2862 font
= list
->GetFont();
2864 wxCFStringRef
cfString( text
, wxLocale::GetSystemEncoding() );
2867 CGRect enclosingCGRect
, iconCGRect
, textCGRect
;
2869 ThemeDrawingState savedState
= NULL
;
2870 CGContextRef context
= (CGContextRef
)list
->MacGetDrawingContext();
2871 wxMacCGContextStateSaver
top_saver_cg( context
);
2873 RGBColor labelColor
;
2875 labelColor
.green
= 0;
2876 labelColor
.blue
= 0;
2878 RGBColor backgroundColor
;
2879 backgroundColor
.red
= 255;
2880 backgroundColor
.green
= 255;
2881 backgroundColor
.blue
= 255;
2883 GetDataBrowserItemPartBounds(GetControlRef(), itemID
, property
, kDataBrowserPropertyEnclosingPart
,
2886 enclosingCGRect
= CGRectMake(enclosingRect
.left
,
2888 enclosingRect
.right
- enclosingRect
.left
,
2889 enclosingRect
.bottom
- enclosingRect
.top
);
2891 bool hasFocus
= (wxWindow::FindFocus() == list
);
2892 active
= IsControlActive(GetControlRef());
2894 // don't paint the background over the vertical rule line
2895 if ( list
->GetWindowStyleFlag() & wxLC_VRULES
)
2897 enclosingCGRect
.origin
.x
+= 1;
2898 enclosingCGRect
.size
.width
-= 1;
2900 if (itemState
== kDataBrowserItemIsSelected
)
2903 GetThemeDrawingState(&savedState
);
2905 if (active
&& hasFocus
)
2907 GetThemeBrushAsColor(kThemeBrushAlternatePrimaryHighlightColor
, 32, true, &backgroundColor
);
2908 GetThemeTextColor(kThemeTextColorWhite
, gdDepth
, colorDevice
, &labelColor
);
2912 GetThemeBrushAsColor(kThemeBrushSecondaryHighlightColor
, 32, true, &backgroundColor
);
2913 GetThemeTextColor(kThemeTextColorBlack
, gdDepth
, colorDevice
, &labelColor
);
2915 wxMacCGContextStateSaver
cg( context
);
2917 CGContextSetRGBFillColor(context
, (CGFloat
)backgroundColor
.red
/ (CGFloat
)USHRT_MAX
,
2918 (CGFloat
)backgroundColor
.green
/ (CGFloat
)USHRT_MAX
,
2919 (CGFloat
)backgroundColor
.blue
/ (CGFloat
)USHRT_MAX
, (CGFloat
) 1.0);
2920 CGContextFillRect(context
, enclosingCGRect
);
2926 color
.GetRGBColor(&labelColor
);
2927 else if (list
->GetTextColour().Ok())
2928 list
->GetTextColour().GetRGBColor(&labelColor
);
2932 bgColor
.GetRGBColor(&backgroundColor
);
2933 CGContextSaveGState(context
);
2935 CGContextSetRGBFillColor(context
, (CGFloat
)backgroundColor
.red
/ (CGFloat
)USHRT_MAX
,
2936 (CGFloat
)backgroundColor
.green
/ (CGFloat
)USHRT_MAX
,
2937 (CGFloat
)backgroundColor
.blue
/ (CGFloat
)USHRT_MAX
, (CGFloat
) 1.0);
2938 CGContextFillRect(context
, enclosingCGRect
);
2940 CGContextRestoreGState(context
);
2944 calculateCGDrawingBounds(enclosingCGRect
, &iconCGRect
, &textCGRect
, (imgIndex
!= -1) );
2948 wxImageList
* imageList
= list
->GetImageList(wxIMAGE_LIST_SMALL
);
2949 if (imageList
&& imageList
->GetImageCount() > 0)
2951 wxBitmap bmp
= imageList
->GetBitmap(imgIndex
);
2952 IconRef icon
= bmp
.GetIconRef();
2954 wxMacCGContextStateSaver
cg( context
);
2956 CGContextTranslateCTM(context
, 0,iconCGRect
.origin
.y
+ CGRectGetMaxY(iconCGRect
));
2957 CGContextScaleCTM(context
,1.0f
,-1.0f
);
2958 PlotIconRefInContext(context
, &iconCGRect
, kAlignNone
,
2959 active
? kTransformNone
: kTransformDisabled
, NULL
,
2960 kPlotIconRefNormalFlags
, icon
);
2964 HIThemeTextHorizontalFlush hFlush
= kHIThemeTextHorizontalFlushLeft
;
2965 HIThemeTextInfo info
;
2967 #if wxOSX_USE_CORE_TEXT
2968 if ( UMAGetSystemVersion() >= 0x1050 )
2970 info
.version
= kHIThemeTextInfoVersionOne
;
2971 info
.fontID
= kThemeViewsFont
;
2974 info
.fontID
= kThemeSpecifiedFont
;
2975 info
.font
= (CTFontRef
) font
.OSXGetCTFont();
2980 #if wxOSX_USE_ATSU_TEXT
2983 info
.version
= kHIThemeTextInfoVersionZero
;
2984 info
.fontID
= kThemeViewsFont
;
2988 info
.fontID
= font
.MacGetThemeFontID();
2990 ::TextSize( (short)(font
.GetPointSize()) ) ;
2991 ::TextFace( font
.MacGetFontStyle() ) ;
2997 list
->GetColumn(listColumn
, item
);
2998 if (item
.GetMask() & wxLIST_MASK_FORMAT
)
3000 if (item
.GetAlign() == wxLIST_FORMAT_LEFT
)
3001 hFlush
= kHIThemeTextHorizontalFlushLeft
;
3002 else if (item
.GetAlign() == wxLIST_FORMAT_CENTER
)
3003 hFlush
= kHIThemeTextHorizontalFlushCenter
;
3004 else if (item
.GetAlign() == wxLIST_FORMAT_RIGHT
)
3006 hFlush
= kHIThemeTextHorizontalFlushRight
;
3007 textCGRect
.origin
.x
-= kItemPadding
; // give a little extra paddding
3011 info
.state
= active
? kThemeStateActive
: kThemeStateInactive
;
3012 info
.horizontalFlushness
= hFlush
;
3013 info
.verticalFlushness
= kHIThemeTextVerticalFlushCenter
;
3014 info
.options
= kHIThemeTextBoxOptionNone
;
3015 info
.truncationPosition
= kHIThemeTextTruncationEnd
;
3016 info
.truncationMaxLines
= 1;
3019 wxMacCGContextStateSaver
cg( context
);
3020 CGContextSetRGBFillColor (context
, (CGFloat
)labelColor
.red
/ (CGFloat
)USHRT_MAX
,
3021 (CGFloat
)labelColor
.green
/ (CGFloat
)USHRT_MAX
,
3022 (CGFloat
)labelColor
.blue
/ (CGFloat
)USHRT_MAX
, (CGFloat
) 1.0);
3024 HIThemeDrawTextBox(cfString
, &textCGRect
, &info
, context
, kHIThemeOrientationNormal
);
3028 if (savedState
!= NULL
)
3029 SetThemeDrawingState(savedState
, true);
3033 OSStatus
wxMacDataBrowserListCtrlControl::GetSetItemData(DataBrowserItemID itemID
,
3034 DataBrowserPropertyID property
,
3035 DataBrowserItemDataRef itemData
,
3036 Boolean changeValue
)
3041 DataBrowserTableViewColumnIndex listColumn
= 0;
3042 verify_noerr( GetColumnPosition( property
, &listColumn
) );
3044 OSStatus err
= errDataBrowserPropertyNotSupported
;
3045 wxListCtrl
* list
= wxDynamicCast( GetWXPeer() , wxListCtrl
);
3046 wxMacListCtrlItem
* lcItem
= NULL
;
3048 if (listColumn
>= 0)
3052 lcItem
= (wxMacListCtrlItem
*) itemID
;
3053 if (lcItem
&& lcItem
->HasColumnInfo(listColumn
)){
3054 wxListItem
* item
= lcItem
->GetColumnInfo(listColumn
);
3055 if (item
->GetMask() & wxLIST_MASK_TEXT
)
3056 text
= item
->GetText();
3057 if (item
->GetMask() & wxLIST_MASK_IMAGE
)
3058 imgIndex
= item
->GetImage();
3063 long itemNum
= (long)itemID
-1;
3064 if (itemNum
>= 0 && itemNum
< list
->GetItemCount())
3066 text
= list
->OnGetItemText( itemNum
, listColumn
);
3067 imgIndex
= list
->OnGetItemColumnImage( itemNum
, listColumn
);
3076 case kDataBrowserItemIsEditableProperty
:
3077 if ( list
&& list
->HasFlag( wxLC_EDIT_LABELS
) )
3079 verify_noerr(SetDataBrowserItemDataBooleanValue( itemData
, true ));
3084 if ( property
>= kMinColumnId
)
3086 if (!text
.IsEmpty()){
3087 wxCFStringRef
cfStr( text
, wxLocale::GetSystemEncoding() );
3088 err
= ::SetDataBrowserItemDataText( itemData
, cfStr
);
3094 if ( imgIndex
!= -1 )
3096 wxImageList
* imageList
= list
->GetImageList(wxIMAGE_LIST_SMALL
);
3097 if (imageList
&& imageList
->GetImageCount() > 0){
3098 wxBitmap bmp
= imageList
->GetBitmap(imgIndex
);
3099 IconRef icon
= bmp
.GetIconRef();
3100 ::SetDataBrowserItemDataIcon(itemData
, icon
);
3114 if ( property
>= kMinColumnId
)
3116 DataBrowserTableViewColumnIndex listColumn
= 0;
3117 verify_noerr( GetColumnPosition( property
, &listColumn
) );
3119 // TODO probably send the 'end edit' from here, as we
3120 // can then deal with the veto
3122 verify_noerr( GetDataBrowserItemDataText( itemData
, &sr
) ) ;
3123 wxCFStringRef
cfStr(sr
) ;;
3125 list
->SetItem( (long)itemData
-1 , listColumn
, cfStr
.AsString() ) ;
3129 lcItem
->SetColumnTextValue( listColumn
, cfStr
.AsString() );
3139 void wxMacDataBrowserListCtrlControl::ItemNotification(DataBrowserItemID itemID
,
3140 DataBrowserItemNotification message
,
3141 DataBrowserItemDataRef itemData
)
3143 wxMacListCtrlItem
*item
= NULL
;
3146 item
= (wxMacListCtrlItem
*) itemID
;
3149 // we want to depend on as little as possible to make sure tear-down of controls is safe
3150 if ( message
== kDataBrowserItemRemoved
)
3153 item
->Notification(this, message
, itemData
);
3156 else if ( message
== kDataBrowserItemAdded
)
3158 // we don't issue events on adding, the item is not really stored in the list yet, so we
3159 // avoid asserts by getting out now
3161 item
->Notification(this, message
, itemData
);
3165 wxListCtrl
*list
= wxDynamicCast( GetWXPeer() , wxListCtrl
);
3168 bool trigger
= false;
3170 wxListEvent
event( wxEVT_COMMAND_LIST_ITEM_SELECTED
, list
->GetId() );
3172 event
.SetEventObject( list
);
3173 if ( !list
->IsVirtual() )
3175 DataBrowserTableViewRowIndex result
= 0;
3176 verify_noerr( GetItemRow( itemID
, &result
) ) ;
3177 event
.m_itemIndex
= result
;
3181 event
.m_itemIndex
= (long)itemID
-1;
3183 event
.m_item
.m_itemId
= event
.m_itemIndex
;
3184 list
->GetItem(event
.m_item
);
3188 case kDataBrowserItemDeselected
:
3189 event
.SetEventType(wxEVT_COMMAND_LIST_ITEM_DESELECTED
);
3190 // as the generic implementation is also triggering this
3191 // event for single selection, we do the same (different than listbox)
3192 trigger
= !IsSelectionSuppressed();
3195 case kDataBrowserItemSelected
:
3196 trigger
= !IsSelectionSuppressed();
3200 case kDataBrowserItemDoubleClicked
:
3201 event
.SetEventType( wxEVT_COMMAND_LIST_ITEM_ACTIVATED
);
3205 case kDataBrowserEditStarted
:
3206 // TODO : how to veto ?
3207 event
.SetEventType( wxEVT_COMMAND_LIST_BEGIN_LABEL_EDIT
) ;
3211 case kDataBrowserEditStopped
:
3212 // TODO probably trigger only upon the value store callback, because
3213 // here IIRC we cannot veto
3214 event
.SetEventType( wxEVT_COMMAND_LIST_END_LABEL_EDIT
) ;
3224 // direct notification is not always having the listbox GetSelection() having in synch with event
3225 wxPostEvent( list
->GetEventHandler(), event
);
3230 Boolean
wxMacDataBrowserListCtrlControl::CompareItems(DataBrowserItemID itemOneID
,
3231 DataBrowserItemID itemTwoID
,
3232 DataBrowserPropertyID sortProperty
)
3235 bool retval
= false;
3237 wxString otherItemText
;
3239 long otherItemOrder
;
3241 DataBrowserTableViewColumnIndex colId
= 0;
3242 verify_noerr( GetColumnPosition( sortProperty
, &colId
) );
3244 wxListCtrl
* list
= wxDynamicCast( GetWXPeer() , wxListCtrl
);
3246 DataBrowserSortOrder sort
;
3247 verify_noerr(GetSortOrder(&sort
));
3253 wxMacListCtrlItem
* item
= (wxMacListCtrlItem
*)itemOneID
;
3254 wxMacListCtrlItem
* otherItem
= (wxMacListCtrlItem
*)itemTwoID
;
3256 itemOrder
= item
->GetOrder();
3257 otherItemOrder
= otherItem
->GetOrder();
3259 wxListCtrlCompare func
= list
->GetCompareFunc();
3265 if (item
&& item
->HasColumnInfo(0))
3266 item1
= item
->GetColumnInfo(0)->GetData();
3267 if (otherItem
&& otherItem
->HasColumnInfo(0))
3268 item2
= otherItem
->GetColumnInfo(0)->GetData();
3270 if (item1
> -1 && item2
> -1)
3272 int result
= func(item1
, item2
, list
->GetCompareFuncData());
3273 if (sort
== kDataBrowserOrderIncreasing
)
3280 // we can't use the native control's sorting abilities, so just
3282 return itemOrder
< otherItemOrder
;
3287 long itemNum
= (long)itemOneID
;
3288 long otherItemNum
= (long)itemTwoID
;
3290 // virtual listctrls don't support sorting
3291 return itemNum
< otherItemNum
;
3295 // fallback for undefined cases
3296 retval
= itemOneID
< itemTwoID
;
3302 wxMacDataBrowserListCtrlControl::~wxMacDataBrowserListCtrlControl()
3306 void wxMacDataBrowserListCtrlControl::MacSetColumnInfo( unsigned int row
, unsigned int column
, wxListItem
* item
)
3308 wxMacDataItem
* dataItem
= GetItemFromLine(row
);
3309 wxASSERT_MSG( dataItem
, wxT("could not obtain wxMacDataItem for row in MacSetColumnInfo. Is row a valid wxListCtrl row?") );
3312 wxMacListCtrlItem
* listItem
= static_cast<wxMacListCtrlItem
*>(dataItem
);
3313 bool hasInfo
= listItem
->HasColumnInfo( column
);
3314 listItem
->SetColumnInfo( column
, item
);
3315 listItem
->SetOrder(row
);
3316 UpdateState(dataItem
, item
);
3318 wxListCtrl
* list
= wxDynamicCast( GetWXPeer() , wxListCtrl
);
3320 // NB: When this call was made before a control was completely shown, it would
3321 // update the item prematurely (i.e. no text would be listed) and, on show,
3322 // only the sorted column would be refreshed, meaning only first column text labels
3323 // would be shown. Making sure not to update items until the control is visible
3324 // seems to fix this issue.
3325 if (hasInfo
&& list
->IsShown())
3327 DataBrowserTableViewColumnID id
= 0;
3328 verify_noerr( GetColumnIDFromIndex( column
, &id
) );
3329 UpdateItem( wxMacDataBrowserRootContainer
, listItem
, id
);
3334 // apply changes that need to happen immediately, rather than when the
3335 // databrowser control fires a callback.
3336 void wxMacDataBrowserListCtrlControl::UpdateState(wxMacDataItem
* dataItem
, wxListItem
* listItem
)
3338 bool isSelected
= IsItemSelected( dataItem
);
3339 bool isSelectedState
= (listItem
->GetState() == wxLIST_STATE_SELECTED
);
3341 // toggle the selection state if wxListInfo state and actual state don't match.
3342 if ( listItem
->GetMask() & wxLIST_MASK_STATE
&& isSelected
!= isSelectedState
)
3344 DataBrowserSetOption options
= kDataBrowserItemsAdd
;
3345 if (!isSelectedState
)
3346 options
= kDataBrowserItemsRemove
;
3347 SetSelectedItem(dataItem
, options
);
3349 // TODO: Set column width if item width > than current column width
3352 void wxMacDataBrowserListCtrlControl::MacGetColumnInfo( unsigned int row
, unsigned int column
, wxListItem
& item
)
3354 wxMacDataItem
* dataItem
= GetItemFromLine(row
);
3355 wxASSERT_MSG( dataItem
, wxT("could not obtain wxMacDataItem in MacGetColumnInfo. Is row a valid wxListCtrl row?") );
3356 // CS should this guard against dataItem = 0 ? , as item is not a pointer if (item) is not appropriate
3359 wxMacListCtrlItem
* listItem
= static_cast<wxMacListCtrlItem
*>(dataItem
);
3361 if (!listItem
->HasColumnInfo( column
))
3364 wxListItem
* oldItem
= listItem
->GetColumnInfo( column
);
3368 long mask
= item
.GetMask();
3370 // by default, get everything for backwards compatibility
3373 if ( mask
& wxLIST_MASK_TEXT
)
3374 item
.SetText(oldItem
->GetText());
3375 if ( mask
& wxLIST_MASK_IMAGE
)
3376 item
.SetImage(oldItem
->GetImage());
3377 if ( mask
& wxLIST_MASK_DATA
)
3378 item
.SetData(oldItem
->GetData());
3379 if ( mask
& wxLIST_MASK_STATE
)
3380 item
.SetState(oldItem
->GetState());
3381 if ( mask
& wxLIST_MASK_WIDTH
)
3382 item
.SetWidth(oldItem
->GetWidth());
3383 if ( mask
& wxLIST_MASK_FORMAT
)
3384 item
.SetAlign(oldItem
->GetAlign());
3386 item
.SetTextColour(oldItem
->GetTextColour());
3387 item
.SetBackgroundColour(oldItem
->GetBackgroundColour());
3388 item
.SetFont(oldItem
->GetFont());
3393 void wxMacDataBrowserListCtrlControl::MacInsertItem( unsigned int n
, wxListItem
* item
)
3396 wxMacDataItemBrowserControl::MacInsert(n
, new wxMacListCtrlItem() );
3397 MacSetColumnInfo(n
, 0, item
);
3400 wxMacListCtrlItem::wxMacListCtrlItem()
3402 m_rowItems
= wxListItemList();
3405 int wxMacListCtrlItem::GetColumnImageValue( unsigned int column
)
3407 if ( HasColumnInfo(column
) )
3408 return GetColumnInfo(column
)->GetImage();
3413 void wxMacListCtrlItem::SetColumnImageValue( unsigned int column
, int imageIndex
)
3415 if ( HasColumnInfo(column
) )
3416 GetColumnInfo(column
)->SetImage(imageIndex
);
3419 wxString
wxMacListCtrlItem::GetColumnTextValue( unsigned int column
)
3421 /* TODO CHECK REMOVE
3425 if ( HasColumnInfo(column
) )
3426 return GetColumnInfo(column
)->GetText();
3428 return wxEmptyString
;
3431 void wxMacListCtrlItem::SetColumnTextValue( unsigned int column
, const wxString
& text
)
3433 if ( HasColumnInfo(column
) )
3434 GetColumnInfo(column
)->SetText(text
);
3436 /* TODO CHECK REMOVE
3437 // for compatibility with superclass APIs
3443 wxListItem
* wxMacListCtrlItem::GetColumnInfo( unsigned int column
)
3445 wxASSERT_MSG( HasColumnInfo(column
), wxT("invalid column index in wxMacListCtrlItem") );
3446 return m_rowItems
[column
];
3449 bool wxMacListCtrlItem::HasColumnInfo( unsigned int column
)
3451 return !(m_rowItems
.find( column
) == m_rowItems
.end());
3454 void wxMacListCtrlItem::SetColumnInfo( unsigned int column
, wxListItem
* item
)
3457 if ( !HasColumnInfo(column
) )
3459 wxListItem
* listItem
= new wxListItem(*item
);
3460 m_rowItems
[column
] = listItem
;
3464 wxListItem
* listItem
= GetColumnInfo( column
);
3465 long mask
= item
->GetMask();
3466 if (mask
& wxLIST_MASK_TEXT
)
3467 listItem
->SetText(item
->GetText());
3468 if (mask
& wxLIST_MASK_DATA
)
3469 listItem
->SetData(item
->GetData());
3470 if (mask
& wxLIST_MASK_IMAGE
)
3471 listItem
->SetImage(item
->GetImage());
3472 if (mask
& wxLIST_MASK_STATE
)
3473 listItem
->SetState(item
->GetState());
3474 if (mask
& wxLIST_MASK_FORMAT
)
3475 listItem
->SetAlign(item
->GetAlign());
3476 if (mask
& wxLIST_MASK_WIDTH
)
3477 listItem
->SetWidth(item
->GetWidth());
3479 if ( item
->HasAttributes() )
3481 if ( listItem
->HasAttributes() )
3482 listItem
->GetAttributes()->AssignFrom(*item
->GetAttributes());
3485 listItem
->SetTextColour(item
->GetTextColour());
3486 listItem
->SetBackgroundColour(item
->GetBackgroundColour());
3487 listItem
->SetFont(item
->GetFont());
3493 int wxListCtrl::CalcColumnAutoWidth(int col
) const
3497 for ( int i
= 0; i
< GetItemCount(); i
++ )
3500 info
.SetMask(wxLIST_MASK_TEXT
| wxLIST_MASK_IMAGE
);
3502 info
.SetColumn(col
);
3505 const wxFont font
= info
.GetFont();
3509 GetTextExtent(info
.GetText(), &w
, NULL
, NULL
, NULL
, &font
);
3511 GetTextExtent(info
.GetText(), &w
, NULL
);
3513 w
+= 2 * kItemPadding
;
3515 if ( info
.GetImage() != -1 )
3518 width
= wxMax(width
, w
);
3524 #endif // wxUSE_LISTCTRL