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 bool HasImage() const { return GetImage() != -1; }
345 bool HasText() const { return !GetText(0).empty(); }
347 void SetItem( int index
, const wxListItem
&info
);
348 void GetItem( int index
, wxListItem
&info
);
350 wxString
GetText(int index
) const;
351 void SetText( int index
, const wxString
& s
);
353 wxListItemAttr
*GetAttr() const;
354 void SetAttr(wxListItemAttr
*attr
);
356 // return true if the highlighting really changed
357 bool Highlight( bool on
);
359 void ReverseHighlight();
361 bool IsHighlighted() const
363 wxASSERT_MSG( !IsVirtual(), _T("unexpected call to IsHighlighted") );
365 return m_highlighted
;
368 // draw the line on the given DC in icon/list mode
369 void Draw( wxDC
*dc
);
371 // the same in report mode
372 void DrawInReportMode( wxDC
*dc
,
374 const wxRect
& rectHL
,
378 // set the line to contain num items (only can be > 1 in report mode)
379 void InitItems( int num
);
381 // get the mode (i.e. style) of the list control
382 inline int GetMode() const;
384 // prepare the DC for drawing with these item's attributes, return true if
385 // we need to draw the items background to highlight it, false otherwise
386 bool SetAttributes(wxDC
*dc
,
387 const wxListItemAttr
*attr
,
390 // draw the text on the DC with the correct justification; also add an
391 // ellipsis if the text is too large to fit in the current width
392 void DrawTextFormatted(wxDC
*dc
, const wxString
&text
, int col
, int x
, int y
, int width
);
394 // these are only used by GetImage/SetImage above, we don't support images
395 // with subitems at the public API level yet
396 void SetImage( int index
, int image
);
397 int GetImage( int index
) const;
400 WX_DECLARE_EXPORTED_OBJARRAY(wxListLineData
, wxListLineDataArray
);
401 #include "wx/arrimpl.cpp"
402 WX_DEFINE_OBJARRAY(wxListLineDataArray
)
404 //-----------------------------------------------------------------------------
405 // wxListHeaderWindow (internal)
406 //-----------------------------------------------------------------------------
408 class WXDLLEXPORT wxListHeaderWindow
: public wxWindow
411 wxListMainWindow
*m_owner
;
412 wxCursor
*m_currentCursor
;
413 wxCursor
*m_resizeCursor
;
416 // column being resized or -1
419 // divider line position in logical (unscrolled) coords
422 // minimal position beyond which the divider line
423 // can't be dragged in logical coords
427 wxListHeaderWindow();
429 wxListHeaderWindow( wxWindow
*win
,
431 wxListMainWindow
*owner
,
432 const wxPoint
&pos
= wxDefaultPosition
,
433 const wxSize
&size
= wxDefaultSize
,
435 const wxString
&name
= wxT("wxlistctrlcolumntitles") );
437 virtual ~wxListHeaderWindow();
440 void AdjustDC( wxDC
& dc
);
442 void OnPaint( wxPaintEvent
&event
);
443 void OnMouse( wxMouseEvent
&event
);
444 void OnSetFocus( wxFocusEvent
&event
);
450 // common part of all ctors
453 // generate and process the list event of the given type, return true if
454 // it wasn't vetoed, i.e. if we should proceed
455 bool SendListEvent(wxEventType type
, const wxPoint
& pos
);
457 DECLARE_DYNAMIC_CLASS(wxListHeaderWindow
)
458 DECLARE_EVENT_TABLE()
461 //-----------------------------------------------------------------------------
462 // wxListRenameTimer (internal)
463 //-----------------------------------------------------------------------------
465 class WXDLLEXPORT wxListRenameTimer
: public wxTimer
468 wxListMainWindow
*m_owner
;
471 wxListRenameTimer( wxListMainWindow
*owner
);
475 //-----------------------------------------------------------------------------
476 // wxListTextCtrl (internal)
477 //-----------------------------------------------------------------------------
479 class WXDLLEXPORT wxListTextCtrl
: public wxTextCtrl
482 wxListTextCtrl(wxListMainWindow
*owner
, size_t itemEdit
);
484 void AcceptChangesAndFinish();
487 void OnChar( wxKeyEvent
&event
);
488 void OnKeyUp( wxKeyEvent
&event
);
489 void OnKillFocus( wxFocusEvent
&event
);
491 bool AcceptChanges();
495 wxListMainWindow
*m_owner
;
496 wxString m_startValue
;
499 bool m_aboutToFinish
;
501 DECLARE_EVENT_TABLE()
504 //-----------------------------------------------------------------------------
505 // wxListMainWindow (internal)
506 //-----------------------------------------------------------------------------
508 WX_DECLARE_LIST(wxListHeaderData
, wxListHeaderDataList
);
509 #include "wx/listimpl.cpp"
510 WX_DEFINE_LIST(wxListHeaderDataList
)
512 class wxListMainWindow
: public wxScrolledWindow
516 wxListMainWindow( wxWindow
*parent
,
518 const wxPoint
& pos
= wxDefaultPosition
,
519 const wxSize
& size
= wxDefaultSize
,
521 const wxString
&name
= _T("listctrlmainwindow") );
523 virtual ~wxListMainWindow();
525 wxWindow
*GetMainWindowOfCompositeControl() { return GetParent(); }
527 bool HasFlag(int flag
) const { return m_parent
->HasFlag(flag
); }
529 // return true if this is a virtual list control
530 bool IsVirtual() const { return HasFlag(wxLC_VIRTUAL
); }
532 // return true if the control is in report mode
533 bool InReportView() const { return HasFlag(wxLC_REPORT
); }
535 // return true if we are in single selection mode, false if multi sel
536 bool IsSingleSel() const { return HasFlag(wxLC_SINGLE_SEL
); }
538 // do we have a header window?
539 bool HasHeader() const
540 { return InReportView() && !HasFlag(wxLC_NO_HEADER
); }
542 void HighlightAll( bool on
);
544 // all these functions only do something if the line is currently visible
546 // change the line "selected" state, return true if it really changed
547 bool HighlightLine( size_t line
, bool highlight
= true);
549 // as HighlightLine() but do it for the range of lines: this is incredibly
550 // more efficient for virtual list controls!
552 // NB: unlike HighlightLine() this one does refresh the lines on screen
553 void HighlightLines( size_t lineFrom
, size_t lineTo
, bool on
= true );
555 // toggle the line state and refresh it
556 void ReverseHighlight( size_t line
)
557 { HighlightLine(line
, !IsHighlighted(line
)); RefreshLine(line
); }
559 // return true if the line is highlighted
560 bool IsHighlighted(size_t line
) const;
562 // refresh one or several lines at once
563 void RefreshLine( size_t line
);
564 void RefreshLines( size_t lineFrom
, size_t lineTo
);
566 // refresh all selected items
567 void RefreshSelected();
569 // refresh all lines below the given one: the difference with
570 // RefreshLines() is that the index here might not be a valid one (happens
571 // when the last line is deleted)
572 void RefreshAfter( size_t lineFrom
);
574 // the methods which are forwarded to wxListLineData itself in list/icon
575 // modes but are here because the lines don't store their positions in the
578 // get the bound rect for the entire line
579 wxRect
GetLineRect(size_t line
) const;
581 // get the bound rect of the label
582 wxRect
GetLineLabelRect(size_t line
) const;
584 // get the bound rect of the items icon (only may be called if we do have
586 wxRect
GetLineIconRect(size_t line
) const;
588 // get the rect to be highlighted when the item has focus
589 wxRect
GetLineHighlightRect(size_t line
) const;
591 // get the size of the total line rect
592 wxSize
GetLineSize(size_t line
) const
593 { return GetLineRect(line
).GetSize(); }
595 // return the hit code for the corresponding position (in this line)
596 long HitTestLine(size_t line
, int x
, int y
) const;
598 // bring the selected item into view, scrolling to it if necessary
599 void MoveToItem(size_t item
);
601 // bring the current item into view
602 void MoveToFocus() { MoveToItem(m_current
); }
604 // start editing the label of the given item
605 void EditLabel( long item
);
607 // suspend/resume redrawing the control
611 void OnRenameTimer();
612 bool OnRenameAccept(size_t itemEdit
, const wxString
& value
);
613 void OnRenameCancelled(size_t itemEdit
);
615 void OnMouse( wxMouseEvent
&event
);
617 // called to switch the selection from the current item to newCurrent,
618 void OnArrowChar( size_t newCurrent
, const wxKeyEvent
& event
);
620 void OnChar( wxKeyEvent
&event
);
621 void OnKeyDown( wxKeyEvent
&event
);
622 void OnSetFocus( wxFocusEvent
&event
);
623 void OnKillFocus( wxFocusEvent
&event
);
624 void OnScroll( wxScrollWinEvent
& event
);
626 void OnPaint( wxPaintEvent
&event
);
628 void DrawImage( int index
, wxDC
*dc
, int x
, int y
);
629 void GetImageSize( int index
, int &width
, int &height
) const;
630 int GetTextLength( const wxString
&s
) const;
632 void SetImageList( wxImageListType
*imageList
, int which
);
633 void SetItemSpacing( int spacing
, bool isSmall
= false );
634 int GetItemSpacing( bool isSmall
= false );
636 void SetColumn( int col
, wxListItem
&item
);
637 void SetColumnWidth( int col
, int width
);
638 void GetColumn( int col
, wxListItem
&item
) const;
639 int GetColumnWidth( int col
) const;
640 int GetColumnCount() const { return m_columns
.GetCount(); }
642 // returns the sum of the heights of all columns
643 int GetHeaderWidth() const;
645 int GetCountPerPage() const;
647 void SetItem( wxListItem
&item
);
648 void GetItem( wxListItem
&item
) const;
649 void SetItemState( long item
, long state
, long stateMask
);
650 void SetItemStateAll( long state
, long stateMask
);
651 int GetItemState( long item
, long stateMask
) const;
652 void GetItemRect( long index
, wxRect
&rect
) const;
653 wxRect
GetViewRect() const;
654 bool GetItemPosition( long item
, wxPoint
& pos
) const;
655 int GetSelectedItemCount() const;
657 wxString
GetItemText(long item
) const
660 info
.m_mask
= wxLIST_MASK_TEXT
;
661 info
.m_itemId
= item
;
666 void SetItemText(long item
, const wxString
& value
)
669 info
.m_mask
= wxLIST_MASK_TEXT
;
670 info
.m_itemId
= item
;
675 // set the scrollbars and update the positions of the items
676 void RecalculatePositions(bool noRefresh
= false);
678 // refresh the window and the header
681 long GetNextItem( long item
, int geometry
, int state
) const;
682 void DeleteItem( long index
);
683 void DeleteAllItems();
684 void DeleteColumn( int col
);
685 void DeleteEverything();
686 void EnsureVisible( long index
);
687 long FindItem( long start
, const wxString
& str
, bool partial
= false );
688 long FindItem( long start
, wxUIntPtr data
);
689 long FindItem( const wxPoint
& pt
);
690 long HitTest( int x
, int y
, int &flags
);
691 void InsertItem( wxListItem
&item
);
692 void InsertColumn( long col
, wxListItem
&item
);
693 int GetItemWidthWithImage(wxListItem
* item
);
694 void SortItems( wxListCtrlCompare fn
, long data
);
696 size_t GetItemCount() const;
697 bool IsEmpty() const { return GetItemCount() == 0; }
698 void SetItemCount(long count
);
700 // change the current (== focused) item, send a notification event
701 void ChangeCurrent(size_t current
);
702 void ResetCurrent() { ChangeCurrent((size_t)-1); }
703 bool HasCurrent() const { return m_current
!= (size_t)-1; }
705 // send out a wxListEvent
706 void SendNotify( size_t line
,
708 const wxPoint
& point
= wxDefaultPosition
);
710 // override base class virtual to reset m_lineHeight when the font changes
711 virtual bool SetFont(const wxFont
& font
)
713 if ( !wxScrolledWindow::SetFont(font
) )
721 // these are for wxListLineData usage only
723 // get the backpointer to the list ctrl
724 wxGenericListCtrl
*GetListCtrl() const
726 return wxStaticCast(GetParent(), wxGenericListCtrl
);
729 // get the height of all lines (assuming they all do have the same height)
730 wxCoord
GetLineHeight() const;
732 // get the y position of the given line (only for report view)
733 wxCoord
GetLineY(size_t line
) const;
735 // get the brush to use for the item highlighting
736 wxBrush
*GetHighlightBrush() const
738 return m_hasFocus
? m_highlightBrush
: m_highlightUnfocusedBrush
;
742 // the array of all line objects for a non virtual list control (for the
743 // virtual list control we only ever use m_lines[0])
744 wxListLineDataArray m_lines
;
746 // the list of column objects
747 wxListHeaderDataList m_columns
;
749 // currently focused item or -1
752 // the number of lines per page
755 // this flag is set when something which should result in the window
756 // redrawing happens (i.e. an item was added or deleted, or its appearance
757 // changed) and OnPaint() doesn't redraw the window while it is set which
758 // allows to minimize the number of repaintings when a lot of items are
759 // being added. The real repainting occurs only after the next OnIdle()
763 wxColour
*m_highlightColour
;
764 wxImageListType
*m_small_image_list
;
765 wxImageListType
*m_normal_image_list
;
767 int m_normal_spacing
;
771 wxTimer
*m_renameTimer
;
775 ColWidthArray m_aColWidths
;
777 // for double click logic
778 size_t m_lineLastClicked
,
779 m_lineBeforeLastClicked
,
780 m_lineSelectSingleOnUp
;
782 wxListTextCtrl
* m_textctrl
;
785 // the total count of items in a virtual list control
788 // the object maintaining the items selection state, only used in virtual
790 wxSelectionStore m_selStore
;
792 // common part of all ctors
795 // get the line data for the given index
796 wxListLineData
*GetLine(size_t n
) const
798 wxASSERT_MSG( n
!= (size_t)-1, _T("invalid line index") );
802 wxConstCast(this, wxListMainWindow
)->CacheLineData(n
);
809 // get a dummy line which can be used for geometry calculations and such:
810 // you must use GetLine() if you want to really draw the line
811 wxListLineData
*GetDummyLine() const;
813 // cache the line data of the n-th line in m_lines[0]
814 void CacheLineData(size_t line
);
816 // get the range of visible lines
817 void GetVisibleLinesRange(size_t *from
, size_t *to
);
819 // force us to recalculate the range of visible lines
820 void ResetVisibleLinesRange() { m_lineFrom
= (size_t)-1; }
822 // get the colour to be used for drawing the rules
823 wxColour
GetRuleColour() const
825 return wxSystemSettings::GetColour(wxSYS_COLOUR_3DLIGHT
);
829 // initialize the current item if needed
830 void UpdateCurrent();
832 // delete all items but don't refresh: called from dtor
833 void DoDeleteAllItems();
835 // the height of one line using the current font
836 wxCoord m_lineHeight
;
838 // the total header width or 0 if not calculated yet
839 wxCoord m_headerWidth
;
841 // the first and last lines being shown on screen right now (inclusive),
842 // both may be -1 if they must be calculated so never access them directly:
843 // use GetVisibleLinesRange() above instead
847 // the brushes to use for item highlighting when we do/don't have focus
848 wxBrush
*m_highlightBrush
,
849 *m_highlightUnfocusedBrush
;
851 // if this is > 0, the control is frozen and doesn't redraw itself
852 size_t m_freezeCount
;
854 DECLARE_DYNAMIC_CLASS(wxListMainWindow
)
855 DECLARE_EVENT_TABLE()
857 friend class wxGenericListCtrl
;
861 wxListItemData::~wxListItemData()
863 // in the virtual list control the attributes are managed by the main
864 // program, so don't delete them
865 if ( !m_owner
->IsVirtual() )
871 void wxListItemData::Init()
879 wxListItemData::wxListItemData(wxListMainWindow
*owner
)
885 if ( owner
->InReportView() )
891 void wxListItemData::SetItem( const wxListItem
&info
)
893 if ( info
.m_mask
& wxLIST_MASK_TEXT
)
894 SetText(info
.m_text
);
895 if ( info
.m_mask
& wxLIST_MASK_IMAGE
)
896 m_image
= info
.m_image
;
897 if ( info
.m_mask
& wxLIST_MASK_DATA
)
898 m_data
= info
.m_data
;
900 if ( info
.HasAttributes() )
903 *m_attr
= *info
.GetAttributes();
905 m_attr
= new wxListItemAttr(*info
.GetAttributes());
913 m_rect
->width
= info
.m_width
;
917 void wxListItemData::SetPosition( int x
, int y
)
919 wxCHECK_RET( m_rect
, _T("unexpected SetPosition() call") );
925 void wxListItemData::SetSize( int width
, int height
)
927 wxCHECK_RET( m_rect
, _T("unexpected SetSize() call") );
930 m_rect
->width
= width
;
932 m_rect
->height
= height
;
935 bool wxListItemData::IsHit( int x
, int y
) const
937 wxCHECK_MSG( m_rect
, false, _T("can't be called in this mode") );
939 return wxRect(GetX(), GetY(), GetWidth(), GetHeight()).Inside(x
, y
);
942 int wxListItemData::GetX() const
944 wxCHECK_MSG( m_rect
, 0, _T("can't be called in this mode") );
949 int wxListItemData::GetY() const
951 wxCHECK_MSG( m_rect
, 0, _T("can't be called in this mode") );
956 int wxListItemData::GetWidth() const
958 wxCHECK_MSG( m_rect
, 0, _T("can't be called in this mode") );
960 return m_rect
->width
;
963 int wxListItemData::GetHeight() const
965 wxCHECK_MSG( m_rect
, 0, _T("can't be called in this mode") );
967 return m_rect
->height
;
970 void wxListItemData::GetItem( wxListItem
&info
) const
972 long mask
= info
.m_mask
;
974 // by default, get everything for backwards compatibility
977 if ( mask
& wxLIST_MASK_TEXT
)
978 info
.m_text
= m_text
;
979 if ( mask
& wxLIST_MASK_IMAGE
)
980 info
.m_image
= m_image
;
981 if ( mask
& wxLIST_MASK_DATA
)
982 info
.m_data
= m_data
;
986 if ( m_attr
->HasTextColour() )
987 info
.SetTextColour(m_attr
->GetTextColour());
988 if ( m_attr
->HasBackgroundColour() )
989 info
.SetBackgroundColour(m_attr
->GetBackgroundColour());
990 if ( m_attr
->HasFont() )
991 info
.SetFont(m_attr
->GetFont());
995 //-----------------------------------------------------------------------------
997 //-----------------------------------------------------------------------------
999 void wxListHeaderData::Init()
1010 wxListHeaderData::wxListHeaderData()
1015 wxListHeaderData::wxListHeaderData( const wxListItem
&item
)
1022 void wxListHeaderData::SetItem( const wxListItem
&item
)
1024 m_mask
= item
.m_mask
;
1026 if ( m_mask
& wxLIST_MASK_TEXT
)
1027 m_text
= item
.m_text
;
1029 if ( m_mask
& wxLIST_MASK_IMAGE
)
1030 m_image
= item
.m_image
;
1032 if ( m_mask
& wxLIST_MASK_FORMAT
)
1033 m_format
= item
.m_format
;
1035 if ( m_mask
& wxLIST_MASK_WIDTH
)
1036 SetWidth(item
.m_width
);
1039 void wxListHeaderData::SetPosition( int x
, int y
)
1045 void wxListHeaderData::SetHeight( int h
)
1050 void wxListHeaderData::SetWidth( int w
)
1052 m_width
= w
< 0 ? WIDTH_COL_DEFAULT
: w
;
1055 void wxListHeaderData::SetFormat( int format
)
1060 bool wxListHeaderData::HasImage() const
1062 return m_image
!= -1;
1065 bool wxListHeaderData::IsHit( int x
, int y
) const
1067 return ((x
>= m_xpos
) && (x
<= m_xpos
+m_width
) && (y
>= m_ypos
) && (y
<= m_ypos
+m_height
));
1070 void wxListHeaderData::GetItem( wxListItem
& item
)
1072 item
.m_mask
= m_mask
;
1073 item
.m_text
= m_text
;
1074 item
.m_image
= m_image
;
1075 item
.m_format
= m_format
;
1076 item
.m_width
= m_width
;
1079 int wxListHeaderData::GetImage() const
1084 int wxListHeaderData::GetWidth() const
1089 int wxListHeaderData::GetFormat() const
1094 //-----------------------------------------------------------------------------
1096 //-----------------------------------------------------------------------------
1098 inline int wxListLineData::GetMode() const
1100 return m_owner
->GetListCtrl()->GetWindowStyleFlag() & wxLC_MASK_TYPE
;
1103 inline bool wxListLineData::InReportView() const
1105 return m_owner
->HasFlag(wxLC_REPORT
);
1108 inline bool wxListLineData::IsVirtual() const
1110 return m_owner
->IsVirtual();
1113 wxListLineData::wxListLineData( wxListMainWindow
*owner
)
1117 if ( InReportView() )
1120 m_gi
= new GeometryInfo
;
1122 m_highlighted
= false;
1124 InitItems( GetMode() == wxLC_REPORT
? m_owner
->GetColumnCount() : 1 );
1127 void wxListLineData::CalculateSize( wxDC
*dc
, int spacing
)
1129 wxListItemDataList::compatibility_iterator node
= m_items
.GetFirst();
1130 wxCHECK_RET( node
, _T("no subitems at all??") );
1132 wxListItemData
*item
= node
->GetData();
1137 switch ( GetMode() )
1140 case wxLC_SMALL_ICON
:
1141 m_gi
->m_rectAll
.width
= spacing
;
1143 s
= item
->GetText();
1148 m_gi
->m_rectLabel
.width
=
1149 m_gi
->m_rectLabel
.height
= 0;
1153 dc
->GetTextExtent( s
, &lw
, &lh
);
1157 m_gi
->m_rectAll
.height
= spacing
+ lh
;
1159 m_gi
->m_rectAll
.width
= lw
;
1161 m_gi
->m_rectLabel
.width
= lw
;
1162 m_gi
->m_rectLabel
.height
= lh
;
1165 if (item
->HasImage())
1168 m_owner
->GetImageSize( item
->GetImage(), w
, h
);
1169 m_gi
->m_rectIcon
.width
= w
+ 8;
1170 m_gi
->m_rectIcon
.height
= h
+ 8;
1172 if ( m_gi
->m_rectIcon
.width
> m_gi
->m_rectAll
.width
)
1173 m_gi
->m_rectAll
.width
= m_gi
->m_rectIcon
.width
;
1174 if ( m_gi
->m_rectIcon
.height
+ lh
> m_gi
->m_rectAll
.height
- 4 )
1175 m_gi
->m_rectAll
.height
= m_gi
->m_rectIcon
.height
+ lh
+ 4;
1178 if ( item
->HasText() )
1180 m_gi
->m_rectHighlight
.width
= m_gi
->m_rectLabel
.width
;
1181 m_gi
->m_rectHighlight
.height
= m_gi
->m_rectLabel
.height
;
1183 else // no text, highlight the icon
1185 m_gi
->m_rectHighlight
.width
= m_gi
->m_rectIcon
.width
;
1186 m_gi
->m_rectHighlight
.height
= m_gi
->m_rectIcon
.height
;
1191 s
= item
->GetTextForMeasuring();
1193 dc
->GetTextExtent( s
, &lw
, &lh
);
1197 m_gi
->m_rectLabel
.width
= lw
;
1198 m_gi
->m_rectLabel
.height
= lh
;
1200 m_gi
->m_rectAll
.width
= lw
;
1201 m_gi
->m_rectAll
.height
= lh
;
1203 if (item
->HasImage())
1206 m_owner
->GetImageSize( item
->GetImage(), w
, h
);
1207 m_gi
->m_rectIcon
.width
= w
;
1208 m_gi
->m_rectIcon
.height
= h
;
1210 m_gi
->m_rectAll
.width
+= 4 + w
;
1211 if (h
> m_gi
->m_rectAll
.height
)
1212 m_gi
->m_rectAll
.height
= h
;
1215 m_gi
->m_rectHighlight
.width
= m_gi
->m_rectAll
.width
;
1216 m_gi
->m_rectHighlight
.height
= m_gi
->m_rectAll
.height
;
1220 wxFAIL_MSG( _T("unexpected call to SetSize") );
1224 wxFAIL_MSG( _T("unknown mode") );
1229 void wxListLineData::SetPosition( int x
, int y
, int spacing
)
1231 wxListItemDataList::compatibility_iterator node
= m_items
.GetFirst();
1232 wxCHECK_RET( node
, _T("no subitems at all??") );
1234 wxListItemData
*item
= node
->GetData();
1236 switch ( GetMode() )
1239 case wxLC_SMALL_ICON
:
1240 m_gi
->m_rectAll
.x
= x
;
1241 m_gi
->m_rectAll
.y
= y
;
1243 if ( item
->HasImage() )
1245 m_gi
->m_rectIcon
.x
= m_gi
->m_rectAll
.x
+ 4 +
1246 (m_gi
->m_rectAll
.width
- m_gi
->m_rectIcon
.width
) / 2;
1247 m_gi
->m_rectIcon
.y
= m_gi
->m_rectAll
.y
+ 4;
1250 if ( item
->HasText() )
1252 if (m_gi
->m_rectAll
.width
> spacing
)
1253 m_gi
->m_rectLabel
.x
= m_gi
->m_rectAll
.x
+ 2;
1255 m_gi
->m_rectLabel
.x
= m_gi
->m_rectAll
.x
+ 2 + (spacing
/ 2) - (m_gi
->m_rectLabel
.width
/ 2);
1256 m_gi
->m_rectLabel
.y
= m_gi
->m_rectAll
.y
+ m_gi
->m_rectAll
.height
+ 2 - m_gi
->m_rectLabel
.height
;
1257 m_gi
->m_rectHighlight
.x
= m_gi
->m_rectLabel
.x
- 2;
1258 m_gi
->m_rectHighlight
.y
= m_gi
->m_rectLabel
.y
- 2;
1260 else // no text, highlight the icon
1262 m_gi
->m_rectHighlight
.x
= m_gi
->m_rectIcon
.x
- 4;
1263 m_gi
->m_rectHighlight
.y
= m_gi
->m_rectIcon
.y
- 4;
1268 m_gi
->m_rectAll
.x
= x
;
1269 m_gi
->m_rectAll
.y
= y
;
1271 m_gi
->m_rectHighlight
.x
= m_gi
->m_rectAll
.x
;
1272 m_gi
->m_rectHighlight
.y
= m_gi
->m_rectAll
.y
;
1273 m_gi
->m_rectLabel
.y
= m_gi
->m_rectAll
.y
+ 2;
1275 if (item
->HasImage())
1277 m_gi
->m_rectIcon
.x
= m_gi
->m_rectAll
.x
+ 2;
1278 m_gi
->m_rectIcon
.y
= m_gi
->m_rectAll
.y
+ 2;
1279 m_gi
->m_rectLabel
.x
= m_gi
->m_rectAll
.x
+ 6 + m_gi
->m_rectIcon
.width
;
1283 m_gi
->m_rectLabel
.x
= m_gi
->m_rectAll
.x
+ 2;
1288 wxFAIL_MSG( _T("unexpected call to SetPosition") );
1292 wxFAIL_MSG( _T("unknown mode") );
1297 void wxListLineData::InitItems( int num
)
1299 for (int i
= 0; i
< num
; i
++)
1300 m_items
.Append( new wxListItemData(m_owner
) );
1303 void wxListLineData::SetItem( int index
, const wxListItem
&info
)
1305 wxListItemDataList::compatibility_iterator node
= m_items
.Item( index
);
1306 wxCHECK_RET( node
, _T("invalid column index in SetItem") );
1308 wxListItemData
*item
= node
->GetData();
1309 item
->SetItem( info
);
1312 void wxListLineData::GetItem( int index
, wxListItem
&info
)
1314 wxListItemDataList::compatibility_iterator node
= m_items
.Item( index
);
1317 wxListItemData
*item
= node
->GetData();
1318 item
->GetItem( info
);
1322 wxString
wxListLineData::GetText(int index
) const
1326 wxListItemDataList::compatibility_iterator node
= m_items
.Item( index
);
1329 wxListItemData
*item
= node
->GetData();
1330 s
= item
->GetText();
1336 void wxListLineData::SetText( int index
, const wxString
& s
)
1338 wxListItemDataList::compatibility_iterator node
= m_items
.Item( index
);
1341 wxListItemData
*item
= node
->GetData();
1346 void wxListLineData::SetImage( int index
, int image
)
1348 wxListItemDataList::compatibility_iterator node
= m_items
.Item( index
);
1349 wxCHECK_RET( node
, _T("invalid column index in SetImage()") );
1351 wxListItemData
*item
= node
->GetData();
1352 item
->SetImage(image
);
1355 int wxListLineData::GetImage( int index
) const
1357 wxListItemDataList::compatibility_iterator node
= m_items
.Item( index
);
1358 wxCHECK_MSG( node
, -1, _T("invalid column index in GetImage()") );
1360 wxListItemData
*item
= node
->GetData();
1361 return item
->GetImage();
1364 wxListItemAttr
*wxListLineData::GetAttr() const
1366 wxListItemDataList::compatibility_iterator node
= m_items
.GetFirst();
1367 wxCHECK_MSG( node
, NULL
, _T("invalid column index in GetAttr()") );
1369 wxListItemData
*item
= node
->GetData();
1370 return item
->GetAttr();
1373 void wxListLineData::SetAttr(wxListItemAttr
*attr
)
1375 wxListItemDataList::compatibility_iterator node
= m_items
.GetFirst();
1376 wxCHECK_RET( node
, _T("invalid column index in SetAttr()") );
1378 wxListItemData
*item
= node
->GetData();
1379 item
->SetAttr(attr
);
1382 bool wxListLineData::SetAttributes(wxDC
*dc
,
1383 const wxListItemAttr
*attr
,
1386 wxWindow
*listctrl
= m_owner
->GetParent();
1390 // don't use foreground colour for drawing highlighted items - this might
1391 // make them completely invisible (and there is no way to do bit
1392 // arithmetics on wxColour, unfortunately)
1395 colText
= wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHTTEXT
);
1396 else if ( attr
&& attr
->HasTextColour() )
1397 colText
= attr
->GetTextColour();
1399 colText
= listctrl
->GetForegroundColour();
1401 dc
->SetTextForeground(colText
);
1405 if ( attr
&& attr
->HasFont() )
1406 font
= attr
->GetFont();
1408 font
= listctrl
->GetFont();
1413 bool hasBgCol
= attr
&& attr
->HasBackgroundColour();
1414 if ( highlighted
|| hasBgCol
)
1417 dc
->SetBrush( *m_owner
->GetHighlightBrush() );
1419 dc
->SetBrush(wxBrush(attr
->GetBackgroundColour(), wxSOLID
));
1421 dc
->SetPen( *wxTRANSPARENT_PEN
);
1429 void wxListLineData::Draw( wxDC
*dc
)
1431 wxListItemDataList::compatibility_iterator node
= m_items
.GetFirst();
1432 wxCHECK_RET( node
, _T("no subitems at all??") );
1434 bool highlighted
= IsHighlighted();
1436 wxListItemAttr
*attr
= GetAttr();
1438 if ( SetAttributes(dc
, attr
, highlighted
) )
1439 dc
->DrawRectangle( m_gi
->m_rectHighlight
);
1441 // just for debugging to better see where the items are
1443 dc
->SetPen(*wxRED_PEN
);
1444 dc
->SetBrush(*wxTRANSPARENT_BRUSH
);
1445 dc
->DrawRectangle( m_gi
->m_rectAll
);
1446 dc
->SetPen(*wxGREEN_PEN
);
1447 dc
->DrawRectangle( m_gi
->m_rectIcon
);
1450 wxListItemData
*item
= node
->GetData();
1451 if (item
->HasImage())
1453 // centre the image inside our rectangle, this looks nicer when items
1454 // ae aligned in a row
1455 const wxRect
& rectIcon
= m_gi
->m_rectIcon
;
1457 m_owner
->DrawImage(item
->GetImage(), dc
, rectIcon
.x
, rectIcon
.y
);
1460 if (item
->HasText())
1462 const wxRect
& rectLabel
= m_gi
->m_rectLabel
;
1464 wxDCClipper
clipper(*dc
, rectLabel
);
1465 dc
->DrawText(item
->GetText(), rectLabel
.x
, rectLabel
.y
);
1469 void wxListLineData::DrawInReportMode( wxDC
*dc
,
1471 const wxRect
& rectHL
,
1474 // TODO: later we should support setting different attributes for
1475 // different columns - to do it, just add "col" argument to
1476 // GetAttr() and move these lines into the loop below
1477 wxListItemAttr
*attr
= GetAttr();
1478 if ( SetAttributes(dc
, attr
, highlighted
) )
1479 dc
->DrawRectangle( rectHL
);
1481 wxCoord x
= rect
.x
+ HEADER_OFFSET_X
,
1482 y
= rect
.y
+ (LINE_SPACING
+ EXTRA_HEIGHT
) / 2;
1485 for ( wxListItemDataList::compatibility_iterator node
= m_items
.GetFirst();
1487 node
= node
->GetNext(), col
++ )
1489 wxListItemData
*item
= node
->GetData();
1491 int width
= m_owner
->GetColumnWidth(col
);
1495 if ( item
->HasImage() )
1498 m_owner
->DrawImage( item
->GetImage(), dc
, xOld
, y
);
1499 m_owner
->GetImageSize( item
->GetImage(), ix
, iy
);
1501 ix
+= IMAGE_MARGIN_IN_REPORT_MODE
;
1507 wxDCClipper
clipper(*dc
, xOld
, y
, width
- 8, rect
.height
);
1509 if ( item
->HasText() )
1510 DrawTextFormatted(dc
, item
->GetText(), col
, xOld
, y
, width
- 8);
1514 void wxListLineData::DrawTextFormatted(wxDC
*dc
,
1515 const wxString
&text
,
1521 wxString drawntext
, ellipsis
;
1522 wxCoord w
, h
, base_w
;
1525 // determine if the string can fit inside the current width
1526 dc
->GetTextExtent(text
, &w
, &h
);
1529 // it can, draw it using the items alignment
1530 m_owner
->GetColumn(col
, item
);
1531 switch ( item
.GetAlign() )
1533 case wxLIST_FORMAT_LEFT
:
1537 case wxLIST_FORMAT_RIGHT
:
1541 case wxLIST_FORMAT_CENTER
:
1542 x
+= (width
- w
) / 2;
1546 wxFAIL_MSG( _T("unknown list item format") );
1550 dc
->DrawText(text
, x
, y
);
1552 else // otherwise, truncate and add an ellipsis if possible
1554 // determine the base width
1555 ellipsis
= wxString(wxT("..."));
1556 dc
->GetTextExtent(ellipsis
, &base_w
, &h
);
1558 // continue until we have enough space or only one character left
1560 size_t len
= text
.Length();
1561 drawntext
= text
.Left(len
);
1564 dc
->GetTextExtent(drawntext
.Last(), &w_c
, &h_c
);
1565 drawntext
.RemoveLast();
1568 if (w
+ base_w
<= width
)
1572 // if still not enough space, remove ellipsis characters
1573 while (ellipsis
.Length() > 0 && w
+ base_w
> width
)
1575 ellipsis
= ellipsis
.Left(ellipsis
.Length() - 1);
1576 dc
->GetTextExtent(ellipsis
, &base_w
, &h
);
1579 // now draw the text
1580 dc
->DrawText(drawntext
, x
, y
);
1581 dc
->DrawText(ellipsis
, x
+ w
, y
);
1585 bool wxListLineData::Highlight( bool on
)
1587 wxCHECK_MSG( !IsVirtual(), false, _T("unexpected call to Highlight") );
1589 if ( on
== m_highlighted
)
1597 void wxListLineData::ReverseHighlight( void )
1599 Highlight(!IsHighlighted());
1602 //-----------------------------------------------------------------------------
1603 // wxListHeaderWindow
1604 //-----------------------------------------------------------------------------
1606 IMPLEMENT_DYNAMIC_CLASS(wxListHeaderWindow
,wxWindow
)
1608 BEGIN_EVENT_TABLE(wxListHeaderWindow
,wxWindow
)
1609 EVT_PAINT (wxListHeaderWindow::OnPaint
)
1610 EVT_MOUSE_EVENTS (wxListHeaderWindow::OnMouse
)
1611 EVT_SET_FOCUS (wxListHeaderWindow::OnSetFocus
)
1614 void wxListHeaderWindow::Init()
1616 m_currentCursor
= (wxCursor
*) NULL
;
1617 m_isDragging
= false;
1621 wxListHeaderWindow::wxListHeaderWindow()
1625 m_owner
= (wxListMainWindow
*) NULL
;
1626 m_resizeCursor
= (wxCursor
*) NULL
;
1629 wxListHeaderWindow::wxListHeaderWindow( wxWindow
*win
,
1631 wxListMainWindow
*owner
,
1635 const wxString
&name
)
1636 : wxWindow( win
, id
, pos
, size
, style
, name
)
1641 m_resizeCursor
= new wxCursor( wxCURSOR_SIZEWE
);
1644 wxVisualAttributes attr
= wxPanel::GetClassDefaultAttributes();
1645 SetOwnForegroundColour( attr
.colFg
);
1646 SetOwnBackgroundColour( attr
.colBg
);
1648 SetOwnFont( attr
.font
);
1650 SetOwnForegroundColour( wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT
));
1651 SetOwnBackgroundColour( wxSystemSettings::GetColour(wxSYS_COLOUR_BTNFACE
));
1653 SetOwnFont( wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT
));
1657 wxListHeaderWindow::~wxListHeaderWindow()
1659 delete m_resizeCursor
;
1662 #ifdef __WXUNIVERSAL__
1663 #include "wx/univ/renderer.h"
1664 #include "wx/univ/theme.h"
1667 // shift the DC origin to match the position of the main window horz
1668 // scrollbar: this allows us to always use logical coords
1669 void wxListHeaderWindow::AdjustDC(wxDC
& dc
)
1672 m_owner
->GetScrollPixelsPerUnit( &xpix
, NULL
);
1675 m_owner
->GetViewStart( &x
, NULL
);
1677 // account for the horz scrollbar offset
1678 dc
.SetDeviceOrigin( -x
* xpix
, 0 );
1681 void wxListHeaderWindow::OnPaint( wxPaintEvent
&WXUNUSED(event
) )
1683 wxPaintDC
dc( this );
1690 dc
.SetFont( GetFont() );
1692 // width and height of the entire header window
1694 GetClientSize( &w
, &h
);
1695 m_owner
->CalcUnscrolledPosition(w
, 0, &w
, NULL
);
1697 dc
.SetBackgroundMode(wxTRANSPARENT
);
1698 dc
.SetTextForeground(GetForegroundColour());
1700 int x
= HEADER_OFFSET_X
;
1701 int numColumns
= m_owner
->GetColumnCount();
1703 for ( int i
= 0; i
< numColumns
&& x
< w
; i
++ )
1705 m_owner
->GetColumn( i
, item
);
1706 int wCol
= item
.m_width
;
1708 // the width of the rect to draw: make it smaller to fit entirely
1709 // inside the column rect
1718 wxRendererNative::Get().DrawHeaderButton
1722 wxRect(x
, HEADER_OFFSET_Y
, cw
, ch
),
1723 m_parent
->IsEnabled() ? 0
1724 : (int)wxCONTROL_DISABLED
1727 // see if we have enough space for the column label
1729 // for this we need the width of the text
1732 dc
.GetTextExtent(item
.GetText(), &wLabel
, &hLabel
);
1733 wLabel
+= 2 * EXTRA_WIDTH
;
1735 // and the width of the icon, if any
1736 static const int MARGIN_BETWEEN_TEXT_AND_ICON
= 2;
1737 int ix
= 0, iy
= 0; // init them just to suppress the compiler warnings
1738 const int image
= item
.m_image
;
1739 wxImageListType
*imageList
;
1742 imageList
= m_owner
->m_small_image_list
;
1745 imageList
->GetSize(image
, ix
, iy
);
1746 wLabel
+= ix
+ MARGIN_BETWEEN_TEXT_AND_ICON
;
1754 // ignore alignment if there is not enough space anyhow
1756 switch ( wLabel
< cw
? item
.GetAlign() : wxLIST_FORMAT_LEFT
)
1759 wxFAIL_MSG( _T("unknown list item format") );
1762 case wxLIST_FORMAT_LEFT
:
1766 case wxLIST_FORMAT_RIGHT
:
1767 xAligned
= x
+ cw
- wLabel
;
1770 case wxLIST_FORMAT_CENTER
:
1771 xAligned
= x
+ (cw
- wLabel
) / 2;
1775 // if we have an image, draw it on the right of the label
1782 xAligned
+ wLabel
- ix
- MARGIN_BETWEEN_TEXT_AND_ICON
,
1783 HEADER_OFFSET_Y
+ (h
- 4 - iy
)/2,
1784 wxIMAGELIST_DRAW_TRANSPARENT
1787 cw
-= ix
+ MARGIN_BETWEEN_TEXT_AND_ICON
;
1790 // draw the text clipping it so that it doesn't overwrite the column
1792 wxDCClipper
clipper(dc
, x
, HEADER_OFFSET_Y
, cw
, h
- 4 );
1794 dc
.DrawText( item
.GetText(),
1795 xAligned
+ EXTRA_WIDTH
, h
/ 2 - hLabel
/ 2 ); //HEADER_OFFSET_Y + EXTRA_HEIGHT );
1803 void wxListHeaderWindow::DrawCurrent()
1805 int x1
= m_currentX
;
1807 m_owner
->ClientToScreen( &x1
, &y1
);
1809 int x2
= m_currentX
;
1811 m_owner
->GetClientSize( NULL
, &y2
);
1812 m_owner
->ClientToScreen( &x2
, &y2
);
1815 dc
.SetLogicalFunction( wxINVERT
);
1816 dc
.SetPen( wxPen( *wxBLACK
, 2, wxSOLID
) );
1817 dc
.SetBrush( *wxTRANSPARENT_BRUSH
);
1821 dc
.DrawLine( x1
, y1
, x2
, y2
);
1823 dc
.SetLogicalFunction( wxCOPY
);
1825 dc
.SetPen( wxNullPen
);
1826 dc
.SetBrush( wxNullBrush
);
1829 void wxListHeaderWindow::OnMouse( wxMouseEvent
&event
)
1831 // we want to work with logical coords
1833 m_owner
->CalcUnscrolledPosition(event
.GetX(), 0, &x
, NULL
);
1834 int y
= event
.GetY();
1838 SendListEvent(wxEVT_COMMAND_LIST_COL_DRAGGING
, event
.GetPosition());
1840 // we don't draw the line beyond our window, but we allow dragging it
1843 GetClientSize( &w
, NULL
);
1844 m_owner
->CalcUnscrolledPosition(w
, 0, &w
, NULL
);
1847 // erase the line if it was drawn
1848 if ( m_currentX
< w
)
1851 if (event
.ButtonUp())
1854 m_isDragging
= false;
1856 m_owner
->SetColumnWidth( m_column
, m_currentX
- m_minX
);
1857 SendListEvent(wxEVT_COMMAND_LIST_COL_END_DRAG
, event
.GetPosition());
1864 m_currentX
= m_minX
+ 7;
1866 // draw in the new location
1867 if ( m_currentX
< w
)
1871 else // not dragging
1874 bool hit_border
= false;
1876 // end of the current column
1879 // find the column where this event occurred
1881 countCol
= m_owner
->GetColumnCount();
1882 for (col
= 0; col
< countCol
; col
++)
1884 xpos
+= m_owner
->GetColumnWidth( col
);
1887 if ( (abs(x
-xpos
) < 3) && (y
< 22) )
1889 // near the column border
1896 // inside the column
1903 if ( col
== countCol
)
1906 if (event
.LeftDown() || event
.RightUp())
1908 if (hit_border
&& event
.LeftDown())
1910 if ( SendListEvent(wxEVT_COMMAND_LIST_COL_BEGIN_DRAG
,
1911 event
.GetPosition()) )
1913 m_isDragging
= true;
1918 //else: column resizing was vetoed by the user code
1920 else // click on a column
1922 SendListEvent( event
.LeftDown()
1923 ? wxEVT_COMMAND_LIST_COL_CLICK
1924 : wxEVT_COMMAND_LIST_COL_RIGHT_CLICK
,
1925 event
.GetPosition());
1928 else if (event
.Moving())
1933 setCursor
= m_currentCursor
== wxSTANDARD_CURSOR
;
1934 m_currentCursor
= m_resizeCursor
;
1938 setCursor
= m_currentCursor
!= wxSTANDARD_CURSOR
;
1939 m_currentCursor
= wxSTANDARD_CURSOR
;
1943 SetCursor(*m_currentCursor
);
1948 void wxListHeaderWindow::OnSetFocus( wxFocusEvent
&WXUNUSED(event
) )
1950 m_owner
->SetFocus();
1954 bool wxListHeaderWindow::SendListEvent(wxEventType type
, const wxPoint
& pos
)
1956 wxWindow
*parent
= GetParent();
1957 wxListEvent
le( type
, parent
->GetId() );
1958 le
.SetEventObject( parent
);
1959 le
.m_pointDrag
= pos
;
1961 // the position should be relative to the parent window, not
1962 // this one for compatibility with MSW and common sense: the
1963 // user code doesn't know anything at all about this header
1964 // window, so why should it get positions relative to it?
1965 le
.m_pointDrag
.y
-= GetSize().y
;
1967 le
.m_col
= m_column
;
1968 return !parent
->GetEventHandler()->ProcessEvent( le
) || le
.IsAllowed();
1971 //-----------------------------------------------------------------------------
1972 // wxListRenameTimer (internal)
1973 //-----------------------------------------------------------------------------
1975 wxListRenameTimer::wxListRenameTimer( wxListMainWindow
*owner
)
1980 void wxListRenameTimer::Notify()
1982 m_owner
->OnRenameTimer();
1985 //-----------------------------------------------------------------------------
1986 // wxListTextCtrl (internal)
1987 //-----------------------------------------------------------------------------
1989 BEGIN_EVENT_TABLE(wxListTextCtrl
,wxTextCtrl
)
1990 EVT_CHAR (wxListTextCtrl::OnChar
)
1991 EVT_KEY_UP (wxListTextCtrl::OnKeyUp
)
1992 EVT_KILL_FOCUS (wxListTextCtrl::OnKillFocus
)
1995 wxListTextCtrl::wxListTextCtrl(wxListMainWindow
*owner
, size_t itemEdit
)
1996 : m_startValue(owner
->GetItemText(itemEdit
)),
1997 m_itemEdited(itemEdit
)
2001 m_aboutToFinish
= false;
2003 wxRect rectLabel
= owner
->GetLineLabelRect(itemEdit
);
2005 m_owner
->CalcScrolledPosition(rectLabel
.x
, rectLabel
.y
,
2006 &rectLabel
.x
, &rectLabel
.y
);
2008 (void)Create(owner
, wxID_ANY
, m_startValue
,
2009 wxPoint(rectLabel
.x
-4,rectLabel
.y
-4),
2010 wxSize(rectLabel
.width
+11,rectLabel
.height
+8));
2013 void wxListTextCtrl::Finish()
2017 wxPendingDelete
.Append(this);
2018 m_owner
->m_textctrl
= NULL
;
2022 m_owner
->SetFocusIgnoringChildren();
2026 bool wxListTextCtrl::AcceptChanges()
2028 const wxString value
= GetValue();
2030 if ( value
== m_startValue
)
2031 // nothing changed, always accept
2034 if ( !m_owner
->OnRenameAccept(m_itemEdited
, value
) )
2035 // vetoed by the user
2038 // accepted, do rename the item
2039 m_owner
->SetItemText(m_itemEdited
, value
);
2044 void wxListTextCtrl::AcceptChangesAndFinish()
2046 m_aboutToFinish
= true;
2048 // Notify the owner about the changes
2051 // Even if vetoed, close the control (consistent with MSW)
2055 void wxListTextCtrl::OnChar( wxKeyEvent
&event
)
2057 switch ( event
.m_keyCode
)
2060 AcceptChangesAndFinish();
2065 m_owner
->OnRenameCancelled( m_itemEdited
);
2073 void wxListTextCtrl::OnKeyUp( wxKeyEvent
&event
)
2081 // auto-grow the textctrl:
2082 wxSize parentSize
= m_owner
->GetSize();
2083 wxPoint myPos
= GetPosition();
2084 wxSize mySize
= GetSize();
2086 GetTextExtent(GetValue() + _T("MM"), &sx
, &sy
);
2087 if (myPos
.x
+ sx
> parentSize
.x
)
2088 sx
= parentSize
.x
- myPos
.x
;
2091 SetSize(sx
, wxDefaultCoord
);
2096 void wxListTextCtrl::OnKillFocus( wxFocusEvent
&event
)
2098 if ( !m_finished
&& !m_aboutToFinish
)
2100 // We must finish regardless of success, otherwise we'll get
2104 if ( !AcceptChanges() )
2105 m_owner
->OnRenameCancelled( m_itemEdited
);
2108 // We must let the native text control handle focus, too, otherwise
2109 // it could have problems with the cursor (e.g., in wxGTK).
2113 //-----------------------------------------------------------------------------
2115 //-----------------------------------------------------------------------------
2117 IMPLEMENT_DYNAMIC_CLASS(wxListMainWindow
,wxScrolledWindow
)
2119 BEGIN_EVENT_TABLE(wxListMainWindow
,wxScrolledWindow
)
2120 EVT_PAINT (wxListMainWindow::OnPaint
)
2121 EVT_MOUSE_EVENTS (wxListMainWindow::OnMouse
)
2122 EVT_CHAR (wxListMainWindow::OnChar
)
2123 EVT_KEY_DOWN (wxListMainWindow::OnKeyDown
)
2124 EVT_SET_FOCUS (wxListMainWindow::OnSetFocus
)
2125 EVT_KILL_FOCUS (wxListMainWindow::OnKillFocus
)
2126 EVT_SCROLLWIN (wxListMainWindow::OnScroll
)
2129 void wxListMainWindow::Init()
2134 m_lineTo
= (size_t)-1;
2140 m_small_image_list
= (wxImageListType
*) NULL
;
2141 m_normal_image_list
= (wxImageListType
*) NULL
;
2143 m_small_spacing
= 30;
2144 m_normal_spacing
= 40;
2148 m_isCreated
= false;
2150 m_lastOnSame
= false;
2151 m_renameTimer
= new wxListRenameTimer( this );
2156 m_lineSelectSingleOnUp
=
2157 m_lineBeforeLastClicked
= (size_t)-1;
2162 wxListMainWindow::wxListMainWindow()
2167 m_highlightUnfocusedBrush
= (wxBrush
*) NULL
;
2170 wxListMainWindow::wxListMainWindow( wxWindow
*parent
,
2175 const wxString
&name
)
2176 : wxScrolledWindow( parent
, id
, pos
, size
,
2177 style
| wxHSCROLL
| wxVSCROLL
, name
)
2181 m_highlightBrush
= new wxBrush
2183 wxSystemSettings::GetColour
2185 wxSYS_COLOUR_HIGHLIGHT
2190 m_highlightUnfocusedBrush
= new wxBrush
2192 wxSystemSettings::GetColour
2194 wxSYS_COLOUR_BTNSHADOW
2199 SetScrollbars( 0, 0, 0, 0, 0, 0 );
2201 wxVisualAttributes attr
= wxGenericListCtrl::GetClassDefaultAttributes();
2202 SetOwnForegroundColour( attr
.colFg
);
2203 SetOwnBackgroundColour( attr
.colBg
);
2205 SetOwnFont( attr
.font
);
2208 wxListMainWindow::~wxListMainWindow()
2211 WX_CLEAR_LIST(wxListHeaderDataList
, m_columns
);
2212 WX_CLEAR_ARRAY(m_aColWidths
);
2214 delete m_highlightBrush
;
2215 delete m_highlightUnfocusedBrush
;
2216 delete m_renameTimer
;
2219 void wxListMainWindow::CacheLineData(size_t line
)
2221 wxGenericListCtrl
*listctrl
= GetListCtrl();
2223 wxListLineData
*ld
= GetDummyLine();
2225 size_t countCol
= GetColumnCount();
2226 for ( size_t col
= 0; col
< countCol
; col
++ )
2228 ld
->SetText(col
, listctrl
->OnGetItemText(line
, col
));
2229 ld
->SetImage(listctrl
->OnGetItemColumnImage(line
, col
));
2232 ld
->SetAttr(listctrl
->OnGetItemAttr(line
));
2235 wxListLineData
*wxListMainWindow::GetDummyLine() const
2237 wxASSERT_MSG( !IsEmpty(), _T("invalid line index") );
2238 wxASSERT_MSG( IsVirtual(), _T("GetDummyLine() shouldn't be called") );
2240 wxListMainWindow
*self
= wxConstCast(this, wxListMainWindow
);
2242 // we need to recreate the dummy line if the number of columns in the
2243 // control changed as it would have the incorrect number of fields
2245 if ( !m_lines
.IsEmpty() &&
2246 m_lines
[0].m_items
.GetCount() != (size_t)GetColumnCount() )
2248 self
->m_lines
.Clear();
2251 if ( m_lines
.IsEmpty() )
2253 wxListLineData
*line
= new wxListLineData(self
);
2254 self
->m_lines
.Add(line
);
2256 // don't waste extra memory -- there never going to be anything
2257 // else/more in this array
2258 self
->m_lines
.Shrink();
2264 // ----------------------------------------------------------------------------
2265 // line geometry (report mode only)
2266 // ----------------------------------------------------------------------------
2268 wxCoord
wxListMainWindow::GetLineHeight() const
2270 // we cache the line height as calling GetTextExtent() is slow
2271 if ( !m_lineHeight
)
2273 wxListMainWindow
*self
= wxConstCast(this, wxListMainWindow
);
2275 wxClientDC
dc( self
);
2276 dc
.SetFont( GetFont() );
2279 dc
.GetTextExtent(_T("H"), NULL
, &y
);
2281 if ( m_small_image_list
&& m_small_image_list
->GetImageCount() )
2284 m_small_image_list
->GetSize(0, iw
, ih
);
2289 self
->m_lineHeight
= y
+ LINE_SPACING
;
2292 return m_lineHeight
;
2295 wxCoord
wxListMainWindow::GetLineY(size_t line
) const
2297 wxASSERT_MSG( InReportView(), _T("only works in report mode") );
2299 return LINE_SPACING
+ line
* GetLineHeight();
2302 wxRect
wxListMainWindow::GetLineRect(size_t line
) const
2304 if ( !InReportView() )
2305 return GetLine(line
)->m_gi
->m_rectAll
;
2308 rect
.x
= HEADER_OFFSET_X
;
2309 rect
.y
= GetLineY(line
);
2310 rect
.width
= GetHeaderWidth();
2311 rect
.height
= GetLineHeight();
2316 wxRect
wxListMainWindow::GetLineLabelRect(size_t line
) const
2318 if ( !InReportView() )
2319 return GetLine(line
)->m_gi
->m_rectLabel
;
2322 rect
.x
= HEADER_OFFSET_X
;
2323 rect
.y
= GetLineY(line
);
2324 rect
.width
= GetColumnWidth(0);
2325 rect
.height
= GetLineHeight();
2330 wxRect
wxListMainWindow::GetLineIconRect(size_t line
) const
2332 if ( !InReportView() )
2333 return GetLine(line
)->m_gi
->m_rectIcon
;
2335 wxListLineData
*ld
= GetLine(line
);
2336 wxASSERT_MSG( ld
->HasImage(), _T("should have an image") );
2339 rect
.x
= HEADER_OFFSET_X
;
2340 rect
.y
= GetLineY(line
);
2341 GetImageSize(ld
->GetImage(), rect
.width
, rect
.height
);
2346 wxRect
wxListMainWindow::GetLineHighlightRect(size_t line
) const
2348 return InReportView() ? GetLineRect(line
)
2349 : GetLine(line
)->m_gi
->m_rectHighlight
;
2352 long wxListMainWindow::HitTestLine(size_t line
, int x
, int y
) const
2354 wxASSERT_MSG( line
< GetItemCount(), _T("invalid line in HitTestLine") );
2356 wxListLineData
*ld
= GetLine(line
);
2358 if ( ld
->HasImage() && GetLineIconRect(line
).Inside(x
, y
) )
2359 return wxLIST_HITTEST_ONITEMICON
;
2361 // VS: Testing for "ld->HasText() || InReportView()" instead of
2362 // "ld->HasText()" is needed to make empty lines in report view
2364 if ( ld
->HasText() || InReportView() )
2366 wxRect rect
= InReportView() ? GetLineRect(line
)
2367 : GetLineLabelRect(line
);
2369 if ( rect
.Inside(x
, y
) )
2370 return wxLIST_HITTEST_ONITEMLABEL
;
2376 // ----------------------------------------------------------------------------
2377 // highlight (selection) handling
2378 // ----------------------------------------------------------------------------
2380 bool wxListMainWindow::IsHighlighted(size_t line
) const
2384 return m_selStore
.IsSelected(line
);
2388 wxListLineData
*ld
= GetLine(line
);
2389 wxCHECK_MSG( ld
, false, _T("invalid index in IsHighlighted") );
2391 return ld
->IsHighlighted();
2395 void wxListMainWindow::HighlightLines( size_t lineFrom
,
2401 wxArrayInt linesChanged
;
2402 if ( !m_selStore
.SelectRange(lineFrom
, lineTo
, highlight
,
2405 // meny items changed state, refresh everything
2406 RefreshLines(lineFrom
, lineTo
);
2408 else // only a few items changed state, refresh only them
2410 size_t count
= linesChanged
.GetCount();
2411 for ( size_t n
= 0; n
< count
; n
++ )
2413 RefreshLine(linesChanged
[n
]);
2417 else // iterate over all items in non report view
2419 for ( size_t line
= lineFrom
; line
<= lineTo
; line
++ )
2421 if ( HighlightLine(line
, highlight
) )
2427 bool wxListMainWindow::HighlightLine( size_t line
, bool highlight
)
2433 changed
= m_selStore
.SelectItem(line
, highlight
);
2437 wxListLineData
*ld
= GetLine(line
);
2438 wxCHECK_MSG( ld
, false, _T("invalid index in HighlightLine") );
2440 changed
= ld
->Highlight(highlight
);
2445 SendNotify( line
, highlight
? wxEVT_COMMAND_LIST_ITEM_SELECTED
2446 : wxEVT_COMMAND_LIST_ITEM_DESELECTED
);
2452 void wxListMainWindow::RefreshLine( size_t line
)
2454 if ( InReportView() )
2456 size_t visibleFrom
, visibleTo
;
2457 GetVisibleLinesRange(&visibleFrom
, &visibleTo
);
2459 if ( line
< visibleFrom
|| line
> visibleTo
)
2463 wxRect rect
= GetLineRect(line
);
2465 CalcScrolledPosition( rect
.x
, rect
.y
, &rect
.x
, &rect
.y
);
2466 RefreshRect( rect
);
2469 void wxListMainWindow::RefreshLines( size_t lineFrom
, size_t lineTo
)
2471 // we suppose that they are ordered by caller
2472 wxASSERT_MSG( lineFrom
<= lineTo
, _T("indices in disorder") );
2474 wxASSERT_MSG( lineTo
< GetItemCount(), _T("invalid line range") );
2476 if ( InReportView() )
2478 size_t visibleFrom
, visibleTo
;
2479 GetVisibleLinesRange(&visibleFrom
, &visibleTo
);
2481 if ( lineFrom
< visibleFrom
)
2482 lineFrom
= visibleFrom
;
2483 if ( lineTo
> visibleTo
)
2488 rect
.y
= GetLineY(lineFrom
);
2489 rect
.width
= GetClientSize().x
;
2490 rect
.height
= GetLineY(lineTo
) - rect
.y
+ GetLineHeight();
2492 CalcScrolledPosition( rect
.x
, rect
.y
, &rect
.x
, &rect
.y
);
2493 RefreshRect( rect
);
2497 // TODO: this should be optimized...
2498 for ( size_t line
= lineFrom
; line
<= lineTo
; line
++ )
2505 void wxListMainWindow::RefreshAfter( size_t lineFrom
)
2507 if ( InReportView() )
2509 size_t visibleFrom
, visibleTo
;
2510 GetVisibleLinesRange(&visibleFrom
, &visibleTo
);
2512 if ( lineFrom
< visibleFrom
)
2513 lineFrom
= visibleFrom
;
2514 else if ( lineFrom
> visibleTo
)
2519 rect
.y
= GetLineY(lineFrom
);
2520 CalcScrolledPosition( rect
.x
, rect
.y
, &rect
.x
, &rect
.y
);
2522 wxSize size
= GetClientSize();
2523 rect
.width
= size
.x
;
2525 // refresh till the bottom of the window
2526 rect
.height
= size
.y
- rect
.y
;
2528 RefreshRect( rect
);
2532 // TODO: how to do it more efficiently?
2537 void wxListMainWindow::RefreshSelected()
2543 if ( InReportView() )
2545 GetVisibleLinesRange(&from
, &to
);
2550 to
= GetItemCount() - 1;
2553 if ( HasCurrent() && m_current
>= from
&& m_current
<= to
)
2554 RefreshLine(m_current
);
2556 for ( size_t line
= from
; line
<= to
; line
++ )
2558 // NB: the test works as expected even if m_current == -1
2559 if ( line
!= m_current
&& IsHighlighted(line
) )
2564 void wxListMainWindow::Freeze()
2569 void wxListMainWindow::Thaw()
2571 wxCHECK_RET( m_freezeCount
> 0, _T("thawing unfrozen list control?") );
2573 if ( !--m_freezeCount
)
2577 void wxListMainWindow::OnPaint( wxPaintEvent
&WXUNUSED(event
) )
2579 // Note: a wxPaintDC must be constructed even if no drawing is
2580 // done (a Windows requirement).
2581 wxPaintDC
dc( this );
2583 if ( IsEmpty() || m_freezeCount
)
2584 // nothing to draw or not the moment to draw it
2588 // delay the repainting until we calculate all the items positions
2594 CalcScrolledPosition( 0, 0, &dev_x
, &dev_y
);
2598 dc
.SetFont( GetFont() );
2600 if ( InReportView() )
2602 int lineHeight
= GetLineHeight();
2604 size_t visibleFrom
, visibleTo
;
2605 GetVisibleLinesRange(&visibleFrom
, &visibleTo
);
2608 wxCoord xOrig
, yOrig
;
2609 CalcUnscrolledPosition(0, 0, &xOrig
, &yOrig
);
2611 // tell the caller cache to cache the data
2614 wxListEvent
evCache(wxEVT_COMMAND_LIST_CACHE_HINT
,
2615 GetParent()->GetId());
2616 evCache
.SetEventObject( GetParent() );
2617 evCache
.m_oldItemIndex
= visibleFrom
;
2618 evCache
.m_itemIndex
= visibleTo
;
2619 GetParent()->GetEventHandler()->ProcessEvent( evCache
);
2622 for ( size_t line
= visibleFrom
; line
<= visibleTo
; line
++ )
2624 rectLine
= GetLineRect(line
);
2626 if ( !IsExposed(rectLine
.x
- xOrig
, rectLine
.y
- yOrig
,
2627 rectLine
.width
, rectLine
.height
) )
2629 // don't redraw unaffected lines to avoid flicker
2633 GetLine(line
)->DrawInReportMode( &dc
,
2635 GetLineHighlightRect(line
),
2636 IsHighlighted(line
) );
2639 if ( HasFlag(wxLC_HRULES
) )
2641 wxPen
pen(GetRuleColour(), 1, wxSOLID
);
2642 wxSize clientSize
= GetClientSize();
2644 // Don't draw the first one
2645 for ( size_t i
= visibleFrom
+ 1; i
<= visibleTo
; i
++ )
2648 dc
.SetBrush( *wxTRANSPARENT_BRUSH
);
2649 dc
.DrawLine(0 - dev_x
, i
* lineHeight
,
2650 clientSize
.x
- dev_x
, i
* lineHeight
);
2653 // Draw last horizontal rule
2654 if ( visibleTo
== GetItemCount() - 1 )
2657 dc
.SetBrush( *wxTRANSPARENT_BRUSH
);
2658 dc
.DrawLine(0 - dev_x
, (m_lineTo
+ 1) * lineHeight
,
2659 clientSize
.x
- dev_x
, (m_lineTo
+ 1) * lineHeight
);
2663 // Draw vertical rules if required
2664 if ( HasFlag(wxLC_VRULES
) && !IsEmpty() )
2666 wxPen
pen(GetRuleColour(), 1, wxSOLID
);
2667 wxRect firstItemRect
, lastItemRect
;
2669 GetItemRect(visibleFrom
, firstItemRect
);
2670 GetItemRect(visibleTo
, lastItemRect
);
2671 int x
= firstItemRect
.GetX();
2673 dc
.SetBrush(* wxTRANSPARENT_BRUSH
);
2675 for (int col
= 0; col
< GetColumnCount(); col
++)
2677 int colWidth
= GetColumnWidth(col
);
2679 dc
.DrawLine(x
- dev_x
- 2, firstItemRect
.GetY() - 1 - dev_y
,
2680 x
- dev_x
- 2, lastItemRect
.GetBottom() + 1 - dev_y
);
2686 size_t count
= GetItemCount();
2687 for ( size_t i
= 0; i
< count
; i
++ )
2689 GetLine(i
)->Draw( &dc
);
2694 // Don't draw rect outline under Mac at all.
2699 dc
.SetPen( *wxBLACK_PEN
);
2700 dc
.SetBrush( *wxTRANSPARENT_BRUSH
);
2701 dc
.DrawRectangle( GetLineHighlightRect( m_current
) );
2709 void wxListMainWindow::HighlightAll( bool on
)
2711 if ( IsSingleSel() )
2713 wxASSERT_MSG( !on
, _T("can't do this in a single selection control") );
2715 // we just have one item to turn off
2716 if ( HasCurrent() && IsHighlighted(m_current
) )
2718 HighlightLine(m_current
, false);
2719 RefreshLine(m_current
);
2724 HighlightLines(0, GetItemCount() - 1, on
);
2728 void wxListMainWindow::SendNotify( size_t line
,
2729 wxEventType command
,
2730 const wxPoint
& point
)
2732 wxListEvent
le( command
, GetParent()->GetId() );
2733 le
.SetEventObject( GetParent() );
2734 le
.m_itemIndex
= line
;
2736 // set only for events which have position
2737 if ( point
!= wxDefaultPosition
)
2738 le
.m_pointDrag
= point
;
2740 // don't try to get the line info for virtual list controls: the main
2741 // program has it anyhow and if we did it would result in accessing all
2742 // the lines, even those which are not visible now and this is precisely
2743 // what we're trying to avoid
2744 if ( !IsVirtual() && (command
!= wxEVT_COMMAND_LIST_DELETE_ITEM
) )
2746 if ( line
!= (size_t)-1 )
2748 GetLine(line
)->GetItem( 0, le
.m_item
);
2750 //else: this happens for wxEVT_COMMAND_LIST_ITEM_FOCUSED event
2752 //else: there may be no more such item
2754 GetParent()->GetEventHandler()->ProcessEvent( le
);
2757 void wxListMainWindow::ChangeCurrent(size_t current
)
2759 m_current
= current
;
2761 SendNotify(current
, wxEVT_COMMAND_LIST_ITEM_FOCUSED
);
2764 void wxListMainWindow::EditLabel( long item
)
2766 wxCHECK_RET( (item
>= 0) && ((size_t)item
< GetItemCount()),
2767 wxT("wrong index in wxGenericListCtrl::EditLabel()") );
2769 size_t itemEdit
= (size_t)item
;
2771 wxListEvent
le( wxEVT_COMMAND_LIST_BEGIN_LABEL_EDIT
, GetParent()->GetId() );
2772 le
.SetEventObject( GetParent() );
2773 le
.m_itemIndex
= item
;
2774 wxListLineData
*data
= GetLine(itemEdit
);
2775 wxCHECK_RET( data
, _T("invalid index in EditLabel()") );
2776 data
->GetItem( 0, le
.m_item
);
2778 if ( GetParent()->GetEventHandler()->ProcessEvent( le
) && !le
.IsAllowed() )
2779 // vetoed by user code
2782 // We have to call this here because the label in question might just have
2783 // been added and no screen update taken place.
2787 m_textctrl
= new wxListTextCtrl(this, itemEdit
);
2788 m_textctrl
->SetFocus();
2791 void wxListMainWindow::OnRenameTimer()
2793 wxCHECK_RET( HasCurrent(), wxT("unexpected rename timer") );
2795 EditLabel( m_current
);
2798 bool wxListMainWindow::OnRenameAccept(size_t itemEdit
, const wxString
& value
)
2800 wxListEvent
le( wxEVT_COMMAND_LIST_END_LABEL_EDIT
, GetParent()->GetId() );
2801 le
.SetEventObject( GetParent() );
2802 le
.m_itemIndex
= itemEdit
;
2804 wxListLineData
*data
= GetLine(itemEdit
);
2806 wxCHECK_MSG( data
, false, _T("invalid index in OnRenameAccept()") );
2808 data
->GetItem( 0, le
.m_item
);
2809 le
.m_item
.m_text
= value
;
2810 return !GetParent()->GetEventHandler()->ProcessEvent( le
) ||
2814 void wxListMainWindow::OnRenameCancelled(size_t itemEdit
)
2816 // let owner know that the edit was cancelled
2817 wxListEvent
le( wxEVT_COMMAND_LIST_END_LABEL_EDIT
, GetParent()->GetId() );
2819 le
.SetEditCanceled(true);
2821 le
.SetEventObject( GetParent() );
2822 le
.m_itemIndex
= itemEdit
;
2824 wxListLineData
*data
= GetLine(itemEdit
);
2825 wxCHECK_RET( data
, _T("invalid index in OnRenameCancelled()") );
2827 data
->GetItem( 0, le
.m_item
);
2828 GetEventHandler()->ProcessEvent( le
);
2831 void wxListMainWindow::OnMouse( wxMouseEvent
&event
)
2834 // On wxMac we can't depend on the EVT_KILL_FOCUS event to properly
2835 // shutdown the edit control when the mouse is clicked elsewhere on the
2836 // listctrl because the order of events is different (or something like
2837 // that), so explicitly end the edit if it is active.
2838 if ( event
.LeftDown() && m_textctrl
)
2839 m_textctrl
->AcceptChangesAndFinish();
2842 event
.SetEventObject( GetParent() );
2843 if ( GetParent()->GetEventHandler()->ProcessEvent( event
) )
2846 if (event
.GetEventType() == wxEVT_MOUSEWHEEL
)
2848 // let the base handle mouse wheel events.
2853 if ( !HasCurrent() || IsEmpty() )
2859 if ( !(event
.Dragging() || event
.ButtonDown() || event
.LeftUp() ||
2860 event
.ButtonDClick()) )
2863 int x
= event
.GetX();
2864 int y
= event
.GetY();
2865 CalcUnscrolledPosition( x
, y
, &x
, &y
);
2867 // where did we hit it (if we did)?
2870 size_t count
= GetItemCount(),
2873 if ( InReportView() )
2875 current
= y
/ GetLineHeight();
2876 if ( current
< count
)
2877 hitResult
= HitTestLine(current
, x
, y
);
2881 // TODO: optimize it too! this is less simple than for report view but
2882 // enumerating all items is still not a way to do it!!
2883 for ( current
= 0; current
< count
; current
++ )
2885 hitResult
= HitTestLine(current
, x
, y
);
2891 if (event
.Dragging())
2893 if (m_dragCount
== 0)
2895 // we have to report the raw, physical coords as we want to be
2896 // able to call HitTest(event.m_pointDrag) from the user code to
2897 // get the item being dragged
2898 m_dragStart
= event
.GetPosition();
2903 if (m_dragCount
!= 3)
2906 int command
= event
.RightIsDown() ? wxEVT_COMMAND_LIST_BEGIN_RDRAG
2907 : wxEVT_COMMAND_LIST_BEGIN_DRAG
;
2909 wxListEvent
le( command
, GetParent()->GetId() );
2910 le
.SetEventObject( GetParent() );
2911 le
.m_itemIndex
= m_lineLastClicked
;
2912 le
.m_pointDrag
= m_dragStart
;
2913 GetParent()->GetEventHandler()->ProcessEvent( le
);
2924 // outside of any item
2928 bool forceClick
= false;
2929 if (event
.ButtonDClick())
2931 m_renameTimer
->Stop();
2932 m_lastOnSame
= false;
2934 if ( current
== m_lineLastClicked
)
2936 SendNotify( current
, wxEVT_COMMAND_LIST_ITEM_ACTIVATED
);
2942 // The first click was on another item, so don't interpret this as
2943 // a double click, but as a simple click instead
2950 if (m_lineSelectSingleOnUp
!= (size_t)-1)
2952 // select single line
2953 HighlightAll( false );
2954 ReverseHighlight(m_lineSelectSingleOnUp
);
2959 if ((current
== m_current
) &&
2960 (hitResult
== wxLIST_HITTEST_ONITEMLABEL
) &&
2961 HasFlag(wxLC_EDIT_LABELS
) )
2963 m_renameTimer
->Start( 100, true );
2967 m_lastOnSame
= false;
2968 m_lineSelectSingleOnUp
= (size_t)-1;
2972 // This is necessary, because after a DnD operation in
2973 // from and to ourself, the up event is swallowed by the
2974 // DnD code. So on next non-up event (which means here and
2975 // now) m_lineSelectSingleOnUp should be reset.
2976 m_lineSelectSingleOnUp
= (size_t)-1;
2978 if (event
.RightDown())
2980 m_lineBeforeLastClicked
= m_lineLastClicked
;
2981 m_lineLastClicked
= current
;
2983 // If the item is already selected, do not update the selection.
2984 // Multi-selections should not be cleared if a selected item is clicked.
2985 if (!IsHighlighted(current
))
2987 HighlightAll(false);
2988 ChangeCurrent(current
);
2989 ReverseHighlight(m_current
);
2992 SendNotify( current
, wxEVT_COMMAND_LIST_ITEM_RIGHT_CLICK
, event
.GetPosition() );
2994 // Allow generation of context menu event
2997 else if (event
.MiddleDown())
2999 SendNotify( current
, wxEVT_COMMAND_LIST_ITEM_MIDDLE_CLICK
);
3001 else if ( event
.LeftDown() || forceClick
)
3003 m_lineBeforeLastClicked
= m_lineLastClicked
;
3004 m_lineLastClicked
= current
;
3006 size_t oldCurrent
= m_current
;
3007 bool oldWasSelected
= IsHighlighted(m_current
);
3009 bool cmdModifierDown
= event
.CmdDown();
3010 if ( IsSingleSel() || !(cmdModifierDown
|| event
.ShiftDown()) )
3012 if ( IsSingleSel() || !IsHighlighted(current
) )
3014 HighlightAll( false );
3016 ChangeCurrent(current
);
3018 ReverseHighlight(m_current
);
3020 else // multi sel & current is highlighted & no mod keys
3022 m_lineSelectSingleOnUp
= current
;
3023 ChangeCurrent(current
); // change focus
3026 else // multi sel & either ctrl or shift is down
3028 if (cmdModifierDown
)
3030 ChangeCurrent(current
);
3032 ReverseHighlight(m_current
);
3034 else if (event
.ShiftDown())
3036 ChangeCurrent(current
);
3038 size_t lineFrom
= oldCurrent
,
3041 if ( lineTo
< lineFrom
)
3044 lineFrom
= m_current
;
3047 HighlightLines(lineFrom
, lineTo
);
3049 else // !ctrl, !shift
3051 // test in the enclosing if should make it impossible
3052 wxFAIL_MSG( _T("how did we get here?") );
3056 if (m_current
!= oldCurrent
)
3057 RefreshLine( oldCurrent
);
3059 // forceClick is only set if the previous click was on another item
3060 m_lastOnSame
= !forceClick
&& (m_current
== oldCurrent
) && oldWasSelected
;
3064 void wxListMainWindow::MoveToItem(size_t item
)
3066 if ( item
== (size_t)-1 )
3069 wxRect rect
= GetLineRect(item
);
3071 int client_w
, client_h
;
3072 GetClientSize( &client_w
, &client_h
);
3074 const int hLine
= GetLineHeight();
3076 int view_x
= SCROLL_UNIT_X
* GetScrollPos( wxHORIZONTAL
);
3077 int view_y
= hLine
* GetScrollPos( wxVERTICAL
);
3079 if ( InReportView() )
3081 // the next we need the range of lines shown it might be different,
3082 // so recalculate it
3083 ResetVisibleLinesRange();
3085 if (rect
.y
< view_y
)
3086 Scroll( -1, rect
.y
/ hLine
);
3087 if (rect
.y
+ rect
.height
+ 5 > view_y
+ client_h
)
3088 Scroll( -1, (rect
.y
+ rect
.height
- client_h
+ hLine
) / hLine
);
3092 if (rect
.x
-view_x
< 5)
3093 Scroll( (rect
.x
- 5) / SCROLL_UNIT_X
, -1 );
3094 if (rect
.x
+ rect
.width
- 5 > view_x
+ client_w
)
3095 Scroll( (rect
.x
+ rect
.width
- client_w
+ SCROLL_UNIT_X
) / SCROLL_UNIT_X
, -1 );
3099 // ----------------------------------------------------------------------------
3100 // keyboard handling
3101 // ----------------------------------------------------------------------------
3103 void wxListMainWindow::OnArrowChar(size_t newCurrent
, const wxKeyEvent
& event
)
3105 wxCHECK_RET( newCurrent
< (size_t)GetItemCount(),
3106 _T("invalid item index in OnArrowChar()") );
3108 size_t oldCurrent
= m_current
;
3110 // in single selection we just ignore Shift as we can't select several
3112 if ( event
.ShiftDown() && !IsSingleSel() )
3114 ChangeCurrent(newCurrent
);
3116 // refresh the old focus to remove it
3117 RefreshLine( oldCurrent
);
3119 // select all the items between the old and the new one
3120 if ( oldCurrent
> newCurrent
)
3122 newCurrent
= oldCurrent
;
3123 oldCurrent
= m_current
;
3126 HighlightLines(oldCurrent
, newCurrent
);
3130 // all previously selected items are unselected unless ctrl is held
3131 if ( !event
.ControlDown() )
3132 HighlightAll(false);
3134 ChangeCurrent(newCurrent
);
3136 // refresh the old focus to remove it
3137 RefreshLine( oldCurrent
);
3139 if ( !event
.ControlDown() )
3141 HighlightLine( m_current
, true );
3145 RefreshLine( m_current
);
3150 void wxListMainWindow::OnKeyDown( wxKeyEvent
&event
)
3152 wxWindow
*parent
= GetParent();
3154 // propagate the key event upwards
3155 wxKeyEvent
ke( wxEVT_KEY_DOWN
);
3156 ke
.m_shiftDown
= event
.m_shiftDown
;
3157 ke
.m_controlDown
= event
.m_controlDown
;
3158 ke
.m_altDown
= event
.m_altDown
;
3159 ke
.m_metaDown
= event
.m_metaDown
;
3160 ke
.m_keyCode
= event
.m_keyCode
;
3163 ke
.SetEventObject( parent
);
3164 if (parent
->GetEventHandler()->ProcessEvent( ke
)) return;
3169 void wxListMainWindow::OnChar( wxKeyEvent
&event
)
3171 wxWindow
*parent
= GetParent();
3173 // send a list_key event up
3176 wxListEvent
le( wxEVT_COMMAND_LIST_KEY_DOWN
, GetParent()->GetId() );
3177 le
.m_itemIndex
= m_current
;
3178 GetLine(m_current
)->GetItem( 0, le
.m_item
);
3179 le
.m_code
= event
.GetKeyCode();
3180 le
.SetEventObject( parent
);
3181 parent
->GetEventHandler()->ProcessEvent( le
);
3184 // propagate the char event upwards
3185 wxKeyEvent
ke( wxEVT_CHAR
);
3186 ke
.m_shiftDown
= event
.m_shiftDown
;
3187 ke
.m_controlDown
= event
.m_controlDown
;
3188 ke
.m_altDown
= event
.m_altDown
;
3189 ke
.m_metaDown
= event
.m_metaDown
;
3190 ke
.m_keyCode
= event
.m_keyCode
;
3193 ke
.SetEventObject( parent
);
3194 if (parent
->GetEventHandler()->ProcessEvent( ke
)) return;
3196 if (event
.GetKeyCode() == WXK_TAB
)
3198 wxNavigationKeyEvent nevent
;
3199 nevent
.SetWindowChange( event
.ControlDown() );
3200 nevent
.SetDirection( !event
.ShiftDown() );
3201 nevent
.SetEventObject( GetParent()->GetParent() );
3202 nevent
.SetCurrentFocus( m_parent
);
3203 if (GetParent()->GetParent()->GetEventHandler()->ProcessEvent( nevent
))
3207 // no item -> nothing to do
3214 switch (event
.GetKeyCode())
3217 if ( m_current
> 0 )
3218 OnArrowChar( m_current
- 1, event
);
3222 if ( m_current
< (size_t)GetItemCount() - 1 )
3223 OnArrowChar( m_current
+ 1, event
);
3228 OnArrowChar( GetItemCount() - 1, event
);
3233 OnArrowChar( 0, event
);
3238 int steps
= InReportView() ? m_linesPerPage
- 1 : m_current
% m_linesPerPage
;
3240 int index
= m_current
- steps
;
3244 OnArrowChar( index
, event
);
3250 int steps
= InReportView()
3251 ? m_linesPerPage
- 1
3252 : m_linesPerPage
- (m_current
% m_linesPerPage
) - 1;
3254 size_t index
= m_current
+ steps
;
3255 size_t count
= GetItemCount();
3256 if ( index
>= count
)
3259 OnArrowChar( index
, event
);
3264 if ( !InReportView() )
3266 int index
= m_current
- m_linesPerPage
;
3270 OnArrowChar( index
, event
);
3275 if ( !InReportView() )
3277 size_t index
= m_current
+ m_linesPerPage
;
3279 size_t count
= GetItemCount();
3280 if ( index
>= count
)
3283 OnArrowChar( index
, event
);
3288 if ( IsSingleSel() )
3290 SendNotify( m_current
, wxEVT_COMMAND_LIST_ITEM_ACTIVATED
);
3292 if ( IsHighlighted(m_current
) )
3294 // don't unselect the item in single selection mode
3297 //else: select it in ReverseHighlight() below if unselected
3300 ReverseHighlight(m_current
);
3305 SendNotify( m_current
, wxEVT_COMMAND_LIST_ITEM_ACTIVATED
);
3313 // ----------------------------------------------------------------------------
3315 // ----------------------------------------------------------------------------
3317 void wxListMainWindow::OnSetFocus( wxFocusEvent
&WXUNUSED(event
) )
3321 wxFocusEvent
event( wxEVT_SET_FOCUS
, GetParent()->GetId() );
3322 event
.SetEventObject( GetParent() );
3323 if ( GetParent()->GetEventHandler()->ProcessEvent( event
) )
3327 // wxGTK sends us EVT_SET_FOCUS events even if we had never got
3328 // EVT_KILL_FOCUS before which means that we finish by redrawing the items
3329 // which are already drawn correctly resulting in horrible flicker - avoid
3339 void wxListMainWindow::OnKillFocus( wxFocusEvent
&WXUNUSED(event
) )
3343 wxFocusEvent
event( wxEVT_KILL_FOCUS
, GetParent()->GetId() );
3344 event
.SetEventObject( GetParent() );
3345 if ( GetParent()->GetEventHandler()->ProcessEvent( event
) )
3353 void wxListMainWindow::DrawImage( int index
, wxDC
*dc
, int x
, int y
)
3355 if ( HasFlag(wxLC_ICON
) && (m_normal_image_list
))
3357 m_normal_image_list
->Draw( index
, *dc
, x
, y
, wxIMAGELIST_DRAW_TRANSPARENT
);
3359 else if ( HasFlag(wxLC_SMALL_ICON
) && (m_small_image_list
))
3361 m_small_image_list
->Draw( index
, *dc
, x
, y
, wxIMAGELIST_DRAW_TRANSPARENT
);
3363 else if ( HasFlag(wxLC_LIST
) && (m_small_image_list
))
3365 m_small_image_list
->Draw( index
, *dc
, x
, y
, wxIMAGELIST_DRAW_TRANSPARENT
);
3367 else if ( InReportView() && (m_small_image_list
))
3369 m_small_image_list
->Draw( index
, *dc
, x
, y
, wxIMAGELIST_DRAW_TRANSPARENT
);
3373 void wxListMainWindow::GetImageSize( int index
, int &width
, int &height
) const
3375 if ( HasFlag(wxLC_ICON
) && m_normal_image_list
)
3377 m_normal_image_list
->GetSize( index
, width
, height
);
3379 else if ( HasFlag(wxLC_SMALL_ICON
) && m_small_image_list
)
3381 m_small_image_list
->GetSize( index
, width
, height
);
3383 else if ( HasFlag(wxLC_LIST
) && m_small_image_list
)
3385 m_small_image_list
->GetSize( index
, width
, height
);
3387 else if ( InReportView() && m_small_image_list
)
3389 m_small_image_list
->GetSize( index
, width
, height
);
3398 int wxListMainWindow::GetTextLength( const wxString
&s
) const
3400 wxClientDC
dc( wxConstCast(this, wxListMainWindow
) );
3401 dc
.SetFont( GetFont() );
3404 dc
.GetTextExtent( s
, &lw
, NULL
);
3406 return lw
+ AUTOSIZE_COL_MARGIN
;
3409 void wxListMainWindow::SetImageList( wxImageListType
*imageList
, int which
)
3413 // calc the spacing from the icon size
3414 int width
= 0, height
= 0;
3416 if ((imageList
) && (imageList
->GetImageCount()) )
3417 imageList
->GetSize(0, width
, height
);
3419 if (which
== wxIMAGE_LIST_NORMAL
)
3421 m_normal_image_list
= imageList
;
3422 m_normal_spacing
= width
+ 8;
3425 if (which
== wxIMAGE_LIST_SMALL
)
3427 m_small_image_list
= imageList
;
3428 m_small_spacing
= width
+ 14;
3429 m_lineHeight
= 0; // ensure that the line height will be recalc'd
3433 void wxListMainWindow::SetItemSpacing( int spacing
, bool isSmall
)
3437 m_small_spacing
= spacing
;
3439 m_normal_spacing
= spacing
;
3442 int wxListMainWindow::GetItemSpacing( bool isSmall
)
3444 return isSmall
? m_small_spacing
: m_normal_spacing
;
3447 // ----------------------------------------------------------------------------
3449 // ----------------------------------------------------------------------------
3451 void wxListMainWindow::SetColumn( int col
, wxListItem
&item
)
3453 wxListHeaderDataList::compatibility_iterator node
= m_columns
.Item( col
);
3455 wxCHECK_RET( node
, _T("invalid column index in SetColumn") );
3457 if ( item
.m_width
== wxLIST_AUTOSIZE_USEHEADER
)
3458 item
.m_width
= GetTextLength( item
.m_text
);
3460 wxListHeaderData
*column
= node
->GetData();
3461 column
->SetItem( item
);
3463 wxListHeaderWindow
*headerWin
= GetListCtrl()->m_headerWin
;
3465 headerWin
->m_dirty
= true;
3469 // invalidate it as it has to be recalculated
3473 void wxListMainWindow::SetColumnWidth( int col
, int width
)
3475 wxCHECK_RET( col
>= 0 && col
< GetColumnCount(),
3476 _T("invalid column index") );
3478 wxCHECK_RET( InReportView(),
3479 _T("SetColumnWidth() can only be called in report mode.") );
3482 wxListHeaderWindow
*headerWin
= GetListCtrl()->m_headerWin
;
3484 headerWin
->m_dirty
= true;
3486 wxListHeaderDataList::compatibility_iterator node
= m_columns
.Item( col
);
3487 wxCHECK_RET( node
, _T("no column?") );
3489 wxListHeaderData
*column
= node
->GetData();
3491 size_t count
= GetItemCount();
3493 if (width
== wxLIST_AUTOSIZE_USEHEADER
)
3495 width
= GetTextLength(column
->GetText());
3497 else if ( width
== wxLIST_AUTOSIZE
)
3501 // TODO: determine the max width somehow...
3502 width
= WIDTH_COL_DEFAULT
;
3506 wxClientDC
dc(this);
3507 dc
.SetFont( GetFont() );
3509 int max
= AUTOSIZE_COL_MARGIN
;
3511 // if the cached column width isn't valid then recalculate it
3512 if (m_aColWidths
.Item(col
)->bNeedsUpdate
)
3514 for (size_t i
= 0; i
< count
; i
++)
3516 wxListLineData
*line
= GetLine( i
);
3517 wxListItemDataList::compatibility_iterator n
= line
->m_items
.Item( col
);
3519 wxCHECK_RET( n
, _T("no subitem?") );
3521 wxListItemData
*itemData
= n
->GetData();
3524 itemData
->GetItem(item
);
3525 int itemWidth
= GetItemWidthWithImage(&item
);
3526 if (itemWidth
> max
)
3530 m_aColWidths
.Item(col
)->bNeedsUpdate
= false;
3531 m_aColWidths
.Item(col
)->nMaxWidth
= max
;
3534 max
= m_aColWidths
.Item(col
)->nMaxWidth
;
3535 width
= max
+ AUTOSIZE_COL_MARGIN
;
3539 column
->SetWidth( width
);
3541 // invalidate it as it has to be recalculated
3545 int wxListMainWindow::GetHeaderWidth() const
3547 if ( !m_headerWidth
)
3549 wxListMainWindow
*self
= wxConstCast(this, wxListMainWindow
);
3551 size_t count
= GetColumnCount();
3552 for ( size_t col
= 0; col
< count
; col
++ )
3554 self
->m_headerWidth
+= GetColumnWidth(col
);
3558 return m_headerWidth
;
3561 void wxListMainWindow::GetColumn( int col
, wxListItem
&item
) const
3563 wxListHeaderDataList::compatibility_iterator node
= m_columns
.Item( col
);
3564 wxCHECK_RET( node
, _T("invalid column index in GetColumn") );
3566 wxListHeaderData
*column
= node
->GetData();
3567 column
->GetItem( item
);
3570 int wxListMainWindow::GetColumnWidth( int col
) const
3572 wxListHeaderDataList::compatibility_iterator node
= m_columns
.Item( col
);
3573 wxCHECK_MSG( node
, 0, _T("invalid column index") );
3575 wxListHeaderData
*column
= node
->GetData();
3576 return column
->GetWidth();
3579 // ----------------------------------------------------------------------------
3581 // ----------------------------------------------------------------------------
3583 void wxListMainWindow::SetItem( wxListItem
&item
)
3585 long id
= item
.m_itemId
;
3586 wxCHECK_RET( id
>= 0 && (size_t)id
< GetItemCount(),
3587 _T("invalid item index in SetItem") );
3591 wxListLineData
*line
= GetLine((size_t)id
);
3592 line
->SetItem( item
.m_col
, item
);
3594 // Set item state if user wants
3595 if ( item
.m_mask
& wxLIST_MASK_STATE
)
3596 SetItemState( item
.m_itemId
, item
.m_state
, item
.m_state
);
3600 // update the Max Width Cache if needed
3601 int width
= GetItemWidthWithImage(&item
);
3603 if (width
> m_aColWidths
.Item(item
.m_col
)->nMaxWidth
)
3604 m_aColWidths
.Item(item
.m_col
)->nMaxWidth
= width
;
3608 // update the item on screen
3610 GetItemRect(id
, rectItem
);
3611 RefreshRect(rectItem
);
3614 void wxListMainWindow::SetItemStateAll(long state
, long stateMask
)
3619 // first deal with selection
3620 if ( stateMask
& wxLIST_STATE_SELECTED
)
3622 // set/clear select state
3625 // optimized version for virtual listctrl.
3626 m_selStore
.SelectRange(0, GetItemCount() - 1, state
== wxLIST_STATE_SELECTED
);
3629 else if ( state
& wxLIST_STATE_SELECTED
)
3631 const long count
= GetItemCount();
3632 for( long i
= 0; i
< count
; i
++ )
3634 SetItemState( i
, wxLIST_STATE_SELECTED
, wxLIST_STATE_SELECTED
);
3640 // clear for non virtual (somewhat optimized by using GetNextItem())
3642 while ( (i
= GetNextItem(i
, wxLIST_NEXT_ALL
, wxLIST_STATE_SELECTED
)) != -1 )
3644 SetItemState( i
, 0, wxLIST_STATE_SELECTED
);
3649 if ( HasCurrent() && (state
== 0) && (stateMask
& wxLIST_STATE_FOCUSED
) )
3651 // unfocus all: only one item can be focussed, so clearing focus for
3652 // all items is simply clearing focus of the focussed item.
3653 SetItemState(m_current
, state
, stateMask
);
3655 //(setting focus to all items makes no sense, so it is not handled here.)
3658 void wxListMainWindow::SetItemState( long litem
, long state
, long stateMask
)
3662 SetItemStateAll(state
, stateMask
);
3666 wxCHECK_RET( litem
>= 0 && (size_t)litem
< GetItemCount(),
3667 _T("invalid list ctrl item index in SetItem") );
3669 size_t oldCurrent
= m_current
;
3670 size_t item
= (size_t)litem
; // safe because of the check above
3672 // do we need to change the focus?
3673 if ( stateMask
& wxLIST_STATE_FOCUSED
)
3675 if ( state
& wxLIST_STATE_FOCUSED
)
3677 // don't do anything if this item is already focused
3678 if ( item
!= m_current
)
3680 ChangeCurrent(item
);
3682 if ( oldCurrent
!= (size_t)-1 )
3684 if ( IsSingleSel() )
3686 HighlightLine(oldCurrent
, false);
3689 RefreshLine(oldCurrent
);
3692 RefreshLine( m_current
);
3697 // don't do anything if this item is not focused
3698 if ( item
== m_current
)
3702 if ( IsSingleSel() )
3704 // we must unselect the old current item as well or we
3705 // might end up with more than one selected item in a
3706 // single selection control
3707 HighlightLine(oldCurrent
, false);
3710 RefreshLine( oldCurrent
);
3715 // do we need to change the selection state?
3716 if ( stateMask
& wxLIST_STATE_SELECTED
)
3718 bool on
= (state
& wxLIST_STATE_SELECTED
) != 0;
3720 if ( IsSingleSel() )
3724 // selecting the item also makes it the focused one in the
3726 if ( m_current
!= item
)
3728 ChangeCurrent(item
);
3730 if ( oldCurrent
!= (size_t)-1 )
3732 HighlightLine( oldCurrent
, false );
3733 RefreshLine( oldCurrent
);
3739 // only the current item may be selected anyhow
3740 if ( item
!= m_current
)
3745 if ( HighlightLine(item
, on
) )
3752 int wxListMainWindow::GetItemState( long item
, long stateMask
) const
3754 wxCHECK_MSG( item
>= 0 && (size_t)item
< GetItemCount(), 0,
3755 _T("invalid list ctrl item index in GetItemState()") );
3757 int ret
= wxLIST_STATE_DONTCARE
;
3759 if ( stateMask
& wxLIST_STATE_FOCUSED
)
3761 if ( (size_t)item
== m_current
)
3762 ret
|= wxLIST_STATE_FOCUSED
;
3765 if ( stateMask
& wxLIST_STATE_SELECTED
)
3767 if ( IsHighlighted(item
) )
3768 ret
|= wxLIST_STATE_SELECTED
;
3774 void wxListMainWindow::GetItem( wxListItem
&item
) const
3776 wxCHECK_RET( item
.m_itemId
>= 0 && (size_t)item
.m_itemId
< GetItemCount(),
3777 _T("invalid item index in GetItem") );
3779 wxListLineData
*line
= GetLine((size_t)item
.m_itemId
);
3780 line
->GetItem( item
.m_col
, item
);
3782 // Get item state if user wants it
3783 if ( item
.m_mask
& wxLIST_MASK_STATE
)
3784 item
.m_state
= GetItemState( item
.m_itemId
, wxLIST_STATE_SELECTED
|
3785 wxLIST_STATE_FOCUSED
);
3788 // ----------------------------------------------------------------------------
3790 // ----------------------------------------------------------------------------
3792 size_t wxListMainWindow::GetItemCount() const
3794 return IsVirtual() ? m_countVirt
: m_lines
.GetCount();
3797 void wxListMainWindow::SetItemCount(long count
)
3799 m_selStore
.SetItemCount(count
);
3800 m_countVirt
= count
;
3802 ResetVisibleLinesRange();
3804 // scrollbars must be reset
3808 int wxListMainWindow::GetSelectedItemCount() const
3810 // deal with the quick case first
3811 if ( IsSingleSel() )
3812 return HasCurrent() ? IsHighlighted(m_current
) : false;
3814 // virtual controls remmebers all its selections itself
3816 return m_selStore
.GetSelectedCount();
3818 // TODO: we probably should maintain the number of items selected even for
3819 // non virtual controls as enumerating all lines is really slow...
3820 size_t countSel
= 0;
3821 size_t count
= GetItemCount();
3822 for ( size_t line
= 0; line
< count
; line
++ )
3824 if ( GetLine(line
)->IsHighlighted() )
3831 // ----------------------------------------------------------------------------
3832 // item position/size
3833 // ----------------------------------------------------------------------------
3835 wxRect
wxListMainWindow::GetViewRect() const
3837 wxASSERT_MSG( !HasFlag(wxLC_REPORT
| wxLC_LIST
),
3838 _T("wxListCtrl::GetViewRect() only works in icon mode") );
3840 // we need to find the longest/tallest label
3841 wxCoord xMax
= 0, yMax
= 0;
3842 const int count
= GetItemCount();
3845 for ( int i
= 0; i
< count
; i
++ )
3850 wxCoord x
= r
.GetRight(),
3860 // some fudge needed to make it look prettier
3861 xMax
+= 2 * EXTRA_BORDER_X
;
3862 yMax
+= 2 * EXTRA_BORDER_Y
;
3864 // account for the scrollbars if necessary
3865 const wxSize sizeAll
= GetClientSize();
3866 if ( xMax
> sizeAll
.x
)
3867 yMax
+= wxSystemSettings::GetMetric(wxSYS_HSCROLL_Y
);
3868 if ( yMax
> sizeAll
.y
)
3869 xMax
+= wxSystemSettings::GetMetric(wxSYS_VSCROLL_X
);
3871 return wxRect(0, 0, xMax
, yMax
);
3874 void wxListMainWindow::GetItemRect( long index
, wxRect
&rect
) const
3876 wxCHECK_RET( index
>= 0 && (size_t)index
< GetItemCount(),
3877 _T("invalid index in GetItemRect") );
3879 // ensure that we're laid out, otherwise we could return nonsense
3882 wxConstCast(this, wxListMainWindow
)->
3883 RecalculatePositions(true /* no refresh */);
3886 rect
= GetLineRect((size_t)index
);
3888 CalcScrolledPosition(rect
.x
, rect
.y
, &rect
.x
, &rect
.y
);
3891 bool wxListMainWindow::GetItemPosition(long item
, wxPoint
& pos
) const
3894 GetItemRect(item
, rect
);
3902 // ----------------------------------------------------------------------------
3903 // geometry calculation
3904 // ----------------------------------------------------------------------------
3906 void wxListMainWindow::RecalculatePositions(bool noRefresh
)
3908 wxClientDC
dc( this );
3909 dc
.SetFont( GetFont() );
3911 const size_t count
= GetItemCount();
3914 if ( HasFlag(wxLC_ICON
) )
3915 iconSpacing
= m_normal_spacing
;
3916 else if ( HasFlag(wxLC_SMALL_ICON
) )
3917 iconSpacing
= m_small_spacing
;
3921 // Note that we do not call GetClientSize() here but
3922 // GetSize() and subtract the border size for sunken
3923 // borders manually. This is technically incorrect,
3924 // but we need to know the client area's size WITHOUT
3925 // scrollbars here. Since we don't know if there are
3926 // any scrollbars, we use GetSize() instead. Another
3927 // solution would be to call SetScrollbars() here to
3928 // remove the scrollbars and call GetClientSize() then,
3929 // but this might result in flicker and - worse - will
3930 // reset the scrollbars to 0 which is not good at all
3931 // if you resize a dialog/window, but don't want to
3932 // reset the window scrolling. RR.
3933 // Furthermore, we actually do NOT subtract the border
3934 // width as 2 pixels is just the extra space which we
3935 // need around the actual content in the window. Other-
3936 // wise the text would e.g. touch the upper border. RR.
3939 GetSize( &clientWidth
, &clientHeight
);
3941 const int lineHeight
= GetLineHeight();
3943 if ( InReportView() )
3945 // all lines have the same height and we scroll one line per step
3946 int entireHeight
= count
* lineHeight
+ LINE_SPACING
;
3948 m_linesPerPage
= clientHeight
/ lineHeight
;
3950 ResetVisibleLinesRange();
3952 SetScrollbars( SCROLL_UNIT_X
, lineHeight
,
3953 GetHeaderWidth() / SCROLL_UNIT_X
,
3954 (entireHeight
+ lineHeight
- 1) / lineHeight
,
3955 GetScrollPos(wxHORIZONTAL
),
3956 GetScrollPos(wxVERTICAL
),
3961 // we have 3 different layout strategies: either layout all items
3962 // horizontally/vertically (wxLC_ALIGN_XXX styles explicitly given) or
3963 // to arrange them in top to bottom, left to right (don't ask me why
3964 // not the other way round...) order
3965 if ( HasFlag(wxLC_ALIGN_LEFT
| wxLC_ALIGN_TOP
) )
3967 int x
= EXTRA_BORDER_X
;
3968 int y
= EXTRA_BORDER_Y
;
3970 wxCoord widthMax
= 0;
3973 for ( i
= 0; i
< count
; i
++ )
3975 wxListLineData
*line
= GetLine(i
);
3976 line
->CalculateSize( &dc
, iconSpacing
);
3977 line
->SetPosition( x
, y
, iconSpacing
);
3979 wxSize sizeLine
= GetLineSize(i
);
3981 if ( HasFlag(wxLC_ALIGN_TOP
) )
3983 if ( sizeLine
.x
> widthMax
)
3984 widthMax
= sizeLine
.x
;
3988 else // wxLC_ALIGN_LEFT
3990 x
+= sizeLine
.x
+ MARGIN_BETWEEN_ROWS
;
3994 if ( HasFlag(wxLC_ALIGN_TOP
) )
3996 // traverse the items again and tweak their sizes so that they are
3997 // all the same in a row
3998 for ( i
= 0; i
< count
; i
++ )
4000 wxListLineData
*line
= GetLine(i
);
4001 line
->m_gi
->ExtendWidth(widthMax
);
4009 (x
+ SCROLL_UNIT_X
) / SCROLL_UNIT_X
,
4010 (y
+ lineHeight
) / lineHeight
,
4011 GetScrollPos( wxHORIZONTAL
),
4012 GetScrollPos( wxVERTICAL
),
4016 else // "flowed" arrangement, the most complicated case
4018 // at first we try without any scrollbars, if the items don't fit into
4019 // the window, we recalculate after subtracting the space taken by the
4022 int entireWidth
= 0;
4024 for (int tries
= 0; tries
< 2; tries
++)
4026 entireWidth
= 2 * EXTRA_BORDER_X
;
4030 // Now we have decided that the items do not fit into the
4031 // client area, so we need a scrollbar
4032 entireWidth
+= SCROLL_UNIT_X
;
4035 int x
= EXTRA_BORDER_X
;
4036 int y
= EXTRA_BORDER_Y
;
4037 int maxWidthInThisRow
= 0;
4040 int currentlyVisibleLines
= 0;
4042 for (size_t i
= 0; i
< count
; i
++)
4044 currentlyVisibleLines
++;
4045 wxListLineData
*line
= GetLine( i
);
4046 line
->CalculateSize( &dc
, iconSpacing
);
4047 line
->SetPosition( x
, y
, iconSpacing
);
4049 wxSize sizeLine
= GetLineSize( i
);
4051 if ( maxWidthInThisRow
< sizeLine
.x
)
4052 maxWidthInThisRow
= sizeLine
.x
;
4055 if (currentlyVisibleLines
> m_linesPerPage
)
4056 m_linesPerPage
= currentlyVisibleLines
;
4058 if ( y
+ sizeLine
.y
>= clientHeight
)
4060 currentlyVisibleLines
= 0;
4062 maxWidthInThisRow
+= MARGIN_BETWEEN_ROWS
;
4063 x
+= maxWidthInThisRow
;
4064 entireWidth
+= maxWidthInThisRow
;
4065 maxWidthInThisRow
= 0;
4068 // We have reached the last item.
4069 if ( i
== count
- 1 )
4070 entireWidth
+= maxWidthInThisRow
;
4072 if ( (tries
== 0) &&
4073 (entireWidth
+ SCROLL_UNIT_X
> clientWidth
) )
4075 clientHeight
-= wxSystemSettings::
4076 GetMetric(wxSYS_HSCROLL_Y
);
4081 if ( i
== count
- 1 )
4082 tries
= 1; // Everything fits, no second try required.
4090 (entireWidth
+ SCROLL_UNIT_X
) / SCROLL_UNIT_X
,
4092 GetScrollPos( wxHORIZONTAL
),
4101 // FIXME: why should we call it from here?
4108 void wxListMainWindow::RefreshAll()
4113 wxListHeaderWindow
*headerWin
= GetListCtrl()->m_headerWin
;
4114 if ( headerWin
&& headerWin
->m_dirty
)
4116 headerWin
->m_dirty
= false;
4117 headerWin
->Refresh();
4121 void wxListMainWindow::UpdateCurrent()
4123 if ( !HasCurrent() && !IsEmpty() )
4127 long wxListMainWindow::GetNextItem( long item
,
4128 int WXUNUSED(geometry
),
4132 max
= GetItemCount();
4133 wxCHECK_MSG( (ret
== -1) || (ret
< max
), -1,
4134 _T("invalid listctrl index in GetNextItem()") );
4136 // notice that we start with the next item (or the first one if item == -1)
4137 // and this is intentional to allow writing a simple loop to iterate over
4138 // all selected items
4141 // this is not an error because the index was OK initially,
4142 // just no such item
4149 size_t count
= GetItemCount();
4150 for ( size_t line
= (size_t)ret
; line
< count
; line
++ )
4152 if ( (state
& wxLIST_STATE_FOCUSED
) && (line
== m_current
) )
4155 if ( (state
& wxLIST_STATE_SELECTED
) && IsHighlighted(line
) )
4162 // ----------------------------------------------------------------------------
4164 // ----------------------------------------------------------------------------
4166 void wxListMainWindow::DeleteItem( long lindex
)
4168 size_t count
= GetItemCount();
4170 wxCHECK_RET( (lindex
>= 0) && ((size_t)lindex
< count
),
4171 _T("invalid item index in DeleteItem") );
4173 size_t index
= (size_t)lindex
;
4175 // we don't need to adjust the index for the previous items
4176 if ( HasCurrent() && m_current
>= index
)
4178 // if the current item is being deleted, we want the next one to
4179 // become selected - unless there is no next one - so don't adjust
4180 // m_current in this case
4181 if ( m_current
!= index
|| m_current
== count
- 1 )
4185 if ( InReportView() )
4187 // mark the Column Max Width cache as dirty if the items in the line
4188 // we're deleting contain the Max Column Width
4189 wxListLineData
* const line
= GetLine(index
);
4190 wxListItemDataList::compatibility_iterator n
;
4191 wxListItemData
*itemData
;
4195 for (size_t i
= 0; i
< m_columns
.GetCount(); i
++)
4197 n
= line
->m_items
.Item( i
);
4198 itemData
= n
->GetData();
4199 itemData
->GetItem(item
);
4201 itemWidth
= GetItemWidthWithImage(&item
);
4203 if (itemWidth
>= m_aColWidths
.Item(i
)->nMaxWidth
)
4204 m_aColWidths
.Item(i
)->bNeedsUpdate
= true;
4207 ResetVisibleLinesRange();
4213 m_selStore
.OnItemDelete(index
);
4217 m_lines
.RemoveAt( index
);
4220 // we need to refresh the (vert) scrollbar as the number of items changed
4223 SendNotify( index
, wxEVT_COMMAND_LIST_DELETE_ITEM
);
4225 RefreshAfter(index
);
4228 void wxListMainWindow::DeleteColumn( int col
)
4230 wxListHeaderDataList::compatibility_iterator node
= m_columns
.Item( col
);
4232 wxCHECK_RET( node
, wxT("invalid column index in DeleteColumn()") );
4235 delete node
->GetData();
4236 m_columns
.Erase( node
);
4240 // update all the items
4241 for ( size_t i
= 0; i
< m_lines
.GetCount(); i
++ )
4243 wxListLineData
* const line
= GetLine(i
);
4244 wxListItemDataList::compatibility_iterator n
= line
->m_items
.Item( col
);
4245 delete n
->GetData();
4246 line
->m_items
.Erase(n
);
4250 if ( InReportView() ) // we only cache max widths when in Report View
4252 delete m_aColWidths
.Item(col
);
4253 m_aColWidths
.RemoveAt(col
);
4256 // invalidate it as it has to be recalculated
4260 void wxListMainWindow::DoDeleteAllItems()
4263 // nothing to do - in particular, don't send the event
4268 // to make the deletion of all items faster, we don't send the
4269 // notifications for each item deletion in this case but only one event
4270 // for all of them: this is compatible with wxMSW and documented in
4271 // DeleteAllItems() description
4273 wxListEvent
event( wxEVT_COMMAND_LIST_DELETE_ALL_ITEMS
, GetParent()->GetId() );
4274 event
.SetEventObject( GetParent() );
4275 GetParent()->GetEventHandler()->ProcessEvent( event
);
4283 if ( InReportView() )
4285 ResetVisibleLinesRange();
4286 for (size_t i
= 0; i
< m_aColWidths
.GetCount(); i
++)
4288 m_aColWidths
.Item(i
)->bNeedsUpdate
= true;
4295 void wxListMainWindow::DeleteAllItems()
4299 RecalculatePositions();
4302 void wxListMainWindow::DeleteEverything()
4304 WX_CLEAR_LIST(wxListHeaderDataList
, m_columns
);
4305 WX_CLEAR_ARRAY(m_aColWidths
);
4310 // ----------------------------------------------------------------------------
4311 // scanning for an item
4312 // ----------------------------------------------------------------------------
4314 void wxListMainWindow::EnsureVisible( long index
)
4316 wxCHECK_RET( index
>= 0 && (size_t)index
< GetItemCount(),
4317 _T("invalid index in EnsureVisible") );
4319 // We have to call this here because the label in question might just have
4320 // been added and its position is not known yet
4322 RecalculatePositions(true /* no refresh */);
4324 MoveToItem((size_t)index
);
4327 long wxListMainWindow::FindItem(long start
, const wxString
& str
, bool WXUNUSED(partial
) )
4334 size_t count
= GetItemCount();
4335 for ( size_t i
= (size_t)pos
; i
< count
; i
++ )
4337 wxListLineData
*line
= GetLine(i
);
4338 if ( line
->GetText(0) == tmp
)
4345 long wxListMainWindow::FindItem(long start
, wxUIntPtr data
)
4351 size_t count
= GetItemCount();
4352 for (size_t i
= (size_t)pos
; i
< count
; i
++)
4354 wxListLineData
*line
= GetLine(i
);
4356 line
->GetItem( 0, item
);
4357 if (item
.m_data
== data
)
4364 long wxListMainWindow::FindItem( const wxPoint
& pt
)
4367 GetVisibleLinesRange( &topItem
, NULL
);
4370 GetItemPosition( GetItemCount() - 1, p
);
4374 long id
= (long)floor( pt
.y
* double(GetItemCount() - topItem
- 1) / p
.y
+ topItem
);
4375 if ( id
>= 0 && id
< (long)GetItemCount() )
4381 long wxListMainWindow::HitTest( int x
, int y
, int &flags
)
4383 CalcUnscrolledPosition( x
, y
, &x
, &y
);
4385 size_t count
= GetItemCount();
4387 if ( InReportView() )
4389 size_t current
= y
/ GetLineHeight();
4390 if ( current
< count
)
4392 flags
= HitTestLine(current
, x
, y
);
4399 // TODO: optimize it too! this is less simple than for report view but
4400 // enumerating all items is still not a way to do it!!
4401 for ( size_t current
= 0; current
< count
; current
++ )
4403 flags
= HitTestLine(current
, x
, y
);
4412 // ----------------------------------------------------------------------------
4414 // ----------------------------------------------------------------------------
4416 void wxListMainWindow::InsertItem( wxListItem
&item
)
4418 wxASSERT_MSG( !IsVirtual(), _T("can't be used with virtual control") );
4420 int count
= GetItemCount();
4421 wxCHECK_RET( item
.m_itemId
>= 0, _T("invalid item index") );
4423 if (item
.m_itemId
> count
)
4424 item
.m_itemId
= count
;
4426 size_t id
= item
.m_itemId
;
4430 if ( InReportView() )
4432 ResetVisibleLinesRange();
4434 // calculate the width of the item and adjust the max column width
4435 wxColWidthInfo
*pWidthInfo
= m_aColWidths
.Item(item
.GetColumn());
4436 int width
= GetItemWidthWithImage(&item
);
4437 item
.SetWidth(width
);
4438 if (width
> pWidthInfo
->nMaxWidth
)
4439 pWidthInfo
->nMaxWidth
= width
;
4442 wxListLineData
*line
= new wxListLineData(this);
4444 line
->SetItem( item
.m_col
, item
);
4446 m_lines
.Insert( line
, id
);
4450 // If an item is selected at or below the point of insertion, we need to
4451 // increment the member variables because the current row's index has gone
4453 if ( HasCurrent() && m_current
>= id
)
4456 SendNotify(id
, wxEVT_COMMAND_LIST_INSERT_ITEM
);
4458 RefreshLines(id
, GetItemCount() - 1);
4461 void wxListMainWindow::InsertColumn( long col
, wxListItem
&item
)
4464 if ( InReportView() )
4466 if (item
.m_width
== wxLIST_AUTOSIZE_USEHEADER
)
4467 item
.m_width
= GetTextLength( item
.m_text
);
4469 wxListHeaderData
*column
= new wxListHeaderData( item
);
4470 wxColWidthInfo
*colWidthInfo
= new wxColWidthInfo();
4472 bool insert
= (col
>= 0) && ((size_t)col
< m_columns
.GetCount());
4475 wxListHeaderDataList::compatibility_iterator
4476 node
= m_columns
.Item( col
);
4477 m_columns
.Insert( node
, column
);
4478 m_aColWidths
.Insert( colWidthInfo
, col
);
4482 m_columns
.Append( column
);
4483 m_aColWidths
.Add( colWidthInfo
);
4488 // update all the items
4489 for ( size_t i
= 0; i
< m_lines
.GetCount(); i
++ )
4491 wxListLineData
* const line
= GetLine(i
);
4492 wxListItemData
* const data
= new wxListItemData(this);
4494 line
->m_items
.Insert(col
, data
);
4496 line
->m_items
.Append(data
);
4500 // invalidate it as it has to be recalculated
4505 int wxListMainWindow::GetItemWidthWithImage(wxListItem
* item
)
4508 wxClientDC
dc(this);
4510 dc
.SetFont( GetFont() );
4512 if (item
->GetImage() != -1)
4515 GetImageSize( item
->GetImage(), ix
, iy
);
4519 if (!item
->GetText().empty())
4522 dc
.GetTextExtent( item
->GetText(), &w
, NULL
);
4529 // ----------------------------------------------------------------------------
4531 // ----------------------------------------------------------------------------
4533 wxListCtrlCompare list_ctrl_compare_func_2
;
4534 long list_ctrl_compare_data
;
4536 int LINKAGEMODE
list_ctrl_compare_func_1( wxListLineData
**arg1
, wxListLineData
**arg2
)
4538 wxListLineData
*line1
= *arg1
;
4539 wxListLineData
*line2
= *arg2
;
4541 line1
->GetItem( 0, item
);
4542 wxUIntPtr data1
= item
.m_data
;
4543 line2
->GetItem( 0, item
);
4544 wxUIntPtr data2
= item
.m_data
;
4545 return list_ctrl_compare_func_2( data1
, data2
, list_ctrl_compare_data
);
4548 void wxListMainWindow::SortItems( wxListCtrlCompare fn
, long data
)
4550 list_ctrl_compare_func_2
= fn
;
4551 list_ctrl_compare_data
= data
;
4552 m_lines
.Sort( list_ctrl_compare_func_1
);
4556 // ----------------------------------------------------------------------------
4558 // ----------------------------------------------------------------------------
4560 void wxListMainWindow::OnScroll(wxScrollWinEvent
& event
)
4562 // update our idea of which lines are shown when we redraw the window the
4564 ResetVisibleLinesRange();
4567 #if ( defined(__WXGTK__) || defined(__WXMAC__) ) && !defined(__WXUNIVERSAL__)
4568 wxScrolledWindow::OnScroll(event
);
4570 HandleOnScroll( event
);
4573 if ( event
.GetOrientation() == wxHORIZONTAL
&& HasHeader() )
4575 wxGenericListCtrl
* lc
= GetListCtrl();
4576 wxCHECK_RET( lc
, _T("no listctrl window?") );
4578 lc
->m_headerWin
->Refresh();
4579 lc
->m_headerWin
->Update();
4583 int wxListMainWindow::GetCountPerPage() const
4585 if ( !m_linesPerPage
)
4587 wxConstCast(this, wxListMainWindow
)->
4588 m_linesPerPage
= GetClientSize().y
/ GetLineHeight();
4591 return m_linesPerPage
;
4594 void wxListMainWindow::GetVisibleLinesRange(size_t *from
, size_t *to
)
4596 wxASSERT_MSG( InReportView(), _T("this is for report mode only") );
4598 if ( m_lineFrom
== (size_t)-1 )
4600 size_t count
= GetItemCount();
4603 m_lineFrom
= GetScrollPos(wxVERTICAL
);
4605 // this may happen if SetScrollbars() hadn't been called yet
4606 if ( m_lineFrom
>= count
)
4607 m_lineFrom
= count
- 1;
4609 // we redraw one extra line but this is needed to make the redrawing
4610 // logic work when there is a fractional number of lines on screen
4611 m_lineTo
= m_lineFrom
+ m_linesPerPage
;
4612 if ( m_lineTo
>= count
)
4613 m_lineTo
= count
- 1;
4615 else // empty control
4618 m_lineTo
= (size_t)-1;
4622 wxASSERT_MSG( IsEmpty() ||
4623 (m_lineFrom
<= m_lineTo
&& m_lineTo
< GetItemCount()),
4624 _T("GetVisibleLinesRange() returns incorrect result") );
4632 // -------------------------------------------------------------------------------------
4633 // wxGenericListCtrl
4634 // -------------------------------------------------------------------------------------
4636 IMPLEMENT_DYNAMIC_CLASS(wxGenericListCtrl
, wxControl
)
4638 BEGIN_EVENT_TABLE(wxGenericListCtrl
,wxControl
)
4639 EVT_SIZE(wxGenericListCtrl::OnSize
)
4642 wxGenericListCtrl::wxGenericListCtrl()
4644 m_imageListNormal
= (wxImageListType
*) NULL
;
4645 m_imageListSmall
= (wxImageListType
*) NULL
;
4646 m_imageListState
= (wxImageListType
*) NULL
;
4648 m_ownsImageListNormal
=
4649 m_ownsImageListSmall
=
4650 m_ownsImageListState
= false;
4652 m_mainWin
= (wxListMainWindow
*) NULL
;
4653 m_headerWin
= (wxListHeaderWindow
*) NULL
;
4657 wxGenericListCtrl::~wxGenericListCtrl()
4659 if (m_ownsImageListNormal
)
4660 delete m_imageListNormal
;
4661 if (m_ownsImageListSmall
)
4662 delete m_imageListSmall
;
4663 if (m_ownsImageListState
)
4664 delete m_imageListState
;
4667 void wxGenericListCtrl::CalculateAndSetHeaderHeight()
4673 GetThemeMetric( kThemeMetricListHeaderHeight
, &h
);
4675 // we use 'g' to get the descent, too
4677 m_headerWin
->GetTextExtent(wxT("Hg"), &w
, &h
, &d
);
4678 h
+= d
+ 2 * HEADER_OFFSET_Y
+ EXTRA_HEIGHT
;
4681 // only update if changed
4682 if ( h
!= m_headerHeight
)
4686 m_headerWin
->SetSize(m_headerWin
->GetSize().x
, m_headerHeight
);
4689 ResizeReportView(true);
4694 void wxGenericListCtrl::CreateHeaderWindow()
4696 m_headerWin
= new wxListHeaderWindow
4698 this, wxID_ANY
, m_mainWin
,
4700 wxSize(GetClientSize().x
, m_headerHeight
),
4703 CalculateAndSetHeaderHeight();
4706 bool wxGenericListCtrl::Create(wxWindow
*parent
,
4711 const wxValidator
&validator
,
4712 const wxString
&name
)
4716 m_imageListState
= (wxImageListType
*) NULL
;
4717 m_ownsImageListNormal
=
4718 m_ownsImageListSmall
=
4719 m_ownsImageListState
= false;
4721 m_mainWin
= (wxListMainWindow
*) NULL
;
4722 m_headerWin
= (wxListHeaderWindow
*) NULL
;
4726 if ( !(style
& wxLC_MASK_TYPE
) )
4728 style
= style
| wxLC_LIST
;
4731 if ( !wxControl::Create( parent
, id
, pos
, size
, style
, validator
, name
) )
4734 // don't create the inner window with the border
4735 style
&= ~wxBORDER_MASK
;
4737 m_mainWin
= new wxListMainWindow( this, wxID_ANY
, wxPoint(0, 0), size
, style
);
4739 #ifdef __WXMAC_CARBON__
4740 // Human Interface Guidelines ask us for a special font in this case
4741 if ( GetWindowVariant() == wxWINDOW_VARIANT_NORMAL
)
4744 font
.MacCreateThemeFont( kThemeViewsFont
);
4749 if ( InReportView() )
4751 CreateHeaderWindow();
4753 #ifdef __WXMAC_CARBON__
4757 font
.MacCreateThemeFont( kThemeSmallSystemFont
);
4758 m_headerWin
->SetFont( font
);
4759 CalculateAndSetHeaderHeight();
4763 if ( HasFlag(wxLC_NO_HEADER
) )
4764 // VZ: why do we create it at all then?
4765 m_headerWin
->Show( false );
4773 void wxGenericListCtrl::SetSingleStyle( long style
, bool add
)
4775 wxASSERT_MSG( !(style
& wxLC_VIRTUAL
),
4776 _T("wxLC_VIRTUAL can't be [un]set") );
4778 long flag
= GetWindowStyle();
4782 if (style
& wxLC_MASK_TYPE
)
4783 flag
&= ~(wxLC_MASK_TYPE
| wxLC_VIRTUAL
);
4784 if (style
& wxLC_MASK_ALIGN
)
4785 flag
&= ~wxLC_MASK_ALIGN
;
4786 if (style
& wxLC_MASK_SORT
)
4787 flag
&= ~wxLC_MASK_SORT
;
4795 SetWindowStyleFlag( flag
);
4798 void wxGenericListCtrl::SetWindowStyleFlag( long flag
)
4802 m_mainWin
->DeleteEverything();
4804 // has the header visibility changed?
4805 bool hasHeader
= HasHeader();
4806 bool willHaveHeader
= (flag
& wxLC_REPORT
) && !(flag
& wxLC_NO_HEADER
);
4808 if ( hasHeader
!= willHaveHeader
)
4815 // don't delete, just hide, as we can reuse it later
4816 m_headerWin
->Show(false);
4818 //else: nothing to do
4820 else // must show header
4824 CreateHeaderWindow();
4826 else // already have it, just show
4828 m_headerWin
->Show( true );
4832 ResizeReportView(willHaveHeader
);
4836 wxWindow::SetWindowStyleFlag( flag
);
4839 bool wxGenericListCtrl::GetColumn(int col
, wxListItem
&item
) const
4841 m_mainWin
->GetColumn( col
, item
);
4845 bool wxGenericListCtrl::SetColumn( int col
, wxListItem
& item
)
4847 m_mainWin
->SetColumn( col
, item
);
4851 int wxGenericListCtrl::GetColumnWidth( int col
) const
4853 return m_mainWin
->GetColumnWidth( col
);
4856 bool wxGenericListCtrl::SetColumnWidth( int col
, int width
)
4858 m_mainWin
->SetColumnWidth( col
, width
);
4862 int wxGenericListCtrl::GetCountPerPage() const
4864 return m_mainWin
->GetCountPerPage(); // different from Windows ?
4867 bool wxGenericListCtrl::GetItem( wxListItem
&info
) const
4869 m_mainWin
->GetItem( info
);
4873 bool wxGenericListCtrl::SetItem( wxListItem
&info
)
4875 m_mainWin
->SetItem( info
);
4879 long wxGenericListCtrl::SetItem( long index
, int col
, const wxString
& label
, int imageId
)
4882 info
.m_text
= label
;
4883 info
.m_mask
= wxLIST_MASK_TEXT
;
4884 info
.m_itemId
= index
;
4888 info
.m_image
= imageId
;
4889 info
.m_mask
|= wxLIST_MASK_IMAGE
;
4892 m_mainWin
->SetItem(info
);
4896 int wxGenericListCtrl::GetItemState( long item
, long stateMask
) const
4898 return m_mainWin
->GetItemState( item
, stateMask
);
4901 bool wxGenericListCtrl::SetItemState( long item
, long state
, long stateMask
)
4903 m_mainWin
->SetItemState( item
, state
, stateMask
);
4908 wxGenericListCtrl::SetItemImage( long item
, int image
, int WXUNUSED(selImage
) )
4911 info
.m_image
= image
;
4912 info
.m_mask
= wxLIST_MASK_IMAGE
;
4913 info
.m_itemId
= item
;
4914 m_mainWin
->SetItem( info
);
4918 wxString
wxGenericListCtrl::GetItemText( long item
) const
4920 return m_mainWin
->GetItemText(item
);
4923 void wxGenericListCtrl::SetItemText( long item
, const wxString
& str
)
4925 m_mainWin
->SetItemText(item
, str
);
4928 wxUIntPtr
wxGenericListCtrl::GetItemData( long item
) const
4931 info
.m_mask
= wxLIST_MASK_DATA
;
4932 info
.m_itemId
= item
;
4933 m_mainWin
->GetItem( info
);
4937 bool wxGenericListCtrl::SetItemData( long item
, long data
)
4940 info
.m_mask
= wxLIST_MASK_DATA
;
4941 info
.m_itemId
= item
;
4943 m_mainWin
->SetItem( info
);
4947 wxRect
wxGenericListCtrl::GetViewRect() const
4949 return m_mainWin
->GetViewRect();
4952 bool wxGenericListCtrl::GetItemRect( long item
, wxRect
&rect
, int WXUNUSED(code
) ) const
4954 m_mainWin
->GetItemRect( item
, rect
);
4955 if ( m_mainWin
->HasHeader() )
4956 rect
.y
+= m_headerHeight
+ 1;
4960 bool wxGenericListCtrl::GetItemPosition( long item
, wxPoint
& pos
) const
4962 m_mainWin
->GetItemPosition( item
, pos
);
4966 bool wxGenericListCtrl::SetItemPosition( long WXUNUSED(item
), const wxPoint
& WXUNUSED(pos
) )
4971 int wxGenericListCtrl::GetItemCount() const
4973 return m_mainWin
->GetItemCount();
4976 int wxGenericListCtrl::GetColumnCount() const
4978 return m_mainWin
->GetColumnCount();
4981 void wxGenericListCtrl::SetItemSpacing( int spacing
, bool isSmall
)
4983 m_mainWin
->SetItemSpacing( spacing
, isSmall
);
4986 wxSize
wxGenericListCtrl::GetItemSpacing() const
4988 const int spacing
= m_mainWin
->GetItemSpacing(HasFlag(wxLC_SMALL_ICON
));
4990 return wxSize(spacing
, spacing
);
4993 int wxGenericListCtrl::GetItemSpacing( bool isSmall
) const
4995 return m_mainWin
->GetItemSpacing( isSmall
);
4998 void wxGenericListCtrl::SetItemTextColour( long item
, const wxColour
&col
)
5001 info
.m_itemId
= item
;
5002 info
.SetTextColour( col
);
5003 m_mainWin
->SetItem( info
);
5006 wxColour
wxGenericListCtrl::GetItemTextColour( long item
) const
5009 info
.m_itemId
= item
;
5010 m_mainWin
->GetItem( info
);
5011 return info
.GetTextColour();
5014 void wxGenericListCtrl::SetItemBackgroundColour( long item
, const wxColour
&col
)
5017 info
.m_itemId
= item
;
5018 info
.SetBackgroundColour( col
);
5019 m_mainWin
->SetItem( info
);
5022 wxColour
wxGenericListCtrl::GetItemBackgroundColour( long item
) const
5025 info
.m_itemId
= item
;
5026 m_mainWin
->GetItem( info
);
5027 return info
.GetBackgroundColour();
5030 void wxGenericListCtrl::SetItemFont( long item
, const wxFont
&f
)
5033 info
.m_itemId
= item
;
5035 m_mainWin
->SetItem( info
);
5038 wxFont
wxGenericListCtrl::GetItemFont( long item
) const
5041 info
.m_itemId
= item
;
5042 m_mainWin
->GetItem( info
);
5043 return info
.GetFont();
5046 int wxGenericListCtrl::GetSelectedItemCount() const
5048 return m_mainWin
->GetSelectedItemCount();
5051 wxColour
wxGenericListCtrl::GetTextColour() const
5053 return GetForegroundColour();
5056 void wxGenericListCtrl::SetTextColour(const wxColour
& col
)
5058 SetForegroundColour(col
);
5061 long wxGenericListCtrl::GetTopItem() const
5064 m_mainWin
->GetVisibleLinesRange(&top
, NULL
);
5068 long wxGenericListCtrl::GetNextItem( long item
, int geom
, int state
) const
5070 return m_mainWin
->GetNextItem( item
, geom
, state
);
5073 wxImageListType
*wxGenericListCtrl::GetImageList(int which
) const
5075 if (which
== wxIMAGE_LIST_NORMAL
)
5076 return m_imageListNormal
;
5077 else if (which
== wxIMAGE_LIST_SMALL
)
5078 return m_imageListSmall
;
5079 else if (which
== wxIMAGE_LIST_STATE
)
5080 return m_imageListState
;
5082 return (wxImageListType
*) NULL
;
5085 void wxGenericListCtrl::SetImageList( wxImageListType
*imageList
, int which
)
5087 if ( which
== wxIMAGE_LIST_NORMAL
)
5089 if (m_ownsImageListNormal
)
5090 delete m_imageListNormal
;
5091 m_imageListNormal
= imageList
;
5092 m_ownsImageListNormal
= false;
5094 else if ( which
== wxIMAGE_LIST_SMALL
)
5096 if (m_ownsImageListSmall
)
5097 delete m_imageListSmall
;
5098 m_imageListSmall
= imageList
;
5099 m_ownsImageListSmall
= false;
5101 else if ( which
== wxIMAGE_LIST_STATE
)
5103 if (m_ownsImageListState
)
5104 delete m_imageListState
;
5105 m_imageListState
= imageList
;
5106 m_ownsImageListState
= false;
5109 m_mainWin
->SetImageList( imageList
, which
);
5112 void wxGenericListCtrl::AssignImageList(wxImageListType
*imageList
, int which
)
5114 SetImageList(imageList
, which
);
5115 if ( which
== wxIMAGE_LIST_NORMAL
)
5116 m_ownsImageListNormal
= true;
5117 else if ( which
== wxIMAGE_LIST_SMALL
)
5118 m_ownsImageListSmall
= true;
5119 else if ( which
== wxIMAGE_LIST_STATE
)
5120 m_ownsImageListState
= true;
5123 bool wxGenericListCtrl::Arrange( int WXUNUSED(flag
) )
5128 bool wxGenericListCtrl::DeleteItem( long item
)
5130 m_mainWin
->DeleteItem( item
);
5134 bool wxGenericListCtrl::DeleteAllItems()
5136 m_mainWin
->DeleteAllItems();
5140 bool wxGenericListCtrl::DeleteAllColumns()
5142 size_t count
= m_mainWin
->m_columns
.GetCount();
5143 for ( size_t n
= 0; n
< count
; n
++ )
5148 void wxGenericListCtrl::ClearAll()
5150 m_mainWin
->DeleteEverything();
5153 bool wxGenericListCtrl::DeleteColumn( int col
)
5155 m_mainWin
->DeleteColumn( col
);
5157 // if we don't have the header any longer, we need to relayout the window
5158 if ( !GetColumnCount() )
5159 ResizeReportView(false /* no header */);
5163 void wxGenericListCtrl::Edit( long item
)
5165 m_mainWin
->EditLabel( item
);
5168 bool wxGenericListCtrl::EnsureVisible( long item
)
5170 m_mainWin
->EnsureVisible( item
);
5174 long wxGenericListCtrl::FindItem( long start
, const wxString
& str
, bool partial
)
5176 return m_mainWin
->FindItem( start
, str
, partial
);
5179 long wxGenericListCtrl::FindItem( long start
, wxUIntPtr data
)
5181 return m_mainWin
->FindItem( start
, data
);
5184 long wxGenericListCtrl::FindItem( long WXUNUSED(start
), const wxPoint
& pt
,
5185 int WXUNUSED(direction
))
5187 return m_mainWin
->FindItem( pt
);
5190 long wxGenericListCtrl::HitTest( const wxPoint
&point
, int &flags
)
5192 return m_mainWin
->HitTest( (int)point
.x
, (int)point
.y
, flags
);
5195 long wxGenericListCtrl::InsertItem( wxListItem
& info
)
5197 m_mainWin
->InsertItem( info
);
5198 return info
.m_itemId
;
5201 long wxGenericListCtrl::InsertItem( long index
, const wxString
&label
)
5204 info
.m_text
= label
;
5205 info
.m_mask
= wxLIST_MASK_TEXT
;
5206 info
.m_itemId
= index
;
5207 return InsertItem( info
);
5210 long wxGenericListCtrl::InsertItem( long index
, int imageIndex
)
5213 info
.m_mask
= wxLIST_MASK_IMAGE
;
5214 info
.m_image
= imageIndex
;
5215 info
.m_itemId
= index
;
5216 return InsertItem( info
);
5219 long wxGenericListCtrl::InsertItem( long index
, const wxString
&label
, int imageIndex
)
5222 info
.m_text
= label
;
5223 info
.m_image
= imageIndex
;
5224 info
.m_mask
= wxLIST_MASK_TEXT
| wxLIST_MASK_IMAGE
;
5225 info
.m_itemId
= index
;
5226 return InsertItem( info
);
5229 long wxGenericListCtrl::InsertColumn( long col
, wxListItem
&item
)
5231 wxCHECK_MSG( m_headerWin
, -1, _T("can't add column in non report mode") );
5233 m_mainWin
->InsertColumn( col
, item
);
5235 // if we hadn't had a header before but have one now
5236 // then we need to relayout the window
5237 if ( GetColumnCount() == 1 && m_mainWin
->HasHeader() )
5238 ResizeReportView(true /* have header */);
5240 m_headerWin
->Refresh();
5245 long wxGenericListCtrl::InsertColumn( long col
, const wxString
&heading
,
5246 int format
, int width
)
5249 item
.m_mask
= wxLIST_MASK_TEXT
| wxLIST_MASK_FORMAT
;
5250 item
.m_text
= heading
;
5253 item
.m_mask
|= wxLIST_MASK_WIDTH
;
5254 item
.m_width
= width
;
5257 item
.m_format
= format
;
5259 return InsertColumn( col
, item
);
5262 bool wxGenericListCtrl::ScrollList( int WXUNUSED(dx
), int WXUNUSED(dy
) )
5268 // fn is a function which takes 3 long arguments: item1, item2, data.
5269 // item1 is the long data associated with a first item (NOT the index).
5270 // item2 is the long data associated with a second item (NOT the index).
5271 // data is the same value as passed to SortItems.
5272 // The return value is a negative number if the first item should precede the second
5273 // item, a positive number of the second item should precede the first,
5274 // or zero if the two items are equivalent.
5275 // data is arbitrary data to be passed to the sort function.
5277 bool wxGenericListCtrl::SortItems( wxListCtrlCompare fn
, long data
)
5279 m_mainWin
->SortItems( fn
, data
);
5283 // ----------------------------------------------------------------------------
5285 // ----------------------------------------------------------------------------
5287 void wxGenericListCtrl::OnSize(wxSizeEvent
& WXUNUSED(event
))
5292 ResizeReportView(m_mainWin
->HasHeader());
5293 m_mainWin
->RecalculatePositions();
5296 void wxGenericListCtrl::ResizeReportView(bool showHeader
)
5299 GetClientSize( &cw
, &ch
);
5303 m_headerWin
->SetSize( 0, 0, cw
, m_headerHeight
);
5304 m_mainWin
->SetSize( 0, m_headerHeight
+ 1, cw
, ch
- m_headerHeight
- 1 );
5306 else // no header window
5308 m_mainWin
->SetSize( 0, 0, cw
, ch
);
5312 void wxGenericListCtrl::OnInternalIdle()
5314 wxWindow::OnInternalIdle();
5316 // do it only if needed
5317 if ( !m_mainWin
->m_dirty
)
5320 m_mainWin
->RecalculatePositions();
5323 // ----------------------------------------------------------------------------
5325 // ----------------------------------------------------------------------------
5327 bool wxGenericListCtrl::SetBackgroundColour( const wxColour
&colour
)
5331 m_mainWin
->SetBackgroundColour( colour
);
5332 m_mainWin
->m_dirty
= true;
5338 bool wxGenericListCtrl::SetForegroundColour( const wxColour
&colour
)
5340 if ( !wxWindow::SetForegroundColour( colour
) )
5345 m_mainWin
->SetForegroundColour( colour
);
5346 m_mainWin
->m_dirty
= true;
5350 m_headerWin
->SetForegroundColour( colour
);
5355 bool wxGenericListCtrl::SetFont( const wxFont
&font
)
5357 if ( !wxWindow::SetFont( font
) )
5362 m_mainWin
->SetFont( font
);
5363 m_mainWin
->m_dirty
= true;
5368 m_headerWin
->SetFont( font
);
5369 CalculateAndSetHeaderHeight();
5378 #include "wx/listbox.h"
5383 wxGenericListCtrl::GetClassDefaultAttributes(wxWindowVariant variant
)
5386 // Use the same color scheme as wxListBox
5387 return wxListBox::GetClassDefaultAttributes(variant
);
5389 wxUnusedVar(variant
);
5390 wxVisualAttributes attr
;
5391 attr
.colFg
= wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT
);
5392 attr
.colBg
= wxSystemSettings::GetColour(wxSYS_COLOUR_LISTBOX
);
5393 attr
.font
= wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT
);
5398 // ----------------------------------------------------------------------------
5399 // methods forwarded to m_mainWin
5400 // ----------------------------------------------------------------------------
5402 #if wxUSE_DRAG_AND_DROP
5404 void wxGenericListCtrl::SetDropTarget( wxDropTarget
*dropTarget
)
5406 m_mainWin
->SetDropTarget( dropTarget
);
5409 wxDropTarget
*wxGenericListCtrl::GetDropTarget() const
5411 return m_mainWin
->GetDropTarget();
5416 bool wxGenericListCtrl::SetCursor( const wxCursor
&cursor
)
5418 return m_mainWin
? m_mainWin
->wxWindow::SetCursor(cursor
) : false;
5421 wxColour
wxGenericListCtrl::GetBackgroundColour() const
5423 return m_mainWin
? m_mainWin
->GetBackgroundColour() : wxColour();
5426 wxColour
wxGenericListCtrl::GetForegroundColour() const
5428 return m_mainWin
? m_mainWin
->GetForegroundColour() : wxColour();
5431 bool wxGenericListCtrl::DoPopupMenu( wxMenu
*menu
, int x
, int y
)
5434 return m_mainWin
->PopupMenu( menu
, x
, y
);
5440 void wxGenericListCtrl::SetFocus()
5442 // The test in window.cpp fails as we are a composite
5443 // window, so it checks against "this", but not m_mainWin.
5444 if ( DoFindFocus() != this )
5445 m_mainWin
->SetFocus();
5448 wxSize
wxGenericListCtrl::DoGetBestSize() const
5450 // Something is better than nothing...
5451 // 100x80 is what the MSW version will get from the default
5452 // wxControl::DoGetBestSize
5453 return wxSize(100, 80);
5456 // ----------------------------------------------------------------------------
5457 // virtual list control support
5458 // ----------------------------------------------------------------------------
5460 wxString
wxGenericListCtrl::OnGetItemText(long WXUNUSED(item
), long WXUNUSED(col
)) const
5462 // this is a pure virtual function, in fact - which is not really pure
5463 // because the controls which are not virtual don't need to implement it
5464 wxFAIL_MSG( _T("wxGenericListCtrl::OnGetItemText not supposed to be called") );
5466 return wxEmptyString
;
5469 int wxGenericListCtrl::OnGetItemImage(long WXUNUSED(item
)) const
5471 wxCHECK_MSG(!GetImageList(wxIMAGE_LIST_SMALL
),
5473 wxT("List control has an image list, OnGetItemImage or OnGetItemColumnImage should be overridden."));
5477 int wxGenericListCtrl::OnGetItemColumnImage(long item
, long column
) const
5480 return OnGetItemImage(item
);
5486 wxGenericListCtrl::OnGetItemAttr(long WXUNUSED_UNLESS_DEBUG(item
)) const
5488 wxASSERT_MSG( item
>= 0 && item
< GetItemCount(),
5489 _T("invalid item index in OnGetItemAttr()") );
5491 // no attributes by default
5495 void wxGenericListCtrl::SetItemCount(long count
)
5497 wxASSERT_MSG( IsVirtual(), _T("this is for virtual controls only") );
5499 m_mainWin
->SetItemCount(count
);
5502 void wxGenericListCtrl::RefreshItem(long item
)
5504 m_mainWin
->RefreshLine(item
);
5507 void wxGenericListCtrl::RefreshItems(long itemFrom
, long itemTo
)
5509 m_mainWin
->RefreshLines(itemFrom
, itemTo
);
5512 // Generic wxListCtrl is more or less a container for two other
5513 // windows which drawings are done upon. These are namely
5514 // 'm_headerWin' and 'm_mainWin'.
5515 // Here we override 'virtual wxWindow::Refresh()' to mimic the
5516 // behaviour wxListCtrl has under wxMSW.
5518 void wxGenericListCtrl::Refresh(bool eraseBackground
, const wxRect
*rect
)
5522 // The easy case, no rectangle specified.
5524 m_headerWin
->Refresh(eraseBackground
);
5527 m_mainWin
->Refresh(eraseBackground
);
5531 // Refresh the header window
5534 wxRect rectHeader
= m_headerWin
->GetRect();
5535 rectHeader
.Intersect(*rect
);
5536 if (rectHeader
.GetWidth() && rectHeader
.GetHeight())
5539 m_headerWin
->GetPosition(&x
, &y
);
5540 rectHeader
.Offset(-x
, -y
);
5541 m_headerWin
->Refresh(eraseBackground
, &rectHeader
);
5546 // Refresh the main window
5549 wxRect rectMain
= m_mainWin
->GetRect();
5550 rectMain
.Intersect(*rect
);
5551 if (rectMain
.GetWidth() && rectMain
.GetHeight())
5554 m_mainWin
->GetPosition(&x
, &y
);
5555 rectMain
.Offset(-x
, -y
);
5556 m_mainWin
->Refresh(eraseBackground
, &rectMain
);
5562 void wxGenericListCtrl::Freeze()
5564 m_mainWin
->Freeze();
5567 void wxGenericListCtrl::Thaw()
5572 #endif // wxUSE_LISTCTRL