1 /////////////////////////////////////////////////////////////////////////////
2 // Name: 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 /////////////////////////////////////////////////////////////////////////////
14 1. we need to implement searching/sorting for virtual controls somehow
15 ?2. when changing selection the lines are refreshed twice
18 // ============================================================================
20 // ============================================================================
22 // ----------------------------------------------------------------------------
24 // ----------------------------------------------------------------------------
26 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
27 #pragma implementation "listctrl.h"
28 #pragma implementation "listctrlbase.h"
31 // For compilers that support precompilation, includes "wx.h".
32 #include "wx/wxprec.h"
43 #include "wx/dynarray.h"
45 #include "wx/dcscreen.h"
47 #include "wx/textctrl.h"
50 // under Win32 we always use the native version and also may use the generic
51 // one, however some things should be done only if we use only the generic
53 #if defined(__WIN32__) && !defined(__WXUNIVERSAL__)
54 #define HAVE_NATIVE_LISTCTRL
57 // if we have the native control, wx/listctrl.h declares it and not this one
58 #ifdef HAVE_NATIVE_LISTCTRL
59 #include "wx/generic/listctrl.h"
60 #else // !HAVE_NATIVE_LISTCTRL
61 #include "wx/listctrl.h"
63 // if we have a native version, its implementation file does all this
64 IMPLEMENT_DYNAMIC_CLASS(wxListItem
, wxObject
)
65 IMPLEMENT_DYNAMIC_CLASS(wxListView
, wxListCtrl
)
66 IMPLEMENT_DYNAMIC_CLASS(wxListEvent
, wxNotifyEvent
)
68 IMPLEMENT_DYNAMIC_CLASS(wxListCtrl
, wxGenericListCtrl
)
69 #endif // HAVE_NATIVE_LISTCTRL/!HAVE_NATIVE_LISTCTRL
71 #include "wx/selstore.h"
72 #include "wx/renderer.h"
76 #include "wx/mac/private.h"
81 // NOTE: If using the wxListBox visual attributes works everywhere then this can
82 // be removed, as well as the #else case below.
83 #define _USE_VISATTR 0
86 // ----------------------------------------------------------------------------
88 // ----------------------------------------------------------------------------
90 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_BEGIN_DRAG
)
91 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_BEGIN_RDRAG
)
92 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_BEGIN_LABEL_EDIT
)
93 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_END_LABEL_EDIT
)
94 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_DELETE_ITEM
)
95 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_DELETE_ALL_ITEMS
)
96 #if WXWIN_COMPATIBILITY_2_4
97 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_GET_INFO
)
98 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_SET_INFO
)
100 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_ITEM_SELECTED
)
101 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_ITEM_DESELECTED
)
102 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_KEY_DOWN
)
103 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_INSERT_ITEM
)
104 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_COL_CLICK
)
105 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_COL_RIGHT_CLICK
)
106 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_COL_BEGIN_DRAG
)
107 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_COL_DRAGGING
)
108 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_COL_END_DRAG
)
109 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_ITEM_RIGHT_CLICK
)
110 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_ITEM_MIDDLE_CLICK
)
111 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_ITEM_ACTIVATED
)
112 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_ITEM_FOCUSED
)
113 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_CACHE_HINT
)
115 // ----------------------------------------------------------------------------
117 // ----------------------------------------------------------------------------
119 // // the height of the header window (FIXME: should depend on its font!)
120 // static const int HEADER_HEIGHT = 23;
122 static const int SCROLL_UNIT_X
= 15;
124 // the spacing between the lines (in report mode)
125 static const int LINE_SPACING
= 0;
127 // extra margins around the text label
128 static const int EXTRA_WIDTH
= 4;
129 static const int EXTRA_HEIGHT
= 4;
131 // margin between the window and the items
132 static const int EXTRA_BORDER_X
= 2;
133 static const int EXTRA_BORDER_Y
= 2;
135 // offset for the header window
136 static const int HEADER_OFFSET_X
= 1;
137 static const int HEADER_OFFSET_Y
= 1;
139 // margin between rows of icons in [small] icon view
140 static const int MARGIN_BETWEEN_ROWS
= 6;
142 // when autosizing the columns, add some slack
143 static const int AUTOSIZE_COL_MARGIN
= 10;
145 // default and minimal widths for the header columns
146 static const int WIDTH_COL_DEFAULT
= 80;
147 static const int WIDTH_COL_MIN
= 10;
149 // the space between the image and the text in the report mode
150 static const int IMAGE_MARGIN_IN_REPORT_MODE
= 5;
152 // ============================================================================
154 // ============================================================================
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
210 // is NULL and the owner window is used to retrieve the item position and
214 // the list ctrl we are in
215 wxListMainWindow
*m_owner
;
217 // custom attributes or NULL
218 wxListItemAttr
*m_attr
;
221 // common part of all ctors
227 //-----------------------------------------------------------------------------
228 // wxListHeaderData (internal)
229 //-----------------------------------------------------------------------------
231 class WXDLLEXPORT wxListHeaderData
: public wxObject
235 wxListHeaderData( const wxListItem
&info
);
236 void SetItem( const wxListItem
&item
);
237 void SetPosition( int x
, int y
);
238 void SetWidth( int w
);
239 void SetFormat( int format
);
240 void SetHeight( int h
);
241 bool HasImage() const;
243 bool HasText() const { return !m_text
.empty(); }
244 const wxString
& GetText() const { return m_text
; }
245 void SetText(const wxString
& text
) { m_text
= text
; }
247 void GetItem( wxListItem
&item
);
249 bool IsHit( int x
, int y
) const;
250 int GetImage() const;
251 int GetWidth() const;
252 int GetFormat() const;
268 //-----------------------------------------------------------------------------
269 // wxListLineData (internal)
270 //-----------------------------------------------------------------------------
272 WX_DECLARE_LIST(wxListItemData
, wxListItemDataList
);
273 #include "wx/listimpl.cpp"
274 WX_DEFINE_LIST(wxListItemDataList
);
279 // the list of subitems: only may have more than one item in report mode
280 wxListItemDataList m_items
;
282 // this is not used in report view
294 // the part to be highlighted
295 wxRect m_rectHighlight
;
297 // extend all our rects to be centered inside theo ne of given width
298 void ExtendWidth(wxCoord w
)
300 wxASSERT_MSG( m_rectAll
.width
<= w
,
301 _T("width can only be increased") );
304 m_rectLabel
.x
= m_rectAll
.x
+ (w
- m_rectLabel
.width
)/2;
305 m_rectIcon
.x
= m_rectAll
.x
+ (w
- m_rectIcon
.width
)/2;
306 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 bool HasImage() const { return GetImage() != -1; }
345 bool HasText() const { return !GetText(0).empty(); }
347 void SetItem( int index
, const wxListItem
&info
);
348 void GetItem( int index
, wxListItem
&info
);
350 wxString
GetText(int index
) const;
351 void SetText( int index
, const wxString s
);
353 wxListItemAttr
*GetAttr() const;
354 void SetAttr(wxListItemAttr
*attr
);
356 // return true if the highlighting really changed
357 bool Highlight( bool on
);
359 void ReverseHighlight();
361 bool IsHighlighted() const
363 wxASSERT_MSG( !IsVirtual(), _T("unexpected call to IsHighlighted") );
365 return m_highlighted
;
368 // draw the line on the given DC in icon/list mode
369 void Draw( wxDC
*dc
);
371 // the same in report mode
372 void DrawInReportMode( wxDC
*dc
,
374 const wxRect
& rectHL
,
378 // set the line to contain num items (only can be > 1 in report mode)
379 void InitItems( int num
);
381 // get the mode (i.e. style) of the list control
382 inline int GetMode() const;
384 // prepare the DC for drawing with these item's attributes, return true if
385 // we need to draw the items background to highlight it, false otherwise
386 bool SetAttributes(wxDC
*dc
,
387 const wxListItemAttr
*attr
,
390 // draw the text on the DC with the correct justification; also add an
391 // ellipsis if the text is too large to fit in the current width
392 void DrawTextFormatted(wxDC
*dc
, const wxString
&text
, int col
, int x
, int y
, int width
);
394 // these are only used by GetImage/SetImage above, we don't support images
395 // with subitems at the public API level yet
396 void SetImage( int index
, int image
);
397 int GetImage( int index
) const;
400 WX_DECLARE_EXPORTED_OBJARRAY(wxListLineData
, wxListLineDataArray
);
401 #include "wx/arrimpl.cpp"
402 WX_DEFINE_OBJARRAY(wxListLineDataArray
);
404 //-----------------------------------------------------------------------------
405 // wxListHeaderWindow (internal)
406 //-----------------------------------------------------------------------------
408 class WXDLLEXPORT wxListHeaderWindow
: public wxWindow
411 wxListMainWindow
*m_owner
;
412 wxCursor
*m_currentCursor
;
413 wxCursor
*m_resizeCursor
;
416 // column being resized or -1
419 // divider line position in logical (unscrolled) coords
422 // minimal position beyond which the divider line can't be dragged in
427 wxListHeaderWindow();
429 wxListHeaderWindow( wxWindow
*win
,
431 wxListMainWindow
*owner
,
432 const wxPoint
&pos
= wxDefaultPosition
,
433 const wxSize
&size
= wxDefaultSize
,
435 const wxString
&name
= wxT("wxlistctrlcolumntitles") );
437 virtual ~wxListHeaderWindow();
440 void AdjustDC(wxDC
& dc
);
442 void OnPaint( wxPaintEvent
&event
);
443 void OnMouse( wxMouseEvent
&event
);
444 void OnSetFocus( wxFocusEvent
&event
);
450 // common part of all ctors
453 // generate and process the list event of the given type, return true if
454 // it wasn't vetoed, i.e. if we should proceed
455 bool SendListEvent(wxEventType type
, wxPoint pos
);
457 DECLARE_DYNAMIC_CLASS(wxListHeaderWindow
)
458 DECLARE_EVENT_TABLE()
461 //-----------------------------------------------------------------------------
462 // wxListRenameTimer (internal)
463 //-----------------------------------------------------------------------------
465 class WXDLLEXPORT wxListRenameTimer
: public wxTimer
468 wxListMainWindow
*m_owner
;
471 wxListRenameTimer( wxListMainWindow
*owner
);
475 //-----------------------------------------------------------------------------
476 // wxListTextCtrl (internal)
477 //-----------------------------------------------------------------------------
479 class WXDLLEXPORT wxListTextCtrl
: public wxTextCtrl
482 wxListTextCtrl(wxListMainWindow
*owner
, size_t itemEdit
);
485 void OnChar( wxKeyEvent
&event
);
486 void OnKeyUp( wxKeyEvent
&event
);
487 void OnKillFocus( wxFocusEvent
&event
);
489 bool AcceptChanges();
493 wxListMainWindow
*m_owner
;
494 wxString m_startValue
;
498 DECLARE_EVENT_TABLE()
501 //-----------------------------------------------------------------------------
502 // wxListMainWindow (internal)
503 //-----------------------------------------------------------------------------
505 WX_DECLARE_LIST(wxListHeaderData
, wxListHeaderDataList
);
506 #include "wx/listimpl.cpp"
507 WX_DEFINE_LIST(wxListHeaderDataList
);
509 class wxListMainWindow
: public wxScrolledWindow
513 wxListMainWindow( wxWindow
*parent
,
515 const wxPoint
& pos
= wxDefaultPosition
,
516 const wxSize
& size
= wxDefaultSize
,
518 const wxString
&name
= _T("listctrlmainwindow") );
520 virtual ~wxListMainWindow();
522 wxWindow
*GetMainWindowOfCompositeControl() { return GetParent(); }
524 bool HasFlag(int flag
) const { return m_parent
->HasFlag(flag
); }
526 // return true if this is a virtual list control
527 bool IsVirtual() const { return HasFlag(wxLC_VIRTUAL
); }
529 // return true if the control is in report mode
530 bool InReportView() const { return HasFlag(wxLC_REPORT
); }
532 // return true if we are in single selection mode, false if multi sel
533 bool IsSingleSel() const { return HasFlag(wxLC_SINGLE_SEL
); }
535 // do we have a header window?
536 bool HasHeader() const
537 { return InReportView() && !HasFlag(wxLC_NO_HEADER
); }
539 void HighlightAll( bool on
);
541 // all these functions only do something if the line is currently visible
543 // change the line "selected" state, return true if it really changed
544 bool HighlightLine( size_t line
, bool highlight
= true);
546 // as HighlightLine() but do it for the range of lines: this is incredibly
547 // more efficient for virtual list controls!
549 // NB: unlike HighlightLine() this one does refresh the lines on screen
550 void HighlightLines( size_t lineFrom
, size_t lineTo
, bool on
= true );
552 // toggle the line state and refresh it
553 void ReverseHighlight( size_t line
)
554 { HighlightLine(line
, !IsHighlighted(line
)); RefreshLine(line
); }
556 // return true if the line is highlighted
557 bool IsHighlighted(size_t line
) const;
559 // refresh one or several lines at once
560 void RefreshLine( size_t line
);
561 void RefreshLines( size_t lineFrom
, size_t lineTo
);
563 // refresh all selected items
564 void RefreshSelected();
566 // refresh all lines below the given one: the difference with
567 // RefreshLines() is that the index here might not be a valid one (happens
568 // when the last line is deleted)
569 void RefreshAfter( size_t lineFrom
);
571 // the methods which are forwarded to wxListLineData itself in list/icon
572 // modes but are here because the lines don't store their positions in the
575 // get the bound rect for the entire line
576 wxRect
GetLineRect(size_t line
) const;
578 // get the bound rect of the label
579 wxRect
GetLineLabelRect(size_t line
) const;
581 // get the bound rect of the items icon (only may be called if we do have
583 wxRect
GetLineIconRect(size_t line
) const;
585 // get the rect to be highlighted when the item has focus
586 wxRect
GetLineHighlightRect(size_t line
) const;
588 // get the size of the total line rect
589 wxSize
GetLineSize(size_t line
) const
590 { return GetLineRect(line
).GetSize(); }
592 // return the hit code for the corresponding position (in this line)
593 long HitTestLine(size_t line
, int x
, int y
) const;
595 // bring the selected item into view, scrolling to it if necessary
596 void MoveToItem(size_t item
);
598 // bring the current item into view
599 void MoveToFocus() { MoveToItem(m_current
); }
601 // start editing the label of the given item
602 void EditLabel( long item
);
604 // suspend/resume redrawing the control
608 void OnRenameTimer();
609 bool OnRenameAccept(size_t itemEdit
, const wxString
& value
);
610 void OnRenameCancelled(size_t itemEdit
);
612 void OnMouse( wxMouseEvent
&event
);
614 // called to switch the selection from the current item to newCurrent,
615 void OnArrowChar( size_t newCurrent
, const wxKeyEvent
& event
);
617 void OnChar( wxKeyEvent
&event
);
618 void OnKeyDown( wxKeyEvent
&event
);
619 void OnSetFocus( wxFocusEvent
&event
);
620 void OnKillFocus( wxFocusEvent
&event
);
621 void OnScroll(wxScrollWinEvent
& event
) ;
623 void OnPaint( wxPaintEvent
&event
);
625 void DrawImage( int index
, wxDC
*dc
, int x
, int y
);
626 void GetImageSize( int index
, int &width
, int &height
) const;
627 int GetTextLength( const wxString
&s
) const;
629 void SetImageList( wxImageListType
*imageList
, int which
);
630 void SetItemSpacing( int spacing
, bool isSmall
= false );
631 int GetItemSpacing( bool isSmall
= false );
633 void SetColumn( int col
, wxListItem
&item
);
634 void SetColumnWidth( int col
, int width
);
635 void GetColumn( int col
, wxListItem
&item
) const;
636 int GetColumnWidth( int col
) const;
637 int GetColumnCount() const { return m_columns
.GetCount(); }
639 // returns the sum of the heights of all columns
640 int GetHeaderWidth() const;
642 int GetCountPerPage() const;
644 void SetItem( wxListItem
&item
);
645 void GetItem( wxListItem
&item
) const;
646 void SetItemState( long item
, long state
, long stateMask
);
647 void SetItemStateAll( long state
, long stateMask
);
648 int GetItemState( long item
, long stateMask
) const;
649 void GetItemRect( long index
, wxRect
&rect
) const;
650 wxRect
GetViewRect() const;
651 bool GetItemPosition( long item
, wxPoint
& pos
) const;
652 int GetSelectedItemCount() const;
654 wxString
GetItemText(long item
) const
657 info
.m_itemId
= item
;
662 void SetItemText(long item
, const wxString
& value
)
665 info
.m_mask
= wxLIST_MASK_TEXT
;
666 info
.m_itemId
= item
;
671 // set the scrollbars and update the positions of the items
672 void RecalculatePositions(bool noRefresh
= false);
674 // refresh the window and the header
677 long GetNextItem( long item
, int geometry
, int state
) const;
678 void DeleteItem( long index
);
679 void DeleteAllItems();
680 void DeleteColumn( int col
);
681 void DeleteEverything();
682 void EnsureVisible( long index
);
683 long FindItem( long start
, const wxString
& str
, bool partial
= false );
684 long FindItem( long start
, wxUIntPtr data
);
685 long FindItem( const wxPoint
& pt
);
686 long HitTest( int x
, int y
, int &flags
);
687 void InsertItem( wxListItem
&item
);
688 void InsertColumn( long col
, wxListItem
&item
);
689 void SortItems( wxListCtrlCompare fn
, long data
);
691 size_t GetItemCount() const;
692 bool IsEmpty() const { return GetItemCount() == 0; }
693 void SetItemCount(long count
);
695 // change the current (== focused) item, send a notification event
696 void ChangeCurrent(size_t current
);
697 void ResetCurrent() { ChangeCurrent((size_t)-1); }
698 bool HasCurrent() const { return m_current
!= (size_t)-1; }
700 // send out a wxListEvent
701 void SendNotify( size_t line
,
703 wxPoint point
= wxDefaultPosition
);
705 // override base class virtual to reset m_lineHeight when the font changes
706 virtual bool SetFont(const wxFont
& font
)
708 if ( !wxScrolledWindow::SetFont(font
) )
716 // these are for wxListLineData usage only
718 // get the backpointer to the list ctrl
719 wxGenericListCtrl
*GetListCtrl() const
721 return wxStaticCast(GetParent(), wxGenericListCtrl
);
724 // get the height of all lines (assuming they all do have the same height)
725 wxCoord
GetLineHeight() const;
727 // get the y position of the given line (only for report view)
728 wxCoord
GetLineY(size_t line
) const;
730 // get the brush to use for the item highlighting
731 wxBrush
*GetHighlightBrush() const
733 return m_hasFocus
? m_highlightBrush
: m_highlightUnfocusedBrush
;
737 // the array of all line objects for a non virtual list control (for the
738 // virtual list control we only ever use m_lines[0])
739 wxListLineDataArray m_lines
;
741 // the list of column objects
742 wxListHeaderDataList m_columns
;
744 // currently focused item or -1
747 // the number of lines per page
750 // this flag is set when something which should result in the window
751 // redrawing happens (i.e. an item was added or deleted, or its appearance
752 // changed) and OnPaint() doesn't redraw the window while it is set which
753 // allows to minimize the number of repaintings when a lot of items are
754 // being added. The real repainting occurs only after the next OnIdle()
758 wxColour
*m_highlightColour
;
759 wxImageListType
*m_small_image_list
;
760 wxImageListType
*m_normal_image_list
;
762 int m_normal_spacing
;
766 wxTimer
*m_renameTimer
;
771 // for double click logic
772 size_t m_lineLastClicked
,
773 m_lineBeforeLastClicked
,
774 m_lineSelectSingleOnUp
;
777 // the total count of items in a virtual list control
780 // the object maintaining the items selection state, only used in virtual
782 wxSelectionStore m_selStore
;
784 // common part of all ctors
787 // get the line data for the given index
788 wxListLineData
*GetLine(size_t n
) const
790 wxASSERT_MSG( n
!= (size_t)-1, _T("invalid line index") );
794 wxConstCast(this, wxListMainWindow
)->CacheLineData(n
);
802 // get a dummy line which can be used for geometry calculations and such:
803 // you must use GetLine() if you want to really draw the line
804 wxListLineData
*GetDummyLine() const;
806 // cache the line data of the n-th line in m_lines[0]
807 void CacheLineData(size_t line
);
809 // get the range of visible lines
810 void GetVisibleLinesRange(size_t *from
, size_t *to
);
812 // force us to recalculate the range of visible lines
813 void ResetVisibleLinesRange() { m_lineFrom
= (size_t)-1; }
815 // get the colour to be used for drawing the rules
816 wxColour
GetRuleColour() const
821 return wxSystemSettings::GetColour(wxSYS_COLOUR_3DLIGHT
);
826 // initialize the current item if needed
827 void UpdateCurrent();
829 // delete all items but don't refresh: called from dtor
830 void DoDeleteAllItems();
832 // the height of one line using the current font
833 wxCoord m_lineHeight
;
835 // the total header width or 0 if not calculated yet
836 wxCoord m_headerWidth
;
838 // the first and last lines being shown on screen right now (inclusive),
839 // both may be -1 if they must be calculated so never access them directly:
840 // use GetVisibleLinesRange() above instead
844 // the brushes to use for item highlighting when we do/don't have focus
845 wxBrush
*m_highlightBrush
,
846 *m_highlightUnfocusedBrush
;
848 // if this is > 0, the control is frozen and doesn't redraw itself
849 size_t m_freezeCount
;
851 DECLARE_DYNAMIC_CLASS(wxListMainWindow
)
852 DECLARE_EVENT_TABLE()
854 friend class wxGenericListCtrl
;
857 // ============================================================================
859 // ============================================================================
861 //-----------------------------------------------------------------------------
863 //-----------------------------------------------------------------------------
865 wxListItemData::~wxListItemData()
867 // in the virtual list control the attributes are managed by the main
868 // program, so don't delete them
869 if ( !m_owner
->IsVirtual() )
877 void wxListItemData::Init()
885 wxListItemData::wxListItemData(wxListMainWindow
*owner
)
891 if ( owner
->InReportView() )
901 void wxListItemData::SetItem( const wxListItem
&info
)
903 if ( info
.m_mask
& wxLIST_MASK_TEXT
)
904 SetText(info
.m_text
);
905 if ( info
.m_mask
& wxLIST_MASK_IMAGE
)
906 m_image
= info
.m_image
;
907 if ( info
.m_mask
& wxLIST_MASK_DATA
)
908 m_data
= info
.m_data
;
910 if ( info
.HasAttributes() )
913 *m_attr
= *info
.GetAttributes();
915 m_attr
= new wxListItemAttr(*info
.GetAttributes());
923 m_rect
->width
= info
.m_width
;
927 void wxListItemData::SetPosition( int x
, int y
)
929 wxCHECK_RET( m_rect
, _T("unexpected SetPosition() call") );
935 void wxListItemData::SetSize( int width
, int height
)
937 wxCHECK_RET( m_rect
, _T("unexpected SetSize() call") );
940 m_rect
->width
= width
;
942 m_rect
->height
= height
;
945 bool wxListItemData::IsHit( int x
, int y
) const
947 wxCHECK_MSG( m_rect
, false, _T("can't be called in this mode") );
949 return wxRect(GetX(), GetY(), GetWidth(), GetHeight()).Inside(x
, y
);
952 int wxListItemData::GetX() const
954 wxCHECK_MSG( m_rect
, 0, _T("can't be called in this mode") );
959 int wxListItemData::GetY() const
961 wxCHECK_MSG( m_rect
, 0, _T("can't be called in this mode") );
966 int wxListItemData::GetWidth() const
968 wxCHECK_MSG( m_rect
, 0, _T("can't be called in this mode") );
970 return m_rect
->width
;
973 int wxListItemData::GetHeight() const
975 wxCHECK_MSG( m_rect
, 0, _T("can't be called in this mode") );
977 return m_rect
->height
;
980 void wxListItemData::GetItem( wxListItem
&info
) const
982 info
.m_text
= m_text
;
983 info
.m_image
= m_image
;
984 info
.m_data
= m_data
;
988 if ( m_attr
->HasTextColour() )
989 info
.SetTextColour(m_attr
->GetTextColour());
990 if ( m_attr
->HasBackgroundColour() )
991 info
.SetBackgroundColour(m_attr
->GetBackgroundColour());
992 if ( m_attr
->HasFont() )
993 info
.SetFont(m_attr
->GetFont());
997 //-----------------------------------------------------------------------------
999 //-----------------------------------------------------------------------------
1001 void wxListHeaderData::Init()
1012 wxListHeaderData::wxListHeaderData()
1017 wxListHeaderData::wxListHeaderData( const wxListItem
&item
)
1024 void wxListHeaderData::SetItem( const wxListItem
&item
)
1026 m_mask
= item
.m_mask
;
1028 if ( m_mask
& wxLIST_MASK_TEXT
)
1029 m_text
= item
.m_text
;
1031 if ( m_mask
& wxLIST_MASK_IMAGE
)
1032 m_image
= item
.m_image
;
1034 if ( m_mask
& wxLIST_MASK_FORMAT
)
1035 m_format
= item
.m_format
;
1037 if ( m_mask
& wxLIST_MASK_WIDTH
)
1038 SetWidth(item
.m_width
);
1041 void wxListHeaderData::SetPosition( int x
, int y
)
1047 void wxListHeaderData::SetHeight( int h
)
1052 void wxListHeaderData::SetWidth( int w
)
1056 m_width
= WIDTH_COL_DEFAULT
;
1057 else if (m_width
< WIDTH_COL_MIN
)
1058 m_width
= WIDTH_COL_MIN
;
1061 void wxListHeaderData::SetFormat( int format
)
1066 bool wxListHeaderData::HasImage() const
1068 return m_image
!= -1;
1071 bool wxListHeaderData::IsHit( int x
, int y
) const
1073 return ((x
>= m_xpos
) && (x
<= m_xpos
+m_width
) && (y
>= m_ypos
) && (y
<= m_ypos
+m_height
));
1076 void wxListHeaderData::GetItem( wxListItem
& item
)
1078 item
.m_mask
= m_mask
;
1079 item
.m_text
= m_text
;
1080 item
.m_image
= m_image
;
1081 item
.m_format
= m_format
;
1082 item
.m_width
= m_width
;
1085 int wxListHeaderData::GetImage() const
1090 int wxListHeaderData::GetWidth() const
1095 int wxListHeaderData::GetFormat() const
1100 //-----------------------------------------------------------------------------
1102 //-----------------------------------------------------------------------------
1104 inline int wxListLineData::GetMode() const
1106 return m_owner
->GetListCtrl()->GetWindowStyleFlag() & wxLC_MASK_TYPE
;
1109 inline bool wxListLineData::InReportView() const
1111 return m_owner
->HasFlag(wxLC_REPORT
);
1114 inline bool wxListLineData::IsVirtual() const
1116 return m_owner
->IsVirtual();
1119 wxListLineData::wxListLineData( wxListMainWindow
*owner
)
1123 if ( InReportView() )
1129 m_gi
= new GeometryInfo
;
1132 m_highlighted
= false;
1134 InitItems( GetMode() == wxLC_REPORT
? m_owner
->GetColumnCount() : 1 );
1137 void wxListLineData::CalculateSize( wxDC
*dc
, int spacing
)
1139 wxListItemDataList::compatibility_iterator node
= m_items
.GetFirst();
1140 wxCHECK_RET( node
, _T("no subitems at all??") );
1142 wxListItemData
*item
= node
->GetData();
1147 switch ( GetMode() )
1150 case wxLC_SMALL_ICON
:
1151 m_gi
->m_rectAll
.width
= spacing
;
1153 s
= item
->GetText();
1158 m_gi
->m_rectLabel
.width
=
1159 m_gi
->m_rectLabel
.height
= 0;
1163 dc
->GetTextExtent( s
, &lw
, &lh
);
1167 m_gi
->m_rectAll
.height
= spacing
+ lh
;
1169 m_gi
->m_rectAll
.width
= lw
;
1171 m_gi
->m_rectLabel
.width
= lw
;
1172 m_gi
->m_rectLabel
.height
= lh
;
1175 if (item
->HasImage())
1178 m_owner
->GetImageSize( item
->GetImage(), w
, h
);
1179 m_gi
->m_rectIcon
.width
= w
+ 8;
1180 m_gi
->m_rectIcon
.height
= h
+ 8;
1182 if ( m_gi
->m_rectIcon
.width
> m_gi
->m_rectAll
.width
)
1183 m_gi
->m_rectAll
.width
= m_gi
->m_rectIcon
.width
;
1184 if ( m_gi
->m_rectIcon
.height
+ lh
> m_gi
->m_rectAll
.height
- 4 )
1185 m_gi
->m_rectAll
.height
= m_gi
->m_rectIcon
.height
+ lh
+ 4;
1188 if ( item
->HasText() )
1190 m_gi
->m_rectHighlight
.width
= m_gi
->m_rectLabel
.width
;
1191 m_gi
->m_rectHighlight
.height
= m_gi
->m_rectLabel
.height
;
1193 else // no text, highlight the icon
1195 m_gi
->m_rectHighlight
.width
= m_gi
->m_rectIcon
.width
;
1196 m_gi
->m_rectHighlight
.height
= m_gi
->m_rectIcon
.height
;
1201 s
= item
->GetTextForMeasuring();
1203 dc
->GetTextExtent( s
, &lw
, &lh
);
1207 m_gi
->m_rectLabel
.width
= lw
;
1208 m_gi
->m_rectLabel
.height
= lh
;
1210 m_gi
->m_rectAll
.width
= lw
;
1211 m_gi
->m_rectAll
.height
= lh
;
1213 if (item
->HasImage())
1216 m_owner
->GetImageSize( item
->GetImage(), w
, h
);
1217 m_gi
->m_rectIcon
.width
= w
;
1218 m_gi
->m_rectIcon
.height
= h
;
1220 m_gi
->m_rectAll
.width
+= 4 + w
;
1221 if (h
> m_gi
->m_rectAll
.height
)
1222 m_gi
->m_rectAll
.height
= h
;
1225 m_gi
->m_rectHighlight
.width
= m_gi
->m_rectAll
.width
;
1226 m_gi
->m_rectHighlight
.height
= m_gi
->m_rectAll
.height
;
1230 wxFAIL_MSG( _T("unexpected call to SetSize") );
1234 wxFAIL_MSG( _T("unknown mode") );
1238 void wxListLineData::SetPosition( int x
, int y
, int spacing
)
1240 wxListItemDataList::compatibility_iterator node
= m_items
.GetFirst();
1241 wxCHECK_RET( node
, _T("no subitems at all??") );
1243 wxListItemData
*item
= node
->GetData();
1245 switch ( GetMode() )
1248 case wxLC_SMALL_ICON
:
1249 m_gi
->m_rectAll
.x
= x
;
1250 m_gi
->m_rectAll
.y
= y
;
1252 if ( item
->HasImage() )
1254 m_gi
->m_rectIcon
.x
= m_gi
->m_rectAll
.x
+ 4 +
1255 (m_gi
->m_rectAll
.width
- m_gi
->m_rectIcon
.width
) / 2;
1256 m_gi
->m_rectIcon
.y
= m_gi
->m_rectAll
.y
+ 4;
1259 if ( item
->HasText() )
1261 if (m_gi
->m_rectAll
.width
> spacing
)
1262 m_gi
->m_rectLabel
.x
= m_gi
->m_rectAll
.x
+ 2;
1264 m_gi
->m_rectLabel
.x
= m_gi
->m_rectAll
.x
+ 2 + (spacing
/2) - (m_gi
->m_rectLabel
.width
/2);
1265 m_gi
->m_rectLabel
.y
= m_gi
->m_rectAll
.y
+ m_gi
->m_rectAll
.height
+ 2 - m_gi
->m_rectLabel
.height
;
1266 m_gi
->m_rectHighlight
.x
= m_gi
->m_rectLabel
.x
- 2;
1267 m_gi
->m_rectHighlight
.y
= m_gi
->m_rectLabel
.y
- 2;
1269 else // no text, highlight the icon
1271 m_gi
->m_rectHighlight
.x
= m_gi
->m_rectIcon
.x
- 4;
1272 m_gi
->m_rectHighlight
.y
= m_gi
->m_rectIcon
.y
- 4;
1277 m_gi
->m_rectAll
.x
= x
;
1278 m_gi
->m_rectAll
.y
= y
;
1280 m_gi
->m_rectHighlight
.x
= m_gi
->m_rectAll
.x
;
1281 m_gi
->m_rectHighlight
.y
= m_gi
->m_rectAll
.y
;
1282 m_gi
->m_rectLabel
.y
= m_gi
->m_rectAll
.y
+ 2;
1284 if (item
->HasImage())
1286 m_gi
->m_rectIcon
.x
= m_gi
->m_rectAll
.x
+ 2;
1287 m_gi
->m_rectIcon
.y
= m_gi
->m_rectAll
.y
+ 2;
1288 m_gi
->m_rectLabel
.x
= m_gi
->m_rectAll
.x
+ 6 + m_gi
->m_rectIcon
.width
;
1292 m_gi
->m_rectLabel
.x
= m_gi
->m_rectAll
.x
+ 2;
1297 wxFAIL_MSG( _T("unexpected call to SetPosition") );
1301 wxFAIL_MSG( _T("unknown mode") );
1305 void wxListLineData::InitItems( int num
)
1307 for (int i
= 0; i
< num
; i
++)
1308 m_items
.Append( new wxListItemData(m_owner
) );
1311 void wxListLineData::SetItem( int index
, const wxListItem
&info
)
1313 wxListItemDataList::compatibility_iterator node
= m_items
.Item( index
);
1314 wxCHECK_RET( node
, _T("invalid column index in SetItem") );
1316 wxListItemData
*item
= node
->GetData();
1317 item
->SetItem( info
);
1320 void wxListLineData::GetItem( int index
, wxListItem
&info
)
1322 wxListItemDataList::compatibility_iterator node
= m_items
.Item( index
);
1325 wxListItemData
*item
= node
->GetData();
1326 item
->GetItem( info
);
1330 wxString
wxListLineData::GetText(int index
) const
1334 wxListItemDataList::compatibility_iterator node
= m_items
.Item( index
);
1337 wxListItemData
*item
= node
->GetData();
1338 s
= item
->GetText();
1344 void wxListLineData::SetText( int index
, const wxString s
)
1346 wxListItemDataList::compatibility_iterator node
= m_items
.Item( index
);
1349 wxListItemData
*item
= node
->GetData();
1354 void wxListLineData::SetImage( int index
, int image
)
1356 wxListItemDataList::compatibility_iterator node
= m_items
.Item( index
);
1357 wxCHECK_RET( node
, _T("invalid column index in SetImage()") );
1359 wxListItemData
*item
= node
->GetData();
1360 item
->SetImage(image
);
1363 int wxListLineData::GetImage( int index
) const
1365 wxListItemDataList::compatibility_iterator node
= m_items
.Item( index
);
1366 wxCHECK_MSG( node
, -1, _T("invalid column index in GetImage()") );
1368 wxListItemData
*item
= node
->GetData();
1369 return item
->GetImage();
1372 wxListItemAttr
*wxListLineData::GetAttr() const
1374 wxListItemDataList::compatibility_iterator node
= m_items
.GetFirst();
1375 wxCHECK_MSG( node
, NULL
, _T("invalid column index in GetAttr()") );
1377 wxListItemData
*item
= node
->GetData();
1378 return item
->GetAttr();
1381 void wxListLineData::SetAttr(wxListItemAttr
*attr
)
1383 wxListItemDataList::compatibility_iterator node
= m_items
.GetFirst();
1384 wxCHECK_RET( node
, _T("invalid column index in SetAttr()") );
1386 wxListItemData
*item
= node
->GetData();
1387 item
->SetAttr(attr
);
1390 bool wxListLineData::SetAttributes(wxDC
*dc
,
1391 const wxListItemAttr
*attr
,
1394 wxWindow
*listctrl
= m_owner
->GetParent();
1398 // don't use foreground colour for drawing highlighted items - this might
1399 // make them completely invisible (and there is no way to do bit
1400 // arithmetics on wxColour, unfortunately)
1404 colText
= wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHTTEXT
);
1408 if ( attr
&& attr
->HasTextColour() )
1410 colText
= attr
->GetTextColour();
1414 colText
= listctrl
->GetForegroundColour();
1418 dc
->SetTextForeground(colText
);
1422 if ( attr
&& attr
->HasFont() )
1424 font
= attr
->GetFont();
1428 font
= listctrl
->GetFont();
1434 bool hasBgCol
= attr
&& attr
->HasBackgroundColour();
1435 if ( highlighted
|| hasBgCol
)
1439 dc
->SetBrush( *m_owner
->GetHighlightBrush() );
1443 dc
->SetBrush(wxBrush(attr
->GetBackgroundColour(), wxSOLID
));
1446 dc
->SetPen( *wxTRANSPARENT_PEN
);
1454 void wxListLineData::Draw( wxDC
*dc
)
1456 wxListItemDataList::compatibility_iterator node
= m_items
.GetFirst();
1457 wxCHECK_RET( node
, _T("no subitems at all??") );
1459 bool highlighted
= IsHighlighted();
1461 wxListItemAttr
*attr
= GetAttr();
1463 if ( SetAttributes(dc
, attr
, highlighted
) )
1465 dc
->DrawRectangle( m_gi
->m_rectHighlight
);
1468 // just for debugging to better see where the items are
1470 dc
->SetPen(*wxRED_PEN
);
1471 dc
->SetBrush(*wxTRANSPARENT_BRUSH
);
1472 dc
->DrawRectangle( m_gi
->m_rectAll
);
1473 dc
->SetPen(*wxGREEN_PEN
);
1474 dc
->DrawRectangle( m_gi
->m_rectIcon
);
1477 wxListItemData
*item
= node
->GetData();
1478 if (item
->HasImage())
1480 // centre the image inside our rectangle, this looks nicer when items
1481 // ae aligned in a row
1482 const wxRect
& rectIcon
= m_gi
->m_rectIcon
;
1484 m_owner
->DrawImage(item
->GetImage(), dc
, rectIcon
.x
, rectIcon
.y
);
1487 if (item
->HasText())
1489 const wxRect
& rectLabel
= m_gi
->m_rectLabel
;
1491 wxDCClipper
clipper(*dc
, rectLabel
);
1492 dc
->DrawText(item
->GetText(), rectLabel
.x
, rectLabel
.y
);
1496 void wxListLineData::DrawInReportMode( wxDC
*dc
,
1498 const wxRect
& rectHL
,
1501 // TODO: later we should support setting different attributes for
1502 // different columns - to do it, just add "col" argument to
1503 // GetAttr() and move these lines into the loop below
1504 wxListItemAttr
*attr
= GetAttr();
1505 if ( SetAttributes(dc
, attr
, highlighted
) )
1507 dc
->DrawRectangle( rectHL
);
1510 wxCoord x
= rect
.x
+ HEADER_OFFSET_X
,
1511 y
= rect
.y
+ (LINE_SPACING
+ EXTRA_HEIGHT
) / 2;
1514 for ( wxListItemDataList::compatibility_iterator node
= m_items
.GetFirst();
1516 node
= node
->GetNext(), col
++ )
1518 wxListItemData
*item
= node
->GetData();
1520 int width
= m_owner
->GetColumnWidth(col
);
1524 if ( item
->HasImage() )
1527 m_owner
->DrawImage( item
->GetImage(), dc
, xOld
, y
);
1528 m_owner
->GetImageSize( item
->GetImage(), ix
, iy
);
1530 ix
+= IMAGE_MARGIN_IN_REPORT_MODE
;
1536 wxDCClipper
clipper(*dc
, xOld
, y
, width
- 8, rect
.height
);
1538 if ( item
->HasText() )
1540 DrawTextFormatted(dc
, item
->GetText(), col
, xOld
, y
, width
- 8);
1545 void wxListLineData::DrawTextFormatted(wxDC
*dc
,
1546 const wxString
&text
,
1552 wxString drawntext
, ellipsis
;
1553 wxCoord w
, h
, base_w
;
1556 // determine if the string can fit inside the current width
1557 dc
->GetTextExtent(text
, &w
, &h
);
1560 // it can, draw it using the items alignment
1561 m_owner
->GetColumn(col
, item
);
1562 switch ( item
.GetAlign() )
1565 wxFAIL_MSG( _T("unknown list item format") );
1568 case wxLIST_FORMAT_LEFT
:
1572 case wxLIST_FORMAT_RIGHT
:
1576 case wxLIST_FORMAT_CENTER
:
1577 x
+= (width
- w
) / 2;
1581 dc
->DrawText(text
, x
, y
);
1583 else // otherwise, truncate and add an ellipsis if possible
1585 // determine the base width
1586 ellipsis
= wxString(wxT("..."));
1587 dc
->GetTextExtent(ellipsis
, &base_w
, &h
);
1589 // continue until we have enough space or only one character left
1591 size_t len
= text
.Length();
1592 drawntext
= text
.Left(len
);
1595 dc
->GetTextExtent(drawntext
.Last(), &w_c
, &h_c
);
1596 drawntext
.RemoveLast();
1599 if (w
+ base_w
<= width
)
1603 // if still not enough space, remove ellipsis characters
1604 while (ellipsis
.Length() > 0 && w
+ base_w
> width
)
1606 ellipsis
= ellipsis
.Left(ellipsis
.Length() - 1);
1607 dc
->GetTextExtent(ellipsis
, &base_w
, &h
);
1610 // now draw the text
1611 dc
->DrawText(drawntext
, x
, y
);
1612 dc
->DrawText(ellipsis
, x
+ w
, y
);
1616 bool wxListLineData::Highlight( bool on
)
1618 wxCHECK_MSG( !IsVirtual(), false, _T("unexpected call to Highlight") );
1620 if ( on
== m_highlighted
)
1628 void wxListLineData::ReverseHighlight( void )
1630 Highlight(!IsHighlighted());
1633 //-----------------------------------------------------------------------------
1634 // wxListHeaderWindow
1635 //-----------------------------------------------------------------------------
1637 IMPLEMENT_DYNAMIC_CLASS(wxListHeaderWindow
,wxWindow
)
1639 BEGIN_EVENT_TABLE(wxListHeaderWindow
,wxWindow
)
1640 EVT_PAINT (wxListHeaderWindow::OnPaint
)
1641 EVT_MOUSE_EVENTS (wxListHeaderWindow::OnMouse
)
1642 EVT_SET_FOCUS (wxListHeaderWindow::OnSetFocus
)
1645 void wxListHeaderWindow::Init()
1647 m_currentCursor
= (wxCursor
*) NULL
;
1648 m_isDragging
= false;
1652 wxListHeaderWindow::wxListHeaderWindow()
1656 m_owner
= (wxListMainWindow
*) NULL
;
1657 m_resizeCursor
= (wxCursor
*) NULL
;
1660 wxListHeaderWindow::wxListHeaderWindow( wxWindow
*win
,
1662 wxListMainWindow
*owner
,
1666 const wxString
&name
)
1667 : wxWindow( win
, id
, pos
, size
, style
, name
)
1672 m_resizeCursor
= new wxCursor( wxCURSOR_SIZEWE
);
1675 wxVisualAttributes attr
= wxPanel::GetClassDefaultAttributes();
1676 SetOwnForegroundColour( attr
.colFg
);
1677 SetOwnBackgroundColour( attr
.colBg
);
1679 SetOwnFont( attr
.font
);
1681 SetOwnForegroundColour( wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT
));
1682 SetOwnBackgroundColour( wxSystemSettings::GetColour(wxSYS_COLOUR_BTNFACE
));
1684 SetOwnFont( wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT
));
1688 wxListHeaderWindow::~wxListHeaderWindow()
1690 delete m_resizeCursor
;
1693 #ifdef __WXUNIVERSAL__
1694 #include "wx/univ/renderer.h"
1695 #include "wx/univ/theme.h"
1698 // shift the DC origin to match the position of the main window horz
1699 // scrollbar: this allows us to always use logical coords
1700 void wxListHeaderWindow::AdjustDC(wxDC
& dc
)
1703 m_owner
->GetScrollPixelsPerUnit( &xpix
, NULL
);
1706 m_owner
->GetViewStart( &x
, NULL
);
1708 // account for the horz scrollbar offset
1709 dc
.SetDeviceOrigin( -x
* xpix
, 0 );
1712 void wxListHeaderWindow::OnPaint( wxPaintEvent
&WXUNUSED(event
) )
1714 wxPaintDC
dc( this );
1721 dc
.SetFont( GetFont() );
1723 // width and height of the entire header window
1725 GetClientSize( &w
, &h
);
1726 m_owner
->CalcUnscrolledPosition(w
, 0, &w
, NULL
);
1728 dc
.SetBackgroundMode(wxTRANSPARENT
);
1730 dc
.SetTextForeground(GetForegroundColour());
1732 int x
= HEADER_OFFSET_X
;
1734 int numColumns
= m_owner
->GetColumnCount();
1736 for ( int i
= 0; i
< numColumns
&& x
< w
; i
++ )
1738 m_owner
->GetColumn( i
, item
);
1739 int wCol
= item
.m_width
;
1741 // the width of the rect to draw: make it smaller to fit entirely
1742 // inside the column rect
1745 wxRendererNative::Get().DrawHeaderButton
1749 wxRect(x
, HEADER_OFFSET_Y
, cw
, h
- 2),
1750 m_parent
->IsEnabled() ? 0
1751 : (int)wxCONTROL_DISABLED
1754 // see if we have enough space for the column label
1756 // for this we need the width of the text
1759 dc
.GetTextExtent(item
.GetText(), &wLabel
, &hLabel
);
1760 wLabel
+= 2*EXTRA_WIDTH
;
1762 // and the width of the icon, if any
1763 static const int MARGIN_BETWEEN_TEXT_AND_ICON
= 2;
1764 int ix
= 0, // init them just to suppress the compiler warnings
1766 const int image
= item
.m_image
;
1767 wxImageListType
*imageList
;
1770 imageList
= m_owner
->m_small_image_list
;
1773 imageList
->GetSize(image
, ix
, iy
);
1774 wLabel
+= ix
+ MARGIN_BETWEEN_TEXT_AND_ICON
;
1782 // ignore alignment if there is not enough space anyhow
1784 switch ( wLabel
< cw
? item
.GetAlign() : wxLIST_FORMAT_LEFT
)
1787 wxFAIL_MSG( _T("unknown list item format") );
1790 case wxLIST_FORMAT_LEFT
:
1794 case wxLIST_FORMAT_RIGHT
:
1795 xAligned
= x
+ cw
- wLabel
;
1798 case wxLIST_FORMAT_CENTER
:
1799 xAligned
= x
+ (cw
- wLabel
) / 2;
1804 // if we have an image, draw it on the right of the label
1811 xAligned
+ wLabel
- ix
- MARGIN_BETWEEN_TEXT_AND_ICON
,
1812 HEADER_OFFSET_Y
+ (h
- 4 - iy
)/2,
1813 wxIMAGELIST_DRAW_TRANSPARENT
1816 cw
-= ix
+ MARGIN_BETWEEN_TEXT_AND_ICON
;
1819 // draw the text clipping it so that it doesn't overwrite the column
1821 wxDCClipper
clipper(dc
, x
, HEADER_OFFSET_Y
, cw
, h
- 4 );
1823 dc
.DrawText( item
.GetText(),
1824 xAligned
+ EXTRA_WIDTH
, h
/ 2 - hLabel
/ 2 ); //HEADER_OFFSET_Y + EXTRA_HEIGHT );
1832 void wxListHeaderWindow::DrawCurrent()
1834 int x1
= m_currentX
;
1836 m_owner
->ClientToScreen( &x1
, &y1
);
1838 int x2
= m_currentX
;
1840 m_owner
->GetClientSize( NULL
, &y2
);
1841 m_owner
->ClientToScreen( &x2
, &y2
);
1844 dc
.SetLogicalFunction( wxINVERT
);
1845 dc
.SetPen( wxPen( *wxBLACK
, 2, wxSOLID
) );
1846 dc
.SetBrush( *wxTRANSPARENT_BRUSH
);
1850 dc
.DrawLine( x1
, y1
, x2
, y2
);
1852 dc
.SetLogicalFunction( wxCOPY
);
1854 dc
.SetPen( wxNullPen
);
1855 dc
.SetBrush( wxNullBrush
);
1858 void wxListHeaderWindow::OnMouse( wxMouseEvent
&event
)
1860 // we want to work with logical coords
1862 m_owner
->CalcUnscrolledPosition(event
.GetX(), 0, &x
, NULL
);
1863 int y
= event
.GetY();
1867 SendListEvent(wxEVT_COMMAND_LIST_COL_DRAGGING
, event
.GetPosition());
1869 // we don't draw the line beyond our window, but we allow dragging it
1872 GetClientSize( &w
, NULL
);
1873 m_owner
->CalcUnscrolledPosition(w
, 0, &w
, NULL
);
1876 // erase the line if it was drawn
1877 if ( m_currentX
< w
)
1880 if (event
.ButtonUp())
1883 m_isDragging
= false;
1885 m_owner
->SetColumnWidth( m_column
, m_currentX
- m_minX
);
1886 SendListEvent(wxEVT_COMMAND_LIST_COL_END_DRAG
, event
.GetPosition());
1893 m_currentX
= m_minX
+ 7;
1895 // draw in the new location
1896 if ( m_currentX
< w
)
1900 else // not dragging
1903 bool hit_border
= false;
1905 // end of the current column
1908 // find the column where this event occured
1910 countCol
= m_owner
->GetColumnCount();
1911 for (col
= 0; col
< countCol
; col
++)
1913 xpos
+= m_owner
->GetColumnWidth( col
);
1916 if ( (abs(x
-xpos
) < 3) && (y
< 22) )
1918 // near the column border
1925 // inside the column
1932 if ( col
== countCol
)
1935 if (event
.LeftDown() || event
.RightUp())
1937 if (hit_border
&& event
.LeftDown())
1939 if ( SendListEvent(wxEVT_COMMAND_LIST_COL_BEGIN_DRAG
,
1940 event
.GetPosition()) )
1942 m_isDragging
= true;
1947 //else: column resizing was vetoed by the user code
1949 else // click on a column
1951 SendListEvent( event
.LeftDown()
1952 ? wxEVT_COMMAND_LIST_COL_CLICK
1953 : wxEVT_COMMAND_LIST_COL_RIGHT_CLICK
,
1954 event
.GetPosition());
1957 else if (event
.Moving())
1962 setCursor
= m_currentCursor
== wxSTANDARD_CURSOR
;
1963 m_currentCursor
= m_resizeCursor
;
1967 setCursor
= m_currentCursor
!= wxSTANDARD_CURSOR
;
1968 m_currentCursor
= wxSTANDARD_CURSOR
;
1972 SetCursor(*m_currentCursor
);
1977 void wxListHeaderWindow::OnSetFocus( wxFocusEvent
&WXUNUSED(event
) )
1979 m_owner
->SetFocus();
1983 bool wxListHeaderWindow::SendListEvent(wxEventType type
, wxPoint pos
)
1985 wxWindow
*parent
= GetParent();
1986 wxListEvent
le( type
, parent
->GetId() );
1987 le
.SetEventObject( parent
);
1988 le
.m_pointDrag
= pos
;
1990 // the position should be relative to the parent window, not
1991 // this one for compatibility with MSW and common sense: the
1992 // user code doesn't know anything at all about this header
1993 // window, so why should it get positions relative to it?
1994 le
.m_pointDrag
.y
-= GetSize().y
;
1996 le
.m_col
= m_column
;
1997 return !parent
->GetEventHandler()->ProcessEvent( le
) || le
.IsAllowed();
2000 //-----------------------------------------------------------------------------
2001 // wxListRenameTimer (internal)
2002 //-----------------------------------------------------------------------------
2004 wxListRenameTimer::wxListRenameTimer( wxListMainWindow
*owner
)
2009 void wxListRenameTimer::Notify()
2011 m_owner
->OnRenameTimer();
2014 //-----------------------------------------------------------------------------
2015 // wxListTextCtrl (internal)
2016 //-----------------------------------------------------------------------------
2018 BEGIN_EVENT_TABLE(wxListTextCtrl
,wxTextCtrl
)
2019 EVT_CHAR (wxListTextCtrl::OnChar
)
2020 EVT_KEY_UP (wxListTextCtrl::OnKeyUp
)
2021 EVT_KILL_FOCUS (wxListTextCtrl::OnKillFocus
)
2024 wxListTextCtrl::wxListTextCtrl(wxListMainWindow
*owner
, size_t itemEdit
)
2025 : m_startValue(owner
->GetItemText(itemEdit
)),
2026 m_itemEdited(itemEdit
)
2031 wxRect rectLabel
= owner
->GetLineLabelRect(itemEdit
);
2033 m_owner
->CalcScrolledPosition(rectLabel
.x
, rectLabel
.y
,
2034 &rectLabel
.x
, &rectLabel
.y
);
2036 (void)Create(owner
, wxID_ANY
, m_startValue
,
2037 wxPoint(rectLabel
.x
-4,rectLabel
.y
-4),
2038 wxSize(rectLabel
.width
+11,rectLabel
.height
+8));
2041 void wxListTextCtrl::Finish()
2045 wxPendingDelete
.Append(this);
2049 m_owner
->SetFocusIgnoringChildren();
2053 bool wxListTextCtrl::AcceptChanges()
2055 const wxString value
= GetValue();
2057 if ( value
== m_startValue
)
2059 // nothing changed, always accept
2063 if ( !m_owner
->OnRenameAccept(m_itemEdited
, value
) )
2065 // vetoed by the user
2069 // accepted, do rename the item
2070 m_owner
->SetItemText(m_itemEdited
, value
);
2075 void wxListTextCtrl::OnChar( wxKeyEvent
&event
)
2077 switch ( event
.m_keyCode
)
2080 // Notify the owner about the changes
2083 // Even if vetoed, close the control (consistent with MSW)
2090 m_owner
->OnRenameCancelled( m_itemEdited
);
2098 void wxListTextCtrl::OnKeyUp( wxKeyEvent
&event
)
2106 // auto-grow the textctrl:
2107 wxSize parentSize
= m_owner
->GetSize();
2108 wxPoint myPos
= GetPosition();
2109 wxSize mySize
= GetSize();
2111 GetTextExtent(GetValue() + _T("MM"), &sx
, &sy
);
2112 if (myPos
.x
+ sx
> parentSize
.x
)
2113 sx
= parentSize
.x
- myPos
.x
;
2116 SetSize(sx
, wxDefaultCoord
);
2121 void wxListTextCtrl::OnKillFocus( wxFocusEvent
&event
)
2125 // We must finish regardless of success, otherwise we'll get
2129 if ( !AcceptChanges() )
2130 m_owner
->OnRenameCancelled( m_itemEdited
);
2133 // We must let the native text control handle focus, too, otherwise
2134 // it could have problems with the cursor (e.g., in wxGTK):
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 );
2180 m_lineSelectSingleOnUp
=
2181 m_lineBeforeLastClicked
= (size_t)-1;
2186 wxListMainWindow::wxListMainWindow()
2191 m_highlightUnfocusedBrush
= (wxBrush
*) NULL
;
2194 wxListMainWindow::wxListMainWindow( wxWindow
*parent
,
2199 const wxString
&name
)
2200 : wxScrolledWindow( parent
, id
, pos
, size
,
2201 style
| wxHSCROLL
| wxVSCROLL
, name
)
2205 m_highlightBrush
= new wxBrush
2207 wxSystemSettings::GetColour
2209 wxSYS_COLOUR_HIGHLIGHT
2214 m_highlightUnfocusedBrush
= new wxBrush
2216 wxSystemSettings::GetColour
2218 wxSYS_COLOUR_BTNSHADOW
2226 SetScrollbars( 0, 0, 0, 0, 0, 0 );
2228 wxVisualAttributes attr
= wxGenericListCtrl::GetClassDefaultAttributes();
2229 SetOwnForegroundColour( attr
.colFg
);
2230 SetOwnBackgroundColour( attr
.colBg
);
2232 SetOwnFont( attr
.font
);
2235 wxListMainWindow::~wxListMainWindow()
2238 WX_CLEAR_LIST(wxListHeaderDataList
, m_columns
);
2240 delete m_highlightBrush
;
2241 delete m_highlightUnfocusedBrush
;
2243 delete m_renameTimer
;
2246 void wxListMainWindow::CacheLineData(size_t line
)
2248 wxGenericListCtrl
*listctrl
= GetListCtrl();
2250 wxListLineData
*ld
= GetDummyLine();
2252 size_t countCol
= GetColumnCount();
2253 for ( size_t col
= 0; col
< countCol
; col
++ )
2255 ld
->SetText(col
, listctrl
->OnGetItemText(line
, col
));
2258 ld
->SetImage(listctrl
->OnGetItemImage(line
));
2259 ld
->SetAttr(listctrl
->OnGetItemAttr(line
));
2262 wxListLineData
*wxListMainWindow::GetDummyLine() const
2264 wxASSERT_MSG( !IsEmpty(), _T("invalid line index") );
2266 wxASSERT_MSG( IsVirtual(), _T("GetDummyLine() shouldn't be called") );
2268 wxListMainWindow
*self
= wxConstCast(this, wxListMainWindow
);
2270 // we need to recreate the dummy line if the number of columns in the
2271 // control changed as it would have the incorrect number of fields
2273 if ( !m_lines
.IsEmpty() &&
2274 m_lines
[0].m_items
.GetCount() != (size_t)GetColumnCount() )
2276 self
->m_lines
.Clear();
2279 if ( m_lines
.IsEmpty() )
2281 wxListLineData
*line
= new wxListLineData(self
);
2282 self
->m_lines
.Add(line
);
2284 // don't waste extra memory -- there never going to be anything
2285 // else/more in this array
2286 self
->m_lines
.Shrink();
2292 // ----------------------------------------------------------------------------
2293 // line geometry (report mode only)
2294 // ----------------------------------------------------------------------------
2296 wxCoord
wxListMainWindow::GetLineHeight() const
2298 // we cache the line height as calling GetTextExtent() is slow
2299 if ( !m_lineHeight
)
2301 wxListMainWindow
*self
= wxConstCast(this, wxListMainWindow
);
2303 wxClientDC
dc( self
);
2304 dc
.SetFont( GetFont() );
2307 dc
.GetTextExtent(_T("H"), NULL
, &y
);
2309 if ( m_small_image_list
&& m_small_image_list
->GetImageCount() )
2313 m_small_image_list
->GetSize(0, iw
, ih
);
2318 self
->m_lineHeight
= y
+ LINE_SPACING
;
2321 return m_lineHeight
;
2324 wxCoord
wxListMainWindow::GetLineY(size_t line
) const
2326 wxASSERT_MSG( InReportView(), _T("only works in report mode") );
2328 return LINE_SPACING
+ line
*GetLineHeight();
2331 wxRect
wxListMainWindow::GetLineRect(size_t line
) const
2333 if ( !InReportView() )
2334 return GetLine(line
)->m_gi
->m_rectAll
;
2337 rect
.x
= HEADER_OFFSET_X
;
2338 rect
.y
= GetLineY(line
);
2339 rect
.width
= GetHeaderWidth();
2340 rect
.height
= GetLineHeight();
2345 wxRect
wxListMainWindow::GetLineLabelRect(size_t line
) const
2347 if ( !InReportView() )
2348 return GetLine(line
)->m_gi
->m_rectLabel
;
2351 rect
.x
= HEADER_OFFSET_X
;
2352 rect
.y
= GetLineY(line
);
2353 rect
.width
= GetColumnWidth(0);
2354 rect
.height
= GetLineHeight();
2359 wxRect
wxListMainWindow::GetLineIconRect(size_t line
) const
2361 if ( !InReportView() )
2362 return GetLine(line
)->m_gi
->m_rectIcon
;
2364 wxListLineData
*ld
= GetLine(line
);
2365 wxASSERT_MSG( ld
->HasImage(), _T("should have an image") );
2368 rect
.x
= HEADER_OFFSET_X
;
2369 rect
.y
= GetLineY(line
);
2370 GetImageSize(ld
->GetImage(), rect
.width
, rect
.height
);
2375 wxRect
wxListMainWindow::GetLineHighlightRect(size_t line
) const
2377 return InReportView() ? GetLineRect(line
)
2378 : GetLine(line
)->m_gi
->m_rectHighlight
;
2381 long wxListMainWindow::HitTestLine(size_t line
, int x
, int y
) const
2383 wxASSERT_MSG( line
< GetItemCount(), _T("invalid line in HitTestLine") );
2385 wxListLineData
*ld
= GetLine(line
);
2387 if ( ld
->HasImage() && GetLineIconRect(line
).Inside(x
, y
) )
2388 return wxLIST_HITTEST_ONITEMICON
;
2390 // VS: Testing for "ld->HasText() || InReportView()" instead of
2391 // "ld->HasText()" is needed to make empty lines in report view
2393 if ( ld
->HasText() || InReportView() )
2395 wxRect rect
= InReportView() ? GetLineRect(line
)
2396 : GetLineLabelRect(line
);
2398 if ( rect
.Inside(x
, y
) )
2399 return wxLIST_HITTEST_ONITEMLABEL
;
2405 // ----------------------------------------------------------------------------
2406 // highlight (selection) handling
2407 // ----------------------------------------------------------------------------
2409 bool wxListMainWindow::IsHighlighted(size_t line
) const
2413 return m_selStore
.IsSelected(line
);
2417 wxListLineData
*ld
= GetLine(line
);
2418 wxCHECK_MSG( ld
, false, _T("invalid index in IsHighlighted") );
2420 return ld
->IsHighlighted();
2424 void wxListMainWindow::HighlightLines( size_t lineFrom
,
2430 wxArrayInt linesChanged
;
2431 if ( !m_selStore
.SelectRange(lineFrom
, lineTo
, highlight
,
2434 // meny items changed state, refresh everything
2435 RefreshLines(lineFrom
, lineTo
);
2437 else // only a few items changed state, refresh only them
2439 size_t count
= linesChanged
.GetCount();
2440 for ( size_t n
= 0; n
< count
; n
++ )
2442 RefreshLine(linesChanged
[n
]);
2446 else // iterate over all items in non report view
2448 for ( size_t line
= lineFrom
; line
<= lineTo
; line
++ )
2450 if ( HighlightLine(line
, highlight
) )
2458 bool wxListMainWindow::HighlightLine( size_t line
, bool highlight
)
2464 changed
= m_selStore
.SelectItem(line
, highlight
);
2468 wxListLineData
*ld
= GetLine(line
);
2469 wxCHECK_MSG( ld
, false, _T("invalid index in HighlightLine") );
2471 changed
= ld
->Highlight(highlight
);
2476 SendNotify( line
, highlight
? wxEVT_COMMAND_LIST_ITEM_SELECTED
2477 : wxEVT_COMMAND_LIST_ITEM_DESELECTED
);
2483 void wxListMainWindow::RefreshLine( size_t line
)
2485 if ( InReportView() )
2487 size_t visibleFrom
, visibleTo
;
2488 GetVisibleLinesRange(&visibleFrom
, &visibleTo
);
2490 if ( line
< visibleFrom
|| line
> visibleTo
)
2494 wxRect rect
= GetLineRect(line
);
2496 CalcScrolledPosition( rect
.x
, rect
.y
, &rect
.x
, &rect
.y
);
2497 RefreshRect( rect
);
2500 void wxListMainWindow::RefreshLines( size_t lineFrom
, size_t lineTo
)
2502 // we suppose that they are ordered by caller
2503 wxASSERT_MSG( lineFrom
<= lineTo
, _T("indices in disorder") );
2505 wxASSERT_MSG( lineTo
< GetItemCount(), _T("invalid line range") );
2507 if ( InReportView() )
2509 size_t visibleFrom
, visibleTo
;
2510 GetVisibleLinesRange(&visibleFrom
, &visibleTo
);
2512 if ( lineFrom
< visibleFrom
)
2513 lineFrom
= visibleFrom
;
2514 if ( lineTo
> visibleTo
)
2519 rect
.y
= GetLineY(lineFrom
);
2520 rect
.width
= GetClientSize().x
;
2521 rect
.height
= GetLineY(lineTo
) - rect
.y
+ GetLineHeight();
2523 CalcScrolledPosition( rect
.x
, rect
.y
, &rect
.x
, &rect
.y
);
2524 RefreshRect( rect
);
2528 // TODO: this should be optimized...
2529 for ( size_t line
= lineFrom
; line
<= lineTo
; line
++ )
2536 void wxListMainWindow::RefreshAfter( size_t lineFrom
)
2538 if ( InReportView() )
2540 size_t visibleFrom
, visibleTo
;
2541 GetVisibleLinesRange(&visibleFrom
, &visibleTo
);
2543 if ( lineFrom
< visibleFrom
)
2544 lineFrom
= visibleFrom
;
2545 else if ( lineFrom
> visibleTo
)
2550 rect
.y
= GetLineY(lineFrom
);
2551 CalcScrolledPosition( rect
.x
, rect
.y
, &rect
.x
, &rect
.y
);
2553 wxSize size
= GetClientSize();
2554 rect
.width
= size
.x
;
2555 // refresh till the bottom of the window
2556 rect
.height
= size
.y
- rect
.y
;
2558 RefreshRect( rect
);
2562 // TODO: how to do it more efficiently?
2567 void wxListMainWindow::RefreshSelected()
2573 if ( InReportView() )
2575 GetVisibleLinesRange(&from
, &to
);
2580 to
= GetItemCount() - 1;
2583 if ( HasCurrent() && m_current
>= from
&& m_current
<= to
)
2585 RefreshLine(m_current
);
2588 for ( size_t line
= from
; line
<= to
; line
++ )
2590 // NB: the test works as expected even if m_current == -1
2591 if ( line
!= m_current
&& IsHighlighted(line
) )
2598 void wxListMainWindow::Freeze()
2603 void wxListMainWindow::Thaw()
2605 wxCHECK_RET( m_freezeCount
> 0, _T("thawing unfrozen list control?") );
2607 if ( !--m_freezeCount
)
2613 void wxListMainWindow::OnPaint( wxPaintEvent
&WXUNUSED(event
) )
2615 // Note: a wxPaintDC must be constructed even if no drawing is
2616 // done (a Windows requirement).
2617 wxPaintDC
dc( this );
2619 if ( IsEmpty() || m_freezeCount
)
2621 // nothing to draw or not the moment to draw it
2627 // delay the repainting until we calculate all the items positions
2634 CalcScrolledPosition( 0, 0, &dev_x
, &dev_y
);
2638 dc
.SetFont( GetFont() );
2640 if ( InReportView() )
2642 int lineHeight
= GetLineHeight();
2644 size_t visibleFrom
, visibleTo
;
2645 GetVisibleLinesRange(&visibleFrom
, &visibleTo
);
2648 wxCoord xOrig
, yOrig
;
2649 CalcUnscrolledPosition(0, 0, &xOrig
, &yOrig
);
2651 // tell the caller cache to cache the data
2654 wxListEvent
evCache(wxEVT_COMMAND_LIST_CACHE_HINT
,
2655 GetParent()->GetId());
2656 evCache
.SetEventObject( GetParent() );
2657 evCache
.m_oldItemIndex
= visibleFrom
;
2658 evCache
.m_itemIndex
= visibleTo
;
2659 GetParent()->GetEventHandler()->ProcessEvent( evCache
);
2662 for ( size_t line
= visibleFrom
; line
<= visibleTo
; line
++ )
2664 rectLine
= GetLineRect(line
);
2666 if ( !IsExposed(rectLine
.x
- xOrig
, rectLine
.y
- yOrig
,
2667 rectLine
.width
, rectLine
.height
) )
2669 // don't redraw unaffected lines to avoid flicker
2673 GetLine(line
)->DrawInReportMode( &dc
,
2675 GetLineHighlightRect(line
),
2676 IsHighlighted(line
) );
2679 if ( HasFlag(wxLC_HRULES
) )
2681 wxPen
pen(GetRuleColour(), 1, wxSOLID
);
2682 wxSize clientSize
= GetClientSize();
2684 // Don't draw the first one
2685 for ( size_t i
= visibleFrom
+1; i
<= visibleTo
; i
++ )
2688 dc
.SetBrush( *wxTRANSPARENT_BRUSH
);
2689 dc
.DrawLine(0 - dev_x
, i
*lineHeight
,
2690 clientSize
.x
- dev_x
, i
*lineHeight
);
2693 // Draw last horizontal rule
2694 if ( visibleTo
== GetItemCount() - 1 )
2697 dc
.SetBrush( *wxTRANSPARENT_BRUSH
);
2698 dc
.DrawLine(0 - dev_x
, (m_lineTo
+1)*lineHeight
,
2699 clientSize
.x
- dev_x
, (m_lineTo
+1)*lineHeight
);
2703 // Draw vertical rules if required
2704 if ( HasFlag(wxLC_VRULES
) && !IsEmpty() )
2706 wxPen
pen(GetRuleColour(), 1, wxSOLID
);
2708 wxRect firstItemRect
;
2709 wxRect lastItemRect
;
2710 GetItemRect(visibleFrom
, firstItemRect
);
2711 GetItemRect(visibleTo
, lastItemRect
);
2712 int x
= firstItemRect
.GetX();
2714 dc
.SetBrush(* wxTRANSPARENT_BRUSH
);
2715 for (int col
= 0; col
< GetColumnCount(); col
++)
2717 int colWidth
= GetColumnWidth(col
);
2719 dc
.DrawLine(x
- dev_x
- 2, firstItemRect
.GetY() - 1 - dev_y
,
2720 x
- dev_x
- 2, lastItemRect
.GetBottom() + 1 - dev_y
);
2726 size_t count
= GetItemCount();
2727 for ( size_t i
= 0; i
< count
; i
++ )
2729 GetLine(i
)->Draw( &dc
);
2734 // Don't draw rect outline under Mac at all.
2739 dc
.SetPen( *wxBLACK_PEN
);
2740 dc
.SetBrush( *wxTRANSPARENT_BRUSH
);
2741 dc
.DrawRectangle( GetLineHighlightRect(m_current
) );
2749 void wxListMainWindow::HighlightAll( bool on
)
2751 if ( IsSingleSel() )
2753 wxASSERT_MSG( !on
, _T("can't do this in a single sel control") );
2755 // we just have one item to turn off
2756 if ( HasCurrent() && IsHighlighted(m_current
) )
2758 HighlightLine(m_current
, false);
2759 RefreshLine(m_current
);
2764 HighlightLines(0, GetItemCount() - 1, on
);
2768 void wxListMainWindow::SendNotify( size_t line
,
2769 wxEventType command
,
2772 wxListEvent
le( command
, GetParent()->GetId() );
2773 le
.SetEventObject( GetParent() );
2774 le
.m_itemIndex
= line
;
2776 // set only for events which have position
2777 if ( point
!= wxDefaultPosition
)
2778 le
.m_pointDrag
= point
;
2780 // don't try to get the line info for virtual list controls: the main
2781 // program has it anyhow and if we did it would result in accessing all
2782 // the lines, even those which are not visible now and this is precisely
2783 // what we're trying to avoid
2784 if ( !IsVirtual() && (command
!= wxEVT_COMMAND_LIST_DELETE_ITEM
) )
2786 if ( line
!= (size_t)-1 )
2788 GetLine(line
)->GetItem( 0, le
.m_item
);
2790 //else: this happens for wxEVT_COMMAND_LIST_ITEM_FOCUSED event
2792 //else: there may be no more such item
2794 GetParent()->GetEventHandler()->ProcessEvent( le
);
2797 void wxListMainWindow::ChangeCurrent(size_t current
)
2799 m_current
= current
;
2801 SendNotify(current
, wxEVT_COMMAND_LIST_ITEM_FOCUSED
);
2804 void wxListMainWindow::EditLabel( long item
)
2806 wxCHECK_RET( (item
>= 0) && ((size_t)item
< GetItemCount()),
2807 wxT("wrong index in wxGenericListCtrl::EditLabel()") );
2809 size_t itemEdit
= (size_t)item
;
2811 wxListEvent
le( wxEVT_COMMAND_LIST_BEGIN_LABEL_EDIT
, GetParent()->GetId() );
2812 le
.SetEventObject( GetParent() );
2813 le
.m_itemIndex
= item
;
2814 wxListLineData
*data
= GetLine(itemEdit
);
2815 wxCHECK_RET( data
, _T("invalid index in EditLabel()") );
2816 data
->GetItem( 0, le
.m_item
);
2817 if ( GetParent()->GetEventHandler()->ProcessEvent( le
) && !le
.IsAllowed() )
2819 // vetoed by user code
2823 // We have to call this here because the label in question might just have
2824 // been added and no screen update taken place.
2828 wxListTextCtrl
*text
= new wxListTextCtrl(this, itemEdit
);
2833 void wxListMainWindow::OnRenameTimer()
2835 wxCHECK_RET( HasCurrent(), wxT("unexpected rename timer") );
2837 EditLabel( m_current
);
2840 bool wxListMainWindow::OnRenameAccept(size_t itemEdit
, const wxString
& value
)
2842 wxListEvent
le( wxEVT_COMMAND_LIST_END_LABEL_EDIT
, GetParent()->GetId() );
2843 le
.SetEventObject( GetParent() );
2844 le
.m_itemIndex
= itemEdit
;
2846 wxListLineData
*data
= GetLine(itemEdit
);
2847 wxCHECK_MSG( data
, false, _T("invalid index in OnRenameAccept()") );
2849 data
->GetItem( 0, le
.m_item
);
2850 le
.m_item
.m_text
= value
;
2851 return !GetParent()->GetEventHandler()->ProcessEvent( le
) ||
2855 void wxListMainWindow::OnRenameCancelled(size_t itemEdit
)
2857 // let owner know that the edit was cancelled
2858 wxListEvent
le( wxEVT_COMMAND_LIST_END_LABEL_EDIT
, GetParent()->GetId() );
2860 le
.SetEditCanceled(true);
2862 le
.SetEventObject( GetParent() );
2863 le
.m_itemIndex
= itemEdit
;
2865 wxListLineData
*data
= GetLine(itemEdit
);
2866 wxCHECK_RET( data
, _T("invalid index in OnRenameCancelled()") );
2868 data
->GetItem( 0, le
.m_item
);
2870 GetEventHandler()->ProcessEvent( le
);
2873 void wxListMainWindow::OnMouse( wxMouseEvent
&event
)
2875 event
.SetEventObject( GetParent() );
2876 if ( GetParent()->GetEventHandler()->ProcessEvent( event
) )
2879 if (event
.GetEventType() == wxEVT_MOUSEWHEEL
)
2881 // let the base handle mouse wheel events.
2886 if ( !HasCurrent() || IsEmpty() )
2892 if ( !(event
.Dragging() || event
.ButtonDown() || event
.LeftUp() ||
2893 event
.ButtonDClick()) )
2896 int x
= event
.GetX();
2897 int y
= event
.GetY();
2898 CalcUnscrolledPosition( x
, y
, &x
, &y
);
2900 // where did we hit it (if we did)?
2903 size_t count
= GetItemCount(),
2906 if ( InReportView() )
2908 current
= y
/ GetLineHeight();
2909 if ( current
< count
)
2910 hitResult
= HitTestLine(current
, x
, y
);
2914 // TODO: optimize it too! this is less simple than for report view but
2915 // enumerating all items is still not a way to do it!!
2916 for ( current
= 0; current
< count
; current
++ )
2918 hitResult
= HitTestLine(current
, x
, y
);
2924 if (event
.Dragging())
2926 if (m_dragCount
== 0)
2928 // we have to report the raw, physical coords as we want to be
2929 // able to call HitTest(event.m_pointDrag) from the user code to
2930 // get the item being dragged
2931 m_dragStart
= event
.GetPosition();
2936 if (m_dragCount
!= 3)
2939 int command
= event
.RightIsDown() ? wxEVT_COMMAND_LIST_BEGIN_RDRAG
2940 : wxEVT_COMMAND_LIST_BEGIN_DRAG
;
2942 wxListEvent
le( command
, GetParent()->GetId() );
2943 le
.SetEventObject( GetParent() );
2944 le
.m_itemIndex
= m_lineLastClicked
;
2945 le
.m_pointDrag
= m_dragStart
;
2946 GetParent()->GetEventHandler()->ProcessEvent( le
);
2957 // outside of any item
2961 bool forceClick
= false;
2962 if (event
.ButtonDClick())
2964 m_renameTimer
->Stop();
2965 m_lastOnSame
= false;
2967 if ( current
== m_lineLastClicked
)
2969 SendNotify( current
, wxEVT_COMMAND_LIST_ITEM_ACTIVATED
);
2975 // The first click was on another item, so don't interpret this as
2976 // a double click, but as a simple click instead
2983 if(m_lineSelectSingleOnUp
!= (size_t) -1)
2985 // select single line
2986 HighlightAll( false );
2987 ReverseHighlight(m_lineSelectSingleOnUp
);
2989 else if (m_lastOnSame
)
2991 if ((current
== m_current
) &&
2992 (hitResult
== wxLIST_HITTEST_ONITEMLABEL
) &&
2993 HasFlag(wxLC_EDIT_LABELS
) )
2995 m_renameTimer
->Start( 100, true );
2998 m_lastOnSame
= false;
2999 m_lineSelectSingleOnUp
= (size_t) -1;
3003 // This is neccessary , because after a DnD operation in
3004 // from and to ourself, the up event is swallowed by the
3005 // DnD code. So on next non-up event (which means here and
3006 // now) m_lineSelectSingleOnUp should be reset.
3007 m_lineSelectSingleOnUp
= (size_t) -1;
3009 if (event
.RightDown())
3011 m_lineBeforeLastClicked
= m_lineLastClicked
;
3012 m_lineLastClicked
= current
;
3013 // If the item is already selected, do not update the selection.
3014 // Multi-selections should not be cleared if a selected item is clicked.
3015 if (!IsHighlighted(current
))
3017 HighlightAll(false);
3018 ChangeCurrent(current
);
3019 ReverseHighlight(m_current
);
3021 SendNotify( current
, wxEVT_COMMAND_LIST_ITEM_RIGHT_CLICK
,
3022 event
.GetPosition() );
3023 // Allow generation of context menu event
3026 else if (event
.MiddleDown())
3028 SendNotify( current
, wxEVT_COMMAND_LIST_ITEM_MIDDLE_CLICK
);
3030 else if ( event
.LeftDown() || forceClick
)
3032 m_lineBeforeLastClicked
= m_lineLastClicked
;
3033 m_lineLastClicked
= current
;
3035 size_t oldCurrent
= m_current
;
3036 bool cmdModifierDown
= event
.CmdDown();
3037 if ( !(cmdModifierDown
|| event
.ShiftDown()) )
3039 if( IsSingleSel() || !IsHighlighted(current
) )
3041 HighlightAll( false );
3043 ChangeCurrent(current
);
3045 ReverseHighlight(m_current
);
3047 else // multi sel & current is highlighted & no mod keys
3049 m_lineSelectSingleOnUp
= current
;
3050 ChangeCurrent(current
); // change focus
3053 else // multi sel & either ctrl or shift is down
3055 if (cmdModifierDown
)
3057 ChangeCurrent(current
);
3059 ReverseHighlight(m_current
);
3061 else if (event
.ShiftDown())
3063 ChangeCurrent(current
);
3065 size_t lineFrom
= oldCurrent
,
3068 if ( lineTo
< lineFrom
)
3071 lineFrom
= m_current
;
3074 HighlightLines(lineFrom
, lineTo
);
3076 else // !ctrl, !shift
3078 // test in the enclosing if should make it impossible
3079 wxFAIL_MSG( _T("how did we get here?") );
3083 if (m_current
!= oldCurrent
)
3085 RefreshLine( oldCurrent
);
3088 // forceClick is only set if the previous click was on another item
3089 m_lastOnSame
= !forceClick
&& (m_current
== oldCurrent
);
3093 void wxListMainWindow::MoveToItem(size_t item
)
3095 if ( item
== (size_t)-1 )
3098 wxRect rect
= GetLineRect(item
);
3100 int client_w
, client_h
;
3101 GetClientSize( &client_w
, &client_h
);
3103 const int hLine
= GetLineHeight();
3105 int view_x
= SCROLL_UNIT_X
*GetScrollPos( wxHORIZONTAL
);
3106 int view_y
= hLine
*GetScrollPos( wxVERTICAL
);
3108 if ( InReportView() )
3110 // the next we need the range of lines shown it might be different, so
3112 ResetVisibleLinesRange();
3114 if (rect
.y
< view_y
)
3115 Scroll( -1, rect
.y
/hLine
);
3116 if (rect
.y
+rect
.height
+5 > view_y
+client_h
)
3117 Scroll( -1, (rect
.y
+rect
.height
-client_h
+hLine
)/hLine
);
3121 if (rect
.x
-view_x
< 5)
3122 Scroll( (rect
.x
-5)/SCROLL_UNIT_X
, -1 );
3123 if (rect
.x
+rect
.width
-5 > view_x
+client_w
)
3124 Scroll( (rect
.x
+rect
.width
-client_w
+SCROLL_UNIT_X
)/SCROLL_UNIT_X
, -1 );
3128 // ----------------------------------------------------------------------------
3129 // keyboard handling
3130 // ----------------------------------------------------------------------------
3132 void wxListMainWindow::OnArrowChar(size_t newCurrent
, const wxKeyEvent
& event
)
3134 wxCHECK_RET( newCurrent
< (size_t)GetItemCount(),
3135 _T("invalid item index in OnArrowChar()") );
3137 size_t oldCurrent
= m_current
;
3139 // in single selection we just ignore Shift as we can't select several
3141 if ( event
.ShiftDown() && !IsSingleSel() )
3143 ChangeCurrent(newCurrent
);
3145 // refresh the old focus to remove it
3146 RefreshLine( oldCurrent
);
3148 // select all the items between the old and the new one
3149 if ( oldCurrent
> newCurrent
)
3151 newCurrent
= oldCurrent
;
3152 oldCurrent
= m_current
;
3155 HighlightLines(oldCurrent
, newCurrent
);
3159 // all previously selected items are unselected unless ctrl is held
3160 if ( !event
.ControlDown() )
3161 HighlightAll(false);
3163 ChangeCurrent(newCurrent
);
3165 // refresh the old focus to remove it
3166 RefreshLine( oldCurrent
);
3168 if ( !event
.ControlDown() )
3170 HighlightLine( m_current
, true );
3174 RefreshLine( m_current
);
3179 void wxListMainWindow::OnKeyDown( wxKeyEvent
&event
)
3181 wxWindow
*parent
= GetParent();
3183 /* we propagate the key event up */
3184 wxKeyEvent
ke( wxEVT_KEY_DOWN
);
3185 ke
.m_shiftDown
= event
.m_shiftDown
;
3186 ke
.m_controlDown
= event
.m_controlDown
;
3187 ke
.m_altDown
= event
.m_altDown
;
3188 ke
.m_metaDown
= event
.m_metaDown
;
3189 ke
.m_keyCode
= event
.m_keyCode
;
3192 ke
.SetEventObject( parent
);
3193 if (parent
->GetEventHandler()->ProcessEvent( ke
)) return;
3198 void wxListMainWindow::OnChar( wxKeyEvent
&event
)
3200 wxWindow
*parent
= GetParent();
3202 /* we send a list_key event up */
3205 wxListEvent
le( wxEVT_COMMAND_LIST_KEY_DOWN
, GetParent()->GetId() );
3206 le
.m_itemIndex
= m_current
;
3207 GetLine(m_current
)->GetItem( 0, le
.m_item
);
3208 le
.m_code
= event
.GetKeyCode();
3209 le
.SetEventObject( parent
);
3210 parent
->GetEventHandler()->ProcessEvent( le
);
3213 /* we propagate the char event up */
3214 wxKeyEvent
ke( wxEVT_CHAR
);
3215 ke
.m_shiftDown
= event
.m_shiftDown
;
3216 ke
.m_controlDown
= event
.m_controlDown
;
3217 ke
.m_altDown
= event
.m_altDown
;
3218 ke
.m_metaDown
= event
.m_metaDown
;
3219 ke
.m_keyCode
= event
.m_keyCode
;
3222 ke
.SetEventObject( parent
);
3223 if (parent
->GetEventHandler()->ProcessEvent( ke
)) return;
3225 if (event
.GetKeyCode() == WXK_TAB
)
3227 wxNavigationKeyEvent nevent
;
3228 nevent
.SetWindowChange( event
.ControlDown() );
3229 nevent
.SetDirection( !event
.ShiftDown() );
3230 nevent
.SetEventObject( GetParent()->GetParent() );
3231 nevent
.SetCurrentFocus( m_parent
);
3232 if (GetParent()->GetParent()->GetEventHandler()->ProcessEvent( nevent
))
3236 /* no item -> nothing to do */
3243 switch (event
.GetKeyCode())
3246 if ( m_current
> 0 )
3247 OnArrowChar( m_current
- 1, event
);
3251 if ( m_current
< (size_t)GetItemCount() - 1 )
3252 OnArrowChar( m_current
+ 1, event
);
3257 OnArrowChar( GetItemCount() - 1, event
);
3262 OnArrowChar( 0, event
);
3267 int steps
= InReportView() ? m_linesPerPage
- 1 : m_current
% m_linesPerPage
;
3269 int index
= m_current
- steps
;
3273 OnArrowChar( index
, event
);
3279 int steps
= InReportView()
3280 ? m_linesPerPage
- 1
3281 : m_linesPerPage
- (m_current
% m_linesPerPage
) - 1;
3283 size_t index
= m_current
+ steps
;
3284 size_t count
= GetItemCount();
3285 if ( index
>= count
)
3288 OnArrowChar( index
, event
);
3293 if ( !InReportView() )
3295 int index
= m_current
- m_linesPerPage
;
3299 OnArrowChar( index
, event
);
3304 if ( !InReportView() )
3306 size_t index
= m_current
+ m_linesPerPage
;
3308 size_t count
= GetItemCount();
3309 if ( index
>= count
)
3312 OnArrowChar( index
, event
);
3317 if ( IsSingleSel() )
3319 SendNotify( m_current
, wxEVT_COMMAND_LIST_ITEM_ACTIVATED
);
3321 if ( IsHighlighted(m_current
) )
3323 // don't unselect the item in single selection mode
3326 //else: select it in ReverseHighlight() below if unselected
3329 ReverseHighlight(m_current
);
3334 SendNotify( m_current
, wxEVT_COMMAND_LIST_ITEM_ACTIVATED
);
3342 // ----------------------------------------------------------------------------
3344 // ----------------------------------------------------------------------------
3346 void wxListMainWindow::OnSetFocus( wxFocusEvent
&WXUNUSED(event
) )
3350 wxFocusEvent
event( wxEVT_SET_FOCUS
, GetParent()->GetId() );
3351 event
.SetEventObject( GetParent() );
3352 if ( GetParent()->GetEventHandler()->ProcessEvent( event
) )
3356 // wxGTK sends us EVT_SET_FOCUS events even if we had never got
3357 // EVT_KILL_FOCUS before which means that we finish by redrawing the items
3358 // which are already drawn correctly resulting in horrible flicker - avoid
3368 void wxListMainWindow::OnKillFocus( wxFocusEvent
&WXUNUSED(event
) )
3372 wxFocusEvent
event( wxEVT_KILL_FOCUS
, GetParent()->GetId() );
3373 event
.SetEventObject( GetParent() );
3374 if ( GetParent()->GetEventHandler()->ProcessEvent( event
) )
3381 void wxListMainWindow::DrawImage( int index
, wxDC
*dc
, int x
, int y
)
3383 if ( HasFlag(wxLC_ICON
) && (m_normal_image_list
))
3385 m_normal_image_list
->Draw( index
, *dc
, x
, y
, wxIMAGELIST_DRAW_TRANSPARENT
);
3387 else if ( HasFlag(wxLC_SMALL_ICON
) && (m_small_image_list
))
3389 m_small_image_list
->Draw( index
, *dc
, x
, y
, wxIMAGELIST_DRAW_TRANSPARENT
);
3391 else if ( HasFlag(wxLC_LIST
) && (m_small_image_list
))
3393 m_small_image_list
->Draw( index
, *dc
, x
, y
, wxIMAGELIST_DRAW_TRANSPARENT
);
3395 else if ( InReportView() && (m_small_image_list
))
3397 m_small_image_list
->Draw( index
, *dc
, x
, y
, wxIMAGELIST_DRAW_TRANSPARENT
);
3401 void wxListMainWindow::GetImageSize( int index
, int &width
, int &height
) const
3403 if ( HasFlag(wxLC_ICON
) && m_normal_image_list
)
3405 m_normal_image_list
->GetSize( index
, width
, height
);
3407 else if ( HasFlag(wxLC_SMALL_ICON
) && m_small_image_list
)
3409 m_small_image_list
->GetSize( index
, width
, height
);
3411 else if ( HasFlag(wxLC_LIST
) && m_small_image_list
)
3413 m_small_image_list
->GetSize( index
, width
, height
);
3415 else if ( InReportView() && m_small_image_list
)
3417 m_small_image_list
->GetSize( index
, width
, height
);
3426 int wxListMainWindow::GetTextLength( const wxString
&s
) const
3428 wxClientDC
dc( wxConstCast(this, wxListMainWindow
) );
3429 dc
.SetFont( GetFont() );
3432 dc
.GetTextExtent( s
, &lw
, NULL
);
3434 return lw
+ AUTOSIZE_COL_MARGIN
;
3437 void wxListMainWindow::SetImageList( wxImageListType
*imageList
, int which
)
3441 // calc the spacing from the icon size
3444 if ((imageList
) && (imageList
->GetImageCount()) )
3446 imageList
->GetSize(0, width
, height
);
3449 if (which
== wxIMAGE_LIST_NORMAL
)
3451 m_normal_image_list
= imageList
;
3452 m_normal_spacing
= width
+ 8;
3455 if (which
== wxIMAGE_LIST_SMALL
)
3457 m_small_image_list
= imageList
;
3458 m_small_spacing
= width
+ 14;
3459 m_lineHeight
= 0; // ensure that the line height will be recalc'd
3463 void wxListMainWindow::SetItemSpacing( int spacing
, bool isSmall
)
3468 m_small_spacing
= spacing
;
3472 m_normal_spacing
= spacing
;
3476 int wxListMainWindow::GetItemSpacing( bool isSmall
)
3478 return isSmall
? m_small_spacing
: m_normal_spacing
;
3481 // ----------------------------------------------------------------------------
3483 // ----------------------------------------------------------------------------
3485 void wxListMainWindow::SetColumn( int col
, wxListItem
&item
)
3487 wxListHeaderDataList::compatibility_iterator node
= m_columns
.Item( col
);
3489 wxCHECK_RET( node
, _T("invalid column index in SetColumn") );
3491 if ( item
.m_width
== wxLIST_AUTOSIZE_USEHEADER
)
3492 item
.m_width
= GetTextLength( item
.m_text
);
3494 wxListHeaderData
*column
= node
->GetData();
3495 column
->SetItem( item
);
3497 wxListHeaderWindow
*headerWin
= GetListCtrl()->m_headerWin
;
3499 headerWin
->m_dirty
= true;
3503 // invalidate it as it has to be recalculated
3507 void wxListMainWindow::SetColumnWidth( int col
, int width
)
3509 wxCHECK_RET( col
>= 0 && col
< GetColumnCount(),
3510 _T("invalid column index") );
3512 wxCHECK_RET( InReportView(),
3513 _T("SetColumnWidth() can only be called in report mode.") );
3516 wxListHeaderWindow
*headerWin
= GetListCtrl()->m_headerWin
;
3518 headerWin
->m_dirty
= true;
3520 wxListHeaderDataList::compatibility_iterator node
= m_columns
.Item( col
);
3521 wxCHECK_RET( node
, _T("no column?") );
3523 wxListHeaderData
*column
= node
->GetData();
3525 size_t count
= GetItemCount();
3527 if (width
== wxLIST_AUTOSIZE_USEHEADER
)
3529 width
= GetTextLength(column
->GetText());
3531 else if ( width
== wxLIST_AUTOSIZE
)
3535 // TODO: determine the max width somehow...
3536 width
= WIDTH_COL_DEFAULT
;
3540 wxClientDC
dc(this);
3541 dc
.SetFont( GetFont() );
3543 int max
= AUTOSIZE_COL_MARGIN
;
3545 for ( size_t i
= 0; i
< count
; i
++ )
3547 wxListLineData
*line
= GetLine(i
);
3548 wxListItemDataList::compatibility_iterator n
= line
->m_items
.Item( col
);
3550 wxCHECK_RET( n
, _T("no subitem?") );
3552 wxListItemData
*item
= n
->GetData();
3555 if (item
->HasImage())
3558 GetImageSize( item
->GetImage(), ix
, iy
);
3562 if (item
->HasText())
3565 dc
.GetTextExtent( item
->GetText(), &w
, NULL
);
3573 width
= max
+ AUTOSIZE_COL_MARGIN
;
3577 column
->SetWidth( width
);
3579 // invalidate it as it has to be recalculated
3583 int wxListMainWindow::GetHeaderWidth() const
3585 if ( !m_headerWidth
)
3587 wxListMainWindow
*self
= wxConstCast(this, wxListMainWindow
);
3589 size_t count
= GetColumnCount();
3590 for ( size_t col
= 0; col
< count
; col
++ )
3592 self
->m_headerWidth
+= GetColumnWidth(col
);
3596 return m_headerWidth
;
3599 void wxListMainWindow::GetColumn( int col
, wxListItem
&item
) const
3601 wxListHeaderDataList::compatibility_iterator node
= m_columns
.Item( col
);
3602 wxCHECK_RET( node
, _T("invalid column index in GetColumn") );
3604 wxListHeaderData
*column
= node
->GetData();
3605 column
->GetItem( item
);
3608 int wxListMainWindow::GetColumnWidth( int col
) const
3610 wxListHeaderDataList::compatibility_iterator node
= m_columns
.Item( col
);
3611 wxCHECK_MSG( node
, 0, _T("invalid column index") );
3613 wxListHeaderData
*column
= node
->GetData();
3614 return column
->GetWidth();
3617 // ----------------------------------------------------------------------------
3619 // ----------------------------------------------------------------------------
3621 void wxListMainWindow::SetItem( wxListItem
&item
)
3623 long id
= item
.m_itemId
;
3624 wxCHECK_RET( id
>= 0 && (size_t)id
< GetItemCount(),
3625 _T("invalid item index in SetItem") );
3629 wxListLineData
*line
= GetLine((size_t)id
);
3630 line
->SetItem( item
.m_col
, item
);
3633 // update the item on screen
3635 GetItemRect(id
, rectItem
);
3636 RefreshRect(rectItem
);
3639 void wxListMainWindow::SetItemStateAll(long state
, long stateMask
)
3644 // first deal with selection
3645 if ( stateMask
& wxLIST_STATE_SELECTED
)
3647 // set/clear select state
3650 // optimized version for virtual listctrl.
3651 m_selStore
.SelectRange(0, GetItemCount() - 1, state
== wxLIST_STATE_SELECTED
);
3654 else if ( state
& wxLIST_STATE_SELECTED
)
3656 const long count
= GetItemCount();
3657 for( long i
= 0; i
< count
; i
++ )
3659 SetItemState( i
, wxLIST_STATE_SELECTED
, wxLIST_STATE_SELECTED
);
3665 // clear for non virtual (somewhat optimized by using GetNextItem())
3667 while ( (i
= GetNextItem(i
, wxLIST_NEXT_ALL
, wxLIST_STATE_SELECTED
)) != -1 )
3669 SetItemState( i
, 0, wxLIST_STATE_SELECTED
);
3674 if ( HasCurrent() && (state
== 0) && (stateMask
& wxLIST_STATE_FOCUSED
) )
3676 // unfocus all: only one item can be focussed, so clearing focus for
3677 // all items is simply clearing focus of the focussed item.
3678 SetItemState(m_current
, state
, stateMask
);
3680 //(setting focus to all items makes no sense, so it is not handled here.)
3683 void wxListMainWindow::SetItemState( long litem
, long state
, long stateMask
)
3687 SetItemStateAll(state
, stateMask
);
3691 wxCHECK_RET( litem
>= 0 && (size_t)litem
< GetItemCount(),
3692 _T("invalid list ctrl item index in SetItem") );
3694 size_t oldCurrent
= m_current
;
3695 size_t item
= (size_t)litem
; // safe because of the check above
3697 // do we need to change the focus?
3698 if ( stateMask
& wxLIST_STATE_FOCUSED
)
3700 if ( state
& wxLIST_STATE_FOCUSED
)
3702 // don't do anything if this item is already focused
3703 if ( item
!= m_current
)
3705 ChangeCurrent(item
);
3707 if ( oldCurrent
!= (size_t)-1 )
3709 if ( IsSingleSel() )
3711 HighlightLine(oldCurrent
, false);
3714 RefreshLine(oldCurrent
);
3717 RefreshLine( m_current
);
3722 // don't do anything if this item is not focused
3723 if ( item
== m_current
)
3727 if ( IsSingleSel() )
3729 // we must unselect the old current item as well or we
3730 // might end up with more than one selected item in a
3731 // single selection control
3732 HighlightLine(oldCurrent
, false);
3735 RefreshLine( oldCurrent
);
3740 // do we need to change the selection state?
3741 if ( stateMask
& wxLIST_STATE_SELECTED
)
3743 bool on
= (state
& wxLIST_STATE_SELECTED
) != 0;
3745 if ( IsSingleSel() )
3749 // selecting the item also makes it the focused one in the
3751 if ( m_current
!= item
)
3753 ChangeCurrent(item
);
3755 if ( oldCurrent
!= (size_t)-1 )
3757 HighlightLine( oldCurrent
, false );
3758 RefreshLine( oldCurrent
);
3764 // only the current item may be selected anyhow
3765 if ( item
!= m_current
)
3770 if ( HighlightLine(item
, on
) )
3777 int wxListMainWindow::GetItemState( long item
, long stateMask
) const
3779 wxCHECK_MSG( item
>= 0 && (size_t)item
< GetItemCount(), 0,
3780 _T("invalid list ctrl item index in GetItemState()") );
3782 int ret
= wxLIST_STATE_DONTCARE
;
3784 if ( stateMask
& wxLIST_STATE_FOCUSED
)
3786 if ( (size_t)item
== m_current
)
3787 ret
|= wxLIST_STATE_FOCUSED
;
3790 if ( stateMask
& wxLIST_STATE_SELECTED
)
3792 if ( IsHighlighted(item
) )
3793 ret
|= wxLIST_STATE_SELECTED
;
3799 void wxListMainWindow::GetItem( wxListItem
&item
) const
3801 wxCHECK_RET( item
.m_itemId
>= 0 && (size_t)item
.m_itemId
< GetItemCount(),
3802 _T("invalid item index in GetItem") );
3804 wxListLineData
*line
= GetLine((size_t)item
.m_itemId
);
3805 line
->GetItem( item
.m_col
, item
);
3808 // ----------------------------------------------------------------------------
3810 // ----------------------------------------------------------------------------
3812 size_t wxListMainWindow::GetItemCount() const
3814 return IsVirtual() ? m_countVirt
: m_lines
.GetCount();
3817 void wxListMainWindow::SetItemCount(long count
)
3819 m_selStore
.SetItemCount(count
);
3820 m_countVirt
= count
;
3822 ResetVisibleLinesRange();
3824 // scrollbars must be reset
3828 int wxListMainWindow::GetSelectedItemCount() const
3830 // deal with the quick case first
3831 if ( IsSingleSel() )
3833 return HasCurrent() ? IsHighlighted(m_current
) : false;
3836 // virtual controls remmebers all its selections itself
3838 return m_selStore
.GetSelectedCount();
3840 // TODO: we probably should maintain the number of items selected even for
3841 // non virtual controls as enumerating all lines is really slow...
3842 size_t countSel
= 0;
3843 size_t count
= GetItemCount();
3844 for ( size_t line
= 0; line
< count
; line
++ )
3846 if ( GetLine(line
)->IsHighlighted() )
3853 // ----------------------------------------------------------------------------
3854 // item position/size
3855 // ----------------------------------------------------------------------------
3857 wxRect
wxListMainWindow::GetViewRect() const
3859 wxASSERT_MSG( !HasFlag(wxLC_REPORT
| wxLC_LIST
),
3860 _T("wxListCtrl::GetViewRect() only works in icon mode") );
3862 // we need to find the longest/tallest label
3865 const int count
= GetItemCount();
3868 for ( int i
= 0; i
< count
; i
++ )
3873 wxCoord x
= r
.GetRight(),
3883 // some fudge needed to make it look prettier
3884 xMax
+= 2*EXTRA_BORDER_X
;
3885 yMax
+= 2*EXTRA_BORDER_Y
;
3887 // account for the scrollbars if necessary
3888 const wxSize sizeAll
= GetClientSize();
3889 if ( xMax
> sizeAll
.x
)
3890 yMax
+= wxSystemSettings::GetMetric(wxSYS_HSCROLL_Y
);
3891 if ( yMax
> sizeAll
.y
)
3892 xMax
+= wxSystemSettings::GetMetric(wxSYS_VSCROLL_X
);
3894 return wxRect(0, 0, xMax
, yMax
);
3897 void wxListMainWindow::GetItemRect( long index
, wxRect
&rect
) const
3899 wxCHECK_RET( index
>= 0 && (size_t)index
< GetItemCount(),
3900 _T("invalid index in GetItemRect") );
3902 // ensure that we're laid out, otherwise we could return nonsense
3905 wxConstCast(this, wxListMainWindow
)->
3906 RecalculatePositions(true /* no refresh */);
3909 rect
= GetLineRect((size_t)index
);
3911 CalcScrolledPosition(rect
.x
, rect
.y
, &rect
.x
, &rect
.y
);
3914 bool wxListMainWindow::GetItemPosition(long item
, wxPoint
& pos
) const
3917 GetItemRect(item
, rect
);
3925 // ----------------------------------------------------------------------------
3926 // geometry calculation
3927 // ----------------------------------------------------------------------------
3929 void wxListMainWindow::RecalculatePositions(bool noRefresh
)
3931 wxClientDC
dc( this );
3932 dc
.SetFont( GetFont() );
3934 const size_t count
= GetItemCount();
3937 if ( HasFlag(wxLC_ICON
) )
3938 iconSpacing
= m_normal_spacing
;
3939 else if ( HasFlag(wxLC_SMALL_ICON
) )
3940 iconSpacing
= m_small_spacing
;
3944 // Note that we do not call GetClientSize() here but
3945 // GetSize() and subtract the border size for sunken
3946 // borders manually. This is technically incorrect,
3947 // but we need to know the client area's size WITHOUT
3948 // scrollbars here. Since we don't know if there are
3949 // any scrollbars, we use GetSize() instead. Another
3950 // solution would be to call SetScrollbars() here to
3951 // remove the scrollbars and call GetClientSize() then,
3952 // but this might result in flicker and - worse - will
3953 // reset the scrollbars to 0 which is not good at all
3954 // if you resize a dialog/window, but don't want to
3955 // reset the window scrolling. RR.
3956 // Furthermore, we actually do NOT subtract the border
3957 // width as 2 pixels is just the extra space which we
3958 // need around the actual content in the window. Other-
3959 // wise the text would e.g. touch the upper border. RR.
3962 GetSize( &clientWidth
, &clientHeight
);
3964 const int lineHeight
= GetLineHeight();
3966 if ( InReportView() )
3968 // all lines have the same height and we scroll one line per step
3969 int entireHeight
= count
*lineHeight
+ LINE_SPACING
;
3971 m_linesPerPage
= clientHeight
/ lineHeight
;
3973 ResetVisibleLinesRange();
3975 SetScrollbars( SCROLL_UNIT_X
, lineHeight
,
3976 GetHeaderWidth() / SCROLL_UNIT_X
,
3977 (entireHeight
+ lineHeight
- 1) / lineHeight
,
3978 GetScrollPos(wxHORIZONTAL
),
3979 GetScrollPos(wxVERTICAL
),
3984 // we have 3 different layout strategies: either layout all items
3985 // horizontally/vertically (wxLC_ALIGN_XXX styles explicitly given) or
3986 // to arrange them in top to bottom, left to right (don't ask me why
3987 // not the other way round...) order
3988 if ( HasFlag(wxLC_ALIGN_LEFT
| wxLC_ALIGN_TOP
) )
3990 int x
= EXTRA_BORDER_X
;
3991 int y
= EXTRA_BORDER_Y
;
3993 wxCoord widthMax
= 0;
3996 for ( i
= 0; i
< count
; i
++ )
3998 wxListLineData
*line
= GetLine(i
);
3999 line
->CalculateSize( &dc
, iconSpacing
);
4000 line
->SetPosition( x
, y
, iconSpacing
);
4002 wxSize sizeLine
= GetLineSize(i
);
4004 if ( HasFlag(wxLC_ALIGN_TOP
) )
4006 if ( sizeLine
.x
> widthMax
)
4007 widthMax
= sizeLine
.x
;
4011 else // wxLC_ALIGN_LEFT
4013 x
+= sizeLine
.x
+ MARGIN_BETWEEN_ROWS
;
4017 if ( HasFlag(wxLC_ALIGN_TOP
) )
4019 // traverse the items again and tweak their sizes so that they are
4020 // all the same in a row
4021 for ( i
= 0; i
< count
; i
++ )
4023 wxListLineData
*line
= GetLine(i
);
4024 line
->m_gi
->ExtendWidth(widthMax
);
4033 (x
+ SCROLL_UNIT_X
) / SCROLL_UNIT_X
,
4034 (y
+ lineHeight
) / lineHeight
,
4035 GetScrollPos( wxHORIZONTAL
),
4036 GetScrollPos( wxVERTICAL
),
4040 else // "flowed" arrangement, the most complicated case
4042 // at first we try without any scrollbars, if the items don't fit into
4043 // the window, we recalculate after subtracting the space taken by the
4046 int entireWidth
= 0;
4048 for (int tries
= 0; tries
< 2; tries
++)
4050 entireWidth
= 2*EXTRA_BORDER_X
;
4054 // Now we have decided that the items do not fit into the
4055 // client area, so we need a scrollbar
4056 entireWidth
+= SCROLL_UNIT_X
;
4059 int x
= EXTRA_BORDER_X
;
4060 int y
= EXTRA_BORDER_Y
;
4061 int maxWidthInThisRow
= 0;
4064 int currentlyVisibleLines
= 0;
4066 for (size_t i
= 0; i
< count
; i
++)
4068 currentlyVisibleLines
++;
4069 wxListLineData
*line
= GetLine(i
);
4070 line
->CalculateSize( &dc
, iconSpacing
);
4071 line
->SetPosition( x
, y
, iconSpacing
);
4073 wxSize sizeLine
= GetLineSize(i
);
4075 if ( maxWidthInThisRow
< sizeLine
.x
)
4076 maxWidthInThisRow
= sizeLine
.x
;
4079 if (currentlyVisibleLines
> m_linesPerPage
)
4080 m_linesPerPage
= currentlyVisibleLines
;
4082 if ( y
+ sizeLine
.y
>= clientHeight
)
4084 currentlyVisibleLines
= 0;
4086 maxWidthInThisRow
+= MARGIN_BETWEEN_ROWS
;
4087 x
+= maxWidthInThisRow
;
4088 entireWidth
+= maxWidthInThisRow
;
4089 maxWidthInThisRow
= 0;
4092 // We have reached the last item.
4093 if ( i
== count
- 1 )
4094 entireWidth
+= maxWidthInThisRow
;
4096 if ( (tries
== 0) &&
4097 (entireWidth
+ SCROLL_UNIT_X
> clientWidth
) )
4099 clientHeight
-= wxSystemSettings::
4100 GetMetric(wxSYS_HSCROLL_Y
);
4105 if ( i
== count
- 1 )
4106 tries
= 1; // Everything fits, no second try required.
4114 (entireWidth
+ SCROLL_UNIT_X
) / SCROLL_UNIT_X
,
4116 GetScrollPos( wxHORIZONTAL
),
4125 // FIXME: why should we call it from here?
4132 void wxListMainWindow::RefreshAll()
4137 wxListHeaderWindow
*headerWin
= GetListCtrl()->m_headerWin
;
4138 if ( headerWin
&& headerWin
->m_dirty
)
4140 headerWin
->m_dirty
= false;
4141 headerWin
->Refresh();
4145 void wxListMainWindow::UpdateCurrent()
4147 if ( !HasCurrent() && !IsEmpty() )
4153 long wxListMainWindow::GetNextItem( long item
,
4154 int WXUNUSED(geometry
),
4158 max
= GetItemCount();
4159 wxCHECK_MSG( (ret
== -1) || (ret
< max
), -1,
4160 _T("invalid listctrl index in GetNextItem()") );
4162 // notice that we start with the next item (or the first one if item == -1)
4163 // and this is intentional to allow writing a simple loop to iterate over
4164 // all selected items
4168 // this is not an error because the index was ok initially, just no
4179 size_t count
= GetItemCount();
4180 for ( size_t line
= (size_t)ret
; line
< count
; line
++ )
4182 if ( (state
& wxLIST_STATE_FOCUSED
) && (line
== m_current
) )
4185 if ( (state
& wxLIST_STATE_SELECTED
) && IsHighlighted(line
) )
4192 // ----------------------------------------------------------------------------
4194 // ----------------------------------------------------------------------------
4196 void wxListMainWindow::DeleteItem( long lindex
)
4198 size_t count
= GetItemCount();
4200 wxCHECK_RET( (lindex
>= 0) && ((size_t)lindex
< count
),
4201 _T("invalid item index in DeleteItem") );
4203 size_t index
= (size_t)lindex
;
4205 // we don't need to adjust the index for the previous items
4206 if ( HasCurrent() && m_current
>= index
)
4208 // if the current item is being deleted, we want the next one to
4209 // become selected - unless there is no next one - so don't adjust
4210 // m_current in this case
4211 if ( m_current
!= index
|| m_current
== count
- 1 )
4217 if ( InReportView() )
4219 ResetVisibleLinesRange();
4226 m_selStore
.OnItemDelete(index
);
4230 m_lines
.RemoveAt( index
);
4233 // we need to refresh the (vert) scrollbar as the number of items changed
4236 SendNotify( index
, wxEVT_COMMAND_LIST_DELETE_ITEM
);
4238 RefreshAfter(index
);
4241 void wxListMainWindow::DeleteColumn( int col
)
4243 wxListHeaderDataList::compatibility_iterator node
= m_columns
.Item( col
);
4245 wxCHECK_RET( node
, wxT("invalid column index in DeleteColumn()") );
4248 delete node
->GetData();
4249 m_columns
.Erase( node
);
4253 // update all the items
4254 for ( size_t i
= 0; i
< m_lines
.GetCount(); i
++ )
4256 wxListLineData
* const line
= GetLine(i
);
4257 wxListItemDataList::compatibility_iterator n
= line
->m_items
.Item( col
);
4258 delete n
->GetData();
4259 line
->m_items
.Erase(n
);
4263 // invalidate it as it has to be recalculated
4267 void wxListMainWindow::DoDeleteAllItems()
4271 // nothing to do - in particular, don't send the event
4277 // to make the deletion of all items faster, we don't send the
4278 // notifications for each item deletion in this case but only one event
4279 // for all of them: this is compatible with wxMSW and documented in
4280 // DeleteAllItems() description
4282 wxListEvent
event( wxEVT_COMMAND_LIST_DELETE_ALL_ITEMS
, GetParent()->GetId() );
4283 event
.SetEventObject( GetParent() );
4284 GetParent()->GetEventHandler()->ProcessEvent( event
);
4293 if ( InReportView() )
4295 ResetVisibleLinesRange();
4301 void wxListMainWindow::DeleteAllItems()
4305 RecalculatePositions();
4308 void wxListMainWindow::DeleteEverything()
4310 WX_CLEAR_LIST(wxListHeaderDataList
, m_columns
);
4315 // ----------------------------------------------------------------------------
4316 // scanning for an item
4317 // ----------------------------------------------------------------------------
4319 void wxListMainWindow::EnsureVisible( long index
)
4321 wxCHECK_RET( index
>= 0 && (size_t)index
< GetItemCount(),
4322 _T("invalid index in EnsureVisible") );
4324 // We have to call this here because the label in question might just have
4325 // been added and its position is not known yet
4328 RecalculatePositions(true /* no refresh */);
4331 MoveToItem((size_t)index
);
4334 long wxListMainWindow::FindItem(long start
, const wxString
& str
, bool WXUNUSED(partial
) )
4341 size_t count
= GetItemCount();
4342 for ( size_t i
= (size_t)pos
; i
< count
; i
++ )
4344 wxListLineData
*line
= GetLine(i
);
4345 if ( line
->GetText(0) == tmp
)
4352 long wxListMainWindow::FindItem(long start
, wxUIntPtr data
)
4358 size_t count
= GetItemCount();
4359 for (size_t i
= (size_t)pos
; i
< count
; i
++)
4361 wxListLineData
*line
= GetLine(i
);
4363 line
->GetItem( 0, item
);
4364 if (item
.m_data
== data
)
4371 long wxListMainWindow::FindItem( const wxPoint
& pt
)
4374 GetVisibleLinesRange(&topItem
, NULL
);
4377 GetItemPosition( GetItemCount()-1, p
);
4380 long id
= (long) floor( pt
.y
*double(GetItemCount()-topItem
-1)/p
.y
+topItem
);
4381 if( id
>= 0 && id
< (long)GetItemCount() )
4387 long wxListMainWindow::HitTest( int x
, int y
, int &flags
)
4389 CalcUnscrolledPosition( x
, y
, &x
, &y
);
4391 size_t count
= GetItemCount();
4393 if ( InReportView() )
4395 size_t current
= y
/ GetLineHeight();
4396 if ( current
< count
)
4398 flags
= HitTestLine(current
, x
, y
);
4405 // TODO: optimize it too! this is less simple than for report view but
4406 // enumerating all items is still not a way to do it!!
4407 for ( size_t current
= 0; current
< count
; current
++ )
4409 flags
= HitTestLine(current
, x
, y
);
4418 // ----------------------------------------------------------------------------
4420 // ----------------------------------------------------------------------------
4422 void wxListMainWindow::InsertItem( wxListItem
&item
)
4424 wxASSERT_MSG( !IsVirtual(), _T("can't be used with virtual control") );
4426 int count
= GetItemCount();
4427 wxCHECK_RET( item
.m_itemId
>= 0, _T("invalid item index") );
4429 if (item
.m_itemId
> count
)
4430 item
.m_itemId
= count
;
4432 size_t id
= item
.m_itemId
;
4437 // this is unused variable
4440 if ( InReportView() )
4443 // this is unused variable
4446 ResetVisibleLinesRange();
4448 else if ( HasFlag(wxLC_LIST
) )
4450 // this is unused variable
4455 else if ( HasFlag(wxLC_ICON
) )
4457 // this is unused variable
4462 else if ( HasFlag(wxLC_SMALL_ICON
) )
4464 // this is unused variable
4465 mode
= wxLC_ICON
; // no typo
4471 wxFAIL_MSG( _T("unknown mode") );
4474 wxListLineData
*line
= new wxListLineData(this);
4476 line
->SetItem( item
.m_col
, item
);
4478 m_lines
.Insert( line
, id
);
4482 // If an item is selected at or below the point of insertion, we need to
4483 // increment the member variables because the current row's index has gone
4485 if ( HasCurrent() && m_current
>= id
)
4490 SendNotify(id
, wxEVT_COMMAND_LIST_INSERT_ITEM
);
4492 RefreshLines(id
, GetItemCount() - 1);
4495 void wxListMainWindow::InsertColumn( long col
, wxListItem
&item
)
4498 if ( InReportView() )
4500 if (item
.m_width
== wxLIST_AUTOSIZE_USEHEADER
)
4501 item
.m_width
= GetTextLength( item
.m_text
);
4503 wxListHeaderData
*column
= new wxListHeaderData( item
);
4504 bool insert
= (col
>= 0) && ((size_t)col
< m_columns
.GetCount());
4507 wxListHeaderDataList::compatibility_iterator node
= m_columns
.Item( col
);
4508 m_columns
.Insert( node
, column
);
4512 m_columns
.Append( column
);
4517 // update all the items
4518 for ( size_t i
= 0; i
< m_lines
.GetCount(); i
++ )
4520 wxListLineData
* const line
= GetLine(i
);
4521 wxListItemData
* const data
= new wxListItemData(this);
4523 line
->m_items
.Insert(col
, data
);
4525 line
->m_items
.Append(data
);
4529 // invalidate it as it has to be recalculated
4534 // ----------------------------------------------------------------------------
4536 // ----------------------------------------------------------------------------
4538 wxListCtrlCompare list_ctrl_compare_func_2
;
4539 long list_ctrl_compare_data
;
4541 int LINKAGEMODE
list_ctrl_compare_func_1( wxListLineData
**arg1
, wxListLineData
**arg2
)
4543 wxListLineData
*line1
= *arg1
;
4544 wxListLineData
*line2
= *arg2
;
4546 line1
->GetItem( 0, item
);
4547 wxUIntPtr data1
= item
.m_data
;
4548 line2
->GetItem( 0, item
);
4549 wxUIntPtr data2
= item
.m_data
;
4550 return list_ctrl_compare_func_2( data1
, data2
, list_ctrl_compare_data
);
4553 void wxListMainWindow::SortItems( wxListCtrlCompare fn
, long data
)
4555 list_ctrl_compare_func_2
= fn
;
4556 list_ctrl_compare_data
= data
;
4557 m_lines
.Sort( list_ctrl_compare_func_1
);
4561 // ----------------------------------------------------------------------------
4563 // ----------------------------------------------------------------------------
4565 void wxListMainWindow::OnScroll(wxScrollWinEvent
& event
)
4567 // update our idea of which lines are shown when we redraw the window the
4569 ResetVisibleLinesRange();
4572 #if defined(__WXGTK__) && !defined(__WXUNIVERSAL__)
4573 wxScrolledWindow::OnScroll(event
);
4575 HandleOnScroll( event
);
4578 if ( event
.GetOrientation() == wxHORIZONTAL
&& HasHeader() )
4580 wxGenericListCtrl
* lc
= GetListCtrl();
4581 wxCHECK_RET( lc
, _T("no listctrl window?") );
4583 lc
->m_headerWin
->Refresh();
4584 lc
->m_headerWin
->Update();
4588 int wxListMainWindow::GetCountPerPage() const
4590 if ( !m_linesPerPage
)
4592 wxConstCast(this, wxListMainWindow
)->
4593 m_linesPerPage
= GetClientSize().y
/ GetLineHeight();
4596 return m_linesPerPage
;
4599 void wxListMainWindow::GetVisibleLinesRange(size_t *from
, size_t *to
)
4601 wxASSERT_MSG( InReportView(), _T("this is for report mode only") );
4603 if ( m_lineFrom
== (size_t)-1 )
4605 size_t count
= GetItemCount();
4608 m_lineFrom
= GetScrollPos(wxVERTICAL
);
4610 // this may happen if SetScrollbars() hadn't been called yet
4611 if ( m_lineFrom
>= count
)
4612 m_lineFrom
= count
- 1;
4614 // we redraw one extra line but this is needed to make the redrawing
4615 // logic work when there is a fractional number of lines on screen
4616 m_lineTo
= m_lineFrom
+ m_linesPerPage
;
4617 if ( m_lineTo
>= count
)
4618 m_lineTo
= count
- 1;
4620 else // empty control
4623 m_lineTo
= (size_t)-1;
4627 wxASSERT_MSG( IsEmpty() ||
4628 (m_lineFrom
<= m_lineTo
&& m_lineTo
< GetItemCount()),
4629 _T("GetVisibleLinesRange() returns incorrect result") );
4637 // -------------------------------------------------------------------------------------
4638 // wxGenericListCtrl
4639 // -------------------------------------------------------------------------------------
4641 IMPLEMENT_DYNAMIC_CLASS(wxGenericListCtrl
, wxControl
)
4643 BEGIN_EVENT_TABLE(wxGenericListCtrl
,wxControl
)
4644 EVT_SIZE(wxGenericListCtrl::OnSize
)
4647 wxGenericListCtrl::wxGenericListCtrl()
4649 m_imageListNormal
= (wxImageListType
*) NULL
;
4650 m_imageListSmall
= (wxImageListType
*) NULL
;
4651 m_imageListState
= (wxImageListType
*) NULL
;
4653 m_ownsImageListNormal
=
4654 m_ownsImageListSmall
=
4655 m_ownsImageListState
= false;
4657 m_mainWin
= (wxListMainWindow
*) NULL
;
4658 m_headerWin
= (wxListHeaderWindow
*) NULL
;
4662 wxGenericListCtrl::~wxGenericListCtrl()
4664 if (m_ownsImageListNormal
)
4665 delete m_imageListNormal
;
4666 if (m_ownsImageListSmall
)
4667 delete m_imageListSmall
;
4668 if (m_ownsImageListState
)
4669 delete m_imageListState
;
4672 void wxGenericListCtrl::CalculateAndSetHeaderHeight()
4678 GetThemeMetric( kThemeMetricListHeaderHeight
, &h
);
4680 // we use 'g' to get the descent, too
4682 m_headerWin
->GetTextExtent(wxT("Hg"), &w
, &h
, &d
);
4683 h
+= d
+ 2 * HEADER_OFFSET_Y
+ EXTRA_HEIGHT
;
4685 // only update if changed
4686 if ( h
!= m_headerHeight
)
4690 m_headerWin
->SetSize(m_headerWin
->GetSize().x
, m_headerHeight
);
4693 ResizeReportView(true);
4698 void wxGenericListCtrl::CreateHeaderWindow()
4700 m_headerWin
= new wxListHeaderWindow
4702 this, wxID_ANY
, m_mainWin
,
4704 wxSize(GetClientSize().x
, m_headerHeight
),
4707 CalculateAndSetHeaderHeight();
4710 bool wxGenericListCtrl::Create(wxWindow
*parent
,
4715 const wxValidator
&validator
,
4716 const wxString
&name
)
4720 m_imageListState
= (wxImageListType
*) NULL
;
4721 m_ownsImageListNormal
=
4722 m_ownsImageListSmall
=
4723 m_ownsImageListState
= false;
4725 m_mainWin
= (wxListMainWindow
*) NULL
;
4726 m_headerWin
= (wxListHeaderWindow
*) NULL
;
4730 if ( !(style
& wxLC_MASK_TYPE
) )
4732 style
= style
| wxLC_LIST
;
4735 if ( !wxControl::Create( parent
, id
, pos
, size
, style
, validator
, name
) )
4738 // don't create the inner window with the border
4739 style
&= ~wxBORDER_MASK
;
4741 m_mainWin
= new wxListMainWindow( this, wxID_ANY
, wxPoint(0,0), size
, style
);
4743 #ifdef __WXMAC_CARBON__
4744 // Human Interface Guidelines ask us for a special font in this case
4745 if ( GetWindowVariant() == wxWINDOW_VARIANT_NORMAL
)
4748 font
.MacCreateThemeFont( kThemeViewsFont
) ;
4752 if ( InReportView() )
4754 CreateHeaderWindow();
4756 if ( HasFlag(wxLC_NO_HEADER
) )
4758 // VZ: why do we create it at all then?
4759 m_headerWin
->Show( false );
4768 void wxGenericListCtrl::SetSingleStyle( long style
, bool add
)
4770 wxASSERT_MSG( !(style
& wxLC_VIRTUAL
),
4771 _T("wxLC_VIRTUAL can't be [un]set") );
4773 long flag
= GetWindowStyle();
4777 if (style
& wxLC_MASK_TYPE
)
4778 flag
&= ~(wxLC_MASK_TYPE
| wxLC_VIRTUAL
);
4779 if (style
& wxLC_MASK_ALIGN
)
4780 flag
&= ~wxLC_MASK_ALIGN
;
4781 if (style
& wxLC_MASK_SORT
)
4782 flag
&= ~wxLC_MASK_SORT
;
4794 SetWindowStyleFlag( flag
);
4797 void wxGenericListCtrl::SetWindowStyleFlag( long flag
)
4801 m_mainWin
->DeleteEverything();
4803 // has the header visibility changed?
4804 bool hasHeader
= HasHeader();
4805 bool willHaveHeader
= (flag
& wxLC_REPORT
) && !(flag
& wxLC_NO_HEADER
);
4807 if ( hasHeader
!= willHaveHeader
)
4814 // don't delete, just hide, as we can reuse it later
4815 m_headerWin
->Show(false);
4817 //else: nothing to do
4819 else // must show header
4823 CreateHeaderWindow();
4825 else // already have it, just show
4827 m_headerWin
->Show( true );
4831 ResizeReportView(willHaveHeader
);
4835 wxWindow::SetWindowStyleFlag( flag
);
4838 bool wxGenericListCtrl::GetColumn(int col
, wxListItem
&item
) const
4840 m_mainWin
->GetColumn( col
, item
);
4844 bool wxGenericListCtrl::SetColumn( int col
, wxListItem
& item
)
4846 m_mainWin
->SetColumn( col
, item
);
4850 int wxGenericListCtrl::GetColumnWidth( int col
) const
4852 return m_mainWin
->GetColumnWidth( col
);
4855 bool wxGenericListCtrl::SetColumnWidth( int col
, int width
)
4857 m_mainWin
->SetColumnWidth( col
, width
);
4861 int wxGenericListCtrl::GetCountPerPage() const
4863 return m_mainWin
->GetCountPerPage(); // different from Windows ?
4866 bool wxGenericListCtrl::GetItem( wxListItem
&info
) const
4868 m_mainWin
->GetItem( info
);
4872 bool wxGenericListCtrl::SetItem( wxListItem
&info
)
4874 m_mainWin
->SetItem( info
);
4878 long wxGenericListCtrl::SetItem( long index
, int col
, const wxString
& label
, int imageId
)
4881 info
.m_text
= label
;
4882 info
.m_mask
= wxLIST_MASK_TEXT
;
4883 info
.m_itemId
= index
;
4887 info
.m_image
= imageId
;
4888 info
.m_mask
|= wxLIST_MASK_IMAGE
;
4890 m_mainWin
->SetItem(info
);
4894 int wxGenericListCtrl::GetItemState( long item
, long stateMask
) const
4896 return m_mainWin
->GetItemState( item
, stateMask
);
4899 bool wxGenericListCtrl::SetItemState( long item
, long state
, long stateMask
)
4901 m_mainWin
->SetItemState( item
, state
, stateMask
);
4906 wxGenericListCtrl::SetItemImage( long item
, int image
, int WXUNUSED(selImage
) )
4909 info
.m_image
= image
;
4910 info
.m_mask
= wxLIST_MASK_IMAGE
;
4911 info
.m_itemId
= item
;
4912 m_mainWin
->SetItem( info
);
4916 wxString
wxGenericListCtrl::GetItemText( long item
) const
4918 return m_mainWin
->GetItemText(item
);
4921 void wxGenericListCtrl::SetItemText( long item
, const wxString
& str
)
4923 m_mainWin
->SetItemText(item
, str
);
4926 wxUIntPtr
wxGenericListCtrl::GetItemData( long item
) const
4929 info
.m_itemId
= item
;
4930 m_mainWin
->GetItem( info
);
4934 bool wxGenericListCtrl::SetItemData( long item
, long data
)
4937 info
.m_mask
= wxLIST_MASK_DATA
;
4938 info
.m_itemId
= item
;
4940 m_mainWin
->SetItem( info
);
4944 wxRect
wxGenericListCtrl::GetViewRect() const
4946 return m_mainWin
->GetViewRect();
4949 bool wxGenericListCtrl::GetItemRect( long item
, wxRect
&rect
, int WXUNUSED(code
) ) const
4951 m_mainWin
->GetItemRect( item
, rect
);
4952 if ( m_mainWin
->HasHeader() )
4953 rect
.y
+= m_headerHeight
+ 1;
4957 bool wxGenericListCtrl::GetItemPosition( long item
, wxPoint
& pos
) const
4959 m_mainWin
->GetItemPosition( item
, pos
);
4963 bool wxGenericListCtrl::SetItemPosition( long WXUNUSED(item
), const wxPoint
& WXUNUSED(pos
) )
4968 int wxGenericListCtrl::GetItemCount() const
4970 return m_mainWin
->GetItemCount();
4973 int wxGenericListCtrl::GetColumnCount() const
4975 return m_mainWin
->GetColumnCount();
4978 void wxGenericListCtrl::SetItemSpacing( int spacing
, bool isSmall
)
4980 m_mainWin
->SetItemSpacing( spacing
, isSmall
);
4983 wxSize
wxGenericListCtrl::GetItemSpacing() const
4985 const int spacing
= m_mainWin
->GetItemSpacing(HasFlag(wxLC_SMALL_ICON
));
4987 return wxSize(spacing
, spacing
);
4990 int wxGenericListCtrl::GetItemSpacing( bool isSmall
) const
4992 return m_mainWin
->GetItemSpacing( isSmall
);
4995 void wxGenericListCtrl::SetItemTextColour( long item
, const wxColour
&col
)
4998 info
.m_itemId
= item
;
4999 info
.SetTextColour( col
);
5000 m_mainWin
->SetItem( info
);
5003 wxColour
wxGenericListCtrl::GetItemTextColour( long item
) const
5006 info
.m_itemId
= item
;
5007 m_mainWin
->GetItem( info
);
5008 return info
.GetTextColour();
5011 void wxGenericListCtrl::SetItemBackgroundColour( long item
, const wxColour
&col
)
5014 info
.m_itemId
= item
;
5015 info
.SetBackgroundColour( col
);
5016 m_mainWin
->SetItem( info
);
5019 wxColour
wxGenericListCtrl::GetItemBackgroundColour( long item
) const
5022 info
.m_itemId
= item
;
5023 m_mainWin
->GetItem( info
);
5024 return info
.GetBackgroundColour();
5027 int wxGenericListCtrl::GetSelectedItemCount() const
5029 return m_mainWin
->GetSelectedItemCount();
5032 wxColour
wxGenericListCtrl::GetTextColour() const
5034 return GetForegroundColour();
5037 void wxGenericListCtrl::SetTextColour(const wxColour
& col
)
5039 SetForegroundColour(col
);
5042 long wxGenericListCtrl::GetTopItem() const
5045 m_mainWin
->GetVisibleLinesRange(&top
, NULL
);
5049 long wxGenericListCtrl::GetNextItem( long item
, int geom
, int state
) const
5051 return m_mainWin
->GetNextItem( item
, geom
, state
);
5054 wxImageListType
*wxGenericListCtrl::GetImageList(int which
) const
5056 if (which
== wxIMAGE_LIST_NORMAL
)
5058 return m_imageListNormal
;
5060 else if (which
== wxIMAGE_LIST_SMALL
)
5062 return m_imageListSmall
;
5064 else if (which
== wxIMAGE_LIST_STATE
)
5066 return m_imageListState
;
5068 return (wxImageListType
*) NULL
;
5071 void wxGenericListCtrl::SetImageList( wxImageListType
*imageList
, int which
)
5073 if ( which
== wxIMAGE_LIST_NORMAL
)
5075 if (m_ownsImageListNormal
) delete m_imageListNormal
;
5076 m_imageListNormal
= imageList
;
5077 m_ownsImageListNormal
= false;
5079 else if ( which
== wxIMAGE_LIST_SMALL
)
5081 if (m_ownsImageListSmall
) delete m_imageListSmall
;
5082 m_imageListSmall
= imageList
;
5083 m_ownsImageListSmall
= false;
5085 else if ( which
== wxIMAGE_LIST_STATE
)
5087 if (m_ownsImageListState
) delete m_imageListState
;
5088 m_imageListState
= imageList
;
5089 m_ownsImageListState
= false;
5092 m_mainWin
->SetImageList( imageList
, which
);
5095 void wxGenericListCtrl::AssignImageList(wxImageListType
*imageList
, int which
)
5097 SetImageList(imageList
, which
);
5098 if ( which
== wxIMAGE_LIST_NORMAL
)
5099 m_ownsImageListNormal
= true;
5100 else if ( which
== wxIMAGE_LIST_SMALL
)
5101 m_ownsImageListSmall
= true;
5102 else if ( which
== wxIMAGE_LIST_STATE
)
5103 m_ownsImageListState
= true;
5106 bool wxGenericListCtrl::Arrange( int WXUNUSED(flag
) )
5111 bool wxGenericListCtrl::DeleteItem( long item
)
5113 m_mainWin
->DeleteItem( item
);
5117 bool wxGenericListCtrl::DeleteAllItems()
5119 m_mainWin
->DeleteAllItems();
5123 bool wxGenericListCtrl::DeleteAllColumns()
5125 size_t count
= m_mainWin
->m_columns
.GetCount();
5126 for ( size_t n
= 0; n
< count
; n
++ )
5132 void wxGenericListCtrl::ClearAll()
5134 m_mainWin
->DeleteEverything();
5137 bool wxGenericListCtrl::DeleteColumn( int col
)
5139 m_mainWin
->DeleteColumn( col
);
5141 // if we don't have the header any longer, we need to relayout the window
5142 if ( !GetColumnCount() )
5144 ResizeReportView(false /* no header */);
5150 void wxGenericListCtrl::Edit( long item
)
5152 m_mainWin
->EditLabel( item
);
5155 bool wxGenericListCtrl::EnsureVisible( long item
)
5157 m_mainWin
->EnsureVisible( item
);
5161 long wxGenericListCtrl::FindItem( long start
, const wxString
& str
, bool partial
)
5163 return m_mainWin
->FindItem( start
, str
, partial
);
5166 long wxGenericListCtrl::FindItem( long start
, wxUIntPtr data
)
5168 return m_mainWin
->FindItem( start
, data
);
5171 long wxGenericListCtrl::FindItem( long WXUNUSED(start
), const wxPoint
& pt
,
5172 int WXUNUSED(direction
))
5174 return m_mainWin
->FindItem( pt
);
5177 long wxGenericListCtrl::HitTest( const wxPoint
&point
, int &flags
)
5179 return m_mainWin
->HitTest( (int)point
.x
, (int)point
.y
, flags
);
5182 long wxGenericListCtrl::InsertItem( wxListItem
& info
)
5184 m_mainWin
->InsertItem( info
);
5185 return info
.m_itemId
;
5188 long wxGenericListCtrl::InsertItem( long index
, const wxString
&label
)
5191 info
.m_text
= label
;
5192 info
.m_mask
= wxLIST_MASK_TEXT
;
5193 info
.m_itemId
= index
;
5194 return InsertItem( info
);
5197 long wxGenericListCtrl::InsertItem( long index
, int imageIndex
)
5200 info
.m_mask
= wxLIST_MASK_IMAGE
;
5201 info
.m_image
= imageIndex
;
5202 info
.m_itemId
= index
;
5203 return InsertItem( info
);
5206 long wxGenericListCtrl::InsertItem( long index
, const wxString
&label
, int imageIndex
)
5209 info
.m_text
= label
;
5210 info
.m_image
= imageIndex
;
5211 info
.m_mask
= wxLIST_MASK_TEXT
| wxLIST_MASK_IMAGE
;
5212 info
.m_itemId
= index
;
5213 return InsertItem( info
);
5216 long wxGenericListCtrl::InsertColumn( long col
, wxListItem
&item
)
5218 wxCHECK_MSG( m_headerWin
, -1, _T("can't add column in non report mode") );
5220 m_mainWin
->InsertColumn( col
, item
);
5222 // if we hadn't had header before and have it now we need to relayout the
5224 if ( GetColumnCount() == 1 && m_mainWin
->HasHeader() )
5226 ResizeReportView(true /* have header */);
5229 m_headerWin
->Refresh();
5234 long wxGenericListCtrl::InsertColumn( long col
, const wxString
&heading
,
5235 int format
, int width
)
5238 item
.m_mask
= wxLIST_MASK_TEXT
| wxLIST_MASK_FORMAT
;
5239 item
.m_text
= heading
;
5242 item
.m_mask
|= wxLIST_MASK_WIDTH
;
5243 item
.m_width
= width
;
5245 item
.m_format
= format
;
5247 return InsertColumn( col
, item
);
5250 bool wxGenericListCtrl::ScrollList( int WXUNUSED(dx
), int WXUNUSED(dy
) )
5256 // fn is a function which takes 3 long arguments: item1, item2, data.
5257 // item1 is the long data associated with a first item (NOT the index).
5258 // item2 is the long data associated with a second item (NOT the index).
5259 // data is the same value as passed to SortItems.
5260 // The return value is a negative number if the first item should precede the second
5261 // item, a positive number of the second item should precede the first,
5262 // or zero if the two items are equivalent.
5263 // data is arbitrary data to be passed to the sort function.
5265 bool wxGenericListCtrl::SortItems( wxListCtrlCompare fn
, long data
)
5267 m_mainWin
->SortItems( fn
, data
);
5271 // ----------------------------------------------------------------------------
5273 // ----------------------------------------------------------------------------
5275 void wxGenericListCtrl::OnSize(wxSizeEvent
& WXUNUSED(event
))
5280 ResizeReportView(m_mainWin
->HasHeader());
5282 m_mainWin
->RecalculatePositions();
5285 void wxGenericListCtrl::ResizeReportView(bool showHeader
)
5288 GetClientSize( &cw
, &ch
);
5292 m_headerWin
->SetSize( 0, 0, cw
, m_headerHeight
);
5293 m_mainWin
->SetSize( 0, m_headerHeight
+ 1, cw
, ch
- m_headerHeight
- 1 );
5295 else // no header window
5297 m_mainWin
->SetSize( 0, 0, cw
, ch
);
5301 void wxGenericListCtrl::OnInternalIdle()
5303 wxWindow::OnInternalIdle();
5305 // do it only if needed
5306 if ( !m_mainWin
->m_dirty
)
5309 m_mainWin
->RecalculatePositions();
5312 // ----------------------------------------------------------------------------
5314 // ----------------------------------------------------------------------------
5316 bool wxGenericListCtrl::SetBackgroundColour( const wxColour
&colour
)
5320 m_mainWin
->SetBackgroundColour( colour
);
5321 m_mainWin
->m_dirty
= true;
5327 bool wxGenericListCtrl::SetForegroundColour( const wxColour
&colour
)
5329 if ( !wxWindow::SetForegroundColour( colour
) )
5334 m_mainWin
->SetForegroundColour( colour
);
5335 m_mainWin
->m_dirty
= true;
5340 m_headerWin
->SetForegroundColour( colour
);
5346 bool wxGenericListCtrl::SetFont( const wxFont
&font
)
5348 if ( !wxWindow::SetFont( font
) )
5353 m_mainWin
->SetFont( font
);
5354 m_mainWin
->m_dirty
= true;
5359 m_headerWin
->SetFont( font
);
5360 CalculateAndSetHeaderHeight();
5371 #include "wx/listbox.h"
5376 wxGenericListCtrl::GetClassDefaultAttributes(wxWindowVariant variant
)
5379 // Use the same color scheme as wxListBox
5380 return wxListBox::GetClassDefaultAttributes(variant
);
5382 wxUnusedVar(variant
);
5383 wxVisualAttributes attr
;
5384 attr
.colFg
= wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT
);
5385 attr
.colBg
= wxSystemSettings::GetColour(wxSYS_COLOUR_LISTBOX
);
5386 attr
.font
= wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT
);
5391 // ----------------------------------------------------------------------------
5392 // methods forwarded to m_mainWin
5393 // ----------------------------------------------------------------------------
5395 #if wxUSE_DRAG_AND_DROP
5397 void wxGenericListCtrl::SetDropTarget( wxDropTarget
*dropTarget
)
5399 m_mainWin
->SetDropTarget( dropTarget
);
5402 wxDropTarget
*wxGenericListCtrl::GetDropTarget() const
5404 return m_mainWin
->GetDropTarget();
5407 #endif // wxUSE_DRAG_AND_DROP
5409 bool wxGenericListCtrl::SetCursor( const wxCursor
&cursor
)
5411 return m_mainWin
? m_mainWin
->wxWindow::SetCursor(cursor
) : false;
5414 wxColour
wxGenericListCtrl::GetBackgroundColour() const
5416 return m_mainWin
? m_mainWin
->GetBackgroundColour() : wxColour();
5419 wxColour
wxGenericListCtrl::GetForegroundColour() const
5421 return m_mainWin
? m_mainWin
->GetForegroundColour() : wxColour();
5424 bool wxGenericListCtrl::DoPopupMenu( wxMenu
*menu
, int x
, int y
)
5427 return m_mainWin
->PopupMenu( menu
, x
, y
);
5430 #endif // wxUSE_MENUS
5433 void wxGenericListCtrl::SetFocus()
5435 /* The test in window.cpp fails as we are a composite
5436 window, so it checks against "this", but not m_mainWin. */
5437 if ( DoFindFocus() != this )
5438 m_mainWin
->SetFocus();
5441 wxSize
wxGenericListCtrl::DoGetBestSize() const
5443 // Something is better than nothing...
5444 // 100x80 is what the MSW version will get from the default
5445 // wxControl::DoGetBestSize
5446 return wxSize(100,80);
5449 // ----------------------------------------------------------------------------
5450 // virtual list control support
5451 // ----------------------------------------------------------------------------
5453 wxString
wxGenericListCtrl::OnGetItemText(long WXUNUSED(item
), long WXUNUSED(col
)) const
5455 // this is a pure virtual function, in fact - which is not really pure
5456 // because the controls which are not virtual don't need to implement it
5457 wxFAIL_MSG( _T("wxGenericListCtrl::OnGetItemText not supposed to be called") );
5459 return wxEmptyString
;
5462 int wxGenericListCtrl::OnGetItemImage(long WXUNUSED(item
)) const
5464 wxCHECK_MSG(!GetImageList(wxIMAGE_LIST_SMALL
),
5466 wxT("List control has an image list, OnGetItemImage should be overridden."));
5471 wxGenericListCtrl::OnGetItemAttr(long WXUNUSED_UNLESS_DEBUG(item
)) const
5473 wxASSERT_MSG( item
>= 0 && item
< GetItemCount(),
5474 _T("invalid item index in OnGetItemAttr()") );
5476 // no attributes by default
5480 void wxGenericListCtrl::SetItemCount(long count
)
5482 wxASSERT_MSG( IsVirtual(), _T("this is for virtual controls only") );
5484 m_mainWin
->SetItemCount(count
);
5487 void wxGenericListCtrl::RefreshItem(long item
)
5489 m_mainWin
->RefreshLine(item
);
5492 void wxGenericListCtrl::RefreshItems(long itemFrom
, long itemTo
)
5494 m_mainWin
->RefreshLines(itemFrom
, itemTo
);
5498 * Generic wxListCtrl is more or less a container for two other
5499 * windows which drawings are done upon. These are namely
5500 * 'm_headerWin' and 'm_mainWin'.
5501 * Here we override 'virtual wxWindow::Refresh()' to mimic the
5502 * behaviour wxListCtrl has under wxMSW.
5504 void wxGenericListCtrl::Refresh(bool eraseBackground
, const wxRect
*rect
)
5508 // The easy case, no rectangle specified.
5510 m_headerWin
->Refresh(eraseBackground
);
5513 m_mainWin
->Refresh(eraseBackground
);
5517 // Refresh the header window
5520 wxRect rectHeader
= m_headerWin
->GetRect();
5521 rectHeader
.Intersect(*rect
);
5522 if (rectHeader
.GetWidth() && rectHeader
.GetHeight())
5525 m_headerWin
->GetPosition(&x
, &y
);
5526 rectHeader
.Offset(-x
, -y
);
5527 m_headerWin
->Refresh(eraseBackground
, &rectHeader
);
5532 // Refresh the main window
5535 wxRect rectMain
= m_mainWin
->GetRect();
5536 rectMain
.Intersect(*rect
);
5537 if (rectMain
.GetWidth() && rectMain
.GetHeight())
5540 m_mainWin
->GetPosition(&x
, &y
);
5541 rectMain
.Offset(-x
, -y
);
5542 m_mainWin
->Refresh(eraseBackground
, &rectMain
);
5548 void wxGenericListCtrl::Freeze()
5550 m_mainWin
->Freeze();
5553 void wxGenericListCtrl::Thaw()
5558 #endif // wxUSE_LISTCTRL