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 #include "wx/hashmap.h"
43 #define wxMAC_ALWAYS_USE_GENERIC_LISTCTRL wxT("mac.listctrl.always_use_generic")
45 #if wxUSE_EXTENDED_RTTI
46 WX_DEFINE_FLAGS( wxListCtrlStyle
)
48 wxBEGIN_FLAGS( wxListCtrlStyle
)
49 // new style border flags, we put them first to
50 // use them for streaming out
51 wxFLAGS_MEMBER(wxBORDER_SIMPLE
)
52 wxFLAGS_MEMBER(wxBORDER_SUNKEN
)
53 wxFLAGS_MEMBER(wxBORDER_DOUBLE
)
54 wxFLAGS_MEMBER(wxBORDER_RAISED
)
55 wxFLAGS_MEMBER(wxBORDER_STATIC
)
56 wxFLAGS_MEMBER(wxBORDER_NONE
)
58 // old style border flags
59 wxFLAGS_MEMBER(wxSIMPLE_BORDER
)
60 wxFLAGS_MEMBER(wxSUNKEN_BORDER
)
61 wxFLAGS_MEMBER(wxDOUBLE_BORDER
)
62 wxFLAGS_MEMBER(wxRAISED_BORDER
)
63 wxFLAGS_MEMBER(wxSTATIC_BORDER
)
64 wxFLAGS_MEMBER(wxBORDER
)
66 // standard window styles
67 wxFLAGS_MEMBER(wxTAB_TRAVERSAL
)
68 wxFLAGS_MEMBER(wxCLIP_CHILDREN
)
69 wxFLAGS_MEMBER(wxTRANSPARENT_WINDOW
)
70 wxFLAGS_MEMBER(wxWANTS_CHARS
)
71 wxFLAGS_MEMBER(wxFULL_REPAINT_ON_RESIZE
)
72 wxFLAGS_MEMBER(wxALWAYS_SHOW_SB
)
73 wxFLAGS_MEMBER(wxVSCROLL
)
74 wxFLAGS_MEMBER(wxHSCROLL
)
76 wxFLAGS_MEMBER(wxLC_LIST
)
77 wxFLAGS_MEMBER(wxLC_REPORT
)
78 wxFLAGS_MEMBER(wxLC_ICON
)
79 wxFLAGS_MEMBER(wxLC_SMALL_ICON
)
80 wxFLAGS_MEMBER(wxLC_ALIGN_TOP
)
81 wxFLAGS_MEMBER(wxLC_ALIGN_LEFT
)
82 wxFLAGS_MEMBER(wxLC_AUTOARRANGE
)
83 wxFLAGS_MEMBER(wxLC_USER_TEXT
)
84 wxFLAGS_MEMBER(wxLC_EDIT_LABELS
)
85 wxFLAGS_MEMBER(wxLC_NO_HEADER
)
86 wxFLAGS_MEMBER(wxLC_SINGLE_SEL
)
87 wxFLAGS_MEMBER(wxLC_SORT_ASCENDING
)
88 wxFLAGS_MEMBER(wxLC_SORT_DESCENDING
)
89 wxFLAGS_MEMBER(wxLC_VIRTUAL
)
91 wxEND_FLAGS( wxListCtrlStyle
)
93 IMPLEMENT_DYNAMIC_CLASS_XTI(wxListCtrl
, wxControl
,"wx/listctrl.h")
95 wxBEGIN_PROPERTIES_TABLE(wxListCtrl
)
96 wxEVENT_PROPERTY( TextUpdated
, wxEVT_COMMAND_TEXT_UPDATED
, wxCommandEvent
)
98 wxPROPERTY_FLAGS( WindowStyle
, wxListCtrlStyle
, long , SetWindowStyleFlag
, GetWindowStyleFlag
, EMPTY_MACROVALUE
, 0 /*flags*/ , wxT("Helpstring") , wxT("group")) // style
99 wxEND_PROPERTIES_TABLE()
101 wxBEGIN_HANDLERS_TABLE(wxListCtrl
)
102 wxEND_HANDLERS_TABLE()
104 wxCONSTRUCTOR_5( wxListCtrl
, wxWindow
* , Parent
, wxWindowID
, Id
, wxPoint
, Position
, wxSize
, Size
, long , WindowStyle
)
107 TODO : Expose more information of a list's layout etc. via appropriate objects (à la NotebookPageInfo)
110 IMPLEMENT_DYNAMIC_CLASS(wxListCtrl
, wxControl
)
113 IMPLEMENT_DYNAMIC_CLASS(wxListView
, wxListCtrl
)
114 IMPLEMENT_DYNAMIC_CLASS(wxListItem
, wxObject
)
116 IMPLEMENT_DYNAMIC_CLASS(wxListEvent
, wxNotifyEvent
)
118 WX_DECLARE_HASH_MAP( int, wxListItem
*, wxIntegerHash
, wxIntegerEqual
, wxListItemList
);
120 #include "wx/listimpl.cpp"
121 WX_DEFINE_LIST(wxColumnList
)
123 // so we can check for column clicks
124 static const EventTypeSpec eventList
[] =
126 { kEventClassControl
, kEventControlHit
},
127 { kEventClassControl
, kEventControlDraw
}
130 static pascal OSStatus
wxMacListCtrlEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
132 OSStatus result
= eventNotHandledErr
;
134 wxMacCarbonEvent
cEvent( event
) ;
136 ControlRef controlRef
;
137 cEvent
.GetParameter( kEventParamDirectObject
, &controlRef
) ;
139 wxListCtrl
*window
= (wxListCtrl
*) data
;
140 wxListEvent
le( wxEVT_COMMAND_LIST_COL_CLICK
, window
->GetId() );
141 le
.SetEventObject( window
);
143 switch ( GetEventKind( event
) )
145 // check if the column was clicked on and fire an event if so
146 case kEventControlHit
:
148 ControlPartCode result
= cEvent
.GetParameter
<ControlPartCode
>(kEventParamControlPart
, typeControlPartCode
) ;
149 if (result
== kControlButtonPart
){
150 DataBrowserPropertyID col
;
151 GetDataBrowserSortProperty(controlRef
, &col
);
152 int column
= col
- kMinColumnId
;
154 // FIXME: we can't use the sort property for virtual listctrls
155 // so we need to find a better way to determine which column was clicked...
156 if (!window
->IsVirtual())
157 window
->GetEventHandler()->ProcessEvent( le
);
159 result
= CallNextEventHandler(handler
, event
);
162 case kEventControlDraw
:
164 CGContextRef context
= cEvent
.GetParameter
<CGContextRef
>(kEventParamCGContextRef
, typeCGContextRef
) ;
165 window
->MacSetDrawingContext(context
);
166 result
= CallNextEventHandler(handler
, event
);
167 window
->MacSetDrawingContext(NULL
);
178 DEFINE_ONE_SHOT_HANDLER_GETTER( wxMacListCtrlEventHandler
)
180 class wxMacListCtrlItem
: public wxMacListBoxItem
185 virtual void Notification(wxMacDataItemBrowserControl
*owner
,
186 DataBrowserItemNotification message
,
187 DataBrowserItemDataRef itemData
) const;
189 virtual void SetColumnInfo( unsigned int column
, wxListItem
* item
);
190 virtual wxListItem
* GetColumnInfo( unsigned int column
);
191 virtual bool HasColumnInfo( unsigned int column
);
193 virtual void SetColumnTextValue( unsigned int column
, const wxString
& text
);
194 virtual wxString
GetColumnTextValue( unsigned int column
);
196 virtual int GetColumnImageValue( unsigned int column
);
197 virtual void SetColumnImageValue( unsigned int column
, int imageIndex
);
199 virtual ~wxMacListCtrlItem();
201 wxListItemList m_rowItems
;
204 DataBrowserDrawItemUPP gDataBrowserDrawItemUPP
= NULL
;
205 //DataBrowserEditItemUPP gDataBrowserEditItemUPP = NULL;
206 DataBrowserHitTestUPP gDataBrowserHitTestUPP
= NULL
;
208 // TODO: Make a better name!!
209 class wxMacDataBrowserListCtrlControl
: public wxMacDataItemBrowserControl
212 wxMacDataBrowserListCtrlControl( wxWindow
*peer
, const wxPoint
& pos
, const wxSize
& size
, long style
);
213 wxMacDataBrowserListCtrlControl() {}
214 virtual ~wxMacDataBrowserListCtrlControl();
216 // create a list item (can be a subclass of wxMacListBoxItem)
218 virtual wxMacDataItem
* CreateItem();
220 virtual void MacInsertItem( unsigned int n
, wxListItem
* item
);
221 virtual void MacSetColumnInfo( unsigned int row
, unsigned int column
, wxListItem
* item
);
222 virtual void MacGetColumnInfo( unsigned int row
, unsigned int column
, wxListItem
& item
);
223 virtual void UpdateState(wxMacDataItem
* dataItem
, wxListItem
* item
);
226 // we need to override to provide specialized handling for virtual wxListCtrls
227 virtual OSStatus
GetSetItemData(DataBrowserItemID itemID
,
228 DataBrowserPropertyID property
,
229 DataBrowserItemDataRef itemData
,
230 Boolean changeValue
);
232 virtual void ItemNotification(
233 DataBrowserItemID itemID
,
234 DataBrowserItemNotification message
,
235 DataBrowserItemDataRef itemData
);
237 virtual Boolean
CompareItems(DataBrowserItemID itemOneID
,
238 DataBrowserItemID itemTwoID
,
239 DataBrowserPropertyID sortProperty
);
241 static pascal void DataBrowserDrawItemProc(ControlRef browser
,
242 DataBrowserItemID item
,
243 DataBrowserPropertyID property
,
244 DataBrowserItemState itemState
,
247 Boolean colorDevice
);
249 virtual void DrawItem(DataBrowserItemID itemID
,
250 DataBrowserPropertyID property
,
251 DataBrowserItemState itemState
,
252 const Rect
*itemRect
,
254 Boolean colorDevice
);
256 static pascal Boolean
DataBrowserEditTextProc(ControlRef browser
,
257 DataBrowserItemID item
,
258 DataBrowserPropertyID property
,
259 CFStringRef theString
,
260 Rect
*maxEditTextRect
,
261 Boolean
*shrinkToFit
);
263 static pascal Boolean
DataBrowserHitTestProc(ControlRef browser
,
264 DataBrowserItemID itemID
,
265 DataBrowserPropertyID property
,
267 const Rect
*mouseRect
) { return true; }
269 virtual bool ConfirmEditText(DataBrowserItemID item
,
270 DataBrowserPropertyID property
,
271 CFStringRef theString
,
272 Rect
*maxEditTextRect
,
273 Boolean
*shrinkToFit
);
277 wxClientDataType m_clientDataItemsType
;
279 DECLARE_DYNAMIC_CLASS_NO_COPY(wxMacDataBrowserListCtrlControl
)
282 class wxMacListCtrlEventDelegate
: public wxEvtHandler
285 wxMacListCtrlEventDelegate( wxListCtrl
* list
, int id
);
286 virtual bool ProcessEvent( wxEvent
& event
);
293 wxMacListCtrlEventDelegate::wxMacListCtrlEventDelegate( wxListCtrl
* list
, int id
)
299 bool wxMacListCtrlEventDelegate::ProcessEvent( wxEvent
& event
)
301 // even though we use a generic list ctrl underneath, make sure
302 // we present ourselves as wxListCtrl.
303 event
.SetEventObject( m_list
);
306 if ( !event
.IsKindOf( CLASSINFO( wxCommandEvent
) ) )
308 if (m_list
->GetEventHandler()->ProcessEvent( event
))
311 return wxEvtHandler::ProcessEvent(event
);
314 //-----------------------------------------------------------------------------
315 // wxListCtrlRenameTimer (internal)
316 //-----------------------------------------------------------------------------
318 class wxListCtrlRenameTimer
: public wxTimer
324 wxListCtrlRenameTimer( wxListCtrl
*owner
);
328 //-----------------------------------------------------------------------------
329 // wxListCtrlTextCtrlWrapper: wraps a wxTextCtrl to make it work for inline editing
330 //-----------------------------------------------------------------------------
332 class wxListCtrlTextCtrlWrapper
: public wxEvtHandler
335 // NB: text must be a valid object but not Create()d yet
336 wxListCtrlTextCtrlWrapper(wxListCtrl
*owner
,
340 wxTextCtrl
*GetText() const { return m_text
; }
342 void AcceptChangesAndFinish();
345 void OnChar( wxKeyEvent
&event
);
346 void OnKeyUp( wxKeyEvent
&event
);
347 void OnKillFocus( wxFocusEvent
&event
);
349 bool AcceptChanges();
355 wxString m_startValue
;
358 bool m_aboutToFinish
;
360 DECLARE_EVENT_TABLE()
363 //-----------------------------------------------------------------------------
364 // wxListCtrlRenameTimer (internal)
365 //-----------------------------------------------------------------------------
367 wxListCtrlRenameTimer::wxListCtrlRenameTimer( wxListCtrl
*owner
)
372 void wxListCtrlRenameTimer::Notify()
374 m_owner
->OnRenameTimer();
377 //-----------------------------------------------------------------------------
378 // wxListCtrlTextCtrlWrapper (internal)
379 //-----------------------------------------------------------------------------
381 BEGIN_EVENT_TABLE(wxListCtrlTextCtrlWrapper
, wxEvtHandler
)
382 EVT_CHAR (wxListCtrlTextCtrlWrapper::OnChar
)
383 EVT_KEY_UP (wxListCtrlTextCtrlWrapper::OnKeyUp
)
384 EVT_KILL_FOCUS (wxListCtrlTextCtrlWrapper::OnKillFocus
)
387 wxListCtrlTextCtrlWrapper::wxListCtrlTextCtrlWrapper(wxListCtrl
*owner
,
390 : m_startValue(owner
->GetItemText(itemEdit
)),
391 m_itemEdited(itemEdit
)
396 m_aboutToFinish
= false;
400 owner
->GetItemRect(itemEdit
, rectLabel
);
402 m_text
->Create(owner
, wxID_ANY
, m_startValue
,
403 wxPoint(rectLabel
.x
+offset
,rectLabel
.y
),
404 wxSize(rectLabel
.width
-offset
,rectLabel
.height
));
407 m_text
->PushEventHandler(this);
410 void wxListCtrlTextCtrlWrapper::Finish()
416 m_text
->RemoveEventHandler(this);
417 m_owner
->FinishEditing(m_text
);
419 wxPendingDelete
.Append( this );
423 bool wxListCtrlTextCtrlWrapper::AcceptChanges()
425 const wxString value
= m_text
->GetValue();
427 if ( value
== m_startValue
)
428 // nothing changed, always accept
431 if ( !m_owner
->OnRenameAccept(m_itemEdited
, value
) )
432 // vetoed by the user
435 // accepted, do rename the item
436 m_owner
->SetItemText(m_itemEdited
, value
);
441 void wxListCtrlTextCtrlWrapper::AcceptChangesAndFinish()
443 m_aboutToFinish
= true;
445 // Notify the owner about the changes
448 // Even if vetoed, close the control (consistent with MSW)
452 void wxListCtrlTextCtrlWrapper::OnChar( wxKeyEvent
&event
)
454 switch ( event
.m_keyCode
)
457 AcceptChangesAndFinish();
461 m_owner
->OnRenameCancelled( m_itemEdited
);
470 void wxListCtrlTextCtrlWrapper::OnKeyUp( wxKeyEvent
&event
)
478 // auto-grow the textctrl:
479 wxSize parentSize
= m_owner
->GetSize();
480 wxPoint myPos
= m_text
->GetPosition();
481 wxSize mySize
= m_text
->GetSize();
483 m_text
->GetTextExtent(m_text
->GetValue() + _T("MM"), &sx
, &sy
);
484 if (myPos
.x
+ sx
> parentSize
.x
)
485 sx
= parentSize
.x
- myPos
.x
;
488 m_text
->SetSize(sx
, wxDefaultCoord
);
493 void wxListCtrlTextCtrlWrapper::OnKillFocus( wxFocusEvent
&event
)
495 if ( !m_finished
&& !m_aboutToFinish
)
497 if ( !AcceptChanges() )
498 m_owner
->OnRenameCancelled( m_itemEdited
);
503 // We must let the native text control handle focus
507 BEGIN_EVENT_TABLE(wxListCtrl
, wxControl
)
508 EVT_LEFT_DOWN(wxListCtrl::OnLeftDown
)
509 EVT_LEFT_DCLICK(wxListCtrl::OnDblClick
)
512 // ============================================================================
514 // ============================================================================
516 wxMacListControl
* wxListCtrl::GetPeer() const
518 wxMacDataBrowserListCtrlControl
*lb
= wxDynamicCast(m_peer
,wxMacDataBrowserListCtrlControl
);
519 return lb
? wx_static_cast(wxMacListControl
*,lb
) : 0 ;
522 // ----------------------------------------------------------------------------
523 // wxListCtrl construction
524 // ----------------------------------------------------------------------------
526 void wxListCtrl::Init()
528 m_imageListNormal
= NULL
;
529 m_imageListSmall
= NULL
;
530 m_imageListState
= NULL
;
532 // keep track of if we created our own image lists, or if they were assigned
534 m_ownsImageListNormal
= m_ownsImageListSmall
= m_ownsImageListState
= false;
538 m_genericImpl
= NULL
;
540 m_compareFunc
= NULL
;
541 m_compareFuncData
= 0;
542 m_colsInfo
= wxColumnList();
543 m_textColor
= wxNullColour
;
544 m_bgColor
= wxNullColour
;
545 m_textctrlWrapper
= NULL
;
547 m_renameTimer
= new wxListCtrlRenameTimer( this );
550 class wxGenericListCtrlHook
: public wxGenericListCtrl
553 wxGenericListCtrlHook(wxListCtrl
* parent
,
558 const wxValidator
& validator
,
559 const wxString
& name
)
560 : wxGenericListCtrl(parent
, id
, pos
, size
, style
, validator
, name
),
561 m_nativeListCtrl(parent
)
566 virtual wxListItemAttr
* OnGetItemAttr(long item
) const
568 return m_nativeListCtrl
->OnGetItemAttr(item
);
571 virtual int OnGetItemImage(long item
) const
573 return m_nativeListCtrl
->OnGetItemImage(item
);
576 virtual int OnGetItemColumnImage(long item
, long column
) const
578 return m_nativeListCtrl
->OnGetItemColumnImage(item
, column
);
581 virtual wxString
OnGetItemText(long item
, long column
) const
583 return m_nativeListCtrl
->OnGetItemText(item
, column
);
586 wxListCtrl
* m_nativeListCtrl
;
590 void wxListCtrl::OnLeftDown(wxMouseEvent
& event
)
592 if ( m_textctrlWrapper
)
595 m_textctrlWrapper
->AcceptChangesAndFinish();
599 long current
= HitTest(event
.GetPosition(), hitResult
);
600 if ((current
== m_current
) &&
601 (hitResult
== wxLIST_HITTEST_ONITEM
) &&
602 HasFlag(wxLC_EDIT_LABELS
) )
604 m_renameTimer
->Start( 100, true );
613 void wxListCtrl::OnDblClick(wxMouseEvent
& event
)
619 bool wxListCtrl::Create(wxWindow
*parent
,
624 const wxValidator
& validator
,
625 const wxString
& name
)
628 // for now, we'll always use the generic list control for ICON and LIST views,
629 // because they dynamically change the number of columns on resize.
630 // Also, allow the user to set it to use the list ctrl as well.
631 if ( (wxSystemOptions::HasOption( wxMAC_ALWAYS_USE_GENERIC_LISTCTRL
)
632 && (wxSystemOptions::GetOptionInt( wxMAC_ALWAYS_USE_GENERIC_LISTCTRL
) == 1)) ||
633 (style
& wxLC_ICON
) || (style
& wxLC_SMALL_ICON
) || (style
& wxLC_LIST
) )
635 m_macIsUserPane
= true;
637 long paneStyle
= style
;
638 paneStyle
&= ~wxSIMPLE_BORDER
;
639 paneStyle
&= ~wxDOUBLE_BORDER
;
640 paneStyle
&= ~wxSUNKEN_BORDER
;
641 paneStyle
&= ~wxRAISED_BORDER
;
642 paneStyle
&= ~wxSTATIC_BORDER
;
643 if ( !wxWindow::Create(parent
, id
, pos
, size
, paneStyle
| wxNO_BORDER
, name
) )
646 // since the generic control is a child, make sure we position it at 0, 0
647 m_genericImpl
= new wxGenericListCtrlHook(this, id
, wxPoint(0, 0), size
, style
, validator
, name
);
648 m_genericImpl
->PushEventHandler( new wxMacListCtrlEventDelegate( this, GetId() ) );
654 m_macIsUserPane
= false;
656 if ( !wxWindow::Create(parent
, id
, pos
, size
, style
, name
) )
658 m_dbImpl
= new wxMacDataBrowserListCtrlControl( this, pos
, size
, style
);
661 MacPostControlCreate( pos
, size
);
663 InstallControlEventHandler( m_peer
->GetControlRef() , GetwxMacListCtrlEventHandlerUPP(),
664 GetEventTypeCount(eventList
), eventList
, this,
665 (EventHandlerRef
*)&m_macListCtrlEventHandler
);
671 wxListCtrl::~wxListCtrl()
675 m_genericImpl
->PopEventHandler(/* deleteHandler = */ true);
678 if (m_ownsImageListNormal
)
679 delete m_imageListNormal
;
680 if (m_ownsImageListSmall
)
681 delete m_imageListSmall
;
682 if (m_ownsImageListState
)
683 delete m_imageListState
;
685 delete m_renameTimer
;
688 // ----------------------------------------------------------------------------
689 // set/get/change style
690 // ----------------------------------------------------------------------------
692 // Add or remove a single window style
693 void wxListCtrl::SetSingleStyle(long style
, bool add
)
695 long flag
= GetWindowStyleFlag();
697 // Get rid of conflicting styles
700 if ( style
& wxLC_MASK_TYPE
)
701 flag
= flag
& ~wxLC_MASK_TYPE
;
702 if ( style
& wxLC_MASK_ALIGN
)
703 flag
= flag
& ~wxLC_MASK_ALIGN
;
704 if ( style
& wxLC_MASK_SORT
)
705 flag
= flag
& ~wxLC_MASK_SORT
;
713 SetWindowStyleFlag(flag
);
716 // Set the whole window style
717 void wxListCtrl::SetWindowStyleFlag(long flag
)
719 if ( flag
!= m_windowStyle
)
721 m_windowStyle
= flag
;
725 m_genericImpl
->SetWindowStyleFlag(flag
);
732 void wxListCtrl::DoSetSize( int x
, int y
, int width
, int height
, int sizeFlags
)
734 wxControl::DoSetSize(x
, y
, width
, height
, sizeFlags
);
737 m_genericImpl
->SetSize(0, 0, width
, height
, sizeFlags
);
739 // determine if we need a horizontal scrollbar, and add it if so
743 for (int column
= 0; column
< GetColumnCount(); column
++)
745 totalWidth
+= m_dbImpl
->GetColumnWidth( column
);
748 Boolean vertScrollBar
;
749 GetDataBrowserHasScrollBars( m_dbImpl
->GetControlRef(), NULL
, &vertScrollBar
);
750 if (totalWidth
> width
)
751 SetDataBrowserHasScrollBars( m_dbImpl
->GetControlRef(), true, vertScrollBar
);
753 SetDataBrowserHasScrollBars( m_dbImpl
->GetControlRef(), false, vertScrollBar
);
757 wxSize
wxListCtrl::DoGetBestSize() const
759 return wxWindow::DoGetBestSize();
762 bool wxListCtrl::SetFont(const wxFont
& font
)
765 rv
= wxControl::SetFont(font
);
767 rv
= m_genericImpl
->SetFont(font
);
771 bool wxListCtrl::SetForegroundColour(const wxColour
& colour
)
775 rv
= m_genericImpl
->SetForegroundColour(colour
);
777 SetTextColour(colour
);
781 bool wxListCtrl::SetBackgroundColour(const wxColour
& colour
)
785 rv
= m_genericImpl
->SetBackgroundColour(colour
);
791 wxColour
wxListCtrl::GetBackgroundColour()
794 return m_genericImpl
->GetBackgroundColour();
801 // ----------------------------------------------------------------------------
803 // ----------------------------------------------------------------------------
805 // Gets information about this column
806 bool wxListCtrl::GetColumn(int col
, wxListItem
& item
) const
809 return m_genericImpl
->GetColumn(col
, item
);
815 wxColumnList::compatibility_iterator node
= m_colsInfo
.Item( col
);
816 wxASSERT_MSG( node
, _T("invalid column index in wxMacListCtrlItem") );
817 wxListItem
* column
= node
->GetData();
819 long mask
= column
->GetMask();
820 if (mask
& wxLIST_MASK_TEXT
)
821 item
.SetText(column
->GetText());
822 if (mask
& wxLIST_MASK_DATA
)
823 item
.SetData(column
->GetData());
824 if (mask
& wxLIST_MASK_IMAGE
)
825 item
.SetImage(column
->GetImage());
826 if (mask
& wxLIST_MASK_STATE
)
827 item
.SetState(column
->GetState());
828 if (mask
& wxLIST_MASK_FORMAT
)
829 item
.SetAlign(column
->GetAlign());
830 if (mask
& wxLIST_MASK_WIDTH
)
831 item
.SetWidth(column
->GetWidth());
837 // Sets information about this column
838 bool wxListCtrl::SetColumn(int col
, wxListItem
& item
)
841 return m_genericImpl
->SetColumn(col
, item
);
845 long mask
= item
.GetMask();
846 if ( col
>= (int)m_colsInfo
.GetCount() )
848 wxListItem
* listItem
= new wxListItem(item
);
849 m_colsInfo
.Append( listItem
);
854 GetColumn( col
, listItem
);
856 if (mask
& wxLIST_MASK_TEXT
)
857 listItem
.SetText(item
.GetText());
858 if (mask
& wxLIST_MASK_DATA
)
859 listItem
.SetData(item
.GetData());
860 if (mask
& wxLIST_MASK_IMAGE
)
861 listItem
.SetImage(item
.GetImage());
862 if (mask
& wxLIST_MASK_STATE
)
863 listItem
.SetState(item
.GetState());
864 if (mask
& wxLIST_MASK_FORMAT
)
865 listItem
.SetAlign(item
.GetAlign());
866 if (mask
& wxLIST_MASK_WIDTH
)
867 listItem
.SetWidth(item
.GetWidth());
870 // change the appearance in the databrowser.
871 DataBrowserListViewHeaderDesc columnDesc
;
872 columnDesc
.version
=kDataBrowserListViewLatestHeaderDesc
;
873 verify_noerr( m_dbImpl
->GetHeaderDesc( kMinColumnId
+ col
, &columnDesc
) );
876 if (item.GetMask() & wxLIST_MASK_TEXT)
880 enc = m_font.GetEncoding();
882 enc = wxLocale::GetSystemEncoding();
883 wxMacCFStringHolder cfTitle;
884 cfTitle.Assign( item.GetText() , enc );
885 if(columnDesc.titleString)
886 CFRelease(columnDesc.titleString);
887 columnDesc.titleString = cfTitle;
891 if (item
.GetMask() & wxLIST_MASK_IMAGE
&& item
.GetImage() != -1 )
893 columnDesc
.btnContentInfo
.contentType
= kControlContentIconRef
;
894 wxImageList
* imageList
= GetImageList(wxIMAGE_LIST_SMALL
);
895 if (imageList
&& imageList
->GetImageCount() > 0 )
897 wxBitmap bmp
= imageList
->GetBitmap( item
.GetImage() );
898 IconRef icon
= bmp
.GetBitmapData()->GetIconRef();
899 columnDesc
.btnContentInfo
.u
.iconRef
= icon
;
903 verify_noerr( m_dbImpl
->SetHeaderDesc( kMinColumnId
+ col
, &columnDesc
) );
909 int wxListCtrl::GetColumnCount() const
912 return m_genericImpl
->GetColumnCount();
917 m_dbImpl
->GetColumnCount(&count
);
924 // Gets the column width
925 int wxListCtrl::GetColumnWidth(int col
) const
928 return m_genericImpl
->GetColumnWidth(col
);
932 return m_dbImpl
->GetColumnWidth(col
);
938 // Sets the column width
939 bool wxListCtrl::SetColumnWidth(int col
, int width
)
942 return m_genericImpl
->SetColumnWidth(col
, width
);
947 if (width
== wxLIST_AUTOSIZE
|| width
== wxLIST_AUTOSIZE_USEHEADER
)
952 for (int column
= 0; column
< GetColumnCount(); column
++)
955 GetColumn(col
, colInfo
);
957 colInfo
.SetWidth(width
);
958 SetColumn(col
, colInfo
);
960 m_dbImpl
->SetColumnWidth(col
, mywidth
);
966 GetColumn(col
, colInfo
);
968 colInfo
.SetWidth(width
);
969 SetColumn(col
, colInfo
);
970 m_dbImpl
->SetColumnWidth(col
, mywidth
);
978 // Gets the number of items that can fit vertically in the
979 // visible area of the list control (list or report view)
980 // or the total number of items in the list control (icon
981 // or small icon view)
982 int wxListCtrl::GetCountPerPage() const
985 return m_genericImpl
->GetCountPerPage();
994 // Gets the edit control for editing labels.
995 wxTextCtrl
* wxListCtrl::GetEditControl() const
998 return m_genericImpl
->GetEditControl();
1003 // Gets information about the item
1004 bool wxListCtrl::GetItem(wxListItem
& info
) const
1007 return m_genericImpl
->GetItem(info
);
1012 m_dbImpl
->MacGetColumnInfo(info
.m_itemId
, info
.m_col
, info
);
1015 info
.SetText( OnGetItemText(info
.m_itemId
, info
.m_col
) );
1016 info
.SetImage( OnGetItemColumnImage(info
.m_itemId
, info
.m_col
) );
1017 if (info
.GetMask() & wxLIST_MASK_STATE
)
1019 if (IsDataBrowserItemSelected( m_dbImpl
->GetControlRef(), info
.m_itemId
+1 ))
1020 info
.SetState(info
.GetState() | wxLIST_STATE_SELECTED
);
1023 wxListItemAttr
* attrs
= OnGetItemAttr( info
.m_itemId
);
1026 info
.SetFont( attrs
->GetFont() );
1027 info
.SetBackgroundColour( attrs
->GetBackgroundColour() );
1028 info
.SetTextColour( attrs
->GetTextColour() );
1032 bool success
= true;
1036 // Sets information about the item
1037 bool wxListCtrl::SetItem(wxListItem
& info
)
1040 return m_genericImpl
->SetItem(info
);
1043 m_dbImpl
->MacSetColumnInfo( info
.m_itemId
, info
.m_col
, &info
);
1048 long wxListCtrl::SetItem(long index
, int col
, const wxString
& label
, int imageId
)
1051 return m_genericImpl
->SetItem(index
, col
, label
, imageId
);
1054 info
.m_text
= label
;
1055 info
.m_mask
= wxLIST_MASK_TEXT
;
1056 info
.m_itemId
= index
;
1060 info
.m_image
= imageId
;
1061 info
.m_mask
|= wxLIST_MASK_IMAGE
;
1063 return SetItem(info
);
1067 // Gets the item state
1068 int wxListCtrl::GetItemState(long item
, long stateMask
) const
1071 return m_genericImpl
->GetItemState(item
, stateMask
);
1075 if ( HasFlag(wxLC_VIRTUAL
) )
1077 if (stateMask
== wxLIST_STATE_SELECTED
)
1079 if (IsDataBrowserItemSelected( m_dbImpl
->GetControlRef(), item
+1 ))
1080 return wxLIST_STATE_SELECTED
;
1089 info
.m_mask
= wxLIST_MASK_STATE
;
1090 info
.m_stateMask
= stateMask
;
1091 info
.m_itemId
= item
;
1096 return info
.m_state
;
1103 // Sets the item state
1104 bool wxListCtrl::SetItemState(long item
, long state
, long stateMask
)
1107 return m_genericImpl
->SetItemState(item
, state
, stateMask
);
1111 DataBrowserSetOption option
= kDataBrowserItemsAdd
;
1112 if ( stateMask
== wxLIST_STATE_SELECTED
&& state
== 0 )
1113 option
= kDataBrowserItemsRemove
;
1117 if ( HasFlag(wxLC_VIRTUAL
) )
1119 wxMacDataItemBrowserSelectionSuppressor
suppressor(m_dbImpl
);
1120 m_dbImpl
->SetSelectedAllItems(option
);
1124 for(int i
= 0; i
< GetItemCount();i
++)
1128 info
.m_mask
= wxLIST_MASK_STATE
;
1129 info
.m_stateMask
= stateMask
;
1130 info
.m_state
= state
;
1137 if ( HasFlag(wxLC_VIRTUAL
) )
1139 long itemID
= item
+1;
1140 SetDataBrowserSelectedItems(m_dbImpl
->GetControlRef(), 1, (DataBrowserItemID
*)&itemID
, option
);
1145 info
.m_itemId
= item
;
1146 info
.m_mask
= wxLIST_MASK_STATE
;
1147 info
.m_stateMask
= stateMask
;
1148 info
.m_state
= state
;
1149 return SetItem(info
);
1156 // Sets the item image
1157 bool wxListCtrl::SetItemImage(long item
, int image
, int WXUNUSED(selImage
))
1159 return SetItemColumnImage(item
, 0, image
);
1162 // Sets the item image
1163 bool wxListCtrl::SetItemColumnImage(long item
, long column
, int image
)
1166 return m_genericImpl
->SetItemColumnImage(item
, column
, image
);
1170 info
.m_mask
= wxLIST_MASK_IMAGE
;
1171 info
.m_image
= image
;
1172 info
.m_itemId
= item
;
1173 info
.m_col
= column
;
1175 return SetItem(info
);
1178 // Gets the item text
1179 wxString
wxListCtrl::GetItemText(long item
) const
1182 return m_genericImpl
->GetItemText(item
);
1186 info
.m_mask
= wxLIST_MASK_TEXT
;
1187 info
.m_itemId
= item
;
1190 return wxEmptyString
;
1194 // Sets the item text
1195 void wxListCtrl::SetItemText(long item
, const wxString
& str
)
1198 return m_genericImpl
->SetItemText(item
, str
);
1202 info
.m_mask
= wxLIST_MASK_TEXT
;
1203 info
.m_itemId
= item
;
1209 // Gets the item data
1210 long wxListCtrl::GetItemData(long item
) const
1213 return m_genericImpl
->GetItemData(item
);
1217 info
.m_mask
= wxLIST_MASK_DATA
;
1218 info
.m_itemId
= item
;
1225 // Sets the item data
1226 bool wxListCtrl::SetItemData(long item
, long data
)
1229 return m_genericImpl
->SetItemData(item
, data
);
1233 info
.m_mask
= wxLIST_MASK_DATA
;
1234 info
.m_itemId
= item
;
1237 return SetItem(info
);
1240 wxRect
wxListCtrl::GetViewRect() const
1242 wxASSERT_MSG( !HasFlag(wxLC_REPORT
| wxLC_LIST
),
1243 _T("wxListCtrl::GetViewRect() only works in icon mode") );
1246 return m_genericImpl
->GetViewRect();
1252 // Gets the item rectangle
1253 bool wxListCtrl::GetItemRect(long item
, wxRect
& rect
, int code
) const
1256 return m_genericImpl
->GetItemRect(item
, rect
, code
);
1261 DataBrowserItemID id
;
1262 DataBrowserPropertyID col
= kMinColumnId
;
1264 DataBrowserPropertyPart part
= kDataBrowserPropertyEnclosingPart
;
1265 if ( code
== wxLIST_RECT_LABEL
)
1266 part
= kDataBrowserPropertyTextPart
;
1267 else if ( code
== wxLIST_RECT_ICON
)
1268 part
= kDataBrowserPropertyIconPart
;
1270 if ( !(GetWindowStyleFlag() & wxLC_VIRTUAL
) )
1272 wxMacDataItem
* thisItem
= m_dbImpl
->GetItemFromLine(item
);
1273 id
= (DataBrowserItemID
) thisItem
;
1278 GetDataBrowserItemPartBounds( m_dbImpl
->GetControlRef(), id
, col
, part
, &bounds
);
1280 rect
.x
= bounds
.left
;
1281 rect
.y
= bounds
.top
;
1282 rect
.width
= bounds
.right
- bounds
.left
; //GetClientSize().x; // we need the width of the whole row, not just the item.
1283 rect
.height
= bounds
.bottom
- bounds
.top
;
1284 //fprintf("id = %d, bounds = %d, %d, %d, %d\n", id, rect.x, rect.y, rect.width, rect.height);
1289 // Gets the item position
1290 bool wxListCtrl::GetItemPosition(long item
, wxPoint
& pos
) const
1293 return m_genericImpl
->GetItemPosition(item
, pos
);
1295 bool success
= false;
1300 GetItemRect(item
, itemRect
);
1301 pos
= itemRect
.GetPosition();
1308 // Sets the item position.
1309 bool wxListCtrl::SetItemPosition(long item
, const wxPoint
& pos
)
1312 return m_genericImpl
->SetItemPosition(item
, pos
);
1317 // Gets the number of items in the list control
1318 int wxListCtrl::GetItemCount() const
1321 return m_genericImpl
->GetItemCount();
1324 return m_dbImpl
->MacGetCount();
1329 void wxListCtrl::SetItemSpacing( int spacing
, bool isSmall
)
1332 m_genericImpl
->SetItemSpacing(spacing
, isSmall
);
1335 wxSize
wxListCtrl::GetItemSpacing() const
1338 return m_genericImpl
->GetItemSpacing();
1340 return wxSize(0, 0);
1343 void wxListCtrl::SetItemTextColour( long item
, const wxColour
&col
)
1347 m_genericImpl
->SetItemTextColour(item
, col
);
1352 info
.m_itemId
= item
;
1353 info
.SetTextColour( col
);
1357 wxColour
wxListCtrl::GetItemTextColour( long item
) const
1360 return m_genericImpl
->GetItemTextColour(item
);
1366 return info
.GetTextColour();
1368 return wxNullColour
;
1371 void wxListCtrl::SetItemBackgroundColour( long item
, const wxColour
&col
)
1375 m_genericImpl
->SetItemBackgroundColour(item
, col
);
1380 info
.m_itemId
= item
;
1381 info
.SetBackgroundColour( col
);
1385 wxColour
wxListCtrl::GetItemBackgroundColour( long item
) const
1388 return m_genericImpl
->GetItemBackgroundColour(item
);
1394 return info
.GetBackgroundColour();
1396 return wxNullColour
;
1399 void wxListCtrl::SetItemFont( long item
, const wxFont
&f
)
1403 m_genericImpl
->SetItemFont(item
, f
);
1408 info
.m_itemId
= item
;
1413 wxFont
wxListCtrl::GetItemFont( long item
) const
1416 return m_genericImpl
->GetItemFont(item
);
1422 return info
.GetFont();
1428 // Gets the number of selected items in the list control
1429 int wxListCtrl::GetSelectedItemCount() const
1432 return m_genericImpl
->GetSelectedItemCount();
1435 return m_dbImpl
->GetSelectedItemCount(NULL
, true);
1440 // Gets the text colour of the listview
1441 wxColour
wxListCtrl::GetTextColour() const
1444 return m_genericImpl
->GetTextColour();
1446 // TODO: we need owner drawn list items to customize text color.
1450 return wxNullColour
;
1453 // Sets the text colour of the listview
1454 void wxListCtrl::SetTextColour(const wxColour
& col
)
1458 m_genericImpl
->SetTextColour(col
);
1466 // Gets the index of the topmost visible item when in
1467 // list or report view
1468 long wxListCtrl::GetTopItem() const
1471 return m_genericImpl
->GetTopItem();
1476 long item
= HitTest( wxPoint(1, 1), flags
);
1477 if (flags
== wxLIST_HITTEST_ONITEM
)
1484 // Searches for an item, starting from 'item'.
1485 // 'geometry' is one of
1486 // wxLIST_NEXT_ABOVE/ALL/BELOW/LEFT/RIGHT.
1487 // 'state' is a state bit flag, one or more of
1488 // wxLIST_STATE_DROPHILITED/FOCUSED/SELECTED/CUT.
1489 // item can be -1 to find the first item that matches the
1491 // Returns the item or -1 if unsuccessful.
1492 long wxListCtrl::GetNextItem(long item
, int geom
, int state
) const
1495 return m_genericImpl
->GetNextItem(item
, geom
, state
);
1497 if (m_dbImpl
&& geom
== wxLIST_NEXT_ALL
&& state
== wxLIST_STATE_SELECTED
)
1499 long count
= m_dbImpl
->MacGetCount() ;
1500 for ( long line
= item
+ 1 ; line
< count
; line
++ )
1502 wxMacDataItem
* id
= m_dbImpl
->GetItemFromLine(line
);
1503 if ( m_dbImpl
->IsItemSelected(id
) )
1513 wxImageList
*wxListCtrl::GetImageList(int which
) const
1516 return m_genericImpl
->GetImageList(which
);
1518 if ( which
== wxIMAGE_LIST_NORMAL
)
1520 return m_imageListNormal
;
1522 else if ( which
== wxIMAGE_LIST_SMALL
)
1524 return m_imageListSmall
;
1526 else if ( which
== wxIMAGE_LIST_STATE
)
1528 return m_imageListState
;
1533 void wxListCtrl::SetImageList(wxImageList
*imageList
, int which
)
1537 m_genericImpl
->SetImageList(imageList
, which
);
1541 if ( which
== wxIMAGE_LIST_NORMAL
)
1543 if (m_ownsImageListNormal
) delete m_imageListNormal
;
1544 m_imageListNormal
= imageList
;
1545 m_ownsImageListNormal
= false;
1547 else if ( which
== wxIMAGE_LIST_SMALL
)
1549 if (m_ownsImageListSmall
) delete m_imageListSmall
;
1550 m_imageListSmall
= imageList
;
1551 m_ownsImageListSmall
= false;
1553 else if ( which
== wxIMAGE_LIST_STATE
)
1555 if (m_ownsImageListState
) delete m_imageListState
;
1556 m_imageListState
= imageList
;
1557 m_ownsImageListState
= false;
1561 void wxListCtrl::AssignImageList(wxImageList
*imageList
, int which
)
1565 m_genericImpl
->AssignImageList(imageList
, which
);
1569 SetImageList(imageList
, which
);
1570 if ( which
== wxIMAGE_LIST_NORMAL
)
1571 m_ownsImageListNormal
= true;
1572 else if ( which
== wxIMAGE_LIST_SMALL
)
1573 m_ownsImageListSmall
= true;
1574 else if ( which
== wxIMAGE_LIST_STATE
)
1575 m_ownsImageListState
= true;
1578 // ----------------------------------------------------------------------------
1580 // ----------------------------------------------------------------------------
1582 // Arranges the items
1583 bool wxListCtrl::Arrange(int flag
)
1586 return m_genericImpl
->Arrange(flag
);
1591 bool wxListCtrl::DeleteItem(long item
)
1594 return m_genericImpl
->DeleteItem(item
);
1598 m_dbImpl
->MacDelete(item
);
1599 wxListEvent
event( wxEVT_COMMAND_LIST_DELETE_ITEM
, GetId() );
1600 event
.SetEventObject( this );
1601 event
.m_itemIndex
= item
;
1602 GetEventHandler()->ProcessEvent( event
);
1608 // Deletes all items
1609 bool wxListCtrl::DeleteAllItems()
1612 return m_genericImpl
->DeleteAllItems();
1616 m_dbImpl
->MacClear();
1617 wxListEvent
event( wxEVT_COMMAND_LIST_DELETE_ALL_ITEMS
, GetId() );
1618 event
.SetEventObject( this );
1619 GetEventHandler()->ProcessEvent( event
);
1624 // Deletes all items
1625 bool wxListCtrl::DeleteAllColumns()
1628 return m_genericImpl
->DeleteAllColumns();
1633 m_dbImpl
->GetColumnCount(&cols
);
1634 for (UInt32 col
= 0; col
< cols
; col
++)
1644 bool wxListCtrl::DeleteColumn(int col
)
1647 return m_genericImpl
->DeleteColumn(col
);
1651 OSStatus err
= m_dbImpl
->RemoveColumn(col
);
1652 return err
== noErr
;
1658 // Clears items, and columns if there are any.
1659 void wxListCtrl::ClearAll()
1663 m_genericImpl
->ClearAll();
1674 wxTextCtrl
* wxListCtrl::EditLabel(long item
, wxClassInfo
* textControlClass
)
1677 return m_genericImpl
->EditLabel(item
, textControlClass
);
1681 wxCHECK_MSG( (item
>= 0) && ((long)item
< GetItemCount()), NULL
,
1682 wxT("wrong index in wxListCtrl::EditLabel()") );
1684 wxASSERT_MSG( textControlClass
->IsKindOf(CLASSINFO(wxTextCtrl
)),
1685 wxT("EditLabel() needs a text control") );
1687 wxListEvent
le( wxEVT_COMMAND_LIST_BEGIN_LABEL_EDIT
, GetParent()->GetId() );
1688 le
.SetEventObject( this );
1689 le
.m_itemIndex
= item
;
1691 GetItem( le
.m_item
);
1693 if ( GetParent()->GetEventHandler()->ProcessEvent( le
) && !le
.IsAllowed() )
1695 // vetoed by user code
1699 wxTextCtrl
* const text
= (wxTextCtrl
*)textControlClass
->CreateObject();
1700 m_textctrlWrapper
= new wxListCtrlTextCtrlWrapper(this, text
, item
);
1701 return m_textctrlWrapper
->GetText();
1706 // End label editing, optionally cancelling the edit
1707 bool wxListCtrl::EndEditLabel(bool cancel
)
1709 // TODO: generic impl. doesn't have this method - is it needed for us?
1711 return true; // m_genericImpl->EndEditLabel(cancel);
1714 verify_noerr( SetDataBrowserEditItem(m_dbImpl
->GetControlRef(), kDataBrowserNoItem
, kMinColumnId
) );
1718 // Ensures this item is visible
1719 bool wxListCtrl::EnsureVisible(long item
)
1722 return m_genericImpl
->EnsureVisible(item
);
1726 wxMacDataItem
* dataItem
= m_dbImpl
->GetItemFromLine(item
);
1727 m_dbImpl
->RevealItem(dataItem
, kDataBrowserRevealWithoutSelecting
);
1733 // Find an item whose label matches this string, starting from the item after 'start'
1734 // or the beginning if 'start' is -1.
1735 long wxListCtrl::FindItem(long start
, const wxString
& str
, bool partial
)
1738 return m_genericImpl
->FindItem(start
, str
, partial
);
1740 wxString str_upper
= str
.Upper();
1745 long count
= GetItemCount();
1749 wxString line_upper
= GetItemText(idx
).Upper();
1752 if (line_upper
== str_upper
)
1757 if (line_upper
.find(str_upper
) == 0)
1767 // Find an item whose data matches this data, starting from the item after 'start'
1768 // or the beginning if 'start' is -1.
1769 long wxListCtrl::FindItem(long start
, long data
)
1772 return m_genericImpl
->FindItem(start
, data
);
1777 long count
= GetItemCount();
1781 if (GetItemData(idx
) == data
)
1789 // Find an item nearest this position in the specified direction, starting from
1790 // the item after 'start' or the beginning if 'start' is -1.
1791 long wxListCtrl::FindItem(long start
, const wxPoint
& pt
, int direction
)
1794 return m_genericImpl
->FindItem(start
, pt
, direction
);
1798 // Determines which item (if any) is at the specified point,
1799 // giving details in 'flags' (see wxLIST_HITTEST_... flags above)
1801 wxListCtrl::HitTest(const wxPoint
& point
, int& flags
, long *ptrSubItem
) const
1804 return m_genericImpl
->HitTest(point
, flags
, ptrSubItem
);
1806 flags
= wxLIST_HITTEST_NOWHERE
;
1809 int colHeaderHeight
= 22; // TODO: Find a way to get this value from the db control?
1810 UInt16 rowHeight
= 0;
1811 m_dbImpl
->GetDefaultRowHeight(&rowHeight
);
1814 // get the actual row by taking scroll position into account
1815 UInt32 offsetX
, offsetY
;
1816 m_dbImpl
->GetScrollPosition( &offsetY
, &offsetX
);
1819 if ( !(GetWindowStyleFlag() & wxLC_NO_HEADER
) )
1820 y
-= colHeaderHeight
;
1825 int row
= y
/ rowHeight
;
1826 DataBrowserItemID id
;
1827 m_dbImpl
->GetItemID( (DataBrowserTableViewRowIndex
) row
, &id
);
1829 // TODO: Use GetDataBrowserItemPartBounds to return if we are in icon or label
1830 if ( !(GetWindowStyleFlag() & wxLC_VIRTUAL
) )
1832 wxMacListCtrlItem
* lcItem
;
1833 lcItem
= (wxMacListCtrlItem
*) id
;
1836 flags
= wxLIST_HITTEST_ONITEM
;
1842 if (row
< GetItemCount() )
1844 flags
= wxLIST_HITTEST_ONITEM
;
1853 int wxListCtrl::GetScrollPos(int orient
) const
1856 return m_genericImpl
->GetScrollPos(orient
);
1860 UInt32 offsetX
, offsetY
;
1861 m_dbImpl
->GetScrollPosition( &offsetY
, &offsetX
);
1862 if ( orient
== wxHORIZONTAL
)
1871 // Inserts an item, returning the index of the new item if successful,
1873 long wxListCtrl::InsertItem(wxListItem
& info
)
1875 wxASSERT_MSG( !IsVirtual(), _T("can't be used with virtual controls") );
1878 return m_genericImpl
->InsertItem(info
);
1880 if (m_dbImpl
&& !IsVirtual())
1882 int count
= GetItemCount();
1884 if (info
.m_itemId
> count
)
1885 info
.m_itemId
= count
;
1887 m_dbImpl
->MacInsertItem(info
.m_itemId
, &info
);
1888 wxMacDataItem
* dataItem
= m_dbImpl
->GetItemFromLine(info
.m_itemId
);
1890 wxListEvent
event( wxEVT_COMMAND_LIST_INSERT_ITEM
, GetId() );
1891 event
.SetEventObject( this );
1892 event
.m_itemIndex
= info
.m_itemId
;
1893 GetEventHandler()->ProcessEvent( event
);
1894 return info
.m_itemId
;
1899 long wxListCtrl::InsertItem(long index
, const wxString
& label
)
1902 return m_genericImpl
->InsertItem(index
, label
);
1905 info
.m_text
= label
;
1906 info
.m_mask
= wxLIST_MASK_TEXT
;
1907 info
.m_itemId
= index
;
1908 return InsertItem(info
);
1911 // Inserts an image item
1912 long wxListCtrl::InsertItem(long index
, int imageIndex
)
1915 return m_genericImpl
->InsertItem(index
, imageIndex
);
1918 info
.m_image
= imageIndex
;
1919 info
.m_mask
= wxLIST_MASK_IMAGE
;
1920 info
.m_itemId
= index
;
1921 return InsertItem(info
);
1924 // Inserts an image/string item
1925 long wxListCtrl::InsertItem(long index
, const wxString
& label
, int imageIndex
)
1928 return m_genericImpl
->InsertItem(index
, label
, imageIndex
);
1931 info
.m_image
= imageIndex
;
1932 info
.m_text
= label
;
1933 info
.m_mask
= wxLIST_MASK_IMAGE
| wxLIST_MASK_TEXT
;
1934 info
.m_itemId
= index
;
1935 return InsertItem(info
);
1938 // For list view mode (only), inserts a column.
1939 long wxListCtrl::InsertColumn(long col
, wxListItem
& item
)
1942 return m_genericImpl
->InsertColumn(col
, item
);
1946 int width
= item
.GetWidth();
1947 if ( !(item
.GetMask() & wxLIST_MASK_WIDTH
) )
1950 DataBrowserPropertyType type
= kDataBrowserCustomType
; //kDataBrowserTextType;
1951 wxImageList
* imageList
= GetImageList(wxIMAGE_LIST_SMALL
);
1952 if (imageList
&& imageList
->GetImageCount() > 0)
1954 wxBitmap bmp
= imageList
->GetBitmap(0);
1956 // type = kDataBrowserIconAndTextType;
1959 SInt16 just
= teFlushDefault
;
1960 if (item
.GetMask() & wxLIST_MASK_FORMAT
)
1962 if (item
.GetAlign() == wxLIST_FORMAT_LEFT
)
1964 else if (item
.GetAlign() == wxLIST_FORMAT_CENTER
)
1966 else if (item
.GetAlign() == wxLIST_FORMAT_RIGHT
)
1967 just
= teFlushRight
;
1969 m_dbImpl
->InsertColumn(col
, type
, item
.GetText(), just
, width
);
1970 SetColumn(col
, item
);
1972 // set/remove options based on the wxListCtrl type.
1973 DataBrowserTableViewColumnID id
;
1974 m_dbImpl
->GetColumnIDFromIndex(col
, &id
);
1975 DataBrowserPropertyFlags flags
;
1976 verify_noerr(m_dbImpl
->GetPropertyFlags(id
, &flags
));
1977 if (GetWindowStyleFlag() & wxLC_EDIT_LABELS
)
1978 flags
|= kDataBrowserPropertyIsEditable
;
1980 if (GetWindowStyleFlag() & wxLC_VIRTUAL
){
1981 flags
&= ~kDataBrowserListViewSortableColumn
;
1983 verify_noerr(m_dbImpl
->SetPropertyFlags(id
, flags
));
1989 long wxListCtrl::InsertColumn(long col
,
1990 const wxString
& heading
,
1995 return m_genericImpl
->InsertColumn(col
, heading
, format
, width
);
1998 item
.m_mask
= wxLIST_MASK_TEXT
| wxLIST_MASK_FORMAT
;
1999 item
.m_text
= heading
;
2002 item
.m_mask
|= wxLIST_MASK_WIDTH
;
2003 item
.m_width
= width
;
2005 item
.m_format
= format
;
2007 return InsertColumn(col
, item
);
2010 // scroll the control by the given number of pixels (exception: in list view,
2011 // dx is interpreted as number of columns)
2012 bool wxListCtrl::ScrollList(int dx
, int dy
)
2015 return m_genericImpl
->ScrollList(dx
, dy
);
2019 m_dbImpl
->SetScrollPosition(dx
, dy
);
2025 bool wxListCtrl::SortItems(wxListCtrlCompare fn
, long data
)
2028 return m_genericImpl
->SortItems(fn
, data
);
2033 m_compareFuncData
= data
;
2034 SortDataBrowserContainer( m_dbImpl
->GetControlRef(), kDataBrowserNoItem
, true);
2036 // we need to do this after each call, else we get a crash from wxPython when
2037 // SortItems is called the second time.
2038 m_compareFunc
= NULL
;
2039 m_compareFuncData
= 0;
2045 void wxListCtrl::OnRenameTimer()
2047 wxCHECK_RET( HasCurrent(), wxT("unexpected rename timer") );
2049 EditLabel( m_current
);
2052 bool wxListCtrl::OnRenameAccept(long itemEdit
, const wxString
& value
)
2054 wxListEvent
le( wxEVT_COMMAND_LIST_END_LABEL_EDIT
, GetId() );
2055 le
.SetEventObject( this );
2056 le
.m_itemIndex
= itemEdit
;
2058 GetItem( le
.m_item
);
2059 le
.m_item
.m_text
= value
;
2060 return !GetEventHandler()->ProcessEvent( le
) ||
2064 void wxListCtrl::OnRenameCancelled(long itemEdit
)
2066 // let owner know that the edit was cancelled
2067 wxListEvent
le( wxEVT_COMMAND_LIST_END_LABEL_EDIT
, GetParent()->GetId() );
2069 le
.SetEditCanceled(true);
2071 le
.SetEventObject( this );
2072 le
.m_itemIndex
= itemEdit
;
2074 GetItem( le
.m_item
);
2075 GetEventHandler()->ProcessEvent( le
);
2078 // ----------------------------------------------------------------------------
2079 // virtual list controls
2080 // ----------------------------------------------------------------------------
2082 wxString
wxListCtrl::OnGetItemText(long WXUNUSED(item
), long WXUNUSED(col
)) const
2084 // this is a pure virtual function, in fact - which is not really pure
2085 // because the controls which are not virtual don't need to implement it
2086 wxFAIL_MSG( _T("wxListCtrl::OnGetItemText not supposed to be called") );
2088 return wxEmptyString
;
2091 int wxListCtrl::OnGetItemImage(long WXUNUSED(item
)) const
2093 wxCHECK_MSG(!GetImageList(wxIMAGE_LIST_SMALL
),
2095 wxT("List control has an image list, OnGetItemImage or OnGetItemColumnImage should be overridden."));
2099 int wxListCtrl::OnGetItemColumnImage(long item
, long column
) const
2102 return OnGetItemImage(item
);
2107 wxListItemAttr
*wxListCtrl::OnGetItemAttr(long WXUNUSED_UNLESS_DEBUG(item
)) const
2109 wxASSERT_MSG( item
>= 0 && item
< GetItemCount(),
2110 _T("invalid item index in OnGetItemAttr()") );
2112 // no attributes by default
2116 void wxListCtrl::SetItemCount(long count
)
2118 wxASSERT_MSG( IsVirtual(), _T("this is for virtual controls only") );
2122 m_genericImpl
->SetItemCount(count
);
2128 // we need to temporarily disable the new item creation notification
2129 // procedure to speed things up
2130 // FIXME: Even this doesn't seem to help much...
2132 // FIXME: Find a more efficient way to do this.
2133 m_dbImpl
->MacClear();
2135 DataBrowserCallbacks callbacks
;
2136 DataBrowserItemNotificationUPP itemUPP
;
2137 GetDataBrowserCallbacks(m_dbImpl
->GetControlRef(), &callbacks
);
2138 itemUPP
= callbacks
.u
.v1
.itemNotificationCallback
;
2139 callbacks
.u
.v1
.itemNotificationCallback
= 0;
2140 m_dbImpl
->SetCallbacks(&callbacks
);
2141 ::AddDataBrowserItems(m_dbImpl
->GetControlRef(), kDataBrowserNoItem
,
2142 count
, NULL
, kDataBrowserItemNoProperty
);
2143 callbacks
.u
.v1
.itemNotificationCallback
= itemUPP
;
2144 m_dbImpl
->SetCallbacks(&callbacks
);
2149 void wxListCtrl::RefreshItem(long item
)
2153 m_genericImpl
->RefreshItem(item
);
2158 GetItemRect(item
, rect
);
2162 void wxListCtrl::RefreshItems(long itemFrom
, long itemTo
)
2166 m_genericImpl
->RefreshItems(itemFrom
, itemTo
);
2170 wxRect rect1
, rect2
;
2171 GetItemRect(itemFrom
, rect1
);
2172 GetItemRect(itemTo
, rect2
);
2174 wxRect rect
= rect1
;
2175 rect
.height
= rect2
.GetBottom() - rect1
.GetTop();
2180 void wxListCtrl::SetDropTarget( wxDropTarget
*dropTarget
)
2182 #if wxUSE_DRAG_AND_DROP
2184 m_genericImpl
->SetDropTarget( dropTarget
);
2187 wxWindow::SetDropTarget( dropTarget
);
2191 wxDropTarget
*wxListCtrl::GetDropTarget() const
2193 #if wxUSE_DRAG_AND_DROP
2195 return m_genericImpl
->GetDropTarget();
2198 return wxWindow::GetDropTarget();
2203 #if wxABI_VERSION >= 20801
2204 void wxListCtrl::SetFocus()
2208 m_genericImpl
->SetFocus();
2212 wxWindow::SetFocus();
2216 // wxMac internal data structures
2218 wxMacListCtrlItem::~wxMacListCtrlItem()
2222 void wxMacListCtrlItem::Notification(wxMacDataItemBrowserControl
*owner
,
2223 DataBrowserItemNotification message
,
2224 DataBrowserItemDataRef itemData
) const
2227 wxMacDataBrowserListCtrlControl
*lb
= wxDynamicCast(owner
, wxMacDataBrowserListCtrlControl
);
2229 // we want to depend on as little as possible to make sure tear-down of controls is safe
2230 if ( message
== kDataBrowserItemRemoved
)
2232 if ( lb
!= NULL
&& lb
->GetClientDataType() == wxClientData_Object
)
2234 delete (wxClientData
*) (m_data
);
2240 else if ( message
== kDataBrowserItemAdded
)
2242 // we don't issue events on adding, the item is not really stored in the list yet, so we
2243 // avoid asserts by gettting out now
2247 wxListCtrl
*list
= wxDynamicCast( owner
->GetPeer() , wxListCtrl
);
2250 bool trigger
= false;
2252 wxListEvent
event( wxEVT_COMMAND_LIST_ITEM_SELECTED
, list
->GetId() );
2253 bool isSingle
= (list
->GetWindowStyle() & wxLC_SINGLE_SEL
) != 0;
2255 event
.SetEventObject( list
);
2256 event
.m_itemIndex
= owner
->GetLineFromItem( this ) ;
2257 if ( !list
->IsVirtual() )
2259 lb
->MacGetColumnInfo(event
.m_itemIndex
,0,event
.m_item
);
2264 case kDataBrowserItemDeselected
:
2265 event
.SetEventType(wxEVT_COMMAND_LIST_ITEM_DESELECTED
);
2267 trigger
= !lb
->IsSelectionSuppressed();
2270 case kDataBrowserItemSelected
:
2271 trigger
= !lb
->IsSelectionSuppressed();
2274 case kDataBrowserItemDoubleClicked
:
2275 event
.SetEventType( wxEVT_COMMAND_LIST_ITEM_ACTIVATED
);
2279 case kDataBrowserEditStarted
:
2280 // TODO : how to veto ?
2281 event
.SetEventType( wxEVT_COMMAND_LIST_BEGIN_LABEL_EDIT
) ;
2285 case kDataBrowserEditStopped
:
2286 // TODO probably trigger only upon the value store callback, because
2287 // here IIRC we cannot veto
2288 event
.SetEventType( wxEVT_COMMAND_LIST_END_LABEL_EDIT
) ;
2298 // direct notification is not always having the listbox GetSelection() having in synch with event
2299 wxPostEvent( list
->GetEventHandler(), event
);
2305 IMPLEMENT_DYNAMIC_CLASS(wxMacDataBrowserListCtrlControl
, wxMacDataItemBrowserControl
)
2307 wxMacDataBrowserListCtrlControl::wxMacDataBrowserListCtrlControl( wxWindow
*peer
, const wxPoint
& pos
, const wxSize
& size
, long style
)
2308 : wxMacDataItemBrowserControl( peer
, pos
, size
, style
)
2310 OSStatus err
= noErr
;
2311 m_clientDataItemsType
= wxClientData_None
;
2312 m_isVirtual
= false;
2314 if ( style
& wxLC_VIRTUAL
)
2317 DataBrowserSelectionFlags options
= kDataBrowserDragSelect
;
2318 if ( style
& wxLC_SINGLE_SEL
)
2320 options
|= kDataBrowserSelectOnlyOne
;
2324 options
|= kDataBrowserCmdTogglesSelection
;
2327 err
= SetSelectionFlags( options
);
2328 verify_noerr( err
);
2330 DataBrowserCustomCallbacks callbacks
;
2331 InitializeDataBrowserCustomCallbacks( &callbacks
, kDataBrowserLatestCustomCallbacks
);
2333 if ( gDataBrowserDrawItemUPP
== NULL
)
2334 gDataBrowserDrawItemUPP
= NewDataBrowserDrawItemUPP(DataBrowserDrawItemProc
);
2336 if ( gDataBrowserHitTestUPP
== NULL
)
2337 gDataBrowserHitTestUPP
= NewDataBrowserHitTestUPP(DataBrowserHitTestProc
);
2339 callbacks
.u
.v1
.drawItemCallback
= gDataBrowserDrawItemUPP
;
2340 callbacks
.u
.v1
.hitTestCallback
= gDataBrowserHitTestUPP
;
2342 SetDataBrowserCustomCallbacks( GetControlRef(), &callbacks
);
2344 if ( style
& wxLC_LIST
)
2346 InsertColumn(0, kDataBrowserIconAndTextType
, wxEmptyString
, -1, -1);
2347 verify_noerr( AutoSizeColumns() );
2350 if ( style
& wxLC_LIST
|| style
& wxLC_NO_HEADER
)
2351 verify_noerr( SetHeaderButtonHeight( 0 ) );
2354 SetSortProperty( kMinColumnId
- 1 );
2356 SetSortProperty( kMinColumnId
);
2357 if ( style
& wxLC_SORT_ASCENDING
)
2359 m_sortOrder
= SortOrder_Text_Ascending
;
2360 SetSortOrder( kDataBrowserOrderIncreasing
);
2362 else if ( style
& wxLC_SORT_DESCENDING
)
2364 m_sortOrder
= SortOrder_Text_Descending
;
2365 SetSortOrder( kDataBrowserOrderDecreasing
);
2369 m_sortOrder
= SortOrder_None
;
2372 if ( style
& wxLC_VRULES
)
2374 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4
2375 verify_noerr( DataBrowserChangeAttributes(m_controlRef
, kDataBrowserAttributeListViewDrawColumnDividers
, kDataBrowserAttributeNone
) );
2379 verify_noerr( SetHiliteStyle(kDataBrowserTableViewFillHilite
) );
2380 err
= SetHasScrollBars( (style
& wxHSCROLL
) != 0 , true );
2383 pascal Boolean
wxMacDataBrowserListCtrlControl::DataBrowserEditTextProc(
2385 DataBrowserItemID itemID
,
2386 DataBrowserPropertyID property
,
2387 CFStringRef theString
,
2388 Rect
*maxEditTextRect
,
2389 Boolean
*shrinkToFit
)
2391 Boolean result
= false;
2392 wxMacDataBrowserListCtrlControl
* ctl
= wxDynamicCast(wxMacControl::GetReferenceFromNativeControl( browser
), wxMacDataBrowserListCtrlControl
);
2395 result
= ctl
->ConfirmEditText(itemID
, property
, theString
, maxEditTextRect
, shrinkToFit
);
2396 theString
= CFSTR("Hello!");
2401 bool wxMacDataBrowserListCtrlControl::ConfirmEditText(
2402 DataBrowserItemID itemID
,
2403 DataBrowserPropertyID property
,
2404 CFStringRef theString
,
2405 Rect
*maxEditTextRect
,
2406 Boolean
*shrinkToFit
)
2411 pascal void wxMacDataBrowserListCtrlControl::DataBrowserDrawItemProc(
2413 DataBrowserItemID itemID
,
2414 DataBrowserPropertyID property
,
2415 DataBrowserItemState itemState
,
2416 const Rect
*itemRect
,
2418 Boolean colorDevice
)
2420 wxMacDataBrowserListCtrlControl
* ctl
= wxDynamicCast(wxMacControl::GetReferenceFromNativeControl( browser
), wxMacDataBrowserListCtrlControl
);
2423 ctl
->DrawItem(itemID
, property
, itemState
, itemRect
, gdDepth
, colorDevice
);
2427 // routines needed for DrawItem
2432 kTextBoxHeight
= 14,
2433 kIconTextSpacingV
= 2,
2435 kContentHeight
= kIconHeight
+ kTextBoxHeight
+ kIconTextSpacingV
2438 static void calculateCGDrawingBounds(CGRect inItemRect
, CGRect
*outIconRect
, CGRect
*outTextRect
, bool hasIcon
= false)
2441 float iconH
, iconW
= 0;
2442 float padding
= kItemPadding
;
2445 iconH
= kIconHeight
;
2447 padding
= padding
*2;
2450 textBottom
= inItemRect
.origin
.y
;
2452 *outIconRect
= CGRectMake(inItemRect
.origin
.x
+ kItemPadding
,
2453 textBottom
+ kIconTextSpacingV
, kIconWidth
,
2456 *outTextRect
= CGRectMake(inItemRect
.origin
.x
+ padding
+ iconW
,
2457 textBottom
+ kIconTextSpacingV
, inItemRect
.size
.width
- padding
- iconW
,
2458 inItemRect
.size
.height
- kIconTextSpacingV
);
2461 void wxMacDataBrowserListCtrlControl::DrawItem(
2462 DataBrowserItemID itemID
,
2463 DataBrowserPropertyID property
,
2464 DataBrowserItemState itemState
,
2465 const Rect
*itemRect
,
2467 Boolean colorDevice
)
2470 wxFont font
= wxNullFont
;
2472 short listColumn
= property
- kMinColumnId
;
2474 wxListCtrl
* list
= wxDynamicCast( GetPeer() , wxListCtrl
);
2475 wxMacListCtrlItem
* lcItem
;
2476 wxColour color
= *wxBLACK
;
2477 wxColour bgColor
= wxNullColour
;
2479 if (listColumn
>= 0)
2483 lcItem
= (wxMacListCtrlItem
*) itemID
;
2484 if (lcItem
->HasColumnInfo(listColumn
)){
2485 wxListItem
* item
= lcItem
->GetColumnInfo(listColumn
);
2487 // we always use the 0 column to get font and text/background colors.
2488 if (lcItem
->HasColumnInfo(0))
2490 wxListItem
* firstItem
= lcItem
->GetColumnInfo(0);
2491 color
= firstItem
->GetTextColour();
2492 bgColor
= firstItem
->GetBackgroundColour();
2493 font
= firstItem
->GetFont();
2496 if (item
->GetMask() & wxLIST_MASK_TEXT
)
2497 text
= item
->GetText();
2498 if (item
->GetMask() & wxLIST_MASK_IMAGE
)
2499 imgIndex
= item
->GetImage();
2505 text
= list
->OnGetItemText( (long)itemID
-1, listColumn
);
2506 imgIndex
= list
->OnGetItemColumnImage( (long)itemID
-1, listColumn
);
2507 wxListItemAttr
* attrs
= list
->OnGetItemAttr( (long)itemID
-1 );
2510 if (attrs
->HasBackgroundColour())
2511 bgColor
= attrs
->GetBackgroundColour();
2512 if (attrs
->HasTextColour())
2513 color
= attrs
->GetTextColour();
2514 if (attrs
->HasFont())
2515 font
= attrs
->GetFont();
2520 wxColour listBgColor
= list
->GetBackgroundColour();
2521 if (bgColor
== wxNullColour
)
2522 bgColor
= listBgColor
;
2524 wxFont listFont
= list
->GetFont();
2525 if (font
== wxNullFont
)
2528 wxMacCFStringHolder cfString
;
2529 cfString
.Assign( text
, wxLocale::GetSystemEncoding() );
2532 CGRect enclosingCGRect
, iconCGRect
, textCGRect
;
2534 ThemeDrawingState savedState
= NULL
;
2535 CGContextRef context
= (CGContextRef
)list
->MacGetDrawingContext();
2536 RGBColor labelColor
;
2538 labelColor
.green
= 0;
2539 labelColor
.blue
= 0;
2541 RGBColor backgroundColor
;
2542 backgroundColor
.red
= 255;
2543 backgroundColor
.green
= 255;
2544 backgroundColor
.blue
= 255;
2546 GetDataBrowserItemPartBounds(GetControlRef(), itemID
, property
, kDataBrowserPropertyEnclosingPart
,
2549 enclosingCGRect
= CGRectMake(enclosingRect
.left
,
2551 enclosingRect
.right
- enclosingRect
.left
,
2552 enclosingRect
.bottom
- enclosingRect
.top
);
2554 active
= IsControlActive(GetControlRef());
2556 // don't paint the background over the vertical rule line
2557 if ( list
->GetWindowStyleFlag() & wxLC_VRULES
)
2559 enclosingCGRect
.origin
.x
+= 1;
2560 enclosingCGRect
.size
.width
-= 1;
2562 if (itemState
== kDataBrowserItemIsSelected
)
2565 GetThemeDrawingState(&savedState
);
2567 GetThemeBrushAsColor(kThemeBrushAlternatePrimaryHighlightColor
, 32, true, &backgroundColor
);
2568 GetThemeTextColor(kThemeTextColorWhite
, gdDepth
, colorDevice
, &labelColor
);
2570 CGContextSaveGState(context
);
2572 CGContextSetRGBFillColor(context
, (float)backgroundColor
.red
/ (float)USHRT_MAX
,
2573 (float)backgroundColor
.green
/ (float)USHRT_MAX
,
2574 (float)backgroundColor
.blue
/ (float)USHRT_MAX
, 1.0);
2575 CGContextFillRect(context
, enclosingCGRect
);
2577 CGContextRestoreGState(context
);
2583 labelColor
= MAC_WXCOLORREF( color
.GetPixel() );
2584 else if (list
->GetTextColour().Ok())
2585 labelColor
= MAC_WXCOLORREF( list
->GetTextColour().GetPixel() );
2589 backgroundColor
= MAC_WXCOLORREF( bgColor
.GetPixel() );
2590 CGContextSaveGState(context
);
2592 CGContextSetRGBFillColor(context
, (float)backgroundColor
.red
/ (float)USHRT_MAX
,
2593 (float)backgroundColor
.green
/ (float)USHRT_MAX
,
2594 (float)backgroundColor
.blue
/ (float)USHRT_MAX
, 1.0);
2595 CGContextFillRect(context
, enclosingCGRect
);
2597 CGContextRestoreGState(context
);
2601 calculateCGDrawingBounds(enclosingCGRect
, &iconCGRect
, &textCGRect
, (imgIndex
!= -1) );
2605 wxImageList
* imageList
= list
->GetImageList(wxIMAGE_LIST_SMALL
);
2606 if (imageList
&& imageList
->GetImageCount() > 0){
2607 wxBitmap bmp
= imageList
->GetBitmap(imgIndex
);
2608 IconRef icon
= bmp
.GetBitmapData()->GetIconRef();
2610 CGContextSaveGState(context
);
2611 CGContextTranslateCTM(context
, 0,iconCGRect
.origin
.y
+ CGRectGetMaxY(iconCGRect
));
2612 CGContextScaleCTM(context
,1.0f
,-1.0f
);
2613 PlotIconRefInContext(context
, &iconCGRect
, kAlignNone
,
2614 active
? kTransformNone
: kTransformDisabled
, NULL
,
2615 kPlotIconRefNormalFlags
, icon
);
2617 CGContextRestoreGState(context
);
2621 HIThemeTextHorizontalFlush hFlush
= kHIThemeTextHorizontalFlushLeft
;
2622 UInt16 fontID
= kThemeViewsFont
;
2626 if (font
.GetFamily() != wxFONTFAMILY_DEFAULT
)
2627 fontID
= font
.MacGetThemeFontID();
2629 // FIXME: replace these with CG or ATSUI calls so we can remove this #ifndef.
2631 ::TextSize( (short)(font
.MacGetFontSize()) ) ;
2632 ::TextFace( font
.MacGetFontStyle() ) ;
2637 list
->GetColumn(listColumn
, item
);
2638 if (item
.GetMask() & wxLIST_MASK_FORMAT
)
2640 if (item
.GetAlign() == wxLIST_FORMAT_LEFT
)
2641 hFlush
= kHIThemeTextHorizontalFlushLeft
;
2642 else if (item
.GetAlign() == wxLIST_FORMAT_CENTER
)
2643 hFlush
= kHIThemeTextHorizontalFlushCenter
;
2644 else if (item
.GetAlign() == wxLIST_FORMAT_RIGHT
)
2646 hFlush
= kHIThemeTextHorizontalFlushRight
;
2647 textCGRect
.origin
.x
-= kItemPadding
; // give a little extra paddding
2651 HIThemeTextInfo info
;
2652 info
.version
= kHIThemeTextInfoVersionZero
;
2653 info
.state
= active
? kThemeStateActive
: kThemeStateInactive
;
2654 info
.fontID
= fontID
;
2655 info
.horizontalFlushness
= hFlush
;
2656 info
.verticalFlushness
= kHIThemeTextVerticalFlushCenter
;
2657 info
.options
= kHIThemeTextBoxOptionNone
;
2658 info
.truncationPosition
= kHIThemeTextTruncationEnd
;
2659 info
.truncationMaxLines
= 1;
2661 CGContextSaveGState(context
);
2662 CGContextSetRGBFillColor (context
, (float)labelColor
.red
/ (float)USHRT_MAX
,
2663 (float)labelColor
.green
/ (float)USHRT_MAX
,
2664 (float)labelColor
.blue
/ (float)USHRT_MAX
, 1.0);
2666 HIThemeDrawTextBox(cfString
, &textCGRect
, &info
, context
, kHIThemeOrientationNormal
);
2668 CGContextRestoreGState(context
);
2670 if (savedState
!= NULL
)
2671 SetThemeDrawingState(savedState
, true);
2674 OSStatus
wxMacDataBrowserListCtrlControl::GetSetItemData(DataBrowserItemID itemID
,
2675 DataBrowserPropertyID property
,
2676 DataBrowserItemDataRef itemData
,
2677 Boolean changeValue
)
2681 short listColumn
= property
- kMinColumnId
;
2683 OSStatus err
= errDataBrowserPropertyNotSupported
;
2684 wxListCtrl
* list
= wxDynamicCast( GetPeer() , wxListCtrl
);
2685 wxMacListCtrlItem
* lcItem
;
2687 if (listColumn
>= 0)
2691 lcItem
= (wxMacListCtrlItem
*) itemID
;
2692 if (lcItem
&& lcItem
->HasColumnInfo(listColumn
)){
2693 wxListItem
* item
= lcItem
->GetColumnInfo(listColumn
);
2694 if (item
->GetMask() & wxLIST_MASK_TEXT
)
2695 text
= item
->GetText();
2696 if (item
->GetMask() & wxLIST_MASK_IMAGE
)
2697 imgIndex
= item
->GetImage();
2702 text
= list
->OnGetItemText( (long)itemID
-1, listColumn
);
2703 imgIndex
= list
->OnGetItemColumnImage( (long)itemID
-1, listColumn
);
2711 case kDataBrowserItemIsEditableProperty
:
2712 if ( list
&& list
->HasFlag( wxLC_EDIT_LABELS
) )
2714 verify_noerr(SetDataBrowserItemDataBooleanValue( itemData
, true ));
2719 if ( property
>= kMinColumnId
)
2721 wxMacCFStringHolder cfStr
;
2724 cfStr
.Assign( text
, wxLocale::GetSystemEncoding() );
2725 err
= ::SetDataBrowserItemDataText( itemData
, cfStr
);
2731 if ( imgIndex
!= -1 )
2733 wxImageList
* imageList
= list
->GetImageList(wxIMAGE_LIST_SMALL
);
2734 if (imageList
&& imageList
->GetImageCount() > 0){
2735 wxBitmap bmp
= imageList
->GetBitmap(imgIndex
);
2736 IconRef icon
= bmp
.GetBitmapData()->GetIconRef();
2737 ::SetDataBrowserItemDataIcon(itemData
, icon
);
2751 if ( property
>= kMinColumnId
)
2753 short listColumn
= property
- kMinColumnId
;
2755 // TODO probably send the 'end edit' from here, as we
2756 // can then deal with the veto
2758 verify_noerr( GetDataBrowserItemDataText( itemData
, &sr
) ) ;
2759 wxMacCFStringHolder
cfStr(sr
) ;;
2761 list
->SetItem( (long)itemData
-1 , listColumn
, cfStr
.AsString() ) ;
2765 lcItem
->SetColumnTextValue( listColumn
, cfStr
.AsString() );
2775 void wxMacDataBrowserListCtrlControl::ItemNotification(DataBrowserItemID itemID
,
2776 DataBrowserItemNotification message
,
2777 DataBrowserItemDataRef itemData
)
2779 // we want to depend on as little as possible to make sure tear-down of controls is safe
2780 if ( message
== kDataBrowserItemRemoved
)
2782 // make sure MacDelete does the proper teardown.
2785 else if ( message
== kDataBrowserItemAdded
)
2787 // we don't issue events on adding, the item is not really stored in the list yet, so we
2788 // avoid asserts by getting out now
2792 wxListCtrl
*list
= wxDynamicCast( GetPeer() , wxListCtrl
);
2795 bool trigger
= false;
2797 wxListEvent
event( wxEVT_COMMAND_LIST_ITEM_SELECTED
, list
->GetId() );
2798 bool isSingle
= (list
->GetWindowStyle() & wxLC_SINGLE_SEL
) != 0;
2800 event
.SetEventObject( list
);
2801 if ( !list
->IsVirtual() )
2803 DataBrowserTableViewRowIndex result
= 0;
2804 verify_noerr( GetItemRow( itemID
, &result
) ) ;
2805 event
.m_itemIndex
= result
;
2807 if (event
.m_itemIndex
>= 0)
2808 MacGetColumnInfo(event
.m_itemIndex
,0,event
.m_item
);
2812 event
.m_itemIndex
= (long)itemID
-1;
2817 case kDataBrowserItemDeselected
:
2818 event
.SetEventType(wxEVT_COMMAND_LIST_ITEM_DESELECTED
);
2820 trigger
= !IsSelectionSuppressed();
2823 case kDataBrowserItemSelected
:
2824 trigger
= !IsSelectionSuppressed();
2828 case kDataBrowserItemDoubleClicked
:
2829 event
.SetEventType( wxEVT_COMMAND_LIST_ITEM_ACTIVATED
);
2833 case kDataBrowserEditStarted
:
2834 // TODO : how to veto ?
2835 event
.SetEventType( wxEVT_COMMAND_LIST_BEGIN_LABEL_EDIT
) ;
2839 case kDataBrowserEditStopped
:
2840 // TODO probably trigger only upon the value store callback, because
2841 // here IIRC we cannot veto
2842 event
.SetEventType( wxEVT_COMMAND_LIST_END_LABEL_EDIT
) ;
2852 // direct notification is not always having the listbox GetSelection() having in synch with event
2853 wxPostEvent( list
->GetEventHandler(), event
);
2858 Boolean
wxMacDataBrowserListCtrlControl::CompareItems(DataBrowserItemID itemOneID
,
2859 DataBrowserItemID itemTwoID
,
2860 DataBrowserPropertyID sortProperty
)
2863 bool retval
= false;
2865 wxString otherItemText
;
2867 long otherItemOrder
;
2869 int colId
= sortProperty
- kMinColumnId
;
2871 wxListCtrl
* list
= wxDynamicCast( GetPeer() , wxListCtrl
);
2873 DataBrowserSortOrder sort
;
2874 verify_noerr(GetSortOrder(&sort
));
2880 wxMacListCtrlItem
* item
= (wxMacListCtrlItem
*)itemOneID
;
2881 wxMacListCtrlItem
* otherItem
= (wxMacListCtrlItem
*)itemTwoID
;
2883 wxListCtrlCompare func
= list
->GetCompareFunc();
2888 if (item
&& item
->HasColumnInfo(0))
2889 item1
= item
->GetColumnInfo(0)->GetData();
2890 if (otherItem
&& otherItem
->HasColumnInfo(0))
2891 item2
= otherItem
->GetColumnInfo(0)->GetData();
2893 if (item1
> -1 && item2
> -1)
2895 int result
= func(item1
, item2
, list
->GetCompareFuncData());
2896 if (sort
== kDataBrowserOrderIncreasing
)
2903 if (item
->HasColumnInfo(colId
))
2905 wxListItem
* colItem
= item
->GetColumnInfo(colId
);
2906 itemText
= colItem
->GetText();
2907 itemOrder
= colItem
->GetId();
2909 if (otherItem
->HasColumnInfo(colId
))
2911 wxListItem
* colItem
= otherItem
->GetColumnInfo(colId
);
2912 otherItemText
= colItem
->GetText();
2913 otherItemOrder
= colItem
->GetId();
2919 long itemNum
= (long)itemOneID
;
2920 long otherItemNum
= (long)itemTwoID
;
2921 itemText
= list
->OnGetItemText( itemNum
-1, colId
);
2922 otherItemText
= list
->OnGetItemText( otherItemNum
-1, colId
);
2924 // virtual listctrls don't support sorting
2925 return itemNum
< otherItemNum
;
2930 if ( sort
== kDataBrowserOrderIncreasing
&& !m_sortOrder
== SortOrder_None
)
2932 retval
= itemText
.CmpNoCase( otherItemText
) > 0;
2934 else if ( sort
== kDataBrowserOrderDecreasing
&& !m_sortOrder
== SortOrder_None
)
2936 retval
= itemText
.CmpNoCase( otherItemText
) < 0;
2940 retval
= itemOrder
< otherItemOrder
;
2944 // fallback for undefined cases
2945 retval
= itemOneID
< itemTwoID
;
2951 wxMacDataBrowserListCtrlControl::~wxMacDataBrowserListCtrlControl()
2955 void wxMacDataBrowserListCtrlControl::MacSetColumnInfo( unsigned int row
, unsigned int column
, wxListItem
* item
)
2957 wxMacDataItem
* dataItem
= GetItemFromLine(row
);
2958 wxASSERT_MSG( dataItem
, _T("could not obtain wxMacDataItem for row in MacSetColumnInfo. Is row a valid wxListCtrl row?") );
2961 wxMacListCtrlItem
* listItem
= wx_static_cast(wxMacListCtrlItem
*,dataItem
);
2962 bool hasInfo
= listItem
->HasColumnInfo( column
);
2963 listItem
->SetColumnInfo( column
, item
);
2964 UpdateState(dataItem
, item
);
2966 wxListCtrl
* list
= wxDynamicCast( GetPeer() , wxListCtrl
);
2968 // NB: When this call was made before a control was completely shown, it would
2969 // update the item prematurely (i.e. no text would be listed) and, on show,
2970 // only the sorted column would be refreshed, meaning only first column text labels
2971 // would be shown. Making sure not to update items until the control is visible
2972 // seems to fix this issue.
2973 if (hasInfo
&& list
->IsShown())
2974 UpdateItem( wxMacDataBrowserRootContainer
, listItem
, kMinColumnId
+ column
);
2978 // apply changes that need to happen immediately, rather than when the
2979 // databrowser control fires a callback.
2980 void wxMacDataBrowserListCtrlControl::UpdateState(wxMacDataItem
* dataItem
, wxListItem
* listItem
)
2982 bool isSelected
= IsItemSelected( dataItem
);
2983 bool isSelectedState
= (listItem
->GetState() == wxLIST_STATE_SELECTED
);
2985 // toggle the selection state if wxListInfo state and actual state don't match.
2986 if ( isSelected
!= isSelectedState
)
2988 DataBrowserSetOption options
= kDataBrowserItemsAdd
;
2989 if (!isSelectedState
)
2990 options
= kDataBrowserItemsRemove
;
2991 SetSelectedItem(dataItem
, options
);
2993 // TODO: Set column width if item width > than current column width
2996 void wxMacDataBrowserListCtrlControl::MacGetColumnInfo( unsigned int row
, unsigned int column
, wxListItem
& item
)
2998 wxMacDataItem
* dataItem
= GetItemFromLine(row
);
2999 wxASSERT_MSG( dataItem
, _T("could not obtain wxMacDataItem in MacGetColumnInfo. Is row a valid wxListCtrl row?") );
3000 // CS should this guard against dataItem = 0 ? , as item is not a pointer if (item) is not appropriate
3003 wxMacListCtrlItem
* listItem
=wx_static_cast(wxMacListCtrlItem
*,dataItem
);
3005 if (!listItem
->HasColumnInfo( column
))
3008 wxListItem
* oldItem
= listItem
->GetColumnInfo( column
);
3012 long mask
= item
.GetMask();
3014 // by default, get everything for backwards compatibility
3017 if ( mask
& wxLIST_MASK_TEXT
)
3018 item
.SetText(oldItem
->GetText());
3019 if ( mask
& wxLIST_MASK_IMAGE
)
3020 item
.SetImage(oldItem
->GetImage());
3021 if ( mask
& wxLIST_MASK_DATA
)
3022 item
.SetData(oldItem
->GetData());
3023 if ( mask
& wxLIST_MASK_STATE
)
3024 item
.SetState(oldItem
->GetState());
3025 if ( mask
& wxLIST_MASK_WIDTH
)
3026 item
.SetWidth(oldItem
->GetWidth());
3027 if ( mask
& wxLIST_MASK_FORMAT
)
3028 item
.SetAlign(oldItem
->GetAlign());
3030 item
.SetTextColour(oldItem
->GetTextColour());
3031 item
.SetBackgroundColour(oldItem
->GetBackgroundColour());
3032 item
.SetFont(oldItem
->GetFont());
3037 void wxMacDataBrowserListCtrlControl::MacInsertItem( unsigned int n
, wxListItem
* item
)
3039 wxMacDataItemBrowserControl::MacInsert(n
, item
->GetText());
3040 MacSetColumnInfo(n
, 0, item
);
3043 wxMacDataItem
* wxMacDataBrowserListCtrlControl::CreateItem()
3045 return new wxMacListCtrlItem();
3048 wxMacListCtrlItem::wxMacListCtrlItem()
3050 m_rowItems
= wxListItemList();
3053 int wxMacListCtrlItem::GetColumnImageValue( unsigned int column
)
3055 if ( HasColumnInfo(column
) )
3056 return GetColumnInfo(column
)->GetImage();
3061 void wxMacListCtrlItem::SetColumnImageValue( unsigned int column
, int imageIndex
)
3063 if ( HasColumnInfo(column
) )
3064 GetColumnInfo(column
)->SetImage(imageIndex
);
3067 wxString
wxMacListCtrlItem::GetColumnTextValue( unsigned int column
)
3072 if ( HasColumnInfo(column
) )
3073 return GetColumnInfo(column
)->GetText();
3075 return wxEmptyString
;
3078 void wxMacListCtrlItem::SetColumnTextValue( unsigned int column
, const wxString
& text
)
3080 if ( HasColumnInfo(column
) )
3081 GetColumnInfo(column
)->SetText(text
);
3083 // for compatibility with superclass APIs
3088 wxListItem
* wxMacListCtrlItem::GetColumnInfo( unsigned int column
)
3090 wxASSERT_MSG( HasColumnInfo(column
), _T("invalid column index in wxMacListCtrlItem") );
3091 return m_rowItems
[column
];
3094 bool wxMacListCtrlItem::HasColumnInfo( unsigned int column
)
3096 return !(m_rowItems
.find( column
) == m_rowItems
.end());
3099 void wxMacListCtrlItem::SetColumnInfo( unsigned int column
, wxListItem
* item
)
3102 if ( !HasColumnInfo(column
) )
3104 wxListItem
* listItem
= new wxListItem(*item
);
3105 m_rowItems
[column
] = listItem
;
3109 wxListItem
* listItem
= GetColumnInfo( column
);
3110 long mask
= item
->GetMask();
3111 if (mask
& wxLIST_MASK_TEXT
)
3112 listItem
->SetText(item
->GetText());
3113 if (mask
& wxLIST_MASK_DATA
)
3114 listItem
->SetData(item
->GetData());
3115 if (mask
& wxLIST_MASK_IMAGE
)
3116 listItem
->SetImage(item
->GetImage());
3117 if (mask
& wxLIST_MASK_STATE
)
3118 listItem
->SetState(item
->GetState());
3119 if (mask
& wxLIST_MASK_FORMAT
)
3120 listItem
->SetAlign(item
->GetAlign());
3121 if (mask
& wxLIST_MASK_WIDTH
)
3122 listItem
->SetWidth(item
->GetWidth());
3124 if ( item
->HasAttributes() )
3126 if ( listItem
->HasAttributes() )
3127 listItem
->GetAttributes()->AssignFrom(*item
->GetAttributes());
3130 listItem
->SetTextColour(item
->GetTextColour());
3131 listItem
->SetBackgroundColour(item
->GetBackgroundColour());
3132 listItem
->SetFont(item
->GetFont());
3138 #endif // wxUSE_LISTCTRL