1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/generic/listctrl.cpp
3 // Purpose: generic implementation of wxListCtrl
4 // Author: Robert Roebling
5 // Vadim Zeitlin (virtual list control support)
7 // Copyright: (c) 1998 Robert Roebling
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
13 // 1. we need to implement searching/sorting for virtual controls somehow
14 // 2. when changing selection the lines are refreshed twice
17 // For compilers that support precompilation, includes "wx.h".
18 #include "wx/wxprec.h"
26 #include "wx/listctrl.h"
28 #if (!defined(__WXMSW__) || defined(__WXUNIVERSAL__)) && !defined(__WXMAC__)
29 // if we have a native version, its implementation file does all this
30 IMPLEMENT_DYNAMIC_CLASS(wxListItem
, wxObject
)
31 IMPLEMENT_DYNAMIC_CLASS(wxListView
, wxListCtrl
)
32 IMPLEMENT_DYNAMIC_CLASS(wxListEvent
, wxNotifyEvent
)
34 IMPLEMENT_DYNAMIC_CLASS(wxListCtrl
, wxGenericListCtrl
)
38 #include "wx/scrolwin.h"
40 #include "wx/settings.h"
41 #include "wx/dynarray.h"
42 #include "wx/dcclient.h"
43 #include "wx/dcscreen.h"
47 #include "wx/imaglist.h"
48 #include "wx/selstore.h"
49 #include "wx/renderer.h"
52 #include "wx/mac/private.h"
56 // NOTE: If using the wxListBox visual attributes works everywhere then this can
57 // be removed, as well as the #else case below.
58 #define _USE_VISATTR 0
61 // ----------------------------------------------------------------------------
63 // ----------------------------------------------------------------------------
65 // // the height of the header window (FIXME: should depend on its font!)
66 // static const int HEADER_HEIGHT = 23;
68 static const int SCROLL_UNIT_X
= 15;
70 // the spacing between the lines (in report mode)
71 static const int LINE_SPACING
= 0;
73 // extra margins around the text label
74 static const int EXTRA_WIDTH
= 4;
75 static const int EXTRA_HEIGHT
= 4;
77 // margin between the window and the items
78 static const int EXTRA_BORDER_X
= 2;
79 static const int EXTRA_BORDER_Y
= 2;
81 // offset for the header window
82 static const int HEADER_OFFSET_X
= 1;
83 static const int HEADER_OFFSET_Y
= 1;
85 // margin between rows of icons in [small] icon view
86 static const int MARGIN_BETWEEN_ROWS
= 6;
88 // when autosizing the columns, add some slack
89 static const int AUTOSIZE_COL_MARGIN
= 10;
91 // default width for the header columns
92 static const int WIDTH_COL_DEFAULT
= 80;
94 // the space between the image and the text in the report mode
95 static const int IMAGE_MARGIN_IN_REPORT_MODE
= 5;
97 // ============================================================================
99 // ============================================================================
101 //-----------------------------------------------------------------------------
102 // wxColWidthInfo (internal)
103 //-----------------------------------------------------------------------------
105 struct wxColWidthInfo
108 bool bNeedsUpdate
; // only set to true when an item whose
109 // width == nMaxWidth is removed
111 wxColWidthInfo(int w
= 0, bool needsUpdate
= false)
114 bNeedsUpdate
= needsUpdate
;
118 WX_DEFINE_ARRAY_PTR(wxColWidthInfo
*, ColWidthArray
);
120 //-----------------------------------------------------------------------------
121 // wxListItemData (internal)
122 //-----------------------------------------------------------------------------
124 class WXDLLEXPORT wxListItemData
127 wxListItemData(wxListMainWindow
*owner
);
130 void SetItem( const wxListItem
&info
);
131 void SetImage( int image
) { m_image
= image
; }
132 void SetData( wxUIntPtr data
) { m_data
= data
; }
133 void SetPosition( int x
, int y
);
134 void SetSize( int width
, int height
);
136 bool HasText() const { return !m_text
.empty(); }
137 const wxString
& GetText() const { return m_text
; }
138 void SetText(const wxString
& text
) { m_text
= text
; }
140 // we can't use empty string for measuring the string width/height, so
141 // always return something
142 wxString
GetTextForMeasuring() const
144 wxString s
= GetText();
151 bool IsHit( int x
, int y
) const;
155 int GetWidth() const;
156 int GetHeight() const;
158 int GetImage() const { return m_image
; }
159 bool HasImage() const { return GetImage() != -1; }
161 void GetItem( wxListItem
&info
) const;
163 void SetAttr(wxListItemAttr
*attr
) { m_attr
= attr
; }
164 wxListItemAttr
*GetAttr() const { return m_attr
; }
167 // the item image or -1
170 // user data associated with the item
173 // the item coordinates are not used in report mode; instead this pointer is
174 // NULL and the owner window is used to retrieve the item position and size
177 // the list ctrl we are in
178 wxListMainWindow
*m_owner
;
180 // custom attributes or NULL
181 wxListItemAttr
*m_attr
;
184 // common part of all ctors
190 //-----------------------------------------------------------------------------
191 // wxListHeaderData (internal)
192 //-----------------------------------------------------------------------------
194 class WXDLLEXPORT wxListHeaderData
: public wxObject
198 wxListHeaderData( const wxListItem
&info
);
199 void SetItem( const wxListItem
&item
);
200 void SetPosition( int x
, int y
);
201 void SetWidth( int w
);
202 void SetFormat( int format
);
203 void SetHeight( int h
);
204 bool HasImage() const;
206 bool HasText() const { return !m_text
.empty(); }
207 const wxString
& GetText() const { return m_text
; }
208 void SetText(const wxString
& text
) { m_text
= text
; }
210 void GetItem( wxListItem
&item
);
212 bool IsHit( int x
, int y
) const;
213 int GetImage() const;
214 int GetWidth() const;
215 int GetFormat() const;
231 //-----------------------------------------------------------------------------
232 // wxListLineData (internal)
233 //-----------------------------------------------------------------------------
235 WX_DECLARE_EXPORTED_LIST(wxListItemData
, wxListItemDataList
);
236 #include "wx/listimpl.cpp"
237 WX_DEFINE_LIST(wxListItemDataList
)
242 // the list of subitems: only may have more than one item in report mode
243 wxListItemDataList m_items
;
245 // this is not used in report view
257 // the part to be highlighted
258 wxRect m_rectHighlight
;
260 // extend all our rects to be centered inside the one of given width
261 void ExtendWidth(wxCoord w
)
263 wxASSERT_MSG( m_rectAll
.width
<= w
,
264 _T("width can only be increased") );
267 m_rectLabel
.x
= m_rectAll
.x
+ (w
- m_rectLabel
.width
) / 2;
268 m_rectIcon
.x
= m_rectAll
.x
+ (w
- m_rectIcon
.width
) / 2;
269 m_rectHighlight
.x
= m_rectAll
.x
+ (w
- m_rectHighlight
.width
) / 2;
274 // is this item selected? [NB: not used in virtual mode]
277 // back pointer to the list ctrl
278 wxListMainWindow
*m_owner
;
281 wxListLineData(wxListMainWindow
*owner
);
285 WX_CLEAR_LIST(wxListItemDataList
, m_items
);
289 // are we in report mode?
290 inline bool InReportView() const;
292 // are we in virtual report mode?
293 inline bool IsVirtual() const;
295 // these 2 methods shouldn't be called for report view controls, in that
296 // case we determine our position/size ourselves
298 // calculate the size of the line
299 void CalculateSize( wxDC
*dc
, int spacing
);
301 // remember the position this line appears at
302 void SetPosition( int x
, int y
, int spacing
);
306 void SetImage( int image
) { SetImage(0, image
); }
307 int GetImage() const { return GetImage(0); }
308 void SetImage( int index
, int image
);
309 int GetImage( int index
) const;
311 bool HasImage() const { return GetImage() != -1; }
312 bool HasText() const { return !GetText(0).empty(); }
314 void SetItem( int index
, const wxListItem
&info
);
315 void GetItem( int index
, wxListItem
&info
);
317 wxString
GetText(int index
) const;
318 void SetText( int index
, const wxString
& s
);
320 wxListItemAttr
*GetAttr() const;
321 void SetAttr(wxListItemAttr
*attr
);
323 // return true if the highlighting really changed
324 bool Highlight( bool on
);
326 void ReverseHighlight();
328 bool IsHighlighted() const
330 wxASSERT_MSG( !IsVirtual(), _T("unexpected call to IsHighlighted") );
332 return m_highlighted
;
335 // draw the line on the given DC in icon/list mode
336 void Draw( wxDC
*dc
);
338 // the same in report mode
339 void DrawInReportMode( wxDC
*dc
,
341 const wxRect
& rectHL
,
345 // set the line to contain num items (only can be > 1 in report mode)
346 void InitItems( int num
);
348 // get the mode (i.e. style) of the list control
349 inline int GetMode() const;
351 // prepare the DC for drawing with these item's attributes, return true if
352 // we need to draw the items background to highlight it, false otherwise
353 bool SetAttributes(wxDC
*dc
,
354 const wxListItemAttr
*attr
,
357 // draw the text on the DC with the correct justification; also add an
358 // ellipsis if the text is too large to fit in the current width
359 void DrawTextFormatted(wxDC
*dc
,
360 const wxString
&text
,
363 int yMid
, // this is middle, not top, of the text
367 WX_DECLARE_EXPORTED_OBJARRAY(wxListLineData
, wxListLineDataArray
);
368 #include "wx/arrimpl.cpp"
369 WX_DEFINE_OBJARRAY(wxListLineDataArray
)
371 //-----------------------------------------------------------------------------
372 // wxListHeaderWindow (internal)
373 //-----------------------------------------------------------------------------
375 class WXDLLEXPORT wxListHeaderWindow
: public wxWindow
378 wxListMainWindow
*m_owner
;
379 const wxCursor
*m_currentCursor
;
380 wxCursor
*m_resizeCursor
;
383 // column being resized or -1
386 // divider line position in logical (unscrolled) coords
389 // minimal position beyond which the divider line
390 // can't be dragged in logical coords
394 wxListHeaderWindow();
396 wxListHeaderWindow( wxWindow
*win
,
398 wxListMainWindow
*owner
,
399 const wxPoint
&pos
= wxDefaultPosition
,
400 const wxSize
&size
= wxDefaultSize
,
402 const wxString
&name
= wxT("wxlistctrlcolumntitles") );
404 virtual ~wxListHeaderWindow();
407 void AdjustDC( wxDC
& dc
);
409 void OnPaint( wxPaintEvent
&event
);
410 void OnMouse( wxMouseEvent
&event
);
411 void OnSetFocus( wxFocusEvent
&event
);
417 // common part of all ctors
420 // generate and process the list event of the given type, return true if
421 // it wasn't vetoed, i.e. if we should proceed
422 bool SendListEvent(wxEventType type
, const wxPoint
& pos
);
424 DECLARE_DYNAMIC_CLASS(wxListHeaderWindow
)
425 DECLARE_EVENT_TABLE()
428 //-----------------------------------------------------------------------------
429 // wxListRenameTimer (internal)
430 //-----------------------------------------------------------------------------
432 class WXDLLEXPORT wxListRenameTimer
: public wxTimer
435 wxListMainWindow
*m_owner
;
438 wxListRenameTimer( wxListMainWindow
*owner
);
442 //-----------------------------------------------------------------------------
443 // wxListTextCtrlWrapper: wraps a wxTextCtrl to make it work for inline editing
444 //-----------------------------------------------------------------------------
446 class WXDLLEXPORT wxListTextCtrlWrapper
: public wxEvtHandler
449 // NB: text must be a valid object but not Create()d yet
450 wxListTextCtrlWrapper(wxListMainWindow
*owner
,
454 wxTextCtrl
*GetText() const { return m_text
; }
456 void AcceptChangesAndFinish();
459 void OnChar( wxKeyEvent
&event
);
460 void OnKeyUp( wxKeyEvent
&event
);
461 void OnKillFocus( wxFocusEvent
&event
);
463 bool AcceptChanges();
467 wxListMainWindow
*m_owner
;
469 wxString m_startValue
;
472 bool m_aboutToFinish
;
474 DECLARE_EVENT_TABLE()
477 //-----------------------------------------------------------------------------
478 // wxListMainWindow (internal)
479 //-----------------------------------------------------------------------------
481 WX_DECLARE_EXPORTED_LIST(wxListHeaderData
, wxListHeaderDataList
);
482 #include "wx/listimpl.cpp"
483 WX_DEFINE_LIST(wxListHeaderDataList
)
485 class wxListMainWindow
: public wxScrolledWindow
489 wxListMainWindow( wxWindow
*parent
,
491 const wxPoint
& pos
= wxDefaultPosition
,
492 const wxSize
& size
= wxDefaultSize
,
494 const wxString
&name
= _T("listctrlmainwindow") );
496 virtual ~wxListMainWindow();
498 bool HasFlag(int flag
) const { return m_parent
->HasFlag(flag
); }
500 // return true if this is a virtual list control
501 bool IsVirtual() const { return HasFlag(wxLC_VIRTUAL
); }
503 // return true if the control is in report mode
504 bool InReportView() const { return HasFlag(wxLC_REPORT
); }
506 // return true if we are in single selection mode, false if multi sel
507 bool IsSingleSel() const { return HasFlag(wxLC_SINGLE_SEL
); }
509 // do we have a header window?
510 bool HasHeader() const
511 { return InReportView() && !HasFlag(wxLC_NO_HEADER
); }
513 void HighlightAll( bool on
);
515 // all these functions only do something if the line is currently visible
517 // change the line "selected" state, return true if it really changed
518 bool HighlightLine( size_t line
, bool highlight
= true);
520 // as HighlightLine() but do it for the range of lines: this is incredibly
521 // more efficient for virtual list controls!
523 // NB: unlike HighlightLine() this one does refresh the lines on screen
524 void HighlightLines( size_t lineFrom
, size_t lineTo
, bool on
= true );
526 // toggle the line state and refresh it
527 void ReverseHighlight( size_t line
)
528 { HighlightLine(line
, !IsHighlighted(line
)); RefreshLine(line
); }
530 // return true if the line is highlighted
531 bool IsHighlighted(size_t line
) const;
533 // refresh one or several lines at once
534 void RefreshLine( size_t line
);
535 void RefreshLines( size_t lineFrom
, size_t lineTo
);
537 // refresh all selected items
538 void RefreshSelected();
540 // refresh all lines below the given one: the difference with
541 // RefreshLines() is that the index here might not be a valid one (happens
542 // when the last line is deleted)
543 void RefreshAfter( size_t lineFrom
);
545 // the methods which are forwarded to wxListLineData itself in list/icon
546 // modes but are here because the lines don't store their positions in the
549 // get the bound rect for the entire line
550 wxRect
GetLineRect(size_t line
) const;
552 // get the bound rect of the label
553 wxRect
GetLineLabelRect(size_t line
) const;
555 // get the bound rect of the items icon (only may be called if we do have
557 wxRect
GetLineIconRect(size_t line
) const;
559 // get the rect to be highlighted when the item has focus
560 wxRect
GetLineHighlightRect(size_t line
) const;
562 // get the size of the total line rect
563 wxSize
GetLineSize(size_t line
) const
564 { return GetLineRect(line
).GetSize(); }
566 // return the hit code for the corresponding position (in this line)
567 long HitTestLine(size_t line
, int x
, int y
) const;
569 // bring the selected item into view, scrolling to it if necessary
570 void MoveToItem(size_t item
);
572 // bring the current item into view
573 void MoveToFocus() { MoveToItem(m_current
); }
575 // start editing the label of the given item
576 wxTextCtrl
*EditLabel(long item
,
577 wxClassInfo
* textControlClass
= CLASSINFO(wxTextCtrl
));
578 wxTextCtrl
*GetEditControl() const
580 return m_textctrlWrapper
? m_textctrlWrapper
->GetText() : NULL
;
583 void FinishEditing(wxTextCtrl
*text
)
586 m_textctrlWrapper
= NULL
;
587 SetFocusIgnoringChildren();
590 // suspend/resume redrawing the control
594 void OnRenameTimer();
595 bool OnRenameAccept(size_t itemEdit
, const wxString
& value
);
596 void OnRenameCancelled(size_t itemEdit
);
598 void OnMouse( wxMouseEvent
&event
);
600 // called to switch the selection from the current item to newCurrent,
601 void OnArrowChar( size_t newCurrent
, const wxKeyEvent
& event
);
603 void OnChar( wxKeyEvent
&event
);
604 void OnKeyDown( wxKeyEvent
&event
);
605 void OnSetFocus( wxFocusEvent
&event
);
606 void OnKillFocus( wxFocusEvent
&event
);
607 void OnScroll( wxScrollWinEvent
& event
);
609 void OnPaint( wxPaintEvent
&event
);
611 void DrawImage( int index
, wxDC
*dc
, int x
, int y
);
612 void GetImageSize( int index
, int &width
, int &height
) const;
613 int GetTextLength( const wxString
&s
) const;
615 void SetImageList( wxImageList
*imageList
, int which
);
616 void SetItemSpacing( int spacing
, bool isSmall
= false );
617 int GetItemSpacing( bool isSmall
= false );
619 void SetColumn( int col
, wxListItem
&item
);
620 void SetColumnWidth( int col
, int width
);
621 void GetColumn( int col
, wxListItem
&item
) const;
622 int GetColumnWidth( int col
) const;
623 int GetColumnCount() const { return m_columns
.GetCount(); }
625 // returns the sum of the heights of all columns
626 int GetHeaderWidth() const;
628 int GetCountPerPage() const;
630 void SetItem( wxListItem
&item
);
631 void GetItem( wxListItem
&item
) const;
632 void SetItemState( long item
, long state
, long stateMask
);
633 void SetItemStateAll( long state
, long stateMask
);
634 int GetItemState( long item
, long stateMask
) const;
635 void GetItemRect( long index
, wxRect
&rect
) const;
636 wxRect
GetViewRect() const;
637 bool GetItemPosition( long item
, wxPoint
& pos
) const;
638 int GetSelectedItemCount() const;
640 wxString
GetItemText(long item
) const
643 info
.m_mask
= wxLIST_MASK_TEXT
;
644 info
.m_itemId
= item
;
649 void SetItemText(long item
, const wxString
& value
)
652 info
.m_mask
= wxLIST_MASK_TEXT
;
653 info
.m_itemId
= item
;
658 // set the scrollbars and update the positions of the items
659 void RecalculatePositions(bool noRefresh
= false);
661 // refresh the window and the header
664 long GetNextItem( long item
, int geometry
, int state
) const;
665 void DeleteItem( long index
);
666 void DeleteAllItems();
667 void DeleteColumn( int col
);
668 void DeleteEverything();
669 void EnsureVisible( long index
);
670 long FindItem( long start
, const wxString
& str
, bool partial
= false );
671 long FindItem( long start
, wxUIntPtr data
);
672 long FindItem( const wxPoint
& pt
);
673 long HitTest( int x
, int y
, int &flags
) const;
674 void InsertItem( wxListItem
&item
);
675 void InsertColumn( long col
, wxListItem
&item
);
676 int GetItemWidthWithImage(wxListItem
* item
);
677 void SortItems( wxListCtrlCompare fn
, long data
);
679 size_t GetItemCount() const;
680 bool IsEmpty() const { return GetItemCount() == 0; }
681 void SetItemCount(long count
);
683 // change the current (== focused) item, send a notification event
684 void ChangeCurrent(size_t current
);
685 void ResetCurrent() { ChangeCurrent((size_t)-1); }
686 bool HasCurrent() const { return m_current
!= (size_t)-1; }
688 // send out a wxListEvent
689 void SendNotify( size_t line
,
691 const wxPoint
& point
= wxDefaultPosition
);
693 // override base class virtual to reset m_lineHeight when the font changes
694 virtual bool SetFont(const wxFont
& font
)
696 if ( !wxScrolledWindow::SetFont(font
) )
704 // these are for wxListLineData usage only
706 // get the backpointer to the list ctrl
707 wxGenericListCtrl
*GetListCtrl() const
709 return wxStaticCast(GetParent(), wxGenericListCtrl
);
712 // get the height of all lines (assuming they all do have the same height)
713 wxCoord
GetLineHeight() const;
715 // get the y position of the given line (only for report view)
716 wxCoord
GetLineY(size_t line
) const;
718 // get the brush to use for the item highlighting
719 wxBrush
*GetHighlightBrush() const
721 return m_hasFocus
? m_highlightBrush
: m_highlightUnfocusedBrush
;
725 // the array of all line objects for a non virtual list control (for the
726 // virtual list control we only ever use m_lines[0])
727 wxListLineDataArray m_lines
;
729 // the list of column objects
730 wxListHeaderDataList m_columns
;
732 // currently focused item or -1
735 // the number of lines per page
738 // this flag is set when something which should result in the window
739 // redrawing happens (i.e. an item was added or deleted, or its appearance
740 // changed) and OnPaint() doesn't redraw the window while it is set which
741 // allows to minimize the number of repaintings when a lot of items are
742 // being added. The real repainting occurs only after the next OnIdle()
746 wxColour
*m_highlightColour
;
747 wxImageList
*m_small_image_list
;
748 wxImageList
*m_normal_image_list
;
750 int m_normal_spacing
;
754 wxTimer
*m_renameTimer
;
758 ColWidthArray m_aColWidths
;
760 // for double click logic
761 size_t m_lineLastClicked
,
762 m_lineBeforeLastClicked
,
763 m_lineSelectSingleOnUp
;
766 wxWindow
*GetMainWindowOfCompositeControl() { return GetParent(); }
768 // the total count of items in a virtual list control
771 // the object maintaining the items selection state, only used in virtual
773 wxSelectionStore m_selStore
;
775 // common part of all ctors
778 // get the line data for the given index
779 wxListLineData
*GetLine(size_t n
) const
781 wxASSERT_MSG( n
!= (size_t)-1, _T("invalid line index") );
785 wxConstCast(this, wxListMainWindow
)->CacheLineData(n
);
792 // get a dummy line which can be used for geometry calculations and such:
793 // you must use GetLine() if you want to really draw the line
794 wxListLineData
*GetDummyLine() const;
796 // cache the line data of the n-th line in m_lines[0]
797 void CacheLineData(size_t line
);
799 // get the range of visible lines
800 void GetVisibleLinesRange(size_t *from
, size_t *to
);
802 // force us to recalculate the range of visible lines
803 void ResetVisibleLinesRange() { m_lineFrom
= (size_t)-1; }
805 // get the colour to be used for drawing the rules
806 wxColour
GetRuleColour() const
808 return wxSystemSettings::GetColour(wxSYS_COLOUR_3DLIGHT
);
812 // initialize the current item if needed
813 void UpdateCurrent();
815 // delete all items but don't refresh: called from dtor
816 void DoDeleteAllItems();
818 // the height of one line using the current font
819 wxCoord m_lineHeight
;
821 // the total header width or 0 if not calculated yet
822 wxCoord m_headerWidth
;
824 // the first and last lines being shown on screen right now (inclusive),
825 // both may be -1 if they must be calculated so never access them directly:
826 // use GetVisibleLinesRange() above instead
830 // the brushes to use for item highlighting when we do/don't have focus
831 wxBrush
*m_highlightBrush
,
832 *m_highlightUnfocusedBrush
;
834 // if this is > 0, the control is frozen and doesn't redraw itself
835 size_t m_freezeCount
;
837 // wrapper around the text control currently used for in place editing or
838 // NULL if no item is being edited
839 wxListTextCtrlWrapper
*m_textctrlWrapper
;
842 DECLARE_DYNAMIC_CLASS(wxListMainWindow
)
843 DECLARE_EVENT_TABLE()
845 friend class wxGenericListCtrl
;
849 wxListItemData::~wxListItemData()
851 // in the virtual list control the attributes are managed by the main
852 // program, so don't delete them
853 if ( !m_owner
->IsVirtual() )
859 void wxListItemData::Init()
867 wxListItemData::wxListItemData(wxListMainWindow
*owner
)
873 if ( owner
->InReportView() )
879 void wxListItemData::SetItem( const wxListItem
&info
)
881 if ( info
.m_mask
& wxLIST_MASK_TEXT
)
882 SetText(info
.m_text
);
883 if ( info
.m_mask
& wxLIST_MASK_IMAGE
)
884 m_image
= info
.m_image
;
885 if ( info
.m_mask
& wxLIST_MASK_DATA
)
886 m_data
= info
.m_data
;
888 if ( info
.HasAttributes() )
891 m_attr
->AssignFrom(*info
.GetAttributes());
893 m_attr
= new wxListItemAttr(*info
.GetAttributes());
901 m_rect
->width
= info
.m_width
;
905 void wxListItemData::SetPosition( int x
, int y
)
907 wxCHECK_RET( m_rect
, _T("unexpected SetPosition() call") );
913 void wxListItemData::SetSize( int width
, int height
)
915 wxCHECK_RET( m_rect
, _T("unexpected SetSize() call") );
918 m_rect
->width
= width
;
920 m_rect
->height
= height
;
923 bool wxListItemData::IsHit( int x
, int y
) const
925 wxCHECK_MSG( m_rect
, false, _T("can't be called in this mode") );
927 return wxRect(GetX(), GetY(), GetWidth(), GetHeight()).Contains(x
, y
);
930 int wxListItemData::GetX() const
932 wxCHECK_MSG( m_rect
, 0, _T("can't be called in this mode") );
937 int wxListItemData::GetY() const
939 wxCHECK_MSG( m_rect
, 0, _T("can't be called in this mode") );
944 int wxListItemData::GetWidth() const
946 wxCHECK_MSG( m_rect
, 0, _T("can't be called in this mode") );
948 return m_rect
->width
;
951 int wxListItemData::GetHeight() const
953 wxCHECK_MSG( m_rect
, 0, _T("can't be called in this mode") );
955 return m_rect
->height
;
958 void wxListItemData::GetItem( wxListItem
&info
) const
960 long mask
= info
.m_mask
;
962 // by default, get everything for backwards compatibility
965 if ( mask
& wxLIST_MASK_TEXT
)
966 info
.m_text
= m_text
;
967 if ( mask
& wxLIST_MASK_IMAGE
)
968 info
.m_image
= m_image
;
969 if ( mask
& wxLIST_MASK_DATA
)
970 info
.m_data
= m_data
;
974 if ( m_attr
->HasTextColour() )
975 info
.SetTextColour(m_attr
->GetTextColour());
976 if ( m_attr
->HasBackgroundColour() )
977 info
.SetBackgroundColour(m_attr
->GetBackgroundColour());
978 if ( m_attr
->HasFont() )
979 info
.SetFont(m_attr
->GetFont());
983 //-----------------------------------------------------------------------------
985 //-----------------------------------------------------------------------------
987 void wxListHeaderData::Init()
998 wxListHeaderData::wxListHeaderData()
1003 wxListHeaderData::wxListHeaderData( const wxListItem
&item
)
1010 void wxListHeaderData::SetItem( const wxListItem
&item
)
1012 m_mask
= item
.m_mask
;
1014 if ( m_mask
& wxLIST_MASK_TEXT
)
1015 m_text
= item
.m_text
;
1017 if ( m_mask
& wxLIST_MASK_IMAGE
)
1018 m_image
= item
.m_image
;
1020 if ( m_mask
& wxLIST_MASK_FORMAT
)
1021 m_format
= item
.m_format
;
1023 if ( m_mask
& wxLIST_MASK_WIDTH
)
1024 SetWidth(item
.m_width
);
1027 void wxListHeaderData::SetPosition( int x
, int y
)
1033 void wxListHeaderData::SetHeight( int h
)
1038 void wxListHeaderData::SetWidth( int w
)
1040 m_width
= w
< 0 ? WIDTH_COL_DEFAULT
: w
;
1043 void wxListHeaderData::SetFormat( int format
)
1048 bool wxListHeaderData::HasImage() const
1050 return m_image
!= -1;
1053 bool wxListHeaderData::IsHit( int x
, int y
) const
1055 return ((x
>= m_xpos
) && (x
<= m_xpos
+m_width
) && (y
>= m_ypos
) && (y
<= m_ypos
+m_height
));
1058 void wxListHeaderData::GetItem( wxListItem
& item
)
1060 item
.m_mask
= m_mask
;
1061 item
.m_text
= m_text
;
1062 item
.m_image
= m_image
;
1063 item
.m_format
= m_format
;
1064 item
.m_width
= m_width
;
1067 int wxListHeaderData::GetImage() const
1072 int wxListHeaderData::GetWidth() const
1077 int wxListHeaderData::GetFormat() const
1082 //-----------------------------------------------------------------------------
1084 //-----------------------------------------------------------------------------
1086 inline int wxListLineData::GetMode() const
1088 return m_owner
->GetListCtrl()->GetWindowStyleFlag() & wxLC_MASK_TYPE
;
1091 inline bool wxListLineData::InReportView() const
1093 return m_owner
->HasFlag(wxLC_REPORT
);
1096 inline bool wxListLineData::IsVirtual() const
1098 return m_owner
->IsVirtual();
1101 wxListLineData::wxListLineData( wxListMainWindow
*owner
)
1105 if ( InReportView() )
1108 m_gi
= new GeometryInfo
;
1110 m_highlighted
= false;
1112 InitItems( GetMode() == wxLC_REPORT
? m_owner
->GetColumnCount() : 1 );
1115 void wxListLineData::CalculateSize( wxDC
*dc
, int spacing
)
1117 wxListItemDataList::compatibility_iterator node
= m_items
.GetFirst();
1118 wxCHECK_RET( node
, _T("no subitems at all??") );
1120 wxListItemData
*item
= node
->GetData();
1125 switch ( GetMode() )
1128 case wxLC_SMALL_ICON
:
1129 m_gi
->m_rectAll
.width
= spacing
;
1131 s
= item
->GetText();
1136 m_gi
->m_rectLabel
.width
=
1137 m_gi
->m_rectLabel
.height
= 0;
1141 dc
->GetTextExtent( s
, &lw
, &lh
);
1145 m_gi
->m_rectAll
.height
= spacing
+ lh
;
1147 m_gi
->m_rectAll
.width
= lw
;
1149 m_gi
->m_rectLabel
.width
= lw
;
1150 m_gi
->m_rectLabel
.height
= lh
;
1153 if (item
->HasImage())
1156 m_owner
->GetImageSize( item
->GetImage(), w
, h
);
1157 m_gi
->m_rectIcon
.width
= w
+ 8;
1158 m_gi
->m_rectIcon
.height
= h
+ 8;
1160 if ( m_gi
->m_rectIcon
.width
> m_gi
->m_rectAll
.width
)
1161 m_gi
->m_rectAll
.width
= m_gi
->m_rectIcon
.width
;
1162 if ( m_gi
->m_rectIcon
.height
+ lh
> m_gi
->m_rectAll
.height
- 4 )
1163 m_gi
->m_rectAll
.height
= m_gi
->m_rectIcon
.height
+ lh
+ 4;
1166 if ( item
->HasText() )
1168 m_gi
->m_rectHighlight
.width
= m_gi
->m_rectLabel
.width
;
1169 m_gi
->m_rectHighlight
.height
= m_gi
->m_rectLabel
.height
;
1171 else // no text, highlight the icon
1173 m_gi
->m_rectHighlight
.width
= m_gi
->m_rectIcon
.width
;
1174 m_gi
->m_rectHighlight
.height
= m_gi
->m_rectIcon
.height
;
1179 s
= item
->GetTextForMeasuring();
1181 dc
->GetTextExtent( s
, &lw
, &lh
);
1185 m_gi
->m_rectLabel
.width
= lw
;
1186 m_gi
->m_rectLabel
.height
= lh
;
1188 m_gi
->m_rectAll
.width
= lw
;
1189 m_gi
->m_rectAll
.height
= lh
;
1191 if (item
->HasImage())
1194 m_owner
->GetImageSize( item
->GetImage(), w
, h
);
1195 m_gi
->m_rectIcon
.width
= w
;
1196 m_gi
->m_rectIcon
.height
= h
;
1198 m_gi
->m_rectAll
.width
+= 4 + w
;
1199 if (h
> m_gi
->m_rectAll
.height
)
1200 m_gi
->m_rectAll
.height
= h
;
1203 m_gi
->m_rectHighlight
.width
= m_gi
->m_rectAll
.width
;
1204 m_gi
->m_rectHighlight
.height
= m_gi
->m_rectAll
.height
;
1208 wxFAIL_MSG( _T("unexpected call to SetSize") );
1212 wxFAIL_MSG( _T("unknown mode") );
1217 void wxListLineData::SetPosition( int x
, int y
, int spacing
)
1219 wxListItemDataList::compatibility_iterator node
= m_items
.GetFirst();
1220 wxCHECK_RET( node
, _T("no subitems at all??") );
1222 wxListItemData
*item
= node
->GetData();
1224 switch ( GetMode() )
1227 case wxLC_SMALL_ICON
:
1228 m_gi
->m_rectAll
.x
= x
;
1229 m_gi
->m_rectAll
.y
= y
;
1231 if ( item
->HasImage() )
1233 m_gi
->m_rectIcon
.x
= m_gi
->m_rectAll
.x
+ 4 +
1234 (m_gi
->m_rectAll
.width
- m_gi
->m_rectIcon
.width
) / 2;
1235 m_gi
->m_rectIcon
.y
= m_gi
->m_rectAll
.y
+ 4;
1238 if ( item
->HasText() )
1240 if (m_gi
->m_rectAll
.width
> spacing
)
1241 m_gi
->m_rectLabel
.x
= m_gi
->m_rectAll
.x
+ 2;
1243 m_gi
->m_rectLabel
.x
= m_gi
->m_rectAll
.x
+ 2 + (spacing
/ 2) - (m_gi
->m_rectLabel
.width
/ 2);
1244 m_gi
->m_rectLabel
.y
= m_gi
->m_rectAll
.y
+ m_gi
->m_rectAll
.height
+ 2 - m_gi
->m_rectLabel
.height
;
1245 m_gi
->m_rectHighlight
.x
= m_gi
->m_rectLabel
.x
- 2;
1246 m_gi
->m_rectHighlight
.y
= m_gi
->m_rectLabel
.y
- 2;
1248 else // no text, highlight the icon
1250 m_gi
->m_rectHighlight
.x
= m_gi
->m_rectIcon
.x
- 4;
1251 m_gi
->m_rectHighlight
.y
= m_gi
->m_rectIcon
.y
- 4;
1256 m_gi
->m_rectAll
.x
= x
;
1257 m_gi
->m_rectAll
.y
= y
;
1259 m_gi
->m_rectHighlight
.x
= m_gi
->m_rectAll
.x
;
1260 m_gi
->m_rectHighlight
.y
= m_gi
->m_rectAll
.y
;
1261 m_gi
->m_rectLabel
.y
= m_gi
->m_rectAll
.y
+ 2;
1263 if (item
->HasImage())
1265 m_gi
->m_rectIcon
.x
= m_gi
->m_rectAll
.x
+ 2;
1266 m_gi
->m_rectIcon
.y
= m_gi
->m_rectAll
.y
+ 2;
1267 m_gi
->m_rectLabel
.x
= m_gi
->m_rectAll
.x
+ 6 + m_gi
->m_rectIcon
.width
;
1271 m_gi
->m_rectLabel
.x
= m_gi
->m_rectAll
.x
+ 2;
1276 wxFAIL_MSG( _T("unexpected call to SetPosition") );
1280 wxFAIL_MSG( _T("unknown mode") );
1285 void wxListLineData::InitItems( int num
)
1287 for (int i
= 0; i
< num
; i
++)
1288 m_items
.Append( new wxListItemData(m_owner
) );
1291 void wxListLineData::SetItem( int index
, const wxListItem
&info
)
1293 wxListItemDataList::compatibility_iterator node
= m_items
.Item( index
);
1294 wxCHECK_RET( node
, _T("invalid column index in SetItem") );
1296 wxListItemData
*item
= node
->GetData();
1297 item
->SetItem( info
);
1300 void wxListLineData::GetItem( int index
, wxListItem
&info
)
1302 wxListItemDataList::compatibility_iterator node
= m_items
.Item( index
);
1305 wxListItemData
*item
= node
->GetData();
1306 item
->GetItem( info
);
1310 wxString
wxListLineData::GetText(int index
) const
1314 wxListItemDataList::compatibility_iterator node
= m_items
.Item( index
);
1317 wxListItemData
*item
= node
->GetData();
1318 s
= item
->GetText();
1324 void wxListLineData::SetText( int index
, const wxString
& s
)
1326 wxListItemDataList::compatibility_iterator node
= m_items
.Item( index
);
1329 wxListItemData
*item
= node
->GetData();
1334 void wxListLineData::SetImage( int index
, int image
)
1336 wxListItemDataList::compatibility_iterator node
= m_items
.Item( index
);
1337 wxCHECK_RET( node
, _T("invalid column index in SetImage()") );
1339 wxListItemData
*item
= node
->GetData();
1340 item
->SetImage(image
);
1343 int wxListLineData::GetImage( int index
) const
1345 wxListItemDataList::compatibility_iterator node
= m_items
.Item( index
);
1346 wxCHECK_MSG( node
, -1, _T("invalid column index in GetImage()") );
1348 wxListItemData
*item
= node
->GetData();
1349 return item
->GetImage();
1352 wxListItemAttr
*wxListLineData::GetAttr() const
1354 wxListItemDataList::compatibility_iterator node
= m_items
.GetFirst();
1355 wxCHECK_MSG( node
, NULL
, _T("invalid column index in GetAttr()") );
1357 wxListItemData
*item
= node
->GetData();
1358 return item
->GetAttr();
1361 void wxListLineData::SetAttr(wxListItemAttr
*attr
)
1363 wxListItemDataList::compatibility_iterator node
= m_items
.GetFirst();
1364 wxCHECK_RET( node
, _T("invalid column index in SetAttr()") );
1366 wxListItemData
*item
= node
->GetData();
1367 item
->SetAttr(attr
);
1370 bool wxListLineData::SetAttributes(wxDC
*dc
,
1371 const wxListItemAttr
*attr
,
1374 wxWindow
*listctrl
= m_owner
->GetParent();
1378 // don't use foreground colour for drawing highlighted items - this might
1379 // make them completely invisible (and there is no way to do bit
1380 // arithmetics on wxColour, unfortunately)
1386 colText
= wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHTTEXT
);
1388 else if ( attr
&& attr
->HasTextColour() )
1389 colText
= attr
->GetTextColour();
1391 colText
= listctrl
->GetForegroundColour();
1393 dc
->SetTextForeground(colText
);
1397 if ( attr
&& attr
->HasFont() )
1398 font
= attr
->GetFont();
1400 font
= listctrl
->GetFont();
1405 bool hasBgCol
= attr
&& attr
->HasBackgroundColour();
1406 if ( highlighted
|| hasBgCol
)
1409 dc
->SetBrush( *m_owner
->GetHighlightBrush() );
1411 dc
->SetBrush(wxBrush(attr
->GetBackgroundColour(), wxSOLID
));
1413 dc
->SetPen( *wxTRANSPARENT_PEN
);
1421 void wxListLineData::Draw( wxDC
*dc
)
1423 wxListItemDataList::compatibility_iterator node
= m_items
.GetFirst();
1424 wxCHECK_RET( node
, _T("no subitems at all??") );
1426 bool highlighted
= IsHighlighted();
1428 wxListItemAttr
*attr
= GetAttr();
1430 if ( SetAttributes(dc
, attr
, highlighted
) )
1431 dc
->DrawRectangle( m_gi
->m_rectHighlight
);
1433 // just for debugging to better see where the items are
1435 dc
->SetPen(*wxRED_PEN
);
1436 dc
->SetBrush(*wxTRANSPARENT_BRUSH
);
1437 dc
->DrawRectangle( m_gi
->m_rectAll
);
1438 dc
->SetPen(*wxGREEN_PEN
);
1439 dc
->DrawRectangle( m_gi
->m_rectIcon
);
1442 wxListItemData
*item
= node
->GetData();
1443 if (item
->HasImage())
1445 // centre the image inside our rectangle, this looks nicer when items
1446 // ae aligned in a row
1447 const wxRect
& rectIcon
= m_gi
->m_rectIcon
;
1449 m_owner
->DrawImage(item
->GetImage(), dc
, rectIcon
.x
, rectIcon
.y
);
1452 if (item
->HasText())
1454 const wxRect
& rectLabel
= m_gi
->m_rectLabel
;
1456 wxDCClipper
clipper(*dc
, rectLabel
);
1457 dc
->DrawText(item
->GetText(), rectLabel
.x
, rectLabel
.y
);
1461 void wxListLineData::DrawInReportMode( wxDC
*dc
,
1463 const wxRect
& rectHL
,
1466 // TODO: later we should support setting different attributes for
1467 // different columns - to do it, just add "col" argument to
1468 // GetAttr() and move these lines into the loop below
1469 wxListItemAttr
*attr
= GetAttr();
1470 if ( SetAttributes(dc
, attr
, highlighted
) )
1471 dc
->DrawRectangle( rectHL
);
1473 wxCoord x
= rect
.x
+ HEADER_OFFSET_X
,
1474 yMid
= rect
.y
+ rect
.height
/2;
1477 for ( wxListItemDataList::compatibility_iterator node
= m_items
.GetFirst();
1479 node
= node
->GetNext(), col
++ )
1481 wxListItemData
*item
= node
->GetData();
1483 int width
= m_owner
->GetColumnWidth(col
);
1487 if ( item
->HasImage() )
1490 m_owner
->GetImageSize( item
->GetImage(), ix
, iy
);
1491 m_owner
->DrawImage( item
->GetImage(), dc
, xOld
, yMid
- iy
/2 );
1493 ix
+= IMAGE_MARGIN_IN_REPORT_MODE
;
1499 if ( item
->HasText() )
1500 DrawTextFormatted(dc
, item
->GetText(), col
, xOld
, yMid
, width
- 8);
1504 void wxListLineData::DrawTextFormatted(wxDC
*dc
,
1505 const wxString
&text
,
1512 dc
->GetTextExtent(text
, &w
, &h
);
1514 const wxCoord y
= yMid
- (h
+ 1)/2;
1516 wxDCClipper
clipper(*dc
, x
, y
, width
, h
);
1518 // determine if the string can fit inside the current width
1521 // it can, draw it using the items alignment
1523 m_owner
->GetColumn(col
, item
);
1524 switch ( item
.GetAlign() )
1526 case wxLIST_FORMAT_LEFT
:
1530 case wxLIST_FORMAT_RIGHT
:
1534 case wxLIST_FORMAT_CENTER
:
1535 x
+= (width
- w
) / 2;
1539 wxFAIL_MSG( _T("unknown list item format") );
1543 dc
->DrawText(text
, x
, y
);
1545 else // otherwise, truncate and add an ellipsis if possible
1547 // determine the base width
1548 wxString
ellipsis(wxT("..."));
1550 dc
->GetTextExtent(ellipsis
, &base_w
, &h
);
1552 // continue until we have enough space or only one character left
1554 size_t len
= text
.length();
1555 wxString drawntext
= text
.Left(len
);
1558 dc
->GetTextExtent(drawntext
.Last(), &w_c
, &h_c
);
1559 drawntext
.RemoveLast();
1562 if (w
+ base_w
<= width
)
1566 // if still not enough space, remove ellipsis characters
1567 while (ellipsis
.length() > 0 && w
+ base_w
> width
)
1569 ellipsis
= ellipsis
.Left(ellipsis
.length() - 1);
1570 dc
->GetTextExtent(ellipsis
, &base_w
, &h
);
1573 // now draw the text
1574 dc
->DrawText(drawntext
, x
, y
);
1575 dc
->DrawText(ellipsis
, x
+ w
, y
);
1579 bool wxListLineData::Highlight( bool on
)
1581 wxCHECK_MSG( !IsVirtual(), false, _T("unexpected call to Highlight") );
1583 if ( on
== m_highlighted
)
1591 void wxListLineData::ReverseHighlight( void )
1593 Highlight(!IsHighlighted());
1596 //-----------------------------------------------------------------------------
1597 // wxListHeaderWindow
1598 //-----------------------------------------------------------------------------
1600 IMPLEMENT_DYNAMIC_CLASS(wxListHeaderWindow
,wxWindow
)
1602 BEGIN_EVENT_TABLE(wxListHeaderWindow
,wxWindow
)
1603 EVT_PAINT (wxListHeaderWindow::OnPaint
)
1604 EVT_MOUSE_EVENTS (wxListHeaderWindow::OnMouse
)
1605 EVT_SET_FOCUS (wxListHeaderWindow::OnSetFocus
)
1608 void wxListHeaderWindow::Init()
1610 m_currentCursor
= (wxCursor
*) NULL
;
1611 m_isDragging
= false;
1615 wxListHeaderWindow::wxListHeaderWindow()
1619 m_owner
= (wxListMainWindow
*) NULL
;
1620 m_resizeCursor
= (wxCursor
*) NULL
;
1623 wxListHeaderWindow::wxListHeaderWindow( wxWindow
*win
,
1625 wxListMainWindow
*owner
,
1629 const wxString
&name
)
1630 : wxWindow( win
, id
, pos
, size
, style
, name
)
1635 m_resizeCursor
= new wxCursor( wxCURSOR_SIZEWE
);
1638 wxVisualAttributes attr
= wxPanel::GetClassDefaultAttributes();
1639 SetOwnForegroundColour( attr
.colFg
);
1640 SetOwnBackgroundColour( attr
.colBg
);
1642 SetOwnFont( attr
.font
);
1644 SetOwnForegroundColour( wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT
));
1645 SetOwnBackgroundColour( wxSystemSettings::GetColour(wxSYS_COLOUR_BTNFACE
));
1647 SetOwnFont( wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT
));
1651 wxListHeaderWindow::~wxListHeaderWindow()
1653 delete m_resizeCursor
;
1656 #ifdef __WXUNIVERSAL__
1657 #include "wx/univ/renderer.h"
1658 #include "wx/univ/theme.h"
1661 // shift the DC origin to match the position of the main window horz
1662 // scrollbar: this allows us to always use logical coords
1663 void wxListHeaderWindow::AdjustDC(wxDC
& dc
)
1666 m_owner
->GetScrollPixelsPerUnit( &xpix
, NULL
);
1669 m_owner
->GetViewStart( &view_start
, NULL
);
1674 dc
.GetDeviceOrigin( &org_x
, &org_y
);
1676 // account for the horz scrollbar offset
1678 if (GetLayoutDirection() == wxLayout_RightToLeft
)
1680 // Maybe we just have to check for m_signX
1681 // in the DC, but I leave the #ifdef __WXGTK__
1683 dc
.SetDeviceOrigin( org_x
+ (view_start
* xpix
), org_y
);
1687 dc
.SetDeviceOrigin( org_x
- (view_start
* xpix
), org_y
);
1690 void wxListHeaderWindow::OnPaint( wxPaintEvent
&WXUNUSED(event
) )
1692 wxPaintDC
dc( this );
1697 dc
.SetFont( GetFont() );
1699 // width and height of the entire header window
1701 GetClientSize( &w
, &h
);
1702 m_owner
->CalcUnscrolledPosition(w
, 0, &w
, NULL
);
1704 dc
.SetBackgroundMode(wxTRANSPARENT
);
1705 dc
.SetTextForeground(GetForegroundColour());
1707 int x
= HEADER_OFFSET_X
;
1708 int numColumns
= m_owner
->GetColumnCount();
1710 for ( int i
= 0; i
< numColumns
&& x
< w
; i
++ )
1712 m_owner
->GetColumn( i
, item
);
1713 int wCol
= item
.m_width
;
1715 // the width of the rect to draw: make it smaller to fit entirely
1716 // inside the column rect
1725 wxRendererNative::Get().DrawHeaderButton
1729 wxRect(x
, HEADER_OFFSET_Y
, cw
, ch
),
1730 m_parent
->IsEnabled() ? 0
1731 : (int)wxCONTROL_DISABLED
1734 // see if we have enough space for the column label
1736 // for this we need the width of the text
1739 dc
.GetTextExtent(item
.GetText(), &wLabel
, &hLabel
);
1740 wLabel
+= 2 * EXTRA_WIDTH
;
1742 // and the width of the icon, if any
1743 static const int MARGIN_BETWEEN_TEXT_AND_ICON
= 2;
1744 int ix
= 0, iy
= 0; // init them just to suppress the compiler warnings
1745 const int image
= item
.m_image
;
1746 wxImageList
*imageList
;
1749 imageList
= m_owner
->m_small_image_list
;
1752 imageList
->GetSize(image
, ix
, iy
);
1753 wLabel
+= ix
+ MARGIN_BETWEEN_TEXT_AND_ICON
;
1761 // ignore alignment if there is not enough space anyhow
1763 switch ( wLabel
< cw
? item
.GetAlign() : wxLIST_FORMAT_LEFT
)
1766 wxFAIL_MSG( _T("unknown list item format") );
1769 case wxLIST_FORMAT_LEFT
:
1773 case wxLIST_FORMAT_RIGHT
:
1774 xAligned
= x
+ cw
- wLabel
;
1777 case wxLIST_FORMAT_CENTER
:
1778 xAligned
= x
+ (cw
- wLabel
) / 2;
1782 // if we have an image, draw it on the right of the label
1789 xAligned
+ wLabel
- ix
- MARGIN_BETWEEN_TEXT_AND_ICON
,
1790 HEADER_OFFSET_Y
+ (h
- 4 - iy
)/2,
1791 wxIMAGELIST_DRAW_TRANSPARENT
1794 cw
-= ix
+ MARGIN_BETWEEN_TEXT_AND_ICON
;
1797 // draw the text clipping it so that it doesn't overwrite the column
1799 wxDCClipper
clipper(dc
, x
, HEADER_OFFSET_Y
, cw
, h
- 4 );
1801 dc
.DrawText( item
.GetText(),
1802 xAligned
+ EXTRA_WIDTH
, h
/ 2 - hLabel
/ 2 ); //HEADER_OFFSET_Y + EXTRA_HEIGHT );
1808 void wxListHeaderWindow::DrawCurrent()
1810 int x1
= m_currentX
;
1812 m_owner
->ClientToScreen( &x1
, &y1
);
1814 int x2
= m_currentX
;
1816 m_owner
->GetClientSize( NULL
, &y2
);
1817 m_owner
->ClientToScreen( &x2
, &y2
);
1820 dc
.SetLogicalFunction( wxINVERT
);
1821 dc
.SetPen( wxPen( *wxBLACK
, 2, wxSOLID
) );
1822 dc
.SetBrush( *wxTRANSPARENT_BRUSH
);
1826 dc
.DrawLine( x1
, y1
, x2
, y2
);
1828 dc
.SetLogicalFunction( wxCOPY
);
1830 dc
.SetPen( wxNullPen
);
1831 dc
.SetBrush( wxNullBrush
);
1834 void wxListHeaderWindow::OnMouse( wxMouseEvent
&event
)
1836 // we want to work with logical coords
1838 m_owner
->CalcUnscrolledPosition(event
.GetX(), 0, &x
, NULL
);
1839 int y
= event
.GetY();
1843 SendListEvent(wxEVT_COMMAND_LIST_COL_DRAGGING
, event
.GetPosition());
1845 // we don't draw the line beyond our window, but we allow dragging it
1848 GetClientSize( &w
, NULL
);
1849 m_owner
->CalcUnscrolledPosition(w
, 0, &w
, NULL
);
1852 // erase the line if it was drawn
1853 if ( m_currentX
< w
)
1856 if (event
.ButtonUp())
1859 m_isDragging
= false;
1861 m_owner
->SetColumnWidth( m_column
, m_currentX
- m_minX
);
1862 SendListEvent(wxEVT_COMMAND_LIST_COL_END_DRAG
, event
.GetPosition());
1869 m_currentX
= m_minX
+ 7;
1871 // draw in the new location
1872 if ( m_currentX
< w
)
1876 else // not dragging
1879 bool hit_border
= false;
1881 // end of the current column
1884 // find the column where this event occurred
1886 countCol
= m_owner
->GetColumnCount();
1887 for (col
= 0; col
< countCol
; col
++)
1889 xpos
+= m_owner
->GetColumnWidth( col
);
1892 if ( (abs(x
-xpos
) < 3) && (y
< 22) )
1894 // near the column border
1901 // inside the column
1908 if ( col
== countCol
)
1911 if (event
.LeftDown() || event
.RightUp())
1913 if (hit_border
&& event
.LeftDown())
1915 if ( SendListEvent(wxEVT_COMMAND_LIST_COL_BEGIN_DRAG
,
1916 event
.GetPosition()) )
1918 m_isDragging
= true;
1923 //else: column resizing was vetoed by the user code
1925 else // click on a column
1927 SendListEvent( event
.LeftDown()
1928 ? wxEVT_COMMAND_LIST_COL_CLICK
1929 : wxEVT_COMMAND_LIST_COL_RIGHT_CLICK
,
1930 event
.GetPosition());
1933 else if (event
.Moving())
1938 setCursor
= m_currentCursor
== wxSTANDARD_CURSOR
;
1939 m_currentCursor
= m_resizeCursor
;
1943 setCursor
= m_currentCursor
!= wxSTANDARD_CURSOR
;
1944 m_currentCursor
= wxSTANDARD_CURSOR
;
1948 SetCursor(*m_currentCursor
);
1953 void wxListHeaderWindow::OnSetFocus( wxFocusEvent
&WXUNUSED(event
) )
1955 m_owner
->SetFocus();
1959 bool wxListHeaderWindow::SendListEvent(wxEventType type
, const wxPoint
& pos
)
1961 wxWindow
*parent
= GetParent();
1962 wxListEvent
le( type
, parent
->GetId() );
1963 le
.SetEventObject( parent
);
1964 le
.m_pointDrag
= pos
;
1966 // the position should be relative to the parent window, not
1967 // this one for compatibility with MSW and common sense: the
1968 // user code doesn't know anything at all about this header
1969 // window, so why should it get positions relative to it?
1970 le
.m_pointDrag
.y
-= GetSize().y
;
1972 le
.m_col
= m_column
;
1973 return !parent
->GetEventHandler()->ProcessEvent( le
) || le
.IsAllowed();
1976 //-----------------------------------------------------------------------------
1977 // wxListRenameTimer (internal)
1978 //-----------------------------------------------------------------------------
1980 wxListRenameTimer::wxListRenameTimer( wxListMainWindow
*owner
)
1985 void wxListRenameTimer::Notify()
1987 m_owner
->OnRenameTimer();
1990 //-----------------------------------------------------------------------------
1991 // wxListTextCtrlWrapper (internal)
1992 //-----------------------------------------------------------------------------
1994 BEGIN_EVENT_TABLE(wxListTextCtrlWrapper
, wxEvtHandler
)
1995 EVT_CHAR (wxListTextCtrlWrapper::OnChar
)
1996 EVT_KEY_UP (wxListTextCtrlWrapper::OnKeyUp
)
1997 EVT_KILL_FOCUS (wxListTextCtrlWrapper::OnKillFocus
)
2000 wxListTextCtrlWrapper::wxListTextCtrlWrapper(wxListMainWindow
*owner
,
2003 : m_startValue(owner
->GetItemText(itemEdit
)),
2004 m_itemEdited(itemEdit
)
2009 m_aboutToFinish
= false;
2011 wxRect rectLabel
= owner
->GetLineLabelRect(itemEdit
);
2013 m_owner
->CalcScrolledPosition(rectLabel
.x
, rectLabel
.y
,
2014 &rectLabel
.x
, &rectLabel
.y
);
2016 m_text
->Create(owner
, wxID_ANY
, m_startValue
,
2017 wxPoint(rectLabel
.x
-4,rectLabel
.y
-4),
2018 wxSize(rectLabel
.width
+11,rectLabel
.height
+8));
2021 m_text
->PushEventHandler(this);
2024 void wxListTextCtrlWrapper::Finish()
2030 m_text
->RemoveEventHandler(this);
2031 m_owner
->FinishEditing(m_text
);
2033 wxPendingDelete
.Append( this );
2037 bool wxListTextCtrlWrapper::AcceptChanges()
2039 const wxString value
= m_text
->GetValue();
2041 if ( value
== m_startValue
)
2042 // nothing changed, always accept
2045 if ( !m_owner
->OnRenameAccept(m_itemEdited
, value
) )
2046 // vetoed by the user
2049 // accepted, do rename the item
2050 m_owner
->SetItemText(m_itemEdited
, value
);
2055 void wxListTextCtrlWrapper::AcceptChangesAndFinish()
2057 m_aboutToFinish
= true;
2059 // Notify the owner about the changes
2062 // Even if vetoed, close the control (consistent with MSW)
2066 void wxListTextCtrlWrapper::OnChar( wxKeyEvent
&event
)
2068 switch ( event
.m_keyCode
)
2071 AcceptChangesAndFinish();
2075 m_owner
->OnRenameCancelled( m_itemEdited
);
2084 void wxListTextCtrlWrapper::OnKeyUp( wxKeyEvent
&event
)
2092 // auto-grow the textctrl:
2093 wxSize parentSize
= m_owner
->GetSize();
2094 wxPoint myPos
= m_text
->GetPosition();
2095 wxSize mySize
= m_text
->GetSize();
2097 m_text
->GetTextExtent(m_text
->GetValue() + _T("MM"), &sx
, &sy
);
2098 if (myPos
.x
+ sx
> parentSize
.x
)
2099 sx
= parentSize
.x
- myPos
.x
;
2102 m_text
->SetSize(sx
, wxDefaultCoord
);
2107 void wxListTextCtrlWrapper::OnKillFocus( wxFocusEvent
&event
)
2109 if ( !m_finished
&& !m_aboutToFinish
)
2111 if ( !AcceptChanges() )
2112 m_owner
->OnRenameCancelled( m_itemEdited
);
2117 // We must let the native text control handle focus
2121 //-----------------------------------------------------------------------------
2123 //-----------------------------------------------------------------------------
2125 IMPLEMENT_DYNAMIC_CLASS(wxListMainWindow
,wxScrolledWindow
)
2127 BEGIN_EVENT_TABLE(wxListMainWindow
,wxScrolledWindow
)
2128 EVT_PAINT (wxListMainWindow::OnPaint
)
2129 EVT_MOUSE_EVENTS (wxListMainWindow::OnMouse
)
2130 EVT_CHAR (wxListMainWindow::OnChar
)
2131 EVT_KEY_DOWN (wxListMainWindow::OnKeyDown
)
2132 EVT_SET_FOCUS (wxListMainWindow::OnSetFocus
)
2133 EVT_KILL_FOCUS (wxListMainWindow::OnKillFocus
)
2134 EVT_SCROLLWIN (wxListMainWindow::OnScroll
)
2137 void wxListMainWindow::Init()
2142 m_lineTo
= (size_t)-1;
2148 m_small_image_list
= (wxImageList
*) NULL
;
2149 m_normal_image_list
= (wxImageList
*) NULL
;
2151 m_small_spacing
= 30;
2152 m_normal_spacing
= 40;
2156 m_isCreated
= false;
2158 m_lastOnSame
= false;
2159 m_renameTimer
= new wxListRenameTimer( this );
2160 m_textctrlWrapper
= NULL
;
2164 m_lineSelectSingleOnUp
=
2165 m_lineBeforeLastClicked
= (size_t)-1;
2170 wxListMainWindow::wxListMainWindow()
2175 m_highlightUnfocusedBrush
= (wxBrush
*) NULL
;
2178 wxListMainWindow::wxListMainWindow( wxWindow
*parent
,
2183 const wxString
&name
)
2184 : wxScrolledWindow( parent
, id
, pos
, size
,
2185 style
| wxHSCROLL
| wxVSCROLL
, name
)
2191 // OS X sel item highlight color differs from text highlight color, which is
2192 // what wxSYS_COLOUR_HIGHLIGHT returns.
2194 GetThemeBrushAsColor(kThemeBrushAlternatePrimaryHighlightColor
, 32, true, &hilight
);
2195 m_highlightBrush
= new wxBrush( wxColour(hilight
.red
, hilight
.green
, hilight
.blue
), wxSOLID
);
2197 m_highlightBrush
= new wxBrush
2199 wxSystemSettings::GetColour
2201 wxSYS_COLOUR_HIGHLIGHT
2208 // on Mac, this color also differs from the wxSYS_COLOUR_BTNSHADOW, enough to be noticable.
2209 // I don't know if BTNSHADOW is appropriate in other contexts, so I'm just changing it here.
2210 GetThemeBrushAsColor(kThemeBrushSecondaryHighlightColor
, 32, true, &hilight
);
2211 m_highlightUnfocusedBrush
= new wxBrush( wxColour(hilight
.red
, hilight
.green
, hilight
.blue
), wxSOLID
);
2213 m_highlightUnfocusedBrush
= new wxBrush
2215 wxSystemSettings::GetColour
2217 wxSYS_COLOUR_BTNSHADOW
2223 SetScrollbars( 0, 0, 0, 0, 0, 0 );
2225 wxVisualAttributes attr
= wxGenericListCtrl::GetClassDefaultAttributes();
2226 SetOwnForegroundColour( attr
.colFg
);
2227 SetOwnBackgroundColour( attr
.colBg
);
2229 SetOwnFont( attr
.font
);
2232 wxListMainWindow::~wxListMainWindow()
2235 WX_CLEAR_LIST(wxListHeaderDataList
, m_columns
);
2236 WX_CLEAR_ARRAY(m_aColWidths
);
2238 delete m_highlightBrush
;
2239 delete m_highlightUnfocusedBrush
;
2240 delete m_renameTimer
;
2243 void wxListMainWindow::CacheLineData(size_t line
)
2245 wxGenericListCtrl
*listctrl
= GetListCtrl();
2247 wxListLineData
*ld
= GetDummyLine();
2249 size_t countCol
= GetColumnCount();
2250 for ( size_t col
= 0; col
< countCol
; col
++ )
2252 ld
->SetText(col
, listctrl
->OnGetItemText(line
, col
));
2253 ld
->SetImage(col
, listctrl
->OnGetItemColumnImage(line
, col
));
2256 ld
->SetAttr(listctrl
->OnGetItemAttr(line
));
2259 wxListLineData
*wxListMainWindow::GetDummyLine() const
2261 wxASSERT_MSG( !IsEmpty(), _T("invalid line index") );
2262 wxASSERT_MSG( IsVirtual(), _T("GetDummyLine() shouldn't be called") );
2264 wxListMainWindow
*self
= wxConstCast(this, wxListMainWindow
);
2266 // we need to recreate the dummy line if the number of columns in the
2267 // control changed as it would have the incorrect number of fields
2269 if ( !m_lines
.IsEmpty() &&
2270 m_lines
[0].m_items
.GetCount() != (size_t)GetColumnCount() )
2272 self
->m_lines
.Clear();
2275 if ( m_lines
.IsEmpty() )
2277 wxListLineData
*line
= new wxListLineData(self
);
2278 self
->m_lines
.Add(line
);
2280 // don't waste extra memory -- there never going to be anything
2281 // else/more in this array
2282 self
->m_lines
.Shrink();
2288 // ----------------------------------------------------------------------------
2289 // line geometry (report mode only)
2290 // ----------------------------------------------------------------------------
2292 wxCoord
wxListMainWindow::GetLineHeight() const
2294 // we cache the line height as calling GetTextExtent() is slow
2295 if ( !m_lineHeight
)
2297 wxListMainWindow
*self
= wxConstCast(this, wxListMainWindow
);
2299 wxClientDC
dc( self
);
2300 dc
.SetFont( GetFont() );
2303 dc
.GetTextExtent(_T("H"), NULL
, &y
);
2305 if ( m_small_image_list
&& m_small_image_list
->GetImageCount() )
2308 m_small_image_list
->GetSize(0, iw
, ih
);
2313 self
->m_lineHeight
= y
+ LINE_SPACING
;
2316 return m_lineHeight
;
2319 wxCoord
wxListMainWindow::GetLineY(size_t line
) const
2321 wxASSERT_MSG( InReportView(), _T("only works in report mode") );
2323 return LINE_SPACING
+ line
* GetLineHeight();
2326 wxRect
wxListMainWindow::GetLineRect(size_t line
) const
2328 if ( !InReportView() )
2329 return GetLine(line
)->m_gi
->m_rectAll
;
2332 rect
.x
= HEADER_OFFSET_X
;
2333 rect
.y
= GetLineY(line
);
2334 rect
.width
= GetHeaderWidth();
2335 rect
.height
= GetLineHeight();
2340 wxRect
wxListMainWindow::GetLineLabelRect(size_t line
) const
2342 if ( !InReportView() )
2343 return GetLine(line
)->m_gi
->m_rectLabel
;
2346 rect
.x
= HEADER_OFFSET_X
;
2347 rect
.y
= GetLineY(line
);
2348 rect
.width
= GetColumnWidth(0);
2349 rect
.height
= GetLineHeight();
2354 wxRect
wxListMainWindow::GetLineIconRect(size_t line
) const
2356 if ( !InReportView() )
2357 return GetLine(line
)->m_gi
->m_rectIcon
;
2359 wxListLineData
*ld
= GetLine(line
);
2360 wxASSERT_MSG( ld
->HasImage(), _T("should have an image") );
2363 rect
.x
= HEADER_OFFSET_X
;
2364 rect
.y
= GetLineY(line
);
2365 GetImageSize(ld
->GetImage(), rect
.width
, rect
.height
);
2370 wxRect
wxListMainWindow::GetLineHighlightRect(size_t line
) const
2372 return InReportView() ? GetLineRect(line
)
2373 : GetLine(line
)->m_gi
->m_rectHighlight
;
2376 long wxListMainWindow::HitTestLine(size_t line
, int x
, int y
) const
2378 wxASSERT_MSG( line
< GetItemCount(), _T("invalid line in HitTestLine") );
2380 wxListLineData
*ld
= GetLine(line
);
2382 if ( ld
->HasImage() && GetLineIconRect(line
).Contains(x
, y
) )
2383 return wxLIST_HITTEST_ONITEMICON
;
2385 // VS: Testing for "ld->HasText() || InReportView()" instead of
2386 // "ld->HasText()" is needed to make empty lines in report view
2388 if ( ld
->HasText() || InReportView() )
2390 wxRect rect
= InReportView() ? GetLineRect(line
)
2391 : GetLineLabelRect(line
);
2393 if ( rect
.Contains(x
, y
) )
2394 return wxLIST_HITTEST_ONITEMLABEL
;
2400 // ----------------------------------------------------------------------------
2401 // highlight (selection) handling
2402 // ----------------------------------------------------------------------------
2404 bool wxListMainWindow::IsHighlighted(size_t line
) const
2408 return m_selStore
.IsSelected(line
);
2412 wxListLineData
*ld
= GetLine(line
);
2413 wxCHECK_MSG( ld
, false, _T("invalid index in IsHighlighted") );
2415 return ld
->IsHighlighted();
2419 void wxListMainWindow::HighlightLines( size_t lineFrom
,
2425 wxArrayInt linesChanged
;
2426 if ( !m_selStore
.SelectRange(lineFrom
, lineTo
, highlight
,
2429 // meny items changed state, refresh everything
2430 RefreshLines(lineFrom
, lineTo
);
2432 else // only a few items changed state, refresh only them
2434 size_t count
= linesChanged
.GetCount();
2435 for ( size_t n
= 0; n
< count
; n
++ )
2437 RefreshLine(linesChanged
[n
]);
2441 else // iterate over all items in non report view
2443 for ( size_t line
= lineFrom
; line
<= lineTo
; line
++ )
2445 if ( HighlightLine(line
, highlight
) )
2451 bool wxListMainWindow::HighlightLine( size_t line
, bool highlight
)
2457 changed
= m_selStore
.SelectItem(line
, highlight
);
2461 wxListLineData
*ld
= GetLine(line
);
2462 wxCHECK_MSG( ld
, false, _T("invalid index in HighlightLine") );
2464 changed
= ld
->Highlight(highlight
);
2469 SendNotify( line
, highlight
? wxEVT_COMMAND_LIST_ITEM_SELECTED
2470 : wxEVT_COMMAND_LIST_ITEM_DESELECTED
);
2476 void wxListMainWindow::RefreshLine( size_t line
)
2478 if ( InReportView() )
2480 size_t visibleFrom
, visibleTo
;
2481 GetVisibleLinesRange(&visibleFrom
, &visibleTo
);
2483 if ( line
< visibleFrom
|| line
> visibleTo
)
2487 wxRect rect
= GetLineRect(line
);
2489 CalcScrolledPosition( rect
.x
, rect
.y
, &rect
.x
, &rect
.y
);
2490 RefreshRect( rect
);
2493 void wxListMainWindow::RefreshLines( size_t lineFrom
, size_t lineTo
)
2495 // we suppose that they are ordered by caller
2496 wxASSERT_MSG( lineFrom
<= lineTo
, _T("indices in disorder") );
2498 wxASSERT_MSG( lineTo
< GetItemCount(), _T("invalid line range") );
2500 if ( InReportView() )
2502 size_t visibleFrom
, visibleTo
;
2503 GetVisibleLinesRange(&visibleFrom
, &visibleTo
);
2505 if ( lineFrom
< visibleFrom
)
2506 lineFrom
= visibleFrom
;
2507 if ( lineTo
> visibleTo
)
2512 rect
.y
= GetLineY(lineFrom
);
2513 rect
.width
= GetClientSize().x
;
2514 rect
.height
= GetLineY(lineTo
) - rect
.y
+ GetLineHeight();
2516 CalcScrolledPosition( rect
.x
, rect
.y
, &rect
.x
, &rect
.y
);
2517 RefreshRect( rect
);
2521 // TODO: this should be optimized...
2522 for ( size_t line
= lineFrom
; line
<= lineTo
; line
++ )
2529 void wxListMainWindow::RefreshAfter( size_t lineFrom
)
2531 if ( InReportView() )
2533 size_t visibleFrom
, visibleTo
;
2534 GetVisibleLinesRange(&visibleFrom
, &visibleTo
);
2536 if ( lineFrom
< visibleFrom
)
2537 lineFrom
= visibleFrom
;
2538 else if ( lineFrom
> visibleTo
)
2543 rect
.y
= GetLineY(lineFrom
);
2544 CalcScrolledPosition( rect
.x
, rect
.y
, &rect
.x
, &rect
.y
);
2546 wxSize size
= GetClientSize();
2547 rect
.width
= size
.x
;
2549 // refresh till the bottom of the window
2550 rect
.height
= size
.y
- rect
.y
;
2552 RefreshRect( rect
);
2556 // TODO: how to do it more efficiently?
2561 void wxListMainWindow::RefreshSelected()
2567 if ( InReportView() )
2569 GetVisibleLinesRange(&from
, &to
);
2574 to
= GetItemCount() - 1;
2577 if ( HasCurrent() && m_current
>= from
&& m_current
<= to
)
2578 RefreshLine(m_current
);
2580 for ( size_t line
= from
; line
<= to
; line
++ )
2582 // NB: the test works as expected even if m_current == -1
2583 if ( line
!= m_current
&& IsHighlighted(line
) )
2588 void wxListMainWindow::Freeze()
2593 void wxListMainWindow::Thaw()
2595 wxCHECK_RET( m_freezeCount
> 0, _T("thawing unfrozen list control?") );
2597 if ( --m_freezeCount
== 0 )
2601 void wxListMainWindow::OnPaint( wxPaintEvent
&WXUNUSED(event
) )
2603 // Note: a wxPaintDC must be constructed even if no drawing is
2604 // done (a Windows requirement).
2605 wxPaintDC
dc( this );
2607 if ( IsEmpty() || m_freezeCount
)
2608 // nothing to draw or not the moment to draw it
2612 // delay the repainting until we calculate all the items positions
2618 CalcScrolledPosition( 0, 0, &dev_x
, &dev_y
);
2620 dc
.SetFont( GetFont() );
2622 if ( InReportView() )
2624 int lineHeight
= GetLineHeight();
2626 size_t visibleFrom
, visibleTo
;
2627 GetVisibleLinesRange(&visibleFrom
, &visibleTo
);
2630 int xOrig
= dc
.LogicalToDeviceX( 0 );
2631 int yOrig
= dc
.LogicalToDeviceY( 0 );
2633 // tell the caller cache to cache the data
2636 wxListEvent
evCache(wxEVT_COMMAND_LIST_CACHE_HINT
,
2637 GetParent()->GetId());
2638 evCache
.SetEventObject( GetParent() );
2639 evCache
.m_oldItemIndex
= visibleFrom
;
2640 evCache
.m_itemIndex
= visibleTo
;
2641 GetParent()->GetEventHandler()->ProcessEvent( evCache
);
2644 for ( size_t line
= visibleFrom
; line
<= visibleTo
; line
++ )
2646 rectLine
= GetLineRect(line
);
2649 if ( !IsExposed(rectLine
.x
+ xOrig
, rectLine
.y
+ yOrig
,
2650 rectLine
.width
, rectLine
.height
) )
2652 // don't redraw unaffected lines to avoid flicker
2656 GetLine(line
)->DrawInReportMode( &dc
,
2658 GetLineHighlightRect(line
),
2659 IsHighlighted(line
) );
2662 if ( HasFlag(wxLC_HRULES
) )
2664 wxPen
pen(GetRuleColour(), 1, wxSOLID
);
2665 wxSize clientSize
= GetClientSize();
2667 // Don't draw the first one
2668 for ( size_t i
= visibleFrom
+ 1; i
<= visibleTo
; i
++ )
2671 dc
.SetBrush( *wxTRANSPARENT_BRUSH
);
2672 dc
.DrawLine(0 - dev_x
, i
* lineHeight
,
2673 clientSize
.x
- dev_x
, i
* lineHeight
);
2676 // Draw last horizontal rule
2677 if ( visibleTo
== GetItemCount() - 1 )
2680 dc
.SetBrush( *wxTRANSPARENT_BRUSH
);
2681 dc
.DrawLine(0 - dev_x
, (m_lineTo
+ 1) * lineHeight
,
2682 clientSize
.x
- dev_x
, (m_lineTo
+ 1) * lineHeight
);
2686 // Draw vertical rules if required
2687 if ( HasFlag(wxLC_VRULES
) && !IsEmpty() )
2689 wxPen
pen(GetRuleColour(), 1, wxSOLID
);
2690 wxRect firstItemRect
, lastItemRect
;
2692 GetItemRect(visibleFrom
, firstItemRect
);
2693 GetItemRect(visibleTo
, lastItemRect
);
2694 int x
= firstItemRect
.GetX();
2696 dc
.SetBrush(* wxTRANSPARENT_BRUSH
);
2698 for (int col
= 0; col
< GetColumnCount(); col
++)
2700 int colWidth
= GetColumnWidth(col
);
2702 dc
.DrawLine(x
- dev_x
- 2, firstItemRect
.GetY() - 1 - dev_y
,
2703 x
- dev_x
- 2, lastItemRect
.GetBottom() + 1 - dev_y
);
2709 size_t count
= GetItemCount();
2710 for ( size_t i
= 0; i
< count
; i
++ )
2712 GetLine(i
)->Draw( &dc
);
2717 // Don't draw rect outline under Mac at all.
2722 dc
.SetPen( *wxBLACK_PEN
);
2723 dc
.SetBrush( *wxTRANSPARENT_BRUSH
);
2724 dc
.DrawRectangle( GetLineHighlightRect( m_current
) );
2730 void wxListMainWindow::HighlightAll( bool on
)
2732 if ( IsSingleSel() )
2734 wxASSERT_MSG( !on
, _T("can't do this in a single selection control") );
2736 // we just have one item to turn off
2737 if ( HasCurrent() && IsHighlighted(m_current
) )
2739 HighlightLine(m_current
, false);
2740 RefreshLine(m_current
);
2745 HighlightLines(0, GetItemCount() - 1, on
);
2749 void wxListMainWindow::SendNotify( size_t line
,
2750 wxEventType command
,
2751 const wxPoint
& point
)
2753 wxListEvent
le( command
, GetParent()->GetId() );
2754 le
.SetEventObject( GetParent() );
2755 le
.m_itemIndex
= line
;
2757 // set only for events which have position
2758 if ( point
!= wxDefaultPosition
)
2759 le
.m_pointDrag
= point
;
2761 // don't try to get the line info for virtual list controls: the main
2762 // program has it anyhow and if we did it would result in accessing all
2763 // the lines, even those which are not visible now and this is precisely
2764 // what we're trying to avoid
2765 if ( !IsVirtual() && (command
!= wxEVT_COMMAND_LIST_DELETE_ITEM
) )
2767 if ( line
!= (size_t)-1 )
2769 GetLine(line
)->GetItem( 0, le
.m_item
);
2771 //else: this happens for wxEVT_COMMAND_LIST_ITEM_FOCUSED event
2773 //else: there may be no more such item
2775 GetParent()->GetEventHandler()->ProcessEvent( le
);
2778 void wxListMainWindow::ChangeCurrent(size_t current
)
2780 m_current
= current
;
2782 SendNotify(current
, wxEVT_COMMAND_LIST_ITEM_FOCUSED
);
2785 wxTextCtrl
*wxListMainWindow::EditLabel(long item
, wxClassInfo
* textControlClass
)
2787 wxCHECK_MSG( (item
>= 0) && ((size_t)item
< GetItemCount()), NULL
,
2788 wxT("wrong index in wxGenericListCtrl::EditLabel()") );
2790 wxASSERT_MSG( textControlClass
->IsKindOf(CLASSINFO(wxTextCtrl
)),
2791 wxT("EditLabel() needs a text control") );
2793 size_t itemEdit
= (size_t)item
;
2795 wxListEvent
le( wxEVT_COMMAND_LIST_BEGIN_LABEL_EDIT
, GetParent()->GetId() );
2796 le
.SetEventObject( GetParent() );
2797 le
.m_itemIndex
= item
;
2798 wxListLineData
*data
= GetLine(itemEdit
);
2799 wxCHECK_MSG( data
, NULL
, _T("invalid index in EditLabel()") );
2800 data
->GetItem( 0, le
.m_item
);
2802 if ( GetParent()->GetEventHandler()->ProcessEvent( le
) && !le
.IsAllowed() )
2804 // vetoed by user code
2808 // We have to call this here because the label in question might just have
2809 // been added and no screen update taken place.
2813 wxTextCtrl
* const text
= (wxTextCtrl
*)textControlClass
->CreateObject();
2814 m_textctrlWrapper
= new wxListTextCtrlWrapper(this, text
, item
);
2815 return m_textctrlWrapper
->GetText();
2818 void wxListMainWindow::OnRenameTimer()
2820 wxCHECK_RET( HasCurrent(), wxT("unexpected rename timer") );
2822 EditLabel( m_current
);
2825 bool wxListMainWindow::OnRenameAccept(size_t itemEdit
, const wxString
& value
)
2827 wxListEvent
le( wxEVT_COMMAND_LIST_END_LABEL_EDIT
, GetParent()->GetId() );
2828 le
.SetEventObject( GetParent() );
2829 le
.m_itemIndex
= itemEdit
;
2831 wxListLineData
*data
= GetLine(itemEdit
);
2833 wxCHECK_MSG( data
, false, _T("invalid index in OnRenameAccept()") );
2835 data
->GetItem( 0, le
.m_item
);
2836 le
.m_item
.m_text
= value
;
2837 return !GetParent()->GetEventHandler()->ProcessEvent( le
) ||
2841 void wxListMainWindow::OnRenameCancelled(size_t itemEdit
)
2843 // let owner know that the edit was cancelled
2844 wxListEvent
le( wxEVT_COMMAND_LIST_END_LABEL_EDIT
, GetParent()->GetId() );
2846 le
.SetEditCanceled(true);
2848 le
.SetEventObject( GetParent() );
2849 le
.m_itemIndex
= itemEdit
;
2851 wxListLineData
*data
= GetLine(itemEdit
);
2852 wxCHECK_RET( data
, _T("invalid index in OnRenameCancelled()") );
2854 data
->GetItem( 0, le
.m_item
);
2855 GetEventHandler()->ProcessEvent( le
);
2858 void wxListMainWindow::OnMouse( wxMouseEvent
&event
)
2862 // On wxMac we can't depend on the EVT_KILL_FOCUS event to properly
2863 // shutdown the edit control when the mouse is clicked elsewhere on the
2864 // listctrl because the order of events is different (or something like
2865 // that), so explicitly end the edit if it is active.
2866 if ( event
.LeftDown() && m_textctrlWrapper
)
2867 m_textctrlWrapper
->AcceptChangesAndFinish();
2870 event
.SetEventObject( GetParent() );
2871 if ( GetParent()->GetEventHandler()->ProcessEvent( event
) )
2874 if (event
.GetEventType() == wxEVT_MOUSEWHEEL
)
2876 // let the base handle mouse wheel events.
2881 if ( !HasCurrent() || IsEmpty() )
2883 if (event
.RightDown())
2885 SendNotify( (size_t)-1, wxEVT_COMMAND_LIST_ITEM_RIGHT_CLICK
, event
.GetPosition() );
2886 // Allow generation of context menu event
2895 if ( !(event
.Dragging() || event
.ButtonDown() || event
.LeftUp() ||
2896 event
.ButtonDClick()) )
2899 int x
= event
.GetX();
2900 int y
= event
.GetY();
2901 CalcUnscrolledPosition( x
, y
, &x
, &y
);
2903 // where did we hit it (if we did)?
2906 size_t count
= GetItemCount(),
2909 if ( InReportView() )
2911 current
= y
/ GetLineHeight();
2912 if ( current
< count
)
2913 hitResult
= HitTestLine(current
, x
, y
);
2917 // TODO: optimize it too! this is less simple than for report view but
2918 // enumerating all items is still not a way to do it!!
2919 for ( current
= 0; current
< count
; current
++ )
2921 hitResult
= HitTestLine(current
, x
, y
);
2927 if (event
.Dragging())
2929 if (m_dragCount
== 0)
2931 // we have to report the raw, physical coords as we want to be
2932 // able to call HitTest(event.m_pointDrag) from the user code to
2933 // get the item being dragged
2934 m_dragStart
= event
.GetPosition();
2939 if (m_dragCount
!= 3)
2942 int command
= event
.RightIsDown() ? wxEVT_COMMAND_LIST_BEGIN_RDRAG
2943 : wxEVT_COMMAND_LIST_BEGIN_DRAG
;
2945 wxListEvent
le( command
, GetParent()->GetId() );
2946 le
.SetEventObject( GetParent() );
2947 le
.m_itemIndex
= m_lineLastClicked
;
2948 le
.m_pointDrag
= m_dragStart
;
2949 GetParent()->GetEventHandler()->ProcessEvent( le
);
2960 // outside of any item
2961 if (event
.RightDown())
2963 SendNotify( (size_t) -1, wxEVT_COMMAND_LIST_ITEM_RIGHT_CLICK
, event
.GetPosition() );
2964 // Allow generation of context menu event
2969 // reset the selection and bail out
2970 HighlightAll(false);
2976 bool forceClick
= false;
2977 if (event
.ButtonDClick())
2979 m_renameTimer
->Stop();
2980 m_lastOnSame
= false;
2982 if ( current
== m_lineLastClicked
)
2984 SendNotify( current
, wxEVT_COMMAND_LIST_ITEM_ACTIVATED
);
2990 // The first click was on another item, so don't interpret this as
2991 // a double click, but as a simple click instead
2998 if (m_lineSelectSingleOnUp
!= (size_t)-1)
3000 // select single line
3001 HighlightAll( false );
3002 ReverseHighlight(m_lineSelectSingleOnUp
);
3007 if ((current
== m_current
) &&
3008 (hitResult
== wxLIST_HITTEST_ONITEMLABEL
) &&
3009 HasFlag(wxLC_EDIT_LABELS
) )
3011 m_renameTimer
->Start( 100, true );
3015 m_lastOnSame
= false;
3016 m_lineSelectSingleOnUp
= (size_t)-1;
3020 // This is necessary, because after a DnD operation in
3021 // from and to ourself, the up event is swallowed by the
3022 // DnD code. So on next non-up event (which means here and
3023 // now) m_lineSelectSingleOnUp should be reset.
3024 m_lineSelectSingleOnUp
= (size_t)-1;
3026 if (event
.RightDown())
3028 m_lineBeforeLastClicked
= m_lineLastClicked
;
3029 m_lineLastClicked
= current
;
3031 // If the item is already selected, do not update the selection.
3032 // Multi-selections should not be cleared if a selected item is clicked.
3033 if (!IsHighlighted(current
))
3035 HighlightAll(false);
3036 ChangeCurrent(current
);
3037 ReverseHighlight(m_current
);
3040 SendNotify( current
, wxEVT_COMMAND_LIST_ITEM_RIGHT_CLICK
, event
.GetPosition() );
3042 // Allow generation of context menu event
3045 else if (event
.MiddleDown())
3047 SendNotify( current
, wxEVT_COMMAND_LIST_ITEM_MIDDLE_CLICK
);
3049 else if ( event
.LeftDown() || forceClick
)
3051 m_lineBeforeLastClicked
= m_lineLastClicked
;
3052 m_lineLastClicked
= current
;
3054 size_t oldCurrent
= m_current
;
3055 bool oldWasSelected
= IsHighlighted(m_current
);
3057 bool cmdModifierDown
= event
.CmdDown();
3058 if ( IsSingleSel() || !(cmdModifierDown
|| event
.ShiftDown()) )
3060 if ( IsSingleSel() || !IsHighlighted(current
) )
3062 HighlightAll( false );
3064 ChangeCurrent(current
);
3066 ReverseHighlight(m_current
);
3068 else // multi sel & current is highlighted & no mod keys
3070 m_lineSelectSingleOnUp
= current
;
3071 ChangeCurrent(current
); // change focus
3074 else // multi sel & either ctrl or shift is down
3076 if (cmdModifierDown
)
3078 ChangeCurrent(current
);
3080 ReverseHighlight(m_current
);
3082 else if (event
.ShiftDown())
3084 ChangeCurrent(current
);
3086 size_t lineFrom
= oldCurrent
,
3089 if ( lineTo
< lineFrom
)
3092 lineFrom
= m_current
;
3095 HighlightLines(lineFrom
, lineTo
);
3097 else // !ctrl, !shift
3099 // test in the enclosing if should make it impossible
3100 wxFAIL_MSG( _T("how did we get here?") );
3104 if (m_current
!= oldCurrent
)
3105 RefreshLine( oldCurrent
);
3107 // forceClick is only set if the previous click was on another item
3108 m_lastOnSame
= !forceClick
&& (m_current
== oldCurrent
) && oldWasSelected
;
3112 void wxListMainWindow::MoveToItem(size_t item
)
3114 if ( item
== (size_t)-1 )
3117 wxRect rect
= GetLineRect(item
);
3119 int client_w
, client_h
;
3120 GetClientSize( &client_w
, &client_h
);
3122 const int hLine
= GetLineHeight();
3124 int view_x
= SCROLL_UNIT_X
* GetScrollPos( wxHORIZONTAL
);
3125 int view_y
= hLine
* GetScrollPos( wxVERTICAL
);
3127 if ( InReportView() )
3129 // the next we need the range of lines shown it might be different,
3130 // so recalculate it
3131 ResetVisibleLinesRange();
3133 if (rect
.y
< view_y
)
3134 Scroll( -1, rect
.y
/ hLine
);
3135 if (rect
.y
+ rect
.height
+ 5 > view_y
+ client_h
)
3136 Scroll( -1, (rect
.y
+ rect
.height
- client_h
+ hLine
) / hLine
);
3140 if (rect
.x
-view_x
< 5)
3141 Scroll( (rect
.x
- 5) / SCROLL_UNIT_X
, -1 );
3142 if (rect
.x
+ rect
.width
- 5 > view_x
+ client_w
)
3143 Scroll( (rect
.x
+ rect
.width
- client_w
+ SCROLL_UNIT_X
) / SCROLL_UNIT_X
, -1 );
3147 // ----------------------------------------------------------------------------
3148 // keyboard handling
3149 // ----------------------------------------------------------------------------
3151 void wxListMainWindow::OnArrowChar(size_t newCurrent
, const wxKeyEvent
& event
)
3153 wxCHECK_RET( newCurrent
< (size_t)GetItemCount(),
3154 _T("invalid item index in OnArrowChar()") );
3156 size_t oldCurrent
= m_current
;
3158 // in single selection we just ignore Shift as we can't select several
3160 if ( event
.ShiftDown() && !IsSingleSel() )
3162 ChangeCurrent(newCurrent
);
3164 // refresh the old focus to remove it
3165 RefreshLine( oldCurrent
);
3167 // select all the items between the old and the new one
3168 if ( oldCurrent
> newCurrent
)
3170 newCurrent
= oldCurrent
;
3171 oldCurrent
= m_current
;
3174 HighlightLines(oldCurrent
, newCurrent
);
3178 // all previously selected items are unselected unless ctrl is held
3179 if ( !event
.ControlDown() )
3180 HighlightAll(false);
3182 ChangeCurrent(newCurrent
);
3184 // refresh the old focus to remove it
3185 RefreshLine( oldCurrent
);
3187 if ( !event
.ControlDown() )
3189 HighlightLine( m_current
, true );
3193 RefreshLine( m_current
);
3198 void wxListMainWindow::OnKeyDown( wxKeyEvent
&event
)
3200 wxWindow
*parent
= GetParent();
3202 // propagate the key event upwards
3203 wxKeyEvent
ke( wxEVT_KEY_DOWN
);
3204 ke
.m_shiftDown
= event
.m_shiftDown
;
3205 ke
.m_controlDown
= event
.m_controlDown
;
3206 ke
.m_altDown
= event
.m_altDown
;
3207 ke
.m_metaDown
= event
.m_metaDown
;
3208 ke
.m_keyCode
= event
.m_keyCode
;
3211 ke
.SetEventObject( parent
);
3212 if (parent
->GetEventHandler()->ProcessEvent( ke
)) return;
3217 void wxListMainWindow::OnChar( wxKeyEvent
&event
)
3219 wxWindow
*parent
= GetParent();
3221 // send a list_key event up
3224 wxListEvent
le( wxEVT_COMMAND_LIST_KEY_DOWN
, GetParent()->GetId() );
3225 le
.m_itemIndex
= m_current
;
3226 GetLine(m_current
)->GetItem( 0, le
.m_item
);
3227 le
.m_code
= event
.GetKeyCode();
3228 le
.SetEventObject( parent
);
3229 parent
->GetEventHandler()->ProcessEvent( le
);
3232 // propagate the char event upwards
3233 wxKeyEvent
ke( wxEVT_CHAR
);
3234 ke
.m_shiftDown
= event
.m_shiftDown
;
3235 ke
.m_controlDown
= event
.m_controlDown
;
3236 ke
.m_altDown
= event
.m_altDown
;
3237 ke
.m_metaDown
= event
.m_metaDown
;
3238 ke
.m_keyCode
= event
.m_keyCode
;
3241 ke
.SetEventObject( parent
);
3242 if (parent
->GetEventHandler()->ProcessEvent( ke
)) return;
3244 if (event
.GetKeyCode() == WXK_TAB
)
3246 wxNavigationKeyEvent nevent
;
3247 nevent
.SetWindowChange( event
.ControlDown() );
3248 nevent
.SetDirection( !event
.ShiftDown() );
3249 nevent
.SetEventObject( GetParent()->GetParent() );
3250 nevent
.SetCurrentFocus( m_parent
);
3251 if (GetParent()->GetParent()->GetEventHandler()->ProcessEvent( nevent
))
3255 // no item -> nothing to do
3262 // don't use m_linesPerPage directly as it might not be computed yet
3263 const int pageSize
= GetCountPerPage();
3264 wxCHECK_RET( pageSize
, _T("should have non zero page size") );
3266 if (GetLayoutDirection() == wxLayout_RightToLeft
)
3268 if (event
.GetKeyCode() == WXK_RIGHT
)
3269 event
.m_keyCode
= WXK_LEFT
;
3270 else if (event
.GetKeyCode() == WXK_LEFT
)
3271 event
.m_keyCode
= WXK_RIGHT
;
3274 switch ( event
.GetKeyCode() )
3277 if ( m_current
> 0 )
3278 OnArrowChar( m_current
- 1, event
);
3282 if ( m_current
< (size_t)GetItemCount() - 1 )
3283 OnArrowChar( m_current
+ 1, event
);
3288 OnArrowChar( GetItemCount() - 1, event
);
3293 OnArrowChar( 0, event
);
3298 int steps
= InReportView() ? pageSize
- 1
3299 : m_current
% pageSize
;
3301 int index
= m_current
- steps
;
3305 OnArrowChar( index
, event
);
3311 int steps
= InReportView()
3313 : pageSize
- (m_current
% pageSize
) - 1;
3315 size_t index
= m_current
+ steps
;
3316 size_t count
= GetItemCount();
3317 if ( index
>= count
)
3320 OnArrowChar( index
, event
);
3325 if ( !InReportView() )
3327 int index
= m_current
- pageSize
;
3331 OnArrowChar( index
, event
);
3336 if ( !InReportView() )
3338 size_t index
= m_current
+ pageSize
;
3340 size_t count
= GetItemCount();
3341 if ( index
>= count
)
3344 OnArrowChar( index
, event
);
3349 if ( IsSingleSel() )
3351 SendNotify( m_current
, wxEVT_COMMAND_LIST_ITEM_ACTIVATED
);
3353 if ( IsHighlighted(m_current
) )
3355 // don't unselect the item in single selection mode
3358 //else: select it in ReverseHighlight() below if unselected
3361 ReverseHighlight(m_current
);
3366 SendNotify( m_current
, wxEVT_COMMAND_LIST_ITEM_ACTIVATED
);
3374 // ----------------------------------------------------------------------------
3376 // ----------------------------------------------------------------------------
3378 void wxListMainWindow::OnSetFocus( wxFocusEvent
&WXUNUSED(event
) )
3382 wxFocusEvent
event( wxEVT_SET_FOCUS
, GetParent()->GetId() );
3383 event
.SetEventObject( GetParent() );
3384 if ( GetParent()->GetEventHandler()->ProcessEvent( event
) )
3388 // wxGTK sends us EVT_SET_FOCUS events even if we had never got
3389 // EVT_KILL_FOCUS before which means that we finish by redrawing the items
3390 // which are already drawn correctly resulting in horrible flicker - avoid
3400 void wxListMainWindow::OnKillFocus( wxFocusEvent
&WXUNUSED(event
) )
3404 wxFocusEvent
event( wxEVT_KILL_FOCUS
, GetParent()->GetId() );
3405 event
.SetEventObject( GetParent() );
3406 if ( GetParent()->GetEventHandler()->ProcessEvent( event
) )
3414 void wxListMainWindow::DrawImage( int index
, wxDC
*dc
, int x
, int y
)
3416 if ( HasFlag(wxLC_ICON
) && (m_normal_image_list
))
3418 m_normal_image_list
->Draw( index
, *dc
, x
, y
, wxIMAGELIST_DRAW_TRANSPARENT
);
3420 else if ( HasFlag(wxLC_SMALL_ICON
) && (m_small_image_list
))
3422 m_small_image_list
->Draw( index
, *dc
, x
, y
, wxIMAGELIST_DRAW_TRANSPARENT
);
3424 else if ( HasFlag(wxLC_LIST
) && (m_small_image_list
))
3426 m_small_image_list
->Draw( index
, *dc
, x
, y
, wxIMAGELIST_DRAW_TRANSPARENT
);
3428 else if ( InReportView() && (m_small_image_list
))
3430 m_small_image_list
->Draw( index
, *dc
, x
, y
, wxIMAGELIST_DRAW_TRANSPARENT
);
3434 void wxListMainWindow::GetImageSize( int index
, int &width
, int &height
) const
3436 if ( HasFlag(wxLC_ICON
) && m_normal_image_list
)
3438 m_normal_image_list
->GetSize( index
, width
, height
);
3440 else if ( HasFlag(wxLC_SMALL_ICON
) && m_small_image_list
)
3442 m_small_image_list
->GetSize( index
, width
, height
);
3444 else if ( HasFlag(wxLC_LIST
) && m_small_image_list
)
3446 m_small_image_list
->GetSize( index
, width
, height
);
3448 else if ( InReportView() && m_small_image_list
)
3450 m_small_image_list
->GetSize( index
, width
, height
);
3459 int wxListMainWindow::GetTextLength( const wxString
&s
) const
3461 wxClientDC
dc( wxConstCast(this, wxListMainWindow
) );
3462 dc
.SetFont( GetFont() );
3465 dc
.GetTextExtent( s
, &lw
, NULL
);
3467 return lw
+ AUTOSIZE_COL_MARGIN
;
3470 void wxListMainWindow::SetImageList( wxImageList
*imageList
, int which
)
3474 // calc the spacing from the icon size
3475 int width
= 0, height
= 0;
3477 if ((imageList
) && (imageList
->GetImageCount()) )
3478 imageList
->GetSize(0, width
, height
);
3480 if (which
== wxIMAGE_LIST_NORMAL
)
3482 m_normal_image_list
= imageList
;
3483 m_normal_spacing
= width
+ 8;
3486 if (which
== wxIMAGE_LIST_SMALL
)
3488 m_small_image_list
= imageList
;
3489 m_small_spacing
= width
+ 14;
3490 m_lineHeight
= 0; // ensure that the line height will be recalc'd
3494 void wxListMainWindow::SetItemSpacing( int spacing
, bool isSmall
)
3498 m_small_spacing
= spacing
;
3500 m_normal_spacing
= spacing
;
3503 int wxListMainWindow::GetItemSpacing( bool isSmall
)
3505 return isSmall
? m_small_spacing
: m_normal_spacing
;
3508 // ----------------------------------------------------------------------------
3510 // ----------------------------------------------------------------------------
3512 void wxListMainWindow::SetColumn( int col
, wxListItem
&item
)
3514 wxListHeaderDataList::compatibility_iterator node
= m_columns
.Item( col
);
3516 wxCHECK_RET( node
, _T("invalid column index in SetColumn") );
3518 if ( item
.m_width
== wxLIST_AUTOSIZE_USEHEADER
)
3519 item
.m_width
= GetTextLength( item
.m_text
);
3521 wxListHeaderData
*column
= node
->GetData();
3522 column
->SetItem( item
);
3524 wxListHeaderWindow
*headerWin
= GetListCtrl()->m_headerWin
;
3526 headerWin
->m_dirty
= true;
3530 // invalidate it as it has to be recalculated
3534 void wxListMainWindow::SetColumnWidth( int col
, int width
)
3536 wxCHECK_RET( col
>= 0 && col
< GetColumnCount(),
3537 _T("invalid column index") );
3539 wxCHECK_RET( InReportView(),
3540 _T("SetColumnWidth() can only be called in report mode.") );
3543 wxListHeaderWindow
*headerWin
= GetListCtrl()->m_headerWin
;
3545 headerWin
->m_dirty
= true;
3547 wxListHeaderDataList::compatibility_iterator node
= m_columns
.Item( col
);
3548 wxCHECK_RET( node
, _T("no column?") );
3550 wxListHeaderData
*column
= node
->GetData();
3552 size_t count
= GetItemCount();
3554 if (width
== wxLIST_AUTOSIZE_USEHEADER
)
3556 width
= GetTextLength(column
->GetText());
3558 else if ( width
== wxLIST_AUTOSIZE
)
3562 // TODO: determine the max width somehow...
3563 width
= WIDTH_COL_DEFAULT
;
3567 wxClientDC
dc(this);
3568 dc
.SetFont( GetFont() );
3570 int max
= AUTOSIZE_COL_MARGIN
;
3572 // if the cached column width isn't valid then recalculate it
3573 if (m_aColWidths
.Item(col
)->bNeedsUpdate
)
3575 for (size_t i
= 0; i
< count
; i
++)
3577 wxListLineData
*line
= GetLine( i
);
3578 wxListItemDataList::compatibility_iterator n
= line
->m_items
.Item( col
);
3580 wxCHECK_RET( n
, _T("no subitem?") );
3582 wxListItemData
*itemData
= n
->GetData();
3585 itemData
->GetItem(item
);
3586 int itemWidth
= GetItemWidthWithImage(&item
);
3587 if (itemWidth
> max
)
3591 m_aColWidths
.Item(col
)->bNeedsUpdate
= false;
3592 m_aColWidths
.Item(col
)->nMaxWidth
= max
;
3595 max
= m_aColWidths
.Item(col
)->nMaxWidth
;
3596 width
= max
+ AUTOSIZE_COL_MARGIN
;
3600 column
->SetWidth( width
);
3602 // invalidate it as it has to be recalculated
3606 int wxListMainWindow::GetHeaderWidth() const
3608 if ( !m_headerWidth
)
3610 wxListMainWindow
*self
= wxConstCast(this, wxListMainWindow
);
3612 size_t count
= GetColumnCount();
3613 for ( size_t col
= 0; col
< count
; col
++ )
3615 self
->m_headerWidth
+= GetColumnWidth(col
);
3619 return m_headerWidth
;
3622 void wxListMainWindow::GetColumn( int col
, wxListItem
&item
) const
3624 wxListHeaderDataList::compatibility_iterator node
= m_columns
.Item( col
);
3625 wxCHECK_RET( node
, _T("invalid column index in GetColumn") );
3627 wxListHeaderData
*column
= node
->GetData();
3628 column
->GetItem( item
);
3631 int wxListMainWindow::GetColumnWidth( int col
) const
3633 wxListHeaderDataList::compatibility_iterator node
= m_columns
.Item( col
);
3634 wxCHECK_MSG( node
, 0, _T("invalid column index") );
3636 wxListHeaderData
*column
= node
->GetData();
3637 return column
->GetWidth();
3640 // ----------------------------------------------------------------------------
3642 // ----------------------------------------------------------------------------
3644 void wxListMainWindow::SetItem( wxListItem
&item
)
3646 long id
= item
.m_itemId
;
3647 wxCHECK_RET( id
>= 0 && (size_t)id
< GetItemCount(),
3648 _T("invalid item index in SetItem") );
3652 wxListLineData
*line
= GetLine((size_t)id
);
3653 line
->SetItem( item
.m_col
, item
);
3655 // Set item state if user wants
3656 if ( item
.m_mask
& wxLIST_MASK_STATE
)
3657 SetItemState( item
.m_itemId
, item
.m_state
, item
.m_state
);
3661 // update the Max Width Cache if needed
3662 int width
= GetItemWidthWithImage(&item
);
3664 if (width
> m_aColWidths
.Item(item
.m_col
)->nMaxWidth
)
3665 m_aColWidths
.Item(item
.m_col
)->nMaxWidth
= width
;
3669 // update the item on screen
3671 GetItemRect(id
, rectItem
);
3672 RefreshRect(rectItem
);
3675 void wxListMainWindow::SetItemStateAll(long state
, long stateMask
)
3680 // first deal with selection
3681 if ( stateMask
& wxLIST_STATE_SELECTED
)
3683 // set/clear select state
3686 // optimized version for virtual listctrl.
3687 m_selStore
.SelectRange(0, GetItemCount() - 1, state
== wxLIST_STATE_SELECTED
);
3690 else if ( state
& wxLIST_STATE_SELECTED
)
3692 const long count
= GetItemCount();
3693 for( long i
= 0; i
< count
; i
++ )
3695 SetItemState( i
, wxLIST_STATE_SELECTED
, wxLIST_STATE_SELECTED
);
3701 // clear for non virtual (somewhat optimized by using GetNextItem())
3703 while ( (i
= GetNextItem(i
, wxLIST_NEXT_ALL
, wxLIST_STATE_SELECTED
)) != -1 )
3705 SetItemState( i
, 0, wxLIST_STATE_SELECTED
);
3710 if ( HasCurrent() && (state
== 0) && (stateMask
& wxLIST_STATE_FOCUSED
) )
3712 // unfocus all: only one item can be focussed, so clearing focus for
3713 // all items is simply clearing focus of the focussed item.
3714 SetItemState(m_current
, state
, stateMask
);
3716 //(setting focus to all items makes no sense, so it is not handled here.)
3719 void wxListMainWindow::SetItemState( long litem
, long state
, long stateMask
)
3723 SetItemStateAll(state
, stateMask
);
3727 wxCHECK_RET( litem
>= 0 && (size_t)litem
< GetItemCount(),
3728 _T("invalid list ctrl item index in SetItem") );
3730 size_t oldCurrent
= m_current
;
3731 size_t item
= (size_t)litem
; // safe because of the check above
3733 // do we need to change the focus?
3734 if ( stateMask
& wxLIST_STATE_FOCUSED
)
3736 if ( state
& wxLIST_STATE_FOCUSED
)
3738 // don't do anything if this item is already focused
3739 if ( item
!= m_current
)
3741 ChangeCurrent(item
);
3743 if ( oldCurrent
!= (size_t)-1 )
3745 if ( IsSingleSel() )
3747 HighlightLine(oldCurrent
, false);
3750 RefreshLine(oldCurrent
);
3753 RefreshLine( m_current
);
3758 // don't do anything if this item is not focused
3759 if ( item
== m_current
)
3763 if ( IsSingleSel() )
3765 // we must unselect the old current item as well or we
3766 // might end up with more than one selected item in a
3767 // single selection control
3768 HighlightLine(oldCurrent
, false);
3771 RefreshLine( oldCurrent
);
3776 // do we need to change the selection state?
3777 if ( stateMask
& wxLIST_STATE_SELECTED
)
3779 bool on
= (state
& wxLIST_STATE_SELECTED
) != 0;
3781 if ( IsSingleSel() )
3785 // selecting the item also makes it the focused one in the
3787 if ( m_current
!= item
)
3789 ChangeCurrent(item
);
3791 if ( oldCurrent
!= (size_t)-1 )
3793 HighlightLine( oldCurrent
, false );
3794 RefreshLine( oldCurrent
);
3800 // only the current item may be selected anyhow
3801 if ( item
!= m_current
)
3806 if ( HighlightLine(item
, on
) )
3813 int wxListMainWindow::GetItemState( long item
, long stateMask
) const
3815 wxCHECK_MSG( item
>= 0 && (size_t)item
< GetItemCount(), 0,
3816 _T("invalid list ctrl item index in GetItemState()") );
3818 int ret
= wxLIST_STATE_DONTCARE
;
3820 if ( stateMask
& wxLIST_STATE_FOCUSED
)
3822 if ( (size_t)item
== m_current
)
3823 ret
|= wxLIST_STATE_FOCUSED
;
3826 if ( stateMask
& wxLIST_STATE_SELECTED
)
3828 if ( IsHighlighted(item
) )
3829 ret
|= wxLIST_STATE_SELECTED
;
3835 void wxListMainWindow::GetItem( wxListItem
&item
) const
3837 wxCHECK_RET( item
.m_itemId
>= 0 && (size_t)item
.m_itemId
< GetItemCount(),
3838 _T("invalid item index in GetItem") );
3840 wxListLineData
*line
= GetLine((size_t)item
.m_itemId
);
3841 line
->GetItem( item
.m_col
, item
);
3843 // Get item state if user wants it
3844 if ( item
.m_mask
& wxLIST_MASK_STATE
)
3845 item
.m_state
= GetItemState( item
.m_itemId
, wxLIST_STATE_SELECTED
|
3846 wxLIST_STATE_FOCUSED
);
3849 // ----------------------------------------------------------------------------
3851 // ----------------------------------------------------------------------------
3853 size_t wxListMainWindow::GetItemCount() const
3855 return IsVirtual() ? m_countVirt
: m_lines
.GetCount();
3858 void wxListMainWindow::SetItemCount(long count
)
3860 m_selStore
.SetItemCount(count
);
3861 m_countVirt
= count
;
3863 ResetVisibleLinesRange();
3865 // scrollbars must be reset
3869 int wxListMainWindow::GetSelectedItemCount() const
3871 // deal with the quick case first
3872 if ( IsSingleSel() )
3873 return HasCurrent() ? IsHighlighted(m_current
) : false;
3875 // virtual controls remmebers all its selections itself
3877 return m_selStore
.GetSelectedCount();
3879 // TODO: we probably should maintain the number of items selected even for
3880 // non virtual controls as enumerating all lines is really slow...
3881 size_t countSel
= 0;
3882 size_t count
= GetItemCount();
3883 for ( size_t line
= 0; line
< count
; line
++ )
3885 if ( GetLine(line
)->IsHighlighted() )
3892 // ----------------------------------------------------------------------------
3893 // item position/size
3894 // ----------------------------------------------------------------------------
3896 wxRect
wxListMainWindow::GetViewRect() const
3898 wxASSERT_MSG( !HasFlag(wxLC_REPORT
| wxLC_LIST
),
3899 _T("wxListCtrl::GetViewRect() only works in icon mode") );
3901 // we need to find the longest/tallest label
3902 wxCoord xMax
= 0, yMax
= 0;
3903 const int count
= GetItemCount();
3906 for ( int i
= 0; i
< count
; i
++ )
3911 wxCoord x
= r
.GetRight(),
3921 // some fudge needed to make it look prettier
3922 xMax
+= 2 * EXTRA_BORDER_X
;
3923 yMax
+= 2 * EXTRA_BORDER_Y
;
3925 // account for the scrollbars if necessary
3926 const wxSize sizeAll
= GetClientSize();
3927 if ( xMax
> sizeAll
.x
)
3928 yMax
+= wxSystemSettings::GetMetric(wxSYS_HSCROLL_Y
);
3929 if ( yMax
> sizeAll
.y
)
3930 xMax
+= wxSystemSettings::GetMetric(wxSYS_VSCROLL_X
);
3932 return wxRect(0, 0, xMax
, yMax
);
3935 void wxListMainWindow::GetItemRect( long index
, wxRect
&rect
) const
3937 wxCHECK_RET( index
>= 0 && (size_t)index
< GetItemCount(),
3938 _T("invalid index in GetItemRect") );
3940 // ensure that we're laid out, otherwise we could return nonsense
3943 wxConstCast(this, wxListMainWindow
)->
3944 RecalculatePositions(true /* no refresh */);
3947 rect
= GetLineRect((size_t)index
);
3949 CalcScrolledPosition(rect
.x
, rect
.y
, &rect
.x
, &rect
.y
);
3952 bool wxListMainWindow::GetItemPosition(long item
, wxPoint
& pos
) const
3955 GetItemRect(item
, rect
);
3963 // ----------------------------------------------------------------------------
3964 // geometry calculation
3965 // ----------------------------------------------------------------------------
3967 void wxListMainWindow::RecalculatePositions(bool noRefresh
)
3969 const int lineHeight
= GetLineHeight();
3971 wxClientDC
dc( this );
3972 dc
.SetFont( GetFont() );
3974 const size_t count
= GetItemCount();
3977 if ( HasFlag(wxLC_ICON
) )
3978 iconSpacing
= m_normal_spacing
;
3979 else if ( HasFlag(wxLC_SMALL_ICON
) )
3980 iconSpacing
= m_small_spacing
;
3984 // Note that we do not call GetClientSize() here but
3985 // GetSize() and subtract the border size for sunken
3986 // borders manually. This is technically incorrect,
3987 // but we need to know the client area's size WITHOUT
3988 // scrollbars here. Since we don't know if there are
3989 // any scrollbars, we use GetSize() instead. Another
3990 // solution would be to call SetScrollbars() here to
3991 // remove the scrollbars and call GetClientSize() then,
3992 // but this might result in flicker and - worse - will
3993 // reset the scrollbars to 0 which is not good at all
3994 // if you resize a dialog/window, but don't want to
3995 // reset the window scrolling. RR.
3996 // Furthermore, we actually do NOT subtract the border
3997 // width as 2 pixels is just the extra space which we
3998 // need around the actual content in the window. Other-
3999 // wise the text would e.g. touch the upper border. RR.
4002 GetSize( &clientWidth
, &clientHeight
);
4004 if ( InReportView() )
4006 // all lines have the same height and we scroll one line per step
4007 int entireHeight
= count
* lineHeight
+ LINE_SPACING
;
4009 m_linesPerPage
= clientHeight
/ lineHeight
;
4011 ResetVisibleLinesRange();
4013 SetScrollbars( SCROLL_UNIT_X
, lineHeight
,
4014 GetHeaderWidth() / SCROLL_UNIT_X
,
4015 (entireHeight
+ lineHeight
- 1) / lineHeight
,
4016 GetScrollPos(wxHORIZONTAL
),
4017 GetScrollPos(wxVERTICAL
),
4022 // we have 3 different layout strategies: either layout all items
4023 // horizontally/vertically (wxLC_ALIGN_XXX styles explicitly given) or
4024 // to arrange them in top to bottom, left to right (don't ask me why
4025 // not the other way round...) order
4026 if ( HasFlag(wxLC_ALIGN_LEFT
| wxLC_ALIGN_TOP
) )
4028 int x
= EXTRA_BORDER_X
;
4029 int y
= EXTRA_BORDER_Y
;
4031 wxCoord widthMax
= 0;
4034 for ( i
= 0; i
< count
; i
++ )
4036 wxListLineData
*line
= GetLine(i
);
4037 line
->CalculateSize( &dc
, iconSpacing
);
4038 line
->SetPosition( x
, y
, iconSpacing
);
4040 wxSize sizeLine
= GetLineSize(i
);
4042 if ( HasFlag(wxLC_ALIGN_TOP
) )
4044 if ( sizeLine
.x
> widthMax
)
4045 widthMax
= sizeLine
.x
;
4049 else // wxLC_ALIGN_LEFT
4051 x
+= sizeLine
.x
+ MARGIN_BETWEEN_ROWS
;
4055 if ( HasFlag(wxLC_ALIGN_TOP
) )
4057 // traverse the items again and tweak their sizes so that they are
4058 // all the same in a row
4059 for ( i
= 0; i
< count
; i
++ )
4061 wxListLineData
*line
= GetLine(i
);
4062 line
->m_gi
->ExtendWidth(widthMax
);
4070 (x
+ SCROLL_UNIT_X
) / SCROLL_UNIT_X
,
4071 (y
+ lineHeight
) / lineHeight
,
4072 GetScrollPos( wxHORIZONTAL
),
4073 GetScrollPos( wxVERTICAL
),
4077 else // "flowed" arrangement, the most complicated case
4079 // at first we try without any scrollbars, if the items don't fit into
4080 // the window, we recalculate after subtracting the space taken by the
4083 int entireWidth
= 0;
4085 for (int tries
= 0; tries
< 2; tries
++)
4087 entireWidth
= 2 * EXTRA_BORDER_X
;
4091 // Now we have decided that the items do not fit into the
4092 // client area, so we need a scrollbar
4093 entireWidth
+= SCROLL_UNIT_X
;
4096 int x
= EXTRA_BORDER_X
;
4097 int y
= EXTRA_BORDER_Y
;
4098 int maxWidthInThisRow
= 0;
4101 int currentlyVisibleLines
= 0;
4103 for (size_t i
= 0; i
< count
; i
++)
4105 currentlyVisibleLines
++;
4106 wxListLineData
*line
= GetLine( i
);
4107 line
->CalculateSize( &dc
, iconSpacing
);
4108 line
->SetPosition( x
, y
, iconSpacing
);
4110 wxSize sizeLine
= GetLineSize( i
);
4112 if ( maxWidthInThisRow
< sizeLine
.x
)
4113 maxWidthInThisRow
= sizeLine
.x
;
4116 if (currentlyVisibleLines
> m_linesPerPage
)
4117 m_linesPerPage
= currentlyVisibleLines
;
4119 if ( y
+ sizeLine
.y
>= clientHeight
)
4121 currentlyVisibleLines
= 0;
4123 maxWidthInThisRow
+= MARGIN_BETWEEN_ROWS
;
4124 x
+= maxWidthInThisRow
;
4125 entireWidth
+= maxWidthInThisRow
;
4126 maxWidthInThisRow
= 0;
4129 // We have reached the last item.
4130 if ( i
== count
- 1 )
4131 entireWidth
+= maxWidthInThisRow
;
4133 if ( (tries
== 0) &&
4134 (entireWidth
+ SCROLL_UNIT_X
> clientWidth
) )
4136 clientHeight
-= wxSystemSettings::
4137 GetMetric(wxSYS_HSCROLL_Y
);
4142 if ( i
== count
- 1 )
4143 tries
= 1; // Everything fits, no second try required.
4151 (entireWidth
+ SCROLL_UNIT_X
) / SCROLL_UNIT_X
,
4153 GetScrollPos( wxHORIZONTAL
),
4162 // FIXME: why should we call it from here?
4169 void wxListMainWindow::RefreshAll()
4174 wxListHeaderWindow
*headerWin
= GetListCtrl()->m_headerWin
;
4175 if ( headerWin
&& headerWin
->m_dirty
)
4177 headerWin
->m_dirty
= false;
4178 headerWin
->Refresh();
4182 void wxListMainWindow::UpdateCurrent()
4184 if ( !HasCurrent() && !IsEmpty() )
4188 long wxListMainWindow::GetNextItem( long item
,
4189 int WXUNUSED(geometry
),
4193 max
= GetItemCount();
4194 wxCHECK_MSG( (ret
== -1) || (ret
< max
), -1,
4195 _T("invalid listctrl index in GetNextItem()") );
4197 // notice that we start with the next item (or the first one if item == -1)
4198 // and this is intentional to allow writing a simple loop to iterate over
4199 // all selected items
4202 // this is not an error because the index was OK initially,
4203 // just no such item
4210 size_t count
= GetItemCount();
4211 for ( size_t line
= (size_t)ret
; line
< count
; line
++ )
4213 if ( (state
& wxLIST_STATE_FOCUSED
) && (line
== m_current
) )
4216 if ( (state
& wxLIST_STATE_SELECTED
) && IsHighlighted(line
) )
4223 // ----------------------------------------------------------------------------
4225 // ----------------------------------------------------------------------------
4227 void wxListMainWindow::DeleteItem( long lindex
)
4229 size_t count
= GetItemCount();
4231 wxCHECK_RET( (lindex
>= 0) && ((size_t)lindex
< count
),
4232 _T("invalid item index in DeleteItem") );
4234 size_t index
= (size_t)lindex
;
4236 // we don't need to adjust the index for the previous items
4237 if ( HasCurrent() && m_current
>= index
)
4239 // if the current item is being deleted, we want the next one to
4240 // become selected - unless there is no next one - so don't adjust
4241 // m_current in this case
4242 if ( m_current
!= index
|| m_current
== count
- 1 )
4246 if ( InReportView() )
4248 // mark the Column Max Width cache as dirty if the items in the line
4249 // we're deleting contain the Max Column Width
4250 wxListLineData
* const line
= GetLine(index
);
4251 wxListItemDataList::compatibility_iterator n
;
4252 wxListItemData
*itemData
;
4256 for (size_t i
= 0; i
< m_columns
.GetCount(); i
++)
4258 n
= line
->m_items
.Item( i
);
4259 itemData
= n
->GetData();
4260 itemData
->GetItem(item
);
4262 itemWidth
= GetItemWidthWithImage(&item
);
4264 if (itemWidth
>= m_aColWidths
.Item(i
)->nMaxWidth
)
4265 m_aColWidths
.Item(i
)->bNeedsUpdate
= true;
4268 ResetVisibleLinesRange();
4274 m_selStore
.OnItemDelete(index
);
4278 m_lines
.RemoveAt( index
);
4281 // we need to refresh the (vert) scrollbar as the number of items changed
4284 SendNotify( index
, wxEVT_COMMAND_LIST_DELETE_ITEM
);
4286 RefreshAfter(index
);
4289 void wxListMainWindow::DeleteColumn( int col
)
4291 wxListHeaderDataList::compatibility_iterator node
= m_columns
.Item( col
);
4293 wxCHECK_RET( node
, wxT("invalid column index in DeleteColumn()") );
4296 delete node
->GetData();
4297 m_columns
.Erase( node
);
4301 // update all the items
4302 for ( size_t i
= 0; i
< m_lines
.GetCount(); i
++ )
4304 wxListLineData
* const line
= GetLine(i
);
4305 wxListItemDataList::compatibility_iterator n
= line
->m_items
.Item( col
);
4306 delete n
->GetData();
4307 line
->m_items
.Erase(n
);
4311 if ( InReportView() ) // we only cache max widths when in Report View
4313 delete m_aColWidths
.Item(col
);
4314 m_aColWidths
.RemoveAt(col
);
4317 // invalidate it as it has to be recalculated
4321 void wxListMainWindow::DoDeleteAllItems()
4324 // nothing to do - in particular, don't send the event
4329 // to make the deletion of all items faster, we don't send the
4330 // notifications for each item deletion in this case but only one event
4331 // for all of them: this is compatible with wxMSW and documented in
4332 // DeleteAllItems() description
4334 wxListEvent
event( wxEVT_COMMAND_LIST_DELETE_ALL_ITEMS
, GetParent()->GetId() );
4335 event
.SetEventObject( GetParent() );
4336 GetParent()->GetEventHandler()->ProcessEvent( event
);
4344 if ( InReportView() )
4346 ResetVisibleLinesRange();
4347 for (size_t i
= 0; i
< m_aColWidths
.GetCount(); i
++)
4349 m_aColWidths
.Item(i
)->bNeedsUpdate
= true;
4356 void wxListMainWindow::DeleteAllItems()
4360 RecalculatePositions();
4363 void wxListMainWindow::DeleteEverything()
4365 WX_CLEAR_LIST(wxListHeaderDataList
, m_columns
);
4366 WX_CLEAR_ARRAY(m_aColWidths
);
4371 // ----------------------------------------------------------------------------
4372 // scanning for an item
4373 // ----------------------------------------------------------------------------
4375 void wxListMainWindow::EnsureVisible( long index
)
4377 wxCHECK_RET( index
>= 0 && (size_t)index
< GetItemCount(),
4378 _T("invalid index in EnsureVisible") );
4380 // We have to call this here because the label in question might just have
4381 // been added and its position is not known yet
4383 RecalculatePositions(true /* no refresh */);
4385 MoveToItem((size_t)index
);
4388 long wxListMainWindow::FindItem(long start
, const wxString
& str
, bool WXUNUSED(partial
) )
4395 size_t count
= GetItemCount();
4396 for ( size_t i
= (size_t)pos
; i
< count
; i
++ )
4398 wxListLineData
*line
= GetLine(i
);
4399 if ( line
->GetText(0) == tmp
)
4406 long wxListMainWindow::FindItem(long start
, wxUIntPtr data
)
4412 size_t count
= GetItemCount();
4413 for (size_t i
= (size_t)pos
; i
< count
; i
++)
4415 wxListLineData
*line
= GetLine(i
);
4417 line
->GetItem( 0, item
);
4418 if (item
.m_data
== data
)
4425 long wxListMainWindow::FindItem( const wxPoint
& pt
)
4428 GetVisibleLinesRange( &topItem
, NULL
);
4431 GetItemPosition( GetItemCount() - 1, p
);
4435 long id
= (long)floor( pt
.y
* double(GetItemCount() - topItem
- 1) / p
.y
+ topItem
);
4436 if ( id
>= 0 && id
< (long)GetItemCount() )
4442 long wxListMainWindow::HitTest( int x
, int y
, int &flags
) const
4444 CalcUnscrolledPosition( x
, y
, &x
, &y
);
4446 size_t count
= GetItemCount();
4448 if ( InReportView() )
4450 size_t current
= y
/ GetLineHeight();
4451 if ( current
< count
)
4453 flags
= HitTestLine(current
, x
, y
);
4460 // TODO: optimize it too! this is less simple than for report view but
4461 // enumerating all items is still not a way to do it!!
4462 for ( size_t current
= 0; current
< count
; current
++ )
4464 flags
= HitTestLine(current
, x
, y
);
4473 // ----------------------------------------------------------------------------
4475 // ----------------------------------------------------------------------------
4477 void wxListMainWindow::InsertItem( wxListItem
&item
)
4479 wxASSERT_MSG( !IsVirtual(), _T("can't be used with virtual control") );
4481 int count
= GetItemCount();
4482 wxCHECK_RET( item
.m_itemId
>= 0, _T("invalid item index") );
4484 if (item
.m_itemId
> count
)
4485 item
.m_itemId
= count
;
4487 size_t id
= item
.m_itemId
;
4491 if ( InReportView() )
4493 ResetVisibleLinesRange();
4495 // calculate the width of the item and adjust the max column width
4496 wxColWidthInfo
*pWidthInfo
= m_aColWidths
.Item(item
.GetColumn());
4497 int width
= GetItemWidthWithImage(&item
);
4498 item
.SetWidth(width
);
4499 if (width
> pWidthInfo
->nMaxWidth
)
4500 pWidthInfo
->nMaxWidth
= width
;
4503 wxListLineData
*line
= new wxListLineData(this);
4505 line
->SetItem( item
.m_col
, item
);
4507 m_lines
.Insert( line
, id
);
4511 // If an item is selected at or below the point of insertion, we need to
4512 // increment the member variables because the current row's index has gone
4514 if ( HasCurrent() && m_current
>= id
)
4517 SendNotify(id
, wxEVT_COMMAND_LIST_INSERT_ITEM
);
4519 RefreshLines(id
, GetItemCount() - 1);
4522 void wxListMainWindow::InsertColumn( long col
, wxListItem
&item
)
4525 if ( InReportView() )
4527 if (item
.m_width
== wxLIST_AUTOSIZE_USEHEADER
)
4528 item
.m_width
= GetTextLength( item
.m_text
);
4530 wxListHeaderData
*column
= new wxListHeaderData( item
);
4531 wxColWidthInfo
*colWidthInfo
= new wxColWidthInfo();
4533 bool insert
= (col
>= 0) && ((size_t)col
< m_columns
.GetCount());
4536 wxListHeaderDataList::compatibility_iterator
4537 node
= m_columns
.Item( col
);
4538 m_columns
.Insert( node
, column
);
4539 m_aColWidths
.Insert( colWidthInfo
, col
);
4543 m_columns
.Append( column
);
4544 m_aColWidths
.Add( colWidthInfo
);
4549 // update all the items
4550 for ( size_t i
= 0; i
< m_lines
.GetCount(); i
++ )
4552 wxListLineData
* const line
= GetLine(i
);
4553 wxListItemData
* const data
= new wxListItemData(this);
4555 line
->m_items
.Insert(col
, data
);
4557 line
->m_items
.Append(data
);
4561 // invalidate it as it has to be recalculated
4566 int wxListMainWindow::GetItemWidthWithImage(wxListItem
* item
)
4569 wxClientDC
dc(this);
4571 dc
.SetFont( GetFont() );
4573 if (item
->GetImage() != -1)
4576 GetImageSize( item
->GetImage(), ix
, iy
);
4580 if (!item
->GetText().empty())
4583 dc
.GetTextExtent( item
->GetText(), &w
, NULL
);
4590 // ----------------------------------------------------------------------------
4592 // ----------------------------------------------------------------------------
4594 wxListCtrlCompare list_ctrl_compare_func_2
;
4595 long list_ctrl_compare_data
;
4597 int LINKAGEMODE
list_ctrl_compare_func_1( wxListLineData
**arg1
, wxListLineData
**arg2
)
4599 wxListLineData
*line1
= *arg1
;
4600 wxListLineData
*line2
= *arg2
;
4602 line1
->GetItem( 0, item
);
4603 wxUIntPtr data1
= item
.m_data
;
4604 line2
->GetItem( 0, item
);
4605 wxUIntPtr data2
= item
.m_data
;
4606 return list_ctrl_compare_func_2( data1
, data2
, list_ctrl_compare_data
);
4609 void wxListMainWindow::SortItems( wxListCtrlCompare fn
, long data
)
4611 list_ctrl_compare_func_2
= fn
;
4612 list_ctrl_compare_data
= data
;
4613 m_lines
.Sort( list_ctrl_compare_func_1
);
4617 // ----------------------------------------------------------------------------
4619 // ----------------------------------------------------------------------------
4621 void wxListMainWindow::OnScroll(wxScrollWinEvent
& event
)
4623 // update our idea of which lines are shown when we redraw the window the
4625 ResetVisibleLinesRange();
4628 #if ( defined(__WXGTK__) || defined(__WXMAC__) ) && !defined(__WXUNIVERSAL__)
4629 wxScrolledWindow::OnScroll(event
);
4631 HandleOnScroll( event
);
4634 if ( event
.GetOrientation() == wxHORIZONTAL
&& HasHeader() )
4636 wxGenericListCtrl
* lc
= GetListCtrl();
4637 wxCHECK_RET( lc
, _T("no listctrl window?") );
4639 lc
->m_headerWin
->Refresh();
4640 lc
->m_headerWin
->Update();
4644 int wxListMainWindow::GetCountPerPage() const
4646 if ( !m_linesPerPage
)
4648 wxConstCast(this, wxListMainWindow
)->
4649 m_linesPerPage
= GetClientSize().y
/ GetLineHeight();
4652 return m_linesPerPage
;
4655 void wxListMainWindow::GetVisibleLinesRange(size_t *from
, size_t *to
)
4657 wxASSERT_MSG( InReportView(), _T("this is for report mode only") );
4659 if ( m_lineFrom
== (size_t)-1 )
4661 size_t count
= GetItemCount();
4664 m_lineFrom
= GetScrollPos(wxVERTICAL
);
4666 // this may happen if SetScrollbars() hadn't been called yet
4667 if ( m_lineFrom
>= count
)
4668 m_lineFrom
= count
- 1;
4670 // we redraw one extra line but this is needed to make the redrawing
4671 // logic work when there is a fractional number of lines on screen
4672 m_lineTo
= m_lineFrom
+ m_linesPerPage
;
4673 if ( m_lineTo
>= count
)
4674 m_lineTo
= count
- 1;
4676 else // empty control
4679 m_lineTo
= (size_t)-1;
4683 wxASSERT_MSG( IsEmpty() ||
4684 (m_lineFrom
<= m_lineTo
&& m_lineTo
< GetItemCount()),
4685 _T("GetVisibleLinesRange() returns incorrect result") );
4693 // -------------------------------------------------------------------------------------
4694 // wxGenericListCtrl
4695 // -------------------------------------------------------------------------------------
4697 IMPLEMENT_DYNAMIC_CLASS(wxGenericListCtrl
, wxControl
)
4699 BEGIN_EVENT_TABLE(wxGenericListCtrl
,wxControl
)
4700 EVT_SIZE(wxGenericListCtrl::OnSize
)
4703 wxGenericListCtrl::wxGenericListCtrl()
4705 m_imageListNormal
= (wxImageList
*) NULL
;
4706 m_imageListSmall
= (wxImageList
*) NULL
;
4707 m_imageListState
= (wxImageList
*) NULL
;
4709 m_ownsImageListNormal
=
4710 m_ownsImageListSmall
=
4711 m_ownsImageListState
= false;
4713 m_mainWin
= (wxListMainWindow
*) NULL
;
4714 m_headerWin
= (wxListHeaderWindow
*) NULL
;
4718 wxGenericListCtrl::~wxGenericListCtrl()
4720 if (m_ownsImageListNormal
)
4721 delete m_imageListNormal
;
4722 if (m_ownsImageListSmall
)
4723 delete m_imageListSmall
;
4724 if (m_ownsImageListState
)
4725 delete m_imageListState
;
4728 void wxGenericListCtrl::CalculateAndSetHeaderHeight()
4734 GetThemeMetric( kThemeMetricListHeaderHeight
, &h
);
4736 // we use 'g' to get the descent, too
4738 m_headerWin
->GetTextExtent(wxT("Hg"), &w
, &h
, &d
);
4739 h
+= d
+ 2 * HEADER_OFFSET_Y
+ EXTRA_HEIGHT
;
4742 // only update if changed
4743 if ( h
!= m_headerHeight
)
4748 ResizeReportView(true);
4749 else //why is this needed if it doesn't have a header?
4750 m_headerWin
->SetSize(m_headerWin
->GetSize().x
, m_headerHeight
);
4755 void wxGenericListCtrl::CreateHeaderWindow()
4757 m_headerWin
= new wxListHeaderWindow
4759 this, wxID_ANY
, m_mainWin
,
4761 wxSize(GetClientSize().x
, m_headerHeight
),
4764 CalculateAndSetHeaderHeight();
4767 bool wxGenericListCtrl::Create(wxWindow
*parent
,
4772 const wxValidator
&validator
,
4773 const wxString
&name
)
4777 m_imageListState
= (wxImageList
*) NULL
;
4778 m_ownsImageListNormal
=
4779 m_ownsImageListSmall
=
4780 m_ownsImageListState
= false;
4782 m_mainWin
= (wxListMainWindow
*) NULL
;
4783 m_headerWin
= (wxListHeaderWindow
*) NULL
;
4787 if ( !(style
& wxLC_MASK_TYPE
) )
4789 style
= style
| wxLC_LIST
;
4792 if ( !wxControl::Create( parent
, id
, pos
, size
, style
, validator
, name
) )
4795 // don't create the inner window with the border
4796 style
&= ~wxBORDER_MASK
;
4798 m_mainWin
= new wxListMainWindow( this, wxID_ANY
, wxPoint(0, 0), size
, style
);
4800 #ifdef __WXMAC_CARBON__
4801 // Human Interface Guidelines ask us for a special font in this case
4802 if ( GetWindowVariant() == wxWINDOW_VARIANT_NORMAL
)
4805 font
.MacCreateThemeFont( kThemeViewsFont
);
4810 if ( InReportView() )
4812 CreateHeaderWindow();
4814 #ifdef __WXMAC_CARBON__
4818 font
.MacCreateThemeFont( kThemeSmallSystemFont
);
4819 m_headerWin
->SetFont( font
);
4820 CalculateAndSetHeaderHeight();
4824 if ( HasFlag(wxLC_NO_HEADER
) )
4825 // VZ: why do we create it at all then?
4826 m_headerWin
->Show( false );
4834 void wxGenericListCtrl::SetSingleStyle( long style
, bool add
)
4836 wxASSERT_MSG( !(style
& wxLC_VIRTUAL
),
4837 _T("wxLC_VIRTUAL can't be [un]set") );
4839 long flag
= GetWindowStyle();
4843 if (style
& wxLC_MASK_TYPE
)
4844 flag
&= ~(wxLC_MASK_TYPE
| wxLC_VIRTUAL
);
4845 if (style
& wxLC_MASK_ALIGN
)
4846 flag
&= ~wxLC_MASK_ALIGN
;
4847 if (style
& wxLC_MASK_SORT
)
4848 flag
&= ~wxLC_MASK_SORT
;
4856 SetWindowStyleFlag( flag
);
4859 void wxGenericListCtrl::SetWindowStyleFlag( long flag
)
4863 m_mainWin
->DeleteEverything();
4865 // has the header visibility changed?
4866 bool hasHeader
= HasHeader();
4867 bool willHaveHeader
= (flag
& wxLC_REPORT
) && !(flag
& wxLC_NO_HEADER
);
4869 if ( hasHeader
!= willHaveHeader
)
4876 // don't delete, just hide, as we can reuse it later
4877 m_headerWin
->Show(false);
4879 //else: nothing to do
4881 else // must show header
4885 CreateHeaderWindow();
4887 else // already have it, just show
4889 m_headerWin
->Show( true );
4893 ResizeReportView(willHaveHeader
);
4897 wxWindow::SetWindowStyleFlag( flag
);
4900 bool wxGenericListCtrl::GetColumn(int col
, wxListItem
&item
) const
4902 m_mainWin
->GetColumn( col
, item
);
4906 bool wxGenericListCtrl::SetColumn( int col
, wxListItem
& item
)
4908 m_mainWin
->SetColumn( col
, item
);
4912 int wxGenericListCtrl::GetColumnWidth( int col
) const
4914 return m_mainWin
->GetColumnWidth( col
);
4917 bool wxGenericListCtrl::SetColumnWidth( int col
, int width
)
4919 m_mainWin
->SetColumnWidth( col
, width
);
4923 int wxGenericListCtrl::GetCountPerPage() const
4925 return m_mainWin
->GetCountPerPage(); // different from Windows ?
4928 bool wxGenericListCtrl::GetItem( wxListItem
&info
) const
4930 m_mainWin
->GetItem( info
);
4934 bool wxGenericListCtrl::SetItem( wxListItem
&info
)
4936 m_mainWin
->SetItem( info
);
4940 long wxGenericListCtrl::SetItem( long index
, int col
, const wxString
& label
, int imageId
)
4943 info
.m_text
= label
;
4944 info
.m_mask
= wxLIST_MASK_TEXT
;
4945 info
.m_itemId
= index
;
4949 info
.m_image
= imageId
;
4950 info
.m_mask
|= wxLIST_MASK_IMAGE
;
4953 m_mainWin
->SetItem(info
);
4957 int wxGenericListCtrl::GetItemState( long item
, long stateMask
) const
4959 return m_mainWin
->GetItemState( item
, stateMask
);
4962 bool wxGenericListCtrl::SetItemState( long item
, long state
, long stateMask
)
4964 m_mainWin
->SetItemState( item
, state
, stateMask
);
4969 wxGenericListCtrl::SetItemImage( long item
, int image
, int WXUNUSED(selImage
) )
4971 return SetItemColumnImage(item
, 0, image
);
4975 wxGenericListCtrl::SetItemColumnImage( long item
, long column
, int image
)
4978 info
.m_image
= image
;
4979 info
.m_mask
= wxLIST_MASK_IMAGE
;
4980 info
.m_itemId
= item
;
4981 info
.m_col
= column
;
4982 m_mainWin
->SetItem( info
);
4986 wxString
wxGenericListCtrl::GetItemText( long item
) const
4988 return m_mainWin
->GetItemText(item
);
4991 void wxGenericListCtrl::SetItemText( long item
, const wxString
& str
)
4993 m_mainWin
->SetItemText(item
, str
);
4996 wxUIntPtr
wxGenericListCtrl::GetItemData( long item
) const
4999 info
.m_mask
= wxLIST_MASK_DATA
;
5000 info
.m_itemId
= item
;
5001 m_mainWin
->GetItem( info
);
5005 bool wxGenericListCtrl::SetItemData( long item
, long data
)
5008 info
.m_mask
= wxLIST_MASK_DATA
;
5009 info
.m_itemId
= item
;
5011 m_mainWin
->SetItem( info
);
5015 wxRect
wxGenericListCtrl::GetViewRect() const
5017 return m_mainWin
->GetViewRect();
5020 bool wxGenericListCtrl::GetItemRect( long item
, wxRect
&rect
, int WXUNUSED(code
) ) const
5022 m_mainWin
->GetItemRect( item
, rect
);
5023 if ( m_mainWin
->HasHeader() )
5024 rect
.y
+= m_headerHeight
+ 1;
5028 bool wxGenericListCtrl::GetItemPosition( long item
, wxPoint
& pos
) const
5030 m_mainWin
->GetItemPosition( item
, pos
);
5034 bool wxGenericListCtrl::SetItemPosition( long WXUNUSED(item
), const wxPoint
& WXUNUSED(pos
) )
5039 int wxGenericListCtrl::GetItemCount() const
5041 return m_mainWin
->GetItemCount();
5044 int wxGenericListCtrl::GetColumnCount() const
5046 return m_mainWin
->GetColumnCount();
5049 void wxGenericListCtrl::SetItemSpacing( int spacing
, bool isSmall
)
5051 m_mainWin
->SetItemSpacing( spacing
, isSmall
);
5054 wxSize
wxGenericListCtrl::GetItemSpacing() const
5056 const int spacing
= m_mainWin
->GetItemSpacing(HasFlag(wxLC_SMALL_ICON
));
5058 return wxSize(spacing
, spacing
);
5061 #if WXWIN_COMPATIBILITY_2_6
5062 int wxGenericListCtrl::GetItemSpacing( bool isSmall
) const
5064 return m_mainWin
->GetItemSpacing( isSmall
);
5066 #endif // WXWIN_COMPATIBILITY_2_6
5068 void wxGenericListCtrl::SetItemTextColour( long item
, const wxColour
&col
)
5071 info
.m_itemId
= item
;
5072 info
.SetTextColour( col
);
5073 m_mainWin
->SetItem( info
);
5076 wxColour
wxGenericListCtrl::GetItemTextColour( long item
) const
5079 info
.m_itemId
= item
;
5080 m_mainWin
->GetItem( info
);
5081 return info
.GetTextColour();
5084 void wxGenericListCtrl::SetItemBackgroundColour( long item
, const wxColour
&col
)
5087 info
.m_itemId
= item
;
5088 info
.SetBackgroundColour( col
);
5089 m_mainWin
->SetItem( info
);
5092 wxColour
wxGenericListCtrl::GetItemBackgroundColour( long item
) const
5095 info
.m_itemId
= item
;
5096 m_mainWin
->GetItem( info
);
5097 return info
.GetBackgroundColour();
5100 void wxGenericListCtrl::SetItemFont( long item
, const wxFont
&f
)
5103 info
.m_itemId
= item
;
5105 m_mainWin
->SetItem( info
);
5108 wxFont
wxGenericListCtrl::GetItemFont( long item
) const
5111 info
.m_itemId
= item
;
5112 m_mainWin
->GetItem( info
);
5113 return info
.GetFont();
5116 int wxGenericListCtrl::GetSelectedItemCount() const
5118 return m_mainWin
->GetSelectedItemCount();
5121 wxColour
wxGenericListCtrl::GetTextColour() const
5123 return GetForegroundColour();
5126 void wxGenericListCtrl::SetTextColour(const wxColour
& col
)
5128 SetForegroundColour(col
);
5131 long wxGenericListCtrl::GetTopItem() const
5134 m_mainWin
->GetVisibleLinesRange(&top
, NULL
);
5138 long wxGenericListCtrl::GetNextItem( long item
, int geom
, int state
) const
5140 return m_mainWin
->GetNextItem( item
, geom
, state
);
5143 wxImageList
*wxGenericListCtrl::GetImageList(int which
) const
5145 if (which
== wxIMAGE_LIST_NORMAL
)
5146 return m_imageListNormal
;
5147 else if (which
== wxIMAGE_LIST_SMALL
)
5148 return m_imageListSmall
;
5149 else if (which
== wxIMAGE_LIST_STATE
)
5150 return m_imageListState
;
5152 return (wxImageList
*) NULL
;
5155 void wxGenericListCtrl::SetImageList( wxImageList
*imageList
, int which
)
5157 if ( which
== wxIMAGE_LIST_NORMAL
)
5159 if (m_ownsImageListNormal
)
5160 delete m_imageListNormal
;
5161 m_imageListNormal
= imageList
;
5162 m_ownsImageListNormal
= false;
5164 else if ( which
== wxIMAGE_LIST_SMALL
)
5166 if (m_ownsImageListSmall
)
5167 delete m_imageListSmall
;
5168 m_imageListSmall
= imageList
;
5169 m_ownsImageListSmall
= false;
5171 else if ( which
== wxIMAGE_LIST_STATE
)
5173 if (m_ownsImageListState
)
5174 delete m_imageListState
;
5175 m_imageListState
= imageList
;
5176 m_ownsImageListState
= false;
5179 m_mainWin
->SetImageList( imageList
, which
);
5182 void wxGenericListCtrl::AssignImageList(wxImageList
*imageList
, int which
)
5184 SetImageList(imageList
, which
);
5185 if ( which
== wxIMAGE_LIST_NORMAL
)
5186 m_ownsImageListNormal
= true;
5187 else if ( which
== wxIMAGE_LIST_SMALL
)
5188 m_ownsImageListSmall
= true;
5189 else if ( which
== wxIMAGE_LIST_STATE
)
5190 m_ownsImageListState
= true;
5193 bool wxGenericListCtrl::Arrange( int WXUNUSED(flag
) )
5198 bool wxGenericListCtrl::DeleteItem( long item
)
5200 m_mainWin
->DeleteItem( item
);
5204 bool wxGenericListCtrl::DeleteAllItems()
5206 m_mainWin
->DeleteAllItems();
5210 bool wxGenericListCtrl::DeleteAllColumns()
5212 size_t count
= m_mainWin
->m_columns
.GetCount();
5213 for ( size_t n
= 0; n
< count
; n
++ )
5218 void wxGenericListCtrl::ClearAll()
5220 m_mainWin
->DeleteEverything();
5223 bool wxGenericListCtrl::DeleteColumn( int col
)
5225 m_mainWin
->DeleteColumn( col
);
5227 // if we don't have the header any longer, we need to relayout the window
5228 if ( !GetColumnCount() )
5229 ResizeReportView(false /* no header */);
5233 wxTextCtrl
*wxGenericListCtrl::EditLabel(long item
,
5234 wxClassInfo
* textControlClass
)
5236 return m_mainWin
->EditLabel( item
, textControlClass
);
5239 wxTextCtrl
*wxGenericListCtrl::GetEditControl() const
5241 return m_mainWin
->GetEditControl();
5244 bool wxGenericListCtrl::EnsureVisible( long item
)
5246 m_mainWin
->EnsureVisible( item
);
5250 long wxGenericListCtrl::FindItem( long start
, const wxString
& str
, bool partial
)
5252 return m_mainWin
->FindItem( start
, str
, partial
);
5255 long wxGenericListCtrl::FindItem( long start
, wxUIntPtr data
)
5257 return m_mainWin
->FindItem( start
, data
);
5260 long wxGenericListCtrl::FindItem( long WXUNUSED(start
), const wxPoint
& pt
,
5261 int WXUNUSED(direction
))
5263 return m_mainWin
->FindItem( pt
);
5266 // TODO: sub item hit testing
5267 long wxGenericListCtrl::HitTest(const wxPoint
& point
, int& flags
, long *) const
5269 return m_mainWin
->HitTest( (int)point
.x
, (int)point
.y
, flags
);
5272 long wxGenericListCtrl::InsertItem( wxListItem
& info
)
5274 m_mainWin
->InsertItem( info
);
5275 return info
.m_itemId
;
5278 long wxGenericListCtrl::InsertItem( long index
, const wxString
&label
)
5281 info
.m_text
= label
;
5282 info
.m_mask
= wxLIST_MASK_TEXT
;
5283 info
.m_itemId
= index
;
5284 return InsertItem( info
);
5287 long wxGenericListCtrl::InsertItem( long index
, int imageIndex
)
5290 info
.m_mask
= wxLIST_MASK_IMAGE
;
5291 info
.m_image
= imageIndex
;
5292 info
.m_itemId
= index
;
5293 return InsertItem( info
);
5296 long wxGenericListCtrl::InsertItem( long index
, const wxString
&label
, int imageIndex
)
5299 info
.m_text
= label
;
5300 info
.m_image
= imageIndex
;
5301 info
.m_mask
= wxLIST_MASK_TEXT
| wxLIST_MASK_IMAGE
;
5302 info
.m_itemId
= index
;
5303 return InsertItem( info
);
5306 long wxGenericListCtrl::InsertColumn( long col
, wxListItem
&item
)
5308 wxCHECK_MSG( m_headerWin
, -1, _T("can't add column in non report mode") );
5310 m_mainWin
->InsertColumn( col
, item
);
5312 // if we hadn't had a header before but have one now
5313 // then we need to relayout the window
5314 if ( GetColumnCount() == 1 && m_mainWin
->HasHeader() )
5315 ResizeReportView(true /* have header */);
5317 m_headerWin
->Refresh();
5322 long wxGenericListCtrl::InsertColumn( long col
, const wxString
&heading
,
5323 int format
, int width
)
5326 item
.m_mask
= wxLIST_MASK_TEXT
| wxLIST_MASK_FORMAT
;
5327 item
.m_text
= heading
;
5330 item
.m_mask
|= wxLIST_MASK_WIDTH
;
5331 item
.m_width
= width
;
5334 item
.m_format
= format
;
5336 return InsertColumn( col
, item
);
5339 bool wxGenericListCtrl::ScrollList( int WXUNUSED(dx
), int WXUNUSED(dy
) )
5345 // fn is a function which takes 3 long arguments: item1, item2, data.
5346 // item1 is the long data associated with a first item (NOT the index).
5347 // item2 is the long data associated with a second item (NOT the index).
5348 // data is the same value as passed to SortItems.
5349 // The return value is a negative number if the first item should precede the second
5350 // item, a positive number of the second item should precede the first,
5351 // or zero if the two items are equivalent.
5352 // data is arbitrary data to be passed to the sort function.
5354 bool wxGenericListCtrl::SortItems( wxListCtrlCompare fn
, long data
)
5356 m_mainWin
->SortItems( fn
, data
);
5360 // ----------------------------------------------------------------------------
5362 // ----------------------------------------------------------------------------
5364 void wxGenericListCtrl::OnSize(wxSizeEvent
& WXUNUSED(event
))
5369 ResizeReportView(m_mainWin
->HasHeader());
5370 m_mainWin
->RecalculatePositions();
5373 void wxGenericListCtrl::ResizeReportView(bool showHeader
)
5376 GetClientSize( &cw
, &ch
);
5380 m_headerWin
->SetSize( 0, 0, cw
, m_headerHeight
);
5381 if(ch
> m_headerHeight
)
5382 m_mainWin
->SetSize( 0, m_headerHeight
+ 1,
5383 cw
, ch
- m_headerHeight
- 1 );
5385 m_mainWin
->SetSize( 0, m_headerHeight
+ 1,
5388 else // no header window
5390 m_mainWin
->SetSize( 0, 0, cw
, ch
);
5394 void wxGenericListCtrl::OnInternalIdle()
5396 wxWindow::OnInternalIdle();
5398 // do it only if needed
5399 if ( !m_mainWin
->m_dirty
)
5402 m_mainWin
->RecalculatePositions();
5405 // ----------------------------------------------------------------------------
5407 // ----------------------------------------------------------------------------
5409 bool wxGenericListCtrl::SetBackgroundColour( const wxColour
&colour
)
5413 m_mainWin
->SetBackgroundColour( colour
);
5414 m_mainWin
->m_dirty
= true;
5420 bool wxGenericListCtrl::SetForegroundColour( const wxColour
&colour
)
5422 if ( !wxWindow::SetForegroundColour( colour
) )
5427 m_mainWin
->SetForegroundColour( colour
);
5428 m_mainWin
->m_dirty
= true;
5432 m_headerWin
->SetForegroundColour( colour
);
5437 bool wxGenericListCtrl::SetFont( const wxFont
&font
)
5439 if ( !wxWindow::SetFont( font
) )
5444 m_mainWin
->SetFont( font
);
5445 m_mainWin
->m_dirty
= true;
5450 m_headerWin
->SetFont( font
);
5451 CalculateAndSetHeaderHeight();
5461 wxGenericListCtrl::GetClassDefaultAttributes(wxWindowVariant variant
)
5464 // Use the same color scheme as wxListBox
5465 return wxListBox::GetClassDefaultAttributes(variant
);
5467 wxUnusedVar(variant
);
5468 wxVisualAttributes attr
;
5469 attr
.colFg
= wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT
);
5470 attr
.colBg
= wxSystemSettings::GetColour(wxSYS_COLOUR_LISTBOX
);
5471 attr
.font
= wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT
);
5476 // ----------------------------------------------------------------------------
5477 // methods forwarded to m_mainWin
5478 // ----------------------------------------------------------------------------
5480 #if wxUSE_DRAG_AND_DROP
5482 void wxGenericListCtrl::SetDropTarget( wxDropTarget
*dropTarget
)
5484 m_mainWin
->SetDropTarget( dropTarget
);
5487 wxDropTarget
*wxGenericListCtrl::GetDropTarget() const
5489 return m_mainWin
->GetDropTarget();
5494 bool wxGenericListCtrl::SetCursor( const wxCursor
&cursor
)
5496 return m_mainWin
? m_mainWin
->wxWindow::SetCursor(cursor
) : false;
5499 wxColour
wxGenericListCtrl::GetBackgroundColour() const
5501 return m_mainWin
? m_mainWin
->GetBackgroundColour() : wxColour();
5504 wxColour
wxGenericListCtrl::GetForegroundColour() const
5506 return m_mainWin
? m_mainWin
->GetForegroundColour() : wxColour();
5509 bool wxGenericListCtrl::DoPopupMenu( wxMenu
*menu
, int x
, int y
)
5512 return m_mainWin
->PopupMenu( menu
, x
, y
);
5518 void wxGenericListCtrl::DoClientToScreen( int *x
, int *y
) const
5520 m_mainWin
->DoClientToScreen(x
, y
);
5523 void wxGenericListCtrl::DoScreenToClient( int *x
, int *y
) const
5525 m_mainWin
->DoScreenToClient(x
, y
);
5528 void wxGenericListCtrl::SetFocus()
5530 // The test in window.cpp fails as we are a composite
5531 // window, so it checks against "this", but not m_mainWin.
5532 if ( DoFindFocus() != this )
5533 m_mainWin
->SetFocus();
5536 wxSize
wxGenericListCtrl::DoGetBestSize() const
5538 // Something is better than nothing...
5539 // 100x80 is what the MSW version will get from the default
5540 // wxControl::DoGetBestSize
5541 return wxSize(100, 80);
5544 // ----------------------------------------------------------------------------
5545 // virtual list control support
5546 // ----------------------------------------------------------------------------
5548 wxString
wxGenericListCtrl::OnGetItemText(long WXUNUSED(item
), long WXUNUSED(col
)) const
5550 // this is a pure virtual function, in fact - which is not really pure
5551 // because the controls which are not virtual don't need to implement it
5552 wxFAIL_MSG( _T("wxGenericListCtrl::OnGetItemText not supposed to be called") );
5554 return wxEmptyString
;
5557 int wxGenericListCtrl::OnGetItemImage(long WXUNUSED(item
)) const
5559 wxCHECK_MSG(!GetImageList(wxIMAGE_LIST_SMALL
),
5561 wxT("List control has an image list, OnGetItemImage or OnGetItemColumnImage should be overridden."));
5565 int wxGenericListCtrl::OnGetItemColumnImage(long item
, long column
) const
5568 return OnGetItemImage(item
);
5574 wxGenericListCtrl::OnGetItemAttr(long WXUNUSED_UNLESS_DEBUG(item
)) const
5576 wxASSERT_MSG( item
>= 0 && item
< GetItemCount(),
5577 _T("invalid item index in OnGetItemAttr()") );
5579 // no attributes by default
5583 void wxGenericListCtrl::SetItemCount(long count
)
5585 wxASSERT_MSG( IsVirtual(), _T("this is for virtual controls only") );
5587 m_mainWin
->SetItemCount(count
);
5590 void wxGenericListCtrl::RefreshItem(long item
)
5592 m_mainWin
->RefreshLine(item
);
5595 void wxGenericListCtrl::RefreshItems(long itemFrom
, long itemTo
)
5597 m_mainWin
->RefreshLines(itemFrom
, itemTo
);
5600 // Generic wxListCtrl is more or less a container for two other
5601 // windows which drawings are done upon. These are namely
5602 // 'm_headerWin' and 'm_mainWin'.
5603 // Here we override 'virtual wxWindow::Refresh()' to mimic the
5604 // behaviour wxListCtrl has under wxMSW.
5606 void wxGenericListCtrl::Refresh(bool eraseBackground
, const wxRect
*rect
)
5610 // The easy case, no rectangle specified.
5612 m_headerWin
->Refresh(eraseBackground
);
5615 m_mainWin
->Refresh(eraseBackground
);
5619 // Refresh the header window
5622 wxRect rectHeader
= m_headerWin
->GetRect();
5623 rectHeader
.Intersect(*rect
);
5624 if (rectHeader
.GetWidth() && rectHeader
.GetHeight())
5627 m_headerWin
->GetPosition(&x
, &y
);
5628 rectHeader
.Offset(-x
, -y
);
5629 m_headerWin
->Refresh(eraseBackground
, &rectHeader
);
5633 // Refresh the main window
5636 wxRect rectMain
= m_mainWin
->GetRect();
5637 rectMain
.Intersect(*rect
);
5638 if (rectMain
.GetWidth() && rectMain
.GetHeight())
5641 m_mainWin
->GetPosition(&x
, &y
);
5642 rectMain
.Offset(-x
, -y
);
5643 m_mainWin
->Refresh(eraseBackground
, &rectMain
);
5649 void wxGenericListCtrl::Freeze()
5651 m_mainWin
->Freeze();
5654 void wxGenericListCtrl::Thaw()
5659 #endif // wxUSE_LISTCTRL