1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/osx/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"
33 #include "wx/settings.h"
36 #include "wx/osx/uma.h"
38 #include "wx/imaglist.h"
39 #include "wx/sysopt.h"
42 #include "wx/hashmap.h"
44 #if wxUSE_EXTENDED_RTTI
45 WX_DEFINE_FLAGS( wxListCtrlStyle
)
47 wxBEGIN_FLAGS( wxListCtrlStyle
)
48 // new style border flags, we put them first to
49 // use them for streaming out
50 wxFLAGS_MEMBER(wxBORDER_SIMPLE
)
51 wxFLAGS_MEMBER(wxBORDER_SUNKEN
)
52 wxFLAGS_MEMBER(wxBORDER_DOUBLE
)
53 wxFLAGS_MEMBER(wxBORDER_RAISED
)
54 wxFLAGS_MEMBER(wxBORDER_STATIC
)
55 wxFLAGS_MEMBER(wxBORDER_NONE
)
57 // old style border flags
58 wxFLAGS_MEMBER(wxSIMPLE_BORDER
)
59 wxFLAGS_MEMBER(wxSUNKEN_BORDER
)
60 wxFLAGS_MEMBER(wxDOUBLE_BORDER
)
61 wxFLAGS_MEMBER(wxRAISED_BORDER
)
62 wxFLAGS_MEMBER(wxSTATIC_BORDER
)
63 wxFLAGS_MEMBER(wxBORDER
)
65 // standard window styles
66 wxFLAGS_MEMBER(wxTAB_TRAVERSAL
)
67 wxFLAGS_MEMBER(wxCLIP_CHILDREN
)
68 wxFLAGS_MEMBER(wxTRANSPARENT_WINDOW
)
69 wxFLAGS_MEMBER(wxWANTS_CHARS
)
70 wxFLAGS_MEMBER(wxFULL_REPAINT_ON_RESIZE
)
71 wxFLAGS_MEMBER(wxALWAYS_SHOW_SB
)
72 wxFLAGS_MEMBER(wxVSCROLL
)
73 wxFLAGS_MEMBER(wxHSCROLL
)
75 wxFLAGS_MEMBER(wxLC_LIST
)
76 wxFLAGS_MEMBER(wxLC_REPORT
)
77 wxFLAGS_MEMBER(wxLC_ICON
)
78 wxFLAGS_MEMBER(wxLC_SMALL_ICON
)
79 wxFLAGS_MEMBER(wxLC_ALIGN_TOP
)
80 wxFLAGS_MEMBER(wxLC_ALIGN_LEFT
)
81 wxFLAGS_MEMBER(wxLC_AUTOARRANGE
)
82 wxFLAGS_MEMBER(wxLC_USER_TEXT
)
83 wxFLAGS_MEMBER(wxLC_EDIT_LABELS
)
84 wxFLAGS_MEMBER(wxLC_NO_HEADER
)
85 wxFLAGS_MEMBER(wxLC_SINGLE_SEL
)
86 wxFLAGS_MEMBER(wxLC_SORT_ASCENDING
)
87 wxFLAGS_MEMBER(wxLC_SORT_DESCENDING
)
88 wxFLAGS_MEMBER(wxLC_VIRTUAL
)
90 wxEND_FLAGS( wxListCtrlStyle
)
92 IMPLEMENT_DYNAMIC_CLASS_XTI(wxListCtrl
, wxControl
,"wx/listctrl.h")
94 wxBEGIN_PROPERTIES_TABLE(wxListCtrl
)
95 wxEVENT_PROPERTY( TextUpdated
, wxEVT_COMMAND_TEXT_UPDATED
, wxCommandEvent
)
97 wxPROPERTY_FLAGS( WindowStyle
, wxListCtrlStyle
, long , SetWindowStyleFlag
, GetWindowStyleFlag
, EMPTY_MACROVALUE
, 0 /*flags*/ , wxT("Helpstring") , wxT("group")) // style
98 wxEND_PROPERTIES_TABLE()
100 wxBEGIN_HANDLERS_TABLE(wxListCtrl
)
101 wxEND_HANDLERS_TABLE()
103 wxCONSTRUCTOR_5( wxListCtrl
, wxWindow
* , Parent
, wxWindowID
, Id
, wxPoint
, Position
, wxSize
, Size
, long , WindowStyle
)
106 TODO : Expose more information of a list's layout etc. via appropriate objects (¢ la NotebookPageInfo)
109 IMPLEMENT_DYNAMIC_CLASS(wxListCtrl
, wxControl
)
112 IMPLEMENT_DYNAMIC_CLASS(wxListView
, wxListCtrl
)
113 IMPLEMENT_DYNAMIC_CLASS(wxListItem
, wxObject
)
115 IMPLEMENT_DYNAMIC_CLASS(wxListEvent
, wxNotifyEvent
)
117 WX_DECLARE_HASH_MAP( int, wxListItem
*, wxIntegerHash
, wxIntegerEqual
, wxListItemList
);
119 #include "wx/listimpl.cpp"
120 WX_DEFINE_LIST(wxColumnList
)
122 // so we can check for column clicks
123 static const EventTypeSpec eventList
[] =
125 { kEventClassControl
, kEventControlHit
},
126 { kEventClassControl
, kEventControlDraw
}
129 static pascal OSStatus
wxMacListCtrlEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
131 OSStatus result
= eventNotHandledErr
;
133 wxMacCarbonEvent
cEvent( event
) ;
135 ControlRef controlRef
;
136 cEvent
.GetParameter( kEventParamDirectObject
, &controlRef
) ;
138 wxListCtrl
*window
= (wxListCtrl
*) data
;
139 wxListEvent
le( wxEVT_COMMAND_LIST_COL_CLICK
, window
->GetId() );
140 le
.SetEventObject( window
);
142 switch ( GetEventKind( event
) )
144 // check if the column was clicked on and fire an event if so
145 case kEventControlHit
:
147 ControlPartCode result
= cEvent
.GetParameter
<ControlPartCode
>(kEventParamControlPart
, typeControlPartCode
) ;
148 if (result
== kControlButtonPart
){
149 DataBrowserPropertyID col
;
150 GetDataBrowserSortProperty(controlRef
, &col
);
151 int column
= col
- kMinColumnId
;
153 // FIXME: we can't use the sort property for virtual listctrls
154 // so we need to find a better way to determine which column was clicked...
155 if (!window
->IsVirtual())
156 window
->HandleWindowEvent( le
);
158 result
= CallNextEventHandler(handler
, event
);
161 case kEventControlDraw
:
163 CGContextRef context
= cEvent
.GetParameter
<CGContextRef
>(kEventParamCGContextRef
, typeCGContextRef
) ;
164 window
->MacSetDrawingContext(context
);
165 result
= CallNextEventHandler(handler
, event
);
166 window
->MacSetDrawingContext(NULL
);
177 DEFINE_ONE_SHOT_HANDLER_GETTER( wxMacListCtrlEventHandler
)
179 class wxMacListCtrlItem
: public wxMacDataItem
184 virtual void Notification(wxMacDataItemBrowserControl
*owner
,
185 DataBrowserItemNotification message
,
186 DataBrowserItemDataRef itemData
) const;
188 virtual void SetColumnInfo( unsigned int column
, wxListItem
* item
);
189 virtual wxListItem
* GetColumnInfo( unsigned int column
);
190 virtual bool HasColumnInfo( unsigned int column
);
192 virtual void SetColumnTextValue( unsigned int column
, const wxString
& text
);
193 virtual wxString
GetColumnTextValue( unsigned int column
);
195 virtual int GetColumnImageValue( unsigned int column
);
196 virtual void SetColumnImageValue( unsigned int column
, int imageIndex
);
198 virtual ~wxMacListCtrlItem();
200 wxListItemList m_rowItems
;
203 DataBrowserDrawItemUPP gDataBrowserDrawItemUPP
= NULL
;
204 //DataBrowserEditItemUPP gDataBrowserEditItemUPP = NULL;
205 DataBrowserHitTestUPP gDataBrowserHitTestUPP
= NULL
;
207 // TODO: Make a better name!!
208 class wxMacDataBrowserListCtrlControl
: public wxMacDataItemBrowserControl
211 wxMacDataBrowserListCtrlControl( wxWindow
*peer
, const wxPoint
& pos
, const wxSize
& size
, long style
);
212 wxMacDataBrowserListCtrlControl() {}
213 virtual ~wxMacDataBrowserListCtrlControl();
215 // create a list item (can be a subclass of wxMacListBoxItem)
217 virtual void MacInsertItem( unsigned int n
, wxListItem
* item
);
218 virtual void MacSetColumnInfo( unsigned int row
, unsigned int column
, wxListItem
* item
);
219 virtual void MacGetColumnInfo( unsigned int row
, unsigned int column
, wxListItem
& item
);
220 virtual void UpdateState(wxMacDataItem
* dataItem
, wxListItem
* item
);
221 int GetFlags() { return m_flags
; }
224 // we need to override to provide specialized handling for virtual wxListCtrls
225 virtual OSStatus
GetSetItemData(DataBrowserItemID itemID
,
226 DataBrowserPropertyID property
,
227 DataBrowserItemDataRef itemData
,
228 Boolean changeValue
);
230 virtual void ItemNotification(
231 DataBrowserItemID itemID
,
232 DataBrowserItemNotification message
,
233 DataBrowserItemDataRef itemData
);
235 virtual Boolean
CompareItems(DataBrowserItemID itemOneID
,
236 DataBrowserItemID itemTwoID
,
237 DataBrowserPropertyID sortProperty
);
239 static pascal void DataBrowserDrawItemProc(ControlRef browser
,
240 DataBrowserItemID item
,
241 DataBrowserPropertyID property
,
242 DataBrowserItemState itemState
,
245 Boolean colorDevice
);
247 virtual void DrawItem(DataBrowserItemID itemID
,
248 DataBrowserPropertyID property
,
249 DataBrowserItemState itemState
,
250 const Rect
*itemRect
,
252 Boolean colorDevice
);
254 static pascal Boolean
DataBrowserEditTextProc(ControlRef browser
,
255 DataBrowserItemID item
,
256 DataBrowserPropertyID property
,
257 CFStringRef theString
,
258 Rect
*maxEditTextRect
,
259 Boolean
*shrinkToFit
);
261 static pascal Boolean
DataBrowserHitTestProc(ControlRef
WXUNUSED(browser
),
262 DataBrowserItemID
WXUNUSED(itemID
),
263 DataBrowserPropertyID
WXUNUSED(property
),
264 const Rect
*WXUNUSED(theRect
),
265 const Rect
*WXUNUSED(mouseRect
)) { return true; }
267 virtual bool ConfirmEditText(DataBrowserItemID item
,
268 DataBrowserPropertyID property
,
269 CFStringRef theString
,
270 Rect
*maxEditTextRect
,
271 Boolean
*shrinkToFit
);
275 wxClientDataType m_clientDataItemsType
;
278 DECLARE_DYNAMIC_CLASS_NO_COPY(wxMacDataBrowserListCtrlControl
)
281 class wxMacListCtrlEventDelegate
: public wxEvtHandler
284 wxMacListCtrlEventDelegate( wxListCtrl
* list
, int id
);
285 virtual bool ProcessEvent( wxEvent
& event
);
292 wxMacListCtrlEventDelegate::wxMacListCtrlEventDelegate( wxListCtrl
* list
, int id
)
298 bool wxMacListCtrlEventDelegate::ProcessEvent( wxEvent
& event
)
300 // even though we use a generic list ctrl underneath, make sure
301 // we present ourselves as wxListCtrl.
302 event
.SetEventObject( m_list
);
305 if ( !event
.IsKindOf( CLASSINFO( wxCommandEvent
) ) )
307 if (m_list
->HandleWindowEvent( event
))
310 return wxEvtHandler::ProcessEvent(event
);
313 //-----------------------------------------------------------------------------
314 // wxListCtrlRenameTimer (internal)
315 //-----------------------------------------------------------------------------
317 class wxListCtrlRenameTimer
: public wxTimer
323 wxListCtrlRenameTimer( wxListCtrl
*owner
);
327 //-----------------------------------------------------------------------------
328 // wxListCtrlTextCtrlWrapper: wraps a wxTextCtrl to make it work for inline editing
329 //-----------------------------------------------------------------------------
331 class wxListCtrlTextCtrlWrapper
: public wxEvtHandler
334 // NB: text must be a valid object but not Create()d yet
335 wxListCtrlTextCtrlWrapper(wxListCtrl
*owner
,
339 wxTextCtrl
*GetText() const { return m_text
; }
341 void AcceptChangesAndFinish();
344 void OnChar( wxKeyEvent
&event
);
345 void OnKeyUp( wxKeyEvent
&event
);
346 void OnKillFocus( wxFocusEvent
&event
);
348 bool AcceptChanges();
354 wxString m_startValue
;
357 bool m_aboutToFinish
;
359 DECLARE_EVENT_TABLE()
362 //-----------------------------------------------------------------------------
363 // wxListCtrlRenameTimer (internal)
364 //-----------------------------------------------------------------------------
366 wxListCtrlRenameTimer::wxListCtrlRenameTimer( wxListCtrl
*owner
)
371 void wxListCtrlRenameTimer::Notify()
373 m_owner
->OnRenameTimer();
376 //-----------------------------------------------------------------------------
377 // wxListCtrlTextCtrlWrapper (internal)
378 //-----------------------------------------------------------------------------
380 BEGIN_EVENT_TABLE(wxListCtrlTextCtrlWrapper
, wxEvtHandler
)
381 EVT_CHAR (wxListCtrlTextCtrlWrapper::OnChar
)
382 EVT_KEY_UP (wxListCtrlTextCtrlWrapper::OnKeyUp
)
383 EVT_KILL_FOCUS (wxListCtrlTextCtrlWrapper::OnKillFocus
)
386 wxListCtrlTextCtrlWrapper::wxListCtrlTextCtrlWrapper(wxListCtrl
*owner
,
389 : m_startValue(owner
->GetItemText(itemEdit
)),
390 m_itemEdited(itemEdit
)
395 m_aboutToFinish
= false;
399 owner
->GetItemRect(itemEdit
, rectLabel
);
401 m_text
->Create(owner
, wxID_ANY
, m_startValue
,
402 wxPoint(rectLabel
.x
+offset
,rectLabel
.y
),
403 wxSize(rectLabel
.width
-offset
,rectLabel
.height
));
406 m_text
->PushEventHandler(this);
409 void wxListCtrlTextCtrlWrapper::Finish()
415 m_text
->RemoveEventHandler(this);
416 m_owner
->FinishEditing(m_text
);
418 wxPendingDelete
.Append( this );
422 bool wxListCtrlTextCtrlWrapper::AcceptChanges()
424 const wxString value
= m_text
->GetValue();
426 if ( value
== m_startValue
)
427 // nothing changed, always accept
430 if ( !m_owner
->OnRenameAccept(m_itemEdited
, value
) )
431 // vetoed by the user
434 // accepted, do rename the item
435 m_owner
->SetItemText(m_itemEdited
, value
);
440 void wxListCtrlTextCtrlWrapper::AcceptChangesAndFinish()
442 m_aboutToFinish
= true;
444 // Notify the owner about the changes
447 // Even if vetoed, close the control (consistent with MSW)
451 void wxListCtrlTextCtrlWrapper::OnChar( wxKeyEvent
&event
)
453 switch ( event
.m_keyCode
)
456 AcceptChangesAndFinish();
460 m_owner
->OnRenameCancelled( m_itemEdited
);
469 void wxListCtrlTextCtrlWrapper::OnKeyUp( wxKeyEvent
&event
)
477 // auto-grow the textctrl:
478 wxSize parentSize
= m_owner
->GetSize();
479 wxPoint myPos
= m_text
->GetPosition();
480 wxSize mySize
= m_text
->GetSize();
482 m_text
->GetTextExtent(m_text
->GetValue() + _T("MM"), &sx
, &sy
);
483 if (myPos
.x
+ sx
> parentSize
.x
)
484 sx
= parentSize
.x
- myPos
.x
;
487 m_text
->SetSize(sx
, wxDefaultCoord
);
492 void wxListCtrlTextCtrlWrapper::OnKillFocus( wxFocusEvent
&event
)
494 if ( !m_finished
&& !m_aboutToFinish
)
496 if ( !AcceptChanges() )
497 m_owner
->OnRenameCancelled( m_itemEdited
);
502 // We must let the native text control handle focus
506 BEGIN_EVENT_TABLE(wxListCtrl
, wxControl
)
507 EVT_LEFT_DOWN(wxListCtrl::OnLeftDown
)
508 EVT_LEFT_DCLICK(wxListCtrl::OnDblClick
)
509 EVT_MIDDLE_DOWN(wxListCtrl::OnMiddleDown
)
510 EVT_RIGHT_DOWN(wxListCtrl::OnRightDown
)
511 EVT_CHAR(wxListCtrl::OnChar
)
514 // ============================================================================
516 // ============================================================================
518 wxMacDataBrowserListCtrlControl
* wxListCtrl::GetListPeer() const
520 return dynamic_cast<wxMacDataBrowserListCtrlControl
*> ( GetPeer() );
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::OnDblClick(wxMouseEvent
& event
)
620 #if wxABI_VERSION >= 20801
621 void wxListCtrl::OnRightDown(wxMouseEvent
& event
)
624 FireMouseEvent(wxEVT_COMMAND_LIST_ITEM_RIGHT_CLICK
, event
.GetPosition());
628 void wxListCtrl::OnMiddleDown(wxMouseEvent
& event
)
631 FireMouseEvent(wxEVT_COMMAND_LIST_ITEM_MIDDLE_CLICK
, event
.GetPosition());
635 void wxListCtrl::FireMouseEvent(wxEventType eventType
, wxPoint position
)
637 wxListEvent
le( eventType
, GetId() );
638 le
.SetEventObject(this);
639 le
.m_pointDrag
= position
;
643 long item
= HitTest(position
, flags
);
644 if (flags
& wxLIST_HITTEST_ONITEM
)
646 le
.m_itemIndex
= item
;
647 le
.m_item
.m_itemId
= item
;
649 HandleWindowEvent(le
);
653 void wxListCtrl::OnChar(wxKeyEvent
& event
)
659 wxListEvent
le( wxEVT_COMMAND_LIST_KEY_DOWN
, GetId() );
660 le
.SetEventObject(this);
661 le
.m_code
= event
.GetKeyCode();
666 // if m_current isn't set, check if there's been a selection
667 // made before continuing
668 m_current
= GetNextItem(-1, wxLIST_NEXT_BELOW
, wxLIST_STATE_SELECTED
);
671 // We need to determine m_current ourselves when navigation keys
672 // are used. Note that PAGEUP and PAGEDOWN do not alter the current
673 // item on native Mac ListCtrl, so we only handle up and down keys.
674 switch ( event
.GetKeyCode() )
685 if ( m_current
< GetItemCount() - 1 )
688 m_current
= GetItemCount() - 1;
695 le
.m_itemIndex
= m_current
;
696 le
.m_item
.m_itemId
= m_current
;
698 HandleWindowEvent(le
);
705 bool wxListCtrl::Create(wxWindow
*parent
,
710 const wxValidator
& validator
,
711 const wxString
& name
)
714 // for now, we'll always use the generic list control for ICON and LIST views,
715 // because they dynamically change the number of columns on resize.
716 // Also, allow the user to set it to use the list ctrl as well.
717 if ( (wxSystemOptions::HasOption( wxMAC_ALWAYS_USE_GENERIC_LISTCTRL
)
718 && (wxSystemOptions::GetOptionInt( wxMAC_ALWAYS_USE_GENERIC_LISTCTRL
) == 1)) ||
719 (style
& wxLC_ICON
) || (style
& wxLC_SMALL_ICON
) || (style
& wxLC_LIST
) )
721 m_macIsUserPane
= true;
723 long paneStyle
= style
;
724 paneStyle
&= ~wxSIMPLE_BORDER
;
725 paneStyle
&= ~wxDOUBLE_BORDER
;
726 paneStyle
&= ~wxSUNKEN_BORDER
;
727 paneStyle
&= ~wxRAISED_BORDER
;
728 paneStyle
&= ~wxSTATIC_BORDER
;
729 if ( !wxWindow::Create(parent
, id
, pos
, size
, paneStyle
| wxNO_BORDER
, name
) )
732 // since the generic control is a child, make sure we position it at 0, 0
733 m_genericImpl
= new wxGenericListCtrlHook(this, id
, wxPoint(0, 0), size
, style
, validator
, name
);
734 m_genericImpl
->PushEventHandler( new wxMacListCtrlEventDelegate( this, GetId() ) );
740 m_macIsUserPane
= false;
741 if ( !wxWindow::Create(parent
, id
, pos
, size
, style
& ~(wxHSCROLL
| wxVSCROLL
), name
) )
743 m_dbImpl
= new wxMacDataBrowserListCtrlControl( this, pos
, size
, style
);
746 MacPostControlCreate( pos
, size
);
748 InstallControlEventHandler( m_peer
->GetControlRef() , GetwxMacListCtrlEventHandlerUPP(),
749 GetEventTypeCount(eventList
), eventList
, this,
750 (EventHandlerRef
*)&m_macListCtrlEventHandler
);
756 wxListCtrl::~wxListCtrl()
760 m_genericImpl
->PopEventHandler(/* deleteHandler = */ true);
763 if (m_ownsImageListNormal
)
764 delete m_imageListNormal
;
765 if (m_ownsImageListSmall
)
766 delete m_imageListSmall
;
767 if (m_ownsImageListState
)
768 delete m_imageListState
;
770 delete m_renameTimer
;
772 WX_CLEAR_LIST(wxColumnList
, m_colsInfo
);
777 wxListCtrl::GetClassDefaultAttributes(wxWindowVariant
WXUNUSED(variant
))
779 wxVisualAttributes attr
;
781 attr
.colFg
= wxSystemSettings::GetColour( wxSYS_COLOUR_WINDOWTEXT
);
782 attr
.colBg
= wxSystemSettings::GetColour( wxSYS_COLOUR_LISTBOX
);
783 attr
.font
.MacCreateFromThemeFont(kThemeViewsFont
);
788 // ----------------------------------------------------------------------------
789 // set/get/change style
790 // ----------------------------------------------------------------------------
792 // Add or remove a single window style
793 void wxListCtrl::SetSingleStyle(long style
, bool add
)
795 long flag
= GetWindowStyleFlag();
797 // Get rid of conflicting styles
800 if ( style
& wxLC_MASK_TYPE
)
801 flag
= flag
& ~wxLC_MASK_TYPE
;
802 if ( style
& wxLC_MASK_ALIGN
)
803 flag
= flag
& ~wxLC_MASK_ALIGN
;
804 if ( style
& wxLC_MASK_SORT
)
805 flag
= flag
& ~wxLC_MASK_SORT
;
813 SetWindowStyleFlag(flag
);
816 // Set the whole window style
817 void wxListCtrl::SetWindowStyleFlag(long flag
)
819 if ( flag
!= m_windowStyle
)
821 m_windowStyle
= flag
;
825 m_genericImpl
->SetWindowStyleFlag(flag
);
832 void wxListCtrl::DoSetSize( int x
, int y
, int width
, int height
, int sizeFlags
)
834 wxControl::DoSetSize(x
, y
, width
, height
, sizeFlags
);
837 m_genericImpl
->SetSize(0, 0, width
, height
, sizeFlags
);
839 // determine if we need a horizontal scrollbar, and add it if so
843 for (int column
= 0; column
< GetColumnCount(); column
++)
845 totalWidth
+= m_dbImpl
->GetColumnWidth( column
);
848 if ( !(m_dbImpl
->GetFlags() & wxHSCROLL
) )
850 Boolean vertScrollBar
;
851 GetDataBrowserHasScrollBars( m_dbImpl
->GetControlRef(), NULL
, &vertScrollBar
);
852 if (totalWidth
> width
)
853 SetDataBrowserHasScrollBars( m_dbImpl
->GetControlRef(), true, vertScrollBar
);
855 SetDataBrowserHasScrollBars( m_dbImpl
->GetControlRef(), false, vertScrollBar
);
860 wxSize
wxListCtrl::DoGetBestSize() const
862 return wxWindow::DoGetBestSize();
865 bool wxListCtrl::SetFont(const wxFont
& font
)
868 rv
= wxControl::SetFont(font
);
870 rv
= m_genericImpl
->SetFont(font
);
874 bool wxListCtrl::SetForegroundColour(const wxColour
& colour
)
878 rv
= m_genericImpl
->SetForegroundColour(colour
);
880 SetTextColour(colour
);
884 bool wxListCtrl::SetBackgroundColour(const wxColour
& colour
)
888 rv
= m_genericImpl
->SetBackgroundColour(colour
);
894 wxColour
wxListCtrl::GetBackgroundColour() const
897 return m_genericImpl
->GetBackgroundColour();
904 // ----------------------------------------------------------------------------
906 // ----------------------------------------------------------------------------
908 // Gets information about this column
909 bool wxListCtrl::GetColumn(int col
, wxListItem
& item
) const
912 return m_genericImpl
->GetColumn(col
, item
);
918 wxColumnList::compatibility_iterator node
= m_colsInfo
.Item( col
);
919 wxASSERT_MSG( node
, _T("invalid column index in wxMacListCtrlItem") );
920 wxListItem
* column
= node
->GetData();
922 long mask
= column
->GetMask();
923 if (mask
& wxLIST_MASK_TEXT
)
924 item
.SetText(column
->GetText());
925 if (mask
& wxLIST_MASK_DATA
)
926 item
.SetData(column
->GetData());
927 if (mask
& wxLIST_MASK_IMAGE
)
928 item
.SetImage(column
->GetImage());
929 if (mask
& wxLIST_MASK_STATE
)
930 item
.SetState(column
->GetState());
931 if (mask
& wxLIST_MASK_FORMAT
)
932 item
.SetAlign(column
->GetAlign());
933 if (mask
& wxLIST_MASK_WIDTH
)
934 item
.SetWidth(column
->GetWidth());
940 // Sets information about this column
941 bool wxListCtrl::SetColumn(int col
, wxListItem
& item
)
944 return m_genericImpl
->SetColumn(col
, item
);
948 long mask
= item
.GetMask();
949 if ( col
>= (int)m_colsInfo
.GetCount() )
951 wxListItem
* listItem
= new wxListItem(item
);
952 m_colsInfo
.Append( listItem
);
957 GetColumn( col
, listItem
);
959 if (mask
& wxLIST_MASK_TEXT
)
960 listItem
.SetText(item
.GetText());
961 if (mask
& wxLIST_MASK_DATA
)
962 listItem
.SetData(item
.GetData());
963 if (mask
& wxLIST_MASK_IMAGE
)
964 listItem
.SetImage(item
.GetImage());
965 if (mask
& wxLIST_MASK_STATE
)
966 listItem
.SetState(item
.GetState());
967 if (mask
& wxLIST_MASK_FORMAT
)
968 listItem
.SetAlign(item
.GetAlign());
969 if (mask
& wxLIST_MASK_WIDTH
)
970 listItem
.SetWidth(item
.GetWidth());
973 // change the appearance in the databrowser.
974 DataBrowserListViewHeaderDesc columnDesc
;
975 columnDesc
.version
=kDataBrowserListViewLatestHeaderDesc
;
976 verify_noerr( m_dbImpl
->GetHeaderDesc( kMinColumnId
+ col
, &columnDesc
) );
979 if (item.GetMask() & wxLIST_MASK_TEXT)
983 enc = GetFont().GetEncoding();
985 enc = wxLocale::GetSystemEncoding();
986 wxCFStringRef cfTitle;
987 cfTitle.Assign( item.GetText() , enc );
988 if(columnDesc.titleString)
989 CFRelease(columnDesc.titleString);
990 columnDesc.titleString = cfTitle;
994 if (item
.GetMask() & wxLIST_MASK_IMAGE
&& item
.GetImage() != -1 )
996 wxImageList
* imageList
= GetImageList(wxIMAGE_LIST_SMALL
);
997 if (imageList
&& imageList
->GetImageCount() > 0 )
999 wxBitmap bmp
= imageList
->GetBitmap( item
.GetImage() );
1000 IconRef icon
= bmp
.GetIconRef();
1001 columnDesc
.btnContentInfo
.u
.iconRef
= icon
;
1002 columnDesc
.btnContentInfo
.contentType
= kControlContentIconRef
;
1006 verify_noerr( m_dbImpl
->SetHeaderDesc( kMinColumnId
+ col
, &columnDesc
) );
1012 int wxListCtrl::GetColumnCount() const
1015 return m_genericImpl
->GetColumnCount();
1020 m_dbImpl
->GetColumnCount(&count
);
1027 // Gets the column width
1028 int wxListCtrl::GetColumnWidth(int col
) const
1031 return m_genericImpl
->GetColumnWidth(col
);
1035 return m_dbImpl
->GetColumnWidth(col
);
1041 // Sets the column width
1042 bool wxListCtrl::SetColumnWidth(int col
, int width
)
1045 return m_genericImpl
->SetColumnWidth(col
, width
);
1049 if ( width
== wxLIST_AUTOSIZE_USEHEADER
)
1051 width
= 150; // FIXME
1056 for (int column
= 0; column
< GetColumnCount(); column
++)
1059 GetColumn(column
, colInfo
);
1061 colInfo
.SetWidth(width
);
1062 SetColumn(column
, colInfo
);
1064 const int mywidth
= (width
== wxLIST_AUTOSIZE
)
1065 ? CalcColumnAutoWidth(column
) : width
;
1066 m_dbImpl
->SetColumnWidth(column
, mywidth
);
1071 if ( width
== wxLIST_AUTOSIZE
)
1072 width
= CalcColumnAutoWidth(col
);
1075 GetColumn(col
, colInfo
);
1077 colInfo
.SetWidth(width
);
1078 SetColumn(col
, colInfo
);
1079 m_dbImpl
->SetColumnWidth(col
, width
);
1087 // Gets the number of items that can fit vertically in the
1088 // visible area of the list control (list or report view)
1089 // or the total number of items in the list control (icon
1090 // or small icon view)
1091 int wxListCtrl::GetCountPerPage() const
1094 return m_genericImpl
->GetCountPerPage();
1099 m_dbImpl
->GetDefaultRowHeight( &height
);
1101 return GetClientSize().y
/ height
;
1107 // Gets the edit control for editing labels.
1108 wxTextCtrl
* wxListCtrl::GetEditControl() const
1111 return m_genericImpl
->GetEditControl();
1116 // Gets information about the item
1117 bool wxListCtrl::GetItem(wxListItem
& info
) const
1120 return m_genericImpl
->GetItem(info
);
1126 if (info
.m_itemId
>= 0 && info
.m_itemId
< GetItemCount())
1128 m_dbImpl
->MacGetColumnInfo(info
.m_itemId
, info
.m_col
, info
);
1129 if (info
.GetMask() & wxLIST_MASK_STATE
)
1131 DataBrowserItemID id
= (DataBrowserItemID
)m_dbImpl
->GetItemFromLine(info
.m_itemId
);
1132 if (IsDataBrowserItemSelected( m_dbImpl
->GetControlRef(), id
))
1133 info
.SetState(info
.GetState() | wxLIST_STATE_SELECTED
);
1139 if (info
.m_itemId
>= 0 && info
.m_itemId
< GetItemCount())
1141 info
.SetText( OnGetItemText(info
.m_itemId
, info
.m_col
) );
1142 info
.SetImage( OnGetItemColumnImage(info
.m_itemId
, info
.m_col
) );
1143 if (info
.GetMask() & wxLIST_MASK_STATE
)
1145 if (IsDataBrowserItemSelected( m_dbImpl
->GetControlRef(), info
.m_itemId
+1 ))
1146 info
.SetState(info
.GetState() | wxLIST_STATE_SELECTED
);
1149 wxListItemAttr
* attrs
= OnGetItemAttr( info
.m_itemId
);
1152 info
.SetFont( attrs
->GetFont() );
1153 info
.SetBackgroundColour( attrs
->GetBackgroundColour() );
1154 info
.SetTextColour( attrs
->GetTextColour() );
1159 bool success
= true;
1163 // Sets information about the item
1164 bool wxListCtrl::SetItem(wxListItem
& info
)
1167 return m_genericImpl
->SetItem(info
);
1170 m_dbImpl
->MacSetColumnInfo( info
.m_itemId
, info
.m_col
, &info
);
1175 long wxListCtrl::SetItem(long index
, int col
, const wxString
& label
, int imageId
)
1178 return m_genericImpl
->SetItem(index
, col
, label
, imageId
);
1181 info
.m_text
= label
;
1182 info
.m_mask
= wxLIST_MASK_TEXT
;
1183 info
.m_itemId
= index
;
1187 info
.m_image
= imageId
;
1188 info
.m_mask
|= wxLIST_MASK_IMAGE
;
1190 return SetItem(info
);
1194 // Gets the item state
1195 int wxListCtrl::GetItemState(long item
, long stateMask
) const
1198 return m_genericImpl
->GetItemState(item
, stateMask
);
1202 if ( HasFlag(wxLC_VIRTUAL
) )
1204 if (stateMask
== wxLIST_STATE_SELECTED
)
1206 if (IsDataBrowserItemSelected( m_dbImpl
->GetControlRef(), item
+1 ))
1207 return wxLIST_STATE_SELECTED
;
1216 info
.m_mask
= wxLIST_MASK_STATE
;
1217 info
.m_stateMask
= stateMask
;
1218 info
.m_itemId
= item
;
1223 return info
.m_state
;
1230 // Sets the item state
1231 bool wxListCtrl::SetItemState(long item
, long state
, long stateMask
)
1234 return m_genericImpl
->SetItemState(item
, state
, stateMask
);
1238 DataBrowserSetOption option
= kDataBrowserItemsAdd
;
1239 if ( (stateMask
& wxLIST_STATE_SELECTED
) && state
== 0 )
1240 option
= kDataBrowserItemsRemove
;
1244 if ( HasFlag(wxLC_VIRTUAL
) )
1246 wxMacDataItemBrowserSelectionSuppressor
suppressor(m_dbImpl
);
1247 m_dbImpl
->SetSelectedAllItems(option
);
1251 for(int i
= 0; i
< GetItemCount();i
++)
1255 info
.m_mask
= wxLIST_MASK_STATE
;
1256 info
.m_stateMask
= stateMask
;
1257 info
.m_state
= state
;
1264 if ( HasFlag(wxLC_VIRTUAL
) )
1266 long itemID
= item
+1;
1267 bool isSelected
= IsDataBrowserItemSelected(m_dbImpl
->GetControlRef(), (DataBrowserItemID
)itemID
);
1268 bool isSelectedState
= (state
== wxLIST_STATE_SELECTED
);
1270 // toggle the selection state if wxListInfo state and actual state don't match.
1271 if ( (stateMask
& wxLIST_STATE_SELECTED
) && isSelected
!= isSelectedState
)
1273 SetDataBrowserSelectedItems(m_dbImpl
->GetControlRef(), 1, (DataBrowserItemID
*)&itemID
, option
);
1279 info
.m_itemId
= item
;
1280 info
.m_mask
= wxLIST_MASK_STATE
;
1281 info
.m_stateMask
= stateMask
;
1282 info
.m_state
= state
;
1283 return SetItem(info
);
1290 // Sets the item image
1291 bool wxListCtrl::SetItemImage(long item
, int image
, int WXUNUSED(selImage
))
1293 return SetItemColumnImage(item
, 0, image
);
1296 // Sets the item image
1297 bool wxListCtrl::SetItemColumnImage(long item
, long column
, int image
)
1300 return m_genericImpl
->SetItemColumnImage(item
, column
, image
);
1304 info
.m_mask
= wxLIST_MASK_IMAGE
;
1305 info
.m_image
= image
;
1306 info
.m_itemId
= item
;
1307 info
.m_col
= column
;
1309 return SetItem(info
);
1312 // Gets the item text
1313 wxString
wxListCtrl::GetItemText(long item
) const
1316 return m_genericImpl
->GetItemText(item
);
1320 info
.m_mask
= wxLIST_MASK_TEXT
;
1321 info
.m_itemId
= item
;
1324 return wxEmptyString
;
1328 // Sets the item text
1329 void wxListCtrl::SetItemText(long item
, const wxString
& str
)
1332 return m_genericImpl
->SetItemText(item
, str
);
1336 info
.m_mask
= wxLIST_MASK_TEXT
;
1337 info
.m_itemId
= item
;
1343 // Gets the item data
1344 long wxListCtrl::GetItemData(long item
) const
1347 return m_genericImpl
->GetItemData(item
);
1351 info
.m_mask
= wxLIST_MASK_DATA
;
1352 info
.m_itemId
= item
;
1359 // Sets the item data
1360 bool wxListCtrl::SetItemPtrData(long item
, wxUIntPtr data
)
1363 return m_genericImpl
->SetItemData(item
, data
);
1367 info
.m_mask
= wxLIST_MASK_DATA
;
1368 info
.m_itemId
= item
;
1371 return SetItem(info
);
1374 wxRect
wxListCtrl::GetViewRect() const
1376 wxASSERT_MSG( !HasFlag(wxLC_REPORT
| wxLC_LIST
),
1377 _T("wxListCtrl::GetViewRect() only works in icon mode") );
1380 return m_genericImpl
->GetViewRect();
1386 // Gets the item rectangle
1387 bool wxListCtrl::GetItemRect(long item
, wxRect
& rect
, int code
) const
1390 return m_genericImpl
->GetItemRect(item
, rect
, code
);
1395 DataBrowserItemID id
;
1396 DataBrowserPropertyID col
= kMinColumnId
;
1398 DataBrowserPropertyPart part
= kDataBrowserPropertyEnclosingPart
;
1399 if ( code
== wxLIST_RECT_LABEL
)
1400 part
= kDataBrowserPropertyTextPart
;
1401 else if ( code
== wxLIST_RECT_ICON
)
1402 part
= kDataBrowserPropertyIconPart
;
1404 if ( !(GetWindowStyleFlag() & wxLC_VIRTUAL
) )
1406 wxMacDataItem
* thisItem
= m_dbImpl
->GetItemFromLine(item
);
1407 id
= (DataBrowserItemID
) thisItem
;
1412 GetDataBrowserItemPartBounds( m_dbImpl
->GetControlRef(), id
, col
, part
, &bounds
);
1414 rect
.x
= bounds
.left
;
1415 rect
.y
= bounds
.top
;
1416 rect
.width
= bounds
.right
- bounds
.left
; //GetClientSize().x; // we need the width of the whole row, not just the item.
1417 rect
.height
= bounds
.bottom
- bounds
.top
;
1418 //fprintf("id = %d, bounds = %d, %d, %d, %d\n", id, rect.x, rect.y, rect.width, rect.height);
1423 // Gets the item position
1424 bool wxListCtrl::GetItemPosition(long item
, wxPoint
& pos
) const
1427 return m_genericImpl
->GetItemPosition(item
, pos
);
1429 bool success
= false;
1434 GetItemRect(item
, itemRect
);
1435 pos
= itemRect
.GetPosition();
1442 // Sets the item position.
1443 bool wxListCtrl::SetItemPosition(long item
, const wxPoint
& pos
)
1446 return m_genericImpl
->SetItemPosition(item
, pos
);
1451 // Gets the number of items in the list control
1452 int wxListCtrl::GetItemCount() const
1455 return m_genericImpl
->GetItemCount();
1458 return m_dbImpl
->MacGetCount();
1463 void wxListCtrl::SetItemSpacing( int spacing
, bool isSmall
)
1466 m_genericImpl
->SetItemSpacing(spacing
, isSmall
);
1469 wxSize
wxListCtrl::GetItemSpacing() const
1472 return m_genericImpl
->GetItemSpacing();
1474 return wxSize(0, 0);
1477 void wxListCtrl::SetItemTextColour( long item
, const wxColour
&col
)
1481 m_genericImpl
->SetItemTextColour(item
, col
);
1486 info
.m_itemId
= item
;
1487 info
.SetTextColour( col
);
1491 wxColour
wxListCtrl::GetItemTextColour( long item
) const
1494 return m_genericImpl
->GetItemTextColour(item
);
1500 return info
.GetTextColour();
1502 return wxNullColour
;
1505 void wxListCtrl::SetItemBackgroundColour( long item
, const wxColour
&col
)
1509 m_genericImpl
->SetItemBackgroundColour(item
, col
);
1514 info
.m_itemId
= item
;
1515 info
.SetBackgroundColour( col
);
1519 wxColour
wxListCtrl::GetItemBackgroundColour( long item
) const
1522 return m_genericImpl
->GetItemBackgroundColour(item
);
1528 return info
.GetBackgroundColour();
1530 return wxNullColour
;
1533 void wxListCtrl::SetItemFont( long item
, const wxFont
&f
)
1537 m_genericImpl
->SetItemFont(item
, f
);
1542 info
.m_itemId
= item
;
1547 wxFont
wxListCtrl::GetItemFont( long item
) const
1550 return m_genericImpl
->GetItemFont(item
);
1556 return info
.GetFont();
1562 // Gets the number of selected items in the list control
1563 int wxListCtrl::GetSelectedItemCount() const
1566 return m_genericImpl
->GetSelectedItemCount();
1569 return m_dbImpl
->GetSelectedItemCount(NULL
, true);
1574 // Gets the text colour of the listview
1575 wxColour
wxListCtrl::GetTextColour() const
1578 return m_genericImpl
->GetTextColour();
1580 // TODO: we need owner drawn list items to customize text color.
1584 return wxNullColour
;
1587 // Sets the text colour of the listview
1588 void wxListCtrl::SetTextColour(const wxColour
& col
)
1592 m_genericImpl
->SetTextColour(col
);
1600 // Gets the index of the topmost visible item when in
1601 // list or report view
1602 long wxListCtrl::GetTopItem() const
1605 return m_genericImpl
->GetTopItem();
1610 long item
= HitTest( wxPoint(1, 1), flags
);
1611 if (flags
== wxLIST_HITTEST_ONITEM
)
1618 // Searches for an item, starting from 'item'.
1619 // 'geometry' is one of
1620 // wxLIST_NEXT_ABOVE/ALL/BELOW/LEFT/RIGHT.
1621 // 'state' is a state bit flag, one or more of
1622 // wxLIST_STATE_DROPHILITED/FOCUSED/SELECTED/CUT.
1623 // item can be -1 to find the first item that matches the
1625 // Returns the item or -1 if unsuccessful.
1626 long wxListCtrl::GetNextItem(long item
, int geom
, int state
) const
1629 return m_genericImpl
->GetNextItem(item
, geom
, state
);
1631 // TODO: implement all geometry and state options?
1634 if ( geom
== wxLIST_NEXT_ALL
|| geom
== wxLIST_NEXT_BELOW
)
1636 long count
= m_dbImpl
->MacGetCount() ;
1637 for ( long line
= item
+ 1 ; line
< count
; line
++ )
1639 DataBrowserItemID id
= line
+ 1;
1641 id
= (DataBrowserItemID
)m_dbImpl
->GetItemFromLine(line
);
1643 if ( (state
== wxLIST_STATE_DONTCARE
) )
1646 if ( (state
& wxLIST_STATE_SELECTED
) && IsDataBrowserItemSelected(m_dbImpl
->GetControlRef(), id
) )
1651 if ( geom
== wxLIST_NEXT_ABOVE
)
1655 item2
= m_dbImpl
->MacGetCount();
1657 for ( long line
= item2
- 1 ; line
>= 0; line
-- )
1659 DataBrowserItemID id
= line
+ 1;
1661 id
= (DataBrowserItemID
)m_dbImpl
->GetItemFromLine(line
);
1663 if ( (state
== wxLIST_STATE_DONTCARE
) )
1666 if ( (state
& wxLIST_STATE_SELECTED
) && IsDataBrowserItemSelected(m_dbImpl
->GetControlRef(), id
) )
1676 wxImageList
*wxListCtrl::GetImageList(int which
) const
1679 return m_genericImpl
->GetImageList(which
);
1681 if ( which
== wxIMAGE_LIST_NORMAL
)
1683 return m_imageListNormal
;
1685 else if ( which
== wxIMAGE_LIST_SMALL
)
1687 return m_imageListSmall
;
1689 else if ( which
== wxIMAGE_LIST_STATE
)
1691 return m_imageListState
;
1696 void wxListCtrl::SetImageList(wxImageList
*imageList
, int which
)
1700 m_genericImpl
->SetImageList(imageList
, which
);
1704 if ( which
== wxIMAGE_LIST_NORMAL
)
1706 if (m_ownsImageListNormal
) delete m_imageListNormal
;
1707 m_imageListNormal
= imageList
;
1708 m_ownsImageListNormal
= false;
1710 else if ( which
== wxIMAGE_LIST_SMALL
)
1712 if (m_ownsImageListSmall
) delete m_imageListSmall
;
1713 m_imageListSmall
= imageList
;
1714 m_ownsImageListSmall
= false;
1716 else if ( which
== wxIMAGE_LIST_STATE
)
1718 if (m_ownsImageListState
) delete m_imageListState
;
1719 m_imageListState
= imageList
;
1720 m_ownsImageListState
= false;
1724 void wxListCtrl::AssignImageList(wxImageList
*imageList
, int which
)
1728 m_genericImpl
->AssignImageList(imageList
, which
);
1732 SetImageList(imageList
, which
);
1733 if ( which
== wxIMAGE_LIST_NORMAL
)
1734 m_ownsImageListNormal
= true;
1735 else if ( which
== wxIMAGE_LIST_SMALL
)
1736 m_ownsImageListSmall
= true;
1737 else if ( which
== wxIMAGE_LIST_STATE
)
1738 m_ownsImageListState
= true;
1741 // ----------------------------------------------------------------------------
1743 // ----------------------------------------------------------------------------
1745 // Arranges the items
1746 bool wxListCtrl::Arrange(int flag
)
1749 return m_genericImpl
->Arrange(flag
);
1754 bool wxListCtrl::DeleteItem(long item
)
1757 return m_genericImpl
->DeleteItem(item
);
1761 m_dbImpl
->MacDelete(item
);
1762 wxListEvent
event( wxEVT_COMMAND_LIST_DELETE_ITEM
, GetId() );
1763 event
.SetEventObject( this );
1764 event
.m_itemIndex
= item
;
1765 HandleWindowEvent( event
);
1771 // Deletes all items
1772 bool wxListCtrl::DeleteAllItems()
1775 return m_genericImpl
->DeleteAllItems();
1779 m_dbImpl
->MacClear();
1780 wxListEvent
event( wxEVT_COMMAND_LIST_DELETE_ALL_ITEMS
, GetId() );
1781 event
.SetEventObject( this );
1782 HandleWindowEvent( event
);
1787 // Deletes all items
1788 bool wxListCtrl::DeleteAllColumns()
1791 return m_genericImpl
->DeleteAllColumns();
1796 m_dbImpl
->GetColumnCount(&cols
);
1797 for (UInt32 col
= 0; col
< cols
; col
++)
1807 bool wxListCtrl::DeleteColumn(int col
)
1810 return m_genericImpl
->DeleteColumn(col
);
1814 OSStatus err
= m_dbImpl
->RemoveColumn(col
);
1815 return err
== noErr
;
1821 // Clears items, and columns if there are any.
1822 void wxListCtrl::ClearAll()
1826 m_genericImpl
->ClearAll();
1837 wxTextCtrl
* wxListCtrl::EditLabel(long item
, wxClassInfo
* textControlClass
)
1840 return m_genericImpl
->EditLabel(item
, textControlClass
);
1844 wxCHECK_MSG( (item
>= 0) && ((long)item
< GetItemCount()), NULL
,
1845 wxT("wrong index in wxListCtrl::EditLabel()") );
1847 wxASSERT_MSG( textControlClass
->IsKindOf(CLASSINFO(wxTextCtrl
)),
1848 wxT("EditLabel() needs a text control") );
1850 wxListEvent
le( wxEVT_COMMAND_LIST_BEGIN_LABEL_EDIT
, GetParent()->GetId() );
1851 le
.SetEventObject( this );
1852 le
.m_itemIndex
= item
;
1854 GetItem( le
.m_item
);
1856 if ( GetParent()->HandleWindowEvent( le
) && !le
.IsAllowed() )
1858 // vetoed by user code
1862 wxTextCtrl
* const text
= (wxTextCtrl
*)textControlClass
->CreateObject();
1863 m_textctrlWrapper
= new wxListCtrlTextCtrlWrapper(this, text
, item
);
1864 return m_textctrlWrapper
->GetText();
1869 // End label editing, optionally cancelling the edit
1870 bool wxListCtrl::EndEditLabel(bool WXUNUSED(cancel
))
1872 // TODO: generic impl. doesn't have this method - is it needed for us?
1874 return true; // m_genericImpl->EndEditLabel(cancel);
1877 verify_noerr( SetDataBrowserEditItem(m_dbImpl
->GetControlRef(), kDataBrowserNoItem
, kMinColumnId
) );
1881 // Ensures this item is visible
1882 bool wxListCtrl::EnsureVisible(long item
)
1885 return m_genericImpl
->EnsureVisible(item
);
1889 wxMacDataItem
* dataItem
= m_dbImpl
->GetItemFromLine(item
);
1890 m_dbImpl
->RevealItem(dataItem
, kDataBrowserRevealWithoutSelecting
);
1896 // Find an item whose label matches this string, starting from the item after 'start'
1897 // or the beginning if 'start' is -1.
1898 long wxListCtrl::FindItem(long start
, const wxString
& str
, bool partial
)
1901 return m_genericImpl
->FindItem(start
, str
, partial
);
1903 wxString str_upper
= str
.Upper();
1908 long count
= GetItemCount();
1912 wxString line_upper
= GetItemText(idx
).Upper();
1915 if (line_upper
== str_upper
)
1920 if (line_upper
.find(str_upper
) == 0)
1930 // Find an item whose data matches this data, starting from the item after 'start'
1931 // or the beginning if 'start' is -1.
1932 long wxListCtrl::FindItem(long start
, long data
)
1935 return m_genericImpl
->FindItem(start
, data
);
1940 long count
= GetItemCount();
1944 if (GetItemData(idx
) == data
)
1952 // Find an item nearest this position in the specified direction, starting from
1953 // the item after 'start' or the beginning if 'start' is -1.
1954 long wxListCtrl::FindItem(long start
, const wxPoint
& pt
, int direction
)
1957 return m_genericImpl
->FindItem(start
, pt
, direction
);
1961 // Determines which item (if any) is at the specified point,
1962 // giving details in 'flags' (see wxLIST_HITTEST_... flags above)
1964 wxListCtrl::HitTest(const wxPoint
& point
, int& flags
, long *ptrSubItem
) const
1967 return m_genericImpl
->HitTest(point
, flags
, ptrSubItem
);
1969 flags
= wxLIST_HITTEST_NOWHERE
;
1972 int colHeaderHeight
= 22; // TODO: Find a way to get this value from the db control?
1973 UInt16 rowHeight
= 0;
1974 m_dbImpl
->GetDefaultRowHeight(&rowHeight
);
1977 // get the actual row by taking scroll position into account
1978 UInt32 offsetX
, offsetY
;
1979 m_dbImpl
->GetScrollPosition( &offsetY
, &offsetX
);
1982 if ( !(GetWindowStyleFlag() & wxLC_NO_HEADER
) )
1983 y
-= colHeaderHeight
;
1988 int row
= y
/ rowHeight
;
1989 DataBrowserItemID id
;
1990 m_dbImpl
->GetItemID( (DataBrowserTableViewRowIndex
) row
, &id
);
1992 // TODO: Use GetDataBrowserItemPartBounds to return if we are in icon or label
1993 if ( !(GetWindowStyleFlag() & wxLC_VIRTUAL
) )
1995 wxMacListCtrlItem
* lcItem
;
1996 lcItem
= (wxMacListCtrlItem
*) id
;
1999 flags
= wxLIST_HITTEST_ONITEM
;
2005 if (row
< GetItemCount() )
2007 flags
= wxLIST_HITTEST_ONITEM
;
2016 int wxListCtrl::GetScrollPos(int orient
) const
2019 return m_genericImpl
->GetScrollPos(orient
);
2023 UInt32 offsetX
, offsetY
;
2024 m_dbImpl
->GetScrollPosition( &offsetY
, &offsetX
);
2025 if ( orient
== wxHORIZONTAL
)
2034 // Inserts an item, returning the index of the new item if successful,
2036 long wxListCtrl::InsertItem(wxListItem
& info
)
2038 wxASSERT_MSG( !IsVirtual(), _T("can't be used with virtual controls") );
2041 return m_genericImpl
->InsertItem(info
);
2043 if (m_dbImpl
&& !IsVirtual())
2045 int count
= GetItemCount();
2047 if (info
.m_itemId
> count
)
2048 info
.m_itemId
= count
;
2050 m_dbImpl
->MacInsertItem(info
.m_itemId
, &info
);
2052 wxListEvent
event( wxEVT_COMMAND_LIST_INSERT_ITEM
, GetId() );
2053 event
.SetEventObject( this );
2054 event
.m_itemIndex
= info
.m_itemId
;
2055 HandleWindowEvent( event
);
2056 return info
.m_itemId
;
2061 long wxListCtrl::InsertItem(long index
, const wxString
& label
)
2064 return m_genericImpl
->InsertItem(index
, label
);
2067 info
.m_text
= label
;
2068 info
.m_mask
= wxLIST_MASK_TEXT
;
2069 info
.m_itemId
= index
;
2070 return InsertItem(info
);
2073 // Inserts an image item
2074 long wxListCtrl::InsertItem(long index
, int imageIndex
)
2077 return m_genericImpl
->InsertItem(index
, imageIndex
);
2080 info
.m_image
= imageIndex
;
2081 info
.m_mask
= wxLIST_MASK_IMAGE
;
2082 info
.m_itemId
= index
;
2083 return InsertItem(info
);
2086 // Inserts an image/string item
2087 long wxListCtrl::InsertItem(long index
, const wxString
& label
, int imageIndex
)
2090 return m_genericImpl
->InsertItem(index
, label
, imageIndex
);
2093 info
.m_image
= imageIndex
;
2094 info
.m_text
= label
;
2095 info
.m_mask
= wxLIST_MASK_IMAGE
| wxLIST_MASK_TEXT
;
2096 info
.m_itemId
= index
;
2097 return InsertItem(info
);
2100 // For list view mode (only), inserts a column.
2101 long wxListCtrl::InsertColumn(long col
, wxListItem
& item
)
2104 return m_genericImpl
->InsertColumn(col
, item
);
2108 int width
= item
.GetWidth();
2109 if ( !(item
.GetMask() & wxLIST_MASK_WIDTH
) )
2112 DataBrowserPropertyType type
= kDataBrowserCustomType
; //kDataBrowserTextType;
2113 wxImageList
* imageList
= GetImageList(wxIMAGE_LIST_SMALL
);
2114 if (imageList
&& imageList
->GetImageCount() > 0)
2116 wxBitmap bmp
= imageList
->GetBitmap(0);
2118 // type = kDataBrowserIconAndTextType;
2121 SInt16 just
= teFlushDefault
;
2122 if (item
.GetMask() & wxLIST_MASK_FORMAT
)
2124 if (item
.GetAlign() == wxLIST_FORMAT_LEFT
)
2126 else if (item
.GetAlign() == wxLIST_FORMAT_CENTER
)
2128 else if (item
.GetAlign() == wxLIST_FORMAT_RIGHT
)
2129 just
= teFlushRight
;
2131 m_dbImpl
->InsertColumn(col
, type
, item
.GetText(), just
, width
);
2132 SetColumn(col
, item
);
2134 // set/remove options based on the wxListCtrl type.
2135 DataBrowserTableViewColumnID id
;
2136 m_dbImpl
->GetColumnIDFromIndex(col
, &id
);
2137 DataBrowserPropertyFlags flags
;
2138 verify_noerr(m_dbImpl
->GetPropertyFlags(id
, &flags
));
2139 if (GetWindowStyleFlag() & wxLC_EDIT_LABELS
)
2140 flags
|= kDataBrowserPropertyIsEditable
;
2142 if (GetWindowStyleFlag() & wxLC_VIRTUAL
){
2143 flags
&= ~kDataBrowserListViewSortableColumn
;
2145 verify_noerr(m_dbImpl
->SetPropertyFlags(id
, flags
));
2151 long wxListCtrl::InsertColumn(long col
,
2152 const wxString
& heading
,
2157 return m_genericImpl
->InsertColumn(col
, heading
, format
, width
);
2160 item
.m_mask
= wxLIST_MASK_TEXT
| wxLIST_MASK_FORMAT
;
2161 item
.m_text
= heading
;
2164 item
.m_mask
|= wxLIST_MASK_WIDTH
;
2165 item
.m_width
= width
;
2167 item
.m_format
= format
;
2169 return InsertColumn(col
, item
);
2172 // scroll the control by the given number of pixels (exception: in list view,
2173 // dx is interpreted as number of columns)
2174 bool wxListCtrl::ScrollList(int dx
, int dy
)
2177 return m_genericImpl
->ScrollList(dx
, dy
);
2181 m_dbImpl
->SetScrollPosition(dx
, dy
);
2187 bool wxListCtrl::SortItems(wxListCtrlCompare fn
, long data
)
2190 return m_genericImpl
->SortItems(fn
, data
);
2195 m_compareFuncData
= data
;
2196 SortDataBrowserContainer( m_dbImpl
->GetControlRef(), kDataBrowserNoItem
, true);
2198 // we need to do this after each call, else we get a crash from wxPython when
2199 // SortItems is called the second time.
2200 m_compareFunc
= NULL
;
2201 m_compareFuncData
= 0;
2207 void wxListCtrl::OnRenameTimer()
2209 wxCHECK_RET( HasCurrent(), wxT("unexpected rename timer") );
2211 EditLabel( m_current
);
2214 bool wxListCtrl::OnRenameAccept(long itemEdit
, const wxString
& value
)
2216 wxListEvent
le( wxEVT_COMMAND_LIST_END_LABEL_EDIT
, GetId() );
2217 le
.SetEventObject( this );
2218 le
.m_itemIndex
= itemEdit
;
2220 GetItem( le
.m_item
);
2221 le
.m_item
.m_text
= value
;
2222 return !HandleWindowEvent( le
) ||
2226 void wxListCtrl::OnRenameCancelled(long itemEdit
)
2228 // let owner know that the edit was cancelled
2229 wxListEvent
le( wxEVT_COMMAND_LIST_END_LABEL_EDIT
, GetParent()->GetId() );
2231 le
.SetEditCanceled(true);
2233 le
.SetEventObject( this );
2234 le
.m_itemIndex
= itemEdit
;
2236 GetItem( le
.m_item
);
2237 HandleWindowEvent( le
);
2240 // ----------------------------------------------------------------------------
2241 // virtual list controls
2242 // ----------------------------------------------------------------------------
2244 wxString
wxListCtrl::OnGetItemText(long WXUNUSED(item
), long WXUNUSED(col
)) const
2246 // this is a pure virtual function, in fact - which is not really pure
2247 // because the controls which are not virtual don't need to implement it
2248 wxFAIL_MSG( _T("wxListCtrl::OnGetItemText not supposed to be called") );
2250 return wxEmptyString
;
2253 int wxListCtrl::OnGetItemImage(long WXUNUSED(item
)) const
2255 wxCHECK_MSG(!GetImageList(wxIMAGE_LIST_SMALL
),
2257 wxT("List control has an image list, OnGetItemImage or OnGetItemColumnImage should be overridden."));
2261 int wxListCtrl::OnGetItemColumnImage(long item
, long column
) const
2264 return OnGetItemImage(item
);
2269 wxListItemAttr
*wxListCtrl::OnGetItemAttr(long WXUNUSED_UNLESS_DEBUG(item
)) const
2271 wxASSERT_MSG( item
>= 0 && item
< GetItemCount(),
2272 _T("invalid item index in OnGetItemAttr()") );
2274 // no attributes by default
2278 void wxListCtrl::SetItemCount(long count
)
2280 wxASSERT_MSG( IsVirtual(), _T("this is for virtual controls only") );
2284 m_genericImpl
->SetItemCount(count
);
2290 // we need to temporarily disable the new item creation notification
2291 // procedure to speed things up
2292 // FIXME: Even this doesn't seem to help much...
2294 // FIXME: Find a more efficient way to do this.
2295 m_dbImpl
->MacClear();
2297 DataBrowserCallbacks callbacks
;
2298 DataBrowserItemNotificationUPP itemUPP
;
2299 GetDataBrowserCallbacks(m_dbImpl
->GetControlRef(), &callbacks
);
2300 itemUPP
= callbacks
.u
.v1
.itemNotificationCallback
;
2301 callbacks
.u
.v1
.itemNotificationCallback
= 0;
2302 m_dbImpl
->SetCallbacks(&callbacks
);
2303 ::AddDataBrowserItems(m_dbImpl
->GetControlRef(), kDataBrowserNoItem
,
2304 count
, NULL
, kDataBrowserItemNoProperty
);
2305 callbacks
.u
.v1
.itemNotificationCallback
= itemUPP
;
2306 m_dbImpl
->SetCallbacks(&callbacks
);
2311 void wxListCtrl::RefreshItem(long item
)
2315 m_genericImpl
->RefreshItem(item
);
2321 DataBrowserItemID id
;
2325 wxMacDataItem
* thisItem
= m_dbImpl
->GetItemFromLine(item
);
2326 id
= (DataBrowserItemID
) thisItem
;
2331 m_dbImpl
->wxMacDataBrowserControl::UpdateItems
2335 kDataBrowserItemNoProperty
, // preSortProperty
2336 kDataBrowserNoItem
// update all columns
2341 void wxListCtrl::RefreshItems(long itemFrom
, long itemTo
)
2345 m_genericImpl
->RefreshItems(itemFrom
, itemTo
);
2351 const long count
= itemTo
- itemFrom
+ 1;
2352 DataBrowserItemID
*ids
= new DataBrowserItemID
[count
];
2356 for ( long i
= 0; i
< count
; i
++ )
2358 wxMacDataItem
* thisItem
= m_dbImpl
->GetItemFromLine(itemFrom
+i
);
2359 ids
[i
] = (DataBrowserItemID
) thisItem
;
2364 for ( long i
= 0; i
< count
; i
++ )
2365 ids
[i
] = itemFrom
+i
+1;
2368 m_dbImpl
->wxMacDataBrowserControl::UpdateItems
2372 kDataBrowserItemNoProperty
, // preSortProperty
2373 kDataBrowserNoItem
// update all columns
2380 void wxListCtrl::SetDropTarget( wxDropTarget
*dropTarget
)
2382 #if wxUSE_DRAG_AND_DROP
2384 m_genericImpl
->SetDropTarget( dropTarget
);
2387 wxWindow::SetDropTarget( dropTarget
);
2391 wxDropTarget
*wxListCtrl::GetDropTarget() const
2393 #if wxUSE_DRAG_AND_DROP
2395 return m_genericImpl
->GetDropTarget();
2398 return wxWindow::GetDropTarget();
2403 #if wxABI_VERSION >= 20801
2404 void wxListCtrl::SetFocus()
2408 m_genericImpl
->SetFocus();
2412 wxWindow::SetFocus();
2416 // wxMac internal data structures
2418 wxMacListCtrlItem::~wxMacListCtrlItem()
2420 WX_CLEAR_HASH_MAP( wxListItemList
, m_rowItems
);
2423 void wxMacListCtrlItem::Notification(wxMacDataItemBrowserControl
*owner
,
2424 DataBrowserItemNotification message
,
2425 DataBrowserItemDataRef
WXUNUSED(itemData
) ) const
2428 wxMacDataBrowserListCtrlControl
*lb
= wxDynamicCast(owner
, wxMacDataBrowserListCtrlControl
);
2430 // we want to depend on as little as possible to make sure tear-down of controls is safe
2431 if ( message
== kDataBrowserItemRemoved
)
2436 else if ( message
== kDataBrowserItemAdded
)
2438 // we don't issue events on adding, the item is not really stored in the list yet, so we
2439 // avoid asserts by gettting out now
2443 wxListCtrl
*list
= wxDynamicCast( owner
->GetWXPeer() , wxListCtrl
);
2446 bool trigger
= false;
2448 wxListEvent
event( wxEVT_COMMAND_LIST_ITEM_SELECTED
, list
->GetId() );
2449 bool isSingle
= (list
->GetWindowStyle() & wxLC_SINGLE_SEL
) != 0;
2451 event
.SetEventObject( list
);
2452 event
.m_itemIndex
= owner
->GetLineFromItem( this ) ;
2453 event
.m_item
.m_itemId
= event
.m_itemIndex
;
2454 list
->GetItem(event
.m_item
);
2458 case kDataBrowserItemDeselected
:
2459 event
.SetEventType(wxEVT_COMMAND_LIST_ITEM_DESELECTED
);
2461 trigger
= !lb
->IsSelectionSuppressed();
2464 case kDataBrowserItemSelected
:
2465 trigger
= !lb
->IsSelectionSuppressed();
2468 case kDataBrowserItemDoubleClicked
:
2469 event
.SetEventType( wxEVT_COMMAND_LIST_ITEM_ACTIVATED
);
2473 case kDataBrowserEditStarted
:
2474 // TODO : how to veto ?
2475 event
.SetEventType( wxEVT_COMMAND_LIST_BEGIN_LABEL_EDIT
) ;
2479 case kDataBrowserEditStopped
:
2480 // TODO probably trigger only upon the value store callback, because
2481 // here IIRC we cannot veto
2482 event
.SetEventType( wxEVT_COMMAND_LIST_END_LABEL_EDIT
) ;
2492 // direct notification is not always having the listbox GetSelection() having in synch with event
2493 wxPostEvent( list
->GetEventHandler(), event
);
2499 IMPLEMENT_DYNAMIC_CLASS(wxMacDataBrowserListCtrlControl
, wxMacDataItemBrowserControl
)
2501 wxMacDataBrowserListCtrlControl::wxMacDataBrowserListCtrlControl( wxWindow
*peer
, const wxPoint
& pos
, const wxSize
& size
, long style
)
2502 : wxMacDataItemBrowserControl( peer
, pos
, size
, style
)
2504 OSStatus err
= noErr
;
2505 m_clientDataItemsType
= wxClientData_None
;
2506 m_isVirtual
= false;
2509 if ( style
& wxLC_VIRTUAL
)
2512 DataBrowserSelectionFlags options
= kDataBrowserDragSelect
;
2513 if ( style
& wxLC_SINGLE_SEL
)
2515 options
|= kDataBrowserSelectOnlyOne
;
2519 options
|= kDataBrowserCmdTogglesSelection
;
2522 err
= SetSelectionFlags( options
);
2523 verify_noerr( err
);
2525 DataBrowserCustomCallbacks callbacks
;
2526 InitializeDataBrowserCustomCallbacks( &callbacks
, kDataBrowserLatestCustomCallbacks
);
2528 if ( gDataBrowserDrawItemUPP
== NULL
)
2529 gDataBrowserDrawItemUPP
= NewDataBrowserDrawItemUPP(DataBrowserDrawItemProc
);
2531 if ( gDataBrowserHitTestUPP
== NULL
)
2532 gDataBrowserHitTestUPP
= NewDataBrowserHitTestUPP(DataBrowserHitTestProc
);
2534 callbacks
.u
.v1
.drawItemCallback
= gDataBrowserDrawItemUPP
;
2535 callbacks
.u
.v1
.hitTestCallback
= gDataBrowserHitTestUPP
;
2537 SetDataBrowserCustomCallbacks( GetControlRef(), &callbacks
);
2539 if ( style
& wxLC_LIST
)
2541 InsertColumn(0, kDataBrowserIconAndTextType
, wxEmptyString
, -1, -1);
2542 verify_noerr( AutoSizeColumns() );
2545 if ( style
& wxLC_LIST
|| style
& wxLC_NO_HEADER
)
2546 verify_noerr( SetHeaderButtonHeight( 0 ) );
2549 SetSortProperty( kMinColumnId
- 1 );
2551 SetSortProperty( kMinColumnId
);
2553 m_sortOrder
= SortOrder_None
;
2555 if ( style
& wxLC_SORT_DESCENDING
)
2557 SetSortOrder( kDataBrowserOrderDecreasing
);
2559 else if ( style
& wxLC_SORT_ASCENDING
)
2561 SetSortOrder( kDataBrowserOrderIncreasing
);
2564 if ( style
& wxLC_VRULES
)
2566 verify_noerr( DataBrowserChangeAttributes(m_controlRef
, kDataBrowserAttributeListViewDrawColumnDividers
, kDataBrowserAttributeNone
) );
2569 verify_noerr( SetHiliteStyle(kDataBrowserTableViewFillHilite
) );
2570 verify_noerr( SetHasScrollBars( (style
& wxHSCROLL
) != 0 , true ) );
2573 pascal Boolean
wxMacDataBrowserListCtrlControl::DataBrowserEditTextProc(
2575 DataBrowserItemID itemID
,
2576 DataBrowserPropertyID property
,
2577 CFStringRef theString
,
2578 Rect
*maxEditTextRect
,
2579 Boolean
*shrinkToFit
)
2581 Boolean result
= false;
2582 wxMacDataBrowserListCtrlControl
* ctl
= wxDynamicCast(wxMacControl::GetReferenceFromNativeControl( browser
), wxMacDataBrowserListCtrlControl
);
2585 result
= ctl
->ConfirmEditText(itemID
, property
, theString
, maxEditTextRect
, shrinkToFit
);
2586 theString
= CFSTR("Hello!");
2591 bool wxMacDataBrowserListCtrlControl::ConfirmEditText(
2592 DataBrowserItemID
WXUNUSED(itemID
),
2593 DataBrowserPropertyID
WXUNUSED(property
),
2594 CFStringRef
WXUNUSED(theString
),
2595 Rect
*WXUNUSED(maxEditTextRect
),
2596 Boolean
*WXUNUSED(shrinkToFit
))
2601 pascal void wxMacDataBrowserListCtrlControl::DataBrowserDrawItemProc(
2603 DataBrowserItemID itemID
,
2604 DataBrowserPropertyID property
,
2605 DataBrowserItemState itemState
,
2606 const Rect
*itemRect
,
2608 Boolean colorDevice
)
2610 wxMacDataBrowserListCtrlControl
* ctl
= wxDynamicCast(wxMacControl::GetReferenceFromNativeControl( browser
), wxMacDataBrowserListCtrlControl
);
2613 ctl
->DrawItem(itemID
, property
, itemState
, itemRect
, gdDepth
, colorDevice
);
2617 // routines needed for DrawItem
2622 kTextBoxHeight
= 14,
2623 kIconTextSpacingV
= 2,
2625 kContentHeight
= kIconHeight
+ kTextBoxHeight
+ kIconTextSpacingV
2628 static void calculateCGDrawingBounds(CGRect inItemRect
, CGRect
*outIconRect
, CGRect
*outTextRect
, bool hasIcon
= false)
2631 float iconH
, iconW
= 0;
2632 float padding
= kItemPadding
;
2635 iconH
= kIconHeight
;
2637 padding
= padding
*2;
2640 textBottom
= inItemRect
.origin
.y
;
2642 *outIconRect
= CGRectMake(inItemRect
.origin
.x
+ kItemPadding
,
2643 textBottom
+ kIconTextSpacingV
, kIconWidth
,
2646 *outTextRect
= CGRectMake(inItemRect
.origin
.x
+ padding
+ iconW
,
2647 textBottom
+ kIconTextSpacingV
, inItemRect
.size
.width
- padding
- iconW
,
2648 inItemRect
.size
.height
- kIconTextSpacingV
);
2651 void wxMacDataBrowserListCtrlControl::DrawItem(
2652 DataBrowserItemID itemID
,
2653 DataBrowserPropertyID property
,
2654 DataBrowserItemState itemState
,
2655 const Rect
*WXUNUSED(itemRect
),
2657 Boolean colorDevice
)
2660 wxFont font
= wxNullFont
;
2662 short listColumn
= property
- kMinColumnId
;
2664 wxListCtrl
* list
= wxDynamicCast( GetWXPeer() , wxListCtrl
);
2665 wxMacListCtrlItem
* lcItem
;
2666 wxColour color
= *wxBLACK
;
2667 wxColour bgColor
= wxNullColour
;
2669 if (listColumn
>= 0)
2673 lcItem
= (wxMacListCtrlItem
*) itemID
;
2674 if (lcItem
->HasColumnInfo(listColumn
)){
2675 wxListItem
* item
= lcItem
->GetColumnInfo(listColumn
);
2677 // we always use the 0 column to get font and text/background colors.
2678 if (lcItem
->HasColumnInfo(0))
2680 wxListItem
* firstItem
= lcItem
->GetColumnInfo(0);
2681 color
= firstItem
->GetTextColour();
2682 bgColor
= firstItem
->GetBackgroundColour();
2683 font
= firstItem
->GetFont();
2686 if (item
->GetMask() & wxLIST_MASK_TEXT
)
2687 text
= item
->GetText();
2688 if (item
->GetMask() & wxLIST_MASK_IMAGE
)
2689 imgIndex
= item
->GetImage();
2695 long itemNum
= (long)itemID
-1;
2696 if (itemNum
>= 0 && itemNum
< list
->GetItemCount())
2698 text
= list
->OnGetItemText( itemNum
, listColumn
);
2699 imgIndex
= list
->OnGetItemColumnImage( itemNum
, listColumn
);
2700 wxListItemAttr
* attrs
= list
->OnGetItemAttr( itemNum
);
2703 if (attrs
->HasBackgroundColour())
2704 bgColor
= attrs
->GetBackgroundColour();
2705 if (attrs
->HasTextColour())
2706 color
= attrs
->GetTextColour();
2707 if (attrs
->HasFont())
2708 font
= attrs
->GetFont();
2714 wxColour listBgColor
= list
->GetBackgroundColour();
2715 if (bgColor
== wxNullColour
)
2716 bgColor
= listBgColor
;
2719 font
= list
->GetFont();
2721 wxCFStringRef
cfString( text
, wxLocale::GetSystemEncoding() );
2724 CGRect enclosingCGRect
, iconCGRect
, textCGRect
;
2726 ThemeDrawingState savedState
= NULL
;
2727 CGContextRef context
= (CGContextRef
)list
->MacGetDrawingContext();
2728 RGBColor labelColor
;
2730 labelColor
.green
= 0;
2731 labelColor
.blue
= 0;
2733 RGBColor backgroundColor
;
2734 backgroundColor
.red
= 255;
2735 backgroundColor
.green
= 255;
2736 backgroundColor
.blue
= 255;
2738 GetDataBrowserItemPartBounds(GetControlRef(), itemID
, property
, kDataBrowserPropertyEnclosingPart
,
2741 enclosingCGRect
= CGRectMake(enclosingRect
.left
,
2743 enclosingRect
.right
- enclosingRect
.left
,
2744 enclosingRect
.bottom
- enclosingRect
.top
);
2746 bool hasFocus
= (wxWindow::FindFocus() == list
);
2747 active
= IsControlActive(GetControlRef());
2749 // don't paint the background over the vertical rule line
2750 if ( list
->GetWindowStyleFlag() & wxLC_VRULES
)
2752 enclosingCGRect
.origin
.x
+= 1;
2753 enclosingCGRect
.size
.width
-= 1;
2755 if (itemState
== kDataBrowserItemIsSelected
)
2758 GetThemeDrawingState(&savedState
);
2760 if (active
&& hasFocus
)
2762 GetThemeBrushAsColor(kThemeBrushAlternatePrimaryHighlightColor
, 32, true, &backgroundColor
);
2763 GetThemeTextColor(kThemeTextColorWhite
, gdDepth
, colorDevice
, &labelColor
);
2767 GetThemeBrushAsColor(kThemeBrushSecondaryHighlightColor
, 32, true, &backgroundColor
);
2768 GetThemeTextColor(kThemeTextColorBlack
, gdDepth
, colorDevice
, &labelColor
);
2770 CGContextSaveGState(context
);
2772 CGContextSetRGBFillColor(context
, (CGFloat
)backgroundColor
.red
/ (CGFloat
)USHRT_MAX
,
2773 (CGFloat
)backgroundColor
.green
/ (CGFloat
)USHRT_MAX
,
2774 (CGFloat
)backgroundColor
.blue
/ (CGFloat
)USHRT_MAX
, (CGFloat
) 1.0);
2775 CGContextFillRect(context
, enclosingCGRect
);
2777 CGContextRestoreGState(context
);
2783 color
.GetRGBColor(&labelColor
);
2784 else if (list
->GetTextColour().Ok())
2785 list
->GetTextColour().GetRGBColor(&labelColor
);
2789 bgColor
.GetRGBColor(&backgroundColor
);
2790 CGContextSaveGState(context
);
2792 CGContextSetRGBFillColor(context
, (CGFloat
)backgroundColor
.red
/ (CGFloat
)USHRT_MAX
,
2793 (CGFloat
)backgroundColor
.green
/ (CGFloat
)USHRT_MAX
,
2794 (CGFloat
)backgroundColor
.blue
/ (CGFloat
)USHRT_MAX
, (CGFloat
) 1.0);
2795 CGContextFillRect(context
, enclosingCGRect
);
2797 CGContextRestoreGState(context
);
2801 calculateCGDrawingBounds(enclosingCGRect
, &iconCGRect
, &textCGRect
, (imgIndex
!= -1) );
2805 wxImageList
* imageList
= list
->GetImageList(wxIMAGE_LIST_SMALL
);
2806 if (imageList
&& imageList
->GetImageCount() > 0){
2807 wxBitmap bmp
= imageList
->GetBitmap(imgIndex
);
2808 IconRef icon
= bmp
.GetIconRef();
2810 CGContextSaveGState(context
);
2811 CGContextTranslateCTM(context
, 0,iconCGRect
.origin
.y
+ CGRectGetMaxY(iconCGRect
));
2812 CGContextScaleCTM(context
,1.0f
,-1.0f
);
2813 PlotIconRefInContext(context
, &iconCGRect
, kAlignNone
,
2814 active
? kTransformNone
: kTransformDisabled
, NULL
,
2815 kPlotIconRefNormalFlags
, icon
);
2817 CGContextRestoreGState(context
);
2821 HIThemeTextHorizontalFlush hFlush
= kHIThemeTextHorizontalFlushLeft
;
2822 HIThemeTextInfo info
;
2824 #if wxOSX_USE_CORE_TEXT
2825 if ( UMAGetSystemVersion() >= 0x1050 )
2827 info
.version
= kHIThemeTextInfoVersionOne
;
2828 info
.fontID
= kThemeViewsFont
;
2831 info
.fontID
= kThemeSpecifiedFont
;
2832 info
.font
= (CTFontRef
) font
.MacGetCTFont();
2837 #if wxOSX_USE_ATSU_TEXT
2840 info
.version
= kHIThemeTextInfoVersionZero
;
2841 info
.fontID
= kThemeViewsFont
;
2845 info
.fontID
= font
.MacGetThemeFontID();
2847 ::TextSize( (short)(font
.MacGetFontSize()) ) ;
2848 ::TextFace( font
.MacGetFontStyle() ) ;
2854 list
->GetColumn(listColumn
, item
);
2855 if (item
.GetMask() & wxLIST_MASK_FORMAT
)
2857 if (item
.GetAlign() == wxLIST_FORMAT_LEFT
)
2858 hFlush
= kHIThemeTextHorizontalFlushLeft
;
2859 else if (item
.GetAlign() == wxLIST_FORMAT_CENTER
)
2860 hFlush
= kHIThemeTextHorizontalFlushCenter
;
2861 else if (item
.GetAlign() == wxLIST_FORMAT_RIGHT
)
2863 hFlush
= kHIThemeTextHorizontalFlushRight
;
2864 textCGRect
.origin
.x
-= kItemPadding
; // give a little extra paddding
2868 info
.state
= active
? kThemeStateActive
: kThemeStateInactive
;
2869 info
.horizontalFlushness
= hFlush
;
2870 info
.verticalFlushness
= kHIThemeTextVerticalFlushCenter
;
2871 info
.options
= kHIThemeTextBoxOptionNone
;
2872 info
.truncationPosition
= kHIThemeTextTruncationEnd
;
2873 info
.truncationMaxLines
= 1;
2875 CGContextSaveGState(context
);
2876 CGContextSetRGBFillColor (context
, (CGFloat
)labelColor
.red
/ (CGFloat
)USHRT_MAX
,
2877 (CGFloat
)labelColor
.green
/ (CGFloat
)USHRT_MAX
,
2878 (CGFloat
)labelColor
.blue
/ (CGFloat
)USHRT_MAX
, (CGFloat
) 1.0);
2880 HIThemeDrawTextBox(cfString
, &textCGRect
, &info
, context
, kHIThemeOrientationNormal
);
2882 CGContextRestoreGState(context
);
2885 if (savedState
!= NULL
)
2886 SetThemeDrawingState(savedState
, true);
2890 OSStatus
wxMacDataBrowserListCtrlControl::GetSetItemData(DataBrowserItemID itemID
,
2891 DataBrowserPropertyID property
,
2892 DataBrowserItemDataRef itemData
,
2893 Boolean changeValue
)
2897 short listColumn
= property
- kMinColumnId
;
2899 OSStatus err
= errDataBrowserPropertyNotSupported
;
2900 wxListCtrl
* list
= wxDynamicCast( GetWXPeer() , wxListCtrl
);
2901 wxMacListCtrlItem
* lcItem
= NULL
;
2903 if (listColumn
>= 0)
2907 lcItem
= (wxMacListCtrlItem
*) itemID
;
2908 if (lcItem
&& lcItem
->HasColumnInfo(listColumn
)){
2909 wxListItem
* item
= lcItem
->GetColumnInfo(listColumn
);
2910 if (item
->GetMask() & wxLIST_MASK_TEXT
)
2911 text
= item
->GetText();
2912 if (item
->GetMask() & wxLIST_MASK_IMAGE
)
2913 imgIndex
= item
->GetImage();
2918 long itemNum
= (long)itemID
-1;
2919 if (itemNum
>= 0 && itemNum
< list
->GetItemCount())
2921 text
= list
->OnGetItemText( itemNum
, listColumn
);
2922 imgIndex
= list
->OnGetItemColumnImage( itemNum
, listColumn
);
2931 case kDataBrowserItemIsEditableProperty
:
2932 if ( list
&& list
->HasFlag( wxLC_EDIT_LABELS
) )
2934 verify_noerr(SetDataBrowserItemDataBooleanValue( itemData
, true ));
2939 if ( property
>= kMinColumnId
)
2941 if (!text
.IsEmpty()){
2942 wxCFStringRef
cfStr( text
, wxLocale::GetSystemEncoding() );
2943 err
= ::SetDataBrowserItemDataText( itemData
, cfStr
);
2949 if ( imgIndex
!= -1 )
2951 wxImageList
* imageList
= list
->GetImageList(wxIMAGE_LIST_SMALL
);
2952 if (imageList
&& imageList
->GetImageCount() > 0){
2953 wxBitmap bmp
= imageList
->GetBitmap(imgIndex
);
2954 IconRef icon
= bmp
.GetIconRef();
2955 ::SetDataBrowserItemDataIcon(itemData
, icon
);
2969 if ( property
>= kMinColumnId
)
2971 short listColumn
= property
- kMinColumnId
;
2973 // TODO probably send the 'end edit' from here, as we
2974 // can then deal with the veto
2976 verify_noerr( GetDataBrowserItemDataText( itemData
, &sr
) ) ;
2977 wxCFStringRef
cfStr(sr
) ;;
2979 list
->SetItem( (long)itemData
-1 , listColumn
, cfStr
.AsString() ) ;
2983 lcItem
->SetColumnTextValue( listColumn
, cfStr
.AsString() );
2993 void wxMacDataBrowserListCtrlControl::ItemNotification(DataBrowserItemID itemID
,
2994 DataBrowserItemNotification message
,
2995 DataBrowserItemDataRef itemData
)
2997 wxMacListCtrlItem
*item
= NULL
;
3000 item
= (wxMacListCtrlItem
*) itemID
;
3003 // we want to depend on as little as possible to make sure tear-down of controls is safe
3004 if ( message
== kDataBrowserItemRemoved
)
3007 item
->Notification(this, message
, itemData
);
3010 else if ( message
== kDataBrowserItemAdded
)
3012 // we don't issue events on adding, the item is not really stored in the list yet, so we
3013 // avoid asserts by getting out now
3015 item
->Notification(this, message
, itemData
);
3019 wxListCtrl
*list
= wxDynamicCast( GetWXPeer() , wxListCtrl
);
3022 bool trigger
= false;
3024 wxListEvent
event( wxEVT_COMMAND_LIST_ITEM_SELECTED
, list
->GetId() );
3026 event
.SetEventObject( list
);
3027 if ( !list
->IsVirtual() )
3029 DataBrowserTableViewRowIndex result
= 0;
3030 verify_noerr( GetItemRow( itemID
, &result
) ) ;
3031 event
.m_itemIndex
= result
;
3035 event
.m_itemIndex
= (long)itemID
-1;
3037 event
.m_item
.m_itemId
= event
.m_itemIndex
;
3038 list
->GetItem(event
.m_item
);
3042 case kDataBrowserItemDeselected
:
3043 event
.SetEventType(wxEVT_COMMAND_LIST_ITEM_DESELECTED
);
3044 // as the generic implementation is also triggering this
3045 // event for single selection, we do the same (different than listbox)
3046 trigger
= !IsSelectionSuppressed();
3049 case kDataBrowserItemSelected
:
3050 trigger
= !IsSelectionSuppressed();
3054 case kDataBrowserItemDoubleClicked
:
3055 event
.SetEventType( wxEVT_COMMAND_LIST_ITEM_ACTIVATED
);
3059 case kDataBrowserEditStarted
:
3060 // TODO : how to veto ?
3061 event
.SetEventType( wxEVT_COMMAND_LIST_BEGIN_LABEL_EDIT
) ;
3065 case kDataBrowserEditStopped
:
3066 // TODO probably trigger only upon the value store callback, because
3067 // here IIRC we cannot veto
3068 event
.SetEventType( wxEVT_COMMAND_LIST_END_LABEL_EDIT
) ;
3078 // direct notification is not always having the listbox GetSelection() having in synch with event
3079 wxPostEvent( list
->GetEventHandler(), event
);
3084 Boolean
wxMacDataBrowserListCtrlControl::CompareItems(DataBrowserItemID itemOneID
,
3085 DataBrowserItemID itemTwoID
,
3086 DataBrowserPropertyID sortProperty
)
3089 bool retval
= false;
3091 wxString otherItemText
;
3093 long otherItemOrder
;
3095 int colId
= sortProperty
- kMinColumnId
;
3097 wxListCtrl
* list
= wxDynamicCast( GetWXPeer() , wxListCtrl
);
3099 DataBrowserSortOrder sort
;
3100 verify_noerr(GetSortOrder(&sort
));
3106 wxMacListCtrlItem
* item
= (wxMacListCtrlItem
*)itemOneID
;
3107 wxMacListCtrlItem
* otherItem
= (wxMacListCtrlItem
*)itemTwoID
;
3109 itemOrder
= item
->GetOrder();
3110 otherItemOrder
= otherItem
->GetOrder();
3112 wxListCtrlCompare func
= list
->GetCompareFunc();
3118 if (item
&& item
->HasColumnInfo(0))
3119 item1
= item
->GetColumnInfo(0)->GetData();
3120 if (otherItem
&& otherItem
->HasColumnInfo(0))
3121 item2
= otherItem
->GetColumnInfo(0)->GetData();
3123 if (item1
> -1 && item2
> -1)
3125 int result
= func(item1
, item2
, list
->GetCompareFuncData());
3126 if (sort
== kDataBrowserOrderIncreasing
)
3133 // we can't use the native control's sorting abilities, so just
3135 return itemOrder
< otherItemOrder
;
3140 long itemNum
= (long)itemOneID
;
3141 long otherItemNum
= (long)itemTwoID
;
3143 // virtual listctrls don't support sorting
3144 return itemNum
< otherItemNum
;
3148 // fallback for undefined cases
3149 retval
= itemOneID
< itemTwoID
;
3155 wxMacDataBrowserListCtrlControl::~wxMacDataBrowserListCtrlControl()
3159 void wxMacDataBrowserListCtrlControl::MacSetColumnInfo( unsigned int row
, unsigned int column
, wxListItem
* item
)
3161 wxMacDataItem
* dataItem
= GetItemFromLine(row
);
3162 wxASSERT_MSG( dataItem
, _T("could not obtain wxMacDataItem for row in MacSetColumnInfo. Is row a valid wxListCtrl row?") );
3165 wxMacListCtrlItem
* listItem
= wx_static_cast(wxMacListCtrlItem
*,dataItem
);
3166 bool hasInfo
= listItem
->HasColumnInfo( column
);
3167 listItem
->SetColumnInfo( column
, item
);
3168 listItem
->SetOrder(row
);
3169 UpdateState(dataItem
, item
);
3171 wxListCtrl
* list
= wxDynamicCast( GetWXPeer() , wxListCtrl
);
3173 // NB: When this call was made before a control was completely shown, it would
3174 // update the item prematurely (i.e. no text would be listed) and, on show,
3175 // only the sorted column would be refreshed, meaning only first column text labels
3176 // would be shown. Making sure not to update items until the control is visible
3177 // seems to fix this issue.
3178 if (hasInfo
&& list
->IsShown())
3179 UpdateItem( wxMacDataBrowserRootContainer
, listItem
, kMinColumnId
+ column
);
3183 // apply changes that need to happen immediately, rather than when the
3184 // databrowser control fires a callback.
3185 void wxMacDataBrowserListCtrlControl::UpdateState(wxMacDataItem
* dataItem
, wxListItem
* listItem
)
3187 bool isSelected
= IsItemSelected( dataItem
);
3188 bool isSelectedState
= (listItem
->GetState() == wxLIST_STATE_SELECTED
);
3190 // toggle the selection state if wxListInfo state and actual state don't match.
3191 if ( listItem
->GetMask() & wxLIST_MASK_STATE
&& isSelected
!= isSelectedState
)
3193 DataBrowserSetOption options
= kDataBrowserItemsAdd
;
3194 if (!isSelectedState
)
3195 options
= kDataBrowserItemsRemove
;
3196 SetSelectedItem(dataItem
, options
);
3198 // TODO: Set column width if item width > than current column width
3201 void wxMacDataBrowserListCtrlControl::MacGetColumnInfo( unsigned int row
, unsigned int column
, wxListItem
& item
)
3203 wxMacDataItem
* dataItem
= GetItemFromLine(row
);
3204 wxASSERT_MSG( dataItem
, _T("could not obtain wxMacDataItem in MacGetColumnInfo. Is row a valid wxListCtrl row?") );
3205 // CS should this guard against dataItem = 0 ? , as item is not a pointer if (item) is not appropriate
3208 wxMacListCtrlItem
* listItem
=wx_static_cast(wxMacListCtrlItem
*,dataItem
);
3210 if (!listItem
->HasColumnInfo( column
))
3213 wxListItem
* oldItem
= listItem
->GetColumnInfo( column
);
3217 long mask
= item
.GetMask();
3219 // by default, get everything for backwards compatibility
3222 if ( mask
& wxLIST_MASK_TEXT
)
3223 item
.SetText(oldItem
->GetText());
3224 if ( mask
& wxLIST_MASK_IMAGE
)
3225 item
.SetImage(oldItem
->GetImage());
3226 if ( mask
& wxLIST_MASK_DATA
)
3227 item
.SetData(oldItem
->GetData());
3228 if ( mask
& wxLIST_MASK_STATE
)
3229 item
.SetState(oldItem
->GetState());
3230 if ( mask
& wxLIST_MASK_WIDTH
)
3231 item
.SetWidth(oldItem
->GetWidth());
3232 if ( mask
& wxLIST_MASK_FORMAT
)
3233 item
.SetAlign(oldItem
->GetAlign());
3235 item
.SetTextColour(oldItem
->GetTextColour());
3236 item
.SetBackgroundColour(oldItem
->GetBackgroundColour());
3237 item
.SetFont(oldItem
->GetFont());
3242 void wxMacDataBrowserListCtrlControl::MacInsertItem( unsigned int n
, wxListItem
* item
)
3245 wxMacDataItemBrowserControl::MacInsert(n
, new wxMacListCtrlItem() );
3246 MacSetColumnInfo(n
, 0, item
);
3249 wxMacListCtrlItem::wxMacListCtrlItem()
3251 m_rowItems
= wxListItemList();
3254 int wxMacListCtrlItem::GetColumnImageValue( unsigned int column
)
3256 if ( HasColumnInfo(column
) )
3257 return GetColumnInfo(column
)->GetImage();
3262 void wxMacListCtrlItem::SetColumnImageValue( unsigned int column
, int imageIndex
)
3264 if ( HasColumnInfo(column
) )
3265 GetColumnInfo(column
)->SetImage(imageIndex
);
3268 wxString
wxMacListCtrlItem::GetColumnTextValue( unsigned int column
)
3270 /* TODO CHECK REMOVE
3274 if ( HasColumnInfo(column
) )
3275 return GetColumnInfo(column
)->GetText();
3277 return wxEmptyString
;
3280 void wxMacListCtrlItem::SetColumnTextValue( unsigned int column
, const wxString
& text
)
3282 if ( HasColumnInfo(column
) )
3283 GetColumnInfo(column
)->SetText(text
);
3285 /* TODO CHECK REMOVE
3286 // for compatibility with superclass APIs
3292 wxListItem
* wxMacListCtrlItem::GetColumnInfo( unsigned int column
)
3294 wxASSERT_MSG( HasColumnInfo(column
), _T("invalid column index in wxMacListCtrlItem") );
3295 return m_rowItems
[column
];
3298 bool wxMacListCtrlItem::HasColumnInfo( unsigned int column
)
3300 return !(m_rowItems
.find( column
) == m_rowItems
.end());
3303 void wxMacListCtrlItem::SetColumnInfo( unsigned int column
, wxListItem
* item
)
3306 if ( !HasColumnInfo(column
) )
3308 wxListItem
* listItem
= new wxListItem(*item
);
3309 m_rowItems
[column
] = listItem
;
3313 wxListItem
* listItem
= GetColumnInfo( column
);
3314 long mask
= item
->GetMask();
3315 if (mask
& wxLIST_MASK_TEXT
)
3316 listItem
->SetText(item
->GetText());
3317 if (mask
& wxLIST_MASK_DATA
)
3318 listItem
->SetData(item
->GetData());
3319 if (mask
& wxLIST_MASK_IMAGE
)
3320 listItem
->SetImage(item
->GetImage());
3321 if (mask
& wxLIST_MASK_STATE
)
3322 listItem
->SetState(item
->GetState());
3323 if (mask
& wxLIST_MASK_FORMAT
)
3324 listItem
->SetAlign(item
->GetAlign());
3325 if (mask
& wxLIST_MASK_WIDTH
)
3326 listItem
->SetWidth(item
->GetWidth());
3328 if ( item
->HasAttributes() )
3330 if ( listItem
->HasAttributes() )
3331 listItem
->GetAttributes()->AssignFrom(*item
->GetAttributes());
3334 listItem
->SetTextColour(item
->GetTextColour());
3335 listItem
->SetBackgroundColour(item
->GetBackgroundColour());
3336 listItem
->SetFont(item
->GetFont());
3342 int wxListCtrl::CalcColumnAutoWidth(int col
) const
3346 for ( int i
= 0; i
< GetItemCount(); i
++ )
3349 info
.SetMask(wxLIST_MASK_TEXT
| wxLIST_MASK_IMAGE
);
3351 info
.SetColumn(col
);
3354 const wxFont font
= info
.GetFont();
3358 GetTextExtent(info
.GetText(), &w
, NULL
, NULL
, NULL
, &font
);
3360 GetTextExtent(info
.GetText(), &w
, NULL
);
3362 w
+= 2 * kItemPadding
;
3364 if ( info
.GetImage() != -1 )
3367 width
= wxMax(width
, w
);
3373 #endif // wxUSE_LISTCTRL