1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/generic/listctrl.cpp
3 // Purpose: generic implementation of wxListCtrl
4 // Author: Robert Roebling
5 // Vadim Zeitlin (virtual list control support)
7 // Copyright: (c) 1998 Robert Roebling
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
13 // 1. we need to implement searching/sorting for virtual controls somehow
14 // 2. when changing selection the lines are refreshed twice
17 // For compilers that support precompilation, includes "wx.h".
18 #include "wx/wxprec.h"
27 #include "wx/dynarray.h"
29 #include "wx/dcscreen.h"
30 #include "wx/textctrl.h"
33 // under Win32 we always use the native version and also may use the generic
34 // one, however some things should be done only if we use only the generic
36 #if defined(__WIN32__) && !defined(__WXUNIVERSAL__)
37 #define HAVE_NATIVE_LISTCTRL
40 // if we have the native control, wx/listctrl.h declares it and not this one
41 #ifdef HAVE_NATIVE_LISTCTRL
42 #include "wx/generic/listctrl.h"
43 #else // !HAVE_NATIVE_LISTCTRL
44 #include "wx/listctrl.h"
46 // if we have a native version, its implementation file does all this
47 IMPLEMENT_DYNAMIC_CLASS(wxListItem
, wxObject
)
48 IMPLEMENT_DYNAMIC_CLASS(wxListView
, wxListCtrl
)
49 IMPLEMENT_DYNAMIC_CLASS(wxListEvent
, wxNotifyEvent
)
51 IMPLEMENT_DYNAMIC_CLASS(wxListCtrl
, wxGenericListCtrl
)
52 #endif // HAVE_NATIVE_LISTCTRL/!HAVE_NATIVE_LISTCTRL
54 #include "wx/selstore.h"
55 #include "wx/renderer.h"
59 #include "wx/mac/private.h"
63 // NOTE: If using the wxListBox visual attributes works everywhere then this can
64 // be removed, as well as the #else case below.
65 #define _USE_VISATTR 0
68 // ----------------------------------------------------------------------------
70 // ----------------------------------------------------------------------------
72 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_BEGIN_DRAG
)
73 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_BEGIN_RDRAG
)
74 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_BEGIN_LABEL_EDIT
)
75 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_END_LABEL_EDIT
)
76 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_DELETE_ITEM
)
77 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_DELETE_ALL_ITEMS
)
78 #if WXWIN_COMPATIBILITY_2_4
79 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_GET_INFO
)
80 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_SET_INFO
)
82 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_ITEM_SELECTED
)
83 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_ITEM_DESELECTED
)
84 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_KEY_DOWN
)
85 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_INSERT_ITEM
)
86 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_COL_CLICK
)
87 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_COL_RIGHT_CLICK
)
88 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_COL_BEGIN_DRAG
)
89 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_COL_DRAGGING
)
90 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_COL_END_DRAG
)
91 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_ITEM_RIGHT_CLICK
)
92 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_ITEM_MIDDLE_CLICK
)
93 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_ITEM_ACTIVATED
)
94 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_ITEM_FOCUSED
)
95 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_CACHE_HINT
)
97 // ----------------------------------------------------------------------------
99 // ----------------------------------------------------------------------------
101 // // the height of the header window (FIXME: should depend on its font!)
102 // static const int HEADER_HEIGHT = 23;
104 static const int SCROLL_UNIT_X
= 15;
106 // the spacing between the lines (in report mode)
107 static const int LINE_SPACING
= 0;
109 // extra margins around the text label
110 static const int EXTRA_WIDTH
= 4;
111 static const int EXTRA_HEIGHT
= 4;
113 // margin between the window and the items
114 static const int EXTRA_BORDER_X
= 2;
115 static const int EXTRA_BORDER_Y
= 2;
117 // offset for the header window
118 static const int HEADER_OFFSET_X
= 1;
119 static const int HEADER_OFFSET_Y
= 1;
121 // margin between rows of icons in [small] icon view
122 static const int MARGIN_BETWEEN_ROWS
= 6;
124 // when autosizing the columns, add some slack
125 static const int AUTOSIZE_COL_MARGIN
= 10;
127 // default width for the header columns
128 static const int WIDTH_COL_DEFAULT
= 80;
130 // the space between the image and the text in the report mode
131 static const int IMAGE_MARGIN_IN_REPORT_MODE
= 5;
133 // ============================================================================
135 // ============================================================================
137 //-----------------------------------------------------------------------------
138 // wxColWidthInfo (internal)
139 //-----------------------------------------------------------------------------
141 struct wxColWidthInfo
144 bool bNeedsUpdate
; // only set to true when an item whose
145 // width == nMaxWidth is removed
147 wxColWidthInfo(int w
= 0, bool needsUpdate
= false)
150 bNeedsUpdate
= needsUpdate
;
154 WX_DEFINE_ARRAY_PTR(wxColWidthInfo
*, ColWidthArray
);
156 //-----------------------------------------------------------------------------
157 // wxListItemData (internal)
158 //-----------------------------------------------------------------------------
160 class WXDLLEXPORT wxListItemData
163 wxListItemData(wxListMainWindow
*owner
);
166 void SetItem( const wxListItem
&info
);
167 void SetImage( int image
) { m_image
= image
; }
168 void SetData( wxUIntPtr data
) { m_data
= data
; }
169 void SetPosition( int x
, int y
);
170 void SetSize( int width
, int height
);
172 bool HasText() const { return !m_text
.empty(); }
173 const wxString
& GetText() const { return m_text
; }
174 void SetText(const wxString
& text
) { m_text
= text
; }
176 // we can't use empty string for measuring the string width/height, so
177 // always return something
178 wxString
GetTextForMeasuring() const
180 wxString s
= GetText();
187 bool IsHit( int x
, int y
) const;
191 int GetWidth() const;
192 int GetHeight() const;
194 int GetImage() const { return m_image
; }
195 bool HasImage() const { return GetImage() != -1; }
197 void GetItem( wxListItem
&info
) const;
199 void SetAttr(wxListItemAttr
*attr
) { m_attr
= attr
; }
200 wxListItemAttr
*GetAttr() const { return m_attr
; }
203 // the item image or -1
206 // user data associated with the item
209 // the item coordinates are not used in report mode; instead this pointer is
210 // NULL and the owner window is used to retrieve the item position and size
213 // the list ctrl we are in
214 wxListMainWindow
*m_owner
;
216 // custom attributes or NULL
217 wxListItemAttr
*m_attr
;
220 // common part of all ctors
226 //-----------------------------------------------------------------------------
227 // wxListHeaderData (internal)
228 //-----------------------------------------------------------------------------
230 class WXDLLEXPORT wxListHeaderData
: public wxObject
234 wxListHeaderData( const wxListItem
&info
);
235 void SetItem( const wxListItem
&item
);
236 void SetPosition( int x
, int y
);
237 void SetWidth( int w
);
238 void SetFormat( int format
);
239 void SetHeight( int h
);
240 bool HasImage() const;
242 bool HasText() const { return !m_text
.empty(); }
243 const wxString
& GetText() const { return m_text
; }
244 void SetText(const wxString
& text
) { m_text
= text
; }
246 void GetItem( wxListItem
&item
);
248 bool IsHit( int x
, int y
) const;
249 int GetImage() const;
250 int GetWidth() const;
251 int GetFormat() const;
267 //-----------------------------------------------------------------------------
268 // wxListLineData (internal)
269 //-----------------------------------------------------------------------------
271 WX_DECLARE_EXPORTED_LIST(wxListItemData
, wxListItemDataList
);
272 #include "wx/listimpl.cpp"
273 WX_DEFINE_LIST(wxListItemDataList
)
278 // the list of subitems: only may have more than one item in report mode
279 wxListItemDataList m_items
;
281 // this is not used in report view
293 // the part to be highlighted
294 wxRect m_rectHighlight
;
296 // extend all our rects to be centered inside the one of given width
297 void ExtendWidth(wxCoord w
)
299 wxASSERT_MSG( m_rectAll
.width
<= w
,
300 _T("width can only be increased") );
303 m_rectLabel
.x
= m_rectAll
.x
+ (w
- m_rectLabel
.width
) / 2;
304 m_rectIcon
.x
= m_rectAll
.x
+ (w
- m_rectIcon
.width
) / 2;
305 m_rectHighlight
.x
= m_rectAll
.x
+ (w
- m_rectHighlight
.width
) / 2;
310 // is this item selected? [NB: not used in virtual mode]
313 // back pointer to the list ctrl
314 wxListMainWindow
*m_owner
;
317 wxListLineData(wxListMainWindow
*owner
);
321 WX_CLEAR_LIST(wxListItemDataList
, m_items
);
325 // are we in report mode?
326 inline bool InReportView() const;
328 // are we in virtual report mode?
329 inline bool IsVirtual() const;
331 // these 2 methods shouldn't be called for report view controls, in that
332 // case we determine our position/size ourselves
334 // calculate the size of the line
335 void CalculateSize( wxDC
*dc
, int spacing
);
337 // remember the position this line appears at
338 void SetPosition( int x
, int y
, int spacing
);
342 void SetImage( int image
) { SetImage(0, image
); }
343 int GetImage() const { return GetImage(0); }
344 void SetImage( int index
, int image
);
345 int GetImage( int index
) const;
347 bool HasImage() const { return GetImage() != -1; }
348 bool HasText() const { return !GetText(0).empty(); }
350 void SetItem( int index
, const wxListItem
&info
);
351 void GetItem( int index
, wxListItem
&info
);
353 wxString
GetText(int index
) const;
354 void SetText( int index
, const wxString
& s
);
356 wxListItemAttr
*GetAttr() const;
357 void SetAttr(wxListItemAttr
*attr
);
359 // return true if the highlighting really changed
360 bool Highlight( bool on
);
362 void ReverseHighlight();
364 bool IsHighlighted() const
366 wxASSERT_MSG( !IsVirtual(), _T("unexpected call to IsHighlighted") );
368 return m_highlighted
;
371 // draw the line on the given DC in icon/list mode
372 void Draw( wxDC
*dc
);
374 // the same in report mode
375 void DrawInReportMode( wxDC
*dc
,
377 const wxRect
& rectHL
,
381 // set the line to contain num items (only can be > 1 in report mode)
382 void InitItems( int num
);
384 // get the mode (i.e. style) of the list control
385 inline int GetMode() const;
387 // prepare the DC for drawing with these item's attributes, return true if
388 // we need to draw the items background to highlight it, false otherwise
389 bool SetAttributes(wxDC
*dc
,
390 const wxListItemAttr
*attr
,
393 // draw the text on the DC with the correct justification; also add an
394 // ellipsis if the text is too large to fit in the current width
395 void DrawTextFormatted(wxDC
*dc
,
396 const wxString
&text
,
399 int yMid
, // this is middle, not top, of the text
403 WX_DECLARE_EXPORTED_OBJARRAY(wxListLineData
, wxListLineDataArray
);
404 #include "wx/arrimpl.cpp"
405 WX_DEFINE_OBJARRAY(wxListLineDataArray
)
407 //-----------------------------------------------------------------------------
408 // wxListHeaderWindow (internal)
409 //-----------------------------------------------------------------------------
411 class WXDLLEXPORT wxListHeaderWindow
: public wxWindow
414 wxListMainWindow
*m_owner
;
415 const wxCursor
*m_currentCursor
;
416 wxCursor
*m_resizeCursor
;
419 // column being resized or -1
422 // divider line position in logical (unscrolled) coords
425 // minimal position beyond which the divider line
426 // can't be dragged in logical coords
430 wxListHeaderWindow();
432 wxListHeaderWindow( wxWindow
*win
,
434 wxListMainWindow
*owner
,
435 const wxPoint
&pos
= wxDefaultPosition
,
436 const wxSize
&size
= wxDefaultSize
,
438 const wxString
&name
= wxT("wxlistctrlcolumntitles") );
440 virtual ~wxListHeaderWindow();
443 void AdjustDC( wxDC
& dc
);
445 void OnPaint( wxPaintEvent
&event
);
446 void OnMouse( wxMouseEvent
&event
);
447 void OnSetFocus( wxFocusEvent
&event
);
453 // common part of all ctors
456 // generate and process the list event of the given type, return true if
457 // it wasn't vetoed, i.e. if we should proceed
458 bool SendListEvent(wxEventType type
, const wxPoint
& pos
);
460 DECLARE_DYNAMIC_CLASS(wxListHeaderWindow
)
461 DECLARE_EVENT_TABLE()
464 //-----------------------------------------------------------------------------
465 // wxListRenameTimer (internal)
466 //-----------------------------------------------------------------------------
468 class WXDLLEXPORT wxListRenameTimer
: public wxTimer
471 wxListMainWindow
*m_owner
;
474 wxListRenameTimer( wxListMainWindow
*owner
);
478 //-----------------------------------------------------------------------------
479 // wxListTextCtrlWrapper: wraps a wxTextCtrl to make it work for inline editing
480 //-----------------------------------------------------------------------------
482 class WXDLLEXPORT wxListTextCtrlWrapper
: public wxEvtHandler
485 // NB: text must be a valid object but not Create()d yet
486 wxListTextCtrlWrapper(wxListMainWindow
*owner
,
490 wxTextCtrl
*GetText() const { return m_text
; }
492 void AcceptChangesAndFinish();
495 void OnChar( wxKeyEvent
&event
);
496 void OnKeyUp( wxKeyEvent
&event
);
497 void OnKillFocus( wxFocusEvent
&event
);
499 bool AcceptChanges();
503 wxListMainWindow
*m_owner
;
505 wxString m_startValue
;
508 bool m_aboutToFinish
;
510 DECLARE_EVENT_TABLE()
513 //-----------------------------------------------------------------------------
514 // wxListMainWindow (internal)
515 //-----------------------------------------------------------------------------
517 WX_DECLARE_EXPORTED_LIST(wxListHeaderData
, wxListHeaderDataList
);
518 #include "wx/listimpl.cpp"
519 WX_DEFINE_LIST(wxListHeaderDataList
)
521 class wxListMainWindow
: public wxScrolledWindow
525 wxListMainWindow( wxWindow
*parent
,
527 const wxPoint
& pos
= wxDefaultPosition
,
528 const wxSize
& size
= wxDefaultSize
,
530 const wxString
&name
= _T("listctrlmainwindow") );
532 virtual ~wxListMainWindow();
534 bool HasFlag(int flag
) const { return m_parent
->HasFlag(flag
); }
536 // return true if this is a virtual list control
537 bool IsVirtual() const { return HasFlag(wxLC_VIRTUAL
); }
539 // return true if the control is in report mode
540 bool InReportView() const { return HasFlag(wxLC_REPORT
); }
542 // return true if we are in single selection mode, false if multi sel
543 bool IsSingleSel() const { return HasFlag(wxLC_SINGLE_SEL
); }
545 // do we have a header window?
546 bool HasHeader() const
547 { return InReportView() && !HasFlag(wxLC_NO_HEADER
); }
549 void HighlightAll( bool on
);
551 // all these functions only do something if the line is currently visible
553 // change the line "selected" state, return true if it really changed
554 bool HighlightLine( size_t line
, bool highlight
= true);
556 // as HighlightLine() but do it for the range of lines: this is incredibly
557 // more efficient for virtual list controls!
559 // NB: unlike HighlightLine() this one does refresh the lines on screen
560 void HighlightLines( size_t lineFrom
, size_t lineTo
, bool on
= true );
562 // toggle the line state and refresh it
563 void ReverseHighlight( size_t line
)
564 { HighlightLine(line
, !IsHighlighted(line
)); RefreshLine(line
); }
566 // return true if the line is highlighted
567 bool IsHighlighted(size_t line
) const;
569 // refresh one or several lines at once
570 void RefreshLine( size_t line
);
571 void RefreshLines( size_t lineFrom
, size_t lineTo
);
573 // refresh all selected items
574 void RefreshSelected();
576 // refresh all lines below the given one: the difference with
577 // RefreshLines() is that the index here might not be a valid one (happens
578 // when the last line is deleted)
579 void RefreshAfter( size_t lineFrom
);
581 // the methods which are forwarded to wxListLineData itself in list/icon
582 // modes but are here because the lines don't store their positions in the
585 // get the bound rect for the entire line
586 wxRect
GetLineRect(size_t line
) const;
588 // get the bound rect of the label
589 wxRect
GetLineLabelRect(size_t line
) const;
591 // get the bound rect of the items icon (only may be called if we do have
593 wxRect
GetLineIconRect(size_t line
) const;
595 // get the rect to be highlighted when the item has focus
596 wxRect
GetLineHighlightRect(size_t line
) const;
598 // get the size of the total line rect
599 wxSize
GetLineSize(size_t line
) const
600 { return GetLineRect(line
).GetSize(); }
602 // return the hit code for the corresponding position (in this line)
603 long HitTestLine(size_t line
, int x
, int y
) const;
605 // bring the selected item into view, scrolling to it if necessary
606 void MoveToItem(size_t item
);
608 // bring the current item into view
609 void MoveToFocus() { MoveToItem(m_current
); }
611 // start editing the label of the given item
612 wxTextCtrl
*EditLabel(long item
,
613 wxClassInfo
* textControlClass
= CLASSINFO(wxTextCtrl
));
614 wxTextCtrl
*GetEditControl() const
616 return m_textctrlWrapper
? m_textctrlWrapper
->GetText() : NULL
;
619 void FinishEditing(wxTextCtrl
*text
)
622 m_textctrlWrapper
= NULL
;
623 SetFocusIgnoringChildren();
626 // suspend/resume redrawing the control
630 void OnRenameTimer();
631 bool OnRenameAccept(size_t itemEdit
, const wxString
& value
);
632 void OnRenameCancelled(size_t itemEdit
);
634 void OnMouse( wxMouseEvent
&event
);
636 // called to switch the selection from the current item to newCurrent,
637 void OnArrowChar( size_t newCurrent
, const wxKeyEvent
& event
);
639 void OnChar( wxKeyEvent
&event
);
640 void OnKeyDown( wxKeyEvent
&event
);
641 void OnSetFocus( wxFocusEvent
&event
);
642 void OnKillFocus( wxFocusEvent
&event
);
643 void OnScroll( wxScrollWinEvent
& event
);
645 void OnPaint( wxPaintEvent
&event
);
647 void DrawImage( int index
, wxDC
*dc
, int x
, int y
);
648 void GetImageSize( int index
, int &width
, int &height
) const;
649 int GetTextLength( const wxString
&s
) const;
651 void SetImageList( wxImageListType
*imageList
, int which
);
652 void SetItemSpacing( int spacing
, bool isSmall
= false );
653 int GetItemSpacing( bool isSmall
= false );
655 void SetColumn( int col
, wxListItem
&item
);
656 void SetColumnWidth( int col
, int width
);
657 void GetColumn( int col
, wxListItem
&item
) const;
658 int GetColumnWidth( int col
) const;
659 int GetColumnCount() const { return m_columns
.GetCount(); }
661 // returns the sum of the heights of all columns
662 int GetHeaderWidth() const;
664 int GetCountPerPage() const;
666 void SetItem( wxListItem
&item
);
667 void GetItem( wxListItem
&item
) const;
668 void SetItemState( long item
, long state
, long stateMask
);
669 void SetItemStateAll( long state
, long stateMask
);
670 int GetItemState( long item
, long stateMask
) const;
671 void GetItemRect( long index
, wxRect
&rect
) const;
672 wxRect
GetViewRect() const;
673 bool GetItemPosition( long item
, wxPoint
& pos
) const;
674 int GetSelectedItemCount() const;
676 wxString
GetItemText(long item
) const
679 info
.m_mask
= wxLIST_MASK_TEXT
;
680 info
.m_itemId
= item
;
685 void SetItemText(long item
, const wxString
& value
)
688 info
.m_mask
= wxLIST_MASK_TEXT
;
689 info
.m_itemId
= item
;
694 // set the scrollbars and update the positions of the items
695 void RecalculatePositions(bool noRefresh
= false);
697 // refresh the window and the header
700 long GetNextItem( long item
, int geometry
, int state
) const;
701 void DeleteItem( long index
);
702 void DeleteAllItems();
703 void DeleteColumn( int col
);
704 void DeleteEverything();
705 void EnsureVisible( long index
);
706 long FindItem( long start
, const wxString
& str
, bool partial
= false );
707 long FindItem( long start
, wxUIntPtr data
);
708 long FindItem( const wxPoint
& pt
);
709 long HitTest( int x
, int y
, int &flags
);
710 void InsertItem( wxListItem
&item
);
711 void InsertColumn( long col
, wxListItem
&item
);
712 int GetItemWidthWithImage(wxListItem
* item
);
713 void SortItems( wxListCtrlCompare fn
, long data
);
715 size_t GetItemCount() const;
716 bool IsEmpty() const { return GetItemCount() == 0; }
717 void SetItemCount(long count
);
719 // change the current (== focused) item, send a notification event
720 void ChangeCurrent(size_t current
);
721 void ResetCurrent() { ChangeCurrent((size_t)-1); }
722 bool HasCurrent() const { return m_current
!= (size_t)-1; }
724 // send out a wxListEvent
725 void SendNotify( size_t line
,
727 const wxPoint
& point
= wxDefaultPosition
);
729 // override base class virtual to reset m_lineHeight when the font changes
730 virtual bool SetFont(const wxFont
& font
)
732 if ( !wxScrolledWindow::SetFont(font
) )
740 // these are for wxListLineData usage only
742 // get the backpointer to the list ctrl
743 wxGenericListCtrl
*GetListCtrl() const
745 return wxStaticCast(GetParent(), wxGenericListCtrl
);
748 // get the height of all lines (assuming they all do have the same height)
749 wxCoord
GetLineHeight() const;
751 // get the y position of the given line (only for report view)
752 wxCoord
GetLineY(size_t line
) const;
754 // get the brush to use for the item highlighting
755 wxBrush
*GetHighlightBrush() const
757 return m_hasFocus
? m_highlightBrush
: m_highlightUnfocusedBrush
;
761 // the array of all line objects for a non virtual list control (for the
762 // virtual list control we only ever use m_lines[0])
763 wxListLineDataArray m_lines
;
765 // the list of column objects
766 wxListHeaderDataList m_columns
;
768 // currently focused item or -1
771 // the number of lines per page
774 // this flag is set when something which should result in the window
775 // redrawing happens (i.e. an item was added or deleted, or its appearance
776 // changed) and OnPaint() doesn't redraw the window while it is set which
777 // allows to minimize the number of repaintings when a lot of items are
778 // being added. The real repainting occurs only after the next OnIdle()
782 wxColour
*m_highlightColour
;
783 wxImageListType
*m_small_image_list
;
784 wxImageListType
*m_normal_image_list
;
786 int m_normal_spacing
;
790 wxTimer
*m_renameTimer
;
794 ColWidthArray m_aColWidths
;
796 // for double click logic
797 size_t m_lineLastClicked
,
798 m_lineBeforeLastClicked
,
799 m_lineSelectSingleOnUp
;
802 wxWindow
*GetMainWindowOfCompositeControl() { return GetParent(); }
804 // the total count of items in a virtual list control
807 // the object maintaining the items selection state, only used in virtual
809 wxSelectionStore m_selStore
;
811 // common part of all ctors
814 // get the line data for the given index
815 wxListLineData
*GetLine(size_t n
) const
817 wxASSERT_MSG( n
!= (size_t)-1, _T("invalid line index") );
821 wxConstCast(this, wxListMainWindow
)->CacheLineData(n
);
828 // get a dummy line which can be used for geometry calculations and such:
829 // you must use GetLine() if you want to really draw the line
830 wxListLineData
*GetDummyLine() const;
832 // cache the line data of the n-th line in m_lines[0]
833 void CacheLineData(size_t line
);
835 // get the range of visible lines
836 void GetVisibleLinesRange(size_t *from
, size_t *to
);
838 // force us to recalculate the range of visible lines
839 void ResetVisibleLinesRange() { m_lineFrom
= (size_t)-1; }
841 // get the colour to be used for drawing the rules
842 wxColour
GetRuleColour() const
844 return wxSystemSettings::GetColour(wxSYS_COLOUR_3DLIGHT
);
848 // initialize the current item if needed
849 void UpdateCurrent();
851 // delete all items but don't refresh: called from dtor
852 void DoDeleteAllItems();
854 // the height of one line using the current font
855 wxCoord m_lineHeight
;
857 // the total header width or 0 if not calculated yet
858 wxCoord m_headerWidth
;
860 // the first and last lines being shown on screen right now (inclusive),
861 // both may be -1 if they must be calculated so never access them directly:
862 // use GetVisibleLinesRange() above instead
866 // the brushes to use for item highlighting when we do/don't have focus
867 wxBrush
*m_highlightBrush
,
868 *m_highlightUnfocusedBrush
;
870 // if this is > 0, the control is frozen and doesn't redraw itself
871 size_t m_freezeCount
;
873 // wrapper around the text control currently used for in place editing or
874 // NULL if no item is being edited
875 wxListTextCtrlWrapper
*m_textctrlWrapper
;
878 DECLARE_DYNAMIC_CLASS(wxListMainWindow
)
879 DECLARE_EVENT_TABLE()
881 friend class wxGenericListCtrl
;
885 wxListItemData::~wxListItemData()
887 // in the virtual list control the attributes are managed by the main
888 // program, so don't delete them
889 if ( !m_owner
->IsVirtual() )
895 void wxListItemData::Init()
903 wxListItemData::wxListItemData(wxListMainWindow
*owner
)
909 if ( owner
->InReportView() )
915 void wxListItemData::SetItem( const wxListItem
&info
)
917 if ( info
.m_mask
& wxLIST_MASK_TEXT
)
918 SetText(info
.m_text
);
919 if ( info
.m_mask
& wxLIST_MASK_IMAGE
)
920 m_image
= info
.m_image
;
921 if ( info
.m_mask
& wxLIST_MASK_DATA
)
922 m_data
= info
.m_data
;
924 if ( info
.HasAttributes() )
927 *m_attr
= *info
.GetAttributes();
929 m_attr
= new wxListItemAttr(*info
.GetAttributes());
937 m_rect
->width
= info
.m_width
;
941 void wxListItemData::SetPosition( int x
, int y
)
943 wxCHECK_RET( m_rect
, _T("unexpected SetPosition() call") );
949 void wxListItemData::SetSize( int width
, int height
)
951 wxCHECK_RET( m_rect
, _T("unexpected SetSize() call") );
954 m_rect
->width
= width
;
956 m_rect
->height
= height
;
959 bool wxListItemData::IsHit( int x
, int y
) const
961 wxCHECK_MSG( m_rect
, false, _T("can't be called in this mode") );
963 return wxRect(GetX(), GetY(), GetWidth(), GetHeight()).Inside(x
, y
);
966 int wxListItemData::GetX() const
968 wxCHECK_MSG( m_rect
, 0, _T("can't be called in this mode") );
973 int wxListItemData::GetY() const
975 wxCHECK_MSG( m_rect
, 0, _T("can't be called in this mode") );
980 int wxListItemData::GetWidth() const
982 wxCHECK_MSG( m_rect
, 0, _T("can't be called in this mode") );
984 return m_rect
->width
;
987 int wxListItemData::GetHeight() const
989 wxCHECK_MSG( m_rect
, 0, _T("can't be called in this mode") );
991 return m_rect
->height
;
994 void wxListItemData::GetItem( wxListItem
&info
) const
996 long mask
= info
.m_mask
;
998 // by default, get everything for backwards compatibility
1001 if ( mask
& wxLIST_MASK_TEXT
)
1002 info
.m_text
= m_text
;
1003 if ( mask
& wxLIST_MASK_IMAGE
)
1004 info
.m_image
= m_image
;
1005 if ( mask
& wxLIST_MASK_DATA
)
1006 info
.m_data
= m_data
;
1010 if ( m_attr
->HasTextColour() )
1011 info
.SetTextColour(m_attr
->GetTextColour());
1012 if ( m_attr
->HasBackgroundColour() )
1013 info
.SetBackgroundColour(m_attr
->GetBackgroundColour());
1014 if ( m_attr
->HasFont() )
1015 info
.SetFont(m_attr
->GetFont());
1019 //-----------------------------------------------------------------------------
1021 //-----------------------------------------------------------------------------
1023 void wxListHeaderData::Init()
1034 wxListHeaderData::wxListHeaderData()
1039 wxListHeaderData::wxListHeaderData( const wxListItem
&item
)
1046 void wxListHeaderData::SetItem( const wxListItem
&item
)
1048 m_mask
= item
.m_mask
;
1050 if ( m_mask
& wxLIST_MASK_TEXT
)
1051 m_text
= item
.m_text
;
1053 if ( m_mask
& wxLIST_MASK_IMAGE
)
1054 m_image
= item
.m_image
;
1056 if ( m_mask
& wxLIST_MASK_FORMAT
)
1057 m_format
= item
.m_format
;
1059 if ( m_mask
& wxLIST_MASK_WIDTH
)
1060 SetWidth(item
.m_width
);
1063 void wxListHeaderData::SetPosition( int x
, int y
)
1069 void wxListHeaderData::SetHeight( int h
)
1074 void wxListHeaderData::SetWidth( int w
)
1076 m_width
= w
< 0 ? WIDTH_COL_DEFAULT
: w
;
1079 void wxListHeaderData::SetFormat( int format
)
1084 bool wxListHeaderData::HasImage() const
1086 return m_image
!= -1;
1089 bool wxListHeaderData::IsHit( int x
, int y
) const
1091 return ((x
>= m_xpos
) && (x
<= m_xpos
+m_width
) && (y
>= m_ypos
) && (y
<= m_ypos
+m_height
));
1094 void wxListHeaderData::GetItem( wxListItem
& item
)
1096 item
.m_mask
= m_mask
;
1097 item
.m_text
= m_text
;
1098 item
.m_image
= m_image
;
1099 item
.m_format
= m_format
;
1100 item
.m_width
= m_width
;
1103 int wxListHeaderData::GetImage() const
1108 int wxListHeaderData::GetWidth() const
1113 int wxListHeaderData::GetFormat() const
1118 //-----------------------------------------------------------------------------
1120 //-----------------------------------------------------------------------------
1122 inline int wxListLineData::GetMode() const
1124 return m_owner
->GetListCtrl()->GetWindowStyleFlag() & wxLC_MASK_TYPE
;
1127 inline bool wxListLineData::InReportView() const
1129 return m_owner
->HasFlag(wxLC_REPORT
);
1132 inline bool wxListLineData::IsVirtual() const
1134 return m_owner
->IsVirtual();
1137 wxListLineData::wxListLineData( wxListMainWindow
*owner
)
1141 if ( InReportView() )
1144 m_gi
= new GeometryInfo
;
1146 m_highlighted
= false;
1148 InitItems( GetMode() == wxLC_REPORT
? m_owner
->GetColumnCount() : 1 );
1151 void wxListLineData::CalculateSize( wxDC
*dc
, int spacing
)
1153 wxListItemDataList::compatibility_iterator node
= m_items
.GetFirst();
1154 wxCHECK_RET( node
, _T("no subitems at all??") );
1156 wxListItemData
*item
= node
->GetData();
1161 switch ( GetMode() )
1164 case wxLC_SMALL_ICON
:
1165 m_gi
->m_rectAll
.width
= spacing
;
1167 s
= item
->GetText();
1172 m_gi
->m_rectLabel
.width
=
1173 m_gi
->m_rectLabel
.height
= 0;
1177 dc
->GetTextExtent( s
, &lw
, &lh
);
1181 m_gi
->m_rectAll
.height
= spacing
+ lh
;
1183 m_gi
->m_rectAll
.width
= lw
;
1185 m_gi
->m_rectLabel
.width
= lw
;
1186 m_gi
->m_rectLabel
.height
= lh
;
1189 if (item
->HasImage())
1192 m_owner
->GetImageSize( item
->GetImage(), w
, h
);
1193 m_gi
->m_rectIcon
.width
= w
+ 8;
1194 m_gi
->m_rectIcon
.height
= h
+ 8;
1196 if ( m_gi
->m_rectIcon
.width
> m_gi
->m_rectAll
.width
)
1197 m_gi
->m_rectAll
.width
= m_gi
->m_rectIcon
.width
;
1198 if ( m_gi
->m_rectIcon
.height
+ lh
> m_gi
->m_rectAll
.height
- 4 )
1199 m_gi
->m_rectAll
.height
= m_gi
->m_rectIcon
.height
+ lh
+ 4;
1202 if ( item
->HasText() )
1204 m_gi
->m_rectHighlight
.width
= m_gi
->m_rectLabel
.width
;
1205 m_gi
->m_rectHighlight
.height
= m_gi
->m_rectLabel
.height
;
1207 else // no text, highlight the icon
1209 m_gi
->m_rectHighlight
.width
= m_gi
->m_rectIcon
.width
;
1210 m_gi
->m_rectHighlight
.height
= m_gi
->m_rectIcon
.height
;
1215 s
= item
->GetTextForMeasuring();
1217 dc
->GetTextExtent( s
, &lw
, &lh
);
1221 m_gi
->m_rectLabel
.width
= lw
;
1222 m_gi
->m_rectLabel
.height
= lh
;
1224 m_gi
->m_rectAll
.width
= lw
;
1225 m_gi
->m_rectAll
.height
= lh
;
1227 if (item
->HasImage())
1230 m_owner
->GetImageSize( item
->GetImage(), w
, h
);
1231 m_gi
->m_rectIcon
.width
= w
;
1232 m_gi
->m_rectIcon
.height
= h
;
1234 m_gi
->m_rectAll
.width
+= 4 + w
;
1235 if (h
> m_gi
->m_rectAll
.height
)
1236 m_gi
->m_rectAll
.height
= h
;
1239 m_gi
->m_rectHighlight
.width
= m_gi
->m_rectAll
.width
;
1240 m_gi
->m_rectHighlight
.height
= m_gi
->m_rectAll
.height
;
1244 wxFAIL_MSG( _T("unexpected call to SetSize") );
1248 wxFAIL_MSG( _T("unknown mode") );
1253 void wxListLineData::SetPosition( int x
, int y
, int spacing
)
1255 wxListItemDataList::compatibility_iterator node
= m_items
.GetFirst();
1256 wxCHECK_RET( node
, _T("no subitems at all??") );
1258 wxListItemData
*item
= node
->GetData();
1260 switch ( GetMode() )
1263 case wxLC_SMALL_ICON
:
1264 m_gi
->m_rectAll
.x
= x
;
1265 m_gi
->m_rectAll
.y
= y
;
1267 if ( item
->HasImage() )
1269 m_gi
->m_rectIcon
.x
= m_gi
->m_rectAll
.x
+ 4 +
1270 (m_gi
->m_rectAll
.width
- m_gi
->m_rectIcon
.width
) / 2;
1271 m_gi
->m_rectIcon
.y
= m_gi
->m_rectAll
.y
+ 4;
1274 if ( item
->HasText() )
1276 if (m_gi
->m_rectAll
.width
> spacing
)
1277 m_gi
->m_rectLabel
.x
= m_gi
->m_rectAll
.x
+ 2;
1279 m_gi
->m_rectLabel
.x
= m_gi
->m_rectAll
.x
+ 2 + (spacing
/ 2) - (m_gi
->m_rectLabel
.width
/ 2);
1280 m_gi
->m_rectLabel
.y
= m_gi
->m_rectAll
.y
+ m_gi
->m_rectAll
.height
+ 2 - m_gi
->m_rectLabel
.height
;
1281 m_gi
->m_rectHighlight
.x
= m_gi
->m_rectLabel
.x
- 2;
1282 m_gi
->m_rectHighlight
.y
= m_gi
->m_rectLabel
.y
- 2;
1284 else // no text, highlight the icon
1286 m_gi
->m_rectHighlight
.x
= m_gi
->m_rectIcon
.x
- 4;
1287 m_gi
->m_rectHighlight
.y
= m_gi
->m_rectIcon
.y
- 4;
1292 m_gi
->m_rectAll
.x
= x
;
1293 m_gi
->m_rectAll
.y
= y
;
1295 m_gi
->m_rectHighlight
.x
= m_gi
->m_rectAll
.x
;
1296 m_gi
->m_rectHighlight
.y
= m_gi
->m_rectAll
.y
;
1297 m_gi
->m_rectLabel
.y
= m_gi
->m_rectAll
.y
+ 2;
1299 if (item
->HasImage())
1301 m_gi
->m_rectIcon
.x
= m_gi
->m_rectAll
.x
+ 2;
1302 m_gi
->m_rectIcon
.y
= m_gi
->m_rectAll
.y
+ 2;
1303 m_gi
->m_rectLabel
.x
= m_gi
->m_rectAll
.x
+ 6 + m_gi
->m_rectIcon
.width
;
1307 m_gi
->m_rectLabel
.x
= m_gi
->m_rectAll
.x
+ 2;
1312 wxFAIL_MSG( _T("unexpected call to SetPosition") );
1316 wxFAIL_MSG( _T("unknown mode") );
1321 void wxListLineData::InitItems( int num
)
1323 for (int i
= 0; i
< num
; i
++)
1324 m_items
.Append( new wxListItemData(m_owner
) );
1327 void wxListLineData::SetItem( int index
, const wxListItem
&info
)
1329 wxListItemDataList::compatibility_iterator node
= m_items
.Item( index
);
1330 wxCHECK_RET( node
, _T("invalid column index in SetItem") );
1332 wxListItemData
*item
= node
->GetData();
1333 item
->SetItem( info
);
1336 void wxListLineData::GetItem( int index
, wxListItem
&info
)
1338 wxListItemDataList::compatibility_iterator node
= m_items
.Item( index
);
1341 wxListItemData
*item
= node
->GetData();
1342 item
->GetItem( info
);
1346 wxString
wxListLineData::GetText(int index
) const
1350 wxListItemDataList::compatibility_iterator node
= m_items
.Item( index
);
1353 wxListItemData
*item
= node
->GetData();
1354 s
= item
->GetText();
1360 void wxListLineData::SetText( int index
, const wxString
& s
)
1362 wxListItemDataList::compatibility_iterator node
= m_items
.Item( index
);
1365 wxListItemData
*item
= node
->GetData();
1370 void wxListLineData::SetImage( int index
, int image
)
1372 wxListItemDataList::compatibility_iterator node
= m_items
.Item( index
);
1373 wxCHECK_RET( node
, _T("invalid column index in SetImage()") );
1375 wxListItemData
*item
= node
->GetData();
1376 item
->SetImage(image
);
1379 int wxListLineData::GetImage( int index
) const
1381 wxListItemDataList::compatibility_iterator node
= m_items
.Item( index
);
1382 wxCHECK_MSG( node
, -1, _T("invalid column index in GetImage()") );
1384 wxListItemData
*item
= node
->GetData();
1385 return item
->GetImage();
1388 wxListItemAttr
*wxListLineData::GetAttr() const
1390 wxListItemDataList::compatibility_iterator node
= m_items
.GetFirst();
1391 wxCHECK_MSG( node
, NULL
, _T("invalid column index in GetAttr()") );
1393 wxListItemData
*item
= node
->GetData();
1394 return item
->GetAttr();
1397 void wxListLineData::SetAttr(wxListItemAttr
*attr
)
1399 wxListItemDataList::compatibility_iterator node
= m_items
.GetFirst();
1400 wxCHECK_RET( node
, _T("invalid column index in SetAttr()") );
1402 wxListItemData
*item
= node
->GetData();
1403 item
->SetAttr(attr
);
1406 bool wxListLineData::SetAttributes(wxDC
*dc
,
1407 const wxListItemAttr
*attr
,
1410 wxWindow
*listctrl
= m_owner
->GetParent();
1414 // don't use foreground colour for drawing highlighted items - this might
1415 // make them completely invisible (and there is no way to do bit
1416 // arithmetics on wxColour, unfortunately)
1419 colText
= wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHTTEXT
);
1420 else if ( attr
&& attr
->HasTextColour() )
1421 colText
= attr
->GetTextColour();
1423 colText
= listctrl
->GetForegroundColour();
1425 dc
->SetTextForeground(colText
);
1429 if ( attr
&& attr
->HasFont() )
1430 font
= attr
->GetFont();
1432 font
= listctrl
->GetFont();
1437 bool hasBgCol
= attr
&& attr
->HasBackgroundColour();
1438 if ( highlighted
|| hasBgCol
)
1441 dc
->SetBrush( *m_owner
->GetHighlightBrush() );
1443 dc
->SetBrush(wxBrush(attr
->GetBackgroundColour(), wxSOLID
));
1445 dc
->SetPen( *wxTRANSPARENT_PEN
);
1453 void wxListLineData::Draw( wxDC
*dc
)
1455 wxListItemDataList::compatibility_iterator node
= m_items
.GetFirst();
1456 wxCHECK_RET( node
, _T("no subitems at all??") );
1458 bool highlighted
= IsHighlighted();
1460 wxListItemAttr
*attr
= GetAttr();
1462 if ( SetAttributes(dc
, attr
, highlighted
) )
1463 dc
->DrawRectangle( m_gi
->m_rectHighlight
);
1465 // just for debugging to better see where the items are
1467 dc
->SetPen(*wxRED_PEN
);
1468 dc
->SetBrush(*wxTRANSPARENT_BRUSH
);
1469 dc
->DrawRectangle( m_gi
->m_rectAll
);
1470 dc
->SetPen(*wxGREEN_PEN
);
1471 dc
->DrawRectangle( m_gi
->m_rectIcon
);
1474 wxListItemData
*item
= node
->GetData();
1475 if (item
->HasImage())
1477 // centre the image inside our rectangle, this looks nicer when items
1478 // ae aligned in a row
1479 const wxRect
& rectIcon
= m_gi
->m_rectIcon
;
1481 m_owner
->DrawImage(item
->GetImage(), dc
, rectIcon
.x
, rectIcon
.y
);
1484 if (item
->HasText())
1486 const wxRect
& rectLabel
= m_gi
->m_rectLabel
;
1488 wxDCClipper
clipper(*dc
, rectLabel
);
1489 dc
->DrawText(item
->GetText(), rectLabel
.x
, rectLabel
.y
);
1493 void wxListLineData::DrawInReportMode( wxDC
*dc
,
1495 const wxRect
& rectHL
,
1498 // TODO: later we should support setting different attributes for
1499 // different columns - to do it, just add "col" argument to
1500 // GetAttr() and move these lines into the loop below
1501 wxListItemAttr
*attr
= GetAttr();
1502 if ( SetAttributes(dc
, attr
, highlighted
) )
1503 dc
->DrawRectangle( rectHL
);
1505 wxCoord x
= rect
.x
+ HEADER_OFFSET_X
,
1506 yMid
= rect
.y
+ rect
.height
/2;
1509 for ( wxListItemDataList::compatibility_iterator node
= m_items
.GetFirst();
1511 node
= node
->GetNext(), col
++ )
1513 wxListItemData
*item
= node
->GetData();
1515 int width
= m_owner
->GetColumnWidth(col
);
1519 if ( item
->HasImage() )
1522 m_owner
->GetImageSize( item
->GetImage(), ix
, iy
);
1523 m_owner
->DrawImage( item
->GetImage(), dc
, xOld
, yMid
- iy
/2 );
1525 ix
+= IMAGE_MARGIN_IN_REPORT_MODE
;
1531 if ( item
->HasText() )
1532 DrawTextFormatted(dc
, item
->GetText(), col
, xOld
, yMid
, width
- 8);
1536 void wxListLineData::DrawTextFormatted(wxDC
*dc
,
1537 const wxString
&text
,
1544 dc
->GetTextExtent(text
, &w
, &h
);
1546 const wxCoord y
= yMid
- (h
+ 1)/2;
1548 wxDCClipper
clipper(*dc
, x
, y
, width
, h
);
1550 // determine if the string can fit inside the current width
1553 // it can, draw it using the items alignment
1555 m_owner
->GetColumn(col
, item
);
1556 switch ( item
.GetAlign() )
1558 case wxLIST_FORMAT_LEFT
:
1562 case wxLIST_FORMAT_RIGHT
:
1566 case wxLIST_FORMAT_CENTER
:
1567 x
+= (width
- w
) / 2;
1571 wxFAIL_MSG( _T("unknown list item format") );
1575 dc
->DrawText(text
, x
, y
);
1577 else // otherwise, truncate and add an ellipsis if possible
1579 // determine the base width
1580 wxString
ellipsis(wxT("..."));
1582 dc
->GetTextExtent(ellipsis
, &base_w
, &h
);
1584 // continue until we have enough space or only one character left
1586 size_t len
= text
.length();
1587 wxString drawntext
= text
.Left(len
);
1590 dc
->GetTextExtent(drawntext
.Last(), &w_c
, &h_c
);
1591 drawntext
.RemoveLast();
1594 if (w
+ base_w
<= width
)
1598 // if still not enough space, remove ellipsis characters
1599 while (ellipsis
.length() > 0 && w
+ base_w
> width
)
1601 ellipsis
= ellipsis
.Left(ellipsis
.length() - 1);
1602 dc
->GetTextExtent(ellipsis
, &base_w
, &h
);
1605 // now draw the text
1606 dc
->DrawText(drawntext
, x
, y
);
1607 dc
->DrawText(ellipsis
, x
+ w
, y
);
1611 bool wxListLineData::Highlight( bool on
)
1613 wxCHECK_MSG( !IsVirtual(), false, _T("unexpected call to Highlight") );
1615 if ( on
== m_highlighted
)
1623 void wxListLineData::ReverseHighlight( void )
1625 Highlight(!IsHighlighted());
1628 //-----------------------------------------------------------------------------
1629 // wxListHeaderWindow
1630 //-----------------------------------------------------------------------------
1632 IMPLEMENT_DYNAMIC_CLASS(wxListHeaderWindow
,wxWindow
)
1634 BEGIN_EVENT_TABLE(wxListHeaderWindow
,wxWindow
)
1635 EVT_PAINT (wxListHeaderWindow::OnPaint
)
1636 EVT_MOUSE_EVENTS (wxListHeaderWindow::OnMouse
)
1637 EVT_SET_FOCUS (wxListHeaderWindow::OnSetFocus
)
1640 void wxListHeaderWindow::Init()
1642 m_currentCursor
= (wxCursor
*) NULL
;
1643 m_isDragging
= false;
1647 wxListHeaderWindow::wxListHeaderWindow()
1651 m_owner
= (wxListMainWindow
*) NULL
;
1652 m_resizeCursor
= (wxCursor
*) NULL
;
1655 wxListHeaderWindow::wxListHeaderWindow( wxWindow
*win
,
1657 wxListMainWindow
*owner
,
1661 const wxString
&name
)
1662 : wxWindow( win
, id
, pos
, size
, style
, name
)
1667 m_resizeCursor
= new wxCursor( wxCURSOR_SIZEWE
);
1670 wxVisualAttributes attr
= wxPanel::GetClassDefaultAttributes();
1671 SetOwnForegroundColour( attr
.colFg
);
1672 SetOwnBackgroundColour( attr
.colBg
);
1674 SetOwnFont( attr
.font
);
1676 SetOwnForegroundColour( wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT
));
1677 SetOwnBackgroundColour( wxSystemSettings::GetColour(wxSYS_COLOUR_BTNFACE
));
1679 SetOwnFont( wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT
));
1683 wxListHeaderWindow::~wxListHeaderWindow()
1685 delete m_resizeCursor
;
1688 #ifdef __WXUNIVERSAL__
1689 #include "wx/univ/renderer.h"
1690 #include "wx/univ/theme.h"
1693 // shift the DC origin to match the position of the main window horz
1694 // scrollbar: this allows us to always use logical coords
1695 void wxListHeaderWindow::AdjustDC(wxDC
& dc
)
1698 m_owner
->GetScrollPixelsPerUnit( &xpix
, NULL
);
1701 m_owner
->GetViewStart( &x
, NULL
);
1703 // account for the horz scrollbar offset
1704 dc
.SetDeviceOrigin( -x
* xpix
, 0 );
1707 void wxListHeaderWindow::OnPaint( wxPaintEvent
&WXUNUSED(event
) )
1709 wxPaintDC
dc( this );
1714 dc
.SetFont( GetFont() );
1716 // width and height of the entire header window
1718 GetClientSize( &w
, &h
);
1719 m_owner
->CalcUnscrolledPosition(w
, 0, &w
, NULL
);
1721 dc
.SetBackgroundMode(wxTRANSPARENT
);
1722 dc
.SetTextForeground(GetForegroundColour());
1724 int x
= HEADER_OFFSET_X
;
1725 int numColumns
= m_owner
->GetColumnCount();
1727 for ( int i
= 0; i
< numColumns
&& x
< w
; i
++ )
1729 m_owner
->GetColumn( i
, item
);
1730 int wCol
= item
.m_width
;
1732 // the width of the rect to draw: make it smaller to fit entirely
1733 // inside the column rect
1742 wxRendererNative::Get().DrawHeaderButton
1746 wxRect(x
, HEADER_OFFSET_Y
, cw
, ch
),
1747 m_parent
->IsEnabled() ? 0
1748 : (int)wxCONTROL_DISABLED
1751 // see if we have enough space for the column label
1753 // for this we need the width of the text
1756 dc
.GetTextExtent(item
.GetText(), &wLabel
, &hLabel
);
1757 wLabel
+= 2 * EXTRA_WIDTH
;
1759 // and the width of the icon, if any
1760 static const int MARGIN_BETWEEN_TEXT_AND_ICON
= 2;
1761 int ix
= 0, iy
= 0; // init them just to suppress the compiler warnings
1762 const int image
= item
.m_image
;
1763 wxImageListType
*imageList
;
1766 imageList
= m_owner
->m_small_image_list
;
1769 imageList
->GetSize(image
, ix
, iy
);
1770 wLabel
+= ix
+ MARGIN_BETWEEN_TEXT_AND_ICON
;
1778 // ignore alignment if there is not enough space anyhow
1780 switch ( wLabel
< cw
? item
.GetAlign() : wxLIST_FORMAT_LEFT
)
1783 wxFAIL_MSG( _T("unknown list item format") );
1786 case wxLIST_FORMAT_LEFT
:
1790 case wxLIST_FORMAT_RIGHT
:
1791 xAligned
= x
+ cw
- wLabel
;
1794 case wxLIST_FORMAT_CENTER
:
1795 xAligned
= x
+ (cw
- wLabel
) / 2;
1799 // if we have an image, draw it on the right of the label
1806 xAligned
+ wLabel
- ix
- MARGIN_BETWEEN_TEXT_AND_ICON
,
1807 HEADER_OFFSET_Y
+ (h
- 4 - iy
)/2,
1808 wxIMAGELIST_DRAW_TRANSPARENT
1811 cw
-= ix
+ MARGIN_BETWEEN_TEXT_AND_ICON
;
1814 // draw the text clipping it so that it doesn't overwrite the column
1816 wxDCClipper
clipper(dc
, x
, HEADER_OFFSET_Y
, cw
, h
- 4 );
1818 dc
.DrawText( item
.GetText(),
1819 xAligned
+ EXTRA_WIDTH
, h
/ 2 - hLabel
/ 2 ); //HEADER_OFFSET_Y + EXTRA_HEIGHT );
1825 void wxListHeaderWindow::DrawCurrent()
1827 int x1
= m_currentX
;
1829 m_owner
->ClientToScreen( &x1
, &y1
);
1831 int x2
= m_currentX
;
1833 m_owner
->GetClientSize( NULL
, &y2
);
1834 m_owner
->ClientToScreen( &x2
, &y2
);
1837 dc
.SetLogicalFunction( wxINVERT
);
1838 dc
.SetPen( wxPen( *wxBLACK
, 2, wxSOLID
) );
1839 dc
.SetBrush( *wxTRANSPARENT_BRUSH
);
1843 dc
.DrawLine( x1
, y1
, x2
, y2
);
1845 dc
.SetLogicalFunction( wxCOPY
);
1847 dc
.SetPen( wxNullPen
);
1848 dc
.SetBrush( wxNullBrush
);
1851 void wxListHeaderWindow::OnMouse( wxMouseEvent
&event
)
1853 // we want to work with logical coords
1855 m_owner
->CalcUnscrolledPosition(event
.GetX(), 0, &x
, NULL
);
1856 int y
= event
.GetY();
1860 SendListEvent(wxEVT_COMMAND_LIST_COL_DRAGGING
, event
.GetPosition());
1862 // we don't draw the line beyond our window, but we allow dragging it
1865 GetClientSize( &w
, NULL
);
1866 m_owner
->CalcUnscrolledPosition(w
, 0, &w
, NULL
);
1869 // erase the line if it was drawn
1870 if ( m_currentX
< w
)
1873 if (event
.ButtonUp())
1876 m_isDragging
= false;
1878 m_owner
->SetColumnWidth( m_column
, m_currentX
- m_minX
);
1879 SendListEvent(wxEVT_COMMAND_LIST_COL_END_DRAG
, event
.GetPosition());
1886 m_currentX
= m_minX
+ 7;
1888 // draw in the new location
1889 if ( m_currentX
< w
)
1893 else // not dragging
1896 bool hit_border
= false;
1898 // end of the current column
1901 // find the column where this event occurred
1903 countCol
= m_owner
->GetColumnCount();
1904 for (col
= 0; col
< countCol
; col
++)
1906 xpos
+= m_owner
->GetColumnWidth( col
);
1909 if ( (abs(x
-xpos
) < 3) && (y
< 22) )
1911 // near the column border
1918 // inside the column
1925 if ( col
== countCol
)
1928 if (event
.LeftDown() || event
.RightUp())
1930 if (hit_border
&& event
.LeftDown())
1932 if ( SendListEvent(wxEVT_COMMAND_LIST_COL_BEGIN_DRAG
,
1933 event
.GetPosition()) )
1935 m_isDragging
= true;
1940 //else: column resizing was vetoed by the user code
1942 else // click on a column
1944 SendListEvent( event
.LeftDown()
1945 ? wxEVT_COMMAND_LIST_COL_CLICK
1946 : wxEVT_COMMAND_LIST_COL_RIGHT_CLICK
,
1947 event
.GetPosition());
1950 else if (event
.Moving())
1955 setCursor
= m_currentCursor
== wxSTANDARD_CURSOR
;
1956 m_currentCursor
= m_resizeCursor
;
1960 setCursor
= m_currentCursor
!= wxSTANDARD_CURSOR
;
1961 m_currentCursor
= wxSTANDARD_CURSOR
;
1965 SetCursor(*m_currentCursor
);
1970 void wxListHeaderWindow::OnSetFocus( wxFocusEvent
&WXUNUSED(event
) )
1972 m_owner
->SetFocus();
1976 bool wxListHeaderWindow::SendListEvent(wxEventType type
, const wxPoint
& pos
)
1978 wxWindow
*parent
= GetParent();
1979 wxListEvent
le( type
, parent
->GetId() );
1980 le
.SetEventObject( parent
);
1981 le
.m_pointDrag
= pos
;
1983 // the position should be relative to the parent window, not
1984 // this one for compatibility with MSW and common sense: the
1985 // user code doesn't know anything at all about this header
1986 // window, so why should it get positions relative to it?
1987 le
.m_pointDrag
.y
-= GetSize().y
;
1989 le
.m_col
= m_column
;
1990 return !parent
->GetEventHandler()->ProcessEvent( le
) || le
.IsAllowed();
1993 //-----------------------------------------------------------------------------
1994 // wxListRenameTimer (internal)
1995 //-----------------------------------------------------------------------------
1997 wxListRenameTimer::wxListRenameTimer( wxListMainWindow
*owner
)
2002 void wxListRenameTimer::Notify()
2004 m_owner
->OnRenameTimer();
2007 //-----------------------------------------------------------------------------
2008 // wxListTextCtrlWrapper (internal)
2009 //-----------------------------------------------------------------------------
2011 BEGIN_EVENT_TABLE(wxListTextCtrlWrapper
, wxEvtHandler
)
2012 EVT_CHAR (wxListTextCtrlWrapper::OnChar
)
2013 EVT_KEY_UP (wxListTextCtrlWrapper::OnKeyUp
)
2014 EVT_KILL_FOCUS (wxListTextCtrlWrapper::OnKillFocus
)
2017 wxListTextCtrlWrapper::wxListTextCtrlWrapper(wxListMainWindow
*owner
,
2020 : m_startValue(owner
->GetItemText(itemEdit
)),
2021 m_itemEdited(itemEdit
)
2026 m_aboutToFinish
= false;
2028 wxRect rectLabel
= owner
->GetLineLabelRect(itemEdit
);
2030 m_owner
->CalcScrolledPosition(rectLabel
.x
, rectLabel
.y
,
2031 &rectLabel
.x
, &rectLabel
.y
);
2033 m_text
->Create(owner
, wxID_ANY
, m_startValue
,
2034 wxPoint(rectLabel
.x
-4,rectLabel
.y
-4),
2035 wxSize(rectLabel
.width
+11,rectLabel
.height
+8));
2038 m_text
->PushEventHandler(this);
2041 void wxListTextCtrlWrapper::Finish()
2047 m_text
->RemoveEventHandler(this);
2048 m_owner
->FinishEditing(m_text
);
2050 wxPendingDelete
.Append( this );
2054 bool wxListTextCtrlWrapper::AcceptChanges()
2056 const wxString value
= m_text
->GetValue();
2058 if ( value
== m_startValue
)
2059 // nothing changed, always accept
2062 if ( !m_owner
->OnRenameAccept(m_itemEdited
, value
) )
2063 // vetoed by the user
2066 // accepted, do rename the item
2067 m_owner
->SetItemText(m_itemEdited
, value
);
2072 void wxListTextCtrlWrapper::AcceptChangesAndFinish()
2074 m_aboutToFinish
= true;
2076 // Notify the owner about the changes
2079 // Even if vetoed, close the control (consistent with MSW)
2083 void wxListTextCtrlWrapper::OnChar( wxKeyEvent
&event
)
2085 switch ( event
.m_keyCode
)
2088 AcceptChangesAndFinish();
2092 m_owner
->OnRenameCancelled( m_itemEdited
);
2101 void wxListTextCtrlWrapper::OnKeyUp( wxKeyEvent
&event
)
2109 // auto-grow the textctrl:
2110 wxSize parentSize
= m_owner
->GetSize();
2111 wxPoint myPos
= m_text
->GetPosition();
2112 wxSize mySize
= m_text
->GetSize();
2114 m_text
->GetTextExtent(m_text
->GetValue() + _T("MM"), &sx
, &sy
);
2115 if (myPos
.x
+ sx
> parentSize
.x
)
2116 sx
= parentSize
.x
- myPos
.x
;
2119 m_text
->SetSize(sx
, wxDefaultCoord
);
2124 void wxListTextCtrlWrapper::OnKillFocus( wxFocusEvent
&event
)
2126 if ( !m_finished
&& !m_aboutToFinish
)
2128 if ( !AcceptChanges() )
2129 m_owner
->OnRenameCancelled( m_itemEdited
);
2134 // We must let the native text control handle focus
2138 //-----------------------------------------------------------------------------
2140 //-----------------------------------------------------------------------------
2142 IMPLEMENT_DYNAMIC_CLASS(wxListMainWindow
,wxScrolledWindow
)
2144 BEGIN_EVENT_TABLE(wxListMainWindow
,wxScrolledWindow
)
2145 EVT_PAINT (wxListMainWindow::OnPaint
)
2146 EVT_MOUSE_EVENTS (wxListMainWindow::OnMouse
)
2147 EVT_CHAR (wxListMainWindow::OnChar
)
2148 EVT_KEY_DOWN (wxListMainWindow::OnKeyDown
)
2149 EVT_SET_FOCUS (wxListMainWindow::OnSetFocus
)
2150 EVT_KILL_FOCUS (wxListMainWindow::OnKillFocus
)
2151 EVT_SCROLLWIN (wxListMainWindow::OnScroll
)
2154 void wxListMainWindow::Init()
2159 m_lineTo
= (size_t)-1;
2165 m_small_image_list
= (wxImageListType
*) NULL
;
2166 m_normal_image_list
= (wxImageListType
*) NULL
;
2168 m_small_spacing
= 30;
2169 m_normal_spacing
= 40;
2173 m_isCreated
= false;
2175 m_lastOnSame
= false;
2176 m_renameTimer
= new wxListRenameTimer( this );
2177 m_textctrlWrapper
= NULL
;
2181 m_lineSelectSingleOnUp
=
2182 m_lineBeforeLastClicked
= (size_t)-1;
2187 wxListMainWindow::wxListMainWindow()
2192 m_highlightUnfocusedBrush
= (wxBrush
*) NULL
;
2195 wxListMainWindow::wxListMainWindow( wxWindow
*parent
,
2200 const wxString
&name
)
2201 : wxScrolledWindow( parent
, id
, pos
, size
,
2202 style
| wxHSCROLL
| wxVSCROLL
, name
)
2206 m_highlightBrush
= new wxBrush
2208 wxSystemSettings::GetColour
2210 wxSYS_COLOUR_HIGHLIGHT
2215 m_highlightUnfocusedBrush
= new wxBrush
2217 wxSystemSettings::GetColour
2219 wxSYS_COLOUR_BTNSHADOW
2224 SetScrollbars( 0, 0, 0, 0, 0, 0 );
2226 wxVisualAttributes attr
= wxGenericListCtrl::GetClassDefaultAttributes();
2227 SetOwnForegroundColour( attr
.colFg
);
2228 SetOwnBackgroundColour( attr
.colBg
);
2230 SetOwnFont( attr
.font
);
2233 wxListMainWindow::~wxListMainWindow()
2236 WX_CLEAR_LIST(wxListHeaderDataList
, m_columns
);
2237 WX_CLEAR_ARRAY(m_aColWidths
);
2239 delete m_highlightBrush
;
2240 delete m_highlightUnfocusedBrush
;
2241 delete m_renameTimer
;
2244 void wxListMainWindow::CacheLineData(size_t line
)
2246 wxGenericListCtrl
*listctrl
= GetListCtrl();
2248 wxListLineData
*ld
= GetDummyLine();
2250 size_t countCol
= GetColumnCount();
2251 for ( size_t col
= 0; col
< countCol
; col
++ )
2253 ld
->SetText(col
, listctrl
->OnGetItemText(line
, col
));
2254 ld
->SetImage(col
, listctrl
->OnGetItemColumnImage(line
, col
));
2257 ld
->SetAttr(listctrl
->OnGetItemAttr(line
));
2260 wxListLineData
*wxListMainWindow::GetDummyLine() const
2262 wxASSERT_MSG( !IsEmpty(), _T("invalid line index") );
2263 wxASSERT_MSG( IsVirtual(), _T("GetDummyLine() shouldn't be called") );
2265 wxListMainWindow
*self
= wxConstCast(this, wxListMainWindow
);
2267 // we need to recreate the dummy line if the number of columns in the
2268 // control changed as it would have the incorrect number of fields
2270 if ( !m_lines
.IsEmpty() &&
2271 m_lines
[0].m_items
.GetCount() != (size_t)GetColumnCount() )
2273 self
->m_lines
.Clear();
2276 if ( m_lines
.IsEmpty() )
2278 wxListLineData
*line
= new wxListLineData(self
);
2279 self
->m_lines
.Add(line
);
2281 // don't waste extra memory -- there never going to be anything
2282 // else/more in this array
2283 self
->m_lines
.Shrink();
2289 // ----------------------------------------------------------------------------
2290 // line geometry (report mode only)
2291 // ----------------------------------------------------------------------------
2293 wxCoord
wxListMainWindow::GetLineHeight() const
2295 // we cache the line height as calling GetTextExtent() is slow
2296 if ( !m_lineHeight
)
2298 wxListMainWindow
*self
= wxConstCast(this, wxListMainWindow
);
2300 wxClientDC
dc( self
);
2301 dc
.SetFont( GetFont() );
2304 dc
.GetTextExtent(_T("H"), NULL
, &y
);
2306 if ( m_small_image_list
&& m_small_image_list
->GetImageCount() )
2309 m_small_image_list
->GetSize(0, iw
, ih
);
2314 self
->m_lineHeight
= y
+ LINE_SPACING
;
2317 return m_lineHeight
;
2320 wxCoord
wxListMainWindow::GetLineY(size_t line
) const
2322 wxASSERT_MSG( InReportView(), _T("only works in report mode") );
2324 return LINE_SPACING
+ line
* GetLineHeight();
2327 wxRect
wxListMainWindow::GetLineRect(size_t line
) const
2329 if ( !InReportView() )
2330 return GetLine(line
)->m_gi
->m_rectAll
;
2333 rect
.x
= HEADER_OFFSET_X
;
2334 rect
.y
= GetLineY(line
);
2335 rect
.width
= GetHeaderWidth();
2336 rect
.height
= GetLineHeight();
2341 wxRect
wxListMainWindow::GetLineLabelRect(size_t line
) const
2343 if ( !InReportView() )
2344 return GetLine(line
)->m_gi
->m_rectLabel
;
2347 rect
.x
= HEADER_OFFSET_X
;
2348 rect
.y
= GetLineY(line
);
2349 rect
.width
= GetColumnWidth(0);
2350 rect
.height
= GetLineHeight();
2355 wxRect
wxListMainWindow::GetLineIconRect(size_t line
) const
2357 if ( !InReportView() )
2358 return GetLine(line
)->m_gi
->m_rectIcon
;
2360 wxListLineData
*ld
= GetLine(line
);
2361 wxASSERT_MSG( ld
->HasImage(), _T("should have an image") );
2364 rect
.x
= HEADER_OFFSET_X
;
2365 rect
.y
= GetLineY(line
);
2366 GetImageSize(ld
->GetImage(), rect
.width
, rect
.height
);
2371 wxRect
wxListMainWindow::GetLineHighlightRect(size_t line
) const
2373 return InReportView() ? GetLineRect(line
)
2374 : GetLine(line
)->m_gi
->m_rectHighlight
;
2377 long wxListMainWindow::HitTestLine(size_t line
, int x
, int y
) const
2379 wxASSERT_MSG( line
< GetItemCount(), _T("invalid line in HitTestLine") );
2381 wxListLineData
*ld
= GetLine(line
);
2383 if ( ld
->HasImage() && GetLineIconRect(line
).Inside(x
, y
) )
2384 return wxLIST_HITTEST_ONITEMICON
;
2386 // VS: Testing for "ld->HasText() || InReportView()" instead of
2387 // "ld->HasText()" is needed to make empty lines in report view
2389 if ( ld
->HasText() || InReportView() )
2391 wxRect rect
= InReportView() ? GetLineRect(line
)
2392 : GetLineLabelRect(line
);
2394 if ( rect
.Inside(x
, y
) )
2395 return wxLIST_HITTEST_ONITEMLABEL
;
2401 // ----------------------------------------------------------------------------
2402 // highlight (selection) handling
2403 // ----------------------------------------------------------------------------
2405 bool wxListMainWindow::IsHighlighted(size_t line
) const
2409 return m_selStore
.IsSelected(line
);
2413 wxListLineData
*ld
= GetLine(line
);
2414 wxCHECK_MSG( ld
, false, _T("invalid index in IsHighlighted") );
2416 return ld
->IsHighlighted();
2420 void wxListMainWindow::HighlightLines( size_t lineFrom
,
2426 wxArrayInt linesChanged
;
2427 if ( !m_selStore
.SelectRange(lineFrom
, lineTo
, highlight
,
2430 // meny items changed state, refresh everything
2431 RefreshLines(lineFrom
, lineTo
);
2433 else // only a few items changed state, refresh only them
2435 size_t count
= linesChanged
.GetCount();
2436 for ( size_t n
= 0; n
< count
; n
++ )
2438 RefreshLine(linesChanged
[n
]);
2442 else // iterate over all items in non report view
2444 for ( size_t line
= lineFrom
; line
<= lineTo
; line
++ )
2446 if ( HighlightLine(line
, highlight
) )
2452 bool wxListMainWindow::HighlightLine( size_t line
, bool highlight
)
2458 changed
= m_selStore
.SelectItem(line
, highlight
);
2462 wxListLineData
*ld
= GetLine(line
);
2463 wxCHECK_MSG( ld
, false, _T("invalid index in HighlightLine") );
2465 changed
= ld
->Highlight(highlight
);
2470 SendNotify( line
, highlight
? wxEVT_COMMAND_LIST_ITEM_SELECTED
2471 : wxEVT_COMMAND_LIST_ITEM_DESELECTED
);
2477 void wxListMainWindow::RefreshLine( size_t line
)
2479 if ( InReportView() )
2481 size_t visibleFrom
, visibleTo
;
2482 GetVisibleLinesRange(&visibleFrom
, &visibleTo
);
2484 if ( line
< visibleFrom
|| line
> visibleTo
)
2488 wxRect rect
= GetLineRect(line
);
2490 CalcScrolledPosition( rect
.x
, rect
.y
, &rect
.x
, &rect
.y
);
2491 RefreshRect( rect
);
2494 void wxListMainWindow::RefreshLines( size_t lineFrom
, size_t lineTo
)
2496 // we suppose that they are ordered by caller
2497 wxASSERT_MSG( lineFrom
<= lineTo
, _T("indices in disorder") );
2499 wxASSERT_MSG( lineTo
< GetItemCount(), _T("invalid line range") );
2501 if ( InReportView() )
2503 size_t visibleFrom
, visibleTo
;
2504 GetVisibleLinesRange(&visibleFrom
, &visibleTo
);
2506 if ( lineFrom
< visibleFrom
)
2507 lineFrom
= visibleFrom
;
2508 if ( lineTo
> visibleTo
)
2513 rect
.y
= GetLineY(lineFrom
);
2514 rect
.width
= GetClientSize().x
;
2515 rect
.height
= GetLineY(lineTo
) - rect
.y
+ GetLineHeight();
2517 CalcScrolledPosition( rect
.x
, rect
.y
, &rect
.x
, &rect
.y
);
2518 RefreshRect( rect
);
2522 // TODO: this should be optimized...
2523 for ( size_t line
= lineFrom
; line
<= lineTo
; line
++ )
2530 void wxListMainWindow::RefreshAfter( size_t lineFrom
)
2532 if ( InReportView() )
2534 size_t visibleFrom
, visibleTo
;
2535 GetVisibleLinesRange(&visibleFrom
, &visibleTo
);
2537 if ( lineFrom
< visibleFrom
)
2538 lineFrom
= visibleFrom
;
2539 else if ( lineFrom
> visibleTo
)
2544 rect
.y
= GetLineY(lineFrom
);
2545 CalcScrolledPosition( rect
.x
, rect
.y
, &rect
.x
, &rect
.y
);
2547 wxSize size
= GetClientSize();
2548 rect
.width
= size
.x
;
2550 // refresh till the bottom of the window
2551 rect
.height
= size
.y
- rect
.y
;
2553 RefreshRect( rect
);
2557 // TODO: how to do it more efficiently?
2562 void wxListMainWindow::RefreshSelected()
2568 if ( InReportView() )
2570 GetVisibleLinesRange(&from
, &to
);
2575 to
= GetItemCount() - 1;
2578 if ( HasCurrent() && m_current
>= from
&& m_current
<= to
)
2579 RefreshLine(m_current
);
2581 for ( size_t line
= from
; line
<= to
; line
++ )
2583 // NB: the test works as expected even if m_current == -1
2584 if ( line
!= m_current
&& IsHighlighted(line
) )
2589 void wxListMainWindow::Freeze()
2594 void wxListMainWindow::Thaw()
2596 wxCHECK_RET( m_freezeCount
> 0, _T("thawing unfrozen list control?") );
2598 if ( --m_freezeCount
== 0 )
2602 void wxListMainWindow::OnPaint( wxPaintEvent
&WXUNUSED(event
) )
2604 // Note: a wxPaintDC must be constructed even if no drawing is
2605 // done (a Windows requirement).
2606 wxPaintDC
dc( this );
2608 if ( IsEmpty() || m_freezeCount
)
2609 // nothing to draw or not the moment to draw it
2613 // delay the repainting until we calculate all the items positions
2619 CalcScrolledPosition( 0, 0, &dev_x
, &dev_y
);
2621 dc
.SetFont( GetFont() );
2623 if ( InReportView() )
2625 int lineHeight
= GetLineHeight();
2627 size_t visibleFrom
, visibleTo
;
2628 GetVisibleLinesRange(&visibleFrom
, &visibleTo
);
2631 wxCoord xOrig
, yOrig
;
2632 CalcUnscrolledPosition(0, 0, &xOrig
, &yOrig
);
2634 // tell the caller cache to cache the data
2637 wxListEvent
evCache(wxEVT_COMMAND_LIST_CACHE_HINT
,
2638 GetParent()->GetId());
2639 evCache
.SetEventObject( GetParent() );
2640 evCache
.m_oldItemIndex
= visibleFrom
;
2641 evCache
.m_itemIndex
= visibleTo
;
2642 GetParent()->GetEventHandler()->ProcessEvent( evCache
);
2645 for ( size_t line
= visibleFrom
; line
<= visibleTo
; line
++ )
2647 rectLine
= GetLineRect(line
);
2649 if ( !IsExposed(rectLine
.x
- xOrig
, rectLine
.y
- yOrig
,
2650 rectLine
.width
, rectLine
.height
) )
2652 // don't redraw unaffected lines to avoid flicker
2656 GetLine(line
)->DrawInReportMode( &dc
,
2658 GetLineHighlightRect(line
),
2659 IsHighlighted(line
) );
2662 if ( HasFlag(wxLC_HRULES
) )
2664 wxPen
pen(GetRuleColour(), 1, wxSOLID
);
2665 wxSize clientSize
= GetClientSize();
2667 // Don't draw the first one
2668 for ( size_t i
= visibleFrom
+ 1; i
<= visibleTo
; i
++ )
2671 dc
.SetBrush( *wxTRANSPARENT_BRUSH
);
2672 dc
.DrawLine(0 - dev_x
, i
* lineHeight
,
2673 clientSize
.x
- dev_x
, i
* lineHeight
);
2676 // Draw last horizontal rule
2677 if ( visibleTo
== GetItemCount() - 1 )
2680 dc
.SetBrush( *wxTRANSPARENT_BRUSH
);
2681 dc
.DrawLine(0 - dev_x
, (m_lineTo
+ 1) * lineHeight
,
2682 clientSize
.x
- dev_x
, (m_lineTo
+ 1) * lineHeight
);
2686 // Draw vertical rules if required
2687 if ( HasFlag(wxLC_VRULES
) && !IsEmpty() )
2689 wxPen
pen(GetRuleColour(), 1, wxSOLID
);
2690 wxRect firstItemRect
, lastItemRect
;
2692 GetItemRect(visibleFrom
, firstItemRect
);
2693 GetItemRect(visibleTo
, lastItemRect
);
2694 int x
= firstItemRect
.GetX();
2696 dc
.SetBrush(* wxTRANSPARENT_BRUSH
);
2698 for (int col
= 0; col
< GetColumnCount(); col
++)
2700 int colWidth
= GetColumnWidth(col
);
2702 dc
.DrawLine(x
- dev_x
- 2, firstItemRect
.GetY() - 1 - dev_y
,
2703 x
- dev_x
- 2, lastItemRect
.GetBottom() + 1 - dev_y
);
2709 size_t count
= GetItemCount();
2710 for ( size_t i
= 0; i
< count
; i
++ )
2712 GetLine(i
)->Draw( &dc
);
2717 // Don't draw rect outline under Mac at all.
2722 dc
.SetPen( *wxBLACK_PEN
);
2723 dc
.SetBrush( *wxTRANSPARENT_BRUSH
);
2724 dc
.DrawRectangle( GetLineHighlightRect( m_current
) );
2730 void wxListMainWindow::HighlightAll( bool on
)
2732 if ( IsSingleSel() )
2734 wxASSERT_MSG( !on
, _T("can't do this in a single selection control") );
2736 // we just have one item to turn off
2737 if ( HasCurrent() && IsHighlighted(m_current
) )
2739 HighlightLine(m_current
, false);
2740 RefreshLine(m_current
);
2745 HighlightLines(0, GetItemCount() - 1, on
);
2749 void wxListMainWindow::SendNotify( size_t line
,
2750 wxEventType command
,
2751 const wxPoint
& point
)
2753 wxListEvent
le( command
, GetParent()->GetId() );
2754 le
.SetEventObject( GetParent() );
2755 le
.m_itemIndex
= line
;
2757 // set only for events which have position
2758 if ( point
!= wxDefaultPosition
)
2759 le
.m_pointDrag
= point
;
2761 // don't try to get the line info for virtual list controls: the main
2762 // program has it anyhow and if we did it would result in accessing all
2763 // the lines, even those which are not visible now and this is precisely
2764 // what we're trying to avoid
2765 if ( !IsVirtual() && (command
!= wxEVT_COMMAND_LIST_DELETE_ITEM
) )
2767 if ( line
!= (size_t)-1 )
2769 GetLine(line
)->GetItem( 0, le
.m_item
);
2771 //else: this happens for wxEVT_COMMAND_LIST_ITEM_FOCUSED event
2773 //else: there may be no more such item
2775 GetParent()->GetEventHandler()->ProcessEvent( le
);
2778 void wxListMainWindow::ChangeCurrent(size_t current
)
2780 m_current
= current
;
2782 SendNotify(current
, wxEVT_COMMAND_LIST_ITEM_FOCUSED
);
2785 wxTextCtrl
*wxListMainWindow::EditLabel(long item
, wxClassInfo
* textControlClass
)
2787 wxCHECK_MSG( (item
>= 0) && ((size_t)item
< GetItemCount()), NULL
,
2788 wxT("wrong index in wxGenericListCtrl::EditLabel()") );
2790 wxASSERT_MSG( textControlClass
->IsKindOf(CLASSINFO(wxTextCtrl
)),
2791 wxT("EditLabel() needs a text control") );
2793 size_t itemEdit
= (size_t)item
;
2795 wxListEvent
le( wxEVT_COMMAND_LIST_BEGIN_LABEL_EDIT
, GetParent()->GetId() );
2796 le
.SetEventObject( GetParent() );
2797 le
.m_itemIndex
= item
;
2798 wxListLineData
*data
= GetLine(itemEdit
);
2799 wxCHECK_MSG( data
, NULL
, _T("invalid index in EditLabel()") );
2800 data
->GetItem( 0, le
.m_item
);
2802 if ( GetParent()->GetEventHandler()->ProcessEvent( le
) && !le
.IsAllowed() )
2804 // vetoed by user code
2808 // We have to call this here because the label in question might just have
2809 // been added and no screen update taken place.
2813 wxTextCtrl
* const text
= (wxTextCtrl
*)textControlClass
->CreateObject();
2814 m_textctrlWrapper
= new wxListTextCtrlWrapper(this, text
, item
);
2815 return m_textctrlWrapper
->GetText();
2818 void wxListMainWindow::OnRenameTimer()
2820 wxCHECK_RET( HasCurrent(), wxT("unexpected rename timer") );
2822 EditLabel( m_current
);
2825 bool wxListMainWindow::OnRenameAccept(size_t itemEdit
, const wxString
& value
)
2827 wxListEvent
le( wxEVT_COMMAND_LIST_END_LABEL_EDIT
, GetParent()->GetId() );
2828 le
.SetEventObject( GetParent() );
2829 le
.m_itemIndex
= itemEdit
;
2831 wxListLineData
*data
= GetLine(itemEdit
);
2833 wxCHECK_MSG( data
, false, _T("invalid index in OnRenameAccept()") );
2835 data
->GetItem( 0, le
.m_item
);
2836 le
.m_item
.m_text
= value
;
2837 return !GetParent()->GetEventHandler()->ProcessEvent( le
) ||
2841 void wxListMainWindow::OnRenameCancelled(size_t itemEdit
)
2843 // let owner know that the edit was cancelled
2844 wxListEvent
le( wxEVT_COMMAND_LIST_END_LABEL_EDIT
, GetParent()->GetId() );
2846 le
.SetEditCanceled(true);
2848 le
.SetEventObject( GetParent() );
2849 le
.m_itemIndex
= itemEdit
;
2851 wxListLineData
*data
= GetLine(itemEdit
);
2852 wxCHECK_RET( data
, _T("invalid index in OnRenameCancelled()") );
2854 data
->GetItem( 0, le
.m_item
);
2855 GetEventHandler()->ProcessEvent( le
);
2858 void wxListMainWindow::OnMouse( wxMouseEvent
&event
)
2862 // On wxMac we can't depend on the EVT_KILL_FOCUS event to properly
2863 // shutdown the edit control when the mouse is clicked elsewhere on the
2864 // listctrl because the order of events is different (or something like
2865 // that), so explicitly end the edit if it is active.
2866 if ( event
.LeftDown() && m_textctrlWrapper
)
2867 m_textctrlWrapper
->AcceptChangesAndFinish();
2870 event
.SetEventObject( GetParent() );
2871 if ( GetParent()->GetEventHandler()->ProcessEvent( event
) )
2874 if (event
.GetEventType() == wxEVT_MOUSEWHEEL
)
2876 // let the base handle mouse wheel events.
2881 if ( !HasCurrent() || IsEmpty() )
2883 if (event
.RightDown())
2885 SendNotify( (size_t)-1, wxEVT_COMMAND_LIST_ITEM_RIGHT_CLICK
, event
.GetPosition() );
2886 // Allow generation of context menu event
2895 if ( !(event
.Dragging() || event
.ButtonDown() || event
.LeftUp() ||
2896 event
.ButtonDClick()) )
2899 int x
= event
.GetX();
2900 int y
= event
.GetY();
2901 CalcUnscrolledPosition( x
, y
, &x
, &y
);
2903 // where did we hit it (if we did)?
2906 size_t count
= GetItemCount(),
2909 if ( InReportView() )
2911 current
= y
/ GetLineHeight();
2912 if ( current
< count
)
2913 hitResult
= HitTestLine(current
, x
, y
);
2917 // TODO: optimize it too! this is less simple than for report view but
2918 // enumerating all items is still not a way to do it!!
2919 for ( current
= 0; current
< count
; current
++ )
2921 hitResult
= HitTestLine(current
, x
, y
);
2927 if (event
.Dragging())
2929 if (m_dragCount
== 0)
2931 // we have to report the raw, physical coords as we want to be
2932 // able to call HitTest(event.m_pointDrag) from the user code to
2933 // get the item being dragged
2934 m_dragStart
= event
.GetPosition();
2939 if (m_dragCount
!= 3)
2942 int command
= event
.RightIsDown() ? wxEVT_COMMAND_LIST_BEGIN_RDRAG
2943 : wxEVT_COMMAND_LIST_BEGIN_DRAG
;
2945 wxListEvent
le( command
, GetParent()->GetId() );
2946 le
.SetEventObject( GetParent() );
2947 le
.m_itemIndex
= m_lineLastClicked
;
2948 le
.m_pointDrag
= m_dragStart
;
2949 GetParent()->GetEventHandler()->ProcessEvent( le
);
2960 // outside of any item
2961 if (event
.RightDown())
2963 SendNotify( (size_t) -1, wxEVT_COMMAND_LIST_ITEM_RIGHT_CLICK
, event
.GetPosition() );
2964 // Allow generation of context menu event
2969 // reset the selection and bail out
2970 HighlightAll(false);
2976 bool forceClick
= false;
2977 if (event
.ButtonDClick())
2979 m_renameTimer
->Stop();
2980 m_lastOnSame
= false;
2982 if ( current
== m_lineLastClicked
)
2984 SendNotify( current
, wxEVT_COMMAND_LIST_ITEM_ACTIVATED
);
2990 // The first click was on another item, so don't interpret this as
2991 // a double click, but as a simple click instead
2998 if (m_lineSelectSingleOnUp
!= (size_t)-1)
3000 // select single line
3001 HighlightAll( false );
3002 ReverseHighlight(m_lineSelectSingleOnUp
);
3007 if ((current
== m_current
) &&
3008 (hitResult
== wxLIST_HITTEST_ONITEMLABEL
) &&
3009 HasFlag(wxLC_EDIT_LABELS
) )
3011 m_renameTimer
->Start( 100, true );
3015 m_lastOnSame
= false;
3016 m_lineSelectSingleOnUp
= (size_t)-1;
3020 // This is necessary, because after a DnD operation in
3021 // from and to ourself, the up event is swallowed by the
3022 // DnD code. So on next non-up event (which means here and
3023 // now) m_lineSelectSingleOnUp should be reset.
3024 m_lineSelectSingleOnUp
= (size_t)-1;
3026 if (event
.RightDown())
3028 m_lineBeforeLastClicked
= m_lineLastClicked
;
3029 m_lineLastClicked
= current
;
3031 // If the item is already selected, do not update the selection.
3032 // Multi-selections should not be cleared if a selected item is clicked.
3033 if (!IsHighlighted(current
))
3035 HighlightAll(false);
3036 ChangeCurrent(current
);
3037 ReverseHighlight(m_current
);
3040 SendNotify( current
, wxEVT_COMMAND_LIST_ITEM_RIGHT_CLICK
, event
.GetPosition() );
3042 // Allow generation of context menu event
3045 else if (event
.MiddleDown())
3047 SendNotify( current
, wxEVT_COMMAND_LIST_ITEM_MIDDLE_CLICK
);
3049 else if ( event
.LeftDown() || forceClick
)
3051 m_lineBeforeLastClicked
= m_lineLastClicked
;
3052 m_lineLastClicked
= current
;
3054 size_t oldCurrent
= m_current
;
3055 bool oldWasSelected
= IsHighlighted(m_current
);
3057 bool cmdModifierDown
= event
.CmdDown();
3058 if ( IsSingleSel() || !(cmdModifierDown
|| event
.ShiftDown()) )
3060 if ( IsSingleSel() || !IsHighlighted(current
) )
3062 HighlightAll( false );
3064 ChangeCurrent(current
);
3066 ReverseHighlight(m_current
);
3068 else // multi sel & current is highlighted & no mod keys
3070 m_lineSelectSingleOnUp
= current
;
3071 ChangeCurrent(current
); // change focus
3074 else // multi sel & either ctrl or shift is down
3076 if (cmdModifierDown
)
3078 ChangeCurrent(current
);
3080 ReverseHighlight(m_current
);
3082 else if (event
.ShiftDown())
3084 ChangeCurrent(current
);
3086 size_t lineFrom
= oldCurrent
,
3089 if ( lineTo
< lineFrom
)
3092 lineFrom
= m_current
;
3095 HighlightLines(lineFrom
, lineTo
);
3097 else // !ctrl, !shift
3099 // test in the enclosing if should make it impossible
3100 wxFAIL_MSG( _T("how did we get here?") );
3104 if (m_current
!= oldCurrent
)
3105 RefreshLine( oldCurrent
);
3107 // forceClick is only set if the previous click was on another item
3108 m_lastOnSame
= !forceClick
&& (m_current
== oldCurrent
) && oldWasSelected
;
3112 void wxListMainWindow::MoveToItem(size_t item
)
3114 if ( item
== (size_t)-1 )
3117 wxRect rect
= GetLineRect(item
);
3119 int client_w
, client_h
;
3120 GetClientSize( &client_w
, &client_h
);
3122 const int hLine
= GetLineHeight();
3124 int view_x
= SCROLL_UNIT_X
* GetScrollPos( wxHORIZONTAL
);
3125 int view_y
= hLine
* GetScrollPos( wxVERTICAL
);
3127 if ( InReportView() )
3129 // the next we need the range of lines shown it might be different,
3130 // so recalculate it
3131 ResetVisibleLinesRange();
3133 if (rect
.y
< view_y
)
3134 Scroll( -1, rect
.y
/ hLine
);
3135 if (rect
.y
+ rect
.height
+ 5 > view_y
+ client_h
)
3136 Scroll( -1, (rect
.y
+ rect
.height
- client_h
+ hLine
) / hLine
);
3140 if (rect
.x
-view_x
< 5)
3141 Scroll( (rect
.x
- 5) / SCROLL_UNIT_X
, -1 );
3142 if (rect
.x
+ rect
.width
- 5 > view_x
+ client_w
)
3143 Scroll( (rect
.x
+ rect
.width
- client_w
+ SCROLL_UNIT_X
) / SCROLL_UNIT_X
, -1 );
3147 // ----------------------------------------------------------------------------
3148 // keyboard handling
3149 // ----------------------------------------------------------------------------
3151 void wxListMainWindow::OnArrowChar(size_t newCurrent
, const wxKeyEvent
& event
)
3153 wxCHECK_RET( newCurrent
< (size_t)GetItemCount(),
3154 _T("invalid item index in OnArrowChar()") );
3156 size_t oldCurrent
= m_current
;
3158 // in single selection we just ignore Shift as we can't select several
3160 if ( event
.ShiftDown() && !IsSingleSel() )
3162 ChangeCurrent(newCurrent
);
3164 // refresh the old focus to remove it
3165 RefreshLine( oldCurrent
);
3167 // select all the items between the old and the new one
3168 if ( oldCurrent
> newCurrent
)
3170 newCurrent
= oldCurrent
;
3171 oldCurrent
= m_current
;
3174 HighlightLines(oldCurrent
, newCurrent
);
3178 // all previously selected items are unselected unless ctrl is held
3179 if ( !event
.ControlDown() )
3180 HighlightAll(false);
3182 ChangeCurrent(newCurrent
);
3184 // refresh the old focus to remove it
3185 RefreshLine( oldCurrent
);
3187 if ( !event
.ControlDown() )
3189 HighlightLine( m_current
, true );
3193 RefreshLine( m_current
);
3198 void wxListMainWindow::OnKeyDown( wxKeyEvent
&event
)
3200 wxWindow
*parent
= GetParent();
3202 // propagate the key event upwards
3203 wxKeyEvent
ke( wxEVT_KEY_DOWN
);
3204 ke
.m_shiftDown
= event
.m_shiftDown
;
3205 ke
.m_controlDown
= event
.m_controlDown
;
3206 ke
.m_altDown
= event
.m_altDown
;
3207 ke
.m_metaDown
= event
.m_metaDown
;
3208 ke
.m_keyCode
= event
.m_keyCode
;
3211 ke
.SetEventObject( parent
);
3212 if (parent
->GetEventHandler()->ProcessEvent( ke
)) return;
3217 void wxListMainWindow::OnChar( wxKeyEvent
&event
)
3219 wxWindow
*parent
= GetParent();
3221 // send a list_key event up
3224 wxListEvent
le( wxEVT_COMMAND_LIST_KEY_DOWN
, GetParent()->GetId() );
3225 le
.m_itemIndex
= m_current
;
3226 GetLine(m_current
)->GetItem( 0, le
.m_item
);
3227 le
.m_code
= event
.GetKeyCode();
3228 le
.SetEventObject( parent
);
3229 parent
->GetEventHandler()->ProcessEvent( le
);
3232 // propagate the char event upwards
3233 wxKeyEvent
ke( wxEVT_CHAR
);
3234 ke
.m_shiftDown
= event
.m_shiftDown
;
3235 ke
.m_controlDown
= event
.m_controlDown
;
3236 ke
.m_altDown
= event
.m_altDown
;
3237 ke
.m_metaDown
= event
.m_metaDown
;
3238 ke
.m_keyCode
= event
.m_keyCode
;
3241 ke
.SetEventObject( parent
);
3242 if (parent
->GetEventHandler()->ProcessEvent( ke
)) return;
3244 if (event
.GetKeyCode() == WXK_TAB
)
3246 wxNavigationKeyEvent nevent
;
3247 nevent
.SetWindowChange( event
.ControlDown() );
3248 nevent
.SetDirection( !event
.ShiftDown() );
3249 nevent
.SetEventObject( GetParent()->GetParent() );
3250 nevent
.SetCurrentFocus( m_parent
);
3251 if (GetParent()->GetParent()->GetEventHandler()->ProcessEvent( nevent
))
3255 // no item -> nothing to do
3262 // don't use m_linesPerPage directly as it might not be computed yet
3263 const int pageSize
= GetCountPerPage();
3264 wxCHECK_RET( pageSize
, _T("should have non zero page size") );
3266 switch ( event
.GetKeyCode() )
3269 if ( m_current
> 0 )
3270 OnArrowChar( m_current
- 1, event
);
3274 if ( m_current
< (size_t)GetItemCount() - 1 )
3275 OnArrowChar( m_current
+ 1, event
);
3280 OnArrowChar( GetItemCount() - 1, event
);
3285 OnArrowChar( 0, event
);
3290 int steps
= InReportView() ? pageSize
- 1
3291 : m_current
% pageSize
;
3293 int index
= m_current
- steps
;
3297 OnArrowChar( index
, event
);
3303 int steps
= InReportView()
3305 : pageSize
- (m_current
% pageSize
) - 1;
3307 size_t index
= m_current
+ steps
;
3308 size_t count
= GetItemCount();
3309 if ( index
>= count
)
3312 OnArrowChar( index
, event
);
3317 if ( !InReportView() )
3319 int index
= m_current
- pageSize
;
3323 OnArrowChar( index
, event
);
3328 if ( !InReportView() )
3330 size_t index
= m_current
+ pageSize
;
3332 size_t count
= GetItemCount();
3333 if ( index
>= count
)
3336 OnArrowChar( index
, event
);
3341 if ( IsSingleSel() )
3343 SendNotify( m_current
, wxEVT_COMMAND_LIST_ITEM_ACTIVATED
);
3345 if ( IsHighlighted(m_current
) )
3347 // don't unselect the item in single selection mode
3350 //else: select it in ReverseHighlight() below if unselected
3353 ReverseHighlight(m_current
);
3358 SendNotify( m_current
, wxEVT_COMMAND_LIST_ITEM_ACTIVATED
);
3366 // ----------------------------------------------------------------------------
3368 // ----------------------------------------------------------------------------
3370 void wxListMainWindow::OnSetFocus( wxFocusEvent
&WXUNUSED(event
) )
3374 wxFocusEvent
event( wxEVT_SET_FOCUS
, GetParent()->GetId() );
3375 event
.SetEventObject( GetParent() );
3376 if ( GetParent()->GetEventHandler()->ProcessEvent( event
) )
3380 // wxGTK sends us EVT_SET_FOCUS events even if we had never got
3381 // EVT_KILL_FOCUS before which means that we finish by redrawing the items
3382 // which are already drawn correctly resulting in horrible flicker - avoid
3392 void wxListMainWindow::OnKillFocus( wxFocusEvent
&WXUNUSED(event
) )
3396 wxFocusEvent
event( wxEVT_KILL_FOCUS
, GetParent()->GetId() );
3397 event
.SetEventObject( GetParent() );
3398 if ( GetParent()->GetEventHandler()->ProcessEvent( event
) )
3406 void wxListMainWindow::DrawImage( int index
, wxDC
*dc
, int x
, int y
)
3408 if ( HasFlag(wxLC_ICON
) && (m_normal_image_list
))
3410 m_normal_image_list
->Draw( index
, *dc
, x
, y
, wxIMAGELIST_DRAW_TRANSPARENT
);
3412 else if ( HasFlag(wxLC_SMALL_ICON
) && (m_small_image_list
))
3414 m_small_image_list
->Draw( index
, *dc
, x
, y
, wxIMAGELIST_DRAW_TRANSPARENT
);
3416 else if ( HasFlag(wxLC_LIST
) && (m_small_image_list
))
3418 m_small_image_list
->Draw( index
, *dc
, x
, y
, wxIMAGELIST_DRAW_TRANSPARENT
);
3420 else if ( InReportView() && (m_small_image_list
))
3422 m_small_image_list
->Draw( index
, *dc
, x
, y
, wxIMAGELIST_DRAW_TRANSPARENT
);
3426 void wxListMainWindow::GetImageSize( int index
, int &width
, int &height
) const
3428 if ( HasFlag(wxLC_ICON
) && m_normal_image_list
)
3430 m_normal_image_list
->GetSize( index
, width
, height
);
3432 else if ( HasFlag(wxLC_SMALL_ICON
) && m_small_image_list
)
3434 m_small_image_list
->GetSize( index
, width
, height
);
3436 else if ( HasFlag(wxLC_LIST
) && m_small_image_list
)
3438 m_small_image_list
->GetSize( index
, width
, height
);
3440 else if ( InReportView() && m_small_image_list
)
3442 m_small_image_list
->GetSize( index
, width
, height
);
3451 int wxListMainWindow::GetTextLength( const wxString
&s
) const
3453 wxClientDC
dc( wxConstCast(this, wxListMainWindow
) );
3454 dc
.SetFont( GetFont() );
3457 dc
.GetTextExtent( s
, &lw
, NULL
);
3459 return lw
+ AUTOSIZE_COL_MARGIN
;
3462 void wxListMainWindow::SetImageList( wxImageListType
*imageList
, int which
)
3466 // calc the spacing from the icon size
3467 int width
= 0, height
= 0;
3469 if ((imageList
) && (imageList
->GetImageCount()) )
3470 imageList
->GetSize(0, width
, height
);
3472 if (which
== wxIMAGE_LIST_NORMAL
)
3474 m_normal_image_list
= imageList
;
3475 m_normal_spacing
= width
+ 8;
3478 if (which
== wxIMAGE_LIST_SMALL
)
3480 m_small_image_list
= imageList
;
3481 m_small_spacing
= width
+ 14;
3482 m_lineHeight
= 0; // ensure that the line height will be recalc'd
3486 void wxListMainWindow::SetItemSpacing( int spacing
, bool isSmall
)
3490 m_small_spacing
= spacing
;
3492 m_normal_spacing
= spacing
;
3495 int wxListMainWindow::GetItemSpacing( bool isSmall
)
3497 return isSmall
? m_small_spacing
: m_normal_spacing
;
3500 // ----------------------------------------------------------------------------
3502 // ----------------------------------------------------------------------------
3504 void wxListMainWindow::SetColumn( int col
, wxListItem
&item
)
3506 wxListHeaderDataList::compatibility_iterator node
= m_columns
.Item( col
);
3508 wxCHECK_RET( node
, _T("invalid column index in SetColumn") );
3510 if ( item
.m_width
== wxLIST_AUTOSIZE_USEHEADER
)
3511 item
.m_width
= GetTextLength( item
.m_text
);
3513 wxListHeaderData
*column
= node
->GetData();
3514 column
->SetItem( item
);
3516 wxListHeaderWindow
*headerWin
= GetListCtrl()->m_headerWin
;
3518 headerWin
->m_dirty
= true;
3522 // invalidate it as it has to be recalculated
3526 void wxListMainWindow::SetColumnWidth( int col
, int width
)
3528 wxCHECK_RET( col
>= 0 && col
< GetColumnCount(),
3529 _T("invalid column index") );
3531 wxCHECK_RET( InReportView(),
3532 _T("SetColumnWidth() can only be called in report mode.") );
3535 wxListHeaderWindow
*headerWin
= GetListCtrl()->m_headerWin
;
3537 headerWin
->m_dirty
= true;
3539 wxListHeaderDataList::compatibility_iterator node
= m_columns
.Item( col
);
3540 wxCHECK_RET( node
, _T("no column?") );
3542 wxListHeaderData
*column
= node
->GetData();
3544 size_t count
= GetItemCount();
3546 if (width
== wxLIST_AUTOSIZE_USEHEADER
)
3548 width
= GetTextLength(column
->GetText());
3550 else if ( width
== wxLIST_AUTOSIZE
)
3554 // TODO: determine the max width somehow...
3555 width
= WIDTH_COL_DEFAULT
;
3559 wxClientDC
dc(this);
3560 dc
.SetFont( GetFont() );
3562 int max
= AUTOSIZE_COL_MARGIN
;
3564 // if the cached column width isn't valid then recalculate it
3565 if (m_aColWidths
.Item(col
)->bNeedsUpdate
)
3567 for (size_t i
= 0; i
< count
; i
++)
3569 wxListLineData
*line
= GetLine( i
);
3570 wxListItemDataList::compatibility_iterator n
= line
->m_items
.Item( col
);
3572 wxCHECK_RET( n
, _T("no subitem?") );
3574 wxListItemData
*itemData
= n
->GetData();
3577 itemData
->GetItem(item
);
3578 int itemWidth
= GetItemWidthWithImage(&item
);
3579 if (itemWidth
> max
)
3583 m_aColWidths
.Item(col
)->bNeedsUpdate
= false;
3584 m_aColWidths
.Item(col
)->nMaxWidth
= max
;
3587 max
= m_aColWidths
.Item(col
)->nMaxWidth
;
3588 width
= max
+ AUTOSIZE_COL_MARGIN
;
3592 column
->SetWidth( width
);
3594 // invalidate it as it has to be recalculated
3598 int wxListMainWindow::GetHeaderWidth() const
3600 if ( !m_headerWidth
)
3602 wxListMainWindow
*self
= wxConstCast(this, wxListMainWindow
);
3604 size_t count
= GetColumnCount();
3605 for ( size_t col
= 0; col
< count
; col
++ )
3607 self
->m_headerWidth
+= GetColumnWidth(col
);
3611 return m_headerWidth
;
3614 void wxListMainWindow::GetColumn( int col
, wxListItem
&item
) const
3616 wxListHeaderDataList::compatibility_iterator node
= m_columns
.Item( col
);
3617 wxCHECK_RET( node
, _T("invalid column index in GetColumn") );
3619 wxListHeaderData
*column
= node
->GetData();
3620 column
->GetItem( item
);
3623 int wxListMainWindow::GetColumnWidth( int col
) const
3625 wxListHeaderDataList::compatibility_iterator node
= m_columns
.Item( col
);
3626 wxCHECK_MSG( node
, 0, _T("invalid column index") );
3628 wxListHeaderData
*column
= node
->GetData();
3629 return column
->GetWidth();
3632 // ----------------------------------------------------------------------------
3634 // ----------------------------------------------------------------------------
3636 void wxListMainWindow::SetItem( wxListItem
&item
)
3638 long id
= item
.m_itemId
;
3639 wxCHECK_RET( id
>= 0 && (size_t)id
< GetItemCount(),
3640 _T("invalid item index in SetItem") );
3644 wxListLineData
*line
= GetLine((size_t)id
);
3645 line
->SetItem( item
.m_col
, item
);
3647 // Set item state if user wants
3648 if ( item
.m_mask
& wxLIST_MASK_STATE
)
3649 SetItemState( item
.m_itemId
, item
.m_state
, item
.m_state
);
3653 // update the Max Width Cache if needed
3654 int width
= GetItemWidthWithImage(&item
);
3656 if (width
> m_aColWidths
.Item(item
.m_col
)->nMaxWidth
)
3657 m_aColWidths
.Item(item
.m_col
)->nMaxWidth
= width
;
3661 // update the item on screen
3663 GetItemRect(id
, rectItem
);
3664 RefreshRect(rectItem
);
3667 void wxListMainWindow::SetItemStateAll(long state
, long stateMask
)
3672 // first deal with selection
3673 if ( stateMask
& wxLIST_STATE_SELECTED
)
3675 // set/clear select state
3678 // optimized version for virtual listctrl.
3679 m_selStore
.SelectRange(0, GetItemCount() - 1, state
== wxLIST_STATE_SELECTED
);
3682 else if ( state
& wxLIST_STATE_SELECTED
)
3684 const long count
= GetItemCount();
3685 for( long i
= 0; i
< count
; i
++ )
3687 SetItemState( i
, wxLIST_STATE_SELECTED
, wxLIST_STATE_SELECTED
);
3693 // clear for non virtual (somewhat optimized by using GetNextItem())
3695 while ( (i
= GetNextItem(i
, wxLIST_NEXT_ALL
, wxLIST_STATE_SELECTED
)) != -1 )
3697 SetItemState( i
, 0, wxLIST_STATE_SELECTED
);
3702 if ( HasCurrent() && (state
== 0) && (stateMask
& wxLIST_STATE_FOCUSED
) )
3704 // unfocus all: only one item can be focussed, so clearing focus for
3705 // all items is simply clearing focus of the focussed item.
3706 SetItemState(m_current
, state
, stateMask
);
3708 //(setting focus to all items makes no sense, so it is not handled here.)
3711 void wxListMainWindow::SetItemState( long litem
, long state
, long stateMask
)
3715 SetItemStateAll(state
, stateMask
);
3719 wxCHECK_RET( litem
>= 0 && (size_t)litem
< GetItemCount(),
3720 _T("invalid list ctrl item index in SetItem") );
3722 size_t oldCurrent
= m_current
;
3723 size_t item
= (size_t)litem
; // safe because of the check above
3725 // do we need to change the focus?
3726 if ( stateMask
& wxLIST_STATE_FOCUSED
)
3728 if ( state
& wxLIST_STATE_FOCUSED
)
3730 // don't do anything if this item is already focused
3731 if ( item
!= m_current
)
3733 ChangeCurrent(item
);
3735 if ( oldCurrent
!= (size_t)-1 )
3737 if ( IsSingleSel() )
3739 HighlightLine(oldCurrent
, false);
3742 RefreshLine(oldCurrent
);
3745 RefreshLine( m_current
);
3750 // don't do anything if this item is not focused
3751 if ( item
== m_current
)
3755 if ( IsSingleSel() )
3757 // we must unselect the old current item as well or we
3758 // might end up with more than one selected item in a
3759 // single selection control
3760 HighlightLine(oldCurrent
, false);
3763 RefreshLine( oldCurrent
);
3768 // do we need to change the selection state?
3769 if ( stateMask
& wxLIST_STATE_SELECTED
)
3771 bool on
= (state
& wxLIST_STATE_SELECTED
) != 0;
3773 if ( IsSingleSel() )
3777 // selecting the item also makes it the focused one in the
3779 if ( m_current
!= item
)
3781 ChangeCurrent(item
);
3783 if ( oldCurrent
!= (size_t)-1 )
3785 HighlightLine( oldCurrent
, false );
3786 RefreshLine( oldCurrent
);
3792 // only the current item may be selected anyhow
3793 if ( item
!= m_current
)
3798 if ( HighlightLine(item
, on
) )
3805 int wxListMainWindow::GetItemState( long item
, long stateMask
) const
3807 wxCHECK_MSG( item
>= 0 && (size_t)item
< GetItemCount(), 0,
3808 _T("invalid list ctrl item index in GetItemState()") );
3810 int ret
= wxLIST_STATE_DONTCARE
;
3812 if ( stateMask
& wxLIST_STATE_FOCUSED
)
3814 if ( (size_t)item
== m_current
)
3815 ret
|= wxLIST_STATE_FOCUSED
;
3818 if ( stateMask
& wxLIST_STATE_SELECTED
)
3820 if ( IsHighlighted(item
) )
3821 ret
|= wxLIST_STATE_SELECTED
;
3827 void wxListMainWindow::GetItem( wxListItem
&item
) const
3829 wxCHECK_RET( item
.m_itemId
>= 0 && (size_t)item
.m_itemId
< GetItemCount(),
3830 _T("invalid item index in GetItem") );
3832 wxListLineData
*line
= GetLine((size_t)item
.m_itemId
);
3833 line
->GetItem( item
.m_col
, item
);
3835 // Get item state if user wants it
3836 if ( item
.m_mask
& wxLIST_MASK_STATE
)
3837 item
.m_state
= GetItemState( item
.m_itemId
, wxLIST_STATE_SELECTED
|
3838 wxLIST_STATE_FOCUSED
);
3841 // ----------------------------------------------------------------------------
3843 // ----------------------------------------------------------------------------
3845 size_t wxListMainWindow::GetItemCount() const
3847 return IsVirtual() ? m_countVirt
: m_lines
.GetCount();
3850 void wxListMainWindow::SetItemCount(long count
)
3852 m_selStore
.SetItemCount(count
);
3853 m_countVirt
= count
;
3855 ResetVisibleLinesRange();
3857 // scrollbars must be reset
3861 int wxListMainWindow::GetSelectedItemCount() const
3863 // deal with the quick case first
3864 if ( IsSingleSel() )
3865 return HasCurrent() ? IsHighlighted(m_current
) : false;
3867 // virtual controls remmebers all its selections itself
3869 return m_selStore
.GetSelectedCount();
3871 // TODO: we probably should maintain the number of items selected even for
3872 // non virtual controls as enumerating all lines is really slow...
3873 size_t countSel
= 0;
3874 size_t count
= GetItemCount();
3875 for ( size_t line
= 0; line
< count
; line
++ )
3877 if ( GetLine(line
)->IsHighlighted() )
3884 // ----------------------------------------------------------------------------
3885 // item position/size
3886 // ----------------------------------------------------------------------------
3888 wxRect
wxListMainWindow::GetViewRect() const
3890 wxASSERT_MSG( !HasFlag(wxLC_REPORT
| wxLC_LIST
),
3891 _T("wxListCtrl::GetViewRect() only works in icon mode") );
3893 // we need to find the longest/tallest label
3894 wxCoord xMax
= 0, yMax
= 0;
3895 const int count
= GetItemCount();
3898 for ( int i
= 0; i
< count
; i
++ )
3903 wxCoord x
= r
.GetRight(),
3913 // some fudge needed to make it look prettier
3914 xMax
+= 2 * EXTRA_BORDER_X
;
3915 yMax
+= 2 * EXTRA_BORDER_Y
;
3917 // account for the scrollbars if necessary
3918 const wxSize sizeAll
= GetClientSize();
3919 if ( xMax
> sizeAll
.x
)
3920 yMax
+= wxSystemSettings::GetMetric(wxSYS_HSCROLL_Y
);
3921 if ( yMax
> sizeAll
.y
)
3922 xMax
+= wxSystemSettings::GetMetric(wxSYS_VSCROLL_X
);
3924 return wxRect(0, 0, xMax
, yMax
);
3927 void wxListMainWindow::GetItemRect( long index
, wxRect
&rect
) const
3929 wxCHECK_RET( index
>= 0 && (size_t)index
< GetItemCount(),
3930 _T("invalid index in GetItemRect") );
3932 // ensure that we're laid out, otherwise we could return nonsense
3935 wxConstCast(this, wxListMainWindow
)->
3936 RecalculatePositions(true /* no refresh */);
3939 rect
= GetLineRect((size_t)index
);
3941 CalcScrolledPosition(rect
.x
, rect
.y
, &rect
.x
, &rect
.y
);
3944 bool wxListMainWindow::GetItemPosition(long item
, wxPoint
& pos
) const
3947 GetItemRect(item
, rect
);
3955 // ----------------------------------------------------------------------------
3956 // geometry calculation
3957 // ----------------------------------------------------------------------------
3959 void wxListMainWindow::RecalculatePositions(bool noRefresh
)
3961 wxClientDC
dc( this );
3962 dc
.SetFont( GetFont() );
3964 const size_t count
= GetItemCount();
3967 if ( HasFlag(wxLC_ICON
) )
3968 iconSpacing
= m_normal_spacing
;
3969 else if ( HasFlag(wxLC_SMALL_ICON
) )
3970 iconSpacing
= m_small_spacing
;
3974 // Note that we do not call GetClientSize() here but
3975 // GetSize() and subtract the border size for sunken
3976 // borders manually. This is technically incorrect,
3977 // but we need to know the client area's size WITHOUT
3978 // scrollbars here. Since we don't know if there are
3979 // any scrollbars, we use GetSize() instead. Another
3980 // solution would be to call SetScrollbars() here to
3981 // remove the scrollbars and call GetClientSize() then,
3982 // but this might result in flicker and - worse - will
3983 // reset the scrollbars to 0 which is not good at all
3984 // if you resize a dialog/window, but don't want to
3985 // reset the window scrolling. RR.
3986 // Furthermore, we actually do NOT subtract the border
3987 // width as 2 pixels is just the extra space which we
3988 // need around the actual content in the window. Other-
3989 // wise the text would e.g. touch the upper border. RR.
3992 GetSize( &clientWidth
, &clientHeight
);
3994 const int lineHeight
= GetLineHeight();
3996 if ( InReportView() )
3998 // all lines have the same height and we scroll one line per step
3999 int entireHeight
= count
* lineHeight
+ LINE_SPACING
;
4001 m_linesPerPage
= clientHeight
/ lineHeight
;
4003 ResetVisibleLinesRange();
4005 SetScrollbars( SCROLL_UNIT_X
, lineHeight
,
4006 GetHeaderWidth() / SCROLL_UNIT_X
,
4007 (entireHeight
+ lineHeight
- 1) / lineHeight
,
4008 GetScrollPos(wxHORIZONTAL
),
4009 GetScrollPos(wxVERTICAL
),
4014 // we have 3 different layout strategies: either layout all items
4015 // horizontally/vertically (wxLC_ALIGN_XXX styles explicitly given) or
4016 // to arrange them in top to bottom, left to right (don't ask me why
4017 // not the other way round...) order
4018 if ( HasFlag(wxLC_ALIGN_LEFT
| wxLC_ALIGN_TOP
) )
4020 int x
= EXTRA_BORDER_X
;
4021 int y
= EXTRA_BORDER_Y
;
4023 wxCoord widthMax
= 0;
4026 for ( i
= 0; i
< count
; i
++ )
4028 wxListLineData
*line
= GetLine(i
);
4029 line
->CalculateSize( &dc
, iconSpacing
);
4030 line
->SetPosition( x
, y
, iconSpacing
);
4032 wxSize sizeLine
= GetLineSize(i
);
4034 if ( HasFlag(wxLC_ALIGN_TOP
) )
4036 if ( sizeLine
.x
> widthMax
)
4037 widthMax
= sizeLine
.x
;
4041 else // wxLC_ALIGN_LEFT
4043 x
+= sizeLine
.x
+ MARGIN_BETWEEN_ROWS
;
4047 if ( HasFlag(wxLC_ALIGN_TOP
) )
4049 // traverse the items again and tweak their sizes so that they are
4050 // all the same in a row
4051 for ( i
= 0; i
< count
; i
++ )
4053 wxListLineData
*line
= GetLine(i
);
4054 line
->m_gi
->ExtendWidth(widthMax
);
4062 (x
+ SCROLL_UNIT_X
) / SCROLL_UNIT_X
,
4063 (y
+ lineHeight
) / lineHeight
,
4064 GetScrollPos( wxHORIZONTAL
),
4065 GetScrollPos( wxVERTICAL
),
4069 else // "flowed" arrangement, the most complicated case
4071 // at first we try without any scrollbars, if the items don't fit into
4072 // the window, we recalculate after subtracting the space taken by the
4075 int entireWidth
= 0;
4077 for (int tries
= 0; tries
< 2; tries
++)
4079 entireWidth
= 2 * EXTRA_BORDER_X
;
4083 // Now we have decided that the items do not fit into the
4084 // client area, so we need a scrollbar
4085 entireWidth
+= SCROLL_UNIT_X
;
4088 int x
= EXTRA_BORDER_X
;
4089 int y
= EXTRA_BORDER_Y
;
4090 int maxWidthInThisRow
= 0;
4093 int currentlyVisibleLines
= 0;
4095 for (size_t i
= 0; i
< count
; i
++)
4097 currentlyVisibleLines
++;
4098 wxListLineData
*line
= GetLine( i
);
4099 line
->CalculateSize( &dc
, iconSpacing
);
4100 line
->SetPosition( x
, y
, iconSpacing
);
4102 wxSize sizeLine
= GetLineSize( i
);
4104 if ( maxWidthInThisRow
< sizeLine
.x
)
4105 maxWidthInThisRow
= sizeLine
.x
;
4108 if (currentlyVisibleLines
> m_linesPerPage
)
4109 m_linesPerPage
= currentlyVisibleLines
;
4111 if ( y
+ sizeLine
.y
>= clientHeight
)
4113 currentlyVisibleLines
= 0;
4115 maxWidthInThisRow
+= MARGIN_BETWEEN_ROWS
;
4116 x
+= maxWidthInThisRow
;
4117 entireWidth
+= maxWidthInThisRow
;
4118 maxWidthInThisRow
= 0;
4121 // We have reached the last item.
4122 if ( i
== count
- 1 )
4123 entireWidth
+= maxWidthInThisRow
;
4125 if ( (tries
== 0) &&
4126 (entireWidth
+ SCROLL_UNIT_X
> clientWidth
) )
4128 clientHeight
-= wxSystemSettings::
4129 GetMetric(wxSYS_HSCROLL_Y
);
4134 if ( i
== count
- 1 )
4135 tries
= 1; // Everything fits, no second try required.
4143 (entireWidth
+ SCROLL_UNIT_X
) / SCROLL_UNIT_X
,
4145 GetScrollPos( wxHORIZONTAL
),
4154 // FIXME: why should we call it from here?
4161 void wxListMainWindow::RefreshAll()
4166 wxListHeaderWindow
*headerWin
= GetListCtrl()->m_headerWin
;
4167 if ( headerWin
&& headerWin
->m_dirty
)
4169 headerWin
->m_dirty
= false;
4170 headerWin
->Refresh();
4174 void wxListMainWindow::UpdateCurrent()
4176 if ( !HasCurrent() && !IsEmpty() )
4180 long wxListMainWindow::GetNextItem( long item
,
4181 int WXUNUSED(geometry
),
4185 max
= GetItemCount();
4186 wxCHECK_MSG( (ret
== -1) || (ret
< max
), -1,
4187 _T("invalid listctrl index in GetNextItem()") );
4189 // notice that we start with the next item (or the first one if item == -1)
4190 // and this is intentional to allow writing a simple loop to iterate over
4191 // all selected items
4194 // this is not an error because the index was OK initially,
4195 // just no such item
4202 size_t count
= GetItemCount();
4203 for ( size_t line
= (size_t)ret
; line
< count
; line
++ )
4205 if ( (state
& wxLIST_STATE_FOCUSED
) && (line
== m_current
) )
4208 if ( (state
& wxLIST_STATE_SELECTED
) && IsHighlighted(line
) )
4215 // ----------------------------------------------------------------------------
4217 // ----------------------------------------------------------------------------
4219 void wxListMainWindow::DeleteItem( long lindex
)
4221 size_t count
= GetItemCount();
4223 wxCHECK_RET( (lindex
>= 0) && ((size_t)lindex
< count
),
4224 _T("invalid item index in DeleteItem") );
4226 size_t index
= (size_t)lindex
;
4228 // we don't need to adjust the index for the previous items
4229 if ( HasCurrent() && m_current
>= index
)
4231 // if the current item is being deleted, we want the next one to
4232 // become selected - unless there is no next one - so don't adjust
4233 // m_current in this case
4234 if ( m_current
!= index
|| m_current
== count
- 1 )
4238 if ( InReportView() )
4240 // mark the Column Max Width cache as dirty if the items in the line
4241 // we're deleting contain the Max Column Width
4242 wxListLineData
* const line
= GetLine(index
);
4243 wxListItemDataList::compatibility_iterator n
;
4244 wxListItemData
*itemData
;
4248 for (size_t i
= 0; i
< m_columns
.GetCount(); i
++)
4250 n
= line
->m_items
.Item( i
);
4251 itemData
= n
->GetData();
4252 itemData
->GetItem(item
);
4254 itemWidth
= GetItemWidthWithImage(&item
);
4256 if (itemWidth
>= m_aColWidths
.Item(i
)->nMaxWidth
)
4257 m_aColWidths
.Item(i
)->bNeedsUpdate
= true;
4260 ResetVisibleLinesRange();
4266 m_selStore
.OnItemDelete(index
);
4270 m_lines
.RemoveAt( index
);
4273 // we need to refresh the (vert) scrollbar as the number of items changed
4276 SendNotify( index
, wxEVT_COMMAND_LIST_DELETE_ITEM
);
4278 RefreshAfter(index
);
4281 void wxListMainWindow::DeleteColumn( int col
)
4283 wxListHeaderDataList::compatibility_iterator node
= m_columns
.Item( col
);
4285 wxCHECK_RET( node
, wxT("invalid column index in DeleteColumn()") );
4288 delete node
->GetData();
4289 m_columns
.Erase( node
);
4293 // update all the items
4294 for ( size_t i
= 0; i
< m_lines
.GetCount(); i
++ )
4296 wxListLineData
* const line
= GetLine(i
);
4297 wxListItemDataList::compatibility_iterator n
= line
->m_items
.Item( col
);
4298 delete n
->GetData();
4299 line
->m_items
.Erase(n
);
4303 if ( InReportView() ) // we only cache max widths when in Report View
4305 delete m_aColWidths
.Item(col
);
4306 m_aColWidths
.RemoveAt(col
);
4309 // invalidate it as it has to be recalculated
4313 void wxListMainWindow::DoDeleteAllItems()
4316 // nothing to do - in particular, don't send the event
4321 // to make the deletion of all items faster, we don't send the
4322 // notifications for each item deletion in this case but only one event
4323 // for all of them: this is compatible with wxMSW and documented in
4324 // DeleteAllItems() description
4326 wxListEvent
event( wxEVT_COMMAND_LIST_DELETE_ALL_ITEMS
, GetParent()->GetId() );
4327 event
.SetEventObject( GetParent() );
4328 GetParent()->GetEventHandler()->ProcessEvent( event
);
4336 if ( InReportView() )
4338 ResetVisibleLinesRange();
4339 for (size_t i
= 0; i
< m_aColWidths
.GetCount(); i
++)
4341 m_aColWidths
.Item(i
)->bNeedsUpdate
= true;
4348 void wxListMainWindow::DeleteAllItems()
4352 RecalculatePositions();
4355 void wxListMainWindow::DeleteEverything()
4357 WX_CLEAR_LIST(wxListHeaderDataList
, m_columns
);
4358 WX_CLEAR_ARRAY(m_aColWidths
);
4363 // ----------------------------------------------------------------------------
4364 // scanning for an item
4365 // ----------------------------------------------------------------------------
4367 void wxListMainWindow::EnsureVisible( long index
)
4369 wxCHECK_RET( index
>= 0 && (size_t)index
< GetItemCount(),
4370 _T("invalid index in EnsureVisible") );
4372 // We have to call this here because the label in question might just have
4373 // been added and its position is not known yet
4375 RecalculatePositions(true /* no refresh */);
4377 MoveToItem((size_t)index
);
4380 long wxListMainWindow::FindItem(long start
, const wxString
& str
, bool WXUNUSED(partial
) )
4387 size_t count
= GetItemCount();
4388 for ( size_t i
= (size_t)pos
; i
< count
; i
++ )
4390 wxListLineData
*line
= GetLine(i
);
4391 if ( line
->GetText(0) == tmp
)
4398 long wxListMainWindow::FindItem(long start
, wxUIntPtr data
)
4404 size_t count
= GetItemCount();
4405 for (size_t i
= (size_t)pos
; i
< count
; i
++)
4407 wxListLineData
*line
= GetLine(i
);
4409 line
->GetItem( 0, item
);
4410 if (item
.m_data
== data
)
4417 long wxListMainWindow::FindItem( const wxPoint
& pt
)
4420 GetVisibleLinesRange( &topItem
, NULL
);
4423 GetItemPosition( GetItemCount() - 1, p
);
4427 long id
= (long)floor( pt
.y
* double(GetItemCount() - topItem
- 1) / p
.y
+ topItem
);
4428 if ( id
>= 0 && id
< (long)GetItemCount() )
4434 long wxListMainWindow::HitTest( int x
, int y
, int &flags
)
4436 CalcUnscrolledPosition( x
, y
, &x
, &y
);
4438 size_t count
= GetItemCount();
4440 if ( InReportView() )
4442 size_t current
= y
/ GetLineHeight();
4443 if ( current
< count
)
4445 flags
= HitTestLine(current
, x
, y
);
4452 // TODO: optimize it too! this is less simple than for report view but
4453 // enumerating all items is still not a way to do it!!
4454 for ( size_t current
= 0; current
< count
; current
++ )
4456 flags
= HitTestLine(current
, x
, y
);
4465 // ----------------------------------------------------------------------------
4467 // ----------------------------------------------------------------------------
4469 void wxListMainWindow::InsertItem( wxListItem
&item
)
4471 wxASSERT_MSG( !IsVirtual(), _T("can't be used with virtual control") );
4473 int count
= GetItemCount();
4474 wxCHECK_RET( item
.m_itemId
>= 0, _T("invalid item index") );
4476 if (item
.m_itemId
> count
)
4477 item
.m_itemId
= count
;
4479 size_t id
= item
.m_itemId
;
4483 if ( InReportView() )
4485 ResetVisibleLinesRange();
4487 // calculate the width of the item and adjust the max column width
4488 wxColWidthInfo
*pWidthInfo
= m_aColWidths
.Item(item
.GetColumn());
4489 int width
= GetItemWidthWithImage(&item
);
4490 item
.SetWidth(width
);
4491 if (width
> pWidthInfo
->nMaxWidth
)
4492 pWidthInfo
->nMaxWidth
= width
;
4495 wxListLineData
*line
= new wxListLineData(this);
4497 line
->SetItem( item
.m_col
, item
);
4499 m_lines
.Insert( line
, id
);
4503 // If an item is selected at or below the point of insertion, we need to
4504 // increment the member variables because the current row's index has gone
4506 if ( HasCurrent() && m_current
>= id
)
4509 SendNotify(id
, wxEVT_COMMAND_LIST_INSERT_ITEM
);
4511 RefreshLines(id
, GetItemCount() - 1);
4514 void wxListMainWindow::InsertColumn( long col
, wxListItem
&item
)
4517 if ( InReportView() )
4519 if (item
.m_width
== wxLIST_AUTOSIZE_USEHEADER
)
4520 item
.m_width
= GetTextLength( item
.m_text
);
4522 wxListHeaderData
*column
= new wxListHeaderData( item
);
4523 wxColWidthInfo
*colWidthInfo
= new wxColWidthInfo();
4525 bool insert
= (col
>= 0) && ((size_t)col
< m_columns
.GetCount());
4528 wxListHeaderDataList::compatibility_iterator
4529 node
= m_columns
.Item( col
);
4530 m_columns
.Insert( node
, column
);
4531 m_aColWidths
.Insert( colWidthInfo
, col
);
4535 m_columns
.Append( column
);
4536 m_aColWidths
.Add( colWidthInfo
);
4541 // update all the items
4542 for ( size_t i
= 0; i
< m_lines
.GetCount(); i
++ )
4544 wxListLineData
* const line
= GetLine(i
);
4545 wxListItemData
* const data
= new wxListItemData(this);
4547 line
->m_items
.Insert(col
, data
);
4549 line
->m_items
.Append(data
);
4553 // invalidate it as it has to be recalculated
4558 int wxListMainWindow::GetItemWidthWithImage(wxListItem
* item
)
4561 wxClientDC
dc(this);
4563 dc
.SetFont( GetFont() );
4565 if (item
->GetImage() != -1)
4568 GetImageSize( item
->GetImage(), ix
, iy
);
4572 if (!item
->GetText().empty())
4575 dc
.GetTextExtent( item
->GetText(), &w
, NULL
);
4582 // ----------------------------------------------------------------------------
4584 // ----------------------------------------------------------------------------
4586 wxListCtrlCompare list_ctrl_compare_func_2
;
4587 long list_ctrl_compare_data
;
4589 int LINKAGEMODE
list_ctrl_compare_func_1( wxListLineData
**arg1
, wxListLineData
**arg2
)
4591 wxListLineData
*line1
= *arg1
;
4592 wxListLineData
*line2
= *arg2
;
4594 line1
->GetItem( 0, item
);
4595 wxUIntPtr data1
= item
.m_data
;
4596 line2
->GetItem( 0, item
);
4597 wxUIntPtr data2
= item
.m_data
;
4598 return list_ctrl_compare_func_2( data1
, data2
, list_ctrl_compare_data
);
4601 void wxListMainWindow::SortItems( wxListCtrlCompare fn
, long data
)
4603 list_ctrl_compare_func_2
= fn
;
4604 list_ctrl_compare_data
= data
;
4605 m_lines
.Sort( list_ctrl_compare_func_1
);
4609 // ----------------------------------------------------------------------------
4611 // ----------------------------------------------------------------------------
4613 void wxListMainWindow::OnScroll(wxScrollWinEvent
& event
)
4615 // update our idea of which lines are shown when we redraw the window the
4617 ResetVisibleLinesRange();
4620 #if ( defined(__WXGTK__) || defined(__WXMAC__) ) && !defined(__WXUNIVERSAL__)
4621 wxScrolledWindow::OnScroll(event
);
4623 HandleOnScroll( event
);
4626 if ( event
.GetOrientation() == wxHORIZONTAL
&& HasHeader() )
4628 wxGenericListCtrl
* lc
= GetListCtrl();
4629 wxCHECK_RET( lc
, _T("no listctrl window?") );
4631 lc
->m_headerWin
->Refresh();
4632 lc
->m_headerWin
->Update();
4636 int wxListMainWindow::GetCountPerPage() const
4638 if ( !m_linesPerPage
)
4640 wxConstCast(this, wxListMainWindow
)->
4641 m_linesPerPage
= GetClientSize().y
/ GetLineHeight();
4644 return m_linesPerPage
;
4647 void wxListMainWindow::GetVisibleLinesRange(size_t *from
, size_t *to
)
4649 wxASSERT_MSG( InReportView(), _T("this is for report mode only") );
4651 if ( m_lineFrom
== (size_t)-1 )
4653 size_t count
= GetItemCount();
4656 m_lineFrom
= GetScrollPos(wxVERTICAL
);
4658 // this may happen if SetScrollbars() hadn't been called yet
4659 if ( m_lineFrom
>= count
)
4660 m_lineFrom
= count
- 1;
4662 // we redraw one extra line but this is needed to make the redrawing
4663 // logic work when there is a fractional number of lines on screen
4664 m_lineTo
= m_lineFrom
+ m_linesPerPage
;
4665 if ( m_lineTo
>= count
)
4666 m_lineTo
= count
- 1;
4668 else // empty control
4671 m_lineTo
= (size_t)-1;
4675 wxASSERT_MSG( IsEmpty() ||
4676 (m_lineFrom
<= m_lineTo
&& m_lineTo
< GetItemCount()),
4677 _T("GetVisibleLinesRange() returns incorrect result") );
4685 // -------------------------------------------------------------------------------------
4686 // wxGenericListCtrl
4687 // -------------------------------------------------------------------------------------
4689 IMPLEMENT_DYNAMIC_CLASS(wxGenericListCtrl
, wxControl
)
4691 BEGIN_EVENT_TABLE(wxGenericListCtrl
,wxControl
)
4692 EVT_SIZE(wxGenericListCtrl::OnSize
)
4695 wxGenericListCtrl::wxGenericListCtrl()
4697 m_imageListNormal
= (wxImageListType
*) NULL
;
4698 m_imageListSmall
= (wxImageListType
*) NULL
;
4699 m_imageListState
= (wxImageListType
*) NULL
;
4701 m_ownsImageListNormal
=
4702 m_ownsImageListSmall
=
4703 m_ownsImageListState
= false;
4705 m_mainWin
= (wxListMainWindow
*) NULL
;
4706 m_headerWin
= (wxListHeaderWindow
*) NULL
;
4710 wxGenericListCtrl::~wxGenericListCtrl()
4712 if (m_ownsImageListNormal
)
4713 delete m_imageListNormal
;
4714 if (m_ownsImageListSmall
)
4715 delete m_imageListSmall
;
4716 if (m_ownsImageListState
)
4717 delete m_imageListState
;
4720 void wxGenericListCtrl::CalculateAndSetHeaderHeight()
4726 GetThemeMetric( kThemeMetricListHeaderHeight
, &h
);
4728 // we use 'g' to get the descent, too
4730 m_headerWin
->GetTextExtent(wxT("Hg"), &w
, &h
, &d
);
4731 h
+= d
+ 2 * HEADER_OFFSET_Y
+ EXTRA_HEIGHT
;
4734 // only update if changed
4735 if ( h
!= m_headerHeight
)
4740 ResizeReportView(true);
4741 else //why is this needed if it doesn't have a header?
4742 m_headerWin
->SetSize(m_headerWin
->GetSize().x
, m_headerHeight
);
4747 void wxGenericListCtrl::CreateHeaderWindow()
4749 m_headerWin
= new wxListHeaderWindow
4751 this, wxID_ANY
, m_mainWin
,
4753 wxSize(GetClientSize().x
, m_headerHeight
),
4756 CalculateAndSetHeaderHeight();
4759 bool wxGenericListCtrl::Create(wxWindow
*parent
,
4764 const wxValidator
&validator
,
4765 const wxString
&name
)
4769 m_imageListState
= (wxImageListType
*) NULL
;
4770 m_ownsImageListNormal
=
4771 m_ownsImageListSmall
=
4772 m_ownsImageListState
= false;
4774 m_mainWin
= (wxListMainWindow
*) NULL
;
4775 m_headerWin
= (wxListHeaderWindow
*) NULL
;
4779 if ( !(style
& wxLC_MASK_TYPE
) )
4781 style
= style
| wxLC_LIST
;
4784 if ( !wxControl::Create( parent
, id
, pos
, size
, style
, validator
, name
) )
4787 // don't create the inner window with the border
4788 style
&= ~wxBORDER_MASK
;
4790 m_mainWin
= new wxListMainWindow( this, wxID_ANY
, wxPoint(0, 0), size
, style
);
4792 #ifdef __WXMAC_CARBON__
4793 // Human Interface Guidelines ask us for a special font in this case
4794 if ( GetWindowVariant() == wxWINDOW_VARIANT_NORMAL
)
4797 font
.MacCreateThemeFont( kThemeViewsFont
);
4802 if ( InReportView() )
4804 CreateHeaderWindow();
4806 #ifdef __WXMAC_CARBON__
4810 font
.MacCreateThemeFont( kThemeSmallSystemFont
);
4811 m_headerWin
->SetFont( font
);
4812 CalculateAndSetHeaderHeight();
4816 if ( HasFlag(wxLC_NO_HEADER
) )
4817 // VZ: why do we create it at all then?
4818 m_headerWin
->Show( false );
4826 void wxGenericListCtrl::SetSingleStyle( long style
, bool add
)
4828 wxASSERT_MSG( !(style
& wxLC_VIRTUAL
),
4829 _T("wxLC_VIRTUAL can't be [un]set") );
4831 long flag
= GetWindowStyle();
4835 if (style
& wxLC_MASK_TYPE
)
4836 flag
&= ~(wxLC_MASK_TYPE
| wxLC_VIRTUAL
);
4837 if (style
& wxLC_MASK_ALIGN
)
4838 flag
&= ~wxLC_MASK_ALIGN
;
4839 if (style
& wxLC_MASK_SORT
)
4840 flag
&= ~wxLC_MASK_SORT
;
4848 SetWindowStyleFlag( flag
);
4851 void wxGenericListCtrl::SetWindowStyleFlag( long flag
)
4855 m_mainWin
->DeleteEverything();
4857 // has the header visibility changed?
4858 bool hasHeader
= HasHeader();
4859 bool willHaveHeader
= (flag
& wxLC_REPORT
) && !(flag
& wxLC_NO_HEADER
);
4861 if ( hasHeader
!= willHaveHeader
)
4868 // don't delete, just hide, as we can reuse it later
4869 m_headerWin
->Show(false);
4871 //else: nothing to do
4873 else // must show header
4877 CreateHeaderWindow();
4879 else // already have it, just show
4881 m_headerWin
->Show( true );
4885 ResizeReportView(willHaveHeader
);
4889 wxWindow::SetWindowStyleFlag( flag
);
4892 bool wxGenericListCtrl::GetColumn(int col
, wxListItem
&item
) const
4894 m_mainWin
->GetColumn( col
, item
);
4898 bool wxGenericListCtrl::SetColumn( int col
, wxListItem
& item
)
4900 m_mainWin
->SetColumn( col
, item
);
4904 int wxGenericListCtrl::GetColumnWidth( int col
) const
4906 return m_mainWin
->GetColumnWidth( col
);
4909 bool wxGenericListCtrl::SetColumnWidth( int col
, int width
)
4911 m_mainWin
->SetColumnWidth( col
, width
);
4915 int wxGenericListCtrl::GetCountPerPage() const
4917 return m_mainWin
->GetCountPerPage(); // different from Windows ?
4920 bool wxGenericListCtrl::GetItem( wxListItem
&info
) const
4922 m_mainWin
->GetItem( info
);
4926 bool wxGenericListCtrl::SetItem( wxListItem
&info
)
4928 m_mainWin
->SetItem( info
);
4932 long wxGenericListCtrl::SetItem( long index
, int col
, const wxString
& label
, int imageId
)
4935 info
.m_text
= label
;
4936 info
.m_mask
= wxLIST_MASK_TEXT
;
4937 info
.m_itemId
= index
;
4941 info
.m_image
= imageId
;
4942 info
.m_mask
|= wxLIST_MASK_IMAGE
;
4945 m_mainWin
->SetItem(info
);
4949 int wxGenericListCtrl::GetItemState( long item
, long stateMask
) const
4951 return m_mainWin
->GetItemState( item
, stateMask
);
4954 bool wxGenericListCtrl::SetItemState( long item
, long state
, long stateMask
)
4956 m_mainWin
->SetItemState( item
, state
, stateMask
);
4961 wxGenericListCtrl::SetItemImage( long item
, int image
, int WXUNUSED(selImage
) )
4963 return SetItemColumnImage(item
, 0, image
);
4967 wxGenericListCtrl::SetItemColumnImage( long item
, long column
, int image
)
4970 info
.m_image
= image
;
4971 info
.m_mask
= wxLIST_MASK_IMAGE
;
4972 info
.m_itemId
= item
;
4973 info
.m_col
= column
;
4974 m_mainWin
->SetItem( info
);
4978 wxString
wxGenericListCtrl::GetItemText( long item
) const
4980 return m_mainWin
->GetItemText(item
);
4983 void wxGenericListCtrl::SetItemText( long item
, const wxString
& str
)
4985 m_mainWin
->SetItemText(item
, str
);
4988 wxUIntPtr
wxGenericListCtrl::GetItemData( long item
) const
4991 info
.m_mask
= wxLIST_MASK_DATA
;
4992 info
.m_itemId
= item
;
4993 m_mainWin
->GetItem( info
);
4997 bool wxGenericListCtrl::SetItemData( long item
, long data
)
5000 info
.m_mask
= wxLIST_MASK_DATA
;
5001 info
.m_itemId
= item
;
5003 m_mainWin
->SetItem( info
);
5007 wxRect
wxGenericListCtrl::GetViewRect() const
5009 return m_mainWin
->GetViewRect();
5012 bool wxGenericListCtrl::GetItemRect( long item
, wxRect
&rect
, int WXUNUSED(code
) ) const
5014 m_mainWin
->GetItemRect( item
, rect
);
5015 if ( m_mainWin
->HasHeader() )
5016 rect
.y
+= m_headerHeight
+ 1;
5020 bool wxGenericListCtrl::GetItemPosition( long item
, wxPoint
& pos
) const
5022 m_mainWin
->GetItemPosition( item
, pos
);
5026 bool wxGenericListCtrl::SetItemPosition( long WXUNUSED(item
), const wxPoint
& WXUNUSED(pos
) )
5031 int wxGenericListCtrl::GetItemCount() const
5033 return m_mainWin
->GetItemCount();
5036 int wxGenericListCtrl::GetColumnCount() const
5038 return m_mainWin
->GetColumnCount();
5041 void wxGenericListCtrl::SetItemSpacing( int spacing
, bool isSmall
)
5043 m_mainWin
->SetItemSpacing( spacing
, isSmall
);
5046 wxSize
wxGenericListCtrl::GetItemSpacing() const
5048 const int spacing
= m_mainWin
->GetItemSpacing(HasFlag(wxLC_SMALL_ICON
));
5050 return wxSize(spacing
, spacing
);
5053 #if WXWIN_COMPATIBILITY_2_6
5054 int wxGenericListCtrl::GetItemSpacing( bool isSmall
) const
5056 return m_mainWin
->GetItemSpacing( isSmall
);
5058 #endif // WXWIN_COMPATIBILITY_2_6
5060 void wxGenericListCtrl::SetItemTextColour( long item
, const wxColour
&col
)
5063 info
.m_itemId
= item
;
5064 info
.SetTextColour( col
);
5065 m_mainWin
->SetItem( info
);
5068 wxColour
wxGenericListCtrl::GetItemTextColour( long item
) const
5071 info
.m_itemId
= item
;
5072 m_mainWin
->GetItem( info
);
5073 return info
.GetTextColour();
5076 void wxGenericListCtrl::SetItemBackgroundColour( long item
, const wxColour
&col
)
5079 info
.m_itemId
= item
;
5080 info
.SetBackgroundColour( col
);
5081 m_mainWin
->SetItem( info
);
5084 wxColour
wxGenericListCtrl::GetItemBackgroundColour( long item
) const
5087 info
.m_itemId
= item
;
5088 m_mainWin
->GetItem( info
);
5089 return info
.GetBackgroundColour();
5092 void wxGenericListCtrl::SetItemFont( long item
, const wxFont
&f
)
5095 info
.m_itemId
= item
;
5097 m_mainWin
->SetItem( info
);
5100 wxFont
wxGenericListCtrl::GetItemFont( long item
) const
5103 info
.m_itemId
= item
;
5104 m_mainWin
->GetItem( info
);
5105 return info
.GetFont();
5108 int wxGenericListCtrl::GetSelectedItemCount() const
5110 return m_mainWin
->GetSelectedItemCount();
5113 wxColour
wxGenericListCtrl::GetTextColour() const
5115 return GetForegroundColour();
5118 void wxGenericListCtrl::SetTextColour(const wxColour
& col
)
5120 SetForegroundColour(col
);
5123 long wxGenericListCtrl::GetTopItem() const
5126 m_mainWin
->GetVisibleLinesRange(&top
, NULL
);
5130 long wxGenericListCtrl::GetNextItem( long item
, int geom
, int state
) const
5132 return m_mainWin
->GetNextItem( item
, geom
, state
);
5135 wxImageListType
*wxGenericListCtrl::GetImageList(int which
) const
5137 if (which
== wxIMAGE_LIST_NORMAL
)
5138 return m_imageListNormal
;
5139 else if (which
== wxIMAGE_LIST_SMALL
)
5140 return m_imageListSmall
;
5141 else if (which
== wxIMAGE_LIST_STATE
)
5142 return m_imageListState
;
5144 return (wxImageListType
*) NULL
;
5147 void wxGenericListCtrl::SetImageList( wxImageListType
*imageList
, int which
)
5149 if ( which
== wxIMAGE_LIST_NORMAL
)
5151 if (m_ownsImageListNormal
)
5152 delete m_imageListNormal
;
5153 m_imageListNormal
= imageList
;
5154 m_ownsImageListNormal
= false;
5156 else if ( which
== wxIMAGE_LIST_SMALL
)
5158 if (m_ownsImageListSmall
)
5159 delete m_imageListSmall
;
5160 m_imageListSmall
= imageList
;
5161 m_ownsImageListSmall
= false;
5163 else if ( which
== wxIMAGE_LIST_STATE
)
5165 if (m_ownsImageListState
)
5166 delete m_imageListState
;
5167 m_imageListState
= imageList
;
5168 m_ownsImageListState
= false;
5171 m_mainWin
->SetImageList( imageList
, which
);
5174 void wxGenericListCtrl::AssignImageList(wxImageListType
*imageList
, int which
)
5176 SetImageList(imageList
, which
);
5177 if ( which
== wxIMAGE_LIST_NORMAL
)
5178 m_ownsImageListNormal
= true;
5179 else if ( which
== wxIMAGE_LIST_SMALL
)
5180 m_ownsImageListSmall
= true;
5181 else if ( which
== wxIMAGE_LIST_STATE
)
5182 m_ownsImageListState
= true;
5185 bool wxGenericListCtrl::Arrange( int WXUNUSED(flag
) )
5190 bool wxGenericListCtrl::DeleteItem( long item
)
5192 m_mainWin
->DeleteItem( item
);
5196 bool wxGenericListCtrl::DeleteAllItems()
5198 m_mainWin
->DeleteAllItems();
5202 bool wxGenericListCtrl::DeleteAllColumns()
5204 size_t count
= m_mainWin
->m_columns
.GetCount();
5205 for ( size_t n
= 0; n
< count
; n
++ )
5210 void wxGenericListCtrl::ClearAll()
5212 m_mainWin
->DeleteEverything();
5215 bool wxGenericListCtrl::DeleteColumn( int col
)
5217 m_mainWin
->DeleteColumn( col
);
5219 // if we don't have the header any longer, we need to relayout the window
5220 if ( !GetColumnCount() )
5221 ResizeReportView(false /* no header */);
5225 wxTextCtrl
*wxGenericListCtrl::EditLabel(long item
,
5226 wxClassInfo
* textControlClass
)
5228 return m_mainWin
->EditLabel( item
, textControlClass
);
5231 wxTextCtrl
*wxGenericListCtrl::GetEditControl() const
5233 return m_mainWin
->GetEditControl();
5236 bool wxGenericListCtrl::EnsureVisible( long item
)
5238 m_mainWin
->EnsureVisible( item
);
5242 long wxGenericListCtrl::FindItem( long start
, const wxString
& str
, bool partial
)
5244 return m_mainWin
->FindItem( start
, str
, partial
);
5247 long wxGenericListCtrl::FindItem( long start
, wxUIntPtr data
)
5249 return m_mainWin
->FindItem( start
, data
);
5252 long wxGenericListCtrl::FindItem( long WXUNUSED(start
), const wxPoint
& pt
,
5253 int WXUNUSED(direction
))
5255 return m_mainWin
->FindItem( pt
);
5258 long wxGenericListCtrl::HitTest( const wxPoint
&point
, int &flags
)
5260 return m_mainWin
->HitTest( (int)point
.x
, (int)point
.y
, flags
);
5263 long wxGenericListCtrl::InsertItem( wxListItem
& info
)
5265 m_mainWin
->InsertItem( info
);
5266 return info
.m_itemId
;
5269 long wxGenericListCtrl::InsertItem( long index
, const wxString
&label
)
5272 info
.m_text
= label
;
5273 info
.m_mask
= wxLIST_MASK_TEXT
;
5274 info
.m_itemId
= index
;
5275 return InsertItem( info
);
5278 long wxGenericListCtrl::InsertItem( long index
, int imageIndex
)
5281 info
.m_mask
= wxLIST_MASK_IMAGE
;
5282 info
.m_image
= imageIndex
;
5283 info
.m_itemId
= index
;
5284 return InsertItem( info
);
5287 long wxGenericListCtrl::InsertItem( long index
, const wxString
&label
, int imageIndex
)
5290 info
.m_text
= label
;
5291 info
.m_image
= imageIndex
;
5292 info
.m_mask
= wxLIST_MASK_TEXT
| wxLIST_MASK_IMAGE
;
5293 info
.m_itemId
= index
;
5294 return InsertItem( info
);
5297 long wxGenericListCtrl::InsertColumn( long col
, wxListItem
&item
)
5299 wxCHECK_MSG( m_headerWin
, -1, _T("can't add column in non report mode") );
5301 m_mainWin
->InsertColumn( col
, item
);
5303 // if we hadn't had a header before but have one now
5304 // then we need to relayout the window
5305 if ( GetColumnCount() == 1 && m_mainWin
->HasHeader() )
5306 ResizeReportView(true /* have header */);
5308 m_headerWin
->Refresh();
5313 long wxGenericListCtrl::InsertColumn( long col
, const wxString
&heading
,
5314 int format
, int width
)
5317 item
.m_mask
= wxLIST_MASK_TEXT
| wxLIST_MASK_FORMAT
;
5318 item
.m_text
= heading
;
5321 item
.m_mask
|= wxLIST_MASK_WIDTH
;
5322 item
.m_width
= width
;
5325 item
.m_format
= format
;
5327 return InsertColumn( col
, item
);
5330 bool wxGenericListCtrl::ScrollList( int WXUNUSED(dx
), int WXUNUSED(dy
) )
5336 // fn is a function which takes 3 long arguments: item1, item2, data.
5337 // item1 is the long data associated with a first item (NOT the index).
5338 // item2 is the long data associated with a second item (NOT the index).
5339 // data is the same value as passed to SortItems.
5340 // The return value is a negative number if the first item should precede the second
5341 // item, a positive number of the second item should precede the first,
5342 // or zero if the two items are equivalent.
5343 // data is arbitrary data to be passed to the sort function.
5345 bool wxGenericListCtrl::SortItems( wxListCtrlCompare fn
, long data
)
5347 m_mainWin
->SortItems( fn
, data
);
5351 // ----------------------------------------------------------------------------
5353 // ----------------------------------------------------------------------------
5355 void wxGenericListCtrl::OnSize(wxSizeEvent
& WXUNUSED(event
))
5360 ResizeReportView(m_mainWin
->HasHeader());
5361 m_mainWin
->RecalculatePositions();
5364 void wxGenericListCtrl::ResizeReportView(bool showHeader
)
5367 GetClientSize( &cw
, &ch
);
5371 m_headerWin
->SetSize( 0, 0, cw
, m_headerHeight
);
5372 if(ch
> m_headerHeight
)
5373 m_mainWin
->SetSize( 0, m_headerHeight
+ 1,
5374 cw
, ch
- m_headerHeight
- 1 );
5376 m_mainWin
->SetSize( 0, m_headerHeight
+ 1,
5379 else // no header window
5381 m_mainWin
->SetSize( 0, 0, cw
, ch
);
5385 void wxGenericListCtrl::OnInternalIdle()
5387 wxWindow::OnInternalIdle();
5389 // do it only if needed
5390 if ( !m_mainWin
->m_dirty
)
5393 m_mainWin
->RecalculatePositions();
5396 // ----------------------------------------------------------------------------
5398 // ----------------------------------------------------------------------------
5400 bool wxGenericListCtrl::SetBackgroundColour( const wxColour
&colour
)
5404 m_mainWin
->SetBackgroundColour( colour
);
5405 m_mainWin
->m_dirty
= true;
5411 bool wxGenericListCtrl::SetForegroundColour( const wxColour
&colour
)
5413 if ( !wxWindow::SetForegroundColour( colour
) )
5418 m_mainWin
->SetForegroundColour( colour
);
5419 m_mainWin
->m_dirty
= true;
5423 m_headerWin
->SetForegroundColour( colour
);
5428 bool wxGenericListCtrl::SetFont( const wxFont
&font
)
5430 if ( !wxWindow::SetFont( font
) )
5435 m_mainWin
->SetFont( font
);
5436 m_mainWin
->m_dirty
= true;
5441 m_headerWin
->SetFont( font
);
5442 CalculateAndSetHeaderHeight();
5451 #include "wx/listbox.h"
5456 wxGenericListCtrl::GetClassDefaultAttributes(wxWindowVariant variant
)
5459 // Use the same color scheme as wxListBox
5460 return wxListBox::GetClassDefaultAttributes(variant
);
5462 wxUnusedVar(variant
);
5463 wxVisualAttributes attr
;
5464 attr
.colFg
= wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT
);
5465 attr
.colBg
= wxSystemSettings::GetColour(wxSYS_COLOUR_LISTBOX
);
5466 attr
.font
= wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT
);
5471 // ----------------------------------------------------------------------------
5472 // methods forwarded to m_mainWin
5473 // ----------------------------------------------------------------------------
5475 #if wxUSE_DRAG_AND_DROP
5477 void wxGenericListCtrl::SetDropTarget( wxDropTarget
*dropTarget
)
5479 m_mainWin
->SetDropTarget( dropTarget
);
5482 wxDropTarget
*wxGenericListCtrl::GetDropTarget() const
5484 return m_mainWin
->GetDropTarget();
5489 bool wxGenericListCtrl::SetCursor( const wxCursor
&cursor
)
5491 return m_mainWin
? m_mainWin
->wxWindow::SetCursor(cursor
) : false;
5494 wxColour
wxGenericListCtrl::GetBackgroundColour() const
5496 return m_mainWin
? m_mainWin
->GetBackgroundColour() : wxColour();
5499 wxColour
wxGenericListCtrl::GetForegroundColour() const
5501 return m_mainWin
? m_mainWin
->GetForegroundColour() : wxColour();
5504 bool wxGenericListCtrl::DoPopupMenu( wxMenu
*menu
, int x
, int y
)
5507 return m_mainWin
->PopupMenu( menu
, x
, y
);
5513 void wxGenericListCtrl::DoClientToScreen( int *x
, int *y
) const
5515 m_mainWin
->DoClientToScreen(x
, y
);
5518 void wxGenericListCtrl::DoScreenToClient( int *x
, int *y
) const
5520 m_mainWin
->DoScreenToClient(x
, y
);
5523 void wxGenericListCtrl::SetFocus()
5525 // The test in window.cpp fails as we are a composite
5526 // window, so it checks against "this", but not m_mainWin.
5527 if ( DoFindFocus() != this )
5528 m_mainWin
->SetFocus();
5531 wxSize
wxGenericListCtrl::DoGetBestSize() const
5533 // Something is better than nothing...
5534 // 100x80 is what the MSW version will get from the default
5535 // wxControl::DoGetBestSize
5536 return wxSize(100, 80);
5539 // ----------------------------------------------------------------------------
5540 // virtual list control support
5541 // ----------------------------------------------------------------------------
5543 wxString
wxGenericListCtrl::OnGetItemText(long WXUNUSED(item
), long WXUNUSED(col
)) const
5545 // this is a pure virtual function, in fact - which is not really pure
5546 // because the controls which are not virtual don't need to implement it
5547 wxFAIL_MSG( _T("wxGenericListCtrl::OnGetItemText not supposed to be called") );
5549 return wxEmptyString
;
5552 int wxGenericListCtrl::OnGetItemImage(long WXUNUSED(item
)) const
5554 wxCHECK_MSG(!GetImageList(wxIMAGE_LIST_SMALL
),
5556 wxT("List control has an image list, OnGetItemImage or OnGetItemColumnImage should be overridden."));
5560 int wxGenericListCtrl::OnGetItemColumnImage(long item
, long column
) const
5563 return OnGetItemImage(item
);
5569 wxGenericListCtrl::OnGetItemAttr(long WXUNUSED_UNLESS_DEBUG(item
)) const
5571 wxASSERT_MSG( item
>= 0 && item
< GetItemCount(),
5572 _T("invalid item index in OnGetItemAttr()") );
5574 // no attributes by default
5578 void wxGenericListCtrl::SetItemCount(long count
)
5580 wxASSERT_MSG( IsVirtual(), _T("this is for virtual controls only") );
5582 m_mainWin
->SetItemCount(count
);
5585 void wxGenericListCtrl::RefreshItem(long item
)
5587 m_mainWin
->RefreshLine(item
);
5590 void wxGenericListCtrl::RefreshItems(long itemFrom
, long itemTo
)
5592 m_mainWin
->RefreshLines(itemFrom
, itemTo
);
5595 // Generic wxListCtrl is more or less a container for two other
5596 // windows which drawings are done upon. These are namely
5597 // 'm_headerWin' and 'm_mainWin'.
5598 // Here we override 'virtual wxWindow::Refresh()' to mimic the
5599 // behaviour wxListCtrl has under wxMSW.
5601 void wxGenericListCtrl::Refresh(bool eraseBackground
, const wxRect
*rect
)
5605 // The easy case, no rectangle specified.
5607 m_headerWin
->Refresh(eraseBackground
);
5610 m_mainWin
->Refresh(eraseBackground
);
5614 // Refresh the header window
5617 wxRect rectHeader
= m_headerWin
->GetRect();
5618 rectHeader
.Intersect(*rect
);
5619 if (rectHeader
.GetWidth() && rectHeader
.GetHeight())
5622 m_headerWin
->GetPosition(&x
, &y
);
5623 rectHeader
.Offset(-x
, -y
);
5624 m_headerWin
->Refresh(eraseBackground
, &rectHeader
);
5628 // Refresh the main window
5631 wxRect rectMain
= m_mainWin
->GetRect();
5632 rectMain
.Intersect(*rect
);
5633 if (rectMain
.GetWidth() && rectMain
.GetHeight())
5636 m_mainWin
->GetPosition(&x
, &y
);
5637 rectMain
.Offset(-x
, -y
);
5638 m_mainWin
->Refresh(eraseBackground
, &rectMain
);
5644 void wxGenericListCtrl::Freeze()
5646 m_mainWin
->Freeze();
5649 void wxGenericListCtrl::Thaw()
5654 #endif // wxUSE_LISTCTRL