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 wxMacDataBrowserListCtrlControl() {}
212 virtual ~wxMacDataBrowserListCtrlControl();
214 // create a list item (can be a subclass of wxMacListBoxItem)
216 virtual wxMacDataItem
* CreateItem();
218 virtual void MacInsertItem( unsigned int n
, wxListItem
* item
);
219 virtual void MacSetColumnInfo( unsigned int row
, unsigned int column
, wxListItem
* item
);
220 virtual void MacGetColumnInfo( unsigned int row
, unsigned int column
, wxListItem
& item
);
221 virtual void UpdateState(wxMacDataItem
* dataItem
, wxListItem
* item
);
224 // we need to override to provide specialized handling for virtual wxListCtrls
225 virtual OSStatus
GetSetItemData(DataBrowserItemID itemID
,
226 DataBrowserPropertyID property
,
227 DataBrowserItemDataRef itemData
,
228 Boolean changeValue
);
230 virtual void ItemNotification(
231 DataBrowserItemID itemID
,
232 DataBrowserItemNotification message
,
233 DataBrowserItemDataRef itemData
);
235 virtual Boolean
CompareItems(DataBrowserItemID itemOneID
,
236 DataBrowserItemID itemTwoID
,
237 DataBrowserPropertyID sortProperty
);
239 static pascal void DataBrowserDrawItemProc(ControlRef browser
,
240 DataBrowserItemID item
,
241 DataBrowserPropertyID property
,
242 DataBrowserItemState itemState
,
245 Boolean colorDevice
);
247 virtual void DrawItem(DataBrowserItemID itemID
,
248 DataBrowserPropertyID property
,
249 DataBrowserItemState itemState
,
250 const Rect
*itemRect
,
252 Boolean colorDevice
);
254 static pascal Boolean
DataBrowserEditTextProc(ControlRef browser
,
255 DataBrowserItemID item
,
256 DataBrowserPropertyID property
,
257 CFStringRef theString
,
258 Rect
*maxEditTextRect
,
259 Boolean
*shrinkToFit
);
261 static pascal Boolean
DataBrowserHitTestProc(ControlRef browser
,
262 DataBrowserItemID itemID
,
263 DataBrowserPropertyID property
,
265 const Rect
*mouseRect
) { return true; }
267 virtual bool ConfirmEditText(DataBrowserItemID item
,
268 DataBrowserPropertyID property
,
269 CFStringRef theString
,
270 Rect
*maxEditTextRect
,
271 Boolean
*shrinkToFit
);
275 wxClientDataType m_clientDataItemsType
;
277 DECLARE_DYNAMIC_CLASS_NO_COPY(wxMacDataBrowserListCtrlControl
)
280 class wxMacListCtrlEventDelegate
: public wxEvtHandler
283 wxMacListCtrlEventDelegate( wxListCtrl
* list
, int id
);
284 virtual bool ProcessEvent( wxEvent
& event
);
291 wxMacListCtrlEventDelegate::wxMacListCtrlEventDelegate( wxListCtrl
* list
, int id
)
297 bool wxMacListCtrlEventDelegate::ProcessEvent( wxEvent
& event
)
299 // even though we use a generic list ctrl underneath, make sure
300 // we present ourselves as wxListCtrl.
301 event
.SetEventObject( m_list
);
304 if ( !event
.IsKindOf( CLASSINFO( wxCommandEvent
) ) )
306 if (m_list
->GetEventHandler()->ProcessEvent( event
))
309 return wxEvtHandler::ProcessEvent(event
);
312 //-----------------------------------------------------------------------------
313 // wxListCtrlRenameTimer (internal)
314 //-----------------------------------------------------------------------------
316 class wxListCtrlRenameTimer
: public wxTimer
322 wxListCtrlRenameTimer( wxListCtrl
*owner
);
326 //-----------------------------------------------------------------------------
327 // wxListCtrlTextCtrlWrapper: wraps a wxTextCtrl to make it work for inline editing
328 //-----------------------------------------------------------------------------
330 class wxListCtrlTextCtrlWrapper
: public wxEvtHandler
333 // NB: text must be a valid object but not Create()d yet
334 wxListCtrlTextCtrlWrapper(wxListCtrl
*owner
,
338 wxTextCtrl
*GetText() const { return m_text
; }
340 void AcceptChangesAndFinish();
343 void OnChar( wxKeyEvent
&event
);
344 void OnKeyUp( wxKeyEvent
&event
);
345 void OnKillFocus( wxFocusEvent
&event
);
347 bool AcceptChanges();
353 wxString m_startValue
;
356 bool m_aboutToFinish
;
358 DECLARE_EVENT_TABLE()
361 //-----------------------------------------------------------------------------
362 // wxListCtrlRenameTimer (internal)
363 //-----------------------------------------------------------------------------
365 wxListCtrlRenameTimer::wxListCtrlRenameTimer( wxListCtrl
*owner
)
370 void wxListCtrlRenameTimer::Notify()
372 m_owner
->OnRenameTimer();
375 //-----------------------------------------------------------------------------
376 // wxListCtrlTextCtrlWrapper (internal)
377 //-----------------------------------------------------------------------------
379 BEGIN_EVENT_TABLE(wxListCtrlTextCtrlWrapper
, wxEvtHandler
)
380 EVT_CHAR (wxListCtrlTextCtrlWrapper::OnChar
)
381 EVT_KEY_UP (wxListCtrlTextCtrlWrapper::OnKeyUp
)
382 EVT_KILL_FOCUS (wxListCtrlTextCtrlWrapper::OnKillFocus
)
385 wxListCtrlTextCtrlWrapper::wxListCtrlTextCtrlWrapper(wxListCtrl
*owner
,
388 : m_startValue(owner
->GetItemText(itemEdit
)),
389 m_itemEdited(itemEdit
)
394 m_aboutToFinish
= false;
398 owner
->GetItemRect(itemEdit
, rectLabel
);
400 m_text
->Create(owner
, wxID_ANY
, m_startValue
,
401 wxPoint(rectLabel
.x
+offset
,rectLabel
.y
),
402 wxSize(rectLabel
.width
-offset
,rectLabel
.height
));
405 m_text
->PushEventHandler(this);
408 void wxListCtrlTextCtrlWrapper::Finish()
414 m_text
->RemoveEventHandler(this);
415 m_owner
->FinishEditing(m_text
);
417 wxPendingDelete
.Append( this );
421 bool wxListCtrlTextCtrlWrapper::AcceptChanges()
423 const wxString value
= m_text
->GetValue();
425 if ( value
== m_startValue
)
426 // nothing changed, always accept
429 if ( !m_owner
->OnRenameAccept(m_itemEdited
, value
) )
430 // vetoed by the user
433 // accepted, do rename the item
434 m_owner
->SetItemText(m_itemEdited
, value
);
439 void wxListCtrlTextCtrlWrapper::AcceptChangesAndFinish()
441 m_aboutToFinish
= true;
443 // Notify the owner about the changes
446 // Even if vetoed, close the control (consistent with MSW)
450 void wxListCtrlTextCtrlWrapper::OnChar( wxKeyEvent
&event
)
452 switch ( event
.m_keyCode
)
455 AcceptChangesAndFinish();
459 m_owner
->OnRenameCancelled( m_itemEdited
);
468 void wxListCtrlTextCtrlWrapper::OnKeyUp( wxKeyEvent
&event
)
476 // auto-grow the textctrl:
477 wxSize parentSize
= m_owner
->GetSize();
478 wxPoint myPos
= m_text
->GetPosition();
479 wxSize mySize
= m_text
->GetSize();
481 m_text
->GetTextExtent(m_text
->GetValue() + _T("MM"), &sx
, &sy
);
482 if (myPos
.x
+ sx
> parentSize
.x
)
483 sx
= parentSize
.x
- myPos
.x
;
486 m_text
->SetSize(sx
, wxDefaultCoord
);
491 void wxListCtrlTextCtrlWrapper::OnKillFocus( wxFocusEvent
&event
)
493 if ( !m_finished
&& !m_aboutToFinish
)
495 if ( !AcceptChanges() )
496 m_owner
->OnRenameCancelled( m_itemEdited
);
501 // We must let the native text control handle focus
505 BEGIN_EVENT_TABLE(wxListCtrl
, wxControl
)
506 EVT_LEFT_DOWN(wxListCtrl::OnLeftDown
)
507 EVT_LEFT_DCLICK(wxListCtrl::OnDblClick
)
510 // ============================================================================
512 // ============================================================================
514 wxMacListControl
* wxListCtrl::GetPeer() const
516 wxMacDataBrowserListCtrlControl
*lb
= wxDynamicCast(m_peer
,wxMacDataBrowserListCtrlControl
);
517 return lb
? wx_static_cast(wxMacListControl
*,lb
) : 0 ;
520 // ----------------------------------------------------------------------------
521 // wxListCtrl construction
522 // ----------------------------------------------------------------------------
524 void wxListCtrl::Init()
526 m_imageListNormal
= NULL
;
527 m_imageListSmall
= NULL
;
528 m_imageListState
= NULL
;
530 // keep track of if we created our own image lists, or if they were assigned
532 m_ownsImageListNormal
= m_ownsImageListSmall
= m_ownsImageListState
= false;
536 m_genericImpl
= NULL
;
538 m_compareFunc
= NULL
;
539 m_compareFuncData
= 0;
540 m_colsInfo
= wxColumnList();
541 m_textColor
= wxNullColour
;
542 m_bgColor
= wxNullColour
;
543 m_textctrlWrapper
= NULL
;
545 m_renameTimer
= new wxListCtrlRenameTimer( this );
548 class wxGenericListCtrlHook
: public wxGenericListCtrl
551 wxGenericListCtrlHook(wxListCtrl
* parent
,
556 const wxValidator
& validator
,
557 const wxString
& name
)
558 : wxGenericListCtrl(parent
, id
, pos
, size
, style
, validator
, name
),
559 m_nativeListCtrl(parent
)
564 virtual wxListItemAttr
* OnGetItemAttr(long item
) const
566 return m_nativeListCtrl
->OnGetItemAttr(item
);
569 virtual int OnGetItemImage(long item
) const
571 return m_nativeListCtrl
->OnGetItemImage(item
);
574 virtual int OnGetItemColumnImage(long item
, long column
) const
576 return m_nativeListCtrl
->OnGetItemColumnImage(item
, column
);
579 virtual wxString
OnGetItemText(long item
, long column
) const
581 return m_nativeListCtrl
->OnGetItemText(item
, column
);
584 wxListCtrl
* m_nativeListCtrl
;
588 void wxListCtrl::OnLeftDown(wxMouseEvent
& event
)
590 if ( m_textctrlWrapper
)
593 m_textctrlWrapper
->AcceptChangesAndFinish();
597 long current
= HitTest(event
.GetPosition(), hitResult
);
598 if ((current
== m_current
) &&
599 (hitResult
== wxLIST_HITTEST_ONITEM
) &&
600 HasFlag(wxLC_EDIT_LABELS
) )
602 m_renameTimer
->Start( 100, true );
611 void wxListCtrl::OnDblClick(wxMouseEvent
& event
)
617 bool wxListCtrl::Create(wxWindow
*parent
,
622 const wxValidator
& validator
,
623 const wxString
& name
)
626 // for now, we'll always use the generic list control for ICON and LIST views,
627 // because they dynamically change the number of columns on resize.
628 // Also, allow the user to set it to use the list ctrl as well.
629 if ( (wxSystemOptions::HasOption( wxMAC_ALWAYS_USE_GENERIC_LISTCTRL
)
630 && (wxSystemOptions::GetOptionInt( wxMAC_ALWAYS_USE_GENERIC_LISTCTRL
) == 1)) ||
631 (style
& wxLC_ICON
) || (style
& wxLC_SMALL_ICON
) || (style
& wxLC_LIST
) )
633 m_macIsUserPane
= true;
635 long paneStyle
= style
;
636 paneStyle
&= ~wxSIMPLE_BORDER
;
637 paneStyle
&= ~wxDOUBLE_BORDER
;
638 paneStyle
&= ~wxSUNKEN_BORDER
;
639 paneStyle
&= ~wxRAISED_BORDER
;
640 paneStyle
&= ~wxSTATIC_BORDER
;
641 if ( !wxWindow::Create(parent
, id
, pos
, size
, paneStyle
| wxNO_BORDER
, name
) )
644 // since the generic control is a child, make sure we position it at 0, 0
645 m_genericImpl
= new wxGenericListCtrlHook(this, id
, wxPoint(0, 0), size
, style
, validator
, name
);
646 m_genericImpl
->PushEventHandler( new wxMacListCtrlEventDelegate( this, GetId() ) );
652 m_macIsUserPane
= false;
654 if ( !wxWindow::Create(parent
, id
, pos
, size
, style
, name
) )
656 m_dbImpl
= new wxMacDataBrowserListCtrlControl( this, pos
, size
, style
);
659 MacPostControlCreate( pos
, size
);
661 InstallControlEventHandler( m_peer
->GetControlRef() , GetwxMacListCtrlEventHandlerUPP(),
662 GetEventTypeCount(eventList
), eventList
, this,
663 (EventHandlerRef
*)&m_macListCtrlEventHandler
);
669 wxListCtrl::~wxListCtrl()
673 m_genericImpl
->PopEventHandler(/* deleteHandler = */ true);
676 if (m_ownsImageListNormal
)
677 delete m_imageListNormal
;
678 if (m_ownsImageListSmall
)
679 delete m_imageListSmall
;
680 if (m_ownsImageListState
)
681 delete m_imageListState
;
683 delete m_renameTimer
;
686 // ----------------------------------------------------------------------------
687 // set/get/change style
688 // ----------------------------------------------------------------------------
690 // Add or remove a single window style
691 void wxListCtrl::SetSingleStyle(long style
, bool add
)
693 long flag
= GetWindowStyleFlag();
695 // Get rid of conflicting styles
698 if ( style
& wxLC_MASK_TYPE
)
699 flag
= flag
& ~wxLC_MASK_TYPE
;
700 if ( style
& wxLC_MASK_ALIGN
)
701 flag
= flag
& ~wxLC_MASK_ALIGN
;
702 if ( style
& wxLC_MASK_SORT
)
703 flag
= flag
& ~wxLC_MASK_SORT
;
711 SetWindowStyleFlag(flag
);
714 // Set the whole window style
715 void wxListCtrl::SetWindowStyleFlag(long flag
)
717 if ( flag
!= m_windowStyle
)
719 m_windowStyle
= flag
;
723 m_genericImpl
->SetWindowStyleFlag(flag
);
730 void wxListCtrl::DoSetSize( int x
, int y
, int width
, int height
, int sizeFlags
)
732 wxControl::DoSetSize(x
, y
, width
, height
, sizeFlags
);
735 m_genericImpl
->SetSize(0, 0, width
, height
, sizeFlags
);
737 // determine if we need a horizontal scrollbar, and add it if so
741 for (int column
= 0; column
< GetColumnCount(); column
++)
743 totalWidth
+= m_dbImpl
->GetColumnWidth( column
);
746 Boolean vertScrollBar
;
747 GetDataBrowserHasScrollBars( m_dbImpl
->GetControlRef(), NULL
, &vertScrollBar
);
748 if (totalWidth
> width
)
749 SetDataBrowserHasScrollBars( m_dbImpl
->GetControlRef(), true, vertScrollBar
);
751 SetDataBrowserHasScrollBars( m_dbImpl
->GetControlRef(), false, vertScrollBar
);
755 wxSize
wxListCtrl::DoGetBestSize() const
757 return wxWindow::DoGetBestSize();
760 bool wxListCtrl::SetFont(const wxFont
& font
)
763 rv
= wxControl::SetFont(font
);
765 rv
= m_genericImpl
->SetFont(font
);
769 bool wxListCtrl::SetForegroundColour(const wxColour
& colour
)
773 rv
= m_genericImpl
->SetForegroundColour(colour
);
775 SetTextColour(colour
);
779 bool wxListCtrl::SetBackgroundColour(const wxColour
& colour
)
783 rv
= m_genericImpl
->SetBackgroundColour(colour
);
789 wxColour
wxListCtrl::GetBackgroundColour()
792 return m_genericImpl
->GetBackgroundColour();
799 // ----------------------------------------------------------------------------
801 // ----------------------------------------------------------------------------
803 // Gets information about this column
804 bool wxListCtrl::GetColumn(int col
, wxListItem
& item
) const
807 return m_genericImpl
->GetColumn(col
, item
);
813 wxColumnList::compatibility_iterator node
= m_colsInfo
.Item( col
);
814 wxASSERT_MSG( node
, _T("invalid column index in wxMacListCtrlItem") );
815 wxListItem
* column
= node
->GetData();
817 long mask
= column
->GetMask();
818 if (mask
& wxLIST_MASK_TEXT
)
819 item
.SetText(column
->GetText());
820 if (mask
& wxLIST_MASK_DATA
)
821 item
.SetData(column
->GetData());
822 if (mask
& wxLIST_MASK_IMAGE
)
823 item
.SetImage(column
->GetImage());
824 if (mask
& wxLIST_MASK_STATE
)
825 item
.SetState(column
->GetState());
826 if (mask
& wxLIST_MASK_FORMAT
)
827 item
.SetAlign(column
->GetAlign());
828 if (mask
& wxLIST_MASK_WIDTH
)
829 item
.SetWidth(column
->GetWidth());
835 // Sets information about this column
836 bool wxListCtrl::SetColumn(int col
, wxListItem
& item
)
839 return m_genericImpl
->SetColumn(col
, item
);
843 long mask
= item
.GetMask();
844 if ( col
>= (int)m_colsInfo
.GetCount() )
846 wxListItem
* listItem
= new wxListItem(item
);
847 m_colsInfo
.Append( listItem
);
852 GetColumn( col
, listItem
);
854 if (mask
& wxLIST_MASK_TEXT
)
855 listItem
.SetText(item
.GetText());
856 if (mask
& wxLIST_MASK_DATA
)
857 listItem
.SetData(item
.GetData());
858 if (mask
& wxLIST_MASK_IMAGE
)
859 listItem
.SetImage(item
.GetImage());
860 if (mask
& wxLIST_MASK_STATE
)
861 listItem
.SetState(item
.GetState());
862 if (mask
& wxLIST_MASK_FORMAT
)
863 listItem
.SetAlign(item
.GetAlign());
864 if (mask
& wxLIST_MASK_WIDTH
)
865 listItem
.SetWidth(item
.GetWidth());
868 // change the appearance in the databrowser.
869 DataBrowserListViewHeaderDesc columnDesc
;
870 columnDesc
.version
=kDataBrowserListViewLatestHeaderDesc
;
871 verify_noerr( m_dbImpl
->GetHeaderDesc( kMinColumnId
+ col
, &columnDesc
) );
874 if (item.GetMask() & wxLIST_MASK_TEXT)
878 enc = m_font.GetEncoding();
880 enc = wxLocale::GetSystemEncoding();
881 wxMacCFStringHolder cfTitle;
882 cfTitle.Assign( item.GetText() , enc );
883 if(columnDesc.titleString)
884 CFRelease(columnDesc.titleString);
885 columnDesc.titleString = cfTitle;
889 if (item
.GetMask() & wxLIST_MASK_IMAGE
&& item
.GetImage() != -1 )
891 columnDesc
.btnContentInfo
.contentType
= kControlContentIconRef
;
892 wxImageList
* imageList
= GetImageList(wxIMAGE_LIST_SMALL
);
893 if (imageList
&& imageList
->GetImageCount() > 0 )
895 wxBitmap bmp
= imageList
->GetBitmap( item
.GetImage() );
896 IconRef icon
= bmp
.GetBitmapData()->GetIconRef();
897 columnDesc
.btnContentInfo
.u
.iconRef
= icon
;
901 verify_noerr( m_dbImpl
->SetHeaderDesc( kMinColumnId
+ col
, &columnDesc
) );
907 int wxListCtrl::GetColumnCount() const
910 return m_genericImpl
->GetColumnCount();
915 m_dbImpl
->GetColumnCount(&count
);
922 // Gets the column width
923 int wxListCtrl::GetColumnWidth(int col
) const
926 return m_genericImpl
->GetColumnWidth(col
);
930 return m_dbImpl
->GetColumnWidth(col
);
936 // Sets the column width
937 bool wxListCtrl::SetColumnWidth(int col
, int width
)
940 return m_genericImpl
->SetColumnWidth(col
, width
);
945 if (width
== wxLIST_AUTOSIZE
|| width
== wxLIST_AUTOSIZE_USEHEADER
)
950 for (int column
= 0; column
< GetColumnCount(); column
++)
953 GetColumn(col
, colInfo
);
955 colInfo
.SetWidth(width
);
956 SetColumn(col
, colInfo
);
958 m_dbImpl
->SetColumnWidth(col
, mywidth
);
964 GetColumn(col
, colInfo
);
966 colInfo
.SetWidth(width
);
967 SetColumn(col
, colInfo
);
968 m_dbImpl
->SetColumnWidth(col
, mywidth
);
976 // Gets the number of items that can fit vertically in the
977 // visible area of the list control (list or report view)
978 // or the total number of items in the list control (icon
979 // or small icon view)
980 int wxListCtrl::GetCountPerPage() const
983 return m_genericImpl
->GetCountPerPage();
992 // Gets the edit control for editing labels.
993 wxTextCtrl
* wxListCtrl::GetEditControl() const
996 return m_genericImpl
->GetEditControl();
1001 // Gets information about the item
1002 bool wxListCtrl::GetItem(wxListItem
& info
) const
1005 return m_genericImpl
->GetItem(info
);
1010 m_dbImpl
->MacGetColumnInfo(info
.m_itemId
, info
.m_col
, info
);
1013 info
.SetText( OnGetItemText(info
.m_itemId
, info
.m_col
) );
1014 info
.SetImage( OnGetItemColumnImage(info
.m_itemId
, info
.m_col
) );
1015 if (info
.GetMask() & wxLIST_MASK_STATE
)
1017 if (IsDataBrowserItemSelected( m_dbImpl
->GetControlRef(), info
.m_itemId
+1 ))
1018 info
.SetState(info
.GetState() | wxLIST_STATE_SELECTED
);
1021 wxListItemAttr
* attrs
= OnGetItemAttr( info
.m_itemId
);
1024 info
.SetFont( attrs
->GetFont() );
1025 info
.SetBackgroundColour( attrs
->GetBackgroundColour() );
1026 info
.SetTextColour( attrs
->GetTextColour() );
1030 bool success
= true;
1034 // Sets information about the item
1035 bool wxListCtrl::SetItem(wxListItem
& info
)
1038 return m_genericImpl
->SetItem(info
);
1041 m_dbImpl
->MacSetColumnInfo( info
.m_itemId
, info
.m_col
, &info
);
1046 long wxListCtrl::SetItem(long index
, int col
, const wxString
& label
, int imageId
)
1049 return m_genericImpl
->SetItem(index
, col
, label
, imageId
);
1052 info
.m_text
= label
;
1053 info
.m_mask
= wxLIST_MASK_TEXT
;
1054 info
.m_itemId
= index
;
1058 info
.m_image
= imageId
;
1059 info
.m_mask
|= wxLIST_MASK_IMAGE
;
1061 return SetItem(info
);
1065 // Gets the item state
1066 int wxListCtrl::GetItemState(long item
, long stateMask
) const
1069 return m_genericImpl
->GetItemState(item
, stateMask
);
1073 if ( HasFlag(wxLC_VIRTUAL
) )
1075 if (stateMask
== wxLIST_STATE_SELECTED
)
1077 if (IsDataBrowserItemSelected( m_dbImpl
->GetControlRef(), item
+1 ))
1078 return wxLIST_STATE_SELECTED
;
1087 info
.m_mask
= wxLIST_MASK_STATE
;
1088 info
.m_stateMask
= stateMask
;
1089 info
.m_itemId
= item
;
1094 return info
.m_state
;
1101 // Sets the item state
1102 bool wxListCtrl::SetItemState(long item
, long state
, long stateMask
)
1105 return m_genericImpl
->SetItemState(item
, state
, stateMask
);
1109 DataBrowserSetOption option
= kDataBrowserItemsAdd
;
1110 if ( stateMask
== wxLIST_STATE_SELECTED
&& state
== 0 )
1111 option
= kDataBrowserItemsRemove
;
1115 if ( HasFlag(wxLC_VIRTUAL
) )
1117 wxMacDataItemBrowserSelectionSuppressor
suppressor(m_dbImpl
);
1118 m_dbImpl
->SetSelectedAllItems(option
);
1122 for(int i
= 0; i
< GetItemCount();i
++)
1126 info
.m_mask
= wxLIST_MASK_STATE
;
1127 info
.m_stateMask
= stateMask
;
1128 info
.m_state
= state
;
1135 if ( HasFlag(wxLC_VIRTUAL
) )
1137 long itemID
= item
+1;
1138 SetDataBrowserSelectedItems(m_dbImpl
->GetControlRef(), 1, (DataBrowserItemID
*)&itemID
, option
);
1143 info
.m_itemId
= item
;
1144 info
.m_mask
= wxLIST_MASK_STATE
;
1145 info
.m_stateMask
= stateMask
;
1146 info
.m_state
= state
;
1147 return SetItem(info
);
1154 // Sets the item image
1155 bool wxListCtrl::SetItemImage(long item
, int image
, int WXUNUSED(selImage
))
1157 return SetItemColumnImage(item
, 0, image
);
1160 // Sets the item image
1161 bool wxListCtrl::SetItemColumnImage(long item
, long column
, int image
)
1164 return m_genericImpl
->SetItemColumnImage(item
, column
, image
);
1168 info
.m_mask
= wxLIST_MASK_IMAGE
;
1169 info
.m_image
= image
;
1170 info
.m_itemId
= item
;
1171 info
.m_col
= column
;
1173 return SetItem(info
);
1176 // Gets the item text
1177 wxString
wxListCtrl::GetItemText(long item
) const
1180 return m_genericImpl
->GetItemText(item
);
1184 info
.m_mask
= wxLIST_MASK_TEXT
;
1185 info
.m_itemId
= item
;
1188 return wxEmptyString
;
1192 // Sets the item text
1193 void wxListCtrl::SetItemText(long item
, const wxString
& str
)
1196 return m_genericImpl
->SetItemText(item
, str
);
1200 info
.m_mask
= wxLIST_MASK_TEXT
;
1201 info
.m_itemId
= item
;
1207 // Gets the item data
1208 long wxListCtrl::GetItemData(long item
) const
1211 return m_genericImpl
->GetItemData(item
);
1215 info
.m_mask
= wxLIST_MASK_DATA
;
1216 info
.m_itemId
= item
;
1223 // Sets the item data
1224 bool wxListCtrl::SetItemData(long item
, long data
)
1227 return m_genericImpl
->SetItemData(item
, data
);
1231 info
.m_mask
= wxLIST_MASK_DATA
;
1232 info
.m_itemId
= item
;
1235 return SetItem(info
);
1238 wxRect
wxListCtrl::GetViewRect() const
1240 wxASSERT_MSG( !HasFlag(wxLC_REPORT
| wxLC_LIST
),
1241 _T("wxListCtrl::GetViewRect() only works in icon mode") );
1244 return m_genericImpl
->GetViewRect();
1250 // Gets the item rectangle
1251 bool wxListCtrl::GetItemRect(long item
, wxRect
& rect
, int code
) const
1254 return m_genericImpl
->GetItemRect(item
, rect
, code
);
1259 DataBrowserItemID id
;
1260 DataBrowserPropertyID col
= kMinColumnId
;
1262 DataBrowserPropertyPart part
= kDataBrowserPropertyEnclosingPart
;
1263 if ( code
== wxLIST_RECT_LABEL
)
1264 part
= kDataBrowserPropertyTextPart
;
1265 else if ( code
== wxLIST_RECT_ICON
)
1266 part
= kDataBrowserPropertyIconPart
;
1268 if ( !(GetWindowStyleFlag() & wxLC_VIRTUAL
) )
1270 wxMacDataItem
* thisItem
= m_dbImpl
->GetItemFromLine(item
);
1271 id
= (DataBrowserItemID
) thisItem
;
1276 GetDataBrowserItemPartBounds( m_dbImpl
->GetControlRef(), id
, col
, part
, &bounds
);
1278 rect
.x
= bounds
.left
;
1279 rect
.y
= bounds
.top
;
1280 rect
.width
= bounds
.right
- bounds
.left
; //GetClientSize().x; // we need the width of the whole row, not just the item.
1281 rect
.height
= bounds
.bottom
- bounds
.top
;
1282 //fprintf("id = %d, bounds = %d, %d, %d, %d\n", id, rect.x, rect.y, rect.width, rect.height);
1287 // Gets the item position
1288 bool wxListCtrl::GetItemPosition(long item
, wxPoint
& pos
) const
1291 return m_genericImpl
->GetItemPosition(item
, pos
);
1293 bool success
= false;
1298 GetItemRect(item
, itemRect
);
1299 pos
= itemRect
.GetPosition();
1306 // Sets the item position.
1307 bool wxListCtrl::SetItemPosition(long item
, const wxPoint
& pos
)
1310 return m_genericImpl
->SetItemPosition(item
, pos
);
1315 // Gets the number of items in the list control
1316 int wxListCtrl::GetItemCount() const
1319 return m_genericImpl
->GetItemCount();
1322 return m_dbImpl
->MacGetCount();
1327 void wxListCtrl::SetItemSpacing( int spacing
, bool isSmall
)
1330 m_genericImpl
->SetItemSpacing(spacing
, isSmall
);
1333 wxSize
wxListCtrl::GetItemSpacing() const
1336 return m_genericImpl
->GetItemSpacing();
1338 return wxSize(0, 0);
1341 void wxListCtrl::SetItemTextColour( long item
, const wxColour
&col
)
1345 m_genericImpl
->SetItemTextColour(item
, col
);
1350 info
.m_itemId
= item
;
1351 info
.SetTextColour( col
);
1355 wxColour
wxListCtrl::GetItemTextColour( long item
) const
1358 return m_genericImpl
->GetItemTextColour(item
);
1364 return info
.GetTextColour();
1366 return wxNullColour
;
1369 void wxListCtrl::SetItemBackgroundColour( long item
, const wxColour
&col
)
1373 m_genericImpl
->SetItemBackgroundColour(item
, col
);
1378 info
.m_itemId
= item
;
1379 info
.SetBackgroundColour( col
);
1383 wxColour
wxListCtrl::GetItemBackgroundColour( long item
) const
1386 return m_genericImpl
->GetItemBackgroundColour(item
);
1392 return info
.GetBackgroundColour();
1394 return wxNullColour
;
1397 void wxListCtrl::SetItemFont( long item
, const wxFont
&f
)
1401 m_genericImpl
->SetItemFont(item
, f
);
1406 info
.m_itemId
= item
;
1411 wxFont
wxListCtrl::GetItemFont( long item
) const
1414 return m_genericImpl
->GetItemFont(item
);
1420 return info
.GetFont();
1426 // Gets the number of selected items in the list control
1427 int wxListCtrl::GetSelectedItemCount() const
1430 return m_genericImpl
->GetSelectedItemCount();
1433 return m_dbImpl
->GetSelectedItemCount(NULL
, true);
1438 // Gets the text colour of the listview
1439 wxColour
wxListCtrl::GetTextColour() const
1442 return m_genericImpl
->GetTextColour();
1444 // TODO: we need owner drawn list items to customize text color.
1448 return wxNullColour
;
1451 // Sets the text colour of the listview
1452 void wxListCtrl::SetTextColour(const wxColour
& col
)
1456 m_genericImpl
->SetTextColour(col
);
1464 // Gets the index of the topmost visible item when in
1465 // list or report view
1466 long wxListCtrl::GetTopItem() const
1469 return m_genericImpl
->GetTopItem();
1474 long item
= HitTest( wxPoint(1, 1), flags
);
1475 if (flags
== wxLIST_HITTEST_ONITEM
)
1482 // Searches for an item, starting from 'item'.
1483 // 'geometry' is one of
1484 // wxLIST_NEXT_ABOVE/ALL/BELOW/LEFT/RIGHT.
1485 // 'state' is a state bit flag, one or more of
1486 // wxLIST_STATE_DROPHILITED/FOCUSED/SELECTED/CUT.
1487 // item can be -1 to find the first item that matches the
1489 // Returns the item or -1 if unsuccessful.
1490 long wxListCtrl::GetNextItem(long item
, int geom
, int state
) const
1493 return m_genericImpl
->GetNextItem(item
, geom
, state
);
1495 if (m_dbImpl
&& geom
== wxLIST_NEXT_ALL
&& state
== wxLIST_STATE_SELECTED
)
1497 long count
= m_dbImpl
->MacGetCount() ;
1498 for ( long line
= item
+ 1 ; line
< count
; line
++ )
1500 wxMacDataItem
* id
= m_dbImpl
->GetItemFromLine(line
);
1501 if ( m_dbImpl
->IsItemSelected(id
) )
1511 wxImageList
*wxListCtrl::GetImageList(int which
) const
1514 return m_genericImpl
->GetImageList(which
);
1516 if ( which
== wxIMAGE_LIST_NORMAL
)
1518 return m_imageListNormal
;
1520 else if ( which
== wxIMAGE_LIST_SMALL
)
1522 return m_imageListSmall
;
1524 else if ( which
== wxIMAGE_LIST_STATE
)
1526 return m_imageListState
;
1531 void wxListCtrl::SetImageList(wxImageList
*imageList
, int which
)
1535 m_genericImpl
->SetImageList(imageList
, which
);
1539 if ( which
== wxIMAGE_LIST_NORMAL
)
1541 if (m_ownsImageListNormal
) delete m_imageListNormal
;
1542 m_imageListNormal
= imageList
;
1543 m_ownsImageListNormal
= false;
1545 else if ( which
== wxIMAGE_LIST_SMALL
)
1547 if (m_ownsImageListSmall
) delete m_imageListSmall
;
1548 m_imageListSmall
= imageList
;
1549 m_ownsImageListSmall
= false;
1551 else if ( which
== wxIMAGE_LIST_STATE
)
1553 if (m_ownsImageListState
) delete m_imageListState
;
1554 m_imageListState
= imageList
;
1555 m_ownsImageListState
= false;
1559 void wxListCtrl::AssignImageList(wxImageList
*imageList
, int which
)
1563 m_genericImpl
->AssignImageList(imageList
, which
);
1567 SetImageList(imageList
, which
);
1568 if ( which
== wxIMAGE_LIST_NORMAL
)
1569 m_ownsImageListNormal
= true;
1570 else if ( which
== wxIMAGE_LIST_SMALL
)
1571 m_ownsImageListSmall
= true;
1572 else if ( which
== wxIMAGE_LIST_STATE
)
1573 m_ownsImageListState
= true;
1576 // ----------------------------------------------------------------------------
1578 // ----------------------------------------------------------------------------
1580 // Arranges the items
1581 bool wxListCtrl::Arrange(int flag
)
1584 return m_genericImpl
->Arrange(flag
);
1589 bool wxListCtrl::DeleteItem(long item
)
1592 return m_genericImpl
->DeleteItem(item
);
1596 m_dbImpl
->MacDelete(item
);
1597 wxListEvent
event( wxEVT_COMMAND_LIST_DELETE_ITEM
, GetId() );
1598 event
.SetEventObject( this );
1599 event
.m_itemIndex
= item
;
1600 GetEventHandler()->ProcessEvent( event
);
1606 // Deletes all items
1607 bool wxListCtrl::DeleteAllItems()
1610 return m_genericImpl
->DeleteAllItems();
1614 m_dbImpl
->MacClear();
1615 wxListEvent
event( wxEVT_COMMAND_LIST_DELETE_ALL_ITEMS
, GetId() );
1616 event
.SetEventObject( this );
1617 GetEventHandler()->ProcessEvent( event
);
1622 // Deletes all items
1623 bool wxListCtrl::DeleteAllColumns()
1626 return m_genericImpl
->DeleteAllColumns();
1631 m_dbImpl
->GetColumnCount(&cols
);
1632 for (UInt32 col
= 0; col
< cols
; col
++)
1642 bool wxListCtrl::DeleteColumn(int col
)
1645 return m_genericImpl
->DeleteColumn(col
);
1649 OSStatus err
= m_dbImpl
->RemoveColumn(col
);
1650 return err
== noErr
;
1656 // Clears items, and columns if there are any.
1657 void wxListCtrl::ClearAll()
1661 m_genericImpl
->ClearAll();
1672 wxTextCtrl
* wxListCtrl::EditLabel(long item
, wxClassInfo
* textControlClass
)
1675 return m_genericImpl
->EditLabel(item
, textControlClass
);
1679 wxCHECK_MSG( (item
>= 0) && ((long)item
< GetItemCount()), NULL
,
1680 wxT("wrong index in wxListCtrl::EditLabel()") );
1682 wxASSERT_MSG( textControlClass
->IsKindOf(CLASSINFO(wxTextCtrl
)),
1683 wxT("EditLabel() needs a text control") );
1685 wxListEvent
le( wxEVT_COMMAND_LIST_BEGIN_LABEL_EDIT
, GetParent()->GetId() );
1686 le
.SetEventObject( this );
1687 le
.m_itemIndex
= item
;
1689 GetItem( le
.m_item
);
1691 if ( GetParent()->GetEventHandler()->ProcessEvent( le
) && !le
.IsAllowed() )
1693 // vetoed by user code
1697 wxTextCtrl
* const text
= (wxTextCtrl
*)textControlClass
->CreateObject();
1698 m_textctrlWrapper
= new wxListCtrlTextCtrlWrapper(this, text
, item
);
1699 return m_textctrlWrapper
->GetText();
1704 // End label editing, optionally cancelling the edit
1705 bool wxListCtrl::EndEditLabel(bool cancel
)
1707 // TODO: generic impl. doesn't have this method - is it needed for us?
1709 return true; // m_genericImpl->EndEditLabel(cancel);
1712 verify_noerr( SetDataBrowserEditItem(m_dbImpl
->GetControlRef(), kDataBrowserNoItem
, kMinColumnId
) );
1716 // Ensures this item is visible
1717 bool wxListCtrl::EnsureVisible(long item
)
1720 return m_genericImpl
->EnsureVisible(item
);
1724 wxMacDataItem
* dataItem
= m_dbImpl
->GetItemFromLine(item
);
1725 m_dbImpl
->RevealItem(dataItem
, kDataBrowserRevealWithoutSelecting
);
1731 // Find an item whose label matches this string, starting from the item after 'start'
1732 // or the beginning if 'start' is -1.
1733 long wxListCtrl::FindItem(long start
, const wxString
& str
, bool partial
)
1736 return m_genericImpl
->FindItem(start
, str
, partial
);
1738 wxString str_upper
= str
.Upper();
1743 long count
= GetItemCount();
1747 wxString line_upper
= GetItemText(idx
).Upper();
1750 if (line_upper
== str_upper
)
1755 if (line_upper
.find(str_upper
) == 0)
1765 // Find an item whose data matches this data, starting from the item after 'start'
1766 // or the beginning if 'start' is -1.
1767 long wxListCtrl::FindItem(long start
, long data
)
1770 return m_genericImpl
->FindItem(start
, data
);
1775 long count
= GetItemCount();
1779 if (GetItemData(idx
) == data
)
1787 // Find an item nearest this position in the specified direction, starting from
1788 // the item after 'start' or the beginning if 'start' is -1.
1789 long wxListCtrl::FindItem(long start
, const wxPoint
& pt
, int direction
)
1792 return m_genericImpl
->FindItem(start
, pt
, direction
);
1796 // Determines which item (if any) is at the specified point,
1797 // giving details in 'flags' (see wxLIST_HITTEST_... flags above)
1799 wxListCtrl::HitTest(const wxPoint
& point
, int& flags
, long *ptrSubItem
) const
1802 return m_genericImpl
->HitTest(point
, flags
, ptrSubItem
);
1804 flags
= wxLIST_HITTEST_NOWHERE
;
1807 int colHeaderHeight
= 22; // TODO: Find a way to get this value from the db control?
1808 UInt16 rowHeight
= 0;
1809 m_dbImpl
->GetDefaultRowHeight(&rowHeight
);
1812 // get the actual row by taking scroll position into account
1813 UInt32 offsetX
, offsetY
;
1814 m_dbImpl
->GetScrollPosition( &offsetY
, &offsetX
);
1817 if ( !(GetWindowStyleFlag() & wxLC_NO_HEADER
) )
1818 y
-= colHeaderHeight
;
1823 int row
= y
/ rowHeight
;
1824 DataBrowserItemID id
;
1825 m_dbImpl
->GetItemID( (DataBrowserTableViewRowIndex
) row
, &id
);
1827 // TODO: Use GetDataBrowserItemPartBounds to return if we are in icon or label
1828 if ( !(GetWindowStyleFlag() & wxLC_VIRTUAL
) )
1830 wxMacListCtrlItem
* lcItem
;
1831 lcItem
= (wxMacListCtrlItem
*) id
;
1834 flags
= wxLIST_HITTEST_ONITEM
;
1840 if (row
< GetItemCount() )
1842 flags
= wxLIST_HITTEST_ONITEM
;
1851 int wxListCtrl::GetScrollPos(int orient
) const
1854 return m_genericImpl
->GetScrollPos(orient
);
1858 UInt32 offsetX
, offsetY
;
1859 m_dbImpl
->GetScrollPosition( &offsetY
, &offsetX
);
1860 if ( orient
== wxHORIZONTAL
)
1869 // Inserts an item, returning the index of the new item if successful,
1871 long wxListCtrl::InsertItem(wxListItem
& info
)
1873 wxASSERT_MSG( !IsVirtual(), _T("can't be used with virtual controls") );
1876 return m_genericImpl
->InsertItem(info
);
1878 if (m_dbImpl
&& !IsVirtual())
1880 int count
= GetItemCount();
1882 if (info
.m_itemId
> count
)
1883 info
.m_itemId
= count
;
1885 m_dbImpl
->MacInsertItem(info
.m_itemId
, &info
);
1886 wxMacDataItem
* dataItem
= m_dbImpl
->GetItemFromLine(info
.m_itemId
);
1888 wxListEvent
event( wxEVT_COMMAND_LIST_INSERT_ITEM
, GetId() );
1889 event
.SetEventObject( this );
1890 event
.m_itemIndex
= info
.m_itemId
;
1891 GetEventHandler()->ProcessEvent( event
);
1892 return info
.m_itemId
;
1897 long wxListCtrl::InsertItem(long index
, const wxString
& label
)
1900 return m_genericImpl
->InsertItem(index
, label
);
1903 info
.m_text
= label
;
1904 info
.m_mask
= wxLIST_MASK_TEXT
;
1905 info
.m_itemId
= index
;
1906 return InsertItem(info
);
1909 // Inserts an image item
1910 long wxListCtrl::InsertItem(long index
, int imageIndex
)
1913 return m_genericImpl
->InsertItem(index
, imageIndex
);
1916 info
.m_image
= imageIndex
;
1917 info
.m_mask
= wxLIST_MASK_IMAGE
;
1918 info
.m_itemId
= index
;
1919 return InsertItem(info
);
1922 // Inserts an image/string item
1923 long wxListCtrl::InsertItem(long index
, const wxString
& label
, int imageIndex
)
1926 return m_genericImpl
->InsertItem(index
, label
, imageIndex
);
1929 info
.m_image
= imageIndex
;
1930 info
.m_text
= label
;
1931 info
.m_mask
= wxLIST_MASK_IMAGE
| wxLIST_MASK_TEXT
;
1932 info
.m_itemId
= index
;
1933 return InsertItem(info
);
1936 // For list view mode (only), inserts a column.
1937 long wxListCtrl::InsertColumn(long col
, wxListItem
& item
)
1940 return m_genericImpl
->InsertColumn(col
, item
);
1944 int width
= item
.GetWidth();
1945 if ( !(item
.GetMask() & wxLIST_MASK_WIDTH
) )
1948 DataBrowserPropertyType type
= kDataBrowserCustomType
; //kDataBrowserTextType;
1949 wxImageList
* imageList
= GetImageList(wxIMAGE_LIST_SMALL
);
1950 if (imageList
&& imageList
->GetImageCount() > 0)
1952 wxBitmap bmp
= imageList
->GetBitmap(0);
1954 // type = kDataBrowserIconAndTextType;
1957 SInt16 just
= teFlushDefault
;
1958 if (item
.GetMask() & wxLIST_MASK_FORMAT
)
1960 if (item
.GetAlign() == wxLIST_FORMAT_LEFT
)
1962 else if (item
.GetAlign() == wxLIST_FORMAT_CENTER
)
1964 else if (item
.GetAlign() == wxLIST_FORMAT_RIGHT
)
1965 just
= teFlushRight
;
1967 m_dbImpl
->InsertColumn(col
, type
, item
.GetText(), just
, width
);
1968 SetColumn(col
, item
);
1970 // set/remove options based on the wxListCtrl type.
1971 DataBrowserTableViewColumnID id
;
1972 m_dbImpl
->GetColumnIDFromIndex(col
, &id
);
1973 DataBrowserPropertyFlags flags
;
1974 verify_noerr(m_dbImpl
->GetPropertyFlags(id
, &flags
));
1975 if (GetWindowStyleFlag() & wxLC_EDIT_LABELS
)
1976 flags
|= kDataBrowserPropertyIsEditable
;
1978 if (GetWindowStyleFlag() & wxLC_VIRTUAL
){
1979 flags
&= ~kDataBrowserListViewSortableColumn
;
1981 verify_noerr(m_dbImpl
->SetPropertyFlags(id
, flags
));
1987 long wxListCtrl::InsertColumn(long col
,
1988 const wxString
& heading
,
1993 return m_genericImpl
->InsertColumn(col
, heading
, format
, width
);
1996 item
.m_mask
= wxLIST_MASK_TEXT
| wxLIST_MASK_FORMAT
;
1997 item
.m_text
= heading
;
2000 item
.m_mask
|= wxLIST_MASK_WIDTH
;
2001 item
.m_width
= width
;
2003 item
.m_format
= format
;
2005 return InsertColumn(col
, item
);
2008 // scroll the control by the given number of pixels (exception: in list view,
2009 // dx is interpreted as number of columns)
2010 bool wxListCtrl::ScrollList(int dx
, int dy
)
2013 return m_genericImpl
->ScrollList(dx
, dy
);
2017 m_dbImpl
->SetScrollPosition(dx
, dy
);
2023 bool wxListCtrl::SortItems(wxListCtrlCompare fn
, long data
)
2026 return m_genericImpl
->SortItems(fn
, data
);
2031 m_compareFuncData
= data
;
2032 SortDataBrowserContainer( m_dbImpl
->GetControlRef(), kDataBrowserNoItem
, true);
2034 // we need to do this after each call, else we get a crash from wxPython when
2035 // SortItems is called the second time.
2036 m_compareFunc
= NULL
;
2037 m_compareFuncData
= 0;
2043 void wxListCtrl::OnRenameTimer()
2045 wxCHECK_RET( HasCurrent(), wxT("unexpected rename timer") );
2047 EditLabel( m_current
);
2050 bool wxListCtrl::OnRenameAccept(long itemEdit
, const wxString
& value
)
2052 wxListEvent
le( wxEVT_COMMAND_LIST_END_LABEL_EDIT
, GetId() );
2053 le
.SetEventObject( this );
2054 le
.m_itemIndex
= itemEdit
;
2056 GetItem( le
.m_item
);
2057 le
.m_item
.m_text
= value
;
2058 return !GetEventHandler()->ProcessEvent( le
) ||
2062 void wxListCtrl::OnRenameCancelled(long itemEdit
)
2064 // let owner know that the edit was cancelled
2065 wxListEvent
le( wxEVT_COMMAND_LIST_END_LABEL_EDIT
, GetParent()->GetId() );
2067 le
.SetEditCanceled(true);
2069 le
.SetEventObject( this );
2070 le
.m_itemIndex
= itemEdit
;
2072 GetItem( le
.m_item
);
2073 GetEventHandler()->ProcessEvent( le
);
2076 // ----------------------------------------------------------------------------
2077 // virtual list controls
2078 // ----------------------------------------------------------------------------
2080 wxString
wxListCtrl::OnGetItemText(long WXUNUSED(item
), long WXUNUSED(col
)) const
2082 // this is a pure virtual function, in fact - which is not really pure
2083 // because the controls which are not virtual don't need to implement it
2084 wxFAIL_MSG( _T("wxListCtrl::OnGetItemText not supposed to be called") );
2086 return wxEmptyString
;
2089 int wxListCtrl::OnGetItemImage(long WXUNUSED(item
)) const
2091 wxCHECK_MSG(!GetImageList(wxIMAGE_LIST_SMALL
),
2093 wxT("List control has an image list, OnGetItemImage or OnGetItemColumnImage should be overridden."));
2097 int wxListCtrl::OnGetItemColumnImage(long item
, long column
) const
2100 return OnGetItemImage(item
);
2105 wxListItemAttr
*wxListCtrl::OnGetItemAttr(long WXUNUSED_UNLESS_DEBUG(item
)) const
2107 wxASSERT_MSG( item
>= 0 && item
< GetItemCount(),
2108 _T("invalid item index in OnGetItemAttr()") );
2110 // no attributes by default
2114 void wxListCtrl::SetItemCount(long count
)
2116 wxASSERT_MSG( IsVirtual(), _T("this is for virtual controls only") );
2120 m_genericImpl
->SetItemCount(count
);
2126 // we need to temporarily disable the new item creation notification
2127 // procedure to speed things up
2128 // FIXME: Even this doesn't seem to help much...
2130 // FIXME: Find a more efficient way to do this.
2131 m_dbImpl
->MacClear();
2133 DataBrowserCallbacks callbacks
;
2134 DataBrowserItemNotificationUPP itemUPP
;
2135 GetDataBrowserCallbacks(m_dbImpl
->GetControlRef(), &callbacks
);
2136 itemUPP
= callbacks
.u
.v1
.itemNotificationCallback
;
2137 callbacks
.u
.v1
.itemNotificationCallback
= 0;
2138 m_dbImpl
->SetCallbacks(&callbacks
);
2139 ::AddDataBrowserItems(m_dbImpl
->GetControlRef(), kDataBrowserNoItem
,
2140 count
, NULL
, kDataBrowserItemNoProperty
);
2141 callbacks
.u
.v1
.itemNotificationCallback
= itemUPP
;
2142 m_dbImpl
->SetCallbacks(&callbacks
);
2147 void wxListCtrl::RefreshItem(long item
)
2151 m_genericImpl
->RefreshItem(item
);
2156 GetItemRect(item
, rect
);
2160 void wxListCtrl::RefreshItems(long itemFrom
, long itemTo
)
2164 m_genericImpl
->RefreshItems(itemFrom
, itemTo
);
2168 wxRect rect1
, rect2
;
2169 GetItemRect(itemFrom
, rect1
);
2170 GetItemRect(itemTo
, rect2
);
2172 wxRect rect
= rect1
;
2173 rect
.height
= rect2
.GetBottom() - rect1
.GetTop();
2178 void wxListCtrl::SetDropTarget( wxDropTarget
*dropTarget
)
2180 #if wxUSE_DRAG_AND_DROP
2182 m_genericImpl
->SetDropTarget( dropTarget
);
2185 wxWindow::SetDropTarget( dropTarget
);
2189 wxDropTarget
*wxListCtrl::GetDropTarget() const
2191 #if wxUSE_DRAG_AND_DROP
2193 return m_genericImpl
->GetDropTarget();
2196 return wxWindow::GetDropTarget();
2201 // wxMac internal data structures
2203 wxMacListCtrlItem::~wxMacListCtrlItem()
2207 void wxMacListCtrlItem::Notification(wxMacDataItemBrowserControl
*owner
,
2208 DataBrowserItemNotification message
,
2209 DataBrowserItemDataRef itemData
) const
2212 wxMacDataBrowserListCtrlControl
*lb
= wxDynamicCast(owner
, wxMacDataBrowserListCtrlControl
);
2214 // we want to depend on as little as possible to make sure tear-down of controls is safe
2215 if ( message
== kDataBrowserItemRemoved
)
2217 if ( lb
!= NULL
&& lb
->GetClientDataType() == wxClientData_Object
)
2219 delete (wxClientData
*) (m_data
);
2225 else if ( message
== kDataBrowserItemAdded
)
2227 // we don't issue events on adding, the item is not really stored in the list yet, so we
2228 // avoid asserts by gettting out now
2232 wxListCtrl
*list
= wxDynamicCast( owner
->GetPeer() , wxListCtrl
);
2235 bool trigger
= false;
2237 wxListEvent
event( wxEVT_COMMAND_LIST_ITEM_SELECTED
, list
->GetId() );
2238 bool isSingle
= (list
->GetWindowStyle() & wxLC_SINGLE_SEL
) != 0;
2240 event
.SetEventObject( list
);
2241 event
.m_itemIndex
= owner
->GetLineFromItem( this ) ;
2242 if ( !list
->IsVirtual() )
2244 lb
->MacGetColumnInfo(event
.m_itemIndex
,0,event
.m_item
);
2249 case kDataBrowserItemDeselected
:
2250 event
.SetEventType(wxEVT_COMMAND_LIST_ITEM_DESELECTED
);
2252 trigger
= !lb
->IsSelectionSuppressed();
2255 case kDataBrowserItemSelected
:
2256 trigger
= !lb
->IsSelectionSuppressed();
2259 case kDataBrowserItemDoubleClicked
:
2260 event
.SetEventType( wxEVT_COMMAND_LIST_ITEM_ACTIVATED
);
2264 case kDataBrowserEditStarted
:
2265 // TODO : how to veto ?
2266 event
.SetEventType( wxEVT_COMMAND_LIST_BEGIN_LABEL_EDIT
) ;
2270 case kDataBrowserEditStopped
:
2271 // TODO probably trigger only upon the value store callback, because
2272 // here IIRC we cannot veto
2273 event
.SetEventType( wxEVT_COMMAND_LIST_END_LABEL_EDIT
) ;
2283 // direct notification is not always having the listbox GetSelection() having in synch with event
2284 wxPostEvent( list
->GetEventHandler(), event
);
2290 IMPLEMENT_DYNAMIC_CLASS(wxMacDataBrowserListCtrlControl
, wxMacDataItemBrowserControl
)
2292 wxMacDataBrowserListCtrlControl::wxMacDataBrowserListCtrlControl( wxWindow
*peer
, const wxPoint
& pos
, const wxSize
& size
, long style
)
2293 : wxMacDataItemBrowserControl( peer
, pos
, size
, style
)
2295 OSStatus err
= noErr
;
2296 m_clientDataItemsType
= wxClientData_None
;
2297 m_isVirtual
= false;
2299 if ( style
& wxLC_VIRTUAL
)
2302 DataBrowserSelectionFlags options
= kDataBrowserDragSelect
;
2303 if ( style
& wxLC_SINGLE_SEL
)
2305 options
|= kDataBrowserSelectOnlyOne
;
2309 options
|= kDataBrowserCmdTogglesSelection
;
2312 err
= SetSelectionFlags( options
);
2313 verify_noerr( err
);
2315 DataBrowserCustomCallbacks callbacks
;
2316 InitializeDataBrowserCustomCallbacks( &callbacks
, kDataBrowserLatestCustomCallbacks
);
2318 if ( gDataBrowserDrawItemUPP
== NULL
)
2319 gDataBrowserDrawItemUPP
= NewDataBrowserDrawItemUPP(DataBrowserDrawItemProc
);
2321 if ( gDataBrowserHitTestUPP
== NULL
)
2322 gDataBrowserHitTestUPP
= NewDataBrowserHitTestUPP(DataBrowserHitTestProc
);
2324 callbacks
.u
.v1
.drawItemCallback
= gDataBrowserDrawItemUPP
;
2325 callbacks
.u
.v1
.hitTestCallback
= gDataBrowserHitTestUPP
;
2327 SetDataBrowserCustomCallbacks( GetControlRef(), &callbacks
);
2329 if ( style
& wxLC_LIST
)
2331 InsertColumn(0, kDataBrowserIconAndTextType
, wxEmptyString
, -1, -1);
2332 verify_noerr( AutoSizeColumns() );
2335 if ( style
& wxLC_LIST
|| style
& wxLC_NO_HEADER
)
2336 verify_noerr( SetHeaderButtonHeight( 0 ) );
2339 SetSortProperty( kMinColumnId
- 1 );
2341 SetSortProperty( kMinColumnId
);
2342 if ( style
& wxLC_SORT_ASCENDING
)
2344 m_sortOrder
= SortOrder_Text_Ascending
;
2345 SetSortOrder( kDataBrowserOrderIncreasing
);
2347 else if ( style
& wxLC_SORT_DESCENDING
)
2349 m_sortOrder
= SortOrder_Text_Descending
;
2350 SetSortOrder( kDataBrowserOrderDecreasing
);
2354 m_sortOrder
= SortOrder_None
;
2357 if ( style
& wxLC_VRULES
)
2359 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4
2360 verify_noerr( DataBrowserChangeAttributes(m_controlRef
, kDataBrowserAttributeListViewDrawColumnDividers
, kDataBrowserAttributeNone
) );
2364 verify_noerr( SetHiliteStyle(kDataBrowserTableViewFillHilite
) );
2365 err
= SetHasScrollBars( (style
& wxHSCROLL
) != 0 , true );
2368 pascal Boolean
wxMacDataBrowserListCtrlControl::DataBrowserEditTextProc(
2370 DataBrowserItemID itemID
,
2371 DataBrowserPropertyID property
,
2372 CFStringRef theString
,
2373 Rect
*maxEditTextRect
,
2374 Boolean
*shrinkToFit
)
2376 Boolean result
= false;
2377 wxMacDataBrowserListCtrlControl
* ctl
= wxDynamicCast(wxMacControl::GetReferenceFromNativeControl( browser
), wxMacDataBrowserListCtrlControl
);
2380 result
= ctl
->ConfirmEditText(itemID
, property
, theString
, maxEditTextRect
, shrinkToFit
);
2381 theString
= CFSTR("Hello!");
2386 bool wxMacDataBrowserListCtrlControl::ConfirmEditText(
2387 DataBrowserItemID itemID
,
2388 DataBrowserPropertyID property
,
2389 CFStringRef theString
,
2390 Rect
*maxEditTextRect
,
2391 Boolean
*shrinkToFit
)
2396 pascal void wxMacDataBrowserListCtrlControl::DataBrowserDrawItemProc(
2398 DataBrowserItemID itemID
,
2399 DataBrowserPropertyID property
,
2400 DataBrowserItemState itemState
,
2401 const Rect
*itemRect
,
2403 Boolean colorDevice
)
2405 wxMacDataBrowserListCtrlControl
* ctl
= wxDynamicCast(wxMacControl::GetReferenceFromNativeControl( browser
), wxMacDataBrowserListCtrlControl
);
2408 ctl
->DrawItem(itemID
, property
, itemState
, itemRect
, gdDepth
, colorDevice
);
2412 // routines needed for DrawItem
2417 kTextBoxHeight
= 14,
2418 kIconTextSpacingV
= 2,
2420 kContentHeight
= kIconHeight
+ kTextBoxHeight
+ kIconTextSpacingV
2423 static void calculateCGDrawingBounds(CGRect inItemRect
, CGRect
*outIconRect
, CGRect
*outTextRect
, bool hasIcon
= false)
2426 float iconH
, iconW
= 0;
2427 float padding
= kItemPadding
;
2430 iconH
= kIconHeight
;
2432 padding
= padding
*2;
2435 textBottom
= inItemRect
.origin
.y
;
2437 *outIconRect
= CGRectMake(inItemRect
.origin
.x
+ kItemPadding
,
2438 textBottom
+ kIconTextSpacingV
, kIconWidth
,
2441 *outTextRect
= CGRectMake(inItemRect
.origin
.x
+ padding
+ iconW
,
2442 textBottom
+ kIconTextSpacingV
, inItemRect
.size
.width
- padding
- iconW
,
2443 inItemRect
.size
.height
- kIconTextSpacingV
);
2446 void wxMacDataBrowserListCtrlControl::DrawItem(
2447 DataBrowserItemID itemID
,
2448 DataBrowserPropertyID property
,
2449 DataBrowserItemState itemState
,
2450 const Rect
*itemRect
,
2452 Boolean colorDevice
)
2455 wxFont font
= wxNullFont
;
2457 short listColumn
= property
- kMinColumnId
;
2459 wxListCtrl
* list
= wxDynamicCast( GetPeer() , wxListCtrl
);
2460 wxMacListCtrlItem
* lcItem
;
2461 wxColour color
= *wxBLACK
;
2462 wxColour bgColor
= wxNullColour
;
2464 if (listColumn
>= 0)
2468 lcItem
= (wxMacListCtrlItem
*) itemID
;
2469 if (lcItem
->HasColumnInfo(listColumn
)){
2470 wxListItem
* item
= lcItem
->GetColumnInfo(listColumn
);
2472 // we always use the 0 column to get font and text/background colors.
2473 if (lcItem
->HasColumnInfo(0))
2475 wxListItem
* firstItem
= lcItem
->GetColumnInfo(0);
2476 color
= firstItem
->GetTextColour();
2477 bgColor
= firstItem
->GetBackgroundColour();
2478 font
= firstItem
->GetFont();
2481 if (item
->GetMask() & wxLIST_MASK_TEXT
)
2482 text
= item
->GetText();
2483 if (item
->GetMask() & wxLIST_MASK_IMAGE
)
2484 imgIndex
= item
->GetImage();
2490 text
= list
->OnGetItemText( (long)itemID
-1, listColumn
);
2491 imgIndex
= list
->OnGetItemColumnImage( (long)itemID
-1, listColumn
);
2492 wxListItemAttr
* attrs
= list
->OnGetItemAttr( (long)itemID
-1 );
2495 if (attrs
->HasBackgroundColour())
2496 bgColor
= attrs
->GetBackgroundColour();
2497 if (attrs
->HasTextColour())
2498 color
= attrs
->GetTextColour();
2499 if (attrs
->HasFont())
2500 font
= attrs
->GetFont();
2505 wxColour listBgColor
= list
->GetBackgroundColour();
2506 if (bgColor
== wxNullColour
)
2507 bgColor
= listBgColor
;
2509 wxFont listFont
= list
->GetFont();
2510 if (font
== wxNullFont
)
2513 wxMacCFStringHolder cfString
;
2514 cfString
.Assign( text
, wxLocale::GetSystemEncoding() );
2517 CGRect enclosingCGRect
, iconCGRect
, textCGRect
;
2519 ThemeDrawingState savedState
= NULL
;
2520 CGContextRef context
= (CGContextRef
)list
->MacGetDrawingContext();
2521 RGBColor labelColor
;
2523 labelColor
.green
= 0;
2524 labelColor
.blue
= 0;
2526 RGBColor backgroundColor
;
2527 backgroundColor
.red
= 255;
2528 backgroundColor
.green
= 255;
2529 backgroundColor
.blue
= 255;
2531 GetDataBrowserItemPartBounds(GetControlRef(), itemID
, property
, kDataBrowserPropertyEnclosingPart
,
2534 enclosingCGRect
= CGRectMake(enclosingRect
.left
,
2536 enclosingRect
.right
- enclosingRect
.left
,
2537 enclosingRect
.bottom
- enclosingRect
.top
);
2539 active
= IsControlActive(GetControlRef());
2541 // don't paint the background over the vertical rule line
2542 if ( list
->GetWindowStyleFlag() & wxLC_VRULES
)
2544 enclosingCGRect
.origin
.x
+= 1;
2545 enclosingCGRect
.size
.width
-= 1;
2547 if (itemState
== kDataBrowserItemIsSelected
)
2550 GetThemeDrawingState(&savedState
);
2552 GetThemeBrushAsColor(kThemeBrushAlternatePrimaryHighlightColor
, 32, true, &backgroundColor
);
2553 GetThemeTextColor(kThemeTextColorWhite
, gdDepth
, colorDevice
, &labelColor
);
2555 CGContextSaveGState(context
);
2557 CGContextSetRGBFillColor(context
, (float)backgroundColor
.red
/ (float)USHRT_MAX
,
2558 (float)backgroundColor
.green
/ (float)USHRT_MAX
,
2559 (float)backgroundColor
.blue
/ (float)USHRT_MAX
, 1.0);
2560 CGContextFillRect(context
, enclosingCGRect
);
2562 CGContextRestoreGState(context
);
2568 labelColor
= MAC_WXCOLORREF( color
.GetPixel() );
2569 else if (list
->GetTextColour().Ok())
2570 labelColor
= MAC_WXCOLORREF( list
->GetTextColour().GetPixel() );
2574 backgroundColor
= MAC_WXCOLORREF( bgColor
.GetPixel() );
2575 CGContextSaveGState(context
);
2577 CGContextSetRGBFillColor(context
, (float)backgroundColor
.red
/ (float)USHRT_MAX
,
2578 (float)backgroundColor
.green
/ (float)USHRT_MAX
,
2579 (float)backgroundColor
.blue
/ (float)USHRT_MAX
, 1.0);
2580 CGContextFillRect(context
, enclosingCGRect
);
2582 CGContextRestoreGState(context
);
2586 calculateCGDrawingBounds(enclosingCGRect
, &iconCGRect
, &textCGRect
, (imgIndex
!= -1) );
2590 wxImageList
* imageList
= list
->GetImageList(wxIMAGE_LIST_SMALL
);
2591 if (imageList
&& imageList
->GetImageCount() > 0){
2592 wxBitmap bmp
= imageList
->GetBitmap(imgIndex
);
2593 IconRef icon
= bmp
.GetBitmapData()->GetIconRef();
2595 CGContextSaveGState(context
);
2596 CGContextTranslateCTM(context
, 0,iconCGRect
.origin
.y
+ CGRectGetMaxY(iconCGRect
));
2597 CGContextScaleCTM(context
,1.0f
,-1.0f
);
2598 PlotIconRefInContext(context
, &iconCGRect
, kAlignNone
,
2599 active
? kTransformNone
: kTransformDisabled
, NULL
,
2600 kPlotIconRefNormalFlags
, icon
);
2602 CGContextRestoreGState(context
);
2606 HIThemeTextHorizontalFlush hFlush
= kHIThemeTextHorizontalFlushLeft
;
2607 UInt16 fontID
= kThemeViewsFont
;
2611 if (font
.GetFamily() != wxFONTFAMILY_DEFAULT
)
2612 fontID
= font
.MacGetThemeFontID();
2614 // FIXME: replace these with CG or ATSUI calls so we can remove this #ifndef.
2616 ::TextSize( (short)(font
.MacGetFontSize()) ) ;
2617 ::TextFace( font
.MacGetFontStyle() ) ;
2622 list
->GetColumn(listColumn
, item
);
2623 if (item
.GetMask() & wxLIST_MASK_FORMAT
)
2625 if (item
.GetAlign() == wxLIST_FORMAT_LEFT
)
2626 hFlush
= kHIThemeTextHorizontalFlushLeft
;
2627 else if (item
.GetAlign() == wxLIST_FORMAT_CENTER
)
2628 hFlush
= kHIThemeTextHorizontalFlushCenter
;
2629 else if (item
.GetAlign() == wxLIST_FORMAT_RIGHT
)
2631 hFlush
= kHIThemeTextHorizontalFlushRight
;
2632 textCGRect
.origin
.x
-= kItemPadding
; // give a little extra paddding
2636 HIThemeTextInfo info
;
2637 info
.version
= kHIThemeTextInfoVersionZero
;
2638 info
.state
= active
? kThemeStateActive
: kThemeStateInactive
;
2639 info
.fontID
= fontID
;
2640 info
.horizontalFlushness
= hFlush
;
2641 info
.verticalFlushness
= kHIThemeTextVerticalFlushCenter
;
2642 info
.options
= kHIThemeTextBoxOptionNone
;
2643 info
.truncationPosition
= kHIThemeTextTruncationEnd
;
2644 info
.truncationMaxLines
= 1;
2646 CGContextSaveGState(context
);
2647 CGContextSetRGBFillColor (context
, (float)labelColor
.red
/ (float)USHRT_MAX
,
2648 (float)labelColor
.green
/ (float)USHRT_MAX
,
2649 (float)labelColor
.blue
/ (float)USHRT_MAX
, 1.0);
2651 HIThemeDrawTextBox(cfString
, &textCGRect
, &info
, context
, kHIThemeOrientationNormal
);
2653 CGContextRestoreGState(context
);
2655 if (savedState
!= NULL
)
2656 SetThemeDrawingState(savedState
, true);
2659 OSStatus
wxMacDataBrowserListCtrlControl::GetSetItemData(DataBrowserItemID itemID
,
2660 DataBrowserPropertyID property
,
2661 DataBrowserItemDataRef itemData
,
2662 Boolean changeValue
)
2666 short listColumn
= property
- kMinColumnId
;
2668 OSStatus err
= errDataBrowserPropertyNotSupported
;
2669 wxListCtrl
* list
= wxDynamicCast( GetPeer() , wxListCtrl
);
2670 wxMacListCtrlItem
* lcItem
;
2672 if (listColumn
>= 0)
2676 lcItem
= (wxMacListCtrlItem
*) itemID
;
2677 if (lcItem
&& lcItem
->HasColumnInfo(listColumn
)){
2678 wxListItem
* item
= lcItem
->GetColumnInfo(listColumn
);
2679 if (item
->GetMask() & wxLIST_MASK_TEXT
)
2680 text
= item
->GetText();
2681 if (item
->GetMask() & wxLIST_MASK_IMAGE
)
2682 imgIndex
= item
->GetImage();
2687 text
= list
->OnGetItemText( (long)itemID
-1, listColumn
);
2688 imgIndex
= list
->OnGetItemColumnImage( (long)itemID
-1, listColumn
);
2696 case kDataBrowserItemIsEditableProperty
:
2697 if ( list
&& list
->HasFlag( wxLC_EDIT_LABELS
) )
2699 verify_noerr(SetDataBrowserItemDataBooleanValue( itemData
, true ));
2704 if ( property
>= kMinColumnId
)
2706 wxMacCFStringHolder cfStr
;
2709 cfStr
.Assign( text
, wxLocale::GetSystemEncoding() );
2710 err
= ::SetDataBrowserItemDataText( itemData
, cfStr
);
2716 if ( imgIndex
!= -1 )
2718 wxImageList
* imageList
= list
->GetImageList(wxIMAGE_LIST_SMALL
);
2719 if (imageList
&& imageList
->GetImageCount() > 0){
2720 wxBitmap bmp
= imageList
->GetBitmap(imgIndex
);
2721 IconRef icon
= bmp
.GetBitmapData()->GetIconRef();
2722 ::SetDataBrowserItemDataIcon(itemData
, icon
);
2736 if ( property
>= kMinColumnId
)
2738 short listColumn
= property
- kMinColumnId
;
2740 // TODO probably send the 'end edit' from here, as we
2741 // can then deal with the veto
2743 verify_noerr( GetDataBrowserItemDataText( itemData
, &sr
) ) ;
2744 wxMacCFStringHolder
cfStr(sr
) ;;
2746 list
->SetItem( (long)itemData
-1 , listColumn
, cfStr
.AsString() ) ;
2750 lcItem
->SetColumnTextValue( listColumn
, cfStr
.AsString() );
2760 void wxMacDataBrowserListCtrlControl::ItemNotification(DataBrowserItemID itemID
,
2761 DataBrowserItemNotification message
,
2762 DataBrowserItemDataRef itemData
)
2764 // we want to depend on as little as possible to make sure tear-down of controls is safe
2765 if ( message
== kDataBrowserItemRemoved
)
2767 // make sure MacDelete does the proper teardown.
2770 else if ( message
== kDataBrowserItemAdded
)
2772 // we don't issue events on adding, the item is not really stored in the list yet, so we
2773 // avoid asserts by getting out now
2777 wxListCtrl
*list
= wxDynamicCast( GetPeer() , wxListCtrl
);
2780 bool trigger
= false;
2782 wxListEvent
event( wxEVT_COMMAND_LIST_ITEM_SELECTED
, list
->GetId() );
2783 bool isSingle
= (list
->GetWindowStyle() & wxLC_SINGLE_SEL
) != 0;
2785 event
.SetEventObject( list
);
2786 if ( !list
->IsVirtual() )
2788 DataBrowserTableViewRowIndex result
= 0;
2789 verify_noerr( GetItemRow( itemID
, &result
) ) ;
2790 event
.m_itemIndex
= result
;
2792 if (event
.m_itemIndex
>= 0)
2793 MacGetColumnInfo(event
.m_itemIndex
,0,event
.m_item
);
2797 event
.m_itemIndex
= (long)itemID
-1;
2802 case kDataBrowserItemDeselected
:
2803 event
.SetEventType(wxEVT_COMMAND_LIST_ITEM_DESELECTED
);
2805 trigger
= !IsSelectionSuppressed();
2808 case kDataBrowserItemSelected
:
2809 trigger
= !IsSelectionSuppressed();
2813 case kDataBrowserItemDoubleClicked
:
2814 event
.SetEventType( wxEVT_COMMAND_LIST_ITEM_ACTIVATED
);
2818 case kDataBrowserEditStarted
:
2819 // TODO : how to veto ?
2820 event
.SetEventType( wxEVT_COMMAND_LIST_BEGIN_LABEL_EDIT
) ;
2824 case kDataBrowserEditStopped
:
2825 // TODO probably trigger only upon the value store callback, because
2826 // here IIRC we cannot veto
2827 event
.SetEventType( wxEVT_COMMAND_LIST_END_LABEL_EDIT
) ;
2837 // direct notification is not always having the listbox GetSelection() having in synch with event
2838 wxPostEvent( list
->GetEventHandler(), event
);
2843 Boolean
wxMacDataBrowserListCtrlControl::CompareItems(DataBrowserItemID itemOneID
,
2844 DataBrowserItemID itemTwoID
,
2845 DataBrowserPropertyID sortProperty
)
2848 bool retval
= false;
2850 wxString otherItemText
;
2851 int colId
= sortProperty
- kMinColumnId
;
2853 wxListCtrl
* list
= wxDynamicCast( GetPeer() , wxListCtrl
);
2859 wxMacListCtrlItem
* item
= (wxMacListCtrlItem
*)itemOneID
;
2860 wxMacListCtrlItem
* otherItem
= (wxMacListCtrlItem
*)itemTwoID
;
2862 wxListCtrlCompare func
= list
->GetCompareFunc();
2867 if (item
&& item
->HasColumnInfo(0))
2868 item1
= item
->GetColumnInfo(0)->GetData();
2869 if (otherItem
&& otherItem
->HasColumnInfo(0))
2870 item2
= otherItem
->GetColumnInfo(0)->GetData();
2872 if (item1
> -1 && item2
> -1)
2874 int result
= func(item1
, item2
, list
->GetCompareFuncData());
2878 if (item
->HasColumnInfo(colId
))
2879 itemText
= item
->GetColumnInfo(colId
)->GetText();
2880 if (otherItem
->HasColumnInfo(colId
))
2881 otherItemText
= otherItem
->GetColumnInfo(colId
)->GetText();
2886 long itemNum
= (long)itemOneID
;
2887 long otherItemNum
= (long)itemTwoID
;
2888 itemText
= list
->OnGetItemText( itemNum
-1, colId
);
2889 otherItemText
= list
->OnGetItemText( otherItemNum
-1, colId
);
2893 DataBrowserSortOrder sort
;
2894 verify_noerr(GetSortOrder(&sort
));
2896 if ( sort
== kDataBrowserOrderIncreasing
)
2898 retval
= itemText
.CmpNoCase( otherItemText
) > 0;
2900 else if ( sort
== kDataBrowserOrderDecreasing
)
2902 retval
= itemText
.CmpNoCase( otherItemText
) < 0;
2906 // fallback for undefined cases
2907 retval
= itemOneID
< itemTwoID
;
2913 wxMacDataBrowserListCtrlControl::~wxMacDataBrowserListCtrlControl()
2917 void wxMacDataBrowserListCtrlControl::MacSetColumnInfo( unsigned int row
, unsigned int column
, wxListItem
* item
)
2919 wxMacDataItem
* dataItem
= GetItemFromLine(row
);
2920 wxASSERT_MSG( dataItem
, _T("could not obtain wxMacDataItem for row in MacSetColumnInfo. Is row a valid wxListCtrl row?") );
2923 wxMacListCtrlItem
* listItem
= wx_static_cast(wxMacListCtrlItem
*,dataItem
);
2924 bool hasInfo
= listItem
->HasColumnInfo( column
);
2925 listItem
->SetColumnInfo( column
, item
);
2926 UpdateState(dataItem
, item
);
2928 wxListCtrl
* list
= wxDynamicCast( GetPeer() , wxListCtrl
);
2930 // NB: When this call was made before a control was completely shown, it would
2931 // update the item prematurely (i.e. no text would be listed) and, on show,
2932 // only the sorted column would be refreshed, meaning only first column text labels
2933 // would be shown. Making sure not to update items until the control is visible
2934 // seems to fix this issue.
2935 if (hasInfo
&& list
->IsShown())
2936 UpdateItem( wxMacDataBrowserRootContainer
, listItem
, kMinColumnId
+ column
);
2940 // apply changes that need to happen immediately, rather than when the
2941 // databrowser control fires a callback.
2942 void wxMacDataBrowserListCtrlControl::UpdateState(wxMacDataItem
* dataItem
, wxListItem
* listItem
)
2944 bool isSelected
= IsItemSelected( dataItem
);
2945 bool isSelectedState
= (listItem
->GetState() == wxLIST_STATE_SELECTED
);
2947 // toggle the selection state if wxListInfo state and actual state don't match.
2948 if ( isSelected
!= isSelectedState
)
2950 DataBrowserSetOption options
= kDataBrowserItemsAdd
;
2951 if (!isSelectedState
)
2952 options
= kDataBrowserItemsRemove
;
2953 SetSelectedItem(dataItem
, options
);
2955 // TODO: Set column width if item width > than current column width
2958 void wxMacDataBrowserListCtrlControl::MacGetColumnInfo( unsigned int row
, unsigned int column
, wxListItem
& item
)
2960 wxMacDataItem
* dataItem
= GetItemFromLine(row
);
2961 wxASSERT_MSG( dataItem
, _T("could not obtain wxMacDataItem in MacGetColumnInfo. Is row a valid wxListCtrl row?") );
2962 // CS should this guard against dataItem = 0 ? , as item is not a pointer if (item) is not appropriate
2965 wxMacListCtrlItem
* listItem
=wx_static_cast(wxMacListCtrlItem
*,dataItem
);
2967 if (!listItem
->HasColumnInfo( column
))
2970 wxListItem
* oldItem
= listItem
->GetColumnInfo( column
);
2974 long mask
= item
.GetMask();
2976 // by default, get everything for backwards compatibility
2979 if ( mask
& wxLIST_MASK_TEXT
)
2980 item
.SetText(oldItem
->GetText());
2981 if ( mask
& wxLIST_MASK_IMAGE
)
2982 item
.SetImage(oldItem
->GetImage());
2983 if ( mask
& wxLIST_MASK_DATA
)
2984 item
.SetData(oldItem
->GetData());
2985 if ( mask
& wxLIST_MASK_STATE
)
2986 item
.SetState(oldItem
->GetState());
2987 if ( mask
& wxLIST_MASK_WIDTH
)
2988 item
.SetWidth(oldItem
->GetWidth());
2989 if ( mask
& wxLIST_MASK_FORMAT
)
2990 item
.SetAlign(oldItem
->GetAlign());
2992 item
.SetTextColour(oldItem
->GetTextColour());
2993 item
.SetBackgroundColour(oldItem
->GetBackgroundColour());
2994 item
.SetFont(oldItem
->GetFont());
2999 void wxMacDataBrowserListCtrlControl::MacInsertItem( unsigned int n
, wxListItem
* item
)
3001 wxMacDataItemBrowserControl::MacInsert(n
, item
->GetText());
3002 MacSetColumnInfo(n
, 0, item
);
3005 wxMacDataItem
* wxMacDataBrowserListCtrlControl::CreateItem()
3007 return new wxMacListCtrlItem();
3010 wxMacListCtrlItem::wxMacListCtrlItem()
3012 m_rowItems
= wxListItemList( wxKEY_INTEGER
);
3015 int wxMacListCtrlItem::GetColumnImageValue( unsigned int column
)
3017 if ( HasColumnInfo(column
) )
3018 return GetColumnInfo(column
)->GetImage();
3023 void wxMacListCtrlItem::SetColumnImageValue( unsigned int column
, int imageIndex
)
3025 if ( HasColumnInfo(column
) )
3026 GetColumnInfo(column
)->SetImage(imageIndex
);
3029 wxString
wxMacListCtrlItem::GetColumnTextValue( unsigned int column
)
3034 if ( HasColumnInfo(column
) )
3035 return GetColumnInfo(column
)->GetText();
3037 return wxEmptyString
;
3040 void wxMacListCtrlItem::SetColumnTextValue( unsigned int column
, const wxString
& text
)
3042 if ( HasColumnInfo(column
) )
3043 GetColumnInfo(column
)->SetText(text
);
3045 // for compatibility with superclass APIs
3050 wxListItem
* wxMacListCtrlItem::GetColumnInfo( unsigned int column
)
3052 wxListItemList::compatibility_iterator node
= m_rowItems
.Find( column
);
3053 wxASSERT_MSG( node
, _T("invalid column index in wxMacListCtrlItem") );
3055 return node
->GetData();
3058 bool wxMacListCtrlItem::HasColumnInfo( unsigned int column
)
3060 return m_rowItems
.Find( column
) != NULL
;
3063 void wxMacListCtrlItem::SetColumnInfo( unsigned int column
, wxListItem
* item
)
3066 if ( !HasColumnInfo(column
) )
3068 wxListItem
* listItem
= new wxListItem(*item
);
3069 m_rowItems
.Append( column
, listItem
);
3073 wxListItem
* listItem
= GetColumnInfo( column
);
3074 long mask
= item
->GetMask();
3075 if (mask
& wxLIST_MASK_TEXT
)
3076 listItem
->SetText(item
->GetText());
3077 if (mask
& wxLIST_MASK_DATA
)
3078 listItem
->SetData(item
->GetData());
3079 if (mask
& wxLIST_MASK_IMAGE
)
3080 listItem
->SetImage(item
->GetImage());
3081 if (mask
& wxLIST_MASK_STATE
)
3082 listItem
->SetState(item
->GetState());
3083 if (mask
& wxLIST_MASK_FORMAT
)
3084 listItem
->SetAlign(item
->GetAlign());
3085 if (mask
& wxLIST_MASK_WIDTH
)
3086 listItem
->SetWidth(item
->GetWidth());
3088 if ( item
->HasAttributes() )
3090 if ( listItem
->HasAttributes() )
3091 listItem
->GetAttributes()->AssignFrom(*item
->GetAttributes());
3094 listItem
->SetTextColour(item
->GetTextColour());
3095 listItem
->SetBackgroundColour(item
->GetBackgroundColour());
3096 listItem
->SetFont(item
->GetFont());
3102 #endif // wxUSE_LISTCTRL