1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/osx/listctrl_mac.cpp
4 // Author: Julian Smart
5 // Modified by: Agron Selimaj
7 // Copyright: (c) Julian Smart
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
11 // ============================================================================
13 // ============================================================================
15 // ----------------------------------------------------------------------------
17 // ----------------------------------------------------------------------------
19 // For compilers that support precompilation, includes "wx.h".
20 #include "wx/wxprec.h"
28 #include "wx/listctrl.h"
32 #include "wx/settings.h"
35 #include "wx/osx/uma.h"
37 #include "wx/imaglist.h"
38 #include "wx/sysopt.h"
41 #include "wx/hashmap.h"
43 WX_DECLARE_HASH_MAP( int, wxListItem
*, wxIntegerHash
, wxIntegerEqual
, wxListItemList
);
45 #include "wx/listimpl.cpp"
46 WX_DEFINE_LIST(wxColumnList
)
48 // so we can check for column clicks
49 static const EventTypeSpec eventList
[] =
51 { kEventClassControl
, kEventControlHit
},
52 { kEventClassControl
, kEventControlDraw
}
55 static pascal OSStatus
wxMacListCtrlEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
57 OSStatus result
= eventNotHandledErr
;
59 wxMacCarbonEvent
cEvent( event
) ;
61 ControlRef controlRef
;
62 cEvent
.GetParameter( kEventParamDirectObject
, &controlRef
) ;
64 wxListCtrl
*window
= (wxListCtrl
*) data
;
65 wxListEvent
le( wxEVT_LIST_COL_CLICK
, window
->GetId() );
66 le
.SetEventObject( window
);
68 switch ( GetEventKind( event
) )
70 // check if the column was clicked on and fire an event if so
71 case kEventControlHit
:
73 ControlPartCode result
= cEvent
.GetParameter
<ControlPartCode
>(kEventParamControlPart
, typeControlPartCode
) ;
74 if (result
== kControlButtonPart
){
75 DataBrowserPropertyID col
;
76 GetDataBrowserSortProperty(controlRef
, &col
);
78 DataBrowserTableViewColumnIndex column
= 0;
79 verify_noerr( GetDataBrowserTableViewColumnPosition( controlRef
, col
, &column
) );
82 // FIXME: we can't use the sort property for virtual listctrls
83 // so we need to find a better way to determine which column was clicked...
84 if (!window
->IsVirtual())
85 window
->HandleWindowEvent( le
);
87 result
= CallNextEventHandler(handler
, event
);
90 case kEventControlDraw
:
92 CGContextRef context
= cEvent
.GetParameter
<CGContextRef
>(kEventParamCGContextRef
, typeCGContextRef
) ;
93 window
->MacSetDrawingContext(context
);
94 result
= CallNextEventHandler(handler
, event
);
95 window
->MacSetDrawingContext(NULL
);
106 DEFINE_ONE_SHOT_HANDLER_GETTER( wxMacListCtrlEventHandler
)
108 class wxMacListCtrlItem
: public wxMacDataItem
113 virtual void Notification(wxMacDataItemBrowserControl
*owner
,
114 DataBrowserItemNotification message
,
115 DataBrowserItemDataRef itemData
) const;
117 virtual void SetColumnInfo( unsigned int column
, wxListItem
* item
);
118 virtual wxListItem
* GetColumnInfo( unsigned int column
);
119 virtual bool HasColumnInfo( unsigned int column
);
121 virtual void SetColumnTextValue( unsigned int column
, const wxString
& text
);
122 virtual wxString
GetColumnTextValue( unsigned int column
);
124 virtual int GetColumnImageValue( unsigned int column
);
125 virtual void SetColumnImageValue( unsigned int column
, int imageIndex
);
127 virtual ~wxMacListCtrlItem();
129 wxListItemList m_rowItems
;
132 DataBrowserDrawItemUPP gDataBrowserDrawItemUPP
= NULL
;
133 //DataBrowserEditItemUPP gDataBrowserEditItemUPP = NULL;
134 DataBrowserHitTestUPP gDataBrowserHitTestUPP
= NULL
;
136 // TODO: Make a better name!!
137 class wxMacDataBrowserListCtrlControl
: public wxMacDataItemBrowserControl
140 wxMacDataBrowserListCtrlControl( wxWindow
*peer
, const wxPoint
& pos
, const wxSize
& size
, long style
);
141 wxMacDataBrowserListCtrlControl() {}
142 virtual ~wxMacDataBrowserListCtrlControl();
144 // create a list item (can be a subclass of wxMacListBoxItem)
146 virtual void MacInsertItem( unsigned int n
, wxListItem
* item
);
147 virtual void MacSetColumnInfo( unsigned int row
, unsigned int column
, wxListItem
* item
);
148 virtual void MacGetColumnInfo( unsigned int row
, unsigned int column
, wxListItem
& item
);
149 virtual void UpdateState(wxMacDataItem
* dataItem
, wxListItem
* item
);
150 int GetFlags() { return m_flags
; }
153 // we need to override to provide specialized handling for virtual wxListCtrls
154 virtual OSStatus
GetSetItemData(DataBrowserItemID itemID
,
155 DataBrowserPropertyID property
,
156 DataBrowserItemDataRef itemData
,
157 Boolean changeValue
);
159 virtual void ItemNotification(
160 DataBrowserItemID itemID
,
161 DataBrowserItemNotification message
,
162 DataBrowserItemDataRef itemData
);
164 virtual Boolean
CompareItems(DataBrowserItemID itemOneID
,
165 DataBrowserItemID itemTwoID
,
166 DataBrowserPropertyID sortProperty
);
168 static pascal void DataBrowserDrawItemProc(ControlRef browser
,
169 DataBrowserItemID item
,
170 DataBrowserPropertyID property
,
171 DataBrowserItemState itemState
,
174 Boolean colorDevice
);
176 virtual void DrawItem(DataBrowserItemID itemID
,
177 DataBrowserPropertyID property
,
178 DataBrowserItemState itemState
,
179 const Rect
*itemRect
,
181 Boolean colorDevice
);
183 static pascal Boolean
DataBrowserEditTextProc(ControlRef browser
,
184 DataBrowserItemID item
,
185 DataBrowserPropertyID property
,
186 CFStringRef theString
,
187 Rect
*maxEditTextRect
,
188 Boolean
*shrinkToFit
);
190 static pascal Boolean
DataBrowserHitTestProc(ControlRef
WXUNUSED(browser
),
191 DataBrowserItemID
WXUNUSED(itemID
),
192 DataBrowserPropertyID
WXUNUSED(property
),
193 const Rect
*WXUNUSED(theRect
),
194 const Rect
*WXUNUSED(mouseRect
)) { return true; }
196 virtual bool ConfirmEditText(DataBrowserItemID item
,
197 DataBrowserPropertyID property
,
198 CFStringRef theString
,
199 Rect
*maxEditTextRect
,
200 Boolean
*shrinkToFit
);
204 wxClientDataType m_clientDataItemsType
;
207 DECLARE_DYNAMIC_CLASS_NO_COPY(wxMacDataBrowserListCtrlControl
)
210 class wxMacListCtrlEventDelegate
: public wxEvtHandler
213 wxMacListCtrlEventDelegate( wxListCtrl
* list
, int id
);
214 virtual bool ProcessEvent( wxEvent
& event
);
221 wxMacListCtrlEventDelegate::wxMacListCtrlEventDelegate( wxListCtrl
* list
, int id
)
227 bool wxMacListCtrlEventDelegate::ProcessEvent( wxEvent
& event
)
229 int id
= event
.GetId();
230 wxObject
* obj
= event
.GetEventObject();
232 // even though we use a generic list ctrl underneath, make sure
233 // we present ourselves as wxListCtrl.
234 event
.SetEventObject( m_list
);
237 if ( !event
.IsKindOf( CLASSINFO( wxCommandEvent
) ) )
239 if (m_list
->GetEventHandler()->ProcessEvent( event
))
242 event
.SetEventObject(obj
);
246 // Also try with the original id
247 bool success
= wxEvtHandler::ProcessEvent(event
);
249 event
.SetEventObject(obj
);
250 if (!success
&& id
!= m_id
)
251 success
= wxEvtHandler::ProcessEvent(event
);
255 //-----------------------------------------------------------------------------
256 // wxListCtrlRenameTimer (internal)
257 //-----------------------------------------------------------------------------
259 class wxListCtrlRenameTimer
: public wxTimer
265 wxListCtrlRenameTimer( wxListCtrl
*owner
);
269 //-----------------------------------------------------------------------------
270 // wxListCtrlTextCtrlWrapper: wraps a wxTextCtrl to make it work for inline editing
271 //-----------------------------------------------------------------------------
273 class wxListCtrlTextCtrlWrapper
: public wxEvtHandler
276 // NB: text must be a valid object but not Create()d yet
277 wxListCtrlTextCtrlWrapper(wxListCtrl
*owner
,
281 wxTextCtrl
*GetText() const { return m_text
; }
283 void AcceptChangesAndFinish();
286 void OnChar( wxKeyEvent
&event
);
287 void OnKeyUp( wxKeyEvent
&event
);
288 void OnKillFocus( wxFocusEvent
&event
);
290 bool AcceptChanges();
296 wxString m_startValue
;
299 bool m_aboutToFinish
;
301 DECLARE_EVENT_TABLE()
304 //-----------------------------------------------------------------------------
305 // wxListCtrlRenameTimer (internal)
306 //-----------------------------------------------------------------------------
308 wxListCtrlRenameTimer::wxListCtrlRenameTimer( wxListCtrl
*owner
)
313 void wxListCtrlRenameTimer::Notify()
315 m_owner
->OnRenameTimer();
318 //-----------------------------------------------------------------------------
319 // wxListCtrlTextCtrlWrapper (internal)
320 //-----------------------------------------------------------------------------
322 BEGIN_EVENT_TABLE(wxListCtrlTextCtrlWrapper
, wxEvtHandler
)
323 EVT_CHAR (wxListCtrlTextCtrlWrapper::OnChar
)
324 EVT_KEY_UP (wxListCtrlTextCtrlWrapper::OnKeyUp
)
325 EVT_KILL_FOCUS (wxListCtrlTextCtrlWrapper::OnKillFocus
)
328 wxListCtrlTextCtrlWrapper::wxListCtrlTextCtrlWrapper(wxListCtrl
*owner
,
331 : m_startValue(owner
->GetItemText(itemEdit
)),
332 m_itemEdited(itemEdit
)
337 m_aboutToFinish
= false;
341 owner
->GetItemRect(itemEdit
, rectLabel
);
343 m_text
->Create(owner
, wxID_ANY
, m_startValue
,
344 wxPoint(rectLabel
.x
+offset
,rectLabel
.y
),
345 wxSize(rectLabel
.width
-offset
,rectLabel
.height
));
348 m_text
->PushEventHandler(this);
351 void wxListCtrlTextCtrlWrapper::Finish()
357 m_text
->RemoveEventHandler(this);
358 m_owner
->FinishEditing(m_text
);
360 wxPendingDelete
.Append( this );
364 bool wxListCtrlTextCtrlWrapper::AcceptChanges()
366 const wxString value
= m_text
->GetValue();
368 if ( value
== m_startValue
)
369 // nothing changed, always accept
372 if ( !m_owner
->OnRenameAccept(m_itemEdited
, value
) )
373 // vetoed by the user
376 // accepted, do rename the item
377 m_owner
->SetItemText(m_itemEdited
, value
);
382 void wxListCtrlTextCtrlWrapper::AcceptChangesAndFinish()
384 m_aboutToFinish
= true;
386 // Notify the owner about the changes
389 // Even if vetoed, close the control (consistent with MSW)
393 void wxListCtrlTextCtrlWrapper::OnChar( wxKeyEvent
&event
)
395 switch ( event
.m_keyCode
)
398 AcceptChangesAndFinish();
402 m_owner
->OnRenameCancelled( m_itemEdited
);
411 void wxListCtrlTextCtrlWrapper::OnKeyUp( wxKeyEvent
&event
)
419 // auto-grow the textctrl:
420 wxSize parentSize
= m_owner
->GetSize();
421 wxPoint myPos
= m_text
->GetPosition();
422 wxSize mySize
= m_text
->GetSize();
424 m_text
->GetTextExtent(m_text
->GetValue() + wxT("MM"), &sx
, &sy
);
425 if (myPos
.x
+ sx
> parentSize
.x
)
426 sx
= parentSize
.x
- myPos
.x
;
429 m_text
->SetSize(sx
, wxDefaultCoord
);
434 void wxListCtrlTextCtrlWrapper::OnKillFocus( wxFocusEvent
&event
)
436 if ( !m_finished
&& !m_aboutToFinish
)
438 if ( !AcceptChanges() )
439 m_owner
->OnRenameCancelled( m_itemEdited
);
444 // We must let the native text control handle focus
448 // ============================================================================
450 // ============================================================================
452 wxMacDataBrowserListCtrlControl
* wxListCtrl::GetListPeer() const
454 return dynamic_cast<wxMacDataBrowserListCtrlControl
*> ( GetPeer() );
457 // ----------------------------------------------------------------------------
458 // wxListCtrl construction
459 // ----------------------------------------------------------------------------
461 void wxListCtrl::Init()
463 m_imageListNormal
= NULL
;
464 m_imageListSmall
= NULL
;
465 m_imageListState
= NULL
;
467 // keep track of if we created our own image lists, or if they were assigned
469 m_ownsImageListNormal
= m_ownsImageListSmall
= m_ownsImageListState
= false;
473 m_genericImpl
= NULL
;
475 m_compareFunc
= NULL
;
476 m_compareFuncData
= 0;
477 m_colsInfo
= wxColumnList();
478 m_textColor
= wxNullColour
;
479 m_bgColor
= wxNullColour
;
480 m_textctrlWrapper
= NULL
;
482 m_renameTimer
= NULL
;
485 class wxGenericListCtrlHook
: public wxGenericListCtrl
488 wxGenericListCtrlHook(wxListCtrl
* parent
,
493 const wxValidator
& validator
,
494 const wxString
& name
)
495 : wxGenericListCtrl(parent
, id
, pos
, size
, style
, validator
, name
),
496 m_nativeListCtrl(parent
)
501 virtual wxListItemAttr
* OnGetItemAttr(long item
) const
503 return m_nativeListCtrl
->OnGetItemAttr(item
);
506 virtual int OnGetItemImage(long item
) const
508 return m_nativeListCtrl
->OnGetItemImage(item
);
511 virtual int OnGetItemColumnImage(long item
, long column
) const
513 return m_nativeListCtrl
->OnGetItemColumnImage(item
, column
);
516 virtual wxString
OnGetItemText(long item
, long column
) const
518 return m_nativeListCtrl
->OnGetItemText(item
, column
);
521 wxListCtrl
* m_nativeListCtrl
;
525 void wxListCtrl::OnLeftDown(wxMouseEvent
& event
)
527 if ( m_textctrlWrapper
)
530 m_textctrlWrapper
->AcceptChangesAndFinish();
534 long current
= HitTest(event
.GetPosition(), hitResult
);
535 if ((current
== m_current
) &&
536 (hitResult
& wxLIST_HITTEST_ONITEMLABEL
) &&
537 HasFlag(wxLC_EDIT_LABELS
) )
540 m_renameTimer
->Start( 250, true );
549 void wxListCtrl::OnDblClick(wxMouseEvent
& event
)
551 if ( m_renameTimer
&& m_renameTimer
->IsRunning() )
552 m_renameTimer
->Stop();
556 #if wxABI_VERSION >= 20801
557 void wxListCtrl::OnRightDown(wxMouseEvent
& event
)
560 FireMouseEvent(wxEVT_LIST_ITEM_RIGHT_CLICK
, event
.GetPosition());
564 void wxListCtrl::OnMiddleDown(wxMouseEvent
& event
)
567 FireMouseEvent(wxEVT_LIST_ITEM_MIDDLE_CLICK
, event
.GetPosition());
571 void wxListCtrl::FireMouseEvent(wxEventType eventType
, wxPoint position
)
573 wxListEvent
le( eventType
, GetId() );
574 le
.SetEventObject(this);
575 le
.m_pointDrag
= position
;
579 long item
= HitTest(position
, flags
);
580 if (flags
& wxLIST_HITTEST_ONITEM
)
582 le
.m_itemIndex
= item
;
583 le
.m_item
.m_itemId
= item
;
585 HandleWindowEvent(le
);
589 void wxListCtrl::OnChar(wxKeyEvent
& event
)
595 wxListEvent
le( wxEVT_LIST_KEY_DOWN
, GetId() );
596 le
.SetEventObject(this);
597 le
.m_code
= event
.GetKeyCode();
602 // if m_current isn't set, check if there's been a selection
603 // made before continuing
604 m_current
= GetNextItem(-1, wxLIST_NEXT_BELOW
, wxLIST_STATE_SELECTED
);
607 // We need to determine m_current ourselves when navigation keys
608 // are used. Note that PAGEUP and PAGEDOWN do not alter the current
609 // item on native Mac ListCtrl, so we only handle up and down keys.
610 switch ( event
.GetKeyCode() )
621 if ( m_current
< GetItemCount() - 1 )
624 m_current
= GetItemCount() - 1;
631 le
.m_itemIndex
= m_current
;
632 le
.m_item
.m_itemId
= m_current
;
634 HandleWindowEvent(le
);
641 bool wxListCtrl::Create(wxWindow
*parent
,
646 const wxValidator
& validator
,
647 const wxString
& name
)
650 // for now, we'll always use the generic list control for ICON and LIST views,
651 // because they dynamically change the number of columns on resize.
652 // Also, allow the user to set it to use the list ctrl as well.
653 if ( (wxSystemOptions::HasOption( wxMAC_ALWAYS_USE_GENERIC_LISTCTRL
)
654 && (wxSystemOptions::GetOptionInt( wxMAC_ALWAYS_USE_GENERIC_LISTCTRL
) == 1)) ||
655 (style
& wxLC_ICON
) || (style
& wxLC_SMALL_ICON
) || (style
& wxLC_LIST
) )
657 long paneStyle
= style
;
658 paneStyle
&= ~wxSIMPLE_BORDER
;
659 paneStyle
&= ~wxDOUBLE_BORDER
;
660 paneStyle
&= ~wxSUNKEN_BORDER
;
661 paneStyle
&= ~wxRAISED_BORDER
;
662 paneStyle
&= ~wxSTATIC_BORDER
;
663 if ( !wxWindow::Create(parent
, id
, pos
, size
, paneStyle
| wxNO_BORDER
, name
) )
666 // since the generic control is a child, make sure we position it at 0, 0
667 m_genericImpl
= new wxGenericListCtrlHook(this, id
, wxPoint(0, 0), size
, style
, validator
, name
);
668 m_genericImpl
->PushEventHandler( new wxMacListCtrlEventDelegate( this, GetId() ) );
675 if ( !wxWindow::Create(parent
, id
, pos
, size
, style
& ~(wxHSCROLL
| wxVSCROLL
), name
) )
677 m_dbImpl
= new wxMacDataBrowserListCtrlControl( this, pos
, size
, style
);
680 MacPostControlCreate( pos
, size
);
682 InstallControlEventHandler( GetPeer()->GetControlRef() , GetwxMacListCtrlEventHandlerUPP(),
683 GetEventTypeCount(eventList
), eventList
, this,
684 (EventHandlerRef
*)&m_macListCtrlEventHandler
);
686 m_renameTimer
= new wxListCtrlRenameTimer( this );
688 Connect( wxID_ANY
, wxEVT_CHAR
, wxCharEventHandler(wxListCtrl::OnChar
), NULL
, this );
689 Connect( wxID_ANY
, wxEVT_LEFT_DOWN
, wxMouseEventHandler(wxListCtrl::OnLeftDown
), NULL
, this );
690 Connect( wxID_ANY
, wxEVT_LEFT_DCLICK
, wxMouseEventHandler(wxListCtrl::OnDblClick
), NULL
, this );
691 Connect( wxID_ANY
, wxEVT_MIDDLE_DOWN
, wxMouseEventHandler(wxListCtrl::OnMiddleDown
), NULL
, this );
692 Connect( wxID_ANY
, wxEVT_RIGHT_DOWN
, wxMouseEventHandler(wxListCtrl::OnRightDown
), NULL
, this );
698 wxListCtrl::~wxListCtrl()
702 m_genericImpl
->PopEventHandler(/* deleteHandler = */ true);
705 if (m_ownsImageListNormal
)
706 delete m_imageListNormal
;
707 if (m_ownsImageListSmall
)
708 delete m_imageListSmall
;
709 if (m_ownsImageListState
)
710 delete m_imageListState
;
712 delete m_renameTimer
;
714 WX_CLEAR_LIST(wxColumnList
, m_colsInfo
);
719 wxListCtrl::GetClassDefaultAttributes(wxWindowVariant
WXUNUSED(variant
))
721 wxVisualAttributes attr
;
723 attr
.colFg
= wxSystemSettings::GetColour( wxSYS_COLOUR_WINDOWTEXT
);
724 attr
.colBg
= wxSystemSettings::GetColour( wxSYS_COLOUR_LISTBOX
);
725 static wxFont font
= wxFont(wxOSX_SYSTEM_FONT_VIEWS
);
731 // ----------------------------------------------------------------------------
732 // set/get/change style
733 // ----------------------------------------------------------------------------
735 // Add or remove a single window style
736 void wxListCtrl::SetSingleStyle(long style
, bool add
)
738 long flag
= GetWindowStyleFlag();
740 // Get rid of conflicting styles
743 if ( style
& wxLC_MASK_TYPE
)
744 flag
= flag
& ~wxLC_MASK_TYPE
;
745 if ( style
& wxLC_MASK_ALIGN
)
746 flag
= flag
& ~wxLC_MASK_ALIGN
;
747 if ( style
& wxLC_MASK_SORT
)
748 flag
= flag
& ~wxLC_MASK_SORT
;
756 SetWindowStyleFlag(flag
);
759 // Set the whole window style
760 void wxListCtrl::SetWindowStyleFlag(long flag
)
762 if ( flag
!= m_windowStyle
)
764 m_windowStyle
= flag
;
768 m_genericImpl
->SetWindowStyleFlag(flag
);
775 void wxListCtrl::DoSetSize( int x
, int y
, int width
, int height
, int sizeFlags
)
777 wxListCtrlBase::DoSetSize(x
, y
, width
, height
, sizeFlags
);
780 m_genericImpl
->SetSize(0, 0, width
, height
, sizeFlags
);
782 // determine if we need a horizontal scrollbar, and add it if so
786 for (int column
= 0; column
< GetColumnCount(); column
++)
788 totalWidth
+= m_dbImpl
->GetColumnWidth( column
);
791 if ( !(m_dbImpl
->GetFlags() & wxHSCROLL
) )
793 Boolean vertScrollBar
;
794 GetDataBrowserHasScrollBars( m_dbImpl
->GetControlRef(), NULL
, &vertScrollBar
);
795 if (totalWidth
> width
)
796 SetDataBrowserHasScrollBars( m_dbImpl
->GetControlRef(), true, vertScrollBar
);
798 SetDataBrowserHasScrollBars( m_dbImpl
->GetControlRef(), false, vertScrollBar
);
803 bool wxListCtrl::SetFont(const wxFont
& font
)
805 bool rv
= wxListCtrlBase::SetFont(font
);
807 rv
= m_genericImpl
->SetFont(font
);
811 bool wxListCtrl::SetForegroundColour(const wxColour
& colour
)
815 rv
= m_genericImpl
->SetForegroundColour(colour
);
817 SetTextColour(colour
);
821 bool wxListCtrl::SetBackgroundColour(const wxColour
& colour
)
825 rv
= m_genericImpl
->SetBackgroundColour(colour
);
831 wxColour
wxListCtrl::GetBackgroundColour() const
834 return m_genericImpl
->GetBackgroundColour();
841 void wxListCtrl::Freeze ()
844 m_genericImpl
->Freeze();
845 wxListCtrlBase::Freeze();
848 void wxListCtrl::Thaw ()
851 m_genericImpl
->Thaw();
852 wxListCtrlBase::Thaw();
855 void wxListCtrl::Update ()
858 m_genericImpl
->Update();
859 wxListCtrlBase::Update();
862 // ----------------------------------------------------------------------------
864 // ----------------------------------------------------------------------------
866 // Gets information about this column
867 bool wxListCtrl::GetColumn(int col
, wxListItem
& item
) const
870 return m_genericImpl
->GetColumn(col
, item
);
876 wxColumnList::compatibility_iterator node
= m_colsInfo
.Item( col
);
877 wxASSERT_MSG( node
, wxT("invalid column index in wxMacListCtrlItem") );
878 wxListItem
* column
= node
->GetData();
880 long mask
= column
->GetMask();
881 if (mask
& wxLIST_MASK_TEXT
)
882 item
.SetText(column
->GetText());
883 if (mask
& wxLIST_MASK_DATA
)
884 item
.SetData(column
->GetData());
885 if (mask
& wxLIST_MASK_IMAGE
)
886 item
.SetImage(column
->GetImage());
887 if (mask
& wxLIST_MASK_STATE
)
888 item
.SetState(column
->GetState());
889 if (mask
& wxLIST_MASK_FORMAT
)
890 item
.SetAlign(column
->GetAlign());
891 if (mask
& wxLIST_MASK_WIDTH
)
892 item
.SetWidth(column
->GetWidth());
898 // Sets information about this column
899 bool wxListCtrl::SetColumn(int col
, const wxListItem
& item
)
902 return m_genericImpl
->SetColumn(col
, item
);
906 wxASSERT_MSG( col
< (int)m_colsInfo
.GetCount(), wxT("invalid column index in wxMacListCtrlItem") );
908 long mask
= item
.GetMask();
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
;
931 DataBrowserTableViewColumnID id
= 0;
932 verify_noerr( m_dbImpl
->GetColumnIDFromIndex( col
, &id
) );
933 verify_noerr( m_dbImpl
->GetHeaderDesc( id
, &columnDesc
) );
936 if (item.GetMask() & wxLIST_MASK_TEXT)
940 enc = GetFont().GetEncoding();
942 enc = wxLocale::GetSystemEncoding();
943 wxCFStringRef cfTitle;
944 cfTitle.Assign( item.GetText() , enc );
945 if(columnDesc.titleString)
946 CFRelease(columnDesc.titleString);
947 columnDesc.titleString = cfTitle;
951 if (item
.GetMask() & wxLIST_MASK_IMAGE
&& item
.GetImage() != -1 )
953 wxImageList
* imageList
= GetImageList(wxIMAGE_LIST_SMALL
);
954 if (imageList
&& imageList
->GetImageCount() > 0 )
956 wxBitmap bmp
= imageList
->GetBitmap( item
.GetImage() );
957 IconRef icon
= bmp
.GetIconRef();
958 columnDesc
.btnContentInfo
.u
.iconRef
= icon
;
959 columnDesc
.btnContentInfo
.contentType
= kControlContentIconRef
;
963 verify_noerr( m_dbImpl
->SetHeaderDesc( id
, &columnDesc
) );
969 int wxListCtrl::GetColumnCount() const
972 return m_genericImpl
->GetColumnCount();
977 m_dbImpl
->GetColumnCount(&count
);
984 // Gets the column width
985 int wxListCtrl::GetColumnWidth(int col
) const
988 return m_genericImpl
->GetColumnWidth(col
);
992 return m_dbImpl
->GetColumnWidth(col
);
998 // Sets the column width
999 bool wxListCtrl::SetColumnWidth(int col
, int width
)
1002 return m_genericImpl
->SetColumnWidth(col
, width
);
1006 if ( width
== wxLIST_AUTOSIZE_USEHEADER
)
1008 width
= 150; // FIXME
1013 for (int column
= 0; column
< GetColumnCount(); column
++)
1016 GetColumn(column
, colInfo
);
1018 colInfo
.SetWidth(width
);
1019 SetColumn(column
, colInfo
);
1021 const int mywidth
= (width
== wxLIST_AUTOSIZE
)
1022 ? CalcColumnAutoWidth(column
) : width
;
1023 m_dbImpl
->SetColumnWidth(column
, mywidth
);
1028 if ( width
== wxLIST_AUTOSIZE
)
1029 width
= CalcColumnAutoWidth(col
);
1032 GetColumn(col
, colInfo
);
1034 colInfo
.SetWidth(width
);
1035 SetColumn(col
, colInfo
);
1036 m_dbImpl
->SetColumnWidth(col
, width
);
1044 // Gets the number of items that can fit vertically in the
1045 // visible area of the list control (list or report view)
1046 // or the total number of items in the list control (icon
1047 // or small icon view)
1048 int wxListCtrl::GetCountPerPage() const
1051 return m_genericImpl
->GetCountPerPage();
1056 m_dbImpl
->GetDefaultRowHeight( &height
);
1058 return GetClientSize().y
/ height
;
1064 // Gets the edit control for editing labels.
1065 wxTextCtrl
* wxListCtrl::GetEditControl() const
1068 return m_genericImpl
->GetEditControl();
1073 // Gets information about the item
1074 bool wxListCtrl::GetItem(wxListItem
& info
) const
1077 return m_genericImpl
->GetItem(info
);
1083 if (info
.m_itemId
>= 0 && info
.m_itemId
< GetItemCount())
1085 m_dbImpl
->MacGetColumnInfo(info
.m_itemId
, info
.m_col
, info
);
1086 // MacGetColumnInfo returns erroneous information in the state field, so zero it.
1088 if (info
.GetMask() & wxLIST_MASK_STATE
)
1090 DataBrowserItemID id
= (DataBrowserItemID
)m_dbImpl
->GetItemFromLine(info
.m_itemId
);
1091 if (IsDataBrowserItemSelected( m_dbImpl
->GetControlRef(), id
))
1092 info
.SetState(info
.GetState() | wxLIST_STATE_SELECTED
);
1098 if (info
.m_itemId
>= 0 && info
.m_itemId
< GetItemCount())
1100 info
.SetText( OnGetItemText(info
.m_itemId
, info
.m_col
) );
1101 info
.SetImage( OnGetItemColumnImage(info
.m_itemId
, info
.m_col
) );
1102 if (info
.GetMask() & wxLIST_MASK_STATE
)
1104 if (IsDataBrowserItemSelected( m_dbImpl
->GetControlRef(), info
.m_itemId
+1 ))
1105 info
.SetState(info
.GetState() | wxLIST_STATE_SELECTED
);
1108 wxListItemAttr
* attrs
= OnGetItemAttr( info
.m_itemId
);
1111 info
.SetFont( attrs
->GetFont() );
1112 info
.SetBackgroundColour( attrs
->GetBackgroundColour() );
1113 info
.SetTextColour( attrs
->GetTextColour() );
1118 bool success
= true;
1122 // Sets information about the item
1123 bool wxListCtrl::SetItem(wxListItem
& info
)
1126 return m_genericImpl
->SetItem(info
);
1129 m_dbImpl
->MacSetColumnInfo( info
.m_itemId
, info
.m_col
, &info
);
1134 long wxListCtrl::SetItem(long index
, int col
, const wxString
& label
, int imageId
)
1137 return m_genericImpl
->SetItem(index
, col
, label
, imageId
);
1140 info
.m_text
= label
;
1141 info
.m_mask
= wxLIST_MASK_TEXT
;
1142 info
.m_itemId
= index
;
1146 info
.m_image
= imageId
;
1147 info
.m_mask
|= wxLIST_MASK_IMAGE
;
1149 return SetItem(info
);
1153 // Gets the item state
1154 int wxListCtrl::GetItemState(long item
, long stateMask
) const
1157 return m_genericImpl
->GetItemState(item
, stateMask
);
1161 if ( HasFlag(wxLC_VIRTUAL
) )
1163 if (stateMask
== wxLIST_STATE_SELECTED
)
1165 if (IsDataBrowserItemSelected( m_dbImpl
->GetControlRef(), item
+1 ))
1166 return wxLIST_STATE_SELECTED
;
1175 info
.m_mask
= wxLIST_MASK_STATE
;
1176 info
.m_stateMask
= stateMask
;
1177 info
.m_itemId
= item
;
1182 return info
.m_state
;
1189 // Sets the item state
1190 bool wxListCtrl::SetItemState(long item
, long state
, long stateMask
)
1193 return m_genericImpl
->SetItemState(item
, state
, stateMask
);
1197 DataBrowserSetOption option
= kDataBrowserItemsAdd
;
1198 if ( (stateMask
& wxLIST_STATE_SELECTED
) && state
== 0 )
1199 option
= kDataBrowserItemsRemove
;
1203 if ( HasFlag(wxLC_VIRTUAL
) )
1205 wxMacDataItemBrowserSelectionSuppressor
suppressor(m_dbImpl
);
1206 m_dbImpl
->SetSelectedAllItems(option
);
1210 for(int i
= 0; i
< GetItemCount();i
++)
1214 info
.m_mask
= wxLIST_MASK_STATE
;
1215 info
.m_stateMask
= stateMask
;
1216 info
.m_state
= state
;
1223 if ( HasFlag(wxLC_VIRTUAL
) )
1225 long itemID
= item
+1;
1226 bool isSelected
= IsDataBrowserItemSelected(m_dbImpl
->GetControlRef(), (DataBrowserItemID
)itemID
);
1227 bool isSelectedState
= (state
== wxLIST_STATE_SELECTED
);
1229 // toggle the selection state if wxListInfo state and actual state don't match.
1230 if ( (stateMask
& wxLIST_STATE_SELECTED
) && isSelected
!= isSelectedState
)
1232 SetDataBrowserSelectedItems(m_dbImpl
->GetControlRef(), 1, (DataBrowserItemID
*)&itemID
, option
);
1238 info
.m_itemId
= item
;
1239 info
.m_mask
= wxLIST_MASK_STATE
;
1240 info
.m_stateMask
= stateMask
;
1241 info
.m_state
= state
;
1242 return SetItem(info
);
1249 // Sets the item image
1250 bool wxListCtrl::SetItemImage(long item
, int image
, int WXUNUSED(selImage
))
1252 return SetItemColumnImage(item
, 0, image
);
1255 // Sets the item image
1256 bool wxListCtrl::SetItemColumnImage(long item
, long column
, int image
)
1259 return m_genericImpl
->SetItemColumnImage(item
, column
, image
);
1263 info
.m_mask
= wxLIST_MASK_IMAGE
;
1264 info
.m_image
= image
;
1265 info
.m_itemId
= item
;
1266 info
.m_col
= column
;
1268 return SetItem(info
);
1271 // Gets the item text
1272 wxString
wxListCtrl::GetItemText(long item
, int column
) const
1275 return m_genericImpl
->GetItemText(item
, column
);
1279 info
.m_mask
= wxLIST_MASK_TEXT
;
1280 info
.m_itemId
= item
;
1281 info
.m_col
= column
;
1284 return wxEmptyString
;
1288 // Sets the item text
1289 void wxListCtrl::SetItemText(long item
, const wxString
& str
)
1292 return m_genericImpl
->SetItemText(item
, str
);
1296 info
.m_mask
= wxLIST_MASK_TEXT
;
1297 info
.m_itemId
= item
;
1303 // Gets the item data
1304 long wxListCtrl::GetItemData(long item
) const
1307 return m_genericImpl
->GetItemData(item
);
1311 info
.m_mask
= wxLIST_MASK_DATA
;
1312 info
.m_itemId
= item
;
1319 // Sets the item data
1320 bool wxListCtrl::SetItemPtrData(long item
, wxUIntPtr data
)
1323 return m_genericImpl
->SetItemData(item
, data
);
1327 info
.m_mask
= wxLIST_MASK_DATA
;
1328 info
.m_itemId
= item
;
1331 return SetItem(info
);
1334 wxRect
wxListCtrl::GetViewRect() const
1336 wxASSERT_MSG( !HasFlag(wxLC_REPORT
| wxLC_LIST
),
1337 wxT("wxListCtrl::GetViewRect() only works in icon mode") );
1340 return m_genericImpl
->GetViewRect();
1346 bool wxListCtrl::GetSubItemRect( long item
, long subItem
, wxRect
& rect
, int code
) const
1349 return m_genericImpl
->GetSubItemRect(item
, subItem
, rect
, code
);
1351 // TODO: implement for DataBrowser implementation
1355 // Gets the item rectangle
1356 bool wxListCtrl::GetItemRect(long item
, wxRect
& rect
, int code
) const
1359 return m_genericImpl
->GetItemRect(item
, rect
, code
);
1364 DataBrowserItemID id
;
1366 DataBrowserTableViewColumnID col
= 0;
1367 verify_noerr( m_dbImpl
->GetColumnIDFromIndex( 0, &col
) );
1370 DataBrowserPropertyPart part
= kDataBrowserPropertyEnclosingPart
;
1371 if ( code
== wxLIST_RECT_LABEL
)
1372 part
= kDataBrowserPropertyTextPart
;
1373 else if ( code
== wxLIST_RECT_ICON
)
1374 part
= kDataBrowserPropertyIconPart
;
1376 if ( !(GetWindowStyleFlag() & wxLC_VIRTUAL
) )
1378 wxMacDataItem
* thisItem
= m_dbImpl
->GetItemFromLine(item
);
1379 id
= (DataBrowserItemID
) thisItem
;
1384 GetDataBrowserItemPartBounds( m_dbImpl
->GetControlRef(), id
, col
, part
, &bounds
);
1386 rect
.x
= bounds
.left
;
1387 rect
.y
= bounds
.top
;
1388 rect
.width
= bounds
.right
- bounds
.left
; //GetClientSize().x; // we need the width of the whole row, not just the item.
1389 rect
.height
= bounds
.bottom
- bounds
.top
;
1390 //fprintf("id = %d, bounds = %d, %d, %d, %d\n", id, rect.x, rect.y, rect.width, rect.height);
1395 // Gets the item position
1396 bool wxListCtrl::GetItemPosition(long item
, wxPoint
& pos
) const
1399 return m_genericImpl
->GetItemPosition(item
, pos
);
1401 bool success
= false;
1406 GetItemRect(item
, itemRect
);
1407 pos
= itemRect
.GetPosition();
1414 // Sets the item position.
1415 bool wxListCtrl::SetItemPosition(long item
, const wxPoint
& pos
)
1418 return m_genericImpl
->SetItemPosition(item
, pos
);
1423 // Gets the number of items in the list control
1424 int wxListCtrl::GetItemCount() const
1427 return m_genericImpl
->GetItemCount();
1430 return m_dbImpl
->MacGetCount();
1435 void wxListCtrl::SetItemSpacing( int spacing
, bool isSmall
)
1438 m_genericImpl
->SetItemSpacing(spacing
, isSmall
);
1441 wxSize
wxListCtrl::GetItemSpacing() const
1444 return m_genericImpl
->GetItemSpacing();
1446 return wxSize(0, 0);
1449 void wxListCtrl::SetItemTextColour( long item
, const wxColour
&col
)
1453 m_genericImpl
->SetItemTextColour(item
, col
);
1458 info
.m_itemId
= item
;
1459 info
.SetTextColour( col
);
1463 wxColour
wxListCtrl::GetItemTextColour( long item
) const
1466 return m_genericImpl
->GetItemTextColour(item
);
1472 return info
.GetTextColour();
1474 return wxNullColour
;
1477 void wxListCtrl::SetItemBackgroundColour( long item
, const wxColour
&col
)
1481 m_genericImpl
->SetItemBackgroundColour(item
, col
);
1486 info
.m_itemId
= item
;
1487 info
.SetBackgroundColour( col
);
1491 wxColour
wxListCtrl::GetItemBackgroundColour( long item
) const
1494 return m_genericImpl
->GetItemBackgroundColour(item
);
1500 return info
.GetBackgroundColour();
1502 return wxNullColour
;
1505 void wxListCtrl::SetItemFont( long item
, const wxFont
&f
)
1509 m_genericImpl
->SetItemFont(item
, f
);
1514 info
.m_itemId
= item
;
1519 wxFont
wxListCtrl::GetItemFont( long item
) const
1522 return m_genericImpl
->GetItemFont(item
);
1528 return info
.GetFont();
1534 // Gets the number of selected items in the list control
1535 int wxListCtrl::GetSelectedItemCount() const
1538 return m_genericImpl
->GetSelectedItemCount();
1541 return m_dbImpl
->GetSelectedItemCount(NULL
, true);
1546 // Gets the text colour of the listview
1547 wxColour
wxListCtrl::GetTextColour() const
1550 return m_genericImpl
->GetTextColour();
1552 // TODO: we need owner drawn list items to customize text color.
1556 return wxNullColour
;
1559 // Sets the text colour of the listview
1560 void wxListCtrl::SetTextColour(const wxColour
& col
)
1564 m_genericImpl
->SetTextColour(col
);
1572 // Gets the index of the topmost visible item when in
1573 // list or report view
1574 long wxListCtrl::GetTopItem() const
1577 return m_genericImpl
->GetTopItem();
1582 long item
= HitTest( wxPoint(1, 1), flags
);
1583 if (flags
== wxLIST_HITTEST_ONITEM
)
1590 // Searches for an item, starting from 'item'.
1591 // 'geometry' is one of
1592 // wxLIST_NEXT_ABOVE/ALL/BELOW/LEFT/RIGHT.
1593 // 'state' is a state bit flag, one or more of
1594 // wxLIST_STATE_DROPHILITED/FOCUSED/SELECTED/CUT.
1595 // item can be -1 to find the first item that matches the
1597 // Returns the item or -1 if unsuccessful.
1598 long wxListCtrl::GetNextItem(long item
, int geom
, int state
) const
1601 return m_genericImpl
->GetNextItem(item
, geom
, state
);
1603 // TODO: implement all geometry and state options?
1606 if ( geom
== wxLIST_NEXT_ALL
|| geom
== wxLIST_NEXT_BELOW
)
1608 long count
= m_dbImpl
->MacGetCount() ;
1609 for ( long line
= item
+ 1 ; line
< count
; line
++ )
1611 DataBrowserItemID id
= line
+ 1;
1613 id
= (DataBrowserItemID
)m_dbImpl
->GetItemFromLine(line
);
1615 if ( (state
& wxLIST_STATE_FOCUSED
) && (m_current
== line
))
1618 if ( (state
== wxLIST_STATE_DONTCARE
) )
1621 if ( (state
& wxLIST_STATE_SELECTED
) && IsDataBrowserItemSelected(m_dbImpl
->GetControlRef(), id
) )
1626 if ( geom
== wxLIST_NEXT_ABOVE
)
1630 item2
= m_dbImpl
->MacGetCount();
1632 for ( long line
= item2
- 1 ; line
>= 0; line
-- )
1634 DataBrowserItemID id
= line
+ 1;
1636 id
= (DataBrowserItemID
)m_dbImpl
->GetItemFromLine(line
);
1638 if ( (state
& wxLIST_STATE_FOCUSED
) && (m_current
== line
))
1641 if ( (state
== wxLIST_STATE_DONTCARE
) )
1644 if ( (state
& wxLIST_STATE_SELECTED
) && IsDataBrowserItemSelected(m_dbImpl
->GetControlRef(), id
) )
1654 wxImageList
*wxListCtrl::GetImageList(int which
) const
1657 return m_genericImpl
->GetImageList(which
);
1659 if ( which
== wxIMAGE_LIST_NORMAL
)
1661 return m_imageListNormal
;
1663 else if ( which
== wxIMAGE_LIST_SMALL
)
1665 return m_imageListSmall
;
1667 else if ( which
== wxIMAGE_LIST_STATE
)
1669 return m_imageListState
;
1674 void wxListCtrl::SetImageList(wxImageList
*imageList
, int which
)
1678 m_genericImpl
->SetImageList(imageList
, which
);
1682 if ( which
== wxIMAGE_LIST_NORMAL
)
1684 if (m_ownsImageListNormal
) delete m_imageListNormal
;
1685 m_imageListNormal
= imageList
;
1686 m_ownsImageListNormal
= false;
1688 else if ( which
== wxIMAGE_LIST_SMALL
)
1690 if (m_ownsImageListSmall
) delete m_imageListSmall
;
1691 m_imageListSmall
= imageList
;
1692 m_ownsImageListSmall
= false;
1694 else if ( which
== wxIMAGE_LIST_STATE
)
1696 if (m_ownsImageListState
) delete m_imageListState
;
1697 m_imageListState
= imageList
;
1698 m_ownsImageListState
= false;
1702 void wxListCtrl::AssignImageList(wxImageList
*imageList
, int which
)
1706 m_genericImpl
->AssignImageList(imageList
, which
);
1710 SetImageList(imageList
, which
);
1711 if ( which
== wxIMAGE_LIST_NORMAL
)
1712 m_ownsImageListNormal
= true;
1713 else if ( which
== wxIMAGE_LIST_SMALL
)
1714 m_ownsImageListSmall
= true;
1715 else if ( which
== wxIMAGE_LIST_STATE
)
1716 m_ownsImageListState
= true;
1719 // ----------------------------------------------------------------------------
1721 // ----------------------------------------------------------------------------
1723 // Arranges the items
1724 bool wxListCtrl::Arrange(int flag
)
1727 return m_genericImpl
->Arrange(flag
);
1732 bool wxListCtrl::DeleteItem(long item
)
1735 return m_genericImpl
->DeleteItem(item
);
1739 m_dbImpl
->MacDelete(item
);
1740 wxListEvent
event( wxEVT_LIST_DELETE_ITEM
, GetId() );
1741 event
.SetEventObject( this );
1742 event
.m_itemIndex
= item
;
1743 HandleWindowEvent( event
);
1749 // Deletes all items
1750 bool wxListCtrl::DeleteAllItems()
1754 return m_genericImpl
->DeleteAllItems();
1758 m_dbImpl
->MacClear();
1759 wxListEvent
event( wxEVT_LIST_DELETE_ALL_ITEMS
, GetId() );
1760 event
.SetEventObject( this );
1761 HandleWindowEvent( event
);
1766 // Deletes all items
1767 bool wxListCtrl::DeleteAllColumns()
1770 return m_genericImpl
->DeleteAllColumns();
1775 m_dbImpl
->GetColumnCount(&cols
);
1776 for (UInt32 col
= 0; col
< cols
; col
++)
1786 bool wxListCtrl::DeleteColumn(int col
)
1789 return m_genericImpl
->DeleteColumn(col
);
1793 OSStatus err
= m_dbImpl
->RemoveColumn(col
);
1794 return err
== noErr
;
1800 // Clears items, and columns if there are any.
1801 void wxListCtrl::ClearAll()
1805 m_genericImpl
->ClearAll();
1816 wxTextCtrl
* wxListCtrl::EditLabel(long item
, wxClassInfo
* textControlClass
)
1819 return m_genericImpl
->EditLabel(item
, textControlClass
);
1823 wxCHECK_MSG( (item
>= 0) && ((long)item
< GetItemCount()), NULL
,
1824 wxT("wrong index in wxListCtrl::EditLabel()") );
1826 wxASSERT_MSG( textControlClass
->IsKindOf(CLASSINFO(wxTextCtrl
)),
1827 wxT("EditLabel() needs a text control") );
1829 wxListEvent
le( wxEVT_LIST_BEGIN_LABEL_EDIT
, GetParent()->GetId() );
1830 le
.SetEventObject( this );
1831 le
.m_itemIndex
= item
;
1833 GetItem( le
.m_item
);
1835 if ( GetParent()->HandleWindowEvent( le
) && !le
.IsAllowed() )
1837 // vetoed by user code
1841 wxTextCtrl
* const text
= (wxTextCtrl
*)textControlClass
->CreateObject();
1842 m_textctrlWrapper
= new wxListCtrlTextCtrlWrapper(this, text
, item
);
1843 return m_textctrlWrapper
->GetText();
1848 // End label editing, optionally cancelling the edit
1849 bool wxListCtrl::EndEditLabel(bool WXUNUSED(cancel
))
1851 // TODO: generic impl. doesn't have this method - is it needed for us?
1853 return true; // m_genericImpl->EndEditLabel(cancel);
1857 DataBrowserTableViewColumnID id
= 0;
1858 verify_noerr( m_dbImpl
->GetColumnIDFromIndex( 0, &id
) );
1859 verify_noerr( SetDataBrowserEditItem(m_dbImpl
->GetControlRef(), kDataBrowserNoItem
, id
) );
1864 // Ensures this item is visible
1865 bool wxListCtrl::EnsureVisible(long item
)
1868 return m_genericImpl
->EnsureVisible(item
);
1872 wxMacDataItem
* dataItem
= m_dbImpl
->GetItemFromLine(item
);
1873 m_dbImpl
->RevealItem(dataItem
, kDataBrowserRevealWithoutSelecting
);
1879 // Find an item whose label matches this string, starting from the item after 'start'
1880 // or the beginning if 'start' is -1.
1881 long wxListCtrl::FindItem(long start
, const wxString
& str
, bool partial
)
1884 return m_genericImpl
->FindItem(start
, str
, partial
);
1886 wxString str_upper
= str
.Upper();
1891 long count
= GetItemCount();
1895 wxString line_upper
= GetItemText(idx
).Upper();
1898 if (line_upper
== str_upper
)
1903 if (line_upper
.find(str_upper
) == 0)
1913 // Find an item whose data matches this data, starting from the item after 'start'
1914 // or the beginning if 'start' is -1.
1915 long wxListCtrl::FindItem(long start
, long data
)
1918 return m_genericImpl
->FindItem(start
, data
);
1923 long count
= GetItemCount();
1927 if (GetItemData(idx
) == data
)
1935 // Find an item nearest this position in the specified direction, starting from
1936 // the item after 'start' or the beginning if 'start' is -1.
1937 long wxListCtrl::FindItem(long start
, const wxPoint
& pt
, int direction
)
1940 return m_genericImpl
->FindItem(start
, pt
, direction
);
1944 static void calculateCGDrawingBounds(CGRect inItemRect
, CGRect
*outIconRect
, CGRect
*outTextRect
, bool hasIcon
);
1946 // Determines which item (if any) is at the specified point,
1947 // giving details in 'flags' (see wxLIST_HITTEST_... flags above)
1949 wxListCtrl::HitTest(const wxPoint
& point
, int& flags
, long *ptrSubItem
) const
1955 return m_genericImpl
->HitTest(point
, flags
, ptrSubItem
);
1957 flags
= wxLIST_HITTEST_NOWHERE
;
1960 int colHeaderHeight
= 22; // TODO: Find a way to get this value from the db control?
1961 UInt16 rowHeight
= 0;
1962 m_dbImpl
->GetDefaultRowHeight(&rowHeight
);
1965 // get the actual row by taking scroll position into account
1966 UInt32 offsetX
, offsetY
;
1967 m_dbImpl
->GetScrollPosition( &offsetY
, &offsetX
);
1970 if ( !(GetWindowStyleFlag() & wxLC_NO_HEADER
) )
1971 y
-= colHeaderHeight
;
1976 int row
= y
/ rowHeight
;
1977 DataBrowserItemID id
;
1978 m_dbImpl
->GetItemID( (DataBrowserTableViewRowIndex
) row
, &id
);
1980 CGPoint click_point
= CGPointMake( point
.x
, point
.y
);
1981 if (row
< GetItemCount() )
1984 for( column
= 0; column
< GetColumnCount(); column
++ )
1987 CGRect enclosingCGRect
, iconCGRect
, textCGRect
;
1989 wxMacListCtrlItem
* lcItem
;
1991 WXUNUSED_UNLESS_DEBUG( OSStatus status
= ) m_dbImpl
->GetItemPartBounds( id
, kMinColumnId
+ column
, kDataBrowserPropertyEnclosingPart
, &enclosingRect
);
1992 wxASSERT( status
== noErr
);
1994 enclosingCGRect
= CGRectMake(enclosingRect
.left
,
1996 enclosingRect
.right
- enclosingRect
.left
,
1997 enclosingRect
.bottom
- enclosingRect
.top
);
2001 if ( !(GetWindowStyleFlag() & wxLC_VIRTUAL
) )
2003 lcItem
= (wxMacListCtrlItem
*) id
;
2004 if (lcItem
->HasColumnInfo(column
))
2006 wxListItem
* item
= lcItem
->GetColumnInfo(column
);
2008 if (item
->GetMask() & wxLIST_MASK_IMAGE
)
2010 imgIndex
= item
->GetImage();
2016 long itemNum
= (long)id
-1;
2017 if (itemNum
>= 0 && itemNum
< GetItemCount())
2019 imgIndex
= OnGetItemColumnImage( itemNum
, column
);
2024 calculateCGDrawingBounds(enclosingCGRect
, &iconCGRect
, &textCGRect
, (imgIndex
!= -1) );
2026 if ( CGRectContainsPoint( iconCGRect
, click_point
) )
2028 flags
= wxLIST_HITTEST_ONITEMICON
;
2030 *ptrSubItem
= column
;
2033 else if ( CGRectContainsPoint( textCGRect
, click_point
) )
2035 flags
= wxLIST_HITTEST_ONITEMLABEL
;
2037 *ptrSubItem
= column
;
2042 if ( !(GetWindowStyleFlag() & wxLC_VIRTUAL
) )
2044 wxMacListCtrlItem
* lcItem
;
2045 lcItem
= (wxMacListCtrlItem
*) id
;
2048 flags
= wxLIST_HITTEST_ONITEM
;
2050 *ptrSubItem
= column
;
2056 flags
= wxLIST_HITTEST_ONITEM
;
2058 *ptrSubItem
= column
;
2064 if ( wxControl::HitTest( point
) )
2065 flags
= wxLIST_HITTEST_NOWHERE
;
2072 int wxListCtrl::GetScrollPos(int orient
) const
2075 return m_genericImpl
->GetScrollPos(orient
);
2079 UInt32 offsetX
, offsetY
;
2080 m_dbImpl
->GetScrollPosition( &offsetY
, &offsetX
);
2081 if ( orient
== wxHORIZONTAL
)
2090 // Inserts an item, returning the index of the new item if successful,
2092 long wxListCtrl::InsertItem(wxListItem
& info
)
2094 wxASSERT_MSG( !IsVirtual(), wxT("can't be used with virtual controls") );
2097 return m_genericImpl
->InsertItem(info
);
2099 if (m_dbImpl
&& !IsVirtual())
2101 int count
= GetItemCount();
2103 if (info
.m_itemId
> count
)
2104 info
.m_itemId
= count
;
2106 m_dbImpl
->MacInsertItem(info
.m_itemId
, &info
);
2108 wxListEvent
event( wxEVT_LIST_INSERT_ITEM
, GetId() );
2109 event
.SetEventObject( this );
2110 event
.m_itemIndex
= info
.m_itemId
;
2111 HandleWindowEvent( event
);
2112 return info
.m_itemId
;
2117 long wxListCtrl::InsertItem(long index
, const wxString
& label
)
2120 return m_genericImpl
->InsertItem(index
, label
);
2123 info
.m_text
= label
;
2124 info
.m_mask
= wxLIST_MASK_TEXT
;
2125 info
.m_itemId
= index
;
2126 return InsertItem(info
);
2129 // Inserts an image item
2130 long wxListCtrl::InsertItem(long index
, int imageIndex
)
2133 return m_genericImpl
->InsertItem(index
, imageIndex
);
2136 info
.m_image
= imageIndex
;
2137 info
.m_mask
= wxLIST_MASK_IMAGE
;
2138 info
.m_itemId
= index
;
2139 return InsertItem(info
);
2142 // Inserts an image/string item
2143 long wxListCtrl::InsertItem(long index
, const wxString
& label
, int imageIndex
)
2146 return m_genericImpl
->InsertItem(index
, label
, imageIndex
);
2149 info
.m_image
= imageIndex
;
2150 info
.m_text
= label
;
2151 info
.m_mask
= wxLIST_MASK_IMAGE
| wxLIST_MASK_TEXT
;
2152 info
.m_itemId
= index
;
2153 return InsertItem(info
);
2156 // For list view mode (only), inserts a column.
2157 long wxListCtrl::DoInsertColumn(long col
, const wxListItem
& item
)
2160 return m_genericImpl
->InsertColumn(col
, item
);
2164 int width
= item
.GetWidth();
2165 if ( !(item
.GetMask() & wxLIST_MASK_WIDTH
) )
2168 DataBrowserPropertyType type
= kDataBrowserCustomType
; //kDataBrowserTextType;
2169 wxImageList
* imageList
= GetImageList(wxIMAGE_LIST_SMALL
);
2170 if (imageList
&& imageList
->GetImageCount() > 0)
2172 wxBitmap bmp
= imageList
->GetBitmap(0);
2174 // type = kDataBrowserIconAndTextType;
2177 SInt16 just
= teFlushDefault
;
2178 if (item
.GetMask() & wxLIST_MASK_FORMAT
)
2180 if (item
.GetAlign() == wxLIST_FORMAT_LEFT
)
2182 else if (item
.GetAlign() == wxLIST_FORMAT_CENTER
)
2184 else if (item
.GetAlign() == wxLIST_FORMAT_RIGHT
)
2185 just
= teFlushRight
;
2187 m_dbImpl
->InsertColumn(col
, type
, item
.GetText(), just
, width
);
2189 wxListItem
* listItem
= new wxListItem(item
);
2190 m_colsInfo
.Insert( col
, listItem
);
2191 SetColumn(col
, item
);
2193 // set/remove options based on the wxListCtrl type.
2194 DataBrowserTableViewColumnID id
;
2195 m_dbImpl
->GetColumnIDFromIndex(col
, &id
);
2196 DataBrowserPropertyFlags flags
;
2197 verify_noerr(m_dbImpl
->GetPropertyFlags(id
, &flags
));
2198 if (GetWindowStyleFlag() & wxLC_EDIT_LABELS
)
2199 flags
|= kDataBrowserPropertyIsEditable
;
2201 if (GetWindowStyleFlag() & wxLC_VIRTUAL
){
2202 flags
&= ~kDataBrowserListViewSortableColumn
;
2204 verify_noerr(m_dbImpl
->SetPropertyFlags(id
, flags
));
2210 // scroll the control by the given number of pixels (exception: in list view,
2211 // dx is interpreted as number of columns)
2212 bool wxListCtrl::ScrollList(int dx
, int dy
)
2215 return m_genericImpl
->ScrollList(dx
, dy
);
2219 // Notice that the parameter order is correct here: first argument is
2220 // the "top" displacement, second one is the "left" one.
2221 m_dbImpl
->SetScrollPosition(dy
, dx
);
2227 bool wxListCtrl::SortItems(wxListCtrlCompare fn
, wxIntPtr data
)
2230 return m_genericImpl
->SortItems(fn
, data
);
2235 m_compareFuncData
= data
;
2236 SortDataBrowserContainer( m_dbImpl
->GetControlRef(), kDataBrowserNoItem
, true);
2238 // we need to do this after each call, else we get a crash from wxPython when
2239 // SortItems is called the second time.
2240 m_compareFunc
= NULL
;
2241 m_compareFuncData
= 0;
2247 void wxListCtrl::OnRenameTimer()
2249 wxCHECK_RET( HasCurrent(), wxT("unexpected rename timer") );
2251 EditLabel( m_current
);
2254 bool wxListCtrl::OnRenameAccept(long itemEdit
, const wxString
& value
)
2256 wxListEvent
le( wxEVT_LIST_END_LABEL_EDIT
, GetId() );
2257 le
.SetEventObject( this );
2258 le
.m_itemIndex
= itemEdit
;
2260 GetItem( le
.m_item
);
2261 le
.m_item
.m_text
= value
;
2262 return !HandleWindowEvent( le
) ||
2266 void wxListCtrl::OnRenameCancelled(long itemEdit
)
2268 // let owner know that the edit was cancelled
2269 wxListEvent
le( wxEVT_LIST_END_LABEL_EDIT
, GetParent()->GetId() );
2271 le
.SetEditCanceled(true);
2273 le
.SetEventObject( this );
2274 le
.m_itemIndex
= itemEdit
;
2276 GetItem( le
.m_item
);
2277 HandleWindowEvent( le
);
2280 // ----------------------------------------------------------------------------
2281 // virtual list controls
2282 // ----------------------------------------------------------------------------
2284 wxString
wxListCtrl::OnGetItemText(long WXUNUSED(item
), long WXUNUSED(col
)) const
2286 // this is a pure virtual function, in fact - which is not really pure
2287 // because the controls which are not virtual don't need to implement it
2288 wxFAIL_MSG( wxT("wxListCtrl::OnGetItemText not supposed to be called") );
2290 return wxEmptyString
;
2293 int wxListCtrl::OnGetItemImage(long WXUNUSED(item
)) const
2295 wxCHECK_MSG(!GetImageList(wxIMAGE_LIST_SMALL
),
2297 wxT("List control has an image list, OnGetItemImage or OnGetItemColumnImage should be overridden."));
2301 int wxListCtrl::OnGetItemColumnImage(long item
, long column
) const
2304 return OnGetItemImage(item
);
2309 void wxListCtrl::SetItemCount(long count
)
2311 wxASSERT_MSG( IsVirtual(), wxT("this is for virtual controls only") );
2315 m_genericImpl
->SetItemCount(count
);
2321 // we need to temporarily disable the new item creation notification
2322 // procedure to speed things up
2323 // FIXME: Even this doesn't seem to help much...
2325 // FIXME: Find a more efficient way to do this.
2326 m_dbImpl
->MacClear();
2328 DataBrowserCallbacks callbacks
;
2329 DataBrowserItemNotificationUPP itemUPP
;
2330 GetDataBrowserCallbacks(m_dbImpl
->GetControlRef(), &callbacks
);
2331 itemUPP
= callbacks
.u
.v1
.itemNotificationCallback
;
2332 callbacks
.u
.v1
.itemNotificationCallback
= 0;
2333 m_dbImpl
->SetCallbacks(&callbacks
);
2334 ::AddDataBrowserItems(m_dbImpl
->GetControlRef(), kDataBrowserNoItem
,
2335 count
, NULL
, kDataBrowserItemNoProperty
);
2336 callbacks
.u
.v1
.itemNotificationCallback
= itemUPP
;
2337 m_dbImpl
->SetCallbacks(&callbacks
);
2342 void wxListCtrl::RefreshItem(long item
)
2346 m_genericImpl
->RefreshItem(item
);
2352 DataBrowserItemID id
;
2356 wxMacDataItem
* thisItem
= m_dbImpl
->GetItemFromLine(item
);
2357 id
= (DataBrowserItemID
) thisItem
;
2362 m_dbImpl
->wxMacDataBrowserControl::UpdateItems
2366 kDataBrowserItemNoProperty
, // preSortProperty
2367 kDataBrowserNoItem
// update all columns
2372 void wxListCtrl::RefreshItems(long itemFrom
, long itemTo
)
2376 m_genericImpl
->RefreshItems(itemFrom
, itemTo
);
2382 const long count
= itemTo
- itemFrom
+ 1;
2383 DataBrowserItemID
*ids
= new DataBrowserItemID
[count
];
2387 for ( long i
= 0; i
< count
; i
++ )
2389 wxMacDataItem
* thisItem
= m_dbImpl
->GetItemFromLine(itemFrom
+i
);
2390 ids
[i
] = (DataBrowserItemID
) thisItem
;
2395 for ( long i
= 0; i
< count
; i
++ )
2396 ids
[i
] = itemFrom
+i
+1;
2399 m_dbImpl
->wxMacDataBrowserControl::UpdateItems
2403 kDataBrowserItemNoProperty
, // preSortProperty
2404 kDataBrowserNoItem
// update all columns
2411 void wxListCtrl::SetDropTarget( wxDropTarget
*dropTarget
)
2413 #if wxUSE_DRAG_AND_DROP
2415 m_genericImpl
->SetDropTarget( dropTarget
);
2418 wxWindow::SetDropTarget( dropTarget
);
2422 wxDropTarget
*wxListCtrl::GetDropTarget() const
2424 #if wxUSE_DRAG_AND_DROP
2426 return m_genericImpl
->GetDropTarget();
2429 return wxWindow::GetDropTarget();
2434 #if wxABI_VERSION >= 20801
2435 void wxListCtrl::SetFocus()
2439 m_genericImpl
->SetFocus();
2443 wxWindow::SetFocus();
2447 // wxMac internal data structures
2449 wxMacListCtrlItem::~wxMacListCtrlItem()
2451 WX_CLEAR_HASH_MAP( wxListItemList
, m_rowItems
);
2454 void wxMacListCtrlItem::Notification(wxMacDataItemBrowserControl
*owner
,
2455 DataBrowserItemNotification message
,
2456 DataBrowserItemDataRef
WXUNUSED(itemData
) ) const
2459 wxMacDataBrowserListCtrlControl
*lb
= wxDynamicCast(owner
, wxMacDataBrowserListCtrlControl
);
2461 // we want to depend on as little as possible to make sure tear-down of controls is safe
2462 if ( message
== kDataBrowserItemRemoved
)
2467 else if ( message
== kDataBrowserItemAdded
)
2469 // we don't issue events on adding, the item is not really stored in the list yet, so we
2470 // avoid asserts by gettting out now
2474 wxListCtrl
*list
= wxDynamicCast( owner
->GetWXPeer() , wxListCtrl
);
2477 bool trigger
= false;
2479 wxListEvent
event( wxEVT_LIST_ITEM_SELECTED
, list
->GetId() );
2480 bool isSingle
= (list
->GetWindowStyle() & wxLC_SINGLE_SEL
) != 0;
2482 event
.SetEventObject( list
);
2483 event
.m_itemIndex
= owner
->GetLineFromItem( this ) ;
2484 event
.m_item
.m_itemId
= event
.m_itemIndex
;
2485 list
->GetItem(event
.m_item
);
2489 case kDataBrowserItemDeselected
:
2490 event
.SetEventType(wxEVT_LIST_ITEM_DESELECTED
);
2492 trigger
= !lb
->IsSelectionSuppressed();
2495 case kDataBrowserItemSelected
:
2496 trigger
= !lb
->IsSelectionSuppressed();
2499 case kDataBrowserItemDoubleClicked
:
2500 event
.SetEventType( wxEVT_LIST_ITEM_ACTIVATED
);
2504 case kDataBrowserEditStarted
:
2505 // TODO : how to veto ?
2506 event
.SetEventType( wxEVT_LIST_BEGIN_LABEL_EDIT
) ;
2510 case kDataBrowserEditStopped
:
2511 // TODO probably trigger only upon the value store callback, because
2512 // here IIRC we cannot veto
2513 event
.SetEventType( wxEVT_LIST_END_LABEL_EDIT
) ;
2523 // direct notification is not always having the listbox GetSelection() having in synch with event
2524 wxPostEvent( list
->GetEventHandler(), event
);
2530 IMPLEMENT_DYNAMIC_CLASS(wxMacDataBrowserListCtrlControl
, wxMacDataItemBrowserControl
)
2532 wxMacDataBrowserListCtrlControl::wxMacDataBrowserListCtrlControl( wxWindow
*peer
, const wxPoint
& pos
, const wxSize
& size
, long style
)
2533 : wxMacDataItemBrowserControl( peer
, pos
, size
, style
)
2535 OSStatus err
= noErr
;
2536 m_clientDataItemsType
= wxClientData_None
;
2537 m_isVirtual
= false;
2540 if ( style
& wxLC_VIRTUAL
)
2543 DataBrowserSelectionFlags options
= kDataBrowserDragSelect
;
2544 if ( style
& wxLC_SINGLE_SEL
)
2546 options
|= kDataBrowserSelectOnlyOne
;
2550 options
|= kDataBrowserCmdTogglesSelection
;
2553 err
= SetSelectionFlags( options
);
2554 verify_noerr( err
);
2556 DataBrowserCustomCallbacks callbacks
;
2557 InitializeDataBrowserCustomCallbacks( &callbacks
, kDataBrowserLatestCustomCallbacks
);
2559 if ( gDataBrowserDrawItemUPP
== NULL
)
2560 gDataBrowserDrawItemUPP
= NewDataBrowserDrawItemUPP(DataBrowserDrawItemProc
);
2562 if ( gDataBrowserHitTestUPP
== NULL
)
2563 gDataBrowserHitTestUPP
= NewDataBrowserHitTestUPP(DataBrowserHitTestProc
);
2565 callbacks
.u
.v1
.drawItemCallback
= gDataBrowserDrawItemUPP
;
2566 callbacks
.u
.v1
.hitTestCallback
= gDataBrowserHitTestUPP
;
2568 SetDataBrowserCustomCallbacks( GetControlRef(), &callbacks
);
2570 if ( style
& wxLC_LIST
)
2572 InsertColumn(0, kDataBrowserIconAndTextType
, wxEmptyString
, -1, -1);
2573 verify_noerr( AutoSizeColumns() );
2576 if ( style
& wxLC_LIST
|| style
& wxLC_NO_HEADER
)
2577 verify_noerr( SetHeaderButtonHeight( 0 ) );
2580 SetSortProperty( kMinColumnId
- 1 );
2582 SetSortProperty( kMinColumnId
);
2584 m_sortOrder
= SortOrder_None
;
2586 if ( style
& wxLC_SORT_DESCENDING
)
2588 SetSortOrder( kDataBrowserOrderDecreasing
);
2590 else if ( style
& wxLC_SORT_ASCENDING
)
2592 SetSortOrder( kDataBrowserOrderIncreasing
);
2595 if ( style
& wxLC_VRULES
)
2597 verify_noerr( DataBrowserChangeAttributes(m_controlRef
, kDataBrowserAttributeListViewDrawColumnDividers
, kDataBrowserAttributeNone
) );
2600 verify_noerr( SetHiliteStyle(kDataBrowserTableViewFillHilite
) );
2601 verify_noerr( SetHasScrollBars( (style
& wxHSCROLL
) != 0 , true ) );
2604 pascal Boolean
wxMacDataBrowserListCtrlControl::DataBrowserEditTextProc(
2606 DataBrowserItemID itemID
,
2607 DataBrowserPropertyID property
,
2608 CFStringRef theString
,
2609 Rect
*maxEditTextRect
,
2610 Boolean
*shrinkToFit
)
2612 Boolean result
= false;
2613 wxMacDataBrowserListCtrlControl
* ctl
= wxDynamicCast(wxMacControl::GetReferenceFromNativeControl( browser
), wxMacDataBrowserListCtrlControl
);
2616 result
= ctl
->ConfirmEditText(itemID
, property
, theString
, maxEditTextRect
, shrinkToFit
);
2617 theString
= CFSTR("Hello!");
2622 bool wxMacDataBrowserListCtrlControl::ConfirmEditText(
2623 DataBrowserItemID
WXUNUSED(itemID
),
2624 DataBrowserPropertyID
WXUNUSED(property
),
2625 CFStringRef
WXUNUSED(theString
),
2626 Rect
*WXUNUSED(maxEditTextRect
),
2627 Boolean
*WXUNUSED(shrinkToFit
))
2632 pascal void wxMacDataBrowserListCtrlControl::DataBrowserDrawItemProc(
2634 DataBrowserItemID itemID
,
2635 DataBrowserPropertyID property
,
2636 DataBrowserItemState itemState
,
2637 const Rect
*itemRect
,
2639 Boolean colorDevice
)
2641 wxMacDataBrowserListCtrlControl
* ctl
= wxDynamicCast(wxMacControl::GetReferenceFromNativeControl( browser
), wxMacDataBrowserListCtrlControl
);
2644 ctl
->DrawItem(itemID
, property
, itemState
, itemRect
, gdDepth
, colorDevice
);
2648 // routines needed for DrawItem
2653 kTextBoxHeight
= 14,
2654 kIconTextSpacingV
= 2,
2656 kContentHeight
= kIconHeight
+ kTextBoxHeight
+ kIconTextSpacingV
2659 static void calculateCGDrawingBounds(CGRect inItemRect
, CGRect
*outIconRect
, CGRect
*outTextRect
, bool hasIcon
= false)
2663 float padding
= kItemPadding
;
2667 padding
= padding
*2;
2670 textBottom
= inItemRect
.origin
.y
;
2672 *outIconRect
= CGRectMake(inItemRect
.origin
.x
+ kItemPadding
,
2673 textBottom
+ kIconTextSpacingV
, kIconWidth
,
2676 *outTextRect
= CGRectMake(inItemRect
.origin
.x
+ padding
+ iconW
,
2677 textBottom
+ kIconTextSpacingV
, inItemRect
.size
.width
- padding
- iconW
,
2678 inItemRect
.size
.height
- kIconTextSpacingV
);
2681 void wxMacDataBrowserListCtrlControl::DrawItem(
2682 DataBrowserItemID itemID
,
2683 DataBrowserPropertyID property
,
2684 DataBrowserItemState itemState
,
2685 const Rect
*WXUNUSED(itemRect
),
2687 Boolean colorDevice
)
2690 wxFont font
= wxNullFont
;
2693 DataBrowserTableViewColumnIndex listColumn
= 0;
2694 GetColumnPosition( property
, &listColumn
);
2696 wxListCtrl
* list
= wxDynamicCast( GetWXPeer() , wxListCtrl
);
2697 wxMacListCtrlItem
* lcItem
;
2698 wxColour color
= *wxBLACK
;
2699 wxColour bgColor
= wxNullColour
;
2701 if (listColumn
>= 0)
2705 lcItem
= (wxMacListCtrlItem
*) itemID
;
2706 if (lcItem
->HasColumnInfo(listColumn
))
2708 wxListItem
* item
= lcItem
->GetColumnInfo(listColumn
);
2710 // we always use the 0 column to get font and text/background colors.
2711 if (lcItem
->HasColumnInfo(0))
2713 wxListItem
* firstItem
= lcItem
->GetColumnInfo(0);
2714 color
= firstItem
->GetTextColour();
2715 bgColor
= firstItem
->GetBackgroundColour();
2716 font
= firstItem
->GetFont();
2719 if (item
->GetMask() & wxLIST_MASK_TEXT
)
2720 text
= item
->GetText();
2721 if (item
->GetMask() & wxLIST_MASK_IMAGE
)
2722 imgIndex
= item
->GetImage();
2728 long itemNum
= (long)itemID
-1;
2729 if (itemNum
>= 0 && itemNum
< list
->GetItemCount())
2731 text
= list
->OnGetItemText( itemNum
, listColumn
);
2732 imgIndex
= list
->OnGetItemColumnImage( itemNum
, listColumn
);
2733 wxListItemAttr
* attrs
= list
->OnGetItemAttr( itemNum
);
2736 if (attrs
->HasBackgroundColour())
2737 bgColor
= attrs
->GetBackgroundColour();
2738 if (attrs
->HasTextColour())
2739 color
= attrs
->GetTextColour();
2740 if (attrs
->HasFont())
2741 font
= attrs
->GetFont();
2747 wxColour listBgColor
= list
->GetBackgroundColour();
2748 if (bgColor
== wxNullColour
)
2749 bgColor
= listBgColor
;
2752 font
= list
->GetFont();
2754 wxCFStringRef
cfString( text
, wxLocale::GetSystemEncoding() );
2757 CGRect enclosingCGRect
, iconCGRect
, textCGRect
;
2759 ThemeDrawingState savedState
= NULL
;
2760 CGContextRef context
= (CGContextRef
)list
->MacGetDrawingContext();
2761 wxMacCGContextStateSaver
top_saver_cg( context
);
2763 RGBColor labelColor
;
2765 labelColor
.green
= 0;
2766 labelColor
.blue
= 0;
2768 RGBColor backgroundColor
;
2769 backgroundColor
.red
= 255;
2770 backgroundColor
.green
= 255;
2771 backgroundColor
.blue
= 255;
2773 GetDataBrowserItemPartBounds(GetControlRef(), itemID
, property
, kDataBrowserPropertyEnclosingPart
,
2776 enclosingCGRect
= CGRectMake(enclosingRect
.left
,
2778 enclosingRect
.right
- enclosingRect
.left
,
2779 enclosingRect
.bottom
- enclosingRect
.top
);
2781 bool hasFocus
= (wxWindow::FindFocus() == list
);
2782 active
= IsControlActive(GetControlRef());
2784 // don't paint the background over the vertical rule line
2785 if ( list
->GetWindowStyleFlag() & wxLC_VRULES
)
2787 enclosingCGRect
.origin
.x
+= 1;
2788 enclosingCGRect
.size
.width
-= 1;
2790 if (itemState
== kDataBrowserItemIsSelected
)
2793 GetThemeDrawingState(&savedState
);
2795 if (active
&& hasFocus
)
2797 GetThemeBrushAsColor(kThemeBrushAlternatePrimaryHighlightColor
, 32, true, &backgroundColor
);
2798 GetThemeTextColor(kThemeTextColorWhite
, gdDepth
, colorDevice
, &labelColor
);
2802 GetThemeBrushAsColor(kThemeBrushSecondaryHighlightColor
, 32, true, &backgroundColor
);
2803 GetThemeTextColor(kThemeTextColorBlack
, gdDepth
, colorDevice
, &labelColor
);
2805 wxMacCGContextStateSaver
cg( context
);
2807 CGContextSetRGBFillColor(context
, (CGFloat
)backgroundColor
.red
/ (CGFloat
)USHRT_MAX
,
2808 (CGFloat
)backgroundColor
.green
/ (CGFloat
)USHRT_MAX
,
2809 (CGFloat
)backgroundColor
.blue
/ (CGFloat
)USHRT_MAX
, (CGFloat
) 1.0);
2810 CGContextFillRect(context
, enclosingCGRect
);
2816 color
.GetRGBColor(&labelColor
);
2817 else if (list
->GetTextColour().IsOk())
2818 list
->GetTextColour().GetRGBColor(&labelColor
);
2822 bgColor
.GetRGBColor(&backgroundColor
);
2823 CGContextSaveGState(context
);
2825 CGContextSetRGBFillColor(context
, (CGFloat
)backgroundColor
.red
/ (CGFloat
)USHRT_MAX
,
2826 (CGFloat
)backgroundColor
.green
/ (CGFloat
)USHRT_MAX
,
2827 (CGFloat
)backgroundColor
.blue
/ (CGFloat
)USHRT_MAX
, (CGFloat
) 1.0);
2828 CGContextFillRect(context
, enclosingCGRect
);
2830 CGContextRestoreGState(context
);
2834 calculateCGDrawingBounds(enclosingCGRect
, &iconCGRect
, &textCGRect
, (imgIndex
!= -1) );
2838 wxImageList
* imageList
= list
->GetImageList(wxIMAGE_LIST_SMALL
);
2839 if (imageList
&& imageList
->GetImageCount() > 0)
2841 wxBitmap bmp
= imageList
->GetBitmap(imgIndex
);
2842 IconRef icon
= bmp
.GetIconRef();
2844 wxMacCGContextStateSaver
cg( context
);
2846 CGContextTranslateCTM(context
, 0,iconCGRect
.origin
.y
+ CGRectGetMaxY(iconCGRect
));
2847 CGContextScaleCTM(context
,1.0f
,-1.0f
);
2848 PlotIconRefInContext(context
, &iconCGRect
, kAlignNone
,
2849 active
? kTransformNone
: kTransformDisabled
, NULL
,
2850 kPlotIconRefNormalFlags
, icon
);
2854 HIThemeTextHorizontalFlush hFlush
= kHIThemeTextHorizontalFlushLeft
;
2855 HIThemeTextInfo info
;
2857 #if wxOSX_USE_CORE_TEXT
2858 if ( UMAGetSystemVersion() >= 0x1050 )
2860 info
.version
= kHIThemeTextInfoVersionOne
;
2861 info
.fontID
= kThemeViewsFont
;
2864 info
.fontID
= kThemeSpecifiedFont
;
2865 info
.font
= (CTFontRef
) font
.OSXGetCTFont();
2870 #if wxOSX_USE_ATSU_TEXT
2873 info
.version
= kHIThemeTextInfoVersionZero
;
2874 info
.fontID
= kThemeViewsFont
;
2878 info
.fontID
= font
.MacGetThemeFontID();
2880 ::TextSize( (short)(font
.GetPointSize()) ) ;
2881 ::TextFace( font
.MacGetFontStyle() ) ;
2887 list
->GetColumn(listColumn
, item
);
2888 if (item
.GetMask() & wxLIST_MASK_FORMAT
)
2890 if (item
.GetAlign() == wxLIST_FORMAT_LEFT
)
2891 hFlush
= kHIThemeTextHorizontalFlushLeft
;
2892 else if (item
.GetAlign() == wxLIST_FORMAT_CENTER
)
2893 hFlush
= kHIThemeTextHorizontalFlushCenter
;
2894 else if (item
.GetAlign() == wxLIST_FORMAT_RIGHT
)
2896 hFlush
= kHIThemeTextHorizontalFlushRight
;
2897 textCGRect
.origin
.x
-= kItemPadding
; // give a little extra paddding
2901 info
.state
= active
? kThemeStateActive
: kThemeStateInactive
;
2902 info
.horizontalFlushness
= hFlush
;
2903 info
.verticalFlushness
= kHIThemeTextVerticalFlushCenter
;
2904 info
.options
= kHIThemeTextBoxOptionNone
;
2905 info
.truncationPosition
= kHIThemeTextTruncationEnd
;
2906 info
.truncationMaxLines
= 1;
2909 wxMacCGContextStateSaver
cg( context
);
2910 CGContextSetRGBFillColor (context
, (CGFloat
)labelColor
.red
/ (CGFloat
)USHRT_MAX
,
2911 (CGFloat
)labelColor
.green
/ (CGFloat
)USHRT_MAX
,
2912 (CGFloat
)labelColor
.blue
/ (CGFloat
)USHRT_MAX
, (CGFloat
) 1.0);
2914 HIThemeDrawTextBox(cfString
, &textCGRect
, &info
, context
, kHIThemeOrientationNormal
);
2918 if (savedState
!= NULL
)
2919 SetThemeDrawingState(savedState
, true);
2923 OSStatus
wxMacDataBrowserListCtrlControl::GetSetItemData(DataBrowserItemID itemID
,
2924 DataBrowserPropertyID property
,
2925 DataBrowserItemDataRef itemData
,
2926 Boolean changeValue
)
2931 DataBrowserTableViewColumnIndex listColumn
= 0;
2932 verify_noerr( GetColumnPosition( property
, &listColumn
) );
2934 OSStatus err
= errDataBrowserPropertyNotSupported
;
2935 wxListCtrl
* list
= wxDynamicCast( GetWXPeer() , wxListCtrl
);
2936 wxMacListCtrlItem
* lcItem
= NULL
;
2938 if (listColumn
>= 0)
2942 lcItem
= (wxMacListCtrlItem
*) itemID
;
2943 if (lcItem
&& lcItem
->HasColumnInfo(listColumn
)){
2944 wxListItem
* item
= lcItem
->GetColumnInfo(listColumn
);
2945 if (item
->GetMask() & wxLIST_MASK_TEXT
)
2946 text
= item
->GetText();
2947 if (item
->GetMask() & wxLIST_MASK_IMAGE
)
2948 imgIndex
= item
->GetImage();
2953 long itemNum
= (long)itemID
-1;
2954 if (itemNum
>= 0 && itemNum
< list
->GetItemCount())
2956 text
= list
->OnGetItemText( itemNum
, listColumn
);
2957 imgIndex
= list
->OnGetItemColumnImage( itemNum
, listColumn
);
2966 case kDataBrowserItemIsEditableProperty
:
2967 if ( list
&& list
->HasFlag( wxLC_EDIT_LABELS
) )
2969 verify_noerr(SetDataBrowserItemDataBooleanValue( itemData
, true ));
2974 if ( property
>= kMinColumnId
)
2976 if (!text
.IsEmpty()){
2977 wxCFStringRef
cfStr( text
, wxLocale::GetSystemEncoding() );
2978 err
= ::SetDataBrowserItemDataText( itemData
, cfStr
);
2984 if ( imgIndex
!= -1 )
2986 wxImageList
* imageList
= list
->GetImageList(wxIMAGE_LIST_SMALL
);
2987 if (imageList
&& imageList
->GetImageCount() > 0){
2988 wxBitmap bmp
= imageList
->GetBitmap(imgIndex
);
2989 IconRef icon
= bmp
.GetIconRef();
2990 ::SetDataBrowserItemDataIcon(itemData
, icon
);
3004 if ( property
>= kMinColumnId
)
3006 DataBrowserTableViewColumnIndex listColumn
= 0;
3007 verify_noerr( GetColumnPosition( property
, &listColumn
) );
3009 // TODO probably send the 'end edit' from here, as we
3010 // can then deal with the veto
3012 verify_noerr( GetDataBrowserItemDataText( itemData
, &sr
) ) ;
3013 wxCFStringRef
cfStr(sr
) ;;
3015 list
->SetItem( (long)itemData
-1 , listColumn
, cfStr
.AsString() ) ;
3019 lcItem
->SetColumnTextValue( listColumn
, cfStr
.AsString() );
3029 void wxMacDataBrowserListCtrlControl::ItemNotification(DataBrowserItemID itemID
,
3030 DataBrowserItemNotification message
,
3031 DataBrowserItemDataRef itemData
)
3033 wxMacListCtrlItem
*item
= NULL
;
3036 item
= (wxMacListCtrlItem
*) itemID
;
3039 // we want to depend on as little as possible to make sure tear-down of controls is safe
3040 if ( message
== kDataBrowserItemRemoved
)
3043 item
->Notification(this, message
, itemData
);
3046 else if ( message
== kDataBrowserItemAdded
)
3048 // we don't issue events on adding, the item is not really stored in the list yet, so we
3049 // avoid asserts by getting out now
3051 item
->Notification(this, message
, itemData
);
3055 wxListCtrl
*list
= wxDynamicCast( GetWXPeer() , wxListCtrl
);
3058 bool trigger
= false;
3060 wxListEvent
event( wxEVT_LIST_ITEM_SELECTED
, list
->GetId() );
3062 event
.SetEventObject( list
);
3063 if ( !list
->IsVirtual() )
3065 DataBrowserTableViewRowIndex result
= 0;
3066 verify_noerr( GetItemRow( itemID
, &result
) ) ;
3067 event
.m_itemIndex
= result
;
3071 event
.m_itemIndex
= (long)itemID
-1;
3073 event
.m_item
.m_itemId
= event
.m_itemIndex
;
3074 list
->GetItem(event
.m_item
);
3078 case kDataBrowserItemDeselected
:
3079 event
.SetEventType(wxEVT_LIST_ITEM_DESELECTED
);
3080 // as the generic implementation is also triggering this
3081 // event for single selection, we do the same (different than listbox)
3082 trigger
= !IsSelectionSuppressed();
3085 case kDataBrowserItemSelected
:
3086 trigger
= !IsSelectionSuppressed();
3090 case kDataBrowserItemDoubleClicked
:
3091 event
.SetEventType( wxEVT_LIST_ITEM_ACTIVATED
);
3095 case kDataBrowserEditStarted
:
3096 // TODO : how to veto ?
3097 event
.SetEventType( wxEVT_LIST_BEGIN_LABEL_EDIT
) ;
3101 case kDataBrowserEditStopped
:
3102 // TODO probably trigger only upon the value store callback, because
3103 // here IIRC we cannot veto
3104 event
.SetEventType( wxEVT_LIST_END_LABEL_EDIT
) ;
3114 // direct notification is not always having the listbox GetSelection() having in synch with event
3115 wxPostEvent( list
->GetEventHandler(), event
);
3120 Boolean
wxMacDataBrowserListCtrlControl::CompareItems(DataBrowserItemID itemOneID
,
3121 DataBrowserItemID itemTwoID
,
3122 DataBrowserPropertyID sortProperty
)
3125 bool retval
= false;
3127 wxString otherItemText
;
3129 long otherItemOrder
;
3131 DataBrowserTableViewColumnIndex colId
= 0;
3132 verify_noerr( GetColumnPosition( sortProperty
, &colId
) );
3134 wxListCtrl
* list
= wxDynamicCast( GetWXPeer() , wxListCtrl
);
3136 DataBrowserSortOrder sort
;
3137 verify_noerr(GetSortOrder(&sort
));
3143 wxMacListCtrlItem
* item
= (wxMacListCtrlItem
*)itemOneID
;
3144 wxMacListCtrlItem
* otherItem
= (wxMacListCtrlItem
*)itemTwoID
;
3146 itemOrder
= item
->GetOrder();
3147 otherItemOrder
= otherItem
->GetOrder();
3149 wxListCtrlCompare func
= list
->GetCompareFunc();
3155 if (item
&& item
->HasColumnInfo(0))
3156 item1
= item
->GetColumnInfo(0)->GetData();
3157 if (otherItem
&& otherItem
->HasColumnInfo(0))
3158 item2
= otherItem
->GetColumnInfo(0)->GetData();
3160 if (item1
> -1 && item2
> -1)
3162 int result
= func(item1
, item2
, list
->GetCompareFuncData());
3163 if (sort
== kDataBrowserOrderIncreasing
)
3170 // we can't use the native control's sorting abilities, so just
3172 return itemOrder
< otherItemOrder
;
3177 long itemNum
= (long)itemOneID
;
3178 long otherItemNum
= (long)itemTwoID
;
3180 // virtual listctrls don't support sorting
3181 return itemNum
< otherItemNum
;
3185 // fallback for undefined cases
3186 retval
= itemOneID
< itemTwoID
;
3192 wxMacDataBrowserListCtrlControl::~wxMacDataBrowserListCtrlControl()
3196 void wxMacDataBrowserListCtrlControl::MacSetColumnInfo( unsigned int row
, unsigned int column
, wxListItem
* item
)
3198 wxMacDataItem
* dataItem
= GetItemFromLine(row
);
3199 wxASSERT_MSG( dataItem
, wxT("could not obtain wxMacDataItem for row in MacSetColumnInfo. Is row a valid wxListCtrl row?") );
3202 wxMacListCtrlItem
* listItem
= static_cast<wxMacListCtrlItem
*>(dataItem
);
3203 bool hasInfo
= listItem
->HasColumnInfo( column
);
3204 listItem
->SetColumnInfo( column
, item
);
3205 listItem
->SetOrder(row
);
3206 UpdateState(dataItem
, item
);
3208 wxListCtrl
* list
= wxDynamicCast( GetWXPeer() , wxListCtrl
);
3210 // NB: When this call was made before a control was completely shown, it would
3211 // update the item prematurely (i.e. no text would be listed) and, on show,
3212 // only the sorted column would be refreshed, meaning only first column text labels
3213 // would be shown. Making sure not to update items until the control is visible
3214 // seems to fix this issue.
3215 if (hasInfo
&& list
->IsShown())
3217 DataBrowserTableViewColumnID id
= 0;
3218 verify_noerr( GetColumnIDFromIndex( column
, &id
) );
3219 UpdateItem( wxMacDataBrowserRootContainer
, listItem
, id
);
3224 // apply changes that need to happen immediately, rather than when the
3225 // databrowser control fires a callback.
3226 void wxMacDataBrowserListCtrlControl::UpdateState(wxMacDataItem
* dataItem
, wxListItem
* listItem
)
3228 bool isSelected
= IsItemSelected( dataItem
);
3229 bool isSelectedState
= (listItem
->GetState() == wxLIST_STATE_SELECTED
);
3231 // toggle the selection state if wxListInfo state and actual state don't match.
3232 if ( listItem
->GetMask() & wxLIST_MASK_STATE
&& isSelected
!= isSelectedState
)
3234 DataBrowserSetOption options
= kDataBrowserItemsAdd
;
3235 if (!isSelectedState
)
3236 options
= kDataBrowserItemsRemove
;
3237 SetSelectedItem(dataItem
, options
);
3239 // TODO: Set column width if item width > than current column width
3242 void wxMacDataBrowserListCtrlControl::MacGetColumnInfo( unsigned int row
, unsigned int column
, wxListItem
& item
)
3244 wxMacDataItem
* dataItem
= GetItemFromLine(row
);
3245 wxASSERT_MSG( dataItem
, wxT("could not obtain wxMacDataItem in MacGetColumnInfo. Is row a valid wxListCtrl row?") );
3246 // CS should this guard against dataItem = 0 ? , as item is not a pointer if (item) is not appropriate
3249 wxMacListCtrlItem
* listItem
= static_cast<wxMacListCtrlItem
*>(dataItem
);
3251 if (!listItem
->HasColumnInfo( column
))
3254 wxListItem
* oldItem
= listItem
->GetColumnInfo( column
);
3258 long mask
= item
.GetMask();
3260 // by default, get everything for backwards compatibility
3263 if ( mask
& wxLIST_MASK_TEXT
)
3264 item
.SetText(oldItem
->GetText());
3265 if ( mask
& wxLIST_MASK_IMAGE
)
3266 item
.SetImage(oldItem
->GetImage());
3267 if ( mask
& wxLIST_MASK_DATA
)
3268 item
.SetData(oldItem
->GetData());
3269 if ( mask
& wxLIST_MASK_STATE
)
3270 item
.SetState(oldItem
->GetState());
3271 if ( mask
& wxLIST_MASK_WIDTH
)
3272 item
.SetWidth(oldItem
->GetWidth());
3273 if ( mask
& wxLIST_MASK_FORMAT
)
3274 item
.SetAlign(oldItem
->GetAlign());
3276 item
.SetTextColour(oldItem
->GetTextColour());
3277 item
.SetBackgroundColour(oldItem
->GetBackgroundColour());
3278 item
.SetFont(oldItem
->GetFont());
3283 void wxMacDataBrowserListCtrlControl::MacInsertItem( unsigned int n
, wxListItem
* item
)
3286 wxMacDataItemBrowserControl::MacInsert(n
, new wxMacListCtrlItem() );
3287 MacSetColumnInfo(n
, 0, item
);
3290 wxMacListCtrlItem::wxMacListCtrlItem()
3292 m_rowItems
= wxListItemList();
3295 int wxMacListCtrlItem::GetColumnImageValue( unsigned int column
)
3297 if ( HasColumnInfo(column
) )
3298 return GetColumnInfo(column
)->GetImage();
3303 void wxMacListCtrlItem::SetColumnImageValue( unsigned int column
, int imageIndex
)
3305 if ( HasColumnInfo(column
) )
3306 GetColumnInfo(column
)->SetImage(imageIndex
);
3309 wxString
wxMacListCtrlItem::GetColumnTextValue( unsigned int column
)
3311 /* TODO CHECK REMOVE
3315 if ( HasColumnInfo(column
) )
3316 return GetColumnInfo(column
)->GetText();
3318 return wxEmptyString
;
3321 void wxMacListCtrlItem::SetColumnTextValue( unsigned int column
, const wxString
& text
)
3323 if ( HasColumnInfo(column
) )
3324 GetColumnInfo(column
)->SetText(text
);
3326 /* TODO CHECK REMOVE
3327 // for compatibility with superclass APIs
3333 wxListItem
* wxMacListCtrlItem::GetColumnInfo( unsigned int column
)
3335 wxASSERT_MSG( HasColumnInfo(column
), wxT("invalid column index in wxMacListCtrlItem") );
3336 return m_rowItems
[column
];
3339 bool wxMacListCtrlItem::HasColumnInfo( unsigned int column
)
3341 return !(m_rowItems
.find( column
) == m_rowItems
.end());
3344 void wxMacListCtrlItem::SetColumnInfo( unsigned int column
, wxListItem
* item
)
3347 if ( !HasColumnInfo(column
) )
3349 wxListItem
* listItem
= new wxListItem(*item
);
3350 m_rowItems
[column
] = listItem
;
3354 wxListItem
* listItem
= GetColumnInfo( column
);
3355 long mask
= item
->GetMask();
3356 if (mask
& wxLIST_MASK_TEXT
)
3357 listItem
->SetText(item
->GetText());
3358 if (mask
& wxLIST_MASK_DATA
)
3359 listItem
->SetData(item
->GetData());
3360 if (mask
& wxLIST_MASK_IMAGE
)
3361 listItem
->SetImage(item
->GetImage());
3362 if (mask
& wxLIST_MASK_STATE
)
3363 listItem
->SetState(item
->GetState());
3364 if (mask
& wxLIST_MASK_FORMAT
)
3365 listItem
->SetAlign(item
->GetAlign());
3366 if (mask
& wxLIST_MASK_WIDTH
)
3367 listItem
->SetWidth(item
->GetWidth());
3369 if ( item
->HasAttributes() )
3371 if ( listItem
->HasAttributes() )
3372 listItem
->GetAttributes()->AssignFrom(*item
->GetAttributes());
3375 listItem
->SetTextColour(item
->GetTextColour());
3376 listItem
->SetBackgroundColour(item
->GetBackgroundColour());
3377 listItem
->SetFont(item
->GetFont());
3383 int wxListCtrl::CalcColumnAutoWidth(int col
) const
3387 for ( int i
= 0; i
< GetItemCount(); i
++ )
3390 info
.SetMask(wxLIST_MASK_TEXT
| wxLIST_MASK_IMAGE
);
3392 info
.SetColumn(col
);
3395 const wxFont font
= info
.GetFont();
3399 GetTextExtent(info
.GetText(), &w
, NULL
, NULL
, NULL
, &font
);
3401 GetTextExtent(info
.GetText(), &w
, NULL
);
3403 w
+= 2 * kItemPadding
;
3405 if ( info
.GetImage() != -1 )
3408 width
= wxMax(width
, w
);
3414 #endif // wxUSE_LISTCTRL