1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/osx/listctrl_mac.cpp
4 // Author: Julian Smart
5 // Modified by: Agron Selimaj
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 // ============================================================================
14 // ============================================================================
16 // ----------------------------------------------------------------------------
18 // ----------------------------------------------------------------------------
20 // For compilers that support precompilation, includes "wx.h".
21 #include "wx/wxprec.h"
29 #include "wx/listctrl.h"
33 #include "wx/settings.h"
36 #include "wx/osx/uma.h"
38 #include "wx/imaglist.h"
39 #include "wx/sysopt.h"
42 #include "wx/hashmap.h"
44 WX_DECLARE_HASH_MAP( int, wxListItem
*, wxIntegerHash
, wxIntegerEqual
, wxListItemList
);
46 #include "wx/listimpl.cpp"
47 WX_DEFINE_LIST(wxColumnList
)
49 // so we can check for column clicks
50 static const EventTypeSpec eventList
[] =
52 { kEventClassControl
, kEventControlHit
},
53 { kEventClassControl
, kEventControlDraw
}
56 static pascal OSStatus
wxMacListCtrlEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
58 OSStatus result
= eventNotHandledErr
;
60 wxMacCarbonEvent
cEvent( event
) ;
62 ControlRef controlRef
;
63 cEvent
.GetParameter( kEventParamDirectObject
, &controlRef
) ;
65 wxListCtrl
*window
= (wxListCtrl
*) data
;
66 wxListEvent
le( wxEVT_LIST_COL_CLICK
, window
->GetId() );
67 le
.SetEventObject( window
);
69 switch ( GetEventKind( event
) )
71 // check if the column was clicked on and fire an event if so
72 case kEventControlHit
:
74 ControlPartCode result
= cEvent
.GetParameter
<ControlPartCode
>(kEventParamControlPart
, typeControlPartCode
) ;
75 if (result
== kControlButtonPart
){
76 DataBrowserPropertyID col
;
77 GetDataBrowserSortProperty(controlRef
, &col
);
79 DataBrowserTableViewColumnIndex column
= 0;
80 verify_noerr( GetDataBrowserTableViewColumnPosition( controlRef
, col
, &column
) );
83 // FIXME: we can't use the sort property for virtual listctrls
84 // so we need to find a better way to determine which column was clicked...
85 if (!window
->IsVirtual())
86 window
->HandleWindowEvent( le
);
88 result
= CallNextEventHandler(handler
, event
);
91 case kEventControlDraw
:
93 CGContextRef context
= cEvent
.GetParameter
<CGContextRef
>(kEventParamCGContextRef
, typeCGContextRef
) ;
94 window
->MacSetDrawingContext(context
);
95 result
= CallNextEventHandler(handler
, event
);
96 window
->MacSetDrawingContext(NULL
);
107 DEFINE_ONE_SHOT_HANDLER_GETTER( wxMacListCtrlEventHandler
)
109 class wxMacListCtrlItem
: public wxMacDataItem
114 virtual void Notification(wxMacDataItemBrowserControl
*owner
,
115 DataBrowserItemNotification message
,
116 DataBrowserItemDataRef itemData
) const;
118 virtual void SetColumnInfo( unsigned int column
, wxListItem
* item
);
119 virtual wxListItem
* GetColumnInfo( unsigned int column
);
120 virtual bool HasColumnInfo( unsigned int column
);
122 virtual void SetColumnTextValue( unsigned int column
, const wxString
& text
);
123 virtual wxString
GetColumnTextValue( unsigned int column
);
125 virtual int GetColumnImageValue( unsigned int column
);
126 virtual void SetColumnImageValue( unsigned int column
, int imageIndex
);
128 virtual ~wxMacListCtrlItem();
130 wxListItemList m_rowItems
;
133 DataBrowserDrawItemUPP gDataBrowserDrawItemUPP
= NULL
;
134 //DataBrowserEditItemUPP gDataBrowserEditItemUPP = NULL;
135 DataBrowserHitTestUPP gDataBrowserHitTestUPP
= NULL
;
137 // TODO: Make a better name!!
138 class wxMacDataBrowserListCtrlControl
: public wxMacDataItemBrowserControl
141 wxMacDataBrowserListCtrlControl( wxWindow
*peer
, const wxPoint
& pos
, const wxSize
& size
, long style
);
142 wxMacDataBrowserListCtrlControl() {}
143 virtual ~wxMacDataBrowserListCtrlControl();
145 // create a list item (can be a subclass of wxMacListBoxItem)
147 virtual void MacInsertItem( unsigned int n
, wxListItem
* item
);
148 virtual void MacSetColumnInfo( unsigned int row
, unsigned int column
, wxListItem
* item
);
149 virtual void MacGetColumnInfo( unsigned int row
, unsigned int column
, wxListItem
& item
);
150 virtual void UpdateState(wxMacDataItem
* dataItem
, wxListItem
* item
);
151 int GetFlags() { return m_flags
; }
154 // we need to override to provide specialized handling for virtual wxListCtrls
155 virtual OSStatus
GetSetItemData(DataBrowserItemID itemID
,
156 DataBrowserPropertyID property
,
157 DataBrowserItemDataRef itemData
,
158 Boolean changeValue
);
160 virtual void ItemNotification(
161 DataBrowserItemID itemID
,
162 DataBrowserItemNotification message
,
163 DataBrowserItemDataRef itemData
);
165 virtual Boolean
CompareItems(DataBrowserItemID itemOneID
,
166 DataBrowserItemID itemTwoID
,
167 DataBrowserPropertyID sortProperty
);
169 static pascal void DataBrowserDrawItemProc(ControlRef browser
,
170 DataBrowserItemID item
,
171 DataBrowserPropertyID property
,
172 DataBrowserItemState itemState
,
175 Boolean colorDevice
);
177 virtual void DrawItem(DataBrowserItemID itemID
,
178 DataBrowserPropertyID property
,
179 DataBrowserItemState itemState
,
180 const Rect
*itemRect
,
182 Boolean colorDevice
);
184 static pascal Boolean
DataBrowserEditTextProc(ControlRef browser
,
185 DataBrowserItemID item
,
186 DataBrowserPropertyID property
,
187 CFStringRef theString
,
188 Rect
*maxEditTextRect
,
189 Boolean
*shrinkToFit
);
191 static pascal Boolean
DataBrowserHitTestProc(ControlRef
WXUNUSED(browser
),
192 DataBrowserItemID
WXUNUSED(itemID
),
193 DataBrowserPropertyID
WXUNUSED(property
),
194 const Rect
*WXUNUSED(theRect
),
195 const Rect
*WXUNUSED(mouseRect
)) { return true; }
197 virtual bool ConfirmEditText(DataBrowserItemID item
,
198 DataBrowserPropertyID property
,
199 CFStringRef theString
,
200 Rect
*maxEditTextRect
,
201 Boolean
*shrinkToFit
);
205 wxClientDataType m_clientDataItemsType
;
208 DECLARE_DYNAMIC_CLASS_NO_COPY(wxMacDataBrowserListCtrlControl
)
211 class wxMacListCtrlEventDelegate
: public wxEvtHandler
214 wxMacListCtrlEventDelegate( wxListCtrl
* list
, int id
);
215 virtual bool ProcessEvent( wxEvent
& event
);
222 wxMacListCtrlEventDelegate::wxMacListCtrlEventDelegate( wxListCtrl
* list
, int id
)
228 bool wxMacListCtrlEventDelegate::ProcessEvent( wxEvent
& event
)
230 int id
= event
.GetId();
231 wxObject
* obj
= event
.GetEventObject();
233 // even though we use a generic list ctrl underneath, make sure
234 // we present ourselves as wxListCtrl.
235 event
.SetEventObject( m_list
);
238 if ( !event
.IsKindOf( CLASSINFO( wxCommandEvent
) ) )
240 if (m_list
->GetEventHandler()->ProcessEvent( event
))
243 event
.SetEventObject(obj
);
247 // Also try with the original id
248 bool success
= wxEvtHandler::ProcessEvent(event
);
250 event
.SetEventObject(obj
);
251 if (!success
&& id
!= m_id
)
252 success
= wxEvtHandler::ProcessEvent(event
);
256 //-----------------------------------------------------------------------------
257 // wxListCtrlRenameTimer (internal)
258 //-----------------------------------------------------------------------------
260 class wxListCtrlRenameTimer
: public wxTimer
266 wxListCtrlRenameTimer( wxListCtrl
*owner
);
270 //-----------------------------------------------------------------------------
271 // wxListCtrlTextCtrlWrapper: wraps a wxTextCtrl to make it work for inline editing
272 //-----------------------------------------------------------------------------
274 class wxListCtrlTextCtrlWrapper
: public wxEvtHandler
277 // NB: text must be a valid object but not Create()d yet
278 wxListCtrlTextCtrlWrapper(wxListCtrl
*owner
,
282 wxTextCtrl
*GetText() const { return m_text
; }
284 void AcceptChangesAndFinish();
287 void OnChar( wxKeyEvent
&event
);
288 void OnKeyUp( wxKeyEvent
&event
);
289 void OnKillFocus( wxFocusEvent
&event
);
291 bool AcceptChanges();
297 wxString m_startValue
;
300 bool m_aboutToFinish
;
302 DECLARE_EVENT_TABLE()
305 //-----------------------------------------------------------------------------
306 // wxListCtrlRenameTimer (internal)
307 //-----------------------------------------------------------------------------
309 wxListCtrlRenameTimer::wxListCtrlRenameTimer( wxListCtrl
*owner
)
314 void wxListCtrlRenameTimer::Notify()
316 m_owner
->OnRenameTimer();
319 //-----------------------------------------------------------------------------
320 // wxListCtrlTextCtrlWrapper (internal)
321 //-----------------------------------------------------------------------------
323 BEGIN_EVENT_TABLE(wxListCtrlTextCtrlWrapper
, wxEvtHandler
)
324 EVT_CHAR (wxListCtrlTextCtrlWrapper::OnChar
)
325 EVT_KEY_UP (wxListCtrlTextCtrlWrapper::OnKeyUp
)
326 EVT_KILL_FOCUS (wxListCtrlTextCtrlWrapper::OnKillFocus
)
329 wxListCtrlTextCtrlWrapper::wxListCtrlTextCtrlWrapper(wxListCtrl
*owner
,
332 : m_startValue(owner
->GetItemText(itemEdit
)),
333 m_itemEdited(itemEdit
)
338 m_aboutToFinish
= false;
342 owner
->GetItemRect(itemEdit
, rectLabel
);
344 m_text
->Create(owner
, wxID_ANY
, m_startValue
,
345 wxPoint(rectLabel
.x
+offset
,rectLabel
.y
),
346 wxSize(rectLabel
.width
-offset
,rectLabel
.height
));
349 m_text
->PushEventHandler(this);
352 void wxListCtrlTextCtrlWrapper::Finish()
358 m_text
->RemoveEventHandler(this);
359 m_owner
->FinishEditing(m_text
);
361 wxPendingDelete
.Append( this );
365 bool wxListCtrlTextCtrlWrapper::AcceptChanges()
367 const wxString value
= m_text
->GetValue();
369 if ( value
== m_startValue
)
370 // nothing changed, always accept
373 if ( !m_owner
->OnRenameAccept(m_itemEdited
, value
) )
374 // vetoed by the user
377 // accepted, do rename the item
378 m_owner
->SetItemText(m_itemEdited
, value
);
383 void wxListCtrlTextCtrlWrapper::AcceptChangesAndFinish()
385 m_aboutToFinish
= true;
387 // Notify the owner about the changes
390 // Even if vetoed, close the control (consistent with MSW)
394 void wxListCtrlTextCtrlWrapper::OnChar( wxKeyEvent
&event
)
396 switch ( event
.m_keyCode
)
399 AcceptChangesAndFinish();
403 m_owner
->OnRenameCancelled( m_itemEdited
);
412 void wxListCtrlTextCtrlWrapper::OnKeyUp( wxKeyEvent
&event
)
420 // auto-grow the textctrl:
421 wxSize parentSize
= m_owner
->GetSize();
422 wxPoint myPos
= m_text
->GetPosition();
423 wxSize mySize
= m_text
->GetSize();
425 m_text
->GetTextExtent(m_text
->GetValue() + wxT("MM"), &sx
, &sy
);
426 if (myPos
.x
+ sx
> parentSize
.x
)
427 sx
= parentSize
.x
- myPos
.x
;
430 m_text
->SetSize(sx
, wxDefaultCoord
);
435 void wxListCtrlTextCtrlWrapper::OnKillFocus( wxFocusEvent
&event
)
437 if ( !m_finished
&& !m_aboutToFinish
)
439 if ( !AcceptChanges() )
440 m_owner
->OnRenameCancelled( m_itemEdited
);
445 // We must let the native text control handle focus
449 // ============================================================================
451 // ============================================================================
453 wxMacDataBrowserListCtrlControl
* wxListCtrl::GetListPeer() const
455 return dynamic_cast<wxMacDataBrowserListCtrlControl
*> ( GetPeer() );
458 // ----------------------------------------------------------------------------
459 // wxListCtrl construction
460 // ----------------------------------------------------------------------------
462 void wxListCtrl::Init()
464 m_imageListNormal
= NULL
;
465 m_imageListSmall
= NULL
;
466 m_imageListState
= NULL
;
468 // keep track of if we created our own image lists, or if they were assigned
470 m_ownsImageListNormal
= m_ownsImageListSmall
= m_ownsImageListState
= false;
474 m_genericImpl
= NULL
;
476 m_compareFunc
= NULL
;
477 m_compareFuncData
= 0;
478 m_colsInfo
= wxColumnList();
479 m_textColor
= wxNullColour
;
480 m_bgColor
= wxNullColour
;
481 m_textctrlWrapper
= NULL
;
483 m_renameTimer
= NULL
;
486 class wxGenericListCtrlHook
: public wxGenericListCtrl
489 wxGenericListCtrlHook(wxListCtrl
* parent
,
494 const wxValidator
& validator
,
495 const wxString
& name
)
496 : wxGenericListCtrl(parent
, id
, pos
, size
, style
, validator
, name
),
497 m_nativeListCtrl(parent
)
502 virtual wxListItemAttr
* OnGetItemAttr(long item
) const
504 return m_nativeListCtrl
->OnGetItemAttr(item
);
507 virtual int OnGetItemImage(long item
) const
509 return m_nativeListCtrl
->OnGetItemImage(item
);
512 virtual int OnGetItemColumnImage(long item
, long column
) const
514 return m_nativeListCtrl
->OnGetItemColumnImage(item
, column
);
517 virtual wxString
OnGetItemText(long item
, long column
) const
519 return m_nativeListCtrl
->OnGetItemText(item
, column
);
522 wxListCtrl
* m_nativeListCtrl
;
526 void wxListCtrl::OnLeftDown(wxMouseEvent
& event
)
528 if ( m_textctrlWrapper
)
531 m_textctrlWrapper
->AcceptChangesAndFinish();
535 long current
= HitTest(event
.GetPosition(), hitResult
);
536 if ((current
== m_current
) &&
537 (hitResult
& wxLIST_HITTEST_ONITEMLABEL
) &&
538 HasFlag(wxLC_EDIT_LABELS
) )
541 m_renameTimer
->Start( 250, true );
550 void wxListCtrl::OnDblClick(wxMouseEvent
& event
)
552 if ( m_renameTimer
&& m_renameTimer
->IsRunning() )
553 m_renameTimer
->Stop();
557 #if wxABI_VERSION >= 20801
558 void wxListCtrl::OnRightDown(wxMouseEvent
& event
)
561 FireMouseEvent(wxEVT_LIST_ITEM_RIGHT_CLICK
, event
.GetPosition());
565 void wxListCtrl::OnMiddleDown(wxMouseEvent
& event
)
568 FireMouseEvent(wxEVT_LIST_ITEM_MIDDLE_CLICK
, event
.GetPosition());
572 void wxListCtrl::FireMouseEvent(wxEventType eventType
, wxPoint position
)
574 wxListEvent
le( eventType
, GetId() );
575 le
.SetEventObject(this);
576 le
.m_pointDrag
= position
;
580 long item
= HitTest(position
, flags
);
581 if (flags
& wxLIST_HITTEST_ONITEM
)
583 le
.m_itemIndex
= item
;
584 le
.m_item
.m_itemId
= item
;
586 HandleWindowEvent(le
);
590 void wxListCtrl::OnChar(wxKeyEvent
& event
)
596 wxListEvent
le( wxEVT_LIST_KEY_DOWN
, GetId() );
597 le
.SetEventObject(this);
598 le
.m_code
= event
.GetKeyCode();
603 // if m_current isn't set, check if there's been a selection
604 // made before continuing
605 m_current
= GetNextItem(-1, wxLIST_NEXT_BELOW
, wxLIST_STATE_SELECTED
);
608 // We need to determine m_current ourselves when navigation keys
609 // are used. Note that PAGEUP and PAGEDOWN do not alter the current
610 // item on native Mac ListCtrl, so we only handle up and down keys.
611 switch ( event
.GetKeyCode() )
622 if ( m_current
< GetItemCount() - 1 )
625 m_current
= GetItemCount() - 1;
632 le
.m_itemIndex
= m_current
;
633 le
.m_item
.m_itemId
= m_current
;
635 HandleWindowEvent(le
);
642 bool wxListCtrl::Create(wxWindow
*parent
,
647 const wxValidator
& validator
,
648 const wxString
& name
)
651 // for now, we'll always use the generic list control for ICON and LIST views,
652 // because they dynamically change the number of columns on resize.
653 // Also, allow the user to set it to use the list ctrl as well.
654 if ( (wxSystemOptions::HasOption( wxMAC_ALWAYS_USE_GENERIC_LISTCTRL
)
655 && (wxSystemOptions::GetOptionInt( wxMAC_ALWAYS_USE_GENERIC_LISTCTRL
) == 1)) ||
656 (style
& wxLC_ICON
) || (style
& wxLC_SMALL_ICON
) || (style
& wxLC_LIST
) )
658 long paneStyle
= style
;
659 paneStyle
&= ~wxSIMPLE_BORDER
;
660 paneStyle
&= ~wxDOUBLE_BORDER
;
661 paneStyle
&= ~wxSUNKEN_BORDER
;
662 paneStyle
&= ~wxRAISED_BORDER
;
663 paneStyle
&= ~wxSTATIC_BORDER
;
664 if ( !wxWindow::Create(parent
, id
, pos
, size
, paneStyle
| wxNO_BORDER
, name
) )
667 // since the generic control is a child, make sure we position it at 0, 0
668 m_genericImpl
= new wxGenericListCtrlHook(this, id
, wxPoint(0, 0), size
, style
, validator
, name
);
669 m_genericImpl
->PushEventHandler( new wxMacListCtrlEventDelegate( this, GetId() ) );
676 if ( !wxWindow::Create(parent
, id
, pos
, size
, style
& ~(wxHSCROLL
| wxVSCROLL
), name
) )
678 m_dbImpl
= new wxMacDataBrowserListCtrlControl( this, pos
, size
, style
);
681 MacPostControlCreate( pos
, size
);
683 InstallControlEventHandler( GetPeer()->GetControlRef() , GetwxMacListCtrlEventHandlerUPP(),
684 GetEventTypeCount(eventList
), eventList
, this,
685 (EventHandlerRef
*)&m_macListCtrlEventHandler
);
687 m_renameTimer
= new wxListCtrlRenameTimer( this );
689 Connect( wxID_ANY
, wxEVT_CHAR
, wxCharEventHandler(wxListCtrl::OnChar
), NULL
, this );
690 Connect( wxID_ANY
, wxEVT_LEFT_DOWN
, wxMouseEventHandler(wxListCtrl::OnLeftDown
), NULL
, this );
691 Connect( wxID_ANY
, wxEVT_LEFT_DCLICK
, wxMouseEventHandler(wxListCtrl::OnDblClick
), NULL
, this );
692 Connect( wxID_ANY
, wxEVT_MIDDLE_DOWN
, wxMouseEventHandler(wxListCtrl::OnMiddleDown
), NULL
, this );
693 Connect( wxID_ANY
, wxEVT_RIGHT_DOWN
, wxMouseEventHandler(wxListCtrl::OnRightDown
), NULL
, this );
699 wxListCtrl::~wxListCtrl()
703 m_genericImpl
->PopEventHandler(/* deleteHandler = */ true);
706 if (m_ownsImageListNormal
)
707 delete m_imageListNormal
;
708 if (m_ownsImageListSmall
)
709 delete m_imageListSmall
;
710 if (m_ownsImageListState
)
711 delete m_imageListState
;
713 delete m_renameTimer
;
715 WX_CLEAR_LIST(wxColumnList
, m_colsInfo
);
720 wxListCtrl::GetClassDefaultAttributes(wxWindowVariant
WXUNUSED(variant
))
722 wxVisualAttributes attr
;
724 attr
.colFg
= wxSystemSettings::GetColour( wxSYS_COLOUR_WINDOWTEXT
);
725 attr
.colBg
= wxSystemSettings::GetColour( wxSYS_COLOUR_LISTBOX
);
726 static wxFont font
= wxFont(wxOSX_SYSTEM_FONT_VIEWS
);
732 // ----------------------------------------------------------------------------
733 // set/get/change style
734 // ----------------------------------------------------------------------------
736 // Add or remove a single window style
737 void wxListCtrl::SetSingleStyle(long style
, bool add
)
739 long flag
= GetWindowStyleFlag();
741 // Get rid of conflicting styles
744 if ( style
& wxLC_MASK_TYPE
)
745 flag
= flag
& ~wxLC_MASK_TYPE
;
746 if ( style
& wxLC_MASK_ALIGN
)
747 flag
= flag
& ~wxLC_MASK_ALIGN
;
748 if ( style
& wxLC_MASK_SORT
)
749 flag
= flag
& ~wxLC_MASK_SORT
;
757 SetWindowStyleFlag(flag
);
760 // Set the whole window style
761 void wxListCtrl::SetWindowStyleFlag(long flag
)
763 if ( flag
!= m_windowStyle
)
765 m_windowStyle
= flag
;
769 m_genericImpl
->SetWindowStyleFlag(flag
);
776 void wxListCtrl::DoSetSize( int x
, int y
, int width
, int height
, int sizeFlags
)
778 wxListCtrlBase::DoSetSize(x
, y
, width
, height
, sizeFlags
);
781 m_genericImpl
->SetSize(0, 0, width
, height
, sizeFlags
);
783 // determine if we need a horizontal scrollbar, and add it if so
787 for (int column
= 0; column
< GetColumnCount(); column
++)
789 totalWidth
+= m_dbImpl
->GetColumnWidth( column
);
792 if ( !(m_dbImpl
->GetFlags() & wxHSCROLL
) )
794 Boolean vertScrollBar
;
795 GetDataBrowserHasScrollBars( m_dbImpl
->GetControlRef(), NULL
, &vertScrollBar
);
796 if (totalWidth
> width
)
797 SetDataBrowserHasScrollBars( m_dbImpl
->GetControlRef(), true, vertScrollBar
);
799 SetDataBrowserHasScrollBars( m_dbImpl
->GetControlRef(), false, vertScrollBar
);
804 bool wxListCtrl::SetFont(const wxFont
& font
)
806 bool rv
= wxListCtrlBase::SetFont(font
);
808 rv
= m_genericImpl
->SetFont(font
);
812 bool wxListCtrl::SetForegroundColour(const wxColour
& colour
)
816 rv
= m_genericImpl
->SetForegroundColour(colour
);
818 SetTextColour(colour
);
822 bool wxListCtrl::SetBackgroundColour(const wxColour
& colour
)
826 rv
= m_genericImpl
->SetBackgroundColour(colour
);
832 wxColour
wxListCtrl::GetBackgroundColour() const
835 return m_genericImpl
->GetBackgroundColour();
842 void wxListCtrl::Freeze ()
845 m_genericImpl
->Freeze();
846 wxListCtrlBase::Freeze();
849 void wxListCtrl::Thaw ()
852 m_genericImpl
->Thaw();
853 wxListCtrlBase::Thaw();
856 void wxListCtrl::Update ()
859 m_genericImpl
->Update();
860 wxListCtrlBase::Update();
863 // ----------------------------------------------------------------------------
865 // ----------------------------------------------------------------------------
867 // Gets information about this column
868 bool wxListCtrl::GetColumn(int col
, wxListItem
& item
) const
871 return m_genericImpl
->GetColumn(col
, item
);
877 wxColumnList::compatibility_iterator node
= m_colsInfo
.Item( col
);
878 wxASSERT_MSG( node
, wxT("invalid column index in wxMacListCtrlItem") );
879 wxListItem
* column
= node
->GetData();
881 long mask
= column
->GetMask();
882 if (mask
& wxLIST_MASK_TEXT
)
883 item
.SetText(column
->GetText());
884 if (mask
& wxLIST_MASK_DATA
)
885 item
.SetData(column
->GetData());
886 if (mask
& wxLIST_MASK_IMAGE
)
887 item
.SetImage(column
->GetImage());
888 if (mask
& wxLIST_MASK_STATE
)
889 item
.SetState(column
->GetState());
890 if (mask
& wxLIST_MASK_FORMAT
)
891 item
.SetAlign(column
->GetAlign());
892 if (mask
& wxLIST_MASK_WIDTH
)
893 item
.SetWidth(column
->GetWidth());
899 // Sets information about this column
900 bool wxListCtrl::SetColumn(int col
, const wxListItem
& item
)
903 return m_genericImpl
->SetColumn(col
, item
);
907 wxASSERT_MSG( col
< (int)m_colsInfo
.GetCount(), wxT("invalid column index in wxMacListCtrlItem") );
909 long mask
= item
.GetMask();
912 GetColumn( col
, listItem
);
914 if (mask
& wxLIST_MASK_TEXT
)
915 listItem
.SetText(item
.GetText());
916 if (mask
& wxLIST_MASK_DATA
)
917 listItem
.SetData(item
.GetData());
918 if (mask
& wxLIST_MASK_IMAGE
)
919 listItem
.SetImage(item
.GetImage());
920 if (mask
& wxLIST_MASK_STATE
)
921 listItem
.SetState(item
.GetState());
922 if (mask
& wxLIST_MASK_FORMAT
)
923 listItem
.SetAlign(item
.GetAlign());
924 if (mask
& wxLIST_MASK_WIDTH
)
925 listItem
.SetWidth(item
.GetWidth());
928 // change the appearance in the databrowser.
929 DataBrowserListViewHeaderDesc columnDesc
;
930 columnDesc
.version
=kDataBrowserListViewLatestHeaderDesc
;
932 DataBrowserTableViewColumnID id
= 0;
933 verify_noerr( m_dbImpl
->GetColumnIDFromIndex( col
, &id
) );
934 verify_noerr( m_dbImpl
->GetHeaderDesc( id
, &columnDesc
) );
937 if (item.GetMask() & wxLIST_MASK_TEXT)
941 enc = GetFont().GetEncoding();
943 enc = wxLocale::GetSystemEncoding();
944 wxCFStringRef cfTitle;
945 cfTitle.Assign( item.GetText() , enc );
946 if(columnDesc.titleString)
947 CFRelease(columnDesc.titleString);
948 columnDesc.titleString = cfTitle;
952 if (item
.GetMask() & wxLIST_MASK_IMAGE
&& item
.GetImage() != -1 )
954 wxImageList
* imageList
= GetImageList(wxIMAGE_LIST_SMALL
);
955 if (imageList
&& imageList
->GetImageCount() > 0 )
957 wxBitmap bmp
= imageList
->GetBitmap( item
.GetImage() );
958 IconRef icon
= bmp
.GetIconRef();
959 columnDesc
.btnContentInfo
.u
.iconRef
= icon
;
960 columnDesc
.btnContentInfo
.contentType
= kControlContentIconRef
;
964 verify_noerr( m_dbImpl
->SetHeaderDesc( id
, &columnDesc
) );
970 int wxListCtrl::GetColumnCount() const
973 return m_genericImpl
->GetColumnCount();
978 m_dbImpl
->GetColumnCount(&count
);
985 // Gets the column width
986 int wxListCtrl::GetColumnWidth(int col
) const
989 return m_genericImpl
->GetColumnWidth(col
);
993 return m_dbImpl
->GetColumnWidth(col
);
999 // Sets the column width
1000 bool wxListCtrl::SetColumnWidth(int col
, int width
)
1003 return m_genericImpl
->SetColumnWidth(col
, width
);
1007 if ( width
== wxLIST_AUTOSIZE_USEHEADER
)
1009 width
= 150; // FIXME
1014 for (int column
= 0; column
< GetColumnCount(); column
++)
1017 GetColumn(column
, colInfo
);
1019 colInfo
.SetWidth(width
);
1020 SetColumn(column
, colInfo
);
1022 const int mywidth
= (width
== wxLIST_AUTOSIZE
)
1023 ? CalcColumnAutoWidth(column
) : width
;
1024 m_dbImpl
->SetColumnWidth(column
, mywidth
);
1029 if ( width
== wxLIST_AUTOSIZE
)
1030 width
= CalcColumnAutoWidth(col
);
1033 GetColumn(col
, colInfo
);
1035 colInfo
.SetWidth(width
);
1036 SetColumn(col
, colInfo
);
1037 m_dbImpl
->SetColumnWidth(col
, width
);
1045 // Gets the number of items that can fit vertically in the
1046 // visible area of the list control (list or report view)
1047 // or the total number of items in the list control (icon
1048 // or small icon view)
1049 int wxListCtrl::GetCountPerPage() const
1052 return m_genericImpl
->GetCountPerPage();
1057 m_dbImpl
->GetDefaultRowHeight( &height
);
1059 return GetClientSize().y
/ height
;
1065 // Gets the edit control for editing labels.
1066 wxTextCtrl
* wxListCtrl::GetEditControl() const
1069 return m_genericImpl
->GetEditControl();
1074 // Gets information about the item
1075 bool wxListCtrl::GetItem(wxListItem
& info
) const
1078 return m_genericImpl
->GetItem(info
);
1084 if (info
.m_itemId
>= 0 && info
.m_itemId
< GetItemCount())
1086 m_dbImpl
->MacGetColumnInfo(info
.m_itemId
, info
.m_col
, info
);
1087 // MacGetColumnInfo returns erroneous information in the state field, so zero it.
1089 if (info
.GetMask() & wxLIST_MASK_STATE
)
1091 DataBrowserItemID id
= (DataBrowserItemID
)m_dbImpl
->GetItemFromLine(info
.m_itemId
);
1092 if (IsDataBrowserItemSelected( m_dbImpl
->GetControlRef(), id
))
1093 info
.SetState(info
.GetState() | wxLIST_STATE_SELECTED
);
1099 if (info
.m_itemId
>= 0 && info
.m_itemId
< GetItemCount())
1101 info
.SetText( OnGetItemText(info
.m_itemId
, info
.m_col
) );
1102 info
.SetImage( OnGetItemColumnImage(info
.m_itemId
, info
.m_col
) );
1103 if (info
.GetMask() & wxLIST_MASK_STATE
)
1105 if (IsDataBrowserItemSelected( m_dbImpl
->GetControlRef(), info
.m_itemId
+1 ))
1106 info
.SetState(info
.GetState() | wxLIST_STATE_SELECTED
);
1109 wxListItemAttr
* attrs
= OnGetItemAttr( info
.m_itemId
);
1112 info
.SetFont( attrs
->GetFont() );
1113 info
.SetBackgroundColour( attrs
->GetBackgroundColour() );
1114 info
.SetTextColour( attrs
->GetTextColour() );
1119 bool success
= true;
1123 // Sets information about the item
1124 bool wxListCtrl::SetItem(wxListItem
& info
)
1127 return m_genericImpl
->SetItem(info
);
1130 m_dbImpl
->MacSetColumnInfo( info
.m_itemId
, info
.m_col
, &info
);
1135 long wxListCtrl::SetItem(long index
, int col
, const wxString
& label
, int imageId
)
1138 return m_genericImpl
->SetItem(index
, col
, label
, imageId
);
1141 info
.m_text
= label
;
1142 info
.m_mask
= wxLIST_MASK_TEXT
;
1143 info
.m_itemId
= index
;
1147 info
.m_image
= imageId
;
1148 info
.m_mask
|= wxLIST_MASK_IMAGE
;
1150 return SetItem(info
);
1154 // Gets the item state
1155 int wxListCtrl::GetItemState(long item
, long stateMask
) const
1158 return m_genericImpl
->GetItemState(item
, stateMask
);
1162 if ( HasFlag(wxLC_VIRTUAL
) )
1164 if (stateMask
== wxLIST_STATE_SELECTED
)
1166 if (IsDataBrowserItemSelected( m_dbImpl
->GetControlRef(), item
+1 ))
1167 return wxLIST_STATE_SELECTED
;
1176 info
.m_mask
= wxLIST_MASK_STATE
;
1177 info
.m_stateMask
= stateMask
;
1178 info
.m_itemId
= item
;
1183 return info
.m_state
;
1190 // Sets the item state
1191 bool wxListCtrl::SetItemState(long item
, long state
, long stateMask
)
1194 return m_genericImpl
->SetItemState(item
, state
, stateMask
);
1198 DataBrowserSetOption option
= kDataBrowserItemsAdd
;
1199 if ( (stateMask
& wxLIST_STATE_SELECTED
) && state
== 0 )
1200 option
= kDataBrowserItemsRemove
;
1204 if ( HasFlag(wxLC_VIRTUAL
) )
1206 wxMacDataItemBrowserSelectionSuppressor
suppressor(m_dbImpl
);
1207 m_dbImpl
->SetSelectedAllItems(option
);
1211 for(int i
= 0; i
< GetItemCount();i
++)
1215 info
.m_mask
= wxLIST_MASK_STATE
;
1216 info
.m_stateMask
= stateMask
;
1217 info
.m_state
= state
;
1224 if ( HasFlag(wxLC_VIRTUAL
) )
1226 long itemID
= item
+1;
1227 bool isSelected
= IsDataBrowserItemSelected(m_dbImpl
->GetControlRef(), (DataBrowserItemID
)itemID
);
1228 bool isSelectedState
= (state
== wxLIST_STATE_SELECTED
);
1230 // toggle the selection state if wxListInfo state and actual state don't match.
1231 if ( (stateMask
& wxLIST_STATE_SELECTED
) && isSelected
!= isSelectedState
)
1233 SetDataBrowserSelectedItems(m_dbImpl
->GetControlRef(), 1, (DataBrowserItemID
*)&itemID
, option
);
1239 info
.m_itemId
= item
;
1240 info
.m_mask
= wxLIST_MASK_STATE
;
1241 info
.m_stateMask
= stateMask
;
1242 info
.m_state
= state
;
1243 return SetItem(info
);
1250 // Sets the item image
1251 bool wxListCtrl::SetItemImage(long item
, int image
, int WXUNUSED(selImage
))
1253 return SetItemColumnImage(item
, 0, image
);
1256 // Sets the item image
1257 bool wxListCtrl::SetItemColumnImage(long item
, long column
, int image
)
1260 return m_genericImpl
->SetItemColumnImage(item
, column
, image
);
1264 info
.m_mask
= wxLIST_MASK_IMAGE
;
1265 info
.m_image
= image
;
1266 info
.m_itemId
= item
;
1267 info
.m_col
= column
;
1269 return SetItem(info
);
1272 // Gets the item text
1273 wxString
wxListCtrl::GetItemText(long item
, int column
) const
1276 return m_genericImpl
->GetItemText(item
, column
);
1280 info
.m_mask
= wxLIST_MASK_TEXT
;
1281 info
.m_itemId
= item
;
1282 info
.m_col
= column
;
1285 return wxEmptyString
;
1289 // Sets the item text
1290 void wxListCtrl::SetItemText(long item
, const wxString
& str
)
1293 return m_genericImpl
->SetItemText(item
, str
);
1297 info
.m_mask
= wxLIST_MASK_TEXT
;
1298 info
.m_itemId
= item
;
1304 // Gets the item data
1305 long wxListCtrl::GetItemData(long item
) const
1308 return m_genericImpl
->GetItemData(item
);
1312 info
.m_mask
= wxLIST_MASK_DATA
;
1313 info
.m_itemId
= item
;
1320 // Sets the item data
1321 bool wxListCtrl::SetItemPtrData(long item
, wxUIntPtr data
)
1324 return m_genericImpl
->SetItemData(item
, data
);
1328 info
.m_mask
= wxLIST_MASK_DATA
;
1329 info
.m_itemId
= item
;
1332 return SetItem(info
);
1335 wxRect
wxListCtrl::GetViewRect() const
1337 wxASSERT_MSG( !HasFlag(wxLC_REPORT
| wxLC_LIST
),
1338 wxT("wxListCtrl::GetViewRect() only works in icon mode") );
1341 return m_genericImpl
->GetViewRect();
1347 bool wxListCtrl::GetSubItemRect( long item
, long subItem
, wxRect
& rect
, int code
) const
1350 return m_genericImpl
->GetSubItemRect(item
, subItem
, rect
, code
);
1352 // TODO: implement for DataBrowser implementation
1356 // Gets the item rectangle
1357 bool wxListCtrl::GetItemRect(long item
, wxRect
& rect
, int code
) const
1360 return m_genericImpl
->GetItemRect(item
, rect
, code
);
1365 DataBrowserItemID id
;
1367 DataBrowserTableViewColumnID col
= 0;
1368 verify_noerr( m_dbImpl
->GetColumnIDFromIndex( 0, &col
) );
1371 DataBrowserPropertyPart part
= kDataBrowserPropertyEnclosingPart
;
1372 if ( code
== wxLIST_RECT_LABEL
)
1373 part
= kDataBrowserPropertyTextPart
;
1374 else if ( code
== wxLIST_RECT_ICON
)
1375 part
= kDataBrowserPropertyIconPart
;
1377 if ( !(GetWindowStyleFlag() & wxLC_VIRTUAL
) )
1379 wxMacDataItem
* thisItem
= m_dbImpl
->GetItemFromLine(item
);
1380 id
= (DataBrowserItemID
) thisItem
;
1385 GetDataBrowserItemPartBounds( m_dbImpl
->GetControlRef(), id
, col
, part
, &bounds
);
1387 rect
.x
= bounds
.left
;
1388 rect
.y
= bounds
.top
;
1389 rect
.width
= bounds
.right
- bounds
.left
; //GetClientSize().x; // we need the width of the whole row, not just the item.
1390 rect
.height
= bounds
.bottom
- bounds
.top
;
1391 //fprintf("id = %d, bounds = %d, %d, %d, %d\n", id, rect.x, rect.y, rect.width, rect.height);
1396 // Gets the item position
1397 bool wxListCtrl::GetItemPosition(long item
, wxPoint
& pos
) const
1400 return m_genericImpl
->GetItemPosition(item
, pos
);
1402 bool success
= false;
1407 GetItemRect(item
, itemRect
);
1408 pos
= itemRect
.GetPosition();
1415 // Sets the item position.
1416 bool wxListCtrl::SetItemPosition(long item
, const wxPoint
& pos
)
1419 return m_genericImpl
->SetItemPosition(item
, pos
);
1424 // Gets the number of items in the list control
1425 int wxListCtrl::GetItemCount() const
1428 return m_genericImpl
->GetItemCount();
1431 return m_dbImpl
->MacGetCount();
1436 void wxListCtrl::SetItemSpacing( int spacing
, bool isSmall
)
1439 m_genericImpl
->SetItemSpacing(spacing
, isSmall
);
1442 wxSize
wxListCtrl::GetItemSpacing() const
1445 return m_genericImpl
->GetItemSpacing();
1447 return wxSize(0, 0);
1450 void wxListCtrl::SetItemTextColour( long item
, const wxColour
&col
)
1454 m_genericImpl
->SetItemTextColour(item
, col
);
1459 info
.m_itemId
= item
;
1460 info
.SetTextColour( col
);
1464 wxColour
wxListCtrl::GetItemTextColour( long item
) const
1467 return m_genericImpl
->GetItemTextColour(item
);
1473 return info
.GetTextColour();
1475 return wxNullColour
;
1478 void wxListCtrl::SetItemBackgroundColour( long item
, const wxColour
&col
)
1482 m_genericImpl
->SetItemBackgroundColour(item
, col
);
1487 info
.m_itemId
= item
;
1488 info
.SetBackgroundColour( col
);
1492 wxColour
wxListCtrl::GetItemBackgroundColour( long item
) const
1495 return m_genericImpl
->GetItemBackgroundColour(item
);
1501 return info
.GetBackgroundColour();
1503 return wxNullColour
;
1506 void wxListCtrl::SetItemFont( long item
, const wxFont
&f
)
1510 m_genericImpl
->SetItemFont(item
, f
);
1515 info
.m_itemId
= item
;
1520 wxFont
wxListCtrl::GetItemFont( long item
) const
1523 return m_genericImpl
->GetItemFont(item
);
1529 return info
.GetFont();
1535 // Gets the number of selected items in the list control
1536 int wxListCtrl::GetSelectedItemCount() const
1539 return m_genericImpl
->GetSelectedItemCount();
1542 return m_dbImpl
->GetSelectedItemCount(NULL
, true);
1547 // Gets the text colour of the listview
1548 wxColour
wxListCtrl::GetTextColour() const
1551 return m_genericImpl
->GetTextColour();
1553 // TODO: we need owner drawn list items to customize text color.
1557 return wxNullColour
;
1560 // Sets the text colour of the listview
1561 void wxListCtrl::SetTextColour(const wxColour
& col
)
1565 m_genericImpl
->SetTextColour(col
);
1573 // Gets the index of the topmost visible item when in
1574 // list or report view
1575 long wxListCtrl::GetTopItem() const
1578 return m_genericImpl
->GetTopItem();
1583 long item
= HitTest( wxPoint(1, 1), flags
);
1584 if (flags
== wxLIST_HITTEST_ONITEM
)
1591 // Searches for an item, starting from 'item'.
1592 // 'geometry' is one of
1593 // wxLIST_NEXT_ABOVE/ALL/BELOW/LEFT/RIGHT.
1594 // 'state' is a state bit flag, one or more of
1595 // wxLIST_STATE_DROPHILITED/FOCUSED/SELECTED/CUT.
1596 // item can be -1 to find the first item that matches the
1598 // Returns the item or -1 if unsuccessful.
1599 long wxListCtrl::GetNextItem(long item
, int geom
, int state
) const
1602 return m_genericImpl
->GetNextItem(item
, geom
, state
);
1604 // TODO: implement all geometry and state options?
1607 if ( geom
== wxLIST_NEXT_ALL
|| geom
== wxLIST_NEXT_BELOW
)
1609 long count
= m_dbImpl
->MacGetCount() ;
1610 for ( long line
= item
+ 1 ; line
< count
; line
++ )
1612 DataBrowserItemID id
= line
+ 1;
1614 id
= (DataBrowserItemID
)m_dbImpl
->GetItemFromLine(line
);
1616 if ( (state
& wxLIST_STATE_FOCUSED
) && (m_current
== line
))
1619 if ( (state
== wxLIST_STATE_DONTCARE
) )
1622 if ( (state
& wxLIST_STATE_SELECTED
) && IsDataBrowserItemSelected(m_dbImpl
->GetControlRef(), id
) )
1627 if ( geom
== wxLIST_NEXT_ABOVE
)
1631 item2
= m_dbImpl
->MacGetCount();
1633 for ( long line
= item2
- 1 ; line
>= 0; line
-- )
1635 DataBrowserItemID id
= line
+ 1;
1637 id
= (DataBrowserItemID
)m_dbImpl
->GetItemFromLine(line
);
1639 if ( (state
& wxLIST_STATE_FOCUSED
) && (m_current
== line
))
1642 if ( (state
== wxLIST_STATE_DONTCARE
) )
1645 if ( (state
& wxLIST_STATE_SELECTED
) && IsDataBrowserItemSelected(m_dbImpl
->GetControlRef(), id
) )
1655 wxImageList
*wxListCtrl::GetImageList(int which
) const
1658 return m_genericImpl
->GetImageList(which
);
1660 if ( which
== wxIMAGE_LIST_NORMAL
)
1662 return m_imageListNormal
;
1664 else if ( which
== wxIMAGE_LIST_SMALL
)
1666 return m_imageListSmall
;
1668 else if ( which
== wxIMAGE_LIST_STATE
)
1670 return m_imageListState
;
1675 void wxListCtrl::SetImageList(wxImageList
*imageList
, int which
)
1679 m_genericImpl
->SetImageList(imageList
, which
);
1683 if ( which
== wxIMAGE_LIST_NORMAL
)
1685 if (m_ownsImageListNormal
) delete m_imageListNormal
;
1686 m_imageListNormal
= imageList
;
1687 m_ownsImageListNormal
= false;
1689 else if ( which
== wxIMAGE_LIST_SMALL
)
1691 if (m_ownsImageListSmall
) delete m_imageListSmall
;
1692 m_imageListSmall
= imageList
;
1693 m_ownsImageListSmall
= false;
1695 else if ( which
== wxIMAGE_LIST_STATE
)
1697 if (m_ownsImageListState
) delete m_imageListState
;
1698 m_imageListState
= imageList
;
1699 m_ownsImageListState
= false;
1703 void wxListCtrl::AssignImageList(wxImageList
*imageList
, int which
)
1707 m_genericImpl
->AssignImageList(imageList
, which
);
1711 SetImageList(imageList
, which
);
1712 if ( which
== wxIMAGE_LIST_NORMAL
)
1713 m_ownsImageListNormal
= true;
1714 else if ( which
== wxIMAGE_LIST_SMALL
)
1715 m_ownsImageListSmall
= true;
1716 else if ( which
== wxIMAGE_LIST_STATE
)
1717 m_ownsImageListState
= true;
1720 // ----------------------------------------------------------------------------
1722 // ----------------------------------------------------------------------------
1724 // Arranges the items
1725 bool wxListCtrl::Arrange(int flag
)
1728 return m_genericImpl
->Arrange(flag
);
1733 bool wxListCtrl::DeleteItem(long item
)
1736 return m_genericImpl
->DeleteItem(item
);
1740 m_dbImpl
->MacDelete(item
);
1741 wxListEvent
event( wxEVT_LIST_DELETE_ITEM
, GetId() );
1742 event
.SetEventObject( this );
1743 event
.m_itemIndex
= item
;
1744 HandleWindowEvent( event
);
1750 // Deletes all items
1751 bool wxListCtrl::DeleteAllItems()
1755 return m_genericImpl
->DeleteAllItems();
1759 m_dbImpl
->MacClear();
1760 wxListEvent
event( wxEVT_LIST_DELETE_ALL_ITEMS
, GetId() );
1761 event
.SetEventObject( this );
1762 HandleWindowEvent( event
);
1767 // Deletes all items
1768 bool wxListCtrl::DeleteAllColumns()
1771 return m_genericImpl
->DeleteAllColumns();
1776 m_dbImpl
->GetColumnCount(&cols
);
1777 for (UInt32 col
= 0; col
< cols
; col
++)
1787 bool wxListCtrl::DeleteColumn(int col
)
1790 return m_genericImpl
->DeleteColumn(col
);
1794 OSStatus err
= m_dbImpl
->RemoveColumn(col
);
1795 return err
== noErr
;
1801 // Clears items, and columns if there are any.
1802 void wxListCtrl::ClearAll()
1806 m_genericImpl
->ClearAll();
1817 wxTextCtrl
* wxListCtrl::EditLabel(long item
, wxClassInfo
* textControlClass
)
1820 return m_genericImpl
->EditLabel(item
, textControlClass
);
1824 wxCHECK_MSG( (item
>= 0) && ((long)item
< GetItemCount()), NULL
,
1825 wxT("wrong index in wxListCtrl::EditLabel()") );
1827 wxASSERT_MSG( textControlClass
->IsKindOf(CLASSINFO(wxTextCtrl
)),
1828 wxT("EditLabel() needs a text control") );
1830 wxListEvent
le( wxEVT_LIST_BEGIN_LABEL_EDIT
, GetParent()->GetId() );
1831 le
.SetEventObject( this );
1832 le
.m_itemIndex
= item
;
1834 GetItem( le
.m_item
);
1836 if ( GetParent()->HandleWindowEvent( le
) && !le
.IsAllowed() )
1838 // vetoed by user code
1842 wxTextCtrl
* const text
= (wxTextCtrl
*)textControlClass
->CreateObject();
1843 m_textctrlWrapper
= new wxListCtrlTextCtrlWrapper(this, text
, item
);
1844 return m_textctrlWrapper
->GetText();
1849 // End label editing, optionally cancelling the edit
1850 bool wxListCtrl::EndEditLabel(bool WXUNUSED(cancel
))
1852 // TODO: generic impl. doesn't have this method - is it needed for us?
1854 return true; // m_genericImpl->EndEditLabel(cancel);
1858 DataBrowserTableViewColumnID id
= 0;
1859 verify_noerr( m_dbImpl
->GetColumnIDFromIndex( 0, &id
) );
1860 verify_noerr( SetDataBrowserEditItem(m_dbImpl
->GetControlRef(), kDataBrowserNoItem
, id
) );
1865 // Ensures this item is visible
1866 bool wxListCtrl::EnsureVisible(long item
)
1869 return m_genericImpl
->EnsureVisible(item
);
1873 wxMacDataItem
* dataItem
= m_dbImpl
->GetItemFromLine(item
);
1874 m_dbImpl
->RevealItem(dataItem
, kDataBrowserRevealWithoutSelecting
);
1880 // Find an item whose label matches this string, starting from the item after 'start'
1881 // or the beginning if 'start' is -1.
1882 long wxListCtrl::FindItem(long start
, const wxString
& str
, bool partial
)
1885 return m_genericImpl
->FindItem(start
, str
, partial
);
1887 wxString str_upper
= str
.Upper();
1892 long count
= GetItemCount();
1896 wxString line_upper
= GetItemText(idx
).Upper();
1899 if (line_upper
== str_upper
)
1904 if (line_upper
.find(str_upper
) == 0)
1914 // Find an item whose data matches this data, starting from the item after 'start'
1915 // or the beginning if 'start' is -1.
1916 long wxListCtrl::FindItem(long start
, long data
)
1919 return m_genericImpl
->FindItem(start
, data
);
1924 long count
= GetItemCount();
1928 if (GetItemData(idx
) == data
)
1936 // Find an item nearest this position in the specified direction, starting from
1937 // the item after 'start' or the beginning if 'start' is -1.
1938 long wxListCtrl::FindItem(long start
, const wxPoint
& pt
, int direction
)
1941 return m_genericImpl
->FindItem(start
, pt
, direction
);
1945 static void calculateCGDrawingBounds(CGRect inItemRect
, CGRect
*outIconRect
, CGRect
*outTextRect
, bool hasIcon
);
1947 // Determines which item (if any) is at the specified point,
1948 // giving details in 'flags' (see wxLIST_HITTEST_... flags above)
1950 wxListCtrl::HitTest(const wxPoint
& point
, int& flags
, long *ptrSubItem
) const
1956 return m_genericImpl
->HitTest(point
, flags
, ptrSubItem
);
1958 flags
= wxLIST_HITTEST_NOWHERE
;
1961 int colHeaderHeight
= 22; // TODO: Find a way to get this value from the db control?
1962 UInt16 rowHeight
= 0;
1963 m_dbImpl
->GetDefaultRowHeight(&rowHeight
);
1966 // get the actual row by taking scroll position into account
1967 UInt32 offsetX
, offsetY
;
1968 m_dbImpl
->GetScrollPosition( &offsetY
, &offsetX
);
1971 if ( !(GetWindowStyleFlag() & wxLC_NO_HEADER
) )
1972 y
-= colHeaderHeight
;
1977 int row
= y
/ rowHeight
;
1978 DataBrowserItemID id
;
1979 m_dbImpl
->GetItemID( (DataBrowserTableViewRowIndex
) row
, &id
);
1981 CGPoint click_point
= CGPointMake( point
.x
, point
.y
);
1982 if (row
< GetItemCount() )
1985 for( column
= 0; column
< GetColumnCount(); column
++ )
1988 CGRect enclosingCGRect
, iconCGRect
, textCGRect
;
1990 wxMacListCtrlItem
* lcItem
;
1992 WXUNUSED_UNLESS_DEBUG( OSStatus status
= ) m_dbImpl
->GetItemPartBounds( id
, kMinColumnId
+ column
, kDataBrowserPropertyEnclosingPart
, &enclosingRect
);
1993 wxASSERT( status
== noErr
);
1995 enclosingCGRect
= CGRectMake(enclosingRect
.left
,
1997 enclosingRect
.right
- enclosingRect
.left
,
1998 enclosingRect
.bottom
- enclosingRect
.top
);
2002 if ( !(GetWindowStyleFlag() & wxLC_VIRTUAL
) )
2004 lcItem
= (wxMacListCtrlItem
*) id
;
2005 if (lcItem
->HasColumnInfo(column
))
2007 wxListItem
* item
= lcItem
->GetColumnInfo(column
);
2009 if (item
->GetMask() & wxLIST_MASK_IMAGE
)
2011 imgIndex
= item
->GetImage();
2017 long itemNum
= (long)id
-1;
2018 if (itemNum
>= 0 && itemNum
< GetItemCount())
2020 imgIndex
= OnGetItemColumnImage( itemNum
, column
);
2025 calculateCGDrawingBounds(enclosingCGRect
, &iconCGRect
, &textCGRect
, (imgIndex
!= -1) );
2027 if ( CGRectContainsPoint( iconCGRect
, click_point
) )
2029 flags
= wxLIST_HITTEST_ONITEMICON
;
2031 *ptrSubItem
= column
;
2034 else if ( CGRectContainsPoint( textCGRect
, click_point
) )
2036 flags
= wxLIST_HITTEST_ONITEMLABEL
;
2038 *ptrSubItem
= column
;
2043 if ( !(GetWindowStyleFlag() & wxLC_VIRTUAL
) )
2045 wxMacListCtrlItem
* lcItem
;
2046 lcItem
= (wxMacListCtrlItem
*) id
;
2049 flags
= wxLIST_HITTEST_ONITEM
;
2051 *ptrSubItem
= column
;
2057 flags
= wxLIST_HITTEST_ONITEM
;
2059 *ptrSubItem
= column
;
2065 if ( wxControl::HitTest( point
) )
2066 flags
= wxLIST_HITTEST_NOWHERE
;
2073 int wxListCtrl::GetScrollPos(int orient
) const
2076 return m_genericImpl
->GetScrollPos(orient
);
2080 UInt32 offsetX
, offsetY
;
2081 m_dbImpl
->GetScrollPosition( &offsetY
, &offsetX
);
2082 if ( orient
== wxHORIZONTAL
)
2091 // Inserts an item, returning the index of the new item if successful,
2093 long wxListCtrl::InsertItem(wxListItem
& info
)
2095 wxASSERT_MSG( !IsVirtual(), wxT("can't be used with virtual controls") );
2098 return m_genericImpl
->InsertItem(info
);
2100 if (m_dbImpl
&& !IsVirtual())
2102 int count
= GetItemCount();
2104 if (info
.m_itemId
> count
)
2105 info
.m_itemId
= count
;
2107 m_dbImpl
->MacInsertItem(info
.m_itemId
, &info
);
2109 wxListEvent
event( wxEVT_LIST_INSERT_ITEM
, GetId() );
2110 event
.SetEventObject( this );
2111 event
.m_itemIndex
= info
.m_itemId
;
2112 HandleWindowEvent( event
);
2113 return info
.m_itemId
;
2118 long wxListCtrl::InsertItem(long index
, const wxString
& label
)
2121 return m_genericImpl
->InsertItem(index
, label
);
2124 info
.m_text
= label
;
2125 info
.m_mask
= wxLIST_MASK_TEXT
;
2126 info
.m_itemId
= index
;
2127 return InsertItem(info
);
2130 // Inserts an image item
2131 long wxListCtrl::InsertItem(long index
, int imageIndex
)
2134 return m_genericImpl
->InsertItem(index
, imageIndex
);
2137 info
.m_image
= imageIndex
;
2138 info
.m_mask
= wxLIST_MASK_IMAGE
;
2139 info
.m_itemId
= index
;
2140 return InsertItem(info
);
2143 // Inserts an image/string item
2144 long wxListCtrl::InsertItem(long index
, const wxString
& label
, int imageIndex
)
2147 return m_genericImpl
->InsertItem(index
, label
, imageIndex
);
2150 info
.m_image
= imageIndex
;
2151 info
.m_text
= label
;
2152 info
.m_mask
= wxLIST_MASK_IMAGE
| wxLIST_MASK_TEXT
;
2153 info
.m_itemId
= index
;
2154 return InsertItem(info
);
2157 // For list view mode (only), inserts a column.
2158 long wxListCtrl::DoInsertColumn(long col
, const wxListItem
& item
)
2161 return m_genericImpl
->InsertColumn(col
, item
);
2165 int width
= item
.GetWidth();
2166 if ( !(item
.GetMask() & wxLIST_MASK_WIDTH
) )
2169 DataBrowserPropertyType type
= kDataBrowserCustomType
; //kDataBrowserTextType;
2170 wxImageList
* imageList
= GetImageList(wxIMAGE_LIST_SMALL
);
2171 if (imageList
&& imageList
->GetImageCount() > 0)
2173 wxBitmap bmp
= imageList
->GetBitmap(0);
2175 // type = kDataBrowserIconAndTextType;
2178 SInt16 just
= teFlushDefault
;
2179 if (item
.GetMask() & wxLIST_MASK_FORMAT
)
2181 if (item
.GetAlign() == wxLIST_FORMAT_LEFT
)
2183 else if (item
.GetAlign() == wxLIST_FORMAT_CENTER
)
2185 else if (item
.GetAlign() == wxLIST_FORMAT_RIGHT
)
2186 just
= teFlushRight
;
2188 m_dbImpl
->InsertColumn(col
, type
, item
.GetText(), just
, width
);
2190 wxListItem
* listItem
= new wxListItem(item
);
2191 m_colsInfo
.Insert( col
, listItem
);
2192 SetColumn(col
, item
);
2194 // set/remove options based on the wxListCtrl type.
2195 DataBrowserTableViewColumnID id
;
2196 m_dbImpl
->GetColumnIDFromIndex(col
, &id
);
2197 DataBrowserPropertyFlags flags
;
2198 verify_noerr(m_dbImpl
->GetPropertyFlags(id
, &flags
));
2199 if (GetWindowStyleFlag() & wxLC_EDIT_LABELS
)
2200 flags
|= kDataBrowserPropertyIsEditable
;
2202 if (GetWindowStyleFlag() & wxLC_VIRTUAL
){
2203 flags
&= ~kDataBrowserListViewSortableColumn
;
2205 verify_noerr(m_dbImpl
->SetPropertyFlags(id
, flags
));
2211 // scroll the control by the given number of pixels (exception: in list view,
2212 // dx is interpreted as number of columns)
2213 bool wxListCtrl::ScrollList(int dx
, int dy
)
2216 return m_genericImpl
->ScrollList(dx
, dy
);
2220 // Notice that the parameter order is correct here: first argument is
2221 // the "top" displacement, second one is the "left" one.
2222 m_dbImpl
->SetScrollPosition(dy
, dx
);
2228 bool wxListCtrl::SortItems(wxListCtrlCompare fn
, wxIntPtr data
)
2231 return m_genericImpl
->SortItems(fn
, data
);
2236 m_compareFuncData
= data
;
2237 SortDataBrowserContainer( m_dbImpl
->GetControlRef(), kDataBrowserNoItem
, true);
2239 // we need to do this after each call, else we get a crash from wxPython when
2240 // SortItems is called the second time.
2241 m_compareFunc
= NULL
;
2242 m_compareFuncData
= 0;
2248 void wxListCtrl::OnRenameTimer()
2250 wxCHECK_RET( HasCurrent(), wxT("unexpected rename timer") );
2252 EditLabel( m_current
);
2255 bool wxListCtrl::OnRenameAccept(long itemEdit
, const wxString
& value
)
2257 wxListEvent
le( wxEVT_LIST_END_LABEL_EDIT
, GetId() );
2258 le
.SetEventObject( this );
2259 le
.m_itemIndex
= itemEdit
;
2261 GetItem( le
.m_item
);
2262 le
.m_item
.m_text
= value
;
2263 return !HandleWindowEvent( le
) ||
2267 void wxListCtrl::OnRenameCancelled(long itemEdit
)
2269 // let owner know that the edit was cancelled
2270 wxListEvent
le( wxEVT_LIST_END_LABEL_EDIT
, GetParent()->GetId() );
2272 le
.SetEditCanceled(true);
2274 le
.SetEventObject( this );
2275 le
.m_itemIndex
= itemEdit
;
2277 GetItem( le
.m_item
);
2278 HandleWindowEvent( le
);
2281 // ----------------------------------------------------------------------------
2282 // virtual list controls
2283 // ----------------------------------------------------------------------------
2285 wxString
wxListCtrl::OnGetItemText(long WXUNUSED(item
), long WXUNUSED(col
)) const
2287 // this is a pure virtual function, in fact - which is not really pure
2288 // because the controls which are not virtual don't need to implement it
2289 wxFAIL_MSG( wxT("wxListCtrl::OnGetItemText not supposed to be called") );
2291 return wxEmptyString
;
2294 int wxListCtrl::OnGetItemImage(long WXUNUSED(item
)) const
2296 wxCHECK_MSG(!GetImageList(wxIMAGE_LIST_SMALL
),
2298 wxT("List control has an image list, OnGetItemImage or OnGetItemColumnImage should be overridden."));
2302 int wxListCtrl::OnGetItemColumnImage(long item
, long column
) const
2305 return OnGetItemImage(item
);
2310 void wxListCtrl::SetItemCount(long count
)
2312 wxASSERT_MSG( IsVirtual(), wxT("this is for virtual controls only") );
2316 m_genericImpl
->SetItemCount(count
);
2322 // we need to temporarily disable the new item creation notification
2323 // procedure to speed things up
2324 // FIXME: Even this doesn't seem to help much...
2326 // FIXME: Find a more efficient way to do this.
2327 m_dbImpl
->MacClear();
2329 DataBrowserCallbacks callbacks
;
2330 DataBrowserItemNotificationUPP itemUPP
;
2331 GetDataBrowserCallbacks(m_dbImpl
->GetControlRef(), &callbacks
);
2332 itemUPP
= callbacks
.u
.v1
.itemNotificationCallback
;
2333 callbacks
.u
.v1
.itemNotificationCallback
= 0;
2334 m_dbImpl
->SetCallbacks(&callbacks
);
2335 ::AddDataBrowserItems(m_dbImpl
->GetControlRef(), kDataBrowserNoItem
,
2336 count
, NULL
, kDataBrowserItemNoProperty
);
2337 callbacks
.u
.v1
.itemNotificationCallback
= itemUPP
;
2338 m_dbImpl
->SetCallbacks(&callbacks
);
2343 void wxListCtrl::RefreshItem(long item
)
2347 m_genericImpl
->RefreshItem(item
);
2353 DataBrowserItemID id
;
2357 wxMacDataItem
* thisItem
= m_dbImpl
->GetItemFromLine(item
);
2358 id
= (DataBrowserItemID
) thisItem
;
2363 m_dbImpl
->wxMacDataBrowserControl::UpdateItems
2367 kDataBrowserItemNoProperty
, // preSortProperty
2368 kDataBrowserNoItem
// update all columns
2373 void wxListCtrl::RefreshItems(long itemFrom
, long itemTo
)
2377 m_genericImpl
->RefreshItems(itemFrom
, itemTo
);
2383 const long count
= itemTo
- itemFrom
+ 1;
2384 DataBrowserItemID
*ids
= new DataBrowserItemID
[count
];
2388 for ( long i
= 0; i
< count
; i
++ )
2390 wxMacDataItem
* thisItem
= m_dbImpl
->GetItemFromLine(itemFrom
+i
);
2391 ids
[i
] = (DataBrowserItemID
) thisItem
;
2396 for ( long i
= 0; i
< count
; i
++ )
2397 ids
[i
] = itemFrom
+i
+1;
2400 m_dbImpl
->wxMacDataBrowserControl::UpdateItems
2404 kDataBrowserItemNoProperty
, // preSortProperty
2405 kDataBrowserNoItem
// update all columns
2412 void wxListCtrl::SetDropTarget( wxDropTarget
*dropTarget
)
2414 #if wxUSE_DRAG_AND_DROP
2416 m_genericImpl
->SetDropTarget( dropTarget
);
2419 wxWindow::SetDropTarget( dropTarget
);
2423 wxDropTarget
*wxListCtrl::GetDropTarget() const
2425 #if wxUSE_DRAG_AND_DROP
2427 return m_genericImpl
->GetDropTarget();
2430 return wxWindow::GetDropTarget();
2435 #if wxABI_VERSION >= 20801
2436 void wxListCtrl::SetFocus()
2440 m_genericImpl
->SetFocus();
2444 wxWindow::SetFocus();
2448 // wxMac internal data structures
2450 wxMacListCtrlItem::~wxMacListCtrlItem()
2452 WX_CLEAR_HASH_MAP( wxListItemList
, m_rowItems
);
2455 void wxMacListCtrlItem::Notification(wxMacDataItemBrowserControl
*owner
,
2456 DataBrowserItemNotification message
,
2457 DataBrowserItemDataRef
WXUNUSED(itemData
) ) const
2460 wxMacDataBrowserListCtrlControl
*lb
= wxDynamicCast(owner
, wxMacDataBrowserListCtrlControl
);
2462 // we want to depend on as little as possible to make sure tear-down of controls is safe
2463 if ( message
== kDataBrowserItemRemoved
)
2468 else if ( message
== kDataBrowserItemAdded
)
2470 // we don't issue events on adding, the item is not really stored in the list yet, so we
2471 // avoid asserts by gettting out now
2475 wxListCtrl
*list
= wxDynamicCast( owner
->GetWXPeer() , wxListCtrl
);
2478 bool trigger
= false;
2480 wxListEvent
event( wxEVT_LIST_ITEM_SELECTED
, list
->GetId() );
2481 bool isSingle
= (list
->GetWindowStyle() & wxLC_SINGLE_SEL
) != 0;
2483 event
.SetEventObject( list
);
2484 event
.m_itemIndex
= owner
->GetLineFromItem( this ) ;
2485 event
.m_item
.m_itemId
= event
.m_itemIndex
;
2486 list
->GetItem(event
.m_item
);
2490 case kDataBrowserItemDeselected
:
2491 event
.SetEventType(wxEVT_LIST_ITEM_DESELECTED
);
2493 trigger
= !lb
->IsSelectionSuppressed();
2496 case kDataBrowserItemSelected
:
2497 trigger
= !lb
->IsSelectionSuppressed();
2500 case kDataBrowserItemDoubleClicked
:
2501 event
.SetEventType( wxEVT_LIST_ITEM_ACTIVATED
);
2505 case kDataBrowserEditStarted
:
2506 // TODO : how to veto ?
2507 event
.SetEventType( wxEVT_LIST_BEGIN_LABEL_EDIT
) ;
2511 case kDataBrowserEditStopped
:
2512 // TODO probably trigger only upon the value store callback, because
2513 // here IIRC we cannot veto
2514 event
.SetEventType( wxEVT_LIST_END_LABEL_EDIT
) ;
2524 // direct notification is not always having the listbox GetSelection() having in synch with event
2525 wxPostEvent( list
->GetEventHandler(), event
);
2531 IMPLEMENT_DYNAMIC_CLASS(wxMacDataBrowserListCtrlControl
, wxMacDataItemBrowserControl
)
2533 wxMacDataBrowserListCtrlControl::wxMacDataBrowserListCtrlControl( wxWindow
*peer
, const wxPoint
& pos
, const wxSize
& size
, long style
)
2534 : wxMacDataItemBrowserControl( peer
, pos
, size
, style
)
2536 OSStatus err
= noErr
;
2537 m_clientDataItemsType
= wxClientData_None
;
2538 m_isVirtual
= false;
2541 if ( style
& wxLC_VIRTUAL
)
2544 DataBrowserSelectionFlags options
= kDataBrowserDragSelect
;
2545 if ( style
& wxLC_SINGLE_SEL
)
2547 options
|= kDataBrowserSelectOnlyOne
;
2551 options
|= kDataBrowserCmdTogglesSelection
;
2554 err
= SetSelectionFlags( options
);
2555 verify_noerr( err
);
2557 DataBrowserCustomCallbacks callbacks
;
2558 InitializeDataBrowserCustomCallbacks( &callbacks
, kDataBrowserLatestCustomCallbacks
);
2560 if ( gDataBrowserDrawItemUPP
== NULL
)
2561 gDataBrowserDrawItemUPP
= NewDataBrowserDrawItemUPP(DataBrowserDrawItemProc
);
2563 if ( gDataBrowserHitTestUPP
== NULL
)
2564 gDataBrowserHitTestUPP
= NewDataBrowserHitTestUPP(DataBrowserHitTestProc
);
2566 callbacks
.u
.v1
.drawItemCallback
= gDataBrowserDrawItemUPP
;
2567 callbacks
.u
.v1
.hitTestCallback
= gDataBrowserHitTestUPP
;
2569 SetDataBrowserCustomCallbacks( GetControlRef(), &callbacks
);
2571 if ( style
& wxLC_LIST
)
2573 InsertColumn(0, kDataBrowserIconAndTextType
, wxEmptyString
, -1, -1);
2574 verify_noerr( AutoSizeColumns() );
2577 if ( style
& wxLC_LIST
|| style
& wxLC_NO_HEADER
)
2578 verify_noerr( SetHeaderButtonHeight( 0 ) );
2581 SetSortProperty( kMinColumnId
- 1 );
2583 SetSortProperty( kMinColumnId
);
2585 m_sortOrder
= SortOrder_None
;
2587 if ( style
& wxLC_SORT_DESCENDING
)
2589 SetSortOrder( kDataBrowserOrderDecreasing
);
2591 else if ( style
& wxLC_SORT_ASCENDING
)
2593 SetSortOrder( kDataBrowserOrderIncreasing
);
2596 if ( style
& wxLC_VRULES
)
2598 verify_noerr( DataBrowserChangeAttributes(m_controlRef
, kDataBrowserAttributeListViewDrawColumnDividers
, kDataBrowserAttributeNone
) );
2601 verify_noerr( SetHiliteStyle(kDataBrowserTableViewFillHilite
) );
2602 verify_noerr( SetHasScrollBars( (style
& wxHSCROLL
) != 0 , true ) );
2605 pascal Boolean
wxMacDataBrowserListCtrlControl::DataBrowserEditTextProc(
2607 DataBrowserItemID itemID
,
2608 DataBrowserPropertyID property
,
2609 CFStringRef theString
,
2610 Rect
*maxEditTextRect
,
2611 Boolean
*shrinkToFit
)
2613 Boolean result
= false;
2614 wxMacDataBrowserListCtrlControl
* ctl
= wxDynamicCast(wxMacControl::GetReferenceFromNativeControl( browser
), wxMacDataBrowserListCtrlControl
);
2617 result
= ctl
->ConfirmEditText(itemID
, property
, theString
, maxEditTextRect
, shrinkToFit
);
2618 theString
= CFSTR("Hello!");
2623 bool wxMacDataBrowserListCtrlControl::ConfirmEditText(
2624 DataBrowserItemID
WXUNUSED(itemID
),
2625 DataBrowserPropertyID
WXUNUSED(property
),
2626 CFStringRef
WXUNUSED(theString
),
2627 Rect
*WXUNUSED(maxEditTextRect
),
2628 Boolean
*WXUNUSED(shrinkToFit
))
2633 pascal void wxMacDataBrowserListCtrlControl::DataBrowserDrawItemProc(
2635 DataBrowserItemID itemID
,
2636 DataBrowserPropertyID property
,
2637 DataBrowserItemState itemState
,
2638 const Rect
*itemRect
,
2640 Boolean colorDevice
)
2642 wxMacDataBrowserListCtrlControl
* ctl
= wxDynamicCast(wxMacControl::GetReferenceFromNativeControl( browser
), wxMacDataBrowserListCtrlControl
);
2645 ctl
->DrawItem(itemID
, property
, itemState
, itemRect
, gdDepth
, colorDevice
);
2649 // routines needed for DrawItem
2654 kTextBoxHeight
= 14,
2655 kIconTextSpacingV
= 2,
2657 kContentHeight
= kIconHeight
+ kTextBoxHeight
+ kIconTextSpacingV
2660 static void calculateCGDrawingBounds(CGRect inItemRect
, CGRect
*outIconRect
, CGRect
*outTextRect
, bool hasIcon
= false)
2664 float padding
= kItemPadding
;
2668 padding
= padding
*2;
2671 textBottom
= inItemRect
.origin
.y
;
2673 *outIconRect
= CGRectMake(inItemRect
.origin
.x
+ kItemPadding
,
2674 textBottom
+ kIconTextSpacingV
, kIconWidth
,
2677 *outTextRect
= CGRectMake(inItemRect
.origin
.x
+ padding
+ iconW
,
2678 textBottom
+ kIconTextSpacingV
, inItemRect
.size
.width
- padding
- iconW
,
2679 inItemRect
.size
.height
- kIconTextSpacingV
);
2682 void wxMacDataBrowserListCtrlControl::DrawItem(
2683 DataBrowserItemID itemID
,
2684 DataBrowserPropertyID property
,
2685 DataBrowserItemState itemState
,
2686 const Rect
*WXUNUSED(itemRect
),
2688 Boolean colorDevice
)
2691 wxFont font
= wxNullFont
;
2694 DataBrowserTableViewColumnIndex listColumn
= 0;
2695 GetColumnPosition( property
, &listColumn
);
2697 wxListCtrl
* list
= wxDynamicCast( GetWXPeer() , wxListCtrl
);
2698 wxMacListCtrlItem
* lcItem
;
2699 wxColour color
= *wxBLACK
;
2700 wxColour bgColor
= wxNullColour
;
2702 if (listColumn
>= 0)
2706 lcItem
= (wxMacListCtrlItem
*) itemID
;
2707 if (lcItem
->HasColumnInfo(listColumn
))
2709 wxListItem
* item
= lcItem
->GetColumnInfo(listColumn
);
2711 // we always use the 0 column to get font and text/background colors.
2712 if (lcItem
->HasColumnInfo(0))
2714 wxListItem
* firstItem
= lcItem
->GetColumnInfo(0);
2715 color
= firstItem
->GetTextColour();
2716 bgColor
= firstItem
->GetBackgroundColour();
2717 font
= firstItem
->GetFont();
2720 if (item
->GetMask() & wxLIST_MASK_TEXT
)
2721 text
= item
->GetText();
2722 if (item
->GetMask() & wxLIST_MASK_IMAGE
)
2723 imgIndex
= item
->GetImage();
2729 long itemNum
= (long)itemID
-1;
2730 if (itemNum
>= 0 && itemNum
< list
->GetItemCount())
2732 text
= list
->OnGetItemText( itemNum
, listColumn
);
2733 imgIndex
= list
->OnGetItemColumnImage( itemNum
, listColumn
);
2734 wxListItemAttr
* attrs
= list
->OnGetItemAttr( itemNum
);
2737 if (attrs
->HasBackgroundColour())
2738 bgColor
= attrs
->GetBackgroundColour();
2739 if (attrs
->HasTextColour())
2740 color
= attrs
->GetTextColour();
2741 if (attrs
->HasFont())
2742 font
= attrs
->GetFont();
2748 wxColour listBgColor
= list
->GetBackgroundColour();
2749 if (bgColor
== wxNullColour
)
2750 bgColor
= listBgColor
;
2753 font
= list
->GetFont();
2755 wxCFStringRef
cfString( text
, wxLocale::GetSystemEncoding() );
2758 CGRect enclosingCGRect
, iconCGRect
, textCGRect
;
2760 ThemeDrawingState savedState
= NULL
;
2761 CGContextRef context
= (CGContextRef
)list
->MacGetDrawingContext();
2762 wxMacCGContextStateSaver
top_saver_cg( context
);
2764 RGBColor labelColor
;
2766 labelColor
.green
= 0;
2767 labelColor
.blue
= 0;
2769 RGBColor backgroundColor
;
2770 backgroundColor
.red
= 255;
2771 backgroundColor
.green
= 255;
2772 backgroundColor
.blue
= 255;
2774 GetDataBrowserItemPartBounds(GetControlRef(), itemID
, property
, kDataBrowserPropertyEnclosingPart
,
2777 enclosingCGRect
= CGRectMake(enclosingRect
.left
,
2779 enclosingRect
.right
- enclosingRect
.left
,
2780 enclosingRect
.bottom
- enclosingRect
.top
);
2782 bool hasFocus
= (wxWindow::FindFocus() == list
);
2783 active
= IsControlActive(GetControlRef());
2785 // don't paint the background over the vertical rule line
2786 if ( list
->GetWindowStyleFlag() & wxLC_VRULES
)
2788 enclosingCGRect
.origin
.x
+= 1;
2789 enclosingCGRect
.size
.width
-= 1;
2791 if (itemState
== kDataBrowserItemIsSelected
)
2794 GetThemeDrawingState(&savedState
);
2796 if (active
&& hasFocus
)
2798 GetThemeBrushAsColor(kThemeBrushAlternatePrimaryHighlightColor
, 32, true, &backgroundColor
);
2799 GetThemeTextColor(kThemeTextColorWhite
, gdDepth
, colorDevice
, &labelColor
);
2803 GetThemeBrushAsColor(kThemeBrushSecondaryHighlightColor
, 32, true, &backgroundColor
);
2804 GetThemeTextColor(kThemeTextColorBlack
, gdDepth
, colorDevice
, &labelColor
);
2806 wxMacCGContextStateSaver
cg( context
);
2808 CGContextSetRGBFillColor(context
, (CGFloat
)backgroundColor
.red
/ (CGFloat
)USHRT_MAX
,
2809 (CGFloat
)backgroundColor
.green
/ (CGFloat
)USHRT_MAX
,
2810 (CGFloat
)backgroundColor
.blue
/ (CGFloat
)USHRT_MAX
, (CGFloat
) 1.0);
2811 CGContextFillRect(context
, enclosingCGRect
);
2817 color
.GetRGBColor(&labelColor
);
2818 else if (list
->GetTextColour().IsOk())
2819 list
->GetTextColour().GetRGBColor(&labelColor
);
2823 bgColor
.GetRGBColor(&backgroundColor
);
2824 CGContextSaveGState(context
);
2826 CGContextSetRGBFillColor(context
, (CGFloat
)backgroundColor
.red
/ (CGFloat
)USHRT_MAX
,
2827 (CGFloat
)backgroundColor
.green
/ (CGFloat
)USHRT_MAX
,
2828 (CGFloat
)backgroundColor
.blue
/ (CGFloat
)USHRT_MAX
, (CGFloat
) 1.0);
2829 CGContextFillRect(context
, enclosingCGRect
);
2831 CGContextRestoreGState(context
);
2835 calculateCGDrawingBounds(enclosingCGRect
, &iconCGRect
, &textCGRect
, (imgIndex
!= -1) );
2839 wxImageList
* imageList
= list
->GetImageList(wxIMAGE_LIST_SMALL
);
2840 if (imageList
&& imageList
->GetImageCount() > 0)
2842 wxBitmap bmp
= imageList
->GetBitmap(imgIndex
);
2843 IconRef icon
= bmp
.GetIconRef();
2845 wxMacCGContextStateSaver
cg( context
);
2847 CGContextTranslateCTM(context
, 0,iconCGRect
.origin
.y
+ CGRectGetMaxY(iconCGRect
));
2848 CGContextScaleCTM(context
,1.0f
,-1.0f
);
2849 PlotIconRefInContext(context
, &iconCGRect
, kAlignNone
,
2850 active
? kTransformNone
: kTransformDisabled
, NULL
,
2851 kPlotIconRefNormalFlags
, icon
);
2855 HIThemeTextHorizontalFlush hFlush
= kHIThemeTextHorizontalFlushLeft
;
2856 HIThemeTextInfo info
;
2858 #if wxOSX_USE_CORE_TEXT
2859 if ( UMAGetSystemVersion() >= 0x1050 )
2861 info
.version
= kHIThemeTextInfoVersionOne
;
2862 info
.fontID
= kThemeViewsFont
;
2865 info
.fontID
= kThemeSpecifiedFont
;
2866 info
.font
= (CTFontRef
) font
.OSXGetCTFont();
2871 #if wxOSX_USE_ATSU_TEXT
2874 info
.version
= kHIThemeTextInfoVersionZero
;
2875 info
.fontID
= kThemeViewsFont
;
2879 info
.fontID
= font
.MacGetThemeFontID();
2881 ::TextSize( (short)(font
.GetPointSize()) ) ;
2882 ::TextFace( font
.MacGetFontStyle() ) ;
2888 list
->GetColumn(listColumn
, item
);
2889 if (item
.GetMask() & wxLIST_MASK_FORMAT
)
2891 if (item
.GetAlign() == wxLIST_FORMAT_LEFT
)
2892 hFlush
= kHIThemeTextHorizontalFlushLeft
;
2893 else if (item
.GetAlign() == wxLIST_FORMAT_CENTER
)
2894 hFlush
= kHIThemeTextHorizontalFlushCenter
;
2895 else if (item
.GetAlign() == wxLIST_FORMAT_RIGHT
)
2897 hFlush
= kHIThemeTextHorizontalFlushRight
;
2898 textCGRect
.origin
.x
-= kItemPadding
; // give a little extra paddding
2902 info
.state
= active
? kThemeStateActive
: kThemeStateInactive
;
2903 info
.horizontalFlushness
= hFlush
;
2904 info
.verticalFlushness
= kHIThemeTextVerticalFlushCenter
;
2905 info
.options
= kHIThemeTextBoxOptionNone
;
2906 info
.truncationPosition
= kHIThemeTextTruncationEnd
;
2907 info
.truncationMaxLines
= 1;
2910 wxMacCGContextStateSaver
cg( context
);
2911 CGContextSetRGBFillColor (context
, (CGFloat
)labelColor
.red
/ (CGFloat
)USHRT_MAX
,
2912 (CGFloat
)labelColor
.green
/ (CGFloat
)USHRT_MAX
,
2913 (CGFloat
)labelColor
.blue
/ (CGFloat
)USHRT_MAX
, (CGFloat
) 1.0);
2915 HIThemeDrawTextBox(cfString
, &textCGRect
, &info
, context
, kHIThemeOrientationNormal
);
2919 if (savedState
!= NULL
)
2920 SetThemeDrawingState(savedState
, true);
2924 OSStatus
wxMacDataBrowserListCtrlControl::GetSetItemData(DataBrowserItemID itemID
,
2925 DataBrowserPropertyID property
,
2926 DataBrowserItemDataRef itemData
,
2927 Boolean changeValue
)
2932 DataBrowserTableViewColumnIndex listColumn
= 0;
2933 verify_noerr( GetColumnPosition( property
, &listColumn
) );
2935 OSStatus err
= errDataBrowserPropertyNotSupported
;
2936 wxListCtrl
* list
= wxDynamicCast( GetWXPeer() , wxListCtrl
);
2937 wxMacListCtrlItem
* lcItem
= NULL
;
2939 if (listColumn
>= 0)
2943 lcItem
= (wxMacListCtrlItem
*) itemID
;
2944 if (lcItem
&& lcItem
->HasColumnInfo(listColumn
)){
2945 wxListItem
* item
= lcItem
->GetColumnInfo(listColumn
);
2946 if (item
->GetMask() & wxLIST_MASK_TEXT
)
2947 text
= item
->GetText();
2948 if (item
->GetMask() & wxLIST_MASK_IMAGE
)
2949 imgIndex
= item
->GetImage();
2954 long itemNum
= (long)itemID
-1;
2955 if (itemNum
>= 0 && itemNum
< list
->GetItemCount())
2957 text
= list
->OnGetItemText( itemNum
, listColumn
);
2958 imgIndex
= list
->OnGetItemColumnImage( itemNum
, listColumn
);
2967 case kDataBrowserItemIsEditableProperty
:
2968 if ( list
&& list
->HasFlag( wxLC_EDIT_LABELS
) )
2970 verify_noerr(SetDataBrowserItemDataBooleanValue( itemData
, true ));
2975 if ( property
>= kMinColumnId
)
2977 if (!text
.IsEmpty()){
2978 wxCFStringRef
cfStr( text
, wxLocale::GetSystemEncoding() );
2979 err
= ::SetDataBrowserItemDataText( itemData
, cfStr
);
2985 if ( imgIndex
!= -1 )
2987 wxImageList
* imageList
= list
->GetImageList(wxIMAGE_LIST_SMALL
);
2988 if (imageList
&& imageList
->GetImageCount() > 0){
2989 wxBitmap bmp
= imageList
->GetBitmap(imgIndex
);
2990 IconRef icon
= bmp
.GetIconRef();
2991 ::SetDataBrowserItemDataIcon(itemData
, icon
);
3005 if ( property
>= kMinColumnId
)
3007 DataBrowserTableViewColumnIndex listColumn
= 0;
3008 verify_noerr( GetColumnPosition( property
, &listColumn
) );
3010 // TODO probably send the 'end edit' from here, as we
3011 // can then deal with the veto
3013 verify_noerr( GetDataBrowserItemDataText( itemData
, &sr
) ) ;
3014 wxCFStringRef
cfStr(sr
) ;;
3016 list
->SetItem( (long)itemData
-1 , listColumn
, cfStr
.AsString() ) ;
3020 lcItem
->SetColumnTextValue( listColumn
, cfStr
.AsString() );
3030 void wxMacDataBrowserListCtrlControl::ItemNotification(DataBrowserItemID itemID
,
3031 DataBrowserItemNotification message
,
3032 DataBrowserItemDataRef itemData
)
3034 wxMacListCtrlItem
*item
= NULL
;
3037 item
= (wxMacListCtrlItem
*) itemID
;
3040 // we want to depend on as little as possible to make sure tear-down of controls is safe
3041 if ( message
== kDataBrowserItemRemoved
)
3044 item
->Notification(this, message
, itemData
);
3047 else if ( message
== kDataBrowserItemAdded
)
3049 // we don't issue events on adding, the item is not really stored in the list yet, so we
3050 // avoid asserts by getting out now
3052 item
->Notification(this, message
, itemData
);
3056 wxListCtrl
*list
= wxDynamicCast( GetWXPeer() , wxListCtrl
);
3059 bool trigger
= false;
3061 wxListEvent
event( wxEVT_LIST_ITEM_SELECTED
, list
->GetId() );
3063 event
.SetEventObject( list
);
3064 if ( !list
->IsVirtual() )
3066 DataBrowserTableViewRowIndex result
= 0;
3067 verify_noerr( GetItemRow( itemID
, &result
) ) ;
3068 event
.m_itemIndex
= result
;
3072 event
.m_itemIndex
= (long)itemID
-1;
3074 event
.m_item
.m_itemId
= event
.m_itemIndex
;
3075 list
->GetItem(event
.m_item
);
3079 case kDataBrowserItemDeselected
:
3080 event
.SetEventType(wxEVT_LIST_ITEM_DESELECTED
);
3081 // as the generic implementation is also triggering this
3082 // event for single selection, we do the same (different than listbox)
3083 trigger
= !IsSelectionSuppressed();
3086 case kDataBrowserItemSelected
:
3087 trigger
= !IsSelectionSuppressed();
3091 case kDataBrowserItemDoubleClicked
:
3092 event
.SetEventType( wxEVT_LIST_ITEM_ACTIVATED
);
3096 case kDataBrowserEditStarted
:
3097 // TODO : how to veto ?
3098 event
.SetEventType( wxEVT_LIST_BEGIN_LABEL_EDIT
) ;
3102 case kDataBrowserEditStopped
:
3103 // TODO probably trigger only upon the value store callback, because
3104 // here IIRC we cannot veto
3105 event
.SetEventType( wxEVT_LIST_END_LABEL_EDIT
) ;
3115 // direct notification is not always having the listbox GetSelection() having in synch with event
3116 wxPostEvent( list
->GetEventHandler(), event
);
3121 Boolean
wxMacDataBrowserListCtrlControl::CompareItems(DataBrowserItemID itemOneID
,
3122 DataBrowserItemID itemTwoID
,
3123 DataBrowserPropertyID sortProperty
)
3126 bool retval
= false;
3128 wxString otherItemText
;
3130 long otherItemOrder
;
3132 DataBrowserTableViewColumnIndex colId
= 0;
3133 verify_noerr( GetColumnPosition( sortProperty
, &colId
) );
3135 wxListCtrl
* list
= wxDynamicCast( GetWXPeer() , wxListCtrl
);
3137 DataBrowserSortOrder sort
;
3138 verify_noerr(GetSortOrder(&sort
));
3144 wxMacListCtrlItem
* item
= (wxMacListCtrlItem
*)itemOneID
;
3145 wxMacListCtrlItem
* otherItem
= (wxMacListCtrlItem
*)itemTwoID
;
3147 itemOrder
= item
->GetOrder();
3148 otherItemOrder
= otherItem
->GetOrder();
3150 wxListCtrlCompare func
= list
->GetCompareFunc();
3156 if (item
&& item
->HasColumnInfo(0))
3157 item1
= item
->GetColumnInfo(0)->GetData();
3158 if (otherItem
&& otherItem
->HasColumnInfo(0))
3159 item2
= otherItem
->GetColumnInfo(0)->GetData();
3161 if (item1
> -1 && item2
> -1)
3163 int result
= func(item1
, item2
, list
->GetCompareFuncData());
3164 if (sort
== kDataBrowserOrderIncreasing
)
3171 // we can't use the native control's sorting abilities, so just
3173 return itemOrder
< otherItemOrder
;
3178 long itemNum
= (long)itemOneID
;
3179 long otherItemNum
= (long)itemTwoID
;
3181 // virtual listctrls don't support sorting
3182 return itemNum
< otherItemNum
;
3186 // fallback for undefined cases
3187 retval
= itemOneID
< itemTwoID
;
3193 wxMacDataBrowserListCtrlControl::~wxMacDataBrowserListCtrlControl()
3197 void wxMacDataBrowserListCtrlControl::MacSetColumnInfo( unsigned int row
, unsigned int column
, wxListItem
* item
)
3199 wxMacDataItem
* dataItem
= GetItemFromLine(row
);
3200 wxASSERT_MSG( dataItem
, wxT("could not obtain wxMacDataItem for row in MacSetColumnInfo. Is row a valid wxListCtrl row?") );
3203 wxMacListCtrlItem
* listItem
= static_cast<wxMacListCtrlItem
*>(dataItem
);
3204 bool hasInfo
= listItem
->HasColumnInfo( column
);
3205 listItem
->SetColumnInfo( column
, item
);
3206 listItem
->SetOrder(row
);
3207 UpdateState(dataItem
, item
);
3209 wxListCtrl
* list
= wxDynamicCast( GetWXPeer() , wxListCtrl
);
3211 // NB: When this call was made before a control was completely shown, it would
3212 // update the item prematurely (i.e. no text would be listed) and, on show,
3213 // only the sorted column would be refreshed, meaning only first column text labels
3214 // would be shown. Making sure not to update items until the control is visible
3215 // seems to fix this issue.
3216 if (hasInfo
&& list
->IsShown())
3218 DataBrowserTableViewColumnID id
= 0;
3219 verify_noerr( GetColumnIDFromIndex( column
, &id
) );
3220 UpdateItem( wxMacDataBrowserRootContainer
, listItem
, id
);
3225 // apply changes that need to happen immediately, rather than when the
3226 // databrowser control fires a callback.
3227 void wxMacDataBrowserListCtrlControl::UpdateState(wxMacDataItem
* dataItem
, wxListItem
* listItem
)
3229 bool isSelected
= IsItemSelected( dataItem
);
3230 bool isSelectedState
= (listItem
->GetState() == wxLIST_STATE_SELECTED
);
3232 // toggle the selection state if wxListInfo state and actual state don't match.
3233 if ( listItem
->GetMask() & wxLIST_MASK_STATE
&& isSelected
!= isSelectedState
)
3235 DataBrowserSetOption options
= kDataBrowserItemsAdd
;
3236 if (!isSelectedState
)
3237 options
= kDataBrowserItemsRemove
;
3238 SetSelectedItem(dataItem
, options
);
3240 // TODO: Set column width if item width > than current column width
3243 void wxMacDataBrowserListCtrlControl::MacGetColumnInfo( unsigned int row
, unsigned int column
, wxListItem
& item
)
3245 wxMacDataItem
* dataItem
= GetItemFromLine(row
);
3246 wxASSERT_MSG( dataItem
, wxT("could not obtain wxMacDataItem in MacGetColumnInfo. Is row a valid wxListCtrl row?") );
3247 // CS should this guard against dataItem = 0 ? , as item is not a pointer if (item) is not appropriate
3250 wxMacListCtrlItem
* listItem
= static_cast<wxMacListCtrlItem
*>(dataItem
);
3252 if (!listItem
->HasColumnInfo( column
))
3255 wxListItem
* oldItem
= listItem
->GetColumnInfo( column
);
3259 long mask
= item
.GetMask();
3261 // by default, get everything for backwards compatibility
3264 if ( mask
& wxLIST_MASK_TEXT
)
3265 item
.SetText(oldItem
->GetText());
3266 if ( mask
& wxLIST_MASK_IMAGE
)
3267 item
.SetImage(oldItem
->GetImage());
3268 if ( mask
& wxLIST_MASK_DATA
)
3269 item
.SetData(oldItem
->GetData());
3270 if ( mask
& wxLIST_MASK_STATE
)
3271 item
.SetState(oldItem
->GetState());
3272 if ( mask
& wxLIST_MASK_WIDTH
)
3273 item
.SetWidth(oldItem
->GetWidth());
3274 if ( mask
& wxLIST_MASK_FORMAT
)
3275 item
.SetAlign(oldItem
->GetAlign());
3277 item
.SetTextColour(oldItem
->GetTextColour());
3278 item
.SetBackgroundColour(oldItem
->GetBackgroundColour());
3279 item
.SetFont(oldItem
->GetFont());
3284 void wxMacDataBrowserListCtrlControl::MacInsertItem( unsigned int n
, wxListItem
* item
)
3287 wxMacDataItemBrowserControl::MacInsert(n
, new wxMacListCtrlItem() );
3288 MacSetColumnInfo(n
, 0, item
);
3291 wxMacListCtrlItem::wxMacListCtrlItem()
3293 m_rowItems
= wxListItemList();
3296 int wxMacListCtrlItem::GetColumnImageValue( unsigned int column
)
3298 if ( HasColumnInfo(column
) )
3299 return GetColumnInfo(column
)->GetImage();
3304 void wxMacListCtrlItem::SetColumnImageValue( unsigned int column
, int imageIndex
)
3306 if ( HasColumnInfo(column
) )
3307 GetColumnInfo(column
)->SetImage(imageIndex
);
3310 wxString
wxMacListCtrlItem::GetColumnTextValue( unsigned int column
)
3312 /* TODO CHECK REMOVE
3316 if ( HasColumnInfo(column
) )
3317 return GetColumnInfo(column
)->GetText();
3319 return wxEmptyString
;
3322 void wxMacListCtrlItem::SetColumnTextValue( unsigned int column
, const wxString
& text
)
3324 if ( HasColumnInfo(column
) )
3325 GetColumnInfo(column
)->SetText(text
);
3327 /* TODO CHECK REMOVE
3328 // for compatibility with superclass APIs
3334 wxListItem
* wxMacListCtrlItem::GetColumnInfo( unsigned int column
)
3336 wxASSERT_MSG( HasColumnInfo(column
), wxT("invalid column index in wxMacListCtrlItem") );
3337 return m_rowItems
[column
];
3340 bool wxMacListCtrlItem::HasColumnInfo( unsigned int column
)
3342 return !(m_rowItems
.find( column
) == m_rowItems
.end());
3345 void wxMacListCtrlItem::SetColumnInfo( unsigned int column
, wxListItem
* item
)
3348 if ( !HasColumnInfo(column
) )
3350 wxListItem
* listItem
= new wxListItem(*item
);
3351 m_rowItems
[column
] = listItem
;
3355 wxListItem
* listItem
= GetColumnInfo( column
);
3356 long mask
= item
->GetMask();
3357 if (mask
& wxLIST_MASK_TEXT
)
3358 listItem
->SetText(item
->GetText());
3359 if (mask
& wxLIST_MASK_DATA
)
3360 listItem
->SetData(item
->GetData());
3361 if (mask
& wxLIST_MASK_IMAGE
)
3362 listItem
->SetImage(item
->GetImage());
3363 if (mask
& wxLIST_MASK_STATE
)
3364 listItem
->SetState(item
->GetState());
3365 if (mask
& wxLIST_MASK_FORMAT
)
3366 listItem
->SetAlign(item
->GetAlign());
3367 if (mask
& wxLIST_MASK_WIDTH
)
3368 listItem
->SetWidth(item
->GetWidth());
3370 if ( item
->HasAttributes() )
3372 if ( listItem
->HasAttributes() )
3373 listItem
->GetAttributes()->AssignFrom(*item
->GetAttributes());
3376 listItem
->SetTextColour(item
->GetTextColour());
3377 listItem
->SetBackgroundColour(item
->GetBackgroundColour());
3378 listItem
->SetFont(item
->GetFont());
3384 int wxListCtrl::CalcColumnAutoWidth(int col
) const
3388 for ( int i
= 0; i
< GetItemCount(); i
++ )
3391 info
.SetMask(wxLIST_MASK_TEXT
| wxLIST_MASK_IMAGE
);
3393 info
.SetColumn(col
);
3396 const wxFont font
= info
.GetFont();
3400 GetTextExtent(info
.GetText(), &w
, NULL
, NULL
, NULL
, &font
);
3402 GetTextExtent(info
.GetText(), &w
, NULL
);
3404 w
+= 2 * kItemPadding
;
3406 if ( info
.GetImage() != -1 )
3409 width
= wxMax(width
, w
);
3415 #endif // wxUSE_LISTCTRL