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 and minimal widths for the header columns
141 static const int WIDTH_COL_DEFAULT
= 80;
142 static const int WIDTH_COL_MIN
= 10;
144 // the space between the image and the text in the report mode
145 static const int IMAGE_MARGIN_IN_REPORT_MODE
= 5;
147 // ============================================================================
149 // ============================================================================
151 //-----------------------------------------------------------------------------
152 // wxColWidthInfo (internal)
153 //-----------------------------------------------------------------------------
155 struct wxColWidthInfo
158 bool bNeedsUpdate
; // only set to true when an item whose
159 // width == nMaxWidth is removed
161 wxColWidthInfo(int w
= 0, bool needsUpdate
= false)
164 bNeedsUpdate
= needsUpdate
;
168 WX_DEFINE_ARRAY_PTR(wxColWidthInfo
*, ColWidthArray
);
170 //-----------------------------------------------------------------------------
171 // wxListItemData (internal)
172 //-----------------------------------------------------------------------------
174 class WXDLLEXPORT wxListItemData
177 wxListItemData(wxListMainWindow
*owner
);
180 void SetItem( const wxListItem
&info
);
181 void SetImage( int image
) { m_image
= image
; }
182 void SetData( wxUIntPtr data
) { m_data
= data
; }
183 void SetPosition( int x
, int y
);
184 void SetSize( int width
, int height
);
186 bool HasText() const { return !m_text
.empty(); }
187 const wxString
& GetText() const { return m_text
; }
188 void SetText(const wxString
& text
) { m_text
= text
; }
190 // we can't use empty string for measuring the string width/height, so
191 // always return something
192 wxString
GetTextForMeasuring() const
194 wxString s
= GetText();
201 bool IsHit( int x
, int y
) const;
205 int GetWidth() const;
206 int GetHeight() const;
208 int GetImage() const { return m_image
; }
209 bool HasImage() const { return GetImage() != -1; }
211 void GetItem( wxListItem
&info
) const;
213 void SetAttr(wxListItemAttr
*attr
) { m_attr
= attr
; }
214 wxListItemAttr
*GetAttr() const { return m_attr
; }
217 // the item image or -1
220 // user data associated with the item
223 // the item coordinates are not used in report mode, instead this pointer
224 // is NULL and the owner window is used to retrieve the item position and
228 // the list ctrl we are in
229 wxListMainWindow
*m_owner
;
231 // custom attributes or NULL
232 wxListItemAttr
*m_attr
;
235 // common part of all ctors
241 //-----------------------------------------------------------------------------
242 // wxListHeaderData (internal)
243 //-----------------------------------------------------------------------------
245 class WXDLLEXPORT wxListHeaderData
: public wxObject
249 wxListHeaderData( const wxListItem
&info
);
250 void SetItem( const wxListItem
&item
);
251 void SetPosition( int x
, int y
);
252 void SetWidth( int w
);
253 void SetFormat( int format
);
254 void SetHeight( int h
);
255 bool HasImage() const;
257 bool HasText() const { return !m_text
.empty(); }
258 const wxString
& GetText() const { return m_text
; }
259 void SetText(const wxString
& text
) { m_text
= text
; }
261 void GetItem( wxListItem
&item
);
263 bool IsHit( int x
, int y
) const;
264 int GetImage() const;
265 int GetWidth() const;
266 int GetFormat() const;
282 //-----------------------------------------------------------------------------
283 // wxListLineData (internal)
284 //-----------------------------------------------------------------------------
286 WX_DECLARE_LIST(wxListItemData
, wxListItemDataList
);
287 #include "wx/listimpl.cpp"
288 WX_DEFINE_LIST(wxListItemDataList
);
293 // the list of subitems: only may have more than one item in report mode
294 wxListItemDataList m_items
;
296 // this is not used in report view
308 // the part to be highlighted
309 wxRect m_rectHighlight
;
311 // extend all our rects to be centered inside the one of given width
312 void ExtendWidth(wxCoord w
)
314 wxASSERT_MSG( m_rectAll
.width
<= w
,
315 _T("width can only be increased") );
318 m_rectLabel
.x
= m_rectAll
.x
+ (w
- m_rectLabel
.width
)/2;
319 m_rectIcon
.x
= m_rectAll
.x
+ (w
- m_rectIcon
.width
)/2;
320 m_rectHighlight
.x
= m_rectAll
.x
+ (w
- m_rectHighlight
.width
)/2;
324 // is this item selected? [NB: not used in virtual mode]
327 // back pointer to the list ctrl
328 wxListMainWindow
*m_owner
;
331 wxListLineData(wxListMainWindow
*owner
);
335 WX_CLEAR_LIST(wxListItemDataList
, m_items
);
339 // are we in report mode?
340 inline bool InReportView() const;
342 // are we in virtual report mode?
343 inline bool IsVirtual() const;
345 // these 2 methods shouldn't be called for report view controls, in that
346 // case we determine our position/size ourselves
348 // calculate the size of the line
349 void CalculateSize( wxDC
*dc
, int spacing
);
351 // remember the position this line appears at
352 void SetPosition( int x
, int y
, int spacing
);
356 void SetImage( int image
) { SetImage(0, image
); }
357 int GetImage() const { return GetImage(0); }
358 bool HasImage() const { return GetImage() != -1; }
359 bool HasText() const { return !GetText(0).empty(); }
361 void SetItem( int index
, const wxListItem
&info
);
362 void GetItem( int index
, wxListItem
&info
);
364 wxString
GetText(int index
) const;
365 void SetText( int index
, const wxString s
);
367 wxListItemAttr
*GetAttr() const;
368 void SetAttr(wxListItemAttr
*attr
);
370 // return true if the highlighting really changed
371 bool Highlight( bool on
);
373 void ReverseHighlight();
375 bool IsHighlighted() const
377 wxASSERT_MSG( !IsVirtual(), _T("unexpected call to IsHighlighted") );
379 return m_highlighted
;
382 // draw the line on the given DC in icon/list mode
383 void Draw( wxDC
*dc
);
385 // the same in report mode
386 void DrawInReportMode( wxDC
*dc
,
388 const wxRect
& rectHL
,
392 // set the line to contain num items (only can be > 1 in report mode)
393 void InitItems( int num
);
395 // get the mode (i.e. style) of the list control
396 inline int GetMode() const;
398 // prepare the DC for drawing with these item's attributes, return true if
399 // we need to draw the items background to highlight it, false otherwise
400 bool SetAttributes(wxDC
*dc
,
401 const wxListItemAttr
*attr
,
404 // draw the text on the DC with the correct justification; also add an
405 // ellipsis if the text is too large to fit in the current width
406 void DrawTextFormatted(wxDC
*dc
, const wxString
&text
, int col
, int x
, int y
, int width
);
408 // these are only used by GetImage/SetImage above, we don't support images
409 // with subitems at the public API level yet
410 void SetImage( int index
, int image
);
411 int GetImage( int index
) const;
414 WX_DECLARE_EXPORTED_OBJARRAY(wxListLineData
, wxListLineDataArray
);
415 #include "wx/arrimpl.cpp"
416 WX_DEFINE_OBJARRAY(wxListLineDataArray
);
418 //-----------------------------------------------------------------------------
419 // wxListHeaderWindow (internal)
420 //-----------------------------------------------------------------------------
422 class WXDLLEXPORT wxListHeaderWindow
: public wxWindow
425 wxListMainWindow
*m_owner
;
426 wxCursor
*m_currentCursor
;
427 wxCursor
*m_resizeCursor
;
430 // column being resized or -1
433 // divider line position in logical (unscrolled) coords
436 // minimal position beyond which the divider line can't be dragged in
441 wxListHeaderWindow();
443 wxListHeaderWindow( wxWindow
*win
,
445 wxListMainWindow
*owner
,
446 const wxPoint
&pos
= wxDefaultPosition
,
447 const wxSize
&size
= wxDefaultSize
,
449 const wxString
&name
= wxT("wxlistctrlcolumntitles") );
451 virtual ~wxListHeaderWindow();
454 void AdjustDC(wxDC
& dc
);
456 void OnPaint( wxPaintEvent
&event
);
457 void OnMouse( wxMouseEvent
&event
);
458 void OnSetFocus( wxFocusEvent
&event
);
464 // common part of all ctors
467 // generate and process the list event of the given type, return true if
468 // it wasn't vetoed, i.e. if we should proceed
469 bool SendListEvent(wxEventType type
, wxPoint pos
);
471 DECLARE_DYNAMIC_CLASS(wxListHeaderWindow
)
472 DECLARE_EVENT_TABLE()
475 //-----------------------------------------------------------------------------
476 // wxListRenameTimer (internal)
477 //-----------------------------------------------------------------------------
479 class WXDLLEXPORT wxListRenameTimer
: public wxTimer
482 wxListMainWindow
*m_owner
;
485 wxListRenameTimer( wxListMainWindow
*owner
);
489 //-----------------------------------------------------------------------------
490 // wxListTextCtrl (internal)
491 //-----------------------------------------------------------------------------
493 class WXDLLEXPORT wxListTextCtrl
: public wxTextCtrl
496 wxListTextCtrl(wxListMainWindow
*owner
, size_t itemEdit
);
499 void OnChar( wxKeyEvent
&event
);
500 void OnKeyUp( wxKeyEvent
&event
);
501 void OnKillFocus( wxFocusEvent
&event
);
503 bool AcceptChanges();
507 wxListMainWindow
*m_owner
;
508 wxString m_startValue
;
511 bool m_aboutToFinish
;
513 DECLARE_EVENT_TABLE()
516 //-----------------------------------------------------------------------------
517 // wxListMainWindow (internal)
518 //-----------------------------------------------------------------------------
520 WX_DECLARE_LIST(wxListHeaderData
, wxListHeaderDataList
);
521 #include "wx/listimpl.cpp"
522 WX_DEFINE_LIST(wxListHeaderDataList
);
524 class wxListMainWindow
: public wxScrolledWindow
528 wxListMainWindow( wxWindow
*parent
,
530 const wxPoint
& pos
= wxDefaultPosition
,
531 const wxSize
& size
= wxDefaultSize
,
533 const wxString
&name
= _T("listctrlmainwindow") );
535 virtual ~wxListMainWindow();
537 wxWindow
*GetMainWindowOfCompositeControl() { return GetParent(); }
539 bool HasFlag(int flag
) const { return m_parent
->HasFlag(flag
); }
541 // return true if this is a virtual list control
542 bool IsVirtual() const { return HasFlag(wxLC_VIRTUAL
); }
544 // return true if the control is in report mode
545 bool InReportView() const { return HasFlag(wxLC_REPORT
); }
547 // return true if we are in single selection mode, false if multi sel
548 bool IsSingleSel() const { return HasFlag(wxLC_SINGLE_SEL
); }
550 // do we have a header window?
551 bool HasHeader() const
552 { return InReportView() && !HasFlag(wxLC_NO_HEADER
); }
554 void HighlightAll( bool on
);
556 // all these functions only do something if the line is currently visible
558 // change the line "selected" state, return true if it really changed
559 bool HighlightLine( size_t line
, bool highlight
= true);
561 // as HighlightLine() but do it for the range of lines: this is incredibly
562 // more efficient for virtual list controls!
564 // NB: unlike HighlightLine() this one does refresh the lines on screen
565 void HighlightLines( size_t lineFrom
, size_t lineTo
, bool on
= true );
567 // toggle the line state and refresh it
568 void ReverseHighlight( size_t line
)
569 { HighlightLine(line
, !IsHighlighted(line
)); RefreshLine(line
); }
571 // return true if the line is highlighted
572 bool IsHighlighted(size_t line
) const;
574 // refresh one or several lines at once
575 void RefreshLine( size_t line
);
576 void RefreshLines( size_t lineFrom
, size_t lineTo
);
578 // refresh all selected items
579 void RefreshSelected();
581 // refresh all lines below the given one: the difference with
582 // RefreshLines() is that the index here might not be a valid one (happens
583 // when the last line is deleted)
584 void RefreshAfter( size_t lineFrom
);
586 // the methods which are forwarded to wxListLineData itself in list/icon
587 // modes but are here because the lines don't store their positions in the
590 // get the bound rect for the entire line
591 wxRect
GetLineRect(size_t line
) const;
593 // get the bound rect of the label
594 wxRect
GetLineLabelRect(size_t line
) const;
596 // get the bound rect of the items icon (only may be called if we do have
598 wxRect
GetLineIconRect(size_t line
) const;
600 // get the rect to be highlighted when the item has focus
601 wxRect
GetLineHighlightRect(size_t line
) const;
603 // get the size of the total line rect
604 wxSize
GetLineSize(size_t line
) const
605 { return GetLineRect(line
).GetSize(); }
607 // return the hit code for the corresponding position (in this line)
608 long HitTestLine(size_t line
, int x
, int y
) const;
610 // bring the selected item into view, scrolling to it if necessary
611 void MoveToItem(size_t item
);
613 // bring the current item into view
614 void MoveToFocus() { MoveToItem(m_current
); }
616 // start editing the label of the given item
617 void EditLabel( long item
);
619 // suspend/resume redrawing the control
623 void OnRenameTimer();
624 bool OnRenameAccept(size_t itemEdit
, const wxString
& value
);
625 void OnRenameCancelled(size_t itemEdit
);
627 void OnMouse( wxMouseEvent
&event
);
629 // called to switch the selection from the current item to newCurrent,
630 void OnArrowChar( size_t newCurrent
, const wxKeyEvent
& event
);
632 void OnChar( wxKeyEvent
&event
);
633 void OnKeyDown( wxKeyEvent
&event
);
634 void OnSetFocus( wxFocusEvent
&event
);
635 void OnKillFocus( wxFocusEvent
&event
);
636 void OnScroll(wxScrollWinEvent
& event
) ;
638 void OnPaint( wxPaintEvent
&event
);
640 void DrawImage( int index
, wxDC
*dc
, int x
, int y
);
641 void GetImageSize( int index
, int &width
, int &height
) const;
642 int GetTextLength( const wxString
&s
) const;
644 void SetImageList( wxImageListType
*imageList
, int which
);
645 void SetItemSpacing( int spacing
, bool isSmall
= false );
646 int GetItemSpacing( bool isSmall
= false );
648 void SetColumn( int col
, wxListItem
&item
);
649 void SetColumnWidth( int col
, int width
);
650 void GetColumn( int col
, wxListItem
&item
) const;
651 int GetColumnWidth( int col
) const;
652 int GetColumnCount() const { return m_columns
.GetCount(); }
654 // returns the sum of the heights of all columns
655 int GetHeaderWidth() const;
657 int GetCountPerPage() const;
659 void SetItem( wxListItem
&item
);
660 void GetItem( wxListItem
&item
) const;
661 void SetItemState( long item
, long state
, long stateMask
);
662 void SetItemStateAll( long state
, long stateMask
);
663 int GetItemState( long item
, long stateMask
) const;
664 void GetItemRect( long index
, wxRect
&rect
) const;
665 wxRect
GetViewRect() const;
666 bool GetItemPosition( long item
, wxPoint
& pos
) const;
667 int GetSelectedItemCount() const;
669 wxString
GetItemText(long item
) const
672 info
.m_mask
= wxLIST_MASK_TEXT
;
673 info
.m_itemId
= item
;
678 void SetItemText(long item
, const wxString
& value
)
681 info
.m_mask
= wxLIST_MASK_TEXT
;
682 info
.m_itemId
= item
;
687 // set the scrollbars and update the positions of the items
688 void RecalculatePositions(bool noRefresh
= false);
690 // refresh the window and the header
693 long GetNextItem( long item
, int geometry
, int state
) const;
694 void DeleteItem( long index
);
695 void DeleteAllItems();
696 void DeleteColumn( int col
);
697 void DeleteEverything();
698 void EnsureVisible( long index
);
699 long FindItem( long start
, const wxString
& str
, bool partial
= false );
700 long FindItem( long start
, wxUIntPtr data
);
701 long FindItem( const wxPoint
& pt
);
702 long HitTest( int x
, int y
, int &flags
);
703 void InsertItem( wxListItem
&item
);
704 void InsertColumn( long col
, wxListItem
&item
);
705 int GetItemWidthWithImage(wxListItem
* item
);
706 void SortItems( wxListCtrlCompare fn
, long data
);
708 size_t GetItemCount() const;
709 bool IsEmpty() const { return GetItemCount() == 0; }
710 void SetItemCount(long count
);
712 // change the current (== focused) item, send a notification event
713 void ChangeCurrent(size_t current
);
714 void ResetCurrent() { ChangeCurrent((size_t)-1); }
715 bool HasCurrent() const { return m_current
!= (size_t)-1; }
717 // send out a wxListEvent
718 void SendNotify( size_t line
,
720 wxPoint point
= wxDefaultPosition
);
722 // override base class virtual to reset m_lineHeight when the font changes
723 virtual bool SetFont(const wxFont
& font
)
725 if ( !wxScrolledWindow::SetFont(font
) )
733 // these are for wxListLineData usage only
735 // get the backpointer to the list ctrl
736 wxGenericListCtrl
*GetListCtrl() const
738 return wxStaticCast(GetParent(), wxGenericListCtrl
);
741 // get the height of all lines (assuming they all do have the same height)
742 wxCoord
GetLineHeight() const;
744 // get the y position of the given line (only for report view)
745 wxCoord
GetLineY(size_t line
) const;
747 // get the brush to use for the item highlighting
748 wxBrush
*GetHighlightBrush() const
750 return m_hasFocus
? m_highlightBrush
: m_highlightUnfocusedBrush
;
754 // the array of all line objects for a non virtual list control (for the
755 // virtual list control we only ever use m_lines[0])
756 wxListLineDataArray m_lines
;
758 // the list of column objects
759 wxListHeaderDataList m_columns
;
761 // currently focused item or -1
764 // the number of lines per page
767 // this flag is set when something which should result in the window
768 // redrawing happens (i.e. an item was added or deleted, or its appearance
769 // changed) and OnPaint() doesn't redraw the window while it is set which
770 // allows to minimize the number of repaintings when a lot of items are
771 // being added. The real repainting occurs only after the next OnIdle()
775 wxColour
*m_highlightColour
;
776 wxImageListType
*m_small_image_list
;
777 wxImageListType
*m_normal_image_list
;
779 int m_normal_spacing
;
783 wxTimer
*m_renameTimer
;
787 ColWidthArray m_aColWidths
;
789 // for double click logic
790 size_t m_lineLastClicked
,
791 m_lineBeforeLastClicked
,
792 m_lineSelectSingleOnUp
;
795 // the total count of items in a virtual list control
798 // the object maintaining the items selection state, only used in virtual
800 wxSelectionStore m_selStore
;
802 // common part of all ctors
805 // get the line data for the given index
806 wxListLineData
*GetLine(size_t n
) const
808 wxASSERT_MSG( n
!= (size_t)-1, _T("invalid line index") );
812 wxConstCast(this, wxListMainWindow
)->CacheLineData(n
);
820 // get a dummy line which can be used for geometry calculations and such:
821 // you must use GetLine() if you want to really draw the line
822 wxListLineData
*GetDummyLine() const;
824 // cache the line data of the n-th line in m_lines[0]
825 void CacheLineData(size_t line
);
827 // get the range of visible lines
828 void GetVisibleLinesRange(size_t *from
, size_t *to
);
830 // force us to recalculate the range of visible lines
831 void ResetVisibleLinesRange() { m_lineFrom
= (size_t)-1; }
833 // get the colour to be used for drawing the rules
834 wxColour
GetRuleColour() const
836 return wxSystemSettings::GetColour(wxSYS_COLOUR_3DLIGHT
);
840 // initialize the current item if needed
841 void UpdateCurrent();
843 // delete all items but don't refresh: called from dtor
844 void DoDeleteAllItems();
846 // the height of one line using the current font
847 wxCoord m_lineHeight
;
849 // the total header width or 0 if not calculated yet
850 wxCoord m_headerWidth
;
852 // the first and last lines being shown on screen right now (inclusive),
853 // both may be -1 if they must be calculated so never access them directly:
854 // use GetVisibleLinesRange() above instead
858 // the brushes to use for item highlighting when we do/don't have focus
859 wxBrush
*m_highlightBrush
,
860 *m_highlightUnfocusedBrush
;
862 // if this is > 0, the control is frozen and doesn't redraw itself
863 size_t m_freezeCount
;
865 DECLARE_DYNAMIC_CLASS(wxListMainWindow
)
866 DECLARE_EVENT_TABLE()
868 friend class wxGenericListCtrl
;
871 // ============================================================================
873 // ============================================================================
875 //-----------------------------------------------------------------------------
877 //-----------------------------------------------------------------------------
879 wxListItemData::~wxListItemData()
881 // in the virtual list control the attributes are managed by the main
882 // program, so don't delete them
883 if ( !m_owner
->IsVirtual() )
891 void wxListItemData::Init()
899 wxListItemData::wxListItemData(wxListMainWindow
*owner
)
905 if ( owner
->InReportView() )
915 void wxListItemData::SetItem( const wxListItem
&info
)
917 if ( info
.m_mask
& wxLIST_MASK_TEXT
)
918 SetText(info
.m_text
);
919 if ( info
.m_mask
& wxLIST_MASK_IMAGE
)
920 m_image
= info
.m_image
;
921 if ( info
.m_mask
& wxLIST_MASK_DATA
)
922 m_data
= info
.m_data
;
924 if ( info
.HasAttributes() )
927 *m_attr
= *info
.GetAttributes();
929 m_attr
= new wxListItemAttr(*info
.GetAttributes());
937 m_rect
->width
= info
.m_width
;
941 void wxListItemData::SetPosition( int x
, int y
)
943 wxCHECK_RET( m_rect
, _T("unexpected SetPosition() call") );
949 void wxListItemData::SetSize( int width
, int height
)
951 wxCHECK_RET( m_rect
, _T("unexpected SetSize() call") );
954 m_rect
->width
= width
;
956 m_rect
->height
= height
;
959 bool wxListItemData::IsHit( int x
, int y
) const
961 wxCHECK_MSG( m_rect
, false, _T("can't be called in this mode") );
963 return wxRect(GetX(), GetY(), GetWidth(), GetHeight()).Inside(x
, y
);
966 int wxListItemData::GetX() const
968 wxCHECK_MSG( m_rect
, 0, _T("can't be called in this mode") );
973 int wxListItemData::GetY() const
975 wxCHECK_MSG( m_rect
, 0, _T("can't be called in this mode") );
980 int wxListItemData::GetWidth() const
982 wxCHECK_MSG( m_rect
, 0, _T("can't be called in this mode") );
984 return m_rect
->width
;
987 int wxListItemData::GetHeight() const
989 wxCHECK_MSG( m_rect
, 0, _T("can't be called in this mode") );
991 return m_rect
->height
;
994 void wxListItemData::GetItem( wxListItem
&info
) const
996 long mask
= info
.m_mask
;
999 // by default, get everything for backwards compatibility
1003 if ( mask
& wxLIST_MASK_TEXT
)
1004 info
.m_text
= m_text
;
1005 if ( mask
& wxLIST_MASK_IMAGE
)
1006 info
.m_image
= m_image
;
1007 if ( mask
& wxLIST_MASK_DATA
)
1008 info
.m_data
= m_data
;
1012 if ( m_attr
->HasTextColour() )
1013 info
.SetTextColour(m_attr
->GetTextColour());
1014 if ( m_attr
->HasBackgroundColour() )
1015 info
.SetBackgroundColour(m_attr
->GetBackgroundColour());
1016 if ( m_attr
->HasFont() )
1017 info
.SetFont(m_attr
->GetFont());
1021 //-----------------------------------------------------------------------------
1023 //-----------------------------------------------------------------------------
1025 void wxListHeaderData::Init()
1036 wxListHeaderData::wxListHeaderData()
1041 wxListHeaderData::wxListHeaderData( const wxListItem
&item
)
1048 void wxListHeaderData::SetItem( const wxListItem
&item
)
1050 m_mask
= item
.m_mask
;
1052 if ( m_mask
& wxLIST_MASK_TEXT
)
1053 m_text
= item
.m_text
;
1055 if ( m_mask
& wxLIST_MASK_IMAGE
)
1056 m_image
= item
.m_image
;
1058 if ( m_mask
& wxLIST_MASK_FORMAT
)
1059 m_format
= item
.m_format
;
1061 if ( m_mask
& wxLIST_MASK_WIDTH
)
1062 SetWidth(item
.m_width
);
1065 void wxListHeaderData::SetPosition( int x
, int y
)
1071 void wxListHeaderData::SetHeight( int h
)
1076 void wxListHeaderData::SetWidth( int w
)
1080 m_width
= WIDTH_COL_DEFAULT
;
1081 else if (m_width
< WIDTH_COL_MIN
)
1082 m_width
= WIDTH_COL_MIN
;
1085 void wxListHeaderData::SetFormat( int format
)
1090 bool wxListHeaderData::HasImage() const
1092 return m_image
!= -1;
1095 bool wxListHeaderData::IsHit( int x
, int y
) const
1097 return ((x
>= m_xpos
) && (x
<= m_xpos
+m_width
) && (y
>= m_ypos
) && (y
<= m_ypos
+m_height
));
1100 void wxListHeaderData::GetItem( wxListItem
& item
)
1102 item
.m_mask
= m_mask
;
1103 item
.m_text
= m_text
;
1104 item
.m_image
= m_image
;
1105 item
.m_format
= m_format
;
1106 item
.m_width
= m_width
;
1109 int wxListHeaderData::GetImage() const
1114 int wxListHeaderData::GetWidth() const
1119 int wxListHeaderData::GetFormat() const
1124 //-----------------------------------------------------------------------------
1126 //-----------------------------------------------------------------------------
1128 inline int wxListLineData::GetMode() const
1130 return m_owner
->GetListCtrl()->GetWindowStyleFlag() & wxLC_MASK_TYPE
;
1133 inline bool wxListLineData::InReportView() const
1135 return m_owner
->HasFlag(wxLC_REPORT
);
1138 inline bool wxListLineData::IsVirtual() const
1140 return m_owner
->IsVirtual();
1143 wxListLineData::wxListLineData( wxListMainWindow
*owner
)
1147 if ( InReportView() )
1153 m_gi
= new GeometryInfo
;
1156 m_highlighted
= false;
1158 InitItems( GetMode() == wxLC_REPORT
? m_owner
->GetColumnCount() : 1 );
1161 void wxListLineData::CalculateSize( wxDC
*dc
, int spacing
)
1163 wxListItemDataList::compatibility_iterator node
= m_items
.GetFirst();
1164 wxCHECK_RET( node
, _T("no subitems at all??") );
1166 wxListItemData
*item
= node
->GetData();
1171 switch ( GetMode() )
1174 case wxLC_SMALL_ICON
:
1175 m_gi
->m_rectAll
.width
= spacing
;
1177 s
= item
->GetText();
1182 m_gi
->m_rectLabel
.width
=
1183 m_gi
->m_rectLabel
.height
= 0;
1187 dc
->GetTextExtent( s
, &lw
, &lh
);
1191 m_gi
->m_rectAll
.height
= spacing
+ lh
;
1193 m_gi
->m_rectAll
.width
= lw
;
1195 m_gi
->m_rectLabel
.width
= lw
;
1196 m_gi
->m_rectLabel
.height
= lh
;
1199 if (item
->HasImage())
1202 m_owner
->GetImageSize( item
->GetImage(), w
, h
);
1203 m_gi
->m_rectIcon
.width
= w
+ 8;
1204 m_gi
->m_rectIcon
.height
= h
+ 8;
1206 if ( m_gi
->m_rectIcon
.width
> m_gi
->m_rectAll
.width
)
1207 m_gi
->m_rectAll
.width
= m_gi
->m_rectIcon
.width
;
1208 if ( m_gi
->m_rectIcon
.height
+ lh
> m_gi
->m_rectAll
.height
- 4 )
1209 m_gi
->m_rectAll
.height
= m_gi
->m_rectIcon
.height
+ lh
+ 4;
1212 if ( item
->HasText() )
1214 m_gi
->m_rectHighlight
.width
= m_gi
->m_rectLabel
.width
;
1215 m_gi
->m_rectHighlight
.height
= m_gi
->m_rectLabel
.height
;
1217 else // no text, highlight the icon
1219 m_gi
->m_rectHighlight
.width
= m_gi
->m_rectIcon
.width
;
1220 m_gi
->m_rectHighlight
.height
= m_gi
->m_rectIcon
.height
;
1225 s
= item
->GetTextForMeasuring();
1227 dc
->GetTextExtent( s
, &lw
, &lh
);
1231 m_gi
->m_rectLabel
.width
= lw
;
1232 m_gi
->m_rectLabel
.height
= lh
;
1234 m_gi
->m_rectAll
.width
= lw
;
1235 m_gi
->m_rectAll
.height
= lh
;
1237 if (item
->HasImage())
1240 m_owner
->GetImageSize( item
->GetImage(), w
, h
);
1241 m_gi
->m_rectIcon
.width
= w
;
1242 m_gi
->m_rectIcon
.height
= h
;
1244 m_gi
->m_rectAll
.width
+= 4 + w
;
1245 if (h
> m_gi
->m_rectAll
.height
)
1246 m_gi
->m_rectAll
.height
= h
;
1249 m_gi
->m_rectHighlight
.width
= m_gi
->m_rectAll
.width
;
1250 m_gi
->m_rectHighlight
.height
= m_gi
->m_rectAll
.height
;
1254 wxFAIL_MSG( _T("unexpected call to SetSize") );
1258 wxFAIL_MSG( _T("unknown mode") );
1262 void wxListLineData::SetPosition( int x
, int y
, int spacing
)
1264 wxListItemDataList::compatibility_iterator node
= m_items
.GetFirst();
1265 wxCHECK_RET( node
, _T("no subitems at all??") );
1267 wxListItemData
*item
= node
->GetData();
1269 switch ( GetMode() )
1272 case wxLC_SMALL_ICON
:
1273 m_gi
->m_rectAll
.x
= x
;
1274 m_gi
->m_rectAll
.y
= y
;
1276 if ( item
->HasImage() )
1278 m_gi
->m_rectIcon
.x
= m_gi
->m_rectAll
.x
+ 4 +
1279 (m_gi
->m_rectAll
.width
- m_gi
->m_rectIcon
.width
) / 2;
1280 m_gi
->m_rectIcon
.y
= m_gi
->m_rectAll
.y
+ 4;
1283 if ( item
->HasText() )
1285 if (m_gi
->m_rectAll
.width
> spacing
)
1286 m_gi
->m_rectLabel
.x
= m_gi
->m_rectAll
.x
+ 2;
1288 m_gi
->m_rectLabel
.x
= m_gi
->m_rectAll
.x
+ 2 + (spacing
/2) - (m_gi
->m_rectLabel
.width
/2);
1289 m_gi
->m_rectLabel
.y
= m_gi
->m_rectAll
.y
+ m_gi
->m_rectAll
.height
+ 2 - m_gi
->m_rectLabel
.height
;
1290 m_gi
->m_rectHighlight
.x
= m_gi
->m_rectLabel
.x
- 2;
1291 m_gi
->m_rectHighlight
.y
= m_gi
->m_rectLabel
.y
- 2;
1293 else // no text, highlight the icon
1295 m_gi
->m_rectHighlight
.x
= m_gi
->m_rectIcon
.x
- 4;
1296 m_gi
->m_rectHighlight
.y
= m_gi
->m_rectIcon
.y
- 4;
1301 m_gi
->m_rectAll
.x
= x
;
1302 m_gi
->m_rectAll
.y
= y
;
1304 m_gi
->m_rectHighlight
.x
= m_gi
->m_rectAll
.x
;
1305 m_gi
->m_rectHighlight
.y
= m_gi
->m_rectAll
.y
;
1306 m_gi
->m_rectLabel
.y
= m_gi
->m_rectAll
.y
+ 2;
1308 if (item
->HasImage())
1310 m_gi
->m_rectIcon
.x
= m_gi
->m_rectAll
.x
+ 2;
1311 m_gi
->m_rectIcon
.y
= m_gi
->m_rectAll
.y
+ 2;
1312 m_gi
->m_rectLabel
.x
= m_gi
->m_rectAll
.x
+ 6 + m_gi
->m_rectIcon
.width
;
1316 m_gi
->m_rectLabel
.x
= m_gi
->m_rectAll
.x
+ 2;
1321 wxFAIL_MSG( _T("unexpected call to SetPosition") );
1325 wxFAIL_MSG( _T("unknown mode") );
1329 void wxListLineData::InitItems( int num
)
1331 for (int i
= 0; i
< num
; i
++)
1332 m_items
.Append( new wxListItemData(m_owner
) );
1335 void wxListLineData::SetItem( int index
, const wxListItem
&info
)
1337 wxListItemDataList::compatibility_iterator node
= m_items
.Item( index
);
1338 wxCHECK_RET( node
, _T("invalid column index in SetItem") );
1340 wxListItemData
*item
= node
->GetData();
1341 item
->SetItem( info
);
1344 void wxListLineData::GetItem( int index
, wxListItem
&info
)
1346 wxListItemDataList::compatibility_iterator node
= m_items
.Item( index
);
1349 wxListItemData
*item
= node
->GetData();
1350 item
->GetItem( info
);
1354 wxString
wxListLineData::GetText(int index
) const
1358 wxListItemDataList::compatibility_iterator node
= m_items
.Item( index
);
1361 wxListItemData
*item
= node
->GetData();
1362 s
= item
->GetText();
1368 void wxListLineData::SetText( int index
, const wxString s
)
1370 wxListItemDataList::compatibility_iterator node
= m_items
.Item( index
);
1373 wxListItemData
*item
= node
->GetData();
1378 void wxListLineData::SetImage( int index
, int image
)
1380 wxListItemDataList::compatibility_iterator node
= m_items
.Item( index
);
1381 wxCHECK_RET( node
, _T("invalid column index in SetImage()") );
1383 wxListItemData
*item
= node
->GetData();
1384 item
->SetImage(image
);
1387 int wxListLineData::GetImage( int index
) const
1389 wxListItemDataList::compatibility_iterator node
= m_items
.Item( index
);
1390 wxCHECK_MSG( node
, -1, _T("invalid column index in GetImage()") );
1392 wxListItemData
*item
= node
->GetData();
1393 return item
->GetImage();
1396 wxListItemAttr
*wxListLineData::GetAttr() const
1398 wxListItemDataList::compatibility_iterator node
= m_items
.GetFirst();
1399 wxCHECK_MSG( node
, NULL
, _T("invalid column index in GetAttr()") );
1401 wxListItemData
*item
= node
->GetData();
1402 return item
->GetAttr();
1405 void wxListLineData::SetAttr(wxListItemAttr
*attr
)
1407 wxListItemDataList::compatibility_iterator node
= m_items
.GetFirst();
1408 wxCHECK_RET( node
, _T("invalid column index in SetAttr()") );
1410 wxListItemData
*item
= node
->GetData();
1411 item
->SetAttr(attr
);
1414 bool wxListLineData::SetAttributes(wxDC
*dc
,
1415 const wxListItemAttr
*attr
,
1418 wxWindow
*listctrl
= m_owner
->GetParent();
1422 // don't use foreground colour for drawing highlighted items - this might
1423 // make them completely invisible (and there is no way to do bit
1424 // arithmetics on wxColour, unfortunately)
1428 colText
= wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHTTEXT
);
1432 if ( attr
&& attr
->HasTextColour() )
1434 colText
= attr
->GetTextColour();
1438 colText
= listctrl
->GetForegroundColour();
1442 dc
->SetTextForeground(colText
);
1446 if ( attr
&& attr
->HasFont() )
1448 font
= attr
->GetFont();
1452 font
= listctrl
->GetFont();
1458 bool hasBgCol
= attr
&& attr
->HasBackgroundColour();
1459 if ( highlighted
|| hasBgCol
)
1463 dc
->SetBrush( *m_owner
->GetHighlightBrush() );
1467 dc
->SetBrush(wxBrush(attr
->GetBackgroundColour(), wxSOLID
));
1470 dc
->SetPen( *wxTRANSPARENT_PEN
);
1478 void wxListLineData::Draw( wxDC
*dc
)
1480 wxListItemDataList::compatibility_iterator node
= m_items
.GetFirst();
1481 wxCHECK_RET( node
, _T("no subitems at all??") );
1483 bool highlighted
= IsHighlighted();
1485 wxListItemAttr
*attr
= GetAttr();
1487 if ( SetAttributes(dc
, attr
, highlighted
) )
1489 dc
->DrawRectangle( m_gi
->m_rectHighlight
);
1492 // just for debugging to better see where the items are
1494 dc
->SetPen(*wxRED_PEN
);
1495 dc
->SetBrush(*wxTRANSPARENT_BRUSH
);
1496 dc
->DrawRectangle( m_gi
->m_rectAll
);
1497 dc
->SetPen(*wxGREEN_PEN
);
1498 dc
->DrawRectangle( m_gi
->m_rectIcon
);
1501 wxListItemData
*item
= node
->GetData();
1502 if (item
->HasImage())
1504 // centre the image inside our rectangle, this looks nicer when items
1505 // ae aligned in a row
1506 const wxRect
& rectIcon
= m_gi
->m_rectIcon
;
1508 m_owner
->DrawImage(item
->GetImage(), dc
, rectIcon
.x
, rectIcon
.y
);
1511 if (item
->HasText())
1513 const wxRect
& rectLabel
= m_gi
->m_rectLabel
;
1515 wxDCClipper
clipper(*dc
, rectLabel
);
1516 dc
->DrawText(item
->GetText(), rectLabel
.x
, rectLabel
.y
);
1520 void wxListLineData::DrawInReportMode( wxDC
*dc
,
1522 const wxRect
& rectHL
,
1525 // TODO: later we should support setting different attributes for
1526 // different columns - to do it, just add "col" argument to
1527 // GetAttr() and move these lines into the loop below
1528 wxListItemAttr
*attr
= GetAttr();
1529 if ( SetAttributes(dc
, attr
, highlighted
) )
1531 dc
->DrawRectangle( rectHL
);
1534 wxCoord x
= rect
.x
+ HEADER_OFFSET_X
,
1535 y
= rect
.y
+ (LINE_SPACING
+ EXTRA_HEIGHT
) / 2;
1538 for ( wxListItemDataList::compatibility_iterator node
= m_items
.GetFirst();
1540 node
= node
->GetNext(), col
++ )
1542 wxListItemData
*item
= node
->GetData();
1544 int width
= m_owner
->GetColumnWidth(col
);
1548 if ( item
->HasImage() )
1551 m_owner
->DrawImage( item
->GetImage(), dc
, xOld
, y
);
1552 m_owner
->GetImageSize( item
->GetImage(), ix
, iy
);
1554 ix
+= IMAGE_MARGIN_IN_REPORT_MODE
;
1560 wxDCClipper
clipper(*dc
, xOld
, y
, width
- 8, rect
.height
);
1562 if ( item
->HasText() )
1564 DrawTextFormatted(dc
, item
->GetText(), col
, xOld
, y
, width
- 8);
1569 void wxListLineData::DrawTextFormatted(wxDC
*dc
,
1570 const wxString
&text
,
1576 wxString drawntext
, ellipsis
;
1577 wxCoord w
, h
, base_w
;
1580 // determine if the string can fit inside the current width
1581 dc
->GetTextExtent(text
, &w
, &h
);
1584 // it can, draw it using the items alignment
1585 m_owner
->GetColumn(col
, item
);
1586 switch ( item
.GetAlign() )
1589 wxFAIL_MSG( _T("unknown list item format") );
1592 case wxLIST_FORMAT_LEFT
:
1596 case wxLIST_FORMAT_RIGHT
:
1600 case wxLIST_FORMAT_CENTER
:
1601 x
+= (width
- w
) / 2;
1605 dc
->DrawText(text
, x
, y
);
1607 else // otherwise, truncate and add an ellipsis if possible
1609 // determine the base width
1610 ellipsis
= wxString(wxT("..."));
1611 dc
->GetTextExtent(ellipsis
, &base_w
, &h
);
1613 // continue until we have enough space or only one character left
1615 size_t len
= text
.Length();
1616 drawntext
= text
.Left(len
);
1619 dc
->GetTextExtent(drawntext
.Last(), &w_c
, &h_c
);
1620 drawntext
.RemoveLast();
1623 if (w
+ base_w
<= width
)
1627 // if still not enough space, remove ellipsis characters
1628 while (ellipsis
.Length() > 0 && w
+ base_w
> width
)
1630 ellipsis
= ellipsis
.Left(ellipsis
.Length() - 1);
1631 dc
->GetTextExtent(ellipsis
, &base_w
, &h
);
1634 // now draw the text
1635 dc
->DrawText(drawntext
, x
, y
);
1636 dc
->DrawText(ellipsis
, x
+ w
, y
);
1640 bool wxListLineData::Highlight( bool on
)
1642 wxCHECK_MSG( !IsVirtual(), false, _T("unexpected call to Highlight") );
1644 if ( on
== m_highlighted
)
1652 void wxListLineData::ReverseHighlight( void )
1654 Highlight(!IsHighlighted());
1657 //-----------------------------------------------------------------------------
1658 // wxListHeaderWindow
1659 //-----------------------------------------------------------------------------
1661 IMPLEMENT_DYNAMIC_CLASS(wxListHeaderWindow
,wxWindow
)
1663 BEGIN_EVENT_TABLE(wxListHeaderWindow
,wxWindow
)
1664 EVT_PAINT (wxListHeaderWindow::OnPaint
)
1665 EVT_MOUSE_EVENTS (wxListHeaderWindow::OnMouse
)
1666 EVT_SET_FOCUS (wxListHeaderWindow::OnSetFocus
)
1669 void wxListHeaderWindow::Init()
1671 m_currentCursor
= (wxCursor
*) NULL
;
1672 m_isDragging
= false;
1676 wxListHeaderWindow::wxListHeaderWindow()
1680 m_owner
= (wxListMainWindow
*) NULL
;
1681 m_resizeCursor
= (wxCursor
*) NULL
;
1684 wxListHeaderWindow::wxListHeaderWindow( wxWindow
*win
,
1686 wxListMainWindow
*owner
,
1690 const wxString
&name
)
1691 : wxWindow( win
, id
, pos
, size
, style
, name
)
1696 m_resizeCursor
= new wxCursor( wxCURSOR_SIZEWE
);
1699 wxVisualAttributes attr
= wxPanel::GetClassDefaultAttributes();
1700 SetOwnForegroundColour( attr
.colFg
);
1701 SetOwnBackgroundColour( attr
.colBg
);
1703 SetOwnFont( attr
.font
);
1705 SetOwnForegroundColour( wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT
));
1706 SetOwnBackgroundColour( wxSystemSettings::GetColour(wxSYS_COLOUR_BTNFACE
));
1708 SetOwnFont( wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT
));
1712 wxListHeaderWindow::~wxListHeaderWindow()
1714 delete m_resizeCursor
;
1717 #ifdef __WXUNIVERSAL__
1718 #include "wx/univ/renderer.h"
1719 #include "wx/univ/theme.h"
1722 // shift the DC origin to match the position of the main window horz
1723 // scrollbar: this allows us to always use logical coords
1724 void wxListHeaderWindow::AdjustDC(wxDC
& dc
)
1727 m_owner
->GetScrollPixelsPerUnit( &xpix
, NULL
);
1730 m_owner
->GetViewStart( &x
, NULL
);
1732 // account for the horz scrollbar offset
1733 dc
.SetDeviceOrigin( -x
* xpix
, 0 );
1736 void wxListHeaderWindow::OnPaint( wxPaintEvent
&WXUNUSED(event
) )
1738 wxPaintDC
dc( this );
1745 dc
.SetFont( GetFont() );
1747 // width and height of the entire header window
1749 GetClientSize( &w
, &h
);
1750 m_owner
->CalcUnscrolledPosition(w
, 0, &w
, NULL
);
1752 dc
.SetBackgroundMode(wxTRANSPARENT
);
1754 dc
.SetTextForeground(GetForegroundColour());
1756 int x
= HEADER_OFFSET_X
;
1758 int numColumns
= m_owner
->GetColumnCount();
1760 for ( int i
= 0; i
< numColumns
&& x
< w
; i
++ )
1762 m_owner
->GetColumn( i
, item
);
1763 int wCol
= item
.m_width
;
1765 // the width of the rect to draw: make it smaller to fit entirely
1766 // inside the column rect
1774 wxRendererNative::Get().DrawHeaderButton
1778 wxRect(x
, HEADER_OFFSET_Y
, cw
, ch
),
1779 m_parent
->IsEnabled() ? 0
1780 : (int)wxCONTROL_DISABLED
1783 // see if we have enough space for the column label
1785 // for this we need the width of the text
1788 dc
.GetTextExtent(item
.GetText(), &wLabel
, &hLabel
);
1789 wLabel
+= 2*EXTRA_WIDTH
;
1791 // and the width of the icon, if any
1792 static const int MARGIN_BETWEEN_TEXT_AND_ICON
= 2;
1793 int ix
= 0, // init them just to suppress the compiler warnings
1795 const int image
= item
.m_image
;
1796 wxImageListType
*imageList
;
1799 imageList
= m_owner
->m_small_image_list
;
1802 imageList
->GetSize(image
, ix
, iy
);
1803 wLabel
+= ix
+ MARGIN_BETWEEN_TEXT_AND_ICON
;
1811 // ignore alignment if there is not enough space anyhow
1813 switch ( wLabel
< cw
? item
.GetAlign() : wxLIST_FORMAT_LEFT
)
1816 wxFAIL_MSG( _T("unknown list item format") );
1819 case wxLIST_FORMAT_LEFT
:
1823 case wxLIST_FORMAT_RIGHT
:
1824 xAligned
= x
+ cw
- wLabel
;
1827 case wxLIST_FORMAT_CENTER
:
1828 xAligned
= x
+ (cw
- wLabel
) / 2;
1833 // if we have an image, draw it on the right of the label
1840 xAligned
+ wLabel
- ix
- MARGIN_BETWEEN_TEXT_AND_ICON
,
1841 HEADER_OFFSET_Y
+ (h
- 4 - iy
)/2,
1842 wxIMAGELIST_DRAW_TRANSPARENT
1845 cw
-= ix
+ MARGIN_BETWEEN_TEXT_AND_ICON
;
1848 // draw the text clipping it so that it doesn't overwrite the column
1850 wxDCClipper
clipper(dc
, x
, HEADER_OFFSET_Y
, cw
, h
- 4 );
1852 dc
.DrawText( item
.GetText(),
1853 xAligned
+ EXTRA_WIDTH
, h
/ 2 - hLabel
/ 2 ); //HEADER_OFFSET_Y + EXTRA_HEIGHT );
1861 void wxListHeaderWindow::DrawCurrent()
1863 int x1
= m_currentX
;
1865 m_owner
->ClientToScreen( &x1
, &y1
);
1867 int x2
= m_currentX
;
1869 m_owner
->GetClientSize( NULL
, &y2
);
1870 m_owner
->ClientToScreen( &x2
, &y2
);
1873 dc
.SetLogicalFunction( wxINVERT
);
1874 dc
.SetPen( wxPen( *wxBLACK
, 2, wxSOLID
) );
1875 dc
.SetBrush( *wxTRANSPARENT_BRUSH
);
1879 dc
.DrawLine( x1
, y1
, x2
, y2
);
1881 dc
.SetLogicalFunction( wxCOPY
);
1883 dc
.SetPen( wxNullPen
);
1884 dc
.SetBrush( wxNullBrush
);
1887 void wxListHeaderWindow::OnMouse( wxMouseEvent
&event
)
1889 // we want to work with logical coords
1891 m_owner
->CalcUnscrolledPosition(event
.GetX(), 0, &x
, NULL
);
1892 int y
= event
.GetY();
1896 SendListEvent(wxEVT_COMMAND_LIST_COL_DRAGGING
, event
.GetPosition());
1898 // we don't draw the line beyond our window, but we allow dragging it
1901 GetClientSize( &w
, NULL
);
1902 m_owner
->CalcUnscrolledPosition(w
, 0, &w
, NULL
);
1905 // erase the line if it was drawn
1906 if ( m_currentX
< w
)
1909 if (event
.ButtonUp())
1912 m_isDragging
= false;
1914 m_owner
->SetColumnWidth( m_column
, m_currentX
- m_minX
);
1915 SendListEvent(wxEVT_COMMAND_LIST_COL_END_DRAG
, event
.GetPosition());
1922 m_currentX
= m_minX
+ 7;
1924 // draw in the new location
1925 if ( m_currentX
< w
)
1929 else // not dragging
1932 bool hit_border
= false;
1934 // end of the current column
1937 // find the column where this event occurred
1939 countCol
= m_owner
->GetColumnCount();
1940 for (col
= 0; col
< countCol
; col
++)
1942 xpos
+= m_owner
->GetColumnWidth( col
);
1945 if ( (abs(x
-xpos
) < 3) && (y
< 22) )
1947 // near the column border
1954 // inside the column
1961 if ( col
== countCol
)
1964 if (event
.LeftDown() || event
.RightUp())
1966 if (hit_border
&& event
.LeftDown())
1968 if ( SendListEvent(wxEVT_COMMAND_LIST_COL_BEGIN_DRAG
,
1969 event
.GetPosition()) )
1971 m_isDragging
= true;
1976 //else: column resizing was vetoed by the user code
1978 else // click on a column
1980 SendListEvent( event
.LeftDown()
1981 ? wxEVT_COMMAND_LIST_COL_CLICK
1982 : wxEVT_COMMAND_LIST_COL_RIGHT_CLICK
,
1983 event
.GetPosition());
1986 else if (event
.Moving())
1991 setCursor
= m_currentCursor
== wxSTANDARD_CURSOR
;
1992 m_currentCursor
= m_resizeCursor
;
1996 setCursor
= m_currentCursor
!= wxSTANDARD_CURSOR
;
1997 m_currentCursor
= wxSTANDARD_CURSOR
;
2001 SetCursor(*m_currentCursor
);
2006 void wxListHeaderWindow::OnSetFocus( wxFocusEvent
&WXUNUSED(event
) )
2008 m_owner
->SetFocus();
2012 bool wxListHeaderWindow::SendListEvent(wxEventType type
, wxPoint pos
)
2014 wxWindow
*parent
= GetParent();
2015 wxListEvent
le( type
, parent
->GetId() );
2016 le
.SetEventObject( parent
);
2017 le
.m_pointDrag
= pos
;
2019 // the position should be relative to the parent window, not
2020 // this one for compatibility with MSW and common sense: the
2021 // user code doesn't know anything at all about this header
2022 // window, so why should it get positions relative to it?
2023 le
.m_pointDrag
.y
-= GetSize().y
;
2025 le
.m_col
= m_column
;
2026 return !parent
->GetEventHandler()->ProcessEvent( le
) || le
.IsAllowed();
2029 //-----------------------------------------------------------------------------
2030 // wxListRenameTimer (internal)
2031 //-----------------------------------------------------------------------------
2033 wxListRenameTimer::wxListRenameTimer( wxListMainWindow
*owner
)
2038 void wxListRenameTimer::Notify()
2040 m_owner
->OnRenameTimer();
2043 //-----------------------------------------------------------------------------
2044 // wxListTextCtrl (internal)
2045 //-----------------------------------------------------------------------------
2047 BEGIN_EVENT_TABLE(wxListTextCtrl
,wxTextCtrl
)
2048 EVT_CHAR (wxListTextCtrl::OnChar
)
2049 EVT_KEY_UP (wxListTextCtrl::OnKeyUp
)
2050 EVT_KILL_FOCUS (wxListTextCtrl::OnKillFocus
)
2053 wxListTextCtrl::wxListTextCtrl(wxListMainWindow
*owner
, size_t itemEdit
)
2054 : m_startValue(owner
->GetItemText(itemEdit
)),
2055 m_itemEdited(itemEdit
)
2059 m_aboutToFinish
= false;
2061 wxRect rectLabel
= owner
->GetLineLabelRect(itemEdit
);
2063 m_owner
->CalcScrolledPosition(rectLabel
.x
, rectLabel
.y
,
2064 &rectLabel
.x
, &rectLabel
.y
);
2066 (void)Create(owner
, wxID_ANY
, m_startValue
,
2067 wxPoint(rectLabel
.x
-4,rectLabel
.y
-4),
2068 wxSize(rectLabel
.width
+11,rectLabel
.height
+8));
2071 void wxListTextCtrl::Finish()
2075 wxPendingDelete
.Append(this);
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::OnChar( wxKeyEvent
&event
)
2107 switch ( event
.m_keyCode
)
2110 m_aboutToFinish
= true;
2111 // Notify the owner about the changes
2113 // Even if vetoed, close the control (consistent with MSW)
2119 m_owner
->OnRenameCancelled( m_itemEdited
);
2127 void wxListTextCtrl::OnKeyUp( wxKeyEvent
&event
)
2135 // auto-grow the textctrl:
2136 wxSize parentSize
= m_owner
->GetSize();
2137 wxPoint myPos
= GetPosition();
2138 wxSize mySize
= GetSize();
2140 GetTextExtent(GetValue() + _T("MM"), &sx
, &sy
);
2141 if (myPos
.x
+ sx
> parentSize
.x
)
2142 sx
= parentSize
.x
- myPos
.x
;
2145 SetSize(sx
, wxDefaultCoord
);
2150 void wxListTextCtrl::OnKillFocus( wxFocusEvent
&event
)
2152 if ( !m_finished
&& !m_aboutToFinish
)
2154 // We must finish regardless of success, otherwise we'll get
2158 if ( !AcceptChanges() )
2159 m_owner
->OnRenameCancelled( m_itemEdited
);
2162 // We must let the native text control handle focus, too, otherwise
2163 // it could have problems with the cursor (e.g., in wxGTK).
2167 //-----------------------------------------------------------------------------
2169 //-----------------------------------------------------------------------------
2171 IMPLEMENT_DYNAMIC_CLASS(wxListMainWindow
,wxScrolledWindow
)
2173 BEGIN_EVENT_TABLE(wxListMainWindow
,wxScrolledWindow
)
2174 EVT_PAINT (wxListMainWindow::OnPaint
)
2175 EVT_MOUSE_EVENTS (wxListMainWindow::OnMouse
)
2176 EVT_CHAR (wxListMainWindow::OnChar
)
2177 EVT_KEY_DOWN (wxListMainWindow::OnKeyDown
)
2178 EVT_SET_FOCUS (wxListMainWindow::OnSetFocus
)
2179 EVT_KILL_FOCUS (wxListMainWindow::OnKillFocus
)
2180 EVT_SCROLLWIN (wxListMainWindow::OnScroll
)
2183 void wxListMainWindow::Init()
2188 m_lineTo
= (size_t)-1;
2194 m_small_image_list
= (wxImageListType
*) NULL
;
2195 m_normal_image_list
= (wxImageListType
*) NULL
;
2197 m_small_spacing
= 30;
2198 m_normal_spacing
= 40;
2202 m_isCreated
= false;
2204 m_lastOnSame
= false;
2205 m_renameTimer
= new wxListRenameTimer( this );
2209 m_lineSelectSingleOnUp
=
2210 m_lineBeforeLastClicked
= (size_t)-1;
2215 wxListMainWindow::wxListMainWindow()
2220 m_highlightUnfocusedBrush
= (wxBrush
*) NULL
;
2223 wxListMainWindow::wxListMainWindow( wxWindow
*parent
,
2228 const wxString
&name
)
2229 : wxScrolledWindow( parent
, id
, pos
, size
,
2230 style
| wxHSCROLL
| wxVSCROLL
, name
)
2234 m_highlightBrush
= new wxBrush
2236 wxSystemSettings::GetColour
2238 wxSYS_COLOUR_HIGHLIGHT
2243 m_highlightUnfocusedBrush
= new wxBrush
2245 wxSystemSettings::GetColour
2247 wxSYS_COLOUR_BTNSHADOW
2252 SetScrollbars( 0, 0, 0, 0, 0, 0 );
2254 wxVisualAttributes attr
= wxGenericListCtrl::GetClassDefaultAttributes();
2255 SetOwnForegroundColour( attr
.colFg
);
2256 SetOwnBackgroundColour( attr
.colBg
);
2258 SetOwnFont( attr
.font
);
2261 wxListMainWindow::~wxListMainWindow()
2264 WX_CLEAR_LIST(wxListHeaderDataList
, m_columns
);
2265 WX_CLEAR_ARRAY(m_aColWidths
);
2267 delete m_highlightBrush
;
2268 delete m_highlightUnfocusedBrush
;
2270 delete m_renameTimer
;
2273 void wxListMainWindow::CacheLineData(size_t line
)
2275 wxGenericListCtrl
*listctrl
= GetListCtrl();
2277 wxListLineData
*ld
= GetDummyLine();
2279 size_t countCol
= GetColumnCount();
2280 for ( size_t col
= 0; col
< countCol
; col
++ )
2282 ld
->SetText(col
, listctrl
->OnGetItemText(line
, col
));
2285 ld
->SetImage(listctrl
->OnGetItemImage(line
));
2286 ld
->SetAttr(listctrl
->OnGetItemAttr(line
));
2289 wxListLineData
*wxListMainWindow::GetDummyLine() const
2291 wxASSERT_MSG( !IsEmpty(), _T("invalid line index") );
2293 wxASSERT_MSG( IsVirtual(), _T("GetDummyLine() shouldn't be called") );
2295 wxListMainWindow
*self
= wxConstCast(this, wxListMainWindow
);
2297 // we need to recreate the dummy line if the number of columns in the
2298 // control changed as it would have the incorrect number of fields
2300 if ( !m_lines
.IsEmpty() &&
2301 m_lines
[0].m_items
.GetCount() != (size_t)GetColumnCount() )
2303 self
->m_lines
.Clear();
2306 if ( m_lines
.IsEmpty() )
2308 wxListLineData
*line
= new wxListLineData(self
);
2309 self
->m_lines
.Add(line
);
2311 // don't waste extra memory -- there never going to be anything
2312 // else/more in this array
2313 self
->m_lines
.Shrink();
2319 // ----------------------------------------------------------------------------
2320 // line geometry (report mode only)
2321 // ----------------------------------------------------------------------------
2323 wxCoord
wxListMainWindow::GetLineHeight() const
2325 // we cache the line height as calling GetTextExtent() is slow
2326 if ( !m_lineHeight
)
2328 wxListMainWindow
*self
= wxConstCast(this, wxListMainWindow
);
2330 wxClientDC
dc( self
);
2331 dc
.SetFont( GetFont() );
2334 dc
.GetTextExtent(_T("H"), NULL
, &y
);
2336 if ( m_small_image_list
&& m_small_image_list
->GetImageCount() )
2340 m_small_image_list
->GetSize(0, iw
, ih
);
2345 self
->m_lineHeight
= y
+ LINE_SPACING
;
2348 return m_lineHeight
;
2351 wxCoord
wxListMainWindow::GetLineY(size_t line
) const
2353 wxASSERT_MSG( InReportView(), _T("only works in report mode") );
2355 return LINE_SPACING
+ line
*GetLineHeight();
2358 wxRect
wxListMainWindow::GetLineRect(size_t line
) const
2360 if ( !InReportView() )
2361 return GetLine(line
)->m_gi
->m_rectAll
;
2364 rect
.x
= HEADER_OFFSET_X
;
2365 rect
.y
= GetLineY(line
);
2366 rect
.width
= GetHeaderWidth();
2367 rect
.height
= GetLineHeight();
2372 wxRect
wxListMainWindow::GetLineLabelRect(size_t line
) const
2374 if ( !InReportView() )
2375 return GetLine(line
)->m_gi
->m_rectLabel
;
2378 rect
.x
= HEADER_OFFSET_X
;
2379 rect
.y
= GetLineY(line
);
2380 rect
.width
= GetColumnWidth(0);
2381 rect
.height
= GetLineHeight();
2386 wxRect
wxListMainWindow::GetLineIconRect(size_t line
) const
2388 if ( !InReportView() )
2389 return GetLine(line
)->m_gi
->m_rectIcon
;
2391 wxListLineData
*ld
= GetLine(line
);
2392 wxASSERT_MSG( ld
->HasImage(), _T("should have an image") );
2395 rect
.x
= HEADER_OFFSET_X
;
2396 rect
.y
= GetLineY(line
);
2397 GetImageSize(ld
->GetImage(), rect
.width
, rect
.height
);
2402 wxRect
wxListMainWindow::GetLineHighlightRect(size_t line
) const
2404 return InReportView() ? GetLineRect(line
)
2405 : GetLine(line
)->m_gi
->m_rectHighlight
;
2408 long wxListMainWindow::HitTestLine(size_t line
, int x
, int y
) const
2410 wxASSERT_MSG( line
< GetItemCount(), _T("invalid line in HitTestLine") );
2412 wxListLineData
*ld
= GetLine(line
);
2414 if ( ld
->HasImage() && GetLineIconRect(line
).Inside(x
, y
) )
2415 return wxLIST_HITTEST_ONITEMICON
;
2417 // VS: Testing for "ld->HasText() || InReportView()" instead of
2418 // "ld->HasText()" is needed to make empty lines in report view
2420 if ( ld
->HasText() || InReportView() )
2422 wxRect rect
= InReportView() ? GetLineRect(line
)
2423 : GetLineLabelRect(line
);
2425 if ( rect
.Inside(x
, y
) )
2426 return wxLIST_HITTEST_ONITEMLABEL
;
2432 // ----------------------------------------------------------------------------
2433 // highlight (selection) handling
2434 // ----------------------------------------------------------------------------
2436 bool wxListMainWindow::IsHighlighted(size_t line
) const
2440 return m_selStore
.IsSelected(line
);
2444 wxListLineData
*ld
= GetLine(line
);
2445 wxCHECK_MSG( ld
, false, _T("invalid index in IsHighlighted") );
2447 return ld
->IsHighlighted();
2451 void wxListMainWindow::HighlightLines( size_t lineFrom
,
2457 wxArrayInt linesChanged
;
2458 if ( !m_selStore
.SelectRange(lineFrom
, lineTo
, highlight
,
2461 // meny items changed state, refresh everything
2462 RefreshLines(lineFrom
, lineTo
);
2464 else // only a few items changed state, refresh only them
2466 size_t count
= linesChanged
.GetCount();
2467 for ( size_t n
= 0; n
< count
; n
++ )
2469 RefreshLine(linesChanged
[n
]);
2473 else // iterate over all items in non report view
2475 for ( size_t line
= lineFrom
; line
<= lineTo
; line
++ )
2477 if ( HighlightLine(line
, highlight
) )
2485 bool wxListMainWindow::HighlightLine( size_t line
, bool highlight
)
2491 changed
= m_selStore
.SelectItem(line
, highlight
);
2495 wxListLineData
*ld
= GetLine(line
);
2496 wxCHECK_MSG( ld
, false, _T("invalid index in HighlightLine") );
2498 changed
= ld
->Highlight(highlight
);
2503 SendNotify( line
, highlight
? wxEVT_COMMAND_LIST_ITEM_SELECTED
2504 : wxEVT_COMMAND_LIST_ITEM_DESELECTED
);
2510 void wxListMainWindow::RefreshLine( size_t line
)
2512 if ( InReportView() )
2514 size_t visibleFrom
, visibleTo
;
2515 GetVisibleLinesRange(&visibleFrom
, &visibleTo
);
2517 if ( line
< visibleFrom
|| line
> visibleTo
)
2521 wxRect rect
= GetLineRect(line
);
2523 CalcScrolledPosition( rect
.x
, rect
.y
, &rect
.x
, &rect
.y
);
2524 RefreshRect( rect
);
2527 void wxListMainWindow::RefreshLines( size_t lineFrom
, size_t lineTo
)
2529 // we suppose that they are ordered by caller
2530 wxASSERT_MSG( lineFrom
<= lineTo
, _T("indices in disorder") );
2532 wxASSERT_MSG( lineTo
< GetItemCount(), _T("invalid line range") );
2534 if ( InReportView() )
2536 size_t visibleFrom
, visibleTo
;
2537 GetVisibleLinesRange(&visibleFrom
, &visibleTo
);
2539 if ( lineFrom
< visibleFrom
)
2540 lineFrom
= visibleFrom
;
2541 if ( lineTo
> visibleTo
)
2546 rect
.y
= GetLineY(lineFrom
);
2547 rect
.width
= GetClientSize().x
;
2548 rect
.height
= GetLineY(lineTo
) - rect
.y
+ GetLineHeight();
2550 CalcScrolledPosition( rect
.x
, rect
.y
, &rect
.x
, &rect
.y
);
2551 RefreshRect( rect
);
2555 // TODO: this should be optimized...
2556 for ( size_t line
= lineFrom
; line
<= lineTo
; line
++ )
2563 void wxListMainWindow::RefreshAfter( size_t lineFrom
)
2565 if ( InReportView() )
2567 size_t visibleFrom
, visibleTo
;
2568 GetVisibleLinesRange(&visibleFrom
, &visibleTo
);
2570 if ( lineFrom
< visibleFrom
)
2571 lineFrom
= visibleFrom
;
2572 else if ( lineFrom
> visibleTo
)
2577 rect
.y
= GetLineY(lineFrom
);
2578 CalcScrolledPosition( rect
.x
, rect
.y
, &rect
.x
, &rect
.y
);
2580 wxSize size
= GetClientSize();
2581 rect
.width
= size
.x
;
2582 // refresh till the bottom of the window
2583 rect
.height
= size
.y
- rect
.y
;
2585 RefreshRect( rect
);
2589 // TODO: how to do it more efficiently?
2594 void wxListMainWindow::RefreshSelected()
2600 if ( InReportView() )
2602 GetVisibleLinesRange(&from
, &to
);
2607 to
= GetItemCount() - 1;
2610 if ( HasCurrent() && m_current
>= from
&& m_current
<= to
)
2612 RefreshLine(m_current
);
2615 for ( size_t line
= from
; line
<= to
; line
++ )
2617 // NB: the test works as expected even if m_current == -1
2618 if ( line
!= m_current
&& IsHighlighted(line
) )
2625 void wxListMainWindow::Freeze()
2630 void wxListMainWindow::Thaw()
2632 wxCHECK_RET( m_freezeCount
> 0, _T("thawing unfrozen list control?") );
2634 if ( !--m_freezeCount
)
2640 void wxListMainWindow::OnPaint( wxPaintEvent
&WXUNUSED(event
) )
2642 // Note: a wxPaintDC must be constructed even if no drawing is
2643 // done (a Windows requirement).
2644 wxPaintDC
dc( this );
2646 if ( IsEmpty() || m_freezeCount
)
2648 // nothing to draw or not the moment to draw it
2654 // delay the repainting until we calculate all the items positions
2661 CalcScrolledPosition( 0, 0, &dev_x
, &dev_y
);
2665 dc
.SetFont( GetFont() );
2667 if ( InReportView() )
2669 int lineHeight
= GetLineHeight();
2671 size_t visibleFrom
, visibleTo
;
2672 GetVisibleLinesRange(&visibleFrom
, &visibleTo
);
2675 wxCoord xOrig
, yOrig
;
2676 CalcUnscrolledPosition(0, 0, &xOrig
, &yOrig
);
2678 // tell the caller cache to cache the data
2681 wxListEvent
evCache(wxEVT_COMMAND_LIST_CACHE_HINT
,
2682 GetParent()->GetId());
2683 evCache
.SetEventObject( GetParent() );
2684 evCache
.m_oldItemIndex
= visibleFrom
;
2685 evCache
.m_itemIndex
= visibleTo
;
2686 GetParent()->GetEventHandler()->ProcessEvent( evCache
);
2689 for ( size_t line
= visibleFrom
; line
<= visibleTo
; line
++ )
2691 rectLine
= GetLineRect(line
);
2693 if ( !IsExposed(rectLine
.x
- xOrig
, rectLine
.y
- yOrig
,
2694 rectLine
.width
, rectLine
.height
) )
2696 // don't redraw unaffected lines to avoid flicker
2700 GetLine(line
)->DrawInReportMode( &dc
,
2702 GetLineHighlightRect(line
),
2703 IsHighlighted(line
) );
2706 if ( HasFlag(wxLC_HRULES
) )
2708 wxPen
pen(GetRuleColour(), 1, wxSOLID
);
2709 wxSize clientSize
= GetClientSize();
2711 // Don't draw the first one
2712 for ( size_t i
= visibleFrom
+1; i
<= visibleTo
; i
++ )
2715 dc
.SetBrush( *wxTRANSPARENT_BRUSH
);
2716 dc
.DrawLine(0 - dev_x
, i
*lineHeight
,
2717 clientSize
.x
- dev_x
, i
*lineHeight
);
2720 // Draw last horizontal rule
2721 if ( visibleTo
== GetItemCount() - 1 )
2724 dc
.SetBrush( *wxTRANSPARENT_BRUSH
);
2725 dc
.DrawLine(0 - dev_x
, (m_lineTo
+1)*lineHeight
,
2726 clientSize
.x
- dev_x
, (m_lineTo
+1)*lineHeight
);
2730 // Draw vertical rules if required
2731 if ( HasFlag(wxLC_VRULES
) && !IsEmpty() )
2733 wxPen
pen(GetRuleColour(), 1, wxSOLID
);
2735 wxRect firstItemRect
;
2736 wxRect lastItemRect
;
2737 GetItemRect(visibleFrom
, firstItemRect
);
2738 GetItemRect(visibleTo
, lastItemRect
);
2739 int x
= firstItemRect
.GetX();
2741 dc
.SetBrush(* wxTRANSPARENT_BRUSH
);
2742 for (int col
= 0; col
< GetColumnCount(); col
++)
2744 int colWidth
= GetColumnWidth(col
);
2746 dc
.DrawLine(x
- dev_x
- 2, firstItemRect
.GetY() - 1 - dev_y
,
2747 x
- dev_x
- 2, lastItemRect
.GetBottom() + 1 - dev_y
);
2753 size_t count
= GetItemCount();
2754 for ( size_t i
= 0; i
< count
; i
++ )
2756 GetLine(i
)->Draw( &dc
);
2761 // Don't draw rect outline under Mac at all.
2766 dc
.SetPen( *wxBLACK_PEN
);
2767 dc
.SetBrush( *wxTRANSPARENT_BRUSH
);
2768 dc
.DrawRectangle( GetLineHighlightRect(m_current
) );
2776 void wxListMainWindow::HighlightAll( bool on
)
2778 if ( IsSingleSel() )
2780 wxASSERT_MSG( !on
, _T("can't do this in a single sel control") );
2782 // we just have one item to turn off
2783 if ( HasCurrent() && IsHighlighted(m_current
) )
2785 HighlightLine(m_current
, false);
2786 RefreshLine(m_current
);
2791 HighlightLines(0, GetItemCount() - 1, on
);
2795 void wxListMainWindow::SendNotify( size_t line
,
2796 wxEventType command
,
2799 wxListEvent
le( command
, GetParent()->GetId() );
2800 le
.SetEventObject( GetParent() );
2801 le
.m_itemIndex
= line
;
2803 // set only for events which have position
2804 if ( point
!= wxDefaultPosition
)
2805 le
.m_pointDrag
= point
;
2807 // don't try to get the line info for virtual list controls: the main
2808 // program has it anyhow and if we did it would result in accessing all
2809 // the lines, even those which are not visible now and this is precisely
2810 // what we're trying to avoid
2811 if ( !IsVirtual() && (command
!= wxEVT_COMMAND_LIST_DELETE_ITEM
) )
2813 if ( line
!= (size_t)-1 )
2815 GetLine(line
)->GetItem( 0, le
.m_item
);
2817 //else: this happens for wxEVT_COMMAND_LIST_ITEM_FOCUSED event
2819 //else: there may be no more such item
2821 GetParent()->GetEventHandler()->ProcessEvent( le
);
2824 void wxListMainWindow::ChangeCurrent(size_t current
)
2826 m_current
= current
;
2828 SendNotify(current
, wxEVT_COMMAND_LIST_ITEM_FOCUSED
);
2831 void wxListMainWindow::EditLabel( long item
)
2833 wxCHECK_RET( (item
>= 0) && ((size_t)item
< GetItemCount()),
2834 wxT("wrong index in wxGenericListCtrl::EditLabel()") );
2836 size_t itemEdit
= (size_t)item
;
2838 wxListEvent
le( wxEVT_COMMAND_LIST_BEGIN_LABEL_EDIT
, GetParent()->GetId() );
2839 le
.SetEventObject( GetParent() );
2840 le
.m_itemIndex
= item
;
2841 wxListLineData
*data
= GetLine(itemEdit
);
2842 wxCHECK_RET( data
, _T("invalid index in EditLabel()") );
2843 data
->GetItem( 0, le
.m_item
);
2844 if ( GetParent()->GetEventHandler()->ProcessEvent( le
) && !le
.IsAllowed() )
2846 // vetoed by user code
2850 // We have to call this here because the label in question might just have
2851 // been added and no screen update taken place.
2855 wxListTextCtrl
*text
= new wxListTextCtrl(this, itemEdit
);
2860 void wxListMainWindow::OnRenameTimer()
2862 wxCHECK_RET( HasCurrent(), wxT("unexpected rename timer") );
2864 EditLabel( m_current
);
2867 bool wxListMainWindow::OnRenameAccept(size_t itemEdit
, const wxString
& value
)
2869 wxListEvent
le( wxEVT_COMMAND_LIST_END_LABEL_EDIT
, GetParent()->GetId() );
2870 le
.SetEventObject( GetParent() );
2871 le
.m_itemIndex
= itemEdit
;
2873 wxListLineData
*data
= GetLine(itemEdit
);
2874 wxCHECK_MSG( data
, false, _T("invalid index in OnRenameAccept()") );
2876 data
->GetItem( 0, le
.m_item
);
2877 le
.m_item
.m_text
= value
;
2878 return !GetParent()->GetEventHandler()->ProcessEvent( le
) ||
2882 void wxListMainWindow::OnRenameCancelled(size_t itemEdit
)
2884 // let owner know that the edit was cancelled
2885 wxListEvent
le( wxEVT_COMMAND_LIST_END_LABEL_EDIT
, GetParent()->GetId() );
2887 le
.SetEditCanceled(true);
2889 le
.SetEventObject( GetParent() );
2890 le
.m_itemIndex
= itemEdit
;
2892 wxListLineData
*data
= GetLine(itemEdit
);
2893 wxCHECK_RET( data
, _T("invalid index in OnRenameCancelled()") );
2895 data
->GetItem( 0, le
.m_item
);
2897 GetEventHandler()->ProcessEvent( le
);
2900 void wxListMainWindow::OnMouse( wxMouseEvent
&event
)
2902 event
.SetEventObject( GetParent() );
2903 if ( GetParent()->GetEventHandler()->ProcessEvent( event
) )
2906 if (event
.GetEventType() == wxEVT_MOUSEWHEEL
)
2908 // let the base handle mouse wheel events.
2913 if ( !HasCurrent() || IsEmpty() )
2919 if ( !(event
.Dragging() || event
.ButtonDown() || event
.LeftUp() ||
2920 event
.ButtonDClick()) )
2923 int x
= event
.GetX();
2924 int y
= event
.GetY();
2925 CalcUnscrolledPosition( x
, y
, &x
, &y
);
2927 // where did we hit it (if we did)?
2930 size_t count
= GetItemCount(),
2933 if ( InReportView() )
2935 current
= y
/ GetLineHeight();
2936 if ( current
< count
)
2937 hitResult
= HitTestLine(current
, x
, y
);
2941 // TODO: optimize it too! this is less simple than for report view but
2942 // enumerating all items is still not a way to do it!!
2943 for ( current
= 0; current
< count
; current
++ )
2945 hitResult
= HitTestLine(current
, x
, y
);
2951 if (event
.Dragging())
2953 if (m_dragCount
== 0)
2955 // we have to report the raw, physical coords as we want to be
2956 // able to call HitTest(event.m_pointDrag) from the user code to
2957 // get the item being dragged
2958 m_dragStart
= event
.GetPosition();
2963 if (m_dragCount
!= 3)
2966 int command
= event
.RightIsDown() ? wxEVT_COMMAND_LIST_BEGIN_RDRAG
2967 : wxEVT_COMMAND_LIST_BEGIN_DRAG
;
2969 wxListEvent
le( command
, GetParent()->GetId() );
2970 le
.SetEventObject( GetParent() );
2971 le
.m_itemIndex
= m_lineLastClicked
;
2972 le
.m_pointDrag
= m_dragStart
;
2973 GetParent()->GetEventHandler()->ProcessEvent( le
);
2984 // outside of any item
2988 bool forceClick
= false;
2989 if (event
.ButtonDClick())
2991 m_renameTimer
->Stop();
2992 m_lastOnSame
= false;
2994 if ( current
== m_lineLastClicked
)
2996 SendNotify( current
, wxEVT_COMMAND_LIST_ITEM_ACTIVATED
);
3002 // The first click was on another item, so don't interpret this as
3003 // a double click, but as a simple click instead
3010 if(m_lineSelectSingleOnUp
!= (size_t) -1)
3012 // select single line
3013 HighlightAll( false );
3014 ReverseHighlight(m_lineSelectSingleOnUp
);
3018 if ((current
== m_current
) &&
3019 (hitResult
== wxLIST_HITTEST_ONITEMLABEL
) &&
3020 HasFlag(wxLC_EDIT_LABELS
) )
3022 m_renameTimer
->Start( 100, true );
3025 m_lastOnSame
= false;
3026 m_lineSelectSingleOnUp
= (size_t) -1;
3030 // This is necessary, because after a DnD operation in
3031 // from and to ourself, the up event is swallowed by the
3032 // DnD code. So on next non-up event (which means here and
3033 // now) m_lineSelectSingleOnUp should be reset.
3034 m_lineSelectSingleOnUp
= (size_t) -1;
3036 if (event
.RightDown())
3038 m_lineBeforeLastClicked
= m_lineLastClicked
;
3039 m_lineLastClicked
= current
;
3040 // If the item is already selected, do not update the selection.
3041 // Multi-selections should not be cleared if a selected item is clicked.
3042 if (!IsHighlighted(current
))
3044 HighlightAll(false);
3045 ChangeCurrent(current
);
3046 ReverseHighlight(m_current
);
3048 SendNotify( current
, wxEVT_COMMAND_LIST_ITEM_RIGHT_CLICK
,
3049 event
.GetPosition() );
3050 // Allow generation of context menu event
3053 else if (event
.MiddleDown())
3055 SendNotify( current
, wxEVT_COMMAND_LIST_ITEM_MIDDLE_CLICK
);
3057 else if ( event
.LeftDown() || forceClick
)
3059 m_lineBeforeLastClicked
= m_lineLastClicked
;
3060 m_lineLastClicked
= current
;
3062 size_t oldCurrent
= m_current
;
3063 bool oldWasSelected
= IsHighlighted(m_current
);
3065 bool cmdModifierDown
= event
.CmdDown();
3066 if ( IsSingleSel() || !(cmdModifierDown
|| event
.ShiftDown()) )
3068 if( IsSingleSel() || !IsHighlighted(current
) )
3070 HighlightAll( false );
3072 ChangeCurrent(current
);
3074 ReverseHighlight(m_current
);
3076 else // multi sel & current is highlighted & no mod keys
3078 m_lineSelectSingleOnUp
= current
;
3079 ChangeCurrent(current
); // change focus
3082 else // multi sel & either ctrl or shift is down
3084 if (cmdModifierDown
)
3086 ChangeCurrent(current
);
3088 ReverseHighlight(m_current
);
3090 else if (event
.ShiftDown())
3092 ChangeCurrent(current
);
3094 size_t lineFrom
= oldCurrent
,
3097 if ( lineTo
< lineFrom
)
3100 lineFrom
= m_current
;
3103 HighlightLines(lineFrom
, lineTo
);
3105 else // !ctrl, !shift
3107 // test in the enclosing if should make it impossible
3108 wxFAIL_MSG( _T("how did we get here?") );
3112 if (m_current
!= oldCurrent
)
3114 RefreshLine( oldCurrent
);
3117 // forceClick is only set if the previous click was on another item
3118 m_lastOnSame
= !forceClick
&& (m_current
== oldCurrent
) && oldWasSelected
;
3122 void wxListMainWindow::MoveToItem(size_t item
)
3124 if ( item
== (size_t)-1 )
3127 wxRect rect
= GetLineRect(item
);
3129 int client_w
, client_h
;
3130 GetClientSize( &client_w
, &client_h
);
3132 const int hLine
= GetLineHeight();
3134 int view_x
= SCROLL_UNIT_X
*GetScrollPos( wxHORIZONTAL
);
3135 int view_y
= hLine
*GetScrollPos( wxVERTICAL
);
3137 if ( InReportView() )
3139 // the next we need the range of lines shown it might be different, so
3141 ResetVisibleLinesRange();
3143 if (rect
.y
< view_y
)
3144 Scroll( -1, rect
.y
/hLine
);
3145 if (rect
.y
+rect
.height
+5 > view_y
+client_h
)
3146 Scroll( -1, (rect
.y
+rect
.height
-client_h
+hLine
)/hLine
);
3150 if (rect
.x
-view_x
< 5)
3151 Scroll( (rect
.x
-5)/SCROLL_UNIT_X
, -1 );
3152 if (rect
.x
+rect
.width
-5 > view_x
+client_w
)
3153 Scroll( (rect
.x
+rect
.width
-client_w
+SCROLL_UNIT_X
)/SCROLL_UNIT_X
, -1 );
3157 // ----------------------------------------------------------------------------
3158 // keyboard handling
3159 // ----------------------------------------------------------------------------
3161 void wxListMainWindow::OnArrowChar(size_t newCurrent
, const wxKeyEvent
& event
)
3163 wxCHECK_RET( newCurrent
< (size_t)GetItemCount(),
3164 _T("invalid item index in OnArrowChar()") );
3166 size_t oldCurrent
= m_current
;
3168 // in single selection we just ignore Shift as we can't select several
3170 if ( event
.ShiftDown() && !IsSingleSel() )
3172 ChangeCurrent(newCurrent
);
3174 // refresh the old focus to remove it
3175 RefreshLine( oldCurrent
);
3177 // select all the items between the old and the new one
3178 if ( oldCurrent
> newCurrent
)
3180 newCurrent
= oldCurrent
;
3181 oldCurrent
= m_current
;
3184 HighlightLines(oldCurrent
, newCurrent
);
3188 // all previously selected items are unselected unless ctrl is held
3189 if ( !event
.ControlDown() )
3190 HighlightAll(false);
3192 ChangeCurrent(newCurrent
);
3194 // refresh the old focus to remove it
3195 RefreshLine( oldCurrent
);
3197 if ( !event
.ControlDown() )
3199 HighlightLine( m_current
, true );
3203 RefreshLine( m_current
);
3208 void wxListMainWindow::OnKeyDown( wxKeyEvent
&event
)
3210 wxWindow
*parent
= GetParent();
3212 /* we propagate the key event up */
3213 wxKeyEvent
ke( wxEVT_KEY_DOWN
);
3214 ke
.m_shiftDown
= event
.m_shiftDown
;
3215 ke
.m_controlDown
= event
.m_controlDown
;
3216 ke
.m_altDown
= event
.m_altDown
;
3217 ke
.m_metaDown
= event
.m_metaDown
;
3218 ke
.m_keyCode
= event
.m_keyCode
;
3221 ke
.SetEventObject( parent
);
3222 if (parent
->GetEventHandler()->ProcessEvent( ke
)) return;
3227 void wxListMainWindow::OnChar( wxKeyEvent
&event
)
3229 wxWindow
*parent
= GetParent();
3231 /* we send a list_key event up */
3234 wxListEvent
le( wxEVT_COMMAND_LIST_KEY_DOWN
, GetParent()->GetId() );
3235 le
.m_itemIndex
= m_current
;
3236 GetLine(m_current
)->GetItem( 0, le
.m_item
);
3237 le
.m_code
= event
.GetKeyCode();
3238 le
.SetEventObject( parent
);
3239 parent
->GetEventHandler()->ProcessEvent( le
);
3242 /* we propagate the char event up */
3243 wxKeyEvent
ke( wxEVT_CHAR
);
3244 ke
.m_shiftDown
= event
.m_shiftDown
;
3245 ke
.m_controlDown
= event
.m_controlDown
;
3246 ke
.m_altDown
= event
.m_altDown
;
3247 ke
.m_metaDown
= event
.m_metaDown
;
3248 ke
.m_keyCode
= event
.m_keyCode
;
3251 ke
.SetEventObject( parent
);
3252 if (parent
->GetEventHandler()->ProcessEvent( ke
)) return;
3254 if (event
.GetKeyCode() == WXK_TAB
)
3256 wxNavigationKeyEvent nevent
;
3257 nevent
.SetWindowChange( event
.ControlDown() );
3258 nevent
.SetDirection( !event
.ShiftDown() );
3259 nevent
.SetEventObject( GetParent()->GetParent() );
3260 nevent
.SetCurrentFocus( m_parent
);
3261 if (GetParent()->GetParent()->GetEventHandler()->ProcessEvent( nevent
))
3265 /* no item -> nothing to do */
3272 switch (event
.GetKeyCode())
3275 if ( m_current
> 0 )
3276 OnArrowChar( m_current
- 1, event
);
3280 if ( m_current
< (size_t)GetItemCount() - 1 )
3281 OnArrowChar( m_current
+ 1, event
);
3286 OnArrowChar( GetItemCount() - 1, event
);
3291 OnArrowChar( 0, event
);
3296 int steps
= InReportView() ? m_linesPerPage
- 1 : m_current
% m_linesPerPage
;
3298 int index
= m_current
- steps
;
3302 OnArrowChar( index
, event
);
3308 int steps
= InReportView()
3309 ? m_linesPerPage
- 1
3310 : m_linesPerPage
- (m_current
% m_linesPerPage
) - 1;
3312 size_t index
= m_current
+ steps
;
3313 size_t count
= GetItemCount();
3314 if ( index
>= count
)
3317 OnArrowChar( index
, event
);
3322 if ( !InReportView() )
3324 int index
= m_current
- m_linesPerPage
;
3328 OnArrowChar( index
, event
);
3333 if ( !InReportView() )
3335 size_t index
= m_current
+ m_linesPerPage
;
3337 size_t count
= GetItemCount();
3338 if ( index
>= count
)
3341 OnArrowChar( index
, event
);
3346 if ( IsSingleSel() )
3348 SendNotify( m_current
, wxEVT_COMMAND_LIST_ITEM_ACTIVATED
);
3350 if ( IsHighlighted(m_current
) )
3352 // don't unselect the item in single selection mode
3355 //else: select it in ReverseHighlight() below if unselected
3358 ReverseHighlight(m_current
);
3363 SendNotify( m_current
, wxEVT_COMMAND_LIST_ITEM_ACTIVATED
);
3371 // ----------------------------------------------------------------------------
3373 // ----------------------------------------------------------------------------
3375 void wxListMainWindow::OnSetFocus( wxFocusEvent
&WXUNUSED(event
) )
3379 wxFocusEvent
event( wxEVT_SET_FOCUS
, GetParent()->GetId() );
3380 event
.SetEventObject( GetParent() );
3381 if ( GetParent()->GetEventHandler()->ProcessEvent( event
) )
3385 // wxGTK sends us EVT_SET_FOCUS events even if we had never got
3386 // EVT_KILL_FOCUS before which means that we finish by redrawing the items
3387 // which are already drawn correctly resulting in horrible flicker - avoid
3397 void wxListMainWindow::OnKillFocus( wxFocusEvent
&WXUNUSED(event
) )
3401 wxFocusEvent
event( wxEVT_KILL_FOCUS
, GetParent()->GetId() );
3402 event
.SetEventObject( GetParent() );
3403 if ( GetParent()->GetEventHandler()->ProcessEvent( event
) )
3410 void wxListMainWindow::DrawImage( int index
, wxDC
*dc
, int x
, int y
)
3412 if ( HasFlag(wxLC_ICON
) && (m_normal_image_list
))
3414 m_normal_image_list
->Draw( index
, *dc
, x
, y
, wxIMAGELIST_DRAW_TRANSPARENT
);
3416 else if ( HasFlag(wxLC_SMALL_ICON
) && (m_small_image_list
))
3418 m_small_image_list
->Draw( index
, *dc
, x
, y
, wxIMAGELIST_DRAW_TRANSPARENT
);
3420 else if ( HasFlag(wxLC_LIST
) && (m_small_image_list
))
3422 m_small_image_list
->Draw( index
, *dc
, x
, y
, wxIMAGELIST_DRAW_TRANSPARENT
);
3424 else if ( InReportView() && (m_small_image_list
))
3426 m_small_image_list
->Draw( index
, *dc
, x
, y
, wxIMAGELIST_DRAW_TRANSPARENT
);
3430 void wxListMainWindow::GetImageSize( int index
, int &width
, int &height
) const
3432 if ( HasFlag(wxLC_ICON
) && m_normal_image_list
)
3434 m_normal_image_list
->GetSize( index
, width
, height
);
3436 else if ( HasFlag(wxLC_SMALL_ICON
) && m_small_image_list
)
3438 m_small_image_list
->GetSize( index
, width
, height
);
3440 else if ( HasFlag(wxLC_LIST
) && m_small_image_list
)
3442 m_small_image_list
->GetSize( index
, width
, height
);
3444 else if ( InReportView() && m_small_image_list
)
3446 m_small_image_list
->GetSize( index
, width
, height
);
3455 int wxListMainWindow::GetTextLength( const wxString
&s
) const
3457 wxClientDC
dc( wxConstCast(this, wxListMainWindow
) );
3458 dc
.SetFont( GetFont() );
3461 dc
.GetTextExtent( s
, &lw
, NULL
);
3463 return lw
+ AUTOSIZE_COL_MARGIN
;
3466 void wxListMainWindow::SetImageList( wxImageListType
*imageList
, int which
)
3470 // calc the spacing from the icon size
3473 if ((imageList
) && (imageList
->GetImageCount()) )
3475 imageList
->GetSize(0, width
, height
);
3478 if (which
== wxIMAGE_LIST_NORMAL
)
3480 m_normal_image_list
= imageList
;
3481 m_normal_spacing
= width
+ 8;
3484 if (which
== wxIMAGE_LIST_SMALL
)
3486 m_small_image_list
= imageList
;
3487 m_small_spacing
= width
+ 14;
3488 m_lineHeight
= 0; // ensure that the line height will be recalc'd
3492 void wxListMainWindow::SetItemSpacing( int spacing
, bool isSmall
)
3497 m_small_spacing
= spacing
;
3501 m_normal_spacing
= spacing
;
3505 int wxListMainWindow::GetItemSpacing( bool isSmall
)
3507 return isSmall
? m_small_spacing
: m_normal_spacing
;
3510 // ----------------------------------------------------------------------------
3512 // ----------------------------------------------------------------------------
3514 void wxListMainWindow::SetColumn( int col
, wxListItem
&item
)
3516 wxListHeaderDataList::compatibility_iterator node
= m_columns
.Item( col
);
3518 wxCHECK_RET( node
, _T("invalid column index in SetColumn") );
3520 if ( item
.m_width
== wxLIST_AUTOSIZE_USEHEADER
)
3521 item
.m_width
= GetTextLength( item
.m_text
);
3523 wxListHeaderData
*column
= node
->GetData();
3524 column
->SetItem( item
);
3526 wxListHeaderWindow
*headerWin
= GetListCtrl()->m_headerWin
;
3528 headerWin
->m_dirty
= true;
3532 // invalidate it as it has to be recalculated
3536 void wxListMainWindow::SetColumnWidth( int col
, int width
)
3538 wxCHECK_RET( col
>= 0 && col
< GetColumnCount(),
3539 _T("invalid column index") );
3541 wxCHECK_RET( InReportView(),
3542 _T("SetColumnWidth() can only be called in report mode.") );
3545 wxListHeaderWindow
*headerWin
= GetListCtrl()->m_headerWin
;
3547 headerWin
->m_dirty
= true;
3549 wxListHeaderDataList::compatibility_iterator node
= m_columns
.Item( col
);
3550 wxCHECK_RET( node
, _T("no column?") );
3552 wxListHeaderData
*column
= node
->GetData();
3554 size_t count
= GetItemCount();
3556 if (width
== wxLIST_AUTOSIZE_USEHEADER
)
3558 width
= GetTextLength(column
->GetText());
3560 else if ( width
== wxLIST_AUTOSIZE
)
3564 // TODO: determine the max width somehow...
3565 width
= WIDTH_COL_DEFAULT
;
3569 wxClientDC
dc(this);
3570 dc
.SetFont( GetFont() );
3572 int max
= AUTOSIZE_COL_MARGIN
;
3574 // if the cached column width isn't valid then recalculate it
3575 if (m_aColWidths
.Item(col
)->bNeedsUpdate
)
3577 for (size_t i
= 0; i
< count
; i
++)
3579 wxListLineData
*line
= GetLine(i
);
3580 wxListItemDataList::compatibility_iterator n
= line
->m_items
.Item( col
);
3582 wxCHECK_RET( n
, _T("no subitem?") );
3584 wxListItemData
*itemData
= n
->GetData();
3587 itemData
->GetItem(item
);
3588 int itemWidth
= GetItemWidthWithImage(&item
);
3589 if (itemWidth
> max
)
3593 m_aColWidths
.Item(col
)->bNeedsUpdate
= false;
3594 m_aColWidths
.Item(col
)->nMaxWidth
= max
;
3597 max
= m_aColWidths
.Item(col
)->nMaxWidth
;
3598 width
= max
+ AUTOSIZE_COL_MARGIN
;
3602 column
->SetWidth( width
);
3604 // invalidate it as it has to be recalculated
3608 int wxListMainWindow::GetHeaderWidth() const
3610 if ( !m_headerWidth
)
3612 wxListMainWindow
*self
= wxConstCast(this, wxListMainWindow
);
3614 size_t count
= GetColumnCount();
3615 for ( size_t col
= 0; col
< count
; col
++ )
3617 self
->m_headerWidth
+= GetColumnWidth(col
);
3621 return m_headerWidth
;
3624 void wxListMainWindow::GetColumn( int col
, wxListItem
&item
) const
3626 wxListHeaderDataList::compatibility_iterator node
= m_columns
.Item( col
);
3627 wxCHECK_RET( node
, _T("invalid column index in GetColumn") );
3629 wxListHeaderData
*column
= node
->GetData();
3630 column
->GetItem( item
);
3633 int wxListMainWindow::GetColumnWidth( int col
) const
3635 wxListHeaderDataList::compatibility_iterator node
= m_columns
.Item( col
);
3636 wxCHECK_MSG( node
, 0, _T("invalid column index") );
3638 wxListHeaderData
*column
= node
->GetData();
3639 return column
->GetWidth();
3642 // ----------------------------------------------------------------------------
3644 // ----------------------------------------------------------------------------
3646 void wxListMainWindow::SetItem( wxListItem
&item
)
3648 long id
= item
.m_itemId
;
3649 wxCHECK_RET( id
>= 0 && (size_t)id
< GetItemCount(),
3650 _T("invalid item index in SetItem") );
3654 wxListLineData
*line
= GetLine((size_t)id
);
3655 line
->SetItem( item
.m_col
, item
);
3657 // Set item state if user wants
3658 if ( item
.m_mask
& wxLIST_MASK_STATE
)
3659 SetItemState( item
.m_itemId
, item
.m_state
, item
.m_state
);
3663 // update the Max Width Cache if needed
3664 int width
= GetItemWidthWithImage(&item
);
3666 if (width
> m_aColWidths
.Item(item
.m_col
)->nMaxWidth
)
3667 m_aColWidths
.Item(item
.m_col
)->nMaxWidth
= width
;
3671 // update the item on screen
3673 GetItemRect(id
, rectItem
);
3674 RefreshRect(rectItem
);
3677 void wxListMainWindow::SetItemStateAll(long state
, long stateMask
)
3682 // first deal with selection
3683 if ( stateMask
& wxLIST_STATE_SELECTED
)
3685 // set/clear select state
3688 // optimized version for virtual listctrl.
3689 m_selStore
.SelectRange(0, GetItemCount() - 1, state
== wxLIST_STATE_SELECTED
);
3692 else if ( state
& wxLIST_STATE_SELECTED
)
3694 const long count
= GetItemCount();
3695 for( long i
= 0; i
< count
; i
++ )
3697 SetItemState( i
, wxLIST_STATE_SELECTED
, wxLIST_STATE_SELECTED
);
3703 // clear for non virtual (somewhat optimized by using GetNextItem())
3705 while ( (i
= GetNextItem(i
, wxLIST_NEXT_ALL
, wxLIST_STATE_SELECTED
)) != -1 )
3707 SetItemState( i
, 0, wxLIST_STATE_SELECTED
);
3712 if ( HasCurrent() && (state
== 0) && (stateMask
& wxLIST_STATE_FOCUSED
) )
3714 // unfocus all: only one item can be focussed, so clearing focus for
3715 // all items is simply clearing focus of the focussed item.
3716 SetItemState(m_current
, state
, stateMask
);
3718 //(setting focus to all items makes no sense, so it is not handled here.)
3721 void wxListMainWindow::SetItemState( long litem
, long state
, long stateMask
)
3725 SetItemStateAll(state
, stateMask
);
3729 wxCHECK_RET( litem
>= 0 && (size_t)litem
< GetItemCount(),
3730 _T("invalid list ctrl item index in SetItem") );
3732 size_t oldCurrent
= m_current
;
3733 size_t item
= (size_t)litem
; // safe because of the check above
3735 // do we need to change the focus?
3736 if ( stateMask
& wxLIST_STATE_FOCUSED
)
3738 if ( state
& wxLIST_STATE_FOCUSED
)
3740 // don't do anything if this item is already focused
3741 if ( item
!= m_current
)
3743 ChangeCurrent(item
);
3745 if ( oldCurrent
!= (size_t)-1 )
3747 if ( IsSingleSel() )
3749 HighlightLine(oldCurrent
, false);
3752 RefreshLine(oldCurrent
);
3755 RefreshLine( m_current
);
3760 // don't do anything if this item is not focused
3761 if ( item
== m_current
)
3765 if ( IsSingleSel() )
3767 // we must unselect the old current item as well or we
3768 // might end up with more than one selected item in a
3769 // single selection control
3770 HighlightLine(oldCurrent
, false);
3773 RefreshLine( oldCurrent
);
3778 // do we need to change the selection state?
3779 if ( stateMask
& wxLIST_STATE_SELECTED
)
3781 bool on
= (state
& wxLIST_STATE_SELECTED
) != 0;
3783 if ( IsSingleSel() )
3787 // selecting the item also makes it the focused one in the
3789 if ( m_current
!= item
)
3791 ChangeCurrent(item
);
3793 if ( oldCurrent
!= (size_t)-1 )
3795 HighlightLine( oldCurrent
, false );
3796 RefreshLine( oldCurrent
);
3802 // only the current item may be selected anyhow
3803 if ( item
!= m_current
)
3808 if ( HighlightLine(item
, on
) )
3815 int wxListMainWindow::GetItemState( long item
, long stateMask
) const
3817 wxCHECK_MSG( item
>= 0 && (size_t)item
< GetItemCount(), 0,
3818 _T("invalid list ctrl item index in GetItemState()") );
3820 int ret
= wxLIST_STATE_DONTCARE
;
3822 if ( stateMask
& wxLIST_STATE_FOCUSED
)
3824 if ( (size_t)item
== m_current
)
3825 ret
|= wxLIST_STATE_FOCUSED
;
3828 if ( stateMask
& wxLIST_STATE_SELECTED
)
3830 if ( IsHighlighted(item
) )
3831 ret
|= wxLIST_STATE_SELECTED
;
3837 void wxListMainWindow::GetItem( wxListItem
&item
) const
3839 wxCHECK_RET( item
.m_itemId
>= 0 && (size_t)item
.m_itemId
< GetItemCount(),
3840 _T("invalid item index in GetItem") );
3842 wxListLineData
*line
= GetLine((size_t)item
.m_itemId
);
3843 line
->GetItem( item
.m_col
, item
);
3845 // Get item state if user wants it
3846 if ( item
.m_mask
& wxLIST_MASK_STATE
)
3847 item
.m_state
= GetItemState( item
.m_itemId
, wxLIST_STATE_SELECTED
|
3848 wxLIST_STATE_FOCUSED
);
3851 // ----------------------------------------------------------------------------
3853 // ----------------------------------------------------------------------------
3855 size_t wxListMainWindow::GetItemCount() const
3857 return IsVirtual() ? m_countVirt
: m_lines
.GetCount();
3860 void wxListMainWindow::SetItemCount(long count
)
3862 m_selStore
.SetItemCount(count
);
3863 m_countVirt
= count
;
3865 ResetVisibleLinesRange();
3867 // scrollbars must be reset
3871 int wxListMainWindow::GetSelectedItemCount() const
3873 // deal with the quick case first
3874 if ( IsSingleSel() )
3876 return HasCurrent() ? IsHighlighted(m_current
) : false;
3879 // virtual controls remmebers all its selections itself
3881 return m_selStore
.GetSelectedCount();
3883 // TODO: we probably should maintain the number of items selected even for
3884 // non virtual controls as enumerating all lines is really slow...
3885 size_t countSel
= 0;
3886 size_t count
= GetItemCount();
3887 for ( size_t line
= 0; line
< count
; line
++ )
3889 if ( GetLine(line
)->IsHighlighted() )
3896 // ----------------------------------------------------------------------------
3897 // item position/size
3898 // ----------------------------------------------------------------------------
3900 wxRect
wxListMainWindow::GetViewRect() const
3902 wxASSERT_MSG( !HasFlag(wxLC_REPORT
| wxLC_LIST
),
3903 _T("wxListCtrl::GetViewRect() only works in icon mode") );
3905 // we need to find the longest/tallest label
3908 const int count
= GetItemCount();
3911 for ( int i
= 0; i
< count
; i
++ )
3916 wxCoord x
= r
.GetRight(),
3926 // some fudge needed to make it look prettier
3927 xMax
+= 2*EXTRA_BORDER_X
;
3928 yMax
+= 2*EXTRA_BORDER_Y
;
3930 // account for the scrollbars if necessary
3931 const wxSize sizeAll
= GetClientSize();
3932 if ( xMax
> sizeAll
.x
)
3933 yMax
+= wxSystemSettings::GetMetric(wxSYS_HSCROLL_Y
);
3934 if ( yMax
> sizeAll
.y
)
3935 xMax
+= wxSystemSettings::GetMetric(wxSYS_VSCROLL_X
);
3937 return wxRect(0, 0, xMax
, yMax
);
3940 void wxListMainWindow::GetItemRect( long index
, wxRect
&rect
) const
3942 wxCHECK_RET( index
>= 0 && (size_t)index
< GetItemCount(),
3943 _T("invalid index in GetItemRect") );
3945 // ensure that we're laid out, otherwise we could return nonsense
3948 wxConstCast(this, wxListMainWindow
)->
3949 RecalculatePositions(true /* no refresh */);
3952 rect
= GetLineRect((size_t)index
);
3954 CalcScrolledPosition(rect
.x
, rect
.y
, &rect
.x
, &rect
.y
);
3957 bool wxListMainWindow::GetItemPosition(long item
, wxPoint
& pos
) const
3960 GetItemRect(item
, rect
);
3968 // ----------------------------------------------------------------------------
3969 // geometry calculation
3970 // ----------------------------------------------------------------------------
3972 void wxListMainWindow::RecalculatePositions(bool noRefresh
)
3974 wxClientDC
dc( this );
3975 dc
.SetFont( GetFont() );
3977 const size_t count
= GetItemCount();
3980 if ( HasFlag(wxLC_ICON
) )
3981 iconSpacing
= m_normal_spacing
;
3982 else if ( HasFlag(wxLC_SMALL_ICON
) )
3983 iconSpacing
= m_small_spacing
;
3987 // Note that we do not call GetClientSize() here but
3988 // GetSize() and subtract the border size for sunken
3989 // borders manually. This is technically incorrect,
3990 // but we need to know the client area's size WITHOUT
3991 // scrollbars here. Since we don't know if there are
3992 // any scrollbars, we use GetSize() instead. Another
3993 // solution would be to call SetScrollbars() here to
3994 // remove the scrollbars and call GetClientSize() then,
3995 // but this might result in flicker and - worse - will
3996 // reset the scrollbars to 0 which is not good at all
3997 // if you resize a dialog/window, but don't want to
3998 // reset the window scrolling. RR.
3999 // Furthermore, we actually do NOT subtract the border
4000 // width as 2 pixels is just the extra space which we
4001 // need around the actual content in the window. Other-
4002 // wise the text would e.g. touch the upper border. RR.
4005 GetSize( &clientWidth
, &clientHeight
);
4007 const int lineHeight
= GetLineHeight();
4009 if ( InReportView() )
4011 // all lines have the same height and we scroll one line per step
4012 int entireHeight
= count
*lineHeight
+ LINE_SPACING
;
4014 m_linesPerPage
= clientHeight
/ lineHeight
;
4016 ResetVisibleLinesRange();
4018 SetScrollbars( SCROLL_UNIT_X
, lineHeight
,
4019 GetHeaderWidth() / SCROLL_UNIT_X
,
4020 (entireHeight
+ lineHeight
- 1) / lineHeight
,
4021 GetScrollPos(wxHORIZONTAL
),
4022 GetScrollPos(wxVERTICAL
),
4027 // we have 3 different layout strategies: either layout all items
4028 // horizontally/vertically (wxLC_ALIGN_XXX styles explicitly given) or
4029 // to arrange them in top to bottom, left to right (don't ask me why
4030 // not the other way round...) order
4031 if ( HasFlag(wxLC_ALIGN_LEFT
| wxLC_ALIGN_TOP
) )
4033 int x
= EXTRA_BORDER_X
;
4034 int y
= EXTRA_BORDER_Y
;
4036 wxCoord widthMax
= 0;
4039 for ( i
= 0; i
< count
; i
++ )
4041 wxListLineData
*line
= GetLine(i
);
4042 line
->CalculateSize( &dc
, iconSpacing
);
4043 line
->SetPosition( x
, y
, iconSpacing
);
4045 wxSize sizeLine
= GetLineSize(i
);
4047 if ( HasFlag(wxLC_ALIGN_TOP
) )
4049 if ( sizeLine
.x
> widthMax
)
4050 widthMax
= sizeLine
.x
;
4054 else // wxLC_ALIGN_LEFT
4056 x
+= sizeLine
.x
+ MARGIN_BETWEEN_ROWS
;
4060 if ( HasFlag(wxLC_ALIGN_TOP
) )
4062 // traverse the items again and tweak their sizes so that they are
4063 // all the same in a row
4064 for ( i
= 0; i
< count
; i
++ )
4066 wxListLineData
*line
= GetLine(i
);
4067 line
->m_gi
->ExtendWidth(widthMax
);
4076 (x
+ SCROLL_UNIT_X
) / SCROLL_UNIT_X
,
4077 (y
+ lineHeight
) / lineHeight
,
4078 GetScrollPos( wxHORIZONTAL
),
4079 GetScrollPos( wxVERTICAL
),
4083 else // "flowed" arrangement, the most complicated case
4085 // at first we try without any scrollbars, if the items don't fit into
4086 // the window, we recalculate after subtracting the space taken by the
4089 int entireWidth
= 0;
4091 for (int tries
= 0; tries
< 2; tries
++)
4093 entireWidth
= 2*EXTRA_BORDER_X
;
4097 // Now we have decided that the items do not fit into the
4098 // client area, so we need a scrollbar
4099 entireWidth
+= SCROLL_UNIT_X
;
4102 int x
= EXTRA_BORDER_X
;
4103 int y
= EXTRA_BORDER_Y
;
4104 int maxWidthInThisRow
= 0;
4107 int currentlyVisibleLines
= 0;
4109 for (size_t i
= 0; i
< count
; i
++)
4111 currentlyVisibleLines
++;
4112 wxListLineData
*line
= GetLine(i
);
4113 line
->CalculateSize( &dc
, iconSpacing
);
4114 line
->SetPosition( x
, y
, iconSpacing
);
4116 wxSize sizeLine
= GetLineSize(i
);
4118 if ( maxWidthInThisRow
< sizeLine
.x
)
4119 maxWidthInThisRow
= sizeLine
.x
;
4122 if (currentlyVisibleLines
> m_linesPerPage
)
4123 m_linesPerPage
= currentlyVisibleLines
;
4125 if ( y
+ sizeLine
.y
>= clientHeight
)
4127 currentlyVisibleLines
= 0;
4129 maxWidthInThisRow
+= MARGIN_BETWEEN_ROWS
;
4130 x
+= maxWidthInThisRow
;
4131 entireWidth
+= maxWidthInThisRow
;
4132 maxWidthInThisRow
= 0;
4135 // We have reached the last item.
4136 if ( i
== count
- 1 )
4137 entireWidth
+= maxWidthInThisRow
;
4139 if ( (tries
== 0) &&
4140 (entireWidth
+ SCROLL_UNIT_X
> clientWidth
) )
4142 clientHeight
-= wxSystemSettings::
4143 GetMetric(wxSYS_HSCROLL_Y
);
4148 if ( i
== count
- 1 )
4149 tries
= 1; // Everything fits, no second try required.
4157 (entireWidth
+ SCROLL_UNIT_X
) / SCROLL_UNIT_X
,
4159 GetScrollPos( wxHORIZONTAL
),
4168 // FIXME: why should we call it from here?
4175 void wxListMainWindow::RefreshAll()
4180 wxListHeaderWindow
*headerWin
= GetListCtrl()->m_headerWin
;
4181 if ( headerWin
&& headerWin
->m_dirty
)
4183 headerWin
->m_dirty
= false;
4184 headerWin
->Refresh();
4188 void wxListMainWindow::UpdateCurrent()
4190 if ( !HasCurrent() && !IsEmpty() )
4196 long wxListMainWindow::GetNextItem( long item
,
4197 int WXUNUSED(geometry
),
4201 max
= GetItemCount();
4202 wxCHECK_MSG( (ret
== -1) || (ret
< max
), -1,
4203 _T("invalid listctrl index in GetNextItem()") );
4205 // notice that we start with the next item (or the first one if item == -1)
4206 // and this is intentional to allow writing a simple loop to iterate over
4207 // all selected items
4211 // this is not an error because the index was ok initially, just no
4222 size_t count
= GetItemCount();
4223 for ( size_t line
= (size_t)ret
; line
< count
; line
++ )
4225 if ( (state
& wxLIST_STATE_FOCUSED
) && (line
== m_current
) )
4228 if ( (state
& wxLIST_STATE_SELECTED
) && IsHighlighted(line
) )
4235 // ----------------------------------------------------------------------------
4237 // ----------------------------------------------------------------------------
4239 void wxListMainWindow::DeleteItem( long lindex
)
4241 size_t count
= GetItemCount();
4243 wxCHECK_RET( (lindex
>= 0) && ((size_t)lindex
< count
),
4244 _T("invalid item index in DeleteItem") );
4246 size_t index
= (size_t)lindex
;
4248 // we don't need to adjust the index for the previous items
4249 if ( HasCurrent() && m_current
>= index
)
4251 // if the current item is being deleted, we want the next one to
4252 // become selected - unless there is no next one - so don't adjust
4253 // m_current in this case
4254 if ( m_current
!= index
|| m_current
== count
- 1 )
4260 if ( InReportView() )
4262 // mark the Column Max Width cache as dirty if the items in the line
4263 // we're deleting contain the Max Column Width
4264 wxListLineData
* const line
= GetLine(index
);
4265 wxListItemDataList::compatibility_iterator n
;
4266 wxListItemData
*itemData
;
4270 for (size_t i
= 0; i
< m_columns
.GetCount(); i
++)
4272 n
= line
->m_items
.Item( i
);
4273 itemData
= n
->GetData();
4274 itemData
->GetItem(item
);
4276 itemWidth
= GetItemWidthWithImage(&item
);
4278 if (itemWidth
>= m_aColWidths
.Item(i
)->nMaxWidth
)
4279 m_aColWidths
.Item(i
)->bNeedsUpdate
= true;
4282 ResetVisibleLinesRange();
4289 m_selStore
.OnItemDelete(index
);
4293 m_lines
.RemoveAt( index
);
4296 // we need to refresh the (vert) scrollbar as the number of items changed
4299 SendNotify( index
, wxEVT_COMMAND_LIST_DELETE_ITEM
);
4301 RefreshAfter(index
);
4304 void wxListMainWindow::DeleteColumn( int col
)
4306 wxListHeaderDataList::compatibility_iterator node
= m_columns
.Item( col
);
4308 wxCHECK_RET( node
, wxT("invalid column index in DeleteColumn()") );
4311 delete node
->GetData();
4312 m_columns
.Erase( node
);
4316 // update all the items
4317 for ( size_t i
= 0; i
< m_lines
.GetCount(); i
++ )
4319 wxListLineData
* const line
= GetLine(i
);
4320 wxListItemDataList::compatibility_iterator n
= line
->m_items
.Item( col
);
4321 delete n
->GetData();
4322 line
->m_items
.Erase(n
);
4326 if ( InReportView() ) // we only cache max widths when in Report View
4328 delete m_aColWidths
.Item(col
);
4329 m_aColWidths
.RemoveAt(col
);
4332 // invalidate it as it has to be recalculated
4336 void wxListMainWindow::DoDeleteAllItems()
4340 // nothing to do - in particular, don't send the event
4346 // to make the deletion of all items faster, we don't send the
4347 // notifications for each item deletion in this case but only one event
4348 // for all of them: this is compatible with wxMSW and documented in
4349 // DeleteAllItems() description
4351 wxListEvent
event( wxEVT_COMMAND_LIST_DELETE_ALL_ITEMS
, GetParent()->GetId() );
4352 event
.SetEventObject( GetParent() );
4353 GetParent()->GetEventHandler()->ProcessEvent( event
);
4362 if ( InReportView() )
4364 ResetVisibleLinesRange();
4365 for (size_t i
= 0; i
< m_aColWidths
.GetCount(); i
++)
4367 m_aColWidths
.Item(i
)->bNeedsUpdate
= true;
4374 void wxListMainWindow::DeleteAllItems()
4378 RecalculatePositions();
4381 void wxListMainWindow::DeleteEverything()
4383 WX_CLEAR_LIST(wxListHeaderDataList
, m_columns
);
4384 WX_CLEAR_ARRAY(m_aColWidths
);
4389 // ----------------------------------------------------------------------------
4390 // scanning for an item
4391 // ----------------------------------------------------------------------------
4393 void wxListMainWindow::EnsureVisible( long index
)
4395 wxCHECK_RET( index
>= 0 && (size_t)index
< GetItemCount(),
4396 _T("invalid index in EnsureVisible") );
4398 // We have to call this here because the label in question might just have
4399 // been added and its position is not known yet
4402 RecalculatePositions(true /* no refresh */);
4405 MoveToItem((size_t)index
);
4408 long wxListMainWindow::FindItem(long start
, const wxString
& str
, bool WXUNUSED(partial
) )
4415 size_t count
= GetItemCount();
4416 for ( size_t i
= (size_t)pos
; i
< count
; i
++ )
4418 wxListLineData
*line
= GetLine(i
);
4419 if ( line
->GetText(0) == tmp
)
4426 long wxListMainWindow::FindItem(long start
, wxUIntPtr data
)
4432 size_t count
= GetItemCount();
4433 for (size_t i
= (size_t)pos
; i
< count
; i
++)
4435 wxListLineData
*line
= GetLine(i
);
4437 line
->GetItem( 0, item
);
4438 if (item
.m_data
== data
)
4445 long wxListMainWindow::FindItem( const wxPoint
& pt
)
4448 GetVisibleLinesRange(&topItem
, NULL
);
4451 GetItemPosition( GetItemCount()-1, p
);
4454 long id
= (long) floor( pt
.y
*double(GetItemCount()-topItem
-1)/p
.y
+topItem
);
4455 if( id
>= 0 && id
< (long)GetItemCount() )
4461 long wxListMainWindow::HitTest( int x
, int y
, int &flags
)
4463 CalcUnscrolledPosition( x
, y
, &x
, &y
);
4465 size_t count
= GetItemCount();
4467 if ( InReportView() )
4469 size_t current
= y
/ GetLineHeight();
4470 if ( current
< count
)
4472 flags
= HitTestLine(current
, x
, y
);
4479 // TODO: optimize it too! this is less simple than for report view but
4480 // enumerating all items is still not a way to do it!!
4481 for ( size_t current
= 0; current
< count
; current
++ )
4483 flags
= HitTestLine(current
, x
, y
);
4492 // ----------------------------------------------------------------------------
4494 // ----------------------------------------------------------------------------
4496 void wxListMainWindow::InsertItem( wxListItem
&item
)
4498 wxASSERT_MSG( !IsVirtual(), _T("can't be used with virtual control") );
4500 int count
= GetItemCount();
4501 wxCHECK_RET( item
.m_itemId
>= 0, _T("invalid item index") );
4503 if (item
.m_itemId
> count
)
4504 item
.m_itemId
= count
;
4506 size_t id
= item
.m_itemId
;
4510 if ( InReportView() )
4512 ResetVisibleLinesRange();
4514 // calculate the width of the item and adjust the max column width
4515 wxColWidthInfo
*pWidthInfo
= m_aColWidths
.Item(item
.GetColumn());
4516 int width
= GetItemWidthWithImage(&item
);
4517 item
.SetWidth(width
);
4518 if (width
> pWidthInfo
->nMaxWidth
)
4519 pWidthInfo
->nMaxWidth
= width
;
4522 wxListLineData
*line
= new wxListLineData(this);
4524 line
->SetItem( item
.m_col
, item
);
4526 m_lines
.Insert( line
, id
);
4530 // If an item is selected at or below the point of insertion, we need to
4531 // increment the member variables because the current row's index has gone
4533 if ( HasCurrent() && m_current
>= id
)
4538 SendNotify(id
, wxEVT_COMMAND_LIST_INSERT_ITEM
);
4540 RefreshLines(id
, GetItemCount() - 1);
4543 void wxListMainWindow::InsertColumn( long col
, wxListItem
&item
)
4546 if ( InReportView() )
4548 if (item
.m_width
== wxLIST_AUTOSIZE_USEHEADER
)
4549 item
.m_width
= GetTextLength( item
.m_text
);
4551 wxListHeaderData
*column
= new wxListHeaderData( item
);
4552 wxColWidthInfo
*colWidthInfo
= new wxColWidthInfo();
4554 bool insert
= (col
>= 0) && ((size_t)col
< m_columns
.GetCount());
4557 wxListHeaderDataList::compatibility_iterator
4558 node
= m_columns
.Item( col
);
4559 m_columns
.Insert( node
, column
);
4560 m_aColWidths
.Insert( colWidthInfo
, col
);
4564 m_columns
.Append( column
);
4565 m_aColWidths
.Add( colWidthInfo
);
4570 // update all the items
4571 for ( size_t i
= 0; i
< m_lines
.GetCount(); i
++ )
4573 wxListLineData
* const line
= GetLine(i
);
4574 wxListItemData
* const data
= new wxListItemData(this);
4576 line
->m_items
.Insert(col
, data
);
4578 line
->m_items
.Append(data
);
4582 // invalidate it as it has to be recalculated
4587 int wxListMainWindow::GetItemWidthWithImage(wxListItem
* item
)
4590 wxClientDC
dc(this);
4592 dc
.SetFont( GetFont() );
4594 if (item
->GetImage() != -1)
4597 GetImageSize( item
->GetImage(), ix
, iy
);
4601 if (!item
->GetText().empty())
4604 dc
.GetTextExtent( item
->GetText(), &w
, NULL
);
4611 // ----------------------------------------------------------------------------
4613 // ----------------------------------------------------------------------------
4615 wxListCtrlCompare list_ctrl_compare_func_2
;
4616 long list_ctrl_compare_data
;
4618 int LINKAGEMODE
list_ctrl_compare_func_1( wxListLineData
**arg1
, wxListLineData
**arg2
)
4620 wxListLineData
*line1
= *arg1
;
4621 wxListLineData
*line2
= *arg2
;
4623 line1
->GetItem( 0, item
);
4624 wxUIntPtr data1
= item
.m_data
;
4625 line2
->GetItem( 0, item
);
4626 wxUIntPtr data2
= item
.m_data
;
4627 return list_ctrl_compare_func_2( data1
, data2
, list_ctrl_compare_data
);
4630 void wxListMainWindow::SortItems( wxListCtrlCompare fn
, long data
)
4632 list_ctrl_compare_func_2
= fn
;
4633 list_ctrl_compare_data
= data
;
4634 m_lines
.Sort( list_ctrl_compare_func_1
);
4638 // ----------------------------------------------------------------------------
4640 // ----------------------------------------------------------------------------
4642 void wxListMainWindow::OnScroll(wxScrollWinEvent
& event
)
4644 // update our idea of which lines are shown when we redraw the window the
4646 ResetVisibleLinesRange();
4649 #if ( defined(__WXGTK__) || defined(__WXMAC__) ) && !defined(__WXUNIVERSAL__)
4650 wxScrolledWindow::OnScroll(event
);
4652 HandleOnScroll( event
);
4655 if ( event
.GetOrientation() == wxHORIZONTAL
&& HasHeader() )
4657 wxGenericListCtrl
* lc
= GetListCtrl();
4658 wxCHECK_RET( lc
, _T("no listctrl window?") );
4660 lc
->m_headerWin
->Refresh();
4661 lc
->m_headerWin
->Update();
4665 int wxListMainWindow::GetCountPerPage() const
4667 if ( !m_linesPerPage
)
4669 wxConstCast(this, wxListMainWindow
)->
4670 m_linesPerPage
= GetClientSize().y
/ GetLineHeight();
4673 return m_linesPerPage
;
4676 void wxListMainWindow::GetVisibleLinesRange(size_t *from
, size_t *to
)
4678 wxASSERT_MSG( InReportView(), _T("this is for report mode only") );
4680 if ( m_lineFrom
== (size_t)-1 )
4682 size_t count
= GetItemCount();
4685 m_lineFrom
= GetScrollPos(wxVERTICAL
);
4687 // this may happen if SetScrollbars() hadn't been called yet
4688 if ( m_lineFrom
>= count
)
4689 m_lineFrom
= count
- 1;
4691 // we redraw one extra line but this is needed to make the redrawing
4692 // logic work when there is a fractional number of lines on screen
4693 m_lineTo
= m_lineFrom
+ m_linesPerPage
;
4694 if ( m_lineTo
>= count
)
4695 m_lineTo
= count
- 1;
4697 else // empty control
4700 m_lineTo
= (size_t)-1;
4704 wxASSERT_MSG( IsEmpty() ||
4705 (m_lineFrom
<= m_lineTo
&& m_lineTo
< GetItemCount()),
4706 _T("GetVisibleLinesRange() returns incorrect result") );
4714 // -------------------------------------------------------------------------------------
4715 // wxGenericListCtrl
4716 // -------------------------------------------------------------------------------------
4718 IMPLEMENT_DYNAMIC_CLASS(wxGenericListCtrl
, wxControl
)
4720 BEGIN_EVENT_TABLE(wxGenericListCtrl
,wxControl
)
4721 EVT_SIZE(wxGenericListCtrl::OnSize
)
4724 wxGenericListCtrl::wxGenericListCtrl()
4726 m_imageListNormal
= (wxImageListType
*) NULL
;
4727 m_imageListSmall
= (wxImageListType
*) NULL
;
4728 m_imageListState
= (wxImageListType
*) NULL
;
4730 m_ownsImageListNormal
=
4731 m_ownsImageListSmall
=
4732 m_ownsImageListState
= false;
4734 m_mainWin
= (wxListMainWindow
*) NULL
;
4735 m_headerWin
= (wxListHeaderWindow
*) NULL
;
4739 wxGenericListCtrl::~wxGenericListCtrl()
4741 if (m_ownsImageListNormal
)
4742 delete m_imageListNormal
;
4743 if (m_ownsImageListSmall
)
4744 delete m_imageListSmall
;
4745 if (m_ownsImageListState
)
4746 delete m_imageListState
;
4749 void wxGenericListCtrl::CalculateAndSetHeaderHeight()
4755 GetThemeMetric( kThemeMetricListHeaderHeight
, &h
);
4757 // we use 'g' to get the descent, too
4759 m_headerWin
->GetTextExtent(wxT("Hg"), &w
, &h
, &d
);
4760 h
+= d
+ 2 * HEADER_OFFSET_Y
+ EXTRA_HEIGHT
;
4762 // only update if changed
4763 if ( h
!= m_headerHeight
)
4767 m_headerWin
->SetSize(m_headerWin
->GetSize().x
, m_headerHeight
);
4770 ResizeReportView(true);
4775 void wxGenericListCtrl::CreateHeaderWindow()
4777 m_headerWin
= new wxListHeaderWindow
4779 this, wxID_ANY
, m_mainWin
,
4781 wxSize(GetClientSize().x
, m_headerHeight
),
4784 CalculateAndSetHeaderHeight();
4787 bool wxGenericListCtrl::Create(wxWindow
*parent
,
4792 const wxValidator
&validator
,
4793 const wxString
&name
)
4797 m_imageListState
= (wxImageListType
*) NULL
;
4798 m_ownsImageListNormal
=
4799 m_ownsImageListSmall
=
4800 m_ownsImageListState
= false;
4802 m_mainWin
= (wxListMainWindow
*) NULL
;
4803 m_headerWin
= (wxListHeaderWindow
*) NULL
;
4807 if ( !(style
& wxLC_MASK_TYPE
) )
4809 style
= style
| wxLC_LIST
;
4812 if ( !wxControl::Create( parent
, id
, pos
, size
, style
, validator
, name
) )
4815 // don't create the inner window with the border
4816 style
&= ~wxBORDER_MASK
;
4818 m_mainWin
= new wxListMainWindow( this, wxID_ANY
, wxPoint(0,0), size
, style
);
4820 #ifdef __WXMAC_CARBON__
4821 // Human Interface Guidelines ask us for a special font in this case
4822 if ( GetWindowVariant() == wxWINDOW_VARIANT_NORMAL
)
4825 font
.MacCreateThemeFont( kThemeViewsFont
) ;
4829 if ( InReportView() )
4831 CreateHeaderWindow();
4832 #ifdef __WXMAC_CARBON__
4836 font
.MacCreateThemeFont( kThemeSmallSystemFont
) ;
4837 m_headerWin
->SetFont( font
);
4838 CalculateAndSetHeaderHeight();
4841 if ( HasFlag(wxLC_NO_HEADER
) )
4843 // VZ: why do we create it at all then?
4844 m_headerWin
->Show( false );
4853 void wxGenericListCtrl::SetSingleStyle( long style
, bool add
)
4855 wxASSERT_MSG( !(style
& wxLC_VIRTUAL
),
4856 _T("wxLC_VIRTUAL can't be [un]set") );
4858 long flag
= GetWindowStyle();
4862 if (style
& wxLC_MASK_TYPE
)
4863 flag
&= ~(wxLC_MASK_TYPE
| wxLC_VIRTUAL
);
4864 if (style
& wxLC_MASK_ALIGN
)
4865 flag
&= ~wxLC_MASK_ALIGN
;
4866 if (style
& wxLC_MASK_SORT
)
4867 flag
&= ~wxLC_MASK_SORT
;
4879 SetWindowStyleFlag( flag
);
4882 void wxGenericListCtrl::SetWindowStyleFlag( long flag
)
4886 m_mainWin
->DeleteEverything();
4888 // has the header visibility changed?
4889 bool hasHeader
= HasHeader();
4890 bool willHaveHeader
= (flag
& wxLC_REPORT
) && !(flag
& wxLC_NO_HEADER
);
4892 if ( hasHeader
!= willHaveHeader
)
4899 // don't delete, just hide, as we can reuse it later
4900 m_headerWin
->Show(false);
4902 //else: nothing to do
4904 else // must show header
4908 CreateHeaderWindow();
4910 else // already have it, just show
4912 m_headerWin
->Show( true );
4916 ResizeReportView(willHaveHeader
);
4920 wxWindow::SetWindowStyleFlag( flag
);
4923 bool wxGenericListCtrl::GetColumn(int col
, wxListItem
&item
) const
4925 m_mainWin
->GetColumn( col
, item
);
4929 bool wxGenericListCtrl::SetColumn( int col
, wxListItem
& item
)
4931 m_mainWin
->SetColumn( col
, item
);
4935 int wxGenericListCtrl::GetColumnWidth( int col
) const
4937 return m_mainWin
->GetColumnWidth( col
);
4940 bool wxGenericListCtrl::SetColumnWidth( int col
, int width
)
4942 m_mainWin
->SetColumnWidth( col
, width
);
4946 int wxGenericListCtrl::GetCountPerPage() const
4948 return m_mainWin
->GetCountPerPage(); // different from Windows ?
4951 bool wxGenericListCtrl::GetItem( wxListItem
&info
) const
4953 m_mainWin
->GetItem( info
);
4957 bool wxGenericListCtrl::SetItem( wxListItem
&info
)
4959 m_mainWin
->SetItem( info
);
4963 long wxGenericListCtrl::SetItem( long index
, int col
, const wxString
& label
, int imageId
)
4966 info
.m_text
= label
;
4967 info
.m_mask
= wxLIST_MASK_TEXT
;
4968 info
.m_itemId
= index
;
4972 info
.m_image
= imageId
;
4973 info
.m_mask
|= wxLIST_MASK_IMAGE
;
4975 m_mainWin
->SetItem(info
);
4979 int wxGenericListCtrl::GetItemState( long item
, long stateMask
) const
4981 return m_mainWin
->GetItemState( item
, stateMask
);
4984 bool wxGenericListCtrl::SetItemState( long item
, long state
, long stateMask
)
4986 m_mainWin
->SetItemState( item
, state
, stateMask
);
4991 wxGenericListCtrl::SetItemImage( long item
, int image
, int WXUNUSED(selImage
) )
4994 info
.m_image
= image
;
4995 info
.m_mask
= wxLIST_MASK_IMAGE
;
4996 info
.m_itemId
= item
;
4997 m_mainWin
->SetItem( info
);
5001 wxString
wxGenericListCtrl::GetItemText( long item
) const
5003 return m_mainWin
->GetItemText(item
);
5006 void wxGenericListCtrl::SetItemText( long item
, const wxString
& str
)
5008 m_mainWin
->SetItemText(item
, str
);
5011 wxUIntPtr
wxGenericListCtrl::GetItemData( long item
) const
5014 info
.m_mask
= wxLIST_MASK_DATA
;
5015 info
.m_itemId
= item
;
5016 m_mainWin
->GetItem( info
);
5020 bool wxGenericListCtrl::SetItemData( long item
, long data
)
5023 info
.m_mask
= wxLIST_MASK_DATA
;
5024 info
.m_itemId
= item
;
5026 m_mainWin
->SetItem( info
);
5030 wxRect
wxGenericListCtrl::GetViewRect() const
5032 return m_mainWin
->GetViewRect();
5035 bool wxGenericListCtrl::GetItemRect( long item
, wxRect
&rect
, int WXUNUSED(code
) ) const
5037 m_mainWin
->GetItemRect( item
, rect
);
5038 if ( m_mainWin
->HasHeader() )
5039 rect
.y
+= m_headerHeight
+ 1;
5043 bool wxGenericListCtrl::GetItemPosition( long item
, wxPoint
& pos
) const
5045 m_mainWin
->GetItemPosition( item
, pos
);
5049 bool wxGenericListCtrl::SetItemPosition( long WXUNUSED(item
), const wxPoint
& WXUNUSED(pos
) )
5054 int wxGenericListCtrl::GetItemCount() const
5056 return m_mainWin
->GetItemCount();
5059 int wxGenericListCtrl::GetColumnCount() const
5061 return m_mainWin
->GetColumnCount();
5064 void wxGenericListCtrl::SetItemSpacing( int spacing
, bool isSmall
)
5066 m_mainWin
->SetItemSpacing( spacing
, isSmall
);
5069 wxSize
wxGenericListCtrl::GetItemSpacing() const
5071 const int spacing
= m_mainWin
->GetItemSpacing(HasFlag(wxLC_SMALL_ICON
));
5073 return wxSize(spacing
, spacing
);
5076 int wxGenericListCtrl::GetItemSpacing( bool isSmall
) const
5078 return m_mainWin
->GetItemSpacing( isSmall
);
5081 void wxGenericListCtrl::SetItemTextColour( long item
, const wxColour
&col
)
5084 info
.m_itemId
= item
;
5085 info
.SetTextColour( col
);
5086 m_mainWin
->SetItem( info
);
5089 wxColour
wxGenericListCtrl::GetItemTextColour( long item
) const
5092 info
.m_itemId
= item
;
5093 m_mainWin
->GetItem( info
);
5094 return info
.GetTextColour();
5097 void wxGenericListCtrl::SetItemBackgroundColour( long item
, const wxColour
&col
)
5100 info
.m_itemId
= item
;
5101 info
.SetBackgroundColour( col
);
5102 m_mainWin
->SetItem( info
);
5105 wxColour
wxGenericListCtrl::GetItemBackgroundColour( long item
) const
5108 info
.m_itemId
= item
;
5109 m_mainWin
->GetItem( info
);
5110 return info
.GetBackgroundColour();
5113 void wxGenericListCtrl::SetItemFont( long item
, const wxFont
&f
)
5116 info
.m_itemId
= item
;
5118 m_mainWin
->SetItem( info
);
5121 wxFont
wxGenericListCtrl::GetItemFont( long item
) const
5124 info
.m_itemId
= item
;
5125 m_mainWin
->GetItem( info
);
5126 return info
.GetFont();
5129 int wxGenericListCtrl::GetSelectedItemCount() const
5131 return m_mainWin
->GetSelectedItemCount();
5134 wxColour
wxGenericListCtrl::GetTextColour() const
5136 return GetForegroundColour();
5139 void wxGenericListCtrl::SetTextColour(const wxColour
& col
)
5141 SetForegroundColour(col
);
5144 long wxGenericListCtrl::GetTopItem() const
5147 m_mainWin
->GetVisibleLinesRange(&top
, NULL
);
5151 long wxGenericListCtrl::GetNextItem( long item
, int geom
, int state
) const
5153 return m_mainWin
->GetNextItem( item
, geom
, state
);
5156 wxImageListType
*wxGenericListCtrl::GetImageList(int which
) const
5158 if (which
== wxIMAGE_LIST_NORMAL
)
5160 return m_imageListNormal
;
5162 else if (which
== wxIMAGE_LIST_SMALL
)
5164 return m_imageListSmall
;
5166 else if (which
== wxIMAGE_LIST_STATE
)
5168 return m_imageListState
;
5170 return (wxImageListType
*) NULL
;
5173 void wxGenericListCtrl::SetImageList( wxImageListType
*imageList
, int which
)
5175 if ( which
== wxIMAGE_LIST_NORMAL
)
5177 if (m_ownsImageListNormal
) delete m_imageListNormal
;
5178 m_imageListNormal
= imageList
;
5179 m_ownsImageListNormal
= false;
5181 else if ( which
== wxIMAGE_LIST_SMALL
)
5183 if (m_ownsImageListSmall
) delete m_imageListSmall
;
5184 m_imageListSmall
= imageList
;
5185 m_ownsImageListSmall
= false;
5187 else if ( which
== wxIMAGE_LIST_STATE
)
5189 if (m_ownsImageListState
) delete m_imageListState
;
5190 m_imageListState
= imageList
;
5191 m_ownsImageListState
= false;
5194 m_mainWin
->SetImageList( imageList
, which
);
5197 void wxGenericListCtrl::AssignImageList(wxImageListType
*imageList
, int which
)
5199 SetImageList(imageList
, which
);
5200 if ( which
== wxIMAGE_LIST_NORMAL
)
5201 m_ownsImageListNormal
= true;
5202 else if ( which
== wxIMAGE_LIST_SMALL
)
5203 m_ownsImageListSmall
= true;
5204 else if ( which
== wxIMAGE_LIST_STATE
)
5205 m_ownsImageListState
= true;
5208 bool wxGenericListCtrl::Arrange( int WXUNUSED(flag
) )
5213 bool wxGenericListCtrl::DeleteItem( long item
)
5215 m_mainWin
->DeleteItem( item
);
5219 bool wxGenericListCtrl::DeleteAllItems()
5221 m_mainWin
->DeleteAllItems();
5225 bool wxGenericListCtrl::DeleteAllColumns()
5227 size_t count
= m_mainWin
->m_columns
.GetCount();
5228 for ( size_t n
= 0; n
< count
; n
++ )
5234 void wxGenericListCtrl::ClearAll()
5236 m_mainWin
->DeleteEverything();
5239 bool wxGenericListCtrl::DeleteColumn( int col
)
5241 m_mainWin
->DeleteColumn( col
);
5243 // if we don't have the header any longer, we need to relayout the window
5244 if ( !GetColumnCount() )
5246 ResizeReportView(false /* no header */);
5252 void wxGenericListCtrl::Edit( long item
)
5254 m_mainWin
->EditLabel( item
);
5257 bool wxGenericListCtrl::EnsureVisible( long item
)
5259 m_mainWin
->EnsureVisible( item
);
5263 long wxGenericListCtrl::FindItem( long start
, const wxString
& str
, bool partial
)
5265 return m_mainWin
->FindItem( start
, str
, partial
);
5268 long wxGenericListCtrl::FindItem( long start
, wxUIntPtr data
)
5270 return m_mainWin
->FindItem( start
, data
);
5273 long wxGenericListCtrl::FindItem( long WXUNUSED(start
), const wxPoint
& pt
,
5274 int WXUNUSED(direction
))
5276 return m_mainWin
->FindItem( pt
);
5279 long wxGenericListCtrl::HitTest( const wxPoint
&point
, int &flags
)
5281 return m_mainWin
->HitTest( (int)point
.x
, (int)point
.y
, flags
);
5284 long wxGenericListCtrl::InsertItem( wxListItem
& info
)
5286 m_mainWin
->InsertItem( info
);
5287 return info
.m_itemId
;
5290 long wxGenericListCtrl::InsertItem( long index
, const wxString
&label
)
5293 info
.m_text
= label
;
5294 info
.m_mask
= wxLIST_MASK_TEXT
;
5295 info
.m_itemId
= index
;
5296 return InsertItem( info
);
5299 long wxGenericListCtrl::InsertItem( long index
, int imageIndex
)
5302 info
.m_mask
= wxLIST_MASK_IMAGE
;
5303 info
.m_image
= imageIndex
;
5304 info
.m_itemId
= index
;
5305 return InsertItem( info
);
5308 long wxGenericListCtrl::InsertItem( long index
, const wxString
&label
, int imageIndex
)
5311 info
.m_text
= label
;
5312 info
.m_image
= imageIndex
;
5313 info
.m_mask
= wxLIST_MASK_TEXT
| wxLIST_MASK_IMAGE
;
5314 info
.m_itemId
= index
;
5315 return InsertItem( info
);
5318 long wxGenericListCtrl::InsertColumn( long col
, wxListItem
&item
)
5320 wxCHECK_MSG( m_headerWin
, -1, _T("can't add column in non report mode") );
5322 m_mainWin
->InsertColumn( col
, item
);
5324 // if we hadn't had header before and have it now we need to relayout the
5326 if ( GetColumnCount() == 1 && m_mainWin
->HasHeader() )
5328 ResizeReportView(true /* have header */);
5331 m_headerWin
->Refresh();
5336 long wxGenericListCtrl::InsertColumn( long col
, const wxString
&heading
,
5337 int format
, int width
)
5340 item
.m_mask
= wxLIST_MASK_TEXT
| wxLIST_MASK_FORMAT
;
5341 item
.m_text
= heading
;
5344 item
.m_mask
|= wxLIST_MASK_WIDTH
;
5345 item
.m_width
= width
;
5347 item
.m_format
= format
;
5349 return InsertColumn( col
, item
);
5352 bool wxGenericListCtrl::ScrollList( int WXUNUSED(dx
), int WXUNUSED(dy
) )
5358 // fn is a function which takes 3 long arguments: item1, item2, data.
5359 // item1 is the long data associated with a first item (NOT the index).
5360 // item2 is the long data associated with a second item (NOT the index).
5361 // data is the same value as passed to SortItems.
5362 // The return value is a negative number if the first item should precede the second
5363 // item, a positive number of the second item should precede the first,
5364 // or zero if the two items are equivalent.
5365 // data is arbitrary data to be passed to the sort function.
5367 bool wxGenericListCtrl::SortItems( wxListCtrlCompare fn
, long data
)
5369 m_mainWin
->SortItems( fn
, data
);
5373 // ----------------------------------------------------------------------------
5375 // ----------------------------------------------------------------------------
5377 void wxGenericListCtrl::OnSize(wxSizeEvent
& WXUNUSED(event
))
5382 ResizeReportView(m_mainWin
->HasHeader());
5384 m_mainWin
->RecalculatePositions();
5387 void wxGenericListCtrl::ResizeReportView(bool showHeader
)
5390 GetClientSize( &cw
, &ch
);
5394 m_headerWin
->SetSize( 0, 0, cw
, m_headerHeight
);
5395 m_mainWin
->SetSize( 0, m_headerHeight
+ 1, cw
, ch
- m_headerHeight
- 1 );
5397 else // no header window
5399 m_mainWin
->SetSize( 0, 0, cw
, ch
);
5403 void wxGenericListCtrl::OnInternalIdle()
5405 wxWindow::OnInternalIdle();
5407 // do it only if needed
5408 if ( !m_mainWin
->m_dirty
)
5411 m_mainWin
->RecalculatePositions();
5414 // ----------------------------------------------------------------------------
5416 // ----------------------------------------------------------------------------
5418 bool wxGenericListCtrl::SetBackgroundColour( const wxColour
&colour
)
5422 m_mainWin
->SetBackgroundColour( colour
);
5423 m_mainWin
->m_dirty
= true;
5429 bool wxGenericListCtrl::SetForegroundColour( const wxColour
&colour
)
5431 if ( !wxWindow::SetForegroundColour( colour
) )
5436 m_mainWin
->SetForegroundColour( colour
);
5437 m_mainWin
->m_dirty
= true;
5442 m_headerWin
->SetForegroundColour( colour
);
5448 bool wxGenericListCtrl::SetFont( const wxFont
&font
)
5450 if ( !wxWindow::SetFont( font
) )
5455 m_mainWin
->SetFont( font
);
5456 m_mainWin
->m_dirty
= true;
5461 m_headerWin
->SetFont( font
);
5462 CalculateAndSetHeaderHeight();
5473 #include "wx/listbox.h"
5478 wxGenericListCtrl::GetClassDefaultAttributes(wxWindowVariant variant
)
5481 // Use the same color scheme as wxListBox
5482 return wxListBox::GetClassDefaultAttributes(variant
);
5484 wxUnusedVar(variant
);
5485 wxVisualAttributes attr
;
5486 attr
.colFg
= wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT
);
5487 attr
.colBg
= wxSystemSettings::GetColour(wxSYS_COLOUR_LISTBOX
);
5488 attr
.font
= wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT
);
5493 // ----------------------------------------------------------------------------
5494 // methods forwarded to m_mainWin
5495 // ----------------------------------------------------------------------------
5497 #if wxUSE_DRAG_AND_DROP
5499 void wxGenericListCtrl::SetDropTarget( wxDropTarget
*dropTarget
)
5501 m_mainWin
->SetDropTarget( dropTarget
);
5504 wxDropTarget
*wxGenericListCtrl::GetDropTarget() const
5506 return m_mainWin
->GetDropTarget();
5509 #endif // wxUSE_DRAG_AND_DROP
5511 bool wxGenericListCtrl::SetCursor( const wxCursor
&cursor
)
5513 return m_mainWin
? m_mainWin
->wxWindow::SetCursor(cursor
) : false;
5516 wxColour
wxGenericListCtrl::GetBackgroundColour() const
5518 return m_mainWin
? m_mainWin
->GetBackgroundColour() : wxColour();
5521 wxColour
wxGenericListCtrl::GetForegroundColour() const
5523 return m_mainWin
? m_mainWin
->GetForegroundColour() : wxColour();
5526 bool wxGenericListCtrl::DoPopupMenu( wxMenu
*menu
, int x
, int y
)
5529 return m_mainWin
->PopupMenu( menu
, x
, y
);
5532 #endif // wxUSE_MENUS
5535 void wxGenericListCtrl::SetFocus()
5537 /* The test in window.cpp fails as we are a composite
5538 window, so it checks against "this", but not m_mainWin. */
5539 if ( DoFindFocus() != this )
5540 m_mainWin
->SetFocus();
5543 wxSize
wxGenericListCtrl::DoGetBestSize() const
5545 // Something is better than nothing...
5546 // 100x80 is what the MSW version will get from the default
5547 // wxControl::DoGetBestSize
5548 return wxSize(100,80);
5551 // ----------------------------------------------------------------------------
5552 // virtual list control support
5553 // ----------------------------------------------------------------------------
5555 wxString
wxGenericListCtrl::OnGetItemText(long WXUNUSED(item
), long WXUNUSED(col
)) const
5557 // this is a pure virtual function, in fact - which is not really pure
5558 // because the controls which are not virtual don't need to implement it
5559 wxFAIL_MSG( _T("wxGenericListCtrl::OnGetItemText not supposed to be called") );
5561 return wxEmptyString
;
5564 int wxGenericListCtrl::OnGetItemImage(long WXUNUSED(item
)) const
5566 wxCHECK_MSG(!GetImageList(wxIMAGE_LIST_SMALL
),
5568 wxT("List control has an image list, OnGetItemImage should be overridden."));
5573 wxGenericListCtrl::OnGetItemAttr(long WXUNUSED_UNLESS_DEBUG(item
)) const
5575 wxASSERT_MSG( item
>= 0 && item
< GetItemCount(),
5576 _T("invalid item index in OnGetItemAttr()") );
5578 // no attributes by default
5582 void wxGenericListCtrl::SetItemCount(long count
)
5584 wxASSERT_MSG( IsVirtual(), _T("this is for virtual controls only") );
5586 m_mainWin
->SetItemCount(count
);
5589 void wxGenericListCtrl::RefreshItem(long item
)
5591 m_mainWin
->RefreshLine(item
);
5594 void wxGenericListCtrl::RefreshItems(long itemFrom
, long itemTo
)
5596 m_mainWin
->RefreshLines(itemFrom
, itemTo
);
5600 * Generic wxListCtrl is more or less a container for two other
5601 * windows which drawings are done upon. These are namely
5602 * 'm_headerWin' and 'm_mainWin'.
5603 * Here we override 'virtual wxWindow::Refresh()' to mimic the
5604 * behaviour wxListCtrl has under wxMSW.
5606 void wxGenericListCtrl::Refresh(bool eraseBackground
, const wxRect
*rect
)
5610 // The easy case, no rectangle specified.
5612 m_headerWin
->Refresh(eraseBackground
);
5615 m_mainWin
->Refresh(eraseBackground
);
5619 // Refresh the header window
5622 wxRect rectHeader
= m_headerWin
->GetRect();
5623 rectHeader
.Intersect(*rect
);
5624 if (rectHeader
.GetWidth() && rectHeader
.GetHeight())
5627 m_headerWin
->GetPosition(&x
, &y
);
5628 rectHeader
.Offset(-x
, -y
);
5629 m_headerWin
->Refresh(eraseBackground
, &rectHeader
);
5634 // Refresh the main window
5637 wxRect rectMain
= m_mainWin
->GetRect();
5638 rectMain
.Intersect(*rect
);
5639 if (rectMain
.GetWidth() && rectMain
.GetHeight())
5642 m_mainWin
->GetPosition(&x
, &y
);
5643 rectMain
.Offset(-x
, -y
);
5644 m_mainWin
->Refresh(eraseBackground
, &rectMain
);
5650 void wxGenericListCtrl::Freeze()
5652 m_mainWin
->Freeze();
5655 void wxGenericListCtrl::Thaw()
5660 #endif // wxUSE_LISTCTRL