1 /////////////////////////////////////////////////////////////////////////////
2 // Name: generic/listctrl.cpp
3 // Purpose: generic implementation of wxListCtrl
4 // Author: Robert Roebling
5 // Vadim Zeitlin (virtual list control support)
7 // Copyright: (c) 1998 Robert Roebling
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
14 1. we need to implement searching/sorting for virtual controls somehow
15 ?2. when changing selection the lines are refreshed twice
18 // ============================================================================
20 // ============================================================================
22 // ----------------------------------------------------------------------------
24 // ----------------------------------------------------------------------------
26 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
27 #pragma implementation "listctrl.h"
28 #pragma implementation "listctrlbase.h"
31 // For compilers that support precompilation, includes "wx.h".
32 #include "wx/wxprec.h"
43 #include "wx/dynarray.h"
45 #include "wx/dcscreen.h"
47 #include "wx/textctrl.h"
50 // under Win32 we always use the native version and also may use the generic
51 // one, however some things should be done only if we use only the generic
53 #if defined(__WIN32__) && !defined(__WXUNIVERSAL__)
54 #define HAVE_NATIVE_LISTCTRL
57 // if we have the native control, wx/listctrl.h declares it and not this one
58 #ifdef HAVE_NATIVE_LISTCTRL
59 #include "wx/generic/listctrl.h"
60 #else // !HAVE_NATIVE_LISTCTRL
61 #include "wx/listctrl.h"
63 // if we have a native version, its implementation file does all this
64 IMPLEMENT_DYNAMIC_CLASS(wxListItem
, wxObject
)
65 IMPLEMENT_DYNAMIC_CLASS(wxListView
, wxListCtrl
)
66 IMPLEMENT_DYNAMIC_CLASS(wxListEvent
, wxNotifyEvent
)
68 IMPLEMENT_DYNAMIC_CLASS(wxListCtrl
, wxGenericListCtrl
)
69 #endif // HAVE_NATIVE_LISTCTRL/!HAVE_NATIVE_LISTCTRL
71 #include "wx/selstore.h"
72 #include "wx/renderer.h"
76 #include "wx/mac/private.h"
81 // NOTE: If using the wxListBox visual attributes works everywhere then this can
82 // be removed, as well as the #else case below.
83 #define _USE_VISATTR 0
86 // ----------------------------------------------------------------------------
88 // ----------------------------------------------------------------------------
90 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_BEGIN_DRAG
)
91 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_BEGIN_RDRAG
)
92 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_BEGIN_LABEL_EDIT
)
93 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_END_LABEL_EDIT
)
94 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_DELETE_ITEM
)
95 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_DELETE_ALL_ITEMS
)
96 #if WXWIN_COMPATIBILITY_2_4
97 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_GET_INFO
)
98 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_SET_INFO
)
100 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_ITEM_SELECTED
)
101 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_ITEM_DESELECTED
)
102 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_KEY_DOWN
)
103 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_INSERT_ITEM
)
104 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_COL_CLICK
)
105 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_COL_RIGHT_CLICK
)
106 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_COL_BEGIN_DRAG
)
107 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_COL_DRAGGING
)
108 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_COL_END_DRAG
)
109 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_ITEM_RIGHT_CLICK
)
110 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_ITEM_MIDDLE_CLICK
)
111 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_ITEM_ACTIVATED
)
112 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_ITEM_FOCUSED
)
113 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_CACHE_HINT
)
115 // ----------------------------------------------------------------------------
117 // ----------------------------------------------------------------------------
119 // // the height of the header window (FIXME: should depend on its font!)
120 // static const int HEADER_HEIGHT = 23;
122 static const int SCROLL_UNIT_X
= 15;
124 // the spacing between the lines (in report mode)
125 static const int LINE_SPACING
= 0;
127 // extra margins around the text label
128 static const int EXTRA_WIDTH
= 4;
129 static const int EXTRA_HEIGHT
= 4;
131 // margin between the window and the items
132 static const int EXTRA_BORDER_X
= 2;
133 static const int EXTRA_BORDER_Y
= 2;
135 // offset for the header window
136 static const int HEADER_OFFSET_X
= 1;
137 static const int HEADER_OFFSET_Y
= 1;
139 // margin between rows of icons in [small] icon view
140 static const int MARGIN_BETWEEN_ROWS
= 6;
142 // when autosizing the columns, add some slack
143 static const int AUTOSIZE_COL_MARGIN
= 10;
145 // default and minimal widths for the header columns
146 static const int WIDTH_COL_DEFAULT
= 80;
147 static const int WIDTH_COL_MIN
= 10;
149 // the space between the image and the text in the report mode
150 static const int IMAGE_MARGIN_IN_REPORT_MODE
= 5;
152 // ============================================================================
154 // ============================================================================
156 //-----------------------------------------------------------------------------
157 // wxColWidthInfo (internal)
158 //-----------------------------------------------------------------------------
160 struct wxColWidthInfo
163 bool bNeedsUpdate
; // only set to true when an item whose
164 // width == nMaxWidth is removed
166 wxColWidthInfo(int w
= 0, bool needsUpdate
= false)
169 bNeedsUpdate
= needsUpdate
;
173 WX_DEFINE_ARRAY_PTR(wxColWidthInfo
*, ColWidthArray
);
175 //-----------------------------------------------------------------------------
176 // wxListItemData (internal)
177 //-----------------------------------------------------------------------------
179 class WXDLLEXPORT wxListItemData
182 wxListItemData(wxListMainWindow
*owner
);
185 void SetItem( const wxListItem
&info
);
186 void SetImage( int image
) { m_image
= image
; }
187 void SetData( wxUIntPtr data
) { m_data
= data
; }
188 void SetPosition( int x
, int y
);
189 void SetSize( int width
, int height
);
191 bool HasText() const { return !m_text
.empty(); }
192 const wxString
& GetText() const { return m_text
; }
193 void SetText(const wxString
& text
) { m_text
= text
; }
195 // we can't use empty string for measuring the string width/height, so
196 // always return something
197 wxString
GetTextForMeasuring() const
199 wxString s
= GetText();
206 bool IsHit( int x
, int y
) const;
210 int GetWidth() const;
211 int GetHeight() const;
213 int GetImage() const { return m_image
; }
214 bool HasImage() const { return GetImage() != -1; }
216 void GetItem( wxListItem
&info
) const;
218 void SetAttr(wxListItemAttr
*attr
) { m_attr
= attr
; }
219 wxListItemAttr
*GetAttr() const { return m_attr
; }
222 // the item image or -1
225 // user data associated with the item
228 // the item coordinates are not used in report mode, instead this pointer
229 // is NULL and the owner window is used to retrieve the item position and
233 // the list ctrl we are in
234 wxListMainWindow
*m_owner
;
236 // custom attributes or NULL
237 wxListItemAttr
*m_attr
;
240 // common part of all ctors
246 //-----------------------------------------------------------------------------
247 // wxListHeaderData (internal)
248 //-----------------------------------------------------------------------------
250 class WXDLLEXPORT wxListHeaderData
: public wxObject
254 wxListHeaderData( const wxListItem
&info
);
255 void SetItem( const wxListItem
&item
);
256 void SetPosition( int x
, int y
);
257 void SetWidth( int w
);
258 void SetFormat( int format
);
259 void SetHeight( int h
);
260 bool HasImage() const;
262 bool HasText() const { return !m_text
.empty(); }
263 const wxString
& GetText() const { return m_text
; }
264 void SetText(const wxString
& text
) { m_text
= text
; }
266 void GetItem( wxListItem
&item
);
268 bool IsHit( int x
, int y
) const;
269 int GetImage() const;
270 int GetWidth() const;
271 int GetFormat() const;
287 //-----------------------------------------------------------------------------
288 // wxListLineData (internal)
289 //-----------------------------------------------------------------------------
291 WX_DECLARE_LIST(wxListItemData
, wxListItemDataList
);
292 #include "wx/listimpl.cpp"
293 WX_DEFINE_LIST(wxListItemDataList
);
298 // the list of subitems: only may have more than one item in report mode
299 wxListItemDataList m_items
;
301 // this is not used in report view
313 // the part to be highlighted
314 wxRect m_rectHighlight
;
316 // extend all our rects to be centered inside the one of given width
317 void ExtendWidth(wxCoord w
)
319 wxASSERT_MSG( m_rectAll
.width
<= w
,
320 _T("width can only be increased") );
323 m_rectLabel
.x
= m_rectAll
.x
+ (w
- m_rectLabel
.width
)/2;
324 m_rectIcon
.x
= m_rectAll
.x
+ (w
- m_rectIcon
.width
)/2;
325 m_rectHighlight
.x
= m_rectAll
.x
+ (w
- m_rectHighlight
.width
)/2;
329 // is this item selected? [NB: not used in virtual mode]
332 // back pointer to the list ctrl
333 wxListMainWindow
*m_owner
;
336 wxListLineData(wxListMainWindow
*owner
);
340 WX_CLEAR_LIST(wxListItemDataList
, m_items
);
344 // are we in report mode?
345 inline bool InReportView() const;
347 // are we in virtual report mode?
348 inline bool IsVirtual() const;
350 // these 2 methods shouldn't be called for report view controls, in that
351 // case we determine our position/size ourselves
353 // calculate the size of the line
354 void CalculateSize( wxDC
*dc
, int spacing
);
356 // remember the position this line appears at
357 void SetPosition( int x
, int y
, int spacing
);
361 void SetImage( int image
) { SetImage(0, image
); }
362 int GetImage() const { return GetImage(0); }
363 bool HasImage() const { return GetImage() != -1; }
364 bool HasText() const { return !GetText(0).empty(); }
366 void SetItem( int index
, const wxListItem
&info
);
367 void GetItem( int index
, wxListItem
&info
);
369 wxString
GetText(int index
) const;
370 void SetText( int index
, const wxString s
);
372 wxListItemAttr
*GetAttr() const;
373 void SetAttr(wxListItemAttr
*attr
);
375 // return true if the highlighting really changed
376 bool Highlight( bool on
);
378 void ReverseHighlight();
380 bool IsHighlighted() const
382 wxASSERT_MSG( !IsVirtual(), _T("unexpected call to IsHighlighted") );
384 return m_highlighted
;
387 // draw the line on the given DC in icon/list mode
388 void Draw( wxDC
*dc
);
390 // the same in report mode
391 void DrawInReportMode( wxDC
*dc
,
393 const wxRect
& rectHL
,
397 // set the line to contain num items (only can be > 1 in report mode)
398 void InitItems( int num
);
400 // get the mode (i.e. style) of the list control
401 inline int GetMode() const;
403 // prepare the DC for drawing with these item's attributes, return true if
404 // we need to draw the items background to highlight it, false otherwise
405 bool SetAttributes(wxDC
*dc
,
406 const wxListItemAttr
*attr
,
409 // draw the text on the DC with the correct justification; also add an
410 // ellipsis if the text is too large to fit in the current width
411 void DrawTextFormatted(wxDC
*dc
, const wxString
&text
, int col
, int x
, int y
, int width
);
413 // these are only used by GetImage/SetImage above, we don't support images
414 // with subitems at the public API level yet
415 void SetImage( int index
, int image
);
416 int GetImage( int index
) const;
419 WX_DECLARE_EXPORTED_OBJARRAY(wxListLineData
, wxListLineDataArray
);
420 #include "wx/arrimpl.cpp"
421 WX_DEFINE_OBJARRAY(wxListLineDataArray
);
423 //-----------------------------------------------------------------------------
424 // wxListHeaderWindow (internal)
425 //-----------------------------------------------------------------------------
427 class WXDLLEXPORT wxListHeaderWindow
: public wxWindow
430 wxListMainWindow
*m_owner
;
431 wxCursor
*m_currentCursor
;
432 wxCursor
*m_resizeCursor
;
435 // column being resized or -1
438 // divider line position in logical (unscrolled) coords
441 // minimal position beyond which the divider line can't be dragged in
446 wxListHeaderWindow();
448 wxListHeaderWindow( wxWindow
*win
,
450 wxListMainWindow
*owner
,
451 const wxPoint
&pos
= wxDefaultPosition
,
452 const wxSize
&size
= wxDefaultSize
,
454 const wxString
&name
= wxT("wxlistctrlcolumntitles") );
456 virtual ~wxListHeaderWindow();
459 void AdjustDC(wxDC
& dc
);
461 void OnPaint( wxPaintEvent
&event
);
462 void OnMouse( wxMouseEvent
&event
);
463 void OnSetFocus( wxFocusEvent
&event
);
469 // common part of all ctors
472 // generate and process the list event of the given type, return true if
473 // it wasn't vetoed, i.e. if we should proceed
474 bool SendListEvent(wxEventType type
, wxPoint pos
);
476 DECLARE_DYNAMIC_CLASS(wxListHeaderWindow
)
477 DECLARE_EVENT_TABLE()
480 //-----------------------------------------------------------------------------
481 // wxListRenameTimer (internal)
482 //-----------------------------------------------------------------------------
484 class WXDLLEXPORT wxListRenameTimer
: public wxTimer
487 wxListMainWindow
*m_owner
;
490 wxListRenameTimer( wxListMainWindow
*owner
);
494 //-----------------------------------------------------------------------------
495 // wxListTextCtrl (internal)
496 //-----------------------------------------------------------------------------
498 class WXDLLEXPORT wxListTextCtrl
: public wxTextCtrl
501 wxListTextCtrl(wxListMainWindow
*owner
, size_t itemEdit
);
504 void OnChar( wxKeyEvent
&event
);
505 void OnKeyUp( wxKeyEvent
&event
);
506 void OnKillFocus( wxFocusEvent
&event
);
508 bool AcceptChanges();
512 wxListMainWindow
*m_owner
;
513 wxString m_startValue
;
516 bool m_aboutToFinish
;
518 DECLARE_EVENT_TABLE()
521 //-----------------------------------------------------------------------------
522 // wxListMainWindow (internal)
523 //-----------------------------------------------------------------------------
525 WX_DECLARE_LIST(wxListHeaderData
, wxListHeaderDataList
);
526 #include "wx/listimpl.cpp"
527 WX_DEFINE_LIST(wxListHeaderDataList
);
529 class wxListMainWindow
: public wxScrolledWindow
533 wxListMainWindow( wxWindow
*parent
,
535 const wxPoint
& pos
= wxDefaultPosition
,
536 const wxSize
& size
= wxDefaultSize
,
538 const wxString
&name
= _T("listctrlmainwindow") );
540 virtual ~wxListMainWindow();
542 wxWindow
*GetMainWindowOfCompositeControl() { return GetParent(); }
544 bool HasFlag(int flag
) const { return m_parent
->HasFlag(flag
); }
546 // return true if this is a virtual list control
547 bool IsVirtual() const { return HasFlag(wxLC_VIRTUAL
); }
549 // return true if the control is in report mode
550 bool InReportView() const { return HasFlag(wxLC_REPORT
); }
552 // return true if we are in single selection mode, false if multi sel
553 bool IsSingleSel() const { return HasFlag(wxLC_SINGLE_SEL
); }
555 // do we have a header window?
556 bool HasHeader() const
557 { return InReportView() && !HasFlag(wxLC_NO_HEADER
); }
559 void HighlightAll( bool on
);
561 // all these functions only do something if the line is currently visible
563 // change the line "selected" state, return true if it really changed
564 bool HighlightLine( size_t line
, bool highlight
= true);
566 // as HighlightLine() but do it for the range of lines: this is incredibly
567 // more efficient for virtual list controls!
569 // NB: unlike HighlightLine() this one does refresh the lines on screen
570 void HighlightLines( size_t lineFrom
, size_t lineTo
, bool on
= true );
572 // toggle the line state and refresh it
573 void ReverseHighlight( size_t line
)
574 { HighlightLine(line
, !IsHighlighted(line
)); RefreshLine(line
); }
576 // return true if the line is highlighted
577 bool IsHighlighted(size_t line
) const;
579 // refresh one or several lines at once
580 void RefreshLine( size_t line
);
581 void RefreshLines( size_t lineFrom
, size_t lineTo
);
583 // refresh all selected items
584 void RefreshSelected();
586 // refresh all lines below the given one: the difference with
587 // RefreshLines() is that the index here might not be a valid one (happens
588 // when the last line is deleted)
589 void RefreshAfter( size_t lineFrom
);
591 // the methods which are forwarded to wxListLineData itself in list/icon
592 // modes but are here because the lines don't store their positions in the
595 // get the bound rect for the entire line
596 wxRect
GetLineRect(size_t line
) const;
598 // get the bound rect of the label
599 wxRect
GetLineLabelRect(size_t line
) const;
601 // get the bound rect of the items icon (only may be called if we do have
603 wxRect
GetLineIconRect(size_t line
) const;
605 // get the rect to be highlighted when the item has focus
606 wxRect
GetLineHighlightRect(size_t line
) const;
608 // get the size of the total line rect
609 wxSize
GetLineSize(size_t line
) const
610 { return GetLineRect(line
).GetSize(); }
612 // return the hit code for the corresponding position (in this line)
613 long HitTestLine(size_t line
, int x
, int y
) const;
615 // bring the selected item into view, scrolling to it if necessary
616 void MoveToItem(size_t item
);
618 // bring the current item into view
619 void MoveToFocus() { MoveToItem(m_current
); }
621 // start editing the label of the given item
622 void EditLabel( long item
);
624 // suspend/resume redrawing the control
628 void OnRenameTimer();
629 bool OnRenameAccept(size_t itemEdit
, const wxString
& value
);
630 void OnRenameCancelled(size_t itemEdit
);
632 void OnMouse( wxMouseEvent
&event
);
634 // called to switch the selection from the current item to newCurrent,
635 void OnArrowChar( size_t newCurrent
, const wxKeyEvent
& event
);
637 void OnChar( wxKeyEvent
&event
);
638 void OnKeyDown( wxKeyEvent
&event
);
639 void OnSetFocus( wxFocusEvent
&event
);
640 void OnKillFocus( wxFocusEvent
&event
);
641 void OnScroll(wxScrollWinEvent
& event
) ;
643 void OnPaint( wxPaintEvent
&event
);
645 void DrawImage( int index
, wxDC
*dc
, int x
, int y
);
646 void GetImageSize( int index
, int &width
, int &height
) const;
647 int GetTextLength( const wxString
&s
) const;
649 void SetImageList( wxImageListType
*imageList
, int which
);
650 void SetItemSpacing( int spacing
, bool isSmall
= false );
651 int GetItemSpacing( bool isSmall
= false );
653 void SetColumn( int col
, wxListItem
&item
);
654 void SetColumnWidth( int col
, int width
);
655 void GetColumn( int col
, wxListItem
&item
) const;
656 int GetColumnWidth( int col
) const;
657 int GetColumnCount() const { return m_columns
.GetCount(); }
659 // returns the sum of the heights of all columns
660 int GetHeaderWidth() const;
662 int GetCountPerPage() const;
664 void SetItem( wxListItem
&item
);
665 void GetItem( wxListItem
&item
) const;
666 void SetItemState( long item
, long state
, long stateMask
);
667 void SetItemStateAll( long state
, long stateMask
);
668 int GetItemState( long item
, long stateMask
) const;
669 void GetItemRect( long index
, wxRect
&rect
) const;
670 wxRect
GetViewRect() const;
671 bool GetItemPosition( long item
, wxPoint
& pos
) const;
672 int GetSelectedItemCount() const;
674 wxString
GetItemText(long item
) const
677 info
.m_itemId
= item
;
682 void SetItemText(long item
, const wxString
& value
)
685 info
.m_mask
= wxLIST_MASK_TEXT
;
686 info
.m_itemId
= item
;
691 // set the scrollbars and update the positions of the items
692 void RecalculatePositions(bool noRefresh
= false);
694 // refresh the window and the header
697 long GetNextItem( long item
, int geometry
, int state
) const;
698 void DeleteItem( long index
);
699 void DeleteAllItems();
700 void DeleteColumn( int col
);
701 void DeleteEverything();
702 void EnsureVisible( long index
);
703 long FindItem( long start
, const wxString
& str
, bool partial
= false );
704 long FindItem( long start
, wxUIntPtr data
);
705 long FindItem( const wxPoint
& pt
);
706 long HitTest( int x
, int y
, int &flags
);
707 void InsertItem( wxListItem
&item
);
708 void InsertColumn( long col
, wxListItem
&item
);
709 int GetItemWidthWithImage(wxListItem
* item
);
710 void SortItems( wxListCtrlCompare fn
, long data
);
712 size_t GetItemCount() const;
713 bool IsEmpty() const { return GetItemCount() == 0; }
714 void SetItemCount(long count
);
716 // change the current (== focused) item, send a notification event
717 void ChangeCurrent(size_t current
);
718 void ResetCurrent() { ChangeCurrent((size_t)-1); }
719 bool HasCurrent() const { return m_current
!= (size_t)-1; }
721 // send out a wxListEvent
722 void SendNotify( size_t line
,
724 wxPoint point
= wxDefaultPosition
);
726 // override base class virtual to reset m_lineHeight when the font changes
727 virtual bool SetFont(const wxFont
& font
)
729 if ( !wxScrolledWindow::SetFont(font
) )
737 // these are for wxListLineData usage only
739 // get the backpointer to the list ctrl
740 wxGenericListCtrl
*GetListCtrl() const
742 return wxStaticCast(GetParent(), wxGenericListCtrl
);
745 // get the height of all lines (assuming they all do have the same height)
746 wxCoord
GetLineHeight() const;
748 // get the y position of the given line (only for report view)
749 wxCoord
GetLineY(size_t line
) const;
751 // get the brush to use for the item highlighting
752 wxBrush
*GetHighlightBrush() const
754 return m_hasFocus
? m_highlightBrush
: m_highlightUnfocusedBrush
;
758 // the array of all line objects for a non virtual list control (for the
759 // virtual list control we only ever use m_lines[0])
760 wxListLineDataArray m_lines
;
762 // the list of column objects
763 wxListHeaderDataList m_columns
;
765 // currently focused item or -1
768 // the number of lines per page
771 // this flag is set when something which should result in the window
772 // redrawing happens (i.e. an item was added or deleted, or its appearance
773 // changed) and OnPaint() doesn't redraw the window while it is set which
774 // allows to minimize the number of repaintings when a lot of items are
775 // being added. The real repainting occurs only after the next OnIdle()
779 wxColour
*m_highlightColour
;
780 wxImageListType
*m_small_image_list
;
781 wxImageListType
*m_normal_image_list
;
783 int m_normal_spacing
;
787 wxTimer
*m_renameTimer
;
791 ColWidthArray m_aColWidths
;
793 // for double click logic
794 size_t m_lineLastClicked
,
795 m_lineBeforeLastClicked
,
796 m_lineSelectSingleOnUp
;
799 // the total count of items in a virtual list control
802 // the object maintaining the items selection state, only used in virtual
804 wxSelectionStore m_selStore
;
806 // common part of all ctors
809 // get the line data for the given index
810 wxListLineData
*GetLine(size_t n
) const
812 wxASSERT_MSG( n
!= (size_t)-1, _T("invalid line index") );
816 wxConstCast(this, wxListMainWindow
)->CacheLineData(n
);
824 // get a dummy line which can be used for geometry calculations and such:
825 // you must use GetLine() if you want to really draw the line
826 wxListLineData
*GetDummyLine() const;
828 // cache the line data of the n-th line in m_lines[0]
829 void CacheLineData(size_t line
);
831 // get the range of visible lines
832 void GetVisibleLinesRange(size_t *from
, size_t *to
);
834 // force us to recalculate the range of visible lines
835 void ResetVisibleLinesRange() { m_lineFrom
= (size_t)-1; }
837 // get the colour to be used for drawing the rules
838 wxColour
GetRuleColour() const
840 return wxSystemSettings::GetColour(wxSYS_COLOUR_3DLIGHT
);
844 // initialize the current item if needed
845 void UpdateCurrent();
847 // delete all items but don't refresh: called from dtor
848 void DoDeleteAllItems();
850 // the height of one line using the current font
851 wxCoord m_lineHeight
;
853 // the total header width or 0 if not calculated yet
854 wxCoord m_headerWidth
;
856 // the first and last lines being shown on screen right now (inclusive),
857 // both may be -1 if they must be calculated so never access them directly:
858 // use GetVisibleLinesRange() above instead
862 // the brushes to use for item highlighting when we do/don't have focus
863 wxBrush
*m_highlightBrush
,
864 *m_highlightUnfocusedBrush
;
866 // if this is > 0, the control is frozen and doesn't redraw itself
867 size_t m_freezeCount
;
869 DECLARE_DYNAMIC_CLASS(wxListMainWindow
)
870 DECLARE_EVENT_TABLE()
872 friend class wxGenericListCtrl
;
875 // ============================================================================
877 // ============================================================================
879 //-----------------------------------------------------------------------------
881 //-----------------------------------------------------------------------------
883 wxListItemData::~wxListItemData()
885 // in the virtual list control the attributes are managed by the main
886 // program, so don't delete them
887 if ( !m_owner
->IsVirtual() )
895 void wxListItemData::Init()
903 wxListItemData::wxListItemData(wxListMainWindow
*owner
)
909 if ( owner
->InReportView() )
919 void wxListItemData::SetItem( const wxListItem
&info
)
921 if ( info
.m_mask
& wxLIST_MASK_TEXT
)
922 SetText(info
.m_text
);
923 if ( info
.m_mask
& wxLIST_MASK_IMAGE
)
924 m_image
= info
.m_image
;
925 if ( info
.m_mask
& wxLIST_MASK_DATA
)
926 m_data
= info
.m_data
;
928 if ( info
.HasAttributes() )
931 *m_attr
= *info
.GetAttributes();
933 m_attr
= new wxListItemAttr(*info
.GetAttributes());
941 m_rect
->width
= info
.m_width
;
945 void wxListItemData::SetPosition( int x
, int y
)
947 wxCHECK_RET( m_rect
, _T("unexpected SetPosition() call") );
953 void wxListItemData::SetSize( int width
, int height
)
955 wxCHECK_RET( m_rect
, _T("unexpected SetSize() call") );
958 m_rect
->width
= width
;
960 m_rect
->height
= height
;
963 bool wxListItemData::IsHit( int x
, int y
) const
965 wxCHECK_MSG( m_rect
, false, _T("can't be called in this mode") );
967 return wxRect(GetX(), GetY(), GetWidth(), GetHeight()).Inside(x
, y
);
970 int wxListItemData::GetX() const
972 wxCHECK_MSG( m_rect
, 0, _T("can't be called in this mode") );
977 int wxListItemData::GetY() const
979 wxCHECK_MSG( m_rect
, 0, _T("can't be called in this mode") );
984 int wxListItemData::GetWidth() const
986 wxCHECK_MSG( m_rect
, 0, _T("can't be called in this mode") );
988 return m_rect
->width
;
991 int wxListItemData::GetHeight() const
993 wxCHECK_MSG( m_rect
, 0, _T("can't be called in this mode") );
995 return m_rect
->height
;
998 void wxListItemData::GetItem( wxListItem
&info
) const
1000 info
.m_text
= m_text
;
1001 info
.m_image
= m_image
;
1002 info
.m_data
= m_data
;
1006 if ( m_attr
->HasTextColour() )
1007 info
.SetTextColour(m_attr
->GetTextColour());
1008 if ( m_attr
->HasBackgroundColour() )
1009 info
.SetBackgroundColour(m_attr
->GetBackgroundColour());
1010 if ( m_attr
->HasFont() )
1011 info
.SetFont(m_attr
->GetFont());
1015 //-----------------------------------------------------------------------------
1017 //-----------------------------------------------------------------------------
1019 void wxListHeaderData::Init()
1030 wxListHeaderData::wxListHeaderData()
1035 wxListHeaderData::wxListHeaderData( const wxListItem
&item
)
1042 void wxListHeaderData::SetItem( const wxListItem
&item
)
1044 m_mask
= item
.m_mask
;
1046 if ( m_mask
& wxLIST_MASK_TEXT
)
1047 m_text
= item
.m_text
;
1049 if ( m_mask
& wxLIST_MASK_IMAGE
)
1050 m_image
= item
.m_image
;
1052 if ( m_mask
& wxLIST_MASK_FORMAT
)
1053 m_format
= item
.m_format
;
1055 if ( m_mask
& wxLIST_MASK_WIDTH
)
1056 SetWidth(item
.m_width
);
1059 void wxListHeaderData::SetPosition( int x
, int y
)
1065 void wxListHeaderData::SetHeight( int h
)
1070 void wxListHeaderData::SetWidth( int w
)
1074 m_width
= WIDTH_COL_DEFAULT
;
1075 else if (m_width
< WIDTH_COL_MIN
)
1076 m_width
= WIDTH_COL_MIN
;
1079 void wxListHeaderData::SetFormat( int format
)
1084 bool wxListHeaderData::HasImage() const
1086 return m_image
!= -1;
1089 bool wxListHeaderData::IsHit( int x
, int y
) const
1091 return ((x
>= m_xpos
) && (x
<= m_xpos
+m_width
) && (y
>= m_ypos
) && (y
<= m_ypos
+m_height
));
1094 void wxListHeaderData::GetItem( wxListItem
& item
)
1096 item
.m_mask
= m_mask
;
1097 item
.m_text
= m_text
;
1098 item
.m_image
= m_image
;
1099 item
.m_format
= m_format
;
1100 item
.m_width
= m_width
;
1103 int wxListHeaderData::GetImage() const
1108 int wxListHeaderData::GetWidth() const
1113 int wxListHeaderData::GetFormat() const
1118 //-----------------------------------------------------------------------------
1120 //-----------------------------------------------------------------------------
1122 inline int wxListLineData::GetMode() const
1124 return m_owner
->GetListCtrl()->GetWindowStyleFlag() & wxLC_MASK_TYPE
;
1127 inline bool wxListLineData::InReportView() const
1129 return m_owner
->HasFlag(wxLC_REPORT
);
1132 inline bool wxListLineData::IsVirtual() const
1134 return m_owner
->IsVirtual();
1137 wxListLineData::wxListLineData( wxListMainWindow
*owner
)
1141 if ( InReportView() )
1147 m_gi
= new GeometryInfo
;
1150 m_highlighted
= false;
1152 InitItems( GetMode() == wxLC_REPORT
? m_owner
->GetColumnCount() : 1 );
1155 void wxListLineData::CalculateSize( wxDC
*dc
, int spacing
)
1157 wxListItemDataList::compatibility_iterator node
= m_items
.GetFirst();
1158 wxCHECK_RET( node
, _T("no subitems at all??") );
1160 wxListItemData
*item
= node
->GetData();
1165 switch ( GetMode() )
1168 case wxLC_SMALL_ICON
:
1169 m_gi
->m_rectAll
.width
= spacing
;
1171 s
= item
->GetText();
1176 m_gi
->m_rectLabel
.width
=
1177 m_gi
->m_rectLabel
.height
= 0;
1181 dc
->GetTextExtent( s
, &lw
, &lh
);
1185 m_gi
->m_rectAll
.height
= spacing
+ lh
;
1187 m_gi
->m_rectAll
.width
= lw
;
1189 m_gi
->m_rectLabel
.width
= lw
;
1190 m_gi
->m_rectLabel
.height
= lh
;
1193 if (item
->HasImage())
1196 m_owner
->GetImageSize( item
->GetImage(), w
, h
);
1197 m_gi
->m_rectIcon
.width
= w
+ 8;
1198 m_gi
->m_rectIcon
.height
= h
+ 8;
1200 if ( m_gi
->m_rectIcon
.width
> m_gi
->m_rectAll
.width
)
1201 m_gi
->m_rectAll
.width
= m_gi
->m_rectIcon
.width
;
1202 if ( m_gi
->m_rectIcon
.height
+ lh
> m_gi
->m_rectAll
.height
- 4 )
1203 m_gi
->m_rectAll
.height
= m_gi
->m_rectIcon
.height
+ lh
+ 4;
1206 if ( item
->HasText() )
1208 m_gi
->m_rectHighlight
.width
= m_gi
->m_rectLabel
.width
;
1209 m_gi
->m_rectHighlight
.height
= m_gi
->m_rectLabel
.height
;
1211 else // no text, highlight the icon
1213 m_gi
->m_rectHighlight
.width
= m_gi
->m_rectIcon
.width
;
1214 m_gi
->m_rectHighlight
.height
= m_gi
->m_rectIcon
.height
;
1219 s
= item
->GetTextForMeasuring();
1221 dc
->GetTextExtent( s
, &lw
, &lh
);
1225 m_gi
->m_rectLabel
.width
= lw
;
1226 m_gi
->m_rectLabel
.height
= lh
;
1228 m_gi
->m_rectAll
.width
= lw
;
1229 m_gi
->m_rectAll
.height
= lh
;
1231 if (item
->HasImage())
1234 m_owner
->GetImageSize( item
->GetImage(), w
, h
);
1235 m_gi
->m_rectIcon
.width
= w
;
1236 m_gi
->m_rectIcon
.height
= h
;
1238 m_gi
->m_rectAll
.width
+= 4 + w
;
1239 if (h
> m_gi
->m_rectAll
.height
)
1240 m_gi
->m_rectAll
.height
= h
;
1243 m_gi
->m_rectHighlight
.width
= m_gi
->m_rectAll
.width
;
1244 m_gi
->m_rectHighlight
.height
= m_gi
->m_rectAll
.height
;
1248 wxFAIL_MSG( _T("unexpected call to SetSize") );
1252 wxFAIL_MSG( _T("unknown mode") );
1256 void wxListLineData::SetPosition( int x
, int y
, int spacing
)
1258 wxListItemDataList::compatibility_iterator node
= m_items
.GetFirst();
1259 wxCHECK_RET( node
, _T("no subitems at all??") );
1261 wxListItemData
*item
= node
->GetData();
1263 switch ( GetMode() )
1266 case wxLC_SMALL_ICON
:
1267 m_gi
->m_rectAll
.x
= x
;
1268 m_gi
->m_rectAll
.y
= y
;
1270 if ( item
->HasImage() )
1272 m_gi
->m_rectIcon
.x
= m_gi
->m_rectAll
.x
+ 4 +
1273 (m_gi
->m_rectAll
.width
- m_gi
->m_rectIcon
.width
) / 2;
1274 m_gi
->m_rectIcon
.y
= m_gi
->m_rectAll
.y
+ 4;
1277 if ( item
->HasText() )
1279 if (m_gi
->m_rectAll
.width
> spacing
)
1280 m_gi
->m_rectLabel
.x
= m_gi
->m_rectAll
.x
+ 2;
1282 m_gi
->m_rectLabel
.x
= m_gi
->m_rectAll
.x
+ 2 + (spacing
/2) - (m_gi
->m_rectLabel
.width
/2);
1283 m_gi
->m_rectLabel
.y
= m_gi
->m_rectAll
.y
+ m_gi
->m_rectAll
.height
+ 2 - m_gi
->m_rectLabel
.height
;
1284 m_gi
->m_rectHighlight
.x
= m_gi
->m_rectLabel
.x
- 2;
1285 m_gi
->m_rectHighlight
.y
= m_gi
->m_rectLabel
.y
- 2;
1287 else // no text, highlight the icon
1289 m_gi
->m_rectHighlight
.x
= m_gi
->m_rectIcon
.x
- 4;
1290 m_gi
->m_rectHighlight
.y
= m_gi
->m_rectIcon
.y
- 4;
1295 m_gi
->m_rectAll
.x
= x
;
1296 m_gi
->m_rectAll
.y
= y
;
1298 m_gi
->m_rectHighlight
.x
= m_gi
->m_rectAll
.x
;
1299 m_gi
->m_rectHighlight
.y
= m_gi
->m_rectAll
.y
;
1300 m_gi
->m_rectLabel
.y
= m_gi
->m_rectAll
.y
+ 2;
1302 if (item
->HasImage())
1304 m_gi
->m_rectIcon
.x
= m_gi
->m_rectAll
.x
+ 2;
1305 m_gi
->m_rectIcon
.y
= m_gi
->m_rectAll
.y
+ 2;
1306 m_gi
->m_rectLabel
.x
= m_gi
->m_rectAll
.x
+ 6 + m_gi
->m_rectIcon
.width
;
1310 m_gi
->m_rectLabel
.x
= m_gi
->m_rectAll
.x
+ 2;
1315 wxFAIL_MSG( _T("unexpected call to SetPosition") );
1319 wxFAIL_MSG( _T("unknown mode") );
1323 void wxListLineData::InitItems( int num
)
1325 for (int i
= 0; i
< num
; i
++)
1326 m_items
.Append( new wxListItemData(m_owner
) );
1329 void wxListLineData::SetItem( int index
, const wxListItem
&info
)
1331 wxListItemDataList::compatibility_iterator node
= m_items
.Item( index
);
1332 wxCHECK_RET( node
, _T("invalid column index in SetItem") );
1334 wxListItemData
*item
= node
->GetData();
1335 item
->SetItem( info
);
1338 void wxListLineData::GetItem( int index
, wxListItem
&info
)
1340 wxListItemDataList::compatibility_iterator node
= m_items
.Item( index
);
1343 wxListItemData
*item
= node
->GetData();
1344 item
->GetItem( info
);
1348 wxString
wxListLineData::GetText(int index
) const
1352 wxListItemDataList::compatibility_iterator node
= m_items
.Item( index
);
1355 wxListItemData
*item
= node
->GetData();
1356 s
= item
->GetText();
1362 void wxListLineData::SetText( int index
, const wxString s
)
1364 wxListItemDataList::compatibility_iterator node
= m_items
.Item( index
);
1367 wxListItemData
*item
= node
->GetData();
1372 void wxListLineData::SetImage( int index
, int image
)
1374 wxListItemDataList::compatibility_iterator node
= m_items
.Item( index
);
1375 wxCHECK_RET( node
, _T("invalid column index in SetImage()") );
1377 wxListItemData
*item
= node
->GetData();
1378 item
->SetImage(image
);
1381 int wxListLineData::GetImage( int index
) const
1383 wxListItemDataList::compatibility_iterator node
= m_items
.Item( index
);
1384 wxCHECK_MSG( node
, -1, _T("invalid column index in GetImage()") );
1386 wxListItemData
*item
= node
->GetData();
1387 return item
->GetImage();
1390 wxListItemAttr
*wxListLineData::GetAttr() const
1392 wxListItemDataList::compatibility_iterator node
= m_items
.GetFirst();
1393 wxCHECK_MSG( node
, NULL
, _T("invalid column index in GetAttr()") );
1395 wxListItemData
*item
= node
->GetData();
1396 return item
->GetAttr();
1399 void wxListLineData::SetAttr(wxListItemAttr
*attr
)
1401 wxListItemDataList::compatibility_iterator node
= m_items
.GetFirst();
1402 wxCHECK_RET( node
, _T("invalid column index in SetAttr()") );
1404 wxListItemData
*item
= node
->GetData();
1405 item
->SetAttr(attr
);
1408 bool wxListLineData::SetAttributes(wxDC
*dc
,
1409 const wxListItemAttr
*attr
,
1412 wxWindow
*listctrl
= m_owner
->GetParent();
1416 // don't use foreground colour for drawing highlighted items - this might
1417 // make them completely invisible (and there is no way to do bit
1418 // arithmetics on wxColour, unfortunately)
1422 colText
= wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHTTEXT
);
1426 if ( attr
&& attr
->HasTextColour() )
1428 colText
= attr
->GetTextColour();
1432 colText
= listctrl
->GetForegroundColour();
1436 dc
->SetTextForeground(colText
);
1440 if ( attr
&& attr
->HasFont() )
1442 font
= attr
->GetFont();
1446 font
= listctrl
->GetFont();
1452 bool hasBgCol
= attr
&& attr
->HasBackgroundColour();
1453 if ( highlighted
|| hasBgCol
)
1457 dc
->SetBrush( *m_owner
->GetHighlightBrush() );
1461 dc
->SetBrush(wxBrush(attr
->GetBackgroundColour(), wxSOLID
));
1464 dc
->SetPen( *wxTRANSPARENT_PEN
);
1472 void wxListLineData::Draw( wxDC
*dc
)
1474 wxListItemDataList::compatibility_iterator node
= m_items
.GetFirst();
1475 wxCHECK_RET( node
, _T("no subitems at all??") );
1477 bool highlighted
= IsHighlighted();
1479 wxListItemAttr
*attr
= GetAttr();
1481 if ( SetAttributes(dc
, attr
, highlighted
) )
1483 dc
->DrawRectangle( m_gi
->m_rectHighlight
);
1486 // just for debugging to better see where the items are
1488 dc
->SetPen(*wxRED_PEN
);
1489 dc
->SetBrush(*wxTRANSPARENT_BRUSH
);
1490 dc
->DrawRectangle( m_gi
->m_rectAll
);
1491 dc
->SetPen(*wxGREEN_PEN
);
1492 dc
->DrawRectangle( m_gi
->m_rectIcon
);
1495 wxListItemData
*item
= node
->GetData();
1496 if (item
->HasImage())
1498 // centre the image inside our rectangle, this looks nicer when items
1499 // ae aligned in a row
1500 const wxRect
& rectIcon
= m_gi
->m_rectIcon
;
1502 m_owner
->DrawImage(item
->GetImage(), dc
, rectIcon
.x
, rectIcon
.y
);
1505 if (item
->HasText())
1507 const wxRect
& rectLabel
= m_gi
->m_rectLabel
;
1509 wxDCClipper
clipper(*dc
, rectLabel
);
1510 dc
->DrawText(item
->GetText(), rectLabel
.x
, rectLabel
.y
);
1514 void wxListLineData::DrawInReportMode( wxDC
*dc
,
1516 const wxRect
& rectHL
,
1519 // TODO: later we should support setting different attributes for
1520 // different columns - to do it, just add "col" argument to
1521 // GetAttr() and move these lines into the loop below
1522 wxListItemAttr
*attr
= GetAttr();
1523 if ( SetAttributes(dc
, attr
, highlighted
) )
1525 dc
->DrawRectangle( rectHL
);
1528 wxCoord x
= rect
.x
+ HEADER_OFFSET_X
,
1529 y
= rect
.y
+ (LINE_SPACING
+ EXTRA_HEIGHT
) / 2;
1532 for ( wxListItemDataList::compatibility_iterator node
= m_items
.GetFirst();
1534 node
= node
->GetNext(), col
++ )
1536 wxListItemData
*item
= node
->GetData();
1538 int width
= m_owner
->GetColumnWidth(col
);
1542 if ( item
->HasImage() )
1545 m_owner
->DrawImage( item
->GetImage(), dc
, xOld
, y
);
1546 m_owner
->GetImageSize( item
->GetImage(), ix
, iy
);
1548 ix
+= IMAGE_MARGIN_IN_REPORT_MODE
;
1554 wxDCClipper
clipper(*dc
, xOld
, y
, width
- 8, rect
.height
);
1556 if ( item
->HasText() )
1558 DrawTextFormatted(dc
, item
->GetText(), col
, xOld
, y
, width
- 8);
1563 void wxListLineData::DrawTextFormatted(wxDC
*dc
,
1564 const wxString
&text
,
1570 wxString drawntext
, ellipsis
;
1571 wxCoord w
, h
, base_w
;
1574 // determine if the string can fit inside the current width
1575 dc
->GetTextExtent(text
, &w
, &h
);
1578 // it can, draw it using the items alignment
1579 m_owner
->GetColumn(col
, item
);
1580 switch ( item
.GetAlign() )
1583 wxFAIL_MSG( _T("unknown list item format") );
1586 case wxLIST_FORMAT_LEFT
:
1590 case wxLIST_FORMAT_RIGHT
:
1594 case wxLIST_FORMAT_CENTER
:
1595 x
+= (width
- w
) / 2;
1599 dc
->DrawText(text
, x
, y
);
1601 else // otherwise, truncate and add an ellipsis if possible
1603 // determine the base width
1604 ellipsis
= wxString(wxT("..."));
1605 dc
->GetTextExtent(ellipsis
, &base_w
, &h
);
1607 // continue until we have enough space or only one character left
1609 size_t len
= text
.Length();
1610 drawntext
= text
.Left(len
);
1613 dc
->GetTextExtent(drawntext
.Last(), &w_c
, &h_c
);
1614 drawntext
.RemoveLast();
1617 if (w
+ base_w
<= width
)
1621 // if still not enough space, remove ellipsis characters
1622 while (ellipsis
.Length() > 0 && w
+ base_w
> width
)
1624 ellipsis
= ellipsis
.Left(ellipsis
.Length() - 1);
1625 dc
->GetTextExtent(ellipsis
, &base_w
, &h
);
1628 // now draw the text
1629 dc
->DrawText(drawntext
, x
, y
);
1630 dc
->DrawText(ellipsis
, x
+ w
, y
);
1634 bool wxListLineData::Highlight( bool on
)
1636 wxCHECK_MSG( !IsVirtual(), false, _T("unexpected call to Highlight") );
1638 if ( on
== m_highlighted
)
1646 void wxListLineData::ReverseHighlight( void )
1648 Highlight(!IsHighlighted());
1651 //-----------------------------------------------------------------------------
1652 // wxListHeaderWindow
1653 //-----------------------------------------------------------------------------
1655 IMPLEMENT_DYNAMIC_CLASS(wxListHeaderWindow
,wxWindow
)
1657 BEGIN_EVENT_TABLE(wxListHeaderWindow
,wxWindow
)
1658 EVT_PAINT (wxListHeaderWindow::OnPaint
)
1659 EVT_MOUSE_EVENTS (wxListHeaderWindow::OnMouse
)
1660 EVT_SET_FOCUS (wxListHeaderWindow::OnSetFocus
)
1663 void wxListHeaderWindow::Init()
1665 m_currentCursor
= (wxCursor
*) NULL
;
1666 m_isDragging
= false;
1670 wxListHeaderWindow::wxListHeaderWindow()
1674 m_owner
= (wxListMainWindow
*) NULL
;
1675 m_resizeCursor
= (wxCursor
*) NULL
;
1678 wxListHeaderWindow::wxListHeaderWindow( wxWindow
*win
,
1680 wxListMainWindow
*owner
,
1684 const wxString
&name
)
1685 : wxWindow( win
, id
, pos
, size
, style
, name
)
1690 m_resizeCursor
= new wxCursor( wxCURSOR_SIZEWE
);
1693 wxVisualAttributes attr
= wxPanel::GetClassDefaultAttributes();
1694 SetOwnForegroundColour( attr
.colFg
);
1695 SetOwnBackgroundColour( attr
.colBg
);
1697 SetOwnFont( attr
.font
);
1699 SetOwnForegroundColour( wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT
));
1700 SetOwnBackgroundColour( wxSystemSettings::GetColour(wxSYS_COLOUR_BTNFACE
));
1702 SetOwnFont( wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT
));
1706 wxListHeaderWindow::~wxListHeaderWindow()
1708 delete m_resizeCursor
;
1711 #ifdef __WXUNIVERSAL__
1712 #include "wx/univ/renderer.h"
1713 #include "wx/univ/theme.h"
1716 // shift the DC origin to match the position of the main window horz
1717 // scrollbar: this allows us to always use logical coords
1718 void wxListHeaderWindow::AdjustDC(wxDC
& dc
)
1721 m_owner
->GetScrollPixelsPerUnit( &xpix
, NULL
);
1724 m_owner
->GetViewStart( &x
, NULL
);
1726 // account for the horz scrollbar offset
1727 dc
.SetDeviceOrigin( -x
* xpix
, 0 );
1730 void wxListHeaderWindow::OnPaint( wxPaintEvent
&WXUNUSED(event
) )
1732 wxPaintDC
dc( this );
1739 dc
.SetFont( GetFont() );
1741 // width and height of the entire header window
1743 GetClientSize( &w
, &h
);
1744 m_owner
->CalcUnscrolledPosition(w
, 0, &w
, NULL
);
1746 dc
.SetBackgroundMode(wxTRANSPARENT
);
1748 dc
.SetTextForeground(GetForegroundColour());
1750 int x
= HEADER_OFFSET_X
;
1752 int numColumns
= m_owner
->GetColumnCount();
1754 for ( int i
= 0; i
< numColumns
&& x
< w
; i
++ )
1756 m_owner
->GetColumn( i
, item
);
1757 int wCol
= item
.m_width
;
1759 // the width of the rect to draw: make it smaller to fit entirely
1760 // inside the column rect
1768 wxRendererNative::Get().DrawHeaderButton
1772 wxRect(x
, HEADER_OFFSET_Y
, cw
, ch
),
1773 m_parent
->IsEnabled() ? 0
1774 : (int)wxCONTROL_DISABLED
1777 // see if we have enough space for the column label
1779 // for this we need the width of the text
1782 dc
.GetTextExtent(item
.GetText(), &wLabel
, &hLabel
);
1783 wLabel
+= 2*EXTRA_WIDTH
;
1785 // and the width of the icon, if any
1786 static const int MARGIN_BETWEEN_TEXT_AND_ICON
= 2;
1787 int ix
= 0, // init them just to suppress the compiler warnings
1789 const int image
= item
.m_image
;
1790 wxImageListType
*imageList
;
1793 imageList
= m_owner
->m_small_image_list
;
1796 imageList
->GetSize(image
, ix
, iy
);
1797 wLabel
+= ix
+ MARGIN_BETWEEN_TEXT_AND_ICON
;
1805 // ignore alignment if there is not enough space anyhow
1807 switch ( wLabel
< cw
? item
.GetAlign() : wxLIST_FORMAT_LEFT
)
1810 wxFAIL_MSG( _T("unknown list item format") );
1813 case wxLIST_FORMAT_LEFT
:
1817 case wxLIST_FORMAT_RIGHT
:
1818 xAligned
= x
+ cw
- wLabel
;
1821 case wxLIST_FORMAT_CENTER
:
1822 xAligned
= x
+ (cw
- wLabel
) / 2;
1827 // if we have an image, draw it on the right of the label
1834 xAligned
+ wLabel
- ix
- MARGIN_BETWEEN_TEXT_AND_ICON
,
1835 HEADER_OFFSET_Y
+ (h
- 4 - iy
)/2,
1836 wxIMAGELIST_DRAW_TRANSPARENT
1839 cw
-= ix
+ MARGIN_BETWEEN_TEXT_AND_ICON
;
1842 // draw the text clipping it so that it doesn't overwrite the column
1844 wxDCClipper
clipper(dc
, x
, HEADER_OFFSET_Y
, cw
, h
- 4 );
1846 dc
.DrawText( item
.GetText(),
1847 xAligned
+ EXTRA_WIDTH
, h
/ 2 - hLabel
/ 2 ); //HEADER_OFFSET_Y + EXTRA_HEIGHT );
1855 void wxListHeaderWindow::DrawCurrent()
1857 int x1
= m_currentX
;
1859 m_owner
->ClientToScreen( &x1
, &y1
);
1861 int x2
= m_currentX
;
1863 m_owner
->GetClientSize( NULL
, &y2
);
1864 m_owner
->ClientToScreen( &x2
, &y2
);
1867 dc
.SetLogicalFunction( wxINVERT
);
1868 dc
.SetPen( wxPen( *wxBLACK
, 2, wxSOLID
) );
1869 dc
.SetBrush( *wxTRANSPARENT_BRUSH
);
1873 dc
.DrawLine( x1
, y1
, x2
, y2
);
1875 dc
.SetLogicalFunction( wxCOPY
);
1877 dc
.SetPen( wxNullPen
);
1878 dc
.SetBrush( wxNullBrush
);
1881 void wxListHeaderWindow::OnMouse( wxMouseEvent
&event
)
1883 // we want to work with logical coords
1885 m_owner
->CalcUnscrolledPosition(event
.GetX(), 0, &x
, NULL
);
1886 int y
= event
.GetY();
1890 SendListEvent(wxEVT_COMMAND_LIST_COL_DRAGGING
, event
.GetPosition());
1892 // we don't draw the line beyond our window, but we allow dragging it
1895 GetClientSize( &w
, NULL
);
1896 m_owner
->CalcUnscrolledPosition(w
, 0, &w
, NULL
);
1899 // erase the line if it was drawn
1900 if ( m_currentX
< w
)
1903 if (event
.ButtonUp())
1906 m_isDragging
= false;
1908 m_owner
->SetColumnWidth( m_column
, m_currentX
- m_minX
);
1909 SendListEvent(wxEVT_COMMAND_LIST_COL_END_DRAG
, event
.GetPosition());
1916 m_currentX
= m_minX
+ 7;
1918 // draw in the new location
1919 if ( m_currentX
< w
)
1923 else // not dragging
1926 bool hit_border
= false;
1928 // end of the current column
1931 // find the column where this event occurred
1933 countCol
= m_owner
->GetColumnCount();
1934 for (col
= 0; col
< countCol
; col
++)
1936 xpos
+= m_owner
->GetColumnWidth( col
);
1939 if ( (abs(x
-xpos
) < 3) && (y
< 22) )
1941 // near the column border
1948 // inside the column
1955 if ( col
== countCol
)
1958 if (event
.LeftDown() || event
.RightUp())
1960 if (hit_border
&& event
.LeftDown())
1962 if ( SendListEvent(wxEVT_COMMAND_LIST_COL_BEGIN_DRAG
,
1963 event
.GetPosition()) )
1965 m_isDragging
= true;
1970 //else: column resizing was vetoed by the user code
1972 else // click on a column
1974 SendListEvent( event
.LeftDown()
1975 ? wxEVT_COMMAND_LIST_COL_CLICK
1976 : wxEVT_COMMAND_LIST_COL_RIGHT_CLICK
,
1977 event
.GetPosition());
1980 else if (event
.Moving())
1985 setCursor
= m_currentCursor
== wxSTANDARD_CURSOR
;
1986 m_currentCursor
= m_resizeCursor
;
1990 setCursor
= m_currentCursor
!= wxSTANDARD_CURSOR
;
1991 m_currentCursor
= wxSTANDARD_CURSOR
;
1995 SetCursor(*m_currentCursor
);
2000 void wxListHeaderWindow::OnSetFocus( wxFocusEvent
&WXUNUSED(event
) )
2002 m_owner
->SetFocus();
2006 bool wxListHeaderWindow::SendListEvent(wxEventType type
, wxPoint pos
)
2008 wxWindow
*parent
= GetParent();
2009 wxListEvent
le( type
, parent
->GetId() );
2010 le
.SetEventObject( parent
);
2011 le
.m_pointDrag
= pos
;
2013 // the position should be relative to the parent window, not
2014 // this one for compatibility with MSW and common sense: the
2015 // user code doesn't know anything at all about this header
2016 // window, so why should it get positions relative to it?
2017 le
.m_pointDrag
.y
-= GetSize().y
;
2019 le
.m_col
= m_column
;
2020 return !parent
->GetEventHandler()->ProcessEvent( le
) || le
.IsAllowed();
2023 //-----------------------------------------------------------------------------
2024 // wxListRenameTimer (internal)
2025 //-----------------------------------------------------------------------------
2027 wxListRenameTimer::wxListRenameTimer( wxListMainWindow
*owner
)
2032 void wxListRenameTimer::Notify()
2034 m_owner
->OnRenameTimer();
2037 //-----------------------------------------------------------------------------
2038 // wxListTextCtrl (internal)
2039 //-----------------------------------------------------------------------------
2041 BEGIN_EVENT_TABLE(wxListTextCtrl
,wxTextCtrl
)
2042 EVT_CHAR (wxListTextCtrl::OnChar
)
2043 EVT_KEY_UP (wxListTextCtrl::OnKeyUp
)
2044 EVT_KILL_FOCUS (wxListTextCtrl::OnKillFocus
)
2047 wxListTextCtrl::wxListTextCtrl(wxListMainWindow
*owner
, size_t itemEdit
)
2048 : m_startValue(owner
->GetItemText(itemEdit
)),
2049 m_itemEdited(itemEdit
)
2053 m_aboutToFinish
= false;
2055 wxRect rectLabel
= owner
->GetLineLabelRect(itemEdit
);
2057 m_owner
->CalcScrolledPosition(rectLabel
.x
, rectLabel
.y
,
2058 &rectLabel
.x
, &rectLabel
.y
);
2060 (void)Create(owner
, wxID_ANY
, m_startValue
,
2061 wxPoint(rectLabel
.x
-4,rectLabel
.y
-4),
2062 wxSize(rectLabel
.width
+11,rectLabel
.height
+8));
2065 void wxListTextCtrl::Finish()
2069 wxPendingDelete
.Append(this);
2073 m_owner
->SetFocusIgnoringChildren();
2077 bool wxListTextCtrl::AcceptChanges()
2079 const wxString value
= GetValue();
2081 if ( value
== m_startValue
)
2083 // nothing changed, always accept
2087 if ( !m_owner
->OnRenameAccept(m_itemEdited
, value
) )
2089 // vetoed by the user
2093 // accepted, do rename the item
2094 m_owner
->SetItemText(m_itemEdited
, value
);
2099 void wxListTextCtrl::OnChar( wxKeyEvent
&event
)
2101 switch ( event
.m_keyCode
)
2104 m_aboutToFinish
= true;
2105 // Notify the owner about the changes
2107 // Even if vetoed, close the control (consistent with MSW)
2113 m_owner
->OnRenameCancelled( m_itemEdited
);
2121 void wxListTextCtrl::OnKeyUp( wxKeyEvent
&event
)
2129 // auto-grow the textctrl:
2130 wxSize parentSize
= m_owner
->GetSize();
2131 wxPoint myPos
= GetPosition();
2132 wxSize mySize
= GetSize();
2134 GetTextExtent(GetValue() + _T("MM"), &sx
, &sy
);
2135 if (myPos
.x
+ sx
> parentSize
.x
)
2136 sx
= parentSize
.x
- myPos
.x
;
2139 SetSize(sx
, wxDefaultCoord
);
2144 void wxListTextCtrl::OnKillFocus( wxFocusEvent
&event
)
2146 if ( !m_finished
&& !m_aboutToFinish
)
2148 // We must finish regardless of success, otherwise we'll get
2152 if ( !AcceptChanges() )
2153 m_owner
->OnRenameCancelled( m_itemEdited
);
2156 // We must let the native text control handle focus, too, otherwise
2157 // it could have problems with the cursor (e.g., in wxGTK).
2161 //-----------------------------------------------------------------------------
2163 //-----------------------------------------------------------------------------
2165 IMPLEMENT_DYNAMIC_CLASS(wxListMainWindow
,wxScrolledWindow
)
2167 BEGIN_EVENT_TABLE(wxListMainWindow
,wxScrolledWindow
)
2168 EVT_PAINT (wxListMainWindow::OnPaint
)
2169 EVT_MOUSE_EVENTS (wxListMainWindow::OnMouse
)
2170 EVT_CHAR (wxListMainWindow::OnChar
)
2171 EVT_KEY_DOWN (wxListMainWindow::OnKeyDown
)
2172 EVT_SET_FOCUS (wxListMainWindow::OnSetFocus
)
2173 EVT_KILL_FOCUS (wxListMainWindow::OnKillFocus
)
2174 EVT_SCROLLWIN (wxListMainWindow::OnScroll
)
2177 void wxListMainWindow::Init()
2182 m_lineTo
= (size_t)-1;
2188 m_small_image_list
= (wxImageListType
*) NULL
;
2189 m_normal_image_list
= (wxImageListType
*) NULL
;
2191 m_small_spacing
= 30;
2192 m_normal_spacing
= 40;
2196 m_isCreated
= false;
2198 m_lastOnSame
= false;
2199 m_renameTimer
= new wxListRenameTimer( this );
2203 m_lineSelectSingleOnUp
=
2204 m_lineBeforeLastClicked
= (size_t)-1;
2209 wxListMainWindow::wxListMainWindow()
2214 m_highlightUnfocusedBrush
= (wxBrush
*) NULL
;
2217 wxListMainWindow::wxListMainWindow( wxWindow
*parent
,
2222 const wxString
&name
)
2223 : wxScrolledWindow( parent
, id
, pos
, size
,
2224 style
| wxHSCROLL
| wxVSCROLL
, name
)
2228 m_highlightBrush
= new wxBrush
2230 wxSystemSettings::GetColour
2232 wxSYS_COLOUR_HIGHLIGHT
2237 m_highlightUnfocusedBrush
= new wxBrush
2239 wxSystemSettings::GetColour
2241 wxSYS_COLOUR_BTNSHADOW
2246 SetScrollbars( 0, 0, 0, 0, 0, 0 );
2248 wxVisualAttributes attr
= wxGenericListCtrl::GetClassDefaultAttributes();
2249 SetOwnForegroundColour( attr
.colFg
);
2250 SetOwnBackgroundColour( attr
.colBg
);
2252 SetOwnFont( attr
.font
);
2255 wxListMainWindow::~wxListMainWindow()
2258 WX_CLEAR_LIST(wxListHeaderDataList
, m_columns
);
2259 WX_CLEAR_ARRAY(m_aColWidths
);
2261 delete m_highlightBrush
;
2262 delete m_highlightUnfocusedBrush
;
2264 delete m_renameTimer
;
2267 void wxListMainWindow::CacheLineData(size_t line
)
2269 wxGenericListCtrl
*listctrl
= GetListCtrl();
2271 wxListLineData
*ld
= GetDummyLine();
2273 size_t countCol
= GetColumnCount();
2274 for ( size_t col
= 0; col
< countCol
; col
++ )
2276 ld
->SetText(col
, listctrl
->OnGetItemText(line
, col
));
2279 ld
->SetImage(listctrl
->OnGetItemImage(line
));
2280 ld
->SetAttr(listctrl
->OnGetItemAttr(line
));
2283 wxListLineData
*wxListMainWindow::GetDummyLine() const
2285 wxASSERT_MSG( !IsEmpty(), _T("invalid line index") );
2287 wxASSERT_MSG( IsVirtual(), _T("GetDummyLine() shouldn't be called") );
2289 wxListMainWindow
*self
= wxConstCast(this, wxListMainWindow
);
2291 // we need to recreate the dummy line if the number of columns in the
2292 // control changed as it would have the incorrect number of fields
2294 if ( !m_lines
.IsEmpty() &&
2295 m_lines
[0].m_items
.GetCount() != (size_t)GetColumnCount() )
2297 self
->m_lines
.Clear();
2300 if ( m_lines
.IsEmpty() )
2302 wxListLineData
*line
= new wxListLineData(self
);
2303 self
->m_lines
.Add(line
);
2305 // don't waste extra memory -- there never going to be anything
2306 // else/more in this array
2307 self
->m_lines
.Shrink();
2313 // ----------------------------------------------------------------------------
2314 // line geometry (report mode only)
2315 // ----------------------------------------------------------------------------
2317 wxCoord
wxListMainWindow::GetLineHeight() const
2319 // we cache the line height as calling GetTextExtent() is slow
2320 if ( !m_lineHeight
)
2322 wxListMainWindow
*self
= wxConstCast(this, wxListMainWindow
);
2324 wxClientDC
dc( self
);
2325 dc
.SetFont( GetFont() );
2328 dc
.GetTextExtent(_T("H"), NULL
, &y
);
2330 if ( m_small_image_list
&& m_small_image_list
->GetImageCount() )
2334 m_small_image_list
->GetSize(0, iw
, ih
);
2339 self
->m_lineHeight
= y
+ LINE_SPACING
;
2342 return m_lineHeight
;
2345 wxCoord
wxListMainWindow::GetLineY(size_t line
) const
2347 wxASSERT_MSG( InReportView(), _T("only works in report mode") );
2349 return LINE_SPACING
+ line
*GetLineHeight();
2352 wxRect
wxListMainWindow::GetLineRect(size_t line
) const
2354 if ( !InReportView() )
2355 return GetLine(line
)->m_gi
->m_rectAll
;
2358 rect
.x
= HEADER_OFFSET_X
;
2359 rect
.y
= GetLineY(line
);
2360 rect
.width
= GetHeaderWidth();
2361 rect
.height
= GetLineHeight();
2366 wxRect
wxListMainWindow::GetLineLabelRect(size_t line
) const
2368 if ( !InReportView() )
2369 return GetLine(line
)->m_gi
->m_rectLabel
;
2372 rect
.x
= HEADER_OFFSET_X
;
2373 rect
.y
= GetLineY(line
);
2374 rect
.width
= GetColumnWidth(0);
2375 rect
.height
= GetLineHeight();
2380 wxRect
wxListMainWindow::GetLineIconRect(size_t line
) const
2382 if ( !InReportView() )
2383 return GetLine(line
)->m_gi
->m_rectIcon
;
2385 wxListLineData
*ld
= GetLine(line
);
2386 wxASSERT_MSG( ld
->HasImage(), _T("should have an image") );
2389 rect
.x
= HEADER_OFFSET_X
;
2390 rect
.y
= GetLineY(line
);
2391 GetImageSize(ld
->GetImage(), rect
.width
, rect
.height
);
2396 wxRect
wxListMainWindow::GetLineHighlightRect(size_t line
) const
2398 return InReportView() ? GetLineRect(line
)
2399 : GetLine(line
)->m_gi
->m_rectHighlight
;
2402 long wxListMainWindow::HitTestLine(size_t line
, int x
, int y
) const
2404 wxASSERT_MSG( line
< GetItemCount(), _T("invalid line in HitTestLine") );
2406 wxListLineData
*ld
= GetLine(line
);
2408 if ( ld
->HasImage() && GetLineIconRect(line
).Inside(x
, y
) )
2409 return wxLIST_HITTEST_ONITEMICON
;
2411 // VS: Testing for "ld->HasText() || InReportView()" instead of
2412 // "ld->HasText()" is needed to make empty lines in report view
2414 if ( ld
->HasText() || InReportView() )
2416 wxRect rect
= InReportView() ? GetLineRect(line
)
2417 : GetLineLabelRect(line
);
2419 if ( rect
.Inside(x
, y
) )
2420 return wxLIST_HITTEST_ONITEMLABEL
;
2426 // ----------------------------------------------------------------------------
2427 // highlight (selection) handling
2428 // ----------------------------------------------------------------------------
2430 bool wxListMainWindow::IsHighlighted(size_t line
) const
2434 return m_selStore
.IsSelected(line
);
2438 wxListLineData
*ld
= GetLine(line
);
2439 wxCHECK_MSG( ld
, false, _T("invalid index in IsHighlighted") );
2441 return ld
->IsHighlighted();
2445 void wxListMainWindow::HighlightLines( size_t lineFrom
,
2451 wxArrayInt linesChanged
;
2452 if ( !m_selStore
.SelectRange(lineFrom
, lineTo
, highlight
,
2455 // meny items changed state, refresh everything
2456 RefreshLines(lineFrom
, lineTo
);
2458 else // only a few items changed state, refresh only them
2460 size_t count
= linesChanged
.GetCount();
2461 for ( size_t n
= 0; n
< count
; n
++ )
2463 RefreshLine(linesChanged
[n
]);
2467 else // iterate over all items in non report view
2469 for ( size_t line
= lineFrom
; line
<= lineTo
; line
++ )
2471 if ( HighlightLine(line
, highlight
) )
2479 bool wxListMainWindow::HighlightLine( size_t line
, bool highlight
)
2485 changed
= m_selStore
.SelectItem(line
, highlight
);
2489 wxListLineData
*ld
= GetLine(line
);
2490 wxCHECK_MSG( ld
, false, _T("invalid index in HighlightLine") );
2492 changed
= ld
->Highlight(highlight
);
2497 SendNotify( line
, highlight
? wxEVT_COMMAND_LIST_ITEM_SELECTED
2498 : wxEVT_COMMAND_LIST_ITEM_DESELECTED
);
2504 void wxListMainWindow::RefreshLine( size_t line
)
2506 if ( InReportView() )
2508 size_t visibleFrom
, visibleTo
;
2509 GetVisibleLinesRange(&visibleFrom
, &visibleTo
);
2511 if ( line
< visibleFrom
|| line
> visibleTo
)
2515 wxRect rect
= GetLineRect(line
);
2517 CalcScrolledPosition( rect
.x
, rect
.y
, &rect
.x
, &rect
.y
);
2518 RefreshRect( rect
);
2521 void wxListMainWindow::RefreshLines( size_t lineFrom
, size_t lineTo
)
2523 // we suppose that they are ordered by caller
2524 wxASSERT_MSG( lineFrom
<= lineTo
, _T("indices in disorder") );
2526 wxASSERT_MSG( lineTo
< GetItemCount(), _T("invalid line range") );
2528 if ( InReportView() )
2530 size_t visibleFrom
, visibleTo
;
2531 GetVisibleLinesRange(&visibleFrom
, &visibleTo
);
2533 if ( lineFrom
< visibleFrom
)
2534 lineFrom
= visibleFrom
;
2535 if ( lineTo
> visibleTo
)
2540 rect
.y
= GetLineY(lineFrom
);
2541 rect
.width
= GetClientSize().x
;
2542 rect
.height
= GetLineY(lineTo
) - rect
.y
+ GetLineHeight();
2544 CalcScrolledPosition( rect
.x
, rect
.y
, &rect
.x
, &rect
.y
);
2545 RefreshRect( rect
);
2549 // TODO: this should be optimized...
2550 for ( size_t line
= lineFrom
; line
<= lineTo
; line
++ )
2557 void wxListMainWindow::RefreshAfter( size_t lineFrom
)
2559 if ( InReportView() )
2561 size_t visibleFrom
, visibleTo
;
2562 GetVisibleLinesRange(&visibleFrom
, &visibleTo
);
2564 if ( lineFrom
< visibleFrom
)
2565 lineFrom
= visibleFrom
;
2566 else if ( lineFrom
> visibleTo
)
2571 rect
.y
= GetLineY(lineFrom
);
2572 CalcScrolledPosition( rect
.x
, rect
.y
, &rect
.x
, &rect
.y
);
2574 wxSize size
= GetClientSize();
2575 rect
.width
= size
.x
;
2576 // refresh till the bottom of the window
2577 rect
.height
= size
.y
- rect
.y
;
2579 RefreshRect( rect
);
2583 // TODO: how to do it more efficiently?
2588 void wxListMainWindow::RefreshSelected()
2594 if ( InReportView() )
2596 GetVisibleLinesRange(&from
, &to
);
2601 to
= GetItemCount() - 1;
2604 if ( HasCurrent() && m_current
>= from
&& m_current
<= to
)
2606 RefreshLine(m_current
);
2609 for ( size_t line
= from
; line
<= to
; line
++ )
2611 // NB: the test works as expected even if m_current == -1
2612 if ( line
!= m_current
&& IsHighlighted(line
) )
2619 void wxListMainWindow::Freeze()
2624 void wxListMainWindow::Thaw()
2626 wxCHECK_RET( m_freezeCount
> 0, _T("thawing unfrozen list control?") );
2628 if ( !--m_freezeCount
)
2634 void wxListMainWindow::OnPaint( wxPaintEvent
&WXUNUSED(event
) )
2636 // Note: a wxPaintDC must be constructed even if no drawing is
2637 // done (a Windows requirement).
2638 wxPaintDC
dc( this );
2640 if ( IsEmpty() || m_freezeCount
)
2642 // nothing to draw or not the moment to draw it
2648 // delay the repainting until we calculate all the items positions
2655 CalcScrolledPosition( 0, 0, &dev_x
, &dev_y
);
2659 dc
.SetFont( GetFont() );
2661 if ( InReportView() )
2663 int lineHeight
= GetLineHeight();
2665 size_t visibleFrom
, visibleTo
;
2666 GetVisibleLinesRange(&visibleFrom
, &visibleTo
);
2669 wxCoord xOrig
, yOrig
;
2670 CalcUnscrolledPosition(0, 0, &xOrig
, &yOrig
);
2672 // tell the caller cache to cache the data
2675 wxListEvent
evCache(wxEVT_COMMAND_LIST_CACHE_HINT
,
2676 GetParent()->GetId());
2677 evCache
.SetEventObject( GetParent() );
2678 evCache
.m_oldItemIndex
= visibleFrom
;
2679 evCache
.m_itemIndex
= visibleTo
;
2680 GetParent()->GetEventHandler()->ProcessEvent( evCache
);
2683 for ( size_t line
= visibleFrom
; line
<= visibleTo
; line
++ )
2685 rectLine
= GetLineRect(line
);
2687 if ( !IsExposed(rectLine
.x
- xOrig
, rectLine
.y
- yOrig
,
2688 rectLine
.width
, rectLine
.height
) )
2690 // don't redraw unaffected lines to avoid flicker
2694 GetLine(line
)->DrawInReportMode( &dc
,
2696 GetLineHighlightRect(line
),
2697 IsHighlighted(line
) );
2700 if ( HasFlag(wxLC_HRULES
) )
2702 wxPen
pen(GetRuleColour(), 1, wxSOLID
);
2703 wxSize clientSize
= GetClientSize();
2705 // Don't draw the first one
2706 for ( size_t i
= visibleFrom
+1; i
<= visibleTo
; i
++ )
2709 dc
.SetBrush( *wxTRANSPARENT_BRUSH
);
2710 dc
.DrawLine(0 - dev_x
, i
*lineHeight
,
2711 clientSize
.x
- dev_x
, i
*lineHeight
);
2714 // Draw last horizontal rule
2715 if ( visibleTo
== GetItemCount() - 1 )
2718 dc
.SetBrush( *wxTRANSPARENT_BRUSH
);
2719 dc
.DrawLine(0 - dev_x
, (m_lineTo
+1)*lineHeight
,
2720 clientSize
.x
- dev_x
, (m_lineTo
+1)*lineHeight
);
2724 // Draw vertical rules if required
2725 if ( HasFlag(wxLC_VRULES
) && !IsEmpty() )
2727 wxPen
pen(GetRuleColour(), 1, wxSOLID
);
2729 wxRect firstItemRect
;
2730 wxRect lastItemRect
;
2731 GetItemRect(visibleFrom
, firstItemRect
);
2732 GetItemRect(visibleTo
, lastItemRect
);
2733 int x
= firstItemRect
.GetX();
2735 dc
.SetBrush(* wxTRANSPARENT_BRUSH
);
2736 for (int col
= 0; col
< GetColumnCount(); col
++)
2738 int colWidth
= GetColumnWidth(col
);
2740 dc
.DrawLine(x
- dev_x
- 2, firstItemRect
.GetY() - 1 - dev_y
,
2741 x
- dev_x
- 2, lastItemRect
.GetBottom() + 1 - dev_y
);
2747 size_t count
= GetItemCount();
2748 for ( size_t i
= 0; i
< count
; i
++ )
2750 GetLine(i
)->Draw( &dc
);
2755 // Don't draw rect outline under Mac at all.
2760 dc
.SetPen( *wxBLACK_PEN
);
2761 dc
.SetBrush( *wxTRANSPARENT_BRUSH
);
2762 dc
.DrawRectangle( GetLineHighlightRect(m_current
) );
2770 void wxListMainWindow::HighlightAll( bool on
)
2772 if ( IsSingleSel() )
2774 wxASSERT_MSG( !on
, _T("can't do this in a single sel control") );
2776 // we just have one item to turn off
2777 if ( HasCurrent() && IsHighlighted(m_current
) )
2779 HighlightLine(m_current
, false);
2780 RefreshLine(m_current
);
2785 HighlightLines(0, GetItemCount() - 1, on
);
2789 void wxListMainWindow::SendNotify( size_t line
,
2790 wxEventType command
,
2793 wxListEvent
le( command
, GetParent()->GetId() );
2794 le
.SetEventObject( GetParent() );
2795 le
.m_itemIndex
= line
;
2797 // set only for events which have position
2798 if ( point
!= wxDefaultPosition
)
2799 le
.m_pointDrag
= point
;
2801 // don't try to get the line info for virtual list controls: the main
2802 // program has it anyhow and if we did it would result in accessing all
2803 // the lines, even those which are not visible now and this is precisely
2804 // what we're trying to avoid
2805 if ( !IsVirtual() && (command
!= wxEVT_COMMAND_LIST_DELETE_ITEM
) )
2807 if ( line
!= (size_t)-1 )
2809 GetLine(line
)->GetItem( 0, le
.m_item
);
2811 //else: this happens for wxEVT_COMMAND_LIST_ITEM_FOCUSED event
2813 //else: there may be no more such item
2815 GetParent()->GetEventHandler()->ProcessEvent( le
);
2818 void wxListMainWindow::ChangeCurrent(size_t current
)
2820 m_current
= current
;
2822 SendNotify(current
, wxEVT_COMMAND_LIST_ITEM_FOCUSED
);
2825 void wxListMainWindow::EditLabel( long item
)
2827 wxCHECK_RET( (item
>= 0) && ((size_t)item
< GetItemCount()),
2828 wxT("wrong index in wxGenericListCtrl::EditLabel()") );
2830 size_t itemEdit
= (size_t)item
;
2832 wxListEvent
le( wxEVT_COMMAND_LIST_BEGIN_LABEL_EDIT
, GetParent()->GetId() );
2833 le
.SetEventObject( GetParent() );
2834 le
.m_itemIndex
= item
;
2835 wxListLineData
*data
= GetLine(itemEdit
);
2836 wxCHECK_RET( data
, _T("invalid index in EditLabel()") );
2837 data
->GetItem( 0, le
.m_item
);
2838 if ( GetParent()->GetEventHandler()->ProcessEvent( le
) && !le
.IsAllowed() )
2840 // vetoed by user code
2844 // We have to call this here because the label in question might just have
2845 // been added and no screen update taken place.
2849 wxListTextCtrl
*text
= new wxListTextCtrl(this, itemEdit
);
2854 void wxListMainWindow::OnRenameTimer()
2856 wxCHECK_RET( HasCurrent(), wxT("unexpected rename timer") );
2858 EditLabel( m_current
);
2861 bool wxListMainWindow::OnRenameAccept(size_t itemEdit
, const wxString
& value
)
2863 wxListEvent
le( wxEVT_COMMAND_LIST_END_LABEL_EDIT
, GetParent()->GetId() );
2864 le
.SetEventObject( GetParent() );
2865 le
.m_itemIndex
= itemEdit
;
2867 wxListLineData
*data
= GetLine(itemEdit
);
2868 wxCHECK_MSG( data
, false, _T("invalid index in OnRenameAccept()") );
2870 data
->GetItem( 0, le
.m_item
);
2871 le
.m_item
.m_text
= value
;
2872 return !GetParent()->GetEventHandler()->ProcessEvent( le
) ||
2876 void wxListMainWindow::OnRenameCancelled(size_t itemEdit
)
2878 // let owner know that the edit was cancelled
2879 wxListEvent
le( wxEVT_COMMAND_LIST_END_LABEL_EDIT
, GetParent()->GetId() );
2881 le
.SetEditCanceled(true);
2883 le
.SetEventObject( GetParent() );
2884 le
.m_itemIndex
= itemEdit
;
2886 wxListLineData
*data
= GetLine(itemEdit
);
2887 wxCHECK_RET( data
, _T("invalid index in OnRenameCancelled()") );
2889 data
->GetItem( 0, le
.m_item
);
2891 GetEventHandler()->ProcessEvent( le
);
2894 void wxListMainWindow::OnMouse( wxMouseEvent
&event
)
2896 event
.SetEventObject( GetParent() );
2897 if ( GetParent()->GetEventHandler()->ProcessEvent( event
) )
2900 if (event
.GetEventType() == wxEVT_MOUSEWHEEL
)
2902 // let the base handle mouse wheel events.
2907 if ( !HasCurrent() || IsEmpty() )
2913 if ( !(event
.Dragging() || event
.ButtonDown() || event
.LeftUp() ||
2914 event
.ButtonDClick()) )
2917 int x
= event
.GetX();
2918 int y
= event
.GetY();
2919 CalcUnscrolledPosition( x
, y
, &x
, &y
);
2921 // where did we hit it (if we did)?
2924 size_t count
= GetItemCount(),
2927 if ( InReportView() )
2929 current
= y
/ GetLineHeight();
2930 if ( current
< count
)
2931 hitResult
= HitTestLine(current
, x
, y
);
2935 // TODO: optimize it too! this is less simple than for report view but
2936 // enumerating all items is still not a way to do it!!
2937 for ( current
= 0; current
< count
; current
++ )
2939 hitResult
= HitTestLine(current
, x
, y
);
2945 if (event
.Dragging())
2947 if (m_dragCount
== 0)
2949 // we have to report the raw, physical coords as we want to be
2950 // able to call HitTest(event.m_pointDrag) from the user code to
2951 // get the item being dragged
2952 m_dragStart
= event
.GetPosition();
2957 if (m_dragCount
!= 3)
2960 int command
= event
.RightIsDown() ? wxEVT_COMMAND_LIST_BEGIN_RDRAG
2961 : wxEVT_COMMAND_LIST_BEGIN_DRAG
;
2963 wxListEvent
le( command
, GetParent()->GetId() );
2964 le
.SetEventObject( GetParent() );
2965 le
.m_itemIndex
= m_lineLastClicked
;
2966 le
.m_pointDrag
= m_dragStart
;
2967 GetParent()->GetEventHandler()->ProcessEvent( le
);
2978 // outside of any item
2982 bool forceClick
= false;
2983 if (event
.ButtonDClick())
2985 m_renameTimer
->Stop();
2986 m_lastOnSame
= false;
2988 if ( current
== m_lineLastClicked
)
2990 SendNotify( current
, wxEVT_COMMAND_LIST_ITEM_ACTIVATED
);
2996 // The first click was on another item, so don't interpret this as
2997 // a double click, but as a simple click instead
3004 if(m_lineSelectSingleOnUp
!= (size_t) -1)
3006 // select single line
3007 HighlightAll( false );
3008 ReverseHighlight(m_lineSelectSingleOnUp
);
3012 if ((current
== m_current
) &&
3013 (hitResult
== wxLIST_HITTEST_ONITEMLABEL
) &&
3014 HasFlag(wxLC_EDIT_LABELS
) )
3016 m_renameTimer
->Start( 100, true );
3019 m_lastOnSame
= false;
3020 m_lineSelectSingleOnUp
= (size_t) -1;
3024 // This is necessary, because after a DnD operation in
3025 // from and to ourself, the up event is swallowed by the
3026 // DnD code. So on next non-up event (which means here and
3027 // now) m_lineSelectSingleOnUp should be reset.
3028 m_lineSelectSingleOnUp
= (size_t) -1;
3030 if (event
.RightDown())
3032 m_lineBeforeLastClicked
= m_lineLastClicked
;
3033 m_lineLastClicked
= current
;
3034 // If the item is already selected, do not update the selection.
3035 // Multi-selections should not be cleared if a selected item is clicked.
3036 if (!IsHighlighted(current
))
3038 HighlightAll(false);
3039 ChangeCurrent(current
);
3040 ReverseHighlight(m_current
);
3042 SendNotify( current
, wxEVT_COMMAND_LIST_ITEM_RIGHT_CLICK
,
3043 event
.GetPosition() );
3044 // Allow generation of context menu event
3047 else if (event
.MiddleDown())
3049 SendNotify( current
, wxEVT_COMMAND_LIST_ITEM_MIDDLE_CLICK
);
3051 else if ( event
.LeftDown() || forceClick
)
3053 m_lineBeforeLastClicked
= m_lineLastClicked
;
3054 m_lineLastClicked
= current
;
3056 size_t oldCurrent
= m_current
;
3057 bool oldWasSelected
= IsHighlighted(m_current
);
3059 bool cmdModifierDown
= event
.CmdDown();
3060 if ( IsSingleSel() || !(cmdModifierDown
|| event
.ShiftDown()) )
3062 if( IsSingleSel() || !IsHighlighted(current
) )
3064 HighlightAll( false );
3066 ChangeCurrent(current
);
3068 ReverseHighlight(m_current
);
3070 else // multi sel & current is highlighted & no mod keys
3072 m_lineSelectSingleOnUp
= current
;
3073 ChangeCurrent(current
); // change focus
3076 else // multi sel & either ctrl or shift is down
3078 if (cmdModifierDown
)
3080 ChangeCurrent(current
);
3082 ReverseHighlight(m_current
);
3084 else if (event
.ShiftDown())
3086 ChangeCurrent(current
);
3088 size_t lineFrom
= oldCurrent
,
3091 if ( lineTo
< lineFrom
)
3094 lineFrom
= m_current
;
3097 HighlightLines(lineFrom
, lineTo
);
3099 else // !ctrl, !shift
3101 // test in the enclosing if should make it impossible
3102 wxFAIL_MSG( _T("how did we get here?") );
3106 if (m_current
!= oldCurrent
)
3108 RefreshLine( oldCurrent
);
3111 // forceClick is only set if the previous click was on another item
3112 m_lastOnSame
= !forceClick
&& (m_current
== oldCurrent
) && oldWasSelected
;
3116 void wxListMainWindow::MoveToItem(size_t item
)
3118 if ( item
== (size_t)-1 )
3121 wxRect rect
= GetLineRect(item
);
3123 int client_w
, client_h
;
3124 GetClientSize( &client_w
, &client_h
);
3126 const int hLine
= GetLineHeight();
3128 int view_x
= SCROLL_UNIT_X
*GetScrollPos( wxHORIZONTAL
);
3129 int view_y
= hLine
*GetScrollPos( wxVERTICAL
);
3131 if ( InReportView() )
3133 // the next we need the range of lines shown it might be different, so
3135 ResetVisibleLinesRange();
3137 if (rect
.y
< view_y
)
3138 Scroll( -1, rect
.y
/hLine
);
3139 if (rect
.y
+rect
.height
+5 > view_y
+client_h
)
3140 Scroll( -1, (rect
.y
+rect
.height
-client_h
+hLine
)/hLine
);
3144 if (rect
.x
-view_x
< 5)
3145 Scroll( (rect
.x
-5)/SCROLL_UNIT_X
, -1 );
3146 if (rect
.x
+rect
.width
-5 > view_x
+client_w
)
3147 Scroll( (rect
.x
+rect
.width
-client_w
+SCROLL_UNIT_X
)/SCROLL_UNIT_X
, -1 );
3151 // ----------------------------------------------------------------------------
3152 // keyboard handling
3153 // ----------------------------------------------------------------------------
3155 void wxListMainWindow::OnArrowChar(size_t newCurrent
, const wxKeyEvent
& event
)
3157 wxCHECK_RET( newCurrent
< (size_t)GetItemCount(),
3158 _T("invalid item index in OnArrowChar()") );
3160 size_t oldCurrent
= m_current
;
3162 // in single selection we just ignore Shift as we can't select several
3164 if ( event
.ShiftDown() && !IsSingleSel() )
3166 ChangeCurrent(newCurrent
);
3168 // refresh the old focus to remove it
3169 RefreshLine( oldCurrent
);
3171 // select all the items between the old and the new one
3172 if ( oldCurrent
> newCurrent
)
3174 newCurrent
= oldCurrent
;
3175 oldCurrent
= m_current
;
3178 HighlightLines(oldCurrent
, newCurrent
);
3182 // all previously selected items are unselected unless ctrl is held
3183 if ( !event
.ControlDown() )
3184 HighlightAll(false);
3186 ChangeCurrent(newCurrent
);
3188 // refresh the old focus to remove it
3189 RefreshLine( oldCurrent
);
3191 if ( !event
.ControlDown() )
3193 HighlightLine( m_current
, true );
3197 RefreshLine( m_current
);
3202 void wxListMainWindow::OnKeyDown( wxKeyEvent
&event
)
3204 wxWindow
*parent
= GetParent();
3206 /* we propagate the key event up */
3207 wxKeyEvent
ke( wxEVT_KEY_DOWN
);
3208 ke
.m_shiftDown
= event
.m_shiftDown
;
3209 ke
.m_controlDown
= event
.m_controlDown
;
3210 ke
.m_altDown
= event
.m_altDown
;
3211 ke
.m_metaDown
= event
.m_metaDown
;
3212 ke
.m_keyCode
= event
.m_keyCode
;
3215 ke
.SetEventObject( parent
);
3216 if (parent
->GetEventHandler()->ProcessEvent( ke
)) return;
3221 void wxListMainWindow::OnChar( wxKeyEvent
&event
)
3223 wxWindow
*parent
= GetParent();
3225 /* we send a list_key event up */
3228 wxListEvent
le( wxEVT_COMMAND_LIST_KEY_DOWN
, GetParent()->GetId() );
3229 le
.m_itemIndex
= m_current
;
3230 GetLine(m_current
)->GetItem( 0, le
.m_item
);
3231 le
.m_code
= event
.GetKeyCode();
3232 le
.SetEventObject( parent
);
3233 parent
->GetEventHandler()->ProcessEvent( le
);
3236 /* we propagate the char event up */
3237 wxKeyEvent
ke( wxEVT_CHAR
);
3238 ke
.m_shiftDown
= event
.m_shiftDown
;
3239 ke
.m_controlDown
= event
.m_controlDown
;
3240 ke
.m_altDown
= event
.m_altDown
;
3241 ke
.m_metaDown
= event
.m_metaDown
;
3242 ke
.m_keyCode
= event
.m_keyCode
;
3245 ke
.SetEventObject( parent
);
3246 if (parent
->GetEventHandler()->ProcessEvent( ke
)) return;
3248 if (event
.GetKeyCode() == WXK_TAB
)
3250 wxNavigationKeyEvent nevent
;
3251 nevent
.SetWindowChange( event
.ControlDown() );
3252 nevent
.SetDirection( !event
.ShiftDown() );
3253 nevent
.SetEventObject( GetParent()->GetParent() );
3254 nevent
.SetCurrentFocus( m_parent
);
3255 if (GetParent()->GetParent()->GetEventHandler()->ProcessEvent( nevent
))
3259 /* no item -> nothing to do */
3266 switch (event
.GetKeyCode())
3269 if ( m_current
> 0 )
3270 OnArrowChar( m_current
- 1, event
);
3274 if ( m_current
< (size_t)GetItemCount() - 1 )
3275 OnArrowChar( m_current
+ 1, event
);
3280 OnArrowChar( GetItemCount() - 1, event
);
3285 OnArrowChar( 0, event
);
3290 int steps
= InReportView() ? m_linesPerPage
- 1 : m_current
% m_linesPerPage
;
3292 int index
= m_current
- steps
;
3296 OnArrowChar( index
, event
);
3302 int steps
= InReportView()
3303 ? m_linesPerPage
- 1
3304 : m_linesPerPage
- (m_current
% m_linesPerPage
) - 1;
3306 size_t index
= m_current
+ steps
;
3307 size_t count
= GetItemCount();
3308 if ( index
>= count
)
3311 OnArrowChar( index
, event
);
3316 if ( !InReportView() )
3318 int index
= m_current
- m_linesPerPage
;
3322 OnArrowChar( index
, event
);
3327 if ( !InReportView() )
3329 size_t index
= m_current
+ m_linesPerPage
;
3331 size_t count
= GetItemCount();
3332 if ( index
>= count
)
3335 OnArrowChar( index
, event
);
3340 if ( IsSingleSel() )
3342 SendNotify( m_current
, wxEVT_COMMAND_LIST_ITEM_ACTIVATED
);
3344 if ( IsHighlighted(m_current
) )
3346 // don't unselect the item in single selection mode
3349 //else: select it in ReverseHighlight() below if unselected
3352 ReverseHighlight(m_current
);
3357 SendNotify( m_current
, wxEVT_COMMAND_LIST_ITEM_ACTIVATED
);
3365 // ----------------------------------------------------------------------------
3367 // ----------------------------------------------------------------------------
3369 void wxListMainWindow::OnSetFocus( wxFocusEvent
&WXUNUSED(event
) )
3373 wxFocusEvent
event( wxEVT_SET_FOCUS
, GetParent()->GetId() );
3374 event
.SetEventObject( GetParent() );
3375 if ( GetParent()->GetEventHandler()->ProcessEvent( event
) )
3379 // wxGTK sends us EVT_SET_FOCUS events even if we had never got
3380 // EVT_KILL_FOCUS before which means that we finish by redrawing the items
3381 // which are already drawn correctly resulting in horrible flicker - avoid
3391 void wxListMainWindow::OnKillFocus( wxFocusEvent
&WXUNUSED(event
) )
3395 wxFocusEvent
event( wxEVT_KILL_FOCUS
, GetParent()->GetId() );
3396 event
.SetEventObject( GetParent() );
3397 if ( GetParent()->GetEventHandler()->ProcessEvent( event
) )
3404 void wxListMainWindow::DrawImage( int index
, wxDC
*dc
, int x
, int y
)
3406 if ( HasFlag(wxLC_ICON
) && (m_normal_image_list
))
3408 m_normal_image_list
->Draw( index
, *dc
, x
, y
, wxIMAGELIST_DRAW_TRANSPARENT
);
3410 else if ( HasFlag(wxLC_SMALL_ICON
) && (m_small_image_list
))
3412 m_small_image_list
->Draw( index
, *dc
, x
, y
, wxIMAGELIST_DRAW_TRANSPARENT
);
3414 else if ( HasFlag(wxLC_LIST
) && (m_small_image_list
))
3416 m_small_image_list
->Draw( index
, *dc
, x
, y
, wxIMAGELIST_DRAW_TRANSPARENT
);
3418 else if ( InReportView() && (m_small_image_list
))
3420 m_small_image_list
->Draw( index
, *dc
, x
, y
, wxIMAGELIST_DRAW_TRANSPARENT
);
3424 void wxListMainWindow::GetImageSize( int index
, int &width
, int &height
) const
3426 if ( HasFlag(wxLC_ICON
) && m_normal_image_list
)
3428 m_normal_image_list
->GetSize( index
, width
, height
);
3430 else if ( HasFlag(wxLC_SMALL_ICON
) && m_small_image_list
)
3432 m_small_image_list
->GetSize( index
, width
, height
);
3434 else if ( HasFlag(wxLC_LIST
) && m_small_image_list
)
3436 m_small_image_list
->GetSize( index
, width
, height
);
3438 else if ( InReportView() && m_small_image_list
)
3440 m_small_image_list
->GetSize( index
, width
, height
);
3449 int wxListMainWindow::GetTextLength( const wxString
&s
) const
3451 wxClientDC
dc( wxConstCast(this, wxListMainWindow
) );
3452 dc
.SetFont( GetFont() );
3455 dc
.GetTextExtent( s
, &lw
, NULL
);
3457 return lw
+ AUTOSIZE_COL_MARGIN
;
3460 void wxListMainWindow::SetImageList( wxImageListType
*imageList
, int which
)
3464 // calc the spacing from the icon size
3467 if ((imageList
) && (imageList
->GetImageCount()) )
3469 imageList
->GetSize(0, width
, height
);
3472 if (which
== wxIMAGE_LIST_NORMAL
)
3474 m_normal_image_list
= imageList
;
3475 m_normal_spacing
= width
+ 8;
3478 if (which
== wxIMAGE_LIST_SMALL
)
3480 m_small_image_list
= imageList
;
3481 m_small_spacing
= width
+ 14;
3482 m_lineHeight
= 0; // ensure that the line height will be recalc'd
3486 void wxListMainWindow::SetItemSpacing( int spacing
, bool isSmall
)
3491 m_small_spacing
= spacing
;
3495 m_normal_spacing
= spacing
;
3499 int wxListMainWindow::GetItemSpacing( bool isSmall
)
3501 return isSmall
? m_small_spacing
: m_normal_spacing
;
3504 // ----------------------------------------------------------------------------
3506 // ----------------------------------------------------------------------------
3508 void wxListMainWindow::SetColumn( int col
, wxListItem
&item
)
3510 wxListHeaderDataList::compatibility_iterator node
= m_columns
.Item( col
);
3512 wxCHECK_RET( node
, _T("invalid column index in SetColumn") );
3514 if ( item
.m_width
== wxLIST_AUTOSIZE_USEHEADER
)
3515 item
.m_width
= GetTextLength( item
.m_text
);
3517 wxListHeaderData
*column
= node
->GetData();
3518 column
->SetItem( item
);
3520 wxListHeaderWindow
*headerWin
= GetListCtrl()->m_headerWin
;
3522 headerWin
->m_dirty
= true;
3526 // invalidate it as it has to be recalculated
3530 void wxListMainWindow::SetColumnWidth( int col
, int width
)
3532 wxCHECK_RET( col
>= 0 && col
< GetColumnCount(),
3533 _T("invalid column index") );
3535 wxCHECK_RET( InReportView(),
3536 _T("SetColumnWidth() can only be called in report mode.") );
3539 wxListHeaderWindow
*headerWin
= GetListCtrl()->m_headerWin
;
3541 headerWin
->m_dirty
= true;
3543 wxListHeaderDataList::compatibility_iterator node
= m_columns
.Item( col
);
3544 wxCHECK_RET( node
, _T("no column?") );
3546 wxListHeaderData
*column
= node
->GetData();
3548 size_t count
= GetItemCount();
3550 if (width
== wxLIST_AUTOSIZE_USEHEADER
)
3552 width
= GetTextLength(column
->GetText());
3554 else if ( width
== wxLIST_AUTOSIZE
)
3558 // TODO: determine the max width somehow...
3559 width
= WIDTH_COL_DEFAULT
;
3563 wxClientDC
dc(this);
3564 dc
.SetFont( GetFont() );
3566 int max
= AUTOSIZE_COL_MARGIN
;
3568 // if the cached column width isn't valid then recalculate it
3569 if (m_aColWidths
.Item(col
)->bNeedsUpdate
)
3571 for (size_t i
= 0; i
< count
; i
++)
3573 wxListLineData
*line
= GetLine(i
);
3574 wxListItemDataList::compatibility_iterator n
= line
->m_items
.Item( col
);
3576 wxCHECK_RET( n
, _T("no subitem?") );
3578 wxListItemData
*itemData
= n
->GetData();
3581 itemData
->GetItem(item
);
3582 int itemWidth
= GetItemWidthWithImage(&item
);
3583 if (itemWidth
> max
)
3587 m_aColWidths
.Item(col
)->bNeedsUpdate
= false;
3588 m_aColWidths
.Item(col
)->nMaxWidth
= max
;
3591 max
= m_aColWidths
.Item(col
)->nMaxWidth
;
3592 width
= max
+ AUTOSIZE_COL_MARGIN
;
3596 column
->SetWidth( width
);
3598 // invalidate it as it has to be recalculated
3602 int wxListMainWindow::GetHeaderWidth() const
3604 if ( !m_headerWidth
)
3606 wxListMainWindow
*self
= wxConstCast(this, wxListMainWindow
);
3608 size_t count
= GetColumnCount();
3609 for ( size_t col
= 0; col
< count
; col
++ )
3611 self
->m_headerWidth
+= GetColumnWidth(col
);
3615 return m_headerWidth
;
3618 void wxListMainWindow::GetColumn( int col
, wxListItem
&item
) const
3620 wxListHeaderDataList::compatibility_iterator node
= m_columns
.Item( col
);
3621 wxCHECK_RET( node
, _T("invalid column index in GetColumn") );
3623 wxListHeaderData
*column
= node
->GetData();
3624 column
->GetItem( item
);
3627 int wxListMainWindow::GetColumnWidth( int col
) const
3629 wxListHeaderDataList::compatibility_iterator node
= m_columns
.Item( col
);
3630 wxCHECK_MSG( node
, 0, _T("invalid column index") );
3632 wxListHeaderData
*column
= node
->GetData();
3633 return column
->GetWidth();
3636 // ----------------------------------------------------------------------------
3638 // ----------------------------------------------------------------------------
3640 void wxListMainWindow::SetItem( wxListItem
&item
)
3642 long id
= item
.m_itemId
;
3643 wxCHECK_RET( id
>= 0 && (size_t)id
< GetItemCount(),
3644 _T("invalid item index in SetItem") );
3648 wxListLineData
*line
= GetLine((size_t)id
);
3649 line
->SetItem( item
.m_col
, item
);
3653 // update the Max Width Cache if needed
3654 int width
= GetItemWidthWithImage(&item
);
3656 if (width
> m_aColWidths
.Item(item
.m_col
)->nMaxWidth
)
3657 m_aColWidths
.Item(item
.m_col
)->nMaxWidth
= width
;
3661 // update the item on screen
3663 GetItemRect(id
, rectItem
);
3664 RefreshRect(rectItem
);
3667 void wxListMainWindow::SetItemStateAll(long state
, long stateMask
)
3672 // first deal with selection
3673 if ( stateMask
& wxLIST_STATE_SELECTED
)
3675 // set/clear select state
3678 // optimized version for virtual listctrl.
3679 m_selStore
.SelectRange(0, GetItemCount() - 1, state
== wxLIST_STATE_SELECTED
);
3682 else if ( state
& wxLIST_STATE_SELECTED
)
3684 const long count
= GetItemCount();
3685 for( long i
= 0; i
< count
; i
++ )
3687 SetItemState( i
, wxLIST_STATE_SELECTED
, wxLIST_STATE_SELECTED
);
3693 // clear for non virtual (somewhat optimized by using GetNextItem())
3695 while ( (i
= GetNextItem(i
, wxLIST_NEXT_ALL
, wxLIST_STATE_SELECTED
)) != -1 )
3697 SetItemState( i
, 0, wxLIST_STATE_SELECTED
);
3702 if ( HasCurrent() && (state
== 0) && (stateMask
& wxLIST_STATE_FOCUSED
) )
3704 // unfocus all: only one item can be focussed, so clearing focus for
3705 // all items is simply clearing focus of the focussed item.
3706 SetItemState(m_current
, state
, stateMask
);
3708 //(setting focus to all items makes no sense, so it is not handled here.)
3711 void wxListMainWindow::SetItemState( long litem
, long state
, long stateMask
)
3715 SetItemStateAll(state
, stateMask
);
3719 wxCHECK_RET( litem
>= 0 && (size_t)litem
< GetItemCount(),
3720 _T("invalid list ctrl item index in SetItem") );
3722 size_t oldCurrent
= m_current
;
3723 size_t item
= (size_t)litem
; // safe because of the check above
3725 // do we need to change the focus?
3726 if ( stateMask
& wxLIST_STATE_FOCUSED
)
3728 if ( state
& wxLIST_STATE_FOCUSED
)
3730 // don't do anything if this item is already focused
3731 if ( item
!= m_current
)
3733 ChangeCurrent(item
);
3735 if ( oldCurrent
!= (size_t)-1 )
3737 if ( IsSingleSel() )
3739 HighlightLine(oldCurrent
, false);
3742 RefreshLine(oldCurrent
);
3745 RefreshLine( m_current
);
3750 // don't do anything if this item is not focused
3751 if ( item
== m_current
)
3755 if ( IsSingleSel() )
3757 // we must unselect the old current item as well or we
3758 // might end up with more than one selected item in a
3759 // single selection control
3760 HighlightLine(oldCurrent
, false);
3763 RefreshLine( oldCurrent
);
3768 // do we need to change the selection state?
3769 if ( stateMask
& wxLIST_STATE_SELECTED
)
3771 bool on
= (state
& wxLIST_STATE_SELECTED
) != 0;
3773 if ( IsSingleSel() )
3777 // selecting the item also makes it the focused one in the
3779 if ( m_current
!= item
)
3781 ChangeCurrent(item
);
3783 if ( oldCurrent
!= (size_t)-1 )
3785 HighlightLine( oldCurrent
, false );
3786 RefreshLine( oldCurrent
);
3792 // only the current item may be selected anyhow
3793 if ( item
!= m_current
)
3798 if ( HighlightLine(item
, on
) )
3805 int wxListMainWindow::GetItemState( long item
, long stateMask
) const
3807 wxCHECK_MSG( item
>= 0 && (size_t)item
< GetItemCount(), 0,
3808 _T("invalid list ctrl item index in GetItemState()") );
3810 int ret
= wxLIST_STATE_DONTCARE
;
3812 if ( stateMask
& wxLIST_STATE_FOCUSED
)
3814 if ( (size_t)item
== m_current
)
3815 ret
|= wxLIST_STATE_FOCUSED
;
3818 if ( stateMask
& wxLIST_STATE_SELECTED
)
3820 if ( IsHighlighted(item
) )
3821 ret
|= wxLIST_STATE_SELECTED
;
3827 void wxListMainWindow::GetItem( wxListItem
&item
) const
3829 wxCHECK_RET( item
.m_itemId
>= 0 && (size_t)item
.m_itemId
< GetItemCount(),
3830 _T("invalid item index in GetItem") );
3832 wxListLineData
*line
= GetLine((size_t)item
.m_itemId
);
3833 line
->GetItem( item
.m_col
, item
);
3836 // ----------------------------------------------------------------------------
3838 // ----------------------------------------------------------------------------
3840 size_t wxListMainWindow::GetItemCount() const
3842 return IsVirtual() ? m_countVirt
: m_lines
.GetCount();
3845 void wxListMainWindow::SetItemCount(long count
)
3847 m_selStore
.SetItemCount(count
);
3848 m_countVirt
= count
;
3850 ResetVisibleLinesRange();
3852 // scrollbars must be reset
3856 int wxListMainWindow::GetSelectedItemCount() const
3858 // deal with the quick case first
3859 if ( IsSingleSel() )
3861 return HasCurrent() ? IsHighlighted(m_current
) : false;
3864 // virtual controls remmebers all its selections itself
3866 return m_selStore
.GetSelectedCount();
3868 // TODO: we probably should maintain the number of items selected even for
3869 // non virtual controls as enumerating all lines is really slow...
3870 size_t countSel
= 0;
3871 size_t count
= GetItemCount();
3872 for ( size_t line
= 0; line
< count
; line
++ )
3874 if ( GetLine(line
)->IsHighlighted() )
3881 // ----------------------------------------------------------------------------
3882 // item position/size
3883 // ----------------------------------------------------------------------------
3885 wxRect
wxListMainWindow::GetViewRect() const
3887 wxASSERT_MSG( !HasFlag(wxLC_REPORT
| wxLC_LIST
),
3888 _T("wxListCtrl::GetViewRect() only works in icon mode") );
3890 // we need to find the longest/tallest label
3893 const int count
= GetItemCount();
3896 for ( int i
= 0; i
< count
; i
++ )
3901 wxCoord x
= r
.GetRight(),
3911 // some fudge needed to make it look prettier
3912 xMax
+= 2*EXTRA_BORDER_X
;
3913 yMax
+= 2*EXTRA_BORDER_Y
;
3915 // account for the scrollbars if necessary
3916 const wxSize sizeAll
= GetClientSize();
3917 if ( xMax
> sizeAll
.x
)
3918 yMax
+= wxSystemSettings::GetMetric(wxSYS_HSCROLL_Y
);
3919 if ( yMax
> sizeAll
.y
)
3920 xMax
+= wxSystemSettings::GetMetric(wxSYS_VSCROLL_X
);
3922 return wxRect(0, 0, xMax
, yMax
);
3925 void wxListMainWindow::GetItemRect( long index
, wxRect
&rect
) const
3927 wxCHECK_RET( index
>= 0 && (size_t)index
< GetItemCount(),
3928 _T("invalid index in GetItemRect") );
3930 // ensure that we're laid out, otherwise we could return nonsense
3933 wxConstCast(this, wxListMainWindow
)->
3934 RecalculatePositions(true /* no refresh */);
3937 rect
= GetLineRect((size_t)index
);
3939 CalcScrolledPosition(rect
.x
, rect
.y
, &rect
.x
, &rect
.y
);
3942 bool wxListMainWindow::GetItemPosition(long item
, wxPoint
& pos
) const
3945 GetItemRect(item
, rect
);
3953 // ----------------------------------------------------------------------------
3954 // geometry calculation
3955 // ----------------------------------------------------------------------------
3957 void wxListMainWindow::RecalculatePositions(bool noRefresh
)
3959 wxClientDC
dc( this );
3960 dc
.SetFont( GetFont() );
3962 const size_t count
= GetItemCount();
3965 if ( HasFlag(wxLC_ICON
) )
3966 iconSpacing
= m_normal_spacing
;
3967 else if ( HasFlag(wxLC_SMALL_ICON
) )
3968 iconSpacing
= m_small_spacing
;
3972 // Note that we do not call GetClientSize() here but
3973 // GetSize() and subtract the border size for sunken
3974 // borders manually. This is technically incorrect,
3975 // but we need to know the client area's size WITHOUT
3976 // scrollbars here. Since we don't know if there are
3977 // any scrollbars, we use GetSize() instead. Another
3978 // solution would be to call SetScrollbars() here to
3979 // remove the scrollbars and call GetClientSize() then,
3980 // but this might result in flicker and - worse - will
3981 // reset the scrollbars to 0 which is not good at all
3982 // if you resize a dialog/window, but don't want to
3983 // reset the window scrolling. RR.
3984 // Furthermore, we actually do NOT subtract the border
3985 // width as 2 pixels is just the extra space which we
3986 // need around the actual content in the window. Other-
3987 // wise the text would e.g. touch the upper border. RR.
3990 GetSize( &clientWidth
, &clientHeight
);
3992 const int lineHeight
= GetLineHeight();
3994 if ( InReportView() )
3996 // all lines have the same height and we scroll one line per step
3997 int entireHeight
= count
*lineHeight
+ LINE_SPACING
;
3999 m_linesPerPage
= clientHeight
/ lineHeight
;
4001 ResetVisibleLinesRange();
4003 SetScrollbars( SCROLL_UNIT_X
, lineHeight
,
4004 GetHeaderWidth() / SCROLL_UNIT_X
,
4005 (entireHeight
+ lineHeight
- 1) / lineHeight
,
4006 GetScrollPos(wxHORIZONTAL
),
4007 GetScrollPos(wxVERTICAL
),
4012 // we have 3 different layout strategies: either layout all items
4013 // horizontally/vertically (wxLC_ALIGN_XXX styles explicitly given) or
4014 // to arrange them in top to bottom, left to right (don't ask me why
4015 // not the other way round...) order
4016 if ( HasFlag(wxLC_ALIGN_LEFT
| wxLC_ALIGN_TOP
) )
4018 int x
= EXTRA_BORDER_X
;
4019 int y
= EXTRA_BORDER_Y
;
4021 wxCoord widthMax
= 0;
4024 for ( i
= 0; i
< count
; i
++ )
4026 wxListLineData
*line
= GetLine(i
);
4027 line
->CalculateSize( &dc
, iconSpacing
);
4028 line
->SetPosition( x
, y
, iconSpacing
);
4030 wxSize sizeLine
= GetLineSize(i
);
4032 if ( HasFlag(wxLC_ALIGN_TOP
) )
4034 if ( sizeLine
.x
> widthMax
)
4035 widthMax
= sizeLine
.x
;
4039 else // wxLC_ALIGN_LEFT
4041 x
+= sizeLine
.x
+ MARGIN_BETWEEN_ROWS
;
4045 if ( HasFlag(wxLC_ALIGN_TOP
) )
4047 // traverse the items again and tweak their sizes so that they are
4048 // all the same in a row
4049 for ( i
= 0; i
< count
; i
++ )
4051 wxListLineData
*line
= GetLine(i
);
4052 line
->m_gi
->ExtendWidth(widthMax
);
4061 (x
+ SCROLL_UNIT_X
) / SCROLL_UNIT_X
,
4062 (y
+ lineHeight
) / lineHeight
,
4063 GetScrollPos( wxHORIZONTAL
),
4064 GetScrollPos( wxVERTICAL
),
4068 else // "flowed" arrangement, the most complicated case
4070 // at first we try without any scrollbars, if the items don't fit into
4071 // the window, we recalculate after subtracting the space taken by the
4074 int entireWidth
= 0;
4076 for (int tries
= 0; tries
< 2; tries
++)
4078 entireWidth
= 2*EXTRA_BORDER_X
;
4082 // Now we have decided that the items do not fit into the
4083 // client area, so we need a scrollbar
4084 entireWidth
+= SCROLL_UNIT_X
;
4087 int x
= EXTRA_BORDER_X
;
4088 int y
= EXTRA_BORDER_Y
;
4089 int maxWidthInThisRow
= 0;
4092 int currentlyVisibleLines
= 0;
4094 for (size_t i
= 0; i
< count
; i
++)
4096 currentlyVisibleLines
++;
4097 wxListLineData
*line
= GetLine(i
);
4098 line
->CalculateSize( &dc
, iconSpacing
);
4099 line
->SetPosition( x
, y
, iconSpacing
);
4101 wxSize sizeLine
= GetLineSize(i
);
4103 if ( maxWidthInThisRow
< sizeLine
.x
)
4104 maxWidthInThisRow
= sizeLine
.x
;
4107 if (currentlyVisibleLines
> m_linesPerPage
)
4108 m_linesPerPage
= currentlyVisibleLines
;
4110 if ( y
+ sizeLine
.y
>= clientHeight
)
4112 currentlyVisibleLines
= 0;
4114 maxWidthInThisRow
+= MARGIN_BETWEEN_ROWS
;
4115 x
+= maxWidthInThisRow
;
4116 entireWidth
+= maxWidthInThisRow
;
4117 maxWidthInThisRow
= 0;
4120 // We have reached the last item.
4121 if ( i
== count
- 1 )
4122 entireWidth
+= maxWidthInThisRow
;
4124 if ( (tries
== 0) &&
4125 (entireWidth
+ SCROLL_UNIT_X
> clientWidth
) )
4127 clientHeight
-= wxSystemSettings::
4128 GetMetric(wxSYS_HSCROLL_Y
);
4133 if ( i
== count
- 1 )
4134 tries
= 1; // Everything fits, no second try required.
4142 (entireWidth
+ SCROLL_UNIT_X
) / SCROLL_UNIT_X
,
4144 GetScrollPos( wxHORIZONTAL
),
4153 // FIXME: why should we call it from here?
4160 void wxListMainWindow::RefreshAll()
4165 wxListHeaderWindow
*headerWin
= GetListCtrl()->m_headerWin
;
4166 if ( headerWin
&& headerWin
->m_dirty
)
4168 headerWin
->m_dirty
= false;
4169 headerWin
->Refresh();
4173 void wxListMainWindow::UpdateCurrent()
4175 if ( !HasCurrent() && !IsEmpty() )
4181 long wxListMainWindow::GetNextItem( long item
,
4182 int WXUNUSED(geometry
),
4186 max
= GetItemCount();
4187 wxCHECK_MSG( (ret
== -1) || (ret
< max
), -1,
4188 _T("invalid listctrl index in GetNextItem()") );
4190 // notice that we start with the next item (or the first one if item == -1)
4191 // and this is intentional to allow writing a simple loop to iterate over
4192 // all selected items
4196 // this is not an error because the index was ok initially, just no
4207 size_t count
= GetItemCount();
4208 for ( size_t line
= (size_t)ret
; line
< count
; line
++ )
4210 if ( (state
& wxLIST_STATE_FOCUSED
) && (line
== m_current
) )
4213 if ( (state
& wxLIST_STATE_SELECTED
) && IsHighlighted(line
) )
4220 // ----------------------------------------------------------------------------
4222 // ----------------------------------------------------------------------------
4224 void wxListMainWindow::DeleteItem( long lindex
)
4226 size_t count
= GetItemCount();
4228 wxCHECK_RET( (lindex
>= 0) && ((size_t)lindex
< count
),
4229 _T("invalid item index in DeleteItem") );
4231 size_t index
= (size_t)lindex
;
4233 // we don't need to adjust the index for the previous items
4234 if ( HasCurrent() && m_current
>= index
)
4236 // if the current item is being deleted, we want the next one to
4237 // become selected - unless there is no next one - so don't adjust
4238 // m_current in this case
4239 if ( m_current
!= index
|| m_current
== count
- 1 )
4245 if ( InReportView() )
4247 // mark the Column Max Width cache as dirty if the items in the line
4248 // we're deleting contain the Max Column Width
4249 wxListLineData
* const line
= GetLine(index
);
4250 wxListItemDataList::compatibility_iterator n
;
4251 wxListItemData
*itemData
;
4255 for (size_t i
= 0; i
< m_columns
.GetCount(); i
++)
4257 n
= line
->m_items
.Item( i
);
4258 itemData
= n
->GetData();
4259 itemData
->GetItem(item
);
4261 itemWidth
= GetItemWidthWithImage(&item
);
4263 if (itemWidth
>= m_aColWidths
.Item(i
)->nMaxWidth
)
4264 m_aColWidths
.Item(i
)->bNeedsUpdate
= true;
4267 ResetVisibleLinesRange();
4274 m_selStore
.OnItemDelete(index
);
4278 m_lines
.RemoveAt( index
);
4281 // we need to refresh the (vert) scrollbar as the number of items changed
4284 SendNotify( index
, wxEVT_COMMAND_LIST_DELETE_ITEM
);
4286 RefreshAfter(index
);
4289 void wxListMainWindow::DeleteColumn( int col
)
4291 wxListHeaderDataList::compatibility_iterator node
= m_columns
.Item( col
);
4293 wxCHECK_RET( node
, wxT("invalid column index in DeleteColumn()") );
4296 delete node
->GetData();
4297 m_columns
.Erase( node
);
4301 // update all the items
4302 for ( size_t i
= 0; i
< m_lines
.GetCount(); i
++ )
4304 wxListLineData
* const line
= GetLine(i
);
4305 wxListItemDataList::compatibility_iterator n
= line
->m_items
.Item( col
);
4306 delete n
->GetData();
4307 line
->m_items
.Erase(n
);
4311 if ( InReportView() ) // we only cache max widths when in Report View
4313 delete m_aColWidths
.Item(col
);
4314 m_aColWidths
.RemoveAt(col
);
4317 // invalidate it as it has to be recalculated
4321 void wxListMainWindow::DoDeleteAllItems()
4325 // nothing to do - in particular, don't send the event
4331 // to make the deletion of all items faster, we don't send the
4332 // notifications for each item deletion in this case but only one event
4333 // for all of them: this is compatible with wxMSW and documented in
4334 // DeleteAllItems() description
4336 wxListEvent
event( wxEVT_COMMAND_LIST_DELETE_ALL_ITEMS
, GetParent()->GetId() );
4337 event
.SetEventObject( GetParent() );
4338 GetParent()->GetEventHandler()->ProcessEvent( event
);
4347 if ( InReportView() )
4349 ResetVisibleLinesRange();
4350 for (size_t i
= 0; i
< m_aColWidths
.GetCount(); i
++)
4352 m_aColWidths
.Item(i
)->bNeedsUpdate
= true;
4359 void wxListMainWindow::DeleteAllItems()
4363 RecalculatePositions();
4366 void wxListMainWindow::DeleteEverything()
4368 WX_CLEAR_LIST(wxListHeaderDataList
, m_columns
);
4369 WX_CLEAR_ARRAY(m_aColWidths
);
4374 // ----------------------------------------------------------------------------
4375 // scanning for an item
4376 // ----------------------------------------------------------------------------
4378 void wxListMainWindow::EnsureVisible( long index
)
4380 wxCHECK_RET( index
>= 0 && (size_t)index
< GetItemCount(),
4381 _T("invalid index in EnsureVisible") );
4383 // We have to call this here because the label in question might just have
4384 // been added and its position is not known yet
4387 RecalculatePositions(true /* no refresh */);
4390 MoveToItem((size_t)index
);
4393 long wxListMainWindow::FindItem(long start
, const wxString
& str
, bool WXUNUSED(partial
) )
4400 size_t count
= GetItemCount();
4401 for ( size_t i
= (size_t)pos
; i
< count
; i
++ )
4403 wxListLineData
*line
= GetLine(i
);
4404 if ( line
->GetText(0) == tmp
)
4411 long wxListMainWindow::FindItem(long start
, wxUIntPtr data
)
4417 size_t count
= GetItemCount();
4418 for (size_t i
= (size_t)pos
; i
< count
; i
++)
4420 wxListLineData
*line
= GetLine(i
);
4422 line
->GetItem( 0, item
);
4423 if (item
.m_data
== data
)
4430 long wxListMainWindow::FindItem( const wxPoint
& pt
)
4433 GetVisibleLinesRange(&topItem
, NULL
);
4436 GetItemPosition( GetItemCount()-1, p
);
4439 long id
= (long) floor( pt
.y
*double(GetItemCount()-topItem
-1)/p
.y
+topItem
);
4440 if( id
>= 0 && id
< (long)GetItemCount() )
4446 long wxListMainWindow::HitTest( int x
, int y
, int &flags
)
4448 CalcUnscrolledPosition( x
, y
, &x
, &y
);
4450 size_t count
= GetItemCount();
4452 if ( InReportView() )
4454 size_t current
= y
/ GetLineHeight();
4455 if ( current
< count
)
4457 flags
= HitTestLine(current
, x
, y
);
4464 // TODO: optimize it too! this is less simple than for report view but
4465 // enumerating all items is still not a way to do it!!
4466 for ( size_t current
= 0; current
< count
; current
++ )
4468 flags
= HitTestLine(current
, x
, y
);
4477 // ----------------------------------------------------------------------------
4479 // ----------------------------------------------------------------------------
4481 void wxListMainWindow::InsertItem( wxListItem
&item
)
4483 wxASSERT_MSG( !IsVirtual(), _T("can't be used with virtual control") );
4485 int count
= GetItemCount();
4486 wxCHECK_RET( item
.m_itemId
>= 0, _T("invalid item index") );
4488 if (item
.m_itemId
> count
)
4489 item
.m_itemId
= count
;
4491 size_t id
= item
.m_itemId
;
4495 if ( InReportView() )
4497 ResetVisibleLinesRange();
4499 // calculate the width of the item and adjust the max column width
4500 wxColWidthInfo
*pWidthInfo
= m_aColWidths
.Item(item
.GetColumn());
4501 int width
= GetItemWidthWithImage(&item
);
4502 item
.SetWidth(width
);
4503 if (width
> pWidthInfo
->nMaxWidth
)
4504 pWidthInfo
->nMaxWidth
= width
;
4507 wxListLineData
*line
= new wxListLineData(this);
4509 line
->SetItem( item
.m_col
, item
);
4511 m_lines
.Insert( line
, id
);
4515 // If an item is selected at or below the point of insertion, we need to
4516 // increment the member variables because the current row's index has gone
4518 if ( HasCurrent() && m_current
>= id
)
4523 SendNotify(id
, wxEVT_COMMAND_LIST_INSERT_ITEM
);
4525 RefreshLines(id
, GetItemCount() - 1);
4528 void wxListMainWindow::InsertColumn( long col
, wxListItem
&item
)
4531 if ( InReportView() )
4533 if (item
.m_width
== wxLIST_AUTOSIZE_USEHEADER
)
4534 item
.m_width
= GetTextLength( item
.m_text
);
4536 wxListHeaderData
*column
= new wxListHeaderData( item
);
4537 wxColWidthInfo
*colWidthInfo
= new wxColWidthInfo();
4539 bool insert
= (col
>= 0) && ((size_t)col
< m_columns
.GetCount());
4542 wxListHeaderDataList::compatibility_iterator
4543 node
= m_columns
.Item( col
);
4544 m_columns
.Insert( node
, column
);
4545 m_aColWidths
.Insert( colWidthInfo
, col
);
4549 m_columns
.Append( column
);
4550 m_aColWidths
.Add( colWidthInfo
);
4555 // update all the items
4556 for ( size_t i
= 0; i
< m_lines
.GetCount(); i
++ )
4558 wxListLineData
* const line
= GetLine(i
);
4559 wxListItemData
* const data
= new wxListItemData(this);
4561 line
->m_items
.Insert(col
, data
);
4563 line
->m_items
.Append(data
);
4567 // invalidate it as it has to be recalculated
4572 int wxListMainWindow::GetItemWidthWithImage(wxListItem
* item
)
4575 wxClientDC
dc(this);
4577 dc
.SetFont( GetFont() );
4579 if (item
->GetImage() != -1)
4582 GetImageSize( item
->GetImage(), ix
, iy
);
4586 if (!item
->GetText().empty())
4589 dc
.GetTextExtent( item
->GetText(), &w
, NULL
);
4596 // ----------------------------------------------------------------------------
4598 // ----------------------------------------------------------------------------
4600 wxListCtrlCompare list_ctrl_compare_func_2
;
4601 long list_ctrl_compare_data
;
4603 int LINKAGEMODE
list_ctrl_compare_func_1( wxListLineData
**arg1
, wxListLineData
**arg2
)
4605 wxListLineData
*line1
= *arg1
;
4606 wxListLineData
*line2
= *arg2
;
4608 line1
->GetItem( 0, item
);
4609 wxUIntPtr data1
= item
.m_data
;
4610 line2
->GetItem( 0, item
);
4611 wxUIntPtr data2
= item
.m_data
;
4612 return list_ctrl_compare_func_2( data1
, data2
, list_ctrl_compare_data
);
4615 void wxListMainWindow::SortItems( wxListCtrlCompare fn
, long data
)
4617 list_ctrl_compare_func_2
= fn
;
4618 list_ctrl_compare_data
= data
;
4619 m_lines
.Sort( list_ctrl_compare_func_1
);
4623 // ----------------------------------------------------------------------------
4625 // ----------------------------------------------------------------------------
4627 void wxListMainWindow::OnScroll(wxScrollWinEvent
& event
)
4629 // update our idea of which lines are shown when we redraw the window the
4631 ResetVisibleLinesRange();
4634 #if ( defined(__WXGTK__) || defined(__WXMAC__) ) && !defined(__WXUNIVERSAL__)
4635 wxScrolledWindow::OnScroll(event
);
4637 HandleOnScroll( event
);
4640 if ( event
.GetOrientation() == wxHORIZONTAL
&& HasHeader() )
4642 wxGenericListCtrl
* lc
= GetListCtrl();
4643 wxCHECK_RET( lc
, _T("no listctrl window?") );
4645 lc
->m_headerWin
->Refresh();
4646 lc
->m_headerWin
->Update();
4650 int wxListMainWindow::GetCountPerPage() const
4652 if ( !m_linesPerPage
)
4654 wxConstCast(this, wxListMainWindow
)->
4655 m_linesPerPage
= GetClientSize().y
/ GetLineHeight();
4658 return m_linesPerPage
;
4661 void wxListMainWindow::GetVisibleLinesRange(size_t *from
, size_t *to
)
4663 wxASSERT_MSG( InReportView(), _T("this is for report mode only") );
4665 if ( m_lineFrom
== (size_t)-1 )
4667 size_t count
= GetItemCount();
4670 m_lineFrom
= GetScrollPos(wxVERTICAL
);
4672 // this may happen if SetScrollbars() hadn't been called yet
4673 if ( m_lineFrom
>= count
)
4674 m_lineFrom
= count
- 1;
4676 // we redraw one extra line but this is needed to make the redrawing
4677 // logic work when there is a fractional number of lines on screen
4678 m_lineTo
= m_lineFrom
+ m_linesPerPage
;
4679 if ( m_lineTo
>= count
)
4680 m_lineTo
= count
- 1;
4682 else // empty control
4685 m_lineTo
= (size_t)-1;
4689 wxASSERT_MSG( IsEmpty() ||
4690 (m_lineFrom
<= m_lineTo
&& m_lineTo
< GetItemCount()),
4691 _T("GetVisibleLinesRange() returns incorrect result") );
4699 // -------------------------------------------------------------------------------------
4700 // wxGenericListCtrl
4701 // -------------------------------------------------------------------------------------
4703 IMPLEMENT_DYNAMIC_CLASS(wxGenericListCtrl
, wxControl
)
4705 BEGIN_EVENT_TABLE(wxGenericListCtrl
,wxControl
)
4706 EVT_SIZE(wxGenericListCtrl::OnSize
)
4709 wxGenericListCtrl::wxGenericListCtrl()
4711 m_imageListNormal
= (wxImageListType
*) NULL
;
4712 m_imageListSmall
= (wxImageListType
*) NULL
;
4713 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 wxGenericListCtrl::~wxGenericListCtrl()
4726 if (m_ownsImageListNormal
)
4727 delete m_imageListNormal
;
4728 if (m_ownsImageListSmall
)
4729 delete m_imageListSmall
;
4730 if (m_ownsImageListState
)
4731 delete m_imageListState
;
4734 void wxGenericListCtrl::CalculateAndSetHeaderHeight()
4740 GetThemeMetric( kThemeMetricListHeaderHeight
, &h
);
4742 // we use 'g' to get the descent, too
4744 m_headerWin
->GetTextExtent(wxT("Hg"), &w
, &h
, &d
);
4745 h
+= d
+ 2 * HEADER_OFFSET_Y
+ EXTRA_HEIGHT
;
4747 // only update if changed
4748 if ( h
!= m_headerHeight
)
4752 m_headerWin
->SetSize(m_headerWin
->GetSize().x
, m_headerHeight
);
4755 ResizeReportView(true);
4760 void wxGenericListCtrl::CreateHeaderWindow()
4762 m_headerWin
= new wxListHeaderWindow
4764 this, wxID_ANY
, m_mainWin
,
4766 wxSize(GetClientSize().x
, m_headerHeight
),
4769 CalculateAndSetHeaderHeight();
4772 bool wxGenericListCtrl::Create(wxWindow
*parent
,
4777 const wxValidator
&validator
,
4778 const wxString
&name
)
4782 m_imageListState
= (wxImageListType
*) NULL
;
4783 m_ownsImageListNormal
=
4784 m_ownsImageListSmall
=
4785 m_ownsImageListState
= false;
4787 m_mainWin
= (wxListMainWindow
*) NULL
;
4788 m_headerWin
= (wxListHeaderWindow
*) NULL
;
4792 if ( !(style
& wxLC_MASK_TYPE
) )
4794 style
= style
| wxLC_LIST
;
4797 if ( !wxControl::Create( parent
, id
, pos
, size
, style
, validator
, name
) )
4800 // don't create the inner window with the border
4801 style
&= ~wxBORDER_MASK
;
4803 m_mainWin
= new wxListMainWindow( this, wxID_ANY
, wxPoint(0,0), size
, style
);
4805 #ifdef __WXMAC_CARBON__
4806 // Human Interface Guidelines ask us for a special font in this case
4807 if ( GetWindowVariant() == wxWINDOW_VARIANT_NORMAL
)
4810 font
.MacCreateThemeFont( kThemeViewsFont
) ;
4814 if ( InReportView() )
4816 CreateHeaderWindow();
4817 #ifdef __WXMAC_CARBON__
4821 font
.MacCreateThemeFont( kThemeSmallSystemFont
) ;
4822 m_headerWin
->SetFont( font
);
4823 CalculateAndSetHeaderHeight();
4826 if ( HasFlag(wxLC_NO_HEADER
) )
4828 // VZ: why do we create it at all then?
4829 m_headerWin
->Show( false );
4838 void wxGenericListCtrl::SetSingleStyle( long style
, bool add
)
4840 wxASSERT_MSG( !(style
& wxLC_VIRTUAL
),
4841 _T("wxLC_VIRTUAL can't be [un]set") );
4843 long flag
= GetWindowStyle();
4847 if (style
& wxLC_MASK_TYPE
)
4848 flag
&= ~(wxLC_MASK_TYPE
| wxLC_VIRTUAL
);
4849 if (style
& wxLC_MASK_ALIGN
)
4850 flag
&= ~wxLC_MASK_ALIGN
;
4851 if (style
& wxLC_MASK_SORT
)
4852 flag
&= ~wxLC_MASK_SORT
;
4864 SetWindowStyleFlag( flag
);
4867 void wxGenericListCtrl::SetWindowStyleFlag( long flag
)
4871 m_mainWin
->DeleteEverything();
4873 // has the header visibility changed?
4874 bool hasHeader
= HasHeader();
4875 bool willHaveHeader
= (flag
& wxLC_REPORT
) && !(flag
& wxLC_NO_HEADER
);
4877 if ( hasHeader
!= willHaveHeader
)
4884 // don't delete, just hide, as we can reuse it later
4885 m_headerWin
->Show(false);
4887 //else: nothing to do
4889 else // must show header
4893 CreateHeaderWindow();
4895 else // already have it, just show
4897 m_headerWin
->Show( true );
4901 ResizeReportView(willHaveHeader
);
4905 wxWindow::SetWindowStyleFlag( flag
);
4908 bool wxGenericListCtrl::GetColumn(int col
, wxListItem
&item
) const
4910 m_mainWin
->GetColumn( col
, item
);
4914 bool wxGenericListCtrl::SetColumn( int col
, wxListItem
& item
)
4916 m_mainWin
->SetColumn( col
, item
);
4920 int wxGenericListCtrl::GetColumnWidth( int col
) const
4922 return m_mainWin
->GetColumnWidth( col
);
4925 bool wxGenericListCtrl::SetColumnWidth( int col
, int width
)
4927 m_mainWin
->SetColumnWidth( col
, width
);
4931 int wxGenericListCtrl::GetCountPerPage() const
4933 return m_mainWin
->GetCountPerPage(); // different from Windows ?
4936 bool wxGenericListCtrl::GetItem( wxListItem
&info
) const
4938 m_mainWin
->GetItem( info
);
4942 bool wxGenericListCtrl::SetItem( wxListItem
&info
)
4944 m_mainWin
->SetItem( info
);
4948 long wxGenericListCtrl::SetItem( long index
, int col
, const wxString
& label
, int imageId
)
4951 info
.m_text
= label
;
4952 info
.m_mask
= wxLIST_MASK_TEXT
;
4953 info
.m_itemId
= index
;
4957 info
.m_image
= imageId
;
4958 info
.m_mask
|= wxLIST_MASK_IMAGE
;
4960 m_mainWin
->SetItem(info
);
4964 int wxGenericListCtrl::GetItemState( long item
, long stateMask
) const
4966 return m_mainWin
->GetItemState( item
, stateMask
);
4969 bool wxGenericListCtrl::SetItemState( long item
, long state
, long stateMask
)
4971 m_mainWin
->SetItemState( item
, state
, stateMask
);
4976 wxGenericListCtrl::SetItemImage( long item
, int image
, int WXUNUSED(selImage
) )
4979 info
.m_image
= image
;
4980 info
.m_mask
= wxLIST_MASK_IMAGE
;
4981 info
.m_itemId
= item
;
4982 m_mainWin
->SetItem( info
);
4986 wxString
wxGenericListCtrl::GetItemText( long item
) const
4988 return m_mainWin
->GetItemText(item
);
4991 void wxGenericListCtrl::SetItemText( long item
, const wxString
& str
)
4993 m_mainWin
->SetItemText(item
, str
);
4996 wxUIntPtr
wxGenericListCtrl::GetItemData( long item
) const
4999 info
.m_itemId
= item
;
5000 m_mainWin
->GetItem( info
);
5004 bool wxGenericListCtrl::SetItemData( long item
, long data
)
5007 info
.m_mask
= wxLIST_MASK_DATA
;
5008 info
.m_itemId
= item
;
5010 m_mainWin
->SetItem( info
);
5014 wxRect
wxGenericListCtrl::GetViewRect() const
5016 return m_mainWin
->GetViewRect();
5019 bool wxGenericListCtrl::GetItemRect( long item
, wxRect
&rect
, int WXUNUSED(code
) ) const
5021 m_mainWin
->GetItemRect( item
, rect
);
5022 if ( m_mainWin
->HasHeader() )
5023 rect
.y
+= m_headerHeight
+ 1;
5027 bool wxGenericListCtrl::GetItemPosition( long item
, wxPoint
& pos
) const
5029 m_mainWin
->GetItemPosition( item
, pos
);
5033 bool wxGenericListCtrl::SetItemPosition( long WXUNUSED(item
), const wxPoint
& WXUNUSED(pos
) )
5038 int wxGenericListCtrl::GetItemCount() const
5040 return m_mainWin
->GetItemCount();
5043 int wxGenericListCtrl::GetColumnCount() const
5045 return m_mainWin
->GetColumnCount();
5048 void wxGenericListCtrl::SetItemSpacing( int spacing
, bool isSmall
)
5050 m_mainWin
->SetItemSpacing( spacing
, isSmall
);
5053 wxSize
wxGenericListCtrl::GetItemSpacing() const
5055 const int spacing
= m_mainWin
->GetItemSpacing(HasFlag(wxLC_SMALL_ICON
));
5057 return wxSize(spacing
, spacing
);
5060 int wxGenericListCtrl::GetItemSpacing( bool isSmall
) const
5062 return m_mainWin
->GetItemSpacing( isSmall
);
5065 void wxGenericListCtrl::SetItemTextColour( long item
, const wxColour
&col
)
5068 info
.m_itemId
= item
;
5069 info
.SetTextColour( col
);
5070 m_mainWin
->SetItem( info
);
5073 wxColour
wxGenericListCtrl::GetItemTextColour( long item
) const
5076 info
.m_itemId
= item
;
5077 m_mainWin
->GetItem( info
);
5078 return info
.GetTextColour();
5081 void wxGenericListCtrl::SetItemBackgroundColour( long item
, const wxColour
&col
)
5084 info
.m_itemId
= item
;
5085 info
.SetBackgroundColour( col
);
5086 m_mainWin
->SetItem( info
);
5089 wxColour
wxGenericListCtrl::GetItemBackgroundColour( long item
) const
5092 info
.m_itemId
= item
;
5093 m_mainWin
->GetItem( info
);
5094 return info
.GetBackgroundColour();
5097 void wxGenericListCtrl::SetItemFont( long item
, const wxFont
&f
)
5100 info
.m_itemId
= item
;
5102 m_mainWin
->SetItem( info
);
5105 wxFont
wxGenericListCtrl::GetItemFont( long item
) const
5108 info
.m_itemId
= item
;
5109 m_mainWin
->GetItem( info
);
5110 return info
.GetFont();
5113 int wxGenericListCtrl::GetSelectedItemCount() const
5115 return m_mainWin
->GetSelectedItemCount();
5118 wxColour
wxGenericListCtrl::GetTextColour() const
5120 return GetForegroundColour();
5123 void wxGenericListCtrl::SetTextColour(const wxColour
& col
)
5125 SetForegroundColour(col
);
5128 long wxGenericListCtrl::GetTopItem() const
5131 m_mainWin
->GetVisibleLinesRange(&top
, NULL
);
5135 long wxGenericListCtrl::GetNextItem( long item
, int geom
, int state
) const
5137 return m_mainWin
->GetNextItem( item
, geom
, state
);
5140 wxImageListType
*wxGenericListCtrl::GetImageList(int which
) const
5142 if (which
== wxIMAGE_LIST_NORMAL
)
5144 return m_imageListNormal
;
5146 else if (which
== wxIMAGE_LIST_SMALL
)
5148 return m_imageListSmall
;
5150 else if (which
== wxIMAGE_LIST_STATE
)
5152 return m_imageListState
;
5154 return (wxImageListType
*) NULL
;
5157 void wxGenericListCtrl::SetImageList( wxImageListType
*imageList
, int which
)
5159 if ( which
== wxIMAGE_LIST_NORMAL
)
5161 if (m_ownsImageListNormal
) delete m_imageListNormal
;
5162 m_imageListNormal
= imageList
;
5163 m_ownsImageListNormal
= false;
5165 else if ( which
== wxIMAGE_LIST_SMALL
)
5167 if (m_ownsImageListSmall
) delete m_imageListSmall
;
5168 m_imageListSmall
= imageList
;
5169 m_ownsImageListSmall
= false;
5171 else if ( which
== wxIMAGE_LIST_STATE
)
5173 if (m_ownsImageListState
) delete m_imageListState
;
5174 m_imageListState
= imageList
;
5175 m_ownsImageListState
= false;
5178 m_mainWin
->SetImageList( imageList
, which
);
5181 void wxGenericListCtrl::AssignImageList(wxImageListType
*imageList
, int which
)
5183 SetImageList(imageList
, which
);
5184 if ( which
== wxIMAGE_LIST_NORMAL
)
5185 m_ownsImageListNormal
= true;
5186 else if ( which
== wxIMAGE_LIST_SMALL
)
5187 m_ownsImageListSmall
= true;
5188 else if ( which
== wxIMAGE_LIST_STATE
)
5189 m_ownsImageListState
= true;
5192 bool wxGenericListCtrl::Arrange( int WXUNUSED(flag
) )
5197 bool wxGenericListCtrl::DeleteItem( long item
)
5199 m_mainWin
->DeleteItem( item
);
5203 bool wxGenericListCtrl::DeleteAllItems()
5205 m_mainWin
->DeleteAllItems();
5209 bool wxGenericListCtrl::DeleteAllColumns()
5211 size_t count
= m_mainWin
->m_columns
.GetCount();
5212 for ( size_t n
= 0; n
< count
; n
++ )
5218 void wxGenericListCtrl::ClearAll()
5220 m_mainWin
->DeleteEverything();
5223 bool wxGenericListCtrl::DeleteColumn( int col
)
5225 m_mainWin
->DeleteColumn( col
);
5227 // if we don't have the header any longer, we need to relayout the window
5228 if ( !GetColumnCount() )
5230 ResizeReportView(false /* no header */);
5236 void wxGenericListCtrl::Edit( long item
)
5238 m_mainWin
->EditLabel( item
);
5241 bool wxGenericListCtrl::EnsureVisible( long item
)
5243 m_mainWin
->EnsureVisible( item
);
5247 long wxGenericListCtrl::FindItem( long start
, const wxString
& str
, bool partial
)
5249 return m_mainWin
->FindItem( start
, str
, partial
);
5252 long wxGenericListCtrl::FindItem( long start
, wxUIntPtr data
)
5254 return m_mainWin
->FindItem( start
, data
);
5257 long wxGenericListCtrl::FindItem( long WXUNUSED(start
), const wxPoint
& pt
,
5258 int WXUNUSED(direction
))
5260 return m_mainWin
->FindItem( pt
);
5263 long wxGenericListCtrl::HitTest( const wxPoint
&point
, int &flags
)
5265 return m_mainWin
->HitTest( (int)point
.x
, (int)point
.y
, flags
);
5268 long wxGenericListCtrl::InsertItem( wxListItem
& info
)
5270 m_mainWin
->InsertItem( info
);
5271 return info
.m_itemId
;
5274 long wxGenericListCtrl::InsertItem( long index
, const wxString
&label
)
5277 info
.m_text
= label
;
5278 info
.m_mask
= wxLIST_MASK_TEXT
;
5279 info
.m_itemId
= index
;
5280 return InsertItem( info
);
5283 long wxGenericListCtrl::InsertItem( long index
, int imageIndex
)
5286 info
.m_mask
= wxLIST_MASK_IMAGE
;
5287 info
.m_image
= imageIndex
;
5288 info
.m_itemId
= index
;
5289 return InsertItem( info
);
5292 long wxGenericListCtrl::InsertItem( long index
, const wxString
&label
, int imageIndex
)
5295 info
.m_text
= label
;
5296 info
.m_image
= imageIndex
;
5297 info
.m_mask
= wxLIST_MASK_TEXT
| wxLIST_MASK_IMAGE
;
5298 info
.m_itemId
= index
;
5299 return InsertItem( info
);
5302 long wxGenericListCtrl::InsertColumn( long col
, wxListItem
&item
)
5304 wxCHECK_MSG( m_headerWin
, -1, _T("can't add column in non report mode") );
5306 m_mainWin
->InsertColumn( col
, item
);
5308 // if we hadn't had header before and have it now we need to relayout the
5310 if ( GetColumnCount() == 1 && m_mainWin
->HasHeader() )
5312 ResizeReportView(true /* have header */);
5315 m_headerWin
->Refresh();
5320 long wxGenericListCtrl::InsertColumn( long col
, const wxString
&heading
,
5321 int format
, int width
)
5324 item
.m_mask
= wxLIST_MASK_TEXT
| wxLIST_MASK_FORMAT
;
5325 item
.m_text
= heading
;
5328 item
.m_mask
|= wxLIST_MASK_WIDTH
;
5329 item
.m_width
= width
;
5331 item
.m_format
= format
;
5333 return InsertColumn( col
, item
);
5336 bool wxGenericListCtrl::ScrollList( int WXUNUSED(dx
), int WXUNUSED(dy
) )
5342 // fn is a function which takes 3 long arguments: item1, item2, data.
5343 // item1 is the long data associated with a first item (NOT the index).
5344 // item2 is the long data associated with a second item (NOT the index).
5345 // data is the same value as passed to SortItems.
5346 // The return value is a negative number if the first item should precede the second
5347 // item, a positive number of the second item should precede the first,
5348 // or zero if the two items are equivalent.
5349 // data is arbitrary data to be passed to the sort function.
5351 bool wxGenericListCtrl::SortItems( wxListCtrlCompare fn
, long data
)
5353 m_mainWin
->SortItems( fn
, data
);
5357 // ----------------------------------------------------------------------------
5359 // ----------------------------------------------------------------------------
5361 void wxGenericListCtrl::OnSize(wxSizeEvent
& WXUNUSED(event
))
5366 ResizeReportView(m_mainWin
->HasHeader());
5368 m_mainWin
->RecalculatePositions();
5371 void wxGenericListCtrl::ResizeReportView(bool showHeader
)
5374 GetClientSize( &cw
, &ch
);
5378 m_headerWin
->SetSize( 0, 0, cw
, m_headerHeight
);
5379 m_mainWin
->SetSize( 0, m_headerHeight
+ 1, cw
, ch
- m_headerHeight
- 1 );
5381 else // no header window
5383 m_mainWin
->SetSize( 0, 0, cw
, ch
);
5387 void wxGenericListCtrl::OnInternalIdle()
5389 wxWindow::OnInternalIdle();
5391 // do it only if needed
5392 if ( !m_mainWin
->m_dirty
)
5395 m_mainWin
->RecalculatePositions();
5398 // ----------------------------------------------------------------------------
5400 // ----------------------------------------------------------------------------
5402 bool wxGenericListCtrl::SetBackgroundColour( const wxColour
&colour
)
5406 m_mainWin
->SetBackgroundColour( colour
);
5407 m_mainWin
->m_dirty
= true;
5413 bool wxGenericListCtrl::SetForegroundColour( const wxColour
&colour
)
5415 if ( !wxWindow::SetForegroundColour( colour
) )
5420 m_mainWin
->SetForegroundColour( colour
);
5421 m_mainWin
->m_dirty
= true;
5426 m_headerWin
->SetForegroundColour( colour
);
5432 bool wxGenericListCtrl::SetFont( const wxFont
&font
)
5434 if ( !wxWindow::SetFont( font
) )
5439 m_mainWin
->SetFont( font
);
5440 m_mainWin
->m_dirty
= true;
5445 m_headerWin
->SetFont( font
);
5446 CalculateAndSetHeaderHeight();
5457 #include "wx/listbox.h"
5462 wxGenericListCtrl::GetClassDefaultAttributes(wxWindowVariant variant
)
5465 // Use the same color scheme as wxListBox
5466 return wxListBox::GetClassDefaultAttributes(variant
);
5468 wxUnusedVar(variant
);
5469 wxVisualAttributes attr
;
5470 attr
.colFg
= wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT
);
5471 attr
.colBg
= wxSystemSettings::GetColour(wxSYS_COLOUR_LISTBOX
);
5472 attr
.font
= wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT
);
5477 // ----------------------------------------------------------------------------
5478 // methods forwarded to m_mainWin
5479 // ----------------------------------------------------------------------------
5481 #if wxUSE_DRAG_AND_DROP
5483 void wxGenericListCtrl::SetDropTarget( wxDropTarget
*dropTarget
)
5485 m_mainWin
->SetDropTarget( dropTarget
);
5488 wxDropTarget
*wxGenericListCtrl::GetDropTarget() const
5490 return m_mainWin
->GetDropTarget();
5493 #endif // wxUSE_DRAG_AND_DROP
5495 bool wxGenericListCtrl::SetCursor( const wxCursor
&cursor
)
5497 return m_mainWin
? m_mainWin
->wxWindow::SetCursor(cursor
) : false;
5500 wxColour
wxGenericListCtrl::GetBackgroundColour() const
5502 return m_mainWin
? m_mainWin
->GetBackgroundColour() : wxColour();
5505 wxColour
wxGenericListCtrl::GetForegroundColour() const
5507 return m_mainWin
? m_mainWin
->GetForegroundColour() : wxColour();
5510 bool wxGenericListCtrl::DoPopupMenu( wxMenu
*menu
, int x
, int y
)
5513 return m_mainWin
->PopupMenu( menu
, x
, y
);
5516 #endif // wxUSE_MENUS
5519 void wxGenericListCtrl::SetFocus()
5521 /* The test in window.cpp fails as we are a composite
5522 window, so it checks against "this", but not m_mainWin. */
5523 if ( DoFindFocus() != this )
5524 m_mainWin
->SetFocus();
5527 wxSize
wxGenericListCtrl::DoGetBestSize() const
5529 // Something is better than nothing...
5530 // 100x80 is what the MSW version will get from the default
5531 // wxControl::DoGetBestSize
5532 return wxSize(100,80);
5535 // ----------------------------------------------------------------------------
5536 // virtual list control support
5537 // ----------------------------------------------------------------------------
5539 wxString
wxGenericListCtrl::OnGetItemText(long WXUNUSED(item
), long WXUNUSED(col
)) const
5541 // this is a pure virtual function, in fact - which is not really pure
5542 // because the controls which are not virtual don't need to implement it
5543 wxFAIL_MSG( _T("wxGenericListCtrl::OnGetItemText not supposed to be called") );
5545 return wxEmptyString
;
5548 int wxGenericListCtrl::OnGetItemImage(long WXUNUSED(item
)) const
5550 wxCHECK_MSG(!GetImageList(wxIMAGE_LIST_SMALL
),
5552 wxT("List control has an image list, OnGetItemImage should be overridden."));
5557 wxGenericListCtrl::OnGetItemAttr(long WXUNUSED_UNLESS_DEBUG(item
)) const
5559 wxASSERT_MSG( item
>= 0 && item
< GetItemCount(),
5560 _T("invalid item index in OnGetItemAttr()") );
5562 // no attributes by default
5566 void wxGenericListCtrl::SetItemCount(long count
)
5568 wxASSERT_MSG( IsVirtual(), _T("this is for virtual controls only") );
5570 m_mainWin
->SetItemCount(count
);
5573 void wxGenericListCtrl::RefreshItem(long item
)
5575 m_mainWin
->RefreshLine(item
);
5578 void wxGenericListCtrl::RefreshItems(long itemFrom
, long itemTo
)
5580 m_mainWin
->RefreshLines(itemFrom
, itemTo
);
5584 * Generic wxListCtrl is more or less a container for two other
5585 * windows which drawings are done upon. These are namely
5586 * 'm_headerWin' and 'm_mainWin'.
5587 * Here we override 'virtual wxWindow::Refresh()' to mimic the
5588 * behaviour wxListCtrl has under wxMSW.
5590 void wxGenericListCtrl::Refresh(bool eraseBackground
, const wxRect
*rect
)
5594 // The easy case, no rectangle specified.
5596 m_headerWin
->Refresh(eraseBackground
);
5599 m_mainWin
->Refresh(eraseBackground
);
5603 // Refresh the header window
5606 wxRect rectHeader
= m_headerWin
->GetRect();
5607 rectHeader
.Intersect(*rect
);
5608 if (rectHeader
.GetWidth() && rectHeader
.GetHeight())
5611 m_headerWin
->GetPosition(&x
, &y
);
5612 rectHeader
.Offset(-x
, -y
);
5613 m_headerWin
->Refresh(eraseBackground
, &rectHeader
);
5618 // Refresh the main window
5621 wxRect rectMain
= m_mainWin
->GetRect();
5622 rectMain
.Intersect(*rect
);
5623 if (rectMain
.GetWidth() && rectMain
.GetHeight())
5626 m_mainWin
->GetPosition(&x
, &y
);
5627 rectMain
.Offset(-x
, -y
);
5628 m_mainWin
->Refresh(eraseBackground
, &rectMain
);
5634 void wxGenericListCtrl::Freeze()
5636 m_mainWin
->Freeze();
5639 void wxGenericListCtrl::Thaw()
5644 #endif // wxUSE_LISTCTRL