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 // under Win32 we always use the native version and also may use the generic
27 // one, however some things should be done only if we use only the generic
29 #if (defined(__WIN32__) && !defined(__WXUNIVERSAL__)) || defined(__WXMAC__)
30 #define HAVE_NATIVE_LISTCTRL
33 // if we have the native control, wx/listctrl.h declares it and not this one
34 #include "wx/listctrl.h"
36 #ifndef HAVE_NATIVE_LISTCTRL
37 // if we have a native version, its implementation file does all this
38 IMPLEMENT_DYNAMIC_CLASS(wxListItem
, wxObject
)
39 IMPLEMENT_DYNAMIC_CLASS(wxListView
, wxListCtrl
)
40 IMPLEMENT_DYNAMIC_CLASS(wxListEvent
, wxNotifyEvent
)
42 IMPLEMENT_DYNAMIC_CLASS(wxListCtrl
, wxGenericListCtrl
)
43 #endif // HAVE_NATIVE_LISTCTRL/!HAVE_NATIVE_LISTCTRL
46 #include "wx/dynarray.h"
48 #include "wx/dcscreen.h"
49 #include "wx/textctrl.h"
50 #include "wx/listbox.h"
54 #include "wx/selstore.h"
55 #include "wx/renderer.h"
58 #include "wx/mac/private.h"
62 // NOTE: If using the wxListBox visual attributes works everywhere then this can
63 // be removed, as well as the #else case below.
64 #define _USE_VISATTR 0
67 // ----------------------------------------------------------------------------
69 // ----------------------------------------------------------------------------
71 // // the height of the header window (FIXME: should depend on its font!)
72 // static const int HEADER_HEIGHT = 23;
74 static const int SCROLL_UNIT_X
= 15;
76 // the spacing between the lines (in report mode)
77 static const int LINE_SPACING
= 0;
79 // extra margins around the text label
80 static const int EXTRA_WIDTH
= 4;
81 static const int EXTRA_HEIGHT
= 4;
83 // margin between the window and the items
84 static const int EXTRA_BORDER_X
= 2;
85 static const int EXTRA_BORDER_Y
= 2;
87 // offset for the header window
88 static const int HEADER_OFFSET_X
= 1;
89 static const int HEADER_OFFSET_Y
= 1;
91 // margin between rows of icons in [small] icon view
92 static const int MARGIN_BETWEEN_ROWS
= 6;
94 // when autosizing the columns, add some slack
95 static const int AUTOSIZE_COL_MARGIN
= 10;
97 // default width for the header columns
98 static const int WIDTH_COL_DEFAULT
= 80;
100 // the space between the image and the text in the report mode
101 static const int IMAGE_MARGIN_IN_REPORT_MODE
= 5;
103 // ============================================================================
105 // ============================================================================
107 //-----------------------------------------------------------------------------
108 // wxColWidthInfo (internal)
109 //-----------------------------------------------------------------------------
111 struct wxColWidthInfo
114 bool bNeedsUpdate
; // only set to true when an item whose
115 // width == nMaxWidth is removed
117 wxColWidthInfo(int w
= 0, bool needsUpdate
= false)
120 bNeedsUpdate
= needsUpdate
;
124 WX_DEFINE_ARRAY_PTR(wxColWidthInfo
*, ColWidthArray
);
126 //-----------------------------------------------------------------------------
127 // wxListItemData (internal)
128 //-----------------------------------------------------------------------------
130 class WXDLLEXPORT wxListItemData
133 wxListItemData(wxListMainWindow
*owner
);
136 void SetItem( const wxListItem
&info
);
137 void SetImage( int image
) { m_image
= image
; }
138 void SetData( wxUIntPtr data
) { m_data
= data
; }
139 void SetPosition( int x
, int y
);
140 void SetSize( int width
, int height
);
142 bool HasText() const { return !m_text
.empty(); }
143 const wxString
& GetText() const { return m_text
; }
144 void SetText(const wxString
& text
) { m_text
= text
; }
146 // we can't use empty string for measuring the string width/height, so
147 // always return something
148 wxString
GetTextForMeasuring() const
150 wxString s
= GetText();
157 bool IsHit( int x
, int y
) const;
161 int GetWidth() const;
162 int GetHeight() const;
164 int GetImage() const { return m_image
; }
165 bool HasImage() const { return GetImage() != -1; }
167 void GetItem( wxListItem
&info
) const;
169 void SetAttr(wxListItemAttr
*attr
) { m_attr
= attr
; }
170 wxListItemAttr
*GetAttr() const { return m_attr
; }
173 // the item image or -1
176 // user data associated with the item
179 // the item coordinates are not used in report mode; instead this pointer is
180 // NULL and the owner window is used to retrieve the item position and size
183 // the list ctrl we are in
184 wxListMainWindow
*m_owner
;
186 // custom attributes or NULL
187 wxListItemAttr
*m_attr
;
190 // common part of all ctors
196 //-----------------------------------------------------------------------------
197 // wxListHeaderData (internal)
198 //-----------------------------------------------------------------------------
200 class WXDLLEXPORT wxListHeaderData
: public wxObject
204 wxListHeaderData( const wxListItem
&info
);
205 void SetItem( const wxListItem
&item
);
206 void SetPosition( int x
, int y
);
207 void SetWidth( int w
);
208 void SetFormat( int format
);
209 void SetHeight( int h
);
210 bool HasImage() const;
212 bool HasText() const { return !m_text
.empty(); }
213 const wxString
& GetText() const { return m_text
; }
214 void SetText(const wxString
& text
) { m_text
= text
; }
216 void GetItem( wxListItem
&item
);
218 bool IsHit( int x
, int y
) const;
219 int GetImage() const;
220 int GetWidth() const;
221 int GetFormat() const;
237 //-----------------------------------------------------------------------------
238 // wxListLineData (internal)
239 //-----------------------------------------------------------------------------
241 WX_DECLARE_EXPORTED_LIST(wxListItemData
, wxListItemDataList
);
242 #include "wx/listimpl.cpp"
243 WX_DEFINE_LIST(wxListItemDataList
)
248 // the list of subitems: only may have more than one item in report mode
249 wxListItemDataList m_items
;
251 // this is not used in report view
263 // the part to be highlighted
264 wxRect m_rectHighlight
;
266 // extend all our rects to be centered inside the one of given width
267 void ExtendWidth(wxCoord w
)
269 wxASSERT_MSG( m_rectAll
.width
<= w
,
270 _T("width can only be increased") );
273 m_rectLabel
.x
= m_rectAll
.x
+ (w
- m_rectLabel
.width
) / 2;
274 m_rectIcon
.x
= m_rectAll
.x
+ (w
- m_rectIcon
.width
) / 2;
275 m_rectHighlight
.x
= m_rectAll
.x
+ (w
- m_rectHighlight
.width
) / 2;
280 // is this item selected? [NB: not used in virtual mode]
283 // back pointer to the list ctrl
284 wxListMainWindow
*m_owner
;
287 wxListLineData(wxListMainWindow
*owner
);
291 WX_CLEAR_LIST(wxListItemDataList
, m_items
);
295 // are we in report mode?
296 inline bool InReportView() const;
298 // are we in virtual report mode?
299 inline bool IsVirtual() const;
301 // these 2 methods shouldn't be called for report view controls, in that
302 // case we determine our position/size ourselves
304 // calculate the size of the line
305 void CalculateSize( wxDC
*dc
, int spacing
);
307 // remember the position this line appears at
308 void SetPosition( int x
, int y
, int spacing
);
312 void SetImage( int image
) { SetImage(0, image
); }
313 int GetImage() const { return GetImage(0); }
314 void SetImage( int index
, int image
);
315 int GetImage( int index
) const;
317 bool HasImage() const { return GetImage() != -1; }
318 bool HasText() const { return !GetText(0).empty(); }
320 void SetItem( int index
, const wxListItem
&info
);
321 void GetItem( int index
, wxListItem
&info
);
323 wxString
GetText(int index
) const;
324 void SetText( int index
, const wxString
& s
);
326 wxListItemAttr
*GetAttr() const;
327 void SetAttr(wxListItemAttr
*attr
);
329 // return true if the highlighting really changed
330 bool Highlight( bool on
);
332 void ReverseHighlight();
334 bool IsHighlighted() const
336 wxASSERT_MSG( !IsVirtual(), _T("unexpected call to IsHighlighted") );
338 return m_highlighted
;
341 // draw the line on the given DC in icon/list mode
342 void Draw( wxDC
*dc
);
344 // the same in report mode
345 void DrawInReportMode( wxDC
*dc
,
347 const wxRect
& rectHL
,
351 // set the line to contain num items (only can be > 1 in report mode)
352 void InitItems( int num
);
354 // get the mode (i.e. style) of the list control
355 inline int GetMode() const;
357 // prepare the DC for drawing with these item's attributes, return true if
358 // we need to draw the items background to highlight it, false otherwise
359 bool SetAttributes(wxDC
*dc
,
360 const wxListItemAttr
*attr
,
363 // draw the text on the DC with the correct justification; also add an
364 // ellipsis if the text is too large to fit in the current width
365 void DrawTextFormatted(wxDC
*dc
,
366 const wxString
&text
,
369 int yMid
, // this is middle, not top, of the text
373 WX_DECLARE_EXPORTED_OBJARRAY(wxListLineData
, wxListLineDataArray
);
374 #include "wx/arrimpl.cpp"
375 WX_DEFINE_OBJARRAY(wxListLineDataArray
)
377 //-----------------------------------------------------------------------------
378 // wxListHeaderWindow (internal)
379 //-----------------------------------------------------------------------------
381 class WXDLLEXPORT wxListHeaderWindow
: public wxWindow
384 wxListMainWindow
*m_owner
;
385 const wxCursor
*m_currentCursor
;
386 wxCursor
*m_resizeCursor
;
389 // column being resized or -1
392 // divider line position in logical (unscrolled) coords
395 // minimal position beyond which the divider line
396 // can't be dragged in logical coords
400 wxListHeaderWindow();
402 wxListHeaderWindow( wxWindow
*win
,
404 wxListMainWindow
*owner
,
405 const wxPoint
&pos
= wxDefaultPosition
,
406 const wxSize
&size
= wxDefaultSize
,
408 const wxString
&name
= wxT("wxlistctrlcolumntitles") );
410 virtual ~wxListHeaderWindow();
413 void AdjustDC( wxDC
& dc
);
415 void OnPaint( wxPaintEvent
&event
);
416 void OnMouse( wxMouseEvent
&event
);
417 void OnSetFocus( wxFocusEvent
&event
);
423 // common part of all ctors
426 // generate and process the list event of the given type, return true if
427 // it wasn't vetoed, i.e. if we should proceed
428 bool SendListEvent(wxEventType type
, const wxPoint
& pos
);
430 DECLARE_DYNAMIC_CLASS(wxListHeaderWindow
)
431 DECLARE_EVENT_TABLE()
434 //-----------------------------------------------------------------------------
435 // wxListRenameTimer (internal)
436 //-----------------------------------------------------------------------------
438 class WXDLLEXPORT wxListRenameTimer
: public wxTimer
441 wxListMainWindow
*m_owner
;
444 wxListRenameTimer( wxListMainWindow
*owner
);
448 //-----------------------------------------------------------------------------
449 // wxListTextCtrlWrapper: wraps a wxTextCtrl to make it work for inline editing
450 //-----------------------------------------------------------------------------
452 class WXDLLEXPORT wxListTextCtrlWrapper
: public wxEvtHandler
455 // NB: text must be a valid object but not Create()d yet
456 wxListTextCtrlWrapper(wxListMainWindow
*owner
,
460 wxTextCtrl
*GetText() const { return m_text
; }
462 void AcceptChangesAndFinish();
465 void OnChar( wxKeyEvent
&event
);
466 void OnKeyUp( wxKeyEvent
&event
);
467 void OnKillFocus( wxFocusEvent
&event
);
469 bool AcceptChanges();
473 wxListMainWindow
*m_owner
;
475 wxString m_startValue
;
478 bool m_aboutToFinish
;
480 DECLARE_EVENT_TABLE()
483 //-----------------------------------------------------------------------------
484 // wxListMainWindow (internal)
485 //-----------------------------------------------------------------------------
487 WX_DECLARE_EXPORTED_LIST(wxListHeaderData
, wxListHeaderDataList
);
488 #include "wx/listimpl.cpp"
489 WX_DEFINE_LIST(wxListHeaderDataList
)
491 class wxListMainWindow
: public wxScrolledWindow
495 wxListMainWindow( wxWindow
*parent
,
497 const wxPoint
& pos
= wxDefaultPosition
,
498 const wxSize
& size
= wxDefaultSize
,
500 const wxString
&name
= _T("listctrlmainwindow") );
502 virtual ~wxListMainWindow();
504 bool HasFlag(int flag
) const { return m_parent
->HasFlag(flag
); }
506 // return true if this is a virtual list control
507 bool IsVirtual() const { return HasFlag(wxLC_VIRTUAL
); }
509 // return true if the control is in report mode
510 bool InReportView() const { return HasFlag(wxLC_REPORT
); }
512 // return true if we are in single selection mode, false if multi sel
513 bool IsSingleSel() const { return HasFlag(wxLC_SINGLE_SEL
); }
515 // do we have a header window?
516 bool HasHeader() const
517 { return InReportView() && !HasFlag(wxLC_NO_HEADER
); }
519 void HighlightAll( bool on
);
521 // all these functions only do something if the line is currently visible
523 // change the line "selected" state, return true if it really changed
524 bool HighlightLine( size_t line
, bool highlight
= true);
526 // as HighlightLine() but do it for the range of lines: this is incredibly
527 // more efficient for virtual list controls!
529 // NB: unlike HighlightLine() this one does refresh the lines on screen
530 void HighlightLines( size_t lineFrom
, size_t lineTo
, bool on
= true );
532 // toggle the line state and refresh it
533 void ReverseHighlight( size_t line
)
534 { HighlightLine(line
, !IsHighlighted(line
)); RefreshLine(line
); }
536 // return true if the line is highlighted
537 bool IsHighlighted(size_t line
) const;
539 // refresh one or several lines at once
540 void RefreshLine( size_t line
);
541 void RefreshLines( size_t lineFrom
, size_t lineTo
);
543 // refresh all selected items
544 void RefreshSelected();
546 // refresh all lines below the given one: the difference with
547 // RefreshLines() is that the index here might not be a valid one (happens
548 // when the last line is deleted)
549 void RefreshAfter( size_t lineFrom
);
551 // the methods which are forwarded to wxListLineData itself in list/icon
552 // modes but are here because the lines don't store their positions in the
555 // get the bound rect for the entire line
556 wxRect
GetLineRect(size_t line
) const;
558 // get the bound rect of the label
559 wxRect
GetLineLabelRect(size_t line
) const;
561 // get the bound rect of the items icon (only may be called if we do have
563 wxRect
GetLineIconRect(size_t line
) const;
565 // get the rect to be highlighted when the item has focus
566 wxRect
GetLineHighlightRect(size_t line
) const;
568 // get the size of the total line rect
569 wxSize
GetLineSize(size_t line
) const
570 { return GetLineRect(line
).GetSize(); }
572 // return the hit code for the corresponding position (in this line)
573 long HitTestLine(size_t line
, int x
, int y
) const;
575 // bring the selected item into view, scrolling to it if necessary
576 void MoveToItem(size_t item
);
578 // bring the current item into view
579 void MoveToFocus() { MoveToItem(m_current
); }
581 // start editing the label of the given item
582 wxTextCtrl
*EditLabel(long item
,
583 wxClassInfo
* textControlClass
= CLASSINFO(wxTextCtrl
));
584 wxTextCtrl
*GetEditControl() const
586 return m_textctrlWrapper
? m_textctrlWrapper
->GetText() : NULL
;
589 void FinishEditing(wxTextCtrl
*text
)
592 m_textctrlWrapper
= NULL
;
593 SetFocusIgnoringChildren();
596 // suspend/resume redrawing the control
600 void OnRenameTimer();
601 bool OnRenameAccept(size_t itemEdit
, const wxString
& value
);
602 void OnRenameCancelled(size_t itemEdit
);
604 void OnMouse( wxMouseEvent
&event
);
606 // called to switch the selection from the current item to newCurrent,
607 void OnArrowChar( size_t newCurrent
, const wxKeyEvent
& event
);
609 void OnChar( wxKeyEvent
&event
);
610 void OnKeyDown( wxKeyEvent
&event
);
611 void OnSetFocus( wxFocusEvent
&event
);
612 void OnKillFocus( wxFocusEvent
&event
);
613 void OnScroll( wxScrollWinEvent
& event
);
615 void OnPaint( wxPaintEvent
&event
);
617 void DrawImage( int index
, wxDC
*dc
, int x
, int y
);
618 void GetImageSize( int index
, int &width
, int &height
) const;
619 int GetTextLength( const wxString
&s
) const;
621 void SetImageList( wxImageList
*imageList
, int which
);
622 void SetItemSpacing( int spacing
, bool isSmall
= false );
623 int GetItemSpacing( bool isSmall
= false );
625 void SetColumn( int col
, wxListItem
&item
);
626 void SetColumnWidth( int col
, int width
);
627 void GetColumn( int col
, wxListItem
&item
) const;
628 int GetColumnWidth( int col
) const;
629 int GetColumnCount() const { return m_columns
.GetCount(); }
631 // returns the sum of the heights of all columns
632 int GetHeaderWidth() const;
634 int GetCountPerPage() const;
636 void SetItem( wxListItem
&item
);
637 void GetItem( wxListItem
&item
) const;
638 void SetItemState( long item
, long state
, long stateMask
);
639 void SetItemStateAll( long state
, long stateMask
);
640 int GetItemState( long item
, long stateMask
) const;
641 void GetItemRect( long index
, wxRect
&rect
) const;
642 wxRect
GetViewRect() const;
643 bool GetItemPosition( long item
, wxPoint
& pos
) const;
644 int GetSelectedItemCount() const;
646 wxString
GetItemText(long item
) const
649 info
.m_mask
= wxLIST_MASK_TEXT
;
650 info
.m_itemId
= item
;
655 void SetItemText(long item
, const wxString
& value
)
658 info
.m_mask
= wxLIST_MASK_TEXT
;
659 info
.m_itemId
= item
;
664 // set the scrollbars and update the positions of the items
665 void RecalculatePositions(bool noRefresh
= false);
667 // refresh the window and the header
670 long GetNextItem( long item
, int geometry
, int state
) const;
671 void DeleteItem( long index
);
672 void DeleteAllItems();
673 void DeleteColumn( int col
);
674 void DeleteEverything();
675 void EnsureVisible( long index
);
676 long FindItem( long start
, const wxString
& str
, bool partial
= false );
677 long FindItem( long start
, wxUIntPtr data
);
678 long FindItem( const wxPoint
& pt
);
679 long HitTest( int x
, int y
, int &flags
) const;
680 void InsertItem( wxListItem
&item
);
681 void InsertColumn( long col
, wxListItem
&item
);
682 int GetItemWidthWithImage(wxListItem
* item
);
683 void SortItems( wxListCtrlCompare fn
, long data
);
685 size_t GetItemCount() const;
686 bool IsEmpty() const { return GetItemCount() == 0; }
687 void SetItemCount(long count
);
689 // change the current (== focused) item, send a notification event
690 void ChangeCurrent(size_t current
);
691 void ResetCurrent() { ChangeCurrent((size_t)-1); }
692 bool HasCurrent() const { return m_current
!= (size_t)-1; }
694 // send out a wxListEvent
695 void SendNotify( size_t line
,
697 const wxPoint
& point
= wxDefaultPosition
);
699 // override base class virtual to reset m_lineHeight when the font changes
700 virtual bool SetFont(const wxFont
& font
)
702 if ( !wxScrolledWindow::SetFont(font
) )
710 // these are for wxListLineData usage only
712 // get the backpointer to the list ctrl
713 wxGenericListCtrl
*GetListCtrl() const
715 return wxStaticCast(GetParent(), wxGenericListCtrl
);
718 // get the height of all lines (assuming they all do have the same height)
719 wxCoord
GetLineHeight() const;
721 // get the y position of the given line (only for report view)
722 wxCoord
GetLineY(size_t line
) const;
724 // get the brush to use for the item highlighting
725 wxBrush
*GetHighlightBrush() const
727 return m_hasFocus
? m_highlightBrush
: m_highlightUnfocusedBrush
;
731 // the array of all line objects for a non virtual list control (for the
732 // virtual list control we only ever use m_lines[0])
733 wxListLineDataArray m_lines
;
735 // the list of column objects
736 wxListHeaderDataList m_columns
;
738 // currently focused item or -1
741 // the number of lines per page
744 // this flag is set when something which should result in the window
745 // redrawing happens (i.e. an item was added or deleted, or its appearance
746 // changed) and OnPaint() doesn't redraw the window while it is set which
747 // allows to minimize the number of repaintings when a lot of items are
748 // being added. The real repainting occurs only after the next OnIdle()
752 wxColour
*m_highlightColour
;
753 wxImageList
*m_small_image_list
;
754 wxImageList
*m_normal_image_list
;
756 int m_normal_spacing
;
760 wxTimer
*m_renameTimer
;
764 ColWidthArray m_aColWidths
;
766 // for double click logic
767 size_t m_lineLastClicked
,
768 m_lineBeforeLastClicked
,
769 m_lineSelectSingleOnUp
;
772 wxWindow
*GetMainWindowOfCompositeControl() { return GetParent(); }
774 // the total count of items in a virtual list control
777 // the object maintaining the items selection state, only used in virtual
779 wxSelectionStore m_selStore
;
781 // common part of all ctors
784 // get the line data for the given index
785 wxListLineData
*GetLine(size_t n
) const
787 wxASSERT_MSG( n
!= (size_t)-1, _T("invalid line index") );
791 wxConstCast(this, wxListMainWindow
)->CacheLineData(n
);
798 // get a dummy line which can be used for geometry calculations and such:
799 // you must use GetLine() if you want to really draw the line
800 wxListLineData
*GetDummyLine() const;
802 // cache the line data of the n-th line in m_lines[0]
803 void CacheLineData(size_t line
);
805 // get the range of visible lines
806 void GetVisibleLinesRange(size_t *from
, size_t *to
);
808 // force us to recalculate the range of visible lines
809 void ResetVisibleLinesRange() { m_lineFrom
= (size_t)-1; }
811 // get the colour to be used for drawing the rules
812 wxColour
GetRuleColour() const
814 return wxSystemSettings::GetColour(wxSYS_COLOUR_3DLIGHT
);
818 // initialize the current item if needed
819 void UpdateCurrent();
821 // delete all items but don't refresh: called from dtor
822 void DoDeleteAllItems();
824 // the height of one line using the current font
825 wxCoord m_lineHeight
;
827 // the total header width or 0 if not calculated yet
828 wxCoord m_headerWidth
;
830 // the first and last lines being shown on screen right now (inclusive),
831 // both may be -1 if they must be calculated so never access them directly:
832 // use GetVisibleLinesRange() above instead
836 // the brushes to use for item highlighting when we do/don't have focus
837 wxBrush
*m_highlightBrush
,
838 *m_highlightUnfocusedBrush
;
840 // if this is > 0, the control is frozen and doesn't redraw itself
841 size_t m_freezeCount
;
843 // wrapper around the text control currently used for in place editing or
844 // NULL if no item is being edited
845 wxListTextCtrlWrapper
*m_textctrlWrapper
;
848 DECLARE_DYNAMIC_CLASS(wxListMainWindow
)
849 DECLARE_EVENT_TABLE()
851 friend class wxGenericListCtrl
;
855 wxListItemData::~wxListItemData()
857 // in the virtual list control the attributes are managed by the main
858 // program, so don't delete them
859 if ( !m_owner
->IsVirtual() )
865 void wxListItemData::Init()
873 wxListItemData::wxListItemData(wxListMainWindow
*owner
)
879 if ( owner
->InReportView() )
885 void wxListItemData::SetItem( const wxListItem
&info
)
887 if ( info
.m_mask
& wxLIST_MASK_TEXT
)
888 SetText(info
.m_text
);
889 if ( info
.m_mask
& wxLIST_MASK_IMAGE
)
890 m_image
= info
.m_image
;
891 if ( info
.m_mask
& wxLIST_MASK_DATA
)
892 m_data
= info
.m_data
;
894 if ( info
.HasAttributes() )
897 *m_attr
= *info
.GetAttributes();
899 m_attr
= new wxListItemAttr(*info
.GetAttributes());
907 m_rect
->width
= info
.m_width
;
911 void wxListItemData::SetPosition( int x
, int y
)
913 wxCHECK_RET( m_rect
, _T("unexpected SetPosition() call") );
919 void wxListItemData::SetSize( int width
, int height
)
921 wxCHECK_RET( m_rect
, _T("unexpected SetSize() call") );
924 m_rect
->width
= width
;
926 m_rect
->height
= height
;
929 bool wxListItemData::IsHit( int x
, int y
) const
931 wxCHECK_MSG( m_rect
, false, _T("can't be called in this mode") );
933 return wxRect(GetX(), GetY(), GetWidth(), GetHeight()).Contains(x
, y
);
936 int wxListItemData::GetX() const
938 wxCHECK_MSG( m_rect
, 0, _T("can't be called in this mode") );
943 int wxListItemData::GetY() const
945 wxCHECK_MSG( m_rect
, 0, _T("can't be called in this mode") );
950 int wxListItemData::GetWidth() const
952 wxCHECK_MSG( m_rect
, 0, _T("can't be called in this mode") );
954 return m_rect
->width
;
957 int wxListItemData::GetHeight() const
959 wxCHECK_MSG( m_rect
, 0, _T("can't be called in this mode") );
961 return m_rect
->height
;
964 void wxListItemData::GetItem( wxListItem
&info
) const
966 long mask
= info
.m_mask
;
968 // by default, get everything for backwards compatibility
971 if ( mask
& wxLIST_MASK_TEXT
)
972 info
.m_text
= m_text
;
973 if ( mask
& wxLIST_MASK_IMAGE
)
974 info
.m_image
= m_image
;
975 if ( mask
& wxLIST_MASK_DATA
)
976 info
.m_data
= m_data
;
980 if ( m_attr
->HasTextColour() )
981 info
.SetTextColour(m_attr
->GetTextColour());
982 if ( m_attr
->HasBackgroundColour() )
983 info
.SetBackgroundColour(m_attr
->GetBackgroundColour());
984 if ( m_attr
->HasFont() )
985 info
.SetFont(m_attr
->GetFont());
989 //-----------------------------------------------------------------------------
991 //-----------------------------------------------------------------------------
993 void wxListHeaderData::Init()
1004 wxListHeaderData::wxListHeaderData()
1009 wxListHeaderData::wxListHeaderData( const wxListItem
&item
)
1016 void wxListHeaderData::SetItem( const wxListItem
&item
)
1018 m_mask
= item
.m_mask
;
1020 if ( m_mask
& wxLIST_MASK_TEXT
)
1021 m_text
= item
.m_text
;
1023 if ( m_mask
& wxLIST_MASK_IMAGE
)
1024 m_image
= item
.m_image
;
1026 if ( m_mask
& wxLIST_MASK_FORMAT
)
1027 m_format
= item
.m_format
;
1029 if ( m_mask
& wxLIST_MASK_WIDTH
)
1030 SetWidth(item
.m_width
);
1033 void wxListHeaderData::SetPosition( int x
, int y
)
1039 void wxListHeaderData::SetHeight( int h
)
1044 void wxListHeaderData::SetWidth( int w
)
1046 m_width
= w
< 0 ? WIDTH_COL_DEFAULT
: w
;
1049 void wxListHeaderData::SetFormat( int format
)
1054 bool wxListHeaderData::HasImage() const
1056 return m_image
!= -1;
1059 bool wxListHeaderData::IsHit( int x
, int y
) const
1061 return ((x
>= m_xpos
) && (x
<= m_xpos
+m_width
) && (y
>= m_ypos
) && (y
<= m_ypos
+m_height
));
1064 void wxListHeaderData::GetItem( wxListItem
& item
)
1066 item
.m_mask
= m_mask
;
1067 item
.m_text
= m_text
;
1068 item
.m_image
= m_image
;
1069 item
.m_format
= m_format
;
1070 item
.m_width
= m_width
;
1073 int wxListHeaderData::GetImage() const
1078 int wxListHeaderData::GetWidth() const
1083 int wxListHeaderData::GetFormat() const
1088 //-----------------------------------------------------------------------------
1090 //-----------------------------------------------------------------------------
1092 inline int wxListLineData::GetMode() const
1094 return m_owner
->GetListCtrl()->GetWindowStyleFlag() & wxLC_MASK_TYPE
;
1097 inline bool wxListLineData::InReportView() const
1099 return m_owner
->HasFlag(wxLC_REPORT
);
1102 inline bool wxListLineData::IsVirtual() const
1104 return m_owner
->IsVirtual();
1107 wxListLineData::wxListLineData( wxListMainWindow
*owner
)
1111 if ( InReportView() )
1114 m_gi
= new GeometryInfo
;
1116 m_highlighted
= false;
1118 InitItems( GetMode() == wxLC_REPORT
? m_owner
->GetColumnCount() : 1 );
1121 void wxListLineData::CalculateSize( wxDC
*dc
, int spacing
)
1123 wxListItemDataList::compatibility_iterator node
= m_items
.GetFirst();
1124 wxCHECK_RET( node
, _T("no subitems at all??") );
1126 wxListItemData
*item
= node
->GetData();
1131 switch ( GetMode() )
1134 case wxLC_SMALL_ICON
:
1135 m_gi
->m_rectAll
.width
= spacing
;
1137 s
= item
->GetText();
1142 m_gi
->m_rectLabel
.width
=
1143 m_gi
->m_rectLabel
.height
= 0;
1147 dc
->GetTextExtent( s
, &lw
, &lh
);
1151 m_gi
->m_rectAll
.height
= spacing
+ lh
;
1153 m_gi
->m_rectAll
.width
= lw
;
1155 m_gi
->m_rectLabel
.width
= lw
;
1156 m_gi
->m_rectLabel
.height
= lh
;
1159 if (item
->HasImage())
1162 m_owner
->GetImageSize( item
->GetImage(), w
, h
);
1163 m_gi
->m_rectIcon
.width
= w
+ 8;
1164 m_gi
->m_rectIcon
.height
= h
+ 8;
1166 if ( m_gi
->m_rectIcon
.width
> m_gi
->m_rectAll
.width
)
1167 m_gi
->m_rectAll
.width
= m_gi
->m_rectIcon
.width
;
1168 if ( m_gi
->m_rectIcon
.height
+ lh
> m_gi
->m_rectAll
.height
- 4 )
1169 m_gi
->m_rectAll
.height
= m_gi
->m_rectIcon
.height
+ lh
+ 4;
1172 if ( item
->HasText() )
1174 m_gi
->m_rectHighlight
.width
= m_gi
->m_rectLabel
.width
;
1175 m_gi
->m_rectHighlight
.height
= m_gi
->m_rectLabel
.height
;
1177 else // no text, highlight the icon
1179 m_gi
->m_rectHighlight
.width
= m_gi
->m_rectIcon
.width
;
1180 m_gi
->m_rectHighlight
.height
= m_gi
->m_rectIcon
.height
;
1185 s
= item
->GetTextForMeasuring();
1187 dc
->GetTextExtent( s
, &lw
, &lh
);
1191 m_gi
->m_rectLabel
.width
= lw
;
1192 m_gi
->m_rectLabel
.height
= lh
;
1194 m_gi
->m_rectAll
.width
= lw
;
1195 m_gi
->m_rectAll
.height
= lh
;
1197 if (item
->HasImage())
1200 m_owner
->GetImageSize( item
->GetImage(), w
, h
);
1201 m_gi
->m_rectIcon
.width
= w
;
1202 m_gi
->m_rectIcon
.height
= h
;
1204 m_gi
->m_rectAll
.width
+= 4 + w
;
1205 if (h
> m_gi
->m_rectAll
.height
)
1206 m_gi
->m_rectAll
.height
= h
;
1209 m_gi
->m_rectHighlight
.width
= m_gi
->m_rectAll
.width
;
1210 m_gi
->m_rectHighlight
.height
= m_gi
->m_rectAll
.height
;
1214 wxFAIL_MSG( _T("unexpected call to SetSize") );
1218 wxFAIL_MSG( _T("unknown mode") );
1223 void wxListLineData::SetPosition( int x
, int y
, int spacing
)
1225 wxListItemDataList::compatibility_iterator node
= m_items
.GetFirst();
1226 wxCHECK_RET( node
, _T("no subitems at all??") );
1228 wxListItemData
*item
= node
->GetData();
1230 switch ( GetMode() )
1233 case wxLC_SMALL_ICON
:
1234 m_gi
->m_rectAll
.x
= x
;
1235 m_gi
->m_rectAll
.y
= y
;
1237 if ( item
->HasImage() )
1239 m_gi
->m_rectIcon
.x
= m_gi
->m_rectAll
.x
+ 4 +
1240 (m_gi
->m_rectAll
.width
- m_gi
->m_rectIcon
.width
) / 2;
1241 m_gi
->m_rectIcon
.y
= m_gi
->m_rectAll
.y
+ 4;
1244 if ( item
->HasText() )
1246 if (m_gi
->m_rectAll
.width
> spacing
)
1247 m_gi
->m_rectLabel
.x
= m_gi
->m_rectAll
.x
+ 2;
1249 m_gi
->m_rectLabel
.x
= m_gi
->m_rectAll
.x
+ 2 + (spacing
/ 2) - (m_gi
->m_rectLabel
.width
/ 2);
1250 m_gi
->m_rectLabel
.y
= m_gi
->m_rectAll
.y
+ m_gi
->m_rectAll
.height
+ 2 - m_gi
->m_rectLabel
.height
;
1251 m_gi
->m_rectHighlight
.x
= m_gi
->m_rectLabel
.x
- 2;
1252 m_gi
->m_rectHighlight
.y
= m_gi
->m_rectLabel
.y
- 2;
1254 else // no text, highlight the icon
1256 m_gi
->m_rectHighlight
.x
= m_gi
->m_rectIcon
.x
- 4;
1257 m_gi
->m_rectHighlight
.y
= m_gi
->m_rectIcon
.y
- 4;
1262 m_gi
->m_rectAll
.x
= x
;
1263 m_gi
->m_rectAll
.y
= y
;
1265 m_gi
->m_rectHighlight
.x
= m_gi
->m_rectAll
.x
;
1266 m_gi
->m_rectHighlight
.y
= m_gi
->m_rectAll
.y
;
1267 m_gi
->m_rectLabel
.y
= m_gi
->m_rectAll
.y
+ 2;
1269 if (item
->HasImage())
1271 m_gi
->m_rectIcon
.x
= m_gi
->m_rectAll
.x
+ 2;
1272 m_gi
->m_rectIcon
.y
= m_gi
->m_rectAll
.y
+ 2;
1273 m_gi
->m_rectLabel
.x
= m_gi
->m_rectAll
.x
+ 6 + m_gi
->m_rectIcon
.width
;
1277 m_gi
->m_rectLabel
.x
= m_gi
->m_rectAll
.x
+ 2;
1282 wxFAIL_MSG( _T("unexpected call to SetPosition") );
1286 wxFAIL_MSG( _T("unknown mode") );
1291 void wxListLineData::InitItems( int num
)
1293 for (int i
= 0; i
< num
; i
++)
1294 m_items
.Append( new wxListItemData(m_owner
) );
1297 void wxListLineData::SetItem( int index
, const wxListItem
&info
)
1299 wxListItemDataList::compatibility_iterator node
= m_items
.Item( index
);
1300 wxCHECK_RET( node
, _T("invalid column index in SetItem") );
1302 wxListItemData
*item
= node
->GetData();
1303 item
->SetItem( info
);
1306 void wxListLineData::GetItem( int index
, wxListItem
&info
)
1308 wxListItemDataList::compatibility_iterator node
= m_items
.Item( index
);
1311 wxListItemData
*item
= node
->GetData();
1312 item
->GetItem( info
);
1316 wxString
wxListLineData::GetText(int index
) const
1320 wxListItemDataList::compatibility_iterator node
= m_items
.Item( index
);
1323 wxListItemData
*item
= node
->GetData();
1324 s
= item
->GetText();
1330 void wxListLineData::SetText( int index
, const wxString
& s
)
1332 wxListItemDataList::compatibility_iterator node
= m_items
.Item( index
);
1335 wxListItemData
*item
= node
->GetData();
1340 void wxListLineData::SetImage( int index
, int image
)
1342 wxListItemDataList::compatibility_iterator node
= m_items
.Item( index
);
1343 wxCHECK_RET( node
, _T("invalid column index in SetImage()") );
1345 wxListItemData
*item
= node
->GetData();
1346 item
->SetImage(image
);
1349 int wxListLineData::GetImage( int index
) const
1351 wxListItemDataList::compatibility_iterator node
= m_items
.Item( index
);
1352 wxCHECK_MSG( node
, -1, _T("invalid column index in GetImage()") );
1354 wxListItemData
*item
= node
->GetData();
1355 return item
->GetImage();
1358 wxListItemAttr
*wxListLineData::GetAttr() const
1360 wxListItemDataList::compatibility_iterator node
= m_items
.GetFirst();
1361 wxCHECK_MSG( node
, NULL
, _T("invalid column index in GetAttr()") );
1363 wxListItemData
*item
= node
->GetData();
1364 return item
->GetAttr();
1367 void wxListLineData::SetAttr(wxListItemAttr
*attr
)
1369 wxListItemDataList::compatibility_iterator node
= m_items
.GetFirst();
1370 wxCHECK_RET( node
, _T("invalid column index in SetAttr()") );
1372 wxListItemData
*item
= node
->GetData();
1373 item
->SetAttr(attr
);
1376 bool wxListLineData::SetAttributes(wxDC
*dc
,
1377 const wxListItemAttr
*attr
,
1380 wxWindow
*listctrl
= m_owner
->GetParent();
1384 // don't use foreground colour for drawing highlighted items - this might
1385 // make them completely invisible (and there is no way to do bit
1386 // arithmetics on wxColour, unfortunately)
1389 colText
= wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHTTEXT
);
1390 else if ( attr
&& attr
->HasTextColour() )
1391 colText
= attr
->GetTextColour();
1393 colText
= listctrl
->GetForegroundColour();
1395 dc
->SetTextForeground(colText
);
1399 if ( attr
&& attr
->HasFont() )
1400 font
= attr
->GetFont();
1402 font
= listctrl
->GetFont();
1407 bool hasBgCol
= attr
&& attr
->HasBackgroundColour();
1408 if ( highlighted
|| hasBgCol
)
1411 dc
->SetBrush( *m_owner
->GetHighlightBrush() );
1413 dc
->SetBrush(wxBrush(attr
->GetBackgroundColour(), wxSOLID
));
1415 dc
->SetPen( *wxTRANSPARENT_PEN
);
1423 void wxListLineData::Draw( wxDC
*dc
)
1425 wxListItemDataList::compatibility_iterator node
= m_items
.GetFirst();
1426 wxCHECK_RET( node
, _T("no subitems at all??") );
1428 bool highlighted
= IsHighlighted();
1430 wxListItemAttr
*attr
= GetAttr();
1432 if ( SetAttributes(dc
, attr
, highlighted
) )
1433 dc
->DrawRectangle( m_gi
->m_rectHighlight
);
1435 // just for debugging to better see where the items are
1437 dc
->SetPen(*wxRED_PEN
);
1438 dc
->SetBrush(*wxTRANSPARENT_BRUSH
);
1439 dc
->DrawRectangle( m_gi
->m_rectAll
);
1440 dc
->SetPen(*wxGREEN_PEN
);
1441 dc
->DrawRectangle( m_gi
->m_rectIcon
);
1444 wxListItemData
*item
= node
->GetData();
1445 if (item
->HasImage())
1447 // centre the image inside our rectangle, this looks nicer when items
1448 // ae aligned in a row
1449 const wxRect
& rectIcon
= m_gi
->m_rectIcon
;
1451 m_owner
->DrawImage(item
->GetImage(), dc
, rectIcon
.x
, rectIcon
.y
);
1454 if (item
->HasText())
1456 const wxRect
& rectLabel
= m_gi
->m_rectLabel
;
1458 wxDCClipper
clipper(*dc
, rectLabel
);
1459 dc
->DrawText(item
->GetText(), rectLabel
.x
, rectLabel
.y
);
1463 void wxListLineData::DrawInReportMode( wxDC
*dc
,
1465 const wxRect
& rectHL
,
1468 // TODO: later we should support setting different attributes for
1469 // different columns - to do it, just add "col" argument to
1470 // GetAttr() and move these lines into the loop below
1471 wxListItemAttr
*attr
= GetAttr();
1472 if ( SetAttributes(dc
, attr
, highlighted
) )
1473 dc
->DrawRectangle( rectHL
);
1475 wxCoord x
= rect
.x
+ HEADER_OFFSET_X
,
1476 yMid
= rect
.y
+ rect
.height
/2;
1479 for ( wxListItemDataList::compatibility_iterator node
= m_items
.GetFirst();
1481 node
= node
->GetNext(), col
++ )
1483 wxListItemData
*item
= node
->GetData();
1485 int width
= m_owner
->GetColumnWidth(col
);
1489 if ( item
->HasImage() )
1492 m_owner
->GetImageSize( item
->GetImage(), ix
, iy
);
1493 m_owner
->DrawImage( item
->GetImage(), dc
, xOld
, yMid
- iy
/2 );
1495 ix
+= IMAGE_MARGIN_IN_REPORT_MODE
;
1501 if ( item
->HasText() )
1502 DrawTextFormatted(dc
, item
->GetText(), col
, xOld
, yMid
, width
- 8);
1506 void wxListLineData::DrawTextFormatted(wxDC
*dc
,
1507 const wxString
&text
,
1514 dc
->GetTextExtent(text
, &w
, &h
);
1516 const wxCoord y
= yMid
- (h
+ 1)/2;
1518 wxDCClipper
clipper(*dc
, x
, y
, width
, h
);
1520 // determine if the string can fit inside the current width
1523 // it can, draw it using the items alignment
1525 m_owner
->GetColumn(col
, item
);
1526 switch ( item
.GetAlign() )
1528 case wxLIST_FORMAT_LEFT
:
1532 case wxLIST_FORMAT_RIGHT
:
1536 case wxLIST_FORMAT_CENTER
:
1537 x
+= (width
- w
) / 2;
1541 wxFAIL_MSG( _T("unknown list item format") );
1545 dc
->DrawText(text
, x
, y
);
1547 else // otherwise, truncate and add an ellipsis if possible
1549 // determine the base width
1550 wxString
ellipsis(wxT("..."));
1552 dc
->GetTextExtent(ellipsis
, &base_w
, &h
);
1554 // continue until we have enough space or only one character left
1556 size_t len
= text
.length();
1557 wxString drawntext
= text
.Left(len
);
1560 dc
->GetTextExtent(drawntext
.Last(), &w_c
, &h_c
);
1561 drawntext
.RemoveLast();
1564 if (w
+ base_w
<= width
)
1568 // if still not enough space, remove ellipsis characters
1569 while (ellipsis
.length() > 0 && w
+ base_w
> width
)
1571 ellipsis
= ellipsis
.Left(ellipsis
.length() - 1);
1572 dc
->GetTextExtent(ellipsis
, &base_w
, &h
);
1575 // now draw the text
1576 dc
->DrawText(drawntext
, x
, y
);
1577 dc
->DrawText(ellipsis
, x
+ w
, y
);
1581 bool wxListLineData::Highlight( bool on
)
1583 wxCHECK_MSG( !IsVirtual(), false, _T("unexpected call to Highlight") );
1585 if ( on
== m_highlighted
)
1593 void wxListLineData::ReverseHighlight( void )
1595 Highlight(!IsHighlighted());
1598 //-----------------------------------------------------------------------------
1599 // wxListHeaderWindow
1600 //-----------------------------------------------------------------------------
1602 IMPLEMENT_DYNAMIC_CLASS(wxListHeaderWindow
,wxWindow
)
1604 BEGIN_EVENT_TABLE(wxListHeaderWindow
,wxWindow
)
1605 EVT_PAINT (wxListHeaderWindow::OnPaint
)
1606 EVT_MOUSE_EVENTS (wxListHeaderWindow::OnMouse
)
1607 EVT_SET_FOCUS (wxListHeaderWindow::OnSetFocus
)
1610 void wxListHeaderWindow::Init()
1612 m_currentCursor
= (wxCursor
*) NULL
;
1613 m_isDragging
= false;
1617 wxListHeaderWindow::wxListHeaderWindow()
1621 m_owner
= (wxListMainWindow
*) NULL
;
1622 m_resizeCursor
= (wxCursor
*) NULL
;
1625 wxListHeaderWindow::wxListHeaderWindow( wxWindow
*win
,
1627 wxListMainWindow
*owner
,
1631 const wxString
&name
)
1632 : wxWindow( win
, id
, pos
, size
, style
, name
)
1637 m_resizeCursor
= new wxCursor( wxCURSOR_SIZEWE
);
1640 wxVisualAttributes attr
= wxPanel::GetClassDefaultAttributes();
1641 SetOwnForegroundColour( attr
.colFg
);
1642 SetOwnBackgroundColour( attr
.colBg
);
1644 SetOwnFont( attr
.font
);
1646 SetOwnForegroundColour( wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT
));
1647 SetOwnBackgroundColour( wxSystemSettings::GetColour(wxSYS_COLOUR_BTNFACE
));
1649 SetOwnFont( wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT
));
1653 wxListHeaderWindow::~wxListHeaderWindow()
1655 delete m_resizeCursor
;
1658 #ifdef __WXUNIVERSAL__
1659 #include "wx/univ/renderer.h"
1660 #include "wx/univ/theme.h"
1663 // shift the DC origin to match the position of the main window horz
1664 // scrollbar: this allows us to always use logical coords
1665 void wxListHeaderWindow::AdjustDC(wxDC
& dc
)
1668 m_owner
->GetScrollPixelsPerUnit( &xpix
, NULL
);
1671 m_owner
->GetViewStart( &view_start
, NULL
);
1676 dc
.GetDeviceOrigin( &org_x
, &org_y
);
1678 // account for the horz scrollbar offset
1680 if (GetLayoutDirection() == wxLayout_RightToLeft
)
1682 // Maybe we just have to check for m_signX
1683 // in the DC, but I leave the #ifdef __WXGTK__
1685 dc
.SetDeviceOrigin( org_x
+ (view_start
* xpix
), org_y
);
1689 dc
.SetDeviceOrigin( org_x
- (view_start
* xpix
), org_y
);
1692 void wxListHeaderWindow::OnPaint( wxPaintEvent
&WXUNUSED(event
) )
1694 wxPaintDC
dc( this );
1699 dc
.SetFont( GetFont() );
1701 // width and height of the entire header window
1703 GetClientSize( &w
, &h
);
1704 m_owner
->CalcUnscrolledPosition(w
, 0, &w
, NULL
);
1706 dc
.SetBackgroundMode(wxTRANSPARENT
);
1707 dc
.SetTextForeground(GetForegroundColour());
1709 int x
= HEADER_OFFSET_X
;
1710 int numColumns
= m_owner
->GetColumnCount();
1712 for ( int i
= 0; i
< numColumns
&& x
< w
; i
++ )
1714 m_owner
->GetColumn( i
, item
);
1715 int wCol
= item
.m_width
;
1717 // the width of the rect to draw: make it smaller to fit entirely
1718 // inside the column rect
1727 wxRendererNative::Get().DrawHeaderButton
1731 wxRect(x
, HEADER_OFFSET_Y
, cw
, ch
),
1732 m_parent
->IsEnabled() ? 0
1733 : (int)wxCONTROL_DISABLED
1736 // see if we have enough space for the column label
1738 // for this we need the width of the text
1741 dc
.GetTextExtent(item
.GetText(), &wLabel
, &hLabel
);
1742 wLabel
+= 2 * EXTRA_WIDTH
;
1744 // and the width of the icon, if any
1745 static const int MARGIN_BETWEEN_TEXT_AND_ICON
= 2;
1746 int ix
= 0, iy
= 0; // init them just to suppress the compiler warnings
1747 const int image
= item
.m_image
;
1748 wxImageList
*imageList
;
1751 imageList
= m_owner
->m_small_image_list
;
1754 imageList
->GetSize(image
, ix
, iy
);
1755 wLabel
+= ix
+ MARGIN_BETWEEN_TEXT_AND_ICON
;
1763 // ignore alignment if there is not enough space anyhow
1765 switch ( wLabel
< cw
? item
.GetAlign() : wxLIST_FORMAT_LEFT
)
1768 wxFAIL_MSG( _T("unknown list item format") );
1771 case wxLIST_FORMAT_LEFT
:
1775 case wxLIST_FORMAT_RIGHT
:
1776 xAligned
= x
+ cw
- wLabel
;
1779 case wxLIST_FORMAT_CENTER
:
1780 xAligned
= x
+ (cw
- wLabel
) / 2;
1784 // if we have an image, draw it on the right of the label
1791 xAligned
+ wLabel
- ix
- MARGIN_BETWEEN_TEXT_AND_ICON
,
1792 HEADER_OFFSET_Y
+ (h
- 4 - iy
)/2,
1793 wxIMAGELIST_DRAW_TRANSPARENT
1796 cw
-= ix
+ MARGIN_BETWEEN_TEXT_AND_ICON
;
1799 // draw the text clipping it so that it doesn't overwrite the column
1801 wxDCClipper
clipper(dc
, x
, HEADER_OFFSET_Y
, cw
, h
- 4 );
1803 dc
.DrawText( item
.GetText(),
1804 xAligned
+ EXTRA_WIDTH
, h
/ 2 - hLabel
/ 2 ); //HEADER_OFFSET_Y + EXTRA_HEIGHT );
1810 void wxListHeaderWindow::DrawCurrent()
1812 int x1
= m_currentX
;
1814 m_owner
->ClientToScreen( &x1
, &y1
);
1816 int x2
= m_currentX
;
1818 m_owner
->GetClientSize( NULL
, &y2
);
1819 m_owner
->ClientToScreen( &x2
, &y2
);
1822 dc
.SetLogicalFunction( wxINVERT
);
1823 dc
.SetPen( wxPen( *wxBLACK
, 2, wxSOLID
) );
1824 dc
.SetBrush( *wxTRANSPARENT_BRUSH
);
1828 dc
.DrawLine( x1
, y1
, x2
, y2
);
1830 dc
.SetLogicalFunction( wxCOPY
);
1832 dc
.SetPen( wxNullPen
);
1833 dc
.SetBrush( wxNullBrush
);
1836 void wxListHeaderWindow::OnMouse( wxMouseEvent
&event
)
1838 // we want to work with logical coords
1840 m_owner
->CalcUnscrolledPosition(event
.GetX(), 0, &x
, NULL
);
1841 int y
= event
.GetY();
1845 SendListEvent(wxEVT_COMMAND_LIST_COL_DRAGGING
, event
.GetPosition());
1847 // we don't draw the line beyond our window, but we allow dragging it
1850 GetClientSize( &w
, NULL
);
1851 m_owner
->CalcUnscrolledPosition(w
, 0, &w
, NULL
);
1854 // erase the line if it was drawn
1855 if ( m_currentX
< w
)
1858 if (event
.ButtonUp())
1861 m_isDragging
= false;
1863 m_owner
->SetColumnWidth( m_column
, m_currentX
- m_minX
);
1864 SendListEvent(wxEVT_COMMAND_LIST_COL_END_DRAG
, event
.GetPosition());
1871 m_currentX
= m_minX
+ 7;
1873 // draw in the new location
1874 if ( m_currentX
< w
)
1878 else // not dragging
1881 bool hit_border
= false;
1883 // end of the current column
1886 // find the column where this event occurred
1888 countCol
= m_owner
->GetColumnCount();
1889 for (col
= 0; col
< countCol
; col
++)
1891 xpos
+= m_owner
->GetColumnWidth( col
);
1894 if ( (abs(x
-xpos
) < 3) && (y
< 22) )
1896 // near the column border
1903 // inside the column
1910 if ( col
== countCol
)
1913 if (event
.LeftDown() || event
.RightUp())
1915 if (hit_border
&& event
.LeftDown())
1917 if ( SendListEvent(wxEVT_COMMAND_LIST_COL_BEGIN_DRAG
,
1918 event
.GetPosition()) )
1920 m_isDragging
= true;
1925 //else: column resizing was vetoed by the user code
1927 else // click on a column
1929 SendListEvent( event
.LeftDown()
1930 ? wxEVT_COMMAND_LIST_COL_CLICK
1931 : wxEVT_COMMAND_LIST_COL_RIGHT_CLICK
,
1932 event
.GetPosition());
1935 else if (event
.Moving())
1940 setCursor
= m_currentCursor
== wxSTANDARD_CURSOR
;
1941 m_currentCursor
= m_resizeCursor
;
1945 setCursor
= m_currentCursor
!= wxSTANDARD_CURSOR
;
1946 m_currentCursor
= wxSTANDARD_CURSOR
;
1950 SetCursor(*m_currentCursor
);
1955 void wxListHeaderWindow::OnSetFocus( wxFocusEvent
&WXUNUSED(event
) )
1957 m_owner
->SetFocus();
1961 bool wxListHeaderWindow::SendListEvent(wxEventType type
, const wxPoint
& pos
)
1963 wxWindow
*parent
= GetParent();
1964 wxListEvent
le( type
, parent
->GetId() );
1965 le
.SetEventObject( parent
);
1966 le
.m_pointDrag
= pos
;
1968 // the position should be relative to the parent window, not
1969 // this one for compatibility with MSW and common sense: the
1970 // user code doesn't know anything at all about this header
1971 // window, so why should it get positions relative to it?
1972 le
.m_pointDrag
.y
-= GetSize().y
;
1974 le
.m_col
= m_column
;
1975 return !parent
->GetEventHandler()->ProcessEvent( le
) || le
.IsAllowed();
1978 //-----------------------------------------------------------------------------
1979 // wxListRenameTimer (internal)
1980 //-----------------------------------------------------------------------------
1982 wxListRenameTimer::wxListRenameTimer( wxListMainWindow
*owner
)
1987 void wxListRenameTimer::Notify()
1989 m_owner
->OnRenameTimer();
1992 //-----------------------------------------------------------------------------
1993 // wxListTextCtrlWrapper (internal)
1994 //-----------------------------------------------------------------------------
1996 BEGIN_EVENT_TABLE(wxListTextCtrlWrapper
, wxEvtHandler
)
1997 EVT_CHAR (wxListTextCtrlWrapper::OnChar
)
1998 EVT_KEY_UP (wxListTextCtrlWrapper::OnKeyUp
)
1999 EVT_KILL_FOCUS (wxListTextCtrlWrapper::OnKillFocus
)
2002 wxListTextCtrlWrapper::wxListTextCtrlWrapper(wxListMainWindow
*owner
,
2005 : m_startValue(owner
->GetItemText(itemEdit
)),
2006 m_itemEdited(itemEdit
)
2011 m_aboutToFinish
= false;
2013 wxRect rectLabel
= owner
->GetLineLabelRect(itemEdit
);
2015 m_owner
->CalcScrolledPosition(rectLabel
.x
, rectLabel
.y
,
2016 &rectLabel
.x
, &rectLabel
.y
);
2018 m_text
->Create(owner
, wxID_ANY
, m_startValue
,
2019 wxPoint(rectLabel
.x
-4,rectLabel
.y
-4),
2020 wxSize(rectLabel
.width
+11,rectLabel
.height
+8));
2023 m_text
->PushEventHandler(this);
2026 void wxListTextCtrlWrapper::Finish()
2032 m_text
->RemoveEventHandler(this);
2033 m_owner
->FinishEditing(m_text
);
2035 wxPendingDelete
.Append( this );
2039 bool wxListTextCtrlWrapper::AcceptChanges()
2041 const wxString value
= m_text
->GetValue();
2043 if ( value
== m_startValue
)
2044 // nothing changed, always accept
2047 if ( !m_owner
->OnRenameAccept(m_itemEdited
, value
) )
2048 // vetoed by the user
2051 // accepted, do rename the item
2052 m_owner
->SetItemText(m_itemEdited
, value
);
2057 void wxListTextCtrlWrapper::AcceptChangesAndFinish()
2059 m_aboutToFinish
= true;
2061 // Notify the owner about the changes
2064 // Even if vetoed, close the control (consistent with MSW)
2068 void wxListTextCtrlWrapper::OnChar( wxKeyEvent
&event
)
2070 switch ( event
.m_keyCode
)
2073 AcceptChangesAndFinish();
2077 m_owner
->OnRenameCancelled( m_itemEdited
);
2086 void wxListTextCtrlWrapper::OnKeyUp( wxKeyEvent
&event
)
2094 // auto-grow the textctrl:
2095 wxSize parentSize
= m_owner
->GetSize();
2096 wxPoint myPos
= m_text
->GetPosition();
2097 wxSize mySize
= m_text
->GetSize();
2099 m_text
->GetTextExtent(m_text
->GetValue() + _T("MM"), &sx
, &sy
);
2100 if (myPos
.x
+ sx
> parentSize
.x
)
2101 sx
= parentSize
.x
- myPos
.x
;
2104 m_text
->SetSize(sx
, wxDefaultCoord
);
2109 void wxListTextCtrlWrapper::OnKillFocus( wxFocusEvent
&event
)
2111 if ( !m_finished
&& !m_aboutToFinish
)
2113 if ( !AcceptChanges() )
2114 m_owner
->OnRenameCancelled( m_itemEdited
);
2119 // We must let the native text control handle focus
2123 //-----------------------------------------------------------------------------
2125 //-----------------------------------------------------------------------------
2127 IMPLEMENT_DYNAMIC_CLASS(wxListMainWindow
,wxScrolledWindow
)
2129 BEGIN_EVENT_TABLE(wxListMainWindow
,wxScrolledWindow
)
2130 EVT_PAINT (wxListMainWindow::OnPaint
)
2131 EVT_MOUSE_EVENTS (wxListMainWindow::OnMouse
)
2132 EVT_CHAR (wxListMainWindow::OnChar
)
2133 EVT_KEY_DOWN (wxListMainWindow::OnKeyDown
)
2134 EVT_SET_FOCUS (wxListMainWindow::OnSetFocus
)
2135 EVT_KILL_FOCUS (wxListMainWindow::OnKillFocus
)
2136 EVT_SCROLLWIN (wxListMainWindow::OnScroll
)
2139 void wxListMainWindow::Init()
2144 m_lineTo
= (size_t)-1;
2150 m_small_image_list
= (wxImageList
*) NULL
;
2151 m_normal_image_list
= (wxImageList
*) NULL
;
2153 m_small_spacing
= 30;
2154 m_normal_spacing
= 40;
2158 m_isCreated
= false;
2160 m_lastOnSame
= false;
2161 m_renameTimer
= new wxListRenameTimer( this );
2162 m_textctrlWrapper
= NULL
;
2166 m_lineSelectSingleOnUp
=
2167 m_lineBeforeLastClicked
= (size_t)-1;
2172 wxListMainWindow::wxListMainWindow()
2177 m_highlightUnfocusedBrush
= (wxBrush
*) NULL
;
2180 wxListMainWindow::wxListMainWindow( wxWindow
*parent
,
2185 const wxString
&name
)
2186 : wxScrolledWindow( parent
, id
, pos
, size
,
2187 style
| wxHSCROLL
| wxVSCROLL
, name
)
2191 m_highlightBrush
= new wxBrush
2193 wxSystemSettings::GetColour
2195 wxSYS_COLOUR_HIGHLIGHT
2200 m_highlightUnfocusedBrush
= new wxBrush
2202 wxSystemSettings::GetColour
2204 wxSYS_COLOUR_BTNSHADOW
2209 SetScrollbars( 0, 0, 0, 0, 0, 0 );
2211 wxVisualAttributes attr
= wxGenericListCtrl::GetClassDefaultAttributes();
2212 SetOwnForegroundColour( attr
.colFg
);
2213 SetOwnBackgroundColour( attr
.colBg
);
2215 SetOwnFont( attr
.font
);
2218 wxListMainWindow::~wxListMainWindow()
2221 WX_CLEAR_LIST(wxListHeaderDataList
, m_columns
);
2222 WX_CLEAR_ARRAY(m_aColWidths
);
2224 delete m_highlightBrush
;
2225 delete m_highlightUnfocusedBrush
;
2226 delete m_renameTimer
;
2229 void wxListMainWindow::CacheLineData(size_t line
)
2231 wxGenericListCtrl
*listctrl
= GetListCtrl();
2233 wxListLineData
*ld
= GetDummyLine();
2235 size_t countCol
= GetColumnCount();
2236 for ( size_t col
= 0; col
< countCol
; col
++ )
2238 ld
->SetText(col
, listctrl
->OnGetItemText(line
, col
));
2239 ld
->SetImage(col
, listctrl
->OnGetItemColumnImage(line
, col
));
2242 ld
->SetAttr(listctrl
->OnGetItemAttr(line
));
2245 wxListLineData
*wxListMainWindow::GetDummyLine() const
2247 wxASSERT_MSG( !IsEmpty(), _T("invalid line index") );
2248 wxASSERT_MSG( IsVirtual(), _T("GetDummyLine() shouldn't be called") );
2250 wxListMainWindow
*self
= wxConstCast(this, wxListMainWindow
);
2252 // we need to recreate the dummy line if the number of columns in the
2253 // control changed as it would have the incorrect number of fields
2255 if ( !m_lines
.IsEmpty() &&
2256 m_lines
[0].m_items
.GetCount() != (size_t)GetColumnCount() )
2258 self
->m_lines
.Clear();
2261 if ( m_lines
.IsEmpty() )
2263 wxListLineData
*line
= new wxListLineData(self
);
2264 self
->m_lines
.Add(line
);
2266 // don't waste extra memory -- there never going to be anything
2267 // else/more in this array
2268 self
->m_lines
.Shrink();
2274 // ----------------------------------------------------------------------------
2275 // line geometry (report mode only)
2276 // ----------------------------------------------------------------------------
2278 wxCoord
wxListMainWindow::GetLineHeight() const
2280 // we cache the line height as calling GetTextExtent() is slow
2281 if ( !m_lineHeight
)
2283 wxListMainWindow
*self
= wxConstCast(this, wxListMainWindow
);
2285 wxClientDC
dc( self
);
2286 dc
.SetFont( GetFont() );
2289 dc
.GetTextExtent(_T("H"), NULL
, &y
);
2291 if ( m_small_image_list
&& m_small_image_list
->GetImageCount() )
2294 m_small_image_list
->GetSize(0, iw
, ih
);
2299 self
->m_lineHeight
= y
+ LINE_SPACING
;
2302 return m_lineHeight
;
2305 wxCoord
wxListMainWindow::GetLineY(size_t line
) const
2307 wxASSERT_MSG( InReportView(), _T("only works in report mode") );
2309 return LINE_SPACING
+ line
* GetLineHeight();
2312 wxRect
wxListMainWindow::GetLineRect(size_t line
) const
2314 if ( !InReportView() )
2315 return GetLine(line
)->m_gi
->m_rectAll
;
2318 rect
.x
= HEADER_OFFSET_X
;
2319 rect
.y
= GetLineY(line
);
2320 rect
.width
= GetHeaderWidth();
2321 rect
.height
= GetLineHeight();
2326 wxRect
wxListMainWindow::GetLineLabelRect(size_t line
) const
2328 if ( !InReportView() )
2329 return GetLine(line
)->m_gi
->m_rectLabel
;
2332 rect
.x
= HEADER_OFFSET_X
;
2333 rect
.y
= GetLineY(line
);
2334 rect
.width
= GetColumnWidth(0);
2335 rect
.height
= GetLineHeight();
2340 wxRect
wxListMainWindow::GetLineIconRect(size_t line
) const
2342 if ( !InReportView() )
2343 return GetLine(line
)->m_gi
->m_rectIcon
;
2345 wxListLineData
*ld
= GetLine(line
);
2346 wxASSERT_MSG( ld
->HasImage(), _T("should have an image") );
2349 rect
.x
= HEADER_OFFSET_X
;
2350 rect
.y
= GetLineY(line
);
2351 GetImageSize(ld
->GetImage(), rect
.width
, rect
.height
);
2356 wxRect
wxListMainWindow::GetLineHighlightRect(size_t line
) const
2358 return InReportView() ? GetLineRect(line
)
2359 : GetLine(line
)->m_gi
->m_rectHighlight
;
2362 long wxListMainWindow::HitTestLine(size_t line
, int x
, int y
) const
2364 wxASSERT_MSG( line
< GetItemCount(), _T("invalid line in HitTestLine") );
2366 wxListLineData
*ld
= GetLine(line
);
2368 if ( ld
->HasImage() && GetLineIconRect(line
).Contains(x
, y
) )
2369 return wxLIST_HITTEST_ONITEMICON
;
2371 // VS: Testing for "ld->HasText() || InReportView()" instead of
2372 // "ld->HasText()" is needed to make empty lines in report view
2374 if ( ld
->HasText() || InReportView() )
2376 wxRect rect
= InReportView() ? GetLineRect(line
)
2377 : GetLineLabelRect(line
);
2379 if ( rect
.Contains(x
, y
) )
2380 return wxLIST_HITTEST_ONITEMLABEL
;
2386 // ----------------------------------------------------------------------------
2387 // highlight (selection) handling
2388 // ----------------------------------------------------------------------------
2390 bool wxListMainWindow::IsHighlighted(size_t line
) const
2394 return m_selStore
.IsSelected(line
);
2398 wxListLineData
*ld
= GetLine(line
);
2399 wxCHECK_MSG( ld
, false, _T("invalid index in IsHighlighted") );
2401 return ld
->IsHighlighted();
2405 void wxListMainWindow::HighlightLines( size_t lineFrom
,
2411 wxArrayInt linesChanged
;
2412 if ( !m_selStore
.SelectRange(lineFrom
, lineTo
, highlight
,
2415 // meny items changed state, refresh everything
2416 RefreshLines(lineFrom
, lineTo
);
2418 else // only a few items changed state, refresh only them
2420 size_t count
= linesChanged
.GetCount();
2421 for ( size_t n
= 0; n
< count
; n
++ )
2423 RefreshLine(linesChanged
[n
]);
2427 else // iterate over all items in non report view
2429 for ( size_t line
= lineFrom
; line
<= lineTo
; line
++ )
2431 if ( HighlightLine(line
, highlight
) )
2437 bool wxListMainWindow::HighlightLine( size_t line
, bool highlight
)
2443 changed
= m_selStore
.SelectItem(line
, highlight
);
2447 wxListLineData
*ld
= GetLine(line
);
2448 wxCHECK_MSG( ld
, false, _T("invalid index in HighlightLine") );
2450 changed
= ld
->Highlight(highlight
);
2455 SendNotify( line
, highlight
? wxEVT_COMMAND_LIST_ITEM_SELECTED
2456 : wxEVT_COMMAND_LIST_ITEM_DESELECTED
);
2462 void wxListMainWindow::RefreshLine( size_t line
)
2464 if ( InReportView() )
2466 size_t visibleFrom
, visibleTo
;
2467 GetVisibleLinesRange(&visibleFrom
, &visibleTo
);
2469 if ( line
< visibleFrom
|| line
> visibleTo
)
2473 wxRect rect
= GetLineRect(line
);
2475 CalcScrolledPosition( rect
.x
, rect
.y
, &rect
.x
, &rect
.y
);
2476 RefreshRect( rect
);
2479 void wxListMainWindow::RefreshLines( size_t lineFrom
, size_t lineTo
)
2481 // we suppose that they are ordered by caller
2482 wxASSERT_MSG( lineFrom
<= lineTo
, _T("indices in disorder") );
2484 wxASSERT_MSG( lineTo
< GetItemCount(), _T("invalid line range") );
2486 if ( InReportView() )
2488 size_t visibleFrom
, visibleTo
;
2489 GetVisibleLinesRange(&visibleFrom
, &visibleTo
);
2491 if ( lineFrom
< visibleFrom
)
2492 lineFrom
= visibleFrom
;
2493 if ( lineTo
> visibleTo
)
2498 rect
.y
= GetLineY(lineFrom
);
2499 rect
.width
= GetClientSize().x
;
2500 rect
.height
= GetLineY(lineTo
) - rect
.y
+ GetLineHeight();
2502 CalcScrolledPosition( rect
.x
, rect
.y
, &rect
.x
, &rect
.y
);
2503 RefreshRect( rect
);
2507 // TODO: this should be optimized...
2508 for ( size_t line
= lineFrom
; line
<= lineTo
; line
++ )
2515 void wxListMainWindow::RefreshAfter( size_t lineFrom
)
2517 if ( InReportView() )
2519 size_t visibleFrom
, visibleTo
;
2520 GetVisibleLinesRange(&visibleFrom
, &visibleTo
);
2522 if ( lineFrom
< visibleFrom
)
2523 lineFrom
= visibleFrom
;
2524 else if ( lineFrom
> visibleTo
)
2529 rect
.y
= GetLineY(lineFrom
);
2530 CalcScrolledPosition( rect
.x
, rect
.y
, &rect
.x
, &rect
.y
);
2532 wxSize size
= GetClientSize();
2533 rect
.width
= size
.x
;
2535 // refresh till the bottom of the window
2536 rect
.height
= size
.y
- rect
.y
;
2538 RefreshRect( rect
);
2542 // TODO: how to do it more efficiently?
2547 void wxListMainWindow::RefreshSelected()
2553 if ( InReportView() )
2555 GetVisibleLinesRange(&from
, &to
);
2560 to
= GetItemCount() - 1;
2563 if ( HasCurrent() && m_current
>= from
&& m_current
<= to
)
2564 RefreshLine(m_current
);
2566 for ( size_t line
= from
; line
<= to
; line
++ )
2568 // NB: the test works as expected even if m_current == -1
2569 if ( line
!= m_current
&& IsHighlighted(line
) )
2574 void wxListMainWindow::Freeze()
2579 void wxListMainWindow::Thaw()
2581 wxCHECK_RET( m_freezeCount
> 0, _T("thawing unfrozen list control?") );
2583 if ( --m_freezeCount
== 0 )
2587 void wxListMainWindow::OnPaint( wxPaintEvent
&WXUNUSED(event
) )
2589 // Note: a wxPaintDC must be constructed even if no drawing is
2590 // done (a Windows requirement).
2591 wxPaintDC
dc( this );
2593 if ( IsEmpty() || m_freezeCount
)
2594 // nothing to draw or not the moment to draw it
2598 // delay the repainting until we calculate all the items positions
2604 CalcScrolledPosition( 0, 0, &dev_x
, &dev_y
);
2606 dc
.SetFont( GetFont() );
2608 if ( InReportView() )
2610 int lineHeight
= GetLineHeight();
2612 size_t visibleFrom
, visibleTo
;
2613 GetVisibleLinesRange(&visibleFrom
, &visibleTo
);
2616 int xOrig
= dc
.LogicalToDeviceX( 0 );
2617 int yOrig
= dc
.LogicalToDeviceY( 0 );
2619 // tell the caller cache to cache the data
2622 wxListEvent
evCache(wxEVT_COMMAND_LIST_CACHE_HINT
,
2623 GetParent()->GetId());
2624 evCache
.SetEventObject( GetParent() );
2625 evCache
.m_oldItemIndex
= visibleFrom
;
2626 evCache
.m_itemIndex
= visibleTo
;
2627 GetParent()->GetEventHandler()->ProcessEvent( evCache
);
2630 for ( size_t line
= visibleFrom
; line
<= visibleTo
; line
++ )
2632 rectLine
= GetLineRect(line
);
2635 if ( !IsExposed(rectLine
.x
+ xOrig
, rectLine
.y
+ yOrig
,
2636 rectLine
.width
, rectLine
.height
) )
2638 // don't redraw unaffected lines to avoid flicker
2642 GetLine(line
)->DrawInReportMode( &dc
,
2644 GetLineHighlightRect(line
),
2645 IsHighlighted(line
) );
2648 if ( HasFlag(wxLC_HRULES
) )
2650 wxPen
pen(GetRuleColour(), 1, wxSOLID
);
2651 wxSize clientSize
= GetClientSize();
2653 // Don't draw the first one
2654 for ( size_t i
= visibleFrom
+ 1; i
<= visibleTo
; i
++ )
2657 dc
.SetBrush( *wxTRANSPARENT_BRUSH
);
2658 dc
.DrawLine(0 - dev_x
, i
* lineHeight
,
2659 clientSize
.x
- dev_x
, i
* lineHeight
);
2662 // Draw last horizontal rule
2663 if ( visibleTo
== GetItemCount() - 1 )
2666 dc
.SetBrush( *wxTRANSPARENT_BRUSH
);
2667 dc
.DrawLine(0 - dev_x
, (m_lineTo
+ 1) * lineHeight
,
2668 clientSize
.x
- dev_x
, (m_lineTo
+ 1) * lineHeight
);
2672 // Draw vertical rules if required
2673 if ( HasFlag(wxLC_VRULES
) && !IsEmpty() )
2675 wxPen
pen(GetRuleColour(), 1, wxSOLID
);
2676 wxRect firstItemRect
, lastItemRect
;
2678 GetItemRect(visibleFrom
, firstItemRect
);
2679 GetItemRect(visibleTo
, lastItemRect
);
2680 int x
= firstItemRect
.GetX();
2682 dc
.SetBrush(* wxTRANSPARENT_BRUSH
);
2684 for (int col
= 0; col
< GetColumnCount(); col
++)
2686 int colWidth
= GetColumnWidth(col
);
2688 dc
.DrawLine(x
- dev_x
- 2, firstItemRect
.GetY() - 1 - dev_y
,
2689 x
- dev_x
- 2, lastItemRect
.GetBottom() + 1 - dev_y
);
2695 size_t count
= GetItemCount();
2696 for ( size_t i
= 0; i
< count
; i
++ )
2698 GetLine(i
)->Draw( &dc
);
2703 // Don't draw rect outline under Mac at all.
2708 dc
.SetPen( *wxBLACK_PEN
);
2709 dc
.SetBrush( *wxTRANSPARENT_BRUSH
);
2710 dc
.DrawRectangle( GetLineHighlightRect( m_current
) );
2716 void wxListMainWindow::HighlightAll( bool on
)
2718 if ( IsSingleSel() )
2720 wxASSERT_MSG( !on
, _T("can't do this in a single selection control") );
2722 // we just have one item to turn off
2723 if ( HasCurrent() && IsHighlighted(m_current
) )
2725 HighlightLine(m_current
, false);
2726 RefreshLine(m_current
);
2731 HighlightLines(0, GetItemCount() - 1, on
);
2735 void wxListMainWindow::SendNotify( size_t line
,
2736 wxEventType command
,
2737 const wxPoint
& point
)
2739 wxListEvent
le( command
, GetParent()->GetId() );
2740 le
.SetEventObject( GetParent() );
2741 le
.m_itemIndex
= line
;
2743 // set only for events which have position
2744 if ( point
!= wxDefaultPosition
)
2745 le
.m_pointDrag
= point
;
2747 // don't try to get the line info for virtual list controls: the main
2748 // program has it anyhow and if we did it would result in accessing all
2749 // the lines, even those which are not visible now and this is precisely
2750 // what we're trying to avoid
2751 if ( !IsVirtual() && (command
!= wxEVT_COMMAND_LIST_DELETE_ITEM
) )
2753 if ( line
!= (size_t)-1 )
2755 GetLine(line
)->GetItem( 0, le
.m_item
);
2757 //else: this happens for wxEVT_COMMAND_LIST_ITEM_FOCUSED event
2759 //else: there may be no more such item
2761 GetParent()->GetEventHandler()->ProcessEvent( le
);
2764 void wxListMainWindow::ChangeCurrent(size_t current
)
2766 m_current
= current
;
2768 SendNotify(current
, wxEVT_COMMAND_LIST_ITEM_FOCUSED
);
2771 wxTextCtrl
*wxListMainWindow::EditLabel(long item
, wxClassInfo
* textControlClass
)
2773 wxCHECK_MSG( (item
>= 0) && ((size_t)item
< GetItemCount()), NULL
,
2774 wxT("wrong index in wxGenericListCtrl::EditLabel()") );
2776 wxASSERT_MSG( textControlClass
->IsKindOf(CLASSINFO(wxTextCtrl
)),
2777 wxT("EditLabel() needs a text control") );
2779 size_t itemEdit
= (size_t)item
;
2781 wxListEvent
le( wxEVT_COMMAND_LIST_BEGIN_LABEL_EDIT
, GetParent()->GetId() );
2782 le
.SetEventObject( GetParent() );
2783 le
.m_itemIndex
= item
;
2784 wxListLineData
*data
= GetLine(itemEdit
);
2785 wxCHECK_MSG( data
, NULL
, _T("invalid index in EditLabel()") );
2786 data
->GetItem( 0, le
.m_item
);
2788 if ( GetParent()->GetEventHandler()->ProcessEvent( le
) && !le
.IsAllowed() )
2790 // vetoed by user code
2794 // We have to call this here because the label in question might just have
2795 // been added and no screen update taken place.
2799 wxTextCtrl
* const text
= (wxTextCtrl
*)textControlClass
->CreateObject();
2800 m_textctrlWrapper
= new wxListTextCtrlWrapper(this, text
, item
);
2801 return m_textctrlWrapper
->GetText();
2804 void wxListMainWindow::OnRenameTimer()
2806 wxCHECK_RET( HasCurrent(), wxT("unexpected rename timer") );
2808 EditLabel( m_current
);
2811 bool wxListMainWindow::OnRenameAccept(size_t itemEdit
, const wxString
& value
)
2813 wxListEvent
le( wxEVT_COMMAND_LIST_END_LABEL_EDIT
, GetParent()->GetId() );
2814 le
.SetEventObject( GetParent() );
2815 le
.m_itemIndex
= itemEdit
;
2817 wxListLineData
*data
= GetLine(itemEdit
);
2819 wxCHECK_MSG( data
, false, _T("invalid index in OnRenameAccept()") );
2821 data
->GetItem( 0, le
.m_item
);
2822 le
.m_item
.m_text
= value
;
2823 return !GetParent()->GetEventHandler()->ProcessEvent( le
) ||
2827 void wxListMainWindow::OnRenameCancelled(size_t itemEdit
)
2829 // let owner know that the edit was cancelled
2830 wxListEvent
le( wxEVT_COMMAND_LIST_END_LABEL_EDIT
, GetParent()->GetId() );
2832 le
.SetEditCanceled(true);
2834 le
.SetEventObject( GetParent() );
2835 le
.m_itemIndex
= itemEdit
;
2837 wxListLineData
*data
= GetLine(itemEdit
);
2838 wxCHECK_RET( data
, _T("invalid index in OnRenameCancelled()") );
2840 data
->GetItem( 0, le
.m_item
);
2841 GetEventHandler()->ProcessEvent( le
);
2844 void wxListMainWindow::OnMouse( wxMouseEvent
&event
)
2848 // On wxMac we can't depend on the EVT_KILL_FOCUS event to properly
2849 // shutdown the edit control when the mouse is clicked elsewhere on the
2850 // listctrl because the order of events is different (or something like
2851 // that), so explicitly end the edit if it is active.
2852 if ( event
.LeftDown() && m_textctrlWrapper
)
2853 m_textctrlWrapper
->AcceptChangesAndFinish();
2856 event
.SetEventObject( GetParent() );
2857 if ( GetParent()->GetEventHandler()->ProcessEvent( event
) )
2860 if (event
.GetEventType() == wxEVT_MOUSEWHEEL
)
2862 // let the base handle mouse wheel events.
2867 if ( !HasCurrent() || IsEmpty() )
2869 if (event
.RightDown())
2871 SendNotify( (size_t)-1, wxEVT_COMMAND_LIST_ITEM_RIGHT_CLICK
, event
.GetPosition() );
2872 // Allow generation of context menu event
2881 if ( !(event
.Dragging() || event
.ButtonDown() || event
.LeftUp() ||
2882 event
.ButtonDClick()) )
2885 int x
= event
.GetX();
2886 int y
= event
.GetY();
2887 CalcUnscrolledPosition( x
, y
, &x
, &y
);
2889 // where did we hit it (if we did)?
2892 size_t count
= GetItemCount(),
2895 if ( InReportView() )
2897 current
= y
/ GetLineHeight();
2898 if ( current
< count
)
2899 hitResult
= HitTestLine(current
, x
, y
);
2903 // TODO: optimize it too! this is less simple than for report view but
2904 // enumerating all items is still not a way to do it!!
2905 for ( current
= 0; current
< count
; current
++ )
2907 hitResult
= HitTestLine(current
, x
, y
);
2913 if (event
.Dragging())
2915 if (m_dragCount
== 0)
2917 // we have to report the raw, physical coords as we want to be
2918 // able to call HitTest(event.m_pointDrag) from the user code to
2919 // get the item being dragged
2920 m_dragStart
= event
.GetPosition();
2925 if (m_dragCount
!= 3)
2928 int command
= event
.RightIsDown() ? wxEVT_COMMAND_LIST_BEGIN_RDRAG
2929 : wxEVT_COMMAND_LIST_BEGIN_DRAG
;
2931 wxListEvent
le( command
, GetParent()->GetId() );
2932 le
.SetEventObject( GetParent() );
2933 le
.m_itemIndex
= m_lineLastClicked
;
2934 le
.m_pointDrag
= m_dragStart
;
2935 GetParent()->GetEventHandler()->ProcessEvent( le
);
2946 // outside of any item
2947 if (event
.RightDown())
2949 SendNotify( (size_t) -1, wxEVT_COMMAND_LIST_ITEM_RIGHT_CLICK
, event
.GetPosition() );
2950 // Allow generation of context menu event
2955 // reset the selection and bail out
2956 HighlightAll(false);
2962 bool forceClick
= false;
2963 if (event
.ButtonDClick())
2965 m_renameTimer
->Stop();
2966 m_lastOnSame
= false;
2968 if ( current
== m_lineLastClicked
)
2970 SendNotify( current
, wxEVT_COMMAND_LIST_ITEM_ACTIVATED
);
2976 // The first click was on another item, so don't interpret this as
2977 // a double click, but as a simple click instead
2984 if (m_lineSelectSingleOnUp
!= (size_t)-1)
2986 // select single line
2987 HighlightAll( false );
2988 ReverseHighlight(m_lineSelectSingleOnUp
);
2993 if ((current
== m_current
) &&
2994 (hitResult
== wxLIST_HITTEST_ONITEMLABEL
) &&
2995 HasFlag(wxLC_EDIT_LABELS
) )
2997 m_renameTimer
->Start( 100, true );
3001 m_lastOnSame
= false;
3002 m_lineSelectSingleOnUp
= (size_t)-1;
3006 // This is necessary, because after a DnD operation in
3007 // from and to ourself, the up event is swallowed by the
3008 // DnD code. So on next non-up event (which means here and
3009 // now) m_lineSelectSingleOnUp should be reset.
3010 m_lineSelectSingleOnUp
= (size_t)-1;
3012 if (event
.RightDown())
3014 m_lineBeforeLastClicked
= m_lineLastClicked
;
3015 m_lineLastClicked
= current
;
3017 // If the item is already selected, do not update the selection.
3018 // Multi-selections should not be cleared if a selected item is clicked.
3019 if (!IsHighlighted(current
))
3021 HighlightAll(false);
3022 ChangeCurrent(current
);
3023 ReverseHighlight(m_current
);
3026 SendNotify( current
, wxEVT_COMMAND_LIST_ITEM_RIGHT_CLICK
, event
.GetPosition() );
3028 // Allow generation of context menu event
3031 else if (event
.MiddleDown())
3033 SendNotify( current
, wxEVT_COMMAND_LIST_ITEM_MIDDLE_CLICK
);
3035 else if ( event
.LeftDown() || forceClick
)
3037 m_lineBeforeLastClicked
= m_lineLastClicked
;
3038 m_lineLastClicked
= current
;
3040 size_t oldCurrent
= m_current
;
3041 bool oldWasSelected
= IsHighlighted(m_current
);
3043 bool cmdModifierDown
= event
.CmdDown();
3044 if ( IsSingleSel() || !(cmdModifierDown
|| event
.ShiftDown()) )
3046 if ( IsSingleSel() || !IsHighlighted(current
) )
3048 HighlightAll( false );
3050 ChangeCurrent(current
);
3052 ReverseHighlight(m_current
);
3054 else // multi sel & current is highlighted & no mod keys
3056 m_lineSelectSingleOnUp
= current
;
3057 ChangeCurrent(current
); // change focus
3060 else // multi sel & either ctrl or shift is down
3062 if (cmdModifierDown
)
3064 ChangeCurrent(current
);
3066 ReverseHighlight(m_current
);
3068 else if (event
.ShiftDown())
3070 ChangeCurrent(current
);
3072 size_t lineFrom
= oldCurrent
,
3075 if ( lineTo
< lineFrom
)
3078 lineFrom
= m_current
;
3081 HighlightLines(lineFrom
, lineTo
);
3083 else // !ctrl, !shift
3085 // test in the enclosing if should make it impossible
3086 wxFAIL_MSG( _T("how did we get here?") );
3090 if (m_current
!= oldCurrent
)
3091 RefreshLine( oldCurrent
);
3093 // forceClick is only set if the previous click was on another item
3094 m_lastOnSame
= !forceClick
&& (m_current
== oldCurrent
) && oldWasSelected
;
3098 void wxListMainWindow::MoveToItem(size_t item
)
3100 if ( item
== (size_t)-1 )
3103 wxRect rect
= GetLineRect(item
);
3105 int client_w
, client_h
;
3106 GetClientSize( &client_w
, &client_h
);
3108 const int hLine
= GetLineHeight();
3110 int view_x
= SCROLL_UNIT_X
* GetScrollPos( wxHORIZONTAL
);
3111 int view_y
= hLine
* GetScrollPos( wxVERTICAL
);
3113 if ( InReportView() )
3115 // the next we need the range of lines shown it might be different,
3116 // so recalculate it
3117 ResetVisibleLinesRange();
3119 if (rect
.y
< view_y
)
3120 Scroll( -1, rect
.y
/ hLine
);
3121 if (rect
.y
+ rect
.height
+ 5 > view_y
+ client_h
)
3122 Scroll( -1, (rect
.y
+ rect
.height
- client_h
+ hLine
) / hLine
);
3126 if (rect
.x
-view_x
< 5)
3127 Scroll( (rect
.x
- 5) / SCROLL_UNIT_X
, -1 );
3128 if (rect
.x
+ rect
.width
- 5 > view_x
+ client_w
)
3129 Scroll( (rect
.x
+ rect
.width
- client_w
+ SCROLL_UNIT_X
) / SCROLL_UNIT_X
, -1 );
3133 // ----------------------------------------------------------------------------
3134 // keyboard handling
3135 // ----------------------------------------------------------------------------
3137 void wxListMainWindow::OnArrowChar(size_t newCurrent
, const wxKeyEvent
& event
)
3139 wxCHECK_RET( newCurrent
< (size_t)GetItemCount(),
3140 _T("invalid item index in OnArrowChar()") );
3142 size_t oldCurrent
= m_current
;
3144 // in single selection we just ignore Shift as we can't select several
3146 if ( event
.ShiftDown() && !IsSingleSel() )
3148 ChangeCurrent(newCurrent
);
3150 // refresh the old focus to remove it
3151 RefreshLine( oldCurrent
);
3153 // select all the items between the old and the new one
3154 if ( oldCurrent
> newCurrent
)
3156 newCurrent
= oldCurrent
;
3157 oldCurrent
= m_current
;
3160 HighlightLines(oldCurrent
, newCurrent
);
3164 // all previously selected items are unselected unless ctrl is held
3165 if ( !event
.ControlDown() )
3166 HighlightAll(false);
3168 ChangeCurrent(newCurrent
);
3170 // refresh the old focus to remove it
3171 RefreshLine( oldCurrent
);
3173 if ( !event
.ControlDown() )
3175 HighlightLine( m_current
, true );
3179 RefreshLine( m_current
);
3184 void wxListMainWindow::OnKeyDown( wxKeyEvent
&event
)
3186 wxWindow
*parent
= GetParent();
3188 // propagate the key event upwards
3189 wxKeyEvent
ke( wxEVT_KEY_DOWN
);
3190 ke
.m_shiftDown
= event
.m_shiftDown
;
3191 ke
.m_controlDown
= event
.m_controlDown
;
3192 ke
.m_altDown
= event
.m_altDown
;
3193 ke
.m_metaDown
= event
.m_metaDown
;
3194 ke
.m_keyCode
= event
.m_keyCode
;
3197 ke
.SetEventObject( parent
);
3198 if (parent
->GetEventHandler()->ProcessEvent( ke
)) return;
3203 void wxListMainWindow::OnChar( wxKeyEvent
&event
)
3205 wxWindow
*parent
= GetParent();
3207 // send a list_key event up
3210 wxListEvent
le( wxEVT_COMMAND_LIST_KEY_DOWN
, GetParent()->GetId() );
3211 le
.m_itemIndex
= m_current
;
3212 GetLine(m_current
)->GetItem( 0, le
.m_item
);
3213 le
.m_code
= event
.GetKeyCode();
3214 le
.SetEventObject( parent
);
3215 parent
->GetEventHandler()->ProcessEvent( le
);
3218 // propagate the char event upwards
3219 wxKeyEvent
ke( wxEVT_CHAR
);
3220 ke
.m_shiftDown
= event
.m_shiftDown
;
3221 ke
.m_controlDown
= event
.m_controlDown
;
3222 ke
.m_altDown
= event
.m_altDown
;
3223 ke
.m_metaDown
= event
.m_metaDown
;
3224 ke
.m_keyCode
= event
.m_keyCode
;
3227 ke
.SetEventObject( parent
);
3228 if (parent
->GetEventHandler()->ProcessEvent( ke
)) return;
3230 if (event
.GetKeyCode() == WXK_TAB
)
3232 wxNavigationKeyEvent nevent
;
3233 nevent
.SetWindowChange( event
.ControlDown() );
3234 nevent
.SetDirection( !event
.ShiftDown() );
3235 nevent
.SetEventObject( GetParent()->GetParent() );
3236 nevent
.SetCurrentFocus( m_parent
);
3237 if (GetParent()->GetParent()->GetEventHandler()->ProcessEvent( nevent
))
3241 // no item -> nothing to do
3248 // don't use m_linesPerPage directly as it might not be computed yet
3249 const int pageSize
= GetCountPerPage();
3250 wxCHECK_RET( pageSize
, _T("should have non zero page size") );
3252 if (GetLayoutDirection() == wxLayout_RightToLeft
)
3254 if (event
.GetKeyCode() == WXK_RIGHT
)
3255 event
.m_keyCode
= WXK_LEFT
;
3256 else if (event
.GetKeyCode() == WXK_LEFT
)
3257 event
.m_keyCode
= WXK_RIGHT
;
3260 switch ( event
.GetKeyCode() )
3263 if ( m_current
> 0 )
3264 OnArrowChar( m_current
- 1, event
);
3268 if ( m_current
< (size_t)GetItemCount() - 1 )
3269 OnArrowChar( m_current
+ 1, event
);
3274 OnArrowChar( GetItemCount() - 1, event
);
3279 OnArrowChar( 0, event
);
3284 int steps
= InReportView() ? pageSize
- 1
3285 : m_current
% pageSize
;
3287 int index
= m_current
- steps
;
3291 OnArrowChar( index
, event
);
3297 int steps
= InReportView()
3299 : pageSize
- (m_current
% pageSize
) - 1;
3301 size_t index
= m_current
+ steps
;
3302 size_t count
= GetItemCount();
3303 if ( index
>= count
)
3306 OnArrowChar( index
, event
);
3311 if ( !InReportView() )
3313 int index
= m_current
- pageSize
;
3317 OnArrowChar( index
, event
);
3322 if ( !InReportView() )
3324 size_t index
= m_current
+ pageSize
;
3326 size_t count
= GetItemCount();
3327 if ( index
>= count
)
3330 OnArrowChar( index
, event
);
3335 if ( IsSingleSel() )
3337 SendNotify( m_current
, wxEVT_COMMAND_LIST_ITEM_ACTIVATED
);
3339 if ( IsHighlighted(m_current
) )
3341 // don't unselect the item in single selection mode
3344 //else: select it in ReverseHighlight() below if unselected
3347 ReverseHighlight(m_current
);
3352 SendNotify( m_current
, wxEVT_COMMAND_LIST_ITEM_ACTIVATED
);
3360 // ----------------------------------------------------------------------------
3362 // ----------------------------------------------------------------------------
3364 void wxListMainWindow::OnSetFocus( wxFocusEvent
&WXUNUSED(event
) )
3368 wxFocusEvent
event( wxEVT_SET_FOCUS
, GetParent()->GetId() );
3369 event
.SetEventObject( GetParent() );
3370 if ( GetParent()->GetEventHandler()->ProcessEvent( event
) )
3374 // wxGTK sends us EVT_SET_FOCUS events even if we had never got
3375 // EVT_KILL_FOCUS before which means that we finish by redrawing the items
3376 // which are already drawn correctly resulting in horrible flicker - avoid
3386 void wxListMainWindow::OnKillFocus( wxFocusEvent
&WXUNUSED(event
) )
3390 wxFocusEvent
event( wxEVT_KILL_FOCUS
, GetParent()->GetId() );
3391 event
.SetEventObject( GetParent() );
3392 if ( GetParent()->GetEventHandler()->ProcessEvent( event
) )
3400 void wxListMainWindow::DrawImage( int index
, wxDC
*dc
, int x
, int y
)
3402 if ( HasFlag(wxLC_ICON
) && (m_normal_image_list
))
3404 m_normal_image_list
->Draw( index
, *dc
, x
, y
, wxIMAGELIST_DRAW_TRANSPARENT
);
3406 else if ( HasFlag(wxLC_SMALL_ICON
) && (m_small_image_list
))
3408 m_small_image_list
->Draw( index
, *dc
, x
, y
, wxIMAGELIST_DRAW_TRANSPARENT
);
3410 else if ( HasFlag(wxLC_LIST
) && (m_small_image_list
))
3412 m_small_image_list
->Draw( index
, *dc
, x
, y
, wxIMAGELIST_DRAW_TRANSPARENT
);
3414 else if ( InReportView() && (m_small_image_list
))
3416 m_small_image_list
->Draw( index
, *dc
, x
, y
, wxIMAGELIST_DRAW_TRANSPARENT
);
3420 void wxListMainWindow::GetImageSize( int index
, int &width
, int &height
) const
3422 if ( HasFlag(wxLC_ICON
) && m_normal_image_list
)
3424 m_normal_image_list
->GetSize( index
, width
, height
);
3426 else if ( HasFlag(wxLC_SMALL_ICON
) && m_small_image_list
)
3428 m_small_image_list
->GetSize( index
, width
, height
);
3430 else if ( HasFlag(wxLC_LIST
) && m_small_image_list
)
3432 m_small_image_list
->GetSize( index
, width
, height
);
3434 else if ( InReportView() && m_small_image_list
)
3436 m_small_image_list
->GetSize( index
, width
, height
);
3445 int wxListMainWindow::GetTextLength( const wxString
&s
) const
3447 wxClientDC
dc( wxConstCast(this, wxListMainWindow
) );
3448 dc
.SetFont( GetFont() );
3451 dc
.GetTextExtent( s
, &lw
, NULL
);
3453 return lw
+ AUTOSIZE_COL_MARGIN
;
3456 void wxListMainWindow::SetImageList( wxImageList
*imageList
, int which
)
3460 // calc the spacing from the icon size
3461 int width
= 0, height
= 0;
3463 if ((imageList
) && (imageList
->GetImageCount()) )
3464 imageList
->GetSize(0, width
, height
);
3466 if (which
== wxIMAGE_LIST_NORMAL
)
3468 m_normal_image_list
= imageList
;
3469 m_normal_spacing
= width
+ 8;
3472 if (which
== wxIMAGE_LIST_SMALL
)
3474 m_small_image_list
= imageList
;
3475 m_small_spacing
= width
+ 14;
3476 m_lineHeight
= 0; // ensure that the line height will be recalc'd
3480 void wxListMainWindow::SetItemSpacing( int spacing
, bool isSmall
)
3484 m_small_spacing
= spacing
;
3486 m_normal_spacing
= spacing
;
3489 int wxListMainWindow::GetItemSpacing( bool isSmall
)
3491 return isSmall
? m_small_spacing
: m_normal_spacing
;
3494 // ----------------------------------------------------------------------------
3496 // ----------------------------------------------------------------------------
3498 void wxListMainWindow::SetColumn( int col
, wxListItem
&item
)
3500 wxListHeaderDataList::compatibility_iterator node
= m_columns
.Item( col
);
3502 wxCHECK_RET( node
, _T("invalid column index in SetColumn") );
3504 if ( item
.m_width
== wxLIST_AUTOSIZE_USEHEADER
)
3505 item
.m_width
= GetTextLength( item
.m_text
);
3507 wxListHeaderData
*column
= node
->GetData();
3508 column
->SetItem( item
);
3510 wxListHeaderWindow
*headerWin
= GetListCtrl()->m_headerWin
;
3512 headerWin
->m_dirty
= true;
3516 // invalidate it as it has to be recalculated
3520 void wxListMainWindow::SetColumnWidth( int col
, int width
)
3522 wxCHECK_RET( col
>= 0 && col
< GetColumnCount(),
3523 _T("invalid column index") );
3525 wxCHECK_RET( InReportView(),
3526 _T("SetColumnWidth() can only be called in report mode.") );
3529 wxListHeaderWindow
*headerWin
= GetListCtrl()->m_headerWin
;
3531 headerWin
->m_dirty
= true;
3533 wxListHeaderDataList::compatibility_iterator node
= m_columns
.Item( col
);
3534 wxCHECK_RET( node
, _T("no column?") );
3536 wxListHeaderData
*column
= node
->GetData();
3538 size_t count
= GetItemCount();
3540 if (width
== wxLIST_AUTOSIZE_USEHEADER
)
3542 width
= GetTextLength(column
->GetText());
3544 else if ( width
== wxLIST_AUTOSIZE
)
3548 // TODO: determine the max width somehow...
3549 width
= WIDTH_COL_DEFAULT
;
3553 wxClientDC
dc(this);
3554 dc
.SetFont( GetFont() );
3556 int max
= AUTOSIZE_COL_MARGIN
;
3558 // if the cached column width isn't valid then recalculate it
3559 if (m_aColWidths
.Item(col
)->bNeedsUpdate
)
3561 for (size_t i
= 0; i
< count
; i
++)
3563 wxListLineData
*line
= GetLine( i
);
3564 wxListItemDataList::compatibility_iterator n
= line
->m_items
.Item( col
);
3566 wxCHECK_RET( n
, _T("no subitem?") );
3568 wxListItemData
*itemData
= n
->GetData();
3571 itemData
->GetItem(item
);
3572 int itemWidth
= GetItemWidthWithImage(&item
);
3573 if (itemWidth
> max
)
3577 m_aColWidths
.Item(col
)->bNeedsUpdate
= false;
3578 m_aColWidths
.Item(col
)->nMaxWidth
= max
;
3581 max
= m_aColWidths
.Item(col
)->nMaxWidth
;
3582 width
= max
+ AUTOSIZE_COL_MARGIN
;
3586 column
->SetWidth( width
);
3588 // invalidate it as it has to be recalculated
3592 int wxListMainWindow::GetHeaderWidth() const
3594 if ( !m_headerWidth
)
3596 wxListMainWindow
*self
= wxConstCast(this, wxListMainWindow
);
3598 size_t count
= GetColumnCount();
3599 for ( size_t col
= 0; col
< count
; col
++ )
3601 self
->m_headerWidth
+= GetColumnWidth(col
);
3605 return m_headerWidth
;
3608 void wxListMainWindow::GetColumn( int col
, wxListItem
&item
) const
3610 wxListHeaderDataList::compatibility_iterator node
= m_columns
.Item( col
);
3611 wxCHECK_RET( node
, _T("invalid column index in GetColumn") );
3613 wxListHeaderData
*column
= node
->GetData();
3614 column
->GetItem( item
);
3617 int wxListMainWindow::GetColumnWidth( int col
) const
3619 wxListHeaderDataList::compatibility_iterator node
= m_columns
.Item( col
);
3620 wxCHECK_MSG( node
, 0, _T("invalid column index") );
3622 wxListHeaderData
*column
= node
->GetData();
3623 return column
->GetWidth();
3626 // ----------------------------------------------------------------------------
3628 // ----------------------------------------------------------------------------
3630 void wxListMainWindow::SetItem( wxListItem
&item
)
3632 long id
= item
.m_itemId
;
3633 wxCHECK_RET( id
>= 0 && (size_t)id
< GetItemCount(),
3634 _T("invalid item index in SetItem") );
3638 wxListLineData
*line
= GetLine((size_t)id
);
3639 line
->SetItem( item
.m_col
, item
);
3641 // Set item state if user wants
3642 if ( item
.m_mask
& wxLIST_MASK_STATE
)
3643 SetItemState( item
.m_itemId
, item
.m_state
, item
.m_state
);
3647 // update the Max Width Cache if needed
3648 int width
= GetItemWidthWithImage(&item
);
3650 if (width
> m_aColWidths
.Item(item
.m_col
)->nMaxWidth
)
3651 m_aColWidths
.Item(item
.m_col
)->nMaxWidth
= width
;
3655 // update the item on screen
3657 GetItemRect(id
, rectItem
);
3658 RefreshRect(rectItem
);
3661 void wxListMainWindow::SetItemStateAll(long state
, long stateMask
)
3666 // first deal with selection
3667 if ( stateMask
& wxLIST_STATE_SELECTED
)
3669 // set/clear select state
3672 // optimized version for virtual listctrl.
3673 m_selStore
.SelectRange(0, GetItemCount() - 1, state
== wxLIST_STATE_SELECTED
);
3676 else if ( state
& wxLIST_STATE_SELECTED
)
3678 const long count
= GetItemCount();
3679 for( long i
= 0; i
< count
; i
++ )
3681 SetItemState( i
, wxLIST_STATE_SELECTED
, wxLIST_STATE_SELECTED
);
3687 // clear for non virtual (somewhat optimized by using GetNextItem())
3689 while ( (i
= GetNextItem(i
, wxLIST_NEXT_ALL
, wxLIST_STATE_SELECTED
)) != -1 )
3691 SetItemState( i
, 0, wxLIST_STATE_SELECTED
);
3696 if ( HasCurrent() && (state
== 0) && (stateMask
& wxLIST_STATE_FOCUSED
) )
3698 // unfocus all: only one item can be focussed, so clearing focus for
3699 // all items is simply clearing focus of the focussed item.
3700 SetItemState(m_current
, state
, stateMask
);
3702 //(setting focus to all items makes no sense, so it is not handled here.)
3705 void wxListMainWindow::SetItemState( long litem
, long state
, long stateMask
)
3709 SetItemStateAll(state
, stateMask
);
3713 wxCHECK_RET( litem
>= 0 && (size_t)litem
< GetItemCount(),
3714 _T("invalid list ctrl item index in SetItem") );
3716 size_t oldCurrent
= m_current
;
3717 size_t item
= (size_t)litem
; // safe because of the check above
3719 // do we need to change the focus?
3720 if ( stateMask
& wxLIST_STATE_FOCUSED
)
3722 if ( state
& wxLIST_STATE_FOCUSED
)
3724 // don't do anything if this item is already focused
3725 if ( item
!= m_current
)
3727 ChangeCurrent(item
);
3729 if ( oldCurrent
!= (size_t)-1 )
3731 if ( IsSingleSel() )
3733 HighlightLine(oldCurrent
, false);
3736 RefreshLine(oldCurrent
);
3739 RefreshLine( m_current
);
3744 // don't do anything if this item is not focused
3745 if ( item
== m_current
)
3749 if ( IsSingleSel() )
3751 // we must unselect the old current item as well or we
3752 // might end up with more than one selected item in a
3753 // single selection control
3754 HighlightLine(oldCurrent
, false);
3757 RefreshLine( oldCurrent
);
3762 // do we need to change the selection state?
3763 if ( stateMask
& wxLIST_STATE_SELECTED
)
3765 bool on
= (state
& wxLIST_STATE_SELECTED
) != 0;
3767 if ( IsSingleSel() )
3771 // selecting the item also makes it the focused one in the
3773 if ( m_current
!= item
)
3775 ChangeCurrent(item
);
3777 if ( oldCurrent
!= (size_t)-1 )
3779 HighlightLine( oldCurrent
, false );
3780 RefreshLine( oldCurrent
);
3786 // only the current item may be selected anyhow
3787 if ( item
!= m_current
)
3792 if ( HighlightLine(item
, on
) )
3799 int wxListMainWindow::GetItemState( long item
, long stateMask
) const
3801 wxCHECK_MSG( item
>= 0 && (size_t)item
< GetItemCount(), 0,
3802 _T("invalid list ctrl item index in GetItemState()") );
3804 int ret
= wxLIST_STATE_DONTCARE
;
3806 if ( stateMask
& wxLIST_STATE_FOCUSED
)
3808 if ( (size_t)item
== m_current
)
3809 ret
|= wxLIST_STATE_FOCUSED
;
3812 if ( stateMask
& wxLIST_STATE_SELECTED
)
3814 if ( IsHighlighted(item
) )
3815 ret
|= wxLIST_STATE_SELECTED
;
3821 void wxListMainWindow::GetItem( wxListItem
&item
) const
3823 wxCHECK_RET( item
.m_itemId
>= 0 && (size_t)item
.m_itemId
< GetItemCount(),
3824 _T("invalid item index in GetItem") );
3826 wxListLineData
*line
= GetLine((size_t)item
.m_itemId
);
3827 line
->GetItem( item
.m_col
, item
);
3829 // Get item state if user wants it
3830 if ( item
.m_mask
& wxLIST_MASK_STATE
)
3831 item
.m_state
= GetItemState( item
.m_itemId
, wxLIST_STATE_SELECTED
|
3832 wxLIST_STATE_FOCUSED
);
3835 // ----------------------------------------------------------------------------
3837 // ----------------------------------------------------------------------------
3839 size_t wxListMainWindow::GetItemCount() const
3841 return IsVirtual() ? m_countVirt
: m_lines
.GetCount();
3844 void wxListMainWindow::SetItemCount(long count
)
3846 m_selStore
.SetItemCount(count
);
3847 m_countVirt
= count
;
3849 ResetVisibleLinesRange();
3851 // scrollbars must be reset
3855 int wxListMainWindow::GetSelectedItemCount() const
3857 // deal with the quick case first
3858 if ( IsSingleSel() )
3859 return HasCurrent() ? IsHighlighted(m_current
) : false;
3861 // virtual controls remmebers all its selections itself
3863 return m_selStore
.GetSelectedCount();
3865 // TODO: we probably should maintain the number of items selected even for
3866 // non virtual controls as enumerating all lines is really slow...
3867 size_t countSel
= 0;
3868 size_t count
= GetItemCount();
3869 for ( size_t line
= 0; line
< count
; line
++ )
3871 if ( GetLine(line
)->IsHighlighted() )
3878 // ----------------------------------------------------------------------------
3879 // item position/size
3880 // ----------------------------------------------------------------------------
3882 wxRect
wxListMainWindow::GetViewRect() const
3884 wxASSERT_MSG( !HasFlag(wxLC_REPORT
| wxLC_LIST
),
3885 _T("wxListCtrl::GetViewRect() only works in icon mode") );
3887 // we need to find the longest/tallest label
3888 wxCoord xMax
= 0, yMax
= 0;
3889 const int count
= GetItemCount();
3892 for ( int i
= 0; i
< count
; i
++ )
3897 wxCoord x
= r
.GetRight(),
3907 // some fudge needed to make it look prettier
3908 xMax
+= 2 * EXTRA_BORDER_X
;
3909 yMax
+= 2 * EXTRA_BORDER_Y
;
3911 // account for the scrollbars if necessary
3912 const wxSize sizeAll
= GetClientSize();
3913 if ( xMax
> sizeAll
.x
)
3914 yMax
+= wxSystemSettings::GetMetric(wxSYS_HSCROLL_Y
);
3915 if ( yMax
> sizeAll
.y
)
3916 xMax
+= wxSystemSettings::GetMetric(wxSYS_VSCROLL_X
);
3918 return wxRect(0, 0, xMax
, yMax
);
3921 void wxListMainWindow::GetItemRect( long index
, wxRect
&rect
) const
3923 wxCHECK_RET( index
>= 0 && (size_t)index
< GetItemCount(),
3924 _T("invalid index in GetItemRect") );
3926 // ensure that we're laid out, otherwise we could return nonsense
3929 wxConstCast(this, wxListMainWindow
)->
3930 RecalculatePositions(true /* no refresh */);
3933 rect
= GetLineRect((size_t)index
);
3935 CalcScrolledPosition(rect
.x
, rect
.y
, &rect
.x
, &rect
.y
);
3938 bool wxListMainWindow::GetItemPosition(long item
, wxPoint
& pos
) const
3941 GetItemRect(item
, rect
);
3949 // ----------------------------------------------------------------------------
3950 // geometry calculation
3951 // ----------------------------------------------------------------------------
3953 void wxListMainWindow::RecalculatePositions(bool noRefresh
)
3955 wxClientDC
dc( this );
3956 dc
.SetFont( GetFont() );
3958 const size_t count
= GetItemCount();
3961 if ( HasFlag(wxLC_ICON
) )
3962 iconSpacing
= m_normal_spacing
;
3963 else if ( HasFlag(wxLC_SMALL_ICON
) )
3964 iconSpacing
= m_small_spacing
;
3968 // Note that we do not call GetClientSize() here but
3969 // GetSize() and subtract the border size for sunken
3970 // borders manually. This is technically incorrect,
3971 // but we need to know the client area's size WITHOUT
3972 // scrollbars here. Since we don't know if there are
3973 // any scrollbars, we use GetSize() instead. Another
3974 // solution would be to call SetScrollbars() here to
3975 // remove the scrollbars and call GetClientSize() then,
3976 // but this might result in flicker and - worse - will
3977 // reset the scrollbars to 0 which is not good at all
3978 // if you resize a dialog/window, but don't want to
3979 // reset the window scrolling. RR.
3980 // Furthermore, we actually do NOT subtract the border
3981 // width as 2 pixels is just the extra space which we
3982 // need around the actual content in the window. Other-
3983 // wise the text would e.g. touch the upper border. RR.
3986 GetSize( &clientWidth
, &clientHeight
);
3988 const int lineHeight
= GetLineHeight();
3990 if ( InReportView() )
3992 // all lines have the same height and we scroll one line per step
3993 int entireHeight
= count
* lineHeight
+ LINE_SPACING
;
3995 m_linesPerPage
= clientHeight
/ lineHeight
;
3997 ResetVisibleLinesRange();
3999 SetScrollbars( SCROLL_UNIT_X
, lineHeight
,
4000 GetHeaderWidth() / SCROLL_UNIT_X
,
4001 (entireHeight
+ lineHeight
- 1) / lineHeight
,
4002 GetScrollPos(wxHORIZONTAL
),
4003 GetScrollPos(wxVERTICAL
),
4008 // we have 3 different layout strategies: either layout all items
4009 // horizontally/vertically (wxLC_ALIGN_XXX styles explicitly given) or
4010 // to arrange them in top to bottom, left to right (don't ask me why
4011 // not the other way round...) order
4012 if ( HasFlag(wxLC_ALIGN_LEFT
| wxLC_ALIGN_TOP
) )
4014 int x
= EXTRA_BORDER_X
;
4015 int y
= EXTRA_BORDER_Y
;
4017 wxCoord widthMax
= 0;
4020 for ( i
= 0; i
< count
; i
++ )
4022 wxListLineData
*line
= GetLine(i
);
4023 line
->CalculateSize( &dc
, iconSpacing
);
4024 line
->SetPosition( x
, y
, iconSpacing
);
4026 wxSize sizeLine
= GetLineSize(i
);
4028 if ( HasFlag(wxLC_ALIGN_TOP
) )
4030 if ( sizeLine
.x
> widthMax
)
4031 widthMax
= sizeLine
.x
;
4035 else // wxLC_ALIGN_LEFT
4037 x
+= sizeLine
.x
+ MARGIN_BETWEEN_ROWS
;
4041 if ( HasFlag(wxLC_ALIGN_TOP
) )
4043 // traverse the items again and tweak their sizes so that they are
4044 // all the same in a row
4045 for ( i
= 0; i
< count
; i
++ )
4047 wxListLineData
*line
= GetLine(i
);
4048 line
->m_gi
->ExtendWidth(widthMax
);
4056 (x
+ SCROLL_UNIT_X
) / SCROLL_UNIT_X
,
4057 (y
+ lineHeight
) / lineHeight
,
4058 GetScrollPos( wxHORIZONTAL
),
4059 GetScrollPos( wxVERTICAL
),
4063 else // "flowed" arrangement, the most complicated case
4065 // at first we try without any scrollbars, if the items don't fit into
4066 // the window, we recalculate after subtracting the space taken by the
4069 int entireWidth
= 0;
4071 for (int tries
= 0; tries
< 2; tries
++)
4073 entireWidth
= 2 * EXTRA_BORDER_X
;
4077 // Now we have decided that the items do not fit into the
4078 // client area, so we need a scrollbar
4079 entireWidth
+= SCROLL_UNIT_X
;
4082 int x
= EXTRA_BORDER_X
;
4083 int y
= EXTRA_BORDER_Y
;
4084 int maxWidthInThisRow
= 0;
4087 int currentlyVisibleLines
= 0;
4089 for (size_t i
= 0; i
< count
; i
++)
4091 currentlyVisibleLines
++;
4092 wxListLineData
*line
= GetLine( i
);
4093 line
->CalculateSize( &dc
, iconSpacing
);
4094 line
->SetPosition( x
, y
, iconSpacing
);
4096 wxSize sizeLine
= GetLineSize( i
);
4098 if ( maxWidthInThisRow
< sizeLine
.x
)
4099 maxWidthInThisRow
= sizeLine
.x
;
4102 if (currentlyVisibleLines
> m_linesPerPage
)
4103 m_linesPerPage
= currentlyVisibleLines
;
4105 if ( y
+ sizeLine
.y
>= clientHeight
)
4107 currentlyVisibleLines
= 0;
4109 maxWidthInThisRow
+= MARGIN_BETWEEN_ROWS
;
4110 x
+= maxWidthInThisRow
;
4111 entireWidth
+= maxWidthInThisRow
;
4112 maxWidthInThisRow
= 0;
4115 // We have reached the last item.
4116 if ( i
== count
- 1 )
4117 entireWidth
+= maxWidthInThisRow
;
4119 if ( (tries
== 0) &&
4120 (entireWidth
+ SCROLL_UNIT_X
> clientWidth
) )
4122 clientHeight
-= wxSystemSettings::
4123 GetMetric(wxSYS_HSCROLL_Y
);
4128 if ( i
== count
- 1 )
4129 tries
= 1; // Everything fits, no second try required.
4137 (entireWidth
+ SCROLL_UNIT_X
) / SCROLL_UNIT_X
,
4139 GetScrollPos( wxHORIZONTAL
),
4148 // FIXME: why should we call it from here?
4155 void wxListMainWindow::RefreshAll()
4160 wxListHeaderWindow
*headerWin
= GetListCtrl()->m_headerWin
;
4161 if ( headerWin
&& headerWin
->m_dirty
)
4163 headerWin
->m_dirty
= false;
4164 headerWin
->Refresh();
4168 void wxListMainWindow::UpdateCurrent()
4170 if ( !HasCurrent() && !IsEmpty() )
4174 long wxListMainWindow::GetNextItem( long item
,
4175 int WXUNUSED(geometry
),
4179 max
= GetItemCount();
4180 wxCHECK_MSG( (ret
== -1) || (ret
< max
), -1,
4181 _T("invalid listctrl index in GetNextItem()") );
4183 // notice that we start with the next item (or the first one if item == -1)
4184 // and this is intentional to allow writing a simple loop to iterate over
4185 // all selected items
4188 // this is not an error because the index was OK initially,
4189 // just no such item
4196 size_t count
= GetItemCount();
4197 for ( size_t line
= (size_t)ret
; line
< count
; line
++ )
4199 if ( (state
& wxLIST_STATE_FOCUSED
) && (line
== m_current
) )
4202 if ( (state
& wxLIST_STATE_SELECTED
) && IsHighlighted(line
) )
4209 // ----------------------------------------------------------------------------
4211 // ----------------------------------------------------------------------------
4213 void wxListMainWindow::DeleteItem( long lindex
)
4215 size_t count
= GetItemCount();
4217 wxCHECK_RET( (lindex
>= 0) && ((size_t)lindex
< count
),
4218 _T("invalid item index in DeleteItem") );
4220 size_t index
= (size_t)lindex
;
4222 // we don't need to adjust the index for the previous items
4223 if ( HasCurrent() && m_current
>= index
)
4225 // if the current item is being deleted, we want the next one to
4226 // become selected - unless there is no next one - so don't adjust
4227 // m_current in this case
4228 if ( m_current
!= index
|| m_current
== count
- 1 )
4232 if ( InReportView() )
4234 // mark the Column Max Width cache as dirty if the items in the line
4235 // we're deleting contain the Max Column Width
4236 wxListLineData
* const line
= GetLine(index
);
4237 wxListItemDataList::compatibility_iterator n
;
4238 wxListItemData
*itemData
;
4242 for (size_t i
= 0; i
< m_columns
.GetCount(); i
++)
4244 n
= line
->m_items
.Item( i
);
4245 itemData
= n
->GetData();
4246 itemData
->GetItem(item
);
4248 itemWidth
= GetItemWidthWithImage(&item
);
4250 if (itemWidth
>= m_aColWidths
.Item(i
)->nMaxWidth
)
4251 m_aColWidths
.Item(i
)->bNeedsUpdate
= true;
4254 ResetVisibleLinesRange();
4260 m_selStore
.OnItemDelete(index
);
4264 m_lines
.RemoveAt( index
);
4267 // we need to refresh the (vert) scrollbar as the number of items changed
4270 SendNotify( index
, wxEVT_COMMAND_LIST_DELETE_ITEM
);
4272 RefreshAfter(index
);
4275 void wxListMainWindow::DeleteColumn( int col
)
4277 wxListHeaderDataList::compatibility_iterator node
= m_columns
.Item( col
);
4279 wxCHECK_RET( node
, wxT("invalid column index in DeleteColumn()") );
4282 delete node
->GetData();
4283 m_columns
.Erase( node
);
4287 // update all the items
4288 for ( size_t i
= 0; i
< m_lines
.GetCount(); i
++ )
4290 wxListLineData
* const line
= GetLine(i
);
4291 wxListItemDataList::compatibility_iterator n
= line
->m_items
.Item( col
);
4292 delete n
->GetData();
4293 line
->m_items
.Erase(n
);
4297 if ( InReportView() ) // we only cache max widths when in Report View
4299 delete m_aColWidths
.Item(col
);
4300 m_aColWidths
.RemoveAt(col
);
4303 // invalidate it as it has to be recalculated
4307 void wxListMainWindow::DoDeleteAllItems()
4310 // nothing to do - in particular, don't send the event
4315 // to make the deletion of all items faster, we don't send the
4316 // notifications for each item deletion in this case but only one event
4317 // for all of them: this is compatible with wxMSW and documented in
4318 // DeleteAllItems() description
4320 wxListEvent
event( wxEVT_COMMAND_LIST_DELETE_ALL_ITEMS
, GetParent()->GetId() );
4321 event
.SetEventObject( GetParent() );
4322 GetParent()->GetEventHandler()->ProcessEvent( event
);
4330 if ( InReportView() )
4332 ResetVisibleLinesRange();
4333 for (size_t i
= 0; i
< m_aColWidths
.GetCount(); i
++)
4335 m_aColWidths
.Item(i
)->bNeedsUpdate
= true;
4342 void wxListMainWindow::DeleteAllItems()
4346 RecalculatePositions();
4349 void wxListMainWindow::DeleteEverything()
4351 WX_CLEAR_LIST(wxListHeaderDataList
, m_columns
);
4352 WX_CLEAR_ARRAY(m_aColWidths
);
4357 // ----------------------------------------------------------------------------
4358 // scanning for an item
4359 // ----------------------------------------------------------------------------
4361 void wxListMainWindow::EnsureVisible( long index
)
4363 wxCHECK_RET( index
>= 0 && (size_t)index
< GetItemCount(),
4364 _T("invalid index in EnsureVisible") );
4366 // We have to call this here because the label in question might just have
4367 // been added and its position is not known yet
4369 RecalculatePositions(true /* no refresh */);
4371 MoveToItem((size_t)index
);
4374 long wxListMainWindow::FindItem(long start
, const wxString
& str
, bool WXUNUSED(partial
) )
4381 size_t count
= GetItemCount();
4382 for ( size_t i
= (size_t)pos
; i
< count
; i
++ )
4384 wxListLineData
*line
= GetLine(i
);
4385 if ( line
->GetText(0) == tmp
)
4392 long wxListMainWindow::FindItem(long start
, wxUIntPtr data
)
4398 size_t count
= GetItemCount();
4399 for (size_t i
= (size_t)pos
; i
< count
; i
++)
4401 wxListLineData
*line
= GetLine(i
);
4403 line
->GetItem( 0, item
);
4404 if (item
.m_data
== data
)
4411 long wxListMainWindow::FindItem( const wxPoint
& pt
)
4414 GetVisibleLinesRange( &topItem
, NULL
);
4417 GetItemPosition( GetItemCount() - 1, p
);
4421 long id
= (long)floor( pt
.y
* double(GetItemCount() - topItem
- 1) / p
.y
+ topItem
);
4422 if ( id
>= 0 && id
< (long)GetItemCount() )
4428 long wxListMainWindow::HitTest( int x
, int y
, int &flags
) const
4430 CalcUnscrolledPosition( x
, y
, &x
, &y
);
4432 size_t count
= GetItemCount();
4434 if ( InReportView() )
4436 size_t current
= y
/ GetLineHeight();
4437 if ( current
< count
)
4439 flags
= HitTestLine(current
, x
, y
);
4446 // TODO: optimize it too! this is less simple than for report view but
4447 // enumerating all items is still not a way to do it!!
4448 for ( size_t current
= 0; current
< count
; current
++ )
4450 flags
= HitTestLine(current
, x
, y
);
4459 // ----------------------------------------------------------------------------
4461 // ----------------------------------------------------------------------------
4463 void wxListMainWindow::InsertItem( wxListItem
&item
)
4465 wxASSERT_MSG( !IsVirtual(), _T("can't be used with virtual control") );
4467 int count
= GetItemCount();
4468 wxCHECK_RET( item
.m_itemId
>= 0, _T("invalid item index") );
4470 if (item
.m_itemId
> count
)
4471 item
.m_itemId
= count
;
4473 size_t id
= item
.m_itemId
;
4477 if ( InReportView() )
4479 ResetVisibleLinesRange();
4481 // calculate the width of the item and adjust the max column width
4482 wxColWidthInfo
*pWidthInfo
= m_aColWidths
.Item(item
.GetColumn());
4483 int width
= GetItemWidthWithImage(&item
);
4484 item
.SetWidth(width
);
4485 if (width
> pWidthInfo
->nMaxWidth
)
4486 pWidthInfo
->nMaxWidth
= width
;
4489 wxListLineData
*line
= new wxListLineData(this);
4491 line
->SetItem( item
.m_col
, item
);
4493 m_lines
.Insert( line
, id
);
4497 // If an item is selected at or below the point of insertion, we need to
4498 // increment the member variables because the current row's index has gone
4500 if ( HasCurrent() && m_current
>= id
)
4503 SendNotify(id
, wxEVT_COMMAND_LIST_INSERT_ITEM
);
4505 RefreshLines(id
, GetItemCount() - 1);
4508 void wxListMainWindow::InsertColumn( long col
, wxListItem
&item
)
4511 if ( InReportView() )
4513 if (item
.m_width
== wxLIST_AUTOSIZE_USEHEADER
)
4514 item
.m_width
= GetTextLength( item
.m_text
);
4516 wxListHeaderData
*column
= new wxListHeaderData( item
);
4517 wxColWidthInfo
*colWidthInfo
= new wxColWidthInfo();
4519 bool insert
= (col
>= 0) && ((size_t)col
< m_columns
.GetCount());
4522 wxListHeaderDataList::compatibility_iterator
4523 node
= m_columns
.Item( col
);
4524 m_columns
.Insert( node
, column
);
4525 m_aColWidths
.Insert( colWidthInfo
, col
);
4529 m_columns
.Append( column
);
4530 m_aColWidths
.Add( colWidthInfo
);
4535 // update all the items
4536 for ( size_t i
= 0; i
< m_lines
.GetCount(); i
++ )
4538 wxListLineData
* const line
= GetLine(i
);
4539 wxListItemData
* const data
= new wxListItemData(this);
4541 line
->m_items
.Insert(col
, data
);
4543 line
->m_items
.Append(data
);
4547 // invalidate it as it has to be recalculated
4552 int wxListMainWindow::GetItemWidthWithImage(wxListItem
* item
)
4555 wxClientDC
dc(this);
4557 dc
.SetFont( GetFont() );
4559 if (item
->GetImage() != -1)
4562 GetImageSize( item
->GetImage(), ix
, iy
);
4566 if (!item
->GetText().empty())
4569 dc
.GetTextExtent( item
->GetText(), &w
, NULL
);
4576 // ----------------------------------------------------------------------------
4578 // ----------------------------------------------------------------------------
4580 wxListCtrlCompare list_ctrl_compare_func_2
;
4581 long list_ctrl_compare_data
;
4583 int LINKAGEMODE
list_ctrl_compare_func_1( wxListLineData
**arg1
, wxListLineData
**arg2
)
4585 wxListLineData
*line1
= *arg1
;
4586 wxListLineData
*line2
= *arg2
;
4588 line1
->GetItem( 0, item
);
4589 wxUIntPtr data1
= item
.m_data
;
4590 line2
->GetItem( 0, item
);
4591 wxUIntPtr data2
= item
.m_data
;
4592 return list_ctrl_compare_func_2( data1
, data2
, list_ctrl_compare_data
);
4595 void wxListMainWindow::SortItems( wxListCtrlCompare fn
, long data
)
4597 list_ctrl_compare_func_2
= fn
;
4598 list_ctrl_compare_data
= data
;
4599 m_lines
.Sort( list_ctrl_compare_func_1
);
4603 // ----------------------------------------------------------------------------
4605 // ----------------------------------------------------------------------------
4607 void wxListMainWindow::OnScroll(wxScrollWinEvent
& event
)
4609 // update our idea of which lines are shown when we redraw the window the
4611 ResetVisibleLinesRange();
4614 #if ( defined(__WXGTK__) || defined(__WXMAC__) ) && !defined(__WXUNIVERSAL__)
4615 wxScrolledWindow::OnScroll(event
);
4617 HandleOnScroll( event
);
4620 if ( event
.GetOrientation() == wxHORIZONTAL
&& HasHeader() )
4622 wxGenericListCtrl
* lc
= GetListCtrl();
4623 wxCHECK_RET( lc
, _T("no listctrl window?") );
4625 lc
->m_headerWin
->Refresh();
4626 lc
->m_headerWin
->Update();
4630 int wxListMainWindow::GetCountPerPage() const
4632 if ( !m_linesPerPage
)
4634 wxConstCast(this, wxListMainWindow
)->
4635 m_linesPerPage
= GetClientSize().y
/ GetLineHeight();
4638 return m_linesPerPage
;
4641 void wxListMainWindow::GetVisibleLinesRange(size_t *from
, size_t *to
)
4643 wxASSERT_MSG( InReportView(), _T("this is for report mode only") );
4645 if ( m_lineFrom
== (size_t)-1 )
4647 size_t count
= GetItemCount();
4650 m_lineFrom
= GetScrollPos(wxVERTICAL
);
4652 // this may happen if SetScrollbars() hadn't been called yet
4653 if ( m_lineFrom
>= count
)
4654 m_lineFrom
= count
- 1;
4656 // we redraw one extra line but this is needed to make the redrawing
4657 // logic work when there is a fractional number of lines on screen
4658 m_lineTo
= m_lineFrom
+ m_linesPerPage
;
4659 if ( m_lineTo
>= count
)
4660 m_lineTo
= count
- 1;
4662 else // empty control
4665 m_lineTo
= (size_t)-1;
4669 wxASSERT_MSG( IsEmpty() ||
4670 (m_lineFrom
<= m_lineTo
&& m_lineTo
< GetItemCount()),
4671 _T("GetVisibleLinesRange() returns incorrect result") );
4679 // -------------------------------------------------------------------------------------
4680 // wxGenericListCtrl
4681 // -------------------------------------------------------------------------------------
4683 IMPLEMENT_DYNAMIC_CLASS(wxGenericListCtrl
, wxControl
)
4685 BEGIN_EVENT_TABLE(wxGenericListCtrl
,wxControl
)
4686 EVT_SIZE(wxGenericListCtrl::OnSize
)
4689 wxGenericListCtrl::wxGenericListCtrl()
4691 m_imageListNormal
= (wxImageList
*) NULL
;
4692 m_imageListSmall
= (wxImageList
*) NULL
;
4693 m_imageListState
= (wxImageList
*) NULL
;
4695 m_ownsImageListNormal
=
4696 m_ownsImageListSmall
=
4697 m_ownsImageListState
= false;
4699 m_mainWin
= (wxListMainWindow
*) NULL
;
4700 m_headerWin
= (wxListHeaderWindow
*) NULL
;
4704 wxGenericListCtrl::~wxGenericListCtrl()
4706 if (m_ownsImageListNormal
)
4707 delete m_imageListNormal
;
4708 if (m_ownsImageListSmall
)
4709 delete m_imageListSmall
;
4710 if (m_ownsImageListState
)
4711 delete m_imageListState
;
4714 void wxGenericListCtrl::CalculateAndSetHeaderHeight()
4720 GetThemeMetric( kThemeMetricListHeaderHeight
, &h
);
4722 // we use 'g' to get the descent, too
4724 m_headerWin
->GetTextExtent(wxT("Hg"), &w
, &h
, &d
);
4725 h
+= d
+ 2 * HEADER_OFFSET_Y
+ EXTRA_HEIGHT
;
4728 // only update if changed
4729 if ( h
!= m_headerHeight
)
4734 ResizeReportView(true);
4735 else //why is this needed if it doesn't have a header?
4736 m_headerWin
->SetSize(m_headerWin
->GetSize().x
, m_headerHeight
);
4741 void wxGenericListCtrl::CreateHeaderWindow()
4743 m_headerWin
= new wxListHeaderWindow
4745 this, wxID_ANY
, m_mainWin
,
4747 wxSize(GetClientSize().x
, m_headerHeight
),
4750 CalculateAndSetHeaderHeight();
4753 bool wxGenericListCtrl::Create(wxWindow
*parent
,
4758 const wxValidator
&validator
,
4759 const wxString
&name
)
4763 m_imageListState
= (wxImageList
*) NULL
;
4764 m_ownsImageListNormal
=
4765 m_ownsImageListSmall
=
4766 m_ownsImageListState
= false;
4768 m_mainWin
= (wxListMainWindow
*) NULL
;
4769 m_headerWin
= (wxListHeaderWindow
*) NULL
;
4773 if ( !(style
& wxLC_MASK_TYPE
) )
4775 style
= style
| wxLC_LIST
;
4778 if ( !wxControl::Create( parent
, id
, pos
, size
, style
, validator
, name
) )
4781 // don't create the inner window with the border
4782 style
&= ~wxBORDER_MASK
;
4784 m_mainWin
= new wxListMainWindow( this, wxID_ANY
, wxPoint(0, 0), size
, style
);
4786 #ifdef __WXMAC_CARBON__
4787 // Human Interface Guidelines ask us for a special font in this case
4788 if ( GetWindowVariant() == wxWINDOW_VARIANT_NORMAL
)
4791 font
.MacCreateThemeFont( kThemeViewsFont
);
4796 if ( InReportView() )
4798 CreateHeaderWindow();
4800 #ifdef __WXMAC_CARBON__
4804 font
.MacCreateThemeFont( kThemeSmallSystemFont
);
4805 m_headerWin
->SetFont( font
);
4806 CalculateAndSetHeaderHeight();
4810 if ( HasFlag(wxLC_NO_HEADER
) )
4811 // VZ: why do we create it at all then?
4812 m_headerWin
->Show( false );
4820 void wxGenericListCtrl::SetSingleStyle( long style
, bool add
)
4822 wxASSERT_MSG( !(style
& wxLC_VIRTUAL
),
4823 _T("wxLC_VIRTUAL can't be [un]set") );
4825 long flag
= GetWindowStyle();
4829 if (style
& wxLC_MASK_TYPE
)
4830 flag
&= ~(wxLC_MASK_TYPE
| wxLC_VIRTUAL
);
4831 if (style
& wxLC_MASK_ALIGN
)
4832 flag
&= ~wxLC_MASK_ALIGN
;
4833 if (style
& wxLC_MASK_SORT
)
4834 flag
&= ~wxLC_MASK_SORT
;
4842 SetWindowStyleFlag( flag
);
4845 void wxGenericListCtrl::SetWindowStyleFlag( long flag
)
4849 m_mainWin
->DeleteEverything();
4851 // has the header visibility changed?
4852 bool hasHeader
= HasHeader();
4853 bool willHaveHeader
= (flag
& wxLC_REPORT
) && !(flag
& wxLC_NO_HEADER
);
4855 if ( hasHeader
!= willHaveHeader
)
4862 // don't delete, just hide, as we can reuse it later
4863 m_headerWin
->Show(false);
4865 //else: nothing to do
4867 else // must show header
4871 CreateHeaderWindow();
4873 else // already have it, just show
4875 m_headerWin
->Show( true );
4879 ResizeReportView(willHaveHeader
);
4883 wxWindow::SetWindowStyleFlag( flag
);
4886 bool wxGenericListCtrl::GetColumn(int col
, wxListItem
&item
) const
4888 m_mainWin
->GetColumn( col
, item
);
4892 bool wxGenericListCtrl::SetColumn( int col
, wxListItem
& item
)
4894 m_mainWin
->SetColumn( col
, item
);
4898 int wxGenericListCtrl::GetColumnWidth( int col
) const
4900 return m_mainWin
->GetColumnWidth( col
);
4903 bool wxGenericListCtrl::SetColumnWidth( int col
, int width
)
4905 m_mainWin
->SetColumnWidth( col
, width
);
4909 int wxGenericListCtrl::GetCountPerPage() const
4911 return m_mainWin
->GetCountPerPage(); // different from Windows ?
4914 bool wxGenericListCtrl::GetItem( wxListItem
&info
) const
4916 m_mainWin
->GetItem( info
);
4920 bool wxGenericListCtrl::SetItem( wxListItem
&info
)
4922 m_mainWin
->SetItem( info
);
4926 long wxGenericListCtrl::SetItem( long index
, int col
, const wxString
& label
, int imageId
)
4929 info
.m_text
= label
;
4930 info
.m_mask
= wxLIST_MASK_TEXT
;
4931 info
.m_itemId
= index
;
4935 info
.m_image
= imageId
;
4936 info
.m_mask
|= wxLIST_MASK_IMAGE
;
4939 m_mainWin
->SetItem(info
);
4943 int wxGenericListCtrl::GetItemState( long item
, long stateMask
) const
4945 return m_mainWin
->GetItemState( item
, stateMask
);
4948 bool wxGenericListCtrl::SetItemState( long item
, long state
, long stateMask
)
4950 m_mainWin
->SetItemState( item
, state
, stateMask
);
4955 wxGenericListCtrl::SetItemImage( long item
, int image
, int WXUNUSED(selImage
) )
4957 return SetItemColumnImage(item
, 0, image
);
4961 wxGenericListCtrl::SetItemColumnImage( long item
, long column
, int image
)
4964 info
.m_image
= image
;
4965 info
.m_mask
= wxLIST_MASK_IMAGE
;
4966 info
.m_itemId
= item
;
4967 info
.m_col
= column
;
4968 m_mainWin
->SetItem( info
);
4972 wxString
wxGenericListCtrl::GetItemText( long item
) const
4974 return m_mainWin
->GetItemText(item
);
4977 void wxGenericListCtrl::SetItemText( long item
, const wxString
& str
)
4979 m_mainWin
->SetItemText(item
, str
);
4982 wxUIntPtr
wxGenericListCtrl::GetItemData( long item
) const
4985 info
.m_mask
= wxLIST_MASK_DATA
;
4986 info
.m_itemId
= item
;
4987 m_mainWin
->GetItem( info
);
4991 bool wxGenericListCtrl::SetItemData( long item
, long data
)
4994 info
.m_mask
= wxLIST_MASK_DATA
;
4995 info
.m_itemId
= item
;
4997 m_mainWin
->SetItem( info
);
5001 wxRect
wxGenericListCtrl::GetViewRect() const
5003 return m_mainWin
->GetViewRect();
5006 bool wxGenericListCtrl::GetItemRect( long item
, wxRect
&rect
, int WXUNUSED(code
) ) const
5008 m_mainWin
->GetItemRect( item
, rect
);
5009 if ( m_mainWin
->HasHeader() )
5010 rect
.y
+= m_headerHeight
+ 1;
5014 bool wxGenericListCtrl::GetItemPosition( long item
, wxPoint
& pos
) const
5016 m_mainWin
->GetItemPosition( item
, pos
);
5020 bool wxGenericListCtrl::SetItemPosition( long WXUNUSED(item
), const wxPoint
& WXUNUSED(pos
) )
5025 int wxGenericListCtrl::GetItemCount() const
5027 return m_mainWin
->GetItemCount();
5030 int wxGenericListCtrl::GetColumnCount() const
5032 return m_mainWin
->GetColumnCount();
5035 void wxGenericListCtrl::SetItemSpacing( int spacing
, bool isSmall
)
5037 m_mainWin
->SetItemSpacing( spacing
, isSmall
);
5040 wxSize
wxGenericListCtrl::GetItemSpacing() const
5042 const int spacing
= m_mainWin
->GetItemSpacing(HasFlag(wxLC_SMALL_ICON
));
5044 return wxSize(spacing
, spacing
);
5047 #if WXWIN_COMPATIBILITY_2_6
5048 int wxGenericListCtrl::GetItemSpacing( bool isSmall
) const
5050 return m_mainWin
->GetItemSpacing( isSmall
);
5052 #endif // WXWIN_COMPATIBILITY_2_6
5054 void wxGenericListCtrl::SetItemTextColour( long item
, const wxColour
&col
)
5057 info
.m_itemId
= item
;
5058 info
.SetTextColour( col
);
5059 m_mainWin
->SetItem( info
);
5062 wxColour
wxGenericListCtrl::GetItemTextColour( long item
) const
5065 info
.m_itemId
= item
;
5066 m_mainWin
->GetItem( info
);
5067 return info
.GetTextColour();
5070 void wxGenericListCtrl::SetItemBackgroundColour( long item
, const wxColour
&col
)
5073 info
.m_itemId
= item
;
5074 info
.SetBackgroundColour( col
);
5075 m_mainWin
->SetItem( info
);
5078 wxColour
wxGenericListCtrl::GetItemBackgroundColour( long item
) const
5081 info
.m_itemId
= item
;
5082 m_mainWin
->GetItem( info
);
5083 return info
.GetBackgroundColour();
5086 void wxGenericListCtrl::SetItemFont( long item
, const wxFont
&f
)
5089 info
.m_itemId
= item
;
5091 m_mainWin
->SetItem( info
);
5094 wxFont
wxGenericListCtrl::GetItemFont( long item
) const
5097 info
.m_itemId
= item
;
5098 m_mainWin
->GetItem( info
);
5099 return info
.GetFont();
5102 int wxGenericListCtrl::GetSelectedItemCount() const
5104 return m_mainWin
->GetSelectedItemCount();
5107 wxColour
wxGenericListCtrl::GetTextColour() const
5109 return GetForegroundColour();
5112 void wxGenericListCtrl::SetTextColour(const wxColour
& col
)
5114 SetForegroundColour(col
);
5117 long wxGenericListCtrl::GetTopItem() const
5120 m_mainWin
->GetVisibleLinesRange(&top
, NULL
);
5124 long wxGenericListCtrl::GetNextItem( long item
, int geom
, int state
) const
5126 return m_mainWin
->GetNextItem( item
, geom
, state
);
5129 wxImageList
*wxGenericListCtrl::GetImageList(int which
) const
5131 if (which
== wxIMAGE_LIST_NORMAL
)
5132 return m_imageListNormal
;
5133 else if (which
== wxIMAGE_LIST_SMALL
)
5134 return m_imageListSmall
;
5135 else if (which
== wxIMAGE_LIST_STATE
)
5136 return m_imageListState
;
5138 return (wxImageList
*) NULL
;
5141 void wxGenericListCtrl::SetImageList( wxImageList
*imageList
, int which
)
5143 if ( which
== wxIMAGE_LIST_NORMAL
)
5145 if (m_ownsImageListNormal
)
5146 delete m_imageListNormal
;
5147 m_imageListNormal
= imageList
;
5148 m_ownsImageListNormal
= false;
5150 else if ( which
== wxIMAGE_LIST_SMALL
)
5152 if (m_ownsImageListSmall
)
5153 delete m_imageListSmall
;
5154 m_imageListSmall
= imageList
;
5155 m_ownsImageListSmall
= false;
5157 else if ( which
== wxIMAGE_LIST_STATE
)
5159 if (m_ownsImageListState
)
5160 delete m_imageListState
;
5161 m_imageListState
= imageList
;
5162 m_ownsImageListState
= false;
5165 m_mainWin
->SetImageList( imageList
, which
);
5168 void wxGenericListCtrl::AssignImageList(wxImageList
*imageList
, int which
)
5170 SetImageList(imageList
, which
);
5171 if ( which
== wxIMAGE_LIST_NORMAL
)
5172 m_ownsImageListNormal
= true;
5173 else if ( which
== wxIMAGE_LIST_SMALL
)
5174 m_ownsImageListSmall
= true;
5175 else if ( which
== wxIMAGE_LIST_STATE
)
5176 m_ownsImageListState
= true;
5179 bool wxGenericListCtrl::Arrange( int WXUNUSED(flag
) )
5184 bool wxGenericListCtrl::DeleteItem( long item
)
5186 m_mainWin
->DeleteItem( item
);
5190 bool wxGenericListCtrl::DeleteAllItems()
5192 m_mainWin
->DeleteAllItems();
5196 bool wxGenericListCtrl::DeleteAllColumns()
5198 size_t count
= m_mainWin
->m_columns
.GetCount();
5199 for ( size_t n
= 0; n
< count
; n
++ )
5204 void wxGenericListCtrl::ClearAll()
5206 m_mainWin
->DeleteEverything();
5209 bool wxGenericListCtrl::DeleteColumn( int col
)
5211 m_mainWin
->DeleteColumn( col
);
5213 // if we don't have the header any longer, we need to relayout the window
5214 if ( !GetColumnCount() )
5215 ResizeReportView(false /* no header */);
5219 wxTextCtrl
*wxGenericListCtrl::EditLabel(long item
,
5220 wxClassInfo
* textControlClass
)
5222 return m_mainWin
->EditLabel( item
, textControlClass
);
5225 wxTextCtrl
*wxGenericListCtrl::GetEditControl() const
5227 return m_mainWin
->GetEditControl();
5230 bool wxGenericListCtrl::EnsureVisible( long item
)
5232 m_mainWin
->EnsureVisible( item
);
5236 long wxGenericListCtrl::FindItem( long start
, const wxString
& str
, bool partial
)
5238 return m_mainWin
->FindItem( start
, str
, partial
);
5241 long wxGenericListCtrl::FindItem( long start
, wxUIntPtr data
)
5243 return m_mainWin
->FindItem( start
, data
);
5246 long wxGenericListCtrl::FindItem( long WXUNUSED(start
), const wxPoint
& pt
,
5247 int WXUNUSED(direction
))
5249 return m_mainWin
->FindItem( pt
);
5252 // TODO: sub item hit testing
5253 long wxGenericListCtrl::HitTest(const wxPoint
& point
, int& flags
, long *) const
5255 return m_mainWin
->HitTest( (int)point
.x
, (int)point
.y
, flags
);
5258 long wxGenericListCtrl::InsertItem( wxListItem
& info
)
5260 m_mainWin
->InsertItem( info
);
5261 return info
.m_itemId
;
5264 long wxGenericListCtrl::InsertItem( long index
, const wxString
&label
)
5267 info
.m_text
= label
;
5268 info
.m_mask
= wxLIST_MASK_TEXT
;
5269 info
.m_itemId
= index
;
5270 return InsertItem( info
);
5273 long wxGenericListCtrl::InsertItem( long index
, int imageIndex
)
5276 info
.m_mask
= wxLIST_MASK_IMAGE
;
5277 info
.m_image
= imageIndex
;
5278 info
.m_itemId
= index
;
5279 return InsertItem( info
);
5282 long wxGenericListCtrl::InsertItem( long index
, const wxString
&label
, int imageIndex
)
5285 info
.m_text
= label
;
5286 info
.m_image
= imageIndex
;
5287 info
.m_mask
= wxLIST_MASK_TEXT
| wxLIST_MASK_IMAGE
;
5288 info
.m_itemId
= index
;
5289 return InsertItem( info
);
5292 long wxGenericListCtrl::InsertColumn( long col
, wxListItem
&item
)
5294 wxCHECK_MSG( m_headerWin
, -1, _T("can't add column in non report mode") );
5296 m_mainWin
->InsertColumn( col
, item
);
5298 // if we hadn't had a header before but have one now
5299 // then we need to relayout the window
5300 if ( GetColumnCount() == 1 && m_mainWin
->HasHeader() )
5301 ResizeReportView(true /* have header */);
5303 m_headerWin
->Refresh();
5308 long wxGenericListCtrl::InsertColumn( long col
, const wxString
&heading
,
5309 int format
, int width
)
5312 item
.m_mask
= wxLIST_MASK_TEXT
| wxLIST_MASK_FORMAT
;
5313 item
.m_text
= heading
;
5316 item
.m_mask
|= wxLIST_MASK_WIDTH
;
5317 item
.m_width
= width
;
5320 item
.m_format
= format
;
5322 return InsertColumn( col
, item
);
5325 bool wxGenericListCtrl::ScrollList( int WXUNUSED(dx
), int WXUNUSED(dy
) )
5331 // fn is a function which takes 3 long arguments: item1, item2, data.
5332 // item1 is the long data associated with a first item (NOT the index).
5333 // item2 is the long data associated with a second item (NOT the index).
5334 // data is the same value as passed to SortItems.
5335 // The return value is a negative number if the first item should precede the second
5336 // item, a positive number of the second item should precede the first,
5337 // or zero if the two items are equivalent.
5338 // data is arbitrary data to be passed to the sort function.
5340 bool wxGenericListCtrl::SortItems( wxListCtrlCompare fn
, long data
)
5342 m_mainWin
->SortItems( fn
, data
);
5346 // ----------------------------------------------------------------------------
5348 // ----------------------------------------------------------------------------
5350 void wxGenericListCtrl::OnSize(wxSizeEvent
& WXUNUSED(event
))
5355 ResizeReportView(m_mainWin
->HasHeader());
5356 m_mainWin
->RecalculatePositions();
5359 void wxGenericListCtrl::ResizeReportView(bool showHeader
)
5362 GetClientSize( &cw
, &ch
);
5366 m_headerWin
->SetSize( 0, 0, cw
, m_headerHeight
);
5367 if(ch
> m_headerHeight
)
5368 m_mainWin
->SetSize( 0, m_headerHeight
+ 1,
5369 cw
, ch
- m_headerHeight
- 1 );
5371 m_mainWin
->SetSize( 0, m_headerHeight
+ 1,
5374 else // no header window
5376 m_mainWin
->SetSize( 0, 0, cw
, ch
);
5380 void wxGenericListCtrl::OnInternalIdle()
5382 wxWindow::OnInternalIdle();
5384 // do it only if needed
5385 if ( !m_mainWin
->m_dirty
)
5388 m_mainWin
->RecalculatePositions();
5391 // ----------------------------------------------------------------------------
5393 // ----------------------------------------------------------------------------
5395 bool wxGenericListCtrl::SetBackgroundColour( const wxColour
&colour
)
5399 m_mainWin
->SetBackgroundColour( colour
);
5400 m_mainWin
->m_dirty
= true;
5406 bool wxGenericListCtrl::SetForegroundColour( const wxColour
&colour
)
5408 if ( !wxWindow::SetForegroundColour( colour
) )
5413 m_mainWin
->SetForegroundColour( colour
);
5414 m_mainWin
->m_dirty
= true;
5418 m_headerWin
->SetForegroundColour( colour
);
5423 bool wxGenericListCtrl::SetFont( const wxFont
&font
)
5425 if ( !wxWindow::SetFont( font
) )
5430 m_mainWin
->SetFont( font
);
5431 m_mainWin
->m_dirty
= true;
5436 m_headerWin
->SetFont( font
);
5437 CalculateAndSetHeaderHeight();
5447 wxGenericListCtrl::GetClassDefaultAttributes(wxWindowVariant variant
)
5450 // Use the same color scheme as wxListBox
5451 return wxListBox::GetClassDefaultAttributes(variant
);
5453 wxUnusedVar(variant
);
5454 wxVisualAttributes attr
;
5455 attr
.colFg
= wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT
);
5456 attr
.colBg
= wxSystemSettings::GetColour(wxSYS_COLOUR_LISTBOX
);
5457 attr
.font
= wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT
);
5462 // ----------------------------------------------------------------------------
5463 // methods forwarded to m_mainWin
5464 // ----------------------------------------------------------------------------
5466 #if wxUSE_DRAG_AND_DROP
5468 void wxGenericListCtrl::SetDropTarget( wxDropTarget
*dropTarget
)
5470 m_mainWin
->SetDropTarget( dropTarget
);
5473 wxDropTarget
*wxGenericListCtrl::GetDropTarget() const
5475 return m_mainWin
->GetDropTarget();
5480 bool wxGenericListCtrl::SetCursor( const wxCursor
&cursor
)
5482 return m_mainWin
? m_mainWin
->wxWindow::SetCursor(cursor
) : false;
5485 wxColour
wxGenericListCtrl::GetBackgroundColour() const
5487 return m_mainWin
? m_mainWin
->GetBackgroundColour() : wxColour();
5490 wxColour
wxGenericListCtrl::GetForegroundColour() const
5492 return m_mainWin
? m_mainWin
->GetForegroundColour() : wxColour();
5495 bool wxGenericListCtrl::DoPopupMenu( wxMenu
*menu
, int x
, int y
)
5498 return m_mainWin
->PopupMenu( menu
, x
, y
);
5504 void wxGenericListCtrl::DoClientToScreen( int *x
, int *y
) const
5506 m_mainWin
->DoClientToScreen(x
, y
);
5509 void wxGenericListCtrl::DoScreenToClient( int *x
, int *y
) const
5511 m_mainWin
->DoScreenToClient(x
, y
);
5514 void wxGenericListCtrl::SetFocus()
5516 // The test in window.cpp fails as we are a composite
5517 // window, so it checks against "this", but not m_mainWin.
5518 if ( DoFindFocus() != this )
5519 m_mainWin
->SetFocus();
5522 wxSize
wxGenericListCtrl::DoGetBestSize() const
5524 // Something is better than nothing...
5525 // 100x80 is what the MSW version will get from the default
5526 // wxControl::DoGetBestSize
5527 return wxSize(100, 80);
5530 // ----------------------------------------------------------------------------
5531 // virtual list control support
5532 // ----------------------------------------------------------------------------
5534 wxString
wxGenericListCtrl::OnGetItemText(long WXUNUSED(item
), long WXUNUSED(col
)) const
5536 // this is a pure virtual function, in fact - which is not really pure
5537 // because the controls which are not virtual don't need to implement it
5538 wxFAIL_MSG( _T("wxGenericListCtrl::OnGetItemText not supposed to be called") );
5540 return wxEmptyString
;
5543 int wxGenericListCtrl::OnGetItemImage(long WXUNUSED(item
)) const
5545 wxCHECK_MSG(!GetImageList(wxIMAGE_LIST_SMALL
),
5547 wxT("List control has an image list, OnGetItemImage or OnGetItemColumnImage should be overridden."));
5551 int wxGenericListCtrl::OnGetItemColumnImage(long item
, long column
) const
5554 return OnGetItemImage(item
);
5560 wxGenericListCtrl::OnGetItemAttr(long WXUNUSED_UNLESS_DEBUG(item
)) const
5562 wxASSERT_MSG( item
>= 0 && item
< GetItemCount(),
5563 _T("invalid item index in OnGetItemAttr()") );
5565 // no attributes by default
5569 void wxGenericListCtrl::SetItemCount(long count
)
5571 wxASSERT_MSG( IsVirtual(), _T("this is for virtual controls only") );
5573 m_mainWin
->SetItemCount(count
);
5576 void wxGenericListCtrl::RefreshItem(long item
)
5578 m_mainWin
->RefreshLine(item
);
5581 void wxGenericListCtrl::RefreshItems(long itemFrom
, long itemTo
)
5583 m_mainWin
->RefreshLines(itemFrom
, itemTo
);
5586 // Generic wxListCtrl is more or less a container for two other
5587 // windows which drawings are done upon. These are namely
5588 // 'm_headerWin' and 'm_mainWin'.
5589 // Here we override 'virtual wxWindow::Refresh()' to mimic the
5590 // behaviour wxListCtrl has under wxMSW.
5592 void wxGenericListCtrl::Refresh(bool eraseBackground
, const wxRect
*rect
)
5596 // The easy case, no rectangle specified.
5598 m_headerWin
->Refresh(eraseBackground
);
5601 m_mainWin
->Refresh(eraseBackground
);
5605 // Refresh the header window
5608 wxRect rectHeader
= m_headerWin
->GetRect();
5609 rectHeader
.Intersect(*rect
);
5610 if (rectHeader
.GetWidth() && rectHeader
.GetHeight())
5613 m_headerWin
->GetPosition(&x
, &y
);
5614 rectHeader
.Offset(-x
, -y
);
5615 m_headerWin
->Refresh(eraseBackground
, &rectHeader
);
5619 // Refresh the main window
5622 wxRect rectMain
= m_mainWin
->GetRect();
5623 rectMain
.Intersect(*rect
);
5624 if (rectMain
.GetWidth() && rectMain
.GetHeight())
5627 m_mainWin
->GetPosition(&x
, &y
);
5628 rectMain
.Offset(-x
, -y
);
5629 m_mainWin
->Refresh(eraseBackground
, &rectMain
);
5635 void wxGenericListCtrl::Freeze()
5637 m_mainWin
->Freeze();
5640 void wxGenericListCtrl::Thaw()
5645 #endif // wxUSE_LISTCTRL