1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/mac/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"
35 #include "wx/mac/uma.h"
37 #include "wx/imaglist.h"
38 #include "wx/sysopt.h"
41 #define wxMAC_ALWAYS_USE_GENERIC_LISTCTRL wxT("mac.listctrl.always_use_generic")
43 #if wxUSE_EXTENDED_RTTI
44 WX_DEFINE_FLAGS( wxListCtrlStyle
)
46 wxBEGIN_FLAGS( wxListCtrlStyle
)
47 // new style border flags, we put them first to
48 // use them for streaming out
49 wxFLAGS_MEMBER(wxBORDER_SIMPLE
)
50 wxFLAGS_MEMBER(wxBORDER_SUNKEN
)
51 wxFLAGS_MEMBER(wxBORDER_DOUBLE
)
52 wxFLAGS_MEMBER(wxBORDER_RAISED
)
53 wxFLAGS_MEMBER(wxBORDER_STATIC
)
54 wxFLAGS_MEMBER(wxBORDER_NONE
)
56 // old style border flags
57 wxFLAGS_MEMBER(wxSIMPLE_BORDER
)
58 wxFLAGS_MEMBER(wxSUNKEN_BORDER
)
59 wxFLAGS_MEMBER(wxDOUBLE_BORDER
)
60 wxFLAGS_MEMBER(wxRAISED_BORDER
)
61 wxFLAGS_MEMBER(wxSTATIC_BORDER
)
62 wxFLAGS_MEMBER(wxBORDER
)
64 // standard window styles
65 wxFLAGS_MEMBER(wxTAB_TRAVERSAL
)
66 wxFLAGS_MEMBER(wxCLIP_CHILDREN
)
67 wxFLAGS_MEMBER(wxTRANSPARENT_WINDOW
)
68 wxFLAGS_MEMBER(wxWANTS_CHARS
)
69 wxFLAGS_MEMBER(wxFULL_REPAINT_ON_RESIZE
)
70 wxFLAGS_MEMBER(wxALWAYS_SHOW_SB
)
71 wxFLAGS_MEMBER(wxVSCROLL
)
72 wxFLAGS_MEMBER(wxHSCROLL
)
74 wxFLAGS_MEMBER(wxLC_LIST
)
75 wxFLAGS_MEMBER(wxLC_REPORT
)
76 wxFLAGS_MEMBER(wxLC_ICON
)
77 wxFLAGS_MEMBER(wxLC_SMALL_ICON
)
78 wxFLAGS_MEMBER(wxLC_ALIGN_TOP
)
79 wxFLAGS_MEMBER(wxLC_ALIGN_LEFT
)
80 wxFLAGS_MEMBER(wxLC_AUTOARRANGE
)
81 wxFLAGS_MEMBER(wxLC_USER_TEXT
)
82 wxFLAGS_MEMBER(wxLC_EDIT_LABELS
)
83 wxFLAGS_MEMBER(wxLC_NO_HEADER
)
84 wxFLAGS_MEMBER(wxLC_SINGLE_SEL
)
85 wxFLAGS_MEMBER(wxLC_SORT_ASCENDING
)
86 wxFLAGS_MEMBER(wxLC_SORT_DESCENDING
)
87 wxFLAGS_MEMBER(wxLC_VIRTUAL
)
89 wxEND_FLAGS( wxListCtrlStyle
)
91 IMPLEMENT_DYNAMIC_CLASS_XTI(wxListCtrl
, wxControl
,"wx/listctrl.h")
93 wxBEGIN_PROPERTIES_TABLE(wxListCtrl
)
94 wxEVENT_PROPERTY( TextUpdated
, wxEVT_COMMAND_TEXT_UPDATED
, wxCommandEvent
)
96 wxPROPERTY_FLAGS( WindowStyle
, wxListCtrlStyle
, long , SetWindowStyleFlag
, GetWindowStyleFlag
, EMPTY_MACROVALUE
, 0 /*flags*/ , wxT("Helpstring") , wxT("group")) // style
97 wxEND_PROPERTIES_TABLE()
99 wxBEGIN_HANDLERS_TABLE(wxListCtrl
)
100 wxEND_HANDLERS_TABLE()
102 wxCONSTRUCTOR_5( wxListCtrl
, wxWindow
* , Parent
, wxWindowID
, Id
, wxPoint
, Position
, wxSize
, Size
, long , WindowStyle
)
105 TODO : Expose more information of a list's layout etc. via appropriate objects (à la NotebookPageInfo)
108 IMPLEMENT_DYNAMIC_CLASS(wxListCtrl
, wxControl
)
111 IMPLEMENT_DYNAMIC_CLASS(wxListView
, wxListCtrl
)
112 IMPLEMENT_DYNAMIC_CLASS(wxListItem
, wxObject
)
114 IMPLEMENT_DYNAMIC_CLASS(wxListEvent
, wxNotifyEvent
)
116 WX_DECLARE_EXPORTED_LIST(wxListItem
, wxListItemList
);
117 #include "wx/listimpl.cpp"
118 WX_DEFINE_LIST(wxListItemList
)
119 WX_DEFINE_LIST(wxColumnList
)
121 // so we can check for column clicks
122 static const EventTypeSpec eventList
[] =
124 { kEventClassControl
, kEventControlHit
},
125 { kEventClassControl
, kEventControlDraw
}
128 static pascal OSStatus
wxMacListCtrlEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
130 OSStatus result
= eventNotHandledErr
;
132 wxMacCarbonEvent
cEvent( event
) ;
134 ControlRef controlRef
;
135 cEvent
.GetParameter( kEventParamDirectObject
, &controlRef
) ;
137 wxListCtrl
*window
= (wxListCtrl
*) data
;
138 wxListEvent
le( wxEVT_COMMAND_LIST_COL_CLICK
, window
->GetId() );
139 le
.SetEventObject( window
);
141 switch ( GetEventKind( event
) )
143 // check if the column was clicked on and fire an event if so
144 case kEventControlHit
:
146 ControlPartCode result
= cEvent
.GetParameter
<ControlPartCode
>(kEventParamControlPart
, typeControlPartCode
) ;
147 if (result
== kControlButtonPart
){
148 DataBrowserPropertyID col
;
149 GetDataBrowserSortProperty(controlRef
, &col
);
150 int column
= col
- kMinColumnId
;
152 window
->GetEventHandler()->ProcessEvent( le
);
154 result
= CallNextEventHandler(handler
, event
);
157 case kEventControlDraw
:
159 CGContextRef context
= cEvent
.GetParameter
<CGContextRef
>(kEventParamCGContextRef
, typeCGContextRef
) ;
160 window
->MacSetDrawingContext(context
);
161 result
= CallNextEventHandler(handler
, event
);
162 window
->MacSetDrawingContext(NULL
);
173 DEFINE_ONE_SHOT_HANDLER_GETTER( wxMacListCtrlEventHandler
)
175 class wxMacListCtrlItem
: public wxMacListBoxItem
180 virtual void Notification(wxMacDataItemBrowserControl
*owner
,
181 DataBrowserItemNotification message
,
182 DataBrowserItemDataRef itemData
) const;
184 virtual void SetColumnInfo( unsigned int column
, wxListItem
* item
);
185 virtual wxListItem
* GetColumnInfo( unsigned int column
);
186 virtual bool HasColumnInfo( unsigned int column
);
188 virtual void SetColumnTextValue( unsigned int column
, const wxString
& text
);
189 virtual const wxString
& GetColumnTextValue( unsigned int column
);
191 virtual int GetColumnImageValue( unsigned int column
);
192 virtual void SetColumnImageValue( unsigned int column
, int imageIndex
);
194 virtual ~wxMacListCtrlItem();
196 wxListItemList m_rowItems
;
199 DataBrowserDrawItemUPP gDataBrowserDrawItemUPP
= NULL
;
200 //DataBrowserEditItemUPP gDataBrowserEditItemUPP = NULL;
201 DataBrowserHitTestUPP gDataBrowserHitTestUPP
= NULL
;
203 // TODO: Make a better name!!
204 class wxMacDataBrowserListCtrlControl
: public wxMacDataItemBrowserControl
207 wxMacDataBrowserListCtrlControl( wxWindow
*peer
, const wxPoint
& pos
, const wxSize
& size
, long style
);
208 virtual ~wxMacDataBrowserListCtrlControl();
210 // create a list item (can be a subclass of wxMacListBoxItem)
212 virtual wxMacDataItem
* CreateItem();
214 virtual void MacInsertItem( unsigned int n
, wxListItem
* item
);
215 virtual void MacSetColumnInfo( unsigned int row
, unsigned int column
, wxListItem
* item
);
216 virtual void MacGetColumnInfo( unsigned int row
, unsigned int column
, wxListItem
& item
);
217 virtual void UpdateState(wxMacDataItem
* dataItem
, wxListItem
* item
);
220 // we need to override to provide specialized handling for virtual wxListCtrls
221 virtual OSStatus
GetSetItemData(DataBrowserItemID itemID
,
222 DataBrowserPropertyID property
,
223 DataBrowserItemDataRef itemData
,
224 Boolean changeValue
);
226 virtual void ItemNotification(
227 DataBrowserItemID itemID
,
228 DataBrowserItemNotification message
,
229 DataBrowserItemDataRef itemData
);
231 virtual Boolean
CompareItems(DataBrowserItemID itemOneID
,
232 DataBrowserItemID itemTwoID
,
233 DataBrowserPropertyID sortProperty
);
235 static pascal void DataBrowserDrawItemProc(ControlRef browser
,
236 DataBrowserItemID item
,
237 DataBrowserPropertyID property
,
238 DataBrowserItemState itemState
,
241 Boolean colorDevice
);
243 virtual void DrawItem(DataBrowserItemID itemID
,
244 DataBrowserPropertyID property
,
245 DataBrowserItemState itemState
,
246 const Rect
*itemRect
,
248 Boolean colorDevice
);
250 static pascal Boolean
DataBrowserEditTextProc(ControlRef browser
,
251 DataBrowserItemID item
,
252 DataBrowserPropertyID property
,
253 CFStringRef theString
,
254 Rect
*maxEditTextRect
,
255 Boolean
*shrinkToFit
);
257 static pascal Boolean
DataBrowserHitTestProc(ControlRef browser
,
258 DataBrowserItemID itemID
,
259 DataBrowserPropertyID property
,
261 const Rect
*mouseRect
) { return true; }
263 virtual bool ConfirmEditText(DataBrowserItemID item
,
264 DataBrowserPropertyID property
,
265 CFStringRef theString
,
266 Rect
*maxEditTextRect
,
267 Boolean
*shrinkToFit
);
271 wxClientDataType m_clientDataItemsType
;
276 class wxMacListCtrlEventDelegate
: public wxEvtHandler
279 wxMacListCtrlEventDelegate( wxListCtrl
* list
, int id
);
280 virtual bool ProcessEvent( wxEvent
& event
);
287 wxMacListCtrlEventDelegate::wxMacListCtrlEventDelegate( wxListCtrl
* list
, int id
)
293 bool wxMacListCtrlEventDelegate::ProcessEvent( wxEvent
& event
)
295 // even though we use a generic list ctrl underneath, make sure
296 // we present ourselves as wxListCtrl.
297 event
.SetEventObject( m_list
);
300 if ( !event
.IsKindOf( CLASSINFO( wxCommandEvent
) ) )
302 if (m_list
->GetEventHandler()->ProcessEvent( event
))
305 return wxEvtHandler::ProcessEvent(event
);
308 //-----------------------------------------------------------------------------
309 // wxListCtrlRenameTimer (internal)
310 //-----------------------------------------------------------------------------
312 class wxListCtrlRenameTimer
: public wxTimer
318 wxListCtrlRenameTimer( wxListCtrl
*owner
);
322 //-----------------------------------------------------------------------------
323 // wxListCtrlTextCtrlWrapper: wraps a wxTextCtrl to make it work for inline editing
324 //-----------------------------------------------------------------------------
326 class wxListCtrlTextCtrlWrapper
: public wxEvtHandler
329 // NB: text must be a valid object but not Create()d yet
330 wxListCtrlTextCtrlWrapper(wxListCtrl
*owner
,
334 wxTextCtrl
*GetText() const { return m_text
; }
336 void AcceptChangesAndFinish();
339 void OnChar( wxKeyEvent
&event
);
340 void OnKeyUp( wxKeyEvent
&event
);
341 void OnKillFocus( wxFocusEvent
&event
);
343 bool AcceptChanges();
349 wxString m_startValue
;
352 bool m_aboutToFinish
;
354 DECLARE_EVENT_TABLE()
357 //-----------------------------------------------------------------------------
358 // wxListCtrlRenameTimer (internal)
359 //-----------------------------------------------------------------------------
361 wxListCtrlRenameTimer::wxListCtrlRenameTimer( wxListCtrl
*owner
)
366 void wxListCtrlRenameTimer::Notify()
368 m_owner
->OnRenameTimer();
371 //-----------------------------------------------------------------------------
372 // wxListCtrlTextCtrlWrapper (internal)
373 //-----------------------------------------------------------------------------
375 BEGIN_EVENT_TABLE(wxListCtrlTextCtrlWrapper
, wxEvtHandler
)
376 EVT_CHAR (wxListCtrlTextCtrlWrapper::OnChar
)
377 EVT_KEY_UP (wxListCtrlTextCtrlWrapper::OnKeyUp
)
378 EVT_KILL_FOCUS (wxListCtrlTextCtrlWrapper::OnKillFocus
)
381 wxListCtrlTextCtrlWrapper::wxListCtrlTextCtrlWrapper(wxListCtrl
*owner
,
384 : m_startValue(owner
->GetItemText(itemEdit
)),
385 m_itemEdited(itemEdit
)
390 m_aboutToFinish
= false;
393 owner
->GetItemRect(itemEdit
, rectLabel
);
395 m_text
->Create(owner
, wxID_ANY
, m_startValue
,
396 wxPoint(rectLabel
.x
+8,rectLabel
.y
),
397 wxSize(rectLabel
.width
,rectLabel
.height
));
400 m_text
->PushEventHandler(this);
403 void wxListCtrlTextCtrlWrapper::Finish()
409 m_text
->RemoveEventHandler(this);
410 m_owner
->FinishEditing(m_text
);
412 wxPendingDelete
.Append( this );
416 bool wxListCtrlTextCtrlWrapper::AcceptChanges()
418 const wxString value
= m_text
->GetValue();
420 if ( value
== m_startValue
)
421 // nothing changed, always accept
424 if ( !m_owner
->OnRenameAccept(m_itemEdited
, value
) )
425 // vetoed by the user
428 // accepted, do rename the item
429 m_owner
->SetItemText(m_itemEdited
, value
);
434 void wxListCtrlTextCtrlWrapper::AcceptChangesAndFinish()
436 m_aboutToFinish
= true;
438 // Notify the owner about the changes
441 // Even if vetoed, close the control (consistent with MSW)
445 void wxListCtrlTextCtrlWrapper::OnChar( wxKeyEvent
&event
)
447 switch ( event
.m_keyCode
)
450 AcceptChangesAndFinish();
454 m_owner
->OnRenameCancelled( m_itemEdited
);
463 void wxListCtrlTextCtrlWrapper::OnKeyUp( wxKeyEvent
&event
)
471 // auto-grow the textctrl:
472 wxSize parentSize
= m_owner
->GetSize();
473 wxPoint myPos
= m_text
->GetPosition();
474 wxSize mySize
= m_text
->GetSize();
476 m_text
->GetTextExtent(m_text
->GetValue() + _T("MM"), &sx
, &sy
);
477 if (myPos
.x
+ sx
> parentSize
.x
)
478 sx
= parentSize
.x
- myPos
.x
;
481 m_text
->SetSize(sx
, wxDefaultCoord
);
486 void wxListCtrlTextCtrlWrapper::OnKillFocus( wxFocusEvent
&event
)
488 if ( !m_finished
&& !m_aboutToFinish
)
490 if ( !AcceptChanges() )
491 m_owner
->OnRenameCancelled( m_itemEdited
);
496 // We must let the native text control handle focus
500 BEGIN_EVENT_TABLE(wxListCtrl
, wxControl
)
501 EVT_LEFT_DOWN(wxListCtrl::OnLeftDown
)
502 EVT_LEFT_DCLICK(wxListCtrl::OnDblClick
)
505 // ============================================================================
507 // ============================================================================
509 wxMacListControl
* wxListCtrl::GetPeer() const
511 return dynamic_cast<wxMacListControl
*>(m_peer
);
514 // ----------------------------------------------------------------------------
515 // wxListCtrl construction
516 // ----------------------------------------------------------------------------
518 void wxListCtrl::Init()
520 m_imageListNormal
= NULL
;
521 m_imageListSmall
= NULL
;
522 m_imageListState
= NULL
;
524 // keep track of if we created our own image lists, or if they were assigned
526 m_ownsImageListNormal
= m_ownsImageListSmall
= m_ownsImageListState
= false;
530 m_genericImpl
= NULL
;
532 m_compareFunc
= NULL
;
533 m_compareFuncData
= 0;
534 m_colsInfo
= wxColumnList();
535 m_textColor
= wxNullColour
;
536 m_bgColor
= wxNullColour
;
537 m_textctrlWrapper
= NULL
;
539 m_renameTimer
= new wxListCtrlRenameTimer( this );
542 class wxGenericListCtrlHook
: public wxGenericListCtrl
545 wxGenericListCtrlHook(wxListCtrl
* parent
,
550 const wxValidator
& validator
,
551 const wxString
& name
)
552 : wxGenericListCtrl(parent
, id
, pos
, size
, style
, validator
, name
),
553 m_nativeListCtrl(parent
)
558 virtual wxListItemAttr
* OnGetItemAttr(long item
) const
560 return m_nativeListCtrl
->OnGetItemAttr(item
);
563 virtual int OnGetItemImage(long item
) const
565 return m_nativeListCtrl
->OnGetItemImage(item
);
568 virtual int OnGetItemColumnImage(long item
, long column
) const
570 return m_nativeListCtrl
->OnGetItemColumnImage(item
, column
);
573 virtual wxString
OnGetItemText(long item
, long column
) const
575 return m_nativeListCtrl
->OnGetItemText(item
, column
);
578 wxListCtrl
* m_nativeListCtrl
;
582 void wxListCtrl::OnLeftDown(wxMouseEvent
& event
)
584 if ( m_textctrlWrapper
)
587 m_textctrlWrapper
->AcceptChangesAndFinish();
591 long current
= HitTest(event
.GetPosition(), hitResult
);
592 if ((current
== m_current
) &&
593 (hitResult
== wxLIST_HITTEST_ONITEM
) &&
594 HasFlag(wxLC_EDIT_LABELS
) )
596 m_renameTimer
->Start( 100, true );
605 void wxListCtrl::OnDblClick(wxMouseEvent
& event
)
611 bool wxListCtrl::Create(wxWindow
*parent
,
616 const wxValidator
& validator
,
617 const wxString
& name
)
620 // for now, we'll always use the generic list control for ICON and LIST views,
621 // because they dynamically change the number of columns on resize.
622 // Also, allow the user to set it to use the list ctrl as well.
623 // Also, use generic list control in VIRTUAL mode.
624 if ( (wxSystemOptions::HasOption( wxMAC_ALWAYS_USE_GENERIC_LISTCTRL
)
625 && (wxSystemOptions::GetOptionInt( wxMAC_ALWAYS_USE_GENERIC_LISTCTRL
) == 1)) ||
626 (style
& wxLC_ICON
) || (style
& wxLC_SMALL_ICON
) || (style
& wxLC_LIST
) )
628 m_macIsUserPane
= true;
630 if ( !wxWindow::Create(parent
, id
, pos
, size
, style
& wxNO_BORDER
, name
) )
632 m_genericImpl
= new wxGenericListCtrlHook(this, id
, pos
, size
, style
, validator
, name
);
633 m_genericImpl
->PushEventHandler( new wxMacListCtrlEventDelegate( this, GetId() ) );
639 m_macIsUserPane
= false;
641 if ( !wxWindow::Create(parent
, id
, pos
, size
, style
, name
) )
643 m_dbImpl
= new wxMacDataBrowserListCtrlControl( this, pos
, size
, style
);
646 MacPostControlCreate( pos
, size
);
648 InstallControlEventHandler( m_peer
->GetControlRef() , GetwxMacListCtrlEventHandlerUPP(),
649 GetEventTypeCount(eventList
), eventList
, this,
650 (EventHandlerRef
*)&m_macListCtrlEventHandler
);
656 wxListCtrl::~wxListCtrl()
660 m_genericImpl
->PopEventHandler(/* deleteHandler = */ true);
663 if (m_ownsImageListNormal
)
664 delete m_imageListNormal
;
665 if (m_ownsImageListSmall
)
666 delete m_imageListSmall
;
667 if (m_ownsImageListState
)
668 delete m_imageListState
;
670 delete m_renameTimer
;
673 // ----------------------------------------------------------------------------
674 // set/get/change style
675 // ----------------------------------------------------------------------------
677 // Add or remove a single window style
678 void wxListCtrl::SetSingleStyle(long style
, bool add
)
680 long flag
= GetWindowStyleFlag();
682 // Get rid of conflicting styles
685 if ( style
& wxLC_MASK_TYPE
)
686 flag
= flag
& ~wxLC_MASK_TYPE
;
687 if ( style
& wxLC_MASK_ALIGN
)
688 flag
= flag
& ~wxLC_MASK_ALIGN
;
689 if ( style
& wxLC_MASK_SORT
)
690 flag
= flag
& ~wxLC_MASK_SORT
;
698 SetWindowStyleFlag(flag
);
701 // Set the whole window style
702 void wxListCtrl::SetWindowStyleFlag(long flag
)
704 if ( flag
!= m_windowStyle
)
706 m_windowStyle
= flag
;
710 m_genericImpl
->SetWindowStyleFlag(flag
);
717 void wxListCtrl::DoSetSize( int x
, int y
, int width
, int height
, int sizeFlags
)
719 wxControl::DoSetSize(x
, y
, width
, height
, sizeFlags
);
722 m_genericImpl
->SetSize(x
, y
, width
, height
, sizeFlags
);
725 wxSize
wxListCtrl::DoGetBestSize() const
728 return m_genericImpl
->GetBestSize();
730 return wxWindow::DoGetBestSize();
733 bool wxListCtrl::SetFont(const wxFont
& font
)
736 rv
= wxControl::SetFont(font
);
738 rv
= m_genericImpl
->SetFont(font
);
742 bool wxListCtrl::SetForegroundColour(const wxColour
& colour
)
746 rv
= m_genericImpl
->SetForegroundColour(colour
);
748 SetTextColour(colour
);
752 bool wxListCtrl::SetBackgroundColour(const wxColour
& colour
)
756 rv
= m_genericImpl
->SetBackgroundColour(colour
);
762 wxColour
wxListCtrl::GetBackgroundColour()
765 return m_genericImpl
->GetBackgroundColour();
772 // ----------------------------------------------------------------------------
774 // ----------------------------------------------------------------------------
776 // Gets information about this column
777 bool wxListCtrl::GetColumn(int col
, wxListItem
& item
) const
780 return m_genericImpl
->GetColumn(col
, item
);
787 wxColumnList::compatibility_iterator node
= m_colsInfo
.Item( col
);
788 wxASSERT_MSG( node
, _T("invalid column index in wxMacListCtrlItem") );
789 wxListItem
* column
= node
->GetData();
791 long mask
= column
->GetMask();
792 if (mask
& wxLIST_MASK_TEXT
)
793 item
.SetText(column
->GetText());
794 if (mask
& wxLIST_MASK_DATA
)
795 item
.SetData(column
->GetData());
796 if (mask
& wxLIST_MASK_IMAGE
)
797 item
.SetImage(column
->GetImage());
798 if (mask
& wxLIST_MASK_STATE
)
799 item
.SetState(column
->GetState());
800 if (mask
& wxLIST_MASK_FORMAT
)
801 item
.SetAlign(column
->GetAlign());
802 if (mask
& wxLIST_MASK_WIDTH
)
803 item
.SetWidth(column
->GetWidth());
809 // Sets information about this column
810 bool wxListCtrl::SetColumn(int col
, wxListItem
& item
)
813 return m_genericImpl
->SetColumn(col
, item
);
817 if ( col
>= (int)m_colsInfo
.GetCount() )
819 wxListItem
* listItem
= new wxListItem(item
);
820 m_colsInfo
.Append( listItem
);
825 GetColumn( col
, listItem
);
826 long mask
= item
.GetMask();
827 if (mask
& wxLIST_MASK_TEXT
)
828 listItem
.SetText(item
.GetText());
829 if (mask
& wxLIST_MASK_DATA
)
830 listItem
.SetData(item
.GetData());
831 if (mask
& wxLIST_MASK_IMAGE
)
832 listItem
.SetImage(item
.GetImage());
833 if (mask
& wxLIST_MASK_STATE
)
834 listItem
.SetState(item
.GetState());
835 if (mask
& wxLIST_MASK_FORMAT
)
836 listItem
.SetAlign(item
.GetAlign());
837 if (mask
& wxLIST_MASK_WIDTH
)
838 listItem
.SetWidth(item
.GetWidth());
841 // change the appearance in the databrowser.
842 DataBrowserListViewHeaderDesc columnDesc
;
843 columnDesc
.version
=kDataBrowserListViewLatestHeaderDesc
;
844 verify_noerr( m_dbImpl
->GetHeaderDesc( kMinColumnId
+ col
, &columnDesc
) );
847 if (item.GetMask() & wxLIST_MASK_TEXT)
851 enc = m_font.GetEncoding();
853 enc = wxLocale::GetSystemEncoding();
854 wxMacCFStringHolder cfTitle;
855 cfTitle.Assign( item.GetText() , enc );
856 if(columnDesc.titleString)
857 CFRelease(columnDesc.titleString);
858 columnDesc.titleString = cfTitle;
862 if (item
.GetMask() & wxLIST_MASK_IMAGE
&& item
.GetImage() != -1 )
864 columnDesc
.btnContentInfo
.contentType
= kControlContentIconRef
;
865 wxImageList
* imageList
= GetImageList(wxIMAGE_LIST_SMALL
);
866 if (imageList
&& imageList
->GetImageCount() > 0 )
868 wxBitmap bmp
= imageList
->GetBitmap( item
.GetImage() );
869 IconRef icon
= bmp
.GetBitmapData()->GetIconRef();
870 columnDesc
.btnContentInfo
.u
.iconRef
= icon
;
874 verify_noerr( m_dbImpl
->SetHeaderDesc( kMinColumnId
+ col
, &columnDesc
) );
880 int wxListCtrl::GetColumnCount() const
883 return m_genericImpl
->GetColumnCount();
888 m_dbImpl
->GetColumnCount(&count
);
895 // Gets the column width
896 int wxListCtrl::GetColumnWidth(int col
) const
899 return m_genericImpl
->GetColumnWidth(col
);
903 return m_dbImpl
->GetColumnWidth(col
);
909 // Sets the column width
910 bool wxListCtrl::SetColumnWidth(int col
, int width
)
913 return m_genericImpl
->SetColumnWidth(col
, width
);
918 if (width
== wxLIST_AUTOSIZE
|| width
== wxLIST_AUTOSIZE_USEHEADER
)
923 for (int column
= 0; column
< GetColumnCount(); column
++)
925 m_dbImpl
->SetColumnWidth(col
, mywidth
);
929 m_dbImpl
->SetColumnWidth(col
, mywidth
);
937 // Gets the number of items that can fit vertically in the
938 // visible area of the list control (list or report view)
939 // or the total number of items in the list control (icon
940 // or small icon view)
941 int wxListCtrl::GetCountPerPage() const
944 return m_genericImpl
->GetCountPerPage();
953 // Gets the edit control for editing labels.
954 wxTextCtrl
* wxListCtrl::GetEditControl() const
957 return m_genericImpl
->GetEditControl();
962 // Gets information about the item
963 bool wxListCtrl::GetItem(wxListItem
& info
) const
966 return m_genericImpl
->GetItem(info
);
971 m_dbImpl
->MacGetColumnInfo(info
.m_itemId
, info
.m_col
, info
);
974 info
.SetText( OnGetItemText(info
.m_itemId
, info
.m_col
) );
975 info
.SetImage( OnGetItemColumnImage(info
.m_itemId
, info
.m_col
) );
976 wxListItemAttr
* attrs
= OnGetItemAttr( info
.m_itemId
);
979 info
.SetFont( attrs
->GetFont() );
980 info
.SetBackgroundColour( attrs
->GetBackgroundColour() );
981 info
.SetTextColour( attrs
->GetTextColour() );
989 // Sets information about the item
990 bool wxListCtrl::SetItem(wxListItem
& info
)
993 return m_genericImpl
->SetItem(info
);
996 m_dbImpl
->MacSetColumnInfo( info
.m_itemId
, info
.m_col
, &info
);
1001 long wxListCtrl::SetItem(long index
, int col
, const wxString
& label
, int imageId
)
1004 return m_genericImpl
->SetItem(index
, col
, label
, imageId
);
1007 info
.m_text
= label
;
1008 info
.m_mask
= wxLIST_MASK_TEXT
;
1009 info
.m_itemId
= index
;
1013 info
.m_image
= imageId
;
1014 info
.m_mask
|= wxLIST_MASK_IMAGE
;
1016 return SetItem(info
);
1020 // Gets the item state
1021 int wxListCtrl::GetItemState(long item
, long stateMask
) const
1024 return m_genericImpl
->GetItemState(item
, stateMask
);
1028 info
.m_mask
= wxLIST_MASK_STATE
;
1029 info
.m_stateMask
= stateMask
;
1030 info
.m_itemId
= item
;
1035 return info
.m_state
;
1038 // Sets the item state
1039 bool wxListCtrl::SetItemState(long item
, long state
, long stateMask
)
1042 return m_genericImpl
->SetItemState(item
, state
, stateMask
);
1045 info
.m_mask
= wxLIST_MASK_STATE
;
1046 info
.m_stateMask
= stateMask
;
1047 info
.m_state
= state
;
1048 info
.m_itemId
= item
;
1049 return SetItem(info
);
1052 // Sets the item image
1053 bool wxListCtrl::SetItemImage(long item
, int image
, int WXUNUSED(selImage
))
1055 return SetItemColumnImage(item
, 0, image
);
1058 // Sets the item image
1059 bool wxListCtrl::SetItemColumnImage(long item
, long column
, int image
)
1062 return m_genericImpl
->SetItemColumnImage(item
, column
, image
);
1066 info
.m_mask
= wxLIST_MASK_IMAGE
;
1067 info
.m_image
= image
;
1068 info
.m_itemId
= item
;
1069 info
.m_col
= column
;
1071 return SetItem(info
);
1074 // Gets the item text
1075 wxString
wxListCtrl::GetItemText(long item
) const
1078 return m_genericImpl
->GetItemText(item
);
1082 info
.m_mask
= wxLIST_MASK_TEXT
;
1083 info
.m_itemId
= item
;
1086 return wxEmptyString
;
1090 // Sets the item text
1091 void wxListCtrl::SetItemText(long item
, const wxString
& str
)
1094 return m_genericImpl
->SetItemText(item
, str
);
1098 info
.m_mask
= wxLIST_MASK_TEXT
;
1099 info
.m_itemId
= item
;
1105 // Gets the item data
1106 long wxListCtrl::GetItemData(long item
) const
1109 return m_genericImpl
->GetItemData(item
);
1113 info
.m_mask
= wxLIST_MASK_DATA
;
1114 info
.m_itemId
= item
;
1121 // Sets the item data
1122 bool wxListCtrl::SetItemData(long item
, long data
)
1125 return m_genericImpl
->SetItemData(item
, data
);
1129 info
.m_mask
= wxLIST_MASK_DATA
;
1130 info
.m_itemId
= item
;
1133 return SetItem(info
);
1136 wxRect
wxListCtrl::GetViewRect() const
1138 wxASSERT_MSG( !HasFlag(wxLC_REPORT
| wxLC_LIST
),
1139 _T("wxListCtrl::GetViewRect() only works in icon mode") );
1142 return m_genericImpl
->GetViewRect();
1148 // Gets the item rectangle
1149 bool wxListCtrl::GetItemRect(long item
, wxRect
& rect
, int code
) const
1152 return m_genericImpl
->GetItemRect(item
, rect
, code
);
1157 DataBrowserItemID id
;
1158 DataBrowserPropertyID col
= kMinColumnId
;
1160 DataBrowserPropertyPart part
= kDataBrowserPropertyEnclosingPart
;
1161 if ( code
== wxLIST_RECT_LABEL
)
1162 part
= kDataBrowserPropertyTextPart
;
1163 else if ( code
== wxLIST_RECT_ICON
)
1164 part
= kDataBrowserPropertyIconPart
;
1166 if ( !(GetWindowStyleFlag() & wxLC_VIRTUAL
) )
1168 wxMacDataItem
* thisItem
= m_dbImpl
->GetItemFromLine(item
);
1169 id
= (DataBrowserItemID
) thisItem
;
1174 GetDataBrowserItemPartBounds( m_dbImpl
->GetControlRef(), id
, col
, part
, &bounds
);
1176 rect
.x
= bounds
.left
;
1177 rect
.y
= bounds
.top
;
1178 rect
.width
= bounds
.right
- bounds
.left
; //GetClientSize().x; // we need the width of the whole row, not just the item.
1179 rect
.height
= bounds
.bottom
- bounds
.top
;
1180 //fprintf("id = %d, bounds = %d, %d, %d, %d\n", id, rect.x, rect.y, rect.width, rect.height);
1185 // Gets the item position
1186 bool wxListCtrl::GetItemPosition(long item
, wxPoint
& pos
) const
1189 return m_genericImpl
->GetItemPosition(item
, pos
);
1191 bool success
= false;
1196 GetItemRect(item
, itemRect
);
1197 pos
= itemRect
.GetPosition();
1204 // Sets the item position.
1205 bool wxListCtrl::SetItemPosition(long item
, const wxPoint
& pos
)
1208 return m_genericImpl
->SetItemPosition(item
, pos
);
1213 // Gets the number of items in the list control
1214 int wxListCtrl::GetItemCount() const
1217 return m_genericImpl
->GetItemCount();
1220 return m_dbImpl
->MacGetCount();
1225 void wxListCtrl::SetItemSpacing( int spacing
, bool isSmall
)
1228 m_genericImpl
->SetItemSpacing(spacing
, isSmall
);
1231 wxSize
wxListCtrl::GetItemSpacing() const
1234 return m_genericImpl
->GetItemSpacing();
1236 return wxSize(0, 0);
1239 void wxListCtrl::SetItemTextColour( long item
, const wxColour
&col
)
1243 m_genericImpl
->SetItemTextColour(item
, col
);
1248 info
.m_itemId
= item
;
1249 info
.SetTextColour( col
);
1253 wxColour
wxListCtrl::GetItemTextColour( long item
) const
1256 return m_genericImpl
->GetItemTextColour(item
);
1262 return info
.GetTextColour();
1264 return wxNullColour
;
1267 void wxListCtrl::SetItemBackgroundColour( long item
, const wxColour
&col
)
1271 m_genericImpl
->SetItemBackgroundColour(item
, col
);
1276 info
.m_itemId
= item
;
1277 info
.SetBackgroundColour( col
);
1281 wxColour
wxListCtrl::GetItemBackgroundColour( long item
) const
1284 return m_genericImpl
->GetItemBackgroundColour(item
);
1290 return info
.GetBackgroundColour();
1292 return wxNullColour
;
1295 void wxListCtrl::SetItemFont( long item
, const wxFont
&f
)
1299 m_genericImpl
->SetItemFont(item
, f
);
1304 info
.m_itemId
= item
;
1309 wxFont
wxListCtrl::GetItemFont( long item
) const
1312 return m_genericImpl
->GetItemFont(item
);
1318 return info
.GetFont();
1324 // Gets the number of selected items in the list control
1325 int wxListCtrl::GetSelectedItemCount() const
1328 return m_genericImpl
->GetSelectedItemCount();
1331 return m_dbImpl
->GetSelectedItemCount(NULL
, true);
1336 // Gets the text colour of the listview
1337 wxColour
wxListCtrl::GetTextColour() const
1340 return m_genericImpl
->GetTextColour();
1342 // TODO: we need owner drawn list items to customize text color.
1346 return wxNullColour
;
1349 // Sets the text colour of the listview
1350 void wxListCtrl::SetTextColour(const wxColour
& col
)
1354 m_genericImpl
->SetTextColour(col
);
1362 // Gets the index of the topmost visible item when in
1363 // list or report view
1364 long wxListCtrl::GetTopItem() const
1367 return m_genericImpl
->GetTopItem();
1372 // Searches for an item, starting from 'item'.
1373 // 'geometry' is one of
1374 // wxLIST_NEXT_ABOVE/ALL/BELOW/LEFT/RIGHT.
1375 // 'state' is a state bit flag, one or more of
1376 // wxLIST_STATE_DROPHILITED/FOCUSED/SELECTED/CUT.
1377 // item can be -1 to find the first item that matches the
1379 // Returns the item or -1 if unsuccessful.
1380 long wxListCtrl::GetNextItem(long item
, int geom
, int state
) const
1383 return m_genericImpl
->GetNextItem(item
, geom
, state
);
1385 if (m_dbImpl
&& geom
== wxLIST_NEXT_ALL
&& state
== wxLIST_STATE_SELECTED
)
1387 long count
= m_dbImpl
->MacGetCount() ;
1388 for ( long line
= item
+ 1 ; line
< count
; line
++ )
1390 wxMacDataItem
* id
= m_dbImpl
->GetItemFromLine(line
);
1391 if ( m_dbImpl
->IsItemSelected(id
) )
1401 wxImageList
*wxListCtrl::GetImageList(int which
) const
1404 return m_genericImpl
->GetImageList(which
);
1406 if ( which
== wxIMAGE_LIST_NORMAL
)
1408 return m_imageListNormal
;
1410 else if ( which
== wxIMAGE_LIST_SMALL
)
1412 return m_imageListSmall
;
1414 else if ( which
== wxIMAGE_LIST_STATE
)
1416 return m_imageListState
;
1421 void wxListCtrl::SetImageList(wxImageList
*imageList
, int which
)
1425 m_genericImpl
->SetImageList(imageList
, which
);
1429 if ( which
== wxIMAGE_LIST_NORMAL
)
1431 if (m_ownsImageListNormal
) delete m_imageListNormal
;
1432 m_imageListNormal
= imageList
;
1433 m_ownsImageListNormal
= false;
1435 else if ( which
== wxIMAGE_LIST_SMALL
)
1437 if (m_ownsImageListSmall
) delete m_imageListSmall
;
1438 m_imageListSmall
= imageList
;
1439 m_ownsImageListSmall
= false;
1441 else if ( which
== wxIMAGE_LIST_STATE
)
1443 if (m_ownsImageListState
) delete m_imageListState
;
1444 m_imageListState
= imageList
;
1445 m_ownsImageListState
= false;
1449 void wxListCtrl::AssignImageList(wxImageList
*imageList
, int which
)
1453 m_genericImpl
->AssignImageList(imageList
, which
);
1457 SetImageList(imageList
, which
);
1458 if ( which
== wxIMAGE_LIST_NORMAL
)
1459 m_ownsImageListNormal
= true;
1460 else if ( which
== wxIMAGE_LIST_SMALL
)
1461 m_ownsImageListSmall
= true;
1462 else if ( which
== wxIMAGE_LIST_STATE
)
1463 m_ownsImageListState
= true;
1466 // ----------------------------------------------------------------------------
1468 // ----------------------------------------------------------------------------
1470 // Arranges the items
1471 bool wxListCtrl::Arrange(int flag
)
1474 return m_genericImpl
->Arrange(flag
);
1479 bool wxListCtrl::DeleteItem(long item
)
1482 return m_genericImpl
->DeleteItem(item
);
1486 m_dbImpl
->MacDelete(item
);
1487 wxListEvent
event( wxEVT_COMMAND_LIST_DELETE_ITEM
, GetId() );
1488 event
.SetEventObject( this );
1489 event
.m_itemIndex
= item
;
1490 GetEventHandler()->ProcessEvent( event
);
1496 // Deletes all items
1497 bool wxListCtrl::DeleteAllItems()
1500 return m_genericImpl
->DeleteAllItems();
1504 m_dbImpl
->MacClear();
1505 wxListEvent
event( wxEVT_COMMAND_LIST_DELETE_ALL_ITEMS
, GetId() );
1506 event
.SetEventObject( this );
1507 GetEventHandler()->ProcessEvent( event
);
1512 // Deletes all items
1513 bool wxListCtrl::DeleteAllColumns()
1516 return m_genericImpl
->DeleteAllColumns();
1521 m_dbImpl
->GetColumnCount(&cols
);
1522 for (UInt32 col
= 0; col
< cols
; col
++)
1532 bool wxListCtrl::DeleteColumn(int col
)
1535 return m_genericImpl
->DeleteColumn(col
);
1539 OSStatus err
= m_dbImpl
->RemoveColumn(col
);
1540 return err
== noErr
;
1546 // Clears items, and columns if there are any.
1547 void wxListCtrl::ClearAll()
1551 m_genericImpl
->ClearAll();
1562 wxTextCtrl
* wxListCtrl::EditLabel(long item
, wxClassInfo
* textControlClass
)
1565 return m_genericImpl
->EditLabel(item
, textControlClass
);
1569 wxCHECK_MSG( (item
>= 0) && ((long)item
< GetItemCount()), NULL
,
1570 wxT("wrong index in wxListCtrl::EditLabel()") );
1572 wxASSERT_MSG( textControlClass
->IsKindOf(CLASSINFO(wxTextCtrl
)),
1573 wxT("EditLabel() needs a text control") );
1575 wxListEvent
le( wxEVT_COMMAND_LIST_BEGIN_LABEL_EDIT
, GetParent()->GetId() );
1576 le
.SetEventObject( this );
1577 le
.m_itemIndex
= item
;
1579 GetItem( le
.m_item
);
1581 if ( GetParent()->GetEventHandler()->ProcessEvent( le
) && !le
.IsAllowed() )
1583 // vetoed by user code
1587 wxTextCtrl
* const text
= (wxTextCtrl
*)textControlClass
->CreateObject();
1588 m_textctrlWrapper
= new wxListCtrlTextCtrlWrapper(this, text
, item
);
1589 return m_textctrlWrapper
->GetText();
1594 // End label editing, optionally cancelling the edit
1595 bool wxListCtrl::EndEditLabel(bool cancel
)
1597 // TODO: generic impl. doesn't have this method - is it needed for us?
1599 return true; // m_genericImpl->EndEditLabel(cancel);
1602 verify_noerr( SetDataBrowserEditItem(m_dbImpl
->GetControlRef(), kDataBrowserNoItem
, kMinColumnId
) );
1606 // Ensures this item is visible
1607 bool wxListCtrl::EnsureVisible(long item
)
1610 return m_genericImpl
->EnsureVisible(item
);
1614 wxMacDataItem
* dataItem
= m_dbImpl
->GetItemFromLine(item
);
1615 m_dbImpl
->RevealItem(dataItem
, kDataBrowserRevealWithoutSelecting
);
1621 // Find an item whose label matches this string, starting from the item after 'start'
1622 // or the beginning if 'start' is -1.
1623 long wxListCtrl::FindItem(long start
, const wxString
& str
, bool partial
)
1626 return m_genericImpl
->FindItem(start
, str
, partial
);
1631 // Find an item whose data matches this data, starting from the item after 'start'
1632 // or the beginning if 'start' is -1.
1633 long wxListCtrl::FindItem(long start
, long data
)
1636 return m_genericImpl
->FindItem(start
, data
);
1638 long idx
= start
+ 1;
1639 long count
= GetItemCount();
1643 if (GetItemData(idx
) == data
)
1651 // Find an item nearest this position in the specified direction, starting from
1652 // the item after 'start' or the beginning if 'start' is -1.
1653 long wxListCtrl::FindItem(long start
, const wxPoint
& pt
, int direction
)
1656 return m_genericImpl
->FindItem(start
, pt
, direction
);
1660 // Determines which item (if any) is at the specified point,
1661 // giving details in 'flags' (see wxLIST_HITTEST_... flags above)
1663 wxListCtrl::HitTest(const wxPoint
& point
, int& flags
, long *ptrSubItem
) const
1666 return m_genericImpl
->HitTest(point
, flags
, ptrSubItem
);
1668 flags
= wxLIST_HITTEST_NOWHERE
;
1671 int colHeaderHeight
= 22; // TODO: Find a way to get this value from the db control?
1672 UInt16 rowHeight
= 0;
1673 m_dbImpl
->GetDefaultRowHeight(&rowHeight
);
1676 // get the actual row by taking scroll position into account
1677 UInt32 offsetX
, offsetY
;
1678 m_dbImpl
->GetScrollPosition( &offsetY
, &offsetX
);
1681 if ( !(GetWindowStyleFlag() & wxLC_NO_HEADER
) )
1682 y
-= colHeaderHeight
;
1684 int row
= y
/ rowHeight
;
1685 DataBrowserItemID id
;
1686 m_dbImpl
->GetItemID( (DataBrowserTableViewRowIndex
) row
, &id
);
1688 // TODO: Use GetDataBrowserItemPartBounds to return if we are in icon or label
1689 if ( !(GetWindowStyleFlag() & wxLC_VIRTUAL
) )
1691 wxMacListCtrlItem
* lcItem
;
1692 lcItem
= (wxMacListCtrlItem
*) id
;
1695 flags
= wxLIST_HITTEST_ONITEM
;
1701 if (row
< GetItemCount() )
1703 flags
= wxLIST_HITTEST_ONITEM
;
1713 // Inserts an item, returning the index of the new item if successful,
1715 long wxListCtrl::InsertItem(wxListItem
& info
)
1717 wxASSERT_MSG( !IsVirtual(), _T("can't be used with virtual controls") );
1720 return m_genericImpl
->InsertItem(info
);
1724 int count
= GetItemCount();
1726 if (info
.m_itemId
> count
)
1727 info
.m_itemId
= count
;
1729 m_dbImpl
->MacInsertItem(info
.m_itemId
, &info
);
1730 wxListEvent
event( wxEVT_COMMAND_LIST_INSERT_ITEM
, GetId() );
1731 event
.SetEventObject( this );
1732 event
.m_itemIndex
= info
.m_itemId
;
1733 GetEventHandler()->ProcessEvent( event
);
1736 return info
.m_itemId
;
1739 long wxListCtrl::InsertItem(long index
, const wxString
& label
)
1742 return m_genericImpl
->InsertItem(index
, label
);
1745 info
.m_text
= label
;
1746 info
.m_mask
= wxLIST_MASK_TEXT
;
1747 info
.m_itemId
= index
;
1748 return InsertItem(info
);
1751 // Inserts an image item
1752 long wxListCtrl::InsertItem(long index
, int imageIndex
)
1755 return m_genericImpl
->InsertItem(index
, imageIndex
);
1758 info
.m_image
= imageIndex
;
1759 info
.m_mask
= wxLIST_MASK_IMAGE
;
1760 info
.m_itemId
= index
;
1761 return InsertItem(info
);
1764 // Inserts an image/string item
1765 long wxListCtrl::InsertItem(long index
, const wxString
& label
, int imageIndex
)
1768 return m_genericImpl
->InsertItem(index
, label
, imageIndex
);
1771 info
.m_image
= imageIndex
;
1772 info
.m_text
= label
;
1773 info
.m_mask
= wxLIST_MASK_IMAGE
| wxLIST_MASK_TEXT
;
1774 info
.m_itemId
= index
;
1775 return InsertItem(info
);
1778 // For list view mode (only), inserts a column.
1779 long wxListCtrl::InsertColumn(long col
, wxListItem
& item
)
1782 return m_genericImpl
->InsertColumn(col
, item
);
1786 int width
= item
.GetWidth();
1787 if ( !(item
.GetMask() & wxLIST_MASK_WIDTH
) )
1790 DataBrowserPropertyType type
= kDataBrowserCustomType
; //kDataBrowserTextType;
1791 wxImageList
* imageList
= GetImageList(wxIMAGE_LIST_SMALL
);
1792 if (imageList
&& imageList
->GetImageCount() > 0)
1794 wxBitmap bmp
= imageList
->GetBitmap(0);
1796 // type = kDataBrowserIconAndTextType;
1799 SInt16 just
= teFlushDefault
;
1800 if (item
.GetMask() & wxLIST_MASK_FORMAT
)
1802 if (item
.GetAlign() == wxLIST_FORMAT_LEFT
)
1804 else if (item
.GetAlign() == wxLIST_FORMAT_CENTER
)
1806 else if (item
.GetAlign() == wxLIST_FORMAT_RIGHT
)
1807 just
= teFlushRight
;
1809 m_dbImpl
->InsertColumn(col
, type
, item
.GetText(), just
, width
);
1810 SetColumn(col
, item
);
1812 // set/remove options based on the wxListCtrl type.
1813 DataBrowserTableViewColumnID id
;
1814 m_dbImpl
->GetColumnIDFromIndex(col
, &id
);
1815 DataBrowserPropertyFlags flags
;
1816 verify_noerr(m_dbImpl
->GetPropertyFlags(id
, &flags
));
1817 if (GetWindowStyleFlag() & wxLC_EDIT_LABELS
)
1818 flags
|= kDataBrowserPropertyIsEditable
;
1820 if (GetWindowStyleFlag() & wxLC_VIRTUAL
){
1821 flags
&= ~kDataBrowserListViewSortableColumn
;
1823 verify_noerr(m_dbImpl
->SetPropertyFlags(id
, flags
));
1829 long wxListCtrl::InsertColumn(long col
,
1830 const wxString
& heading
,
1835 return m_genericImpl
->InsertColumn(col
, heading
, format
, width
);
1838 item
.m_mask
= wxLIST_MASK_TEXT
| wxLIST_MASK_FORMAT
;
1839 item
.m_text
= heading
;
1842 item
.m_mask
|= wxLIST_MASK_WIDTH
;
1843 item
.m_width
= width
;
1845 item
.m_format
= format
;
1847 return InsertColumn(col
, item
);
1850 // scroll the control by the given number of pixels (exception: in list view,
1851 // dx is interpreted as number of columns)
1852 bool wxListCtrl::ScrollList(int dx
, int dy
)
1855 return m_genericImpl
->ScrollList(dx
, dy
);
1859 m_dbImpl
->SetScrollPosition(dx
, dy
);
1865 bool wxListCtrl::SortItems(wxListCtrlCompare fn
, long data
)
1868 return m_genericImpl
->SortItems(fn
, data
);
1873 m_compareFuncData
= data
;
1879 void wxListCtrl::OnRenameTimer()
1881 wxCHECK_RET( HasCurrent(), wxT("unexpected rename timer") );
1883 EditLabel( m_current
);
1886 bool wxListCtrl::OnRenameAccept(long itemEdit
, const wxString
& value
)
1888 wxListEvent
le( wxEVT_COMMAND_LIST_END_LABEL_EDIT
, GetId() );
1889 le
.SetEventObject( this );
1890 le
.m_itemIndex
= itemEdit
;
1892 GetItem( le
.m_item
);
1893 le
.m_item
.m_text
= value
;
1894 return !GetEventHandler()->ProcessEvent( le
) ||
1898 void wxListCtrl::OnRenameCancelled(long itemEdit
)
1900 // let owner know that the edit was cancelled
1901 wxListEvent
le( wxEVT_COMMAND_LIST_END_LABEL_EDIT
, GetParent()->GetId() );
1903 le
.SetEditCanceled(true);
1905 le
.SetEventObject( this );
1906 le
.m_itemIndex
= itemEdit
;
1908 GetItem( le
.m_item
);
1909 GetEventHandler()->ProcessEvent( le
);
1912 // ----------------------------------------------------------------------------
1913 // virtual list controls
1914 // ----------------------------------------------------------------------------
1916 wxString
wxListCtrl::OnGetItemText(long WXUNUSED(item
), long WXUNUSED(col
)) const
1918 // this is a pure virtual function, in fact - which is not really pure
1919 // because the controls which are not virtual don't need to implement it
1920 wxFAIL_MSG( _T("wxListCtrl::OnGetItemText not supposed to be called") );
1922 return wxEmptyString
;
1925 int wxListCtrl::OnGetItemImage(long WXUNUSED(item
)) const
1927 wxCHECK_MSG(!GetImageList(wxIMAGE_LIST_SMALL
),
1929 wxT("List control has an image list, OnGetItemImage or OnGetItemColumnImage should be overridden."));
1933 int wxListCtrl::OnGetItemColumnImage(long item
, long column
) const
1936 return OnGetItemImage(item
);
1941 wxListItemAttr
*wxListCtrl::OnGetItemAttr(long WXUNUSED_UNLESS_DEBUG(item
)) const
1943 wxASSERT_MSG( item
>= 0 && item
< GetItemCount(),
1944 _T("invalid item index in OnGetItemAttr()") );
1946 // no attributes by default
1950 void wxListCtrl::SetItemCount(long count
)
1952 wxASSERT_MSG( IsVirtual(), _T("this is for virtual controls only") );
1956 m_genericImpl
->SetItemCount(count
);
1962 // we need to temporarily disable the new item creation notification
1963 // procedure to speed things up
1964 // FIXME: Even this doesn't seem to help much...
1965 DataBrowserCallbacks callbacks
;
1966 DataBrowserItemNotificationUPP itemUPP
;
1967 GetDataBrowserCallbacks(m_dbImpl
->GetControlRef(), &callbacks
);
1968 itemUPP
= callbacks
.u
.v1
.itemNotificationCallback
;
1969 callbacks
.u
.v1
.itemNotificationCallback
= 0;
1970 m_dbImpl
->SetCallbacks(&callbacks
);
1971 ::AddDataBrowserItems(m_dbImpl
->GetControlRef(), kDataBrowserNoItem
,
1972 count
, NULL
, kDataBrowserItemNoProperty
);
1973 callbacks
.u
.v1
.itemNotificationCallback
= itemUPP
;
1974 m_dbImpl
->SetCallbacks(&callbacks
);
1979 void wxListCtrl::RefreshItem(long item
)
1983 m_genericImpl
->RefreshItem(item
);
1988 GetItemRect(item
, rect
);
1992 void wxListCtrl::RefreshItems(long itemFrom
, long itemTo
)
1996 m_genericImpl
->RefreshItems(itemFrom
, itemTo
);
2000 wxRect rect1
, rect2
;
2001 GetItemRect(itemFrom
, rect1
);
2002 GetItemRect(itemTo
, rect2
);
2004 wxRect rect
= rect1
;
2005 rect
.height
= rect2
.GetBottom() - rect1
.GetTop();
2011 // wxMac internal data structures
2013 wxMacListCtrlItem::~wxMacListCtrlItem()
2017 void wxMacListCtrlItem::Notification(wxMacDataItemBrowserControl
*owner
,
2018 DataBrowserItemNotification message
,
2019 DataBrowserItemDataRef itemData
) const
2022 wxMacDataBrowserListCtrlControl
*lb
= dynamic_cast<wxMacDataBrowserListCtrlControl
*>(owner
);
2024 // we want to depend on as little as possible to make sure tear-down of controls is safe
2025 if ( message
== kDataBrowserItemRemoved
)
2027 if ( lb
!= NULL
&& lb
->GetClientDataType() == wxClientData_Object
)
2029 delete (wxClientData
*) (m_data
);
2035 else if ( message
== kDataBrowserItemAdded
)
2037 // we don't issue events on adding, the item is not really stored in the list yet, so we
2038 // avoid asserts by gettting out now
2042 wxListCtrl
*list
= wxDynamicCast( owner
->GetPeer() , wxListCtrl
);
2045 bool trigger
= false;
2047 wxListEvent
event( wxEVT_COMMAND_LIST_ITEM_SELECTED
, list
->GetId() );
2048 bool isSingle
= (list
->GetWindowStyle() & wxLC_SINGLE_SEL
) != 0;
2050 event
.SetEventObject( list
);
2051 event
.m_itemIndex
= owner
->GetLineFromItem( this ) ;
2052 if ( !list
->IsVirtual() )
2054 lb
->MacGetColumnInfo(event
.m_itemIndex
,0,event
.m_item
);
2059 case kDataBrowserItemDeselected
:
2060 event
.SetEventType(wxEVT_COMMAND_LIST_ITEM_DESELECTED
);
2062 trigger
= !lb
->IsSelectionSuppressed();
2065 case kDataBrowserItemSelected
:
2066 trigger
= !lb
->IsSelectionSuppressed();
2069 case kDataBrowserItemDoubleClicked
:
2070 event
.SetEventType( wxEVT_COMMAND_LIST_ITEM_ACTIVATED
);
2074 case kDataBrowserEditStarted
:
2075 // TODO : how to veto ?
2076 event
.SetEventType( wxEVT_COMMAND_LIST_BEGIN_LABEL_EDIT
) ;
2080 case kDataBrowserEditStopped
:
2081 // TODO probably trigger only upon the value store callback, because
2082 // here IIRC we cannot veto
2083 event
.SetEventType( wxEVT_COMMAND_LIST_END_LABEL_EDIT
) ;
2093 // direct notification is not always having the listbox GetSelection() having in synch with event
2094 wxPostEvent( list
->GetEventHandler(), event
);
2100 wxMacDataBrowserListCtrlControl::wxMacDataBrowserListCtrlControl( wxWindow
*peer
, const wxPoint
& pos
, const wxSize
& size
, long style
)
2101 : wxMacDataItemBrowserControl( peer
, pos
, size
, style
)
2103 OSStatus err
= noErr
;
2104 m_clientDataItemsType
= wxClientData_None
;
2105 m_isVirtual
= false;
2107 if ( style
& wxLC_VIRTUAL
)
2110 DataBrowserSelectionFlags options
= kDataBrowserDragSelect
;
2111 if ( style
& wxLC_SINGLE_SEL
)
2113 options
|= kDataBrowserSelectOnlyOne
;
2117 options
|= kDataBrowserCmdTogglesSelection
;
2120 err
= SetSelectionFlags( options
);
2121 verify_noerr( err
);
2123 DataBrowserCustomCallbacks callbacks
;
2124 InitializeDataBrowserCustomCallbacks( &callbacks
, kDataBrowserLatestCustomCallbacks
);
2126 if ( gDataBrowserDrawItemUPP
== NULL
)
2127 gDataBrowserDrawItemUPP
= NewDataBrowserDrawItemUPP(DataBrowserDrawItemProc
);
2129 // if ( gDataBrowserEditItemUPP == NULL )
2130 // gDataBrowserEditItemUPP = NewDataBrowserEditItemUPP(DataBrowserEditTextProc);
2132 if ( gDataBrowserHitTestUPP
== NULL
)
2133 gDataBrowserHitTestUPP
= NewDataBrowserHitTestUPP(DataBrowserHitTestProc
);
2135 callbacks
.u
.v1
.drawItemCallback
= gDataBrowserDrawItemUPP
;
2136 // callbacks.u.v1.editTextCallback = gDataBrowserEditItemUPP;
2137 callbacks
.u
.v1
.hitTestCallback
= gDataBrowserHitTestUPP
;
2139 SetDataBrowserCustomCallbacks( GetControlRef(), &callbacks
);
2141 if ( style
& wxLC_LIST
)
2143 InsertColumn(0, kDataBrowserIconAndTextType
, wxEmptyString
, -1, -1);
2144 verify_noerr( AutoSizeColumns() );
2147 if ( style
& wxLC_LIST
|| style
& wxLC_NO_HEADER
)
2148 verify_noerr( SetHeaderButtonHeight( 0 ) );
2151 SetSortProperty( kMinColumnId
- 1 );
2153 SetSortProperty( kMinColumnId
);
2154 if ( style
& wxLC_SORT_ASCENDING
)
2156 m_sortOrder
= SortOrder_Text_Ascending
;
2157 SetSortOrder( kDataBrowserOrderIncreasing
);
2159 else if ( style
& wxLC_SORT_DESCENDING
)
2161 m_sortOrder
= SortOrder_Text_Descending
;
2162 SetSortOrder( kDataBrowserOrderDecreasing
);
2166 m_sortOrder
= SortOrder_None
;
2169 if ( style
& wxLC_VRULES
)
2171 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4
2172 verify_noerr( DataBrowserChangeAttributes(m_controlRef
, kDataBrowserAttributeListViewDrawColumnDividers
, kDataBrowserAttributeNone
) );
2176 verify_noerr( SetHiliteStyle(kDataBrowserTableViewFillHilite
) );
2177 err
= SetHasScrollBars( (style
& wxHSCROLL
) != 0 , true );
2180 pascal Boolean
wxMacDataBrowserListCtrlControl::DataBrowserEditTextProc(
2182 DataBrowserItemID itemID
,
2183 DataBrowserPropertyID property
,
2184 CFStringRef theString
,
2185 Rect
*maxEditTextRect
,
2186 Boolean
*shrinkToFit
)
2188 Boolean result
= false;
2189 wxMacDataBrowserListCtrlControl
* ctl
= dynamic_cast<wxMacDataBrowserListCtrlControl
*>( wxMacControl::GetReferenceFromNativeControl( browser
) );
2192 result
= ctl
->ConfirmEditText(itemID
, property
, theString
, maxEditTextRect
, shrinkToFit
);
2193 theString
= CFSTR("Hello!");
2198 bool wxMacDataBrowserListCtrlControl::ConfirmEditText(
2199 DataBrowserItemID itemID
,
2200 DataBrowserPropertyID property
,
2201 CFStringRef theString
,
2202 Rect
*maxEditTextRect
,
2203 Boolean
*shrinkToFit
)
2205 //wxListCtrl* list = wxDynamicCast( GetPeer() , wxListCtrl );
2209 pascal void wxMacDataBrowserListCtrlControl::DataBrowserDrawItemProc(
2211 DataBrowserItemID itemID
,
2212 DataBrowserPropertyID property
,
2213 DataBrowserItemState itemState
,
2214 const Rect
*itemRect
,
2216 Boolean colorDevice
)
2218 wxMacDataBrowserListCtrlControl
* ctl
= dynamic_cast<wxMacDataBrowserListCtrlControl
*>( wxMacControl::GetReferenceFromNativeControl( browser
) );
2221 ctl
->DrawItem(itemID
, property
, itemState
, itemRect
, gdDepth
, colorDevice
);
2225 // routines needed for DrawItem
2230 kTextBoxHeight
= 14,
2231 kIconTextSpacingV
= 2,
2233 kContentHeight
= kIconHeight
+ kTextBoxHeight
+ kIconTextSpacingV
2236 static void calculateCGDrawingBounds(CGRect inItemRect
, CGRect
*outIconRect
, CGRect
*outTextRect
, bool hasIcon
= false)
2239 float iconH
, iconW
= 0;
2240 float padding
= kItemPadding
;
2243 iconH
= kIconHeight
;
2245 padding
= padding
*2;
2248 textBottom
= inItemRect
.origin
.y
;
2250 *outIconRect
= CGRectMake(inItemRect
.origin
.x
+ kItemPadding
,
2251 textBottom
+ kIconTextSpacingV
, kIconWidth
,
2254 *outTextRect
= CGRectMake(inItemRect
.origin
.x
+ padding
+ iconW
,
2255 textBottom
+ kIconTextSpacingV
, inItemRect
.size
.width
- padding
- iconW
,
2256 inItemRect
.size
.height
- kIconTextSpacingV
);
2259 void wxMacDataBrowserListCtrlControl::DrawItem(
2260 DataBrowserItemID itemID
,
2261 DataBrowserPropertyID property
,
2262 DataBrowserItemState itemState
,
2263 const Rect
*itemRect
,
2265 Boolean colorDevice
)
2268 wxFont font
= wxNullFont
;
2270 short listColumn
= property
- kMinColumnId
;
2272 wxListCtrl
* list
= wxDynamicCast( GetPeer() , wxListCtrl
);
2273 wxMacListCtrlItem
* lcItem
;
2274 wxColour color
= *wxBLACK
;
2275 wxColour bgColor
= wxNullColour
;
2277 if (listColumn
>= 0)
2281 lcItem
= (wxMacListCtrlItem
*) itemID
;
2282 if (lcItem
->HasColumnInfo(listColumn
)){
2283 wxListItem
* item
= lcItem
->GetColumnInfo(listColumn
);
2285 // we always use the 0 column to get font and text/background colors.
2286 if (lcItem
->HasColumnInfo(0))
2288 wxListItem
* firstItem
= lcItem
->GetColumnInfo(0);
2289 color
= firstItem
->GetTextColour();
2290 bgColor
= firstItem
->GetBackgroundColour();
2291 font
= firstItem
->GetFont();
2294 if (item
->GetMask() & wxLIST_MASK_TEXT
)
2295 text
= item
->GetText();
2296 if (item
->GetMask() & wxLIST_MASK_IMAGE
)
2297 imgIndex
= item
->GetImage();
2303 text
= list
->OnGetItemText( (long)itemID
-1, listColumn
);
2304 imgIndex
= list
->OnGetItemColumnImage( (long)itemID
-1, listColumn
);
2305 wxListItemAttr
* attrs
= list
->OnGetItemAttr( (long)itemID
-1 );
2308 if (attrs
->HasBackgroundColour())
2309 bgColor
= attrs
->GetBackgroundColour();
2310 if (attrs
->HasTextColour())
2311 color
= attrs
->GetTextColour();
2312 if (attrs
->HasFont())
2313 font
= attrs
->GetFont();
2318 wxColour listBgColor
= list
->GetBackgroundColour();
2319 if (bgColor
== wxNullColour
)
2320 bgColor
= listBgColor
;
2322 wxFont listFont
= list
->GetFont();
2323 if (font
== wxNullFont
)
2326 wxMacCFStringHolder cfString
;
2327 cfString
.Assign( text
, wxLocale::GetSystemEncoding() );
2330 CGRect enclosingCGRect
, iconCGRect
, textCGRect
;
2332 ThemeDrawingState savedState
= NULL
;
2333 CGContextRef context
= (CGContextRef
)list
->MacGetDrawingContext();
2334 RGBColor labelColor
;
2336 GetDataBrowserItemPartBounds(GetControlRef(), itemID
, property
, kDataBrowserPropertyEnclosingPart
,
2339 enclosingCGRect
= CGRectMake(enclosingRect
.left
,
2341 enclosingRect
.right
- enclosingRect
.left
,
2342 enclosingRect
.bottom
- enclosingRect
.top
);
2344 active
= IsControlActive(GetControlRef());
2346 if (itemState
== kDataBrowserItemIsSelected
)
2348 RGBColor foregroundColor
;
2350 GetThemeDrawingState(&savedState
);
2352 GetThemeBrushAsColor(kThemeBrushAlternatePrimaryHighlightColor
, 32, true, &foregroundColor
);
2353 GetThemeTextColor(kThemeTextColorWhite
, gdDepth
, colorDevice
, &labelColor
);
2355 CGContextSaveGState(context
);
2357 CGContextSetRGBFillColor(context
, (float)foregroundColor
.red
/ (float)USHRT_MAX
,
2358 (float)foregroundColor
.green
/ (float)USHRT_MAX
,
2359 (float)foregroundColor
.blue
/ (float)USHRT_MAX
, 1.0);
2360 CGContextFillRect(context
, enclosingCGRect
);
2362 CGContextRestoreGState(context
);
2368 labelColor
= MAC_WXCOLORREF( color
.GetPixel() );
2369 else if (list
->GetTextColour().Ok())
2370 labelColor
= MAC_WXCOLORREF( list
->GetTextColour().GetPixel() );
2374 labelColor
.green
= 0;
2375 labelColor
.blue
= 0;
2380 RGBColor foregroundColor
= MAC_WXCOLORREF( bgColor
.GetPixel() );
2381 CGContextSaveGState(context
);
2383 CGContextSetRGBFillColor(context
, (float)foregroundColor
.red
/ (float)USHRT_MAX
,
2384 (float)foregroundColor
.green
/ (float)USHRT_MAX
,
2385 (float)foregroundColor
.blue
/ (float)USHRT_MAX
, 1.0);
2386 CGContextFillRect(context
, enclosingCGRect
);
2388 CGContextRestoreGState(context
);
2392 calculateCGDrawingBounds(enclosingCGRect
, &iconCGRect
, &textCGRect
, (imgIndex
!= -1) );
2396 wxImageList
* imageList
= list
->GetImageList(wxIMAGE_LIST_SMALL
);
2397 if (imageList
&& imageList
->GetImageCount() > 0){
2398 wxBitmap bmp
= imageList
->GetBitmap(imgIndex
);
2399 IconRef icon
= bmp
.GetBitmapData()->GetIconRef();
2403 iconLabel
.green
= 0;
2406 CGContextSaveGState(context
);
2407 CGContextTranslateCTM(context
, 0,iconCGRect
.origin
.y
+ CGRectGetMaxY(iconCGRect
));
2408 CGContextScaleCTM(context
,1.0f
,-1.0f
);
2409 PlotIconRefInContext(context
, &iconCGRect
, kAlignNone
,
2410 active
? kTransformNone
: kTransformDisabled
, &iconLabel
,
2411 kPlotIconRefNormalFlags
, icon
);
2413 CGContextRestoreGState(context
);
2417 HIThemeTextHorizontalFlush hFlush
= kHIThemeTextHorizontalFlushLeft
;
2418 UInt16 fontID
= kThemeViewsFont
;
2422 if (font
.GetFamily() != wxFONTFAMILY_DEFAULT
)
2423 fontID
= font
.MacGetThemeFontID();
2425 // FIXME: replace these with CG or ATSUI calls so we can remove this #ifndef.
2427 ::TextSize( (short)(font
.MacGetFontSize()) ) ;
2428 ::TextFace( font
.MacGetFontStyle() ) ;
2433 list
->GetColumn(listColumn
, item
);
2434 if (item
.GetMask() & wxLIST_MASK_FORMAT
)
2436 if (item
.GetAlign() == wxLIST_FORMAT_LEFT
)
2437 hFlush
= kHIThemeTextHorizontalFlushLeft
;
2438 else if (item
.GetAlign() == wxLIST_FORMAT_CENTER
)
2439 hFlush
= kHIThemeTextHorizontalFlushCenter
;
2440 else if (item
.GetAlign() == wxLIST_FORMAT_RIGHT
)
2442 hFlush
= kHIThemeTextHorizontalFlushRight
;
2443 textCGRect
.origin
.x
-= kItemPadding
; // give a little extra paddding
2447 HIThemeTextInfo info
;
2448 info
.version
= kHIThemeTextInfoVersionZero
;
2449 info
.state
= active
? kThemeStateActive
: kThemeStateInactive
;
2450 info
.fontID
= fontID
;
2451 info
.horizontalFlushness
= hFlush
;
2452 info
.verticalFlushness
= kHIThemeTextVerticalFlushCenter
;
2453 info
.options
= kHIThemeTextBoxOptionNone
;
2454 info
.truncationPosition
= kHIThemeTextTruncationEnd
;
2455 info
.truncationMaxLines
= 1;
2457 CGContextSaveGState(context
);
2458 CGContextSetRGBFillColor (context
, (float)labelColor
.red
/ (float)USHRT_MAX
,
2459 (float)labelColor
.green
/ (float)USHRT_MAX
,
2460 (float)labelColor
.blue
/ (float)USHRT_MAX
, 1.0);
2462 HIThemeDrawTextBox(cfString
, &textCGRect
, &info
, context
, kHIThemeOrientationNormal
);
2464 CGContextRestoreGState(context
);
2466 if (savedState
!= NULL
)
2467 SetThemeDrawingState(savedState
, true);
2470 OSStatus
wxMacDataBrowserListCtrlControl::GetSetItemData(DataBrowserItemID itemID
,
2471 DataBrowserPropertyID property
,
2472 DataBrowserItemDataRef itemData
,
2473 Boolean changeValue
)
2477 short listColumn
= property
- kMinColumnId
;
2479 OSStatus err
= errDataBrowserPropertyNotSupported
;
2480 wxListCtrl
* list
= wxDynamicCast( GetPeer() , wxListCtrl
);
2481 wxMacListCtrlItem
* lcItem
;
2483 if (listColumn
>= 0)
2487 lcItem
= (wxMacListCtrlItem
*) itemID
;
2488 if (lcItem
->HasColumnInfo(listColumn
)){
2489 wxListItem
* item
= lcItem
->GetColumnInfo(listColumn
);
2490 if (item
->GetMask() & wxLIST_MASK_TEXT
)
2491 text
= item
->GetText();
2492 if (item
->GetMask() & wxLIST_MASK_IMAGE
)
2493 imgIndex
= item
->GetImage();
2498 text
= list
->OnGetItemText( (long)itemID
-1, listColumn
);
2499 imgIndex
= list
->OnGetItemColumnImage( (long)itemID
-1, listColumn
);
2507 case kDataBrowserItemIsEditableProperty
:
2508 if ( list
&& list
->HasFlag( wxLC_EDIT_LABELS
) )
2510 verify_noerr(SetDataBrowserItemDataBooleanValue( itemData
, true ));
2515 if ( property
>= kMinColumnId
)
2517 wxMacCFStringHolder cfStr
;
2520 cfStr
.Assign( text
, wxLocale::GetSystemEncoding() );
2521 err
= ::SetDataBrowserItemDataText( itemData
, cfStr
);
2527 if ( imgIndex
!= -1 )
2529 wxImageList
* imageList
= list
->GetImageList(wxIMAGE_LIST_SMALL
);
2530 if (imageList
&& imageList
->GetImageCount() > 0){
2531 wxBitmap bmp
= imageList
->GetBitmap(imgIndex
);
2532 IconRef icon
= bmp
.GetBitmapData()->GetIconRef();
2533 ::SetDataBrowserItemDataIcon(itemData
, icon
);
2547 if ( property
>= kMinColumnId
)
2549 short listColumn
= property
- kMinColumnId
;
2551 // TODO probably send the 'end edit' from here, as we
2552 // can then deal with the veto
2554 verify_noerr( GetDataBrowserItemDataText( itemData
, &sr
) ) ;
2555 wxMacCFStringHolder
cfStr(sr
) ;;
2557 list
->SetItem( (long)itemData
-1 , listColumn
, cfStr
.AsString() ) ;
2561 lcItem
->SetColumnTextValue( listColumn
, cfStr
.AsString() );
2571 void wxMacDataBrowserListCtrlControl::ItemNotification(DataBrowserItemID itemID
,
2572 DataBrowserItemNotification message
,
2573 DataBrowserItemDataRef itemData
)
2575 // we want to depend on as little as possible to make sure tear-down of controls is safe
2576 if ( message
== kDataBrowserItemRemoved
)
2578 // make sure MacDelete does the proper teardown.
2581 else if ( message
== kDataBrowserItemAdded
)
2583 // we don't issue events on adding, the item is not really stored in the list yet, so we
2584 // avoid asserts by getting out now
2588 wxListCtrl
*list
= wxDynamicCast( GetPeer() , wxListCtrl
);
2591 bool trigger
= false;
2593 wxListEvent
event( wxEVT_COMMAND_LIST_ITEM_SELECTED
, list
->GetId() );
2594 bool isSingle
= (list
->GetWindowStyle() & wxLC_SINGLE_SEL
) != 0;
2596 event
.SetEventObject( list
);
2597 if ( !list
->IsVirtual() )
2599 DataBrowserTableViewRowIndex result
= 0;
2600 verify_noerr( GetItemRow( itemID
, &result
) ) ;
2601 event
.m_itemIndex
= result
;
2603 if (event
.m_itemIndex
>= 0)
2604 MacGetColumnInfo(event
.m_itemIndex
,0,event
.m_item
);
2608 event
.m_itemIndex
= (long)itemID
;
2613 case kDataBrowserItemDeselected
:
2614 event
.SetEventType(wxEVT_COMMAND_LIST_ITEM_DESELECTED
);
2616 trigger
= !IsSelectionSuppressed();
2619 case kDataBrowserItemSelected
:
2620 trigger
= !IsSelectionSuppressed();
2624 case kDataBrowserItemDoubleClicked
:
2625 event
.SetEventType( wxEVT_COMMAND_LIST_ITEM_ACTIVATED
);
2629 case kDataBrowserEditStarted
:
2630 // TODO : how to veto ?
2631 event
.SetEventType( wxEVT_COMMAND_LIST_BEGIN_LABEL_EDIT
) ;
2635 case kDataBrowserEditStopped
:
2636 // TODO probably trigger only upon the value store callback, because
2637 // here IIRC we cannot veto
2638 event
.SetEventType( wxEVT_COMMAND_LIST_END_LABEL_EDIT
) ;
2648 // direct notification is not always having the listbox GetSelection() having in synch with event
2649 wxPostEvent( list
->GetEventHandler(), event
);
2654 Boolean
wxMacDataBrowserListCtrlControl::CompareItems(DataBrowserItemID itemOneID
,
2655 DataBrowserItemID itemTwoID
,
2656 DataBrowserPropertyID sortProperty
)
2659 bool retval
= false;
2661 wxString otherItemText
;
2662 int colId
= sortProperty
- kMinColumnId
;
2664 long otherItemNum
= 0;
2666 wxListCtrl
* list
= wxDynamicCast( GetPeer() , wxListCtrl
);
2673 wxMacListCtrlItem
* item
= (wxMacListCtrlItem
*)itemOneID
;
2674 wxMacListCtrlItem
* otherItem
= (wxMacListCtrlItem
*)itemTwoID
;
2675 wxListCtrlCompare func
= list
->GetCompareFunc();
2676 if (func
!= NULL
&& item
->HasColumnInfo(colId
) && otherItem
->HasColumnInfo(colId
))
2677 return func(item
->GetColumnInfo(colId
)->GetData(), otherItem
->GetColumnInfo(colId
)->GetData(), list
->GetCompareFuncData()) >= 0;
2679 itemNum
= item
->GetOrder();
2680 otherItemNum
= otherItem
->GetOrder();
2681 if (item
->HasColumnInfo(colId
))
2682 itemText
= item
->GetColumnInfo(colId
)->GetText();
2683 if (otherItem
->HasColumnInfo(colId
))
2684 otherItemText
= otherItem
->GetColumnInfo(colId
)->GetText();
2688 itemNum
= (long)itemOneID
;
2689 otherItemNum
= (long)itemTwoID
;
2690 itemText
= list
->OnGetItemText( itemNum
-1, colId
);
2691 otherItemText
= list
->OnGetItemText( otherItemNum
-1, colId
);
2695 DataBrowserSortOrder sort
;
2696 verify_noerr(GetSortOrder(&sort
));
2698 if ( sort
== kDataBrowserOrderIncreasing
)
2700 retval
= itemText
.CmpNoCase( otherItemText
) > 0;
2702 else if ( sort
== kDataBrowserOrderDecreasing
)
2704 retval
= itemText
.CmpNoCase( otherItemText
) < 0;
2708 // fallback for undefined cases
2709 retval
= itemOneID
< itemTwoID
;
2715 wxMacDataBrowserListCtrlControl::~wxMacDataBrowserListCtrlControl()
2719 void wxMacDataBrowserListCtrlControl::MacSetColumnInfo( unsigned int row
, unsigned int column
, wxListItem
* item
)
2721 wxMacDataItem
* dataItem
= GetItemFromLine(row
);
2724 wxMacListCtrlItem
* listItem
= dynamic_cast<wxMacListCtrlItem
*>(dataItem
);
2725 listItem
->SetColumnInfo( column
, item
);
2726 UpdateState(dataItem
, item
);
2730 // apply changes that need to happen immediately, rather than when the
2731 // databrowser control fires a callback.
2732 void wxMacDataBrowserListCtrlControl::UpdateState(wxMacDataItem
* dataItem
, wxListItem
* listItem
)
2734 bool isSelected
= IsItemSelected( dataItem
);
2735 bool isSelectedState
= (listItem
->GetState() == wxLIST_STATE_SELECTED
);
2737 // toggle the selection state if wxListInfo state and actual state don't match.
2738 if ( isSelected
!= isSelectedState
)
2740 DataBrowserSetOption options
= kDataBrowserItemsAdd
;
2741 if (!isSelectedState
)
2742 options
= kDataBrowserItemsRemove
;
2743 SetSelectedItem(dataItem
, options
);
2745 // TODO: Set column width if item width > than current column width
2748 void wxMacDataBrowserListCtrlControl::MacGetColumnInfo( unsigned int row
, unsigned int column
, wxListItem
& item
)
2750 wxMacDataItem
* dataItem
= GetItemFromLine(row
);
2751 // CS should this guard against dataItem = 0 ? , as item is not a pointer if (item) is not appropriate
2754 wxMacListCtrlItem
* listItem
= dynamic_cast<wxMacListCtrlItem
*>(dataItem
);
2755 wxListItem
* oldItem
= listItem
->GetColumnInfo( column
);
2757 long mask
= item
.GetMask();
2759 // by default, get everything for backwards compatibility
2762 if ( mask
& wxLIST_MASK_TEXT
)
2763 item
.SetText(oldItem
->GetText());
2764 if ( mask
& wxLIST_MASK_IMAGE
)
2765 item
.SetImage(oldItem
->GetImage());
2766 if ( mask
& wxLIST_MASK_DATA
)
2767 item
.SetData(oldItem
->GetData());
2768 if ( mask
& wxLIST_MASK_STATE
)
2769 item
.SetState(oldItem
->GetState());
2770 if ( mask
& wxLIST_MASK_WIDTH
)
2771 item
.SetWidth(oldItem
->GetWidth());
2772 if ( mask
& wxLIST_MASK_FORMAT
)
2773 item
.SetAlign(oldItem
->GetAlign());
2775 item
.SetTextColour(oldItem
->GetTextColour());
2776 item
.SetBackgroundColour(oldItem
->GetBackgroundColour());
2777 item
.SetFont(oldItem
->GetFont());
2781 void wxMacDataBrowserListCtrlControl::MacInsertItem( unsigned int n
, wxListItem
* item
)
2783 wxMacDataItemBrowserControl::MacInsert(n
, item
->GetText());
2784 MacSetColumnInfo(n
, 0, item
);
2787 wxMacDataItem
* wxMacDataBrowserListCtrlControl::CreateItem()
2789 return new wxMacListCtrlItem();
2792 wxMacListCtrlItem::wxMacListCtrlItem()
2794 m_rowItems
= wxListItemList();
2797 int wxMacListCtrlItem::GetColumnImageValue( unsigned int column
)
2799 return GetColumnInfo(column
)->GetImage();
2802 void wxMacListCtrlItem::SetColumnImageValue( unsigned int column
, int imageIndex
)
2804 GetColumnInfo(column
)->SetImage(imageIndex
);
2807 const wxString
& wxMacListCtrlItem::GetColumnTextValue( unsigned int column
)
2812 return GetColumnInfo(column
)->GetText();
2815 void wxMacListCtrlItem::SetColumnTextValue( unsigned int column
, const wxString
& text
)
2817 GetColumnInfo(column
)->SetText(text
);
2819 // for compatibility with superclass APIs
2824 wxListItem
* wxMacListCtrlItem::GetColumnInfo( unsigned int column
)
2826 wxListItemList::compatibility_iterator node
= m_rowItems
.Item( column
);
2827 wxASSERT_MSG( node
, _T("invalid column index in wxMacListCtrlItem") );
2829 return node
->GetData();
2832 bool wxMacListCtrlItem::HasColumnInfo( unsigned int column
)
2834 return m_rowItems
.GetCount() > column
;
2837 void wxMacListCtrlItem::SetColumnInfo( unsigned int column
, wxListItem
* item
)
2840 if ( column
>= m_rowItems
.GetCount() )
2842 wxListItem
* listItem
= new wxListItem(*item
);
2843 m_rowItems
.Append( listItem
);
2847 wxListItem
* listItem
= GetColumnInfo( column
);
2848 long mask
= item
->GetMask();
2849 if (mask
& wxLIST_MASK_TEXT
)
2850 listItem
->SetText(item
->GetText());
2851 if (mask
& wxLIST_MASK_DATA
)
2852 listItem
->SetData(item
->GetData());
2853 if (mask
& wxLIST_MASK_IMAGE
)
2854 listItem
->SetImage(item
->GetImage());
2855 if (mask
& wxLIST_MASK_STATE
)
2856 listItem
->SetState(item
->GetState());
2857 if (mask
& wxLIST_MASK_FORMAT
)
2858 listItem
->SetAlign(item
->GetAlign());
2859 if (mask
& wxLIST_MASK_WIDTH
)
2860 listItem
->SetWidth(item
->GetWidth());
2862 listItem
->SetTextColour(item
->GetTextColour());
2863 listItem
->SetBackgroundColour(item
->GetBackgroundColour());
2864 listItem
->SetFont(item
->GetFont());
2868 #endif // wxUSE_LISTCTRL