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 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;
394 owner
->GetItemRect(itemEdit
, rectLabel
);
396 m_text
->Create(owner
, wxID_ANY
, m_startValue
,
397 wxPoint(rectLabel
.x
+offset
,rectLabel
.y
),
398 wxSize(rectLabel
.width
-offset
,rectLabel
.height
));
401 m_text
->PushEventHandler(this);
404 void wxListCtrlTextCtrlWrapper::Finish()
410 m_text
->RemoveEventHandler(this);
411 m_owner
->FinishEditing(m_text
);
413 wxPendingDelete
.Append( this );
417 bool wxListCtrlTextCtrlWrapper::AcceptChanges()
419 const wxString value
= m_text
->GetValue();
421 if ( value
== m_startValue
)
422 // nothing changed, always accept
425 if ( !m_owner
->OnRenameAccept(m_itemEdited
, value
) )
426 // vetoed by the user
429 // accepted, do rename the item
430 m_owner
->SetItemText(m_itemEdited
, value
);
435 void wxListCtrlTextCtrlWrapper::AcceptChangesAndFinish()
437 m_aboutToFinish
= true;
439 // Notify the owner about the changes
442 // Even if vetoed, close the control (consistent with MSW)
446 void wxListCtrlTextCtrlWrapper::OnChar( wxKeyEvent
&event
)
448 switch ( event
.m_keyCode
)
451 AcceptChangesAndFinish();
455 m_owner
->OnRenameCancelled( m_itemEdited
);
464 void wxListCtrlTextCtrlWrapper::OnKeyUp( wxKeyEvent
&event
)
472 // auto-grow the textctrl:
473 wxSize parentSize
= m_owner
->GetSize();
474 wxPoint myPos
= m_text
->GetPosition();
475 wxSize mySize
= m_text
->GetSize();
477 m_text
->GetTextExtent(m_text
->GetValue() + _T("MM"), &sx
, &sy
);
478 if (myPos
.x
+ sx
> parentSize
.x
)
479 sx
= parentSize
.x
- myPos
.x
;
482 m_text
->SetSize(sx
, wxDefaultCoord
);
487 void wxListCtrlTextCtrlWrapper::OnKillFocus( wxFocusEvent
&event
)
489 if ( !m_finished
&& !m_aboutToFinish
)
491 if ( !AcceptChanges() )
492 m_owner
->OnRenameCancelled( m_itemEdited
);
497 // We must let the native text control handle focus
501 BEGIN_EVENT_TABLE(wxListCtrl
, wxControl
)
502 EVT_LEFT_DOWN(wxListCtrl::OnLeftDown
)
503 EVT_LEFT_DCLICK(wxListCtrl::OnDblClick
)
506 // ============================================================================
508 // ============================================================================
510 wxMacListControl
* wxListCtrl::GetPeer() const
512 return dynamic_cast<wxMacListControl
*>(m_peer
);
515 // ----------------------------------------------------------------------------
516 // wxListCtrl construction
517 // ----------------------------------------------------------------------------
519 void wxListCtrl::Init()
521 m_imageListNormal
= NULL
;
522 m_imageListSmall
= NULL
;
523 m_imageListState
= NULL
;
525 // keep track of if we created our own image lists, or if they were assigned
527 m_ownsImageListNormal
= m_ownsImageListSmall
= m_ownsImageListState
= false;
531 m_genericImpl
= NULL
;
533 m_compareFunc
= NULL
;
534 m_compareFuncData
= 0;
535 m_colsInfo
= wxColumnList();
536 m_textColor
= wxNullColour
;
537 m_bgColor
= wxNullColour
;
538 m_textctrlWrapper
= NULL
;
540 m_renameTimer
= new wxListCtrlRenameTimer( this );
543 class wxGenericListCtrlHook
: public wxGenericListCtrl
546 wxGenericListCtrlHook(wxListCtrl
* parent
,
551 const wxValidator
& validator
,
552 const wxString
& name
)
553 : wxGenericListCtrl(parent
, id
, pos
, size
, style
, validator
, name
),
554 m_nativeListCtrl(parent
)
559 virtual wxListItemAttr
* OnGetItemAttr(long item
) const
561 return m_nativeListCtrl
->OnGetItemAttr(item
);
564 virtual int OnGetItemImage(long item
) const
566 return m_nativeListCtrl
->OnGetItemImage(item
);
569 virtual int OnGetItemColumnImage(long item
, long column
) const
571 return m_nativeListCtrl
->OnGetItemColumnImage(item
, column
);
574 virtual wxString
OnGetItemText(long item
, long column
) const
576 return m_nativeListCtrl
->OnGetItemText(item
, column
);
579 wxListCtrl
* m_nativeListCtrl
;
583 void wxListCtrl::OnLeftDown(wxMouseEvent
& event
)
585 if ( m_textctrlWrapper
)
588 m_textctrlWrapper
->AcceptChangesAndFinish();
592 long current
= HitTest(event
.GetPosition(), hitResult
);
593 if ((current
== m_current
) &&
594 (hitResult
== wxLIST_HITTEST_ONITEM
) &&
595 HasFlag(wxLC_EDIT_LABELS
) )
597 m_renameTimer
->Start( 100, true );
606 void wxListCtrl::OnDblClick(wxMouseEvent
& event
)
612 bool wxListCtrl::Create(wxWindow
*parent
,
617 const wxValidator
& validator
,
618 const wxString
& name
)
621 // for now, we'll always use the generic list control for ICON and LIST views,
622 // because they dynamically change the number of columns on resize.
623 // Also, allow the user to set it to use the list ctrl as well.
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 long paneStyle
= style
;
631 paneStyle
&= ~wxSIMPLE_BORDER
;
632 paneStyle
&= ~wxDOUBLE_BORDER
;
633 paneStyle
&= ~wxSUNKEN_BORDER
;
634 paneStyle
&= ~wxRAISED_BORDER
;
635 paneStyle
&= ~wxSTATIC_BORDER
;
636 if ( !wxWindow::Create(parent
, id
, pos
, size
, paneStyle
| wxNO_BORDER
, name
) )
639 // since the generic control is a child, make sure we position it at 0, 0
640 m_genericImpl
= new wxGenericListCtrlHook(this, id
, wxPoint(0, 0), size
, style
, validator
, name
);
641 m_genericImpl
->PushEventHandler( new wxMacListCtrlEventDelegate( this, GetId() ) );
647 m_macIsUserPane
= false;
649 if ( !wxWindow::Create(parent
, id
, pos
, size
, style
, name
) )
651 m_dbImpl
= new wxMacDataBrowserListCtrlControl( this, pos
, size
, style
);
654 MacPostControlCreate( pos
, size
);
656 InstallControlEventHandler( m_peer
->GetControlRef() , GetwxMacListCtrlEventHandlerUPP(),
657 GetEventTypeCount(eventList
), eventList
, this,
658 (EventHandlerRef
*)&m_macListCtrlEventHandler
);
664 wxListCtrl::~wxListCtrl()
668 m_genericImpl
->PopEventHandler(/* deleteHandler = */ true);
671 if (m_ownsImageListNormal
)
672 delete m_imageListNormal
;
673 if (m_ownsImageListSmall
)
674 delete m_imageListSmall
;
675 if (m_ownsImageListState
)
676 delete m_imageListState
;
678 delete m_renameTimer
;
681 // ----------------------------------------------------------------------------
682 // set/get/change style
683 // ----------------------------------------------------------------------------
685 // Add or remove a single window style
686 void wxListCtrl::SetSingleStyle(long style
, bool add
)
688 long flag
= GetWindowStyleFlag();
690 // Get rid of conflicting styles
693 if ( style
& wxLC_MASK_TYPE
)
694 flag
= flag
& ~wxLC_MASK_TYPE
;
695 if ( style
& wxLC_MASK_ALIGN
)
696 flag
= flag
& ~wxLC_MASK_ALIGN
;
697 if ( style
& wxLC_MASK_SORT
)
698 flag
= flag
& ~wxLC_MASK_SORT
;
706 SetWindowStyleFlag(flag
);
709 // Set the whole window style
710 void wxListCtrl::SetWindowStyleFlag(long flag
)
712 if ( flag
!= m_windowStyle
)
714 m_windowStyle
= flag
;
718 m_genericImpl
->SetWindowStyleFlag(flag
);
725 void wxListCtrl::DoSetSize( int x
, int y
, int width
, int height
, int sizeFlags
)
727 wxControl::DoSetSize(x
, y
, width
, height
, sizeFlags
);
730 m_genericImpl
->SetSize(0, 0, width
, height
, sizeFlags
);
732 // determine if we need a horizontal scrollbar, and add it if so
736 for (int column
= 0; column
< GetColumnCount(); column
++)
738 totalWidth
+= m_dbImpl
->GetColumnWidth( column
);
741 Boolean vertScrollBar
;
742 GetDataBrowserHasScrollBars( m_dbImpl
->GetControlRef(), NULL
, &vertScrollBar
);
743 if (totalWidth
> width
)
744 SetDataBrowserHasScrollBars( m_dbImpl
->GetControlRef(), true, vertScrollBar
);
746 SetDataBrowserHasScrollBars( m_dbImpl
->GetControlRef(), false, vertScrollBar
);
750 wxSize
wxListCtrl::DoGetBestSize() const
752 return wxWindow::DoGetBestSize();
755 bool wxListCtrl::SetFont(const wxFont
& font
)
758 rv
= wxControl::SetFont(font
);
760 rv
= m_genericImpl
->SetFont(font
);
764 bool wxListCtrl::SetForegroundColour(const wxColour
& colour
)
768 rv
= m_genericImpl
->SetForegroundColour(colour
);
770 SetTextColour(colour
);
774 bool wxListCtrl::SetBackgroundColour(const wxColour
& colour
)
778 rv
= m_genericImpl
->SetBackgroundColour(colour
);
784 wxColour
wxListCtrl::GetBackgroundColour()
787 return m_genericImpl
->GetBackgroundColour();
794 // ----------------------------------------------------------------------------
796 // ----------------------------------------------------------------------------
798 // Gets information about this column
799 bool wxListCtrl::GetColumn(int col
, wxListItem
& item
) const
802 return m_genericImpl
->GetColumn(col
, item
);
809 wxColumnList::compatibility_iterator node
= m_colsInfo
.Item( col
);
810 wxASSERT_MSG( node
, _T("invalid column index in wxMacListCtrlItem") );
811 wxListItem
* column
= node
->GetData();
813 long mask
= column
->GetMask();
814 if (mask
& wxLIST_MASK_TEXT
)
815 item
.SetText(column
->GetText());
816 if (mask
& wxLIST_MASK_DATA
)
817 item
.SetData(column
->GetData());
818 if (mask
& wxLIST_MASK_IMAGE
)
819 item
.SetImage(column
->GetImage());
820 if (mask
& wxLIST_MASK_STATE
)
821 item
.SetState(column
->GetState());
822 if (mask
& wxLIST_MASK_FORMAT
)
823 item
.SetAlign(column
->GetAlign());
824 if (mask
& wxLIST_MASK_WIDTH
)
825 item
.SetWidth(column
->GetWidth());
831 // Sets information about this column
832 bool wxListCtrl::SetColumn(int col
, wxListItem
& item
)
835 return m_genericImpl
->SetColumn(col
, item
);
839 long mask
= item
.GetMask();
840 if ( col
>= (int)m_colsInfo
.GetCount() )
842 wxListItem
* listItem
= new wxListItem(item
);
843 m_colsInfo
.Append( listItem
);
848 GetColumn( col
, listItem
);
850 if (mask
& wxLIST_MASK_TEXT
)
851 listItem
.SetText(item
.GetText());
852 if (mask
& wxLIST_MASK_DATA
)
853 listItem
.SetData(item
.GetData());
854 if (mask
& wxLIST_MASK_IMAGE
)
855 listItem
.SetImage(item
.GetImage());
856 if (mask
& wxLIST_MASK_STATE
)
857 listItem
.SetState(item
.GetState());
858 if (mask
& wxLIST_MASK_FORMAT
)
859 listItem
.SetAlign(item
.GetAlign());
860 if (mask
& wxLIST_MASK_WIDTH
)
861 listItem
.SetWidth(item
.GetWidth());
864 // change the appearance in the databrowser.
865 DataBrowserListViewHeaderDesc columnDesc
;
866 columnDesc
.version
=kDataBrowserListViewLatestHeaderDesc
;
867 verify_noerr( m_dbImpl
->GetHeaderDesc( kMinColumnId
+ col
, &columnDesc
) );
870 if (item.GetMask() & wxLIST_MASK_TEXT)
874 enc = m_font.GetEncoding();
876 enc = wxLocale::GetSystemEncoding();
877 wxMacCFStringHolder cfTitle;
878 cfTitle.Assign( item.GetText() , enc );
879 if(columnDesc.titleString)
880 CFRelease(columnDesc.titleString);
881 columnDesc.titleString = cfTitle;
885 if (item
.GetMask() & wxLIST_MASK_IMAGE
&& item
.GetImage() != -1 )
887 columnDesc
.btnContentInfo
.contentType
= kControlContentIconRef
;
888 wxImageList
* imageList
= GetImageList(wxIMAGE_LIST_SMALL
);
889 if (imageList
&& imageList
->GetImageCount() > 0 )
891 wxBitmap bmp
= imageList
->GetBitmap( item
.GetImage() );
892 IconRef icon
= bmp
.GetBitmapData()->GetIconRef();
893 columnDesc
.btnContentInfo
.u
.iconRef
= icon
;
897 verify_noerr( m_dbImpl
->SetHeaderDesc( kMinColumnId
+ col
, &columnDesc
) );
903 int wxListCtrl::GetColumnCount() const
906 return m_genericImpl
->GetColumnCount();
911 m_dbImpl
->GetColumnCount(&count
);
918 // Gets the column width
919 int wxListCtrl::GetColumnWidth(int col
) const
922 return m_genericImpl
->GetColumnWidth(col
);
926 return m_dbImpl
->GetColumnWidth(col
);
932 // Sets the column width
933 bool wxListCtrl::SetColumnWidth(int col
, int width
)
936 return m_genericImpl
->SetColumnWidth(col
, width
);
941 if (width
== wxLIST_AUTOSIZE
|| width
== wxLIST_AUTOSIZE_USEHEADER
)
946 for (int column
= 0; column
< GetColumnCount(); column
++)
949 GetColumn(col
, colInfo
);
951 colInfo
.SetWidth(width
);
952 SetColumn(col
, colInfo
);
954 m_dbImpl
->SetColumnWidth(col
, mywidth
);
960 GetColumn(col
, colInfo
);
962 colInfo
.SetWidth(width
);
963 SetColumn(col
, colInfo
);
964 m_dbImpl
->SetColumnWidth(col
, mywidth
);
972 // Gets the number of items that can fit vertically in the
973 // visible area of the list control (list or report view)
974 // or the total number of items in the list control (icon
975 // or small icon view)
976 int wxListCtrl::GetCountPerPage() const
979 return m_genericImpl
->GetCountPerPage();
988 // Gets the edit control for editing labels.
989 wxTextCtrl
* wxListCtrl::GetEditControl() const
992 return m_genericImpl
->GetEditControl();
997 // Gets information about the item
998 bool wxListCtrl::GetItem(wxListItem
& info
) const
1001 return m_genericImpl
->GetItem(info
);
1006 m_dbImpl
->MacGetColumnInfo(info
.m_itemId
, info
.m_col
, info
);
1009 info
.SetText( OnGetItemText(info
.m_itemId
, info
.m_col
) );
1010 info
.SetImage( OnGetItemColumnImage(info
.m_itemId
, info
.m_col
) );
1011 wxListItemAttr
* attrs
= OnGetItemAttr( info
.m_itemId
);
1014 info
.SetFont( attrs
->GetFont() );
1015 info
.SetBackgroundColour( attrs
->GetBackgroundColour() );
1016 info
.SetTextColour( attrs
->GetTextColour() );
1020 bool success
= true;
1024 // Sets information about the item
1025 bool wxListCtrl::SetItem(wxListItem
& info
)
1028 return m_genericImpl
->SetItem(info
);
1031 m_dbImpl
->MacSetColumnInfo( info
.m_itemId
, info
.m_col
, &info
);
1036 long wxListCtrl::SetItem(long index
, int col
, const wxString
& label
, int imageId
)
1039 return m_genericImpl
->SetItem(index
, col
, label
, imageId
);
1042 info
.m_text
= label
;
1043 info
.m_mask
= wxLIST_MASK_TEXT
;
1044 info
.m_itemId
= index
;
1048 info
.m_image
= imageId
;
1049 info
.m_mask
|= wxLIST_MASK_IMAGE
;
1051 return SetItem(info
);
1055 // Gets the item state
1056 int wxListCtrl::GetItemState(long item
, long stateMask
) const
1059 return m_genericImpl
->GetItemState(item
, stateMask
);
1063 info
.m_mask
= wxLIST_MASK_STATE
;
1064 info
.m_stateMask
= stateMask
;
1065 info
.m_itemId
= item
;
1070 return info
.m_state
;
1073 // Sets the item state
1074 bool wxListCtrl::SetItemState(long item
, long state
, long stateMask
)
1077 return m_genericImpl
->SetItemState(item
, state
, stateMask
);
1080 info
.m_itemId
= item
;
1081 info
.m_mask
= wxLIST_MASK_STATE
;
1082 info
.m_stateMask
= stateMask
;
1083 info
.m_state
= state
;
1084 return SetItem(info
);
1087 // Sets the item image
1088 bool wxListCtrl::SetItemImage(long item
, int image
, int WXUNUSED(selImage
))
1090 return SetItemColumnImage(item
, 0, image
);
1093 // Sets the item image
1094 bool wxListCtrl::SetItemColumnImage(long item
, long column
, int image
)
1097 return m_genericImpl
->SetItemColumnImage(item
, column
, image
);
1101 info
.m_mask
= wxLIST_MASK_IMAGE
;
1102 info
.m_image
= image
;
1103 info
.m_itemId
= item
;
1104 info
.m_col
= column
;
1106 return SetItem(info
);
1109 // Gets the item text
1110 wxString
wxListCtrl::GetItemText(long item
) const
1113 return m_genericImpl
->GetItemText(item
);
1117 info
.m_mask
= wxLIST_MASK_TEXT
;
1118 info
.m_itemId
= item
;
1121 return wxEmptyString
;
1125 // Sets the item text
1126 void wxListCtrl::SetItemText(long item
, const wxString
& str
)
1129 return m_genericImpl
->SetItemText(item
, str
);
1133 info
.m_mask
= wxLIST_MASK_TEXT
;
1134 info
.m_itemId
= item
;
1140 // Gets the item data
1141 long wxListCtrl::GetItemData(long item
) const
1144 return m_genericImpl
->GetItemData(item
);
1148 info
.m_mask
= wxLIST_MASK_DATA
;
1149 info
.m_itemId
= item
;
1156 // Sets the item data
1157 bool wxListCtrl::SetItemData(long item
, long data
)
1160 return m_genericImpl
->SetItemData(item
, data
);
1164 info
.m_mask
= wxLIST_MASK_DATA
;
1165 info
.m_itemId
= item
;
1168 return SetItem(info
);
1171 wxRect
wxListCtrl::GetViewRect() const
1173 wxASSERT_MSG( !HasFlag(wxLC_REPORT
| wxLC_LIST
),
1174 _T("wxListCtrl::GetViewRect() only works in icon mode") );
1177 return m_genericImpl
->GetViewRect();
1183 // Gets the item rectangle
1184 bool wxListCtrl::GetItemRect(long item
, wxRect
& rect
, int code
) const
1187 return m_genericImpl
->GetItemRect(item
, rect
, code
);
1192 DataBrowserItemID id
;
1193 DataBrowserPropertyID col
= kMinColumnId
;
1195 DataBrowserPropertyPart part
= kDataBrowserPropertyEnclosingPart
;
1196 if ( code
== wxLIST_RECT_LABEL
)
1197 part
= kDataBrowserPropertyTextPart
;
1198 else if ( code
== wxLIST_RECT_ICON
)
1199 part
= kDataBrowserPropertyIconPart
;
1201 if ( !(GetWindowStyleFlag() & wxLC_VIRTUAL
) )
1203 wxMacDataItem
* thisItem
= m_dbImpl
->GetItemFromLine(item
);
1204 id
= (DataBrowserItemID
) thisItem
;
1209 GetDataBrowserItemPartBounds( m_dbImpl
->GetControlRef(), id
, col
, part
, &bounds
);
1211 rect
.x
= bounds
.left
;
1212 rect
.y
= bounds
.top
;
1213 rect
.width
= bounds
.right
- bounds
.left
; //GetClientSize().x; // we need the width of the whole row, not just the item.
1214 rect
.height
= bounds
.bottom
- bounds
.top
;
1215 //fprintf("id = %d, bounds = %d, %d, %d, %d\n", id, rect.x, rect.y, rect.width, rect.height);
1220 // Gets the item position
1221 bool wxListCtrl::GetItemPosition(long item
, wxPoint
& pos
) const
1224 return m_genericImpl
->GetItemPosition(item
, pos
);
1226 bool success
= false;
1231 GetItemRect(item
, itemRect
);
1232 pos
= itemRect
.GetPosition();
1239 // Sets the item position.
1240 bool wxListCtrl::SetItemPosition(long item
, const wxPoint
& pos
)
1243 return m_genericImpl
->SetItemPosition(item
, pos
);
1248 // Gets the number of items in the list control
1249 int wxListCtrl::GetItemCount() const
1252 return m_genericImpl
->GetItemCount();
1255 return m_dbImpl
->MacGetCount();
1260 void wxListCtrl::SetItemSpacing( int spacing
, bool isSmall
)
1263 m_genericImpl
->SetItemSpacing(spacing
, isSmall
);
1266 wxSize
wxListCtrl::GetItemSpacing() const
1269 return m_genericImpl
->GetItemSpacing();
1271 return wxSize(0, 0);
1274 void wxListCtrl::SetItemTextColour( long item
, const wxColour
&col
)
1278 m_genericImpl
->SetItemTextColour(item
, col
);
1283 info
.m_itemId
= item
;
1284 info
.SetTextColour( col
);
1288 wxColour
wxListCtrl::GetItemTextColour( long item
) const
1291 return m_genericImpl
->GetItemTextColour(item
);
1297 return info
.GetTextColour();
1299 return wxNullColour
;
1302 void wxListCtrl::SetItemBackgroundColour( long item
, const wxColour
&col
)
1306 m_genericImpl
->SetItemBackgroundColour(item
, col
);
1311 info
.m_itemId
= item
;
1312 info
.SetBackgroundColour( col
);
1316 wxColour
wxListCtrl::GetItemBackgroundColour( long item
) const
1319 return m_genericImpl
->GetItemBackgroundColour(item
);
1325 return info
.GetBackgroundColour();
1327 return wxNullColour
;
1330 void wxListCtrl::SetItemFont( long item
, const wxFont
&f
)
1334 m_genericImpl
->SetItemFont(item
, f
);
1339 info
.m_itemId
= item
;
1344 wxFont
wxListCtrl::GetItemFont( long item
) const
1347 return m_genericImpl
->GetItemFont(item
);
1353 return info
.GetFont();
1359 // Gets the number of selected items in the list control
1360 int wxListCtrl::GetSelectedItemCount() const
1363 return m_genericImpl
->GetSelectedItemCount();
1366 return m_dbImpl
->GetSelectedItemCount(NULL
, true);
1371 // Gets the text colour of the listview
1372 wxColour
wxListCtrl::GetTextColour() const
1375 return m_genericImpl
->GetTextColour();
1377 // TODO: we need owner drawn list items to customize text color.
1381 return wxNullColour
;
1384 // Sets the text colour of the listview
1385 void wxListCtrl::SetTextColour(const wxColour
& col
)
1389 m_genericImpl
->SetTextColour(col
);
1397 // Gets the index of the topmost visible item when in
1398 // list or report view
1399 long wxListCtrl::GetTopItem() const
1402 return m_genericImpl
->GetTopItem();
1407 // Searches for an item, starting from 'item'.
1408 // 'geometry' is one of
1409 // wxLIST_NEXT_ABOVE/ALL/BELOW/LEFT/RIGHT.
1410 // 'state' is a state bit flag, one or more of
1411 // wxLIST_STATE_DROPHILITED/FOCUSED/SELECTED/CUT.
1412 // item can be -1 to find the first item that matches the
1414 // Returns the item or -1 if unsuccessful.
1415 long wxListCtrl::GetNextItem(long item
, int geom
, int state
) const
1418 return m_genericImpl
->GetNextItem(item
, geom
, state
);
1420 if (m_dbImpl
&& geom
== wxLIST_NEXT_ALL
&& state
== wxLIST_STATE_SELECTED
)
1422 long count
= m_dbImpl
->MacGetCount() ;
1423 for ( long line
= item
+ 1 ; line
< count
; line
++ )
1425 wxMacDataItem
* id
= m_dbImpl
->GetItemFromLine(line
);
1426 if ( m_dbImpl
->IsItemSelected(id
) )
1436 wxImageList
*wxListCtrl::GetImageList(int which
) const
1439 return m_genericImpl
->GetImageList(which
);
1441 if ( which
== wxIMAGE_LIST_NORMAL
)
1443 return m_imageListNormal
;
1445 else if ( which
== wxIMAGE_LIST_SMALL
)
1447 return m_imageListSmall
;
1449 else if ( which
== wxIMAGE_LIST_STATE
)
1451 return m_imageListState
;
1456 void wxListCtrl::SetImageList(wxImageList
*imageList
, int which
)
1460 m_genericImpl
->SetImageList(imageList
, which
);
1464 if ( which
== wxIMAGE_LIST_NORMAL
)
1466 if (m_ownsImageListNormal
) delete m_imageListNormal
;
1467 m_imageListNormal
= imageList
;
1468 m_ownsImageListNormal
= false;
1470 else if ( which
== wxIMAGE_LIST_SMALL
)
1472 if (m_ownsImageListSmall
) delete m_imageListSmall
;
1473 m_imageListSmall
= imageList
;
1474 m_ownsImageListSmall
= false;
1476 else if ( which
== wxIMAGE_LIST_STATE
)
1478 if (m_ownsImageListState
) delete m_imageListState
;
1479 m_imageListState
= imageList
;
1480 m_ownsImageListState
= false;
1484 void wxListCtrl::AssignImageList(wxImageList
*imageList
, int which
)
1488 m_genericImpl
->AssignImageList(imageList
, which
);
1492 SetImageList(imageList
, which
);
1493 if ( which
== wxIMAGE_LIST_NORMAL
)
1494 m_ownsImageListNormal
= true;
1495 else if ( which
== wxIMAGE_LIST_SMALL
)
1496 m_ownsImageListSmall
= true;
1497 else if ( which
== wxIMAGE_LIST_STATE
)
1498 m_ownsImageListState
= true;
1501 // ----------------------------------------------------------------------------
1503 // ----------------------------------------------------------------------------
1505 // Arranges the items
1506 bool wxListCtrl::Arrange(int flag
)
1509 return m_genericImpl
->Arrange(flag
);
1514 bool wxListCtrl::DeleteItem(long item
)
1517 return m_genericImpl
->DeleteItem(item
);
1521 m_dbImpl
->MacDelete(item
);
1522 wxListEvent
event( wxEVT_COMMAND_LIST_DELETE_ITEM
, GetId() );
1523 event
.SetEventObject( this );
1524 event
.m_itemIndex
= item
;
1525 GetEventHandler()->ProcessEvent( event
);
1531 // Deletes all items
1532 bool wxListCtrl::DeleteAllItems()
1535 return m_genericImpl
->DeleteAllItems();
1539 m_dbImpl
->MacClear();
1540 wxListEvent
event( wxEVT_COMMAND_LIST_DELETE_ALL_ITEMS
, GetId() );
1541 event
.SetEventObject( this );
1542 GetEventHandler()->ProcessEvent( event
);
1547 // Deletes all items
1548 bool wxListCtrl::DeleteAllColumns()
1551 return m_genericImpl
->DeleteAllColumns();
1556 m_dbImpl
->GetColumnCount(&cols
);
1557 for (UInt32 col
= 0; col
< cols
; col
++)
1567 bool wxListCtrl::DeleteColumn(int col
)
1570 return m_genericImpl
->DeleteColumn(col
);
1574 OSStatus err
= m_dbImpl
->RemoveColumn(col
);
1575 return err
== noErr
;
1581 // Clears items, and columns if there are any.
1582 void wxListCtrl::ClearAll()
1586 m_genericImpl
->ClearAll();
1597 wxTextCtrl
* wxListCtrl::EditLabel(long item
, wxClassInfo
* textControlClass
)
1600 return m_genericImpl
->EditLabel(item
, textControlClass
);
1604 wxCHECK_MSG( (item
>= 0) && ((long)item
< GetItemCount()), NULL
,
1605 wxT("wrong index in wxListCtrl::EditLabel()") );
1607 wxASSERT_MSG( textControlClass
->IsKindOf(CLASSINFO(wxTextCtrl
)),
1608 wxT("EditLabel() needs a text control") );
1610 wxListEvent
le( wxEVT_COMMAND_LIST_BEGIN_LABEL_EDIT
, GetParent()->GetId() );
1611 le
.SetEventObject( this );
1612 le
.m_itemIndex
= item
;
1614 GetItem( le
.m_item
);
1616 if ( GetParent()->GetEventHandler()->ProcessEvent( le
) && !le
.IsAllowed() )
1618 // vetoed by user code
1622 wxTextCtrl
* const text
= (wxTextCtrl
*)textControlClass
->CreateObject();
1623 m_textctrlWrapper
= new wxListCtrlTextCtrlWrapper(this, text
, item
);
1624 return m_textctrlWrapper
->GetText();
1629 // End label editing, optionally cancelling the edit
1630 bool wxListCtrl::EndEditLabel(bool cancel
)
1632 // TODO: generic impl. doesn't have this method - is it needed for us?
1634 return true; // m_genericImpl->EndEditLabel(cancel);
1637 verify_noerr( SetDataBrowserEditItem(m_dbImpl
->GetControlRef(), kDataBrowserNoItem
, kMinColumnId
) );
1641 // Ensures this item is visible
1642 bool wxListCtrl::EnsureVisible(long item
)
1645 return m_genericImpl
->EnsureVisible(item
);
1649 wxMacDataItem
* dataItem
= m_dbImpl
->GetItemFromLine(item
);
1650 m_dbImpl
->RevealItem(dataItem
, kDataBrowserRevealWithoutSelecting
);
1656 // Find an item whose label matches this string, starting from the item after 'start'
1657 // or the beginning if 'start' is -1.
1658 long wxListCtrl::FindItem(long start
, const wxString
& str
, bool partial
)
1661 return m_genericImpl
->FindItem(start
, str
, partial
);
1666 // Find an item whose data matches this data, starting from the item after 'start'
1667 // or the beginning if 'start' is -1.
1668 long wxListCtrl::FindItem(long start
, long data
)
1671 return m_genericImpl
->FindItem(start
, data
);
1673 long idx
= start
+ 1;
1674 long count
= GetItemCount();
1678 if (GetItemData(idx
) == data
)
1686 // Find an item nearest this position in the specified direction, starting from
1687 // the item after 'start' or the beginning if 'start' is -1.
1688 long wxListCtrl::FindItem(long start
, const wxPoint
& pt
, int direction
)
1691 return m_genericImpl
->FindItem(start
, pt
, direction
);
1695 // Determines which item (if any) is at the specified point,
1696 // giving details in 'flags' (see wxLIST_HITTEST_... flags above)
1698 wxListCtrl::HitTest(const wxPoint
& point
, int& flags
, long *ptrSubItem
) const
1701 return m_genericImpl
->HitTest(point
, flags
, ptrSubItem
);
1703 flags
= wxLIST_HITTEST_NOWHERE
;
1706 int colHeaderHeight
= 22; // TODO: Find a way to get this value from the db control?
1707 UInt16 rowHeight
= 0;
1708 m_dbImpl
->GetDefaultRowHeight(&rowHeight
);
1711 // get the actual row by taking scroll position into account
1712 UInt32 offsetX
, offsetY
;
1713 m_dbImpl
->GetScrollPosition( &offsetY
, &offsetX
);
1716 if ( !(GetWindowStyleFlag() & wxLC_NO_HEADER
) )
1717 y
-= colHeaderHeight
;
1722 int row
= y
/ rowHeight
;
1723 DataBrowserItemID id
;
1724 m_dbImpl
->GetItemID( (DataBrowserTableViewRowIndex
) row
, &id
);
1726 // TODO: Use GetDataBrowserItemPartBounds to return if we are in icon or label
1727 if ( !(GetWindowStyleFlag() & wxLC_VIRTUAL
) )
1729 wxMacListCtrlItem
* lcItem
;
1730 lcItem
= (wxMacListCtrlItem
*) id
;
1733 flags
= wxLIST_HITTEST_ONITEM
;
1739 if (row
< GetItemCount() )
1741 flags
= wxLIST_HITTEST_ONITEM
;
1751 // Inserts an item, returning the index of the new item if successful,
1753 long wxListCtrl::InsertItem(wxListItem
& info
)
1755 wxASSERT_MSG( !IsVirtual(), _T("can't be used with virtual controls") );
1758 return m_genericImpl
->InsertItem(info
);
1762 int count
= GetItemCount();
1764 if (info
.m_itemId
> count
)
1765 info
.m_itemId
= count
;
1767 m_dbImpl
->MacInsertItem(info
.m_itemId
, &info
);
1768 wxListEvent
event( wxEVT_COMMAND_LIST_INSERT_ITEM
, GetId() );
1769 event
.SetEventObject( this );
1770 event
.m_itemIndex
= info
.m_itemId
;
1771 GetEventHandler()->ProcessEvent( event
);
1774 return info
.m_itemId
;
1777 long wxListCtrl::InsertItem(long index
, const wxString
& label
)
1780 return m_genericImpl
->InsertItem(index
, label
);
1783 info
.m_text
= label
;
1784 info
.m_mask
= wxLIST_MASK_TEXT
;
1785 info
.m_itemId
= index
;
1786 return InsertItem(info
);
1789 // Inserts an image item
1790 long wxListCtrl::InsertItem(long index
, int imageIndex
)
1793 return m_genericImpl
->InsertItem(index
, imageIndex
);
1796 info
.m_image
= imageIndex
;
1797 info
.m_mask
= wxLIST_MASK_IMAGE
;
1798 info
.m_itemId
= index
;
1799 return InsertItem(info
);
1802 // Inserts an image/string item
1803 long wxListCtrl::InsertItem(long index
, const wxString
& label
, int imageIndex
)
1806 return m_genericImpl
->InsertItem(index
, label
, imageIndex
);
1809 info
.m_image
= imageIndex
;
1810 info
.m_text
= label
;
1811 info
.m_mask
= wxLIST_MASK_IMAGE
| wxLIST_MASK_TEXT
;
1812 info
.m_itemId
= index
;
1813 return InsertItem(info
);
1816 // For list view mode (only), inserts a column.
1817 long wxListCtrl::InsertColumn(long col
, wxListItem
& item
)
1820 return m_genericImpl
->InsertColumn(col
, item
);
1824 int width
= item
.GetWidth();
1825 if ( !(item
.GetMask() & wxLIST_MASK_WIDTH
) )
1828 DataBrowserPropertyType type
= kDataBrowserCustomType
; //kDataBrowserTextType;
1829 wxImageList
* imageList
= GetImageList(wxIMAGE_LIST_SMALL
);
1830 if (imageList
&& imageList
->GetImageCount() > 0)
1832 wxBitmap bmp
= imageList
->GetBitmap(0);
1834 // type = kDataBrowserIconAndTextType;
1837 SInt16 just
= teFlushDefault
;
1838 if (item
.GetMask() & wxLIST_MASK_FORMAT
)
1840 if (item
.GetAlign() == wxLIST_FORMAT_LEFT
)
1842 else if (item
.GetAlign() == wxLIST_FORMAT_CENTER
)
1844 else if (item
.GetAlign() == wxLIST_FORMAT_RIGHT
)
1845 just
= teFlushRight
;
1847 m_dbImpl
->InsertColumn(col
, type
, item
.GetText(), just
, width
);
1848 SetColumn(col
, item
);
1850 // set/remove options based on the wxListCtrl type.
1851 DataBrowserTableViewColumnID id
;
1852 m_dbImpl
->GetColumnIDFromIndex(col
, &id
);
1853 DataBrowserPropertyFlags flags
;
1854 verify_noerr(m_dbImpl
->GetPropertyFlags(id
, &flags
));
1855 if (GetWindowStyleFlag() & wxLC_EDIT_LABELS
)
1856 flags
|= kDataBrowserPropertyIsEditable
;
1858 if (GetWindowStyleFlag() & wxLC_VIRTUAL
){
1859 flags
&= ~kDataBrowserListViewSortableColumn
;
1861 verify_noerr(m_dbImpl
->SetPropertyFlags(id
, flags
));
1867 long wxListCtrl::InsertColumn(long col
,
1868 const wxString
& heading
,
1873 return m_genericImpl
->InsertColumn(col
, heading
, format
, width
);
1876 item
.m_mask
= wxLIST_MASK_TEXT
| wxLIST_MASK_FORMAT
;
1877 item
.m_text
= heading
;
1880 item
.m_mask
|= wxLIST_MASK_WIDTH
;
1881 item
.m_width
= width
;
1883 item
.m_format
= format
;
1885 return InsertColumn(col
, item
);
1888 // scroll the control by the given number of pixels (exception: in list view,
1889 // dx is interpreted as number of columns)
1890 bool wxListCtrl::ScrollList(int dx
, int dy
)
1893 return m_genericImpl
->ScrollList(dx
, dy
);
1897 m_dbImpl
->SetScrollPosition(dx
, dy
);
1903 bool wxListCtrl::SortItems(wxListCtrlCompare fn
, long data
)
1906 return m_genericImpl
->SortItems(fn
, data
);
1911 m_compareFuncData
= data
;
1917 void wxListCtrl::OnRenameTimer()
1919 wxCHECK_RET( HasCurrent(), wxT("unexpected rename timer") );
1921 EditLabel( m_current
);
1924 bool wxListCtrl::OnRenameAccept(long itemEdit
, const wxString
& value
)
1926 wxListEvent
le( wxEVT_COMMAND_LIST_END_LABEL_EDIT
, GetId() );
1927 le
.SetEventObject( this );
1928 le
.m_itemIndex
= itemEdit
;
1930 GetItem( le
.m_item
);
1931 le
.m_item
.m_text
= value
;
1932 return !GetEventHandler()->ProcessEvent( le
) ||
1936 void wxListCtrl::OnRenameCancelled(long itemEdit
)
1938 // let owner know that the edit was cancelled
1939 wxListEvent
le( wxEVT_COMMAND_LIST_END_LABEL_EDIT
, GetParent()->GetId() );
1941 le
.SetEditCanceled(true);
1943 le
.SetEventObject( this );
1944 le
.m_itemIndex
= itemEdit
;
1946 GetItem( le
.m_item
);
1947 GetEventHandler()->ProcessEvent( le
);
1950 // ----------------------------------------------------------------------------
1951 // virtual list controls
1952 // ----------------------------------------------------------------------------
1954 wxString
wxListCtrl::OnGetItemText(long WXUNUSED(item
), long WXUNUSED(col
)) const
1956 // this is a pure virtual function, in fact - which is not really pure
1957 // because the controls which are not virtual don't need to implement it
1958 wxFAIL_MSG( _T("wxListCtrl::OnGetItemText not supposed to be called") );
1960 return wxEmptyString
;
1963 int wxListCtrl::OnGetItemImage(long WXUNUSED(item
)) const
1965 wxCHECK_MSG(!GetImageList(wxIMAGE_LIST_SMALL
),
1967 wxT("List control has an image list, OnGetItemImage or OnGetItemColumnImage should be overridden."));
1971 int wxListCtrl::OnGetItemColumnImage(long item
, long column
) const
1974 return OnGetItemImage(item
);
1979 wxListItemAttr
*wxListCtrl::OnGetItemAttr(long WXUNUSED_UNLESS_DEBUG(item
)) const
1981 wxASSERT_MSG( item
>= 0 && item
< GetItemCount(),
1982 _T("invalid item index in OnGetItemAttr()") );
1984 // no attributes by default
1988 void wxListCtrl::SetItemCount(long count
)
1990 wxASSERT_MSG( IsVirtual(), _T("this is for virtual controls only") );
1994 m_genericImpl
->SetItemCount(count
);
2000 // we need to temporarily disable the new item creation notification
2001 // procedure to speed things up
2002 // FIXME: Even this doesn't seem to help much...
2003 DataBrowserCallbacks callbacks
;
2004 DataBrowserItemNotificationUPP itemUPP
;
2005 GetDataBrowserCallbacks(m_dbImpl
->GetControlRef(), &callbacks
);
2006 itemUPP
= callbacks
.u
.v1
.itemNotificationCallback
;
2007 callbacks
.u
.v1
.itemNotificationCallback
= 0;
2008 m_dbImpl
->SetCallbacks(&callbacks
);
2009 ::AddDataBrowserItems(m_dbImpl
->GetControlRef(), kDataBrowserNoItem
,
2010 count
, NULL
, kDataBrowserItemNoProperty
);
2011 callbacks
.u
.v1
.itemNotificationCallback
= itemUPP
;
2012 m_dbImpl
->SetCallbacks(&callbacks
);
2017 void wxListCtrl::RefreshItem(long item
)
2021 m_genericImpl
->RefreshItem(item
);
2026 GetItemRect(item
, rect
);
2030 void wxListCtrl::RefreshItems(long itemFrom
, long itemTo
)
2034 m_genericImpl
->RefreshItems(itemFrom
, itemTo
);
2038 wxRect rect1
, rect2
;
2039 GetItemRect(itemFrom
, rect1
);
2040 GetItemRect(itemTo
, rect2
);
2042 wxRect rect
= rect1
;
2043 rect
.height
= rect2
.GetBottom() - rect1
.GetTop();
2049 // wxMac internal data structures
2051 wxMacListCtrlItem::~wxMacListCtrlItem()
2055 void wxMacListCtrlItem::Notification(wxMacDataItemBrowserControl
*owner
,
2056 DataBrowserItemNotification message
,
2057 DataBrowserItemDataRef itemData
) const
2060 wxMacDataBrowserListCtrlControl
*lb
= dynamic_cast<wxMacDataBrowserListCtrlControl
*>(owner
);
2062 // we want to depend on as little as possible to make sure tear-down of controls is safe
2063 if ( message
== kDataBrowserItemRemoved
)
2065 if ( lb
!= NULL
&& lb
->GetClientDataType() == wxClientData_Object
)
2067 delete (wxClientData
*) (m_data
);
2073 else if ( message
== kDataBrowserItemAdded
)
2075 // we don't issue events on adding, the item is not really stored in the list yet, so we
2076 // avoid asserts by gettting out now
2080 wxListCtrl
*list
= wxDynamicCast( owner
->GetPeer() , wxListCtrl
);
2083 bool trigger
= false;
2085 wxListEvent
event( wxEVT_COMMAND_LIST_ITEM_SELECTED
, list
->GetId() );
2086 bool isSingle
= (list
->GetWindowStyle() & wxLC_SINGLE_SEL
) != 0;
2088 event
.SetEventObject( list
);
2089 event
.m_itemIndex
= owner
->GetLineFromItem( this ) ;
2090 if ( !list
->IsVirtual() )
2092 lb
->MacGetColumnInfo(event
.m_itemIndex
,0,event
.m_item
);
2097 case kDataBrowserItemDeselected
:
2098 event
.SetEventType(wxEVT_COMMAND_LIST_ITEM_DESELECTED
);
2100 trigger
= !lb
->IsSelectionSuppressed();
2103 case kDataBrowserItemSelected
:
2104 trigger
= !lb
->IsSelectionSuppressed();
2107 case kDataBrowserItemDoubleClicked
:
2108 event
.SetEventType( wxEVT_COMMAND_LIST_ITEM_ACTIVATED
);
2112 case kDataBrowserEditStarted
:
2113 // TODO : how to veto ?
2114 event
.SetEventType( wxEVT_COMMAND_LIST_BEGIN_LABEL_EDIT
) ;
2118 case kDataBrowserEditStopped
:
2119 // TODO probably trigger only upon the value store callback, because
2120 // here IIRC we cannot veto
2121 event
.SetEventType( wxEVT_COMMAND_LIST_END_LABEL_EDIT
) ;
2131 // direct notification is not always having the listbox GetSelection() having in synch with event
2132 wxPostEvent( list
->GetEventHandler(), event
);
2138 wxMacDataBrowserListCtrlControl::wxMacDataBrowserListCtrlControl( wxWindow
*peer
, const wxPoint
& pos
, const wxSize
& size
, long style
)
2139 : wxMacDataItemBrowserControl( peer
, pos
, size
, style
)
2141 OSStatus err
= noErr
;
2142 m_clientDataItemsType
= wxClientData_None
;
2143 m_isVirtual
= false;
2145 if ( style
& wxLC_VIRTUAL
)
2148 DataBrowserSelectionFlags options
= kDataBrowserDragSelect
;
2149 if ( style
& wxLC_SINGLE_SEL
)
2151 options
|= kDataBrowserSelectOnlyOne
;
2155 options
|= kDataBrowserCmdTogglesSelection
;
2158 err
= SetSelectionFlags( options
);
2159 verify_noerr( err
);
2161 DataBrowserCustomCallbacks callbacks
;
2162 InitializeDataBrowserCustomCallbacks( &callbacks
, kDataBrowserLatestCustomCallbacks
);
2164 if ( gDataBrowserDrawItemUPP
== NULL
)
2165 gDataBrowserDrawItemUPP
= NewDataBrowserDrawItemUPP(DataBrowserDrawItemProc
);
2167 if ( gDataBrowserHitTestUPP
== NULL
)
2168 gDataBrowserHitTestUPP
= NewDataBrowserHitTestUPP(DataBrowserHitTestProc
);
2170 callbacks
.u
.v1
.drawItemCallback
= gDataBrowserDrawItemUPP
;
2171 callbacks
.u
.v1
.hitTestCallback
= gDataBrowserHitTestUPP
;
2173 SetDataBrowserCustomCallbacks( GetControlRef(), &callbacks
);
2175 if ( style
& wxLC_LIST
)
2177 InsertColumn(0, kDataBrowserIconAndTextType
, wxEmptyString
, -1, -1);
2178 verify_noerr( AutoSizeColumns() );
2181 if ( style
& wxLC_LIST
|| style
& wxLC_NO_HEADER
)
2182 verify_noerr( SetHeaderButtonHeight( 0 ) );
2185 SetSortProperty( kMinColumnId
- 1 );
2187 SetSortProperty( kMinColumnId
);
2188 if ( style
& wxLC_SORT_ASCENDING
)
2190 m_sortOrder
= SortOrder_Text_Ascending
;
2191 SetSortOrder( kDataBrowserOrderIncreasing
);
2193 else if ( style
& wxLC_SORT_DESCENDING
)
2195 m_sortOrder
= SortOrder_Text_Descending
;
2196 SetSortOrder( kDataBrowserOrderDecreasing
);
2200 m_sortOrder
= SortOrder_None
;
2203 if ( style
& wxLC_VRULES
)
2205 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4
2206 verify_noerr( DataBrowserChangeAttributes(m_controlRef
, kDataBrowserAttributeListViewDrawColumnDividers
, kDataBrowserAttributeNone
) );
2210 verify_noerr( SetHiliteStyle(kDataBrowserTableViewFillHilite
) );
2211 err
= SetHasScrollBars( (style
& wxHSCROLL
) != 0 , true );
2214 pascal Boolean
wxMacDataBrowserListCtrlControl::DataBrowserEditTextProc(
2216 DataBrowserItemID itemID
,
2217 DataBrowserPropertyID property
,
2218 CFStringRef theString
,
2219 Rect
*maxEditTextRect
,
2220 Boolean
*shrinkToFit
)
2222 Boolean result
= false;
2223 wxMacDataBrowserListCtrlControl
* ctl
= dynamic_cast<wxMacDataBrowserListCtrlControl
*>( wxMacControl::GetReferenceFromNativeControl( browser
) );
2226 result
= ctl
->ConfirmEditText(itemID
, property
, theString
, maxEditTextRect
, shrinkToFit
);
2227 theString
= CFSTR("Hello!");
2232 bool wxMacDataBrowserListCtrlControl::ConfirmEditText(
2233 DataBrowserItemID itemID
,
2234 DataBrowserPropertyID property
,
2235 CFStringRef theString
,
2236 Rect
*maxEditTextRect
,
2237 Boolean
*shrinkToFit
)
2242 pascal void wxMacDataBrowserListCtrlControl::DataBrowserDrawItemProc(
2244 DataBrowserItemID itemID
,
2245 DataBrowserPropertyID property
,
2246 DataBrowserItemState itemState
,
2247 const Rect
*itemRect
,
2249 Boolean colorDevice
)
2251 wxMacDataBrowserListCtrlControl
* ctl
= dynamic_cast<wxMacDataBrowserListCtrlControl
*>( wxMacControl::GetReferenceFromNativeControl( browser
) );
2254 ctl
->DrawItem(itemID
, property
, itemState
, itemRect
, gdDepth
, colorDevice
);
2258 // routines needed for DrawItem
2263 kTextBoxHeight
= 14,
2264 kIconTextSpacingV
= 2,
2266 kContentHeight
= kIconHeight
+ kTextBoxHeight
+ kIconTextSpacingV
2269 static void calculateCGDrawingBounds(CGRect inItemRect
, CGRect
*outIconRect
, CGRect
*outTextRect
, bool hasIcon
= false)
2272 float iconH
, iconW
= 0;
2273 float padding
= kItemPadding
;
2276 iconH
= kIconHeight
;
2278 padding
= padding
*2;
2281 textBottom
= inItemRect
.origin
.y
;
2283 *outIconRect
= CGRectMake(inItemRect
.origin
.x
+ kItemPadding
,
2284 textBottom
+ kIconTextSpacingV
, kIconWidth
,
2287 *outTextRect
= CGRectMake(inItemRect
.origin
.x
+ padding
+ iconW
,
2288 textBottom
+ kIconTextSpacingV
, inItemRect
.size
.width
- padding
- iconW
,
2289 inItemRect
.size
.height
- kIconTextSpacingV
);
2292 void wxMacDataBrowserListCtrlControl::DrawItem(
2293 DataBrowserItemID itemID
,
2294 DataBrowserPropertyID property
,
2295 DataBrowserItemState itemState
,
2296 const Rect
*itemRect
,
2298 Boolean colorDevice
)
2301 wxFont font
= wxNullFont
;
2303 short listColumn
= property
- kMinColumnId
;
2305 wxListCtrl
* list
= wxDynamicCast( GetPeer() , wxListCtrl
);
2306 wxMacListCtrlItem
* lcItem
;
2307 wxColour color
= *wxBLACK
;
2308 wxColour bgColor
= wxNullColour
;
2310 if (listColumn
>= 0)
2314 lcItem
= (wxMacListCtrlItem
*) itemID
;
2315 if (lcItem
->HasColumnInfo(listColumn
)){
2316 wxListItem
* item
= lcItem
->GetColumnInfo(listColumn
);
2318 // we always use the 0 column to get font and text/background colors.
2319 if (lcItem
->HasColumnInfo(0))
2321 wxListItem
* firstItem
= lcItem
->GetColumnInfo(0);
2322 color
= firstItem
->GetTextColour();
2323 bgColor
= firstItem
->GetBackgroundColour();
2324 font
= firstItem
->GetFont();
2327 if (item
->GetMask() & wxLIST_MASK_TEXT
)
2328 text
= item
->GetText();
2329 if (item
->GetMask() & wxLIST_MASK_IMAGE
)
2330 imgIndex
= item
->GetImage();
2336 text
= list
->OnGetItemText( (long)itemID
-1, listColumn
);
2337 imgIndex
= list
->OnGetItemColumnImage( (long)itemID
-1, listColumn
);
2338 wxListItemAttr
* attrs
= list
->OnGetItemAttr( (long)itemID
-1 );
2341 if (attrs
->HasBackgroundColour())
2342 bgColor
= attrs
->GetBackgroundColour();
2343 if (attrs
->HasTextColour())
2344 color
= attrs
->GetTextColour();
2345 if (attrs
->HasFont())
2346 font
= attrs
->GetFont();
2351 wxColour listBgColor
= list
->GetBackgroundColour();
2352 if (bgColor
== wxNullColour
)
2353 bgColor
= listBgColor
;
2355 wxFont listFont
= list
->GetFont();
2356 if (font
== wxNullFont
)
2359 wxMacCFStringHolder cfString
;
2360 cfString
.Assign( text
, wxLocale::GetSystemEncoding() );
2363 CGRect enclosingCGRect
, iconCGRect
, textCGRect
;
2365 ThemeDrawingState savedState
= NULL
;
2366 CGContextRef context
= (CGContextRef
)list
->MacGetDrawingContext();
2367 RGBColor labelColor
;
2369 GetDataBrowserItemPartBounds(GetControlRef(), itemID
, property
, kDataBrowserPropertyEnclosingPart
,
2372 enclosingCGRect
= CGRectMake(enclosingRect
.left
,
2374 enclosingRect
.right
- enclosingRect
.left
,
2375 enclosingRect
.bottom
- enclosingRect
.top
);
2377 active
= IsControlActive(GetControlRef());
2379 // don't paint the background over the vertical rule line
2380 if ( list
->GetWindowStyleFlag() & wxLC_VRULES
)
2382 enclosingCGRect
.origin
.x
+= 1;
2383 enclosingCGRect
.size
.width
-= 1;
2385 if (itemState
== kDataBrowserItemIsSelected
)
2387 RGBColor foregroundColor
;
2389 GetThemeDrawingState(&savedState
);
2391 GetThemeBrushAsColor(kThemeBrushAlternatePrimaryHighlightColor
, 32, true, &foregroundColor
);
2392 GetThemeTextColor(kThemeTextColorWhite
, gdDepth
, colorDevice
, &labelColor
);
2394 CGContextSaveGState(context
);
2396 CGContextSetRGBFillColor(context
, (float)foregroundColor
.red
/ (float)USHRT_MAX
,
2397 (float)foregroundColor
.green
/ (float)USHRT_MAX
,
2398 (float)foregroundColor
.blue
/ (float)USHRT_MAX
, 1.0);
2399 CGContextFillRect(context
, enclosingCGRect
);
2401 CGContextRestoreGState(context
);
2407 labelColor
= MAC_WXCOLORREF( color
.GetPixel() );
2408 else if (list
->GetTextColour().Ok())
2409 labelColor
= MAC_WXCOLORREF( list
->GetTextColour().GetPixel() );
2413 labelColor
.green
= 0;
2414 labelColor
.blue
= 0;
2419 RGBColor foregroundColor
= MAC_WXCOLORREF( bgColor
.GetPixel() );
2420 CGContextSaveGState(context
);
2422 CGContextSetRGBFillColor(context
, (float)foregroundColor
.red
/ (float)USHRT_MAX
,
2423 (float)foregroundColor
.green
/ (float)USHRT_MAX
,
2424 (float)foregroundColor
.blue
/ (float)USHRT_MAX
, 1.0);
2425 CGContextFillRect(context
, enclosingCGRect
);
2427 CGContextRestoreGState(context
);
2431 calculateCGDrawingBounds(enclosingCGRect
, &iconCGRect
, &textCGRect
, (imgIndex
!= -1) );
2435 wxImageList
* imageList
= list
->GetImageList(wxIMAGE_LIST_SMALL
);
2436 if (imageList
&& imageList
->GetImageCount() > 0){
2437 wxBitmap bmp
= imageList
->GetBitmap(imgIndex
);
2438 IconRef icon
= bmp
.GetBitmapData()->GetIconRef();
2442 iconLabel
.green
= 0;
2445 CGContextSaveGState(context
);
2446 CGContextTranslateCTM(context
, 0,iconCGRect
.origin
.y
+ CGRectGetMaxY(iconCGRect
));
2447 CGContextScaleCTM(context
,1.0f
,-1.0f
);
2448 PlotIconRefInContext(context
, &iconCGRect
, kAlignNone
,
2449 active
? kTransformNone
: kTransformDisabled
, &iconLabel
,
2450 kPlotIconRefNormalFlags
, icon
);
2452 CGContextRestoreGState(context
);
2456 HIThemeTextHorizontalFlush hFlush
= kHIThemeTextHorizontalFlushLeft
;
2457 UInt16 fontID
= kThemeViewsFont
;
2461 if (font
.GetFamily() != wxFONTFAMILY_DEFAULT
)
2462 fontID
= font
.MacGetThemeFontID();
2464 // FIXME: replace these with CG or ATSUI calls so we can remove this #ifndef.
2466 ::TextSize( (short)(font
.MacGetFontSize()) ) ;
2467 ::TextFace( font
.MacGetFontStyle() ) ;
2472 list
->GetColumn(listColumn
, item
);
2473 if (item
.GetMask() & wxLIST_MASK_FORMAT
)
2475 if (item
.GetAlign() == wxLIST_FORMAT_LEFT
)
2476 hFlush
= kHIThemeTextHorizontalFlushLeft
;
2477 else if (item
.GetAlign() == wxLIST_FORMAT_CENTER
)
2478 hFlush
= kHIThemeTextHorizontalFlushCenter
;
2479 else if (item
.GetAlign() == wxLIST_FORMAT_RIGHT
)
2481 hFlush
= kHIThemeTextHorizontalFlushRight
;
2482 textCGRect
.origin
.x
-= kItemPadding
; // give a little extra paddding
2486 HIThemeTextInfo info
;
2487 info
.version
= kHIThemeTextInfoVersionZero
;
2488 info
.state
= active
? kThemeStateActive
: kThemeStateInactive
;
2489 info
.fontID
= fontID
;
2490 info
.horizontalFlushness
= hFlush
;
2491 info
.verticalFlushness
= kHIThemeTextVerticalFlushCenter
;
2492 info
.options
= kHIThemeTextBoxOptionNone
;
2493 info
.truncationPosition
= kHIThemeTextTruncationEnd
;
2494 info
.truncationMaxLines
= 1;
2496 CGContextSaveGState(context
);
2497 CGContextSetRGBFillColor (context
, (float)labelColor
.red
/ (float)USHRT_MAX
,
2498 (float)labelColor
.green
/ (float)USHRT_MAX
,
2499 (float)labelColor
.blue
/ (float)USHRT_MAX
, 1.0);
2501 HIThemeDrawTextBox(cfString
, &textCGRect
, &info
, context
, kHIThemeOrientationNormal
);
2503 CGContextRestoreGState(context
);
2505 if (savedState
!= NULL
)
2506 SetThemeDrawingState(savedState
, true);
2509 OSStatus
wxMacDataBrowserListCtrlControl::GetSetItemData(DataBrowserItemID itemID
,
2510 DataBrowserPropertyID property
,
2511 DataBrowserItemDataRef itemData
,
2512 Boolean changeValue
)
2516 short listColumn
= property
- kMinColumnId
;
2518 OSStatus err
= errDataBrowserPropertyNotSupported
;
2519 wxListCtrl
* list
= wxDynamicCast( GetPeer() , wxListCtrl
);
2520 wxMacListCtrlItem
* lcItem
;
2522 if (listColumn
>= 0)
2526 lcItem
= (wxMacListCtrlItem
*) itemID
;
2527 if (lcItem
&& lcItem
->HasColumnInfo(listColumn
)){
2528 wxListItem
* item
= lcItem
->GetColumnInfo(listColumn
);
2529 if (item
->GetMask() & wxLIST_MASK_TEXT
)
2530 text
= item
->GetText();
2531 if (item
->GetMask() & wxLIST_MASK_IMAGE
)
2532 imgIndex
= item
->GetImage();
2537 text
= list
->OnGetItemText( (long)itemID
-1, listColumn
);
2538 imgIndex
= list
->OnGetItemColumnImage( (long)itemID
-1, listColumn
);
2546 case kDataBrowserItemIsEditableProperty
:
2547 if ( list
&& list
->HasFlag( wxLC_EDIT_LABELS
) )
2549 verify_noerr(SetDataBrowserItemDataBooleanValue( itemData
, true ));
2554 if ( property
>= kMinColumnId
)
2556 wxMacCFStringHolder cfStr
;
2559 cfStr
.Assign( text
, wxLocale::GetSystemEncoding() );
2560 err
= ::SetDataBrowserItemDataText( itemData
, cfStr
);
2566 if ( imgIndex
!= -1 )
2568 wxImageList
* imageList
= list
->GetImageList(wxIMAGE_LIST_SMALL
);
2569 if (imageList
&& imageList
->GetImageCount() > 0){
2570 wxBitmap bmp
= imageList
->GetBitmap(imgIndex
);
2571 IconRef icon
= bmp
.GetBitmapData()->GetIconRef();
2572 ::SetDataBrowserItemDataIcon(itemData
, icon
);
2586 if ( property
>= kMinColumnId
)
2588 short listColumn
= property
- kMinColumnId
;
2590 // TODO probably send the 'end edit' from here, as we
2591 // can then deal with the veto
2593 verify_noerr( GetDataBrowserItemDataText( itemData
, &sr
) ) ;
2594 wxMacCFStringHolder
cfStr(sr
) ;;
2596 list
->SetItem( (long)itemData
-1 , listColumn
, cfStr
.AsString() ) ;
2600 lcItem
->SetColumnTextValue( listColumn
, cfStr
.AsString() );
2610 void wxMacDataBrowserListCtrlControl::ItemNotification(DataBrowserItemID itemID
,
2611 DataBrowserItemNotification message
,
2612 DataBrowserItemDataRef itemData
)
2614 // we want to depend on as little as possible to make sure tear-down of controls is safe
2615 if ( message
== kDataBrowserItemRemoved
)
2617 // make sure MacDelete does the proper teardown.
2620 else if ( message
== kDataBrowserItemAdded
)
2622 // we don't issue events on adding, the item is not really stored in the list yet, so we
2623 // avoid asserts by getting out now
2627 wxListCtrl
*list
= wxDynamicCast( GetPeer() , wxListCtrl
);
2630 bool trigger
= false;
2632 wxListEvent
event( wxEVT_COMMAND_LIST_ITEM_SELECTED
, list
->GetId() );
2633 bool isSingle
= (list
->GetWindowStyle() & wxLC_SINGLE_SEL
) != 0;
2635 event
.SetEventObject( list
);
2636 if ( !list
->IsVirtual() )
2638 DataBrowserTableViewRowIndex result
= 0;
2639 verify_noerr( GetItemRow( itemID
, &result
) ) ;
2640 event
.m_itemIndex
= result
;
2642 if (event
.m_itemIndex
>= 0)
2643 MacGetColumnInfo(event
.m_itemIndex
,0,event
.m_item
);
2647 event
.m_itemIndex
= (long)itemID
;
2652 case kDataBrowserItemDeselected
:
2653 event
.SetEventType(wxEVT_COMMAND_LIST_ITEM_DESELECTED
);
2655 trigger
= !IsSelectionSuppressed();
2658 case kDataBrowserItemSelected
:
2659 trigger
= !IsSelectionSuppressed();
2663 case kDataBrowserItemDoubleClicked
:
2664 event
.SetEventType( wxEVT_COMMAND_LIST_ITEM_ACTIVATED
);
2668 case kDataBrowserEditStarted
:
2669 // TODO : how to veto ?
2670 event
.SetEventType( wxEVT_COMMAND_LIST_BEGIN_LABEL_EDIT
) ;
2674 case kDataBrowserEditStopped
:
2675 // TODO probably trigger only upon the value store callback, because
2676 // here IIRC we cannot veto
2677 event
.SetEventType( wxEVT_COMMAND_LIST_END_LABEL_EDIT
) ;
2687 // direct notification is not always having the listbox GetSelection() having in synch with event
2688 wxPostEvent( list
->GetEventHandler(), event
);
2693 Boolean
wxMacDataBrowserListCtrlControl::CompareItems(DataBrowserItemID itemOneID
,
2694 DataBrowserItemID itemTwoID
,
2695 DataBrowserPropertyID sortProperty
)
2698 bool retval
= false;
2700 wxString otherItemText
;
2701 int colId
= sortProperty
- kMinColumnId
;
2703 wxListCtrl
* list
= wxDynamicCast( GetPeer() , wxListCtrl
);
2709 wxMacListCtrlItem
* item
= (wxMacListCtrlItem
*)itemOneID
;
2710 wxMacListCtrlItem
* otherItem
= (wxMacListCtrlItem
*)itemTwoID
;
2711 wxListCtrlCompare func
= list
->GetCompareFunc();
2712 long item1
= GetLineFromItem(item
);
2713 long item2
= GetLineFromItem(otherItem
);
2715 if (func
!= NULL
&& item
->HasColumnInfo(colId
) && otherItem
->HasColumnInfo(colId
))
2716 return func(item1
, item2
, list
->GetCompareFuncData()) >= 0;
2718 if (item
->HasColumnInfo(colId
))
2719 itemText
= item
->GetColumnInfo(colId
)->GetText();
2720 if (otherItem
->HasColumnInfo(colId
))
2721 otherItemText
= otherItem
->GetColumnInfo(colId
)->GetText();
2726 long itemNum
= (long)itemOneID
;
2727 long otherItemNum
= (long)itemTwoID
;
2728 itemText
= list
->OnGetItemText( itemNum
-1, colId
);
2729 otherItemText
= list
->OnGetItemText( otherItemNum
-1, colId
);
2733 DataBrowserSortOrder sort
;
2734 verify_noerr(GetSortOrder(&sort
));
2736 if ( sort
== kDataBrowserOrderIncreasing
)
2738 retval
= itemText
.CmpNoCase( otherItemText
) > 0;
2740 else if ( sort
== kDataBrowserOrderDecreasing
)
2742 retval
= itemText
.CmpNoCase( otherItemText
) < 0;
2746 // fallback for undefined cases
2747 retval
= itemOneID
< itemTwoID
;
2753 wxMacDataBrowserListCtrlControl::~wxMacDataBrowserListCtrlControl()
2757 void wxMacDataBrowserListCtrlControl::MacSetColumnInfo( unsigned int row
, unsigned int column
, wxListItem
* item
)
2759 wxMacDataItem
* dataItem
= GetItemFromLine(row
);
2760 wxASSERT_MSG( dataItem
, _T("could not obtain wxMacDataItem for row in MacSetColumnInfo. Is row a valid wxListCtrl row?") );
2763 wxMacListCtrlItem
* listItem
= dynamic_cast<wxMacListCtrlItem
*>(dataItem
);
2764 listItem
->SetColumnInfo( column
, item
);
2765 UpdateState(dataItem
, item
);
2769 // apply changes that need to happen immediately, rather than when the
2770 // databrowser control fires a callback.
2771 void wxMacDataBrowserListCtrlControl::UpdateState(wxMacDataItem
* dataItem
, wxListItem
* listItem
)
2773 bool isSelected
= IsItemSelected( dataItem
);
2774 bool isSelectedState
= (listItem
->GetState() == wxLIST_STATE_SELECTED
);
2776 // toggle the selection state if wxListInfo state and actual state don't match.
2777 if ( isSelected
!= isSelectedState
)
2779 DataBrowserSetOption options
= kDataBrowserItemsAdd
;
2780 if (!isSelectedState
)
2781 options
= kDataBrowserItemsRemove
;
2782 SetSelectedItem(dataItem
, options
);
2784 // TODO: Set column width if item width > than current column width
2787 void wxMacDataBrowserListCtrlControl::MacGetColumnInfo( unsigned int row
, unsigned int column
, wxListItem
& item
)
2789 wxMacDataItem
* dataItem
= GetItemFromLine(row
);
2790 wxASSERT_MSG( dataItem
, _T("could not obtain wxMacDataItem in MacGetColumnInfo. Is row a valid wxListCtrl row?") );
2791 // CS should this guard against dataItem = 0 ? , as item is not a pointer if (item) is not appropriate
2794 wxMacListCtrlItem
* listItem
= dynamic_cast<wxMacListCtrlItem
*>(dataItem
);
2796 if (!listItem
->HasColumnInfo( column
))
2799 wxListItem
* oldItem
= listItem
->GetColumnInfo( column
);
2803 long mask
= item
.GetMask();
2805 // by default, get everything for backwards compatibility
2808 if ( mask
& wxLIST_MASK_TEXT
)
2809 item
.SetText(oldItem
->GetText());
2810 if ( mask
& wxLIST_MASK_IMAGE
)
2811 item
.SetImage(oldItem
->GetImage());
2812 if ( mask
& wxLIST_MASK_DATA
)
2813 item
.SetData(oldItem
->GetData());
2814 if ( mask
& wxLIST_MASK_STATE
)
2815 item
.SetState(oldItem
->GetState());
2816 if ( mask
& wxLIST_MASK_WIDTH
)
2817 item
.SetWidth(oldItem
->GetWidth());
2818 if ( mask
& wxLIST_MASK_FORMAT
)
2819 item
.SetAlign(oldItem
->GetAlign());
2821 item
.SetTextColour(oldItem
->GetTextColour());
2822 item
.SetBackgroundColour(oldItem
->GetBackgroundColour());
2823 item
.SetFont(oldItem
->GetFont());
2828 void wxMacDataBrowserListCtrlControl::MacInsertItem( unsigned int n
, wxListItem
* item
)
2830 wxMacDataItemBrowserControl::MacInsert(n
, item
->GetText());
2831 MacSetColumnInfo(n
, 0, item
);
2834 wxMacDataItem
* wxMacDataBrowserListCtrlControl::CreateItem()
2836 return new wxMacListCtrlItem();
2839 wxMacListCtrlItem::wxMacListCtrlItem()
2841 m_rowItems
= wxListItemList( wxKEY_INTEGER
);
2844 int wxMacListCtrlItem::GetColumnImageValue( unsigned int column
)
2846 if ( HasColumnInfo(column
) )
2847 return GetColumnInfo(column
)->GetImage();
2852 void wxMacListCtrlItem::SetColumnImageValue( unsigned int column
, int imageIndex
)
2854 if ( HasColumnInfo(column
) )
2855 GetColumnInfo(column
)->SetImage(imageIndex
);
2858 wxString
wxMacListCtrlItem::GetColumnTextValue( unsigned int column
)
2863 if ( HasColumnInfo(column
) )
2864 return GetColumnInfo(column
)->GetText();
2866 return wxEmptyString
;
2869 void wxMacListCtrlItem::SetColumnTextValue( unsigned int column
, const wxString
& text
)
2871 if ( HasColumnInfo(column
) )
2872 GetColumnInfo(column
)->SetText(text
);
2874 // for compatibility with superclass APIs
2879 wxListItem
* wxMacListCtrlItem::GetColumnInfo( unsigned int column
)
2881 wxListItemList::compatibility_iterator node
= m_rowItems
.Find( column
);
2882 wxASSERT_MSG( node
, _T("invalid column index in wxMacListCtrlItem") );
2884 return node
->GetData();
2887 bool wxMacListCtrlItem::HasColumnInfo( unsigned int column
)
2889 return m_rowItems
.Find( column
) != NULL
;
2892 void wxMacListCtrlItem::SetColumnInfo( unsigned int column
, wxListItem
* item
)
2895 if ( !HasColumnInfo(column
) )
2897 wxListItem
* listItem
= new wxListItem(*item
);
2898 m_rowItems
.Append( column
, listItem
);
2902 wxListItem
* listItem
= GetColumnInfo( column
);
2903 long mask
= item
->GetMask();
2904 if (mask
& wxLIST_MASK_TEXT
)
2905 listItem
->SetText(item
->GetText());
2906 if (mask
& wxLIST_MASK_DATA
)
2907 listItem
->SetData(item
->GetData());
2908 if (mask
& wxLIST_MASK_IMAGE
)
2909 listItem
->SetImage(item
->GetImage());
2910 if (mask
& wxLIST_MASK_STATE
)
2911 listItem
->SetState(item
->GetState());
2912 if (mask
& wxLIST_MASK_FORMAT
)
2913 listItem
->SetAlign(item
->GetAlign());
2914 if (mask
& wxLIST_MASK_WIDTH
)
2915 listItem
->SetWidth(item
->GetWidth());
2917 if ( item
->HasAttributes() )
2919 if ( listItem
->HasAttributes() )
2920 listItem
->GetAttributes()->AssignFrom(*item
->GetAttributes());
2923 listItem
->SetTextColour(item
->GetTextColour());
2924 listItem
->SetBackgroundColour(item
->GetBackgroundColour());
2925 listItem
->SetFont(item
->GetFont());
2931 #endif // wxUSE_LISTCTRL