1 /////////////////////////////////////////////////////////////////////////////
2 // Name: generic/listctrl.cpp
3 // Purpose: generic implementation of wxListCtrl
4 // Author: Robert Roebling
5 // Vadim Zeitlin (virtual list control support)
7 // Copyright: (c) 1998 Robert Roebling
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
13 // 1. we need to implement searching/sorting for virtual controls somehow
14 // 2. when changing selection the lines are refreshed twice
17 // For compilers that support precompilation, includes "wx.h".
18 #include "wx/wxprec.h"
28 #include "wx/dynarray.h"
29 #include "wx/dcscreen.h"
30 #include "wx/textctrl.h"
33 // under Win32 we always use the native version and also may use the generic
34 // one, however some things should be done only if we use only the generic
36 #if defined(__WIN32__) && !defined(__WXUNIVERSAL__)
37 #define HAVE_NATIVE_LISTCTRL
40 // if we have the native control, wx/listctrl.h declares it and not this one
41 #ifdef HAVE_NATIVE_LISTCTRL
42 #include "wx/generic/listctrl.h"
43 #else // !HAVE_NATIVE_LISTCTRL
44 #include "wx/listctrl.h"
46 // if we have a native version, its implementation file does all this
47 IMPLEMENT_DYNAMIC_CLASS(wxListItem
, wxObject
)
48 IMPLEMENT_DYNAMIC_CLASS(wxListView
, wxListCtrl
)
49 IMPLEMENT_DYNAMIC_CLASS(wxListEvent
, wxNotifyEvent
)
51 IMPLEMENT_DYNAMIC_CLASS(wxListCtrl
, wxGenericListCtrl
)
52 #endif // HAVE_NATIVE_LISTCTRL/!HAVE_NATIVE_LISTCTRL
54 #include "wx/selstore.h"
55 #include "wx/renderer.h"
59 #include "wx/mac/private.h"
63 // NOTE: If using the wxListBox visual attributes works everywhere then this can
64 // be removed, as well as the #else case below.
65 #define _USE_VISATTR 0
68 // ----------------------------------------------------------------------------
70 // ----------------------------------------------------------------------------
72 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_BEGIN_DRAG
)
73 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_BEGIN_RDRAG
)
74 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_BEGIN_LABEL_EDIT
)
75 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_END_LABEL_EDIT
)
76 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_DELETE_ITEM
)
77 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_DELETE_ALL_ITEMS
)
78 #if WXWIN_COMPATIBILITY_2_4
79 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_GET_INFO
)
80 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_SET_INFO
)
82 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_ITEM_SELECTED
)
83 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_ITEM_DESELECTED
)
84 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_KEY_DOWN
)
85 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_INSERT_ITEM
)
86 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_COL_CLICK
)
87 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_COL_RIGHT_CLICK
)
88 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_COL_BEGIN_DRAG
)
89 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_COL_DRAGGING
)
90 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_COL_END_DRAG
)
91 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_ITEM_RIGHT_CLICK
)
92 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_ITEM_MIDDLE_CLICK
)
93 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_ITEM_ACTIVATED
)
94 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_ITEM_FOCUSED
)
95 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_CACHE_HINT
)
97 // ----------------------------------------------------------------------------
99 // ----------------------------------------------------------------------------
101 // // the height of the header window (FIXME: should depend on its font!)
102 // static const int HEADER_HEIGHT = 23;
104 static const int SCROLL_UNIT_X
= 15;
106 // the spacing between the lines (in report mode)
107 static const int LINE_SPACING
= 0;
109 // extra margins around the text label
110 static const int EXTRA_WIDTH
= 4;
111 static const int EXTRA_HEIGHT
= 4;
113 // margin between the window and the items
114 static const int EXTRA_BORDER_X
= 2;
115 static const int EXTRA_BORDER_Y
= 2;
117 // offset for the header window
118 static const int HEADER_OFFSET_X
= 1;
119 static const int HEADER_OFFSET_Y
= 1;
121 // margin between rows of icons in [small] icon view
122 static const int MARGIN_BETWEEN_ROWS
= 6;
124 // when autosizing the columns, add some slack
125 static const int AUTOSIZE_COL_MARGIN
= 10;
127 // default width for the header columns
128 static const int WIDTH_COL_DEFAULT
= 80;
130 // the space between the image and the text in the report mode
131 static const int IMAGE_MARGIN_IN_REPORT_MODE
= 5;
133 // ============================================================================
135 // ============================================================================
137 //-----------------------------------------------------------------------------
138 // wxColWidthInfo (internal)
139 //-----------------------------------------------------------------------------
141 struct wxColWidthInfo
144 bool bNeedsUpdate
; // only set to true when an item whose
145 // width == nMaxWidth is removed
147 wxColWidthInfo(int w
= 0, bool needsUpdate
= false)
150 bNeedsUpdate
= needsUpdate
;
154 WX_DEFINE_ARRAY_PTR(wxColWidthInfo
*, ColWidthArray
);
156 //-----------------------------------------------------------------------------
157 // wxListItemData (internal)
158 //-----------------------------------------------------------------------------
160 class WXDLLEXPORT wxListItemData
163 wxListItemData(wxListMainWindow
*owner
);
166 void SetItem( const wxListItem
&info
);
167 void SetImage( int image
) { m_image
= image
; }
168 void SetData( wxUIntPtr data
) { m_data
= data
; }
169 void SetPosition( int x
, int y
);
170 void SetSize( int width
, int height
);
172 bool HasText() const { return !m_text
.empty(); }
173 const wxString
& GetText() const { return m_text
; }
174 void SetText(const wxString
& text
) { m_text
= text
; }
176 // we can't use empty string for measuring the string width/height, so
177 // always return something
178 wxString
GetTextForMeasuring() const
180 wxString s
= GetText();
187 bool IsHit( int x
, int y
) const;
191 int GetWidth() const;
192 int GetHeight() const;
194 int GetImage() const { return m_image
; }
195 bool HasImage() const { return GetImage() != -1; }
197 void GetItem( wxListItem
&info
) const;
199 void SetAttr(wxListItemAttr
*attr
) { m_attr
= attr
; }
200 wxListItemAttr
*GetAttr() const { return m_attr
; }
203 // the item image or -1
206 // user data associated with the item
209 // the item coordinates are not used in report mode; instead this pointer is
210 // NULL and the owner window is used to retrieve the item position and size
213 // the list ctrl we are in
214 wxListMainWindow
*m_owner
;
216 // custom attributes or NULL
217 wxListItemAttr
*m_attr
;
220 // common part of all ctors
226 //-----------------------------------------------------------------------------
227 // wxListHeaderData (internal)
228 //-----------------------------------------------------------------------------
230 class WXDLLEXPORT wxListHeaderData
: public wxObject
234 wxListHeaderData( const wxListItem
&info
);
235 void SetItem( const wxListItem
&item
);
236 void SetPosition( int x
, int y
);
237 void SetWidth( int w
);
238 void SetFormat( int format
);
239 void SetHeight( int h
);
240 bool HasImage() const;
242 bool HasText() const { return !m_text
.empty(); }
243 const wxString
& GetText() const { return m_text
; }
244 void SetText(const wxString
& text
) { m_text
= text
; }
246 void GetItem( wxListItem
&item
);
248 bool IsHit( int x
, int y
) const;
249 int GetImage() const;
250 int GetWidth() const;
251 int GetFormat() const;
267 //-----------------------------------------------------------------------------
268 // wxListLineData (internal)
269 //-----------------------------------------------------------------------------
271 WX_DECLARE_LIST(wxListItemData
, wxListItemDataList
);
272 #include "wx/listimpl.cpp"
273 WX_DEFINE_LIST(wxListItemDataList
)
278 // the list of subitems: only may have more than one item in report mode
279 wxListItemDataList m_items
;
281 // this is not used in report view
293 // the part to be highlighted
294 wxRect m_rectHighlight
;
296 // extend all our rects to be centered inside the one of given width
297 void ExtendWidth(wxCoord w
)
299 wxASSERT_MSG( m_rectAll
.width
<= w
,
300 _T("width can only be increased") );
303 m_rectLabel
.x
= m_rectAll
.x
+ (w
- m_rectLabel
.width
) / 2;
304 m_rectIcon
.x
= m_rectAll
.x
+ (w
- m_rectIcon
.width
) / 2;
305 m_rectHighlight
.x
= m_rectAll
.x
+ (w
- m_rectHighlight
.width
) / 2;
310 // is this item selected? [NB: not used in virtual mode]
313 // back pointer to the list ctrl
314 wxListMainWindow
*m_owner
;
317 wxListLineData(wxListMainWindow
*owner
);
321 WX_CLEAR_LIST(wxListItemDataList
, m_items
);
325 // are we in report mode?
326 inline bool InReportView() const;
328 // are we in virtual report mode?
329 inline bool IsVirtual() const;
331 // these 2 methods shouldn't be called for report view controls, in that
332 // case we determine our position/size ourselves
334 // calculate the size of the line
335 void CalculateSize( wxDC
*dc
, int spacing
);
337 // remember the position this line appears at
338 void SetPosition( int x
, int y
, int spacing
);
342 void SetImage( int image
) { SetImage(0, image
); }
343 int GetImage() const { return GetImage(0); }
344 void SetImage( int index
, int image
);
345 int GetImage( int index
) const;
347 bool HasImage() const { return GetImage() != -1; }
348 bool HasText() const { return !GetText(0).empty(); }
350 void SetItem( int index
, const wxListItem
&info
);
351 void GetItem( int index
, wxListItem
&info
);
353 wxString
GetText(int index
) const;
354 void SetText( int index
, const wxString
& s
);
356 wxListItemAttr
*GetAttr() const;
357 void SetAttr(wxListItemAttr
*attr
);
359 // return true if the highlighting really changed
360 bool Highlight( bool on
);
362 void ReverseHighlight();
364 bool IsHighlighted() const
366 wxASSERT_MSG( !IsVirtual(), _T("unexpected call to IsHighlighted") );
368 return m_highlighted
;
371 // draw the line on the given DC in icon/list mode
372 void Draw( wxDC
*dc
);
374 // the same in report mode
375 void DrawInReportMode( wxDC
*dc
,
377 const wxRect
& rectHL
,
381 // set the line to contain num items (only can be > 1 in report mode)
382 void InitItems( int num
);
384 // get the mode (i.e. style) of the list control
385 inline int GetMode() const;
387 // prepare the DC for drawing with these item's attributes, return true if
388 // we need to draw the items background to highlight it, false otherwise
389 bool SetAttributes(wxDC
*dc
,
390 const wxListItemAttr
*attr
,
393 // draw the text on the DC with the correct justification; also add an
394 // ellipsis if the text is too large to fit in the current width
395 void DrawTextFormatted(wxDC
*dc
, const wxString
&text
, int col
, int x
, int y
, int width
);
398 WX_DECLARE_EXPORTED_OBJARRAY(wxListLineData
, wxListLineDataArray
);
399 #include "wx/arrimpl.cpp"
400 WX_DEFINE_OBJARRAY(wxListLineDataArray
)
402 //-----------------------------------------------------------------------------
403 // wxListHeaderWindow (internal)
404 //-----------------------------------------------------------------------------
406 class WXDLLEXPORT wxListHeaderWindow
: public wxWindow
409 wxListMainWindow
*m_owner
;
410 wxCursor
*m_currentCursor
;
411 wxCursor
*m_resizeCursor
;
414 // column being resized or -1
417 // divider line position in logical (unscrolled) coords
420 // minimal position beyond which the divider line
421 // can't be dragged in logical coords
425 wxListHeaderWindow();
427 wxListHeaderWindow( wxWindow
*win
,
429 wxListMainWindow
*owner
,
430 const wxPoint
&pos
= wxDefaultPosition
,
431 const wxSize
&size
= wxDefaultSize
,
433 const wxString
&name
= wxT("wxlistctrlcolumntitles") );
435 virtual ~wxListHeaderWindow();
438 void AdjustDC( wxDC
& dc
);
440 void OnPaint( wxPaintEvent
&event
);
441 void OnMouse( wxMouseEvent
&event
);
442 void OnSetFocus( wxFocusEvent
&event
);
448 // common part of all ctors
451 // generate and process the list event of the given type, return true if
452 // it wasn't vetoed, i.e. if we should proceed
453 bool SendListEvent(wxEventType type
, const wxPoint
& pos
);
455 DECLARE_DYNAMIC_CLASS(wxListHeaderWindow
)
456 DECLARE_EVENT_TABLE()
459 //-----------------------------------------------------------------------------
460 // wxListRenameTimer (internal)
461 //-----------------------------------------------------------------------------
463 class WXDLLEXPORT wxListRenameTimer
: public wxTimer
466 wxListMainWindow
*m_owner
;
469 wxListRenameTimer( wxListMainWindow
*owner
);
473 //-----------------------------------------------------------------------------
474 // wxListTextCtrl (internal)
475 //-----------------------------------------------------------------------------
477 class WXDLLEXPORT wxListTextCtrl
: public wxTextCtrl
480 wxListTextCtrl(wxListMainWindow
*owner
, size_t itemEdit
);
482 void AcceptChangesAndFinish();
485 void OnChar( wxKeyEvent
&event
);
486 void OnKeyUp( wxKeyEvent
&event
);
487 void OnKillFocus( wxFocusEvent
&event
);
489 bool AcceptChanges();
493 wxListMainWindow
*m_owner
;
494 wxString m_startValue
;
497 bool m_aboutToFinish
;
499 DECLARE_EVENT_TABLE()
502 //-----------------------------------------------------------------------------
503 // wxListMainWindow (internal)
504 //-----------------------------------------------------------------------------
506 WX_DECLARE_LIST(wxListHeaderData
, wxListHeaderDataList
);
507 #include "wx/listimpl.cpp"
508 WX_DEFINE_LIST(wxListHeaderDataList
)
510 class wxListMainWindow
: public wxScrolledWindow
514 wxListMainWindow( wxWindow
*parent
,
516 const wxPoint
& pos
= wxDefaultPosition
,
517 const wxSize
& size
= wxDefaultSize
,
519 const wxString
&name
= _T("listctrlmainwindow") );
521 virtual ~wxListMainWindow();
523 wxWindow
*GetMainWindowOfCompositeControl() { return GetParent(); }
525 bool HasFlag(int flag
) const { return m_parent
->HasFlag(flag
); }
527 // return true if this is a virtual list control
528 bool IsVirtual() const { return HasFlag(wxLC_VIRTUAL
); }
530 // return true if the control is in report mode
531 bool InReportView() const { return HasFlag(wxLC_REPORT
); }
533 // return true if we are in single selection mode, false if multi sel
534 bool IsSingleSel() const { return HasFlag(wxLC_SINGLE_SEL
); }
536 // do we have a header window?
537 bool HasHeader() const
538 { return InReportView() && !HasFlag(wxLC_NO_HEADER
); }
540 void HighlightAll( bool on
);
542 // all these functions only do something if the line is currently visible
544 // change the line "selected" state, return true if it really changed
545 bool HighlightLine( size_t line
, bool highlight
= true);
547 // as HighlightLine() but do it for the range of lines: this is incredibly
548 // more efficient for virtual list controls!
550 // NB: unlike HighlightLine() this one does refresh the lines on screen
551 void HighlightLines( size_t lineFrom
, size_t lineTo
, bool on
= true );
553 // toggle the line state and refresh it
554 void ReverseHighlight( size_t line
)
555 { HighlightLine(line
, !IsHighlighted(line
)); RefreshLine(line
); }
557 // return true if the line is highlighted
558 bool IsHighlighted(size_t line
) const;
560 // refresh one or several lines at once
561 void RefreshLine( size_t line
);
562 void RefreshLines( size_t lineFrom
, size_t lineTo
);
564 // refresh all selected items
565 void RefreshSelected();
567 // refresh all lines below the given one: the difference with
568 // RefreshLines() is that the index here might not be a valid one (happens
569 // when the last line is deleted)
570 void RefreshAfter( size_t lineFrom
);
572 // the methods which are forwarded to wxListLineData itself in list/icon
573 // modes but are here because the lines don't store their positions in the
576 // get the bound rect for the entire line
577 wxRect
GetLineRect(size_t line
) const;
579 // get the bound rect of the label
580 wxRect
GetLineLabelRect(size_t line
) const;
582 // get the bound rect of the items icon (only may be called if we do have
584 wxRect
GetLineIconRect(size_t line
) const;
586 // get the rect to be highlighted when the item has focus
587 wxRect
GetLineHighlightRect(size_t line
) const;
589 // get the size of the total line rect
590 wxSize
GetLineSize(size_t line
) const
591 { return GetLineRect(line
).GetSize(); }
593 // return the hit code for the corresponding position (in this line)
594 long HitTestLine(size_t line
, int x
, int y
) const;
596 // bring the selected item into view, scrolling to it if necessary
597 void MoveToItem(size_t item
);
599 // bring the current item into view
600 void MoveToFocus() { MoveToItem(m_current
); }
602 // start editing the label of the given item
603 void EditLabel( long item
);
605 // suspend/resume redrawing the control
609 void OnRenameTimer();
610 bool OnRenameAccept(size_t itemEdit
, const wxString
& value
);
611 void OnRenameCancelled(size_t itemEdit
);
613 void OnMouse( wxMouseEvent
&event
);
615 // called to switch the selection from the current item to newCurrent,
616 void OnArrowChar( size_t newCurrent
, const wxKeyEvent
& event
);
618 void OnChar( wxKeyEvent
&event
);
619 void OnKeyDown( wxKeyEvent
&event
);
620 void OnSetFocus( wxFocusEvent
&event
);
621 void OnKillFocus( wxFocusEvent
&event
);
622 void OnScroll( wxScrollWinEvent
& event
);
624 void OnPaint( wxPaintEvent
&event
);
626 void DrawImage( int index
, wxDC
*dc
, int x
, int y
);
627 void GetImageSize( int index
, int &width
, int &height
) const;
628 int GetTextLength( const wxString
&s
) const;
630 void SetImageList( wxImageListType
*imageList
, int which
);
631 void SetItemSpacing( int spacing
, bool isSmall
= false );
632 int GetItemSpacing( bool isSmall
= false );
634 void SetColumn( int col
, wxListItem
&item
);
635 void SetColumnWidth( int col
, int width
);
636 void GetColumn( int col
, wxListItem
&item
) const;
637 int GetColumnWidth( int col
) const;
638 int GetColumnCount() const { return m_columns
.GetCount(); }
640 // returns the sum of the heights of all columns
641 int GetHeaderWidth() const;
643 int GetCountPerPage() const;
645 void SetItem( wxListItem
&item
);
646 void GetItem( wxListItem
&item
) const;
647 void SetItemState( long item
, long state
, long stateMask
);
648 void SetItemStateAll( long state
, long stateMask
);
649 int GetItemState( long item
, long stateMask
) const;
650 void GetItemRect( long index
, wxRect
&rect
) const;
651 wxRect
GetViewRect() const;
652 bool GetItemPosition( long item
, wxPoint
& pos
) const;
653 int GetSelectedItemCount() const;
655 wxString
GetItemText(long item
) const
658 info
.m_mask
= wxLIST_MASK_TEXT
;
659 info
.m_itemId
= item
;
664 void SetItemText(long item
, const wxString
& value
)
667 info
.m_mask
= wxLIST_MASK_TEXT
;
668 info
.m_itemId
= item
;
673 // set the scrollbars and update the positions of the items
674 void RecalculatePositions(bool noRefresh
= false);
676 // refresh the window and the header
679 long GetNextItem( long item
, int geometry
, int state
) const;
680 void DeleteItem( long index
);
681 void DeleteAllItems();
682 void DeleteColumn( int col
);
683 void DeleteEverything();
684 void EnsureVisible( long index
);
685 long FindItem( long start
, const wxString
& str
, bool partial
= false );
686 long FindItem( long start
, wxUIntPtr data
);
687 long FindItem( const wxPoint
& pt
);
688 long HitTest( int x
, int y
, int &flags
);
689 void InsertItem( wxListItem
&item
);
690 void InsertColumn( long col
, wxListItem
&item
);
691 int GetItemWidthWithImage(wxListItem
* item
);
692 void SortItems( wxListCtrlCompare fn
, long data
);
694 size_t GetItemCount() const;
695 bool IsEmpty() const { return GetItemCount() == 0; }
696 void SetItemCount(long count
);
698 // change the current (== focused) item, send a notification event
699 void ChangeCurrent(size_t current
);
700 void ResetCurrent() { ChangeCurrent((size_t)-1); }
701 bool HasCurrent() const { return m_current
!= (size_t)-1; }
703 // send out a wxListEvent
704 void SendNotify( size_t line
,
706 const wxPoint
& point
= wxDefaultPosition
);
708 // override base class virtual to reset m_lineHeight when the font changes
709 virtual bool SetFont(const wxFont
& font
)
711 if ( !wxScrolledWindow::SetFont(font
) )
719 // these are for wxListLineData usage only
721 // get the backpointer to the list ctrl
722 wxGenericListCtrl
*GetListCtrl() const
724 return wxStaticCast(GetParent(), wxGenericListCtrl
);
727 // get the height of all lines (assuming they all do have the same height)
728 wxCoord
GetLineHeight() const;
730 // get the y position of the given line (only for report view)
731 wxCoord
GetLineY(size_t line
) const;
733 // get the brush to use for the item highlighting
734 wxBrush
*GetHighlightBrush() const
736 return m_hasFocus
? m_highlightBrush
: m_highlightUnfocusedBrush
;
740 // the array of all line objects for a non virtual list control (for the
741 // virtual list control we only ever use m_lines[0])
742 wxListLineDataArray m_lines
;
744 // the list of column objects
745 wxListHeaderDataList m_columns
;
747 // currently focused item or -1
750 // the number of lines per page
753 // this flag is set when something which should result in the window
754 // redrawing happens (i.e. an item was added or deleted, or its appearance
755 // changed) and OnPaint() doesn't redraw the window while it is set which
756 // allows to minimize the number of repaintings when a lot of items are
757 // being added. The real repainting occurs only after the next OnIdle()
761 wxColour
*m_highlightColour
;
762 wxImageListType
*m_small_image_list
;
763 wxImageListType
*m_normal_image_list
;
765 int m_normal_spacing
;
769 wxTimer
*m_renameTimer
;
773 ColWidthArray m_aColWidths
;
775 // for double click logic
776 size_t m_lineLastClicked
,
777 m_lineBeforeLastClicked
,
778 m_lineSelectSingleOnUp
;
780 wxListTextCtrl
* m_textctrl
;
783 // the total count of items in a virtual list control
786 // the object maintaining the items selection state, only used in virtual
788 wxSelectionStore m_selStore
;
790 // common part of all ctors
793 // get the line data for the given index
794 wxListLineData
*GetLine(size_t n
) const
796 wxASSERT_MSG( n
!= (size_t)-1, _T("invalid line index") );
800 wxConstCast(this, wxListMainWindow
)->CacheLineData(n
);
807 // get a dummy line which can be used for geometry calculations and such:
808 // you must use GetLine() if you want to really draw the line
809 wxListLineData
*GetDummyLine() const;
811 // cache the line data of the n-th line in m_lines[0]
812 void CacheLineData(size_t line
);
814 // get the range of visible lines
815 void GetVisibleLinesRange(size_t *from
, size_t *to
);
817 // force us to recalculate the range of visible lines
818 void ResetVisibleLinesRange() { m_lineFrom
= (size_t)-1; }
820 // get the colour to be used for drawing the rules
821 wxColour
GetRuleColour() const
823 return wxSystemSettings::GetColour(wxSYS_COLOUR_3DLIGHT
);
827 // initialize the current item if needed
828 void UpdateCurrent();
830 // delete all items but don't refresh: called from dtor
831 void DoDeleteAllItems();
833 // the height of one line using the current font
834 wxCoord m_lineHeight
;
836 // the total header width or 0 if not calculated yet
837 wxCoord m_headerWidth
;
839 // the first and last lines being shown on screen right now (inclusive),
840 // both may be -1 if they must be calculated so never access them directly:
841 // use GetVisibleLinesRange() above instead
845 // the brushes to use for item highlighting when we do/don't have focus
846 wxBrush
*m_highlightBrush
,
847 *m_highlightUnfocusedBrush
;
849 // if this is > 0, the control is frozen and doesn't redraw itself
850 size_t m_freezeCount
;
852 DECLARE_DYNAMIC_CLASS(wxListMainWindow
)
853 DECLARE_EVENT_TABLE()
855 friend class wxGenericListCtrl
;
859 wxListItemData::~wxListItemData()
861 // in the virtual list control the attributes are managed by the main
862 // program, so don't delete them
863 if ( !m_owner
->IsVirtual() )
869 void wxListItemData::Init()
877 wxListItemData::wxListItemData(wxListMainWindow
*owner
)
883 if ( owner
->InReportView() )
889 void wxListItemData::SetItem( const wxListItem
&info
)
891 if ( info
.m_mask
& wxLIST_MASK_TEXT
)
892 SetText(info
.m_text
);
893 if ( info
.m_mask
& wxLIST_MASK_IMAGE
)
894 m_image
= info
.m_image
;
895 if ( info
.m_mask
& wxLIST_MASK_DATA
)
896 m_data
= info
.m_data
;
898 if ( info
.HasAttributes() )
901 *m_attr
= *info
.GetAttributes();
903 m_attr
= new wxListItemAttr(*info
.GetAttributes());
911 m_rect
->width
= info
.m_width
;
915 void wxListItemData::SetPosition( int x
, int y
)
917 wxCHECK_RET( m_rect
, _T("unexpected SetPosition() call") );
923 void wxListItemData::SetSize( int width
, int height
)
925 wxCHECK_RET( m_rect
, _T("unexpected SetSize() call") );
928 m_rect
->width
= width
;
930 m_rect
->height
= height
;
933 bool wxListItemData::IsHit( int x
, int y
) const
935 wxCHECK_MSG( m_rect
, false, _T("can't be called in this mode") );
937 return wxRect(GetX(), GetY(), GetWidth(), GetHeight()).Inside(x
, y
);
940 int wxListItemData::GetX() const
942 wxCHECK_MSG( m_rect
, 0, _T("can't be called in this mode") );
947 int wxListItemData::GetY() const
949 wxCHECK_MSG( m_rect
, 0, _T("can't be called in this mode") );
954 int wxListItemData::GetWidth() const
956 wxCHECK_MSG( m_rect
, 0, _T("can't be called in this mode") );
958 return m_rect
->width
;
961 int wxListItemData::GetHeight() const
963 wxCHECK_MSG( m_rect
, 0, _T("can't be called in this mode") );
965 return m_rect
->height
;
968 void wxListItemData::GetItem( wxListItem
&info
) const
970 long mask
= info
.m_mask
;
972 // by default, get everything for backwards compatibility
975 if ( mask
& wxLIST_MASK_TEXT
)
976 info
.m_text
= m_text
;
977 if ( mask
& wxLIST_MASK_IMAGE
)
978 info
.m_image
= m_image
;
979 if ( mask
& wxLIST_MASK_DATA
)
980 info
.m_data
= m_data
;
984 if ( m_attr
->HasTextColour() )
985 info
.SetTextColour(m_attr
->GetTextColour());
986 if ( m_attr
->HasBackgroundColour() )
987 info
.SetBackgroundColour(m_attr
->GetBackgroundColour());
988 if ( m_attr
->HasFont() )
989 info
.SetFont(m_attr
->GetFont());
993 //-----------------------------------------------------------------------------
995 //-----------------------------------------------------------------------------
997 void wxListHeaderData::Init()
1008 wxListHeaderData::wxListHeaderData()
1013 wxListHeaderData::wxListHeaderData( const wxListItem
&item
)
1020 void wxListHeaderData::SetItem( const wxListItem
&item
)
1022 m_mask
= item
.m_mask
;
1024 if ( m_mask
& wxLIST_MASK_TEXT
)
1025 m_text
= item
.m_text
;
1027 if ( m_mask
& wxLIST_MASK_IMAGE
)
1028 m_image
= item
.m_image
;
1030 if ( m_mask
& wxLIST_MASK_FORMAT
)
1031 m_format
= item
.m_format
;
1033 if ( m_mask
& wxLIST_MASK_WIDTH
)
1034 SetWidth(item
.m_width
);
1037 void wxListHeaderData::SetPosition( int x
, int y
)
1043 void wxListHeaderData::SetHeight( int h
)
1048 void wxListHeaderData::SetWidth( int w
)
1050 m_width
= w
< 0 ? WIDTH_COL_DEFAULT
: w
;
1053 void wxListHeaderData::SetFormat( int format
)
1058 bool wxListHeaderData::HasImage() const
1060 return m_image
!= -1;
1063 bool wxListHeaderData::IsHit( int x
, int y
) const
1065 return ((x
>= m_xpos
) && (x
<= m_xpos
+m_width
) && (y
>= m_ypos
) && (y
<= m_ypos
+m_height
));
1068 void wxListHeaderData::GetItem( wxListItem
& item
)
1070 item
.m_mask
= m_mask
;
1071 item
.m_text
= m_text
;
1072 item
.m_image
= m_image
;
1073 item
.m_format
= m_format
;
1074 item
.m_width
= m_width
;
1077 int wxListHeaderData::GetImage() const
1082 int wxListHeaderData::GetWidth() const
1087 int wxListHeaderData::GetFormat() const
1092 //-----------------------------------------------------------------------------
1094 //-----------------------------------------------------------------------------
1096 inline int wxListLineData::GetMode() const
1098 return m_owner
->GetListCtrl()->GetWindowStyleFlag() & wxLC_MASK_TYPE
;
1101 inline bool wxListLineData::InReportView() const
1103 return m_owner
->HasFlag(wxLC_REPORT
);
1106 inline bool wxListLineData::IsVirtual() const
1108 return m_owner
->IsVirtual();
1111 wxListLineData::wxListLineData( wxListMainWindow
*owner
)
1115 if ( InReportView() )
1118 m_gi
= new GeometryInfo
;
1120 m_highlighted
= false;
1122 InitItems( GetMode() == wxLC_REPORT
? m_owner
->GetColumnCount() : 1 );
1125 void wxListLineData::CalculateSize( wxDC
*dc
, int spacing
)
1127 wxListItemDataList::compatibility_iterator node
= m_items
.GetFirst();
1128 wxCHECK_RET( node
, _T("no subitems at all??") );
1130 wxListItemData
*item
= node
->GetData();
1135 switch ( GetMode() )
1138 case wxLC_SMALL_ICON
:
1139 m_gi
->m_rectAll
.width
= spacing
;
1141 s
= item
->GetText();
1146 m_gi
->m_rectLabel
.width
=
1147 m_gi
->m_rectLabel
.height
= 0;
1151 dc
->GetTextExtent( s
, &lw
, &lh
);
1155 m_gi
->m_rectAll
.height
= spacing
+ lh
;
1157 m_gi
->m_rectAll
.width
= lw
;
1159 m_gi
->m_rectLabel
.width
= lw
;
1160 m_gi
->m_rectLabel
.height
= lh
;
1163 if (item
->HasImage())
1166 m_owner
->GetImageSize( item
->GetImage(), w
, h
);
1167 m_gi
->m_rectIcon
.width
= w
+ 8;
1168 m_gi
->m_rectIcon
.height
= h
+ 8;
1170 if ( m_gi
->m_rectIcon
.width
> m_gi
->m_rectAll
.width
)
1171 m_gi
->m_rectAll
.width
= m_gi
->m_rectIcon
.width
;
1172 if ( m_gi
->m_rectIcon
.height
+ lh
> m_gi
->m_rectAll
.height
- 4 )
1173 m_gi
->m_rectAll
.height
= m_gi
->m_rectIcon
.height
+ lh
+ 4;
1176 if ( item
->HasText() )
1178 m_gi
->m_rectHighlight
.width
= m_gi
->m_rectLabel
.width
;
1179 m_gi
->m_rectHighlight
.height
= m_gi
->m_rectLabel
.height
;
1181 else // no text, highlight the icon
1183 m_gi
->m_rectHighlight
.width
= m_gi
->m_rectIcon
.width
;
1184 m_gi
->m_rectHighlight
.height
= m_gi
->m_rectIcon
.height
;
1189 s
= item
->GetTextForMeasuring();
1191 dc
->GetTextExtent( s
, &lw
, &lh
);
1195 m_gi
->m_rectLabel
.width
= lw
;
1196 m_gi
->m_rectLabel
.height
= lh
;
1198 m_gi
->m_rectAll
.width
= lw
;
1199 m_gi
->m_rectAll
.height
= lh
;
1201 if (item
->HasImage())
1204 m_owner
->GetImageSize( item
->GetImage(), w
, h
);
1205 m_gi
->m_rectIcon
.width
= w
;
1206 m_gi
->m_rectIcon
.height
= h
;
1208 m_gi
->m_rectAll
.width
+= 4 + w
;
1209 if (h
> m_gi
->m_rectAll
.height
)
1210 m_gi
->m_rectAll
.height
= h
;
1213 m_gi
->m_rectHighlight
.width
= m_gi
->m_rectAll
.width
;
1214 m_gi
->m_rectHighlight
.height
= m_gi
->m_rectAll
.height
;
1218 wxFAIL_MSG( _T("unexpected call to SetSize") );
1222 wxFAIL_MSG( _T("unknown mode") );
1227 void wxListLineData::SetPosition( int x
, int y
, int spacing
)
1229 wxListItemDataList::compatibility_iterator node
= m_items
.GetFirst();
1230 wxCHECK_RET( node
, _T("no subitems at all??") );
1232 wxListItemData
*item
= node
->GetData();
1234 switch ( GetMode() )
1237 case wxLC_SMALL_ICON
:
1238 m_gi
->m_rectAll
.x
= x
;
1239 m_gi
->m_rectAll
.y
= y
;
1241 if ( item
->HasImage() )
1243 m_gi
->m_rectIcon
.x
= m_gi
->m_rectAll
.x
+ 4 +
1244 (m_gi
->m_rectAll
.width
- m_gi
->m_rectIcon
.width
) / 2;
1245 m_gi
->m_rectIcon
.y
= m_gi
->m_rectAll
.y
+ 4;
1248 if ( item
->HasText() )
1250 if (m_gi
->m_rectAll
.width
> spacing
)
1251 m_gi
->m_rectLabel
.x
= m_gi
->m_rectAll
.x
+ 2;
1253 m_gi
->m_rectLabel
.x
= m_gi
->m_rectAll
.x
+ 2 + (spacing
/ 2) - (m_gi
->m_rectLabel
.width
/ 2);
1254 m_gi
->m_rectLabel
.y
= m_gi
->m_rectAll
.y
+ m_gi
->m_rectAll
.height
+ 2 - m_gi
->m_rectLabel
.height
;
1255 m_gi
->m_rectHighlight
.x
= m_gi
->m_rectLabel
.x
- 2;
1256 m_gi
->m_rectHighlight
.y
= m_gi
->m_rectLabel
.y
- 2;
1258 else // no text, highlight the icon
1260 m_gi
->m_rectHighlight
.x
= m_gi
->m_rectIcon
.x
- 4;
1261 m_gi
->m_rectHighlight
.y
= m_gi
->m_rectIcon
.y
- 4;
1266 m_gi
->m_rectAll
.x
= x
;
1267 m_gi
->m_rectAll
.y
= y
;
1269 m_gi
->m_rectHighlight
.x
= m_gi
->m_rectAll
.x
;
1270 m_gi
->m_rectHighlight
.y
= m_gi
->m_rectAll
.y
;
1271 m_gi
->m_rectLabel
.y
= m_gi
->m_rectAll
.y
+ 2;
1273 if (item
->HasImage())
1275 m_gi
->m_rectIcon
.x
= m_gi
->m_rectAll
.x
+ 2;
1276 m_gi
->m_rectIcon
.y
= m_gi
->m_rectAll
.y
+ 2;
1277 m_gi
->m_rectLabel
.x
= m_gi
->m_rectAll
.x
+ 6 + m_gi
->m_rectIcon
.width
;
1281 m_gi
->m_rectLabel
.x
= m_gi
->m_rectAll
.x
+ 2;
1286 wxFAIL_MSG( _T("unexpected call to SetPosition") );
1290 wxFAIL_MSG( _T("unknown mode") );
1295 void wxListLineData::InitItems( int num
)
1297 for (int i
= 0; i
< num
; i
++)
1298 m_items
.Append( new wxListItemData(m_owner
) );
1301 void wxListLineData::SetItem( int index
, const wxListItem
&info
)
1303 wxListItemDataList::compatibility_iterator node
= m_items
.Item( index
);
1304 wxCHECK_RET( node
, _T("invalid column index in SetItem") );
1306 wxListItemData
*item
= node
->GetData();
1307 item
->SetItem( info
);
1310 void wxListLineData::GetItem( int index
, wxListItem
&info
)
1312 wxListItemDataList::compatibility_iterator node
= m_items
.Item( index
);
1315 wxListItemData
*item
= node
->GetData();
1316 item
->GetItem( info
);
1320 wxString
wxListLineData::GetText(int index
) const
1324 wxListItemDataList::compatibility_iterator node
= m_items
.Item( index
);
1327 wxListItemData
*item
= node
->GetData();
1328 s
= item
->GetText();
1334 void wxListLineData::SetText( int index
, const wxString
& s
)
1336 wxListItemDataList::compatibility_iterator node
= m_items
.Item( index
);
1339 wxListItemData
*item
= node
->GetData();
1344 void wxListLineData::SetImage( int index
, int image
)
1346 wxListItemDataList::compatibility_iterator node
= m_items
.Item( index
);
1347 wxCHECK_RET( node
, _T("invalid column index in SetImage()") );
1349 wxListItemData
*item
= node
->GetData();
1350 item
->SetImage(image
);
1353 int wxListLineData::GetImage( int index
) const
1355 wxListItemDataList::compatibility_iterator node
= m_items
.Item( index
);
1356 wxCHECK_MSG( node
, -1, _T("invalid column index in GetImage()") );
1358 wxListItemData
*item
= node
->GetData();
1359 return item
->GetImage();
1362 wxListItemAttr
*wxListLineData::GetAttr() const
1364 wxListItemDataList::compatibility_iterator node
= m_items
.GetFirst();
1365 wxCHECK_MSG( node
, NULL
, _T("invalid column index in GetAttr()") );
1367 wxListItemData
*item
= node
->GetData();
1368 return item
->GetAttr();
1371 void wxListLineData::SetAttr(wxListItemAttr
*attr
)
1373 wxListItemDataList::compatibility_iterator node
= m_items
.GetFirst();
1374 wxCHECK_RET( node
, _T("invalid column index in SetAttr()") );
1376 wxListItemData
*item
= node
->GetData();
1377 item
->SetAttr(attr
);
1380 bool wxListLineData::SetAttributes(wxDC
*dc
,
1381 const wxListItemAttr
*attr
,
1384 wxWindow
*listctrl
= m_owner
->GetParent();
1388 // don't use foreground colour for drawing highlighted items - this might
1389 // make them completely invisible (and there is no way to do bit
1390 // arithmetics on wxColour, unfortunately)
1393 colText
= wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHTTEXT
);
1394 else if ( attr
&& attr
->HasTextColour() )
1395 colText
= attr
->GetTextColour();
1397 colText
= listctrl
->GetForegroundColour();
1399 dc
->SetTextForeground(colText
);
1403 if ( attr
&& attr
->HasFont() )
1404 font
= attr
->GetFont();
1406 font
= listctrl
->GetFont();
1411 bool hasBgCol
= attr
&& attr
->HasBackgroundColour();
1412 if ( highlighted
|| hasBgCol
)
1415 dc
->SetBrush( *m_owner
->GetHighlightBrush() );
1417 dc
->SetBrush(wxBrush(attr
->GetBackgroundColour(), wxSOLID
));
1419 dc
->SetPen( *wxTRANSPARENT_PEN
);
1427 void wxListLineData::Draw( wxDC
*dc
)
1429 wxListItemDataList::compatibility_iterator node
= m_items
.GetFirst();
1430 wxCHECK_RET( node
, _T("no subitems at all??") );
1432 bool highlighted
= IsHighlighted();
1434 wxListItemAttr
*attr
= GetAttr();
1436 if ( SetAttributes(dc
, attr
, highlighted
) )
1437 dc
->DrawRectangle( m_gi
->m_rectHighlight
);
1439 // just for debugging to better see where the items are
1441 dc
->SetPen(*wxRED_PEN
);
1442 dc
->SetBrush(*wxTRANSPARENT_BRUSH
);
1443 dc
->DrawRectangle( m_gi
->m_rectAll
);
1444 dc
->SetPen(*wxGREEN_PEN
);
1445 dc
->DrawRectangle( m_gi
->m_rectIcon
);
1448 wxListItemData
*item
= node
->GetData();
1449 if (item
->HasImage())
1451 // centre the image inside our rectangle, this looks nicer when items
1452 // ae aligned in a row
1453 const wxRect
& rectIcon
= m_gi
->m_rectIcon
;
1455 m_owner
->DrawImage(item
->GetImage(), dc
, rectIcon
.x
, rectIcon
.y
);
1458 if (item
->HasText())
1460 const wxRect
& rectLabel
= m_gi
->m_rectLabel
;
1462 wxDCClipper
clipper(*dc
, rectLabel
);
1463 dc
->DrawText(item
->GetText(), rectLabel
.x
, rectLabel
.y
);
1467 void wxListLineData::DrawInReportMode( wxDC
*dc
,
1469 const wxRect
& rectHL
,
1472 // TODO: later we should support setting different attributes for
1473 // different columns - to do it, just add "col" argument to
1474 // GetAttr() and move these lines into the loop below
1475 wxListItemAttr
*attr
= GetAttr();
1476 if ( SetAttributes(dc
, attr
, highlighted
) )
1477 dc
->DrawRectangle( rectHL
);
1479 wxCoord x
= rect
.x
+ HEADER_OFFSET_X
,
1480 y
= rect
.y
+ (LINE_SPACING
+ EXTRA_HEIGHT
) / 2;
1483 for ( wxListItemDataList::compatibility_iterator node
= m_items
.GetFirst();
1485 node
= node
->GetNext(), col
++ )
1487 wxListItemData
*item
= node
->GetData();
1489 int width
= m_owner
->GetColumnWidth(col
);
1493 if ( item
->HasImage() )
1496 m_owner
->DrawImage( item
->GetImage(), dc
, xOld
, y
);
1497 m_owner
->GetImageSize( item
->GetImage(), ix
, iy
);
1499 ix
+= IMAGE_MARGIN_IN_REPORT_MODE
;
1505 wxDCClipper
clipper(*dc
, xOld
, y
, width
- 8, rect
.height
);
1507 if ( item
->HasText() )
1508 DrawTextFormatted(dc
, item
->GetText(), col
, xOld
, y
, width
- 8);
1512 void wxListLineData::DrawTextFormatted(wxDC
*dc
,
1513 const wxString
&text
,
1519 wxString drawntext
, ellipsis
;
1520 wxCoord w
, h
, base_w
;
1523 // determine if the string can fit inside the current width
1524 dc
->GetTextExtent(text
, &w
, &h
);
1527 // it can, draw it using the items alignment
1528 m_owner
->GetColumn(col
, item
);
1529 switch ( item
.GetAlign() )
1531 case wxLIST_FORMAT_LEFT
:
1535 case wxLIST_FORMAT_RIGHT
:
1539 case wxLIST_FORMAT_CENTER
:
1540 x
+= (width
- w
) / 2;
1544 wxFAIL_MSG( _T("unknown list item format") );
1548 dc
->DrawText(text
, x
, y
);
1550 else // otherwise, truncate and add an ellipsis if possible
1552 // determine the base width
1553 ellipsis
= wxString(wxT("..."));
1554 dc
->GetTextExtent(ellipsis
, &base_w
, &h
);
1556 // continue until we have enough space or only one character left
1558 size_t len
= text
.Length();
1559 drawntext
= text
.Left(len
);
1562 dc
->GetTextExtent(drawntext
.Last(), &w_c
, &h_c
);
1563 drawntext
.RemoveLast();
1566 if (w
+ base_w
<= width
)
1570 // if still not enough space, remove ellipsis characters
1571 while (ellipsis
.Length() > 0 && w
+ base_w
> width
)
1573 ellipsis
= ellipsis
.Left(ellipsis
.Length() - 1);
1574 dc
->GetTextExtent(ellipsis
, &base_w
, &h
);
1577 // now draw the text
1578 dc
->DrawText(drawntext
, x
, y
);
1579 dc
->DrawText(ellipsis
, x
+ w
, y
);
1583 bool wxListLineData::Highlight( bool on
)
1585 wxCHECK_MSG( !IsVirtual(), false, _T("unexpected call to Highlight") );
1587 if ( on
== m_highlighted
)
1595 void wxListLineData::ReverseHighlight( void )
1597 Highlight(!IsHighlighted());
1600 //-----------------------------------------------------------------------------
1601 // wxListHeaderWindow
1602 //-----------------------------------------------------------------------------
1604 IMPLEMENT_DYNAMIC_CLASS(wxListHeaderWindow
,wxWindow
)
1606 BEGIN_EVENT_TABLE(wxListHeaderWindow
,wxWindow
)
1607 EVT_PAINT (wxListHeaderWindow::OnPaint
)
1608 EVT_MOUSE_EVENTS (wxListHeaderWindow::OnMouse
)
1609 EVT_SET_FOCUS (wxListHeaderWindow::OnSetFocus
)
1612 void wxListHeaderWindow::Init()
1614 m_currentCursor
= (wxCursor
*) NULL
;
1615 m_isDragging
= false;
1619 wxListHeaderWindow::wxListHeaderWindow()
1623 m_owner
= (wxListMainWindow
*) NULL
;
1624 m_resizeCursor
= (wxCursor
*) NULL
;
1627 wxListHeaderWindow::wxListHeaderWindow( wxWindow
*win
,
1629 wxListMainWindow
*owner
,
1633 const wxString
&name
)
1634 : wxWindow( win
, id
, pos
, size
, style
, name
)
1639 m_resizeCursor
= new wxCursor( wxCURSOR_SIZEWE
);
1642 wxVisualAttributes attr
= wxPanel::GetClassDefaultAttributes();
1643 SetOwnForegroundColour( attr
.colFg
);
1644 SetOwnBackgroundColour( attr
.colBg
);
1646 SetOwnFont( attr
.font
);
1648 SetOwnForegroundColour( wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT
));
1649 SetOwnBackgroundColour( wxSystemSettings::GetColour(wxSYS_COLOUR_BTNFACE
));
1651 SetOwnFont( wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT
));
1655 wxListHeaderWindow::~wxListHeaderWindow()
1657 delete m_resizeCursor
;
1660 #ifdef __WXUNIVERSAL__
1661 #include "wx/univ/renderer.h"
1662 #include "wx/univ/theme.h"
1665 // shift the DC origin to match the position of the main window horz
1666 // scrollbar: this allows us to always use logical coords
1667 void wxListHeaderWindow::AdjustDC(wxDC
& dc
)
1670 m_owner
->GetScrollPixelsPerUnit( &xpix
, NULL
);
1673 m_owner
->GetViewStart( &x
, NULL
);
1675 // account for the horz scrollbar offset
1676 dc
.SetDeviceOrigin( -x
* xpix
, 0 );
1679 void wxListHeaderWindow::OnPaint( wxPaintEvent
&WXUNUSED(event
) )
1681 wxPaintDC
dc( this );
1688 dc
.SetFont( GetFont() );
1690 // width and height of the entire header window
1692 GetClientSize( &w
, &h
);
1693 m_owner
->CalcUnscrolledPosition(w
, 0, &w
, NULL
);
1695 dc
.SetBackgroundMode(wxTRANSPARENT
);
1696 dc
.SetTextForeground(GetForegroundColour());
1698 int x
= HEADER_OFFSET_X
;
1699 int numColumns
= m_owner
->GetColumnCount();
1701 for ( int i
= 0; i
< numColumns
&& x
< w
; i
++ )
1703 m_owner
->GetColumn( i
, item
);
1704 int wCol
= item
.m_width
;
1706 // the width of the rect to draw: make it smaller to fit entirely
1707 // inside the column rect
1716 wxRendererNative::Get().DrawHeaderButton
1720 wxRect(x
, HEADER_OFFSET_Y
, cw
, ch
),
1721 m_parent
->IsEnabled() ? 0
1722 : (int)wxCONTROL_DISABLED
1725 // see if we have enough space for the column label
1727 // for this we need the width of the text
1730 dc
.GetTextExtent(item
.GetText(), &wLabel
, &hLabel
);
1731 wLabel
+= 2 * EXTRA_WIDTH
;
1733 // and the width of the icon, if any
1734 static const int MARGIN_BETWEEN_TEXT_AND_ICON
= 2;
1735 int ix
= 0, iy
= 0; // init them just to suppress the compiler warnings
1736 const int image
= item
.m_image
;
1737 wxImageListType
*imageList
;
1740 imageList
= m_owner
->m_small_image_list
;
1743 imageList
->GetSize(image
, ix
, iy
);
1744 wLabel
+= ix
+ MARGIN_BETWEEN_TEXT_AND_ICON
;
1752 // ignore alignment if there is not enough space anyhow
1754 switch ( wLabel
< cw
? item
.GetAlign() : wxLIST_FORMAT_LEFT
)
1757 wxFAIL_MSG( _T("unknown list item format") );
1760 case wxLIST_FORMAT_LEFT
:
1764 case wxLIST_FORMAT_RIGHT
:
1765 xAligned
= x
+ cw
- wLabel
;
1768 case wxLIST_FORMAT_CENTER
:
1769 xAligned
= x
+ (cw
- wLabel
) / 2;
1773 // if we have an image, draw it on the right of the label
1780 xAligned
+ wLabel
- ix
- MARGIN_BETWEEN_TEXT_AND_ICON
,
1781 HEADER_OFFSET_Y
+ (h
- 4 - iy
)/2,
1782 wxIMAGELIST_DRAW_TRANSPARENT
1785 cw
-= ix
+ MARGIN_BETWEEN_TEXT_AND_ICON
;
1788 // draw the text clipping it so that it doesn't overwrite the column
1790 wxDCClipper
clipper(dc
, x
, HEADER_OFFSET_Y
, cw
, h
- 4 );
1792 dc
.DrawText( item
.GetText(),
1793 xAligned
+ EXTRA_WIDTH
, h
/ 2 - hLabel
/ 2 ); //HEADER_OFFSET_Y + EXTRA_HEIGHT );
1801 void wxListHeaderWindow::DrawCurrent()
1803 int x1
= m_currentX
;
1805 m_owner
->ClientToScreen( &x1
, &y1
);
1807 int x2
= m_currentX
;
1809 m_owner
->GetClientSize( NULL
, &y2
);
1810 m_owner
->ClientToScreen( &x2
, &y2
);
1813 dc
.SetLogicalFunction( wxINVERT
);
1814 dc
.SetPen( wxPen( *wxBLACK
, 2, wxSOLID
) );
1815 dc
.SetBrush( *wxTRANSPARENT_BRUSH
);
1819 dc
.DrawLine( x1
, y1
, x2
, y2
);
1821 dc
.SetLogicalFunction( wxCOPY
);
1823 dc
.SetPen( wxNullPen
);
1824 dc
.SetBrush( wxNullBrush
);
1827 void wxListHeaderWindow::OnMouse( wxMouseEvent
&event
)
1829 // we want to work with logical coords
1831 m_owner
->CalcUnscrolledPosition(event
.GetX(), 0, &x
, NULL
);
1832 int y
= event
.GetY();
1836 SendListEvent(wxEVT_COMMAND_LIST_COL_DRAGGING
, event
.GetPosition());
1838 // we don't draw the line beyond our window, but we allow dragging it
1841 GetClientSize( &w
, NULL
);
1842 m_owner
->CalcUnscrolledPosition(w
, 0, &w
, NULL
);
1845 // erase the line if it was drawn
1846 if ( m_currentX
< w
)
1849 if (event
.ButtonUp())
1852 m_isDragging
= false;
1854 m_owner
->SetColumnWidth( m_column
, m_currentX
- m_minX
);
1855 SendListEvent(wxEVT_COMMAND_LIST_COL_END_DRAG
, event
.GetPosition());
1862 m_currentX
= m_minX
+ 7;
1864 // draw in the new location
1865 if ( m_currentX
< w
)
1869 else // not dragging
1872 bool hit_border
= false;
1874 // end of the current column
1877 // find the column where this event occurred
1879 countCol
= m_owner
->GetColumnCount();
1880 for (col
= 0; col
< countCol
; col
++)
1882 xpos
+= m_owner
->GetColumnWidth( col
);
1885 if ( (abs(x
-xpos
) < 3) && (y
< 22) )
1887 // near the column border
1894 // inside the column
1901 if ( col
== countCol
)
1904 if (event
.LeftDown() || event
.RightUp())
1906 if (hit_border
&& event
.LeftDown())
1908 if ( SendListEvent(wxEVT_COMMAND_LIST_COL_BEGIN_DRAG
,
1909 event
.GetPosition()) )
1911 m_isDragging
= true;
1916 //else: column resizing was vetoed by the user code
1918 else // click on a column
1920 SendListEvent( event
.LeftDown()
1921 ? wxEVT_COMMAND_LIST_COL_CLICK
1922 : wxEVT_COMMAND_LIST_COL_RIGHT_CLICK
,
1923 event
.GetPosition());
1926 else if (event
.Moving())
1931 setCursor
= m_currentCursor
== wxSTANDARD_CURSOR
;
1932 m_currentCursor
= m_resizeCursor
;
1936 setCursor
= m_currentCursor
!= wxSTANDARD_CURSOR
;
1937 m_currentCursor
= wxSTANDARD_CURSOR
;
1941 SetCursor(*m_currentCursor
);
1946 void wxListHeaderWindow::OnSetFocus( wxFocusEvent
&WXUNUSED(event
) )
1948 m_owner
->SetFocus();
1952 bool wxListHeaderWindow::SendListEvent(wxEventType type
, const wxPoint
& pos
)
1954 wxWindow
*parent
= GetParent();
1955 wxListEvent
le( type
, parent
->GetId() );
1956 le
.SetEventObject( parent
);
1957 le
.m_pointDrag
= pos
;
1959 // the position should be relative to the parent window, not
1960 // this one for compatibility with MSW and common sense: the
1961 // user code doesn't know anything at all about this header
1962 // window, so why should it get positions relative to it?
1963 le
.m_pointDrag
.y
-= GetSize().y
;
1965 le
.m_col
= m_column
;
1966 return !parent
->GetEventHandler()->ProcessEvent( le
) || le
.IsAllowed();
1969 //-----------------------------------------------------------------------------
1970 // wxListRenameTimer (internal)
1971 //-----------------------------------------------------------------------------
1973 wxListRenameTimer::wxListRenameTimer( wxListMainWindow
*owner
)
1978 void wxListRenameTimer::Notify()
1980 m_owner
->OnRenameTimer();
1983 //-----------------------------------------------------------------------------
1984 // wxListTextCtrl (internal)
1985 //-----------------------------------------------------------------------------
1987 BEGIN_EVENT_TABLE(wxListTextCtrl
,wxTextCtrl
)
1988 EVT_CHAR (wxListTextCtrl::OnChar
)
1989 EVT_KEY_UP (wxListTextCtrl::OnKeyUp
)
1990 EVT_KILL_FOCUS (wxListTextCtrl::OnKillFocus
)
1993 wxListTextCtrl::wxListTextCtrl(wxListMainWindow
*owner
, size_t itemEdit
)
1994 : m_startValue(owner
->GetItemText(itemEdit
)),
1995 m_itemEdited(itemEdit
)
1999 m_aboutToFinish
= false;
2001 wxRect rectLabel
= owner
->GetLineLabelRect(itemEdit
);
2003 m_owner
->CalcScrolledPosition(rectLabel
.x
, rectLabel
.y
,
2004 &rectLabel
.x
, &rectLabel
.y
);
2006 (void)Create(owner
, wxID_ANY
, m_startValue
,
2007 wxPoint(rectLabel
.x
-4,rectLabel
.y
-4),
2008 wxSize(rectLabel
.width
+11,rectLabel
.height
+8));
2011 void wxListTextCtrl::Finish()
2015 wxPendingDelete
.Append(this);
2016 m_owner
->m_textctrl
= NULL
;
2020 m_owner
->SetFocusIgnoringChildren();
2024 bool wxListTextCtrl::AcceptChanges()
2026 const wxString value
= GetValue();
2028 if ( value
== m_startValue
)
2029 // nothing changed, always accept
2032 if ( !m_owner
->OnRenameAccept(m_itemEdited
, value
) )
2033 // vetoed by the user
2036 // accepted, do rename the item
2037 m_owner
->SetItemText(m_itemEdited
, value
);
2042 void wxListTextCtrl::AcceptChangesAndFinish()
2044 m_aboutToFinish
= true;
2046 // Notify the owner about the changes
2049 // Even if vetoed, close the control (consistent with MSW)
2053 void wxListTextCtrl::OnChar( wxKeyEvent
&event
)
2055 switch ( event
.m_keyCode
)
2058 AcceptChangesAndFinish();
2063 m_owner
->OnRenameCancelled( m_itemEdited
);
2071 void wxListTextCtrl::OnKeyUp( wxKeyEvent
&event
)
2079 // auto-grow the textctrl:
2080 wxSize parentSize
= m_owner
->GetSize();
2081 wxPoint myPos
= GetPosition();
2082 wxSize mySize
= GetSize();
2084 GetTextExtent(GetValue() + _T("MM"), &sx
, &sy
);
2085 if (myPos
.x
+ sx
> parentSize
.x
)
2086 sx
= parentSize
.x
- myPos
.x
;
2089 SetSize(sx
, wxDefaultCoord
);
2094 void wxListTextCtrl::OnKillFocus( wxFocusEvent
&event
)
2096 if ( !m_finished
&& !m_aboutToFinish
)
2098 // We must finish regardless of success, otherwise we'll get
2102 if ( !AcceptChanges() )
2103 m_owner
->OnRenameCancelled( m_itemEdited
);
2106 // We must let the native text control handle focus, too, otherwise
2107 // it could have problems with the cursor (e.g., in wxGTK).
2111 //-----------------------------------------------------------------------------
2113 //-----------------------------------------------------------------------------
2115 IMPLEMENT_DYNAMIC_CLASS(wxListMainWindow
,wxScrolledWindow
)
2117 BEGIN_EVENT_TABLE(wxListMainWindow
,wxScrolledWindow
)
2118 EVT_PAINT (wxListMainWindow::OnPaint
)
2119 EVT_MOUSE_EVENTS (wxListMainWindow::OnMouse
)
2120 EVT_CHAR (wxListMainWindow::OnChar
)
2121 EVT_KEY_DOWN (wxListMainWindow::OnKeyDown
)
2122 EVT_SET_FOCUS (wxListMainWindow::OnSetFocus
)
2123 EVT_KILL_FOCUS (wxListMainWindow::OnKillFocus
)
2124 EVT_SCROLLWIN (wxListMainWindow::OnScroll
)
2127 void wxListMainWindow::Init()
2132 m_lineTo
= (size_t)-1;
2138 m_small_image_list
= (wxImageListType
*) NULL
;
2139 m_normal_image_list
= (wxImageListType
*) NULL
;
2141 m_small_spacing
= 30;
2142 m_normal_spacing
= 40;
2146 m_isCreated
= false;
2148 m_lastOnSame
= false;
2149 m_renameTimer
= new wxListRenameTimer( this );
2154 m_lineSelectSingleOnUp
=
2155 m_lineBeforeLastClicked
= (size_t)-1;
2160 wxListMainWindow::wxListMainWindow()
2165 m_highlightUnfocusedBrush
= (wxBrush
*) NULL
;
2168 wxListMainWindow::wxListMainWindow( wxWindow
*parent
,
2173 const wxString
&name
)
2174 : wxScrolledWindow( parent
, id
, pos
, size
,
2175 style
| wxHSCROLL
| wxVSCROLL
, name
)
2179 m_highlightBrush
= new wxBrush
2181 wxSystemSettings::GetColour
2183 wxSYS_COLOUR_HIGHLIGHT
2188 m_highlightUnfocusedBrush
= new wxBrush
2190 wxSystemSettings::GetColour
2192 wxSYS_COLOUR_BTNSHADOW
2197 SetScrollbars( 0, 0, 0, 0, 0, 0 );
2199 wxVisualAttributes attr
= wxGenericListCtrl::GetClassDefaultAttributes();
2200 SetOwnForegroundColour( attr
.colFg
);
2201 SetOwnBackgroundColour( attr
.colBg
);
2203 SetOwnFont( attr
.font
);
2206 wxListMainWindow::~wxListMainWindow()
2209 WX_CLEAR_LIST(wxListHeaderDataList
, m_columns
);
2210 WX_CLEAR_ARRAY(m_aColWidths
);
2212 delete m_highlightBrush
;
2213 delete m_highlightUnfocusedBrush
;
2214 delete m_renameTimer
;
2217 void wxListMainWindow::CacheLineData(size_t line
)
2219 wxGenericListCtrl
*listctrl
= GetListCtrl();
2221 wxListLineData
*ld
= GetDummyLine();
2223 size_t countCol
= GetColumnCount();
2224 for ( size_t col
= 0; col
< countCol
; col
++ )
2226 ld
->SetText(col
, listctrl
->OnGetItemText(line
, col
));
2227 ld
->SetImage(col
, listctrl
->OnGetItemColumnImage(line
, col
));
2230 ld
->SetAttr(listctrl
->OnGetItemAttr(line
));
2233 wxListLineData
*wxListMainWindow::GetDummyLine() const
2235 wxASSERT_MSG( !IsEmpty(), _T("invalid line index") );
2236 wxASSERT_MSG( IsVirtual(), _T("GetDummyLine() shouldn't be called") );
2238 wxListMainWindow
*self
= wxConstCast(this, wxListMainWindow
);
2240 // we need to recreate the dummy line if the number of columns in the
2241 // control changed as it would have the incorrect number of fields
2243 if ( !m_lines
.IsEmpty() &&
2244 m_lines
[0].m_items
.GetCount() != (size_t)GetColumnCount() )
2246 self
->m_lines
.Clear();
2249 if ( m_lines
.IsEmpty() )
2251 wxListLineData
*line
= new wxListLineData(self
);
2252 self
->m_lines
.Add(line
);
2254 // don't waste extra memory -- there never going to be anything
2255 // else/more in this array
2256 self
->m_lines
.Shrink();
2262 // ----------------------------------------------------------------------------
2263 // line geometry (report mode only)
2264 // ----------------------------------------------------------------------------
2266 wxCoord
wxListMainWindow::GetLineHeight() const
2268 // we cache the line height as calling GetTextExtent() is slow
2269 if ( !m_lineHeight
)
2271 wxListMainWindow
*self
= wxConstCast(this, wxListMainWindow
);
2273 wxClientDC
dc( self
);
2274 dc
.SetFont( GetFont() );
2277 dc
.GetTextExtent(_T("H"), NULL
, &y
);
2279 if ( m_small_image_list
&& m_small_image_list
->GetImageCount() )
2282 m_small_image_list
->GetSize(0, iw
, ih
);
2287 self
->m_lineHeight
= y
+ LINE_SPACING
;
2290 return m_lineHeight
;
2293 wxCoord
wxListMainWindow::GetLineY(size_t line
) const
2295 wxASSERT_MSG( InReportView(), _T("only works in report mode") );
2297 return LINE_SPACING
+ line
* GetLineHeight();
2300 wxRect
wxListMainWindow::GetLineRect(size_t line
) const
2302 if ( !InReportView() )
2303 return GetLine(line
)->m_gi
->m_rectAll
;
2306 rect
.x
= HEADER_OFFSET_X
;
2307 rect
.y
= GetLineY(line
);
2308 rect
.width
= GetHeaderWidth();
2309 rect
.height
= GetLineHeight();
2314 wxRect
wxListMainWindow::GetLineLabelRect(size_t line
) const
2316 if ( !InReportView() )
2317 return GetLine(line
)->m_gi
->m_rectLabel
;
2320 rect
.x
= HEADER_OFFSET_X
;
2321 rect
.y
= GetLineY(line
);
2322 rect
.width
= GetColumnWidth(0);
2323 rect
.height
= GetLineHeight();
2328 wxRect
wxListMainWindow::GetLineIconRect(size_t line
) const
2330 if ( !InReportView() )
2331 return GetLine(line
)->m_gi
->m_rectIcon
;
2333 wxListLineData
*ld
= GetLine(line
);
2334 wxASSERT_MSG( ld
->HasImage(), _T("should have an image") );
2337 rect
.x
= HEADER_OFFSET_X
;
2338 rect
.y
= GetLineY(line
);
2339 GetImageSize(ld
->GetImage(), rect
.width
, rect
.height
);
2344 wxRect
wxListMainWindow::GetLineHighlightRect(size_t line
) const
2346 return InReportView() ? GetLineRect(line
)
2347 : GetLine(line
)->m_gi
->m_rectHighlight
;
2350 long wxListMainWindow::HitTestLine(size_t line
, int x
, int y
) const
2352 wxASSERT_MSG( line
< GetItemCount(), _T("invalid line in HitTestLine") );
2354 wxListLineData
*ld
= GetLine(line
);
2356 if ( ld
->HasImage() && GetLineIconRect(line
).Inside(x
, y
) )
2357 return wxLIST_HITTEST_ONITEMICON
;
2359 // VS: Testing for "ld->HasText() || InReportView()" instead of
2360 // "ld->HasText()" is needed to make empty lines in report view
2362 if ( ld
->HasText() || InReportView() )
2364 wxRect rect
= InReportView() ? GetLineRect(line
)
2365 : GetLineLabelRect(line
);
2367 if ( rect
.Inside(x
, y
) )
2368 return wxLIST_HITTEST_ONITEMLABEL
;
2374 // ----------------------------------------------------------------------------
2375 // highlight (selection) handling
2376 // ----------------------------------------------------------------------------
2378 bool wxListMainWindow::IsHighlighted(size_t line
) const
2382 return m_selStore
.IsSelected(line
);
2386 wxListLineData
*ld
= GetLine(line
);
2387 wxCHECK_MSG( ld
, false, _T("invalid index in IsHighlighted") );
2389 return ld
->IsHighlighted();
2393 void wxListMainWindow::HighlightLines( size_t lineFrom
,
2399 wxArrayInt linesChanged
;
2400 if ( !m_selStore
.SelectRange(lineFrom
, lineTo
, highlight
,
2403 // meny items changed state, refresh everything
2404 RefreshLines(lineFrom
, lineTo
);
2406 else // only a few items changed state, refresh only them
2408 size_t count
= linesChanged
.GetCount();
2409 for ( size_t n
= 0; n
< count
; n
++ )
2411 RefreshLine(linesChanged
[n
]);
2415 else // iterate over all items in non report view
2417 for ( size_t line
= lineFrom
; line
<= lineTo
; line
++ )
2419 if ( HighlightLine(line
, highlight
) )
2425 bool wxListMainWindow::HighlightLine( size_t line
, bool highlight
)
2431 changed
= m_selStore
.SelectItem(line
, highlight
);
2435 wxListLineData
*ld
= GetLine(line
);
2436 wxCHECK_MSG( ld
, false, _T("invalid index in HighlightLine") );
2438 changed
= ld
->Highlight(highlight
);
2443 SendNotify( line
, highlight
? wxEVT_COMMAND_LIST_ITEM_SELECTED
2444 : wxEVT_COMMAND_LIST_ITEM_DESELECTED
);
2450 void wxListMainWindow::RefreshLine( size_t line
)
2452 if ( InReportView() )
2454 size_t visibleFrom
, visibleTo
;
2455 GetVisibleLinesRange(&visibleFrom
, &visibleTo
);
2457 if ( line
< visibleFrom
|| line
> visibleTo
)
2461 wxRect rect
= GetLineRect(line
);
2463 CalcScrolledPosition( rect
.x
, rect
.y
, &rect
.x
, &rect
.y
);
2464 RefreshRect( rect
);
2467 void wxListMainWindow::RefreshLines( size_t lineFrom
, size_t lineTo
)
2469 // we suppose that they are ordered by caller
2470 wxASSERT_MSG( lineFrom
<= lineTo
, _T("indices in disorder") );
2472 wxASSERT_MSG( lineTo
< GetItemCount(), _T("invalid line range") );
2474 if ( InReportView() )
2476 size_t visibleFrom
, visibleTo
;
2477 GetVisibleLinesRange(&visibleFrom
, &visibleTo
);
2479 if ( lineFrom
< visibleFrom
)
2480 lineFrom
= visibleFrom
;
2481 if ( lineTo
> visibleTo
)
2486 rect
.y
= GetLineY(lineFrom
);
2487 rect
.width
= GetClientSize().x
;
2488 rect
.height
= GetLineY(lineTo
) - rect
.y
+ GetLineHeight();
2490 CalcScrolledPosition( rect
.x
, rect
.y
, &rect
.x
, &rect
.y
);
2491 RefreshRect( rect
);
2495 // TODO: this should be optimized...
2496 for ( size_t line
= lineFrom
; line
<= lineTo
; line
++ )
2503 void wxListMainWindow::RefreshAfter( size_t lineFrom
)
2505 if ( InReportView() )
2507 size_t visibleFrom
, visibleTo
;
2508 GetVisibleLinesRange(&visibleFrom
, &visibleTo
);
2510 if ( lineFrom
< visibleFrom
)
2511 lineFrom
= visibleFrom
;
2512 else if ( lineFrom
> visibleTo
)
2517 rect
.y
= GetLineY(lineFrom
);
2518 CalcScrolledPosition( rect
.x
, rect
.y
, &rect
.x
, &rect
.y
);
2520 wxSize size
= GetClientSize();
2521 rect
.width
= size
.x
;
2523 // refresh till the bottom of the window
2524 rect
.height
= size
.y
- rect
.y
;
2526 RefreshRect( rect
);
2530 // TODO: how to do it more efficiently?
2535 void wxListMainWindow::RefreshSelected()
2541 if ( InReportView() )
2543 GetVisibleLinesRange(&from
, &to
);
2548 to
= GetItemCount() - 1;
2551 if ( HasCurrent() && m_current
>= from
&& m_current
<= to
)
2552 RefreshLine(m_current
);
2554 for ( size_t line
= from
; line
<= to
; line
++ )
2556 // NB: the test works as expected even if m_current == -1
2557 if ( line
!= m_current
&& IsHighlighted(line
) )
2562 void wxListMainWindow::Freeze()
2567 void wxListMainWindow::Thaw()
2569 wxCHECK_RET( m_freezeCount
> 0, _T("thawing unfrozen list control?") );
2571 if ( !--m_freezeCount
)
2575 void wxListMainWindow::OnPaint( wxPaintEvent
&WXUNUSED(event
) )
2577 // Note: a wxPaintDC must be constructed even if no drawing is
2578 // done (a Windows requirement).
2579 wxPaintDC
dc( this );
2581 if ( IsEmpty() || m_freezeCount
)
2582 // nothing to draw or not the moment to draw it
2586 // delay the repainting until we calculate all the items positions
2592 CalcScrolledPosition( 0, 0, &dev_x
, &dev_y
);
2596 dc
.SetFont( GetFont() );
2598 if ( InReportView() )
2600 int lineHeight
= GetLineHeight();
2602 size_t visibleFrom
, visibleTo
;
2603 GetVisibleLinesRange(&visibleFrom
, &visibleTo
);
2606 wxCoord xOrig
, yOrig
;
2607 CalcUnscrolledPosition(0, 0, &xOrig
, &yOrig
);
2609 // tell the caller cache to cache the data
2612 wxListEvent
evCache(wxEVT_COMMAND_LIST_CACHE_HINT
,
2613 GetParent()->GetId());
2614 evCache
.SetEventObject( GetParent() );
2615 evCache
.m_oldItemIndex
= visibleFrom
;
2616 evCache
.m_itemIndex
= visibleTo
;
2617 GetParent()->GetEventHandler()->ProcessEvent( evCache
);
2620 for ( size_t line
= visibleFrom
; line
<= visibleTo
; line
++ )
2622 rectLine
= GetLineRect(line
);
2624 if ( !IsExposed(rectLine
.x
- xOrig
, rectLine
.y
- yOrig
,
2625 rectLine
.width
, rectLine
.height
) )
2627 // don't redraw unaffected lines to avoid flicker
2631 GetLine(line
)->DrawInReportMode( &dc
,
2633 GetLineHighlightRect(line
),
2634 IsHighlighted(line
) );
2637 if ( HasFlag(wxLC_HRULES
) )
2639 wxPen
pen(GetRuleColour(), 1, wxSOLID
);
2640 wxSize clientSize
= GetClientSize();
2642 // Don't draw the first one
2643 for ( size_t i
= visibleFrom
+ 1; i
<= visibleTo
; i
++ )
2646 dc
.SetBrush( *wxTRANSPARENT_BRUSH
);
2647 dc
.DrawLine(0 - dev_x
, i
* lineHeight
,
2648 clientSize
.x
- dev_x
, i
* lineHeight
);
2651 // Draw last horizontal rule
2652 if ( visibleTo
== GetItemCount() - 1 )
2655 dc
.SetBrush( *wxTRANSPARENT_BRUSH
);
2656 dc
.DrawLine(0 - dev_x
, (m_lineTo
+ 1) * lineHeight
,
2657 clientSize
.x
- dev_x
, (m_lineTo
+ 1) * lineHeight
);
2661 // Draw vertical rules if required
2662 if ( HasFlag(wxLC_VRULES
) && !IsEmpty() )
2664 wxPen
pen(GetRuleColour(), 1, wxSOLID
);
2665 wxRect firstItemRect
, lastItemRect
;
2667 GetItemRect(visibleFrom
, firstItemRect
);
2668 GetItemRect(visibleTo
, lastItemRect
);
2669 int x
= firstItemRect
.GetX();
2671 dc
.SetBrush(* wxTRANSPARENT_BRUSH
);
2673 for (int col
= 0; col
< GetColumnCount(); col
++)
2675 int colWidth
= GetColumnWidth(col
);
2677 dc
.DrawLine(x
- dev_x
- 2, firstItemRect
.GetY() - 1 - dev_y
,
2678 x
- dev_x
- 2, lastItemRect
.GetBottom() + 1 - dev_y
);
2684 size_t count
= GetItemCount();
2685 for ( size_t i
= 0; i
< count
; i
++ )
2687 GetLine(i
)->Draw( &dc
);
2692 // Don't draw rect outline under Mac at all.
2697 dc
.SetPen( *wxBLACK_PEN
);
2698 dc
.SetBrush( *wxTRANSPARENT_BRUSH
);
2699 dc
.DrawRectangle( GetLineHighlightRect( m_current
) );
2707 void wxListMainWindow::HighlightAll( bool on
)
2709 if ( IsSingleSel() )
2711 wxASSERT_MSG( !on
, _T("can't do this in a single selection control") );
2713 // we just have one item to turn off
2714 if ( HasCurrent() && IsHighlighted(m_current
) )
2716 HighlightLine(m_current
, false);
2717 RefreshLine(m_current
);
2722 HighlightLines(0, GetItemCount() - 1, on
);
2726 void wxListMainWindow::SendNotify( size_t line
,
2727 wxEventType command
,
2728 const wxPoint
& point
)
2730 wxListEvent
le( command
, GetParent()->GetId() );
2731 le
.SetEventObject( GetParent() );
2732 le
.m_itemIndex
= line
;
2734 // set only for events which have position
2735 if ( point
!= wxDefaultPosition
)
2736 le
.m_pointDrag
= point
;
2738 // don't try to get the line info for virtual list controls: the main
2739 // program has it anyhow and if we did it would result in accessing all
2740 // the lines, even those which are not visible now and this is precisely
2741 // what we're trying to avoid
2742 if ( !IsVirtual() && (command
!= wxEVT_COMMAND_LIST_DELETE_ITEM
) )
2744 if ( line
!= (size_t)-1 )
2746 GetLine(line
)->GetItem( 0, le
.m_item
);
2748 //else: this happens for wxEVT_COMMAND_LIST_ITEM_FOCUSED event
2750 //else: there may be no more such item
2752 GetParent()->GetEventHandler()->ProcessEvent( le
);
2755 void wxListMainWindow::ChangeCurrent(size_t current
)
2757 m_current
= current
;
2759 SendNotify(current
, wxEVT_COMMAND_LIST_ITEM_FOCUSED
);
2762 void wxListMainWindow::EditLabel( long item
)
2764 wxCHECK_RET( (item
>= 0) && ((size_t)item
< GetItemCount()),
2765 wxT("wrong index in wxGenericListCtrl::EditLabel()") );
2767 size_t itemEdit
= (size_t)item
;
2769 wxListEvent
le( wxEVT_COMMAND_LIST_BEGIN_LABEL_EDIT
, GetParent()->GetId() );
2770 le
.SetEventObject( GetParent() );
2771 le
.m_itemIndex
= item
;
2772 wxListLineData
*data
= GetLine(itemEdit
);
2773 wxCHECK_RET( data
, _T("invalid index in EditLabel()") );
2774 data
->GetItem( 0, le
.m_item
);
2776 if ( GetParent()->GetEventHandler()->ProcessEvent( le
) && !le
.IsAllowed() )
2777 // vetoed by user code
2780 // We have to call this here because the label in question might just have
2781 // been added and no screen update taken place.
2785 m_textctrl
= new wxListTextCtrl(this, itemEdit
);
2786 m_textctrl
->SetFocus();
2789 void wxListMainWindow::OnRenameTimer()
2791 wxCHECK_RET( HasCurrent(), wxT("unexpected rename timer") );
2793 EditLabel( m_current
);
2796 bool wxListMainWindow::OnRenameAccept(size_t itemEdit
, const wxString
& value
)
2798 wxListEvent
le( wxEVT_COMMAND_LIST_END_LABEL_EDIT
, GetParent()->GetId() );
2799 le
.SetEventObject( GetParent() );
2800 le
.m_itemIndex
= itemEdit
;
2802 wxListLineData
*data
= GetLine(itemEdit
);
2804 wxCHECK_MSG( data
, false, _T("invalid index in OnRenameAccept()") );
2806 data
->GetItem( 0, le
.m_item
);
2807 le
.m_item
.m_text
= value
;
2808 return !GetParent()->GetEventHandler()->ProcessEvent( le
) ||
2812 void wxListMainWindow::OnRenameCancelled(size_t itemEdit
)
2814 // let owner know that the edit was cancelled
2815 wxListEvent
le( wxEVT_COMMAND_LIST_END_LABEL_EDIT
, GetParent()->GetId() );
2817 le
.SetEditCanceled(true);
2819 le
.SetEventObject( GetParent() );
2820 le
.m_itemIndex
= itemEdit
;
2822 wxListLineData
*data
= GetLine(itemEdit
);
2823 wxCHECK_RET( data
, _T("invalid index in OnRenameCancelled()") );
2825 data
->GetItem( 0, le
.m_item
);
2826 GetEventHandler()->ProcessEvent( le
);
2829 void wxListMainWindow::OnMouse( wxMouseEvent
&event
)
2832 // On wxMac we can't depend on the EVT_KILL_FOCUS event to properly
2833 // shutdown the edit control when the mouse is clicked elsewhere on the
2834 // listctrl because the order of events is different (or something like
2835 // that), so explicitly end the edit if it is active.
2836 if ( event
.LeftDown() && m_textctrl
)
2837 m_textctrl
->AcceptChangesAndFinish();
2840 event
.SetEventObject( GetParent() );
2841 if ( GetParent()->GetEventHandler()->ProcessEvent( event
) )
2844 if (event
.GetEventType() == wxEVT_MOUSEWHEEL
)
2846 // let the base handle mouse wheel events.
2851 if ( !HasCurrent() || IsEmpty() )
2857 if ( !(event
.Dragging() || event
.ButtonDown() || event
.LeftUp() ||
2858 event
.ButtonDClick()) )
2861 int x
= event
.GetX();
2862 int y
= event
.GetY();
2863 CalcUnscrolledPosition( x
, y
, &x
, &y
);
2865 // where did we hit it (if we did)?
2868 size_t count
= GetItemCount(),
2871 if ( InReportView() )
2873 current
= y
/ GetLineHeight();
2874 if ( current
< count
)
2875 hitResult
= HitTestLine(current
, x
, y
);
2879 // TODO: optimize it too! this is less simple than for report view but
2880 // enumerating all items is still not a way to do it!!
2881 for ( current
= 0; current
< count
; current
++ )
2883 hitResult
= HitTestLine(current
, x
, y
);
2889 if (event
.Dragging())
2891 if (m_dragCount
== 0)
2893 // we have to report the raw, physical coords as we want to be
2894 // able to call HitTest(event.m_pointDrag) from the user code to
2895 // get the item being dragged
2896 m_dragStart
= event
.GetPosition();
2901 if (m_dragCount
!= 3)
2904 int command
= event
.RightIsDown() ? wxEVT_COMMAND_LIST_BEGIN_RDRAG
2905 : wxEVT_COMMAND_LIST_BEGIN_DRAG
;
2907 wxListEvent
le( command
, GetParent()->GetId() );
2908 le
.SetEventObject( GetParent() );
2909 le
.m_itemIndex
= m_lineLastClicked
;
2910 le
.m_pointDrag
= m_dragStart
;
2911 GetParent()->GetEventHandler()->ProcessEvent( le
);
2922 // outside of any item
2926 bool forceClick
= false;
2927 if (event
.ButtonDClick())
2929 m_renameTimer
->Stop();
2930 m_lastOnSame
= false;
2932 if ( current
== m_lineLastClicked
)
2934 SendNotify( current
, wxEVT_COMMAND_LIST_ITEM_ACTIVATED
);
2940 // The first click was on another item, so don't interpret this as
2941 // a double click, but as a simple click instead
2948 if (m_lineSelectSingleOnUp
!= (size_t)-1)
2950 // select single line
2951 HighlightAll( false );
2952 ReverseHighlight(m_lineSelectSingleOnUp
);
2957 if ((current
== m_current
) &&
2958 (hitResult
== wxLIST_HITTEST_ONITEMLABEL
) &&
2959 HasFlag(wxLC_EDIT_LABELS
) )
2961 m_renameTimer
->Start( 100, true );
2965 m_lastOnSame
= false;
2966 m_lineSelectSingleOnUp
= (size_t)-1;
2970 // This is necessary, because after a DnD operation in
2971 // from and to ourself, the up event is swallowed by the
2972 // DnD code. So on next non-up event (which means here and
2973 // now) m_lineSelectSingleOnUp should be reset.
2974 m_lineSelectSingleOnUp
= (size_t)-1;
2976 if (event
.RightDown())
2978 m_lineBeforeLastClicked
= m_lineLastClicked
;
2979 m_lineLastClicked
= current
;
2981 // If the item is already selected, do not update the selection.
2982 // Multi-selections should not be cleared if a selected item is clicked.
2983 if (!IsHighlighted(current
))
2985 HighlightAll(false);
2986 ChangeCurrent(current
);
2987 ReverseHighlight(m_current
);
2990 SendNotify( current
, wxEVT_COMMAND_LIST_ITEM_RIGHT_CLICK
, event
.GetPosition() );
2992 // Allow generation of context menu event
2995 else if (event
.MiddleDown())
2997 SendNotify( current
, wxEVT_COMMAND_LIST_ITEM_MIDDLE_CLICK
);
2999 else if ( event
.LeftDown() || forceClick
)
3001 m_lineBeforeLastClicked
= m_lineLastClicked
;
3002 m_lineLastClicked
= current
;
3004 size_t oldCurrent
= m_current
;
3005 bool oldWasSelected
= IsHighlighted(m_current
);
3007 bool cmdModifierDown
= event
.CmdDown();
3008 if ( IsSingleSel() || !(cmdModifierDown
|| event
.ShiftDown()) )
3010 if ( IsSingleSel() || !IsHighlighted(current
) )
3012 HighlightAll( false );
3014 ChangeCurrent(current
);
3016 ReverseHighlight(m_current
);
3018 else // multi sel & current is highlighted & no mod keys
3020 m_lineSelectSingleOnUp
= current
;
3021 ChangeCurrent(current
); // change focus
3024 else // multi sel & either ctrl or shift is down
3026 if (cmdModifierDown
)
3028 ChangeCurrent(current
);
3030 ReverseHighlight(m_current
);
3032 else if (event
.ShiftDown())
3034 ChangeCurrent(current
);
3036 size_t lineFrom
= oldCurrent
,
3039 if ( lineTo
< lineFrom
)
3042 lineFrom
= m_current
;
3045 HighlightLines(lineFrom
, lineTo
);
3047 else // !ctrl, !shift
3049 // test in the enclosing if should make it impossible
3050 wxFAIL_MSG( _T("how did we get here?") );
3054 if (m_current
!= oldCurrent
)
3055 RefreshLine( oldCurrent
);
3057 // forceClick is only set if the previous click was on another item
3058 m_lastOnSame
= !forceClick
&& (m_current
== oldCurrent
) && oldWasSelected
;
3062 void wxListMainWindow::MoveToItem(size_t item
)
3064 if ( item
== (size_t)-1 )
3067 wxRect rect
= GetLineRect(item
);
3069 int client_w
, client_h
;
3070 GetClientSize( &client_w
, &client_h
);
3072 const int hLine
= GetLineHeight();
3074 int view_x
= SCROLL_UNIT_X
* GetScrollPos( wxHORIZONTAL
);
3075 int view_y
= hLine
* GetScrollPos( wxVERTICAL
);
3077 if ( InReportView() )
3079 // the next we need the range of lines shown it might be different,
3080 // so recalculate it
3081 ResetVisibleLinesRange();
3083 if (rect
.y
< view_y
)
3084 Scroll( -1, rect
.y
/ hLine
);
3085 if (rect
.y
+ rect
.height
+ 5 > view_y
+ client_h
)
3086 Scroll( -1, (rect
.y
+ rect
.height
- client_h
+ hLine
) / hLine
);
3090 if (rect
.x
-view_x
< 5)
3091 Scroll( (rect
.x
- 5) / SCROLL_UNIT_X
, -1 );
3092 if (rect
.x
+ rect
.width
- 5 > view_x
+ client_w
)
3093 Scroll( (rect
.x
+ rect
.width
- client_w
+ SCROLL_UNIT_X
) / SCROLL_UNIT_X
, -1 );
3097 // ----------------------------------------------------------------------------
3098 // keyboard handling
3099 // ----------------------------------------------------------------------------
3101 void wxListMainWindow::OnArrowChar(size_t newCurrent
, const wxKeyEvent
& event
)
3103 wxCHECK_RET( newCurrent
< (size_t)GetItemCount(),
3104 _T("invalid item index in OnArrowChar()") );
3106 size_t oldCurrent
= m_current
;
3108 // in single selection we just ignore Shift as we can't select several
3110 if ( event
.ShiftDown() && !IsSingleSel() )
3112 ChangeCurrent(newCurrent
);
3114 // refresh the old focus to remove it
3115 RefreshLine( oldCurrent
);
3117 // select all the items between the old and the new one
3118 if ( oldCurrent
> newCurrent
)
3120 newCurrent
= oldCurrent
;
3121 oldCurrent
= m_current
;
3124 HighlightLines(oldCurrent
, newCurrent
);
3128 // all previously selected items are unselected unless ctrl is held
3129 if ( !event
.ControlDown() )
3130 HighlightAll(false);
3132 ChangeCurrent(newCurrent
);
3134 // refresh the old focus to remove it
3135 RefreshLine( oldCurrent
);
3137 if ( !event
.ControlDown() )
3139 HighlightLine( m_current
, true );
3143 RefreshLine( m_current
);
3148 void wxListMainWindow::OnKeyDown( wxKeyEvent
&event
)
3150 wxWindow
*parent
= GetParent();
3152 // propagate the key event upwards
3153 wxKeyEvent
ke( wxEVT_KEY_DOWN
);
3154 ke
.m_shiftDown
= event
.m_shiftDown
;
3155 ke
.m_controlDown
= event
.m_controlDown
;
3156 ke
.m_altDown
= event
.m_altDown
;
3157 ke
.m_metaDown
= event
.m_metaDown
;
3158 ke
.m_keyCode
= event
.m_keyCode
;
3161 ke
.SetEventObject( parent
);
3162 if (parent
->GetEventHandler()->ProcessEvent( ke
)) return;
3167 void wxListMainWindow::OnChar( wxKeyEvent
&event
)
3169 wxWindow
*parent
= GetParent();
3171 // send a list_key event up
3174 wxListEvent
le( wxEVT_COMMAND_LIST_KEY_DOWN
, GetParent()->GetId() );
3175 le
.m_itemIndex
= m_current
;
3176 GetLine(m_current
)->GetItem( 0, le
.m_item
);
3177 le
.m_code
= event
.GetKeyCode();
3178 le
.SetEventObject( parent
);
3179 parent
->GetEventHandler()->ProcessEvent( le
);
3182 // propagate the char event upwards
3183 wxKeyEvent
ke( wxEVT_CHAR
);
3184 ke
.m_shiftDown
= event
.m_shiftDown
;
3185 ke
.m_controlDown
= event
.m_controlDown
;
3186 ke
.m_altDown
= event
.m_altDown
;
3187 ke
.m_metaDown
= event
.m_metaDown
;
3188 ke
.m_keyCode
= event
.m_keyCode
;
3191 ke
.SetEventObject( parent
);
3192 if (parent
->GetEventHandler()->ProcessEvent( ke
)) return;
3194 if (event
.GetKeyCode() == WXK_TAB
)
3196 wxNavigationKeyEvent nevent
;
3197 nevent
.SetWindowChange( event
.ControlDown() );
3198 nevent
.SetDirection( !event
.ShiftDown() );
3199 nevent
.SetEventObject( GetParent()->GetParent() );
3200 nevent
.SetCurrentFocus( m_parent
);
3201 if (GetParent()->GetParent()->GetEventHandler()->ProcessEvent( nevent
))
3205 // no item -> nothing to do
3212 switch (event
.GetKeyCode())
3215 if ( m_current
> 0 )
3216 OnArrowChar( m_current
- 1, event
);
3220 if ( m_current
< (size_t)GetItemCount() - 1 )
3221 OnArrowChar( m_current
+ 1, event
);
3226 OnArrowChar( GetItemCount() - 1, event
);
3231 OnArrowChar( 0, event
);
3236 int steps
= InReportView() ? m_linesPerPage
- 1 : m_current
% m_linesPerPage
;
3238 int index
= m_current
- steps
;
3242 OnArrowChar( index
, event
);
3248 int steps
= InReportView()
3249 ? m_linesPerPage
- 1
3250 : m_linesPerPage
- (m_current
% m_linesPerPage
) - 1;
3252 size_t index
= m_current
+ steps
;
3253 size_t count
= GetItemCount();
3254 if ( index
>= count
)
3257 OnArrowChar( index
, event
);
3262 if ( !InReportView() )
3264 int index
= m_current
- m_linesPerPage
;
3268 OnArrowChar( index
, event
);
3273 if ( !InReportView() )
3275 size_t index
= m_current
+ m_linesPerPage
;
3277 size_t count
= GetItemCount();
3278 if ( index
>= count
)
3281 OnArrowChar( index
, event
);
3286 if ( IsSingleSel() )
3288 SendNotify( m_current
, wxEVT_COMMAND_LIST_ITEM_ACTIVATED
);
3290 if ( IsHighlighted(m_current
) )
3292 // don't unselect the item in single selection mode
3295 //else: select it in ReverseHighlight() below if unselected
3298 ReverseHighlight(m_current
);
3303 SendNotify( m_current
, wxEVT_COMMAND_LIST_ITEM_ACTIVATED
);
3311 // ----------------------------------------------------------------------------
3313 // ----------------------------------------------------------------------------
3315 void wxListMainWindow::OnSetFocus( wxFocusEvent
&WXUNUSED(event
) )
3319 wxFocusEvent
event( wxEVT_SET_FOCUS
, GetParent()->GetId() );
3320 event
.SetEventObject( GetParent() );
3321 if ( GetParent()->GetEventHandler()->ProcessEvent( event
) )
3325 // wxGTK sends us EVT_SET_FOCUS events even if we had never got
3326 // EVT_KILL_FOCUS before which means that we finish by redrawing the items
3327 // which are already drawn correctly resulting in horrible flicker - avoid
3337 void wxListMainWindow::OnKillFocus( wxFocusEvent
&WXUNUSED(event
) )
3341 wxFocusEvent
event( wxEVT_KILL_FOCUS
, GetParent()->GetId() );
3342 event
.SetEventObject( GetParent() );
3343 if ( GetParent()->GetEventHandler()->ProcessEvent( event
) )
3351 void wxListMainWindow::DrawImage( int index
, wxDC
*dc
, int x
, int y
)
3353 if ( HasFlag(wxLC_ICON
) && (m_normal_image_list
))
3355 m_normal_image_list
->Draw( index
, *dc
, x
, y
, wxIMAGELIST_DRAW_TRANSPARENT
);
3357 else if ( HasFlag(wxLC_SMALL_ICON
) && (m_small_image_list
))
3359 m_small_image_list
->Draw( index
, *dc
, x
, y
, wxIMAGELIST_DRAW_TRANSPARENT
);
3361 else if ( HasFlag(wxLC_LIST
) && (m_small_image_list
))
3363 m_small_image_list
->Draw( index
, *dc
, x
, y
, wxIMAGELIST_DRAW_TRANSPARENT
);
3365 else if ( InReportView() && (m_small_image_list
))
3367 m_small_image_list
->Draw( index
, *dc
, x
, y
, wxIMAGELIST_DRAW_TRANSPARENT
);
3371 void wxListMainWindow::GetImageSize( int index
, int &width
, int &height
) const
3373 if ( HasFlag(wxLC_ICON
) && m_normal_image_list
)
3375 m_normal_image_list
->GetSize( index
, width
, height
);
3377 else if ( HasFlag(wxLC_SMALL_ICON
) && m_small_image_list
)
3379 m_small_image_list
->GetSize( index
, width
, height
);
3381 else if ( HasFlag(wxLC_LIST
) && m_small_image_list
)
3383 m_small_image_list
->GetSize( index
, width
, height
);
3385 else if ( InReportView() && m_small_image_list
)
3387 m_small_image_list
->GetSize( index
, width
, height
);
3396 int wxListMainWindow::GetTextLength( const wxString
&s
) const
3398 wxClientDC
dc( wxConstCast(this, wxListMainWindow
) );
3399 dc
.SetFont( GetFont() );
3402 dc
.GetTextExtent( s
, &lw
, NULL
);
3404 return lw
+ AUTOSIZE_COL_MARGIN
;
3407 void wxListMainWindow::SetImageList( wxImageListType
*imageList
, int which
)
3411 // calc the spacing from the icon size
3412 int width
= 0, height
= 0;
3414 if ((imageList
) && (imageList
->GetImageCount()) )
3415 imageList
->GetSize(0, width
, height
);
3417 if (which
== wxIMAGE_LIST_NORMAL
)
3419 m_normal_image_list
= imageList
;
3420 m_normal_spacing
= width
+ 8;
3423 if (which
== wxIMAGE_LIST_SMALL
)
3425 m_small_image_list
= imageList
;
3426 m_small_spacing
= width
+ 14;
3427 m_lineHeight
= 0; // ensure that the line height will be recalc'd
3431 void wxListMainWindow::SetItemSpacing( int spacing
, bool isSmall
)
3435 m_small_spacing
= spacing
;
3437 m_normal_spacing
= spacing
;
3440 int wxListMainWindow::GetItemSpacing( bool isSmall
)
3442 return isSmall
? m_small_spacing
: m_normal_spacing
;
3445 // ----------------------------------------------------------------------------
3447 // ----------------------------------------------------------------------------
3449 void wxListMainWindow::SetColumn( int col
, wxListItem
&item
)
3451 wxListHeaderDataList::compatibility_iterator node
= m_columns
.Item( col
);
3453 wxCHECK_RET( node
, _T("invalid column index in SetColumn") );
3455 if ( item
.m_width
== wxLIST_AUTOSIZE_USEHEADER
)
3456 item
.m_width
= GetTextLength( item
.m_text
);
3458 wxListHeaderData
*column
= node
->GetData();
3459 column
->SetItem( item
);
3461 wxListHeaderWindow
*headerWin
= GetListCtrl()->m_headerWin
;
3463 headerWin
->m_dirty
= true;
3467 // invalidate it as it has to be recalculated
3471 void wxListMainWindow::SetColumnWidth( int col
, int width
)
3473 wxCHECK_RET( col
>= 0 && col
< GetColumnCount(),
3474 _T("invalid column index") );
3476 wxCHECK_RET( InReportView(),
3477 _T("SetColumnWidth() can only be called in report mode.") );
3480 wxListHeaderWindow
*headerWin
= GetListCtrl()->m_headerWin
;
3482 headerWin
->m_dirty
= true;
3484 wxListHeaderDataList::compatibility_iterator node
= m_columns
.Item( col
);
3485 wxCHECK_RET( node
, _T("no column?") );
3487 wxListHeaderData
*column
= node
->GetData();
3489 size_t count
= GetItemCount();
3491 if (width
== wxLIST_AUTOSIZE_USEHEADER
)
3493 width
= GetTextLength(column
->GetText());
3495 else if ( width
== wxLIST_AUTOSIZE
)
3499 // TODO: determine the max width somehow...
3500 width
= WIDTH_COL_DEFAULT
;
3504 wxClientDC
dc(this);
3505 dc
.SetFont( GetFont() );
3507 int max
= AUTOSIZE_COL_MARGIN
;
3509 // if the cached column width isn't valid then recalculate it
3510 if (m_aColWidths
.Item(col
)->bNeedsUpdate
)
3512 for (size_t i
= 0; i
< count
; i
++)
3514 wxListLineData
*line
= GetLine( i
);
3515 wxListItemDataList::compatibility_iterator n
= line
->m_items
.Item( col
);
3517 wxCHECK_RET( n
, _T("no subitem?") );
3519 wxListItemData
*itemData
= n
->GetData();
3522 itemData
->GetItem(item
);
3523 int itemWidth
= GetItemWidthWithImage(&item
);
3524 if (itemWidth
> max
)
3528 m_aColWidths
.Item(col
)->bNeedsUpdate
= false;
3529 m_aColWidths
.Item(col
)->nMaxWidth
= max
;
3532 max
= m_aColWidths
.Item(col
)->nMaxWidth
;
3533 width
= max
+ AUTOSIZE_COL_MARGIN
;
3537 column
->SetWidth( width
);
3539 // invalidate it as it has to be recalculated
3543 int wxListMainWindow::GetHeaderWidth() const
3545 if ( !m_headerWidth
)
3547 wxListMainWindow
*self
= wxConstCast(this, wxListMainWindow
);
3549 size_t count
= GetColumnCount();
3550 for ( size_t col
= 0; col
< count
; col
++ )
3552 self
->m_headerWidth
+= GetColumnWidth(col
);
3556 return m_headerWidth
;
3559 void wxListMainWindow::GetColumn( int col
, wxListItem
&item
) const
3561 wxListHeaderDataList::compatibility_iterator node
= m_columns
.Item( col
);
3562 wxCHECK_RET( node
, _T("invalid column index in GetColumn") );
3564 wxListHeaderData
*column
= node
->GetData();
3565 column
->GetItem( item
);
3568 int wxListMainWindow::GetColumnWidth( int col
) const
3570 wxListHeaderDataList::compatibility_iterator node
= m_columns
.Item( col
);
3571 wxCHECK_MSG( node
, 0, _T("invalid column index") );
3573 wxListHeaderData
*column
= node
->GetData();
3574 return column
->GetWidth();
3577 // ----------------------------------------------------------------------------
3579 // ----------------------------------------------------------------------------
3581 void wxListMainWindow::SetItem( wxListItem
&item
)
3583 long id
= item
.m_itemId
;
3584 wxCHECK_RET( id
>= 0 && (size_t)id
< GetItemCount(),
3585 _T("invalid item index in SetItem") );
3589 wxListLineData
*line
= GetLine((size_t)id
);
3590 line
->SetItem( item
.m_col
, item
);
3592 // Set item state if user wants
3593 if ( item
.m_mask
& wxLIST_MASK_STATE
)
3594 SetItemState( item
.m_itemId
, item
.m_state
, item
.m_state
);
3598 // update the Max Width Cache if needed
3599 int width
= GetItemWidthWithImage(&item
);
3601 if (width
> m_aColWidths
.Item(item
.m_col
)->nMaxWidth
)
3602 m_aColWidths
.Item(item
.m_col
)->nMaxWidth
= width
;
3606 // update the item on screen
3608 GetItemRect(id
, rectItem
);
3609 RefreshRect(rectItem
);
3612 void wxListMainWindow::SetItemStateAll(long state
, long stateMask
)
3617 // first deal with selection
3618 if ( stateMask
& wxLIST_STATE_SELECTED
)
3620 // set/clear select state
3623 // optimized version for virtual listctrl.
3624 m_selStore
.SelectRange(0, GetItemCount() - 1, state
== wxLIST_STATE_SELECTED
);
3627 else if ( state
& wxLIST_STATE_SELECTED
)
3629 const long count
= GetItemCount();
3630 for( long i
= 0; i
< count
; i
++ )
3632 SetItemState( i
, wxLIST_STATE_SELECTED
, wxLIST_STATE_SELECTED
);
3638 // clear for non virtual (somewhat optimized by using GetNextItem())
3640 while ( (i
= GetNextItem(i
, wxLIST_NEXT_ALL
, wxLIST_STATE_SELECTED
)) != -1 )
3642 SetItemState( i
, 0, wxLIST_STATE_SELECTED
);
3647 if ( HasCurrent() && (state
== 0) && (stateMask
& wxLIST_STATE_FOCUSED
) )
3649 // unfocus all: only one item can be focussed, so clearing focus for
3650 // all items is simply clearing focus of the focussed item.
3651 SetItemState(m_current
, state
, stateMask
);
3653 //(setting focus to all items makes no sense, so it is not handled here.)
3656 void wxListMainWindow::SetItemState( long litem
, long state
, long stateMask
)
3660 SetItemStateAll(state
, stateMask
);
3664 wxCHECK_RET( litem
>= 0 && (size_t)litem
< GetItemCount(),
3665 _T("invalid list ctrl item index in SetItem") );
3667 size_t oldCurrent
= m_current
;
3668 size_t item
= (size_t)litem
; // safe because of the check above
3670 // do we need to change the focus?
3671 if ( stateMask
& wxLIST_STATE_FOCUSED
)
3673 if ( state
& wxLIST_STATE_FOCUSED
)
3675 // don't do anything if this item is already focused
3676 if ( item
!= m_current
)
3678 ChangeCurrent(item
);
3680 if ( oldCurrent
!= (size_t)-1 )
3682 if ( IsSingleSel() )
3684 HighlightLine(oldCurrent
, false);
3687 RefreshLine(oldCurrent
);
3690 RefreshLine( m_current
);
3695 // don't do anything if this item is not focused
3696 if ( item
== m_current
)
3700 if ( IsSingleSel() )
3702 // we must unselect the old current item as well or we
3703 // might end up with more than one selected item in a
3704 // single selection control
3705 HighlightLine(oldCurrent
, false);
3708 RefreshLine( oldCurrent
);
3713 // do we need to change the selection state?
3714 if ( stateMask
& wxLIST_STATE_SELECTED
)
3716 bool on
= (state
& wxLIST_STATE_SELECTED
) != 0;
3718 if ( IsSingleSel() )
3722 // selecting the item also makes it the focused one in the
3724 if ( m_current
!= item
)
3726 ChangeCurrent(item
);
3728 if ( oldCurrent
!= (size_t)-1 )
3730 HighlightLine( oldCurrent
, false );
3731 RefreshLine( oldCurrent
);
3737 // only the current item may be selected anyhow
3738 if ( item
!= m_current
)
3743 if ( HighlightLine(item
, on
) )
3750 int wxListMainWindow::GetItemState( long item
, long stateMask
) const
3752 wxCHECK_MSG( item
>= 0 && (size_t)item
< GetItemCount(), 0,
3753 _T("invalid list ctrl item index in GetItemState()") );
3755 int ret
= wxLIST_STATE_DONTCARE
;
3757 if ( stateMask
& wxLIST_STATE_FOCUSED
)
3759 if ( (size_t)item
== m_current
)
3760 ret
|= wxLIST_STATE_FOCUSED
;
3763 if ( stateMask
& wxLIST_STATE_SELECTED
)
3765 if ( IsHighlighted(item
) )
3766 ret
|= wxLIST_STATE_SELECTED
;
3772 void wxListMainWindow::GetItem( wxListItem
&item
) const
3774 wxCHECK_RET( item
.m_itemId
>= 0 && (size_t)item
.m_itemId
< GetItemCount(),
3775 _T("invalid item index in GetItem") );
3777 wxListLineData
*line
= GetLine((size_t)item
.m_itemId
);
3778 line
->GetItem( item
.m_col
, item
);
3780 // Get item state if user wants it
3781 if ( item
.m_mask
& wxLIST_MASK_STATE
)
3782 item
.m_state
= GetItemState( item
.m_itemId
, wxLIST_STATE_SELECTED
|
3783 wxLIST_STATE_FOCUSED
);
3786 // ----------------------------------------------------------------------------
3788 // ----------------------------------------------------------------------------
3790 size_t wxListMainWindow::GetItemCount() const
3792 return IsVirtual() ? m_countVirt
: m_lines
.GetCount();
3795 void wxListMainWindow::SetItemCount(long count
)
3797 m_selStore
.SetItemCount(count
);
3798 m_countVirt
= count
;
3800 ResetVisibleLinesRange();
3802 // scrollbars must be reset
3806 int wxListMainWindow::GetSelectedItemCount() const
3808 // deal with the quick case first
3809 if ( IsSingleSel() )
3810 return HasCurrent() ? IsHighlighted(m_current
) : false;
3812 // virtual controls remmebers all its selections itself
3814 return m_selStore
.GetSelectedCount();
3816 // TODO: we probably should maintain the number of items selected even for
3817 // non virtual controls as enumerating all lines is really slow...
3818 size_t countSel
= 0;
3819 size_t count
= GetItemCount();
3820 for ( size_t line
= 0; line
< count
; line
++ )
3822 if ( GetLine(line
)->IsHighlighted() )
3829 // ----------------------------------------------------------------------------
3830 // item position/size
3831 // ----------------------------------------------------------------------------
3833 wxRect
wxListMainWindow::GetViewRect() const
3835 wxASSERT_MSG( !HasFlag(wxLC_REPORT
| wxLC_LIST
),
3836 _T("wxListCtrl::GetViewRect() only works in icon mode") );
3838 // we need to find the longest/tallest label
3839 wxCoord xMax
= 0, yMax
= 0;
3840 const int count
= GetItemCount();
3843 for ( int i
= 0; i
< count
; i
++ )
3848 wxCoord x
= r
.GetRight(),
3858 // some fudge needed to make it look prettier
3859 xMax
+= 2 * EXTRA_BORDER_X
;
3860 yMax
+= 2 * EXTRA_BORDER_Y
;
3862 // account for the scrollbars if necessary
3863 const wxSize sizeAll
= GetClientSize();
3864 if ( xMax
> sizeAll
.x
)
3865 yMax
+= wxSystemSettings::GetMetric(wxSYS_HSCROLL_Y
);
3866 if ( yMax
> sizeAll
.y
)
3867 xMax
+= wxSystemSettings::GetMetric(wxSYS_VSCROLL_X
);
3869 return wxRect(0, 0, xMax
, yMax
);
3872 void wxListMainWindow::GetItemRect( long index
, wxRect
&rect
) const
3874 wxCHECK_RET( index
>= 0 && (size_t)index
< GetItemCount(),
3875 _T("invalid index in GetItemRect") );
3877 // ensure that we're laid out, otherwise we could return nonsense
3880 wxConstCast(this, wxListMainWindow
)->
3881 RecalculatePositions(true /* no refresh */);
3884 rect
= GetLineRect((size_t)index
);
3886 CalcScrolledPosition(rect
.x
, rect
.y
, &rect
.x
, &rect
.y
);
3889 bool wxListMainWindow::GetItemPosition(long item
, wxPoint
& pos
) const
3892 GetItemRect(item
, rect
);
3900 // ----------------------------------------------------------------------------
3901 // geometry calculation
3902 // ----------------------------------------------------------------------------
3904 void wxListMainWindow::RecalculatePositions(bool noRefresh
)
3906 wxClientDC
dc( this );
3907 dc
.SetFont( GetFont() );
3909 const size_t count
= GetItemCount();
3912 if ( HasFlag(wxLC_ICON
) )
3913 iconSpacing
= m_normal_spacing
;
3914 else if ( HasFlag(wxLC_SMALL_ICON
) )
3915 iconSpacing
= m_small_spacing
;
3919 // Note that we do not call GetClientSize() here but
3920 // GetSize() and subtract the border size for sunken
3921 // borders manually. This is technically incorrect,
3922 // but we need to know the client area's size WITHOUT
3923 // scrollbars here. Since we don't know if there are
3924 // any scrollbars, we use GetSize() instead. Another
3925 // solution would be to call SetScrollbars() here to
3926 // remove the scrollbars and call GetClientSize() then,
3927 // but this might result in flicker and - worse - will
3928 // reset the scrollbars to 0 which is not good at all
3929 // if you resize a dialog/window, but don't want to
3930 // reset the window scrolling. RR.
3931 // Furthermore, we actually do NOT subtract the border
3932 // width as 2 pixels is just the extra space which we
3933 // need around the actual content in the window. Other-
3934 // wise the text would e.g. touch the upper border. RR.
3937 GetSize( &clientWidth
, &clientHeight
);
3939 const int lineHeight
= GetLineHeight();
3941 if ( InReportView() )
3943 // all lines have the same height and we scroll one line per step
3944 int entireHeight
= count
* lineHeight
+ LINE_SPACING
;
3946 m_linesPerPage
= clientHeight
/ lineHeight
;
3948 ResetVisibleLinesRange();
3950 SetScrollbars( SCROLL_UNIT_X
, lineHeight
,
3951 GetHeaderWidth() / SCROLL_UNIT_X
,
3952 (entireHeight
+ lineHeight
- 1) / lineHeight
,
3953 GetScrollPos(wxHORIZONTAL
),
3954 GetScrollPos(wxVERTICAL
),
3959 // we have 3 different layout strategies: either layout all items
3960 // horizontally/vertically (wxLC_ALIGN_XXX styles explicitly given) or
3961 // to arrange them in top to bottom, left to right (don't ask me why
3962 // not the other way round...) order
3963 if ( HasFlag(wxLC_ALIGN_LEFT
| wxLC_ALIGN_TOP
) )
3965 int x
= EXTRA_BORDER_X
;
3966 int y
= EXTRA_BORDER_Y
;
3968 wxCoord widthMax
= 0;
3971 for ( i
= 0; i
< count
; i
++ )
3973 wxListLineData
*line
= GetLine(i
);
3974 line
->CalculateSize( &dc
, iconSpacing
);
3975 line
->SetPosition( x
, y
, iconSpacing
);
3977 wxSize sizeLine
= GetLineSize(i
);
3979 if ( HasFlag(wxLC_ALIGN_TOP
) )
3981 if ( sizeLine
.x
> widthMax
)
3982 widthMax
= sizeLine
.x
;
3986 else // wxLC_ALIGN_LEFT
3988 x
+= sizeLine
.x
+ MARGIN_BETWEEN_ROWS
;
3992 if ( HasFlag(wxLC_ALIGN_TOP
) )
3994 // traverse the items again and tweak their sizes so that they are
3995 // all the same in a row
3996 for ( i
= 0; i
< count
; i
++ )
3998 wxListLineData
*line
= GetLine(i
);
3999 line
->m_gi
->ExtendWidth(widthMax
);
4007 (x
+ SCROLL_UNIT_X
) / SCROLL_UNIT_X
,
4008 (y
+ lineHeight
) / lineHeight
,
4009 GetScrollPos( wxHORIZONTAL
),
4010 GetScrollPos( wxVERTICAL
),
4014 else // "flowed" arrangement, the most complicated case
4016 // at first we try without any scrollbars, if the items don't fit into
4017 // the window, we recalculate after subtracting the space taken by the
4020 int entireWidth
= 0;
4022 for (int tries
= 0; tries
< 2; tries
++)
4024 entireWidth
= 2 * EXTRA_BORDER_X
;
4028 // Now we have decided that the items do not fit into the
4029 // client area, so we need a scrollbar
4030 entireWidth
+= SCROLL_UNIT_X
;
4033 int x
= EXTRA_BORDER_X
;
4034 int y
= EXTRA_BORDER_Y
;
4035 int maxWidthInThisRow
= 0;
4038 int currentlyVisibleLines
= 0;
4040 for (size_t i
= 0; i
< count
; i
++)
4042 currentlyVisibleLines
++;
4043 wxListLineData
*line
= GetLine( i
);
4044 line
->CalculateSize( &dc
, iconSpacing
);
4045 line
->SetPosition( x
, y
, iconSpacing
);
4047 wxSize sizeLine
= GetLineSize( i
);
4049 if ( maxWidthInThisRow
< sizeLine
.x
)
4050 maxWidthInThisRow
= sizeLine
.x
;
4053 if (currentlyVisibleLines
> m_linesPerPage
)
4054 m_linesPerPage
= currentlyVisibleLines
;
4056 if ( y
+ sizeLine
.y
>= clientHeight
)
4058 currentlyVisibleLines
= 0;
4060 maxWidthInThisRow
+= MARGIN_BETWEEN_ROWS
;
4061 x
+= maxWidthInThisRow
;
4062 entireWidth
+= maxWidthInThisRow
;
4063 maxWidthInThisRow
= 0;
4066 // We have reached the last item.
4067 if ( i
== count
- 1 )
4068 entireWidth
+= maxWidthInThisRow
;
4070 if ( (tries
== 0) &&
4071 (entireWidth
+ SCROLL_UNIT_X
> clientWidth
) )
4073 clientHeight
-= wxSystemSettings::
4074 GetMetric(wxSYS_HSCROLL_Y
);
4079 if ( i
== count
- 1 )
4080 tries
= 1; // Everything fits, no second try required.
4088 (entireWidth
+ SCROLL_UNIT_X
) / SCROLL_UNIT_X
,
4090 GetScrollPos( wxHORIZONTAL
),
4099 // FIXME: why should we call it from here?
4106 void wxListMainWindow::RefreshAll()
4111 wxListHeaderWindow
*headerWin
= GetListCtrl()->m_headerWin
;
4112 if ( headerWin
&& headerWin
->m_dirty
)
4114 headerWin
->m_dirty
= false;
4115 headerWin
->Refresh();
4119 void wxListMainWindow::UpdateCurrent()
4121 if ( !HasCurrent() && !IsEmpty() )
4125 long wxListMainWindow::GetNextItem( long item
,
4126 int WXUNUSED(geometry
),
4130 max
= GetItemCount();
4131 wxCHECK_MSG( (ret
== -1) || (ret
< max
), -1,
4132 _T("invalid listctrl index in GetNextItem()") );
4134 // notice that we start with the next item (or the first one if item == -1)
4135 // and this is intentional to allow writing a simple loop to iterate over
4136 // all selected items
4139 // this is not an error because the index was OK initially,
4140 // just no such item
4147 size_t count
= GetItemCount();
4148 for ( size_t line
= (size_t)ret
; line
< count
; line
++ )
4150 if ( (state
& wxLIST_STATE_FOCUSED
) && (line
== m_current
) )
4153 if ( (state
& wxLIST_STATE_SELECTED
) && IsHighlighted(line
) )
4160 // ----------------------------------------------------------------------------
4162 // ----------------------------------------------------------------------------
4164 void wxListMainWindow::DeleteItem( long lindex
)
4166 size_t count
= GetItemCount();
4168 wxCHECK_RET( (lindex
>= 0) && ((size_t)lindex
< count
),
4169 _T("invalid item index in DeleteItem") );
4171 size_t index
= (size_t)lindex
;
4173 // we don't need to adjust the index for the previous items
4174 if ( HasCurrent() && m_current
>= index
)
4176 // if the current item is being deleted, we want the next one to
4177 // become selected - unless there is no next one - so don't adjust
4178 // m_current in this case
4179 if ( m_current
!= index
|| m_current
== count
- 1 )
4183 if ( InReportView() )
4185 // mark the Column Max Width cache as dirty if the items in the line
4186 // we're deleting contain the Max Column Width
4187 wxListLineData
* const line
= GetLine(index
);
4188 wxListItemDataList::compatibility_iterator n
;
4189 wxListItemData
*itemData
;
4193 for (size_t i
= 0; i
< m_columns
.GetCount(); i
++)
4195 n
= line
->m_items
.Item( i
);
4196 itemData
= n
->GetData();
4197 itemData
->GetItem(item
);
4199 itemWidth
= GetItemWidthWithImage(&item
);
4201 if (itemWidth
>= m_aColWidths
.Item(i
)->nMaxWidth
)
4202 m_aColWidths
.Item(i
)->bNeedsUpdate
= true;
4205 ResetVisibleLinesRange();
4211 m_selStore
.OnItemDelete(index
);
4215 m_lines
.RemoveAt( index
);
4218 // we need to refresh the (vert) scrollbar as the number of items changed
4221 SendNotify( index
, wxEVT_COMMAND_LIST_DELETE_ITEM
);
4223 RefreshAfter(index
);
4226 void wxListMainWindow::DeleteColumn( int col
)
4228 wxListHeaderDataList::compatibility_iterator node
= m_columns
.Item( col
);
4230 wxCHECK_RET( node
, wxT("invalid column index in DeleteColumn()") );
4233 delete node
->GetData();
4234 m_columns
.Erase( node
);
4238 // update all the items
4239 for ( size_t i
= 0; i
< m_lines
.GetCount(); i
++ )
4241 wxListLineData
* const line
= GetLine(i
);
4242 wxListItemDataList::compatibility_iterator n
= line
->m_items
.Item( col
);
4243 delete n
->GetData();
4244 line
->m_items
.Erase(n
);
4248 if ( InReportView() ) // we only cache max widths when in Report View
4250 delete m_aColWidths
.Item(col
);
4251 m_aColWidths
.RemoveAt(col
);
4254 // invalidate it as it has to be recalculated
4258 void wxListMainWindow::DoDeleteAllItems()
4261 // nothing to do - in particular, don't send the event
4266 // to make the deletion of all items faster, we don't send the
4267 // notifications for each item deletion in this case but only one event
4268 // for all of them: this is compatible with wxMSW and documented in
4269 // DeleteAllItems() description
4271 wxListEvent
event( wxEVT_COMMAND_LIST_DELETE_ALL_ITEMS
, GetParent()->GetId() );
4272 event
.SetEventObject( GetParent() );
4273 GetParent()->GetEventHandler()->ProcessEvent( event
);
4281 if ( InReportView() )
4283 ResetVisibleLinesRange();
4284 for (size_t i
= 0; i
< m_aColWidths
.GetCount(); i
++)
4286 m_aColWidths
.Item(i
)->bNeedsUpdate
= true;
4293 void wxListMainWindow::DeleteAllItems()
4297 RecalculatePositions();
4300 void wxListMainWindow::DeleteEverything()
4302 WX_CLEAR_LIST(wxListHeaderDataList
, m_columns
);
4303 WX_CLEAR_ARRAY(m_aColWidths
);
4308 // ----------------------------------------------------------------------------
4309 // scanning for an item
4310 // ----------------------------------------------------------------------------
4312 void wxListMainWindow::EnsureVisible( long index
)
4314 wxCHECK_RET( index
>= 0 && (size_t)index
< GetItemCount(),
4315 _T("invalid index in EnsureVisible") );
4317 // We have to call this here because the label in question might just have
4318 // been added and its position is not known yet
4320 RecalculatePositions(true /* no refresh */);
4322 MoveToItem((size_t)index
);
4325 long wxListMainWindow::FindItem(long start
, const wxString
& str
, bool WXUNUSED(partial
) )
4332 size_t count
= GetItemCount();
4333 for ( size_t i
= (size_t)pos
; i
< count
; i
++ )
4335 wxListLineData
*line
= GetLine(i
);
4336 if ( line
->GetText(0) == tmp
)
4343 long wxListMainWindow::FindItem(long start
, wxUIntPtr data
)
4349 size_t count
= GetItemCount();
4350 for (size_t i
= (size_t)pos
; i
< count
; i
++)
4352 wxListLineData
*line
= GetLine(i
);
4354 line
->GetItem( 0, item
);
4355 if (item
.m_data
== data
)
4362 long wxListMainWindow::FindItem( const wxPoint
& pt
)
4365 GetVisibleLinesRange( &topItem
, NULL
);
4368 GetItemPosition( GetItemCount() - 1, p
);
4372 long id
= (long)floor( pt
.y
* double(GetItemCount() - topItem
- 1) / p
.y
+ topItem
);
4373 if ( id
>= 0 && id
< (long)GetItemCount() )
4379 long wxListMainWindow::HitTest( int x
, int y
, int &flags
)
4381 CalcUnscrolledPosition( x
, y
, &x
, &y
);
4383 size_t count
= GetItemCount();
4385 if ( InReportView() )
4387 size_t current
= y
/ GetLineHeight();
4388 if ( current
< count
)
4390 flags
= HitTestLine(current
, x
, y
);
4397 // TODO: optimize it too! this is less simple than for report view but
4398 // enumerating all items is still not a way to do it!!
4399 for ( size_t current
= 0; current
< count
; current
++ )
4401 flags
= HitTestLine(current
, x
, y
);
4410 // ----------------------------------------------------------------------------
4412 // ----------------------------------------------------------------------------
4414 void wxListMainWindow::InsertItem( wxListItem
&item
)
4416 wxASSERT_MSG( !IsVirtual(), _T("can't be used with virtual control") );
4418 int count
= GetItemCount();
4419 wxCHECK_RET( item
.m_itemId
>= 0, _T("invalid item index") );
4421 if (item
.m_itemId
> count
)
4422 item
.m_itemId
= count
;
4424 size_t id
= item
.m_itemId
;
4428 if ( InReportView() )
4430 ResetVisibleLinesRange();
4432 // calculate the width of the item and adjust the max column width
4433 wxColWidthInfo
*pWidthInfo
= m_aColWidths
.Item(item
.GetColumn());
4434 int width
= GetItemWidthWithImage(&item
);
4435 item
.SetWidth(width
);
4436 if (width
> pWidthInfo
->nMaxWidth
)
4437 pWidthInfo
->nMaxWidth
= width
;
4440 wxListLineData
*line
= new wxListLineData(this);
4442 line
->SetItem( item
.m_col
, item
);
4444 m_lines
.Insert( line
, id
);
4448 // If an item is selected at or below the point of insertion, we need to
4449 // increment the member variables because the current row's index has gone
4451 if ( HasCurrent() && m_current
>= id
)
4454 SendNotify(id
, wxEVT_COMMAND_LIST_INSERT_ITEM
);
4456 RefreshLines(id
, GetItemCount() - 1);
4459 void wxListMainWindow::InsertColumn( long col
, wxListItem
&item
)
4462 if ( InReportView() )
4464 if (item
.m_width
== wxLIST_AUTOSIZE_USEHEADER
)
4465 item
.m_width
= GetTextLength( item
.m_text
);
4467 wxListHeaderData
*column
= new wxListHeaderData( item
);
4468 wxColWidthInfo
*colWidthInfo
= new wxColWidthInfo();
4470 bool insert
= (col
>= 0) && ((size_t)col
< m_columns
.GetCount());
4473 wxListHeaderDataList::compatibility_iterator
4474 node
= m_columns
.Item( col
);
4475 m_columns
.Insert( node
, column
);
4476 m_aColWidths
.Insert( colWidthInfo
, col
);
4480 m_columns
.Append( column
);
4481 m_aColWidths
.Add( colWidthInfo
);
4486 // update all the items
4487 for ( size_t i
= 0; i
< m_lines
.GetCount(); i
++ )
4489 wxListLineData
* const line
= GetLine(i
);
4490 wxListItemData
* const data
= new wxListItemData(this);
4492 line
->m_items
.Insert(col
, data
);
4494 line
->m_items
.Append(data
);
4498 // invalidate it as it has to be recalculated
4503 int wxListMainWindow::GetItemWidthWithImage(wxListItem
* item
)
4506 wxClientDC
dc(this);
4508 dc
.SetFont( GetFont() );
4510 if (item
->GetImage() != -1)
4513 GetImageSize( item
->GetImage(), ix
, iy
);
4517 if (!item
->GetText().empty())
4520 dc
.GetTextExtent( item
->GetText(), &w
, NULL
);
4527 // ----------------------------------------------------------------------------
4529 // ----------------------------------------------------------------------------
4531 wxListCtrlCompare list_ctrl_compare_func_2
;
4532 long list_ctrl_compare_data
;
4534 int LINKAGEMODE
list_ctrl_compare_func_1( wxListLineData
**arg1
, wxListLineData
**arg2
)
4536 wxListLineData
*line1
= *arg1
;
4537 wxListLineData
*line2
= *arg2
;
4539 line1
->GetItem( 0, item
);
4540 wxUIntPtr data1
= item
.m_data
;
4541 line2
->GetItem( 0, item
);
4542 wxUIntPtr data2
= item
.m_data
;
4543 return list_ctrl_compare_func_2( data1
, data2
, list_ctrl_compare_data
);
4546 void wxListMainWindow::SortItems( wxListCtrlCompare fn
, long data
)
4548 list_ctrl_compare_func_2
= fn
;
4549 list_ctrl_compare_data
= data
;
4550 m_lines
.Sort( list_ctrl_compare_func_1
);
4554 // ----------------------------------------------------------------------------
4556 // ----------------------------------------------------------------------------
4558 void wxListMainWindow::OnScroll(wxScrollWinEvent
& event
)
4560 // update our idea of which lines are shown when we redraw the window the
4562 ResetVisibleLinesRange();
4565 #if ( defined(__WXGTK__) || defined(__WXMAC__) ) && !defined(__WXUNIVERSAL__)
4566 wxScrolledWindow::OnScroll(event
);
4568 HandleOnScroll( event
);
4571 if ( event
.GetOrientation() == wxHORIZONTAL
&& HasHeader() )
4573 wxGenericListCtrl
* lc
= GetListCtrl();
4574 wxCHECK_RET( lc
, _T("no listctrl window?") );
4576 lc
->m_headerWin
->Refresh();
4577 lc
->m_headerWin
->Update();
4581 int wxListMainWindow::GetCountPerPage() const
4583 if ( !m_linesPerPage
)
4585 wxConstCast(this, wxListMainWindow
)->
4586 m_linesPerPage
= GetClientSize().y
/ GetLineHeight();
4589 return m_linesPerPage
;
4592 void wxListMainWindow::GetVisibleLinesRange(size_t *from
, size_t *to
)
4594 wxASSERT_MSG( InReportView(), _T("this is for report mode only") );
4596 if ( m_lineFrom
== (size_t)-1 )
4598 size_t count
= GetItemCount();
4601 m_lineFrom
= GetScrollPos(wxVERTICAL
);
4603 // this may happen if SetScrollbars() hadn't been called yet
4604 if ( m_lineFrom
>= count
)
4605 m_lineFrom
= count
- 1;
4607 // we redraw one extra line but this is needed to make the redrawing
4608 // logic work when there is a fractional number of lines on screen
4609 m_lineTo
= m_lineFrom
+ m_linesPerPage
;
4610 if ( m_lineTo
>= count
)
4611 m_lineTo
= count
- 1;
4613 else // empty control
4616 m_lineTo
= (size_t)-1;
4620 wxASSERT_MSG( IsEmpty() ||
4621 (m_lineFrom
<= m_lineTo
&& m_lineTo
< GetItemCount()),
4622 _T("GetVisibleLinesRange() returns incorrect result") );
4630 // -------------------------------------------------------------------------------------
4631 // wxGenericListCtrl
4632 // -------------------------------------------------------------------------------------
4634 IMPLEMENT_DYNAMIC_CLASS(wxGenericListCtrl
, wxControl
)
4636 BEGIN_EVENT_TABLE(wxGenericListCtrl
,wxControl
)
4637 EVT_SIZE(wxGenericListCtrl::OnSize
)
4640 wxGenericListCtrl::wxGenericListCtrl()
4642 m_imageListNormal
= (wxImageListType
*) NULL
;
4643 m_imageListSmall
= (wxImageListType
*) NULL
;
4644 m_imageListState
= (wxImageListType
*) NULL
;
4646 m_ownsImageListNormal
=
4647 m_ownsImageListSmall
=
4648 m_ownsImageListState
= false;
4650 m_mainWin
= (wxListMainWindow
*) NULL
;
4651 m_headerWin
= (wxListHeaderWindow
*) NULL
;
4655 wxGenericListCtrl::~wxGenericListCtrl()
4657 if (m_ownsImageListNormal
)
4658 delete m_imageListNormal
;
4659 if (m_ownsImageListSmall
)
4660 delete m_imageListSmall
;
4661 if (m_ownsImageListState
)
4662 delete m_imageListState
;
4665 void wxGenericListCtrl::CalculateAndSetHeaderHeight()
4671 GetThemeMetric( kThemeMetricListHeaderHeight
, &h
);
4673 // we use 'g' to get the descent, too
4675 m_headerWin
->GetTextExtent(wxT("Hg"), &w
, &h
, &d
);
4676 h
+= d
+ 2 * HEADER_OFFSET_Y
+ EXTRA_HEIGHT
;
4679 // only update if changed
4680 if ( h
!= m_headerHeight
)
4684 m_headerWin
->SetSize(m_headerWin
->GetSize().x
, m_headerHeight
);
4687 ResizeReportView(true);
4692 void wxGenericListCtrl::CreateHeaderWindow()
4694 m_headerWin
= new wxListHeaderWindow
4696 this, wxID_ANY
, m_mainWin
,
4698 wxSize(GetClientSize().x
, m_headerHeight
),
4701 CalculateAndSetHeaderHeight();
4704 bool wxGenericListCtrl::Create(wxWindow
*parent
,
4709 const wxValidator
&validator
,
4710 const wxString
&name
)
4714 m_imageListState
= (wxImageListType
*) NULL
;
4715 m_ownsImageListNormal
=
4716 m_ownsImageListSmall
=
4717 m_ownsImageListState
= false;
4719 m_mainWin
= (wxListMainWindow
*) NULL
;
4720 m_headerWin
= (wxListHeaderWindow
*) NULL
;
4724 if ( !(style
& wxLC_MASK_TYPE
) )
4726 style
= style
| wxLC_LIST
;
4729 if ( !wxControl::Create( parent
, id
, pos
, size
, style
, validator
, name
) )
4732 // don't create the inner window with the border
4733 style
&= ~wxBORDER_MASK
;
4735 m_mainWin
= new wxListMainWindow( this, wxID_ANY
, wxPoint(0, 0), size
, style
);
4737 #ifdef __WXMAC_CARBON__
4738 // Human Interface Guidelines ask us for a special font in this case
4739 if ( GetWindowVariant() == wxWINDOW_VARIANT_NORMAL
)
4742 font
.MacCreateThemeFont( kThemeViewsFont
);
4747 if ( InReportView() )
4749 CreateHeaderWindow();
4751 #ifdef __WXMAC_CARBON__
4755 font
.MacCreateThemeFont( kThemeSmallSystemFont
);
4756 m_headerWin
->SetFont( font
);
4757 CalculateAndSetHeaderHeight();
4761 if ( HasFlag(wxLC_NO_HEADER
) )
4762 // VZ: why do we create it at all then?
4763 m_headerWin
->Show( false );
4771 void wxGenericListCtrl::SetSingleStyle( long style
, bool add
)
4773 wxASSERT_MSG( !(style
& wxLC_VIRTUAL
),
4774 _T("wxLC_VIRTUAL can't be [un]set") );
4776 long flag
= GetWindowStyle();
4780 if (style
& wxLC_MASK_TYPE
)
4781 flag
&= ~(wxLC_MASK_TYPE
| wxLC_VIRTUAL
);
4782 if (style
& wxLC_MASK_ALIGN
)
4783 flag
&= ~wxLC_MASK_ALIGN
;
4784 if (style
& wxLC_MASK_SORT
)
4785 flag
&= ~wxLC_MASK_SORT
;
4793 SetWindowStyleFlag( flag
);
4796 void wxGenericListCtrl::SetWindowStyleFlag( long flag
)
4800 m_mainWin
->DeleteEverything();
4802 // has the header visibility changed?
4803 bool hasHeader
= HasHeader();
4804 bool willHaveHeader
= (flag
& wxLC_REPORT
) && !(flag
& wxLC_NO_HEADER
);
4806 if ( hasHeader
!= willHaveHeader
)
4813 // don't delete, just hide, as we can reuse it later
4814 m_headerWin
->Show(false);
4816 //else: nothing to do
4818 else // must show header
4822 CreateHeaderWindow();
4824 else // already have it, just show
4826 m_headerWin
->Show( true );
4830 ResizeReportView(willHaveHeader
);
4834 wxWindow::SetWindowStyleFlag( flag
);
4837 bool wxGenericListCtrl::GetColumn(int col
, wxListItem
&item
) const
4839 m_mainWin
->GetColumn( col
, item
);
4843 bool wxGenericListCtrl::SetColumn( int col
, wxListItem
& item
)
4845 m_mainWin
->SetColumn( col
, item
);
4849 int wxGenericListCtrl::GetColumnWidth( int col
) const
4851 return m_mainWin
->GetColumnWidth( col
);
4854 bool wxGenericListCtrl::SetColumnWidth( int col
, int width
)
4856 m_mainWin
->SetColumnWidth( col
, width
);
4860 int wxGenericListCtrl::GetCountPerPage() const
4862 return m_mainWin
->GetCountPerPage(); // different from Windows ?
4865 bool wxGenericListCtrl::GetItem( wxListItem
&info
) const
4867 m_mainWin
->GetItem( info
);
4871 bool wxGenericListCtrl::SetItem( wxListItem
&info
)
4873 m_mainWin
->SetItem( info
);
4877 long wxGenericListCtrl::SetItem( long index
, int col
, const wxString
& label
, int imageId
)
4880 info
.m_text
= label
;
4881 info
.m_mask
= wxLIST_MASK_TEXT
;
4882 info
.m_itemId
= index
;
4886 info
.m_image
= imageId
;
4887 info
.m_mask
|= wxLIST_MASK_IMAGE
;
4890 m_mainWin
->SetItem(info
);
4894 int wxGenericListCtrl::GetItemState( long item
, long stateMask
) const
4896 return m_mainWin
->GetItemState( item
, stateMask
);
4899 bool wxGenericListCtrl::SetItemState( long item
, long state
, long stateMask
)
4901 m_mainWin
->SetItemState( item
, state
, stateMask
);
4906 wxGenericListCtrl::SetItemImage( long item
, int image
, int WXUNUSED(selImage
) )
4909 info
.m_image
= image
;
4910 info
.m_mask
= wxLIST_MASK_IMAGE
;
4911 info
.m_itemId
= item
;
4912 m_mainWin
->SetItem( info
);
4916 wxString
wxGenericListCtrl::GetItemText( long item
) const
4918 return m_mainWin
->GetItemText(item
);
4921 void wxGenericListCtrl::SetItemText( long item
, const wxString
& str
)
4923 m_mainWin
->SetItemText(item
, str
);
4926 wxUIntPtr
wxGenericListCtrl::GetItemData( long item
) const
4929 info
.m_mask
= wxLIST_MASK_DATA
;
4930 info
.m_itemId
= item
;
4931 m_mainWin
->GetItem( info
);
4935 bool wxGenericListCtrl::SetItemData( long item
, long data
)
4938 info
.m_mask
= wxLIST_MASK_DATA
;
4939 info
.m_itemId
= item
;
4941 m_mainWin
->SetItem( info
);
4945 wxRect
wxGenericListCtrl::GetViewRect() const
4947 return m_mainWin
->GetViewRect();
4950 bool wxGenericListCtrl::GetItemRect( long item
, wxRect
&rect
, int WXUNUSED(code
) ) const
4952 m_mainWin
->GetItemRect( item
, rect
);
4953 if ( m_mainWin
->HasHeader() )
4954 rect
.y
+= m_headerHeight
+ 1;
4958 bool wxGenericListCtrl::GetItemPosition( long item
, wxPoint
& pos
) const
4960 m_mainWin
->GetItemPosition( item
, pos
);
4964 bool wxGenericListCtrl::SetItemPosition( long WXUNUSED(item
), const wxPoint
& WXUNUSED(pos
) )
4969 int wxGenericListCtrl::GetItemCount() const
4971 return m_mainWin
->GetItemCount();
4974 int wxGenericListCtrl::GetColumnCount() const
4976 return m_mainWin
->GetColumnCount();
4979 void wxGenericListCtrl::SetItemSpacing( int spacing
, bool isSmall
)
4981 m_mainWin
->SetItemSpacing( spacing
, isSmall
);
4984 wxSize
wxGenericListCtrl::GetItemSpacing() const
4986 const int spacing
= m_mainWin
->GetItemSpacing(HasFlag(wxLC_SMALL_ICON
));
4988 return wxSize(spacing
, spacing
);
4991 int wxGenericListCtrl::GetItemSpacing( bool isSmall
) const
4993 return m_mainWin
->GetItemSpacing( isSmall
);
4996 void wxGenericListCtrl::SetItemTextColour( long item
, const wxColour
&col
)
4999 info
.m_itemId
= item
;
5000 info
.SetTextColour( col
);
5001 m_mainWin
->SetItem( info
);
5004 wxColour
wxGenericListCtrl::GetItemTextColour( long item
) const
5007 info
.m_itemId
= item
;
5008 m_mainWin
->GetItem( info
);
5009 return info
.GetTextColour();
5012 void wxGenericListCtrl::SetItemBackgroundColour( long item
, const wxColour
&col
)
5015 info
.m_itemId
= item
;
5016 info
.SetBackgroundColour( col
);
5017 m_mainWin
->SetItem( info
);
5020 wxColour
wxGenericListCtrl::GetItemBackgroundColour( long item
) const
5023 info
.m_itemId
= item
;
5024 m_mainWin
->GetItem( info
);
5025 return info
.GetBackgroundColour();
5028 void wxGenericListCtrl::SetItemFont( long item
, const wxFont
&f
)
5031 info
.m_itemId
= item
;
5033 m_mainWin
->SetItem( info
);
5036 wxFont
wxGenericListCtrl::GetItemFont( long item
) const
5039 info
.m_itemId
= item
;
5040 m_mainWin
->GetItem( info
);
5041 return info
.GetFont();
5044 int wxGenericListCtrl::GetSelectedItemCount() const
5046 return m_mainWin
->GetSelectedItemCount();
5049 wxColour
wxGenericListCtrl::GetTextColour() const
5051 return GetForegroundColour();
5054 void wxGenericListCtrl::SetTextColour(const wxColour
& col
)
5056 SetForegroundColour(col
);
5059 long wxGenericListCtrl::GetTopItem() const
5062 m_mainWin
->GetVisibleLinesRange(&top
, NULL
);
5066 long wxGenericListCtrl::GetNextItem( long item
, int geom
, int state
) const
5068 return m_mainWin
->GetNextItem( item
, geom
, state
);
5071 wxImageListType
*wxGenericListCtrl::GetImageList(int which
) const
5073 if (which
== wxIMAGE_LIST_NORMAL
)
5074 return m_imageListNormal
;
5075 else if (which
== wxIMAGE_LIST_SMALL
)
5076 return m_imageListSmall
;
5077 else if (which
== wxIMAGE_LIST_STATE
)
5078 return m_imageListState
;
5080 return (wxImageListType
*) NULL
;
5083 void wxGenericListCtrl::SetImageList( wxImageListType
*imageList
, int which
)
5085 if ( which
== wxIMAGE_LIST_NORMAL
)
5087 if (m_ownsImageListNormal
)
5088 delete m_imageListNormal
;
5089 m_imageListNormal
= imageList
;
5090 m_ownsImageListNormal
= false;
5092 else if ( which
== wxIMAGE_LIST_SMALL
)
5094 if (m_ownsImageListSmall
)
5095 delete m_imageListSmall
;
5096 m_imageListSmall
= imageList
;
5097 m_ownsImageListSmall
= false;
5099 else if ( which
== wxIMAGE_LIST_STATE
)
5101 if (m_ownsImageListState
)
5102 delete m_imageListState
;
5103 m_imageListState
= imageList
;
5104 m_ownsImageListState
= false;
5107 m_mainWin
->SetImageList( imageList
, which
);
5110 void wxGenericListCtrl::AssignImageList(wxImageListType
*imageList
, int which
)
5112 SetImageList(imageList
, which
);
5113 if ( which
== wxIMAGE_LIST_NORMAL
)
5114 m_ownsImageListNormal
= true;
5115 else if ( which
== wxIMAGE_LIST_SMALL
)
5116 m_ownsImageListSmall
= true;
5117 else if ( which
== wxIMAGE_LIST_STATE
)
5118 m_ownsImageListState
= true;
5121 bool wxGenericListCtrl::Arrange( int WXUNUSED(flag
) )
5126 bool wxGenericListCtrl::DeleteItem( long item
)
5128 m_mainWin
->DeleteItem( item
);
5132 bool wxGenericListCtrl::DeleteAllItems()
5134 m_mainWin
->DeleteAllItems();
5138 bool wxGenericListCtrl::DeleteAllColumns()
5140 size_t count
= m_mainWin
->m_columns
.GetCount();
5141 for ( size_t n
= 0; n
< count
; n
++ )
5146 void wxGenericListCtrl::ClearAll()
5148 m_mainWin
->DeleteEverything();
5151 bool wxGenericListCtrl::DeleteColumn( int col
)
5153 m_mainWin
->DeleteColumn( col
);
5155 // if we don't have the header any longer, we need to relayout the window
5156 if ( !GetColumnCount() )
5157 ResizeReportView(false /* no header */);
5161 void wxGenericListCtrl::Edit( long item
)
5163 m_mainWin
->EditLabel( item
);
5166 bool wxGenericListCtrl::EnsureVisible( long item
)
5168 m_mainWin
->EnsureVisible( item
);
5172 long wxGenericListCtrl::FindItem( long start
, const wxString
& str
, bool partial
)
5174 return m_mainWin
->FindItem( start
, str
, partial
);
5177 long wxGenericListCtrl::FindItem( long start
, wxUIntPtr data
)
5179 return m_mainWin
->FindItem( start
, data
);
5182 long wxGenericListCtrl::FindItem( long WXUNUSED(start
), const wxPoint
& pt
,
5183 int WXUNUSED(direction
))
5185 return m_mainWin
->FindItem( pt
);
5188 long wxGenericListCtrl::HitTest( const wxPoint
&point
, int &flags
)
5190 return m_mainWin
->HitTest( (int)point
.x
, (int)point
.y
, flags
);
5193 long wxGenericListCtrl::InsertItem( wxListItem
& info
)
5195 m_mainWin
->InsertItem( info
);
5196 return info
.m_itemId
;
5199 long wxGenericListCtrl::InsertItem( long index
, const wxString
&label
)
5202 info
.m_text
= label
;
5203 info
.m_mask
= wxLIST_MASK_TEXT
;
5204 info
.m_itemId
= index
;
5205 return InsertItem( info
);
5208 long wxGenericListCtrl::InsertItem( long index
, int imageIndex
)
5211 info
.m_mask
= wxLIST_MASK_IMAGE
;
5212 info
.m_image
= imageIndex
;
5213 info
.m_itemId
= index
;
5214 return InsertItem( info
);
5217 long wxGenericListCtrl::InsertItem( long index
, const wxString
&label
, int imageIndex
)
5220 info
.m_text
= label
;
5221 info
.m_image
= imageIndex
;
5222 info
.m_mask
= wxLIST_MASK_TEXT
| wxLIST_MASK_IMAGE
;
5223 info
.m_itemId
= index
;
5224 return InsertItem( info
);
5227 long wxGenericListCtrl::InsertColumn( long col
, wxListItem
&item
)
5229 wxCHECK_MSG( m_headerWin
, -1, _T("can't add column in non report mode") );
5231 m_mainWin
->InsertColumn( col
, item
);
5233 // if we hadn't had a header before but have one now
5234 // then we need to relayout the window
5235 if ( GetColumnCount() == 1 && m_mainWin
->HasHeader() )
5236 ResizeReportView(true /* have header */);
5238 m_headerWin
->Refresh();
5243 long wxGenericListCtrl::InsertColumn( long col
, const wxString
&heading
,
5244 int format
, int width
)
5247 item
.m_mask
= wxLIST_MASK_TEXT
| wxLIST_MASK_FORMAT
;
5248 item
.m_text
= heading
;
5251 item
.m_mask
|= wxLIST_MASK_WIDTH
;
5252 item
.m_width
= width
;
5255 item
.m_format
= format
;
5257 return InsertColumn( col
, item
);
5260 bool wxGenericListCtrl::ScrollList( int WXUNUSED(dx
), int WXUNUSED(dy
) )
5266 // fn is a function which takes 3 long arguments: item1, item2, data.
5267 // item1 is the long data associated with a first item (NOT the index).
5268 // item2 is the long data associated with a second item (NOT the index).
5269 // data is the same value as passed to SortItems.
5270 // The return value is a negative number if the first item should precede the second
5271 // item, a positive number of the second item should precede the first,
5272 // or zero if the two items are equivalent.
5273 // data is arbitrary data to be passed to the sort function.
5275 bool wxGenericListCtrl::SortItems( wxListCtrlCompare fn
, long data
)
5277 m_mainWin
->SortItems( fn
, data
);
5281 // ----------------------------------------------------------------------------
5283 // ----------------------------------------------------------------------------
5285 void wxGenericListCtrl::OnSize(wxSizeEvent
& WXUNUSED(event
))
5290 ResizeReportView(m_mainWin
->HasHeader());
5291 m_mainWin
->RecalculatePositions();
5294 void wxGenericListCtrl::ResizeReportView(bool showHeader
)
5297 GetClientSize( &cw
, &ch
);
5301 m_headerWin
->SetSize( 0, 0, cw
, m_headerHeight
);
5302 m_mainWin
->SetSize( 0, m_headerHeight
+ 1, cw
, ch
- m_headerHeight
- 1 );
5304 else // no header window
5306 m_mainWin
->SetSize( 0, 0, cw
, ch
);
5310 void wxGenericListCtrl::OnInternalIdle()
5312 wxWindow::OnInternalIdle();
5314 // do it only if needed
5315 if ( !m_mainWin
->m_dirty
)
5318 m_mainWin
->RecalculatePositions();
5321 // ----------------------------------------------------------------------------
5323 // ----------------------------------------------------------------------------
5325 bool wxGenericListCtrl::SetBackgroundColour( const wxColour
&colour
)
5329 m_mainWin
->SetBackgroundColour( colour
);
5330 m_mainWin
->m_dirty
= true;
5336 bool wxGenericListCtrl::SetForegroundColour( const wxColour
&colour
)
5338 if ( !wxWindow::SetForegroundColour( colour
) )
5343 m_mainWin
->SetForegroundColour( colour
);
5344 m_mainWin
->m_dirty
= true;
5348 m_headerWin
->SetForegroundColour( colour
);
5353 bool wxGenericListCtrl::SetFont( const wxFont
&font
)
5355 if ( !wxWindow::SetFont( font
) )
5360 m_mainWin
->SetFont( font
);
5361 m_mainWin
->m_dirty
= true;
5366 m_headerWin
->SetFont( font
);
5367 CalculateAndSetHeaderHeight();
5376 #include "wx/listbox.h"
5381 wxGenericListCtrl::GetClassDefaultAttributes(wxWindowVariant variant
)
5384 // Use the same color scheme as wxListBox
5385 return wxListBox::GetClassDefaultAttributes(variant
);
5387 wxUnusedVar(variant
);
5388 wxVisualAttributes attr
;
5389 attr
.colFg
= wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT
);
5390 attr
.colBg
= wxSystemSettings::GetColour(wxSYS_COLOUR_LISTBOX
);
5391 attr
.font
= wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT
);
5396 // ----------------------------------------------------------------------------
5397 // methods forwarded to m_mainWin
5398 // ----------------------------------------------------------------------------
5400 #if wxUSE_DRAG_AND_DROP
5402 void wxGenericListCtrl::SetDropTarget( wxDropTarget
*dropTarget
)
5404 m_mainWin
->SetDropTarget( dropTarget
);
5407 wxDropTarget
*wxGenericListCtrl::GetDropTarget() const
5409 return m_mainWin
->GetDropTarget();
5414 bool wxGenericListCtrl::SetCursor( const wxCursor
&cursor
)
5416 return m_mainWin
? m_mainWin
->wxWindow::SetCursor(cursor
) : false;
5419 wxColour
wxGenericListCtrl::GetBackgroundColour() const
5421 return m_mainWin
? m_mainWin
->GetBackgroundColour() : wxColour();
5424 wxColour
wxGenericListCtrl::GetForegroundColour() const
5426 return m_mainWin
? m_mainWin
->GetForegroundColour() : wxColour();
5429 bool wxGenericListCtrl::DoPopupMenu( wxMenu
*menu
, int x
, int y
)
5432 return m_mainWin
->PopupMenu( menu
, x
, y
);
5438 void wxGenericListCtrl::SetFocus()
5440 // The test in window.cpp fails as we are a composite
5441 // window, so it checks against "this", but not m_mainWin.
5442 if ( DoFindFocus() != this )
5443 m_mainWin
->SetFocus();
5446 wxSize
wxGenericListCtrl::DoGetBestSize() const
5448 // Something is better than nothing...
5449 // 100x80 is what the MSW version will get from the default
5450 // wxControl::DoGetBestSize
5451 return wxSize(100, 80);
5454 // ----------------------------------------------------------------------------
5455 // virtual list control support
5456 // ----------------------------------------------------------------------------
5458 wxString
wxGenericListCtrl::OnGetItemText(long WXUNUSED(item
), long WXUNUSED(col
)) const
5460 // this is a pure virtual function, in fact - which is not really pure
5461 // because the controls which are not virtual don't need to implement it
5462 wxFAIL_MSG( _T("wxGenericListCtrl::OnGetItemText not supposed to be called") );
5464 return wxEmptyString
;
5467 int wxGenericListCtrl::OnGetItemImage(long WXUNUSED(item
)) const
5469 wxCHECK_MSG(!GetImageList(wxIMAGE_LIST_SMALL
),
5471 wxT("List control has an image list, OnGetItemImage or OnGetItemColumnImage should be overridden."));
5475 int wxGenericListCtrl::OnGetItemColumnImage(long item
, long column
) const
5478 return OnGetItemImage(item
);
5484 wxGenericListCtrl::OnGetItemAttr(long WXUNUSED_UNLESS_DEBUG(item
)) const
5486 wxASSERT_MSG( item
>= 0 && item
< GetItemCount(),
5487 _T("invalid item index in OnGetItemAttr()") );
5489 // no attributes by default
5493 void wxGenericListCtrl::SetItemCount(long count
)
5495 wxASSERT_MSG( IsVirtual(), _T("this is for virtual controls only") );
5497 m_mainWin
->SetItemCount(count
);
5500 void wxGenericListCtrl::RefreshItem(long item
)
5502 m_mainWin
->RefreshLine(item
);
5505 void wxGenericListCtrl::RefreshItems(long itemFrom
, long itemTo
)
5507 m_mainWin
->RefreshLines(itemFrom
, itemTo
);
5510 // Generic wxListCtrl is more or less a container for two other
5511 // windows which drawings are done upon. These are namely
5512 // 'm_headerWin' and 'm_mainWin'.
5513 // Here we override 'virtual wxWindow::Refresh()' to mimic the
5514 // behaviour wxListCtrl has under wxMSW.
5516 void wxGenericListCtrl::Refresh(bool eraseBackground
, const wxRect
*rect
)
5520 // The easy case, no rectangle specified.
5522 m_headerWin
->Refresh(eraseBackground
);
5525 m_mainWin
->Refresh(eraseBackground
);
5529 // Refresh the header window
5532 wxRect rectHeader
= m_headerWin
->GetRect();
5533 rectHeader
.Intersect(*rect
);
5534 if (rectHeader
.GetWidth() && rectHeader
.GetHeight())
5537 m_headerWin
->GetPosition(&x
, &y
);
5538 rectHeader
.Offset(-x
, -y
);
5539 m_headerWin
->Refresh(eraseBackground
, &rectHeader
);
5543 // Refresh the main window
5546 wxRect rectMain
= m_mainWin
->GetRect();
5547 rectMain
.Intersect(*rect
);
5548 if (rectMain
.GetWidth() && rectMain
.GetHeight())
5551 m_mainWin
->GetPosition(&x
, &y
);
5552 rectMain
.Offset(-x
, -y
);
5553 m_mainWin
->Refresh(eraseBackground
, &rectMain
);
5559 void wxGenericListCtrl::Freeze()
5561 m_mainWin
->Freeze();
5564 void wxGenericListCtrl::Thaw()
5569 #endif // wxUSE_LISTCTRL