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 #if wxUSE_EXTENDED_RTTI
45 WX_DEFINE_FLAGS( wxListCtrlStyle
)
47 wxBEGIN_FLAGS( wxListCtrlStyle
)
48 // new style border flags, we put them first to
49 // use them for streaming out
50 wxFLAGS_MEMBER(wxBORDER_SIMPLE
)
51 wxFLAGS_MEMBER(wxBORDER_SUNKEN
)
52 wxFLAGS_MEMBER(wxBORDER_DOUBLE
)
53 wxFLAGS_MEMBER(wxBORDER_RAISED
)
54 wxFLAGS_MEMBER(wxBORDER_STATIC
)
55 wxFLAGS_MEMBER(wxBORDER_NONE
)
57 // old style border flags
58 wxFLAGS_MEMBER(wxSIMPLE_BORDER
)
59 wxFLAGS_MEMBER(wxSUNKEN_BORDER
)
60 wxFLAGS_MEMBER(wxDOUBLE_BORDER
)
61 wxFLAGS_MEMBER(wxRAISED_BORDER
)
62 wxFLAGS_MEMBER(wxSTATIC_BORDER
)
63 wxFLAGS_MEMBER(wxBORDER
)
65 // standard window styles
66 wxFLAGS_MEMBER(wxTAB_TRAVERSAL
)
67 wxFLAGS_MEMBER(wxCLIP_CHILDREN
)
68 wxFLAGS_MEMBER(wxTRANSPARENT_WINDOW
)
69 wxFLAGS_MEMBER(wxWANTS_CHARS
)
70 wxFLAGS_MEMBER(wxFULL_REPAINT_ON_RESIZE
)
71 wxFLAGS_MEMBER(wxALWAYS_SHOW_SB
)
72 wxFLAGS_MEMBER(wxVSCROLL
)
73 wxFLAGS_MEMBER(wxHSCROLL
)
75 wxFLAGS_MEMBER(wxLC_LIST
)
76 wxFLAGS_MEMBER(wxLC_REPORT
)
77 wxFLAGS_MEMBER(wxLC_ICON
)
78 wxFLAGS_MEMBER(wxLC_SMALL_ICON
)
79 wxFLAGS_MEMBER(wxLC_ALIGN_TOP
)
80 wxFLAGS_MEMBER(wxLC_ALIGN_LEFT
)
81 wxFLAGS_MEMBER(wxLC_AUTOARRANGE
)
82 wxFLAGS_MEMBER(wxLC_USER_TEXT
)
83 wxFLAGS_MEMBER(wxLC_EDIT_LABELS
)
84 wxFLAGS_MEMBER(wxLC_NO_HEADER
)
85 wxFLAGS_MEMBER(wxLC_SINGLE_SEL
)
86 wxFLAGS_MEMBER(wxLC_SORT_ASCENDING
)
87 wxFLAGS_MEMBER(wxLC_SORT_DESCENDING
)
88 wxFLAGS_MEMBER(wxLC_VIRTUAL
)
90 wxEND_FLAGS( wxListCtrlStyle
)
92 IMPLEMENT_DYNAMIC_CLASS_XTI(wxListCtrl
, wxControl
,"wx/listctrl.h")
94 wxBEGIN_PROPERTIES_TABLE(wxListCtrl
)
95 wxEVENT_PROPERTY( TextUpdated
, wxEVT_COMMAND_TEXT_UPDATED
, wxCommandEvent
)
97 wxPROPERTY_FLAGS( WindowStyle
, wxListCtrlStyle
, long , SetWindowStyleFlag
, GetWindowStyleFlag
, EMPTY_MACROVALUE
, 0 /*flags*/ , wxT("Helpstring") , wxT("group")) // style
98 wxEND_PROPERTIES_TABLE()
100 wxBEGIN_HANDLERS_TABLE(wxListCtrl
)
101 wxEND_HANDLERS_TABLE()
103 wxCONSTRUCTOR_5( wxListCtrl
, wxWindow
* , Parent
, wxWindowID
, Id
, wxPoint
, Position
, wxSize
, Size
, long , WindowStyle
)
106 TODO : Expose more information of a list's layout etc. via appropriate objects (a la NotebookPageInfo)
109 IMPLEMENT_DYNAMIC_CLASS(wxListCtrl
, wxControl
)
112 IMPLEMENT_DYNAMIC_CLASS(wxListView
, wxListCtrl
)
113 IMPLEMENT_DYNAMIC_CLASS(wxListItem
, wxObject
)
115 IMPLEMENT_DYNAMIC_CLASS(wxListEvent
, wxNotifyEvent
)
117 WX_DECLARE_HASH_MAP( int, wxListItem
*, wxIntegerHash
, wxIntegerEqual
, wxListItemList
);
119 #include "wx/listimpl.cpp"
120 WX_DEFINE_LIST(wxColumnList
)
122 // so we can check for column clicks
123 static const EventTypeSpec eventList
[] =
125 { kEventClassControl
, kEventControlHit
},
126 { kEventClassControl
, kEventControlDraw
}
129 static pascal OSStatus
wxMacListCtrlEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
131 OSStatus result
= eventNotHandledErr
;
133 wxMacCarbonEvent
cEvent( event
) ;
135 ControlRef controlRef
;
136 cEvent
.GetParameter( kEventParamDirectObject
, &controlRef
) ;
138 wxListCtrl
*window
= (wxListCtrl
*) data
;
139 wxListEvent
le( wxEVT_COMMAND_LIST_COL_CLICK
, window
->GetId() );
140 le
.SetEventObject( window
);
142 switch ( GetEventKind( event
) )
144 // check if the column was clicked on and fire an event if so
145 case kEventControlHit
:
147 ControlPartCode result
= cEvent
.GetParameter
<ControlPartCode
>(kEventParamControlPart
, typeControlPartCode
) ;
148 if (result
== kControlButtonPart
){
149 DataBrowserPropertyID col
;
150 GetDataBrowserSortProperty(controlRef
, &col
);
152 DataBrowserTableViewColumnIndex column
= 0;
153 verify_noerr( GetDataBrowserTableViewColumnPosition( controlRef
, col
, &column
) );
156 // FIXME: we can't use the sort property for virtual listctrls
157 // so we need to find a better way to determine which column was clicked...
158 if (!window
->IsVirtual())
159 window
->HandleWindowEvent( le
);
161 result
= CallNextEventHandler(handler
, event
);
164 case kEventControlDraw
:
166 CGContextRef context
= cEvent
.GetParameter
<CGContextRef
>(kEventParamCGContextRef
, typeCGContextRef
) ;
167 window
->MacSetDrawingContext(context
);
168 result
= CallNextEventHandler(handler
, event
);
169 window
->MacSetDrawingContext(NULL
);
180 DEFINE_ONE_SHOT_HANDLER_GETTER( wxMacListCtrlEventHandler
)
182 class wxMacListCtrlItem
: public wxMacDataItem
187 virtual void Notification(wxMacDataItemBrowserControl
*owner
,
188 DataBrowserItemNotification message
,
189 DataBrowserItemDataRef itemData
) const;
191 virtual void SetColumnInfo( unsigned int column
, wxListItem
* item
);
192 virtual wxListItem
* GetColumnInfo( unsigned int column
);
193 virtual bool HasColumnInfo( unsigned int column
);
195 virtual void SetColumnTextValue( unsigned int column
, const wxString
& text
);
196 virtual wxString
GetColumnTextValue( unsigned int column
);
198 virtual int GetColumnImageValue( unsigned int column
);
199 virtual void SetColumnImageValue( unsigned int column
, int imageIndex
);
201 virtual ~wxMacListCtrlItem();
203 wxListItemList m_rowItems
;
206 DataBrowserDrawItemUPP gDataBrowserDrawItemUPP
= NULL
;
207 //DataBrowserEditItemUPP gDataBrowserEditItemUPP = NULL;
208 DataBrowserHitTestUPP gDataBrowserHitTestUPP
= NULL
;
210 // TODO: Make a better name!!
211 class wxMacDataBrowserListCtrlControl
: public wxMacDataItemBrowserControl
214 wxMacDataBrowserListCtrlControl( wxWindow
*peer
, const wxPoint
& pos
, const wxSize
& size
, long style
);
215 wxMacDataBrowserListCtrlControl() {}
216 virtual ~wxMacDataBrowserListCtrlControl();
218 // create a list item (can be a subclass of wxMacListBoxItem)
220 virtual void MacInsertItem( unsigned int n
, wxListItem
* item
);
221 virtual void MacSetColumnInfo( unsigned int row
, unsigned int column
, wxListItem
* item
);
222 virtual void MacGetColumnInfo( unsigned int row
, unsigned int column
, wxListItem
& item
);
223 virtual void UpdateState(wxMacDataItem
* dataItem
, wxListItem
* item
);
224 int GetFlags() { return m_flags
; }
227 // we need to override to provide specialized handling for virtual wxListCtrls
228 virtual OSStatus
GetSetItemData(DataBrowserItemID itemID
,
229 DataBrowserPropertyID property
,
230 DataBrowserItemDataRef itemData
,
231 Boolean changeValue
);
233 virtual void ItemNotification(
234 DataBrowserItemID itemID
,
235 DataBrowserItemNotification message
,
236 DataBrowserItemDataRef itemData
);
238 virtual Boolean
CompareItems(DataBrowserItemID itemOneID
,
239 DataBrowserItemID itemTwoID
,
240 DataBrowserPropertyID sortProperty
);
242 static pascal void DataBrowserDrawItemProc(ControlRef browser
,
243 DataBrowserItemID item
,
244 DataBrowserPropertyID property
,
245 DataBrowserItemState itemState
,
248 Boolean colorDevice
);
250 virtual void DrawItem(DataBrowserItemID itemID
,
251 DataBrowserPropertyID property
,
252 DataBrowserItemState itemState
,
253 const Rect
*itemRect
,
255 Boolean colorDevice
);
257 static pascal Boolean
DataBrowserEditTextProc(ControlRef browser
,
258 DataBrowserItemID item
,
259 DataBrowserPropertyID property
,
260 CFStringRef theString
,
261 Rect
*maxEditTextRect
,
262 Boolean
*shrinkToFit
);
264 static pascal Boolean
DataBrowserHitTestProc(ControlRef
WXUNUSED(browser
),
265 DataBrowserItemID
WXUNUSED(itemID
),
266 DataBrowserPropertyID
WXUNUSED(property
),
267 const Rect
*WXUNUSED(theRect
),
268 const Rect
*WXUNUSED(mouseRect
)) { return true; }
270 virtual bool ConfirmEditText(DataBrowserItemID item
,
271 DataBrowserPropertyID property
,
272 CFStringRef theString
,
273 Rect
*maxEditTextRect
,
274 Boolean
*shrinkToFit
);
278 wxClientDataType m_clientDataItemsType
;
281 DECLARE_DYNAMIC_CLASS_NO_COPY(wxMacDataBrowserListCtrlControl
)
284 class wxMacListCtrlEventDelegate
: public wxEvtHandler
287 wxMacListCtrlEventDelegate( wxListCtrl
* list
, int id
);
288 virtual bool ProcessEvent( wxEvent
& event
);
295 wxMacListCtrlEventDelegate::wxMacListCtrlEventDelegate( wxListCtrl
* list
, int id
)
301 bool wxMacListCtrlEventDelegate::ProcessEvent( wxEvent
& event
)
303 int id
= event
.GetId();
304 wxObject
* obj
= event
.GetEventObject();
306 // even though we use a generic list ctrl underneath, make sure
307 // we present ourselves as wxListCtrl.
308 event
.SetEventObject( m_list
);
311 if ( !event
.IsKindOf( CLASSINFO( wxCommandEvent
) ) )
313 if (m_list
->GetEventHandler()->ProcessEvent( event
))
316 event
.SetEventObject(obj
);
320 // Also try with the original id
321 bool success
= wxEvtHandler::ProcessEvent(event
);
323 event
.SetEventObject(obj
);
324 if (!success
&& id
!= m_id
)
325 success
= wxEvtHandler::ProcessEvent(event
);
329 //-----------------------------------------------------------------------------
330 // wxListCtrlRenameTimer (internal)
331 //-----------------------------------------------------------------------------
333 class wxListCtrlRenameTimer
: public wxTimer
339 wxListCtrlRenameTimer( wxListCtrl
*owner
);
343 //-----------------------------------------------------------------------------
344 // wxListCtrlTextCtrlWrapper: wraps a wxTextCtrl to make it work for inline editing
345 //-----------------------------------------------------------------------------
347 class wxListCtrlTextCtrlWrapper
: public wxEvtHandler
350 // NB: text must be a valid object but not Create()d yet
351 wxListCtrlTextCtrlWrapper(wxListCtrl
*owner
,
355 wxTextCtrl
*GetText() const { return m_text
; }
357 void AcceptChangesAndFinish();
360 void OnChar( wxKeyEvent
&event
);
361 void OnKeyUp( wxKeyEvent
&event
);
362 void OnKillFocus( wxFocusEvent
&event
);
364 bool AcceptChanges();
370 wxString m_startValue
;
373 bool m_aboutToFinish
;
375 DECLARE_EVENT_TABLE()
378 //-----------------------------------------------------------------------------
379 // wxListCtrlRenameTimer (internal)
380 //-----------------------------------------------------------------------------
382 wxListCtrlRenameTimer::wxListCtrlRenameTimer( wxListCtrl
*owner
)
387 void wxListCtrlRenameTimer::Notify()
389 m_owner
->OnRenameTimer();
392 //-----------------------------------------------------------------------------
393 // wxListCtrlTextCtrlWrapper (internal)
394 //-----------------------------------------------------------------------------
396 BEGIN_EVENT_TABLE(wxListCtrlTextCtrlWrapper
, wxEvtHandler
)
397 EVT_CHAR (wxListCtrlTextCtrlWrapper::OnChar
)
398 EVT_KEY_UP (wxListCtrlTextCtrlWrapper::OnKeyUp
)
399 EVT_KILL_FOCUS (wxListCtrlTextCtrlWrapper::OnKillFocus
)
402 wxListCtrlTextCtrlWrapper::wxListCtrlTextCtrlWrapper(wxListCtrl
*owner
,
405 : m_startValue(owner
->GetItemText(itemEdit
)),
406 m_itemEdited(itemEdit
)
411 m_aboutToFinish
= false;
415 owner
->GetItemRect(itemEdit
, rectLabel
);
417 m_text
->Create(owner
, wxID_ANY
, m_startValue
,
418 wxPoint(rectLabel
.x
+offset
,rectLabel
.y
),
419 wxSize(rectLabel
.width
-offset
,rectLabel
.height
));
422 m_text
->PushEventHandler(this);
425 void wxListCtrlTextCtrlWrapper::Finish()
431 m_text
->RemoveEventHandler(this);
432 m_owner
->FinishEditing(m_text
);
434 wxPendingDelete
.Append( this );
438 bool wxListCtrlTextCtrlWrapper::AcceptChanges()
440 const wxString value
= m_text
->GetValue();
442 if ( value
== m_startValue
)
443 // nothing changed, always accept
446 if ( !m_owner
->OnRenameAccept(m_itemEdited
, value
) )
447 // vetoed by the user
450 // accepted, do rename the item
451 m_owner
->SetItemText(m_itemEdited
, value
);
456 void wxListCtrlTextCtrlWrapper::AcceptChangesAndFinish()
458 m_aboutToFinish
= true;
460 // Notify the owner about the changes
463 // Even if vetoed, close the control (consistent with MSW)
467 void wxListCtrlTextCtrlWrapper::OnChar( wxKeyEvent
&event
)
469 switch ( event
.m_keyCode
)
472 AcceptChangesAndFinish();
476 m_owner
->OnRenameCancelled( m_itemEdited
);
485 void wxListCtrlTextCtrlWrapper::OnKeyUp( wxKeyEvent
&event
)
493 // auto-grow the textctrl:
494 wxSize parentSize
= m_owner
->GetSize();
495 wxPoint myPos
= m_text
->GetPosition();
496 wxSize mySize
= m_text
->GetSize();
498 m_text
->GetTextExtent(m_text
->GetValue() + wxT("MM"), &sx
, &sy
);
499 if (myPos
.x
+ sx
> parentSize
.x
)
500 sx
= parentSize
.x
- myPos
.x
;
503 m_text
->SetSize(sx
, wxDefaultCoord
);
508 void wxListCtrlTextCtrlWrapper::OnKillFocus( wxFocusEvent
&event
)
510 if ( !m_finished
&& !m_aboutToFinish
)
512 if ( !AcceptChanges() )
513 m_owner
->OnRenameCancelled( m_itemEdited
);
518 // We must let the native text control handle focus
522 BEGIN_EVENT_TABLE(wxListCtrl
, wxControl
)
523 EVT_LEFT_DOWN(wxListCtrl::OnLeftDown
)
524 EVT_LEFT_DCLICK(wxListCtrl::OnDblClick
)
525 EVT_MIDDLE_DOWN(wxListCtrl::OnMiddleDown
)
526 EVT_RIGHT_DOWN(wxListCtrl::OnRightDown
)
527 EVT_CHAR(wxListCtrl::OnChar
)
530 // ============================================================================
532 // ============================================================================
534 wxMacDataBrowserListCtrlControl
* wxListCtrl::GetListPeer() const
536 return dynamic_cast<wxMacDataBrowserListCtrlControl
*> ( GetPeer() );
539 // ----------------------------------------------------------------------------
540 // wxListCtrl construction
541 // ----------------------------------------------------------------------------
543 void wxListCtrl::Init()
545 m_imageListNormal
= NULL
;
546 m_imageListSmall
= NULL
;
547 m_imageListState
= NULL
;
549 // keep track of if we created our own image lists, or if they were assigned
551 m_ownsImageListNormal
= m_ownsImageListSmall
= m_ownsImageListState
= false;
555 m_genericImpl
= NULL
;
557 m_compareFunc
= NULL
;
558 m_compareFuncData
= 0;
559 m_colsInfo
= wxColumnList();
560 m_textColor
= wxNullColour
;
561 m_bgColor
= wxNullColour
;
562 m_textctrlWrapper
= NULL
;
564 m_renameTimer
= new wxListCtrlRenameTimer( this );
567 class wxGenericListCtrlHook
: public wxGenericListCtrl
570 wxGenericListCtrlHook(wxListCtrl
* parent
,
575 const wxValidator
& validator
,
576 const wxString
& name
)
577 : wxGenericListCtrl(parent
, id
, pos
, size
, style
, validator
, name
),
578 m_nativeListCtrl(parent
)
583 virtual wxListItemAttr
* OnGetItemAttr(long item
) const
585 return m_nativeListCtrl
->OnGetItemAttr(item
);
588 virtual int OnGetItemImage(long item
) const
590 return m_nativeListCtrl
->OnGetItemImage(item
);
593 virtual int OnGetItemColumnImage(long item
, long column
) const
595 return m_nativeListCtrl
->OnGetItemColumnImage(item
, column
);
598 virtual wxString
OnGetItemText(long item
, long column
) const
600 return m_nativeListCtrl
->OnGetItemText(item
, column
);
603 wxListCtrl
* m_nativeListCtrl
;
607 void wxListCtrl::OnLeftDown(wxMouseEvent
& event
)
609 if ( m_textctrlWrapper
)
612 m_textctrlWrapper
->AcceptChangesAndFinish();
616 long current
= HitTest(event
.GetPosition(), hitResult
);
617 if ((current
== m_current
) &&
618 (hitResult
& wxLIST_HITTEST_ONITEMLABEL
) &&
619 HasFlag(wxLC_EDIT_LABELS
) )
621 m_renameTimer
->Start( 100, true );
630 void wxListCtrl::OnDblClick(wxMouseEvent
& event
)
632 if ( m_renameTimer
->IsRunning() )
633 m_renameTimer
->Stop();
637 #if wxABI_VERSION >= 20801
638 void wxListCtrl::OnRightDown(wxMouseEvent
& event
)
641 FireMouseEvent(wxEVT_COMMAND_LIST_ITEM_RIGHT_CLICK
, event
.GetPosition());
645 void wxListCtrl::OnMiddleDown(wxMouseEvent
& event
)
648 FireMouseEvent(wxEVT_COMMAND_LIST_ITEM_MIDDLE_CLICK
, event
.GetPosition());
652 void wxListCtrl::FireMouseEvent(wxEventType eventType
, wxPoint position
)
654 wxListEvent
le( eventType
, GetId() );
655 le
.SetEventObject(this);
656 le
.m_pointDrag
= position
;
660 long item
= HitTest(position
, flags
);
661 if (flags
& wxLIST_HITTEST_ONITEM
)
663 le
.m_itemIndex
= item
;
664 le
.m_item
.m_itemId
= item
;
666 HandleWindowEvent(le
);
670 void wxListCtrl::OnChar(wxKeyEvent
& event
)
676 wxListEvent
le( wxEVT_COMMAND_LIST_KEY_DOWN
, GetId() );
677 le
.SetEventObject(this);
678 le
.m_code
= event
.GetKeyCode();
683 // if m_current isn't set, check if there's been a selection
684 // made before continuing
685 m_current
= GetNextItem(-1, wxLIST_NEXT_BELOW
, wxLIST_STATE_SELECTED
);
688 // We need to determine m_current ourselves when navigation keys
689 // are used. Note that PAGEUP and PAGEDOWN do not alter the current
690 // item on native Mac ListCtrl, so we only handle up and down keys.
691 switch ( event
.GetKeyCode() )
702 if ( m_current
< GetItemCount() - 1 )
705 m_current
= GetItemCount() - 1;
712 le
.m_itemIndex
= m_current
;
713 le
.m_item
.m_itemId
= m_current
;
715 HandleWindowEvent(le
);
722 bool wxListCtrl::Create(wxWindow
*parent
,
727 const wxValidator
& validator
,
728 const wxString
& name
)
731 // for now, we'll always use the generic list control for ICON and LIST views,
732 // because they dynamically change the number of columns on resize.
733 // Also, allow the user to set it to use the list ctrl as well.
734 if ( (wxSystemOptions::HasOption( wxMAC_ALWAYS_USE_GENERIC_LISTCTRL
)
735 && (wxSystemOptions::GetOptionInt( wxMAC_ALWAYS_USE_GENERIC_LISTCTRL
) == 1)) ||
736 (style
& wxLC_ICON
) || (style
& wxLC_SMALL_ICON
) || (style
& wxLC_LIST
) )
738 m_macIsUserPane
= true;
740 long paneStyle
= style
;
741 paneStyle
&= ~wxSIMPLE_BORDER
;
742 paneStyle
&= ~wxDOUBLE_BORDER
;
743 paneStyle
&= ~wxSUNKEN_BORDER
;
744 paneStyle
&= ~wxRAISED_BORDER
;
745 paneStyle
&= ~wxSTATIC_BORDER
;
746 if ( !wxWindow::Create(parent
, id
, pos
, size
, paneStyle
| wxNO_BORDER
, name
) )
749 // since the generic control is a child, make sure we position it at 0, 0
750 m_genericImpl
= new wxGenericListCtrlHook(this, id
, wxPoint(0, 0), size
, style
, validator
, name
);
751 m_genericImpl
->PushEventHandler( new wxMacListCtrlEventDelegate( this, GetId() ) );
757 m_macIsUserPane
= false;
758 if ( !wxWindow::Create(parent
, id
, pos
, size
, style
& ~(wxHSCROLL
| wxVSCROLL
), name
) )
760 m_dbImpl
= new wxMacDataBrowserListCtrlControl( this, pos
, size
, style
);
763 MacPostControlCreate( pos
, size
);
765 InstallControlEventHandler( m_peer
->GetControlRef() , GetwxMacListCtrlEventHandlerUPP(),
766 GetEventTypeCount(eventList
), eventList
, this,
767 (EventHandlerRef
*)&m_macListCtrlEventHandler
);
773 wxListCtrl::~wxListCtrl()
777 m_genericImpl
->PopEventHandler(/* deleteHandler = */ true);
780 if (m_ownsImageListNormal
)
781 delete m_imageListNormal
;
782 if (m_ownsImageListSmall
)
783 delete m_imageListSmall
;
784 if (m_ownsImageListState
)
785 delete m_imageListState
;
787 delete m_renameTimer
;
789 WX_CLEAR_LIST(wxColumnList
, m_colsInfo
);
794 wxListCtrl::GetClassDefaultAttributes(wxWindowVariant
WXUNUSED(variant
))
796 wxVisualAttributes attr
;
798 attr
.colFg
= wxSystemSettings::GetColour( wxSYS_COLOUR_WINDOWTEXT
);
799 attr
.colBg
= wxSystemSettings::GetColour( wxSYS_COLOUR_LISTBOX
);
800 attr
.font
.CreateSystemFont(wxOSX_SYSTEM_FONT_VIEWS
);
805 // ----------------------------------------------------------------------------
806 // set/get/change style
807 // ----------------------------------------------------------------------------
809 // Add or remove a single window style
810 void wxListCtrl::SetSingleStyle(long style
, bool add
)
812 long flag
= GetWindowStyleFlag();
814 // Get rid of conflicting styles
817 if ( style
& wxLC_MASK_TYPE
)
818 flag
= flag
& ~wxLC_MASK_TYPE
;
819 if ( style
& wxLC_MASK_ALIGN
)
820 flag
= flag
& ~wxLC_MASK_ALIGN
;
821 if ( style
& wxLC_MASK_SORT
)
822 flag
= flag
& ~wxLC_MASK_SORT
;
830 SetWindowStyleFlag(flag
);
833 // Set the whole window style
834 void wxListCtrl::SetWindowStyleFlag(long flag
)
836 if ( flag
!= m_windowStyle
)
838 m_windowStyle
= flag
;
842 m_genericImpl
->SetWindowStyleFlag(flag
);
849 void wxListCtrl::DoSetSize( int x
, int y
, int width
, int height
, int sizeFlags
)
851 wxControl::DoSetSize(x
, y
, width
, height
, sizeFlags
);
854 m_genericImpl
->SetSize(0, 0, width
, height
, sizeFlags
);
856 // determine if we need a horizontal scrollbar, and add it if so
860 for (int column
= 0; column
< GetColumnCount(); column
++)
862 totalWidth
+= m_dbImpl
->GetColumnWidth( column
);
865 if ( !(m_dbImpl
->GetFlags() & wxHSCROLL
) )
867 Boolean vertScrollBar
;
868 GetDataBrowserHasScrollBars( m_dbImpl
->GetControlRef(), NULL
, &vertScrollBar
);
869 if (totalWidth
> width
)
870 SetDataBrowserHasScrollBars( m_dbImpl
->GetControlRef(), true, vertScrollBar
);
872 SetDataBrowserHasScrollBars( m_dbImpl
->GetControlRef(), false, vertScrollBar
);
877 wxSize
wxListCtrl::DoGetBestSize() const
879 return wxWindow::DoGetBestSize();
882 bool wxListCtrl::SetFont(const wxFont
& font
)
885 rv
= wxControl::SetFont(font
);
887 rv
= m_genericImpl
->SetFont(font
);
891 bool wxListCtrl::SetForegroundColour(const wxColour
& colour
)
895 rv
= m_genericImpl
->SetForegroundColour(colour
);
897 SetTextColour(colour
);
901 bool wxListCtrl::SetBackgroundColour(const wxColour
& colour
)
905 rv
= m_genericImpl
->SetBackgroundColour(colour
);
911 wxColour
wxListCtrl::GetBackgroundColour() const
914 return m_genericImpl
->GetBackgroundColour();
921 void wxListCtrl::Freeze ()
924 m_genericImpl
->Freeze();
928 void wxListCtrl::Thaw ()
931 m_genericImpl
->Thaw();
935 void wxListCtrl::Update ()
938 m_genericImpl
->Update();
942 // ----------------------------------------------------------------------------
944 // ----------------------------------------------------------------------------
946 // Gets information about this column
947 bool wxListCtrl::GetColumn(int col
, wxListItem
& item
) const
950 return m_genericImpl
->GetColumn(col
, item
);
956 wxColumnList::compatibility_iterator node
= m_colsInfo
.Item( col
);
957 wxASSERT_MSG( node
, wxT("invalid column index in wxMacListCtrlItem") );
958 wxListItem
* column
= node
->GetData();
960 long mask
= column
->GetMask();
961 if (mask
& wxLIST_MASK_TEXT
)
962 item
.SetText(column
->GetText());
963 if (mask
& wxLIST_MASK_DATA
)
964 item
.SetData(column
->GetData());
965 if (mask
& wxLIST_MASK_IMAGE
)
966 item
.SetImage(column
->GetImage());
967 if (mask
& wxLIST_MASK_STATE
)
968 item
.SetState(column
->GetState());
969 if (mask
& wxLIST_MASK_FORMAT
)
970 item
.SetAlign(column
->GetAlign());
971 if (mask
& wxLIST_MASK_WIDTH
)
972 item
.SetWidth(column
->GetWidth());
978 // Sets information about this column
979 bool wxListCtrl::SetColumn(int col
, wxListItem
& item
)
982 return m_genericImpl
->SetColumn(col
, item
);
986 wxASSERT_MSG( col
< (int)m_colsInfo
.GetCount(), wxT("invalid column index in wxMacListCtrlItem") );
988 long mask
= item
.GetMask();
991 GetColumn( col
, listItem
);
993 if (mask
& wxLIST_MASK_TEXT
)
994 listItem
.SetText(item
.GetText());
995 if (mask
& wxLIST_MASK_DATA
)
996 listItem
.SetData(item
.GetData());
997 if (mask
& wxLIST_MASK_IMAGE
)
998 listItem
.SetImage(item
.GetImage());
999 if (mask
& wxLIST_MASK_STATE
)
1000 listItem
.SetState(item
.GetState());
1001 if (mask
& wxLIST_MASK_FORMAT
)
1002 listItem
.SetAlign(item
.GetAlign());
1003 if (mask
& wxLIST_MASK_WIDTH
)
1004 listItem
.SetWidth(item
.GetWidth());
1007 // change the appearance in the databrowser.
1008 DataBrowserListViewHeaderDesc columnDesc
;
1009 columnDesc
.version
=kDataBrowserListViewLatestHeaderDesc
;
1011 DataBrowserTableViewColumnID id
= 0;
1012 verify_noerr( m_dbImpl
->GetColumnIDFromIndex( col
, &id
) );
1013 verify_noerr( m_dbImpl
->GetHeaderDesc( id
, &columnDesc
) );
1016 if (item.GetMask() & wxLIST_MASK_TEXT)
1020 enc = GetFont().GetEncoding();
1022 enc = wxLocale::GetSystemEncoding();
1023 wxCFStringRef cfTitle;
1024 cfTitle.Assign( item.GetText() , enc );
1025 if(columnDesc.titleString)
1026 CFRelease(columnDesc.titleString);
1027 columnDesc.titleString = cfTitle;
1031 if (item
.GetMask() & wxLIST_MASK_IMAGE
&& item
.GetImage() != -1 )
1033 wxImageList
* imageList
= GetImageList(wxIMAGE_LIST_SMALL
);
1034 if (imageList
&& imageList
->GetImageCount() > 0 )
1036 wxBitmap bmp
= imageList
->GetBitmap( item
.GetImage() );
1037 IconRef icon
= bmp
.GetIconRef();
1038 columnDesc
.btnContentInfo
.u
.iconRef
= icon
;
1039 columnDesc
.btnContentInfo
.contentType
= kControlContentIconRef
;
1043 verify_noerr( m_dbImpl
->SetHeaderDesc( id
, &columnDesc
) );
1049 int wxListCtrl::GetColumnCount() const
1052 return m_genericImpl
->GetColumnCount();
1057 m_dbImpl
->GetColumnCount(&count
);
1064 // Gets the column width
1065 int wxListCtrl::GetColumnWidth(int col
) const
1068 return m_genericImpl
->GetColumnWidth(col
);
1072 return m_dbImpl
->GetColumnWidth(col
);
1078 // Sets the column width
1079 bool wxListCtrl::SetColumnWidth(int col
, int width
)
1082 return m_genericImpl
->SetColumnWidth(col
, width
);
1086 if ( width
== wxLIST_AUTOSIZE_USEHEADER
)
1088 width
= 150; // FIXME
1093 for (int column
= 0; column
< GetColumnCount(); column
++)
1096 GetColumn(column
, colInfo
);
1098 colInfo
.SetWidth(width
);
1099 SetColumn(column
, colInfo
);
1101 const int mywidth
= (width
== wxLIST_AUTOSIZE
)
1102 ? CalcColumnAutoWidth(column
) : width
;
1103 m_dbImpl
->SetColumnWidth(column
, mywidth
);
1108 if ( width
== wxLIST_AUTOSIZE
)
1109 width
= CalcColumnAutoWidth(col
);
1112 GetColumn(col
, colInfo
);
1114 colInfo
.SetWidth(width
);
1115 SetColumn(col
, colInfo
);
1116 m_dbImpl
->SetColumnWidth(col
, width
);
1124 // Gets the number of items that can fit vertically in the
1125 // visible area of the list control (list or report view)
1126 // or the total number of items in the list control (icon
1127 // or small icon view)
1128 int wxListCtrl::GetCountPerPage() const
1131 return m_genericImpl
->GetCountPerPage();
1136 m_dbImpl
->GetDefaultRowHeight( &height
);
1138 return GetClientSize().y
/ height
;
1144 // Gets the edit control for editing labels.
1145 wxTextCtrl
* wxListCtrl::GetEditControl() const
1148 return m_genericImpl
->GetEditControl();
1153 // Gets information about the item
1154 bool wxListCtrl::GetItem(wxListItem
& info
) const
1157 return m_genericImpl
->GetItem(info
);
1163 if (info
.m_itemId
>= 0 && info
.m_itemId
< GetItemCount())
1165 m_dbImpl
->MacGetColumnInfo(info
.m_itemId
, info
.m_col
, info
);
1166 // MacGetColumnInfo returns erroneous information in the state field, so zero it.
1168 if (info
.GetMask() & wxLIST_MASK_STATE
)
1170 DataBrowserItemID id
= (DataBrowserItemID
)m_dbImpl
->GetItemFromLine(info
.m_itemId
);
1171 if (IsDataBrowserItemSelected( m_dbImpl
->GetControlRef(), id
))
1172 info
.SetState(info
.GetState() | wxLIST_STATE_SELECTED
);
1178 if (info
.m_itemId
>= 0 && info
.m_itemId
< GetItemCount())
1180 info
.SetText( OnGetItemText(info
.m_itemId
, info
.m_col
) );
1181 info
.SetImage( OnGetItemColumnImage(info
.m_itemId
, info
.m_col
) );
1182 if (info
.GetMask() & wxLIST_MASK_STATE
)
1184 if (IsDataBrowserItemSelected( m_dbImpl
->GetControlRef(), info
.m_itemId
+1 ))
1185 info
.SetState(info
.GetState() | wxLIST_STATE_SELECTED
);
1188 wxListItemAttr
* attrs
= OnGetItemAttr( info
.m_itemId
);
1191 info
.SetFont( attrs
->GetFont() );
1192 info
.SetBackgroundColour( attrs
->GetBackgroundColour() );
1193 info
.SetTextColour( attrs
->GetTextColour() );
1198 bool success
= true;
1202 // Sets information about the item
1203 bool wxListCtrl::SetItem(wxListItem
& info
)
1206 return m_genericImpl
->SetItem(info
);
1209 m_dbImpl
->MacSetColumnInfo( info
.m_itemId
, info
.m_col
, &info
);
1214 long wxListCtrl::SetItem(long index
, int col
, const wxString
& label
, int imageId
)
1217 return m_genericImpl
->SetItem(index
, col
, label
, imageId
);
1220 info
.m_text
= label
;
1221 info
.m_mask
= wxLIST_MASK_TEXT
;
1222 info
.m_itemId
= index
;
1226 info
.m_image
= imageId
;
1227 info
.m_mask
|= wxLIST_MASK_IMAGE
;
1229 return SetItem(info
);
1233 // Gets the item state
1234 int wxListCtrl::GetItemState(long item
, long stateMask
) const
1237 return m_genericImpl
->GetItemState(item
, stateMask
);
1241 if ( HasFlag(wxLC_VIRTUAL
) )
1243 if (stateMask
== wxLIST_STATE_SELECTED
)
1245 if (IsDataBrowserItemSelected( m_dbImpl
->GetControlRef(), item
+1 ))
1246 return wxLIST_STATE_SELECTED
;
1255 info
.m_mask
= wxLIST_MASK_STATE
;
1256 info
.m_stateMask
= stateMask
;
1257 info
.m_itemId
= item
;
1262 return info
.m_state
;
1269 // Sets the item state
1270 bool wxListCtrl::SetItemState(long item
, long state
, long stateMask
)
1273 return m_genericImpl
->SetItemState(item
, state
, stateMask
);
1277 DataBrowserSetOption option
= kDataBrowserItemsAdd
;
1278 if ( (stateMask
& wxLIST_STATE_SELECTED
) && state
== 0 )
1279 option
= kDataBrowserItemsRemove
;
1283 if ( HasFlag(wxLC_VIRTUAL
) )
1285 wxMacDataItemBrowserSelectionSuppressor
suppressor(m_dbImpl
);
1286 m_dbImpl
->SetSelectedAllItems(option
);
1290 for(int i
= 0; i
< GetItemCount();i
++)
1294 info
.m_mask
= wxLIST_MASK_STATE
;
1295 info
.m_stateMask
= stateMask
;
1296 info
.m_state
= state
;
1303 if ( HasFlag(wxLC_VIRTUAL
) )
1305 long itemID
= item
+1;
1306 bool isSelected
= IsDataBrowserItemSelected(m_dbImpl
->GetControlRef(), (DataBrowserItemID
)itemID
);
1307 bool isSelectedState
= (state
== wxLIST_STATE_SELECTED
);
1309 // toggle the selection state if wxListInfo state and actual state don't match.
1310 if ( (stateMask
& wxLIST_STATE_SELECTED
) && isSelected
!= isSelectedState
)
1312 SetDataBrowserSelectedItems(m_dbImpl
->GetControlRef(), 1, (DataBrowserItemID
*)&itemID
, option
);
1318 info
.m_itemId
= item
;
1319 info
.m_mask
= wxLIST_MASK_STATE
;
1320 info
.m_stateMask
= stateMask
;
1321 info
.m_state
= state
;
1322 return SetItem(info
);
1329 // Sets the item image
1330 bool wxListCtrl::SetItemImage(long item
, int image
, int WXUNUSED(selImage
))
1332 return SetItemColumnImage(item
, 0, image
);
1335 // Sets the item image
1336 bool wxListCtrl::SetItemColumnImage(long item
, long column
, int image
)
1339 return m_genericImpl
->SetItemColumnImage(item
, column
, image
);
1343 info
.m_mask
= wxLIST_MASK_IMAGE
;
1344 info
.m_image
= image
;
1345 info
.m_itemId
= item
;
1346 info
.m_col
= column
;
1348 return SetItem(info
);
1351 // Gets the item text
1352 wxString
wxListCtrl::GetItemText(long item
) const
1355 return m_genericImpl
->GetItemText(item
);
1359 info
.m_mask
= wxLIST_MASK_TEXT
;
1360 info
.m_itemId
= item
;
1363 return wxEmptyString
;
1367 // Sets the item text
1368 void wxListCtrl::SetItemText(long item
, const wxString
& str
)
1371 return m_genericImpl
->SetItemText(item
, str
);
1375 info
.m_mask
= wxLIST_MASK_TEXT
;
1376 info
.m_itemId
= item
;
1382 // Gets the item data
1383 long wxListCtrl::GetItemData(long item
) const
1386 return m_genericImpl
->GetItemData(item
);
1390 info
.m_mask
= wxLIST_MASK_DATA
;
1391 info
.m_itemId
= item
;
1398 // Sets the item data
1399 bool wxListCtrl::SetItemPtrData(long item
, wxUIntPtr data
)
1402 return m_genericImpl
->SetItemData(item
, data
);
1406 info
.m_mask
= wxLIST_MASK_DATA
;
1407 info
.m_itemId
= item
;
1410 return SetItem(info
);
1413 wxRect
wxListCtrl::GetViewRect() const
1415 wxASSERT_MSG( !HasFlag(wxLC_REPORT
| wxLC_LIST
),
1416 wxT("wxListCtrl::GetViewRect() only works in icon mode") );
1419 return m_genericImpl
->GetViewRect();
1425 bool wxListCtrl::GetSubItemRect( long item
, long subItem
, wxRect
& rect
, int code
) const
1428 return m_genericImpl
->GetSubItemRect(item
, subItem
, rect
, code
);
1430 // TODO: implement for DataBrowser implementation
1434 // Gets the item rectangle
1435 bool wxListCtrl::GetItemRect(long item
, wxRect
& rect
, int code
) const
1438 return m_genericImpl
->GetItemRect(item
, rect
, code
);
1443 DataBrowserItemID id
;
1445 DataBrowserTableViewColumnID col
= 0;
1446 verify_noerr( m_dbImpl
->GetColumnIDFromIndex( 0, &col
) );
1449 DataBrowserPropertyPart part
= kDataBrowserPropertyEnclosingPart
;
1450 if ( code
== wxLIST_RECT_LABEL
)
1451 part
= kDataBrowserPropertyTextPart
;
1452 else if ( code
== wxLIST_RECT_ICON
)
1453 part
= kDataBrowserPropertyIconPart
;
1455 if ( !(GetWindowStyleFlag() & wxLC_VIRTUAL
) )
1457 wxMacDataItem
* thisItem
= m_dbImpl
->GetItemFromLine(item
);
1458 id
= (DataBrowserItemID
) thisItem
;
1463 GetDataBrowserItemPartBounds( m_dbImpl
->GetControlRef(), id
, col
, part
, &bounds
);
1465 rect
.x
= bounds
.left
;
1466 rect
.y
= bounds
.top
;
1467 rect
.width
= bounds
.right
- bounds
.left
; //GetClientSize().x; // we need the width of the whole row, not just the item.
1468 rect
.height
= bounds
.bottom
- bounds
.top
;
1469 //fprintf("id = %d, bounds = %d, %d, %d, %d\n", id, rect.x, rect.y, rect.width, rect.height);
1474 // Gets the item position
1475 bool wxListCtrl::GetItemPosition(long item
, wxPoint
& pos
) const
1478 return m_genericImpl
->GetItemPosition(item
, pos
);
1480 bool success
= false;
1485 GetItemRect(item
, itemRect
);
1486 pos
= itemRect
.GetPosition();
1493 // Sets the item position.
1494 bool wxListCtrl::SetItemPosition(long item
, const wxPoint
& pos
)
1497 return m_genericImpl
->SetItemPosition(item
, pos
);
1502 // Gets the number of items in the list control
1503 int wxListCtrl::GetItemCount() const
1506 return m_genericImpl
->GetItemCount();
1509 return m_dbImpl
->MacGetCount();
1514 void wxListCtrl::SetItemSpacing( int spacing
, bool isSmall
)
1517 m_genericImpl
->SetItemSpacing(spacing
, isSmall
);
1520 wxSize
wxListCtrl::GetItemSpacing() const
1523 return m_genericImpl
->GetItemSpacing();
1525 return wxSize(0, 0);
1528 void wxListCtrl::SetItemTextColour( long item
, const wxColour
&col
)
1532 m_genericImpl
->SetItemTextColour(item
, col
);
1537 info
.m_itemId
= item
;
1538 info
.SetTextColour( col
);
1542 wxColour
wxListCtrl::GetItemTextColour( long item
) const
1545 return m_genericImpl
->GetItemTextColour(item
);
1551 return info
.GetTextColour();
1553 return wxNullColour
;
1556 void wxListCtrl::SetItemBackgroundColour( long item
, const wxColour
&col
)
1560 m_genericImpl
->SetItemBackgroundColour(item
, col
);
1565 info
.m_itemId
= item
;
1566 info
.SetBackgroundColour( col
);
1570 wxColour
wxListCtrl::GetItemBackgroundColour( long item
) const
1573 return m_genericImpl
->GetItemBackgroundColour(item
);
1579 return info
.GetBackgroundColour();
1581 return wxNullColour
;
1584 void wxListCtrl::SetItemFont( long item
, const wxFont
&f
)
1588 m_genericImpl
->SetItemFont(item
, f
);
1593 info
.m_itemId
= item
;
1598 wxFont
wxListCtrl::GetItemFont( long item
) const
1601 return m_genericImpl
->GetItemFont(item
);
1607 return info
.GetFont();
1613 // Gets the number of selected items in the list control
1614 int wxListCtrl::GetSelectedItemCount() const
1617 return m_genericImpl
->GetSelectedItemCount();
1620 return m_dbImpl
->GetSelectedItemCount(NULL
, true);
1625 // Gets the text colour of the listview
1626 wxColour
wxListCtrl::GetTextColour() const
1629 return m_genericImpl
->GetTextColour();
1631 // TODO: we need owner drawn list items to customize text color.
1635 return wxNullColour
;
1638 // Sets the text colour of the listview
1639 void wxListCtrl::SetTextColour(const wxColour
& col
)
1643 m_genericImpl
->SetTextColour(col
);
1651 // Gets the index of the topmost visible item when in
1652 // list or report view
1653 long wxListCtrl::GetTopItem() const
1656 return m_genericImpl
->GetTopItem();
1661 long item
= HitTest( wxPoint(1, 1), flags
);
1662 if (flags
== wxLIST_HITTEST_ONITEM
)
1669 // Searches for an item, starting from 'item'.
1670 // 'geometry' is one of
1671 // wxLIST_NEXT_ABOVE/ALL/BELOW/LEFT/RIGHT.
1672 // 'state' is a state bit flag, one or more of
1673 // wxLIST_STATE_DROPHILITED/FOCUSED/SELECTED/CUT.
1674 // item can be -1 to find the first item that matches the
1676 // Returns the item or -1 if unsuccessful.
1677 long wxListCtrl::GetNextItem(long item
, int geom
, int state
) const
1680 return m_genericImpl
->GetNextItem(item
, geom
, state
);
1682 // TODO: implement all geometry and state options?
1685 if ( geom
== wxLIST_NEXT_ALL
|| geom
== wxLIST_NEXT_BELOW
)
1687 long count
= m_dbImpl
->MacGetCount() ;
1688 for ( long line
= item
+ 1 ; line
< count
; line
++ )
1690 DataBrowserItemID id
= line
+ 1;
1692 id
= (DataBrowserItemID
)m_dbImpl
->GetItemFromLine(line
);
1694 if ( (state
& wxLIST_STATE_FOCUSED
) && (m_current
== line
))
1697 if ( (state
== wxLIST_STATE_DONTCARE
) )
1700 if ( (state
& wxLIST_STATE_SELECTED
) && IsDataBrowserItemSelected(m_dbImpl
->GetControlRef(), id
) )
1705 if ( geom
== wxLIST_NEXT_ABOVE
)
1709 item2
= m_dbImpl
->MacGetCount();
1711 for ( long line
= item2
- 1 ; line
>= 0; line
-- )
1713 DataBrowserItemID id
= line
+ 1;
1715 id
= (DataBrowserItemID
)m_dbImpl
->GetItemFromLine(line
);
1717 if ( (state
& wxLIST_STATE_FOCUSED
) && (m_current
== line
))
1720 if ( (state
== wxLIST_STATE_DONTCARE
) )
1723 if ( (state
& wxLIST_STATE_SELECTED
) && IsDataBrowserItemSelected(m_dbImpl
->GetControlRef(), id
) )
1733 wxImageList
*wxListCtrl::GetImageList(int which
) const
1736 return m_genericImpl
->GetImageList(which
);
1738 if ( which
== wxIMAGE_LIST_NORMAL
)
1740 return m_imageListNormal
;
1742 else if ( which
== wxIMAGE_LIST_SMALL
)
1744 return m_imageListSmall
;
1746 else if ( which
== wxIMAGE_LIST_STATE
)
1748 return m_imageListState
;
1753 void wxListCtrl::SetImageList(wxImageList
*imageList
, int which
)
1757 m_genericImpl
->SetImageList(imageList
, which
);
1761 if ( which
== wxIMAGE_LIST_NORMAL
)
1763 if (m_ownsImageListNormal
) delete m_imageListNormal
;
1764 m_imageListNormal
= imageList
;
1765 m_ownsImageListNormal
= false;
1767 else if ( which
== wxIMAGE_LIST_SMALL
)
1769 if (m_ownsImageListSmall
) delete m_imageListSmall
;
1770 m_imageListSmall
= imageList
;
1771 m_ownsImageListSmall
= false;
1773 else if ( which
== wxIMAGE_LIST_STATE
)
1775 if (m_ownsImageListState
) delete m_imageListState
;
1776 m_imageListState
= imageList
;
1777 m_ownsImageListState
= false;
1781 void wxListCtrl::AssignImageList(wxImageList
*imageList
, int which
)
1785 m_genericImpl
->AssignImageList(imageList
, which
);
1789 SetImageList(imageList
, which
);
1790 if ( which
== wxIMAGE_LIST_NORMAL
)
1791 m_ownsImageListNormal
= true;
1792 else if ( which
== wxIMAGE_LIST_SMALL
)
1793 m_ownsImageListSmall
= true;
1794 else if ( which
== wxIMAGE_LIST_STATE
)
1795 m_ownsImageListState
= true;
1798 // ----------------------------------------------------------------------------
1800 // ----------------------------------------------------------------------------
1802 // Arranges the items
1803 bool wxListCtrl::Arrange(int flag
)
1806 return m_genericImpl
->Arrange(flag
);
1811 bool wxListCtrl::DeleteItem(long item
)
1814 return m_genericImpl
->DeleteItem(item
);
1818 m_dbImpl
->MacDelete(item
);
1819 wxListEvent
event( wxEVT_COMMAND_LIST_DELETE_ITEM
, GetId() );
1820 event
.SetEventObject( this );
1821 event
.m_itemIndex
= item
;
1822 HandleWindowEvent( event
);
1828 // Deletes all items
1829 bool wxListCtrl::DeleteAllItems()
1833 return m_genericImpl
->DeleteAllItems();
1837 m_dbImpl
->MacClear();
1838 wxListEvent
event( wxEVT_COMMAND_LIST_DELETE_ALL_ITEMS
, GetId() );
1839 event
.SetEventObject( this );
1840 HandleWindowEvent( event
);
1845 // Deletes all items
1846 bool wxListCtrl::DeleteAllColumns()
1849 return m_genericImpl
->DeleteAllColumns();
1854 m_dbImpl
->GetColumnCount(&cols
);
1855 for (UInt32 col
= 0; col
< cols
; col
++)
1865 bool wxListCtrl::DeleteColumn(int col
)
1868 return m_genericImpl
->DeleteColumn(col
);
1872 OSStatus err
= m_dbImpl
->RemoveColumn(col
);
1873 return err
== noErr
;
1879 // Clears items, and columns if there are any.
1880 void wxListCtrl::ClearAll()
1884 m_genericImpl
->ClearAll();
1895 wxTextCtrl
* wxListCtrl::EditLabel(long item
, wxClassInfo
* textControlClass
)
1898 return m_genericImpl
->EditLabel(item
, textControlClass
);
1902 wxCHECK_MSG( (item
>= 0) && ((long)item
< GetItemCount()), NULL
,
1903 wxT("wrong index in wxListCtrl::EditLabel()") );
1905 wxASSERT_MSG( textControlClass
->IsKindOf(CLASSINFO(wxTextCtrl
)),
1906 wxT("EditLabel() needs a text control") );
1908 wxListEvent
le( wxEVT_COMMAND_LIST_BEGIN_LABEL_EDIT
, GetParent()->GetId() );
1909 le
.SetEventObject( this );
1910 le
.m_itemIndex
= item
;
1912 GetItem( le
.m_item
);
1914 if ( GetParent()->HandleWindowEvent( le
) && !le
.IsAllowed() )
1916 // vetoed by user code
1920 wxTextCtrl
* const text
= (wxTextCtrl
*)textControlClass
->CreateObject();
1921 m_textctrlWrapper
= new wxListCtrlTextCtrlWrapper(this, text
, item
);
1922 return m_textctrlWrapper
->GetText();
1927 // End label editing, optionally cancelling the edit
1928 bool wxListCtrl::EndEditLabel(bool WXUNUSED(cancel
))
1930 // TODO: generic impl. doesn't have this method - is it needed for us?
1932 return true; // m_genericImpl->EndEditLabel(cancel);
1936 DataBrowserTableViewColumnID id
= 0;
1937 verify_noerr( m_dbImpl
->GetColumnIDFromIndex( 0, &id
) );
1938 verify_noerr( SetDataBrowserEditItem(m_dbImpl
->GetControlRef(), kDataBrowserNoItem
, id
) );
1943 // Ensures this item is visible
1944 bool wxListCtrl::EnsureVisible(long item
)
1947 return m_genericImpl
->EnsureVisible(item
);
1951 wxMacDataItem
* dataItem
= m_dbImpl
->GetItemFromLine(item
);
1952 m_dbImpl
->RevealItem(dataItem
, kDataBrowserRevealWithoutSelecting
);
1958 // Find an item whose label matches this string, starting from the item after 'start'
1959 // or the beginning if 'start' is -1.
1960 long wxListCtrl::FindItem(long start
, const wxString
& str
, bool partial
)
1963 return m_genericImpl
->FindItem(start
, str
, partial
);
1965 wxString str_upper
= str
.Upper();
1970 long count
= GetItemCount();
1974 wxString line_upper
= GetItemText(idx
).Upper();
1977 if (line_upper
== str_upper
)
1982 if (line_upper
.find(str_upper
) == 0)
1992 // Find an item whose data matches this data, starting from the item after 'start'
1993 // or the beginning if 'start' is -1.
1994 long wxListCtrl::FindItem(long start
, long data
)
1997 return m_genericImpl
->FindItem(start
, data
);
2002 long count
= GetItemCount();
2006 if (GetItemData(idx
) == data
)
2014 // Find an item nearest this position in the specified direction, starting from
2015 // the item after 'start' or the beginning if 'start' is -1.
2016 long wxListCtrl::FindItem(long start
, const wxPoint
& pt
, int direction
)
2019 return m_genericImpl
->FindItem(start
, pt
, direction
);
2023 static void calculateCGDrawingBounds(CGRect inItemRect
, CGRect
*outIconRect
, CGRect
*outTextRect
, bool hasIcon
);
2025 // Determines which item (if any) is at the specified point,
2026 // giving details in 'flags' (see wxLIST_HITTEST_... flags above)
2028 wxListCtrl::HitTest(const wxPoint
& point
, int& flags
, long *ptrSubItem
) const
2034 return m_genericImpl
->HitTest(point
, flags
, ptrSubItem
);
2036 flags
= wxLIST_HITTEST_NOWHERE
;
2039 int colHeaderHeight
= 22; // TODO: Find a way to get this value from the db control?
2040 UInt16 rowHeight
= 0;
2041 m_dbImpl
->GetDefaultRowHeight(&rowHeight
);
2044 // get the actual row by taking scroll position into account
2045 UInt32 offsetX
, offsetY
;
2046 m_dbImpl
->GetScrollPosition( &offsetY
, &offsetX
);
2049 if ( !(GetWindowStyleFlag() & wxLC_NO_HEADER
) )
2050 y
-= colHeaderHeight
;
2055 int row
= y
/ rowHeight
;
2056 DataBrowserItemID id
;
2057 m_dbImpl
->GetItemID( (DataBrowserTableViewRowIndex
) row
, &id
);
2059 CGPoint click_point
= CGPointMake( point
.x
, point
.y
);
2060 if (row
< GetItemCount() )
2063 for( column
= 0; column
< GetColumnCount(); column
++ )
2066 CGRect enclosingCGRect
, iconCGRect
, textCGRect
;
2068 wxMacListCtrlItem
* lcItem
;
2070 WXUNUSED_UNLESS_DEBUG( OSStatus status
= ) m_dbImpl
->GetItemPartBounds( id
, kMinColumnId
+ column
, kDataBrowserPropertyEnclosingPart
, &enclosingRect
);
2071 wxASSERT( status
== noErr
);
2073 enclosingCGRect
= CGRectMake(enclosingRect
.left
,
2075 enclosingRect
.right
- enclosingRect
.left
,
2076 enclosingRect
.bottom
- enclosingRect
.top
);
2080 if ( !(GetWindowStyleFlag() & wxLC_VIRTUAL
) )
2082 lcItem
= (wxMacListCtrlItem
*) id
;
2083 if (lcItem
->HasColumnInfo(column
))
2085 wxListItem
* item
= lcItem
->GetColumnInfo(column
);
2087 if (item
->GetMask() & wxLIST_MASK_IMAGE
)
2089 imgIndex
= item
->GetImage();
2095 long itemNum
= (long)id
-1;
2096 if (itemNum
>= 0 && itemNum
< GetItemCount())
2098 imgIndex
= OnGetItemColumnImage( itemNum
, column
);
2103 calculateCGDrawingBounds(enclosingCGRect
, &iconCGRect
, &textCGRect
, (imgIndex
!= -1) );
2105 if ( CGRectContainsPoint( iconCGRect
, click_point
) )
2107 flags
= wxLIST_HITTEST_ONITEMICON
;
2109 *ptrSubItem
= column
;
2112 else if ( CGRectContainsPoint( textCGRect
, click_point
) )
2114 flags
= wxLIST_HITTEST_ONITEMLABEL
;
2116 *ptrSubItem
= column
;
2121 if ( !(GetWindowStyleFlag() & wxLC_VIRTUAL
) )
2123 wxMacListCtrlItem
* lcItem
;
2124 lcItem
= (wxMacListCtrlItem
*) id
;
2127 flags
= wxLIST_HITTEST_ONITEM
;
2129 *ptrSubItem
= column
;
2135 flags
= wxLIST_HITTEST_ONITEM
;
2137 *ptrSubItem
= column
;
2143 if ( wxControl::HitTest( point
) )
2144 flags
= wxLIST_HITTEST_NOWHERE
;
2151 int wxListCtrl::GetScrollPos(int orient
) const
2154 return m_genericImpl
->GetScrollPos(orient
);
2158 UInt32 offsetX
, offsetY
;
2159 m_dbImpl
->GetScrollPosition( &offsetY
, &offsetX
);
2160 if ( orient
== wxHORIZONTAL
)
2169 // Inserts an item, returning the index of the new item if successful,
2171 long wxListCtrl::InsertItem(wxListItem
& info
)
2173 wxASSERT_MSG( !IsVirtual(), wxT("can't be used with virtual controls") );
2176 return m_genericImpl
->InsertItem(info
);
2178 if (m_dbImpl
&& !IsVirtual())
2180 int count
= GetItemCount();
2182 if (info
.m_itemId
> count
)
2183 info
.m_itemId
= count
;
2185 m_dbImpl
->MacInsertItem(info
.m_itemId
, &info
);
2187 wxListEvent
event( wxEVT_COMMAND_LIST_INSERT_ITEM
, GetId() );
2188 event
.SetEventObject( this );
2189 event
.m_itemIndex
= info
.m_itemId
;
2190 HandleWindowEvent( event
);
2191 return info
.m_itemId
;
2196 long wxListCtrl::InsertItem(long index
, const wxString
& label
)
2199 return m_genericImpl
->InsertItem(index
, label
);
2202 info
.m_text
= label
;
2203 info
.m_mask
= wxLIST_MASK_TEXT
;
2204 info
.m_itemId
= index
;
2205 return InsertItem(info
);
2208 // Inserts an image item
2209 long wxListCtrl::InsertItem(long index
, int imageIndex
)
2212 return m_genericImpl
->InsertItem(index
, imageIndex
);
2215 info
.m_image
= imageIndex
;
2216 info
.m_mask
= wxLIST_MASK_IMAGE
;
2217 info
.m_itemId
= index
;
2218 return InsertItem(info
);
2221 // Inserts an image/string item
2222 long wxListCtrl::InsertItem(long index
, const wxString
& label
, int imageIndex
)
2225 return m_genericImpl
->InsertItem(index
, label
, imageIndex
);
2228 info
.m_image
= imageIndex
;
2229 info
.m_text
= label
;
2230 info
.m_mask
= wxLIST_MASK_IMAGE
| wxLIST_MASK_TEXT
;
2231 info
.m_itemId
= index
;
2232 return InsertItem(info
);
2235 // For list view mode (only), inserts a column.
2236 long wxListCtrl::InsertColumn(long col
, wxListItem
& item
)
2239 return m_genericImpl
->InsertColumn(col
, item
);
2243 int width
= item
.GetWidth();
2244 if ( !(item
.GetMask() & wxLIST_MASK_WIDTH
) )
2247 DataBrowserPropertyType type
= kDataBrowserCustomType
; //kDataBrowserTextType;
2248 wxImageList
* imageList
= GetImageList(wxIMAGE_LIST_SMALL
);
2249 if (imageList
&& imageList
->GetImageCount() > 0)
2251 wxBitmap bmp
= imageList
->GetBitmap(0);
2253 // type = kDataBrowserIconAndTextType;
2256 SInt16 just
= teFlushDefault
;
2257 if (item
.GetMask() & wxLIST_MASK_FORMAT
)
2259 if (item
.GetAlign() == wxLIST_FORMAT_LEFT
)
2261 else if (item
.GetAlign() == wxLIST_FORMAT_CENTER
)
2263 else if (item
.GetAlign() == wxLIST_FORMAT_RIGHT
)
2264 just
= teFlushRight
;
2266 m_dbImpl
->InsertColumn(col
, type
, item
.GetText(), just
, width
);
2268 wxListItem
* listItem
= new wxListItem(item
);
2269 m_colsInfo
.Insert( col
, listItem
);
2270 SetColumn(col
, item
);
2272 // set/remove options based on the wxListCtrl type.
2273 DataBrowserTableViewColumnID id
;
2274 m_dbImpl
->GetColumnIDFromIndex(col
, &id
);
2275 DataBrowserPropertyFlags flags
;
2276 verify_noerr(m_dbImpl
->GetPropertyFlags(id
, &flags
));
2277 if (GetWindowStyleFlag() & wxLC_EDIT_LABELS
)
2278 flags
|= kDataBrowserPropertyIsEditable
;
2280 if (GetWindowStyleFlag() & wxLC_VIRTUAL
){
2281 flags
&= ~kDataBrowserListViewSortableColumn
;
2283 verify_noerr(m_dbImpl
->SetPropertyFlags(id
, flags
));
2289 long wxListCtrl::InsertColumn(long col
,
2290 const wxString
& heading
,
2295 return m_genericImpl
->InsertColumn(col
, heading
, format
, width
);
2298 item
.m_mask
= wxLIST_MASK_TEXT
| wxLIST_MASK_FORMAT
;
2299 item
.m_text
= heading
;
2302 item
.m_mask
|= wxLIST_MASK_WIDTH
;
2303 item
.m_width
= width
;
2305 item
.m_format
= format
;
2307 return InsertColumn(col
, item
);
2310 // scroll the control by the given number of pixels (exception: in list view,
2311 // dx is interpreted as number of columns)
2312 bool wxListCtrl::ScrollList(int dx
, int dy
)
2315 return m_genericImpl
->ScrollList(dx
, dy
);
2319 m_dbImpl
->SetScrollPosition(dx
, dy
);
2325 bool wxListCtrl::SortItems(wxListCtrlCompare fn
, wxIntPtr data
)
2328 return m_genericImpl
->SortItems(fn
, data
);
2333 m_compareFuncData
= data
;
2334 SortDataBrowserContainer( m_dbImpl
->GetControlRef(), kDataBrowserNoItem
, true);
2336 // we need to do this after each call, else we get a crash from wxPython when
2337 // SortItems is called the second time.
2338 m_compareFunc
= NULL
;
2339 m_compareFuncData
= 0;
2345 void wxListCtrl::OnRenameTimer()
2347 wxCHECK_RET( HasCurrent(), wxT("unexpected rename timer") );
2349 EditLabel( m_current
);
2352 bool wxListCtrl::OnRenameAccept(long itemEdit
, const wxString
& value
)
2354 wxListEvent
le( wxEVT_COMMAND_LIST_END_LABEL_EDIT
, GetId() );
2355 le
.SetEventObject( this );
2356 le
.m_itemIndex
= itemEdit
;
2358 GetItem( le
.m_item
);
2359 le
.m_item
.m_text
= value
;
2360 return !HandleWindowEvent( le
) ||
2364 void wxListCtrl::OnRenameCancelled(long itemEdit
)
2366 // let owner know that the edit was cancelled
2367 wxListEvent
le( wxEVT_COMMAND_LIST_END_LABEL_EDIT
, GetParent()->GetId() );
2369 le
.SetEditCanceled(true);
2371 le
.SetEventObject( this );
2372 le
.m_itemIndex
= itemEdit
;
2374 GetItem( le
.m_item
);
2375 HandleWindowEvent( le
);
2378 // ----------------------------------------------------------------------------
2379 // virtual list controls
2380 // ----------------------------------------------------------------------------
2382 wxString
wxListCtrl::OnGetItemText(long WXUNUSED(item
), long WXUNUSED(col
)) const
2384 // this is a pure virtual function, in fact - which is not really pure
2385 // because the controls which are not virtual don't need to implement it
2386 wxFAIL_MSG( wxT("wxListCtrl::OnGetItemText not supposed to be called") );
2388 return wxEmptyString
;
2391 int wxListCtrl::OnGetItemImage(long WXUNUSED(item
)) const
2393 wxCHECK_MSG(!GetImageList(wxIMAGE_LIST_SMALL
),
2395 wxT("List control has an image list, OnGetItemImage or OnGetItemColumnImage should be overridden."));
2399 int wxListCtrl::OnGetItemColumnImage(long item
, long column
) const
2402 return OnGetItemImage(item
);
2407 wxListItemAttr
*wxListCtrl::OnGetItemAttr(long WXUNUSED_UNLESS_DEBUG(item
)) const
2409 wxASSERT_MSG( item
>= 0 && item
< GetItemCount(),
2410 wxT("invalid item index in OnGetItemAttr()") );
2412 // no attributes by default
2416 void wxListCtrl::SetItemCount(long count
)
2418 wxASSERT_MSG( IsVirtual(), wxT("this is for virtual controls only") );
2422 m_genericImpl
->SetItemCount(count
);
2428 // we need to temporarily disable the new item creation notification
2429 // procedure to speed things up
2430 // FIXME: Even this doesn't seem to help much...
2432 // FIXME: Find a more efficient way to do this.
2433 m_dbImpl
->MacClear();
2435 DataBrowserCallbacks callbacks
;
2436 DataBrowserItemNotificationUPP itemUPP
;
2437 GetDataBrowserCallbacks(m_dbImpl
->GetControlRef(), &callbacks
);
2438 itemUPP
= callbacks
.u
.v1
.itemNotificationCallback
;
2439 callbacks
.u
.v1
.itemNotificationCallback
= 0;
2440 m_dbImpl
->SetCallbacks(&callbacks
);
2441 ::AddDataBrowserItems(m_dbImpl
->GetControlRef(), kDataBrowserNoItem
,
2442 count
, NULL
, kDataBrowserItemNoProperty
);
2443 callbacks
.u
.v1
.itemNotificationCallback
= itemUPP
;
2444 m_dbImpl
->SetCallbacks(&callbacks
);
2449 void wxListCtrl::RefreshItem(long item
)
2453 m_genericImpl
->RefreshItem(item
);
2459 DataBrowserItemID id
;
2463 wxMacDataItem
* thisItem
= m_dbImpl
->GetItemFromLine(item
);
2464 id
= (DataBrowserItemID
) thisItem
;
2469 m_dbImpl
->wxMacDataBrowserControl::UpdateItems
2473 kDataBrowserItemNoProperty
, // preSortProperty
2474 kDataBrowserNoItem
// update all columns
2479 void wxListCtrl::RefreshItems(long itemFrom
, long itemTo
)
2483 m_genericImpl
->RefreshItems(itemFrom
, itemTo
);
2489 const long count
= itemTo
- itemFrom
+ 1;
2490 DataBrowserItemID
*ids
= new DataBrowserItemID
[count
];
2494 for ( long i
= 0; i
< count
; i
++ )
2496 wxMacDataItem
* thisItem
= m_dbImpl
->GetItemFromLine(itemFrom
+i
);
2497 ids
[i
] = (DataBrowserItemID
) thisItem
;
2502 for ( long i
= 0; i
< count
; i
++ )
2503 ids
[i
] = itemFrom
+i
+1;
2506 m_dbImpl
->wxMacDataBrowserControl::UpdateItems
2510 kDataBrowserItemNoProperty
, // preSortProperty
2511 kDataBrowserNoItem
// update all columns
2518 void wxListCtrl::SetDropTarget( wxDropTarget
*dropTarget
)
2520 #if wxUSE_DRAG_AND_DROP
2522 m_genericImpl
->SetDropTarget( dropTarget
);
2525 wxWindow::SetDropTarget( dropTarget
);
2529 wxDropTarget
*wxListCtrl::GetDropTarget() const
2531 #if wxUSE_DRAG_AND_DROP
2533 return m_genericImpl
->GetDropTarget();
2536 return wxWindow::GetDropTarget();
2541 #if wxABI_VERSION >= 20801
2542 void wxListCtrl::SetFocus()
2546 m_genericImpl
->SetFocus();
2550 wxWindow::SetFocus();
2554 // wxMac internal data structures
2556 wxMacListCtrlItem::~wxMacListCtrlItem()
2558 WX_CLEAR_HASH_MAP( wxListItemList
, m_rowItems
);
2561 void wxMacListCtrlItem::Notification(wxMacDataItemBrowserControl
*owner
,
2562 DataBrowserItemNotification message
,
2563 DataBrowserItemDataRef
WXUNUSED(itemData
) ) const
2566 wxMacDataBrowserListCtrlControl
*lb
= wxDynamicCast(owner
, wxMacDataBrowserListCtrlControl
);
2568 // we want to depend on as little as possible to make sure tear-down of controls is safe
2569 if ( message
== kDataBrowserItemRemoved
)
2574 else if ( message
== kDataBrowserItemAdded
)
2576 // we don't issue events on adding, the item is not really stored in the list yet, so we
2577 // avoid asserts by gettting out now
2581 wxListCtrl
*list
= wxDynamicCast( owner
->GetWXPeer() , wxListCtrl
);
2584 bool trigger
= false;
2586 wxListEvent
event( wxEVT_COMMAND_LIST_ITEM_SELECTED
, list
->GetId() );
2587 bool isSingle
= (list
->GetWindowStyle() & wxLC_SINGLE_SEL
) != 0;
2589 event
.SetEventObject( list
);
2590 event
.m_itemIndex
= owner
->GetLineFromItem( this ) ;
2591 event
.m_item
.m_itemId
= event
.m_itemIndex
;
2592 list
->GetItem(event
.m_item
);
2596 case kDataBrowserItemDeselected
:
2597 event
.SetEventType(wxEVT_COMMAND_LIST_ITEM_DESELECTED
);
2599 trigger
= !lb
->IsSelectionSuppressed();
2602 case kDataBrowserItemSelected
:
2603 trigger
= !lb
->IsSelectionSuppressed();
2606 case kDataBrowserItemDoubleClicked
:
2607 event
.SetEventType( wxEVT_COMMAND_LIST_ITEM_ACTIVATED
);
2611 case kDataBrowserEditStarted
:
2612 // TODO : how to veto ?
2613 event
.SetEventType( wxEVT_COMMAND_LIST_BEGIN_LABEL_EDIT
) ;
2617 case kDataBrowserEditStopped
:
2618 // TODO probably trigger only upon the value store callback, because
2619 // here IIRC we cannot veto
2620 event
.SetEventType( wxEVT_COMMAND_LIST_END_LABEL_EDIT
) ;
2630 // direct notification is not always having the listbox GetSelection() having in synch with event
2631 wxPostEvent( list
->GetEventHandler(), event
);
2637 IMPLEMENT_DYNAMIC_CLASS(wxMacDataBrowserListCtrlControl
, wxMacDataItemBrowserControl
)
2639 wxMacDataBrowserListCtrlControl::wxMacDataBrowserListCtrlControl( wxWindow
*peer
, const wxPoint
& pos
, const wxSize
& size
, long style
)
2640 : wxMacDataItemBrowserControl( peer
, pos
, size
, style
)
2642 OSStatus err
= noErr
;
2643 m_clientDataItemsType
= wxClientData_None
;
2644 m_isVirtual
= false;
2647 if ( style
& wxLC_VIRTUAL
)
2650 DataBrowserSelectionFlags options
= kDataBrowserDragSelect
;
2651 if ( style
& wxLC_SINGLE_SEL
)
2653 options
|= kDataBrowserSelectOnlyOne
;
2657 options
|= kDataBrowserCmdTogglesSelection
;
2660 err
= SetSelectionFlags( options
);
2661 verify_noerr( err
);
2663 DataBrowserCustomCallbacks callbacks
;
2664 InitializeDataBrowserCustomCallbacks( &callbacks
, kDataBrowserLatestCustomCallbacks
);
2666 if ( gDataBrowserDrawItemUPP
== NULL
)
2667 gDataBrowserDrawItemUPP
= NewDataBrowserDrawItemUPP(DataBrowserDrawItemProc
);
2669 if ( gDataBrowserHitTestUPP
== NULL
)
2670 gDataBrowserHitTestUPP
= NewDataBrowserHitTestUPP(DataBrowserHitTestProc
);
2672 callbacks
.u
.v1
.drawItemCallback
= gDataBrowserDrawItemUPP
;
2673 callbacks
.u
.v1
.hitTestCallback
= gDataBrowserHitTestUPP
;
2675 SetDataBrowserCustomCallbacks( GetControlRef(), &callbacks
);
2677 if ( style
& wxLC_LIST
)
2679 InsertColumn(0, kDataBrowserIconAndTextType
, wxEmptyString
, -1, -1);
2680 verify_noerr( AutoSizeColumns() );
2683 if ( style
& wxLC_LIST
|| style
& wxLC_NO_HEADER
)
2684 verify_noerr( SetHeaderButtonHeight( 0 ) );
2687 SetSortProperty( kMinColumnId
- 1 );
2689 SetSortProperty( kMinColumnId
);
2691 m_sortOrder
= SortOrder_None
;
2693 if ( style
& wxLC_SORT_DESCENDING
)
2695 SetSortOrder( kDataBrowserOrderDecreasing
);
2697 else if ( style
& wxLC_SORT_ASCENDING
)
2699 SetSortOrder( kDataBrowserOrderIncreasing
);
2702 if ( style
& wxLC_VRULES
)
2704 verify_noerr( DataBrowserChangeAttributes(m_controlRef
, kDataBrowserAttributeListViewDrawColumnDividers
, kDataBrowserAttributeNone
) );
2707 verify_noerr( SetHiliteStyle(kDataBrowserTableViewFillHilite
) );
2708 verify_noerr( SetHasScrollBars( (style
& wxHSCROLL
) != 0 , true ) );
2711 pascal Boolean
wxMacDataBrowserListCtrlControl::DataBrowserEditTextProc(
2713 DataBrowserItemID itemID
,
2714 DataBrowserPropertyID property
,
2715 CFStringRef theString
,
2716 Rect
*maxEditTextRect
,
2717 Boolean
*shrinkToFit
)
2719 Boolean result
= false;
2720 wxMacDataBrowserListCtrlControl
* ctl
= wxDynamicCast(wxMacControl::GetReferenceFromNativeControl( browser
), wxMacDataBrowserListCtrlControl
);
2723 result
= ctl
->ConfirmEditText(itemID
, property
, theString
, maxEditTextRect
, shrinkToFit
);
2724 theString
= CFSTR("Hello!");
2729 bool wxMacDataBrowserListCtrlControl::ConfirmEditText(
2730 DataBrowserItemID
WXUNUSED(itemID
),
2731 DataBrowserPropertyID
WXUNUSED(property
),
2732 CFStringRef
WXUNUSED(theString
),
2733 Rect
*WXUNUSED(maxEditTextRect
),
2734 Boolean
*WXUNUSED(shrinkToFit
))
2739 pascal void wxMacDataBrowserListCtrlControl::DataBrowserDrawItemProc(
2741 DataBrowserItemID itemID
,
2742 DataBrowserPropertyID property
,
2743 DataBrowserItemState itemState
,
2744 const Rect
*itemRect
,
2746 Boolean colorDevice
)
2748 wxMacDataBrowserListCtrlControl
* ctl
= wxDynamicCast(wxMacControl::GetReferenceFromNativeControl( browser
), wxMacDataBrowserListCtrlControl
);
2751 ctl
->DrawItem(itemID
, property
, itemState
, itemRect
, gdDepth
, colorDevice
);
2755 // routines needed for DrawItem
2760 kTextBoxHeight
= 14,
2761 kIconTextSpacingV
= 2,
2763 kContentHeight
= kIconHeight
+ kTextBoxHeight
+ kIconTextSpacingV
2766 static void calculateCGDrawingBounds(CGRect inItemRect
, CGRect
*outIconRect
, CGRect
*outTextRect
, bool hasIcon
= false)
2769 float iconH
, iconW
= 0;
2770 float padding
= kItemPadding
;
2773 iconH
= kIconHeight
;
2775 padding
= padding
*2;
2778 textBottom
= inItemRect
.origin
.y
;
2780 *outIconRect
= CGRectMake(inItemRect
.origin
.x
+ kItemPadding
,
2781 textBottom
+ kIconTextSpacingV
, kIconWidth
,
2784 *outTextRect
= CGRectMake(inItemRect
.origin
.x
+ padding
+ iconW
,
2785 textBottom
+ kIconTextSpacingV
, inItemRect
.size
.width
- padding
- iconW
,
2786 inItemRect
.size
.height
- kIconTextSpacingV
);
2789 void wxMacDataBrowserListCtrlControl::DrawItem(
2790 DataBrowserItemID itemID
,
2791 DataBrowserPropertyID property
,
2792 DataBrowserItemState itemState
,
2793 const Rect
*WXUNUSED(itemRect
),
2795 Boolean colorDevice
)
2798 wxFont font
= wxNullFont
;
2801 DataBrowserTableViewColumnIndex listColumn
= 0;
2802 GetColumnPosition( property
, &listColumn
);
2804 wxListCtrl
* list
= wxDynamicCast( GetWXPeer() , wxListCtrl
);
2805 wxMacListCtrlItem
* lcItem
;
2806 wxColour color
= *wxBLACK
;
2807 wxColour bgColor
= wxNullColour
;
2809 if (listColumn
>= 0)
2813 lcItem
= (wxMacListCtrlItem
*) itemID
;
2814 if (lcItem
->HasColumnInfo(listColumn
))
2816 wxListItem
* item
= lcItem
->GetColumnInfo(listColumn
);
2818 // we always use the 0 column to get font and text/background colors.
2819 if (lcItem
->HasColumnInfo(0))
2821 wxListItem
* firstItem
= lcItem
->GetColumnInfo(0);
2822 color
= firstItem
->GetTextColour();
2823 bgColor
= firstItem
->GetBackgroundColour();
2824 font
= firstItem
->GetFont();
2827 if (item
->GetMask() & wxLIST_MASK_TEXT
)
2828 text
= item
->GetText();
2829 if (item
->GetMask() & wxLIST_MASK_IMAGE
)
2830 imgIndex
= item
->GetImage();
2836 long itemNum
= (long)itemID
-1;
2837 if (itemNum
>= 0 && itemNum
< list
->GetItemCount())
2839 text
= list
->OnGetItemText( itemNum
, listColumn
);
2840 imgIndex
= list
->OnGetItemColumnImage( itemNum
, listColumn
);
2841 wxListItemAttr
* attrs
= list
->OnGetItemAttr( itemNum
);
2844 if (attrs
->HasBackgroundColour())
2845 bgColor
= attrs
->GetBackgroundColour();
2846 if (attrs
->HasTextColour())
2847 color
= attrs
->GetTextColour();
2848 if (attrs
->HasFont())
2849 font
= attrs
->GetFont();
2855 wxColour listBgColor
= list
->GetBackgroundColour();
2856 if (bgColor
== wxNullColour
)
2857 bgColor
= listBgColor
;
2860 font
= list
->GetFont();
2862 wxCFStringRef
cfString( text
, wxLocale::GetSystemEncoding() );
2865 CGRect enclosingCGRect
, iconCGRect
, textCGRect
;
2867 ThemeDrawingState savedState
= NULL
;
2868 CGContextRef context
= (CGContextRef
)list
->MacGetDrawingContext();
2869 wxMacCGContextStateSaver
top_saver_cg( context
);
2871 RGBColor labelColor
;
2873 labelColor
.green
= 0;
2874 labelColor
.blue
= 0;
2876 RGBColor backgroundColor
;
2877 backgroundColor
.red
= 255;
2878 backgroundColor
.green
= 255;
2879 backgroundColor
.blue
= 255;
2881 GetDataBrowserItemPartBounds(GetControlRef(), itemID
, property
, kDataBrowserPropertyEnclosingPart
,
2884 enclosingCGRect
= CGRectMake(enclosingRect
.left
,
2886 enclosingRect
.right
- enclosingRect
.left
,
2887 enclosingRect
.bottom
- enclosingRect
.top
);
2889 bool hasFocus
= (wxWindow::FindFocus() == list
);
2890 active
= IsControlActive(GetControlRef());
2892 // don't paint the background over the vertical rule line
2893 if ( list
->GetWindowStyleFlag() & wxLC_VRULES
)
2895 enclosingCGRect
.origin
.x
+= 1;
2896 enclosingCGRect
.size
.width
-= 1;
2898 if (itemState
== kDataBrowserItemIsSelected
)
2901 GetThemeDrawingState(&savedState
);
2903 if (active
&& hasFocus
)
2905 GetThemeBrushAsColor(kThemeBrushAlternatePrimaryHighlightColor
, 32, true, &backgroundColor
);
2906 GetThemeTextColor(kThemeTextColorWhite
, gdDepth
, colorDevice
, &labelColor
);
2910 GetThemeBrushAsColor(kThemeBrushSecondaryHighlightColor
, 32, true, &backgroundColor
);
2911 GetThemeTextColor(kThemeTextColorBlack
, gdDepth
, colorDevice
, &labelColor
);
2913 wxMacCGContextStateSaver
cg( context
);
2915 CGContextSetRGBFillColor(context
, (CGFloat
)backgroundColor
.red
/ (CGFloat
)USHRT_MAX
,
2916 (CGFloat
)backgroundColor
.green
/ (CGFloat
)USHRT_MAX
,
2917 (CGFloat
)backgroundColor
.blue
/ (CGFloat
)USHRT_MAX
, (CGFloat
) 1.0);
2918 CGContextFillRect(context
, enclosingCGRect
);
2924 color
.GetRGBColor(&labelColor
);
2925 else if (list
->GetTextColour().Ok())
2926 list
->GetTextColour().GetRGBColor(&labelColor
);
2930 bgColor
.GetRGBColor(&backgroundColor
);
2931 CGContextSaveGState(context
);
2933 CGContextSetRGBFillColor(context
, (CGFloat
)backgroundColor
.red
/ (CGFloat
)USHRT_MAX
,
2934 (CGFloat
)backgroundColor
.green
/ (CGFloat
)USHRT_MAX
,
2935 (CGFloat
)backgroundColor
.blue
/ (CGFloat
)USHRT_MAX
, (CGFloat
) 1.0);
2936 CGContextFillRect(context
, enclosingCGRect
);
2938 CGContextRestoreGState(context
);
2942 calculateCGDrawingBounds(enclosingCGRect
, &iconCGRect
, &textCGRect
, (imgIndex
!= -1) );
2946 wxImageList
* imageList
= list
->GetImageList(wxIMAGE_LIST_SMALL
);
2947 if (imageList
&& imageList
->GetImageCount() > 0)
2949 wxBitmap bmp
= imageList
->GetBitmap(imgIndex
);
2950 IconRef icon
= bmp
.GetIconRef();
2952 wxMacCGContextStateSaver
cg( context
);
2954 CGContextTranslateCTM(context
, 0,iconCGRect
.origin
.y
+ CGRectGetMaxY(iconCGRect
));
2955 CGContextScaleCTM(context
,1.0f
,-1.0f
);
2956 PlotIconRefInContext(context
, &iconCGRect
, kAlignNone
,
2957 active
? kTransformNone
: kTransformDisabled
, NULL
,
2958 kPlotIconRefNormalFlags
, icon
);
2962 HIThemeTextHorizontalFlush hFlush
= kHIThemeTextHorizontalFlushLeft
;
2963 HIThemeTextInfo info
;
2965 #if wxOSX_USE_CORE_TEXT
2966 if ( UMAGetSystemVersion() >= 0x1050 )
2968 info
.version
= kHIThemeTextInfoVersionOne
;
2969 info
.fontID
= kThemeViewsFont
;
2972 info
.fontID
= kThemeSpecifiedFont
;
2973 info
.font
= (CTFontRef
) font
.OSXGetCTFont();
2978 #if wxOSX_USE_ATSU_TEXT
2981 info
.version
= kHIThemeTextInfoVersionZero
;
2982 info
.fontID
= kThemeViewsFont
;
2986 info
.fontID
= font
.MacGetThemeFontID();
2988 ::TextSize( (short)(font
.GetPointSize()) ) ;
2989 ::TextFace( font
.MacGetFontStyle() ) ;
2995 list
->GetColumn(listColumn
, item
);
2996 if (item
.GetMask() & wxLIST_MASK_FORMAT
)
2998 if (item
.GetAlign() == wxLIST_FORMAT_LEFT
)
2999 hFlush
= kHIThemeTextHorizontalFlushLeft
;
3000 else if (item
.GetAlign() == wxLIST_FORMAT_CENTER
)
3001 hFlush
= kHIThemeTextHorizontalFlushCenter
;
3002 else if (item
.GetAlign() == wxLIST_FORMAT_RIGHT
)
3004 hFlush
= kHIThemeTextHorizontalFlushRight
;
3005 textCGRect
.origin
.x
-= kItemPadding
; // give a little extra paddding
3009 info
.state
= active
? kThemeStateActive
: kThemeStateInactive
;
3010 info
.horizontalFlushness
= hFlush
;
3011 info
.verticalFlushness
= kHIThemeTextVerticalFlushCenter
;
3012 info
.options
= kHIThemeTextBoxOptionNone
;
3013 info
.truncationPosition
= kHIThemeTextTruncationEnd
;
3014 info
.truncationMaxLines
= 1;
3017 wxMacCGContextStateSaver
cg( context
);
3018 CGContextSetRGBFillColor (context
, (CGFloat
)labelColor
.red
/ (CGFloat
)USHRT_MAX
,
3019 (CGFloat
)labelColor
.green
/ (CGFloat
)USHRT_MAX
,
3020 (CGFloat
)labelColor
.blue
/ (CGFloat
)USHRT_MAX
, (CGFloat
) 1.0);
3022 HIThemeDrawTextBox(cfString
, &textCGRect
, &info
, context
, kHIThemeOrientationNormal
);
3026 if (savedState
!= NULL
)
3027 SetThemeDrawingState(savedState
, true);
3031 OSStatus
wxMacDataBrowserListCtrlControl::GetSetItemData(DataBrowserItemID itemID
,
3032 DataBrowserPropertyID property
,
3033 DataBrowserItemDataRef itemData
,
3034 Boolean changeValue
)
3039 DataBrowserTableViewColumnIndex listColumn
= 0;
3040 verify_noerr( GetColumnPosition( property
, &listColumn
) );
3042 OSStatus err
= errDataBrowserPropertyNotSupported
;
3043 wxListCtrl
* list
= wxDynamicCast( GetWXPeer() , wxListCtrl
);
3044 wxMacListCtrlItem
* lcItem
= NULL
;
3046 if (listColumn
>= 0)
3050 lcItem
= (wxMacListCtrlItem
*) itemID
;
3051 if (lcItem
&& lcItem
->HasColumnInfo(listColumn
)){
3052 wxListItem
* item
= lcItem
->GetColumnInfo(listColumn
);
3053 if (item
->GetMask() & wxLIST_MASK_TEXT
)
3054 text
= item
->GetText();
3055 if (item
->GetMask() & wxLIST_MASK_IMAGE
)
3056 imgIndex
= item
->GetImage();
3061 long itemNum
= (long)itemID
-1;
3062 if (itemNum
>= 0 && itemNum
< list
->GetItemCount())
3064 text
= list
->OnGetItemText( itemNum
, listColumn
);
3065 imgIndex
= list
->OnGetItemColumnImage( itemNum
, listColumn
);
3074 case kDataBrowserItemIsEditableProperty
:
3075 if ( list
&& list
->HasFlag( wxLC_EDIT_LABELS
) )
3077 verify_noerr(SetDataBrowserItemDataBooleanValue( itemData
, true ));
3082 if ( property
>= kMinColumnId
)
3084 if (!text
.IsEmpty()){
3085 wxCFStringRef
cfStr( text
, wxLocale::GetSystemEncoding() );
3086 err
= ::SetDataBrowserItemDataText( itemData
, cfStr
);
3092 if ( imgIndex
!= -1 )
3094 wxImageList
* imageList
= list
->GetImageList(wxIMAGE_LIST_SMALL
);
3095 if (imageList
&& imageList
->GetImageCount() > 0){
3096 wxBitmap bmp
= imageList
->GetBitmap(imgIndex
);
3097 IconRef icon
= bmp
.GetIconRef();
3098 ::SetDataBrowserItemDataIcon(itemData
, icon
);
3112 if ( property
>= kMinColumnId
)
3114 DataBrowserTableViewColumnIndex listColumn
= 0;
3115 verify_noerr( GetColumnPosition( property
, &listColumn
) );
3117 // TODO probably send the 'end edit' from here, as we
3118 // can then deal with the veto
3120 verify_noerr( GetDataBrowserItemDataText( itemData
, &sr
) ) ;
3121 wxCFStringRef
cfStr(sr
) ;;
3123 list
->SetItem( (long)itemData
-1 , listColumn
, cfStr
.AsString() ) ;
3127 lcItem
->SetColumnTextValue( listColumn
, cfStr
.AsString() );
3137 void wxMacDataBrowserListCtrlControl::ItemNotification(DataBrowserItemID itemID
,
3138 DataBrowserItemNotification message
,
3139 DataBrowserItemDataRef itemData
)
3141 wxMacListCtrlItem
*item
= NULL
;
3144 item
= (wxMacListCtrlItem
*) itemID
;
3147 // we want to depend on as little as possible to make sure tear-down of controls is safe
3148 if ( message
== kDataBrowserItemRemoved
)
3151 item
->Notification(this, message
, itemData
);
3154 else if ( message
== kDataBrowserItemAdded
)
3156 // we don't issue events on adding, the item is not really stored in the list yet, so we
3157 // avoid asserts by getting out now
3159 item
->Notification(this, message
, itemData
);
3163 wxListCtrl
*list
= wxDynamicCast( GetWXPeer() , wxListCtrl
);
3166 bool trigger
= false;
3168 wxListEvent
event( wxEVT_COMMAND_LIST_ITEM_SELECTED
, list
->GetId() );
3170 event
.SetEventObject( list
);
3171 if ( !list
->IsVirtual() )
3173 DataBrowserTableViewRowIndex result
= 0;
3174 verify_noerr( GetItemRow( itemID
, &result
) ) ;
3175 event
.m_itemIndex
= result
;
3179 event
.m_itemIndex
= (long)itemID
-1;
3181 event
.m_item
.m_itemId
= event
.m_itemIndex
;
3182 list
->GetItem(event
.m_item
);
3186 case kDataBrowserItemDeselected
:
3187 event
.SetEventType(wxEVT_COMMAND_LIST_ITEM_DESELECTED
);
3188 // as the generic implementation is also triggering this
3189 // event for single selection, we do the same (different than listbox)
3190 trigger
= !IsSelectionSuppressed();
3193 case kDataBrowserItemSelected
:
3194 trigger
= !IsSelectionSuppressed();
3198 case kDataBrowserItemDoubleClicked
:
3199 event
.SetEventType( wxEVT_COMMAND_LIST_ITEM_ACTIVATED
);
3203 case kDataBrowserEditStarted
:
3204 // TODO : how to veto ?
3205 event
.SetEventType( wxEVT_COMMAND_LIST_BEGIN_LABEL_EDIT
) ;
3209 case kDataBrowserEditStopped
:
3210 // TODO probably trigger only upon the value store callback, because
3211 // here IIRC we cannot veto
3212 event
.SetEventType( wxEVT_COMMAND_LIST_END_LABEL_EDIT
) ;
3222 // direct notification is not always having the listbox GetSelection() having in synch with event
3223 wxPostEvent( list
->GetEventHandler(), event
);
3228 Boolean
wxMacDataBrowserListCtrlControl::CompareItems(DataBrowserItemID itemOneID
,
3229 DataBrowserItemID itemTwoID
,
3230 DataBrowserPropertyID sortProperty
)
3233 bool retval
= false;
3235 wxString otherItemText
;
3237 long otherItemOrder
;
3239 DataBrowserTableViewColumnIndex colId
= 0;
3240 verify_noerr( GetColumnPosition( sortProperty
, &colId
) );
3242 wxListCtrl
* list
= wxDynamicCast( GetWXPeer() , wxListCtrl
);
3244 DataBrowserSortOrder sort
;
3245 verify_noerr(GetSortOrder(&sort
));
3251 wxMacListCtrlItem
* item
= (wxMacListCtrlItem
*)itemOneID
;
3252 wxMacListCtrlItem
* otherItem
= (wxMacListCtrlItem
*)itemTwoID
;
3254 itemOrder
= item
->GetOrder();
3255 otherItemOrder
= otherItem
->GetOrder();
3257 wxListCtrlCompare func
= list
->GetCompareFunc();
3263 if (item
&& item
->HasColumnInfo(0))
3264 item1
= item
->GetColumnInfo(0)->GetData();
3265 if (otherItem
&& otherItem
->HasColumnInfo(0))
3266 item2
= otherItem
->GetColumnInfo(0)->GetData();
3268 if (item1
> -1 && item2
> -1)
3270 int result
= func(item1
, item2
, list
->GetCompareFuncData());
3271 if (sort
== kDataBrowserOrderIncreasing
)
3278 // we can't use the native control's sorting abilities, so just
3280 return itemOrder
< otherItemOrder
;
3285 long itemNum
= (long)itemOneID
;
3286 long otherItemNum
= (long)itemTwoID
;
3288 // virtual listctrls don't support sorting
3289 return itemNum
< otherItemNum
;
3293 // fallback for undefined cases
3294 retval
= itemOneID
< itemTwoID
;
3300 wxMacDataBrowserListCtrlControl::~wxMacDataBrowserListCtrlControl()
3304 void wxMacDataBrowserListCtrlControl::MacSetColumnInfo( unsigned int row
, unsigned int column
, wxListItem
* item
)
3306 wxMacDataItem
* dataItem
= GetItemFromLine(row
);
3307 wxASSERT_MSG( dataItem
, wxT("could not obtain wxMacDataItem for row in MacSetColumnInfo. Is row a valid wxListCtrl row?") );
3310 wxMacListCtrlItem
* listItem
= static_cast<wxMacListCtrlItem
*>(dataItem
);
3311 bool hasInfo
= listItem
->HasColumnInfo( column
);
3312 listItem
->SetColumnInfo( column
, item
);
3313 listItem
->SetOrder(row
);
3314 UpdateState(dataItem
, item
);
3316 wxListCtrl
* list
= wxDynamicCast( GetWXPeer() , wxListCtrl
);
3318 // NB: When this call was made before a control was completely shown, it would
3319 // update the item prematurely (i.e. no text would be listed) and, on show,
3320 // only the sorted column would be refreshed, meaning only first column text labels
3321 // would be shown. Making sure not to update items until the control is visible
3322 // seems to fix this issue.
3323 if (hasInfo
&& list
->IsShown())
3325 DataBrowserTableViewColumnID id
= 0;
3326 verify_noerr( GetColumnIDFromIndex( column
, &id
) );
3327 UpdateItem( wxMacDataBrowserRootContainer
, listItem
, id
);
3332 // apply changes that need to happen immediately, rather than when the
3333 // databrowser control fires a callback.
3334 void wxMacDataBrowserListCtrlControl::UpdateState(wxMacDataItem
* dataItem
, wxListItem
* listItem
)
3336 bool isSelected
= IsItemSelected( dataItem
);
3337 bool isSelectedState
= (listItem
->GetState() == wxLIST_STATE_SELECTED
);
3339 // toggle the selection state if wxListInfo state and actual state don't match.
3340 if ( listItem
->GetMask() & wxLIST_MASK_STATE
&& isSelected
!= isSelectedState
)
3342 DataBrowserSetOption options
= kDataBrowserItemsAdd
;
3343 if (!isSelectedState
)
3344 options
= kDataBrowserItemsRemove
;
3345 SetSelectedItem(dataItem
, options
);
3347 // TODO: Set column width if item width > than current column width
3350 void wxMacDataBrowserListCtrlControl::MacGetColumnInfo( unsigned int row
, unsigned int column
, wxListItem
& item
)
3352 wxMacDataItem
* dataItem
= GetItemFromLine(row
);
3353 wxASSERT_MSG( dataItem
, wxT("could not obtain wxMacDataItem in MacGetColumnInfo. Is row a valid wxListCtrl row?") );
3354 // CS should this guard against dataItem = 0 ? , as item is not a pointer if (item) is not appropriate
3357 wxMacListCtrlItem
* listItem
= static_cast<wxMacListCtrlItem
*>(dataItem
);
3359 if (!listItem
->HasColumnInfo( column
))
3362 wxListItem
* oldItem
= listItem
->GetColumnInfo( column
);
3366 long mask
= item
.GetMask();
3368 // by default, get everything for backwards compatibility
3371 if ( mask
& wxLIST_MASK_TEXT
)
3372 item
.SetText(oldItem
->GetText());
3373 if ( mask
& wxLIST_MASK_IMAGE
)
3374 item
.SetImage(oldItem
->GetImage());
3375 if ( mask
& wxLIST_MASK_DATA
)
3376 item
.SetData(oldItem
->GetData());
3377 if ( mask
& wxLIST_MASK_STATE
)
3378 item
.SetState(oldItem
->GetState());
3379 if ( mask
& wxLIST_MASK_WIDTH
)
3380 item
.SetWidth(oldItem
->GetWidth());
3381 if ( mask
& wxLIST_MASK_FORMAT
)
3382 item
.SetAlign(oldItem
->GetAlign());
3384 item
.SetTextColour(oldItem
->GetTextColour());
3385 item
.SetBackgroundColour(oldItem
->GetBackgroundColour());
3386 item
.SetFont(oldItem
->GetFont());
3391 void wxMacDataBrowserListCtrlControl::MacInsertItem( unsigned int n
, wxListItem
* item
)
3394 wxMacDataItemBrowserControl::MacInsert(n
, new wxMacListCtrlItem() );
3395 MacSetColumnInfo(n
, 0, item
);
3398 wxMacListCtrlItem::wxMacListCtrlItem()
3400 m_rowItems
= wxListItemList();
3403 int wxMacListCtrlItem::GetColumnImageValue( unsigned int column
)
3405 if ( HasColumnInfo(column
) )
3406 return GetColumnInfo(column
)->GetImage();
3411 void wxMacListCtrlItem::SetColumnImageValue( unsigned int column
, int imageIndex
)
3413 if ( HasColumnInfo(column
) )
3414 GetColumnInfo(column
)->SetImage(imageIndex
);
3417 wxString
wxMacListCtrlItem::GetColumnTextValue( unsigned int column
)
3419 /* TODO CHECK REMOVE
3423 if ( HasColumnInfo(column
) )
3424 return GetColumnInfo(column
)->GetText();
3426 return wxEmptyString
;
3429 void wxMacListCtrlItem::SetColumnTextValue( unsigned int column
, const wxString
& text
)
3431 if ( HasColumnInfo(column
) )
3432 GetColumnInfo(column
)->SetText(text
);
3434 /* TODO CHECK REMOVE
3435 // for compatibility with superclass APIs
3441 wxListItem
* wxMacListCtrlItem::GetColumnInfo( unsigned int column
)
3443 wxASSERT_MSG( HasColumnInfo(column
), wxT("invalid column index in wxMacListCtrlItem") );
3444 return m_rowItems
[column
];
3447 bool wxMacListCtrlItem::HasColumnInfo( unsigned int column
)
3449 return !(m_rowItems
.find( column
) == m_rowItems
.end());
3452 void wxMacListCtrlItem::SetColumnInfo( unsigned int column
, wxListItem
* item
)
3455 if ( !HasColumnInfo(column
) )
3457 wxListItem
* listItem
= new wxListItem(*item
);
3458 m_rowItems
[column
] = listItem
;
3462 wxListItem
* listItem
= GetColumnInfo( column
);
3463 long mask
= item
->GetMask();
3464 if (mask
& wxLIST_MASK_TEXT
)
3465 listItem
->SetText(item
->GetText());
3466 if (mask
& wxLIST_MASK_DATA
)
3467 listItem
->SetData(item
->GetData());
3468 if (mask
& wxLIST_MASK_IMAGE
)
3469 listItem
->SetImage(item
->GetImage());
3470 if (mask
& wxLIST_MASK_STATE
)
3471 listItem
->SetState(item
->GetState());
3472 if (mask
& wxLIST_MASK_FORMAT
)
3473 listItem
->SetAlign(item
->GetAlign());
3474 if (mask
& wxLIST_MASK_WIDTH
)
3475 listItem
->SetWidth(item
->GetWidth());
3477 if ( item
->HasAttributes() )
3479 if ( listItem
->HasAttributes() )
3480 listItem
->GetAttributes()->AssignFrom(*item
->GetAttributes());
3483 listItem
->SetTextColour(item
->GetTextColour());
3484 listItem
->SetBackgroundColour(item
->GetBackgroundColour());
3485 listItem
->SetFont(item
->GetFont());
3491 int wxListCtrl::CalcColumnAutoWidth(int col
) const
3495 for ( int i
= 0; i
< GetItemCount(); i
++ )
3498 info
.SetMask(wxLIST_MASK_TEXT
| wxLIST_MASK_IMAGE
);
3500 info
.SetColumn(col
);
3503 const wxFont font
= info
.GetFont();
3507 GetTextExtent(info
.GetText(), &w
, NULL
, NULL
, NULL
, &font
);
3509 GetTextExtent(info
.GetText(), &w
, NULL
);
3511 w
+= 2 * kItemPadding
;
3513 if ( info
.GetImage() != -1 )
3516 width
= wxMax(width
, w
);
3522 #endif // wxUSE_LISTCTRL