1 /////////////////////////////////////////////////////////////////////////////
2 // Name: generic/listctrl.cpp
3 // Purpose: generic implementation of wxListCtrl
4 // Author: Robert Roebling
5 // Vadim Zeitlin (virtual list control support)
7 // Copyright: (c) 1998 Robert Roebling
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
14 1. we need to implement searching/sorting for virtual controls somehow
15 ?2. when changing selection the lines are refreshed twice
18 // ============================================================================
20 // ============================================================================
22 // ----------------------------------------------------------------------------
24 // ----------------------------------------------------------------------------
26 // For compilers that support precompilation, includes "wx.h".
27 #include "wx/wxprec.h"
38 #include "wx/dynarray.h"
40 #include "wx/dcscreen.h"
42 #include "wx/textctrl.h"
45 // under Win32 we always use the native version and also may use the generic
46 // one, however some things should be done only if we use only the generic
48 #if defined(__WIN32__) && !defined(__WXUNIVERSAL__)
49 #define HAVE_NATIVE_LISTCTRL
52 // if we have the native control, wx/listctrl.h declares it and not this one
53 #ifdef HAVE_NATIVE_LISTCTRL
54 #include "wx/generic/listctrl.h"
55 #else // !HAVE_NATIVE_LISTCTRL
56 #include "wx/listctrl.h"
58 // if we have a native version, its implementation file does all this
59 IMPLEMENT_DYNAMIC_CLASS(wxListItem
, wxObject
)
60 IMPLEMENT_DYNAMIC_CLASS(wxListView
, wxListCtrl
)
61 IMPLEMENT_DYNAMIC_CLASS(wxListEvent
, wxNotifyEvent
)
63 IMPLEMENT_DYNAMIC_CLASS(wxListCtrl
, wxGenericListCtrl
)
64 #endif // HAVE_NATIVE_LISTCTRL/!HAVE_NATIVE_LISTCTRL
66 #include "wx/selstore.h"
67 #include "wx/renderer.h"
71 #include "wx/mac/private.h"
76 // NOTE: If using the wxListBox visual attributes works everywhere then this can
77 // be removed, as well as the #else case below.
78 #define _USE_VISATTR 0
81 // ----------------------------------------------------------------------------
83 // ----------------------------------------------------------------------------
85 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_BEGIN_DRAG
)
86 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_BEGIN_RDRAG
)
87 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_BEGIN_LABEL_EDIT
)
88 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_END_LABEL_EDIT
)
89 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_DELETE_ITEM
)
90 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_DELETE_ALL_ITEMS
)
91 #if WXWIN_COMPATIBILITY_2_4
92 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_GET_INFO
)
93 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_SET_INFO
)
95 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_ITEM_SELECTED
)
96 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_ITEM_DESELECTED
)
97 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_KEY_DOWN
)
98 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_INSERT_ITEM
)
99 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_COL_CLICK
)
100 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_COL_RIGHT_CLICK
)
101 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_COL_BEGIN_DRAG
)
102 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_COL_DRAGGING
)
103 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_COL_END_DRAG
)
104 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_ITEM_RIGHT_CLICK
)
105 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_ITEM_MIDDLE_CLICK
)
106 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_ITEM_ACTIVATED
)
107 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_ITEM_FOCUSED
)
108 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_CACHE_HINT
)
110 // ----------------------------------------------------------------------------
112 // ----------------------------------------------------------------------------
114 // // the height of the header window (FIXME: should depend on its font!)
115 // static const int HEADER_HEIGHT = 23;
117 static const int SCROLL_UNIT_X
= 15;
119 // the spacing between the lines (in report mode)
120 static const int LINE_SPACING
= 0;
122 // extra margins around the text label
123 static const int EXTRA_WIDTH
= 4;
124 static const int EXTRA_HEIGHT
= 4;
126 // margin between the window and the items
127 static const int EXTRA_BORDER_X
= 2;
128 static const int EXTRA_BORDER_Y
= 2;
130 // offset for the header window
131 static const int HEADER_OFFSET_X
= 1;
132 static const int HEADER_OFFSET_Y
= 1;
134 // margin between rows of icons in [small] icon view
135 static const int MARGIN_BETWEEN_ROWS
= 6;
137 // when autosizing the columns, add some slack
138 static const int AUTOSIZE_COL_MARGIN
= 10;
140 // default width for the header columns
141 static const int WIDTH_COL_DEFAULT
= 80;
143 // the space between the image and the text in the report mode
144 static const int IMAGE_MARGIN_IN_REPORT_MODE
= 5;
146 // ============================================================================
148 // ============================================================================
150 //-----------------------------------------------------------------------------
151 // wxColWidthInfo (internal)
152 //-----------------------------------------------------------------------------
154 struct wxColWidthInfo
157 bool bNeedsUpdate
; // only set to true when an item whose
158 // width == nMaxWidth is removed
160 wxColWidthInfo(int w
= 0, bool needsUpdate
= false)
163 bNeedsUpdate
= needsUpdate
;
167 WX_DEFINE_ARRAY_PTR(wxColWidthInfo
*, ColWidthArray
);
169 //-----------------------------------------------------------------------------
170 // wxListItemData (internal)
171 //-----------------------------------------------------------------------------
173 class WXDLLEXPORT wxListItemData
176 wxListItemData(wxListMainWindow
*owner
);
179 void SetItem( const wxListItem
&info
);
180 void SetImage( int image
) { m_image
= image
; }
181 void SetData( wxUIntPtr data
) { m_data
= data
; }
182 void SetPosition( int x
, int y
);
183 void SetSize( int width
, int height
);
185 bool HasText() const { return !m_text
.empty(); }
186 const wxString
& GetText() const { return m_text
; }
187 void SetText(const wxString
& text
) { m_text
= text
; }
189 // we can't use empty string for measuring the string width/height, so
190 // always return something
191 wxString
GetTextForMeasuring() const
193 wxString s
= GetText();
200 bool IsHit( int x
, int y
) const;
204 int GetWidth() const;
205 int GetHeight() const;
207 int GetImage() const { return m_image
; }
208 bool HasImage() const { return GetImage() != -1; }
210 void GetItem( wxListItem
&info
) const;
212 void SetAttr(wxListItemAttr
*attr
) { m_attr
= attr
; }
213 wxListItemAttr
*GetAttr() const { return m_attr
; }
216 // the item image or -1
219 // user data associated with the item
222 // the item coordinates are not used in report mode, instead this pointer
223 // is NULL and the owner window is used to retrieve the item position and
227 // the list ctrl we are in
228 wxListMainWindow
*m_owner
;
230 // custom attributes or NULL
231 wxListItemAttr
*m_attr
;
234 // common part of all ctors
240 //-----------------------------------------------------------------------------
241 // wxListHeaderData (internal)
242 //-----------------------------------------------------------------------------
244 class WXDLLEXPORT wxListHeaderData
: public wxObject
248 wxListHeaderData( const wxListItem
&info
);
249 void SetItem( const wxListItem
&item
);
250 void SetPosition( int x
, int y
);
251 void SetWidth( int w
);
252 void SetFormat( int format
);
253 void SetHeight( int h
);
254 bool HasImage() const;
256 bool HasText() const { return !m_text
.empty(); }
257 const wxString
& GetText() const { return m_text
; }
258 void SetText(const wxString
& text
) { m_text
= text
; }
260 void GetItem( wxListItem
&item
);
262 bool IsHit( int x
, int y
) const;
263 int GetImage() const;
264 int GetWidth() const;
265 int GetFormat() const;
281 //-----------------------------------------------------------------------------
282 // wxListLineData (internal)
283 //-----------------------------------------------------------------------------
285 WX_DECLARE_LIST(wxListItemData
, wxListItemDataList
);
286 #include "wx/listimpl.cpp"
287 WX_DEFINE_LIST(wxListItemDataList
)
292 // the list of subitems: only may have more than one item in report mode
293 wxListItemDataList m_items
;
295 // this is not used in report view
307 // the part to be highlighted
308 wxRect m_rectHighlight
;
310 // extend all our rects to be centered inside the one of given width
311 void ExtendWidth(wxCoord w
)
313 wxASSERT_MSG( m_rectAll
.width
<= w
,
314 _T("width can only be increased") );
317 m_rectLabel
.x
= m_rectAll
.x
+ (w
- m_rectLabel
.width
)/2;
318 m_rectIcon
.x
= m_rectAll
.x
+ (w
- m_rectIcon
.width
)/2;
319 m_rectHighlight
.x
= m_rectAll
.x
+ (w
- m_rectHighlight
.width
)/2;
323 // is this item selected? [NB: not used in virtual mode]
326 // back pointer to the list ctrl
327 wxListMainWindow
*m_owner
;
330 wxListLineData(wxListMainWindow
*owner
);
334 WX_CLEAR_LIST(wxListItemDataList
, m_items
);
338 // are we in report mode?
339 inline bool InReportView() const;
341 // are we in virtual report mode?
342 inline bool IsVirtual() const;
344 // these 2 methods shouldn't be called for report view controls, in that
345 // case we determine our position/size ourselves
347 // calculate the size of the line
348 void CalculateSize( wxDC
*dc
, int spacing
);
350 // remember the position this line appears at
351 void SetPosition( int x
, int y
, int spacing
);
355 void SetImage( int image
) { SetImage(0, image
); }
356 int GetImage() const { return GetImage(0); }
357 bool HasImage() const { return GetImage() != -1; }
358 bool HasText() const { return !GetText(0).empty(); }
360 void SetItem( int index
, const wxListItem
&info
);
361 void GetItem( int index
, wxListItem
&info
);
363 wxString
GetText(int index
) const;
364 void SetText( int index
, const wxString
& s
);
366 wxListItemAttr
*GetAttr() const;
367 void SetAttr(wxListItemAttr
*attr
);
369 // return true if the highlighting really changed
370 bool Highlight( bool on
);
372 void ReverseHighlight();
374 bool IsHighlighted() const
376 wxASSERT_MSG( !IsVirtual(), _T("unexpected call to IsHighlighted") );
378 return m_highlighted
;
381 // draw the line on the given DC in icon/list mode
382 void Draw( wxDC
*dc
);
384 // the same in report mode
385 void DrawInReportMode( wxDC
*dc
,
387 const wxRect
& rectHL
,
391 // set the line to contain num items (only can be > 1 in report mode)
392 void InitItems( int num
);
394 // get the mode (i.e. style) of the list control
395 inline int GetMode() const;
397 // prepare the DC for drawing with these item's attributes, return true if
398 // we need to draw the items background to highlight it, false otherwise
399 bool SetAttributes(wxDC
*dc
,
400 const wxListItemAttr
*attr
,
403 // draw the text on the DC with the correct justification; also add an
404 // ellipsis if the text is too large to fit in the current width
405 void DrawTextFormatted(wxDC
*dc
, const wxString
&text
, int col
, int x
, int y
, int width
);
407 // these are only used by GetImage/SetImage above, we don't support images
408 // with subitems at the public API level yet
409 void SetImage( int index
, int image
);
410 int GetImage( int index
) const;
413 WX_DECLARE_EXPORTED_OBJARRAY(wxListLineData
, wxListLineDataArray
);
414 #include "wx/arrimpl.cpp"
415 WX_DEFINE_OBJARRAY(wxListLineDataArray
)
417 //-----------------------------------------------------------------------------
418 // wxListHeaderWindow (internal)
419 //-----------------------------------------------------------------------------
421 class WXDLLEXPORT wxListHeaderWindow
: public wxWindow
424 wxListMainWindow
*m_owner
;
425 wxCursor
*m_currentCursor
;
426 wxCursor
*m_resizeCursor
;
429 // column being resized or -1
432 // divider line position in logical (unscrolled) coords
435 // minimal position beyond which the divider line can't be dragged in
440 wxListHeaderWindow();
442 wxListHeaderWindow( wxWindow
*win
,
444 wxListMainWindow
*owner
,
445 const wxPoint
&pos
= wxDefaultPosition
,
446 const wxSize
&size
= wxDefaultSize
,
448 const wxString
&name
= wxT("wxlistctrlcolumntitles") );
450 virtual ~wxListHeaderWindow();
453 void AdjustDC(wxDC
& dc
);
455 void OnPaint( wxPaintEvent
&event
);
456 void OnMouse( wxMouseEvent
&event
);
457 void OnSetFocus( wxFocusEvent
&event
);
463 // common part of all ctors
466 // generate and process the list event of the given type, return true if
467 // it wasn't vetoed, i.e. if we should proceed
468 bool SendListEvent(wxEventType type
, const wxPoint
& pos
);
470 DECLARE_DYNAMIC_CLASS(wxListHeaderWindow
)
471 DECLARE_EVENT_TABLE()
474 //-----------------------------------------------------------------------------
475 // wxListRenameTimer (internal)
476 //-----------------------------------------------------------------------------
478 class WXDLLEXPORT wxListRenameTimer
: public wxTimer
481 wxListMainWindow
*m_owner
;
484 wxListRenameTimer( wxListMainWindow
*owner
);
488 //-----------------------------------------------------------------------------
489 // wxListTextCtrl (internal)
490 //-----------------------------------------------------------------------------
492 class WXDLLEXPORT wxListTextCtrl
: public wxTextCtrl
495 wxListTextCtrl(wxListMainWindow
*owner
, size_t itemEdit
);
497 void AcceptChangesAndFinish();
500 void OnChar( wxKeyEvent
&event
);
501 void OnKeyUp( wxKeyEvent
&event
);
502 void OnKillFocus( wxFocusEvent
&event
);
504 bool AcceptChanges();
508 wxListMainWindow
*m_owner
;
509 wxString m_startValue
;
512 bool m_aboutToFinish
;
514 DECLARE_EVENT_TABLE()
517 //-----------------------------------------------------------------------------
518 // wxListMainWindow (internal)
519 //-----------------------------------------------------------------------------
521 WX_DECLARE_LIST(wxListHeaderData
, wxListHeaderDataList
);
522 #include "wx/listimpl.cpp"
523 WX_DEFINE_LIST(wxListHeaderDataList
)
525 class wxListMainWindow
: public wxScrolledWindow
529 wxListMainWindow( wxWindow
*parent
,
531 const wxPoint
& pos
= wxDefaultPosition
,
532 const wxSize
& size
= wxDefaultSize
,
534 const wxString
&name
= _T("listctrlmainwindow") );
536 virtual ~wxListMainWindow();
538 wxWindow
*GetMainWindowOfCompositeControl() { return GetParent(); }
540 bool HasFlag(int flag
) const { return m_parent
->HasFlag(flag
); }
542 // return true if this is a virtual list control
543 bool IsVirtual() const { return HasFlag(wxLC_VIRTUAL
); }
545 // return true if the control is in report mode
546 bool InReportView() const { return HasFlag(wxLC_REPORT
); }
548 // return true if we are in single selection mode, false if multi sel
549 bool IsSingleSel() const { return HasFlag(wxLC_SINGLE_SEL
); }
551 // do we have a header window?
552 bool HasHeader() const
553 { return InReportView() && !HasFlag(wxLC_NO_HEADER
); }
555 void HighlightAll( bool on
);
557 // all these functions only do something if the line is currently visible
559 // change the line "selected" state, return true if it really changed
560 bool HighlightLine( size_t line
, bool highlight
= true);
562 // as HighlightLine() but do it for the range of lines: this is incredibly
563 // more efficient for virtual list controls!
565 // NB: unlike HighlightLine() this one does refresh the lines on screen
566 void HighlightLines( size_t lineFrom
, size_t lineTo
, bool on
= true );
568 // toggle the line state and refresh it
569 void ReverseHighlight( size_t line
)
570 { HighlightLine(line
, !IsHighlighted(line
)); RefreshLine(line
); }
572 // return true if the line is highlighted
573 bool IsHighlighted(size_t line
) const;
575 // refresh one or several lines at once
576 void RefreshLine( size_t line
);
577 void RefreshLines( size_t lineFrom
, size_t lineTo
);
579 // refresh all selected items
580 void RefreshSelected();
582 // refresh all lines below the given one: the difference with
583 // RefreshLines() is that the index here might not be a valid one (happens
584 // when the last line is deleted)
585 void RefreshAfter( size_t lineFrom
);
587 // the methods which are forwarded to wxListLineData itself in list/icon
588 // modes but are here because the lines don't store their positions in the
591 // get the bound rect for the entire line
592 wxRect
GetLineRect(size_t line
) const;
594 // get the bound rect of the label
595 wxRect
GetLineLabelRect(size_t line
) const;
597 // get the bound rect of the items icon (only may be called if we do have
599 wxRect
GetLineIconRect(size_t line
) const;
601 // get the rect to be highlighted when the item has focus
602 wxRect
GetLineHighlightRect(size_t line
) const;
604 // get the size of the total line rect
605 wxSize
GetLineSize(size_t line
) const
606 { return GetLineRect(line
).GetSize(); }
608 // return the hit code for the corresponding position (in this line)
609 long HitTestLine(size_t line
, int x
, int y
) const;
611 // bring the selected item into view, scrolling to it if necessary
612 void MoveToItem(size_t item
);
614 // bring the current item into view
615 void MoveToFocus() { MoveToItem(m_current
); }
617 // start editing the label of the given item
618 void EditLabel( long item
);
620 // suspend/resume redrawing the control
624 void OnRenameTimer();
625 bool OnRenameAccept(size_t itemEdit
, const wxString
& value
);
626 void OnRenameCancelled(size_t itemEdit
);
628 void OnMouse( wxMouseEvent
&event
);
630 // called to switch the selection from the current item to newCurrent,
631 void OnArrowChar( size_t newCurrent
, const wxKeyEvent
& event
);
633 void OnChar( wxKeyEvent
&event
);
634 void OnKeyDown( wxKeyEvent
&event
);
635 void OnSetFocus( wxFocusEvent
&event
);
636 void OnKillFocus( wxFocusEvent
&event
);
637 void OnScroll(wxScrollWinEvent
& event
) ;
639 void OnPaint( wxPaintEvent
&event
);
641 void DrawImage( int index
, wxDC
*dc
, int x
, int y
);
642 void GetImageSize( int index
, int &width
, int &height
) const;
643 int GetTextLength( const wxString
&s
) const;
645 void SetImageList( wxImageListType
*imageList
, int which
);
646 void SetItemSpacing( int spacing
, bool isSmall
= false );
647 int GetItemSpacing( bool isSmall
= false );
649 void SetColumn( int col
, wxListItem
&item
);
650 void SetColumnWidth( int col
, int width
);
651 void GetColumn( int col
, wxListItem
&item
) const;
652 int GetColumnWidth( int col
) const;
653 int GetColumnCount() const { return m_columns
.GetCount(); }
655 // returns the sum of the heights of all columns
656 int GetHeaderWidth() const;
658 int GetCountPerPage() const;
660 void SetItem( wxListItem
&item
);
661 void GetItem( wxListItem
&item
) const;
662 void SetItemState( long item
, long state
, long stateMask
);
663 void SetItemStateAll( long state
, long stateMask
);
664 int GetItemState( long item
, long stateMask
) const;
665 void GetItemRect( long index
, wxRect
&rect
) const;
666 wxRect
GetViewRect() const;
667 bool GetItemPosition( long item
, wxPoint
& pos
) const;
668 int GetSelectedItemCount() const;
670 wxString
GetItemText(long item
) const
673 info
.m_mask
= wxLIST_MASK_TEXT
;
674 info
.m_itemId
= item
;
679 void SetItemText(long item
, const wxString
& value
)
682 info
.m_mask
= wxLIST_MASK_TEXT
;
683 info
.m_itemId
= item
;
688 // set the scrollbars and update the positions of the items
689 void RecalculatePositions(bool noRefresh
= false);
691 // refresh the window and the header
694 long GetNextItem( long item
, int geometry
, int state
) const;
695 void DeleteItem( long index
);
696 void DeleteAllItems();
697 void DeleteColumn( int col
);
698 void DeleteEverything();
699 void EnsureVisible( long index
);
700 long FindItem( long start
, const wxString
& str
, bool partial
= false );
701 long FindItem( long start
, wxUIntPtr data
);
702 long FindItem( const wxPoint
& pt
);
703 long HitTest( int x
, int y
, int &flags
);
704 void InsertItem( wxListItem
&item
);
705 void InsertColumn( long col
, wxListItem
&item
);
706 int GetItemWidthWithImage(wxListItem
* item
);
707 void SortItems( wxListCtrlCompare fn
, long data
);
709 size_t GetItemCount() const;
710 bool IsEmpty() const { return GetItemCount() == 0; }
711 void SetItemCount(long count
);
713 // change the current (== focused) item, send a notification event
714 void ChangeCurrent(size_t current
);
715 void ResetCurrent() { ChangeCurrent((size_t)-1); }
716 bool HasCurrent() const { return m_current
!= (size_t)-1; }
718 // send out a wxListEvent
719 void SendNotify( size_t line
,
721 const wxPoint
& point
= wxDefaultPosition
);
723 // override base class virtual to reset m_lineHeight when the font changes
724 virtual bool SetFont(const wxFont
& font
)
726 if ( !wxScrolledWindow::SetFont(font
) )
734 // these are for wxListLineData usage only
736 // get the backpointer to the list ctrl
737 wxGenericListCtrl
*GetListCtrl() const
739 return wxStaticCast(GetParent(), wxGenericListCtrl
);
742 // get the height of all lines (assuming they all do have the same height)
743 wxCoord
GetLineHeight() const;
745 // get the y position of the given line (only for report view)
746 wxCoord
GetLineY(size_t line
) const;
748 // get the brush to use for the item highlighting
749 wxBrush
*GetHighlightBrush() const
751 return m_hasFocus
? m_highlightBrush
: m_highlightUnfocusedBrush
;
755 // the array of all line objects for a non virtual list control (for the
756 // virtual list control we only ever use m_lines[0])
757 wxListLineDataArray m_lines
;
759 // the list of column objects
760 wxListHeaderDataList m_columns
;
762 // currently focused item or -1
765 // the number of lines per page
768 // this flag is set when something which should result in the window
769 // redrawing happens (i.e. an item was added or deleted, or its appearance
770 // changed) and OnPaint() doesn't redraw the window while it is set which
771 // allows to minimize the number of repaintings when a lot of items are
772 // being added. The real repainting occurs only after the next OnIdle()
776 wxColour
*m_highlightColour
;
777 wxImageListType
*m_small_image_list
;
778 wxImageListType
*m_normal_image_list
;
780 int m_normal_spacing
;
784 wxTimer
*m_renameTimer
;
788 ColWidthArray m_aColWidths
;
790 // for double click logic
791 size_t m_lineLastClicked
,
792 m_lineBeforeLastClicked
,
793 m_lineSelectSingleOnUp
;
795 wxListTextCtrl
* m_textctrl
;
798 // the total count of items in a virtual list control
801 // the object maintaining the items selection state, only used in virtual
803 wxSelectionStore m_selStore
;
805 // common part of all ctors
808 // get the line data for the given index
809 wxListLineData
*GetLine(size_t n
) const
811 wxASSERT_MSG( n
!= (size_t)-1, _T("invalid line index") );
815 wxConstCast(this, wxListMainWindow
)->CacheLineData(n
);
823 // get a dummy line which can be used for geometry calculations and such:
824 // you must use GetLine() if you want to really draw the line
825 wxListLineData
*GetDummyLine() const;
827 // cache the line data of the n-th line in m_lines[0]
828 void CacheLineData(size_t line
);
830 // get the range of visible lines
831 void GetVisibleLinesRange(size_t *from
, size_t *to
);
833 // force us to recalculate the range of visible lines
834 void ResetVisibleLinesRange() { m_lineFrom
= (size_t)-1; }
836 // get the colour to be used for drawing the rules
837 wxColour
GetRuleColour() const
839 return wxSystemSettings::GetColour(wxSYS_COLOUR_3DLIGHT
);
843 // initialize the current item if needed
844 void UpdateCurrent();
846 // delete all items but don't refresh: called from dtor
847 void DoDeleteAllItems();
849 // the height of one line using the current font
850 wxCoord m_lineHeight
;
852 // the total header width or 0 if not calculated yet
853 wxCoord m_headerWidth
;
855 // the first and last lines being shown on screen right now (inclusive),
856 // both may be -1 if they must be calculated so never access them directly:
857 // use GetVisibleLinesRange() above instead
861 // the brushes to use for item highlighting when we do/don't have focus
862 wxBrush
*m_highlightBrush
,
863 *m_highlightUnfocusedBrush
;
865 // if this is > 0, the control is frozen and doesn't redraw itself
866 size_t m_freezeCount
;
868 DECLARE_DYNAMIC_CLASS(wxListMainWindow
)
869 DECLARE_EVENT_TABLE()
871 friend class wxGenericListCtrl
;
874 // ============================================================================
876 // ============================================================================
878 //-----------------------------------------------------------------------------
880 //-----------------------------------------------------------------------------
882 wxListItemData::~wxListItemData()
884 // in the virtual list control the attributes are managed by the main
885 // program, so don't delete them
886 if ( !m_owner
->IsVirtual() )
894 void wxListItemData::Init()
902 wxListItemData::wxListItemData(wxListMainWindow
*owner
)
908 if ( owner
->InReportView() )
918 void wxListItemData::SetItem( const wxListItem
&info
)
920 if ( info
.m_mask
& wxLIST_MASK_TEXT
)
921 SetText(info
.m_text
);
922 if ( info
.m_mask
& wxLIST_MASK_IMAGE
)
923 m_image
= info
.m_image
;
924 if ( info
.m_mask
& wxLIST_MASK_DATA
)
925 m_data
= info
.m_data
;
927 if ( info
.HasAttributes() )
930 *m_attr
= *info
.GetAttributes();
932 m_attr
= new wxListItemAttr(*info
.GetAttributes());
940 m_rect
->width
= info
.m_width
;
944 void wxListItemData::SetPosition( int x
, int y
)
946 wxCHECK_RET( m_rect
, _T("unexpected SetPosition() call") );
952 void wxListItemData::SetSize( int width
, int height
)
954 wxCHECK_RET( m_rect
, _T("unexpected SetSize() call") );
957 m_rect
->width
= width
;
959 m_rect
->height
= height
;
962 bool wxListItemData::IsHit( int x
, int y
) const
964 wxCHECK_MSG( m_rect
, false, _T("can't be called in this mode") );
966 return wxRect(GetX(), GetY(), GetWidth(), GetHeight()).Inside(x
, y
);
969 int wxListItemData::GetX() const
971 wxCHECK_MSG( m_rect
, 0, _T("can't be called in this mode") );
976 int wxListItemData::GetY() const
978 wxCHECK_MSG( m_rect
, 0, _T("can't be called in this mode") );
983 int wxListItemData::GetWidth() const
985 wxCHECK_MSG( m_rect
, 0, _T("can't be called in this mode") );
987 return m_rect
->width
;
990 int wxListItemData::GetHeight() const
992 wxCHECK_MSG( m_rect
, 0, _T("can't be called in this mode") );
994 return m_rect
->height
;
997 void wxListItemData::GetItem( wxListItem
&info
) const
999 long mask
= info
.m_mask
;
1002 // by default, get everything for backwards compatibility
1006 if ( mask
& wxLIST_MASK_TEXT
)
1007 info
.m_text
= m_text
;
1008 if ( mask
& wxLIST_MASK_IMAGE
)
1009 info
.m_image
= m_image
;
1010 if ( mask
& wxLIST_MASK_DATA
)
1011 info
.m_data
= m_data
;
1015 if ( m_attr
->HasTextColour() )
1016 info
.SetTextColour(m_attr
->GetTextColour());
1017 if ( m_attr
->HasBackgroundColour() )
1018 info
.SetBackgroundColour(m_attr
->GetBackgroundColour());
1019 if ( m_attr
->HasFont() )
1020 info
.SetFont(m_attr
->GetFont());
1024 //-----------------------------------------------------------------------------
1026 //-----------------------------------------------------------------------------
1028 void wxListHeaderData::Init()
1039 wxListHeaderData::wxListHeaderData()
1044 wxListHeaderData::wxListHeaderData( const wxListItem
&item
)
1051 void wxListHeaderData::SetItem( const wxListItem
&item
)
1053 m_mask
= item
.m_mask
;
1055 if ( m_mask
& wxLIST_MASK_TEXT
)
1056 m_text
= item
.m_text
;
1058 if ( m_mask
& wxLIST_MASK_IMAGE
)
1059 m_image
= item
.m_image
;
1061 if ( m_mask
& wxLIST_MASK_FORMAT
)
1062 m_format
= item
.m_format
;
1064 if ( m_mask
& wxLIST_MASK_WIDTH
)
1065 SetWidth(item
.m_width
);
1068 void wxListHeaderData::SetPosition( int x
, int y
)
1074 void wxListHeaderData::SetHeight( int h
)
1079 void wxListHeaderData::SetWidth( int w
)
1081 m_width
= w
< 0 ? WIDTH_COL_DEFAULT
: w
;
1084 void wxListHeaderData::SetFormat( int format
)
1089 bool wxListHeaderData::HasImage() const
1091 return m_image
!= -1;
1094 bool wxListHeaderData::IsHit( int x
, int y
) const
1096 return ((x
>= m_xpos
) && (x
<= m_xpos
+m_width
) && (y
>= m_ypos
) && (y
<= m_ypos
+m_height
));
1099 void wxListHeaderData::GetItem( wxListItem
& item
)
1101 item
.m_mask
= m_mask
;
1102 item
.m_text
= m_text
;
1103 item
.m_image
= m_image
;
1104 item
.m_format
= m_format
;
1105 item
.m_width
= m_width
;
1108 int wxListHeaderData::GetImage() const
1113 int wxListHeaderData::GetWidth() const
1118 int wxListHeaderData::GetFormat() const
1123 //-----------------------------------------------------------------------------
1125 //-----------------------------------------------------------------------------
1127 inline int wxListLineData::GetMode() const
1129 return m_owner
->GetListCtrl()->GetWindowStyleFlag() & wxLC_MASK_TYPE
;
1132 inline bool wxListLineData::InReportView() const
1134 return m_owner
->HasFlag(wxLC_REPORT
);
1137 inline bool wxListLineData::IsVirtual() const
1139 return m_owner
->IsVirtual();
1142 wxListLineData::wxListLineData( wxListMainWindow
*owner
)
1146 if ( InReportView() )
1152 m_gi
= new GeometryInfo
;
1155 m_highlighted
= false;
1157 InitItems( GetMode() == wxLC_REPORT
? m_owner
->GetColumnCount() : 1 );
1160 void wxListLineData::CalculateSize( wxDC
*dc
, int spacing
)
1162 wxListItemDataList::compatibility_iterator node
= m_items
.GetFirst();
1163 wxCHECK_RET( node
, _T("no subitems at all??") );
1165 wxListItemData
*item
= node
->GetData();
1170 switch ( GetMode() )
1173 case wxLC_SMALL_ICON
:
1174 m_gi
->m_rectAll
.width
= spacing
;
1176 s
= item
->GetText();
1181 m_gi
->m_rectLabel
.width
=
1182 m_gi
->m_rectLabel
.height
= 0;
1186 dc
->GetTextExtent( s
, &lw
, &lh
);
1190 m_gi
->m_rectAll
.height
= spacing
+ lh
;
1192 m_gi
->m_rectAll
.width
= lw
;
1194 m_gi
->m_rectLabel
.width
= lw
;
1195 m_gi
->m_rectLabel
.height
= lh
;
1198 if (item
->HasImage())
1201 m_owner
->GetImageSize( item
->GetImage(), w
, h
);
1202 m_gi
->m_rectIcon
.width
= w
+ 8;
1203 m_gi
->m_rectIcon
.height
= h
+ 8;
1205 if ( m_gi
->m_rectIcon
.width
> m_gi
->m_rectAll
.width
)
1206 m_gi
->m_rectAll
.width
= m_gi
->m_rectIcon
.width
;
1207 if ( m_gi
->m_rectIcon
.height
+ lh
> m_gi
->m_rectAll
.height
- 4 )
1208 m_gi
->m_rectAll
.height
= m_gi
->m_rectIcon
.height
+ lh
+ 4;
1211 if ( item
->HasText() )
1213 m_gi
->m_rectHighlight
.width
= m_gi
->m_rectLabel
.width
;
1214 m_gi
->m_rectHighlight
.height
= m_gi
->m_rectLabel
.height
;
1216 else // no text, highlight the icon
1218 m_gi
->m_rectHighlight
.width
= m_gi
->m_rectIcon
.width
;
1219 m_gi
->m_rectHighlight
.height
= m_gi
->m_rectIcon
.height
;
1224 s
= item
->GetTextForMeasuring();
1226 dc
->GetTextExtent( s
, &lw
, &lh
);
1230 m_gi
->m_rectLabel
.width
= lw
;
1231 m_gi
->m_rectLabel
.height
= lh
;
1233 m_gi
->m_rectAll
.width
= lw
;
1234 m_gi
->m_rectAll
.height
= lh
;
1236 if (item
->HasImage())
1239 m_owner
->GetImageSize( item
->GetImage(), w
, h
);
1240 m_gi
->m_rectIcon
.width
= w
;
1241 m_gi
->m_rectIcon
.height
= h
;
1243 m_gi
->m_rectAll
.width
+= 4 + w
;
1244 if (h
> m_gi
->m_rectAll
.height
)
1245 m_gi
->m_rectAll
.height
= h
;
1248 m_gi
->m_rectHighlight
.width
= m_gi
->m_rectAll
.width
;
1249 m_gi
->m_rectHighlight
.height
= m_gi
->m_rectAll
.height
;
1253 wxFAIL_MSG( _T("unexpected call to SetSize") );
1257 wxFAIL_MSG( _T("unknown mode") );
1261 void wxListLineData::SetPosition( int x
, int y
, int spacing
)
1263 wxListItemDataList::compatibility_iterator node
= m_items
.GetFirst();
1264 wxCHECK_RET( node
, _T("no subitems at all??") );
1266 wxListItemData
*item
= node
->GetData();
1268 switch ( GetMode() )
1271 case wxLC_SMALL_ICON
:
1272 m_gi
->m_rectAll
.x
= x
;
1273 m_gi
->m_rectAll
.y
= y
;
1275 if ( item
->HasImage() )
1277 m_gi
->m_rectIcon
.x
= m_gi
->m_rectAll
.x
+ 4 +
1278 (m_gi
->m_rectAll
.width
- m_gi
->m_rectIcon
.width
) / 2;
1279 m_gi
->m_rectIcon
.y
= m_gi
->m_rectAll
.y
+ 4;
1282 if ( item
->HasText() )
1284 if (m_gi
->m_rectAll
.width
> spacing
)
1285 m_gi
->m_rectLabel
.x
= m_gi
->m_rectAll
.x
+ 2;
1287 m_gi
->m_rectLabel
.x
= m_gi
->m_rectAll
.x
+ 2 + (spacing
/2) - (m_gi
->m_rectLabel
.width
/2);
1288 m_gi
->m_rectLabel
.y
= m_gi
->m_rectAll
.y
+ m_gi
->m_rectAll
.height
+ 2 - m_gi
->m_rectLabel
.height
;
1289 m_gi
->m_rectHighlight
.x
= m_gi
->m_rectLabel
.x
- 2;
1290 m_gi
->m_rectHighlight
.y
= m_gi
->m_rectLabel
.y
- 2;
1292 else // no text, highlight the icon
1294 m_gi
->m_rectHighlight
.x
= m_gi
->m_rectIcon
.x
- 4;
1295 m_gi
->m_rectHighlight
.y
= m_gi
->m_rectIcon
.y
- 4;
1300 m_gi
->m_rectAll
.x
= x
;
1301 m_gi
->m_rectAll
.y
= y
;
1303 m_gi
->m_rectHighlight
.x
= m_gi
->m_rectAll
.x
;
1304 m_gi
->m_rectHighlight
.y
= m_gi
->m_rectAll
.y
;
1305 m_gi
->m_rectLabel
.y
= m_gi
->m_rectAll
.y
+ 2;
1307 if (item
->HasImage())
1309 m_gi
->m_rectIcon
.x
= m_gi
->m_rectAll
.x
+ 2;
1310 m_gi
->m_rectIcon
.y
= m_gi
->m_rectAll
.y
+ 2;
1311 m_gi
->m_rectLabel
.x
= m_gi
->m_rectAll
.x
+ 6 + m_gi
->m_rectIcon
.width
;
1315 m_gi
->m_rectLabel
.x
= m_gi
->m_rectAll
.x
+ 2;
1320 wxFAIL_MSG( _T("unexpected call to SetPosition") );
1324 wxFAIL_MSG( _T("unknown mode") );
1328 void wxListLineData::InitItems( int num
)
1330 for (int i
= 0; i
< num
; i
++)
1331 m_items
.Append( new wxListItemData(m_owner
) );
1334 void wxListLineData::SetItem( int index
, const wxListItem
&info
)
1336 wxListItemDataList::compatibility_iterator node
= m_items
.Item( index
);
1337 wxCHECK_RET( node
, _T("invalid column index in SetItem") );
1339 wxListItemData
*item
= node
->GetData();
1340 item
->SetItem( info
);
1343 void wxListLineData::GetItem( int index
, wxListItem
&info
)
1345 wxListItemDataList::compatibility_iterator node
= m_items
.Item( index
);
1348 wxListItemData
*item
= node
->GetData();
1349 item
->GetItem( info
);
1353 wxString
wxListLineData::GetText(int index
) const
1357 wxListItemDataList::compatibility_iterator node
= m_items
.Item( index
);
1360 wxListItemData
*item
= node
->GetData();
1361 s
= item
->GetText();
1367 void wxListLineData::SetText( int index
, const wxString
& s
)
1369 wxListItemDataList::compatibility_iterator node
= m_items
.Item( index
);
1372 wxListItemData
*item
= node
->GetData();
1377 void wxListLineData::SetImage( int index
, int image
)
1379 wxListItemDataList::compatibility_iterator node
= m_items
.Item( index
);
1380 wxCHECK_RET( node
, _T("invalid column index in SetImage()") );
1382 wxListItemData
*item
= node
->GetData();
1383 item
->SetImage(image
);
1386 int wxListLineData::GetImage( int index
) const
1388 wxListItemDataList::compatibility_iterator node
= m_items
.Item( index
);
1389 wxCHECK_MSG( node
, -1, _T("invalid column index in GetImage()") );
1391 wxListItemData
*item
= node
->GetData();
1392 return item
->GetImage();
1395 wxListItemAttr
*wxListLineData::GetAttr() const
1397 wxListItemDataList::compatibility_iterator node
= m_items
.GetFirst();
1398 wxCHECK_MSG( node
, NULL
, _T("invalid column index in GetAttr()") );
1400 wxListItemData
*item
= node
->GetData();
1401 return item
->GetAttr();
1404 void wxListLineData::SetAttr(wxListItemAttr
*attr
)
1406 wxListItemDataList::compatibility_iterator node
= m_items
.GetFirst();
1407 wxCHECK_RET( node
, _T("invalid column index in SetAttr()") );
1409 wxListItemData
*item
= node
->GetData();
1410 item
->SetAttr(attr
);
1413 bool wxListLineData::SetAttributes(wxDC
*dc
,
1414 const wxListItemAttr
*attr
,
1417 wxWindow
*listctrl
= m_owner
->GetParent();
1421 // don't use foreground colour for drawing highlighted items - this might
1422 // make them completely invisible (and there is no way to do bit
1423 // arithmetics on wxColour, unfortunately)
1427 colText
= wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHTTEXT
);
1431 if ( attr
&& attr
->HasTextColour() )
1433 colText
= attr
->GetTextColour();
1437 colText
= listctrl
->GetForegroundColour();
1441 dc
->SetTextForeground(colText
);
1445 if ( attr
&& attr
->HasFont() )
1447 font
= attr
->GetFont();
1451 font
= listctrl
->GetFont();
1457 bool hasBgCol
= attr
&& attr
->HasBackgroundColour();
1458 if ( highlighted
|| hasBgCol
)
1462 dc
->SetBrush( *m_owner
->GetHighlightBrush() );
1466 dc
->SetBrush(wxBrush(attr
->GetBackgroundColour(), wxSOLID
));
1469 dc
->SetPen( *wxTRANSPARENT_PEN
);
1477 void wxListLineData::Draw( wxDC
*dc
)
1479 wxListItemDataList::compatibility_iterator node
= m_items
.GetFirst();
1480 wxCHECK_RET( node
, _T("no subitems at all??") );
1482 bool highlighted
= IsHighlighted();
1484 wxListItemAttr
*attr
= GetAttr();
1486 if ( SetAttributes(dc
, attr
, highlighted
) )
1488 dc
->DrawRectangle( m_gi
->m_rectHighlight
);
1491 // just for debugging to better see where the items are
1493 dc
->SetPen(*wxRED_PEN
);
1494 dc
->SetBrush(*wxTRANSPARENT_BRUSH
);
1495 dc
->DrawRectangle( m_gi
->m_rectAll
);
1496 dc
->SetPen(*wxGREEN_PEN
);
1497 dc
->DrawRectangle( m_gi
->m_rectIcon
);
1500 wxListItemData
*item
= node
->GetData();
1501 if (item
->HasImage())
1503 // centre the image inside our rectangle, this looks nicer when items
1504 // ae aligned in a row
1505 const wxRect
& rectIcon
= m_gi
->m_rectIcon
;
1507 m_owner
->DrawImage(item
->GetImage(), dc
, rectIcon
.x
, rectIcon
.y
);
1510 if (item
->HasText())
1512 const wxRect
& rectLabel
= m_gi
->m_rectLabel
;
1514 wxDCClipper
clipper(*dc
, rectLabel
);
1515 dc
->DrawText(item
->GetText(), rectLabel
.x
, rectLabel
.y
);
1519 void wxListLineData::DrawInReportMode( wxDC
*dc
,
1521 const wxRect
& rectHL
,
1524 // TODO: later we should support setting different attributes for
1525 // different columns - to do it, just add "col" argument to
1526 // GetAttr() and move these lines into the loop below
1527 wxListItemAttr
*attr
= GetAttr();
1528 if ( SetAttributes(dc
, attr
, highlighted
) )
1530 dc
->DrawRectangle( rectHL
);
1533 wxCoord x
= rect
.x
+ HEADER_OFFSET_X
,
1534 y
= rect
.y
+ (LINE_SPACING
+ EXTRA_HEIGHT
) / 2;
1537 for ( wxListItemDataList::compatibility_iterator node
= m_items
.GetFirst();
1539 node
= node
->GetNext(), col
++ )
1541 wxListItemData
*item
= node
->GetData();
1543 int width
= m_owner
->GetColumnWidth(col
);
1547 if ( item
->HasImage() )
1550 m_owner
->DrawImage( item
->GetImage(), dc
, xOld
, y
);
1551 m_owner
->GetImageSize( item
->GetImage(), ix
, iy
);
1553 ix
+= IMAGE_MARGIN_IN_REPORT_MODE
;
1559 wxDCClipper
clipper(*dc
, xOld
, y
, width
- 8, rect
.height
);
1561 if ( item
->HasText() )
1563 DrawTextFormatted(dc
, item
->GetText(), col
, xOld
, y
, width
- 8);
1568 void wxListLineData::DrawTextFormatted(wxDC
*dc
,
1569 const wxString
&text
,
1575 wxString drawntext
, ellipsis
;
1576 wxCoord w
, h
, base_w
;
1579 // determine if the string can fit inside the current width
1580 dc
->GetTextExtent(text
, &w
, &h
);
1583 // it can, draw it using the items alignment
1584 m_owner
->GetColumn(col
, item
);
1585 switch ( item
.GetAlign() )
1588 wxFAIL_MSG( _T("unknown list item format") );
1591 case wxLIST_FORMAT_LEFT
:
1595 case wxLIST_FORMAT_RIGHT
:
1599 case wxLIST_FORMAT_CENTER
:
1600 x
+= (width
- w
) / 2;
1604 dc
->DrawText(text
, x
, y
);
1606 else // otherwise, truncate and add an ellipsis if possible
1608 // determine the base width
1609 ellipsis
= wxString(wxT("..."));
1610 dc
->GetTextExtent(ellipsis
, &base_w
, &h
);
1612 // continue until we have enough space or only one character left
1614 size_t len
= text
.Length();
1615 drawntext
= text
.Left(len
);
1618 dc
->GetTextExtent(drawntext
.Last(), &w_c
, &h_c
);
1619 drawntext
.RemoveLast();
1622 if (w
+ base_w
<= width
)
1626 // if still not enough space, remove ellipsis characters
1627 while (ellipsis
.Length() > 0 && w
+ base_w
> width
)
1629 ellipsis
= ellipsis
.Left(ellipsis
.Length() - 1);
1630 dc
->GetTextExtent(ellipsis
, &base_w
, &h
);
1633 // now draw the text
1634 dc
->DrawText(drawntext
, x
, y
);
1635 dc
->DrawText(ellipsis
, x
+ w
, y
);
1639 bool wxListLineData::Highlight( bool on
)
1641 wxCHECK_MSG( !IsVirtual(), false, _T("unexpected call to Highlight") );
1643 if ( on
== m_highlighted
)
1651 void wxListLineData::ReverseHighlight( void )
1653 Highlight(!IsHighlighted());
1656 //-----------------------------------------------------------------------------
1657 // wxListHeaderWindow
1658 //-----------------------------------------------------------------------------
1660 IMPLEMENT_DYNAMIC_CLASS(wxListHeaderWindow
,wxWindow
)
1662 BEGIN_EVENT_TABLE(wxListHeaderWindow
,wxWindow
)
1663 EVT_PAINT (wxListHeaderWindow::OnPaint
)
1664 EVT_MOUSE_EVENTS (wxListHeaderWindow::OnMouse
)
1665 EVT_SET_FOCUS (wxListHeaderWindow::OnSetFocus
)
1668 void wxListHeaderWindow::Init()
1670 m_currentCursor
= (wxCursor
*) NULL
;
1671 m_isDragging
= false;
1675 wxListHeaderWindow::wxListHeaderWindow()
1679 m_owner
= (wxListMainWindow
*) NULL
;
1680 m_resizeCursor
= (wxCursor
*) NULL
;
1683 wxListHeaderWindow::wxListHeaderWindow( wxWindow
*win
,
1685 wxListMainWindow
*owner
,
1689 const wxString
&name
)
1690 : wxWindow( win
, id
, pos
, size
, style
, name
)
1695 m_resizeCursor
= new wxCursor( wxCURSOR_SIZEWE
);
1698 wxVisualAttributes attr
= wxPanel::GetClassDefaultAttributes();
1699 SetOwnForegroundColour( attr
.colFg
);
1700 SetOwnBackgroundColour( attr
.colBg
);
1702 SetOwnFont( attr
.font
);
1704 SetOwnForegroundColour( wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT
));
1705 SetOwnBackgroundColour( wxSystemSettings::GetColour(wxSYS_COLOUR_BTNFACE
));
1707 SetOwnFont( wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT
));
1711 wxListHeaderWindow::~wxListHeaderWindow()
1713 delete m_resizeCursor
;
1716 #ifdef __WXUNIVERSAL__
1717 #include "wx/univ/renderer.h"
1718 #include "wx/univ/theme.h"
1721 // shift the DC origin to match the position of the main window horz
1722 // scrollbar: this allows us to always use logical coords
1723 void wxListHeaderWindow::AdjustDC(wxDC
& dc
)
1726 m_owner
->GetScrollPixelsPerUnit( &xpix
, NULL
);
1729 m_owner
->GetViewStart( &x
, NULL
);
1731 // account for the horz scrollbar offset
1732 dc
.SetDeviceOrigin( -x
* xpix
, 0 );
1735 void wxListHeaderWindow::OnPaint( wxPaintEvent
&WXUNUSED(event
) )
1737 wxPaintDC
dc( this );
1744 dc
.SetFont( GetFont() );
1746 // width and height of the entire header window
1748 GetClientSize( &w
, &h
);
1749 m_owner
->CalcUnscrolledPosition(w
, 0, &w
, NULL
);
1751 dc
.SetBackgroundMode(wxTRANSPARENT
);
1753 dc
.SetTextForeground(GetForegroundColour());
1755 int x
= HEADER_OFFSET_X
;
1757 int numColumns
= m_owner
->GetColumnCount();
1759 for ( int i
= 0; i
< numColumns
&& x
< w
; i
++ )
1761 m_owner
->GetColumn( i
, item
);
1762 int wCol
= item
.m_width
;
1764 // the width of the rect to draw: make it smaller to fit entirely
1765 // inside the column rect
1773 wxRendererNative::Get().DrawHeaderButton
1777 wxRect(x
, HEADER_OFFSET_Y
, cw
, ch
),
1778 m_parent
->IsEnabled() ? 0
1779 : (int)wxCONTROL_DISABLED
1782 // see if we have enough space for the column label
1784 // for this we need the width of the text
1787 dc
.GetTextExtent(item
.GetText(), &wLabel
, &hLabel
);
1788 wLabel
+= 2*EXTRA_WIDTH
;
1790 // and the width of the icon, if any
1791 static const int MARGIN_BETWEEN_TEXT_AND_ICON
= 2;
1792 int ix
= 0, // init them just to suppress the compiler warnings
1794 const int image
= item
.m_image
;
1795 wxImageListType
*imageList
;
1798 imageList
= m_owner
->m_small_image_list
;
1801 imageList
->GetSize(image
, ix
, iy
);
1802 wLabel
+= ix
+ MARGIN_BETWEEN_TEXT_AND_ICON
;
1810 // ignore alignment if there is not enough space anyhow
1812 switch ( wLabel
< cw
? item
.GetAlign() : wxLIST_FORMAT_LEFT
)
1815 wxFAIL_MSG( _T("unknown list item format") );
1818 case wxLIST_FORMAT_LEFT
:
1822 case wxLIST_FORMAT_RIGHT
:
1823 xAligned
= x
+ cw
- wLabel
;
1826 case wxLIST_FORMAT_CENTER
:
1827 xAligned
= x
+ (cw
- wLabel
) / 2;
1832 // if we have an image, draw it on the right of the label
1839 xAligned
+ wLabel
- ix
- MARGIN_BETWEEN_TEXT_AND_ICON
,
1840 HEADER_OFFSET_Y
+ (h
- 4 - iy
)/2,
1841 wxIMAGELIST_DRAW_TRANSPARENT
1844 cw
-= ix
+ MARGIN_BETWEEN_TEXT_AND_ICON
;
1847 // draw the text clipping it so that it doesn't overwrite the column
1849 wxDCClipper
clipper(dc
, x
, HEADER_OFFSET_Y
, cw
, h
- 4 );
1851 dc
.DrawText( item
.GetText(),
1852 xAligned
+ EXTRA_WIDTH
, h
/ 2 - hLabel
/ 2 ); //HEADER_OFFSET_Y + EXTRA_HEIGHT );
1860 void wxListHeaderWindow::DrawCurrent()
1862 int x1
= m_currentX
;
1864 m_owner
->ClientToScreen( &x1
, &y1
);
1866 int x2
= m_currentX
;
1868 m_owner
->GetClientSize( NULL
, &y2
);
1869 m_owner
->ClientToScreen( &x2
, &y2
);
1872 dc
.SetLogicalFunction( wxINVERT
);
1873 dc
.SetPen( wxPen( *wxBLACK
, 2, wxSOLID
) );
1874 dc
.SetBrush( *wxTRANSPARENT_BRUSH
);
1878 dc
.DrawLine( x1
, y1
, x2
, y2
);
1880 dc
.SetLogicalFunction( wxCOPY
);
1882 dc
.SetPen( wxNullPen
);
1883 dc
.SetBrush( wxNullBrush
);
1886 void wxListHeaderWindow::OnMouse( wxMouseEvent
&event
)
1888 // we want to work with logical coords
1890 m_owner
->CalcUnscrolledPosition(event
.GetX(), 0, &x
, NULL
);
1891 int y
= event
.GetY();
1895 SendListEvent(wxEVT_COMMAND_LIST_COL_DRAGGING
, event
.GetPosition());
1897 // we don't draw the line beyond our window, but we allow dragging it
1900 GetClientSize( &w
, NULL
);
1901 m_owner
->CalcUnscrolledPosition(w
, 0, &w
, NULL
);
1904 // erase the line if it was drawn
1905 if ( m_currentX
< w
)
1908 if (event
.ButtonUp())
1911 m_isDragging
= false;
1913 m_owner
->SetColumnWidth( m_column
, m_currentX
- m_minX
);
1914 SendListEvent(wxEVT_COMMAND_LIST_COL_END_DRAG
, event
.GetPosition());
1921 m_currentX
= m_minX
+ 7;
1923 // draw in the new location
1924 if ( m_currentX
< w
)
1928 else // not dragging
1931 bool hit_border
= false;
1933 // end of the current column
1936 // find the column where this event occurred
1938 countCol
= m_owner
->GetColumnCount();
1939 for (col
= 0; col
< countCol
; col
++)
1941 xpos
+= m_owner
->GetColumnWidth( col
);
1944 if ( (abs(x
-xpos
) < 3) && (y
< 22) )
1946 // near the column border
1953 // inside the column
1960 if ( col
== countCol
)
1963 if (event
.LeftDown() || event
.RightUp())
1965 if (hit_border
&& event
.LeftDown())
1967 if ( SendListEvent(wxEVT_COMMAND_LIST_COL_BEGIN_DRAG
,
1968 event
.GetPosition()) )
1970 m_isDragging
= true;
1975 //else: column resizing was vetoed by the user code
1977 else // click on a column
1979 SendListEvent( event
.LeftDown()
1980 ? wxEVT_COMMAND_LIST_COL_CLICK
1981 : wxEVT_COMMAND_LIST_COL_RIGHT_CLICK
,
1982 event
.GetPosition());
1985 else if (event
.Moving())
1990 setCursor
= m_currentCursor
== wxSTANDARD_CURSOR
;
1991 m_currentCursor
= m_resizeCursor
;
1995 setCursor
= m_currentCursor
!= wxSTANDARD_CURSOR
;
1996 m_currentCursor
= wxSTANDARD_CURSOR
;
2000 SetCursor(*m_currentCursor
);
2005 void wxListHeaderWindow::OnSetFocus( wxFocusEvent
&WXUNUSED(event
) )
2007 m_owner
->SetFocus();
2011 bool wxListHeaderWindow::SendListEvent(wxEventType type
, const wxPoint
& pos
)
2013 wxWindow
*parent
= GetParent();
2014 wxListEvent
le( type
, parent
->GetId() );
2015 le
.SetEventObject( parent
);
2016 le
.m_pointDrag
= pos
;
2018 // the position should be relative to the parent window, not
2019 // this one for compatibility with MSW and common sense: the
2020 // user code doesn't know anything at all about this header
2021 // window, so why should it get positions relative to it?
2022 le
.m_pointDrag
.y
-= GetSize().y
;
2024 le
.m_col
= m_column
;
2025 return !parent
->GetEventHandler()->ProcessEvent( le
) || le
.IsAllowed();
2028 //-----------------------------------------------------------------------------
2029 // wxListRenameTimer (internal)
2030 //-----------------------------------------------------------------------------
2032 wxListRenameTimer::wxListRenameTimer( wxListMainWindow
*owner
)
2037 void wxListRenameTimer::Notify()
2039 m_owner
->OnRenameTimer();
2042 //-----------------------------------------------------------------------------
2043 // wxListTextCtrl (internal)
2044 //-----------------------------------------------------------------------------
2046 BEGIN_EVENT_TABLE(wxListTextCtrl
,wxTextCtrl
)
2047 EVT_CHAR (wxListTextCtrl::OnChar
)
2048 EVT_KEY_UP (wxListTextCtrl::OnKeyUp
)
2049 EVT_KILL_FOCUS (wxListTextCtrl::OnKillFocus
)
2052 wxListTextCtrl::wxListTextCtrl(wxListMainWindow
*owner
, size_t itemEdit
)
2053 : m_startValue(owner
->GetItemText(itemEdit
)),
2054 m_itemEdited(itemEdit
)
2058 m_aboutToFinish
= false;
2060 wxRect rectLabel
= owner
->GetLineLabelRect(itemEdit
);
2062 m_owner
->CalcScrolledPosition(rectLabel
.x
, rectLabel
.y
,
2063 &rectLabel
.x
, &rectLabel
.y
);
2065 (void)Create(owner
, wxID_ANY
, m_startValue
,
2066 wxPoint(rectLabel
.x
-4,rectLabel
.y
-4),
2067 wxSize(rectLabel
.width
+11,rectLabel
.height
+8));
2070 void wxListTextCtrl::Finish()
2074 wxPendingDelete
.Append(this);
2075 m_owner
->m_textctrl
= NULL
;
2079 m_owner
->SetFocusIgnoringChildren();
2083 bool wxListTextCtrl::AcceptChanges()
2085 const wxString value
= GetValue();
2087 if ( value
== m_startValue
)
2089 // nothing changed, always accept
2093 if ( !m_owner
->OnRenameAccept(m_itemEdited
, value
) )
2095 // vetoed by the user
2099 // accepted, do rename the item
2100 m_owner
->SetItemText(m_itemEdited
, value
);
2105 void wxListTextCtrl::AcceptChangesAndFinish()
2107 m_aboutToFinish
= true;
2108 // Notify the owner about the changes
2110 // Even if vetoed, close the control (consistent with MSW)
2114 void wxListTextCtrl::OnChar( wxKeyEvent
&event
)
2116 switch ( event
.m_keyCode
)
2119 AcceptChangesAndFinish();
2124 m_owner
->OnRenameCancelled( m_itemEdited
);
2132 void wxListTextCtrl::OnKeyUp( wxKeyEvent
&event
)
2140 // auto-grow the textctrl:
2141 wxSize parentSize
= m_owner
->GetSize();
2142 wxPoint myPos
= GetPosition();
2143 wxSize mySize
= GetSize();
2145 GetTextExtent(GetValue() + _T("MM"), &sx
, &sy
);
2146 if (myPos
.x
+ sx
> parentSize
.x
)
2147 sx
= parentSize
.x
- myPos
.x
;
2150 SetSize(sx
, wxDefaultCoord
);
2155 void wxListTextCtrl::OnKillFocus( wxFocusEvent
&event
)
2157 if ( !m_finished
&& !m_aboutToFinish
)
2159 // We must finish regardless of success, otherwise we'll get
2163 if ( !AcceptChanges() )
2164 m_owner
->OnRenameCancelled( m_itemEdited
);
2167 // We must let the native text control handle focus, too, otherwise
2168 // it could have problems with the cursor (e.g., in wxGTK).
2172 //-----------------------------------------------------------------------------
2174 //-----------------------------------------------------------------------------
2176 IMPLEMENT_DYNAMIC_CLASS(wxListMainWindow
,wxScrolledWindow
)
2178 BEGIN_EVENT_TABLE(wxListMainWindow
,wxScrolledWindow
)
2179 EVT_PAINT (wxListMainWindow::OnPaint
)
2180 EVT_MOUSE_EVENTS (wxListMainWindow::OnMouse
)
2181 EVT_CHAR (wxListMainWindow::OnChar
)
2182 EVT_KEY_DOWN (wxListMainWindow::OnKeyDown
)
2183 EVT_SET_FOCUS (wxListMainWindow::OnSetFocus
)
2184 EVT_KILL_FOCUS (wxListMainWindow::OnKillFocus
)
2185 EVT_SCROLLWIN (wxListMainWindow::OnScroll
)
2188 void wxListMainWindow::Init()
2193 m_lineTo
= (size_t)-1;
2199 m_small_image_list
= (wxImageListType
*) NULL
;
2200 m_normal_image_list
= (wxImageListType
*) NULL
;
2202 m_small_spacing
= 30;
2203 m_normal_spacing
= 40;
2207 m_isCreated
= false;
2209 m_lastOnSame
= false;
2210 m_renameTimer
= new wxListRenameTimer( this );
2215 m_lineSelectSingleOnUp
=
2216 m_lineBeforeLastClicked
= (size_t)-1;
2221 wxListMainWindow::wxListMainWindow()
2226 m_highlightUnfocusedBrush
= (wxBrush
*) NULL
;
2229 wxListMainWindow::wxListMainWindow( wxWindow
*parent
,
2234 const wxString
&name
)
2235 : wxScrolledWindow( parent
, id
, pos
, size
,
2236 style
| wxHSCROLL
| wxVSCROLL
, name
)
2240 m_highlightBrush
= new wxBrush
2242 wxSystemSettings::GetColour
2244 wxSYS_COLOUR_HIGHLIGHT
2249 m_highlightUnfocusedBrush
= new wxBrush
2251 wxSystemSettings::GetColour
2253 wxSYS_COLOUR_BTNSHADOW
2258 SetScrollbars( 0, 0, 0, 0, 0, 0 );
2260 wxVisualAttributes attr
= wxGenericListCtrl::GetClassDefaultAttributes();
2261 SetOwnForegroundColour( attr
.colFg
);
2262 SetOwnBackgroundColour( attr
.colBg
);
2264 SetOwnFont( attr
.font
);
2267 wxListMainWindow::~wxListMainWindow()
2270 WX_CLEAR_LIST(wxListHeaderDataList
, m_columns
);
2271 WX_CLEAR_ARRAY(m_aColWidths
);
2273 delete m_highlightBrush
;
2274 delete m_highlightUnfocusedBrush
;
2276 delete m_renameTimer
;
2279 void wxListMainWindow::CacheLineData(size_t line
)
2281 wxGenericListCtrl
*listctrl
= GetListCtrl();
2283 wxListLineData
*ld
= GetDummyLine();
2285 size_t countCol
= GetColumnCount();
2286 for ( size_t col
= 0; col
< countCol
; col
++ )
2288 ld
->SetText(col
, listctrl
->OnGetItemText(line
, col
));
2291 ld
->SetImage(listctrl
->OnGetItemImage(line
));
2292 ld
->SetAttr(listctrl
->OnGetItemAttr(line
));
2295 wxListLineData
*wxListMainWindow::GetDummyLine() const
2297 wxASSERT_MSG( !IsEmpty(), _T("invalid line index") );
2299 wxASSERT_MSG( IsVirtual(), _T("GetDummyLine() shouldn't be called") );
2301 wxListMainWindow
*self
= wxConstCast(this, wxListMainWindow
);
2303 // we need to recreate the dummy line if the number of columns in the
2304 // control changed as it would have the incorrect number of fields
2306 if ( !m_lines
.IsEmpty() &&
2307 m_lines
[0].m_items
.GetCount() != (size_t)GetColumnCount() )
2309 self
->m_lines
.Clear();
2312 if ( m_lines
.IsEmpty() )
2314 wxListLineData
*line
= new wxListLineData(self
);
2315 self
->m_lines
.Add(line
);
2317 // don't waste extra memory -- there never going to be anything
2318 // else/more in this array
2319 self
->m_lines
.Shrink();
2325 // ----------------------------------------------------------------------------
2326 // line geometry (report mode only)
2327 // ----------------------------------------------------------------------------
2329 wxCoord
wxListMainWindow::GetLineHeight() const
2331 // we cache the line height as calling GetTextExtent() is slow
2332 if ( !m_lineHeight
)
2334 wxListMainWindow
*self
= wxConstCast(this, wxListMainWindow
);
2336 wxClientDC
dc( self
);
2337 dc
.SetFont( GetFont() );
2340 dc
.GetTextExtent(_T("H"), NULL
, &y
);
2342 if ( m_small_image_list
&& m_small_image_list
->GetImageCount() )
2346 m_small_image_list
->GetSize(0, iw
, ih
);
2351 self
->m_lineHeight
= y
+ LINE_SPACING
;
2354 return m_lineHeight
;
2357 wxCoord
wxListMainWindow::GetLineY(size_t line
) const
2359 wxASSERT_MSG( InReportView(), _T("only works in report mode") );
2361 return LINE_SPACING
+ line
*GetLineHeight();
2364 wxRect
wxListMainWindow::GetLineRect(size_t line
) const
2366 if ( !InReportView() )
2367 return GetLine(line
)->m_gi
->m_rectAll
;
2370 rect
.x
= HEADER_OFFSET_X
;
2371 rect
.y
= GetLineY(line
);
2372 rect
.width
= GetHeaderWidth();
2373 rect
.height
= GetLineHeight();
2378 wxRect
wxListMainWindow::GetLineLabelRect(size_t line
) const
2380 if ( !InReportView() )
2381 return GetLine(line
)->m_gi
->m_rectLabel
;
2384 rect
.x
= HEADER_OFFSET_X
;
2385 rect
.y
= GetLineY(line
);
2386 rect
.width
= GetColumnWidth(0);
2387 rect
.height
= GetLineHeight();
2392 wxRect
wxListMainWindow::GetLineIconRect(size_t line
) const
2394 if ( !InReportView() )
2395 return GetLine(line
)->m_gi
->m_rectIcon
;
2397 wxListLineData
*ld
= GetLine(line
);
2398 wxASSERT_MSG( ld
->HasImage(), _T("should have an image") );
2401 rect
.x
= HEADER_OFFSET_X
;
2402 rect
.y
= GetLineY(line
);
2403 GetImageSize(ld
->GetImage(), rect
.width
, rect
.height
);
2408 wxRect
wxListMainWindow::GetLineHighlightRect(size_t line
) const
2410 return InReportView() ? GetLineRect(line
)
2411 : GetLine(line
)->m_gi
->m_rectHighlight
;
2414 long wxListMainWindow::HitTestLine(size_t line
, int x
, int y
) const
2416 wxASSERT_MSG( line
< GetItemCount(), _T("invalid line in HitTestLine") );
2418 wxListLineData
*ld
= GetLine(line
);
2420 if ( ld
->HasImage() && GetLineIconRect(line
).Inside(x
, y
) )
2421 return wxLIST_HITTEST_ONITEMICON
;
2423 // VS: Testing for "ld->HasText() || InReportView()" instead of
2424 // "ld->HasText()" is needed to make empty lines in report view
2426 if ( ld
->HasText() || InReportView() )
2428 wxRect rect
= InReportView() ? GetLineRect(line
)
2429 : GetLineLabelRect(line
);
2431 if ( rect
.Inside(x
, y
) )
2432 return wxLIST_HITTEST_ONITEMLABEL
;
2438 // ----------------------------------------------------------------------------
2439 // highlight (selection) handling
2440 // ----------------------------------------------------------------------------
2442 bool wxListMainWindow::IsHighlighted(size_t line
) const
2446 return m_selStore
.IsSelected(line
);
2450 wxListLineData
*ld
= GetLine(line
);
2451 wxCHECK_MSG( ld
, false, _T("invalid index in IsHighlighted") );
2453 return ld
->IsHighlighted();
2457 void wxListMainWindow::HighlightLines( size_t lineFrom
,
2463 wxArrayInt linesChanged
;
2464 if ( !m_selStore
.SelectRange(lineFrom
, lineTo
, highlight
,
2467 // meny items changed state, refresh everything
2468 RefreshLines(lineFrom
, lineTo
);
2470 else // only a few items changed state, refresh only them
2472 size_t count
= linesChanged
.GetCount();
2473 for ( size_t n
= 0; n
< count
; n
++ )
2475 RefreshLine(linesChanged
[n
]);
2479 else // iterate over all items in non report view
2481 for ( size_t line
= lineFrom
; line
<= lineTo
; line
++ )
2483 if ( HighlightLine(line
, highlight
) )
2491 bool wxListMainWindow::HighlightLine( size_t line
, bool highlight
)
2497 changed
= m_selStore
.SelectItem(line
, highlight
);
2501 wxListLineData
*ld
= GetLine(line
);
2502 wxCHECK_MSG( ld
, false, _T("invalid index in HighlightLine") );
2504 changed
= ld
->Highlight(highlight
);
2509 SendNotify( line
, highlight
? wxEVT_COMMAND_LIST_ITEM_SELECTED
2510 : wxEVT_COMMAND_LIST_ITEM_DESELECTED
);
2516 void wxListMainWindow::RefreshLine( size_t line
)
2518 if ( InReportView() )
2520 size_t visibleFrom
, visibleTo
;
2521 GetVisibleLinesRange(&visibleFrom
, &visibleTo
);
2523 if ( line
< visibleFrom
|| line
> visibleTo
)
2527 wxRect rect
= GetLineRect(line
);
2529 CalcScrolledPosition( rect
.x
, rect
.y
, &rect
.x
, &rect
.y
);
2530 RefreshRect( rect
);
2533 void wxListMainWindow::RefreshLines( size_t lineFrom
, size_t lineTo
)
2535 // we suppose that they are ordered by caller
2536 wxASSERT_MSG( lineFrom
<= lineTo
, _T("indices in disorder") );
2538 wxASSERT_MSG( lineTo
< GetItemCount(), _T("invalid line range") );
2540 if ( InReportView() )
2542 size_t visibleFrom
, visibleTo
;
2543 GetVisibleLinesRange(&visibleFrom
, &visibleTo
);
2545 if ( lineFrom
< visibleFrom
)
2546 lineFrom
= visibleFrom
;
2547 if ( lineTo
> visibleTo
)
2552 rect
.y
= GetLineY(lineFrom
);
2553 rect
.width
= GetClientSize().x
;
2554 rect
.height
= GetLineY(lineTo
) - rect
.y
+ GetLineHeight();
2556 CalcScrolledPosition( rect
.x
, rect
.y
, &rect
.x
, &rect
.y
);
2557 RefreshRect( rect
);
2561 // TODO: this should be optimized...
2562 for ( size_t line
= lineFrom
; line
<= lineTo
; line
++ )
2569 void wxListMainWindow::RefreshAfter( size_t lineFrom
)
2571 if ( InReportView() )
2573 size_t visibleFrom
, visibleTo
;
2574 GetVisibleLinesRange(&visibleFrom
, &visibleTo
);
2576 if ( lineFrom
< visibleFrom
)
2577 lineFrom
= visibleFrom
;
2578 else if ( lineFrom
> visibleTo
)
2583 rect
.y
= GetLineY(lineFrom
);
2584 CalcScrolledPosition( rect
.x
, rect
.y
, &rect
.x
, &rect
.y
);
2586 wxSize size
= GetClientSize();
2587 rect
.width
= size
.x
;
2588 // refresh till the bottom of the window
2589 rect
.height
= size
.y
- rect
.y
;
2591 RefreshRect( rect
);
2595 // TODO: how to do it more efficiently?
2600 void wxListMainWindow::RefreshSelected()
2606 if ( InReportView() )
2608 GetVisibleLinesRange(&from
, &to
);
2613 to
= GetItemCount() - 1;
2616 if ( HasCurrent() && m_current
>= from
&& m_current
<= to
)
2618 RefreshLine(m_current
);
2621 for ( size_t line
= from
; line
<= to
; line
++ )
2623 // NB: the test works as expected even if m_current == -1
2624 if ( line
!= m_current
&& IsHighlighted(line
) )
2631 void wxListMainWindow::Freeze()
2636 void wxListMainWindow::Thaw()
2638 wxCHECK_RET( m_freezeCount
> 0, _T("thawing unfrozen list control?") );
2640 if ( !--m_freezeCount
)
2646 void wxListMainWindow::OnPaint( wxPaintEvent
&WXUNUSED(event
) )
2648 // Note: a wxPaintDC must be constructed even if no drawing is
2649 // done (a Windows requirement).
2650 wxPaintDC
dc( this );
2652 if ( IsEmpty() || m_freezeCount
)
2654 // nothing to draw or not the moment to draw it
2660 // delay the repainting until we calculate all the items positions
2667 CalcScrolledPosition( 0, 0, &dev_x
, &dev_y
);
2671 dc
.SetFont( GetFont() );
2673 if ( InReportView() )
2675 int lineHeight
= GetLineHeight();
2677 size_t visibleFrom
, visibleTo
;
2678 GetVisibleLinesRange(&visibleFrom
, &visibleTo
);
2681 wxCoord xOrig
, yOrig
;
2682 CalcUnscrolledPosition(0, 0, &xOrig
, &yOrig
);
2684 // tell the caller cache to cache the data
2687 wxListEvent
evCache(wxEVT_COMMAND_LIST_CACHE_HINT
,
2688 GetParent()->GetId());
2689 evCache
.SetEventObject( GetParent() );
2690 evCache
.m_oldItemIndex
= visibleFrom
;
2691 evCache
.m_itemIndex
= visibleTo
;
2692 GetParent()->GetEventHandler()->ProcessEvent( evCache
);
2695 for ( size_t line
= visibleFrom
; line
<= visibleTo
; line
++ )
2697 rectLine
= GetLineRect(line
);
2699 if ( !IsExposed(rectLine
.x
- xOrig
, rectLine
.y
- yOrig
,
2700 rectLine
.width
, rectLine
.height
) )
2702 // don't redraw unaffected lines to avoid flicker
2706 GetLine(line
)->DrawInReportMode( &dc
,
2708 GetLineHighlightRect(line
),
2709 IsHighlighted(line
) );
2712 if ( HasFlag(wxLC_HRULES
) )
2714 wxPen
pen(GetRuleColour(), 1, wxSOLID
);
2715 wxSize clientSize
= GetClientSize();
2717 // Don't draw the first one
2718 for ( size_t i
= visibleFrom
+1; i
<= visibleTo
; i
++ )
2721 dc
.SetBrush( *wxTRANSPARENT_BRUSH
);
2722 dc
.DrawLine(0 - dev_x
, i
*lineHeight
,
2723 clientSize
.x
- dev_x
, i
*lineHeight
);
2726 // Draw last horizontal rule
2727 if ( visibleTo
== GetItemCount() - 1 )
2730 dc
.SetBrush( *wxTRANSPARENT_BRUSH
);
2731 dc
.DrawLine(0 - dev_x
, (m_lineTo
+1)*lineHeight
,
2732 clientSize
.x
- dev_x
, (m_lineTo
+1)*lineHeight
);
2736 // Draw vertical rules if required
2737 if ( HasFlag(wxLC_VRULES
) && !IsEmpty() )
2739 wxPen
pen(GetRuleColour(), 1, wxSOLID
);
2741 wxRect firstItemRect
;
2742 wxRect lastItemRect
;
2743 GetItemRect(visibleFrom
, firstItemRect
);
2744 GetItemRect(visibleTo
, lastItemRect
);
2745 int x
= firstItemRect
.GetX();
2747 dc
.SetBrush(* wxTRANSPARENT_BRUSH
);
2748 for (int col
= 0; col
< GetColumnCount(); col
++)
2750 int colWidth
= GetColumnWidth(col
);
2752 dc
.DrawLine(x
- dev_x
- 2, firstItemRect
.GetY() - 1 - dev_y
,
2753 x
- dev_x
- 2, lastItemRect
.GetBottom() + 1 - dev_y
);
2759 size_t count
= GetItemCount();
2760 for ( size_t i
= 0; i
< count
; i
++ )
2762 GetLine(i
)->Draw( &dc
);
2767 // Don't draw rect outline under Mac at all.
2772 dc
.SetPen( *wxBLACK_PEN
);
2773 dc
.SetBrush( *wxTRANSPARENT_BRUSH
);
2774 dc
.DrawRectangle( GetLineHighlightRect(m_current
) );
2782 void wxListMainWindow::HighlightAll( bool on
)
2784 if ( IsSingleSel() )
2786 wxASSERT_MSG( !on
, _T("can't do this in a single sel control") );
2788 // we just have one item to turn off
2789 if ( HasCurrent() && IsHighlighted(m_current
) )
2791 HighlightLine(m_current
, false);
2792 RefreshLine(m_current
);
2797 HighlightLines(0, GetItemCount() - 1, on
);
2801 void wxListMainWindow::SendNotify( size_t line
,
2802 wxEventType command
,
2803 const wxPoint
& point
)
2805 wxListEvent
le( command
, GetParent()->GetId() );
2806 le
.SetEventObject( GetParent() );
2807 le
.m_itemIndex
= line
;
2809 // set only for events which have position
2810 if ( point
!= wxDefaultPosition
)
2811 le
.m_pointDrag
= point
;
2813 // don't try to get the line info for virtual list controls: the main
2814 // program has it anyhow and if we did it would result in accessing all
2815 // the lines, even those which are not visible now and this is precisely
2816 // what we're trying to avoid
2817 if ( !IsVirtual() && (command
!= wxEVT_COMMAND_LIST_DELETE_ITEM
) )
2819 if ( line
!= (size_t)-1 )
2821 GetLine(line
)->GetItem( 0, le
.m_item
);
2823 //else: this happens for wxEVT_COMMAND_LIST_ITEM_FOCUSED event
2825 //else: there may be no more such item
2827 GetParent()->GetEventHandler()->ProcessEvent( le
);
2830 void wxListMainWindow::ChangeCurrent(size_t current
)
2832 m_current
= current
;
2834 SendNotify(current
, wxEVT_COMMAND_LIST_ITEM_FOCUSED
);
2837 void wxListMainWindow::EditLabel( long item
)
2839 wxCHECK_RET( (item
>= 0) && ((size_t)item
< GetItemCount()),
2840 wxT("wrong index in wxGenericListCtrl::EditLabel()") );
2842 size_t itemEdit
= (size_t)item
;
2844 wxListEvent
le( wxEVT_COMMAND_LIST_BEGIN_LABEL_EDIT
, GetParent()->GetId() );
2845 le
.SetEventObject( GetParent() );
2846 le
.m_itemIndex
= item
;
2847 wxListLineData
*data
= GetLine(itemEdit
);
2848 wxCHECK_RET( data
, _T("invalid index in EditLabel()") );
2849 data
->GetItem( 0, le
.m_item
);
2850 if ( GetParent()->GetEventHandler()->ProcessEvent( le
) && !le
.IsAllowed() )
2852 // vetoed by user code
2856 // We have to call this here because the label in question might just have
2857 // been added and no screen update taken place.
2861 m_textctrl
= new wxListTextCtrl(this, itemEdit
);
2862 m_textctrl
->SetFocus();
2865 void wxListMainWindow::OnRenameTimer()
2867 wxCHECK_RET( HasCurrent(), wxT("unexpected rename timer") );
2869 EditLabel( m_current
);
2872 bool wxListMainWindow::OnRenameAccept(size_t itemEdit
, const wxString
& value
)
2874 wxListEvent
le( wxEVT_COMMAND_LIST_END_LABEL_EDIT
, GetParent()->GetId() );
2875 le
.SetEventObject( GetParent() );
2876 le
.m_itemIndex
= itemEdit
;
2878 wxListLineData
*data
= GetLine(itemEdit
);
2879 wxCHECK_MSG( data
, false, _T("invalid index in OnRenameAccept()") );
2881 data
->GetItem( 0, le
.m_item
);
2882 le
.m_item
.m_text
= value
;
2883 return !GetParent()->GetEventHandler()->ProcessEvent( le
) ||
2887 void wxListMainWindow::OnRenameCancelled(size_t itemEdit
)
2889 // let owner know that the edit was cancelled
2890 wxListEvent
le( wxEVT_COMMAND_LIST_END_LABEL_EDIT
, GetParent()->GetId() );
2892 le
.SetEditCanceled(true);
2894 le
.SetEventObject( GetParent() );
2895 le
.m_itemIndex
= itemEdit
;
2897 wxListLineData
*data
= GetLine(itemEdit
);
2898 wxCHECK_RET( data
, _T("invalid index in OnRenameCancelled()") );
2900 data
->GetItem( 0, le
.m_item
);
2902 GetEventHandler()->ProcessEvent( le
);
2905 void wxListMainWindow::OnMouse( wxMouseEvent
&event
)
2908 // On wxMac we can't depend on the EVT_KILL_FOCUS event to properly
2909 // shutdown the edit control when the mouse is clicked elsewhere on the
2910 // listctrl because the order of events is different (or something like
2911 // that,) so explicitly end the edit if it is active.
2912 if ( event
.LeftDown() && m_textctrl
)
2914 m_textctrl
->AcceptChangesAndFinish();
2918 event
.SetEventObject( GetParent() );
2919 if ( GetParent()->GetEventHandler()->ProcessEvent( event
) )
2922 if (event
.GetEventType() == wxEVT_MOUSEWHEEL
)
2924 // let the base handle mouse wheel events.
2929 if ( !HasCurrent() || IsEmpty() )
2935 if ( !(event
.Dragging() || event
.ButtonDown() || event
.LeftUp() ||
2936 event
.ButtonDClick()) )
2939 int x
= event
.GetX();
2940 int y
= event
.GetY();
2941 CalcUnscrolledPosition( x
, y
, &x
, &y
);
2943 // where did we hit it (if we did)?
2946 size_t count
= GetItemCount(),
2949 if ( InReportView() )
2951 current
= y
/ GetLineHeight();
2952 if ( current
< count
)
2953 hitResult
= HitTestLine(current
, x
, y
);
2957 // TODO: optimize it too! this is less simple than for report view but
2958 // enumerating all items is still not a way to do it!!
2959 for ( current
= 0; current
< count
; current
++ )
2961 hitResult
= HitTestLine(current
, x
, y
);
2967 if (event
.Dragging())
2969 if (m_dragCount
== 0)
2971 // we have to report the raw, physical coords as we want to be
2972 // able to call HitTest(event.m_pointDrag) from the user code to
2973 // get the item being dragged
2974 m_dragStart
= event
.GetPosition();
2979 if (m_dragCount
!= 3)
2982 int command
= event
.RightIsDown() ? wxEVT_COMMAND_LIST_BEGIN_RDRAG
2983 : wxEVT_COMMAND_LIST_BEGIN_DRAG
;
2985 wxListEvent
le( command
, GetParent()->GetId() );
2986 le
.SetEventObject( GetParent() );
2987 le
.m_itemIndex
= m_lineLastClicked
;
2988 le
.m_pointDrag
= m_dragStart
;
2989 GetParent()->GetEventHandler()->ProcessEvent( le
);
3000 // outside of any item
3004 bool forceClick
= false;
3005 if (event
.ButtonDClick())
3007 m_renameTimer
->Stop();
3008 m_lastOnSame
= false;
3010 if ( current
== m_lineLastClicked
)
3012 SendNotify( current
, wxEVT_COMMAND_LIST_ITEM_ACTIVATED
);
3018 // The first click was on another item, so don't interpret this as
3019 // a double click, but as a simple click instead
3026 if(m_lineSelectSingleOnUp
!= (size_t) -1)
3028 // select single line
3029 HighlightAll( false );
3030 ReverseHighlight(m_lineSelectSingleOnUp
);
3034 if ((current
== m_current
) &&
3035 (hitResult
== wxLIST_HITTEST_ONITEMLABEL
) &&
3036 HasFlag(wxLC_EDIT_LABELS
) )
3038 m_renameTimer
->Start( 100, true );
3041 m_lastOnSame
= false;
3042 m_lineSelectSingleOnUp
= (size_t) -1;
3046 // This is necessary, because after a DnD operation in
3047 // from and to ourself, the up event is swallowed by the
3048 // DnD code. So on next non-up event (which means here and
3049 // now) m_lineSelectSingleOnUp should be reset.
3050 m_lineSelectSingleOnUp
= (size_t) -1;
3052 if (event
.RightDown())
3054 m_lineBeforeLastClicked
= m_lineLastClicked
;
3055 m_lineLastClicked
= current
;
3056 // If the item is already selected, do not update the selection.
3057 // Multi-selections should not be cleared if a selected item is clicked.
3058 if (!IsHighlighted(current
))
3060 HighlightAll(false);
3061 ChangeCurrent(current
);
3062 ReverseHighlight(m_current
);
3064 SendNotify( current
, wxEVT_COMMAND_LIST_ITEM_RIGHT_CLICK
,
3065 event
.GetPosition() );
3066 // Allow generation of context menu event
3069 else if (event
.MiddleDown())
3071 SendNotify( current
, wxEVT_COMMAND_LIST_ITEM_MIDDLE_CLICK
);
3073 else if ( event
.LeftDown() || forceClick
)
3075 m_lineBeforeLastClicked
= m_lineLastClicked
;
3076 m_lineLastClicked
= current
;
3078 size_t oldCurrent
= m_current
;
3079 bool oldWasSelected
= IsHighlighted(m_current
);
3081 bool cmdModifierDown
= event
.CmdDown();
3082 if ( IsSingleSel() || !(cmdModifierDown
|| event
.ShiftDown()) )
3084 if( IsSingleSel() || !IsHighlighted(current
) )
3086 HighlightAll( false );
3088 ChangeCurrent(current
);
3090 ReverseHighlight(m_current
);
3092 else // multi sel & current is highlighted & no mod keys
3094 m_lineSelectSingleOnUp
= current
;
3095 ChangeCurrent(current
); // change focus
3098 else // multi sel & either ctrl or shift is down
3100 if (cmdModifierDown
)
3102 ChangeCurrent(current
);
3104 ReverseHighlight(m_current
);
3106 else if (event
.ShiftDown())
3108 ChangeCurrent(current
);
3110 size_t lineFrom
= oldCurrent
,
3113 if ( lineTo
< lineFrom
)
3116 lineFrom
= m_current
;
3119 HighlightLines(lineFrom
, lineTo
);
3121 else // !ctrl, !shift
3123 // test in the enclosing if should make it impossible
3124 wxFAIL_MSG( _T("how did we get here?") );
3128 if (m_current
!= oldCurrent
)
3130 RefreshLine( oldCurrent
);
3133 // forceClick is only set if the previous click was on another item
3134 m_lastOnSame
= !forceClick
&& (m_current
== oldCurrent
) && oldWasSelected
;
3138 void wxListMainWindow::MoveToItem(size_t item
)
3140 if ( item
== (size_t)-1 )
3143 wxRect rect
= GetLineRect(item
);
3145 int client_w
, client_h
;
3146 GetClientSize( &client_w
, &client_h
);
3148 const int hLine
= GetLineHeight();
3150 int view_x
= SCROLL_UNIT_X
*GetScrollPos( wxHORIZONTAL
);
3151 int view_y
= hLine
*GetScrollPos( wxVERTICAL
);
3153 if ( InReportView() )
3155 // the next we need the range of lines shown it might be different, so
3157 ResetVisibleLinesRange();
3159 if (rect
.y
< view_y
)
3160 Scroll( -1, rect
.y
/hLine
);
3161 if (rect
.y
+rect
.height
+5 > view_y
+client_h
)
3162 Scroll( -1, (rect
.y
+rect
.height
-client_h
+hLine
)/hLine
);
3166 if (rect
.x
-view_x
< 5)
3167 Scroll( (rect
.x
-5)/SCROLL_UNIT_X
, -1 );
3168 if (rect
.x
+rect
.width
-5 > view_x
+client_w
)
3169 Scroll( (rect
.x
+rect
.width
-client_w
+SCROLL_UNIT_X
)/SCROLL_UNIT_X
, -1 );
3173 // ----------------------------------------------------------------------------
3174 // keyboard handling
3175 // ----------------------------------------------------------------------------
3177 void wxListMainWindow::OnArrowChar(size_t newCurrent
, const wxKeyEvent
& event
)
3179 wxCHECK_RET( newCurrent
< (size_t)GetItemCount(),
3180 _T("invalid item index in OnArrowChar()") );
3182 size_t oldCurrent
= m_current
;
3184 // in single selection we just ignore Shift as we can't select several
3186 if ( event
.ShiftDown() && !IsSingleSel() )
3188 ChangeCurrent(newCurrent
);
3190 // refresh the old focus to remove it
3191 RefreshLine( oldCurrent
);
3193 // select all the items between the old and the new one
3194 if ( oldCurrent
> newCurrent
)
3196 newCurrent
= oldCurrent
;
3197 oldCurrent
= m_current
;
3200 HighlightLines(oldCurrent
, newCurrent
);
3204 // all previously selected items are unselected unless ctrl is held
3205 if ( !event
.ControlDown() )
3206 HighlightAll(false);
3208 ChangeCurrent(newCurrent
);
3210 // refresh the old focus to remove it
3211 RefreshLine( oldCurrent
);
3213 if ( !event
.ControlDown() )
3215 HighlightLine( m_current
, true );
3219 RefreshLine( m_current
);
3224 void wxListMainWindow::OnKeyDown( wxKeyEvent
&event
)
3226 wxWindow
*parent
= GetParent();
3228 /* we propagate the key event up */
3229 wxKeyEvent
ke( wxEVT_KEY_DOWN
);
3230 ke
.m_shiftDown
= event
.m_shiftDown
;
3231 ke
.m_controlDown
= event
.m_controlDown
;
3232 ke
.m_altDown
= event
.m_altDown
;
3233 ke
.m_metaDown
= event
.m_metaDown
;
3234 ke
.m_keyCode
= event
.m_keyCode
;
3237 ke
.SetEventObject( parent
);
3238 if (parent
->GetEventHandler()->ProcessEvent( ke
)) return;
3243 void wxListMainWindow::OnChar( wxKeyEvent
&event
)
3245 wxWindow
*parent
= GetParent();
3247 /* we send a list_key event up */
3250 wxListEvent
le( wxEVT_COMMAND_LIST_KEY_DOWN
, GetParent()->GetId() );
3251 le
.m_itemIndex
= m_current
;
3252 GetLine(m_current
)->GetItem( 0, le
.m_item
);
3253 le
.m_code
= event
.GetKeyCode();
3254 le
.SetEventObject( parent
);
3255 parent
->GetEventHandler()->ProcessEvent( le
);
3258 /* we propagate the char event up */
3259 wxKeyEvent
ke( wxEVT_CHAR
);
3260 ke
.m_shiftDown
= event
.m_shiftDown
;
3261 ke
.m_controlDown
= event
.m_controlDown
;
3262 ke
.m_altDown
= event
.m_altDown
;
3263 ke
.m_metaDown
= event
.m_metaDown
;
3264 ke
.m_keyCode
= event
.m_keyCode
;
3267 ke
.SetEventObject( parent
);
3268 if (parent
->GetEventHandler()->ProcessEvent( ke
)) return;
3270 if (event
.GetKeyCode() == WXK_TAB
)
3272 wxNavigationKeyEvent nevent
;
3273 nevent
.SetWindowChange( event
.ControlDown() );
3274 nevent
.SetDirection( !event
.ShiftDown() );
3275 nevent
.SetEventObject( GetParent()->GetParent() );
3276 nevent
.SetCurrentFocus( m_parent
);
3277 if (GetParent()->GetParent()->GetEventHandler()->ProcessEvent( nevent
))
3281 /* no item -> nothing to do */
3288 switch (event
.GetKeyCode())
3291 if ( m_current
> 0 )
3292 OnArrowChar( m_current
- 1, event
);
3296 if ( m_current
< (size_t)GetItemCount() - 1 )
3297 OnArrowChar( m_current
+ 1, event
);
3302 OnArrowChar( GetItemCount() - 1, event
);
3307 OnArrowChar( 0, event
);
3312 int steps
= InReportView() ? m_linesPerPage
- 1 : m_current
% m_linesPerPage
;
3314 int index
= m_current
- steps
;
3318 OnArrowChar( index
, event
);
3324 int steps
= InReportView()
3325 ? m_linesPerPage
- 1
3326 : m_linesPerPage
- (m_current
% m_linesPerPage
) - 1;
3328 size_t index
= m_current
+ steps
;
3329 size_t count
= GetItemCount();
3330 if ( index
>= count
)
3333 OnArrowChar( index
, event
);
3338 if ( !InReportView() )
3340 int index
= m_current
- m_linesPerPage
;
3344 OnArrowChar( index
, event
);
3349 if ( !InReportView() )
3351 size_t index
= m_current
+ m_linesPerPage
;
3353 size_t count
= GetItemCount();
3354 if ( index
>= count
)
3357 OnArrowChar( index
, event
);
3362 if ( IsSingleSel() )
3364 SendNotify( m_current
, wxEVT_COMMAND_LIST_ITEM_ACTIVATED
);
3366 if ( IsHighlighted(m_current
) )
3368 // don't unselect the item in single selection mode
3371 //else: select it in ReverseHighlight() below if unselected
3374 ReverseHighlight(m_current
);
3379 SendNotify( m_current
, wxEVT_COMMAND_LIST_ITEM_ACTIVATED
);
3387 // ----------------------------------------------------------------------------
3389 // ----------------------------------------------------------------------------
3391 void wxListMainWindow::OnSetFocus( wxFocusEvent
&WXUNUSED(event
) )
3395 wxFocusEvent
event( wxEVT_SET_FOCUS
, GetParent()->GetId() );
3396 event
.SetEventObject( GetParent() );
3397 if ( GetParent()->GetEventHandler()->ProcessEvent( event
) )
3401 // wxGTK sends us EVT_SET_FOCUS events even if we had never got
3402 // EVT_KILL_FOCUS before which means that we finish by redrawing the items
3403 // which are already drawn correctly resulting in horrible flicker - avoid
3413 void wxListMainWindow::OnKillFocus( wxFocusEvent
&WXUNUSED(event
) )
3417 wxFocusEvent
event( wxEVT_KILL_FOCUS
, GetParent()->GetId() );
3418 event
.SetEventObject( GetParent() );
3419 if ( GetParent()->GetEventHandler()->ProcessEvent( event
) )
3426 void wxListMainWindow::DrawImage( int index
, wxDC
*dc
, int x
, int y
)
3428 if ( HasFlag(wxLC_ICON
) && (m_normal_image_list
))
3430 m_normal_image_list
->Draw( index
, *dc
, x
, y
, wxIMAGELIST_DRAW_TRANSPARENT
);
3432 else if ( HasFlag(wxLC_SMALL_ICON
) && (m_small_image_list
))
3434 m_small_image_list
->Draw( index
, *dc
, x
, y
, wxIMAGELIST_DRAW_TRANSPARENT
);
3436 else if ( HasFlag(wxLC_LIST
) && (m_small_image_list
))
3438 m_small_image_list
->Draw( index
, *dc
, x
, y
, wxIMAGELIST_DRAW_TRANSPARENT
);
3440 else if ( InReportView() && (m_small_image_list
))
3442 m_small_image_list
->Draw( index
, *dc
, x
, y
, wxIMAGELIST_DRAW_TRANSPARENT
);
3446 void wxListMainWindow::GetImageSize( int index
, int &width
, int &height
) const
3448 if ( HasFlag(wxLC_ICON
) && m_normal_image_list
)
3450 m_normal_image_list
->GetSize( index
, width
, height
);
3452 else if ( HasFlag(wxLC_SMALL_ICON
) && m_small_image_list
)
3454 m_small_image_list
->GetSize( index
, width
, height
);
3456 else if ( HasFlag(wxLC_LIST
) && m_small_image_list
)
3458 m_small_image_list
->GetSize( index
, width
, height
);
3460 else if ( InReportView() && m_small_image_list
)
3462 m_small_image_list
->GetSize( index
, width
, height
);
3471 int wxListMainWindow::GetTextLength( const wxString
&s
) const
3473 wxClientDC
dc( wxConstCast(this, wxListMainWindow
) );
3474 dc
.SetFont( GetFont() );
3477 dc
.GetTextExtent( s
, &lw
, NULL
);
3479 return lw
+ AUTOSIZE_COL_MARGIN
;
3482 void wxListMainWindow::SetImageList( wxImageListType
*imageList
, int which
)
3486 // calc the spacing from the icon size
3489 if ((imageList
) && (imageList
->GetImageCount()) )
3491 imageList
->GetSize(0, width
, height
);
3494 if (which
== wxIMAGE_LIST_NORMAL
)
3496 m_normal_image_list
= imageList
;
3497 m_normal_spacing
= width
+ 8;
3500 if (which
== wxIMAGE_LIST_SMALL
)
3502 m_small_image_list
= imageList
;
3503 m_small_spacing
= width
+ 14;
3504 m_lineHeight
= 0; // ensure that the line height will be recalc'd
3508 void wxListMainWindow::SetItemSpacing( int spacing
, bool isSmall
)
3513 m_small_spacing
= spacing
;
3517 m_normal_spacing
= spacing
;
3521 int wxListMainWindow::GetItemSpacing( bool isSmall
)
3523 return isSmall
? m_small_spacing
: m_normal_spacing
;
3526 // ----------------------------------------------------------------------------
3528 // ----------------------------------------------------------------------------
3530 void wxListMainWindow::SetColumn( int col
, wxListItem
&item
)
3532 wxListHeaderDataList::compatibility_iterator node
= m_columns
.Item( col
);
3534 wxCHECK_RET( node
, _T("invalid column index in SetColumn") );
3536 if ( item
.m_width
== wxLIST_AUTOSIZE_USEHEADER
)
3537 item
.m_width
= GetTextLength( item
.m_text
);
3539 wxListHeaderData
*column
= node
->GetData();
3540 column
->SetItem( item
);
3542 wxListHeaderWindow
*headerWin
= GetListCtrl()->m_headerWin
;
3544 headerWin
->m_dirty
= true;
3548 // invalidate it as it has to be recalculated
3552 void wxListMainWindow::SetColumnWidth( int col
, int width
)
3554 wxCHECK_RET( col
>= 0 && col
< GetColumnCount(),
3555 _T("invalid column index") );
3557 wxCHECK_RET( InReportView(),
3558 _T("SetColumnWidth() can only be called in report mode.") );
3561 wxListHeaderWindow
*headerWin
= GetListCtrl()->m_headerWin
;
3563 headerWin
->m_dirty
= true;
3565 wxListHeaderDataList::compatibility_iterator node
= m_columns
.Item( col
);
3566 wxCHECK_RET( node
, _T("no column?") );
3568 wxListHeaderData
*column
= node
->GetData();
3570 size_t count
= GetItemCount();
3572 if (width
== wxLIST_AUTOSIZE_USEHEADER
)
3574 width
= GetTextLength(column
->GetText());
3576 else if ( width
== wxLIST_AUTOSIZE
)
3580 // TODO: determine the max width somehow...
3581 width
= WIDTH_COL_DEFAULT
;
3585 wxClientDC
dc(this);
3586 dc
.SetFont( GetFont() );
3588 int max
= AUTOSIZE_COL_MARGIN
;
3590 // if the cached column width isn't valid then recalculate it
3591 if (m_aColWidths
.Item(col
)->bNeedsUpdate
)
3593 for (size_t i
= 0; i
< count
; i
++)
3595 wxListLineData
*line
= GetLine(i
);
3596 wxListItemDataList::compatibility_iterator n
= line
->m_items
.Item( col
);
3598 wxCHECK_RET( n
, _T("no subitem?") );
3600 wxListItemData
*itemData
= n
->GetData();
3603 itemData
->GetItem(item
);
3604 int itemWidth
= GetItemWidthWithImage(&item
);
3605 if (itemWidth
> max
)
3609 m_aColWidths
.Item(col
)->bNeedsUpdate
= false;
3610 m_aColWidths
.Item(col
)->nMaxWidth
= max
;
3613 max
= m_aColWidths
.Item(col
)->nMaxWidth
;
3614 width
= max
+ AUTOSIZE_COL_MARGIN
;
3618 column
->SetWidth( width
);
3620 // invalidate it as it has to be recalculated
3624 int wxListMainWindow::GetHeaderWidth() const
3626 if ( !m_headerWidth
)
3628 wxListMainWindow
*self
= wxConstCast(this, wxListMainWindow
);
3630 size_t count
= GetColumnCount();
3631 for ( size_t col
= 0; col
< count
; col
++ )
3633 self
->m_headerWidth
+= GetColumnWidth(col
);
3637 return m_headerWidth
;
3640 void wxListMainWindow::GetColumn( int col
, wxListItem
&item
) const
3642 wxListHeaderDataList::compatibility_iterator node
= m_columns
.Item( col
);
3643 wxCHECK_RET( node
, _T("invalid column index in GetColumn") );
3645 wxListHeaderData
*column
= node
->GetData();
3646 column
->GetItem( item
);
3649 int wxListMainWindow::GetColumnWidth( int col
) const
3651 wxListHeaderDataList::compatibility_iterator node
= m_columns
.Item( col
);
3652 wxCHECK_MSG( node
, 0, _T("invalid column index") );
3654 wxListHeaderData
*column
= node
->GetData();
3655 return column
->GetWidth();
3658 // ----------------------------------------------------------------------------
3660 // ----------------------------------------------------------------------------
3662 void wxListMainWindow::SetItem( wxListItem
&item
)
3664 long id
= item
.m_itemId
;
3665 wxCHECK_RET( id
>= 0 && (size_t)id
< GetItemCount(),
3666 _T("invalid item index in SetItem") );
3670 wxListLineData
*line
= GetLine((size_t)id
);
3671 line
->SetItem( item
.m_col
, item
);
3673 // Set item state if user wants
3674 if ( item
.m_mask
& wxLIST_MASK_STATE
)
3675 SetItemState( item
.m_itemId
, item
.m_state
, item
.m_state
);
3679 // update the Max Width Cache if needed
3680 int width
= GetItemWidthWithImage(&item
);
3682 if (width
> m_aColWidths
.Item(item
.m_col
)->nMaxWidth
)
3683 m_aColWidths
.Item(item
.m_col
)->nMaxWidth
= width
;
3687 // update the item on screen
3689 GetItemRect(id
, rectItem
);
3690 RefreshRect(rectItem
);
3693 void wxListMainWindow::SetItemStateAll(long state
, long stateMask
)
3698 // first deal with selection
3699 if ( stateMask
& wxLIST_STATE_SELECTED
)
3701 // set/clear select state
3704 // optimized version for virtual listctrl.
3705 m_selStore
.SelectRange(0, GetItemCount() - 1, state
== wxLIST_STATE_SELECTED
);
3708 else if ( state
& wxLIST_STATE_SELECTED
)
3710 const long count
= GetItemCount();
3711 for( long i
= 0; i
< count
; i
++ )
3713 SetItemState( i
, wxLIST_STATE_SELECTED
, wxLIST_STATE_SELECTED
);
3719 // clear for non virtual (somewhat optimized by using GetNextItem())
3721 while ( (i
= GetNextItem(i
, wxLIST_NEXT_ALL
, wxLIST_STATE_SELECTED
)) != -1 )
3723 SetItemState( i
, 0, wxLIST_STATE_SELECTED
);
3728 if ( HasCurrent() && (state
== 0) && (stateMask
& wxLIST_STATE_FOCUSED
) )
3730 // unfocus all: only one item can be focussed, so clearing focus for
3731 // all items is simply clearing focus of the focussed item.
3732 SetItemState(m_current
, state
, stateMask
);
3734 //(setting focus to all items makes no sense, so it is not handled here.)
3737 void wxListMainWindow::SetItemState( long litem
, long state
, long stateMask
)
3741 SetItemStateAll(state
, stateMask
);
3745 wxCHECK_RET( litem
>= 0 && (size_t)litem
< GetItemCount(),
3746 _T("invalid list ctrl item index in SetItem") );
3748 size_t oldCurrent
= m_current
;
3749 size_t item
= (size_t)litem
; // safe because of the check above
3751 // do we need to change the focus?
3752 if ( stateMask
& wxLIST_STATE_FOCUSED
)
3754 if ( state
& wxLIST_STATE_FOCUSED
)
3756 // don't do anything if this item is already focused
3757 if ( item
!= m_current
)
3759 ChangeCurrent(item
);
3761 if ( oldCurrent
!= (size_t)-1 )
3763 if ( IsSingleSel() )
3765 HighlightLine(oldCurrent
, false);
3768 RefreshLine(oldCurrent
);
3771 RefreshLine( m_current
);
3776 // don't do anything if this item is not focused
3777 if ( item
== m_current
)
3781 if ( IsSingleSel() )
3783 // we must unselect the old current item as well or we
3784 // might end up with more than one selected item in a
3785 // single selection control
3786 HighlightLine(oldCurrent
, false);
3789 RefreshLine( oldCurrent
);
3794 // do we need to change the selection state?
3795 if ( stateMask
& wxLIST_STATE_SELECTED
)
3797 bool on
= (state
& wxLIST_STATE_SELECTED
) != 0;
3799 if ( IsSingleSel() )
3803 // selecting the item also makes it the focused one in the
3805 if ( m_current
!= item
)
3807 ChangeCurrent(item
);
3809 if ( oldCurrent
!= (size_t)-1 )
3811 HighlightLine( oldCurrent
, false );
3812 RefreshLine( oldCurrent
);
3818 // only the current item may be selected anyhow
3819 if ( item
!= m_current
)
3824 if ( HighlightLine(item
, on
) )
3831 int wxListMainWindow::GetItemState( long item
, long stateMask
) const
3833 wxCHECK_MSG( item
>= 0 && (size_t)item
< GetItemCount(), 0,
3834 _T("invalid list ctrl item index in GetItemState()") );
3836 int ret
= wxLIST_STATE_DONTCARE
;
3838 if ( stateMask
& wxLIST_STATE_FOCUSED
)
3840 if ( (size_t)item
== m_current
)
3841 ret
|= wxLIST_STATE_FOCUSED
;
3844 if ( stateMask
& wxLIST_STATE_SELECTED
)
3846 if ( IsHighlighted(item
) )
3847 ret
|= wxLIST_STATE_SELECTED
;
3853 void wxListMainWindow::GetItem( wxListItem
&item
) const
3855 wxCHECK_RET( item
.m_itemId
>= 0 && (size_t)item
.m_itemId
< GetItemCount(),
3856 _T("invalid item index in GetItem") );
3858 wxListLineData
*line
= GetLine((size_t)item
.m_itemId
);
3859 line
->GetItem( item
.m_col
, item
);
3861 // Get item state if user wants it
3862 if ( item
.m_mask
& wxLIST_MASK_STATE
)
3863 item
.m_state
= GetItemState( item
.m_itemId
, wxLIST_STATE_SELECTED
|
3864 wxLIST_STATE_FOCUSED
);
3867 // ----------------------------------------------------------------------------
3869 // ----------------------------------------------------------------------------
3871 size_t wxListMainWindow::GetItemCount() const
3873 return IsVirtual() ? m_countVirt
: m_lines
.GetCount();
3876 void wxListMainWindow::SetItemCount(long count
)
3878 m_selStore
.SetItemCount(count
);
3879 m_countVirt
= count
;
3881 ResetVisibleLinesRange();
3883 // scrollbars must be reset
3887 int wxListMainWindow::GetSelectedItemCount() const
3889 // deal with the quick case first
3890 if ( IsSingleSel() )
3892 return HasCurrent() ? IsHighlighted(m_current
) : false;
3895 // virtual controls remmebers all its selections itself
3897 return m_selStore
.GetSelectedCount();
3899 // TODO: we probably should maintain the number of items selected even for
3900 // non virtual controls as enumerating all lines is really slow...
3901 size_t countSel
= 0;
3902 size_t count
= GetItemCount();
3903 for ( size_t line
= 0; line
< count
; line
++ )
3905 if ( GetLine(line
)->IsHighlighted() )
3912 // ----------------------------------------------------------------------------
3913 // item position/size
3914 // ----------------------------------------------------------------------------
3916 wxRect
wxListMainWindow::GetViewRect() const
3918 wxASSERT_MSG( !HasFlag(wxLC_REPORT
| wxLC_LIST
),
3919 _T("wxListCtrl::GetViewRect() only works in icon mode") );
3921 // we need to find the longest/tallest label
3924 const int count
= GetItemCount();
3927 for ( int i
= 0; i
< count
; i
++ )
3932 wxCoord x
= r
.GetRight(),
3942 // some fudge needed to make it look prettier
3943 xMax
+= 2*EXTRA_BORDER_X
;
3944 yMax
+= 2*EXTRA_BORDER_Y
;
3946 // account for the scrollbars if necessary
3947 const wxSize sizeAll
= GetClientSize();
3948 if ( xMax
> sizeAll
.x
)
3949 yMax
+= wxSystemSettings::GetMetric(wxSYS_HSCROLL_Y
);
3950 if ( yMax
> sizeAll
.y
)
3951 xMax
+= wxSystemSettings::GetMetric(wxSYS_VSCROLL_X
);
3953 return wxRect(0, 0, xMax
, yMax
);
3956 void wxListMainWindow::GetItemRect( long index
, wxRect
&rect
) const
3958 wxCHECK_RET( index
>= 0 && (size_t)index
< GetItemCount(),
3959 _T("invalid index in GetItemRect") );
3961 // ensure that we're laid out, otherwise we could return nonsense
3964 wxConstCast(this, wxListMainWindow
)->
3965 RecalculatePositions(true /* no refresh */);
3968 rect
= GetLineRect((size_t)index
);
3970 CalcScrolledPosition(rect
.x
, rect
.y
, &rect
.x
, &rect
.y
);
3973 bool wxListMainWindow::GetItemPosition(long item
, wxPoint
& pos
) const
3976 GetItemRect(item
, rect
);
3984 // ----------------------------------------------------------------------------
3985 // geometry calculation
3986 // ----------------------------------------------------------------------------
3988 void wxListMainWindow::RecalculatePositions(bool noRefresh
)
3990 wxClientDC
dc( this );
3991 dc
.SetFont( GetFont() );
3993 const size_t count
= GetItemCount();
3996 if ( HasFlag(wxLC_ICON
) )
3997 iconSpacing
= m_normal_spacing
;
3998 else if ( HasFlag(wxLC_SMALL_ICON
) )
3999 iconSpacing
= m_small_spacing
;
4003 // Note that we do not call GetClientSize() here but
4004 // GetSize() and subtract the border size for sunken
4005 // borders manually. This is technically incorrect,
4006 // but we need to know the client area's size WITHOUT
4007 // scrollbars here. Since we don't know if there are
4008 // any scrollbars, we use GetSize() instead. Another
4009 // solution would be to call SetScrollbars() here to
4010 // remove the scrollbars and call GetClientSize() then,
4011 // but this might result in flicker and - worse - will
4012 // reset the scrollbars to 0 which is not good at all
4013 // if you resize a dialog/window, but don't want to
4014 // reset the window scrolling. RR.
4015 // Furthermore, we actually do NOT subtract the border
4016 // width as 2 pixels is just the extra space which we
4017 // need around the actual content in the window. Other-
4018 // wise the text would e.g. touch the upper border. RR.
4021 GetSize( &clientWidth
, &clientHeight
);
4023 const int lineHeight
= GetLineHeight();
4025 if ( InReportView() )
4027 // all lines have the same height and we scroll one line per step
4028 int entireHeight
= count
*lineHeight
+ LINE_SPACING
;
4030 m_linesPerPage
= clientHeight
/ lineHeight
;
4032 ResetVisibleLinesRange();
4034 SetScrollbars( SCROLL_UNIT_X
, lineHeight
,
4035 GetHeaderWidth() / SCROLL_UNIT_X
,
4036 (entireHeight
+ lineHeight
- 1) / lineHeight
,
4037 GetScrollPos(wxHORIZONTAL
),
4038 GetScrollPos(wxVERTICAL
),
4043 // we have 3 different layout strategies: either layout all items
4044 // horizontally/vertically (wxLC_ALIGN_XXX styles explicitly given) or
4045 // to arrange them in top to bottom, left to right (don't ask me why
4046 // not the other way round...) order
4047 if ( HasFlag(wxLC_ALIGN_LEFT
| wxLC_ALIGN_TOP
) )
4049 int x
= EXTRA_BORDER_X
;
4050 int y
= EXTRA_BORDER_Y
;
4052 wxCoord widthMax
= 0;
4055 for ( i
= 0; i
< count
; i
++ )
4057 wxListLineData
*line
= GetLine(i
);
4058 line
->CalculateSize( &dc
, iconSpacing
);
4059 line
->SetPosition( x
, y
, iconSpacing
);
4061 wxSize sizeLine
= GetLineSize(i
);
4063 if ( HasFlag(wxLC_ALIGN_TOP
) )
4065 if ( sizeLine
.x
> widthMax
)
4066 widthMax
= sizeLine
.x
;
4070 else // wxLC_ALIGN_LEFT
4072 x
+= sizeLine
.x
+ MARGIN_BETWEEN_ROWS
;
4076 if ( HasFlag(wxLC_ALIGN_TOP
) )
4078 // traverse the items again and tweak their sizes so that they are
4079 // all the same in a row
4080 for ( i
= 0; i
< count
; i
++ )
4082 wxListLineData
*line
= GetLine(i
);
4083 line
->m_gi
->ExtendWidth(widthMax
);
4092 (x
+ SCROLL_UNIT_X
) / SCROLL_UNIT_X
,
4093 (y
+ lineHeight
) / lineHeight
,
4094 GetScrollPos( wxHORIZONTAL
),
4095 GetScrollPos( wxVERTICAL
),
4099 else // "flowed" arrangement, the most complicated case
4101 // at first we try without any scrollbars, if the items don't fit into
4102 // the window, we recalculate after subtracting the space taken by the
4105 int entireWidth
= 0;
4107 for (int tries
= 0; tries
< 2; tries
++)
4109 entireWidth
= 2*EXTRA_BORDER_X
;
4113 // Now we have decided that the items do not fit into the
4114 // client area, so we need a scrollbar
4115 entireWidth
+= SCROLL_UNIT_X
;
4118 int x
= EXTRA_BORDER_X
;
4119 int y
= EXTRA_BORDER_Y
;
4120 int maxWidthInThisRow
= 0;
4123 int currentlyVisibleLines
= 0;
4125 for (size_t i
= 0; i
< count
; i
++)
4127 currentlyVisibleLines
++;
4128 wxListLineData
*line
= GetLine(i
);
4129 line
->CalculateSize( &dc
, iconSpacing
);
4130 line
->SetPosition( x
, y
, iconSpacing
);
4132 wxSize sizeLine
= GetLineSize(i
);
4134 if ( maxWidthInThisRow
< sizeLine
.x
)
4135 maxWidthInThisRow
= sizeLine
.x
;
4138 if (currentlyVisibleLines
> m_linesPerPage
)
4139 m_linesPerPage
= currentlyVisibleLines
;
4141 if ( y
+ sizeLine
.y
>= clientHeight
)
4143 currentlyVisibleLines
= 0;
4145 maxWidthInThisRow
+= MARGIN_BETWEEN_ROWS
;
4146 x
+= maxWidthInThisRow
;
4147 entireWidth
+= maxWidthInThisRow
;
4148 maxWidthInThisRow
= 0;
4151 // We have reached the last item.
4152 if ( i
== count
- 1 )
4153 entireWidth
+= maxWidthInThisRow
;
4155 if ( (tries
== 0) &&
4156 (entireWidth
+ SCROLL_UNIT_X
> clientWidth
) )
4158 clientHeight
-= wxSystemSettings::
4159 GetMetric(wxSYS_HSCROLL_Y
);
4164 if ( i
== count
- 1 )
4165 tries
= 1; // Everything fits, no second try required.
4173 (entireWidth
+ SCROLL_UNIT_X
) / SCROLL_UNIT_X
,
4175 GetScrollPos( wxHORIZONTAL
),
4184 // FIXME: why should we call it from here?
4191 void wxListMainWindow::RefreshAll()
4196 wxListHeaderWindow
*headerWin
= GetListCtrl()->m_headerWin
;
4197 if ( headerWin
&& headerWin
->m_dirty
)
4199 headerWin
->m_dirty
= false;
4200 headerWin
->Refresh();
4204 void wxListMainWindow::UpdateCurrent()
4206 if ( !HasCurrent() && !IsEmpty() )
4212 long wxListMainWindow::GetNextItem( long item
,
4213 int WXUNUSED(geometry
),
4217 max
= GetItemCount();
4218 wxCHECK_MSG( (ret
== -1) || (ret
< max
), -1,
4219 _T("invalid listctrl index in GetNextItem()") );
4221 // notice that we start with the next item (or the first one if item == -1)
4222 // and this is intentional to allow writing a simple loop to iterate over
4223 // all selected items
4227 // this is not an error because the index was ok initially, just no
4238 size_t count
= GetItemCount();
4239 for ( size_t line
= (size_t)ret
; line
< count
; line
++ )
4241 if ( (state
& wxLIST_STATE_FOCUSED
) && (line
== m_current
) )
4244 if ( (state
& wxLIST_STATE_SELECTED
) && IsHighlighted(line
) )
4251 // ----------------------------------------------------------------------------
4253 // ----------------------------------------------------------------------------
4255 void wxListMainWindow::DeleteItem( long lindex
)
4257 size_t count
= GetItemCount();
4259 wxCHECK_RET( (lindex
>= 0) && ((size_t)lindex
< count
),
4260 _T("invalid item index in DeleteItem") );
4262 size_t index
= (size_t)lindex
;
4264 // we don't need to adjust the index for the previous items
4265 if ( HasCurrent() && m_current
>= index
)
4267 // if the current item is being deleted, we want the next one to
4268 // become selected - unless there is no next one - so don't adjust
4269 // m_current in this case
4270 if ( m_current
!= index
|| m_current
== count
- 1 )
4276 if ( InReportView() )
4278 // mark the Column Max Width cache as dirty if the items in the line
4279 // we're deleting contain the Max Column Width
4280 wxListLineData
* const line
= GetLine(index
);
4281 wxListItemDataList::compatibility_iterator n
;
4282 wxListItemData
*itemData
;
4286 for (size_t i
= 0; i
< m_columns
.GetCount(); i
++)
4288 n
= line
->m_items
.Item( i
);
4289 itemData
= n
->GetData();
4290 itemData
->GetItem(item
);
4292 itemWidth
= GetItemWidthWithImage(&item
);
4294 if (itemWidth
>= m_aColWidths
.Item(i
)->nMaxWidth
)
4295 m_aColWidths
.Item(i
)->bNeedsUpdate
= true;
4298 ResetVisibleLinesRange();
4305 m_selStore
.OnItemDelete(index
);
4309 m_lines
.RemoveAt( index
);
4312 // we need to refresh the (vert) scrollbar as the number of items changed
4315 SendNotify( index
, wxEVT_COMMAND_LIST_DELETE_ITEM
);
4317 RefreshAfter(index
);
4320 void wxListMainWindow::DeleteColumn( int col
)
4322 wxListHeaderDataList::compatibility_iterator node
= m_columns
.Item( col
);
4324 wxCHECK_RET( node
, wxT("invalid column index in DeleteColumn()") );
4327 delete node
->GetData();
4328 m_columns
.Erase( node
);
4332 // update all the items
4333 for ( size_t i
= 0; i
< m_lines
.GetCount(); i
++ )
4335 wxListLineData
* const line
= GetLine(i
);
4336 wxListItemDataList::compatibility_iterator n
= line
->m_items
.Item( col
);
4337 delete n
->GetData();
4338 line
->m_items
.Erase(n
);
4342 if ( InReportView() ) // we only cache max widths when in Report View
4344 delete m_aColWidths
.Item(col
);
4345 m_aColWidths
.RemoveAt(col
);
4348 // invalidate it as it has to be recalculated
4352 void wxListMainWindow::DoDeleteAllItems()
4356 // nothing to do - in particular, don't send the event
4362 // to make the deletion of all items faster, we don't send the
4363 // notifications for each item deletion in this case but only one event
4364 // for all of them: this is compatible with wxMSW and documented in
4365 // DeleteAllItems() description
4367 wxListEvent
event( wxEVT_COMMAND_LIST_DELETE_ALL_ITEMS
, GetParent()->GetId() );
4368 event
.SetEventObject( GetParent() );
4369 GetParent()->GetEventHandler()->ProcessEvent( event
);
4378 if ( InReportView() )
4380 ResetVisibleLinesRange();
4381 for (size_t i
= 0; i
< m_aColWidths
.GetCount(); i
++)
4383 m_aColWidths
.Item(i
)->bNeedsUpdate
= true;
4390 void wxListMainWindow::DeleteAllItems()
4394 RecalculatePositions();
4397 void wxListMainWindow::DeleteEverything()
4399 WX_CLEAR_LIST(wxListHeaderDataList
, m_columns
);
4400 WX_CLEAR_ARRAY(m_aColWidths
);
4405 // ----------------------------------------------------------------------------
4406 // scanning for an item
4407 // ----------------------------------------------------------------------------
4409 void wxListMainWindow::EnsureVisible( long index
)
4411 wxCHECK_RET( index
>= 0 && (size_t)index
< GetItemCount(),
4412 _T("invalid index in EnsureVisible") );
4414 // We have to call this here because the label in question might just have
4415 // been added and its position is not known yet
4418 RecalculatePositions(true /* no refresh */);
4421 MoveToItem((size_t)index
);
4424 long wxListMainWindow::FindItem(long start
, const wxString
& str
, bool WXUNUSED(partial
) )
4431 size_t count
= GetItemCount();
4432 for ( size_t i
= (size_t)pos
; i
< count
; i
++ )
4434 wxListLineData
*line
= GetLine(i
);
4435 if ( line
->GetText(0) == tmp
)
4442 long wxListMainWindow::FindItem(long start
, wxUIntPtr data
)
4448 size_t count
= GetItemCount();
4449 for (size_t i
= (size_t)pos
; i
< count
; i
++)
4451 wxListLineData
*line
= GetLine(i
);
4453 line
->GetItem( 0, item
);
4454 if (item
.m_data
== data
)
4461 long wxListMainWindow::FindItem( const wxPoint
& pt
)
4464 GetVisibleLinesRange(&topItem
, NULL
);
4467 GetItemPosition( GetItemCount()-1, p
);
4470 long id
= (long) floor( pt
.y
*double(GetItemCount()-topItem
-1)/p
.y
+topItem
);
4471 if( id
>= 0 && id
< (long)GetItemCount() )
4477 long wxListMainWindow::HitTest( int x
, int y
, int &flags
)
4479 CalcUnscrolledPosition( x
, y
, &x
, &y
);
4481 size_t count
= GetItemCount();
4483 if ( InReportView() )
4485 size_t current
= y
/ GetLineHeight();
4486 if ( current
< count
)
4488 flags
= HitTestLine(current
, x
, y
);
4495 // TODO: optimize it too! this is less simple than for report view but
4496 // enumerating all items is still not a way to do it!!
4497 for ( size_t current
= 0; current
< count
; current
++ )
4499 flags
= HitTestLine(current
, x
, y
);
4508 // ----------------------------------------------------------------------------
4510 // ----------------------------------------------------------------------------
4512 void wxListMainWindow::InsertItem( wxListItem
&item
)
4514 wxASSERT_MSG( !IsVirtual(), _T("can't be used with virtual control") );
4516 int count
= GetItemCount();
4517 wxCHECK_RET( item
.m_itemId
>= 0, _T("invalid item index") );
4519 if (item
.m_itemId
> count
)
4520 item
.m_itemId
= count
;
4522 size_t id
= item
.m_itemId
;
4526 if ( InReportView() )
4528 ResetVisibleLinesRange();
4530 // calculate the width of the item and adjust the max column width
4531 wxColWidthInfo
*pWidthInfo
= m_aColWidths
.Item(item
.GetColumn());
4532 int width
= GetItemWidthWithImage(&item
);
4533 item
.SetWidth(width
);
4534 if (width
> pWidthInfo
->nMaxWidth
)
4535 pWidthInfo
->nMaxWidth
= width
;
4538 wxListLineData
*line
= new wxListLineData(this);
4540 line
->SetItem( item
.m_col
, item
);
4542 m_lines
.Insert( line
, id
);
4546 // If an item is selected at or below the point of insertion, we need to
4547 // increment the member variables because the current row's index has gone
4549 if ( HasCurrent() && m_current
>= id
)
4554 SendNotify(id
, wxEVT_COMMAND_LIST_INSERT_ITEM
);
4556 RefreshLines(id
, GetItemCount() - 1);
4559 void wxListMainWindow::InsertColumn( long col
, wxListItem
&item
)
4562 if ( InReportView() )
4564 if (item
.m_width
== wxLIST_AUTOSIZE_USEHEADER
)
4565 item
.m_width
= GetTextLength( item
.m_text
);
4567 wxListHeaderData
*column
= new wxListHeaderData( item
);
4568 wxColWidthInfo
*colWidthInfo
= new wxColWidthInfo();
4570 bool insert
= (col
>= 0) && ((size_t)col
< m_columns
.GetCount());
4573 wxListHeaderDataList::compatibility_iterator
4574 node
= m_columns
.Item( col
);
4575 m_columns
.Insert( node
, column
);
4576 m_aColWidths
.Insert( colWidthInfo
, col
);
4580 m_columns
.Append( column
);
4581 m_aColWidths
.Add( colWidthInfo
);
4586 // update all the items
4587 for ( size_t i
= 0; i
< m_lines
.GetCount(); i
++ )
4589 wxListLineData
* const line
= GetLine(i
);
4590 wxListItemData
* const data
= new wxListItemData(this);
4592 line
->m_items
.Insert(col
, data
);
4594 line
->m_items
.Append(data
);
4598 // invalidate it as it has to be recalculated
4603 int wxListMainWindow::GetItemWidthWithImage(wxListItem
* item
)
4606 wxClientDC
dc(this);
4608 dc
.SetFont( GetFont() );
4610 if (item
->GetImage() != -1)
4613 GetImageSize( item
->GetImage(), ix
, iy
);
4617 if (!item
->GetText().empty())
4620 dc
.GetTextExtent( item
->GetText(), &w
, NULL
);
4627 // ----------------------------------------------------------------------------
4629 // ----------------------------------------------------------------------------
4631 wxListCtrlCompare list_ctrl_compare_func_2
;
4632 long list_ctrl_compare_data
;
4634 int LINKAGEMODE
list_ctrl_compare_func_1( wxListLineData
**arg1
, wxListLineData
**arg2
)
4636 wxListLineData
*line1
= *arg1
;
4637 wxListLineData
*line2
= *arg2
;
4639 line1
->GetItem( 0, item
);
4640 wxUIntPtr data1
= item
.m_data
;
4641 line2
->GetItem( 0, item
);
4642 wxUIntPtr data2
= item
.m_data
;
4643 return list_ctrl_compare_func_2( data1
, data2
, list_ctrl_compare_data
);
4646 void wxListMainWindow::SortItems( wxListCtrlCompare fn
, long data
)
4648 list_ctrl_compare_func_2
= fn
;
4649 list_ctrl_compare_data
= data
;
4650 m_lines
.Sort( list_ctrl_compare_func_1
);
4654 // ----------------------------------------------------------------------------
4656 // ----------------------------------------------------------------------------
4658 void wxListMainWindow::OnScroll(wxScrollWinEvent
& event
)
4660 // update our idea of which lines are shown when we redraw the window the
4662 ResetVisibleLinesRange();
4665 #if ( defined(__WXGTK__) || defined(__WXMAC__) ) && !defined(__WXUNIVERSAL__)
4666 wxScrolledWindow::OnScroll(event
);
4668 HandleOnScroll( event
);
4671 if ( event
.GetOrientation() == wxHORIZONTAL
&& HasHeader() )
4673 wxGenericListCtrl
* lc
= GetListCtrl();
4674 wxCHECK_RET( lc
, _T("no listctrl window?") );
4676 lc
->m_headerWin
->Refresh();
4677 lc
->m_headerWin
->Update();
4681 int wxListMainWindow::GetCountPerPage() const
4683 if ( !m_linesPerPage
)
4685 wxConstCast(this, wxListMainWindow
)->
4686 m_linesPerPage
= GetClientSize().y
/ GetLineHeight();
4689 return m_linesPerPage
;
4692 void wxListMainWindow::GetVisibleLinesRange(size_t *from
, size_t *to
)
4694 wxASSERT_MSG( InReportView(), _T("this is for report mode only") );
4696 if ( m_lineFrom
== (size_t)-1 )
4698 size_t count
= GetItemCount();
4701 m_lineFrom
= GetScrollPos(wxVERTICAL
);
4703 // this may happen if SetScrollbars() hadn't been called yet
4704 if ( m_lineFrom
>= count
)
4705 m_lineFrom
= count
- 1;
4707 // we redraw one extra line but this is needed to make the redrawing
4708 // logic work when there is a fractional number of lines on screen
4709 m_lineTo
= m_lineFrom
+ m_linesPerPage
;
4710 if ( m_lineTo
>= count
)
4711 m_lineTo
= count
- 1;
4713 else // empty control
4716 m_lineTo
= (size_t)-1;
4720 wxASSERT_MSG( IsEmpty() ||
4721 (m_lineFrom
<= m_lineTo
&& m_lineTo
< GetItemCount()),
4722 _T("GetVisibleLinesRange() returns incorrect result") );
4730 // -------------------------------------------------------------------------------------
4731 // wxGenericListCtrl
4732 // -------------------------------------------------------------------------------------
4734 IMPLEMENT_DYNAMIC_CLASS(wxGenericListCtrl
, wxControl
)
4736 BEGIN_EVENT_TABLE(wxGenericListCtrl
,wxControl
)
4737 EVT_SIZE(wxGenericListCtrl::OnSize
)
4740 wxGenericListCtrl::wxGenericListCtrl()
4742 m_imageListNormal
= (wxImageListType
*) NULL
;
4743 m_imageListSmall
= (wxImageListType
*) NULL
;
4744 m_imageListState
= (wxImageListType
*) NULL
;
4746 m_ownsImageListNormal
=
4747 m_ownsImageListSmall
=
4748 m_ownsImageListState
= false;
4750 m_mainWin
= (wxListMainWindow
*) NULL
;
4751 m_headerWin
= (wxListHeaderWindow
*) NULL
;
4755 wxGenericListCtrl::~wxGenericListCtrl()
4757 if (m_ownsImageListNormal
)
4758 delete m_imageListNormal
;
4759 if (m_ownsImageListSmall
)
4760 delete m_imageListSmall
;
4761 if (m_ownsImageListState
)
4762 delete m_imageListState
;
4765 void wxGenericListCtrl::CalculateAndSetHeaderHeight()
4771 GetThemeMetric( kThemeMetricListHeaderHeight
, &h
);
4773 // we use 'g' to get the descent, too
4775 m_headerWin
->GetTextExtent(wxT("Hg"), &w
, &h
, &d
);
4776 h
+= d
+ 2 * HEADER_OFFSET_Y
+ EXTRA_HEIGHT
;
4778 // only update if changed
4779 if ( h
!= m_headerHeight
)
4783 m_headerWin
->SetSize(m_headerWin
->GetSize().x
, m_headerHeight
);
4786 ResizeReportView(true);
4791 void wxGenericListCtrl::CreateHeaderWindow()
4793 m_headerWin
= new wxListHeaderWindow
4795 this, wxID_ANY
, m_mainWin
,
4797 wxSize(GetClientSize().x
, m_headerHeight
),
4800 CalculateAndSetHeaderHeight();
4803 bool wxGenericListCtrl::Create(wxWindow
*parent
,
4808 const wxValidator
&validator
,
4809 const wxString
&name
)
4813 m_imageListState
= (wxImageListType
*) NULL
;
4814 m_ownsImageListNormal
=
4815 m_ownsImageListSmall
=
4816 m_ownsImageListState
= false;
4818 m_mainWin
= (wxListMainWindow
*) NULL
;
4819 m_headerWin
= (wxListHeaderWindow
*) NULL
;
4823 if ( !(style
& wxLC_MASK_TYPE
) )
4825 style
= style
| wxLC_LIST
;
4828 if ( !wxControl::Create( parent
, id
, pos
, size
, style
, validator
, name
) )
4831 // don't create the inner window with the border
4832 style
&= ~wxBORDER_MASK
;
4834 m_mainWin
= new wxListMainWindow( this, wxID_ANY
, wxPoint(0,0), size
, style
);
4836 #ifdef __WXMAC_CARBON__
4837 // Human Interface Guidelines ask us for a special font in this case
4838 if ( GetWindowVariant() == wxWINDOW_VARIANT_NORMAL
)
4841 font
.MacCreateThemeFont( kThemeViewsFont
) ;
4845 if ( InReportView() )
4847 CreateHeaderWindow();
4848 #ifdef __WXMAC_CARBON__
4852 font
.MacCreateThemeFont( kThemeSmallSystemFont
) ;
4853 m_headerWin
->SetFont( font
);
4854 CalculateAndSetHeaderHeight();
4857 if ( HasFlag(wxLC_NO_HEADER
) )
4859 // VZ: why do we create it at all then?
4860 m_headerWin
->Show( false );
4869 void wxGenericListCtrl::SetSingleStyle( long style
, bool add
)
4871 wxASSERT_MSG( !(style
& wxLC_VIRTUAL
),
4872 _T("wxLC_VIRTUAL can't be [un]set") );
4874 long flag
= GetWindowStyle();
4878 if (style
& wxLC_MASK_TYPE
)
4879 flag
&= ~(wxLC_MASK_TYPE
| wxLC_VIRTUAL
);
4880 if (style
& wxLC_MASK_ALIGN
)
4881 flag
&= ~wxLC_MASK_ALIGN
;
4882 if (style
& wxLC_MASK_SORT
)
4883 flag
&= ~wxLC_MASK_SORT
;
4895 SetWindowStyleFlag( flag
);
4898 void wxGenericListCtrl::SetWindowStyleFlag( long flag
)
4902 m_mainWin
->DeleteEverything();
4904 // has the header visibility changed?
4905 bool hasHeader
= HasHeader();
4906 bool willHaveHeader
= (flag
& wxLC_REPORT
) && !(flag
& wxLC_NO_HEADER
);
4908 if ( hasHeader
!= willHaveHeader
)
4915 // don't delete, just hide, as we can reuse it later
4916 m_headerWin
->Show(false);
4918 //else: nothing to do
4920 else // must show header
4924 CreateHeaderWindow();
4926 else // already have it, just show
4928 m_headerWin
->Show( true );
4932 ResizeReportView(willHaveHeader
);
4936 wxWindow::SetWindowStyleFlag( flag
);
4939 bool wxGenericListCtrl::GetColumn(int col
, wxListItem
&item
) const
4941 m_mainWin
->GetColumn( col
, item
);
4945 bool wxGenericListCtrl::SetColumn( int col
, wxListItem
& item
)
4947 m_mainWin
->SetColumn( col
, item
);
4951 int wxGenericListCtrl::GetColumnWidth( int col
) const
4953 return m_mainWin
->GetColumnWidth( col
);
4956 bool wxGenericListCtrl::SetColumnWidth( int col
, int width
)
4958 m_mainWin
->SetColumnWidth( col
, width
);
4962 int wxGenericListCtrl::GetCountPerPage() const
4964 return m_mainWin
->GetCountPerPage(); // different from Windows ?
4967 bool wxGenericListCtrl::GetItem( wxListItem
&info
) const
4969 m_mainWin
->GetItem( info
);
4973 bool wxGenericListCtrl::SetItem( wxListItem
&info
)
4975 m_mainWin
->SetItem( info
);
4979 long wxGenericListCtrl::SetItem( long index
, int col
, const wxString
& label
, int imageId
)
4982 info
.m_text
= label
;
4983 info
.m_mask
= wxLIST_MASK_TEXT
;
4984 info
.m_itemId
= index
;
4988 info
.m_image
= imageId
;
4989 info
.m_mask
|= wxLIST_MASK_IMAGE
;
4991 m_mainWin
->SetItem(info
);
4995 int wxGenericListCtrl::GetItemState( long item
, long stateMask
) const
4997 return m_mainWin
->GetItemState( item
, stateMask
);
5000 bool wxGenericListCtrl::SetItemState( long item
, long state
, long stateMask
)
5002 m_mainWin
->SetItemState( item
, state
, stateMask
);
5007 wxGenericListCtrl::SetItemImage( long item
, int image
, int WXUNUSED(selImage
) )
5010 info
.m_image
= image
;
5011 info
.m_mask
= wxLIST_MASK_IMAGE
;
5012 info
.m_itemId
= item
;
5013 m_mainWin
->SetItem( info
);
5017 wxString
wxGenericListCtrl::GetItemText( long item
) const
5019 return m_mainWin
->GetItemText(item
);
5022 void wxGenericListCtrl::SetItemText( long item
, const wxString
& str
)
5024 m_mainWin
->SetItemText(item
, str
);
5027 wxUIntPtr
wxGenericListCtrl::GetItemData( long item
) const
5030 info
.m_mask
= wxLIST_MASK_DATA
;
5031 info
.m_itemId
= item
;
5032 m_mainWin
->GetItem( info
);
5036 bool wxGenericListCtrl::SetItemData( long item
, long data
)
5039 info
.m_mask
= wxLIST_MASK_DATA
;
5040 info
.m_itemId
= item
;
5042 m_mainWin
->SetItem( info
);
5046 wxRect
wxGenericListCtrl::GetViewRect() const
5048 return m_mainWin
->GetViewRect();
5051 bool wxGenericListCtrl::GetItemRect( long item
, wxRect
&rect
, int WXUNUSED(code
) ) const
5053 m_mainWin
->GetItemRect( item
, rect
);
5054 if ( m_mainWin
->HasHeader() )
5055 rect
.y
+= m_headerHeight
+ 1;
5059 bool wxGenericListCtrl::GetItemPosition( long item
, wxPoint
& pos
) const
5061 m_mainWin
->GetItemPosition( item
, pos
);
5065 bool wxGenericListCtrl::SetItemPosition( long WXUNUSED(item
), const wxPoint
& WXUNUSED(pos
) )
5070 int wxGenericListCtrl::GetItemCount() const
5072 return m_mainWin
->GetItemCount();
5075 int wxGenericListCtrl::GetColumnCount() const
5077 return m_mainWin
->GetColumnCount();
5080 void wxGenericListCtrl::SetItemSpacing( int spacing
, bool isSmall
)
5082 m_mainWin
->SetItemSpacing( spacing
, isSmall
);
5085 wxSize
wxGenericListCtrl::GetItemSpacing() const
5087 const int spacing
= m_mainWin
->GetItemSpacing(HasFlag(wxLC_SMALL_ICON
));
5089 return wxSize(spacing
, spacing
);
5092 int wxGenericListCtrl::GetItemSpacing( bool isSmall
) const
5094 return m_mainWin
->GetItemSpacing( isSmall
);
5097 void wxGenericListCtrl::SetItemTextColour( long item
, const wxColour
&col
)
5100 info
.m_itemId
= item
;
5101 info
.SetTextColour( col
);
5102 m_mainWin
->SetItem( info
);
5105 wxColour
wxGenericListCtrl::GetItemTextColour( long item
) const
5108 info
.m_itemId
= item
;
5109 m_mainWin
->GetItem( info
);
5110 return info
.GetTextColour();
5113 void wxGenericListCtrl::SetItemBackgroundColour( long item
, const wxColour
&col
)
5116 info
.m_itemId
= item
;
5117 info
.SetBackgroundColour( col
);
5118 m_mainWin
->SetItem( info
);
5121 wxColour
wxGenericListCtrl::GetItemBackgroundColour( long item
) const
5124 info
.m_itemId
= item
;
5125 m_mainWin
->GetItem( info
);
5126 return info
.GetBackgroundColour();
5129 void wxGenericListCtrl::SetItemFont( long item
, const wxFont
&f
)
5132 info
.m_itemId
= item
;
5134 m_mainWin
->SetItem( info
);
5137 wxFont
wxGenericListCtrl::GetItemFont( long item
) const
5140 info
.m_itemId
= item
;
5141 m_mainWin
->GetItem( info
);
5142 return info
.GetFont();
5145 int wxGenericListCtrl::GetSelectedItemCount() const
5147 return m_mainWin
->GetSelectedItemCount();
5150 wxColour
wxGenericListCtrl::GetTextColour() const
5152 return GetForegroundColour();
5155 void wxGenericListCtrl::SetTextColour(const wxColour
& col
)
5157 SetForegroundColour(col
);
5160 long wxGenericListCtrl::GetTopItem() const
5163 m_mainWin
->GetVisibleLinesRange(&top
, NULL
);
5167 long wxGenericListCtrl::GetNextItem( long item
, int geom
, int state
) const
5169 return m_mainWin
->GetNextItem( item
, geom
, state
);
5172 wxImageListType
*wxGenericListCtrl::GetImageList(int which
) const
5174 if (which
== wxIMAGE_LIST_NORMAL
)
5176 return m_imageListNormal
;
5178 else if (which
== wxIMAGE_LIST_SMALL
)
5180 return m_imageListSmall
;
5182 else if (which
== wxIMAGE_LIST_STATE
)
5184 return m_imageListState
;
5186 return (wxImageListType
*) NULL
;
5189 void wxGenericListCtrl::SetImageList( wxImageListType
*imageList
, int which
)
5191 if ( which
== wxIMAGE_LIST_NORMAL
)
5193 if (m_ownsImageListNormal
) delete m_imageListNormal
;
5194 m_imageListNormal
= imageList
;
5195 m_ownsImageListNormal
= false;
5197 else if ( which
== wxIMAGE_LIST_SMALL
)
5199 if (m_ownsImageListSmall
) delete m_imageListSmall
;
5200 m_imageListSmall
= imageList
;
5201 m_ownsImageListSmall
= false;
5203 else if ( which
== wxIMAGE_LIST_STATE
)
5205 if (m_ownsImageListState
) delete m_imageListState
;
5206 m_imageListState
= imageList
;
5207 m_ownsImageListState
= false;
5210 m_mainWin
->SetImageList( imageList
, which
);
5213 void wxGenericListCtrl::AssignImageList(wxImageListType
*imageList
, int which
)
5215 SetImageList(imageList
, which
);
5216 if ( which
== wxIMAGE_LIST_NORMAL
)
5217 m_ownsImageListNormal
= true;
5218 else if ( which
== wxIMAGE_LIST_SMALL
)
5219 m_ownsImageListSmall
= true;
5220 else if ( which
== wxIMAGE_LIST_STATE
)
5221 m_ownsImageListState
= true;
5224 bool wxGenericListCtrl::Arrange( int WXUNUSED(flag
) )
5229 bool wxGenericListCtrl::DeleteItem( long item
)
5231 m_mainWin
->DeleteItem( item
);
5235 bool wxGenericListCtrl::DeleteAllItems()
5237 m_mainWin
->DeleteAllItems();
5241 bool wxGenericListCtrl::DeleteAllColumns()
5243 size_t count
= m_mainWin
->m_columns
.GetCount();
5244 for ( size_t n
= 0; n
< count
; n
++ )
5250 void wxGenericListCtrl::ClearAll()
5252 m_mainWin
->DeleteEverything();
5255 bool wxGenericListCtrl::DeleteColumn( int col
)
5257 m_mainWin
->DeleteColumn( col
);
5259 // if we don't have the header any longer, we need to relayout the window
5260 if ( !GetColumnCount() )
5262 ResizeReportView(false /* no header */);
5268 void wxGenericListCtrl::Edit( long item
)
5270 m_mainWin
->EditLabel( item
);
5273 bool wxGenericListCtrl::EnsureVisible( long item
)
5275 m_mainWin
->EnsureVisible( item
);
5279 long wxGenericListCtrl::FindItem( long start
, const wxString
& str
, bool partial
)
5281 return m_mainWin
->FindItem( start
, str
, partial
);
5284 long wxGenericListCtrl::FindItem( long start
, wxUIntPtr data
)
5286 return m_mainWin
->FindItem( start
, data
);
5289 long wxGenericListCtrl::FindItem( long WXUNUSED(start
), const wxPoint
& pt
,
5290 int WXUNUSED(direction
))
5292 return m_mainWin
->FindItem( pt
);
5295 long wxGenericListCtrl::HitTest( const wxPoint
&point
, int &flags
)
5297 return m_mainWin
->HitTest( (int)point
.x
, (int)point
.y
, flags
);
5300 long wxGenericListCtrl::InsertItem( wxListItem
& info
)
5302 m_mainWin
->InsertItem( info
);
5303 return info
.m_itemId
;
5306 long wxGenericListCtrl::InsertItem( long index
, const wxString
&label
)
5309 info
.m_text
= label
;
5310 info
.m_mask
= wxLIST_MASK_TEXT
;
5311 info
.m_itemId
= index
;
5312 return InsertItem( info
);
5315 long wxGenericListCtrl::InsertItem( long index
, int imageIndex
)
5318 info
.m_mask
= wxLIST_MASK_IMAGE
;
5319 info
.m_image
= imageIndex
;
5320 info
.m_itemId
= index
;
5321 return InsertItem( info
);
5324 long wxGenericListCtrl::InsertItem( long index
, const wxString
&label
, int imageIndex
)
5327 info
.m_text
= label
;
5328 info
.m_image
= imageIndex
;
5329 info
.m_mask
= wxLIST_MASK_TEXT
| wxLIST_MASK_IMAGE
;
5330 info
.m_itemId
= index
;
5331 return InsertItem( info
);
5334 long wxGenericListCtrl::InsertColumn( long col
, wxListItem
&item
)
5336 wxCHECK_MSG( m_headerWin
, -1, _T("can't add column in non report mode") );
5338 m_mainWin
->InsertColumn( col
, item
);
5340 // if we hadn't had header before and have it now we need to relayout the
5342 if ( GetColumnCount() == 1 && m_mainWin
->HasHeader() )
5344 ResizeReportView(true /* have header */);
5347 m_headerWin
->Refresh();
5352 long wxGenericListCtrl::InsertColumn( long col
, const wxString
&heading
,
5353 int format
, int width
)
5356 item
.m_mask
= wxLIST_MASK_TEXT
| wxLIST_MASK_FORMAT
;
5357 item
.m_text
= heading
;
5360 item
.m_mask
|= wxLIST_MASK_WIDTH
;
5361 item
.m_width
= width
;
5363 item
.m_format
= format
;
5365 return InsertColumn( col
, item
);
5368 bool wxGenericListCtrl::ScrollList( int WXUNUSED(dx
), int WXUNUSED(dy
) )
5374 // fn is a function which takes 3 long arguments: item1, item2, data.
5375 // item1 is the long data associated with a first item (NOT the index).
5376 // item2 is the long data associated with a second item (NOT the index).
5377 // data is the same value as passed to SortItems.
5378 // The return value is a negative number if the first item should precede the second
5379 // item, a positive number of the second item should precede the first,
5380 // or zero if the two items are equivalent.
5381 // data is arbitrary data to be passed to the sort function.
5383 bool wxGenericListCtrl::SortItems( wxListCtrlCompare fn
, long data
)
5385 m_mainWin
->SortItems( fn
, data
);
5389 // ----------------------------------------------------------------------------
5391 // ----------------------------------------------------------------------------
5393 void wxGenericListCtrl::OnSize(wxSizeEvent
& WXUNUSED(event
))
5398 ResizeReportView(m_mainWin
->HasHeader());
5400 m_mainWin
->RecalculatePositions();
5403 void wxGenericListCtrl::ResizeReportView(bool showHeader
)
5406 GetClientSize( &cw
, &ch
);
5410 m_headerWin
->SetSize( 0, 0, cw
, m_headerHeight
);
5411 m_mainWin
->SetSize( 0, m_headerHeight
+ 1, cw
, ch
- m_headerHeight
- 1 );
5413 else // no header window
5415 m_mainWin
->SetSize( 0, 0, cw
, ch
);
5419 void wxGenericListCtrl::OnInternalIdle()
5421 wxWindow::OnInternalIdle();
5423 // do it only if needed
5424 if ( !m_mainWin
->m_dirty
)
5427 m_mainWin
->RecalculatePositions();
5430 // ----------------------------------------------------------------------------
5432 // ----------------------------------------------------------------------------
5434 bool wxGenericListCtrl::SetBackgroundColour( const wxColour
&colour
)
5438 m_mainWin
->SetBackgroundColour( colour
);
5439 m_mainWin
->m_dirty
= true;
5445 bool wxGenericListCtrl::SetForegroundColour( const wxColour
&colour
)
5447 if ( !wxWindow::SetForegroundColour( colour
) )
5452 m_mainWin
->SetForegroundColour( colour
);
5453 m_mainWin
->m_dirty
= true;
5458 m_headerWin
->SetForegroundColour( colour
);
5464 bool wxGenericListCtrl::SetFont( const wxFont
&font
)
5466 if ( !wxWindow::SetFont( font
) )
5471 m_mainWin
->SetFont( font
);
5472 m_mainWin
->m_dirty
= true;
5477 m_headerWin
->SetFont( font
);
5478 CalculateAndSetHeaderHeight();
5489 #include "wx/listbox.h"
5494 wxGenericListCtrl::GetClassDefaultAttributes(wxWindowVariant variant
)
5497 // Use the same color scheme as wxListBox
5498 return wxListBox::GetClassDefaultAttributes(variant
);
5500 wxUnusedVar(variant
);
5501 wxVisualAttributes attr
;
5502 attr
.colFg
= wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT
);
5503 attr
.colBg
= wxSystemSettings::GetColour(wxSYS_COLOUR_LISTBOX
);
5504 attr
.font
= wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT
);
5509 // ----------------------------------------------------------------------------
5510 // methods forwarded to m_mainWin
5511 // ----------------------------------------------------------------------------
5513 #if wxUSE_DRAG_AND_DROP
5515 void wxGenericListCtrl::SetDropTarget( wxDropTarget
*dropTarget
)
5517 m_mainWin
->SetDropTarget( dropTarget
);
5520 wxDropTarget
*wxGenericListCtrl::GetDropTarget() const
5522 return m_mainWin
->GetDropTarget();
5525 #endif // wxUSE_DRAG_AND_DROP
5527 bool wxGenericListCtrl::SetCursor( const wxCursor
&cursor
)
5529 return m_mainWin
? m_mainWin
->wxWindow::SetCursor(cursor
) : false;
5532 wxColour
wxGenericListCtrl::GetBackgroundColour() const
5534 return m_mainWin
? m_mainWin
->GetBackgroundColour() : wxColour();
5537 wxColour
wxGenericListCtrl::GetForegroundColour() const
5539 return m_mainWin
? m_mainWin
->GetForegroundColour() : wxColour();
5542 bool wxGenericListCtrl::DoPopupMenu( wxMenu
*menu
, int x
, int y
)
5545 return m_mainWin
->PopupMenu( menu
, x
, y
);
5548 #endif // wxUSE_MENUS
5551 void wxGenericListCtrl::SetFocus()
5553 /* The test in window.cpp fails as we are a composite
5554 window, so it checks against "this", but not m_mainWin. */
5555 if ( DoFindFocus() != this )
5556 m_mainWin
->SetFocus();
5559 wxSize
wxGenericListCtrl::DoGetBestSize() const
5561 // Something is better than nothing...
5562 // 100x80 is what the MSW version will get from the default
5563 // wxControl::DoGetBestSize
5564 return wxSize(100,80);
5567 // ----------------------------------------------------------------------------
5568 // virtual list control support
5569 // ----------------------------------------------------------------------------
5571 wxString
wxGenericListCtrl::OnGetItemText(long WXUNUSED(item
), long WXUNUSED(col
)) const
5573 // this is a pure virtual function, in fact - which is not really pure
5574 // because the controls which are not virtual don't need to implement it
5575 wxFAIL_MSG( _T("wxGenericListCtrl::OnGetItemText not supposed to be called") );
5577 return wxEmptyString
;
5580 int wxGenericListCtrl::OnGetItemImage(long WXUNUSED(item
)) const
5582 wxCHECK_MSG(!GetImageList(wxIMAGE_LIST_SMALL
),
5584 wxT("List control has an image list, OnGetItemImage should be overridden."));
5589 wxGenericListCtrl::OnGetItemAttr(long WXUNUSED_UNLESS_DEBUG(item
)) const
5591 wxASSERT_MSG( item
>= 0 && item
< GetItemCount(),
5592 _T("invalid item index in OnGetItemAttr()") );
5594 // no attributes by default
5598 void wxGenericListCtrl::SetItemCount(long count
)
5600 wxASSERT_MSG( IsVirtual(), _T("this is for virtual controls only") );
5602 m_mainWin
->SetItemCount(count
);
5605 void wxGenericListCtrl::RefreshItem(long item
)
5607 m_mainWin
->RefreshLine(item
);
5610 void wxGenericListCtrl::RefreshItems(long itemFrom
, long itemTo
)
5612 m_mainWin
->RefreshLines(itemFrom
, itemTo
);
5616 * Generic wxListCtrl is more or less a container for two other
5617 * windows which drawings are done upon. These are namely
5618 * 'm_headerWin' and 'm_mainWin'.
5619 * Here we override 'virtual wxWindow::Refresh()' to mimic the
5620 * behaviour wxListCtrl has under wxMSW.
5622 void wxGenericListCtrl::Refresh(bool eraseBackground
, const wxRect
*rect
)
5626 // The easy case, no rectangle specified.
5628 m_headerWin
->Refresh(eraseBackground
);
5631 m_mainWin
->Refresh(eraseBackground
);
5635 // Refresh the header window
5638 wxRect rectHeader
= m_headerWin
->GetRect();
5639 rectHeader
.Intersect(*rect
);
5640 if (rectHeader
.GetWidth() && rectHeader
.GetHeight())
5643 m_headerWin
->GetPosition(&x
, &y
);
5644 rectHeader
.Offset(-x
, -y
);
5645 m_headerWin
->Refresh(eraseBackground
, &rectHeader
);
5650 // Refresh the main window
5653 wxRect rectMain
= m_mainWin
->GetRect();
5654 rectMain
.Intersect(*rect
);
5655 if (rectMain
.GetWidth() && rectMain
.GetHeight())
5658 m_mainWin
->GetPosition(&x
, &y
);
5659 rectMain
.Offset(-x
, -y
);
5660 m_mainWin
->Refresh(eraseBackground
, &rectMain
);
5666 void wxGenericListCtrl::Freeze()
5668 m_mainWin
->Freeze();
5671 void wxGenericListCtrl::Thaw()
5676 #endif // wxUSE_LISTCTRL