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
->GetEventHandler()->ProcessEvent( 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 browser
,
263 DataBrowserItemID itemID
,
264 DataBrowserPropertyID property
,
266 const Rect
*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
->GetEventHandler()->ProcessEvent( event
))
311 return wxEvtHandler::ProcessEvent(event
);
314 //-----------------------------------------------------------------------------
315 // wxListCtrlRenameTimer (internal)
316 //-----------------------------------------------------------------------------
318 class wxListCtrlRenameTimer
: public wxTimer
324 wxListCtrlRenameTimer( wxListCtrl
*owner
);
328 //-----------------------------------------------------------------------------
329 // wxListCtrlTextCtrlWrapper: wraps a wxTextCtrl to make it work for inline editing
330 //-----------------------------------------------------------------------------
332 class wxListCtrlTextCtrlWrapper
: public wxEvtHandler
335 // NB: text must be a valid object but not Create()d yet
336 wxListCtrlTextCtrlWrapper(wxListCtrl
*owner
,
340 wxTextCtrl
*GetText() const { return m_text
; }
342 void AcceptChangesAndFinish();
345 void OnChar( wxKeyEvent
&event
);
346 void OnKeyUp( wxKeyEvent
&event
);
347 void OnKillFocus( wxFocusEvent
&event
);
349 bool AcceptChanges();
355 wxString m_startValue
;
358 bool m_aboutToFinish
;
360 DECLARE_EVENT_TABLE()
363 //-----------------------------------------------------------------------------
364 // wxListCtrlRenameTimer (internal)
365 //-----------------------------------------------------------------------------
367 wxListCtrlRenameTimer::wxListCtrlRenameTimer( wxListCtrl
*owner
)
372 void wxListCtrlRenameTimer::Notify()
374 m_owner
->OnRenameTimer();
377 //-----------------------------------------------------------------------------
378 // wxListCtrlTextCtrlWrapper (internal)
379 //-----------------------------------------------------------------------------
381 BEGIN_EVENT_TABLE(wxListCtrlTextCtrlWrapper
, wxEvtHandler
)
382 EVT_CHAR (wxListCtrlTextCtrlWrapper::OnChar
)
383 EVT_KEY_UP (wxListCtrlTextCtrlWrapper::OnKeyUp
)
384 EVT_KILL_FOCUS (wxListCtrlTextCtrlWrapper::OnKillFocus
)
387 wxListCtrlTextCtrlWrapper::wxListCtrlTextCtrlWrapper(wxListCtrl
*owner
,
390 : m_startValue(owner
->GetItemText(itemEdit
)),
391 m_itemEdited(itemEdit
)
396 m_aboutToFinish
= false;
400 owner
->GetItemRect(itemEdit
, rectLabel
);
402 m_text
->Create(owner
, wxID_ANY
, m_startValue
,
403 wxPoint(rectLabel
.x
+offset
,rectLabel
.y
),
404 wxSize(rectLabel
.width
-offset
,rectLabel
.height
));
407 m_text
->PushEventHandler(this);
410 void wxListCtrlTextCtrlWrapper::Finish()
416 m_text
->RemoveEventHandler(this);
417 m_owner
->FinishEditing(m_text
);
419 wxPendingDelete
.Append( this );
423 bool wxListCtrlTextCtrlWrapper::AcceptChanges()
425 const wxString value
= m_text
->GetValue();
427 if ( value
== m_startValue
)
428 // nothing changed, always accept
431 if ( !m_owner
->OnRenameAccept(m_itemEdited
, value
) )
432 // vetoed by the user
435 // accepted, do rename the item
436 m_owner
->SetItemText(m_itemEdited
, value
);
441 void wxListCtrlTextCtrlWrapper::AcceptChangesAndFinish()
443 m_aboutToFinish
= true;
445 // Notify the owner about the changes
448 // Even if vetoed, close the control (consistent with MSW)
452 void wxListCtrlTextCtrlWrapper::OnChar( wxKeyEvent
&event
)
454 switch ( event
.m_keyCode
)
457 AcceptChangesAndFinish();
461 m_owner
->OnRenameCancelled( m_itemEdited
);
470 void wxListCtrlTextCtrlWrapper::OnKeyUp( wxKeyEvent
&event
)
478 // auto-grow the textctrl:
479 wxSize parentSize
= m_owner
->GetSize();
480 wxPoint myPos
= m_text
->GetPosition();
481 wxSize mySize
= m_text
->GetSize();
483 m_text
->GetTextExtent(m_text
->GetValue() + _T("MM"), &sx
, &sy
);
484 if (myPos
.x
+ sx
> parentSize
.x
)
485 sx
= parentSize
.x
- myPos
.x
;
488 m_text
->SetSize(sx
, wxDefaultCoord
);
493 void wxListCtrlTextCtrlWrapper::OnKillFocus( wxFocusEvent
&event
)
495 if ( !m_finished
&& !m_aboutToFinish
)
497 if ( !AcceptChanges() )
498 m_owner
->OnRenameCancelled( m_itemEdited
);
503 // We must let the native text control handle focus
507 BEGIN_EVENT_TABLE(wxListCtrl
, wxControl
)
508 EVT_LEFT_DOWN(wxListCtrl::OnLeftDown
)
509 EVT_LEFT_DCLICK(wxListCtrl::OnDblClick
)
510 EVT_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 GetEventHandler()->ProcessEvent(le
);
655 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 le
.m_itemIndex
= m_current
;
667 le
.m_item
.m_itemId
= m_current
;
669 GetEventHandler()->ProcessEvent(le
);
676 bool wxListCtrl::Create(wxWindow
*parent
,
681 const wxValidator
& validator
,
682 const wxString
& name
)
685 // for now, we'll always use the generic list control for ICON and LIST views,
686 // because they dynamically change the number of columns on resize.
687 // Also, allow the user to set it to use the list ctrl as well.
688 if ( (wxSystemOptions::HasOption( wxMAC_ALWAYS_USE_GENERIC_LISTCTRL
)
689 && (wxSystemOptions::GetOptionInt( wxMAC_ALWAYS_USE_GENERIC_LISTCTRL
) == 1)) ||
690 (style
& wxLC_ICON
) || (style
& wxLC_SMALL_ICON
) || (style
& wxLC_LIST
) )
692 m_macIsUserPane
= true;
694 long paneStyle
= style
;
695 paneStyle
&= ~wxSIMPLE_BORDER
;
696 paneStyle
&= ~wxDOUBLE_BORDER
;
697 paneStyle
&= ~wxSUNKEN_BORDER
;
698 paneStyle
&= ~wxRAISED_BORDER
;
699 paneStyle
&= ~wxSTATIC_BORDER
;
700 if ( !wxWindow::Create(parent
, id
, pos
, size
, paneStyle
| wxNO_BORDER
, name
) )
703 // since the generic control is a child, make sure we position it at 0, 0
704 m_genericImpl
= new wxGenericListCtrlHook(this, id
, wxPoint(0, 0), size
, style
, validator
, name
);
705 m_genericImpl
->PushEventHandler( new wxMacListCtrlEventDelegate( this, GetId() ) );
711 m_macIsUserPane
= false;
712 if ( !wxWindow::Create(parent
, id
, pos
, size
, style
& ~(wxHSCROLL
| wxVSCROLL
), name
) )
714 m_dbImpl
= new wxMacDataBrowserListCtrlControl( this, pos
, size
, style
);
717 MacPostControlCreate( pos
, size
);
719 InstallControlEventHandler( m_peer
->GetControlRef() , GetwxMacListCtrlEventHandlerUPP(),
720 GetEventTypeCount(eventList
), eventList
, this,
721 (EventHandlerRef
*)&m_macListCtrlEventHandler
);
727 wxListCtrl::~wxListCtrl()
731 m_genericImpl
->PopEventHandler(/* deleteHandler = */ true);
734 if (m_ownsImageListNormal
)
735 delete m_imageListNormal
;
736 if (m_ownsImageListSmall
)
737 delete m_imageListSmall
;
738 if (m_ownsImageListState
)
739 delete m_imageListState
;
741 delete m_renameTimer
;
744 // ----------------------------------------------------------------------------
745 // set/get/change style
746 // ----------------------------------------------------------------------------
748 // Add or remove a single window style
749 void wxListCtrl::SetSingleStyle(long style
, bool add
)
751 long flag
= GetWindowStyleFlag();
753 // Get rid of conflicting styles
756 if ( style
& wxLC_MASK_TYPE
)
757 flag
= flag
& ~wxLC_MASK_TYPE
;
758 if ( style
& wxLC_MASK_ALIGN
)
759 flag
= flag
& ~wxLC_MASK_ALIGN
;
760 if ( style
& wxLC_MASK_SORT
)
761 flag
= flag
& ~wxLC_MASK_SORT
;
769 SetWindowStyleFlag(flag
);
772 // Set the whole window style
773 void wxListCtrl::SetWindowStyleFlag(long flag
)
775 if ( flag
!= m_windowStyle
)
777 m_windowStyle
= flag
;
781 m_genericImpl
->SetWindowStyleFlag(flag
);
788 void wxListCtrl::DoSetSize( int x
, int y
, int width
, int height
, int sizeFlags
)
790 wxControl::DoSetSize(x
, y
, width
, height
, sizeFlags
);
793 m_genericImpl
->SetSize(0, 0, width
, height
, sizeFlags
);
795 // determine if we need a horizontal scrollbar, and add it if so
799 for (int column
= 0; column
< GetColumnCount(); column
++)
801 totalWidth
+= m_dbImpl
->GetColumnWidth( column
);
804 if ( !(m_dbImpl
->GetFlags() & wxHSCROLL
) )
806 Boolean vertScrollBar
;
807 GetDataBrowserHasScrollBars( m_dbImpl
->GetControlRef(), NULL
, &vertScrollBar
);
808 if (totalWidth
> width
)
809 SetDataBrowserHasScrollBars( m_dbImpl
->GetControlRef(), true, vertScrollBar
);
811 SetDataBrowserHasScrollBars( m_dbImpl
->GetControlRef(), false, vertScrollBar
);
816 wxSize
wxListCtrl::DoGetBestSize() const
818 return wxWindow::DoGetBestSize();
821 bool wxListCtrl::SetFont(const wxFont
& font
)
824 rv
= wxControl::SetFont(font
);
826 rv
= m_genericImpl
->SetFont(font
);
830 bool wxListCtrl::SetForegroundColour(const wxColour
& colour
)
834 rv
= m_genericImpl
->SetForegroundColour(colour
);
836 SetTextColour(colour
);
840 bool wxListCtrl::SetBackgroundColour(const wxColour
& colour
)
844 rv
= m_genericImpl
->SetBackgroundColour(colour
);
850 wxColour
wxListCtrl::GetBackgroundColour()
853 return m_genericImpl
->GetBackgroundColour();
860 // ----------------------------------------------------------------------------
862 // ----------------------------------------------------------------------------
864 // Gets information about this column
865 bool wxListCtrl::GetColumn(int col
, wxListItem
& item
) const
868 return m_genericImpl
->GetColumn(col
, item
);
874 wxColumnList::compatibility_iterator node
= m_colsInfo
.Item( col
);
875 wxASSERT_MSG( node
, _T("invalid column index in wxMacListCtrlItem") );
876 wxListItem
* column
= node
->GetData();
878 long mask
= column
->GetMask();
879 if (mask
& wxLIST_MASK_TEXT
)
880 item
.SetText(column
->GetText());
881 if (mask
& wxLIST_MASK_DATA
)
882 item
.SetData(column
->GetData());
883 if (mask
& wxLIST_MASK_IMAGE
)
884 item
.SetImage(column
->GetImage());
885 if (mask
& wxLIST_MASK_STATE
)
886 item
.SetState(column
->GetState());
887 if (mask
& wxLIST_MASK_FORMAT
)
888 item
.SetAlign(column
->GetAlign());
889 if (mask
& wxLIST_MASK_WIDTH
)
890 item
.SetWidth(column
->GetWidth());
896 // Sets information about this column
897 bool wxListCtrl::SetColumn(int col
, wxListItem
& item
)
900 return m_genericImpl
->SetColumn(col
, item
);
904 long mask
= item
.GetMask();
905 if ( col
>= (int)m_colsInfo
.GetCount() )
907 wxListItem
* listItem
= new wxListItem(item
);
908 m_colsInfo
.Append( listItem
);
913 GetColumn( col
, listItem
);
915 if (mask
& wxLIST_MASK_TEXT
)
916 listItem
.SetText(item
.GetText());
917 if (mask
& wxLIST_MASK_DATA
)
918 listItem
.SetData(item
.GetData());
919 if (mask
& wxLIST_MASK_IMAGE
)
920 listItem
.SetImage(item
.GetImage());
921 if (mask
& wxLIST_MASK_STATE
)
922 listItem
.SetState(item
.GetState());
923 if (mask
& wxLIST_MASK_FORMAT
)
924 listItem
.SetAlign(item
.GetAlign());
925 if (mask
& wxLIST_MASK_WIDTH
)
926 listItem
.SetWidth(item
.GetWidth());
929 // change the appearance in the databrowser.
930 DataBrowserListViewHeaderDesc columnDesc
;
931 columnDesc
.version
=kDataBrowserListViewLatestHeaderDesc
;
932 verify_noerr( m_dbImpl
->GetHeaderDesc( kMinColumnId
+ col
, &columnDesc
) );
935 if (item.GetMask() & wxLIST_MASK_TEXT)
939 enc = m_font.GetEncoding();
941 enc = wxLocale::GetSystemEncoding();
942 wxMacCFStringHolder cfTitle;
943 cfTitle.Assign( item.GetText() , enc );
944 if(columnDesc.titleString)
945 CFRelease(columnDesc.titleString);
946 columnDesc.titleString = cfTitle;
950 if (item
.GetMask() & wxLIST_MASK_IMAGE
&& item
.GetImage() != -1 )
952 columnDesc
.btnContentInfo
.contentType
= kControlContentIconRef
;
953 wxImageList
* imageList
= GetImageList(wxIMAGE_LIST_SMALL
);
954 if (imageList
&& imageList
->GetImageCount() > 0 )
956 wxBitmap bmp
= imageList
->GetBitmap( item
.GetImage() );
957 IconRef icon
= bmp
.GetBitmapData()->GetIconRef();
958 columnDesc
.btnContentInfo
.u
.iconRef
= icon
;
962 verify_noerr( m_dbImpl
->SetHeaderDesc( kMinColumnId
+ col
, &columnDesc
) );
968 int wxListCtrl::GetColumnCount() const
971 return m_genericImpl
->GetColumnCount();
976 m_dbImpl
->GetColumnCount(&count
);
983 // Gets the column width
984 int wxListCtrl::GetColumnWidth(int col
) const
987 return m_genericImpl
->GetColumnWidth(col
);
991 return m_dbImpl
->GetColumnWidth(col
);
997 // Sets the column width
998 bool wxListCtrl::SetColumnWidth(int col
, int width
)
1001 return m_genericImpl
->SetColumnWidth(col
, width
);
1005 int mywidth
= width
;
1006 if (width
== wxLIST_AUTOSIZE
|| width
== wxLIST_AUTOSIZE_USEHEADER
)
1011 for (int column
= 0; column
< GetColumnCount(); column
++)
1014 GetColumn(col
, colInfo
);
1016 colInfo
.SetWidth(width
);
1017 SetColumn(col
, colInfo
);
1019 m_dbImpl
->SetColumnWidth(col
, mywidth
);
1025 GetColumn(col
, colInfo
);
1027 colInfo
.SetWidth(width
);
1028 SetColumn(col
, colInfo
);
1029 m_dbImpl
->SetColumnWidth(col
, mywidth
);
1037 // Gets the number of items that can fit vertically in the
1038 // visible area of the list control (list or report view)
1039 // or the total number of items in the list control (icon
1040 // or small icon view)
1041 int wxListCtrl::GetCountPerPage() const
1044 return m_genericImpl
->GetCountPerPage();
1053 // Gets the edit control for editing labels.
1054 wxTextCtrl
* wxListCtrl::GetEditControl() const
1057 return m_genericImpl
->GetEditControl();
1062 // Gets information about the item
1063 bool wxListCtrl::GetItem(wxListItem
& info
) const
1066 return m_genericImpl
->GetItem(info
);
1072 if (info
.m_itemId
>= 0 && info
.m_itemId
< GetItemCount())
1073 m_dbImpl
->MacGetColumnInfo(info
.m_itemId
, info
.m_col
, info
);
1077 if (info
.m_itemId
>= 0 && info
.m_itemId
< GetItemCount())
1079 info
.SetText( OnGetItemText(info
.m_itemId
, info
.m_col
) );
1080 info
.SetImage( OnGetItemColumnImage(info
.m_itemId
, info
.m_col
) );
1081 if (info
.GetMask() & wxLIST_MASK_STATE
)
1083 if (IsDataBrowserItemSelected( m_dbImpl
->GetControlRef(), info
.m_itemId
+1 ))
1084 info
.SetState(info
.GetState() | wxLIST_STATE_SELECTED
);
1087 wxListItemAttr
* attrs
= OnGetItemAttr( info
.m_itemId
);
1090 info
.SetFont( attrs
->GetFont() );
1091 info
.SetBackgroundColour( attrs
->GetBackgroundColour() );
1092 info
.SetTextColour( attrs
->GetTextColour() );
1097 bool success
= true;
1101 // Sets information about the item
1102 bool wxListCtrl::SetItem(wxListItem
& info
)
1105 return m_genericImpl
->SetItem(info
);
1108 m_dbImpl
->MacSetColumnInfo( info
.m_itemId
, info
.m_col
, &info
);
1113 long wxListCtrl::SetItem(long index
, int col
, const wxString
& label
, int imageId
)
1116 return m_genericImpl
->SetItem(index
, col
, label
, imageId
);
1119 info
.m_text
= label
;
1120 info
.m_mask
= wxLIST_MASK_TEXT
;
1121 info
.m_itemId
= index
;
1125 info
.m_image
= imageId
;
1126 info
.m_mask
|= wxLIST_MASK_IMAGE
;
1128 return SetItem(info
);
1132 // Gets the item state
1133 int wxListCtrl::GetItemState(long item
, long stateMask
) const
1136 return m_genericImpl
->GetItemState(item
, stateMask
);
1140 if ( HasFlag(wxLC_VIRTUAL
) )
1142 if (stateMask
== wxLIST_STATE_SELECTED
)
1144 if (IsDataBrowserItemSelected( m_dbImpl
->GetControlRef(), item
+1 ))
1145 return wxLIST_STATE_SELECTED
;
1154 info
.m_mask
= wxLIST_MASK_STATE
;
1155 info
.m_stateMask
= stateMask
;
1156 info
.m_itemId
= item
;
1161 return info
.m_state
;
1168 // Sets the item state
1169 bool wxListCtrl::SetItemState(long item
, long state
, long stateMask
)
1172 return m_genericImpl
->SetItemState(item
, state
, stateMask
);
1176 DataBrowserSetOption option
= kDataBrowserItemsAdd
;
1177 if ( stateMask
== wxLIST_STATE_SELECTED
&& state
== 0 )
1178 option
= kDataBrowserItemsRemove
;
1182 if ( HasFlag(wxLC_VIRTUAL
) )
1184 wxMacDataItemBrowserSelectionSuppressor
suppressor(m_dbImpl
);
1185 m_dbImpl
->SetSelectedAllItems(option
);
1189 for(int i
= 0; i
< GetItemCount();i
++)
1193 info
.m_mask
= wxLIST_MASK_STATE
;
1194 info
.m_stateMask
= stateMask
;
1195 info
.m_state
= state
;
1202 if ( HasFlag(wxLC_VIRTUAL
) )
1204 long itemID
= item
+1;
1205 SetDataBrowserSelectedItems(m_dbImpl
->GetControlRef(), 1, (DataBrowserItemID
*)&itemID
, option
);
1210 info
.m_itemId
= item
;
1211 info
.m_mask
= wxLIST_MASK_STATE
;
1212 info
.m_stateMask
= stateMask
;
1213 info
.m_state
= state
;
1214 return SetItem(info
);
1221 // Sets the item image
1222 bool wxListCtrl::SetItemImage(long item
, int image
, int WXUNUSED(selImage
))
1224 return SetItemColumnImage(item
, 0, image
);
1227 // Sets the item image
1228 bool wxListCtrl::SetItemColumnImage(long item
, long column
, int image
)
1231 return m_genericImpl
->SetItemColumnImage(item
, column
, image
);
1235 info
.m_mask
= wxLIST_MASK_IMAGE
;
1236 info
.m_image
= image
;
1237 info
.m_itemId
= item
;
1238 info
.m_col
= column
;
1240 return SetItem(info
);
1243 // Gets the item text
1244 wxString
wxListCtrl::GetItemText(long item
) const
1247 return m_genericImpl
->GetItemText(item
);
1251 info
.m_mask
= wxLIST_MASK_TEXT
;
1252 info
.m_itemId
= item
;
1255 return wxEmptyString
;
1259 // Sets the item text
1260 void wxListCtrl::SetItemText(long item
, const wxString
& str
)
1263 return m_genericImpl
->SetItemText(item
, str
);
1267 info
.m_mask
= wxLIST_MASK_TEXT
;
1268 info
.m_itemId
= item
;
1274 // Gets the item data
1275 long wxListCtrl::GetItemData(long item
) const
1278 return m_genericImpl
->GetItemData(item
);
1282 info
.m_mask
= wxLIST_MASK_DATA
;
1283 info
.m_itemId
= item
;
1290 // Sets the item data
1291 bool wxListCtrl::SetItemData(long item
, long data
)
1294 return m_genericImpl
->SetItemData(item
, data
);
1298 info
.m_mask
= wxLIST_MASK_DATA
;
1299 info
.m_itemId
= item
;
1302 return SetItem(info
);
1305 wxRect
wxListCtrl::GetViewRect() const
1307 wxASSERT_MSG( !HasFlag(wxLC_REPORT
| wxLC_LIST
),
1308 _T("wxListCtrl::GetViewRect() only works in icon mode") );
1311 return m_genericImpl
->GetViewRect();
1317 // Gets the item rectangle
1318 bool wxListCtrl::GetItemRect(long item
, wxRect
& rect
, int code
) const
1321 return m_genericImpl
->GetItemRect(item
, rect
, code
);
1326 DataBrowserItemID id
;
1327 DataBrowserPropertyID col
= kMinColumnId
;
1329 DataBrowserPropertyPart part
= kDataBrowserPropertyEnclosingPart
;
1330 if ( code
== wxLIST_RECT_LABEL
)
1331 part
= kDataBrowserPropertyTextPart
;
1332 else if ( code
== wxLIST_RECT_ICON
)
1333 part
= kDataBrowserPropertyIconPart
;
1335 if ( !(GetWindowStyleFlag() & wxLC_VIRTUAL
) )
1337 wxMacDataItem
* thisItem
= m_dbImpl
->GetItemFromLine(item
);
1338 id
= (DataBrowserItemID
) thisItem
;
1343 GetDataBrowserItemPartBounds( m_dbImpl
->GetControlRef(), id
, col
, part
, &bounds
);
1345 rect
.x
= bounds
.left
;
1346 rect
.y
= bounds
.top
;
1347 rect
.width
= bounds
.right
- bounds
.left
; //GetClientSize().x; // we need the width of the whole row, not just the item.
1348 rect
.height
= bounds
.bottom
- bounds
.top
;
1349 //fprintf("id = %d, bounds = %d, %d, %d, %d\n", id, rect.x, rect.y, rect.width, rect.height);
1354 // Gets the item position
1355 bool wxListCtrl::GetItemPosition(long item
, wxPoint
& pos
) const
1358 return m_genericImpl
->GetItemPosition(item
, pos
);
1360 bool success
= false;
1365 GetItemRect(item
, itemRect
);
1366 pos
= itemRect
.GetPosition();
1373 // Sets the item position.
1374 bool wxListCtrl::SetItemPosition(long item
, const wxPoint
& pos
)
1377 return m_genericImpl
->SetItemPosition(item
, pos
);
1382 // Gets the number of items in the list control
1383 int wxListCtrl::GetItemCount() const
1386 return m_genericImpl
->GetItemCount();
1389 return m_dbImpl
->MacGetCount();
1394 void wxListCtrl::SetItemSpacing( int spacing
, bool isSmall
)
1397 m_genericImpl
->SetItemSpacing(spacing
, isSmall
);
1400 wxSize
wxListCtrl::GetItemSpacing() const
1403 return m_genericImpl
->GetItemSpacing();
1405 return wxSize(0, 0);
1408 void wxListCtrl::SetItemTextColour( long item
, const wxColour
&col
)
1412 m_genericImpl
->SetItemTextColour(item
, col
);
1417 info
.m_itemId
= item
;
1418 info
.SetTextColour( col
);
1422 wxColour
wxListCtrl::GetItemTextColour( long item
) const
1425 return m_genericImpl
->GetItemTextColour(item
);
1431 return info
.GetTextColour();
1433 return wxNullColour
;
1436 void wxListCtrl::SetItemBackgroundColour( long item
, const wxColour
&col
)
1440 m_genericImpl
->SetItemBackgroundColour(item
, col
);
1445 info
.m_itemId
= item
;
1446 info
.SetBackgroundColour( col
);
1450 wxColour
wxListCtrl::GetItemBackgroundColour( long item
) const
1453 return m_genericImpl
->GetItemBackgroundColour(item
);
1459 return info
.GetBackgroundColour();
1461 return wxNullColour
;
1464 void wxListCtrl::SetItemFont( long item
, const wxFont
&f
)
1468 m_genericImpl
->SetItemFont(item
, f
);
1473 info
.m_itemId
= item
;
1478 wxFont
wxListCtrl::GetItemFont( long item
) const
1481 return m_genericImpl
->GetItemFont(item
);
1487 return info
.GetFont();
1493 // Gets the number of selected items in the list control
1494 int wxListCtrl::GetSelectedItemCount() const
1497 return m_genericImpl
->GetSelectedItemCount();
1500 return m_dbImpl
->GetSelectedItemCount(NULL
, true);
1505 // Gets the text colour of the listview
1506 wxColour
wxListCtrl::GetTextColour() const
1509 return m_genericImpl
->GetTextColour();
1511 // TODO: we need owner drawn list items to customize text color.
1515 return wxNullColour
;
1518 // Sets the text colour of the listview
1519 void wxListCtrl::SetTextColour(const wxColour
& col
)
1523 m_genericImpl
->SetTextColour(col
);
1531 // Gets the index of the topmost visible item when in
1532 // list or report view
1533 long wxListCtrl::GetTopItem() const
1536 return m_genericImpl
->GetTopItem();
1541 long item
= HitTest( wxPoint(1, 1), flags
);
1542 if (flags
== wxLIST_HITTEST_ONITEM
)
1549 // Searches for an item, starting from 'item'.
1550 // 'geometry' is one of
1551 // wxLIST_NEXT_ABOVE/ALL/BELOW/LEFT/RIGHT.
1552 // 'state' is a state bit flag, one or more of
1553 // wxLIST_STATE_DROPHILITED/FOCUSED/SELECTED/CUT.
1554 // item can be -1 to find the first item that matches the
1556 // Returns the item or -1 if unsuccessful.
1557 long wxListCtrl::GetNextItem(long item
, int geom
, int state
) const
1560 return m_genericImpl
->GetNextItem(item
, geom
, state
);
1562 // TODO: implement all geometry and state options?
1565 if ( geom
== wxLIST_NEXT_ALL
|| geom
== wxLIST_NEXT_BELOW
)
1567 long count
= m_dbImpl
->MacGetCount() ;
1568 for ( long line
= item
+ 1 ; line
< count
; line
++ )
1570 wxMacDataItem
* id
= m_dbImpl
->GetItemFromLine(line
);
1572 if ( (state
== wxLIST_STATE_DONTCARE
) )
1575 if ( (state
& wxLIST_STATE_SELECTED
) && m_dbImpl
->IsItemSelected( id
) )
1579 else if ( geom
== wxLIST_NEXT_ABOVE
)
1583 item2
= m_dbImpl
->MacGetCount();
1585 for ( long line
= item2
- 1 ; line
>= 0; line
-- )
1587 wxMacDataItem
* id
= m_dbImpl
->GetItemFromLine(line
);
1589 if ( (state
== wxLIST_STATE_DONTCARE
) )
1592 if ( (state
& wxLIST_STATE_SELECTED
) && m_dbImpl
->IsItemSelected( id
) )
1602 wxImageList
*wxListCtrl::GetImageList(int which
) const
1605 return m_genericImpl
->GetImageList(which
);
1607 if ( which
== wxIMAGE_LIST_NORMAL
)
1609 return m_imageListNormal
;
1611 else if ( which
== wxIMAGE_LIST_SMALL
)
1613 return m_imageListSmall
;
1615 else if ( which
== wxIMAGE_LIST_STATE
)
1617 return m_imageListState
;
1622 void wxListCtrl::SetImageList(wxImageList
*imageList
, int which
)
1626 m_genericImpl
->SetImageList(imageList
, which
);
1630 if ( which
== wxIMAGE_LIST_NORMAL
)
1632 if (m_ownsImageListNormal
) delete m_imageListNormal
;
1633 m_imageListNormal
= imageList
;
1634 m_ownsImageListNormal
= false;
1636 else if ( which
== wxIMAGE_LIST_SMALL
)
1638 if (m_ownsImageListSmall
) delete m_imageListSmall
;
1639 m_imageListSmall
= imageList
;
1640 m_ownsImageListSmall
= false;
1642 else if ( which
== wxIMAGE_LIST_STATE
)
1644 if (m_ownsImageListState
) delete m_imageListState
;
1645 m_imageListState
= imageList
;
1646 m_ownsImageListState
= false;
1650 void wxListCtrl::AssignImageList(wxImageList
*imageList
, int which
)
1654 m_genericImpl
->AssignImageList(imageList
, which
);
1658 SetImageList(imageList
, which
);
1659 if ( which
== wxIMAGE_LIST_NORMAL
)
1660 m_ownsImageListNormal
= true;
1661 else if ( which
== wxIMAGE_LIST_SMALL
)
1662 m_ownsImageListSmall
= true;
1663 else if ( which
== wxIMAGE_LIST_STATE
)
1664 m_ownsImageListState
= true;
1667 // ----------------------------------------------------------------------------
1669 // ----------------------------------------------------------------------------
1671 // Arranges the items
1672 bool wxListCtrl::Arrange(int flag
)
1675 return m_genericImpl
->Arrange(flag
);
1680 bool wxListCtrl::DeleteItem(long item
)
1683 return m_genericImpl
->DeleteItem(item
);
1687 m_dbImpl
->MacDelete(item
);
1688 wxListEvent
event( wxEVT_COMMAND_LIST_DELETE_ITEM
, GetId() );
1689 event
.SetEventObject( this );
1690 event
.m_itemIndex
= item
;
1691 GetEventHandler()->ProcessEvent( event
);
1697 // Deletes all items
1698 bool wxListCtrl::DeleteAllItems()
1701 return m_genericImpl
->DeleteAllItems();
1705 m_dbImpl
->MacClear();
1706 wxListEvent
event( wxEVT_COMMAND_LIST_DELETE_ALL_ITEMS
, GetId() );
1707 event
.SetEventObject( this );
1708 GetEventHandler()->ProcessEvent( event
);
1713 // Deletes all items
1714 bool wxListCtrl::DeleteAllColumns()
1717 return m_genericImpl
->DeleteAllColumns();
1722 m_dbImpl
->GetColumnCount(&cols
);
1723 for (UInt32 col
= 0; col
< cols
; col
++)
1733 bool wxListCtrl::DeleteColumn(int col
)
1736 return m_genericImpl
->DeleteColumn(col
);
1740 OSStatus err
= m_dbImpl
->RemoveColumn(col
);
1741 return err
== noErr
;
1747 // Clears items, and columns if there are any.
1748 void wxListCtrl::ClearAll()
1752 m_genericImpl
->ClearAll();
1763 wxTextCtrl
* wxListCtrl::EditLabel(long item
, wxClassInfo
* textControlClass
)
1766 return m_genericImpl
->EditLabel(item
, textControlClass
);
1770 wxCHECK_MSG( (item
>= 0) && ((long)item
< GetItemCount()), NULL
,
1771 wxT("wrong index in wxListCtrl::EditLabel()") );
1773 wxASSERT_MSG( textControlClass
->IsKindOf(CLASSINFO(wxTextCtrl
)),
1774 wxT("EditLabel() needs a text control") );
1776 wxListEvent
le( wxEVT_COMMAND_LIST_BEGIN_LABEL_EDIT
, GetParent()->GetId() );
1777 le
.SetEventObject( this );
1778 le
.m_itemIndex
= item
;
1780 GetItem( le
.m_item
);
1782 if ( GetParent()->GetEventHandler()->ProcessEvent( le
) && !le
.IsAllowed() )
1784 // vetoed by user code
1788 wxTextCtrl
* const text
= (wxTextCtrl
*)textControlClass
->CreateObject();
1789 m_textctrlWrapper
= new wxListCtrlTextCtrlWrapper(this, text
, item
);
1790 return m_textctrlWrapper
->GetText();
1795 // End label editing, optionally cancelling the edit
1796 bool wxListCtrl::EndEditLabel(bool cancel
)
1798 // TODO: generic impl. doesn't have this method - is it needed for us?
1800 return true; // m_genericImpl->EndEditLabel(cancel);
1803 verify_noerr( SetDataBrowserEditItem(m_dbImpl
->GetControlRef(), kDataBrowserNoItem
, kMinColumnId
) );
1807 // Ensures this item is visible
1808 bool wxListCtrl::EnsureVisible(long item
)
1811 return m_genericImpl
->EnsureVisible(item
);
1815 wxMacDataItem
* dataItem
= m_dbImpl
->GetItemFromLine(item
);
1816 m_dbImpl
->RevealItem(dataItem
, kDataBrowserRevealWithoutSelecting
);
1822 // Find an item whose label matches this string, starting from the item after 'start'
1823 // or the beginning if 'start' is -1.
1824 long wxListCtrl::FindItem(long start
, const wxString
& str
, bool partial
)
1827 return m_genericImpl
->FindItem(start
, str
, partial
);
1829 wxString str_upper
= str
.Upper();
1834 long count
= GetItemCount();
1838 wxString line_upper
= GetItemText(idx
).Upper();
1841 if (line_upper
== str_upper
)
1846 if (line_upper
.find(str_upper
) == 0)
1856 // Find an item whose data matches this data, starting from the item after 'start'
1857 // or the beginning if 'start' is -1.
1858 long wxListCtrl::FindItem(long start
, long data
)
1861 return m_genericImpl
->FindItem(start
, data
);
1866 long count
= GetItemCount();
1870 if (GetItemData(idx
) == data
)
1878 // Find an item nearest this position in the specified direction, starting from
1879 // the item after 'start' or the beginning if 'start' is -1.
1880 long wxListCtrl::FindItem(long start
, const wxPoint
& pt
, int direction
)
1883 return m_genericImpl
->FindItem(start
, pt
, direction
);
1887 // Determines which item (if any) is at the specified point,
1888 // giving details in 'flags' (see wxLIST_HITTEST_... flags above)
1890 wxListCtrl::HitTest(const wxPoint
& point
, int& flags
, long *ptrSubItem
) const
1893 return m_genericImpl
->HitTest(point
, flags
, ptrSubItem
);
1895 flags
= wxLIST_HITTEST_NOWHERE
;
1898 int colHeaderHeight
= 22; // TODO: Find a way to get this value from the db control?
1899 UInt16 rowHeight
= 0;
1900 m_dbImpl
->GetDefaultRowHeight(&rowHeight
);
1903 // get the actual row by taking scroll position into account
1904 UInt32 offsetX
, offsetY
;
1905 m_dbImpl
->GetScrollPosition( &offsetY
, &offsetX
);
1908 if ( !(GetWindowStyleFlag() & wxLC_NO_HEADER
) )
1909 y
-= colHeaderHeight
;
1914 int row
= y
/ rowHeight
;
1915 DataBrowserItemID id
;
1916 m_dbImpl
->GetItemID( (DataBrowserTableViewRowIndex
) row
, &id
);
1918 // TODO: Use GetDataBrowserItemPartBounds to return if we are in icon or label
1919 if ( !(GetWindowStyleFlag() & wxLC_VIRTUAL
) )
1921 wxMacListCtrlItem
* lcItem
;
1922 lcItem
= (wxMacListCtrlItem
*) id
;
1925 flags
= wxLIST_HITTEST_ONITEM
;
1931 if (row
< GetItemCount() )
1933 flags
= wxLIST_HITTEST_ONITEM
;
1942 int wxListCtrl::GetScrollPos(int orient
) const
1945 return m_genericImpl
->GetScrollPos(orient
);
1949 UInt32 offsetX
, offsetY
;
1950 m_dbImpl
->GetScrollPosition( &offsetY
, &offsetX
);
1951 if ( orient
== wxHORIZONTAL
)
1960 // Inserts an item, returning the index of the new item if successful,
1962 long wxListCtrl::InsertItem(wxListItem
& info
)
1964 wxASSERT_MSG( !IsVirtual(), _T("can't be used with virtual controls") );
1967 return m_genericImpl
->InsertItem(info
);
1969 if (m_dbImpl
&& !IsVirtual())
1971 int count
= GetItemCount();
1973 if (info
.m_itemId
> count
)
1974 info
.m_itemId
= count
;
1976 m_dbImpl
->MacInsertItem(info
.m_itemId
, &info
);
1978 wxListEvent
event( wxEVT_COMMAND_LIST_INSERT_ITEM
, GetId() );
1979 event
.SetEventObject( this );
1980 event
.m_itemIndex
= info
.m_itemId
;
1981 GetEventHandler()->ProcessEvent( event
);
1982 return info
.m_itemId
;
1987 long wxListCtrl::InsertItem(long index
, const wxString
& label
)
1990 return m_genericImpl
->InsertItem(index
, label
);
1993 info
.m_text
= label
;
1994 info
.m_mask
= wxLIST_MASK_TEXT
;
1995 info
.m_itemId
= index
;
1996 return InsertItem(info
);
1999 // Inserts an image item
2000 long wxListCtrl::InsertItem(long index
, int imageIndex
)
2003 return m_genericImpl
->InsertItem(index
, imageIndex
);
2006 info
.m_image
= imageIndex
;
2007 info
.m_mask
= wxLIST_MASK_IMAGE
;
2008 info
.m_itemId
= index
;
2009 return InsertItem(info
);
2012 // Inserts an image/string item
2013 long wxListCtrl::InsertItem(long index
, const wxString
& label
, int imageIndex
)
2016 return m_genericImpl
->InsertItem(index
, label
, imageIndex
);
2019 info
.m_image
= imageIndex
;
2020 info
.m_text
= label
;
2021 info
.m_mask
= wxLIST_MASK_IMAGE
| wxLIST_MASK_TEXT
;
2022 info
.m_itemId
= index
;
2023 return InsertItem(info
);
2026 // For list view mode (only), inserts a column.
2027 long wxListCtrl::InsertColumn(long col
, wxListItem
& item
)
2030 return m_genericImpl
->InsertColumn(col
, item
);
2034 int width
= item
.GetWidth();
2035 if ( !(item
.GetMask() & wxLIST_MASK_WIDTH
) )
2038 DataBrowserPropertyType type
= kDataBrowserCustomType
; //kDataBrowserTextType;
2039 wxImageList
* imageList
= GetImageList(wxIMAGE_LIST_SMALL
);
2040 if (imageList
&& imageList
->GetImageCount() > 0)
2042 wxBitmap bmp
= imageList
->GetBitmap(0);
2044 // type = kDataBrowserIconAndTextType;
2047 SInt16 just
= teFlushDefault
;
2048 if (item
.GetMask() & wxLIST_MASK_FORMAT
)
2050 if (item
.GetAlign() == wxLIST_FORMAT_LEFT
)
2052 else if (item
.GetAlign() == wxLIST_FORMAT_CENTER
)
2054 else if (item
.GetAlign() == wxLIST_FORMAT_RIGHT
)
2055 just
= teFlushRight
;
2057 m_dbImpl
->InsertColumn(col
, type
, item
.GetText(), just
, width
);
2058 SetColumn(col
, item
);
2060 // set/remove options based on the wxListCtrl type.
2061 DataBrowserTableViewColumnID id
;
2062 m_dbImpl
->GetColumnIDFromIndex(col
, &id
);
2063 DataBrowserPropertyFlags flags
;
2064 verify_noerr(m_dbImpl
->GetPropertyFlags(id
, &flags
));
2065 if (GetWindowStyleFlag() & wxLC_EDIT_LABELS
)
2066 flags
|= kDataBrowserPropertyIsEditable
;
2068 if (GetWindowStyleFlag() & wxLC_VIRTUAL
){
2069 flags
&= ~kDataBrowserListViewSortableColumn
;
2071 verify_noerr(m_dbImpl
->SetPropertyFlags(id
, flags
));
2077 long wxListCtrl::InsertColumn(long col
,
2078 const wxString
& heading
,
2083 return m_genericImpl
->InsertColumn(col
, heading
, format
, width
);
2086 item
.m_mask
= wxLIST_MASK_TEXT
| wxLIST_MASK_FORMAT
;
2087 item
.m_text
= heading
;
2090 item
.m_mask
|= wxLIST_MASK_WIDTH
;
2091 item
.m_width
= width
;
2093 item
.m_format
= format
;
2095 return InsertColumn(col
, item
);
2098 // scroll the control by the given number of pixels (exception: in list view,
2099 // dx is interpreted as number of columns)
2100 bool wxListCtrl::ScrollList(int dx
, int dy
)
2103 return m_genericImpl
->ScrollList(dx
, dy
);
2107 m_dbImpl
->SetScrollPosition(dx
, dy
);
2113 bool wxListCtrl::SortItems(wxListCtrlCompare fn
, long data
)
2116 return m_genericImpl
->SortItems(fn
, data
);
2121 m_compareFuncData
= data
;
2122 SortDataBrowserContainer( m_dbImpl
->GetControlRef(), kDataBrowserNoItem
, true);
2124 // we need to do this after each call, else we get a crash from wxPython when
2125 // SortItems is called the second time.
2126 m_compareFunc
= NULL
;
2127 m_compareFuncData
= 0;
2133 void wxListCtrl::OnRenameTimer()
2135 wxCHECK_RET( HasCurrent(), wxT("unexpected rename timer") );
2137 EditLabel( m_current
);
2140 bool wxListCtrl::OnRenameAccept(long itemEdit
, const wxString
& value
)
2142 wxListEvent
le( wxEVT_COMMAND_LIST_END_LABEL_EDIT
, GetId() );
2143 le
.SetEventObject( this );
2144 le
.m_itemIndex
= itemEdit
;
2146 GetItem( le
.m_item
);
2147 le
.m_item
.m_text
= value
;
2148 return !GetEventHandler()->ProcessEvent( le
) ||
2152 void wxListCtrl::OnRenameCancelled(long itemEdit
)
2154 // let owner know that the edit was cancelled
2155 wxListEvent
le( wxEVT_COMMAND_LIST_END_LABEL_EDIT
, GetParent()->GetId() );
2157 le
.SetEditCanceled(true);
2159 le
.SetEventObject( this );
2160 le
.m_itemIndex
= itemEdit
;
2162 GetItem( le
.m_item
);
2163 GetEventHandler()->ProcessEvent( le
);
2166 // ----------------------------------------------------------------------------
2167 // virtual list controls
2168 // ----------------------------------------------------------------------------
2170 wxString
wxListCtrl::OnGetItemText(long WXUNUSED(item
), long WXUNUSED(col
)) const
2172 // this is a pure virtual function, in fact - which is not really pure
2173 // because the controls which are not virtual don't need to implement it
2174 wxFAIL_MSG( _T("wxListCtrl::OnGetItemText not supposed to be called") );
2176 return wxEmptyString
;
2179 int wxListCtrl::OnGetItemImage(long WXUNUSED(item
)) const
2181 wxCHECK_MSG(!GetImageList(wxIMAGE_LIST_SMALL
),
2183 wxT("List control has an image list, OnGetItemImage or OnGetItemColumnImage should be overridden."));
2187 int wxListCtrl::OnGetItemColumnImage(long item
, long column
) const
2190 return OnGetItemImage(item
);
2195 wxListItemAttr
*wxListCtrl::OnGetItemAttr(long WXUNUSED_UNLESS_DEBUG(item
)) const
2197 wxASSERT_MSG( item
>= 0 && item
< GetItemCount(),
2198 _T("invalid item index in OnGetItemAttr()") );
2200 // no attributes by default
2204 void wxListCtrl::SetItemCount(long count
)
2206 wxASSERT_MSG( IsVirtual(), _T("this is for virtual controls only") );
2210 m_genericImpl
->SetItemCount(count
);
2216 // we need to temporarily disable the new item creation notification
2217 // procedure to speed things up
2218 // FIXME: Even this doesn't seem to help much...
2220 // FIXME: Find a more efficient way to do this.
2221 m_dbImpl
->MacClear();
2223 DataBrowserCallbacks callbacks
;
2224 DataBrowserItemNotificationUPP itemUPP
;
2225 GetDataBrowserCallbacks(m_dbImpl
->GetControlRef(), &callbacks
);
2226 itemUPP
= callbacks
.u
.v1
.itemNotificationCallback
;
2227 callbacks
.u
.v1
.itemNotificationCallback
= 0;
2228 m_dbImpl
->SetCallbacks(&callbacks
);
2229 ::AddDataBrowserItems(m_dbImpl
->GetControlRef(), kDataBrowserNoItem
,
2230 count
, NULL
, kDataBrowserItemNoProperty
);
2231 callbacks
.u
.v1
.itemNotificationCallback
= itemUPP
;
2232 m_dbImpl
->SetCallbacks(&callbacks
);
2237 void wxListCtrl::RefreshItem(long item
)
2241 m_genericImpl
->RefreshItem(item
);
2246 GetItemRect(item
, rect
);
2250 void wxListCtrl::RefreshItems(long itemFrom
, long itemTo
)
2254 m_genericImpl
->RefreshItems(itemFrom
, itemTo
);
2258 wxRect rect1
, rect2
;
2259 GetItemRect(itemFrom
, rect1
);
2260 GetItemRect(itemTo
, rect2
);
2262 wxRect rect
= rect1
;
2263 rect
.height
= rect2
.GetBottom() - rect1
.GetTop();
2268 void wxListCtrl::SetDropTarget( wxDropTarget
*dropTarget
)
2270 #if wxUSE_DRAG_AND_DROP
2272 m_genericImpl
->SetDropTarget( dropTarget
);
2275 wxWindow::SetDropTarget( dropTarget
);
2279 wxDropTarget
*wxListCtrl::GetDropTarget() const
2281 #if wxUSE_DRAG_AND_DROP
2283 return m_genericImpl
->GetDropTarget();
2286 return wxWindow::GetDropTarget();
2291 #if wxABI_VERSION >= 20801
2292 void wxListCtrl::SetFocus()
2296 m_genericImpl
->SetFocus();
2300 wxWindow::SetFocus();
2304 // wxMac internal data structures
2306 wxMacListCtrlItem::~wxMacListCtrlItem()
2310 void wxMacListCtrlItem::Notification(wxMacDataItemBrowserControl
*owner
,
2311 DataBrowserItemNotification message
,
2312 DataBrowserItemDataRef itemData
) const
2315 wxMacDataBrowserListCtrlControl
*lb
= wxDynamicCast(owner
, wxMacDataBrowserListCtrlControl
);
2317 // we want to depend on as little as possible to make sure tear-down of controls is safe
2318 if ( message
== kDataBrowserItemRemoved
)
2320 if ( lb
!= NULL
&& lb
->GetClientDataType() == wxClientData_Object
)
2322 delete (wxClientData
*) (m_data
);
2328 else if ( message
== kDataBrowserItemAdded
)
2330 // we don't issue events on adding, the item is not really stored in the list yet, so we
2331 // avoid asserts by gettting out now
2335 wxListCtrl
*list
= wxDynamicCast( owner
->GetPeer() , wxListCtrl
);
2338 bool trigger
= false;
2340 wxListEvent
event( wxEVT_COMMAND_LIST_ITEM_SELECTED
, list
->GetId() );
2341 bool isSingle
= (list
->GetWindowStyle() & wxLC_SINGLE_SEL
) != 0;
2343 event
.SetEventObject( list
);
2344 event
.m_itemIndex
= owner
->GetLineFromItem( this ) ;
2345 event
.m_item
.m_itemId
= event
.m_itemIndex
;
2346 list
->GetItem(event
.m_item
);
2350 case kDataBrowserItemDeselected
:
2351 event
.SetEventType(wxEVT_COMMAND_LIST_ITEM_DESELECTED
);
2353 trigger
= !lb
->IsSelectionSuppressed();
2356 case kDataBrowserItemSelected
:
2357 trigger
= !lb
->IsSelectionSuppressed();
2360 case kDataBrowserItemDoubleClicked
:
2361 event
.SetEventType( wxEVT_COMMAND_LIST_ITEM_ACTIVATED
);
2365 case kDataBrowserEditStarted
:
2366 // TODO : how to veto ?
2367 event
.SetEventType( wxEVT_COMMAND_LIST_BEGIN_LABEL_EDIT
) ;
2371 case kDataBrowserEditStopped
:
2372 // TODO probably trigger only upon the value store callback, because
2373 // here IIRC we cannot veto
2374 event
.SetEventType( wxEVT_COMMAND_LIST_END_LABEL_EDIT
) ;
2384 // direct notification is not always having the listbox GetSelection() having in synch with event
2385 wxPostEvent( list
->GetEventHandler(), event
);
2391 IMPLEMENT_DYNAMIC_CLASS(wxMacDataBrowserListCtrlControl
, wxMacDataItemBrowserControl
)
2393 wxMacDataBrowserListCtrlControl::wxMacDataBrowserListCtrlControl( wxWindow
*peer
, const wxPoint
& pos
, const wxSize
& size
, long style
)
2394 : wxMacDataItemBrowserControl( peer
, pos
, size
, style
)
2396 OSStatus err
= noErr
;
2397 m_clientDataItemsType
= wxClientData_None
;
2398 m_isVirtual
= false;
2401 if ( style
& wxLC_VIRTUAL
)
2404 DataBrowserSelectionFlags options
= kDataBrowserDragSelect
;
2405 if ( style
& wxLC_SINGLE_SEL
)
2407 options
|= kDataBrowserSelectOnlyOne
;
2411 options
|= kDataBrowserCmdTogglesSelection
;
2414 err
= SetSelectionFlags( options
);
2415 verify_noerr( err
);
2417 DataBrowserCustomCallbacks callbacks
;
2418 InitializeDataBrowserCustomCallbacks( &callbacks
, kDataBrowserLatestCustomCallbacks
);
2420 if ( gDataBrowserDrawItemUPP
== NULL
)
2421 gDataBrowserDrawItemUPP
= NewDataBrowserDrawItemUPP(DataBrowserDrawItemProc
);
2423 if ( gDataBrowserHitTestUPP
== NULL
)
2424 gDataBrowserHitTestUPP
= NewDataBrowserHitTestUPP(DataBrowserHitTestProc
);
2426 callbacks
.u
.v1
.drawItemCallback
= gDataBrowserDrawItemUPP
;
2427 callbacks
.u
.v1
.hitTestCallback
= gDataBrowserHitTestUPP
;
2429 SetDataBrowserCustomCallbacks( GetControlRef(), &callbacks
);
2431 if ( style
& wxLC_LIST
)
2433 InsertColumn(0, kDataBrowserIconAndTextType
, wxEmptyString
, -1, -1);
2434 verify_noerr( AutoSizeColumns() );
2437 if ( style
& wxLC_LIST
|| style
& wxLC_NO_HEADER
)
2438 verify_noerr( SetHeaderButtonHeight( 0 ) );
2441 SetSortProperty( kMinColumnId
- 1 );
2443 SetSortProperty( kMinColumnId
);
2445 m_sortOrder
= SortOrder_None
;
2447 if ( style
& wxLC_SORT_DESCENDING
)
2449 SetSortOrder( kDataBrowserOrderDecreasing
);
2451 else if ( style
& wxLC_SORT_ASCENDING
)
2453 SetSortOrder( kDataBrowserOrderIncreasing
);
2456 if ( style
& wxLC_VRULES
)
2458 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4
2459 verify_noerr( DataBrowserChangeAttributes(m_controlRef
, kDataBrowserAttributeListViewDrawColumnDividers
, kDataBrowserAttributeNone
) );
2463 verify_noerr( SetHiliteStyle(kDataBrowserTableViewFillHilite
) );
2464 verify_noerr( SetHasScrollBars( (style
& wxHSCROLL
) != 0 , true ) );
2467 pascal Boolean
wxMacDataBrowserListCtrlControl::DataBrowserEditTextProc(
2469 DataBrowserItemID itemID
,
2470 DataBrowserPropertyID property
,
2471 CFStringRef theString
,
2472 Rect
*maxEditTextRect
,
2473 Boolean
*shrinkToFit
)
2475 Boolean result
= false;
2476 wxMacDataBrowserListCtrlControl
* ctl
= wxDynamicCast(wxMacControl::GetReferenceFromNativeControl( browser
), wxMacDataBrowserListCtrlControl
);
2479 result
= ctl
->ConfirmEditText(itemID
, property
, theString
, maxEditTextRect
, shrinkToFit
);
2480 theString
= CFSTR("Hello!");
2485 bool wxMacDataBrowserListCtrlControl::ConfirmEditText(
2486 DataBrowserItemID itemID
,
2487 DataBrowserPropertyID property
,
2488 CFStringRef theString
,
2489 Rect
*maxEditTextRect
,
2490 Boolean
*shrinkToFit
)
2495 pascal void wxMacDataBrowserListCtrlControl::DataBrowserDrawItemProc(
2497 DataBrowserItemID itemID
,
2498 DataBrowserPropertyID property
,
2499 DataBrowserItemState itemState
,
2500 const Rect
*itemRect
,
2502 Boolean colorDevice
)
2504 wxMacDataBrowserListCtrlControl
* ctl
= wxDynamicCast(wxMacControl::GetReferenceFromNativeControl( browser
), wxMacDataBrowserListCtrlControl
);
2507 ctl
->DrawItem(itemID
, property
, itemState
, itemRect
, gdDepth
, colorDevice
);
2511 // routines needed for DrawItem
2516 kTextBoxHeight
= 14,
2517 kIconTextSpacingV
= 2,
2519 kContentHeight
= kIconHeight
+ kTextBoxHeight
+ kIconTextSpacingV
2522 static void calculateCGDrawingBounds(CGRect inItemRect
, CGRect
*outIconRect
, CGRect
*outTextRect
, bool hasIcon
= false)
2525 float iconH
, iconW
= 0;
2526 float padding
= kItemPadding
;
2529 iconH
= kIconHeight
;
2531 padding
= padding
*2;
2534 textBottom
= inItemRect
.origin
.y
;
2536 *outIconRect
= CGRectMake(inItemRect
.origin
.x
+ kItemPadding
,
2537 textBottom
+ kIconTextSpacingV
, kIconWidth
,
2540 *outTextRect
= CGRectMake(inItemRect
.origin
.x
+ padding
+ iconW
,
2541 textBottom
+ kIconTextSpacingV
, inItemRect
.size
.width
- padding
- iconW
,
2542 inItemRect
.size
.height
- kIconTextSpacingV
);
2545 void wxMacDataBrowserListCtrlControl::DrawItem(
2546 DataBrowserItemID itemID
,
2547 DataBrowserPropertyID property
,
2548 DataBrowserItemState itemState
,
2549 const Rect
*itemRect
,
2551 Boolean colorDevice
)
2554 wxFont font
= wxNullFont
;
2556 short listColumn
= property
- kMinColumnId
;
2558 wxListCtrl
* list
= wxDynamicCast( GetPeer() , wxListCtrl
);
2559 wxMacListCtrlItem
* lcItem
;
2560 wxColour color
= *wxBLACK
;
2561 wxColour bgColor
= wxNullColour
;
2563 if (listColumn
>= 0)
2567 lcItem
= (wxMacListCtrlItem
*) itemID
;
2568 if (lcItem
->HasColumnInfo(listColumn
)){
2569 wxListItem
* item
= lcItem
->GetColumnInfo(listColumn
);
2571 // we always use the 0 column to get font and text/background colors.
2572 if (lcItem
->HasColumnInfo(0))
2574 wxListItem
* firstItem
= lcItem
->GetColumnInfo(0);
2575 color
= firstItem
->GetTextColour();
2576 bgColor
= firstItem
->GetBackgroundColour();
2577 font
= firstItem
->GetFont();
2580 if (item
->GetMask() & wxLIST_MASK_TEXT
)
2581 text
= item
->GetText();
2582 if (item
->GetMask() & wxLIST_MASK_IMAGE
)
2583 imgIndex
= item
->GetImage();
2589 long itemNum
= (long)itemID
-1;
2590 if (itemNum
>= 0 && itemNum
< list
->GetItemCount())
2592 text
= list
->OnGetItemText( itemNum
, listColumn
);
2593 imgIndex
= list
->OnGetItemColumnImage( itemNum
, listColumn
);
2594 wxListItemAttr
* attrs
= list
->OnGetItemAttr( itemNum
);
2597 if (attrs
->HasBackgroundColour())
2598 bgColor
= attrs
->GetBackgroundColour();
2599 if (attrs
->HasTextColour())
2600 color
= attrs
->GetTextColour();
2601 if (attrs
->HasFont())
2602 font
= attrs
->GetFont();
2608 wxColour listBgColor
= list
->GetBackgroundColour();
2609 if (bgColor
== wxNullColour
)
2610 bgColor
= listBgColor
;
2612 wxFont listFont
= list
->GetFont();
2613 if (font
== wxNullFont
)
2616 wxMacCFStringHolder cfString
;
2617 cfString
.Assign( text
, wxLocale::GetSystemEncoding() );
2620 CGRect enclosingCGRect
, iconCGRect
, textCGRect
;
2622 ThemeDrawingState savedState
= NULL
;
2623 CGContextRef context
= (CGContextRef
)list
->MacGetDrawingContext();
2624 RGBColor labelColor
;
2626 labelColor
.green
= 0;
2627 labelColor
.blue
= 0;
2629 RGBColor backgroundColor
;
2630 backgroundColor
.red
= 255;
2631 backgroundColor
.green
= 255;
2632 backgroundColor
.blue
= 255;
2634 GetDataBrowserItemPartBounds(GetControlRef(), itemID
, property
, kDataBrowserPropertyEnclosingPart
,
2637 enclosingCGRect
= CGRectMake(enclosingRect
.left
,
2639 enclosingRect
.right
- enclosingRect
.left
,
2640 enclosingRect
.bottom
- enclosingRect
.top
);
2642 bool hasFocus
= (wxWindow::FindFocus() == list
);
2643 active
= IsControlActive(GetControlRef());
2645 // don't paint the background over the vertical rule line
2646 if ( list
->GetWindowStyleFlag() & wxLC_VRULES
)
2648 enclosingCGRect
.origin
.x
+= 1;
2649 enclosingCGRect
.size
.width
-= 1;
2651 if (itemState
== kDataBrowserItemIsSelected
)
2654 GetThemeDrawingState(&savedState
);
2656 if (active
&& hasFocus
)
2658 GetThemeBrushAsColor(kThemeBrushAlternatePrimaryHighlightColor
, 32, true, &backgroundColor
);
2659 GetThemeTextColor(kThemeTextColorWhite
, gdDepth
, colorDevice
, &labelColor
);
2663 GetThemeBrushAsColor(kThemeBrushSecondaryHighlightColor
, 32, true, &backgroundColor
);
2664 GetThemeTextColor(kThemeTextColorBlack
, gdDepth
, colorDevice
, &labelColor
);
2666 CGContextSaveGState(context
);
2668 CGContextSetRGBFillColor(context
, (float)backgroundColor
.red
/ (float)USHRT_MAX
,
2669 (float)backgroundColor
.green
/ (float)USHRT_MAX
,
2670 (float)backgroundColor
.blue
/ (float)USHRT_MAX
, 1.0);
2671 CGContextFillRect(context
, enclosingCGRect
);
2673 CGContextRestoreGState(context
);
2679 labelColor
= MAC_WXCOLORREF( color
.GetPixel() );
2680 else if (list
->GetTextColour().Ok())
2681 labelColor
= MAC_WXCOLORREF( list
->GetTextColour().GetPixel() );
2685 backgroundColor
= MAC_WXCOLORREF( bgColor
.GetPixel() );
2686 CGContextSaveGState(context
);
2688 CGContextSetRGBFillColor(context
, (float)backgroundColor
.red
/ (float)USHRT_MAX
,
2689 (float)backgroundColor
.green
/ (float)USHRT_MAX
,
2690 (float)backgroundColor
.blue
/ (float)USHRT_MAX
, 1.0);
2691 CGContextFillRect(context
, enclosingCGRect
);
2693 CGContextRestoreGState(context
);
2697 calculateCGDrawingBounds(enclosingCGRect
, &iconCGRect
, &textCGRect
, (imgIndex
!= -1) );
2701 wxImageList
* imageList
= list
->GetImageList(wxIMAGE_LIST_SMALL
);
2702 if (imageList
&& imageList
->GetImageCount() > 0){
2703 wxBitmap bmp
= imageList
->GetBitmap(imgIndex
);
2704 IconRef icon
= bmp
.GetBitmapData()->GetIconRef();
2706 CGContextSaveGState(context
);
2707 CGContextTranslateCTM(context
, 0,iconCGRect
.origin
.y
+ CGRectGetMaxY(iconCGRect
));
2708 CGContextScaleCTM(context
,1.0f
,-1.0f
);
2709 PlotIconRefInContext(context
, &iconCGRect
, kAlignNone
,
2710 active
? kTransformNone
: kTransformDisabled
, NULL
,
2711 kPlotIconRefNormalFlags
, icon
);
2713 CGContextRestoreGState(context
);
2717 HIThemeTextHorizontalFlush hFlush
= kHIThemeTextHorizontalFlushLeft
;
2718 UInt16 fontID
= kThemeViewsFont
;
2722 if (font
.GetFamily() != wxFONTFAMILY_DEFAULT
)
2723 fontID
= font
.MacGetThemeFontID();
2725 // FIXME: replace these with CG or ATSUI calls so we can remove this #ifndef.
2727 ::TextSize( (short)(font
.MacGetFontSize()) ) ;
2728 ::TextFace( font
.MacGetFontStyle() ) ;
2733 list
->GetColumn(listColumn
, item
);
2734 if (item
.GetMask() & wxLIST_MASK_FORMAT
)
2736 if (item
.GetAlign() == wxLIST_FORMAT_LEFT
)
2737 hFlush
= kHIThemeTextHorizontalFlushLeft
;
2738 else if (item
.GetAlign() == wxLIST_FORMAT_CENTER
)
2739 hFlush
= kHIThemeTextHorizontalFlushCenter
;
2740 else if (item
.GetAlign() == wxLIST_FORMAT_RIGHT
)
2742 hFlush
= kHIThemeTextHorizontalFlushRight
;
2743 textCGRect
.origin
.x
-= kItemPadding
; // give a little extra paddding
2747 HIThemeTextInfo info
;
2748 info
.version
= kHIThemeTextInfoVersionZero
;
2749 info
.state
= active
? kThemeStateActive
: kThemeStateInactive
;
2750 info
.fontID
= fontID
;
2751 info
.horizontalFlushness
= hFlush
;
2752 info
.verticalFlushness
= kHIThemeTextVerticalFlushCenter
;
2753 info
.options
= kHIThemeTextBoxOptionNone
;
2754 info
.truncationPosition
= kHIThemeTextTruncationEnd
;
2755 info
.truncationMaxLines
= 1;
2757 CGContextSaveGState(context
);
2758 CGContextSetRGBFillColor (context
, (float)labelColor
.red
/ (float)USHRT_MAX
,
2759 (float)labelColor
.green
/ (float)USHRT_MAX
,
2760 (float)labelColor
.blue
/ (float)USHRT_MAX
, 1.0);
2762 HIThemeDrawTextBox(cfString
, &textCGRect
, &info
, context
, kHIThemeOrientationNormal
);
2764 CGContextRestoreGState(context
);
2766 if (savedState
!= NULL
)
2767 SetThemeDrawingState(savedState
, true);
2770 OSStatus
wxMacDataBrowserListCtrlControl::GetSetItemData(DataBrowserItemID itemID
,
2771 DataBrowserPropertyID property
,
2772 DataBrowserItemDataRef itemData
,
2773 Boolean changeValue
)
2777 short listColumn
= property
- kMinColumnId
;
2779 OSStatus err
= errDataBrowserPropertyNotSupported
;
2780 wxListCtrl
* list
= wxDynamicCast( GetPeer() , wxListCtrl
);
2781 wxMacListCtrlItem
* lcItem
;
2783 if (listColumn
>= 0)
2787 lcItem
= (wxMacListCtrlItem
*) itemID
;
2788 if (lcItem
&& lcItem
->HasColumnInfo(listColumn
)){
2789 wxListItem
* item
= lcItem
->GetColumnInfo(listColumn
);
2790 if (item
->GetMask() & wxLIST_MASK_TEXT
)
2791 text
= item
->GetText();
2792 if (item
->GetMask() & wxLIST_MASK_IMAGE
)
2793 imgIndex
= item
->GetImage();
2798 long itemNum
= (long)itemID
-1;
2799 if (itemNum
>= 0 && itemNum
< list
->GetItemCount())
2801 text
= list
->OnGetItemText( itemNum
, listColumn
);
2802 imgIndex
= list
->OnGetItemColumnImage( itemNum
, listColumn
);
2811 case kDataBrowserItemIsEditableProperty
:
2812 if ( list
&& list
->HasFlag( wxLC_EDIT_LABELS
) )
2814 verify_noerr(SetDataBrowserItemDataBooleanValue( itemData
, true ));
2819 if ( property
>= kMinColumnId
)
2821 wxMacCFStringHolder cfStr
;
2824 cfStr
.Assign( text
, wxLocale::GetSystemEncoding() );
2825 err
= ::SetDataBrowserItemDataText( itemData
, cfStr
);
2831 if ( imgIndex
!= -1 )
2833 wxImageList
* imageList
= list
->GetImageList(wxIMAGE_LIST_SMALL
);
2834 if (imageList
&& imageList
->GetImageCount() > 0){
2835 wxBitmap bmp
= imageList
->GetBitmap(imgIndex
);
2836 IconRef icon
= bmp
.GetBitmapData()->GetIconRef();
2837 ::SetDataBrowserItemDataIcon(itemData
, icon
);
2851 if ( property
>= kMinColumnId
)
2853 short listColumn
= property
- kMinColumnId
;
2855 // TODO probably send the 'end edit' from here, as we
2856 // can then deal with the veto
2858 verify_noerr( GetDataBrowserItemDataText( itemData
, &sr
) ) ;
2859 wxMacCFStringHolder
cfStr(sr
) ;;
2861 list
->SetItem( (long)itemData
-1 , listColumn
, cfStr
.AsString() ) ;
2865 lcItem
->SetColumnTextValue( listColumn
, cfStr
.AsString() );
2875 void wxMacDataBrowserListCtrlControl::ItemNotification(DataBrowserItemID itemID
,
2876 DataBrowserItemNotification message
,
2877 DataBrowserItemDataRef itemData
)
2879 // we want to depend on as little as possible to make sure tear-down of controls is safe
2880 if ( message
== kDataBrowserItemRemoved
)
2882 // make sure MacDelete does the proper teardown.
2885 else if ( message
== kDataBrowserItemAdded
)
2887 // we don't issue events on adding, the item is not really stored in the list yet, so we
2888 // avoid asserts by getting out now
2892 wxListCtrl
*list
= wxDynamicCast( GetPeer() , wxListCtrl
);
2895 bool trigger
= false;
2897 wxListEvent
event( wxEVT_COMMAND_LIST_ITEM_SELECTED
, list
->GetId() );
2898 bool isSingle
= (list
->GetWindowStyle() & wxLC_SINGLE_SEL
) != 0;
2900 event
.SetEventObject( list
);
2901 if ( !list
->IsVirtual() )
2903 DataBrowserTableViewRowIndex result
= 0;
2904 verify_noerr( GetItemRow( itemID
, &result
) ) ;
2905 event
.m_itemIndex
= result
;
2909 event
.m_itemIndex
= (long)itemID
-1;
2911 event
.m_item
.m_itemId
= event
.m_itemIndex
;
2912 list
->GetItem(event
.m_item
);
2916 case kDataBrowserItemDeselected
:
2917 event
.SetEventType(wxEVT_COMMAND_LIST_ITEM_DESELECTED
);
2919 trigger
= !IsSelectionSuppressed();
2922 case kDataBrowserItemSelected
:
2923 trigger
= !IsSelectionSuppressed();
2927 case kDataBrowserItemDoubleClicked
:
2928 event
.SetEventType( wxEVT_COMMAND_LIST_ITEM_ACTIVATED
);
2932 case kDataBrowserEditStarted
:
2933 // TODO : how to veto ?
2934 event
.SetEventType( wxEVT_COMMAND_LIST_BEGIN_LABEL_EDIT
) ;
2938 case kDataBrowserEditStopped
:
2939 // TODO probably trigger only upon the value store callback, because
2940 // here IIRC we cannot veto
2941 event
.SetEventType( wxEVT_COMMAND_LIST_END_LABEL_EDIT
) ;
2951 // direct notification is not always having the listbox GetSelection() having in synch with event
2952 wxPostEvent( list
->GetEventHandler(), event
);
2957 Boolean
wxMacDataBrowserListCtrlControl::CompareItems(DataBrowserItemID itemOneID
,
2958 DataBrowserItemID itemTwoID
,
2959 DataBrowserPropertyID sortProperty
)
2962 bool retval
= false;
2964 wxString otherItemText
;
2966 long otherItemOrder
;
2968 int colId
= sortProperty
- kMinColumnId
;
2970 wxListCtrl
* list
= wxDynamicCast( GetPeer() , wxListCtrl
);
2972 DataBrowserSortOrder sort
;
2973 verify_noerr(GetSortOrder(&sort
));
2979 wxMacListCtrlItem
* item
= (wxMacListCtrlItem
*)itemOneID
;
2980 wxMacListCtrlItem
* otherItem
= (wxMacListCtrlItem
*)itemTwoID
;
2982 itemOrder
= item
->GetOrder();
2983 otherItemOrder
= item
->GetOrder();
2985 wxListCtrlCompare func
= list
->GetCompareFunc();
2990 if (item
&& item
->HasColumnInfo(0))
2991 item1
= item
->GetColumnInfo(0)->GetData();
2992 if (otherItem
&& otherItem
->HasColumnInfo(0))
2993 item2
= otherItem
->GetColumnInfo(0)->GetData();
2995 if (item1
> -1 && item2
> -1)
2997 int result
= func(item1
, item2
, list
->GetCompareFuncData());
2998 if (sort
== kDataBrowserOrderIncreasing
)
3005 // we can't use the native control's sorting abilities, so just
3007 return itemOrder
< otherItemOrder
;
3012 long itemNum
= (long)itemOneID
;
3013 long otherItemNum
= (long)itemTwoID
;
3015 // virtual listctrls don't support sorting
3016 return itemNum
< otherItemNum
;
3020 // fallback for undefined cases
3021 retval
= itemOneID
< itemTwoID
;
3027 wxMacDataBrowserListCtrlControl::~wxMacDataBrowserListCtrlControl()
3031 void wxMacDataBrowserListCtrlControl::MacSetColumnInfo( unsigned int row
, unsigned int column
, wxListItem
* item
)
3033 wxMacDataItem
* dataItem
= GetItemFromLine(row
);
3034 wxASSERT_MSG( dataItem
, _T("could not obtain wxMacDataItem for row in MacSetColumnInfo. Is row a valid wxListCtrl row?") );
3037 wxMacListCtrlItem
* listItem
= wx_static_cast(wxMacListCtrlItem
*,dataItem
);
3038 bool hasInfo
= listItem
->HasColumnInfo( column
);
3039 listItem
->SetColumnInfo( column
, item
);
3040 listItem
->SetOrder(row
);
3041 UpdateState(dataItem
, item
);
3043 wxListCtrl
* list
= wxDynamicCast( GetPeer() , wxListCtrl
);
3045 // NB: When this call was made before a control was completely shown, it would
3046 // update the item prematurely (i.e. no text would be listed) and, on show,
3047 // only the sorted column would be refreshed, meaning only first column text labels
3048 // would be shown. Making sure not to update items until the control is visible
3049 // seems to fix this issue.
3050 if (hasInfo
&& list
->IsShown())
3051 UpdateItem( wxMacDataBrowserRootContainer
, listItem
, kMinColumnId
+ column
);
3055 // apply changes that need to happen immediately, rather than when the
3056 // databrowser control fires a callback.
3057 void wxMacDataBrowserListCtrlControl::UpdateState(wxMacDataItem
* dataItem
, wxListItem
* listItem
)
3059 bool isSelected
= IsItemSelected( dataItem
);
3060 bool isSelectedState
= (listItem
->GetState() == wxLIST_STATE_SELECTED
);
3062 // toggle the selection state if wxListInfo state and actual state don't match.
3063 if ( isSelected
!= isSelectedState
)
3065 DataBrowserSetOption options
= kDataBrowserItemsAdd
;
3066 if (!isSelectedState
)
3067 options
= kDataBrowserItemsRemove
;
3068 SetSelectedItem(dataItem
, options
);
3070 // TODO: Set column width if item width > than current column width
3073 void wxMacDataBrowserListCtrlControl::MacGetColumnInfo( unsigned int row
, unsigned int column
, wxListItem
& item
)
3075 wxMacDataItem
* dataItem
= GetItemFromLine(row
);
3076 wxASSERT_MSG( dataItem
, _T("could not obtain wxMacDataItem in MacGetColumnInfo. Is row a valid wxListCtrl row?") );
3077 // CS should this guard against dataItem = 0 ? , as item is not a pointer if (item) is not appropriate
3080 wxMacListCtrlItem
* listItem
=wx_static_cast(wxMacListCtrlItem
*,dataItem
);
3082 if (!listItem
->HasColumnInfo( column
))
3085 wxListItem
* oldItem
= listItem
->GetColumnInfo( column
);
3089 long mask
= item
.GetMask();
3091 // by default, get everything for backwards compatibility
3094 if ( mask
& wxLIST_MASK_TEXT
)
3095 item
.SetText(oldItem
->GetText());
3096 if ( mask
& wxLIST_MASK_IMAGE
)
3097 item
.SetImage(oldItem
->GetImage());
3098 if ( mask
& wxLIST_MASK_DATA
)
3099 item
.SetData(oldItem
->GetData());
3100 if ( mask
& wxLIST_MASK_STATE
)
3101 item
.SetState(oldItem
->GetState());
3102 if ( mask
& wxLIST_MASK_WIDTH
)
3103 item
.SetWidth(oldItem
->GetWidth());
3104 if ( mask
& wxLIST_MASK_FORMAT
)
3105 item
.SetAlign(oldItem
->GetAlign());
3107 item
.SetTextColour(oldItem
->GetTextColour());
3108 item
.SetBackgroundColour(oldItem
->GetBackgroundColour());
3109 item
.SetFont(oldItem
->GetFont());
3114 void wxMacDataBrowserListCtrlControl::MacInsertItem( unsigned int n
, wxListItem
* item
)
3116 wxMacDataItemBrowserControl::MacInsert(n
, item
->GetText());
3117 MacSetColumnInfo(n
, 0, item
);
3120 wxMacDataItem
* wxMacDataBrowserListCtrlControl::CreateItem()
3122 return new wxMacListCtrlItem();
3125 wxMacListCtrlItem::wxMacListCtrlItem()
3127 m_rowItems
= wxListItemList();
3130 int wxMacListCtrlItem::GetColumnImageValue( unsigned int column
)
3132 if ( HasColumnInfo(column
) )
3133 return GetColumnInfo(column
)->GetImage();
3138 void wxMacListCtrlItem::SetColumnImageValue( unsigned int column
, int imageIndex
)
3140 if ( HasColumnInfo(column
) )
3141 GetColumnInfo(column
)->SetImage(imageIndex
);
3144 wxString
wxMacListCtrlItem::GetColumnTextValue( unsigned int column
)
3149 if ( HasColumnInfo(column
) )
3150 return GetColumnInfo(column
)->GetText();
3152 return wxEmptyString
;
3155 void wxMacListCtrlItem::SetColumnTextValue( unsigned int column
, const wxString
& text
)
3157 if ( HasColumnInfo(column
) )
3158 GetColumnInfo(column
)->SetText(text
);
3160 // for compatibility with superclass APIs
3165 wxListItem
* wxMacListCtrlItem::GetColumnInfo( unsigned int column
)
3167 wxASSERT_MSG( HasColumnInfo(column
), _T("invalid column index in wxMacListCtrlItem") );
3168 return m_rowItems
[column
];
3171 bool wxMacListCtrlItem::HasColumnInfo( unsigned int column
)
3173 return !(m_rowItems
.find( column
) == m_rowItems
.end());
3176 void wxMacListCtrlItem::SetColumnInfo( unsigned int column
, wxListItem
* item
)
3179 if ( !HasColumnInfo(column
) )
3181 wxListItem
* listItem
= new wxListItem(*item
);
3182 m_rowItems
[column
] = listItem
;
3186 wxListItem
* listItem
= GetColumnInfo( column
);
3187 long mask
= item
->GetMask();
3188 if (mask
& wxLIST_MASK_TEXT
)
3189 listItem
->SetText(item
->GetText());
3190 if (mask
& wxLIST_MASK_DATA
)
3191 listItem
->SetData(item
->GetData());
3192 if (mask
& wxLIST_MASK_IMAGE
)
3193 listItem
->SetImage(item
->GetImage());
3194 if (mask
& wxLIST_MASK_STATE
)
3195 listItem
->SetState(item
->GetState());
3196 if (mask
& wxLIST_MASK_FORMAT
)
3197 listItem
->SetAlign(item
->GetAlign());
3198 if (mask
& wxLIST_MASK_WIDTH
)
3199 listItem
->SetWidth(item
->GetWidth());
3201 if ( item
->HasAttributes() )
3203 if ( listItem
->HasAttributes() )
3204 listItem
->GetAttributes()->AssignFrom(*item
->GetAttributes());
3207 listItem
->SetTextColour(item
->GetTextColour());
3208 listItem
->SetBackgroundColour(item
->GetBackgroundColour());
3209 listItem
->SetFont(item
->GetFont());
3215 #endif // wxUSE_LISTCTRL