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 /////////////////////////////////////////////////////////////////////////////
13 // 1. we need to implement searching/sorting for virtual controls somehow
14 // 2. when changing selection the lines are refreshed twice
17 // For compilers that support precompilation, includes "wx.h".
18 #include "wx/wxprec.h"
28 #include "wx/dynarray.h"
29 #include "wx/dcscreen.h"
30 #include "wx/textctrl.h"
33 // under Win32 we always use the native version and also may use the generic
34 // one, however some things should be done only if we use only the generic
36 #if defined(__WIN32__) && !defined(__WXUNIVERSAL__)
37 #define HAVE_NATIVE_LISTCTRL
40 // if we have the native control, wx/listctrl.h declares it and not this one
41 #ifdef HAVE_NATIVE_LISTCTRL
42 #include "wx/generic/listctrl.h"
43 #else // !HAVE_NATIVE_LISTCTRL
44 #include "wx/listctrl.h"
46 // if we have a native version, its implementation file does all this
47 IMPLEMENT_DYNAMIC_CLASS(wxListItem
, wxObject
)
48 IMPLEMENT_DYNAMIC_CLASS(wxListView
, wxListCtrl
)
49 IMPLEMENT_DYNAMIC_CLASS(wxListEvent
, wxNotifyEvent
)
51 IMPLEMENT_DYNAMIC_CLASS(wxListCtrl
, wxGenericListCtrl
)
52 #endif // HAVE_NATIVE_LISTCTRL/!HAVE_NATIVE_LISTCTRL
54 #include "wx/selstore.h"
55 #include "wx/renderer.h"
59 #include "wx/mac/private.h"
63 // NOTE: If using the wxListBox visual attributes works everywhere then this can
64 // be removed, as well as the #else case below.
65 #define _USE_VISATTR 0
68 // ----------------------------------------------------------------------------
70 // ----------------------------------------------------------------------------
72 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_BEGIN_DRAG
)
73 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_BEGIN_RDRAG
)
74 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_BEGIN_LABEL_EDIT
)
75 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_END_LABEL_EDIT
)
76 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_DELETE_ITEM
)
77 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_DELETE_ALL_ITEMS
)
78 #if WXWIN_COMPATIBILITY_2_4
79 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_GET_INFO
)
80 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_SET_INFO
)
82 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_ITEM_SELECTED
)
83 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_ITEM_DESELECTED
)
84 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_KEY_DOWN
)
85 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_INSERT_ITEM
)
86 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_COL_CLICK
)
87 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_COL_RIGHT_CLICK
)
88 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_COL_BEGIN_DRAG
)
89 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_COL_DRAGGING
)
90 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_COL_END_DRAG
)
91 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_ITEM_RIGHT_CLICK
)
92 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_ITEM_MIDDLE_CLICK
)
93 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_ITEM_ACTIVATED
)
94 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_ITEM_FOCUSED
)
95 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_CACHE_HINT
)
97 // ----------------------------------------------------------------------------
99 // ----------------------------------------------------------------------------
101 // // the height of the header window (FIXME: should depend on its font!)
102 // static const int HEADER_HEIGHT = 23;
104 static const int SCROLL_UNIT_X
= 15;
106 // the spacing between the lines (in report mode)
107 static const int LINE_SPACING
= 0;
109 // extra margins around the text label
110 static const int EXTRA_WIDTH
= 4;
111 static const int EXTRA_HEIGHT
= 4;
113 // margin between the window and the items
114 static const int EXTRA_BORDER_X
= 2;
115 static const int EXTRA_BORDER_Y
= 2;
117 // offset for the header window
118 static const int HEADER_OFFSET_X
= 1;
119 static const int HEADER_OFFSET_Y
= 1;
121 // margin between rows of icons in [small] icon view
122 static const int MARGIN_BETWEEN_ROWS
= 6;
124 // when autosizing the columns, add some slack
125 static const int AUTOSIZE_COL_MARGIN
= 10;
127 // default width for the header columns
128 static const int WIDTH_COL_DEFAULT
= 80;
130 // the space between the image and the text in the report mode
131 static const int IMAGE_MARGIN_IN_REPORT_MODE
= 5;
133 // ============================================================================
135 // ============================================================================
137 //-----------------------------------------------------------------------------
138 // wxColWidthInfo (internal)
139 //-----------------------------------------------------------------------------
141 struct wxColWidthInfo
144 bool bNeedsUpdate
; // only set to true when an item whose
145 // width == nMaxWidth is removed
147 wxColWidthInfo(int w
= 0, bool needsUpdate
= false)
150 bNeedsUpdate
= needsUpdate
;
154 WX_DEFINE_ARRAY_PTR(wxColWidthInfo
*, ColWidthArray
);
156 //-----------------------------------------------------------------------------
157 // wxListItemData (internal)
158 //-----------------------------------------------------------------------------
160 class WXDLLEXPORT wxListItemData
163 wxListItemData(wxListMainWindow
*owner
);
166 void SetItem( const wxListItem
&info
);
167 void SetImage( int image
) { m_image
= image
; }
168 void SetData( wxUIntPtr data
) { m_data
= data
; }
169 void SetPosition( int x
, int y
);
170 void SetSize( int width
, int height
);
172 bool HasText() const { return !m_text
.empty(); }
173 const wxString
& GetText() const { return m_text
; }
174 void SetText(const wxString
& text
) { m_text
= text
; }
176 // we can't use empty string for measuring the string width/height, so
177 // always return something
178 wxString
GetTextForMeasuring() const
180 wxString s
= GetText();
187 bool IsHit( int x
, int y
) const;
191 int GetWidth() const;
192 int GetHeight() const;
194 int GetImage() const { return m_image
; }
195 bool HasImage() const { return GetImage() != -1; }
197 void GetItem( wxListItem
&info
) const;
199 void SetAttr(wxListItemAttr
*attr
) { m_attr
= attr
; }
200 wxListItemAttr
*GetAttr() const { return m_attr
; }
203 // the item image or -1
206 // user data associated with the item
209 // the item coordinates are not used in report mode; instead this pointer is
210 // NULL and the owner window is used to retrieve the item position and size
213 // the list ctrl we are in
214 wxListMainWindow
*m_owner
;
216 // custom attributes or NULL
217 wxListItemAttr
*m_attr
;
220 // common part of all ctors
226 //-----------------------------------------------------------------------------
227 // wxListHeaderData (internal)
228 //-----------------------------------------------------------------------------
230 class WXDLLEXPORT wxListHeaderData
: public wxObject
234 wxListHeaderData( const wxListItem
&info
);
235 void SetItem( const wxListItem
&item
);
236 void SetPosition( int x
, int y
);
237 void SetWidth( int w
);
238 void SetFormat( int format
);
239 void SetHeight( int h
);
240 bool HasImage() const;
242 bool HasText() const { return !m_text
.empty(); }
243 const wxString
& GetText() const { return m_text
; }
244 void SetText(const wxString
& text
) { m_text
= text
; }
246 void GetItem( wxListItem
&item
);
248 bool IsHit( int x
, int y
) const;
249 int GetImage() const;
250 int GetWidth() const;
251 int GetFormat() const;
267 //-----------------------------------------------------------------------------
268 // wxListLineData (internal)
269 //-----------------------------------------------------------------------------
271 WX_DECLARE_LIST(wxListItemData
, wxListItemDataList
);
272 #include "wx/listimpl.cpp"
273 WX_DEFINE_LIST(wxListItemDataList
)
278 // the list of subitems: only may have more than one item in report mode
279 wxListItemDataList m_items
;
281 // this is not used in report view
293 // the part to be highlighted
294 wxRect m_rectHighlight
;
296 // extend all our rects to be centered inside the one of given width
297 void ExtendWidth(wxCoord w
)
299 wxASSERT_MSG( m_rectAll
.width
<= w
,
300 _T("width can only be increased") );
303 m_rectLabel
.x
= m_rectAll
.x
+ (w
- m_rectLabel
.width
) / 2;
304 m_rectIcon
.x
= m_rectAll
.x
+ (w
- m_rectIcon
.width
) / 2;
305 m_rectHighlight
.x
= m_rectAll
.x
+ (w
- m_rectHighlight
.width
) / 2;
310 // is this item selected? [NB: not used in virtual mode]
313 // back pointer to the list ctrl
314 wxListMainWindow
*m_owner
;
317 wxListLineData(wxListMainWindow
*owner
);
321 WX_CLEAR_LIST(wxListItemDataList
, m_items
);
325 // are we in report mode?
326 inline bool InReportView() const;
328 // are we in virtual report mode?
329 inline bool IsVirtual() const;
331 // these 2 methods shouldn't be called for report view controls, in that
332 // case we determine our position/size ourselves
334 // calculate the size of the line
335 void CalculateSize( wxDC
*dc
, int spacing
);
337 // remember the position this line appears at
338 void SetPosition( int x
, int y
, int spacing
);
342 void SetImage( int image
) { SetImage(0, image
); }
343 int GetImage() const { return GetImage(0); }
344 void SetImage( int index
, int image
);
345 int GetImage( int index
) const;
347 bool HasImage() const { return GetImage() != -1; }
348 bool HasText() const { return !GetText(0).empty(); }
350 void SetItem( int index
, const wxListItem
&info
);
351 void GetItem( int index
, wxListItem
&info
);
353 wxString
GetText(int index
) const;
354 void SetText( int index
, const wxString
& s
);
356 wxListItemAttr
*GetAttr() const;
357 void SetAttr(wxListItemAttr
*attr
);
359 // return true if the highlighting really changed
360 bool Highlight( bool on
);
362 void ReverseHighlight();
364 bool IsHighlighted() const
366 wxASSERT_MSG( !IsVirtual(), _T("unexpected call to IsHighlighted") );
368 return m_highlighted
;
371 // draw the line on the given DC in icon/list mode
372 void Draw( wxDC
*dc
);
374 // the same in report mode
375 void DrawInReportMode( wxDC
*dc
,
377 const wxRect
& rectHL
,
381 // set the line to contain num items (only can be > 1 in report mode)
382 void InitItems( int num
);
384 // get the mode (i.e. style) of the list control
385 inline int GetMode() const;
387 // prepare the DC for drawing with these item's attributes, return true if
388 // we need to draw the items background to highlight it, false otherwise
389 bool SetAttributes(wxDC
*dc
,
390 const wxListItemAttr
*attr
,
393 // draw the text on the DC with the correct justification; also add an
394 // ellipsis if the text is too large to fit in the current width
395 void DrawTextFormatted(wxDC
*dc
, const wxString
&text
, int col
, int x
, int y
, int width
);
398 WX_DECLARE_EXPORTED_OBJARRAY(wxListLineData
, wxListLineDataArray
);
399 #include "wx/arrimpl.cpp"
400 WX_DEFINE_OBJARRAY(wxListLineDataArray
)
402 //-----------------------------------------------------------------------------
403 // wxListHeaderWindow (internal)
404 //-----------------------------------------------------------------------------
406 class WXDLLEXPORT wxListHeaderWindow
: public wxWindow
409 wxListMainWindow
*m_owner
;
410 wxCursor
*m_currentCursor
;
411 wxCursor
*m_resizeCursor
;
414 // column being resized or -1
417 // divider line position in logical (unscrolled) coords
420 // minimal position beyond which the divider line
421 // can't be dragged in logical coords
425 wxListHeaderWindow();
427 wxListHeaderWindow( wxWindow
*win
,
429 wxListMainWindow
*owner
,
430 const wxPoint
&pos
= wxDefaultPosition
,
431 const wxSize
&size
= wxDefaultSize
,
433 const wxString
&name
= wxT("wxlistctrlcolumntitles") );
435 virtual ~wxListHeaderWindow();
438 void AdjustDC( wxDC
& dc
);
440 void OnPaint( wxPaintEvent
&event
);
441 void OnMouse( wxMouseEvent
&event
);
442 void OnSetFocus( wxFocusEvent
&event
);
448 // common part of all ctors
451 // generate and process the list event of the given type, return true if
452 // it wasn't vetoed, i.e. if we should proceed
453 bool SendListEvent(wxEventType type
, const wxPoint
& pos
);
455 DECLARE_DYNAMIC_CLASS(wxListHeaderWindow
)
456 DECLARE_EVENT_TABLE()
459 //-----------------------------------------------------------------------------
460 // wxListRenameTimer (internal)
461 //-----------------------------------------------------------------------------
463 class WXDLLEXPORT wxListRenameTimer
: public wxTimer
466 wxListMainWindow
*m_owner
;
469 wxListRenameTimer( wxListMainWindow
*owner
);
473 //-----------------------------------------------------------------------------
474 // wxListTextCtrl (internal)
475 //-----------------------------------------------------------------------------
477 class WXDLLEXPORT wxListTextCtrl
: public wxTextCtrl
480 wxListTextCtrl(wxListMainWindow
*owner
, size_t itemEdit
);
482 void AcceptChangesAndFinish();
485 void OnChar( wxKeyEvent
&event
);
486 void OnKeyUp( wxKeyEvent
&event
);
487 void OnKillFocus( wxFocusEvent
&event
);
489 bool AcceptChanges();
493 wxListMainWindow
*m_owner
;
494 wxString m_startValue
;
497 bool m_aboutToFinish
;
499 DECLARE_EVENT_TABLE()
502 //-----------------------------------------------------------------------------
503 // wxListMainWindow (internal)
504 //-----------------------------------------------------------------------------
506 WX_DECLARE_LIST(wxListHeaderData
, wxListHeaderDataList
);
507 #include "wx/listimpl.cpp"
508 WX_DEFINE_LIST(wxListHeaderDataList
)
510 class wxListMainWindow
: public wxScrolledWindow
514 wxListMainWindow( wxWindow
*parent
,
516 const wxPoint
& pos
= wxDefaultPosition
,
517 const wxSize
& size
= wxDefaultSize
,
519 const wxString
&name
= _T("listctrlmainwindow") );
521 virtual ~wxListMainWindow();
523 bool HasFlag(int flag
) const { return m_parent
->HasFlag(flag
); }
525 // return true if this is a virtual list control
526 bool IsVirtual() const { return HasFlag(wxLC_VIRTUAL
); }
528 // return true if the control is in report mode
529 bool InReportView() const { return HasFlag(wxLC_REPORT
); }
531 // return true if we are in single selection mode, false if multi sel
532 bool IsSingleSel() const { return HasFlag(wxLC_SINGLE_SEL
); }
534 // do we have a header window?
535 bool HasHeader() const
536 { return InReportView() && !HasFlag(wxLC_NO_HEADER
); }
538 void HighlightAll( bool on
);
540 // all these functions only do something if the line is currently visible
542 // change the line "selected" state, return true if it really changed
543 bool HighlightLine( size_t line
, bool highlight
= true);
545 // as HighlightLine() but do it for the range of lines: this is incredibly
546 // more efficient for virtual list controls!
548 // NB: unlike HighlightLine() this one does refresh the lines on screen
549 void HighlightLines( size_t lineFrom
, size_t lineTo
, bool on
= true );
551 // toggle the line state and refresh it
552 void ReverseHighlight( size_t line
)
553 { HighlightLine(line
, !IsHighlighted(line
)); RefreshLine(line
); }
555 // return true if the line is highlighted
556 bool IsHighlighted(size_t line
) const;
558 // refresh one or several lines at once
559 void RefreshLine( size_t line
);
560 void RefreshLines( size_t lineFrom
, size_t lineTo
);
562 // refresh all selected items
563 void RefreshSelected();
565 // refresh all lines below the given one: the difference with
566 // RefreshLines() is that the index here might not be a valid one (happens
567 // when the last line is deleted)
568 void RefreshAfter( size_t lineFrom
);
570 // the methods which are forwarded to wxListLineData itself in list/icon
571 // modes but are here because the lines don't store their positions in the
574 // get the bound rect for the entire line
575 wxRect
GetLineRect(size_t line
) const;
577 // get the bound rect of the label
578 wxRect
GetLineLabelRect(size_t line
) const;
580 // get the bound rect of the items icon (only may be called if we do have
582 wxRect
GetLineIconRect(size_t line
) const;
584 // get the rect to be highlighted when the item has focus
585 wxRect
GetLineHighlightRect(size_t line
) const;
587 // get the size of the total line rect
588 wxSize
GetLineSize(size_t line
) const
589 { return GetLineRect(line
).GetSize(); }
591 // return the hit code for the corresponding position (in this line)
592 long HitTestLine(size_t line
, int x
, int y
) const;
594 // bring the selected item into view, scrolling to it if necessary
595 void MoveToItem(size_t item
);
597 // bring the current item into view
598 void MoveToFocus() { MoveToItem(m_current
); }
600 // start editing the label of the given item
601 void EditLabel( long item
);
603 // suspend/resume redrawing the control
607 void OnRenameTimer();
608 bool OnRenameAccept(size_t itemEdit
, const wxString
& value
);
609 void OnRenameCancelled(size_t itemEdit
);
611 void OnMouse( wxMouseEvent
&event
);
613 // called to switch the selection from the current item to newCurrent,
614 void OnArrowChar( size_t newCurrent
, const wxKeyEvent
& event
);
616 void OnChar( wxKeyEvent
&event
);
617 void OnKeyDown( wxKeyEvent
&event
);
618 void OnSetFocus( wxFocusEvent
&event
);
619 void OnKillFocus( wxFocusEvent
&event
);
620 void OnScroll( wxScrollWinEvent
& event
);
622 void OnPaint( wxPaintEvent
&event
);
624 void DrawImage( int index
, wxDC
*dc
, int x
, int y
);
625 void GetImageSize( int index
, int &width
, int &height
) const;
626 int GetTextLength( const wxString
&s
) const;
628 void SetImageList( wxImageListType
*imageList
, int which
);
629 void SetItemSpacing( int spacing
, bool isSmall
= false );
630 int GetItemSpacing( bool isSmall
= false );
632 void SetColumn( int col
, wxListItem
&item
);
633 void SetColumnWidth( int col
, int width
);
634 void GetColumn( int col
, wxListItem
&item
) const;
635 int GetColumnWidth( int col
) const;
636 int GetColumnCount() const { return m_columns
.GetCount(); }
638 // returns the sum of the heights of all columns
639 int GetHeaderWidth() const;
641 int GetCountPerPage() const;
643 void SetItem( wxListItem
&item
);
644 void GetItem( wxListItem
&item
) const;
645 void SetItemState( long item
, long state
, long stateMask
);
646 void SetItemStateAll( long state
, long stateMask
);
647 int GetItemState( long item
, long stateMask
) const;
648 void GetItemRect( long index
, wxRect
&rect
) const;
649 wxRect
GetViewRect() const;
650 bool GetItemPosition( long item
, wxPoint
& pos
) const;
651 int GetSelectedItemCount() const;
653 wxString
GetItemText(long item
) const
656 info
.m_mask
= wxLIST_MASK_TEXT
;
657 info
.m_itemId
= item
;
662 void SetItemText(long item
, const wxString
& value
)
665 info
.m_mask
= wxLIST_MASK_TEXT
;
666 info
.m_itemId
= item
;
671 // set the scrollbars and update the positions of the items
672 void RecalculatePositions(bool noRefresh
= false);
674 // refresh the window and the header
677 long GetNextItem( long item
, int geometry
, int state
) const;
678 void DeleteItem( long index
);
679 void DeleteAllItems();
680 void DeleteColumn( int col
);
681 void DeleteEverything();
682 void EnsureVisible( long index
);
683 long FindItem( long start
, const wxString
& str
, bool partial
= false );
684 long FindItem( long start
, wxUIntPtr data
);
685 long FindItem( const wxPoint
& pt
);
686 long HitTest( int x
, int y
, int &flags
);
687 void InsertItem( wxListItem
&item
);
688 void InsertColumn( long col
, wxListItem
&item
);
689 int GetItemWidthWithImage(wxListItem
* item
);
690 void SortItems( wxListCtrlCompare fn
, long data
);
692 size_t GetItemCount() const;
693 bool IsEmpty() const { return GetItemCount() == 0; }
694 void SetItemCount(long count
);
696 // change the current (== focused) item, send a notification event
697 void ChangeCurrent(size_t current
);
698 void ResetCurrent() { ChangeCurrent((size_t)-1); }
699 bool HasCurrent() const { return m_current
!= (size_t)-1; }
701 // send out a wxListEvent
702 void SendNotify( size_t line
,
704 const wxPoint
& point
= wxDefaultPosition
);
706 // override base class virtual to reset m_lineHeight when the font changes
707 virtual bool SetFont(const wxFont
& font
)
709 if ( !wxScrolledWindow::SetFont(font
) )
717 // these are for wxListLineData usage only
719 // get the backpointer to the list ctrl
720 wxGenericListCtrl
*GetListCtrl() const
722 return wxStaticCast(GetParent(), wxGenericListCtrl
);
725 // get the height of all lines (assuming they all do have the same height)
726 wxCoord
GetLineHeight() const;
728 // get the y position of the given line (only for report view)
729 wxCoord
GetLineY(size_t line
) const;
731 // get the brush to use for the item highlighting
732 wxBrush
*GetHighlightBrush() const
734 return m_hasFocus
? m_highlightBrush
: m_highlightUnfocusedBrush
;
738 // the array of all line objects for a non virtual list control (for the
739 // virtual list control we only ever use m_lines[0])
740 wxListLineDataArray m_lines
;
742 // the list of column objects
743 wxListHeaderDataList m_columns
;
745 // currently focused item or -1
748 // the number of lines per page
751 // this flag is set when something which should result in the window
752 // redrawing happens (i.e. an item was added or deleted, or its appearance
753 // changed) and OnPaint() doesn't redraw the window while it is set which
754 // allows to minimize the number of repaintings when a lot of items are
755 // being added. The real repainting occurs only after the next OnIdle()
759 wxColour
*m_highlightColour
;
760 wxImageListType
*m_small_image_list
;
761 wxImageListType
*m_normal_image_list
;
763 int m_normal_spacing
;
767 wxTimer
*m_renameTimer
;
771 ColWidthArray m_aColWidths
;
773 // for double click logic
774 size_t m_lineLastClicked
,
775 m_lineBeforeLastClicked
,
776 m_lineSelectSingleOnUp
;
778 wxListTextCtrl
* m_textctrl
;
781 wxWindow
*GetMainWindowOfCompositeControl() { return GetParent(); }
783 // the total count of items in a virtual list control
786 // the object maintaining the items selection state, only used in virtual
788 wxSelectionStore m_selStore
;
790 // common part of all ctors
793 // get the line data for the given index
794 wxListLineData
*GetLine(size_t n
) const
796 wxASSERT_MSG( n
!= (size_t)-1, _T("invalid line index") );
800 wxConstCast(this, wxListMainWindow
)->CacheLineData(n
);
807 // get a dummy line which can be used for geometry calculations and such:
808 // you must use GetLine() if you want to really draw the line
809 wxListLineData
*GetDummyLine() const;
811 // cache the line data of the n-th line in m_lines[0]
812 void CacheLineData(size_t line
);
814 // get the range of visible lines
815 void GetVisibleLinesRange(size_t *from
, size_t *to
);
817 // force us to recalculate the range of visible lines
818 void ResetVisibleLinesRange() { m_lineFrom
= (size_t)-1; }
820 // get the colour to be used for drawing the rules
821 wxColour
GetRuleColour() const
823 return wxSystemSettings::GetColour(wxSYS_COLOUR_3DLIGHT
);
827 // initialize the current item if needed
828 void UpdateCurrent();
830 // delete all items but don't refresh: called from dtor
831 void DoDeleteAllItems();
833 // the height of one line using the current font
834 wxCoord m_lineHeight
;
836 // the total header width or 0 if not calculated yet
837 wxCoord m_headerWidth
;
839 // the first and last lines being shown on screen right now (inclusive),
840 // both may be -1 if they must be calculated so never access them directly:
841 // use GetVisibleLinesRange() above instead
845 // the brushes to use for item highlighting when we do/don't have focus
846 wxBrush
*m_highlightBrush
,
847 *m_highlightUnfocusedBrush
;
849 // if this is > 0, the control is frozen and doesn't redraw itself
850 size_t m_freezeCount
;
852 DECLARE_DYNAMIC_CLASS(wxListMainWindow
)
853 DECLARE_EVENT_TABLE()
855 friend class wxGenericListCtrl
;
859 wxListItemData::~wxListItemData()
861 // in the virtual list control the attributes are managed by the main
862 // program, so don't delete them
863 if ( !m_owner
->IsVirtual() )
869 void wxListItemData::Init()
877 wxListItemData::wxListItemData(wxListMainWindow
*owner
)
883 if ( owner
->InReportView() )
889 void wxListItemData::SetItem( const wxListItem
&info
)
891 if ( info
.m_mask
& wxLIST_MASK_TEXT
)
892 SetText(info
.m_text
);
893 if ( info
.m_mask
& wxLIST_MASK_IMAGE
)
894 m_image
= info
.m_image
;
895 if ( info
.m_mask
& wxLIST_MASK_DATA
)
896 m_data
= info
.m_data
;
898 if ( info
.HasAttributes() )
901 *m_attr
= *info
.GetAttributes();
903 m_attr
= new wxListItemAttr(*info
.GetAttributes());
911 m_rect
->width
= info
.m_width
;
915 void wxListItemData::SetPosition( int x
, int y
)
917 wxCHECK_RET( m_rect
, _T("unexpected SetPosition() call") );
923 void wxListItemData::SetSize( int width
, int height
)
925 wxCHECK_RET( m_rect
, _T("unexpected SetSize() call") );
928 m_rect
->width
= width
;
930 m_rect
->height
= height
;
933 bool wxListItemData::IsHit( int x
, int y
) const
935 wxCHECK_MSG( m_rect
, false, _T("can't be called in this mode") );
937 return wxRect(GetX(), GetY(), GetWidth(), GetHeight()).Inside(x
, y
);
940 int wxListItemData::GetX() const
942 wxCHECK_MSG( m_rect
, 0, _T("can't be called in this mode") );
947 int wxListItemData::GetY() const
949 wxCHECK_MSG( m_rect
, 0, _T("can't be called in this mode") );
954 int wxListItemData::GetWidth() const
956 wxCHECK_MSG( m_rect
, 0, _T("can't be called in this mode") );
958 return m_rect
->width
;
961 int wxListItemData::GetHeight() const
963 wxCHECK_MSG( m_rect
, 0, _T("can't be called in this mode") );
965 return m_rect
->height
;
968 void wxListItemData::GetItem( wxListItem
&info
) const
970 long mask
= info
.m_mask
;
972 // by default, get everything for backwards compatibility
975 if ( mask
& wxLIST_MASK_TEXT
)
976 info
.m_text
= m_text
;
977 if ( mask
& wxLIST_MASK_IMAGE
)
978 info
.m_image
= m_image
;
979 if ( mask
& wxLIST_MASK_DATA
)
980 info
.m_data
= m_data
;
984 if ( m_attr
->HasTextColour() )
985 info
.SetTextColour(m_attr
->GetTextColour());
986 if ( m_attr
->HasBackgroundColour() )
987 info
.SetBackgroundColour(m_attr
->GetBackgroundColour());
988 if ( m_attr
->HasFont() )
989 info
.SetFont(m_attr
->GetFont());
993 //-----------------------------------------------------------------------------
995 //-----------------------------------------------------------------------------
997 void wxListHeaderData::Init()
1008 wxListHeaderData::wxListHeaderData()
1013 wxListHeaderData::wxListHeaderData( const wxListItem
&item
)
1020 void wxListHeaderData::SetItem( const wxListItem
&item
)
1022 m_mask
= item
.m_mask
;
1024 if ( m_mask
& wxLIST_MASK_TEXT
)
1025 m_text
= item
.m_text
;
1027 if ( m_mask
& wxLIST_MASK_IMAGE
)
1028 m_image
= item
.m_image
;
1030 if ( m_mask
& wxLIST_MASK_FORMAT
)
1031 m_format
= item
.m_format
;
1033 if ( m_mask
& wxLIST_MASK_WIDTH
)
1034 SetWidth(item
.m_width
);
1037 void wxListHeaderData::SetPosition( int x
, int y
)
1043 void wxListHeaderData::SetHeight( int h
)
1048 void wxListHeaderData::SetWidth( int w
)
1050 m_width
= w
< 0 ? WIDTH_COL_DEFAULT
: w
;
1053 void wxListHeaderData::SetFormat( int format
)
1058 bool wxListHeaderData::HasImage() const
1060 return m_image
!= -1;
1063 bool wxListHeaderData::IsHit( int x
, int y
) const
1065 return ((x
>= m_xpos
) && (x
<= m_xpos
+m_width
) && (y
>= m_ypos
) && (y
<= m_ypos
+m_height
));
1068 void wxListHeaderData::GetItem( wxListItem
& item
)
1070 item
.m_mask
= m_mask
;
1071 item
.m_text
= m_text
;
1072 item
.m_image
= m_image
;
1073 item
.m_format
= m_format
;
1074 item
.m_width
= m_width
;
1077 int wxListHeaderData::GetImage() const
1082 int wxListHeaderData::GetWidth() const
1087 int wxListHeaderData::GetFormat() const
1092 //-----------------------------------------------------------------------------
1094 //-----------------------------------------------------------------------------
1096 inline int wxListLineData::GetMode() const
1098 return m_owner
->GetListCtrl()->GetWindowStyleFlag() & wxLC_MASK_TYPE
;
1101 inline bool wxListLineData::InReportView() const
1103 return m_owner
->HasFlag(wxLC_REPORT
);
1106 inline bool wxListLineData::IsVirtual() const
1108 return m_owner
->IsVirtual();
1111 wxListLineData::wxListLineData( wxListMainWindow
*owner
)
1115 if ( InReportView() )
1118 m_gi
= new GeometryInfo
;
1120 m_highlighted
= false;
1122 InitItems( GetMode() == wxLC_REPORT
? m_owner
->GetColumnCount() : 1 );
1125 void wxListLineData::CalculateSize( wxDC
*dc
, int spacing
)
1127 wxListItemDataList::compatibility_iterator node
= m_items
.GetFirst();
1128 wxCHECK_RET( node
, _T("no subitems at all??") );
1130 wxListItemData
*item
= node
->GetData();
1135 switch ( GetMode() )
1138 case wxLC_SMALL_ICON
:
1139 m_gi
->m_rectAll
.width
= spacing
;
1141 s
= item
->GetText();
1146 m_gi
->m_rectLabel
.width
=
1147 m_gi
->m_rectLabel
.height
= 0;
1151 dc
->GetTextExtent( s
, &lw
, &lh
);
1155 m_gi
->m_rectAll
.height
= spacing
+ lh
;
1157 m_gi
->m_rectAll
.width
= lw
;
1159 m_gi
->m_rectLabel
.width
= lw
;
1160 m_gi
->m_rectLabel
.height
= lh
;
1163 if (item
->HasImage())
1166 m_owner
->GetImageSize( item
->GetImage(), w
, h
);
1167 m_gi
->m_rectIcon
.width
= w
+ 8;
1168 m_gi
->m_rectIcon
.height
= h
+ 8;
1170 if ( m_gi
->m_rectIcon
.width
> m_gi
->m_rectAll
.width
)
1171 m_gi
->m_rectAll
.width
= m_gi
->m_rectIcon
.width
;
1172 if ( m_gi
->m_rectIcon
.height
+ lh
> m_gi
->m_rectAll
.height
- 4 )
1173 m_gi
->m_rectAll
.height
= m_gi
->m_rectIcon
.height
+ lh
+ 4;
1176 if ( item
->HasText() )
1178 m_gi
->m_rectHighlight
.width
= m_gi
->m_rectLabel
.width
;
1179 m_gi
->m_rectHighlight
.height
= m_gi
->m_rectLabel
.height
;
1181 else // no text, highlight the icon
1183 m_gi
->m_rectHighlight
.width
= m_gi
->m_rectIcon
.width
;
1184 m_gi
->m_rectHighlight
.height
= m_gi
->m_rectIcon
.height
;
1189 s
= item
->GetTextForMeasuring();
1191 dc
->GetTextExtent( s
, &lw
, &lh
);
1195 m_gi
->m_rectLabel
.width
= lw
;
1196 m_gi
->m_rectLabel
.height
= lh
;
1198 m_gi
->m_rectAll
.width
= lw
;
1199 m_gi
->m_rectAll
.height
= lh
;
1201 if (item
->HasImage())
1204 m_owner
->GetImageSize( item
->GetImage(), w
, h
);
1205 m_gi
->m_rectIcon
.width
= w
;
1206 m_gi
->m_rectIcon
.height
= h
;
1208 m_gi
->m_rectAll
.width
+= 4 + w
;
1209 if (h
> m_gi
->m_rectAll
.height
)
1210 m_gi
->m_rectAll
.height
= h
;
1213 m_gi
->m_rectHighlight
.width
= m_gi
->m_rectAll
.width
;
1214 m_gi
->m_rectHighlight
.height
= m_gi
->m_rectAll
.height
;
1218 wxFAIL_MSG( _T("unexpected call to SetSize") );
1222 wxFAIL_MSG( _T("unknown mode") );
1227 void wxListLineData::SetPosition( int x
, int y
, int spacing
)
1229 wxListItemDataList::compatibility_iterator node
= m_items
.GetFirst();
1230 wxCHECK_RET( node
, _T("no subitems at all??") );
1232 wxListItemData
*item
= node
->GetData();
1234 switch ( GetMode() )
1237 case wxLC_SMALL_ICON
:
1238 m_gi
->m_rectAll
.x
= x
;
1239 m_gi
->m_rectAll
.y
= y
;
1241 if ( item
->HasImage() )
1243 m_gi
->m_rectIcon
.x
= m_gi
->m_rectAll
.x
+ 4 +
1244 (m_gi
->m_rectAll
.width
- m_gi
->m_rectIcon
.width
) / 2;
1245 m_gi
->m_rectIcon
.y
= m_gi
->m_rectAll
.y
+ 4;
1248 if ( item
->HasText() )
1250 if (m_gi
->m_rectAll
.width
> spacing
)
1251 m_gi
->m_rectLabel
.x
= m_gi
->m_rectAll
.x
+ 2;
1253 m_gi
->m_rectLabel
.x
= m_gi
->m_rectAll
.x
+ 2 + (spacing
/ 2) - (m_gi
->m_rectLabel
.width
/ 2);
1254 m_gi
->m_rectLabel
.y
= m_gi
->m_rectAll
.y
+ m_gi
->m_rectAll
.height
+ 2 - m_gi
->m_rectLabel
.height
;
1255 m_gi
->m_rectHighlight
.x
= m_gi
->m_rectLabel
.x
- 2;
1256 m_gi
->m_rectHighlight
.y
= m_gi
->m_rectLabel
.y
- 2;
1258 else // no text, highlight the icon
1260 m_gi
->m_rectHighlight
.x
= m_gi
->m_rectIcon
.x
- 4;
1261 m_gi
->m_rectHighlight
.y
= m_gi
->m_rectIcon
.y
- 4;
1266 m_gi
->m_rectAll
.x
= x
;
1267 m_gi
->m_rectAll
.y
= y
;
1269 m_gi
->m_rectHighlight
.x
= m_gi
->m_rectAll
.x
;
1270 m_gi
->m_rectHighlight
.y
= m_gi
->m_rectAll
.y
;
1271 m_gi
->m_rectLabel
.y
= m_gi
->m_rectAll
.y
+ 2;
1273 if (item
->HasImage())
1275 m_gi
->m_rectIcon
.x
= m_gi
->m_rectAll
.x
+ 2;
1276 m_gi
->m_rectIcon
.y
= m_gi
->m_rectAll
.y
+ 2;
1277 m_gi
->m_rectLabel
.x
= m_gi
->m_rectAll
.x
+ 6 + m_gi
->m_rectIcon
.width
;
1281 m_gi
->m_rectLabel
.x
= m_gi
->m_rectAll
.x
+ 2;
1286 wxFAIL_MSG( _T("unexpected call to SetPosition") );
1290 wxFAIL_MSG( _T("unknown mode") );
1295 void wxListLineData::InitItems( int num
)
1297 for (int i
= 0; i
< num
; i
++)
1298 m_items
.Append( new wxListItemData(m_owner
) );
1301 void wxListLineData::SetItem( int index
, const wxListItem
&info
)
1303 wxListItemDataList::compatibility_iterator node
= m_items
.Item( index
);
1304 wxCHECK_RET( node
, _T("invalid column index in SetItem") );
1306 wxListItemData
*item
= node
->GetData();
1307 item
->SetItem( info
);
1310 void wxListLineData::GetItem( int index
, wxListItem
&info
)
1312 wxListItemDataList::compatibility_iterator node
= m_items
.Item( index
);
1315 wxListItemData
*item
= node
->GetData();
1316 item
->GetItem( info
);
1320 wxString
wxListLineData::GetText(int index
) const
1324 wxListItemDataList::compatibility_iterator node
= m_items
.Item( index
);
1327 wxListItemData
*item
= node
->GetData();
1328 s
= item
->GetText();
1334 void wxListLineData::SetText( int index
, const wxString
& s
)
1336 wxListItemDataList::compatibility_iterator node
= m_items
.Item( index
);
1339 wxListItemData
*item
= node
->GetData();
1344 void wxListLineData::SetImage( int index
, int image
)
1346 wxListItemDataList::compatibility_iterator node
= m_items
.Item( index
);
1347 wxCHECK_RET( node
, _T("invalid column index in SetImage()") );
1349 wxListItemData
*item
= node
->GetData();
1350 item
->SetImage(image
);
1353 int wxListLineData::GetImage( int index
) const
1355 wxListItemDataList::compatibility_iterator node
= m_items
.Item( index
);
1356 wxCHECK_MSG( node
, -1, _T("invalid column index in GetImage()") );
1358 wxListItemData
*item
= node
->GetData();
1359 return item
->GetImage();
1362 wxListItemAttr
*wxListLineData::GetAttr() const
1364 wxListItemDataList::compatibility_iterator node
= m_items
.GetFirst();
1365 wxCHECK_MSG( node
, NULL
, _T("invalid column index in GetAttr()") );
1367 wxListItemData
*item
= node
->GetData();
1368 return item
->GetAttr();
1371 void wxListLineData::SetAttr(wxListItemAttr
*attr
)
1373 wxListItemDataList::compatibility_iterator node
= m_items
.GetFirst();
1374 wxCHECK_RET( node
, _T("invalid column index in SetAttr()") );
1376 wxListItemData
*item
= node
->GetData();
1377 item
->SetAttr(attr
);
1380 bool wxListLineData::SetAttributes(wxDC
*dc
,
1381 const wxListItemAttr
*attr
,
1384 wxWindow
*listctrl
= m_owner
->GetParent();
1388 // don't use foreground colour for drawing highlighted items - this might
1389 // make them completely invisible (and there is no way to do bit
1390 // arithmetics on wxColour, unfortunately)
1393 colText
= wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHTTEXT
);
1394 else if ( attr
&& attr
->HasTextColour() )
1395 colText
= attr
->GetTextColour();
1397 colText
= listctrl
->GetForegroundColour();
1399 dc
->SetTextForeground(colText
);
1403 if ( attr
&& attr
->HasFont() )
1404 font
= attr
->GetFont();
1406 font
= listctrl
->GetFont();
1411 bool hasBgCol
= attr
&& attr
->HasBackgroundColour();
1412 if ( highlighted
|| hasBgCol
)
1415 dc
->SetBrush( *m_owner
->GetHighlightBrush() );
1417 dc
->SetBrush(wxBrush(attr
->GetBackgroundColour(), wxSOLID
));
1419 dc
->SetPen( *wxTRANSPARENT_PEN
);
1427 void wxListLineData::Draw( wxDC
*dc
)
1429 wxListItemDataList::compatibility_iterator node
= m_items
.GetFirst();
1430 wxCHECK_RET( node
, _T("no subitems at all??") );
1432 bool highlighted
= IsHighlighted();
1434 wxListItemAttr
*attr
= GetAttr();
1436 if ( SetAttributes(dc
, attr
, highlighted
) )
1437 dc
->DrawRectangle( m_gi
->m_rectHighlight
);
1439 // just for debugging to better see where the items are
1441 dc
->SetPen(*wxRED_PEN
);
1442 dc
->SetBrush(*wxTRANSPARENT_BRUSH
);
1443 dc
->DrawRectangle( m_gi
->m_rectAll
);
1444 dc
->SetPen(*wxGREEN_PEN
);
1445 dc
->DrawRectangle( m_gi
->m_rectIcon
);
1448 wxListItemData
*item
= node
->GetData();
1449 if (item
->HasImage())
1451 // centre the image inside our rectangle, this looks nicer when items
1452 // ae aligned in a row
1453 const wxRect
& rectIcon
= m_gi
->m_rectIcon
;
1455 m_owner
->DrawImage(item
->GetImage(), dc
, rectIcon
.x
, rectIcon
.y
);
1458 if (item
->HasText())
1460 const wxRect
& rectLabel
= m_gi
->m_rectLabel
;
1462 wxDCClipper
clipper(*dc
, rectLabel
);
1463 dc
->DrawText(item
->GetText(), rectLabel
.x
, rectLabel
.y
);
1467 void wxListLineData::DrawInReportMode( wxDC
*dc
,
1469 const wxRect
& rectHL
,
1472 // TODO: later we should support setting different attributes for
1473 // different columns - to do it, just add "col" argument to
1474 // GetAttr() and move these lines into the loop below
1475 wxListItemAttr
*attr
= GetAttr();
1476 if ( SetAttributes(dc
, attr
, highlighted
) )
1477 dc
->DrawRectangle( rectHL
);
1479 wxCoord x
= rect
.x
+ HEADER_OFFSET_X
,
1480 y
= rect
.y
+ (LINE_SPACING
+ EXTRA_HEIGHT
) / 2;
1483 for ( wxListItemDataList::compatibility_iterator node
= m_items
.GetFirst();
1485 node
= node
->GetNext(), col
++ )
1487 wxListItemData
*item
= node
->GetData();
1489 int width
= m_owner
->GetColumnWidth(col
);
1493 if ( item
->HasImage() )
1496 m_owner
->DrawImage( item
->GetImage(), dc
, xOld
, y
);
1497 m_owner
->GetImageSize( item
->GetImage(), ix
, iy
);
1499 ix
+= IMAGE_MARGIN_IN_REPORT_MODE
;
1505 wxDCClipper
clipper(*dc
, xOld
, y
, width
- 8, rect
.height
);
1507 if ( item
->HasText() )
1508 DrawTextFormatted(dc
, item
->GetText(), col
, xOld
, y
, width
- 8);
1512 void wxListLineData::DrawTextFormatted(wxDC
*dc
,
1513 const wxString
&text
,
1519 wxString drawntext
, ellipsis
;
1520 wxCoord w
, h
, base_w
;
1523 // determine if the string can fit inside the current width
1524 dc
->GetTextExtent(text
, &w
, &h
);
1527 // it can, draw it using the items alignment
1528 m_owner
->GetColumn(col
, item
);
1529 switch ( item
.GetAlign() )
1531 case wxLIST_FORMAT_LEFT
:
1535 case wxLIST_FORMAT_RIGHT
:
1539 case wxLIST_FORMAT_CENTER
:
1540 x
+= (width
- w
) / 2;
1544 wxFAIL_MSG( _T("unknown list item format") );
1548 dc
->DrawText(text
, x
, y
);
1550 else // otherwise, truncate and add an ellipsis if possible
1552 // determine the base width
1553 ellipsis
= wxString(wxT("..."));
1554 dc
->GetTextExtent(ellipsis
, &base_w
, &h
);
1556 // continue until we have enough space or only one character left
1558 size_t len
= text
.Length();
1559 drawntext
= text
.Left(len
);
1562 dc
->GetTextExtent(drawntext
.Last(), &w_c
, &h_c
);
1563 drawntext
.RemoveLast();
1566 if (w
+ base_w
<= width
)
1570 // if still not enough space, remove ellipsis characters
1571 while (ellipsis
.Length() > 0 && w
+ base_w
> width
)
1573 ellipsis
= ellipsis
.Left(ellipsis
.Length() - 1);
1574 dc
->GetTextExtent(ellipsis
, &base_w
, &h
);
1577 // now draw the text
1578 dc
->DrawText(drawntext
, x
, y
);
1579 dc
->DrawText(ellipsis
, x
+ w
, y
);
1583 bool wxListLineData::Highlight( bool on
)
1585 wxCHECK_MSG( !IsVirtual(), false, _T("unexpected call to Highlight") );
1587 if ( on
== m_highlighted
)
1595 void wxListLineData::ReverseHighlight( void )
1597 Highlight(!IsHighlighted());
1600 //-----------------------------------------------------------------------------
1601 // wxListHeaderWindow
1602 //-----------------------------------------------------------------------------
1604 IMPLEMENT_DYNAMIC_CLASS(wxListHeaderWindow
,wxWindow
)
1606 BEGIN_EVENT_TABLE(wxListHeaderWindow
,wxWindow
)
1607 EVT_PAINT (wxListHeaderWindow::OnPaint
)
1608 EVT_MOUSE_EVENTS (wxListHeaderWindow::OnMouse
)
1609 EVT_SET_FOCUS (wxListHeaderWindow::OnSetFocus
)
1612 void wxListHeaderWindow::Init()
1614 m_currentCursor
= (wxCursor
*) NULL
;
1615 m_isDragging
= false;
1619 wxListHeaderWindow::wxListHeaderWindow()
1623 m_owner
= (wxListMainWindow
*) NULL
;
1624 m_resizeCursor
= (wxCursor
*) NULL
;
1627 wxListHeaderWindow::wxListHeaderWindow( wxWindow
*win
,
1629 wxListMainWindow
*owner
,
1633 const wxString
&name
)
1634 : wxWindow( win
, id
, pos
, size
, style
, name
)
1639 m_resizeCursor
= new wxCursor( wxCURSOR_SIZEWE
);
1642 wxVisualAttributes attr
= wxPanel::GetClassDefaultAttributes();
1643 SetOwnForegroundColour( attr
.colFg
);
1644 SetOwnBackgroundColour( attr
.colBg
);
1646 SetOwnFont( attr
.font
);
1648 SetOwnForegroundColour( wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT
));
1649 SetOwnBackgroundColour( wxSystemSettings::GetColour(wxSYS_COLOUR_BTNFACE
));
1651 SetOwnFont( wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT
));
1655 wxListHeaderWindow::~wxListHeaderWindow()
1657 delete m_resizeCursor
;
1660 #ifdef __WXUNIVERSAL__
1661 #include "wx/univ/renderer.h"
1662 #include "wx/univ/theme.h"
1665 // shift the DC origin to match the position of the main window horz
1666 // scrollbar: this allows us to always use logical coords
1667 void wxListHeaderWindow::AdjustDC(wxDC
& dc
)
1670 m_owner
->GetScrollPixelsPerUnit( &xpix
, NULL
);
1673 m_owner
->GetViewStart( &x
, NULL
);
1675 // account for the horz scrollbar offset
1676 dc
.SetDeviceOrigin( -x
* xpix
, 0 );
1679 void wxListHeaderWindow::OnPaint( wxPaintEvent
&WXUNUSED(event
) )
1681 wxPaintDC
dc( this );
1686 dc
.SetFont( GetFont() );
1688 // width and height of the entire header window
1690 GetClientSize( &w
, &h
);
1691 m_owner
->CalcUnscrolledPosition(w
, 0, &w
, NULL
);
1693 dc
.SetBackgroundMode(wxTRANSPARENT
);
1694 dc
.SetTextForeground(GetForegroundColour());
1696 int x
= HEADER_OFFSET_X
;
1697 int numColumns
= m_owner
->GetColumnCount();
1699 for ( int i
= 0; i
< numColumns
&& x
< w
; i
++ )
1701 m_owner
->GetColumn( i
, item
);
1702 int wCol
= item
.m_width
;
1704 // the width of the rect to draw: make it smaller to fit entirely
1705 // inside the column rect
1714 wxRendererNative::Get().DrawHeaderButton
1718 wxRect(x
, HEADER_OFFSET_Y
, cw
, ch
),
1719 m_parent
->IsEnabled() ? 0
1720 : (int)wxCONTROL_DISABLED
1723 // see if we have enough space for the column label
1725 // for this we need the width of the text
1728 dc
.GetTextExtent(item
.GetText(), &wLabel
, &hLabel
);
1729 wLabel
+= 2 * EXTRA_WIDTH
;
1731 // and the width of the icon, if any
1732 static const int MARGIN_BETWEEN_TEXT_AND_ICON
= 2;
1733 int ix
= 0, iy
= 0; // init them just to suppress the compiler warnings
1734 const int image
= item
.m_image
;
1735 wxImageListType
*imageList
;
1738 imageList
= m_owner
->m_small_image_list
;
1741 imageList
->GetSize(image
, ix
, iy
);
1742 wLabel
+= ix
+ MARGIN_BETWEEN_TEXT_AND_ICON
;
1750 // ignore alignment if there is not enough space anyhow
1752 switch ( wLabel
< cw
? item
.GetAlign() : wxLIST_FORMAT_LEFT
)
1755 wxFAIL_MSG( _T("unknown list item format") );
1758 case wxLIST_FORMAT_LEFT
:
1762 case wxLIST_FORMAT_RIGHT
:
1763 xAligned
= x
+ cw
- wLabel
;
1766 case wxLIST_FORMAT_CENTER
:
1767 xAligned
= x
+ (cw
- wLabel
) / 2;
1771 // if we have an image, draw it on the right of the label
1778 xAligned
+ wLabel
- ix
- MARGIN_BETWEEN_TEXT_AND_ICON
,
1779 HEADER_OFFSET_Y
+ (h
- 4 - iy
)/2,
1780 wxIMAGELIST_DRAW_TRANSPARENT
1783 cw
-= ix
+ MARGIN_BETWEEN_TEXT_AND_ICON
;
1786 // draw the text clipping it so that it doesn't overwrite the column
1788 wxDCClipper
clipper(dc
, x
, HEADER_OFFSET_Y
, cw
, h
- 4 );
1790 dc
.DrawText( item
.GetText(),
1791 xAligned
+ EXTRA_WIDTH
, h
/ 2 - hLabel
/ 2 ); //HEADER_OFFSET_Y + EXTRA_HEIGHT );
1797 void wxListHeaderWindow::DrawCurrent()
1799 int x1
= m_currentX
;
1801 m_owner
->ClientToScreen( &x1
, &y1
);
1803 int x2
= m_currentX
;
1805 m_owner
->GetClientSize( NULL
, &y2
);
1806 m_owner
->ClientToScreen( &x2
, &y2
);
1809 dc
.SetLogicalFunction( wxINVERT
);
1810 dc
.SetPen( wxPen( *wxBLACK
, 2, wxSOLID
) );
1811 dc
.SetBrush( *wxTRANSPARENT_BRUSH
);
1815 dc
.DrawLine( x1
, y1
, x2
, y2
);
1817 dc
.SetLogicalFunction( wxCOPY
);
1819 dc
.SetPen( wxNullPen
);
1820 dc
.SetBrush( wxNullBrush
);
1823 void wxListHeaderWindow::OnMouse( wxMouseEvent
&event
)
1825 // we want to work with logical coords
1827 m_owner
->CalcUnscrolledPosition(event
.GetX(), 0, &x
, NULL
);
1828 int y
= event
.GetY();
1832 SendListEvent(wxEVT_COMMAND_LIST_COL_DRAGGING
, event
.GetPosition());
1834 // we don't draw the line beyond our window, but we allow dragging it
1837 GetClientSize( &w
, NULL
);
1838 m_owner
->CalcUnscrolledPosition(w
, 0, &w
, NULL
);
1841 // erase the line if it was drawn
1842 if ( m_currentX
< w
)
1845 if (event
.ButtonUp())
1848 m_isDragging
= false;
1850 m_owner
->SetColumnWidth( m_column
, m_currentX
- m_minX
);
1851 SendListEvent(wxEVT_COMMAND_LIST_COL_END_DRAG
, event
.GetPosition());
1858 m_currentX
= m_minX
+ 7;
1860 // draw in the new location
1861 if ( m_currentX
< w
)
1865 else // not dragging
1868 bool hit_border
= false;
1870 // end of the current column
1873 // find the column where this event occurred
1875 countCol
= m_owner
->GetColumnCount();
1876 for (col
= 0; col
< countCol
; col
++)
1878 xpos
+= m_owner
->GetColumnWidth( col
);
1881 if ( (abs(x
-xpos
) < 3) && (y
< 22) )
1883 // near the column border
1890 // inside the column
1897 if ( col
== countCol
)
1900 if (event
.LeftDown() || event
.RightUp())
1902 if (hit_border
&& event
.LeftDown())
1904 if ( SendListEvent(wxEVT_COMMAND_LIST_COL_BEGIN_DRAG
,
1905 event
.GetPosition()) )
1907 m_isDragging
= true;
1912 //else: column resizing was vetoed by the user code
1914 else // click on a column
1916 SendListEvent( event
.LeftDown()
1917 ? wxEVT_COMMAND_LIST_COL_CLICK
1918 : wxEVT_COMMAND_LIST_COL_RIGHT_CLICK
,
1919 event
.GetPosition());
1922 else if (event
.Moving())
1927 setCursor
= m_currentCursor
== wxSTANDARD_CURSOR
;
1928 m_currentCursor
= m_resizeCursor
;
1932 setCursor
= m_currentCursor
!= wxSTANDARD_CURSOR
;
1933 m_currentCursor
= wxSTANDARD_CURSOR
;
1937 SetCursor(*m_currentCursor
);
1942 void wxListHeaderWindow::OnSetFocus( wxFocusEvent
&WXUNUSED(event
) )
1944 m_owner
->SetFocus();
1948 bool wxListHeaderWindow::SendListEvent(wxEventType type
, const wxPoint
& pos
)
1950 wxWindow
*parent
= GetParent();
1951 wxListEvent
le( type
, parent
->GetId() );
1952 le
.SetEventObject( parent
);
1953 le
.m_pointDrag
= pos
;
1955 // the position should be relative to the parent window, not
1956 // this one for compatibility with MSW and common sense: the
1957 // user code doesn't know anything at all about this header
1958 // window, so why should it get positions relative to it?
1959 le
.m_pointDrag
.y
-= GetSize().y
;
1961 le
.m_col
= m_column
;
1962 return !parent
->GetEventHandler()->ProcessEvent( le
) || le
.IsAllowed();
1965 //-----------------------------------------------------------------------------
1966 // wxListRenameTimer (internal)
1967 //-----------------------------------------------------------------------------
1969 wxListRenameTimer::wxListRenameTimer( wxListMainWindow
*owner
)
1974 void wxListRenameTimer::Notify()
1976 m_owner
->OnRenameTimer();
1979 //-----------------------------------------------------------------------------
1980 // wxListTextCtrl (internal)
1981 //-----------------------------------------------------------------------------
1983 BEGIN_EVENT_TABLE(wxListTextCtrl
,wxTextCtrl
)
1984 EVT_CHAR (wxListTextCtrl::OnChar
)
1985 EVT_KEY_UP (wxListTextCtrl::OnKeyUp
)
1986 EVT_KILL_FOCUS (wxListTextCtrl::OnKillFocus
)
1989 wxListTextCtrl::wxListTextCtrl(wxListMainWindow
*owner
, size_t itemEdit
)
1990 : m_startValue(owner
->GetItemText(itemEdit
)),
1991 m_itemEdited(itemEdit
)
1995 m_aboutToFinish
= false;
1997 wxRect rectLabel
= owner
->GetLineLabelRect(itemEdit
);
1999 m_owner
->CalcScrolledPosition(rectLabel
.x
, rectLabel
.y
,
2000 &rectLabel
.x
, &rectLabel
.y
);
2002 (void)Create(owner
, wxID_ANY
, m_startValue
,
2003 wxPoint(rectLabel
.x
-4,rectLabel
.y
-4),
2004 wxSize(rectLabel
.width
+11,rectLabel
.height
+8));
2007 void wxListTextCtrl::Finish()
2011 wxPendingDelete
.Append(this);
2012 m_owner
->m_textctrl
= NULL
;
2016 m_owner
->SetFocusIgnoringChildren();
2020 bool wxListTextCtrl::AcceptChanges()
2022 const wxString value
= GetValue();
2024 if ( value
== m_startValue
)
2025 // nothing changed, always accept
2028 if ( !m_owner
->OnRenameAccept(m_itemEdited
, value
) )
2029 // vetoed by the user
2032 // accepted, do rename the item
2033 m_owner
->SetItemText(m_itemEdited
, value
);
2038 void wxListTextCtrl::AcceptChangesAndFinish()
2040 m_aboutToFinish
= true;
2042 // Notify the owner about the changes
2045 // Even if vetoed, close the control (consistent with MSW)
2049 void wxListTextCtrl::OnChar( wxKeyEvent
&event
)
2051 switch ( event
.m_keyCode
)
2054 AcceptChangesAndFinish();
2059 m_owner
->OnRenameCancelled( m_itemEdited
);
2067 void wxListTextCtrl::OnKeyUp( wxKeyEvent
&event
)
2075 // auto-grow the textctrl:
2076 wxSize parentSize
= m_owner
->GetSize();
2077 wxPoint myPos
= GetPosition();
2078 wxSize mySize
= GetSize();
2080 GetTextExtent(GetValue() + _T("MM"), &sx
, &sy
);
2081 if (myPos
.x
+ sx
> parentSize
.x
)
2082 sx
= parentSize
.x
- myPos
.x
;
2085 SetSize(sx
, wxDefaultCoord
);
2090 void wxListTextCtrl::OnKillFocus( wxFocusEvent
&event
)
2092 if ( !m_finished
&& !m_aboutToFinish
)
2094 // We must finish regardless of success, otherwise we'll get
2098 if ( !AcceptChanges() )
2099 m_owner
->OnRenameCancelled( m_itemEdited
);
2102 // We must let the native text control handle focus, too, otherwise
2103 // it could have problems with the cursor (e.g., in wxGTK).
2107 //-----------------------------------------------------------------------------
2109 //-----------------------------------------------------------------------------
2111 IMPLEMENT_DYNAMIC_CLASS(wxListMainWindow
,wxScrolledWindow
)
2113 BEGIN_EVENT_TABLE(wxListMainWindow
,wxScrolledWindow
)
2114 EVT_PAINT (wxListMainWindow::OnPaint
)
2115 EVT_MOUSE_EVENTS (wxListMainWindow::OnMouse
)
2116 EVT_CHAR (wxListMainWindow::OnChar
)
2117 EVT_KEY_DOWN (wxListMainWindow::OnKeyDown
)
2118 EVT_SET_FOCUS (wxListMainWindow::OnSetFocus
)
2119 EVT_KILL_FOCUS (wxListMainWindow::OnKillFocus
)
2120 EVT_SCROLLWIN (wxListMainWindow::OnScroll
)
2123 void wxListMainWindow::Init()
2128 m_lineTo
= (size_t)-1;
2134 m_small_image_list
= (wxImageListType
*) NULL
;
2135 m_normal_image_list
= (wxImageListType
*) NULL
;
2137 m_small_spacing
= 30;
2138 m_normal_spacing
= 40;
2142 m_isCreated
= false;
2144 m_lastOnSame
= false;
2145 m_renameTimer
= new wxListRenameTimer( this );
2150 m_lineSelectSingleOnUp
=
2151 m_lineBeforeLastClicked
= (size_t)-1;
2156 wxListMainWindow::wxListMainWindow()
2161 m_highlightUnfocusedBrush
= (wxBrush
*) NULL
;
2164 wxListMainWindow::wxListMainWindow( wxWindow
*parent
,
2169 const wxString
&name
)
2170 : wxScrolledWindow( parent
, id
, pos
, size
,
2171 style
| wxHSCROLL
| wxVSCROLL
, name
)
2175 m_highlightBrush
= new wxBrush
2177 wxSystemSettings::GetColour
2179 wxSYS_COLOUR_HIGHLIGHT
2184 m_highlightUnfocusedBrush
= new wxBrush
2186 wxSystemSettings::GetColour
2188 wxSYS_COLOUR_BTNSHADOW
2193 SetScrollbars( 0, 0, 0, 0, 0, 0 );
2195 wxVisualAttributes attr
= wxGenericListCtrl::GetClassDefaultAttributes();
2196 SetOwnForegroundColour( attr
.colFg
);
2197 SetOwnBackgroundColour( attr
.colBg
);
2199 SetOwnFont( attr
.font
);
2202 wxListMainWindow::~wxListMainWindow()
2205 WX_CLEAR_LIST(wxListHeaderDataList
, m_columns
);
2206 WX_CLEAR_ARRAY(m_aColWidths
);
2208 delete m_highlightBrush
;
2209 delete m_highlightUnfocusedBrush
;
2210 delete m_renameTimer
;
2213 void wxListMainWindow::CacheLineData(size_t line
)
2215 wxGenericListCtrl
*listctrl
= GetListCtrl();
2217 wxListLineData
*ld
= GetDummyLine();
2219 size_t countCol
= GetColumnCount();
2220 for ( size_t col
= 0; col
< countCol
; col
++ )
2222 ld
->SetText(col
, listctrl
->OnGetItemText(line
, col
));
2223 ld
->SetImage(col
, listctrl
->OnGetItemColumnImage(line
, col
));
2226 ld
->SetAttr(listctrl
->OnGetItemAttr(line
));
2229 wxListLineData
*wxListMainWindow::GetDummyLine() const
2231 wxASSERT_MSG( !IsEmpty(), _T("invalid line index") );
2232 wxASSERT_MSG( IsVirtual(), _T("GetDummyLine() shouldn't be called") );
2234 wxListMainWindow
*self
= wxConstCast(this, wxListMainWindow
);
2236 // we need to recreate the dummy line if the number of columns in the
2237 // control changed as it would have the incorrect number of fields
2239 if ( !m_lines
.IsEmpty() &&
2240 m_lines
[0].m_items
.GetCount() != (size_t)GetColumnCount() )
2242 self
->m_lines
.Clear();
2245 if ( m_lines
.IsEmpty() )
2247 wxListLineData
*line
= new wxListLineData(self
);
2248 self
->m_lines
.Add(line
);
2250 // don't waste extra memory -- there never going to be anything
2251 // else/more in this array
2252 self
->m_lines
.Shrink();
2258 // ----------------------------------------------------------------------------
2259 // line geometry (report mode only)
2260 // ----------------------------------------------------------------------------
2262 wxCoord
wxListMainWindow::GetLineHeight() const
2264 // we cache the line height as calling GetTextExtent() is slow
2265 if ( !m_lineHeight
)
2267 wxListMainWindow
*self
= wxConstCast(this, wxListMainWindow
);
2269 wxClientDC
dc( self
);
2270 dc
.SetFont( GetFont() );
2273 dc
.GetTextExtent(_T("H"), NULL
, &y
);
2275 if ( m_small_image_list
&& m_small_image_list
->GetImageCount() )
2278 m_small_image_list
->GetSize(0, iw
, ih
);
2283 self
->m_lineHeight
= y
+ LINE_SPACING
;
2286 return m_lineHeight
;
2289 wxCoord
wxListMainWindow::GetLineY(size_t line
) const
2291 wxASSERT_MSG( InReportView(), _T("only works in report mode") );
2293 return LINE_SPACING
+ line
* GetLineHeight();
2296 wxRect
wxListMainWindow::GetLineRect(size_t line
) const
2298 if ( !InReportView() )
2299 return GetLine(line
)->m_gi
->m_rectAll
;
2302 rect
.x
= HEADER_OFFSET_X
;
2303 rect
.y
= GetLineY(line
);
2304 rect
.width
= GetHeaderWidth();
2305 rect
.height
= GetLineHeight();
2310 wxRect
wxListMainWindow::GetLineLabelRect(size_t line
) const
2312 if ( !InReportView() )
2313 return GetLine(line
)->m_gi
->m_rectLabel
;
2316 rect
.x
= HEADER_OFFSET_X
;
2317 rect
.y
= GetLineY(line
);
2318 rect
.width
= GetColumnWidth(0);
2319 rect
.height
= GetLineHeight();
2324 wxRect
wxListMainWindow::GetLineIconRect(size_t line
) const
2326 if ( !InReportView() )
2327 return GetLine(line
)->m_gi
->m_rectIcon
;
2329 wxListLineData
*ld
= GetLine(line
);
2330 wxASSERT_MSG( ld
->HasImage(), _T("should have an image") );
2333 rect
.x
= HEADER_OFFSET_X
;
2334 rect
.y
= GetLineY(line
);
2335 GetImageSize(ld
->GetImage(), rect
.width
, rect
.height
);
2340 wxRect
wxListMainWindow::GetLineHighlightRect(size_t line
) const
2342 return InReportView() ? GetLineRect(line
)
2343 : GetLine(line
)->m_gi
->m_rectHighlight
;
2346 long wxListMainWindow::HitTestLine(size_t line
, int x
, int y
) const
2348 wxASSERT_MSG( line
< GetItemCount(), _T("invalid line in HitTestLine") );
2350 wxListLineData
*ld
= GetLine(line
);
2352 if ( ld
->HasImage() && GetLineIconRect(line
).Inside(x
, y
) )
2353 return wxLIST_HITTEST_ONITEMICON
;
2355 // VS: Testing for "ld->HasText() || InReportView()" instead of
2356 // "ld->HasText()" is needed to make empty lines in report view
2358 if ( ld
->HasText() || InReportView() )
2360 wxRect rect
= InReportView() ? GetLineRect(line
)
2361 : GetLineLabelRect(line
);
2363 if ( rect
.Inside(x
, y
) )
2364 return wxLIST_HITTEST_ONITEMLABEL
;
2370 // ----------------------------------------------------------------------------
2371 // highlight (selection) handling
2372 // ----------------------------------------------------------------------------
2374 bool wxListMainWindow::IsHighlighted(size_t line
) const
2378 return m_selStore
.IsSelected(line
);
2382 wxListLineData
*ld
= GetLine(line
);
2383 wxCHECK_MSG( ld
, false, _T("invalid index in IsHighlighted") );
2385 return ld
->IsHighlighted();
2389 void wxListMainWindow::HighlightLines( size_t lineFrom
,
2395 wxArrayInt linesChanged
;
2396 if ( !m_selStore
.SelectRange(lineFrom
, lineTo
, highlight
,
2399 // meny items changed state, refresh everything
2400 RefreshLines(lineFrom
, lineTo
);
2402 else // only a few items changed state, refresh only them
2404 size_t count
= linesChanged
.GetCount();
2405 for ( size_t n
= 0; n
< count
; n
++ )
2407 RefreshLine(linesChanged
[n
]);
2411 else // iterate over all items in non report view
2413 for ( size_t line
= lineFrom
; line
<= lineTo
; line
++ )
2415 if ( HighlightLine(line
, highlight
) )
2421 bool wxListMainWindow::HighlightLine( size_t line
, bool highlight
)
2427 changed
= m_selStore
.SelectItem(line
, highlight
);
2431 wxListLineData
*ld
= GetLine(line
);
2432 wxCHECK_MSG( ld
, false, _T("invalid index in HighlightLine") );
2434 changed
= ld
->Highlight(highlight
);
2439 SendNotify( line
, highlight
? wxEVT_COMMAND_LIST_ITEM_SELECTED
2440 : wxEVT_COMMAND_LIST_ITEM_DESELECTED
);
2446 void wxListMainWindow::RefreshLine( size_t line
)
2448 if ( InReportView() )
2450 size_t visibleFrom
, visibleTo
;
2451 GetVisibleLinesRange(&visibleFrom
, &visibleTo
);
2453 if ( line
< visibleFrom
|| line
> visibleTo
)
2457 wxRect rect
= GetLineRect(line
);
2459 CalcScrolledPosition( rect
.x
, rect
.y
, &rect
.x
, &rect
.y
);
2460 RefreshRect( rect
);
2463 void wxListMainWindow::RefreshLines( size_t lineFrom
, size_t lineTo
)
2465 // we suppose that they are ordered by caller
2466 wxASSERT_MSG( lineFrom
<= lineTo
, _T("indices in disorder") );
2468 wxASSERT_MSG( lineTo
< GetItemCount(), _T("invalid line range") );
2470 if ( InReportView() )
2472 size_t visibleFrom
, visibleTo
;
2473 GetVisibleLinesRange(&visibleFrom
, &visibleTo
);
2475 if ( lineFrom
< visibleFrom
)
2476 lineFrom
= visibleFrom
;
2477 if ( lineTo
> visibleTo
)
2482 rect
.y
= GetLineY(lineFrom
);
2483 rect
.width
= GetClientSize().x
;
2484 rect
.height
= GetLineY(lineTo
) - rect
.y
+ GetLineHeight();
2486 CalcScrolledPosition( rect
.x
, rect
.y
, &rect
.x
, &rect
.y
);
2487 RefreshRect( rect
);
2491 // TODO: this should be optimized...
2492 for ( size_t line
= lineFrom
; line
<= lineTo
; line
++ )
2499 void wxListMainWindow::RefreshAfter( size_t lineFrom
)
2501 if ( InReportView() )
2503 size_t visibleFrom
, visibleTo
;
2504 GetVisibleLinesRange(&visibleFrom
, &visibleTo
);
2506 if ( lineFrom
< visibleFrom
)
2507 lineFrom
= visibleFrom
;
2508 else if ( lineFrom
> visibleTo
)
2513 rect
.y
= GetLineY(lineFrom
);
2514 CalcScrolledPosition( rect
.x
, rect
.y
, &rect
.x
, &rect
.y
);
2516 wxSize size
= GetClientSize();
2517 rect
.width
= size
.x
;
2519 // refresh till the bottom of the window
2520 rect
.height
= size
.y
- rect
.y
;
2522 RefreshRect( rect
);
2526 // TODO: how to do it more efficiently?
2531 void wxListMainWindow::RefreshSelected()
2537 if ( InReportView() )
2539 GetVisibleLinesRange(&from
, &to
);
2544 to
= GetItemCount() - 1;
2547 if ( HasCurrent() && m_current
>= from
&& m_current
<= to
)
2548 RefreshLine(m_current
);
2550 for ( size_t line
= from
; line
<= to
; line
++ )
2552 // NB: the test works as expected even if m_current == -1
2553 if ( line
!= m_current
&& IsHighlighted(line
) )
2558 void wxListMainWindow::Freeze()
2563 void wxListMainWindow::Thaw()
2565 wxCHECK_RET( m_freezeCount
> 0, _T("thawing unfrozen list control?") );
2567 if ( --m_freezeCount
== 0 )
2571 void wxListMainWindow::OnPaint( wxPaintEvent
&WXUNUSED(event
) )
2573 // Note: a wxPaintDC must be constructed even if no drawing is
2574 // done (a Windows requirement).
2575 wxPaintDC
dc( this );
2577 if ( IsEmpty() || m_freezeCount
)
2578 // nothing to draw or not the moment to draw it
2582 // delay the repainting until we calculate all the items positions
2588 CalcScrolledPosition( 0, 0, &dev_x
, &dev_y
);
2590 dc
.SetFont( GetFont() );
2592 if ( InReportView() )
2594 int lineHeight
= GetLineHeight();
2596 size_t visibleFrom
, visibleTo
;
2597 GetVisibleLinesRange(&visibleFrom
, &visibleTo
);
2600 wxCoord xOrig
, yOrig
;
2601 CalcUnscrolledPosition(0, 0, &xOrig
, &yOrig
);
2603 // tell the caller cache to cache the data
2606 wxListEvent
evCache(wxEVT_COMMAND_LIST_CACHE_HINT
,
2607 GetParent()->GetId());
2608 evCache
.SetEventObject( GetParent() );
2609 evCache
.m_oldItemIndex
= visibleFrom
;
2610 evCache
.m_itemIndex
= visibleTo
;
2611 GetParent()->GetEventHandler()->ProcessEvent( evCache
);
2614 for ( size_t line
= visibleFrom
; line
<= visibleTo
; line
++ )
2616 rectLine
= GetLineRect(line
);
2618 if ( !IsExposed(rectLine
.x
- xOrig
, rectLine
.y
- yOrig
,
2619 rectLine
.width
, rectLine
.height
) )
2621 // don't redraw unaffected lines to avoid flicker
2625 GetLine(line
)->DrawInReportMode( &dc
,
2627 GetLineHighlightRect(line
),
2628 IsHighlighted(line
) );
2631 if ( HasFlag(wxLC_HRULES
) )
2633 wxPen
pen(GetRuleColour(), 1, wxSOLID
);
2634 wxSize clientSize
= GetClientSize();
2636 // Don't draw the first one
2637 for ( size_t i
= visibleFrom
+ 1; i
<= visibleTo
; i
++ )
2640 dc
.SetBrush( *wxTRANSPARENT_BRUSH
);
2641 dc
.DrawLine(0 - dev_x
, i
* lineHeight
,
2642 clientSize
.x
- dev_x
, i
* lineHeight
);
2645 // Draw last horizontal rule
2646 if ( visibleTo
== GetItemCount() - 1 )
2649 dc
.SetBrush( *wxTRANSPARENT_BRUSH
);
2650 dc
.DrawLine(0 - dev_x
, (m_lineTo
+ 1) * lineHeight
,
2651 clientSize
.x
- dev_x
, (m_lineTo
+ 1) * lineHeight
);
2655 // Draw vertical rules if required
2656 if ( HasFlag(wxLC_VRULES
) && !IsEmpty() )
2658 wxPen
pen(GetRuleColour(), 1, wxSOLID
);
2659 wxRect firstItemRect
, lastItemRect
;
2661 GetItemRect(visibleFrom
, firstItemRect
);
2662 GetItemRect(visibleTo
, lastItemRect
);
2663 int x
= firstItemRect
.GetX();
2665 dc
.SetBrush(* wxTRANSPARENT_BRUSH
);
2667 for (int col
= 0; col
< GetColumnCount(); col
++)
2669 int colWidth
= GetColumnWidth(col
);
2671 dc
.DrawLine(x
- dev_x
- 2, firstItemRect
.GetY() - 1 - dev_y
,
2672 x
- dev_x
- 2, lastItemRect
.GetBottom() + 1 - dev_y
);
2678 size_t count
= GetItemCount();
2679 for ( size_t i
= 0; i
< count
; i
++ )
2681 GetLine(i
)->Draw( &dc
);
2686 // Don't draw rect outline under Mac at all.
2691 dc
.SetPen( *wxBLACK_PEN
);
2692 dc
.SetBrush( *wxTRANSPARENT_BRUSH
);
2693 dc
.DrawRectangle( GetLineHighlightRect( m_current
) );
2699 void wxListMainWindow::HighlightAll( bool on
)
2701 if ( IsSingleSel() )
2703 wxASSERT_MSG( !on
, _T("can't do this in a single selection control") );
2705 // we just have one item to turn off
2706 if ( HasCurrent() && IsHighlighted(m_current
) )
2708 HighlightLine(m_current
, false);
2709 RefreshLine(m_current
);
2714 HighlightLines(0, GetItemCount() - 1, on
);
2718 void wxListMainWindow::SendNotify( size_t line
,
2719 wxEventType command
,
2720 const wxPoint
& point
)
2722 wxListEvent
le( command
, GetParent()->GetId() );
2723 le
.SetEventObject( GetParent() );
2724 le
.m_itemIndex
= line
;
2726 // set only for events which have position
2727 if ( point
!= wxDefaultPosition
)
2728 le
.m_pointDrag
= point
;
2730 // don't try to get the line info for virtual list controls: the main
2731 // program has it anyhow and if we did it would result in accessing all
2732 // the lines, even those which are not visible now and this is precisely
2733 // what we're trying to avoid
2734 if ( !IsVirtual() && (command
!= wxEVT_COMMAND_LIST_DELETE_ITEM
) )
2736 if ( line
!= (size_t)-1 )
2738 GetLine(line
)->GetItem( 0, le
.m_item
);
2740 //else: this happens for wxEVT_COMMAND_LIST_ITEM_FOCUSED event
2742 //else: there may be no more such item
2744 GetParent()->GetEventHandler()->ProcessEvent( le
);
2747 void wxListMainWindow::ChangeCurrent(size_t current
)
2749 m_current
= current
;
2751 SendNotify(current
, wxEVT_COMMAND_LIST_ITEM_FOCUSED
);
2754 void wxListMainWindow::EditLabel( long item
)
2756 wxCHECK_RET( (item
>= 0) && ((size_t)item
< GetItemCount()),
2757 wxT("wrong index in wxGenericListCtrl::EditLabel()") );
2759 size_t itemEdit
= (size_t)item
;
2761 wxListEvent
le( wxEVT_COMMAND_LIST_BEGIN_LABEL_EDIT
, GetParent()->GetId() );
2762 le
.SetEventObject( GetParent() );
2763 le
.m_itemIndex
= item
;
2764 wxListLineData
*data
= GetLine(itemEdit
);
2765 wxCHECK_RET( data
, _T("invalid index in EditLabel()") );
2766 data
->GetItem( 0, le
.m_item
);
2768 if ( GetParent()->GetEventHandler()->ProcessEvent( le
) && !le
.IsAllowed() )
2769 // vetoed by user code
2772 // We have to call this here because the label in question might just have
2773 // been added and no screen update taken place.
2777 m_textctrl
= new wxListTextCtrl(this, itemEdit
);
2778 m_textctrl
->SetFocus();
2781 void wxListMainWindow::OnRenameTimer()
2783 wxCHECK_RET( HasCurrent(), wxT("unexpected rename timer") );
2785 EditLabel( m_current
);
2788 bool wxListMainWindow::OnRenameAccept(size_t itemEdit
, const wxString
& value
)
2790 wxListEvent
le( wxEVT_COMMAND_LIST_END_LABEL_EDIT
, GetParent()->GetId() );
2791 le
.SetEventObject( GetParent() );
2792 le
.m_itemIndex
= itemEdit
;
2794 wxListLineData
*data
= GetLine(itemEdit
);
2796 wxCHECK_MSG( data
, false, _T("invalid index in OnRenameAccept()") );
2798 data
->GetItem( 0, le
.m_item
);
2799 le
.m_item
.m_text
= value
;
2800 return !GetParent()->GetEventHandler()->ProcessEvent( le
) ||
2804 void wxListMainWindow::OnRenameCancelled(size_t itemEdit
)
2806 // let owner know that the edit was cancelled
2807 wxListEvent
le( wxEVT_COMMAND_LIST_END_LABEL_EDIT
, GetParent()->GetId() );
2809 le
.SetEditCanceled(true);
2811 le
.SetEventObject( GetParent() );
2812 le
.m_itemIndex
= itemEdit
;
2814 wxListLineData
*data
= GetLine(itemEdit
);
2815 wxCHECK_RET( data
, _T("invalid index in OnRenameCancelled()") );
2817 data
->GetItem( 0, le
.m_item
);
2818 GetEventHandler()->ProcessEvent( le
);
2821 void wxListMainWindow::OnMouse( wxMouseEvent
&event
)
2824 // On wxMac we can't depend on the EVT_KILL_FOCUS event to properly
2825 // shutdown the edit control when the mouse is clicked elsewhere on the
2826 // listctrl because the order of events is different (or something like
2827 // that), so explicitly end the edit if it is active.
2828 if ( event
.LeftDown() && m_textctrl
)
2829 m_textctrl
->AcceptChangesAndFinish();
2832 event
.SetEventObject( GetParent() );
2833 if ( GetParent()->GetEventHandler()->ProcessEvent( event
) )
2836 if (event
.GetEventType() == wxEVT_MOUSEWHEEL
)
2838 // let the base handle mouse wheel events.
2843 if ( !HasCurrent() || IsEmpty() )
2849 if ( !(event
.Dragging() || event
.ButtonDown() || event
.LeftUp() ||
2850 event
.ButtonDClick()) )
2853 int x
= event
.GetX();
2854 int y
= event
.GetY();
2855 CalcUnscrolledPosition( x
, y
, &x
, &y
);
2857 // where did we hit it (if we did)?
2860 size_t count
= GetItemCount(),
2863 if ( InReportView() )
2865 current
= y
/ GetLineHeight();
2866 if ( current
< count
)
2867 hitResult
= HitTestLine(current
, x
, y
);
2871 // TODO: optimize it too! this is less simple than for report view but
2872 // enumerating all items is still not a way to do it!!
2873 for ( current
= 0; current
< count
; current
++ )
2875 hitResult
= HitTestLine(current
, x
, y
);
2881 if (event
.Dragging())
2883 if (m_dragCount
== 0)
2885 // we have to report the raw, physical coords as we want to be
2886 // able to call HitTest(event.m_pointDrag) from the user code to
2887 // get the item being dragged
2888 m_dragStart
= event
.GetPosition();
2893 if (m_dragCount
!= 3)
2896 int command
= event
.RightIsDown() ? wxEVT_COMMAND_LIST_BEGIN_RDRAG
2897 : wxEVT_COMMAND_LIST_BEGIN_DRAG
;
2899 wxListEvent
le( command
, GetParent()->GetId() );
2900 le
.SetEventObject( GetParent() );
2901 le
.m_itemIndex
= m_lineLastClicked
;
2902 le
.m_pointDrag
= m_dragStart
;
2903 GetParent()->GetEventHandler()->ProcessEvent( le
);
2914 // outside of any item
2918 bool forceClick
= false;
2919 if (event
.ButtonDClick())
2921 m_renameTimer
->Stop();
2922 m_lastOnSame
= false;
2924 if ( current
== m_lineLastClicked
)
2926 SendNotify( current
, wxEVT_COMMAND_LIST_ITEM_ACTIVATED
);
2932 // The first click was on another item, so don't interpret this as
2933 // a double click, but as a simple click instead
2940 if (m_lineSelectSingleOnUp
!= (size_t)-1)
2942 // select single line
2943 HighlightAll( false );
2944 ReverseHighlight(m_lineSelectSingleOnUp
);
2949 if ((current
== m_current
) &&
2950 (hitResult
== wxLIST_HITTEST_ONITEMLABEL
) &&
2951 HasFlag(wxLC_EDIT_LABELS
) )
2953 m_renameTimer
->Start( 100, true );
2957 m_lastOnSame
= false;
2958 m_lineSelectSingleOnUp
= (size_t)-1;
2962 // This is necessary, because after a DnD operation in
2963 // from and to ourself, the up event is swallowed by the
2964 // DnD code. So on next non-up event (which means here and
2965 // now) m_lineSelectSingleOnUp should be reset.
2966 m_lineSelectSingleOnUp
= (size_t)-1;
2968 if (event
.RightDown())
2970 m_lineBeforeLastClicked
= m_lineLastClicked
;
2971 m_lineLastClicked
= current
;
2973 // If the item is already selected, do not update the selection.
2974 // Multi-selections should not be cleared if a selected item is clicked.
2975 if (!IsHighlighted(current
))
2977 HighlightAll(false);
2978 ChangeCurrent(current
);
2979 ReverseHighlight(m_current
);
2982 SendNotify( current
, wxEVT_COMMAND_LIST_ITEM_RIGHT_CLICK
, event
.GetPosition() );
2984 // Allow generation of context menu event
2987 else if (event
.MiddleDown())
2989 SendNotify( current
, wxEVT_COMMAND_LIST_ITEM_MIDDLE_CLICK
);
2991 else if ( event
.LeftDown() || forceClick
)
2993 m_lineBeforeLastClicked
= m_lineLastClicked
;
2994 m_lineLastClicked
= current
;
2996 size_t oldCurrent
= m_current
;
2997 bool oldWasSelected
= IsHighlighted(m_current
);
2999 bool cmdModifierDown
= event
.CmdDown();
3000 if ( IsSingleSel() || !(cmdModifierDown
|| event
.ShiftDown()) )
3002 if ( IsSingleSel() || !IsHighlighted(current
) )
3004 HighlightAll( false );
3006 ChangeCurrent(current
);
3008 ReverseHighlight(m_current
);
3010 else // multi sel & current is highlighted & no mod keys
3012 m_lineSelectSingleOnUp
= current
;
3013 ChangeCurrent(current
); // change focus
3016 else // multi sel & either ctrl or shift is down
3018 if (cmdModifierDown
)
3020 ChangeCurrent(current
);
3022 ReverseHighlight(m_current
);
3024 else if (event
.ShiftDown())
3026 ChangeCurrent(current
);
3028 size_t lineFrom
= oldCurrent
,
3031 if ( lineTo
< lineFrom
)
3034 lineFrom
= m_current
;
3037 HighlightLines(lineFrom
, lineTo
);
3039 else // !ctrl, !shift
3041 // test in the enclosing if should make it impossible
3042 wxFAIL_MSG( _T("how did we get here?") );
3046 if (m_current
!= oldCurrent
)
3047 RefreshLine( oldCurrent
);
3049 // forceClick is only set if the previous click was on another item
3050 m_lastOnSame
= !forceClick
&& (m_current
== oldCurrent
) && oldWasSelected
;
3054 void wxListMainWindow::MoveToItem(size_t item
)
3056 if ( item
== (size_t)-1 )
3059 wxRect rect
= GetLineRect(item
);
3061 int client_w
, client_h
;
3062 GetClientSize( &client_w
, &client_h
);
3064 const int hLine
= GetLineHeight();
3066 int view_x
= SCROLL_UNIT_X
* GetScrollPos( wxHORIZONTAL
);
3067 int view_y
= hLine
* GetScrollPos( wxVERTICAL
);
3069 if ( InReportView() )
3071 // the next we need the range of lines shown it might be different,
3072 // so recalculate it
3073 ResetVisibleLinesRange();
3075 if (rect
.y
< view_y
)
3076 Scroll( -1, rect
.y
/ hLine
);
3077 if (rect
.y
+ rect
.height
+ 5 > view_y
+ client_h
)
3078 Scroll( -1, (rect
.y
+ rect
.height
- client_h
+ hLine
) / hLine
);
3082 if (rect
.x
-view_x
< 5)
3083 Scroll( (rect
.x
- 5) / SCROLL_UNIT_X
, -1 );
3084 if (rect
.x
+ rect
.width
- 5 > view_x
+ client_w
)
3085 Scroll( (rect
.x
+ rect
.width
- client_w
+ SCROLL_UNIT_X
) / SCROLL_UNIT_X
, -1 );
3089 // ----------------------------------------------------------------------------
3090 // keyboard handling
3091 // ----------------------------------------------------------------------------
3093 void wxListMainWindow::OnArrowChar(size_t newCurrent
, const wxKeyEvent
& event
)
3095 wxCHECK_RET( newCurrent
< (size_t)GetItemCount(),
3096 _T("invalid item index in OnArrowChar()") );
3098 size_t oldCurrent
= m_current
;
3100 // in single selection we just ignore Shift as we can't select several
3102 if ( event
.ShiftDown() && !IsSingleSel() )
3104 ChangeCurrent(newCurrent
);
3106 // refresh the old focus to remove it
3107 RefreshLine( oldCurrent
);
3109 // select all the items between the old and the new one
3110 if ( oldCurrent
> newCurrent
)
3112 newCurrent
= oldCurrent
;
3113 oldCurrent
= m_current
;
3116 HighlightLines(oldCurrent
, newCurrent
);
3120 // all previously selected items are unselected unless ctrl is held
3121 if ( !event
.ControlDown() )
3122 HighlightAll(false);
3124 ChangeCurrent(newCurrent
);
3126 // refresh the old focus to remove it
3127 RefreshLine( oldCurrent
);
3129 if ( !event
.ControlDown() )
3131 HighlightLine( m_current
, true );
3135 RefreshLine( m_current
);
3140 void wxListMainWindow::OnKeyDown( wxKeyEvent
&event
)
3142 wxWindow
*parent
= GetParent();
3144 // propagate the key event upwards
3145 wxKeyEvent
ke( wxEVT_KEY_DOWN
);
3146 ke
.m_shiftDown
= event
.m_shiftDown
;
3147 ke
.m_controlDown
= event
.m_controlDown
;
3148 ke
.m_altDown
= event
.m_altDown
;
3149 ke
.m_metaDown
= event
.m_metaDown
;
3150 ke
.m_keyCode
= event
.m_keyCode
;
3153 ke
.SetEventObject( parent
);
3154 if (parent
->GetEventHandler()->ProcessEvent( ke
)) return;
3159 void wxListMainWindow::OnChar( wxKeyEvent
&event
)
3161 wxWindow
*parent
= GetParent();
3163 // send a list_key event up
3166 wxListEvent
le( wxEVT_COMMAND_LIST_KEY_DOWN
, GetParent()->GetId() );
3167 le
.m_itemIndex
= m_current
;
3168 GetLine(m_current
)->GetItem( 0, le
.m_item
);
3169 le
.m_code
= event
.GetKeyCode();
3170 le
.SetEventObject( parent
);
3171 parent
->GetEventHandler()->ProcessEvent( le
);
3174 // propagate the char event upwards
3175 wxKeyEvent
ke( wxEVT_CHAR
);
3176 ke
.m_shiftDown
= event
.m_shiftDown
;
3177 ke
.m_controlDown
= event
.m_controlDown
;
3178 ke
.m_altDown
= event
.m_altDown
;
3179 ke
.m_metaDown
= event
.m_metaDown
;
3180 ke
.m_keyCode
= event
.m_keyCode
;
3183 ke
.SetEventObject( parent
);
3184 if (parent
->GetEventHandler()->ProcessEvent( ke
)) return;
3186 if (event
.GetKeyCode() == WXK_TAB
)
3188 wxNavigationKeyEvent nevent
;
3189 nevent
.SetWindowChange( event
.ControlDown() );
3190 nevent
.SetDirection( !event
.ShiftDown() );
3191 nevent
.SetEventObject( GetParent()->GetParent() );
3192 nevent
.SetCurrentFocus( m_parent
);
3193 if (GetParent()->GetParent()->GetEventHandler()->ProcessEvent( nevent
))
3197 // no item -> nothing to do
3204 switch (event
.GetKeyCode())
3207 if ( m_current
> 0 )
3208 OnArrowChar( m_current
- 1, event
);
3212 if ( m_current
< (size_t)GetItemCount() - 1 )
3213 OnArrowChar( m_current
+ 1, event
);
3218 OnArrowChar( GetItemCount() - 1, event
);
3223 OnArrowChar( 0, event
);
3228 int steps
= InReportView() ? m_linesPerPage
- 1 : m_current
% m_linesPerPage
;
3230 int index
= m_current
- steps
;
3234 OnArrowChar( index
, event
);
3240 int steps
= InReportView()
3241 ? m_linesPerPage
- 1
3242 : m_linesPerPage
- (m_current
% m_linesPerPage
) - 1;
3244 size_t index
= m_current
+ steps
;
3245 size_t count
= GetItemCount();
3246 if ( index
>= count
)
3249 OnArrowChar( index
, event
);
3254 if ( !InReportView() )
3256 int index
= m_current
- m_linesPerPage
;
3260 OnArrowChar( index
, event
);
3265 if ( !InReportView() )
3267 size_t index
= m_current
+ m_linesPerPage
;
3269 size_t count
= GetItemCount();
3270 if ( index
>= count
)
3273 OnArrowChar( index
, event
);
3278 if ( IsSingleSel() )
3280 SendNotify( m_current
, wxEVT_COMMAND_LIST_ITEM_ACTIVATED
);
3282 if ( IsHighlighted(m_current
) )
3284 // don't unselect the item in single selection mode
3287 //else: select it in ReverseHighlight() below if unselected
3290 ReverseHighlight(m_current
);
3295 SendNotify( m_current
, wxEVT_COMMAND_LIST_ITEM_ACTIVATED
);
3303 // ----------------------------------------------------------------------------
3305 // ----------------------------------------------------------------------------
3307 void wxListMainWindow::OnSetFocus( wxFocusEvent
&WXUNUSED(event
) )
3311 wxFocusEvent
event( wxEVT_SET_FOCUS
, GetParent()->GetId() );
3312 event
.SetEventObject( GetParent() );
3313 if ( GetParent()->GetEventHandler()->ProcessEvent( event
) )
3317 // wxGTK sends us EVT_SET_FOCUS events even if we had never got
3318 // EVT_KILL_FOCUS before which means that we finish by redrawing the items
3319 // which are already drawn correctly resulting in horrible flicker - avoid
3329 void wxListMainWindow::OnKillFocus( wxFocusEvent
&WXUNUSED(event
) )
3333 wxFocusEvent
event( wxEVT_KILL_FOCUS
, GetParent()->GetId() );
3334 event
.SetEventObject( GetParent() );
3335 if ( GetParent()->GetEventHandler()->ProcessEvent( event
) )
3343 void wxListMainWindow::DrawImage( int index
, wxDC
*dc
, int x
, int y
)
3345 if ( HasFlag(wxLC_ICON
) && (m_normal_image_list
))
3347 m_normal_image_list
->Draw( index
, *dc
, x
, y
, wxIMAGELIST_DRAW_TRANSPARENT
);
3349 else if ( HasFlag(wxLC_SMALL_ICON
) && (m_small_image_list
))
3351 m_small_image_list
->Draw( index
, *dc
, x
, y
, wxIMAGELIST_DRAW_TRANSPARENT
);
3353 else if ( HasFlag(wxLC_LIST
) && (m_small_image_list
))
3355 m_small_image_list
->Draw( index
, *dc
, x
, y
, wxIMAGELIST_DRAW_TRANSPARENT
);
3357 else if ( InReportView() && (m_small_image_list
))
3359 m_small_image_list
->Draw( index
, *dc
, x
, y
, wxIMAGELIST_DRAW_TRANSPARENT
);
3363 void wxListMainWindow::GetImageSize( int index
, int &width
, int &height
) const
3365 if ( HasFlag(wxLC_ICON
) && m_normal_image_list
)
3367 m_normal_image_list
->GetSize( index
, width
, height
);
3369 else if ( HasFlag(wxLC_SMALL_ICON
) && m_small_image_list
)
3371 m_small_image_list
->GetSize( index
, width
, height
);
3373 else if ( HasFlag(wxLC_LIST
) && m_small_image_list
)
3375 m_small_image_list
->GetSize( index
, width
, height
);
3377 else if ( InReportView() && m_small_image_list
)
3379 m_small_image_list
->GetSize( index
, width
, height
);
3388 int wxListMainWindow::GetTextLength( const wxString
&s
) const
3390 wxClientDC
dc( wxConstCast(this, wxListMainWindow
) );
3391 dc
.SetFont( GetFont() );
3394 dc
.GetTextExtent( s
, &lw
, NULL
);
3396 return lw
+ AUTOSIZE_COL_MARGIN
;
3399 void wxListMainWindow::SetImageList( wxImageListType
*imageList
, int which
)
3403 // calc the spacing from the icon size
3404 int width
= 0, height
= 0;
3406 if ((imageList
) && (imageList
->GetImageCount()) )
3407 imageList
->GetSize(0, width
, height
);
3409 if (which
== wxIMAGE_LIST_NORMAL
)
3411 m_normal_image_list
= imageList
;
3412 m_normal_spacing
= width
+ 8;
3415 if (which
== wxIMAGE_LIST_SMALL
)
3417 m_small_image_list
= imageList
;
3418 m_small_spacing
= width
+ 14;
3419 m_lineHeight
= 0; // ensure that the line height will be recalc'd
3423 void wxListMainWindow::SetItemSpacing( int spacing
, bool isSmall
)
3427 m_small_spacing
= spacing
;
3429 m_normal_spacing
= spacing
;
3432 int wxListMainWindow::GetItemSpacing( bool isSmall
)
3434 return isSmall
? m_small_spacing
: m_normal_spacing
;
3437 // ----------------------------------------------------------------------------
3439 // ----------------------------------------------------------------------------
3441 void wxListMainWindow::SetColumn( int col
, wxListItem
&item
)
3443 wxListHeaderDataList::compatibility_iterator node
= m_columns
.Item( col
);
3445 wxCHECK_RET( node
, _T("invalid column index in SetColumn") );
3447 if ( item
.m_width
== wxLIST_AUTOSIZE_USEHEADER
)
3448 item
.m_width
= GetTextLength( item
.m_text
);
3450 wxListHeaderData
*column
= node
->GetData();
3451 column
->SetItem( item
);
3453 wxListHeaderWindow
*headerWin
= GetListCtrl()->m_headerWin
;
3455 headerWin
->m_dirty
= true;
3459 // invalidate it as it has to be recalculated
3463 void wxListMainWindow::SetColumnWidth( int col
, int width
)
3465 wxCHECK_RET( col
>= 0 && col
< GetColumnCount(),
3466 _T("invalid column index") );
3468 wxCHECK_RET( InReportView(),
3469 _T("SetColumnWidth() can only be called in report mode.") );
3472 wxListHeaderWindow
*headerWin
= GetListCtrl()->m_headerWin
;
3474 headerWin
->m_dirty
= true;
3476 wxListHeaderDataList::compatibility_iterator node
= m_columns
.Item( col
);
3477 wxCHECK_RET( node
, _T("no column?") );
3479 wxListHeaderData
*column
= node
->GetData();
3481 size_t count
= GetItemCount();
3483 if (width
== wxLIST_AUTOSIZE_USEHEADER
)
3485 width
= GetTextLength(column
->GetText());
3487 else if ( width
== wxLIST_AUTOSIZE
)
3491 // TODO: determine the max width somehow...
3492 width
= WIDTH_COL_DEFAULT
;
3496 wxClientDC
dc(this);
3497 dc
.SetFont( GetFont() );
3499 int max
= AUTOSIZE_COL_MARGIN
;
3501 // if the cached column width isn't valid then recalculate it
3502 if (m_aColWidths
.Item(col
)->bNeedsUpdate
)
3504 for (size_t i
= 0; i
< count
; i
++)
3506 wxListLineData
*line
= GetLine( i
);
3507 wxListItemDataList::compatibility_iterator n
= line
->m_items
.Item( col
);
3509 wxCHECK_RET( n
, _T("no subitem?") );
3511 wxListItemData
*itemData
= n
->GetData();
3514 itemData
->GetItem(item
);
3515 int itemWidth
= GetItemWidthWithImage(&item
);
3516 if (itemWidth
> max
)
3520 m_aColWidths
.Item(col
)->bNeedsUpdate
= false;
3521 m_aColWidths
.Item(col
)->nMaxWidth
= max
;
3524 max
= m_aColWidths
.Item(col
)->nMaxWidth
;
3525 width
= max
+ AUTOSIZE_COL_MARGIN
;
3529 column
->SetWidth( width
);
3531 // invalidate it as it has to be recalculated
3535 int wxListMainWindow::GetHeaderWidth() const
3537 if ( !m_headerWidth
)
3539 wxListMainWindow
*self
= wxConstCast(this, wxListMainWindow
);
3541 size_t count
= GetColumnCount();
3542 for ( size_t col
= 0; col
< count
; col
++ )
3544 self
->m_headerWidth
+= GetColumnWidth(col
);
3548 return m_headerWidth
;
3551 void wxListMainWindow::GetColumn( int col
, wxListItem
&item
) const
3553 wxListHeaderDataList::compatibility_iterator node
= m_columns
.Item( col
);
3554 wxCHECK_RET( node
, _T("invalid column index in GetColumn") );
3556 wxListHeaderData
*column
= node
->GetData();
3557 column
->GetItem( item
);
3560 int wxListMainWindow::GetColumnWidth( int col
) const
3562 wxListHeaderDataList::compatibility_iterator node
= m_columns
.Item( col
);
3563 wxCHECK_MSG( node
, 0, _T("invalid column index") );
3565 wxListHeaderData
*column
= node
->GetData();
3566 return column
->GetWidth();
3569 // ----------------------------------------------------------------------------
3571 // ----------------------------------------------------------------------------
3573 void wxListMainWindow::SetItem( wxListItem
&item
)
3575 long id
= item
.m_itemId
;
3576 wxCHECK_RET( id
>= 0 && (size_t)id
< GetItemCount(),
3577 _T("invalid item index in SetItem") );
3581 wxListLineData
*line
= GetLine((size_t)id
);
3582 line
->SetItem( item
.m_col
, item
);
3584 // Set item state if user wants
3585 if ( item
.m_mask
& wxLIST_MASK_STATE
)
3586 SetItemState( item
.m_itemId
, item
.m_state
, item
.m_state
);
3590 // update the Max Width Cache if needed
3591 int width
= GetItemWidthWithImage(&item
);
3593 if (width
> m_aColWidths
.Item(item
.m_col
)->nMaxWidth
)
3594 m_aColWidths
.Item(item
.m_col
)->nMaxWidth
= width
;
3598 // update the item on screen
3600 GetItemRect(id
, rectItem
);
3601 RefreshRect(rectItem
);
3604 void wxListMainWindow::SetItemStateAll(long state
, long stateMask
)
3609 // first deal with selection
3610 if ( stateMask
& wxLIST_STATE_SELECTED
)
3612 // set/clear select state
3615 // optimized version for virtual listctrl.
3616 m_selStore
.SelectRange(0, GetItemCount() - 1, state
== wxLIST_STATE_SELECTED
);
3619 else if ( state
& wxLIST_STATE_SELECTED
)
3621 const long count
= GetItemCount();
3622 for( long i
= 0; i
< count
; i
++ )
3624 SetItemState( i
, wxLIST_STATE_SELECTED
, wxLIST_STATE_SELECTED
);
3630 // clear for non virtual (somewhat optimized by using GetNextItem())
3632 while ( (i
= GetNextItem(i
, wxLIST_NEXT_ALL
, wxLIST_STATE_SELECTED
)) != -1 )
3634 SetItemState( i
, 0, wxLIST_STATE_SELECTED
);
3639 if ( HasCurrent() && (state
== 0) && (stateMask
& wxLIST_STATE_FOCUSED
) )
3641 // unfocus all: only one item can be focussed, so clearing focus for
3642 // all items is simply clearing focus of the focussed item.
3643 SetItemState(m_current
, state
, stateMask
);
3645 //(setting focus to all items makes no sense, so it is not handled here.)
3648 void wxListMainWindow::SetItemState( long litem
, long state
, long stateMask
)
3652 SetItemStateAll(state
, stateMask
);
3656 wxCHECK_RET( litem
>= 0 && (size_t)litem
< GetItemCount(),
3657 _T("invalid list ctrl item index in SetItem") );
3659 size_t oldCurrent
= m_current
;
3660 size_t item
= (size_t)litem
; // safe because of the check above
3662 // do we need to change the focus?
3663 if ( stateMask
& wxLIST_STATE_FOCUSED
)
3665 if ( state
& wxLIST_STATE_FOCUSED
)
3667 // don't do anything if this item is already focused
3668 if ( item
!= m_current
)
3670 ChangeCurrent(item
);
3672 if ( oldCurrent
!= (size_t)-1 )
3674 if ( IsSingleSel() )
3676 HighlightLine(oldCurrent
, false);
3679 RefreshLine(oldCurrent
);
3682 RefreshLine( m_current
);
3687 // don't do anything if this item is not focused
3688 if ( item
== m_current
)
3692 if ( IsSingleSel() )
3694 // we must unselect the old current item as well or we
3695 // might end up with more than one selected item in a
3696 // single selection control
3697 HighlightLine(oldCurrent
, false);
3700 RefreshLine( oldCurrent
);
3705 // do we need to change the selection state?
3706 if ( stateMask
& wxLIST_STATE_SELECTED
)
3708 bool on
= (state
& wxLIST_STATE_SELECTED
) != 0;
3710 if ( IsSingleSel() )
3714 // selecting the item also makes it the focused one in the
3716 if ( m_current
!= item
)
3718 ChangeCurrent(item
);
3720 if ( oldCurrent
!= (size_t)-1 )
3722 HighlightLine( oldCurrent
, false );
3723 RefreshLine( oldCurrent
);
3729 // only the current item may be selected anyhow
3730 if ( item
!= m_current
)
3735 if ( HighlightLine(item
, on
) )
3742 int wxListMainWindow::GetItemState( long item
, long stateMask
) const
3744 wxCHECK_MSG( item
>= 0 && (size_t)item
< GetItemCount(), 0,
3745 _T("invalid list ctrl item index in GetItemState()") );
3747 int ret
= wxLIST_STATE_DONTCARE
;
3749 if ( stateMask
& wxLIST_STATE_FOCUSED
)
3751 if ( (size_t)item
== m_current
)
3752 ret
|= wxLIST_STATE_FOCUSED
;
3755 if ( stateMask
& wxLIST_STATE_SELECTED
)
3757 if ( IsHighlighted(item
) )
3758 ret
|= wxLIST_STATE_SELECTED
;
3764 void wxListMainWindow::GetItem( wxListItem
&item
) const
3766 wxCHECK_RET( item
.m_itemId
>= 0 && (size_t)item
.m_itemId
< GetItemCount(),
3767 _T("invalid item index in GetItem") );
3769 wxListLineData
*line
= GetLine((size_t)item
.m_itemId
);
3770 line
->GetItem( item
.m_col
, item
);
3772 // Get item state if user wants it
3773 if ( item
.m_mask
& wxLIST_MASK_STATE
)
3774 item
.m_state
= GetItemState( item
.m_itemId
, wxLIST_STATE_SELECTED
|
3775 wxLIST_STATE_FOCUSED
);
3778 // ----------------------------------------------------------------------------
3780 // ----------------------------------------------------------------------------
3782 size_t wxListMainWindow::GetItemCount() const
3784 return IsVirtual() ? m_countVirt
: m_lines
.GetCount();
3787 void wxListMainWindow::SetItemCount(long count
)
3789 m_selStore
.SetItemCount(count
);
3790 m_countVirt
= count
;
3792 ResetVisibleLinesRange();
3794 // scrollbars must be reset
3798 int wxListMainWindow::GetSelectedItemCount() const
3800 // deal with the quick case first
3801 if ( IsSingleSel() )
3802 return HasCurrent() ? IsHighlighted(m_current
) : false;
3804 // virtual controls remmebers all its selections itself
3806 return m_selStore
.GetSelectedCount();
3808 // TODO: we probably should maintain the number of items selected even for
3809 // non virtual controls as enumerating all lines is really slow...
3810 size_t countSel
= 0;
3811 size_t count
= GetItemCount();
3812 for ( size_t line
= 0; line
< count
; line
++ )
3814 if ( GetLine(line
)->IsHighlighted() )
3821 // ----------------------------------------------------------------------------
3822 // item position/size
3823 // ----------------------------------------------------------------------------
3825 wxRect
wxListMainWindow::GetViewRect() const
3827 wxASSERT_MSG( !HasFlag(wxLC_REPORT
| wxLC_LIST
),
3828 _T("wxListCtrl::GetViewRect() only works in icon mode") );
3830 // we need to find the longest/tallest label
3831 wxCoord xMax
= 0, yMax
= 0;
3832 const int count
= GetItemCount();
3835 for ( int i
= 0; i
< count
; i
++ )
3840 wxCoord x
= r
.GetRight(),
3850 // some fudge needed to make it look prettier
3851 xMax
+= 2 * EXTRA_BORDER_X
;
3852 yMax
+= 2 * EXTRA_BORDER_Y
;
3854 // account for the scrollbars if necessary
3855 const wxSize sizeAll
= GetClientSize();
3856 if ( xMax
> sizeAll
.x
)
3857 yMax
+= wxSystemSettings::GetMetric(wxSYS_HSCROLL_Y
);
3858 if ( yMax
> sizeAll
.y
)
3859 xMax
+= wxSystemSettings::GetMetric(wxSYS_VSCROLL_X
);
3861 return wxRect(0, 0, xMax
, yMax
);
3864 void wxListMainWindow::GetItemRect( long index
, wxRect
&rect
) const
3866 wxCHECK_RET( index
>= 0 && (size_t)index
< GetItemCount(),
3867 _T("invalid index in GetItemRect") );
3869 // ensure that we're laid out, otherwise we could return nonsense
3872 wxConstCast(this, wxListMainWindow
)->
3873 RecalculatePositions(true /* no refresh */);
3876 rect
= GetLineRect((size_t)index
);
3878 CalcScrolledPosition(rect
.x
, rect
.y
, &rect
.x
, &rect
.y
);
3881 bool wxListMainWindow::GetItemPosition(long item
, wxPoint
& pos
) const
3884 GetItemRect(item
, rect
);
3892 // ----------------------------------------------------------------------------
3893 // geometry calculation
3894 // ----------------------------------------------------------------------------
3896 void wxListMainWindow::RecalculatePositions(bool noRefresh
)
3898 wxClientDC
dc( this );
3899 dc
.SetFont( GetFont() );
3901 const size_t count
= GetItemCount();
3904 if ( HasFlag(wxLC_ICON
) )
3905 iconSpacing
= m_normal_spacing
;
3906 else if ( HasFlag(wxLC_SMALL_ICON
) )
3907 iconSpacing
= m_small_spacing
;
3911 // Note that we do not call GetClientSize() here but
3912 // GetSize() and subtract the border size for sunken
3913 // borders manually. This is technically incorrect,
3914 // but we need to know the client area's size WITHOUT
3915 // scrollbars here. Since we don't know if there are
3916 // any scrollbars, we use GetSize() instead. Another
3917 // solution would be to call SetScrollbars() here to
3918 // remove the scrollbars and call GetClientSize() then,
3919 // but this might result in flicker and - worse - will
3920 // reset the scrollbars to 0 which is not good at all
3921 // if you resize a dialog/window, but don't want to
3922 // reset the window scrolling. RR.
3923 // Furthermore, we actually do NOT subtract the border
3924 // width as 2 pixels is just the extra space which we
3925 // need around the actual content in the window. Other-
3926 // wise the text would e.g. touch the upper border. RR.
3929 GetSize( &clientWidth
, &clientHeight
);
3931 const int lineHeight
= GetLineHeight();
3933 if ( InReportView() )
3935 // all lines have the same height and we scroll one line per step
3936 int entireHeight
= count
* lineHeight
+ LINE_SPACING
;
3938 m_linesPerPage
= clientHeight
/ lineHeight
;
3940 ResetVisibleLinesRange();
3942 SetScrollbars( SCROLL_UNIT_X
, lineHeight
,
3943 GetHeaderWidth() / SCROLL_UNIT_X
,
3944 (entireHeight
+ lineHeight
- 1) / lineHeight
,
3945 GetScrollPos(wxHORIZONTAL
),
3946 GetScrollPos(wxVERTICAL
),
3951 // we have 3 different layout strategies: either layout all items
3952 // horizontally/vertically (wxLC_ALIGN_XXX styles explicitly given) or
3953 // to arrange them in top to bottom, left to right (don't ask me why
3954 // not the other way round...) order
3955 if ( HasFlag(wxLC_ALIGN_LEFT
| wxLC_ALIGN_TOP
) )
3957 int x
= EXTRA_BORDER_X
;
3958 int y
= EXTRA_BORDER_Y
;
3960 wxCoord widthMax
= 0;
3963 for ( i
= 0; i
< count
; i
++ )
3965 wxListLineData
*line
= GetLine(i
);
3966 line
->CalculateSize( &dc
, iconSpacing
);
3967 line
->SetPosition( x
, y
, iconSpacing
);
3969 wxSize sizeLine
= GetLineSize(i
);
3971 if ( HasFlag(wxLC_ALIGN_TOP
) )
3973 if ( sizeLine
.x
> widthMax
)
3974 widthMax
= sizeLine
.x
;
3978 else // wxLC_ALIGN_LEFT
3980 x
+= sizeLine
.x
+ MARGIN_BETWEEN_ROWS
;
3984 if ( HasFlag(wxLC_ALIGN_TOP
) )
3986 // traverse the items again and tweak their sizes so that they are
3987 // all the same in a row
3988 for ( i
= 0; i
< count
; i
++ )
3990 wxListLineData
*line
= GetLine(i
);
3991 line
->m_gi
->ExtendWidth(widthMax
);
3999 (x
+ SCROLL_UNIT_X
) / SCROLL_UNIT_X
,
4000 (y
+ lineHeight
) / lineHeight
,
4001 GetScrollPos( wxHORIZONTAL
),
4002 GetScrollPos( wxVERTICAL
),
4006 else // "flowed" arrangement, the most complicated case
4008 // at first we try without any scrollbars, if the items don't fit into
4009 // the window, we recalculate after subtracting the space taken by the
4012 int entireWidth
= 0;
4014 for (int tries
= 0; tries
< 2; tries
++)
4016 entireWidth
= 2 * EXTRA_BORDER_X
;
4020 // Now we have decided that the items do not fit into the
4021 // client area, so we need a scrollbar
4022 entireWidth
+= SCROLL_UNIT_X
;
4025 int x
= EXTRA_BORDER_X
;
4026 int y
= EXTRA_BORDER_Y
;
4027 int maxWidthInThisRow
= 0;
4030 int currentlyVisibleLines
= 0;
4032 for (size_t i
= 0; i
< count
; i
++)
4034 currentlyVisibleLines
++;
4035 wxListLineData
*line
= GetLine( i
);
4036 line
->CalculateSize( &dc
, iconSpacing
);
4037 line
->SetPosition( x
, y
, iconSpacing
);
4039 wxSize sizeLine
= GetLineSize( i
);
4041 if ( maxWidthInThisRow
< sizeLine
.x
)
4042 maxWidthInThisRow
= sizeLine
.x
;
4045 if (currentlyVisibleLines
> m_linesPerPage
)
4046 m_linesPerPage
= currentlyVisibleLines
;
4048 if ( y
+ sizeLine
.y
>= clientHeight
)
4050 currentlyVisibleLines
= 0;
4052 maxWidthInThisRow
+= MARGIN_BETWEEN_ROWS
;
4053 x
+= maxWidthInThisRow
;
4054 entireWidth
+= maxWidthInThisRow
;
4055 maxWidthInThisRow
= 0;
4058 // We have reached the last item.
4059 if ( i
== count
- 1 )
4060 entireWidth
+= maxWidthInThisRow
;
4062 if ( (tries
== 0) &&
4063 (entireWidth
+ SCROLL_UNIT_X
> clientWidth
) )
4065 clientHeight
-= wxSystemSettings::
4066 GetMetric(wxSYS_HSCROLL_Y
);
4071 if ( i
== count
- 1 )
4072 tries
= 1; // Everything fits, no second try required.
4080 (entireWidth
+ SCROLL_UNIT_X
) / SCROLL_UNIT_X
,
4082 GetScrollPos( wxHORIZONTAL
),
4091 // FIXME: why should we call it from here?
4098 void wxListMainWindow::RefreshAll()
4103 wxListHeaderWindow
*headerWin
= GetListCtrl()->m_headerWin
;
4104 if ( headerWin
&& headerWin
->m_dirty
)
4106 headerWin
->m_dirty
= false;
4107 headerWin
->Refresh();
4111 void wxListMainWindow::UpdateCurrent()
4113 if ( !HasCurrent() && !IsEmpty() )
4117 long wxListMainWindow::GetNextItem( long item
,
4118 int WXUNUSED(geometry
),
4122 max
= GetItemCount();
4123 wxCHECK_MSG( (ret
== -1) || (ret
< max
), -1,
4124 _T("invalid listctrl index in GetNextItem()") );
4126 // notice that we start with the next item (or the first one if item == -1)
4127 // and this is intentional to allow writing a simple loop to iterate over
4128 // all selected items
4131 // this is not an error because the index was OK initially,
4132 // just no such item
4139 size_t count
= GetItemCount();
4140 for ( size_t line
= (size_t)ret
; line
< count
; line
++ )
4142 if ( (state
& wxLIST_STATE_FOCUSED
) && (line
== m_current
) )
4145 if ( (state
& wxLIST_STATE_SELECTED
) && IsHighlighted(line
) )
4152 // ----------------------------------------------------------------------------
4154 // ----------------------------------------------------------------------------
4156 void wxListMainWindow::DeleteItem( long lindex
)
4158 size_t count
= GetItemCount();
4160 wxCHECK_RET( (lindex
>= 0) && ((size_t)lindex
< count
),
4161 _T("invalid item index in DeleteItem") );
4163 size_t index
= (size_t)lindex
;
4165 // we don't need to adjust the index for the previous items
4166 if ( HasCurrent() && m_current
>= index
)
4168 // if the current item is being deleted, we want the next one to
4169 // become selected - unless there is no next one - so don't adjust
4170 // m_current in this case
4171 if ( m_current
!= index
|| m_current
== count
- 1 )
4175 if ( InReportView() )
4177 // mark the Column Max Width cache as dirty if the items in the line
4178 // we're deleting contain the Max Column Width
4179 wxListLineData
* const line
= GetLine(index
);
4180 wxListItemDataList::compatibility_iterator n
;
4181 wxListItemData
*itemData
;
4185 for (size_t i
= 0; i
< m_columns
.GetCount(); i
++)
4187 n
= line
->m_items
.Item( i
);
4188 itemData
= n
->GetData();
4189 itemData
->GetItem(item
);
4191 itemWidth
= GetItemWidthWithImage(&item
);
4193 if (itemWidth
>= m_aColWidths
.Item(i
)->nMaxWidth
)
4194 m_aColWidths
.Item(i
)->bNeedsUpdate
= true;
4197 ResetVisibleLinesRange();
4203 m_selStore
.OnItemDelete(index
);
4207 m_lines
.RemoveAt( index
);
4210 // we need to refresh the (vert) scrollbar as the number of items changed
4213 SendNotify( index
, wxEVT_COMMAND_LIST_DELETE_ITEM
);
4215 RefreshAfter(index
);
4218 void wxListMainWindow::DeleteColumn( int col
)
4220 wxListHeaderDataList::compatibility_iterator node
= m_columns
.Item( col
);
4222 wxCHECK_RET( node
, wxT("invalid column index in DeleteColumn()") );
4225 delete node
->GetData();
4226 m_columns
.Erase( node
);
4230 // update all the items
4231 for ( size_t i
= 0; i
< m_lines
.GetCount(); i
++ )
4233 wxListLineData
* const line
= GetLine(i
);
4234 wxListItemDataList::compatibility_iterator n
= line
->m_items
.Item( col
);
4235 delete n
->GetData();
4236 line
->m_items
.Erase(n
);
4240 if ( InReportView() ) // we only cache max widths when in Report View
4242 delete m_aColWidths
.Item(col
);
4243 m_aColWidths
.RemoveAt(col
);
4246 // invalidate it as it has to be recalculated
4250 void wxListMainWindow::DoDeleteAllItems()
4253 // nothing to do - in particular, don't send the event
4258 // to make the deletion of all items faster, we don't send the
4259 // notifications for each item deletion in this case but only one event
4260 // for all of them: this is compatible with wxMSW and documented in
4261 // DeleteAllItems() description
4263 wxListEvent
event( wxEVT_COMMAND_LIST_DELETE_ALL_ITEMS
, GetParent()->GetId() );
4264 event
.SetEventObject( GetParent() );
4265 GetParent()->GetEventHandler()->ProcessEvent( event
);
4273 if ( InReportView() )
4275 ResetVisibleLinesRange();
4276 for (size_t i
= 0; i
< m_aColWidths
.GetCount(); i
++)
4278 m_aColWidths
.Item(i
)->bNeedsUpdate
= true;
4285 void wxListMainWindow::DeleteAllItems()
4289 RecalculatePositions();
4292 void wxListMainWindow::DeleteEverything()
4294 WX_CLEAR_LIST(wxListHeaderDataList
, m_columns
);
4295 WX_CLEAR_ARRAY(m_aColWidths
);
4300 // ----------------------------------------------------------------------------
4301 // scanning for an item
4302 // ----------------------------------------------------------------------------
4304 void wxListMainWindow::EnsureVisible( long index
)
4306 wxCHECK_RET( index
>= 0 && (size_t)index
< GetItemCount(),
4307 _T("invalid index in EnsureVisible") );
4309 // We have to call this here because the label in question might just have
4310 // been added and its position is not known yet
4312 RecalculatePositions(true /* no refresh */);
4314 MoveToItem((size_t)index
);
4317 long wxListMainWindow::FindItem(long start
, const wxString
& str
, bool WXUNUSED(partial
) )
4324 size_t count
= GetItemCount();
4325 for ( size_t i
= (size_t)pos
; i
< count
; i
++ )
4327 wxListLineData
*line
= GetLine(i
);
4328 if ( line
->GetText(0) == tmp
)
4335 long wxListMainWindow::FindItem(long start
, wxUIntPtr data
)
4341 size_t count
= GetItemCount();
4342 for (size_t i
= (size_t)pos
; i
< count
; i
++)
4344 wxListLineData
*line
= GetLine(i
);
4346 line
->GetItem( 0, item
);
4347 if (item
.m_data
== data
)
4354 long wxListMainWindow::FindItem( const wxPoint
& pt
)
4357 GetVisibleLinesRange( &topItem
, NULL
);
4360 GetItemPosition( GetItemCount() - 1, p
);
4364 long id
= (long)floor( pt
.y
* double(GetItemCount() - topItem
- 1) / p
.y
+ topItem
);
4365 if ( id
>= 0 && id
< (long)GetItemCount() )
4371 long wxListMainWindow::HitTest( int x
, int y
, int &flags
)
4373 CalcUnscrolledPosition( x
, y
, &x
, &y
);
4375 size_t count
= GetItemCount();
4377 if ( InReportView() )
4379 size_t current
= y
/ GetLineHeight();
4380 if ( current
< count
)
4382 flags
= HitTestLine(current
, x
, y
);
4389 // TODO: optimize it too! this is less simple than for report view but
4390 // enumerating all items is still not a way to do it!!
4391 for ( size_t current
= 0; current
< count
; current
++ )
4393 flags
= HitTestLine(current
, x
, y
);
4402 // ----------------------------------------------------------------------------
4404 // ----------------------------------------------------------------------------
4406 void wxListMainWindow::InsertItem( wxListItem
&item
)
4408 wxASSERT_MSG( !IsVirtual(), _T("can't be used with virtual control") );
4410 int count
= GetItemCount();
4411 wxCHECK_RET( item
.m_itemId
>= 0, _T("invalid item index") );
4413 if (item
.m_itemId
> count
)
4414 item
.m_itemId
= count
;
4416 size_t id
= item
.m_itemId
;
4420 if ( InReportView() )
4422 ResetVisibleLinesRange();
4424 // calculate the width of the item and adjust the max column width
4425 wxColWidthInfo
*pWidthInfo
= m_aColWidths
.Item(item
.GetColumn());
4426 int width
= GetItemWidthWithImage(&item
);
4427 item
.SetWidth(width
);
4428 if (width
> pWidthInfo
->nMaxWidth
)
4429 pWidthInfo
->nMaxWidth
= width
;
4432 wxListLineData
*line
= new wxListLineData(this);
4434 line
->SetItem( item
.m_col
, item
);
4436 m_lines
.Insert( line
, id
);
4440 // If an item is selected at or below the point of insertion, we need to
4441 // increment the member variables because the current row's index has gone
4443 if ( HasCurrent() && m_current
>= id
)
4446 SendNotify(id
, wxEVT_COMMAND_LIST_INSERT_ITEM
);
4448 RefreshLines(id
, GetItemCount() - 1);
4451 void wxListMainWindow::InsertColumn( long col
, wxListItem
&item
)
4454 if ( InReportView() )
4456 if (item
.m_width
== wxLIST_AUTOSIZE_USEHEADER
)
4457 item
.m_width
= GetTextLength( item
.m_text
);
4459 wxListHeaderData
*column
= new wxListHeaderData( item
);
4460 wxColWidthInfo
*colWidthInfo
= new wxColWidthInfo();
4462 bool insert
= (col
>= 0) && ((size_t)col
< m_columns
.GetCount());
4465 wxListHeaderDataList::compatibility_iterator
4466 node
= m_columns
.Item( col
);
4467 m_columns
.Insert( node
, column
);
4468 m_aColWidths
.Insert( colWidthInfo
, col
);
4472 m_columns
.Append( column
);
4473 m_aColWidths
.Add( colWidthInfo
);
4478 // update all the items
4479 for ( size_t i
= 0; i
< m_lines
.GetCount(); i
++ )
4481 wxListLineData
* const line
= GetLine(i
);
4482 wxListItemData
* const data
= new wxListItemData(this);
4484 line
->m_items
.Insert(col
, data
);
4486 line
->m_items
.Append(data
);
4490 // invalidate it as it has to be recalculated
4495 int wxListMainWindow::GetItemWidthWithImage(wxListItem
* item
)
4498 wxClientDC
dc(this);
4500 dc
.SetFont( GetFont() );
4502 if (item
->GetImage() != -1)
4505 GetImageSize( item
->GetImage(), ix
, iy
);
4509 if (!item
->GetText().empty())
4512 dc
.GetTextExtent( item
->GetText(), &w
, NULL
);
4519 // ----------------------------------------------------------------------------
4521 // ----------------------------------------------------------------------------
4523 wxListCtrlCompare list_ctrl_compare_func_2
;
4524 long list_ctrl_compare_data
;
4526 int LINKAGEMODE
list_ctrl_compare_func_1( wxListLineData
**arg1
, wxListLineData
**arg2
)
4528 wxListLineData
*line1
= *arg1
;
4529 wxListLineData
*line2
= *arg2
;
4531 line1
->GetItem( 0, item
);
4532 wxUIntPtr data1
= item
.m_data
;
4533 line2
->GetItem( 0, item
);
4534 wxUIntPtr data2
= item
.m_data
;
4535 return list_ctrl_compare_func_2( data1
, data2
, list_ctrl_compare_data
);
4538 void wxListMainWindow::SortItems( wxListCtrlCompare fn
, long data
)
4540 list_ctrl_compare_func_2
= fn
;
4541 list_ctrl_compare_data
= data
;
4542 m_lines
.Sort( list_ctrl_compare_func_1
);
4546 // ----------------------------------------------------------------------------
4548 // ----------------------------------------------------------------------------
4550 void wxListMainWindow::OnScroll(wxScrollWinEvent
& event
)
4552 // update our idea of which lines are shown when we redraw the window the
4554 ResetVisibleLinesRange();
4557 #if ( defined(__WXGTK__) || defined(__WXMAC__) ) && !defined(__WXUNIVERSAL__)
4558 wxScrolledWindow::OnScroll(event
);
4560 HandleOnScroll( event
);
4563 if ( event
.GetOrientation() == wxHORIZONTAL
&& HasHeader() )
4565 wxGenericListCtrl
* lc
= GetListCtrl();
4566 wxCHECK_RET( lc
, _T("no listctrl window?") );
4568 lc
->m_headerWin
->Refresh();
4569 lc
->m_headerWin
->Update();
4573 int wxListMainWindow::GetCountPerPage() const
4575 if ( !m_linesPerPage
)
4577 wxConstCast(this, wxListMainWindow
)->
4578 m_linesPerPage
= GetClientSize().y
/ GetLineHeight();
4581 return m_linesPerPage
;
4584 void wxListMainWindow::GetVisibleLinesRange(size_t *from
, size_t *to
)
4586 wxASSERT_MSG( InReportView(), _T("this is for report mode only") );
4588 if ( m_lineFrom
== (size_t)-1 )
4590 size_t count
= GetItemCount();
4593 m_lineFrom
= GetScrollPos(wxVERTICAL
);
4595 // this may happen if SetScrollbars() hadn't been called yet
4596 if ( m_lineFrom
>= count
)
4597 m_lineFrom
= count
- 1;
4599 // we redraw one extra line but this is needed to make the redrawing
4600 // logic work when there is a fractional number of lines on screen
4601 m_lineTo
= m_lineFrom
+ m_linesPerPage
;
4602 if ( m_lineTo
>= count
)
4603 m_lineTo
= count
- 1;
4605 else // empty control
4608 m_lineTo
= (size_t)-1;
4612 wxASSERT_MSG( IsEmpty() ||
4613 (m_lineFrom
<= m_lineTo
&& m_lineTo
< GetItemCount()),
4614 _T("GetVisibleLinesRange() returns incorrect result") );
4622 // -------------------------------------------------------------------------------------
4623 // wxGenericListCtrl
4624 // -------------------------------------------------------------------------------------
4626 IMPLEMENT_DYNAMIC_CLASS(wxGenericListCtrl
, wxControl
)
4628 BEGIN_EVENT_TABLE(wxGenericListCtrl
,wxControl
)
4629 EVT_SIZE(wxGenericListCtrl::OnSize
)
4632 wxGenericListCtrl::wxGenericListCtrl()
4634 m_imageListNormal
= (wxImageListType
*) NULL
;
4635 m_imageListSmall
= (wxImageListType
*) NULL
;
4636 m_imageListState
= (wxImageListType
*) NULL
;
4638 m_ownsImageListNormal
=
4639 m_ownsImageListSmall
=
4640 m_ownsImageListState
= false;
4642 m_mainWin
= (wxListMainWindow
*) NULL
;
4643 m_headerWin
= (wxListHeaderWindow
*) NULL
;
4647 wxGenericListCtrl::~wxGenericListCtrl()
4649 if (m_ownsImageListNormal
)
4650 delete m_imageListNormal
;
4651 if (m_ownsImageListSmall
)
4652 delete m_imageListSmall
;
4653 if (m_ownsImageListState
)
4654 delete m_imageListState
;
4657 void wxGenericListCtrl::CalculateAndSetHeaderHeight()
4663 GetThemeMetric( kThemeMetricListHeaderHeight
, &h
);
4665 // we use 'g' to get the descent, too
4667 m_headerWin
->GetTextExtent(wxT("Hg"), &w
, &h
, &d
);
4668 h
+= d
+ 2 * HEADER_OFFSET_Y
+ EXTRA_HEIGHT
;
4671 // only update if changed
4672 if ( h
!= m_headerHeight
)
4677 ResizeReportView(true);
4678 else //why is this needed if it doesn't have a header?
4679 m_headerWin
->SetSize(m_headerWin
->GetSize().x
, m_headerHeight
);
4684 void wxGenericListCtrl::CreateHeaderWindow()
4686 m_headerWin
= new wxListHeaderWindow
4688 this, wxID_ANY
, m_mainWin
,
4690 wxSize(GetClientSize().x
, m_headerHeight
),
4693 CalculateAndSetHeaderHeight();
4696 bool wxGenericListCtrl::Create(wxWindow
*parent
,
4701 const wxValidator
&validator
,
4702 const wxString
&name
)
4706 m_imageListState
= (wxImageListType
*) NULL
;
4707 m_ownsImageListNormal
=
4708 m_ownsImageListSmall
=
4709 m_ownsImageListState
= false;
4711 m_mainWin
= (wxListMainWindow
*) NULL
;
4712 m_headerWin
= (wxListHeaderWindow
*) NULL
;
4716 if ( !(style
& wxLC_MASK_TYPE
) )
4718 style
= style
| wxLC_LIST
;
4721 if ( !wxControl::Create( parent
, id
, pos
, size
, style
, validator
, name
) )
4724 // don't create the inner window with the border
4725 style
&= ~wxBORDER_MASK
;
4727 m_mainWin
= new wxListMainWindow( this, wxID_ANY
, wxPoint(0, 0), size
, style
);
4729 #ifdef __WXMAC_CARBON__
4730 // Human Interface Guidelines ask us for a special font in this case
4731 if ( GetWindowVariant() == wxWINDOW_VARIANT_NORMAL
)
4734 font
.MacCreateThemeFont( kThemeViewsFont
);
4739 if ( InReportView() )
4741 CreateHeaderWindow();
4743 #ifdef __WXMAC_CARBON__
4747 font
.MacCreateThemeFont( kThemeSmallSystemFont
);
4748 m_headerWin
->SetFont( font
);
4749 CalculateAndSetHeaderHeight();
4753 if ( HasFlag(wxLC_NO_HEADER
) )
4754 // VZ: why do we create it at all then?
4755 m_headerWin
->Show( false );
4763 void wxGenericListCtrl::SetSingleStyle( long style
, bool add
)
4765 wxASSERT_MSG( !(style
& wxLC_VIRTUAL
),
4766 _T("wxLC_VIRTUAL can't be [un]set") );
4768 long flag
= GetWindowStyle();
4772 if (style
& wxLC_MASK_TYPE
)
4773 flag
&= ~(wxLC_MASK_TYPE
| wxLC_VIRTUAL
);
4774 if (style
& wxLC_MASK_ALIGN
)
4775 flag
&= ~wxLC_MASK_ALIGN
;
4776 if (style
& wxLC_MASK_SORT
)
4777 flag
&= ~wxLC_MASK_SORT
;
4785 SetWindowStyleFlag( flag
);
4788 void wxGenericListCtrl::SetWindowStyleFlag( long flag
)
4792 m_mainWin
->DeleteEverything();
4794 // has the header visibility changed?
4795 bool hasHeader
= HasHeader();
4796 bool willHaveHeader
= (flag
& wxLC_REPORT
) && !(flag
& wxLC_NO_HEADER
);
4798 if ( hasHeader
!= willHaveHeader
)
4805 // don't delete, just hide, as we can reuse it later
4806 m_headerWin
->Show(false);
4808 //else: nothing to do
4810 else // must show header
4814 CreateHeaderWindow();
4816 else // already have it, just show
4818 m_headerWin
->Show( true );
4822 ResizeReportView(willHaveHeader
);
4826 wxWindow::SetWindowStyleFlag( flag
);
4829 bool wxGenericListCtrl::GetColumn(int col
, wxListItem
&item
) const
4831 m_mainWin
->GetColumn( col
, item
);
4835 bool wxGenericListCtrl::SetColumn( int col
, wxListItem
& item
)
4837 m_mainWin
->SetColumn( col
, item
);
4841 int wxGenericListCtrl::GetColumnWidth( int col
) const
4843 return m_mainWin
->GetColumnWidth( col
);
4846 bool wxGenericListCtrl::SetColumnWidth( int col
, int width
)
4848 m_mainWin
->SetColumnWidth( col
, width
);
4852 int wxGenericListCtrl::GetCountPerPage() const
4854 return m_mainWin
->GetCountPerPage(); // different from Windows ?
4857 bool wxGenericListCtrl::GetItem( wxListItem
&info
) const
4859 m_mainWin
->GetItem( info
);
4863 bool wxGenericListCtrl::SetItem( wxListItem
&info
)
4865 m_mainWin
->SetItem( info
);
4869 long wxGenericListCtrl::SetItem( long index
, int col
, const wxString
& label
, int imageId
)
4872 info
.m_text
= label
;
4873 info
.m_mask
= wxLIST_MASK_TEXT
;
4874 info
.m_itemId
= index
;
4878 info
.m_image
= imageId
;
4879 info
.m_mask
|= wxLIST_MASK_IMAGE
;
4882 m_mainWin
->SetItem(info
);
4886 int wxGenericListCtrl::GetItemState( long item
, long stateMask
) const
4888 return m_mainWin
->GetItemState( item
, stateMask
);
4891 bool wxGenericListCtrl::SetItemState( long item
, long state
, long stateMask
)
4893 m_mainWin
->SetItemState( item
, state
, stateMask
);
4898 wxGenericListCtrl::SetItemImage( long item
, int image
, int WXUNUSED(selImage
) )
4901 info
.m_image
= image
;
4902 info
.m_mask
= wxLIST_MASK_IMAGE
;
4903 info
.m_itemId
= item
;
4904 m_mainWin
->SetItem( info
);
4908 wxString
wxGenericListCtrl::GetItemText( long item
) const
4910 return m_mainWin
->GetItemText(item
);
4913 void wxGenericListCtrl::SetItemText( long item
, const wxString
& str
)
4915 m_mainWin
->SetItemText(item
, str
);
4918 wxUIntPtr
wxGenericListCtrl::GetItemData( long item
) const
4921 info
.m_mask
= wxLIST_MASK_DATA
;
4922 info
.m_itemId
= item
;
4923 m_mainWin
->GetItem( info
);
4927 bool wxGenericListCtrl::SetItemData( long item
, long data
)
4930 info
.m_mask
= wxLIST_MASK_DATA
;
4931 info
.m_itemId
= item
;
4933 m_mainWin
->SetItem( info
);
4937 wxRect
wxGenericListCtrl::GetViewRect() const
4939 return m_mainWin
->GetViewRect();
4942 bool wxGenericListCtrl::GetItemRect( long item
, wxRect
&rect
, int WXUNUSED(code
) ) const
4944 m_mainWin
->GetItemRect( item
, rect
);
4945 if ( m_mainWin
->HasHeader() )
4946 rect
.y
+= m_headerHeight
+ 1;
4950 bool wxGenericListCtrl::GetItemPosition( long item
, wxPoint
& pos
) const
4952 m_mainWin
->GetItemPosition( item
, pos
);
4956 bool wxGenericListCtrl::SetItemPosition( long WXUNUSED(item
), const wxPoint
& WXUNUSED(pos
) )
4961 int wxGenericListCtrl::GetItemCount() const
4963 return m_mainWin
->GetItemCount();
4966 int wxGenericListCtrl::GetColumnCount() const
4968 return m_mainWin
->GetColumnCount();
4971 void wxGenericListCtrl::SetItemSpacing( int spacing
, bool isSmall
)
4973 m_mainWin
->SetItemSpacing( spacing
, isSmall
);
4976 wxSize
wxGenericListCtrl::GetItemSpacing() const
4978 const int spacing
= m_mainWin
->GetItemSpacing(HasFlag(wxLC_SMALL_ICON
));
4980 return wxSize(spacing
, spacing
);
4983 int wxGenericListCtrl::GetItemSpacing( bool isSmall
) const
4985 return m_mainWin
->GetItemSpacing( isSmall
);
4988 void wxGenericListCtrl::SetItemTextColour( long item
, const wxColour
&col
)
4991 info
.m_itemId
= item
;
4992 info
.SetTextColour( col
);
4993 m_mainWin
->SetItem( info
);
4996 wxColour
wxGenericListCtrl::GetItemTextColour( long item
) const
4999 info
.m_itemId
= item
;
5000 m_mainWin
->GetItem( info
);
5001 return info
.GetTextColour();
5004 void wxGenericListCtrl::SetItemBackgroundColour( long item
, const wxColour
&col
)
5007 info
.m_itemId
= item
;
5008 info
.SetBackgroundColour( col
);
5009 m_mainWin
->SetItem( info
);
5012 wxColour
wxGenericListCtrl::GetItemBackgroundColour( long item
) const
5015 info
.m_itemId
= item
;
5016 m_mainWin
->GetItem( info
);
5017 return info
.GetBackgroundColour();
5020 void wxGenericListCtrl::SetItemFont( long item
, const wxFont
&f
)
5023 info
.m_itemId
= item
;
5025 m_mainWin
->SetItem( info
);
5028 wxFont
wxGenericListCtrl::GetItemFont( long item
) const
5031 info
.m_itemId
= item
;
5032 m_mainWin
->GetItem( info
);
5033 return info
.GetFont();
5036 int wxGenericListCtrl::GetSelectedItemCount() const
5038 return m_mainWin
->GetSelectedItemCount();
5041 wxColour
wxGenericListCtrl::GetTextColour() const
5043 return GetForegroundColour();
5046 void wxGenericListCtrl::SetTextColour(const wxColour
& col
)
5048 SetForegroundColour(col
);
5051 long wxGenericListCtrl::GetTopItem() const
5054 m_mainWin
->GetVisibleLinesRange(&top
, NULL
);
5058 long wxGenericListCtrl::GetNextItem( long item
, int geom
, int state
) const
5060 return m_mainWin
->GetNextItem( item
, geom
, state
);
5063 wxImageListType
*wxGenericListCtrl::GetImageList(int which
) const
5065 if (which
== wxIMAGE_LIST_NORMAL
)
5066 return m_imageListNormal
;
5067 else if (which
== wxIMAGE_LIST_SMALL
)
5068 return m_imageListSmall
;
5069 else if (which
== wxIMAGE_LIST_STATE
)
5070 return m_imageListState
;
5072 return (wxImageListType
*) NULL
;
5075 void wxGenericListCtrl::SetImageList( wxImageListType
*imageList
, int which
)
5077 if ( which
== wxIMAGE_LIST_NORMAL
)
5079 if (m_ownsImageListNormal
)
5080 delete m_imageListNormal
;
5081 m_imageListNormal
= imageList
;
5082 m_ownsImageListNormal
= false;
5084 else if ( which
== wxIMAGE_LIST_SMALL
)
5086 if (m_ownsImageListSmall
)
5087 delete m_imageListSmall
;
5088 m_imageListSmall
= imageList
;
5089 m_ownsImageListSmall
= false;
5091 else if ( which
== wxIMAGE_LIST_STATE
)
5093 if (m_ownsImageListState
)
5094 delete m_imageListState
;
5095 m_imageListState
= imageList
;
5096 m_ownsImageListState
= false;
5099 m_mainWin
->SetImageList( imageList
, which
);
5102 void wxGenericListCtrl::AssignImageList(wxImageListType
*imageList
, int which
)
5104 SetImageList(imageList
, which
);
5105 if ( which
== wxIMAGE_LIST_NORMAL
)
5106 m_ownsImageListNormal
= true;
5107 else if ( which
== wxIMAGE_LIST_SMALL
)
5108 m_ownsImageListSmall
= true;
5109 else if ( which
== wxIMAGE_LIST_STATE
)
5110 m_ownsImageListState
= true;
5113 bool wxGenericListCtrl::Arrange( int WXUNUSED(flag
) )
5118 bool wxGenericListCtrl::DeleteItem( long item
)
5120 m_mainWin
->DeleteItem( item
);
5124 bool wxGenericListCtrl::DeleteAllItems()
5126 m_mainWin
->DeleteAllItems();
5130 bool wxGenericListCtrl::DeleteAllColumns()
5132 size_t count
= m_mainWin
->m_columns
.GetCount();
5133 for ( size_t n
= 0; n
< count
; n
++ )
5138 void wxGenericListCtrl::ClearAll()
5140 m_mainWin
->DeleteEverything();
5143 bool wxGenericListCtrl::DeleteColumn( int col
)
5145 m_mainWin
->DeleteColumn( col
);
5147 // if we don't have the header any longer, we need to relayout the window
5148 if ( !GetColumnCount() )
5149 ResizeReportView(false /* no header */);
5153 void wxGenericListCtrl::Edit( long item
)
5155 m_mainWin
->EditLabel( item
);
5158 bool wxGenericListCtrl::EnsureVisible( long item
)
5160 m_mainWin
->EnsureVisible( item
);
5164 long wxGenericListCtrl::FindItem( long start
, const wxString
& str
, bool partial
)
5166 return m_mainWin
->FindItem( start
, str
, partial
);
5169 long wxGenericListCtrl::FindItem( long start
, wxUIntPtr data
)
5171 return m_mainWin
->FindItem( start
, data
);
5174 long wxGenericListCtrl::FindItem( long WXUNUSED(start
), const wxPoint
& pt
,
5175 int WXUNUSED(direction
))
5177 return m_mainWin
->FindItem( pt
);
5180 long wxGenericListCtrl::HitTest( const wxPoint
&point
, int &flags
)
5182 return m_mainWin
->HitTest( (int)point
.x
, (int)point
.y
, flags
);
5185 long wxGenericListCtrl::InsertItem( wxListItem
& info
)
5187 m_mainWin
->InsertItem( info
);
5188 return info
.m_itemId
;
5191 long wxGenericListCtrl::InsertItem( long index
, const wxString
&label
)
5194 info
.m_text
= label
;
5195 info
.m_mask
= wxLIST_MASK_TEXT
;
5196 info
.m_itemId
= index
;
5197 return InsertItem( info
);
5200 long wxGenericListCtrl::InsertItem( long index
, int imageIndex
)
5203 info
.m_mask
= wxLIST_MASK_IMAGE
;
5204 info
.m_image
= imageIndex
;
5205 info
.m_itemId
= index
;
5206 return InsertItem( info
);
5209 long wxGenericListCtrl::InsertItem( long index
, const wxString
&label
, int imageIndex
)
5212 info
.m_text
= label
;
5213 info
.m_image
= imageIndex
;
5214 info
.m_mask
= wxLIST_MASK_TEXT
| wxLIST_MASK_IMAGE
;
5215 info
.m_itemId
= index
;
5216 return InsertItem( info
);
5219 long wxGenericListCtrl::InsertColumn( long col
, wxListItem
&item
)
5221 wxCHECK_MSG( m_headerWin
, -1, _T("can't add column in non report mode") );
5223 m_mainWin
->InsertColumn( col
, item
);
5225 // if we hadn't had a header before but have one now
5226 // then we need to relayout the window
5227 if ( GetColumnCount() == 1 && m_mainWin
->HasHeader() )
5228 ResizeReportView(true /* have header */);
5230 m_headerWin
->Refresh();
5235 long wxGenericListCtrl::InsertColumn( long col
, const wxString
&heading
,
5236 int format
, int width
)
5239 item
.m_mask
= wxLIST_MASK_TEXT
| wxLIST_MASK_FORMAT
;
5240 item
.m_text
= heading
;
5243 item
.m_mask
|= wxLIST_MASK_WIDTH
;
5244 item
.m_width
= width
;
5247 item
.m_format
= format
;
5249 return InsertColumn( col
, item
);
5252 bool wxGenericListCtrl::ScrollList( int WXUNUSED(dx
), int WXUNUSED(dy
) )
5258 // fn is a function which takes 3 long arguments: item1, item2, data.
5259 // item1 is the long data associated with a first item (NOT the index).
5260 // item2 is the long data associated with a second item (NOT the index).
5261 // data is the same value as passed to SortItems.
5262 // The return value is a negative number if the first item should precede the second
5263 // item, a positive number of the second item should precede the first,
5264 // or zero if the two items are equivalent.
5265 // data is arbitrary data to be passed to the sort function.
5267 bool wxGenericListCtrl::SortItems( wxListCtrlCompare fn
, long data
)
5269 m_mainWin
->SortItems( fn
, data
);
5273 // ----------------------------------------------------------------------------
5275 // ----------------------------------------------------------------------------
5277 void wxGenericListCtrl::OnSize(wxSizeEvent
& WXUNUSED(event
))
5282 ResizeReportView(m_mainWin
->HasHeader());
5283 m_mainWin
->RecalculatePositions();
5286 void wxGenericListCtrl::ResizeReportView(bool showHeader
)
5289 GetClientSize( &cw
, &ch
);
5293 m_headerWin
->SetSize( 0, 0, cw
, m_headerHeight
);
5294 if(ch
> m_headerHeight
)
5295 m_mainWin
->SetSize( 0, m_headerHeight
+ 1,
5296 cw
, ch
- m_headerHeight
- 1 );
5298 m_mainWin
->SetSize( 0, m_headerHeight
+ 1,
5301 else // no header window
5303 m_mainWin
->SetSize( 0, 0, cw
, ch
);
5307 void wxGenericListCtrl::OnInternalIdle()
5309 wxWindow::OnInternalIdle();
5311 // do it only if needed
5312 if ( !m_mainWin
->m_dirty
)
5315 m_mainWin
->RecalculatePositions();
5318 // ----------------------------------------------------------------------------
5320 // ----------------------------------------------------------------------------
5322 bool wxGenericListCtrl::SetBackgroundColour( const wxColour
&colour
)
5326 m_mainWin
->SetBackgroundColour( colour
);
5327 m_mainWin
->m_dirty
= true;
5333 bool wxGenericListCtrl::SetForegroundColour( const wxColour
&colour
)
5335 if ( !wxWindow::SetForegroundColour( colour
) )
5340 m_mainWin
->SetForegroundColour( colour
);
5341 m_mainWin
->m_dirty
= true;
5345 m_headerWin
->SetForegroundColour( colour
);
5350 bool wxGenericListCtrl::SetFont( const wxFont
&font
)
5352 if ( !wxWindow::SetFont( font
) )
5357 m_mainWin
->SetFont( font
);
5358 m_mainWin
->m_dirty
= true;
5363 m_headerWin
->SetFont( font
);
5364 CalculateAndSetHeaderHeight();
5373 #include "wx/listbox.h"
5378 wxGenericListCtrl::GetClassDefaultAttributes(wxWindowVariant variant
)
5381 // Use the same color scheme as wxListBox
5382 return wxListBox::GetClassDefaultAttributes(variant
);
5384 wxUnusedVar(variant
);
5385 wxVisualAttributes attr
;
5386 attr
.colFg
= wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT
);
5387 attr
.colBg
= wxSystemSettings::GetColour(wxSYS_COLOUR_LISTBOX
);
5388 attr
.font
= wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT
);
5393 // ----------------------------------------------------------------------------
5394 // methods forwarded to m_mainWin
5395 // ----------------------------------------------------------------------------
5397 #if wxUSE_DRAG_AND_DROP
5399 void wxGenericListCtrl::SetDropTarget( wxDropTarget
*dropTarget
)
5401 m_mainWin
->SetDropTarget( dropTarget
);
5404 wxDropTarget
*wxGenericListCtrl::GetDropTarget() const
5406 return m_mainWin
->GetDropTarget();
5411 bool wxGenericListCtrl::SetCursor( const wxCursor
&cursor
)
5413 return m_mainWin
? m_mainWin
->wxWindow::SetCursor(cursor
) : false;
5416 wxColour
wxGenericListCtrl::GetBackgroundColour() const
5418 return m_mainWin
? m_mainWin
->GetBackgroundColour() : wxColour();
5421 wxColour
wxGenericListCtrl::GetForegroundColour() const
5423 return m_mainWin
? m_mainWin
->GetForegroundColour() : wxColour();
5426 bool wxGenericListCtrl::DoPopupMenu( wxMenu
*menu
, int x
, int y
)
5429 return m_mainWin
->PopupMenu( menu
, x
, y
);
5435 void wxGenericListCtrl::SetFocus()
5437 // The test in window.cpp fails as we are a composite
5438 // window, so it checks against "this", but not m_mainWin.
5439 if ( DoFindFocus() != this )
5440 m_mainWin
->SetFocus();
5443 wxSize
wxGenericListCtrl::DoGetBestSize() const
5445 // Something is better than nothing...
5446 // 100x80 is what the MSW version will get from the default
5447 // wxControl::DoGetBestSize
5448 return wxSize(100, 80);
5451 // ----------------------------------------------------------------------------
5452 // virtual list control support
5453 // ----------------------------------------------------------------------------
5455 wxString
wxGenericListCtrl::OnGetItemText(long WXUNUSED(item
), long WXUNUSED(col
)) const
5457 // this is a pure virtual function, in fact - which is not really pure
5458 // because the controls which are not virtual don't need to implement it
5459 wxFAIL_MSG( _T("wxGenericListCtrl::OnGetItemText not supposed to be called") );
5461 return wxEmptyString
;
5464 int wxGenericListCtrl::OnGetItemImage(long WXUNUSED(item
)) const
5466 wxCHECK_MSG(!GetImageList(wxIMAGE_LIST_SMALL
),
5468 wxT("List control has an image list, OnGetItemImage or OnGetItemColumnImage should be overridden."));
5472 int wxGenericListCtrl::OnGetItemColumnImage(long item
, long column
) const
5475 return OnGetItemImage(item
);
5481 wxGenericListCtrl::OnGetItemAttr(long WXUNUSED_UNLESS_DEBUG(item
)) const
5483 wxASSERT_MSG( item
>= 0 && item
< GetItemCount(),
5484 _T("invalid item index in OnGetItemAttr()") );
5486 // no attributes by default
5490 void wxGenericListCtrl::SetItemCount(long count
)
5492 wxASSERT_MSG( IsVirtual(), _T("this is for virtual controls only") );
5494 m_mainWin
->SetItemCount(count
);
5497 void wxGenericListCtrl::RefreshItem(long item
)
5499 m_mainWin
->RefreshLine(item
);
5502 void wxGenericListCtrl::RefreshItems(long itemFrom
, long itemTo
)
5504 m_mainWin
->RefreshLines(itemFrom
, itemTo
);
5507 // Generic wxListCtrl is more or less a container for two other
5508 // windows which drawings are done upon. These are namely
5509 // 'm_headerWin' and 'm_mainWin'.
5510 // Here we override 'virtual wxWindow::Refresh()' to mimic the
5511 // behaviour wxListCtrl has under wxMSW.
5513 void wxGenericListCtrl::Refresh(bool eraseBackground
, const wxRect
*rect
)
5517 // The easy case, no rectangle specified.
5519 m_headerWin
->Refresh(eraseBackground
);
5522 m_mainWin
->Refresh(eraseBackground
);
5526 // Refresh the header window
5529 wxRect rectHeader
= m_headerWin
->GetRect();
5530 rectHeader
.Intersect(*rect
);
5531 if (rectHeader
.GetWidth() && rectHeader
.GetHeight())
5534 m_headerWin
->GetPosition(&x
, &y
);
5535 rectHeader
.Offset(-x
, -y
);
5536 m_headerWin
->Refresh(eraseBackground
, &rectHeader
);
5540 // Refresh the main window
5543 wxRect rectMain
= m_mainWin
->GetRect();
5544 rectMain
.Intersect(*rect
);
5545 if (rectMain
.GetWidth() && rectMain
.GetHeight())
5548 m_mainWin
->GetPosition(&x
, &y
);
5549 rectMain
.Offset(-x
, -y
);
5550 m_mainWin
->Refresh(eraseBackground
, &rectMain
);
5556 void wxGenericListCtrl::Freeze()
5558 m_mainWin
->Freeze();
5561 void wxGenericListCtrl::Thaw()
5566 #endif // wxUSE_LISTCTRL