1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/mac/listctrl_mac.cpp
4 // Author: Julian Smart
5 // Modified by: Agron Selimaj
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 // ============================================================================
14 // ============================================================================
16 // ----------------------------------------------------------------------------
18 // ----------------------------------------------------------------------------
20 // For compilers that support precompilation, includes "wx.h".
21 #include "wx/wxprec.h"
29 #include "wx/listctrl.h"
35 #include "wx/mac/uma.h"
37 #include "wx/imaglist.h"
38 #include "wx/sysopt.h"
41 #include "wx/hashmap.h"
43 #define wxMAC_ALWAYS_USE_GENERIC_LISTCTRL wxT("mac.listctrl.always_use_generic")
45 #if wxUSE_EXTENDED_RTTI
46 WX_DEFINE_FLAGS( wxListCtrlStyle
)
48 wxBEGIN_FLAGS( wxListCtrlStyle
)
49 // new style border flags, we put them first to
50 // use them for streaming out
51 wxFLAGS_MEMBER(wxBORDER_SIMPLE
)
52 wxFLAGS_MEMBER(wxBORDER_SUNKEN
)
53 wxFLAGS_MEMBER(wxBORDER_DOUBLE
)
54 wxFLAGS_MEMBER(wxBORDER_RAISED
)
55 wxFLAGS_MEMBER(wxBORDER_STATIC
)
56 wxFLAGS_MEMBER(wxBORDER_NONE
)
58 // old style border flags
59 wxFLAGS_MEMBER(wxSIMPLE_BORDER
)
60 wxFLAGS_MEMBER(wxSUNKEN_BORDER
)
61 wxFLAGS_MEMBER(wxDOUBLE_BORDER
)
62 wxFLAGS_MEMBER(wxRAISED_BORDER
)
63 wxFLAGS_MEMBER(wxSTATIC_BORDER
)
64 wxFLAGS_MEMBER(wxBORDER
)
66 // standard window styles
67 wxFLAGS_MEMBER(wxTAB_TRAVERSAL
)
68 wxFLAGS_MEMBER(wxCLIP_CHILDREN
)
69 wxFLAGS_MEMBER(wxTRANSPARENT_WINDOW
)
70 wxFLAGS_MEMBER(wxWANTS_CHARS
)
71 wxFLAGS_MEMBER(wxFULL_REPAINT_ON_RESIZE
)
72 wxFLAGS_MEMBER(wxALWAYS_SHOW_SB
)
73 wxFLAGS_MEMBER(wxVSCROLL
)
74 wxFLAGS_MEMBER(wxHSCROLL
)
76 wxFLAGS_MEMBER(wxLC_LIST
)
77 wxFLAGS_MEMBER(wxLC_REPORT
)
78 wxFLAGS_MEMBER(wxLC_ICON
)
79 wxFLAGS_MEMBER(wxLC_SMALL_ICON
)
80 wxFLAGS_MEMBER(wxLC_ALIGN_TOP
)
81 wxFLAGS_MEMBER(wxLC_ALIGN_LEFT
)
82 wxFLAGS_MEMBER(wxLC_AUTOARRANGE
)
83 wxFLAGS_MEMBER(wxLC_USER_TEXT
)
84 wxFLAGS_MEMBER(wxLC_EDIT_LABELS
)
85 wxFLAGS_MEMBER(wxLC_NO_HEADER
)
86 wxFLAGS_MEMBER(wxLC_SINGLE_SEL
)
87 wxFLAGS_MEMBER(wxLC_SORT_ASCENDING
)
88 wxFLAGS_MEMBER(wxLC_SORT_DESCENDING
)
89 wxFLAGS_MEMBER(wxLC_VIRTUAL
)
91 wxEND_FLAGS( wxListCtrlStyle
)
93 IMPLEMENT_DYNAMIC_CLASS_XTI(wxListCtrl
, wxControl
,"wx/listctrl.h")
95 wxBEGIN_PROPERTIES_TABLE(wxListCtrl
)
96 wxEVENT_PROPERTY( TextUpdated
, wxEVT_COMMAND_TEXT_UPDATED
, wxCommandEvent
)
98 wxPROPERTY_FLAGS( WindowStyle
, wxListCtrlStyle
, long , SetWindowStyleFlag
, GetWindowStyleFlag
, EMPTY_MACROVALUE
, 0 /*flags*/ , wxT("Helpstring") , wxT("group")) // style
99 wxEND_PROPERTIES_TABLE()
101 wxBEGIN_HANDLERS_TABLE(wxListCtrl
)
102 wxEND_HANDLERS_TABLE()
104 wxCONSTRUCTOR_5( wxListCtrl
, wxWindow
* , Parent
, wxWindowID
, Id
, wxPoint
, Position
, wxSize
, Size
, long , WindowStyle
)
107 TODO : Expose more information of a list's layout etc. via appropriate objects (à la NotebookPageInfo)
110 IMPLEMENT_DYNAMIC_CLASS(wxListCtrl
, wxControl
)
113 IMPLEMENT_DYNAMIC_CLASS(wxListView
, wxListCtrl
)
114 IMPLEMENT_DYNAMIC_CLASS(wxListItem
, wxObject
)
116 IMPLEMENT_DYNAMIC_CLASS(wxListEvent
, wxNotifyEvent
)
118 WX_DECLARE_HASH_MAP( int, wxListItem
*, wxIntegerHash
, wxIntegerEqual
, wxListItemList
);
120 #include "wx/listimpl.cpp"
121 WX_DEFINE_LIST(wxColumnList
)
123 // so we can check for column clicks
124 static const EventTypeSpec eventList
[] =
126 { kEventClassControl
, kEventControlHit
},
127 { kEventClassControl
, kEventControlDraw
}
130 static pascal OSStatus
wxMacListCtrlEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
132 OSStatus result
= eventNotHandledErr
;
134 wxMacCarbonEvent
cEvent( event
) ;
136 ControlRef controlRef
;
137 cEvent
.GetParameter( kEventParamDirectObject
, &controlRef
) ;
139 wxListCtrl
*window
= (wxListCtrl
*) data
;
140 wxListEvent
le( wxEVT_COMMAND_LIST_COL_CLICK
, window
->GetId() );
141 le
.SetEventObject( window
);
143 switch ( GetEventKind( event
) )
145 // check if the column was clicked on and fire an event if so
146 case kEventControlHit
:
148 ControlPartCode result
= cEvent
.GetParameter
<ControlPartCode
>(kEventParamControlPart
, typeControlPartCode
) ;
149 if (result
== kControlButtonPart
){
150 DataBrowserPropertyID col
;
151 GetDataBrowserSortProperty(controlRef
, &col
);
152 int column
= col
- kMinColumnId
;
154 // FIXME: we can't use the sort property for virtual listctrls
155 // so we need to find a better way to determine which column was clicked...
156 if (!window
->IsVirtual())
157 window
->GetEventHandler()->ProcessEvent( le
);
159 result
= CallNextEventHandler(handler
, event
);
162 case kEventControlDraw
:
164 CGContextRef context
= cEvent
.GetParameter
<CGContextRef
>(kEventParamCGContextRef
, typeCGContextRef
) ;
165 window
->MacSetDrawingContext(context
);
166 result
= CallNextEventHandler(handler
, event
);
167 window
->MacSetDrawingContext(NULL
);
178 DEFINE_ONE_SHOT_HANDLER_GETTER( wxMacListCtrlEventHandler
)
180 class wxMacListCtrlItem
: public wxMacListBoxItem
185 virtual void Notification(wxMacDataItemBrowserControl
*owner
,
186 DataBrowserItemNotification message
,
187 DataBrowserItemDataRef itemData
) const;
189 virtual void SetColumnInfo( unsigned int column
, wxListItem
* item
);
190 virtual wxListItem
* GetColumnInfo( unsigned int column
);
191 virtual bool HasColumnInfo( unsigned int column
);
193 virtual void SetColumnTextValue( unsigned int column
, const wxString
& text
);
194 virtual wxString
GetColumnTextValue( unsigned int column
);
196 virtual int GetColumnImageValue( unsigned int column
);
197 virtual void SetColumnImageValue( unsigned int column
, int imageIndex
);
199 virtual ~wxMacListCtrlItem();
201 wxListItemList m_rowItems
;
204 DataBrowserDrawItemUPP gDataBrowserDrawItemUPP
= NULL
;
205 //DataBrowserEditItemUPP gDataBrowserEditItemUPP = NULL;
206 DataBrowserHitTestUPP gDataBrowserHitTestUPP
= NULL
;
208 // TODO: Make a better name!!
209 class wxMacDataBrowserListCtrlControl
: public wxMacDataItemBrowserControl
212 wxMacDataBrowserListCtrlControl( wxWindow
*peer
, const wxPoint
& pos
, const wxSize
& size
, long style
);
213 wxMacDataBrowserListCtrlControl() {}
214 virtual ~wxMacDataBrowserListCtrlControl();
216 // create a list item (can be a subclass of wxMacListBoxItem)
218 virtual wxMacDataItem
* CreateItem();
220 virtual void MacInsertItem( unsigned int n
, wxListItem
* item
);
221 virtual void MacSetColumnInfo( unsigned int row
, unsigned int column
, wxListItem
* item
);
222 virtual void MacGetColumnInfo( unsigned int row
, unsigned int column
, wxListItem
& item
);
223 virtual void UpdateState(wxMacDataItem
* dataItem
, wxListItem
* item
);
226 // we need to override to provide specialized handling for virtual wxListCtrls
227 virtual OSStatus
GetSetItemData(DataBrowserItemID itemID
,
228 DataBrowserPropertyID property
,
229 DataBrowserItemDataRef itemData
,
230 Boolean changeValue
);
232 virtual void ItemNotification(
233 DataBrowserItemID itemID
,
234 DataBrowserItemNotification message
,
235 DataBrowserItemDataRef itemData
);
237 virtual Boolean
CompareItems(DataBrowserItemID itemOneID
,
238 DataBrowserItemID itemTwoID
,
239 DataBrowserPropertyID sortProperty
);
241 static pascal void DataBrowserDrawItemProc(ControlRef browser
,
242 DataBrowserItemID item
,
243 DataBrowserPropertyID property
,
244 DataBrowserItemState itemState
,
247 Boolean colorDevice
);
249 virtual void DrawItem(DataBrowserItemID itemID
,
250 DataBrowserPropertyID property
,
251 DataBrowserItemState itemState
,
252 const Rect
*itemRect
,
254 Boolean colorDevice
);
256 static pascal Boolean
DataBrowserEditTextProc(ControlRef browser
,
257 DataBrowserItemID item
,
258 DataBrowserPropertyID property
,
259 CFStringRef theString
,
260 Rect
*maxEditTextRect
,
261 Boolean
*shrinkToFit
);
263 static pascal Boolean
DataBrowserHitTestProc(ControlRef browser
,
264 DataBrowserItemID itemID
,
265 DataBrowserPropertyID property
,
267 const Rect
*mouseRect
) { return true; }
269 virtual bool ConfirmEditText(DataBrowserItemID item
,
270 DataBrowserPropertyID property
,
271 CFStringRef theString
,
272 Rect
*maxEditTextRect
,
273 Boolean
*shrinkToFit
);
277 wxClientDataType m_clientDataItemsType
;
279 DECLARE_DYNAMIC_CLASS_NO_COPY(wxMacDataBrowserListCtrlControl
)
282 class wxMacListCtrlEventDelegate
: public wxEvtHandler
285 wxMacListCtrlEventDelegate( wxListCtrl
* list
, int id
);
286 virtual bool ProcessEvent( wxEvent
& event
);
293 wxMacListCtrlEventDelegate::wxMacListCtrlEventDelegate( wxListCtrl
* list
, int id
)
299 bool wxMacListCtrlEventDelegate::ProcessEvent( wxEvent
& event
)
301 // even though we use a generic list ctrl underneath, make sure
302 // we present ourselves as wxListCtrl.
303 event
.SetEventObject( m_list
);
306 if ( !event
.IsKindOf( CLASSINFO( wxCommandEvent
) ) )
308 if (m_list
->GetEventHandler()->ProcessEvent( event
))
311 return wxEvtHandler::ProcessEvent(event
);
314 //-----------------------------------------------------------------------------
315 // wxListCtrlRenameTimer (internal)
316 //-----------------------------------------------------------------------------
318 class wxListCtrlRenameTimer
: public wxTimer
324 wxListCtrlRenameTimer( wxListCtrl
*owner
);
328 //-----------------------------------------------------------------------------
329 // wxListCtrlTextCtrlWrapper: wraps a wxTextCtrl to make it work for inline editing
330 //-----------------------------------------------------------------------------
332 class wxListCtrlTextCtrlWrapper
: public wxEvtHandler
335 // NB: text must be a valid object but not Create()d yet
336 wxListCtrlTextCtrlWrapper(wxListCtrl
*owner
,
340 wxTextCtrl
*GetText() const { return m_text
; }
342 void AcceptChangesAndFinish();
345 void OnChar( wxKeyEvent
&event
);
346 void OnKeyUp( wxKeyEvent
&event
);
347 void OnKillFocus( wxFocusEvent
&event
);
349 bool AcceptChanges();
355 wxString m_startValue
;
358 bool m_aboutToFinish
;
360 DECLARE_EVENT_TABLE()
363 //-----------------------------------------------------------------------------
364 // wxListCtrlRenameTimer (internal)
365 //-----------------------------------------------------------------------------
367 wxListCtrlRenameTimer::wxListCtrlRenameTimer( wxListCtrl
*owner
)
372 void wxListCtrlRenameTimer::Notify()
374 m_owner
->OnRenameTimer();
377 //-----------------------------------------------------------------------------
378 // wxListCtrlTextCtrlWrapper (internal)
379 //-----------------------------------------------------------------------------
381 BEGIN_EVENT_TABLE(wxListCtrlTextCtrlWrapper
, wxEvtHandler
)
382 EVT_CHAR (wxListCtrlTextCtrlWrapper::OnChar
)
383 EVT_KEY_UP (wxListCtrlTextCtrlWrapper::OnKeyUp
)
384 EVT_KILL_FOCUS (wxListCtrlTextCtrlWrapper::OnKillFocus
)
387 wxListCtrlTextCtrlWrapper::wxListCtrlTextCtrlWrapper(wxListCtrl
*owner
,
390 : m_startValue(owner
->GetItemText(itemEdit
)),
391 m_itemEdited(itemEdit
)
396 m_aboutToFinish
= false;
400 owner
->GetItemRect(itemEdit
, rectLabel
);
402 m_text
->Create(owner
, wxID_ANY
, m_startValue
,
403 wxPoint(rectLabel
.x
+offset
,rectLabel
.y
),
404 wxSize(rectLabel
.width
-offset
,rectLabel
.height
));
407 m_text
->PushEventHandler(this);
410 void wxListCtrlTextCtrlWrapper::Finish()
416 m_text
->RemoveEventHandler(this);
417 m_owner
->FinishEditing(m_text
);
419 wxPendingDelete
.Append( this );
423 bool wxListCtrlTextCtrlWrapper::AcceptChanges()
425 const wxString value
= m_text
->GetValue();
427 if ( value
== m_startValue
)
428 // nothing changed, always accept
431 if ( !m_owner
->OnRenameAccept(m_itemEdited
, value
) )
432 // vetoed by the user
435 // accepted, do rename the item
436 m_owner
->SetItemText(m_itemEdited
, value
);
441 void wxListCtrlTextCtrlWrapper::AcceptChangesAndFinish()
443 m_aboutToFinish
= true;
445 // Notify the owner about the changes
448 // Even if vetoed, close the control (consistent with MSW)
452 void wxListCtrlTextCtrlWrapper::OnChar( wxKeyEvent
&event
)
454 switch ( event
.m_keyCode
)
457 AcceptChangesAndFinish();
461 m_owner
->OnRenameCancelled( m_itemEdited
);
470 void wxListCtrlTextCtrlWrapper::OnKeyUp( wxKeyEvent
&event
)
478 // auto-grow the textctrl:
479 wxSize parentSize
= m_owner
->GetSize();
480 wxPoint myPos
= m_text
->GetPosition();
481 wxSize mySize
= m_text
->GetSize();
483 m_text
->GetTextExtent(m_text
->GetValue() + _T("MM"), &sx
, &sy
);
484 if (myPos
.x
+ sx
> parentSize
.x
)
485 sx
= parentSize
.x
- myPos
.x
;
488 m_text
->SetSize(sx
, wxDefaultCoord
);
493 void wxListCtrlTextCtrlWrapper::OnKillFocus( wxFocusEvent
&event
)
495 if ( !m_finished
&& !m_aboutToFinish
)
497 if ( !AcceptChanges() )
498 m_owner
->OnRenameCancelled( m_itemEdited
);
503 // We must let the native text control handle focus
507 BEGIN_EVENT_TABLE(wxListCtrl
, wxControl
)
508 EVT_LEFT_DOWN(wxListCtrl::OnLeftDown
)
509 EVT_LEFT_DCLICK(wxListCtrl::OnDblClick
)
510 EVT_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
)
625 FireMouseEvent(wxEVT_COMMAND_LIST_ITEM_RIGHT_CLICK
, event
.GetPosition());
629 void wxListCtrl::OnMiddleDown(wxMouseEvent
& event
)
631 FireMouseEvent(wxEVT_COMMAND_LIST_ITEM_MIDDLE_CLICK
, event
.GetPosition());
635 void wxListCtrl::FireMouseEvent(wxEventType eventType
, wxPoint position
)
637 wxListEvent
le( eventType
, GetId() );
638 le
.SetEventObject(this);
639 le
.m_pointDrag
= position
;
643 long item
= HitTest(position
, flags
);
644 if (flags
& wxLIST_HITTEST_ONITEM
)
646 le
.m_itemIndex
= item
;
650 le
.m_item
.m_itemId
= item
;
653 GetEventHandler()->ProcessEvent(le
);
657 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
;
669 le
.m_item
.m_itemId
= m_current
;
672 GetEventHandler()->ProcessEvent(le
);
677 bool wxListCtrl::Create(wxWindow
*parent
,
682 const wxValidator
& validator
,
683 const wxString
& name
)
686 // for now, we'll always use the generic list control for ICON and LIST views,
687 // because they dynamically change the number of columns on resize.
688 // Also, allow the user to set it to use the list ctrl as well.
689 if ( (wxSystemOptions::HasOption( wxMAC_ALWAYS_USE_GENERIC_LISTCTRL
)
690 && (wxSystemOptions::GetOptionInt( wxMAC_ALWAYS_USE_GENERIC_LISTCTRL
) == 1)) ||
691 (style
& wxLC_ICON
) || (style
& wxLC_SMALL_ICON
) || (style
& wxLC_LIST
) )
693 m_macIsUserPane
= true;
695 long paneStyle
= style
;
696 paneStyle
&= ~wxSIMPLE_BORDER
;
697 paneStyle
&= ~wxDOUBLE_BORDER
;
698 paneStyle
&= ~wxSUNKEN_BORDER
;
699 paneStyle
&= ~wxRAISED_BORDER
;
700 paneStyle
&= ~wxSTATIC_BORDER
;
701 if ( !wxWindow::Create(parent
, id
, pos
, size
, paneStyle
| wxNO_BORDER
, name
) )
704 // since the generic control is a child, make sure we position it at 0, 0
705 m_genericImpl
= new wxGenericListCtrlHook(this, id
, wxPoint(0, 0), size
, style
, validator
, name
);
706 m_genericImpl
->PushEventHandler( new wxMacListCtrlEventDelegate( this, GetId() ) );
712 m_macIsUserPane
= false;
713 if ( !wxWindow::Create(parent
, id
, pos
, size
, style
& ~(wxHSCROLL
| wxVSCROLL
), name
) )
715 m_dbImpl
= new wxMacDataBrowserListCtrlControl( this, pos
, size
, style
);
718 MacPostControlCreate( pos
, size
);
720 InstallControlEventHandler( m_peer
->GetControlRef() , GetwxMacListCtrlEventHandlerUPP(),
721 GetEventTypeCount(eventList
), eventList
, this,
722 (EventHandlerRef
*)&m_macListCtrlEventHandler
);
728 wxListCtrl::~wxListCtrl()
732 m_genericImpl
->PopEventHandler(/* deleteHandler = */ true);
735 if (m_ownsImageListNormal
)
736 delete m_imageListNormal
;
737 if (m_ownsImageListSmall
)
738 delete m_imageListSmall
;
739 if (m_ownsImageListState
)
740 delete m_imageListState
;
742 delete m_renameTimer
;
745 // ----------------------------------------------------------------------------
746 // set/get/change style
747 // ----------------------------------------------------------------------------
749 // Add or remove a single window style
750 void wxListCtrl::SetSingleStyle(long style
, bool add
)
752 long flag
= GetWindowStyleFlag();
754 // Get rid of conflicting styles
757 if ( style
& wxLC_MASK_TYPE
)
758 flag
= flag
& ~wxLC_MASK_TYPE
;
759 if ( style
& wxLC_MASK_ALIGN
)
760 flag
= flag
& ~wxLC_MASK_ALIGN
;
761 if ( style
& wxLC_MASK_SORT
)
762 flag
= flag
& ~wxLC_MASK_SORT
;
770 SetWindowStyleFlag(flag
);
773 // Set the whole window style
774 void wxListCtrl::SetWindowStyleFlag(long flag
)
776 if ( flag
!= m_windowStyle
)
778 m_windowStyle
= flag
;
782 m_genericImpl
->SetWindowStyleFlag(flag
);
789 void wxListCtrl::DoSetSize( int x
, int y
, int width
, int height
, int sizeFlags
)
791 wxControl::DoSetSize(x
, y
, width
, height
, sizeFlags
);
794 m_genericImpl
->SetSize(0, 0, width
, height
, sizeFlags
);
796 // determine if we need a horizontal scrollbar, and add it if so
800 for (int column
= 0; column
< GetColumnCount(); column
++)
802 totalWidth
+= m_dbImpl
->GetColumnWidth( column
);
805 Boolean vertScrollBar
;
806 GetDataBrowserHasScrollBars( m_dbImpl
->GetControlRef(), NULL
, &vertScrollBar
);
807 if (totalWidth
> width
)
808 SetDataBrowserHasScrollBars( m_dbImpl
->GetControlRef(), true, vertScrollBar
);
810 SetDataBrowserHasScrollBars( m_dbImpl
->GetControlRef(), false, vertScrollBar
);
814 wxSize
wxListCtrl::DoGetBestSize() const
816 return wxWindow::DoGetBestSize();
819 bool wxListCtrl::SetFont(const wxFont
& font
)
822 rv
= wxControl::SetFont(font
);
824 rv
= m_genericImpl
->SetFont(font
);
828 bool wxListCtrl::SetForegroundColour(const wxColour
& colour
)
832 rv
= m_genericImpl
->SetForegroundColour(colour
);
834 SetTextColour(colour
);
838 bool wxListCtrl::SetBackgroundColour(const wxColour
& colour
)
842 rv
= m_genericImpl
->SetBackgroundColour(colour
);
848 wxColour
wxListCtrl::GetBackgroundColour()
851 return m_genericImpl
->GetBackgroundColour();
858 // ----------------------------------------------------------------------------
860 // ----------------------------------------------------------------------------
862 // Gets information about this column
863 bool wxListCtrl::GetColumn(int col
, wxListItem
& item
) const
866 return m_genericImpl
->GetColumn(col
, item
);
872 wxColumnList::compatibility_iterator node
= m_colsInfo
.Item( col
);
873 wxASSERT_MSG( node
, _T("invalid column index in wxMacListCtrlItem") );
874 wxListItem
* column
= node
->GetData();
876 long mask
= column
->GetMask();
877 if (mask
& wxLIST_MASK_TEXT
)
878 item
.SetText(column
->GetText());
879 if (mask
& wxLIST_MASK_DATA
)
880 item
.SetData(column
->GetData());
881 if (mask
& wxLIST_MASK_IMAGE
)
882 item
.SetImage(column
->GetImage());
883 if (mask
& wxLIST_MASK_STATE
)
884 item
.SetState(column
->GetState());
885 if (mask
& wxLIST_MASK_FORMAT
)
886 item
.SetAlign(column
->GetAlign());
887 if (mask
& wxLIST_MASK_WIDTH
)
888 item
.SetWidth(column
->GetWidth());
894 // Sets information about this column
895 bool wxListCtrl::SetColumn(int col
, wxListItem
& item
)
898 return m_genericImpl
->SetColumn(col
, item
);
902 long mask
= item
.GetMask();
903 if ( col
>= (int)m_colsInfo
.GetCount() )
905 wxListItem
* listItem
= new wxListItem(item
);
906 m_colsInfo
.Append( listItem
);
911 GetColumn( col
, listItem
);
913 if (mask
& wxLIST_MASK_TEXT
)
914 listItem
.SetText(item
.GetText());
915 if (mask
& wxLIST_MASK_DATA
)
916 listItem
.SetData(item
.GetData());
917 if (mask
& wxLIST_MASK_IMAGE
)
918 listItem
.SetImage(item
.GetImage());
919 if (mask
& wxLIST_MASK_STATE
)
920 listItem
.SetState(item
.GetState());
921 if (mask
& wxLIST_MASK_FORMAT
)
922 listItem
.SetAlign(item
.GetAlign());
923 if (mask
& wxLIST_MASK_WIDTH
)
924 listItem
.SetWidth(item
.GetWidth());
927 // change the appearance in the databrowser.
928 DataBrowserListViewHeaderDesc columnDesc
;
929 columnDesc
.version
=kDataBrowserListViewLatestHeaderDesc
;
930 verify_noerr( m_dbImpl
->GetHeaderDesc( kMinColumnId
+ col
, &columnDesc
) );
933 if (item.GetMask() & wxLIST_MASK_TEXT)
937 enc = m_font.GetEncoding();
939 enc = wxLocale::GetSystemEncoding();
940 wxMacCFStringHolder cfTitle;
941 cfTitle.Assign( item.GetText() , enc );
942 if(columnDesc.titleString)
943 CFRelease(columnDesc.titleString);
944 columnDesc.titleString = cfTitle;
948 if (item
.GetMask() & wxLIST_MASK_IMAGE
&& item
.GetImage() != -1 )
950 columnDesc
.btnContentInfo
.contentType
= kControlContentIconRef
;
951 wxImageList
* imageList
= GetImageList(wxIMAGE_LIST_SMALL
);
952 if (imageList
&& imageList
->GetImageCount() > 0 )
954 wxBitmap bmp
= imageList
->GetBitmap( item
.GetImage() );
955 IconRef icon
= bmp
.GetBitmapData()->GetIconRef();
956 columnDesc
.btnContentInfo
.u
.iconRef
= icon
;
960 verify_noerr( m_dbImpl
->SetHeaderDesc( kMinColumnId
+ col
, &columnDesc
) );
966 int wxListCtrl::GetColumnCount() const
969 return m_genericImpl
->GetColumnCount();
974 m_dbImpl
->GetColumnCount(&count
);
981 // Gets the column width
982 int wxListCtrl::GetColumnWidth(int col
) const
985 return m_genericImpl
->GetColumnWidth(col
);
989 return m_dbImpl
->GetColumnWidth(col
);
995 // Sets the column width
996 bool wxListCtrl::SetColumnWidth(int col
, int width
)
999 return m_genericImpl
->SetColumnWidth(col
, width
);
1003 int mywidth
= width
;
1004 if (width
== wxLIST_AUTOSIZE
|| width
== wxLIST_AUTOSIZE_USEHEADER
)
1009 for (int column
= 0; column
< GetColumnCount(); column
++)
1012 GetColumn(col
, colInfo
);
1014 colInfo
.SetWidth(width
);
1015 SetColumn(col
, colInfo
);
1017 m_dbImpl
->SetColumnWidth(col
, mywidth
);
1023 GetColumn(col
, colInfo
);
1025 colInfo
.SetWidth(width
);
1026 SetColumn(col
, colInfo
);
1027 m_dbImpl
->SetColumnWidth(col
, mywidth
);
1035 // Gets the number of items that can fit vertically in the
1036 // visible area of the list control (list or report view)
1037 // or the total number of items in the list control (icon
1038 // or small icon view)
1039 int wxListCtrl::GetCountPerPage() const
1042 return m_genericImpl
->GetCountPerPage();
1051 // Gets the edit control for editing labels.
1052 wxTextCtrl
* wxListCtrl::GetEditControl() const
1055 return m_genericImpl
->GetEditControl();
1060 // Gets information about the item
1061 bool wxListCtrl::GetItem(wxListItem
& info
) const
1064 return m_genericImpl
->GetItem(info
);
1069 m_dbImpl
->MacGetColumnInfo(info
.m_itemId
, info
.m_col
, info
);
1072 info
.SetText( OnGetItemText(info
.m_itemId
, info
.m_col
) );
1073 info
.SetImage( OnGetItemColumnImage(info
.m_itemId
, info
.m_col
) );
1074 if (info
.GetMask() & wxLIST_MASK_STATE
)
1076 if (IsDataBrowserItemSelected( m_dbImpl
->GetControlRef(), info
.m_itemId
+1 ))
1077 info
.SetState(info
.GetState() | wxLIST_STATE_SELECTED
);
1080 wxListItemAttr
* attrs
= OnGetItemAttr( info
.m_itemId
);
1083 info
.SetFont( attrs
->GetFont() );
1084 info
.SetBackgroundColour( attrs
->GetBackgroundColour() );
1085 info
.SetTextColour( attrs
->GetTextColour() );
1089 bool success
= true;
1093 // Sets information about the item
1094 bool wxListCtrl::SetItem(wxListItem
& info
)
1097 return m_genericImpl
->SetItem(info
);
1100 m_dbImpl
->MacSetColumnInfo( info
.m_itemId
, info
.m_col
, &info
);
1105 long wxListCtrl::SetItem(long index
, int col
, const wxString
& label
, int imageId
)
1108 return m_genericImpl
->SetItem(index
, col
, label
, imageId
);
1111 info
.m_text
= label
;
1112 info
.m_mask
= wxLIST_MASK_TEXT
;
1113 info
.m_itemId
= index
;
1117 info
.m_image
= imageId
;
1118 info
.m_mask
|= wxLIST_MASK_IMAGE
;
1120 return SetItem(info
);
1124 // Gets the item state
1125 int wxListCtrl::GetItemState(long item
, long stateMask
) const
1128 return m_genericImpl
->GetItemState(item
, stateMask
);
1132 if ( HasFlag(wxLC_VIRTUAL
) )
1134 if (stateMask
== wxLIST_STATE_SELECTED
)
1136 if (IsDataBrowserItemSelected( m_dbImpl
->GetControlRef(), item
+1 ))
1137 return wxLIST_STATE_SELECTED
;
1146 info
.m_mask
= wxLIST_MASK_STATE
;
1147 info
.m_stateMask
= stateMask
;
1148 info
.m_itemId
= item
;
1153 return info
.m_state
;
1160 // Sets the item state
1161 bool wxListCtrl::SetItemState(long item
, long state
, long stateMask
)
1164 return m_genericImpl
->SetItemState(item
, state
, stateMask
);
1168 DataBrowserSetOption option
= kDataBrowserItemsAdd
;
1169 if ( stateMask
== wxLIST_STATE_SELECTED
&& state
== 0 )
1170 option
= kDataBrowserItemsRemove
;
1174 if ( HasFlag(wxLC_VIRTUAL
) )
1176 wxMacDataItemBrowserSelectionSuppressor
suppressor(m_dbImpl
);
1177 m_dbImpl
->SetSelectedAllItems(option
);
1181 for(int i
= 0; i
< GetItemCount();i
++)
1185 info
.m_mask
= wxLIST_MASK_STATE
;
1186 info
.m_stateMask
= stateMask
;
1187 info
.m_state
= state
;
1194 if ( HasFlag(wxLC_VIRTUAL
) )
1196 long itemID
= item
+1;
1197 SetDataBrowserSelectedItems(m_dbImpl
->GetControlRef(), 1, (DataBrowserItemID
*)&itemID
, option
);
1202 info
.m_itemId
= item
;
1203 info
.m_mask
= wxLIST_MASK_STATE
;
1204 info
.m_stateMask
= stateMask
;
1205 info
.m_state
= state
;
1206 return SetItem(info
);
1213 // Sets the item image
1214 bool wxListCtrl::SetItemImage(long item
, int image
, int WXUNUSED(selImage
))
1216 return SetItemColumnImage(item
, 0, image
);
1219 // Sets the item image
1220 bool wxListCtrl::SetItemColumnImage(long item
, long column
, int image
)
1223 return m_genericImpl
->SetItemColumnImage(item
, column
, image
);
1227 info
.m_mask
= wxLIST_MASK_IMAGE
;
1228 info
.m_image
= image
;
1229 info
.m_itemId
= item
;
1230 info
.m_col
= column
;
1232 return SetItem(info
);
1235 // Gets the item text
1236 wxString
wxListCtrl::GetItemText(long item
) const
1239 return m_genericImpl
->GetItemText(item
);
1243 info
.m_mask
= wxLIST_MASK_TEXT
;
1244 info
.m_itemId
= item
;
1247 return wxEmptyString
;
1251 // Sets the item text
1252 void wxListCtrl::SetItemText(long item
, const wxString
& str
)
1255 return m_genericImpl
->SetItemText(item
, str
);
1259 info
.m_mask
= wxLIST_MASK_TEXT
;
1260 info
.m_itemId
= item
;
1266 // Gets the item data
1267 long wxListCtrl::GetItemData(long item
) const
1270 return m_genericImpl
->GetItemData(item
);
1274 info
.m_mask
= wxLIST_MASK_DATA
;
1275 info
.m_itemId
= item
;
1282 // Sets the item data
1283 bool wxListCtrl::SetItemData(long item
, long data
)
1286 return m_genericImpl
->SetItemData(item
, data
);
1290 info
.m_mask
= wxLIST_MASK_DATA
;
1291 info
.m_itemId
= item
;
1294 return SetItem(info
);
1297 wxRect
wxListCtrl::GetViewRect() const
1299 wxASSERT_MSG( !HasFlag(wxLC_REPORT
| wxLC_LIST
),
1300 _T("wxListCtrl::GetViewRect() only works in icon mode") );
1303 return m_genericImpl
->GetViewRect();
1309 // Gets the item rectangle
1310 bool wxListCtrl::GetItemRect(long item
, wxRect
& rect
, int code
) const
1313 return m_genericImpl
->GetItemRect(item
, rect
, code
);
1318 DataBrowserItemID id
;
1319 DataBrowserPropertyID col
= kMinColumnId
;
1321 DataBrowserPropertyPart part
= kDataBrowserPropertyEnclosingPart
;
1322 if ( code
== wxLIST_RECT_LABEL
)
1323 part
= kDataBrowserPropertyTextPart
;
1324 else if ( code
== wxLIST_RECT_ICON
)
1325 part
= kDataBrowserPropertyIconPart
;
1327 if ( !(GetWindowStyleFlag() & wxLC_VIRTUAL
) )
1329 wxMacDataItem
* thisItem
= m_dbImpl
->GetItemFromLine(item
);
1330 id
= (DataBrowserItemID
) thisItem
;
1335 GetDataBrowserItemPartBounds( m_dbImpl
->GetControlRef(), id
, col
, part
, &bounds
);
1337 rect
.x
= bounds
.left
;
1338 rect
.y
= bounds
.top
;
1339 rect
.width
= bounds
.right
- bounds
.left
; //GetClientSize().x; // we need the width of the whole row, not just the item.
1340 rect
.height
= bounds
.bottom
- bounds
.top
;
1341 //fprintf("id = %d, bounds = %d, %d, %d, %d\n", id, rect.x, rect.y, rect.width, rect.height);
1346 // Gets the item position
1347 bool wxListCtrl::GetItemPosition(long item
, wxPoint
& pos
) const
1350 return m_genericImpl
->GetItemPosition(item
, pos
);
1352 bool success
= false;
1357 GetItemRect(item
, itemRect
);
1358 pos
= itemRect
.GetPosition();
1365 // Sets the item position.
1366 bool wxListCtrl::SetItemPosition(long item
, const wxPoint
& pos
)
1369 return m_genericImpl
->SetItemPosition(item
, pos
);
1374 // Gets the number of items in the list control
1375 int wxListCtrl::GetItemCount() const
1378 return m_genericImpl
->GetItemCount();
1381 return m_dbImpl
->MacGetCount();
1386 void wxListCtrl::SetItemSpacing( int spacing
, bool isSmall
)
1389 m_genericImpl
->SetItemSpacing(spacing
, isSmall
);
1392 wxSize
wxListCtrl::GetItemSpacing() const
1395 return m_genericImpl
->GetItemSpacing();
1397 return wxSize(0, 0);
1400 void wxListCtrl::SetItemTextColour( long item
, const wxColour
&col
)
1404 m_genericImpl
->SetItemTextColour(item
, col
);
1409 info
.m_itemId
= item
;
1410 info
.SetTextColour( col
);
1414 wxColour
wxListCtrl::GetItemTextColour( long item
) const
1417 return m_genericImpl
->GetItemTextColour(item
);
1423 return info
.GetTextColour();
1425 return wxNullColour
;
1428 void wxListCtrl::SetItemBackgroundColour( long item
, const wxColour
&col
)
1432 m_genericImpl
->SetItemBackgroundColour(item
, col
);
1437 info
.m_itemId
= item
;
1438 info
.SetBackgroundColour( col
);
1442 wxColour
wxListCtrl::GetItemBackgroundColour( long item
) const
1445 return m_genericImpl
->GetItemBackgroundColour(item
);
1451 return info
.GetBackgroundColour();
1453 return wxNullColour
;
1456 void wxListCtrl::SetItemFont( long item
, const wxFont
&f
)
1460 m_genericImpl
->SetItemFont(item
, f
);
1465 info
.m_itemId
= item
;
1470 wxFont
wxListCtrl::GetItemFont( long item
) const
1473 return m_genericImpl
->GetItemFont(item
);
1479 return info
.GetFont();
1485 // Gets the number of selected items in the list control
1486 int wxListCtrl::GetSelectedItemCount() const
1489 return m_genericImpl
->GetSelectedItemCount();
1492 return m_dbImpl
->GetSelectedItemCount(NULL
, true);
1497 // Gets the text colour of the listview
1498 wxColour
wxListCtrl::GetTextColour() const
1501 return m_genericImpl
->GetTextColour();
1503 // TODO: we need owner drawn list items to customize text color.
1507 return wxNullColour
;
1510 // Sets the text colour of the listview
1511 void wxListCtrl::SetTextColour(const wxColour
& col
)
1515 m_genericImpl
->SetTextColour(col
);
1523 // Gets the index of the topmost visible item when in
1524 // list or report view
1525 long wxListCtrl::GetTopItem() const
1528 return m_genericImpl
->GetTopItem();
1533 long item
= HitTest( wxPoint(1, 1), flags
);
1534 if (flags
== wxLIST_HITTEST_ONITEM
)
1541 // Searches for an item, starting from 'item'.
1542 // 'geometry' is one of
1543 // wxLIST_NEXT_ABOVE/ALL/BELOW/LEFT/RIGHT.
1544 // 'state' is a state bit flag, one or more of
1545 // wxLIST_STATE_DROPHILITED/FOCUSED/SELECTED/CUT.
1546 // item can be -1 to find the first item that matches the
1548 // Returns the item or -1 if unsuccessful.
1549 long wxListCtrl::GetNextItem(long item
, int geom
, int state
) const
1552 return m_genericImpl
->GetNextItem(item
, geom
, state
);
1554 if (m_dbImpl
&& geom
== wxLIST_NEXT_ALL
&& state
== wxLIST_STATE_SELECTED
)
1556 long count
= m_dbImpl
->MacGetCount() ;
1557 for ( long line
= item
+ 1 ; line
< count
; line
++ )
1559 wxMacDataItem
* id
= m_dbImpl
->GetItemFromLine(line
);
1560 if ( m_dbImpl
->IsItemSelected(id
) )
1570 wxImageList
*wxListCtrl::GetImageList(int which
) const
1573 return m_genericImpl
->GetImageList(which
);
1575 if ( which
== wxIMAGE_LIST_NORMAL
)
1577 return m_imageListNormal
;
1579 else if ( which
== wxIMAGE_LIST_SMALL
)
1581 return m_imageListSmall
;
1583 else if ( which
== wxIMAGE_LIST_STATE
)
1585 return m_imageListState
;
1590 void wxListCtrl::SetImageList(wxImageList
*imageList
, int which
)
1594 m_genericImpl
->SetImageList(imageList
, which
);
1598 if ( which
== wxIMAGE_LIST_NORMAL
)
1600 if (m_ownsImageListNormal
) delete m_imageListNormal
;
1601 m_imageListNormal
= imageList
;
1602 m_ownsImageListNormal
= false;
1604 else if ( which
== wxIMAGE_LIST_SMALL
)
1606 if (m_ownsImageListSmall
) delete m_imageListSmall
;
1607 m_imageListSmall
= imageList
;
1608 m_ownsImageListSmall
= false;
1610 else if ( which
== wxIMAGE_LIST_STATE
)
1612 if (m_ownsImageListState
) delete m_imageListState
;
1613 m_imageListState
= imageList
;
1614 m_ownsImageListState
= false;
1618 void wxListCtrl::AssignImageList(wxImageList
*imageList
, int which
)
1622 m_genericImpl
->AssignImageList(imageList
, which
);
1626 SetImageList(imageList
, which
);
1627 if ( which
== wxIMAGE_LIST_NORMAL
)
1628 m_ownsImageListNormal
= true;
1629 else if ( which
== wxIMAGE_LIST_SMALL
)
1630 m_ownsImageListSmall
= true;
1631 else if ( which
== wxIMAGE_LIST_STATE
)
1632 m_ownsImageListState
= true;
1635 // ----------------------------------------------------------------------------
1637 // ----------------------------------------------------------------------------
1639 // Arranges the items
1640 bool wxListCtrl::Arrange(int flag
)
1643 return m_genericImpl
->Arrange(flag
);
1648 bool wxListCtrl::DeleteItem(long item
)
1651 return m_genericImpl
->DeleteItem(item
);
1655 m_dbImpl
->MacDelete(item
);
1656 wxListEvent
event( wxEVT_COMMAND_LIST_DELETE_ITEM
, GetId() );
1657 event
.SetEventObject( this );
1658 event
.m_itemIndex
= item
;
1659 GetEventHandler()->ProcessEvent( event
);
1665 // Deletes all items
1666 bool wxListCtrl::DeleteAllItems()
1669 return m_genericImpl
->DeleteAllItems();
1673 m_dbImpl
->MacClear();
1674 wxListEvent
event( wxEVT_COMMAND_LIST_DELETE_ALL_ITEMS
, GetId() );
1675 event
.SetEventObject( this );
1676 GetEventHandler()->ProcessEvent( event
);
1681 // Deletes all items
1682 bool wxListCtrl::DeleteAllColumns()
1685 return m_genericImpl
->DeleteAllColumns();
1690 m_dbImpl
->GetColumnCount(&cols
);
1691 for (UInt32 col
= 0; col
< cols
; col
++)
1701 bool wxListCtrl::DeleteColumn(int col
)
1704 return m_genericImpl
->DeleteColumn(col
);
1708 OSStatus err
= m_dbImpl
->RemoveColumn(col
);
1709 return err
== noErr
;
1715 // Clears items, and columns if there are any.
1716 void wxListCtrl::ClearAll()
1720 m_genericImpl
->ClearAll();
1731 wxTextCtrl
* wxListCtrl::EditLabel(long item
, wxClassInfo
* textControlClass
)
1734 return m_genericImpl
->EditLabel(item
, textControlClass
);
1738 wxCHECK_MSG( (item
>= 0) && ((long)item
< GetItemCount()), NULL
,
1739 wxT("wrong index in wxListCtrl::EditLabel()") );
1741 wxASSERT_MSG( textControlClass
->IsKindOf(CLASSINFO(wxTextCtrl
)),
1742 wxT("EditLabel() needs a text control") );
1744 wxListEvent
le( wxEVT_COMMAND_LIST_BEGIN_LABEL_EDIT
, GetParent()->GetId() );
1745 le
.SetEventObject( this );
1746 le
.m_itemIndex
= item
;
1748 GetItem( le
.m_item
);
1750 if ( GetParent()->GetEventHandler()->ProcessEvent( le
) && !le
.IsAllowed() )
1752 // vetoed by user code
1756 wxTextCtrl
* const text
= (wxTextCtrl
*)textControlClass
->CreateObject();
1757 m_textctrlWrapper
= new wxListCtrlTextCtrlWrapper(this, text
, item
);
1758 return m_textctrlWrapper
->GetText();
1763 // End label editing, optionally cancelling the edit
1764 bool wxListCtrl::EndEditLabel(bool cancel
)
1766 // TODO: generic impl. doesn't have this method - is it needed for us?
1768 return true; // m_genericImpl->EndEditLabel(cancel);
1771 verify_noerr( SetDataBrowserEditItem(m_dbImpl
->GetControlRef(), kDataBrowserNoItem
, kMinColumnId
) );
1775 // Ensures this item is visible
1776 bool wxListCtrl::EnsureVisible(long item
)
1779 return m_genericImpl
->EnsureVisible(item
);
1783 wxMacDataItem
* dataItem
= m_dbImpl
->GetItemFromLine(item
);
1784 m_dbImpl
->RevealItem(dataItem
, kDataBrowserRevealWithoutSelecting
);
1790 // Find an item whose label matches this string, starting from the item after 'start'
1791 // or the beginning if 'start' is -1.
1792 long wxListCtrl::FindItem(long start
, const wxString
& str
, bool partial
)
1795 return m_genericImpl
->FindItem(start
, str
, partial
);
1797 wxString str_upper
= str
.Upper();
1802 long count
= GetItemCount();
1806 wxString line_upper
= GetItemText(idx
).Upper();
1809 if (line_upper
== str_upper
)
1814 if (line_upper
.find(str_upper
) == 0)
1824 // Find an item whose data matches this data, starting from the item after 'start'
1825 // or the beginning if 'start' is -1.
1826 long wxListCtrl::FindItem(long start
, long data
)
1829 return m_genericImpl
->FindItem(start
, data
);
1834 long count
= GetItemCount();
1838 if (GetItemData(idx
) == data
)
1846 // Find an item nearest this position in the specified direction, starting from
1847 // the item after 'start' or the beginning if 'start' is -1.
1848 long wxListCtrl::FindItem(long start
, const wxPoint
& pt
, int direction
)
1851 return m_genericImpl
->FindItem(start
, pt
, direction
);
1855 // Determines which item (if any) is at the specified point,
1856 // giving details in 'flags' (see wxLIST_HITTEST_... flags above)
1858 wxListCtrl::HitTest(const wxPoint
& point
, int& flags
, long *ptrSubItem
) const
1861 return m_genericImpl
->HitTest(point
, flags
, ptrSubItem
);
1863 flags
= wxLIST_HITTEST_NOWHERE
;
1866 int colHeaderHeight
= 22; // TODO: Find a way to get this value from the db control?
1867 UInt16 rowHeight
= 0;
1868 m_dbImpl
->GetDefaultRowHeight(&rowHeight
);
1871 // get the actual row by taking scroll position into account
1872 UInt32 offsetX
, offsetY
;
1873 m_dbImpl
->GetScrollPosition( &offsetY
, &offsetX
);
1876 if ( !(GetWindowStyleFlag() & wxLC_NO_HEADER
) )
1877 y
-= colHeaderHeight
;
1882 int row
= y
/ rowHeight
;
1883 DataBrowserItemID id
;
1884 m_dbImpl
->GetItemID( (DataBrowserTableViewRowIndex
) row
, &id
);
1886 // TODO: Use GetDataBrowserItemPartBounds to return if we are in icon or label
1887 if ( !(GetWindowStyleFlag() & wxLC_VIRTUAL
) )
1889 wxMacListCtrlItem
* lcItem
;
1890 lcItem
= (wxMacListCtrlItem
*) id
;
1893 flags
= wxLIST_HITTEST_ONITEM
;
1899 if (row
< GetItemCount() )
1901 flags
= wxLIST_HITTEST_ONITEM
;
1910 int wxListCtrl::GetScrollPos(int orient
) const
1913 return m_genericImpl
->GetScrollPos(orient
);
1917 UInt32 offsetX
, offsetY
;
1918 m_dbImpl
->GetScrollPosition( &offsetY
, &offsetX
);
1919 if ( orient
== wxHORIZONTAL
)
1928 // Inserts an item, returning the index of the new item if successful,
1930 long wxListCtrl::InsertItem(wxListItem
& info
)
1932 wxASSERT_MSG( !IsVirtual(), _T("can't be used with virtual controls") );
1935 return m_genericImpl
->InsertItem(info
);
1937 if (m_dbImpl
&& !IsVirtual())
1939 int count
= GetItemCount();
1941 if (info
.m_itemId
> count
)
1942 info
.m_itemId
= count
;
1944 m_dbImpl
->MacInsertItem(info
.m_itemId
, &info
);
1945 wxMacDataItem
* dataItem
= m_dbImpl
->GetItemFromLine(info
.m_itemId
);
1947 wxListEvent
event( wxEVT_COMMAND_LIST_INSERT_ITEM
, GetId() );
1948 event
.SetEventObject( this );
1949 event
.m_itemIndex
= info
.m_itemId
;
1950 GetEventHandler()->ProcessEvent( event
);
1951 return info
.m_itemId
;
1956 long wxListCtrl::InsertItem(long index
, const wxString
& label
)
1959 return m_genericImpl
->InsertItem(index
, label
);
1962 info
.m_text
= label
;
1963 info
.m_mask
= wxLIST_MASK_TEXT
;
1964 info
.m_itemId
= index
;
1965 return InsertItem(info
);
1968 // Inserts an image item
1969 long wxListCtrl::InsertItem(long index
, int imageIndex
)
1972 return m_genericImpl
->InsertItem(index
, imageIndex
);
1975 info
.m_image
= imageIndex
;
1976 info
.m_mask
= wxLIST_MASK_IMAGE
;
1977 info
.m_itemId
= index
;
1978 return InsertItem(info
);
1981 // Inserts an image/string item
1982 long wxListCtrl::InsertItem(long index
, const wxString
& label
, int imageIndex
)
1985 return m_genericImpl
->InsertItem(index
, label
, imageIndex
);
1988 info
.m_image
= imageIndex
;
1989 info
.m_text
= label
;
1990 info
.m_mask
= wxLIST_MASK_IMAGE
| wxLIST_MASK_TEXT
;
1991 info
.m_itemId
= index
;
1992 return InsertItem(info
);
1995 // For list view mode (only), inserts a column.
1996 long wxListCtrl::InsertColumn(long col
, wxListItem
& item
)
1999 return m_genericImpl
->InsertColumn(col
, item
);
2003 int width
= item
.GetWidth();
2004 if ( !(item
.GetMask() & wxLIST_MASK_WIDTH
) )
2007 DataBrowserPropertyType type
= kDataBrowserCustomType
; //kDataBrowserTextType;
2008 wxImageList
* imageList
= GetImageList(wxIMAGE_LIST_SMALL
);
2009 if (imageList
&& imageList
->GetImageCount() > 0)
2011 wxBitmap bmp
= imageList
->GetBitmap(0);
2013 // type = kDataBrowserIconAndTextType;
2016 SInt16 just
= teFlushDefault
;
2017 if (item
.GetMask() & wxLIST_MASK_FORMAT
)
2019 if (item
.GetAlign() == wxLIST_FORMAT_LEFT
)
2021 else if (item
.GetAlign() == wxLIST_FORMAT_CENTER
)
2023 else if (item
.GetAlign() == wxLIST_FORMAT_RIGHT
)
2024 just
= teFlushRight
;
2026 m_dbImpl
->InsertColumn(col
, type
, item
.GetText(), just
, width
);
2027 SetColumn(col
, item
);
2029 // set/remove options based on the wxListCtrl type.
2030 DataBrowserTableViewColumnID id
;
2031 m_dbImpl
->GetColumnIDFromIndex(col
, &id
);
2032 DataBrowserPropertyFlags flags
;
2033 verify_noerr(m_dbImpl
->GetPropertyFlags(id
, &flags
));
2034 if (GetWindowStyleFlag() & wxLC_EDIT_LABELS
)
2035 flags
|= kDataBrowserPropertyIsEditable
;
2037 if (GetWindowStyleFlag() & wxLC_VIRTUAL
){
2038 flags
&= ~kDataBrowserListViewSortableColumn
;
2040 verify_noerr(m_dbImpl
->SetPropertyFlags(id
, flags
));
2046 long wxListCtrl::InsertColumn(long col
,
2047 const wxString
& heading
,
2052 return m_genericImpl
->InsertColumn(col
, heading
, format
, width
);
2055 item
.m_mask
= wxLIST_MASK_TEXT
| wxLIST_MASK_FORMAT
;
2056 item
.m_text
= heading
;
2059 item
.m_mask
|= wxLIST_MASK_WIDTH
;
2060 item
.m_width
= width
;
2062 item
.m_format
= format
;
2064 return InsertColumn(col
, item
);
2067 // scroll the control by the given number of pixels (exception: in list view,
2068 // dx is interpreted as number of columns)
2069 bool wxListCtrl::ScrollList(int dx
, int dy
)
2072 return m_genericImpl
->ScrollList(dx
, dy
);
2076 m_dbImpl
->SetScrollPosition(dx
, dy
);
2082 bool wxListCtrl::SortItems(wxListCtrlCompare fn
, long data
)
2085 return m_genericImpl
->SortItems(fn
, data
);
2090 m_compareFuncData
= data
;
2091 SortDataBrowserContainer( m_dbImpl
->GetControlRef(), kDataBrowserNoItem
, true);
2093 // we need to do this after each call, else we get a crash from wxPython when
2094 // SortItems is called the second time.
2095 m_compareFunc
= NULL
;
2096 m_compareFuncData
= 0;
2102 void wxListCtrl::OnRenameTimer()
2104 wxCHECK_RET( HasCurrent(), wxT("unexpected rename timer") );
2106 EditLabel( m_current
);
2109 bool wxListCtrl::OnRenameAccept(long itemEdit
, const wxString
& value
)
2111 wxListEvent
le( wxEVT_COMMAND_LIST_END_LABEL_EDIT
, GetId() );
2112 le
.SetEventObject( this );
2113 le
.m_itemIndex
= itemEdit
;
2115 GetItem( le
.m_item
);
2116 le
.m_item
.m_text
= value
;
2117 return !GetEventHandler()->ProcessEvent( le
) ||
2121 void wxListCtrl::OnRenameCancelled(long itemEdit
)
2123 // let owner know that the edit was cancelled
2124 wxListEvent
le( wxEVT_COMMAND_LIST_END_LABEL_EDIT
, GetParent()->GetId() );
2126 le
.SetEditCanceled(true);
2128 le
.SetEventObject( this );
2129 le
.m_itemIndex
= itemEdit
;
2131 GetItem( le
.m_item
);
2132 GetEventHandler()->ProcessEvent( le
);
2135 // ----------------------------------------------------------------------------
2136 // virtual list controls
2137 // ----------------------------------------------------------------------------
2139 wxString
wxListCtrl::OnGetItemText(long WXUNUSED(item
), long WXUNUSED(col
)) const
2141 // this is a pure virtual function, in fact - which is not really pure
2142 // because the controls which are not virtual don't need to implement it
2143 wxFAIL_MSG( _T("wxListCtrl::OnGetItemText not supposed to be called") );
2145 return wxEmptyString
;
2148 int wxListCtrl::OnGetItemImage(long WXUNUSED(item
)) const
2150 wxCHECK_MSG(!GetImageList(wxIMAGE_LIST_SMALL
),
2152 wxT("List control has an image list, OnGetItemImage or OnGetItemColumnImage should be overridden."));
2156 int wxListCtrl::OnGetItemColumnImage(long item
, long column
) const
2159 return OnGetItemImage(item
);
2164 wxListItemAttr
*wxListCtrl::OnGetItemAttr(long WXUNUSED_UNLESS_DEBUG(item
)) const
2166 wxASSERT_MSG( item
>= 0 && item
< GetItemCount(),
2167 _T("invalid item index in OnGetItemAttr()") );
2169 // no attributes by default
2173 void wxListCtrl::SetItemCount(long count
)
2175 wxASSERT_MSG( IsVirtual(), _T("this is for virtual controls only") );
2179 m_genericImpl
->SetItemCount(count
);
2185 // we need to temporarily disable the new item creation notification
2186 // procedure to speed things up
2187 // FIXME: Even this doesn't seem to help much...
2189 // FIXME: Find a more efficient way to do this.
2190 m_dbImpl
->MacClear();
2192 DataBrowserCallbacks callbacks
;
2193 DataBrowserItemNotificationUPP itemUPP
;
2194 GetDataBrowserCallbacks(m_dbImpl
->GetControlRef(), &callbacks
);
2195 itemUPP
= callbacks
.u
.v1
.itemNotificationCallback
;
2196 callbacks
.u
.v1
.itemNotificationCallback
= 0;
2197 m_dbImpl
->SetCallbacks(&callbacks
);
2198 ::AddDataBrowserItems(m_dbImpl
->GetControlRef(), kDataBrowserNoItem
,
2199 count
, NULL
, kDataBrowserItemNoProperty
);
2200 callbacks
.u
.v1
.itemNotificationCallback
= itemUPP
;
2201 m_dbImpl
->SetCallbacks(&callbacks
);
2206 void wxListCtrl::RefreshItem(long item
)
2210 m_genericImpl
->RefreshItem(item
);
2215 GetItemRect(item
, rect
);
2219 void wxListCtrl::RefreshItems(long itemFrom
, long itemTo
)
2223 m_genericImpl
->RefreshItems(itemFrom
, itemTo
);
2227 wxRect rect1
, rect2
;
2228 GetItemRect(itemFrom
, rect1
);
2229 GetItemRect(itemTo
, rect2
);
2231 wxRect rect
= rect1
;
2232 rect
.height
= rect2
.GetBottom() - rect1
.GetTop();
2237 void wxListCtrl::SetDropTarget( wxDropTarget
*dropTarget
)
2239 #if wxUSE_DRAG_AND_DROP
2241 m_genericImpl
->SetDropTarget( dropTarget
);
2244 wxWindow::SetDropTarget( dropTarget
);
2248 wxDropTarget
*wxListCtrl::GetDropTarget() const
2250 #if wxUSE_DRAG_AND_DROP
2252 return m_genericImpl
->GetDropTarget();
2255 return wxWindow::GetDropTarget();
2260 #if wxABI_VERSION >= 20801
2261 void wxListCtrl::SetFocus()
2265 m_genericImpl
->SetFocus();
2269 wxWindow::SetFocus();
2273 // wxMac internal data structures
2275 wxMacListCtrlItem::~wxMacListCtrlItem()
2279 void wxMacListCtrlItem::Notification(wxMacDataItemBrowserControl
*owner
,
2280 DataBrowserItemNotification message
,
2281 DataBrowserItemDataRef itemData
) const
2284 wxMacDataBrowserListCtrlControl
*lb
= wxDynamicCast(owner
, wxMacDataBrowserListCtrlControl
);
2286 // we want to depend on as little as possible to make sure tear-down of controls is safe
2287 if ( message
== kDataBrowserItemRemoved
)
2289 if ( lb
!= NULL
&& lb
->GetClientDataType() == wxClientData_Object
)
2291 delete (wxClientData
*) (m_data
);
2297 else if ( message
== kDataBrowserItemAdded
)
2299 // we don't issue events on adding, the item is not really stored in the list yet, so we
2300 // avoid asserts by gettting out now
2304 wxListCtrl
*list
= wxDynamicCast( owner
->GetPeer() , wxListCtrl
);
2307 bool trigger
= false;
2309 wxListEvent
event( wxEVT_COMMAND_LIST_ITEM_SELECTED
, list
->GetId() );
2310 bool isSingle
= (list
->GetWindowStyle() & wxLC_SINGLE_SEL
) != 0;
2312 event
.SetEventObject( list
);
2313 event
.m_itemIndex
= owner
->GetLineFromItem( this ) ;
2314 if ( !list
->IsVirtual() )
2316 lb
->MacGetColumnInfo(event
.m_itemIndex
,0,event
.m_item
);
2321 case kDataBrowserItemDeselected
:
2322 event
.SetEventType(wxEVT_COMMAND_LIST_ITEM_DESELECTED
);
2324 trigger
= !lb
->IsSelectionSuppressed();
2327 case kDataBrowserItemSelected
:
2328 trigger
= !lb
->IsSelectionSuppressed();
2331 case kDataBrowserItemDoubleClicked
:
2332 event
.SetEventType( wxEVT_COMMAND_LIST_ITEM_ACTIVATED
);
2336 case kDataBrowserEditStarted
:
2337 // TODO : how to veto ?
2338 event
.SetEventType( wxEVT_COMMAND_LIST_BEGIN_LABEL_EDIT
) ;
2342 case kDataBrowserEditStopped
:
2343 // TODO probably trigger only upon the value store callback, because
2344 // here IIRC we cannot veto
2345 event
.SetEventType( wxEVT_COMMAND_LIST_END_LABEL_EDIT
) ;
2355 // direct notification is not always having the listbox GetSelection() having in synch with event
2356 wxPostEvent( list
->GetEventHandler(), event
);
2362 IMPLEMENT_DYNAMIC_CLASS(wxMacDataBrowserListCtrlControl
, wxMacDataItemBrowserControl
)
2364 wxMacDataBrowserListCtrlControl::wxMacDataBrowserListCtrlControl( wxWindow
*peer
, const wxPoint
& pos
, const wxSize
& size
, long style
)
2365 : wxMacDataItemBrowserControl( peer
, pos
, size
, style
)
2367 OSStatus err
= noErr
;
2368 m_clientDataItemsType
= wxClientData_None
;
2369 m_isVirtual
= false;
2371 if ( style
& wxLC_VIRTUAL
)
2374 DataBrowserSelectionFlags options
= kDataBrowserDragSelect
;
2375 if ( style
& wxLC_SINGLE_SEL
)
2377 options
|= kDataBrowserSelectOnlyOne
;
2381 options
|= kDataBrowserCmdTogglesSelection
;
2384 err
= SetSelectionFlags( options
);
2385 verify_noerr( err
);
2387 DataBrowserCustomCallbacks callbacks
;
2388 InitializeDataBrowserCustomCallbacks( &callbacks
, kDataBrowserLatestCustomCallbacks
);
2390 if ( gDataBrowserDrawItemUPP
== NULL
)
2391 gDataBrowserDrawItemUPP
= NewDataBrowserDrawItemUPP(DataBrowserDrawItemProc
);
2393 if ( gDataBrowserHitTestUPP
== NULL
)
2394 gDataBrowserHitTestUPP
= NewDataBrowserHitTestUPP(DataBrowserHitTestProc
);
2396 callbacks
.u
.v1
.drawItemCallback
= gDataBrowserDrawItemUPP
;
2397 callbacks
.u
.v1
.hitTestCallback
= gDataBrowserHitTestUPP
;
2399 SetDataBrowserCustomCallbacks( GetControlRef(), &callbacks
);
2401 if ( style
& wxLC_LIST
)
2403 InsertColumn(0, kDataBrowserIconAndTextType
, wxEmptyString
, -1, -1);
2404 verify_noerr( AutoSizeColumns() );
2407 if ( style
& wxLC_LIST
|| style
& wxLC_NO_HEADER
)
2408 verify_noerr( SetHeaderButtonHeight( 0 ) );
2411 SetSortProperty( kMinColumnId
- 1 );
2413 SetSortProperty( kMinColumnId
);
2415 m_sortOrder
= SortOrder_None
;
2417 if ( style
& wxLC_SORT_DESCENDING
)
2419 SetSortOrder( kDataBrowserOrderDecreasing
);
2421 else if ( style
& wxLC_SORT_ASCENDING
)
2423 SetSortOrder( kDataBrowserOrderIncreasing
);
2426 if ( style
& wxLC_VRULES
)
2428 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4
2429 verify_noerr( DataBrowserChangeAttributes(m_controlRef
, kDataBrowserAttributeListViewDrawColumnDividers
, kDataBrowserAttributeNone
) );
2433 verify_noerr( SetHiliteStyle(kDataBrowserTableViewFillHilite
) );
2434 err
= SetHasScrollBars( (style
& wxHSCROLL
) != 0 , (style
& wxVSCROLL
) != 0 );
2437 pascal Boolean
wxMacDataBrowserListCtrlControl::DataBrowserEditTextProc(
2439 DataBrowserItemID itemID
,
2440 DataBrowserPropertyID property
,
2441 CFStringRef theString
,
2442 Rect
*maxEditTextRect
,
2443 Boolean
*shrinkToFit
)
2445 Boolean result
= false;
2446 wxMacDataBrowserListCtrlControl
* ctl
= wxDynamicCast(wxMacControl::GetReferenceFromNativeControl( browser
), wxMacDataBrowserListCtrlControl
);
2449 result
= ctl
->ConfirmEditText(itemID
, property
, theString
, maxEditTextRect
, shrinkToFit
);
2450 theString
= CFSTR("Hello!");
2455 bool wxMacDataBrowserListCtrlControl::ConfirmEditText(
2456 DataBrowserItemID itemID
,
2457 DataBrowserPropertyID property
,
2458 CFStringRef theString
,
2459 Rect
*maxEditTextRect
,
2460 Boolean
*shrinkToFit
)
2465 pascal void wxMacDataBrowserListCtrlControl::DataBrowserDrawItemProc(
2467 DataBrowserItemID itemID
,
2468 DataBrowserPropertyID property
,
2469 DataBrowserItemState itemState
,
2470 const Rect
*itemRect
,
2472 Boolean colorDevice
)
2474 wxMacDataBrowserListCtrlControl
* ctl
= wxDynamicCast(wxMacControl::GetReferenceFromNativeControl( browser
), wxMacDataBrowserListCtrlControl
);
2477 ctl
->DrawItem(itemID
, property
, itemState
, itemRect
, gdDepth
, colorDevice
);
2481 // routines needed for DrawItem
2486 kTextBoxHeight
= 14,
2487 kIconTextSpacingV
= 2,
2489 kContentHeight
= kIconHeight
+ kTextBoxHeight
+ kIconTextSpacingV
2492 static void calculateCGDrawingBounds(CGRect inItemRect
, CGRect
*outIconRect
, CGRect
*outTextRect
, bool hasIcon
= false)
2495 float iconH
, iconW
= 0;
2496 float padding
= kItemPadding
;
2499 iconH
= kIconHeight
;
2501 padding
= padding
*2;
2504 textBottom
= inItemRect
.origin
.y
;
2506 *outIconRect
= CGRectMake(inItemRect
.origin
.x
+ kItemPadding
,
2507 textBottom
+ kIconTextSpacingV
, kIconWidth
,
2510 *outTextRect
= CGRectMake(inItemRect
.origin
.x
+ padding
+ iconW
,
2511 textBottom
+ kIconTextSpacingV
, inItemRect
.size
.width
- padding
- iconW
,
2512 inItemRect
.size
.height
- kIconTextSpacingV
);
2515 void wxMacDataBrowserListCtrlControl::DrawItem(
2516 DataBrowserItemID itemID
,
2517 DataBrowserPropertyID property
,
2518 DataBrowserItemState itemState
,
2519 const Rect
*itemRect
,
2521 Boolean colorDevice
)
2524 wxFont font
= wxNullFont
;
2526 short listColumn
= property
- kMinColumnId
;
2528 wxListCtrl
* list
= wxDynamicCast( GetPeer() , wxListCtrl
);
2529 wxMacListCtrlItem
* lcItem
;
2530 wxColour color
= *wxBLACK
;
2531 wxColour bgColor
= wxNullColour
;
2533 if (listColumn
>= 0)
2537 lcItem
= (wxMacListCtrlItem
*) itemID
;
2538 if (lcItem
->HasColumnInfo(listColumn
)){
2539 wxListItem
* item
= lcItem
->GetColumnInfo(listColumn
);
2541 // we always use the 0 column to get font and text/background colors.
2542 if (lcItem
->HasColumnInfo(0))
2544 wxListItem
* firstItem
= lcItem
->GetColumnInfo(0);
2545 color
= firstItem
->GetTextColour();
2546 bgColor
= firstItem
->GetBackgroundColour();
2547 font
= firstItem
->GetFont();
2550 if (item
->GetMask() & wxLIST_MASK_TEXT
)
2551 text
= item
->GetText();
2552 if (item
->GetMask() & wxLIST_MASK_IMAGE
)
2553 imgIndex
= item
->GetImage();
2559 text
= list
->OnGetItemText( (long)itemID
-1, listColumn
);
2560 imgIndex
= list
->OnGetItemColumnImage( (long)itemID
-1, listColumn
);
2561 wxListItemAttr
* attrs
= list
->OnGetItemAttr( (long)itemID
-1 );
2564 if (attrs
->HasBackgroundColour())
2565 bgColor
= attrs
->GetBackgroundColour();
2566 if (attrs
->HasTextColour())
2567 color
= attrs
->GetTextColour();
2568 if (attrs
->HasFont())
2569 font
= attrs
->GetFont();
2574 wxColour listBgColor
= list
->GetBackgroundColour();
2575 if (bgColor
== wxNullColour
)
2576 bgColor
= listBgColor
;
2578 wxFont listFont
= list
->GetFont();
2579 if (font
== wxNullFont
)
2582 wxMacCFStringHolder cfString
;
2583 cfString
.Assign( text
, wxLocale::GetSystemEncoding() );
2586 CGRect enclosingCGRect
, iconCGRect
, textCGRect
;
2588 ThemeDrawingState savedState
= NULL
;
2589 CGContextRef context
= (CGContextRef
)list
->MacGetDrawingContext();
2590 RGBColor labelColor
;
2592 labelColor
.green
= 0;
2593 labelColor
.blue
= 0;
2595 RGBColor backgroundColor
;
2596 backgroundColor
.red
= 255;
2597 backgroundColor
.green
= 255;
2598 backgroundColor
.blue
= 255;
2600 GetDataBrowserItemPartBounds(GetControlRef(), itemID
, property
, kDataBrowserPropertyEnclosingPart
,
2603 enclosingCGRect
= CGRectMake(enclosingRect
.left
,
2605 enclosingRect
.right
- enclosingRect
.left
,
2606 enclosingRect
.bottom
- enclosingRect
.top
);
2608 active
= IsControlActive(GetControlRef());
2610 // don't paint the background over the vertical rule line
2611 if ( list
->GetWindowStyleFlag() & wxLC_VRULES
)
2613 enclosingCGRect
.origin
.x
+= 1;
2614 enclosingCGRect
.size
.width
-= 1;
2616 if (itemState
== kDataBrowserItemIsSelected
)
2619 GetThemeDrawingState(&savedState
);
2621 GetThemeBrushAsColor(kThemeBrushAlternatePrimaryHighlightColor
, 32, true, &backgroundColor
);
2622 GetThemeTextColor(kThemeTextColorWhite
, gdDepth
, colorDevice
, &labelColor
);
2624 CGContextSaveGState(context
);
2626 CGContextSetRGBFillColor(context
, (float)backgroundColor
.red
/ (float)USHRT_MAX
,
2627 (float)backgroundColor
.green
/ (float)USHRT_MAX
,
2628 (float)backgroundColor
.blue
/ (float)USHRT_MAX
, 1.0);
2629 CGContextFillRect(context
, enclosingCGRect
);
2631 CGContextRestoreGState(context
);
2637 labelColor
= MAC_WXCOLORREF( color
.GetPixel() );
2638 else if (list
->GetTextColour().Ok())
2639 labelColor
= MAC_WXCOLORREF( list
->GetTextColour().GetPixel() );
2643 backgroundColor
= MAC_WXCOLORREF( bgColor
.GetPixel() );
2644 CGContextSaveGState(context
);
2646 CGContextSetRGBFillColor(context
, (float)backgroundColor
.red
/ (float)USHRT_MAX
,
2647 (float)backgroundColor
.green
/ (float)USHRT_MAX
,
2648 (float)backgroundColor
.blue
/ (float)USHRT_MAX
, 1.0);
2649 CGContextFillRect(context
, enclosingCGRect
);
2651 CGContextRestoreGState(context
);
2655 calculateCGDrawingBounds(enclosingCGRect
, &iconCGRect
, &textCGRect
, (imgIndex
!= -1) );
2659 wxImageList
* imageList
= list
->GetImageList(wxIMAGE_LIST_SMALL
);
2660 if (imageList
&& imageList
->GetImageCount() > 0){
2661 wxBitmap bmp
= imageList
->GetBitmap(imgIndex
);
2662 IconRef icon
= bmp
.GetBitmapData()->GetIconRef();
2664 CGContextSaveGState(context
);
2665 CGContextTranslateCTM(context
, 0,iconCGRect
.origin
.y
+ CGRectGetMaxY(iconCGRect
));
2666 CGContextScaleCTM(context
,1.0f
,-1.0f
);
2667 PlotIconRefInContext(context
, &iconCGRect
, kAlignNone
,
2668 active
? kTransformNone
: kTransformDisabled
, NULL
,
2669 kPlotIconRefNormalFlags
, icon
);
2671 CGContextRestoreGState(context
);
2675 HIThemeTextHorizontalFlush hFlush
= kHIThemeTextHorizontalFlushLeft
;
2676 UInt16 fontID
= kThemeViewsFont
;
2680 if (font
.GetFamily() != wxFONTFAMILY_DEFAULT
)
2681 fontID
= font
.MacGetThemeFontID();
2683 // FIXME: replace these with CG or ATSUI calls so we can remove this #ifndef.
2685 ::TextSize( (short)(font
.MacGetFontSize()) ) ;
2686 ::TextFace( font
.MacGetFontStyle() ) ;
2691 list
->GetColumn(listColumn
, item
);
2692 if (item
.GetMask() & wxLIST_MASK_FORMAT
)
2694 if (item
.GetAlign() == wxLIST_FORMAT_LEFT
)
2695 hFlush
= kHIThemeTextHorizontalFlushLeft
;
2696 else if (item
.GetAlign() == wxLIST_FORMAT_CENTER
)
2697 hFlush
= kHIThemeTextHorizontalFlushCenter
;
2698 else if (item
.GetAlign() == wxLIST_FORMAT_RIGHT
)
2700 hFlush
= kHIThemeTextHorizontalFlushRight
;
2701 textCGRect
.origin
.x
-= kItemPadding
; // give a little extra paddding
2705 HIThemeTextInfo info
;
2706 info
.version
= kHIThemeTextInfoVersionZero
;
2707 info
.state
= active
? kThemeStateActive
: kThemeStateInactive
;
2708 info
.fontID
= fontID
;
2709 info
.horizontalFlushness
= hFlush
;
2710 info
.verticalFlushness
= kHIThemeTextVerticalFlushCenter
;
2711 info
.options
= kHIThemeTextBoxOptionNone
;
2712 info
.truncationPosition
= kHIThemeTextTruncationEnd
;
2713 info
.truncationMaxLines
= 1;
2715 CGContextSaveGState(context
);
2716 CGContextSetRGBFillColor (context
, (float)labelColor
.red
/ (float)USHRT_MAX
,
2717 (float)labelColor
.green
/ (float)USHRT_MAX
,
2718 (float)labelColor
.blue
/ (float)USHRT_MAX
, 1.0);
2720 HIThemeDrawTextBox(cfString
, &textCGRect
, &info
, context
, kHIThemeOrientationNormal
);
2722 CGContextRestoreGState(context
);
2724 if (savedState
!= NULL
)
2725 SetThemeDrawingState(savedState
, true);
2728 OSStatus
wxMacDataBrowserListCtrlControl::GetSetItemData(DataBrowserItemID itemID
,
2729 DataBrowserPropertyID property
,
2730 DataBrowserItemDataRef itemData
,
2731 Boolean changeValue
)
2735 short listColumn
= property
- kMinColumnId
;
2737 OSStatus err
= errDataBrowserPropertyNotSupported
;
2738 wxListCtrl
* list
= wxDynamicCast( GetPeer() , wxListCtrl
);
2739 wxMacListCtrlItem
* lcItem
;
2741 if (listColumn
>= 0)
2745 lcItem
= (wxMacListCtrlItem
*) itemID
;
2746 if (lcItem
&& lcItem
->HasColumnInfo(listColumn
)){
2747 wxListItem
* item
= lcItem
->GetColumnInfo(listColumn
);
2748 if (item
->GetMask() & wxLIST_MASK_TEXT
)
2749 text
= item
->GetText();
2750 if (item
->GetMask() & wxLIST_MASK_IMAGE
)
2751 imgIndex
= item
->GetImage();
2756 text
= list
->OnGetItemText( (long)itemID
-1, listColumn
);
2757 imgIndex
= list
->OnGetItemColumnImage( (long)itemID
-1, listColumn
);
2765 case kDataBrowserItemIsEditableProperty
:
2766 if ( list
&& list
->HasFlag( wxLC_EDIT_LABELS
) )
2768 verify_noerr(SetDataBrowserItemDataBooleanValue( itemData
, true ));
2773 if ( property
>= kMinColumnId
)
2775 wxMacCFStringHolder cfStr
;
2778 cfStr
.Assign( text
, wxLocale::GetSystemEncoding() );
2779 err
= ::SetDataBrowserItemDataText( itemData
, cfStr
);
2785 if ( imgIndex
!= -1 )
2787 wxImageList
* imageList
= list
->GetImageList(wxIMAGE_LIST_SMALL
);
2788 if (imageList
&& imageList
->GetImageCount() > 0){
2789 wxBitmap bmp
= imageList
->GetBitmap(imgIndex
);
2790 IconRef icon
= bmp
.GetBitmapData()->GetIconRef();
2791 ::SetDataBrowserItemDataIcon(itemData
, icon
);
2805 if ( property
>= kMinColumnId
)
2807 short listColumn
= property
- kMinColumnId
;
2809 // TODO probably send the 'end edit' from here, as we
2810 // can then deal with the veto
2812 verify_noerr( GetDataBrowserItemDataText( itemData
, &sr
) ) ;
2813 wxMacCFStringHolder
cfStr(sr
) ;;
2815 list
->SetItem( (long)itemData
-1 , listColumn
, cfStr
.AsString() ) ;
2819 lcItem
->SetColumnTextValue( listColumn
, cfStr
.AsString() );
2829 void wxMacDataBrowserListCtrlControl::ItemNotification(DataBrowserItemID itemID
,
2830 DataBrowserItemNotification message
,
2831 DataBrowserItemDataRef itemData
)
2833 // we want to depend on as little as possible to make sure tear-down of controls is safe
2834 if ( message
== kDataBrowserItemRemoved
)
2836 // make sure MacDelete does the proper teardown.
2839 else if ( message
== kDataBrowserItemAdded
)
2841 // we don't issue events on adding, the item is not really stored in the list yet, so we
2842 // avoid asserts by getting out now
2846 wxListCtrl
*list
= wxDynamicCast( GetPeer() , wxListCtrl
);
2849 bool trigger
= false;
2851 wxListEvent
event( wxEVT_COMMAND_LIST_ITEM_SELECTED
, list
->GetId() );
2852 bool isSingle
= (list
->GetWindowStyle() & wxLC_SINGLE_SEL
) != 0;
2854 event
.SetEventObject( list
);
2855 if ( !list
->IsVirtual() )
2857 DataBrowserTableViewRowIndex result
= 0;
2858 verify_noerr( GetItemRow( itemID
, &result
) ) ;
2859 event
.m_itemIndex
= result
;
2861 if (event
.m_itemIndex
>= 0)
2862 MacGetColumnInfo(event
.m_itemIndex
,0,event
.m_item
);
2866 event
.m_itemIndex
= (long)itemID
-1;
2871 case kDataBrowserItemDeselected
:
2872 event
.SetEventType(wxEVT_COMMAND_LIST_ITEM_DESELECTED
);
2874 trigger
= !IsSelectionSuppressed();
2877 case kDataBrowserItemSelected
:
2878 trigger
= !IsSelectionSuppressed();
2882 case kDataBrowserItemDoubleClicked
:
2883 event
.SetEventType( wxEVT_COMMAND_LIST_ITEM_ACTIVATED
);
2887 case kDataBrowserEditStarted
:
2888 // TODO : how to veto ?
2889 event
.SetEventType( wxEVT_COMMAND_LIST_BEGIN_LABEL_EDIT
) ;
2893 case kDataBrowserEditStopped
:
2894 // TODO probably trigger only upon the value store callback, because
2895 // here IIRC we cannot veto
2896 event
.SetEventType( wxEVT_COMMAND_LIST_END_LABEL_EDIT
) ;
2906 // direct notification is not always having the listbox GetSelection() having in synch with event
2907 wxPostEvent( list
->GetEventHandler(), event
);
2912 Boolean
wxMacDataBrowserListCtrlControl::CompareItems(DataBrowserItemID itemOneID
,
2913 DataBrowserItemID itemTwoID
,
2914 DataBrowserPropertyID sortProperty
)
2917 bool retval
= false;
2919 wxString otherItemText
;
2921 long otherItemOrder
;
2923 int colId
= sortProperty
- kMinColumnId
;
2925 wxListCtrl
* list
= wxDynamicCast( GetPeer() , wxListCtrl
);
2927 DataBrowserSortOrder sort
;
2928 verify_noerr(GetSortOrder(&sort
));
2934 wxMacListCtrlItem
* item
= (wxMacListCtrlItem
*)itemOneID
;
2935 wxMacListCtrlItem
* otherItem
= (wxMacListCtrlItem
*)itemTwoID
;
2937 itemOrder
= item
->GetOrder();
2938 otherItemOrder
= item
->GetOrder();
2940 wxListCtrlCompare func
= list
->GetCompareFunc();
2945 if (item
&& item
->HasColumnInfo(0))
2946 item1
= item
->GetColumnInfo(0)->GetData();
2947 if (otherItem
&& otherItem
->HasColumnInfo(0))
2948 item2
= otherItem
->GetColumnInfo(0)->GetData();
2950 if (item1
> -1 && item2
> -1)
2952 int result
= func(item1
, item2
, list
->GetCompareFuncData());
2953 if (sort
== kDataBrowserOrderIncreasing
)
2960 // we can't use the native control's sorting abilities, so just
2962 return itemOrder
< otherItemOrder
;
2967 long itemNum
= (long)itemOneID
;
2968 long otherItemNum
= (long)itemTwoID
;
2969 itemText
= list
->OnGetItemText( itemNum
-1, colId
);
2970 otherItemText
= list
->OnGetItemText( otherItemNum
-1, colId
);
2972 // virtual listctrls don't support sorting
2973 return itemNum
< otherItemNum
;
2977 // fallback for undefined cases
2978 retval
= itemOneID
< itemTwoID
;
2984 wxMacDataBrowserListCtrlControl::~wxMacDataBrowserListCtrlControl()
2988 void wxMacDataBrowserListCtrlControl::MacSetColumnInfo( unsigned int row
, unsigned int column
, wxListItem
* item
)
2990 wxMacDataItem
* dataItem
= GetItemFromLine(row
);
2991 wxASSERT_MSG( dataItem
, _T("could not obtain wxMacDataItem for row in MacSetColumnInfo. Is row a valid wxListCtrl row?") );
2994 wxMacListCtrlItem
* listItem
= wx_static_cast(wxMacListCtrlItem
*,dataItem
);
2995 bool hasInfo
= listItem
->HasColumnInfo( column
);
2996 listItem
->SetColumnInfo( column
, item
);
2997 listItem
->SetOrder(row
);
2998 UpdateState(dataItem
, item
);
3000 wxListCtrl
* list
= wxDynamicCast( GetPeer() , wxListCtrl
);
3002 // NB: When this call was made before a control was completely shown, it would
3003 // update the item prematurely (i.e. no text would be listed) and, on show,
3004 // only the sorted column would be refreshed, meaning only first column text labels
3005 // would be shown. Making sure not to update items until the control is visible
3006 // seems to fix this issue.
3007 if (hasInfo
&& list
->IsShown())
3008 UpdateItem( wxMacDataBrowserRootContainer
, listItem
, kMinColumnId
+ column
);
3012 // apply changes that need to happen immediately, rather than when the
3013 // databrowser control fires a callback.
3014 void wxMacDataBrowserListCtrlControl::UpdateState(wxMacDataItem
* dataItem
, wxListItem
* listItem
)
3016 bool isSelected
= IsItemSelected( dataItem
);
3017 bool isSelectedState
= (listItem
->GetState() == wxLIST_STATE_SELECTED
);
3019 // toggle the selection state if wxListInfo state and actual state don't match.
3020 if ( isSelected
!= isSelectedState
)
3022 DataBrowserSetOption options
= kDataBrowserItemsAdd
;
3023 if (!isSelectedState
)
3024 options
= kDataBrowserItemsRemove
;
3025 SetSelectedItem(dataItem
, options
);
3027 // TODO: Set column width if item width > than current column width
3030 void wxMacDataBrowserListCtrlControl::MacGetColumnInfo( unsigned int row
, unsigned int column
, wxListItem
& item
)
3032 wxMacDataItem
* dataItem
= GetItemFromLine(row
);
3033 wxASSERT_MSG( dataItem
, _T("could not obtain wxMacDataItem in MacGetColumnInfo. Is row a valid wxListCtrl row?") );
3034 // CS should this guard against dataItem = 0 ? , as item is not a pointer if (item) is not appropriate
3037 wxMacListCtrlItem
* listItem
=wx_static_cast(wxMacListCtrlItem
*,dataItem
);
3039 if (!listItem
->HasColumnInfo( column
))
3042 wxListItem
* oldItem
= listItem
->GetColumnInfo( column
);
3046 long mask
= item
.GetMask();
3048 // by default, get everything for backwards compatibility
3051 if ( mask
& wxLIST_MASK_TEXT
)
3052 item
.SetText(oldItem
->GetText());
3053 if ( mask
& wxLIST_MASK_IMAGE
)
3054 item
.SetImage(oldItem
->GetImage());
3055 if ( mask
& wxLIST_MASK_DATA
)
3056 item
.SetData(oldItem
->GetData());
3057 if ( mask
& wxLIST_MASK_STATE
)
3058 item
.SetState(oldItem
->GetState());
3059 if ( mask
& wxLIST_MASK_WIDTH
)
3060 item
.SetWidth(oldItem
->GetWidth());
3061 if ( mask
& wxLIST_MASK_FORMAT
)
3062 item
.SetAlign(oldItem
->GetAlign());
3064 item
.SetTextColour(oldItem
->GetTextColour());
3065 item
.SetBackgroundColour(oldItem
->GetBackgroundColour());
3066 item
.SetFont(oldItem
->GetFont());
3071 void wxMacDataBrowserListCtrlControl::MacInsertItem( unsigned int n
, wxListItem
* item
)
3073 wxMacDataItemBrowserControl::MacInsert(n
, item
->GetText());
3074 MacSetColumnInfo(n
, 0, item
);
3077 wxMacDataItem
* wxMacDataBrowserListCtrlControl::CreateItem()
3079 return new wxMacListCtrlItem();
3082 wxMacListCtrlItem::wxMacListCtrlItem()
3084 m_rowItems
= wxListItemList();
3087 int wxMacListCtrlItem::GetColumnImageValue( unsigned int column
)
3089 if ( HasColumnInfo(column
) )
3090 return GetColumnInfo(column
)->GetImage();
3095 void wxMacListCtrlItem::SetColumnImageValue( unsigned int column
, int imageIndex
)
3097 if ( HasColumnInfo(column
) )
3098 GetColumnInfo(column
)->SetImage(imageIndex
);
3101 wxString
wxMacListCtrlItem::GetColumnTextValue( unsigned int column
)
3106 if ( HasColumnInfo(column
) )
3107 return GetColumnInfo(column
)->GetText();
3109 return wxEmptyString
;
3112 void wxMacListCtrlItem::SetColumnTextValue( unsigned int column
, const wxString
& text
)
3114 if ( HasColumnInfo(column
) )
3115 GetColumnInfo(column
)->SetText(text
);
3117 // for compatibility with superclass APIs
3122 wxListItem
* wxMacListCtrlItem::GetColumnInfo( unsigned int column
)
3124 wxASSERT_MSG( HasColumnInfo(column
), _T("invalid column index in wxMacListCtrlItem") );
3125 return m_rowItems
[column
];
3128 bool wxMacListCtrlItem::HasColumnInfo( unsigned int column
)
3130 return !(m_rowItems
.find( column
) == m_rowItems
.end());
3133 void wxMacListCtrlItem::SetColumnInfo( unsigned int column
, wxListItem
* item
)
3136 if ( !HasColumnInfo(column
) )
3138 wxListItem
* listItem
= new wxListItem(*item
);
3139 m_rowItems
[column
] = listItem
;
3143 wxListItem
* listItem
= GetColumnInfo( column
);
3144 long mask
= item
->GetMask();
3145 if (mask
& wxLIST_MASK_TEXT
)
3146 listItem
->SetText(item
->GetText());
3147 if (mask
& wxLIST_MASK_DATA
)
3148 listItem
->SetData(item
->GetData());
3149 if (mask
& wxLIST_MASK_IMAGE
)
3150 listItem
->SetImage(item
->GetImage());
3151 if (mask
& wxLIST_MASK_STATE
)
3152 listItem
->SetState(item
->GetState());
3153 if (mask
& wxLIST_MASK_FORMAT
)
3154 listItem
->SetAlign(item
->GetAlign());
3155 if (mask
& wxLIST_MASK_WIDTH
)
3156 listItem
->SetWidth(item
->GetWidth());
3158 if ( item
->HasAttributes() )
3160 if ( listItem
->HasAttributes() )
3161 listItem
->GetAttributes()->AssignFrom(*item
->GetAttributes());
3164 listItem
->SetTextColour(item
->GetTextColour());
3165 listItem
->SetBackgroundColour(item
->GetBackgroundColour());
3166 listItem
->SetFont(item
->GetFont());
3172 #endif // wxUSE_LISTCTRL