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
) )
633 // since the generic control is a child, make sure we position it at 0, 0
634 m_genericImpl
= new wxGenericListCtrlHook(this, id
, wxPoint(0, 0), size
, style
, validator
, name
);
635 m_genericImpl
->PushEventHandler( new wxMacListCtrlEventDelegate( this, GetId() ) );
641 m_macIsUserPane
= false;
643 if ( !wxWindow::Create(parent
, id
, pos
, size
, style
, name
) )
645 m_dbImpl
= new wxMacDataBrowserListCtrlControl( this, pos
, size
, style
);
648 MacPostControlCreate( pos
, size
);
650 InstallControlEventHandler( m_peer
->GetControlRef() , GetwxMacListCtrlEventHandlerUPP(),
651 GetEventTypeCount(eventList
), eventList
, this,
652 (EventHandlerRef
*)&m_macListCtrlEventHandler
);
658 wxListCtrl::~wxListCtrl()
662 m_genericImpl
->PopEventHandler(/* deleteHandler = */ true);
665 if (m_ownsImageListNormal
)
666 delete m_imageListNormal
;
667 if (m_ownsImageListSmall
)
668 delete m_imageListSmall
;
669 if (m_ownsImageListState
)
670 delete m_imageListState
;
672 delete m_renameTimer
;
675 // ----------------------------------------------------------------------------
676 // set/get/change style
677 // ----------------------------------------------------------------------------
679 // Add or remove a single window style
680 void wxListCtrl::SetSingleStyle(long style
, bool add
)
682 long flag
= GetWindowStyleFlag();
684 // Get rid of conflicting styles
687 if ( style
& wxLC_MASK_TYPE
)
688 flag
= flag
& ~wxLC_MASK_TYPE
;
689 if ( style
& wxLC_MASK_ALIGN
)
690 flag
= flag
& ~wxLC_MASK_ALIGN
;
691 if ( style
& wxLC_MASK_SORT
)
692 flag
= flag
& ~wxLC_MASK_SORT
;
700 SetWindowStyleFlag(flag
);
703 // Set the whole window style
704 void wxListCtrl::SetWindowStyleFlag(long flag
)
706 if ( flag
!= m_windowStyle
)
708 m_windowStyle
= flag
;
712 m_genericImpl
->SetWindowStyleFlag(flag
);
719 void wxListCtrl::DoSetSize( int x
, int y
, int width
, int height
, int sizeFlags
)
721 wxControl::DoSetSize(x
, y
, width
, height
, sizeFlags
);
724 m_genericImpl
->SetSize(0, 0, width
, height
, sizeFlags
);
727 wxSize
wxListCtrl::DoGetBestSize() const
729 return wxWindow::DoGetBestSize();
732 bool wxListCtrl::SetFont(const wxFont
& font
)
735 rv
= wxControl::SetFont(font
);
737 rv
= m_genericImpl
->SetFont(font
);
741 bool wxListCtrl::SetForegroundColour(const wxColour
& colour
)
745 rv
= m_genericImpl
->SetForegroundColour(colour
);
747 SetTextColour(colour
);
751 bool wxListCtrl::SetBackgroundColour(const wxColour
& colour
)
755 rv
= m_genericImpl
->SetBackgroundColour(colour
);
761 wxColour
wxListCtrl::GetBackgroundColour()
764 return m_genericImpl
->GetBackgroundColour();
771 // ----------------------------------------------------------------------------
773 // ----------------------------------------------------------------------------
775 // Gets information about this column
776 bool wxListCtrl::GetColumn(int col
, wxListItem
& item
) const
779 return m_genericImpl
->GetColumn(col
, item
);
786 wxColumnList::compatibility_iterator node
= m_colsInfo
.Item( col
);
787 wxASSERT_MSG( node
, _T("invalid column index in wxMacListCtrlItem") );
788 wxListItem
* column
= node
->GetData();
790 long mask
= column
->GetMask();
791 if (mask
& wxLIST_MASK_TEXT
)
792 item
.SetText(column
->GetText());
793 if (mask
& wxLIST_MASK_DATA
)
794 item
.SetData(column
->GetData());
795 if (mask
& wxLIST_MASK_IMAGE
)
796 item
.SetImage(column
->GetImage());
797 if (mask
& wxLIST_MASK_STATE
)
798 item
.SetState(column
->GetState());
799 if (mask
& wxLIST_MASK_FORMAT
)
800 item
.SetAlign(column
->GetAlign());
801 if (mask
& wxLIST_MASK_WIDTH
)
802 item
.SetWidth(column
->GetWidth());
808 // Sets information about this column
809 bool wxListCtrl::SetColumn(int col
, wxListItem
& item
)
812 return m_genericImpl
->SetColumn(col
, item
);
816 if ( col
>= (int)m_colsInfo
.GetCount() )
818 wxListItem
* listItem
= new wxListItem(item
);
819 m_colsInfo
.Append( listItem
);
824 GetColumn( col
, listItem
);
825 long mask
= item
.GetMask();
826 if (mask
& wxLIST_MASK_TEXT
)
827 listItem
.SetText(item
.GetText());
828 if (mask
& wxLIST_MASK_DATA
)
829 listItem
.SetData(item
.GetData());
830 if (mask
& wxLIST_MASK_IMAGE
)
831 listItem
.SetImage(item
.GetImage());
832 if (mask
& wxLIST_MASK_STATE
)
833 listItem
.SetState(item
.GetState());
834 if (mask
& wxLIST_MASK_FORMAT
)
835 listItem
.SetAlign(item
.GetAlign());
836 if (mask
& wxLIST_MASK_WIDTH
)
837 listItem
.SetWidth(item
.GetWidth());
840 // change the appearance in the databrowser.
841 DataBrowserListViewHeaderDesc columnDesc
;
842 columnDesc
.version
=kDataBrowserListViewLatestHeaderDesc
;
843 verify_noerr( m_dbImpl
->GetHeaderDesc( kMinColumnId
+ col
, &columnDesc
) );
846 if (item.GetMask() & wxLIST_MASK_TEXT)
850 enc = m_font.GetEncoding();
852 enc = wxLocale::GetSystemEncoding();
853 wxMacCFStringHolder cfTitle;
854 cfTitle.Assign( item.GetText() , enc );
855 if(columnDesc.titleString)
856 CFRelease(columnDesc.titleString);
857 columnDesc.titleString = cfTitle;
861 if (item
.GetMask() & wxLIST_MASK_IMAGE
&& item
.GetImage() != -1 )
863 columnDesc
.btnContentInfo
.contentType
= kControlContentIconRef
;
864 wxImageList
* imageList
= GetImageList(wxIMAGE_LIST_SMALL
);
865 if (imageList
&& imageList
->GetImageCount() > 0 )
867 wxBitmap bmp
= imageList
->GetBitmap( item
.GetImage() );
868 IconRef icon
= bmp
.GetBitmapData()->GetIconRef();
869 columnDesc
.btnContentInfo
.u
.iconRef
= icon
;
873 verify_noerr( m_dbImpl
->SetHeaderDesc( kMinColumnId
+ col
, &columnDesc
) );
879 int wxListCtrl::GetColumnCount() const
882 return m_genericImpl
->GetColumnCount();
887 m_dbImpl
->GetColumnCount(&count
);
894 // Gets the column width
895 int wxListCtrl::GetColumnWidth(int col
) const
898 return m_genericImpl
->GetColumnWidth(col
);
902 return m_dbImpl
->GetColumnWidth(col
);
908 // Sets the column width
909 bool wxListCtrl::SetColumnWidth(int col
, int width
)
912 return m_genericImpl
->SetColumnWidth(col
, width
);
917 if (width
== wxLIST_AUTOSIZE
|| width
== wxLIST_AUTOSIZE_USEHEADER
)
922 for (int column
= 0; column
< GetColumnCount(); column
++)
924 m_dbImpl
->SetColumnWidth(col
, mywidth
);
928 m_dbImpl
->SetColumnWidth(col
, mywidth
);
936 // Gets the number of items that can fit vertically in the
937 // visible area of the list control (list or report view)
938 // or the total number of items in the list control (icon
939 // or small icon view)
940 int wxListCtrl::GetCountPerPage() const
943 return m_genericImpl
->GetCountPerPage();
952 // Gets the edit control for editing labels.
953 wxTextCtrl
* wxListCtrl::GetEditControl() const
956 return m_genericImpl
->GetEditControl();
961 // Gets information about the item
962 bool wxListCtrl::GetItem(wxListItem
& info
) const
965 return m_genericImpl
->GetItem(info
);
970 m_dbImpl
->MacGetColumnInfo(info
.m_itemId
, info
.m_col
, info
);
973 info
.SetText( OnGetItemText(info
.m_itemId
, info
.m_col
) );
974 info
.SetImage( OnGetItemColumnImage(info
.m_itemId
, info
.m_col
) );
975 wxListItemAttr
* attrs
= OnGetItemAttr( info
.m_itemId
);
978 info
.SetFont( attrs
->GetFont() );
979 info
.SetBackgroundColour( attrs
->GetBackgroundColour() );
980 info
.SetTextColour( attrs
->GetTextColour() );
988 // Sets information about the item
989 bool wxListCtrl::SetItem(wxListItem
& info
)
992 return m_genericImpl
->SetItem(info
);
995 m_dbImpl
->MacSetColumnInfo( info
.m_itemId
, info
.m_col
, &info
);
1000 long wxListCtrl::SetItem(long index
, int col
, const wxString
& label
, int imageId
)
1003 return m_genericImpl
->SetItem(index
, col
, label
, imageId
);
1006 info
.m_text
= label
;
1007 info
.m_mask
= wxLIST_MASK_TEXT
;
1008 info
.m_itemId
= index
;
1012 info
.m_image
= imageId
;
1013 info
.m_mask
|= wxLIST_MASK_IMAGE
;
1015 return SetItem(info
);
1019 // Gets the item state
1020 int wxListCtrl::GetItemState(long item
, long stateMask
) const
1023 return m_genericImpl
->GetItemState(item
, stateMask
);
1027 info
.m_mask
= wxLIST_MASK_STATE
;
1028 info
.m_stateMask
= stateMask
;
1029 info
.m_itemId
= item
;
1034 return info
.m_state
;
1037 // Sets the item state
1038 bool wxListCtrl::SetItemState(long item
, long state
, long stateMask
)
1041 return m_genericImpl
->SetItemState(item
, state
, stateMask
);
1044 info
.m_mask
= wxLIST_MASK_STATE
;
1045 info
.m_stateMask
= stateMask
;
1046 info
.m_state
= state
;
1047 info
.m_itemId
= item
;
1048 return SetItem(info
);
1051 // Sets the item image
1052 bool wxListCtrl::SetItemImage(long item
, int image
, int WXUNUSED(selImage
))
1054 return SetItemColumnImage(item
, 0, image
);
1057 // Sets the item image
1058 bool wxListCtrl::SetItemColumnImage(long item
, long column
, int image
)
1061 return m_genericImpl
->SetItemColumnImage(item
, column
, image
);
1065 info
.m_mask
= wxLIST_MASK_IMAGE
;
1066 info
.m_image
= image
;
1067 info
.m_itemId
= item
;
1068 info
.m_col
= column
;
1070 return SetItem(info
);
1073 // Gets the item text
1074 wxString
wxListCtrl::GetItemText(long item
) const
1077 return m_genericImpl
->GetItemText(item
);
1081 info
.m_mask
= wxLIST_MASK_TEXT
;
1082 info
.m_itemId
= item
;
1085 return wxEmptyString
;
1089 // Sets the item text
1090 void wxListCtrl::SetItemText(long item
, const wxString
& str
)
1093 return m_genericImpl
->SetItemText(item
, str
);
1097 info
.m_mask
= wxLIST_MASK_TEXT
;
1098 info
.m_itemId
= item
;
1104 // Gets the item data
1105 long wxListCtrl::GetItemData(long item
) const
1108 return m_genericImpl
->GetItemData(item
);
1112 info
.m_mask
= wxLIST_MASK_DATA
;
1113 info
.m_itemId
= item
;
1120 // Sets the item data
1121 bool wxListCtrl::SetItemData(long item
, long data
)
1124 return m_genericImpl
->SetItemData(item
, data
);
1128 info
.m_mask
= wxLIST_MASK_DATA
;
1129 info
.m_itemId
= item
;
1132 return SetItem(info
);
1135 wxRect
wxListCtrl::GetViewRect() const
1137 wxASSERT_MSG( !HasFlag(wxLC_REPORT
| wxLC_LIST
),
1138 _T("wxListCtrl::GetViewRect() only works in icon mode") );
1141 return m_genericImpl
->GetViewRect();
1147 // Gets the item rectangle
1148 bool wxListCtrl::GetItemRect(long item
, wxRect
& rect
, int code
) const
1151 return m_genericImpl
->GetItemRect(item
, rect
, code
);
1156 DataBrowserItemID id
;
1157 DataBrowserPropertyID col
= kMinColumnId
;
1159 DataBrowserPropertyPart part
= kDataBrowserPropertyEnclosingPart
;
1160 if ( code
== wxLIST_RECT_LABEL
)
1161 part
= kDataBrowserPropertyTextPart
;
1162 else if ( code
== wxLIST_RECT_ICON
)
1163 part
= kDataBrowserPropertyIconPart
;
1165 if ( !(GetWindowStyleFlag() & wxLC_VIRTUAL
) )
1167 wxMacDataItem
* thisItem
= m_dbImpl
->GetItemFromLine(item
);
1168 id
= (DataBrowserItemID
) thisItem
;
1173 GetDataBrowserItemPartBounds( m_dbImpl
->GetControlRef(), id
, col
, part
, &bounds
);
1175 rect
.x
= bounds
.left
;
1176 rect
.y
= bounds
.top
;
1177 rect
.width
= bounds
.right
- bounds
.left
; //GetClientSize().x; // we need the width of the whole row, not just the item.
1178 rect
.height
= bounds
.bottom
- bounds
.top
;
1179 //fprintf("id = %d, bounds = %d, %d, %d, %d\n", id, rect.x, rect.y, rect.width, rect.height);
1184 // Gets the item position
1185 bool wxListCtrl::GetItemPosition(long item
, wxPoint
& pos
) const
1188 return m_genericImpl
->GetItemPosition(item
, pos
);
1190 bool success
= false;
1195 GetItemRect(item
, itemRect
);
1196 pos
= itemRect
.GetPosition();
1203 // Sets the item position.
1204 bool wxListCtrl::SetItemPosition(long item
, const wxPoint
& pos
)
1207 return m_genericImpl
->SetItemPosition(item
, pos
);
1212 // Gets the number of items in the list control
1213 int wxListCtrl::GetItemCount() const
1216 return m_genericImpl
->GetItemCount();
1219 return m_dbImpl
->MacGetCount();
1224 void wxListCtrl::SetItemSpacing( int spacing
, bool isSmall
)
1227 m_genericImpl
->SetItemSpacing(spacing
, isSmall
);
1230 wxSize
wxListCtrl::GetItemSpacing() const
1233 return m_genericImpl
->GetItemSpacing();
1235 return wxSize(0, 0);
1238 void wxListCtrl::SetItemTextColour( long item
, const wxColour
&col
)
1242 m_genericImpl
->SetItemTextColour(item
, col
);
1247 info
.m_itemId
= item
;
1248 info
.SetTextColour( col
);
1252 wxColour
wxListCtrl::GetItemTextColour( long item
) const
1255 return m_genericImpl
->GetItemTextColour(item
);
1261 return info
.GetTextColour();
1263 return wxNullColour
;
1266 void wxListCtrl::SetItemBackgroundColour( long item
, const wxColour
&col
)
1270 m_genericImpl
->SetItemBackgroundColour(item
, col
);
1275 info
.m_itemId
= item
;
1276 info
.SetBackgroundColour( col
);
1280 wxColour
wxListCtrl::GetItemBackgroundColour( long item
) const
1283 return m_genericImpl
->GetItemBackgroundColour(item
);
1289 return info
.GetBackgroundColour();
1291 return wxNullColour
;
1294 void wxListCtrl::SetItemFont( long item
, const wxFont
&f
)
1298 m_genericImpl
->SetItemFont(item
, f
);
1303 info
.m_itemId
= item
;
1308 wxFont
wxListCtrl::GetItemFont( long item
) const
1311 return m_genericImpl
->GetItemFont(item
);
1317 return info
.GetFont();
1323 // Gets the number of selected items in the list control
1324 int wxListCtrl::GetSelectedItemCount() const
1327 return m_genericImpl
->GetSelectedItemCount();
1330 return m_dbImpl
->GetSelectedItemCount(NULL
, true);
1335 // Gets the text colour of the listview
1336 wxColour
wxListCtrl::GetTextColour() const
1339 return m_genericImpl
->GetTextColour();
1341 // TODO: we need owner drawn list items to customize text color.
1345 return wxNullColour
;
1348 // Sets the text colour of the listview
1349 void wxListCtrl::SetTextColour(const wxColour
& col
)
1353 m_genericImpl
->SetTextColour(col
);
1361 // Gets the index of the topmost visible item when in
1362 // list or report view
1363 long wxListCtrl::GetTopItem() const
1366 return m_genericImpl
->GetTopItem();
1371 // Searches for an item, starting from 'item'.
1372 // 'geometry' is one of
1373 // wxLIST_NEXT_ABOVE/ALL/BELOW/LEFT/RIGHT.
1374 // 'state' is a state bit flag, one or more of
1375 // wxLIST_STATE_DROPHILITED/FOCUSED/SELECTED/CUT.
1376 // item can be -1 to find the first item that matches the
1378 // Returns the item or -1 if unsuccessful.
1379 long wxListCtrl::GetNextItem(long item
, int geom
, int state
) const
1382 return m_genericImpl
->GetNextItem(item
, geom
, state
);
1384 if (m_dbImpl
&& geom
== wxLIST_NEXT_ALL
&& state
== wxLIST_STATE_SELECTED
)
1386 long count
= m_dbImpl
->MacGetCount() ;
1387 for ( long line
= item
+ 1 ; line
< count
; line
++ )
1389 wxMacDataItem
* id
= m_dbImpl
->GetItemFromLine(line
);
1390 if ( m_dbImpl
->IsItemSelected(id
) )
1400 wxImageList
*wxListCtrl::GetImageList(int which
) const
1403 return m_genericImpl
->GetImageList(which
);
1405 if ( which
== wxIMAGE_LIST_NORMAL
)
1407 return m_imageListNormal
;
1409 else if ( which
== wxIMAGE_LIST_SMALL
)
1411 return m_imageListSmall
;
1413 else if ( which
== wxIMAGE_LIST_STATE
)
1415 return m_imageListState
;
1420 void wxListCtrl::SetImageList(wxImageList
*imageList
, int which
)
1424 m_genericImpl
->SetImageList(imageList
, which
);
1428 if ( which
== wxIMAGE_LIST_NORMAL
)
1430 if (m_ownsImageListNormal
) delete m_imageListNormal
;
1431 m_imageListNormal
= imageList
;
1432 m_ownsImageListNormal
= false;
1434 else if ( which
== wxIMAGE_LIST_SMALL
)
1436 if (m_ownsImageListSmall
) delete m_imageListSmall
;
1437 m_imageListSmall
= imageList
;
1438 m_ownsImageListSmall
= false;
1440 else if ( which
== wxIMAGE_LIST_STATE
)
1442 if (m_ownsImageListState
) delete m_imageListState
;
1443 m_imageListState
= imageList
;
1444 m_ownsImageListState
= false;
1448 void wxListCtrl::AssignImageList(wxImageList
*imageList
, int which
)
1452 m_genericImpl
->AssignImageList(imageList
, which
);
1456 SetImageList(imageList
, which
);
1457 if ( which
== wxIMAGE_LIST_NORMAL
)
1458 m_ownsImageListNormal
= true;
1459 else if ( which
== wxIMAGE_LIST_SMALL
)
1460 m_ownsImageListSmall
= true;
1461 else if ( which
== wxIMAGE_LIST_STATE
)
1462 m_ownsImageListState
= true;
1465 // ----------------------------------------------------------------------------
1467 // ----------------------------------------------------------------------------
1469 // Arranges the items
1470 bool wxListCtrl::Arrange(int flag
)
1473 return m_genericImpl
->Arrange(flag
);
1478 bool wxListCtrl::DeleteItem(long item
)
1481 return m_genericImpl
->DeleteItem(item
);
1485 m_dbImpl
->MacDelete(item
);
1486 wxListEvent
event( wxEVT_COMMAND_LIST_DELETE_ITEM
, GetId() );
1487 event
.SetEventObject( this );
1488 event
.m_itemIndex
= item
;
1489 GetEventHandler()->ProcessEvent( event
);
1495 // Deletes all items
1496 bool wxListCtrl::DeleteAllItems()
1499 return m_genericImpl
->DeleteAllItems();
1503 m_dbImpl
->MacClear();
1504 wxListEvent
event( wxEVT_COMMAND_LIST_DELETE_ALL_ITEMS
, GetId() );
1505 event
.SetEventObject( this );
1506 GetEventHandler()->ProcessEvent( event
);
1511 // Deletes all items
1512 bool wxListCtrl::DeleteAllColumns()
1515 return m_genericImpl
->DeleteAllColumns();
1520 m_dbImpl
->GetColumnCount(&cols
);
1521 for (UInt32 col
= 0; col
< cols
; col
++)
1531 bool wxListCtrl::DeleteColumn(int col
)
1534 return m_genericImpl
->DeleteColumn(col
);
1538 OSStatus err
= m_dbImpl
->RemoveColumn(col
);
1539 return err
== noErr
;
1545 // Clears items, and columns if there are any.
1546 void wxListCtrl::ClearAll()
1550 m_genericImpl
->ClearAll();
1561 wxTextCtrl
* wxListCtrl::EditLabel(long item
, wxClassInfo
* textControlClass
)
1564 return m_genericImpl
->EditLabel(item
, textControlClass
);
1568 wxCHECK_MSG( (item
>= 0) && ((long)item
< GetItemCount()), NULL
,
1569 wxT("wrong index in wxListCtrl::EditLabel()") );
1571 wxASSERT_MSG( textControlClass
->IsKindOf(CLASSINFO(wxTextCtrl
)),
1572 wxT("EditLabel() needs a text control") );
1574 wxListEvent
le( wxEVT_COMMAND_LIST_BEGIN_LABEL_EDIT
, GetParent()->GetId() );
1575 le
.SetEventObject( this );
1576 le
.m_itemIndex
= item
;
1578 GetItem( le
.m_item
);
1580 if ( GetParent()->GetEventHandler()->ProcessEvent( le
) && !le
.IsAllowed() )
1582 // vetoed by user code
1586 wxTextCtrl
* const text
= (wxTextCtrl
*)textControlClass
->CreateObject();
1587 m_textctrlWrapper
= new wxListCtrlTextCtrlWrapper(this, text
, item
);
1588 return m_textctrlWrapper
->GetText();
1593 // End label editing, optionally cancelling the edit
1594 bool wxListCtrl::EndEditLabel(bool cancel
)
1596 // TODO: generic impl. doesn't have this method - is it needed for us?
1598 return true; // m_genericImpl->EndEditLabel(cancel);
1601 verify_noerr( SetDataBrowserEditItem(m_dbImpl
->GetControlRef(), kDataBrowserNoItem
, kMinColumnId
) );
1605 // Ensures this item is visible
1606 bool wxListCtrl::EnsureVisible(long item
)
1609 return m_genericImpl
->EnsureVisible(item
);
1613 wxMacDataItem
* dataItem
= m_dbImpl
->GetItemFromLine(item
);
1614 m_dbImpl
->RevealItem(dataItem
, kDataBrowserRevealWithoutSelecting
);
1620 // Find an item whose label matches this string, starting from the item after 'start'
1621 // or the beginning if 'start' is -1.
1622 long wxListCtrl::FindItem(long start
, const wxString
& str
, bool partial
)
1625 return m_genericImpl
->FindItem(start
, str
, partial
);
1630 // Find an item whose data matches this data, starting from the item after 'start'
1631 // or the beginning if 'start' is -1.
1632 long wxListCtrl::FindItem(long start
, long data
)
1635 return m_genericImpl
->FindItem(start
, data
);
1637 long idx
= start
+ 1;
1638 long count
= GetItemCount();
1642 if (GetItemData(idx
) == data
)
1650 // Find an item nearest this position in the specified direction, starting from
1651 // the item after 'start' or the beginning if 'start' is -1.
1652 long wxListCtrl::FindItem(long start
, const wxPoint
& pt
, int direction
)
1655 return m_genericImpl
->FindItem(start
, pt
, direction
);
1659 // Determines which item (if any) is at the specified point,
1660 // giving details in 'flags' (see wxLIST_HITTEST_... flags above)
1662 wxListCtrl::HitTest(const wxPoint
& point
, int& flags
, long *ptrSubItem
) const
1665 return m_genericImpl
->HitTest(point
, flags
, ptrSubItem
);
1667 flags
= wxLIST_HITTEST_NOWHERE
;
1670 int colHeaderHeight
= 22; // TODO: Find a way to get this value from the db control?
1671 UInt16 rowHeight
= 0;
1672 m_dbImpl
->GetDefaultRowHeight(&rowHeight
);
1675 // get the actual row by taking scroll position into account
1676 UInt32 offsetX
, offsetY
;
1677 m_dbImpl
->GetScrollPosition( &offsetY
, &offsetX
);
1680 if ( !(GetWindowStyleFlag() & wxLC_NO_HEADER
) )
1681 y
-= colHeaderHeight
;
1683 int row
= y
/ rowHeight
;
1684 DataBrowserItemID id
;
1685 m_dbImpl
->GetItemID( (DataBrowserTableViewRowIndex
) row
, &id
);
1687 // TODO: Use GetDataBrowserItemPartBounds to return if we are in icon or label
1688 if ( !(GetWindowStyleFlag() & wxLC_VIRTUAL
) )
1690 wxMacListCtrlItem
* lcItem
;
1691 lcItem
= (wxMacListCtrlItem
*) id
;
1694 flags
= wxLIST_HITTEST_ONITEM
;
1700 if (row
< GetItemCount() )
1702 flags
= wxLIST_HITTEST_ONITEM
;
1712 // Inserts an item, returning the index of the new item if successful,
1714 long wxListCtrl::InsertItem(wxListItem
& info
)
1716 wxASSERT_MSG( !IsVirtual(), _T("can't be used with virtual controls") );
1719 return m_genericImpl
->InsertItem(info
);
1723 int count
= GetItemCount();
1725 if (info
.m_itemId
> count
)
1726 info
.m_itemId
= count
;
1728 m_dbImpl
->MacInsertItem(info
.m_itemId
, &info
);
1729 wxListEvent
event( wxEVT_COMMAND_LIST_INSERT_ITEM
, GetId() );
1730 event
.SetEventObject( this );
1731 event
.m_itemIndex
= info
.m_itemId
;
1732 GetEventHandler()->ProcessEvent( event
);
1735 return info
.m_itemId
;
1738 long wxListCtrl::InsertItem(long index
, const wxString
& label
)
1741 return m_genericImpl
->InsertItem(index
, label
);
1744 info
.m_text
= label
;
1745 info
.m_mask
= wxLIST_MASK_TEXT
;
1746 info
.m_itemId
= index
;
1747 return InsertItem(info
);
1750 // Inserts an image item
1751 long wxListCtrl::InsertItem(long index
, int imageIndex
)
1754 return m_genericImpl
->InsertItem(index
, imageIndex
);
1757 info
.m_image
= imageIndex
;
1758 info
.m_mask
= wxLIST_MASK_IMAGE
;
1759 info
.m_itemId
= index
;
1760 return InsertItem(info
);
1763 // Inserts an image/string item
1764 long wxListCtrl::InsertItem(long index
, const wxString
& label
, int imageIndex
)
1767 return m_genericImpl
->InsertItem(index
, label
, imageIndex
);
1770 info
.m_image
= imageIndex
;
1771 info
.m_text
= label
;
1772 info
.m_mask
= wxLIST_MASK_IMAGE
| wxLIST_MASK_TEXT
;
1773 info
.m_itemId
= index
;
1774 return InsertItem(info
);
1777 // For list view mode (only), inserts a column.
1778 long wxListCtrl::InsertColumn(long col
, wxListItem
& item
)
1781 return m_genericImpl
->InsertColumn(col
, item
);
1785 int width
= item
.GetWidth();
1786 if ( !(item
.GetMask() & wxLIST_MASK_WIDTH
) )
1789 DataBrowserPropertyType type
= kDataBrowserCustomType
; //kDataBrowserTextType;
1790 wxImageList
* imageList
= GetImageList(wxIMAGE_LIST_SMALL
);
1791 if (imageList
&& imageList
->GetImageCount() > 0)
1793 wxBitmap bmp
= imageList
->GetBitmap(0);
1795 // type = kDataBrowserIconAndTextType;
1798 SInt16 just
= teFlushDefault
;
1799 if (item
.GetMask() & wxLIST_MASK_FORMAT
)
1801 if (item
.GetAlign() == wxLIST_FORMAT_LEFT
)
1803 else if (item
.GetAlign() == wxLIST_FORMAT_CENTER
)
1805 else if (item
.GetAlign() == wxLIST_FORMAT_RIGHT
)
1806 just
= teFlushRight
;
1808 m_dbImpl
->InsertColumn(col
, type
, item
.GetText(), just
, width
);
1809 SetColumn(col
, item
);
1811 // set/remove options based on the wxListCtrl type.
1812 DataBrowserTableViewColumnID id
;
1813 m_dbImpl
->GetColumnIDFromIndex(col
, &id
);
1814 DataBrowserPropertyFlags flags
;
1815 verify_noerr(m_dbImpl
->GetPropertyFlags(id
, &flags
));
1816 if (GetWindowStyleFlag() & wxLC_EDIT_LABELS
)
1817 flags
|= kDataBrowserPropertyIsEditable
;
1819 if (GetWindowStyleFlag() & wxLC_VIRTUAL
){
1820 flags
&= ~kDataBrowserListViewSortableColumn
;
1822 verify_noerr(m_dbImpl
->SetPropertyFlags(id
, flags
));
1828 long wxListCtrl::InsertColumn(long col
,
1829 const wxString
& heading
,
1834 return m_genericImpl
->InsertColumn(col
, heading
, format
, width
);
1837 item
.m_mask
= wxLIST_MASK_TEXT
| wxLIST_MASK_FORMAT
;
1838 item
.m_text
= heading
;
1841 item
.m_mask
|= wxLIST_MASK_WIDTH
;
1842 item
.m_width
= width
;
1844 item
.m_format
= format
;
1846 return InsertColumn(col
, item
);
1849 // scroll the control by the given number of pixels (exception: in list view,
1850 // dx is interpreted as number of columns)
1851 bool wxListCtrl::ScrollList(int dx
, int dy
)
1854 return m_genericImpl
->ScrollList(dx
, dy
);
1858 m_dbImpl
->SetScrollPosition(dx
, dy
);
1864 bool wxListCtrl::SortItems(wxListCtrlCompare fn
, long data
)
1867 return m_genericImpl
->SortItems(fn
, data
);
1872 m_compareFuncData
= data
;
1878 void wxListCtrl::OnRenameTimer()
1880 wxCHECK_RET( HasCurrent(), wxT("unexpected rename timer") );
1882 EditLabel( m_current
);
1885 bool wxListCtrl::OnRenameAccept(long itemEdit
, const wxString
& value
)
1887 wxListEvent
le( wxEVT_COMMAND_LIST_END_LABEL_EDIT
, GetId() );
1888 le
.SetEventObject( this );
1889 le
.m_itemIndex
= itemEdit
;
1891 GetItem( le
.m_item
);
1892 le
.m_item
.m_text
= value
;
1893 return !GetEventHandler()->ProcessEvent( le
) ||
1897 void wxListCtrl::OnRenameCancelled(long itemEdit
)
1899 // let owner know that the edit was cancelled
1900 wxListEvent
le( wxEVT_COMMAND_LIST_END_LABEL_EDIT
, GetParent()->GetId() );
1902 le
.SetEditCanceled(true);
1904 le
.SetEventObject( this );
1905 le
.m_itemIndex
= itemEdit
;
1907 GetItem( le
.m_item
);
1908 GetEventHandler()->ProcessEvent( le
);
1911 // ----------------------------------------------------------------------------
1912 // virtual list controls
1913 // ----------------------------------------------------------------------------
1915 wxString
wxListCtrl::OnGetItemText(long WXUNUSED(item
), long WXUNUSED(col
)) const
1917 // this is a pure virtual function, in fact - which is not really pure
1918 // because the controls which are not virtual don't need to implement it
1919 wxFAIL_MSG( _T("wxListCtrl::OnGetItemText not supposed to be called") );
1921 return wxEmptyString
;
1924 int wxListCtrl::OnGetItemImage(long WXUNUSED(item
)) const
1926 wxCHECK_MSG(!GetImageList(wxIMAGE_LIST_SMALL
),
1928 wxT("List control has an image list, OnGetItemImage or OnGetItemColumnImage should be overridden."));
1932 int wxListCtrl::OnGetItemColumnImage(long item
, long column
) const
1935 return OnGetItemImage(item
);
1940 wxListItemAttr
*wxListCtrl::OnGetItemAttr(long WXUNUSED_UNLESS_DEBUG(item
)) const
1942 wxASSERT_MSG( item
>= 0 && item
< GetItemCount(),
1943 _T("invalid item index in OnGetItemAttr()") );
1945 // no attributes by default
1949 void wxListCtrl::SetItemCount(long count
)
1951 wxASSERT_MSG( IsVirtual(), _T("this is for virtual controls only") );
1955 m_genericImpl
->SetItemCount(count
);
1961 // we need to temporarily disable the new item creation notification
1962 // procedure to speed things up
1963 // FIXME: Even this doesn't seem to help much...
1964 DataBrowserCallbacks callbacks
;
1965 DataBrowserItemNotificationUPP itemUPP
;
1966 GetDataBrowserCallbacks(m_dbImpl
->GetControlRef(), &callbacks
);
1967 itemUPP
= callbacks
.u
.v1
.itemNotificationCallback
;
1968 callbacks
.u
.v1
.itemNotificationCallback
= 0;
1969 m_dbImpl
->SetCallbacks(&callbacks
);
1970 ::AddDataBrowserItems(m_dbImpl
->GetControlRef(), kDataBrowserNoItem
,
1971 count
, NULL
, kDataBrowserItemNoProperty
);
1972 callbacks
.u
.v1
.itemNotificationCallback
= itemUPP
;
1973 m_dbImpl
->SetCallbacks(&callbacks
);
1978 void wxListCtrl::RefreshItem(long item
)
1982 m_genericImpl
->RefreshItem(item
);
1987 GetItemRect(item
, rect
);
1991 void wxListCtrl::RefreshItems(long itemFrom
, long itemTo
)
1995 m_genericImpl
->RefreshItems(itemFrom
, itemTo
);
1999 wxRect rect1
, rect2
;
2000 GetItemRect(itemFrom
, rect1
);
2001 GetItemRect(itemTo
, rect2
);
2003 wxRect rect
= rect1
;
2004 rect
.height
= rect2
.GetBottom() - rect1
.GetTop();
2010 // wxMac internal data structures
2012 wxMacListCtrlItem::~wxMacListCtrlItem()
2016 void wxMacListCtrlItem::Notification(wxMacDataItemBrowserControl
*owner
,
2017 DataBrowserItemNotification message
,
2018 DataBrowserItemDataRef itemData
) const
2021 wxMacDataBrowserListCtrlControl
*lb
= dynamic_cast<wxMacDataBrowserListCtrlControl
*>(owner
);
2023 // we want to depend on as little as possible to make sure tear-down of controls is safe
2024 if ( message
== kDataBrowserItemRemoved
)
2026 if ( lb
!= NULL
&& lb
->GetClientDataType() == wxClientData_Object
)
2028 delete (wxClientData
*) (m_data
);
2034 else if ( message
== kDataBrowserItemAdded
)
2036 // we don't issue events on adding, the item is not really stored in the list yet, so we
2037 // avoid asserts by gettting out now
2041 wxListCtrl
*list
= wxDynamicCast( owner
->GetPeer() , wxListCtrl
);
2044 bool trigger
= false;
2046 wxListEvent
event( wxEVT_COMMAND_LIST_ITEM_SELECTED
, list
->GetId() );
2047 bool isSingle
= (list
->GetWindowStyle() & wxLC_SINGLE_SEL
) != 0;
2049 event
.SetEventObject( list
);
2050 event
.m_itemIndex
= owner
->GetLineFromItem( this ) ;
2051 if ( !list
->IsVirtual() )
2053 lb
->MacGetColumnInfo(event
.m_itemIndex
,0,event
.m_item
);
2058 case kDataBrowserItemDeselected
:
2059 event
.SetEventType(wxEVT_COMMAND_LIST_ITEM_DESELECTED
);
2061 trigger
= !lb
->IsSelectionSuppressed();
2064 case kDataBrowserItemSelected
:
2065 trigger
= !lb
->IsSelectionSuppressed();
2068 case kDataBrowserItemDoubleClicked
:
2069 event
.SetEventType( wxEVT_COMMAND_LIST_ITEM_ACTIVATED
);
2073 case kDataBrowserEditStarted
:
2074 // TODO : how to veto ?
2075 event
.SetEventType( wxEVT_COMMAND_LIST_BEGIN_LABEL_EDIT
) ;
2079 case kDataBrowserEditStopped
:
2080 // TODO probably trigger only upon the value store callback, because
2081 // here IIRC we cannot veto
2082 event
.SetEventType( wxEVT_COMMAND_LIST_END_LABEL_EDIT
) ;
2092 // direct notification is not always having the listbox GetSelection() having in synch with event
2093 wxPostEvent( list
->GetEventHandler(), event
);
2099 wxMacDataBrowserListCtrlControl::wxMacDataBrowserListCtrlControl( wxWindow
*peer
, const wxPoint
& pos
, const wxSize
& size
, long style
)
2100 : wxMacDataItemBrowserControl( peer
, pos
, size
, style
)
2102 OSStatus err
= noErr
;
2103 m_clientDataItemsType
= wxClientData_None
;
2104 m_isVirtual
= false;
2106 if ( style
& wxLC_VIRTUAL
)
2109 DataBrowserSelectionFlags options
= kDataBrowserDragSelect
;
2110 if ( style
& wxLC_SINGLE_SEL
)
2112 options
|= kDataBrowserSelectOnlyOne
;
2116 options
|= kDataBrowserCmdTogglesSelection
;
2119 err
= SetSelectionFlags( options
);
2120 verify_noerr( err
);
2122 DataBrowserCustomCallbacks callbacks
;
2123 InitializeDataBrowserCustomCallbacks( &callbacks
, kDataBrowserLatestCustomCallbacks
);
2125 if ( gDataBrowserDrawItemUPP
== NULL
)
2126 gDataBrowserDrawItemUPP
= NewDataBrowserDrawItemUPP(DataBrowserDrawItemProc
);
2128 // if ( gDataBrowserEditItemUPP == NULL )
2129 // gDataBrowserEditItemUPP = NewDataBrowserEditItemUPP(DataBrowserEditTextProc);
2131 if ( gDataBrowserHitTestUPP
== NULL
)
2132 gDataBrowserHitTestUPP
= NewDataBrowserHitTestUPP(DataBrowserHitTestProc
);
2134 callbacks
.u
.v1
.drawItemCallback
= gDataBrowserDrawItemUPP
;
2135 // callbacks.u.v1.editTextCallback = gDataBrowserEditItemUPP;
2136 callbacks
.u
.v1
.hitTestCallback
= gDataBrowserHitTestUPP
;
2138 SetDataBrowserCustomCallbacks( GetControlRef(), &callbacks
);
2140 if ( style
& wxLC_LIST
)
2142 InsertColumn(0, kDataBrowserIconAndTextType
, wxEmptyString
, -1, -1);
2143 verify_noerr( AutoSizeColumns() );
2146 if ( style
& wxLC_LIST
|| style
& wxLC_NO_HEADER
)
2147 verify_noerr( SetHeaderButtonHeight( 0 ) );
2150 SetSortProperty( kMinColumnId
- 1 );
2152 SetSortProperty( kMinColumnId
);
2153 if ( style
& wxLC_SORT_ASCENDING
)
2155 m_sortOrder
= SortOrder_Text_Ascending
;
2156 SetSortOrder( kDataBrowserOrderIncreasing
);
2158 else if ( style
& wxLC_SORT_DESCENDING
)
2160 m_sortOrder
= SortOrder_Text_Descending
;
2161 SetSortOrder( kDataBrowserOrderDecreasing
);
2165 m_sortOrder
= SortOrder_None
;
2168 if ( style
& wxLC_VRULES
)
2170 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4
2171 verify_noerr( DataBrowserChangeAttributes(m_controlRef
, kDataBrowserAttributeListViewDrawColumnDividers
, kDataBrowserAttributeNone
) );
2175 verify_noerr( SetHiliteStyle(kDataBrowserTableViewFillHilite
) );
2176 err
= SetHasScrollBars( (style
& wxHSCROLL
) != 0 , true );
2179 pascal Boolean
wxMacDataBrowserListCtrlControl::DataBrowserEditTextProc(
2181 DataBrowserItemID itemID
,
2182 DataBrowserPropertyID property
,
2183 CFStringRef theString
,
2184 Rect
*maxEditTextRect
,
2185 Boolean
*shrinkToFit
)
2187 Boolean result
= false;
2188 wxMacDataBrowserListCtrlControl
* ctl
= dynamic_cast<wxMacDataBrowserListCtrlControl
*>( wxMacControl::GetReferenceFromNativeControl( browser
) );
2191 result
= ctl
->ConfirmEditText(itemID
, property
, theString
, maxEditTextRect
, shrinkToFit
);
2192 theString
= CFSTR("Hello!");
2197 bool wxMacDataBrowserListCtrlControl::ConfirmEditText(
2198 DataBrowserItemID itemID
,
2199 DataBrowserPropertyID property
,
2200 CFStringRef theString
,
2201 Rect
*maxEditTextRect
,
2202 Boolean
*shrinkToFit
)
2204 //wxListCtrl* list = wxDynamicCast( GetPeer() , wxListCtrl );
2208 pascal void wxMacDataBrowserListCtrlControl::DataBrowserDrawItemProc(
2210 DataBrowserItemID itemID
,
2211 DataBrowserPropertyID property
,
2212 DataBrowserItemState itemState
,
2213 const Rect
*itemRect
,
2215 Boolean colorDevice
)
2217 wxMacDataBrowserListCtrlControl
* ctl
= dynamic_cast<wxMacDataBrowserListCtrlControl
*>( wxMacControl::GetReferenceFromNativeControl( browser
) );
2220 ctl
->DrawItem(itemID
, property
, itemState
, itemRect
, gdDepth
, colorDevice
);
2224 // routines needed for DrawItem
2229 kTextBoxHeight
= 14,
2230 kIconTextSpacingV
= 2,
2232 kContentHeight
= kIconHeight
+ kTextBoxHeight
+ kIconTextSpacingV
2235 static void calculateCGDrawingBounds(CGRect inItemRect
, CGRect
*outIconRect
, CGRect
*outTextRect
, bool hasIcon
= false)
2238 float iconH
, iconW
= 0;
2239 float padding
= kItemPadding
;
2242 iconH
= kIconHeight
;
2244 padding
= padding
*2;
2247 textBottom
= inItemRect
.origin
.y
;
2249 *outIconRect
= CGRectMake(inItemRect
.origin
.x
+ kItemPadding
,
2250 textBottom
+ kIconTextSpacingV
, kIconWidth
,
2253 *outTextRect
= CGRectMake(inItemRect
.origin
.x
+ padding
+ iconW
,
2254 textBottom
+ kIconTextSpacingV
, inItemRect
.size
.width
- padding
- iconW
,
2255 inItemRect
.size
.height
- kIconTextSpacingV
);
2258 void wxMacDataBrowserListCtrlControl::DrawItem(
2259 DataBrowserItemID itemID
,
2260 DataBrowserPropertyID property
,
2261 DataBrowserItemState itemState
,
2262 const Rect
*itemRect
,
2264 Boolean colorDevice
)
2267 wxFont font
= wxNullFont
;
2269 short listColumn
= property
- kMinColumnId
;
2271 wxListCtrl
* list
= wxDynamicCast( GetPeer() , wxListCtrl
);
2272 wxMacListCtrlItem
* lcItem
;
2273 wxColour color
= *wxBLACK
;
2274 wxColour bgColor
= wxNullColour
;
2276 if (listColumn
>= 0)
2280 lcItem
= (wxMacListCtrlItem
*) itemID
;
2281 if (lcItem
->HasColumnInfo(listColumn
)){
2282 wxListItem
* item
= lcItem
->GetColumnInfo(listColumn
);
2284 // we always use the 0 column to get font and text/background colors.
2285 if (lcItem
->HasColumnInfo(0))
2287 wxListItem
* firstItem
= lcItem
->GetColumnInfo(0);
2288 color
= firstItem
->GetTextColour();
2289 bgColor
= firstItem
->GetBackgroundColour();
2290 font
= firstItem
->GetFont();
2293 if (item
->GetMask() & wxLIST_MASK_TEXT
)
2294 text
= item
->GetText();
2295 if (item
->GetMask() & wxLIST_MASK_IMAGE
)
2296 imgIndex
= item
->GetImage();
2302 text
= list
->OnGetItemText( (long)itemID
-1, listColumn
);
2303 imgIndex
= list
->OnGetItemColumnImage( (long)itemID
-1, listColumn
);
2304 wxListItemAttr
* attrs
= list
->OnGetItemAttr( (long)itemID
-1 );
2307 if (attrs
->HasBackgroundColour())
2308 bgColor
= attrs
->GetBackgroundColour();
2309 if (attrs
->HasTextColour())
2310 color
= attrs
->GetTextColour();
2311 if (attrs
->HasFont())
2312 font
= attrs
->GetFont();
2317 wxColour listBgColor
= list
->GetBackgroundColour();
2318 if (bgColor
== wxNullColour
)
2319 bgColor
= listBgColor
;
2321 wxFont listFont
= list
->GetFont();
2322 if (font
== wxNullFont
)
2325 wxMacCFStringHolder cfString
;
2326 cfString
.Assign( text
, wxLocale::GetSystemEncoding() );
2329 CGRect enclosingCGRect
, iconCGRect
, textCGRect
;
2331 ThemeDrawingState savedState
= NULL
;
2332 CGContextRef context
= (CGContextRef
)list
->MacGetDrawingContext();
2333 RGBColor labelColor
;
2335 GetDataBrowserItemPartBounds(GetControlRef(), itemID
, property
, kDataBrowserPropertyEnclosingPart
,
2338 enclosingCGRect
= CGRectMake(enclosingRect
.left
,
2340 enclosingRect
.right
- enclosingRect
.left
,
2341 enclosingRect
.bottom
- enclosingRect
.top
);
2343 active
= IsControlActive(GetControlRef());
2345 if (itemState
== kDataBrowserItemIsSelected
)
2347 RGBColor foregroundColor
;
2349 GetThemeDrawingState(&savedState
);
2351 GetThemeBrushAsColor(kThemeBrushAlternatePrimaryHighlightColor
, 32, true, &foregroundColor
);
2352 GetThemeTextColor(kThemeTextColorWhite
, gdDepth
, colorDevice
, &labelColor
);
2354 CGContextSaveGState(context
);
2356 CGContextSetRGBFillColor(context
, (float)foregroundColor
.red
/ (float)USHRT_MAX
,
2357 (float)foregroundColor
.green
/ (float)USHRT_MAX
,
2358 (float)foregroundColor
.blue
/ (float)USHRT_MAX
, 1.0);
2359 CGContextFillRect(context
, enclosingCGRect
);
2361 CGContextRestoreGState(context
);
2367 labelColor
= MAC_WXCOLORREF( color
.GetPixel() );
2368 else if (list
->GetTextColour().Ok())
2369 labelColor
= MAC_WXCOLORREF( list
->GetTextColour().GetPixel() );
2373 labelColor
.green
= 0;
2374 labelColor
.blue
= 0;
2379 RGBColor foregroundColor
= MAC_WXCOLORREF( bgColor
.GetPixel() );
2380 CGContextSaveGState(context
);
2382 CGContextSetRGBFillColor(context
, (float)foregroundColor
.red
/ (float)USHRT_MAX
,
2383 (float)foregroundColor
.green
/ (float)USHRT_MAX
,
2384 (float)foregroundColor
.blue
/ (float)USHRT_MAX
, 1.0);
2385 CGContextFillRect(context
, enclosingCGRect
);
2387 CGContextRestoreGState(context
);
2391 calculateCGDrawingBounds(enclosingCGRect
, &iconCGRect
, &textCGRect
, (imgIndex
!= -1) );
2395 wxImageList
* imageList
= list
->GetImageList(wxIMAGE_LIST_SMALL
);
2396 if (imageList
&& imageList
->GetImageCount() > 0){
2397 wxBitmap bmp
= imageList
->GetBitmap(imgIndex
);
2398 IconRef icon
= bmp
.GetBitmapData()->GetIconRef();
2402 iconLabel
.green
= 0;
2405 CGContextSaveGState(context
);
2406 CGContextTranslateCTM(context
, 0,iconCGRect
.origin
.y
+ CGRectGetMaxY(iconCGRect
));
2407 CGContextScaleCTM(context
,1.0f
,-1.0f
);
2408 PlotIconRefInContext(context
, &iconCGRect
, kAlignNone
,
2409 active
? kTransformNone
: kTransformDisabled
, &iconLabel
,
2410 kPlotIconRefNormalFlags
, icon
);
2412 CGContextRestoreGState(context
);
2416 HIThemeTextHorizontalFlush hFlush
= kHIThemeTextHorizontalFlushLeft
;
2417 UInt16 fontID
= kThemeViewsFont
;
2421 if (font
.GetFamily() != wxFONTFAMILY_DEFAULT
)
2422 fontID
= font
.MacGetThemeFontID();
2424 // FIXME: replace these with CG or ATSUI calls so we can remove this #ifndef.
2426 ::TextSize( (short)(font
.MacGetFontSize()) ) ;
2427 ::TextFace( font
.MacGetFontStyle() ) ;
2432 list
->GetColumn(listColumn
, item
);
2433 if (item
.GetMask() & wxLIST_MASK_FORMAT
)
2435 if (item
.GetAlign() == wxLIST_FORMAT_LEFT
)
2436 hFlush
= kHIThemeTextHorizontalFlushLeft
;
2437 else if (item
.GetAlign() == wxLIST_FORMAT_CENTER
)
2438 hFlush
= kHIThemeTextHorizontalFlushCenter
;
2439 else if (item
.GetAlign() == wxLIST_FORMAT_RIGHT
)
2441 hFlush
= kHIThemeTextHorizontalFlushRight
;
2442 textCGRect
.origin
.x
-= kItemPadding
; // give a little extra paddding
2446 HIThemeTextInfo info
;
2447 info
.version
= kHIThemeTextInfoVersionZero
;
2448 info
.state
= active
? kThemeStateActive
: kThemeStateInactive
;
2449 info
.fontID
= fontID
;
2450 info
.horizontalFlushness
= hFlush
;
2451 info
.verticalFlushness
= kHIThemeTextVerticalFlushCenter
;
2452 info
.options
= kHIThemeTextBoxOptionNone
;
2453 info
.truncationPosition
= kHIThemeTextTruncationEnd
;
2454 info
.truncationMaxLines
= 1;
2456 CGContextSaveGState(context
);
2457 CGContextSetRGBFillColor (context
, (float)labelColor
.red
/ (float)USHRT_MAX
,
2458 (float)labelColor
.green
/ (float)USHRT_MAX
,
2459 (float)labelColor
.blue
/ (float)USHRT_MAX
, 1.0);
2461 HIThemeDrawTextBox(cfString
, &textCGRect
, &info
, context
, kHIThemeOrientationNormal
);
2463 CGContextRestoreGState(context
);
2465 if (savedState
!= NULL
)
2466 SetThemeDrawingState(savedState
, true);
2469 OSStatus
wxMacDataBrowserListCtrlControl::GetSetItemData(DataBrowserItemID itemID
,
2470 DataBrowserPropertyID property
,
2471 DataBrowserItemDataRef itemData
,
2472 Boolean changeValue
)
2476 short listColumn
= property
- kMinColumnId
;
2478 OSStatus err
= errDataBrowserPropertyNotSupported
;
2479 wxListCtrl
* list
= wxDynamicCast( GetPeer() , wxListCtrl
);
2480 wxMacListCtrlItem
* lcItem
;
2482 if (listColumn
>= 0)
2486 lcItem
= (wxMacListCtrlItem
*) itemID
;
2487 if (lcItem
->HasColumnInfo(listColumn
)){
2488 wxListItem
* item
= lcItem
->GetColumnInfo(listColumn
);
2489 if (item
->GetMask() & wxLIST_MASK_TEXT
)
2490 text
= item
->GetText();
2491 if (item
->GetMask() & wxLIST_MASK_IMAGE
)
2492 imgIndex
= item
->GetImage();
2497 text
= list
->OnGetItemText( (long)itemID
-1, listColumn
);
2498 imgIndex
= list
->OnGetItemColumnImage( (long)itemID
-1, listColumn
);
2506 case kDataBrowserItemIsEditableProperty
:
2507 if ( list
&& list
->HasFlag( wxLC_EDIT_LABELS
) )
2509 verify_noerr(SetDataBrowserItemDataBooleanValue( itemData
, true ));
2514 if ( property
>= kMinColumnId
)
2516 wxMacCFStringHolder cfStr
;
2519 cfStr
.Assign( text
, wxLocale::GetSystemEncoding() );
2520 err
= ::SetDataBrowserItemDataText( itemData
, cfStr
);
2526 if ( imgIndex
!= -1 )
2528 wxImageList
* imageList
= list
->GetImageList(wxIMAGE_LIST_SMALL
);
2529 if (imageList
&& imageList
->GetImageCount() > 0){
2530 wxBitmap bmp
= imageList
->GetBitmap(imgIndex
);
2531 IconRef icon
= bmp
.GetBitmapData()->GetIconRef();
2532 ::SetDataBrowserItemDataIcon(itemData
, icon
);
2546 if ( property
>= kMinColumnId
)
2548 short listColumn
= property
- kMinColumnId
;
2550 // TODO probably send the 'end edit' from here, as we
2551 // can then deal with the veto
2553 verify_noerr( GetDataBrowserItemDataText( itemData
, &sr
) ) ;
2554 wxMacCFStringHolder
cfStr(sr
) ;;
2556 list
->SetItem( (long)itemData
-1 , listColumn
, cfStr
.AsString() ) ;
2560 lcItem
->SetColumnTextValue( listColumn
, cfStr
.AsString() );
2570 void wxMacDataBrowserListCtrlControl::ItemNotification(DataBrowserItemID itemID
,
2571 DataBrowserItemNotification message
,
2572 DataBrowserItemDataRef itemData
)
2574 // we want to depend on as little as possible to make sure tear-down of controls is safe
2575 if ( message
== kDataBrowserItemRemoved
)
2577 // make sure MacDelete does the proper teardown.
2580 else if ( message
== kDataBrowserItemAdded
)
2582 // we don't issue events on adding, the item is not really stored in the list yet, so we
2583 // avoid asserts by getting out now
2587 wxListCtrl
*list
= wxDynamicCast( GetPeer() , wxListCtrl
);
2590 bool trigger
= false;
2592 wxListEvent
event( wxEVT_COMMAND_LIST_ITEM_SELECTED
, list
->GetId() );
2593 bool isSingle
= (list
->GetWindowStyle() & wxLC_SINGLE_SEL
) != 0;
2595 event
.SetEventObject( list
);
2596 if ( !list
->IsVirtual() )
2598 DataBrowserTableViewRowIndex result
= 0;
2599 verify_noerr( GetItemRow( itemID
, &result
) ) ;
2600 event
.m_itemIndex
= result
;
2602 if (event
.m_itemIndex
>= 0)
2603 MacGetColumnInfo(event
.m_itemIndex
,0,event
.m_item
);
2607 event
.m_itemIndex
= (long)itemID
;
2612 case kDataBrowserItemDeselected
:
2613 event
.SetEventType(wxEVT_COMMAND_LIST_ITEM_DESELECTED
);
2615 trigger
= !IsSelectionSuppressed();
2618 case kDataBrowserItemSelected
:
2619 trigger
= !IsSelectionSuppressed();
2623 case kDataBrowserItemDoubleClicked
:
2624 event
.SetEventType( wxEVT_COMMAND_LIST_ITEM_ACTIVATED
);
2628 case kDataBrowserEditStarted
:
2629 // TODO : how to veto ?
2630 event
.SetEventType( wxEVT_COMMAND_LIST_BEGIN_LABEL_EDIT
) ;
2634 case kDataBrowserEditStopped
:
2635 // TODO probably trigger only upon the value store callback, because
2636 // here IIRC we cannot veto
2637 event
.SetEventType( wxEVT_COMMAND_LIST_END_LABEL_EDIT
) ;
2647 // direct notification is not always having the listbox GetSelection() having in synch with event
2648 wxPostEvent( list
->GetEventHandler(), event
);
2653 Boolean
wxMacDataBrowserListCtrlControl::CompareItems(DataBrowserItemID itemOneID
,
2654 DataBrowserItemID itemTwoID
,
2655 DataBrowserPropertyID sortProperty
)
2658 bool retval
= false;
2660 wxString otherItemText
;
2661 int colId
= sortProperty
- kMinColumnId
;
2663 long otherItemNum
= 0;
2665 wxListCtrl
* list
= wxDynamicCast( GetPeer() , wxListCtrl
);
2672 wxMacListCtrlItem
* item
= (wxMacListCtrlItem
*)itemOneID
;
2673 wxMacListCtrlItem
* otherItem
= (wxMacListCtrlItem
*)itemTwoID
;
2674 wxListCtrlCompare func
= list
->GetCompareFunc();
2675 if (func
!= NULL
&& item
->HasColumnInfo(colId
) && otherItem
->HasColumnInfo(colId
))
2676 return func(item
->GetColumnInfo(colId
)->GetData(), otherItem
->GetColumnInfo(colId
)->GetData(), list
->GetCompareFuncData()) >= 0;
2678 itemNum
= item
->GetOrder();
2679 otherItemNum
= otherItem
->GetOrder();
2680 if (item
->HasColumnInfo(colId
))
2681 itemText
= item
->GetColumnInfo(colId
)->GetText();
2682 if (otherItem
->HasColumnInfo(colId
))
2683 otherItemText
= otherItem
->GetColumnInfo(colId
)->GetText();
2687 itemNum
= (long)itemOneID
;
2688 otherItemNum
= (long)itemTwoID
;
2689 itemText
= list
->OnGetItemText( itemNum
-1, colId
);
2690 otherItemText
= list
->OnGetItemText( otherItemNum
-1, colId
);
2694 DataBrowserSortOrder sort
;
2695 verify_noerr(GetSortOrder(&sort
));
2697 if ( sort
== kDataBrowserOrderIncreasing
)
2699 retval
= itemText
.CmpNoCase( otherItemText
) > 0;
2701 else if ( sort
== kDataBrowserOrderDecreasing
)
2703 retval
= itemText
.CmpNoCase( otherItemText
) < 0;
2707 // fallback for undefined cases
2708 retval
= itemOneID
< itemTwoID
;
2714 wxMacDataBrowserListCtrlControl::~wxMacDataBrowserListCtrlControl()
2718 void wxMacDataBrowserListCtrlControl::MacSetColumnInfo( unsigned int row
, unsigned int column
, wxListItem
* item
)
2720 wxMacDataItem
* dataItem
= GetItemFromLine(row
);
2723 wxMacListCtrlItem
* listItem
= dynamic_cast<wxMacListCtrlItem
*>(dataItem
);
2724 listItem
->SetColumnInfo( column
, item
);
2725 UpdateState(dataItem
, item
);
2729 // apply changes that need to happen immediately, rather than when the
2730 // databrowser control fires a callback.
2731 void wxMacDataBrowserListCtrlControl::UpdateState(wxMacDataItem
* dataItem
, wxListItem
* listItem
)
2733 bool isSelected
= IsItemSelected( dataItem
);
2734 bool isSelectedState
= (listItem
->GetState() == wxLIST_STATE_SELECTED
);
2736 // toggle the selection state if wxListInfo state and actual state don't match.
2737 if ( isSelected
!= isSelectedState
)
2739 DataBrowserSetOption options
= kDataBrowserItemsAdd
;
2740 if (!isSelectedState
)
2741 options
= kDataBrowserItemsRemove
;
2742 SetSelectedItem(dataItem
, options
);
2744 // TODO: Set column width if item width > than current column width
2747 void wxMacDataBrowserListCtrlControl::MacGetColumnInfo( unsigned int row
, unsigned int column
, wxListItem
& item
)
2749 wxMacDataItem
* dataItem
= GetItemFromLine(row
);
2750 // CS should this guard against dataItem = 0 ? , as item is not a pointer if (item) is not appropriate
2753 wxMacListCtrlItem
* listItem
= dynamic_cast<wxMacListCtrlItem
*>(dataItem
);
2754 wxListItem
* oldItem
= listItem
->GetColumnInfo( column
);
2756 long mask
= item
.GetMask();
2758 // by default, get everything for backwards compatibility
2761 if ( mask
& wxLIST_MASK_TEXT
)
2762 item
.SetText(oldItem
->GetText());
2763 if ( mask
& wxLIST_MASK_IMAGE
)
2764 item
.SetImage(oldItem
->GetImage());
2765 if ( mask
& wxLIST_MASK_DATA
)
2766 item
.SetData(oldItem
->GetData());
2767 if ( mask
& wxLIST_MASK_STATE
)
2768 item
.SetState(oldItem
->GetState());
2769 if ( mask
& wxLIST_MASK_WIDTH
)
2770 item
.SetWidth(oldItem
->GetWidth());
2771 if ( mask
& wxLIST_MASK_FORMAT
)
2772 item
.SetAlign(oldItem
->GetAlign());
2774 item
.SetTextColour(oldItem
->GetTextColour());
2775 item
.SetBackgroundColour(oldItem
->GetBackgroundColour());
2776 item
.SetFont(oldItem
->GetFont());
2780 void wxMacDataBrowserListCtrlControl::MacInsertItem( unsigned int n
, wxListItem
* item
)
2782 wxMacDataItemBrowserControl::MacInsert(n
, item
->GetText());
2783 MacSetColumnInfo(n
, 0, item
);
2786 wxMacDataItem
* wxMacDataBrowserListCtrlControl::CreateItem()
2788 return new wxMacListCtrlItem();
2791 wxMacListCtrlItem::wxMacListCtrlItem()
2793 m_rowItems
= wxListItemList();
2796 int wxMacListCtrlItem::GetColumnImageValue( unsigned int column
)
2798 return GetColumnInfo(column
)->GetImage();
2801 void wxMacListCtrlItem::SetColumnImageValue( unsigned int column
, int imageIndex
)
2803 GetColumnInfo(column
)->SetImage(imageIndex
);
2806 const wxString
& wxMacListCtrlItem::GetColumnTextValue( unsigned int column
)
2811 return GetColumnInfo(column
)->GetText();
2814 void wxMacListCtrlItem::SetColumnTextValue( unsigned int column
, const wxString
& text
)
2816 GetColumnInfo(column
)->SetText(text
);
2818 // for compatibility with superclass APIs
2823 wxListItem
* wxMacListCtrlItem::GetColumnInfo( unsigned int column
)
2825 wxListItemList::compatibility_iterator node
= m_rowItems
.Item( column
);
2826 wxASSERT_MSG( node
, _T("invalid column index in wxMacListCtrlItem") );
2828 return node
->GetData();
2831 bool wxMacListCtrlItem::HasColumnInfo( unsigned int column
)
2833 return m_rowItems
.GetCount() > column
;
2836 void wxMacListCtrlItem::SetColumnInfo( unsigned int column
, wxListItem
* item
)
2839 if ( column
>= m_rowItems
.GetCount() )
2841 wxListItem
* listItem
= new wxListItem(*item
);
2842 m_rowItems
.Append( listItem
);
2846 wxListItem
* listItem
= GetColumnInfo( column
);
2847 long mask
= item
->GetMask();
2848 if (mask
& wxLIST_MASK_TEXT
)
2849 listItem
->SetText(item
->GetText());
2850 if (mask
& wxLIST_MASK_DATA
)
2851 listItem
->SetData(item
->GetData());
2852 if (mask
& wxLIST_MASK_IMAGE
)
2853 listItem
->SetImage(item
->GetImage());
2854 if (mask
& wxLIST_MASK_STATE
)
2855 listItem
->SetState(item
->GetState());
2856 if (mask
& wxLIST_MASK_FORMAT
)
2857 listItem
->SetAlign(item
->GetAlign());
2858 if (mask
& wxLIST_MASK_WIDTH
)
2859 listItem
->SetWidth(item
->GetWidth());
2861 listItem
->SetTextColour(item
->GetTextColour());
2862 listItem
->SetBackgroundColour(item
->GetBackgroundColour());
2863 listItem
->SetFont(item
->GetFont());
2867 #endif // wxUSE_LISTCTRL