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 long itemEdit
= (long)item
;
1577 wxListEvent
le( wxEVT_COMMAND_LIST_BEGIN_LABEL_EDIT
, GetParent()->GetId() );
1578 le
.SetEventObject( this );
1579 le
.m_itemIndex
= item
;
1581 GetItem( le
.m_item
);
1583 if ( GetParent()->GetEventHandler()->ProcessEvent( le
) && !le
.IsAllowed() )
1585 // vetoed by user code
1589 wxTextCtrl
* const text
= (wxTextCtrl
*)textControlClass
->CreateObject();
1590 m_textctrlWrapper
= new wxListCtrlTextCtrlWrapper(this, text
, item
);
1591 return m_textctrlWrapper
->GetText();
1596 // End label editing, optionally cancelling the edit
1597 bool wxListCtrl::EndEditLabel(bool cancel
)
1599 // TODO: generic impl. doesn't have this method - is it needed for us?
1601 return true; // m_genericImpl->EndEditLabel(cancel);
1604 verify_noerr( SetDataBrowserEditItem(m_dbImpl
->GetControlRef(), kDataBrowserNoItem
, kMinColumnId
) );
1608 // Ensures this item is visible
1609 bool wxListCtrl::EnsureVisible(long item
)
1612 return m_genericImpl
->EnsureVisible(item
);
1616 wxMacDataItem
* dataItem
= m_dbImpl
->GetItemFromLine(item
);
1617 m_dbImpl
->RevealItem(dataItem
, kDataBrowserRevealWithoutSelecting
);
1623 // Find an item whose label matches this string, starting from the item after 'start'
1624 // or the beginning if 'start' is -1.
1625 long wxListCtrl::FindItem(long start
, const wxString
& str
, bool partial
)
1628 return m_genericImpl
->FindItem(start
, str
, partial
);
1633 // Find an item whose data matches this data, starting from the item after 'start'
1634 // or the beginning if 'start' is -1.
1635 long wxListCtrl::FindItem(long start
, long data
)
1638 return m_genericImpl
->FindItem(start
, data
);
1640 long idx
= start
+ 1;
1641 long count
= GetItemCount();
1645 if (GetItemData(idx
) == data
)
1653 // Find an item nearest this position in the specified direction, starting from
1654 // the item after 'start' or the beginning if 'start' is -1.
1655 long wxListCtrl::FindItem(long start
, const wxPoint
& pt
, int direction
)
1658 return m_genericImpl
->FindItem(start
, pt
, direction
);
1662 // Determines which item (if any) is at the specified point,
1663 // giving details in 'flags' (see wxLIST_HITTEST_... flags above)
1665 wxListCtrl::HitTest(const wxPoint
& point
, int& flags
, long *ptrSubItem
) const
1668 return m_genericImpl
->HitTest(point
, flags
, ptrSubItem
);
1670 flags
= wxLIST_HITTEST_NOWHERE
;
1673 int colHeaderHeight
= 22; // TODO: Find a way to get this value from the db control?
1674 UInt16 rowHeight
= 0;
1675 m_dbImpl
->GetDefaultRowHeight(&rowHeight
);
1678 // get the actual row by taking scroll position into account
1679 UInt32 offsetX
, offsetY
;
1680 m_dbImpl
->GetScrollPosition( &offsetY
, &offsetX
);
1683 if ( !(GetWindowStyleFlag() & wxLC_NO_HEADER
) )
1684 y
-= colHeaderHeight
;
1686 int row
= y
/ rowHeight
;
1687 DataBrowserItemID id
;
1688 m_dbImpl
->GetItemID( (DataBrowserTableViewRowIndex
) row
, &id
);
1690 // TODO: Use GetDataBrowserItemPartBounds to return if we are in icon or label
1691 if ( !(GetWindowStyleFlag() & wxLC_VIRTUAL
) )
1693 wxMacListCtrlItem
* lcItem
;
1694 lcItem
= (wxMacListCtrlItem
*) id
;
1697 flags
= wxLIST_HITTEST_ONITEM
;
1703 if (row
< GetItemCount() )
1705 flags
= wxLIST_HITTEST_ONITEM
;
1715 // Inserts an item, returning the index of the new item if successful,
1717 long wxListCtrl::InsertItem(wxListItem
& info
)
1719 wxASSERT_MSG( !IsVirtual(), _T("can't be used with virtual controls") );
1722 return m_genericImpl
->InsertItem(info
);
1726 int count
= GetItemCount();
1728 if (info
.m_itemId
> count
)
1729 info
.m_itemId
= count
;
1731 m_dbImpl
->MacInsertItem(info
.m_itemId
, &info
);
1732 wxListEvent
event( wxEVT_COMMAND_LIST_INSERT_ITEM
, GetId() );
1733 event
.SetEventObject( this );
1734 event
.m_itemIndex
= info
.m_itemId
;
1735 GetEventHandler()->ProcessEvent( event
);
1738 return info
.m_itemId
;
1741 long wxListCtrl::InsertItem(long index
, const wxString
& label
)
1744 return m_genericImpl
->InsertItem(index
, label
);
1747 info
.m_text
= label
;
1748 info
.m_mask
= wxLIST_MASK_TEXT
;
1749 info
.m_itemId
= index
;
1750 return InsertItem(info
);
1753 // Inserts an image item
1754 long wxListCtrl::InsertItem(long index
, int imageIndex
)
1757 return m_genericImpl
->InsertItem(index
, imageIndex
);
1760 info
.m_image
= imageIndex
;
1761 info
.m_mask
= wxLIST_MASK_IMAGE
;
1762 info
.m_itemId
= index
;
1763 return InsertItem(info
);
1766 // Inserts an image/string item
1767 long wxListCtrl::InsertItem(long index
, const wxString
& label
, int imageIndex
)
1770 return m_genericImpl
->InsertItem(index
, label
, imageIndex
);
1773 info
.m_image
= imageIndex
;
1774 info
.m_text
= label
;
1775 info
.m_mask
= wxLIST_MASK_IMAGE
| wxLIST_MASK_TEXT
;
1776 info
.m_itemId
= index
;
1777 return InsertItem(info
);
1780 // For list view mode (only), inserts a column.
1781 long wxListCtrl::InsertColumn(long col
, wxListItem
& item
)
1784 return m_genericImpl
->InsertColumn(col
, item
);
1788 int width
= item
.GetWidth();
1789 if ( !(item
.GetMask() & wxLIST_MASK_WIDTH
) )
1792 DataBrowserPropertyType type
= kDataBrowserCustomType
; //kDataBrowserTextType;
1793 wxImageList
* imageList
= GetImageList(wxIMAGE_LIST_SMALL
);
1794 if (imageList
&& imageList
->GetImageCount() > 0)
1796 wxBitmap bmp
= imageList
->GetBitmap(0);
1798 // type = kDataBrowserIconAndTextType;
1801 SInt16 just
= teFlushDefault
;
1802 if (item
.GetMask() & wxLIST_MASK_FORMAT
)
1804 if (item
.GetAlign() == wxLIST_FORMAT_LEFT
)
1806 else if (item
.GetAlign() == wxLIST_FORMAT_CENTER
)
1808 else if (item
.GetAlign() == wxLIST_FORMAT_RIGHT
)
1809 just
= teFlushRight
;
1811 m_dbImpl
->InsertColumn(col
, type
, item
.GetText(), just
, width
);
1812 SetColumn(col
, item
);
1814 // set/remove options based on the wxListCtrl type.
1815 DataBrowserTableViewColumnID id
;
1816 m_dbImpl
->GetColumnIDFromIndex(col
, &id
);
1817 DataBrowserPropertyFlags flags
;
1818 verify_noerr(m_dbImpl
->GetPropertyFlags(id
, &flags
));
1819 if (GetWindowStyleFlag() & wxLC_EDIT_LABELS
)
1820 flags
|= kDataBrowserPropertyIsEditable
;
1822 if (GetWindowStyleFlag() & wxLC_VIRTUAL
){
1823 flags
&= ~kDataBrowserListViewSortableColumn
;
1825 verify_noerr(m_dbImpl
->SetPropertyFlags(id
, flags
));
1831 long wxListCtrl::InsertColumn(long col
,
1832 const wxString
& heading
,
1837 return m_genericImpl
->InsertColumn(col
, heading
, format
, width
);
1840 item
.m_mask
= wxLIST_MASK_TEXT
| wxLIST_MASK_FORMAT
;
1841 item
.m_text
= heading
;
1844 item
.m_mask
|= wxLIST_MASK_WIDTH
;
1845 item
.m_width
= width
;
1847 item
.m_format
= format
;
1849 return InsertColumn(col
, item
);
1852 // scroll the control by the given number of pixels (exception: in list view,
1853 // dx is interpreted as number of columns)
1854 bool wxListCtrl::ScrollList(int dx
, int dy
)
1857 return m_genericImpl
->ScrollList(dx
, dy
);
1861 m_dbImpl
->SetScrollPosition(dx
, dy
);
1867 bool wxListCtrl::SortItems(wxListCtrlCompare fn
, long data
)
1870 return m_genericImpl
->SortItems(fn
, data
);
1875 m_compareFuncData
= data
;
1881 void wxListCtrl::OnRenameTimer()
1883 wxCHECK_RET( HasCurrent(), wxT("unexpected rename timer") );
1885 EditLabel( m_current
);
1888 bool wxListCtrl::OnRenameAccept(long itemEdit
, const wxString
& value
)
1890 wxListEvent
le( wxEVT_COMMAND_LIST_END_LABEL_EDIT
, GetId() );
1891 le
.SetEventObject( this );
1892 le
.m_itemIndex
= itemEdit
;
1894 GetItem( le
.m_item
);
1895 le
.m_item
.m_text
= value
;
1896 return !GetEventHandler()->ProcessEvent( le
) ||
1900 void wxListCtrl::OnRenameCancelled(long itemEdit
)
1902 // let owner know that the edit was cancelled
1903 wxListEvent
le( wxEVT_COMMAND_LIST_END_LABEL_EDIT
, GetParent()->GetId() );
1905 le
.SetEditCanceled(true);
1907 le
.SetEventObject( this );
1908 le
.m_itemIndex
= itemEdit
;
1910 GetItem( le
.m_item
);
1911 GetEventHandler()->ProcessEvent( le
);
1914 // ----------------------------------------------------------------------------
1915 // virtual list controls
1916 // ----------------------------------------------------------------------------
1918 wxString
wxListCtrl::OnGetItemText(long WXUNUSED(item
), long WXUNUSED(col
)) const
1920 // this is a pure virtual function, in fact - which is not really pure
1921 // because the controls which are not virtual don't need to implement it
1922 wxFAIL_MSG( _T("wxListCtrl::OnGetItemText not supposed to be called") );
1924 return wxEmptyString
;
1927 int wxListCtrl::OnGetItemImage(long WXUNUSED(item
)) const
1929 wxCHECK_MSG(!GetImageList(wxIMAGE_LIST_SMALL
),
1931 wxT("List control has an image list, OnGetItemImage or OnGetItemColumnImage should be overridden."));
1935 int wxListCtrl::OnGetItemColumnImage(long item
, long column
) const
1938 return OnGetItemImage(item
);
1943 wxListItemAttr
*wxListCtrl::OnGetItemAttr(long WXUNUSED_UNLESS_DEBUG(item
)) const
1945 wxASSERT_MSG( item
>= 0 && item
< GetItemCount(),
1946 _T("invalid item index in OnGetItemAttr()") );
1948 // no attributes by default
1952 void wxListCtrl::SetItemCount(long count
)
1954 wxASSERT_MSG( IsVirtual(), _T("this is for virtual controls only") );
1958 m_genericImpl
->SetItemCount(count
);
1964 // we need to temporarily disable the new item creation notification
1965 // procedure to speed things up
1966 // FIXME: Even this doesn't seem to help much...
1967 DataBrowserCallbacks callbacks
;
1968 DataBrowserItemNotificationUPP itemUPP
;
1969 GetDataBrowserCallbacks(m_dbImpl
->GetControlRef(), &callbacks
);
1970 itemUPP
= callbacks
.u
.v1
.itemNotificationCallback
;
1971 callbacks
.u
.v1
.itemNotificationCallback
= 0;
1972 m_dbImpl
->SetCallbacks(&callbacks
);
1973 ::AddDataBrowserItems(m_dbImpl
->GetControlRef(), kDataBrowserNoItem
,
1974 count
, NULL
, kDataBrowserItemNoProperty
);
1975 callbacks
.u
.v1
.itemNotificationCallback
= itemUPP
;
1976 m_dbImpl
->SetCallbacks(&callbacks
);
1981 void wxListCtrl::RefreshItem(long item
)
1985 m_genericImpl
->RefreshItem(item
);
1990 GetItemRect(item
, rect
);
1994 void wxListCtrl::RefreshItems(long itemFrom
, long itemTo
)
1998 m_genericImpl
->RefreshItems(itemFrom
, itemTo
);
2002 wxRect rect1
, rect2
;
2003 GetItemRect(itemFrom
, rect1
);
2004 GetItemRect(itemTo
, rect2
);
2006 wxRect rect
= rect1
;
2007 rect
.height
= rect2
.GetBottom() - rect1
.GetTop();
2013 // wxMac internal data structures
2015 wxMacListCtrlItem::~wxMacListCtrlItem()
2019 void wxMacListCtrlItem::Notification(wxMacDataItemBrowserControl
*owner
,
2020 DataBrowserItemNotification message
,
2021 DataBrowserItemDataRef itemData
) const
2024 wxMacDataBrowserListCtrlControl
*lb
= dynamic_cast<wxMacDataBrowserListCtrlControl
*>(owner
);
2026 // we want to depend on as little as possible to make sure tear-down of controls is safe
2027 if ( message
== kDataBrowserItemRemoved
)
2029 if ( lb
!= NULL
&& lb
->GetClientDataType() == wxClientData_Object
)
2031 delete (wxClientData
*) (m_data
);
2037 else if ( message
== kDataBrowserItemAdded
)
2039 // we don't issue events on adding, the item is not really stored in the list yet, so we
2040 // avoid asserts by gettting out now
2044 wxListCtrl
*list
= wxDynamicCast( owner
->GetPeer() , wxListCtrl
);
2047 bool trigger
= false;
2049 wxListEvent
event( wxEVT_COMMAND_LIST_ITEM_SELECTED
, list
->GetId() );
2050 bool isSingle
= (list
->GetWindowStyle() & wxLC_SINGLE_SEL
) != 0;
2052 event
.SetEventObject( list
);
2053 event
.m_itemIndex
= owner
->GetLineFromItem( this ) ;
2054 if ( !list
->IsVirtual() )
2056 lb
->MacGetColumnInfo(event
.m_itemIndex
,0,event
.m_item
);
2061 case kDataBrowserItemDeselected
:
2062 event
.SetEventType(wxEVT_COMMAND_LIST_ITEM_DESELECTED
);
2064 trigger
= !lb
->IsSelectionSuppressed();
2067 case kDataBrowserItemSelected
:
2068 trigger
= !lb
->IsSelectionSuppressed();
2071 case kDataBrowserItemDoubleClicked
:
2072 event
.SetEventType( wxEVT_COMMAND_LIST_ITEM_ACTIVATED
);
2076 case kDataBrowserEditStarted
:
2077 // TODO : how to veto ?
2078 event
.SetEventType( wxEVT_COMMAND_LIST_BEGIN_LABEL_EDIT
) ;
2082 case kDataBrowserEditStopped
:
2083 // TODO probably trigger only upon the value store callback, because
2084 // here IIRC we cannot veto
2085 event
.SetEventType( wxEVT_COMMAND_LIST_END_LABEL_EDIT
) ;
2095 // direct notification is not always having the listbox GetSelection() having in synch with event
2096 wxPostEvent( list
->GetEventHandler(), event
);
2102 wxMacDataBrowserListCtrlControl::wxMacDataBrowserListCtrlControl( wxWindow
*peer
, const wxPoint
& pos
, const wxSize
& size
, long style
)
2103 : wxMacDataItemBrowserControl( peer
, pos
, size
, style
)
2105 OSStatus err
= noErr
;
2106 m_clientDataItemsType
= wxClientData_None
;
2107 m_isVirtual
= false;
2109 if ( style
& wxLC_VIRTUAL
)
2112 DataBrowserSelectionFlags options
= kDataBrowserDragSelect
;
2113 if ( style
& wxLC_SINGLE_SEL
)
2115 options
|= kDataBrowserSelectOnlyOne
;
2119 options
|= kDataBrowserCmdTogglesSelection
;
2122 err
= SetSelectionFlags( options
);
2123 verify_noerr( err
);
2125 DataBrowserCustomCallbacks callbacks
;
2126 InitializeDataBrowserCustomCallbacks( &callbacks
, kDataBrowserLatestCustomCallbacks
);
2128 if ( gDataBrowserDrawItemUPP
== NULL
)
2129 gDataBrowserDrawItemUPP
= NewDataBrowserDrawItemUPP(DataBrowserDrawItemProc
);
2131 // if ( gDataBrowserEditItemUPP == NULL )
2132 // gDataBrowserEditItemUPP = NewDataBrowserEditItemUPP(DataBrowserEditTextProc);
2134 if ( gDataBrowserHitTestUPP
== NULL
)
2135 gDataBrowserHitTestUPP
= NewDataBrowserHitTestUPP(DataBrowserHitTestProc
);
2137 callbacks
.u
.v1
.drawItemCallback
= gDataBrowserDrawItemUPP
;
2138 // callbacks.u.v1.editTextCallback = gDataBrowserEditItemUPP;
2139 callbacks
.u
.v1
.hitTestCallback
= gDataBrowserHitTestUPP
;
2141 SetDataBrowserCustomCallbacks( GetControlRef(), &callbacks
);
2143 if ( style
& wxLC_LIST
)
2145 InsertColumn(0, kDataBrowserIconAndTextType
, wxEmptyString
, -1, -1);
2146 verify_noerr( AutoSizeColumns() );
2149 if ( style
& wxLC_LIST
|| style
& wxLC_NO_HEADER
)
2150 verify_noerr( SetHeaderButtonHeight( 0 ) );
2153 SetSortProperty( kMinColumnId
- 1 );
2155 SetSortProperty( kMinColumnId
);
2156 if ( style
& wxLC_SORT_ASCENDING
)
2158 m_sortOrder
= SortOrder_Text_Ascending
;
2159 SetSortOrder( kDataBrowserOrderIncreasing
);
2161 else if ( style
& wxLC_SORT_DESCENDING
)
2163 m_sortOrder
= SortOrder_Text_Descending
;
2164 SetSortOrder( kDataBrowserOrderDecreasing
);
2168 m_sortOrder
= SortOrder_None
;
2171 if ( style
& wxLC_VRULES
)
2173 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4
2174 verify_noerr( DataBrowserChangeAttributes(m_controlRef
, kDataBrowserAttributeListViewDrawColumnDividers
, kDataBrowserAttributeNone
) );
2178 verify_noerr( SetHiliteStyle(kDataBrowserTableViewFillHilite
) );
2179 err
= SetHasScrollBars( (style
& wxHSCROLL
) != 0 , true );
2182 pascal Boolean
wxMacDataBrowserListCtrlControl::DataBrowserEditTextProc(
2184 DataBrowserItemID itemID
,
2185 DataBrowserPropertyID property
,
2186 CFStringRef theString
,
2187 Rect
*maxEditTextRect
,
2188 Boolean
*shrinkToFit
)
2190 Boolean result
= false;
2191 wxMacDataBrowserListCtrlControl
* ctl
= dynamic_cast<wxMacDataBrowserListCtrlControl
*>( wxMacControl::GetReferenceFromNativeControl( browser
) );
2194 result
= ctl
->ConfirmEditText(itemID
, property
, theString
, maxEditTextRect
, shrinkToFit
);
2195 theString
= CFSTR("Hello!");
2200 bool wxMacDataBrowserListCtrlControl::ConfirmEditText(
2201 DataBrowserItemID itemID
,
2202 DataBrowserPropertyID property
,
2203 CFStringRef theString
,
2204 Rect
*maxEditTextRect
,
2205 Boolean
*shrinkToFit
)
2207 //wxListCtrl* list = wxDynamicCast( GetPeer() , wxListCtrl );
2211 pascal void wxMacDataBrowserListCtrlControl::DataBrowserDrawItemProc(
2213 DataBrowserItemID itemID
,
2214 DataBrowserPropertyID property
,
2215 DataBrowserItemState itemState
,
2216 const Rect
*itemRect
,
2218 Boolean colorDevice
)
2220 wxMacDataBrowserListCtrlControl
* ctl
= dynamic_cast<wxMacDataBrowserListCtrlControl
*>( wxMacControl::GetReferenceFromNativeControl( browser
) );
2223 ctl
->DrawItem(itemID
, property
, itemState
, itemRect
, gdDepth
, colorDevice
);
2227 // routines needed for DrawItem
2232 kTextBoxHeight
= 14,
2233 kIconTextSpacingV
= 2,
2235 kContentHeight
= kIconHeight
+ kTextBoxHeight
+ kIconTextSpacingV
2238 static void calculateCGDrawingBounds(CGRect inItemRect
, CGRect
*outIconRect
, CGRect
*outTextRect
, bool hasIcon
= false)
2241 float iconH
, iconW
= 0;
2242 float padding
= kItemPadding
;
2245 iconH
= kIconHeight
;
2247 padding
= padding
*2;
2250 textBottom
= inItemRect
.origin
.y
;
2252 *outIconRect
= CGRectMake(inItemRect
.origin
.x
+ kItemPadding
,
2253 textBottom
+ kIconTextSpacingV
, kIconWidth
,
2256 *outTextRect
= CGRectMake(inItemRect
.origin
.x
+ padding
+ iconW
,
2257 textBottom
+ kIconTextSpacingV
, inItemRect
.size
.width
- padding
- iconW
,
2258 inItemRect
.size
.height
- kIconTextSpacingV
);
2261 void wxMacDataBrowserListCtrlControl::DrawItem(
2262 DataBrowserItemID itemID
,
2263 DataBrowserPropertyID property
,
2264 DataBrowserItemState itemState
,
2265 const Rect
*itemRect
,
2267 Boolean colorDevice
)
2270 wxFont font
= wxNullFont
;
2272 short listColumn
= property
- kMinColumnId
;
2274 wxListCtrl
* list
= wxDynamicCast( GetPeer() , wxListCtrl
);
2275 wxMacListCtrlItem
* lcItem
;
2276 wxColour color
= *wxBLACK
;
2277 wxColour bgColor
= wxNullColour
;
2279 if (listColumn
>= 0)
2283 lcItem
= (wxMacListCtrlItem
*) itemID
;
2284 if (lcItem
->HasColumnInfo(listColumn
)){
2285 wxListItem
* item
= lcItem
->GetColumnInfo(listColumn
);
2287 // we always use the 0 column to get font and text/background colors.
2288 if (lcItem
->HasColumnInfo(0))
2290 wxListItem
* firstItem
= lcItem
->GetColumnInfo(0);
2291 color
= firstItem
->GetTextColour();
2292 bgColor
= firstItem
->GetBackgroundColour();
2293 font
= firstItem
->GetFont();
2296 if (item
->GetMask() & wxLIST_MASK_TEXT
)
2297 text
= item
->GetText();
2298 if (item
->GetMask() & wxLIST_MASK_IMAGE
)
2299 imgIndex
= item
->GetImage();
2305 text
= list
->OnGetItemText( (long)itemID
-1, listColumn
);
2306 imgIndex
= list
->OnGetItemColumnImage( (long)itemID
-1, listColumn
);
2307 wxListItemAttr
* attrs
= list
->OnGetItemAttr( (long)itemID
-1 );
2310 if (attrs
->HasBackgroundColour())
2311 bgColor
= attrs
->GetBackgroundColour();
2312 if (attrs
->HasTextColour())
2313 color
= attrs
->GetTextColour();
2314 if (attrs
->HasFont())
2315 font
= attrs
->GetFont();
2320 wxColour listBgColor
= list
->GetBackgroundColour();
2321 if (bgColor
== wxNullColour
)
2322 bgColor
= listBgColor
;
2324 wxFont listFont
= list
->GetFont();
2325 if (font
== wxNullFont
)
2328 wxMacCFStringHolder cfString
;
2329 cfString
.Assign( text
, wxLocale::GetSystemEncoding() );
2332 CGRect enclosingCGRect
, iconCGRect
, textCGRect
;
2334 ThemeDrawingState savedState
= NULL
;
2335 CGContextRef context
= (CGContextRef
)list
->MacGetDrawingContext();
2336 RGBColor labelColor
;
2338 GetDataBrowserItemPartBounds(GetControlRef(), itemID
, property
, kDataBrowserPropertyEnclosingPart
,
2341 enclosingCGRect
= CGRectMake(enclosingRect
.left
,
2343 enclosingRect
.right
- enclosingRect
.left
,
2344 enclosingRect
.bottom
- enclosingRect
.top
);
2346 active
= IsControlActive(GetControlRef());
2348 if (itemState
== kDataBrowserItemIsSelected
)
2350 RGBColor foregroundColor
;
2352 GetThemeDrawingState(&savedState
);
2354 GetThemeBrushAsColor(kThemeBrushAlternatePrimaryHighlightColor
, 32, true, &foregroundColor
);
2355 GetThemeTextColor(kThemeTextColorWhite
, gdDepth
, colorDevice
, &labelColor
);
2357 CGContextSaveGState(context
);
2359 CGContextSetRGBFillColor(context
, (float)foregroundColor
.red
/ (float)USHRT_MAX
,
2360 (float)foregroundColor
.green
/ (float)USHRT_MAX
,
2361 (float)foregroundColor
.blue
/ (float)USHRT_MAX
, 1.0);
2362 CGContextFillRect(context
, enclosingCGRect
);
2364 CGContextRestoreGState(context
);
2370 labelColor
= MAC_WXCOLORREF( color
.GetPixel() );
2371 else if (list
->GetTextColour().Ok())
2372 labelColor
= MAC_WXCOLORREF( list
->GetTextColour().GetPixel() );
2376 labelColor
.green
= 0;
2377 labelColor
.blue
= 0;
2382 RGBColor foregroundColor
= MAC_WXCOLORREF( bgColor
.GetPixel() );
2383 CGContextSaveGState(context
);
2385 CGContextSetRGBFillColor(context
, (float)foregroundColor
.red
/ (float)USHRT_MAX
,
2386 (float)foregroundColor
.green
/ (float)USHRT_MAX
,
2387 (float)foregroundColor
.blue
/ (float)USHRT_MAX
, 1.0);
2388 CGContextFillRect(context
, enclosingCGRect
);
2390 CGContextRestoreGState(context
);
2394 calculateCGDrawingBounds(enclosingCGRect
, &iconCGRect
, &textCGRect
, (imgIndex
!= -1) );
2398 wxImageList
* imageList
= list
->GetImageList(wxIMAGE_LIST_SMALL
);
2399 if (imageList
&& imageList
->GetImageCount() > 0){
2400 wxBitmap bmp
= imageList
->GetBitmap(imgIndex
);
2401 IconRef icon
= bmp
.GetBitmapData()->GetIconRef();
2405 iconLabel
.green
= 0;
2408 CGContextSaveGState(context
);
2409 CGContextTranslateCTM(context
, 0,iconCGRect
.origin
.y
+ CGRectGetMaxY(iconCGRect
));
2410 CGContextScaleCTM(context
,1.0f
,-1.0f
);
2411 PlotIconRefInContext(context
, &iconCGRect
, kAlignNone
,
2412 active
? kTransformNone
: kTransformDisabled
, &iconLabel
,
2413 kPlotIconRefNormalFlags
, icon
);
2415 CGContextRestoreGState(context
);
2419 HIThemeTextHorizontalFlush hFlush
= kHIThemeTextHorizontalFlushLeft
;
2420 UInt16 fontID
= kThemeViewsFont
;
2424 if (font
.GetFamily() != wxFONTFAMILY_DEFAULT
)
2425 fontID
= font
.MacGetThemeFontID();
2427 // FIXME: replace these with CG or ATSUI calls so we can remove this #ifndef.
2429 ::TextSize( (short)(font
.MacGetFontSize()) ) ;
2430 ::TextFace( font
.MacGetFontStyle() ) ;
2435 list
->GetColumn(listColumn
, item
);
2436 if (item
.GetMask() & wxLIST_MASK_FORMAT
)
2438 if (item
.GetAlign() == wxLIST_FORMAT_LEFT
)
2439 hFlush
= kHIThemeTextHorizontalFlushLeft
;
2440 else if (item
.GetAlign() == wxLIST_FORMAT_CENTER
)
2441 hFlush
= kHIThemeTextHorizontalFlushCenter
;
2442 else if (item
.GetAlign() == wxLIST_FORMAT_RIGHT
)
2444 hFlush
= kHIThemeTextHorizontalFlushRight
;
2445 textCGRect
.origin
.x
-= kItemPadding
; // give a little extra paddding
2449 HIThemeTextInfo info
;
2450 info
.version
= kHIThemeTextInfoVersionZero
;
2451 info
.state
= active
? kThemeStateActive
: kThemeStateInactive
;
2452 info
.fontID
= fontID
;
2453 info
.horizontalFlushness
= hFlush
;
2454 info
.verticalFlushness
= kHIThemeTextVerticalFlushCenter
;
2455 info
.options
= kHIThemeTextBoxOptionNone
;
2456 info
.truncationPosition
= kHIThemeTextTruncationEnd
;
2457 info
.truncationMaxLines
= 1;
2459 CGContextSaveGState(context
);
2460 CGContextSetRGBFillColor (context
, (float)labelColor
.red
/ (float)USHRT_MAX
,
2461 (float)labelColor
.green
/ (float)USHRT_MAX
,
2462 (float)labelColor
.blue
/ (float)USHRT_MAX
, 1.0);
2464 HIThemeDrawTextBox(cfString
, &textCGRect
, &info
, context
, kHIThemeOrientationNormal
);
2466 CGContextRestoreGState(context
);
2468 if (savedState
!= NULL
)
2469 SetThemeDrawingState(savedState
, true);
2472 OSStatus
wxMacDataBrowserListCtrlControl::GetSetItemData(DataBrowserItemID itemID
,
2473 DataBrowserPropertyID property
,
2474 DataBrowserItemDataRef itemData
,
2475 Boolean changeValue
)
2479 short listColumn
= property
- kMinColumnId
;
2481 OSStatus err
= errDataBrowserPropertyNotSupported
;
2482 wxListCtrl
* list
= wxDynamicCast( GetPeer() , wxListCtrl
);
2483 wxMacListCtrlItem
* lcItem
;
2485 if (listColumn
>= 0)
2489 lcItem
= (wxMacListCtrlItem
*) itemID
;
2490 if (lcItem
->HasColumnInfo(listColumn
)){
2491 wxListItem
* item
= lcItem
->GetColumnInfo(listColumn
);
2492 if (item
->GetMask() & wxLIST_MASK_TEXT
)
2493 text
= item
->GetText();
2494 if (item
->GetMask() & wxLIST_MASK_IMAGE
)
2495 imgIndex
= item
->GetImage();
2500 text
= list
->OnGetItemText( (long)itemID
-1, listColumn
);
2501 imgIndex
= list
->OnGetItemColumnImage( (long)itemID
-1, listColumn
);
2509 case kDataBrowserItemIsEditableProperty
:
2510 if ( list
&& list
->HasFlag( wxLC_EDIT_LABELS
) )
2512 verify_noerr(SetDataBrowserItemDataBooleanValue( itemData
, true ));
2517 if ( property
>= kMinColumnId
)
2519 wxMacCFStringHolder cfStr
;
2522 cfStr
.Assign( text
, wxLocale::GetSystemEncoding() );
2523 err
= ::SetDataBrowserItemDataText( itemData
, cfStr
);
2529 if ( imgIndex
!= -1 )
2531 wxImageList
* imageList
= list
->GetImageList(wxIMAGE_LIST_SMALL
);
2532 if (imageList
&& imageList
->GetImageCount() > 0){
2533 wxBitmap bmp
= imageList
->GetBitmap(imgIndex
);
2534 IconRef icon
= bmp
.GetBitmapData()->GetIconRef();
2535 ::SetDataBrowserItemDataIcon(itemData
, icon
);
2549 if ( property
>= kMinColumnId
)
2551 short listColumn
= property
- kMinColumnId
;
2553 // TODO probably send the 'end edit' from here, as we
2554 // can then deal with the veto
2556 verify_noerr( GetDataBrowserItemDataText( itemData
, &sr
) ) ;
2557 wxMacCFStringHolder
cfStr(sr
) ;;
2559 list
->SetItem( (long)itemData
-1 , listColumn
, cfStr
.AsString() ) ;
2563 lcItem
->SetColumnTextValue( listColumn
, cfStr
.AsString() );
2573 void wxMacDataBrowserListCtrlControl::ItemNotification(DataBrowserItemID itemID
,
2574 DataBrowserItemNotification message
,
2575 DataBrowserItemDataRef itemData
)
2577 // we want to depend on as little as possible to make sure tear-down of controls is safe
2578 if ( message
== kDataBrowserItemRemoved
)
2580 // make sure MacDelete does the proper teardown.
2583 else if ( message
== kDataBrowserItemAdded
)
2585 // we don't issue events on adding, the item is not really stored in the list yet, so we
2586 // avoid asserts by getting out now
2590 wxListCtrl
*list
= wxDynamicCast( GetPeer() , wxListCtrl
);
2593 bool trigger
= false;
2595 wxListEvent
event( wxEVT_COMMAND_LIST_ITEM_SELECTED
, list
->GetId() );
2596 bool isSingle
= (list
->GetWindowStyle() & wxLC_SINGLE_SEL
) != 0;
2598 event
.SetEventObject( list
);
2599 if ( !list
->IsVirtual() )
2601 DataBrowserTableViewRowIndex result
= 0;
2602 verify_noerr( GetItemRow( itemID
, &result
) ) ;
2603 event
.m_itemIndex
= result
;
2605 if (event
.m_itemIndex
>= 0)
2606 MacGetColumnInfo(event
.m_itemIndex
,0,event
.m_item
);
2610 event
.m_itemIndex
= (long)itemID
;
2615 case kDataBrowserItemDeselected
:
2616 event
.SetEventType(wxEVT_COMMAND_LIST_ITEM_DESELECTED
);
2618 trigger
= !IsSelectionSuppressed();
2621 case kDataBrowserItemSelected
:
2622 trigger
= !IsSelectionSuppressed();
2626 case kDataBrowserItemDoubleClicked
:
2627 event
.SetEventType( wxEVT_COMMAND_LIST_ITEM_ACTIVATED
);
2631 case kDataBrowserEditStarted
:
2632 // TODO : how to veto ?
2633 event
.SetEventType( wxEVT_COMMAND_LIST_BEGIN_LABEL_EDIT
) ;
2637 case kDataBrowserEditStopped
:
2638 // TODO probably trigger only upon the value store callback, because
2639 // here IIRC we cannot veto
2640 event
.SetEventType( wxEVT_COMMAND_LIST_END_LABEL_EDIT
) ;
2650 // direct notification is not always having the listbox GetSelection() having in synch with event
2651 wxPostEvent( list
->GetEventHandler(), event
);
2656 Boolean
wxMacDataBrowserListCtrlControl::CompareItems(DataBrowserItemID itemOneID
,
2657 DataBrowserItemID itemTwoID
,
2658 DataBrowserPropertyID sortProperty
)
2661 bool retval
= false;
2663 wxString otherItemText
;
2664 int colId
= sortProperty
- kMinColumnId
;
2666 long otherItemNum
= 0;
2668 wxListCtrl
* list
= wxDynamicCast( GetPeer() , wxListCtrl
);
2675 wxMacListCtrlItem
* item
= (wxMacListCtrlItem
*)itemOneID
;
2676 wxMacListCtrlItem
* otherItem
= (wxMacListCtrlItem
*)itemTwoID
;
2677 wxListCtrlCompare func
= list
->GetCompareFunc();
2678 if (func
!= NULL
&& item
->HasColumnInfo(colId
) && otherItem
->HasColumnInfo(colId
))
2679 return func(item
->GetColumnInfo(colId
)->GetData(), otherItem
->GetColumnInfo(colId
)->GetData(), list
->GetCompareFuncData()) >= 0;
2681 itemNum
= item
->GetOrder();
2682 otherItemNum
= otherItem
->GetOrder();
2683 if (item
->HasColumnInfo(colId
))
2684 itemText
= item
->GetColumnInfo(colId
)->GetText();
2685 if (otherItem
->HasColumnInfo(colId
))
2686 otherItemText
= otherItem
->GetColumnInfo(colId
)->GetText();
2690 itemNum
= (long)itemOneID
;
2691 otherItemNum
= (long)itemTwoID
;
2692 itemText
= list
->OnGetItemText( itemNum
-1, colId
);
2693 otherItemText
= list
->OnGetItemText( otherItemNum
-1, colId
);
2697 DataBrowserSortOrder sort
;
2698 verify_noerr(GetSortOrder(&sort
));
2700 if ( sort
== kDataBrowserOrderIncreasing
)
2702 retval
= itemText
.CmpNoCase( otherItemText
) > 0;
2704 else if ( sort
== kDataBrowserOrderDecreasing
)
2706 retval
= itemText
.CmpNoCase( otherItemText
) < 0;
2710 // fallback for undefined cases
2711 retval
= itemOneID
< itemTwoID
;
2717 wxMacDataBrowserListCtrlControl::~wxMacDataBrowserListCtrlControl()
2721 void wxMacDataBrowserListCtrlControl::MacSetColumnInfo( unsigned int row
, unsigned int column
, wxListItem
* item
)
2723 wxMacDataItem
* dataItem
= GetItemFromLine(row
);
2726 wxMacListCtrlItem
* listItem
= dynamic_cast<wxMacListCtrlItem
*>(dataItem
);
2727 listItem
->SetColumnInfo( column
, item
);
2728 UpdateState(dataItem
, item
);
2732 // apply changes that need to happen immediately, rather than when the
2733 // databrowser control fires a callback.
2734 void wxMacDataBrowserListCtrlControl::UpdateState(wxMacDataItem
* dataItem
, wxListItem
* listItem
)
2736 bool isSelected
= IsItemSelected( dataItem
);
2737 bool isSelectedState
= (listItem
->GetState() == wxLIST_STATE_SELECTED
);
2739 // toggle the selection state if wxListInfo state and actual state don't match.
2740 if ( isSelected
!= isSelectedState
)
2742 DataBrowserSetOption options
= kDataBrowserItemsAdd
;
2743 if (!isSelectedState
)
2744 options
= kDataBrowserItemsRemove
;
2745 SetSelectedItem(dataItem
, options
);
2747 // TODO: Set column width if item width > than current column width
2750 void wxMacDataBrowserListCtrlControl::MacGetColumnInfo( unsigned int row
, unsigned int column
, wxListItem
& item
)
2752 wxMacDataItem
* dataItem
= GetItemFromLine(row
);
2753 // CS should this guard against dataItem = 0 ? , as item is not a pointer if (item) is not appropriate
2756 wxMacListCtrlItem
* listItem
= dynamic_cast<wxMacListCtrlItem
*>(dataItem
);
2757 wxListItem
* oldItem
= listItem
->GetColumnInfo( column
);
2759 long mask
= item
.GetMask();
2761 // by default, get everything for backwards compatibility
2764 if ( mask
& wxLIST_MASK_TEXT
)
2765 item
.SetText(oldItem
->GetText());
2766 if ( mask
& wxLIST_MASK_IMAGE
)
2767 item
.SetImage(oldItem
->GetImage());
2768 if ( mask
& wxLIST_MASK_DATA
)
2769 item
.SetData(oldItem
->GetData());
2770 if ( mask
& wxLIST_MASK_STATE
)
2771 item
.SetState(oldItem
->GetState());
2772 if ( mask
& wxLIST_MASK_WIDTH
)
2773 item
.SetWidth(oldItem
->GetWidth());
2774 if ( mask
& wxLIST_MASK_FORMAT
)
2775 item
.SetAlign(oldItem
->GetAlign());
2777 item
.SetTextColour(oldItem
->GetTextColour());
2778 item
.SetBackgroundColour(oldItem
->GetBackgroundColour());
2779 item
.SetFont(oldItem
->GetFont());
2783 void wxMacDataBrowserListCtrlControl::MacInsertItem( unsigned int n
, wxListItem
* item
)
2785 wxMacDataItemBrowserControl::MacInsert(n
, item
->GetText());
2786 MacSetColumnInfo(n
, 0, item
);
2789 wxMacDataItem
* wxMacDataBrowserListCtrlControl::CreateItem()
2791 return new wxMacListCtrlItem();
2794 wxMacListCtrlItem::wxMacListCtrlItem()
2796 m_rowItems
= wxListItemList();
2799 int wxMacListCtrlItem::GetColumnImageValue( unsigned int column
)
2801 return GetColumnInfo(column
)->GetImage();
2804 void wxMacListCtrlItem::SetColumnImageValue( unsigned int column
, int imageIndex
)
2806 GetColumnInfo(column
)->SetImage(imageIndex
);
2809 const wxString
& wxMacListCtrlItem::GetColumnTextValue( unsigned int column
)
2814 return GetColumnInfo(column
)->GetText();
2817 void wxMacListCtrlItem::SetColumnTextValue( unsigned int column
, const wxString
& text
)
2819 GetColumnInfo(column
)->SetText(text
);
2821 // for compatibility with superclass APIs
2826 wxListItem
* wxMacListCtrlItem::GetColumnInfo( unsigned int column
)
2828 wxListItemList::compatibility_iterator node
= m_rowItems
.Item( column
);
2829 wxASSERT_MSG( node
, _T("invalid column index in wxMacListCtrlItem") );
2831 return node
->GetData();
2834 bool wxMacListCtrlItem::HasColumnInfo( unsigned int column
)
2836 return m_rowItems
.GetCount() > column
;
2839 void wxMacListCtrlItem::SetColumnInfo( unsigned int column
, wxListItem
* item
)
2842 if ( column
>= m_rowItems
.GetCount() )
2844 wxListItem
* listItem
= new wxListItem(*item
);
2845 m_rowItems
.Append( listItem
);
2849 wxListItem
* listItem
= GetColumnInfo( column
);
2850 long mask
= item
->GetMask();
2851 if (mask
& wxLIST_MASK_TEXT
)
2852 listItem
->SetText(item
->GetText());
2853 if (mask
& wxLIST_MASK_DATA
)
2854 listItem
->SetData(item
->GetData());
2855 if (mask
& wxLIST_MASK_IMAGE
)
2856 listItem
->SetImage(item
->GetImage());
2857 if (mask
& wxLIST_MASK_STATE
)
2858 listItem
->SetState(item
->GetState());
2859 if (mask
& wxLIST_MASK_FORMAT
)
2860 listItem
->SetAlign(item
->GetAlign());
2861 if (mask
& wxLIST_MASK_WIDTH
)
2862 listItem
->SetWidth(item
->GetWidth());
2864 listItem
->SetTextColour(item
->GetTextColour());
2865 listItem
->SetBackgroundColour(item
->GetBackgroundColour());
2866 listItem
->SetFont(item
->GetFont());
2870 #endif // wxUSE_LISTCTRL