1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/generic/listctrl.cpp
3 // Purpose: generic implementation of wxListCtrl
4 // Author: Robert Roebling
5 // Vadim Zeitlin (virtual list control support)
7 // Copyright: (c) 1998 Robert Roebling
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
13 // 1. we need to implement searching/sorting for virtual controls somehow
14 // 2. when changing selection the lines are refreshed twice
17 // For compilers that support precompilation, includes "wx.h".
18 #include "wx/wxprec.h"
26 #include "wx/listctrl.h"
28 #if (!defined(__WXMSW__) || defined(__WXUNIVERSAL__)) && !defined(__WXMAC__)
29 // if we have a native version, its implementation file does all this
30 IMPLEMENT_DYNAMIC_CLASS(wxListItem
, wxObject
)
31 IMPLEMENT_DYNAMIC_CLASS(wxListView
, wxListCtrl
)
32 IMPLEMENT_DYNAMIC_CLASS(wxListEvent
, wxNotifyEvent
)
34 IMPLEMENT_DYNAMIC_CLASS(wxListCtrl
, wxGenericListCtrl
)
38 #include "wx/scrolwin.h"
40 #include "wx/settings.h"
41 #include "wx/dynarray.h"
42 #include "wx/dcclient.h"
43 #include "wx/dcscreen.h"
47 #include "wx/imaglist.h"
48 #include "wx/selstore.h"
49 #include "wx/renderer.h"
52 #include "wx/mac/private.h"
56 // NOTE: If using the wxListBox visual attributes works everywhere then this can
57 // be removed, as well as the #else case below.
58 #define _USE_VISATTR 0
61 // ----------------------------------------------------------------------------
63 // ----------------------------------------------------------------------------
65 // // the height of the header window (FIXME: should depend on its font!)
66 // static const int HEADER_HEIGHT = 23;
68 static const int SCROLL_UNIT_X
= 15;
70 // the spacing between the lines (in report mode)
71 static const int LINE_SPACING
= 0;
73 // extra margins around the text label
74 static const int EXTRA_WIDTH
= 4;
75 static const int EXTRA_HEIGHT
= 4;
77 // margin between the window and the items
78 static const int EXTRA_BORDER_X
= 2;
79 static const int EXTRA_BORDER_Y
= 2;
81 // offset for the header window
82 static const int HEADER_OFFSET_X
= 1;
83 static const int HEADER_OFFSET_Y
= 1;
85 // margin between rows of icons in [small] icon view
86 static const int MARGIN_BETWEEN_ROWS
= 6;
88 // when autosizing the columns, add some slack
89 static const int AUTOSIZE_COL_MARGIN
= 10;
91 // default width for the header columns
92 static const int WIDTH_COL_DEFAULT
= 80;
94 // the space between the image and the text in the report mode
95 static const int IMAGE_MARGIN_IN_REPORT_MODE
= 5;
97 // ============================================================================
99 // ============================================================================
101 //-----------------------------------------------------------------------------
102 // wxColWidthInfo (internal)
103 //-----------------------------------------------------------------------------
105 struct wxColWidthInfo
108 bool bNeedsUpdate
; // only set to true when an item whose
109 // width == nMaxWidth is removed
111 wxColWidthInfo(int w
= 0, bool needsUpdate
= false)
114 bNeedsUpdate
= needsUpdate
;
118 WX_DEFINE_ARRAY_PTR(wxColWidthInfo
*, ColWidthArray
);
120 //-----------------------------------------------------------------------------
121 // wxListItemData (internal)
122 //-----------------------------------------------------------------------------
124 class WXDLLEXPORT wxListItemData
127 wxListItemData(wxListMainWindow
*owner
);
130 void SetItem( const wxListItem
&info
);
131 void SetImage( int image
) { m_image
= image
; }
132 void SetData( wxUIntPtr data
) { m_data
= data
; }
133 void SetPosition( int x
, int y
);
134 void SetSize( int width
, int height
);
136 bool HasText() const { return !m_text
.empty(); }
137 const wxString
& GetText() const { return m_text
; }
138 void SetText(const wxString
& text
) { m_text
= text
; }
140 // we can't use empty string for measuring the string width/height, so
141 // always return something
142 wxString
GetTextForMeasuring() const
144 wxString s
= GetText();
151 bool IsHit( int x
, int y
) const;
155 int GetWidth() const;
156 int GetHeight() const;
158 int GetImage() const { return m_image
; }
159 bool HasImage() const { return GetImage() != -1; }
161 void GetItem( wxListItem
&info
) const;
163 void SetAttr(wxListItemAttr
*attr
) { m_attr
= attr
; }
164 wxListItemAttr
*GetAttr() const { return m_attr
; }
167 // the item image or -1
170 // user data associated with the item
173 // the item coordinates are not used in report mode; instead this pointer is
174 // NULL and the owner window is used to retrieve the item position and size
177 // the list ctrl we are in
178 wxListMainWindow
*m_owner
;
180 // custom attributes or NULL
181 wxListItemAttr
*m_attr
;
184 // common part of all ctors
190 //-----------------------------------------------------------------------------
191 // wxListHeaderData (internal)
192 //-----------------------------------------------------------------------------
194 class WXDLLEXPORT wxListHeaderData
: public wxObject
198 wxListHeaderData( const wxListItem
&info
);
199 void SetItem( const wxListItem
&item
);
200 void SetPosition( int x
, int y
);
201 void SetWidth( int w
);
202 void SetFormat( int format
);
203 void SetHeight( int h
);
204 bool HasImage() const;
206 bool HasText() const { return !m_text
.empty(); }
207 const wxString
& GetText() const { return m_text
; }
208 void SetText(const wxString
& text
) { m_text
= text
; }
210 void GetItem( wxListItem
&item
);
212 bool IsHit( int x
, int y
) const;
213 int GetImage() const;
214 int GetWidth() const;
215 int GetFormat() const;
231 //-----------------------------------------------------------------------------
232 // wxListLineData (internal)
233 //-----------------------------------------------------------------------------
235 WX_DECLARE_EXPORTED_LIST(wxListItemData
, wxListItemDataList
);
236 #include "wx/listimpl.cpp"
237 WX_DEFINE_LIST(wxListItemDataList
)
242 // the list of subitems: only may have more than one item in report mode
243 wxListItemDataList m_items
;
245 // this is not used in report view
257 // the part to be highlighted
258 wxRect m_rectHighlight
;
260 // extend all our rects to be centered inside the one of given width
261 void ExtendWidth(wxCoord w
)
263 wxASSERT_MSG( m_rectAll
.width
<= w
,
264 _T("width can only be increased") );
267 m_rectLabel
.x
= m_rectAll
.x
+ (w
- m_rectLabel
.width
) / 2;
268 m_rectIcon
.x
= m_rectAll
.x
+ (w
- m_rectIcon
.width
) / 2;
269 m_rectHighlight
.x
= m_rectAll
.x
+ (w
- m_rectHighlight
.width
) / 2;
274 // is this item selected? [NB: not used in virtual mode]
277 // back pointer to the list ctrl
278 wxListMainWindow
*m_owner
;
281 wxListLineData(wxListMainWindow
*owner
);
285 WX_CLEAR_LIST(wxListItemDataList
, m_items
);
289 // are we in report mode?
290 inline bool InReportView() const;
292 // are we in virtual report mode?
293 inline bool IsVirtual() const;
295 // these 2 methods shouldn't be called for report view controls, in that
296 // case we determine our position/size ourselves
298 // calculate the size of the line
299 void CalculateSize( wxDC
*dc
, int spacing
);
301 // remember the position this line appears at
302 void SetPosition( int x
, int y
, int spacing
);
306 void SetImage( int image
) { SetImage(0, image
); }
307 int GetImage() const { return GetImage(0); }
308 void SetImage( int index
, int image
);
309 int GetImage( int index
) const;
311 bool HasImage() const { return GetImage() != -1; }
312 bool HasText() const { return !GetText(0).empty(); }
314 void SetItem( int index
, const wxListItem
&info
);
315 void GetItem( int index
, wxListItem
&info
);
317 wxString
GetText(int index
) const;
318 void SetText( int index
, const wxString
& s
);
320 wxListItemAttr
*GetAttr() const;
321 void SetAttr(wxListItemAttr
*attr
);
323 // return true if the highlighting really changed
324 bool Highlight( bool on
);
326 void ReverseHighlight();
328 bool IsHighlighted() const
330 wxASSERT_MSG( !IsVirtual(), _T("unexpected call to IsHighlighted") );
332 return m_highlighted
;
335 // draw the line on the given DC in icon/list mode
336 void Draw( wxDC
*dc
);
338 // the same in report mode
339 void DrawInReportMode( wxDC
*dc
,
341 const wxRect
& rectHL
,
345 // set the line to contain num items (only can be > 1 in report mode)
346 void InitItems( int num
);
348 // get the mode (i.e. style) of the list control
349 inline int GetMode() const;
351 // prepare the DC for drawing with these item's attributes, return true if
352 // we need to draw the items background to highlight it, false otherwise
353 bool SetAttributes(wxDC
*dc
,
354 const wxListItemAttr
*attr
,
357 // draw the text on the DC with the correct justification; also add an
358 // ellipsis if the text is too large to fit in the current width
359 void DrawTextFormatted(wxDC
*dc
,
360 const wxString
&text
,
363 int yMid
, // this is middle, not top, of the text
367 WX_DECLARE_EXPORTED_OBJARRAY(wxListLineData
, wxListLineDataArray
);
368 #include "wx/arrimpl.cpp"
369 WX_DEFINE_OBJARRAY(wxListLineDataArray
)
371 //-----------------------------------------------------------------------------
372 // wxListHeaderWindow (internal)
373 //-----------------------------------------------------------------------------
375 class WXDLLEXPORT wxListHeaderWindow
: public wxWindow
378 wxListMainWindow
*m_owner
;
379 const wxCursor
*m_currentCursor
;
380 wxCursor
*m_resizeCursor
;
383 // column being resized or -1
386 // divider line position in logical (unscrolled) coords
389 // minimal position beyond which the divider line
390 // can't be dragged in logical coords
394 wxListHeaderWindow();
396 wxListHeaderWindow( wxWindow
*win
,
398 wxListMainWindow
*owner
,
399 const wxPoint
&pos
= wxDefaultPosition
,
400 const wxSize
&size
= wxDefaultSize
,
402 const wxString
&name
= wxT("wxlistctrlcolumntitles") );
404 virtual ~wxListHeaderWindow();
407 void AdjustDC( wxDC
& dc
);
409 void OnPaint( wxPaintEvent
&event
);
410 void OnMouse( wxMouseEvent
&event
);
411 void OnSetFocus( wxFocusEvent
&event
);
417 // common part of all ctors
420 // generate and process the list event of the given type, return true if
421 // it wasn't vetoed, i.e. if we should proceed
422 bool SendListEvent(wxEventType type
, const wxPoint
& pos
);
424 DECLARE_DYNAMIC_CLASS(wxListHeaderWindow
)
425 DECLARE_EVENT_TABLE()
428 //-----------------------------------------------------------------------------
429 // wxListRenameTimer (internal)
430 //-----------------------------------------------------------------------------
432 class WXDLLEXPORT wxListRenameTimer
: public wxTimer
435 wxListMainWindow
*m_owner
;
438 wxListRenameTimer( wxListMainWindow
*owner
);
442 //-----------------------------------------------------------------------------
443 // wxListTextCtrlWrapper: wraps a wxTextCtrl to make it work for inline editing
444 //-----------------------------------------------------------------------------
446 class WXDLLEXPORT wxListTextCtrlWrapper
: public wxEvtHandler
449 // NB: text must be a valid object but not Create()d yet
450 wxListTextCtrlWrapper(wxListMainWindow
*owner
,
454 wxTextCtrl
*GetText() const { return m_text
; }
456 void AcceptChangesAndFinish();
459 void OnChar( wxKeyEvent
&event
);
460 void OnKeyUp( wxKeyEvent
&event
);
461 void OnKillFocus( wxFocusEvent
&event
);
463 bool AcceptChanges();
467 wxListMainWindow
*m_owner
;
469 wxString m_startValue
;
472 bool m_aboutToFinish
;
474 DECLARE_EVENT_TABLE()
477 //-----------------------------------------------------------------------------
478 // wxListMainWindow (internal)
479 //-----------------------------------------------------------------------------
481 WX_DECLARE_EXPORTED_LIST(wxListHeaderData
, wxListHeaderDataList
);
482 #include "wx/listimpl.cpp"
483 WX_DEFINE_LIST(wxListHeaderDataList
)
485 class wxListMainWindow
: public wxScrolledWindow
489 wxListMainWindow( wxWindow
*parent
,
491 const wxPoint
& pos
= wxDefaultPosition
,
492 const wxSize
& size
= wxDefaultSize
,
494 const wxString
&name
= _T("listctrlmainwindow") );
496 virtual ~wxListMainWindow();
498 bool HasFlag(int flag
) const { return m_parent
->HasFlag(flag
); }
500 // return true if this is a virtual list control
501 bool IsVirtual() const { return HasFlag(wxLC_VIRTUAL
); }
503 // return true if the control is in report mode
504 bool InReportView() const { return HasFlag(wxLC_REPORT
); }
506 // return true if we are in single selection mode, false if multi sel
507 bool IsSingleSel() const { return HasFlag(wxLC_SINGLE_SEL
); }
509 // do we have a header window?
510 bool HasHeader() const
511 { return InReportView() && !HasFlag(wxLC_NO_HEADER
); }
513 void HighlightAll( bool on
);
515 // all these functions only do something if the line is currently visible
517 // change the line "selected" state, return true if it really changed
518 bool HighlightLine( size_t line
, bool highlight
= true);
520 // as HighlightLine() but do it for the range of lines: this is incredibly
521 // more efficient for virtual list controls!
523 // NB: unlike HighlightLine() this one does refresh the lines on screen
524 void HighlightLines( size_t lineFrom
, size_t lineTo
, bool on
= true );
526 // toggle the line state and refresh it
527 void ReverseHighlight( size_t line
)
528 { HighlightLine(line
, !IsHighlighted(line
)); RefreshLine(line
); }
530 // return true if the line is highlighted
531 bool IsHighlighted(size_t line
) const;
533 // refresh one or several lines at once
534 void RefreshLine( size_t line
);
535 void RefreshLines( size_t lineFrom
, size_t lineTo
);
537 // refresh all selected items
538 void RefreshSelected();
540 // refresh all lines below the given one: the difference with
541 // RefreshLines() is that the index here might not be a valid one (happens
542 // when the last line is deleted)
543 void RefreshAfter( size_t lineFrom
);
545 // the methods which are forwarded to wxListLineData itself in list/icon
546 // modes but are here because the lines don't store their positions in the
549 // get the bound rect for the entire line
550 wxRect
GetLineRect(size_t line
) const;
552 // get the bound rect of the label
553 wxRect
GetLineLabelRect(size_t line
) const;
555 // get the bound rect of the items icon (only may be called if we do have
557 wxRect
GetLineIconRect(size_t line
) const;
559 // get the rect to be highlighted when the item has focus
560 wxRect
GetLineHighlightRect(size_t line
) const;
562 // get the size of the total line rect
563 wxSize
GetLineSize(size_t line
) const
564 { return GetLineRect(line
).GetSize(); }
566 // return the hit code for the corresponding position (in this line)
567 long HitTestLine(size_t line
, int x
, int y
) const;
569 // bring the selected item into view, scrolling to it if necessary
570 void MoveToItem(size_t item
);
572 // bring the current item into view
573 void MoveToFocus() { MoveToItem(m_current
); }
575 // start editing the label of the given item
576 wxTextCtrl
*EditLabel(long item
,
577 wxClassInfo
* textControlClass
= CLASSINFO(wxTextCtrl
));
578 wxTextCtrl
*GetEditControl() const
580 return m_textctrlWrapper
? m_textctrlWrapper
->GetText() : NULL
;
583 void FinishEditing(wxTextCtrl
*text
)
586 m_textctrlWrapper
= NULL
;
587 SetFocusIgnoringChildren();
590 // suspend/resume redrawing the control
594 void OnRenameTimer();
595 bool OnRenameAccept(size_t itemEdit
, const wxString
& value
);
596 void OnRenameCancelled(size_t itemEdit
);
598 void OnMouse( wxMouseEvent
&event
);
600 // called to switch the selection from the current item to newCurrent,
601 void OnArrowChar( size_t newCurrent
, const wxKeyEvent
& event
);
603 void OnChar( wxKeyEvent
&event
);
604 void OnKeyDown( wxKeyEvent
&event
);
605 void OnSetFocus( wxFocusEvent
&event
);
606 void OnKillFocus( wxFocusEvent
&event
);
607 void OnScroll( wxScrollWinEvent
& event
);
609 void OnPaint( wxPaintEvent
&event
);
611 void DrawImage( int index
, wxDC
*dc
, int x
, int y
);
612 void GetImageSize( int index
, int &width
, int &height
) const;
613 int GetTextLength( const wxString
&s
) const;
615 void SetImageList( wxImageList
*imageList
, int which
);
616 void SetItemSpacing( int spacing
, bool isSmall
= false );
617 int GetItemSpacing( bool isSmall
= false );
619 void SetColumn( int col
, wxListItem
&item
);
620 void SetColumnWidth( int col
, int width
);
621 void GetColumn( int col
, wxListItem
&item
) const;
622 int GetColumnWidth( int col
) const;
623 int GetColumnCount() const { return m_columns
.GetCount(); }
625 // returns the sum of the heights of all columns
626 int GetHeaderWidth() const;
628 int GetCountPerPage() const;
630 void SetItem( wxListItem
&item
);
631 void GetItem( wxListItem
&item
) const;
632 void SetItemState( long item
, long state
, long stateMask
);
633 void SetItemStateAll( long state
, long stateMask
);
634 int GetItemState( long item
, long stateMask
) const;
635 void GetItemRect( long index
, wxRect
&rect
) const;
636 wxRect
GetViewRect() const;
637 bool GetItemPosition( long item
, wxPoint
& pos
) const;
638 int GetSelectedItemCount() const;
640 wxString
GetItemText(long item
) const
643 info
.m_mask
= wxLIST_MASK_TEXT
;
644 info
.m_itemId
= item
;
649 void SetItemText(long item
, const wxString
& value
)
652 info
.m_mask
= wxLIST_MASK_TEXT
;
653 info
.m_itemId
= item
;
658 // set the scrollbars and update the positions of the items
659 void RecalculatePositions(bool noRefresh
= false);
661 // refresh the window and the header
664 long GetNextItem( long item
, int geometry
, int state
) const;
665 void DeleteItem( long index
);
666 void DeleteAllItems();
667 void DeleteColumn( int col
);
668 void DeleteEverything();
669 void EnsureVisible( long index
);
670 long FindItem( long start
, const wxString
& str
, bool partial
= false );
671 long FindItem( long start
, wxUIntPtr data
);
672 long FindItem( const wxPoint
& pt
);
673 long HitTest( int x
, int y
, int &flags
) const;
674 void InsertItem( wxListItem
&item
);
675 void InsertColumn( long col
, wxListItem
&item
);
676 int GetItemWidthWithImage(wxListItem
* item
);
677 void SortItems( wxListCtrlCompare fn
, long data
);
679 size_t GetItemCount() const;
680 bool IsEmpty() const { return GetItemCount() == 0; }
681 void SetItemCount(long count
);
683 // change the current (== focused) item, send a notification event
684 void ChangeCurrent(size_t current
);
685 void ResetCurrent() { ChangeCurrent((size_t)-1); }
686 bool HasCurrent() const { return m_current
!= (size_t)-1; }
688 // send out a wxListEvent
689 void SendNotify( size_t line
,
691 const wxPoint
& point
= wxDefaultPosition
);
693 // override base class virtual to reset m_lineHeight when the font changes
694 virtual bool SetFont(const wxFont
& font
)
696 if ( !wxScrolledWindow::SetFont(font
) )
704 // these are for wxListLineData usage only
706 // get the backpointer to the list ctrl
707 wxGenericListCtrl
*GetListCtrl() const
709 return wxStaticCast(GetParent(), wxGenericListCtrl
);
712 // get the height of all lines (assuming they all do have the same height)
713 wxCoord
GetLineHeight() const;
715 // get the y position of the given line (only for report view)
716 wxCoord
GetLineY(size_t line
) const;
718 // get the brush to use for the item highlighting
719 wxBrush
*GetHighlightBrush() const
721 return m_hasFocus
? m_highlightBrush
: m_highlightUnfocusedBrush
;
725 // the array of all line objects for a non virtual list control (for the
726 // virtual list control we only ever use m_lines[0])
727 wxListLineDataArray m_lines
;
729 // the list of column objects
730 wxListHeaderDataList m_columns
;
732 // currently focused item or -1
735 // the number of lines per page
738 // this flag is set when something which should result in the window
739 // redrawing happens (i.e. an item was added or deleted, or its appearance
740 // changed) and OnPaint() doesn't redraw the window while it is set which
741 // allows to minimize the number of repaintings when a lot of items are
742 // being added. The real repainting occurs only after the next OnIdle()
746 wxColour
*m_highlightColour
;
747 wxImageList
*m_small_image_list
;
748 wxImageList
*m_normal_image_list
;
750 int m_normal_spacing
;
754 wxTimer
*m_renameTimer
;
758 ColWidthArray m_aColWidths
;
760 // for double click logic
761 size_t m_lineLastClicked
,
762 m_lineBeforeLastClicked
,
763 m_lineSelectSingleOnUp
;
766 wxWindow
*GetMainWindowOfCompositeControl() { return GetParent(); }
768 // the total count of items in a virtual list control
771 // the object maintaining the items selection state, only used in virtual
773 wxSelectionStore m_selStore
;
775 // common part of all ctors
778 // get the line data for the given index
779 wxListLineData
*GetLine(size_t n
) const
781 wxASSERT_MSG( n
!= (size_t)-1, _T("invalid line index") );
785 wxConstCast(this, wxListMainWindow
)->CacheLineData(n
);
792 // get a dummy line which can be used for geometry calculations and such:
793 // you must use GetLine() if you want to really draw the line
794 wxListLineData
*GetDummyLine() const;
796 // cache the line data of the n-th line in m_lines[0]
797 void CacheLineData(size_t line
);
799 // get the range of visible lines
800 void GetVisibleLinesRange(size_t *from
, size_t *to
);
802 // force us to recalculate the range of visible lines
803 void ResetVisibleLinesRange() { m_lineFrom
= (size_t)-1; }
805 // get the colour to be used for drawing the rules
806 wxColour
GetRuleColour() const
808 return wxSystemSettings::GetColour(wxSYS_COLOUR_3DLIGHT
);
812 // initialize the current item if needed
813 void UpdateCurrent();
815 // delete all items but don't refresh: called from dtor
816 void DoDeleteAllItems();
818 // the height of one line using the current font
819 wxCoord m_lineHeight
;
821 // the total header width or 0 if not calculated yet
822 wxCoord m_headerWidth
;
824 // the first and last lines being shown on screen right now (inclusive),
825 // both may be -1 if they must be calculated so never access them directly:
826 // use GetVisibleLinesRange() above instead
830 // the brushes to use for item highlighting when we do/don't have focus
831 wxBrush
*m_highlightBrush
,
832 *m_highlightUnfocusedBrush
;
834 // if this is > 0, the control is frozen and doesn't redraw itself
835 size_t m_freezeCount
;
837 // wrapper around the text control currently used for in place editing or
838 // NULL if no item is being edited
839 wxListTextCtrlWrapper
*m_textctrlWrapper
;
842 DECLARE_DYNAMIC_CLASS(wxListMainWindow
)
843 DECLARE_EVENT_TABLE()
845 friend class wxGenericListCtrl
;
849 wxListItemData::~wxListItemData()
851 // in the virtual list control the attributes are managed by the main
852 // program, so don't delete them
853 if ( !m_owner
->IsVirtual() )
859 void wxListItemData::Init()
867 wxListItemData::wxListItemData(wxListMainWindow
*owner
)
873 if ( owner
->InReportView() )
879 void wxListItemData::SetItem( const wxListItem
&info
)
881 if ( info
.m_mask
& wxLIST_MASK_TEXT
)
882 SetText(info
.m_text
);
883 if ( info
.m_mask
& wxLIST_MASK_IMAGE
)
884 m_image
= info
.m_image
;
885 if ( info
.m_mask
& wxLIST_MASK_DATA
)
886 m_data
= info
.m_data
;
888 if ( info
.HasAttributes() )
891 *m_attr
= *info
.GetAttributes();
893 m_attr
= new wxListItemAttr(*info
.GetAttributes());
901 m_rect
->width
= info
.m_width
;
905 void wxListItemData::SetPosition( int x
, int y
)
907 wxCHECK_RET( m_rect
, _T("unexpected SetPosition() call") );
913 void wxListItemData::SetSize( int width
, int height
)
915 wxCHECK_RET( m_rect
, _T("unexpected SetSize() call") );
918 m_rect
->width
= width
;
920 m_rect
->height
= height
;
923 bool wxListItemData::IsHit( int x
, int y
) const
925 wxCHECK_MSG( m_rect
, false, _T("can't be called in this mode") );
927 return wxRect(GetX(), GetY(), GetWidth(), GetHeight()).Contains(x
, y
);
930 int wxListItemData::GetX() const
932 wxCHECK_MSG( m_rect
, 0, _T("can't be called in this mode") );
937 int wxListItemData::GetY() const
939 wxCHECK_MSG( m_rect
, 0, _T("can't be called in this mode") );
944 int wxListItemData::GetWidth() const
946 wxCHECK_MSG( m_rect
, 0, _T("can't be called in this mode") );
948 return m_rect
->width
;
951 int wxListItemData::GetHeight() const
953 wxCHECK_MSG( m_rect
, 0, _T("can't be called in this mode") );
955 return m_rect
->height
;
958 void wxListItemData::GetItem( wxListItem
&info
) const
960 long mask
= info
.m_mask
;
962 // by default, get everything for backwards compatibility
965 if ( mask
& wxLIST_MASK_TEXT
)
966 info
.m_text
= m_text
;
967 if ( mask
& wxLIST_MASK_IMAGE
)
968 info
.m_image
= m_image
;
969 if ( mask
& wxLIST_MASK_DATA
)
970 info
.m_data
= m_data
;
974 if ( m_attr
->HasTextColour() )
975 info
.SetTextColour(m_attr
->GetTextColour());
976 if ( m_attr
->HasBackgroundColour() )
977 info
.SetBackgroundColour(m_attr
->GetBackgroundColour());
978 if ( m_attr
->HasFont() )
979 info
.SetFont(m_attr
->GetFont());
983 //-----------------------------------------------------------------------------
985 //-----------------------------------------------------------------------------
987 void wxListHeaderData::Init()
998 wxListHeaderData::wxListHeaderData()
1003 wxListHeaderData::wxListHeaderData( const wxListItem
&item
)
1010 void wxListHeaderData::SetItem( const wxListItem
&item
)
1012 m_mask
= item
.m_mask
;
1014 if ( m_mask
& wxLIST_MASK_TEXT
)
1015 m_text
= item
.m_text
;
1017 if ( m_mask
& wxLIST_MASK_IMAGE
)
1018 m_image
= item
.m_image
;
1020 if ( m_mask
& wxLIST_MASK_FORMAT
)
1021 m_format
= item
.m_format
;
1023 if ( m_mask
& wxLIST_MASK_WIDTH
)
1024 SetWidth(item
.m_width
);
1027 void wxListHeaderData::SetPosition( int x
, int y
)
1033 void wxListHeaderData::SetHeight( int h
)
1038 void wxListHeaderData::SetWidth( int w
)
1040 m_width
= w
< 0 ? WIDTH_COL_DEFAULT
: w
;
1043 void wxListHeaderData::SetFormat( int format
)
1048 bool wxListHeaderData::HasImage() const
1050 return m_image
!= -1;
1053 bool wxListHeaderData::IsHit( int x
, int y
) const
1055 return ((x
>= m_xpos
) && (x
<= m_xpos
+m_width
) && (y
>= m_ypos
) && (y
<= m_ypos
+m_height
));
1058 void wxListHeaderData::GetItem( wxListItem
& item
)
1060 item
.m_mask
= m_mask
;
1061 item
.m_text
= m_text
;
1062 item
.m_image
= m_image
;
1063 item
.m_format
= m_format
;
1064 item
.m_width
= m_width
;
1067 int wxListHeaderData::GetImage() const
1072 int wxListHeaderData::GetWidth() const
1077 int wxListHeaderData::GetFormat() const
1082 //-----------------------------------------------------------------------------
1084 //-----------------------------------------------------------------------------
1086 inline int wxListLineData::GetMode() const
1088 return m_owner
->GetListCtrl()->GetWindowStyleFlag() & wxLC_MASK_TYPE
;
1091 inline bool wxListLineData::InReportView() const
1093 return m_owner
->HasFlag(wxLC_REPORT
);
1096 inline bool wxListLineData::IsVirtual() const
1098 return m_owner
->IsVirtual();
1101 wxListLineData::wxListLineData( wxListMainWindow
*owner
)
1105 if ( InReportView() )
1108 m_gi
= new GeometryInfo
;
1110 m_highlighted
= false;
1112 InitItems( GetMode() == wxLC_REPORT
? m_owner
->GetColumnCount() : 1 );
1115 void wxListLineData::CalculateSize( wxDC
*dc
, int spacing
)
1117 wxListItemDataList::compatibility_iterator node
= m_items
.GetFirst();
1118 wxCHECK_RET( node
, _T("no subitems at all??") );
1120 wxListItemData
*item
= node
->GetData();
1125 switch ( GetMode() )
1128 case wxLC_SMALL_ICON
:
1129 m_gi
->m_rectAll
.width
= spacing
;
1131 s
= item
->GetText();
1136 m_gi
->m_rectLabel
.width
=
1137 m_gi
->m_rectLabel
.height
= 0;
1141 dc
->GetTextExtent( s
, &lw
, &lh
);
1145 m_gi
->m_rectAll
.height
= spacing
+ lh
;
1147 m_gi
->m_rectAll
.width
= lw
;
1149 m_gi
->m_rectLabel
.width
= lw
;
1150 m_gi
->m_rectLabel
.height
= lh
;
1153 if (item
->HasImage())
1156 m_owner
->GetImageSize( item
->GetImage(), w
, h
);
1157 m_gi
->m_rectIcon
.width
= w
+ 8;
1158 m_gi
->m_rectIcon
.height
= h
+ 8;
1160 if ( m_gi
->m_rectIcon
.width
> m_gi
->m_rectAll
.width
)
1161 m_gi
->m_rectAll
.width
= m_gi
->m_rectIcon
.width
;
1162 if ( m_gi
->m_rectIcon
.height
+ lh
> m_gi
->m_rectAll
.height
- 4 )
1163 m_gi
->m_rectAll
.height
= m_gi
->m_rectIcon
.height
+ lh
+ 4;
1166 if ( item
->HasText() )
1168 m_gi
->m_rectHighlight
.width
= m_gi
->m_rectLabel
.width
;
1169 m_gi
->m_rectHighlight
.height
= m_gi
->m_rectLabel
.height
;
1171 else // no text, highlight the icon
1173 m_gi
->m_rectHighlight
.width
= m_gi
->m_rectIcon
.width
;
1174 m_gi
->m_rectHighlight
.height
= m_gi
->m_rectIcon
.height
;
1179 s
= item
->GetTextForMeasuring();
1181 dc
->GetTextExtent( s
, &lw
, &lh
);
1185 m_gi
->m_rectLabel
.width
= lw
;
1186 m_gi
->m_rectLabel
.height
= lh
;
1188 m_gi
->m_rectAll
.width
= lw
;
1189 m_gi
->m_rectAll
.height
= lh
;
1191 if (item
->HasImage())
1194 m_owner
->GetImageSize( item
->GetImage(), w
, h
);
1195 m_gi
->m_rectIcon
.width
= w
;
1196 m_gi
->m_rectIcon
.height
= h
;
1198 m_gi
->m_rectAll
.width
+= 4 + w
;
1199 if (h
> m_gi
->m_rectAll
.height
)
1200 m_gi
->m_rectAll
.height
= h
;
1203 m_gi
->m_rectHighlight
.width
= m_gi
->m_rectAll
.width
;
1204 m_gi
->m_rectHighlight
.height
= m_gi
->m_rectAll
.height
;
1208 wxFAIL_MSG( _T("unexpected call to SetSize") );
1212 wxFAIL_MSG( _T("unknown mode") );
1217 void wxListLineData::SetPosition( int x
, int y
, int spacing
)
1219 wxListItemDataList::compatibility_iterator node
= m_items
.GetFirst();
1220 wxCHECK_RET( node
, _T("no subitems at all??") );
1222 wxListItemData
*item
= node
->GetData();
1224 switch ( GetMode() )
1227 case wxLC_SMALL_ICON
:
1228 m_gi
->m_rectAll
.x
= x
;
1229 m_gi
->m_rectAll
.y
= y
;
1231 if ( item
->HasImage() )
1233 m_gi
->m_rectIcon
.x
= m_gi
->m_rectAll
.x
+ 4 +
1234 (m_gi
->m_rectAll
.width
- m_gi
->m_rectIcon
.width
) / 2;
1235 m_gi
->m_rectIcon
.y
= m_gi
->m_rectAll
.y
+ 4;
1238 if ( item
->HasText() )
1240 if (m_gi
->m_rectAll
.width
> spacing
)
1241 m_gi
->m_rectLabel
.x
= m_gi
->m_rectAll
.x
+ 2;
1243 m_gi
->m_rectLabel
.x
= m_gi
->m_rectAll
.x
+ 2 + (spacing
/ 2) - (m_gi
->m_rectLabel
.width
/ 2);
1244 m_gi
->m_rectLabel
.y
= m_gi
->m_rectAll
.y
+ m_gi
->m_rectAll
.height
+ 2 - m_gi
->m_rectLabel
.height
;
1245 m_gi
->m_rectHighlight
.x
= m_gi
->m_rectLabel
.x
- 2;
1246 m_gi
->m_rectHighlight
.y
= m_gi
->m_rectLabel
.y
- 2;
1248 else // no text, highlight the icon
1250 m_gi
->m_rectHighlight
.x
= m_gi
->m_rectIcon
.x
- 4;
1251 m_gi
->m_rectHighlight
.y
= m_gi
->m_rectIcon
.y
- 4;
1256 m_gi
->m_rectAll
.x
= x
;
1257 m_gi
->m_rectAll
.y
= y
;
1259 m_gi
->m_rectHighlight
.x
= m_gi
->m_rectAll
.x
;
1260 m_gi
->m_rectHighlight
.y
= m_gi
->m_rectAll
.y
;
1261 m_gi
->m_rectLabel
.y
= m_gi
->m_rectAll
.y
+ 2;
1263 if (item
->HasImage())
1265 m_gi
->m_rectIcon
.x
= m_gi
->m_rectAll
.x
+ 2;
1266 m_gi
->m_rectIcon
.y
= m_gi
->m_rectAll
.y
+ 2;
1267 m_gi
->m_rectLabel
.x
= m_gi
->m_rectAll
.x
+ 6 + m_gi
->m_rectIcon
.width
;
1271 m_gi
->m_rectLabel
.x
= m_gi
->m_rectAll
.x
+ 2;
1276 wxFAIL_MSG( _T("unexpected call to SetPosition") );
1280 wxFAIL_MSG( _T("unknown mode") );
1285 void wxListLineData::InitItems( int num
)
1287 for (int i
= 0; i
< num
; i
++)
1288 m_items
.Append( new wxListItemData(m_owner
) );
1291 void wxListLineData::SetItem( int index
, const wxListItem
&info
)
1293 wxListItemDataList::compatibility_iterator node
= m_items
.Item( index
);
1294 wxCHECK_RET( node
, _T("invalid column index in SetItem") );
1296 wxListItemData
*item
= node
->GetData();
1297 item
->SetItem( info
);
1300 void wxListLineData::GetItem( int index
, wxListItem
&info
)
1302 wxListItemDataList::compatibility_iterator node
= m_items
.Item( index
);
1305 wxListItemData
*item
= node
->GetData();
1306 item
->GetItem( info
);
1310 wxString
wxListLineData::GetText(int index
) const
1314 wxListItemDataList::compatibility_iterator node
= m_items
.Item( index
);
1317 wxListItemData
*item
= node
->GetData();
1318 s
= item
->GetText();
1324 void wxListLineData::SetText( int index
, const wxString
& s
)
1326 wxListItemDataList::compatibility_iterator node
= m_items
.Item( index
);
1329 wxListItemData
*item
= node
->GetData();
1334 void wxListLineData::SetImage( int index
, int image
)
1336 wxListItemDataList::compatibility_iterator node
= m_items
.Item( index
);
1337 wxCHECK_RET( node
, _T("invalid column index in SetImage()") );
1339 wxListItemData
*item
= node
->GetData();
1340 item
->SetImage(image
);
1343 int wxListLineData::GetImage( int index
) const
1345 wxListItemDataList::compatibility_iterator node
= m_items
.Item( index
);
1346 wxCHECK_MSG( node
, -1, _T("invalid column index in GetImage()") );
1348 wxListItemData
*item
= node
->GetData();
1349 return item
->GetImage();
1352 wxListItemAttr
*wxListLineData::GetAttr() const
1354 wxListItemDataList::compatibility_iterator node
= m_items
.GetFirst();
1355 wxCHECK_MSG( node
, NULL
, _T("invalid column index in GetAttr()") );
1357 wxListItemData
*item
= node
->GetData();
1358 return item
->GetAttr();
1361 void wxListLineData::SetAttr(wxListItemAttr
*attr
)
1363 wxListItemDataList::compatibility_iterator node
= m_items
.GetFirst();
1364 wxCHECK_RET( node
, _T("invalid column index in SetAttr()") );
1366 wxListItemData
*item
= node
->GetData();
1367 item
->SetAttr(attr
);
1370 bool wxListLineData::SetAttributes(wxDC
*dc
,
1371 const wxListItemAttr
*attr
,
1374 wxWindow
*listctrl
= m_owner
->GetParent();
1378 // don't use foreground colour for drawing highlighted items - this might
1379 // make them completely invisible (and there is no way to do bit
1380 // arithmetics on wxColour, unfortunately)
1383 colText
= wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHTTEXT
);
1384 else if ( attr
&& attr
->HasTextColour() )
1385 colText
= attr
->GetTextColour();
1387 colText
= listctrl
->GetForegroundColour();
1389 dc
->SetTextForeground(colText
);
1393 if ( attr
&& attr
->HasFont() )
1394 font
= attr
->GetFont();
1396 font
= listctrl
->GetFont();
1401 bool hasBgCol
= attr
&& attr
->HasBackgroundColour();
1402 if ( highlighted
|| hasBgCol
)
1405 dc
->SetBrush( *m_owner
->GetHighlightBrush() );
1407 dc
->SetBrush(wxBrush(attr
->GetBackgroundColour(), wxSOLID
));
1409 dc
->SetPen( *wxTRANSPARENT_PEN
);
1417 void wxListLineData::Draw( wxDC
*dc
)
1419 wxListItemDataList::compatibility_iterator node
= m_items
.GetFirst();
1420 wxCHECK_RET( node
, _T("no subitems at all??") );
1422 bool highlighted
= IsHighlighted();
1424 wxListItemAttr
*attr
= GetAttr();
1426 if ( SetAttributes(dc
, attr
, highlighted
) )
1427 dc
->DrawRectangle( m_gi
->m_rectHighlight
);
1429 // just for debugging to better see where the items are
1431 dc
->SetPen(*wxRED_PEN
);
1432 dc
->SetBrush(*wxTRANSPARENT_BRUSH
);
1433 dc
->DrawRectangle( m_gi
->m_rectAll
);
1434 dc
->SetPen(*wxGREEN_PEN
);
1435 dc
->DrawRectangle( m_gi
->m_rectIcon
);
1438 wxListItemData
*item
= node
->GetData();
1439 if (item
->HasImage())
1441 // centre the image inside our rectangle, this looks nicer when items
1442 // ae aligned in a row
1443 const wxRect
& rectIcon
= m_gi
->m_rectIcon
;
1445 m_owner
->DrawImage(item
->GetImage(), dc
, rectIcon
.x
, rectIcon
.y
);
1448 if (item
->HasText())
1450 const wxRect
& rectLabel
= m_gi
->m_rectLabel
;
1452 wxDCClipper
clipper(*dc
, rectLabel
);
1453 dc
->DrawText(item
->GetText(), rectLabel
.x
, rectLabel
.y
);
1457 void wxListLineData::DrawInReportMode( wxDC
*dc
,
1459 const wxRect
& rectHL
,
1462 // TODO: later we should support setting different attributes for
1463 // different columns - to do it, just add "col" argument to
1464 // GetAttr() and move these lines into the loop below
1465 wxListItemAttr
*attr
= GetAttr();
1466 if ( SetAttributes(dc
, attr
, highlighted
) )
1467 dc
->DrawRectangle( rectHL
);
1469 wxCoord x
= rect
.x
+ HEADER_OFFSET_X
,
1470 yMid
= rect
.y
+ rect
.height
/2;
1473 for ( wxListItemDataList::compatibility_iterator node
= m_items
.GetFirst();
1475 node
= node
->GetNext(), col
++ )
1477 wxListItemData
*item
= node
->GetData();
1479 int width
= m_owner
->GetColumnWidth(col
);
1483 if ( item
->HasImage() )
1486 m_owner
->GetImageSize( item
->GetImage(), ix
, iy
);
1487 m_owner
->DrawImage( item
->GetImage(), dc
, xOld
, yMid
- iy
/2 );
1489 ix
+= IMAGE_MARGIN_IN_REPORT_MODE
;
1495 if ( item
->HasText() )
1496 DrawTextFormatted(dc
, item
->GetText(), col
, xOld
, yMid
, width
- 8);
1500 void wxListLineData::DrawTextFormatted(wxDC
*dc
,
1501 const wxString
&text
,
1508 dc
->GetTextExtent(text
, &w
, &h
);
1510 const wxCoord y
= yMid
- (h
+ 1)/2;
1512 wxDCClipper
clipper(*dc
, x
, y
, width
, h
);
1514 // determine if the string can fit inside the current width
1517 // it can, draw it using the items alignment
1519 m_owner
->GetColumn(col
, item
);
1520 switch ( item
.GetAlign() )
1522 case wxLIST_FORMAT_LEFT
:
1526 case wxLIST_FORMAT_RIGHT
:
1530 case wxLIST_FORMAT_CENTER
:
1531 x
+= (width
- w
) / 2;
1535 wxFAIL_MSG( _T("unknown list item format") );
1539 dc
->DrawText(text
, x
, y
);
1541 else // otherwise, truncate and add an ellipsis if possible
1543 // determine the base width
1544 wxString
ellipsis(wxT("..."));
1546 dc
->GetTextExtent(ellipsis
, &base_w
, &h
);
1548 // continue until we have enough space or only one character left
1550 size_t len
= text
.length();
1551 wxString drawntext
= text
.Left(len
);
1554 dc
->GetTextExtent(drawntext
.Last(), &w_c
, &h_c
);
1555 drawntext
.RemoveLast();
1558 if (w
+ base_w
<= width
)
1562 // if still not enough space, remove ellipsis characters
1563 while (ellipsis
.length() > 0 && w
+ base_w
> width
)
1565 ellipsis
= ellipsis
.Left(ellipsis
.length() - 1);
1566 dc
->GetTextExtent(ellipsis
, &base_w
, &h
);
1569 // now draw the text
1570 dc
->DrawText(drawntext
, x
, y
);
1571 dc
->DrawText(ellipsis
, x
+ w
, y
);
1575 bool wxListLineData::Highlight( bool on
)
1577 wxCHECK_MSG( !IsVirtual(), false, _T("unexpected call to Highlight") );
1579 if ( on
== m_highlighted
)
1587 void wxListLineData::ReverseHighlight( void )
1589 Highlight(!IsHighlighted());
1592 //-----------------------------------------------------------------------------
1593 // wxListHeaderWindow
1594 //-----------------------------------------------------------------------------
1596 IMPLEMENT_DYNAMIC_CLASS(wxListHeaderWindow
,wxWindow
)
1598 BEGIN_EVENT_TABLE(wxListHeaderWindow
,wxWindow
)
1599 EVT_PAINT (wxListHeaderWindow::OnPaint
)
1600 EVT_MOUSE_EVENTS (wxListHeaderWindow::OnMouse
)
1601 EVT_SET_FOCUS (wxListHeaderWindow::OnSetFocus
)
1604 void wxListHeaderWindow::Init()
1606 m_currentCursor
= (wxCursor
*) NULL
;
1607 m_isDragging
= false;
1611 wxListHeaderWindow::wxListHeaderWindow()
1615 m_owner
= (wxListMainWindow
*) NULL
;
1616 m_resizeCursor
= (wxCursor
*) NULL
;
1619 wxListHeaderWindow::wxListHeaderWindow( wxWindow
*win
,
1621 wxListMainWindow
*owner
,
1625 const wxString
&name
)
1626 : wxWindow( win
, id
, pos
, size
, style
, name
)
1631 m_resizeCursor
= new wxCursor( wxCURSOR_SIZEWE
);
1634 wxVisualAttributes attr
= wxPanel::GetClassDefaultAttributes();
1635 SetOwnForegroundColour( attr
.colFg
);
1636 SetOwnBackgroundColour( attr
.colBg
);
1638 SetOwnFont( attr
.font
);
1640 SetOwnForegroundColour( wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT
));
1641 SetOwnBackgroundColour( wxSystemSettings::GetColour(wxSYS_COLOUR_BTNFACE
));
1643 SetOwnFont( wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT
));
1647 wxListHeaderWindow::~wxListHeaderWindow()
1649 delete m_resizeCursor
;
1652 #ifdef __WXUNIVERSAL__
1653 #include "wx/univ/renderer.h"
1654 #include "wx/univ/theme.h"
1657 // shift the DC origin to match the position of the main window horz
1658 // scrollbar: this allows us to always use logical coords
1659 void wxListHeaderWindow::AdjustDC(wxDC
& dc
)
1662 m_owner
->GetScrollPixelsPerUnit( &xpix
, NULL
);
1665 m_owner
->GetViewStart( &view_start
, NULL
);
1670 dc
.GetDeviceOrigin( &org_x
, &org_y
);
1672 // account for the horz scrollbar offset
1674 if (GetLayoutDirection() == wxLayout_RightToLeft
)
1676 // Maybe we just have to check for m_signX
1677 // in the DC, but I leave the #ifdef __WXGTK__
1679 dc
.SetDeviceOrigin( org_x
+ (view_start
* xpix
), org_y
);
1683 dc
.SetDeviceOrigin( org_x
- (view_start
* xpix
), org_y
);
1686 void wxListHeaderWindow::OnPaint( wxPaintEvent
&WXUNUSED(event
) )
1688 wxPaintDC
dc( this );
1693 dc
.SetFont( GetFont() );
1695 // width and height of the entire header window
1697 GetClientSize( &w
, &h
);
1698 m_owner
->CalcUnscrolledPosition(w
, 0, &w
, NULL
);
1700 dc
.SetBackgroundMode(wxTRANSPARENT
);
1701 dc
.SetTextForeground(GetForegroundColour());
1703 int x
= HEADER_OFFSET_X
;
1704 int numColumns
= m_owner
->GetColumnCount();
1706 for ( int i
= 0; i
< numColumns
&& x
< w
; i
++ )
1708 m_owner
->GetColumn( i
, item
);
1709 int wCol
= item
.m_width
;
1711 // the width of the rect to draw: make it smaller to fit entirely
1712 // inside the column rect
1721 wxRendererNative::Get().DrawHeaderButton
1725 wxRect(x
, HEADER_OFFSET_Y
, cw
, ch
),
1726 m_parent
->IsEnabled() ? 0
1727 : (int)wxCONTROL_DISABLED
1730 // see if we have enough space for the column label
1732 // for this we need the width of the text
1735 dc
.GetTextExtent(item
.GetText(), &wLabel
, &hLabel
);
1736 wLabel
+= 2 * EXTRA_WIDTH
;
1738 // and the width of the icon, if any
1739 static const int MARGIN_BETWEEN_TEXT_AND_ICON
= 2;
1740 int ix
= 0, iy
= 0; // init them just to suppress the compiler warnings
1741 const int image
= item
.m_image
;
1742 wxImageList
*imageList
;
1745 imageList
= m_owner
->m_small_image_list
;
1748 imageList
->GetSize(image
, ix
, iy
);
1749 wLabel
+= ix
+ MARGIN_BETWEEN_TEXT_AND_ICON
;
1757 // ignore alignment if there is not enough space anyhow
1759 switch ( wLabel
< cw
? item
.GetAlign() : wxLIST_FORMAT_LEFT
)
1762 wxFAIL_MSG( _T("unknown list item format") );
1765 case wxLIST_FORMAT_LEFT
:
1769 case wxLIST_FORMAT_RIGHT
:
1770 xAligned
= x
+ cw
- wLabel
;
1773 case wxLIST_FORMAT_CENTER
:
1774 xAligned
= x
+ (cw
- wLabel
) / 2;
1778 // if we have an image, draw it on the right of the label
1785 xAligned
+ wLabel
- ix
- MARGIN_BETWEEN_TEXT_AND_ICON
,
1786 HEADER_OFFSET_Y
+ (h
- 4 - iy
)/2,
1787 wxIMAGELIST_DRAW_TRANSPARENT
1790 cw
-= ix
+ MARGIN_BETWEEN_TEXT_AND_ICON
;
1793 // draw the text clipping it so that it doesn't overwrite the column
1795 wxDCClipper
clipper(dc
, x
, HEADER_OFFSET_Y
, cw
, h
- 4 );
1797 dc
.DrawText( item
.GetText(),
1798 xAligned
+ EXTRA_WIDTH
, h
/ 2 - hLabel
/ 2 ); //HEADER_OFFSET_Y + EXTRA_HEIGHT );
1804 void wxListHeaderWindow::DrawCurrent()
1806 int x1
= m_currentX
;
1808 m_owner
->ClientToScreen( &x1
, &y1
);
1810 int x2
= m_currentX
;
1812 m_owner
->GetClientSize( NULL
, &y2
);
1813 m_owner
->ClientToScreen( &x2
, &y2
);
1816 dc
.SetLogicalFunction( wxINVERT
);
1817 dc
.SetPen( wxPen( *wxBLACK
, 2, wxSOLID
) );
1818 dc
.SetBrush( *wxTRANSPARENT_BRUSH
);
1822 dc
.DrawLine( x1
, y1
, x2
, y2
);
1824 dc
.SetLogicalFunction( wxCOPY
);
1826 dc
.SetPen( wxNullPen
);
1827 dc
.SetBrush( wxNullBrush
);
1830 void wxListHeaderWindow::OnMouse( wxMouseEvent
&event
)
1832 // we want to work with logical coords
1834 m_owner
->CalcUnscrolledPosition(event
.GetX(), 0, &x
, NULL
);
1835 int y
= event
.GetY();
1839 SendListEvent(wxEVT_COMMAND_LIST_COL_DRAGGING
, event
.GetPosition());
1841 // we don't draw the line beyond our window, but we allow dragging it
1844 GetClientSize( &w
, NULL
);
1845 m_owner
->CalcUnscrolledPosition(w
, 0, &w
, NULL
);
1848 // erase the line if it was drawn
1849 if ( m_currentX
< w
)
1852 if (event
.ButtonUp())
1855 m_isDragging
= false;
1857 m_owner
->SetColumnWidth( m_column
, m_currentX
- m_minX
);
1858 SendListEvent(wxEVT_COMMAND_LIST_COL_END_DRAG
, event
.GetPosition());
1865 m_currentX
= m_minX
+ 7;
1867 // draw in the new location
1868 if ( m_currentX
< w
)
1872 else // not dragging
1875 bool hit_border
= false;
1877 // end of the current column
1880 // find the column where this event occurred
1882 countCol
= m_owner
->GetColumnCount();
1883 for (col
= 0; col
< countCol
; col
++)
1885 xpos
+= m_owner
->GetColumnWidth( col
);
1888 if ( (abs(x
-xpos
) < 3) && (y
< 22) )
1890 // near the column border
1897 // inside the column
1904 if ( col
== countCol
)
1907 if (event
.LeftDown() || event
.RightUp())
1909 if (hit_border
&& event
.LeftDown())
1911 if ( SendListEvent(wxEVT_COMMAND_LIST_COL_BEGIN_DRAG
,
1912 event
.GetPosition()) )
1914 m_isDragging
= true;
1919 //else: column resizing was vetoed by the user code
1921 else // click on a column
1923 SendListEvent( event
.LeftDown()
1924 ? wxEVT_COMMAND_LIST_COL_CLICK
1925 : wxEVT_COMMAND_LIST_COL_RIGHT_CLICK
,
1926 event
.GetPosition());
1929 else if (event
.Moving())
1934 setCursor
= m_currentCursor
== wxSTANDARD_CURSOR
;
1935 m_currentCursor
= m_resizeCursor
;
1939 setCursor
= m_currentCursor
!= wxSTANDARD_CURSOR
;
1940 m_currentCursor
= wxSTANDARD_CURSOR
;
1944 SetCursor(*m_currentCursor
);
1949 void wxListHeaderWindow::OnSetFocus( wxFocusEvent
&WXUNUSED(event
) )
1951 m_owner
->SetFocus();
1955 bool wxListHeaderWindow::SendListEvent(wxEventType type
, const wxPoint
& pos
)
1957 wxWindow
*parent
= GetParent();
1958 wxListEvent
le( type
, parent
->GetId() );
1959 le
.SetEventObject( parent
);
1960 le
.m_pointDrag
= pos
;
1962 // the position should be relative to the parent window, not
1963 // this one for compatibility with MSW and common sense: the
1964 // user code doesn't know anything at all about this header
1965 // window, so why should it get positions relative to it?
1966 le
.m_pointDrag
.y
-= GetSize().y
;
1968 le
.m_col
= m_column
;
1969 return !parent
->GetEventHandler()->ProcessEvent( le
) || le
.IsAllowed();
1972 //-----------------------------------------------------------------------------
1973 // wxListRenameTimer (internal)
1974 //-----------------------------------------------------------------------------
1976 wxListRenameTimer::wxListRenameTimer( wxListMainWindow
*owner
)
1981 void wxListRenameTimer::Notify()
1983 m_owner
->OnRenameTimer();
1986 //-----------------------------------------------------------------------------
1987 // wxListTextCtrlWrapper (internal)
1988 //-----------------------------------------------------------------------------
1990 BEGIN_EVENT_TABLE(wxListTextCtrlWrapper
, wxEvtHandler
)
1991 EVT_CHAR (wxListTextCtrlWrapper::OnChar
)
1992 EVT_KEY_UP (wxListTextCtrlWrapper::OnKeyUp
)
1993 EVT_KILL_FOCUS (wxListTextCtrlWrapper::OnKillFocus
)
1996 wxListTextCtrlWrapper::wxListTextCtrlWrapper(wxListMainWindow
*owner
,
1999 : m_startValue(owner
->GetItemText(itemEdit
)),
2000 m_itemEdited(itemEdit
)
2005 m_aboutToFinish
= false;
2007 wxRect rectLabel
= owner
->GetLineLabelRect(itemEdit
);
2009 m_owner
->CalcScrolledPosition(rectLabel
.x
, rectLabel
.y
,
2010 &rectLabel
.x
, &rectLabel
.y
);
2012 m_text
->Create(owner
, wxID_ANY
, m_startValue
,
2013 wxPoint(rectLabel
.x
-4,rectLabel
.y
-4),
2014 wxSize(rectLabel
.width
+11,rectLabel
.height
+8));
2017 m_text
->PushEventHandler(this);
2020 void wxListTextCtrlWrapper::Finish()
2026 m_text
->RemoveEventHandler(this);
2027 m_owner
->FinishEditing(m_text
);
2029 wxPendingDelete
.Append( this );
2033 bool wxListTextCtrlWrapper::AcceptChanges()
2035 const wxString value
= m_text
->GetValue();
2037 if ( value
== m_startValue
)
2038 // nothing changed, always accept
2041 if ( !m_owner
->OnRenameAccept(m_itemEdited
, value
) )
2042 // vetoed by the user
2045 // accepted, do rename the item
2046 m_owner
->SetItemText(m_itemEdited
, value
);
2051 void wxListTextCtrlWrapper::AcceptChangesAndFinish()
2053 m_aboutToFinish
= true;
2055 // Notify the owner about the changes
2058 // Even if vetoed, close the control (consistent with MSW)
2062 void wxListTextCtrlWrapper::OnChar( wxKeyEvent
&event
)
2064 switch ( event
.m_keyCode
)
2067 AcceptChangesAndFinish();
2071 m_owner
->OnRenameCancelled( m_itemEdited
);
2080 void wxListTextCtrlWrapper::OnKeyUp( wxKeyEvent
&event
)
2088 // auto-grow the textctrl:
2089 wxSize parentSize
= m_owner
->GetSize();
2090 wxPoint myPos
= m_text
->GetPosition();
2091 wxSize mySize
= m_text
->GetSize();
2093 m_text
->GetTextExtent(m_text
->GetValue() + _T("MM"), &sx
, &sy
);
2094 if (myPos
.x
+ sx
> parentSize
.x
)
2095 sx
= parentSize
.x
- myPos
.x
;
2098 m_text
->SetSize(sx
, wxDefaultCoord
);
2103 void wxListTextCtrlWrapper::OnKillFocus( wxFocusEvent
&event
)
2105 if ( !m_finished
&& !m_aboutToFinish
)
2107 if ( !AcceptChanges() )
2108 m_owner
->OnRenameCancelled( m_itemEdited
);
2113 // We must let the native text control handle focus
2117 //-----------------------------------------------------------------------------
2119 //-----------------------------------------------------------------------------
2121 IMPLEMENT_DYNAMIC_CLASS(wxListMainWindow
,wxScrolledWindow
)
2123 BEGIN_EVENT_TABLE(wxListMainWindow
,wxScrolledWindow
)
2124 EVT_PAINT (wxListMainWindow::OnPaint
)
2125 EVT_MOUSE_EVENTS (wxListMainWindow::OnMouse
)
2126 EVT_CHAR (wxListMainWindow::OnChar
)
2127 EVT_KEY_DOWN (wxListMainWindow::OnKeyDown
)
2128 EVT_SET_FOCUS (wxListMainWindow::OnSetFocus
)
2129 EVT_KILL_FOCUS (wxListMainWindow::OnKillFocus
)
2130 EVT_SCROLLWIN (wxListMainWindow::OnScroll
)
2133 void wxListMainWindow::Init()
2138 m_lineTo
= (size_t)-1;
2144 m_small_image_list
= (wxImageList
*) NULL
;
2145 m_normal_image_list
= (wxImageList
*) NULL
;
2147 m_small_spacing
= 30;
2148 m_normal_spacing
= 40;
2152 m_isCreated
= false;
2154 m_lastOnSame
= false;
2155 m_renameTimer
= new wxListRenameTimer( this );
2156 m_textctrlWrapper
= NULL
;
2160 m_lineSelectSingleOnUp
=
2161 m_lineBeforeLastClicked
= (size_t)-1;
2166 wxListMainWindow::wxListMainWindow()
2171 m_highlightUnfocusedBrush
= (wxBrush
*) NULL
;
2174 wxListMainWindow::wxListMainWindow( wxWindow
*parent
,
2179 const wxString
&name
)
2180 : wxScrolledWindow( parent
, id
, pos
, size
,
2181 style
| wxHSCROLL
| wxVSCROLL
, name
)
2185 m_highlightBrush
= new wxBrush
2187 wxSystemSettings::GetColour
2189 wxSYS_COLOUR_HIGHLIGHT
2194 m_highlightUnfocusedBrush
= new wxBrush
2196 wxSystemSettings::GetColour
2198 wxSYS_COLOUR_BTNSHADOW
2203 SetScrollbars( 0, 0, 0, 0, 0, 0 );
2205 wxVisualAttributes attr
= wxGenericListCtrl::GetClassDefaultAttributes();
2206 SetOwnForegroundColour( attr
.colFg
);
2207 SetOwnBackgroundColour( attr
.colBg
);
2209 SetOwnFont( attr
.font
);
2212 wxListMainWindow::~wxListMainWindow()
2215 WX_CLEAR_LIST(wxListHeaderDataList
, m_columns
);
2216 WX_CLEAR_ARRAY(m_aColWidths
);
2218 delete m_highlightBrush
;
2219 delete m_highlightUnfocusedBrush
;
2220 delete m_renameTimer
;
2223 void wxListMainWindow::CacheLineData(size_t line
)
2225 wxGenericListCtrl
*listctrl
= GetListCtrl();
2227 wxListLineData
*ld
= GetDummyLine();
2229 size_t countCol
= GetColumnCount();
2230 for ( size_t col
= 0; col
< countCol
; col
++ )
2232 ld
->SetText(col
, listctrl
->OnGetItemText(line
, col
));
2233 ld
->SetImage(col
, listctrl
->OnGetItemColumnImage(line
, col
));
2236 ld
->SetAttr(listctrl
->OnGetItemAttr(line
));
2239 wxListLineData
*wxListMainWindow::GetDummyLine() const
2241 wxASSERT_MSG( !IsEmpty(), _T("invalid line index") );
2242 wxASSERT_MSG( IsVirtual(), _T("GetDummyLine() shouldn't be called") );
2244 wxListMainWindow
*self
= wxConstCast(this, wxListMainWindow
);
2246 // we need to recreate the dummy line if the number of columns in the
2247 // control changed as it would have the incorrect number of fields
2249 if ( !m_lines
.IsEmpty() &&
2250 m_lines
[0].m_items
.GetCount() != (size_t)GetColumnCount() )
2252 self
->m_lines
.Clear();
2255 if ( m_lines
.IsEmpty() )
2257 wxListLineData
*line
= new wxListLineData(self
);
2258 self
->m_lines
.Add(line
);
2260 // don't waste extra memory -- there never going to be anything
2261 // else/more in this array
2262 self
->m_lines
.Shrink();
2268 // ----------------------------------------------------------------------------
2269 // line geometry (report mode only)
2270 // ----------------------------------------------------------------------------
2272 wxCoord
wxListMainWindow::GetLineHeight() const
2274 // we cache the line height as calling GetTextExtent() is slow
2275 if ( !m_lineHeight
)
2277 wxListMainWindow
*self
= wxConstCast(this, wxListMainWindow
);
2279 wxClientDC
dc( self
);
2280 dc
.SetFont( GetFont() );
2283 dc
.GetTextExtent(_T("H"), NULL
, &y
);
2285 if ( m_small_image_list
&& m_small_image_list
->GetImageCount() )
2288 m_small_image_list
->GetSize(0, iw
, ih
);
2293 self
->m_lineHeight
= y
+ LINE_SPACING
;
2296 return m_lineHeight
;
2299 wxCoord
wxListMainWindow::GetLineY(size_t line
) const
2301 wxASSERT_MSG( InReportView(), _T("only works in report mode") );
2303 return LINE_SPACING
+ line
* GetLineHeight();
2306 wxRect
wxListMainWindow::GetLineRect(size_t line
) const
2308 if ( !InReportView() )
2309 return GetLine(line
)->m_gi
->m_rectAll
;
2312 rect
.x
= HEADER_OFFSET_X
;
2313 rect
.y
= GetLineY(line
);
2314 rect
.width
= GetHeaderWidth();
2315 rect
.height
= GetLineHeight();
2320 wxRect
wxListMainWindow::GetLineLabelRect(size_t line
) const
2322 if ( !InReportView() )
2323 return GetLine(line
)->m_gi
->m_rectLabel
;
2326 rect
.x
= HEADER_OFFSET_X
;
2327 rect
.y
= GetLineY(line
);
2328 rect
.width
= GetColumnWidth(0);
2329 rect
.height
= GetLineHeight();
2334 wxRect
wxListMainWindow::GetLineIconRect(size_t line
) const
2336 if ( !InReportView() )
2337 return GetLine(line
)->m_gi
->m_rectIcon
;
2339 wxListLineData
*ld
= GetLine(line
);
2340 wxASSERT_MSG( ld
->HasImage(), _T("should have an image") );
2343 rect
.x
= HEADER_OFFSET_X
;
2344 rect
.y
= GetLineY(line
);
2345 GetImageSize(ld
->GetImage(), rect
.width
, rect
.height
);
2350 wxRect
wxListMainWindow::GetLineHighlightRect(size_t line
) const
2352 return InReportView() ? GetLineRect(line
)
2353 : GetLine(line
)->m_gi
->m_rectHighlight
;
2356 long wxListMainWindow::HitTestLine(size_t line
, int x
, int y
) const
2358 wxASSERT_MSG( line
< GetItemCount(), _T("invalid line in HitTestLine") );
2360 wxListLineData
*ld
= GetLine(line
);
2362 if ( ld
->HasImage() && GetLineIconRect(line
).Contains(x
, y
) )
2363 return wxLIST_HITTEST_ONITEMICON
;
2365 // VS: Testing for "ld->HasText() || InReportView()" instead of
2366 // "ld->HasText()" is needed to make empty lines in report view
2368 if ( ld
->HasText() || InReportView() )
2370 wxRect rect
= InReportView() ? GetLineRect(line
)
2371 : GetLineLabelRect(line
);
2373 if ( rect
.Contains(x
, y
) )
2374 return wxLIST_HITTEST_ONITEMLABEL
;
2380 // ----------------------------------------------------------------------------
2381 // highlight (selection) handling
2382 // ----------------------------------------------------------------------------
2384 bool wxListMainWindow::IsHighlighted(size_t line
) const
2388 return m_selStore
.IsSelected(line
);
2392 wxListLineData
*ld
= GetLine(line
);
2393 wxCHECK_MSG( ld
, false, _T("invalid index in IsHighlighted") );
2395 return ld
->IsHighlighted();
2399 void wxListMainWindow::HighlightLines( size_t lineFrom
,
2405 wxArrayInt linesChanged
;
2406 if ( !m_selStore
.SelectRange(lineFrom
, lineTo
, highlight
,
2409 // meny items changed state, refresh everything
2410 RefreshLines(lineFrom
, lineTo
);
2412 else // only a few items changed state, refresh only them
2414 size_t count
= linesChanged
.GetCount();
2415 for ( size_t n
= 0; n
< count
; n
++ )
2417 RefreshLine(linesChanged
[n
]);
2421 else // iterate over all items in non report view
2423 for ( size_t line
= lineFrom
; line
<= lineTo
; line
++ )
2425 if ( HighlightLine(line
, highlight
) )
2431 bool wxListMainWindow::HighlightLine( size_t line
, bool highlight
)
2437 changed
= m_selStore
.SelectItem(line
, highlight
);
2441 wxListLineData
*ld
= GetLine(line
);
2442 wxCHECK_MSG( ld
, false, _T("invalid index in HighlightLine") );
2444 changed
= ld
->Highlight(highlight
);
2449 SendNotify( line
, highlight
? wxEVT_COMMAND_LIST_ITEM_SELECTED
2450 : wxEVT_COMMAND_LIST_ITEM_DESELECTED
);
2456 void wxListMainWindow::RefreshLine( size_t line
)
2458 if ( InReportView() )
2460 size_t visibleFrom
, visibleTo
;
2461 GetVisibleLinesRange(&visibleFrom
, &visibleTo
);
2463 if ( line
< visibleFrom
|| line
> visibleTo
)
2467 wxRect rect
= GetLineRect(line
);
2469 CalcScrolledPosition( rect
.x
, rect
.y
, &rect
.x
, &rect
.y
);
2470 RefreshRect( rect
);
2473 void wxListMainWindow::RefreshLines( size_t lineFrom
, size_t lineTo
)
2475 // we suppose that they are ordered by caller
2476 wxASSERT_MSG( lineFrom
<= lineTo
, _T("indices in disorder") );
2478 wxASSERT_MSG( lineTo
< GetItemCount(), _T("invalid line range") );
2480 if ( InReportView() )
2482 size_t visibleFrom
, visibleTo
;
2483 GetVisibleLinesRange(&visibleFrom
, &visibleTo
);
2485 if ( lineFrom
< visibleFrom
)
2486 lineFrom
= visibleFrom
;
2487 if ( lineTo
> visibleTo
)
2492 rect
.y
= GetLineY(lineFrom
);
2493 rect
.width
= GetClientSize().x
;
2494 rect
.height
= GetLineY(lineTo
) - rect
.y
+ GetLineHeight();
2496 CalcScrolledPosition( rect
.x
, rect
.y
, &rect
.x
, &rect
.y
);
2497 RefreshRect( rect
);
2501 // TODO: this should be optimized...
2502 for ( size_t line
= lineFrom
; line
<= lineTo
; line
++ )
2509 void wxListMainWindow::RefreshAfter( size_t lineFrom
)
2511 if ( InReportView() )
2513 size_t visibleFrom
, visibleTo
;
2514 GetVisibleLinesRange(&visibleFrom
, &visibleTo
);
2516 if ( lineFrom
< visibleFrom
)
2517 lineFrom
= visibleFrom
;
2518 else if ( lineFrom
> visibleTo
)
2523 rect
.y
= GetLineY(lineFrom
);
2524 CalcScrolledPosition( rect
.x
, rect
.y
, &rect
.x
, &rect
.y
);
2526 wxSize size
= GetClientSize();
2527 rect
.width
= size
.x
;
2529 // refresh till the bottom of the window
2530 rect
.height
= size
.y
- rect
.y
;
2532 RefreshRect( rect
);
2536 // TODO: how to do it more efficiently?
2541 void wxListMainWindow::RefreshSelected()
2547 if ( InReportView() )
2549 GetVisibleLinesRange(&from
, &to
);
2554 to
= GetItemCount() - 1;
2557 if ( HasCurrent() && m_current
>= from
&& m_current
<= to
)
2558 RefreshLine(m_current
);
2560 for ( size_t line
= from
; line
<= to
; line
++ )
2562 // NB: the test works as expected even if m_current == -1
2563 if ( line
!= m_current
&& IsHighlighted(line
) )
2568 void wxListMainWindow::Freeze()
2573 void wxListMainWindow::Thaw()
2575 wxCHECK_RET( m_freezeCount
> 0, _T("thawing unfrozen list control?") );
2577 if ( --m_freezeCount
== 0 )
2581 void wxListMainWindow::OnPaint( wxPaintEvent
&WXUNUSED(event
) )
2583 // Note: a wxPaintDC must be constructed even if no drawing is
2584 // done (a Windows requirement).
2585 wxPaintDC
dc( this );
2587 if ( IsEmpty() || m_freezeCount
)
2588 // nothing to draw or not the moment to draw it
2592 // delay the repainting until we calculate all the items positions
2598 CalcScrolledPosition( 0, 0, &dev_x
, &dev_y
);
2600 dc
.SetFont( GetFont() );
2602 if ( InReportView() )
2604 int lineHeight
= GetLineHeight();
2606 size_t visibleFrom
, visibleTo
;
2607 GetVisibleLinesRange(&visibleFrom
, &visibleTo
);
2610 int xOrig
= dc
.LogicalToDeviceX( 0 );
2611 int yOrig
= dc
.LogicalToDeviceY( 0 );
2613 // tell the caller cache to cache the data
2616 wxListEvent
evCache(wxEVT_COMMAND_LIST_CACHE_HINT
,
2617 GetParent()->GetId());
2618 evCache
.SetEventObject( GetParent() );
2619 evCache
.m_oldItemIndex
= visibleFrom
;
2620 evCache
.m_itemIndex
= visibleTo
;
2621 GetParent()->GetEventHandler()->ProcessEvent( evCache
);
2624 for ( size_t line
= visibleFrom
; line
<= visibleTo
; line
++ )
2626 rectLine
= GetLineRect(line
);
2629 if ( !IsExposed(rectLine
.x
+ xOrig
, rectLine
.y
+ yOrig
,
2630 rectLine
.width
, rectLine
.height
) )
2632 // don't redraw unaffected lines to avoid flicker
2636 GetLine(line
)->DrawInReportMode( &dc
,
2638 GetLineHighlightRect(line
),
2639 IsHighlighted(line
) );
2642 if ( HasFlag(wxLC_HRULES
) )
2644 wxPen
pen(GetRuleColour(), 1, wxSOLID
);
2645 wxSize clientSize
= GetClientSize();
2647 // Don't draw the first one
2648 for ( size_t i
= visibleFrom
+ 1; i
<= visibleTo
; i
++ )
2651 dc
.SetBrush( *wxTRANSPARENT_BRUSH
);
2652 dc
.DrawLine(0 - dev_x
, i
* lineHeight
,
2653 clientSize
.x
- dev_x
, i
* lineHeight
);
2656 // Draw last horizontal rule
2657 if ( visibleTo
== GetItemCount() - 1 )
2660 dc
.SetBrush( *wxTRANSPARENT_BRUSH
);
2661 dc
.DrawLine(0 - dev_x
, (m_lineTo
+ 1) * lineHeight
,
2662 clientSize
.x
- dev_x
, (m_lineTo
+ 1) * lineHeight
);
2666 // Draw vertical rules if required
2667 if ( HasFlag(wxLC_VRULES
) && !IsEmpty() )
2669 wxPen
pen(GetRuleColour(), 1, wxSOLID
);
2670 wxRect firstItemRect
, lastItemRect
;
2672 GetItemRect(visibleFrom
, firstItemRect
);
2673 GetItemRect(visibleTo
, lastItemRect
);
2674 int x
= firstItemRect
.GetX();
2676 dc
.SetBrush(* wxTRANSPARENT_BRUSH
);
2678 for (int col
= 0; col
< GetColumnCount(); col
++)
2680 int colWidth
= GetColumnWidth(col
);
2682 dc
.DrawLine(x
- dev_x
- 2, firstItemRect
.GetY() - 1 - dev_y
,
2683 x
- dev_x
- 2, lastItemRect
.GetBottom() + 1 - dev_y
);
2689 size_t count
= GetItemCount();
2690 for ( size_t i
= 0; i
< count
; i
++ )
2692 GetLine(i
)->Draw( &dc
);
2697 // Don't draw rect outline under Mac at all.
2702 dc
.SetPen( *wxBLACK_PEN
);
2703 dc
.SetBrush( *wxTRANSPARENT_BRUSH
);
2704 dc
.DrawRectangle( GetLineHighlightRect( m_current
) );
2710 void wxListMainWindow::HighlightAll( bool on
)
2712 if ( IsSingleSel() )
2714 wxASSERT_MSG( !on
, _T("can't do this in a single selection control") );
2716 // we just have one item to turn off
2717 if ( HasCurrent() && IsHighlighted(m_current
) )
2719 HighlightLine(m_current
, false);
2720 RefreshLine(m_current
);
2725 HighlightLines(0, GetItemCount() - 1, on
);
2729 void wxListMainWindow::SendNotify( size_t line
,
2730 wxEventType command
,
2731 const wxPoint
& point
)
2733 wxListEvent
le( command
, GetParent()->GetId() );
2734 le
.SetEventObject( GetParent() );
2735 le
.m_itemIndex
= line
;
2737 // set only for events which have position
2738 if ( point
!= wxDefaultPosition
)
2739 le
.m_pointDrag
= point
;
2741 // don't try to get the line info for virtual list controls: the main
2742 // program has it anyhow and if we did it would result in accessing all
2743 // the lines, even those which are not visible now and this is precisely
2744 // what we're trying to avoid
2745 if ( !IsVirtual() && (command
!= wxEVT_COMMAND_LIST_DELETE_ITEM
) )
2747 if ( line
!= (size_t)-1 )
2749 GetLine(line
)->GetItem( 0, le
.m_item
);
2751 //else: this happens for wxEVT_COMMAND_LIST_ITEM_FOCUSED event
2753 //else: there may be no more such item
2755 GetParent()->GetEventHandler()->ProcessEvent( le
);
2758 void wxListMainWindow::ChangeCurrent(size_t current
)
2760 m_current
= current
;
2762 SendNotify(current
, wxEVT_COMMAND_LIST_ITEM_FOCUSED
);
2765 wxTextCtrl
*wxListMainWindow::EditLabel(long item
, wxClassInfo
* textControlClass
)
2767 wxCHECK_MSG( (item
>= 0) && ((size_t)item
< GetItemCount()), NULL
,
2768 wxT("wrong index in wxGenericListCtrl::EditLabel()") );
2770 wxASSERT_MSG( textControlClass
->IsKindOf(CLASSINFO(wxTextCtrl
)),
2771 wxT("EditLabel() needs a text control") );
2773 size_t itemEdit
= (size_t)item
;
2775 wxListEvent
le( wxEVT_COMMAND_LIST_BEGIN_LABEL_EDIT
, GetParent()->GetId() );
2776 le
.SetEventObject( GetParent() );
2777 le
.m_itemIndex
= item
;
2778 wxListLineData
*data
= GetLine(itemEdit
);
2779 wxCHECK_MSG( data
, NULL
, _T("invalid index in EditLabel()") );
2780 data
->GetItem( 0, le
.m_item
);
2782 if ( GetParent()->GetEventHandler()->ProcessEvent( le
) && !le
.IsAllowed() )
2784 // vetoed by user code
2788 // We have to call this here because the label in question might just have
2789 // been added and no screen update taken place.
2793 wxTextCtrl
* const text
= (wxTextCtrl
*)textControlClass
->CreateObject();
2794 m_textctrlWrapper
= new wxListTextCtrlWrapper(this, text
, item
);
2795 return m_textctrlWrapper
->GetText();
2798 void wxListMainWindow::OnRenameTimer()
2800 wxCHECK_RET( HasCurrent(), wxT("unexpected rename timer") );
2802 EditLabel( m_current
);
2805 bool wxListMainWindow::OnRenameAccept(size_t itemEdit
, const wxString
& value
)
2807 wxListEvent
le( wxEVT_COMMAND_LIST_END_LABEL_EDIT
, GetParent()->GetId() );
2808 le
.SetEventObject( GetParent() );
2809 le
.m_itemIndex
= itemEdit
;
2811 wxListLineData
*data
= GetLine(itemEdit
);
2813 wxCHECK_MSG( data
, false, _T("invalid index in OnRenameAccept()") );
2815 data
->GetItem( 0, le
.m_item
);
2816 le
.m_item
.m_text
= value
;
2817 return !GetParent()->GetEventHandler()->ProcessEvent( le
) ||
2821 void wxListMainWindow::OnRenameCancelled(size_t itemEdit
)
2823 // let owner know that the edit was cancelled
2824 wxListEvent
le( wxEVT_COMMAND_LIST_END_LABEL_EDIT
, GetParent()->GetId() );
2826 le
.SetEditCanceled(true);
2828 le
.SetEventObject( GetParent() );
2829 le
.m_itemIndex
= itemEdit
;
2831 wxListLineData
*data
= GetLine(itemEdit
);
2832 wxCHECK_RET( data
, _T("invalid index in OnRenameCancelled()") );
2834 data
->GetItem( 0, le
.m_item
);
2835 GetEventHandler()->ProcessEvent( le
);
2838 void wxListMainWindow::OnMouse( wxMouseEvent
&event
)
2842 // On wxMac we can't depend on the EVT_KILL_FOCUS event to properly
2843 // shutdown the edit control when the mouse is clicked elsewhere on the
2844 // listctrl because the order of events is different (or something like
2845 // that), so explicitly end the edit if it is active.
2846 if ( event
.LeftDown() && m_textctrlWrapper
)
2847 m_textctrlWrapper
->AcceptChangesAndFinish();
2850 event
.SetEventObject( GetParent() );
2851 if ( GetParent()->GetEventHandler()->ProcessEvent( event
) )
2854 if (event
.GetEventType() == wxEVT_MOUSEWHEEL
)
2856 // let the base handle mouse wheel events.
2861 if ( !HasCurrent() || IsEmpty() )
2863 if (event
.RightDown())
2865 SendNotify( (size_t)-1, wxEVT_COMMAND_LIST_ITEM_RIGHT_CLICK
, event
.GetPosition() );
2866 // Allow generation of context menu event
2875 if ( !(event
.Dragging() || event
.ButtonDown() || event
.LeftUp() ||
2876 event
.ButtonDClick()) )
2879 int x
= event
.GetX();
2880 int y
= event
.GetY();
2881 CalcUnscrolledPosition( x
, y
, &x
, &y
);
2883 // where did we hit it (if we did)?
2886 size_t count
= GetItemCount(),
2889 if ( InReportView() )
2891 current
= y
/ GetLineHeight();
2892 if ( current
< count
)
2893 hitResult
= HitTestLine(current
, x
, y
);
2897 // TODO: optimize it too! this is less simple than for report view but
2898 // enumerating all items is still not a way to do it!!
2899 for ( current
= 0; current
< count
; current
++ )
2901 hitResult
= HitTestLine(current
, x
, y
);
2907 if (event
.Dragging())
2909 if (m_dragCount
== 0)
2911 // we have to report the raw, physical coords as we want to be
2912 // able to call HitTest(event.m_pointDrag) from the user code to
2913 // get the item being dragged
2914 m_dragStart
= event
.GetPosition();
2919 if (m_dragCount
!= 3)
2922 int command
= event
.RightIsDown() ? wxEVT_COMMAND_LIST_BEGIN_RDRAG
2923 : wxEVT_COMMAND_LIST_BEGIN_DRAG
;
2925 wxListEvent
le( command
, GetParent()->GetId() );
2926 le
.SetEventObject( GetParent() );
2927 le
.m_itemIndex
= m_lineLastClicked
;
2928 le
.m_pointDrag
= m_dragStart
;
2929 GetParent()->GetEventHandler()->ProcessEvent( le
);
2940 // outside of any item
2941 if (event
.RightDown())
2943 SendNotify( (size_t) -1, wxEVT_COMMAND_LIST_ITEM_RIGHT_CLICK
, event
.GetPosition() );
2944 // Allow generation of context menu event
2949 // reset the selection and bail out
2950 HighlightAll(false);
2956 bool forceClick
= false;
2957 if (event
.ButtonDClick())
2959 m_renameTimer
->Stop();
2960 m_lastOnSame
= false;
2962 if ( current
== m_lineLastClicked
)
2964 SendNotify( current
, wxEVT_COMMAND_LIST_ITEM_ACTIVATED
);
2970 // The first click was on another item, so don't interpret this as
2971 // a double click, but as a simple click instead
2978 if (m_lineSelectSingleOnUp
!= (size_t)-1)
2980 // select single line
2981 HighlightAll( false );
2982 ReverseHighlight(m_lineSelectSingleOnUp
);
2987 if ((current
== m_current
) &&
2988 (hitResult
== wxLIST_HITTEST_ONITEMLABEL
) &&
2989 HasFlag(wxLC_EDIT_LABELS
) )
2991 m_renameTimer
->Start( 100, true );
2995 m_lastOnSame
= false;
2996 m_lineSelectSingleOnUp
= (size_t)-1;
3000 // This is necessary, because after a DnD operation in
3001 // from and to ourself, the up event is swallowed by the
3002 // DnD code. So on next non-up event (which means here and
3003 // now) m_lineSelectSingleOnUp should be reset.
3004 m_lineSelectSingleOnUp
= (size_t)-1;
3006 if (event
.RightDown())
3008 m_lineBeforeLastClicked
= m_lineLastClicked
;
3009 m_lineLastClicked
= current
;
3011 // If the item is already selected, do not update the selection.
3012 // Multi-selections should not be cleared if a selected item is clicked.
3013 if (!IsHighlighted(current
))
3015 HighlightAll(false);
3016 ChangeCurrent(current
);
3017 ReverseHighlight(m_current
);
3020 SendNotify( current
, wxEVT_COMMAND_LIST_ITEM_RIGHT_CLICK
, event
.GetPosition() );
3022 // Allow generation of context menu event
3025 else if (event
.MiddleDown())
3027 SendNotify( current
, wxEVT_COMMAND_LIST_ITEM_MIDDLE_CLICK
);
3029 else if ( event
.LeftDown() || forceClick
)
3031 m_lineBeforeLastClicked
= m_lineLastClicked
;
3032 m_lineLastClicked
= current
;
3034 size_t oldCurrent
= m_current
;
3035 bool oldWasSelected
= IsHighlighted(m_current
);
3037 bool cmdModifierDown
= event
.CmdDown();
3038 if ( IsSingleSel() || !(cmdModifierDown
|| event
.ShiftDown()) )
3040 if ( IsSingleSel() || !IsHighlighted(current
) )
3042 HighlightAll( false );
3044 ChangeCurrent(current
);
3046 ReverseHighlight(m_current
);
3048 else // multi sel & current is highlighted & no mod keys
3050 m_lineSelectSingleOnUp
= current
;
3051 ChangeCurrent(current
); // change focus
3054 else // multi sel & either ctrl or shift is down
3056 if (cmdModifierDown
)
3058 ChangeCurrent(current
);
3060 ReverseHighlight(m_current
);
3062 else if (event
.ShiftDown())
3064 ChangeCurrent(current
);
3066 size_t lineFrom
= oldCurrent
,
3069 if ( lineTo
< lineFrom
)
3072 lineFrom
= m_current
;
3075 HighlightLines(lineFrom
, lineTo
);
3077 else // !ctrl, !shift
3079 // test in the enclosing if should make it impossible
3080 wxFAIL_MSG( _T("how did we get here?") );
3084 if (m_current
!= oldCurrent
)
3085 RefreshLine( oldCurrent
);
3087 // forceClick is only set if the previous click was on another item
3088 m_lastOnSame
= !forceClick
&& (m_current
== oldCurrent
) && oldWasSelected
;
3092 void wxListMainWindow::MoveToItem(size_t item
)
3094 if ( item
== (size_t)-1 )
3097 wxRect rect
= GetLineRect(item
);
3099 int client_w
, client_h
;
3100 GetClientSize( &client_w
, &client_h
);
3102 const int hLine
= GetLineHeight();
3104 int view_x
= SCROLL_UNIT_X
* GetScrollPos( wxHORIZONTAL
);
3105 int view_y
= hLine
* GetScrollPos( wxVERTICAL
);
3107 if ( InReportView() )
3109 // the next we need the range of lines shown it might be different,
3110 // so recalculate it
3111 ResetVisibleLinesRange();
3113 if (rect
.y
< view_y
)
3114 Scroll( -1, rect
.y
/ hLine
);
3115 if (rect
.y
+ rect
.height
+ 5 > view_y
+ client_h
)
3116 Scroll( -1, (rect
.y
+ rect
.height
- client_h
+ hLine
) / hLine
);
3120 if (rect
.x
-view_x
< 5)
3121 Scroll( (rect
.x
- 5) / SCROLL_UNIT_X
, -1 );
3122 if (rect
.x
+ rect
.width
- 5 > view_x
+ client_w
)
3123 Scroll( (rect
.x
+ rect
.width
- client_w
+ SCROLL_UNIT_X
) / SCROLL_UNIT_X
, -1 );
3127 // ----------------------------------------------------------------------------
3128 // keyboard handling
3129 // ----------------------------------------------------------------------------
3131 void wxListMainWindow::OnArrowChar(size_t newCurrent
, const wxKeyEvent
& event
)
3133 wxCHECK_RET( newCurrent
< (size_t)GetItemCount(),
3134 _T("invalid item index in OnArrowChar()") );
3136 size_t oldCurrent
= m_current
;
3138 // in single selection we just ignore Shift as we can't select several
3140 if ( event
.ShiftDown() && !IsSingleSel() )
3142 ChangeCurrent(newCurrent
);
3144 // refresh the old focus to remove it
3145 RefreshLine( oldCurrent
);
3147 // select all the items between the old and the new one
3148 if ( oldCurrent
> newCurrent
)
3150 newCurrent
= oldCurrent
;
3151 oldCurrent
= m_current
;
3154 HighlightLines(oldCurrent
, newCurrent
);
3158 // all previously selected items are unselected unless ctrl is held
3159 if ( !event
.ControlDown() )
3160 HighlightAll(false);
3162 ChangeCurrent(newCurrent
);
3164 // refresh the old focus to remove it
3165 RefreshLine( oldCurrent
);
3167 if ( !event
.ControlDown() )
3169 HighlightLine( m_current
, true );
3173 RefreshLine( m_current
);
3178 void wxListMainWindow::OnKeyDown( wxKeyEvent
&event
)
3180 wxWindow
*parent
= GetParent();
3182 // propagate the key event upwards
3183 wxKeyEvent
ke( wxEVT_KEY_DOWN
);
3184 ke
.m_shiftDown
= event
.m_shiftDown
;
3185 ke
.m_controlDown
= event
.m_controlDown
;
3186 ke
.m_altDown
= event
.m_altDown
;
3187 ke
.m_metaDown
= event
.m_metaDown
;
3188 ke
.m_keyCode
= event
.m_keyCode
;
3191 ke
.SetEventObject( parent
);
3192 if (parent
->GetEventHandler()->ProcessEvent( ke
)) return;
3197 void wxListMainWindow::OnChar( wxKeyEvent
&event
)
3199 wxWindow
*parent
= GetParent();
3201 // send a list_key event up
3204 wxListEvent
le( wxEVT_COMMAND_LIST_KEY_DOWN
, GetParent()->GetId() );
3205 le
.m_itemIndex
= m_current
;
3206 GetLine(m_current
)->GetItem( 0, le
.m_item
);
3207 le
.m_code
= event
.GetKeyCode();
3208 le
.SetEventObject( parent
);
3209 parent
->GetEventHandler()->ProcessEvent( le
);
3212 // propagate the char event upwards
3213 wxKeyEvent
ke( wxEVT_CHAR
);
3214 ke
.m_shiftDown
= event
.m_shiftDown
;
3215 ke
.m_controlDown
= event
.m_controlDown
;
3216 ke
.m_altDown
= event
.m_altDown
;
3217 ke
.m_metaDown
= event
.m_metaDown
;
3218 ke
.m_keyCode
= event
.m_keyCode
;
3221 ke
.SetEventObject( parent
);
3222 if (parent
->GetEventHandler()->ProcessEvent( ke
)) return;
3224 if (event
.GetKeyCode() == WXK_TAB
)
3226 wxNavigationKeyEvent nevent
;
3227 nevent
.SetWindowChange( event
.ControlDown() );
3228 nevent
.SetDirection( !event
.ShiftDown() );
3229 nevent
.SetEventObject( GetParent()->GetParent() );
3230 nevent
.SetCurrentFocus( m_parent
);
3231 if (GetParent()->GetParent()->GetEventHandler()->ProcessEvent( nevent
))
3235 // no item -> nothing to do
3242 // don't use m_linesPerPage directly as it might not be computed yet
3243 const int pageSize
= GetCountPerPage();
3244 wxCHECK_RET( pageSize
, _T("should have non zero page size") );
3246 if (GetLayoutDirection() == wxLayout_RightToLeft
)
3248 if (event
.GetKeyCode() == WXK_RIGHT
)
3249 event
.m_keyCode
= WXK_LEFT
;
3250 else if (event
.GetKeyCode() == WXK_LEFT
)
3251 event
.m_keyCode
= WXK_RIGHT
;
3254 switch ( event
.GetKeyCode() )
3257 if ( m_current
> 0 )
3258 OnArrowChar( m_current
- 1, event
);
3262 if ( m_current
< (size_t)GetItemCount() - 1 )
3263 OnArrowChar( m_current
+ 1, event
);
3268 OnArrowChar( GetItemCount() - 1, event
);
3273 OnArrowChar( 0, event
);
3278 int steps
= InReportView() ? pageSize
- 1
3279 : m_current
% pageSize
;
3281 int index
= m_current
- steps
;
3285 OnArrowChar( index
, event
);
3291 int steps
= InReportView()
3293 : pageSize
- (m_current
% pageSize
) - 1;
3295 size_t index
= m_current
+ steps
;
3296 size_t count
= GetItemCount();
3297 if ( index
>= count
)
3300 OnArrowChar( index
, event
);
3305 if ( !InReportView() )
3307 int index
= m_current
- pageSize
;
3311 OnArrowChar( index
, event
);
3316 if ( !InReportView() )
3318 size_t index
= m_current
+ pageSize
;
3320 size_t count
= GetItemCount();
3321 if ( index
>= count
)
3324 OnArrowChar( index
, event
);
3329 if ( IsSingleSel() )
3331 SendNotify( m_current
, wxEVT_COMMAND_LIST_ITEM_ACTIVATED
);
3333 if ( IsHighlighted(m_current
) )
3335 // don't unselect the item in single selection mode
3338 //else: select it in ReverseHighlight() below if unselected
3341 ReverseHighlight(m_current
);
3346 SendNotify( m_current
, wxEVT_COMMAND_LIST_ITEM_ACTIVATED
);
3354 // ----------------------------------------------------------------------------
3356 // ----------------------------------------------------------------------------
3358 void wxListMainWindow::OnSetFocus( wxFocusEvent
&WXUNUSED(event
) )
3362 wxFocusEvent
event( wxEVT_SET_FOCUS
, GetParent()->GetId() );
3363 event
.SetEventObject( GetParent() );
3364 if ( GetParent()->GetEventHandler()->ProcessEvent( event
) )
3368 // wxGTK sends us EVT_SET_FOCUS events even if we had never got
3369 // EVT_KILL_FOCUS before which means that we finish by redrawing the items
3370 // which are already drawn correctly resulting in horrible flicker - avoid
3380 void wxListMainWindow::OnKillFocus( wxFocusEvent
&WXUNUSED(event
) )
3384 wxFocusEvent
event( wxEVT_KILL_FOCUS
, GetParent()->GetId() );
3385 event
.SetEventObject( GetParent() );
3386 if ( GetParent()->GetEventHandler()->ProcessEvent( event
) )
3394 void wxListMainWindow::DrawImage( int index
, wxDC
*dc
, int x
, int y
)
3396 if ( HasFlag(wxLC_ICON
) && (m_normal_image_list
))
3398 m_normal_image_list
->Draw( index
, *dc
, x
, y
, wxIMAGELIST_DRAW_TRANSPARENT
);
3400 else if ( HasFlag(wxLC_SMALL_ICON
) && (m_small_image_list
))
3402 m_small_image_list
->Draw( index
, *dc
, x
, y
, wxIMAGELIST_DRAW_TRANSPARENT
);
3404 else if ( HasFlag(wxLC_LIST
) && (m_small_image_list
))
3406 m_small_image_list
->Draw( index
, *dc
, x
, y
, wxIMAGELIST_DRAW_TRANSPARENT
);
3408 else if ( InReportView() && (m_small_image_list
))
3410 m_small_image_list
->Draw( index
, *dc
, x
, y
, wxIMAGELIST_DRAW_TRANSPARENT
);
3414 void wxListMainWindow::GetImageSize( int index
, int &width
, int &height
) const
3416 if ( HasFlag(wxLC_ICON
) && m_normal_image_list
)
3418 m_normal_image_list
->GetSize( index
, width
, height
);
3420 else if ( HasFlag(wxLC_SMALL_ICON
) && m_small_image_list
)
3422 m_small_image_list
->GetSize( index
, width
, height
);
3424 else if ( HasFlag(wxLC_LIST
) && m_small_image_list
)
3426 m_small_image_list
->GetSize( index
, width
, height
);
3428 else if ( InReportView() && m_small_image_list
)
3430 m_small_image_list
->GetSize( index
, width
, height
);
3439 int wxListMainWindow::GetTextLength( const wxString
&s
) const
3441 wxClientDC
dc( wxConstCast(this, wxListMainWindow
) );
3442 dc
.SetFont( GetFont() );
3445 dc
.GetTextExtent( s
, &lw
, NULL
);
3447 return lw
+ AUTOSIZE_COL_MARGIN
;
3450 void wxListMainWindow::SetImageList( wxImageList
*imageList
, int which
)
3454 // calc the spacing from the icon size
3455 int width
= 0, height
= 0;
3457 if ((imageList
) && (imageList
->GetImageCount()) )
3458 imageList
->GetSize(0, width
, height
);
3460 if (which
== wxIMAGE_LIST_NORMAL
)
3462 m_normal_image_list
= imageList
;
3463 m_normal_spacing
= width
+ 8;
3466 if (which
== wxIMAGE_LIST_SMALL
)
3468 m_small_image_list
= imageList
;
3469 m_small_spacing
= width
+ 14;
3470 m_lineHeight
= 0; // ensure that the line height will be recalc'd
3474 void wxListMainWindow::SetItemSpacing( int spacing
, bool isSmall
)
3478 m_small_spacing
= spacing
;
3480 m_normal_spacing
= spacing
;
3483 int wxListMainWindow::GetItemSpacing( bool isSmall
)
3485 return isSmall
? m_small_spacing
: m_normal_spacing
;
3488 // ----------------------------------------------------------------------------
3490 // ----------------------------------------------------------------------------
3492 void wxListMainWindow::SetColumn( int col
, wxListItem
&item
)
3494 wxListHeaderDataList::compatibility_iterator node
= m_columns
.Item( col
);
3496 wxCHECK_RET( node
, _T("invalid column index in SetColumn") );
3498 if ( item
.m_width
== wxLIST_AUTOSIZE_USEHEADER
)
3499 item
.m_width
= GetTextLength( item
.m_text
);
3501 wxListHeaderData
*column
= node
->GetData();
3502 column
->SetItem( item
);
3504 wxListHeaderWindow
*headerWin
= GetListCtrl()->m_headerWin
;
3506 headerWin
->m_dirty
= true;
3510 // invalidate it as it has to be recalculated
3514 void wxListMainWindow::SetColumnWidth( int col
, int width
)
3516 wxCHECK_RET( col
>= 0 && col
< GetColumnCount(),
3517 _T("invalid column index") );
3519 wxCHECK_RET( InReportView(),
3520 _T("SetColumnWidth() can only be called in report mode.") );
3523 wxListHeaderWindow
*headerWin
= GetListCtrl()->m_headerWin
;
3525 headerWin
->m_dirty
= true;
3527 wxListHeaderDataList::compatibility_iterator node
= m_columns
.Item( col
);
3528 wxCHECK_RET( node
, _T("no column?") );
3530 wxListHeaderData
*column
= node
->GetData();
3532 size_t count
= GetItemCount();
3534 if (width
== wxLIST_AUTOSIZE_USEHEADER
)
3536 width
= GetTextLength(column
->GetText());
3538 else if ( width
== wxLIST_AUTOSIZE
)
3542 // TODO: determine the max width somehow...
3543 width
= WIDTH_COL_DEFAULT
;
3547 wxClientDC
dc(this);
3548 dc
.SetFont( GetFont() );
3550 int max
= AUTOSIZE_COL_MARGIN
;
3552 // if the cached column width isn't valid then recalculate it
3553 if (m_aColWidths
.Item(col
)->bNeedsUpdate
)
3555 for (size_t i
= 0; i
< count
; i
++)
3557 wxListLineData
*line
= GetLine( i
);
3558 wxListItemDataList::compatibility_iterator n
= line
->m_items
.Item( col
);
3560 wxCHECK_RET( n
, _T("no subitem?") );
3562 wxListItemData
*itemData
= n
->GetData();
3565 itemData
->GetItem(item
);
3566 int itemWidth
= GetItemWidthWithImage(&item
);
3567 if (itemWidth
> max
)
3571 m_aColWidths
.Item(col
)->bNeedsUpdate
= false;
3572 m_aColWidths
.Item(col
)->nMaxWidth
= max
;
3575 max
= m_aColWidths
.Item(col
)->nMaxWidth
;
3576 width
= max
+ AUTOSIZE_COL_MARGIN
;
3580 column
->SetWidth( width
);
3582 // invalidate it as it has to be recalculated
3586 int wxListMainWindow::GetHeaderWidth() const
3588 if ( !m_headerWidth
)
3590 wxListMainWindow
*self
= wxConstCast(this, wxListMainWindow
);
3592 size_t count
= GetColumnCount();
3593 for ( size_t col
= 0; col
< count
; col
++ )
3595 self
->m_headerWidth
+= GetColumnWidth(col
);
3599 return m_headerWidth
;
3602 void wxListMainWindow::GetColumn( int col
, wxListItem
&item
) const
3604 wxListHeaderDataList::compatibility_iterator node
= m_columns
.Item( col
);
3605 wxCHECK_RET( node
, _T("invalid column index in GetColumn") );
3607 wxListHeaderData
*column
= node
->GetData();
3608 column
->GetItem( item
);
3611 int wxListMainWindow::GetColumnWidth( int col
) const
3613 wxListHeaderDataList::compatibility_iterator node
= m_columns
.Item( col
);
3614 wxCHECK_MSG( node
, 0, _T("invalid column index") );
3616 wxListHeaderData
*column
= node
->GetData();
3617 return column
->GetWidth();
3620 // ----------------------------------------------------------------------------
3622 // ----------------------------------------------------------------------------
3624 void wxListMainWindow::SetItem( wxListItem
&item
)
3626 long id
= item
.m_itemId
;
3627 wxCHECK_RET( id
>= 0 && (size_t)id
< GetItemCount(),
3628 _T("invalid item index in SetItem") );
3632 wxListLineData
*line
= GetLine((size_t)id
);
3633 line
->SetItem( item
.m_col
, item
);
3635 // Set item state if user wants
3636 if ( item
.m_mask
& wxLIST_MASK_STATE
)
3637 SetItemState( item
.m_itemId
, item
.m_state
, item
.m_state
);
3641 // update the Max Width Cache if needed
3642 int width
= GetItemWidthWithImage(&item
);
3644 if (width
> m_aColWidths
.Item(item
.m_col
)->nMaxWidth
)
3645 m_aColWidths
.Item(item
.m_col
)->nMaxWidth
= width
;
3649 // update the item on screen
3651 GetItemRect(id
, rectItem
);
3652 RefreshRect(rectItem
);
3655 void wxListMainWindow::SetItemStateAll(long state
, long stateMask
)
3660 // first deal with selection
3661 if ( stateMask
& wxLIST_STATE_SELECTED
)
3663 // set/clear select state
3666 // optimized version for virtual listctrl.
3667 m_selStore
.SelectRange(0, GetItemCount() - 1, state
== wxLIST_STATE_SELECTED
);
3670 else if ( state
& wxLIST_STATE_SELECTED
)
3672 const long count
= GetItemCount();
3673 for( long i
= 0; i
< count
; i
++ )
3675 SetItemState( i
, wxLIST_STATE_SELECTED
, wxLIST_STATE_SELECTED
);
3681 // clear for non virtual (somewhat optimized by using GetNextItem())
3683 while ( (i
= GetNextItem(i
, wxLIST_NEXT_ALL
, wxLIST_STATE_SELECTED
)) != -1 )
3685 SetItemState( i
, 0, wxLIST_STATE_SELECTED
);
3690 if ( HasCurrent() && (state
== 0) && (stateMask
& wxLIST_STATE_FOCUSED
) )
3692 // unfocus all: only one item can be focussed, so clearing focus for
3693 // all items is simply clearing focus of the focussed item.
3694 SetItemState(m_current
, state
, stateMask
);
3696 //(setting focus to all items makes no sense, so it is not handled here.)
3699 void wxListMainWindow::SetItemState( long litem
, long state
, long stateMask
)
3703 SetItemStateAll(state
, stateMask
);
3707 wxCHECK_RET( litem
>= 0 && (size_t)litem
< GetItemCount(),
3708 _T("invalid list ctrl item index in SetItem") );
3710 size_t oldCurrent
= m_current
;
3711 size_t item
= (size_t)litem
; // safe because of the check above
3713 // do we need to change the focus?
3714 if ( stateMask
& wxLIST_STATE_FOCUSED
)
3716 if ( state
& wxLIST_STATE_FOCUSED
)
3718 // don't do anything if this item is already focused
3719 if ( item
!= m_current
)
3721 ChangeCurrent(item
);
3723 if ( oldCurrent
!= (size_t)-1 )
3725 if ( IsSingleSel() )
3727 HighlightLine(oldCurrent
, false);
3730 RefreshLine(oldCurrent
);
3733 RefreshLine( m_current
);
3738 // don't do anything if this item is not focused
3739 if ( item
== m_current
)
3743 if ( IsSingleSel() )
3745 // we must unselect the old current item as well or we
3746 // might end up with more than one selected item in a
3747 // single selection control
3748 HighlightLine(oldCurrent
, false);
3751 RefreshLine( oldCurrent
);
3756 // do we need to change the selection state?
3757 if ( stateMask
& wxLIST_STATE_SELECTED
)
3759 bool on
= (state
& wxLIST_STATE_SELECTED
) != 0;
3761 if ( IsSingleSel() )
3765 // selecting the item also makes it the focused one in the
3767 if ( m_current
!= item
)
3769 ChangeCurrent(item
);
3771 if ( oldCurrent
!= (size_t)-1 )
3773 HighlightLine( oldCurrent
, false );
3774 RefreshLine( oldCurrent
);
3780 // only the current item may be selected anyhow
3781 if ( item
!= m_current
)
3786 if ( HighlightLine(item
, on
) )
3793 int wxListMainWindow::GetItemState( long item
, long stateMask
) const
3795 wxCHECK_MSG( item
>= 0 && (size_t)item
< GetItemCount(), 0,
3796 _T("invalid list ctrl item index in GetItemState()") );
3798 int ret
= wxLIST_STATE_DONTCARE
;
3800 if ( stateMask
& wxLIST_STATE_FOCUSED
)
3802 if ( (size_t)item
== m_current
)
3803 ret
|= wxLIST_STATE_FOCUSED
;
3806 if ( stateMask
& wxLIST_STATE_SELECTED
)
3808 if ( IsHighlighted(item
) )
3809 ret
|= wxLIST_STATE_SELECTED
;
3815 void wxListMainWindow::GetItem( wxListItem
&item
) const
3817 wxCHECK_RET( item
.m_itemId
>= 0 && (size_t)item
.m_itemId
< GetItemCount(),
3818 _T("invalid item index in GetItem") );
3820 wxListLineData
*line
= GetLine((size_t)item
.m_itemId
);
3821 line
->GetItem( item
.m_col
, item
);
3823 // Get item state if user wants it
3824 if ( item
.m_mask
& wxLIST_MASK_STATE
)
3825 item
.m_state
= GetItemState( item
.m_itemId
, wxLIST_STATE_SELECTED
|
3826 wxLIST_STATE_FOCUSED
);
3829 // ----------------------------------------------------------------------------
3831 // ----------------------------------------------------------------------------
3833 size_t wxListMainWindow::GetItemCount() const
3835 return IsVirtual() ? m_countVirt
: m_lines
.GetCount();
3838 void wxListMainWindow::SetItemCount(long count
)
3840 m_selStore
.SetItemCount(count
);
3841 m_countVirt
= count
;
3843 ResetVisibleLinesRange();
3845 // scrollbars must be reset
3849 int wxListMainWindow::GetSelectedItemCount() const
3851 // deal with the quick case first
3852 if ( IsSingleSel() )
3853 return HasCurrent() ? IsHighlighted(m_current
) : false;
3855 // virtual controls remmebers all its selections itself
3857 return m_selStore
.GetSelectedCount();
3859 // TODO: we probably should maintain the number of items selected even for
3860 // non virtual controls as enumerating all lines is really slow...
3861 size_t countSel
= 0;
3862 size_t count
= GetItemCount();
3863 for ( size_t line
= 0; line
< count
; line
++ )
3865 if ( GetLine(line
)->IsHighlighted() )
3872 // ----------------------------------------------------------------------------
3873 // item position/size
3874 // ----------------------------------------------------------------------------
3876 wxRect
wxListMainWindow::GetViewRect() const
3878 wxASSERT_MSG( !HasFlag(wxLC_REPORT
| wxLC_LIST
),
3879 _T("wxListCtrl::GetViewRect() only works in icon mode") );
3881 // we need to find the longest/tallest label
3882 wxCoord xMax
= 0, yMax
= 0;
3883 const int count
= GetItemCount();
3886 for ( int i
= 0; i
< count
; i
++ )
3891 wxCoord x
= r
.GetRight(),
3901 // some fudge needed to make it look prettier
3902 xMax
+= 2 * EXTRA_BORDER_X
;
3903 yMax
+= 2 * EXTRA_BORDER_Y
;
3905 // account for the scrollbars if necessary
3906 const wxSize sizeAll
= GetClientSize();
3907 if ( xMax
> sizeAll
.x
)
3908 yMax
+= wxSystemSettings::GetMetric(wxSYS_HSCROLL_Y
);
3909 if ( yMax
> sizeAll
.y
)
3910 xMax
+= wxSystemSettings::GetMetric(wxSYS_VSCROLL_X
);
3912 return wxRect(0, 0, xMax
, yMax
);
3915 void wxListMainWindow::GetItemRect( long index
, wxRect
&rect
) const
3917 wxCHECK_RET( index
>= 0 && (size_t)index
< GetItemCount(),
3918 _T("invalid index in GetItemRect") );
3920 // ensure that we're laid out, otherwise we could return nonsense
3923 wxConstCast(this, wxListMainWindow
)->
3924 RecalculatePositions(true /* no refresh */);
3927 rect
= GetLineRect((size_t)index
);
3929 CalcScrolledPosition(rect
.x
, rect
.y
, &rect
.x
, &rect
.y
);
3932 bool wxListMainWindow::GetItemPosition(long item
, wxPoint
& pos
) const
3935 GetItemRect(item
, rect
);
3943 // ----------------------------------------------------------------------------
3944 // geometry calculation
3945 // ----------------------------------------------------------------------------
3947 void wxListMainWindow::RecalculatePositions(bool noRefresh
)
3949 wxClientDC
dc( this );
3950 dc
.SetFont( GetFont() );
3952 const size_t count
= GetItemCount();
3955 if ( HasFlag(wxLC_ICON
) )
3956 iconSpacing
= m_normal_spacing
;
3957 else if ( HasFlag(wxLC_SMALL_ICON
) )
3958 iconSpacing
= m_small_spacing
;
3962 // Note that we do not call GetClientSize() here but
3963 // GetSize() and subtract the border size for sunken
3964 // borders manually. This is technically incorrect,
3965 // but we need to know the client area's size WITHOUT
3966 // scrollbars here. Since we don't know if there are
3967 // any scrollbars, we use GetSize() instead. Another
3968 // solution would be to call SetScrollbars() here to
3969 // remove the scrollbars and call GetClientSize() then,
3970 // but this might result in flicker and - worse - will
3971 // reset the scrollbars to 0 which is not good at all
3972 // if you resize a dialog/window, but don't want to
3973 // reset the window scrolling. RR.
3974 // Furthermore, we actually do NOT subtract the border
3975 // width as 2 pixels is just the extra space which we
3976 // need around the actual content in the window. Other-
3977 // wise the text would e.g. touch the upper border. RR.
3980 GetSize( &clientWidth
, &clientHeight
);
3982 const int lineHeight
= GetLineHeight();
3984 if ( InReportView() )
3986 // all lines have the same height and we scroll one line per step
3987 int entireHeight
= count
* lineHeight
+ LINE_SPACING
;
3989 m_linesPerPage
= clientHeight
/ lineHeight
;
3991 ResetVisibleLinesRange();
3993 SetScrollbars( SCROLL_UNIT_X
, lineHeight
,
3994 GetHeaderWidth() / SCROLL_UNIT_X
,
3995 (entireHeight
+ lineHeight
- 1) / lineHeight
,
3996 GetScrollPos(wxHORIZONTAL
),
3997 GetScrollPos(wxVERTICAL
),
4002 // we have 3 different layout strategies: either layout all items
4003 // horizontally/vertically (wxLC_ALIGN_XXX styles explicitly given) or
4004 // to arrange them in top to bottom, left to right (don't ask me why
4005 // not the other way round...) order
4006 if ( HasFlag(wxLC_ALIGN_LEFT
| wxLC_ALIGN_TOP
) )
4008 int x
= EXTRA_BORDER_X
;
4009 int y
= EXTRA_BORDER_Y
;
4011 wxCoord widthMax
= 0;
4014 for ( i
= 0; i
< count
; i
++ )
4016 wxListLineData
*line
= GetLine(i
);
4017 line
->CalculateSize( &dc
, iconSpacing
);
4018 line
->SetPosition( x
, y
, iconSpacing
);
4020 wxSize sizeLine
= GetLineSize(i
);
4022 if ( HasFlag(wxLC_ALIGN_TOP
) )
4024 if ( sizeLine
.x
> widthMax
)
4025 widthMax
= sizeLine
.x
;
4029 else // wxLC_ALIGN_LEFT
4031 x
+= sizeLine
.x
+ MARGIN_BETWEEN_ROWS
;
4035 if ( HasFlag(wxLC_ALIGN_TOP
) )
4037 // traverse the items again and tweak their sizes so that they are
4038 // all the same in a row
4039 for ( i
= 0; i
< count
; i
++ )
4041 wxListLineData
*line
= GetLine(i
);
4042 line
->m_gi
->ExtendWidth(widthMax
);
4050 (x
+ SCROLL_UNIT_X
) / SCROLL_UNIT_X
,
4051 (y
+ lineHeight
) / lineHeight
,
4052 GetScrollPos( wxHORIZONTAL
),
4053 GetScrollPos( wxVERTICAL
),
4057 else // "flowed" arrangement, the most complicated case
4059 // at first we try without any scrollbars, if the items don't fit into
4060 // the window, we recalculate after subtracting the space taken by the
4063 int entireWidth
= 0;
4065 for (int tries
= 0; tries
< 2; tries
++)
4067 entireWidth
= 2 * EXTRA_BORDER_X
;
4071 // Now we have decided that the items do not fit into the
4072 // client area, so we need a scrollbar
4073 entireWidth
+= SCROLL_UNIT_X
;
4076 int x
= EXTRA_BORDER_X
;
4077 int y
= EXTRA_BORDER_Y
;
4078 int maxWidthInThisRow
= 0;
4081 int currentlyVisibleLines
= 0;
4083 for (size_t i
= 0; i
< count
; i
++)
4085 currentlyVisibleLines
++;
4086 wxListLineData
*line
= GetLine( i
);
4087 line
->CalculateSize( &dc
, iconSpacing
);
4088 line
->SetPosition( x
, y
, iconSpacing
);
4090 wxSize sizeLine
= GetLineSize( i
);
4092 if ( maxWidthInThisRow
< sizeLine
.x
)
4093 maxWidthInThisRow
= sizeLine
.x
;
4096 if (currentlyVisibleLines
> m_linesPerPage
)
4097 m_linesPerPage
= currentlyVisibleLines
;
4099 if ( y
+ sizeLine
.y
>= clientHeight
)
4101 currentlyVisibleLines
= 0;
4103 maxWidthInThisRow
+= MARGIN_BETWEEN_ROWS
;
4104 x
+= maxWidthInThisRow
;
4105 entireWidth
+= maxWidthInThisRow
;
4106 maxWidthInThisRow
= 0;
4109 // We have reached the last item.
4110 if ( i
== count
- 1 )
4111 entireWidth
+= maxWidthInThisRow
;
4113 if ( (tries
== 0) &&
4114 (entireWidth
+ SCROLL_UNIT_X
> clientWidth
) )
4116 clientHeight
-= wxSystemSettings::
4117 GetMetric(wxSYS_HSCROLL_Y
);
4122 if ( i
== count
- 1 )
4123 tries
= 1; // Everything fits, no second try required.
4131 (entireWidth
+ SCROLL_UNIT_X
) / SCROLL_UNIT_X
,
4133 GetScrollPos( wxHORIZONTAL
),
4142 // FIXME: why should we call it from here?
4149 void wxListMainWindow::RefreshAll()
4154 wxListHeaderWindow
*headerWin
= GetListCtrl()->m_headerWin
;
4155 if ( headerWin
&& headerWin
->m_dirty
)
4157 headerWin
->m_dirty
= false;
4158 headerWin
->Refresh();
4162 void wxListMainWindow::UpdateCurrent()
4164 if ( !HasCurrent() && !IsEmpty() )
4168 long wxListMainWindow::GetNextItem( long item
,
4169 int WXUNUSED(geometry
),
4173 max
= GetItemCount();
4174 wxCHECK_MSG( (ret
== -1) || (ret
< max
), -1,
4175 _T("invalid listctrl index in GetNextItem()") );
4177 // notice that we start with the next item (or the first one if item == -1)
4178 // and this is intentional to allow writing a simple loop to iterate over
4179 // all selected items
4182 // this is not an error because the index was OK initially,
4183 // just no such item
4190 size_t count
= GetItemCount();
4191 for ( size_t line
= (size_t)ret
; line
< count
; line
++ )
4193 if ( (state
& wxLIST_STATE_FOCUSED
) && (line
== m_current
) )
4196 if ( (state
& wxLIST_STATE_SELECTED
) && IsHighlighted(line
) )
4203 // ----------------------------------------------------------------------------
4205 // ----------------------------------------------------------------------------
4207 void wxListMainWindow::DeleteItem( long lindex
)
4209 size_t count
= GetItemCount();
4211 wxCHECK_RET( (lindex
>= 0) && ((size_t)lindex
< count
),
4212 _T("invalid item index in DeleteItem") );
4214 size_t index
= (size_t)lindex
;
4216 // we don't need to adjust the index for the previous items
4217 if ( HasCurrent() && m_current
>= index
)
4219 // if the current item is being deleted, we want the next one to
4220 // become selected - unless there is no next one - so don't adjust
4221 // m_current in this case
4222 if ( m_current
!= index
|| m_current
== count
- 1 )
4226 if ( InReportView() )
4228 // mark the Column Max Width cache as dirty if the items in the line
4229 // we're deleting contain the Max Column Width
4230 wxListLineData
* const line
= GetLine(index
);
4231 wxListItemDataList::compatibility_iterator n
;
4232 wxListItemData
*itemData
;
4236 for (size_t i
= 0; i
< m_columns
.GetCount(); i
++)
4238 n
= line
->m_items
.Item( i
);
4239 itemData
= n
->GetData();
4240 itemData
->GetItem(item
);
4242 itemWidth
= GetItemWidthWithImage(&item
);
4244 if (itemWidth
>= m_aColWidths
.Item(i
)->nMaxWidth
)
4245 m_aColWidths
.Item(i
)->bNeedsUpdate
= true;
4248 ResetVisibleLinesRange();
4254 m_selStore
.OnItemDelete(index
);
4258 m_lines
.RemoveAt( index
);
4261 // we need to refresh the (vert) scrollbar as the number of items changed
4264 SendNotify( index
, wxEVT_COMMAND_LIST_DELETE_ITEM
);
4266 RefreshAfter(index
);
4269 void wxListMainWindow::DeleteColumn( int col
)
4271 wxListHeaderDataList::compatibility_iterator node
= m_columns
.Item( col
);
4273 wxCHECK_RET( node
, wxT("invalid column index in DeleteColumn()") );
4276 delete node
->GetData();
4277 m_columns
.Erase( node
);
4281 // update all the items
4282 for ( size_t i
= 0; i
< m_lines
.GetCount(); i
++ )
4284 wxListLineData
* const line
= GetLine(i
);
4285 wxListItemDataList::compatibility_iterator n
= line
->m_items
.Item( col
);
4286 delete n
->GetData();
4287 line
->m_items
.Erase(n
);
4291 if ( InReportView() ) // we only cache max widths when in Report View
4293 delete m_aColWidths
.Item(col
);
4294 m_aColWidths
.RemoveAt(col
);
4297 // invalidate it as it has to be recalculated
4301 void wxListMainWindow::DoDeleteAllItems()
4304 // nothing to do - in particular, don't send the event
4309 // to make the deletion of all items faster, we don't send the
4310 // notifications for each item deletion in this case but only one event
4311 // for all of them: this is compatible with wxMSW and documented in
4312 // DeleteAllItems() description
4314 wxListEvent
event( wxEVT_COMMAND_LIST_DELETE_ALL_ITEMS
, GetParent()->GetId() );
4315 event
.SetEventObject( GetParent() );
4316 GetParent()->GetEventHandler()->ProcessEvent( event
);
4324 if ( InReportView() )
4326 ResetVisibleLinesRange();
4327 for (size_t i
= 0; i
< m_aColWidths
.GetCount(); i
++)
4329 m_aColWidths
.Item(i
)->bNeedsUpdate
= true;
4336 void wxListMainWindow::DeleteAllItems()
4340 RecalculatePositions();
4343 void wxListMainWindow::DeleteEverything()
4345 WX_CLEAR_LIST(wxListHeaderDataList
, m_columns
);
4346 WX_CLEAR_ARRAY(m_aColWidths
);
4351 // ----------------------------------------------------------------------------
4352 // scanning for an item
4353 // ----------------------------------------------------------------------------
4355 void wxListMainWindow::EnsureVisible( long index
)
4357 wxCHECK_RET( index
>= 0 && (size_t)index
< GetItemCount(),
4358 _T("invalid index in EnsureVisible") );
4360 // We have to call this here because the label in question might just have
4361 // been added and its position is not known yet
4363 RecalculatePositions(true /* no refresh */);
4365 MoveToItem((size_t)index
);
4368 long wxListMainWindow::FindItem(long start
, const wxString
& str
, bool WXUNUSED(partial
) )
4375 size_t count
= GetItemCount();
4376 for ( size_t i
= (size_t)pos
; i
< count
; i
++ )
4378 wxListLineData
*line
= GetLine(i
);
4379 if ( line
->GetText(0) == tmp
)
4386 long wxListMainWindow::FindItem(long start
, wxUIntPtr data
)
4392 size_t count
= GetItemCount();
4393 for (size_t i
= (size_t)pos
; i
< count
; i
++)
4395 wxListLineData
*line
= GetLine(i
);
4397 line
->GetItem( 0, item
);
4398 if (item
.m_data
== data
)
4405 long wxListMainWindow::FindItem( const wxPoint
& pt
)
4408 GetVisibleLinesRange( &topItem
, NULL
);
4411 GetItemPosition( GetItemCount() - 1, p
);
4415 long id
= (long)floor( pt
.y
* double(GetItemCount() - topItem
- 1) / p
.y
+ topItem
);
4416 if ( id
>= 0 && id
< (long)GetItemCount() )
4422 long wxListMainWindow::HitTest( int x
, int y
, int &flags
) const
4424 CalcUnscrolledPosition( x
, y
, &x
, &y
);
4426 size_t count
= GetItemCount();
4428 if ( InReportView() )
4430 size_t current
= y
/ GetLineHeight();
4431 if ( current
< count
)
4433 flags
= HitTestLine(current
, x
, y
);
4440 // TODO: optimize it too! this is less simple than for report view but
4441 // enumerating all items is still not a way to do it!!
4442 for ( size_t current
= 0; current
< count
; current
++ )
4444 flags
= HitTestLine(current
, x
, y
);
4453 // ----------------------------------------------------------------------------
4455 // ----------------------------------------------------------------------------
4457 void wxListMainWindow::InsertItem( wxListItem
&item
)
4459 wxASSERT_MSG( !IsVirtual(), _T("can't be used with virtual control") );
4461 int count
= GetItemCount();
4462 wxCHECK_RET( item
.m_itemId
>= 0, _T("invalid item index") );
4464 if (item
.m_itemId
> count
)
4465 item
.m_itemId
= count
;
4467 size_t id
= item
.m_itemId
;
4471 if ( InReportView() )
4473 ResetVisibleLinesRange();
4475 // calculate the width of the item and adjust the max column width
4476 wxColWidthInfo
*pWidthInfo
= m_aColWidths
.Item(item
.GetColumn());
4477 int width
= GetItemWidthWithImage(&item
);
4478 item
.SetWidth(width
);
4479 if (width
> pWidthInfo
->nMaxWidth
)
4480 pWidthInfo
->nMaxWidth
= width
;
4483 wxListLineData
*line
= new wxListLineData(this);
4485 line
->SetItem( item
.m_col
, item
);
4487 m_lines
.Insert( line
, id
);
4491 // If an item is selected at or below the point of insertion, we need to
4492 // increment the member variables because the current row's index has gone
4494 if ( HasCurrent() && m_current
>= id
)
4497 SendNotify(id
, wxEVT_COMMAND_LIST_INSERT_ITEM
);
4499 RefreshLines(id
, GetItemCount() - 1);
4502 void wxListMainWindow::InsertColumn( long col
, wxListItem
&item
)
4505 if ( InReportView() )
4507 if (item
.m_width
== wxLIST_AUTOSIZE_USEHEADER
)
4508 item
.m_width
= GetTextLength( item
.m_text
);
4510 wxListHeaderData
*column
= new wxListHeaderData( item
);
4511 wxColWidthInfo
*colWidthInfo
= new wxColWidthInfo();
4513 bool insert
= (col
>= 0) && ((size_t)col
< m_columns
.GetCount());
4516 wxListHeaderDataList::compatibility_iterator
4517 node
= m_columns
.Item( col
);
4518 m_columns
.Insert( node
, column
);
4519 m_aColWidths
.Insert( colWidthInfo
, col
);
4523 m_columns
.Append( column
);
4524 m_aColWidths
.Add( colWidthInfo
);
4529 // update all the items
4530 for ( size_t i
= 0; i
< m_lines
.GetCount(); i
++ )
4532 wxListLineData
* const line
= GetLine(i
);
4533 wxListItemData
* const data
= new wxListItemData(this);
4535 line
->m_items
.Insert(col
, data
);
4537 line
->m_items
.Append(data
);
4541 // invalidate it as it has to be recalculated
4546 int wxListMainWindow::GetItemWidthWithImage(wxListItem
* item
)
4549 wxClientDC
dc(this);
4551 dc
.SetFont( GetFont() );
4553 if (item
->GetImage() != -1)
4556 GetImageSize( item
->GetImage(), ix
, iy
);
4560 if (!item
->GetText().empty())
4563 dc
.GetTextExtent( item
->GetText(), &w
, NULL
);
4570 // ----------------------------------------------------------------------------
4572 // ----------------------------------------------------------------------------
4574 wxListCtrlCompare list_ctrl_compare_func_2
;
4575 long list_ctrl_compare_data
;
4577 int LINKAGEMODE
list_ctrl_compare_func_1( wxListLineData
**arg1
, wxListLineData
**arg2
)
4579 wxListLineData
*line1
= *arg1
;
4580 wxListLineData
*line2
= *arg2
;
4582 line1
->GetItem( 0, item
);
4583 wxUIntPtr data1
= item
.m_data
;
4584 line2
->GetItem( 0, item
);
4585 wxUIntPtr data2
= item
.m_data
;
4586 return list_ctrl_compare_func_2( data1
, data2
, list_ctrl_compare_data
);
4589 void wxListMainWindow::SortItems( wxListCtrlCompare fn
, long data
)
4591 list_ctrl_compare_func_2
= fn
;
4592 list_ctrl_compare_data
= data
;
4593 m_lines
.Sort( list_ctrl_compare_func_1
);
4597 // ----------------------------------------------------------------------------
4599 // ----------------------------------------------------------------------------
4601 void wxListMainWindow::OnScroll(wxScrollWinEvent
& event
)
4603 // update our idea of which lines are shown when we redraw the window the
4605 ResetVisibleLinesRange();
4608 #if ( defined(__WXGTK__) || defined(__WXMAC__) ) && !defined(__WXUNIVERSAL__)
4609 wxScrolledWindow::OnScroll(event
);
4611 HandleOnScroll( event
);
4614 if ( event
.GetOrientation() == wxHORIZONTAL
&& HasHeader() )
4616 wxGenericListCtrl
* lc
= GetListCtrl();
4617 wxCHECK_RET( lc
, _T("no listctrl window?") );
4619 lc
->m_headerWin
->Refresh();
4620 lc
->m_headerWin
->Update();
4624 int wxListMainWindow::GetCountPerPage() const
4626 if ( !m_linesPerPage
)
4628 wxConstCast(this, wxListMainWindow
)->
4629 m_linesPerPage
= GetClientSize().y
/ GetLineHeight();
4632 return m_linesPerPage
;
4635 void wxListMainWindow::GetVisibleLinesRange(size_t *from
, size_t *to
)
4637 wxASSERT_MSG( InReportView(), _T("this is for report mode only") );
4639 if ( m_lineFrom
== (size_t)-1 )
4641 size_t count
= GetItemCount();
4644 m_lineFrom
= GetScrollPos(wxVERTICAL
);
4646 // this may happen if SetScrollbars() hadn't been called yet
4647 if ( m_lineFrom
>= count
)
4648 m_lineFrom
= count
- 1;
4650 // we redraw one extra line but this is needed to make the redrawing
4651 // logic work when there is a fractional number of lines on screen
4652 m_lineTo
= m_lineFrom
+ m_linesPerPage
;
4653 if ( m_lineTo
>= count
)
4654 m_lineTo
= count
- 1;
4656 else // empty control
4659 m_lineTo
= (size_t)-1;
4663 wxASSERT_MSG( IsEmpty() ||
4664 (m_lineFrom
<= m_lineTo
&& m_lineTo
< GetItemCount()),
4665 _T("GetVisibleLinesRange() returns incorrect result") );
4673 // -------------------------------------------------------------------------------------
4674 // wxGenericListCtrl
4675 // -------------------------------------------------------------------------------------
4677 IMPLEMENT_DYNAMIC_CLASS(wxGenericListCtrl
, wxControl
)
4679 BEGIN_EVENT_TABLE(wxGenericListCtrl
,wxControl
)
4680 EVT_SIZE(wxGenericListCtrl::OnSize
)
4683 wxGenericListCtrl::wxGenericListCtrl()
4685 m_imageListNormal
= (wxImageList
*) NULL
;
4686 m_imageListSmall
= (wxImageList
*) NULL
;
4687 m_imageListState
= (wxImageList
*) NULL
;
4689 m_ownsImageListNormal
=
4690 m_ownsImageListSmall
=
4691 m_ownsImageListState
= false;
4693 m_mainWin
= (wxListMainWindow
*) NULL
;
4694 m_headerWin
= (wxListHeaderWindow
*) NULL
;
4698 wxGenericListCtrl::~wxGenericListCtrl()
4700 if (m_ownsImageListNormal
)
4701 delete m_imageListNormal
;
4702 if (m_ownsImageListSmall
)
4703 delete m_imageListSmall
;
4704 if (m_ownsImageListState
)
4705 delete m_imageListState
;
4708 void wxGenericListCtrl::CalculateAndSetHeaderHeight()
4714 GetThemeMetric( kThemeMetricListHeaderHeight
, &h
);
4716 // we use 'g' to get the descent, too
4718 m_headerWin
->GetTextExtent(wxT("Hg"), &w
, &h
, &d
);
4719 h
+= d
+ 2 * HEADER_OFFSET_Y
+ EXTRA_HEIGHT
;
4722 // only update if changed
4723 if ( h
!= m_headerHeight
)
4728 ResizeReportView(true);
4729 else //why is this needed if it doesn't have a header?
4730 m_headerWin
->SetSize(m_headerWin
->GetSize().x
, m_headerHeight
);
4735 void wxGenericListCtrl::CreateHeaderWindow()
4737 m_headerWin
= new wxListHeaderWindow
4739 this, wxID_ANY
, m_mainWin
,
4741 wxSize(GetClientSize().x
, m_headerHeight
),
4744 CalculateAndSetHeaderHeight();
4747 bool wxGenericListCtrl::Create(wxWindow
*parent
,
4752 const wxValidator
&validator
,
4753 const wxString
&name
)
4757 m_imageListState
= (wxImageList
*) NULL
;
4758 m_ownsImageListNormal
=
4759 m_ownsImageListSmall
=
4760 m_ownsImageListState
= false;
4762 m_mainWin
= (wxListMainWindow
*) NULL
;
4763 m_headerWin
= (wxListHeaderWindow
*) NULL
;
4767 if ( !(style
& wxLC_MASK_TYPE
) )
4769 style
= style
| wxLC_LIST
;
4772 if ( !wxControl::Create( parent
, id
, pos
, size
, style
, validator
, name
) )
4775 // don't create the inner window with the border
4776 style
&= ~wxBORDER_MASK
;
4778 m_mainWin
= new wxListMainWindow( this, wxID_ANY
, wxPoint(0, 0), size
, style
);
4780 #ifdef __WXMAC_CARBON__
4781 // Human Interface Guidelines ask us for a special font in this case
4782 if ( GetWindowVariant() == wxWINDOW_VARIANT_NORMAL
)
4785 font
.MacCreateThemeFont( kThemeViewsFont
);
4790 if ( InReportView() )
4792 CreateHeaderWindow();
4794 #ifdef __WXMAC_CARBON__
4798 font
.MacCreateThemeFont( kThemeSmallSystemFont
);
4799 m_headerWin
->SetFont( font
);
4800 CalculateAndSetHeaderHeight();
4804 if ( HasFlag(wxLC_NO_HEADER
) )
4805 // VZ: why do we create it at all then?
4806 m_headerWin
->Show( false );
4814 void wxGenericListCtrl::SetSingleStyle( long style
, bool add
)
4816 wxASSERT_MSG( !(style
& wxLC_VIRTUAL
),
4817 _T("wxLC_VIRTUAL can't be [un]set") );
4819 long flag
= GetWindowStyle();
4823 if (style
& wxLC_MASK_TYPE
)
4824 flag
&= ~(wxLC_MASK_TYPE
| wxLC_VIRTUAL
);
4825 if (style
& wxLC_MASK_ALIGN
)
4826 flag
&= ~wxLC_MASK_ALIGN
;
4827 if (style
& wxLC_MASK_SORT
)
4828 flag
&= ~wxLC_MASK_SORT
;
4836 SetWindowStyleFlag( flag
);
4839 void wxGenericListCtrl::SetWindowStyleFlag( long flag
)
4843 m_mainWin
->DeleteEverything();
4845 // has the header visibility changed?
4846 bool hasHeader
= HasHeader();
4847 bool willHaveHeader
= (flag
& wxLC_REPORT
) && !(flag
& wxLC_NO_HEADER
);
4849 if ( hasHeader
!= willHaveHeader
)
4856 // don't delete, just hide, as we can reuse it later
4857 m_headerWin
->Show(false);
4859 //else: nothing to do
4861 else // must show header
4865 CreateHeaderWindow();
4867 else // already have it, just show
4869 m_headerWin
->Show( true );
4873 ResizeReportView(willHaveHeader
);
4877 wxWindow::SetWindowStyleFlag( flag
);
4880 bool wxGenericListCtrl::GetColumn(int col
, wxListItem
&item
) const
4882 m_mainWin
->GetColumn( col
, item
);
4886 bool wxGenericListCtrl::SetColumn( int col
, wxListItem
& item
)
4888 m_mainWin
->SetColumn( col
, item
);
4892 int wxGenericListCtrl::GetColumnWidth( int col
) const
4894 return m_mainWin
->GetColumnWidth( col
);
4897 bool wxGenericListCtrl::SetColumnWidth( int col
, int width
)
4899 m_mainWin
->SetColumnWidth( col
, width
);
4903 int wxGenericListCtrl::GetCountPerPage() const
4905 return m_mainWin
->GetCountPerPage(); // different from Windows ?
4908 bool wxGenericListCtrl::GetItem( wxListItem
&info
) const
4910 m_mainWin
->GetItem( info
);
4914 bool wxGenericListCtrl::SetItem( wxListItem
&info
)
4916 m_mainWin
->SetItem( info
);
4920 long wxGenericListCtrl::SetItem( long index
, int col
, const wxString
& label
, int imageId
)
4923 info
.m_text
= label
;
4924 info
.m_mask
= wxLIST_MASK_TEXT
;
4925 info
.m_itemId
= index
;
4929 info
.m_image
= imageId
;
4930 info
.m_mask
|= wxLIST_MASK_IMAGE
;
4933 m_mainWin
->SetItem(info
);
4937 int wxGenericListCtrl::GetItemState( long item
, long stateMask
) const
4939 return m_mainWin
->GetItemState( item
, stateMask
);
4942 bool wxGenericListCtrl::SetItemState( long item
, long state
, long stateMask
)
4944 m_mainWin
->SetItemState( item
, state
, stateMask
);
4949 wxGenericListCtrl::SetItemImage( long item
, int image
, int WXUNUSED(selImage
) )
4951 return SetItemColumnImage(item
, 0, image
);
4955 wxGenericListCtrl::SetItemColumnImage( long item
, long column
, int image
)
4958 info
.m_image
= image
;
4959 info
.m_mask
= wxLIST_MASK_IMAGE
;
4960 info
.m_itemId
= item
;
4961 info
.m_col
= column
;
4962 m_mainWin
->SetItem( info
);
4966 wxString
wxGenericListCtrl::GetItemText( long item
) const
4968 return m_mainWin
->GetItemText(item
);
4971 void wxGenericListCtrl::SetItemText( long item
, const wxString
& str
)
4973 m_mainWin
->SetItemText(item
, str
);
4976 wxUIntPtr
wxGenericListCtrl::GetItemData( long item
) const
4979 info
.m_mask
= wxLIST_MASK_DATA
;
4980 info
.m_itemId
= item
;
4981 m_mainWin
->GetItem( info
);
4985 bool wxGenericListCtrl::SetItemData( long item
, long data
)
4988 info
.m_mask
= wxLIST_MASK_DATA
;
4989 info
.m_itemId
= item
;
4991 m_mainWin
->SetItem( info
);
4995 wxRect
wxGenericListCtrl::GetViewRect() const
4997 return m_mainWin
->GetViewRect();
5000 bool wxGenericListCtrl::GetItemRect( long item
, wxRect
&rect
, int WXUNUSED(code
) ) const
5002 m_mainWin
->GetItemRect( item
, rect
);
5003 if ( m_mainWin
->HasHeader() )
5004 rect
.y
+= m_headerHeight
+ 1;
5008 bool wxGenericListCtrl::GetItemPosition( long item
, wxPoint
& pos
) const
5010 m_mainWin
->GetItemPosition( item
, pos
);
5014 bool wxGenericListCtrl::SetItemPosition( long WXUNUSED(item
), const wxPoint
& WXUNUSED(pos
) )
5019 int wxGenericListCtrl::GetItemCount() const
5021 return m_mainWin
->GetItemCount();
5024 int wxGenericListCtrl::GetColumnCount() const
5026 return m_mainWin
->GetColumnCount();
5029 void wxGenericListCtrl::SetItemSpacing( int spacing
, bool isSmall
)
5031 m_mainWin
->SetItemSpacing( spacing
, isSmall
);
5034 wxSize
wxGenericListCtrl::GetItemSpacing() const
5036 const int spacing
= m_mainWin
->GetItemSpacing(HasFlag(wxLC_SMALL_ICON
));
5038 return wxSize(spacing
, spacing
);
5041 #if WXWIN_COMPATIBILITY_2_6
5042 int wxGenericListCtrl::GetItemSpacing( bool isSmall
) const
5044 return m_mainWin
->GetItemSpacing( isSmall
);
5046 #endif // WXWIN_COMPATIBILITY_2_6
5048 void wxGenericListCtrl::SetItemTextColour( long item
, const wxColour
&col
)
5051 info
.m_itemId
= item
;
5052 info
.SetTextColour( col
);
5053 m_mainWin
->SetItem( info
);
5056 wxColour
wxGenericListCtrl::GetItemTextColour( long item
) const
5059 info
.m_itemId
= item
;
5060 m_mainWin
->GetItem( info
);
5061 return info
.GetTextColour();
5064 void wxGenericListCtrl::SetItemBackgroundColour( long item
, const wxColour
&col
)
5067 info
.m_itemId
= item
;
5068 info
.SetBackgroundColour( col
);
5069 m_mainWin
->SetItem( info
);
5072 wxColour
wxGenericListCtrl::GetItemBackgroundColour( long item
) const
5075 info
.m_itemId
= item
;
5076 m_mainWin
->GetItem( info
);
5077 return info
.GetBackgroundColour();
5080 void wxGenericListCtrl::SetItemFont( long item
, const wxFont
&f
)
5083 info
.m_itemId
= item
;
5085 m_mainWin
->SetItem( info
);
5088 wxFont
wxGenericListCtrl::GetItemFont( long item
) const
5091 info
.m_itemId
= item
;
5092 m_mainWin
->GetItem( info
);
5093 return info
.GetFont();
5096 int wxGenericListCtrl::GetSelectedItemCount() const
5098 return m_mainWin
->GetSelectedItemCount();
5101 wxColour
wxGenericListCtrl::GetTextColour() const
5103 return GetForegroundColour();
5106 void wxGenericListCtrl::SetTextColour(const wxColour
& col
)
5108 SetForegroundColour(col
);
5111 long wxGenericListCtrl::GetTopItem() const
5114 m_mainWin
->GetVisibleLinesRange(&top
, NULL
);
5118 long wxGenericListCtrl::GetNextItem( long item
, int geom
, int state
) const
5120 return m_mainWin
->GetNextItem( item
, geom
, state
);
5123 wxImageList
*wxGenericListCtrl::GetImageList(int which
) const
5125 if (which
== wxIMAGE_LIST_NORMAL
)
5126 return m_imageListNormal
;
5127 else if (which
== wxIMAGE_LIST_SMALL
)
5128 return m_imageListSmall
;
5129 else if (which
== wxIMAGE_LIST_STATE
)
5130 return m_imageListState
;
5132 return (wxImageList
*) NULL
;
5135 void wxGenericListCtrl::SetImageList( wxImageList
*imageList
, int which
)
5137 if ( which
== wxIMAGE_LIST_NORMAL
)
5139 if (m_ownsImageListNormal
)
5140 delete m_imageListNormal
;
5141 m_imageListNormal
= imageList
;
5142 m_ownsImageListNormal
= false;
5144 else if ( which
== wxIMAGE_LIST_SMALL
)
5146 if (m_ownsImageListSmall
)
5147 delete m_imageListSmall
;
5148 m_imageListSmall
= imageList
;
5149 m_ownsImageListSmall
= false;
5151 else if ( which
== wxIMAGE_LIST_STATE
)
5153 if (m_ownsImageListState
)
5154 delete m_imageListState
;
5155 m_imageListState
= imageList
;
5156 m_ownsImageListState
= false;
5159 m_mainWin
->SetImageList( imageList
, which
);
5162 void wxGenericListCtrl::AssignImageList(wxImageList
*imageList
, int which
)
5164 SetImageList(imageList
, which
);
5165 if ( which
== wxIMAGE_LIST_NORMAL
)
5166 m_ownsImageListNormal
= true;
5167 else if ( which
== wxIMAGE_LIST_SMALL
)
5168 m_ownsImageListSmall
= true;
5169 else if ( which
== wxIMAGE_LIST_STATE
)
5170 m_ownsImageListState
= true;
5173 bool wxGenericListCtrl::Arrange( int WXUNUSED(flag
) )
5178 bool wxGenericListCtrl::DeleteItem( long item
)
5180 m_mainWin
->DeleteItem( item
);
5184 bool wxGenericListCtrl::DeleteAllItems()
5186 m_mainWin
->DeleteAllItems();
5190 bool wxGenericListCtrl::DeleteAllColumns()
5192 size_t count
= m_mainWin
->m_columns
.GetCount();
5193 for ( size_t n
= 0; n
< count
; n
++ )
5198 void wxGenericListCtrl::ClearAll()
5200 m_mainWin
->DeleteEverything();
5203 bool wxGenericListCtrl::DeleteColumn( int col
)
5205 m_mainWin
->DeleteColumn( col
);
5207 // if we don't have the header any longer, we need to relayout the window
5208 if ( !GetColumnCount() )
5209 ResizeReportView(false /* no header */);
5213 wxTextCtrl
*wxGenericListCtrl::EditLabel(long item
,
5214 wxClassInfo
* textControlClass
)
5216 return m_mainWin
->EditLabel( item
, textControlClass
);
5219 wxTextCtrl
*wxGenericListCtrl::GetEditControl() const
5221 return m_mainWin
->GetEditControl();
5224 bool wxGenericListCtrl::EnsureVisible( long item
)
5226 m_mainWin
->EnsureVisible( item
);
5230 long wxGenericListCtrl::FindItem( long start
, const wxString
& str
, bool partial
)
5232 return m_mainWin
->FindItem( start
, str
, partial
);
5235 long wxGenericListCtrl::FindItem( long start
, wxUIntPtr data
)
5237 return m_mainWin
->FindItem( start
, data
);
5240 long wxGenericListCtrl::FindItem( long WXUNUSED(start
), const wxPoint
& pt
,
5241 int WXUNUSED(direction
))
5243 return m_mainWin
->FindItem( pt
);
5246 // TODO: sub item hit testing
5247 long wxGenericListCtrl::HitTest(const wxPoint
& point
, int& flags
, long *) const
5249 return m_mainWin
->HitTest( (int)point
.x
, (int)point
.y
, flags
);
5252 long wxGenericListCtrl::InsertItem( wxListItem
& info
)
5254 m_mainWin
->InsertItem( info
);
5255 return info
.m_itemId
;
5258 long wxGenericListCtrl::InsertItem( long index
, const wxString
&label
)
5261 info
.m_text
= label
;
5262 info
.m_mask
= wxLIST_MASK_TEXT
;
5263 info
.m_itemId
= index
;
5264 return InsertItem( info
);
5267 long wxGenericListCtrl::InsertItem( long index
, int imageIndex
)
5270 info
.m_mask
= wxLIST_MASK_IMAGE
;
5271 info
.m_image
= imageIndex
;
5272 info
.m_itemId
= index
;
5273 return InsertItem( info
);
5276 long wxGenericListCtrl::InsertItem( long index
, const wxString
&label
, int imageIndex
)
5279 info
.m_text
= label
;
5280 info
.m_image
= imageIndex
;
5281 info
.m_mask
= wxLIST_MASK_TEXT
| wxLIST_MASK_IMAGE
;
5282 info
.m_itemId
= index
;
5283 return InsertItem( info
);
5286 long wxGenericListCtrl::InsertColumn( long col
, wxListItem
&item
)
5288 wxCHECK_MSG( m_headerWin
, -1, _T("can't add column in non report mode") );
5290 m_mainWin
->InsertColumn( col
, item
);
5292 // if we hadn't had a header before but have one now
5293 // then we need to relayout the window
5294 if ( GetColumnCount() == 1 && m_mainWin
->HasHeader() )
5295 ResizeReportView(true /* have header */);
5297 m_headerWin
->Refresh();
5302 long wxGenericListCtrl::InsertColumn( long col
, const wxString
&heading
,
5303 int format
, int width
)
5306 item
.m_mask
= wxLIST_MASK_TEXT
| wxLIST_MASK_FORMAT
;
5307 item
.m_text
= heading
;
5310 item
.m_mask
|= wxLIST_MASK_WIDTH
;
5311 item
.m_width
= width
;
5314 item
.m_format
= format
;
5316 return InsertColumn( col
, item
);
5319 bool wxGenericListCtrl::ScrollList( int WXUNUSED(dx
), int WXUNUSED(dy
) )
5325 // fn is a function which takes 3 long arguments: item1, item2, data.
5326 // item1 is the long data associated with a first item (NOT the index).
5327 // item2 is the long data associated with a second item (NOT the index).
5328 // data is the same value as passed to SortItems.
5329 // The return value is a negative number if the first item should precede the second
5330 // item, a positive number of the second item should precede the first,
5331 // or zero if the two items are equivalent.
5332 // data is arbitrary data to be passed to the sort function.
5334 bool wxGenericListCtrl::SortItems( wxListCtrlCompare fn
, long data
)
5336 m_mainWin
->SortItems( fn
, data
);
5340 // ----------------------------------------------------------------------------
5342 // ----------------------------------------------------------------------------
5344 void wxGenericListCtrl::OnSize(wxSizeEvent
& WXUNUSED(event
))
5349 ResizeReportView(m_mainWin
->HasHeader());
5350 m_mainWin
->RecalculatePositions();
5353 void wxGenericListCtrl::ResizeReportView(bool showHeader
)
5356 GetClientSize( &cw
, &ch
);
5360 m_headerWin
->SetSize( 0, 0, cw
, m_headerHeight
);
5361 if(ch
> m_headerHeight
)
5362 m_mainWin
->SetSize( 0, m_headerHeight
+ 1,
5363 cw
, ch
- m_headerHeight
- 1 );
5365 m_mainWin
->SetSize( 0, m_headerHeight
+ 1,
5368 else // no header window
5370 m_mainWin
->SetSize( 0, 0, cw
, ch
);
5374 void wxGenericListCtrl::OnInternalIdle()
5376 wxWindow::OnInternalIdle();
5378 // do it only if needed
5379 if ( !m_mainWin
->m_dirty
)
5382 m_mainWin
->RecalculatePositions();
5385 // ----------------------------------------------------------------------------
5387 // ----------------------------------------------------------------------------
5389 bool wxGenericListCtrl::SetBackgroundColour( const wxColour
&colour
)
5393 m_mainWin
->SetBackgroundColour( colour
);
5394 m_mainWin
->m_dirty
= true;
5400 bool wxGenericListCtrl::SetForegroundColour( const wxColour
&colour
)
5402 if ( !wxWindow::SetForegroundColour( colour
) )
5407 m_mainWin
->SetForegroundColour( colour
);
5408 m_mainWin
->m_dirty
= true;
5412 m_headerWin
->SetForegroundColour( colour
);
5417 bool wxGenericListCtrl::SetFont( const wxFont
&font
)
5419 if ( !wxWindow::SetFont( font
) )
5424 m_mainWin
->SetFont( font
);
5425 m_mainWin
->m_dirty
= true;
5430 m_headerWin
->SetFont( font
);
5431 CalculateAndSetHeaderHeight();
5441 wxGenericListCtrl::GetClassDefaultAttributes(wxWindowVariant variant
)
5444 // Use the same color scheme as wxListBox
5445 return wxListBox::GetClassDefaultAttributes(variant
);
5447 wxUnusedVar(variant
);
5448 wxVisualAttributes attr
;
5449 attr
.colFg
= wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT
);
5450 attr
.colBg
= wxSystemSettings::GetColour(wxSYS_COLOUR_LISTBOX
);
5451 attr
.font
= wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT
);
5456 // ----------------------------------------------------------------------------
5457 // methods forwarded to m_mainWin
5458 // ----------------------------------------------------------------------------
5460 #if wxUSE_DRAG_AND_DROP
5462 void wxGenericListCtrl::SetDropTarget( wxDropTarget
*dropTarget
)
5464 m_mainWin
->SetDropTarget( dropTarget
);
5467 wxDropTarget
*wxGenericListCtrl::GetDropTarget() const
5469 return m_mainWin
->GetDropTarget();
5474 bool wxGenericListCtrl::SetCursor( const wxCursor
&cursor
)
5476 return m_mainWin
? m_mainWin
->wxWindow::SetCursor(cursor
) : false;
5479 wxColour
wxGenericListCtrl::GetBackgroundColour() const
5481 return m_mainWin
? m_mainWin
->GetBackgroundColour() : wxColour();
5484 wxColour
wxGenericListCtrl::GetForegroundColour() const
5486 return m_mainWin
? m_mainWin
->GetForegroundColour() : wxColour();
5489 bool wxGenericListCtrl::DoPopupMenu( wxMenu
*menu
, int x
, int y
)
5492 return m_mainWin
->PopupMenu( menu
, x
, y
);
5498 void wxGenericListCtrl::DoClientToScreen( int *x
, int *y
) const
5500 m_mainWin
->DoClientToScreen(x
, y
);
5503 void wxGenericListCtrl::DoScreenToClient( int *x
, int *y
) const
5505 m_mainWin
->DoScreenToClient(x
, y
);
5508 void wxGenericListCtrl::SetFocus()
5510 // The test in window.cpp fails as we are a composite
5511 // window, so it checks against "this", but not m_mainWin.
5512 if ( DoFindFocus() != this )
5513 m_mainWin
->SetFocus();
5516 wxSize
wxGenericListCtrl::DoGetBestSize() const
5518 // Something is better than nothing...
5519 // 100x80 is what the MSW version will get from the default
5520 // wxControl::DoGetBestSize
5521 return wxSize(100, 80);
5524 // ----------------------------------------------------------------------------
5525 // virtual list control support
5526 // ----------------------------------------------------------------------------
5528 wxString
wxGenericListCtrl::OnGetItemText(long WXUNUSED(item
), long WXUNUSED(col
)) const
5530 // this is a pure virtual function, in fact - which is not really pure
5531 // because the controls which are not virtual don't need to implement it
5532 wxFAIL_MSG( _T("wxGenericListCtrl::OnGetItemText not supposed to be called") );
5534 return wxEmptyString
;
5537 int wxGenericListCtrl::OnGetItemImage(long WXUNUSED(item
)) const
5539 wxCHECK_MSG(!GetImageList(wxIMAGE_LIST_SMALL
),
5541 wxT("List control has an image list, OnGetItemImage or OnGetItemColumnImage should be overridden."));
5545 int wxGenericListCtrl::OnGetItemColumnImage(long item
, long column
) const
5548 return OnGetItemImage(item
);
5554 wxGenericListCtrl::OnGetItemAttr(long WXUNUSED_UNLESS_DEBUG(item
)) const
5556 wxASSERT_MSG( item
>= 0 && item
< GetItemCount(),
5557 _T("invalid item index in OnGetItemAttr()") );
5559 // no attributes by default
5563 void wxGenericListCtrl::SetItemCount(long count
)
5565 wxASSERT_MSG( IsVirtual(), _T("this is for virtual controls only") );
5567 m_mainWin
->SetItemCount(count
);
5570 void wxGenericListCtrl::RefreshItem(long item
)
5572 m_mainWin
->RefreshLine(item
);
5575 void wxGenericListCtrl::RefreshItems(long itemFrom
, long itemTo
)
5577 m_mainWin
->RefreshLines(itemFrom
, itemTo
);
5580 // Generic wxListCtrl is more or less a container for two other
5581 // windows which drawings are done upon. These are namely
5582 // 'm_headerWin' and 'm_mainWin'.
5583 // Here we override 'virtual wxWindow::Refresh()' to mimic the
5584 // behaviour wxListCtrl has under wxMSW.
5586 void wxGenericListCtrl::Refresh(bool eraseBackground
, const wxRect
*rect
)
5590 // The easy case, no rectangle specified.
5592 m_headerWin
->Refresh(eraseBackground
);
5595 m_mainWin
->Refresh(eraseBackground
);
5599 // Refresh the header window
5602 wxRect rectHeader
= m_headerWin
->GetRect();
5603 rectHeader
.Intersect(*rect
);
5604 if (rectHeader
.GetWidth() && rectHeader
.GetHeight())
5607 m_headerWin
->GetPosition(&x
, &y
);
5608 rectHeader
.Offset(-x
, -y
);
5609 m_headerWin
->Refresh(eraseBackground
, &rectHeader
);
5613 // Refresh the main window
5616 wxRect rectMain
= m_mainWin
->GetRect();
5617 rectMain
.Intersect(*rect
);
5618 if (rectMain
.GetWidth() && rectMain
.GetHeight())
5621 m_mainWin
->GetPosition(&x
, &y
);
5622 rectMain
.Offset(-x
, -y
);
5623 m_mainWin
->Refresh(eraseBackground
, &rectMain
);
5629 void wxGenericListCtrl::Freeze()
5631 m_mainWin
->Freeze();
5634 void wxGenericListCtrl::Thaw()
5639 #endif // wxUSE_LISTCTRL