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 bool wxListCtrl::GetSubItemRect( long item
, long subItem
, wxRect
& rect
, int code
) const
1389 return m_genericImpl
->GetItemRect(item
, rect
, code
);
1391 // TODO: implement for DataBrowser implementation
1395 // Gets the item rectangle
1396 bool wxListCtrl::GetItemRect(long item
, wxRect
& rect
, int code
) const
1399 return m_genericImpl
->GetItemRect(item
, rect
, code
);
1404 DataBrowserItemID id
;
1405 DataBrowserPropertyID col
= kMinColumnId
;
1407 DataBrowserPropertyPart part
= kDataBrowserPropertyEnclosingPart
;
1408 if ( code
== wxLIST_RECT_LABEL
)
1409 part
= kDataBrowserPropertyTextPart
;
1410 else if ( code
== wxLIST_RECT_ICON
)
1411 part
= kDataBrowserPropertyIconPart
;
1413 if ( !(GetWindowStyleFlag() & wxLC_VIRTUAL
) )
1415 wxMacDataItem
* thisItem
= m_dbImpl
->GetItemFromLine(item
);
1416 id
= (DataBrowserItemID
) thisItem
;
1421 GetDataBrowserItemPartBounds( m_dbImpl
->GetControlRef(), id
, col
, part
, &bounds
);
1423 rect
.x
= bounds
.left
;
1424 rect
.y
= bounds
.top
;
1425 rect
.width
= bounds
.right
- bounds
.left
; //GetClientSize().x; // we need the width of the whole row, not just the item.
1426 rect
.height
= bounds
.bottom
- bounds
.top
;
1427 //fprintf("id = %d, bounds = %d, %d, %d, %d\n", id, rect.x, rect.y, rect.width, rect.height);
1432 // Gets the item position
1433 bool wxListCtrl::GetItemPosition(long item
, wxPoint
& pos
) const
1436 return m_genericImpl
->GetItemPosition(item
, pos
);
1438 bool success
= false;
1443 GetItemRect(item
, itemRect
);
1444 pos
= itemRect
.GetPosition();
1451 // Sets the item position.
1452 bool wxListCtrl::SetItemPosition(long item
, const wxPoint
& pos
)
1455 return m_genericImpl
->SetItemPosition(item
, pos
);
1460 // Gets the number of items in the list control
1461 int wxListCtrl::GetItemCount() const
1464 return m_genericImpl
->GetItemCount();
1467 return m_dbImpl
->MacGetCount();
1472 void wxListCtrl::SetItemSpacing( int spacing
, bool isSmall
)
1475 m_genericImpl
->SetItemSpacing(spacing
, isSmall
);
1478 wxSize
wxListCtrl::GetItemSpacing() const
1481 return m_genericImpl
->GetItemSpacing();
1483 return wxSize(0, 0);
1486 void wxListCtrl::SetItemTextColour( long item
, const wxColour
&col
)
1490 m_genericImpl
->SetItemTextColour(item
, col
);
1495 info
.m_itemId
= item
;
1496 info
.SetTextColour( col
);
1500 wxColour
wxListCtrl::GetItemTextColour( long item
) const
1503 return m_genericImpl
->GetItemTextColour(item
);
1509 return info
.GetTextColour();
1511 return wxNullColour
;
1514 void wxListCtrl::SetItemBackgroundColour( long item
, const wxColour
&col
)
1518 m_genericImpl
->SetItemBackgroundColour(item
, col
);
1523 info
.m_itemId
= item
;
1524 info
.SetBackgroundColour( col
);
1528 wxColour
wxListCtrl::GetItemBackgroundColour( long item
) const
1531 return m_genericImpl
->GetItemBackgroundColour(item
);
1537 return info
.GetBackgroundColour();
1539 return wxNullColour
;
1542 void wxListCtrl::SetItemFont( long item
, const wxFont
&f
)
1546 m_genericImpl
->SetItemFont(item
, f
);
1551 info
.m_itemId
= item
;
1556 wxFont
wxListCtrl::GetItemFont( long item
) const
1559 return m_genericImpl
->GetItemFont(item
);
1565 return info
.GetFont();
1571 // Gets the number of selected items in the list control
1572 int wxListCtrl::GetSelectedItemCount() const
1575 return m_genericImpl
->GetSelectedItemCount();
1578 return m_dbImpl
->GetSelectedItemCount(NULL
, true);
1583 // Gets the text colour of the listview
1584 wxColour
wxListCtrl::GetTextColour() const
1587 return m_genericImpl
->GetTextColour();
1589 // TODO: we need owner drawn list items to customize text color.
1593 return wxNullColour
;
1596 // Sets the text colour of the listview
1597 void wxListCtrl::SetTextColour(const wxColour
& col
)
1601 m_genericImpl
->SetTextColour(col
);
1609 // Gets the index of the topmost visible item when in
1610 // list or report view
1611 long wxListCtrl::GetTopItem() const
1614 return m_genericImpl
->GetTopItem();
1619 long item
= HitTest( wxPoint(1, 1), flags
);
1620 if (flags
== wxLIST_HITTEST_ONITEM
)
1627 // Searches for an item, starting from 'item'.
1628 // 'geometry' is one of
1629 // wxLIST_NEXT_ABOVE/ALL/BELOW/LEFT/RIGHT.
1630 // 'state' is a state bit flag, one or more of
1631 // wxLIST_STATE_DROPHILITED/FOCUSED/SELECTED/CUT.
1632 // item can be -1 to find the first item that matches the
1634 // Returns the item or -1 if unsuccessful.
1635 long wxListCtrl::GetNextItem(long item
, int geom
, int state
) const
1638 return m_genericImpl
->GetNextItem(item
, geom
, state
);
1640 // TODO: implement all geometry and state options?
1643 if ( geom
== wxLIST_NEXT_ALL
|| geom
== wxLIST_NEXT_BELOW
)
1645 long count
= m_dbImpl
->MacGetCount() ;
1646 for ( long line
= item
+ 1 ; line
< count
; line
++ )
1648 DataBrowserItemID id
= line
+ 1;
1650 id
= (DataBrowserItemID
)m_dbImpl
->GetItemFromLine(line
);
1652 if ( (state
== wxLIST_STATE_DONTCARE
) )
1655 if ( (state
& wxLIST_STATE_SELECTED
) && IsDataBrowserItemSelected(m_dbImpl
->GetControlRef(), id
) )
1660 if ( geom
== wxLIST_NEXT_ABOVE
)
1664 item2
= m_dbImpl
->MacGetCount();
1666 for ( long line
= item2
- 1 ; line
>= 0; line
-- )
1668 DataBrowserItemID id
= line
+ 1;
1670 id
= (DataBrowserItemID
)m_dbImpl
->GetItemFromLine(line
);
1672 if ( (state
== wxLIST_STATE_DONTCARE
) )
1675 if ( (state
& wxLIST_STATE_SELECTED
) && IsDataBrowserItemSelected(m_dbImpl
->GetControlRef(), id
) )
1685 wxImageList
*wxListCtrl::GetImageList(int which
) const
1688 return m_genericImpl
->GetImageList(which
);
1690 if ( which
== wxIMAGE_LIST_NORMAL
)
1692 return m_imageListNormal
;
1694 else if ( which
== wxIMAGE_LIST_SMALL
)
1696 return m_imageListSmall
;
1698 else if ( which
== wxIMAGE_LIST_STATE
)
1700 return m_imageListState
;
1705 void wxListCtrl::SetImageList(wxImageList
*imageList
, int which
)
1709 m_genericImpl
->SetImageList(imageList
, which
);
1713 if ( which
== wxIMAGE_LIST_NORMAL
)
1715 if (m_ownsImageListNormal
) delete m_imageListNormal
;
1716 m_imageListNormal
= imageList
;
1717 m_ownsImageListNormal
= false;
1719 else if ( which
== wxIMAGE_LIST_SMALL
)
1721 if (m_ownsImageListSmall
) delete m_imageListSmall
;
1722 m_imageListSmall
= imageList
;
1723 m_ownsImageListSmall
= false;
1725 else if ( which
== wxIMAGE_LIST_STATE
)
1727 if (m_ownsImageListState
) delete m_imageListState
;
1728 m_imageListState
= imageList
;
1729 m_ownsImageListState
= false;
1733 void wxListCtrl::AssignImageList(wxImageList
*imageList
, int which
)
1737 m_genericImpl
->AssignImageList(imageList
, which
);
1741 SetImageList(imageList
, which
);
1742 if ( which
== wxIMAGE_LIST_NORMAL
)
1743 m_ownsImageListNormal
= true;
1744 else if ( which
== wxIMAGE_LIST_SMALL
)
1745 m_ownsImageListSmall
= true;
1746 else if ( which
== wxIMAGE_LIST_STATE
)
1747 m_ownsImageListState
= true;
1750 // ----------------------------------------------------------------------------
1752 // ----------------------------------------------------------------------------
1754 // Arranges the items
1755 bool wxListCtrl::Arrange(int flag
)
1758 return m_genericImpl
->Arrange(flag
);
1763 bool wxListCtrl::DeleteItem(long item
)
1766 return m_genericImpl
->DeleteItem(item
);
1770 m_dbImpl
->MacDelete(item
);
1771 wxListEvent
event( wxEVT_COMMAND_LIST_DELETE_ITEM
, GetId() );
1772 event
.SetEventObject( this );
1773 event
.m_itemIndex
= item
;
1774 HandleWindowEvent( event
);
1780 // Deletes all items
1781 bool wxListCtrl::DeleteAllItems()
1784 return m_genericImpl
->DeleteAllItems();
1788 m_dbImpl
->MacClear();
1789 wxListEvent
event( wxEVT_COMMAND_LIST_DELETE_ALL_ITEMS
, GetId() );
1790 event
.SetEventObject( this );
1791 HandleWindowEvent( event
);
1796 // Deletes all items
1797 bool wxListCtrl::DeleteAllColumns()
1800 return m_genericImpl
->DeleteAllColumns();
1805 m_dbImpl
->GetColumnCount(&cols
);
1806 for (UInt32 col
= 0; col
< cols
; col
++)
1816 bool wxListCtrl::DeleteColumn(int col
)
1819 return m_genericImpl
->DeleteColumn(col
);
1823 OSStatus err
= m_dbImpl
->RemoveColumn(col
);
1824 return err
== noErr
;
1830 // Clears items, and columns if there are any.
1831 void wxListCtrl::ClearAll()
1835 m_genericImpl
->ClearAll();
1846 wxTextCtrl
* wxListCtrl::EditLabel(long item
, wxClassInfo
* textControlClass
)
1849 return m_genericImpl
->EditLabel(item
, textControlClass
);
1853 wxCHECK_MSG( (item
>= 0) && ((long)item
< GetItemCount()), NULL
,
1854 wxT("wrong index in wxListCtrl::EditLabel()") );
1856 wxASSERT_MSG( textControlClass
->IsKindOf(CLASSINFO(wxTextCtrl
)),
1857 wxT("EditLabel() needs a text control") );
1859 wxListEvent
le( wxEVT_COMMAND_LIST_BEGIN_LABEL_EDIT
, GetParent()->GetId() );
1860 le
.SetEventObject( this );
1861 le
.m_itemIndex
= item
;
1863 GetItem( le
.m_item
);
1865 if ( GetParent()->HandleWindowEvent( le
) && !le
.IsAllowed() )
1867 // vetoed by user code
1871 wxTextCtrl
* const text
= (wxTextCtrl
*)textControlClass
->CreateObject();
1872 m_textctrlWrapper
= new wxListCtrlTextCtrlWrapper(this, text
, item
);
1873 return m_textctrlWrapper
->GetText();
1878 // End label editing, optionally cancelling the edit
1879 bool wxListCtrl::EndEditLabel(bool WXUNUSED(cancel
))
1881 // TODO: generic impl. doesn't have this method - is it needed for us?
1883 return true; // m_genericImpl->EndEditLabel(cancel);
1886 verify_noerr( SetDataBrowserEditItem(m_dbImpl
->GetControlRef(), kDataBrowserNoItem
, kMinColumnId
) );
1890 // Ensures this item is visible
1891 bool wxListCtrl::EnsureVisible(long item
)
1894 return m_genericImpl
->EnsureVisible(item
);
1898 wxMacDataItem
* dataItem
= m_dbImpl
->GetItemFromLine(item
);
1899 m_dbImpl
->RevealItem(dataItem
, kDataBrowserRevealWithoutSelecting
);
1905 // Find an item whose label matches this string, starting from the item after 'start'
1906 // or the beginning if 'start' is -1.
1907 long wxListCtrl::FindItem(long start
, const wxString
& str
, bool partial
)
1910 return m_genericImpl
->FindItem(start
, str
, partial
);
1912 wxString str_upper
= str
.Upper();
1917 long count
= GetItemCount();
1921 wxString line_upper
= GetItemText(idx
).Upper();
1924 if (line_upper
== str_upper
)
1929 if (line_upper
.find(str_upper
) == 0)
1939 // Find an item whose data matches this data, starting from the item after 'start'
1940 // or the beginning if 'start' is -1.
1941 long wxListCtrl::FindItem(long start
, long data
)
1944 return m_genericImpl
->FindItem(start
, data
);
1949 long count
= GetItemCount();
1953 if (GetItemData(idx
) == data
)
1961 // Find an item nearest this position in the specified direction, starting from
1962 // the item after 'start' or the beginning if 'start' is -1.
1963 long wxListCtrl::FindItem(long start
, const wxPoint
& pt
, int direction
)
1966 return m_genericImpl
->FindItem(start
, pt
, direction
);
1970 // Determines which item (if any) is at the specified point,
1971 // giving details in 'flags' (see wxLIST_HITTEST_... flags above)
1973 wxListCtrl::HitTest(const wxPoint
& point
, int& flags
, long *ptrSubItem
) const
1976 return m_genericImpl
->HitTest(point
, flags
, ptrSubItem
);
1978 flags
= wxLIST_HITTEST_NOWHERE
;
1981 int colHeaderHeight
= 22; // TODO: Find a way to get this value from the db control?
1982 UInt16 rowHeight
= 0;
1983 m_dbImpl
->GetDefaultRowHeight(&rowHeight
);
1986 // get the actual row by taking scroll position into account
1987 UInt32 offsetX
, offsetY
;
1988 m_dbImpl
->GetScrollPosition( &offsetY
, &offsetX
);
1991 if ( !(GetWindowStyleFlag() & wxLC_NO_HEADER
) )
1992 y
-= colHeaderHeight
;
1997 int row
= y
/ rowHeight
;
1998 DataBrowserItemID id
;
1999 m_dbImpl
->GetItemID( (DataBrowserTableViewRowIndex
) row
, &id
);
2001 // TODO: Use GetDataBrowserItemPartBounds to return if we are in icon or label
2002 if ( !(GetWindowStyleFlag() & wxLC_VIRTUAL
) )
2004 wxMacListCtrlItem
* lcItem
;
2005 lcItem
= (wxMacListCtrlItem
*) id
;
2008 flags
= wxLIST_HITTEST_ONITEM
;
2014 if (row
< GetItemCount() )
2016 flags
= wxLIST_HITTEST_ONITEM
;
2025 int wxListCtrl::GetScrollPos(int orient
) const
2028 return m_genericImpl
->GetScrollPos(orient
);
2032 UInt32 offsetX
, offsetY
;
2033 m_dbImpl
->GetScrollPosition( &offsetY
, &offsetX
);
2034 if ( orient
== wxHORIZONTAL
)
2043 // Inserts an item, returning the index of the new item if successful,
2045 long wxListCtrl::InsertItem(wxListItem
& info
)
2047 wxASSERT_MSG( !IsVirtual(), _T("can't be used with virtual controls") );
2050 return m_genericImpl
->InsertItem(info
);
2052 if (m_dbImpl
&& !IsVirtual())
2054 int count
= GetItemCount();
2056 if (info
.m_itemId
> count
)
2057 info
.m_itemId
= count
;
2059 m_dbImpl
->MacInsertItem(info
.m_itemId
, &info
);
2061 wxListEvent
event( wxEVT_COMMAND_LIST_INSERT_ITEM
, GetId() );
2062 event
.SetEventObject( this );
2063 event
.m_itemIndex
= info
.m_itemId
;
2064 HandleWindowEvent( event
);
2065 return info
.m_itemId
;
2070 long wxListCtrl::InsertItem(long index
, const wxString
& label
)
2073 return m_genericImpl
->InsertItem(index
, label
);
2076 info
.m_text
= label
;
2077 info
.m_mask
= wxLIST_MASK_TEXT
;
2078 info
.m_itemId
= index
;
2079 return InsertItem(info
);
2082 // Inserts an image item
2083 long wxListCtrl::InsertItem(long index
, int imageIndex
)
2086 return m_genericImpl
->InsertItem(index
, imageIndex
);
2089 info
.m_image
= imageIndex
;
2090 info
.m_mask
= wxLIST_MASK_IMAGE
;
2091 info
.m_itemId
= index
;
2092 return InsertItem(info
);
2095 // Inserts an image/string item
2096 long wxListCtrl::InsertItem(long index
, const wxString
& label
, int imageIndex
)
2099 return m_genericImpl
->InsertItem(index
, label
, imageIndex
);
2102 info
.m_image
= imageIndex
;
2103 info
.m_text
= label
;
2104 info
.m_mask
= wxLIST_MASK_IMAGE
| wxLIST_MASK_TEXT
;
2105 info
.m_itemId
= index
;
2106 return InsertItem(info
);
2109 // For list view mode (only), inserts a column.
2110 long wxListCtrl::InsertColumn(long col
, wxListItem
& item
)
2113 return m_genericImpl
->InsertColumn(col
, item
);
2117 int width
= item
.GetWidth();
2118 if ( !(item
.GetMask() & wxLIST_MASK_WIDTH
) )
2121 DataBrowserPropertyType type
= kDataBrowserCustomType
; //kDataBrowserTextType;
2122 wxImageList
* imageList
= GetImageList(wxIMAGE_LIST_SMALL
);
2123 if (imageList
&& imageList
->GetImageCount() > 0)
2125 wxBitmap bmp
= imageList
->GetBitmap(0);
2127 // type = kDataBrowserIconAndTextType;
2130 SInt16 just
= teFlushDefault
;
2131 if (item
.GetMask() & wxLIST_MASK_FORMAT
)
2133 if (item
.GetAlign() == wxLIST_FORMAT_LEFT
)
2135 else if (item
.GetAlign() == wxLIST_FORMAT_CENTER
)
2137 else if (item
.GetAlign() == wxLIST_FORMAT_RIGHT
)
2138 just
= teFlushRight
;
2140 m_dbImpl
->InsertColumn(col
, type
, item
.GetText(), just
, width
);
2141 SetColumn(col
, item
);
2143 // set/remove options based on the wxListCtrl type.
2144 DataBrowserTableViewColumnID id
;
2145 m_dbImpl
->GetColumnIDFromIndex(col
, &id
);
2146 DataBrowserPropertyFlags flags
;
2147 verify_noerr(m_dbImpl
->GetPropertyFlags(id
, &flags
));
2148 if (GetWindowStyleFlag() & wxLC_EDIT_LABELS
)
2149 flags
|= kDataBrowserPropertyIsEditable
;
2151 if (GetWindowStyleFlag() & wxLC_VIRTUAL
){
2152 flags
&= ~kDataBrowserListViewSortableColumn
;
2154 verify_noerr(m_dbImpl
->SetPropertyFlags(id
, flags
));
2160 long wxListCtrl::InsertColumn(long col
,
2161 const wxString
& heading
,
2166 return m_genericImpl
->InsertColumn(col
, heading
, format
, width
);
2169 item
.m_mask
= wxLIST_MASK_TEXT
| wxLIST_MASK_FORMAT
;
2170 item
.m_text
= heading
;
2173 item
.m_mask
|= wxLIST_MASK_WIDTH
;
2174 item
.m_width
= width
;
2176 item
.m_format
= format
;
2178 return InsertColumn(col
, item
);
2181 // scroll the control by the given number of pixels (exception: in list view,
2182 // dx is interpreted as number of columns)
2183 bool wxListCtrl::ScrollList(int dx
, int dy
)
2186 return m_genericImpl
->ScrollList(dx
, dy
);
2190 m_dbImpl
->SetScrollPosition(dx
, dy
);
2196 bool wxListCtrl::SortItems(wxListCtrlCompare fn
, long data
)
2199 return m_genericImpl
->SortItems(fn
, data
);
2204 m_compareFuncData
= data
;
2205 SortDataBrowserContainer( m_dbImpl
->GetControlRef(), kDataBrowserNoItem
, true);
2207 // we need to do this after each call, else we get a crash from wxPython when
2208 // SortItems is called the second time.
2209 m_compareFunc
= NULL
;
2210 m_compareFuncData
= 0;
2216 void wxListCtrl::OnRenameTimer()
2218 wxCHECK_RET( HasCurrent(), wxT("unexpected rename timer") );
2220 EditLabel( m_current
);
2223 bool wxListCtrl::OnRenameAccept(long itemEdit
, const wxString
& value
)
2225 wxListEvent
le( wxEVT_COMMAND_LIST_END_LABEL_EDIT
, GetId() );
2226 le
.SetEventObject( this );
2227 le
.m_itemIndex
= itemEdit
;
2229 GetItem( le
.m_item
);
2230 le
.m_item
.m_text
= value
;
2231 return !HandleWindowEvent( le
) ||
2235 void wxListCtrl::OnRenameCancelled(long itemEdit
)
2237 // let owner know that the edit was cancelled
2238 wxListEvent
le( wxEVT_COMMAND_LIST_END_LABEL_EDIT
, GetParent()->GetId() );
2240 le
.SetEditCanceled(true);
2242 le
.SetEventObject( this );
2243 le
.m_itemIndex
= itemEdit
;
2245 GetItem( le
.m_item
);
2246 HandleWindowEvent( le
);
2249 // ----------------------------------------------------------------------------
2250 // virtual list controls
2251 // ----------------------------------------------------------------------------
2253 wxString
wxListCtrl::OnGetItemText(long WXUNUSED(item
), long WXUNUSED(col
)) const
2255 // this is a pure virtual function, in fact - which is not really pure
2256 // because the controls which are not virtual don't need to implement it
2257 wxFAIL_MSG( _T("wxListCtrl::OnGetItemText not supposed to be called") );
2259 return wxEmptyString
;
2262 int wxListCtrl::OnGetItemImage(long WXUNUSED(item
)) const
2264 wxCHECK_MSG(!GetImageList(wxIMAGE_LIST_SMALL
),
2266 wxT("List control has an image list, OnGetItemImage or OnGetItemColumnImage should be overridden."));
2270 int wxListCtrl::OnGetItemColumnImage(long item
, long column
) const
2273 return OnGetItemImage(item
);
2278 wxListItemAttr
*wxListCtrl::OnGetItemAttr(long WXUNUSED_UNLESS_DEBUG(item
)) const
2280 wxASSERT_MSG( item
>= 0 && item
< GetItemCount(),
2281 _T("invalid item index in OnGetItemAttr()") );
2283 // no attributes by default
2287 void wxListCtrl::SetItemCount(long count
)
2289 wxASSERT_MSG( IsVirtual(), _T("this is for virtual controls only") );
2293 m_genericImpl
->SetItemCount(count
);
2299 // we need to temporarily disable the new item creation notification
2300 // procedure to speed things up
2301 // FIXME: Even this doesn't seem to help much...
2303 // FIXME: Find a more efficient way to do this.
2304 m_dbImpl
->MacClear();
2306 DataBrowserCallbacks callbacks
;
2307 DataBrowserItemNotificationUPP itemUPP
;
2308 GetDataBrowserCallbacks(m_dbImpl
->GetControlRef(), &callbacks
);
2309 itemUPP
= callbacks
.u
.v1
.itemNotificationCallback
;
2310 callbacks
.u
.v1
.itemNotificationCallback
= 0;
2311 m_dbImpl
->SetCallbacks(&callbacks
);
2312 ::AddDataBrowserItems(m_dbImpl
->GetControlRef(), kDataBrowserNoItem
,
2313 count
, NULL
, kDataBrowserItemNoProperty
);
2314 callbacks
.u
.v1
.itemNotificationCallback
= itemUPP
;
2315 m_dbImpl
->SetCallbacks(&callbacks
);
2320 void wxListCtrl::RefreshItem(long item
)
2324 m_genericImpl
->RefreshItem(item
);
2330 DataBrowserItemID id
;
2334 wxMacDataItem
* thisItem
= m_dbImpl
->GetItemFromLine(item
);
2335 id
= (DataBrowserItemID
) thisItem
;
2340 m_dbImpl
->wxMacDataBrowserControl::UpdateItems
2344 kDataBrowserItemNoProperty
, // preSortProperty
2345 kDataBrowserNoItem
// update all columns
2350 void wxListCtrl::RefreshItems(long itemFrom
, long itemTo
)
2354 m_genericImpl
->RefreshItems(itemFrom
, itemTo
);
2360 const long count
= itemTo
- itemFrom
+ 1;
2361 DataBrowserItemID
*ids
= new DataBrowserItemID
[count
];
2365 for ( long i
= 0; i
< count
; i
++ )
2367 wxMacDataItem
* thisItem
= m_dbImpl
->GetItemFromLine(itemFrom
+i
);
2368 ids
[i
] = (DataBrowserItemID
) thisItem
;
2373 for ( long i
= 0; i
< count
; i
++ )
2374 ids
[i
] = itemFrom
+i
+1;
2377 m_dbImpl
->wxMacDataBrowserControl::UpdateItems
2381 kDataBrowserItemNoProperty
, // preSortProperty
2382 kDataBrowserNoItem
// update all columns
2389 void wxListCtrl::SetDropTarget( wxDropTarget
*dropTarget
)
2391 #if wxUSE_DRAG_AND_DROP
2393 m_genericImpl
->SetDropTarget( dropTarget
);
2396 wxWindow::SetDropTarget( dropTarget
);
2400 wxDropTarget
*wxListCtrl::GetDropTarget() const
2402 #if wxUSE_DRAG_AND_DROP
2404 return m_genericImpl
->GetDropTarget();
2407 return wxWindow::GetDropTarget();
2412 #if wxABI_VERSION >= 20801
2413 void wxListCtrl::SetFocus()
2417 m_genericImpl
->SetFocus();
2421 wxWindow::SetFocus();
2425 // wxMac internal data structures
2427 wxMacListCtrlItem::~wxMacListCtrlItem()
2429 WX_CLEAR_HASH_MAP( wxListItemList
, m_rowItems
);
2432 void wxMacListCtrlItem::Notification(wxMacDataItemBrowserControl
*owner
,
2433 DataBrowserItemNotification message
,
2434 DataBrowserItemDataRef
WXUNUSED(itemData
) ) const
2437 wxMacDataBrowserListCtrlControl
*lb
= wxDynamicCast(owner
, wxMacDataBrowserListCtrlControl
);
2439 // we want to depend on as little as possible to make sure tear-down of controls is safe
2440 if ( message
== kDataBrowserItemRemoved
)
2445 else if ( message
== kDataBrowserItemAdded
)
2447 // we don't issue events on adding, the item is not really stored in the list yet, so we
2448 // avoid asserts by gettting out now
2452 wxListCtrl
*list
= wxDynamicCast( owner
->GetWXPeer() , wxListCtrl
);
2455 bool trigger
= false;
2457 wxListEvent
event( wxEVT_COMMAND_LIST_ITEM_SELECTED
, list
->GetId() );
2458 bool isSingle
= (list
->GetWindowStyle() & wxLC_SINGLE_SEL
) != 0;
2460 event
.SetEventObject( list
);
2461 event
.m_itemIndex
= owner
->GetLineFromItem( this ) ;
2462 event
.m_item
.m_itemId
= event
.m_itemIndex
;
2463 list
->GetItem(event
.m_item
);
2467 case kDataBrowserItemDeselected
:
2468 event
.SetEventType(wxEVT_COMMAND_LIST_ITEM_DESELECTED
);
2470 trigger
= !lb
->IsSelectionSuppressed();
2473 case kDataBrowserItemSelected
:
2474 trigger
= !lb
->IsSelectionSuppressed();
2477 case kDataBrowserItemDoubleClicked
:
2478 event
.SetEventType( wxEVT_COMMAND_LIST_ITEM_ACTIVATED
);
2482 case kDataBrowserEditStarted
:
2483 // TODO : how to veto ?
2484 event
.SetEventType( wxEVT_COMMAND_LIST_BEGIN_LABEL_EDIT
) ;
2488 case kDataBrowserEditStopped
:
2489 // TODO probably trigger only upon the value store callback, because
2490 // here IIRC we cannot veto
2491 event
.SetEventType( wxEVT_COMMAND_LIST_END_LABEL_EDIT
) ;
2501 // direct notification is not always having the listbox GetSelection() having in synch with event
2502 wxPostEvent( list
->GetEventHandler(), event
);
2508 IMPLEMENT_DYNAMIC_CLASS(wxMacDataBrowserListCtrlControl
, wxMacDataItemBrowserControl
)
2510 wxMacDataBrowserListCtrlControl::wxMacDataBrowserListCtrlControl( wxWindow
*peer
, const wxPoint
& pos
, const wxSize
& size
, long style
)
2511 : wxMacDataItemBrowserControl( peer
, pos
, size
, style
)
2513 OSStatus err
= noErr
;
2514 m_clientDataItemsType
= wxClientData_None
;
2515 m_isVirtual
= false;
2518 if ( style
& wxLC_VIRTUAL
)
2521 DataBrowserSelectionFlags options
= kDataBrowserDragSelect
;
2522 if ( style
& wxLC_SINGLE_SEL
)
2524 options
|= kDataBrowserSelectOnlyOne
;
2528 options
|= kDataBrowserCmdTogglesSelection
;
2531 err
= SetSelectionFlags( options
);
2532 verify_noerr( err
);
2534 DataBrowserCustomCallbacks callbacks
;
2535 InitializeDataBrowserCustomCallbacks( &callbacks
, kDataBrowserLatestCustomCallbacks
);
2537 if ( gDataBrowserDrawItemUPP
== NULL
)
2538 gDataBrowserDrawItemUPP
= NewDataBrowserDrawItemUPP(DataBrowserDrawItemProc
);
2540 if ( gDataBrowserHitTestUPP
== NULL
)
2541 gDataBrowserHitTestUPP
= NewDataBrowserHitTestUPP(DataBrowserHitTestProc
);
2543 callbacks
.u
.v1
.drawItemCallback
= gDataBrowserDrawItemUPP
;
2544 callbacks
.u
.v1
.hitTestCallback
= gDataBrowserHitTestUPP
;
2546 SetDataBrowserCustomCallbacks( GetControlRef(), &callbacks
);
2548 if ( style
& wxLC_LIST
)
2550 InsertColumn(0, kDataBrowserIconAndTextType
, wxEmptyString
, -1, -1);
2551 verify_noerr( AutoSizeColumns() );
2554 if ( style
& wxLC_LIST
|| style
& wxLC_NO_HEADER
)
2555 verify_noerr( SetHeaderButtonHeight( 0 ) );
2558 SetSortProperty( kMinColumnId
- 1 );
2560 SetSortProperty( kMinColumnId
);
2562 m_sortOrder
= SortOrder_None
;
2564 if ( style
& wxLC_SORT_DESCENDING
)
2566 SetSortOrder( kDataBrowserOrderDecreasing
);
2568 else if ( style
& wxLC_SORT_ASCENDING
)
2570 SetSortOrder( kDataBrowserOrderIncreasing
);
2573 if ( style
& wxLC_VRULES
)
2575 verify_noerr( DataBrowserChangeAttributes(m_controlRef
, kDataBrowserAttributeListViewDrawColumnDividers
, kDataBrowserAttributeNone
) );
2578 verify_noerr( SetHiliteStyle(kDataBrowserTableViewFillHilite
) );
2579 verify_noerr( SetHasScrollBars( (style
& wxHSCROLL
) != 0 , true ) );
2582 pascal Boolean
wxMacDataBrowserListCtrlControl::DataBrowserEditTextProc(
2584 DataBrowserItemID itemID
,
2585 DataBrowserPropertyID property
,
2586 CFStringRef theString
,
2587 Rect
*maxEditTextRect
,
2588 Boolean
*shrinkToFit
)
2590 Boolean result
= false;
2591 wxMacDataBrowserListCtrlControl
* ctl
= wxDynamicCast(wxMacControl::GetReferenceFromNativeControl( browser
), wxMacDataBrowserListCtrlControl
);
2594 result
= ctl
->ConfirmEditText(itemID
, property
, theString
, maxEditTextRect
, shrinkToFit
);
2595 theString
= CFSTR("Hello!");
2600 bool wxMacDataBrowserListCtrlControl::ConfirmEditText(
2601 DataBrowserItemID
WXUNUSED(itemID
),
2602 DataBrowserPropertyID
WXUNUSED(property
),
2603 CFStringRef
WXUNUSED(theString
),
2604 Rect
*WXUNUSED(maxEditTextRect
),
2605 Boolean
*WXUNUSED(shrinkToFit
))
2610 pascal void wxMacDataBrowserListCtrlControl::DataBrowserDrawItemProc(
2612 DataBrowserItemID itemID
,
2613 DataBrowserPropertyID property
,
2614 DataBrowserItemState itemState
,
2615 const Rect
*itemRect
,
2617 Boolean colorDevice
)
2619 wxMacDataBrowserListCtrlControl
* ctl
= wxDynamicCast(wxMacControl::GetReferenceFromNativeControl( browser
), wxMacDataBrowserListCtrlControl
);
2622 ctl
->DrawItem(itemID
, property
, itemState
, itemRect
, gdDepth
, colorDevice
);
2626 // routines needed for DrawItem
2631 kTextBoxHeight
= 14,
2632 kIconTextSpacingV
= 2,
2634 kContentHeight
= kIconHeight
+ kTextBoxHeight
+ kIconTextSpacingV
2637 static void calculateCGDrawingBounds(CGRect inItemRect
, CGRect
*outIconRect
, CGRect
*outTextRect
, bool hasIcon
= false)
2640 float iconH
, iconW
= 0;
2641 float padding
= kItemPadding
;
2644 iconH
= kIconHeight
;
2646 padding
= padding
*2;
2649 textBottom
= inItemRect
.origin
.y
;
2651 *outIconRect
= CGRectMake(inItemRect
.origin
.x
+ kItemPadding
,
2652 textBottom
+ kIconTextSpacingV
, kIconWidth
,
2655 *outTextRect
= CGRectMake(inItemRect
.origin
.x
+ padding
+ iconW
,
2656 textBottom
+ kIconTextSpacingV
, inItemRect
.size
.width
- padding
- iconW
,
2657 inItemRect
.size
.height
- kIconTextSpacingV
);
2660 void wxMacDataBrowserListCtrlControl::DrawItem(
2661 DataBrowserItemID itemID
,
2662 DataBrowserPropertyID property
,
2663 DataBrowserItemState itemState
,
2664 const Rect
*WXUNUSED(itemRect
),
2666 Boolean colorDevice
)
2669 wxFont font
= wxNullFont
;
2671 short listColumn
= property
- kMinColumnId
;
2673 wxListCtrl
* list
= wxDynamicCast( GetWXPeer() , wxListCtrl
);
2674 wxMacListCtrlItem
* lcItem
;
2675 wxColour color
= *wxBLACK
;
2676 wxColour bgColor
= wxNullColour
;
2678 if (listColumn
>= 0)
2682 lcItem
= (wxMacListCtrlItem
*) itemID
;
2683 if (lcItem
->HasColumnInfo(listColumn
)){
2684 wxListItem
* item
= lcItem
->GetColumnInfo(listColumn
);
2686 // we always use the 0 column to get font and text/background colors.
2687 if (lcItem
->HasColumnInfo(0))
2689 wxListItem
* firstItem
= lcItem
->GetColumnInfo(0);
2690 color
= firstItem
->GetTextColour();
2691 bgColor
= firstItem
->GetBackgroundColour();
2692 font
= firstItem
->GetFont();
2695 if (item
->GetMask() & wxLIST_MASK_TEXT
)
2696 text
= item
->GetText();
2697 if (item
->GetMask() & wxLIST_MASK_IMAGE
)
2698 imgIndex
= item
->GetImage();
2704 long itemNum
= (long)itemID
-1;
2705 if (itemNum
>= 0 && itemNum
< list
->GetItemCount())
2707 text
= list
->OnGetItemText( itemNum
, listColumn
);
2708 imgIndex
= list
->OnGetItemColumnImage( itemNum
, listColumn
);
2709 wxListItemAttr
* attrs
= list
->OnGetItemAttr( itemNum
);
2712 if (attrs
->HasBackgroundColour())
2713 bgColor
= attrs
->GetBackgroundColour();
2714 if (attrs
->HasTextColour())
2715 color
= attrs
->GetTextColour();
2716 if (attrs
->HasFont())
2717 font
= attrs
->GetFont();
2723 wxColour listBgColor
= list
->GetBackgroundColour();
2724 if (bgColor
== wxNullColour
)
2725 bgColor
= listBgColor
;
2728 font
= list
->GetFont();
2730 wxCFStringRef
cfString( text
, wxLocale::GetSystemEncoding() );
2733 CGRect enclosingCGRect
, iconCGRect
, textCGRect
;
2735 ThemeDrawingState savedState
= NULL
;
2736 CGContextRef context
= (CGContextRef
)list
->MacGetDrawingContext();
2737 RGBColor labelColor
;
2739 labelColor
.green
= 0;
2740 labelColor
.blue
= 0;
2742 RGBColor backgroundColor
;
2743 backgroundColor
.red
= 255;
2744 backgroundColor
.green
= 255;
2745 backgroundColor
.blue
= 255;
2747 GetDataBrowserItemPartBounds(GetControlRef(), itemID
, property
, kDataBrowserPropertyEnclosingPart
,
2750 enclosingCGRect
= CGRectMake(enclosingRect
.left
,
2752 enclosingRect
.right
- enclosingRect
.left
,
2753 enclosingRect
.bottom
- enclosingRect
.top
);
2755 bool hasFocus
= (wxWindow::FindFocus() == list
);
2756 active
= IsControlActive(GetControlRef());
2758 // don't paint the background over the vertical rule line
2759 if ( list
->GetWindowStyleFlag() & wxLC_VRULES
)
2761 enclosingCGRect
.origin
.x
+= 1;
2762 enclosingCGRect
.size
.width
-= 1;
2764 if (itemState
== kDataBrowserItemIsSelected
)
2767 GetThemeDrawingState(&savedState
);
2769 if (active
&& hasFocus
)
2771 GetThemeBrushAsColor(kThemeBrushAlternatePrimaryHighlightColor
, 32, true, &backgroundColor
);
2772 GetThemeTextColor(kThemeTextColorWhite
, gdDepth
, colorDevice
, &labelColor
);
2776 GetThemeBrushAsColor(kThemeBrushSecondaryHighlightColor
, 32, true, &backgroundColor
);
2777 GetThemeTextColor(kThemeTextColorBlack
, gdDepth
, colorDevice
, &labelColor
);
2779 CGContextSaveGState(context
);
2781 CGContextSetRGBFillColor(context
, (CGFloat
)backgroundColor
.red
/ (CGFloat
)USHRT_MAX
,
2782 (CGFloat
)backgroundColor
.green
/ (CGFloat
)USHRT_MAX
,
2783 (CGFloat
)backgroundColor
.blue
/ (CGFloat
)USHRT_MAX
, (CGFloat
) 1.0);
2784 CGContextFillRect(context
, enclosingCGRect
);
2786 CGContextRestoreGState(context
);
2792 color
.GetRGBColor(&labelColor
);
2793 else if (list
->GetTextColour().Ok())
2794 list
->GetTextColour().GetRGBColor(&labelColor
);
2798 bgColor
.GetRGBColor(&backgroundColor
);
2799 CGContextSaveGState(context
);
2801 CGContextSetRGBFillColor(context
, (CGFloat
)backgroundColor
.red
/ (CGFloat
)USHRT_MAX
,
2802 (CGFloat
)backgroundColor
.green
/ (CGFloat
)USHRT_MAX
,
2803 (CGFloat
)backgroundColor
.blue
/ (CGFloat
)USHRT_MAX
, (CGFloat
) 1.0);
2804 CGContextFillRect(context
, enclosingCGRect
);
2806 CGContextRestoreGState(context
);
2810 calculateCGDrawingBounds(enclosingCGRect
, &iconCGRect
, &textCGRect
, (imgIndex
!= -1) );
2814 wxImageList
* imageList
= list
->GetImageList(wxIMAGE_LIST_SMALL
);
2815 if (imageList
&& imageList
->GetImageCount() > 0){
2816 wxBitmap bmp
= imageList
->GetBitmap(imgIndex
);
2817 IconRef icon
= bmp
.GetIconRef();
2819 CGContextSaveGState(context
);
2820 CGContextTranslateCTM(context
, 0,iconCGRect
.origin
.y
+ CGRectGetMaxY(iconCGRect
));
2821 CGContextScaleCTM(context
,1.0f
,-1.0f
);
2822 PlotIconRefInContext(context
, &iconCGRect
, kAlignNone
,
2823 active
? kTransformNone
: kTransformDisabled
, NULL
,
2824 kPlotIconRefNormalFlags
, icon
);
2826 CGContextRestoreGState(context
);
2830 HIThemeTextHorizontalFlush hFlush
= kHIThemeTextHorizontalFlushLeft
;
2831 HIThemeTextInfo info
;
2833 #if wxOSX_USE_CORE_TEXT
2834 if ( UMAGetSystemVersion() >= 0x1050 )
2836 info
.version
= kHIThemeTextInfoVersionOne
;
2837 info
.fontID
= kThemeViewsFont
;
2840 info
.fontID
= kThemeSpecifiedFont
;
2841 info
.font
= (CTFontRef
) font
.MacGetCTFont();
2846 #if wxOSX_USE_ATSU_TEXT
2849 info
.version
= kHIThemeTextInfoVersionZero
;
2850 info
.fontID
= kThemeViewsFont
;
2854 info
.fontID
= font
.MacGetThemeFontID();
2856 ::TextSize( (short)(font
.MacGetFontSize()) ) ;
2857 ::TextFace( font
.MacGetFontStyle() ) ;
2863 list
->GetColumn(listColumn
, item
);
2864 if (item
.GetMask() & wxLIST_MASK_FORMAT
)
2866 if (item
.GetAlign() == wxLIST_FORMAT_LEFT
)
2867 hFlush
= kHIThemeTextHorizontalFlushLeft
;
2868 else if (item
.GetAlign() == wxLIST_FORMAT_CENTER
)
2869 hFlush
= kHIThemeTextHorizontalFlushCenter
;
2870 else if (item
.GetAlign() == wxLIST_FORMAT_RIGHT
)
2872 hFlush
= kHIThemeTextHorizontalFlushRight
;
2873 textCGRect
.origin
.x
-= kItemPadding
; // give a little extra paddding
2877 info
.state
= active
? kThemeStateActive
: kThemeStateInactive
;
2878 info
.horizontalFlushness
= hFlush
;
2879 info
.verticalFlushness
= kHIThemeTextVerticalFlushCenter
;
2880 info
.options
= kHIThemeTextBoxOptionNone
;
2881 info
.truncationPosition
= kHIThemeTextTruncationEnd
;
2882 info
.truncationMaxLines
= 1;
2884 CGContextSaveGState(context
);
2885 CGContextSetRGBFillColor (context
, (CGFloat
)labelColor
.red
/ (CGFloat
)USHRT_MAX
,
2886 (CGFloat
)labelColor
.green
/ (CGFloat
)USHRT_MAX
,
2887 (CGFloat
)labelColor
.blue
/ (CGFloat
)USHRT_MAX
, (CGFloat
) 1.0);
2889 HIThemeDrawTextBox(cfString
, &textCGRect
, &info
, context
, kHIThemeOrientationNormal
);
2891 CGContextRestoreGState(context
);
2894 if (savedState
!= NULL
)
2895 SetThemeDrawingState(savedState
, true);
2899 OSStatus
wxMacDataBrowserListCtrlControl::GetSetItemData(DataBrowserItemID itemID
,
2900 DataBrowserPropertyID property
,
2901 DataBrowserItemDataRef itemData
,
2902 Boolean changeValue
)
2906 short listColumn
= property
- kMinColumnId
;
2908 OSStatus err
= errDataBrowserPropertyNotSupported
;
2909 wxListCtrl
* list
= wxDynamicCast( GetWXPeer() , wxListCtrl
);
2910 wxMacListCtrlItem
* lcItem
= NULL
;
2912 if (listColumn
>= 0)
2916 lcItem
= (wxMacListCtrlItem
*) itemID
;
2917 if (lcItem
&& lcItem
->HasColumnInfo(listColumn
)){
2918 wxListItem
* item
= lcItem
->GetColumnInfo(listColumn
);
2919 if (item
->GetMask() & wxLIST_MASK_TEXT
)
2920 text
= item
->GetText();
2921 if (item
->GetMask() & wxLIST_MASK_IMAGE
)
2922 imgIndex
= item
->GetImage();
2927 long itemNum
= (long)itemID
-1;
2928 if (itemNum
>= 0 && itemNum
< list
->GetItemCount())
2930 text
= list
->OnGetItemText( itemNum
, listColumn
);
2931 imgIndex
= list
->OnGetItemColumnImage( itemNum
, listColumn
);
2940 case kDataBrowserItemIsEditableProperty
:
2941 if ( list
&& list
->HasFlag( wxLC_EDIT_LABELS
) )
2943 verify_noerr(SetDataBrowserItemDataBooleanValue( itemData
, true ));
2948 if ( property
>= kMinColumnId
)
2950 if (!text
.IsEmpty()){
2951 wxCFStringRef
cfStr( text
, wxLocale::GetSystemEncoding() );
2952 err
= ::SetDataBrowserItemDataText( itemData
, cfStr
);
2958 if ( imgIndex
!= -1 )
2960 wxImageList
* imageList
= list
->GetImageList(wxIMAGE_LIST_SMALL
);
2961 if (imageList
&& imageList
->GetImageCount() > 0){
2962 wxBitmap bmp
= imageList
->GetBitmap(imgIndex
);
2963 IconRef icon
= bmp
.GetIconRef();
2964 ::SetDataBrowserItemDataIcon(itemData
, icon
);
2978 if ( property
>= kMinColumnId
)
2980 short listColumn
= property
- kMinColumnId
;
2982 // TODO probably send the 'end edit' from here, as we
2983 // can then deal with the veto
2985 verify_noerr( GetDataBrowserItemDataText( itemData
, &sr
) ) ;
2986 wxCFStringRef
cfStr(sr
) ;;
2988 list
->SetItem( (long)itemData
-1 , listColumn
, cfStr
.AsString() ) ;
2992 lcItem
->SetColumnTextValue( listColumn
, cfStr
.AsString() );
3002 void wxMacDataBrowserListCtrlControl::ItemNotification(DataBrowserItemID itemID
,
3003 DataBrowserItemNotification message
,
3004 DataBrowserItemDataRef itemData
)
3006 wxMacListCtrlItem
*item
= NULL
;
3009 item
= (wxMacListCtrlItem
*) itemID
;
3012 // we want to depend on as little as possible to make sure tear-down of controls is safe
3013 if ( message
== kDataBrowserItemRemoved
)
3016 item
->Notification(this, message
, itemData
);
3019 else if ( message
== kDataBrowserItemAdded
)
3021 // we don't issue events on adding, the item is not really stored in the list yet, so we
3022 // avoid asserts by getting out now
3024 item
->Notification(this, message
, itemData
);
3028 wxListCtrl
*list
= wxDynamicCast( GetWXPeer() , wxListCtrl
);
3031 bool trigger
= false;
3033 wxListEvent
event( wxEVT_COMMAND_LIST_ITEM_SELECTED
, list
->GetId() );
3035 event
.SetEventObject( list
);
3036 if ( !list
->IsVirtual() )
3038 DataBrowserTableViewRowIndex result
= 0;
3039 verify_noerr( GetItemRow( itemID
, &result
) ) ;
3040 event
.m_itemIndex
= result
;
3044 event
.m_itemIndex
= (long)itemID
-1;
3046 event
.m_item
.m_itemId
= event
.m_itemIndex
;
3047 list
->GetItem(event
.m_item
);
3051 case kDataBrowserItemDeselected
:
3052 event
.SetEventType(wxEVT_COMMAND_LIST_ITEM_DESELECTED
);
3053 // as the generic implementation is also triggering this
3054 // event for single selection, we do the same (different than listbox)
3055 trigger
= !IsSelectionSuppressed();
3058 case kDataBrowserItemSelected
:
3059 trigger
= !IsSelectionSuppressed();
3063 case kDataBrowserItemDoubleClicked
:
3064 event
.SetEventType( wxEVT_COMMAND_LIST_ITEM_ACTIVATED
);
3068 case kDataBrowserEditStarted
:
3069 // TODO : how to veto ?
3070 event
.SetEventType( wxEVT_COMMAND_LIST_BEGIN_LABEL_EDIT
) ;
3074 case kDataBrowserEditStopped
:
3075 // TODO probably trigger only upon the value store callback, because
3076 // here IIRC we cannot veto
3077 event
.SetEventType( wxEVT_COMMAND_LIST_END_LABEL_EDIT
) ;
3087 // direct notification is not always having the listbox GetSelection() having in synch with event
3088 wxPostEvent( list
->GetEventHandler(), event
);
3093 Boolean
wxMacDataBrowserListCtrlControl::CompareItems(DataBrowserItemID itemOneID
,
3094 DataBrowserItemID itemTwoID
,
3095 DataBrowserPropertyID sortProperty
)
3098 bool retval
= false;
3100 wxString otherItemText
;
3102 long otherItemOrder
;
3104 int colId
= sortProperty
- kMinColumnId
;
3106 wxListCtrl
* list
= wxDynamicCast( GetWXPeer() , wxListCtrl
);
3108 DataBrowserSortOrder sort
;
3109 verify_noerr(GetSortOrder(&sort
));
3115 wxMacListCtrlItem
* item
= (wxMacListCtrlItem
*)itemOneID
;
3116 wxMacListCtrlItem
* otherItem
= (wxMacListCtrlItem
*)itemTwoID
;
3118 itemOrder
= item
->GetOrder();
3119 otherItemOrder
= otherItem
->GetOrder();
3121 wxListCtrlCompare func
= list
->GetCompareFunc();
3127 if (item
&& item
->HasColumnInfo(0))
3128 item1
= item
->GetColumnInfo(0)->GetData();
3129 if (otherItem
&& otherItem
->HasColumnInfo(0))
3130 item2
= otherItem
->GetColumnInfo(0)->GetData();
3132 if (item1
> -1 && item2
> -1)
3134 int result
= func(item1
, item2
, list
->GetCompareFuncData());
3135 if (sort
== kDataBrowserOrderIncreasing
)
3142 // we can't use the native control's sorting abilities, so just
3144 return itemOrder
< otherItemOrder
;
3149 long itemNum
= (long)itemOneID
;
3150 long otherItemNum
= (long)itemTwoID
;
3152 // virtual listctrls don't support sorting
3153 return itemNum
< otherItemNum
;
3157 // fallback for undefined cases
3158 retval
= itemOneID
< itemTwoID
;
3164 wxMacDataBrowserListCtrlControl::~wxMacDataBrowserListCtrlControl()
3168 void wxMacDataBrowserListCtrlControl::MacSetColumnInfo( unsigned int row
, unsigned int column
, wxListItem
* item
)
3170 wxMacDataItem
* dataItem
= GetItemFromLine(row
);
3171 wxASSERT_MSG( dataItem
, _T("could not obtain wxMacDataItem for row in MacSetColumnInfo. Is row a valid wxListCtrl row?") );
3174 wxMacListCtrlItem
* listItem
= static_cast<wxMacListCtrlItem
*>(dataItem
);
3175 bool hasInfo
= listItem
->HasColumnInfo( column
);
3176 listItem
->SetColumnInfo( column
, item
);
3177 listItem
->SetOrder(row
);
3178 UpdateState(dataItem
, item
);
3180 wxListCtrl
* list
= wxDynamicCast( GetWXPeer() , wxListCtrl
);
3182 // NB: When this call was made before a control was completely shown, it would
3183 // update the item prematurely (i.e. no text would be listed) and, on show,
3184 // only the sorted column would be refreshed, meaning only first column text labels
3185 // would be shown. Making sure not to update items until the control is visible
3186 // seems to fix this issue.
3187 if (hasInfo
&& list
->IsShown())
3188 UpdateItem( wxMacDataBrowserRootContainer
, listItem
, kMinColumnId
+ column
);
3192 // apply changes that need to happen immediately, rather than when the
3193 // databrowser control fires a callback.
3194 void wxMacDataBrowserListCtrlControl::UpdateState(wxMacDataItem
* dataItem
, wxListItem
* listItem
)
3196 bool isSelected
= IsItemSelected( dataItem
);
3197 bool isSelectedState
= (listItem
->GetState() == wxLIST_STATE_SELECTED
);
3199 // toggle the selection state if wxListInfo state and actual state don't match.
3200 if ( listItem
->GetMask() & wxLIST_MASK_STATE
&& isSelected
!= isSelectedState
)
3202 DataBrowserSetOption options
= kDataBrowserItemsAdd
;
3203 if (!isSelectedState
)
3204 options
= kDataBrowserItemsRemove
;
3205 SetSelectedItem(dataItem
, options
);
3207 // TODO: Set column width if item width > than current column width
3210 void wxMacDataBrowserListCtrlControl::MacGetColumnInfo( unsigned int row
, unsigned int column
, wxListItem
& item
)
3212 wxMacDataItem
* dataItem
= GetItemFromLine(row
);
3213 wxASSERT_MSG( dataItem
, _T("could not obtain wxMacDataItem in MacGetColumnInfo. Is row a valid wxListCtrl row?") );
3214 // CS should this guard against dataItem = 0 ? , as item is not a pointer if (item) is not appropriate
3217 wxMacListCtrlItem
* listItem
= static_cast<wxMacListCtrlItem
*>(dataItem
);
3219 if (!listItem
->HasColumnInfo( column
))
3222 wxListItem
* oldItem
= listItem
->GetColumnInfo( column
);
3226 long mask
= item
.GetMask();
3228 // by default, get everything for backwards compatibility
3231 if ( mask
& wxLIST_MASK_TEXT
)
3232 item
.SetText(oldItem
->GetText());
3233 if ( mask
& wxLIST_MASK_IMAGE
)
3234 item
.SetImage(oldItem
->GetImage());
3235 if ( mask
& wxLIST_MASK_DATA
)
3236 item
.SetData(oldItem
->GetData());
3237 if ( mask
& wxLIST_MASK_STATE
)
3238 item
.SetState(oldItem
->GetState());
3239 if ( mask
& wxLIST_MASK_WIDTH
)
3240 item
.SetWidth(oldItem
->GetWidth());
3241 if ( mask
& wxLIST_MASK_FORMAT
)
3242 item
.SetAlign(oldItem
->GetAlign());
3244 item
.SetTextColour(oldItem
->GetTextColour());
3245 item
.SetBackgroundColour(oldItem
->GetBackgroundColour());
3246 item
.SetFont(oldItem
->GetFont());
3251 void wxMacDataBrowserListCtrlControl::MacInsertItem( unsigned int n
, wxListItem
* item
)
3254 wxMacDataItemBrowserControl::MacInsert(n
, new wxMacListCtrlItem() );
3255 MacSetColumnInfo(n
, 0, item
);
3258 wxMacListCtrlItem::wxMacListCtrlItem()
3260 m_rowItems
= wxListItemList();
3263 int wxMacListCtrlItem::GetColumnImageValue( unsigned int column
)
3265 if ( HasColumnInfo(column
) )
3266 return GetColumnInfo(column
)->GetImage();
3271 void wxMacListCtrlItem::SetColumnImageValue( unsigned int column
, int imageIndex
)
3273 if ( HasColumnInfo(column
) )
3274 GetColumnInfo(column
)->SetImage(imageIndex
);
3277 wxString
wxMacListCtrlItem::GetColumnTextValue( unsigned int column
)
3279 /* TODO CHECK REMOVE
3283 if ( HasColumnInfo(column
) )
3284 return GetColumnInfo(column
)->GetText();
3286 return wxEmptyString
;
3289 void wxMacListCtrlItem::SetColumnTextValue( unsigned int column
, const wxString
& text
)
3291 if ( HasColumnInfo(column
) )
3292 GetColumnInfo(column
)->SetText(text
);
3294 /* TODO CHECK REMOVE
3295 // for compatibility with superclass APIs
3301 wxListItem
* wxMacListCtrlItem::GetColumnInfo( unsigned int column
)
3303 wxASSERT_MSG( HasColumnInfo(column
), _T("invalid column index in wxMacListCtrlItem") );
3304 return m_rowItems
[column
];
3307 bool wxMacListCtrlItem::HasColumnInfo( unsigned int column
)
3309 return !(m_rowItems
.find( column
) == m_rowItems
.end());
3312 void wxMacListCtrlItem::SetColumnInfo( unsigned int column
, wxListItem
* item
)
3315 if ( !HasColumnInfo(column
) )
3317 wxListItem
* listItem
= new wxListItem(*item
);
3318 m_rowItems
[column
] = listItem
;
3322 wxListItem
* listItem
= GetColumnInfo( column
);
3323 long mask
= item
->GetMask();
3324 if (mask
& wxLIST_MASK_TEXT
)
3325 listItem
->SetText(item
->GetText());
3326 if (mask
& wxLIST_MASK_DATA
)
3327 listItem
->SetData(item
->GetData());
3328 if (mask
& wxLIST_MASK_IMAGE
)
3329 listItem
->SetImage(item
->GetImage());
3330 if (mask
& wxLIST_MASK_STATE
)
3331 listItem
->SetState(item
->GetState());
3332 if (mask
& wxLIST_MASK_FORMAT
)
3333 listItem
->SetAlign(item
->GetAlign());
3334 if (mask
& wxLIST_MASK_WIDTH
)
3335 listItem
->SetWidth(item
->GetWidth());
3337 if ( item
->HasAttributes() )
3339 if ( listItem
->HasAttributes() )
3340 listItem
->GetAttributes()->AssignFrom(*item
->GetAttributes());
3343 listItem
->SetTextColour(item
->GetTextColour());
3344 listItem
->SetBackgroundColour(item
->GetBackgroundColour());
3345 listItem
->SetFont(item
->GetFont());
3351 int wxListCtrl::CalcColumnAutoWidth(int col
) const
3355 for ( int i
= 0; i
< GetItemCount(); i
++ )
3358 info
.SetMask(wxLIST_MASK_TEXT
| wxLIST_MASK_IMAGE
);
3360 info
.SetColumn(col
);
3363 const wxFont font
= info
.GetFont();
3367 GetTextExtent(info
.GetText(), &w
, NULL
, NULL
, NULL
, &font
);
3369 GetTextExtent(info
.GetText(), &w
, NULL
);
3371 w
+= 2 * kItemPadding
;
3373 if ( info
.GetImage() != -1 )
3376 width
= wxMax(width
, w
);
3382 #endif // wxUSE_LISTCTRL