1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/mac/listctrl_mac.cpp
4 // Author: Julian Smart
5 // Modified by: Agron Selimaj
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 // ============================================================================
14 // ============================================================================
16 // ----------------------------------------------------------------------------
18 // ----------------------------------------------------------------------------
20 // For compilers that support precompilation, includes "wx.h".
21 #include "wx/wxprec.h"
29 #include "wx/listctrl.h"
35 #include "wx/mac/uma.h"
37 #include "wx/imaglist.h"
38 #include "wx/sysopt.h"
41 #include "wx/hashmap.h"
43 #if wxUSE_EXTENDED_RTTI
44 WX_DEFINE_FLAGS( wxListCtrlStyle
)
46 wxBEGIN_FLAGS( wxListCtrlStyle
)
47 // new style border flags, we put them first to
48 // use them for streaming out
49 wxFLAGS_MEMBER(wxBORDER_SIMPLE
)
50 wxFLAGS_MEMBER(wxBORDER_SUNKEN
)
51 wxFLAGS_MEMBER(wxBORDER_DOUBLE
)
52 wxFLAGS_MEMBER(wxBORDER_RAISED
)
53 wxFLAGS_MEMBER(wxBORDER_STATIC
)
54 wxFLAGS_MEMBER(wxBORDER_NONE
)
56 // old style border flags
57 wxFLAGS_MEMBER(wxSIMPLE_BORDER
)
58 wxFLAGS_MEMBER(wxSUNKEN_BORDER
)
59 wxFLAGS_MEMBER(wxDOUBLE_BORDER
)
60 wxFLAGS_MEMBER(wxRAISED_BORDER
)
61 wxFLAGS_MEMBER(wxSTATIC_BORDER
)
62 wxFLAGS_MEMBER(wxBORDER
)
64 // standard window styles
65 wxFLAGS_MEMBER(wxTAB_TRAVERSAL
)
66 wxFLAGS_MEMBER(wxCLIP_CHILDREN
)
67 wxFLAGS_MEMBER(wxTRANSPARENT_WINDOW
)
68 wxFLAGS_MEMBER(wxWANTS_CHARS
)
69 wxFLAGS_MEMBER(wxFULL_REPAINT_ON_RESIZE
)
70 wxFLAGS_MEMBER(wxALWAYS_SHOW_SB
)
71 wxFLAGS_MEMBER(wxVSCROLL
)
72 wxFLAGS_MEMBER(wxHSCROLL
)
74 wxFLAGS_MEMBER(wxLC_LIST
)
75 wxFLAGS_MEMBER(wxLC_REPORT
)
76 wxFLAGS_MEMBER(wxLC_ICON
)
77 wxFLAGS_MEMBER(wxLC_SMALL_ICON
)
78 wxFLAGS_MEMBER(wxLC_ALIGN_TOP
)
79 wxFLAGS_MEMBER(wxLC_ALIGN_LEFT
)
80 wxFLAGS_MEMBER(wxLC_AUTOARRANGE
)
81 wxFLAGS_MEMBER(wxLC_USER_TEXT
)
82 wxFLAGS_MEMBER(wxLC_EDIT_LABELS
)
83 wxFLAGS_MEMBER(wxLC_NO_HEADER
)
84 wxFLAGS_MEMBER(wxLC_SINGLE_SEL
)
85 wxFLAGS_MEMBER(wxLC_SORT_ASCENDING
)
86 wxFLAGS_MEMBER(wxLC_SORT_DESCENDING
)
87 wxFLAGS_MEMBER(wxLC_VIRTUAL
)
89 wxEND_FLAGS( wxListCtrlStyle
)
91 IMPLEMENT_DYNAMIC_CLASS_XTI(wxListCtrl
, wxControl
,"wx/listctrl.h")
93 wxBEGIN_PROPERTIES_TABLE(wxListCtrl
)
94 wxEVENT_PROPERTY( TextUpdated
, wxEVT_COMMAND_TEXT_UPDATED
, wxCommandEvent
)
96 wxPROPERTY_FLAGS( WindowStyle
, wxListCtrlStyle
, long , SetWindowStyleFlag
, GetWindowStyleFlag
, EMPTY_MACROVALUE
, 0 /*flags*/ , wxT("Helpstring") , wxT("group")) // style
97 wxEND_PROPERTIES_TABLE()
99 wxBEGIN_HANDLERS_TABLE(wxListCtrl
)
100 wxEND_HANDLERS_TABLE()
102 wxCONSTRUCTOR_5( wxListCtrl
, wxWindow
* , Parent
, wxWindowID
, Id
, wxPoint
, Position
, wxSize
, Size
, long , WindowStyle
)
105 TODO : Expose more information of a list's layout etc. via appropriate objects (¢ la NotebookPageInfo)
108 IMPLEMENT_DYNAMIC_CLASS(wxListCtrl
, wxControl
)
111 IMPLEMENT_DYNAMIC_CLASS(wxListView
, wxListCtrl
)
112 IMPLEMENT_DYNAMIC_CLASS(wxListItem
, wxObject
)
114 IMPLEMENT_DYNAMIC_CLASS(wxListEvent
, wxNotifyEvent
)
116 WX_DECLARE_HASH_MAP( int, wxListItem
*, wxIntegerHash
, wxIntegerEqual
, wxListItemList
);
118 #include "wx/listimpl.cpp"
119 WX_DEFINE_LIST(wxColumnList
)
121 // so we can check for column clicks
122 static const EventTypeSpec eventList
[] =
124 { kEventClassControl
, kEventControlHit
},
125 { kEventClassControl
, kEventControlDraw
}
128 static pascal OSStatus
wxMacListCtrlEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
130 OSStatus result
= eventNotHandledErr
;
132 wxMacCarbonEvent
cEvent( event
) ;
134 ControlRef controlRef
;
135 cEvent
.GetParameter( kEventParamDirectObject
, &controlRef
) ;
137 wxListCtrl
*window
= (wxListCtrl
*) data
;
138 wxListEvent
le( wxEVT_COMMAND_LIST_COL_CLICK
, window
->GetId() );
139 le
.SetEventObject( window
);
141 switch ( GetEventKind( event
) )
143 // check if the column was clicked on and fire an event if so
144 case kEventControlHit
:
146 ControlPartCode result
= cEvent
.GetParameter
<ControlPartCode
>(kEventParamControlPart
, typeControlPartCode
) ;
147 if (result
== kControlButtonPart
){
148 DataBrowserPropertyID col
;
149 GetDataBrowserSortProperty(controlRef
, &col
);
150 int column
= col
- kMinColumnId
;
152 // FIXME: we can't use the sort property for virtual listctrls
153 // so we need to find a better way to determine which column was clicked...
154 if (!window
->IsVirtual())
155 window
->HandleWindowEvent( le
);
157 result
= CallNextEventHandler(handler
, event
);
160 case kEventControlDraw
:
162 CGContextRef context
= cEvent
.GetParameter
<CGContextRef
>(kEventParamCGContextRef
, typeCGContextRef
) ;
163 window
->MacSetDrawingContext(context
);
164 result
= CallNextEventHandler(handler
, event
);
165 window
->MacSetDrawingContext(NULL
);
176 DEFINE_ONE_SHOT_HANDLER_GETTER( wxMacListCtrlEventHandler
)
178 class wxMacListCtrlItem
: public wxMacListBoxItem
183 virtual void Notification(wxMacDataItemBrowserControl
*owner
,
184 DataBrowserItemNotification message
,
185 DataBrowserItemDataRef itemData
) const;
187 virtual void SetColumnInfo( unsigned int column
, wxListItem
* item
);
188 virtual wxListItem
* GetColumnInfo( unsigned int column
);
189 virtual bool HasColumnInfo( unsigned int column
);
191 virtual void SetColumnTextValue( unsigned int column
, const wxString
& text
);
192 virtual wxString
GetColumnTextValue( unsigned int column
);
194 virtual int GetColumnImageValue( unsigned int column
);
195 virtual void SetColumnImageValue( unsigned int column
, int imageIndex
);
197 virtual ~wxMacListCtrlItem();
199 wxListItemList m_rowItems
;
202 DataBrowserDrawItemUPP gDataBrowserDrawItemUPP
= NULL
;
203 //DataBrowserEditItemUPP gDataBrowserEditItemUPP = NULL;
204 DataBrowserHitTestUPP gDataBrowserHitTestUPP
= NULL
;
206 // TODO: Make a better name!!
207 class wxMacDataBrowserListCtrlControl
: public wxMacDataItemBrowserControl
210 wxMacDataBrowserListCtrlControl( wxWindow
*peer
, const wxPoint
& pos
, const wxSize
& size
, long style
);
211 wxMacDataBrowserListCtrlControl() {}
212 virtual ~wxMacDataBrowserListCtrlControl();
214 // create a list item (can be a subclass of wxMacListBoxItem)
216 virtual wxMacDataItem
* CreateItem();
218 virtual void MacInsertItem( unsigned int n
, wxListItem
* item
);
219 virtual void MacSetColumnInfo( unsigned int row
, unsigned int column
, wxListItem
* item
);
220 virtual void MacGetColumnInfo( unsigned int row
, unsigned int column
, wxListItem
& item
);
221 virtual void UpdateState(wxMacDataItem
* dataItem
, wxListItem
* item
);
222 int GetFlags() { return m_flags
; }
225 // we need to override to provide specialized handling for virtual wxListCtrls
226 virtual OSStatus
GetSetItemData(DataBrowserItemID itemID
,
227 DataBrowserPropertyID property
,
228 DataBrowserItemDataRef itemData
,
229 Boolean changeValue
);
231 virtual void ItemNotification(
232 DataBrowserItemID itemID
,
233 DataBrowserItemNotification message
,
234 DataBrowserItemDataRef itemData
);
236 virtual Boolean
CompareItems(DataBrowserItemID itemOneID
,
237 DataBrowserItemID itemTwoID
,
238 DataBrowserPropertyID sortProperty
);
240 static pascal void DataBrowserDrawItemProc(ControlRef browser
,
241 DataBrowserItemID item
,
242 DataBrowserPropertyID property
,
243 DataBrowserItemState itemState
,
246 Boolean colorDevice
);
248 virtual void DrawItem(DataBrowserItemID itemID
,
249 DataBrowserPropertyID property
,
250 DataBrowserItemState itemState
,
251 const Rect
*itemRect
,
253 Boolean colorDevice
);
255 static pascal Boolean
DataBrowserEditTextProc(ControlRef browser
,
256 DataBrowserItemID item
,
257 DataBrowserPropertyID property
,
258 CFStringRef theString
,
259 Rect
*maxEditTextRect
,
260 Boolean
*shrinkToFit
);
262 static pascal Boolean
DataBrowserHitTestProc(ControlRef
WXUNUSED(browser
),
263 DataBrowserItemID
WXUNUSED(itemID
),
264 DataBrowserPropertyID
WXUNUSED(property
),
265 const Rect
*WXUNUSED(theRect
),
266 const Rect
*WXUNUSED(mouseRect
)) { return true; }
268 virtual bool ConfirmEditText(DataBrowserItemID item
,
269 DataBrowserPropertyID property
,
270 CFStringRef theString
,
271 Rect
*maxEditTextRect
,
272 Boolean
*shrinkToFit
);
276 wxClientDataType m_clientDataItemsType
;
279 DECLARE_DYNAMIC_CLASS_NO_COPY(wxMacDataBrowserListCtrlControl
)
282 class wxMacListCtrlEventDelegate
: public wxEvtHandler
285 wxMacListCtrlEventDelegate( wxListCtrl
* list
, int id
);
286 virtual bool ProcessEvent( wxEvent
& event
);
293 wxMacListCtrlEventDelegate::wxMacListCtrlEventDelegate( wxListCtrl
* list
, int id
)
299 bool wxMacListCtrlEventDelegate::ProcessEvent( wxEvent
& event
)
301 // even though we use a generic list ctrl underneath, make sure
302 // we present ourselves as wxListCtrl.
303 event
.SetEventObject( m_list
);
306 if ( !event
.IsKindOf( CLASSINFO( wxCommandEvent
) ) )
308 if (m_list
->HandleWindowEvent( event
))
311 return wxEvtHandler::ProcessEvent(event
);
314 //-----------------------------------------------------------------------------
315 // wxListCtrlRenameTimer (internal)
316 //-----------------------------------------------------------------------------
318 class wxListCtrlRenameTimer
: public wxTimer
324 wxListCtrlRenameTimer( wxListCtrl
*owner
);
328 //-----------------------------------------------------------------------------
329 // wxListCtrlTextCtrlWrapper: wraps a wxTextCtrl to make it work for inline editing
330 //-----------------------------------------------------------------------------
332 class wxListCtrlTextCtrlWrapper
: public wxEvtHandler
335 // NB: text must be a valid object but not Create()d yet
336 wxListCtrlTextCtrlWrapper(wxListCtrl
*owner
,
340 wxTextCtrl
*GetText() const { return m_text
; }
342 void AcceptChangesAndFinish();
345 void OnChar( wxKeyEvent
&event
);
346 void OnKeyUp( wxKeyEvent
&event
);
347 void OnKillFocus( wxFocusEvent
&event
);
349 bool AcceptChanges();
355 wxString m_startValue
;
358 bool m_aboutToFinish
;
360 DECLARE_EVENT_TABLE()
363 //-----------------------------------------------------------------------------
364 // wxListCtrlRenameTimer (internal)
365 //-----------------------------------------------------------------------------
367 wxListCtrlRenameTimer::wxListCtrlRenameTimer( wxListCtrl
*owner
)
372 void wxListCtrlRenameTimer::Notify()
374 m_owner
->OnRenameTimer();
377 //-----------------------------------------------------------------------------
378 // wxListCtrlTextCtrlWrapper (internal)
379 //-----------------------------------------------------------------------------
381 BEGIN_EVENT_TABLE(wxListCtrlTextCtrlWrapper
, wxEvtHandler
)
382 EVT_CHAR (wxListCtrlTextCtrlWrapper::OnChar
)
383 EVT_KEY_UP (wxListCtrlTextCtrlWrapper::OnKeyUp
)
384 EVT_KILL_FOCUS (wxListCtrlTextCtrlWrapper::OnKillFocus
)
387 wxListCtrlTextCtrlWrapper::wxListCtrlTextCtrlWrapper(wxListCtrl
*owner
,
390 : m_startValue(owner
->GetItemText(itemEdit
)),
391 m_itemEdited(itemEdit
)
396 m_aboutToFinish
= false;
400 owner
->GetItemRect(itemEdit
, rectLabel
);
402 m_text
->Create(owner
, wxID_ANY
, m_startValue
,
403 wxPoint(rectLabel
.x
+offset
,rectLabel
.y
),
404 wxSize(rectLabel
.width
-offset
,rectLabel
.height
));
407 m_text
->PushEventHandler(this);
410 void wxListCtrlTextCtrlWrapper::Finish()
416 m_text
->RemoveEventHandler(this);
417 m_owner
->FinishEditing(m_text
);
419 wxPendingDelete
.Append( this );
423 bool wxListCtrlTextCtrlWrapper::AcceptChanges()
425 const wxString value
= m_text
->GetValue();
427 if ( value
== m_startValue
)
428 // nothing changed, always accept
431 if ( !m_owner
->OnRenameAccept(m_itemEdited
, value
) )
432 // vetoed by the user
435 // accepted, do rename the item
436 m_owner
->SetItemText(m_itemEdited
, value
);
441 void wxListCtrlTextCtrlWrapper::AcceptChangesAndFinish()
443 m_aboutToFinish
= true;
445 // Notify the owner about the changes
448 // Even if vetoed, close the control (consistent with MSW)
452 void wxListCtrlTextCtrlWrapper::OnChar( wxKeyEvent
&event
)
454 switch ( event
.m_keyCode
)
457 AcceptChangesAndFinish();
461 m_owner
->OnRenameCancelled( m_itemEdited
);
470 void wxListCtrlTextCtrlWrapper::OnKeyUp( wxKeyEvent
&event
)
478 // auto-grow the textctrl:
479 wxSize parentSize
= m_owner
->GetSize();
480 wxPoint myPos
= m_text
->GetPosition();
481 wxSize mySize
= m_text
->GetSize();
483 m_text
->GetTextExtent(m_text
->GetValue() + _T("MM"), &sx
, &sy
);
484 if (myPos
.x
+ sx
> parentSize
.x
)
485 sx
= parentSize
.x
- myPos
.x
;
488 m_text
->SetSize(sx
, wxDefaultCoord
);
493 void wxListCtrlTextCtrlWrapper::OnKillFocus( wxFocusEvent
&event
)
495 if ( !m_finished
&& !m_aboutToFinish
)
497 if ( !AcceptChanges() )
498 m_owner
->OnRenameCancelled( m_itemEdited
);
503 // We must let the native text control handle focus
507 BEGIN_EVENT_TABLE(wxListCtrl
, wxControl
)
508 EVT_LEFT_DOWN(wxListCtrl::OnLeftDown
)
509 EVT_LEFT_DCLICK(wxListCtrl::OnDblClick
)
510 EVT_MIDDLE_DOWN(wxListCtrl::OnMiddleDown
)
511 EVT_RIGHT_DOWN(wxListCtrl::OnRightDown
)
512 EVT_CHAR(wxListCtrl::OnChar
)
515 // ============================================================================
517 // ============================================================================
519 wxMacListControl
* wxListCtrl::GetPeer() const
521 wxMacDataBrowserListCtrlControl
*lb
= wxDynamicCast(m_peer
,wxMacDataBrowserListCtrlControl
);
522 return lb
? wx_static_cast(wxMacListControl
*,lb
) : 0 ;
525 // ----------------------------------------------------------------------------
526 // wxListCtrl construction
527 // ----------------------------------------------------------------------------
529 void wxListCtrl::Init()
531 m_imageListNormal
= NULL
;
532 m_imageListSmall
= NULL
;
533 m_imageListState
= NULL
;
535 // keep track of if we created our own image lists, or if they were assigned
537 m_ownsImageListNormal
= m_ownsImageListSmall
= m_ownsImageListState
= false;
541 m_genericImpl
= NULL
;
543 m_compareFunc
= NULL
;
544 m_compareFuncData
= 0;
545 m_colsInfo
= wxColumnList();
546 m_textColor
= wxNullColour
;
547 m_bgColor
= wxNullColour
;
548 m_textctrlWrapper
= NULL
;
550 m_renameTimer
= new wxListCtrlRenameTimer( this );
553 class wxGenericListCtrlHook
: public wxGenericListCtrl
556 wxGenericListCtrlHook(wxListCtrl
* parent
,
561 const wxValidator
& validator
,
562 const wxString
& name
)
563 : wxGenericListCtrl(parent
, id
, pos
, size
, style
, validator
, name
),
564 m_nativeListCtrl(parent
)
569 virtual wxListItemAttr
* OnGetItemAttr(long item
) const
571 return m_nativeListCtrl
->OnGetItemAttr(item
);
574 virtual int OnGetItemImage(long item
) const
576 return m_nativeListCtrl
->OnGetItemImage(item
);
579 virtual int OnGetItemColumnImage(long item
, long column
) const
581 return m_nativeListCtrl
->OnGetItemColumnImage(item
, column
);
584 virtual wxString
OnGetItemText(long item
, long column
) const
586 return m_nativeListCtrl
->OnGetItemText(item
, column
);
589 wxListCtrl
* m_nativeListCtrl
;
593 void wxListCtrl::OnLeftDown(wxMouseEvent
& event
)
595 if ( m_textctrlWrapper
)
598 m_textctrlWrapper
->AcceptChangesAndFinish();
602 long current
= HitTest(event
.GetPosition(), hitResult
);
603 if ((current
== m_current
) &&
604 (hitResult
== wxLIST_HITTEST_ONITEM
) &&
605 HasFlag(wxLC_EDIT_LABELS
) )
607 m_renameTimer
->Start( 100, true );
616 void wxListCtrl::OnDblClick(wxMouseEvent
& event
)
622 #if wxABI_VERSION >= 20801
623 void wxListCtrl::OnRightDown(wxMouseEvent
& event
)
626 FireMouseEvent(wxEVT_COMMAND_LIST_ITEM_RIGHT_CLICK
, event
.GetPosition());
630 void wxListCtrl::OnMiddleDown(wxMouseEvent
& event
)
633 FireMouseEvent(wxEVT_COMMAND_LIST_ITEM_MIDDLE_CLICK
, event
.GetPosition());
637 void wxListCtrl::FireMouseEvent(wxEventType eventType
, wxPoint position
)
639 wxListEvent
le( eventType
, GetId() );
640 le
.SetEventObject(this);
641 le
.m_pointDrag
= position
;
645 long item
= HitTest(position
, flags
);
646 if (flags
& wxLIST_HITTEST_ONITEM
)
648 le
.m_itemIndex
= item
;
649 le
.m_item
.m_itemId
= item
;
651 HandleWindowEvent(le
);
655 void wxListCtrl::OnChar(wxKeyEvent
& event
)
661 wxListEvent
le( wxEVT_COMMAND_LIST_KEY_DOWN
, GetId() );
662 le
.SetEventObject(this);
663 le
.m_code
= event
.GetKeyCode();
668 // if m_current isn't set, check if there's been a selection
669 // made before continuing
670 m_current
= GetNextItem(-1, wxLIST_NEXT_BELOW
, wxLIST_STATE_SELECTED
);
673 // We need to determine m_current ourselves when navigation keys
674 // are used. Note that PAGEUP and PAGEDOWN do not alter the current
675 // item on native Mac ListCtrl, so we only handle up and down keys.
676 switch ( event
.GetKeyCode() )
687 if ( m_current
< GetItemCount() - 1 )
690 m_current
= GetItemCount() - 1;
697 le
.m_itemIndex
= m_current
;
698 le
.m_item
.m_itemId
= m_current
;
700 HandleWindowEvent(le
);
707 bool wxListCtrl::Create(wxWindow
*parent
,
712 const wxValidator
& validator
,
713 const wxString
& name
)
716 // for now, we'll always use the generic list control for ICON and LIST views,
717 // because they dynamically change the number of columns on resize.
718 // Also, allow the user to set it to use the list ctrl as well.
719 if ( (wxSystemOptions::HasOption( wxMAC_ALWAYS_USE_GENERIC_LISTCTRL
)
720 && (wxSystemOptions::GetOptionInt( wxMAC_ALWAYS_USE_GENERIC_LISTCTRL
) == 1)) ||
721 (style
& wxLC_ICON
) || (style
& wxLC_SMALL_ICON
) || (style
& wxLC_LIST
) )
723 m_macIsUserPane
= true;
725 long paneStyle
= style
;
726 paneStyle
&= ~wxSIMPLE_BORDER
;
727 paneStyle
&= ~wxDOUBLE_BORDER
;
728 paneStyle
&= ~wxSUNKEN_BORDER
;
729 paneStyle
&= ~wxRAISED_BORDER
;
730 paneStyle
&= ~wxSTATIC_BORDER
;
731 if ( !wxWindow::Create(parent
, id
, pos
, size
, paneStyle
| wxNO_BORDER
, name
) )
734 // since the generic control is a child, make sure we position it at 0, 0
735 m_genericImpl
= new wxGenericListCtrlHook(this, id
, wxPoint(0, 0), size
, style
, validator
, name
);
736 m_genericImpl
->PushEventHandler( new wxMacListCtrlEventDelegate( this, GetId() ) );
742 m_macIsUserPane
= false;
743 if ( !wxWindow::Create(parent
, id
, pos
, size
, style
& ~(wxHSCROLL
| wxVSCROLL
), name
) )
745 m_dbImpl
= new wxMacDataBrowserListCtrlControl( this, pos
, size
, style
);
748 MacPostControlCreate( pos
, size
);
750 InstallControlEventHandler( m_peer
->GetControlRef() , GetwxMacListCtrlEventHandlerUPP(),
751 GetEventTypeCount(eventList
), eventList
, this,
752 (EventHandlerRef
*)&m_macListCtrlEventHandler
);
758 wxListCtrl::~wxListCtrl()
762 m_genericImpl
->PopEventHandler(/* deleteHandler = */ true);
765 if (m_ownsImageListNormal
)
766 delete m_imageListNormal
;
767 if (m_ownsImageListSmall
)
768 delete m_imageListSmall
;
769 if (m_ownsImageListState
)
770 delete m_imageListState
;
772 delete m_renameTimer
;
775 // ----------------------------------------------------------------------------
776 // set/get/change style
777 // ----------------------------------------------------------------------------
779 // Add or remove a single window style
780 void wxListCtrl::SetSingleStyle(long style
, bool add
)
782 long flag
= GetWindowStyleFlag();
784 // Get rid of conflicting styles
787 if ( style
& wxLC_MASK_TYPE
)
788 flag
= flag
& ~wxLC_MASK_TYPE
;
789 if ( style
& wxLC_MASK_ALIGN
)
790 flag
= flag
& ~wxLC_MASK_ALIGN
;
791 if ( style
& wxLC_MASK_SORT
)
792 flag
= flag
& ~wxLC_MASK_SORT
;
800 SetWindowStyleFlag(flag
);
803 // Set the whole window style
804 void wxListCtrl::SetWindowStyleFlag(long flag
)
806 if ( flag
!= m_windowStyle
)
808 m_windowStyle
= flag
;
812 m_genericImpl
->SetWindowStyleFlag(flag
);
819 void wxListCtrl::DoSetSize( int x
, int y
, int width
, int height
, int sizeFlags
)
821 wxControl::DoSetSize(x
, y
, width
, height
, sizeFlags
);
824 m_genericImpl
->SetSize(0, 0, width
, height
, sizeFlags
);
826 // determine if we need a horizontal scrollbar, and add it if so
830 for (int column
= 0; column
< GetColumnCount(); column
++)
832 totalWidth
+= m_dbImpl
->GetColumnWidth( column
);
835 if ( !(m_dbImpl
->GetFlags() & wxHSCROLL
) )
837 Boolean vertScrollBar
;
838 GetDataBrowserHasScrollBars( m_dbImpl
->GetControlRef(), NULL
, &vertScrollBar
);
839 if (totalWidth
> width
)
840 SetDataBrowserHasScrollBars( m_dbImpl
->GetControlRef(), true, vertScrollBar
);
842 SetDataBrowserHasScrollBars( m_dbImpl
->GetControlRef(), false, vertScrollBar
);
847 wxSize
wxListCtrl::DoGetBestSize() const
849 return wxWindow::DoGetBestSize();
852 bool wxListCtrl::SetFont(const wxFont
& font
)
855 rv
= wxControl::SetFont(font
);
857 rv
= m_genericImpl
->SetFont(font
);
861 bool wxListCtrl::SetForegroundColour(const wxColour
& colour
)
865 rv
= m_genericImpl
->SetForegroundColour(colour
);
867 SetTextColour(colour
);
871 bool wxListCtrl::SetBackgroundColour(const wxColour
& colour
)
875 rv
= m_genericImpl
->SetBackgroundColour(colour
);
881 wxColour
wxListCtrl::GetBackgroundColour()
884 return m_genericImpl
->GetBackgroundColour();
891 // ----------------------------------------------------------------------------
893 // ----------------------------------------------------------------------------
895 // Gets information about this column
896 bool wxListCtrl::GetColumn(int col
, wxListItem
& item
) const
899 return m_genericImpl
->GetColumn(col
, item
);
905 wxColumnList::compatibility_iterator node
= m_colsInfo
.Item( col
);
906 wxASSERT_MSG( node
, _T("invalid column index in wxMacListCtrlItem") );
907 wxListItem
* column
= node
->GetData();
909 long mask
= column
->GetMask();
910 if (mask
& wxLIST_MASK_TEXT
)
911 item
.SetText(column
->GetText());
912 if (mask
& wxLIST_MASK_DATA
)
913 item
.SetData(column
->GetData());
914 if (mask
& wxLIST_MASK_IMAGE
)
915 item
.SetImage(column
->GetImage());
916 if (mask
& wxLIST_MASK_STATE
)
917 item
.SetState(column
->GetState());
918 if (mask
& wxLIST_MASK_FORMAT
)
919 item
.SetAlign(column
->GetAlign());
920 if (mask
& wxLIST_MASK_WIDTH
)
921 item
.SetWidth(column
->GetWidth());
927 // Sets information about this column
928 bool wxListCtrl::SetColumn(int col
, wxListItem
& item
)
931 return m_genericImpl
->SetColumn(col
, item
);
935 long mask
= item
.GetMask();
936 if ( col
>= (int)m_colsInfo
.GetCount() )
938 wxListItem
* listItem
= new wxListItem(item
);
939 m_colsInfo
.Append( listItem
);
944 GetColumn( col
, listItem
);
946 if (mask
& wxLIST_MASK_TEXT
)
947 listItem
.SetText(item
.GetText());
948 if (mask
& wxLIST_MASK_DATA
)
949 listItem
.SetData(item
.GetData());
950 if (mask
& wxLIST_MASK_IMAGE
)
951 listItem
.SetImage(item
.GetImage());
952 if (mask
& wxLIST_MASK_STATE
)
953 listItem
.SetState(item
.GetState());
954 if (mask
& wxLIST_MASK_FORMAT
)
955 listItem
.SetAlign(item
.GetAlign());
956 if (mask
& wxLIST_MASK_WIDTH
)
957 listItem
.SetWidth(item
.GetWidth());
960 // change the appearance in the databrowser.
961 DataBrowserListViewHeaderDesc columnDesc
;
962 columnDesc
.version
=kDataBrowserListViewLatestHeaderDesc
;
963 verify_noerr( m_dbImpl
->GetHeaderDesc( kMinColumnId
+ col
, &columnDesc
) );
966 if (item.GetMask() & wxLIST_MASK_TEXT)
970 enc = m_font.GetEncoding();
972 enc = wxLocale::GetSystemEncoding();
973 wxCFStringRef cfTitle;
974 cfTitle.Assign( item.GetText() , enc );
975 if(columnDesc.titleString)
976 CFRelease(columnDesc.titleString);
977 columnDesc.titleString = cfTitle;
981 if (item
.GetMask() & wxLIST_MASK_IMAGE
&& item
.GetImage() != -1 )
983 wxImageList
* imageList
= GetImageList(wxIMAGE_LIST_SMALL
);
984 if (imageList
&& imageList
->GetImageCount() > 0 )
986 wxBitmap bmp
= imageList
->GetBitmap( item
.GetImage() );
987 IconRef icon
= bmp
.GetIconRef();
988 columnDesc
.btnContentInfo
.u
.iconRef
= icon
;
989 columnDesc
.btnContentInfo
.contentType
= kControlContentIconRef
;
993 verify_noerr( m_dbImpl
->SetHeaderDesc( kMinColumnId
+ col
, &columnDesc
) );
999 int wxListCtrl::GetColumnCount() const
1002 return m_genericImpl
->GetColumnCount();
1007 m_dbImpl
->GetColumnCount(&count
);
1014 // Gets the column width
1015 int wxListCtrl::GetColumnWidth(int col
) const
1018 return m_genericImpl
->GetColumnWidth(col
);
1022 return m_dbImpl
->GetColumnWidth(col
);
1028 // Sets the column width
1029 bool wxListCtrl::SetColumnWidth(int col
, int width
)
1032 return m_genericImpl
->SetColumnWidth(col
, width
);
1036 int mywidth
= width
;
1037 if (width
== wxLIST_AUTOSIZE
|| width
== wxLIST_AUTOSIZE_USEHEADER
)
1042 for (int column
= 0; column
< GetColumnCount(); column
++)
1045 GetColumn(col
, colInfo
);
1047 colInfo
.SetWidth(width
);
1048 SetColumn(col
, colInfo
);
1050 m_dbImpl
->SetColumnWidth(col
, mywidth
);
1056 GetColumn(col
, colInfo
);
1058 colInfo
.SetWidth(width
);
1059 SetColumn(col
, colInfo
);
1060 m_dbImpl
->SetColumnWidth(col
, mywidth
);
1068 // Gets the number of items that can fit vertically in the
1069 // visible area of the list control (list or report view)
1070 // or the total number of items in the list control (icon
1071 // or small icon view)
1072 int wxListCtrl::GetCountPerPage() const
1075 return m_genericImpl
->GetCountPerPage();
1080 m_dbImpl
->GetDefaultRowHeight( &height
);
1082 return GetClientSize().y
/ height
;
1088 // Gets the edit control for editing labels.
1089 wxTextCtrl
* wxListCtrl::GetEditControl() const
1092 return m_genericImpl
->GetEditControl();
1097 // Gets information about the item
1098 bool wxListCtrl::GetItem(wxListItem
& info
) const
1101 return m_genericImpl
->GetItem(info
);
1107 if (info
.m_itemId
>= 0 && info
.m_itemId
< GetItemCount())
1109 m_dbImpl
->MacGetColumnInfo(info
.m_itemId
, info
.m_col
, info
);
1110 if (info
.GetMask() & wxLIST_MASK_STATE
)
1112 DataBrowserItemID id
= (DataBrowserItemID
)m_dbImpl
->GetItemFromLine(info
.m_itemId
);
1113 if (IsDataBrowserItemSelected( m_dbImpl
->GetControlRef(), id
))
1114 info
.SetState(info
.GetState() | wxLIST_STATE_SELECTED
);
1120 if (info
.m_itemId
>= 0 && info
.m_itemId
< GetItemCount())
1122 info
.SetText( OnGetItemText(info
.m_itemId
, info
.m_col
) );
1123 info
.SetImage( OnGetItemColumnImage(info
.m_itemId
, info
.m_col
) );
1124 if (info
.GetMask() & wxLIST_MASK_STATE
)
1126 if (IsDataBrowserItemSelected( m_dbImpl
->GetControlRef(), info
.m_itemId
+1 ))
1127 info
.SetState(info
.GetState() | wxLIST_STATE_SELECTED
);
1130 wxListItemAttr
* attrs
= OnGetItemAttr( info
.m_itemId
);
1133 info
.SetFont( attrs
->GetFont() );
1134 info
.SetBackgroundColour( attrs
->GetBackgroundColour() );
1135 info
.SetTextColour( attrs
->GetTextColour() );
1140 bool success
= true;
1144 // Sets information about the item
1145 bool wxListCtrl::SetItem(wxListItem
& info
)
1148 return m_genericImpl
->SetItem(info
);
1151 m_dbImpl
->MacSetColumnInfo( info
.m_itemId
, info
.m_col
, &info
);
1156 long wxListCtrl::SetItem(long index
, int col
, const wxString
& label
, int imageId
)
1159 return m_genericImpl
->SetItem(index
, col
, label
, imageId
);
1162 info
.m_text
= label
;
1163 info
.m_mask
= wxLIST_MASK_TEXT
;
1164 info
.m_itemId
= index
;
1168 info
.m_image
= imageId
;
1169 info
.m_mask
|= wxLIST_MASK_IMAGE
;
1171 return SetItem(info
);
1175 // Gets the item state
1176 int wxListCtrl::GetItemState(long item
, long stateMask
) const
1179 return m_genericImpl
->GetItemState(item
, stateMask
);
1183 if ( HasFlag(wxLC_VIRTUAL
) )
1185 if (stateMask
== wxLIST_STATE_SELECTED
)
1187 if (IsDataBrowserItemSelected( m_dbImpl
->GetControlRef(), item
+1 ))
1188 return wxLIST_STATE_SELECTED
;
1197 info
.m_mask
= wxLIST_MASK_STATE
;
1198 info
.m_stateMask
= stateMask
;
1199 info
.m_itemId
= item
;
1204 return info
.m_state
;
1211 // Sets the item state
1212 bool wxListCtrl::SetItemState(long item
, long state
, long stateMask
)
1215 return m_genericImpl
->SetItemState(item
, state
, stateMask
);
1219 DataBrowserSetOption option
= kDataBrowserItemsAdd
;
1220 if ( (stateMask
& wxLIST_STATE_SELECTED
) && state
== 0 )
1221 option
= kDataBrowserItemsRemove
;
1225 if ( HasFlag(wxLC_VIRTUAL
) )
1227 wxMacDataItemBrowserSelectionSuppressor
suppressor(m_dbImpl
);
1228 m_dbImpl
->SetSelectedAllItems(option
);
1232 for(int i
= 0; i
< GetItemCount();i
++)
1236 info
.m_mask
= wxLIST_MASK_STATE
;
1237 info
.m_stateMask
= stateMask
;
1238 info
.m_state
= state
;
1245 if ( HasFlag(wxLC_VIRTUAL
) )
1247 long itemID
= item
+1;
1248 bool isSelected
= IsDataBrowserItemSelected(m_dbImpl
->GetControlRef(), (DataBrowserItemID
)itemID
);
1249 bool isSelectedState
= (state
== wxLIST_STATE_SELECTED
);
1251 // toggle the selection state if wxListInfo state and actual state don't match.
1252 if ( (stateMask
& wxLIST_STATE_SELECTED
) && isSelected
!= isSelectedState
)
1254 SetDataBrowserSelectedItems(m_dbImpl
->GetControlRef(), 1, (DataBrowserItemID
*)&itemID
, option
);
1260 info
.m_itemId
= item
;
1261 info
.m_mask
= wxLIST_MASK_STATE
;
1262 info
.m_stateMask
= stateMask
;
1263 info
.m_state
= state
;
1264 return SetItem(info
);
1271 // Sets the item image
1272 bool wxListCtrl::SetItemImage(long item
, int image
, int WXUNUSED(selImage
))
1274 return SetItemColumnImage(item
, 0, image
);
1277 // Sets the item image
1278 bool wxListCtrl::SetItemColumnImage(long item
, long column
, int image
)
1281 return m_genericImpl
->SetItemColumnImage(item
, column
, image
);
1285 info
.m_mask
= wxLIST_MASK_IMAGE
;
1286 info
.m_image
= image
;
1287 info
.m_itemId
= item
;
1288 info
.m_col
= column
;
1290 return SetItem(info
);
1293 // Gets the item text
1294 wxString
wxListCtrl::GetItemText(long item
) const
1297 return m_genericImpl
->GetItemText(item
);
1301 info
.m_mask
= wxLIST_MASK_TEXT
;
1302 info
.m_itemId
= item
;
1305 return wxEmptyString
;
1309 // Sets the item text
1310 void wxListCtrl::SetItemText(long item
, const wxString
& str
)
1313 return m_genericImpl
->SetItemText(item
, str
);
1317 info
.m_mask
= wxLIST_MASK_TEXT
;
1318 info
.m_itemId
= item
;
1324 // Gets the item data
1325 long wxListCtrl::GetItemData(long item
) const
1328 return m_genericImpl
->GetItemData(item
);
1332 info
.m_mask
= wxLIST_MASK_DATA
;
1333 info
.m_itemId
= item
;
1340 // Sets the item data
1341 bool wxListCtrl::SetItemPtrData(long item
, wxUIntPtr data
)
1344 return m_genericImpl
->SetItemData(item
, data
);
1348 info
.m_mask
= wxLIST_MASK_DATA
;
1349 info
.m_itemId
= item
;
1352 return SetItem(info
);
1355 wxRect
wxListCtrl::GetViewRect() const
1357 wxASSERT_MSG( !HasFlag(wxLC_REPORT
| wxLC_LIST
),
1358 _T("wxListCtrl::GetViewRect() only works in icon mode") );
1361 return m_genericImpl
->GetViewRect();
1367 // Gets the item rectangle
1368 bool wxListCtrl::GetItemRect(long item
, wxRect
& rect
, int code
) const
1371 return m_genericImpl
->GetItemRect(item
, rect
, code
);
1376 DataBrowserItemID id
;
1377 DataBrowserPropertyID col
= kMinColumnId
;
1379 DataBrowserPropertyPart part
= kDataBrowserPropertyEnclosingPart
;
1380 if ( code
== wxLIST_RECT_LABEL
)
1381 part
= kDataBrowserPropertyTextPart
;
1382 else if ( code
== wxLIST_RECT_ICON
)
1383 part
= kDataBrowserPropertyIconPart
;
1385 if ( !(GetWindowStyleFlag() & wxLC_VIRTUAL
) )
1387 wxMacDataItem
* thisItem
= m_dbImpl
->GetItemFromLine(item
);
1388 id
= (DataBrowserItemID
) thisItem
;
1393 GetDataBrowserItemPartBounds( m_dbImpl
->GetControlRef(), id
, col
, part
, &bounds
);
1395 rect
.x
= bounds
.left
;
1396 rect
.y
= bounds
.top
;
1397 rect
.width
= bounds
.right
- bounds
.left
; //GetClientSize().x; // we need the width of the whole row, not just the item.
1398 rect
.height
= bounds
.bottom
- bounds
.top
;
1399 //fprintf("id = %d, bounds = %d, %d, %d, %d\n", id, rect.x, rect.y, rect.width, rect.height);
1404 // Gets the item position
1405 bool wxListCtrl::GetItemPosition(long item
, wxPoint
& pos
) const
1408 return m_genericImpl
->GetItemPosition(item
, pos
);
1410 bool success
= false;
1415 GetItemRect(item
, itemRect
);
1416 pos
= itemRect
.GetPosition();
1423 // Sets the item position.
1424 bool wxListCtrl::SetItemPosition(long item
, const wxPoint
& pos
)
1427 return m_genericImpl
->SetItemPosition(item
, pos
);
1432 // Gets the number of items in the list control
1433 int wxListCtrl::GetItemCount() const
1436 return m_genericImpl
->GetItemCount();
1439 return m_dbImpl
->MacGetCount();
1444 void wxListCtrl::SetItemSpacing( int spacing
, bool isSmall
)
1447 m_genericImpl
->SetItemSpacing(spacing
, isSmall
);
1450 wxSize
wxListCtrl::GetItemSpacing() const
1453 return m_genericImpl
->GetItemSpacing();
1455 return wxSize(0, 0);
1458 void wxListCtrl::SetItemTextColour( long item
, const wxColour
&col
)
1462 m_genericImpl
->SetItemTextColour(item
, col
);
1467 info
.m_itemId
= item
;
1468 info
.SetTextColour( col
);
1472 wxColour
wxListCtrl::GetItemTextColour( long item
) const
1475 return m_genericImpl
->GetItemTextColour(item
);
1481 return info
.GetTextColour();
1483 return wxNullColour
;
1486 void wxListCtrl::SetItemBackgroundColour( long item
, const wxColour
&col
)
1490 m_genericImpl
->SetItemBackgroundColour(item
, col
);
1495 info
.m_itemId
= item
;
1496 info
.SetBackgroundColour( col
);
1500 wxColour
wxListCtrl::GetItemBackgroundColour( long item
) const
1503 return m_genericImpl
->GetItemBackgroundColour(item
);
1509 return info
.GetBackgroundColour();
1511 return wxNullColour
;
1514 void wxListCtrl::SetItemFont( long item
, const wxFont
&f
)
1518 m_genericImpl
->SetItemFont(item
, f
);
1523 info
.m_itemId
= item
;
1528 wxFont
wxListCtrl::GetItemFont( long item
) const
1531 return m_genericImpl
->GetItemFont(item
);
1537 return info
.GetFont();
1543 // Gets the number of selected items in the list control
1544 int wxListCtrl::GetSelectedItemCount() const
1547 return m_genericImpl
->GetSelectedItemCount();
1550 return m_dbImpl
->GetSelectedItemCount(NULL
, true);
1555 // Gets the text colour of the listview
1556 wxColour
wxListCtrl::GetTextColour() const
1559 return m_genericImpl
->GetTextColour();
1561 // TODO: we need owner drawn list items to customize text color.
1565 return wxNullColour
;
1568 // Sets the text colour of the listview
1569 void wxListCtrl::SetTextColour(const wxColour
& col
)
1573 m_genericImpl
->SetTextColour(col
);
1581 // Gets the index of the topmost visible item when in
1582 // list or report view
1583 long wxListCtrl::GetTopItem() const
1586 return m_genericImpl
->GetTopItem();
1591 long item
= HitTest( wxPoint(1, 1), flags
);
1592 if (flags
== wxLIST_HITTEST_ONITEM
)
1599 // Searches for an item, starting from 'item'.
1600 // 'geometry' is one of
1601 // wxLIST_NEXT_ABOVE/ALL/BELOW/LEFT/RIGHT.
1602 // 'state' is a state bit flag, one or more of
1603 // wxLIST_STATE_DROPHILITED/FOCUSED/SELECTED/CUT.
1604 // item can be -1 to find the first item that matches the
1606 // Returns the item or -1 if unsuccessful.
1607 long wxListCtrl::GetNextItem(long item
, int geom
, int state
) const
1610 return m_genericImpl
->GetNextItem(item
, geom
, state
);
1612 // TODO: implement all geometry and state options?
1615 if ( geom
== wxLIST_NEXT_ALL
|| geom
== wxLIST_NEXT_BELOW
)
1617 long count
= m_dbImpl
->MacGetCount() ;
1618 for ( long line
= item
+ 1 ; line
< count
; line
++ )
1620 DataBrowserItemID id
= line
+ 1;
1622 id
= (DataBrowserItemID
)m_dbImpl
->GetItemFromLine(line
);
1624 if ( (state
== wxLIST_STATE_DONTCARE
) )
1627 if ( (state
& wxLIST_STATE_SELECTED
) && IsDataBrowserItemSelected(m_dbImpl
->GetControlRef(), id
) )
1632 if ( geom
== wxLIST_NEXT_ABOVE
)
1636 item2
= m_dbImpl
->MacGetCount();
1638 for ( long line
= item2
- 1 ; line
>= 0; line
-- )
1640 DataBrowserItemID id
= line
+ 1;
1642 id
= (DataBrowserItemID
)m_dbImpl
->GetItemFromLine(line
);
1644 if ( (state
== wxLIST_STATE_DONTCARE
) )
1647 if ( (state
& wxLIST_STATE_SELECTED
) && IsDataBrowserItemSelected(m_dbImpl
->GetControlRef(), id
) )
1657 wxImageList
*wxListCtrl::GetImageList(int which
) const
1660 return m_genericImpl
->GetImageList(which
);
1662 if ( which
== wxIMAGE_LIST_NORMAL
)
1664 return m_imageListNormal
;
1666 else if ( which
== wxIMAGE_LIST_SMALL
)
1668 return m_imageListSmall
;
1670 else if ( which
== wxIMAGE_LIST_STATE
)
1672 return m_imageListState
;
1677 void wxListCtrl::SetImageList(wxImageList
*imageList
, int which
)
1681 m_genericImpl
->SetImageList(imageList
, which
);
1685 if ( which
== wxIMAGE_LIST_NORMAL
)
1687 if (m_ownsImageListNormal
) delete m_imageListNormal
;
1688 m_imageListNormal
= imageList
;
1689 m_ownsImageListNormal
= false;
1691 else if ( which
== wxIMAGE_LIST_SMALL
)
1693 if (m_ownsImageListSmall
) delete m_imageListSmall
;
1694 m_imageListSmall
= imageList
;
1695 m_ownsImageListSmall
= false;
1697 else if ( which
== wxIMAGE_LIST_STATE
)
1699 if (m_ownsImageListState
) delete m_imageListState
;
1700 m_imageListState
= imageList
;
1701 m_ownsImageListState
= false;
1705 void wxListCtrl::AssignImageList(wxImageList
*imageList
, int which
)
1709 m_genericImpl
->AssignImageList(imageList
, which
);
1713 SetImageList(imageList
, which
);
1714 if ( which
== wxIMAGE_LIST_NORMAL
)
1715 m_ownsImageListNormal
= true;
1716 else if ( which
== wxIMAGE_LIST_SMALL
)
1717 m_ownsImageListSmall
= true;
1718 else if ( which
== wxIMAGE_LIST_STATE
)
1719 m_ownsImageListState
= true;
1722 // ----------------------------------------------------------------------------
1724 // ----------------------------------------------------------------------------
1726 // Arranges the items
1727 bool wxListCtrl::Arrange(int flag
)
1730 return m_genericImpl
->Arrange(flag
);
1735 bool wxListCtrl::DeleteItem(long item
)
1738 return m_genericImpl
->DeleteItem(item
);
1742 m_dbImpl
->MacDelete(item
);
1743 wxListEvent
event( wxEVT_COMMAND_LIST_DELETE_ITEM
, GetId() );
1744 event
.SetEventObject( this );
1745 event
.m_itemIndex
= item
;
1746 HandleWindowEvent( event
);
1752 // Deletes all items
1753 bool wxListCtrl::DeleteAllItems()
1756 return m_genericImpl
->DeleteAllItems();
1760 m_dbImpl
->MacClear();
1761 wxListEvent
event( wxEVT_COMMAND_LIST_DELETE_ALL_ITEMS
, GetId() );
1762 event
.SetEventObject( this );
1763 HandleWindowEvent( event
);
1768 // Deletes all items
1769 bool wxListCtrl::DeleteAllColumns()
1772 return m_genericImpl
->DeleteAllColumns();
1777 m_dbImpl
->GetColumnCount(&cols
);
1778 for (UInt32 col
= 0; col
< cols
; col
++)
1788 bool wxListCtrl::DeleteColumn(int col
)
1791 return m_genericImpl
->DeleteColumn(col
);
1795 OSStatus err
= m_dbImpl
->RemoveColumn(col
);
1796 return err
== noErr
;
1802 // Clears items, and columns if there are any.
1803 void wxListCtrl::ClearAll()
1807 m_genericImpl
->ClearAll();
1818 wxTextCtrl
* wxListCtrl::EditLabel(long item
, wxClassInfo
* textControlClass
)
1821 return m_genericImpl
->EditLabel(item
, textControlClass
);
1825 wxCHECK_MSG( (item
>= 0) && ((long)item
< GetItemCount()), NULL
,
1826 wxT("wrong index in wxListCtrl::EditLabel()") );
1828 wxASSERT_MSG( textControlClass
->IsKindOf(CLASSINFO(wxTextCtrl
)),
1829 wxT("EditLabel() needs a text control") );
1831 wxListEvent
le( wxEVT_COMMAND_LIST_BEGIN_LABEL_EDIT
, GetParent()->GetId() );
1832 le
.SetEventObject( this );
1833 le
.m_itemIndex
= item
;
1835 GetItem( le
.m_item
);
1837 if ( GetParent()->HandleWindowEvent( le
) && !le
.IsAllowed() )
1839 // vetoed by user code
1843 wxTextCtrl
* const text
= (wxTextCtrl
*)textControlClass
->CreateObject();
1844 m_textctrlWrapper
= new wxListCtrlTextCtrlWrapper(this, text
, item
);
1845 return m_textctrlWrapper
->GetText();
1850 // End label editing, optionally cancelling the edit
1851 bool wxListCtrl::EndEditLabel(bool WXUNUSED(cancel
))
1853 // TODO: generic impl. doesn't have this method - is it needed for us?
1855 return true; // m_genericImpl->EndEditLabel(cancel);
1858 verify_noerr( SetDataBrowserEditItem(m_dbImpl
->GetControlRef(), kDataBrowserNoItem
, kMinColumnId
) );
1862 // Ensures this item is visible
1863 bool wxListCtrl::EnsureVisible(long item
)
1866 return m_genericImpl
->EnsureVisible(item
);
1870 wxMacDataItem
* dataItem
= m_dbImpl
->GetItemFromLine(item
);
1871 m_dbImpl
->RevealItem(dataItem
, kDataBrowserRevealWithoutSelecting
);
1877 // Find an item whose label matches this string, starting from the item after 'start'
1878 // or the beginning if 'start' is -1.
1879 long wxListCtrl::FindItem(long start
, const wxString
& str
, bool partial
)
1882 return m_genericImpl
->FindItem(start
, str
, partial
);
1884 wxString str_upper
= str
.Upper();
1889 long count
= GetItemCount();
1893 wxString line_upper
= GetItemText(idx
).Upper();
1896 if (line_upper
== str_upper
)
1901 if (line_upper
.find(str_upper
) == 0)
1911 // Find an item whose data matches this data, starting from the item after 'start'
1912 // or the beginning if 'start' is -1.
1913 long wxListCtrl::FindItem(long start
, long data
)
1916 return m_genericImpl
->FindItem(start
, data
);
1921 long count
= GetItemCount();
1925 if (GetItemData(idx
) == data
)
1933 // Find an item nearest this position in the specified direction, starting from
1934 // the item after 'start' or the beginning if 'start' is -1.
1935 long wxListCtrl::FindItem(long start
, const wxPoint
& pt
, int direction
)
1938 return m_genericImpl
->FindItem(start
, pt
, direction
);
1942 // Determines which item (if any) is at the specified point,
1943 // giving details in 'flags' (see wxLIST_HITTEST_... flags above)
1945 wxListCtrl::HitTest(const wxPoint
& point
, int& flags
, long *ptrSubItem
) const
1948 return m_genericImpl
->HitTest(point
, flags
, ptrSubItem
);
1950 flags
= wxLIST_HITTEST_NOWHERE
;
1953 int colHeaderHeight
= 22; // TODO: Find a way to get this value from the db control?
1954 UInt16 rowHeight
= 0;
1955 m_dbImpl
->GetDefaultRowHeight(&rowHeight
);
1958 // get the actual row by taking scroll position into account
1959 UInt32 offsetX
, offsetY
;
1960 m_dbImpl
->GetScrollPosition( &offsetY
, &offsetX
);
1963 if ( !(GetWindowStyleFlag() & wxLC_NO_HEADER
) )
1964 y
-= colHeaderHeight
;
1969 int row
= y
/ rowHeight
;
1970 DataBrowserItemID id
;
1971 m_dbImpl
->GetItemID( (DataBrowserTableViewRowIndex
) row
, &id
);
1973 // TODO: Use GetDataBrowserItemPartBounds to return if we are in icon or label
1974 if ( !(GetWindowStyleFlag() & wxLC_VIRTUAL
) )
1976 wxMacListCtrlItem
* lcItem
;
1977 lcItem
= (wxMacListCtrlItem
*) id
;
1980 flags
= wxLIST_HITTEST_ONITEM
;
1986 if (row
< GetItemCount() )
1988 flags
= wxLIST_HITTEST_ONITEM
;
1997 int wxListCtrl::GetScrollPos(int orient
) const
2000 return m_genericImpl
->GetScrollPos(orient
);
2004 UInt32 offsetX
, offsetY
;
2005 m_dbImpl
->GetScrollPosition( &offsetY
, &offsetX
);
2006 if ( orient
== wxHORIZONTAL
)
2015 // Inserts an item, returning the index of the new item if successful,
2017 long wxListCtrl::InsertItem(wxListItem
& info
)
2019 wxASSERT_MSG( !IsVirtual(), _T("can't be used with virtual controls") );
2022 return m_genericImpl
->InsertItem(info
);
2024 if (m_dbImpl
&& !IsVirtual())
2026 int count
= GetItemCount();
2028 if (info
.m_itemId
> count
)
2029 info
.m_itemId
= count
;
2031 m_dbImpl
->MacInsertItem(info
.m_itemId
, &info
);
2033 wxListEvent
event( wxEVT_COMMAND_LIST_INSERT_ITEM
, GetId() );
2034 event
.SetEventObject( this );
2035 event
.m_itemIndex
= info
.m_itemId
;
2036 HandleWindowEvent( event
);
2037 return info
.m_itemId
;
2042 long wxListCtrl::InsertItem(long index
, const wxString
& label
)
2045 return m_genericImpl
->InsertItem(index
, label
);
2048 info
.m_text
= label
;
2049 info
.m_mask
= wxLIST_MASK_TEXT
;
2050 info
.m_itemId
= index
;
2051 return InsertItem(info
);
2054 // Inserts an image item
2055 long wxListCtrl::InsertItem(long index
, int imageIndex
)
2058 return m_genericImpl
->InsertItem(index
, imageIndex
);
2061 info
.m_image
= imageIndex
;
2062 info
.m_mask
= wxLIST_MASK_IMAGE
;
2063 info
.m_itemId
= index
;
2064 return InsertItem(info
);
2067 // Inserts an image/string item
2068 long wxListCtrl::InsertItem(long index
, const wxString
& label
, int imageIndex
)
2071 return m_genericImpl
->InsertItem(index
, label
, imageIndex
);
2074 info
.m_image
= imageIndex
;
2075 info
.m_text
= label
;
2076 info
.m_mask
= wxLIST_MASK_IMAGE
| wxLIST_MASK_TEXT
;
2077 info
.m_itemId
= index
;
2078 return InsertItem(info
);
2081 // For list view mode (only), inserts a column.
2082 long wxListCtrl::InsertColumn(long col
, wxListItem
& item
)
2085 return m_genericImpl
->InsertColumn(col
, item
);
2089 int width
= item
.GetWidth();
2090 if ( !(item
.GetMask() & wxLIST_MASK_WIDTH
) )
2093 DataBrowserPropertyType type
= kDataBrowserCustomType
; //kDataBrowserTextType;
2094 wxImageList
* imageList
= GetImageList(wxIMAGE_LIST_SMALL
);
2095 if (imageList
&& imageList
->GetImageCount() > 0)
2097 wxBitmap bmp
= imageList
->GetBitmap(0);
2099 // type = kDataBrowserIconAndTextType;
2102 SInt16 just
= teFlushDefault
;
2103 if (item
.GetMask() & wxLIST_MASK_FORMAT
)
2105 if (item
.GetAlign() == wxLIST_FORMAT_LEFT
)
2107 else if (item
.GetAlign() == wxLIST_FORMAT_CENTER
)
2109 else if (item
.GetAlign() == wxLIST_FORMAT_RIGHT
)
2110 just
= teFlushRight
;
2112 m_dbImpl
->InsertColumn(col
, type
, item
.GetText(), just
, width
);
2113 SetColumn(col
, item
);
2115 // set/remove options based on the wxListCtrl type.
2116 DataBrowserTableViewColumnID id
;
2117 m_dbImpl
->GetColumnIDFromIndex(col
, &id
);
2118 DataBrowserPropertyFlags flags
;
2119 verify_noerr(m_dbImpl
->GetPropertyFlags(id
, &flags
));
2120 if (GetWindowStyleFlag() & wxLC_EDIT_LABELS
)
2121 flags
|= kDataBrowserPropertyIsEditable
;
2123 if (GetWindowStyleFlag() & wxLC_VIRTUAL
){
2124 flags
&= ~kDataBrowserListViewSortableColumn
;
2126 verify_noerr(m_dbImpl
->SetPropertyFlags(id
, flags
));
2132 long wxListCtrl::InsertColumn(long col
,
2133 const wxString
& heading
,
2138 return m_genericImpl
->InsertColumn(col
, heading
, format
, width
);
2141 item
.m_mask
= wxLIST_MASK_TEXT
| wxLIST_MASK_FORMAT
;
2142 item
.m_text
= heading
;
2145 item
.m_mask
|= wxLIST_MASK_WIDTH
;
2146 item
.m_width
= width
;
2148 item
.m_format
= format
;
2150 return InsertColumn(col
, item
);
2153 // scroll the control by the given number of pixels (exception: in list view,
2154 // dx is interpreted as number of columns)
2155 bool wxListCtrl::ScrollList(int dx
, int dy
)
2158 return m_genericImpl
->ScrollList(dx
, dy
);
2162 m_dbImpl
->SetScrollPosition(dx
, dy
);
2168 bool wxListCtrl::SortItems(wxListCtrlCompare fn
, long data
)
2171 return m_genericImpl
->SortItems(fn
, data
);
2176 m_compareFuncData
= data
;
2177 SortDataBrowserContainer( m_dbImpl
->GetControlRef(), kDataBrowserNoItem
, true);
2179 // we need to do this after each call, else we get a crash from wxPython when
2180 // SortItems is called the second time.
2181 m_compareFunc
= NULL
;
2182 m_compareFuncData
= 0;
2188 void wxListCtrl::OnRenameTimer()
2190 wxCHECK_RET( HasCurrent(), wxT("unexpected rename timer") );
2192 EditLabel( m_current
);
2195 bool wxListCtrl::OnRenameAccept(long itemEdit
, const wxString
& value
)
2197 wxListEvent
le( wxEVT_COMMAND_LIST_END_LABEL_EDIT
, GetId() );
2198 le
.SetEventObject( this );
2199 le
.m_itemIndex
= itemEdit
;
2201 GetItem( le
.m_item
);
2202 le
.m_item
.m_text
= value
;
2203 return !HandleWindowEvent( le
) ||
2207 void wxListCtrl::OnRenameCancelled(long itemEdit
)
2209 // let owner know that the edit was cancelled
2210 wxListEvent
le( wxEVT_COMMAND_LIST_END_LABEL_EDIT
, GetParent()->GetId() );
2212 le
.SetEditCanceled(true);
2214 le
.SetEventObject( this );
2215 le
.m_itemIndex
= itemEdit
;
2217 GetItem( le
.m_item
);
2218 HandleWindowEvent( le
);
2221 // ----------------------------------------------------------------------------
2222 // virtual list controls
2223 // ----------------------------------------------------------------------------
2225 wxString
wxListCtrl::OnGetItemText(long WXUNUSED(item
), long WXUNUSED(col
)) const
2227 // this is a pure virtual function, in fact - which is not really pure
2228 // because the controls which are not virtual don't need to implement it
2229 wxFAIL_MSG( _T("wxListCtrl::OnGetItemText not supposed to be called") );
2231 return wxEmptyString
;
2234 int wxListCtrl::OnGetItemImage(long WXUNUSED(item
)) const
2236 wxCHECK_MSG(!GetImageList(wxIMAGE_LIST_SMALL
),
2238 wxT("List control has an image list, OnGetItemImage or OnGetItemColumnImage should be overridden."));
2242 int wxListCtrl::OnGetItemColumnImage(long item
, long column
) const
2245 return OnGetItemImage(item
);
2250 wxListItemAttr
*wxListCtrl::OnGetItemAttr(long WXUNUSED_UNLESS_DEBUG(item
)) const
2252 wxASSERT_MSG( item
>= 0 && item
< GetItemCount(),
2253 _T("invalid item index in OnGetItemAttr()") );
2255 // no attributes by default
2259 void wxListCtrl::SetItemCount(long count
)
2261 wxASSERT_MSG( IsVirtual(), _T("this is for virtual controls only") );
2265 m_genericImpl
->SetItemCount(count
);
2271 // we need to temporarily disable the new item creation notification
2272 // procedure to speed things up
2273 // FIXME: Even this doesn't seem to help much...
2275 // FIXME: Find a more efficient way to do this.
2276 m_dbImpl
->MacClear();
2278 DataBrowserCallbacks callbacks
;
2279 DataBrowserItemNotificationUPP itemUPP
;
2280 GetDataBrowserCallbacks(m_dbImpl
->GetControlRef(), &callbacks
);
2281 itemUPP
= callbacks
.u
.v1
.itemNotificationCallback
;
2282 callbacks
.u
.v1
.itemNotificationCallback
= 0;
2283 m_dbImpl
->SetCallbacks(&callbacks
);
2284 ::AddDataBrowserItems(m_dbImpl
->GetControlRef(), kDataBrowserNoItem
,
2285 count
, NULL
, kDataBrowserItemNoProperty
);
2286 callbacks
.u
.v1
.itemNotificationCallback
= itemUPP
;
2287 m_dbImpl
->SetCallbacks(&callbacks
);
2292 void wxListCtrl::RefreshItem(long item
)
2296 m_genericImpl
->RefreshItem(item
);
2301 GetItemRect(item
, rect
);
2305 void wxListCtrl::RefreshItems(long itemFrom
, long itemTo
)
2309 m_genericImpl
->RefreshItems(itemFrom
, itemTo
);
2313 wxRect rect1
, rect2
;
2314 GetItemRect(itemFrom
, rect1
);
2315 GetItemRect(itemTo
, rect2
);
2317 wxRect rect
= rect1
;
2318 rect
.height
= rect2
.GetBottom() - rect1
.GetTop();
2323 void wxListCtrl::SetDropTarget( wxDropTarget
*dropTarget
)
2325 #if wxUSE_DRAG_AND_DROP
2327 m_genericImpl
->SetDropTarget( dropTarget
);
2330 wxWindow::SetDropTarget( dropTarget
);
2334 wxDropTarget
*wxListCtrl::GetDropTarget() const
2336 #if wxUSE_DRAG_AND_DROP
2338 return m_genericImpl
->GetDropTarget();
2341 return wxWindow::GetDropTarget();
2346 #if wxABI_VERSION >= 20801
2347 void wxListCtrl::SetFocus()
2351 m_genericImpl
->SetFocus();
2355 wxWindow::SetFocus();
2359 // wxMac internal data structures
2361 wxMacListCtrlItem::~wxMacListCtrlItem()
2365 void wxMacListCtrlItem::Notification(wxMacDataItemBrowserControl
*owner
,
2366 DataBrowserItemNotification message
,
2367 DataBrowserItemDataRef
WXUNUSED(itemData
) ) const
2370 wxMacDataBrowserListCtrlControl
*lb
= wxDynamicCast(owner
, wxMacDataBrowserListCtrlControl
);
2372 // we want to depend on as little as possible to make sure tear-down of controls is safe
2373 if ( message
== kDataBrowserItemRemoved
)
2375 if ( lb
!= NULL
&& lb
->GetClientDataType() == wxClientData_Object
)
2377 delete (wxClientData
*) (m_data
);
2383 else if ( message
== kDataBrowserItemAdded
)
2385 // we don't issue events on adding, the item is not really stored in the list yet, so we
2386 // avoid asserts by gettting out now
2390 wxListCtrl
*list
= wxDynamicCast( owner
->GetPeer() , wxListCtrl
);
2393 bool trigger
= false;
2395 wxListEvent
event( wxEVT_COMMAND_LIST_ITEM_SELECTED
, list
->GetId() );
2396 bool isSingle
= (list
->GetWindowStyle() & wxLC_SINGLE_SEL
) != 0;
2398 event
.SetEventObject( list
);
2399 event
.m_itemIndex
= owner
->GetLineFromItem( this ) ;
2400 event
.m_item
.m_itemId
= event
.m_itemIndex
;
2401 list
->GetItem(event
.m_item
);
2405 case kDataBrowserItemDeselected
:
2406 event
.SetEventType(wxEVT_COMMAND_LIST_ITEM_DESELECTED
);
2408 trigger
= !lb
->IsSelectionSuppressed();
2411 case kDataBrowserItemSelected
:
2412 trigger
= !lb
->IsSelectionSuppressed();
2415 case kDataBrowserItemDoubleClicked
:
2416 event
.SetEventType( wxEVT_COMMAND_LIST_ITEM_ACTIVATED
);
2420 case kDataBrowserEditStarted
:
2421 // TODO : how to veto ?
2422 event
.SetEventType( wxEVT_COMMAND_LIST_BEGIN_LABEL_EDIT
) ;
2426 case kDataBrowserEditStopped
:
2427 // TODO probably trigger only upon the value store callback, because
2428 // here IIRC we cannot veto
2429 event
.SetEventType( wxEVT_COMMAND_LIST_END_LABEL_EDIT
) ;
2439 // direct notification is not always having the listbox GetSelection() having in synch with event
2440 wxPostEvent( list
->GetEventHandler(), event
);
2446 IMPLEMENT_DYNAMIC_CLASS(wxMacDataBrowserListCtrlControl
, wxMacDataItemBrowserControl
)
2448 wxMacDataBrowserListCtrlControl::wxMacDataBrowserListCtrlControl( wxWindow
*peer
, const wxPoint
& pos
, const wxSize
& size
, long style
)
2449 : wxMacDataItemBrowserControl( peer
, pos
, size
, style
)
2451 OSStatus err
= noErr
;
2452 m_clientDataItemsType
= wxClientData_None
;
2453 m_isVirtual
= false;
2456 if ( style
& wxLC_VIRTUAL
)
2459 DataBrowserSelectionFlags options
= kDataBrowserDragSelect
;
2460 if ( style
& wxLC_SINGLE_SEL
)
2462 options
|= kDataBrowserSelectOnlyOne
;
2466 options
|= kDataBrowserCmdTogglesSelection
;
2469 err
= SetSelectionFlags( options
);
2470 verify_noerr( err
);
2472 DataBrowserCustomCallbacks callbacks
;
2473 InitializeDataBrowserCustomCallbacks( &callbacks
, kDataBrowserLatestCustomCallbacks
);
2475 if ( gDataBrowserDrawItemUPP
== NULL
)
2476 gDataBrowserDrawItemUPP
= NewDataBrowserDrawItemUPP(DataBrowserDrawItemProc
);
2478 if ( gDataBrowserHitTestUPP
== NULL
)
2479 gDataBrowserHitTestUPP
= NewDataBrowserHitTestUPP(DataBrowserHitTestProc
);
2481 callbacks
.u
.v1
.drawItemCallback
= gDataBrowserDrawItemUPP
;
2482 callbacks
.u
.v1
.hitTestCallback
= gDataBrowserHitTestUPP
;
2484 SetDataBrowserCustomCallbacks( GetControlRef(), &callbacks
);
2486 if ( style
& wxLC_LIST
)
2488 InsertColumn(0, kDataBrowserIconAndTextType
, wxEmptyString
, -1, -1);
2489 verify_noerr( AutoSizeColumns() );
2492 if ( style
& wxLC_LIST
|| style
& wxLC_NO_HEADER
)
2493 verify_noerr( SetHeaderButtonHeight( 0 ) );
2496 SetSortProperty( kMinColumnId
- 1 );
2498 SetSortProperty( kMinColumnId
);
2500 m_sortOrder
= SortOrder_None
;
2502 if ( style
& wxLC_SORT_DESCENDING
)
2504 SetSortOrder( kDataBrowserOrderDecreasing
);
2506 else if ( style
& wxLC_SORT_ASCENDING
)
2508 SetSortOrder( kDataBrowserOrderIncreasing
);
2511 if ( style
& wxLC_VRULES
)
2513 verify_noerr( DataBrowserChangeAttributes(m_controlRef
, kDataBrowserAttributeListViewDrawColumnDividers
, kDataBrowserAttributeNone
) );
2516 verify_noerr( SetHiliteStyle(kDataBrowserTableViewFillHilite
) );
2517 verify_noerr( SetHasScrollBars( (style
& wxHSCROLL
) != 0 , true ) );
2520 pascal Boolean
wxMacDataBrowserListCtrlControl::DataBrowserEditTextProc(
2522 DataBrowserItemID itemID
,
2523 DataBrowserPropertyID property
,
2524 CFStringRef theString
,
2525 Rect
*maxEditTextRect
,
2526 Boolean
*shrinkToFit
)
2528 Boolean result
= false;
2529 wxMacDataBrowserListCtrlControl
* ctl
= wxDynamicCast(wxMacControl::GetReferenceFromNativeControl( browser
), wxMacDataBrowserListCtrlControl
);
2532 result
= ctl
->ConfirmEditText(itemID
, property
, theString
, maxEditTextRect
, shrinkToFit
);
2533 theString
= CFSTR("Hello!");
2538 bool wxMacDataBrowserListCtrlControl::ConfirmEditText(
2539 DataBrowserItemID
WXUNUSED(itemID
),
2540 DataBrowserPropertyID
WXUNUSED(property
),
2541 CFStringRef
WXUNUSED(theString
),
2542 Rect
*WXUNUSED(maxEditTextRect
),
2543 Boolean
*WXUNUSED(shrinkToFit
))
2548 pascal void wxMacDataBrowserListCtrlControl::DataBrowserDrawItemProc(
2550 DataBrowserItemID itemID
,
2551 DataBrowserPropertyID property
,
2552 DataBrowserItemState itemState
,
2553 const Rect
*itemRect
,
2555 Boolean colorDevice
)
2557 wxMacDataBrowserListCtrlControl
* ctl
= wxDynamicCast(wxMacControl::GetReferenceFromNativeControl( browser
), wxMacDataBrowserListCtrlControl
);
2560 ctl
->DrawItem(itemID
, property
, itemState
, itemRect
, gdDepth
, colorDevice
);
2564 // routines needed for DrawItem
2569 kTextBoxHeight
= 14,
2570 kIconTextSpacingV
= 2,
2572 kContentHeight
= kIconHeight
+ kTextBoxHeight
+ kIconTextSpacingV
2575 static void calculateCGDrawingBounds(CGRect inItemRect
, CGRect
*outIconRect
, CGRect
*outTextRect
, bool hasIcon
= false)
2578 float iconH
, iconW
= 0;
2579 float padding
= kItemPadding
;
2582 iconH
= kIconHeight
;
2584 padding
= padding
*2;
2587 textBottom
= inItemRect
.origin
.y
;
2589 *outIconRect
= CGRectMake(inItemRect
.origin
.x
+ kItemPadding
,
2590 textBottom
+ kIconTextSpacingV
, kIconWidth
,
2593 *outTextRect
= CGRectMake(inItemRect
.origin
.x
+ padding
+ iconW
,
2594 textBottom
+ kIconTextSpacingV
, inItemRect
.size
.width
- padding
- iconW
,
2595 inItemRect
.size
.height
- kIconTextSpacingV
);
2598 void wxMacDataBrowserListCtrlControl::DrawItem(
2599 DataBrowserItemID itemID
,
2600 DataBrowserPropertyID property
,
2601 DataBrowserItemState itemState
,
2602 const Rect
*WXUNUSED(itemRect
),
2604 Boolean colorDevice
)
2607 wxFont font
= wxNullFont
;
2609 short listColumn
= property
- kMinColumnId
;
2611 wxListCtrl
* list
= wxDynamicCast( GetPeer() , wxListCtrl
);
2612 wxMacListCtrlItem
* lcItem
;
2613 wxColour color
= *wxBLACK
;
2614 wxColour bgColor
= wxNullColour
;
2616 if (listColumn
>= 0)
2620 lcItem
= (wxMacListCtrlItem
*) itemID
;
2621 if (lcItem
->HasColumnInfo(listColumn
)){
2622 wxListItem
* item
= lcItem
->GetColumnInfo(listColumn
);
2624 // we always use the 0 column to get font and text/background colors.
2625 if (lcItem
->HasColumnInfo(0))
2627 wxListItem
* firstItem
= lcItem
->GetColumnInfo(0);
2628 color
= firstItem
->GetTextColour();
2629 bgColor
= firstItem
->GetBackgroundColour();
2630 font
= firstItem
->GetFont();
2633 if (item
->GetMask() & wxLIST_MASK_TEXT
)
2634 text
= item
->GetText();
2635 if (item
->GetMask() & wxLIST_MASK_IMAGE
)
2636 imgIndex
= item
->GetImage();
2642 long itemNum
= (long)itemID
-1;
2643 if (itemNum
>= 0 && itemNum
< list
->GetItemCount())
2645 text
= list
->OnGetItemText( itemNum
, listColumn
);
2646 imgIndex
= list
->OnGetItemColumnImage( itemNum
, listColumn
);
2647 wxListItemAttr
* attrs
= list
->OnGetItemAttr( itemNum
);
2650 if (attrs
->HasBackgroundColour())
2651 bgColor
= attrs
->GetBackgroundColour();
2652 if (attrs
->HasTextColour())
2653 color
= attrs
->GetTextColour();
2654 if (attrs
->HasFont())
2655 font
= attrs
->GetFont();
2661 wxColour listBgColor
= list
->GetBackgroundColour();
2662 if (bgColor
== wxNullColour
)
2663 bgColor
= listBgColor
;
2665 wxFont listFont
= list
->GetFont();
2666 if (font
== wxNullFont
)
2669 wxCFStringRef
cfString( text
, wxLocale::GetSystemEncoding() );
2672 CGRect enclosingCGRect
, iconCGRect
, textCGRect
;
2674 ThemeDrawingState savedState
= NULL
;
2675 CGContextRef context
= (CGContextRef
)list
->MacGetDrawingContext();
2676 RGBColor labelColor
;
2678 labelColor
.green
= 0;
2679 labelColor
.blue
= 0;
2681 RGBColor backgroundColor
;
2682 backgroundColor
.red
= 255;
2683 backgroundColor
.green
= 255;
2684 backgroundColor
.blue
= 255;
2686 GetDataBrowserItemPartBounds(GetControlRef(), itemID
, property
, kDataBrowserPropertyEnclosingPart
,
2689 enclosingCGRect
= CGRectMake(enclosingRect
.left
,
2691 enclosingRect
.right
- enclosingRect
.left
,
2692 enclosingRect
.bottom
- enclosingRect
.top
);
2694 bool hasFocus
= (wxWindow::FindFocus() == list
);
2695 active
= IsControlActive(GetControlRef());
2697 // don't paint the background over the vertical rule line
2698 if ( list
->GetWindowStyleFlag() & wxLC_VRULES
)
2700 enclosingCGRect
.origin
.x
+= 1;
2701 enclosingCGRect
.size
.width
-= 1;
2703 if (itemState
== kDataBrowserItemIsSelected
)
2706 GetThemeDrawingState(&savedState
);
2708 if (active
&& hasFocus
)
2710 GetThemeBrushAsColor(kThemeBrushAlternatePrimaryHighlightColor
, 32, true, &backgroundColor
);
2711 GetThemeTextColor(kThemeTextColorWhite
, gdDepth
, colorDevice
, &labelColor
);
2715 GetThemeBrushAsColor(kThemeBrushSecondaryHighlightColor
, 32, true, &backgroundColor
);
2716 GetThemeTextColor(kThemeTextColorBlack
, gdDepth
, colorDevice
, &labelColor
);
2718 CGContextSaveGState(context
);
2720 CGContextSetRGBFillColor(context
, (float)backgroundColor
.red
/ (float)USHRT_MAX
,
2721 (float)backgroundColor
.green
/ (float)USHRT_MAX
,
2722 (float)backgroundColor
.blue
/ (float)USHRT_MAX
, 1.0);
2723 CGContextFillRect(context
, enclosingCGRect
);
2725 CGContextRestoreGState(context
);
2731 color
.GetRGBColor(&labelColor
);
2732 else if (list
->GetTextColour().Ok())
2733 list
->GetTextColour().GetRGBColor(&labelColor
);
2737 bgColor
.GetRGBColor(&backgroundColor
);
2738 CGContextSaveGState(context
);
2740 CGContextSetRGBFillColor(context
, (float)backgroundColor
.red
/ (float)USHRT_MAX
,
2741 (float)backgroundColor
.green
/ (float)USHRT_MAX
,
2742 (float)backgroundColor
.blue
/ (float)USHRT_MAX
, 1.0);
2743 CGContextFillRect(context
, enclosingCGRect
);
2745 CGContextRestoreGState(context
);
2749 calculateCGDrawingBounds(enclosingCGRect
, &iconCGRect
, &textCGRect
, (imgIndex
!= -1) );
2753 wxImageList
* imageList
= list
->GetImageList(wxIMAGE_LIST_SMALL
);
2754 if (imageList
&& imageList
->GetImageCount() > 0){
2755 wxBitmap bmp
= imageList
->GetBitmap(imgIndex
);
2756 IconRef icon
= bmp
.GetIconRef();
2758 CGContextSaveGState(context
);
2759 CGContextTranslateCTM(context
, 0,iconCGRect
.origin
.y
+ CGRectGetMaxY(iconCGRect
));
2760 CGContextScaleCTM(context
,1.0f
,-1.0f
);
2761 PlotIconRefInContext(context
, &iconCGRect
, kAlignNone
,
2762 active
? kTransformNone
: kTransformDisabled
, NULL
,
2763 kPlotIconRefNormalFlags
, icon
);
2765 CGContextRestoreGState(context
);
2769 HIThemeTextHorizontalFlush hFlush
= kHIThemeTextHorizontalFlushLeft
;
2770 HIThemeTextInfo info
;
2772 #if wxMAC_USE_CORE_TEXT
2773 if ( UMAGetSystemVersion() >= 0x1050 )
2775 info
.version
= kHIThemeTextInfoVersionOne
;
2776 info
.fontID
= kThemeViewsFont
;
2779 info
.fontID
= kThemeSpecifiedFont
;
2780 info
.font
= (CTFontRef
) font
.MacGetCTFont();
2785 #if wxMAC_USE_ATSU_TEXT
2788 info
.version
= kHIThemeTextInfoVersionZero
;
2789 info
.fontID
= kThemeViewsFont
;
2793 if (font
.GetFamily() != wxFONTFAMILY_DEFAULT
)
2794 info
.fontID
= font
.MacGetThemeFontID();
2796 ::TextSize( (short)(font
.MacGetFontSize()) ) ;
2797 ::TextFace( font
.MacGetFontStyle() ) ;
2803 list
->GetColumn(listColumn
, item
);
2804 if (item
.GetMask() & wxLIST_MASK_FORMAT
)
2806 if (item
.GetAlign() == wxLIST_FORMAT_LEFT
)
2807 hFlush
= kHIThemeTextHorizontalFlushLeft
;
2808 else if (item
.GetAlign() == wxLIST_FORMAT_CENTER
)
2809 hFlush
= kHIThemeTextHorizontalFlushCenter
;
2810 else if (item
.GetAlign() == wxLIST_FORMAT_RIGHT
)
2812 hFlush
= kHIThemeTextHorizontalFlushRight
;
2813 textCGRect
.origin
.x
-= kItemPadding
; // give a little extra paddding
2817 info
.state
= active
? kThemeStateActive
: kThemeStateInactive
;
2818 info
.horizontalFlushness
= hFlush
;
2819 info
.verticalFlushness
= kHIThemeTextVerticalFlushCenter
;
2820 info
.options
= kHIThemeTextBoxOptionNone
;
2821 info
.truncationPosition
= kHIThemeTextTruncationEnd
;
2822 info
.truncationMaxLines
= 1;
2824 CGContextSaveGState(context
);
2825 CGContextSetRGBFillColor (context
, (float)labelColor
.red
/ (float)USHRT_MAX
,
2826 (float)labelColor
.green
/ (float)USHRT_MAX
,
2827 (float)labelColor
.blue
/ (float)USHRT_MAX
, 1.0);
2829 HIThemeDrawTextBox(cfString
, &textCGRect
, &info
, context
, kHIThemeOrientationNormal
);
2831 CGContextRestoreGState(context
);
2834 if (savedState
!= NULL
)
2835 SetThemeDrawingState(savedState
, true);
2839 OSStatus
wxMacDataBrowserListCtrlControl::GetSetItemData(DataBrowserItemID itemID
,
2840 DataBrowserPropertyID property
,
2841 DataBrowserItemDataRef itemData
,
2842 Boolean changeValue
)
2846 short listColumn
= property
- kMinColumnId
;
2848 OSStatus err
= errDataBrowserPropertyNotSupported
;
2849 wxListCtrl
* list
= wxDynamicCast( GetPeer() , wxListCtrl
);
2850 wxMacListCtrlItem
* lcItem
;
2852 if (listColumn
>= 0)
2856 lcItem
= (wxMacListCtrlItem
*) itemID
;
2857 if (lcItem
&& lcItem
->HasColumnInfo(listColumn
)){
2858 wxListItem
* item
= lcItem
->GetColumnInfo(listColumn
);
2859 if (item
->GetMask() & wxLIST_MASK_TEXT
)
2860 text
= item
->GetText();
2861 if (item
->GetMask() & wxLIST_MASK_IMAGE
)
2862 imgIndex
= item
->GetImage();
2867 long itemNum
= (long)itemID
-1;
2868 if (itemNum
>= 0 && itemNum
< list
->GetItemCount())
2870 text
= list
->OnGetItemText( itemNum
, listColumn
);
2871 imgIndex
= list
->OnGetItemColumnImage( itemNum
, listColumn
);
2880 case kDataBrowserItemIsEditableProperty
:
2881 if ( list
&& list
->HasFlag( wxLC_EDIT_LABELS
) )
2883 verify_noerr(SetDataBrowserItemDataBooleanValue( itemData
, true ));
2888 if ( property
>= kMinColumnId
)
2890 if (!text
.IsEmpty()){
2891 wxCFStringRef
cfStr( text
, wxLocale::GetSystemEncoding() );
2892 err
= ::SetDataBrowserItemDataText( itemData
, cfStr
);
2898 if ( imgIndex
!= -1 )
2900 wxImageList
* imageList
= list
->GetImageList(wxIMAGE_LIST_SMALL
);
2901 if (imageList
&& imageList
->GetImageCount() > 0){
2902 wxBitmap bmp
= imageList
->GetBitmap(imgIndex
);
2903 IconRef icon
= bmp
.GetIconRef();
2904 ::SetDataBrowserItemDataIcon(itemData
, icon
);
2918 if ( property
>= kMinColumnId
)
2920 short listColumn
= property
- kMinColumnId
;
2922 // TODO probably send the 'end edit' from here, as we
2923 // can then deal with the veto
2925 verify_noerr( GetDataBrowserItemDataText( itemData
, &sr
) ) ;
2926 wxCFStringRef
cfStr(sr
) ;;
2928 list
->SetItem( (long)itemData
-1 , listColumn
, cfStr
.AsString() ) ;
2932 lcItem
->SetColumnTextValue( listColumn
, cfStr
.AsString() );
2942 void wxMacDataBrowserListCtrlControl::ItemNotification(DataBrowserItemID itemID
,
2943 DataBrowserItemNotification message
,
2944 DataBrowserItemDataRef
WXUNUSED(itemData
) )
2946 // we want to depend on as little as possible to make sure tear-down of controls is safe
2947 if ( message
== kDataBrowserItemRemoved
)
2949 // make sure MacDelete does the proper teardown.
2952 else if ( message
== kDataBrowserItemAdded
)
2954 // we don't issue events on adding, the item is not really stored in the list yet, so we
2955 // avoid asserts by getting out now
2959 wxListCtrl
*list
= wxDynamicCast( GetPeer() , wxListCtrl
);
2962 bool trigger
= false;
2964 wxListEvent
event( wxEVT_COMMAND_LIST_ITEM_SELECTED
, list
->GetId() );
2966 event
.SetEventObject( list
);
2967 if ( !list
->IsVirtual() )
2969 DataBrowserTableViewRowIndex result
= 0;
2970 verify_noerr( GetItemRow( itemID
, &result
) ) ;
2971 event
.m_itemIndex
= result
;
2975 event
.m_itemIndex
= (long)itemID
-1;
2977 event
.m_item
.m_itemId
= event
.m_itemIndex
;
2978 list
->GetItem(event
.m_item
);
2982 case kDataBrowserItemDeselected
:
2983 event
.SetEventType(wxEVT_COMMAND_LIST_ITEM_DESELECTED
);
2984 // as the generic implementation is also triggering this
2985 // event for single selection, we do the same (different than listbox)
2986 trigger
= !IsSelectionSuppressed();
2989 case kDataBrowserItemSelected
:
2990 trigger
= !IsSelectionSuppressed();
2994 case kDataBrowserItemDoubleClicked
:
2995 event
.SetEventType( wxEVT_COMMAND_LIST_ITEM_ACTIVATED
);
2999 case kDataBrowserEditStarted
:
3000 // TODO : how to veto ?
3001 event
.SetEventType( wxEVT_COMMAND_LIST_BEGIN_LABEL_EDIT
) ;
3005 case kDataBrowserEditStopped
:
3006 // TODO probably trigger only upon the value store callback, because
3007 // here IIRC we cannot veto
3008 event
.SetEventType( wxEVT_COMMAND_LIST_END_LABEL_EDIT
) ;
3018 // direct notification is not always having the listbox GetSelection() having in synch with event
3019 wxPostEvent( list
->GetEventHandler(), event
);
3024 Boolean
wxMacDataBrowserListCtrlControl::CompareItems(DataBrowserItemID itemOneID
,
3025 DataBrowserItemID itemTwoID
,
3026 DataBrowserPropertyID sortProperty
)
3029 bool retval
= false;
3031 wxString otherItemText
;
3033 long otherItemOrder
;
3035 int colId
= sortProperty
- kMinColumnId
;
3037 wxListCtrl
* list
= wxDynamicCast( GetPeer() , wxListCtrl
);
3039 DataBrowserSortOrder sort
;
3040 verify_noerr(GetSortOrder(&sort
));
3046 wxMacListCtrlItem
* item
= (wxMacListCtrlItem
*)itemOneID
;
3047 wxMacListCtrlItem
* otherItem
= (wxMacListCtrlItem
*)itemTwoID
;
3049 itemOrder
= item
->GetOrder();
3050 otherItemOrder
= item
->GetOrder();
3052 wxListCtrlCompare func
= list
->GetCompareFunc();
3057 if (item
&& item
->HasColumnInfo(0))
3058 item1
= item
->GetColumnInfo(0)->GetData();
3059 if (otherItem
&& otherItem
->HasColumnInfo(0))
3060 item2
= otherItem
->GetColumnInfo(0)->GetData();
3062 if (item1
> -1 && item2
> -1)
3064 int result
= func(item1
, item2
, list
->GetCompareFuncData());
3065 if (sort
== kDataBrowserOrderIncreasing
)
3072 // we can't use the native control's sorting abilities, so just
3074 return itemOrder
< otherItemOrder
;
3079 long itemNum
= (long)itemOneID
;
3080 long otherItemNum
= (long)itemTwoID
;
3082 // virtual listctrls don't support sorting
3083 return itemNum
< otherItemNum
;
3087 // fallback for undefined cases
3088 retval
= itemOneID
< itemTwoID
;
3094 wxMacDataBrowserListCtrlControl::~wxMacDataBrowserListCtrlControl()
3098 void wxMacDataBrowserListCtrlControl::MacSetColumnInfo( unsigned int row
, unsigned int column
, wxListItem
* item
)
3100 wxMacDataItem
* dataItem
= GetItemFromLine(row
);
3101 wxASSERT_MSG( dataItem
, _T("could not obtain wxMacDataItem for row in MacSetColumnInfo. Is row a valid wxListCtrl row?") );
3104 wxMacListCtrlItem
* listItem
= wx_static_cast(wxMacListCtrlItem
*,dataItem
);
3105 bool hasInfo
= listItem
->HasColumnInfo( column
);
3106 listItem
->SetColumnInfo( column
, item
);
3107 listItem
->SetOrder(row
);
3108 UpdateState(dataItem
, item
);
3110 wxListCtrl
* list
= wxDynamicCast( GetPeer() , wxListCtrl
);
3112 // NB: When this call was made before a control was completely shown, it would
3113 // update the item prematurely (i.e. no text would be listed) and, on show,
3114 // only the sorted column would be refreshed, meaning only first column text labels
3115 // would be shown. Making sure not to update items until the control is visible
3116 // seems to fix this issue.
3117 if (hasInfo
&& list
->IsShown())
3118 UpdateItem( wxMacDataBrowserRootContainer
, listItem
, kMinColumnId
+ column
);
3122 // apply changes that need to happen immediately, rather than when the
3123 // databrowser control fires a callback.
3124 void wxMacDataBrowserListCtrlControl::UpdateState(wxMacDataItem
* dataItem
, wxListItem
* listItem
)
3126 bool isSelected
= IsItemSelected( dataItem
);
3127 bool isSelectedState
= (listItem
->GetState() == wxLIST_STATE_SELECTED
);
3129 // toggle the selection state if wxListInfo state and actual state don't match.
3130 if ( listItem
->GetMask() & wxLIST_MASK_STATE
&& isSelected
!= isSelectedState
)
3132 DataBrowserSetOption options
= kDataBrowserItemsAdd
;
3133 if (!isSelectedState
)
3134 options
= kDataBrowserItemsRemove
;
3135 SetSelectedItem(dataItem
, options
);
3137 // TODO: Set column width if item width > than current column width
3140 void wxMacDataBrowserListCtrlControl::MacGetColumnInfo( unsigned int row
, unsigned int column
, wxListItem
& item
)
3142 wxMacDataItem
* dataItem
= GetItemFromLine(row
);
3143 wxASSERT_MSG( dataItem
, _T("could not obtain wxMacDataItem in MacGetColumnInfo. Is row a valid wxListCtrl row?") );
3144 // CS should this guard against dataItem = 0 ? , as item is not a pointer if (item) is not appropriate
3147 wxMacListCtrlItem
* listItem
=wx_static_cast(wxMacListCtrlItem
*,dataItem
);
3149 if (!listItem
->HasColumnInfo( column
))
3152 wxListItem
* oldItem
= listItem
->GetColumnInfo( column
);
3156 long mask
= item
.GetMask();
3158 // by default, get everything for backwards compatibility
3161 if ( mask
& wxLIST_MASK_TEXT
)
3162 item
.SetText(oldItem
->GetText());
3163 if ( mask
& wxLIST_MASK_IMAGE
)
3164 item
.SetImage(oldItem
->GetImage());
3165 if ( mask
& wxLIST_MASK_DATA
)
3166 item
.SetData(oldItem
->GetData());
3167 if ( mask
& wxLIST_MASK_STATE
)
3168 item
.SetState(oldItem
->GetState());
3169 if ( mask
& wxLIST_MASK_WIDTH
)
3170 item
.SetWidth(oldItem
->GetWidth());
3171 if ( mask
& wxLIST_MASK_FORMAT
)
3172 item
.SetAlign(oldItem
->GetAlign());
3174 item
.SetTextColour(oldItem
->GetTextColour());
3175 item
.SetBackgroundColour(oldItem
->GetBackgroundColour());
3176 item
.SetFont(oldItem
->GetFont());
3181 void wxMacDataBrowserListCtrlControl::MacInsertItem( unsigned int n
, wxListItem
* item
)
3183 wxMacDataItemBrowserControl::MacInsert(n
, item
->GetText());
3184 MacSetColumnInfo(n
, 0, item
);
3187 wxMacDataItem
* wxMacDataBrowserListCtrlControl::CreateItem()
3189 return new wxMacListCtrlItem();
3192 wxMacListCtrlItem::wxMacListCtrlItem()
3194 m_rowItems
= wxListItemList();
3197 int wxMacListCtrlItem::GetColumnImageValue( unsigned int column
)
3199 if ( HasColumnInfo(column
) )
3200 return GetColumnInfo(column
)->GetImage();
3205 void wxMacListCtrlItem::SetColumnImageValue( unsigned int column
, int imageIndex
)
3207 if ( HasColumnInfo(column
) )
3208 GetColumnInfo(column
)->SetImage(imageIndex
);
3211 wxString
wxMacListCtrlItem::GetColumnTextValue( unsigned int column
)
3216 if ( HasColumnInfo(column
) )
3217 return GetColumnInfo(column
)->GetText();
3219 return wxEmptyString
;
3222 void wxMacListCtrlItem::SetColumnTextValue( unsigned int column
, const wxString
& text
)
3224 if ( HasColumnInfo(column
) )
3225 GetColumnInfo(column
)->SetText(text
);
3227 // for compatibility with superclass APIs
3232 wxListItem
* wxMacListCtrlItem::GetColumnInfo( unsigned int column
)
3234 wxASSERT_MSG( HasColumnInfo(column
), _T("invalid column index in wxMacListCtrlItem") );
3235 return m_rowItems
[column
];
3238 bool wxMacListCtrlItem::HasColumnInfo( unsigned int column
)
3240 return !(m_rowItems
.find( column
) == m_rowItems
.end());
3243 void wxMacListCtrlItem::SetColumnInfo( unsigned int column
, wxListItem
* item
)
3246 if ( !HasColumnInfo(column
) )
3248 wxListItem
* listItem
= new wxListItem(*item
);
3249 m_rowItems
[column
] = listItem
;
3253 wxListItem
* listItem
= GetColumnInfo( column
);
3254 long mask
= item
->GetMask();
3255 if (mask
& wxLIST_MASK_TEXT
)
3256 listItem
->SetText(item
->GetText());
3257 if (mask
& wxLIST_MASK_DATA
)
3258 listItem
->SetData(item
->GetData());
3259 if (mask
& wxLIST_MASK_IMAGE
)
3260 listItem
->SetImage(item
->GetImage());
3261 if (mask
& wxLIST_MASK_STATE
)
3262 listItem
->SetState(item
->GetState());
3263 if (mask
& wxLIST_MASK_FORMAT
)
3264 listItem
->SetAlign(item
->GetAlign());
3265 if (mask
& wxLIST_MASK_WIDTH
)
3266 listItem
->SetWidth(item
->GetWidth());
3268 if ( item
->HasAttributes() )
3270 if ( listItem
->HasAttributes() )
3271 listItem
->GetAttributes()->AssignFrom(*item
->GetAttributes());
3274 listItem
->SetTextColour(item
->GetTextColour());
3275 listItem
->SetBackgroundColour(item
->GetBackgroundColour());
3276 listItem
->SetFont(item
->GetFont());
3282 #endif // wxUSE_LISTCTRL