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 void wxListCtrl::SetItemCount(long count
)
2313 wxASSERT_MSG( IsVirtual(), wxT("this is for virtual controls only") );
2317 m_genericImpl
->SetItemCount(count
);
2323 // we need to temporarily disable the new item creation notification
2324 // procedure to speed things up
2325 // FIXME: Even this doesn't seem to help much...
2327 // FIXME: Find a more efficient way to do this.
2328 m_dbImpl
->MacClear();
2330 DataBrowserCallbacks callbacks
;
2331 DataBrowserItemNotificationUPP itemUPP
;
2332 GetDataBrowserCallbacks(m_dbImpl
->GetControlRef(), &callbacks
);
2333 itemUPP
= callbacks
.u
.v1
.itemNotificationCallback
;
2334 callbacks
.u
.v1
.itemNotificationCallback
= 0;
2335 m_dbImpl
->SetCallbacks(&callbacks
);
2336 ::AddDataBrowserItems(m_dbImpl
->GetControlRef(), kDataBrowserNoItem
,
2337 count
, NULL
, kDataBrowserItemNoProperty
);
2338 callbacks
.u
.v1
.itemNotificationCallback
= itemUPP
;
2339 m_dbImpl
->SetCallbacks(&callbacks
);
2344 void wxListCtrl::RefreshItem(long item
)
2348 m_genericImpl
->RefreshItem(item
);
2354 DataBrowserItemID id
;
2358 wxMacDataItem
* thisItem
= m_dbImpl
->GetItemFromLine(item
);
2359 id
= (DataBrowserItemID
) thisItem
;
2364 m_dbImpl
->wxMacDataBrowserControl::UpdateItems
2368 kDataBrowserItemNoProperty
, // preSortProperty
2369 kDataBrowserNoItem
// update all columns
2374 void wxListCtrl::RefreshItems(long itemFrom
, long itemTo
)
2378 m_genericImpl
->RefreshItems(itemFrom
, itemTo
);
2384 const long count
= itemTo
- itemFrom
+ 1;
2385 DataBrowserItemID
*ids
= new DataBrowserItemID
[count
];
2389 for ( long i
= 0; i
< count
; i
++ )
2391 wxMacDataItem
* thisItem
= m_dbImpl
->GetItemFromLine(itemFrom
+i
);
2392 ids
[i
] = (DataBrowserItemID
) thisItem
;
2397 for ( long i
= 0; i
< count
; i
++ )
2398 ids
[i
] = itemFrom
+i
+1;
2401 m_dbImpl
->wxMacDataBrowserControl::UpdateItems
2405 kDataBrowserItemNoProperty
, // preSortProperty
2406 kDataBrowserNoItem
// update all columns
2413 void wxListCtrl::SetDropTarget( wxDropTarget
*dropTarget
)
2415 #if wxUSE_DRAG_AND_DROP
2417 m_genericImpl
->SetDropTarget( dropTarget
);
2420 wxWindow::SetDropTarget( dropTarget
);
2424 wxDropTarget
*wxListCtrl::GetDropTarget() const
2426 #if wxUSE_DRAG_AND_DROP
2428 return m_genericImpl
->GetDropTarget();
2431 return wxWindow::GetDropTarget();
2436 #if wxABI_VERSION >= 20801
2437 void wxListCtrl::SetFocus()
2441 m_genericImpl
->SetFocus();
2445 wxWindow::SetFocus();
2449 // wxMac internal data structures
2451 wxMacListCtrlItem::~wxMacListCtrlItem()
2453 WX_CLEAR_HASH_MAP( wxListItemList
, m_rowItems
);
2456 void wxMacListCtrlItem::Notification(wxMacDataItemBrowserControl
*owner
,
2457 DataBrowserItemNotification message
,
2458 DataBrowserItemDataRef
WXUNUSED(itemData
) ) const
2461 wxMacDataBrowserListCtrlControl
*lb
= wxDynamicCast(owner
, wxMacDataBrowserListCtrlControl
);
2463 // we want to depend on as little as possible to make sure tear-down of controls is safe
2464 if ( message
== kDataBrowserItemRemoved
)
2469 else if ( message
== kDataBrowserItemAdded
)
2471 // we don't issue events on adding, the item is not really stored in the list yet, so we
2472 // avoid asserts by gettting out now
2476 wxListCtrl
*list
= wxDynamicCast( owner
->GetWXPeer() , wxListCtrl
);
2479 bool trigger
= false;
2481 wxListEvent
event( wxEVT_COMMAND_LIST_ITEM_SELECTED
, list
->GetId() );
2482 bool isSingle
= (list
->GetWindowStyle() & wxLC_SINGLE_SEL
) != 0;
2484 event
.SetEventObject( list
);
2485 event
.m_itemIndex
= owner
->GetLineFromItem( this ) ;
2486 event
.m_item
.m_itemId
= event
.m_itemIndex
;
2487 list
->GetItem(event
.m_item
);
2491 case kDataBrowserItemDeselected
:
2492 event
.SetEventType(wxEVT_COMMAND_LIST_ITEM_DESELECTED
);
2494 trigger
= !lb
->IsSelectionSuppressed();
2497 case kDataBrowserItemSelected
:
2498 trigger
= !lb
->IsSelectionSuppressed();
2501 case kDataBrowserItemDoubleClicked
:
2502 event
.SetEventType( wxEVT_COMMAND_LIST_ITEM_ACTIVATED
);
2506 case kDataBrowserEditStarted
:
2507 // TODO : how to veto ?
2508 event
.SetEventType( wxEVT_COMMAND_LIST_BEGIN_LABEL_EDIT
) ;
2512 case kDataBrowserEditStopped
:
2513 // TODO probably trigger only upon the value store callback, because
2514 // here IIRC we cannot veto
2515 event
.SetEventType( wxEVT_COMMAND_LIST_END_LABEL_EDIT
) ;
2525 // direct notification is not always having the listbox GetSelection() having in synch with event
2526 wxPostEvent( list
->GetEventHandler(), event
);
2532 IMPLEMENT_DYNAMIC_CLASS(wxMacDataBrowserListCtrlControl
, wxMacDataItemBrowserControl
)
2534 wxMacDataBrowserListCtrlControl::wxMacDataBrowserListCtrlControl( wxWindow
*peer
, const wxPoint
& pos
, const wxSize
& size
, long style
)
2535 : wxMacDataItemBrowserControl( peer
, pos
, size
, style
)
2537 OSStatus err
= noErr
;
2538 m_clientDataItemsType
= wxClientData_None
;
2539 m_isVirtual
= false;
2542 if ( style
& wxLC_VIRTUAL
)
2545 DataBrowserSelectionFlags options
= kDataBrowserDragSelect
;
2546 if ( style
& wxLC_SINGLE_SEL
)
2548 options
|= kDataBrowserSelectOnlyOne
;
2552 options
|= kDataBrowserCmdTogglesSelection
;
2555 err
= SetSelectionFlags( options
);
2556 verify_noerr( err
);
2558 DataBrowserCustomCallbacks callbacks
;
2559 InitializeDataBrowserCustomCallbacks( &callbacks
, kDataBrowserLatestCustomCallbacks
);
2561 if ( gDataBrowserDrawItemUPP
== NULL
)
2562 gDataBrowserDrawItemUPP
= NewDataBrowserDrawItemUPP(DataBrowserDrawItemProc
);
2564 if ( gDataBrowserHitTestUPP
== NULL
)
2565 gDataBrowserHitTestUPP
= NewDataBrowserHitTestUPP(DataBrowserHitTestProc
);
2567 callbacks
.u
.v1
.drawItemCallback
= gDataBrowserDrawItemUPP
;
2568 callbacks
.u
.v1
.hitTestCallback
= gDataBrowserHitTestUPP
;
2570 SetDataBrowserCustomCallbacks( GetControlRef(), &callbacks
);
2572 if ( style
& wxLC_LIST
)
2574 InsertColumn(0, kDataBrowserIconAndTextType
, wxEmptyString
, -1, -1);
2575 verify_noerr( AutoSizeColumns() );
2578 if ( style
& wxLC_LIST
|| style
& wxLC_NO_HEADER
)
2579 verify_noerr( SetHeaderButtonHeight( 0 ) );
2582 SetSortProperty( kMinColumnId
- 1 );
2584 SetSortProperty( kMinColumnId
);
2586 m_sortOrder
= SortOrder_None
;
2588 if ( style
& wxLC_SORT_DESCENDING
)
2590 SetSortOrder( kDataBrowserOrderDecreasing
);
2592 else if ( style
& wxLC_SORT_ASCENDING
)
2594 SetSortOrder( kDataBrowserOrderIncreasing
);
2597 if ( style
& wxLC_VRULES
)
2599 verify_noerr( DataBrowserChangeAttributes(m_controlRef
, kDataBrowserAttributeListViewDrawColumnDividers
, kDataBrowserAttributeNone
) );
2602 verify_noerr( SetHiliteStyle(kDataBrowserTableViewFillHilite
) );
2603 verify_noerr( SetHasScrollBars( (style
& wxHSCROLL
) != 0 , true ) );
2606 pascal Boolean
wxMacDataBrowserListCtrlControl::DataBrowserEditTextProc(
2608 DataBrowserItemID itemID
,
2609 DataBrowserPropertyID property
,
2610 CFStringRef theString
,
2611 Rect
*maxEditTextRect
,
2612 Boolean
*shrinkToFit
)
2614 Boolean result
= false;
2615 wxMacDataBrowserListCtrlControl
* ctl
= wxDynamicCast(wxMacControl::GetReferenceFromNativeControl( browser
), wxMacDataBrowserListCtrlControl
);
2618 result
= ctl
->ConfirmEditText(itemID
, property
, theString
, maxEditTextRect
, shrinkToFit
);
2619 theString
= CFSTR("Hello!");
2624 bool wxMacDataBrowserListCtrlControl::ConfirmEditText(
2625 DataBrowserItemID
WXUNUSED(itemID
),
2626 DataBrowserPropertyID
WXUNUSED(property
),
2627 CFStringRef
WXUNUSED(theString
),
2628 Rect
*WXUNUSED(maxEditTextRect
),
2629 Boolean
*WXUNUSED(shrinkToFit
))
2634 pascal void wxMacDataBrowserListCtrlControl::DataBrowserDrawItemProc(
2636 DataBrowserItemID itemID
,
2637 DataBrowserPropertyID property
,
2638 DataBrowserItemState itemState
,
2639 const Rect
*itemRect
,
2641 Boolean colorDevice
)
2643 wxMacDataBrowserListCtrlControl
* ctl
= wxDynamicCast(wxMacControl::GetReferenceFromNativeControl( browser
), wxMacDataBrowserListCtrlControl
);
2646 ctl
->DrawItem(itemID
, property
, itemState
, itemRect
, gdDepth
, colorDevice
);
2650 // routines needed for DrawItem
2655 kTextBoxHeight
= 14,
2656 kIconTextSpacingV
= 2,
2658 kContentHeight
= kIconHeight
+ kTextBoxHeight
+ kIconTextSpacingV
2661 static void calculateCGDrawingBounds(CGRect inItemRect
, CGRect
*outIconRect
, CGRect
*outTextRect
, bool hasIcon
= false)
2664 float iconH
, iconW
= 0;
2665 float padding
= kItemPadding
;
2668 iconH
= kIconHeight
;
2670 padding
= padding
*2;
2673 textBottom
= inItemRect
.origin
.y
;
2675 *outIconRect
= CGRectMake(inItemRect
.origin
.x
+ kItemPadding
,
2676 textBottom
+ kIconTextSpacingV
, kIconWidth
,
2679 *outTextRect
= CGRectMake(inItemRect
.origin
.x
+ padding
+ iconW
,
2680 textBottom
+ kIconTextSpacingV
, inItemRect
.size
.width
- padding
- iconW
,
2681 inItemRect
.size
.height
- kIconTextSpacingV
);
2684 void wxMacDataBrowserListCtrlControl::DrawItem(
2685 DataBrowserItemID itemID
,
2686 DataBrowserPropertyID property
,
2687 DataBrowserItemState itemState
,
2688 const Rect
*WXUNUSED(itemRect
),
2690 Boolean colorDevice
)
2693 wxFont font
= wxNullFont
;
2696 DataBrowserTableViewColumnIndex listColumn
= 0;
2697 GetColumnPosition( property
, &listColumn
);
2699 wxListCtrl
* list
= wxDynamicCast( GetWXPeer() , wxListCtrl
);
2700 wxMacListCtrlItem
* lcItem
;
2701 wxColour color
= *wxBLACK
;
2702 wxColour bgColor
= wxNullColour
;
2704 if (listColumn
>= 0)
2708 lcItem
= (wxMacListCtrlItem
*) itemID
;
2709 if (lcItem
->HasColumnInfo(listColumn
))
2711 wxListItem
* item
= lcItem
->GetColumnInfo(listColumn
);
2713 // we always use the 0 column to get font and text/background colors.
2714 if (lcItem
->HasColumnInfo(0))
2716 wxListItem
* firstItem
= lcItem
->GetColumnInfo(0);
2717 color
= firstItem
->GetTextColour();
2718 bgColor
= firstItem
->GetBackgroundColour();
2719 font
= firstItem
->GetFont();
2722 if (item
->GetMask() & wxLIST_MASK_TEXT
)
2723 text
= item
->GetText();
2724 if (item
->GetMask() & wxLIST_MASK_IMAGE
)
2725 imgIndex
= item
->GetImage();
2731 long itemNum
= (long)itemID
-1;
2732 if (itemNum
>= 0 && itemNum
< list
->GetItemCount())
2734 text
= list
->OnGetItemText( itemNum
, listColumn
);
2735 imgIndex
= list
->OnGetItemColumnImage( itemNum
, listColumn
);
2736 wxListItemAttr
* attrs
= list
->OnGetItemAttr( itemNum
);
2739 if (attrs
->HasBackgroundColour())
2740 bgColor
= attrs
->GetBackgroundColour();
2741 if (attrs
->HasTextColour())
2742 color
= attrs
->GetTextColour();
2743 if (attrs
->HasFont())
2744 font
= attrs
->GetFont();
2750 wxColour listBgColor
= list
->GetBackgroundColour();
2751 if (bgColor
== wxNullColour
)
2752 bgColor
= listBgColor
;
2755 font
= list
->GetFont();
2757 wxCFStringRef
cfString( text
, wxLocale::GetSystemEncoding() );
2760 CGRect enclosingCGRect
, iconCGRect
, textCGRect
;
2762 ThemeDrawingState savedState
= NULL
;
2763 CGContextRef context
= (CGContextRef
)list
->MacGetDrawingContext();
2764 wxMacCGContextStateSaver
top_saver_cg( context
);
2766 RGBColor labelColor
;
2768 labelColor
.green
= 0;
2769 labelColor
.blue
= 0;
2771 RGBColor backgroundColor
;
2772 backgroundColor
.red
= 255;
2773 backgroundColor
.green
= 255;
2774 backgroundColor
.blue
= 255;
2776 GetDataBrowserItemPartBounds(GetControlRef(), itemID
, property
, kDataBrowserPropertyEnclosingPart
,
2779 enclosingCGRect
= CGRectMake(enclosingRect
.left
,
2781 enclosingRect
.right
- enclosingRect
.left
,
2782 enclosingRect
.bottom
- enclosingRect
.top
);
2784 bool hasFocus
= (wxWindow::FindFocus() == list
);
2785 active
= IsControlActive(GetControlRef());
2787 // don't paint the background over the vertical rule line
2788 if ( list
->GetWindowStyleFlag() & wxLC_VRULES
)
2790 enclosingCGRect
.origin
.x
+= 1;
2791 enclosingCGRect
.size
.width
-= 1;
2793 if (itemState
== kDataBrowserItemIsSelected
)
2796 GetThemeDrawingState(&savedState
);
2798 if (active
&& hasFocus
)
2800 GetThemeBrushAsColor(kThemeBrushAlternatePrimaryHighlightColor
, 32, true, &backgroundColor
);
2801 GetThemeTextColor(kThemeTextColorWhite
, gdDepth
, colorDevice
, &labelColor
);
2805 GetThemeBrushAsColor(kThemeBrushSecondaryHighlightColor
, 32, true, &backgroundColor
);
2806 GetThemeTextColor(kThemeTextColorBlack
, gdDepth
, colorDevice
, &labelColor
);
2808 wxMacCGContextStateSaver
cg( context
);
2810 CGContextSetRGBFillColor(context
, (CGFloat
)backgroundColor
.red
/ (CGFloat
)USHRT_MAX
,
2811 (CGFloat
)backgroundColor
.green
/ (CGFloat
)USHRT_MAX
,
2812 (CGFloat
)backgroundColor
.blue
/ (CGFloat
)USHRT_MAX
, (CGFloat
) 1.0);
2813 CGContextFillRect(context
, enclosingCGRect
);
2819 color
.GetRGBColor(&labelColor
);
2820 else if (list
->GetTextColour().IsOk())
2821 list
->GetTextColour().GetRGBColor(&labelColor
);
2825 bgColor
.GetRGBColor(&backgroundColor
);
2826 CGContextSaveGState(context
);
2828 CGContextSetRGBFillColor(context
, (CGFloat
)backgroundColor
.red
/ (CGFloat
)USHRT_MAX
,
2829 (CGFloat
)backgroundColor
.green
/ (CGFloat
)USHRT_MAX
,
2830 (CGFloat
)backgroundColor
.blue
/ (CGFloat
)USHRT_MAX
, (CGFloat
) 1.0);
2831 CGContextFillRect(context
, enclosingCGRect
);
2833 CGContextRestoreGState(context
);
2837 calculateCGDrawingBounds(enclosingCGRect
, &iconCGRect
, &textCGRect
, (imgIndex
!= -1) );
2841 wxImageList
* imageList
= list
->GetImageList(wxIMAGE_LIST_SMALL
);
2842 if (imageList
&& imageList
->GetImageCount() > 0)
2844 wxBitmap bmp
= imageList
->GetBitmap(imgIndex
);
2845 IconRef icon
= bmp
.GetIconRef();
2847 wxMacCGContextStateSaver
cg( context
);
2849 CGContextTranslateCTM(context
, 0,iconCGRect
.origin
.y
+ CGRectGetMaxY(iconCGRect
));
2850 CGContextScaleCTM(context
,1.0f
,-1.0f
);
2851 PlotIconRefInContext(context
, &iconCGRect
, kAlignNone
,
2852 active
? kTransformNone
: kTransformDisabled
, NULL
,
2853 kPlotIconRefNormalFlags
, icon
);
2857 HIThemeTextHorizontalFlush hFlush
= kHIThemeTextHorizontalFlushLeft
;
2858 HIThemeTextInfo info
;
2860 #if wxOSX_USE_CORE_TEXT
2861 if ( UMAGetSystemVersion() >= 0x1050 )
2863 info
.version
= kHIThemeTextInfoVersionOne
;
2864 info
.fontID
= kThemeViewsFont
;
2867 info
.fontID
= kThemeSpecifiedFont
;
2868 info
.font
= (CTFontRef
) font
.OSXGetCTFont();
2873 #if wxOSX_USE_ATSU_TEXT
2876 info
.version
= kHIThemeTextInfoVersionZero
;
2877 info
.fontID
= kThemeViewsFont
;
2881 info
.fontID
= font
.MacGetThemeFontID();
2883 ::TextSize( (short)(font
.GetPointSize()) ) ;
2884 ::TextFace( font
.MacGetFontStyle() ) ;
2890 list
->GetColumn(listColumn
, item
);
2891 if (item
.GetMask() & wxLIST_MASK_FORMAT
)
2893 if (item
.GetAlign() == wxLIST_FORMAT_LEFT
)
2894 hFlush
= kHIThemeTextHorizontalFlushLeft
;
2895 else if (item
.GetAlign() == wxLIST_FORMAT_CENTER
)
2896 hFlush
= kHIThemeTextHorizontalFlushCenter
;
2897 else if (item
.GetAlign() == wxLIST_FORMAT_RIGHT
)
2899 hFlush
= kHIThemeTextHorizontalFlushRight
;
2900 textCGRect
.origin
.x
-= kItemPadding
; // give a little extra paddding
2904 info
.state
= active
? kThemeStateActive
: kThemeStateInactive
;
2905 info
.horizontalFlushness
= hFlush
;
2906 info
.verticalFlushness
= kHIThemeTextVerticalFlushCenter
;
2907 info
.options
= kHIThemeTextBoxOptionNone
;
2908 info
.truncationPosition
= kHIThemeTextTruncationEnd
;
2909 info
.truncationMaxLines
= 1;
2912 wxMacCGContextStateSaver
cg( context
);
2913 CGContextSetRGBFillColor (context
, (CGFloat
)labelColor
.red
/ (CGFloat
)USHRT_MAX
,
2914 (CGFloat
)labelColor
.green
/ (CGFloat
)USHRT_MAX
,
2915 (CGFloat
)labelColor
.blue
/ (CGFloat
)USHRT_MAX
, (CGFloat
) 1.0);
2917 HIThemeDrawTextBox(cfString
, &textCGRect
, &info
, context
, kHIThemeOrientationNormal
);
2921 if (savedState
!= NULL
)
2922 SetThemeDrawingState(savedState
, true);
2926 OSStatus
wxMacDataBrowserListCtrlControl::GetSetItemData(DataBrowserItemID itemID
,
2927 DataBrowserPropertyID property
,
2928 DataBrowserItemDataRef itemData
,
2929 Boolean changeValue
)
2934 DataBrowserTableViewColumnIndex listColumn
= 0;
2935 verify_noerr( GetColumnPosition( property
, &listColumn
) );
2937 OSStatus err
= errDataBrowserPropertyNotSupported
;
2938 wxListCtrl
* list
= wxDynamicCast( GetWXPeer() , wxListCtrl
);
2939 wxMacListCtrlItem
* lcItem
= NULL
;
2941 if (listColumn
>= 0)
2945 lcItem
= (wxMacListCtrlItem
*) itemID
;
2946 if (lcItem
&& lcItem
->HasColumnInfo(listColumn
)){
2947 wxListItem
* item
= lcItem
->GetColumnInfo(listColumn
);
2948 if (item
->GetMask() & wxLIST_MASK_TEXT
)
2949 text
= item
->GetText();
2950 if (item
->GetMask() & wxLIST_MASK_IMAGE
)
2951 imgIndex
= item
->GetImage();
2956 long itemNum
= (long)itemID
-1;
2957 if (itemNum
>= 0 && itemNum
< list
->GetItemCount())
2959 text
= list
->OnGetItemText( itemNum
, listColumn
);
2960 imgIndex
= list
->OnGetItemColumnImage( itemNum
, listColumn
);
2969 case kDataBrowserItemIsEditableProperty
:
2970 if ( list
&& list
->HasFlag( wxLC_EDIT_LABELS
) )
2972 verify_noerr(SetDataBrowserItemDataBooleanValue( itemData
, true ));
2977 if ( property
>= kMinColumnId
)
2979 if (!text
.IsEmpty()){
2980 wxCFStringRef
cfStr( text
, wxLocale::GetSystemEncoding() );
2981 err
= ::SetDataBrowserItemDataText( itemData
, cfStr
);
2987 if ( imgIndex
!= -1 )
2989 wxImageList
* imageList
= list
->GetImageList(wxIMAGE_LIST_SMALL
);
2990 if (imageList
&& imageList
->GetImageCount() > 0){
2991 wxBitmap bmp
= imageList
->GetBitmap(imgIndex
);
2992 IconRef icon
= bmp
.GetIconRef();
2993 ::SetDataBrowserItemDataIcon(itemData
, icon
);
3007 if ( property
>= kMinColumnId
)
3009 DataBrowserTableViewColumnIndex listColumn
= 0;
3010 verify_noerr( GetColumnPosition( property
, &listColumn
) );
3012 // TODO probably send the 'end edit' from here, as we
3013 // can then deal with the veto
3015 verify_noerr( GetDataBrowserItemDataText( itemData
, &sr
) ) ;
3016 wxCFStringRef
cfStr(sr
) ;;
3018 list
->SetItem( (long)itemData
-1 , listColumn
, cfStr
.AsString() ) ;
3022 lcItem
->SetColumnTextValue( listColumn
, cfStr
.AsString() );
3032 void wxMacDataBrowserListCtrlControl::ItemNotification(DataBrowserItemID itemID
,
3033 DataBrowserItemNotification message
,
3034 DataBrowserItemDataRef itemData
)
3036 wxMacListCtrlItem
*item
= NULL
;
3039 item
= (wxMacListCtrlItem
*) itemID
;
3042 // we want to depend on as little as possible to make sure tear-down of controls is safe
3043 if ( message
== kDataBrowserItemRemoved
)
3046 item
->Notification(this, message
, itemData
);
3049 else if ( message
== kDataBrowserItemAdded
)
3051 // we don't issue events on adding, the item is not really stored in the list yet, so we
3052 // avoid asserts by getting out now
3054 item
->Notification(this, message
, itemData
);
3058 wxListCtrl
*list
= wxDynamicCast( GetWXPeer() , wxListCtrl
);
3061 bool trigger
= false;
3063 wxListEvent
event( wxEVT_COMMAND_LIST_ITEM_SELECTED
, list
->GetId() );
3065 event
.SetEventObject( list
);
3066 if ( !list
->IsVirtual() )
3068 DataBrowserTableViewRowIndex result
= 0;
3069 verify_noerr( GetItemRow( itemID
, &result
) ) ;
3070 event
.m_itemIndex
= result
;
3074 event
.m_itemIndex
= (long)itemID
-1;
3076 event
.m_item
.m_itemId
= event
.m_itemIndex
;
3077 list
->GetItem(event
.m_item
);
3081 case kDataBrowserItemDeselected
:
3082 event
.SetEventType(wxEVT_COMMAND_LIST_ITEM_DESELECTED
);
3083 // as the generic implementation is also triggering this
3084 // event for single selection, we do the same (different than listbox)
3085 trigger
= !IsSelectionSuppressed();
3088 case kDataBrowserItemSelected
:
3089 trigger
= !IsSelectionSuppressed();
3093 case kDataBrowserItemDoubleClicked
:
3094 event
.SetEventType( wxEVT_COMMAND_LIST_ITEM_ACTIVATED
);
3098 case kDataBrowserEditStarted
:
3099 // TODO : how to veto ?
3100 event
.SetEventType( wxEVT_COMMAND_LIST_BEGIN_LABEL_EDIT
) ;
3104 case kDataBrowserEditStopped
:
3105 // TODO probably trigger only upon the value store callback, because
3106 // here IIRC we cannot veto
3107 event
.SetEventType( wxEVT_COMMAND_LIST_END_LABEL_EDIT
) ;
3117 // direct notification is not always having the listbox GetSelection() having in synch with event
3118 wxPostEvent( list
->GetEventHandler(), event
);
3123 Boolean
wxMacDataBrowserListCtrlControl::CompareItems(DataBrowserItemID itemOneID
,
3124 DataBrowserItemID itemTwoID
,
3125 DataBrowserPropertyID sortProperty
)
3128 bool retval
= false;
3130 wxString otherItemText
;
3132 long otherItemOrder
;
3134 DataBrowserTableViewColumnIndex colId
= 0;
3135 verify_noerr( GetColumnPosition( sortProperty
, &colId
) );
3137 wxListCtrl
* list
= wxDynamicCast( GetWXPeer() , wxListCtrl
);
3139 DataBrowserSortOrder sort
;
3140 verify_noerr(GetSortOrder(&sort
));
3146 wxMacListCtrlItem
* item
= (wxMacListCtrlItem
*)itemOneID
;
3147 wxMacListCtrlItem
* otherItem
= (wxMacListCtrlItem
*)itemTwoID
;
3149 itemOrder
= item
->GetOrder();
3150 otherItemOrder
= otherItem
->GetOrder();
3152 wxListCtrlCompare func
= list
->GetCompareFunc();
3158 if (item
&& item
->HasColumnInfo(0))
3159 item1
= item
->GetColumnInfo(0)->GetData();
3160 if (otherItem
&& otherItem
->HasColumnInfo(0))
3161 item2
= otherItem
->GetColumnInfo(0)->GetData();
3163 if (item1
> -1 && item2
> -1)
3165 int result
= func(item1
, item2
, list
->GetCompareFuncData());
3166 if (sort
== kDataBrowserOrderIncreasing
)
3173 // we can't use the native control's sorting abilities, so just
3175 return itemOrder
< otherItemOrder
;
3180 long itemNum
= (long)itemOneID
;
3181 long otherItemNum
= (long)itemTwoID
;
3183 // virtual listctrls don't support sorting
3184 return itemNum
< otherItemNum
;
3188 // fallback for undefined cases
3189 retval
= itemOneID
< itemTwoID
;
3195 wxMacDataBrowserListCtrlControl::~wxMacDataBrowserListCtrlControl()
3199 void wxMacDataBrowserListCtrlControl::MacSetColumnInfo( unsigned int row
, unsigned int column
, wxListItem
* item
)
3201 wxMacDataItem
* dataItem
= GetItemFromLine(row
);
3202 wxASSERT_MSG( dataItem
, wxT("could not obtain wxMacDataItem for row in MacSetColumnInfo. Is row a valid wxListCtrl row?") );
3205 wxMacListCtrlItem
* listItem
= static_cast<wxMacListCtrlItem
*>(dataItem
);
3206 bool hasInfo
= listItem
->HasColumnInfo( column
);
3207 listItem
->SetColumnInfo( column
, item
);
3208 listItem
->SetOrder(row
);
3209 UpdateState(dataItem
, item
);
3211 wxListCtrl
* list
= wxDynamicCast( GetWXPeer() , wxListCtrl
);
3213 // NB: When this call was made before a control was completely shown, it would
3214 // update the item prematurely (i.e. no text would be listed) and, on show,
3215 // only the sorted column would be refreshed, meaning only first column text labels
3216 // would be shown. Making sure not to update items until the control is visible
3217 // seems to fix this issue.
3218 if (hasInfo
&& list
->IsShown())
3220 DataBrowserTableViewColumnID id
= 0;
3221 verify_noerr( GetColumnIDFromIndex( column
, &id
) );
3222 UpdateItem( wxMacDataBrowserRootContainer
, listItem
, id
);
3227 // apply changes that need to happen immediately, rather than when the
3228 // databrowser control fires a callback.
3229 void wxMacDataBrowserListCtrlControl::UpdateState(wxMacDataItem
* dataItem
, wxListItem
* listItem
)
3231 bool isSelected
= IsItemSelected( dataItem
);
3232 bool isSelectedState
= (listItem
->GetState() == wxLIST_STATE_SELECTED
);
3234 // toggle the selection state if wxListInfo state and actual state don't match.
3235 if ( listItem
->GetMask() & wxLIST_MASK_STATE
&& isSelected
!= isSelectedState
)
3237 DataBrowserSetOption options
= kDataBrowserItemsAdd
;
3238 if (!isSelectedState
)
3239 options
= kDataBrowserItemsRemove
;
3240 SetSelectedItem(dataItem
, options
);
3242 // TODO: Set column width if item width > than current column width
3245 void wxMacDataBrowserListCtrlControl::MacGetColumnInfo( unsigned int row
, unsigned int column
, wxListItem
& item
)
3247 wxMacDataItem
* dataItem
= GetItemFromLine(row
);
3248 wxASSERT_MSG( dataItem
, wxT("could not obtain wxMacDataItem in MacGetColumnInfo. Is row a valid wxListCtrl row?") );
3249 // CS should this guard against dataItem = 0 ? , as item is not a pointer if (item) is not appropriate
3252 wxMacListCtrlItem
* listItem
= static_cast<wxMacListCtrlItem
*>(dataItem
);
3254 if (!listItem
->HasColumnInfo( column
))
3257 wxListItem
* oldItem
= listItem
->GetColumnInfo( column
);
3261 long mask
= item
.GetMask();
3263 // by default, get everything for backwards compatibility
3266 if ( mask
& wxLIST_MASK_TEXT
)
3267 item
.SetText(oldItem
->GetText());
3268 if ( mask
& wxLIST_MASK_IMAGE
)
3269 item
.SetImage(oldItem
->GetImage());
3270 if ( mask
& wxLIST_MASK_DATA
)
3271 item
.SetData(oldItem
->GetData());
3272 if ( mask
& wxLIST_MASK_STATE
)
3273 item
.SetState(oldItem
->GetState());
3274 if ( mask
& wxLIST_MASK_WIDTH
)
3275 item
.SetWidth(oldItem
->GetWidth());
3276 if ( mask
& wxLIST_MASK_FORMAT
)
3277 item
.SetAlign(oldItem
->GetAlign());
3279 item
.SetTextColour(oldItem
->GetTextColour());
3280 item
.SetBackgroundColour(oldItem
->GetBackgroundColour());
3281 item
.SetFont(oldItem
->GetFont());
3286 void wxMacDataBrowserListCtrlControl::MacInsertItem( unsigned int n
, wxListItem
* item
)
3289 wxMacDataItemBrowserControl::MacInsert(n
, new wxMacListCtrlItem() );
3290 MacSetColumnInfo(n
, 0, item
);
3293 wxMacListCtrlItem::wxMacListCtrlItem()
3295 m_rowItems
= wxListItemList();
3298 int wxMacListCtrlItem::GetColumnImageValue( unsigned int column
)
3300 if ( HasColumnInfo(column
) )
3301 return GetColumnInfo(column
)->GetImage();
3306 void wxMacListCtrlItem::SetColumnImageValue( unsigned int column
, int imageIndex
)
3308 if ( HasColumnInfo(column
) )
3309 GetColumnInfo(column
)->SetImage(imageIndex
);
3312 wxString
wxMacListCtrlItem::GetColumnTextValue( unsigned int column
)
3314 /* TODO CHECK REMOVE
3318 if ( HasColumnInfo(column
) )
3319 return GetColumnInfo(column
)->GetText();
3321 return wxEmptyString
;
3324 void wxMacListCtrlItem::SetColumnTextValue( unsigned int column
, const wxString
& text
)
3326 if ( HasColumnInfo(column
) )
3327 GetColumnInfo(column
)->SetText(text
);
3329 /* TODO CHECK REMOVE
3330 // for compatibility with superclass APIs
3336 wxListItem
* wxMacListCtrlItem::GetColumnInfo( unsigned int column
)
3338 wxASSERT_MSG( HasColumnInfo(column
), wxT("invalid column index in wxMacListCtrlItem") );
3339 return m_rowItems
[column
];
3342 bool wxMacListCtrlItem::HasColumnInfo( unsigned int column
)
3344 return !(m_rowItems
.find( column
) == m_rowItems
.end());
3347 void wxMacListCtrlItem::SetColumnInfo( unsigned int column
, wxListItem
* item
)
3350 if ( !HasColumnInfo(column
) )
3352 wxListItem
* listItem
= new wxListItem(*item
);
3353 m_rowItems
[column
] = listItem
;
3357 wxListItem
* listItem
= GetColumnInfo( column
);
3358 long mask
= item
->GetMask();
3359 if (mask
& wxLIST_MASK_TEXT
)
3360 listItem
->SetText(item
->GetText());
3361 if (mask
& wxLIST_MASK_DATA
)
3362 listItem
->SetData(item
->GetData());
3363 if (mask
& wxLIST_MASK_IMAGE
)
3364 listItem
->SetImage(item
->GetImage());
3365 if (mask
& wxLIST_MASK_STATE
)
3366 listItem
->SetState(item
->GetState());
3367 if (mask
& wxLIST_MASK_FORMAT
)
3368 listItem
->SetAlign(item
->GetAlign());
3369 if (mask
& wxLIST_MASK_WIDTH
)
3370 listItem
->SetWidth(item
->GetWidth());
3372 if ( item
->HasAttributes() )
3374 if ( listItem
->HasAttributes() )
3375 listItem
->GetAttributes()->AssignFrom(*item
->GetAttributes());
3378 listItem
->SetTextColour(item
->GetTextColour());
3379 listItem
->SetBackgroundColour(item
->GetBackgroundColour());
3380 listItem
->SetFont(item
->GetFont());
3386 int wxListCtrl::CalcColumnAutoWidth(int col
) const
3390 for ( int i
= 0; i
< GetItemCount(); i
++ )
3393 info
.SetMask(wxLIST_MASK_TEXT
| wxLIST_MASK_IMAGE
);
3395 info
.SetColumn(col
);
3398 const wxFont font
= info
.GetFont();
3402 GetTextExtent(info
.GetText(), &w
, NULL
, NULL
, NULL
, &font
);
3404 GetTextExtent(info
.GetText(), &w
, NULL
);
3406 w
+= 2 * kItemPadding
;
3408 if ( info
.GetImage() != -1 )
3411 width
= wxMax(width
, w
);
3417 #endif // wxUSE_LISTCTRL