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
;
497 bool m_aboutToFinish
;
499 DECLARE_EVENT_TABLE()
502 //-----------------------------------------------------------------------------
503 // wxListMainWindow (internal)
504 //-----------------------------------------------------------------------------
506 WX_DECLARE_LIST(wxListHeaderData
, wxListHeaderDataList
);
507 #include "wx/listimpl.cpp"
508 WX_DEFINE_LIST(wxListHeaderDataList
);
510 class wxListMainWindow
: public wxScrolledWindow
514 wxListMainWindow( wxWindow
*parent
,
516 const wxPoint
& pos
= wxDefaultPosition
,
517 const wxSize
& size
= wxDefaultSize
,
519 const wxString
&name
= _T("listctrlmainwindow") );
521 virtual ~wxListMainWindow();
523 wxWindow
*GetMainWindowOfCompositeControl() { return GetParent(); }
525 bool HasFlag(int flag
) const { return m_parent
->HasFlag(flag
); }
527 // return true if this is a virtual list control
528 bool IsVirtual() const { return HasFlag(wxLC_VIRTUAL
); }
530 // return true if the control is in report mode
531 bool InReportView() const { return HasFlag(wxLC_REPORT
); }
533 // return true if we are in single selection mode, false if multi sel
534 bool IsSingleSel() const { return HasFlag(wxLC_SINGLE_SEL
); }
536 // do we have a header window?
537 bool HasHeader() const
538 { return InReportView() && !HasFlag(wxLC_NO_HEADER
); }
540 void HighlightAll( bool on
);
542 // all these functions only do something if the line is currently visible
544 // change the line "selected" state, return true if it really changed
545 bool HighlightLine( size_t line
, bool highlight
= true);
547 // as HighlightLine() but do it for the range of lines: this is incredibly
548 // more efficient for virtual list controls!
550 // NB: unlike HighlightLine() this one does refresh the lines on screen
551 void HighlightLines( size_t lineFrom
, size_t lineTo
, bool on
= true );
553 // toggle the line state and refresh it
554 void ReverseHighlight( size_t line
)
555 { HighlightLine(line
, !IsHighlighted(line
)); RefreshLine(line
); }
557 // return true if the line is highlighted
558 bool IsHighlighted(size_t line
) const;
560 // refresh one or several lines at once
561 void RefreshLine( size_t line
);
562 void RefreshLines( size_t lineFrom
, size_t lineTo
);
564 // refresh all selected items
565 void RefreshSelected();
567 // refresh all lines below the given one: the difference with
568 // RefreshLines() is that the index here might not be a valid one (happens
569 // when the last line is deleted)
570 void RefreshAfter( size_t lineFrom
);
572 // the methods which are forwarded to wxListLineData itself in list/icon
573 // modes but are here because the lines don't store their positions in the
576 // get the bound rect for the entire line
577 wxRect
GetLineRect(size_t line
) const;
579 // get the bound rect of the label
580 wxRect
GetLineLabelRect(size_t line
) const;
582 // get the bound rect of the items icon (only may be called if we do have
584 wxRect
GetLineIconRect(size_t line
) const;
586 // get the rect to be highlighted when the item has focus
587 wxRect
GetLineHighlightRect(size_t line
) const;
589 // get the size of the total line rect
590 wxSize
GetLineSize(size_t line
) const
591 { return GetLineRect(line
).GetSize(); }
593 // return the hit code for the corresponding position (in this line)
594 long HitTestLine(size_t line
, int x
, int y
) const;
596 // bring the selected item into view, scrolling to it if necessary
597 void MoveToItem(size_t item
);
599 // bring the current item into view
600 void MoveToFocus() { MoveToItem(m_current
); }
602 // start editing the label of the given item
603 void EditLabel( long item
);
605 // suspend/resume redrawing the control
609 void OnRenameTimer();
610 bool OnRenameAccept(size_t itemEdit
, const wxString
& value
);
611 void OnRenameCancelled(size_t itemEdit
);
613 void OnMouse( wxMouseEvent
&event
);
615 // called to switch the selection from the current item to newCurrent,
616 void OnArrowChar( size_t newCurrent
, const wxKeyEvent
& event
);
618 void OnChar( wxKeyEvent
&event
);
619 void OnKeyDown( wxKeyEvent
&event
);
620 void OnSetFocus( wxFocusEvent
&event
);
621 void OnKillFocus( wxFocusEvent
&event
);
622 void OnScroll(wxScrollWinEvent
& event
) ;
624 void OnPaint( wxPaintEvent
&event
);
626 void DrawImage( int index
, wxDC
*dc
, int x
, int y
);
627 void GetImageSize( int index
, int &width
, int &height
) const;
628 int GetTextLength( const wxString
&s
) const;
630 void SetImageList( wxImageListType
*imageList
, int which
);
631 void SetItemSpacing( int spacing
, bool isSmall
= false );
632 int GetItemSpacing( bool isSmall
= false );
634 void SetColumn( int col
, wxListItem
&item
);
635 void SetColumnWidth( int col
, int width
);
636 void GetColumn( int col
, wxListItem
&item
) const;
637 int GetColumnWidth( int col
) const;
638 int GetColumnCount() const { return m_columns
.GetCount(); }
640 // returns the sum of the heights of all columns
641 int GetHeaderWidth() const;
643 int GetCountPerPage() const;
645 void SetItem( wxListItem
&item
);
646 void GetItem( wxListItem
&item
) const;
647 void SetItemState( long item
, long state
, long stateMask
);
648 void SetItemStateAll( long state
, long stateMask
);
649 int GetItemState( long item
, long stateMask
) const;
650 void GetItemRect( long index
, wxRect
&rect
) const;
651 wxRect
GetViewRect() const;
652 bool GetItemPosition( long item
, wxPoint
& pos
) const;
653 int GetSelectedItemCount() const;
655 wxString
GetItemText(long item
) const
658 info
.m_itemId
= item
;
663 void SetItemText(long item
, const wxString
& value
)
666 info
.m_mask
= wxLIST_MASK_TEXT
;
667 info
.m_itemId
= item
;
672 // set the scrollbars and update the positions of the items
673 void RecalculatePositions(bool noRefresh
= false);
675 // refresh the window and the header
678 long GetNextItem( long item
, int geometry
, int state
) const;
679 void DeleteItem( long index
);
680 void DeleteAllItems();
681 void DeleteColumn( int col
);
682 void DeleteEverything();
683 void EnsureVisible( long index
);
684 long FindItem( long start
, const wxString
& str
, bool partial
= false );
685 long FindItem( long start
, wxUIntPtr data
);
686 long FindItem( const wxPoint
& pt
);
687 long HitTest( int x
, int y
, int &flags
);
688 void InsertItem( wxListItem
&item
);
689 void InsertColumn( long col
, wxListItem
&item
);
690 void SortItems( wxListCtrlCompare fn
, long data
);
692 size_t GetItemCount() const;
693 bool IsEmpty() const { return GetItemCount() == 0; }
694 void SetItemCount(long count
);
696 // change the current (== focused) item, send a notification event
697 void ChangeCurrent(size_t current
);
698 void ResetCurrent() { ChangeCurrent((size_t)-1); }
699 bool HasCurrent() const { return m_current
!= (size_t)-1; }
701 // send out a wxListEvent
702 void SendNotify( size_t line
,
704 wxPoint point
= wxDefaultPosition
);
706 // override base class virtual to reset m_lineHeight when the font changes
707 virtual bool SetFont(const wxFont
& font
)
709 if ( !wxScrolledWindow::SetFont(font
) )
717 // these are for wxListLineData usage only
719 // get the backpointer to the list ctrl
720 wxGenericListCtrl
*GetListCtrl() const
722 return wxStaticCast(GetParent(), wxGenericListCtrl
);
725 // get the height of all lines (assuming they all do have the same height)
726 wxCoord
GetLineHeight() const;
728 // get the y position of the given line (only for report view)
729 wxCoord
GetLineY(size_t line
) const;
731 // get the brush to use for the item highlighting
732 wxBrush
*GetHighlightBrush() const
734 return m_hasFocus
? m_highlightBrush
: m_highlightUnfocusedBrush
;
738 // the array of all line objects for a non virtual list control (for the
739 // virtual list control we only ever use m_lines[0])
740 wxListLineDataArray m_lines
;
742 // the list of column objects
743 wxListHeaderDataList m_columns
;
745 // currently focused item or -1
748 // the number of lines per page
751 // this flag is set when something which should result in the window
752 // redrawing happens (i.e. an item was added or deleted, or its appearance
753 // changed) and OnPaint() doesn't redraw the window while it is set which
754 // allows to minimize the number of repaintings when a lot of items are
755 // being added. The real repainting occurs only after the next OnIdle()
759 wxColour
*m_highlightColour
;
760 wxImageListType
*m_small_image_list
;
761 wxImageListType
*m_normal_image_list
;
763 int m_normal_spacing
;
767 wxTimer
*m_renameTimer
;
772 // for double click logic
773 size_t m_lineLastClicked
,
774 m_lineBeforeLastClicked
,
775 m_lineSelectSingleOnUp
;
778 // the total count of items in a virtual list control
781 // the object maintaining the items selection state, only used in virtual
783 wxSelectionStore m_selStore
;
785 // common part of all ctors
788 // get the line data for the given index
789 wxListLineData
*GetLine(size_t n
) const
791 wxASSERT_MSG( n
!= (size_t)-1, _T("invalid line index") );
795 wxConstCast(this, wxListMainWindow
)->CacheLineData(n
);
803 // get a dummy line which can be used for geometry calculations and such:
804 // you must use GetLine() if you want to really draw the line
805 wxListLineData
*GetDummyLine() const;
807 // cache the line data of the n-th line in m_lines[0]
808 void CacheLineData(size_t line
);
810 // get the range of visible lines
811 void GetVisibleLinesRange(size_t *from
, size_t *to
);
813 // force us to recalculate the range of visible lines
814 void ResetVisibleLinesRange() { m_lineFrom
= (size_t)-1; }
816 // get the colour to be used for drawing the rules
817 wxColour
GetRuleColour() const
822 return wxSystemSettings::GetColour(wxSYS_COLOUR_3DLIGHT
);
827 // initialize the current item if needed
828 void UpdateCurrent();
830 // delete all items but don't refresh: called from dtor
831 void DoDeleteAllItems();
833 // the height of one line using the current font
834 wxCoord m_lineHeight
;
836 // the total header width or 0 if not calculated yet
837 wxCoord m_headerWidth
;
839 // the first and last lines being shown on screen right now (inclusive),
840 // both may be -1 if they must be calculated so never access them directly:
841 // use GetVisibleLinesRange() above instead
845 // the brushes to use for item highlighting when we do/don't have focus
846 wxBrush
*m_highlightBrush
,
847 *m_highlightUnfocusedBrush
;
849 // if this is > 0, the control is frozen and doesn't redraw itself
850 size_t m_freezeCount
;
852 DECLARE_DYNAMIC_CLASS(wxListMainWindow
)
853 DECLARE_EVENT_TABLE()
855 friend class wxGenericListCtrl
;
858 // ============================================================================
860 // ============================================================================
862 //-----------------------------------------------------------------------------
864 //-----------------------------------------------------------------------------
866 wxListItemData::~wxListItemData()
868 // in the virtual list control the attributes are managed by the main
869 // program, so don't delete them
870 if ( !m_owner
->IsVirtual() )
878 void wxListItemData::Init()
886 wxListItemData::wxListItemData(wxListMainWindow
*owner
)
892 if ( owner
->InReportView() )
902 void wxListItemData::SetItem( const wxListItem
&info
)
904 if ( info
.m_mask
& wxLIST_MASK_TEXT
)
905 SetText(info
.m_text
);
906 if ( info
.m_mask
& wxLIST_MASK_IMAGE
)
907 m_image
= info
.m_image
;
908 if ( info
.m_mask
& wxLIST_MASK_DATA
)
909 m_data
= info
.m_data
;
911 if ( info
.HasAttributes() )
914 *m_attr
= *info
.GetAttributes();
916 m_attr
= new wxListItemAttr(*info
.GetAttributes());
924 m_rect
->width
= info
.m_width
;
928 void wxListItemData::SetPosition( int x
, int y
)
930 wxCHECK_RET( m_rect
, _T("unexpected SetPosition() call") );
936 void wxListItemData::SetSize( int width
, int height
)
938 wxCHECK_RET( m_rect
, _T("unexpected SetSize() call") );
941 m_rect
->width
= width
;
943 m_rect
->height
= height
;
946 bool wxListItemData::IsHit( int x
, int y
) const
948 wxCHECK_MSG( m_rect
, false, _T("can't be called in this mode") );
950 return wxRect(GetX(), GetY(), GetWidth(), GetHeight()).Inside(x
, y
);
953 int wxListItemData::GetX() const
955 wxCHECK_MSG( m_rect
, 0, _T("can't be called in this mode") );
960 int wxListItemData::GetY() const
962 wxCHECK_MSG( m_rect
, 0, _T("can't be called in this mode") );
967 int wxListItemData::GetWidth() const
969 wxCHECK_MSG( m_rect
, 0, _T("can't be called in this mode") );
971 return m_rect
->width
;
974 int wxListItemData::GetHeight() const
976 wxCHECK_MSG( m_rect
, 0, _T("can't be called in this mode") );
978 return m_rect
->height
;
981 void wxListItemData::GetItem( wxListItem
&info
) const
983 info
.m_text
= m_text
;
984 info
.m_image
= m_image
;
985 info
.m_data
= m_data
;
989 if ( m_attr
->HasTextColour() )
990 info
.SetTextColour(m_attr
->GetTextColour());
991 if ( m_attr
->HasBackgroundColour() )
992 info
.SetBackgroundColour(m_attr
->GetBackgroundColour());
993 if ( m_attr
->HasFont() )
994 info
.SetFont(m_attr
->GetFont());
998 //-----------------------------------------------------------------------------
1000 //-----------------------------------------------------------------------------
1002 void wxListHeaderData::Init()
1013 wxListHeaderData::wxListHeaderData()
1018 wxListHeaderData::wxListHeaderData( const wxListItem
&item
)
1025 void wxListHeaderData::SetItem( const wxListItem
&item
)
1027 m_mask
= item
.m_mask
;
1029 if ( m_mask
& wxLIST_MASK_TEXT
)
1030 m_text
= item
.m_text
;
1032 if ( m_mask
& wxLIST_MASK_IMAGE
)
1033 m_image
= item
.m_image
;
1035 if ( m_mask
& wxLIST_MASK_FORMAT
)
1036 m_format
= item
.m_format
;
1038 if ( m_mask
& wxLIST_MASK_WIDTH
)
1039 SetWidth(item
.m_width
);
1042 void wxListHeaderData::SetPosition( int x
, int y
)
1048 void wxListHeaderData::SetHeight( int h
)
1053 void wxListHeaderData::SetWidth( int w
)
1057 m_width
= WIDTH_COL_DEFAULT
;
1058 else if (m_width
< WIDTH_COL_MIN
)
1059 m_width
= WIDTH_COL_MIN
;
1062 void wxListHeaderData::SetFormat( int format
)
1067 bool wxListHeaderData::HasImage() const
1069 return m_image
!= -1;
1072 bool wxListHeaderData::IsHit( int x
, int y
) const
1074 return ((x
>= m_xpos
) && (x
<= m_xpos
+m_width
) && (y
>= m_ypos
) && (y
<= m_ypos
+m_height
));
1077 void wxListHeaderData::GetItem( wxListItem
& item
)
1079 item
.m_mask
= m_mask
;
1080 item
.m_text
= m_text
;
1081 item
.m_image
= m_image
;
1082 item
.m_format
= m_format
;
1083 item
.m_width
= m_width
;
1086 int wxListHeaderData::GetImage() const
1091 int wxListHeaderData::GetWidth() const
1096 int wxListHeaderData::GetFormat() const
1101 //-----------------------------------------------------------------------------
1103 //-----------------------------------------------------------------------------
1105 inline int wxListLineData::GetMode() const
1107 return m_owner
->GetListCtrl()->GetWindowStyleFlag() & wxLC_MASK_TYPE
;
1110 inline bool wxListLineData::InReportView() const
1112 return m_owner
->HasFlag(wxLC_REPORT
);
1115 inline bool wxListLineData::IsVirtual() const
1117 return m_owner
->IsVirtual();
1120 wxListLineData::wxListLineData( wxListMainWindow
*owner
)
1124 if ( InReportView() )
1130 m_gi
= new GeometryInfo
;
1133 m_highlighted
= false;
1135 InitItems( GetMode() == wxLC_REPORT
? m_owner
->GetColumnCount() : 1 );
1138 void wxListLineData::CalculateSize( wxDC
*dc
, int spacing
)
1140 wxListItemDataList::compatibility_iterator node
= m_items
.GetFirst();
1141 wxCHECK_RET( node
, _T("no subitems at all??") );
1143 wxListItemData
*item
= node
->GetData();
1148 switch ( GetMode() )
1151 case wxLC_SMALL_ICON
:
1152 m_gi
->m_rectAll
.width
= spacing
;
1154 s
= item
->GetText();
1159 m_gi
->m_rectLabel
.width
=
1160 m_gi
->m_rectLabel
.height
= 0;
1164 dc
->GetTextExtent( s
, &lw
, &lh
);
1168 m_gi
->m_rectAll
.height
= spacing
+ lh
;
1170 m_gi
->m_rectAll
.width
= lw
;
1172 m_gi
->m_rectLabel
.width
= lw
;
1173 m_gi
->m_rectLabel
.height
= lh
;
1176 if (item
->HasImage())
1179 m_owner
->GetImageSize( item
->GetImage(), w
, h
);
1180 m_gi
->m_rectIcon
.width
= w
+ 8;
1181 m_gi
->m_rectIcon
.height
= h
+ 8;
1183 if ( m_gi
->m_rectIcon
.width
> m_gi
->m_rectAll
.width
)
1184 m_gi
->m_rectAll
.width
= m_gi
->m_rectIcon
.width
;
1185 if ( m_gi
->m_rectIcon
.height
+ lh
> m_gi
->m_rectAll
.height
- 4 )
1186 m_gi
->m_rectAll
.height
= m_gi
->m_rectIcon
.height
+ lh
+ 4;
1189 if ( item
->HasText() )
1191 m_gi
->m_rectHighlight
.width
= m_gi
->m_rectLabel
.width
;
1192 m_gi
->m_rectHighlight
.height
= m_gi
->m_rectLabel
.height
;
1194 else // no text, highlight the icon
1196 m_gi
->m_rectHighlight
.width
= m_gi
->m_rectIcon
.width
;
1197 m_gi
->m_rectHighlight
.height
= m_gi
->m_rectIcon
.height
;
1202 s
= item
->GetTextForMeasuring();
1204 dc
->GetTextExtent( s
, &lw
, &lh
);
1208 m_gi
->m_rectLabel
.width
= lw
;
1209 m_gi
->m_rectLabel
.height
= lh
;
1211 m_gi
->m_rectAll
.width
= lw
;
1212 m_gi
->m_rectAll
.height
= lh
;
1214 if (item
->HasImage())
1217 m_owner
->GetImageSize( item
->GetImage(), w
, h
);
1218 m_gi
->m_rectIcon
.width
= w
;
1219 m_gi
->m_rectIcon
.height
= h
;
1221 m_gi
->m_rectAll
.width
+= 4 + w
;
1222 if (h
> m_gi
->m_rectAll
.height
)
1223 m_gi
->m_rectAll
.height
= h
;
1226 m_gi
->m_rectHighlight
.width
= m_gi
->m_rectAll
.width
;
1227 m_gi
->m_rectHighlight
.height
= m_gi
->m_rectAll
.height
;
1231 wxFAIL_MSG( _T("unexpected call to SetSize") );
1235 wxFAIL_MSG( _T("unknown mode") );
1239 void wxListLineData::SetPosition( int x
, int y
, int spacing
)
1241 wxListItemDataList::compatibility_iterator node
= m_items
.GetFirst();
1242 wxCHECK_RET( node
, _T("no subitems at all??") );
1244 wxListItemData
*item
= node
->GetData();
1246 switch ( GetMode() )
1249 case wxLC_SMALL_ICON
:
1250 m_gi
->m_rectAll
.x
= x
;
1251 m_gi
->m_rectAll
.y
= y
;
1253 if ( item
->HasImage() )
1255 m_gi
->m_rectIcon
.x
= m_gi
->m_rectAll
.x
+ 4 +
1256 (m_gi
->m_rectAll
.width
- m_gi
->m_rectIcon
.width
) / 2;
1257 m_gi
->m_rectIcon
.y
= m_gi
->m_rectAll
.y
+ 4;
1260 if ( item
->HasText() )
1262 if (m_gi
->m_rectAll
.width
> spacing
)
1263 m_gi
->m_rectLabel
.x
= m_gi
->m_rectAll
.x
+ 2;
1265 m_gi
->m_rectLabel
.x
= m_gi
->m_rectAll
.x
+ 2 + (spacing
/2) - (m_gi
->m_rectLabel
.width
/2);
1266 m_gi
->m_rectLabel
.y
= m_gi
->m_rectAll
.y
+ m_gi
->m_rectAll
.height
+ 2 - m_gi
->m_rectLabel
.height
;
1267 m_gi
->m_rectHighlight
.x
= m_gi
->m_rectLabel
.x
- 2;
1268 m_gi
->m_rectHighlight
.y
= m_gi
->m_rectLabel
.y
- 2;
1270 else // no text, highlight the icon
1272 m_gi
->m_rectHighlight
.x
= m_gi
->m_rectIcon
.x
- 4;
1273 m_gi
->m_rectHighlight
.y
= m_gi
->m_rectIcon
.y
- 4;
1278 m_gi
->m_rectAll
.x
= x
;
1279 m_gi
->m_rectAll
.y
= y
;
1281 m_gi
->m_rectHighlight
.x
= m_gi
->m_rectAll
.x
;
1282 m_gi
->m_rectHighlight
.y
= m_gi
->m_rectAll
.y
;
1283 m_gi
->m_rectLabel
.y
= m_gi
->m_rectAll
.y
+ 2;
1285 if (item
->HasImage())
1287 m_gi
->m_rectIcon
.x
= m_gi
->m_rectAll
.x
+ 2;
1288 m_gi
->m_rectIcon
.y
= m_gi
->m_rectAll
.y
+ 2;
1289 m_gi
->m_rectLabel
.x
= m_gi
->m_rectAll
.x
+ 6 + m_gi
->m_rectIcon
.width
;
1293 m_gi
->m_rectLabel
.x
= m_gi
->m_rectAll
.x
+ 2;
1298 wxFAIL_MSG( _T("unexpected call to SetPosition") );
1302 wxFAIL_MSG( _T("unknown mode") );
1306 void wxListLineData::InitItems( int num
)
1308 for (int i
= 0; i
< num
; i
++)
1309 m_items
.Append( new wxListItemData(m_owner
) );
1312 void wxListLineData::SetItem( int index
, const wxListItem
&info
)
1314 wxListItemDataList::compatibility_iterator node
= m_items
.Item( index
);
1315 wxCHECK_RET( node
, _T("invalid column index in SetItem") );
1317 wxListItemData
*item
= node
->GetData();
1318 item
->SetItem( info
);
1321 void wxListLineData::GetItem( int index
, wxListItem
&info
)
1323 wxListItemDataList::compatibility_iterator node
= m_items
.Item( index
);
1326 wxListItemData
*item
= node
->GetData();
1327 item
->GetItem( info
);
1331 wxString
wxListLineData::GetText(int index
) const
1335 wxListItemDataList::compatibility_iterator node
= m_items
.Item( index
);
1338 wxListItemData
*item
= node
->GetData();
1339 s
= item
->GetText();
1345 void wxListLineData::SetText( int index
, const wxString s
)
1347 wxListItemDataList::compatibility_iterator node
= m_items
.Item( index
);
1350 wxListItemData
*item
= node
->GetData();
1355 void wxListLineData::SetImage( int index
, int image
)
1357 wxListItemDataList::compatibility_iterator node
= m_items
.Item( index
);
1358 wxCHECK_RET( node
, _T("invalid column index in SetImage()") );
1360 wxListItemData
*item
= node
->GetData();
1361 item
->SetImage(image
);
1364 int wxListLineData::GetImage( int index
) const
1366 wxListItemDataList::compatibility_iterator node
= m_items
.Item( index
);
1367 wxCHECK_MSG( node
, -1, _T("invalid column index in GetImage()") );
1369 wxListItemData
*item
= node
->GetData();
1370 return item
->GetImage();
1373 wxListItemAttr
*wxListLineData::GetAttr() const
1375 wxListItemDataList::compatibility_iterator node
= m_items
.GetFirst();
1376 wxCHECK_MSG( node
, NULL
, _T("invalid column index in GetAttr()") );
1378 wxListItemData
*item
= node
->GetData();
1379 return item
->GetAttr();
1382 void wxListLineData::SetAttr(wxListItemAttr
*attr
)
1384 wxListItemDataList::compatibility_iterator node
= m_items
.GetFirst();
1385 wxCHECK_RET( node
, _T("invalid column index in SetAttr()") );
1387 wxListItemData
*item
= node
->GetData();
1388 item
->SetAttr(attr
);
1391 bool wxListLineData::SetAttributes(wxDC
*dc
,
1392 const wxListItemAttr
*attr
,
1395 wxWindow
*listctrl
= m_owner
->GetParent();
1399 // don't use foreground colour for drawing highlighted items - this might
1400 // make them completely invisible (and there is no way to do bit
1401 // arithmetics on wxColour, unfortunately)
1405 colText
= wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHTTEXT
);
1409 if ( attr
&& attr
->HasTextColour() )
1411 colText
= attr
->GetTextColour();
1415 colText
= listctrl
->GetForegroundColour();
1419 dc
->SetTextForeground(colText
);
1423 if ( attr
&& attr
->HasFont() )
1425 font
= attr
->GetFont();
1429 font
= listctrl
->GetFont();
1435 bool hasBgCol
= attr
&& attr
->HasBackgroundColour();
1436 if ( highlighted
|| hasBgCol
)
1440 dc
->SetBrush( *m_owner
->GetHighlightBrush() );
1444 dc
->SetBrush(wxBrush(attr
->GetBackgroundColour(), wxSOLID
));
1447 dc
->SetPen( *wxTRANSPARENT_PEN
);
1455 void wxListLineData::Draw( wxDC
*dc
)
1457 wxListItemDataList::compatibility_iterator node
= m_items
.GetFirst();
1458 wxCHECK_RET( node
, _T("no subitems at all??") );
1460 bool highlighted
= IsHighlighted();
1462 wxListItemAttr
*attr
= GetAttr();
1464 if ( SetAttributes(dc
, attr
, highlighted
) )
1466 dc
->DrawRectangle( m_gi
->m_rectHighlight
);
1469 // just for debugging to better see where the items are
1471 dc
->SetPen(*wxRED_PEN
);
1472 dc
->SetBrush(*wxTRANSPARENT_BRUSH
);
1473 dc
->DrawRectangle( m_gi
->m_rectAll
);
1474 dc
->SetPen(*wxGREEN_PEN
);
1475 dc
->DrawRectangle( m_gi
->m_rectIcon
);
1478 wxListItemData
*item
= node
->GetData();
1479 if (item
->HasImage())
1481 // centre the image inside our rectangle, this looks nicer when items
1482 // ae aligned in a row
1483 const wxRect
& rectIcon
= m_gi
->m_rectIcon
;
1485 m_owner
->DrawImage(item
->GetImage(), dc
, rectIcon
.x
, rectIcon
.y
);
1488 if (item
->HasText())
1490 const wxRect
& rectLabel
= m_gi
->m_rectLabel
;
1492 wxDCClipper
clipper(*dc
, rectLabel
);
1493 dc
->DrawText(item
->GetText(), rectLabel
.x
, rectLabel
.y
);
1497 void wxListLineData::DrawInReportMode( wxDC
*dc
,
1499 const wxRect
& rectHL
,
1502 // TODO: later we should support setting different attributes for
1503 // different columns - to do it, just add "col" argument to
1504 // GetAttr() and move these lines into the loop below
1505 wxListItemAttr
*attr
= GetAttr();
1506 if ( SetAttributes(dc
, attr
, highlighted
) )
1508 dc
->DrawRectangle( rectHL
);
1511 wxCoord x
= rect
.x
+ HEADER_OFFSET_X
,
1512 y
= rect
.y
+ (LINE_SPACING
+ EXTRA_HEIGHT
) / 2;
1515 for ( wxListItemDataList::compatibility_iterator node
= m_items
.GetFirst();
1517 node
= node
->GetNext(), col
++ )
1519 wxListItemData
*item
= node
->GetData();
1521 int width
= m_owner
->GetColumnWidth(col
);
1525 if ( item
->HasImage() )
1528 m_owner
->DrawImage( item
->GetImage(), dc
, xOld
, y
);
1529 m_owner
->GetImageSize( item
->GetImage(), ix
, iy
);
1531 ix
+= IMAGE_MARGIN_IN_REPORT_MODE
;
1537 wxDCClipper
clipper(*dc
, xOld
, y
, width
- 8, rect
.height
);
1539 if ( item
->HasText() )
1541 DrawTextFormatted(dc
, item
->GetText(), col
, xOld
, y
, width
- 8);
1546 void wxListLineData::DrawTextFormatted(wxDC
*dc
,
1547 const wxString
&text
,
1553 wxString drawntext
, ellipsis
;
1554 wxCoord w
, h
, base_w
;
1557 // determine if the string can fit inside the current width
1558 dc
->GetTextExtent(text
, &w
, &h
);
1561 // it can, draw it using the items alignment
1562 m_owner
->GetColumn(col
, item
);
1563 switch ( item
.GetAlign() )
1566 wxFAIL_MSG( _T("unknown list item format") );
1569 case wxLIST_FORMAT_LEFT
:
1573 case wxLIST_FORMAT_RIGHT
:
1577 case wxLIST_FORMAT_CENTER
:
1578 x
+= (width
- w
) / 2;
1582 dc
->DrawText(text
, x
, y
);
1584 else // otherwise, truncate and add an ellipsis if possible
1586 // determine the base width
1587 ellipsis
= wxString(wxT("..."));
1588 dc
->GetTextExtent(ellipsis
, &base_w
, &h
);
1590 // continue until we have enough space or only one character left
1592 size_t len
= text
.Length();
1593 drawntext
= text
.Left(len
);
1596 dc
->GetTextExtent(drawntext
.Last(), &w_c
, &h_c
);
1597 drawntext
.RemoveLast();
1600 if (w
+ base_w
<= width
)
1604 // if still not enough space, remove ellipsis characters
1605 while (ellipsis
.Length() > 0 && w
+ base_w
> width
)
1607 ellipsis
= ellipsis
.Left(ellipsis
.Length() - 1);
1608 dc
->GetTextExtent(ellipsis
, &base_w
, &h
);
1611 // now draw the text
1612 dc
->DrawText(drawntext
, x
, y
);
1613 dc
->DrawText(ellipsis
, x
+ w
, y
);
1617 bool wxListLineData::Highlight( bool on
)
1619 wxCHECK_MSG( !IsVirtual(), false, _T("unexpected call to Highlight") );
1621 if ( on
== m_highlighted
)
1629 void wxListLineData::ReverseHighlight( void )
1631 Highlight(!IsHighlighted());
1634 //-----------------------------------------------------------------------------
1635 // wxListHeaderWindow
1636 //-----------------------------------------------------------------------------
1638 IMPLEMENT_DYNAMIC_CLASS(wxListHeaderWindow
,wxWindow
)
1640 BEGIN_EVENT_TABLE(wxListHeaderWindow
,wxWindow
)
1641 EVT_PAINT (wxListHeaderWindow::OnPaint
)
1642 EVT_MOUSE_EVENTS (wxListHeaderWindow::OnMouse
)
1643 EVT_SET_FOCUS (wxListHeaderWindow::OnSetFocus
)
1646 void wxListHeaderWindow::Init()
1648 m_currentCursor
= (wxCursor
*) NULL
;
1649 m_isDragging
= false;
1653 wxListHeaderWindow::wxListHeaderWindow()
1657 m_owner
= (wxListMainWindow
*) NULL
;
1658 m_resizeCursor
= (wxCursor
*) NULL
;
1661 wxListHeaderWindow::wxListHeaderWindow( wxWindow
*win
,
1663 wxListMainWindow
*owner
,
1667 const wxString
&name
)
1668 : wxWindow( win
, id
, pos
, size
, style
, name
)
1673 m_resizeCursor
= new wxCursor( wxCURSOR_SIZEWE
);
1676 wxVisualAttributes attr
= wxPanel::GetClassDefaultAttributes();
1677 SetOwnForegroundColour( attr
.colFg
);
1678 SetOwnBackgroundColour( attr
.colBg
);
1680 SetOwnFont( attr
.font
);
1682 SetOwnForegroundColour( wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT
));
1683 SetOwnBackgroundColour( wxSystemSettings::GetColour(wxSYS_COLOUR_BTNFACE
));
1685 SetOwnFont( wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT
));
1689 wxListHeaderWindow::~wxListHeaderWindow()
1691 delete m_resizeCursor
;
1694 #ifdef __WXUNIVERSAL__
1695 #include "wx/univ/renderer.h"
1696 #include "wx/univ/theme.h"
1699 // shift the DC origin to match the position of the main window horz
1700 // scrollbar: this allows us to always use logical coords
1701 void wxListHeaderWindow::AdjustDC(wxDC
& dc
)
1704 m_owner
->GetScrollPixelsPerUnit( &xpix
, NULL
);
1707 m_owner
->GetViewStart( &x
, NULL
);
1709 // account for the horz scrollbar offset
1710 dc
.SetDeviceOrigin( -x
* xpix
, 0 );
1713 void wxListHeaderWindow::OnPaint( wxPaintEvent
&WXUNUSED(event
) )
1715 wxPaintDC
dc( this );
1722 dc
.SetFont( GetFont() );
1724 // width and height of the entire header window
1726 GetClientSize( &w
, &h
);
1727 m_owner
->CalcUnscrolledPosition(w
, 0, &w
, NULL
);
1729 dc
.SetBackgroundMode(wxTRANSPARENT
);
1731 dc
.SetTextForeground(GetForegroundColour());
1733 int x
= HEADER_OFFSET_X
;
1735 int numColumns
= m_owner
->GetColumnCount();
1737 for ( int i
= 0; i
< numColumns
&& x
< w
; i
++ )
1739 m_owner
->GetColumn( i
, item
);
1740 int wCol
= item
.m_width
;
1742 // the width of the rect to draw: make it smaller to fit entirely
1743 // inside the column rect
1751 wxRendererNative::Get().DrawHeaderButton
1755 wxRect(x
, HEADER_OFFSET_Y
, cw
, ch
),
1756 m_parent
->IsEnabled() ? 0
1757 : (int)wxCONTROL_DISABLED
1760 // see if we have enough space for the column label
1762 // for this we need the width of the text
1765 dc
.GetTextExtent(item
.GetText(), &wLabel
, &hLabel
);
1766 wLabel
+= 2*EXTRA_WIDTH
;
1768 // and the width of the icon, if any
1769 static const int MARGIN_BETWEEN_TEXT_AND_ICON
= 2;
1770 int ix
= 0, // init them just to suppress the compiler warnings
1772 const int image
= item
.m_image
;
1773 wxImageListType
*imageList
;
1776 imageList
= m_owner
->m_small_image_list
;
1779 imageList
->GetSize(image
, ix
, iy
);
1780 wLabel
+= ix
+ MARGIN_BETWEEN_TEXT_AND_ICON
;
1788 // ignore alignment if there is not enough space anyhow
1790 switch ( wLabel
< cw
? item
.GetAlign() : wxLIST_FORMAT_LEFT
)
1793 wxFAIL_MSG( _T("unknown list item format") );
1796 case wxLIST_FORMAT_LEFT
:
1800 case wxLIST_FORMAT_RIGHT
:
1801 xAligned
= x
+ cw
- wLabel
;
1804 case wxLIST_FORMAT_CENTER
:
1805 xAligned
= x
+ (cw
- wLabel
) / 2;
1810 // if we have an image, draw it on the right of the label
1817 xAligned
+ wLabel
- ix
- MARGIN_BETWEEN_TEXT_AND_ICON
,
1818 HEADER_OFFSET_Y
+ (h
- 4 - iy
)/2,
1819 wxIMAGELIST_DRAW_TRANSPARENT
1822 cw
-= ix
+ MARGIN_BETWEEN_TEXT_AND_ICON
;
1825 // draw the text clipping it so that it doesn't overwrite the column
1827 wxDCClipper
clipper(dc
, x
, HEADER_OFFSET_Y
, cw
, h
- 4 );
1829 dc
.DrawText( item
.GetText(),
1830 xAligned
+ EXTRA_WIDTH
, h
/ 2 - hLabel
/ 2 ); //HEADER_OFFSET_Y + EXTRA_HEIGHT );
1838 void wxListHeaderWindow::DrawCurrent()
1840 int x1
= m_currentX
;
1842 m_owner
->ClientToScreen( &x1
, &y1
);
1844 int x2
= m_currentX
;
1846 m_owner
->GetClientSize( NULL
, &y2
);
1847 m_owner
->ClientToScreen( &x2
, &y2
);
1850 dc
.SetLogicalFunction( wxINVERT
);
1851 dc
.SetPen( wxPen( *wxBLACK
, 2, wxSOLID
) );
1852 dc
.SetBrush( *wxTRANSPARENT_BRUSH
);
1856 dc
.DrawLine( x1
, y1
, x2
, y2
);
1858 dc
.SetLogicalFunction( wxCOPY
);
1860 dc
.SetPen( wxNullPen
);
1861 dc
.SetBrush( wxNullBrush
);
1864 void wxListHeaderWindow::OnMouse( wxMouseEvent
&event
)
1866 // we want to work with logical coords
1868 m_owner
->CalcUnscrolledPosition(event
.GetX(), 0, &x
, NULL
);
1869 int y
= event
.GetY();
1873 SendListEvent(wxEVT_COMMAND_LIST_COL_DRAGGING
, event
.GetPosition());
1875 // we don't draw the line beyond our window, but we allow dragging it
1878 GetClientSize( &w
, NULL
);
1879 m_owner
->CalcUnscrolledPosition(w
, 0, &w
, NULL
);
1882 // erase the line if it was drawn
1883 if ( m_currentX
< w
)
1886 if (event
.ButtonUp())
1889 m_isDragging
= false;
1891 m_owner
->SetColumnWidth( m_column
, m_currentX
- m_minX
);
1892 SendListEvent(wxEVT_COMMAND_LIST_COL_END_DRAG
, event
.GetPosition());
1899 m_currentX
= m_minX
+ 7;
1901 // draw in the new location
1902 if ( m_currentX
< w
)
1906 else // not dragging
1909 bool hit_border
= false;
1911 // end of the current column
1914 // find the column where this event occured
1916 countCol
= m_owner
->GetColumnCount();
1917 for (col
= 0; col
< countCol
; col
++)
1919 xpos
+= m_owner
->GetColumnWidth( col
);
1922 if ( (abs(x
-xpos
) < 3) && (y
< 22) )
1924 // near the column border
1931 // inside the column
1938 if ( col
== countCol
)
1941 if (event
.LeftDown() || event
.RightUp())
1943 if (hit_border
&& event
.LeftDown())
1945 if ( SendListEvent(wxEVT_COMMAND_LIST_COL_BEGIN_DRAG
,
1946 event
.GetPosition()) )
1948 m_isDragging
= true;
1953 //else: column resizing was vetoed by the user code
1955 else // click on a column
1957 SendListEvent( event
.LeftDown()
1958 ? wxEVT_COMMAND_LIST_COL_CLICK
1959 : wxEVT_COMMAND_LIST_COL_RIGHT_CLICK
,
1960 event
.GetPosition());
1963 else if (event
.Moving())
1968 setCursor
= m_currentCursor
== wxSTANDARD_CURSOR
;
1969 m_currentCursor
= m_resizeCursor
;
1973 setCursor
= m_currentCursor
!= wxSTANDARD_CURSOR
;
1974 m_currentCursor
= wxSTANDARD_CURSOR
;
1978 SetCursor(*m_currentCursor
);
1983 void wxListHeaderWindow::OnSetFocus( wxFocusEvent
&WXUNUSED(event
) )
1985 m_owner
->SetFocus();
1989 bool wxListHeaderWindow::SendListEvent(wxEventType type
, wxPoint pos
)
1991 wxWindow
*parent
= GetParent();
1992 wxListEvent
le( type
, parent
->GetId() );
1993 le
.SetEventObject( parent
);
1994 le
.m_pointDrag
= pos
;
1996 // the position should be relative to the parent window, not
1997 // this one for compatibility with MSW and common sense: the
1998 // user code doesn't know anything at all about this header
1999 // window, so why should it get positions relative to it?
2000 le
.m_pointDrag
.y
-= GetSize().y
;
2002 le
.m_col
= m_column
;
2003 return !parent
->GetEventHandler()->ProcessEvent( le
) || le
.IsAllowed();
2006 //-----------------------------------------------------------------------------
2007 // wxListRenameTimer (internal)
2008 //-----------------------------------------------------------------------------
2010 wxListRenameTimer::wxListRenameTimer( wxListMainWindow
*owner
)
2015 void wxListRenameTimer::Notify()
2017 m_owner
->OnRenameTimer();
2020 //-----------------------------------------------------------------------------
2021 // wxListTextCtrl (internal)
2022 //-----------------------------------------------------------------------------
2024 BEGIN_EVENT_TABLE(wxListTextCtrl
,wxTextCtrl
)
2025 EVT_CHAR (wxListTextCtrl::OnChar
)
2026 EVT_KEY_UP (wxListTextCtrl::OnKeyUp
)
2027 EVT_KILL_FOCUS (wxListTextCtrl::OnKillFocus
)
2030 wxListTextCtrl::wxListTextCtrl(wxListMainWindow
*owner
, size_t itemEdit
)
2031 : m_startValue(owner
->GetItemText(itemEdit
)),
2032 m_itemEdited(itemEdit
)
2036 m_aboutToFinish
= false;
2038 wxRect rectLabel
= owner
->GetLineLabelRect(itemEdit
);
2040 m_owner
->CalcScrolledPosition(rectLabel
.x
, rectLabel
.y
,
2041 &rectLabel
.x
, &rectLabel
.y
);
2043 (void)Create(owner
, wxID_ANY
, m_startValue
,
2044 wxPoint(rectLabel
.x
-4,rectLabel
.y
-4),
2045 wxSize(rectLabel
.width
+11,rectLabel
.height
+8));
2048 void wxListTextCtrl::Finish()
2052 wxPendingDelete
.Append(this);
2056 m_owner
->SetFocusIgnoringChildren();
2060 bool wxListTextCtrl::AcceptChanges()
2062 const wxString value
= GetValue();
2064 if ( value
== m_startValue
)
2066 // nothing changed, always accept
2070 if ( !m_owner
->OnRenameAccept(m_itemEdited
, value
) )
2072 // vetoed by the user
2076 // accepted, do rename the item
2077 m_owner
->SetItemText(m_itemEdited
, value
);
2082 void wxListTextCtrl::OnChar( wxKeyEvent
&event
)
2084 switch ( event
.m_keyCode
)
2087 m_aboutToFinish
= true;
2088 // Notify the owner about the changes
2090 // Even if vetoed, close the control (consistent with MSW)
2096 m_owner
->OnRenameCancelled( m_itemEdited
);
2104 void wxListTextCtrl::OnKeyUp( wxKeyEvent
&event
)
2112 // auto-grow the textctrl:
2113 wxSize parentSize
= m_owner
->GetSize();
2114 wxPoint myPos
= GetPosition();
2115 wxSize mySize
= GetSize();
2117 GetTextExtent(GetValue() + _T("MM"), &sx
, &sy
);
2118 if (myPos
.x
+ sx
> parentSize
.x
)
2119 sx
= parentSize
.x
- myPos
.x
;
2122 SetSize(sx
, wxDefaultCoord
);
2127 void wxListTextCtrl::OnKillFocus( wxFocusEvent
&event
)
2131 // We must finish regardless of success, otherwise we'll get
2135 if ( !AcceptChanges() )
2136 m_owner
->OnRenameCancelled( m_itemEdited
);
2139 // We must let the native text control handle focus, too, otherwise
2140 // it could have problems with the cursor (e.g., in wxGTK).
2144 //-----------------------------------------------------------------------------
2146 //-----------------------------------------------------------------------------
2148 IMPLEMENT_DYNAMIC_CLASS(wxListMainWindow
,wxScrolledWindow
)
2150 BEGIN_EVENT_TABLE(wxListMainWindow
,wxScrolledWindow
)
2151 EVT_PAINT (wxListMainWindow::OnPaint
)
2152 EVT_MOUSE_EVENTS (wxListMainWindow::OnMouse
)
2153 EVT_CHAR (wxListMainWindow::OnChar
)
2154 EVT_KEY_DOWN (wxListMainWindow::OnKeyDown
)
2155 EVT_SET_FOCUS (wxListMainWindow::OnSetFocus
)
2156 EVT_KILL_FOCUS (wxListMainWindow::OnKillFocus
)
2157 EVT_SCROLLWIN (wxListMainWindow::OnScroll
)
2160 void wxListMainWindow::Init()
2165 m_lineTo
= (size_t)-1;
2171 m_small_image_list
= (wxImageListType
*) NULL
;
2172 m_normal_image_list
= (wxImageListType
*) NULL
;
2174 m_small_spacing
= 30;
2175 m_normal_spacing
= 40;
2179 m_isCreated
= false;
2181 m_lastOnSame
= false;
2182 m_renameTimer
= new wxListRenameTimer( this );
2186 m_lineSelectSingleOnUp
=
2187 m_lineBeforeLastClicked
= (size_t)-1;
2192 wxListMainWindow::wxListMainWindow()
2197 m_highlightUnfocusedBrush
= (wxBrush
*) NULL
;
2200 wxListMainWindow::wxListMainWindow( wxWindow
*parent
,
2205 const wxString
&name
)
2206 : wxScrolledWindow( parent
, id
, pos
, size
,
2207 style
| wxHSCROLL
| wxVSCROLL
, name
)
2211 m_highlightBrush
= new wxBrush
2213 wxSystemSettings::GetColour
2215 wxSYS_COLOUR_HIGHLIGHT
2220 m_highlightUnfocusedBrush
= new wxBrush
2222 wxSystemSettings::GetColour
2224 wxSYS_COLOUR_BTNSHADOW
2232 SetScrollbars( 0, 0, 0, 0, 0, 0 );
2234 wxVisualAttributes attr
= wxGenericListCtrl::GetClassDefaultAttributes();
2235 SetOwnForegroundColour( attr
.colFg
);
2236 SetOwnBackgroundColour( attr
.colBg
);
2238 SetOwnFont( attr
.font
);
2241 wxListMainWindow::~wxListMainWindow()
2244 WX_CLEAR_LIST(wxListHeaderDataList
, m_columns
);
2246 delete m_highlightBrush
;
2247 delete m_highlightUnfocusedBrush
;
2249 delete m_renameTimer
;
2252 void wxListMainWindow::CacheLineData(size_t line
)
2254 wxGenericListCtrl
*listctrl
= GetListCtrl();
2256 wxListLineData
*ld
= GetDummyLine();
2258 size_t countCol
= GetColumnCount();
2259 for ( size_t col
= 0; col
< countCol
; col
++ )
2261 ld
->SetText(col
, listctrl
->OnGetItemText(line
, col
));
2264 ld
->SetImage(listctrl
->OnGetItemImage(line
));
2265 ld
->SetAttr(listctrl
->OnGetItemAttr(line
));
2268 wxListLineData
*wxListMainWindow::GetDummyLine() const
2270 wxASSERT_MSG( !IsEmpty(), _T("invalid line index") );
2272 wxASSERT_MSG( IsVirtual(), _T("GetDummyLine() shouldn't be called") );
2274 wxListMainWindow
*self
= wxConstCast(this, wxListMainWindow
);
2276 // we need to recreate the dummy line if the number of columns in the
2277 // control changed as it would have the incorrect number of fields
2279 if ( !m_lines
.IsEmpty() &&
2280 m_lines
[0].m_items
.GetCount() != (size_t)GetColumnCount() )
2282 self
->m_lines
.Clear();
2285 if ( m_lines
.IsEmpty() )
2287 wxListLineData
*line
= new wxListLineData(self
);
2288 self
->m_lines
.Add(line
);
2290 // don't waste extra memory -- there never going to be anything
2291 // else/more in this array
2292 self
->m_lines
.Shrink();
2298 // ----------------------------------------------------------------------------
2299 // line geometry (report mode only)
2300 // ----------------------------------------------------------------------------
2302 wxCoord
wxListMainWindow::GetLineHeight() const
2304 // we cache the line height as calling GetTextExtent() is slow
2305 if ( !m_lineHeight
)
2307 wxListMainWindow
*self
= wxConstCast(this, wxListMainWindow
);
2309 wxClientDC
dc( self
);
2310 dc
.SetFont( GetFont() );
2313 dc
.GetTextExtent(_T("H"), NULL
, &y
);
2315 if ( m_small_image_list
&& m_small_image_list
->GetImageCount() )
2319 m_small_image_list
->GetSize(0, iw
, ih
);
2324 self
->m_lineHeight
= y
+ LINE_SPACING
;
2327 return m_lineHeight
;
2330 wxCoord
wxListMainWindow::GetLineY(size_t line
) const
2332 wxASSERT_MSG( InReportView(), _T("only works in report mode") );
2334 return LINE_SPACING
+ line
*GetLineHeight();
2337 wxRect
wxListMainWindow::GetLineRect(size_t line
) const
2339 if ( !InReportView() )
2340 return GetLine(line
)->m_gi
->m_rectAll
;
2343 rect
.x
= HEADER_OFFSET_X
;
2344 rect
.y
= GetLineY(line
);
2345 rect
.width
= GetHeaderWidth();
2346 rect
.height
= GetLineHeight();
2351 wxRect
wxListMainWindow::GetLineLabelRect(size_t line
) const
2353 if ( !InReportView() )
2354 return GetLine(line
)->m_gi
->m_rectLabel
;
2357 rect
.x
= HEADER_OFFSET_X
;
2358 rect
.y
= GetLineY(line
);
2359 rect
.width
= GetColumnWidth(0);
2360 rect
.height
= GetLineHeight();
2365 wxRect
wxListMainWindow::GetLineIconRect(size_t line
) const
2367 if ( !InReportView() )
2368 return GetLine(line
)->m_gi
->m_rectIcon
;
2370 wxListLineData
*ld
= GetLine(line
);
2371 wxASSERT_MSG( ld
->HasImage(), _T("should have an image") );
2374 rect
.x
= HEADER_OFFSET_X
;
2375 rect
.y
= GetLineY(line
);
2376 GetImageSize(ld
->GetImage(), rect
.width
, rect
.height
);
2381 wxRect
wxListMainWindow::GetLineHighlightRect(size_t line
) const
2383 return InReportView() ? GetLineRect(line
)
2384 : GetLine(line
)->m_gi
->m_rectHighlight
;
2387 long wxListMainWindow::HitTestLine(size_t line
, int x
, int y
) const
2389 wxASSERT_MSG( line
< GetItemCount(), _T("invalid line in HitTestLine") );
2391 wxListLineData
*ld
= GetLine(line
);
2393 if ( ld
->HasImage() && GetLineIconRect(line
).Inside(x
, y
) )
2394 return wxLIST_HITTEST_ONITEMICON
;
2396 // VS: Testing for "ld->HasText() || InReportView()" instead of
2397 // "ld->HasText()" is needed to make empty lines in report view
2399 if ( ld
->HasText() || InReportView() )
2401 wxRect rect
= InReportView() ? GetLineRect(line
)
2402 : GetLineLabelRect(line
);
2404 if ( rect
.Inside(x
, y
) )
2405 return wxLIST_HITTEST_ONITEMLABEL
;
2411 // ----------------------------------------------------------------------------
2412 // highlight (selection) handling
2413 // ----------------------------------------------------------------------------
2415 bool wxListMainWindow::IsHighlighted(size_t line
) const
2419 return m_selStore
.IsSelected(line
);
2423 wxListLineData
*ld
= GetLine(line
);
2424 wxCHECK_MSG( ld
, false, _T("invalid index in IsHighlighted") );
2426 return ld
->IsHighlighted();
2430 void wxListMainWindow::HighlightLines( size_t lineFrom
,
2436 wxArrayInt linesChanged
;
2437 if ( !m_selStore
.SelectRange(lineFrom
, lineTo
, highlight
,
2440 // meny items changed state, refresh everything
2441 RefreshLines(lineFrom
, lineTo
);
2443 else // only a few items changed state, refresh only them
2445 size_t count
= linesChanged
.GetCount();
2446 for ( size_t n
= 0; n
< count
; n
++ )
2448 RefreshLine(linesChanged
[n
]);
2452 else // iterate over all items in non report view
2454 for ( size_t line
= lineFrom
; line
<= lineTo
; line
++ )
2456 if ( HighlightLine(line
, highlight
) )
2464 bool wxListMainWindow::HighlightLine( size_t line
, bool highlight
)
2470 changed
= m_selStore
.SelectItem(line
, highlight
);
2474 wxListLineData
*ld
= GetLine(line
);
2475 wxCHECK_MSG( ld
, false, _T("invalid index in HighlightLine") );
2477 changed
= ld
->Highlight(highlight
);
2482 SendNotify( line
, highlight
? wxEVT_COMMAND_LIST_ITEM_SELECTED
2483 : wxEVT_COMMAND_LIST_ITEM_DESELECTED
);
2489 void wxListMainWindow::RefreshLine( size_t line
)
2491 if ( InReportView() )
2493 size_t visibleFrom
, visibleTo
;
2494 GetVisibleLinesRange(&visibleFrom
, &visibleTo
);
2496 if ( line
< visibleFrom
|| line
> visibleTo
)
2500 wxRect rect
= GetLineRect(line
);
2502 CalcScrolledPosition( rect
.x
, rect
.y
, &rect
.x
, &rect
.y
);
2503 RefreshRect( rect
);
2506 void wxListMainWindow::RefreshLines( size_t lineFrom
, size_t lineTo
)
2508 // we suppose that they are ordered by caller
2509 wxASSERT_MSG( lineFrom
<= lineTo
, _T("indices in disorder") );
2511 wxASSERT_MSG( lineTo
< GetItemCount(), _T("invalid line range") );
2513 if ( InReportView() )
2515 size_t visibleFrom
, visibleTo
;
2516 GetVisibleLinesRange(&visibleFrom
, &visibleTo
);
2518 if ( lineFrom
< visibleFrom
)
2519 lineFrom
= visibleFrom
;
2520 if ( lineTo
> visibleTo
)
2525 rect
.y
= GetLineY(lineFrom
);
2526 rect
.width
= GetClientSize().x
;
2527 rect
.height
= GetLineY(lineTo
) - rect
.y
+ GetLineHeight();
2529 CalcScrolledPosition( rect
.x
, rect
.y
, &rect
.x
, &rect
.y
);
2530 RefreshRect( rect
);
2534 // TODO: this should be optimized...
2535 for ( size_t line
= lineFrom
; line
<= lineTo
; line
++ )
2542 void wxListMainWindow::RefreshAfter( size_t lineFrom
)
2544 if ( InReportView() )
2546 size_t visibleFrom
, visibleTo
;
2547 GetVisibleLinesRange(&visibleFrom
, &visibleTo
);
2549 if ( lineFrom
< visibleFrom
)
2550 lineFrom
= visibleFrom
;
2551 else if ( lineFrom
> visibleTo
)
2556 rect
.y
= GetLineY(lineFrom
);
2557 CalcScrolledPosition( rect
.x
, rect
.y
, &rect
.x
, &rect
.y
);
2559 wxSize size
= GetClientSize();
2560 rect
.width
= size
.x
;
2561 // refresh till the bottom of the window
2562 rect
.height
= size
.y
- rect
.y
;
2564 RefreshRect( rect
);
2568 // TODO: how to do it more efficiently?
2573 void wxListMainWindow::RefreshSelected()
2579 if ( InReportView() )
2581 GetVisibleLinesRange(&from
, &to
);
2586 to
= GetItemCount() - 1;
2589 if ( HasCurrent() && m_current
>= from
&& m_current
<= to
)
2591 RefreshLine(m_current
);
2594 for ( size_t line
= from
; line
<= to
; line
++ )
2596 // NB: the test works as expected even if m_current == -1
2597 if ( line
!= m_current
&& IsHighlighted(line
) )
2604 void wxListMainWindow::Freeze()
2609 void wxListMainWindow::Thaw()
2611 wxCHECK_RET( m_freezeCount
> 0, _T("thawing unfrozen list control?") );
2613 if ( !--m_freezeCount
)
2619 void wxListMainWindow::OnPaint( wxPaintEvent
&WXUNUSED(event
) )
2621 // Note: a wxPaintDC must be constructed even if no drawing is
2622 // done (a Windows requirement).
2623 wxPaintDC
dc( this );
2625 if ( IsEmpty() || m_freezeCount
)
2627 // nothing to draw or not the moment to draw it
2633 // delay the repainting until we calculate all the items positions
2640 CalcScrolledPosition( 0, 0, &dev_x
, &dev_y
);
2644 dc
.SetFont( GetFont() );
2646 if ( InReportView() )
2648 int lineHeight
= GetLineHeight();
2650 size_t visibleFrom
, visibleTo
;
2651 GetVisibleLinesRange(&visibleFrom
, &visibleTo
);
2654 wxCoord xOrig
, yOrig
;
2655 CalcUnscrolledPosition(0, 0, &xOrig
, &yOrig
);
2657 // tell the caller cache to cache the data
2660 wxListEvent
evCache(wxEVT_COMMAND_LIST_CACHE_HINT
,
2661 GetParent()->GetId());
2662 evCache
.SetEventObject( GetParent() );
2663 evCache
.m_oldItemIndex
= visibleFrom
;
2664 evCache
.m_itemIndex
= visibleTo
;
2665 GetParent()->GetEventHandler()->ProcessEvent( evCache
);
2668 for ( size_t line
= visibleFrom
; line
<= visibleTo
; line
++ )
2670 rectLine
= GetLineRect(line
);
2672 if ( !IsExposed(rectLine
.x
- xOrig
, rectLine
.y
- yOrig
,
2673 rectLine
.width
, rectLine
.height
) )
2675 // don't redraw unaffected lines to avoid flicker
2679 GetLine(line
)->DrawInReportMode( &dc
,
2681 GetLineHighlightRect(line
),
2682 IsHighlighted(line
) );
2685 if ( HasFlag(wxLC_HRULES
) )
2687 wxPen
pen(GetRuleColour(), 1, wxSOLID
);
2688 wxSize clientSize
= GetClientSize();
2690 // Don't draw the first one
2691 for ( size_t i
= visibleFrom
+1; i
<= visibleTo
; i
++ )
2694 dc
.SetBrush( *wxTRANSPARENT_BRUSH
);
2695 dc
.DrawLine(0 - dev_x
, i
*lineHeight
,
2696 clientSize
.x
- dev_x
, i
*lineHeight
);
2699 // Draw last horizontal rule
2700 if ( visibleTo
== GetItemCount() - 1 )
2703 dc
.SetBrush( *wxTRANSPARENT_BRUSH
);
2704 dc
.DrawLine(0 - dev_x
, (m_lineTo
+1)*lineHeight
,
2705 clientSize
.x
- dev_x
, (m_lineTo
+1)*lineHeight
);
2709 // Draw vertical rules if required
2710 if ( HasFlag(wxLC_VRULES
) && !IsEmpty() )
2712 wxPen
pen(GetRuleColour(), 1, wxSOLID
);
2714 wxRect firstItemRect
;
2715 wxRect lastItemRect
;
2716 GetItemRect(visibleFrom
, firstItemRect
);
2717 GetItemRect(visibleTo
, lastItemRect
);
2718 int x
= firstItemRect
.GetX();
2720 dc
.SetBrush(* wxTRANSPARENT_BRUSH
);
2721 for (int col
= 0; col
< GetColumnCount(); col
++)
2723 int colWidth
= GetColumnWidth(col
);
2725 dc
.DrawLine(x
- dev_x
- 2, firstItemRect
.GetY() - 1 - dev_y
,
2726 x
- dev_x
- 2, lastItemRect
.GetBottom() + 1 - dev_y
);
2732 size_t count
= GetItemCount();
2733 for ( size_t i
= 0; i
< count
; i
++ )
2735 GetLine(i
)->Draw( &dc
);
2740 // Don't draw rect outline under Mac at all.
2745 dc
.SetPen( *wxBLACK_PEN
);
2746 dc
.SetBrush( *wxTRANSPARENT_BRUSH
);
2747 dc
.DrawRectangle( GetLineHighlightRect(m_current
) );
2755 void wxListMainWindow::HighlightAll( bool on
)
2757 if ( IsSingleSel() )
2759 wxASSERT_MSG( !on
, _T("can't do this in a single sel control") );
2761 // we just have one item to turn off
2762 if ( HasCurrent() && IsHighlighted(m_current
) )
2764 HighlightLine(m_current
, false);
2765 RefreshLine(m_current
);
2770 HighlightLines(0, GetItemCount() - 1, on
);
2774 void wxListMainWindow::SendNotify( size_t line
,
2775 wxEventType command
,
2778 wxListEvent
le( command
, GetParent()->GetId() );
2779 le
.SetEventObject( GetParent() );
2780 le
.m_itemIndex
= line
;
2782 // set only for events which have position
2783 if ( point
!= wxDefaultPosition
)
2784 le
.m_pointDrag
= point
;
2786 // don't try to get the line info for virtual list controls: the main
2787 // program has it anyhow and if we did it would result in accessing all
2788 // the lines, even those which are not visible now and this is precisely
2789 // what we're trying to avoid
2790 if ( !IsVirtual() && (command
!= wxEVT_COMMAND_LIST_DELETE_ITEM
) )
2792 if ( line
!= (size_t)-1 )
2794 GetLine(line
)->GetItem( 0, le
.m_item
);
2796 //else: this happens for wxEVT_COMMAND_LIST_ITEM_FOCUSED event
2798 //else: there may be no more such item
2800 GetParent()->GetEventHandler()->ProcessEvent( le
);
2803 void wxListMainWindow::ChangeCurrent(size_t current
)
2805 m_current
= current
;
2807 SendNotify(current
, wxEVT_COMMAND_LIST_ITEM_FOCUSED
);
2810 void wxListMainWindow::EditLabel( long item
)
2812 wxCHECK_RET( (item
>= 0) && ((size_t)item
< GetItemCount()),
2813 wxT("wrong index in wxGenericListCtrl::EditLabel()") );
2815 size_t itemEdit
= (size_t)item
;
2817 wxListEvent
le( wxEVT_COMMAND_LIST_BEGIN_LABEL_EDIT
, GetParent()->GetId() );
2818 le
.SetEventObject( GetParent() );
2819 le
.m_itemIndex
= item
;
2820 wxListLineData
*data
= GetLine(itemEdit
);
2821 wxCHECK_RET( data
, _T("invalid index in EditLabel()") );
2822 data
->GetItem( 0, le
.m_item
);
2823 if ( GetParent()->GetEventHandler()->ProcessEvent( le
) && !le
.IsAllowed() )
2825 // vetoed by user code
2829 // We have to call this here because the label in question might just have
2830 // been added and no screen update taken place.
2834 wxListTextCtrl
*text
= new wxListTextCtrl(this, itemEdit
);
2839 void wxListMainWindow::OnRenameTimer()
2841 wxCHECK_RET( HasCurrent(), wxT("unexpected rename timer") );
2843 EditLabel( m_current
);
2846 bool wxListMainWindow::OnRenameAccept(size_t itemEdit
, const wxString
& value
)
2848 wxListEvent
le( wxEVT_COMMAND_LIST_END_LABEL_EDIT
, GetParent()->GetId() );
2849 le
.SetEventObject( GetParent() );
2850 le
.m_itemIndex
= itemEdit
;
2852 wxListLineData
*data
= GetLine(itemEdit
);
2853 wxCHECK_MSG( data
, false, _T("invalid index in OnRenameAccept()") );
2855 data
->GetItem( 0, le
.m_item
);
2856 le
.m_item
.m_text
= value
;
2857 return !GetParent()->GetEventHandler()->ProcessEvent( le
) ||
2861 void wxListMainWindow::OnRenameCancelled(size_t itemEdit
)
2863 // let owner know that the edit was cancelled
2864 wxListEvent
le( wxEVT_COMMAND_LIST_END_LABEL_EDIT
, GetParent()->GetId() );
2866 le
.SetEditCanceled(true);
2868 le
.SetEventObject( GetParent() );
2869 le
.m_itemIndex
= itemEdit
;
2871 wxListLineData
*data
= GetLine(itemEdit
);
2872 wxCHECK_RET( data
, _T("invalid index in OnRenameCancelled()") );
2874 data
->GetItem( 0, le
.m_item
);
2876 GetEventHandler()->ProcessEvent( le
);
2879 void wxListMainWindow::OnMouse( wxMouseEvent
&event
)
2881 event
.SetEventObject( GetParent() );
2882 if ( GetParent()->GetEventHandler()->ProcessEvent( event
) )
2885 if (event
.GetEventType() == wxEVT_MOUSEWHEEL
)
2887 // let the base handle mouse wheel events.
2892 if ( !HasCurrent() || IsEmpty() )
2898 if ( !(event
.Dragging() || event
.ButtonDown() || event
.LeftUp() ||
2899 event
.ButtonDClick()) )
2902 int x
= event
.GetX();
2903 int y
= event
.GetY();
2904 CalcUnscrolledPosition( x
, y
, &x
, &y
);
2906 // where did we hit it (if we did)?
2909 size_t count
= GetItemCount(),
2912 if ( InReportView() )
2914 current
= y
/ GetLineHeight();
2915 if ( current
< count
)
2916 hitResult
= HitTestLine(current
, x
, y
);
2920 // TODO: optimize it too! this is less simple than for report view but
2921 // enumerating all items is still not a way to do it!!
2922 for ( current
= 0; current
< count
; current
++ )
2924 hitResult
= HitTestLine(current
, x
, y
);
2930 if (event
.Dragging())
2932 if (m_dragCount
== 0)
2934 // we have to report the raw, physical coords as we want to be
2935 // able to call HitTest(event.m_pointDrag) from the user code to
2936 // get the item being dragged
2937 m_dragStart
= event
.GetPosition();
2942 if (m_dragCount
!= 3)
2945 int command
= event
.RightIsDown() ? wxEVT_COMMAND_LIST_BEGIN_RDRAG
2946 : wxEVT_COMMAND_LIST_BEGIN_DRAG
;
2948 wxListEvent
le( command
, GetParent()->GetId() );
2949 le
.SetEventObject( GetParent() );
2950 le
.m_itemIndex
= m_lineLastClicked
;
2951 le
.m_pointDrag
= m_dragStart
;
2952 GetParent()->GetEventHandler()->ProcessEvent( le
);
2963 // outside of any item
2967 bool forceClick
= false;
2968 if (event
.ButtonDClick())
2970 m_renameTimer
->Stop();
2971 m_lastOnSame
= false;
2973 if ( current
== m_lineLastClicked
)
2975 SendNotify( current
, wxEVT_COMMAND_LIST_ITEM_ACTIVATED
);
2981 // The first click was on another item, so don't interpret this as
2982 // a double click, but as a simple click instead
2989 if(m_lineSelectSingleOnUp
!= (size_t) -1)
2991 // select single line
2992 HighlightAll( false );
2993 ReverseHighlight(m_lineSelectSingleOnUp
);
2995 else if (m_lastOnSame
)
2997 if ((current
== m_current
) &&
2998 (hitResult
== wxLIST_HITTEST_ONITEMLABEL
) &&
2999 HasFlag(wxLC_EDIT_LABELS
) )
3001 m_renameTimer
->Start( 100, true );
3004 m_lastOnSame
= false;
3005 m_lineSelectSingleOnUp
= (size_t) -1;
3009 // This is neccessary , because after a DnD operation in
3010 // from and to ourself, the up event is swallowed by the
3011 // DnD code. So on next non-up event (which means here and
3012 // now) m_lineSelectSingleOnUp should be reset.
3013 m_lineSelectSingleOnUp
= (size_t) -1;
3015 if (event
.RightDown())
3017 m_lineBeforeLastClicked
= m_lineLastClicked
;
3018 m_lineLastClicked
= current
;
3019 // If the item is already selected, do not update the selection.
3020 // Multi-selections should not be cleared if a selected item is clicked.
3021 if (!IsHighlighted(current
))
3023 HighlightAll(false);
3024 ChangeCurrent(current
);
3025 ReverseHighlight(m_current
);
3027 SendNotify( current
, wxEVT_COMMAND_LIST_ITEM_RIGHT_CLICK
,
3028 event
.GetPosition() );
3029 // Allow generation of context menu event
3032 else if (event
.MiddleDown())
3034 SendNotify( current
, wxEVT_COMMAND_LIST_ITEM_MIDDLE_CLICK
);
3036 else if ( event
.LeftDown() || forceClick
)
3038 m_lineBeforeLastClicked
= m_lineLastClicked
;
3039 m_lineLastClicked
= current
;
3041 size_t oldCurrent
= m_current
;
3042 bool cmdModifierDown
= event
.CmdDown();
3043 if ( IsSingleSel() || !(cmdModifierDown
|| event
.ShiftDown()) )
3045 if( IsSingleSel() || !IsHighlighted(current
) )
3047 HighlightAll( false );
3049 ChangeCurrent(current
);
3051 ReverseHighlight(m_current
);
3053 else // multi sel & current is highlighted & no mod keys
3055 m_lineSelectSingleOnUp
= current
;
3056 ChangeCurrent(current
); // change focus
3059 else // multi sel & either ctrl or shift is down
3061 if (cmdModifierDown
)
3063 ChangeCurrent(current
);
3065 ReverseHighlight(m_current
);
3067 else if (event
.ShiftDown())
3069 ChangeCurrent(current
);
3071 size_t lineFrom
= oldCurrent
,
3074 if ( lineTo
< lineFrom
)
3077 lineFrom
= m_current
;
3080 HighlightLines(lineFrom
, lineTo
);
3082 else // !ctrl, !shift
3084 // test in the enclosing if should make it impossible
3085 wxFAIL_MSG( _T("how did we get here?") );
3089 if (m_current
!= oldCurrent
)
3091 RefreshLine( oldCurrent
);
3094 // forceClick is only set if the previous click was on another item
3095 m_lastOnSame
= !forceClick
&& (m_current
== oldCurrent
);
3099 void wxListMainWindow::MoveToItem(size_t item
)
3101 if ( item
== (size_t)-1 )
3104 wxRect rect
= GetLineRect(item
);
3106 int client_w
, client_h
;
3107 GetClientSize( &client_w
, &client_h
);
3109 const int hLine
= GetLineHeight();
3111 int view_x
= SCROLL_UNIT_X
*GetScrollPos( wxHORIZONTAL
);
3112 int view_y
= hLine
*GetScrollPos( wxVERTICAL
);
3114 if ( InReportView() )
3116 // the next we need the range of lines shown it might be different, so
3118 ResetVisibleLinesRange();
3120 if (rect
.y
< view_y
)
3121 Scroll( -1, rect
.y
/hLine
);
3122 if (rect
.y
+rect
.height
+5 > view_y
+client_h
)
3123 Scroll( -1, (rect
.y
+rect
.height
-client_h
+hLine
)/hLine
);
3127 if (rect
.x
-view_x
< 5)
3128 Scroll( (rect
.x
-5)/SCROLL_UNIT_X
, -1 );
3129 if (rect
.x
+rect
.width
-5 > view_x
+client_w
)
3130 Scroll( (rect
.x
+rect
.width
-client_w
+SCROLL_UNIT_X
)/SCROLL_UNIT_X
, -1 );
3134 // ----------------------------------------------------------------------------
3135 // keyboard handling
3136 // ----------------------------------------------------------------------------
3138 void wxListMainWindow::OnArrowChar(size_t newCurrent
, const wxKeyEvent
& event
)
3140 wxCHECK_RET( newCurrent
< (size_t)GetItemCount(),
3141 _T("invalid item index in OnArrowChar()") );
3143 size_t oldCurrent
= m_current
;
3145 // in single selection we just ignore Shift as we can't select several
3147 if ( event
.ShiftDown() && !IsSingleSel() )
3149 ChangeCurrent(newCurrent
);
3151 // refresh the old focus to remove it
3152 RefreshLine( oldCurrent
);
3154 // select all the items between the old and the new one
3155 if ( oldCurrent
> newCurrent
)
3157 newCurrent
= oldCurrent
;
3158 oldCurrent
= m_current
;
3161 HighlightLines(oldCurrent
, newCurrent
);
3165 // all previously selected items are unselected unless ctrl is held
3166 if ( !event
.ControlDown() )
3167 HighlightAll(false);
3169 ChangeCurrent(newCurrent
);
3171 // refresh the old focus to remove it
3172 RefreshLine( oldCurrent
);
3174 if ( !event
.ControlDown() )
3176 HighlightLine( m_current
, true );
3180 RefreshLine( m_current
);
3185 void wxListMainWindow::OnKeyDown( wxKeyEvent
&event
)
3187 wxWindow
*parent
= GetParent();
3189 /* we propagate the key event up */
3190 wxKeyEvent
ke( wxEVT_KEY_DOWN
);
3191 ke
.m_shiftDown
= event
.m_shiftDown
;
3192 ke
.m_controlDown
= event
.m_controlDown
;
3193 ke
.m_altDown
= event
.m_altDown
;
3194 ke
.m_metaDown
= event
.m_metaDown
;
3195 ke
.m_keyCode
= event
.m_keyCode
;
3198 ke
.SetEventObject( parent
);
3199 if (parent
->GetEventHandler()->ProcessEvent( ke
)) return;
3204 void wxListMainWindow::OnChar( wxKeyEvent
&event
)
3206 wxWindow
*parent
= GetParent();
3208 /* we send a list_key event up */
3211 wxListEvent
le( wxEVT_COMMAND_LIST_KEY_DOWN
, GetParent()->GetId() );
3212 le
.m_itemIndex
= m_current
;
3213 GetLine(m_current
)->GetItem( 0, le
.m_item
);
3214 le
.m_code
= event
.GetKeyCode();
3215 le
.SetEventObject( parent
);
3216 parent
->GetEventHandler()->ProcessEvent( le
);
3219 /* we propagate the char event up */
3220 wxKeyEvent
ke( wxEVT_CHAR
);
3221 ke
.m_shiftDown
= event
.m_shiftDown
;
3222 ke
.m_controlDown
= event
.m_controlDown
;
3223 ke
.m_altDown
= event
.m_altDown
;
3224 ke
.m_metaDown
= event
.m_metaDown
;
3225 ke
.m_keyCode
= event
.m_keyCode
;
3228 ke
.SetEventObject( parent
);
3229 if (parent
->GetEventHandler()->ProcessEvent( ke
)) return;
3231 if (event
.GetKeyCode() == WXK_TAB
)
3233 wxNavigationKeyEvent nevent
;
3234 nevent
.SetWindowChange( event
.ControlDown() );
3235 nevent
.SetDirection( !event
.ShiftDown() );
3236 nevent
.SetEventObject( GetParent()->GetParent() );
3237 nevent
.SetCurrentFocus( m_parent
);
3238 if (GetParent()->GetParent()->GetEventHandler()->ProcessEvent( nevent
))
3242 /* no item -> nothing to do */
3249 switch (event
.GetKeyCode())
3252 if ( m_current
> 0 )
3253 OnArrowChar( m_current
- 1, event
);
3257 if ( m_current
< (size_t)GetItemCount() - 1 )
3258 OnArrowChar( m_current
+ 1, event
);
3263 OnArrowChar( GetItemCount() - 1, event
);
3268 OnArrowChar( 0, event
);
3273 int steps
= InReportView() ? m_linesPerPage
- 1 : m_current
% m_linesPerPage
;
3275 int index
= m_current
- steps
;
3279 OnArrowChar( index
, event
);
3285 int steps
= InReportView()
3286 ? m_linesPerPage
- 1
3287 : m_linesPerPage
- (m_current
% m_linesPerPage
) - 1;
3289 size_t index
= m_current
+ steps
;
3290 size_t count
= GetItemCount();
3291 if ( index
>= count
)
3294 OnArrowChar( index
, event
);
3299 if ( !InReportView() )
3301 int index
= m_current
- m_linesPerPage
;
3305 OnArrowChar( index
, event
);
3310 if ( !InReportView() )
3312 size_t index
= m_current
+ m_linesPerPage
;
3314 size_t count
= GetItemCount();
3315 if ( index
>= count
)
3318 OnArrowChar( index
, event
);
3323 if ( IsSingleSel() )
3325 SendNotify( m_current
, wxEVT_COMMAND_LIST_ITEM_ACTIVATED
);
3327 if ( IsHighlighted(m_current
) )
3329 // don't unselect the item in single selection mode
3332 //else: select it in ReverseHighlight() below if unselected
3335 ReverseHighlight(m_current
);
3340 SendNotify( m_current
, wxEVT_COMMAND_LIST_ITEM_ACTIVATED
);
3348 // ----------------------------------------------------------------------------
3350 // ----------------------------------------------------------------------------
3352 void wxListMainWindow::OnSetFocus( wxFocusEvent
&WXUNUSED(event
) )
3356 wxFocusEvent
event( wxEVT_SET_FOCUS
, GetParent()->GetId() );
3357 event
.SetEventObject( GetParent() );
3358 if ( GetParent()->GetEventHandler()->ProcessEvent( event
) )
3362 // wxGTK sends us EVT_SET_FOCUS events even if we had never got
3363 // EVT_KILL_FOCUS before which means that we finish by redrawing the items
3364 // which are already drawn correctly resulting in horrible flicker - avoid
3374 void wxListMainWindow::OnKillFocus( wxFocusEvent
&WXUNUSED(event
) )
3378 wxFocusEvent
event( wxEVT_KILL_FOCUS
, GetParent()->GetId() );
3379 event
.SetEventObject( GetParent() );
3380 if ( GetParent()->GetEventHandler()->ProcessEvent( event
) )
3387 void wxListMainWindow::DrawImage( int index
, wxDC
*dc
, int x
, int y
)
3389 if ( HasFlag(wxLC_ICON
) && (m_normal_image_list
))
3391 m_normal_image_list
->Draw( index
, *dc
, x
, y
, wxIMAGELIST_DRAW_TRANSPARENT
);
3393 else if ( HasFlag(wxLC_SMALL_ICON
) && (m_small_image_list
))
3395 m_small_image_list
->Draw( index
, *dc
, x
, y
, wxIMAGELIST_DRAW_TRANSPARENT
);
3397 else if ( HasFlag(wxLC_LIST
) && (m_small_image_list
))
3399 m_small_image_list
->Draw( index
, *dc
, x
, y
, wxIMAGELIST_DRAW_TRANSPARENT
);
3401 else if ( InReportView() && (m_small_image_list
))
3403 m_small_image_list
->Draw( index
, *dc
, x
, y
, wxIMAGELIST_DRAW_TRANSPARENT
);
3407 void wxListMainWindow::GetImageSize( int index
, int &width
, int &height
) const
3409 if ( HasFlag(wxLC_ICON
) && m_normal_image_list
)
3411 m_normal_image_list
->GetSize( index
, width
, height
);
3413 else if ( HasFlag(wxLC_SMALL_ICON
) && m_small_image_list
)
3415 m_small_image_list
->GetSize( index
, width
, height
);
3417 else if ( HasFlag(wxLC_LIST
) && m_small_image_list
)
3419 m_small_image_list
->GetSize( index
, width
, height
);
3421 else if ( InReportView() && m_small_image_list
)
3423 m_small_image_list
->GetSize( index
, width
, height
);
3432 int wxListMainWindow::GetTextLength( const wxString
&s
) const
3434 wxClientDC
dc( wxConstCast(this, wxListMainWindow
) );
3435 dc
.SetFont( GetFont() );
3438 dc
.GetTextExtent( s
, &lw
, NULL
);
3440 return lw
+ AUTOSIZE_COL_MARGIN
;
3443 void wxListMainWindow::SetImageList( wxImageListType
*imageList
, int which
)
3447 // calc the spacing from the icon size
3450 if ((imageList
) && (imageList
->GetImageCount()) )
3452 imageList
->GetSize(0, width
, height
);
3455 if (which
== wxIMAGE_LIST_NORMAL
)
3457 m_normal_image_list
= imageList
;
3458 m_normal_spacing
= width
+ 8;
3461 if (which
== wxIMAGE_LIST_SMALL
)
3463 m_small_image_list
= imageList
;
3464 m_small_spacing
= width
+ 14;
3465 m_lineHeight
= 0; // ensure that the line height will be recalc'd
3469 void wxListMainWindow::SetItemSpacing( int spacing
, bool isSmall
)
3474 m_small_spacing
= spacing
;
3478 m_normal_spacing
= spacing
;
3482 int wxListMainWindow::GetItemSpacing( bool isSmall
)
3484 return isSmall
? m_small_spacing
: m_normal_spacing
;
3487 // ----------------------------------------------------------------------------
3489 // ----------------------------------------------------------------------------
3491 void wxListMainWindow::SetColumn( int col
, wxListItem
&item
)
3493 wxListHeaderDataList::compatibility_iterator node
= m_columns
.Item( col
);
3495 wxCHECK_RET( node
, _T("invalid column index in SetColumn") );
3497 if ( item
.m_width
== wxLIST_AUTOSIZE_USEHEADER
)
3498 item
.m_width
= GetTextLength( item
.m_text
);
3500 wxListHeaderData
*column
= node
->GetData();
3501 column
->SetItem( item
);
3503 wxListHeaderWindow
*headerWin
= GetListCtrl()->m_headerWin
;
3505 headerWin
->m_dirty
= true;
3509 // invalidate it as it has to be recalculated
3513 void wxListMainWindow::SetColumnWidth( int col
, int width
)
3515 wxCHECK_RET( col
>= 0 && col
< GetColumnCount(),
3516 _T("invalid column index") );
3518 wxCHECK_RET( InReportView(),
3519 _T("SetColumnWidth() can only be called in report mode.") );
3522 wxListHeaderWindow
*headerWin
= GetListCtrl()->m_headerWin
;
3524 headerWin
->m_dirty
= true;
3526 wxListHeaderDataList::compatibility_iterator node
= m_columns
.Item( col
);
3527 wxCHECK_RET( node
, _T("no column?") );
3529 wxListHeaderData
*column
= node
->GetData();
3531 size_t count
= GetItemCount();
3533 if (width
== wxLIST_AUTOSIZE_USEHEADER
)
3535 width
= GetTextLength(column
->GetText());
3537 else if ( width
== wxLIST_AUTOSIZE
)
3541 // TODO: determine the max width somehow...
3542 width
= WIDTH_COL_DEFAULT
;
3546 wxClientDC
dc(this);
3547 dc
.SetFont( GetFont() );
3549 int max
= AUTOSIZE_COL_MARGIN
;
3551 for ( size_t i
= 0; i
< count
; i
++ )
3553 wxListLineData
*line
= GetLine(i
);
3554 wxListItemDataList::compatibility_iterator n
= line
->m_items
.Item( col
);
3556 wxCHECK_RET( n
, _T("no subitem?") );
3558 wxListItemData
*item
= n
->GetData();
3561 if (item
->HasImage())
3564 GetImageSize( item
->GetImage(), ix
, iy
);
3568 if (item
->HasText())
3571 dc
.GetTextExtent( item
->GetText(), &w
, NULL
);
3579 width
= max
+ AUTOSIZE_COL_MARGIN
;
3583 column
->SetWidth( width
);
3585 // invalidate it as it has to be recalculated
3589 int wxListMainWindow::GetHeaderWidth() const
3591 if ( !m_headerWidth
)
3593 wxListMainWindow
*self
= wxConstCast(this, wxListMainWindow
);
3595 size_t count
= GetColumnCount();
3596 for ( size_t col
= 0; col
< count
; col
++ )
3598 self
->m_headerWidth
+= GetColumnWidth(col
);
3602 return m_headerWidth
;
3605 void wxListMainWindow::GetColumn( int col
, wxListItem
&item
) const
3607 wxListHeaderDataList::compatibility_iterator node
= m_columns
.Item( col
);
3608 wxCHECK_RET( node
, _T("invalid column index in GetColumn") );
3610 wxListHeaderData
*column
= node
->GetData();
3611 column
->GetItem( item
);
3614 int wxListMainWindow::GetColumnWidth( int col
) const
3616 wxListHeaderDataList::compatibility_iterator node
= m_columns
.Item( col
);
3617 wxCHECK_MSG( node
, 0, _T("invalid column index") );
3619 wxListHeaderData
*column
= node
->GetData();
3620 return column
->GetWidth();
3623 // ----------------------------------------------------------------------------
3625 // ----------------------------------------------------------------------------
3627 void wxListMainWindow::SetItem( wxListItem
&item
)
3629 long id
= item
.m_itemId
;
3630 wxCHECK_RET( id
>= 0 && (size_t)id
< GetItemCount(),
3631 _T("invalid item index in SetItem") );
3635 wxListLineData
*line
= GetLine((size_t)id
);
3636 line
->SetItem( item
.m_col
, item
);
3639 // update the item on screen
3641 GetItemRect(id
, rectItem
);
3642 RefreshRect(rectItem
);
3645 void wxListMainWindow::SetItemStateAll(long state
, long stateMask
)
3650 // first deal with selection
3651 if ( stateMask
& wxLIST_STATE_SELECTED
)
3653 // set/clear select state
3656 // optimized version for virtual listctrl.
3657 m_selStore
.SelectRange(0, GetItemCount() - 1, state
== wxLIST_STATE_SELECTED
);
3660 else if ( state
& wxLIST_STATE_SELECTED
)
3662 const long count
= GetItemCount();
3663 for( long i
= 0; i
< count
; i
++ )
3665 SetItemState( i
, wxLIST_STATE_SELECTED
, wxLIST_STATE_SELECTED
);
3671 // clear for non virtual (somewhat optimized by using GetNextItem())
3673 while ( (i
= GetNextItem(i
, wxLIST_NEXT_ALL
, wxLIST_STATE_SELECTED
)) != -1 )
3675 SetItemState( i
, 0, wxLIST_STATE_SELECTED
);
3680 if ( HasCurrent() && (state
== 0) && (stateMask
& wxLIST_STATE_FOCUSED
) )
3682 // unfocus all: only one item can be focussed, so clearing focus for
3683 // all items is simply clearing focus of the focussed item.
3684 SetItemState(m_current
, state
, stateMask
);
3686 //(setting focus to all items makes no sense, so it is not handled here.)
3689 void wxListMainWindow::SetItemState( long litem
, long state
, long stateMask
)
3693 SetItemStateAll(state
, stateMask
);
3697 wxCHECK_RET( litem
>= 0 && (size_t)litem
< GetItemCount(),
3698 _T("invalid list ctrl item index in SetItem") );
3700 size_t oldCurrent
= m_current
;
3701 size_t item
= (size_t)litem
; // safe because of the check above
3703 // do we need to change the focus?
3704 if ( stateMask
& wxLIST_STATE_FOCUSED
)
3706 if ( state
& wxLIST_STATE_FOCUSED
)
3708 // don't do anything if this item is already focused
3709 if ( item
!= m_current
)
3711 ChangeCurrent(item
);
3713 if ( oldCurrent
!= (size_t)-1 )
3715 if ( IsSingleSel() )
3717 HighlightLine(oldCurrent
, false);
3720 RefreshLine(oldCurrent
);
3723 RefreshLine( m_current
);
3728 // don't do anything if this item is not focused
3729 if ( item
== m_current
)
3733 if ( IsSingleSel() )
3735 // we must unselect the old current item as well or we
3736 // might end up with more than one selected item in a
3737 // single selection control
3738 HighlightLine(oldCurrent
, false);
3741 RefreshLine( oldCurrent
);
3746 // do we need to change the selection state?
3747 if ( stateMask
& wxLIST_STATE_SELECTED
)
3749 bool on
= (state
& wxLIST_STATE_SELECTED
) != 0;
3751 if ( IsSingleSel() )
3755 // selecting the item also makes it the focused one in the
3757 if ( m_current
!= item
)
3759 ChangeCurrent(item
);
3761 if ( oldCurrent
!= (size_t)-1 )
3763 HighlightLine( oldCurrent
, false );
3764 RefreshLine( oldCurrent
);
3770 // only the current item may be selected anyhow
3771 if ( item
!= m_current
)
3776 if ( HighlightLine(item
, on
) )
3783 int wxListMainWindow::GetItemState( long item
, long stateMask
) const
3785 wxCHECK_MSG( item
>= 0 && (size_t)item
< GetItemCount(), 0,
3786 _T("invalid list ctrl item index in GetItemState()") );
3788 int ret
= wxLIST_STATE_DONTCARE
;
3790 if ( stateMask
& wxLIST_STATE_FOCUSED
)
3792 if ( (size_t)item
== m_current
)
3793 ret
|= wxLIST_STATE_FOCUSED
;
3796 if ( stateMask
& wxLIST_STATE_SELECTED
)
3798 if ( IsHighlighted(item
) )
3799 ret
|= wxLIST_STATE_SELECTED
;
3805 void wxListMainWindow::GetItem( wxListItem
&item
) const
3807 wxCHECK_RET( item
.m_itemId
>= 0 && (size_t)item
.m_itemId
< GetItemCount(),
3808 _T("invalid item index in GetItem") );
3810 wxListLineData
*line
= GetLine((size_t)item
.m_itemId
);
3811 line
->GetItem( item
.m_col
, item
);
3814 // ----------------------------------------------------------------------------
3816 // ----------------------------------------------------------------------------
3818 size_t wxListMainWindow::GetItemCount() const
3820 return IsVirtual() ? m_countVirt
: m_lines
.GetCount();
3823 void wxListMainWindow::SetItemCount(long count
)
3825 m_selStore
.SetItemCount(count
);
3826 m_countVirt
= count
;
3828 ResetVisibleLinesRange();
3830 // scrollbars must be reset
3834 int wxListMainWindow::GetSelectedItemCount() const
3836 // deal with the quick case first
3837 if ( IsSingleSel() )
3839 return HasCurrent() ? IsHighlighted(m_current
) : false;
3842 // virtual controls remmebers all its selections itself
3844 return m_selStore
.GetSelectedCount();
3846 // TODO: we probably should maintain the number of items selected even for
3847 // non virtual controls as enumerating all lines is really slow...
3848 size_t countSel
= 0;
3849 size_t count
= GetItemCount();
3850 for ( size_t line
= 0; line
< count
; line
++ )
3852 if ( GetLine(line
)->IsHighlighted() )
3859 // ----------------------------------------------------------------------------
3860 // item position/size
3861 // ----------------------------------------------------------------------------
3863 wxRect
wxListMainWindow::GetViewRect() const
3865 wxASSERT_MSG( !HasFlag(wxLC_REPORT
| wxLC_LIST
),
3866 _T("wxListCtrl::GetViewRect() only works in icon mode") );
3868 // we need to find the longest/tallest label
3871 const int count
= GetItemCount();
3874 for ( int i
= 0; i
< count
; i
++ )
3879 wxCoord x
= r
.GetRight(),
3889 // some fudge needed to make it look prettier
3890 xMax
+= 2*EXTRA_BORDER_X
;
3891 yMax
+= 2*EXTRA_BORDER_Y
;
3893 // account for the scrollbars if necessary
3894 const wxSize sizeAll
= GetClientSize();
3895 if ( xMax
> sizeAll
.x
)
3896 yMax
+= wxSystemSettings::GetMetric(wxSYS_HSCROLL_Y
);
3897 if ( yMax
> sizeAll
.y
)
3898 xMax
+= wxSystemSettings::GetMetric(wxSYS_VSCROLL_X
);
3900 return wxRect(0, 0, xMax
, yMax
);
3903 void wxListMainWindow::GetItemRect( long index
, wxRect
&rect
) const
3905 wxCHECK_RET( index
>= 0 && (size_t)index
< GetItemCount(),
3906 _T("invalid index in GetItemRect") );
3908 // ensure that we're laid out, otherwise we could return nonsense
3911 wxConstCast(this, wxListMainWindow
)->
3912 RecalculatePositions(true /* no refresh */);
3915 rect
= GetLineRect((size_t)index
);
3917 CalcScrolledPosition(rect
.x
, rect
.y
, &rect
.x
, &rect
.y
);
3920 bool wxListMainWindow::GetItemPosition(long item
, wxPoint
& pos
) const
3923 GetItemRect(item
, rect
);
3931 // ----------------------------------------------------------------------------
3932 // geometry calculation
3933 // ----------------------------------------------------------------------------
3935 void wxListMainWindow::RecalculatePositions(bool noRefresh
)
3937 wxClientDC
dc( this );
3938 dc
.SetFont( GetFont() );
3940 const size_t count
= GetItemCount();
3943 if ( HasFlag(wxLC_ICON
) )
3944 iconSpacing
= m_normal_spacing
;
3945 else if ( HasFlag(wxLC_SMALL_ICON
) )
3946 iconSpacing
= m_small_spacing
;
3950 // Note that we do not call GetClientSize() here but
3951 // GetSize() and subtract the border size for sunken
3952 // borders manually. This is technically incorrect,
3953 // but we need to know the client area's size WITHOUT
3954 // scrollbars here. Since we don't know if there are
3955 // any scrollbars, we use GetSize() instead. Another
3956 // solution would be to call SetScrollbars() here to
3957 // remove the scrollbars and call GetClientSize() then,
3958 // but this might result in flicker and - worse - will
3959 // reset the scrollbars to 0 which is not good at all
3960 // if you resize a dialog/window, but don't want to
3961 // reset the window scrolling. RR.
3962 // Furthermore, we actually do NOT subtract the border
3963 // width as 2 pixels is just the extra space which we
3964 // need around the actual content in the window. Other-
3965 // wise the text would e.g. touch the upper border. RR.
3968 GetSize( &clientWidth
, &clientHeight
);
3970 const int lineHeight
= GetLineHeight();
3972 if ( InReportView() )
3974 // all lines have the same height and we scroll one line per step
3975 int entireHeight
= count
*lineHeight
+ LINE_SPACING
;
3977 m_linesPerPage
= clientHeight
/ lineHeight
;
3979 ResetVisibleLinesRange();
3981 SetScrollbars( SCROLL_UNIT_X
, lineHeight
,
3982 GetHeaderWidth() / SCROLL_UNIT_X
,
3983 (entireHeight
+ lineHeight
- 1) / lineHeight
,
3984 GetScrollPos(wxHORIZONTAL
),
3985 GetScrollPos(wxVERTICAL
),
3990 // we have 3 different layout strategies: either layout all items
3991 // horizontally/vertically (wxLC_ALIGN_XXX styles explicitly given) or
3992 // to arrange them in top to bottom, left to right (don't ask me why
3993 // not the other way round...) order
3994 if ( HasFlag(wxLC_ALIGN_LEFT
| wxLC_ALIGN_TOP
) )
3996 int x
= EXTRA_BORDER_X
;
3997 int y
= EXTRA_BORDER_Y
;
3999 wxCoord widthMax
= 0;
4002 for ( i
= 0; i
< count
; i
++ )
4004 wxListLineData
*line
= GetLine(i
);
4005 line
->CalculateSize( &dc
, iconSpacing
);
4006 line
->SetPosition( x
, y
, iconSpacing
);
4008 wxSize sizeLine
= GetLineSize(i
);
4010 if ( HasFlag(wxLC_ALIGN_TOP
) )
4012 if ( sizeLine
.x
> widthMax
)
4013 widthMax
= sizeLine
.x
;
4017 else // wxLC_ALIGN_LEFT
4019 x
+= sizeLine
.x
+ MARGIN_BETWEEN_ROWS
;
4023 if ( HasFlag(wxLC_ALIGN_TOP
) )
4025 // traverse the items again and tweak their sizes so that they are
4026 // all the same in a row
4027 for ( i
= 0; i
< count
; i
++ )
4029 wxListLineData
*line
= GetLine(i
);
4030 line
->m_gi
->ExtendWidth(widthMax
);
4039 (x
+ SCROLL_UNIT_X
) / SCROLL_UNIT_X
,
4040 (y
+ lineHeight
) / lineHeight
,
4041 GetScrollPos( wxHORIZONTAL
),
4042 GetScrollPos( wxVERTICAL
),
4046 else // "flowed" arrangement, the most complicated case
4048 // at first we try without any scrollbars, if the items don't fit into
4049 // the window, we recalculate after subtracting the space taken by the
4052 int entireWidth
= 0;
4054 for (int tries
= 0; tries
< 2; tries
++)
4056 entireWidth
= 2*EXTRA_BORDER_X
;
4060 // Now we have decided that the items do not fit into the
4061 // client area, so we need a scrollbar
4062 entireWidth
+= SCROLL_UNIT_X
;
4065 int x
= EXTRA_BORDER_X
;
4066 int y
= EXTRA_BORDER_Y
;
4067 int maxWidthInThisRow
= 0;
4070 int currentlyVisibleLines
= 0;
4072 for (size_t i
= 0; i
< count
; i
++)
4074 currentlyVisibleLines
++;
4075 wxListLineData
*line
= GetLine(i
);
4076 line
->CalculateSize( &dc
, iconSpacing
);
4077 line
->SetPosition( x
, y
, iconSpacing
);
4079 wxSize sizeLine
= GetLineSize(i
);
4081 if ( maxWidthInThisRow
< sizeLine
.x
)
4082 maxWidthInThisRow
= sizeLine
.x
;
4085 if (currentlyVisibleLines
> m_linesPerPage
)
4086 m_linesPerPage
= currentlyVisibleLines
;
4088 if ( y
+ sizeLine
.y
>= clientHeight
)
4090 currentlyVisibleLines
= 0;
4092 maxWidthInThisRow
+= MARGIN_BETWEEN_ROWS
;
4093 x
+= maxWidthInThisRow
;
4094 entireWidth
+= maxWidthInThisRow
;
4095 maxWidthInThisRow
= 0;
4098 // We have reached the last item.
4099 if ( i
== count
- 1 )
4100 entireWidth
+= maxWidthInThisRow
;
4102 if ( (tries
== 0) &&
4103 (entireWidth
+ SCROLL_UNIT_X
> clientWidth
) )
4105 clientHeight
-= wxSystemSettings::
4106 GetMetric(wxSYS_HSCROLL_Y
);
4111 if ( i
== count
- 1 )
4112 tries
= 1; // Everything fits, no second try required.
4120 (entireWidth
+ SCROLL_UNIT_X
) / SCROLL_UNIT_X
,
4122 GetScrollPos( wxHORIZONTAL
),
4131 // FIXME: why should we call it from here?
4138 void wxListMainWindow::RefreshAll()
4143 wxListHeaderWindow
*headerWin
= GetListCtrl()->m_headerWin
;
4144 if ( headerWin
&& headerWin
->m_dirty
)
4146 headerWin
->m_dirty
= false;
4147 headerWin
->Refresh();
4151 void wxListMainWindow::UpdateCurrent()
4153 if ( !HasCurrent() && !IsEmpty() )
4159 long wxListMainWindow::GetNextItem( long item
,
4160 int WXUNUSED(geometry
),
4164 max
= GetItemCount();
4165 wxCHECK_MSG( (ret
== -1) || (ret
< max
), -1,
4166 _T("invalid listctrl index in GetNextItem()") );
4168 // notice that we start with the next item (or the first one if item == -1)
4169 // and this is intentional to allow writing a simple loop to iterate over
4170 // all selected items
4174 // this is not an error because the index was ok initially, just no
4185 size_t count
= GetItemCount();
4186 for ( size_t line
= (size_t)ret
; line
< count
; line
++ )
4188 if ( (state
& wxLIST_STATE_FOCUSED
) && (line
== m_current
) )
4191 if ( (state
& wxLIST_STATE_SELECTED
) && IsHighlighted(line
) )
4198 // ----------------------------------------------------------------------------
4200 // ----------------------------------------------------------------------------
4202 void wxListMainWindow::DeleteItem( long lindex
)
4204 size_t count
= GetItemCount();
4206 wxCHECK_RET( (lindex
>= 0) && ((size_t)lindex
< count
),
4207 _T("invalid item index in DeleteItem") );
4209 size_t index
= (size_t)lindex
;
4211 // we don't need to adjust the index for the previous items
4212 if ( HasCurrent() && m_current
>= index
)
4214 // if the current item is being deleted, we want the next one to
4215 // become selected - unless there is no next one - so don't adjust
4216 // m_current in this case
4217 if ( m_current
!= index
|| m_current
== count
- 1 )
4223 if ( InReportView() )
4225 ResetVisibleLinesRange();
4232 m_selStore
.OnItemDelete(index
);
4236 m_lines
.RemoveAt( index
);
4239 // we need to refresh the (vert) scrollbar as the number of items changed
4242 SendNotify( index
, wxEVT_COMMAND_LIST_DELETE_ITEM
);
4244 RefreshAfter(index
);
4247 void wxListMainWindow::DeleteColumn( int col
)
4249 wxListHeaderDataList::compatibility_iterator node
= m_columns
.Item( col
);
4251 wxCHECK_RET( node
, wxT("invalid column index in DeleteColumn()") );
4254 delete node
->GetData();
4255 m_columns
.Erase( node
);
4259 // update all the items
4260 for ( size_t i
= 0; i
< m_lines
.GetCount(); i
++ )
4262 wxListLineData
* const line
= GetLine(i
);
4263 wxListItemDataList::compatibility_iterator n
= line
->m_items
.Item( col
);
4264 delete n
->GetData();
4265 line
->m_items
.Erase(n
);
4269 // invalidate it as it has to be recalculated
4273 void wxListMainWindow::DoDeleteAllItems()
4277 // nothing to do - in particular, don't send the event
4283 // to make the deletion of all items faster, we don't send the
4284 // notifications for each item deletion in this case but only one event
4285 // for all of them: this is compatible with wxMSW and documented in
4286 // DeleteAllItems() description
4288 wxListEvent
event( wxEVT_COMMAND_LIST_DELETE_ALL_ITEMS
, GetParent()->GetId() );
4289 event
.SetEventObject( GetParent() );
4290 GetParent()->GetEventHandler()->ProcessEvent( event
);
4299 if ( InReportView() )
4301 ResetVisibleLinesRange();
4307 void wxListMainWindow::DeleteAllItems()
4311 RecalculatePositions();
4314 void wxListMainWindow::DeleteEverything()
4316 WX_CLEAR_LIST(wxListHeaderDataList
, m_columns
);
4321 // ----------------------------------------------------------------------------
4322 // scanning for an item
4323 // ----------------------------------------------------------------------------
4325 void wxListMainWindow::EnsureVisible( long index
)
4327 wxCHECK_RET( index
>= 0 && (size_t)index
< GetItemCount(),
4328 _T("invalid index in EnsureVisible") );
4330 // We have to call this here because the label in question might just have
4331 // been added and its position is not known yet
4334 RecalculatePositions(true /* no refresh */);
4337 MoveToItem((size_t)index
);
4340 long wxListMainWindow::FindItem(long start
, const wxString
& str
, bool WXUNUSED(partial
) )
4347 size_t count
= GetItemCount();
4348 for ( size_t i
= (size_t)pos
; i
< count
; i
++ )
4350 wxListLineData
*line
= GetLine(i
);
4351 if ( line
->GetText(0) == tmp
)
4358 long wxListMainWindow::FindItem(long start
, wxUIntPtr data
)
4364 size_t count
= GetItemCount();
4365 for (size_t i
= (size_t)pos
; i
< count
; i
++)
4367 wxListLineData
*line
= GetLine(i
);
4369 line
->GetItem( 0, item
);
4370 if (item
.m_data
== data
)
4377 long wxListMainWindow::FindItem( const wxPoint
& pt
)
4380 GetVisibleLinesRange(&topItem
, NULL
);
4383 GetItemPosition( GetItemCount()-1, p
);
4386 long id
= (long) floor( pt
.y
*double(GetItemCount()-topItem
-1)/p
.y
+topItem
);
4387 if( id
>= 0 && id
< (long)GetItemCount() )
4393 long wxListMainWindow::HitTest( int x
, int y
, int &flags
)
4395 CalcUnscrolledPosition( x
, y
, &x
, &y
);
4397 size_t count
= GetItemCount();
4399 if ( InReportView() )
4401 size_t current
= y
/ GetLineHeight();
4402 if ( current
< count
)
4404 flags
= HitTestLine(current
, x
, y
);
4411 // TODO: optimize it too! this is less simple than for report view but
4412 // enumerating all items is still not a way to do it!!
4413 for ( size_t current
= 0; current
< count
; current
++ )
4415 flags
= HitTestLine(current
, x
, y
);
4424 // ----------------------------------------------------------------------------
4426 // ----------------------------------------------------------------------------
4428 void wxListMainWindow::InsertItem( wxListItem
&item
)
4430 wxASSERT_MSG( !IsVirtual(), _T("can't be used with virtual control") );
4432 int count
= GetItemCount();
4433 wxCHECK_RET( item
.m_itemId
>= 0, _T("invalid item index") );
4435 if (item
.m_itemId
> count
)
4436 item
.m_itemId
= count
;
4438 size_t id
= item
.m_itemId
;
4443 // this is unused variable
4446 if ( InReportView() )
4449 // this is unused variable
4452 ResetVisibleLinesRange();
4454 else if ( HasFlag(wxLC_LIST
) )
4456 // this is unused variable
4461 else if ( HasFlag(wxLC_ICON
) )
4463 // this is unused variable
4468 else if ( HasFlag(wxLC_SMALL_ICON
) )
4470 // this is unused variable
4471 mode
= wxLC_ICON
; // no typo
4477 wxFAIL_MSG( _T("unknown mode") );
4480 wxListLineData
*line
= new wxListLineData(this);
4482 line
->SetItem( item
.m_col
, item
);
4484 m_lines
.Insert( line
, id
);
4488 // If an item is selected at or below the point of insertion, we need to
4489 // increment the member variables because the current row's index has gone
4491 if ( HasCurrent() && m_current
>= id
)
4496 SendNotify(id
, wxEVT_COMMAND_LIST_INSERT_ITEM
);
4498 RefreshLines(id
, GetItemCount() - 1);
4501 void wxListMainWindow::InsertColumn( long col
, wxListItem
&item
)
4504 if ( InReportView() )
4506 if (item
.m_width
== wxLIST_AUTOSIZE_USEHEADER
)
4507 item
.m_width
= GetTextLength( item
.m_text
);
4509 wxListHeaderData
*column
= new wxListHeaderData( item
);
4510 bool insert
= (col
>= 0) && ((size_t)col
< m_columns
.GetCount());
4513 wxListHeaderDataList::compatibility_iterator node
= m_columns
.Item( col
);
4514 m_columns
.Insert( node
, column
);
4518 m_columns
.Append( column
);
4523 // update all the items
4524 for ( size_t i
= 0; i
< m_lines
.GetCount(); i
++ )
4526 wxListLineData
* const line
= GetLine(i
);
4527 wxListItemData
* const data
= new wxListItemData(this);
4529 line
->m_items
.Insert(col
, data
);
4531 line
->m_items
.Append(data
);
4535 // invalidate it as it has to be recalculated
4540 // ----------------------------------------------------------------------------
4542 // ----------------------------------------------------------------------------
4544 wxListCtrlCompare list_ctrl_compare_func_2
;
4545 long list_ctrl_compare_data
;
4547 int LINKAGEMODE
list_ctrl_compare_func_1( wxListLineData
**arg1
, wxListLineData
**arg2
)
4549 wxListLineData
*line1
= *arg1
;
4550 wxListLineData
*line2
= *arg2
;
4552 line1
->GetItem( 0, item
);
4553 wxUIntPtr data1
= item
.m_data
;
4554 line2
->GetItem( 0, item
);
4555 wxUIntPtr data2
= item
.m_data
;
4556 return list_ctrl_compare_func_2( data1
, data2
, list_ctrl_compare_data
);
4559 void wxListMainWindow::SortItems( wxListCtrlCompare fn
, long data
)
4561 list_ctrl_compare_func_2
= fn
;
4562 list_ctrl_compare_data
= data
;
4563 m_lines
.Sort( list_ctrl_compare_func_1
);
4567 // ----------------------------------------------------------------------------
4569 // ----------------------------------------------------------------------------
4571 void wxListMainWindow::OnScroll(wxScrollWinEvent
& event
)
4573 // update our idea of which lines are shown when we redraw the window the
4575 ResetVisibleLinesRange();
4578 #if defined(__WXGTK__) && !defined(__WXUNIVERSAL__)
4579 wxScrolledWindow::OnScroll(event
);
4581 HandleOnScroll( event
);
4584 if ( event
.GetOrientation() == wxHORIZONTAL
&& HasHeader() )
4586 wxGenericListCtrl
* lc
= GetListCtrl();
4587 wxCHECK_RET( lc
, _T("no listctrl window?") );
4589 lc
->m_headerWin
->Refresh();
4590 lc
->m_headerWin
->Update();
4594 int wxListMainWindow::GetCountPerPage() const
4596 if ( !m_linesPerPage
)
4598 wxConstCast(this, wxListMainWindow
)->
4599 m_linesPerPage
= GetClientSize().y
/ GetLineHeight();
4602 return m_linesPerPage
;
4605 void wxListMainWindow::GetVisibleLinesRange(size_t *from
, size_t *to
)
4607 wxASSERT_MSG( InReportView(), _T("this is for report mode only") );
4609 if ( m_lineFrom
== (size_t)-1 )
4611 size_t count
= GetItemCount();
4614 m_lineFrom
= GetScrollPos(wxVERTICAL
);
4616 // this may happen if SetScrollbars() hadn't been called yet
4617 if ( m_lineFrom
>= count
)
4618 m_lineFrom
= count
- 1;
4620 // we redraw one extra line but this is needed to make the redrawing
4621 // logic work when there is a fractional number of lines on screen
4622 m_lineTo
= m_lineFrom
+ m_linesPerPage
;
4623 if ( m_lineTo
>= count
)
4624 m_lineTo
= count
- 1;
4626 else // empty control
4629 m_lineTo
= (size_t)-1;
4633 wxASSERT_MSG( IsEmpty() ||
4634 (m_lineFrom
<= m_lineTo
&& m_lineTo
< GetItemCount()),
4635 _T("GetVisibleLinesRange() returns incorrect result") );
4643 // -------------------------------------------------------------------------------------
4644 // wxGenericListCtrl
4645 // -------------------------------------------------------------------------------------
4647 IMPLEMENT_DYNAMIC_CLASS(wxGenericListCtrl
, wxControl
)
4649 BEGIN_EVENT_TABLE(wxGenericListCtrl
,wxControl
)
4650 EVT_SIZE(wxGenericListCtrl::OnSize
)
4653 wxGenericListCtrl::wxGenericListCtrl()
4655 m_imageListNormal
= (wxImageListType
*) NULL
;
4656 m_imageListSmall
= (wxImageListType
*) NULL
;
4657 m_imageListState
= (wxImageListType
*) NULL
;
4659 m_ownsImageListNormal
=
4660 m_ownsImageListSmall
=
4661 m_ownsImageListState
= false;
4663 m_mainWin
= (wxListMainWindow
*) NULL
;
4664 m_headerWin
= (wxListHeaderWindow
*) NULL
;
4668 wxGenericListCtrl::~wxGenericListCtrl()
4670 if (m_ownsImageListNormal
)
4671 delete m_imageListNormal
;
4672 if (m_ownsImageListSmall
)
4673 delete m_imageListSmall
;
4674 if (m_ownsImageListState
)
4675 delete m_imageListState
;
4678 void wxGenericListCtrl::CalculateAndSetHeaderHeight()
4684 GetThemeMetric( kThemeMetricListHeaderHeight
, &h
);
4686 // we use 'g' to get the descent, too
4688 m_headerWin
->GetTextExtent(wxT("Hg"), &w
, &h
, &d
);
4689 h
+= d
+ 2 * HEADER_OFFSET_Y
+ EXTRA_HEIGHT
;
4691 // only update if changed
4692 if ( h
!= m_headerHeight
)
4696 m_headerWin
->SetSize(m_headerWin
->GetSize().x
, m_headerHeight
);
4699 ResizeReportView(true);
4704 void wxGenericListCtrl::CreateHeaderWindow()
4706 m_headerWin
= new wxListHeaderWindow
4708 this, wxID_ANY
, m_mainWin
,
4710 wxSize(GetClientSize().x
, m_headerHeight
),
4713 CalculateAndSetHeaderHeight();
4716 bool wxGenericListCtrl::Create(wxWindow
*parent
,
4721 const wxValidator
&validator
,
4722 const wxString
&name
)
4726 m_imageListState
= (wxImageListType
*) NULL
;
4727 m_ownsImageListNormal
=
4728 m_ownsImageListSmall
=
4729 m_ownsImageListState
= false;
4731 m_mainWin
= (wxListMainWindow
*) NULL
;
4732 m_headerWin
= (wxListHeaderWindow
*) NULL
;
4736 if ( !(style
& wxLC_MASK_TYPE
) )
4738 style
= style
| wxLC_LIST
;
4741 if ( !wxControl::Create( parent
, id
, pos
, size
, style
, validator
, name
) )
4744 // don't create the inner window with the border
4745 style
&= ~wxBORDER_MASK
;
4747 m_mainWin
= new wxListMainWindow( this, wxID_ANY
, wxPoint(0,0), size
, style
);
4749 #ifdef __WXMAC_CARBON__
4750 // Human Interface Guidelines ask us for a special font in this case
4751 if ( GetWindowVariant() == wxWINDOW_VARIANT_NORMAL
)
4754 font
.MacCreateThemeFont( kThemeViewsFont
) ;
4758 if ( InReportView() )
4760 CreateHeaderWindow();
4761 #ifdef __WXMAC_CARBON__
4765 font
.MacCreateThemeFont( kThemeSmallSystemFont
) ;
4766 m_headerWin
->SetFont( font
);
4767 CalculateAndSetHeaderHeight();
4770 if ( HasFlag(wxLC_NO_HEADER
) )
4772 // VZ: why do we create it at all then?
4773 m_headerWin
->Show( false );
4782 void wxGenericListCtrl::SetSingleStyle( long style
, bool add
)
4784 wxASSERT_MSG( !(style
& wxLC_VIRTUAL
),
4785 _T("wxLC_VIRTUAL can't be [un]set") );
4787 long flag
= GetWindowStyle();
4791 if (style
& wxLC_MASK_TYPE
)
4792 flag
&= ~(wxLC_MASK_TYPE
| wxLC_VIRTUAL
);
4793 if (style
& wxLC_MASK_ALIGN
)
4794 flag
&= ~wxLC_MASK_ALIGN
;
4795 if (style
& wxLC_MASK_SORT
)
4796 flag
&= ~wxLC_MASK_SORT
;
4808 SetWindowStyleFlag( flag
);
4811 void wxGenericListCtrl::SetWindowStyleFlag( long flag
)
4815 m_mainWin
->DeleteEverything();
4817 // has the header visibility changed?
4818 bool hasHeader
= HasHeader();
4819 bool willHaveHeader
= (flag
& wxLC_REPORT
) && !(flag
& wxLC_NO_HEADER
);
4821 if ( hasHeader
!= willHaveHeader
)
4828 // don't delete, just hide, as we can reuse it later
4829 m_headerWin
->Show(false);
4831 //else: nothing to do
4833 else // must show header
4837 CreateHeaderWindow();
4839 else // already have it, just show
4841 m_headerWin
->Show( true );
4845 ResizeReportView(willHaveHeader
);
4849 wxWindow::SetWindowStyleFlag( flag
);
4852 bool wxGenericListCtrl::GetColumn(int col
, wxListItem
&item
) const
4854 m_mainWin
->GetColumn( col
, item
);
4858 bool wxGenericListCtrl::SetColumn( int col
, wxListItem
& item
)
4860 m_mainWin
->SetColumn( col
, item
);
4864 int wxGenericListCtrl::GetColumnWidth( int col
) const
4866 return m_mainWin
->GetColumnWidth( col
);
4869 bool wxGenericListCtrl::SetColumnWidth( int col
, int width
)
4871 m_mainWin
->SetColumnWidth( col
, width
);
4875 int wxGenericListCtrl::GetCountPerPage() const
4877 return m_mainWin
->GetCountPerPage(); // different from Windows ?
4880 bool wxGenericListCtrl::GetItem( wxListItem
&info
) const
4882 m_mainWin
->GetItem( info
);
4886 bool wxGenericListCtrl::SetItem( wxListItem
&info
)
4888 m_mainWin
->SetItem( info
);
4892 long wxGenericListCtrl::SetItem( long index
, int col
, const wxString
& label
, int imageId
)
4895 info
.m_text
= label
;
4896 info
.m_mask
= wxLIST_MASK_TEXT
;
4897 info
.m_itemId
= index
;
4901 info
.m_image
= imageId
;
4902 info
.m_mask
|= wxLIST_MASK_IMAGE
;
4904 m_mainWin
->SetItem(info
);
4908 int wxGenericListCtrl::GetItemState( long item
, long stateMask
) const
4910 return m_mainWin
->GetItemState( item
, stateMask
);
4913 bool wxGenericListCtrl::SetItemState( long item
, long state
, long stateMask
)
4915 m_mainWin
->SetItemState( item
, state
, stateMask
);
4920 wxGenericListCtrl::SetItemImage( long item
, int image
, int WXUNUSED(selImage
) )
4923 info
.m_image
= image
;
4924 info
.m_mask
= wxLIST_MASK_IMAGE
;
4925 info
.m_itemId
= item
;
4926 m_mainWin
->SetItem( info
);
4930 wxString
wxGenericListCtrl::GetItemText( long item
) const
4932 return m_mainWin
->GetItemText(item
);
4935 void wxGenericListCtrl::SetItemText( long item
, const wxString
& str
)
4937 m_mainWin
->SetItemText(item
, str
);
4940 wxUIntPtr
wxGenericListCtrl::GetItemData( long item
) const
4943 info
.m_itemId
= item
;
4944 m_mainWin
->GetItem( info
);
4948 bool wxGenericListCtrl::SetItemData( long item
, long data
)
4951 info
.m_mask
= wxLIST_MASK_DATA
;
4952 info
.m_itemId
= item
;
4954 m_mainWin
->SetItem( info
);
4958 wxRect
wxGenericListCtrl::GetViewRect() const
4960 return m_mainWin
->GetViewRect();
4963 bool wxGenericListCtrl::GetItemRect( long item
, wxRect
&rect
, int WXUNUSED(code
) ) const
4965 m_mainWin
->GetItemRect( item
, rect
);
4966 if ( m_mainWin
->HasHeader() )
4967 rect
.y
+= m_headerHeight
+ 1;
4971 bool wxGenericListCtrl::GetItemPosition( long item
, wxPoint
& pos
) const
4973 m_mainWin
->GetItemPosition( item
, pos
);
4977 bool wxGenericListCtrl::SetItemPosition( long WXUNUSED(item
), const wxPoint
& WXUNUSED(pos
) )
4982 int wxGenericListCtrl::GetItemCount() const
4984 return m_mainWin
->GetItemCount();
4987 int wxGenericListCtrl::GetColumnCount() const
4989 return m_mainWin
->GetColumnCount();
4992 void wxGenericListCtrl::SetItemSpacing( int spacing
, bool isSmall
)
4994 m_mainWin
->SetItemSpacing( spacing
, isSmall
);
4997 wxSize
wxGenericListCtrl::GetItemSpacing() const
4999 const int spacing
= m_mainWin
->GetItemSpacing(HasFlag(wxLC_SMALL_ICON
));
5001 return wxSize(spacing
, spacing
);
5004 int wxGenericListCtrl::GetItemSpacing( bool isSmall
) const
5006 return m_mainWin
->GetItemSpacing( isSmall
);
5009 void wxGenericListCtrl::SetItemTextColour( long item
, const wxColour
&col
)
5012 info
.m_itemId
= item
;
5013 info
.SetTextColour( col
);
5014 m_mainWin
->SetItem( info
);
5017 wxColour
wxGenericListCtrl::GetItemTextColour( long item
) const
5020 info
.m_itemId
= item
;
5021 m_mainWin
->GetItem( info
);
5022 return info
.GetTextColour();
5025 void wxGenericListCtrl::SetItemBackgroundColour( long item
, const wxColour
&col
)
5028 info
.m_itemId
= item
;
5029 info
.SetBackgroundColour( col
);
5030 m_mainWin
->SetItem( info
);
5033 wxColour
wxGenericListCtrl::GetItemBackgroundColour( long item
) const
5036 info
.m_itemId
= item
;
5037 m_mainWin
->GetItem( info
);
5038 return info
.GetBackgroundColour();
5041 int wxGenericListCtrl::GetSelectedItemCount() const
5043 return m_mainWin
->GetSelectedItemCount();
5046 wxColour
wxGenericListCtrl::GetTextColour() const
5048 return GetForegroundColour();
5051 void wxGenericListCtrl::SetTextColour(const wxColour
& col
)
5053 SetForegroundColour(col
);
5056 long wxGenericListCtrl::GetTopItem() const
5059 m_mainWin
->GetVisibleLinesRange(&top
, NULL
);
5063 long wxGenericListCtrl::GetNextItem( long item
, int geom
, int state
) const
5065 return m_mainWin
->GetNextItem( item
, geom
, state
);
5068 wxImageListType
*wxGenericListCtrl::GetImageList(int which
) const
5070 if (which
== wxIMAGE_LIST_NORMAL
)
5072 return m_imageListNormal
;
5074 else if (which
== wxIMAGE_LIST_SMALL
)
5076 return m_imageListSmall
;
5078 else if (which
== wxIMAGE_LIST_STATE
)
5080 return m_imageListState
;
5082 return (wxImageListType
*) NULL
;
5085 void wxGenericListCtrl::SetImageList( wxImageListType
*imageList
, int which
)
5087 if ( which
== wxIMAGE_LIST_NORMAL
)
5089 if (m_ownsImageListNormal
) delete m_imageListNormal
;
5090 m_imageListNormal
= imageList
;
5091 m_ownsImageListNormal
= false;
5093 else if ( which
== wxIMAGE_LIST_SMALL
)
5095 if (m_ownsImageListSmall
) delete m_imageListSmall
;
5096 m_imageListSmall
= imageList
;
5097 m_ownsImageListSmall
= false;
5099 else if ( which
== wxIMAGE_LIST_STATE
)
5101 if (m_ownsImageListState
) delete m_imageListState
;
5102 m_imageListState
= imageList
;
5103 m_ownsImageListState
= false;
5106 m_mainWin
->SetImageList( imageList
, which
);
5109 void wxGenericListCtrl::AssignImageList(wxImageListType
*imageList
, int which
)
5111 SetImageList(imageList
, which
);
5112 if ( which
== wxIMAGE_LIST_NORMAL
)
5113 m_ownsImageListNormal
= true;
5114 else if ( which
== wxIMAGE_LIST_SMALL
)
5115 m_ownsImageListSmall
= true;
5116 else if ( which
== wxIMAGE_LIST_STATE
)
5117 m_ownsImageListState
= true;
5120 bool wxGenericListCtrl::Arrange( int WXUNUSED(flag
) )
5125 bool wxGenericListCtrl::DeleteItem( long item
)
5127 m_mainWin
->DeleteItem( item
);
5131 bool wxGenericListCtrl::DeleteAllItems()
5133 m_mainWin
->DeleteAllItems();
5137 bool wxGenericListCtrl::DeleteAllColumns()
5139 size_t count
= m_mainWin
->m_columns
.GetCount();
5140 for ( size_t n
= 0; n
< count
; n
++ )
5146 void wxGenericListCtrl::ClearAll()
5148 m_mainWin
->DeleteEverything();
5151 bool wxGenericListCtrl::DeleteColumn( int col
)
5153 m_mainWin
->DeleteColumn( col
);
5155 // if we don't have the header any longer, we need to relayout the window
5156 if ( !GetColumnCount() )
5158 ResizeReportView(false /* no header */);
5164 void wxGenericListCtrl::Edit( long item
)
5166 m_mainWin
->EditLabel( item
);
5169 bool wxGenericListCtrl::EnsureVisible( long item
)
5171 m_mainWin
->EnsureVisible( item
);
5175 long wxGenericListCtrl::FindItem( long start
, const wxString
& str
, bool partial
)
5177 return m_mainWin
->FindItem( start
, str
, partial
);
5180 long wxGenericListCtrl::FindItem( long start
, wxUIntPtr data
)
5182 return m_mainWin
->FindItem( start
, data
);
5185 long wxGenericListCtrl::FindItem( long WXUNUSED(start
), const wxPoint
& pt
,
5186 int WXUNUSED(direction
))
5188 return m_mainWin
->FindItem( pt
);
5191 long wxGenericListCtrl::HitTest( const wxPoint
&point
, int &flags
)
5193 return m_mainWin
->HitTest( (int)point
.x
, (int)point
.y
, flags
);
5196 long wxGenericListCtrl::InsertItem( wxListItem
& info
)
5198 m_mainWin
->InsertItem( info
);
5199 return info
.m_itemId
;
5202 long wxGenericListCtrl::InsertItem( long index
, const wxString
&label
)
5205 info
.m_text
= label
;
5206 info
.m_mask
= wxLIST_MASK_TEXT
;
5207 info
.m_itemId
= index
;
5208 return InsertItem( info
);
5211 long wxGenericListCtrl::InsertItem( long index
, int imageIndex
)
5214 info
.m_mask
= wxLIST_MASK_IMAGE
;
5215 info
.m_image
= imageIndex
;
5216 info
.m_itemId
= index
;
5217 return InsertItem( info
);
5220 long wxGenericListCtrl::InsertItem( long index
, const wxString
&label
, int imageIndex
)
5223 info
.m_text
= label
;
5224 info
.m_image
= imageIndex
;
5225 info
.m_mask
= wxLIST_MASK_TEXT
| wxLIST_MASK_IMAGE
;
5226 info
.m_itemId
= index
;
5227 return InsertItem( info
);
5230 long wxGenericListCtrl::InsertColumn( long col
, wxListItem
&item
)
5232 wxCHECK_MSG( m_headerWin
, -1, _T("can't add column in non report mode") );
5234 m_mainWin
->InsertColumn( col
, item
);
5236 // if we hadn't had header before and have it now we need to relayout the
5238 if ( GetColumnCount() == 1 && m_mainWin
->HasHeader() )
5240 ResizeReportView(true /* have header */);
5243 m_headerWin
->Refresh();
5248 long wxGenericListCtrl::InsertColumn( long col
, const wxString
&heading
,
5249 int format
, int width
)
5252 item
.m_mask
= wxLIST_MASK_TEXT
| wxLIST_MASK_FORMAT
;
5253 item
.m_text
= heading
;
5256 item
.m_mask
|= wxLIST_MASK_WIDTH
;
5257 item
.m_width
= width
;
5259 item
.m_format
= format
;
5261 return InsertColumn( col
, item
);
5264 bool wxGenericListCtrl::ScrollList( int WXUNUSED(dx
), int WXUNUSED(dy
) )
5270 // fn is a function which takes 3 long arguments: item1, item2, data.
5271 // item1 is the long data associated with a first item (NOT the index).
5272 // item2 is the long data associated with a second item (NOT the index).
5273 // data is the same value as passed to SortItems.
5274 // The return value is a negative number if the first item should precede the second
5275 // item, a positive number of the second item should precede the first,
5276 // or zero if the two items are equivalent.
5277 // data is arbitrary data to be passed to the sort function.
5279 bool wxGenericListCtrl::SortItems( wxListCtrlCompare fn
, long data
)
5281 m_mainWin
->SortItems( fn
, data
);
5285 // ----------------------------------------------------------------------------
5287 // ----------------------------------------------------------------------------
5289 void wxGenericListCtrl::OnSize(wxSizeEvent
& WXUNUSED(event
))
5294 ResizeReportView(m_mainWin
->HasHeader());
5296 m_mainWin
->RecalculatePositions();
5299 void wxGenericListCtrl::ResizeReportView(bool showHeader
)
5302 GetClientSize( &cw
, &ch
);
5306 m_headerWin
->SetSize( 0, 0, cw
, m_headerHeight
);
5307 m_mainWin
->SetSize( 0, m_headerHeight
+ 1, cw
, ch
- m_headerHeight
- 1 );
5309 else // no header window
5311 m_mainWin
->SetSize( 0, 0, cw
, ch
);
5315 void wxGenericListCtrl::OnInternalIdle()
5317 wxWindow::OnInternalIdle();
5319 // do it only if needed
5320 if ( !m_mainWin
->m_dirty
)
5323 m_mainWin
->RecalculatePositions();
5326 // ----------------------------------------------------------------------------
5328 // ----------------------------------------------------------------------------
5330 bool wxGenericListCtrl::SetBackgroundColour( const wxColour
&colour
)
5334 m_mainWin
->SetBackgroundColour( colour
);
5335 m_mainWin
->m_dirty
= true;
5341 bool wxGenericListCtrl::SetForegroundColour( const wxColour
&colour
)
5343 if ( !wxWindow::SetForegroundColour( colour
) )
5348 m_mainWin
->SetForegroundColour( colour
);
5349 m_mainWin
->m_dirty
= true;
5354 m_headerWin
->SetForegroundColour( colour
);
5360 bool wxGenericListCtrl::SetFont( const wxFont
&font
)
5362 if ( !wxWindow::SetFont( font
) )
5367 m_mainWin
->SetFont( font
);
5368 m_mainWin
->m_dirty
= true;
5373 m_headerWin
->SetFont( font
);
5374 CalculateAndSetHeaderHeight();
5385 #include "wx/listbox.h"
5390 wxGenericListCtrl::GetClassDefaultAttributes(wxWindowVariant variant
)
5393 // Use the same color scheme as wxListBox
5394 return wxListBox::GetClassDefaultAttributes(variant
);
5396 wxUnusedVar(variant
);
5397 wxVisualAttributes attr
;
5398 attr
.colFg
= wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT
);
5399 attr
.colBg
= wxSystemSettings::GetColour(wxSYS_COLOUR_LISTBOX
);
5400 attr
.font
= wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT
);
5405 // ----------------------------------------------------------------------------
5406 // methods forwarded to m_mainWin
5407 // ----------------------------------------------------------------------------
5409 #if wxUSE_DRAG_AND_DROP
5411 void wxGenericListCtrl::SetDropTarget( wxDropTarget
*dropTarget
)
5413 m_mainWin
->SetDropTarget( dropTarget
);
5416 wxDropTarget
*wxGenericListCtrl::GetDropTarget() const
5418 return m_mainWin
->GetDropTarget();
5421 #endif // wxUSE_DRAG_AND_DROP
5423 bool wxGenericListCtrl::SetCursor( const wxCursor
&cursor
)
5425 return m_mainWin
? m_mainWin
->wxWindow::SetCursor(cursor
) : false;
5428 wxColour
wxGenericListCtrl::GetBackgroundColour() const
5430 return m_mainWin
? m_mainWin
->GetBackgroundColour() : wxColour();
5433 wxColour
wxGenericListCtrl::GetForegroundColour() const
5435 return m_mainWin
? m_mainWin
->GetForegroundColour() : wxColour();
5438 bool wxGenericListCtrl::DoPopupMenu( wxMenu
*menu
, int x
, int y
)
5441 return m_mainWin
->PopupMenu( menu
, x
, y
);
5444 #endif // wxUSE_MENUS
5447 void wxGenericListCtrl::SetFocus()
5449 /* The test in window.cpp fails as we are a composite
5450 window, so it checks against "this", but not m_mainWin. */
5451 if ( DoFindFocus() != this )
5452 m_mainWin
->SetFocus();
5455 wxSize
wxGenericListCtrl::DoGetBestSize() const
5457 // Something is better than nothing...
5458 // 100x80 is what the MSW version will get from the default
5459 // wxControl::DoGetBestSize
5460 return wxSize(100,80);
5463 // ----------------------------------------------------------------------------
5464 // virtual list control support
5465 // ----------------------------------------------------------------------------
5467 wxString
wxGenericListCtrl::OnGetItemText(long WXUNUSED(item
), long WXUNUSED(col
)) const
5469 // this is a pure virtual function, in fact - which is not really pure
5470 // because the controls which are not virtual don't need to implement it
5471 wxFAIL_MSG( _T("wxGenericListCtrl::OnGetItemText not supposed to be called") );
5473 return wxEmptyString
;
5476 int wxGenericListCtrl::OnGetItemImage(long WXUNUSED(item
)) const
5478 wxCHECK_MSG(!GetImageList(wxIMAGE_LIST_SMALL
),
5480 wxT("List control has an image list, OnGetItemImage should be overridden."));
5485 wxGenericListCtrl::OnGetItemAttr(long WXUNUSED_UNLESS_DEBUG(item
)) const
5487 wxASSERT_MSG( item
>= 0 && item
< GetItemCount(),
5488 _T("invalid item index in OnGetItemAttr()") );
5490 // no attributes by default
5494 void wxGenericListCtrl::SetItemCount(long count
)
5496 wxASSERT_MSG( IsVirtual(), _T("this is for virtual controls only") );
5498 m_mainWin
->SetItemCount(count
);
5501 void wxGenericListCtrl::RefreshItem(long item
)
5503 m_mainWin
->RefreshLine(item
);
5506 void wxGenericListCtrl::RefreshItems(long itemFrom
, long itemTo
)
5508 m_mainWin
->RefreshLines(itemFrom
, itemTo
);
5512 * Generic wxListCtrl is more or less a container for two other
5513 * windows which drawings are done upon. These are namely
5514 * 'm_headerWin' and 'm_mainWin'.
5515 * Here we override 'virtual wxWindow::Refresh()' to mimic the
5516 * behaviour wxListCtrl has under wxMSW.
5518 void wxGenericListCtrl::Refresh(bool eraseBackground
, const wxRect
*rect
)
5522 // The easy case, no rectangle specified.
5524 m_headerWin
->Refresh(eraseBackground
);
5527 m_mainWin
->Refresh(eraseBackground
);
5531 // Refresh the header window
5534 wxRect rectHeader
= m_headerWin
->GetRect();
5535 rectHeader
.Intersect(*rect
);
5536 if (rectHeader
.GetWidth() && rectHeader
.GetHeight())
5539 m_headerWin
->GetPosition(&x
, &y
);
5540 rectHeader
.Offset(-x
, -y
);
5541 m_headerWin
->Refresh(eraseBackground
, &rectHeader
);
5546 // Refresh the main window
5549 wxRect rectMain
= m_mainWin
->GetRect();
5550 rectMain
.Intersect(*rect
);
5551 if (rectMain
.GetWidth() && rectMain
.GetHeight())
5554 m_mainWin
->GetPosition(&x
, &y
);
5555 rectMain
.Offset(-x
, -y
);
5556 m_mainWin
->Refresh(eraseBackground
, &rectMain
);
5562 void wxGenericListCtrl::Freeze()
5564 m_mainWin
->Freeze();
5567 void wxGenericListCtrl::Thaw()
5572 #endif // wxUSE_LISTCTRL