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
)
510 EVT_RIGHT_DOWN(wxListCtrl::OnRightDown
)
513 // ============================================================================
515 // ============================================================================
517 wxMacListControl
* wxListCtrl::GetPeer() const
519 wxMacDataBrowserListCtrlControl
*lb
= wxDynamicCast(m_peer
,wxMacDataBrowserListCtrlControl
);
520 return lb
? wx_static_cast(wxMacListControl
*,lb
) : 0 ;
523 // ----------------------------------------------------------------------------
524 // wxListCtrl construction
525 // ----------------------------------------------------------------------------
527 void wxListCtrl::Init()
529 m_imageListNormal
= NULL
;
530 m_imageListSmall
= NULL
;
531 m_imageListState
= NULL
;
533 // keep track of if we created our own image lists, or if they were assigned
535 m_ownsImageListNormal
= m_ownsImageListSmall
= m_ownsImageListState
= false;
539 m_genericImpl
= NULL
;
541 m_compareFunc
= NULL
;
542 m_compareFuncData
= 0;
543 m_colsInfo
= wxColumnList();
544 m_textColor
= wxNullColour
;
545 m_bgColor
= wxNullColour
;
546 m_textctrlWrapper
= NULL
;
548 m_renameTimer
= new wxListCtrlRenameTimer( this );
551 class wxGenericListCtrlHook
: public wxGenericListCtrl
554 wxGenericListCtrlHook(wxListCtrl
* parent
,
559 const wxValidator
& validator
,
560 const wxString
& name
)
561 : wxGenericListCtrl(parent
, id
, pos
, size
, style
, validator
, name
),
562 m_nativeListCtrl(parent
)
567 virtual wxListItemAttr
* OnGetItemAttr(long item
) const
569 return m_nativeListCtrl
->OnGetItemAttr(item
);
572 virtual int OnGetItemImage(long item
) const
574 return m_nativeListCtrl
->OnGetItemImage(item
);
577 virtual int OnGetItemColumnImage(long item
, long column
) const
579 return m_nativeListCtrl
->OnGetItemColumnImage(item
, column
);
582 virtual wxString
OnGetItemText(long item
, long column
) const
584 return m_nativeListCtrl
->OnGetItemText(item
, column
);
587 wxListCtrl
* m_nativeListCtrl
;
591 void wxListCtrl::OnLeftDown(wxMouseEvent
& event
)
593 if ( m_textctrlWrapper
)
596 m_textctrlWrapper
->AcceptChangesAndFinish();
600 long current
= HitTest(event
.GetPosition(), hitResult
);
601 if ((current
== m_current
) &&
602 (hitResult
== wxLIST_HITTEST_ONITEM
) &&
603 HasFlag(wxLC_EDIT_LABELS
) )
605 m_renameTimer
->Start( 100, true );
614 void wxListCtrl::OnRightDown(wxMouseEvent
& event
)
616 wxListEvent
le( wxEVT_COMMAND_LIST_ITEM_RIGHT_CLICK
, GetId() );
617 le
.SetEventObject(this);
618 le
.m_pointDrag
= event
.GetPosition();
622 long item
= HitTest(event
.GetPosition(), flags
);
623 if (flags
& wxLIST_HITTEST_ONITEM
)
625 le
.m_itemIndex
= item
;
629 le
.m_item
.m_itemId
= item
;
634 GetEventHandler()->ProcessEvent(le
);
638 void wxListCtrl::OnDblClick(wxMouseEvent
& event
)
644 bool wxListCtrl::Create(wxWindow
*parent
,
649 const wxValidator
& validator
,
650 const wxString
& name
)
653 // for now, we'll always use the generic list control for ICON and LIST views,
654 // because they dynamically change the number of columns on resize.
655 // Also, allow the user to set it to use the list ctrl as well.
656 if ( (wxSystemOptions::HasOption( wxMAC_ALWAYS_USE_GENERIC_LISTCTRL
)
657 && (wxSystemOptions::GetOptionInt( wxMAC_ALWAYS_USE_GENERIC_LISTCTRL
) == 1)) ||
658 (style
& wxLC_ICON
) || (style
& wxLC_SMALL_ICON
) || (style
& wxLC_LIST
) )
660 m_macIsUserPane
= true;
662 long paneStyle
= style
;
663 paneStyle
&= ~wxSIMPLE_BORDER
;
664 paneStyle
&= ~wxDOUBLE_BORDER
;
665 paneStyle
&= ~wxSUNKEN_BORDER
;
666 paneStyle
&= ~wxRAISED_BORDER
;
667 paneStyle
&= ~wxSTATIC_BORDER
;
668 if ( !wxWindow::Create(parent
, id
, pos
, size
, paneStyle
| wxNO_BORDER
, name
) )
671 // since the generic control is a child, make sure we position it at 0, 0
672 m_genericImpl
= new wxGenericListCtrlHook(this, id
, wxPoint(0, 0), size
, style
, validator
, name
);
673 m_genericImpl
->PushEventHandler( new wxMacListCtrlEventDelegate( this, GetId() ) );
679 m_macIsUserPane
= false;
681 if ( !wxWindow::Create(parent
, id
, pos
, size
, style
, name
) )
683 m_dbImpl
= new wxMacDataBrowserListCtrlControl( this, pos
, size
, style
);
686 MacPostControlCreate( pos
, size
);
688 InstallControlEventHandler( m_peer
->GetControlRef() , GetwxMacListCtrlEventHandlerUPP(),
689 GetEventTypeCount(eventList
), eventList
, this,
690 (EventHandlerRef
*)&m_macListCtrlEventHandler
);
696 wxListCtrl::~wxListCtrl()
700 m_genericImpl
->PopEventHandler(/* deleteHandler = */ true);
703 if (m_ownsImageListNormal
)
704 delete m_imageListNormal
;
705 if (m_ownsImageListSmall
)
706 delete m_imageListSmall
;
707 if (m_ownsImageListState
)
708 delete m_imageListState
;
710 delete m_renameTimer
;
713 // ----------------------------------------------------------------------------
714 // set/get/change style
715 // ----------------------------------------------------------------------------
717 // Add or remove a single window style
718 void wxListCtrl::SetSingleStyle(long style
, bool add
)
720 long flag
= GetWindowStyleFlag();
722 // Get rid of conflicting styles
725 if ( style
& wxLC_MASK_TYPE
)
726 flag
= flag
& ~wxLC_MASK_TYPE
;
727 if ( style
& wxLC_MASK_ALIGN
)
728 flag
= flag
& ~wxLC_MASK_ALIGN
;
729 if ( style
& wxLC_MASK_SORT
)
730 flag
= flag
& ~wxLC_MASK_SORT
;
738 SetWindowStyleFlag(flag
);
741 // Set the whole window style
742 void wxListCtrl::SetWindowStyleFlag(long flag
)
744 if ( flag
!= m_windowStyle
)
746 m_windowStyle
= flag
;
750 m_genericImpl
->SetWindowStyleFlag(flag
);
757 void wxListCtrl::DoSetSize( int x
, int y
, int width
, int height
, int sizeFlags
)
759 wxControl::DoSetSize(x
, y
, width
, height
, sizeFlags
);
762 m_genericImpl
->SetSize(0, 0, width
, height
, sizeFlags
);
764 // determine if we need a horizontal scrollbar, and add it if so
768 for (int column
= 0; column
< GetColumnCount(); column
++)
770 totalWidth
+= m_dbImpl
->GetColumnWidth( column
);
773 Boolean vertScrollBar
;
774 GetDataBrowserHasScrollBars( m_dbImpl
->GetControlRef(), NULL
, &vertScrollBar
);
775 if (totalWidth
> width
)
776 SetDataBrowserHasScrollBars( m_dbImpl
->GetControlRef(), true, vertScrollBar
);
778 SetDataBrowserHasScrollBars( m_dbImpl
->GetControlRef(), false, vertScrollBar
);
782 wxSize
wxListCtrl::DoGetBestSize() const
784 return wxWindow::DoGetBestSize();
787 bool wxListCtrl::SetFont(const wxFont
& font
)
790 rv
= wxControl::SetFont(font
);
792 rv
= m_genericImpl
->SetFont(font
);
796 bool wxListCtrl::SetForegroundColour(const wxColour
& colour
)
800 rv
= m_genericImpl
->SetForegroundColour(colour
);
802 SetTextColour(colour
);
806 bool wxListCtrl::SetBackgroundColour(const wxColour
& colour
)
810 rv
= m_genericImpl
->SetBackgroundColour(colour
);
816 wxColour
wxListCtrl::GetBackgroundColour()
819 return m_genericImpl
->GetBackgroundColour();
826 // ----------------------------------------------------------------------------
828 // ----------------------------------------------------------------------------
830 // Gets information about this column
831 bool wxListCtrl::GetColumn(int col
, wxListItem
& item
) const
834 return m_genericImpl
->GetColumn(col
, item
);
840 wxColumnList::compatibility_iterator node
= m_colsInfo
.Item( col
);
841 wxASSERT_MSG( node
, _T("invalid column index in wxMacListCtrlItem") );
842 wxListItem
* column
= node
->GetData();
844 long mask
= column
->GetMask();
845 if (mask
& wxLIST_MASK_TEXT
)
846 item
.SetText(column
->GetText());
847 if (mask
& wxLIST_MASK_DATA
)
848 item
.SetData(column
->GetData());
849 if (mask
& wxLIST_MASK_IMAGE
)
850 item
.SetImage(column
->GetImage());
851 if (mask
& wxLIST_MASK_STATE
)
852 item
.SetState(column
->GetState());
853 if (mask
& wxLIST_MASK_FORMAT
)
854 item
.SetAlign(column
->GetAlign());
855 if (mask
& wxLIST_MASK_WIDTH
)
856 item
.SetWidth(column
->GetWidth());
862 // Sets information about this column
863 bool wxListCtrl::SetColumn(int col
, wxListItem
& item
)
866 return m_genericImpl
->SetColumn(col
, item
);
870 long mask
= item
.GetMask();
871 if ( col
>= (int)m_colsInfo
.GetCount() )
873 wxListItem
* listItem
= new wxListItem(item
);
874 m_colsInfo
.Append( listItem
);
879 GetColumn( col
, listItem
);
881 if (mask
& wxLIST_MASK_TEXT
)
882 listItem
.SetText(item
.GetText());
883 if (mask
& wxLIST_MASK_DATA
)
884 listItem
.SetData(item
.GetData());
885 if (mask
& wxLIST_MASK_IMAGE
)
886 listItem
.SetImage(item
.GetImage());
887 if (mask
& wxLIST_MASK_STATE
)
888 listItem
.SetState(item
.GetState());
889 if (mask
& wxLIST_MASK_FORMAT
)
890 listItem
.SetAlign(item
.GetAlign());
891 if (mask
& wxLIST_MASK_WIDTH
)
892 listItem
.SetWidth(item
.GetWidth());
895 // change the appearance in the databrowser.
896 DataBrowserListViewHeaderDesc columnDesc
;
897 columnDesc
.version
=kDataBrowserListViewLatestHeaderDesc
;
898 verify_noerr( m_dbImpl
->GetHeaderDesc( kMinColumnId
+ col
, &columnDesc
) );
901 if (item.GetMask() & wxLIST_MASK_TEXT)
905 enc = m_font.GetEncoding();
907 enc = wxLocale::GetSystemEncoding();
908 wxMacCFStringHolder cfTitle;
909 cfTitle.Assign( item.GetText() , enc );
910 if(columnDesc.titleString)
911 CFRelease(columnDesc.titleString);
912 columnDesc.titleString = cfTitle;
916 if (item
.GetMask() & wxLIST_MASK_IMAGE
&& item
.GetImage() != -1 )
918 columnDesc
.btnContentInfo
.contentType
= kControlContentIconRef
;
919 wxImageList
* imageList
= GetImageList(wxIMAGE_LIST_SMALL
);
920 if (imageList
&& imageList
->GetImageCount() > 0 )
922 wxBitmap bmp
= imageList
->GetBitmap( item
.GetImage() );
923 IconRef icon
= bmp
.GetBitmapData()->GetIconRef();
924 columnDesc
.btnContentInfo
.u
.iconRef
= icon
;
928 verify_noerr( m_dbImpl
->SetHeaderDesc( kMinColumnId
+ col
, &columnDesc
) );
934 int wxListCtrl::GetColumnCount() const
937 return m_genericImpl
->GetColumnCount();
942 m_dbImpl
->GetColumnCount(&count
);
949 // Gets the column width
950 int wxListCtrl::GetColumnWidth(int col
) const
953 return m_genericImpl
->GetColumnWidth(col
);
957 return m_dbImpl
->GetColumnWidth(col
);
963 // Sets the column width
964 bool wxListCtrl::SetColumnWidth(int col
, int width
)
967 return m_genericImpl
->SetColumnWidth(col
, width
);
972 if (width
== wxLIST_AUTOSIZE
|| width
== wxLIST_AUTOSIZE_USEHEADER
)
977 for (int column
= 0; column
< GetColumnCount(); column
++)
980 GetColumn(col
, colInfo
);
982 colInfo
.SetWidth(width
);
983 SetColumn(col
, colInfo
);
985 m_dbImpl
->SetColumnWidth(col
, mywidth
);
991 GetColumn(col
, colInfo
);
993 colInfo
.SetWidth(width
);
994 SetColumn(col
, colInfo
);
995 m_dbImpl
->SetColumnWidth(col
, mywidth
);
1003 // Gets the number of items that can fit vertically in the
1004 // visible area of the list control (list or report view)
1005 // or the total number of items in the list control (icon
1006 // or small icon view)
1007 int wxListCtrl::GetCountPerPage() const
1010 return m_genericImpl
->GetCountPerPage();
1019 // Gets the edit control for editing labels.
1020 wxTextCtrl
* wxListCtrl::GetEditControl() const
1023 return m_genericImpl
->GetEditControl();
1028 // Gets information about the item
1029 bool wxListCtrl::GetItem(wxListItem
& info
) const
1032 return m_genericImpl
->GetItem(info
);
1037 m_dbImpl
->MacGetColumnInfo(info
.m_itemId
, info
.m_col
, info
);
1040 info
.SetText( OnGetItemText(info
.m_itemId
, info
.m_col
) );
1041 info
.SetImage( OnGetItemColumnImage(info
.m_itemId
, info
.m_col
) );
1042 if (info
.GetMask() & wxLIST_MASK_STATE
)
1044 if (IsDataBrowserItemSelected( m_dbImpl
->GetControlRef(), info
.m_itemId
+1 ))
1045 info
.SetState(info
.GetState() | wxLIST_STATE_SELECTED
);
1048 wxListItemAttr
* attrs
= OnGetItemAttr( info
.m_itemId
);
1051 info
.SetFont( attrs
->GetFont() );
1052 info
.SetBackgroundColour( attrs
->GetBackgroundColour() );
1053 info
.SetTextColour( attrs
->GetTextColour() );
1057 bool success
= true;
1061 // Sets information about the item
1062 bool wxListCtrl::SetItem(wxListItem
& info
)
1065 return m_genericImpl
->SetItem(info
);
1068 m_dbImpl
->MacSetColumnInfo( info
.m_itemId
, info
.m_col
, &info
);
1073 long wxListCtrl::SetItem(long index
, int col
, const wxString
& label
, int imageId
)
1076 return m_genericImpl
->SetItem(index
, col
, label
, imageId
);
1079 info
.m_text
= label
;
1080 info
.m_mask
= wxLIST_MASK_TEXT
;
1081 info
.m_itemId
= index
;
1085 info
.m_image
= imageId
;
1086 info
.m_mask
|= wxLIST_MASK_IMAGE
;
1088 return SetItem(info
);
1092 // Gets the item state
1093 int wxListCtrl::GetItemState(long item
, long stateMask
) const
1096 return m_genericImpl
->GetItemState(item
, stateMask
);
1100 if ( HasFlag(wxLC_VIRTUAL
) )
1102 if (stateMask
== wxLIST_STATE_SELECTED
)
1104 if (IsDataBrowserItemSelected( m_dbImpl
->GetControlRef(), item
+1 ))
1105 return wxLIST_STATE_SELECTED
;
1114 info
.m_mask
= wxLIST_MASK_STATE
;
1115 info
.m_stateMask
= stateMask
;
1116 info
.m_itemId
= item
;
1121 return info
.m_state
;
1128 // Sets the item state
1129 bool wxListCtrl::SetItemState(long item
, long state
, long stateMask
)
1132 return m_genericImpl
->SetItemState(item
, state
, stateMask
);
1136 DataBrowserSetOption option
= kDataBrowserItemsAdd
;
1137 if ( stateMask
== wxLIST_STATE_SELECTED
&& state
== 0 )
1138 option
= kDataBrowserItemsRemove
;
1142 if ( HasFlag(wxLC_VIRTUAL
) )
1144 wxMacDataItemBrowserSelectionSuppressor
suppressor(m_dbImpl
);
1145 m_dbImpl
->SetSelectedAllItems(option
);
1149 for(int i
= 0; i
< GetItemCount();i
++)
1153 info
.m_mask
= wxLIST_MASK_STATE
;
1154 info
.m_stateMask
= stateMask
;
1155 info
.m_state
= state
;
1162 if ( HasFlag(wxLC_VIRTUAL
) )
1164 long itemID
= item
+1;
1165 SetDataBrowserSelectedItems(m_dbImpl
->GetControlRef(), 1, (DataBrowserItemID
*)&itemID
, option
);
1170 info
.m_itemId
= item
;
1171 info
.m_mask
= wxLIST_MASK_STATE
;
1172 info
.m_stateMask
= stateMask
;
1173 info
.m_state
= state
;
1174 return SetItem(info
);
1181 // Sets the item image
1182 bool wxListCtrl::SetItemImage(long item
, int image
, int WXUNUSED(selImage
))
1184 return SetItemColumnImage(item
, 0, image
);
1187 // Sets the item image
1188 bool wxListCtrl::SetItemColumnImage(long item
, long column
, int image
)
1191 return m_genericImpl
->SetItemColumnImage(item
, column
, image
);
1195 info
.m_mask
= wxLIST_MASK_IMAGE
;
1196 info
.m_image
= image
;
1197 info
.m_itemId
= item
;
1198 info
.m_col
= column
;
1200 return SetItem(info
);
1203 // Gets the item text
1204 wxString
wxListCtrl::GetItemText(long item
) const
1207 return m_genericImpl
->GetItemText(item
);
1211 info
.m_mask
= wxLIST_MASK_TEXT
;
1212 info
.m_itemId
= item
;
1215 return wxEmptyString
;
1219 // Sets the item text
1220 void wxListCtrl::SetItemText(long item
, const wxString
& str
)
1223 return m_genericImpl
->SetItemText(item
, str
);
1227 info
.m_mask
= wxLIST_MASK_TEXT
;
1228 info
.m_itemId
= item
;
1234 // Gets the item data
1235 long wxListCtrl::GetItemData(long item
) const
1238 return m_genericImpl
->GetItemData(item
);
1242 info
.m_mask
= wxLIST_MASK_DATA
;
1243 info
.m_itemId
= item
;
1250 // Sets the item data
1251 bool wxListCtrl::SetItemData(long item
, long data
)
1254 return m_genericImpl
->SetItemData(item
, data
);
1258 info
.m_mask
= wxLIST_MASK_DATA
;
1259 info
.m_itemId
= item
;
1262 return SetItem(info
);
1265 wxRect
wxListCtrl::GetViewRect() const
1267 wxASSERT_MSG( !HasFlag(wxLC_REPORT
| wxLC_LIST
),
1268 _T("wxListCtrl::GetViewRect() only works in icon mode") );
1271 return m_genericImpl
->GetViewRect();
1277 // Gets the item rectangle
1278 bool wxListCtrl::GetItemRect(long item
, wxRect
& rect
, int code
) const
1281 return m_genericImpl
->GetItemRect(item
, rect
, code
);
1286 DataBrowserItemID id
;
1287 DataBrowserPropertyID col
= kMinColumnId
;
1289 DataBrowserPropertyPart part
= kDataBrowserPropertyEnclosingPart
;
1290 if ( code
== wxLIST_RECT_LABEL
)
1291 part
= kDataBrowserPropertyTextPart
;
1292 else if ( code
== wxLIST_RECT_ICON
)
1293 part
= kDataBrowserPropertyIconPart
;
1295 if ( !(GetWindowStyleFlag() & wxLC_VIRTUAL
) )
1297 wxMacDataItem
* thisItem
= m_dbImpl
->GetItemFromLine(item
);
1298 id
= (DataBrowserItemID
) thisItem
;
1303 GetDataBrowserItemPartBounds( m_dbImpl
->GetControlRef(), id
, col
, part
, &bounds
);
1305 rect
.x
= bounds
.left
;
1306 rect
.y
= bounds
.top
;
1307 rect
.width
= bounds
.right
- bounds
.left
; //GetClientSize().x; // we need the width of the whole row, not just the item.
1308 rect
.height
= bounds
.bottom
- bounds
.top
;
1309 //fprintf("id = %d, bounds = %d, %d, %d, %d\n", id, rect.x, rect.y, rect.width, rect.height);
1314 // Gets the item position
1315 bool wxListCtrl::GetItemPosition(long item
, wxPoint
& pos
) const
1318 return m_genericImpl
->GetItemPosition(item
, pos
);
1320 bool success
= false;
1325 GetItemRect(item
, itemRect
);
1326 pos
= itemRect
.GetPosition();
1333 // Sets the item position.
1334 bool wxListCtrl::SetItemPosition(long item
, const wxPoint
& pos
)
1337 return m_genericImpl
->SetItemPosition(item
, pos
);
1342 // Gets the number of items in the list control
1343 int wxListCtrl::GetItemCount() const
1346 return m_genericImpl
->GetItemCount();
1349 return m_dbImpl
->MacGetCount();
1354 void wxListCtrl::SetItemSpacing( int spacing
, bool isSmall
)
1357 m_genericImpl
->SetItemSpacing(spacing
, isSmall
);
1360 wxSize
wxListCtrl::GetItemSpacing() const
1363 return m_genericImpl
->GetItemSpacing();
1365 return wxSize(0, 0);
1368 void wxListCtrl::SetItemTextColour( long item
, const wxColour
&col
)
1372 m_genericImpl
->SetItemTextColour(item
, col
);
1377 info
.m_itemId
= item
;
1378 info
.SetTextColour( col
);
1382 wxColour
wxListCtrl::GetItemTextColour( long item
) const
1385 return m_genericImpl
->GetItemTextColour(item
);
1391 return info
.GetTextColour();
1393 return wxNullColour
;
1396 void wxListCtrl::SetItemBackgroundColour( long item
, const wxColour
&col
)
1400 m_genericImpl
->SetItemBackgroundColour(item
, col
);
1405 info
.m_itemId
= item
;
1406 info
.SetBackgroundColour( col
);
1410 wxColour
wxListCtrl::GetItemBackgroundColour( long item
) const
1413 return m_genericImpl
->GetItemBackgroundColour(item
);
1419 return info
.GetBackgroundColour();
1421 return wxNullColour
;
1424 void wxListCtrl::SetItemFont( long item
, const wxFont
&f
)
1428 m_genericImpl
->SetItemFont(item
, f
);
1433 info
.m_itemId
= item
;
1438 wxFont
wxListCtrl::GetItemFont( long item
) const
1441 return m_genericImpl
->GetItemFont(item
);
1447 return info
.GetFont();
1453 // Gets the number of selected items in the list control
1454 int wxListCtrl::GetSelectedItemCount() const
1457 return m_genericImpl
->GetSelectedItemCount();
1460 return m_dbImpl
->GetSelectedItemCount(NULL
, true);
1465 // Gets the text colour of the listview
1466 wxColour
wxListCtrl::GetTextColour() const
1469 return m_genericImpl
->GetTextColour();
1471 // TODO: we need owner drawn list items to customize text color.
1475 return wxNullColour
;
1478 // Sets the text colour of the listview
1479 void wxListCtrl::SetTextColour(const wxColour
& col
)
1483 m_genericImpl
->SetTextColour(col
);
1491 // Gets the index of the topmost visible item when in
1492 // list or report view
1493 long wxListCtrl::GetTopItem() const
1496 return m_genericImpl
->GetTopItem();
1501 long item
= HitTest( wxPoint(1, 1), flags
);
1502 if (flags
== wxLIST_HITTEST_ONITEM
)
1509 // Searches for an item, starting from 'item'.
1510 // 'geometry' is one of
1511 // wxLIST_NEXT_ABOVE/ALL/BELOW/LEFT/RIGHT.
1512 // 'state' is a state bit flag, one or more of
1513 // wxLIST_STATE_DROPHILITED/FOCUSED/SELECTED/CUT.
1514 // item can be -1 to find the first item that matches the
1516 // Returns the item or -1 if unsuccessful.
1517 long wxListCtrl::GetNextItem(long item
, int geom
, int state
) const
1520 return m_genericImpl
->GetNextItem(item
, geom
, state
);
1522 if (m_dbImpl
&& geom
== wxLIST_NEXT_ALL
&& state
== wxLIST_STATE_SELECTED
)
1524 long count
= m_dbImpl
->MacGetCount() ;
1525 for ( long line
= item
+ 1 ; line
< count
; line
++ )
1527 wxMacDataItem
* id
= m_dbImpl
->GetItemFromLine(line
);
1528 if ( m_dbImpl
->IsItemSelected(id
) )
1538 wxImageList
*wxListCtrl::GetImageList(int which
) const
1541 return m_genericImpl
->GetImageList(which
);
1543 if ( which
== wxIMAGE_LIST_NORMAL
)
1545 return m_imageListNormal
;
1547 else if ( which
== wxIMAGE_LIST_SMALL
)
1549 return m_imageListSmall
;
1551 else if ( which
== wxIMAGE_LIST_STATE
)
1553 return m_imageListState
;
1558 void wxListCtrl::SetImageList(wxImageList
*imageList
, int which
)
1562 m_genericImpl
->SetImageList(imageList
, which
);
1566 if ( which
== wxIMAGE_LIST_NORMAL
)
1568 if (m_ownsImageListNormal
) delete m_imageListNormal
;
1569 m_imageListNormal
= imageList
;
1570 m_ownsImageListNormal
= false;
1572 else if ( which
== wxIMAGE_LIST_SMALL
)
1574 if (m_ownsImageListSmall
) delete m_imageListSmall
;
1575 m_imageListSmall
= imageList
;
1576 m_ownsImageListSmall
= false;
1578 else if ( which
== wxIMAGE_LIST_STATE
)
1580 if (m_ownsImageListState
) delete m_imageListState
;
1581 m_imageListState
= imageList
;
1582 m_ownsImageListState
= false;
1586 void wxListCtrl::AssignImageList(wxImageList
*imageList
, int which
)
1590 m_genericImpl
->AssignImageList(imageList
, which
);
1594 SetImageList(imageList
, which
);
1595 if ( which
== wxIMAGE_LIST_NORMAL
)
1596 m_ownsImageListNormal
= true;
1597 else if ( which
== wxIMAGE_LIST_SMALL
)
1598 m_ownsImageListSmall
= true;
1599 else if ( which
== wxIMAGE_LIST_STATE
)
1600 m_ownsImageListState
= true;
1603 // ----------------------------------------------------------------------------
1605 // ----------------------------------------------------------------------------
1607 // Arranges the items
1608 bool wxListCtrl::Arrange(int flag
)
1611 return m_genericImpl
->Arrange(flag
);
1616 bool wxListCtrl::DeleteItem(long item
)
1619 return m_genericImpl
->DeleteItem(item
);
1623 m_dbImpl
->MacDelete(item
);
1624 wxListEvent
event( wxEVT_COMMAND_LIST_DELETE_ITEM
, GetId() );
1625 event
.SetEventObject( this );
1626 event
.m_itemIndex
= item
;
1627 GetEventHandler()->ProcessEvent( event
);
1633 // Deletes all items
1634 bool wxListCtrl::DeleteAllItems()
1637 return m_genericImpl
->DeleteAllItems();
1641 m_dbImpl
->MacClear();
1642 wxListEvent
event( wxEVT_COMMAND_LIST_DELETE_ALL_ITEMS
, GetId() );
1643 event
.SetEventObject( this );
1644 GetEventHandler()->ProcessEvent( event
);
1649 // Deletes all items
1650 bool wxListCtrl::DeleteAllColumns()
1653 return m_genericImpl
->DeleteAllColumns();
1658 m_dbImpl
->GetColumnCount(&cols
);
1659 for (UInt32 col
= 0; col
< cols
; col
++)
1669 bool wxListCtrl::DeleteColumn(int col
)
1672 return m_genericImpl
->DeleteColumn(col
);
1676 OSStatus err
= m_dbImpl
->RemoveColumn(col
);
1677 return err
== noErr
;
1683 // Clears items, and columns if there are any.
1684 void wxListCtrl::ClearAll()
1688 m_genericImpl
->ClearAll();
1699 wxTextCtrl
* wxListCtrl::EditLabel(long item
, wxClassInfo
* textControlClass
)
1702 return m_genericImpl
->EditLabel(item
, textControlClass
);
1706 wxCHECK_MSG( (item
>= 0) && ((long)item
< GetItemCount()), NULL
,
1707 wxT("wrong index in wxListCtrl::EditLabel()") );
1709 wxASSERT_MSG( textControlClass
->IsKindOf(CLASSINFO(wxTextCtrl
)),
1710 wxT("EditLabel() needs a text control") );
1712 wxListEvent
le( wxEVT_COMMAND_LIST_BEGIN_LABEL_EDIT
, GetParent()->GetId() );
1713 le
.SetEventObject( this );
1714 le
.m_itemIndex
= item
;
1716 GetItem( le
.m_item
);
1718 if ( GetParent()->GetEventHandler()->ProcessEvent( le
) && !le
.IsAllowed() )
1720 // vetoed by user code
1724 wxTextCtrl
* const text
= (wxTextCtrl
*)textControlClass
->CreateObject();
1725 m_textctrlWrapper
= new wxListCtrlTextCtrlWrapper(this, text
, item
);
1726 return m_textctrlWrapper
->GetText();
1731 // End label editing, optionally cancelling the edit
1732 bool wxListCtrl::EndEditLabel(bool cancel
)
1734 // TODO: generic impl. doesn't have this method - is it needed for us?
1736 return true; // m_genericImpl->EndEditLabel(cancel);
1739 verify_noerr( SetDataBrowserEditItem(m_dbImpl
->GetControlRef(), kDataBrowserNoItem
, kMinColumnId
) );
1743 // Ensures this item is visible
1744 bool wxListCtrl::EnsureVisible(long item
)
1747 return m_genericImpl
->EnsureVisible(item
);
1751 wxMacDataItem
* dataItem
= m_dbImpl
->GetItemFromLine(item
);
1752 m_dbImpl
->RevealItem(dataItem
, kDataBrowserRevealWithoutSelecting
);
1758 // Find an item whose label matches this string, starting from the item after 'start'
1759 // or the beginning if 'start' is -1.
1760 long wxListCtrl::FindItem(long start
, const wxString
& str
, bool partial
)
1763 return m_genericImpl
->FindItem(start
, str
, partial
);
1765 wxString str_upper
= str
.Upper();
1770 long count
= GetItemCount();
1774 wxString line_upper
= GetItemText(idx
).Upper();
1777 if (line_upper
== str_upper
)
1782 if (line_upper
.find(str_upper
) == 0)
1792 // Find an item whose data matches this data, starting from the item after 'start'
1793 // or the beginning if 'start' is -1.
1794 long wxListCtrl::FindItem(long start
, long data
)
1797 return m_genericImpl
->FindItem(start
, data
);
1802 long count
= GetItemCount();
1806 if (GetItemData(idx
) == data
)
1814 // Find an item nearest this position in the specified direction, starting from
1815 // the item after 'start' or the beginning if 'start' is -1.
1816 long wxListCtrl::FindItem(long start
, const wxPoint
& pt
, int direction
)
1819 return m_genericImpl
->FindItem(start
, pt
, direction
);
1823 // Determines which item (if any) is at the specified point,
1824 // giving details in 'flags' (see wxLIST_HITTEST_... flags above)
1826 wxListCtrl::HitTest(const wxPoint
& point
, int& flags
, long *ptrSubItem
) const
1829 return m_genericImpl
->HitTest(point
, flags
, ptrSubItem
);
1831 flags
= wxLIST_HITTEST_NOWHERE
;
1834 int colHeaderHeight
= 22; // TODO: Find a way to get this value from the db control?
1835 UInt16 rowHeight
= 0;
1836 m_dbImpl
->GetDefaultRowHeight(&rowHeight
);
1839 // get the actual row by taking scroll position into account
1840 UInt32 offsetX
, offsetY
;
1841 m_dbImpl
->GetScrollPosition( &offsetY
, &offsetX
);
1844 if ( !(GetWindowStyleFlag() & wxLC_NO_HEADER
) )
1845 y
-= colHeaderHeight
;
1850 int row
= y
/ rowHeight
;
1851 DataBrowserItemID id
;
1852 m_dbImpl
->GetItemID( (DataBrowserTableViewRowIndex
) row
, &id
);
1854 // TODO: Use GetDataBrowserItemPartBounds to return if we are in icon or label
1855 if ( !(GetWindowStyleFlag() & wxLC_VIRTUAL
) )
1857 wxMacListCtrlItem
* lcItem
;
1858 lcItem
= (wxMacListCtrlItem
*) id
;
1861 flags
= wxLIST_HITTEST_ONITEM
;
1867 if (row
< GetItemCount() )
1869 flags
= wxLIST_HITTEST_ONITEM
;
1878 int wxListCtrl::GetScrollPos(int orient
) const
1881 return m_genericImpl
->GetScrollPos(orient
);
1885 UInt32 offsetX
, offsetY
;
1886 m_dbImpl
->GetScrollPosition( &offsetY
, &offsetX
);
1887 if ( orient
== wxHORIZONTAL
)
1896 // Inserts an item, returning the index of the new item if successful,
1898 long wxListCtrl::InsertItem(wxListItem
& info
)
1900 wxASSERT_MSG( !IsVirtual(), _T("can't be used with virtual controls") );
1903 return m_genericImpl
->InsertItem(info
);
1905 if (m_dbImpl
&& !IsVirtual())
1907 int count
= GetItemCount();
1909 if (info
.m_itemId
> count
)
1910 info
.m_itemId
= count
;
1912 m_dbImpl
->MacInsertItem(info
.m_itemId
, &info
);
1913 wxMacDataItem
* dataItem
= m_dbImpl
->GetItemFromLine(info
.m_itemId
);
1915 wxListEvent
event( wxEVT_COMMAND_LIST_INSERT_ITEM
, GetId() );
1916 event
.SetEventObject( this );
1917 event
.m_itemIndex
= info
.m_itemId
;
1918 GetEventHandler()->ProcessEvent( event
);
1919 return info
.m_itemId
;
1924 long wxListCtrl::InsertItem(long index
, const wxString
& label
)
1927 return m_genericImpl
->InsertItem(index
, label
);
1930 info
.m_text
= label
;
1931 info
.m_mask
= wxLIST_MASK_TEXT
;
1932 info
.m_itemId
= index
;
1933 return InsertItem(info
);
1936 // Inserts an image item
1937 long wxListCtrl::InsertItem(long index
, int imageIndex
)
1940 return m_genericImpl
->InsertItem(index
, imageIndex
);
1943 info
.m_image
= imageIndex
;
1944 info
.m_mask
= wxLIST_MASK_IMAGE
;
1945 info
.m_itemId
= index
;
1946 return InsertItem(info
);
1949 // Inserts an image/string item
1950 long wxListCtrl::InsertItem(long index
, const wxString
& label
, int imageIndex
)
1953 return m_genericImpl
->InsertItem(index
, label
, imageIndex
);
1956 info
.m_image
= imageIndex
;
1957 info
.m_text
= label
;
1958 info
.m_mask
= wxLIST_MASK_IMAGE
| wxLIST_MASK_TEXT
;
1959 info
.m_itemId
= index
;
1960 return InsertItem(info
);
1963 // For list view mode (only), inserts a column.
1964 long wxListCtrl::InsertColumn(long col
, wxListItem
& item
)
1967 return m_genericImpl
->InsertColumn(col
, item
);
1971 int width
= item
.GetWidth();
1972 if ( !(item
.GetMask() & wxLIST_MASK_WIDTH
) )
1975 DataBrowserPropertyType type
= kDataBrowserCustomType
; //kDataBrowserTextType;
1976 wxImageList
* imageList
= GetImageList(wxIMAGE_LIST_SMALL
);
1977 if (imageList
&& imageList
->GetImageCount() > 0)
1979 wxBitmap bmp
= imageList
->GetBitmap(0);
1981 // type = kDataBrowserIconAndTextType;
1984 SInt16 just
= teFlushDefault
;
1985 if (item
.GetMask() & wxLIST_MASK_FORMAT
)
1987 if (item
.GetAlign() == wxLIST_FORMAT_LEFT
)
1989 else if (item
.GetAlign() == wxLIST_FORMAT_CENTER
)
1991 else if (item
.GetAlign() == wxLIST_FORMAT_RIGHT
)
1992 just
= teFlushRight
;
1994 m_dbImpl
->InsertColumn(col
, type
, item
.GetText(), just
, width
);
1995 SetColumn(col
, item
);
1997 // set/remove options based on the wxListCtrl type.
1998 DataBrowserTableViewColumnID id
;
1999 m_dbImpl
->GetColumnIDFromIndex(col
, &id
);
2000 DataBrowserPropertyFlags flags
;
2001 verify_noerr(m_dbImpl
->GetPropertyFlags(id
, &flags
));
2002 if (GetWindowStyleFlag() & wxLC_EDIT_LABELS
)
2003 flags
|= kDataBrowserPropertyIsEditable
;
2005 if (GetWindowStyleFlag() & wxLC_VIRTUAL
){
2006 flags
&= ~kDataBrowserListViewSortableColumn
;
2008 verify_noerr(m_dbImpl
->SetPropertyFlags(id
, flags
));
2014 long wxListCtrl::InsertColumn(long col
,
2015 const wxString
& heading
,
2020 return m_genericImpl
->InsertColumn(col
, heading
, format
, width
);
2023 item
.m_mask
= wxLIST_MASK_TEXT
| wxLIST_MASK_FORMAT
;
2024 item
.m_text
= heading
;
2027 item
.m_mask
|= wxLIST_MASK_WIDTH
;
2028 item
.m_width
= width
;
2030 item
.m_format
= format
;
2032 return InsertColumn(col
, item
);
2035 // scroll the control by the given number of pixels (exception: in list view,
2036 // dx is interpreted as number of columns)
2037 bool wxListCtrl::ScrollList(int dx
, int dy
)
2040 return m_genericImpl
->ScrollList(dx
, dy
);
2044 m_dbImpl
->SetScrollPosition(dx
, dy
);
2050 bool wxListCtrl::SortItems(wxListCtrlCompare fn
, long data
)
2053 return m_genericImpl
->SortItems(fn
, data
);
2058 m_compareFuncData
= data
;
2059 SortDataBrowserContainer( m_dbImpl
->GetControlRef(), kDataBrowserNoItem
, true);
2061 // we need to do this after each call, else we get a crash from wxPython when
2062 // SortItems is called the second time.
2063 m_compareFunc
= NULL
;
2064 m_compareFuncData
= 0;
2070 void wxListCtrl::OnRenameTimer()
2072 wxCHECK_RET( HasCurrent(), wxT("unexpected rename timer") );
2074 EditLabel( m_current
);
2077 bool wxListCtrl::OnRenameAccept(long itemEdit
, const wxString
& value
)
2079 wxListEvent
le( wxEVT_COMMAND_LIST_END_LABEL_EDIT
, GetId() );
2080 le
.SetEventObject( this );
2081 le
.m_itemIndex
= itemEdit
;
2083 GetItem( le
.m_item
);
2084 le
.m_item
.m_text
= value
;
2085 return !GetEventHandler()->ProcessEvent( le
) ||
2089 void wxListCtrl::OnRenameCancelled(long itemEdit
)
2091 // let owner know that the edit was cancelled
2092 wxListEvent
le( wxEVT_COMMAND_LIST_END_LABEL_EDIT
, GetParent()->GetId() );
2094 le
.SetEditCanceled(true);
2096 le
.SetEventObject( this );
2097 le
.m_itemIndex
= itemEdit
;
2099 GetItem( le
.m_item
);
2100 GetEventHandler()->ProcessEvent( le
);
2103 // ----------------------------------------------------------------------------
2104 // virtual list controls
2105 // ----------------------------------------------------------------------------
2107 wxString
wxListCtrl::OnGetItemText(long WXUNUSED(item
), long WXUNUSED(col
)) const
2109 // this is a pure virtual function, in fact - which is not really pure
2110 // because the controls which are not virtual don't need to implement it
2111 wxFAIL_MSG( _T("wxListCtrl::OnGetItemText not supposed to be called") );
2113 return wxEmptyString
;
2116 int wxListCtrl::OnGetItemImage(long WXUNUSED(item
)) const
2118 wxCHECK_MSG(!GetImageList(wxIMAGE_LIST_SMALL
),
2120 wxT("List control has an image list, OnGetItemImage or OnGetItemColumnImage should be overridden."));
2124 int wxListCtrl::OnGetItemColumnImage(long item
, long column
) const
2127 return OnGetItemImage(item
);
2132 wxListItemAttr
*wxListCtrl::OnGetItemAttr(long WXUNUSED_UNLESS_DEBUG(item
)) const
2134 wxASSERT_MSG( item
>= 0 && item
< GetItemCount(),
2135 _T("invalid item index in OnGetItemAttr()") );
2137 // no attributes by default
2141 void wxListCtrl::SetItemCount(long count
)
2143 wxASSERT_MSG( IsVirtual(), _T("this is for virtual controls only") );
2147 m_genericImpl
->SetItemCount(count
);
2153 // we need to temporarily disable the new item creation notification
2154 // procedure to speed things up
2155 // FIXME: Even this doesn't seem to help much...
2157 // FIXME: Find a more efficient way to do this.
2158 m_dbImpl
->MacClear();
2160 DataBrowserCallbacks callbacks
;
2161 DataBrowserItemNotificationUPP itemUPP
;
2162 GetDataBrowserCallbacks(m_dbImpl
->GetControlRef(), &callbacks
);
2163 itemUPP
= callbacks
.u
.v1
.itemNotificationCallback
;
2164 callbacks
.u
.v1
.itemNotificationCallback
= 0;
2165 m_dbImpl
->SetCallbacks(&callbacks
);
2166 ::AddDataBrowserItems(m_dbImpl
->GetControlRef(), kDataBrowserNoItem
,
2167 count
, NULL
, kDataBrowserItemNoProperty
);
2168 callbacks
.u
.v1
.itemNotificationCallback
= itemUPP
;
2169 m_dbImpl
->SetCallbacks(&callbacks
);
2174 void wxListCtrl::RefreshItem(long item
)
2178 m_genericImpl
->RefreshItem(item
);
2183 GetItemRect(item
, rect
);
2187 void wxListCtrl::RefreshItems(long itemFrom
, long itemTo
)
2191 m_genericImpl
->RefreshItems(itemFrom
, itemTo
);
2195 wxRect rect1
, rect2
;
2196 GetItemRect(itemFrom
, rect1
);
2197 GetItemRect(itemTo
, rect2
);
2199 wxRect rect
= rect1
;
2200 rect
.height
= rect2
.GetBottom() - rect1
.GetTop();
2205 void wxListCtrl::SetDropTarget( wxDropTarget
*dropTarget
)
2207 #if wxUSE_DRAG_AND_DROP
2209 m_genericImpl
->SetDropTarget( dropTarget
);
2212 wxWindow::SetDropTarget( dropTarget
);
2216 wxDropTarget
*wxListCtrl::GetDropTarget() const
2218 #if wxUSE_DRAG_AND_DROP
2220 return m_genericImpl
->GetDropTarget();
2223 return wxWindow::GetDropTarget();
2228 #if wxABI_VERSION >= 20801
2229 void wxListCtrl::SetFocus()
2233 m_genericImpl
->SetFocus();
2237 wxWindow::SetFocus();
2241 // wxMac internal data structures
2243 wxMacListCtrlItem::~wxMacListCtrlItem()
2247 void wxMacListCtrlItem::Notification(wxMacDataItemBrowserControl
*owner
,
2248 DataBrowserItemNotification message
,
2249 DataBrowserItemDataRef itemData
) const
2252 wxMacDataBrowserListCtrlControl
*lb
= wxDynamicCast(owner
, wxMacDataBrowserListCtrlControl
);
2254 // we want to depend on as little as possible to make sure tear-down of controls is safe
2255 if ( message
== kDataBrowserItemRemoved
)
2257 if ( lb
!= NULL
&& lb
->GetClientDataType() == wxClientData_Object
)
2259 delete (wxClientData
*) (m_data
);
2265 else if ( message
== kDataBrowserItemAdded
)
2267 // we don't issue events on adding, the item is not really stored in the list yet, so we
2268 // avoid asserts by gettting out now
2272 wxListCtrl
*list
= wxDynamicCast( owner
->GetPeer() , wxListCtrl
);
2275 bool trigger
= false;
2277 wxListEvent
event( wxEVT_COMMAND_LIST_ITEM_SELECTED
, list
->GetId() );
2278 bool isSingle
= (list
->GetWindowStyle() & wxLC_SINGLE_SEL
) != 0;
2280 event
.SetEventObject( list
);
2281 event
.m_itemIndex
= owner
->GetLineFromItem( this ) ;
2282 if ( !list
->IsVirtual() )
2284 lb
->MacGetColumnInfo(event
.m_itemIndex
,0,event
.m_item
);
2289 case kDataBrowserItemDeselected
:
2290 event
.SetEventType(wxEVT_COMMAND_LIST_ITEM_DESELECTED
);
2292 trigger
= !lb
->IsSelectionSuppressed();
2295 case kDataBrowserItemSelected
:
2296 trigger
= !lb
->IsSelectionSuppressed();
2299 case kDataBrowserItemDoubleClicked
:
2300 event
.SetEventType( wxEVT_COMMAND_LIST_ITEM_ACTIVATED
);
2304 case kDataBrowserEditStarted
:
2305 // TODO : how to veto ?
2306 event
.SetEventType( wxEVT_COMMAND_LIST_BEGIN_LABEL_EDIT
) ;
2310 case kDataBrowserEditStopped
:
2311 // TODO probably trigger only upon the value store callback, because
2312 // here IIRC we cannot veto
2313 event
.SetEventType( wxEVT_COMMAND_LIST_END_LABEL_EDIT
) ;
2323 // direct notification is not always having the listbox GetSelection() having in synch with event
2324 wxPostEvent( list
->GetEventHandler(), event
);
2330 IMPLEMENT_DYNAMIC_CLASS(wxMacDataBrowserListCtrlControl
, wxMacDataItemBrowserControl
)
2332 wxMacDataBrowserListCtrlControl::wxMacDataBrowserListCtrlControl( wxWindow
*peer
, const wxPoint
& pos
, const wxSize
& size
, long style
)
2333 : wxMacDataItemBrowserControl( peer
, pos
, size
, style
)
2335 OSStatus err
= noErr
;
2336 m_clientDataItemsType
= wxClientData_None
;
2337 m_isVirtual
= false;
2339 if ( style
& wxLC_VIRTUAL
)
2342 DataBrowserSelectionFlags options
= kDataBrowserDragSelect
;
2343 if ( style
& wxLC_SINGLE_SEL
)
2345 options
|= kDataBrowserSelectOnlyOne
;
2349 options
|= kDataBrowserCmdTogglesSelection
;
2352 err
= SetSelectionFlags( options
);
2353 verify_noerr( err
);
2355 DataBrowserCustomCallbacks callbacks
;
2356 InitializeDataBrowserCustomCallbacks( &callbacks
, kDataBrowserLatestCustomCallbacks
);
2358 if ( gDataBrowserDrawItemUPP
== NULL
)
2359 gDataBrowserDrawItemUPP
= NewDataBrowserDrawItemUPP(DataBrowserDrawItemProc
);
2361 if ( gDataBrowserHitTestUPP
== NULL
)
2362 gDataBrowserHitTestUPP
= NewDataBrowserHitTestUPP(DataBrowserHitTestProc
);
2364 callbacks
.u
.v1
.drawItemCallback
= gDataBrowserDrawItemUPP
;
2365 callbacks
.u
.v1
.hitTestCallback
= gDataBrowserHitTestUPP
;
2367 SetDataBrowserCustomCallbacks( GetControlRef(), &callbacks
);
2369 if ( style
& wxLC_LIST
)
2371 InsertColumn(0, kDataBrowserIconAndTextType
, wxEmptyString
, -1, -1);
2372 verify_noerr( AutoSizeColumns() );
2375 if ( style
& wxLC_LIST
|| style
& wxLC_NO_HEADER
)
2376 verify_noerr( SetHeaderButtonHeight( 0 ) );
2379 SetSortProperty( kMinColumnId
- 1 );
2381 SetSortProperty( kMinColumnId
);
2383 m_sortOrder
= SortOrder_None
;
2385 if ( style
& wxLC_SORT_DESCENDING
)
2387 SetSortOrder( kDataBrowserOrderDecreasing
);
2389 else if ( style
& wxLC_SORT_ASCENDING
)
2391 SetSortOrder( kDataBrowserOrderIncreasing
);
2394 if ( style
& wxLC_VRULES
)
2396 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4
2397 verify_noerr( DataBrowserChangeAttributes(m_controlRef
, kDataBrowserAttributeListViewDrawColumnDividers
, kDataBrowserAttributeNone
) );
2401 verify_noerr( SetHiliteStyle(kDataBrowserTableViewFillHilite
) );
2402 err
= SetHasScrollBars( (style
& wxHSCROLL
) != 0 , true );
2405 pascal Boolean
wxMacDataBrowserListCtrlControl::DataBrowserEditTextProc(
2407 DataBrowserItemID itemID
,
2408 DataBrowserPropertyID property
,
2409 CFStringRef theString
,
2410 Rect
*maxEditTextRect
,
2411 Boolean
*shrinkToFit
)
2413 Boolean result
= false;
2414 wxMacDataBrowserListCtrlControl
* ctl
= wxDynamicCast(wxMacControl::GetReferenceFromNativeControl( browser
), wxMacDataBrowserListCtrlControl
);
2417 result
= ctl
->ConfirmEditText(itemID
, property
, theString
, maxEditTextRect
, shrinkToFit
);
2418 theString
= CFSTR("Hello!");
2423 bool wxMacDataBrowserListCtrlControl::ConfirmEditText(
2424 DataBrowserItemID itemID
,
2425 DataBrowserPropertyID property
,
2426 CFStringRef theString
,
2427 Rect
*maxEditTextRect
,
2428 Boolean
*shrinkToFit
)
2433 pascal void wxMacDataBrowserListCtrlControl::DataBrowserDrawItemProc(
2435 DataBrowserItemID itemID
,
2436 DataBrowserPropertyID property
,
2437 DataBrowserItemState itemState
,
2438 const Rect
*itemRect
,
2440 Boolean colorDevice
)
2442 wxMacDataBrowserListCtrlControl
* ctl
= wxDynamicCast(wxMacControl::GetReferenceFromNativeControl( browser
), wxMacDataBrowserListCtrlControl
);
2445 ctl
->DrawItem(itemID
, property
, itemState
, itemRect
, gdDepth
, colorDevice
);
2449 // routines needed for DrawItem
2454 kTextBoxHeight
= 14,
2455 kIconTextSpacingV
= 2,
2457 kContentHeight
= kIconHeight
+ kTextBoxHeight
+ kIconTextSpacingV
2460 static void calculateCGDrawingBounds(CGRect inItemRect
, CGRect
*outIconRect
, CGRect
*outTextRect
, bool hasIcon
= false)
2463 float iconH
, iconW
= 0;
2464 float padding
= kItemPadding
;
2467 iconH
= kIconHeight
;
2469 padding
= padding
*2;
2472 textBottom
= inItemRect
.origin
.y
;
2474 *outIconRect
= CGRectMake(inItemRect
.origin
.x
+ kItemPadding
,
2475 textBottom
+ kIconTextSpacingV
, kIconWidth
,
2478 *outTextRect
= CGRectMake(inItemRect
.origin
.x
+ padding
+ iconW
,
2479 textBottom
+ kIconTextSpacingV
, inItemRect
.size
.width
- padding
- iconW
,
2480 inItemRect
.size
.height
- kIconTextSpacingV
);
2483 void wxMacDataBrowserListCtrlControl::DrawItem(
2484 DataBrowserItemID itemID
,
2485 DataBrowserPropertyID property
,
2486 DataBrowserItemState itemState
,
2487 const Rect
*itemRect
,
2489 Boolean colorDevice
)
2492 wxFont font
= wxNullFont
;
2494 short listColumn
= property
- kMinColumnId
;
2496 wxListCtrl
* list
= wxDynamicCast( GetPeer() , wxListCtrl
);
2497 wxMacListCtrlItem
* lcItem
;
2498 wxColour color
= *wxBLACK
;
2499 wxColour bgColor
= wxNullColour
;
2501 if (listColumn
>= 0)
2505 lcItem
= (wxMacListCtrlItem
*) itemID
;
2506 if (lcItem
->HasColumnInfo(listColumn
)){
2507 wxListItem
* item
= lcItem
->GetColumnInfo(listColumn
);
2509 // we always use the 0 column to get font and text/background colors.
2510 if (lcItem
->HasColumnInfo(0))
2512 wxListItem
* firstItem
= lcItem
->GetColumnInfo(0);
2513 color
= firstItem
->GetTextColour();
2514 bgColor
= firstItem
->GetBackgroundColour();
2515 font
= firstItem
->GetFont();
2518 if (item
->GetMask() & wxLIST_MASK_TEXT
)
2519 text
= item
->GetText();
2520 if (item
->GetMask() & wxLIST_MASK_IMAGE
)
2521 imgIndex
= item
->GetImage();
2527 text
= list
->OnGetItemText( (long)itemID
-1, listColumn
);
2528 imgIndex
= list
->OnGetItemColumnImage( (long)itemID
-1, listColumn
);
2529 wxListItemAttr
* attrs
= list
->OnGetItemAttr( (long)itemID
-1 );
2532 if (attrs
->HasBackgroundColour())
2533 bgColor
= attrs
->GetBackgroundColour();
2534 if (attrs
->HasTextColour())
2535 color
= attrs
->GetTextColour();
2536 if (attrs
->HasFont())
2537 font
= attrs
->GetFont();
2542 wxColour listBgColor
= list
->GetBackgroundColour();
2543 if (bgColor
== wxNullColour
)
2544 bgColor
= listBgColor
;
2546 wxFont listFont
= list
->GetFont();
2547 if (font
== wxNullFont
)
2550 wxMacCFStringHolder cfString
;
2551 cfString
.Assign( text
, wxLocale::GetSystemEncoding() );
2554 CGRect enclosingCGRect
, iconCGRect
, textCGRect
;
2556 ThemeDrawingState savedState
= NULL
;
2557 CGContextRef context
= (CGContextRef
)list
->MacGetDrawingContext();
2558 RGBColor labelColor
;
2560 labelColor
.green
= 0;
2561 labelColor
.blue
= 0;
2563 RGBColor backgroundColor
;
2564 backgroundColor
.red
= 255;
2565 backgroundColor
.green
= 255;
2566 backgroundColor
.blue
= 255;
2568 GetDataBrowserItemPartBounds(GetControlRef(), itemID
, property
, kDataBrowserPropertyEnclosingPart
,
2571 enclosingCGRect
= CGRectMake(enclosingRect
.left
,
2573 enclosingRect
.right
- enclosingRect
.left
,
2574 enclosingRect
.bottom
- enclosingRect
.top
);
2576 active
= IsControlActive(GetControlRef());
2578 // don't paint the background over the vertical rule line
2579 if ( list
->GetWindowStyleFlag() & wxLC_VRULES
)
2581 enclosingCGRect
.origin
.x
+= 1;
2582 enclosingCGRect
.size
.width
-= 1;
2584 if (itemState
== kDataBrowserItemIsSelected
)
2587 GetThemeDrawingState(&savedState
);
2589 GetThemeBrushAsColor(kThemeBrushAlternatePrimaryHighlightColor
, 32, true, &backgroundColor
);
2590 GetThemeTextColor(kThemeTextColorWhite
, gdDepth
, colorDevice
, &labelColor
);
2592 CGContextSaveGState(context
);
2594 CGContextSetRGBFillColor(context
, (float)backgroundColor
.red
/ (float)USHRT_MAX
,
2595 (float)backgroundColor
.green
/ (float)USHRT_MAX
,
2596 (float)backgroundColor
.blue
/ (float)USHRT_MAX
, 1.0);
2597 CGContextFillRect(context
, enclosingCGRect
);
2599 CGContextRestoreGState(context
);
2605 labelColor
= MAC_WXCOLORREF( color
.GetPixel() );
2606 else if (list
->GetTextColour().Ok())
2607 labelColor
= MAC_WXCOLORREF( list
->GetTextColour().GetPixel() );
2611 backgroundColor
= MAC_WXCOLORREF( bgColor
.GetPixel() );
2612 CGContextSaveGState(context
);
2614 CGContextSetRGBFillColor(context
, (float)backgroundColor
.red
/ (float)USHRT_MAX
,
2615 (float)backgroundColor
.green
/ (float)USHRT_MAX
,
2616 (float)backgroundColor
.blue
/ (float)USHRT_MAX
, 1.0);
2617 CGContextFillRect(context
, enclosingCGRect
);
2619 CGContextRestoreGState(context
);
2623 calculateCGDrawingBounds(enclosingCGRect
, &iconCGRect
, &textCGRect
, (imgIndex
!= -1) );
2627 wxImageList
* imageList
= list
->GetImageList(wxIMAGE_LIST_SMALL
);
2628 if (imageList
&& imageList
->GetImageCount() > 0){
2629 wxBitmap bmp
= imageList
->GetBitmap(imgIndex
);
2630 IconRef icon
= bmp
.GetBitmapData()->GetIconRef();
2632 CGContextSaveGState(context
);
2633 CGContextTranslateCTM(context
, 0,iconCGRect
.origin
.y
+ CGRectGetMaxY(iconCGRect
));
2634 CGContextScaleCTM(context
,1.0f
,-1.0f
);
2635 PlotIconRefInContext(context
, &iconCGRect
, kAlignNone
,
2636 active
? kTransformNone
: kTransformDisabled
, NULL
,
2637 kPlotIconRefNormalFlags
, icon
);
2639 CGContextRestoreGState(context
);
2643 HIThemeTextHorizontalFlush hFlush
= kHIThemeTextHorizontalFlushLeft
;
2644 UInt16 fontID
= kThemeViewsFont
;
2648 if (font
.GetFamily() != wxFONTFAMILY_DEFAULT
)
2649 fontID
= font
.MacGetThemeFontID();
2651 // FIXME: replace these with CG or ATSUI calls so we can remove this #ifndef.
2653 ::TextSize( (short)(font
.MacGetFontSize()) ) ;
2654 ::TextFace( font
.MacGetFontStyle() ) ;
2659 list
->GetColumn(listColumn
, item
);
2660 if (item
.GetMask() & wxLIST_MASK_FORMAT
)
2662 if (item
.GetAlign() == wxLIST_FORMAT_LEFT
)
2663 hFlush
= kHIThemeTextHorizontalFlushLeft
;
2664 else if (item
.GetAlign() == wxLIST_FORMAT_CENTER
)
2665 hFlush
= kHIThemeTextHorizontalFlushCenter
;
2666 else if (item
.GetAlign() == wxLIST_FORMAT_RIGHT
)
2668 hFlush
= kHIThemeTextHorizontalFlushRight
;
2669 textCGRect
.origin
.x
-= kItemPadding
; // give a little extra paddding
2673 HIThemeTextInfo info
;
2674 info
.version
= kHIThemeTextInfoVersionZero
;
2675 info
.state
= active
? kThemeStateActive
: kThemeStateInactive
;
2676 info
.fontID
= fontID
;
2677 info
.horizontalFlushness
= hFlush
;
2678 info
.verticalFlushness
= kHIThemeTextVerticalFlushCenter
;
2679 info
.options
= kHIThemeTextBoxOptionNone
;
2680 info
.truncationPosition
= kHIThemeTextTruncationEnd
;
2681 info
.truncationMaxLines
= 1;
2683 CGContextSaveGState(context
);
2684 CGContextSetRGBFillColor (context
, (float)labelColor
.red
/ (float)USHRT_MAX
,
2685 (float)labelColor
.green
/ (float)USHRT_MAX
,
2686 (float)labelColor
.blue
/ (float)USHRT_MAX
, 1.0);
2688 HIThemeDrawTextBox(cfString
, &textCGRect
, &info
, context
, kHIThemeOrientationNormal
);
2690 CGContextRestoreGState(context
);
2692 if (savedState
!= NULL
)
2693 SetThemeDrawingState(savedState
, true);
2696 OSStatus
wxMacDataBrowserListCtrlControl::GetSetItemData(DataBrowserItemID itemID
,
2697 DataBrowserPropertyID property
,
2698 DataBrowserItemDataRef itemData
,
2699 Boolean changeValue
)
2703 short listColumn
= property
- kMinColumnId
;
2705 OSStatus err
= errDataBrowserPropertyNotSupported
;
2706 wxListCtrl
* list
= wxDynamicCast( GetPeer() , wxListCtrl
);
2707 wxMacListCtrlItem
* lcItem
;
2709 if (listColumn
>= 0)
2713 lcItem
= (wxMacListCtrlItem
*) itemID
;
2714 if (lcItem
&& lcItem
->HasColumnInfo(listColumn
)){
2715 wxListItem
* item
= lcItem
->GetColumnInfo(listColumn
);
2716 if (item
->GetMask() & wxLIST_MASK_TEXT
)
2717 text
= item
->GetText();
2718 if (item
->GetMask() & wxLIST_MASK_IMAGE
)
2719 imgIndex
= item
->GetImage();
2724 text
= list
->OnGetItemText( (long)itemID
-1, listColumn
);
2725 imgIndex
= list
->OnGetItemColumnImage( (long)itemID
-1, listColumn
);
2733 case kDataBrowserItemIsEditableProperty
:
2734 if ( list
&& list
->HasFlag( wxLC_EDIT_LABELS
) )
2736 verify_noerr(SetDataBrowserItemDataBooleanValue( itemData
, true ));
2741 if ( property
>= kMinColumnId
)
2743 wxMacCFStringHolder cfStr
;
2746 cfStr
.Assign( text
, wxLocale::GetSystemEncoding() );
2747 err
= ::SetDataBrowserItemDataText( itemData
, cfStr
);
2753 if ( imgIndex
!= -1 )
2755 wxImageList
* imageList
= list
->GetImageList(wxIMAGE_LIST_SMALL
);
2756 if (imageList
&& imageList
->GetImageCount() > 0){
2757 wxBitmap bmp
= imageList
->GetBitmap(imgIndex
);
2758 IconRef icon
= bmp
.GetBitmapData()->GetIconRef();
2759 ::SetDataBrowserItemDataIcon(itemData
, icon
);
2773 if ( property
>= kMinColumnId
)
2775 short listColumn
= property
- kMinColumnId
;
2777 // TODO probably send the 'end edit' from here, as we
2778 // can then deal with the veto
2780 verify_noerr( GetDataBrowserItemDataText( itemData
, &sr
) ) ;
2781 wxMacCFStringHolder
cfStr(sr
) ;;
2783 list
->SetItem( (long)itemData
-1 , listColumn
, cfStr
.AsString() ) ;
2787 lcItem
->SetColumnTextValue( listColumn
, cfStr
.AsString() );
2797 void wxMacDataBrowserListCtrlControl::ItemNotification(DataBrowserItemID itemID
,
2798 DataBrowserItemNotification message
,
2799 DataBrowserItemDataRef itemData
)
2801 // we want to depend on as little as possible to make sure tear-down of controls is safe
2802 if ( message
== kDataBrowserItemRemoved
)
2804 // make sure MacDelete does the proper teardown.
2807 else if ( message
== kDataBrowserItemAdded
)
2809 // we don't issue events on adding, the item is not really stored in the list yet, so we
2810 // avoid asserts by getting out now
2814 wxListCtrl
*list
= wxDynamicCast( GetPeer() , wxListCtrl
);
2817 bool trigger
= false;
2819 wxListEvent
event( wxEVT_COMMAND_LIST_ITEM_SELECTED
, list
->GetId() );
2820 bool isSingle
= (list
->GetWindowStyle() & wxLC_SINGLE_SEL
) != 0;
2822 event
.SetEventObject( list
);
2823 if ( !list
->IsVirtual() )
2825 DataBrowserTableViewRowIndex result
= 0;
2826 verify_noerr( GetItemRow( itemID
, &result
) ) ;
2827 event
.m_itemIndex
= result
;
2829 if (event
.m_itemIndex
>= 0)
2830 MacGetColumnInfo(event
.m_itemIndex
,0,event
.m_item
);
2834 event
.m_itemIndex
= (long)itemID
-1;
2839 case kDataBrowserItemDeselected
:
2840 event
.SetEventType(wxEVT_COMMAND_LIST_ITEM_DESELECTED
);
2842 trigger
= !IsSelectionSuppressed();
2845 case kDataBrowserItemSelected
:
2846 trigger
= !IsSelectionSuppressed();
2850 case kDataBrowserItemDoubleClicked
:
2851 event
.SetEventType( wxEVT_COMMAND_LIST_ITEM_ACTIVATED
);
2855 case kDataBrowserEditStarted
:
2856 // TODO : how to veto ?
2857 event
.SetEventType( wxEVT_COMMAND_LIST_BEGIN_LABEL_EDIT
) ;
2861 case kDataBrowserEditStopped
:
2862 // TODO probably trigger only upon the value store callback, because
2863 // here IIRC we cannot veto
2864 event
.SetEventType( wxEVT_COMMAND_LIST_END_LABEL_EDIT
) ;
2874 // direct notification is not always having the listbox GetSelection() having in synch with event
2875 wxPostEvent( list
->GetEventHandler(), event
);
2880 Boolean
wxMacDataBrowserListCtrlControl::CompareItems(DataBrowserItemID itemOneID
,
2881 DataBrowserItemID itemTwoID
,
2882 DataBrowserPropertyID sortProperty
)
2885 bool retval
= false;
2887 wxString otherItemText
;
2889 long otherItemOrder
;
2891 int colId
= sortProperty
- kMinColumnId
;
2893 wxListCtrl
* list
= wxDynamicCast( GetPeer() , wxListCtrl
);
2895 DataBrowserSortOrder sort
;
2896 verify_noerr(GetSortOrder(&sort
));
2902 wxMacListCtrlItem
* item
= (wxMacListCtrlItem
*)itemOneID
;
2903 wxMacListCtrlItem
* otherItem
= (wxMacListCtrlItem
*)itemTwoID
;
2905 itemOrder
= item
->GetOrder();
2906 otherItemOrder
= item
->GetOrder();
2908 wxListCtrlCompare func
= list
->GetCompareFunc();
2913 if (item
&& item
->HasColumnInfo(0))
2914 item1
= item
->GetColumnInfo(0)->GetData();
2915 if (otherItem
&& otherItem
->HasColumnInfo(0))
2916 item2
= otherItem
->GetColumnInfo(0)->GetData();
2918 if (item1
> -1 && item2
> -1)
2920 int result
= func(item1
, item2
, list
->GetCompareFuncData());
2921 if (sort
== kDataBrowserOrderIncreasing
)
2928 // we can't use the native control's sorting abilities, so just
2930 return itemOrder
< otherItemOrder
;
2935 long itemNum
= (long)itemOneID
;
2936 long otherItemNum
= (long)itemTwoID
;
2937 itemText
= list
->OnGetItemText( itemNum
-1, colId
);
2938 otherItemText
= list
->OnGetItemText( otherItemNum
-1, colId
);
2940 // virtual listctrls don't support sorting
2941 return itemNum
< otherItemNum
;
2945 // fallback for undefined cases
2946 retval
= itemOneID
< itemTwoID
;
2952 wxMacDataBrowserListCtrlControl::~wxMacDataBrowserListCtrlControl()
2956 void wxMacDataBrowserListCtrlControl::MacSetColumnInfo( unsigned int row
, unsigned int column
, wxListItem
* item
)
2958 wxMacDataItem
* dataItem
= GetItemFromLine(row
);
2959 wxASSERT_MSG( dataItem
, _T("could not obtain wxMacDataItem for row in MacSetColumnInfo. Is row a valid wxListCtrl row?") );
2962 wxMacListCtrlItem
* listItem
= wx_static_cast(wxMacListCtrlItem
*,dataItem
);
2963 bool hasInfo
= listItem
->HasColumnInfo( column
);
2964 listItem
->SetColumnInfo( column
, item
);
2965 listItem
->SetOrder(row
);
2966 UpdateState(dataItem
, item
);
2968 wxListCtrl
* list
= wxDynamicCast( GetPeer() , wxListCtrl
);
2970 // NB: When this call was made before a control was completely shown, it would
2971 // update the item prematurely (i.e. no text would be listed) and, on show,
2972 // only the sorted column would be refreshed, meaning only first column text labels
2973 // would be shown. Making sure not to update items until the control is visible
2974 // seems to fix this issue.
2975 if (hasInfo
&& list
->IsShown())
2976 UpdateItem( wxMacDataBrowserRootContainer
, listItem
, kMinColumnId
+ column
);
2980 // apply changes that need to happen immediately, rather than when the
2981 // databrowser control fires a callback.
2982 void wxMacDataBrowserListCtrlControl::UpdateState(wxMacDataItem
* dataItem
, wxListItem
* listItem
)
2984 bool isSelected
= IsItemSelected( dataItem
);
2985 bool isSelectedState
= (listItem
->GetState() == wxLIST_STATE_SELECTED
);
2987 // toggle the selection state if wxListInfo state and actual state don't match.
2988 if ( isSelected
!= isSelectedState
)
2990 DataBrowserSetOption options
= kDataBrowserItemsAdd
;
2991 if (!isSelectedState
)
2992 options
= kDataBrowserItemsRemove
;
2993 SetSelectedItem(dataItem
, options
);
2995 // TODO: Set column width if item width > than current column width
2998 void wxMacDataBrowserListCtrlControl::MacGetColumnInfo( unsigned int row
, unsigned int column
, wxListItem
& item
)
3000 wxMacDataItem
* dataItem
= GetItemFromLine(row
);
3001 wxASSERT_MSG( dataItem
, _T("could not obtain wxMacDataItem in MacGetColumnInfo. Is row a valid wxListCtrl row?") );
3002 // CS should this guard against dataItem = 0 ? , as item is not a pointer if (item) is not appropriate
3005 wxMacListCtrlItem
* listItem
=wx_static_cast(wxMacListCtrlItem
*,dataItem
);
3007 if (!listItem
->HasColumnInfo( column
))
3010 wxListItem
* oldItem
= listItem
->GetColumnInfo( column
);
3014 long mask
= item
.GetMask();
3016 // by default, get everything for backwards compatibility
3019 if ( mask
& wxLIST_MASK_TEXT
)
3020 item
.SetText(oldItem
->GetText());
3021 if ( mask
& wxLIST_MASK_IMAGE
)
3022 item
.SetImage(oldItem
->GetImage());
3023 if ( mask
& wxLIST_MASK_DATA
)
3024 item
.SetData(oldItem
->GetData());
3025 if ( mask
& wxLIST_MASK_STATE
)
3026 item
.SetState(oldItem
->GetState());
3027 if ( mask
& wxLIST_MASK_WIDTH
)
3028 item
.SetWidth(oldItem
->GetWidth());
3029 if ( mask
& wxLIST_MASK_FORMAT
)
3030 item
.SetAlign(oldItem
->GetAlign());
3032 item
.SetTextColour(oldItem
->GetTextColour());
3033 item
.SetBackgroundColour(oldItem
->GetBackgroundColour());
3034 item
.SetFont(oldItem
->GetFont());
3039 void wxMacDataBrowserListCtrlControl::MacInsertItem( unsigned int n
, wxListItem
* item
)
3041 wxMacDataItemBrowserControl::MacInsert(n
, item
->GetText());
3042 MacSetColumnInfo(n
, 0, item
);
3045 wxMacDataItem
* wxMacDataBrowserListCtrlControl::CreateItem()
3047 return new wxMacListCtrlItem();
3050 wxMacListCtrlItem::wxMacListCtrlItem()
3052 m_rowItems
= wxListItemList();
3055 int wxMacListCtrlItem::GetColumnImageValue( unsigned int column
)
3057 if ( HasColumnInfo(column
) )
3058 return GetColumnInfo(column
)->GetImage();
3063 void wxMacListCtrlItem::SetColumnImageValue( unsigned int column
, int imageIndex
)
3065 if ( HasColumnInfo(column
) )
3066 GetColumnInfo(column
)->SetImage(imageIndex
);
3069 wxString
wxMacListCtrlItem::GetColumnTextValue( unsigned int column
)
3074 if ( HasColumnInfo(column
) )
3075 return GetColumnInfo(column
)->GetText();
3077 return wxEmptyString
;
3080 void wxMacListCtrlItem::SetColumnTextValue( unsigned int column
, const wxString
& text
)
3082 if ( HasColumnInfo(column
) )
3083 GetColumnInfo(column
)->SetText(text
);
3085 // for compatibility with superclass APIs
3090 wxListItem
* wxMacListCtrlItem::GetColumnInfo( unsigned int column
)
3092 wxASSERT_MSG( HasColumnInfo(column
), _T("invalid column index in wxMacListCtrlItem") );
3093 return m_rowItems
[column
];
3096 bool wxMacListCtrlItem::HasColumnInfo( unsigned int column
)
3098 return !(m_rowItems
.find( column
) == m_rowItems
.end());
3101 void wxMacListCtrlItem::SetColumnInfo( unsigned int column
, wxListItem
* item
)
3104 if ( !HasColumnInfo(column
) )
3106 wxListItem
* listItem
= new wxListItem(*item
);
3107 m_rowItems
[column
] = listItem
;
3111 wxListItem
* listItem
= GetColumnInfo( column
);
3112 long mask
= item
->GetMask();
3113 if (mask
& wxLIST_MASK_TEXT
)
3114 listItem
->SetText(item
->GetText());
3115 if (mask
& wxLIST_MASK_DATA
)
3116 listItem
->SetData(item
->GetData());
3117 if (mask
& wxLIST_MASK_IMAGE
)
3118 listItem
->SetImage(item
->GetImage());
3119 if (mask
& wxLIST_MASK_STATE
)
3120 listItem
->SetState(item
->GetState());
3121 if (mask
& wxLIST_MASK_FORMAT
)
3122 listItem
->SetAlign(item
->GetAlign());
3123 if (mask
& wxLIST_MASK_WIDTH
)
3124 listItem
->SetWidth(item
->GetWidth());
3126 if ( item
->HasAttributes() )
3128 if ( listItem
->HasAttributes() )
3129 listItem
->GetAttributes()->AssignFrom(*item
->GetAttributes());
3132 listItem
->SetTextColour(item
->GetTextColour());
3133 listItem
->SetBackgroundColour(item
->GetBackgroundColour());
3134 listItem
->SetFont(item
->GetFont());
3140 #endif // wxUSE_LISTCTRL