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
75 static const int EXTRA_WIDTH
= 6;
77 static const int EXTRA_WIDTH
= 4;
79 static const int EXTRA_HEIGHT
= 4;
81 // margin between the window and the items
82 static const int EXTRA_BORDER_X
= 2;
83 static const int EXTRA_BORDER_Y
= 2;
85 // offset for the header window
86 static const int HEADER_OFFSET_X
= 1;
87 static const int HEADER_OFFSET_Y
= 1;
89 // margin between rows of icons in [small] icon view
90 static const int MARGIN_BETWEEN_ROWS
= 6;
92 // when autosizing the columns, add some slack
93 static const int AUTOSIZE_COL_MARGIN
= 10;
95 // default width for the header columns
96 static const int WIDTH_COL_DEFAULT
= 80;
98 // the space between the image and the text in the report mode
99 static const int IMAGE_MARGIN_IN_REPORT_MODE
= 5;
101 // ============================================================================
103 // ============================================================================
105 //-----------------------------------------------------------------------------
106 // wxColWidthInfo (internal)
107 //-----------------------------------------------------------------------------
109 struct wxColWidthInfo
112 bool bNeedsUpdate
; // only set to true when an item whose
113 // width == nMaxWidth is removed
115 wxColWidthInfo(int w
= 0, bool needsUpdate
= false)
118 bNeedsUpdate
= needsUpdate
;
122 WX_DEFINE_ARRAY_PTR(wxColWidthInfo
*, ColWidthArray
);
124 //-----------------------------------------------------------------------------
125 // wxListItemData (internal)
126 //-----------------------------------------------------------------------------
131 wxListItemData(wxListMainWindow
*owner
);
134 void SetItem( const wxListItem
&info
);
135 void SetImage( int image
) { m_image
= image
; }
136 void SetData( wxUIntPtr data
) { m_data
= data
; }
137 void SetPosition( int x
, int y
);
138 void SetSize( int width
, int height
);
140 bool HasText() const { return !m_text
.empty(); }
141 const wxString
& GetText() const { return m_text
; }
142 void SetText(const wxString
& text
) { m_text
= text
; }
144 // we can't use empty string for measuring the string width/height, so
145 // always return something
146 wxString
GetTextForMeasuring() const
148 wxString s
= GetText();
155 bool IsHit( int x
, int y
) const;
159 int GetWidth() const;
160 int GetHeight() const;
162 int GetImage() const { return m_image
; }
163 bool HasImage() const { return GetImage() != -1; }
165 void GetItem( wxListItem
&info
) const;
167 void SetAttr(wxListItemAttr
*attr
) { m_attr
= attr
; }
168 wxListItemAttr
*GetAttr() const { return m_attr
; }
171 // the item image or -1
174 // user data associated with the item
177 // the item coordinates are not used in report mode; instead this pointer is
178 // NULL and the owner window is used to retrieve the item position and size
181 // the list ctrl we are in
182 wxListMainWindow
*m_owner
;
184 // custom attributes or NULL
185 wxListItemAttr
*m_attr
;
188 // common part of all ctors
194 //-----------------------------------------------------------------------------
195 // wxListHeaderData (internal)
196 //-----------------------------------------------------------------------------
198 class wxListHeaderData
: public wxObject
202 wxListHeaderData( const wxListItem
&info
);
203 void SetItem( const wxListItem
&item
);
204 void SetPosition( int x
, int y
);
205 void SetWidth( int w
);
206 void SetState( int state
);
207 void SetFormat( int format
);
208 void SetHeight( int h
);
209 bool HasImage() const;
211 bool HasText() const { return !m_text
.empty(); }
212 const wxString
& GetText() const { return m_text
; }
213 void SetText(const wxString
& text
) { m_text
= text
; }
215 void GetItem( wxListItem
&item
);
217 bool IsHit( int x
, int y
) const;
218 int GetImage() const;
219 int GetWidth() const;
220 int GetFormat() const;
221 int GetState() const;
238 //-----------------------------------------------------------------------------
239 // wxListLineData (internal)
240 //-----------------------------------------------------------------------------
242 WX_DECLARE_EXPORTED_LIST(wxListItemData
, wxListItemDataList
);
243 #include "wx/listimpl.cpp"
244 WX_DEFINE_LIST(wxListItemDataList
)
249 // the list of subitems: only may have more than one item in report mode
250 wxListItemDataList m_items
;
252 // this is not used in report view
264 // the part to be highlighted
265 wxRect m_rectHighlight
;
267 // extend all our rects to be centered inside the one of given width
268 void ExtendWidth(wxCoord w
)
270 wxASSERT_MSG( m_rectAll
.width
<= w
,
271 _T("width can only be increased") );
274 m_rectLabel
.x
= m_rectAll
.x
+ (w
- m_rectLabel
.width
) / 2;
275 m_rectIcon
.x
= m_rectAll
.x
+ (w
- m_rectIcon
.width
) / 2;
276 m_rectHighlight
.x
= m_rectAll
.x
+ (w
- m_rectHighlight
.width
) / 2;
281 // is this item selected? [NB: not used in virtual mode]
284 // back pointer to the list ctrl
285 wxListMainWindow
*m_owner
;
288 wxListLineData(wxListMainWindow
*owner
);
292 WX_CLEAR_LIST(wxListItemDataList
, m_items
);
296 // are we in report mode?
297 inline bool InReportView() const;
299 // are we in virtual report mode?
300 inline bool IsVirtual() const;
302 // these 2 methods shouldn't be called for report view controls, in that
303 // case we determine our position/size ourselves
305 // calculate the size of the line
306 void CalculateSize( wxDC
*dc
, int spacing
);
308 // remember the position this line appears at
309 void SetPosition( int x
, int y
, int spacing
);
313 void SetImage( int image
) { SetImage(0, image
); }
314 int GetImage() const { return GetImage(0); }
315 void SetImage( int index
, int image
);
316 int GetImage( int index
) const;
318 bool HasImage() const { return GetImage() != -1; }
319 bool HasText() const { return !GetText(0).empty(); }
321 void SetItem( int index
, const wxListItem
&info
);
322 void GetItem( int index
, wxListItem
&info
);
324 wxString
GetText(int index
) const;
325 void SetText( int index
, const wxString
& s
);
327 wxListItemAttr
*GetAttr() const;
328 void SetAttr(wxListItemAttr
*attr
);
330 // return true if the highlighting really changed
331 bool Highlight( bool on
);
333 void ReverseHighlight();
335 bool IsHighlighted() const
337 wxASSERT_MSG( !IsVirtual(), _T("unexpected call to IsHighlighted") );
339 return m_highlighted
;
342 // draw the line on the given DC in icon/list mode
343 void Draw( wxDC
*dc
);
345 // the same in report mode
346 void DrawInReportMode( wxDC
*dc
,
348 const wxRect
& rectHL
,
352 // set the line to contain num items (only can be > 1 in report mode)
353 void InitItems( int num
);
355 // get the mode (i.e. style) of the list control
356 inline int GetMode() const;
358 // prepare the DC for drawing with these item's attributes, return true if
359 // we need to draw the items background to highlight it, false otherwise
360 bool SetAttributes(wxDC
*dc
,
361 const wxListItemAttr
*attr
,
364 // draw the text on the DC with the correct justification; also add an
365 // ellipsis if the text is too large to fit in the current width
366 void DrawTextFormatted(wxDC
*dc
,
367 const wxString
&text
,
370 int yMid
, // this is middle, not top, of the text
374 WX_DECLARE_EXPORTED_OBJARRAY(wxListLineData
, wxListLineDataArray
);
375 #include "wx/arrimpl.cpp"
376 WX_DEFINE_OBJARRAY(wxListLineDataArray
)
378 //-----------------------------------------------------------------------------
379 // wxListHeaderWindow (internal)
380 //-----------------------------------------------------------------------------
382 class wxListHeaderWindow
: public wxWindow
385 wxListMainWindow
*m_owner
;
386 const wxCursor
*m_currentCursor
;
387 wxCursor
*m_resizeCursor
;
390 // column being resized or -1
393 // divider line position in logical (unscrolled) coords
396 // minimal position beyond which the divider line
397 // can't be dragged in logical coords
401 wxListHeaderWindow();
403 wxListHeaderWindow( wxWindow
*win
,
405 wxListMainWindow
*owner
,
406 const wxPoint
&pos
= wxDefaultPosition
,
407 const wxSize
&size
= wxDefaultSize
,
409 const wxString
&name
= wxT("wxlistctrlcolumntitles") );
411 virtual ~wxListHeaderWindow();
414 void AdjustDC( wxDC
& dc
);
416 void OnPaint( wxPaintEvent
&event
);
417 void OnMouse( wxMouseEvent
&event
);
418 void OnSetFocus( wxFocusEvent
&event
);
424 // common part of all ctors
427 // generate and process the list event of the given type, return true if
428 // it wasn't vetoed, i.e. if we should proceed
429 bool SendListEvent(wxEventType type
, const wxPoint
& pos
);
431 DECLARE_DYNAMIC_CLASS(wxListHeaderWindow
)
432 DECLARE_EVENT_TABLE()
435 //-----------------------------------------------------------------------------
436 // wxListRenameTimer (internal)
437 //-----------------------------------------------------------------------------
439 class wxListRenameTimer
: public wxTimer
442 wxListMainWindow
*m_owner
;
445 wxListRenameTimer( wxListMainWindow
*owner
);
449 //-----------------------------------------------------------------------------
450 // wxListTextCtrlWrapper: wraps a wxTextCtrl to make it work for inline editing
451 //-----------------------------------------------------------------------------
453 class wxListTextCtrlWrapper
: public wxEvtHandler
456 // NB: text must be a valid object but not Create()d yet
457 wxListTextCtrlWrapper(wxListMainWindow
*owner
,
461 wxTextCtrl
*GetText() const { return m_text
; }
463 void AcceptChangesAndFinish();
466 void OnChar( wxKeyEvent
&event
);
467 void OnKeyUp( wxKeyEvent
&event
);
468 void OnKillFocus( wxFocusEvent
&event
);
470 bool AcceptChanges();
474 wxListMainWindow
*m_owner
;
476 wxString m_startValue
;
479 bool m_aboutToFinish
;
481 DECLARE_EVENT_TABLE()
484 //-----------------------------------------------------------------------------
485 // wxListMainWindow (internal)
486 //-----------------------------------------------------------------------------
488 WX_DECLARE_EXPORTED_LIST(wxListHeaderData
, wxListHeaderDataList
);
489 #include "wx/listimpl.cpp"
490 WX_DEFINE_LIST(wxListHeaderDataList
)
492 class wxListMainWindow
: public wxScrolledWindow
496 wxListMainWindow( wxWindow
*parent
,
498 const wxPoint
& pos
= wxDefaultPosition
,
499 const wxSize
& size
= wxDefaultSize
,
501 const wxString
&name
= _T("listctrlmainwindow") );
503 virtual ~wxListMainWindow();
505 bool HasFlag(int flag
) const { return m_parent
->HasFlag(flag
); }
507 // return true if this is a virtual list control
508 bool IsVirtual() const { return HasFlag(wxLC_VIRTUAL
); }
510 // return true if the control is in report mode
511 bool InReportView() const { return HasFlag(wxLC_REPORT
); }
513 // return true if we are in single selection mode, false if multi sel
514 bool IsSingleSel() const { return HasFlag(wxLC_SINGLE_SEL
); }
516 // do we have a header window?
517 bool HasHeader() const
518 { return InReportView() && !HasFlag(wxLC_NO_HEADER
); }
520 void HighlightAll( bool on
);
522 // all these functions only do something if the line is currently visible
524 // change the line "selected" state, return true if it really changed
525 bool HighlightLine( size_t line
, bool highlight
= true);
527 // as HighlightLine() but do it for the range of lines: this is incredibly
528 // more efficient for virtual list controls!
530 // NB: unlike HighlightLine() this one does refresh the lines on screen
531 void HighlightLines( size_t lineFrom
, size_t lineTo
, bool on
= true );
533 // toggle the line state and refresh it
534 void ReverseHighlight( size_t line
)
535 { HighlightLine(line
, !IsHighlighted(line
)); RefreshLine(line
); }
537 // return true if the line is highlighted
538 bool IsHighlighted(size_t line
) const;
540 // refresh one or several lines at once
541 void RefreshLine( size_t line
);
542 void RefreshLines( size_t lineFrom
, size_t lineTo
);
544 // refresh all selected items
545 void RefreshSelected();
547 // refresh all lines below the given one: the difference with
548 // RefreshLines() is that the index here might not be a valid one (happens
549 // when the last line is deleted)
550 void RefreshAfter( size_t lineFrom
);
552 // the methods which are forwarded to wxListLineData itself in list/icon
553 // modes but are here because the lines don't store their positions in the
556 // get the bound rect for the entire line
557 wxRect
GetLineRect(size_t line
) const;
559 // get the bound rect of the label
560 wxRect
GetLineLabelRect(size_t line
) const;
562 // get the bound rect of the items icon (only may be called if we do have
564 wxRect
GetLineIconRect(size_t line
) const;
566 // get the rect to be highlighted when the item has focus
567 wxRect
GetLineHighlightRect(size_t line
) const;
569 // get the size of the total line rect
570 wxSize
GetLineSize(size_t line
) const
571 { return GetLineRect(line
).GetSize(); }
573 // return the hit code for the corresponding position (in this line)
574 long HitTestLine(size_t line
, int x
, int y
) const;
576 // bring the selected item into view, scrolling to it if necessary
577 void MoveToItem(size_t item
);
579 // bring the current item into view
580 void MoveToFocus() { MoveToItem(m_current
); }
582 // start editing the label of the given item
583 wxTextCtrl
*EditLabel(long item
,
584 wxClassInfo
* textControlClass
= CLASSINFO(wxTextCtrl
));
585 wxTextCtrl
*GetEditControl() const
587 return m_textctrlWrapper
? m_textctrlWrapper
->GetText() : NULL
;
590 void FinishEditing(wxTextCtrl
*text
)
593 m_textctrlWrapper
= NULL
;
594 SetFocusIgnoringChildren();
597 // suspend/resume redrawing the control
601 void OnRenameTimer();
602 bool OnRenameAccept(size_t itemEdit
, const wxString
& value
);
603 void OnRenameCancelled(size_t itemEdit
);
605 void OnMouse( wxMouseEvent
&event
);
607 // called to switch the selection from the current item to newCurrent,
608 void OnArrowChar( size_t newCurrent
, const wxKeyEvent
& event
);
610 void OnChar( wxKeyEvent
&event
);
611 void OnKeyDown( wxKeyEvent
&event
);
612 void OnKeyUp( wxKeyEvent
&event
);
613 void OnSetFocus( wxFocusEvent
&event
);
614 void OnKillFocus( wxFocusEvent
&event
);
615 void OnScroll( wxScrollWinEvent
& event
);
617 void OnPaint( wxPaintEvent
&event
);
619 void DrawImage( int index
, wxDC
*dc
, int x
, int y
);
620 void GetImageSize( int index
, int &width
, int &height
) const;
621 int GetTextLength( const wxString
&s
) const;
623 void SetImageList( wxImageList
*imageList
, int which
);
624 void SetItemSpacing( int spacing
, bool isSmall
= false );
625 int GetItemSpacing( bool isSmall
= false );
627 void SetColumn( int col
, wxListItem
&item
);
628 void SetColumnWidth( int col
, int width
);
629 void GetColumn( int col
, wxListItem
&item
) const;
630 int GetColumnWidth( int col
) const;
631 int GetColumnCount() const { return m_columns
.GetCount(); }
633 // returns the sum of the heights of all columns
634 int GetHeaderWidth() const;
636 int GetCountPerPage() const;
638 void SetItem( wxListItem
&item
);
639 void GetItem( wxListItem
&item
) const;
640 void SetItemState( long item
, long state
, long stateMask
);
641 void SetItemStateAll( long state
, long stateMask
);
642 int GetItemState( long item
, long stateMask
) const;
643 void GetItemRect( long index
, wxRect
&rect
) const;
644 wxRect
GetViewRect() const;
645 bool GetItemPosition( long item
, wxPoint
& pos
) const;
646 int GetSelectedItemCount() const;
648 wxString
GetItemText(long item
) const
651 info
.m_mask
= wxLIST_MASK_TEXT
;
652 info
.m_itemId
= item
;
657 void SetItemText(long item
, const wxString
& value
)
660 info
.m_mask
= wxLIST_MASK_TEXT
;
661 info
.m_itemId
= item
;
666 // set the scrollbars and update the positions of the items
667 void RecalculatePositions(bool noRefresh
= false);
669 // refresh the window and the header
672 long GetNextItem( long item
, int geometry
, int state
) const;
673 void DeleteItem( long index
);
674 void DeleteAllItems();
675 void DeleteColumn( int col
);
676 void DeleteEverything();
677 void EnsureVisible( long index
);
678 long FindItem( long start
, const wxString
& str
, bool partial
= false );
679 long FindItem( long start
, wxUIntPtr data
);
680 long FindItem( const wxPoint
& pt
);
681 long HitTest( int x
, int y
, int &flags
) const;
682 void InsertItem( wxListItem
&item
);
683 void InsertColumn( long col
, wxListItem
&item
);
684 int GetItemWidthWithImage(wxListItem
* item
);
685 void SortItems( wxListCtrlCompare fn
, long data
);
687 size_t GetItemCount() const;
688 bool IsEmpty() const { return GetItemCount() == 0; }
689 void SetItemCount(long count
);
691 // change the current (== focused) item, send a notification event
692 void ChangeCurrent(size_t current
);
693 void ResetCurrent() { ChangeCurrent((size_t)-1); }
694 bool HasCurrent() const { return m_current
!= (size_t)-1; }
696 // send out a wxListEvent
697 void SendNotify( size_t line
,
699 const wxPoint
& point
= wxDefaultPosition
);
701 // override base class virtual to reset m_lineHeight when the font changes
702 virtual bool SetFont(const wxFont
& font
)
704 if ( !wxScrolledWindow::SetFont(font
) )
712 // these are for wxListLineData usage only
714 // get the backpointer to the list ctrl
715 wxGenericListCtrl
*GetListCtrl() const
717 return wxStaticCast(GetParent(), wxGenericListCtrl
);
720 // get the height of all lines (assuming they all do have the same height)
721 wxCoord
GetLineHeight() const;
723 // get the y position of the given line (only for report view)
724 wxCoord
GetLineY(size_t line
) const;
726 // get the brush to use for the item highlighting
727 wxBrush
*GetHighlightBrush() const
729 return m_hasFocus
? m_highlightBrush
: m_highlightUnfocusedBrush
;
732 bool HasFocus() const
738 // the array of all line objects for a non virtual list control (for the
739 // virtual list control we only ever use m_lines[0])
740 wxListLineDataArray m_lines
;
742 // the list of column objects
743 wxListHeaderDataList m_columns
;
745 // currently focused item or -1
748 // the number of lines per page
751 // this flag is set when something which should result in the window
752 // redrawing happens (i.e. an item was added or deleted, or its appearance
753 // changed) and OnPaint() doesn't redraw the window while it is set which
754 // allows to minimize the number of repaintings when a lot of items are
755 // being added. The real repainting occurs only after the next OnIdle()
759 wxColour
*m_highlightColour
;
760 wxImageList
*m_small_image_list
;
761 wxImageList
*m_normal_image_list
;
763 int m_normal_spacing
;
767 wxTimer
*m_renameTimer
;
771 ColWidthArray m_aColWidths
;
773 // for double click logic
774 size_t m_lineLastClicked
,
775 m_lineBeforeLastClicked
,
776 m_lineSelectSingleOnUp
;
779 wxWindow
*GetMainWindowOfCompositeControl() { return GetParent(); }
781 // the total count of items in a virtual list control
784 // the object maintaining the items selection state, only used in virtual
786 wxSelectionStore m_selStore
;
788 // common part of all ctors
791 // get the line data for the given index
792 wxListLineData
*GetLine(size_t n
) const
794 wxASSERT_MSG( n
!= (size_t)-1, _T("invalid line index") );
798 wxConstCast(this, wxListMainWindow
)->CacheLineData(n
);
805 // get a dummy line which can be used for geometry calculations and such:
806 // you must use GetLine() if you want to really draw the line
807 wxListLineData
*GetDummyLine() const;
809 // cache the line data of the n-th line in m_lines[0]
810 void CacheLineData(size_t line
);
812 // get the range of visible lines
813 void GetVisibleLinesRange(size_t *from
, size_t *to
);
815 // force us to recalculate the range of visible lines
816 void ResetVisibleLinesRange() { m_lineFrom
= (size_t)-1; }
818 // get the colour to be used for drawing the rules
819 wxColour
GetRuleColour() const
821 return wxSystemSettings::GetColour(wxSYS_COLOUR_3DLIGHT
);
825 // initialize the current item if needed
826 void UpdateCurrent();
828 // delete all items but don't refresh: called from dtor
829 void DoDeleteAllItems();
831 // the height of one line using the current font
832 wxCoord m_lineHeight
;
834 // the total header width or 0 if not calculated yet
835 wxCoord m_headerWidth
;
837 // the first and last lines being shown on screen right now (inclusive),
838 // both may be -1 if they must be calculated so never access them directly:
839 // use GetVisibleLinesRange() above instead
843 // the brushes to use for item highlighting when we do/don't have focus
844 wxBrush
*m_highlightBrush
,
845 *m_highlightUnfocusedBrush
;
847 // if this is > 0, the control is frozen and doesn't redraw itself
848 size_t m_freezeCount
;
850 // wrapper around the text control currently used for in place editing or
851 // NULL if no item is being edited
852 wxListTextCtrlWrapper
*m_textctrlWrapper
;
855 DECLARE_DYNAMIC_CLASS(wxListMainWindow
)
856 DECLARE_EVENT_TABLE()
858 friend class wxGenericListCtrl
;
862 wxListItemData::~wxListItemData()
864 // in the virtual list control the attributes are managed by the main
865 // program, so don't delete them
866 if ( !m_owner
->IsVirtual() )
872 void wxListItemData::Init()
880 wxListItemData::wxListItemData(wxListMainWindow
*owner
)
886 if ( owner
->InReportView() )
892 void wxListItemData::SetItem( const wxListItem
&info
)
894 if ( info
.m_mask
& wxLIST_MASK_TEXT
)
895 SetText(info
.m_text
);
896 if ( info
.m_mask
& wxLIST_MASK_IMAGE
)
897 m_image
= info
.m_image
;
898 if ( info
.m_mask
& wxLIST_MASK_DATA
)
899 m_data
= info
.m_data
;
901 if ( info
.HasAttributes() )
904 m_attr
->AssignFrom(*info
.GetAttributes());
906 m_attr
= new wxListItemAttr(*info
.GetAttributes());
914 m_rect
->width
= info
.m_width
;
918 void wxListItemData::SetPosition( int x
, int y
)
920 wxCHECK_RET( m_rect
, _T("unexpected SetPosition() call") );
926 void wxListItemData::SetSize( int width
, int height
)
928 wxCHECK_RET( m_rect
, _T("unexpected SetSize() call") );
931 m_rect
->width
= width
;
933 m_rect
->height
= height
;
936 bool wxListItemData::IsHit( int x
, int y
) const
938 wxCHECK_MSG( m_rect
, false, _T("can't be called in this mode") );
940 return wxRect(GetX(), GetY(), GetWidth(), GetHeight()).Contains(x
, y
);
943 int wxListItemData::GetX() const
945 wxCHECK_MSG( m_rect
, 0, _T("can't be called in this mode") );
950 int wxListItemData::GetY() const
952 wxCHECK_MSG( m_rect
, 0, _T("can't be called in this mode") );
957 int wxListItemData::GetWidth() const
959 wxCHECK_MSG( m_rect
, 0, _T("can't be called in this mode") );
961 return m_rect
->width
;
964 int wxListItemData::GetHeight() const
966 wxCHECK_MSG( m_rect
, 0, _T("can't be called in this mode") );
968 return m_rect
->height
;
971 void wxListItemData::GetItem( wxListItem
&info
) const
973 long mask
= info
.m_mask
;
975 // by default, get everything for backwards compatibility
978 if ( mask
& wxLIST_MASK_TEXT
)
979 info
.m_text
= m_text
;
980 if ( mask
& wxLIST_MASK_IMAGE
)
981 info
.m_image
= m_image
;
982 if ( mask
& wxLIST_MASK_DATA
)
983 info
.m_data
= m_data
;
987 if ( m_attr
->HasTextColour() )
988 info
.SetTextColour(m_attr
->GetTextColour());
989 if ( m_attr
->HasBackgroundColour() )
990 info
.SetBackgroundColour(m_attr
->GetBackgroundColour());
991 if ( m_attr
->HasFont() )
992 info
.SetFont(m_attr
->GetFont());
996 //-----------------------------------------------------------------------------
998 //-----------------------------------------------------------------------------
1000 void wxListHeaderData::Init()
1012 wxListHeaderData::wxListHeaderData()
1017 wxListHeaderData::wxListHeaderData( const wxListItem
&item
)
1024 void wxListHeaderData::SetItem( const wxListItem
&item
)
1026 m_mask
= item
.m_mask
;
1028 if ( m_mask
& wxLIST_MASK_TEXT
)
1029 m_text
= item
.m_text
;
1031 if ( m_mask
& wxLIST_MASK_IMAGE
)
1032 m_image
= item
.m_image
;
1034 if ( m_mask
& wxLIST_MASK_FORMAT
)
1035 m_format
= item
.m_format
;
1037 if ( m_mask
& wxLIST_MASK_WIDTH
)
1038 SetWidth(item
.m_width
);
1040 if ( m_mask
& wxLIST_MASK_STATE
)
1041 SetState(item
.m_state
);
1044 void wxListHeaderData::SetPosition( int x
, int y
)
1050 void wxListHeaderData::SetHeight( int h
)
1055 void wxListHeaderData::SetWidth( int w
)
1057 m_width
= w
< 0 ? WIDTH_COL_DEFAULT
: w
;
1060 void wxListHeaderData::SetState( int flag
)
1065 void wxListHeaderData::SetFormat( int format
)
1070 bool wxListHeaderData::HasImage() const
1072 return m_image
!= -1;
1075 bool wxListHeaderData::IsHit( int x
, int y
) const
1077 return ((x
>= m_xpos
) && (x
<= m_xpos
+m_width
) && (y
>= m_ypos
) && (y
<= m_ypos
+m_height
));
1080 void wxListHeaderData::GetItem( wxListItem
& item
)
1082 item
.m_mask
= m_mask
;
1083 item
.m_text
= m_text
;
1084 item
.m_image
= m_image
;
1085 item
.m_format
= m_format
;
1086 item
.m_width
= m_width
;
1087 item
.m_state
= m_state
;
1090 int wxListHeaderData::GetImage() const
1095 int wxListHeaderData::GetWidth() const
1100 int wxListHeaderData::GetFormat() const
1105 int wxListHeaderData::GetState() const
1110 //-----------------------------------------------------------------------------
1112 //-----------------------------------------------------------------------------
1114 inline int wxListLineData::GetMode() const
1116 return m_owner
->GetListCtrl()->GetWindowStyleFlag() & wxLC_MASK_TYPE
;
1119 inline bool wxListLineData::InReportView() const
1121 return m_owner
->HasFlag(wxLC_REPORT
);
1124 inline bool wxListLineData::IsVirtual() const
1126 return m_owner
->IsVirtual();
1129 wxListLineData::wxListLineData( wxListMainWindow
*owner
)
1133 if ( InReportView() )
1136 m_gi
= new GeometryInfo
;
1138 m_highlighted
= false;
1140 InitItems( GetMode() == wxLC_REPORT
? m_owner
->GetColumnCount() : 1 );
1143 void wxListLineData::CalculateSize( wxDC
*dc
, int spacing
)
1145 wxListItemDataList::compatibility_iterator node
= m_items
.GetFirst();
1146 wxCHECK_RET( node
, _T("no subitems at all??") );
1148 wxListItemData
*item
= node
->GetData();
1153 switch ( GetMode() )
1156 case wxLC_SMALL_ICON
:
1157 m_gi
->m_rectAll
.width
= spacing
;
1159 s
= item
->GetText();
1164 m_gi
->m_rectLabel
.width
=
1165 m_gi
->m_rectLabel
.height
= 0;
1169 dc
->GetTextExtent( s
, &lw
, &lh
);
1173 m_gi
->m_rectAll
.height
= spacing
+ lh
;
1175 m_gi
->m_rectAll
.width
= lw
;
1177 m_gi
->m_rectLabel
.width
= lw
;
1178 m_gi
->m_rectLabel
.height
= lh
;
1181 if (item
->HasImage())
1184 m_owner
->GetImageSize( item
->GetImage(), w
, h
);
1185 m_gi
->m_rectIcon
.width
= w
+ 8;
1186 m_gi
->m_rectIcon
.height
= h
+ 8;
1188 if ( m_gi
->m_rectIcon
.width
> m_gi
->m_rectAll
.width
)
1189 m_gi
->m_rectAll
.width
= m_gi
->m_rectIcon
.width
;
1190 if ( m_gi
->m_rectIcon
.height
+ lh
> m_gi
->m_rectAll
.height
- 4 )
1191 m_gi
->m_rectAll
.height
= m_gi
->m_rectIcon
.height
+ lh
+ 4;
1194 if ( item
->HasText() )
1196 m_gi
->m_rectHighlight
.width
= m_gi
->m_rectLabel
.width
;
1197 m_gi
->m_rectHighlight
.height
= m_gi
->m_rectLabel
.height
;
1199 else // no text, highlight the icon
1201 m_gi
->m_rectHighlight
.width
= m_gi
->m_rectIcon
.width
;
1202 m_gi
->m_rectHighlight
.height
= m_gi
->m_rectIcon
.height
;
1207 s
= item
->GetTextForMeasuring();
1209 dc
->GetTextExtent( s
, &lw
, &lh
);
1213 m_gi
->m_rectLabel
.width
= lw
;
1214 m_gi
->m_rectLabel
.height
= lh
;
1216 m_gi
->m_rectAll
.width
= lw
;
1217 m_gi
->m_rectAll
.height
= lh
;
1219 if (item
->HasImage())
1222 m_owner
->GetImageSize( item
->GetImage(), w
, h
);
1223 m_gi
->m_rectIcon
.width
= w
;
1224 m_gi
->m_rectIcon
.height
= h
;
1226 m_gi
->m_rectAll
.width
+= 4 + w
;
1227 if (h
> m_gi
->m_rectAll
.height
)
1228 m_gi
->m_rectAll
.height
= h
;
1231 m_gi
->m_rectHighlight
.width
= m_gi
->m_rectAll
.width
;
1232 m_gi
->m_rectHighlight
.height
= m_gi
->m_rectAll
.height
;
1236 wxFAIL_MSG( _T("unexpected call to SetSize") );
1240 wxFAIL_MSG( _T("unknown mode") );
1245 void wxListLineData::SetPosition( int x
, int y
, int spacing
)
1247 wxListItemDataList::compatibility_iterator node
= m_items
.GetFirst();
1248 wxCHECK_RET( node
, _T("no subitems at all??") );
1250 wxListItemData
*item
= node
->GetData();
1252 switch ( GetMode() )
1255 case wxLC_SMALL_ICON
:
1256 m_gi
->m_rectAll
.x
= x
;
1257 m_gi
->m_rectAll
.y
= y
;
1259 if ( item
->HasImage() )
1261 m_gi
->m_rectIcon
.x
= m_gi
->m_rectAll
.x
+ 4 +
1262 (m_gi
->m_rectAll
.width
- m_gi
->m_rectIcon
.width
) / 2;
1263 m_gi
->m_rectIcon
.y
= m_gi
->m_rectAll
.y
+ 4;
1266 if ( item
->HasText() )
1268 if (m_gi
->m_rectAll
.width
> spacing
)
1269 m_gi
->m_rectLabel
.x
= m_gi
->m_rectAll
.x
+ (EXTRA_WIDTH
/2);
1271 m_gi
->m_rectLabel
.x
= m_gi
->m_rectAll
.x
+ (EXTRA_WIDTH
/2) + (spacing
/ 2) - (m_gi
->m_rectLabel
.width
/ 2);
1272 m_gi
->m_rectLabel
.y
= m_gi
->m_rectAll
.y
+ m_gi
->m_rectAll
.height
+ 2 - m_gi
->m_rectLabel
.height
;
1273 m_gi
->m_rectHighlight
.x
= m_gi
->m_rectLabel
.x
- 2;
1274 m_gi
->m_rectHighlight
.y
= m_gi
->m_rectLabel
.y
- 2;
1276 else // no text, highlight the icon
1278 m_gi
->m_rectHighlight
.x
= m_gi
->m_rectIcon
.x
- 4;
1279 m_gi
->m_rectHighlight
.y
= m_gi
->m_rectIcon
.y
- 4;
1284 m_gi
->m_rectAll
.x
= x
;
1285 m_gi
->m_rectAll
.y
= y
;
1287 m_gi
->m_rectHighlight
.x
= m_gi
->m_rectAll
.x
;
1288 m_gi
->m_rectHighlight
.y
= m_gi
->m_rectAll
.y
;
1289 m_gi
->m_rectLabel
.y
= m_gi
->m_rectAll
.y
+ 2;
1291 if (item
->HasImage())
1293 m_gi
->m_rectIcon
.x
= m_gi
->m_rectAll
.x
+ 2;
1294 m_gi
->m_rectIcon
.y
= m_gi
->m_rectAll
.y
+ 2;
1295 m_gi
->m_rectLabel
.x
= m_gi
->m_rectAll
.x
+ 4 + (EXTRA_WIDTH
/2) + m_gi
->m_rectIcon
.width
;
1299 m_gi
->m_rectLabel
.x
= m_gi
->m_rectAll
.x
+ (EXTRA_WIDTH
/2);
1304 wxFAIL_MSG( _T("unexpected call to SetPosition") );
1308 wxFAIL_MSG( _T("unknown mode") );
1313 void wxListLineData::InitItems( int num
)
1315 for (int i
= 0; i
< num
; i
++)
1316 m_items
.Append( new wxListItemData(m_owner
) );
1319 void wxListLineData::SetItem( int index
, const wxListItem
&info
)
1321 wxListItemDataList::compatibility_iterator node
= m_items
.Item( index
);
1322 wxCHECK_RET( node
, _T("invalid column index in SetItem") );
1324 wxListItemData
*item
= node
->GetData();
1325 item
->SetItem( info
);
1328 void wxListLineData::GetItem( int index
, wxListItem
&info
)
1330 wxListItemDataList::compatibility_iterator node
= m_items
.Item( index
);
1333 wxListItemData
*item
= node
->GetData();
1334 item
->GetItem( info
);
1338 wxString
wxListLineData::GetText(int index
) const
1342 wxListItemDataList::compatibility_iterator node
= m_items
.Item( index
);
1345 wxListItemData
*item
= node
->GetData();
1346 s
= item
->GetText();
1352 void wxListLineData::SetText( int index
, const wxString
& s
)
1354 wxListItemDataList::compatibility_iterator node
= m_items
.Item( index
);
1357 wxListItemData
*item
= node
->GetData();
1362 void wxListLineData::SetImage( int index
, int image
)
1364 wxListItemDataList::compatibility_iterator node
= m_items
.Item( index
);
1365 wxCHECK_RET( node
, _T("invalid column index in SetImage()") );
1367 wxListItemData
*item
= node
->GetData();
1368 item
->SetImage(image
);
1371 int wxListLineData::GetImage( int index
) const
1373 wxListItemDataList::compatibility_iterator node
= m_items
.Item( index
);
1374 wxCHECK_MSG( node
, -1, _T("invalid column index in GetImage()") );
1376 wxListItemData
*item
= node
->GetData();
1377 return item
->GetImage();
1380 wxListItemAttr
*wxListLineData::GetAttr() const
1382 wxListItemDataList::compatibility_iterator node
= m_items
.GetFirst();
1383 wxCHECK_MSG( node
, NULL
, _T("invalid column index in GetAttr()") );
1385 wxListItemData
*item
= node
->GetData();
1386 return item
->GetAttr();
1389 void wxListLineData::SetAttr(wxListItemAttr
*attr
)
1391 wxListItemDataList::compatibility_iterator node
= m_items
.GetFirst();
1392 wxCHECK_RET( node
, _T("invalid column index in SetAttr()") );
1394 wxListItemData
*item
= node
->GetData();
1395 item
->SetAttr(attr
);
1398 bool wxListLineData::SetAttributes(wxDC
*dc
,
1399 const wxListItemAttr
*attr
,
1402 wxWindow
*listctrl
= m_owner
->GetParent();
1406 // don't use foreground colour for drawing highlighted items - this might
1407 // make them completely invisible (and there is no way to do bit
1408 // arithmetics on wxColour, unfortunately)
1413 if (m_owner
->HasFocus())
1419 colText
= wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHTTEXT
);
1421 else if ( attr
&& attr
->HasTextColour() )
1422 colText
= attr
->GetTextColour();
1424 colText
= listctrl
->GetForegroundColour();
1426 dc
->SetTextForeground(colText
);
1430 if ( attr
&& attr
->HasFont() )
1431 font
= attr
->GetFont();
1433 font
= listctrl
->GetFont();
1438 bool hasBgCol
= attr
&& attr
->HasBackgroundColour();
1439 if ( highlighted
|| hasBgCol
)
1442 dc
->SetBrush( *m_owner
->GetHighlightBrush() );
1444 dc
->SetBrush(wxBrush(attr
->GetBackgroundColour(), wxSOLID
));
1446 dc
->SetPen( *wxTRANSPARENT_PEN
);
1454 void wxListLineData::Draw( wxDC
*dc
)
1456 wxListItemDataList::compatibility_iterator node
= m_items
.GetFirst();
1457 wxCHECK_RET( node
, _T("no subitems at all??") );
1459 bool highlighted
= IsHighlighted();
1461 wxListItemAttr
*attr
= GetAttr();
1463 if ( SetAttributes(dc
, attr
, highlighted
) )
1464 #if ( !defined(__WXGTK20__) && !defined(__WXMAC__) )
1466 dc
->DrawRectangle( m_gi
->m_rectHighlight
);
1472 int flags
= wxCONTROL_SELECTED
;
1473 if (m_owner
->HasFocus())
1474 flags
|= wxCONTROL_FOCUSED
;
1475 wxRendererNative::Get().DrawItemSelectionRect( m_owner
, *dc
, m_gi
->m_rectHighlight
, flags
);
1480 dc
->DrawRectangle( m_gi
->m_rectHighlight
);
1485 // just for debugging to better see where the items are
1487 dc
->SetPen(*wxRED_PEN
);
1488 dc
->SetBrush(*wxTRANSPARENT_BRUSH
);
1489 dc
->DrawRectangle( m_gi
->m_rectAll
);
1490 dc
->SetPen(*wxGREEN_PEN
);
1491 dc
->DrawRectangle( m_gi
->m_rectIcon
);
1494 wxListItemData
*item
= node
->GetData();
1495 if (item
->HasImage())
1497 // centre the image inside our rectangle, this looks nicer when items
1498 // ae aligned in a row
1499 const wxRect
& rectIcon
= m_gi
->m_rectIcon
;
1501 m_owner
->DrawImage(item
->GetImage(), dc
, rectIcon
.x
, rectIcon
.y
);
1504 if (item
->HasText())
1506 const wxRect
& rectLabel
= m_gi
->m_rectLabel
;
1508 wxDCClipper
clipper(*dc
, rectLabel
);
1509 dc
->DrawText(item
->GetText(), rectLabel
.x
, rectLabel
.y
);
1513 void wxListLineData::DrawInReportMode( wxDC
*dc
,
1515 const wxRect
& rectHL
,
1518 // TODO: later we should support setting different attributes for
1519 // different columns - to do it, just add "col" argument to
1520 // GetAttr() and move these lines into the loop below
1521 wxListItemAttr
*attr
= GetAttr();
1522 if ( SetAttributes(dc
, attr
, highlighted
) )
1523 #if ( !defined(__WXGTK20__) && !defined(__WXMAC__) )
1525 dc
->DrawRectangle( rectHL
);
1531 int flags
= wxCONTROL_SELECTED
;
1532 if (m_owner
->HasFocus())
1533 flags
|= wxCONTROL_FOCUSED
;
1534 wxRendererNative::Get().DrawItemSelectionRect( m_owner
, *dc
, rectHL
, flags
);
1538 dc
->DrawRectangle( rectHL
);
1543 wxCoord x
= rect
.x
+ HEADER_OFFSET_X
,
1544 yMid
= rect
.y
+ rect
.height
/2;
1546 // This probably needs to be done
1547 // on all platforms as the icons
1548 // otherwise nearly touch the border
1553 for ( wxListItemDataList::compatibility_iterator node
= m_items
.GetFirst();
1555 node
= node
->GetNext(), col
++ )
1557 wxListItemData
*item
= node
->GetData();
1559 int width
= m_owner
->GetColumnWidth(col
);
1563 if ( item
->HasImage() )
1566 m_owner
->GetImageSize( item
->GetImage(), ix
, iy
);
1567 m_owner
->DrawImage( item
->GetImage(), dc
, xOld
, yMid
- iy
/2 );
1569 ix
+= IMAGE_MARGIN_IN_REPORT_MODE
;
1575 if ( item
->HasText() )
1576 DrawTextFormatted(dc
, item
->GetText(), col
, xOld
, yMid
, width
- 8);
1580 void wxListLineData::DrawTextFormatted(wxDC
*dc
,
1581 const wxString
&text
,
1588 dc
->GetTextExtent(text
, &w
, &h
);
1590 const wxCoord y
= yMid
- (h
+ 1)/2;
1592 wxDCClipper
clipper(*dc
, x
, y
, width
, h
);
1594 // determine if the string can fit inside the current width
1597 // it can, draw it using the items alignment
1599 m_owner
->GetColumn(col
, item
);
1600 switch ( item
.GetAlign() )
1602 case wxLIST_FORMAT_LEFT
:
1606 case wxLIST_FORMAT_RIGHT
:
1610 case wxLIST_FORMAT_CENTER
:
1611 x
+= (width
- w
) / 2;
1615 wxFAIL_MSG( _T("unknown list item format") );
1619 dc
->DrawText(text
, x
, y
);
1621 else // otherwise, truncate and add an ellipsis if possible
1623 // determine the base width
1624 wxString
ellipsis(wxT("..."));
1626 dc
->GetTextExtent(ellipsis
, &base_w
, &h
);
1628 // continue until we have enough space or only one character left
1630 size_t len
= text
.length();
1631 wxString drawntext
= text
.Left(len
);
1634 dc
->GetTextExtent(drawntext
.Last(), &w_c
, &h_c
);
1635 drawntext
.RemoveLast();
1638 if (w
+ base_w
<= width
)
1642 // if still not enough space, remove ellipsis characters
1643 while (ellipsis
.length() > 0 && w
+ base_w
> width
)
1645 ellipsis
= ellipsis
.Left(ellipsis
.length() - 1);
1646 dc
->GetTextExtent(ellipsis
, &base_w
, &h
);
1649 // now draw the text
1650 dc
->DrawText(drawntext
, x
, y
);
1651 dc
->DrawText(ellipsis
, x
+ w
, y
);
1655 bool wxListLineData::Highlight( bool on
)
1657 wxCHECK_MSG( !IsVirtual(), false, _T("unexpected call to Highlight") );
1659 if ( on
== m_highlighted
)
1667 void wxListLineData::ReverseHighlight( void )
1669 Highlight(!IsHighlighted());
1672 //-----------------------------------------------------------------------------
1673 // wxListHeaderWindow
1674 //-----------------------------------------------------------------------------
1676 IMPLEMENT_DYNAMIC_CLASS(wxListHeaderWindow
,wxWindow
)
1678 BEGIN_EVENT_TABLE(wxListHeaderWindow
,wxWindow
)
1679 EVT_PAINT (wxListHeaderWindow::OnPaint
)
1680 EVT_MOUSE_EVENTS (wxListHeaderWindow::OnMouse
)
1681 EVT_SET_FOCUS (wxListHeaderWindow::OnSetFocus
)
1684 void wxListHeaderWindow::Init()
1686 m_currentCursor
= (wxCursor
*) NULL
;
1687 m_isDragging
= false;
1691 wxListHeaderWindow::wxListHeaderWindow()
1695 m_owner
= (wxListMainWindow
*) NULL
;
1696 m_resizeCursor
= (wxCursor
*) NULL
;
1699 wxListHeaderWindow::wxListHeaderWindow( wxWindow
*win
,
1701 wxListMainWindow
*owner
,
1705 const wxString
&name
)
1706 : wxWindow( win
, id
, pos
, size
, style
, name
)
1711 m_resizeCursor
= new wxCursor( wxCURSOR_SIZEWE
);
1714 wxVisualAttributes attr
= wxPanel::GetClassDefaultAttributes();
1715 SetOwnForegroundColour( attr
.colFg
);
1716 SetOwnBackgroundColour( attr
.colBg
);
1718 SetOwnFont( attr
.font
);
1720 SetOwnForegroundColour( wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT
));
1721 SetOwnBackgroundColour( wxSystemSettings::GetColour(wxSYS_COLOUR_BTNFACE
));
1723 SetOwnFont( wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT
));
1727 wxListHeaderWindow::~wxListHeaderWindow()
1729 delete m_resizeCursor
;
1732 #ifdef __WXUNIVERSAL__
1733 #include "wx/univ/renderer.h"
1734 #include "wx/univ/theme.h"
1737 // shift the DC origin to match the position of the main window horz
1738 // scrollbar: this allows us to always use logical coords
1739 void wxListHeaderWindow::AdjustDC(wxDC
& dc
)
1742 m_owner
->GetScrollPixelsPerUnit( &xpix
, NULL
);
1745 m_owner
->GetViewStart( &view_start
, NULL
);
1750 dc
.GetDeviceOrigin( &org_x
, &org_y
);
1752 // account for the horz scrollbar offset
1754 if (GetLayoutDirection() == wxLayout_RightToLeft
)
1756 // Maybe we just have to check for m_signX
1757 // in the DC, but I leave the #ifdef __WXGTK__
1759 dc
.SetDeviceOrigin( org_x
+ (view_start
* xpix
), org_y
);
1763 dc
.SetDeviceOrigin( org_x
- (view_start
* xpix
), org_y
);
1766 void wxListHeaderWindow::OnPaint( wxPaintEvent
&WXUNUSED(event
) )
1768 wxPaintDC
dc( this );
1773 dc
.SetFont( GetFont() );
1775 // width and height of the entire header window
1777 GetClientSize( &w
, &h
);
1778 m_owner
->CalcUnscrolledPosition(w
, 0, &w
, NULL
);
1780 dc
.SetBackgroundMode(wxTRANSPARENT
);
1781 dc
.SetTextForeground(GetForegroundColour());
1783 int x
= HEADER_OFFSET_X
;
1784 int numColumns
= m_owner
->GetColumnCount();
1786 for ( int i
= 0; i
< numColumns
&& x
< w
; i
++ )
1788 m_owner
->GetColumn( i
, item
);
1789 int wCol
= item
.m_width
;
1791 // the width of the rect to draw: make it smaller to fit entirely
1792 // inside the column rect
1802 if (!m_parent
->IsEnabled())
1803 flags
|= wxCONTROL_DISABLED
;
1805 // NB: The code below is not really Mac-specific, but since we are close
1806 // to 2.8 release and I don't have time to test on other platforms, I
1807 // defined this only for wxMac. If this behavior is desired on
1808 // other platforms, please go ahead and revise or remove the #ifdef.
1810 if ( !m_owner
->IsVirtual() && (item
.m_mask
& wxLIST_MASK_STATE
) &&
1811 (item
.m_state
& wxLIST_STATE_SELECTED
) )
1812 flags
|= wxCONTROL_SELECTED
;
1815 wxRendererNative::Get().DrawHeaderButton
1819 wxRect(x
, HEADER_OFFSET_Y
, cw
, ch
),
1823 // see if we have enough space for the column label
1825 // for this we need the width of the text
1828 dc
.GetTextExtent(item
.GetText(), &wLabel
, &hLabel
);
1829 wLabel
+= 2 * EXTRA_WIDTH
;
1831 // and the width of the icon, if any
1832 static const int MARGIN_BETWEEN_TEXT_AND_ICON
= 2;
1833 int ix
= 0, iy
= 0; // init them just to suppress the compiler warnings
1834 const int image
= item
.m_image
;
1835 wxImageList
*imageList
;
1838 imageList
= m_owner
->m_small_image_list
;
1841 imageList
->GetSize(image
, ix
, iy
);
1842 wLabel
+= ix
+ MARGIN_BETWEEN_TEXT_AND_ICON
;
1850 // ignore alignment if there is not enough space anyhow
1852 switch ( wLabel
< cw
? item
.GetAlign() : wxLIST_FORMAT_LEFT
)
1855 wxFAIL_MSG( _T("unknown list item format") );
1858 case wxLIST_FORMAT_LEFT
:
1862 case wxLIST_FORMAT_RIGHT
:
1863 xAligned
= x
+ cw
- wLabel
;
1866 case wxLIST_FORMAT_CENTER
:
1867 xAligned
= x
+ (cw
- wLabel
) / 2;
1871 // if we have an image, draw it on the right of the label
1878 xAligned
+ wLabel
- ix
- MARGIN_BETWEEN_TEXT_AND_ICON
,
1879 HEADER_OFFSET_Y
+ (h
- 4 - iy
)/2,
1880 wxIMAGELIST_DRAW_TRANSPARENT
1883 cw
-= ix
+ MARGIN_BETWEEN_TEXT_AND_ICON
;
1886 // draw the text clipping it so that it doesn't overwrite the column
1888 wxDCClipper
clipper(dc
, x
, HEADER_OFFSET_Y
, cw
, h
- 4 );
1890 dc
.DrawText( item
.GetText(),
1891 xAligned
+ EXTRA_WIDTH
, h
/ 2 - hLabel
/ 2 ); //HEADER_OFFSET_Y + EXTRA_HEIGHT );
1897 void wxListHeaderWindow::DrawCurrent()
1899 int x1
= m_currentX
;
1901 m_owner
->ClientToScreen( &x1
, &y1
);
1903 int x2
= m_currentX
;
1905 m_owner
->GetClientSize( NULL
, &y2
);
1906 m_owner
->ClientToScreen( &x2
, &y2
);
1909 dc
.SetLogicalFunction( wxINVERT
);
1910 dc
.SetPen( wxPen( *wxBLACK
, 2, wxSOLID
) );
1911 dc
.SetBrush( *wxTRANSPARENT_BRUSH
);
1915 dc
.DrawLine( x1
, y1
, x2
, y2
);
1917 dc
.SetLogicalFunction( wxCOPY
);
1919 dc
.SetPen( wxNullPen
);
1920 dc
.SetBrush( wxNullBrush
);
1923 void wxListHeaderWindow::OnMouse( wxMouseEvent
&event
)
1925 // we want to work with logical coords
1927 m_owner
->CalcUnscrolledPosition(event
.GetX(), 0, &x
, NULL
);
1928 int y
= event
.GetY();
1932 SendListEvent(wxEVT_COMMAND_LIST_COL_DRAGGING
, event
.GetPosition());
1934 // we don't draw the line beyond our window, but we allow dragging it
1937 GetClientSize( &w
, NULL
);
1938 m_owner
->CalcUnscrolledPosition(w
, 0, &w
, NULL
);
1941 // erase the line if it was drawn
1942 if ( m_currentX
< w
)
1945 if (event
.ButtonUp())
1948 m_isDragging
= false;
1950 m_owner
->SetColumnWidth( m_column
, m_currentX
- m_minX
);
1951 SendListEvent(wxEVT_COMMAND_LIST_COL_END_DRAG
, event
.GetPosition());
1958 m_currentX
= m_minX
+ 7;
1960 // draw in the new location
1961 if ( m_currentX
< w
)
1965 else // not dragging
1968 bool hit_border
= false;
1970 // end of the current column
1973 // find the column where this event occurred
1975 countCol
= m_owner
->GetColumnCount();
1976 for (col
= 0; col
< countCol
; col
++)
1978 xpos
+= m_owner
->GetColumnWidth( col
);
1981 if ( (abs(x
-xpos
) < 3) && (y
< 22) )
1983 // near the column border
1990 // inside the column
1997 if ( col
== countCol
)
2000 if (event
.LeftDown() || event
.RightUp())
2002 if (hit_border
&& event
.LeftDown())
2004 if ( SendListEvent(wxEVT_COMMAND_LIST_COL_BEGIN_DRAG
,
2005 event
.GetPosition()) )
2007 m_isDragging
= true;
2012 //else: column resizing was vetoed by the user code
2014 else // click on a column
2016 // record the selected state of the columns
2017 if (event
.LeftDown())
2019 for (int i
=0; i
< m_owner
->GetColumnCount(); i
++)
2022 m_owner
->GetColumn(i
, colItem
);
2023 long state
= colItem
.GetState();
2025 colItem
.SetState(state
| wxLIST_STATE_SELECTED
);
2027 colItem
.SetState(state
& ~wxLIST_STATE_SELECTED
);
2028 m_owner
->SetColumn(i
, colItem
);
2032 SendListEvent( event
.LeftDown()
2033 ? wxEVT_COMMAND_LIST_COL_CLICK
2034 : wxEVT_COMMAND_LIST_COL_RIGHT_CLICK
,
2035 event
.GetPosition());
2038 else if (event
.Moving())
2043 setCursor
= m_currentCursor
== wxSTANDARD_CURSOR
;
2044 m_currentCursor
= m_resizeCursor
;
2048 setCursor
= m_currentCursor
!= wxSTANDARD_CURSOR
;
2049 m_currentCursor
= wxSTANDARD_CURSOR
;
2053 SetCursor(*m_currentCursor
);
2058 void wxListHeaderWindow::OnSetFocus( wxFocusEvent
&WXUNUSED(event
) )
2060 m_owner
->SetFocus();
2064 bool wxListHeaderWindow::SendListEvent(wxEventType type
, const wxPoint
& pos
)
2066 wxWindow
*parent
= GetParent();
2067 wxListEvent
le( type
, parent
->GetId() );
2068 le
.SetEventObject( parent
);
2069 le
.m_pointDrag
= pos
;
2071 // the position should be relative to the parent window, not
2072 // this one for compatibility with MSW and common sense: the
2073 // user code doesn't know anything at all about this header
2074 // window, so why should it get positions relative to it?
2075 le
.m_pointDrag
.y
-= GetSize().y
;
2077 le
.m_col
= m_column
;
2078 return !parent
->GetEventHandler()->ProcessEvent( le
) || le
.IsAllowed();
2081 //-----------------------------------------------------------------------------
2082 // wxListRenameTimer (internal)
2083 //-----------------------------------------------------------------------------
2085 wxListRenameTimer::wxListRenameTimer( wxListMainWindow
*owner
)
2090 void wxListRenameTimer::Notify()
2092 m_owner
->OnRenameTimer();
2095 //-----------------------------------------------------------------------------
2096 // wxListTextCtrlWrapper (internal)
2097 //-----------------------------------------------------------------------------
2099 BEGIN_EVENT_TABLE(wxListTextCtrlWrapper
, wxEvtHandler
)
2100 EVT_CHAR (wxListTextCtrlWrapper::OnChar
)
2101 EVT_KEY_UP (wxListTextCtrlWrapper::OnKeyUp
)
2102 EVT_KILL_FOCUS (wxListTextCtrlWrapper::OnKillFocus
)
2105 wxListTextCtrlWrapper::wxListTextCtrlWrapper(wxListMainWindow
*owner
,
2108 : m_startValue(owner
->GetItemText(itemEdit
)),
2109 m_itemEdited(itemEdit
)
2114 m_aboutToFinish
= false;
2116 wxRect rectLabel
= owner
->GetLineLabelRect(itemEdit
);
2118 m_owner
->CalcScrolledPosition(rectLabel
.x
, rectLabel
.y
,
2119 &rectLabel
.x
, &rectLabel
.y
);
2121 m_text
->Create(owner
, wxID_ANY
, m_startValue
,
2122 wxPoint(rectLabel
.x
-4,rectLabel
.y
-4),
2123 wxSize(rectLabel
.width
+11,rectLabel
.height
+8));
2126 m_text
->PushEventHandler(this);
2129 void wxListTextCtrlWrapper::Finish()
2135 m_text
->RemoveEventHandler(this);
2136 m_owner
->FinishEditing(m_text
);
2138 wxPendingDelete
.Append( this );
2142 bool wxListTextCtrlWrapper::AcceptChanges()
2144 const wxString value
= m_text
->GetValue();
2146 if ( value
== m_startValue
)
2147 // nothing changed, always accept
2150 if ( !m_owner
->OnRenameAccept(m_itemEdited
, value
) )
2151 // vetoed by the user
2154 // accepted, do rename the item
2155 m_owner
->SetItemText(m_itemEdited
, value
);
2160 void wxListTextCtrlWrapper::AcceptChangesAndFinish()
2162 m_aboutToFinish
= true;
2164 // Notify the owner about the changes
2167 // Even if vetoed, close the control (consistent with MSW)
2171 void wxListTextCtrlWrapper::OnChar( wxKeyEvent
&event
)
2173 switch ( event
.m_keyCode
)
2176 AcceptChangesAndFinish();
2180 m_owner
->OnRenameCancelled( m_itemEdited
);
2189 void wxListTextCtrlWrapper::OnKeyUp( wxKeyEvent
&event
)
2197 // auto-grow the textctrl:
2198 wxSize parentSize
= m_owner
->GetSize();
2199 wxPoint myPos
= m_text
->GetPosition();
2200 wxSize mySize
= m_text
->GetSize();
2202 m_text
->GetTextExtent(m_text
->GetValue() + _T("MM"), &sx
, &sy
);
2203 if (myPos
.x
+ sx
> parentSize
.x
)
2204 sx
= parentSize
.x
- myPos
.x
;
2207 m_text
->SetSize(sx
, wxDefaultCoord
);
2212 void wxListTextCtrlWrapper::OnKillFocus( wxFocusEvent
&event
)
2214 if ( !m_finished
&& !m_aboutToFinish
)
2216 if ( !AcceptChanges() )
2217 m_owner
->OnRenameCancelled( m_itemEdited
);
2222 // We must let the native text control handle focus
2226 //-----------------------------------------------------------------------------
2228 //-----------------------------------------------------------------------------
2230 IMPLEMENT_DYNAMIC_CLASS(wxListMainWindow
,wxScrolledWindow
)
2232 BEGIN_EVENT_TABLE(wxListMainWindow
,wxScrolledWindow
)
2233 EVT_PAINT (wxListMainWindow::OnPaint
)
2234 EVT_MOUSE_EVENTS (wxListMainWindow::OnMouse
)
2235 EVT_CHAR (wxListMainWindow::OnChar
)
2236 EVT_KEY_DOWN (wxListMainWindow::OnKeyDown
)
2237 EVT_KEY_UP (wxListMainWindow::OnKeyUp
)
2238 EVT_SET_FOCUS (wxListMainWindow::OnSetFocus
)
2239 EVT_KILL_FOCUS (wxListMainWindow::OnKillFocus
)
2240 EVT_SCROLLWIN (wxListMainWindow::OnScroll
)
2243 void wxListMainWindow::Init()
2248 m_lineTo
= (size_t)-1;
2254 m_small_image_list
= (wxImageList
*) NULL
;
2255 m_normal_image_list
= (wxImageList
*) NULL
;
2257 m_small_spacing
= 30;
2258 m_normal_spacing
= 40;
2262 m_isCreated
= false;
2264 m_lastOnSame
= false;
2265 m_renameTimer
= new wxListRenameTimer( this );
2266 m_textctrlWrapper
= NULL
;
2270 m_lineSelectSingleOnUp
=
2271 m_lineBeforeLastClicked
= (size_t)-1;
2276 wxListMainWindow::wxListMainWindow()
2281 m_highlightUnfocusedBrush
= (wxBrush
*) NULL
;
2284 wxListMainWindow::wxListMainWindow( wxWindow
*parent
,
2289 const wxString
&name
)
2290 : wxScrolledWindow( parent
, id
, pos
, size
,
2291 style
| wxHSCROLL
| wxVSCROLL
, name
)
2295 m_highlightBrush
= new wxBrush
2297 wxSystemSettings::GetColour
2299 wxSYS_COLOUR_HIGHLIGHT
2304 m_highlightUnfocusedBrush
= new wxBrush
2306 wxSystemSettings::GetColour
2308 wxSYS_COLOUR_BTNSHADOW
2313 SetScrollbars( 0, 0, 0, 0, 0, 0 );
2315 wxVisualAttributes attr
= wxGenericListCtrl::GetClassDefaultAttributes();
2316 SetOwnForegroundColour( attr
.colFg
);
2317 SetOwnBackgroundColour( attr
.colBg
);
2319 SetOwnFont( attr
.font
);
2322 wxListMainWindow::~wxListMainWindow()
2325 WX_CLEAR_LIST(wxListHeaderDataList
, m_columns
);
2326 WX_CLEAR_ARRAY(m_aColWidths
);
2328 delete m_highlightBrush
;
2329 delete m_highlightUnfocusedBrush
;
2330 delete m_renameTimer
;
2333 void wxListMainWindow::CacheLineData(size_t line
)
2335 wxGenericListCtrl
*listctrl
= GetListCtrl();
2337 wxListLineData
*ld
= GetDummyLine();
2339 size_t countCol
= GetColumnCount();
2340 for ( size_t col
= 0; col
< countCol
; col
++ )
2342 ld
->SetText(col
, listctrl
->OnGetItemText(line
, col
));
2343 ld
->SetImage(col
, listctrl
->OnGetItemColumnImage(line
, col
));
2346 ld
->SetAttr(listctrl
->OnGetItemAttr(line
));
2349 wxListLineData
*wxListMainWindow::GetDummyLine() const
2351 wxASSERT_MSG( !IsEmpty(), _T("invalid line index") );
2352 wxASSERT_MSG( IsVirtual(), _T("GetDummyLine() shouldn't be called") );
2354 wxListMainWindow
*self
= wxConstCast(this, wxListMainWindow
);
2356 // we need to recreate the dummy line if the number of columns in the
2357 // control changed as it would have the incorrect number of fields
2359 if ( !m_lines
.IsEmpty() &&
2360 m_lines
[0].m_items
.GetCount() != (size_t)GetColumnCount() )
2362 self
->m_lines
.Clear();
2365 if ( m_lines
.IsEmpty() )
2367 wxListLineData
*line
= new wxListLineData(self
);
2368 self
->m_lines
.Add(line
);
2370 // don't waste extra memory -- there never going to be anything
2371 // else/more in this array
2372 self
->m_lines
.Shrink();
2378 // ----------------------------------------------------------------------------
2379 // line geometry (report mode only)
2380 // ----------------------------------------------------------------------------
2382 wxCoord
wxListMainWindow::GetLineHeight() const
2384 // we cache the line height as calling GetTextExtent() is slow
2385 if ( !m_lineHeight
)
2387 wxListMainWindow
*self
= wxConstCast(this, wxListMainWindow
);
2389 wxClientDC
dc( self
);
2390 dc
.SetFont( GetFont() );
2393 dc
.GetTextExtent(_T("H"), NULL
, &y
);
2395 if ( m_small_image_list
&& m_small_image_list
->GetImageCount() )
2398 m_small_image_list
->GetSize(0, iw
, ih
);
2403 self
->m_lineHeight
= y
+ LINE_SPACING
;
2406 return m_lineHeight
;
2409 wxCoord
wxListMainWindow::GetLineY(size_t line
) const
2411 wxASSERT_MSG( InReportView(), _T("only works in report mode") );
2413 return LINE_SPACING
+ line
* GetLineHeight();
2416 wxRect
wxListMainWindow::GetLineRect(size_t line
) const
2418 if ( !InReportView() )
2419 return GetLine(line
)->m_gi
->m_rectAll
;
2422 rect
.x
= HEADER_OFFSET_X
;
2423 rect
.y
= GetLineY(line
);
2424 rect
.width
= GetHeaderWidth();
2425 rect
.height
= GetLineHeight();
2430 wxRect
wxListMainWindow::GetLineLabelRect(size_t line
) const
2432 if ( !InReportView() )
2433 return GetLine(line
)->m_gi
->m_rectLabel
;
2436 rect
.x
= HEADER_OFFSET_X
;
2437 rect
.y
= GetLineY(line
);
2438 rect
.width
= GetColumnWidth(0);
2439 rect
.height
= GetLineHeight();
2444 wxRect
wxListMainWindow::GetLineIconRect(size_t line
) const
2446 if ( !InReportView() )
2447 return GetLine(line
)->m_gi
->m_rectIcon
;
2449 wxListLineData
*ld
= GetLine(line
);
2450 wxASSERT_MSG( ld
->HasImage(), _T("should have an image") );
2453 rect
.x
= HEADER_OFFSET_X
;
2454 rect
.y
= GetLineY(line
);
2455 GetImageSize(ld
->GetImage(), rect
.width
, rect
.height
);
2460 wxRect
wxListMainWindow::GetLineHighlightRect(size_t line
) const
2462 return InReportView() ? GetLineRect(line
)
2463 : GetLine(line
)->m_gi
->m_rectHighlight
;
2466 long wxListMainWindow::HitTestLine(size_t line
, int x
, int y
) const
2468 wxASSERT_MSG( line
< GetItemCount(), _T("invalid line in HitTestLine") );
2470 wxListLineData
*ld
= GetLine(line
);
2472 if ( ld
->HasImage() && GetLineIconRect(line
).Contains(x
, y
) )
2473 return wxLIST_HITTEST_ONITEMICON
;
2475 // VS: Testing for "ld->HasText() || InReportView()" instead of
2476 // "ld->HasText()" is needed to make empty lines in report view
2478 if ( ld
->HasText() || InReportView() )
2480 wxRect rect
= InReportView() ? GetLineRect(line
)
2481 : GetLineLabelRect(line
);
2483 if ( rect
.Contains(x
, y
) )
2484 return wxLIST_HITTEST_ONITEMLABEL
;
2490 // ----------------------------------------------------------------------------
2491 // highlight (selection) handling
2492 // ----------------------------------------------------------------------------
2494 bool wxListMainWindow::IsHighlighted(size_t line
) const
2498 return m_selStore
.IsSelected(line
);
2502 wxListLineData
*ld
= GetLine(line
);
2503 wxCHECK_MSG( ld
, false, _T("invalid index in IsHighlighted") );
2505 return ld
->IsHighlighted();
2509 void wxListMainWindow::HighlightLines( size_t lineFrom
,
2515 wxArrayInt linesChanged
;
2516 if ( !m_selStore
.SelectRange(lineFrom
, lineTo
, highlight
,
2519 // meny items changed state, refresh everything
2520 RefreshLines(lineFrom
, lineTo
);
2522 else // only a few items changed state, refresh only them
2524 size_t count
= linesChanged
.GetCount();
2525 for ( size_t n
= 0; n
< count
; n
++ )
2527 RefreshLine(linesChanged
[n
]);
2531 else // iterate over all items in non report view
2533 for ( size_t line
= lineFrom
; line
<= lineTo
; line
++ )
2535 if ( HighlightLine(line
, highlight
) )
2541 bool wxListMainWindow::HighlightLine( size_t line
, bool highlight
)
2547 changed
= m_selStore
.SelectItem(line
, highlight
);
2551 wxListLineData
*ld
= GetLine(line
);
2552 wxCHECK_MSG( ld
, false, _T("invalid index in HighlightLine") );
2554 changed
= ld
->Highlight(highlight
);
2559 SendNotify( line
, highlight
? wxEVT_COMMAND_LIST_ITEM_SELECTED
2560 : wxEVT_COMMAND_LIST_ITEM_DESELECTED
);
2566 void wxListMainWindow::RefreshLine( size_t line
)
2568 if ( InReportView() )
2570 size_t visibleFrom
, visibleTo
;
2571 GetVisibleLinesRange(&visibleFrom
, &visibleTo
);
2573 if ( line
< visibleFrom
|| line
> visibleTo
)
2577 wxRect rect
= GetLineRect(line
);
2579 CalcScrolledPosition( rect
.x
, rect
.y
, &rect
.x
, &rect
.y
);
2580 RefreshRect( rect
);
2583 void wxListMainWindow::RefreshLines( size_t lineFrom
, size_t lineTo
)
2585 // we suppose that they are ordered by caller
2586 wxASSERT_MSG( lineFrom
<= lineTo
, _T("indices in disorder") );
2588 wxASSERT_MSG( lineTo
< GetItemCount(), _T("invalid line range") );
2590 if ( InReportView() )
2592 size_t visibleFrom
, visibleTo
;
2593 GetVisibleLinesRange(&visibleFrom
, &visibleTo
);
2595 if ( lineFrom
< visibleFrom
)
2596 lineFrom
= visibleFrom
;
2597 if ( lineTo
> visibleTo
)
2602 rect
.y
= GetLineY(lineFrom
);
2603 rect
.width
= GetClientSize().x
;
2604 rect
.height
= GetLineY(lineTo
) - rect
.y
+ GetLineHeight();
2606 CalcScrolledPosition( rect
.x
, rect
.y
, &rect
.x
, &rect
.y
);
2607 RefreshRect( rect
);
2611 // TODO: this should be optimized...
2612 for ( size_t line
= lineFrom
; line
<= lineTo
; line
++ )
2619 void wxListMainWindow::RefreshAfter( size_t lineFrom
)
2621 if ( InReportView() )
2623 size_t visibleFrom
, visibleTo
;
2624 GetVisibleLinesRange(&visibleFrom
, &visibleTo
);
2626 if ( lineFrom
< visibleFrom
)
2627 lineFrom
= visibleFrom
;
2628 else if ( lineFrom
> visibleTo
)
2633 rect
.y
= GetLineY(lineFrom
);
2634 CalcScrolledPosition( rect
.x
, rect
.y
, &rect
.x
, &rect
.y
);
2636 wxSize size
= GetClientSize();
2637 rect
.width
= size
.x
;
2639 // refresh till the bottom of the window
2640 rect
.height
= size
.y
- rect
.y
;
2642 RefreshRect( rect
);
2646 // TODO: how to do it more efficiently?
2651 void wxListMainWindow::RefreshSelected()
2657 if ( InReportView() )
2659 GetVisibleLinesRange(&from
, &to
);
2664 to
= GetItemCount() - 1;
2667 if ( HasCurrent() && m_current
>= from
&& m_current
<= to
)
2668 RefreshLine(m_current
);
2670 for ( size_t line
= from
; line
<= to
; line
++ )
2672 // NB: the test works as expected even if m_current == -1
2673 if ( line
!= m_current
&& IsHighlighted(line
) )
2678 void wxListMainWindow::Freeze()
2683 void wxListMainWindow::Thaw()
2685 wxCHECK_RET( m_freezeCount
> 0, _T("thawing unfrozen list control?") );
2687 if ( --m_freezeCount
== 0 )
2691 void wxListMainWindow::OnPaint( wxPaintEvent
&WXUNUSED(event
) )
2693 // Note: a wxPaintDC must be constructed even if no drawing is
2694 // done (a Windows requirement).
2695 wxPaintDC
dc( this );
2697 if ( IsEmpty() || m_freezeCount
)
2698 // nothing to draw or not the moment to draw it
2702 // delay the repainting until we calculate all the items positions
2708 CalcScrolledPosition( 0, 0, &dev_x
, &dev_y
);
2710 dc
.SetFont( GetFont() );
2712 if ( InReportView() )
2714 int lineHeight
= GetLineHeight();
2716 size_t visibleFrom
, visibleTo
;
2717 GetVisibleLinesRange(&visibleFrom
, &visibleTo
);
2720 int xOrig
= dc
.LogicalToDeviceX( 0 );
2721 int yOrig
= dc
.LogicalToDeviceY( 0 );
2723 // tell the caller cache to cache the data
2726 wxListEvent
evCache(wxEVT_COMMAND_LIST_CACHE_HINT
,
2727 GetParent()->GetId());
2728 evCache
.SetEventObject( GetParent() );
2729 evCache
.m_oldItemIndex
= visibleFrom
;
2730 evCache
.m_itemIndex
= visibleTo
;
2731 GetParent()->GetEventHandler()->ProcessEvent( evCache
);
2734 for ( size_t line
= visibleFrom
; line
<= visibleTo
; line
++ )
2736 rectLine
= GetLineRect(line
);
2739 if ( !IsExposed(rectLine
.x
+ xOrig
, rectLine
.y
+ yOrig
,
2740 rectLine
.width
, rectLine
.height
) )
2742 // don't redraw unaffected lines to avoid flicker
2746 GetLine(line
)->DrawInReportMode( &dc
,
2748 GetLineHighlightRect(line
),
2749 IsHighlighted(line
) );
2752 if ( HasFlag(wxLC_HRULES
) )
2754 wxPen
pen(GetRuleColour(), 1, wxSOLID
);
2755 wxSize clientSize
= GetClientSize();
2757 // Don't draw the first one
2758 for ( size_t i
= visibleFrom
+ 1; i
<= visibleTo
; i
++ )
2761 dc
.SetBrush( *wxTRANSPARENT_BRUSH
);
2762 dc
.DrawLine(0 - dev_x
, i
* lineHeight
,
2763 clientSize
.x
- dev_x
, i
* lineHeight
);
2766 // Draw last horizontal rule
2767 if ( visibleTo
== GetItemCount() - 1 )
2770 dc
.SetBrush( *wxTRANSPARENT_BRUSH
);
2771 dc
.DrawLine(0 - dev_x
, (m_lineTo
+ 1) * lineHeight
,
2772 clientSize
.x
- dev_x
, (m_lineTo
+ 1) * lineHeight
);
2776 // Draw vertical rules if required
2777 if ( HasFlag(wxLC_VRULES
) && !IsEmpty() )
2779 wxPen
pen(GetRuleColour(), 1, wxSOLID
);
2780 wxRect firstItemRect
, lastItemRect
;
2782 GetItemRect(visibleFrom
, firstItemRect
);
2783 GetItemRect(visibleTo
, lastItemRect
);
2784 int x
= firstItemRect
.GetX();
2786 dc
.SetBrush(* wxTRANSPARENT_BRUSH
);
2788 for (int col
= 0; col
< GetColumnCount(); col
++)
2790 int colWidth
= GetColumnWidth(col
);
2792 dc
.DrawLine(x
- dev_x
- 2, firstItemRect
.GetY() - 1 - dev_y
,
2793 x
- dev_x
- 2, lastItemRect
.GetBottom() + 1 - dev_y
);
2799 size_t count
= GetItemCount();
2800 for ( size_t i
= 0; i
< count
; i
++ )
2802 GetLine(i
)->Draw( &dc
);
2807 // Don't draw rect outline under Mac at all.
2812 wxRect
rect( GetLineHighlightRect( m_current
) );
2814 dc
.SetPen( *wxBLACK_PEN
);
2815 dc
.SetBrush( *wxTRANSPARENT_BRUSH
);
2816 dc
.DrawRectangle( rect
);
2818 wxRendererNative::Get().DrawItemSelectionRect( this, dc
, rect
, wxCONTROL_CURRENT
|wxCONTROL_FOCUSED
);
2826 void wxListMainWindow::HighlightAll( bool on
)
2828 if ( IsSingleSel() )
2830 wxASSERT_MSG( !on
, _T("can't do this in a single selection control") );
2832 // we just have one item to turn off
2833 if ( HasCurrent() && IsHighlighted(m_current
) )
2835 HighlightLine(m_current
, false);
2836 RefreshLine(m_current
);
2841 HighlightLines(0, GetItemCount() - 1, on
);
2845 void wxListMainWindow::SendNotify( size_t line
,
2846 wxEventType command
,
2847 const wxPoint
& point
)
2849 wxListEvent
le( command
, GetParent()->GetId() );
2850 le
.SetEventObject( GetParent() );
2852 le
.m_itemIndex
= line
;
2854 // set only for events which have position
2855 if ( point
!= wxDefaultPosition
)
2856 le
.m_pointDrag
= point
;
2858 // don't try to get the line info for virtual list controls: the main
2859 // program has it anyhow and if we did it would result in accessing all
2860 // the lines, even those which are not visible now and this is precisely
2861 // what we're trying to avoid
2864 if ( line
!= (size_t)-1 )
2866 GetLine(line
)->GetItem( 0, le
.m_item
);
2868 //else: this happens for wxEVT_COMMAND_LIST_ITEM_FOCUSED event
2870 //else: there may be no more such item
2872 GetParent()->GetEventHandler()->ProcessEvent( le
);
2875 void wxListMainWindow::ChangeCurrent(size_t current
)
2877 m_current
= current
;
2879 // as the current item changed, we shouldn't start editing it when the
2880 // "slow click" timer expires as the click happened on another item
2881 if ( m_renameTimer
->IsRunning() )
2882 m_renameTimer
->Stop();
2884 SendNotify(current
, wxEVT_COMMAND_LIST_ITEM_FOCUSED
);
2887 wxTextCtrl
*wxListMainWindow::EditLabel(long item
, wxClassInfo
* textControlClass
)
2889 wxCHECK_MSG( (item
>= 0) && ((size_t)item
< GetItemCount()), NULL
,
2890 wxT("wrong index in wxGenericListCtrl::EditLabel()") );
2892 wxASSERT_MSG( textControlClass
->IsKindOf(CLASSINFO(wxTextCtrl
)),
2893 wxT("EditLabel() needs a text control") );
2895 size_t itemEdit
= (size_t)item
;
2897 wxListEvent
le( wxEVT_COMMAND_LIST_BEGIN_LABEL_EDIT
, GetParent()->GetId() );
2898 le
.SetEventObject( GetParent() );
2899 le
.m_itemIndex
= item
;
2900 wxListLineData
*data
= GetLine(itemEdit
);
2901 wxCHECK_MSG( data
, NULL
, _T("invalid index in EditLabel()") );
2902 data
->GetItem( 0, le
.m_item
);
2904 if ( GetParent()->GetEventHandler()->ProcessEvent( le
) && !le
.IsAllowed() )
2906 // vetoed by user code
2910 // We have to call this here because the label in question might just have
2911 // been added and no screen update taken place.
2916 // Pending events dispatched by wxSafeYield might have changed the item
2918 if ( (size_t)item
>= GetItemCount() )
2922 wxTextCtrl
* const text
= (wxTextCtrl
*)textControlClass
->CreateObject();
2923 m_textctrlWrapper
= new wxListTextCtrlWrapper(this, text
, item
);
2924 return m_textctrlWrapper
->GetText();
2927 void wxListMainWindow::OnRenameTimer()
2929 wxCHECK_RET( HasCurrent(), wxT("unexpected rename timer") );
2931 EditLabel( m_current
);
2934 bool wxListMainWindow::OnRenameAccept(size_t itemEdit
, const wxString
& value
)
2936 wxListEvent
le( wxEVT_COMMAND_LIST_END_LABEL_EDIT
, GetParent()->GetId() );
2937 le
.SetEventObject( GetParent() );
2938 le
.m_itemIndex
= itemEdit
;
2940 wxListLineData
*data
= GetLine(itemEdit
);
2942 wxCHECK_MSG( data
, false, _T("invalid index in OnRenameAccept()") );
2944 data
->GetItem( 0, le
.m_item
);
2945 le
.m_item
.m_text
= value
;
2946 return !GetParent()->GetEventHandler()->ProcessEvent( le
) ||
2950 void wxListMainWindow::OnRenameCancelled(size_t itemEdit
)
2952 // let owner know that the edit was cancelled
2953 wxListEvent
le( wxEVT_COMMAND_LIST_END_LABEL_EDIT
, GetParent()->GetId() );
2955 le
.SetEditCanceled(true);
2957 le
.SetEventObject( GetParent() );
2958 le
.m_itemIndex
= itemEdit
;
2960 wxListLineData
*data
= GetLine(itemEdit
);
2961 wxCHECK_RET( data
, _T("invalid index in OnRenameCancelled()") );
2963 data
->GetItem( 0, le
.m_item
);
2964 GetEventHandler()->ProcessEvent( le
);
2967 void wxListMainWindow::OnMouse( wxMouseEvent
&event
)
2971 // On wxMac we can't depend on the EVT_KILL_FOCUS event to properly
2972 // shutdown the edit control when the mouse is clicked elsewhere on the
2973 // listctrl because the order of events is different (or something like
2974 // that), so explicitly end the edit if it is active.
2975 if ( event
.LeftDown() && m_textctrlWrapper
)
2976 m_textctrlWrapper
->AcceptChangesAndFinish();
2979 if ( event
.LeftDown() )
2982 event
.SetEventObject( GetParent() );
2983 if ( GetParent()->GetEventHandler()->ProcessEvent( event
) )
2986 if (event
.GetEventType() == wxEVT_MOUSEWHEEL
)
2988 // let the base handle mouse wheel events.
2993 if ( !HasCurrent() || IsEmpty() )
2995 if (event
.RightDown())
2997 SendNotify( (size_t)-1, wxEVT_COMMAND_LIST_ITEM_RIGHT_CLICK
, event
.GetPosition() );
2998 // Allow generation of context menu event
3007 if ( !(event
.Dragging() || event
.ButtonDown() || event
.LeftUp() ||
3008 event
.ButtonDClick()) )
3011 int x
= event
.GetX();
3012 int y
= event
.GetY();
3013 CalcUnscrolledPosition( x
, y
, &x
, &y
);
3015 // where did we hit it (if we did)?
3018 size_t count
= GetItemCount(),
3021 if ( InReportView() )
3023 current
= y
/ GetLineHeight();
3024 if ( current
< count
)
3025 hitResult
= HitTestLine(current
, x
, y
);
3029 // TODO: optimize it too! this is less simple than for report view but
3030 // enumerating all items is still not a way to do it!!
3031 for ( current
= 0; current
< count
; current
++ )
3033 hitResult
= HitTestLine(current
, x
, y
);
3039 if (event
.Dragging())
3041 if (m_dragCount
== 0)
3043 // we have to report the raw, physical coords as we want to be
3044 // able to call HitTest(event.m_pointDrag) from the user code to
3045 // get the item being dragged
3046 m_dragStart
= event
.GetPosition();
3051 if (m_dragCount
!= 3)
3054 int command
= event
.RightIsDown() ? wxEVT_COMMAND_LIST_BEGIN_RDRAG
3055 : wxEVT_COMMAND_LIST_BEGIN_DRAG
;
3057 wxListEvent
le( command
, GetParent()->GetId() );
3058 le
.SetEventObject( GetParent() );
3059 le
.m_itemIndex
= m_lineLastClicked
;
3060 le
.m_pointDrag
= m_dragStart
;
3061 GetParent()->GetEventHandler()->ProcessEvent( le
);
3072 // outside of any item
3073 if (event
.RightDown())
3075 SendNotify( (size_t) -1, wxEVT_COMMAND_LIST_ITEM_RIGHT_CLICK
, event
.GetPosition() );
3076 // Allow generation of context menu event
3081 // reset the selection and bail out
3082 HighlightAll(false);
3088 bool forceClick
= false;
3089 if (event
.ButtonDClick())
3091 if ( m_renameTimer
->IsRunning() )
3092 m_renameTimer
->Stop();
3094 m_lastOnSame
= false;
3096 if ( current
== m_lineLastClicked
)
3098 SendNotify( current
, wxEVT_COMMAND_LIST_ITEM_ACTIVATED
);
3104 // The first click was on another item, so don't interpret this as
3105 // a double click, but as a simple click instead
3112 if (m_lineSelectSingleOnUp
!= (size_t)-1)
3114 // select single line
3115 HighlightAll( false );
3116 ReverseHighlight(m_lineSelectSingleOnUp
);
3121 if ((current
== m_current
) &&
3122 (hitResult
== wxLIST_HITTEST_ONITEMLABEL
) &&
3123 HasFlag(wxLC_EDIT_LABELS
) )
3125 m_renameTimer
->Start( 100, true );
3129 m_lastOnSame
= false;
3130 m_lineSelectSingleOnUp
= (size_t)-1;
3134 // This is necessary, because after a DnD operation in
3135 // from and to ourself, the up event is swallowed by the
3136 // DnD code. So on next non-up event (which means here and
3137 // now) m_lineSelectSingleOnUp should be reset.
3138 m_lineSelectSingleOnUp
= (size_t)-1;
3140 if (event
.RightDown())
3142 m_lineBeforeLastClicked
= m_lineLastClicked
;
3143 m_lineLastClicked
= current
;
3145 // If the item is already selected, do not update the selection.
3146 // Multi-selections should not be cleared if a selected item is clicked.
3147 if (!IsHighlighted(current
))
3149 HighlightAll(false);
3150 ChangeCurrent(current
);
3151 ReverseHighlight(m_current
);
3154 SendNotify( current
, wxEVT_COMMAND_LIST_ITEM_RIGHT_CLICK
, event
.GetPosition() );
3156 // Allow generation of context menu event
3159 else if (event
.MiddleDown())
3161 SendNotify( current
, wxEVT_COMMAND_LIST_ITEM_MIDDLE_CLICK
);
3163 else if ( event
.LeftDown() || forceClick
)
3165 m_lineBeforeLastClicked
= m_lineLastClicked
;
3166 m_lineLastClicked
= current
;
3168 size_t oldCurrent
= m_current
;
3169 bool oldWasSelected
= IsHighlighted(m_current
);
3171 bool cmdModifierDown
= event
.CmdDown();
3172 if ( IsSingleSel() || !(cmdModifierDown
|| event
.ShiftDown()) )
3174 if ( IsSingleSel() || !IsHighlighted(current
) )
3176 HighlightAll( false );
3178 ChangeCurrent(current
);
3180 ReverseHighlight(m_current
);
3182 else // multi sel & current is highlighted & no mod keys
3184 m_lineSelectSingleOnUp
= current
;
3185 ChangeCurrent(current
); // change focus
3188 else // multi sel & either ctrl or shift is down
3190 if (cmdModifierDown
)
3192 ChangeCurrent(current
);
3194 ReverseHighlight(m_current
);
3196 else if (event
.ShiftDown())
3198 ChangeCurrent(current
);
3200 size_t lineFrom
= oldCurrent
,
3203 if ( lineTo
< lineFrom
)
3206 lineFrom
= m_current
;
3209 HighlightLines(lineFrom
, lineTo
);
3211 else // !ctrl, !shift
3213 // test in the enclosing if should make it impossible
3214 wxFAIL_MSG( _T("how did we get here?") );
3218 if (m_current
!= oldCurrent
)
3219 RefreshLine( oldCurrent
);
3221 // forceClick is only set if the previous click was on another item
3222 m_lastOnSame
= !forceClick
&& (m_current
== oldCurrent
) && oldWasSelected
;
3226 void wxListMainWindow::MoveToItem(size_t item
)
3228 if ( item
== (size_t)-1 )
3231 wxRect rect
= GetLineRect(item
);
3233 int client_w
, client_h
;
3234 GetClientSize( &client_w
, &client_h
);
3236 const int hLine
= GetLineHeight();
3238 int view_x
= SCROLL_UNIT_X
* GetScrollPos( wxHORIZONTAL
);
3239 int view_y
= hLine
* GetScrollPos( wxVERTICAL
);
3241 if ( InReportView() )
3243 // the next we need the range of lines shown it might be different,
3244 // so recalculate it
3245 ResetVisibleLinesRange();
3247 if (rect
.y
< view_y
)
3248 Scroll( -1, rect
.y
/ hLine
);
3249 if (rect
.y
+ rect
.height
+ 5 > view_y
+ client_h
)
3250 Scroll( -1, (rect
.y
+ rect
.height
- client_h
+ hLine
) / hLine
);
3254 if (rect
.x
-view_x
< 5)
3255 Scroll( (rect
.x
- 5) / SCROLL_UNIT_X
, -1 );
3256 if (rect
.x
+ rect
.width
- 5 > view_x
+ client_w
)
3257 Scroll( (rect
.x
+ rect
.width
- client_w
+ SCROLL_UNIT_X
) / SCROLL_UNIT_X
, -1 );
3261 // ----------------------------------------------------------------------------
3262 // keyboard handling
3263 // ----------------------------------------------------------------------------
3265 void wxListMainWindow::OnArrowChar(size_t newCurrent
, const wxKeyEvent
& event
)
3267 wxCHECK_RET( newCurrent
< (size_t)GetItemCount(),
3268 _T("invalid item index in OnArrowChar()") );
3270 size_t oldCurrent
= m_current
;
3272 // in single selection we just ignore Shift as we can't select several
3274 if ( event
.ShiftDown() && !IsSingleSel() )
3276 ChangeCurrent(newCurrent
);
3278 // refresh the old focus to remove it
3279 RefreshLine( oldCurrent
);
3281 // select all the items between the old and the new one
3282 if ( oldCurrent
> newCurrent
)
3284 newCurrent
= oldCurrent
;
3285 oldCurrent
= m_current
;
3288 HighlightLines(oldCurrent
, newCurrent
);
3292 // all previously selected items are unselected unless ctrl is held
3293 if ( !event
.ControlDown() )
3294 HighlightAll(false);
3296 ChangeCurrent(newCurrent
);
3298 // refresh the old focus to remove it
3299 RefreshLine( oldCurrent
);
3301 if ( !event
.ControlDown() )
3303 HighlightLine( m_current
, true );
3307 RefreshLine( m_current
);
3312 void wxListMainWindow::OnKeyDown( wxKeyEvent
&event
)
3314 wxWindow
*parent
= GetParent();
3316 // propagate the key event upwards
3317 wxKeyEvent
ke( wxEVT_KEY_DOWN
);
3318 ke
.m_shiftDown
= event
.m_shiftDown
;
3319 ke
.m_controlDown
= event
.m_controlDown
;
3320 ke
.m_altDown
= event
.m_altDown
;
3321 ke
.m_metaDown
= event
.m_metaDown
;
3322 ke
.m_keyCode
= event
.m_keyCode
;
3325 ke
.SetEventObject( parent
);
3326 if (parent
->GetEventHandler()->ProcessEvent( ke
)) return;
3331 void wxListMainWindow::OnKeyUp( wxKeyEvent
&event
)
3333 wxWindow
*parent
= GetParent();
3335 // propagate the key event upwards
3336 wxKeyEvent
ke( wxEVT_KEY_UP
);
3337 ke
.m_shiftDown
= event
.m_shiftDown
;
3338 ke
.m_controlDown
= event
.m_controlDown
;
3339 ke
.m_altDown
= event
.m_altDown
;
3340 ke
.m_metaDown
= event
.m_metaDown
;
3341 ke
.m_keyCode
= event
.m_keyCode
;
3344 ke
.SetEventObject( parent
);
3345 if (parent
->GetEventHandler()->ProcessEvent( ke
)) return;
3350 void wxListMainWindow::OnChar( wxKeyEvent
&event
)
3352 wxWindow
*parent
= GetParent();
3354 // send a list_key event up
3357 wxListEvent
le( wxEVT_COMMAND_LIST_KEY_DOWN
, GetParent()->GetId() );
3358 le
.m_itemIndex
= m_current
;
3359 GetLine(m_current
)->GetItem( 0, le
.m_item
);
3360 le
.m_code
= event
.GetKeyCode();
3361 le
.SetEventObject( parent
);
3362 parent
->GetEventHandler()->ProcessEvent( le
);
3365 // propagate the char event upwards
3366 wxKeyEvent
ke( wxEVT_CHAR
);
3367 ke
.m_shiftDown
= event
.m_shiftDown
;
3368 ke
.m_controlDown
= event
.m_controlDown
;
3369 ke
.m_altDown
= event
.m_altDown
;
3370 ke
.m_metaDown
= event
.m_metaDown
;
3371 ke
.m_keyCode
= event
.m_keyCode
;
3374 ke
.SetEventObject( parent
);
3375 if (parent
->GetEventHandler()->ProcessEvent( ke
)) return;
3377 if (event
.GetKeyCode() == WXK_TAB
)
3379 wxNavigationKeyEvent nevent
;
3380 nevent
.SetWindowChange( event
.ControlDown() );
3381 nevent
.SetDirection( !event
.ShiftDown() );
3382 nevent
.SetEventObject( GetParent()->GetParent() );
3383 nevent
.SetCurrentFocus( m_parent
);
3384 if (GetParent()->GetParent()->GetEventHandler()->ProcessEvent( nevent
))
3388 // no item -> nothing to do
3395 // don't use m_linesPerPage directly as it might not be computed yet
3396 const int pageSize
= GetCountPerPage();
3397 wxCHECK_RET( pageSize
, _T("should have non zero page size") );
3399 if (GetLayoutDirection() == wxLayout_RightToLeft
)
3401 if (event
.GetKeyCode() == WXK_RIGHT
)
3402 event
.m_keyCode
= WXK_LEFT
;
3403 else if (event
.GetKeyCode() == WXK_LEFT
)
3404 event
.m_keyCode
= WXK_RIGHT
;
3407 switch ( event
.GetKeyCode() )
3410 if ( m_current
> 0 )
3411 OnArrowChar( m_current
- 1, event
);
3415 if ( m_current
< (size_t)GetItemCount() - 1 )
3416 OnArrowChar( m_current
+ 1, event
);
3421 OnArrowChar( GetItemCount() - 1, event
);
3426 OnArrowChar( 0, event
);
3431 int steps
= InReportView() ? pageSize
- 1
3432 : m_current
% pageSize
;
3434 int index
= m_current
- steps
;
3438 OnArrowChar( index
, event
);
3444 int steps
= InReportView()
3446 : pageSize
- (m_current
% pageSize
) - 1;
3448 size_t index
= m_current
+ steps
;
3449 size_t count
= GetItemCount();
3450 if ( index
>= count
)
3453 OnArrowChar( index
, event
);
3458 if ( !InReportView() )
3460 int index
= m_current
- pageSize
;
3464 OnArrowChar( index
, event
);
3469 if ( !InReportView() )
3471 size_t index
= m_current
+ pageSize
;
3473 size_t count
= GetItemCount();
3474 if ( index
>= count
)
3477 OnArrowChar( index
, event
);
3482 if ( IsSingleSel() )
3484 SendNotify( m_current
, wxEVT_COMMAND_LIST_ITEM_ACTIVATED
);
3486 if ( IsHighlighted(m_current
) )
3488 // don't unselect the item in single selection mode
3491 //else: select it in ReverseHighlight() below if unselected
3494 ReverseHighlight(m_current
);
3499 SendNotify( m_current
, wxEVT_COMMAND_LIST_ITEM_ACTIVATED
);
3507 // ----------------------------------------------------------------------------
3509 // ----------------------------------------------------------------------------
3511 void wxListMainWindow::OnSetFocus( wxFocusEvent
&WXUNUSED(event
) )
3515 wxFocusEvent
event( wxEVT_SET_FOCUS
, GetParent()->GetId() );
3516 event
.SetEventObject( GetParent() );
3517 if ( GetParent()->GetEventHandler()->ProcessEvent( event
) )
3521 // wxGTK sends us EVT_SET_FOCUS events even if we had never got
3522 // EVT_KILL_FOCUS before which means that we finish by redrawing the items
3523 // which are already drawn correctly resulting in horrible flicker - avoid
3533 void wxListMainWindow::OnKillFocus( wxFocusEvent
&WXUNUSED(event
) )
3537 wxFocusEvent
event( wxEVT_KILL_FOCUS
, GetParent()->GetId() );
3538 event
.SetEventObject( GetParent() );
3539 if ( GetParent()->GetEventHandler()->ProcessEvent( event
) )
3547 void wxListMainWindow::DrawImage( int index
, wxDC
*dc
, int x
, int y
)
3549 if ( HasFlag(wxLC_ICON
) && (m_normal_image_list
))
3551 m_normal_image_list
->Draw( index
, *dc
, x
, y
, wxIMAGELIST_DRAW_TRANSPARENT
);
3553 else if ( HasFlag(wxLC_SMALL_ICON
) && (m_small_image_list
))
3555 m_small_image_list
->Draw( index
, *dc
, x
, y
, wxIMAGELIST_DRAW_TRANSPARENT
);
3557 else if ( HasFlag(wxLC_LIST
) && (m_small_image_list
))
3559 m_small_image_list
->Draw( index
, *dc
, x
, y
, wxIMAGELIST_DRAW_TRANSPARENT
);
3561 else if ( InReportView() && (m_small_image_list
))
3563 m_small_image_list
->Draw( index
, *dc
, x
, y
, wxIMAGELIST_DRAW_TRANSPARENT
);
3567 void wxListMainWindow::GetImageSize( int index
, int &width
, int &height
) const
3569 if ( HasFlag(wxLC_ICON
) && m_normal_image_list
)
3571 m_normal_image_list
->GetSize( index
, width
, height
);
3573 else if ( HasFlag(wxLC_SMALL_ICON
) && m_small_image_list
)
3575 m_small_image_list
->GetSize( index
, width
, height
);
3577 else if ( HasFlag(wxLC_LIST
) && m_small_image_list
)
3579 m_small_image_list
->GetSize( index
, width
, height
);
3581 else if ( InReportView() && m_small_image_list
)
3583 m_small_image_list
->GetSize( index
, width
, height
);
3592 int wxListMainWindow::GetTextLength( const wxString
&s
) const
3594 wxClientDC
dc( wxConstCast(this, wxListMainWindow
) );
3595 dc
.SetFont( GetFont() );
3598 dc
.GetTextExtent( s
, &lw
, NULL
);
3600 return lw
+ AUTOSIZE_COL_MARGIN
;
3603 void wxListMainWindow::SetImageList( wxImageList
*imageList
, int which
)
3607 // calc the spacing from the icon size
3608 int width
= 0, height
= 0;
3610 if ((imageList
) && (imageList
->GetImageCount()) )
3611 imageList
->GetSize(0, width
, height
);
3613 if (which
== wxIMAGE_LIST_NORMAL
)
3615 m_normal_image_list
= imageList
;
3616 m_normal_spacing
= width
+ 8;
3619 if (which
== wxIMAGE_LIST_SMALL
)
3621 m_small_image_list
= imageList
;
3622 m_small_spacing
= width
+ 14;
3623 m_lineHeight
= 0; // ensure that the line height will be recalc'd
3627 void wxListMainWindow::SetItemSpacing( int spacing
, bool isSmall
)
3631 m_small_spacing
= spacing
;
3633 m_normal_spacing
= spacing
;
3636 int wxListMainWindow::GetItemSpacing( bool isSmall
)
3638 return isSmall
? m_small_spacing
: m_normal_spacing
;
3641 // ----------------------------------------------------------------------------
3643 // ----------------------------------------------------------------------------
3645 void wxListMainWindow::SetColumn( int col
, wxListItem
&item
)
3647 wxListHeaderDataList::compatibility_iterator node
= m_columns
.Item( col
);
3649 wxCHECK_RET( node
, _T("invalid column index in SetColumn") );
3651 if ( item
.m_width
== wxLIST_AUTOSIZE_USEHEADER
)
3652 item
.m_width
= GetTextLength( item
.m_text
);
3654 wxListHeaderData
*column
= node
->GetData();
3655 column
->SetItem( item
);
3657 wxListHeaderWindow
*headerWin
= GetListCtrl()->m_headerWin
;
3659 headerWin
->m_dirty
= true;
3663 // invalidate it as it has to be recalculated
3667 void wxListMainWindow::SetColumnWidth( int col
, int width
)
3669 wxCHECK_RET( col
>= 0 && col
< GetColumnCount(),
3670 _T("invalid column index") );
3672 wxCHECK_RET( InReportView(),
3673 _T("SetColumnWidth() can only be called in report mode.") );
3676 wxListHeaderWindow
*headerWin
= GetListCtrl()->m_headerWin
;
3678 headerWin
->m_dirty
= true;
3680 wxListHeaderDataList::compatibility_iterator node
= m_columns
.Item( col
);
3681 wxCHECK_RET( node
, _T("no column?") );
3683 wxListHeaderData
*column
= node
->GetData();
3685 size_t count
= GetItemCount();
3687 if (width
== wxLIST_AUTOSIZE_USEHEADER
)
3689 width
= GetTextLength(column
->GetText());
3691 else if ( width
== wxLIST_AUTOSIZE
)
3695 // TODO: determine the max width somehow...
3696 width
= WIDTH_COL_DEFAULT
;
3700 wxClientDC
dc(this);
3701 dc
.SetFont( GetFont() );
3703 int max
= AUTOSIZE_COL_MARGIN
;
3705 // if the cached column width isn't valid then recalculate it
3706 if (m_aColWidths
.Item(col
)->bNeedsUpdate
)
3708 for (size_t i
= 0; i
< count
; i
++)
3710 wxListLineData
*line
= GetLine( i
);
3711 wxListItemDataList::compatibility_iterator n
= line
->m_items
.Item( col
);
3713 wxCHECK_RET( n
, _T("no subitem?") );
3715 wxListItemData
*itemData
= n
->GetData();
3718 itemData
->GetItem(item
);
3719 int itemWidth
= GetItemWidthWithImage(&item
);
3720 if (itemWidth
> max
)
3724 m_aColWidths
.Item(col
)->bNeedsUpdate
= false;
3725 m_aColWidths
.Item(col
)->nMaxWidth
= max
;
3728 max
= m_aColWidths
.Item(col
)->nMaxWidth
;
3729 width
= max
+ AUTOSIZE_COL_MARGIN
;
3733 column
->SetWidth( width
);
3735 // invalidate it as it has to be recalculated
3739 int wxListMainWindow::GetHeaderWidth() const
3741 if ( !m_headerWidth
)
3743 wxListMainWindow
*self
= wxConstCast(this, wxListMainWindow
);
3745 size_t count
= GetColumnCount();
3746 for ( size_t col
= 0; col
< count
; col
++ )
3748 self
->m_headerWidth
+= GetColumnWidth(col
);
3752 return m_headerWidth
;
3755 void wxListMainWindow::GetColumn( int col
, wxListItem
&item
) const
3757 wxListHeaderDataList::compatibility_iterator node
= m_columns
.Item( col
);
3758 wxCHECK_RET( node
, _T("invalid column index in GetColumn") );
3760 wxListHeaderData
*column
= node
->GetData();
3761 column
->GetItem( item
);
3764 int wxListMainWindow::GetColumnWidth( int col
) const
3766 wxListHeaderDataList::compatibility_iterator node
= m_columns
.Item( col
);
3767 wxCHECK_MSG( node
, 0, _T("invalid column index") );
3769 wxListHeaderData
*column
= node
->GetData();
3770 return column
->GetWidth();
3773 // ----------------------------------------------------------------------------
3775 // ----------------------------------------------------------------------------
3777 void wxListMainWindow::SetItem( wxListItem
&item
)
3779 long id
= item
.m_itemId
;
3780 wxCHECK_RET( id
>= 0 && (size_t)id
< GetItemCount(),
3781 _T("invalid item index in SetItem") );
3785 wxListLineData
*line
= GetLine((size_t)id
);
3786 line
->SetItem( item
.m_col
, item
);
3788 // Set item state if user wants
3789 if ( item
.m_mask
& wxLIST_MASK_STATE
)
3790 SetItemState( item
.m_itemId
, item
.m_state
, item
.m_state
);
3794 // update the Max Width Cache if needed
3795 int width
= GetItemWidthWithImage(&item
);
3797 if (width
> m_aColWidths
.Item(item
.m_col
)->nMaxWidth
)
3798 m_aColWidths
.Item(item
.m_col
)->nMaxWidth
= width
;
3802 // update the item on screen
3804 GetItemRect(id
, rectItem
);
3805 RefreshRect(rectItem
);
3808 void wxListMainWindow::SetItemStateAll(long state
, long stateMask
)
3813 // first deal with selection
3814 if ( stateMask
& wxLIST_STATE_SELECTED
)
3816 // set/clear select state
3819 // optimized version for virtual listctrl.
3820 m_selStore
.SelectRange(0, GetItemCount() - 1, state
== wxLIST_STATE_SELECTED
);
3823 else if ( state
& wxLIST_STATE_SELECTED
)
3825 const long count
= GetItemCount();
3826 for( long i
= 0; i
< count
; i
++ )
3828 SetItemState( i
, wxLIST_STATE_SELECTED
, wxLIST_STATE_SELECTED
);
3834 // clear for non virtual (somewhat optimized by using GetNextItem())
3836 while ( (i
= GetNextItem(i
, wxLIST_NEXT_ALL
, wxLIST_STATE_SELECTED
)) != -1 )
3838 SetItemState( i
, 0, wxLIST_STATE_SELECTED
);
3843 if ( HasCurrent() && (state
== 0) && (stateMask
& wxLIST_STATE_FOCUSED
) )
3845 // unfocus all: only one item can be focussed, so clearing focus for
3846 // all items is simply clearing focus of the focussed item.
3847 SetItemState(m_current
, state
, stateMask
);
3849 //(setting focus to all items makes no sense, so it is not handled here.)
3852 void wxListMainWindow::SetItemState( long litem
, long state
, long stateMask
)
3856 SetItemStateAll(state
, stateMask
);
3860 wxCHECK_RET( litem
>= 0 && (size_t)litem
< GetItemCount(),
3861 _T("invalid list ctrl item index in SetItem") );
3863 size_t oldCurrent
= m_current
;
3864 size_t item
= (size_t)litem
; // safe because of the check above
3866 // do we need to change the focus?
3867 if ( stateMask
& wxLIST_STATE_FOCUSED
)
3869 if ( state
& wxLIST_STATE_FOCUSED
)
3871 // don't do anything if this item is already focused
3872 if ( item
!= m_current
)
3874 ChangeCurrent(item
);
3876 if ( oldCurrent
!= (size_t)-1 )
3878 if ( IsSingleSel() )
3880 HighlightLine(oldCurrent
, false);
3883 RefreshLine(oldCurrent
);
3886 RefreshLine( m_current
);
3891 // don't do anything if this item is not focused
3892 if ( item
== m_current
)
3896 if ( IsSingleSel() )
3898 // we must unselect the old current item as well or we
3899 // might end up with more than one selected item in a
3900 // single selection control
3901 HighlightLine(oldCurrent
, false);
3904 RefreshLine( oldCurrent
);
3909 // do we need to change the selection state?
3910 if ( stateMask
& wxLIST_STATE_SELECTED
)
3912 bool on
= (state
& wxLIST_STATE_SELECTED
) != 0;
3914 if ( IsSingleSel() )
3918 // selecting the item also makes it the focused one in the
3920 if ( m_current
!= item
)
3922 ChangeCurrent(item
);
3924 if ( oldCurrent
!= (size_t)-1 )
3926 HighlightLine( oldCurrent
, false );
3927 RefreshLine( oldCurrent
);
3933 // only the current item may be selected anyhow
3934 if ( item
!= m_current
)
3939 if ( HighlightLine(item
, on
) )
3946 int wxListMainWindow::GetItemState( long item
, long stateMask
) const
3948 wxCHECK_MSG( item
>= 0 && (size_t)item
< GetItemCount(), 0,
3949 _T("invalid list ctrl item index in GetItemState()") );
3951 int ret
= wxLIST_STATE_DONTCARE
;
3953 if ( stateMask
& wxLIST_STATE_FOCUSED
)
3955 if ( (size_t)item
== m_current
)
3956 ret
|= wxLIST_STATE_FOCUSED
;
3959 if ( stateMask
& wxLIST_STATE_SELECTED
)
3961 if ( IsHighlighted(item
) )
3962 ret
|= wxLIST_STATE_SELECTED
;
3968 void wxListMainWindow::GetItem( wxListItem
&item
) const
3970 wxCHECK_RET( item
.m_itemId
>= 0 && (size_t)item
.m_itemId
< GetItemCount(),
3971 _T("invalid item index in GetItem") );
3973 wxListLineData
*line
= GetLine((size_t)item
.m_itemId
);
3974 line
->GetItem( item
.m_col
, item
);
3976 // Get item state if user wants it
3977 if ( item
.m_mask
& wxLIST_MASK_STATE
)
3978 item
.m_state
= GetItemState( item
.m_itemId
, wxLIST_STATE_SELECTED
|
3979 wxLIST_STATE_FOCUSED
);
3982 // ----------------------------------------------------------------------------
3984 // ----------------------------------------------------------------------------
3986 size_t wxListMainWindow::GetItemCount() const
3988 return IsVirtual() ? m_countVirt
: m_lines
.GetCount();
3991 void wxListMainWindow::SetItemCount(long count
)
3993 m_selStore
.SetItemCount(count
);
3994 m_countVirt
= count
;
3996 ResetVisibleLinesRange();
3998 // scrollbars must be reset
4002 int wxListMainWindow::GetSelectedItemCount() const
4004 // deal with the quick case first
4005 if ( IsSingleSel() )
4006 return HasCurrent() ? IsHighlighted(m_current
) : false;
4008 // virtual controls remmebers all its selections itself
4010 return m_selStore
.GetSelectedCount();
4012 // TODO: we probably should maintain the number of items selected even for
4013 // non virtual controls as enumerating all lines is really slow...
4014 size_t countSel
= 0;
4015 size_t count
= GetItemCount();
4016 for ( size_t line
= 0; line
< count
; line
++ )
4018 if ( GetLine(line
)->IsHighlighted() )
4025 // ----------------------------------------------------------------------------
4026 // item position/size
4027 // ----------------------------------------------------------------------------
4029 wxRect
wxListMainWindow::GetViewRect() const
4031 wxASSERT_MSG( !HasFlag(wxLC_REPORT
| wxLC_LIST
),
4032 _T("wxListCtrl::GetViewRect() only works in icon mode") );
4034 // we need to find the longest/tallest label
4035 wxCoord xMax
= 0, yMax
= 0;
4036 const int count
= GetItemCount();
4039 for ( int i
= 0; i
< count
; i
++ )
4044 wxCoord x
= r
.GetRight(),
4054 // some fudge needed to make it look prettier
4055 xMax
+= 2 * EXTRA_BORDER_X
;
4056 yMax
+= 2 * EXTRA_BORDER_Y
;
4058 // account for the scrollbars if necessary
4059 const wxSize sizeAll
= GetClientSize();
4060 if ( xMax
> sizeAll
.x
)
4061 yMax
+= wxSystemSettings::GetMetric(wxSYS_HSCROLL_Y
);
4062 if ( yMax
> sizeAll
.y
)
4063 xMax
+= wxSystemSettings::GetMetric(wxSYS_VSCROLL_X
);
4065 return wxRect(0, 0, xMax
, yMax
);
4068 void wxListMainWindow::GetItemRect( long index
, wxRect
&rect
) const
4070 wxCHECK_RET( index
>= 0 && (size_t)index
< GetItemCount(),
4071 _T("invalid index in GetItemRect") );
4073 // ensure that we're laid out, otherwise we could return nonsense
4076 wxConstCast(this, wxListMainWindow
)->
4077 RecalculatePositions(true /* no refresh */);
4080 rect
= GetLineRect((size_t)index
);
4082 CalcScrolledPosition(rect
.x
, rect
.y
, &rect
.x
, &rect
.y
);
4085 bool wxListMainWindow::GetItemPosition(long item
, wxPoint
& pos
) const
4088 GetItemRect(item
, rect
);
4096 // ----------------------------------------------------------------------------
4097 // geometry calculation
4098 // ----------------------------------------------------------------------------
4100 void wxListMainWindow::RecalculatePositions(bool noRefresh
)
4102 const int lineHeight
= GetLineHeight();
4104 wxClientDC
dc( this );
4105 dc
.SetFont( GetFont() );
4107 const size_t count
= GetItemCount();
4110 if ( HasFlag(wxLC_ICON
) )
4111 iconSpacing
= m_normal_spacing
;
4112 else if ( HasFlag(wxLC_SMALL_ICON
) )
4113 iconSpacing
= m_small_spacing
;
4117 // Note that we do not call GetClientSize() here but
4118 // GetSize() and subtract the border size for sunken
4119 // borders manually. This is technically incorrect,
4120 // but we need to know the client area's size WITHOUT
4121 // scrollbars here. Since we don't know if there are
4122 // any scrollbars, we use GetSize() instead. Another
4123 // solution would be to call SetScrollbars() here to
4124 // remove the scrollbars and call GetClientSize() then,
4125 // but this might result in flicker and - worse - will
4126 // reset the scrollbars to 0 which is not good at all
4127 // if you resize a dialog/window, but don't want to
4128 // reset the window scrolling. RR.
4129 // Furthermore, we actually do NOT subtract the border
4130 // width as 2 pixels is just the extra space which we
4131 // need around the actual content in the window. Other-
4132 // wise the text would e.g. touch the upper border. RR.
4135 GetSize( &clientWidth
, &clientHeight
);
4137 if ( InReportView() )
4139 // all lines have the same height and we scroll one line per step
4140 int entireHeight
= count
* lineHeight
+ LINE_SPACING
;
4142 m_linesPerPage
= clientHeight
/ lineHeight
;
4144 ResetVisibleLinesRange();
4146 SetScrollbars( SCROLL_UNIT_X
, lineHeight
,
4147 GetHeaderWidth() / SCROLL_UNIT_X
,
4148 (entireHeight
+ lineHeight
- 1) / lineHeight
,
4149 GetScrollPos(wxHORIZONTAL
),
4150 GetScrollPos(wxVERTICAL
),
4155 // we have 3 different layout strategies: either layout all items
4156 // horizontally/vertically (wxLC_ALIGN_XXX styles explicitly given) or
4157 // to arrange them in top to bottom, left to right (don't ask me why
4158 // not the other way round...) order
4159 if ( HasFlag(wxLC_ALIGN_LEFT
| wxLC_ALIGN_TOP
) )
4161 int x
= EXTRA_BORDER_X
;
4162 int y
= EXTRA_BORDER_Y
;
4164 wxCoord widthMax
= 0;
4167 for ( i
= 0; i
< count
; i
++ )
4169 wxListLineData
*line
= GetLine(i
);
4170 line
->CalculateSize( &dc
, iconSpacing
);
4171 line
->SetPosition( x
, y
, iconSpacing
);
4173 wxSize sizeLine
= GetLineSize(i
);
4175 if ( HasFlag(wxLC_ALIGN_TOP
) )
4177 if ( sizeLine
.x
> widthMax
)
4178 widthMax
= sizeLine
.x
;
4182 else // wxLC_ALIGN_LEFT
4184 x
+= sizeLine
.x
+ MARGIN_BETWEEN_ROWS
;
4188 if ( HasFlag(wxLC_ALIGN_TOP
) )
4190 // traverse the items again and tweak their sizes so that they are
4191 // all the same in a row
4192 for ( i
= 0; i
< count
; i
++ )
4194 wxListLineData
*line
= GetLine(i
);
4195 line
->m_gi
->ExtendWidth(widthMax
);
4203 (x
+ SCROLL_UNIT_X
) / SCROLL_UNIT_X
,
4204 (y
+ lineHeight
) / lineHeight
,
4205 GetScrollPos( wxHORIZONTAL
),
4206 GetScrollPos( wxVERTICAL
),
4210 else // "flowed" arrangement, the most complicated case
4212 // at first we try without any scrollbars, if the items don't fit into
4213 // the window, we recalculate after subtracting the space taken by the
4216 int entireWidth
= 0;
4218 for (int tries
= 0; tries
< 2; tries
++)
4220 entireWidth
= 2 * EXTRA_BORDER_X
;
4224 // Now we have decided that the items do not fit into the
4225 // client area, so we need a scrollbar
4226 entireWidth
+= SCROLL_UNIT_X
;
4229 int x
= EXTRA_BORDER_X
;
4230 int y
= EXTRA_BORDER_Y
;
4231 int maxWidthInThisRow
= 0;
4234 int currentlyVisibleLines
= 0;
4236 for (size_t i
= 0; i
< count
; i
++)
4238 currentlyVisibleLines
++;
4239 wxListLineData
*line
= GetLine( i
);
4240 line
->CalculateSize( &dc
, iconSpacing
);
4241 line
->SetPosition( x
, y
, iconSpacing
);
4243 wxSize sizeLine
= GetLineSize( i
);
4245 if ( maxWidthInThisRow
< sizeLine
.x
)
4246 maxWidthInThisRow
= sizeLine
.x
;
4249 if (currentlyVisibleLines
> m_linesPerPage
)
4250 m_linesPerPage
= currentlyVisibleLines
;
4252 if ( y
+ sizeLine
.y
>= clientHeight
)
4254 currentlyVisibleLines
= 0;
4256 maxWidthInThisRow
+= MARGIN_BETWEEN_ROWS
;
4257 x
+= maxWidthInThisRow
;
4258 entireWidth
+= maxWidthInThisRow
;
4259 maxWidthInThisRow
= 0;
4262 // We have reached the last item.
4263 if ( i
== count
- 1 )
4264 entireWidth
+= maxWidthInThisRow
;
4266 if ( (tries
== 0) &&
4267 (entireWidth
+ SCROLL_UNIT_X
> clientWidth
) )
4269 clientHeight
-= wxSystemSettings::
4270 GetMetric(wxSYS_HSCROLL_Y
);
4275 if ( i
== count
- 1 )
4276 tries
= 1; // Everything fits, no second try required.
4284 (entireWidth
+ SCROLL_UNIT_X
) / SCROLL_UNIT_X
,
4286 GetScrollPos( wxHORIZONTAL
),
4295 // FIXME: why should we call it from here?
4302 void wxListMainWindow::RefreshAll()
4307 wxListHeaderWindow
*headerWin
= GetListCtrl()->m_headerWin
;
4308 if ( headerWin
&& headerWin
->m_dirty
)
4310 headerWin
->m_dirty
= false;
4311 headerWin
->Refresh();
4315 void wxListMainWindow::UpdateCurrent()
4317 if ( !HasCurrent() && !IsEmpty() )
4321 long wxListMainWindow::GetNextItem( long item
,
4322 int WXUNUSED(geometry
),
4326 max
= GetItemCount();
4327 wxCHECK_MSG( (ret
== -1) || (ret
< max
), -1,
4328 _T("invalid listctrl index in GetNextItem()") );
4330 // notice that we start with the next item (or the first one if item == -1)
4331 // and this is intentional to allow writing a simple loop to iterate over
4332 // all selected items
4335 // this is not an error because the index was OK initially,
4336 // just no such item
4343 size_t count
= GetItemCount();
4344 for ( size_t line
= (size_t)ret
; line
< count
; line
++ )
4346 if ( (state
& wxLIST_STATE_FOCUSED
) && (line
== m_current
) )
4349 if ( (state
& wxLIST_STATE_SELECTED
) && IsHighlighted(line
) )
4356 // ----------------------------------------------------------------------------
4358 // ----------------------------------------------------------------------------
4360 void wxListMainWindow::DeleteItem( long lindex
)
4362 size_t count
= GetItemCount();
4364 wxCHECK_RET( (lindex
>= 0) && ((size_t)lindex
< count
),
4365 _T("invalid item index in DeleteItem") );
4367 size_t index
= (size_t)lindex
;
4369 // we don't need to adjust the index for the previous items
4370 if ( HasCurrent() && m_current
>= index
)
4372 // if the current item is being deleted, we want the next one to
4373 // become selected - unless there is no next one - so don't adjust
4374 // m_current in this case
4375 if ( m_current
!= index
|| m_current
== count
- 1 )
4379 if ( InReportView() )
4381 // mark the Column Max Width cache as dirty if the items in the line
4382 // we're deleting contain the Max Column Width
4383 wxListLineData
* const line
= GetLine(index
);
4384 wxListItemDataList::compatibility_iterator n
;
4385 wxListItemData
*itemData
;
4389 for (size_t i
= 0; i
< m_columns
.GetCount(); i
++)
4391 n
= line
->m_items
.Item( i
);
4392 itemData
= n
->GetData();
4393 itemData
->GetItem(item
);
4395 itemWidth
= GetItemWidthWithImage(&item
);
4397 if (itemWidth
>= m_aColWidths
.Item(i
)->nMaxWidth
)
4398 m_aColWidths
.Item(i
)->bNeedsUpdate
= true;
4401 ResetVisibleLinesRange();
4404 SendNotify( index
, wxEVT_COMMAND_LIST_DELETE_ITEM
, wxDefaultPosition
);
4409 m_selStore
.OnItemDelete(index
);
4413 m_lines
.RemoveAt( index
);
4416 // we need to refresh the (vert) scrollbar as the number of items changed
4419 RefreshAfter(index
);
4422 void wxListMainWindow::DeleteColumn( int col
)
4424 wxListHeaderDataList::compatibility_iterator node
= m_columns
.Item( col
);
4426 wxCHECK_RET( node
, wxT("invalid column index in DeleteColumn()") );
4429 delete node
->GetData();
4430 m_columns
.Erase( node
);
4434 // update all the items
4435 for ( size_t i
= 0; i
< m_lines
.GetCount(); i
++ )
4437 wxListLineData
* const line
= GetLine(i
);
4438 wxListItemDataList::compatibility_iterator n
= line
->m_items
.Item( col
);
4439 delete n
->GetData();
4440 line
->m_items
.Erase(n
);
4444 if ( InReportView() ) // we only cache max widths when in Report View
4446 delete m_aColWidths
.Item(col
);
4447 m_aColWidths
.RemoveAt(col
);
4450 // invalidate it as it has to be recalculated
4454 void wxListMainWindow::DoDeleteAllItems()
4457 // nothing to do - in particular, don't send the event
4462 // to make the deletion of all items faster, we don't send the
4463 // notifications for each item deletion in this case but only one event
4464 // for all of them: this is compatible with wxMSW and documented in
4465 // DeleteAllItems() description
4467 wxListEvent
event( wxEVT_COMMAND_LIST_DELETE_ALL_ITEMS
, GetParent()->GetId() );
4468 event
.SetEventObject( GetParent() );
4469 GetParent()->GetEventHandler()->ProcessEvent( event
);
4477 if ( InReportView() )
4479 ResetVisibleLinesRange();
4480 for (size_t i
= 0; i
< m_aColWidths
.GetCount(); i
++)
4482 m_aColWidths
.Item(i
)->bNeedsUpdate
= true;
4489 void wxListMainWindow::DeleteAllItems()
4493 RecalculatePositions();
4496 void wxListMainWindow::DeleteEverything()
4498 WX_CLEAR_LIST(wxListHeaderDataList
, m_columns
);
4499 WX_CLEAR_ARRAY(m_aColWidths
);
4504 // ----------------------------------------------------------------------------
4505 // scanning for an item
4506 // ----------------------------------------------------------------------------
4508 void wxListMainWindow::EnsureVisible( long index
)
4510 wxCHECK_RET( index
>= 0 && (size_t)index
< GetItemCount(),
4511 _T("invalid index in EnsureVisible") );
4513 // We have to call this here because the label in question might just have
4514 // been added and its position is not known yet
4516 RecalculatePositions(true /* no refresh */);
4518 MoveToItem((size_t)index
);
4521 long wxListMainWindow::FindItem(long start
, const wxString
& str
, bool partial
)
4527 wxString str_upper
= str
.Upper();
4531 size_t count
= GetItemCount();
4532 for ( size_t i
= (size_t)pos
; i
< count
; i
++ )
4534 wxListLineData
*line
= GetLine(i
);
4535 wxString line_upper
= line
->GetText(0).Upper();
4538 if (line_upper
== str_upper
)
4543 if (line_upper
.find(str_upper
) == 0)
4551 long wxListMainWindow::FindItem(long start
, wxUIntPtr data
)
4557 size_t count
= GetItemCount();
4558 for (size_t i
= (size_t)pos
; i
< count
; i
++)
4560 wxListLineData
*line
= GetLine(i
);
4562 line
->GetItem( 0, item
);
4563 if (item
.m_data
== data
)
4570 long wxListMainWindow::FindItem( const wxPoint
& pt
)
4573 GetVisibleLinesRange( &topItem
, NULL
);
4576 GetItemPosition( GetItemCount() - 1, p
);
4580 long id
= (long)floor( pt
.y
* double(GetItemCount() - topItem
- 1) / p
.y
+ topItem
);
4581 if ( id
>= 0 && id
< (long)GetItemCount() )
4587 long wxListMainWindow::HitTest( int x
, int y
, int &flags
) const
4589 CalcUnscrolledPosition( x
, y
, &x
, &y
);
4591 size_t count
= GetItemCount();
4593 if ( InReportView() )
4595 size_t current
= y
/ GetLineHeight();
4596 if ( current
< count
)
4598 flags
= HitTestLine(current
, x
, y
);
4605 // TODO: optimize it too! this is less simple than for report view but
4606 // enumerating all items is still not a way to do it!!
4607 for ( size_t current
= 0; current
< count
; current
++ )
4609 flags
= HitTestLine(current
, x
, y
);
4618 // ----------------------------------------------------------------------------
4620 // ----------------------------------------------------------------------------
4622 void wxListMainWindow::InsertItem( wxListItem
&item
)
4624 wxASSERT_MSG( !IsVirtual(), _T("can't be used with virtual control") );
4626 int count
= GetItemCount();
4627 wxCHECK_RET( item
.m_itemId
>= 0, _T("invalid item index") );
4629 if (item
.m_itemId
> count
)
4630 item
.m_itemId
= count
;
4632 size_t id
= item
.m_itemId
;
4636 if ( InReportView() )
4638 ResetVisibleLinesRange();
4640 // calculate the width of the item and adjust the max column width
4641 wxColWidthInfo
*pWidthInfo
= m_aColWidths
.Item(item
.GetColumn());
4642 int width
= GetItemWidthWithImage(&item
);
4643 item
.SetWidth(width
);
4644 if (width
> pWidthInfo
->nMaxWidth
)
4645 pWidthInfo
->nMaxWidth
= width
;
4648 wxListLineData
*line
= new wxListLineData(this);
4650 line
->SetItem( item
.m_col
, item
);
4652 m_lines
.Insert( line
, id
);
4656 // If an item is selected at or below the point of insertion, we need to
4657 // increment the member variables because the current row's index has gone
4659 if ( HasCurrent() && m_current
>= id
)
4662 SendNotify(id
, wxEVT_COMMAND_LIST_INSERT_ITEM
);
4664 RefreshLines(id
, GetItemCount() - 1);
4667 void wxListMainWindow::InsertColumn( long col
, wxListItem
&item
)
4670 if ( InReportView() )
4672 if (item
.m_width
== wxLIST_AUTOSIZE_USEHEADER
)
4673 item
.m_width
= GetTextLength( item
.m_text
);
4675 wxListHeaderData
*column
= new wxListHeaderData( item
);
4676 wxColWidthInfo
*colWidthInfo
= new wxColWidthInfo();
4678 bool insert
= (col
>= 0) && ((size_t)col
< m_columns
.GetCount());
4681 wxListHeaderDataList::compatibility_iterator
4682 node
= m_columns
.Item( col
);
4683 m_columns
.Insert( node
, column
);
4684 m_aColWidths
.Insert( colWidthInfo
, col
);
4688 m_columns
.Append( column
);
4689 m_aColWidths
.Add( colWidthInfo
);
4694 // update all the items
4695 for ( size_t i
= 0; i
< m_lines
.GetCount(); i
++ )
4697 wxListLineData
* const line
= GetLine(i
);
4698 wxListItemData
* const data
= new wxListItemData(this);
4700 line
->m_items
.Insert(col
, data
);
4702 line
->m_items
.Append(data
);
4706 // invalidate it as it has to be recalculated
4711 int wxListMainWindow::GetItemWidthWithImage(wxListItem
* item
)
4714 wxClientDC
dc(this);
4716 dc
.SetFont( GetFont() );
4718 if (item
->GetImage() != -1)
4721 GetImageSize( item
->GetImage(), ix
, iy
);
4725 if (!item
->GetText().empty())
4728 dc
.GetTextExtent( item
->GetText(), &w
, NULL
);
4735 // ----------------------------------------------------------------------------
4737 // ----------------------------------------------------------------------------
4739 wxListCtrlCompare list_ctrl_compare_func_2
;
4740 long list_ctrl_compare_data
;
4742 int LINKAGEMODE
list_ctrl_compare_func_1( wxListLineData
**arg1
, wxListLineData
**arg2
)
4744 wxListLineData
*line1
= *arg1
;
4745 wxListLineData
*line2
= *arg2
;
4747 line1
->GetItem( 0, item
);
4748 wxUIntPtr data1
= item
.m_data
;
4749 line2
->GetItem( 0, item
);
4750 wxUIntPtr data2
= item
.m_data
;
4751 return list_ctrl_compare_func_2( data1
, data2
, list_ctrl_compare_data
);
4754 void wxListMainWindow::SortItems( wxListCtrlCompare fn
, long data
)
4756 list_ctrl_compare_func_2
= fn
;
4757 list_ctrl_compare_data
= data
;
4758 m_lines
.Sort( list_ctrl_compare_func_1
);
4762 // ----------------------------------------------------------------------------
4764 // ----------------------------------------------------------------------------
4766 void wxListMainWindow::OnScroll(wxScrollWinEvent
& event
)
4768 // update our idea of which lines are shown when we redraw the window the
4770 ResetVisibleLinesRange();
4773 #if ( defined(__WXGTK__) || defined(__WXMAC__) ) && !defined(__WXUNIVERSAL__)
4774 wxScrolledWindow::OnScroll(event
);
4776 HandleOnScroll( event
);
4779 if ( event
.GetOrientation() == wxHORIZONTAL
&& HasHeader() )
4781 wxGenericListCtrl
* lc
= GetListCtrl();
4782 wxCHECK_RET( lc
, _T("no listctrl window?") );
4784 lc
->m_headerWin
->Refresh();
4785 lc
->m_headerWin
->Update();
4789 int wxListMainWindow::GetCountPerPage() const
4791 if ( !m_linesPerPage
)
4793 wxConstCast(this, wxListMainWindow
)->
4794 m_linesPerPage
= GetClientSize().y
/ GetLineHeight();
4797 return m_linesPerPage
;
4800 void wxListMainWindow::GetVisibleLinesRange(size_t *from
, size_t *to
)
4802 wxASSERT_MSG( InReportView(), _T("this is for report mode only") );
4804 if ( m_lineFrom
== (size_t)-1 )
4806 size_t count
= GetItemCount();
4809 m_lineFrom
= GetScrollPos(wxVERTICAL
);
4811 // this may happen if SetScrollbars() hadn't been called yet
4812 if ( m_lineFrom
>= count
)
4813 m_lineFrom
= count
- 1;
4815 // we redraw one extra line but this is needed to make the redrawing
4816 // logic work when there is a fractional number of lines on screen
4817 m_lineTo
= m_lineFrom
+ m_linesPerPage
;
4818 if ( m_lineTo
>= count
)
4819 m_lineTo
= count
- 1;
4821 else // empty control
4824 m_lineTo
= (size_t)-1;
4828 wxASSERT_MSG( IsEmpty() ||
4829 (m_lineFrom
<= m_lineTo
&& m_lineTo
< GetItemCount()),
4830 _T("GetVisibleLinesRange() returns incorrect result") );
4838 // -------------------------------------------------------------------------------------
4839 // wxGenericListCtrl
4840 // -------------------------------------------------------------------------------------
4842 IMPLEMENT_DYNAMIC_CLASS(wxGenericListCtrl
, wxControl
)
4844 BEGIN_EVENT_TABLE(wxGenericListCtrl
,wxControl
)
4845 EVT_SIZE(wxGenericListCtrl::OnSize
)
4848 wxGenericListCtrl::wxGenericListCtrl()
4850 m_imageListNormal
= (wxImageList
*) NULL
;
4851 m_imageListSmall
= (wxImageList
*) NULL
;
4852 m_imageListState
= (wxImageList
*) NULL
;
4854 m_ownsImageListNormal
=
4855 m_ownsImageListSmall
=
4856 m_ownsImageListState
= false;
4858 m_mainWin
= (wxListMainWindow
*) NULL
;
4859 m_headerWin
= (wxListHeaderWindow
*) NULL
;
4863 wxGenericListCtrl::~wxGenericListCtrl()
4865 if (m_ownsImageListNormal
)
4866 delete m_imageListNormal
;
4867 if (m_ownsImageListSmall
)
4868 delete m_imageListSmall
;
4869 if (m_ownsImageListState
)
4870 delete m_imageListState
;
4873 void wxGenericListCtrl::CalculateAndSetHeaderHeight()
4879 GetThemeMetric( kThemeMetricListHeaderHeight
, &h
);
4881 // we use 'g' to get the descent, too
4883 m_headerWin
->GetTextExtent(wxT("Hg"), &w
, &h
, &d
);
4884 h
+= d
+ 2 * HEADER_OFFSET_Y
+ EXTRA_HEIGHT
;
4887 // only update if changed
4888 if ( h
!= m_headerHeight
)
4893 ResizeReportView(true);
4894 else //why is this needed if it doesn't have a header?
4895 m_headerWin
->SetSize(m_headerWin
->GetSize().x
, m_headerHeight
);
4900 void wxGenericListCtrl::CreateHeaderWindow()
4902 m_headerWin
= new wxListHeaderWindow
4904 this, wxID_ANY
, m_mainWin
,
4906 wxSize(GetClientSize().x
, m_headerHeight
),
4909 CalculateAndSetHeaderHeight();
4912 bool wxGenericListCtrl::Create(wxWindow
*parent
,
4917 const wxValidator
&validator
,
4918 const wxString
&name
)
4922 m_imageListState
= (wxImageList
*) NULL
;
4923 m_ownsImageListNormal
=
4924 m_ownsImageListSmall
=
4925 m_ownsImageListState
= false;
4927 m_mainWin
= (wxListMainWindow
*) NULL
;
4928 m_headerWin
= (wxListHeaderWindow
*) NULL
;
4932 if ( !(style
& wxLC_MASK_TYPE
) )
4934 style
= style
| wxLC_LIST
;
4937 if ( !wxControl::Create( parent
, id
, pos
, size
, style
, validator
, name
) )
4940 // don't create the inner window with the border
4941 style
&= ~wxBORDER_MASK
;
4943 m_mainWin
= new wxListMainWindow( this, wxID_ANY
, wxPoint(0, 0), size
, style
);
4945 #ifdef __WXMAC_CARBON__
4946 // Human Interface Guidelines ask us for a special font in this case
4947 if ( GetWindowVariant() == wxWINDOW_VARIANT_NORMAL
)
4950 font
.MacCreateThemeFont( kThemeViewsFont
);
4955 if ( InReportView() )
4957 CreateHeaderWindow();
4959 #ifdef __WXMAC_CARBON__
4963 font
.MacCreateThemeFont( kThemeSmallSystemFont
);
4964 m_headerWin
->SetFont( font
);
4965 CalculateAndSetHeaderHeight();
4969 if ( HasFlag(wxLC_NO_HEADER
) )
4970 // VZ: why do we create it at all then?
4971 m_headerWin
->Show( false );
4974 SetInitialSize(size
);
4979 void wxGenericListCtrl::SetSingleStyle( long style
, bool add
)
4981 wxASSERT_MSG( !(style
& wxLC_VIRTUAL
),
4982 _T("wxLC_VIRTUAL can't be [un]set") );
4984 long flag
= GetWindowStyle();
4988 if (style
& wxLC_MASK_TYPE
)
4989 flag
&= ~(wxLC_MASK_TYPE
| wxLC_VIRTUAL
);
4990 if (style
& wxLC_MASK_ALIGN
)
4991 flag
&= ~wxLC_MASK_ALIGN
;
4992 if (style
& wxLC_MASK_SORT
)
4993 flag
&= ~wxLC_MASK_SORT
;
5001 SetWindowStyleFlag( flag
);
5004 void wxGenericListCtrl::SetWindowStyleFlag( long flag
)
5008 m_mainWin
->DeleteEverything();
5010 // has the header visibility changed?
5011 bool hasHeader
= HasHeader();
5012 bool willHaveHeader
= (flag
& wxLC_REPORT
) && !(flag
& wxLC_NO_HEADER
);
5014 if ( hasHeader
!= willHaveHeader
)
5021 // don't delete, just hide, as we can reuse it later
5022 m_headerWin
->Show(false);
5024 //else: nothing to do
5026 else // must show header
5030 CreateHeaderWindow();
5032 else // already have it, just show
5034 m_headerWin
->Show( true );
5038 ResizeReportView(willHaveHeader
);
5042 wxWindow::SetWindowStyleFlag( flag
);
5045 bool wxGenericListCtrl::GetColumn(int col
, wxListItem
&item
) const
5047 m_mainWin
->GetColumn( col
, item
);
5051 bool wxGenericListCtrl::SetColumn( int col
, wxListItem
& item
)
5053 m_mainWin
->SetColumn( col
, item
);
5057 int wxGenericListCtrl::GetColumnWidth( int col
) const
5059 return m_mainWin
->GetColumnWidth( col
);
5062 bool wxGenericListCtrl::SetColumnWidth( int col
, int width
)
5064 m_mainWin
->SetColumnWidth( col
, width
);
5068 int wxGenericListCtrl::GetCountPerPage() const
5070 return m_mainWin
->GetCountPerPage(); // different from Windows ?
5073 bool wxGenericListCtrl::GetItem( wxListItem
&info
) const
5075 m_mainWin
->GetItem( info
);
5079 bool wxGenericListCtrl::SetItem( wxListItem
&info
)
5081 m_mainWin
->SetItem( info
);
5085 long wxGenericListCtrl::SetItem( long index
, int col
, const wxString
& label
, int imageId
)
5088 info
.m_text
= label
;
5089 info
.m_mask
= wxLIST_MASK_TEXT
;
5090 info
.m_itemId
= index
;
5094 info
.m_image
= imageId
;
5095 info
.m_mask
|= wxLIST_MASK_IMAGE
;
5098 m_mainWin
->SetItem(info
);
5102 int wxGenericListCtrl::GetItemState( long item
, long stateMask
) const
5104 return m_mainWin
->GetItemState( item
, stateMask
);
5107 bool wxGenericListCtrl::SetItemState( long item
, long state
, long stateMask
)
5109 m_mainWin
->SetItemState( item
, state
, stateMask
);
5114 wxGenericListCtrl::SetItemImage( long item
, int image
, int WXUNUSED(selImage
) )
5116 return SetItemColumnImage(item
, 0, image
);
5120 wxGenericListCtrl::SetItemColumnImage( long item
, long column
, int image
)
5123 info
.m_image
= image
;
5124 info
.m_mask
= wxLIST_MASK_IMAGE
;
5125 info
.m_itemId
= item
;
5126 info
.m_col
= column
;
5127 m_mainWin
->SetItem( info
);
5131 wxString
wxGenericListCtrl::GetItemText( long item
) const
5133 return m_mainWin
->GetItemText(item
);
5136 void wxGenericListCtrl::SetItemText( long item
, const wxString
& str
)
5138 m_mainWin
->SetItemText(item
, str
);
5141 wxUIntPtr
wxGenericListCtrl::GetItemData( long item
) const
5144 info
.m_mask
= wxLIST_MASK_DATA
;
5145 info
.m_itemId
= item
;
5146 m_mainWin
->GetItem( info
);
5150 bool wxGenericListCtrl::SetItemData( long item
, long data
)
5153 info
.m_mask
= wxLIST_MASK_DATA
;
5154 info
.m_itemId
= item
;
5156 m_mainWin
->SetItem( info
);
5160 wxRect
wxGenericListCtrl::GetViewRect() const
5162 return m_mainWin
->GetViewRect();
5165 bool wxGenericListCtrl::GetItemRect( long item
, wxRect
&rect
, int WXUNUSED(code
) ) const
5167 m_mainWin
->GetItemRect( item
, rect
);
5168 if ( m_mainWin
->HasHeader() )
5169 rect
.y
+= m_headerHeight
+ 1;
5173 bool wxGenericListCtrl::GetItemPosition( long item
, wxPoint
& pos
) const
5175 m_mainWin
->GetItemPosition( item
, pos
);
5179 bool wxGenericListCtrl::SetItemPosition( long WXUNUSED(item
), const wxPoint
& WXUNUSED(pos
) )
5184 int wxGenericListCtrl::GetItemCount() const
5186 return m_mainWin
->GetItemCount();
5189 int wxGenericListCtrl::GetColumnCount() const
5191 return m_mainWin
->GetColumnCount();
5194 void wxGenericListCtrl::SetItemSpacing( int spacing
, bool isSmall
)
5196 m_mainWin
->SetItemSpacing( spacing
, isSmall
);
5199 wxSize
wxGenericListCtrl::GetItemSpacing() const
5201 const int spacing
= m_mainWin
->GetItemSpacing(HasFlag(wxLC_SMALL_ICON
));
5203 return wxSize(spacing
, spacing
);
5206 #if WXWIN_COMPATIBILITY_2_6
5207 int wxGenericListCtrl::GetItemSpacing( bool isSmall
) const
5209 return m_mainWin
->GetItemSpacing( isSmall
);
5211 #endif // WXWIN_COMPATIBILITY_2_6
5213 void wxGenericListCtrl::SetItemTextColour( long item
, const wxColour
&col
)
5216 info
.m_itemId
= item
;
5217 info
.SetTextColour( col
);
5218 m_mainWin
->SetItem( info
);
5221 wxColour
wxGenericListCtrl::GetItemTextColour( long item
) const
5224 info
.m_itemId
= item
;
5225 m_mainWin
->GetItem( info
);
5226 return info
.GetTextColour();
5229 void wxGenericListCtrl::SetItemBackgroundColour( long item
, const wxColour
&col
)
5232 info
.m_itemId
= item
;
5233 info
.SetBackgroundColour( col
);
5234 m_mainWin
->SetItem( info
);
5237 wxColour
wxGenericListCtrl::GetItemBackgroundColour( long item
) const
5240 info
.m_itemId
= item
;
5241 m_mainWin
->GetItem( info
);
5242 return info
.GetBackgroundColour();
5245 int wxGenericListCtrl::GetScrollPos( int orient
) const
5247 return m_mainWin
->GetScrollPos( orient
);
5250 void wxGenericListCtrl::SetScrollPos( int orient
, int pos
, bool refresh
)
5252 m_mainWin
->SetScrollPos( orient
, pos
, refresh
);
5255 void wxGenericListCtrl::SetItemFont( long item
, const wxFont
&f
)
5258 info
.m_itemId
= item
;
5260 m_mainWin
->SetItem( info
);
5263 wxFont
wxGenericListCtrl::GetItemFont( long item
) const
5266 info
.m_itemId
= item
;
5267 m_mainWin
->GetItem( info
);
5268 return info
.GetFont();
5271 int wxGenericListCtrl::GetSelectedItemCount() const
5273 return m_mainWin
->GetSelectedItemCount();
5276 wxColour
wxGenericListCtrl::GetTextColour() const
5278 return GetForegroundColour();
5281 void wxGenericListCtrl::SetTextColour(const wxColour
& col
)
5283 SetForegroundColour(col
);
5286 long wxGenericListCtrl::GetTopItem() const
5289 m_mainWin
->GetVisibleLinesRange(&top
, NULL
);
5293 long wxGenericListCtrl::GetNextItem( long item
, int geom
, int state
) const
5295 return m_mainWin
->GetNextItem( item
, geom
, state
);
5298 wxImageList
*wxGenericListCtrl::GetImageList(int which
) const
5300 if (which
== wxIMAGE_LIST_NORMAL
)
5301 return m_imageListNormal
;
5302 else if (which
== wxIMAGE_LIST_SMALL
)
5303 return m_imageListSmall
;
5304 else if (which
== wxIMAGE_LIST_STATE
)
5305 return m_imageListState
;
5307 return (wxImageList
*) NULL
;
5310 void wxGenericListCtrl::SetImageList( wxImageList
*imageList
, int which
)
5312 if ( which
== wxIMAGE_LIST_NORMAL
)
5314 if (m_ownsImageListNormal
)
5315 delete m_imageListNormal
;
5316 m_imageListNormal
= imageList
;
5317 m_ownsImageListNormal
= false;
5319 else if ( which
== wxIMAGE_LIST_SMALL
)
5321 if (m_ownsImageListSmall
)
5322 delete m_imageListSmall
;
5323 m_imageListSmall
= imageList
;
5324 m_ownsImageListSmall
= false;
5326 else if ( which
== wxIMAGE_LIST_STATE
)
5328 if (m_ownsImageListState
)
5329 delete m_imageListState
;
5330 m_imageListState
= imageList
;
5331 m_ownsImageListState
= false;
5334 m_mainWin
->SetImageList( imageList
, which
);
5337 void wxGenericListCtrl::AssignImageList(wxImageList
*imageList
, int which
)
5339 SetImageList(imageList
, which
);
5340 if ( which
== wxIMAGE_LIST_NORMAL
)
5341 m_ownsImageListNormal
= true;
5342 else if ( which
== wxIMAGE_LIST_SMALL
)
5343 m_ownsImageListSmall
= true;
5344 else if ( which
== wxIMAGE_LIST_STATE
)
5345 m_ownsImageListState
= true;
5348 bool wxGenericListCtrl::Arrange( int WXUNUSED(flag
) )
5353 bool wxGenericListCtrl::DeleteItem( long item
)
5355 m_mainWin
->DeleteItem( item
);
5359 bool wxGenericListCtrl::DeleteAllItems()
5361 m_mainWin
->DeleteAllItems();
5365 bool wxGenericListCtrl::DeleteAllColumns()
5367 size_t count
= m_mainWin
->m_columns
.GetCount();
5368 for ( size_t n
= 0; n
< count
; n
++ )
5373 void wxGenericListCtrl::ClearAll()
5375 m_mainWin
->DeleteEverything();
5378 bool wxGenericListCtrl::DeleteColumn( int col
)
5380 m_mainWin
->DeleteColumn( col
);
5382 // if we don't have the header any longer, we need to relayout the window
5383 if ( !GetColumnCount() )
5384 ResizeReportView(false /* no header */);
5388 wxTextCtrl
*wxGenericListCtrl::EditLabel(long item
,
5389 wxClassInfo
* textControlClass
)
5391 return m_mainWin
->EditLabel( item
, textControlClass
);
5394 wxTextCtrl
*wxGenericListCtrl::GetEditControl() const
5396 return m_mainWin
->GetEditControl();
5399 bool wxGenericListCtrl::EnsureVisible( long item
)
5401 m_mainWin
->EnsureVisible( item
);
5405 long wxGenericListCtrl::FindItem( long start
, const wxString
& str
, bool partial
)
5407 return m_mainWin
->FindItem( start
, str
, partial
);
5410 long wxGenericListCtrl::FindItem( long start
, wxUIntPtr data
)
5412 return m_mainWin
->FindItem( start
, data
);
5415 long wxGenericListCtrl::FindItem( long WXUNUSED(start
), const wxPoint
& pt
,
5416 int WXUNUSED(direction
))
5418 return m_mainWin
->FindItem( pt
);
5421 // TODO: sub item hit testing
5422 long wxGenericListCtrl::HitTest(const wxPoint
& point
, int& flags
, long *) const
5424 return m_mainWin
->HitTest( (int)point
.x
, (int)point
.y
, flags
);
5427 long wxGenericListCtrl::InsertItem( wxListItem
& info
)
5429 m_mainWin
->InsertItem( info
);
5430 return info
.m_itemId
;
5433 long wxGenericListCtrl::InsertItem( long index
, const wxString
&label
)
5436 info
.m_text
= label
;
5437 info
.m_mask
= wxLIST_MASK_TEXT
;
5438 info
.m_itemId
= index
;
5439 return InsertItem( info
);
5442 long wxGenericListCtrl::InsertItem( long index
, int imageIndex
)
5445 info
.m_mask
= wxLIST_MASK_IMAGE
;
5446 info
.m_image
= imageIndex
;
5447 info
.m_itemId
= index
;
5448 return InsertItem( info
);
5451 long wxGenericListCtrl::InsertItem( long index
, const wxString
&label
, int imageIndex
)
5454 info
.m_text
= label
;
5455 info
.m_image
= imageIndex
;
5456 info
.m_mask
= wxLIST_MASK_TEXT
| wxLIST_MASK_IMAGE
;
5457 info
.m_itemId
= index
;
5458 return InsertItem( info
);
5461 long wxGenericListCtrl::InsertColumn( long col
, wxListItem
&item
)
5463 wxCHECK_MSG( m_headerWin
, -1, _T("can't add column in non report mode") );
5465 m_mainWin
->InsertColumn( col
, item
);
5467 // if we hadn't had a header before but have one now
5468 // then we need to relayout the window
5469 if ( GetColumnCount() == 1 && m_mainWin
->HasHeader() )
5470 ResizeReportView(true /* have header */);
5472 m_headerWin
->Refresh();
5477 long wxGenericListCtrl::InsertColumn( long col
, const wxString
&heading
,
5478 int format
, int width
)
5481 item
.m_mask
= wxLIST_MASK_TEXT
| wxLIST_MASK_FORMAT
;
5482 item
.m_text
= heading
;
5485 item
.m_mask
|= wxLIST_MASK_WIDTH
;
5486 item
.m_width
= width
;
5489 item
.m_format
= format
;
5491 return InsertColumn( col
, item
);
5494 bool wxGenericListCtrl::ScrollList( int WXUNUSED(dx
), int WXUNUSED(dy
) )
5500 // fn is a function which takes 3 long arguments: item1, item2, data.
5501 // item1 is the long data associated with a first item (NOT the index).
5502 // item2 is the long data associated with a second item (NOT the index).
5503 // data is the same value as passed to SortItems.
5504 // The return value is a negative number if the first item should precede the second
5505 // item, a positive number of the second item should precede the first,
5506 // or zero if the two items are equivalent.
5507 // data is arbitrary data to be passed to the sort function.
5509 bool wxGenericListCtrl::SortItems( wxListCtrlCompare fn
, long data
)
5511 m_mainWin
->SortItems( fn
, data
);
5515 // ----------------------------------------------------------------------------
5517 // ----------------------------------------------------------------------------
5519 void wxGenericListCtrl::OnSize(wxSizeEvent
& WXUNUSED(event
))
5524 ResizeReportView(m_mainWin
->HasHeader());
5525 m_mainWin
->RecalculatePositions();
5528 void wxGenericListCtrl::ResizeReportView(bool showHeader
)
5531 GetClientSize( &cw
, &ch
);
5535 m_headerWin
->SetSize( 0, 0, cw
, m_headerHeight
);
5536 if(ch
> m_headerHeight
)
5537 m_mainWin
->SetSize( 0, m_headerHeight
+ 1,
5538 cw
, ch
- m_headerHeight
- 1 );
5540 m_mainWin
->SetSize( 0, m_headerHeight
+ 1,
5543 else // no header window
5545 m_mainWin
->SetSize( 0, 0, cw
, ch
);
5549 void wxGenericListCtrl::OnInternalIdle()
5551 wxWindow::OnInternalIdle();
5553 // do it only if needed
5554 if ( !m_mainWin
->m_dirty
)
5557 m_mainWin
->RecalculatePositions();
5560 // ----------------------------------------------------------------------------
5562 // ----------------------------------------------------------------------------
5564 bool wxGenericListCtrl::SetBackgroundColour( const wxColour
&colour
)
5568 m_mainWin
->SetBackgroundColour( colour
);
5569 m_mainWin
->m_dirty
= true;
5575 bool wxGenericListCtrl::SetForegroundColour( const wxColour
&colour
)
5577 if ( !wxWindow::SetForegroundColour( colour
) )
5582 m_mainWin
->SetForegroundColour( colour
);
5583 m_mainWin
->m_dirty
= true;
5587 m_headerWin
->SetForegroundColour( colour
);
5592 bool wxGenericListCtrl::SetFont( const wxFont
&font
)
5594 if ( !wxWindow::SetFont( font
) )
5599 m_mainWin
->SetFont( font
);
5600 m_mainWin
->m_dirty
= true;
5605 m_headerWin
->SetFont( font
);
5606 CalculateAndSetHeaderHeight();
5616 wxGenericListCtrl::GetClassDefaultAttributes(wxWindowVariant variant
)
5619 // Use the same color scheme as wxListBox
5620 return wxListBox::GetClassDefaultAttributes(variant
);
5622 wxUnusedVar(variant
);
5623 wxVisualAttributes attr
;
5624 attr
.colFg
= wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT
);
5625 attr
.colBg
= wxSystemSettings::GetColour(wxSYS_COLOUR_LISTBOX
);
5626 attr
.font
= wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT
);
5631 // ----------------------------------------------------------------------------
5632 // methods forwarded to m_mainWin
5633 // ----------------------------------------------------------------------------
5635 #if wxUSE_DRAG_AND_DROP
5637 void wxGenericListCtrl::SetDropTarget( wxDropTarget
*dropTarget
)
5639 m_mainWin
->SetDropTarget( dropTarget
);
5642 wxDropTarget
*wxGenericListCtrl::GetDropTarget() const
5644 return m_mainWin
->GetDropTarget();
5649 bool wxGenericListCtrl::SetCursor( const wxCursor
&cursor
)
5651 return m_mainWin
? m_mainWin
->wxWindow::SetCursor(cursor
) : false;
5654 wxColour
wxGenericListCtrl::GetBackgroundColour() const
5656 return m_mainWin
? m_mainWin
->GetBackgroundColour() : wxColour();
5659 wxColour
wxGenericListCtrl::GetForegroundColour() const
5661 return m_mainWin
? m_mainWin
->GetForegroundColour() : wxColour();
5664 bool wxGenericListCtrl::DoPopupMenu( wxMenu
*menu
, int x
, int y
)
5667 return m_mainWin
->PopupMenu( menu
, x
, y
);
5673 void wxGenericListCtrl::DoClientToScreen( int *x
, int *y
) const
5675 m_mainWin
->DoClientToScreen(x
, y
);
5678 void wxGenericListCtrl::DoScreenToClient( int *x
, int *y
) const
5680 m_mainWin
->DoScreenToClient(x
, y
);
5683 void wxGenericListCtrl::SetFocus()
5685 // The test in window.cpp fails as we are a composite
5686 // window, so it checks against "this", but not m_mainWin.
5687 if ( DoFindFocus() != this )
5688 m_mainWin
->SetFocus();
5691 wxSize
wxGenericListCtrl::DoGetBestSize() const
5693 // Something is better than nothing...
5694 // 100x80 is what the MSW version will get from the default
5695 // wxControl::DoGetBestSize
5696 return wxSize(100, 80);
5699 // ----------------------------------------------------------------------------
5700 // virtual list control support
5701 // ----------------------------------------------------------------------------
5703 wxString
wxGenericListCtrl::OnGetItemText(long WXUNUSED(item
), long WXUNUSED(col
)) const
5705 // this is a pure virtual function, in fact - which is not really pure
5706 // because the controls which are not virtual don't need to implement it
5707 wxFAIL_MSG( _T("wxGenericListCtrl::OnGetItemText not supposed to be called") );
5709 return wxEmptyString
;
5712 int wxGenericListCtrl::OnGetItemImage(long WXUNUSED(item
)) const
5714 wxCHECK_MSG(!GetImageList(wxIMAGE_LIST_SMALL
),
5716 wxT("List control has an image list, OnGetItemImage or OnGetItemColumnImage should be overridden."));
5720 int wxGenericListCtrl::OnGetItemColumnImage(long item
, long column
) const
5723 return OnGetItemImage(item
);
5729 wxGenericListCtrl::OnGetItemAttr(long WXUNUSED_UNLESS_DEBUG(item
)) const
5731 wxASSERT_MSG( item
>= 0 && item
< GetItemCount(),
5732 _T("invalid item index in OnGetItemAttr()") );
5734 // no attributes by default
5738 void wxGenericListCtrl::SetItemCount(long count
)
5740 wxASSERT_MSG( IsVirtual(), _T("this is for virtual controls only") );
5742 m_mainWin
->SetItemCount(count
);
5745 void wxGenericListCtrl::RefreshItem(long item
)
5747 m_mainWin
->RefreshLine(item
);
5750 void wxGenericListCtrl::RefreshItems(long itemFrom
, long itemTo
)
5752 m_mainWin
->RefreshLines(itemFrom
, itemTo
);
5755 // Generic wxListCtrl is more or less a container for two other
5756 // windows which drawings are done upon. These are namely
5757 // 'm_headerWin' and 'm_mainWin'.
5758 // Here we override 'virtual wxWindow::Refresh()' to mimic the
5759 // behaviour wxListCtrl has under wxMSW.
5761 void wxGenericListCtrl::Refresh(bool eraseBackground
, const wxRect
*rect
)
5765 // The easy case, no rectangle specified.
5767 m_headerWin
->Refresh(eraseBackground
);
5770 m_mainWin
->Refresh(eraseBackground
);
5774 // Refresh the header window
5777 wxRect rectHeader
= m_headerWin
->GetRect();
5778 rectHeader
.Intersect(*rect
);
5779 if (rectHeader
.GetWidth() && rectHeader
.GetHeight())
5782 m_headerWin
->GetPosition(&x
, &y
);
5783 rectHeader
.Offset(-x
, -y
);
5784 m_headerWin
->Refresh(eraseBackground
, &rectHeader
);
5788 // Refresh the main window
5791 wxRect rectMain
= m_mainWin
->GetRect();
5792 rectMain
.Intersect(*rect
);
5793 if (rectMain
.GetWidth() && rectMain
.GetHeight())
5796 m_mainWin
->GetPosition(&x
, &y
);
5797 rectMain
.Offset(-x
, -y
);
5798 m_mainWin
->Refresh(eraseBackground
, &rectMain
);
5804 void wxGenericListCtrl::Freeze()
5806 m_mainWin
->Freeze();
5809 void wxGenericListCtrl::Thaw()
5814 #endif // wxUSE_LISTCTRL