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 // FIXME: we can't use the sort property for virtual listctrls
153 // so we need to find a better way to determine which column was clicked...
154 if (!window
->IsVirtual())
155 window
->GetEventHandler()->ProcessEvent( le
);
157 result
= CallNextEventHandler(handler
, event
);
160 case kEventControlDraw
:
162 CGContextRef context
= cEvent
.GetParameter
<CGContextRef
>(kEventParamCGContextRef
, typeCGContextRef
) ;
163 window
->MacSetDrawingContext(context
);
164 result
= CallNextEventHandler(handler
, event
);
165 window
->MacSetDrawingContext(NULL
);
176 DEFINE_ONE_SHOT_HANDLER_GETTER( wxMacListCtrlEventHandler
)
178 class wxMacListCtrlItem
: public wxMacListBoxItem
183 virtual void Notification(wxMacDataItemBrowserControl
*owner
,
184 DataBrowserItemNotification message
,
185 DataBrowserItemDataRef itemData
) const;
187 virtual void SetColumnInfo( unsigned int column
, wxListItem
* item
);
188 virtual wxListItem
* GetColumnInfo( unsigned int column
);
189 virtual bool HasColumnInfo( unsigned int column
);
191 virtual void SetColumnTextValue( unsigned int column
, const wxString
& text
);
192 virtual wxString
GetColumnTextValue( unsigned int column
);
194 virtual int GetColumnImageValue( unsigned int column
);
195 virtual void SetColumnImageValue( unsigned int column
, int imageIndex
);
197 virtual ~wxMacListCtrlItem();
199 wxListItemList m_rowItems
;
202 DataBrowserDrawItemUPP gDataBrowserDrawItemUPP
= NULL
;
203 //DataBrowserEditItemUPP gDataBrowserEditItemUPP = NULL;
204 DataBrowserHitTestUPP gDataBrowserHitTestUPP
= NULL
;
206 // TODO: Make a better name!!
207 class wxMacDataBrowserListCtrlControl
: public wxMacDataItemBrowserControl
210 wxMacDataBrowserListCtrlControl( wxWindow
*peer
, const wxPoint
& pos
, const wxSize
& size
, long style
);
211 virtual ~wxMacDataBrowserListCtrlControl();
213 // create a list item (can be a subclass of wxMacListBoxItem)
215 virtual wxMacDataItem
* CreateItem();
217 virtual void MacInsertItem( unsigned int n
, wxListItem
* item
);
218 virtual void MacSetColumnInfo( unsigned int row
, unsigned int column
, wxListItem
* item
);
219 virtual void MacGetColumnInfo( unsigned int row
, unsigned int column
, wxListItem
& item
);
220 virtual void UpdateState(wxMacDataItem
* dataItem
, wxListItem
* item
);
223 // we need to override to provide specialized handling for virtual wxListCtrls
224 virtual OSStatus
GetSetItemData(DataBrowserItemID itemID
,
225 DataBrowserPropertyID property
,
226 DataBrowserItemDataRef itemData
,
227 Boolean changeValue
);
229 virtual void ItemNotification(
230 DataBrowserItemID itemID
,
231 DataBrowserItemNotification message
,
232 DataBrowserItemDataRef itemData
);
234 virtual Boolean
CompareItems(DataBrowserItemID itemOneID
,
235 DataBrowserItemID itemTwoID
,
236 DataBrowserPropertyID sortProperty
);
238 static pascal void DataBrowserDrawItemProc(ControlRef browser
,
239 DataBrowserItemID item
,
240 DataBrowserPropertyID property
,
241 DataBrowserItemState itemState
,
244 Boolean colorDevice
);
246 virtual void DrawItem(DataBrowserItemID itemID
,
247 DataBrowserPropertyID property
,
248 DataBrowserItemState itemState
,
249 const Rect
*itemRect
,
251 Boolean colorDevice
);
253 static pascal Boolean
DataBrowserEditTextProc(ControlRef browser
,
254 DataBrowserItemID item
,
255 DataBrowserPropertyID property
,
256 CFStringRef theString
,
257 Rect
*maxEditTextRect
,
258 Boolean
*shrinkToFit
);
260 static pascal Boolean
DataBrowserHitTestProc(ControlRef browser
,
261 DataBrowserItemID itemID
,
262 DataBrowserPropertyID property
,
264 const Rect
*mouseRect
) { return true; }
266 virtual bool ConfirmEditText(DataBrowserItemID item
,
267 DataBrowserPropertyID property
,
268 CFStringRef theString
,
269 Rect
*maxEditTextRect
,
270 Boolean
*shrinkToFit
);
274 wxClientDataType m_clientDataItemsType
;
279 class wxMacListCtrlEventDelegate
: public wxEvtHandler
282 wxMacListCtrlEventDelegate( wxListCtrl
* list
, int id
);
283 virtual bool ProcessEvent( wxEvent
& event
);
290 wxMacListCtrlEventDelegate::wxMacListCtrlEventDelegate( wxListCtrl
* list
, int id
)
296 bool wxMacListCtrlEventDelegate::ProcessEvent( wxEvent
& event
)
298 // even though we use a generic list ctrl underneath, make sure
299 // we present ourselves as wxListCtrl.
300 event
.SetEventObject( m_list
);
303 if ( !event
.IsKindOf( CLASSINFO( wxCommandEvent
) ) )
305 if (m_list
->GetEventHandler()->ProcessEvent( event
))
308 return wxEvtHandler::ProcessEvent(event
);
311 //-----------------------------------------------------------------------------
312 // wxListCtrlRenameTimer (internal)
313 //-----------------------------------------------------------------------------
315 class wxListCtrlRenameTimer
: public wxTimer
321 wxListCtrlRenameTimer( wxListCtrl
*owner
);
325 //-----------------------------------------------------------------------------
326 // wxListCtrlTextCtrlWrapper: wraps a wxTextCtrl to make it work for inline editing
327 //-----------------------------------------------------------------------------
329 class wxListCtrlTextCtrlWrapper
: public wxEvtHandler
332 // NB: text must be a valid object but not Create()d yet
333 wxListCtrlTextCtrlWrapper(wxListCtrl
*owner
,
337 wxTextCtrl
*GetText() const { return m_text
; }
339 void AcceptChangesAndFinish();
342 void OnChar( wxKeyEvent
&event
);
343 void OnKeyUp( wxKeyEvent
&event
);
344 void OnKillFocus( wxFocusEvent
&event
);
346 bool AcceptChanges();
352 wxString m_startValue
;
355 bool m_aboutToFinish
;
357 DECLARE_EVENT_TABLE()
360 //-----------------------------------------------------------------------------
361 // wxListCtrlRenameTimer (internal)
362 //-----------------------------------------------------------------------------
364 wxListCtrlRenameTimer::wxListCtrlRenameTimer( wxListCtrl
*owner
)
369 void wxListCtrlRenameTimer::Notify()
371 m_owner
->OnRenameTimer();
374 //-----------------------------------------------------------------------------
375 // wxListCtrlTextCtrlWrapper (internal)
376 //-----------------------------------------------------------------------------
378 BEGIN_EVENT_TABLE(wxListCtrlTextCtrlWrapper
, wxEvtHandler
)
379 EVT_CHAR (wxListCtrlTextCtrlWrapper::OnChar
)
380 EVT_KEY_UP (wxListCtrlTextCtrlWrapper::OnKeyUp
)
381 EVT_KILL_FOCUS (wxListCtrlTextCtrlWrapper::OnKillFocus
)
384 wxListCtrlTextCtrlWrapper::wxListCtrlTextCtrlWrapper(wxListCtrl
*owner
,
387 : m_startValue(owner
->GetItemText(itemEdit
)),
388 m_itemEdited(itemEdit
)
393 m_aboutToFinish
= false;
397 owner
->GetItemRect(itemEdit
, rectLabel
);
399 m_text
->Create(owner
, wxID_ANY
, m_startValue
,
400 wxPoint(rectLabel
.x
+offset
,rectLabel
.y
),
401 wxSize(rectLabel
.width
-offset
,rectLabel
.height
));
404 m_text
->PushEventHandler(this);
407 void wxListCtrlTextCtrlWrapper::Finish()
413 m_text
->RemoveEventHandler(this);
414 m_owner
->FinishEditing(m_text
);
416 wxPendingDelete
.Append( this );
420 bool wxListCtrlTextCtrlWrapper::AcceptChanges()
422 const wxString value
= m_text
->GetValue();
424 if ( value
== m_startValue
)
425 // nothing changed, always accept
428 if ( !m_owner
->OnRenameAccept(m_itemEdited
, value
) )
429 // vetoed by the user
432 // accepted, do rename the item
433 m_owner
->SetItemText(m_itemEdited
, value
);
438 void wxListCtrlTextCtrlWrapper::AcceptChangesAndFinish()
440 m_aboutToFinish
= true;
442 // Notify the owner about the changes
445 // Even if vetoed, close the control (consistent with MSW)
449 void wxListCtrlTextCtrlWrapper::OnChar( wxKeyEvent
&event
)
451 switch ( event
.m_keyCode
)
454 AcceptChangesAndFinish();
458 m_owner
->OnRenameCancelled( m_itemEdited
);
467 void wxListCtrlTextCtrlWrapper::OnKeyUp( wxKeyEvent
&event
)
475 // auto-grow the textctrl:
476 wxSize parentSize
= m_owner
->GetSize();
477 wxPoint myPos
= m_text
->GetPosition();
478 wxSize mySize
= m_text
->GetSize();
480 m_text
->GetTextExtent(m_text
->GetValue() + _T("MM"), &sx
, &sy
);
481 if (myPos
.x
+ sx
> parentSize
.x
)
482 sx
= parentSize
.x
- myPos
.x
;
485 m_text
->SetSize(sx
, wxDefaultCoord
);
490 void wxListCtrlTextCtrlWrapper::OnKillFocus( wxFocusEvent
&event
)
492 if ( !m_finished
&& !m_aboutToFinish
)
494 if ( !AcceptChanges() )
495 m_owner
->OnRenameCancelled( m_itemEdited
);
500 // We must let the native text control handle focus
504 BEGIN_EVENT_TABLE(wxListCtrl
, wxControl
)
505 EVT_LEFT_DOWN(wxListCtrl::OnLeftDown
)
506 EVT_LEFT_DCLICK(wxListCtrl::OnDblClick
)
509 // ============================================================================
511 // ============================================================================
513 wxMacListControl
* wxListCtrl::GetPeer() const
515 return dynamic_cast<wxMacListControl
*>(m_peer
);
518 // ----------------------------------------------------------------------------
519 // wxListCtrl construction
520 // ----------------------------------------------------------------------------
522 void wxListCtrl::Init()
524 m_imageListNormal
= NULL
;
525 m_imageListSmall
= NULL
;
526 m_imageListState
= NULL
;
528 // keep track of if we created our own image lists, or if they were assigned
530 m_ownsImageListNormal
= m_ownsImageListSmall
= m_ownsImageListState
= false;
534 m_genericImpl
= NULL
;
536 m_compareFunc
= NULL
;
537 m_compareFuncData
= 0;
538 m_colsInfo
= wxColumnList();
539 m_textColor
= wxNullColour
;
540 m_bgColor
= wxNullColour
;
541 m_textctrlWrapper
= NULL
;
543 m_renameTimer
= new wxListCtrlRenameTimer( this );
546 class wxGenericListCtrlHook
: public wxGenericListCtrl
549 wxGenericListCtrlHook(wxListCtrl
* parent
,
554 const wxValidator
& validator
,
555 const wxString
& name
)
556 : wxGenericListCtrl(parent
, id
, pos
, size
, style
, validator
, name
),
557 m_nativeListCtrl(parent
)
562 virtual wxListItemAttr
* OnGetItemAttr(long item
) const
564 return m_nativeListCtrl
->OnGetItemAttr(item
);
567 virtual int OnGetItemImage(long item
) const
569 return m_nativeListCtrl
->OnGetItemImage(item
);
572 virtual int OnGetItemColumnImage(long item
, long column
) const
574 return m_nativeListCtrl
->OnGetItemColumnImage(item
, column
);
577 virtual wxString
OnGetItemText(long item
, long column
) const
579 return m_nativeListCtrl
->OnGetItemText(item
, column
);
582 wxListCtrl
* m_nativeListCtrl
;
586 void wxListCtrl::OnLeftDown(wxMouseEvent
& event
)
588 if ( m_textctrlWrapper
)
591 m_textctrlWrapper
->AcceptChangesAndFinish();
595 long current
= HitTest(event
.GetPosition(), hitResult
);
596 if ((current
== m_current
) &&
597 (hitResult
== wxLIST_HITTEST_ONITEM
) &&
598 HasFlag(wxLC_EDIT_LABELS
) )
600 m_renameTimer
->Start( 100, true );
609 void wxListCtrl::OnDblClick(wxMouseEvent
& event
)
615 bool wxListCtrl::Create(wxWindow
*parent
,
620 const wxValidator
& validator
,
621 const wxString
& name
)
624 // for now, we'll always use the generic list control for ICON and LIST views,
625 // because they dynamically change the number of columns on resize.
626 // Also, allow the user to set it to use the list ctrl as well.
627 if ( (wxSystemOptions::HasOption( wxMAC_ALWAYS_USE_GENERIC_LISTCTRL
)
628 && (wxSystemOptions::GetOptionInt( wxMAC_ALWAYS_USE_GENERIC_LISTCTRL
) == 1)) ||
629 (style
& wxLC_ICON
) || (style
& wxLC_SMALL_ICON
) || (style
& wxLC_LIST
) )
631 m_macIsUserPane
= true;
633 long paneStyle
= style
;
634 paneStyle
&= ~wxSIMPLE_BORDER
;
635 paneStyle
&= ~wxDOUBLE_BORDER
;
636 paneStyle
&= ~wxSUNKEN_BORDER
;
637 paneStyle
&= ~wxRAISED_BORDER
;
638 paneStyle
&= ~wxSTATIC_BORDER
;
639 if ( !wxWindow::Create(parent
, id
, pos
, size
, paneStyle
| wxNO_BORDER
, name
) )
642 // since the generic control is a child, make sure we position it at 0, 0
643 m_genericImpl
= new wxGenericListCtrlHook(this, id
, wxPoint(0, 0), size
, style
, validator
, name
);
644 m_genericImpl
->PushEventHandler( new wxMacListCtrlEventDelegate( this, GetId() ) );
650 m_macIsUserPane
= false;
652 if ( !wxWindow::Create(parent
, id
, pos
, size
, style
, name
) )
654 m_dbImpl
= new wxMacDataBrowserListCtrlControl( this, pos
, size
, style
);
657 MacPostControlCreate( pos
, size
);
659 InstallControlEventHandler( m_peer
->GetControlRef() , GetwxMacListCtrlEventHandlerUPP(),
660 GetEventTypeCount(eventList
), eventList
, this,
661 (EventHandlerRef
*)&m_macListCtrlEventHandler
);
667 wxListCtrl::~wxListCtrl()
671 m_genericImpl
->PopEventHandler(/* deleteHandler = */ true);
674 if (m_ownsImageListNormal
)
675 delete m_imageListNormal
;
676 if (m_ownsImageListSmall
)
677 delete m_imageListSmall
;
678 if (m_ownsImageListState
)
679 delete m_imageListState
;
681 delete m_renameTimer
;
684 // ----------------------------------------------------------------------------
685 // set/get/change style
686 // ----------------------------------------------------------------------------
688 // Add or remove a single window style
689 void wxListCtrl::SetSingleStyle(long style
, bool add
)
691 long flag
= GetWindowStyleFlag();
693 // Get rid of conflicting styles
696 if ( style
& wxLC_MASK_TYPE
)
697 flag
= flag
& ~wxLC_MASK_TYPE
;
698 if ( style
& wxLC_MASK_ALIGN
)
699 flag
= flag
& ~wxLC_MASK_ALIGN
;
700 if ( style
& wxLC_MASK_SORT
)
701 flag
= flag
& ~wxLC_MASK_SORT
;
709 SetWindowStyleFlag(flag
);
712 // Set the whole window style
713 void wxListCtrl::SetWindowStyleFlag(long flag
)
715 if ( flag
!= m_windowStyle
)
717 m_windowStyle
= flag
;
721 m_genericImpl
->SetWindowStyleFlag(flag
);
728 void wxListCtrl::DoSetSize( int x
, int y
, int width
, int height
, int sizeFlags
)
730 wxControl::DoSetSize(x
, y
, width
, height
, sizeFlags
);
733 m_genericImpl
->SetSize(0, 0, width
, height
, sizeFlags
);
735 // determine if we need a horizontal scrollbar, and add it if so
739 for (int column
= 0; column
< GetColumnCount(); column
++)
741 totalWidth
+= m_dbImpl
->GetColumnWidth( column
);
744 Boolean vertScrollBar
;
745 GetDataBrowserHasScrollBars( m_dbImpl
->GetControlRef(), NULL
, &vertScrollBar
);
746 if (totalWidth
> width
)
747 SetDataBrowserHasScrollBars( m_dbImpl
->GetControlRef(), true, vertScrollBar
);
749 SetDataBrowserHasScrollBars( m_dbImpl
->GetControlRef(), false, vertScrollBar
);
753 wxSize
wxListCtrl::DoGetBestSize() const
755 return wxWindow::DoGetBestSize();
758 bool wxListCtrl::SetFont(const wxFont
& font
)
761 rv
= wxControl::SetFont(font
);
763 rv
= m_genericImpl
->SetFont(font
);
767 bool wxListCtrl::SetForegroundColour(const wxColour
& colour
)
771 rv
= m_genericImpl
->SetForegroundColour(colour
);
773 SetTextColour(colour
);
777 bool wxListCtrl::SetBackgroundColour(const wxColour
& colour
)
781 rv
= m_genericImpl
->SetBackgroundColour(colour
);
787 wxColour
wxListCtrl::GetBackgroundColour()
790 return m_genericImpl
->GetBackgroundColour();
797 // ----------------------------------------------------------------------------
799 // ----------------------------------------------------------------------------
801 // Gets information about this column
802 bool wxListCtrl::GetColumn(int col
, wxListItem
& item
) const
805 return m_genericImpl
->GetColumn(col
, item
);
811 wxColumnList::compatibility_iterator node
= m_colsInfo
.Item( col
);
812 wxASSERT_MSG( node
, _T("invalid column index in wxMacListCtrlItem") );
813 wxListItem
* column
= node
->GetData();
815 long mask
= column
->GetMask();
816 if (mask
& wxLIST_MASK_TEXT
)
817 item
.SetText(column
->GetText());
818 if (mask
& wxLIST_MASK_DATA
)
819 item
.SetData(column
->GetData());
820 if (mask
& wxLIST_MASK_IMAGE
)
821 item
.SetImage(column
->GetImage());
822 if (mask
& wxLIST_MASK_STATE
)
823 item
.SetState(column
->GetState());
824 if (mask
& wxLIST_MASK_FORMAT
)
825 item
.SetAlign(column
->GetAlign());
826 if (mask
& wxLIST_MASK_WIDTH
)
827 item
.SetWidth(column
->GetWidth());
833 // Sets information about this column
834 bool wxListCtrl::SetColumn(int col
, wxListItem
& item
)
837 return m_genericImpl
->SetColumn(col
, item
);
841 long mask
= item
.GetMask();
842 if ( col
>= (int)m_colsInfo
.GetCount() )
844 wxListItem
* listItem
= new wxListItem(item
);
845 m_colsInfo
.Append( listItem
);
850 GetColumn( col
, listItem
);
852 if (mask
& wxLIST_MASK_TEXT
)
853 listItem
.SetText(item
.GetText());
854 if (mask
& wxLIST_MASK_DATA
)
855 listItem
.SetData(item
.GetData());
856 if (mask
& wxLIST_MASK_IMAGE
)
857 listItem
.SetImage(item
.GetImage());
858 if (mask
& wxLIST_MASK_STATE
)
859 listItem
.SetState(item
.GetState());
860 if (mask
& wxLIST_MASK_FORMAT
)
861 listItem
.SetAlign(item
.GetAlign());
862 if (mask
& wxLIST_MASK_WIDTH
)
863 listItem
.SetWidth(item
.GetWidth());
866 // change the appearance in the databrowser.
867 DataBrowserListViewHeaderDesc columnDesc
;
868 columnDesc
.version
=kDataBrowserListViewLatestHeaderDesc
;
869 verify_noerr( m_dbImpl
->GetHeaderDesc( kMinColumnId
+ col
, &columnDesc
) );
872 if (item.GetMask() & wxLIST_MASK_TEXT)
876 enc = m_font.GetEncoding();
878 enc = wxLocale::GetSystemEncoding();
879 wxMacCFStringHolder cfTitle;
880 cfTitle.Assign( item.GetText() , enc );
881 if(columnDesc.titleString)
882 CFRelease(columnDesc.titleString);
883 columnDesc.titleString = cfTitle;
887 if (item
.GetMask() & wxLIST_MASK_IMAGE
&& item
.GetImage() != -1 )
889 columnDesc
.btnContentInfo
.contentType
= kControlContentIconRef
;
890 wxImageList
* imageList
= GetImageList(wxIMAGE_LIST_SMALL
);
891 if (imageList
&& imageList
->GetImageCount() > 0 )
893 wxBitmap bmp
= imageList
->GetBitmap( item
.GetImage() );
894 IconRef icon
= bmp
.GetBitmapData()->GetIconRef();
895 columnDesc
.btnContentInfo
.u
.iconRef
= icon
;
899 verify_noerr( m_dbImpl
->SetHeaderDesc( kMinColumnId
+ col
, &columnDesc
) );
905 int wxListCtrl::GetColumnCount() const
908 return m_genericImpl
->GetColumnCount();
913 m_dbImpl
->GetColumnCount(&count
);
920 // Gets the column width
921 int wxListCtrl::GetColumnWidth(int col
) const
924 return m_genericImpl
->GetColumnWidth(col
);
928 return m_dbImpl
->GetColumnWidth(col
);
934 // Sets the column width
935 bool wxListCtrl::SetColumnWidth(int col
, int width
)
938 return m_genericImpl
->SetColumnWidth(col
, width
);
943 if (width
== wxLIST_AUTOSIZE
|| width
== wxLIST_AUTOSIZE_USEHEADER
)
948 for (int column
= 0; column
< GetColumnCount(); column
++)
951 GetColumn(col
, colInfo
);
953 colInfo
.SetWidth(width
);
954 SetColumn(col
, colInfo
);
956 m_dbImpl
->SetColumnWidth(col
, mywidth
);
962 GetColumn(col
, colInfo
);
964 colInfo
.SetWidth(width
);
965 SetColumn(col
, colInfo
);
966 m_dbImpl
->SetColumnWidth(col
, mywidth
);
974 // Gets the number of items that can fit vertically in the
975 // visible area of the list control (list or report view)
976 // or the total number of items in the list control (icon
977 // or small icon view)
978 int wxListCtrl::GetCountPerPage() const
981 return m_genericImpl
->GetCountPerPage();
990 // Gets the edit control for editing labels.
991 wxTextCtrl
* wxListCtrl::GetEditControl() const
994 return m_genericImpl
->GetEditControl();
999 // Gets information about the item
1000 bool wxListCtrl::GetItem(wxListItem
& info
) const
1003 return m_genericImpl
->GetItem(info
);
1008 m_dbImpl
->MacGetColumnInfo(info
.m_itemId
, info
.m_col
, info
);
1011 info
.SetText( OnGetItemText(info
.m_itemId
, info
.m_col
) );
1012 info
.SetImage( OnGetItemColumnImage(info
.m_itemId
, info
.m_col
) );
1013 if (info
.GetMask() & wxLIST_MASK_STATE
)
1015 if (IsDataBrowserItemSelected( m_dbImpl
->GetControlRef(), info
.m_itemId
+1 ))
1016 info
.SetState(info
.GetState() | wxLIST_STATE_SELECTED
);
1019 wxListItemAttr
* attrs
= OnGetItemAttr( info
.m_itemId
);
1022 info
.SetFont( attrs
->GetFont() );
1023 info
.SetBackgroundColour( attrs
->GetBackgroundColour() );
1024 info
.SetTextColour( attrs
->GetTextColour() );
1028 bool success
= true;
1032 // Sets information about the item
1033 bool wxListCtrl::SetItem(wxListItem
& info
)
1036 return m_genericImpl
->SetItem(info
);
1039 m_dbImpl
->MacSetColumnInfo( info
.m_itemId
, info
.m_col
, &info
);
1044 long wxListCtrl::SetItem(long index
, int col
, const wxString
& label
, int imageId
)
1047 return m_genericImpl
->SetItem(index
, col
, label
, imageId
);
1050 info
.m_text
= label
;
1051 info
.m_mask
= wxLIST_MASK_TEXT
;
1052 info
.m_itemId
= index
;
1056 info
.m_image
= imageId
;
1057 info
.m_mask
|= wxLIST_MASK_IMAGE
;
1059 return SetItem(info
);
1063 // Gets the item state
1064 int wxListCtrl::GetItemState(long item
, long stateMask
) const
1067 return m_genericImpl
->GetItemState(item
, stateMask
);
1071 if ( HasFlag(wxLC_VIRTUAL
) )
1073 if (stateMask
== wxLIST_STATE_SELECTED
)
1075 if (IsDataBrowserItemSelected( m_dbImpl
->GetControlRef(), item
+1 ))
1076 return wxLIST_STATE_SELECTED
;
1085 info
.m_mask
= wxLIST_MASK_STATE
;
1086 info
.m_stateMask
= stateMask
;
1087 info
.m_itemId
= item
;
1092 return info
.m_state
;
1099 // Sets the item state
1100 bool wxListCtrl::SetItemState(long item
, long state
, long stateMask
)
1103 return m_genericImpl
->SetItemState(item
, state
, stateMask
);
1107 DataBrowserSetOption option
= kDataBrowserItemsAdd
;
1108 if ( stateMask
== wxLIST_STATE_SELECTED
&& state
== 0 )
1109 option
= kDataBrowserItemsRemove
;
1113 if ( HasFlag(wxLC_VIRTUAL
) )
1115 wxMacDataItemBrowserSelectionSuppressor
suppressor(m_dbImpl
);
1116 m_dbImpl
->SetSelectedAllItems(option
);
1120 for(int i
= 0; i
< GetItemCount();i
++)
1124 info
.m_mask
= wxLIST_MASK_STATE
;
1125 info
.m_stateMask
= stateMask
;
1126 info
.m_state
= state
;
1133 if ( HasFlag(wxLC_VIRTUAL
) )
1135 long itemID
= item
+1;
1136 SetDataBrowserSelectedItems(m_dbImpl
->GetControlRef(), 1, (DataBrowserItemID
*)&itemID
, option
);
1141 info
.m_itemId
= item
;
1142 info
.m_mask
= wxLIST_MASK_STATE
;
1143 info
.m_stateMask
= stateMask
;
1144 info
.m_state
= state
;
1145 return SetItem(info
);
1152 // Sets the item image
1153 bool wxListCtrl::SetItemImage(long item
, int image
, int WXUNUSED(selImage
))
1155 return SetItemColumnImage(item
, 0, image
);
1158 // Sets the item image
1159 bool wxListCtrl::SetItemColumnImage(long item
, long column
, int image
)
1162 return m_genericImpl
->SetItemColumnImage(item
, column
, image
);
1166 info
.m_mask
= wxLIST_MASK_IMAGE
;
1167 info
.m_image
= image
;
1168 info
.m_itemId
= item
;
1169 info
.m_col
= column
;
1171 return SetItem(info
);
1174 // Gets the item text
1175 wxString
wxListCtrl::GetItemText(long item
) const
1178 return m_genericImpl
->GetItemText(item
);
1182 info
.m_mask
= wxLIST_MASK_TEXT
;
1183 info
.m_itemId
= item
;
1186 return wxEmptyString
;
1190 // Sets the item text
1191 void wxListCtrl::SetItemText(long item
, const wxString
& str
)
1194 return m_genericImpl
->SetItemText(item
, str
);
1198 info
.m_mask
= wxLIST_MASK_TEXT
;
1199 info
.m_itemId
= item
;
1205 // Gets the item data
1206 long wxListCtrl::GetItemData(long item
) const
1209 return m_genericImpl
->GetItemData(item
);
1213 info
.m_mask
= wxLIST_MASK_DATA
;
1214 info
.m_itemId
= item
;
1221 // Sets the item data
1222 bool wxListCtrl::SetItemData(long item
, long data
)
1225 return m_genericImpl
->SetItemData(item
, data
);
1229 info
.m_mask
= wxLIST_MASK_DATA
;
1230 info
.m_itemId
= item
;
1233 return SetItem(info
);
1236 wxRect
wxListCtrl::GetViewRect() const
1238 wxASSERT_MSG( !HasFlag(wxLC_REPORT
| wxLC_LIST
),
1239 _T("wxListCtrl::GetViewRect() only works in icon mode") );
1242 return m_genericImpl
->GetViewRect();
1248 // Gets the item rectangle
1249 bool wxListCtrl::GetItemRect(long item
, wxRect
& rect
, int code
) const
1252 return m_genericImpl
->GetItemRect(item
, rect
, code
);
1257 DataBrowserItemID id
;
1258 DataBrowserPropertyID col
= kMinColumnId
;
1260 DataBrowserPropertyPart part
= kDataBrowserPropertyEnclosingPart
;
1261 if ( code
== wxLIST_RECT_LABEL
)
1262 part
= kDataBrowserPropertyTextPart
;
1263 else if ( code
== wxLIST_RECT_ICON
)
1264 part
= kDataBrowserPropertyIconPart
;
1266 if ( !(GetWindowStyleFlag() & wxLC_VIRTUAL
) )
1268 wxMacDataItem
* thisItem
= m_dbImpl
->GetItemFromLine(item
);
1269 id
= (DataBrowserItemID
) thisItem
;
1274 GetDataBrowserItemPartBounds( m_dbImpl
->GetControlRef(), id
, col
, part
, &bounds
);
1276 rect
.x
= bounds
.left
;
1277 rect
.y
= bounds
.top
;
1278 rect
.width
= bounds
.right
- bounds
.left
; //GetClientSize().x; // we need the width of the whole row, not just the item.
1279 rect
.height
= bounds
.bottom
- bounds
.top
;
1280 //fprintf("id = %d, bounds = %d, %d, %d, %d\n", id, rect.x, rect.y, rect.width, rect.height);
1285 // Gets the item position
1286 bool wxListCtrl::GetItemPosition(long item
, wxPoint
& pos
) const
1289 return m_genericImpl
->GetItemPosition(item
, pos
);
1291 bool success
= false;
1296 GetItemRect(item
, itemRect
);
1297 pos
= itemRect
.GetPosition();
1304 // Sets the item position.
1305 bool wxListCtrl::SetItemPosition(long item
, const wxPoint
& pos
)
1308 return m_genericImpl
->SetItemPosition(item
, pos
);
1313 // Gets the number of items in the list control
1314 int wxListCtrl::GetItemCount() const
1317 return m_genericImpl
->GetItemCount();
1320 return m_dbImpl
->MacGetCount();
1325 void wxListCtrl::SetItemSpacing( int spacing
, bool isSmall
)
1328 m_genericImpl
->SetItemSpacing(spacing
, isSmall
);
1331 wxSize
wxListCtrl::GetItemSpacing() const
1334 return m_genericImpl
->GetItemSpacing();
1336 return wxSize(0, 0);
1339 void wxListCtrl::SetItemTextColour( long item
, const wxColour
&col
)
1343 m_genericImpl
->SetItemTextColour(item
, col
);
1348 info
.m_itemId
= item
;
1349 info
.SetTextColour( col
);
1353 wxColour
wxListCtrl::GetItemTextColour( long item
) const
1356 return m_genericImpl
->GetItemTextColour(item
);
1362 return info
.GetTextColour();
1364 return wxNullColour
;
1367 void wxListCtrl::SetItemBackgroundColour( long item
, const wxColour
&col
)
1371 m_genericImpl
->SetItemBackgroundColour(item
, col
);
1376 info
.m_itemId
= item
;
1377 info
.SetBackgroundColour( col
);
1381 wxColour
wxListCtrl::GetItemBackgroundColour( long item
) const
1384 return m_genericImpl
->GetItemBackgroundColour(item
);
1390 return info
.GetBackgroundColour();
1392 return wxNullColour
;
1395 void wxListCtrl::SetItemFont( long item
, const wxFont
&f
)
1399 m_genericImpl
->SetItemFont(item
, f
);
1404 info
.m_itemId
= item
;
1409 wxFont
wxListCtrl::GetItemFont( long item
) const
1412 return m_genericImpl
->GetItemFont(item
);
1418 return info
.GetFont();
1424 // Gets the number of selected items in the list control
1425 int wxListCtrl::GetSelectedItemCount() const
1428 return m_genericImpl
->GetSelectedItemCount();
1431 return m_dbImpl
->GetSelectedItemCount(NULL
, true);
1436 // Gets the text colour of the listview
1437 wxColour
wxListCtrl::GetTextColour() const
1440 return m_genericImpl
->GetTextColour();
1442 // TODO: we need owner drawn list items to customize text color.
1446 return wxNullColour
;
1449 // Sets the text colour of the listview
1450 void wxListCtrl::SetTextColour(const wxColour
& col
)
1454 m_genericImpl
->SetTextColour(col
);
1462 // Gets the index of the topmost visible item when in
1463 // list or report view
1464 long wxListCtrl::GetTopItem() const
1467 return m_genericImpl
->GetTopItem();
1472 long item
= HitTest( wxPoint(1, 1), flags
);
1473 if (flags
== wxLIST_HITTEST_ONITEM
)
1480 // Searches for an item, starting from 'item'.
1481 // 'geometry' is one of
1482 // wxLIST_NEXT_ABOVE/ALL/BELOW/LEFT/RIGHT.
1483 // 'state' is a state bit flag, one or more of
1484 // wxLIST_STATE_DROPHILITED/FOCUSED/SELECTED/CUT.
1485 // item can be -1 to find the first item that matches the
1487 // Returns the item or -1 if unsuccessful.
1488 long wxListCtrl::GetNextItem(long item
, int geom
, int state
) const
1491 return m_genericImpl
->GetNextItem(item
, geom
, state
);
1493 if (m_dbImpl
&& geom
== wxLIST_NEXT_ALL
&& state
== wxLIST_STATE_SELECTED
)
1495 long count
= m_dbImpl
->MacGetCount() ;
1496 for ( long line
= item
+ 1 ; line
< count
; line
++ )
1498 wxMacDataItem
* id
= m_dbImpl
->GetItemFromLine(line
);
1499 if ( m_dbImpl
->IsItemSelected(id
) )
1509 wxImageList
*wxListCtrl::GetImageList(int which
) const
1512 return m_genericImpl
->GetImageList(which
);
1514 if ( which
== wxIMAGE_LIST_NORMAL
)
1516 return m_imageListNormal
;
1518 else if ( which
== wxIMAGE_LIST_SMALL
)
1520 return m_imageListSmall
;
1522 else if ( which
== wxIMAGE_LIST_STATE
)
1524 return m_imageListState
;
1529 void wxListCtrl::SetImageList(wxImageList
*imageList
, int which
)
1533 m_genericImpl
->SetImageList(imageList
, which
);
1537 if ( which
== wxIMAGE_LIST_NORMAL
)
1539 if (m_ownsImageListNormal
) delete m_imageListNormal
;
1540 m_imageListNormal
= imageList
;
1541 m_ownsImageListNormal
= false;
1543 else if ( which
== wxIMAGE_LIST_SMALL
)
1545 if (m_ownsImageListSmall
) delete m_imageListSmall
;
1546 m_imageListSmall
= imageList
;
1547 m_ownsImageListSmall
= false;
1549 else if ( which
== wxIMAGE_LIST_STATE
)
1551 if (m_ownsImageListState
) delete m_imageListState
;
1552 m_imageListState
= imageList
;
1553 m_ownsImageListState
= false;
1557 void wxListCtrl::AssignImageList(wxImageList
*imageList
, int which
)
1561 m_genericImpl
->AssignImageList(imageList
, which
);
1565 SetImageList(imageList
, which
);
1566 if ( which
== wxIMAGE_LIST_NORMAL
)
1567 m_ownsImageListNormal
= true;
1568 else if ( which
== wxIMAGE_LIST_SMALL
)
1569 m_ownsImageListSmall
= true;
1570 else if ( which
== wxIMAGE_LIST_STATE
)
1571 m_ownsImageListState
= true;
1574 // ----------------------------------------------------------------------------
1576 // ----------------------------------------------------------------------------
1578 // Arranges the items
1579 bool wxListCtrl::Arrange(int flag
)
1582 return m_genericImpl
->Arrange(flag
);
1587 bool wxListCtrl::DeleteItem(long item
)
1590 return m_genericImpl
->DeleteItem(item
);
1594 m_dbImpl
->MacDelete(item
);
1595 wxListEvent
event( wxEVT_COMMAND_LIST_DELETE_ITEM
, GetId() );
1596 event
.SetEventObject( this );
1597 event
.m_itemIndex
= item
;
1598 GetEventHandler()->ProcessEvent( event
);
1604 // Deletes all items
1605 bool wxListCtrl::DeleteAllItems()
1608 return m_genericImpl
->DeleteAllItems();
1612 m_dbImpl
->MacClear();
1613 wxListEvent
event( wxEVT_COMMAND_LIST_DELETE_ALL_ITEMS
, GetId() );
1614 event
.SetEventObject( this );
1615 GetEventHandler()->ProcessEvent( event
);
1620 // Deletes all items
1621 bool wxListCtrl::DeleteAllColumns()
1624 return m_genericImpl
->DeleteAllColumns();
1629 m_dbImpl
->GetColumnCount(&cols
);
1630 for (UInt32 col
= 0; col
< cols
; col
++)
1640 bool wxListCtrl::DeleteColumn(int col
)
1643 return m_genericImpl
->DeleteColumn(col
);
1647 OSStatus err
= m_dbImpl
->RemoveColumn(col
);
1648 return err
== noErr
;
1654 // Clears items, and columns if there are any.
1655 void wxListCtrl::ClearAll()
1659 m_genericImpl
->ClearAll();
1670 wxTextCtrl
* wxListCtrl::EditLabel(long item
, wxClassInfo
* textControlClass
)
1673 return m_genericImpl
->EditLabel(item
, textControlClass
);
1677 wxCHECK_MSG( (item
>= 0) && ((long)item
< GetItemCount()), NULL
,
1678 wxT("wrong index in wxListCtrl::EditLabel()") );
1680 wxASSERT_MSG( textControlClass
->IsKindOf(CLASSINFO(wxTextCtrl
)),
1681 wxT("EditLabel() needs a text control") );
1683 wxListEvent
le( wxEVT_COMMAND_LIST_BEGIN_LABEL_EDIT
, GetParent()->GetId() );
1684 le
.SetEventObject( this );
1685 le
.m_itemIndex
= item
;
1687 GetItem( le
.m_item
);
1689 if ( GetParent()->GetEventHandler()->ProcessEvent( le
) && !le
.IsAllowed() )
1691 // vetoed by user code
1695 wxTextCtrl
* const text
= (wxTextCtrl
*)textControlClass
->CreateObject();
1696 m_textctrlWrapper
= new wxListCtrlTextCtrlWrapper(this, text
, item
);
1697 return m_textctrlWrapper
->GetText();
1702 // End label editing, optionally cancelling the edit
1703 bool wxListCtrl::EndEditLabel(bool cancel
)
1705 // TODO: generic impl. doesn't have this method - is it needed for us?
1707 return true; // m_genericImpl->EndEditLabel(cancel);
1710 verify_noerr( SetDataBrowserEditItem(m_dbImpl
->GetControlRef(), kDataBrowserNoItem
, kMinColumnId
) );
1714 // Ensures this item is visible
1715 bool wxListCtrl::EnsureVisible(long item
)
1718 return m_genericImpl
->EnsureVisible(item
);
1722 wxMacDataItem
* dataItem
= m_dbImpl
->GetItemFromLine(item
);
1723 m_dbImpl
->RevealItem(dataItem
, kDataBrowserRevealWithoutSelecting
);
1729 // Find an item whose label matches this string, starting from the item after 'start'
1730 // or the beginning if 'start' is -1.
1731 long wxListCtrl::FindItem(long start
, const wxString
& str
, bool partial
)
1734 return m_genericImpl
->FindItem(start
, str
, partial
);
1736 wxString str_upper
= str
.Upper();
1741 long count
= GetItemCount();
1745 wxString line_upper
= GetItemText(idx
).Upper();
1748 if (line_upper
== str_upper
)
1753 if (line_upper
.find(str_upper
) == 0)
1763 // Find an item whose data matches this data, starting from the item after 'start'
1764 // or the beginning if 'start' is -1.
1765 long wxListCtrl::FindItem(long start
, long data
)
1768 return m_genericImpl
->FindItem(start
, data
);
1773 long count
= GetItemCount();
1777 if (GetItemData(idx
) == data
)
1785 // Find an item nearest this position in the specified direction, starting from
1786 // the item after 'start' or the beginning if 'start' is -1.
1787 long wxListCtrl::FindItem(long start
, const wxPoint
& pt
, int direction
)
1790 return m_genericImpl
->FindItem(start
, pt
, direction
);
1794 // Determines which item (if any) is at the specified point,
1795 // giving details in 'flags' (see wxLIST_HITTEST_... flags above)
1797 wxListCtrl::HitTest(const wxPoint
& point
, int& flags
, long *ptrSubItem
) const
1800 return m_genericImpl
->HitTest(point
, flags
, ptrSubItem
);
1802 flags
= wxLIST_HITTEST_NOWHERE
;
1805 int colHeaderHeight
= 22; // TODO: Find a way to get this value from the db control?
1806 UInt16 rowHeight
= 0;
1807 m_dbImpl
->GetDefaultRowHeight(&rowHeight
);
1810 // get the actual row by taking scroll position into account
1811 UInt32 offsetX
, offsetY
;
1812 m_dbImpl
->GetScrollPosition( &offsetY
, &offsetX
);
1815 if ( !(GetWindowStyleFlag() & wxLC_NO_HEADER
) )
1816 y
-= colHeaderHeight
;
1821 int row
= y
/ rowHeight
;
1822 DataBrowserItemID id
;
1823 m_dbImpl
->GetItemID( (DataBrowserTableViewRowIndex
) row
, &id
);
1825 // TODO: Use GetDataBrowserItemPartBounds to return if we are in icon or label
1826 if ( !(GetWindowStyleFlag() & wxLC_VIRTUAL
) )
1828 wxMacListCtrlItem
* lcItem
;
1829 lcItem
= (wxMacListCtrlItem
*) id
;
1832 flags
= wxLIST_HITTEST_ONITEM
;
1838 if (row
< GetItemCount() )
1840 flags
= wxLIST_HITTEST_ONITEM
;
1849 int wxListCtrl::GetScrollPos(int orient
) const
1852 return m_genericImpl
->GetScrollPos(orient
);
1856 UInt32 offsetX
, offsetY
;
1857 m_dbImpl
->GetScrollPosition( &offsetY
, &offsetX
);
1858 if ( orient
== wxHORIZONTAL
)
1867 // Inserts an item, returning the index of the new item if successful,
1869 long wxListCtrl::InsertItem(wxListItem
& info
)
1871 wxASSERT_MSG( !IsVirtual(), _T("can't be used with virtual controls") );
1874 return m_genericImpl
->InsertItem(info
);
1876 if (m_dbImpl
&& !IsVirtual())
1878 int count
= GetItemCount();
1880 if (info
.m_itemId
> count
)
1881 info
.m_itemId
= count
;
1883 m_dbImpl
->MacInsertItem(info
.m_itemId
, &info
);
1884 wxMacDataItem
* dataItem
= m_dbImpl
->GetItemFromLine(info
.m_itemId
);
1886 wxListEvent
event( wxEVT_COMMAND_LIST_INSERT_ITEM
, GetId() );
1887 event
.SetEventObject( this );
1888 event
.m_itemIndex
= info
.m_itemId
;
1889 GetEventHandler()->ProcessEvent( event
);
1890 return info
.m_itemId
;
1895 long wxListCtrl::InsertItem(long index
, const wxString
& label
)
1898 return m_genericImpl
->InsertItem(index
, label
);
1901 info
.m_text
= label
;
1902 info
.m_mask
= wxLIST_MASK_TEXT
;
1903 info
.m_itemId
= index
;
1904 return InsertItem(info
);
1907 // Inserts an image item
1908 long wxListCtrl::InsertItem(long index
, int imageIndex
)
1911 return m_genericImpl
->InsertItem(index
, imageIndex
);
1914 info
.m_image
= imageIndex
;
1915 info
.m_mask
= wxLIST_MASK_IMAGE
;
1916 info
.m_itemId
= index
;
1917 return InsertItem(info
);
1920 // Inserts an image/string item
1921 long wxListCtrl::InsertItem(long index
, const wxString
& label
, int imageIndex
)
1924 return m_genericImpl
->InsertItem(index
, label
, imageIndex
);
1927 info
.m_image
= imageIndex
;
1928 info
.m_text
= label
;
1929 info
.m_mask
= wxLIST_MASK_IMAGE
| wxLIST_MASK_TEXT
;
1930 info
.m_itemId
= index
;
1931 return InsertItem(info
);
1934 // For list view mode (only), inserts a column.
1935 long wxListCtrl::InsertColumn(long col
, wxListItem
& item
)
1938 return m_genericImpl
->InsertColumn(col
, item
);
1942 int width
= item
.GetWidth();
1943 if ( !(item
.GetMask() & wxLIST_MASK_WIDTH
) )
1946 DataBrowserPropertyType type
= kDataBrowserCustomType
; //kDataBrowserTextType;
1947 wxImageList
* imageList
= GetImageList(wxIMAGE_LIST_SMALL
);
1948 if (imageList
&& imageList
->GetImageCount() > 0)
1950 wxBitmap bmp
= imageList
->GetBitmap(0);
1952 // type = kDataBrowserIconAndTextType;
1955 SInt16 just
= teFlushDefault
;
1956 if (item
.GetMask() & wxLIST_MASK_FORMAT
)
1958 if (item
.GetAlign() == wxLIST_FORMAT_LEFT
)
1960 else if (item
.GetAlign() == wxLIST_FORMAT_CENTER
)
1962 else if (item
.GetAlign() == wxLIST_FORMAT_RIGHT
)
1963 just
= teFlushRight
;
1965 m_dbImpl
->InsertColumn(col
, type
, item
.GetText(), just
, width
);
1966 SetColumn(col
, item
);
1968 // set/remove options based on the wxListCtrl type.
1969 DataBrowserTableViewColumnID id
;
1970 m_dbImpl
->GetColumnIDFromIndex(col
, &id
);
1971 DataBrowserPropertyFlags flags
;
1972 verify_noerr(m_dbImpl
->GetPropertyFlags(id
, &flags
));
1973 if (GetWindowStyleFlag() & wxLC_EDIT_LABELS
)
1974 flags
|= kDataBrowserPropertyIsEditable
;
1976 if (GetWindowStyleFlag() & wxLC_VIRTUAL
){
1977 flags
&= ~kDataBrowserListViewSortableColumn
;
1979 verify_noerr(m_dbImpl
->SetPropertyFlags(id
, flags
));
1985 long wxListCtrl::InsertColumn(long col
,
1986 const wxString
& heading
,
1991 return m_genericImpl
->InsertColumn(col
, heading
, format
, width
);
1994 item
.m_mask
= wxLIST_MASK_TEXT
| wxLIST_MASK_FORMAT
;
1995 item
.m_text
= heading
;
1998 item
.m_mask
|= wxLIST_MASK_WIDTH
;
1999 item
.m_width
= width
;
2001 item
.m_format
= format
;
2003 return InsertColumn(col
, item
);
2006 // scroll the control by the given number of pixels (exception: in list view,
2007 // dx is interpreted as number of columns)
2008 bool wxListCtrl::ScrollList(int dx
, int dy
)
2011 return m_genericImpl
->ScrollList(dx
, dy
);
2015 m_dbImpl
->SetScrollPosition(dx
, dy
);
2021 bool wxListCtrl::SortItems(wxListCtrlCompare fn
, long data
)
2024 return m_genericImpl
->SortItems(fn
, data
);
2029 m_compareFuncData
= data
;
2030 SortDataBrowserContainer( m_dbImpl
->GetControlRef(), kDataBrowserNoItem
, true);
2032 // we need to do this after each call, else we get a crash from wxPython when
2033 // SortItems is called the second time.
2034 m_compareFunc
= NULL
;
2035 m_compareFuncData
= 0;
2041 void wxListCtrl::OnRenameTimer()
2043 wxCHECK_RET( HasCurrent(), wxT("unexpected rename timer") );
2045 EditLabel( m_current
);
2048 bool wxListCtrl::OnRenameAccept(long itemEdit
, const wxString
& value
)
2050 wxListEvent
le( wxEVT_COMMAND_LIST_END_LABEL_EDIT
, GetId() );
2051 le
.SetEventObject( this );
2052 le
.m_itemIndex
= itemEdit
;
2054 GetItem( le
.m_item
);
2055 le
.m_item
.m_text
= value
;
2056 return !GetEventHandler()->ProcessEvent( le
) ||
2060 void wxListCtrl::OnRenameCancelled(long itemEdit
)
2062 // let owner know that the edit was cancelled
2063 wxListEvent
le( wxEVT_COMMAND_LIST_END_LABEL_EDIT
, GetParent()->GetId() );
2065 le
.SetEditCanceled(true);
2067 le
.SetEventObject( this );
2068 le
.m_itemIndex
= itemEdit
;
2070 GetItem( le
.m_item
);
2071 GetEventHandler()->ProcessEvent( le
);
2074 // ----------------------------------------------------------------------------
2075 // virtual list controls
2076 // ----------------------------------------------------------------------------
2078 wxString
wxListCtrl::OnGetItemText(long WXUNUSED(item
), long WXUNUSED(col
)) const
2080 // this is a pure virtual function, in fact - which is not really pure
2081 // because the controls which are not virtual don't need to implement it
2082 wxFAIL_MSG( _T("wxListCtrl::OnGetItemText not supposed to be called") );
2084 return wxEmptyString
;
2087 int wxListCtrl::OnGetItemImage(long WXUNUSED(item
)) const
2089 wxCHECK_MSG(!GetImageList(wxIMAGE_LIST_SMALL
),
2091 wxT("List control has an image list, OnGetItemImage or OnGetItemColumnImage should be overridden."));
2095 int wxListCtrl::OnGetItemColumnImage(long item
, long column
) const
2098 return OnGetItemImage(item
);
2103 wxListItemAttr
*wxListCtrl::OnGetItemAttr(long WXUNUSED_UNLESS_DEBUG(item
)) const
2105 wxASSERT_MSG( item
>= 0 && item
< GetItemCount(),
2106 _T("invalid item index in OnGetItemAttr()") );
2108 // no attributes by default
2112 void wxListCtrl::SetItemCount(long count
)
2114 wxASSERT_MSG( IsVirtual(), _T("this is for virtual controls only") );
2118 m_genericImpl
->SetItemCount(count
);
2124 // we need to temporarily disable the new item creation notification
2125 // procedure to speed things up
2126 // FIXME: Even this doesn't seem to help much...
2128 // FIXME: Find a more efficient way to do this.
2129 m_dbImpl
->MacClear();
2131 DataBrowserCallbacks callbacks
;
2132 DataBrowserItemNotificationUPP itemUPP
;
2133 GetDataBrowserCallbacks(m_dbImpl
->GetControlRef(), &callbacks
);
2134 itemUPP
= callbacks
.u
.v1
.itemNotificationCallback
;
2135 callbacks
.u
.v1
.itemNotificationCallback
= 0;
2136 m_dbImpl
->SetCallbacks(&callbacks
);
2137 ::AddDataBrowserItems(m_dbImpl
->GetControlRef(), kDataBrowserNoItem
,
2138 count
, NULL
, kDataBrowserItemNoProperty
);
2139 callbacks
.u
.v1
.itemNotificationCallback
= itemUPP
;
2140 m_dbImpl
->SetCallbacks(&callbacks
);
2145 void wxListCtrl::RefreshItem(long item
)
2149 m_genericImpl
->RefreshItem(item
);
2154 GetItemRect(item
, rect
);
2158 void wxListCtrl::RefreshItems(long itemFrom
, long itemTo
)
2162 m_genericImpl
->RefreshItems(itemFrom
, itemTo
);
2166 wxRect rect1
, rect2
;
2167 GetItemRect(itemFrom
, rect1
);
2168 GetItemRect(itemTo
, rect2
);
2170 wxRect rect
= rect1
;
2171 rect
.height
= rect2
.GetBottom() - rect1
.GetTop();
2176 void wxListCtrl::SetDropTarget( wxDropTarget
*dropTarget
)
2178 #if wxUSE_DRAG_AND_DROP
2180 m_genericImpl
->SetDropTarget( dropTarget
);
2183 wxWindow::SetDropTarget( dropTarget
);
2187 wxDropTarget
*wxListCtrl::GetDropTarget() const
2189 #if wxUSE_DRAG_AND_DROP
2191 return m_genericImpl
->GetDropTarget();
2194 return wxWindow::GetDropTarget();
2199 // wxMac internal data structures
2201 wxMacListCtrlItem::~wxMacListCtrlItem()
2205 void wxMacListCtrlItem::Notification(wxMacDataItemBrowserControl
*owner
,
2206 DataBrowserItemNotification message
,
2207 DataBrowserItemDataRef itemData
) const
2210 wxMacDataBrowserListCtrlControl
*lb
= dynamic_cast<wxMacDataBrowserListCtrlControl
*>(owner
);
2212 // we want to depend on as little as possible to make sure tear-down of controls is safe
2213 if ( message
== kDataBrowserItemRemoved
)
2215 if ( lb
!= NULL
&& lb
->GetClientDataType() == wxClientData_Object
)
2217 delete (wxClientData
*) (m_data
);
2223 else if ( message
== kDataBrowserItemAdded
)
2225 // we don't issue events on adding, the item is not really stored in the list yet, so we
2226 // avoid asserts by gettting out now
2230 wxListCtrl
*list
= wxDynamicCast( owner
->GetPeer() , wxListCtrl
);
2233 bool trigger
= false;
2235 wxListEvent
event( wxEVT_COMMAND_LIST_ITEM_SELECTED
, list
->GetId() );
2236 bool isSingle
= (list
->GetWindowStyle() & wxLC_SINGLE_SEL
) != 0;
2238 event
.SetEventObject( list
);
2239 event
.m_itemIndex
= owner
->GetLineFromItem( this ) ;
2240 if ( !list
->IsVirtual() )
2242 lb
->MacGetColumnInfo(event
.m_itemIndex
,0,event
.m_item
);
2247 case kDataBrowserItemDeselected
:
2248 event
.SetEventType(wxEVT_COMMAND_LIST_ITEM_DESELECTED
);
2250 trigger
= !lb
->IsSelectionSuppressed();
2253 case kDataBrowserItemSelected
:
2254 trigger
= !lb
->IsSelectionSuppressed();
2257 case kDataBrowserItemDoubleClicked
:
2258 event
.SetEventType( wxEVT_COMMAND_LIST_ITEM_ACTIVATED
);
2262 case kDataBrowserEditStarted
:
2263 // TODO : how to veto ?
2264 event
.SetEventType( wxEVT_COMMAND_LIST_BEGIN_LABEL_EDIT
) ;
2268 case kDataBrowserEditStopped
:
2269 // TODO probably trigger only upon the value store callback, because
2270 // here IIRC we cannot veto
2271 event
.SetEventType( wxEVT_COMMAND_LIST_END_LABEL_EDIT
) ;
2281 // direct notification is not always having the listbox GetSelection() having in synch with event
2282 wxPostEvent( list
->GetEventHandler(), event
);
2288 wxMacDataBrowserListCtrlControl::wxMacDataBrowserListCtrlControl( wxWindow
*peer
, const wxPoint
& pos
, const wxSize
& size
, long style
)
2289 : wxMacDataItemBrowserControl( peer
, pos
, size
, style
)
2291 OSStatus err
= noErr
;
2292 m_clientDataItemsType
= wxClientData_None
;
2293 m_isVirtual
= false;
2295 if ( style
& wxLC_VIRTUAL
)
2298 DataBrowserSelectionFlags options
= kDataBrowserDragSelect
;
2299 if ( style
& wxLC_SINGLE_SEL
)
2301 options
|= kDataBrowserSelectOnlyOne
;
2305 options
|= kDataBrowserCmdTogglesSelection
;
2308 err
= SetSelectionFlags( options
);
2309 verify_noerr( err
);
2311 DataBrowserCustomCallbacks callbacks
;
2312 InitializeDataBrowserCustomCallbacks( &callbacks
, kDataBrowserLatestCustomCallbacks
);
2314 if ( gDataBrowserDrawItemUPP
== NULL
)
2315 gDataBrowserDrawItemUPP
= NewDataBrowserDrawItemUPP(DataBrowserDrawItemProc
);
2317 if ( gDataBrowserHitTestUPP
== NULL
)
2318 gDataBrowserHitTestUPP
= NewDataBrowserHitTestUPP(DataBrowserHitTestProc
);
2320 callbacks
.u
.v1
.drawItemCallback
= gDataBrowserDrawItemUPP
;
2321 callbacks
.u
.v1
.hitTestCallback
= gDataBrowserHitTestUPP
;
2323 SetDataBrowserCustomCallbacks( GetControlRef(), &callbacks
);
2325 if ( style
& wxLC_LIST
)
2327 InsertColumn(0, kDataBrowserIconAndTextType
, wxEmptyString
, -1, -1);
2328 verify_noerr( AutoSizeColumns() );
2331 if ( style
& wxLC_LIST
|| style
& wxLC_NO_HEADER
)
2332 verify_noerr( SetHeaderButtonHeight( 0 ) );
2335 SetSortProperty( kMinColumnId
- 1 );
2337 SetSortProperty( kMinColumnId
);
2338 if ( style
& wxLC_SORT_ASCENDING
)
2340 m_sortOrder
= SortOrder_Text_Ascending
;
2341 SetSortOrder( kDataBrowserOrderIncreasing
);
2343 else if ( style
& wxLC_SORT_DESCENDING
)
2345 m_sortOrder
= SortOrder_Text_Descending
;
2346 SetSortOrder( kDataBrowserOrderDecreasing
);
2350 m_sortOrder
= SortOrder_None
;
2353 if ( style
& wxLC_VRULES
)
2355 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4
2356 verify_noerr( DataBrowserChangeAttributes(m_controlRef
, kDataBrowserAttributeListViewDrawColumnDividers
, kDataBrowserAttributeNone
) );
2360 verify_noerr( SetHiliteStyle(kDataBrowserTableViewFillHilite
) );
2361 err
= SetHasScrollBars( (style
& wxHSCROLL
) != 0 , true );
2364 pascal Boolean
wxMacDataBrowserListCtrlControl::DataBrowserEditTextProc(
2366 DataBrowserItemID itemID
,
2367 DataBrowserPropertyID property
,
2368 CFStringRef theString
,
2369 Rect
*maxEditTextRect
,
2370 Boolean
*shrinkToFit
)
2372 Boolean result
= false;
2373 wxMacDataBrowserListCtrlControl
* ctl
= dynamic_cast<wxMacDataBrowserListCtrlControl
*>( wxMacControl::GetReferenceFromNativeControl( browser
) );
2376 result
= ctl
->ConfirmEditText(itemID
, property
, theString
, maxEditTextRect
, shrinkToFit
);
2377 theString
= CFSTR("Hello!");
2382 bool wxMacDataBrowserListCtrlControl::ConfirmEditText(
2383 DataBrowserItemID itemID
,
2384 DataBrowserPropertyID property
,
2385 CFStringRef theString
,
2386 Rect
*maxEditTextRect
,
2387 Boolean
*shrinkToFit
)
2392 pascal void wxMacDataBrowserListCtrlControl::DataBrowserDrawItemProc(
2394 DataBrowserItemID itemID
,
2395 DataBrowserPropertyID property
,
2396 DataBrowserItemState itemState
,
2397 const Rect
*itemRect
,
2399 Boolean colorDevice
)
2401 wxMacDataBrowserListCtrlControl
* ctl
= dynamic_cast<wxMacDataBrowserListCtrlControl
*>( wxMacControl::GetReferenceFromNativeControl( browser
) );
2404 ctl
->DrawItem(itemID
, property
, itemState
, itemRect
, gdDepth
, colorDevice
);
2408 // routines needed for DrawItem
2413 kTextBoxHeight
= 14,
2414 kIconTextSpacingV
= 2,
2416 kContentHeight
= kIconHeight
+ kTextBoxHeight
+ kIconTextSpacingV
2419 static void calculateCGDrawingBounds(CGRect inItemRect
, CGRect
*outIconRect
, CGRect
*outTextRect
, bool hasIcon
= false)
2422 float iconH
, iconW
= 0;
2423 float padding
= kItemPadding
;
2426 iconH
= kIconHeight
;
2428 padding
= padding
*2;
2431 textBottom
= inItemRect
.origin
.y
;
2433 *outIconRect
= CGRectMake(inItemRect
.origin
.x
+ kItemPadding
,
2434 textBottom
+ kIconTextSpacingV
, kIconWidth
,
2437 *outTextRect
= CGRectMake(inItemRect
.origin
.x
+ padding
+ iconW
,
2438 textBottom
+ kIconTextSpacingV
, inItemRect
.size
.width
- padding
- iconW
,
2439 inItemRect
.size
.height
- kIconTextSpacingV
);
2442 void wxMacDataBrowserListCtrlControl::DrawItem(
2443 DataBrowserItemID itemID
,
2444 DataBrowserPropertyID property
,
2445 DataBrowserItemState itemState
,
2446 const Rect
*itemRect
,
2448 Boolean colorDevice
)
2451 wxFont font
= wxNullFont
;
2453 short listColumn
= property
- kMinColumnId
;
2455 wxListCtrl
* list
= wxDynamicCast( GetPeer() , wxListCtrl
);
2456 wxMacListCtrlItem
* lcItem
;
2457 wxColour color
= *wxBLACK
;
2458 wxColour bgColor
= wxNullColour
;
2460 if (listColumn
>= 0)
2464 lcItem
= (wxMacListCtrlItem
*) itemID
;
2465 if (lcItem
->HasColumnInfo(listColumn
)){
2466 wxListItem
* item
= lcItem
->GetColumnInfo(listColumn
);
2468 // we always use the 0 column to get font and text/background colors.
2469 if (lcItem
->HasColumnInfo(0))
2471 wxListItem
* firstItem
= lcItem
->GetColumnInfo(0);
2472 color
= firstItem
->GetTextColour();
2473 bgColor
= firstItem
->GetBackgroundColour();
2474 font
= firstItem
->GetFont();
2477 if (item
->GetMask() & wxLIST_MASK_TEXT
)
2478 text
= item
->GetText();
2479 if (item
->GetMask() & wxLIST_MASK_IMAGE
)
2480 imgIndex
= item
->GetImage();
2486 text
= list
->OnGetItemText( (long)itemID
-1, listColumn
);
2487 imgIndex
= list
->OnGetItemColumnImage( (long)itemID
-1, listColumn
);
2488 wxListItemAttr
* attrs
= list
->OnGetItemAttr( (long)itemID
-1 );
2491 if (attrs
->HasBackgroundColour())
2492 bgColor
= attrs
->GetBackgroundColour();
2493 if (attrs
->HasTextColour())
2494 color
= attrs
->GetTextColour();
2495 if (attrs
->HasFont())
2496 font
= attrs
->GetFont();
2501 wxColour listBgColor
= list
->GetBackgroundColour();
2502 if (bgColor
== wxNullColour
)
2503 bgColor
= listBgColor
;
2505 wxFont listFont
= list
->GetFont();
2506 if (font
== wxNullFont
)
2509 wxMacCFStringHolder cfString
;
2510 cfString
.Assign( text
, wxLocale::GetSystemEncoding() );
2513 CGRect enclosingCGRect
, iconCGRect
, textCGRect
;
2515 ThemeDrawingState savedState
= NULL
;
2516 CGContextRef context
= (CGContextRef
)list
->MacGetDrawingContext();
2517 RGBColor labelColor
;
2519 labelColor
.green
= 0;
2520 labelColor
.blue
= 0;
2522 RGBColor backgroundColor
;
2523 backgroundColor
.red
= 255;
2524 backgroundColor
.green
= 255;
2525 backgroundColor
.blue
= 255;
2527 GetDataBrowserItemPartBounds(GetControlRef(), itemID
, property
, kDataBrowserPropertyEnclosingPart
,
2530 enclosingCGRect
= CGRectMake(enclosingRect
.left
,
2532 enclosingRect
.right
- enclosingRect
.left
,
2533 enclosingRect
.bottom
- enclosingRect
.top
);
2535 active
= IsControlActive(GetControlRef());
2537 // don't paint the background over the vertical rule line
2538 if ( list
->GetWindowStyleFlag() & wxLC_VRULES
)
2540 enclosingCGRect
.origin
.x
+= 1;
2541 enclosingCGRect
.size
.width
-= 1;
2543 if (itemState
== kDataBrowserItemIsSelected
)
2546 GetThemeDrawingState(&savedState
);
2548 GetThemeBrushAsColor(kThemeBrushAlternatePrimaryHighlightColor
, 32, true, &backgroundColor
);
2549 GetThemeTextColor(kThemeTextColorWhite
, gdDepth
, colorDevice
, &labelColor
);
2551 CGContextSaveGState(context
);
2553 CGContextSetRGBFillColor(context
, (float)backgroundColor
.red
/ (float)USHRT_MAX
,
2554 (float)backgroundColor
.green
/ (float)USHRT_MAX
,
2555 (float)backgroundColor
.blue
/ (float)USHRT_MAX
, 1.0);
2556 CGContextFillRect(context
, enclosingCGRect
);
2558 CGContextRestoreGState(context
);
2564 labelColor
= MAC_WXCOLORREF( color
.GetPixel() );
2565 else if (list
->GetTextColour().Ok())
2566 labelColor
= MAC_WXCOLORREF( list
->GetTextColour().GetPixel() );
2570 backgroundColor
= MAC_WXCOLORREF( bgColor
.GetPixel() );
2571 CGContextSaveGState(context
);
2573 CGContextSetRGBFillColor(context
, (float)backgroundColor
.red
/ (float)USHRT_MAX
,
2574 (float)backgroundColor
.green
/ (float)USHRT_MAX
,
2575 (float)backgroundColor
.blue
/ (float)USHRT_MAX
, 1.0);
2576 CGContextFillRect(context
, enclosingCGRect
);
2578 CGContextRestoreGState(context
);
2582 calculateCGDrawingBounds(enclosingCGRect
, &iconCGRect
, &textCGRect
, (imgIndex
!= -1) );
2586 wxImageList
* imageList
= list
->GetImageList(wxIMAGE_LIST_SMALL
);
2587 if (imageList
&& imageList
->GetImageCount() > 0){
2588 wxBitmap bmp
= imageList
->GetBitmap(imgIndex
);
2589 IconRef icon
= bmp
.GetBitmapData()->GetIconRef();
2591 CGContextSaveGState(context
);
2592 CGContextTranslateCTM(context
, 0,iconCGRect
.origin
.y
+ CGRectGetMaxY(iconCGRect
));
2593 CGContextScaleCTM(context
,1.0f
,-1.0f
);
2594 PlotIconRefInContext(context
, &iconCGRect
, kAlignNone
,
2595 active
? kTransformNone
: kTransformDisabled
, NULL
,
2596 kPlotIconRefNormalFlags
, icon
);
2598 CGContextRestoreGState(context
);
2602 HIThemeTextHorizontalFlush hFlush
= kHIThemeTextHorizontalFlushLeft
;
2603 UInt16 fontID
= kThemeViewsFont
;
2607 if (font
.GetFamily() != wxFONTFAMILY_DEFAULT
)
2608 fontID
= font
.MacGetThemeFontID();
2610 // FIXME: replace these with CG or ATSUI calls so we can remove this #ifndef.
2612 ::TextSize( (short)(font
.MacGetFontSize()) ) ;
2613 ::TextFace( font
.MacGetFontStyle() ) ;
2618 list
->GetColumn(listColumn
, item
);
2619 if (item
.GetMask() & wxLIST_MASK_FORMAT
)
2621 if (item
.GetAlign() == wxLIST_FORMAT_LEFT
)
2622 hFlush
= kHIThemeTextHorizontalFlushLeft
;
2623 else if (item
.GetAlign() == wxLIST_FORMAT_CENTER
)
2624 hFlush
= kHIThemeTextHorizontalFlushCenter
;
2625 else if (item
.GetAlign() == wxLIST_FORMAT_RIGHT
)
2627 hFlush
= kHIThemeTextHorizontalFlushRight
;
2628 textCGRect
.origin
.x
-= kItemPadding
; // give a little extra paddding
2632 HIThemeTextInfo info
;
2633 info
.version
= kHIThemeTextInfoVersionZero
;
2634 info
.state
= active
? kThemeStateActive
: kThemeStateInactive
;
2635 info
.fontID
= fontID
;
2636 info
.horizontalFlushness
= hFlush
;
2637 info
.verticalFlushness
= kHIThemeTextVerticalFlushCenter
;
2638 info
.options
= kHIThemeTextBoxOptionNone
;
2639 info
.truncationPosition
= kHIThemeTextTruncationEnd
;
2640 info
.truncationMaxLines
= 1;
2642 CGContextSaveGState(context
);
2643 CGContextSetRGBFillColor (context
, (float)labelColor
.red
/ (float)USHRT_MAX
,
2644 (float)labelColor
.green
/ (float)USHRT_MAX
,
2645 (float)labelColor
.blue
/ (float)USHRT_MAX
, 1.0);
2647 HIThemeDrawTextBox(cfString
, &textCGRect
, &info
, context
, kHIThemeOrientationNormal
);
2649 CGContextRestoreGState(context
);
2651 if (savedState
!= NULL
)
2652 SetThemeDrawingState(savedState
, true);
2655 OSStatus
wxMacDataBrowserListCtrlControl::GetSetItemData(DataBrowserItemID itemID
,
2656 DataBrowserPropertyID property
,
2657 DataBrowserItemDataRef itemData
,
2658 Boolean changeValue
)
2662 short listColumn
= property
- kMinColumnId
;
2664 OSStatus err
= errDataBrowserPropertyNotSupported
;
2665 wxListCtrl
* list
= wxDynamicCast( GetPeer() , wxListCtrl
);
2666 wxMacListCtrlItem
* lcItem
;
2668 if (listColumn
>= 0)
2672 lcItem
= (wxMacListCtrlItem
*) itemID
;
2673 if (lcItem
&& lcItem
->HasColumnInfo(listColumn
)){
2674 wxListItem
* item
= lcItem
->GetColumnInfo(listColumn
);
2675 if (item
->GetMask() & wxLIST_MASK_TEXT
)
2676 text
= item
->GetText();
2677 if (item
->GetMask() & wxLIST_MASK_IMAGE
)
2678 imgIndex
= item
->GetImage();
2683 text
= list
->OnGetItemText( (long)itemID
-1, listColumn
);
2684 imgIndex
= list
->OnGetItemColumnImage( (long)itemID
-1, listColumn
);
2692 case kDataBrowserItemIsEditableProperty
:
2693 if ( list
&& list
->HasFlag( wxLC_EDIT_LABELS
) )
2695 verify_noerr(SetDataBrowserItemDataBooleanValue( itemData
, true ));
2700 if ( property
>= kMinColumnId
)
2702 wxMacCFStringHolder cfStr
;
2705 cfStr
.Assign( text
, wxLocale::GetSystemEncoding() );
2706 err
= ::SetDataBrowserItemDataText( itemData
, cfStr
);
2712 if ( imgIndex
!= -1 )
2714 wxImageList
* imageList
= list
->GetImageList(wxIMAGE_LIST_SMALL
);
2715 if (imageList
&& imageList
->GetImageCount() > 0){
2716 wxBitmap bmp
= imageList
->GetBitmap(imgIndex
);
2717 IconRef icon
= bmp
.GetBitmapData()->GetIconRef();
2718 ::SetDataBrowserItemDataIcon(itemData
, icon
);
2732 if ( property
>= kMinColumnId
)
2734 short listColumn
= property
- kMinColumnId
;
2736 // TODO probably send the 'end edit' from here, as we
2737 // can then deal with the veto
2739 verify_noerr( GetDataBrowserItemDataText( itemData
, &sr
) ) ;
2740 wxMacCFStringHolder
cfStr(sr
) ;;
2742 list
->SetItem( (long)itemData
-1 , listColumn
, cfStr
.AsString() ) ;
2746 lcItem
->SetColumnTextValue( listColumn
, cfStr
.AsString() );
2756 void wxMacDataBrowserListCtrlControl::ItemNotification(DataBrowserItemID itemID
,
2757 DataBrowserItemNotification message
,
2758 DataBrowserItemDataRef itemData
)
2760 // we want to depend on as little as possible to make sure tear-down of controls is safe
2761 if ( message
== kDataBrowserItemRemoved
)
2763 // make sure MacDelete does the proper teardown.
2766 else if ( message
== kDataBrowserItemAdded
)
2768 // we don't issue events on adding, the item is not really stored in the list yet, so we
2769 // avoid asserts by getting out now
2773 wxListCtrl
*list
= wxDynamicCast( GetPeer() , wxListCtrl
);
2776 bool trigger
= false;
2778 wxListEvent
event( wxEVT_COMMAND_LIST_ITEM_SELECTED
, list
->GetId() );
2779 bool isSingle
= (list
->GetWindowStyle() & wxLC_SINGLE_SEL
) != 0;
2781 event
.SetEventObject( list
);
2782 if ( !list
->IsVirtual() )
2784 DataBrowserTableViewRowIndex result
= 0;
2785 verify_noerr( GetItemRow( itemID
, &result
) ) ;
2786 event
.m_itemIndex
= result
;
2788 if (event
.m_itemIndex
>= 0)
2789 MacGetColumnInfo(event
.m_itemIndex
,0,event
.m_item
);
2793 event
.m_itemIndex
= (long)itemID
-1;
2798 case kDataBrowserItemDeselected
:
2799 event
.SetEventType(wxEVT_COMMAND_LIST_ITEM_DESELECTED
);
2801 trigger
= !IsSelectionSuppressed();
2804 case kDataBrowserItemSelected
:
2805 trigger
= !IsSelectionSuppressed();
2809 case kDataBrowserItemDoubleClicked
:
2810 event
.SetEventType( wxEVT_COMMAND_LIST_ITEM_ACTIVATED
);
2814 case kDataBrowserEditStarted
:
2815 // TODO : how to veto ?
2816 event
.SetEventType( wxEVT_COMMAND_LIST_BEGIN_LABEL_EDIT
) ;
2820 case kDataBrowserEditStopped
:
2821 // TODO probably trigger only upon the value store callback, because
2822 // here IIRC we cannot veto
2823 event
.SetEventType( wxEVT_COMMAND_LIST_END_LABEL_EDIT
) ;
2833 // direct notification is not always having the listbox GetSelection() having in synch with event
2834 wxPostEvent( list
->GetEventHandler(), event
);
2839 Boolean
wxMacDataBrowserListCtrlControl::CompareItems(DataBrowserItemID itemOneID
,
2840 DataBrowserItemID itemTwoID
,
2841 DataBrowserPropertyID sortProperty
)
2844 bool retval
= false;
2846 wxString otherItemText
;
2847 int colId
= sortProperty
- kMinColumnId
;
2849 wxListCtrl
* list
= wxDynamicCast( GetPeer() , wxListCtrl
);
2855 wxMacListCtrlItem
* item
= (wxMacListCtrlItem
*)itemOneID
;
2856 wxMacListCtrlItem
* otherItem
= (wxMacListCtrlItem
*)itemTwoID
;
2858 wxListCtrlCompare func
= list
->GetCompareFunc();
2863 if (item
&& item
->HasColumnInfo(0))
2864 item1
= item
->GetColumnInfo(0)->GetData();
2865 if (otherItem
&& otherItem
->HasColumnInfo(0))
2866 item2
= otherItem
->GetColumnInfo(0)->GetData();
2868 if (item1
> -1 && item2
> -1)
2870 int result
= func(item1
, item2
, list
->GetCompareFuncData());
2874 if (item
->HasColumnInfo(colId
))
2875 itemText
= item
->GetColumnInfo(colId
)->GetText();
2876 if (otherItem
->HasColumnInfo(colId
))
2877 otherItemText
= otherItem
->GetColumnInfo(colId
)->GetText();
2882 long itemNum
= (long)itemOneID
;
2883 long otherItemNum
= (long)itemTwoID
;
2884 itemText
= list
->OnGetItemText( itemNum
-1, colId
);
2885 otherItemText
= list
->OnGetItemText( otherItemNum
-1, colId
);
2889 DataBrowserSortOrder sort
;
2890 verify_noerr(GetSortOrder(&sort
));
2892 if ( sort
== kDataBrowserOrderIncreasing
)
2894 retval
= itemText
.CmpNoCase( otherItemText
) > 0;
2896 else if ( sort
== kDataBrowserOrderDecreasing
)
2898 retval
= itemText
.CmpNoCase( otherItemText
) < 0;
2902 // fallback for undefined cases
2903 retval
= itemOneID
< itemTwoID
;
2909 wxMacDataBrowserListCtrlControl::~wxMacDataBrowserListCtrlControl()
2913 void wxMacDataBrowserListCtrlControl::MacSetColumnInfo( unsigned int row
, unsigned int column
, wxListItem
* item
)
2915 wxMacDataItem
* dataItem
= GetItemFromLine(row
);
2916 wxASSERT_MSG( dataItem
, _T("could not obtain wxMacDataItem for row in MacSetColumnInfo. Is row a valid wxListCtrl row?") );
2919 wxMacListCtrlItem
* listItem
= dynamic_cast<wxMacListCtrlItem
*>(dataItem
);
2920 bool hasInfo
= listItem
->HasColumnInfo( column
);
2921 listItem
->SetColumnInfo( column
, item
);
2922 UpdateState(dataItem
, item
);
2924 wxListCtrl
* list
= wxDynamicCast( GetPeer() , wxListCtrl
);
2926 // NB: When this call was made before a control was completely shown, it would
2927 // update the item prematurely (i.e. no text would be listed) and, on show,
2928 // only the sorted column would be refreshed, meaning only first column text labels
2929 // would be shown. Making sure not to update items until the control is visible
2930 // seems to fix this issue.
2931 if (hasInfo
&& list
->IsShown())
2932 UpdateItem( wxMacDataBrowserRootContainer
, listItem
, kMinColumnId
+ column
);
2936 // apply changes that need to happen immediately, rather than when the
2937 // databrowser control fires a callback.
2938 void wxMacDataBrowserListCtrlControl::UpdateState(wxMacDataItem
* dataItem
, wxListItem
* listItem
)
2940 bool isSelected
= IsItemSelected( dataItem
);
2941 bool isSelectedState
= (listItem
->GetState() == wxLIST_STATE_SELECTED
);
2943 // toggle the selection state if wxListInfo state and actual state don't match.
2944 if ( isSelected
!= isSelectedState
)
2946 DataBrowserSetOption options
= kDataBrowserItemsAdd
;
2947 if (!isSelectedState
)
2948 options
= kDataBrowserItemsRemove
;
2949 SetSelectedItem(dataItem
, options
);
2951 // TODO: Set column width if item width > than current column width
2954 void wxMacDataBrowserListCtrlControl::MacGetColumnInfo( unsigned int row
, unsigned int column
, wxListItem
& item
)
2956 wxMacDataItem
* dataItem
= GetItemFromLine(row
);
2957 wxASSERT_MSG( dataItem
, _T("could not obtain wxMacDataItem in MacGetColumnInfo. Is row a valid wxListCtrl row?") );
2958 // CS should this guard against dataItem = 0 ? , as item is not a pointer if (item) is not appropriate
2961 wxMacListCtrlItem
* listItem
= dynamic_cast<wxMacListCtrlItem
*>(dataItem
);
2963 if (!listItem
->HasColumnInfo( column
))
2966 wxListItem
* oldItem
= listItem
->GetColumnInfo( column
);
2970 long mask
= item
.GetMask();
2972 // by default, get everything for backwards compatibility
2975 if ( mask
& wxLIST_MASK_TEXT
)
2976 item
.SetText(oldItem
->GetText());
2977 if ( mask
& wxLIST_MASK_IMAGE
)
2978 item
.SetImage(oldItem
->GetImage());
2979 if ( mask
& wxLIST_MASK_DATA
)
2980 item
.SetData(oldItem
->GetData());
2981 if ( mask
& wxLIST_MASK_STATE
)
2982 item
.SetState(oldItem
->GetState());
2983 if ( mask
& wxLIST_MASK_WIDTH
)
2984 item
.SetWidth(oldItem
->GetWidth());
2985 if ( mask
& wxLIST_MASK_FORMAT
)
2986 item
.SetAlign(oldItem
->GetAlign());
2988 item
.SetTextColour(oldItem
->GetTextColour());
2989 item
.SetBackgroundColour(oldItem
->GetBackgroundColour());
2990 item
.SetFont(oldItem
->GetFont());
2995 void wxMacDataBrowserListCtrlControl::MacInsertItem( unsigned int n
, wxListItem
* item
)
2997 wxMacDataItemBrowserControl::MacInsert(n
, item
->GetText());
2998 MacSetColumnInfo(n
, 0, item
);
3001 wxMacDataItem
* wxMacDataBrowserListCtrlControl::CreateItem()
3003 return new wxMacListCtrlItem();
3006 wxMacListCtrlItem::wxMacListCtrlItem()
3008 m_rowItems
= wxListItemList( wxKEY_INTEGER
);
3011 int wxMacListCtrlItem::GetColumnImageValue( unsigned int column
)
3013 if ( HasColumnInfo(column
) )
3014 return GetColumnInfo(column
)->GetImage();
3019 void wxMacListCtrlItem::SetColumnImageValue( unsigned int column
, int imageIndex
)
3021 if ( HasColumnInfo(column
) )
3022 GetColumnInfo(column
)->SetImage(imageIndex
);
3025 wxString
wxMacListCtrlItem::GetColumnTextValue( unsigned int column
)
3030 if ( HasColumnInfo(column
) )
3031 return GetColumnInfo(column
)->GetText();
3033 return wxEmptyString
;
3036 void wxMacListCtrlItem::SetColumnTextValue( unsigned int column
, const wxString
& text
)
3038 if ( HasColumnInfo(column
) )
3039 GetColumnInfo(column
)->SetText(text
);
3041 // for compatibility with superclass APIs
3046 wxListItem
* wxMacListCtrlItem::GetColumnInfo( unsigned int column
)
3048 wxListItemList::compatibility_iterator node
= m_rowItems
.Find( column
);
3049 wxASSERT_MSG( node
, _T("invalid column index in wxMacListCtrlItem") );
3051 return node
->GetData();
3054 bool wxMacListCtrlItem::HasColumnInfo( unsigned int column
)
3056 return m_rowItems
.Find( column
) != NULL
;
3059 void wxMacListCtrlItem::SetColumnInfo( unsigned int column
, wxListItem
* item
)
3062 if ( !HasColumnInfo(column
) )
3064 wxListItem
* listItem
= new wxListItem(*item
);
3065 m_rowItems
.Append( column
, listItem
);
3069 wxListItem
* listItem
= GetColumnInfo( column
);
3070 long mask
= item
->GetMask();
3071 if (mask
& wxLIST_MASK_TEXT
)
3072 listItem
->SetText(item
->GetText());
3073 if (mask
& wxLIST_MASK_DATA
)
3074 listItem
->SetData(item
->GetData());
3075 if (mask
& wxLIST_MASK_IMAGE
)
3076 listItem
->SetImage(item
->GetImage());
3077 if (mask
& wxLIST_MASK_STATE
)
3078 listItem
->SetState(item
->GetState());
3079 if (mask
& wxLIST_MASK_FORMAT
)
3080 listItem
->SetAlign(item
->GetAlign());
3081 if (mask
& wxLIST_MASK_WIDTH
)
3082 listItem
->SetWidth(item
->GetWidth());
3084 if ( item
->HasAttributes() )
3086 if ( listItem
->HasAttributes() )
3087 listItem
->GetAttributes()->AssignFrom(*item
->GetAttributes());
3090 listItem
->SetTextColour(item
->GetTextColour());
3091 listItem
->SetBackgroundColour(item
->GetBackgroundColour());
3092 listItem
->SetFont(item
->GetFont());
3098 #endif // wxUSE_LISTCTRL