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
1750 wxRendererNative::Get().DrawHeaderButton
1754 wxRect(x
, HEADER_OFFSET_Y
, cw
, ch
),
1755 m_parent
->IsEnabled() ? 0
1756 : (int)wxCONTROL_DISABLED
1759 // see if we have enough space for the column label
1761 // for this we need the width of the text
1764 dc
.GetTextExtent(item
.GetText(), &wLabel
, &hLabel
);
1765 wLabel
+= 2*EXTRA_WIDTH
;
1767 // and the width of the icon, if any
1768 static const int MARGIN_BETWEEN_TEXT_AND_ICON
= 2;
1769 int ix
= 0, // init them just to suppress the compiler warnings
1771 const int image
= item
.m_image
;
1772 wxImageListType
*imageList
;
1775 imageList
= m_owner
->m_small_image_list
;
1778 imageList
->GetSize(image
, ix
, iy
);
1779 wLabel
+= ix
+ MARGIN_BETWEEN_TEXT_AND_ICON
;
1787 // ignore alignment if there is not enough space anyhow
1789 switch ( wLabel
< cw
? item
.GetAlign() : wxLIST_FORMAT_LEFT
)
1792 wxFAIL_MSG( _T("unknown list item format") );
1795 case wxLIST_FORMAT_LEFT
:
1799 case wxLIST_FORMAT_RIGHT
:
1800 xAligned
= x
+ cw
- wLabel
;
1803 case wxLIST_FORMAT_CENTER
:
1804 xAligned
= x
+ (cw
- wLabel
) / 2;
1809 // if we have an image, draw it on the right of the label
1816 xAligned
+ wLabel
- ix
- MARGIN_BETWEEN_TEXT_AND_ICON
,
1817 HEADER_OFFSET_Y
+ (h
- 4 - iy
)/2,
1818 wxIMAGELIST_DRAW_TRANSPARENT
1821 cw
-= ix
+ MARGIN_BETWEEN_TEXT_AND_ICON
;
1824 // draw the text clipping it so that it doesn't overwrite the column
1826 wxDCClipper
clipper(dc
, x
, HEADER_OFFSET_Y
, cw
, h
- 4 );
1828 dc
.DrawText( item
.GetText(),
1829 xAligned
+ EXTRA_WIDTH
, h
/ 2 - hLabel
/ 2 ); //HEADER_OFFSET_Y + EXTRA_HEIGHT );
1837 void wxListHeaderWindow::DrawCurrent()
1839 int x1
= m_currentX
;
1841 m_owner
->ClientToScreen( &x1
, &y1
);
1843 int x2
= m_currentX
;
1845 m_owner
->GetClientSize( NULL
, &y2
);
1846 m_owner
->ClientToScreen( &x2
, &y2
);
1849 dc
.SetLogicalFunction( wxINVERT
);
1850 dc
.SetPen( wxPen( *wxBLACK
, 2, wxSOLID
) );
1851 dc
.SetBrush( *wxTRANSPARENT_BRUSH
);
1855 dc
.DrawLine( x1
, y1
, x2
, y2
);
1857 dc
.SetLogicalFunction( wxCOPY
);
1859 dc
.SetPen( wxNullPen
);
1860 dc
.SetBrush( wxNullBrush
);
1863 void wxListHeaderWindow::OnMouse( wxMouseEvent
&event
)
1865 // we want to work with logical coords
1867 m_owner
->CalcUnscrolledPosition(event
.GetX(), 0, &x
, NULL
);
1868 int y
= event
.GetY();
1872 SendListEvent(wxEVT_COMMAND_LIST_COL_DRAGGING
, event
.GetPosition());
1874 // we don't draw the line beyond our window, but we allow dragging it
1877 GetClientSize( &w
, NULL
);
1878 m_owner
->CalcUnscrolledPosition(w
, 0, &w
, NULL
);
1881 // erase the line if it was drawn
1882 if ( m_currentX
< w
)
1885 if (event
.ButtonUp())
1888 m_isDragging
= false;
1890 m_owner
->SetColumnWidth( m_column
, m_currentX
- m_minX
);
1891 SendListEvent(wxEVT_COMMAND_LIST_COL_END_DRAG
, event
.GetPosition());
1898 m_currentX
= m_minX
+ 7;
1900 // draw in the new location
1901 if ( m_currentX
< w
)
1905 else // not dragging
1908 bool hit_border
= false;
1910 // end of the current column
1913 // find the column where this event occured
1915 countCol
= m_owner
->GetColumnCount();
1916 for (col
= 0; col
< countCol
; col
++)
1918 xpos
+= m_owner
->GetColumnWidth( col
);
1921 if ( (abs(x
-xpos
) < 3) && (y
< 22) )
1923 // near the column border
1930 // inside the column
1937 if ( col
== countCol
)
1940 if (event
.LeftDown() || event
.RightUp())
1942 if (hit_border
&& event
.LeftDown())
1944 if ( SendListEvent(wxEVT_COMMAND_LIST_COL_BEGIN_DRAG
,
1945 event
.GetPosition()) )
1947 m_isDragging
= true;
1952 //else: column resizing was vetoed by the user code
1954 else // click on a column
1956 SendListEvent( event
.LeftDown()
1957 ? wxEVT_COMMAND_LIST_COL_CLICK
1958 : wxEVT_COMMAND_LIST_COL_RIGHT_CLICK
,
1959 event
.GetPosition());
1962 else if (event
.Moving())
1967 setCursor
= m_currentCursor
== wxSTANDARD_CURSOR
;
1968 m_currentCursor
= m_resizeCursor
;
1972 setCursor
= m_currentCursor
!= wxSTANDARD_CURSOR
;
1973 m_currentCursor
= wxSTANDARD_CURSOR
;
1977 SetCursor(*m_currentCursor
);
1982 void wxListHeaderWindow::OnSetFocus( wxFocusEvent
&WXUNUSED(event
) )
1984 m_owner
->SetFocus();
1988 bool wxListHeaderWindow::SendListEvent(wxEventType type
, wxPoint pos
)
1990 wxWindow
*parent
= GetParent();
1991 wxListEvent
le( type
, parent
->GetId() );
1992 le
.SetEventObject( parent
);
1993 le
.m_pointDrag
= pos
;
1995 // the position should be relative to the parent window, not
1996 // this one for compatibility with MSW and common sense: the
1997 // user code doesn't know anything at all about this header
1998 // window, so why should it get positions relative to it?
1999 le
.m_pointDrag
.y
-= GetSize().y
;
2001 le
.m_col
= m_column
;
2002 return !parent
->GetEventHandler()->ProcessEvent( le
) || le
.IsAllowed();
2005 //-----------------------------------------------------------------------------
2006 // wxListRenameTimer (internal)
2007 //-----------------------------------------------------------------------------
2009 wxListRenameTimer::wxListRenameTimer( wxListMainWindow
*owner
)
2014 void wxListRenameTimer::Notify()
2016 m_owner
->OnRenameTimer();
2019 //-----------------------------------------------------------------------------
2020 // wxListTextCtrl (internal)
2021 //-----------------------------------------------------------------------------
2023 BEGIN_EVENT_TABLE(wxListTextCtrl
,wxTextCtrl
)
2024 EVT_CHAR (wxListTextCtrl::OnChar
)
2025 EVT_KEY_UP (wxListTextCtrl::OnKeyUp
)
2026 EVT_KILL_FOCUS (wxListTextCtrl::OnKillFocus
)
2029 wxListTextCtrl::wxListTextCtrl(wxListMainWindow
*owner
, size_t itemEdit
)
2030 : m_startValue(owner
->GetItemText(itemEdit
)),
2031 m_itemEdited(itemEdit
)
2036 wxRect rectLabel
= owner
->GetLineLabelRect(itemEdit
);
2038 m_owner
->CalcScrolledPosition(rectLabel
.x
, rectLabel
.y
,
2039 &rectLabel
.x
, &rectLabel
.y
);
2041 (void)Create(owner
, wxID_ANY
, m_startValue
,
2042 wxPoint(rectLabel
.x
-4,rectLabel
.y
-4),
2043 wxSize(rectLabel
.width
+11,rectLabel
.height
+8));
2046 void wxListTextCtrl::Finish()
2050 wxPendingDelete
.Append(this);
2054 m_owner
->SetFocusIgnoringChildren();
2058 bool wxListTextCtrl::AcceptChanges()
2060 const wxString value
= GetValue();
2062 if ( value
== m_startValue
)
2064 // nothing changed, always accept
2068 if ( !m_owner
->OnRenameAccept(m_itemEdited
, value
) )
2070 // vetoed by the user
2074 // accepted, do rename the item
2075 m_owner
->SetItemText(m_itemEdited
, value
);
2080 void wxListTextCtrl::OnChar( wxKeyEvent
&event
)
2082 switch ( event
.m_keyCode
)
2085 // Notify the owner about the changes
2088 // Even if vetoed, close the control (consistent with MSW)
2095 m_owner
->OnRenameCancelled( m_itemEdited
);
2103 void wxListTextCtrl::OnKeyUp( wxKeyEvent
&event
)
2111 // auto-grow the textctrl:
2112 wxSize parentSize
= m_owner
->GetSize();
2113 wxPoint myPos
= GetPosition();
2114 wxSize mySize
= GetSize();
2116 GetTextExtent(GetValue() + _T("MM"), &sx
, &sy
);
2117 if (myPos
.x
+ sx
> parentSize
.x
)
2118 sx
= parentSize
.x
- myPos
.x
;
2121 SetSize(sx
, wxDefaultCoord
);
2126 void wxListTextCtrl::OnKillFocus( wxFocusEvent
&event
)
2130 // We must finish regardless of success, otherwise we'll get
2134 if ( !AcceptChanges() )
2135 m_owner
->OnRenameCancelled( m_itemEdited
);
2138 // We must let the native text control handle focus, too, otherwise
2139 // it could have problems with the cursor (e.g., in wxGTK):
2143 //-----------------------------------------------------------------------------
2145 //-----------------------------------------------------------------------------
2147 IMPLEMENT_DYNAMIC_CLASS(wxListMainWindow
,wxScrolledWindow
)
2149 BEGIN_EVENT_TABLE(wxListMainWindow
,wxScrolledWindow
)
2150 EVT_PAINT (wxListMainWindow::OnPaint
)
2151 EVT_MOUSE_EVENTS (wxListMainWindow::OnMouse
)
2152 EVT_CHAR (wxListMainWindow::OnChar
)
2153 EVT_KEY_DOWN (wxListMainWindow::OnKeyDown
)
2154 EVT_SET_FOCUS (wxListMainWindow::OnSetFocus
)
2155 EVT_KILL_FOCUS (wxListMainWindow::OnKillFocus
)
2156 EVT_SCROLLWIN (wxListMainWindow::OnScroll
)
2159 void wxListMainWindow::Init()
2164 m_lineTo
= (size_t)-1;
2170 m_small_image_list
= (wxImageListType
*) NULL
;
2171 m_normal_image_list
= (wxImageListType
*) NULL
;
2173 m_small_spacing
= 30;
2174 m_normal_spacing
= 40;
2178 m_isCreated
= false;
2180 m_lastOnSame
= false;
2181 m_renameTimer
= new wxListRenameTimer( this );
2185 m_lineSelectSingleOnUp
=
2186 m_lineBeforeLastClicked
= (size_t)-1;
2191 wxListMainWindow::wxListMainWindow()
2196 m_highlightUnfocusedBrush
= (wxBrush
*) NULL
;
2199 wxListMainWindow::wxListMainWindow( wxWindow
*parent
,
2204 const wxString
&name
)
2205 : wxScrolledWindow( parent
, id
, pos
, size
,
2206 style
| wxHSCROLL
| wxVSCROLL
, name
)
2210 m_highlightBrush
= new wxBrush
2212 wxSystemSettings::GetColour
2214 wxSYS_COLOUR_HIGHLIGHT
2219 m_highlightUnfocusedBrush
= new wxBrush
2221 wxSystemSettings::GetColour
2223 wxSYS_COLOUR_BTNSHADOW
2231 SetScrollbars( 0, 0, 0, 0, 0, 0 );
2233 wxVisualAttributes attr
= wxGenericListCtrl::GetClassDefaultAttributes();
2234 SetOwnForegroundColour( attr
.colFg
);
2235 SetOwnBackgroundColour( attr
.colBg
);
2237 SetOwnFont( attr
.font
);
2240 wxListMainWindow::~wxListMainWindow()
2243 WX_CLEAR_LIST(wxListHeaderDataList
, m_columns
);
2245 delete m_highlightBrush
;
2246 delete m_highlightUnfocusedBrush
;
2248 delete m_renameTimer
;
2251 void wxListMainWindow::CacheLineData(size_t line
)
2253 wxGenericListCtrl
*listctrl
= GetListCtrl();
2255 wxListLineData
*ld
= GetDummyLine();
2257 size_t countCol
= GetColumnCount();
2258 for ( size_t col
= 0; col
< countCol
; col
++ )
2260 ld
->SetText(col
, listctrl
->OnGetItemText(line
, col
));
2263 ld
->SetImage(listctrl
->OnGetItemImage(line
));
2264 ld
->SetAttr(listctrl
->OnGetItemAttr(line
));
2267 wxListLineData
*wxListMainWindow::GetDummyLine() const
2269 wxASSERT_MSG( !IsEmpty(), _T("invalid line index") );
2271 wxASSERT_MSG( IsVirtual(), _T("GetDummyLine() shouldn't be called") );
2273 wxListMainWindow
*self
= wxConstCast(this, wxListMainWindow
);
2275 // we need to recreate the dummy line if the number of columns in the
2276 // control changed as it would have the incorrect number of fields
2278 if ( !m_lines
.IsEmpty() &&
2279 m_lines
[0].m_items
.GetCount() != (size_t)GetColumnCount() )
2281 self
->m_lines
.Clear();
2284 if ( m_lines
.IsEmpty() )
2286 wxListLineData
*line
= new wxListLineData(self
);
2287 self
->m_lines
.Add(line
);
2289 // don't waste extra memory -- there never going to be anything
2290 // else/more in this array
2291 self
->m_lines
.Shrink();
2297 // ----------------------------------------------------------------------------
2298 // line geometry (report mode only)
2299 // ----------------------------------------------------------------------------
2301 wxCoord
wxListMainWindow::GetLineHeight() const
2303 // we cache the line height as calling GetTextExtent() is slow
2304 if ( !m_lineHeight
)
2306 wxListMainWindow
*self
= wxConstCast(this, wxListMainWindow
);
2308 wxClientDC
dc( self
);
2309 dc
.SetFont( GetFont() );
2312 dc
.GetTextExtent(_T("H"), NULL
, &y
);
2314 if ( m_small_image_list
&& m_small_image_list
->GetImageCount() )
2318 m_small_image_list
->GetSize(0, iw
, ih
);
2323 self
->m_lineHeight
= y
+ LINE_SPACING
;
2326 return m_lineHeight
;
2329 wxCoord
wxListMainWindow::GetLineY(size_t line
) const
2331 wxASSERT_MSG( InReportView(), _T("only works in report mode") );
2333 return LINE_SPACING
+ line
*GetLineHeight();
2336 wxRect
wxListMainWindow::GetLineRect(size_t line
) const
2338 if ( !InReportView() )
2339 return GetLine(line
)->m_gi
->m_rectAll
;
2342 rect
.x
= HEADER_OFFSET_X
;
2343 rect
.y
= GetLineY(line
);
2344 rect
.width
= GetHeaderWidth();
2345 rect
.height
= GetLineHeight();
2350 wxRect
wxListMainWindow::GetLineLabelRect(size_t line
) const
2352 if ( !InReportView() )
2353 return GetLine(line
)->m_gi
->m_rectLabel
;
2356 rect
.x
= HEADER_OFFSET_X
;
2357 rect
.y
= GetLineY(line
);
2358 rect
.width
= GetColumnWidth(0);
2359 rect
.height
= GetLineHeight();
2364 wxRect
wxListMainWindow::GetLineIconRect(size_t line
) const
2366 if ( !InReportView() )
2367 return GetLine(line
)->m_gi
->m_rectIcon
;
2369 wxListLineData
*ld
= GetLine(line
);
2370 wxASSERT_MSG( ld
->HasImage(), _T("should have an image") );
2373 rect
.x
= HEADER_OFFSET_X
;
2374 rect
.y
= GetLineY(line
);
2375 GetImageSize(ld
->GetImage(), rect
.width
, rect
.height
);
2380 wxRect
wxListMainWindow::GetLineHighlightRect(size_t line
) const
2382 return InReportView() ? GetLineRect(line
)
2383 : GetLine(line
)->m_gi
->m_rectHighlight
;
2386 long wxListMainWindow::HitTestLine(size_t line
, int x
, int y
) const
2388 wxASSERT_MSG( line
< GetItemCount(), _T("invalid line in HitTestLine") );
2390 wxListLineData
*ld
= GetLine(line
);
2392 if ( ld
->HasImage() && GetLineIconRect(line
).Inside(x
, y
) )
2393 return wxLIST_HITTEST_ONITEMICON
;
2395 // VS: Testing for "ld->HasText() || InReportView()" instead of
2396 // "ld->HasText()" is needed to make empty lines in report view
2398 if ( ld
->HasText() || InReportView() )
2400 wxRect rect
= InReportView() ? GetLineRect(line
)
2401 : GetLineLabelRect(line
);
2403 if ( rect
.Inside(x
, y
) )
2404 return wxLIST_HITTEST_ONITEMLABEL
;
2410 // ----------------------------------------------------------------------------
2411 // highlight (selection) handling
2412 // ----------------------------------------------------------------------------
2414 bool wxListMainWindow::IsHighlighted(size_t line
) const
2418 return m_selStore
.IsSelected(line
);
2422 wxListLineData
*ld
= GetLine(line
);
2423 wxCHECK_MSG( ld
, false, _T("invalid index in IsHighlighted") );
2425 return ld
->IsHighlighted();
2429 void wxListMainWindow::HighlightLines( size_t lineFrom
,
2435 wxArrayInt linesChanged
;
2436 if ( !m_selStore
.SelectRange(lineFrom
, lineTo
, highlight
,
2439 // meny items changed state, refresh everything
2440 RefreshLines(lineFrom
, lineTo
);
2442 else // only a few items changed state, refresh only them
2444 size_t count
= linesChanged
.GetCount();
2445 for ( size_t n
= 0; n
< count
; n
++ )
2447 RefreshLine(linesChanged
[n
]);
2451 else // iterate over all items in non report view
2453 for ( size_t line
= lineFrom
; line
<= lineTo
; line
++ )
2455 if ( HighlightLine(line
, highlight
) )
2463 bool wxListMainWindow::HighlightLine( size_t line
, bool highlight
)
2469 changed
= m_selStore
.SelectItem(line
, highlight
);
2473 wxListLineData
*ld
= GetLine(line
);
2474 wxCHECK_MSG( ld
, false, _T("invalid index in HighlightLine") );
2476 changed
= ld
->Highlight(highlight
);
2481 SendNotify( line
, highlight
? wxEVT_COMMAND_LIST_ITEM_SELECTED
2482 : wxEVT_COMMAND_LIST_ITEM_DESELECTED
);
2488 void wxListMainWindow::RefreshLine( size_t line
)
2490 if ( InReportView() )
2492 size_t visibleFrom
, visibleTo
;
2493 GetVisibleLinesRange(&visibleFrom
, &visibleTo
);
2495 if ( line
< visibleFrom
|| line
> visibleTo
)
2499 wxRect rect
= GetLineRect(line
);
2501 CalcScrolledPosition( rect
.x
, rect
.y
, &rect
.x
, &rect
.y
);
2502 RefreshRect( rect
);
2505 void wxListMainWindow::RefreshLines( size_t lineFrom
, size_t lineTo
)
2507 // we suppose that they are ordered by caller
2508 wxASSERT_MSG( lineFrom
<= lineTo
, _T("indices in disorder") );
2510 wxASSERT_MSG( lineTo
< GetItemCount(), _T("invalid line range") );
2512 if ( InReportView() )
2514 size_t visibleFrom
, visibleTo
;
2515 GetVisibleLinesRange(&visibleFrom
, &visibleTo
);
2517 if ( lineFrom
< visibleFrom
)
2518 lineFrom
= visibleFrom
;
2519 if ( lineTo
> visibleTo
)
2524 rect
.y
= GetLineY(lineFrom
);
2525 rect
.width
= GetClientSize().x
;
2526 rect
.height
= GetLineY(lineTo
) - rect
.y
+ GetLineHeight();
2528 CalcScrolledPosition( rect
.x
, rect
.y
, &rect
.x
, &rect
.y
);
2529 RefreshRect( rect
);
2533 // TODO: this should be optimized...
2534 for ( size_t line
= lineFrom
; line
<= lineTo
; line
++ )
2541 void wxListMainWindow::RefreshAfter( size_t lineFrom
)
2543 if ( InReportView() )
2545 size_t visibleFrom
, visibleTo
;
2546 GetVisibleLinesRange(&visibleFrom
, &visibleTo
);
2548 if ( lineFrom
< visibleFrom
)
2549 lineFrom
= visibleFrom
;
2550 else if ( lineFrom
> visibleTo
)
2555 rect
.y
= GetLineY(lineFrom
);
2556 CalcScrolledPosition( rect
.x
, rect
.y
, &rect
.x
, &rect
.y
);
2558 wxSize size
= GetClientSize();
2559 rect
.width
= size
.x
;
2560 // refresh till the bottom of the window
2561 rect
.height
= size
.y
- rect
.y
;
2563 RefreshRect( rect
);
2567 // TODO: how to do it more efficiently?
2572 void wxListMainWindow::RefreshSelected()
2578 if ( InReportView() )
2580 GetVisibleLinesRange(&from
, &to
);
2585 to
= GetItemCount() - 1;
2588 if ( HasCurrent() && m_current
>= from
&& m_current
<= to
)
2590 RefreshLine(m_current
);
2593 for ( size_t line
= from
; line
<= to
; line
++ )
2595 // NB: the test works as expected even if m_current == -1
2596 if ( line
!= m_current
&& IsHighlighted(line
) )
2603 void wxListMainWindow::Freeze()
2608 void wxListMainWindow::Thaw()
2610 wxCHECK_RET( m_freezeCount
> 0, _T("thawing unfrozen list control?") );
2612 if ( !--m_freezeCount
)
2618 void wxListMainWindow::OnPaint( wxPaintEvent
&WXUNUSED(event
) )
2620 // Note: a wxPaintDC must be constructed even if no drawing is
2621 // done (a Windows requirement).
2622 wxPaintDC
dc( this );
2624 if ( IsEmpty() || m_freezeCount
)
2626 // nothing to draw or not the moment to draw it
2632 // delay the repainting until we calculate all the items positions
2639 CalcScrolledPosition( 0, 0, &dev_x
, &dev_y
);
2643 dc
.SetFont( GetFont() );
2645 if ( InReportView() )
2647 int lineHeight
= GetLineHeight();
2649 size_t visibleFrom
, visibleTo
;
2650 GetVisibleLinesRange(&visibleFrom
, &visibleTo
);
2653 wxCoord xOrig
, yOrig
;
2654 CalcUnscrolledPosition(0, 0, &xOrig
, &yOrig
);
2656 // tell the caller cache to cache the data
2659 wxListEvent
evCache(wxEVT_COMMAND_LIST_CACHE_HINT
,
2660 GetParent()->GetId());
2661 evCache
.SetEventObject( GetParent() );
2662 evCache
.m_oldItemIndex
= visibleFrom
;
2663 evCache
.m_itemIndex
= visibleTo
;
2664 GetParent()->GetEventHandler()->ProcessEvent( evCache
);
2667 for ( size_t line
= visibleFrom
; line
<= visibleTo
; line
++ )
2669 rectLine
= GetLineRect(line
);
2671 if ( !IsExposed(rectLine
.x
- xOrig
, rectLine
.y
- yOrig
,
2672 rectLine
.width
, rectLine
.height
) )
2674 // don't redraw unaffected lines to avoid flicker
2678 GetLine(line
)->DrawInReportMode( &dc
,
2680 GetLineHighlightRect(line
),
2681 IsHighlighted(line
) );
2684 if ( HasFlag(wxLC_HRULES
) )
2686 wxPen
pen(GetRuleColour(), 1, wxSOLID
);
2687 wxSize clientSize
= GetClientSize();
2689 // Don't draw the first one
2690 for ( size_t i
= visibleFrom
+1; i
<= visibleTo
; i
++ )
2693 dc
.SetBrush( *wxTRANSPARENT_BRUSH
);
2694 dc
.DrawLine(0 - dev_x
, i
*lineHeight
,
2695 clientSize
.x
- dev_x
, i
*lineHeight
);
2698 // Draw last horizontal rule
2699 if ( visibleTo
== GetItemCount() - 1 )
2702 dc
.SetBrush( *wxTRANSPARENT_BRUSH
);
2703 dc
.DrawLine(0 - dev_x
, (m_lineTo
+1)*lineHeight
,
2704 clientSize
.x
- dev_x
, (m_lineTo
+1)*lineHeight
);
2708 // Draw vertical rules if required
2709 if ( HasFlag(wxLC_VRULES
) && !IsEmpty() )
2711 wxPen
pen(GetRuleColour(), 1, wxSOLID
);
2713 wxRect firstItemRect
;
2714 wxRect lastItemRect
;
2715 GetItemRect(visibleFrom
, firstItemRect
);
2716 GetItemRect(visibleTo
, lastItemRect
);
2717 int x
= firstItemRect
.GetX();
2719 dc
.SetBrush(* wxTRANSPARENT_BRUSH
);
2720 for (int col
= 0; col
< GetColumnCount(); col
++)
2722 int colWidth
= GetColumnWidth(col
);
2724 dc
.DrawLine(x
- dev_x
- 2, firstItemRect
.GetY() - 1 - dev_y
,
2725 x
- dev_x
- 2, lastItemRect
.GetBottom() + 1 - dev_y
);
2731 size_t count
= GetItemCount();
2732 for ( size_t i
= 0; i
< count
; i
++ )
2734 GetLine(i
)->Draw( &dc
);
2739 // Don't draw rect outline under Mac at all.
2744 dc
.SetPen( *wxBLACK_PEN
);
2745 dc
.SetBrush( *wxTRANSPARENT_BRUSH
);
2746 dc
.DrawRectangle( GetLineHighlightRect(m_current
) );
2754 void wxListMainWindow::HighlightAll( bool on
)
2756 if ( IsSingleSel() )
2758 wxASSERT_MSG( !on
, _T("can't do this in a single sel control") );
2760 // we just have one item to turn off
2761 if ( HasCurrent() && IsHighlighted(m_current
) )
2763 HighlightLine(m_current
, false);
2764 RefreshLine(m_current
);
2769 HighlightLines(0, GetItemCount() - 1, on
);
2773 void wxListMainWindow::SendNotify( size_t line
,
2774 wxEventType command
,
2777 wxListEvent
le( command
, GetParent()->GetId() );
2778 le
.SetEventObject( GetParent() );
2779 le
.m_itemIndex
= line
;
2781 // set only for events which have position
2782 if ( point
!= wxDefaultPosition
)
2783 le
.m_pointDrag
= point
;
2785 // don't try to get the line info for virtual list controls: the main
2786 // program has it anyhow and if we did it would result in accessing all
2787 // the lines, even those which are not visible now and this is precisely
2788 // what we're trying to avoid
2789 if ( !IsVirtual() && (command
!= wxEVT_COMMAND_LIST_DELETE_ITEM
) )
2791 if ( line
!= (size_t)-1 )
2793 GetLine(line
)->GetItem( 0, le
.m_item
);
2795 //else: this happens for wxEVT_COMMAND_LIST_ITEM_FOCUSED event
2797 //else: there may be no more such item
2799 GetParent()->GetEventHandler()->ProcessEvent( le
);
2802 void wxListMainWindow::ChangeCurrent(size_t current
)
2804 m_current
= current
;
2806 SendNotify(current
, wxEVT_COMMAND_LIST_ITEM_FOCUSED
);
2809 void wxListMainWindow::EditLabel( long item
)
2811 wxCHECK_RET( (item
>= 0) && ((size_t)item
< GetItemCount()),
2812 wxT("wrong index in wxGenericListCtrl::EditLabel()") );
2814 size_t itemEdit
= (size_t)item
;
2816 wxListEvent
le( wxEVT_COMMAND_LIST_BEGIN_LABEL_EDIT
, GetParent()->GetId() );
2817 le
.SetEventObject( GetParent() );
2818 le
.m_itemIndex
= item
;
2819 wxListLineData
*data
= GetLine(itemEdit
);
2820 wxCHECK_RET( data
, _T("invalid index in EditLabel()") );
2821 data
->GetItem( 0, le
.m_item
);
2822 if ( GetParent()->GetEventHandler()->ProcessEvent( le
) && !le
.IsAllowed() )
2824 // vetoed by user code
2828 // We have to call this here because the label in question might just have
2829 // been added and no screen update taken place.
2833 wxListTextCtrl
*text
= new wxListTextCtrl(this, itemEdit
);
2838 void wxListMainWindow::OnRenameTimer()
2840 wxCHECK_RET( HasCurrent(), wxT("unexpected rename timer") );
2842 EditLabel( m_current
);
2845 bool wxListMainWindow::OnRenameAccept(size_t itemEdit
, const wxString
& value
)
2847 wxListEvent
le( wxEVT_COMMAND_LIST_END_LABEL_EDIT
, GetParent()->GetId() );
2848 le
.SetEventObject( GetParent() );
2849 le
.m_itemIndex
= itemEdit
;
2851 wxListLineData
*data
= GetLine(itemEdit
);
2852 wxCHECK_MSG( data
, false, _T("invalid index in OnRenameAccept()") );
2854 data
->GetItem( 0, le
.m_item
);
2855 le
.m_item
.m_text
= value
;
2856 return !GetParent()->GetEventHandler()->ProcessEvent( le
) ||
2860 void wxListMainWindow::OnRenameCancelled(size_t itemEdit
)
2862 // let owner know that the edit was cancelled
2863 wxListEvent
le( wxEVT_COMMAND_LIST_END_LABEL_EDIT
, GetParent()->GetId() );
2865 le
.SetEditCanceled(true);
2867 le
.SetEventObject( GetParent() );
2868 le
.m_itemIndex
= itemEdit
;
2870 wxListLineData
*data
= GetLine(itemEdit
);
2871 wxCHECK_RET( data
, _T("invalid index in OnRenameCancelled()") );
2873 data
->GetItem( 0, le
.m_item
);
2875 GetEventHandler()->ProcessEvent( le
);
2878 void wxListMainWindow::OnMouse( wxMouseEvent
&event
)
2880 event
.SetEventObject( GetParent() );
2881 if ( GetParent()->GetEventHandler()->ProcessEvent( event
) )
2884 if (event
.GetEventType() == wxEVT_MOUSEWHEEL
)
2886 // let the base handle mouse wheel events.
2891 if ( !HasCurrent() || IsEmpty() )
2897 if ( !(event
.Dragging() || event
.ButtonDown() || event
.LeftUp() ||
2898 event
.ButtonDClick()) )
2901 int x
= event
.GetX();
2902 int y
= event
.GetY();
2903 CalcUnscrolledPosition( x
, y
, &x
, &y
);
2905 // where did we hit it (if we did)?
2908 size_t count
= GetItemCount(),
2911 if ( InReportView() )
2913 current
= y
/ GetLineHeight();
2914 if ( current
< count
)
2915 hitResult
= HitTestLine(current
, x
, y
);
2919 // TODO: optimize it too! this is less simple than for report view but
2920 // enumerating all items is still not a way to do it!!
2921 for ( current
= 0; current
< count
; current
++ )
2923 hitResult
= HitTestLine(current
, x
, y
);
2929 if (event
.Dragging())
2931 if (m_dragCount
== 0)
2933 // we have to report the raw, physical coords as we want to be
2934 // able to call HitTest(event.m_pointDrag) from the user code to
2935 // get the item being dragged
2936 m_dragStart
= event
.GetPosition();
2941 if (m_dragCount
!= 3)
2944 int command
= event
.RightIsDown() ? wxEVT_COMMAND_LIST_BEGIN_RDRAG
2945 : wxEVT_COMMAND_LIST_BEGIN_DRAG
;
2947 wxListEvent
le( command
, GetParent()->GetId() );
2948 le
.SetEventObject( GetParent() );
2949 le
.m_itemIndex
= m_lineLastClicked
;
2950 le
.m_pointDrag
= m_dragStart
;
2951 GetParent()->GetEventHandler()->ProcessEvent( le
);
2962 // outside of any item
2966 bool forceClick
= false;
2967 if (event
.ButtonDClick())
2969 m_renameTimer
->Stop();
2970 m_lastOnSame
= false;
2972 if ( current
== m_lineLastClicked
)
2974 SendNotify( current
, wxEVT_COMMAND_LIST_ITEM_ACTIVATED
);
2980 // The first click was on another item, so don't interpret this as
2981 // a double click, but as a simple click instead
2988 if(m_lineSelectSingleOnUp
!= (size_t) -1)
2990 // select single line
2991 HighlightAll( false );
2992 ReverseHighlight(m_lineSelectSingleOnUp
);
2994 else if (m_lastOnSame
)
2996 if ((current
== m_current
) &&
2997 (hitResult
== wxLIST_HITTEST_ONITEMLABEL
) &&
2998 HasFlag(wxLC_EDIT_LABELS
) )
3000 m_renameTimer
->Start( 100, true );
3003 m_lastOnSame
= false;
3004 m_lineSelectSingleOnUp
= (size_t) -1;
3008 // This is neccessary , because after a DnD operation in
3009 // from and to ourself, the up event is swallowed by the
3010 // DnD code. So on next non-up event (which means here and
3011 // now) m_lineSelectSingleOnUp should be reset.
3012 m_lineSelectSingleOnUp
= (size_t) -1;
3014 if (event
.RightDown())
3016 m_lineBeforeLastClicked
= m_lineLastClicked
;
3017 m_lineLastClicked
= current
;
3018 // If the item is already selected, do not update the selection.
3019 // Multi-selections should not be cleared if a selected item is clicked.
3020 if (!IsHighlighted(current
))
3022 HighlightAll(false);
3023 ChangeCurrent(current
);
3024 ReverseHighlight(m_current
);
3026 SendNotify( current
, wxEVT_COMMAND_LIST_ITEM_RIGHT_CLICK
,
3027 event
.GetPosition() );
3028 // Allow generation of context menu event
3031 else if (event
.MiddleDown())
3033 SendNotify( current
, wxEVT_COMMAND_LIST_ITEM_MIDDLE_CLICK
);
3035 else if ( event
.LeftDown() || forceClick
)
3037 m_lineBeforeLastClicked
= m_lineLastClicked
;
3038 m_lineLastClicked
= current
;
3040 size_t oldCurrent
= m_current
;
3041 bool cmdModifierDown
= event
.CmdDown();
3042 if ( !(cmdModifierDown
|| event
.ShiftDown()) )
3044 if( IsSingleSel() || !IsHighlighted(current
) )
3046 HighlightAll( false );
3048 ChangeCurrent(current
);
3050 ReverseHighlight(m_current
);
3052 else // multi sel & current is highlighted & no mod keys
3054 m_lineSelectSingleOnUp
= current
;
3055 ChangeCurrent(current
); // change focus
3058 else // multi sel & either ctrl or shift is down
3060 if (cmdModifierDown
)
3062 ChangeCurrent(current
);
3064 ReverseHighlight(m_current
);
3066 else if (event
.ShiftDown())
3068 ChangeCurrent(current
);
3070 size_t lineFrom
= oldCurrent
,
3073 if ( lineTo
< lineFrom
)
3076 lineFrom
= m_current
;
3079 HighlightLines(lineFrom
, lineTo
);
3081 else // !ctrl, !shift
3083 // test in the enclosing if should make it impossible
3084 wxFAIL_MSG( _T("how did we get here?") );
3088 if (m_current
!= oldCurrent
)
3090 RefreshLine( oldCurrent
);
3093 // forceClick is only set if the previous click was on another item
3094 m_lastOnSame
= !forceClick
&& (m_current
== oldCurrent
);
3098 void wxListMainWindow::MoveToItem(size_t item
)
3100 if ( item
== (size_t)-1 )
3103 wxRect rect
= GetLineRect(item
);
3105 int client_w
, client_h
;
3106 GetClientSize( &client_w
, &client_h
);
3108 const int hLine
= GetLineHeight();
3110 int view_x
= SCROLL_UNIT_X
*GetScrollPos( wxHORIZONTAL
);
3111 int view_y
= hLine
*GetScrollPos( wxVERTICAL
);
3113 if ( InReportView() )
3115 // the next we need the range of lines shown it might be different, so
3117 ResetVisibleLinesRange();
3119 if (rect
.y
< view_y
)
3120 Scroll( -1, rect
.y
/hLine
);
3121 if (rect
.y
+rect
.height
+5 > view_y
+client_h
)
3122 Scroll( -1, (rect
.y
+rect
.height
-client_h
+hLine
)/hLine
);
3126 if (rect
.x
-view_x
< 5)
3127 Scroll( (rect
.x
-5)/SCROLL_UNIT_X
, -1 );
3128 if (rect
.x
+rect
.width
-5 > view_x
+client_w
)
3129 Scroll( (rect
.x
+rect
.width
-client_w
+SCROLL_UNIT_X
)/SCROLL_UNIT_X
, -1 );
3133 // ----------------------------------------------------------------------------
3134 // keyboard handling
3135 // ----------------------------------------------------------------------------
3137 void wxListMainWindow::OnArrowChar(size_t newCurrent
, const wxKeyEvent
& event
)
3139 wxCHECK_RET( newCurrent
< (size_t)GetItemCount(),
3140 _T("invalid item index in OnArrowChar()") );
3142 size_t oldCurrent
= m_current
;
3144 // in single selection we just ignore Shift as we can't select several
3146 if ( event
.ShiftDown() && !IsSingleSel() )
3148 ChangeCurrent(newCurrent
);
3150 // refresh the old focus to remove it
3151 RefreshLine( oldCurrent
);
3153 // select all the items between the old and the new one
3154 if ( oldCurrent
> newCurrent
)
3156 newCurrent
= oldCurrent
;
3157 oldCurrent
= m_current
;
3160 HighlightLines(oldCurrent
, newCurrent
);
3164 // all previously selected items are unselected unless ctrl is held
3165 if ( !event
.ControlDown() )
3166 HighlightAll(false);
3168 ChangeCurrent(newCurrent
);
3170 // refresh the old focus to remove it
3171 RefreshLine( oldCurrent
);
3173 if ( !event
.ControlDown() )
3175 HighlightLine( m_current
, true );
3179 RefreshLine( m_current
);
3184 void wxListMainWindow::OnKeyDown( wxKeyEvent
&event
)
3186 wxWindow
*parent
= GetParent();
3188 /* we propagate the key event up */
3189 wxKeyEvent
ke( wxEVT_KEY_DOWN
);
3190 ke
.m_shiftDown
= event
.m_shiftDown
;
3191 ke
.m_controlDown
= event
.m_controlDown
;
3192 ke
.m_altDown
= event
.m_altDown
;
3193 ke
.m_metaDown
= event
.m_metaDown
;
3194 ke
.m_keyCode
= event
.m_keyCode
;
3197 ke
.SetEventObject( parent
);
3198 if (parent
->GetEventHandler()->ProcessEvent( ke
)) return;
3203 void wxListMainWindow::OnChar( wxKeyEvent
&event
)
3205 wxWindow
*parent
= GetParent();
3207 /* we send a list_key event up */
3210 wxListEvent
le( wxEVT_COMMAND_LIST_KEY_DOWN
, GetParent()->GetId() );
3211 le
.m_itemIndex
= m_current
;
3212 GetLine(m_current
)->GetItem( 0, le
.m_item
);
3213 le
.m_code
= event
.GetKeyCode();
3214 le
.SetEventObject( parent
);
3215 parent
->GetEventHandler()->ProcessEvent( le
);
3218 /* we propagate the char event up */
3219 wxKeyEvent
ke( wxEVT_CHAR
);
3220 ke
.m_shiftDown
= event
.m_shiftDown
;
3221 ke
.m_controlDown
= event
.m_controlDown
;
3222 ke
.m_altDown
= event
.m_altDown
;
3223 ke
.m_metaDown
= event
.m_metaDown
;
3224 ke
.m_keyCode
= event
.m_keyCode
;
3227 ke
.SetEventObject( parent
);
3228 if (parent
->GetEventHandler()->ProcessEvent( ke
)) return;
3230 if (event
.GetKeyCode() == WXK_TAB
)
3232 wxNavigationKeyEvent nevent
;
3233 nevent
.SetWindowChange( event
.ControlDown() );
3234 nevent
.SetDirection( !event
.ShiftDown() );
3235 nevent
.SetEventObject( GetParent()->GetParent() );
3236 nevent
.SetCurrentFocus( m_parent
);
3237 if (GetParent()->GetParent()->GetEventHandler()->ProcessEvent( nevent
))
3241 /* no item -> nothing to do */
3248 switch (event
.GetKeyCode())
3251 if ( m_current
> 0 )
3252 OnArrowChar( m_current
- 1, event
);
3256 if ( m_current
< (size_t)GetItemCount() - 1 )
3257 OnArrowChar( m_current
+ 1, event
);
3262 OnArrowChar( GetItemCount() - 1, event
);
3267 OnArrowChar( 0, event
);
3272 int steps
= InReportView() ? m_linesPerPage
- 1 : m_current
% m_linesPerPage
;
3274 int index
= m_current
- steps
;
3278 OnArrowChar( index
, event
);
3284 int steps
= InReportView()
3285 ? m_linesPerPage
- 1
3286 : m_linesPerPage
- (m_current
% m_linesPerPage
) - 1;
3288 size_t index
= m_current
+ steps
;
3289 size_t count
= GetItemCount();
3290 if ( index
>= count
)
3293 OnArrowChar( index
, event
);
3298 if ( !InReportView() )
3300 int index
= m_current
- m_linesPerPage
;
3304 OnArrowChar( index
, event
);
3309 if ( !InReportView() )
3311 size_t index
= m_current
+ m_linesPerPage
;
3313 size_t count
= GetItemCount();
3314 if ( index
>= count
)
3317 OnArrowChar( index
, event
);
3322 if ( IsSingleSel() )
3324 SendNotify( m_current
, wxEVT_COMMAND_LIST_ITEM_ACTIVATED
);
3326 if ( IsHighlighted(m_current
) )
3328 // don't unselect the item in single selection mode
3331 //else: select it in ReverseHighlight() below if unselected
3334 ReverseHighlight(m_current
);
3339 SendNotify( m_current
, wxEVT_COMMAND_LIST_ITEM_ACTIVATED
);
3347 // ----------------------------------------------------------------------------
3349 // ----------------------------------------------------------------------------
3351 void wxListMainWindow::OnSetFocus( wxFocusEvent
&WXUNUSED(event
) )
3355 wxFocusEvent
event( wxEVT_SET_FOCUS
, GetParent()->GetId() );
3356 event
.SetEventObject( GetParent() );
3357 if ( GetParent()->GetEventHandler()->ProcessEvent( event
) )
3361 // wxGTK sends us EVT_SET_FOCUS events even if we had never got
3362 // EVT_KILL_FOCUS before which means that we finish by redrawing the items
3363 // which are already drawn correctly resulting in horrible flicker - avoid
3373 void wxListMainWindow::OnKillFocus( wxFocusEvent
&WXUNUSED(event
) )
3377 wxFocusEvent
event( wxEVT_KILL_FOCUS
, GetParent()->GetId() );
3378 event
.SetEventObject( GetParent() );
3379 if ( GetParent()->GetEventHandler()->ProcessEvent( event
) )
3386 void wxListMainWindow::DrawImage( int index
, wxDC
*dc
, int x
, int y
)
3388 if ( HasFlag(wxLC_ICON
) && (m_normal_image_list
))
3390 m_normal_image_list
->Draw( index
, *dc
, x
, y
, wxIMAGELIST_DRAW_TRANSPARENT
);
3392 else if ( HasFlag(wxLC_SMALL_ICON
) && (m_small_image_list
))
3394 m_small_image_list
->Draw( index
, *dc
, x
, y
, wxIMAGELIST_DRAW_TRANSPARENT
);
3396 else if ( HasFlag(wxLC_LIST
) && (m_small_image_list
))
3398 m_small_image_list
->Draw( index
, *dc
, x
, y
, wxIMAGELIST_DRAW_TRANSPARENT
);
3400 else if ( InReportView() && (m_small_image_list
))
3402 m_small_image_list
->Draw( index
, *dc
, x
, y
, wxIMAGELIST_DRAW_TRANSPARENT
);
3406 void wxListMainWindow::GetImageSize( int index
, int &width
, int &height
) const
3408 if ( HasFlag(wxLC_ICON
) && m_normal_image_list
)
3410 m_normal_image_list
->GetSize( index
, width
, height
);
3412 else if ( HasFlag(wxLC_SMALL_ICON
) && m_small_image_list
)
3414 m_small_image_list
->GetSize( index
, width
, height
);
3416 else if ( HasFlag(wxLC_LIST
) && m_small_image_list
)
3418 m_small_image_list
->GetSize( index
, width
, height
);
3420 else if ( InReportView() && m_small_image_list
)
3422 m_small_image_list
->GetSize( index
, width
, height
);
3431 int wxListMainWindow::GetTextLength( const wxString
&s
) const
3433 wxClientDC
dc( wxConstCast(this, wxListMainWindow
) );
3434 dc
.SetFont( GetFont() );
3437 dc
.GetTextExtent( s
, &lw
, NULL
);
3439 return lw
+ AUTOSIZE_COL_MARGIN
;
3442 void wxListMainWindow::SetImageList( wxImageListType
*imageList
, int which
)
3446 // calc the spacing from the icon size
3449 if ((imageList
) && (imageList
->GetImageCount()) )
3451 imageList
->GetSize(0, width
, height
);
3454 if (which
== wxIMAGE_LIST_NORMAL
)
3456 m_normal_image_list
= imageList
;
3457 m_normal_spacing
= width
+ 8;
3460 if (which
== wxIMAGE_LIST_SMALL
)
3462 m_small_image_list
= imageList
;
3463 m_small_spacing
= width
+ 14;
3464 m_lineHeight
= 0; // ensure that the line height will be recalc'd
3468 void wxListMainWindow::SetItemSpacing( int spacing
, bool isSmall
)
3473 m_small_spacing
= spacing
;
3477 m_normal_spacing
= spacing
;
3481 int wxListMainWindow::GetItemSpacing( bool isSmall
)
3483 return isSmall
? m_small_spacing
: m_normal_spacing
;
3486 // ----------------------------------------------------------------------------
3488 // ----------------------------------------------------------------------------
3490 void wxListMainWindow::SetColumn( int col
, wxListItem
&item
)
3492 wxListHeaderDataList::compatibility_iterator node
= m_columns
.Item( col
);
3494 wxCHECK_RET( node
, _T("invalid column index in SetColumn") );
3496 if ( item
.m_width
== wxLIST_AUTOSIZE_USEHEADER
)
3497 item
.m_width
= GetTextLength( item
.m_text
);
3499 wxListHeaderData
*column
= node
->GetData();
3500 column
->SetItem( item
);
3502 wxListHeaderWindow
*headerWin
= GetListCtrl()->m_headerWin
;
3504 headerWin
->m_dirty
= true;
3508 // invalidate it as it has to be recalculated
3512 void wxListMainWindow::SetColumnWidth( int col
, int width
)
3514 wxCHECK_RET( col
>= 0 && col
< GetColumnCount(),
3515 _T("invalid column index") );
3517 wxCHECK_RET( InReportView(),
3518 _T("SetColumnWidth() can only be called in report mode.") );
3521 wxListHeaderWindow
*headerWin
= GetListCtrl()->m_headerWin
;
3523 headerWin
->m_dirty
= true;
3525 wxListHeaderDataList::compatibility_iterator node
= m_columns
.Item( col
);
3526 wxCHECK_RET( node
, _T("no column?") );
3528 wxListHeaderData
*column
= node
->GetData();
3530 size_t count
= GetItemCount();
3532 if (width
== wxLIST_AUTOSIZE_USEHEADER
)
3534 width
= GetTextLength(column
->GetText());
3536 else if ( width
== wxLIST_AUTOSIZE
)
3540 // TODO: determine the max width somehow...
3541 width
= WIDTH_COL_DEFAULT
;
3545 wxClientDC
dc(this);
3546 dc
.SetFont( GetFont() );
3548 int max
= AUTOSIZE_COL_MARGIN
;
3550 for ( size_t i
= 0; i
< count
; i
++ )
3552 wxListLineData
*line
= GetLine(i
);
3553 wxListItemDataList::compatibility_iterator n
= line
->m_items
.Item( col
);
3555 wxCHECK_RET( n
, _T("no subitem?") );
3557 wxListItemData
*item
= n
->GetData();
3560 if (item
->HasImage())
3563 GetImageSize( item
->GetImage(), ix
, iy
);
3567 if (item
->HasText())
3570 dc
.GetTextExtent( item
->GetText(), &w
, NULL
);
3578 width
= max
+ AUTOSIZE_COL_MARGIN
;
3582 column
->SetWidth( width
);
3584 // invalidate it as it has to be recalculated
3588 int wxListMainWindow::GetHeaderWidth() const
3590 if ( !m_headerWidth
)
3592 wxListMainWindow
*self
= wxConstCast(this, wxListMainWindow
);
3594 size_t count
= GetColumnCount();
3595 for ( size_t col
= 0; col
< count
; col
++ )
3597 self
->m_headerWidth
+= GetColumnWidth(col
);
3601 return m_headerWidth
;
3604 void wxListMainWindow::GetColumn( int col
, wxListItem
&item
) const
3606 wxListHeaderDataList::compatibility_iterator node
= m_columns
.Item( col
);
3607 wxCHECK_RET( node
, _T("invalid column index in GetColumn") );
3609 wxListHeaderData
*column
= node
->GetData();
3610 column
->GetItem( item
);
3613 int wxListMainWindow::GetColumnWidth( int col
) const
3615 wxListHeaderDataList::compatibility_iterator node
= m_columns
.Item( col
);
3616 wxCHECK_MSG( node
, 0, _T("invalid column index") );
3618 wxListHeaderData
*column
= node
->GetData();
3619 return column
->GetWidth();
3622 // ----------------------------------------------------------------------------
3624 // ----------------------------------------------------------------------------
3626 void wxListMainWindow::SetItem( wxListItem
&item
)
3628 long id
= item
.m_itemId
;
3629 wxCHECK_RET( id
>= 0 && (size_t)id
< GetItemCount(),
3630 _T("invalid item index in SetItem") );
3634 wxListLineData
*line
= GetLine((size_t)id
);
3635 line
->SetItem( item
.m_col
, item
);
3638 // update the item on screen
3640 GetItemRect(id
, rectItem
);
3641 RefreshRect(rectItem
);
3644 void wxListMainWindow::SetItemStateAll(long state
, long stateMask
)
3649 // first deal with selection
3650 if ( stateMask
& wxLIST_STATE_SELECTED
)
3652 // set/clear select state
3655 // optimized version for virtual listctrl.
3656 m_selStore
.SelectRange(0, GetItemCount() - 1, state
== wxLIST_STATE_SELECTED
);
3659 else if ( state
& wxLIST_STATE_SELECTED
)
3661 const long count
= GetItemCount();
3662 for( long i
= 0; i
< count
; i
++ )
3664 SetItemState( i
, wxLIST_STATE_SELECTED
, wxLIST_STATE_SELECTED
);
3670 // clear for non virtual (somewhat optimized by using GetNextItem())
3672 while ( (i
= GetNextItem(i
, wxLIST_NEXT_ALL
, wxLIST_STATE_SELECTED
)) != -1 )
3674 SetItemState( i
, 0, wxLIST_STATE_SELECTED
);
3679 if ( HasCurrent() && (state
== 0) && (stateMask
& wxLIST_STATE_FOCUSED
) )
3681 // unfocus all: only one item can be focussed, so clearing focus for
3682 // all items is simply clearing focus of the focussed item.
3683 SetItemState(m_current
, state
, stateMask
);
3685 //(setting focus to all items makes no sense, so it is not handled here.)
3688 void wxListMainWindow::SetItemState( long litem
, long state
, long stateMask
)
3692 SetItemStateAll(state
, stateMask
);
3696 wxCHECK_RET( litem
>= 0 && (size_t)litem
< GetItemCount(),
3697 _T("invalid list ctrl item index in SetItem") );
3699 size_t oldCurrent
= m_current
;
3700 size_t item
= (size_t)litem
; // safe because of the check above
3702 // do we need to change the focus?
3703 if ( stateMask
& wxLIST_STATE_FOCUSED
)
3705 if ( state
& wxLIST_STATE_FOCUSED
)
3707 // don't do anything if this item is already focused
3708 if ( item
!= m_current
)
3710 ChangeCurrent(item
);
3712 if ( oldCurrent
!= (size_t)-1 )
3714 if ( IsSingleSel() )
3716 HighlightLine(oldCurrent
, false);
3719 RefreshLine(oldCurrent
);
3722 RefreshLine( m_current
);
3727 // don't do anything if this item is not focused
3728 if ( item
== m_current
)
3732 if ( IsSingleSel() )
3734 // we must unselect the old current item as well or we
3735 // might end up with more than one selected item in a
3736 // single selection control
3737 HighlightLine(oldCurrent
, false);
3740 RefreshLine( oldCurrent
);
3745 // do we need to change the selection state?
3746 if ( stateMask
& wxLIST_STATE_SELECTED
)
3748 bool on
= (state
& wxLIST_STATE_SELECTED
) != 0;
3750 if ( IsSingleSel() )
3754 // selecting the item also makes it the focused one in the
3756 if ( m_current
!= item
)
3758 ChangeCurrent(item
);
3760 if ( oldCurrent
!= (size_t)-1 )
3762 HighlightLine( oldCurrent
, false );
3763 RefreshLine( oldCurrent
);
3769 // only the current item may be selected anyhow
3770 if ( item
!= m_current
)
3775 if ( HighlightLine(item
, on
) )
3782 int wxListMainWindow::GetItemState( long item
, long stateMask
) const
3784 wxCHECK_MSG( item
>= 0 && (size_t)item
< GetItemCount(), 0,
3785 _T("invalid list ctrl item index in GetItemState()") );
3787 int ret
= wxLIST_STATE_DONTCARE
;
3789 if ( stateMask
& wxLIST_STATE_FOCUSED
)
3791 if ( (size_t)item
== m_current
)
3792 ret
|= wxLIST_STATE_FOCUSED
;
3795 if ( stateMask
& wxLIST_STATE_SELECTED
)
3797 if ( IsHighlighted(item
) )
3798 ret
|= wxLIST_STATE_SELECTED
;
3804 void wxListMainWindow::GetItem( wxListItem
&item
) const
3806 wxCHECK_RET( item
.m_itemId
>= 0 && (size_t)item
.m_itemId
< GetItemCount(),
3807 _T("invalid item index in GetItem") );
3809 wxListLineData
*line
= GetLine((size_t)item
.m_itemId
);
3810 line
->GetItem( item
.m_col
, item
);
3813 // ----------------------------------------------------------------------------
3815 // ----------------------------------------------------------------------------
3817 size_t wxListMainWindow::GetItemCount() const
3819 return IsVirtual() ? m_countVirt
: m_lines
.GetCount();
3822 void wxListMainWindow::SetItemCount(long count
)
3824 m_selStore
.SetItemCount(count
);
3825 m_countVirt
= count
;
3827 ResetVisibleLinesRange();
3829 // scrollbars must be reset
3833 int wxListMainWindow::GetSelectedItemCount() const
3835 // deal with the quick case first
3836 if ( IsSingleSel() )
3838 return HasCurrent() ? IsHighlighted(m_current
) : false;
3841 // virtual controls remmebers all its selections itself
3843 return m_selStore
.GetSelectedCount();
3845 // TODO: we probably should maintain the number of items selected even for
3846 // non virtual controls as enumerating all lines is really slow...
3847 size_t countSel
= 0;
3848 size_t count
= GetItemCount();
3849 for ( size_t line
= 0; line
< count
; line
++ )
3851 if ( GetLine(line
)->IsHighlighted() )
3858 // ----------------------------------------------------------------------------
3859 // item position/size
3860 // ----------------------------------------------------------------------------
3862 wxRect
wxListMainWindow::GetViewRect() const
3864 wxASSERT_MSG( !HasFlag(wxLC_REPORT
| wxLC_LIST
),
3865 _T("wxListCtrl::GetViewRect() only works in icon mode") );
3867 // we need to find the longest/tallest label
3870 const int count
= GetItemCount();
3873 for ( int i
= 0; i
< count
; i
++ )
3878 wxCoord x
= r
.GetRight(),
3888 // some fudge needed to make it look prettier
3889 xMax
+= 2*EXTRA_BORDER_X
;
3890 yMax
+= 2*EXTRA_BORDER_Y
;
3892 // account for the scrollbars if necessary
3893 const wxSize sizeAll
= GetClientSize();
3894 if ( xMax
> sizeAll
.x
)
3895 yMax
+= wxSystemSettings::GetMetric(wxSYS_HSCROLL_Y
);
3896 if ( yMax
> sizeAll
.y
)
3897 xMax
+= wxSystemSettings::GetMetric(wxSYS_VSCROLL_X
);
3899 return wxRect(0, 0, xMax
, yMax
);
3902 void wxListMainWindow::GetItemRect( long index
, wxRect
&rect
) const
3904 wxCHECK_RET( index
>= 0 && (size_t)index
< GetItemCount(),
3905 _T("invalid index in GetItemRect") );
3907 // ensure that we're laid out, otherwise we could return nonsense
3910 wxConstCast(this, wxListMainWindow
)->
3911 RecalculatePositions(true /* no refresh */);
3914 rect
= GetLineRect((size_t)index
);
3916 CalcScrolledPosition(rect
.x
, rect
.y
, &rect
.x
, &rect
.y
);
3919 bool wxListMainWindow::GetItemPosition(long item
, wxPoint
& pos
) const
3922 GetItemRect(item
, rect
);
3930 // ----------------------------------------------------------------------------
3931 // geometry calculation
3932 // ----------------------------------------------------------------------------
3934 void wxListMainWindow::RecalculatePositions(bool noRefresh
)
3936 wxClientDC
dc( this );
3937 dc
.SetFont( GetFont() );
3939 const size_t count
= GetItemCount();
3942 if ( HasFlag(wxLC_ICON
) )
3943 iconSpacing
= m_normal_spacing
;
3944 else if ( HasFlag(wxLC_SMALL_ICON
) )
3945 iconSpacing
= m_small_spacing
;
3949 // Note that we do not call GetClientSize() here but
3950 // GetSize() and subtract the border size for sunken
3951 // borders manually. This is technically incorrect,
3952 // but we need to know the client area's size WITHOUT
3953 // scrollbars here. Since we don't know if there are
3954 // any scrollbars, we use GetSize() instead. Another
3955 // solution would be to call SetScrollbars() here to
3956 // remove the scrollbars and call GetClientSize() then,
3957 // but this might result in flicker and - worse - will
3958 // reset the scrollbars to 0 which is not good at all
3959 // if you resize a dialog/window, but don't want to
3960 // reset the window scrolling. RR.
3961 // Furthermore, we actually do NOT subtract the border
3962 // width as 2 pixels is just the extra space which we
3963 // need around the actual content in the window. Other-
3964 // wise the text would e.g. touch the upper border. RR.
3967 GetSize( &clientWidth
, &clientHeight
);
3969 const int lineHeight
= GetLineHeight();
3971 if ( InReportView() )
3973 // all lines have the same height and we scroll one line per step
3974 int entireHeight
= count
*lineHeight
+ LINE_SPACING
;
3976 m_linesPerPage
= clientHeight
/ lineHeight
;
3978 ResetVisibleLinesRange();
3980 SetScrollbars( SCROLL_UNIT_X
, lineHeight
,
3981 GetHeaderWidth() / SCROLL_UNIT_X
,
3982 (entireHeight
+ lineHeight
- 1) / lineHeight
,
3983 GetScrollPos(wxHORIZONTAL
),
3984 GetScrollPos(wxVERTICAL
),
3989 // we have 3 different layout strategies: either layout all items
3990 // horizontally/vertically (wxLC_ALIGN_XXX styles explicitly given) or
3991 // to arrange them in top to bottom, left to right (don't ask me why
3992 // not the other way round...) order
3993 if ( HasFlag(wxLC_ALIGN_LEFT
| wxLC_ALIGN_TOP
) )
3995 int x
= EXTRA_BORDER_X
;
3996 int y
= EXTRA_BORDER_Y
;
3998 wxCoord widthMax
= 0;
4001 for ( i
= 0; i
< count
; i
++ )
4003 wxListLineData
*line
= GetLine(i
);
4004 line
->CalculateSize( &dc
, iconSpacing
);
4005 line
->SetPosition( x
, y
, iconSpacing
);
4007 wxSize sizeLine
= GetLineSize(i
);
4009 if ( HasFlag(wxLC_ALIGN_TOP
) )
4011 if ( sizeLine
.x
> widthMax
)
4012 widthMax
= sizeLine
.x
;
4016 else // wxLC_ALIGN_LEFT
4018 x
+= sizeLine
.x
+ MARGIN_BETWEEN_ROWS
;
4022 if ( HasFlag(wxLC_ALIGN_TOP
) )
4024 // traverse the items again and tweak their sizes so that they are
4025 // all the same in a row
4026 for ( i
= 0; i
< count
; i
++ )
4028 wxListLineData
*line
= GetLine(i
);
4029 line
->m_gi
->ExtendWidth(widthMax
);
4038 (x
+ SCROLL_UNIT_X
) / SCROLL_UNIT_X
,
4039 (y
+ lineHeight
) / lineHeight
,
4040 GetScrollPos( wxHORIZONTAL
),
4041 GetScrollPos( wxVERTICAL
),
4045 else // "flowed" arrangement, the most complicated case
4047 // at first we try without any scrollbars, if the items don't fit into
4048 // the window, we recalculate after subtracting the space taken by the
4051 int entireWidth
= 0;
4053 for (int tries
= 0; tries
< 2; tries
++)
4055 entireWidth
= 2*EXTRA_BORDER_X
;
4059 // Now we have decided that the items do not fit into the
4060 // client area, so we need a scrollbar
4061 entireWidth
+= SCROLL_UNIT_X
;
4064 int x
= EXTRA_BORDER_X
;
4065 int y
= EXTRA_BORDER_Y
;
4066 int maxWidthInThisRow
= 0;
4069 int currentlyVisibleLines
= 0;
4071 for (size_t i
= 0; i
< count
; i
++)
4073 currentlyVisibleLines
++;
4074 wxListLineData
*line
= GetLine(i
);
4075 line
->CalculateSize( &dc
, iconSpacing
);
4076 line
->SetPosition( x
, y
, iconSpacing
);
4078 wxSize sizeLine
= GetLineSize(i
);
4080 if ( maxWidthInThisRow
< sizeLine
.x
)
4081 maxWidthInThisRow
= sizeLine
.x
;
4084 if (currentlyVisibleLines
> m_linesPerPage
)
4085 m_linesPerPage
= currentlyVisibleLines
;
4087 if ( y
+ sizeLine
.y
>= clientHeight
)
4089 currentlyVisibleLines
= 0;
4091 maxWidthInThisRow
+= MARGIN_BETWEEN_ROWS
;
4092 x
+= maxWidthInThisRow
;
4093 entireWidth
+= maxWidthInThisRow
;
4094 maxWidthInThisRow
= 0;
4097 // We have reached the last item.
4098 if ( i
== count
- 1 )
4099 entireWidth
+= maxWidthInThisRow
;
4101 if ( (tries
== 0) &&
4102 (entireWidth
+ SCROLL_UNIT_X
> clientWidth
) )
4104 clientHeight
-= wxSystemSettings::
4105 GetMetric(wxSYS_HSCROLL_Y
);
4110 if ( i
== count
- 1 )
4111 tries
= 1; // Everything fits, no second try required.
4119 (entireWidth
+ SCROLL_UNIT_X
) / SCROLL_UNIT_X
,
4121 GetScrollPos( wxHORIZONTAL
),
4130 // FIXME: why should we call it from here?
4137 void wxListMainWindow::RefreshAll()
4142 wxListHeaderWindow
*headerWin
= GetListCtrl()->m_headerWin
;
4143 if ( headerWin
&& headerWin
->m_dirty
)
4145 headerWin
->m_dirty
= false;
4146 headerWin
->Refresh();
4150 void wxListMainWindow::UpdateCurrent()
4152 if ( !HasCurrent() && !IsEmpty() )
4158 long wxListMainWindow::GetNextItem( long item
,
4159 int WXUNUSED(geometry
),
4163 max
= GetItemCount();
4164 wxCHECK_MSG( (ret
== -1) || (ret
< max
), -1,
4165 _T("invalid listctrl index in GetNextItem()") );
4167 // notice that we start with the next item (or the first one if item == -1)
4168 // and this is intentional to allow writing a simple loop to iterate over
4169 // all selected items
4173 // this is not an error because the index was ok initially, just no
4184 size_t count
= GetItemCount();
4185 for ( size_t line
= (size_t)ret
; line
< count
; line
++ )
4187 if ( (state
& wxLIST_STATE_FOCUSED
) && (line
== m_current
) )
4190 if ( (state
& wxLIST_STATE_SELECTED
) && IsHighlighted(line
) )
4197 // ----------------------------------------------------------------------------
4199 // ----------------------------------------------------------------------------
4201 void wxListMainWindow::DeleteItem( long lindex
)
4203 size_t count
= GetItemCount();
4205 wxCHECK_RET( (lindex
>= 0) && ((size_t)lindex
< count
),
4206 _T("invalid item index in DeleteItem") );
4208 size_t index
= (size_t)lindex
;
4210 // we don't need to adjust the index for the previous items
4211 if ( HasCurrent() && m_current
>= index
)
4213 // if the current item is being deleted, we want the next one to
4214 // become selected - unless there is no next one - so don't adjust
4215 // m_current in this case
4216 if ( m_current
!= index
|| m_current
== count
- 1 )
4222 if ( InReportView() )
4224 ResetVisibleLinesRange();
4231 m_selStore
.OnItemDelete(index
);
4235 m_lines
.RemoveAt( index
);
4238 // we need to refresh the (vert) scrollbar as the number of items changed
4241 SendNotify( index
, wxEVT_COMMAND_LIST_DELETE_ITEM
);
4243 RefreshAfter(index
);
4246 void wxListMainWindow::DeleteColumn( int col
)
4248 wxListHeaderDataList::compatibility_iterator node
= m_columns
.Item( col
);
4250 wxCHECK_RET( node
, wxT("invalid column index in DeleteColumn()") );
4253 delete node
->GetData();
4254 m_columns
.Erase( node
);
4258 // update all the items
4259 for ( size_t i
= 0; i
< m_lines
.GetCount(); i
++ )
4261 wxListLineData
* const line
= GetLine(i
);
4262 wxListItemDataList::compatibility_iterator n
= line
->m_items
.Item( col
);
4263 delete n
->GetData();
4264 line
->m_items
.Erase(n
);
4268 // invalidate it as it has to be recalculated
4272 void wxListMainWindow::DoDeleteAllItems()
4276 // nothing to do - in particular, don't send the event
4282 // to make the deletion of all items faster, we don't send the
4283 // notifications for each item deletion in this case but only one event
4284 // for all of them: this is compatible with wxMSW and documented in
4285 // DeleteAllItems() description
4287 wxListEvent
event( wxEVT_COMMAND_LIST_DELETE_ALL_ITEMS
, GetParent()->GetId() );
4288 event
.SetEventObject( GetParent() );
4289 GetParent()->GetEventHandler()->ProcessEvent( event
);
4298 if ( InReportView() )
4300 ResetVisibleLinesRange();
4306 void wxListMainWindow::DeleteAllItems()
4310 RecalculatePositions();
4313 void wxListMainWindow::DeleteEverything()
4315 WX_CLEAR_LIST(wxListHeaderDataList
, m_columns
);
4320 // ----------------------------------------------------------------------------
4321 // scanning for an item
4322 // ----------------------------------------------------------------------------
4324 void wxListMainWindow::EnsureVisible( long index
)
4326 wxCHECK_RET( index
>= 0 && (size_t)index
< GetItemCount(),
4327 _T("invalid index in EnsureVisible") );
4329 // We have to call this here because the label in question might just have
4330 // been added and its position is not known yet
4333 RecalculatePositions(true /* no refresh */);
4336 MoveToItem((size_t)index
);
4339 long wxListMainWindow::FindItem(long start
, const wxString
& str
, bool WXUNUSED(partial
) )
4346 size_t count
= GetItemCount();
4347 for ( size_t i
= (size_t)pos
; i
< count
; i
++ )
4349 wxListLineData
*line
= GetLine(i
);
4350 if ( line
->GetText(0) == tmp
)
4357 long wxListMainWindow::FindItem(long start
, wxUIntPtr data
)
4363 size_t count
= GetItemCount();
4364 for (size_t i
= (size_t)pos
; i
< count
; i
++)
4366 wxListLineData
*line
= GetLine(i
);
4368 line
->GetItem( 0, item
);
4369 if (item
.m_data
== data
)
4376 long wxListMainWindow::FindItem( const wxPoint
& pt
)
4379 GetVisibleLinesRange(&topItem
, NULL
);
4382 GetItemPosition( GetItemCount()-1, p
);
4385 long id
= (long) floor( pt
.y
*double(GetItemCount()-topItem
-1)/p
.y
+topItem
);
4386 if( id
>= 0 && id
< (long)GetItemCount() )
4392 long wxListMainWindow::HitTest( int x
, int y
, int &flags
)
4394 CalcUnscrolledPosition( x
, y
, &x
, &y
);
4396 size_t count
= GetItemCount();
4398 if ( InReportView() )
4400 size_t current
= y
/ GetLineHeight();
4401 if ( current
< count
)
4403 flags
= HitTestLine(current
, x
, y
);
4410 // TODO: optimize it too! this is less simple than for report view but
4411 // enumerating all items is still not a way to do it!!
4412 for ( size_t current
= 0; current
< count
; current
++ )
4414 flags
= HitTestLine(current
, x
, y
);
4423 // ----------------------------------------------------------------------------
4425 // ----------------------------------------------------------------------------
4427 void wxListMainWindow::InsertItem( wxListItem
&item
)
4429 wxASSERT_MSG( !IsVirtual(), _T("can't be used with virtual control") );
4431 int count
= GetItemCount();
4432 wxCHECK_RET( item
.m_itemId
>= 0, _T("invalid item index") );
4434 if (item
.m_itemId
> count
)
4435 item
.m_itemId
= count
;
4437 size_t id
= item
.m_itemId
;
4442 // this is unused variable
4445 if ( InReportView() )
4448 // this is unused variable
4451 ResetVisibleLinesRange();
4453 else if ( HasFlag(wxLC_LIST
) )
4455 // this is unused variable
4460 else if ( HasFlag(wxLC_ICON
) )
4462 // this is unused variable
4467 else if ( HasFlag(wxLC_SMALL_ICON
) )
4469 // this is unused variable
4470 mode
= wxLC_ICON
; // no typo
4476 wxFAIL_MSG( _T("unknown mode") );
4479 wxListLineData
*line
= new wxListLineData(this);
4481 line
->SetItem( item
.m_col
, item
);
4483 m_lines
.Insert( line
, id
);
4487 // If an item is selected at or below the point of insertion, we need to
4488 // increment the member variables because the current row's index has gone
4490 if ( HasCurrent() && m_current
>= id
)
4495 SendNotify(id
, wxEVT_COMMAND_LIST_INSERT_ITEM
);
4497 RefreshLines(id
, GetItemCount() - 1);
4500 void wxListMainWindow::InsertColumn( long col
, wxListItem
&item
)
4503 if ( InReportView() )
4505 if (item
.m_width
== wxLIST_AUTOSIZE_USEHEADER
)
4506 item
.m_width
= GetTextLength( item
.m_text
);
4508 wxListHeaderData
*column
= new wxListHeaderData( item
);
4509 bool insert
= (col
>= 0) && ((size_t)col
< m_columns
.GetCount());
4512 wxListHeaderDataList::compatibility_iterator node
= m_columns
.Item( col
);
4513 m_columns
.Insert( node
, column
);
4517 m_columns
.Append( column
);
4522 // update all the items
4523 for ( size_t i
= 0; i
< m_lines
.GetCount(); i
++ )
4525 wxListLineData
* const line
= GetLine(i
);
4526 wxListItemData
* const data
= new wxListItemData(this);
4528 line
->m_items
.Insert(col
, data
);
4530 line
->m_items
.Append(data
);
4534 // invalidate it as it has to be recalculated
4539 // ----------------------------------------------------------------------------
4541 // ----------------------------------------------------------------------------
4543 wxListCtrlCompare list_ctrl_compare_func_2
;
4544 long list_ctrl_compare_data
;
4546 int LINKAGEMODE
list_ctrl_compare_func_1( wxListLineData
**arg1
, wxListLineData
**arg2
)
4548 wxListLineData
*line1
= *arg1
;
4549 wxListLineData
*line2
= *arg2
;
4551 line1
->GetItem( 0, item
);
4552 wxUIntPtr data1
= item
.m_data
;
4553 line2
->GetItem( 0, item
);
4554 wxUIntPtr data2
= item
.m_data
;
4555 return list_ctrl_compare_func_2( data1
, data2
, list_ctrl_compare_data
);
4558 void wxListMainWindow::SortItems( wxListCtrlCompare fn
, long data
)
4560 list_ctrl_compare_func_2
= fn
;
4561 list_ctrl_compare_data
= data
;
4562 m_lines
.Sort( list_ctrl_compare_func_1
);
4566 // ----------------------------------------------------------------------------
4568 // ----------------------------------------------------------------------------
4570 void wxListMainWindow::OnScroll(wxScrollWinEvent
& event
)
4572 // update our idea of which lines are shown when we redraw the window the
4574 ResetVisibleLinesRange();
4577 #if defined(__WXGTK__) && !defined(__WXUNIVERSAL__)
4578 wxScrolledWindow::OnScroll(event
);
4580 HandleOnScroll( event
);
4583 if ( event
.GetOrientation() == wxHORIZONTAL
&& HasHeader() )
4585 wxGenericListCtrl
* lc
= GetListCtrl();
4586 wxCHECK_RET( lc
, _T("no listctrl window?") );
4588 lc
->m_headerWin
->Refresh();
4589 lc
->m_headerWin
->Update();
4593 int wxListMainWindow::GetCountPerPage() const
4595 if ( !m_linesPerPage
)
4597 wxConstCast(this, wxListMainWindow
)->
4598 m_linesPerPage
= GetClientSize().y
/ GetLineHeight();
4601 return m_linesPerPage
;
4604 void wxListMainWindow::GetVisibleLinesRange(size_t *from
, size_t *to
)
4606 wxASSERT_MSG( InReportView(), _T("this is for report mode only") );
4608 if ( m_lineFrom
== (size_t)-1 )
4610 size_t count
= GetItemCount();
4613 m_lineFrom
= GetScrollPos(wxVERTICAL
);
4615 // this may happen if SetScrollbars() hadn't been called yet
4616 if ( m_lineFrom
>= count
)
4617 m_lineFrom
= count
- 1;
4619 // we redraw one extra line but this is needed to make the redrawing
4620 // logic work when there is a fractional number of lines on screen
4621 m_lineTo
= m_lineFrom
+ m_linesPerPage
;
4622 if ( m_lineTo
>= count
)
4623 m_lineTo
= count
- 1;
4625 else // empty control
4628 m_lineTo
= (size_t)-1;
4632 wxASSERT_MSG( IsEmpty() ||
4633 (m_lineFrom
<= m_lineTo
&& m_lineTo
< GetItemCount()),
4634 _T("GetVisibleLinesRange() returns incorrect result") );
4642 // -------------------------------------------------------------------------------------
4643 // wxGenericListCtrl
4644 // -------------------------------------------------------------------------------------
4646 IMPLEMENT_DYNAMIC_CLASS(wxGenericListCtrl
, wxControl
)
4648 BEGIN_EVENT_TABLE(wxGenericListCtrl
,wxControl
)
4649 EVT_SIZE(wxGenericListCtrl::OnSize
)
4652 wxGenericListCtrl::wxGenericListCtrl()
4654 m_imageListNormal
= (wxImageListType
*) NULL
;
4655 m_imageListSmall
= (wxImageListType
*) NULL
;
4656 m_imageListState
= (wxImageListType
*) NULL
;
4658 m_ownsImageListNormal
=
4659 m_ownsImageListSmall
=
4660 m_ownsImageListState
= false;
4662 m_mainWin
= (wxListMainWindow
*) NULL
;
4663 m_headerWin
= (wxListHeaderWindow
*) NULL
;
4667 wxGenericListCtrl::~wxGenericListCtrl()
4669 if (m_ownsImageListNormal
)
4670 delete m_imageListNormal
;
4671 if (m_ownsImageListSmall
)
4672 delete m_imageListSmall
;
4673 if (m_ownsImageListState
)
4674 delete m_imageListState
;
4677 void wxGenericListCtrl::CalculateAndSetHeaderHeight()
4683 GetThemeMetric( kThemeMetricListHeaderHeight
, &h
);
4685 // we use 'g' to get the descent, too
4687 m_headerWin
->GetTextExtent(wxT("Hg"), &w
, &h
, &d
);
4688 h
+= d
+ 2 * HEADER_OFFSET_Y
+ EXTRA_HEIGHT
;
4690 // only update if changed
4691 if ( h
!= m_headerHeight
)
4695 m_headerWin
->SetSize(m_headerWin
->GetSize().x
, m_headerHeight
);
4698 ResizeReportView(true);
4703 void wxGenericListCtrl::CreateHeaderWindow()
4705 m_headerWin
= new wxListHeaderWindow
4707 this, wxID_ANY
, m_mainWin
,
4709 wxSize(GetClientSize().x
, m_headerHeight
),
4712 CalculateAndSetHeaderHeight();
4715 bool wxGenericListCtrl::Create(wxWindow
*parent
,
4720 const wxValidator
&validator
,
4721 const wxString
&name
)
4725 m_imageListState
= (wxImageListType
*) NULL
;
4726 m_ownsImageListNormal
=
4727 m_ownsImageListSmall
=
4728 m_ownsImageListState
= false;
4730 m_mainWin
= (wxListMainWindow
*) NULL
;
4731 m_headerWin
= (wxListHeaderWindow
*) NULL
;
4735 if ( !(style
& wxLC_MASK_TYPE
) )
4737 style
= style
| wxLC_LIST
;
4740 if ( !wxControl::Create( parent
, id
, pos
, size
, style
, validator
, name
) )
4743 // don't create the inner window with the border
4744 style
&= ~wxBORDER_MASK
;
4746 m_mainWin
= new wxListMainWindow( this, wxID_ANY
, wxPoint(0,0), size
, style
);
4748 #ifdef __WXMAC_CARBON__
4749 // Human Interface Guidelines ask us for a special font in this case
4750 if ( GetWindowVariant() == wxWINDOW_VARIANT_NORMAL
)
4753 font
.MacCreateThemeFont( kThemeViewsFont
) ;
4757 if ( InReportView() )
4759 CreateHeaderWindow();
4760 #ifdef __WXMAC_CARBON__
4764 font
.MacCreateThemeFont( kThemeSmallSystemFont
) ;
4765 m_headerWin
->SetFont( font
);
4766 CalculateAndSetHeaderHeight();
4769 if ( HasFlag(wxLC_NO_HEADER
) )
4771 // VZ: why do we create it at all then?
4772 m_headerWin
->Show( false );
4781 void wxGenericListCtrl::SetSingleStyle( long style
, bool add
)
4783 wxASSERT_MSG( !(style
& wxLC_VIRTUAL
),
4784 _T("wxLC_VIRTUAL can't be [un]set") );
4786 long flag
= GetWindowStyle();
4790 if (style
& wxLC_MASK_TYPE
)
4791 flag
&= ~(wxLC_MASK_TYPE
| wxLC_VIRTUAL
);
4792 if (style
& wxLC_MASK_ALIGN
)
4793 flag
&= ~wxLC_MASK_ALIGN
;
4794 if (style
& wxLC_MASK_SORT
)
4795 flag
&= ~wxLC_MASK_SORT
;
4807 SetWindowStyleFlag( flag
);
4810 void wxGenericListCtrl::SetWindowStyleFlag( long flag
)
4814 m_mainWin
->DeleteEverything();
4816 // has the header visibility changed?
4817 bool hasHeader
= HasHeader();
4818 bool willHaveHeader
= (flag
& wxLC_REPORT
) && !(flag
& wxLC_NO_HEADER
);
4820 if ( hasHeader
!= willHaveHeader
)
4827 // don't delete, just hide, as we can reuse it later
4828 m_headerWin
->Show(false);
4830 //else: nothing to do
4832 else // must show header
4836 CreateHeaderWindow();
4838 else // already have it, just show
4840 m_headerWin
->Show( true );
4844 ResizeReportView(willHaveHeader
);
4848 wxWindow::SetWindowStyleFlag( flag
);
4851 bool wxGenericListCtrl::GetColumn(int col
, wxListItem
&item
) const
4853 m_mainWin
->GetColumn( col
, item
);
4857 bool wxGenericListCtrl::SetColumn( int col
, wxListItem
& item
)
4859 m_mainWin
->SetColumn( col
, item
);
4863 int wxGenericListCtrl::GetColumnWidth( int col
) const
4865 return m_mainWin
->GetColumnWidth( col
);
4868 bool wxGenericListCtrl::SetColumnWidth( int col
, int width
)
4870 m_mainWin
->SetColumnWidth( col
, width
);
4874 int wxGenericListCtrl::GetCountPerPage() const
4876 return m_mainWin
->GetCountPerPage(); // different from Windows ?
4879 bool wxGenericListCtrl::GetItem( wxListItem
&info
) const
4881 m_mainWin
->GetItem( info
);
4885 bool wxGenericListCtrl::SetItem( wxListItem
&info
)
4887 m_mainWin
->SetItem( info
);
4891 long wxGenericListCtrl::SetItem( long index
, int col
, const wxString
& label
, int imageId
)
4894 info
.m_text
= label
;
4895 info
.m_mask
= wxLIST_MASK_TEXT
;
4896 info
.m_itemId
= index
;
4900 info
.m_image
= imageId
;
4901 info
.m_mask
|= wxLIST_MASK_IMAGE
;
4903 m_mainWin
->SetItem(info
);
4907 int wxGenericListCtrl::GetItemState( long item
, long stateMask
) const
4909 return m_mainWin
->GetItemState( item
, stateMask
);
4912 bool wxGenericListCtrl::SetItemState( long item
, long state
, long stateMask
)
4914 m_mainWin
->SetItemState( item
, state
, stateMask
);
4919 wxGenericListCtrl::SetItemImage( long item
, int image
, int WXUNUSED(selImage
) )
4922 info
.m_image
= image
;
4923 info
.m_mask
= wxLIST_MASK_IMAGE
;
4924 info
.m_itemId
= item
;
4925 m_mainWin
->SetItem( info
);
4929 wxString
wxGenericListCtrl::GetItemText( long item
) const
4931 return m_mainWin
->GetItemText(item
);
4934 void wxGenericListCtrl::SetItemText( long item
, const wxString
& str
)
4936 m_mainWin
->SetItemText(item
, str
);
4939 wxUIntPtr
wxGenericListCtrl::GetItemData( long item
) const
4942 info
.m_itemId
= item
;
4943 m_mainWin
->GetItem( info
);
4947 bool wxGenericListCtrl::SetItemData( long item
, long data
)
4950 info
.m_mask
= wxLIST_MASK_DATA
;
4951 info
.m_itemId
= item
;
4953 m_mainWin
->SetItem( info
);
4957 wxRect
wxGenericListCtrl::GetViewRect() const
4959 return m_mainWin
->GetViewRect();
4962 bool wxGenericListCtrl::GetItemRect( long item
, wxRect
&rect
, int WXUNUSED(code
) ) const
4964 m_mainWin
->GetItemRect( item
, rect
);
4965 if ( m_mainWin
->HasHeader() )
4966 rect
.y
+= m_headerHeight
+ 1;
4970 bool wxGenericListCtrl::GetItemPosition( long item
, wxPoint
& pos
) const
4972 m_mainWin
->GetItemPosition( item
, pos
);
4976 bool wxGenericListCtrl::SetItemPosition( long WXUNUSED(item
), const wxPoint
& WXUNUSED(pos
) )
4981 int wxGenericListCtrl::GetItemCount() const
4983 return m_mainWin
->GetItemCount();
4986 int wxGenericListCtrl::GetColumnCount() const
4988 return m_mainWin
->GetColumnCount();
4991 void wxGenericListCtrl::SetItemSpacing( int spacing
, bool isSmall
)
4993 m_mainWin
->SetItemSpacing( spacing
, isSmall
);
4996 wxSize
wxGenericListCtrl::GetItemSpacing() const
4998 const int spacing
= m_mainWin
->GetItemSpacing(HasFlag(wxLC_SMALL_ICON
));
5000 return wxSize(spacing
, spacing
);
5003 int wxGenericListCtrl::GetItemSpacing( bool isSmall
) const
5005 return m_mainWin
->GetItemSpacing( isSmall
);
5008 void wxGenericListCtrl::SetItemTextColour( long item
, const wxColour
&col
)
5011 info
.m_itemId
= item
;
5012 info
.SetTextColour( col
);
5013 m_mainWin
->SetItem( info
);
5016 wxColour
wxGenericListCtrl::GetItemTextColour( long item
) const
5019 info
.m_itemId
= item
;
5020 m_mainWin
->GetItem( info
);
5021 return info
.GetTextColour();
5024 void wxGenericListCtrl::SetItemBackgroundColour( long item
, const wxColour
&col
)
5027 info
.m_itemId
= item
;
5028 info
.SetBackgroundColour( col
);
5029 m_mainWin
->SetItem( info
);
5032 wxColour
wxGenericListCtrl::GetItemBackgroundColour( long item
) const
5035 info
.m_itemId
= item
;
5036 m_mainWin
->GetItem( info
);
5037 return info
.GetBackgroundColour();
5040 int wxGenericListCtrl::GetSelectedItemCount() const
5042 return m_mainWin
->GetSelectedItemCount();
5045 wxColour
wxGenericListCtrl::GetTextColour() const
5047 return GetForegroundColour();
5050 void wxGenericListCtrl::SetTextColour(const wxColour
& col
)
5052 SetForegroundColour(col
);
5055 long wxGenericListCtrl::GetTopItem() const
5058 m_mainWin
->GetVisibleLinesRange(&top
, NULL
);
5062 long wxGenericListCtrl::GetNextItem( long item
, int geom
, int state
) const
5064 return m_mainWin
->GetNextItem( item
, geom
, state
);
5067 wxImageListType
*wxGenericListCtrl::GetImageList(int which
) const
5069 if (which
== wxIMAGE_LIST_NORMAL
)
5071 return m_imageListNormal
;
5073 else if (which
== wxIMAGE_LIST_SMALL
)
5075 return m_imageListSmall
;
5077 else if (which
== wxIMAGE_LIST_STATE
)
5079 return m_imageListState
;
5081 return (wxImageListType
*) NULL
;
5084 void wxGenericListCtrl::SetImageList( wxImageListType
*imageList
, int which
)
5086 if ( which
== wxIMAGE_LIST_NORMAL
)
5088 if (m_ownsImageListNormal
) delete m_imageListNormal
;
5089 m_imageListNormal
= imageList
;
5090 m_ownsImageListNormal
= false;
5092 else if ( which
== wxIMAGE_LIST_SMALL
)
5094 if (m_ownsImageListSmall
) delete m_imageListSmall
;
5095 m_imageListSmall
= imageList
;
5096 m_ownsImageListSmall
= false;
5098 else if ( which
== wxIMAGE_LIST_STATE
)
5100 if (m_ownsImageListState
) delete m_imageListState
;
5101 m_imageListState
= imageList
;
5102 m_ownsImageListState
= false;
5105 m_mainWin
->SetImageList( imageList
, which
);
5108 void wxGenericListCtrl::AssignImageList(wxImageListType
*imageList
, int which
)
5110 SetImageList(imageList
, which
);
5111 if ( which
== wxIMAGE_LIST_NORMAL
)
5112 m_ownsImageListNormal
= true;
5113 else if ( which
== wxIMAGE_LIST_SMALL
)
5114 m_ownsImageListSmall
= true;
5115 else if ( which
== wxIMAGE_LIST_STATE
)
5116 m_ownsImageListState
= true;
5119 bool wxGenericListCtrl::Arrange( int WXUNUSED(flag
) )
5124 bool wxGenericListCtrl::DeleteItem( long item
)
5126 m_mainWin
->DeleteItem( item
);
5130 bool wxGenericListCtrl::DeleteAllItems()
5132 m_mainWin
->DeleteAllItems();
5136 bool wxGenericListCtrl::DeleteAllColumns()
5138 size_t count
= m_mainWin
->m_columns
.GetCount();
5139 for ( size_t n
= 0; n
< count
; n
++ )
5145 void wxGenericListCtrl::ClearAll()
5147 m_mainWin
->DeleteEverything();
5150 bool wxGenericListCtrl::DeleteColumn( int col
)
5152 m_mainWin
->DeleteColumn( col
);
5154 // if we don't have the header any longer, we need to relayout the window
5155 if ( !GetColumnCount() )
5157 ResizeReportView(false /* no header */);
5163 void wxGenericListCtrl::Edit( long item
)
5165 m_mainWin
->EditLabel( item
);
5168 bool wxGenericListCtrl::EnsureVisible( long item
)
5170 m_mainWin
->EnsureVisible( item
);
5174 long wxGenericListCtrl::FindItem( long start
, const wxString
& str
, bool partial
)
5176 return m_mainWin
->FindItem( start
, str
, partial
);
5179 long wxGenericListCtrl::FindItem( long start
, wxUIntPtr data
)
5181 return m_mainWin
->FindItem( start
, data
);
5184 long wxGenericListCtrl::FindItem( long WXUNUSED(start
), const wxPoint
& pt
,
5185 int WXUNUSED(direction
))
5187 return m_mainWin
->FindItem( pt
);
5190 long wxGenericListCtrl::HitTest( const wxPoint
&point
, int &flags
)
5192 return m_mainWin
->HitTest( (int)point
.x
, (int)point
.y
, flags
);
5195 long wxGenericListCtrl::InsertItem( wxListItem
& info
)
5197 m_mainWin
->InsertItem( info
);
5198 return info
.m_itemId
;
5201 long wxGenericListCtrl::InsertItem( long index
, const wxString
&label
)
5204 info
.m_text
= label
;
5205 info
.m_mask
= wxLIST_MASK_TEXT
;
5206 info
.m_itemId
= index
;
5207 return InsertItem( info
);
5210 long wxGenericListCtrl::InsertItem( long index
, int imageIndex
)
5213 info
.m_mask
= wxLIST_MASK_IMAGE
;
5214 info
.m_image
= imageIndex
;
5215 info
.m_itemId
= index
;
5216 return InsertItem( info
);
5219 long wxGenericListCtrl::InsertItem( long index
, const wxString
&label
, int imageIndex
)
5222 info
.m_text
= label
;
5223 info
.m_image
= imageIndex
;
5224 info
.m_mask
= wxLIST_MASK_TEXT
| wxLIST_MASK_IMAGE
;
5225 info
.m_itemId
= index
;
5226 return InsertItem( info
);
5229 long wxGenericListCtrl::InsertColumn( long col
, wxListItem
&item
)
5231 wxCHECK_MSG( m_headerWin
, -1, _T("can't add column in non report mode") );
5233 m_mainWin
->InsertColumn( col
, item
);
5235 // if we hadn't had header before and have it now we need to relayout the
5237 if ( GetColumnCount() == 1 && m_mainWin
->HasHeader() )
5239 ResizeReportView(true /* have header */);
5242 m_headerWin
->Refresh();
5247 long wxGenericListCtrl::InsertColumn( long col
, const wxString
&heading
,
5248 int format
, int width
)
5251 item
.m_mask
= wxLIST_MASK_TEXT
| wxLIST_MASK_FORMAT
;
5252 item
.m_text
= heading
;
5255 item
.m_mask
|= wxLIST_MASK_WIDTH
;
5256 item
.m_width
= width
;
5258 item
.m_format
= format
;
5260 return InsertColumn( col
, item
);
5263 bool wxGenericListCtrl::ScrollList( int WXUNUSED(dx
), int WXUNUSED(dy
) )
5269 // fn is a function which takes 3 long arguments: item1, item2, data.
5270 // item1 is the long data associated with a first item (NOT the index).
5271 // item2 is the long data associated with a second item (NOT the index).
5272 // data is the same value as passed to SortItems.
5273 // The return value is a negative number if the first item should precede the second
5274 // item, a positive number of the second item should precede the first,
5275 // or zero if the two items are equivalent.
5276 // data is arbitrary data to be passed to the sort function.
5278 bool wxGenericListCtrl::SortItems( wxListCtrlCompare fn
, long data
)
5280 m_mainWin
->SortItems( fn
, data
);
5284 // ----------------------------------------------------------------------------
5286 // ----------------------------------------------------------------------------
5288 void wxGenericListCtrl::OnSize(wxSizeEvent
& WXUNUSED(event
))
5293 ResizeReportView(m_mainWin
->HasHeader());
5295 m_mainWin
->RecalculatePositions();
5298 void wxGenericListCtrl::ResizeReportView(bool showHeader
)
5301 GetClientSize( &cw
, &ch
);
5305 m_headerWin
->SetSize( 0, 0, cw
, m_headerHeight
);
5306 m_mainWin
->SetSize( 0, m_headerHeight
+ 1, cw
, ch
- m_headerHeight
- 1 );
5308 else // no header window
5310 m_mainWin
->SetSize( 0, 0, cw
, ch
);
5314 void wxGenericListCtrl::OnInternalIdle()
5316 wxWindow::OnInternalIdle();
5318 // do it only if needed
5319 if ( !m_mainWin
->m_dirty
)
5322 m_mainWin
->RecalculatePositions();
5325 // ----------------------------------------------------------------------------
5327 // ----------------------------------------------------------------------------
5329 bool wxGenericListCtrl::SetBackgroundColour( const wxColour
&colour
)
5333 m_mainWin
->SetBackgroundColour( colour
);
5334 m_mainWin
->m_dirty
= true;
5340 bool wxGenericListCtrl::SetForegroundColour( const wxColour
&colour
)
5342 if ( !wxWindow::SetForegroundColour( colour
) )
5347 m_mainWin
->SetForegroundColour( colour
);
5348 m_mainWin
->m_dirty
= true;
5353 m_headerWin
->SetForegroundColour( colour
);
5359 bool wxGenericListCtrl::SetFont( const wxFont
&font
)
5361 if ( !wxWindow::SetFont( font
) )
5366 m_mainWin
->SetFont( font
);
5367 m_mainWin
->m_dirty
= true;
5372 m_headerWin
->SetFont( font
);
5373 CalculateAndSetHeaderHeight();
5384 #include "wx/listbox.h"
5389 wxGenericListCtrl::GetClassDefaultAttributes(wxWindowVariant variant
)
5392 // Use the same color scheme as wxListBox
5393 return wxListBox::GetClassDefaultAttributes(variant
);
5395 wxUnusedVar(variant
);
5396 wxVisualAttributes attr
;
5397 attr
.colFg
= wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT
);
5398 attr
.colBg
= wxSystemSettings::GetColour(wxSYS_COLOUR_LISTBOX
);
5399 attr
.font
= wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT
);
5404 // ----------------------------------------------------------------------------
5405 // methods forwarded to m_mainWin
5406 // ----------------------------------------------------------------------------
5408 #if wxUSE_DRAG_AND_DROP
5410 void wxGenericListCtrl::SetDropTarget( wxDropTarget
*dropTarget
)
5412 m_mainWin
->SetDropTarget( dropTarget
);
5415 wxDropTarget
*wxGenericListCtrl::GetDropTarget() const
5417 return m_mainWin
->GetDropTarget();
5420 #endif // wxUSE_DRAG_AND_DROP
5422 bool wxGenericListCtrl::SetCursor( const wxCursor
&cursor
)
5424 return m_mainWin
? m_mainWin
->wxWindow::SetCursor(cursor
) : false;
5427 wxColour
wxGenericListCtrl::GetBackgroundColour() const
5429 return m_mainWin
? m_mainWin
->GetBackgroundColour() : wxColour();
5432 wxColour
wxGenericListCtrl::GetForegroundColour() const
5434 return m_mainWin
? m_mainWin
->GetForegroundColour() : wxColour();
5437 bool wxGenericListCtrl::DoPopupMenu( wxMenu
*menu
, int x
, int y
)
5440 return m_mainWin
->PopupMenu( menu
, x
, y
);
5443 #endif // wxUSE_MENUS
5446 void wxGenericListCtrl::SetFocus()
5448 /* The test in window.cpp fails as we are a composite
5449 window, so it checks against "this", but not m_mainWin. */
5450 if ( DoFindFocus() != this )
5451 m_mainWin
->SetFocus();
5454 wxSize
wxGenericListCtrl::DoGetBestSize() const
5456 // Something is better than nothing...
5457 // 100x80 is what the MSW version will get from the default
5458 // wxControl::DoGetBestSize
5459 return wxSize(100,80);
5462 // ----------------------------------------------------------------------------
5463 // virtual list control support
5464 // ----------------------------------------------------------------------------
5466 wxString
wxGenericListCtrl::OnGetItemText(long WXUNUSED(item
), long WXUNUSED(col
)) const
5468 // this is a pure virtual function, in fact - which is not really pure
5469 // because the controls which are not virtual don't need to implement it
5470 wxFAIL_MSG( _T("wxGenericListCtrl::OnGetItemText not supposed to be called") );
5472 return wxEmptyString
;
5475 int wxGenericListCtrl::OnGetItemImage(long WXUNUSED(item
)) const
5477 wxCHECK_MSG(!GetImageList(wxIMAGE_LIST_SMALL
),
5479 wxT("List control has an image list, OnGetItemImage should be overridden."));
5484 wxGenericListCtrl::OnGetItemAttr(long WXUNUSED_UNLESS_DEBUG(item
)) const
5486 wxASSERT_MSG( item
>= 0 && item
< GetItemCount(),
5487 _T("invalid item index in OnGetItemAttr()") );
5489 // no attributes by default
5493 void wxGenericListCtrl::SetItemCount(long count
)
5495 wxASSERT_MSG( IsVirtual(), _T("this is for virtual controls only") );
5497 m_mainWin
->SetItemCount(count
);
5500 void wxGenericListCtrl::RefreshItem(long item
)
5502 m_mainWin
->RefreshLine(item
);
5505 void wxGenericListCtrl::RefreshItems(long itemFrom
, long itemTo
)
5507 m_mainWin
->RefreshLines(itemFrom
, itemTo
);
5511 * Generic wxListCtrl is more or less a container for two other
5512 * windows which drawings are done upon. These are namely
5513 * 'm_headerWin' and 'm_mainWin'.
5514 * Here we override 'virtual wxWindow::Refresh()' to mimic the
5515 * behaviour wxListCtrl has under wxMSW.
5517 void wxGenericListCtrl::Refresh(bool eraseBackground
, const wxRect
*rect
)
5521 // The easy case, no rectangle specified.
5523 m_headerWin
->Refresh(eraseBackground
);
5526 m_mainWin
->Refresh(eraseBackground
);
5530 // Refresh the header window
5533 wxRect rectHeader
= m_headerWin
->GetRect();
5534 rectHeader
.Intersect(*rect
);
5535 if (rectHeader
.GetWidth() && rectHeader
.GetHeight())
5538 m_headerWin
->GetPosition(&x
, &y
);
5539 rectHeader
.Offset(-x
, -y
);
5540 m_headerWin
->Refresh(eraseBackground
, &rectHeader
);
5545 // Refresh the main window
5548 wxRect rectMain
= m_mainWin
->GetRect();
5549 rectMain
.Intersect(*rect
);
5550 if (rectMain
.GetWidth() && rectMain
.GetHeight())
5553 m_mainWin
->GetPosition(&x
, &y
);
5554 rectMain
.Offset(-x
, -y
);
5555 m_mainWin
->Refresh(eraseBackground
, &rectMain
);
5561 void wxGenericListCtrl::Freeze()
5563 m_mainWin
->Freeze();
5566 void wxGenericListCtrl::Thaw()
5571 #endif // wxUSE_LISTCTRL