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_COMMAND_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_COMMAND_LIST_ITEM_RIGHT_CLICK
, event
.GetPosition());
565 void wxListCtrl::OnMiddleDown(wxMouseEvent
& event
)
568 FireMouseEvent(wxEVT_COMMAND_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_COMMAND_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
)
807 rv
= wxListCtrlBase::SetFont(font
);
809 rv
= m_genericImpl
->SetFont(font
);
813 bool wxListCtrl::SetForegroundColour(const wxColour
& colour
)
817 rv
= m_genericImpl
->SetForegroundColour(colour
);
819 SetTextColour(colour
);
823 bool wxListCtrl::SetBackgroundColour(const wxColour
& colour
)
827 rv
= m_genericImpl
->SetBackgroundColour(colour
);
833 wxColour
wxListCtrl::GetBackgroundColour() const
836 return m_genericImpl
->GetBackgroundColour();
843 void wxListCtrl::Freeze ()
846 m_genericImpl
->Freeze();
847 wxListCtrlBase::Freeze();
850 void wxListCtrl::Thaw ()
853 m_genericImpl
->Thaw();
854 wxListCtrlBase::Thaw();
857 void wxListCtrl::Update ()
860 m_genericImpl
->Update();
861 wxListCtrlBase::Update();
864 // ----------------------------------------------------------------------------
866 // ----------------------------------------------------------------------------
868 // Gets information about this column
869 bool wxListCtrl::GetColumn(int col
, wxListItem
& item
) const
872 return m_genericImpl
->GetColumn(col
, item
);
878 wxColumnList::compatibility_iterator node
= m_colsInfo
.Item( col
);
879 wxASSERT_MSG( node
, wxT("invalid column index in wxMacListCtrlItem") );
880 wxListItem
* column
= node
->GetData();
882 long mask
= column
->GetMask();
883 if (mask
& wxLIST_MASK_TEXT
)
884 item
.SetText(column
->GetText());
885 if (mask
& wxLIST_MASK_DATA
)
886 item
.SetData(column
->GetData());
887 if (mask
& wxLIST_MASK_IMAGE
)
888 item
.SetImage(column
->GetImage());
889 if (mask
& wxLIST_MASK_STATE
)
890 item
.SetState(column
->GetState());
891 if (mask
& wxLIST_MASK_FORMAT
)
892 item
.SetAlign(column
->GetAlign());
893 if (mask
& wxLIST_MASK_WIDTH
)
894 item
.SetWidth(column
->GetWidth());
900 // Sets information about this column
901 bool wxListCtrl::SetColumn(int col
, const wxListItem
& item
)
904 return m_genericImpl
->SetColumn(col
, item
);
908 wxASSERT_MSG( col
< (int)m_colsInfo
.GetCount(), wxT("invalid column index in wxMacListCtrlItem") );
910 long mask
= item
.GetMask();
913 GetColumn( col
, listItem
);
915 if (mask
& wxLIST_MASK_TEXT
)
916 listItem
.SetText(item
.GetText());
917 if (mask
& wxLIST_MASK_DATA
)
918 listItem
.SetData(item
.GetData());
919 if (mask
& wxLIST_MASK_IMAGE
)
920 listItem
.SetImage(item
.GetImage());
921 if (mask
& wxLIST_MASK_STATE
)
922 listItem
.SetState(item
.GetState());
923 if (mask
& wxLIST_MASK_FORMAT
)
924 listItem
.SetAlign(item
.GetAlign());
925 if (mask
& wxLIST_MASK_WIDTH
)
926 listItem
.SetWidth(item
.GetWidth());
929 // change the appearance in the databrowser.
930 DataBrowserListViewHeaderDesc columnDesc
;
931 columnDesc
.version
=kDataBrowserListViewLatestHeaderDesc
;
933 DataBrowserTableViewColumnID id
= 0;
934 verify_noerr( m_dbImpl
->GetColumnIDFromIndex( col
, &id
) );
935 verify_noerr( m_dbImpl
->GetHeaderDesc( id
, &columnDesc
) );
938 if (item.GetMask() & wxLIST_MASK_TEXT)
942 enc = GetFont().GetEncoding();
944 enc = wxLocale::GetSystemEncoding();
945 wxCFStringRef cfTitle;
946 cfTitle.Assign( item.GetText() , enc );
947 if(columnDesc.titleString)
948 CFRelease(columnDesc.titleString);
949 columnDesc.titleString = cfTitle;
953 if (item
.GetMask() & wxLIST_MASK_IMAGE
&& item
.GetImage() != -1 )
955 wxImageList
* imageList
= GetImageList(wxIMAGE_LIST_SMALL
);
956 if (imageList
&& imageList
->GetImageCount() > 0 )
958 wxBitmap bmp
= imageList
->GetBitmap( item
.GetImage() );
959 IconRef icon
= bmp
.GetIconRef();
960 columnDesc
.btnContentInfo
.u
.iconRef
= icon
;
961 columnDesc
.btnContentInfo
.contentType
= kControlContentIconRef
;
965 verify_noerr( m_dbImpl
->SetHeaderDesc( id
, &columnDesc
) );
971 int wxListCtrl::GetColumnCount() const
974 return m_genericImpl
->GetColumnCount();
979 m_dbImpl
->GetColumnCount(&count
);
986 // Gets the column width
987 int wxListCtrl::GetColumnWidth(int col
) const
990 return m_genericImpl
->GetColumnWidth(col
);
994 return m_dbImpl
->GetColumnWidth(col
);
1000 // Sets the column width
1001 bool wxListCtrl::SetColumnWidth(int col
, int width
)
1004 return m_genericImpl
->SetColumnWidth(col
, width
);
1008 if ( width
== wxLIST_AUTOSIZE_USEHEADER
)
1010 width
= 150; // FIXME
1015 for (int column
= 0; column
< GetColumnCount(); column
++)
1018 GetColumn(column
, colInfo
);
1020 colInfo
.SetWidth(width
);
1021 SetColumn(column
, colInfo
);
1023 const int mywidth
= (width
== wxLIST_AUTOSIZE
)
1024 ? CalcColumnAutoWidth(column
) : width
;
1025 m_dbImpl
->SetColumnWidth(column
, mywidth
);
1030 if ( width
== wxLIST_AUTOSIZE
)
1031 width
= CalcColumnAutoWidth(col
);
1034 GetColumn(col
, colInfo
);
1036 colInfo
.SetWidth(width
);
1037 SetColumn(col
, colInfo
);
1038 m_dbImpl
->SetColumnWidth(col
, width
);
1046 // Gets the number of items that can fit vertically in the
1047 // visible area of the list control (list or report view)
1048 // or the total number of items in the list control (icon
1049 // or small icon view)
1050 int wxListCtrl::GetCountPerPage() const
1053 return m_genericImpl
->GetCountPerPage();
1058 m_dbImpl
->GetDefaultRowHeight( &height
);
1060 return GetClientSize().y
/ height
;
1066 // Gets the edit control for editing labels.
1067 wxTextCtrl
* wxListCtrl::GetEditControl() const
1070 return m_genericImpl
->GetEditControl();
1075 // Gets information about the item
1076 bool wxListCtrl::GetItem(wxListItem
& info
) const
1079 return m_genericImpl
->GetItem(info
);
1085 if (info
.m_itemId
>= 0 && info
.m_itemId
< GetItemCount())
1087 m_dbImpl
->MacGetColumnInfo(info
.m_itemId
, info
.m_col
, info
);
1088 // MacGetColumnInfo returns erroneous information in the state field, so zero it.
1090 if (info
.GetMask() & wxLIST_MASK_STATE
)
1092 DataBrowserItemID id
= (DataBrowserItemID
)m_dbImpl
->GetItemFromLine(info
.m_itemId
);
1093 if (IsDataBrowserItemSelected( m_dbImpl
->GetControlRef(), id
))
1094 info
.SetState(info
.GetState() | wxLIST_STATE_SELECTED
);
1100 if (info
.m_itemId
>= 0 && info
.m_itemId
< GetItemCount())
1102 info
.SetText( OnGetItemText(info
.m_itemId
, info
.m_col
) );
1103 info
.SetImage( OnGetItemColumnImage(info
.m_itemId
, info
.m_col
) );
1104 if (info
.GetMask() & wxLIST_MASK_STATE
)
1106 if (IsDataBrowserItemSelected( m_dbImpl
->GetControlRef(), info
.m_itemId
+1 ))
1107 info
.SetState(info
.GetState() | wxLIST_STATE_SELECTED
);
1110 wxListItemAttr
* attrs
= OnGetItemAttr( info
.m_itemId
);
1113 info
.SetFont( attrs
->GetFont() );
1114 info
.SetBackgroundColour( attrs
->GetBackgroundColour() );
1115 info
.SetTextColour( attrs
->GetTextColour() );
1120 bool success
= true;
1124 // Sets information about the item
1125 bool wxListCtrl::SetItem(wxListItem
& info
)
1128 return m_genericImpl
->SetItem(info
);
1131 m_dbImpl
->MacSetColumnInfo( info
.m_itemId
, info
.m_col
, &info
);
1136 long wxListCtrl::SetItem(long index
, int col
, const wxString
& label
, int imageId
)
1139 return m_genericImpl
->SetItem(index
, col
, label
, imageId
);
1142 info
.m_text
= label
;
1143 info
.m_mask
= wxLIST_MASK_TEXT
;
1144 info
.m_itemId
= index
;
1148 info
.m_image
= imageId
;
1149 info
.m_mask
|= wxLIST_MASK_IMAGE
;
1151 return SetItem(info
);
1155 // Gets the item state
1156 int wxListCtrl::GetItemState(long item
, long stateMask
) const
1159 return m_genericImpl
->GetItemState(item
, stateMask
);
1163 if ( HasFlag(wxLC_VIRTUAL
) )
1165 if (stateMask
== wxLIST_STATE_SELECTED
)
1167 if (IsDataBrowserItemSelected( m_dbImpl
->GetControlRef(), item
+1 ))
1168 return wxLIST_STATE_SELECTED
;
1177 info
.m_mask
= wxLIST_MASK_STATE
;
1178 info
.m_stateMask
= stateMask
;
1179 info
.m_itemId
= item
;
1184 return info
.m_state
;
1191 // Sets the item state
1192 bool wxListCtrl::SetItemState(long item
, long state
, long stateMask
)
1195 return m_genericImpl
->SetItemState(item
, state
, stateMask
);
1199 DataBrowserSetOption option
= kDataBrowserItemsAdd
;
1200 if ( (stateMask
& wxLIST_STATE_SELECTED
) && state
== 0 )
1201 option
= kDataBrowserItemsRemove
;
1205 if ( HasFlag(wxLC_VIRTUAL
) )
1207 wxMacDataItemBrowserSelectionSuppressor
suppressor(m_dbImpl
);
1208 m_dbImpl
->SetSelectedAllItems(option
);
1212 for(int i
= 0; i
< GetItemCount();i
++)
1216 info
.m_mask
= wxLIST_MASK_STATE
;
1217 info
.m_stateMask
= stateMask
;
1218 info
.m_state
= state
;
1225 if ( HasFlag(wxLC_VIRTUAL
) )
1227 long itemID
= item
+1;
1228 bool isSelected
= IsDataBrowserItemSelected(m_dbImpl
->GetControlRef(), (DataBrowserItemID
)itemID
);
1229 bool isSelectedState
= (state
== wxLIST_STATE_SELECTED
);
1231 // toggle the selection state if wxListInfo state and actual state don't match.
1232 if ( (stateMask
& wxLIST_STATE_SELECTED
) && isSelected
!= isSelectedState
)
1234 SetDataBrowserSelectedItems(m_dbImpl
->GetControlRef(), 1, (DataBrowserItemID
*)&itemID
, option
);
1240 info
.m_itemId
= item
;
1241 info
.m_mask
= wxLIST_MASK_STATE
;
1242 info
.m_stateMask
= stateMask
;
1243 info
.m_state
= state
;
1244 return SetItem(info
);
1251 // Sets the item image
1252 bool wxListCtrl::SetItemImage(long item
, int image
, int WXUNUSED(selImage
))
1254 return SetItemColumnImage(item
, 0, image
);
1257 // Sets the item image
1258 bool wxListCtrl::SetItemColumnImage(long item
, long column
, int image
)
1261 return m_genericImpl
->SetItemColumnImage(item
, column
, image
);
1265 info
.m_mask
= wxLIST_MASK_IMAGE
;
1266 info
.m_image
= image
;
1267 info
.m_itemId
= item
;
1268 info
.m_col
= column
;
1270 return SetItem(info
);
1273 // Gets the item text
1274 wxString
wxListCtrl::GetItemText(long item
, int column
) const
1277 return m_genericImpl
->GetItemText(item
, column
);
1281 info
.m_mask
= wxLIST_MASK_TEXT
;
1282 info
.m_itemId
= item
;
1283 info
.m_col
= column
;
1286 return wxEmptyString
;
1290 // Sets the item text
1291 void wxListCtrl::SetItemText(long item
, const wxString
& str
)
1294 return m_genericImpl
->SetItemText(item
, str
);
1298 info
.m_mask
= wxLIST_MASK_TEXT
;
1299 info
.m_itemId
= item
;
1305 // Gets the item data
1306 long wxListCtrl::GetItemData(long item
) const
1309 return m_genericImpl
->GetItemData(item
);
1313 info
.m_mask
= wxLIST_MASK_DATA
;
1314 info
.m_itemId
= item
;
1321 // Sets the item data
1322 bool wxListCtrl::SetItemPtrData(long item
, wxUIntPtr data
)
1325 return m_genericImpl
->SetItemData(item
, data
);
1329 info
.m_mask
= wxLIST_MASK_DATA
;
1330 info
.m_itemId
= item
;
1333 return SetItem(info
);
1336 wxRect
wxListCtrl::GetViewRect() const
1338 wxASSERT_MSG( !HasFlag(wxLC_REPORT
| wxLC_LIST
),
1339 wxT("wxListCtrl::GetViewRect() only works in icon mode") );
1342 return m_genericImpl
->GetViewRect();
1348 bool wxListCtrl::GetSubItemRect( long item
, long subItem
, wxRect
& rect
, int code
) const
1351 return m_genericImpl
->GetSubItemRect(item
, subItem
, rect
, code
);
1353 // TODO: implement for DataBrowser implementation
1357 // Gets the item rectangle
1358 bool wxListCtrl::GetItemRect(long item
, wxRect
& rect
, int code
) const
1361 return m_genericImpl
->GetItemRect(item
, rect
, code
);
1366 DataBrowserItemID id
;
1368 DataBrowserTableViewColumnID col
= 0;
1369 verify_noerr( m_dbImpl
->GetColumnIDFromIndex( 0, &col
) );
1372 DataBrowserPropertyPart part
= kDataBrowserPropertyEnclosingPart
;
1373 if ( code
== wxLIST_RECT_LABEL
)
1374 part
= kDataBrowserPropertyTextPart
;
1375 else if ( code
== wxLIST_RECT_ICON
)
1376 part
= kDataBrowserPropertyIconPart
;
1378 if ( !(GetWindowStyleFlag() & wxLC_VIRTUAL
) )
1380 wxMacDataItem
* thisItem
= m_dbImpl
->GetItemFromLine(item
);
1381 id
= (DataBrowserItemID
) thisItem
;
1386 GetDataBrowserItemPartBounds( m_dbImpl
->GetControlRef(), id
, col
, part
, &bounds
);
1388 rect
.x
= bounds
.left
;
1389 rect
.y
= bounds
.top
;
1390 rect
.width
= bounds
.right
- bounds
.left
; //GetClientSize().x; // we need the width of the whole row, not just the item.
1391 rect
.height
= bounds
.bottom
- bounds
.top
;
1392 //fprintf("id = %d, bounds = %d, %d, %d, %d\n", id, rect.x, rect.y, rect.width, rect.height);
1397 // Gets the item position
1398 bool wxListCtrl::GetItemPosition(long item
, wxPoint
& pos
) const
1401 return m_genericImpl
->GetItemPosition(item
, pos
);
1403 bool success
= false;
1408 GetItemRect(item
, itemRect
);
1409 pos
= itemRect
.GetPosition();
1416 // Sets the item position.
1417 bool wxListCtrl::SetItemPosition(long item
, const wxPoint
& pos
)
1420 return m_genericImpl
->SetItemPosition(item
, pos
);
1425 // Gets the number of items in the list control
1426 int wxListCtrl::GetItemCount() const
1429 return m_genericImpl
->GetItemCount();
1432 return m_dbImpl
->MacGetCount();
1437 void wxListCtrl::SetItemSpacing( int spacing
, bool isSmall
)
1440 m_genericImpl
->SetItemSpacing(spacing
, isSmall
);
1443 wxSize
wxListCtrl::GetItemSpacing() const
1446 return m_genericImpl
->GetItemSpacing();
1448 return wxSize(0, 0);
1451 void wxListCtrl::SetItemTextColour( long item
, const wxColour
&col
)
1455 m_genericImpl
->SetItemTextColour(item
, col
);
1460 info
.m_itemId
= item
;
1461 info
.SetTextColour( col
);
1465 wxColour
wxListCtrl::GetItemTextColour( long item
) const
1468 return m_genericImpl
->GetItemTextColour(item
);
1474 return info
.GetTextColour();
1476 return wxNullColour
;
1479 void wxListCtrl::SetItemBackgroundColour( long item
, const wxColour
&col
)
1483 m_genericImpl
->SetItemBackgroundColour(item
, col
);
1488 info
.m_itemId
= item
;
1489 info
.SetBackgroundColour( col
);
1493 wxColour
wxListCtrl::GetItemBackgroundColour( long item
) const
1496 return m_genericImpl
->GetItemBackgroundColour(item
);
1502 return info
.GetBackgroundColour();
1504 return wxNullColour
;
1507 void wxListCtrl::SetItemFont( long item
, const wxFont
&f
)
1511 m_genericImpl
->SetItemFont(item
, f
);
1516 info
.m_itemId
= item
;
1521 wxFont
wxListCtrl::GetItemFont( long item
) const
1524 return m_genericImpl
->GetItemFont(item
);
1530 return info
.GetFont();
1536 // Gets the number of selected items in the list control
1537 int wxListCtrl::GetSelectedItemCount() const
1540 return m_genericImpl
->GetSelectedItemCount();
1543 return m_dbImpl
->GetSelectedItemCount(NULL
, true);
1548 // Gets the text colour of the listview
1549 wxColour
wxListCtrl::GetTextColour() const
1552 return m_genericImpl
->GetTextColour();
1554 // TODO: we need owner drawn list items to customize text color.
1558 return wxNullColour
;
1561 // Sets the text colour of the listview
1562 void wxListCtrl::SetTextColour(const wxColour
& col
)
1566 m_genericImpl
->SetTextColour(col
);
1574 // Gets the index of the topmost visible item when in
1575 // list or report view
1576 long wxListCtrl::GetTopItem() const
1579 return m_genericImpl
->GetTopItem();
1584 long item
= HitTest( wxPoint(1, 1), flags
);
1585 if (flags
== wxLIST_HITTEST_ONITEM
)
1592 // Searches for an item, starting from 'item'.
1593 // 'geometry' is one of
1594 // wxLIST_NEXT_ABOVE/ALL/BELOW/LEFT/RIGHT.
1595 // 'state' is a state bit flag, one or more of
1596 // wxLIST_STATE_DROPHILITED/FOCUSED/SELECTED/CUT.
1597 // item can be -1 to find the first item that matches the
1599 // Returns the item or -1 if unsuccessful.
1600 long wxListCtrl::GetNextItem(long item
, int geom
, int state
) const
1603 return m_genericImpl
->GetNextItem(item
, geom
, state
);
1605 // TODO: implement all geometry and state options?
1608 if ( geom
== wxLIST_NEXT_ALL
|| geom
== wxLIST_NEXT_BELOW
)
1610 long count
= m_dbImpl
->MacGetCount() ;
1611 for ( long line
= item
+ 1 ; line
< count
; line
++ )
1613 DataBrowserItemID id
= line
+ 1;
1615 id
= (DataBrowserItemID
)m_dbImpl
->GetItemFromLine(line
);
1617 if ( (state
& wxLIST_STATE_FOCUSED
) && (m_current
== line
))
1620 if ( (state
== wxLIST_STATE_DONTCARE
) )
1623 if ( (state
& wxLIST_STATE_SELECTED
) && IsDataBrowserItemSelected(m_dbImpl
->GetControlRef(), id
) )
1628 if ( geom
== wxLIST_NEXT_ABOVE
)
1632 item2
= m_dbImpl
->MacGetCount();
1634 for ( long line
= item2
- 1 ; line
>= 0; line
-- )
1636 DataBrowserItemID id
= line
+ 1;
1638 id
= (DataBrowserItemID
)m_dbImpl
->GetItemFromLine(line
);
1640 if ( (state
& wxLIST_STATE_FOCUSED
) && (m_current
== line
))
1643 if ( (state
== wxLIST_STATE_DONTCARE
) )
1646 if ( (state
& wxLIST_STATE_SELECTED
) && IsDataBrowserItemSelected(m_dbImpl
->GetControlRef(), id
) )
1656 wxImageList
*wxListCtrl::GetImageList(int which
) const
1659 return m_genericImpl
->GetImageList(which
);
1661 if ( which
== wxIMAGE_LIST_NORMAL
)
1663 return m_imageListNormal
;
1665 else if ( which
== wxIMAGE_LIST_SMALL
)
1667 return m_imageListSmall
;
1669 else if ( which
== wxIMAGE_LIST_STATE
)
1671 return m_imageListState
;
1676 void wxListCtrl::SetImageList(wxImageList
*imageList
, int which
)
1680 m_genericImpl
->SetImageList(imageList
, which
);
1684 if ( which
== wxIMAGE_LIST_NORMAL
)
1686 if (m_ownsImageListNormal
) delete m_imageListNormal
;
1687 m_imageListNormal
= imageList
;
1688 m_ownsImageListNormal
= false;
1690 else if ( which
== wxIMAGE_LIST_SMALL
)
1692 if (m_ownsImageListSmall
) delete m_imageListSmall
;
1693 m_imageListSmall
= imageList
;
1694 m_ownsImageListSmall
= false;
1696 else if ( which
== wxIMAGE_LIST_STATE
)
1698 if (m_ownsImageListState
) delete m_imageListState
;
1699 m_imageListState
= imageList
;
1700 m_ownsImageListState
= false;
1704 void wxListCtrl::AssignImageList(wxImageList
*imageList
, int which
)
1708 m_genericImpl
->AssignImageList(imageList
, which
);
1712 SetImageList(imageList
, which
);
1713 if ( which
== wxIMAGE_LIST_NORMAL
)
1714 m_ownsImageListNormal
= true;
1715 else if ( which
== wxIMAGE_LIST_SMALL
)
1716 m_ownsImageListSmall
= true;
1717 else if ( which
== wxIMAGE_LIST_STATE
)
1718 m_ownsImageListState
= true;
1721 // ----------------------------------------------------------------------------
1723 // ----------------------------------------------------------------------------
1725 // Arranges the items
1726 bool wxListCtrl::Arrange(int flag
)
1729 return m_genericImpl
->Arrange(flag
);
1734 bool wxListCtrl::DeleteItem(long item
)
1737 return m_genericImpl
->DeleteItem(item
);
1741 m_dbImpl
->MacDelete(item
);
1742 wxListEvent
event( wxEVT_COMMAND_LIST_DELETE_ITEM
, GetId() );
1743 event
.SetEventObject( this );
1744 event
.m_itemIndex
= item
;
1745 HandleWindowEvent( event
);
1751 // Deletes all items
1752 bool wxListCtrl::DeleteAllItems()
1756 return m_genericImpl
->DeleteAllItems();
1760 m_dbImpl
->MacClear();
1761 wxListEvent
event( wxEVT_COMMAND_LIST_DELETE_ALL_ITEMS
, GetId() );
1762 event
.SetEventObject( this );
1763 HandleWindowEvent( event
);
1768 // Deletes all items
1769 bool wxListCtrl::DeleteAllColumns()
1772 return m_genericImpl
->DeleteAllColumns();
1777 m_dbImpl
->GetColumnCount(&cols
);
1778 for (UInt32 col
= 0; col
< cols
; col
++)
1788 bool wxListCtrl::DeleteColumn(int col
)
1791 return m_genericImpl
->DeleteColumn(col
);
1795 OSStatus err
= m_dbImpl
->RemoveColumn(col
);
1796 return err
== noErr
;
1802 // Clears items, and columns if there are any.
1803 void wxListCtrl::ClearAll()
1807 m_genericImpl
->ClearAll();
1818 wxTextCtrl
* wxListCtrl::EditLabel(long item
, wxClassInfo
* textControlClass
)
1821 return m_genericImpl
->EditLabel(item
, textControlClass
);
1825 wxCHECK_MSG( (item
>= 0) && ((long)item
< GetItemCount()), NULL
,
1826 wxT("wrong index in wxListCtrl::EditLabel()") );
1828 wxASSERT_MSG( textControlClass
->IsKindOf(CLASSINFO(wxTextCtrl
)),
1829 wxT("EditLabel() needs a text control") );
1831 wxListEvent
le( wxEVT_COMMAND_LIST_BEGIN_LABEL_EDIT
, GetParent()->GetId() );
1832 le
.SetEventObject( this );
1833 le
.m_itemIndex
= item
;
1835 GetItem( le
.m_item
);
1837 if ( GetParent()->HandleWindowEvent( le
) && !le
.IsAllowed() )
1839 // vetoed by user code
1843 wxTextCtrl
* const text
= (wxTextCtrl
*)textControlClass
->CreateObject();
1844 m_textctrlWrapper
= new wxListCtrlTextCtrlWrapper(this, text
, item
);
1845 return m_textctrlWrapper
->GetText();
1850 // End label editing, optionally cancelling the edit
1851 bool wxListCtrl::EndEditLabel(bool WXUNUSED(cancel
))
1853 // TODO: generic impl. doesn't have this method - is it needed for us?
1855 return true; // m_genericImpl->EndEditLabel(cancel);
1859 DataBrowserTableViewColumnID id
= 0;
1860 verify_noerr( m_dbImpl
->GetColumnIDFromIndex( 0, &id
) );
1861 verify_noerr( SetDataBrowserEditItem(m_dbImpl
->GetControlRef(), kDataBrowserNoItem
, id
) );
1866 // Ensures this item is visible
1867 bool wxListCtrl::EnsureVisible(long item
)
1870 return m_genericImpl
->EnsureVisible(item
);
1874 wxMacDataItem
* dataItem
= m_dbImpl
->GetItemFromLine(item
);
1875 m_dbImpl
->RevealItem(dataItem
, kDataBrowserRevealWithoutSelecting
);
1881 // Find an item whose label matches this string, starting from the item after 'start'
1882 // or the beginning if 'start' is -1.
1883 long wxListCtrl::FindItem(long start
, const wxString
& str
, bool partial
)
1886 return m_genericImpl
->FindItem(start
, str
, partial
);
1888 wxString str_upper
= str
.Upper();
1893 long count
= GetItemCount();
1897 wxString line_upper
= GetItemText(idx
).Upper();
1900 if (line_upper
== str_upper
)
1905 if (line_upper
.find(str_upper
) == 0)
1915 // Find an item whose data matches this data, starting from the item after 'start'
1916 // or the beginning if 'start' is -1.
1917 long wxListCtrl::FindItem(long start
, long data
)
1920 return m_genericImpl
->FindItem(start
, data
);
1925 long count
= GetItemCount();
1929 if (GetItemData(idx
) == data
)
1937 // Find an item nearest this position in the specified direction, starting from
1938 // the item after 'start' or the beginning if 'start' is -1.
1939 long wxListCtrl::FindItem(long start
, const wxPoint
& pt
, int direction
)
1942 return m_genericImpl
->FindItem(start
, pt
, direction
);
1946 static void calculateCGDrawingBounds(CGRect inItemRect
, CGRect
*outIconRect
, CGRect
*outTextRect
, bool hasIcon
);
1948 // Determines which item (if any) is at the specified point,
1949 // giving details in 'flags' (see wxLIST_HITTEST_... flags above)
1951 wxListCtrl::HitTest(const wxPoint
& point
, int& flags
, long *ptrSubItem
) const
1957 return m_genericImpl
->HitTest(point
, flags
, ptrSubItem
);
1959 flags
= wxLIST_HITTEST_NOWHERE
;
1962 int colHeaderHeight
= 22; // TODO: Find a way to get this value from the db control?
1963 UInt16 rowHeight
= 0;
1964 m_dbImpl
->GetDefaultRowHeight(&rowHeight
);
1967 // get the actual row by taking scroll position into account
1968 UInt32 offsetX
, offsetY
;
1969 m_dbImpl
->GetScrollPosition( &offsetY
, &offsetX
);
1972 if ( !(GetWindowStyleFlag() & wxLC_NO_HEADER
) )
1973 y
-= colHeaderHeight
;
1978 int row
= y
/ rowHeight
;
1979 DataBrowserItemID id
;
1980 m_dbImpl
->GetItemID( (DataBrowserTableViewRowIndex
) row
, &id
);
1982 CGPoint click_point
= CGPointMake( point
.x
, point
.y
);
1983 if (row
< GetItemCount() )
1986 for( column
= 0; column
< GetColumnCount(); column
++ )
1989 CGRect enclosingCGRect
, iconCGRect
, textCGRect
;
1991 wxMacListCtrlItem
* lcItem
;
1993 WXUNUSED_UNLESS_DEBUG( OSStatus status
= ) m_dbImpl
->GetItemPartBounds( id
, kMinColumnId
+ column
, kDataBrowserPropertyEnclosingPart
, &enclosingRect
);
1994 wxASSERT( status
== noErr
);
1996 enclosingCGRect
= CGRectMake(enclosingRect
.left
,
1998 enclosingRect
.right
- enclosingRect
.left
,
1999 enclosingRect
.bottom
- enclosingRect
.top
);
2003 if ( !(GetWindowStyleFlag() & wxLC_VIRTUAL
) )
2005 lcItem
= (wxMacListCtrlItem
*) id
;
2006 if (lcItem
->HasColumnInfo(column
))
2008 wxListItem
* item
= lcItem
->GetColumnInfo(column
);
2010 if (item
->GetMask() & wxLIST_MASK_IMAGE
)
2012 imgIndex
= item
->GetImage();
2018 long itemNum
= (long)id
-1;
2019 if (itemNum
>= 0 && itemNum
< GetItemCount())
2021 imgIndex
= OnGetItemColumnImage( itemNum
, column
);
2026 calculateCGDrawingBounds(enclosingCGRect
, &iconCGRect
, &textCGRect
, (imgIndex
!= -1) );
2028 if ( CGRectContainsPoint( iconCGRect
, click_point
) )
2030 flags
= wxLIST_HITTEST_ONITEMICON
;
2032 *ptrSubItem
= column
;
2035 else if ( CGRectContainsPoint( textCGRect
, click_point
) )
2037 flags
= wxLIST_HITTEST_ONITEMLABEL
;
2039 *ptrSubItem
= column
;
2044 if ( !(GetWindowStyleFlag() & wxLC_VIRTUAL
) )
2046 wxMacListCtrlItem
* lcItem
;
2047 lcItem
= (wxMacListCtrlItem
*) id
;
2050 flags
= wxLIST_HITTEST_ONITEM
;
2052 *ptrSubItem
= column
;
2058 flags
= wxLIST_HITTEST_ONITEM
;
2060 *ptrSubItem
= column
;
2066 if ( wxControl::HitTest( point
) )
2067 flags
= wxLIST_HITTEST_NOWHERE
;
2074 int wxListCtrl::GetScrollPos(int orient
) const
2077 return m_genericImpl
->GetScrollPos(orient
);
2081 UInt32 offsetX
, offsetY
;
2082 m_dbImpl
->GetScrollPosition( &offsetY
, &offsetX
);
2083 if ( orient
== wxHORIZONTAL
)
2092 // Inserts an item, returning the index of the new item if successful,
2094 long wxListCtrl::InsertItem(wxListItem
& info
)
2096 wxASSERT_MSG( !IsVirtual(), wxT("can't be used with virtual controls") );
2099 return m_genericImpl
->InsertItem(info
);
2101 if (m_dbImpl
&& !IsVirtual())
2103 int count
= GetItemCount();
2105 if (info
.m_itemId
> count
)
2106 info
.m_itemId
= count
;
2108 m_dbImpl
->MacInsertItem(info
.m_itemId
, &info
);
2110 wxListEvent
event( wxEVT_COMMAND_LIST_INSERT_ITEM
, GetId() );
2111 event
.SetEventObject( this );
2112 event
.m_itemIndex
= info
.m_itemId
;
2113 HandleWindowEvent( event
);
2114 return info
.m_itemId
;
2119 long wxListCtrl::InsertItem(long index
, const wxString
& label
)
2122 return m_genericImpl
->InsertItem(index
, label
);
2125 info
.m_text
= label
;
2126 info
.m_mask
= wxLIST_MASK_TEXT
;
2127 info
.m_itemId
= index
;
2128 return InsertItem(info
);
2131 // Inserts an image item
2132 long wxListCtrl::InsertItem(long index
, int imageIndex
)
2135 return m_genericImpl
->InsertItem(index
, imageIndex
);
2138 info
.m_image
= imageIndex
;
2139 info
.m_mask
= wxLIST_MASK_IMAGE
;
2140 info
.m_itemId
= index
;
2141 return InsertItem(info
);
2144 // Inserts an image/string item
2145 long wxListCtrl::InsertItem(long index
, const wxString
& label
, int imageIndex
)
2148 return m_genericImpl
->InsertItem(index
, label
, imageIndex
);
2151 info
.m_image
= imageIndex
;
2152 info
.m_text
= label
;
2153 info
.m_mask
= wxLIST_MASK_IMAGE
| wxLIST_MASK_TEXT
;
2154 info
.m_itemId
= index
;
2155 return InsertItem(info
);
2158 // For list view mode (only), inserts a column.
2159 long wxListCtrl::DoInsertColumn(long col
, const wxListItem
& item
)
2162 return m_genericImpl
->InsertColumn(col
, item
);
2166 int width
= item
.GetWidth();
2167 if ( !(item
.GetMask() & wxLIST_MASK_WIDTH
) )
2170 DataBrowserPropertyType type
= kDataBrowserCustomType
; //kDataBrowserTextType;
2171 wxImageList
* imageList
= GetImageList(wxIMAGE_LIST_SMALL
);
2172 if (imageList
&& imageList
->GetImageCount() > 0)
2174 wxBitmap bmp
= imageList
->GetBitmap(0);
2176 // type = kDataBrowserIconAndTextType;
2179 SInt16 just
= teFlushDefault
;
2180 if (item
.GetMask() & wxLIST_MASK_FORMAT
)
2182 if (item
.GetAlign() == wxLIST_FORMAT_LEFT
)
2184 else if (item
.GetAlign() == wxLIST_FORMAT_CENTER
)
2186 else if (item
.GetAlign() == wxLIST_FORMAT_RIGHT
)
2187 just
= teFlushRight
;
2189 m_dbImpl
->InsertColumn(col
, type
, item
.GetText(), just
, width
);
2191 wxListItem
* listItem
= new wxListItem(item
);
2192 m_colsInfo
.Insert( col
, listItem
);
2193 SetColumn(col
, item
);
2195 // set/remove options based on the wxListCtrl type.
2196 DataBrowserTableViewColumnID id
;
2197 m_dbImpl
->GetColumnIDFromIndex(col
, &id
);
2198 DataBrowserPropertyFlags flags
;
2199 verify_noerr(m_dbImpl
->GetPropertyFlags(id
, &flags
));
2200 if (GetWindowStyleFlag() & wxLC_EDIT_LABELS
)
2201 flags
|= kDataBrowserPropertyIsEditable
;
2203 if (GetWindowStyleFlag() & wxLC_VIRTUAL
){
2204 flags
&= ~kDataBrowserListViewSortableColumn
;
2206 verify_noerr(m_dbImpl
->SetPropertyFlags(id
, flags
));
2212 // scroll the control by the given number of pixels (exception: in list view,
2213 // dx is interpreted as number of columns)
2214 bool wxListCtrl::ScrollList(int dx
, int dy
)
2217 return m_genericImpl
->ScrollList(dx
, dy
);
2221 // Notice that the parameter order is correct here: first argument is
2222 // the "top" displacement, second one is the "left" one.
2223 m_dbImpl
->SetScrollPosition(dy
, dx
);
2229 bool wxListCtrl::SortItems(wxListCtrlCompare fn
, wxIntPtr data
)
2232 return m_genericImpl
->SortItems(fn
, data
);
2237 m_compareFuncData
= data
;
2238 SortDataBrowserContainer( m_dbImpl
->GetControlRef(), kDataBrowserNoItem
, true);
2240 // we need to do this after each call, else we get a crash from wxPython when
2241 // SortItems is called the second time.
2242 m_compareFunc
= NULL
;
2243 m_compareFuncData
= 0;
2249 void wxListCtrl::OnRenameTimer()
2251 wxCHECK_RET( HasCurrent(), wxT("unexpected rename timer") );
2253 EditLabel( m_current
);
2256 bool wxListCtrl::OnRenameAccept(long itemEdit
, const wxString
& value
)
2258 wxListEvent
le( wxEVT_COMMAND_LIST_END_LABEL_EDIT
, GetId() );
2259 le
.SetEventObject( this );
2260 le
.m_itemIndex
= itemEdit
;
2262 GetItem( le
.m_item
);
2263 le
.m_item
.m_text
= value
;
2264 return !HandleWindowEvent( le
) ||
2268 void wxListCtrl::OnRenameCancelled(long itemEdit
)
2270 // let owner know that the edit was cancelled
2271 wxListEvent
le( wxEVT_COMMAND_LIST_END_LABEL_EDIT
, GetParent()->GetId() );
2273 le
.SetEditCanceled(true);
2275 le
.SetEventObject( this );
2276 le
.m_itemIndex
= itemEdit
;
2278 GetItem( le
.m_item
);
2279 HandleWindowEvent( le
);
2282 // ----------------------------------------------------------------------------
2283 // virtual list controls
2284 // ----------------------------------------------------------------------------
2286 wxString
wxListCtrl::OnGetItemText(long WXUNUSED(item
), long WXUNUSED(col
)) const
2288 // this is a pure virtual function, in fact - which is not really pure
2289 // because the controls which are not virtual don't need to implement it
2290 wxFAIL_MSG( wxT("wxListCtrl::OnGetItemText not supposed to be called") );
2292 return wxEmptyString
;
2295 int wxListCtrl::OnGetItemImage(long WXUNUSED(item
)) const
2297 wxCHECK_MSG(!GetImageList(wxIMAGE_LIST_SMALL
),
2299 wxT("List control has an image list, OnGetItemImage or OnGetItemColumnImage should be overridden."));
2303 int wxListCtrl::OnGetItemColumnImage(long item
, long column
) const
2306 return OnGetItemImage(item
);
2311 wxListItemAttr
*wxListCtrl::OnGetItemAttr(long WXUNUSED_UNLESS_DEBUG(item
)) const
2313 wxASSERT_MSG( item
>= 0 && item
< GetItemCount(),
2314 wxT("invalid item index in OnGetItemAttr()") );
2316 // no attributes by default
2320 void wxListCtrl::SetItemCount(long count
)
2322 wxASSERT_MSG( IsVirtual(), wxT("this is for virtual controls only") );
2326 m_genericImpl
->SetItemCount(count
);
2332 // we need to temporarily disable the new item creation notification
2333 // procedure to speed things up
2334 // FIXME: Even this doesn't seem to help much...
2336 // FIXME: Find a more efficient way to do this.
2337 m_dbImpl
->MacClear();
2339 DataBrowserCallbacks callbacks
;
2340 DataBrowserItemNotificationUPP itemUPP
;
2341 GetDataBrowserCallbacks(m_dbImpl
->GetControlRef(), &callbacks
);
2342 itemUPP
= callbacks
.u
.v1
.itemNotificationCallback
;
2343 callbacks
.u
.v1
.itemNotificationCallback
= 0;
2344 m_dbImpl
->SetCallbacks(&callbacks
);
2345 ::AddDataBrowserItems(m_dbImpl
->GetControlRef(), kDataBrowserNoItem
,
2346 count
, NULL
, kDataBrowserItemNoProperty
);
2347 callbacks
.u
.v1
.itemNotificationCallback
= itemUPP
;
2348 m_dbImpl
->SetCallbacks(&callbacks
);
2353 void wxListCtrl::RefreshItem(long item
)
2357 m_genericImpl
->RefreshItem(item
);
2363 DataBrowserItemID id
;
2367 wxMacDataItem
* thisItem
= m_dbImpl
->GetItemFromLine(item
);
2368 id
= (DataBrowserItemID
) thisItem
;
2373 m_dbImpl
->wxMacDataBrowserControl::UpdateItems
2377 kDataBrowserItemNoProperty
, // preSortProperty
2378 kDataBrowserNoItem
// update all columns
2383 void wxListCtrl::RefreshItems(long itemFrom
, long itemTo
)
2387 m_genericImpl
->RefreshItems(itemFrom
, itemTo
);
2393 const long count
= itemTo
- itemFrom
+ 1;
2394 DataBrowserItemID
*ids
= new DataBrowserItemID
[count
];
2398 for ( long i
= 0; i
< count
; i
++ )
2400 wxMacDataItem
* thisItem
= m_dbImpl
->GetItemFromLine(itemFrom
+i
);
2401 ids
[i
] = (DataBrowserItemID
) thisItem
;
2406 for ( long i
= 0; i
< count
; i
++ )
2407 ids
[i
] = itemFrom
+i
+1;
2410 m_dbImpl
->wxMacDataBrowserControl::UpdateItems
2414 kDataBrowserItemNoProperty
, // preSortProperty
2415 kDataBrowserNoItem
// update all columns
2422 void wxListCtrl::SetDropTarget( wxDropTarget
*dropTarget
)
2424 #if wxUSE_DRAG_AND_DROP
2426 m_genericImpl
->SetDropTarget( dropTarget
);
2429 wxWindow::SetDropTarget( dropTarget
);
2433 wxDropTarget
*wxListCtrl::GetDropTarget() const
2435 #if wxUSE_DRAG_AND_DROP
2437 return m_genericImpl
->GetDropTarget();
2440 return wxWindow::GetDropTarget();
2445 #if wxABI_VERSION >= 20801
2446 void wxListCtrl::SetFocus()
2450 m_genericImpl
->SetFocus();
2454 wxWindow::SetFocus();
2458 // wxMac internal data structures
2460 wxMacListCtrlItem::~wxMacListCtrlItem()
2462 WX_CLEAR_HASH_MAP( wxListItemList
, m_rowItems
);
2465 void wxMacListCtrlItem::Notification(wxMacDataItemBrowserControl
*owner
,
2466 DataBrowserItemNotification message
,
2467 DataBrowserItemDataRef
WXUNUSED(itemData
) ) const
2470 wxMacDataBrowserListCtrlControl
*lb
= wxDynamicCast(owner
, wxMacDataBrowserListCtrlControl
);
2472 // we want to depend on as little as possible to make sure tear-down of controls is safe
2473 if ( message
== kDataBrowserItemRemoved
)
2478 else if ( message
== kDataBrowserItemAdded
)
2480 // we don't issue events on adding, the item is not really stored in the list yet, so we
2481 // avoid asserts by gettting out now
2485 wxListCtrl
*list
= wxDynamicCast( owner
->GetWXPeer() , wxListCtrl
);
2488 bool trigger
= false;
2490 wxListEvent
event( wxEVT_COMMAND_LIST_ITEM_SELECTED
, list
->GetId() );
2491 bool isSingle
= (list
->GetWindowStyle() & wxLC_SINGLE_SEL
) != 0;
2493 event
.SetEventObject( list
);
2494 event
.m_itemIndex
= owner
->GetLineFromItem( this ) ;
2495 event
.m_item
.m_itemId
= event
.m_itemIndex
;
2496 list
->GetItem(event
.m_item
);
2500 case kDataBrowserItemDeselected
:
2501 event
.SetEventType(wxEVT_COMMAND_LIST_ITEM_DESELECTED
);
2503 trigger
= !lb
->IsSelectionSuppressed();
2506 case kDataBrowserItemSelected
:
2507 trigger
= !lb
->IsSelectionSuppressed();
2510 case kDataBrowserItemDoubleClicked
:
2511 event
.SetEventType( wxEVT_COMMAND_LIST_ITEM_ACTIVATED
);
2515 case kDataBrowserEditStarted
:
2516 // TODO : how to veto ?
2517 event
.SetEventType( wxEVT_COMMAND_LIST_BEGIN_LABEL_EDIT
) ;
2521 case kDataBrowserEditStopped
:
2522 // TODO probably trigger only upon the value store callback, because
2523 // here IIRC we cannot veto
2524 event
.SetEventType( wxEVT_COMMAND_LIST_END_LABEL_EDIT
) ;
2534 // direct notification is not always having the listbox GetSelection() having in synch with event
2535 wxPostEvent( list
->GetEventHandler(), event
);
2541 IMPLEMENT_DYNAMIC_CLASS(wxMacDataBrowserListCtrlControl
, wxMacDataItemBrowserControl
)
2543 wxMacDataBrowserListCtrlControl::wxMacDataBrowserListCtrlControl( wxWindow
*peer
, const wxPoint
& pos
, const wxSize
& size
, long style
)
2544 : wxMacDataItemBrowserControl( peer
, pos
, size
, style
)
2546 OSStatus err
= noErr
;
2547 m_clientDataItemsType
= wxClientData_None
;
2548 m_isVirtual
= false;
2551 if ( style
& wxLC_VIRTUAL
)
2554 DataBrowserSelectionFlags options
= kDataBrowserDragSelect
;
2555 if ( style
& wxLC_SINGLE_SEL
)
2557 options
|= kDataBrowserSelectOnlyOne
;
2561 options
|= kDataBrowserCmdTogglesSelection
;
2564 err
= SetSelectionFlags( options
);
2565 verify_noerr( err
);
2567 DataBrowserCustomCallbacks callbacks
;
2568 InitializeDataBrowserCustomCallbacks( &callbacks
, kDataBrowserLatestCustomCallbacks
);
2570 if ( gDataBrowserDrawItemUPP
== NULL
)
2571 gDataBrowserDrawItemUPP
= NewDataBrowserDrawItemUPP(DataBrowserDrawItemProc
);
2573 if ( gDataBrowserHitTestUPP
== NULL
)
2574 gDataBrowserHitTestUPP
= NewDataBrowserHitTestUPP(DataBrowserHitTestProc
);
2576 callbacks
.u
.v1
.drawItemCallback
= gDataBrowserDrawItemUPP
;
2577 callbacks
.u
.v1
.hitTestCallback
= gDataBrowserHitTestUPP
;
2579 SetDataBrowserCustomCallbacks( GetControlRef(), &callbacks
);
2581 if ( style
& wxLC_LIST
)
2583 InsertColumn(0, kDataBrowserIconAndTextType
, wxEmptyString
, -1, -1);
2584 verify_noerr( AutoSizeColumns() );
2587 if ( style
& wxLC_LIST
|| style
& wxLC_NO_HEADER
)
2588 verify_noerr( SetHeaderButtonHeight( 0 ) );
2591 SetSortProperty( kMinColumnId
- 1 );
2593 SetSortProperty( kMinColumnId
);
2595 m_sortOrder
= SortOrder_None
;
2597 if ( style
& wxLC_SORT_DESCENDING
)
2599 SetSortOrder( kDataBrowserOrderDecreasing
);
2601 else if ( style
& wxLC_SORT_ASCENDING
)
2603 SetSortOrder( kDataBrowserOrderIncreasing
);
2606 if ( style
& wxLC_VRULES
)
2608 verify_noerr( DataBrowserChangeAttributes(m_controlRef
, kDataBrowserAttributeListViewDrawColumnDividers
, kDataBrowserAttributeNone
) );
2611 verify_noerr( SetHiliteStyle(kDataBrowserTableViewFillHilite
) );
2612 verify_noerr( SetHasScrollBars( (style
& wxHSCROLL
) != 0 , true ) );
2615 pascal Boolean
wxMacDataBrowserListCtrlControl::DataBrowserEditTextProc(
2617 DataBrowserItemID itemID
,
2618 DataBrowserPropertyID property
,
2619 CFStringRef theString
,
2620 Rect
*maxEditTextRect
,
2621 Boolean
*shrinkToFit
)
2623 Boolean result
= false;
2624 wxMacDataBrowserListCtrlControl
* ctl
= wxDynamicCast(wxMacControl::GetReferenceFromNativeControl( browser
), wxMacDataBrowserListCtrlControl
);
2627 result
= ctl
->ConfirmEditText(itemID
, property
, theString
, maxEditTextRect
, shrinkToFit
);
2628 theString
= CFSTR("Hello!");
2633 bool wxMacDataBrowserListCtrlControl::ConfirmEditText(
2634 DataBrowserItemID
WXUNUSED(itemID
),
2635 DataBrowserPropertyID
WXUNUSED(property
),
2636 CFStringRef
WXUNUSED(theString
),
2637 Rect
*WXUNUSED(maxEditTextRect
),
2638 Boolean
*WXUNUSED(shrinkToFit
))
2643 pascal void wxMacDataBrowserListCtrlControl::DataBrowserDrawItemProc(
2645 DataBrowserItemID itemID
,
2646 DataBrowserPropertyID property
,
2647 DataBrowserItemState itemState
,
2648 const Rect
*itemRect
,
2650 Boolean colorDevice
)
2652 wxMacDataBrowserListCtrlControl
* ctl
= wxDynamicCast(wxMacControl::GetReferenceFromNativeControl( browser
), wxMacDataBrowserListCtrlControl
);
2655 ctl
->DrawItem(itemID
, property
, itemState
, itemRect
, gdDepth
, colorDevice
);
2659 // routines needed for DrawItem
2664 kTextBoxHeight
= 14,
2665 kIconTextSpacingV
= 2,
2667 kContentHeight
= kIconHeight
+ kTextBoxHeight
+ kIconTextSpacingV
2670 static void calculateCGDrawingBounds(CGRect inItemRect
, CGRect
*outIconRect
, CGRect
*outTextRect
, bool hasIcon
= false)
2673 float iconH
, iconW
= 0;
2674 float padding
= kItemPadding
;
2677 iconH
= kIconHeight
;
2679 padding
= padding
*2;
2682 textBottom
= inItemRect
.origin
.y
;
2684 *outIconRect
= CGRectMake(inItemRect
.origin
.x
+ kItemPadding
,
2685 textBottom
+ kIconTextSpacingV
, kIconWidth
,
2688 *outTextRect
= CGRectMake(inItemRect
.origin
.x
+ padding
+ iconW
,
2689 textBottom
+ kIconTextSpacingV
, inItemRect
.size
.width
- padding
- iconW
,
2690 inItemRect
.size
.height
- kIconTextSpacingV
);
2693 void wxMacDataBrowserListCtrlControl::DrawItem(
2694 DataBrowserItemID itemID
,
2695 DataBrowserPropertyID property
,
2696 DataBrowserItemState itemState
,
2697 const Rect
*WXUNUSED(itemRect
),
2699 Boolean colorDevice
)
2702 wxFont font
= wxNullFont
;
2705 DataBrowserTableViewColumnIndex listColumn
= 0;
2706 GetColumnPosition( property
, &listColumn
);
2708 wxListCtrl
* list
= wxDynamicCast( GetWXPeer() , wxListCtrl
);
2709 wxMacListCtrlItem
* lcItem
;
2710 wxColour color
= *wxBLACK
;
2711 wxColour bgColor
= wxNullColour
;
2713 if (listColumn
>= 0)
2717 lcItem
= (wxMacListCtrlItem
*) itemID
;
2718 if (lcItem
->HasColumnInfo(listColumn
))
2720 wxListItem
* item
= lcItem
->GetColumnInfo(listColumn
);
2722 // we always use the 0 column to get font and text/background colors.
2723 if (lcItem
->HasColumnInfo(0))
2725 wxListItem
* firstItem
= lcItem
->GetColumnInfo(0);
2726 color
= firstItem
->GetTextColour();
2727 bgColor
= firstItem
->GetBackgroundColour();
2728 font
= firstItem
->GetFont();
2731 if (item
->GetMask() & wxLIST_MASK_TEXT
)
2732 text
= item
->GetText();
2733 if (item
->GetMask() & wxLIST_MASK_IMAGE
)
2734 imgIndex
= item
->GetImage();
2740 long itemNum
= (long)itemID
-1;
2741 if (itemNum
>= 0 && itemNum
< list
->GetItemCount())
2743 text
= list
->OnGetItemText( itemNum
, listColumn
);
2744 imgIndex
= list
->OnGetItemColumnImage( itemNum
, listColumn
);
2745 wxListItemAttr
* attrs
= list
->OnGetItemAttr( itemNum
);
2748 if (attrs
->HasBackgroundColour())
2749 bgColor
= attrs
->GetBackgroundColour();
2750 if (attrs
->HasTextColour())
2751 color
= attrs
->GetTextColour();
2752 if (attrs
->HasFont())
2753 font
= attrs
->GetFont();
2759 wxColour listBgColor
= list
->GetBackgroundColour();
2760 if (bgColor
== wxNullColour
)
2761 bgColor
= listBgColor
;
2764 font
= list
->GetFont();
2766 wxCFStringRef
cfString( text
, wxLocale::GetSystemEncoding() );
2769 CGRect enclosingCGRect
, iconCGRect
, textCGRect
;
2771 ThemeDrawingState savedState
= NULL
;
2772 CGContextRef context
= (CGContextRef
)list
->MacGetDrawingContext();
2773 wxMacCGContextStateSaver
top_saver_cg( context
);
2775 RGBColor labelColor
;
2777 labelColor
.green
= 0;
2778 labelColor
.blue
= 0;
2780 RGBColor backgroundColor
;
2781 backgroundColor
.red
= 255;
2782 backgroundColor
.green
= 255;
2783 backgroundColor
.blue
= 255;
2785 GetDataBrowserItemPartBounds(GetControlRef(), itemID
, property
, kDataBrowserPropertyEnclosingPart
,
2788 enclosingCGRect
= CGRectMake(enclosingRect
.left
,
2790 enclosingRect
.right
- enclosingRect
.left
,
2791 enclosingRect
.bottom
- enclosingRect
.top
);
2793 bool hasFocus
= (wxWindow::FindFocus() == list
);
2794 active
= IsControlActive(GetControlRef());
2796 // don't paint the background over the vertical rule line
2797 if ( list
->GetWindowStyleFlag() & wxLC_VRULES
)
2799 enclosingCGRect
.origin
.x
+= 1;
2800 enclosingCGRect
.size
.width
-= 1;
2802 if (itemState
== kDataBrowserItemIsSelected
)
2805 GetThemeDrawingState(&savedState
);
2807 if (active
&& hasFocus
)
2809 GetThemeBrushAsColor(kThemeBrushAlternatePrimaryHighlightColor
, 32, true, &backgroundColor
);
2810 GetThemeTextColor(kThemeTextColorWhite
, gdDepth
, colorDevice
, &labelColor
);
2814 GetThemeBrushAsColor(kThemeBrushSecondaryHighlightColor
, 32, true, &backgroundColor
);
2815 GetThemeTextColor(kThemeTextColorBlack
, gdDepth
, colorDevice
, &labelColor
);
2817 wxMacCGContextStateSaver
cg( context
);
2819 CGContextSetRGBFillColor(context
, (CGFloat
)backgroundColor
.red
/ (CGFloat
)USHRT_MAX
,
2820 (CGFloat
)backgroundColor
.green
/ (CGFloat
)USHRT_MAX
,
2821 (CGFloat
)backgroundColor
.blue
/ (CGFloat
)USHRT_MAX
, (CGFloat
) 1.0);
2822 CGContextFillRect(context
, enclosingCGRect
);
2828 color
.GetRGBColor(&labelColor
);
2829 else if (list
->GetTextColour().IsOk())
2830 list
->GetTextColour().GetRGBColor(&labelColor
);
2834 bgColor
.GetRGBColor(&backgroundColor
);
2835 CGContextSaveGState(context
);
2837 CGContextSetRGBFillColor(context
, (CGFloat
)backgroundColor
.red
/ (CGFloat
)USHRT_MAX
,
2838 (CGFloat
)backgroundColor
.green
/ (CGFloat
)USHRT_MAX
,
2839 (CGFloat
)backgroundColor
.blue
/ (CGFloat
)USHRT_MAX
, (CGFloat
) 1.0);
2840 CGContextFillRect(context
, enclosingCGRect
);
2842 CGContextRestoreGState(context
);
2846 calculateCGDrawingBounds(enclosingCGRect
, &iconCGRect
, &textCGRect
, (imgIndex
!= -1) );
2850 wxImageList
* imageList
= list
->GetImageList(wxIMAGE_LIST_SMALL
);
2851 if (imageList
&& imageList
->GetImageCount() > 0)
2853 wxBitmap bmp
= imageList
->GetBitmap(imgIndex
);
2854 IconRef icon
= bmp
.GetIconRef();
2856 wxMacCGContextStateSaver
cg( context
);
2858 CGContextTranslateCTM(context
, 0,iconCGRect
.origin
.y
+ CGRectGetMaxY(iconCGRect
));
2859 CGContextScaleCTM(context
,1.0f
,-1.0f
);
2860 PlotIconRefInContext(context
, &iconCGRect
, kAlignNone
,
2861 active
? kTransformNone
: kTransformDisabled
, NULL
,
2862 kPlotIconRefNormalFlags
, icon
);
2866 HIThemeTextHorizontalFlush hFlush
= kHIThemeTextHorizontalFlushLeft
;
2867 HIThemeTextInfo info
;
2869 #if wxOSX_USE_CORE_TEXT
2870 if ( UMAGetSystemVersion() >= 0x1050 )
2872 info
.version
= kHIThemeTextInfoVersionOne
;
2873 info
.fontID
= kThemeViewsFont
;
2876 info
.fontID
= kThemeSpecifiedFont
;
2877 info
.font
= (CTFontRef
) font
.OSXGetCTFont();
2882 #if wxOSX_USE_ATSU_TEXT
2885 info
.version
= kHIThemeTextInfoVersionZero
;
2886 info
.fontID
= kThemeViewsFont
;
2890 info
.fontID
= font
.MacGetThemeFontID();
2892 ::TextSize( (short)(font
.GetPointSize()) ) ;
2893 ::TextFace( font
.MacGetFontStyle() ) ;
2899 list
->GetColumn(listColumn
, item
);
2900 if (item
.GetMask() & wxLIST_MASK_FORMAT
)
2902 if (item
.GetAlign() == wxLIST_FORMAT_LEFT
)
2903 hFlush
= kHIThemeTextHorizontalFlushLeft
;
2904 else if (item
.GetAlign() == wxLIST_FORMAT_CENTER
)
2905 hFlush
= kHIThemeTextHorizontalFlushCenter
;
2906 else if (item
.GetAlign() == wxLIST_FORMAT_RIGHT
)
2908 hFlush
= kHIThemeTextHorizontalFlushRight
;
2909 textCGRect
.origin
.x
-= kItemPadding
; // give a little extra paddding
2913 info
.state
= active
? kThemeStateActive
: kThemeStateInactive
;
2914 info
.horizontalFlushness
= hFlush
;
2915 info
.verticalFlushness
= kHIThemeTextVerticalFlushCenter
;
2916 info
.options
= kHIThemeTextBoxOptionNone
;
2917 info
.truncationPosition
= kHIThemeTextTruncationEnd
;
2918 info
.truncationMaxLines
= 1;
2921 wxMacCGContextStateSaver
cg( context
);
2922 CGContextSetRGBFillColor (context
, (CGFloat
)labelColor
.red
/ (CGFloat
)USHRT_MAX
,
2923 (CGFloat
)labelColor
.green
/ (CGFloat
)USHRT_MAX
,
2924 (CGFloat
)labelColor
.blue
/ (CGFloat
)USHRT_MAX
, (CGFloat
) 1.0);
2926 HIThemeDrawTextBox(cfString
, &textCGRect
, &info
, context
, kHIThemeOrientationNormal
);
2930 if (savedState
!= NULL
)
2931 SetThemeDrawingState(savedState
, true);
2935 OSStatus
wxMacDataBrowserListCtrlControl::GetSetItemData(DataBrowserItemID itemID
,
2936 DataBrowserPropertyID property
,
2937 DataBrowserItemDataRef itemData
,
2938 Boolean changeValue
)
2943 DataBrowserTableViewColumnIndex listColumn
= 0;
2944 verify_noerr( GetColumnPosition( property
, &listColumn
) );
2946 OSStatus err
= errDataBrowserPropertyNotSupported
;
2947 wxListCtrl
* list
= wxDynamicCast( GetWXPeer() , wxListCtrl
);
2948 wxMacListCtrlItem
* lcItem
= NULL
;
2950 if (listColumn
>= 0)
2954 lcItem
= (wxMacListCtrlItem
*) itemID
;
2955 if (lcItem
&& lcItem
->HasColumnInfo(listColumn
)){
2956 wxListItem
* item
= lcItem
->GetColumnInfo(listColumn
);
2957 if (item
->GetMask() & wxLIST_MASK_TEXT
)
2958 text
= item
->GetText();
2959 if (item
->GetMask() & wxLIST_MASK_IMAGE
)
2960 imgIndex
= item
->GetImage();
2965 long itemNum
= (long)itemID
-1;
2966 if (itemNum
>= 0 && itemNum
< list
->GetItemCount())
2968 text
= list
->OnGetItemText( itemNum
, listColumn
);
2969 imgIndex
= list
->OnGetItemColumnImage( itemNum
, listColumn
);
2978 case kDataBrowserItemIsEditableProperty
:
2979 if ( list
&& list
->HasFlag( wxLC_EDIT_LABELS
) )
2981 verify_noerr(SetDataBrowserItemDataBooleanValue( itemData
, true ));
2986 if ( property
>= kMinColumnId
)
2988 if (!text
.IsEmpty()){
2989 wxCFStringRef
cfStr( text
, wxLocale::GetSystemEncoding() );
2990 err
= ::SetDataBrowserItemDataText( itemData
, cfStr
);
2996 if ( imgIndex
!= -1 )
2998 wxImageList
* imageList
= list
->GetImageList(wxIMAGE_LIST_SMALL
);
2999 if (imageList
&& imageList
->GetImageCount() > 0){
3000 wxBitmap bmp
= imageList
->GetBitmap(imgIndex
);
3001 IconRef icon
= bmp
.GetIconRef();
3002 ::SetDataBrowserItemDataIcon(itemData
, icon
);
3016 if ( property
>= kMinColumnId
)
3018 DataBrowserTableViewColumnIndex listColumn
= 0;
3019 verify_noerr( GetColumnPosition( property
, &listColumn
) );
3021 // TODO probably send the 'end edit' from here, as we
3022 // can then deal with the veto
3024 verify_noerr( GetDataBrowserItemDataText( itemData
, &sr
) ) ;
3025 wxCFStringRef
cfStr(sr
) ;;
3027 list
->SetItem( (long)itemData
-1 , listColumn
, cfStr
.AsString() ) ;
3031 lcItem
->SetColumnTextValue( listColumn
, cfStr
.AsString() );
3041 void wxMacDataBrowserListCtrlControl::ItemNotification(DataBrowserItemID itemID
,
3042 DataBrowserItemNotification message
,
3043 DataBrowserItemDataRef itemData
)
3045 wxMacListCtrlItem
*item
= NULL
;
3048 item
= (wxMacListCtrlItem
*) itemID
;
3051 // we want to depend on as little as possible to make sure tear-down of controls is safe
3052 if ( message
== kDataBrowserItemRemoved
)
3055 item
->Notification(this, message
, itemData
);
3058 else if ( message
== kDataBrowserItemAdded
)
3060 // we don't issue events on adding, the item is not really stored in the list yet, so we
3061 // avoid asserts by getting out now
3063 item
->Notification(this, message
, itemData
);
3067 wxListCtrl
*list
= wxDynamicCast( GetWXPeer() , wxListCtrl
);
3070 bool trigger
= false;
3072 wxListEvent
event( wxEVT_COMMAND_LIST_ITEM_SELECTED
, list
->GetId() );
3074 event
.SetEventObject( list
);
3075 if ( !list
->IsVirtual() )
3077 DataBrowserTableViewRowIndex result
= 0;
3078 verify_noerr( GetItemRow( itemID
, &result
) ) ;
3079 event
.m_itemIndex
= result
;
3083 event
.m_itemIndex
= (long)itemID
-1;
3085 event
.m_item
.m_itemId
= event
.m_itemIndex
;
3086 list
->GetItem(event
.m_item
);
3090 case kDataBrowserItemDeselected
:
3091 event
.SetEventType(wxEVT_COMMAND_LIST_ITEM_DESELECTED
);
3092 // as the generic implementation is also triggering this
3093 // event for single selection, we do the same (different than listbox)
3094 trigger
= !IsSelectionSuppressed();
3097 case kDataBrowserItemSelected
:
3098 trigger
= !IsSelectionSuppressed();
3102 case kDataBrowserItemDoubleClicked
:
3103 event
.SetEventType( wxEVT_COMMAND_LIST_ITEM_ACTIVATED
);
3107 case kDataBrowserEditStarted
:
3108 // TODO : how to veto ?
3109 event
.SetEventType( wxEVT_COMMAND_LIST_BEGIN_LABEL_EDIT
) ;
3113 case kDataBrowserEditStopped
:
3114 // TODO probably trigger only upon the value store callback, because
3115 // here IIRC we cannot veto
3116 event
.SetEventType( wxEVT_COMMAND_LIST_END_LABEL_EDIT
) ;
3126 // direct notification is not always having the listbox GetSelection() having in synch with event
3127 wxPostEvent( list
->GetEventHandler(), event
);
3132 Boolean
wxMacDataBrowserListCtrlControl::CompareItems(DataBrowserItemID itemOneID
,
3133 DataBrowserItemID itemTwoID
,
3134 DataBrowserPropertyID sortProperty
)
3137 bool retval
= false;
3139 wxString otherItemText
;
3141 long otherItemOrder
;
3143 DataBrowserTableViewColumnIndex colId
= 0;
3144 verify_noerr( GetColumnPosition( sortProperty
, &colId
) );
3146 wxListCtrl
* list
= wxDynamicCast( GetWXPeer() , wxListCtrl
);
3148 DataBrowserSortOrder sort
;
3149 verify_noerr(GetSortOrder(&sort
));
3155 wxMacListCtrlItem
* item
= (wxMacListCtrlItem
*)itemOneID
;
3156 wxMacListCtrlItem
* otherItem
= (wxMacListCtrlItem
*)itemTwoID
;
3158 itemOrder
= item
->GetOrder();
3159 otherItemOrder
= otherItem
->GetOrder();
3161 wxListCtrlCompare func
= list
->GetCompareFunc();
3167 if (item
&& item
->HasColumnInfo(0))
3168 item1
= item
->GetColumnInfo(0)->GetData();
3169 if (otherItem
&& otherItem
->HasColumnInfo(0))
3170 item2
= otherItem
->GetColumnInfo(0)->GetData();
3172 if (item1
> -1 && item2
> -1)
3174 int result
= func(item1
, item2
, list
->GetCompareFuncData());
3175 if (sort
== kDataBrowserOrderIncreasing
)
3182 // we can't use the native control's sorting abilities, so just
3184 return itemOrder
< otherItemOrder
;
3189 long itemNum
= (long)itemOneID
;
3190 long otherItemNum
= (long)itemTwoID
;
3192 // virtual listctrls don't support sorting
3193 return itemNum
< otherItemNum
;
3197 // fallback for undefined cases
3198 retval
= itemOneID
< itemTwoID
;
3204 wxMacDataBrowserListCtrlControl::~wxMacDataBrowserListCtrlControl()
3208 void wxMacDataBrowserListCtrlControl::MacSetColumnInfo( unsigned int row
, unsigned int column
, wxListItem
* item
)
3210 wxMacDataItem
* dataItem
= GetItemFromLine(row
);
3211 wxASSERT_MSG( dataItem
, wxT("could not obtain wxMacDataItem for row in MacSetColumnInfo. Is row a valid wxListCtrl row?") );
3214 wxMacListCtrlItem
* listItem
= static_cast<wxMacListCtrlItem
*>(dataItem
);
3215 bool hasInfo
= listItem
->HasColumnInfo( column
);
3216 listItem
->SetColumnInfo( column
, item
);
3217 listItem
->SetOrder(row
);
3218 UpdateState(dataItem
, item
);
3220 wxListCtrl
* list
= wxDynamicCast( GetWXPeer() , wxListCtrl
);
3222 // NB: When this call was made before a control was completely shown, it would
3223 // update the item prematurely (i.e. no text would be listed) and, on show,
3224 // only the sorted column would be refreshed, meaning only first column text labels
3225 // would be shown. Making sure not to update items until the control is visible
3226 // seems to fix this issue.
3227 if (hasInfo
&& list
->IsShown())
3229 DataBrowserTableViewColumnID id
= 0;
3230 verify_noerr( GetColumnIDFromIndex( column
, &id
) );
3231 UpdateItem( wxMacDataBrowserRootContainer
, listItem
, id
);
3236 // apply changes that need to happen immediately, rather than when the
3237 // databrowser control fires a callback.
3238 void wxMacDataBrowserListCtrlControl::UpdateState(wxMacDataItem
* dataItem
, wxListItem
* listItem
)
3240 bool isSelected
= IsItemSelected( dataItem
);
3241 bool isSelectedState
= (listItem
->GetState() == wxLIST_STATE_SELECTED
);
3243 // toggle the selection state if wxListInfo state and actual state don't match.
3244 if ( listItem
->GetMask() & wxLIST_MASK_STATE
&& isSelected
!= isSelectedState
)
3246 DataBrowserSetOption options
= kDataBrowserItemsAdd
;
3247 if (!isSelectedState
)
3248 options
= kDataBrowserItemsRemove
;
3249 SetSelectedItem(dataItem
, options
);
3251 // TODO: Set column width if item width > than current column width
3254 void wxMacDataBrowserListCtrlControl::MacGetColumnInfo( unsigned int row
, unsigned int column
, wxListItem
& item
)
3256 wxMacDataItem
* dataItem
= GetItemFromLine(row
);
3257 wxASSERT_MSG( dataItem
, wxT("could not obtain wxMacDataItem in MacGetColumnInfo. Is row a valid wxListCtrl row?") );
3258 // CS should this guard against dataItem = 0 ? , as item is not a pointer if (item) is not appropriate
3261 wxMacListCtrlItem
* listItem
= static_cast<wxMacListCtrlItem
*>(dataItem
);
3263 if (!listItem
->HasColumnInfo( column
))
3266 wxListItem
* oldItem
= listItem
->GetColumnInfo( column
);
3270 long mask
= item
.GetMask();
3272 // by default, get everything for backwards compatibility
3275 if ( mask
& wxLIST_MASK_TEXT
)
3276 item
.SetText(oldItem
->GetText());
3277 if ( mask
& wxLIST_MASK_IMAGE
)
3278 item
.SetImage(oldItem
->GetImage());
3279 if ( mask
& wxLIST_MASK_DATA
)
3280 item
.SetData(oldItem
->GetData());
3281 if ( mask
& wxLIST_MASK_STATE
)
3282 item
.SetState(oldItem
->GetState());
3283 if ( mask
& wxLIST_MASK_WIDTH
)
3284 item
.SetWidth(oldItem
->GetWidth());
3285 if ( mask
& wxLIST_MASK_FORMAT
)
3286 item
.SetAlign(oldItem
->GetAlign());
3288 item
.SetTextColour(oldItem
->GetTextColour());
3289 item
.SetBackgroundColour(oldItem
->GetBackgroundColour());
3290 item
.SetFont(oldItem
->GetFont());
3295 void wxMacDataBrowserListCtrlControl::MacInsertItem( unsigned int n
, wxListItem
* item
)
3298 wxMacDataItemBrowserControl::MacInsert(n
, new wxMacListCtrlItem() );
3299 MacSetColumnInfo(n
, 0, item
);
3302 wxMacListCtrlItem::wxMacListCtrlItem()
3304 m_rowItems
= wxListItemList();
3307 int wxMacListCtrlItem::GetColumnImageValue( unsigned int column
)
3309 if ( HasColumnInfo(column
) )
3310 return GetColumnInfo(column
)->GetImage();
3315 void wxMacListCtrlItem::SetColumnImageValue( unsigned int column
, int imageIndex
)
3317 if ( HasColumnInfo(column
) )
3318 GetColumnInfo(column
)->SetImage(imageIndex
);
3321 wxString
wxMacListCtrlItem::GetColumnTextValue( unsigned int column
)
3323 /* TODO CHECK REMOVE
3327 if ( HasColumnInfo(column
) )
3328 return GetColumnInfo(column
)->GetText();
3330 return wxEmptyString
;
3333 void wxMacListCtrlItem::SetColumnTextValue( unsigned int column
, const wxString
& text
)
3335 if ( HasColumnInfo(column
) )
3336 GetColumnInfo(column
)->SetText(text
);
3338 /* TODO CHECK REMOVE
3339 // for compatibility with superclass APIs
3345 wxListItem
* wxMacListCtrlItem::GetColumnInfo( unsigned int column
)
3347 wxASSERT_MSG( HasColumnInfo(column
), wxT("invalid column index in wxMacListCtrlItem") );
3348 return m_rowItems
[column
];
3351 bool wxMacListCtrlItem::HasColumnInfo( unsigned int column
)
3353 return !(m_rowItems
.find( column
) == m_rowItems
.end());
3356 void wxMacListCtrlItem::SetColumnInfo( unsigned int column
, wxListItem
* item
)
3359 if ( !HasColumnInfo(column
) )
3361 wxListItem
* listItem
= new wxListItem(*item
);
3362 m_rowItems
[column
] = listItem
;
3366 wxListItem
* listItem
= GetColumnInfo( column
);
3367 long mask
= item
->GetMask();
3368 if (mask
& wxLIST_MASK_TEXT
)
3369 listItem
->SetText(item
->GetText());
3370 if (mask
& wxLIST_MASK_DATA
)
3371 listItem
->SetData(item
->GetData());
3372 if (mask
& wxLIST_MASK_IMAGE
)
3373 listItem
->SetImage(item
->GetImage());
3374 if (mask
& wxLIST_MASK_STATE
)
3375 listItem
->SetState(item
->GetState());
3376 if (mask
& wxLIST_MASK_FORMAT
)
3377 listItem
->SetAlign(item
->GetAlign());
3378 if (mask
& wxLIST_MASK_WIDTH
)
3379 listItem
->SetWidth(item
->GetWidth());
3381 if ( item
->HasAttributes() )
3383 if ( listItem
->HasAttributes() )
3384 listItem
->GetAttributes()->AssignFrom(*item
->GetAttributes());
3387 listItem
->SetTextColour(item
->GetTextColour());
3388 listItem
->SetBackgroundColour(item
->GetBackgroundColour());
3389 listItem
->SetFont(item
->GetFont());
3395 int wxListCtrl::CalcColumnAutoWidth(int col
) const
3399 for ( int i
= 0; i
< GetItemCount(); i
++ )
3402 info
.SetMask(wxLIST_MASK_TEXT
| wxLIST_MASK_IMAGE
);
3404 info
.SetColumn(col
);
3407 const wxFont font
= info
.GetFont();
3411 GetTextExtent(info
.GetText(), &w
, NULL
, NULL
, NULL
, &font
);
3413 GetTextExtent(info
.GetText(), &w
, NULL
);
3415 w
+= 2 * kItemPadding
;
3417 if ( info
.GetImage() != -1 )
3420 width
= wxMax(width
, w
);
3426 #endif // wxUSE_LISTCTRL