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_mask
= wxLIST_MASK_TEXT
;
678 info
.m_itemId
= item
;
683 void SetItemText(long item
, const wxString
& value
)
686 info
.m_mask
= wxLIST_MASK_TEXT
;
687 info
.m_itemId
= item
;
692 // set the scrollbars and update the positions of the items
693 void RecalculatePositions(bool noRefresh
= false);
695 // refresh the window and the header
698 long GetNextItem( long item
, int geometry
, int state
) const;
699 void DeleteItem( long index
);
700 void DeleteAllItems();
701 void DeleteColumn( int col
);
702 void DeleteEverything();
703 void EnsureVisible( long index
);
704 long FindItem( long start
, const wxString
& str
, bool partial
= false );
705 long FindItem( long start
, wxUIntPtr data
);
706 long FindItem( const wxPoint
& pt
);
707 long HitTest( int x
, int y
, int &flags
);
708 void InsertItem( wxListItem
&item
);
709 void InsertColumn( long col
, wxListItem
&item
);
710 int GetItemWidthWithImage(wxListItem
* item
);
711 void SortItems( wxListCtrlCompare fn
, long data
);
713 size_t GetItemCount() const;
714 bool IsEmpty() const { return GetItemCount() == 0; }
715 void SetItemCount(long count
);
717 // change the current (== focused) item, send a notification event
718 void ChangeCurrent(size_t current
);
719 void ResetCurrent() { ChangeCurrent((size_t)-1); }
720 bool HasCurrent() const { return m_current
!= (size_t)-1; }
722 // send out a wxListEvent
723 void SendNotify( size_t line
,
725 wxPoint point
= wxDefaultPosition
);
727 // override base class virtual to reset m_lineHeight when the font changes
728 virtual bool SetFont(const wxFont
& font
)
730 if ( !wxScrolledWindow::SetFont(font
) )
738 // these are for wxListLineData usage only
740 // get the backpointer to the list ctrl
741 wxGenericListCtrl
*GetListCtrl() const
743 return wxStaticCast(GetParent(), wxGenericListCtrl
);
746 // get the height of all lines (assuming they all do have the same height)
747 wxCoord
GetLineHeight() const;
749 // get the y position of the given line (only for report view)
750 wxCoord
GetLineY(size_t line
) const;
752 // get the brush to use for the item highlighting
753 wxBrush
*GetHighlightBrush() const
755 return m_hasFocus
? m_highlightBrush
: m_highlightUnfocusedBrush
;
759 // the array of all line objects for a non virtual list control (for the
760 // virtual list control we only ever use m_lines[0])
761 wxListLineDataArray m_lines
;
763 // the list of column objects
764 wxListHeaderDataList m_columns
;
766 // currently focused item or -1
769 // the number of lines per page
772 // this flag is set when something which should result in the window
773 // redrawing happens (i.e. an item was added or deleted, or its appearance
774 // changed) and OnPaint() doesn't redraw the window while it is set which
775 // allows to minimize the number of repaintings when a lot of items are
776 // being added. The real repainting occurs only after the next OnIdle()
780 wxColour
*m_highlightColour
;
781 wxImageListType
*m_small_image_list
;
782 wxImageListType
*m_normal_image_list
;
784 int m_normal_spacing
;
788 wxTimer
*m_renameTimer
;
792 ColWidthArray m_aColWidths
;
794 // for double click logic
795 size_t m_lineLastClicked
,
796 m_lineBeforeLastClicked
,
797 m_lineSelectSingleOnUp
;
800 // the total count of items in a virtual list control
803 // the object maintaining the items selection state, only used in virtual
805 wxSelectionStore m_selStore
;
807 // common part of all ctors
810 // get the line data for the given index
811 wxListLineData
*GetLine(size_t n
) const
813 wxASSERT_MSG( n
!= (size_t)-1, _T("invalid line index") );
817 wxConstCast(this, wxListMainWindow
)->CacheLineData(n
);
825 // get a dummy line which can be used for geometry calculations and such:
826 // you must use GetLine() if you want to really draw the line
827 wxListLineData
*GetDummyLine() const;
829 // cache the line data of the n-th line in m_lines[0]
830 void CacheLineData(size_t line
);
832 // get the range of visible lines
833 void GetVisibleLinesRange(size_t *from
, size_t *to
);
835 // force us to recalculate the range of visible lines
836 void ResetVisibleLinesRange() { m_lineFrom
= (size_t)-1; }
838 // get the colour to be used for drawing the rules
839 wxColour
GetRuleColour() const
841 return wxSystemSettings::GetColour(wxSYS_COLOUR_3DLIGHT
);
845 // initialize the current item if needed
846 void UpdateCurrent();
848 // delete all items but don't refresh: called from dtor
849 void DoDeleteAllItems();
851 // the height of one line using the current font
852 wxCoord m_lineHeight
;
854 // the total header width or 0 if not calculated yet
855 wxCoord m_headerWidth
;
857 // the first and last lines being shown on screen right now (inclusive),
858 // both may be -1 if they must be calculated so never access them directly:
859 // use GetVisibleLinesRange() above instead
863 // the brushes to use for item highlighting when we do/don't have focus
864 wxBrush
*m_highlightBrush
,
865 *m_highlightUnfocusedBrush
;
867 // if this is > 0, the control is frozen and doesn't redraw itself
868 size_t m_freezeCount
;
870 DECLARE_DYNAMIC_CLASS(wxListMainWindow
)
871 DECLARE_EVENT_TABLE()
873 friend class wxGenericListCtrl
;
876 // ============================================================================
878 // ============================================================================
880 //-----------------------------------------------------------------------------
882 //-----------------------------------------------------------------------------
884 wxListItemData::~wxListItemData()
886 // in the virtual list control the attributes are managed by the main
887 // program, so don't delete them
888 if ( !m_owner
->IsVirtual() )
896 void wxListItemData::Init()
904 wxListItemData::wxListItemData(wxListMainWindow
*owner
)
910 if ( owner
->InReportView() )
920 void wxListItemData::SetItem( const wxListItem
&info
)
922 if ( info
.m_mask
& wxLIST_MASK_TEXT
)
923 SetText(info
.m_text
);
924 if ( info
.m_mask
& wxLIST_MASK_IMAGE
)
925 m_image
= info
.m_image
;
926 if ( info
.m_mask
& wxLIST_MASK_DATA
)
927 m_data
= info
.m_data
;
929 if ( info
.HasAttributes() )
932 *m_attr
= *info
.GetAttributes();
934 m_attr
= new wxListItemAttr(*info
.GetAttributes());
942 m_rect
->width
= info
.m_width
;
946 void wxListItemData::SetPosition( int x
, int y
)
948 wxCHECK_RET( m_rect
, _T("unexpected SetPosition() call") );
954 void wxListItemData::SetSize( int width
, int height
)
956 wxCHECK_RET( m_rect
, _T("unexpected SetSize() call") );
959 m_rect
->width
= width
;
961 m_rect
->height
= height
;
964 bool wxListItemData::IsHit( int x
, int y
) const
966 wxCHECK_MSG( m_rect
, false, _T("can't be called in this mode") );
968 return wxRect(GetX(), GetY(), GetWidth(), GetHeight()).Inside(x
, y
);
971 int wxListItemData::GetX() const
973 wxCHECK_MSG( m_rect
, 0, _T("can't be called in this mode") );
978 int wxListItemData::GetY() const
980 wxCHECK_MSG( m_rect
, 0, _T("can't be called in this mode") );
985 int wxListItemData::GetWidth() const
987 wxCHECK_MSG( m_rect
, 0, _T("can't be called in this mode") );
989 return m_rect
->width
;
992 int wxListItemData::GetHeight() const
994 wxCHECK_MSG( m_rect
, 0, _T("can't be called in this mode") );
996 return m_rect
->height
;
999 void wxListItemData::GetItem( wxListItem
&info
) const
1001 long mask
= info
.m_mask
;
1004 // by default, get everything for backwards compatibility
1008 if ( mask
& wxLIST_MASK_TEXT
)
1009 info
.m_text
= m_text
;
1010 if ( mask
& wxLIST_MASK_IMAGE
)
1011 info
.m_image
= m_image
;
1012 if ( mask
& wxLIST_MASK_DATA
)
1013 info
.m_data
= m_data
;
1017 if ( m_attr
->HasTextColour() )
1018 info
.SetTextColour(m_attr
->GetTextColour());
1019 if ( m_attr
->HasBackgroundColour() )
1020 info
.SetBackgroundColour(m_attr
->GetBackgroundColour());
1021 if ( m_attr
->HasFont() )
1022 info
.SetFont(m_attr
->GetFont());
1026 //-----------------------------------------------------------------------------
1028 //-----------------------------------------------------------------------------
1030 void wxListHeaderData::Init()
1041 wxListHeaderData::wxListHeaderData()
1046 wxListHeaderData::wxListHeaderData( const wxListItem
&item
)
1053 void wxListHeaderData::SetItem( const wxListItem
&item
)
1055 m_mask
= item
.m_mask
;
1057 if ( m_mask
& wxLIST_MASK_TEXT
)
1058 m_text
= item
.m_text
;
1060 if ( m_mask
& wxLIST_MASK_IMAGE
)
1061 m_image
= item
.m_image
;
1063 if ( m_mask
& wxLIST_MASK_FORMAT
)
1064 m_format
= item
.m_format
;
1066 if ( m_mask
& wxLIST_MASK_WIDTH
)
1067 SetWidth(item
.m_width
);
1070 void wxListHeaderData::SetPosition( int x
, int y
)
1076 void wxListHeaderData::SetHeight( int h
)
1081 void wxListHeaderData::SetWidth( int w
)
1085 m_width
= WIDTH_COL_DEFAULT
;
1086 else if (m_width
< WIDTH_COL_MIN
)
1087 m_width
= WIDTH_COL_MIN
;
1090 void wxListHeaderData::SetFormat( int format
)
1095 bool wxListHeaderData::HasImage() const
1097 return m_image
!= -1;
1100 bool wxListHeaderData::IsHit( int x
, int y
) const
1102 return ((x
>= m_xpos
) && (x
<= m_xpos
+m_width
) && (y
>= m_ypos
) && (y
<= m_ypos
+m_height
));
1105 void wxListHeaderData::GetItem( wxListItem
& item
)
1107 item
.m_mask
= m_mask
;
1108 item
.m_text
= m_text
;
1109 item
.m_image
= m_image
;
1110 item
.m_format
= m_format
;
1111 item
.m_width
= m_width
;
1114 int wxListHeaderData::GetImage() const
1119 int wxListHeaderData::GetWidth() const
1124 int wxListHeaderData::GetFormat() const
1129 //-----------------------------------------------------------------------------
1131 //-----------------------------------------------------------------------------
1133 inline int wxListLineData::GetMode() const
1135 return m_owner
->GetListCtrl()->GetWindowStyleFlag() & wxLC_MASK_TYPE
;
1138 inline bool wxListLineData::InReportView() const
1140 return m_owner
->HasFlag(wxLC_REPORT
);
1143 inline bool wxListLineData::IsVirtual() const
1145 return m_owner
->IsVirtual();
1148 wxListLineData::wxListLineData( wxListMainWindow
*owner
)
1152 if ( InReportView() )
1158 m_gi
= new GeometryInfo
;
1161 m_highlighted
= false;
1163 InitItems( GetMode() == wxLC_REPORT
? m_owner
->GetColumnCount() : 1 );
1166 void wxListLineData::CalculateSize( wxDC
*dc
, int spacing
)
1168 wxListItemDataList::compatibility_iterator node
= m_items
.GetFirst();
1169 wxCHECK_RET( node
, _T("no subitems at all??") );
1171 wxListItemData
*item
= node
->GetData();
1176 switch ( GetMode() )
1179 case wxLC_SMALL_ICON
:
1180 m_gi
->m_rectAll
.width
= spacing
;
1182 s
= item
->GetText();
1187 m_gi
->m_rectLabel
.width
=
1188 m_gi
->m_rectLabel
.height
= 0;
1192 dc
->GetTextExtent( s
, &lw
, &lh
);
1196 m_gi
->m_rectAll
.height
= spacing
+ lh
;
1198 m_gi
->m_rectAll
.width
= lw
;
1200 m_gi
->m_rectLabel
.width
= lw
;
1201 m_gi
->m_rectLabel
.height
= lh
;
1204 if (item
->HasImage())
1207 m_owner
->GetImageSize( item
->GetImage(), w
, h
);
1208 m_gi
->m_rectIcon
.width
= w
+ 8;
1209 m_gi
->m_rectIcon
.height
= h
+ 8;
1211 if ( m_gi
->m_rectIcon
.width
> m_gi
->m_rectAll
.width
)
1212 m_gi
->m_rectAll
.width
= m_gi
->m_rectIcon
.width
;
1213 if ( m_gi
->m_rectIcon
.height
+ lh
> m_gi
->m_rectAll
.height
- 4 )
1214 m_gi
->m_rectAll
.height
= m_gi
->m_rectIcon
.height
+ lh
+ 4;
1217 if ( item
->HasText() )
1219 m_gi
->m_rectHighlight
.width
= m_gi
->m_rectLabel
.width
;
1220 m_gi
->m_rectHighlight
.height
= m_gi
->m_rectLabel
.height
;
1222 else // no text, highlight the icon
1224 m_gi
->m_rectHighlight
.width
= m_gi
->m_rectIcon
.width
;
1225 m_gi
->m_rectHighlight
.height
= m_gi
->m_rectIcon
.height
;
1230 s
= item
->GetTextForMeasuring();
1232 dc
->GetTextExtent( s
, &lw
, &lh
);
1236 m_gi
->m_rectLabel
.width
= lw
;
1237 m_gi
->m_rectLabel
.height
= lh
;
1239 m_gi
->m_rectAll
.width
= lw
;
1240 m_gi
->m_rectAll
.height
= lh
;
1242 if (item
->HasImage())
1245 m_owner
->GetImageSize( item
->GetImage(), w
, h
);
1246 m_gi
->m_rectIcon
.width
= w
;
1247 m_gi
->m_rectIcon
.height
= h
;
1249 m_gi
->m_rectAll
.width
+= 4 + w
;
1250 if (h
> m_gi
->m_rectAll
.height
)
1251 m_gi
->m_rectAll
.height
= h
;
1254 m_gi
->m_rectHighlight
.width
= m_gi
->m_rectAll
.width
;
1255 m_gi
->m_rectHighlight
.height
= m_gi
->m_rectAll
.height
;
1259 wxFAIL_MSG( _T("unexpected call to SetSize") );
1263 wxFAIL_MSG( _T("unknown mode") );
1267 void wxListLineData::SetPosition( int x
, int y
, int spacing
)
1269 wxListItemDataList::compatibility_iterator node
= m_items
.GetFirst();
1270 wxCHECK_RET( node
, _T("no subitems at all??") );
1272 wxListItemData
*item
= node
->GetData();
1274 switch ( GetMode() )
1277 case wxLC_SMALL_ICON
:
1278 m_gi
->m_rectAll
.x
= x
;
1279 m_gi
->m_rectAll
.y
= y
;
1281 if ( item
->HasImage() )
1283 m_gi
->m_rectIcon
.x
= m_gi
->m_rectAll
.x
+ 4 +
1284 (m_gi
->m_rectAll
.width
- m_gi
->m_rectIcon
.width
) / 2;
1285 m_gi
->m_rectIcon
.y
= m_gi
->m_rectAll
.y
+ 4;
1288 if ( item
->HasText() )
1290 if (m_gi
->m_rectAll
.width
> spacing
)
1291 m_gi
->m_rectLabel
.x
= m_gi
->m_rectAll
.x
+ 2;
1293 m_gi
->m_rectLabel
.x
= m_gi
->m_rectAll
.x
+ 2 + (spacing
/2) - (m_gi
->m_rectLabel
.width
/2);
1294 m_gi
->m_rectLabel
.y
= m_gi
->m_rectAll
.y
+ m_gi
->m_rectAll
.height
+ 2 - m_gi
->m_rectLabel
.height
;
1295 m_gi
->m_rectHighlight
.x
= m_gi
->m_rectLabel
.x
- 2;
1296 m_gi
->m_rectHighlight
.y
= m_gi
->m_rectLabel
.y
- 2;
1298 else // no text, highlight the icon
1300 m_gi
->m_rectHighlight
.x
= m_gi
->m_rectIcon
.x
- 4;
1301 m_gi
->m_rectHighlight
.y
= m_gi
->m_rectIcon
.y
- 4;
1306 m_gi
->m_rectAll
.x
= x
;
1307 m_gi
->m_rectAll
.y
= y
;
1309 m_gi
->m_rectHighlight
.x
= m_gi
->m_rectAll
.x
;
1310 m_gi
->m_rectHighlight
.y
= m_gi
->m_rectAll
.y
;
1311 m_gi
->m_rectLabel
.y
= m_gi
->m_rectAll
.y
+ 2;
1313 if (item
->HasImage())
1315 m_gi
->m_rectIcon
.x
= m_gi
->m_rectAll
.x
+ 2;
1316 m_gi
->m_rectIcon
.y
= m_gi
->m_rectAll
.y
+ 2;
1317 m_gi
->m_rectLabel
.x
= m_gi
->m_rectAll
.x
+ 6 + m_gi
->m_rectIcon
.width
;
1321 m_gi
->m_rectLabel
.x
= m_gi
->m_rectAll
.x
+ 2;
1326 wxFAIL_MSG( _T("unexpected call to SetPosition") );
1330 wxFAIL_MSG( _T("unknown mode") );
1334 void wxListLineData::InitItems( int num
)
1336 for (int i
= 0; i
< num
; i
++)
1337 m_items
.Append( new wxListItemData(m_owner
) );
1340 void wxListLineData::SetItem( int index
, const wxListItem
&info
)
1342 wxListItemDataList::compatibility_iterator node
= m_items
.Item( index
);
1343 wxCHECK_RET( node
, _T("invalid column index in SetItem") );
1345 wxListItemData
*item
= node
->GetData();
1346 item
->SetItem( info
);
1349 void wxListLineData::GetItem( int index
, wxListItem
&info
)
1351 wxListItemDataList::compatibility_iterator node
= m_items
.Item( index
);
1354 wxListItemData
*item
= node
->GetData();
1355 item
->GetItem( info
);
1359 wxString
wxListLineData::GetText(int index
) const
1363 wxListItemDataList::compatibility_iterator node
= m_items
.Item( index
);
1366 wxListItemData
*item
= node
->GetData();
1367 s
= item
->GetText();
1373 void wxListLineData::SetText( int index
, const wxString s
)
1375 wxListItemDataList::compatibility_iterator node
= m_items
.Item( index
);
1378 wxListItemData
*item
= node
->GetData();
1383 void wxListLineData::SetImage( int index
, int image
)
1385 wxListItemDataList::compatibility_iterator node
= m_items
.Item( index
);
1386 wxCHECK_RET( node
, _T("invalid column index in SetImage()") );
1388 wxListItemData
*item
= node
->GetData();
1389 item
->SetImage(image
);
1392 int wxListLineData::GetImage( int index
) const
1394 wxListItemDataList::compatibility_iterator node
= m_items
.Item( index
);
1395 wxCHECK_MSG( node
, -1, _T("invalid column index in GetImage()") );
1397 wxListItemData
*item
= node
->GetData();
1398 return item
->GetImage();
1401 wxListItemAttr
*wxListLineData::GetAttr() const
1403 wxListItemDataList::compatibility_iterator node
= m_items
.GetFirst();
1404 wxCHECK_MSG( node
, NULL
, _T("invalid column index in GetAttr()") );
1406 wxListItemData
*item
= node
->GetData();
1407 return item
->GetAttr();
1410 void wxListLineData::SetAttr(wxListItemAttr
*attr
)
1412 wxListItemDataList::compatibility_iterator node
= m_items
.GetFirst();
1413 wxCHECK_RET( node
, _T("invalid column index in SetAttr()") );
1415 wxListItemData
*item
= node
->GetData();
1416 item
->SetAttr(attr
);
1419 bool wxListLineData::SetAttributes(wxDC
*dc
,
1420 const wxListItemAttr
*attr
,
1423 wxWindow
*listctrl
= m_owner
->GetParent();
1427 // don't use foreground colour for drawing highlighted items - this might
1428 // make them completely invisible (and there is no way to do bit
1429 // arithmetics on wxColour, unfortunately)
1433 colText
= wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHTTEXT
);
1437 if ( attr
&& attr
->HasTextColour() )
1439 colText
= attr
->GetTextColour();
1443 colText
= listctrl
->GetForegroundColour();
1447 dc
->SetTextForeground(colText
);
1451 if ( attr
&& attr
->HasFont() )
1453 font
= attr
->GetFont();
1457 font
= listctrl
->GetFont();
1463 bool hasBgCol
= attr
&& attr
->HasBackgroundColour();
1464 if ( highlighted
|| hasBgCol
)
1468 dc
->SetBrush( *m_owner
->GetHighlightBrush() );
1472 dc
->SetBrush(wxBrush(attr
->GetBackgroundColour(), wxSOLID
));
1475 dc
->SetPen( *wxTRANSPARENT_PEN
);
1483 void wxListLineData::Draw( wxDC
*dc
)
1485 wxListItemDataList::compatibility_iterator node
= m_items
.GetFirst();
1486 wxCHECK_RET( node
, _T("no subitems at all??") );
1488 bool highlighted
= IsHighlighted();
1490 wxListItemAttr
*attr
= GetAttr();
1492 if ( SetAttributes(dc
, attr
, highlighted
) )
1494 dc
->DrawRectangle( m_gi
->m_rectHighlight
);
1497 // just for debugging to better see where the items are
1499 dc
->SetPen(*wxRED_PEN
);
1500 dc
->SetBrush(*wxTRANSPARENT_BRUSH
);
1501 dc
->DrawRectangle( m_gi
->m_rectAll
);
1502 dc
->SetPen(*wxGREEN_PEN
);
1503 dc
->DrawRectangle( m_gi
->m_rectIcon
);
1506 wxListItemData
*item
= node
->GetData();
1507 if (item
->HasImage())
1509 // centre the image inside our rectangle, this looks nicer when items
1510 // ae aligned in a row
1511 const wxRect
& rectIcon
= m_gi
->m_rectIcon
;
1513 m_owner
->DrawImage(item
->GetImage(), dc
, rectIcon
.x
, rectIcon
.y
);
1516 if (item
->HasText())
1518 const wxRect
& rectLabel
= m_gi
->m_rectLabel
;
1520 wxDCClipper
clipper(*dc
, rectLabel
);
1521 dc
->DrawText(item
->GetText(), rectLabel
.x
, rectLabel
.y
);
1525 void wxListLineData::DrawInReportMode( wxDC
*dc
,
1527 const wxRect
& rectHL
,
1530 // TODO: later we should support setting different attributes for
1531 // different columns - to do it, just add "col" argument to
1532 // GetAttr() and move these lines into the loop below
1533 wxListItemAttr
*attr
= GetAttr();
1534 if ( SetAttributes(dc
, attr
, highlighted
) )
1536 dc
->DrawRectangle( rectHL
);
1539 wxCoord x
= rect
.x
+ HEADER_OFFSET_X
,
1540 y
= rect
.y
+ (LINE_SPACING
+ EXTRA_HEIGHT
) / 2;
1543 for ( wxListItemDataList::compatibility_iterator node
= m_items
.GetFirst();
1545 node
= node
->GetNext(), col
++ )
1547 wxListItemData
*item
= node
->GetData();
1549 int width
= m_owner
->GetColumnWidth(col
);
1553 if ( item
->HasImage() )
1556 m_owner
->DrawImage( item
->GetImage(), dc
, xOld
, y
);
1557 m_owner
->GetImageSize( item
->GetImage(), ix
, iy
);
1559 ix
+= IMAGE_MARGIN_IN_REPORT_MODE
;
1565 wxDCClipper
clipper(*dc
, xOld
, y
, width
- 8, rect
.height
);
1567 if ( item
->HasText() )
1569 DrawTextFormatted(dc
, item
->GetText(), col
, xOld
, y
, width
- 8);
1574 void wxListLineData::DrawTextFormatted(wxDC
*dc
,
1575 const wxString
&text
,
1581 wxString drawntext
, ellipsis
;
1582 wxCoord w
, h
, base_w
;
1585 // determine if the string can fit inside the current width
1586 dc
->GetTextExtent(text
, &w
, &h
);
1589 // it can, draw it using the items alignment
1590 m_owner
->GetColumn(col
, item
);
1591 switch ( item
.GetAlign() )
1594 wxFAIL_MSG( _T("unknown list item format") );
1597 case wxLIST_FORMAT_LEFT
:
1601 case wxLIST_FORMAT_RIGHT
:
1605 case wxLIST_FORMAT_CENTER
:
1606 x
+= (width
- w
) / 2;
1610 dc
->DrawText(text
, x
, y
);
1612 else // otherwise, truncate and add an ellipsis if possible
1614 // determine the base width
1615 ellipsis
= wxString(wxT("..."));
1616 dc
->GetTextExtent(ellipsis
, &base_w
, &h
);
1618 // continue until we have enough space or only one character left
1620 size_t len
= text
.Length();
1621 drawntext
= text
.Left(len
);
1624 dc
->GetTextExtent(drawntext
.Last(), &w_c
, &h_c
);
1625 drawntext
.RemoveLast();
1628 if (w
+ base_w
<= width
)
1632 // if still not enough space, remove ellipsis characters
1633 while (ellipsis
.Length() > 0 && w
+ base_w
> width
)
1635 ellipsis
= ellipsis
.Left(ellipsis
.Length() - 1);
1636 dc
->GetTextExtent(ellipsis
, &base_w
, &h
);
1639 // now draw the text
1640 dc
->DrawText(drawntext
, x
, y
);
1641 dc
->DrawText(ellipsis
, x
+ w
, y
);
1645 bool wxListLineData::Highlight( bool on
)
1647 wxCHECK_MSG( !IsVirtual(), false, _T("unexpected call to Highlight") );
1649 if ( on
== m_highlighted
)
1657 void wxListLineData::ReverseHighlight( void )
1659 Highlight(!IsHighlighted());
1662 //-----------------------------------------------------------------------------
1663 // wxListHeaderWindow
1664 //-----------------------------------------------------------------------------
1666 IMPLEMENT_DYNAMIC_CLASS(wxListHeaderWindow
,wxWindow
)
1668 BEGIN_EVENT_TABLE(wxListHeaderWindow
,wxWindow
)
1669 EVT_PAINT (wxListHeaderWindow::OnPaint
)
1670 EVT_MOUSE_EVENTS (wxListHeaderWindow::OnMouse
)
1671 EVT_SET_FOCUS (wxListHeaderWindow::OnSetFocus
)
1674 void wxListHeaderWindow::Init()
1676 m_currentCursor
= (wxCursor
*) NULL
;
1677 m_isDragging
= false;
1681 wxListHeaderWindow::wxListHeaderWindow()
1685 m_owner
= (wxListMainWindow
*) NULL
;
1686 m_resizeCursor
= (wxCursor
*) NULL
;
1689 wxListHeaderWindow::wxListHeaderWindow( wxWindow
*win
,
1691 wxListMainWindow
*owner
,
1695 const wxString
&name
)
1696 : wxWindow( win
, id
, pos
, size
, style
, name
)
1701 m_resizeCursor
= new wxCursor( wxCURSOR_SIZEWE
);
1704 wxVisualAttributes attr
= wxPanel::GetClassDefaultAttributes();
1705 SetOwnForegroundColour( attr
.colFg
);
1706 SetOwnBackgroundColour( attr
.colBg
);
1708 SetOwnFont( attr
.font
);
1710 SetOwnForegroundColour( wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT
));
1711 SetOwnBackgroundColour( wxSystemSettings::GetColour(wxSYS_COLOUR_BTNFACE
));
1713 SetOwnFont( wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT
));
1717 wxListHeaderWindow::~wxListHeaderWindow()
1719 delete m_resizeCursor
;
1722 #ifdef __WXUNIVERSAL__
1723 #include "wx/univ/renderer.h"
1724 #include "wx/univ/theme.h"
1727 // shift the DC origin to match the position of the main window horz
1728 // scrollbar: this allows us to always use logical coords
1729 void wxListHeaderWindow::AdjustDC(wxDC
& dc
)
1732 m_owner
->GetScrollPixelsPerUnit( &xpix
, NULL
);
1735 m_owner
->GetViewStart( &x
, NULL
);
1737 // account for the horz scrollbar offset
1738 dc
.SetDeviceOrigin( -x
* xpix
, 0 );
1741 void wxListHeaderWindow::OnPaint( wxPaintEvent
&WXUNUSED(event
) )
1743 wxPaintDC
dc( this );
1750 dc
.SetFont( GetFont() );
1752 // width and height of the entire header window
1754 GetClientSize( &w
, &h
);
1755 m_owner
->CalcUnscrolledPosition(w
, 0, &w
, NULL
);
1757 dc
.SetBackgroundMode(wxTRANSPARENT
);
1759 dc
.SetTextForeground(GetForegroundColour());
1761 int x
= HEADER_OFFSET_X
;
1763 int numColumns
= m_owner
->GetColumnCount();
1765 for ( int i
= 0; i
< numColumns
&& x
< w
; i
++ )
1767 m_owner
->GetColumn( i
, item
);
1768 int wCol
= item
.m_width
;
1770 // the width of the rect to draw: make it smaller to fit entirely
1771 // inside the column rect
1779 wxRendererNative::Get().DrawHeaderButton
1783 wxRect(x
, HEADER_OFFSET_Y
, cw
, ch
),
1784 m_parent
->IsEnabled() ? 0
1785 : (int)wxCONTROL_DISABLED
1788 // see if we have enough space for the column label
1790 // for this we need the width of the text
1793 dc
.GetTextExtent(item
.GetText(), &wLabel
, &hLabel
);
1794 wLabel
+= 2*EXTRA_WIDTH
;
1796 // and the width of the icon, if any
1797 static const int MARGIN_BETWEEN_TEXT_AND_ICON
= 2;
1798 int ix
= 0, // init them just to suppress the compiler warnings
1800 const int image
= item
.m_image
;
1801 wxImageListType
*imageList
;
1804 imageList
= m_owner
->m_small_image_list
;
1807 imageList
->GetSize(image
, ix
, iy
);
1808 wLabel
+= ix
+ MARGIN_BETWEEN_TEXT_AND_ICON
;
1816 // ignore alignment if there is not enough space anyhow
1818 switch ( wLabel
< cw
? item
.GetAlign() : wxLIST_FORMAT_LEFT
)
1821 wxFAIL_MSG( _T("unknown list item format") );
1824 case wxLIST_FORMAT_LEFT
:
1828 case wxLIST_FORMAT_RIGHT
:
1829 xAligned
= x
+ cw
- wLabel
;
1832 case wxLIST_FORMAT_CENTER
:
1833 xAligned
= x
+ (cw
- wLabel
) / 2;
1838 // if we have an image, draw it on the right of the label
1845 xAligned
+ wLabel
- ix
- MARGIN_BETWEEN_TEXT_AND_ICON
,
1846 HEADER_OFFSET_Y
+ (h
- 4 - iy
)/2,
1847 wxIMAGELIST_DRAW_TRANSPARENT
1850 cw
-= ix
+ MARGIN_BETWEEN_TEXT_AND_ICON
;
1853 // draw the text clipping it so that it doesn't overwrite the column
1855 wxDCClipper
clipper(dc
, x
, HEADER_OFFSET_Y
, cw
, h
- 4 );
1857 dc
.DrawText( item
.GetText(),
1858 xAligned
+ EXTRA_WIDTH
, h
/ 2 - hLabel
/ 2 ); //HEADER_OFFSET_Y + EXTRA_HEIGHT );
1866 void wxListHeaderWindow::DrawCurrent()
1868 int x1
= m_currentX
;
1870 m_owner
->ClientToScreen( &x1
, &y1
);
1872 int x2
= m_currentX
;
1874 m_owner
->GetClientSize( NULL
, &y2
);
1875 m_owner
->ClientToScreen( &x2
, &y2
);
1878 dc
.SetLogicalFunction( wxINVERT
);
1879 dc
.SetPen( wxPen( *wxBLACK
, 2, wxSOLID
) );
1880 dc
.SetBrush( *wxTRANSPARENT_BRUSH
);
1884 dc
.DrawLine( x1
, y1
, x2
, y2
);
1886 dc
.SetLogicalFunction( wxCOPY
);
1888 dc
.SetPen( wxNullPen
);
1889 dc
.SetBrush( wxNullBrush
);
1892 void wxListHeaderWindow::OnMouse( wxMouseEvent
&event
)
1894 // we want to work with logical coords
1896 m_owner
->CalcUnscrolledPosition(event
.GetX(), 0, &x
, NULL
);
1897 int y
= event
.GetY();
1901 SendListEvent(wxEVT_COMMAND_LIST_COL_DRAGGING
, event
.GetPosition());
1903 // we don't draw the line beyond our window, but we allow dragging it
1906 GetClientSize( &w
, NULL
);
1907 m_owner
->CalcUnscrolledPosition(w
, 0, &w
, NULL
);
1910 // erase the line if it was drawn
1911 if ( m_currentX
< w
)
1914 if (event
.ButtonUp())
1917 m_isDragging
= false;
1919 m_owner
->SetColumnWidth( m_column
, m_currentX
- m_minX
);
1920 SendListEvent(wxEVT_COMMAND_LIST_COL_END_DRAG
, event
.GetPosition());
1927 m_currentX
= m_minX
+ 7;
1929 // draw in the new location
1930 if ( m_currentX
< w
)
1934 else // not dragging
1937 bool hit_border
= false;
1939 // end of the current column
1942 // find the column where this event occurred
1944 countCol
= m_owner
->GetColumnCount();
1945 for (col
= 0; col
< countCol
; col
++)
1947 xpos
+= m_owner
->GetColumnWidth( col
);
1950 if ( (abs(x
-xpos
) < 3) && (y
< 22) )
1952 // near the column border
1959 // inside the column
1966 if ( col
== countCol
)
1969 if (event
.LeftDown() || event
.RightUp())
1971 if (hit_border
&& event
.LeftDown())
1973 if ( SendListEvent(wxEVT_COMMAND_LIST_COL_BEGIN_DRAG
,
1974 event
.GetPosition()) )
1976 m_isDragging
= true;
1981 //else: column resizing was vetoed by the user code
1983 else // click on a column
1985 SendListEvent( event
.LeftDown()
1986 ? wxEVT_COMMAND_LIST_COL_CLICK
1987 : wxEVT_COMMAND_LIST_COL_RIGHT_CLICK
,
1988 event
.GetPosition());
1991 else if (event
.Moving())
1996 setCursor
= m_currentCursor
== wxSTANDARD_CURSOR
;
1997 m_currentCursor
= m_resizeCursor
;
2001 setCursor
= m_currentCursor
!= wxSTANDARD_CURSOR
;
2002 m_currentCursor
= wxSTANDARD_CURSOR
;
2006 SetCursor(*m_currentCursor
);
2011 void wxListHeaderWindow::OnSetFocus( wxFocusEvent
&WXUNUSED(event
) )
2013 m_owner
->SetFocus();
2017 bool wxListHeaderWindow::SendListEvent(wxEventType type
, wxPoint pos
)
2019 wxWindow
*parent
= GetParent();
2020 wxListEvent
le( type
, parent
->GetId() );
2021 le
.SetEventObject( parent
);
2022 le
.m_pointDrag
= pos
;
2024 // the position should be relative to the parent window, not
2025 // this one for compatibility with MSW and common sense: the
2026 // user code doesn't know anything at all about this header
2027 // window, so why should it get positions relative to it?
2028 le
.m_pointDrag
.y
-= GetSize().y
;
2030 le
.m_col
= m_column
;
2031 return !parent
->GetEventHandler()->ProcessEvent( le
) || le
.IsAllowed();
2034 //-----------------------------------------------------------------------------
2035 // wxListRenameTimer (internal)
2036 //-----------------------------------------------------------------------------
2038 wxListRenameTimer::wxListRenameTimer( wxListMainWindow
*owner
)
2043 void wxListRenameTimer::Notify()
2045 m_owner
->OnRenameTimer();
2048 //-----------------------------------------------------------------------------
2049 // wxListTextCtrl (internal)
2050 //-----------------------------------------------------------------------------
2052 BEGIN_EVENT_TABLE(wxListTextCtrl
,wxTextCtrl
)
2053 EVT_CHAR (wxListTextCtrl::OnChar
)
2054 EVT_KEY_UP (wxListTextCtrl::OnKeyUp
)
2055 EVT_KILL_FOCUS (wxListTextCtrl::OnKillFocus
)
2058 wxListTextCtrl::wxListTextCtrl(wxListMainWindow
*owner
, size_t itemEdit
)
2059 : m_startValue(owner
->GetItemText(itemEdit
)),
2060 m_itemEdited(itemEdit
)
2064 m_aboutToFinish
= false;
2066 wxRect rectLabel
= owner
->GetLineLabelRect(itemEdit
);
2068 m_owner
->CalcScrolledPosition(rectLabel
.x
, rectLabel
.y
,
2069 &rectLabel
.x
, &rectLabel
.y
);
2071 (void)Create(owner
, wxID_ANY
, m_startValue
,
2072 wxPoint(rectLabel
.x
-4,rectLabel
.y
-4),
2073 wxSize(rectLabel
.width
+11,rectLabel
.height
+8));
2076 void wxListTextCtrl::Finish()
2080 wxPendingDelete
.Append(this);
2084 m_owner
->SetFocusIgnoringChildren();
2088 bool wxListTextCtrl::AcceptChanges()
2090 const wxString value
= GetValue();
2092 if ( value
== m_startValue
)
2094 // nothing changed, always accept
2098 if ( !m_owner
->OnRenameAccept(m_itemEdited
, value
) )
2100 // vetoed by the user
2104 // accepted, do rename the item
2105 m_owner
->SetItemText(m_itemEdited
, value
);
2110 void wxListTextCtrl::OnChar( wxKeyEvent
&event
)
2112 switch ( event
.m_keyCode
)
2115 m_aboutToFinish
= true;
2116 // Notify the owner about the changes
2118 // Even if vetoed, close the control (consistent with MSW)
2124 m_owner
->OnRenameCancelled( m_itemEdited
);
2132 void wxListTextCtrl::OnKeyUp( wxKeyEvent
&event
)
2140 // auto-grow the textctrl:
2141 wxSize parentSize
= m_owner
->GetSize();
2142 wxPoint myPos
= GetPosition();
2143 wxSize mySize
= GetSize();
2145 GetTextExtent(GetValue() + _T("MM"), &sx
, &sy
);
2146 if (myPos
.x
+ sx
> parentSize
.x
)
2147 sx
= parentSize
.x
- myPos
.x
;
2150 SetSize(sx
, wxDefaultCoord
);
2155 void wxListTextCtrl::OnKillFocus( wxFocusEvent
&event
)
2157 if ( !m_finished
&& !m_aboutToFinish
)
2159 // We must finish regardless of success, otherwise we'll get
2163 if ( !AcceptChanges() )
2164 m_owner
->OnRenameCancelled( m_itemEdited
);
2167 // We must let the native text control handle focus, too, otherwise
2168 // it could have problems with the cursor (e.g., in wxGTK).
2172 //-----------------------------------------------------------------------------
2174 //-----------------------------------------------------------------------------
2176 IMPLEMENT_DYNAMIC_CLASS(wxListMainWindow
,wxScrolledWindow
)
2178 BEGIN_EVENT_TABLE(wxListMainWindow
,wxScrolledWindow
)
2179 EVT_PAINT (wxListMainWindow::OnPaint
)
2180 EVT_MOUSE_EVENTS (wxListMainWindow::OnMouse
)
2181 EVT_CHAR (wxListMainWindow::OnChar
)
2182 EVT_KEY_DOWN (wxListMainWindow::OnKeyDown
)
2183 EVT_SET_FOCUS (wxListMainWindow::OnSetFocus
)
2184 EVT_KILL_FOCUS (wxListMainWindow::OnKillFocus
)
2185 EVT_SCROLLWIN (wxListMainWindow::OnScroll
)
2188 void wxListMainWindow::Init()
2193 m_lineTo
= (size_t)-1;
2199 m_small_image_list
= (wxImageListType
*) NULL
;
2200 m_normal_image_list
= (wxImageListType
*) NULL
;
2202 m_small_spacing
= 30;
2203 m_normal_spacing
= 40;
2207 m_isCreated
= false;
2209 m_lastOnSame
= false;
2210 m_renameTimer
= new wxListRenameTimer( this );
2214 m_lineSelectSingleOnUp
=
2215 m_lineBeforeLastClicked
= (size_t)-1;
2220 wxListMainWindow::wxListMainWindow()
2225 m_highlightUnfocusedBrush
= (wxBrush
*) NULL
;
2228 wxListMainWindow::wxListMainWindow( wxWindow
*parent
,
2233 const wxString
&name
)
2234 : wxScrolledWindow( parent
, id
, pos
, size
,
2235 style
| wxHSCROLL
| wxVSCROLL
, name
)
2239 m_highlightBrush
= new wxBrush
2241 wxSystemSettings::GetColour
2243 wxSYS_COLOUR_HIGHLIGHT
2248 m_highlightUnfocusedBrush
= new wxBrush
2250 wxSystemSettings::GetColour
2252 wxSYS_COLOUR_BTNSHADOW
2257 SetScrollbars( 0, 0, 0, 0, 0, 0 );
2259 wxVisualAttributes attr
= wxGenericListCtrl::GetClassDefaultAttributes();
2260 SetOwnForegroundColour( attr
.colFg
);
2261 SetOwnBackgroundColour( attr
.colBg
);
2263 SetOwnFont( attr
.font
);
2266 wxListMainWindow::~wxListMainWindow()
2269 WX_CLEAR_LIST(wxListHeaderDataList
, m_columns
);
2270 WX_CLEAR_ARRAY(m_aColWidths
);
2272 delete m_highlightBrush
;
2273 delete m_highlightUnfocusedBrush
;
2275 delete m_renameTimer
;
2278 void wxListMainWindow::CacheLineData(size_t line
)
2280 wxGenericListCtrl
*listctrl
= GetListCtrl();
2282 wxListLineData
*ld
= GetDummyLine();
2284 size_t countCol
= GetColumnCount();
2285 for ( size_t col
= 0; col
< countCol
; col
++ )
2287 ld
->SetText(col
, listctrl
->OnGetItemText(line
, col
));
2290 ld
->SetImage(listctrl
->OnGetItemImage(line
));
2291 ld
->SetAttr(listctrl
->OnGetItemAttr(line
));
2294 wxListLineData
*wxListMainWindow::GetDummyLine() const
2296 wxASSERT_MSG( !IsEmpty(), _T("invalid line index") );
2298 wxASSERT_MSG( IsVirtual(), _T("GetDummyLine() shouldn't be called") );
2300 wxListMainWindow
*self
= wxConstCast(this, wxListMainWindow
);
2302 // we need to recreate the dummy line if the number of columns in the
2303 // control changed as it would have the incorrect number of fields
2305 if ( !m_lines
.IsEmpty() &&
2306 m_lines
[0].m_items
.GetCount() != (size_t)GetColumnCount() )
2308 self
->m_lines
.Clear();
2311 if ( m_lines
.IsEmpty() )
2313 wxListLineData
*line
= new wxListLineData(self
);
2314 self
->m_lines
.Add(line
);
2316 // don't waste extra memory -- there never going to be anything
2317 // else/more in this array
2318 self
->m_lines
.Shrink();
2324 // ----------------------------------------------------------------------------
2325 // line geometry (report mode only)
2326 // ----------------------------------------------------------------------------
2328 wxCoord
wxListMainWindow::GetLineHeight() const
2330 // we cache the line height as calling GetTextExtent() is slow
2331 if ( !m_lineHeight
)
2333 wxListMainWindow
*self
= wxConstCast(this, wxListMainWindow
);
2335 wxClientDC
dc( self
);
2336 dc
.SetFont( GetFont() );
2339 dc
.GetTextExtent(_T("H"), NULL
, &y
);
2341 if ( m_small_image_list
&& m_small_image_list
->GetImageCount() )
2345 m_small_image_list
->GetSize(0, iw
, ih
);
2350 self
->m_lineHeight
= y
+ LINE_SPACING
;
2353 return m_lineHeight
;
2356 wxCoord
wxListMainWindow::GetLineY(size_t line
) const
2358 wxASSERT_MSG( InReportView(), _T("only works in report mode") );
2360 return LINE_SPACING
+ line
*GetLineHeight();
2363 wxRect
wxListMainWindow::GetLineRect(size_t line
) const
2365 if ( !InReportView() )
2366 return GetLine(line
)->m_gi
->m_rectAll
;
2369 rect
.x
= HEADER_OFFSET_X
;
2370 rect
.y
= GetLineY(line
);
2371 rect
.width
= GetHeaderWidth();
2372 rect
.height
= GetLineHeight();
2377 wxRect
wxListMainWindow::GetLineLabelRect(size_t line
) const
2379 if ( !InReportView() )
2380 return GetLine(line
)->m_gi
->m_rectLabel
;
2383 rect
.x
= HEADER_OFFSET_X
;
2384 rect
.y
= GetLineY(line
);
2385 rect
.width
= GetColumnWidth(0);
2386 rect
.height
= GetLineHeight();
2391 wxRect
wxListMainWindow::GetLineIconRect(size_t line
) const
2393 if ( !InReportView() )
2394 return GetLine(line
)->m_gi
->m_rectIcon
;
2396 wxListLineData
*ld
= GetLine(line
);
2397 wxASSERT_MSG( ld
->HasImage(), _T("should have an image") );
2400 rect
.x
= HEADER_OFFSET_X
;
2401 rect
.y
= GetLineY(line
);
2402 GetImageSize(ld
->GetImage(), rect
.width
, rect
.height
);
2407 wxRect
wxListMainWindow::GetLineHighlightRect(size_t line
) const
2409 return InReportView() ? GetLineRect(line
)
2410 : GetLine(line
)->m_gi
->m_rectHighlight
;
2413 long wxListMainWindow::HitTestLine(size_t line
, int x
, int y
) const
2415 wxASSERT_MSG( line
< GetItemCount(), _T("invalid line in HitTestLine") );
2417 wxListLineData
*ld
= GetLine(line
);
2419 if ( ld
->HasImage() && GetLineIconRect(line
).Inside(x
, y
) )
2420 return wxLIST_HITTEST_ONITEMICON
;
2422 // VS: Testing for "ld->HasText() || InReportView()" instead of
2423 // "ld->HasText()" is needed to make empty lines in report view
2425 if ( ld
->HasText() || InReportView() )
2427 wxRect rect
= InReportView() ? GetLineRect(line
)
2428 : GetLineLabelRect(line
);
2430 if ( rect
.Inside(x
, y
) )
2431 return wxLIST_HITTEST_ONITEMLABEL
;
2437 // ----------------------------------------------------------------------------
2438 // highlight (selection) handling
2439 // ----------------------------------------------------------------------------
2441 bool wxListMainWindow::IsHighlighted(size_t line
) const
2445 return m_selStore
.IsSelected(line
);
2449 wxListLineData
*ld
= GetLine(line
);
2450 wxCHECK_MSG( ld
, false, _T("invalid index in IsHighlighted") );
2452 return ld
->IsHighlighted();
2456 void wxListMainWindow::HighlightLines( size_t lineFrom
,
2462 wxArrayInt linesChanged
;
2463 if ( !m_selStore
.SelectRange(lineFrom
, lineTo
, highlight
,
2466 // meny items changed state, refresh everything
2467 RefreshLines(lineFrom
, lineTo
);
2469 else // only a few items changed state, refresh only them
2471 size_t count
= linesChanged
.GetCount();
2472 for ( size_t n
= 0; n
< count
; n
++ )
2474 RefreshLine(linesChanged
[n
]);
2478 else // iterate over all items in non report view
2480 for ( size_t line
= lineFrom
; line
<= lineTo
; line
++ )
2482 if ( HighlightLine(line
, highlight
) )
2490 bool wxListMainWindow::HighlightLine( size_t line
, bool highlight
)
2496 changed
= m_selStore
.SelectItem(line
, highlight
);
2500 wxListLineData
*ld
= GetLine(line
);
2501 wxCHECK_MSG( ld
, false, _T("invalid index in HighlightLine") );
2503 changed
= ld
->Highlight(highlight
);
2508 SendNotify( line
, highlight
? wxEVT_COMMAND_LIST_ITEM_SELECTED
2509 : wxEVT_COMMAND_LIST_ITEM_DESELECTED
);
2515 void wxListMainWindow::RefreshLine( size_t line
)
2517 if ( InReportView() )
2519 size_t visibleFrom
, visibleTo
;
2520 GetVisibleLinesRange(&visibleFrom
, &visibleTo
);
2522 if ( line
< visibleFrom
|| line
> visibleTo
)
2526 wxRect rect
= GetLineRect(line
);
2528 CalcScrolledPosition( rect
.x
, rect
.y
, &rect
.x
, &rect
.y
);
2529 RefreshRect( rect
);
2532 void wxListMainWindow::RefreshLines( size_t lineFrom
, size_t lineTo
)
2534 // we suppose that they are ordered by caller
2535 wxASSERT_MSG( lineFrom
<= lineTo
, _T("indices in disorder") );
2537 wxASSERT_MSG( lineTo
< GetItemCount(), _T("invalid line range") );
2539 if ( InReportView() )
2541 size_t visibleFrom
, visibleTo
;
2542 GetVisibleLinesRange(&visibleFrom
, &visibleTo
);
2544 if ( lineFrom
< visibleFrom
)
2545 lineFrom
= visibleFrom
;
2546 if ( lineTo
> visibleTo
)
2551 rect
.y
= GetLineY(lineFrom
);
2552 rect
.width
= GetClientSize().x
;
2553 rect
.height
= GetLineY(lineTo
) - rect
.y
+ GetLineHeight();
2555 CalcScrolledPosition( rect
.x
, rect
.y
, &rect
.x
, &rect
.y
);
2556 RefreshRect( rect
);
2560 // TODO: this should be optimized...
2561 for ( size_t line
= lineFrom
; line
<= lineTo
; line
++ )
2568 void wxListMainWindow::RefreshAfter( size_t lineFrom
)
2570 if ( InReportView() )
2572 size_t visibleFrom
, visibleTo
;
2573 GetVisibleLinesRange(&visibleFrom
, &visibleTo
);
2575 if ( lineFrom
< visibleFrom
)
2576 lineFrom
= visibleFrom
;
2577 else if ( lineFrom
> visibleTo
)
2582 rect
.y
= GetLineY(lineFrom
);
2583 CalcScrolledPosition( rect
.x
, rect
.y
, &rect
.x
, &rect
.y
);
2585 wxSize size
= GetClientSize();
2586 rect
.width
= size
.x
;
2587 // refresh till the bottom of the window
2588 rect
.height
= size
.y
- rect
.y
;
2590 RefreshRect( rect
);
2594 // TODO: how to do it more efficiently?
2599 void wxListMainWindow::RefreshSelected()
2605 if ( InReportView() )
2607 GetVisibleLinesRange(&from
, &to
);
2612 to
= GetItemCount() - 1;
2615 if ( HasCurrent() && m_current
>= from
&& m_current
<= to
)
2617 RefreshLine(m_current
);
2620 for ( size_t line
= from
; line
<= to
; line
++ )
2622 // NB: the test works as expected even if m_current == -1
2623 if ( line
!= m_current
&& IsHighlighted(line
) )
2630 void wxListMainWindow::Freeze()
2635 void wxListMainWindow::Thaw()
2637 wxCHECK_RET( m_freezeCount
> 0, _T("thawing unfrozen list control?") );
2639 if ( !--m_freezeCount
)
2645 void wxListMainWindow::OnPaint( wxPaintEvent
&WXUNUSED(event
) )
2647 // Note: a wxPaintDC must be constructed even if no drawing is
2648 // done (a Windows requirement).
2649 wxPaintDC
dc( this );
2651 if ( IsEmpty() || m_freezeCount
)
2653 // nothing to draw or not the moment to draw it
2659 // delay the repainting until we calculate all the items positions
2666 CalcScrolledPosition( 0, 0, &dev_x
, &dev_y
);
2670 dc
.SetFont( GetFont() );
2672 if ( InReportView() )
2674 int lineHeight
= GetLineHeight();
2676 size_t visibleFrom
, visibleTo
;
2677 GetVisibleLinesRange(&visibleFrom
, &visibleTo
);
2680 wxCoord xOrig
, yOrig
;
2681 CalcUnscrolledPosition(0, 0, &xOrig
, &yOrig
);
2683 // tell the caller cache to cache the data
2686 wxListEvent
evCache(wxEVT_COMMAND_LIST_CACHE_HINT
,
2687 GetParent()->GetId());
2688 evCache
.SetEventObject( GetParent() );
2689 evCache
.m_oldItemIndex
= visibleFrom
;
2690 evCache
.m_itemIndex
= visibleTo
;
2691 GetParent()->GetEventHandler()->ProcessEvent( evCache
);
2694 for ( size_t line
= visibleFrom
; line
<= visibleTo
; line
++ )
2696 rectLine
= GetLineRect(line
);
2698 if ( !IsExposed(rectLine
.x
- xOrig
, rectLine
.y
- yOrig
,
2699 rectLine
.width
, rectLine
.height
) )
2701 // don't redraw unaffected lines to avoid flicker
2705 GetLine(line
)->DrawInReportMode( &dc
,
2707 GetLineHighlightRect(line
),
2708 IsHighlighted(line
) );
2711 if ( HasFlag(wxLC_HRULES
) )
2713 wxPen
pen(GetRuleColour(), 1, wxSOLID
);
2714 wxSize clientSize
= GetClientSize();
2716 // Don't draw the first one
2717 for ( size_t i
= visibleFrom
+1; i
<= visibleTo
; i
++ )
2720 dc
.SetBrush( *wxTRANSPARENT_BRUSH
);
2721 dc
.DrawLine(0 - dev_x
, i
*lineHeight
,
2722 clientSize
.x
- dev_x
, i
*lineHeight
);
2725 // Draw last horizontal rule
2726 if ( visibleTo
== GetItemCount() - 1 )
2729 dc
.SetBrush( *wxTRANSPARENT_BRUSH
);
2730 dc
.DrawLine(0 - dev_x
, (m_lineTo
+1)*lineHeight
,
2731 clientSize
.x
- dev_x
, (m_lineTo
+1)*lineHeight
);
2735 // Draw vertical rules if required
2736 if ( HasFlag(wxLC_VRULES
) && !IsEmpty() )
2738 wxPen
pen(GetRuleColour(), 1, wxSOLID
);
2740 wxRect firstItemRect
;
2741 wxRect lastItemRect
;
2742 GetItemRect(visibleFrom
, firstItemRect
);
2743 GetItemRect(visibleTo
, lastItemRect
);
2744 int x
= firstItemRect
.GetX();
2746 dc
.SetBrush(* wxTRANSPARENT_BRUSH
);
2747 for (int col
= 0; col
< GetColumnCount(); col
++)
2749 int colWidth
= GetColumnWidth(col
);
2751 dc
.DrawLine(x
- dev_x
- 2, firstItemRect
.GetY() - 1 - dev_y
,
2752 x
- dev_x
- 2, lastItemRect
.GetBottom() + 1 - dev_y
);
2758 size_t count
= GetItemCount();
2759 for ( size_t i
= 0; i
< count
; i
++ )
2761 GetLine(i
)->Draw( &dc
);
2766 // Don't draw rect outline under Mac at all.
2771 dc
.SetPen( *wxBLACK_PEN
);
2772 dc
.SetBrush( *wxTRANSPARENT_BRUSH
);
2773 dc
.DrawRectangle( GetLineHighlightRect(m_current
) );
2781 void wxListMainWindow::HighlightAll( bool on
)
2783 if ( IsSingleSel() )
2785 wxASSERT_MSG( !on
, _T("can't do this in a single sel control") );
2787 // we just have one item to turn off
2788 if ( HasCurrent() && IsHighlighted(m_current
) )
2790 HighlightLine(m_current
, false);
2791 RefreshLine(m_current
);
2796 HighlightLines(0, GetItemCount() - 1, on
);
2800 void wxListMainWindow::SendNotify( size_t line
,
2801 wxEventType command
,
2804 wxListEvent
le( command
, GetParent()->GetId() );
2805 le
.SetEventObject( GetParent() );
2806 le
.m_itemIndex
= line
;
2808 // set only for events which have position
2809 if ( point
!= wxDefaultPosition
)
2810 le
.m_pointDrag
= point
;
2812 // don't try to get the line info for virtual list controls: the main
2813 // program has it anyhow and if we did it would result in accessing all
2814 // the lines, even those which are not visible now and this is precisely
2815 // what we're trying to avoid
2816 if ( !IsVirtual() && (command
!= wxEVT_COMMAND_LIST_DELETE_ITEM
) )
2818 if ( line
!= (size_t)-1 )
2820 GetLine(line
)->GetItem( 0, le
.m_item
);
2822 //else: this happens for wxEVT_COMMAND_LIST_ITEM_FOCUSED event
2824 //else: there may be no more such item
2826 GetParent()->GetEventHandler()->ProcessEvent( le
);
2829 void wxListMainWindow::ChangeCurrent(size_t current
)
2831 m_current
= current
;
2833 SendNotify(current
, wxEVT_COMMAND_LIST_ITEM_FOCUSED
);
2836 void wxListMainWindow::EditLabel( long item
)
2838 wxCHECK_RET( (item
>= 0) && ((size_t)item
< GetItemCount()),
2839 wxT("wrong index in wxGenericListCtrl::EditLabel()") );
2841 size_t itemEdit
= (size_t)item
;
2843 wxListEvent
le( wxEVT_COMMAND_LIST_BEGIN_LABEL_EDIT
, GetParent()->GetId() );
2844 le
.SetEventObject( GetParent() );
2845 le
.m_itemIndex
= item
;
2846 wxListLineData
*data
= GetLine(itemEdit
);
2847 wxCHECK_RET( data
, _T("invalid index in EditLabel()") );
2848 data
->GetItem( 0, le
.m_item
);
2849 if ( GetParent()->GetEventHandler()->ProcessEvent( le
) && !le
.IsAllowed() )
2851 // vetoed by user code
2855 // We have to call this here because the label in question might just have
2856 // been added and no screen update taken place.
2860 wxListTextCtrl
*text
= new wxListTextCtrl(this, itemEdit
);
2865 void wxListMainWindow::OnRenameTimer()
2867 wxCHECK_RET( HasCurrent(), wxT("unexpected rename timer") );
2869 EditLabel( m_current
);
2872 bool wxListMainWindow::OnRenameAccept(size_t itemEdit
, const wxString
& value
)
2874 wxListEvent
le( wxEVT_COMMAND_LIST_END_LABEL_EDIT
, GetParent()->GetId() );
2875 le
.SetEventObject( GetParent() );
2876 le
.m_itemIndex
= itemEdit
;
2878 wxListLineData
*data
= GetLine(itemEdit
);
2879 wxCHECK_MSG( data
, false, _T("invalid index in OnRenameAccept()") );
2881 data
->GetItem( 0, le
.m_item
);
2882 le
.m_item
.m_text
= value
;
2883 return !GetParent()->GetEventHandler()->ProcessEvent( le
) ||
2887 void wxListMainWindow::OnRenameCancelled(size_t itemEdit
)
2889 // let owner know that the edit was cancelled
2890 wxListEvent
le( wxEVT_COMMAND_LIST_END_LABEL_EDIT
, GetParent()->GetId() );
2892 le
.SetEditCanceled(true);
2894 le
.SetEventObject( GetParent() );
2895 le
.m_itemIndex
= itemEdit
;
2897 wxListLineData
*data
= GetLine(itemEdit
);
2898 wxCHECK_RET( data
, _T("invalid index in OnRenameCancelled()") );
2900 data
->GetItem( 0, le
.m_item
);
2902 GetEventHandler()->ProcessEvent( le
);
2905 void wxListMainWindow::OnMouse( wxMouseEvent
&event
)
2907 event
.SetEventObject( GetParent() );
2908 if ( GetParent()->GetEventHandler()->ProcessEvent( event
) )
2911 if (event
.GetEventType() == wxEVT_MOUSEWHEEL
)
2913 // let the base handle mouse wheel events.
2918 if ( !HasCurrent() || IsEmpty() )
2924 if ( !(event
.Dragging() || event
.ButtonDown() || event
.LeftUp() ||
2925 event
.ButtonDClick()) )
2928 int x
= event
.GetX();
2929 int y
= event
.GetY();
2930 CalcUnscrolledPosition( x
, y
, &x
, &y
);
2932 // where did we hit it (if we did)?
2935 size_t count
= GetItemCount(),
2938 if ( InReportView() )
2940 current
= y
/ GetLineHeight();
2941 if ( current
< count
)
2942 hitResult
= HitTestLine(current
, x
, y
);
2946 // TODO: optimize it too! this is less simple than for report view but
2947 // enumerating all items is still not a way to do it!!
2948 for ( current
= 0; current
< count
; current
++ )
2950 hitResult
= HitTestLine(current
, x
, y
);
2956 if (event
.Dragging())
2958 if (m_dragCount
== 0)
2960 // we have to report the raw, physical coords as we want to be
2961 // able to call HitTest(event.m_pointDrag) from the user code to
2962 // get the item being dragged
2963 m_dragStart
= event
.GetPosition();
2968 if (m_dragCount
!= 3)
2971 int command
= event
.RightIsDown() ? wxEVT_COMMAND_LIST_BEGIN_RDRAG
2972 : wxEVT_COMMAND_LIST_BEGIN_DRAG
;
2974 wxListEvent
le( command
, GetParent()->GetId() );
2975 le
.SetEventObject( GetParent() );
2976 le
.m_itemIndex
= m_lineLastClicked
;
2977 le
.m_pointDrag
= m_dragStart
;
2978 GetParent()->GetEventHandler()->ProcessEvent( le
);
2989 // outside of any item
2993 bool forceClick
= false;
2994 if (event
.ButtonDClick())
2996 m_renameTimer
->Stop();
2997 m_lastOnSame
= false;
2999 if ( current
== m_lineLastClicked
)
3001 SendNotify( current
, wxEVT_COMMAND_LIST_ITEM_ACTIVATED
);
3007 // The first click was on another item, so don't interpret this as
3008 // a double click, but as a simple click instead
3015 if(m_lineSelectSingleOnUp
!= (size_t) -1)
3017 // select single line
3018 HighlightAll( false );
3019 ReverseHighlight(m_lineSelectSingleOnUp
);
3023 if ((current
== m_current
) &&
3024 (hitResult
== wxLIST_HITTEST_ONITEMLABEL
) &&
3025 HasFlag(wxLC_EDIT_LABELS
) )
3027 m_renameTimer
->Start( 100, true );
3030 m_lastOnSame
= false;
3031 m_lineSelectSingleOnUp
= (size_t) -1;
3035 // This is necessary, because after a DnD operation in
3036 // from and to ourself, the up event is swallowed by the
3037 // DnD code. So on next non-up event (which means here and
3038 // now) m_lineSelectSingleOnUp should be reset.
3039 m_lineSelectSingleOnUp
= (size_t) -1;
3041 if (event
.RightDown())
3043 m_lineBeforeLastClicked
= m_lineLastClicked
;
3044 m_lineLastClicked
= current
;
3045 // If the item is already selected, do not update the selection.
3046 // Multi-selections should not be cleared if a selected item is clicked.
3047 if (!IsHighlighted(current
))
3049 HighlightAll(false);
3050 ChangeCurrent(current
);
3051 ReverseHighlight(m_current
);
3053 SendNotify( current
, wxEVT_COMMAND_LIST_ITEM_RIGHT_CLICK
,
3054 event
.GetPosition() );
3055 // Allow generation of context menu event
3058 else if (event
.MiddleDown())
3060 SendNotify( current
, wxEVT_COMMAND_LIST_ITEM_MIDDLE_CLICK
);
3062 else if ( event
.LeftDown() || forceClick
)
3064 m_lineBeforeLastClicked
= m_lineLastClicked
;
3065 m_lineLastClicked
= current
;
3067 size_t oldCurrent
= m_current
;
3068 bool oldWasSelected
= IsHighlighted(m_current
);
3070 bool cmdModifierDown
= event
.CmdDown();
3071 if ( IsSingleSel() || !(cmdModifierDown
|| event
.ShiftDown()) )
3073 if( IsSingleSel() || !IsHighlighted(current
) )
3075 HighlightAll( false );
3077 ChangeCurrent(current
);
3079 ReverseHighlight(m_current
);
3081 else // multi sel & current is highlighted & no mod keys
3083 m_lineSelectSingleOnUp
= current
;
3084 ChangeCurrent(current
); // change focus
3087 else // multi sel & either ctrl or shift is down
3089 if (cmdModifierDown
)
3091 ChangeCurrent(current
);
3093 ReverseHighlight(m_current
);
3095 else if (event
.ShiftDown())
3097 ChangeCurrent(current
);
3099 size_t lineFrom
= oldCurrent
,
3102 if ( lineTo
< lineFrom
)
3105 lineFrom
= m_current
;
3108 HighlightLines(lineFrom
, lineTo
);
3110 else // !ctrl, !shift
3112 // test in the enclosing if should make it impossible
3113 wxFAIL_MSG( _T("how did we get here?") );
3117 if (m_current
!= oldCurrent
)
3119 RefreshLine( oldCurrent
);
3122 // forceClick is only set if the previous click was on another item
3123 m_lastOnSame
= !forceClick
&& (m_current
== oldCurrent
) && oldWasSelected
;
3127 void wxListMainWindow::MoveToItem(size_t item
)
3129 if ( item
== (size_t)-1 )
3132 wxRect rect
= GetLineRect(item
);
3134 int client_w
, client_h
;
3135 GetClientSize( &client_w
, &client_h
);
3137 const int hLine
= GetLineHeight();
3139 int view_x
= SCROLL_UNIT_X
*GetScrollPos( wxHORIZONTAL
);
3140 int view_y
= hLine
*GetScrollPos( wxVERTICAL
);
3142 if ( InReportView() )
3144 // the next we need the range of lines shown it might be different, so
3146 ResetVisibleLinesRange();
3148 if (rect
.y
< view_y
)
3149 Scroll( -1, rect
.y
/hLine
);
3150 if (rect
.y
+rect
.height
+5 > view_y
+client_h
)
3151 Scroll( -1, (rect
.y
+rect
.height
-client_h
+hLine
)/hLine
);
3155 if (rect
.x
-view_x
< 5)
3156 Scroll( (rect
.x
-5)/SCROLL_UNIT_X
, -1 );
3157 if (rect
.x
+rect
.width
-5 > view_x
+client_w
)
3158 Scroll( (rect
.x
+rect
.width
-client_w
+SCROLL_UNIT_X
)/SCROLL_UNIT_X
, -1 );
3162 // ----------------------------------------------------------------------------
3163 // keyboard handling
3164 // ----------------------------------------------------------------------------
3166 void wxListMainWindow::OnArrowChar(size_t newCurrent
, const wxKeyEvent
& event
)
3168 wxCHECK_RET( newCurrent
< (size_t)GetItemCount(),
3169 _T("invalid item index in OnArrowChar()") );
3171 size_t oldCurrent
= m_current
;
3173 // in single selection we just ignore Shift as we can't select several
3175 if ( event
.ShiftDown() && !IsSingleSel() )
3177 ChangeCurrent(newCurrent
);
3179 // refresh the old focus to remove it
3180 RefreshLine( oldCurrent
);
3182 // select all the items between the old and the new one
3183 if ( oldCurrent
> newCurrent
)
3185 newCurrent
= oldCurrent
;
3186 oldCurrent
= m_current
;
3189 HighlightLines(oldCurrent
, newCurrent
);
3193 // all previously selected items are unselected unless ctrl is held
3194 if ( !event
.ControlDown() )
3195 HighlightAll(false);
3197 ChangeCurrent(newCurrent
);
3199 // refresh the old focus to remove it
3200 RefreshLine( oldCurrent
);
3202 if ( !event
.ControlDown() )
3204 HighlightLine( m_current
, true );
3208 RefreshLine( m_current
);
3213 void wxListMainWindow::OnKeyDown( wxKeyEvent
&event
)
3215 wxWindow
*parent
= GetParent();
3217 /* we propagate the key event up */
3218 wxKeyEvent
ke( wxEVT_KEY_DOWN
);
3219 ke
.m_shiftDown
= event
.m_shiftDown
;
3220 ke
.m_controlDown
= event
.m_controlDown
;
3221 ke
.m_altDown
= event
.m_altDown
;
3222 ke
.m_metaDown
= event
.m_metaDown
;
3223 ke
.m_keyCode
= event
.m_keyCode
;
3226 ke
.SetEventObject( parent
);
3227 if (parent
->GetEventHandler()->ProcessEvent( ke
)) return;
3232 void wxListMainWindow::OnChar( wxKeyEvent
&event
)
3234 wxWindow
*parent
= GetParent();
3236 /* we send a list_key event up */
3239 wxListEvent
le( wxEVT_COMMAND_LIST_KEY_DOWN
, GetParent()->GetId() );
3240 le
.m_itemIndex
= m_current
;
3241 GetLine(m_current
)->GetItem( 0, le
.m_item
);
3242 le
.m_code
= event
.GetKeyCode();
3243 le
.SetEventObject( parent
);
3244 parent
->GetEventHandler()->ProcessEvent( le
);
3247 /* we propagate the char event up */
3248 wxKeyEvent
ke( wxEVT_CHAR
);
3249 ke
.m_shiftDown
= event
.m_shiftDown
;
3250 ke
.m_controlDown
= event
.m_controlDown
;
3251 ke
.m_altDown
= event
.m_altDown
;
3252 ke
.m_metaDown
= event
.m_metaDown
;
3253 ke
.m_keyCode
= event
.m_keyCode
;
3256 ke
.SetEventObject( parent
);
3257 if (parent
->GetEventHandler()->ProcessEvent( ke
)) return;
3259 if (event
.GetKeyCode() == WXK_TAB
)
3261 wxNavigationKeyEvent nevent
;
3262 nevent
.SetWindowChange( event
.ControlDown() );
3263 nevent
.SetDirection( !event
.ShiftDown() );
3264 nevent
.SetEventObject( GetParent()->GetParent() );
3265 nevent
.SetCurrentFocus( m_parent
);
3266 if (GetParent()->GetParent()->GetEventHandler()->ProcessEvent( nevent
))
3270 /* no item -> nothing to do */
3277 switch (event
.GetKeyCode())
3280 if ( m_current
> 0 )
3281 OnArrowChar( m_current
- 1, event
);
3285 if ( m_current
< (size_t)GetItemCount() - 1 )
3286 OnArrowChar( m_current
+ 1, event
);
3291 OnArrowChar( GetItemCount() - 1, event
);
3296 OnArrowChar( 0, event
);
3301 int steps
= InReportView() ? m_linesPerPage
- 1 : m_current
% m_linesPerPage
;
3303 int index
= m_current
- steps
;
3307 OnArrowChar( index
, event
);
3313 int steps
= InReportView()
3314 ? m_linesPerPage
- 1
3315 : m_linesPerPage
- (m_current
% m_linesPerPage
) - 1;
3317 size_t index
= m_current
+ steps
;
3318 size_t count
= GetItemCount();
3319 if ( index
>= count
)
3322 OnArrowChar( index
, event
);
3327 if ( !InReportView() )
3329 int index
= m_current
- m_linesPerPage
;
3333 OnArrowChar( index
, event
);
3338 if ( !InReportView() )
3340 size_t index
= m_current
+ m_linesPerPage
;
3342 size_t count
= GetItemCount();
3343 if ( index
>= count
)
3346 OnArrowChar( index
, event
);
3351 if ( IsSingleSel() )
3353 SendNotify( m_current
, wxEVT_COMMAND_LIST_ITEM_ACTIVATED
);
3355 if ( IsHighlighted(m_current
) )
3357 // don't unselect the item in single selection mode
3360 //else: select it in ReverseHighlight() below if unselected
3363 ReverseHighlight(m_current
);
3368 SendNotify( m_current
, wxEVT_COMMAND_LIST_ITEM_ACTIVATED
);
3376 // ----------------------------------------------------------------------------
3378 // ----------------------------------------------------------------------------
3380 void wxListMainWindow::OnSetFocus( wxFocusEvent
&WXUNUSED(event
) )
3384 wxFocusEvent
event( wxEVT_SET_FOCUS
, GetParent()->GetId() );
3385 event
.SetEventObject( GetParent() );
3386 if ( GetParent()->GetEventHandler()->ProcessEvent( event
) )
3390 // wxGTK sends us EVT_SET_FOCUS events even if we had never got
3391 // EVT_KILL_FOCUS before which means that we finish by redrawing the items
3392 // which are already drawn correctly resulting in horrible flicker - avoid
3402 void wxListMainWindow::OnKillFocus( wxFocusEvent
&WXUNUSED(event
) )
3406 wxFocusEvent
event( wxEVT_KILL_FOCUS
, GetParent()->GetId() );
3407 event
.SetEventObject( GetParent() );
3408 if ( GetParent()->GetEventHandler()->ProcessEvent( event
) )
3415 void wxListMainWindow::DrawImage( int index
, wxDC
*dc
, int x
, int y
)
3417 if ( HasFlag(wxLC_ICON
) && (m_normal_image_list
))
3419 m_normal_image_list
->Draw( index
, *dc
, x
, y
, wxIMAGELIST_DRAW_TRANSPARENT
);
3421 else if ( HasFlag(wxLC_SMALL_ICON
) && (m_small_image_list
))
3423 m_small_image_list
->Draw( index
, *dc
, x
, y
, wxIMAGELIST_DRAW_TRANSPARENT
);
3425 else if ( HasFlag(wxLC_LIST
) && (m_small_image_list
))
3427 m_small_image_list
->Draw( index
, *dc
, x
, y
, wxIMAGELIST_DRAW_TRANSPARENT
);
3429 else if ( InReportView() && (m_small_image_list
))
3431 m_small_image_list
->Draw( index
, *dc
, x
, y
, wxIMAGELIST_DRAW_TRANSPARENT
);
3435 void wxListMainWindow::GetImageSize( int index
, int &width
, int &height
) const
3437 if ( HasFlag(wxLC_ICON
) && m_normal_image_list
)
3439 m_normal_image_list
->GetSize( index
, width
, height
);
3441 else if ( HasFlag(wxLC_SMALL_ICON
) && m_small_image_list
)
3443 m_small_image_list
->GetSize( index
, width
, height
);
3445 else if ( HasFlag(wxLC_LIST
) && m_small_image_list
)
3447 m_small_image_list
->GetSize( index
, width
, height
);
3449 else if ( InReportView() && m_small_image_list
)
3451 m_small_image_list
->GetSize( index
, width
, height
);
3460 int wxListMainWindow::GetTextLength( const wxString
&s
) const
3462 wxClientDC
dc( wxConstCast(this, wxListMainWindow
) );
3463 dc
.SetFont( GetFont() );
3466 dc
.GetTextExtent( s
, &lw
, NULL
);
3468 return lw
+ AUTOSIZE_COL_MARGIN
;
3471 void wxListMainWindow::SetImageList( wxImageListType
*imageList
, int which
)
3475 // calc the spacing from the icon size
3478 if ((imageList
) && (imageList
->GetImageCount()) )
3480 imageList
->GetSize(0, width
, height
);
3483 if (which
== wxIMAGE_LIST_NORMAL
)
3485 m_normal_image_list
= imageList
;
3486 m_normal_spacing
= width
+ 8;
3489 if (which
== wxIMAGE_LIST_SMALL
)
3491 m_small_image_list
= imageList
;
3492 m_small_spacing
= width
+ 14;
3493 m_lineHeight
= 0; // ensure that the line height will be recalc'd
3497 void wxListMainWindow::SetItemSpacing( int spacing
, bool isSmall
)
3502 m_small_spacing
= spacing
;
3506 m_normal_spacing
= spacing
;
3510 int wxListMainWindow::GetItemSpacing( bool isSmall
)
3512 return isSmall
? m_small_spacing
: m_normal_spacing
;
3515 // ----------------------------------------------------------------------------
3517 // ----------------------------------------------------------------------------
3519 void wxListMainWindow::SetColumn( int col
, wxListItem
&item
)
3521 wxListHeaderDataList::compatibility_iterator node
= m_columns
.Item( col
);
3523 wxCHECK_RET( node
, _T("invalid column index in SetColumn") );
3525 if ( item
.m_width
== wxLIST_AUTOSIZE_USEHEADER
)
3526 item
.m_width
= GetTextLength( item
.m_text
);
3528 wxListHeaderData
*column
= node
->GetData();
3529 column
->SetItem( item
);
3531 wxListHeaderWindow
*headerWin
= GetListCtrl()->m_headerWin
;
3533 headerWin
->m_dirty
= true;
3537 // invalidate it as it has to be recalculated
3541 void wxListMainWindow::SetColumnWidth( int col
, int width
)
3543 wxCHECK_RET( col
>= 0 && col
< GetColumnCount(),
3544 _T("invalid column index") );
3546 wxCHECK_RET( InReportView(),
3547 _T("SetColumnWidth() can only be called in report mode.") );
3550 wxListHeaderWindow
*headerWin
= GetListCtrl()->m_headerWin
;
3552 headerWin
->m_dirty
= true;
3554 wxListHeaderDataList::compatibility_iterator node
= m_columns
.Item( col
);
3555 wxCHECK_RET( node
, _T("no column?") );
3557 wxListHeaderData
*column
= node
->GetData();
3559 size_t count
= GetItemCount();
3561 if (width
== wxLIST_AUTOSIZE_USEHEADER
)
3563 width
= GetTextLength(column
->GetText());
3565 else if ( width
== wxLIST_AUTOSIZE
)
3569 // TODO: determine the max width somehow...
3570 width
= WIDTH_COL_DEFAULT
;
3574 wxClientDC
dc(this);
3575 dc
.SetFont( GetFont() );
3577 int max
= AUTOSIZE_COL_MARGIN
;
3579 // if the cached column width isn't valid then recalculate it
3580 if (m_aColWidths
.Item(col
)->bNeedsUpdate
)
3582 for (size_t i
= 0; i
< count
; i
++)
3584 wxListLineData
*line
= GetLine(i
);
3585 wxListItemDataList::compatibility_iterator n
= line
->m_items
.Item( col
);
3587 wxCHECK_RET( n
, _T("no subitem?") );
3589 wxListItemData
*itemData
= n
->GetData();
3592 itemData
->GetItem(item
);
3593 int itemWidth
= GetItemWidthWithImage(&item
);
3594 if (itemWidth
> max
)
3598 m_aColWidths
.Item(col
)->bNeedsUpdate
= false;
3599 m_aColWidths
.Item(col
)->nMaxWidth
= max
;
3602 max
= m_aColWidths
.Item(col
)->nMaxWidth
;
3603 width
= max
+ AUTOSIZE_COL_MARGIN
;
3607 column
->SetWidth( width
);
3609 // invalidate it as it has to be recalculated
3613 int wxListMainWindow::GetHeaderWidth() const
3615 if ( !m_headerWidth
)
3617 wxListMainWindow
*self
= wxConstCast(this, wxListMainWindow
);
3619 size_t count
= GetColumnCount();
3620 for ( size_t col
= 0; col
< count
; col
++ )
3622 self
->m_headerWidth
+= GetColumnWidth(col
);
3626 return m_headerWidth
;
3629 void wxListMainWindow::GetColumn( int col
, wxListItem
&item
) const
3631 wxListHeaderDataList::compatibility_iterator node
= m_columns
.Item( col
);
3632 wxCHECK_RET( node
, _T("invalid column index in GetColumn") );
3634 wxListHeaderData
*column
= node
->GetData();
3635 column
->GetItem( item
);
3638 int wxListMainWindow::GetColumnWidth( int col
) const
3640 wxListHeaderDataList::compatibility_iterator node
= m_columns
.Item( col
);
3641 wxCHECK_MSG( node
, 0, _T("invalid column index") );
3643 wxListHeaderData
*column
= node
->GetData();
3644 return column
->GetWidth();
3647 // ----------------------------------------------------------------------------
3649 // ----------------------------------------------------------------------------
3651 void wxListMainWindow::SetItem( wxListItem
&item
)
3653 long id
= item
.m_itemId
;
3654 wxCHECK_RET( id
>= 0 && (size_t)id
< GetItemCount(),
3655 _T("invalid item index in SetItem") );
3659 wxListLineData
*line
= GetLine((size_t)id
);
3660 line
->SetItem( item
.m_col
, item
);
3662 // Set item state if user wants
3663 if ( item
.m_mask
& wxLIST_MASK_STATE
)
3664 SetItemState( item
.m_itemId
, item
.m_state
, item
.m_state
);
3668 // update the Max Width Cache if needed
3669 int width
= GetItemWidthWithImage(&item
);
3671 if (width
> m_aColWidths
.Item(item
.m_col
)->nMaxWidth
)
3672 m_aColWidths
.Item(item
.m_col
)->nMaxWidth
= width
;
3676 // update the item on screen
3678 GetItemRect(id
, rectItem
);
3679 RefreshRect(rectItem
);
3682 void wxListMainWindow::SetItemStateAll(long state
, long stateMask
)
3687 // first deal with selection
3688 if ( stateMask
& wxLIST_STATE_SELECTED
)
3690 // set/clear select state
3693 // optimized version for virtual listctrl.
3694 m_selStore
.SelectRange(0, GetItemCount() - 1, state
== wxLIST_STATE_SELECTED
);
3697 else if ( state
& wxLIST_STATE_SELECTED
)
3699 const long count
= GetItemCount();
3700 for( long i
= 0; i
< count
; i
++ )
3702 SetItemState( i
, wxLIST_STATE_SELECTED
, wxLIST_STATE_SELECTED
);
3708 // clear for non virtual (somewhat optimized by using GetNextItem())
3710 while ( (i
= GetNextItem(i
, wxLIST_NEXT_ALL
, wxLIST_STATE_SELECTED
)) != -1 )
3712 SetItemState( i
, 0, wxLIST_STATE_SELECTED
);
3717 if ( HasCurrent() && (state
== 0) && (stateMask
& wxLIST_STATE_FOCUSED
) )
3719 // unfocus all: only one item can be focussed, so clearing focus for
3720 // all items is simply clearing focus of the focussed item.
3721 SetItemState(m_current
, state
, stateMask
);
3723 //(setting focus to all items makes no sense, so it is not handled here.)
3726 void wxListMainWindow::SetItemState( long litem
, long state
, long stateMask
)
3730 SetItemStateAll(state
, stateMask
);
3734 wxCHECK_RET( litem
>= 0 && (size_t)litem
< GetItemCount(),
3735 _T("invalid list ctrl item index in SetItem") );
3737 size_t oldCurrent
= m_current
;
3738 size_t item
= (size_t)litem
; // safe because of the check above
3740 // do we need to change the focus?
3741 if ( stateMask
& wxLIST_STATE_FOCUSED
)
3743 if ( state
& wxLIST_STATE_FOCUSED
)
3745 // don't do anything if this item is already focused
3746 if ( item
!= m_current
)
3748 ChangeCurrent(item
);
3750 if ( oldCurrent
!= (size_t)-1 )
3752 if ( IsSingleSel() )
3754 HighlightLine(oldCurrent
, false);
3757 RefreshLine(oldCurrent
);
3760 RefreshLine( m_current
);
3765 // don't do anything if this item is not focused
3766 if ( item
== m_current
)
3770 if ( IsSingleSel() )
3772 // we must unselect the old current item as well or we
3773 // might end up with more than one selected item in a
3774 // single selection control
3775 HighlightLine(oldCurrent
, false);
3778 RefreshLine( oldCurrent
);
3783 // do we need to change the selection state?
3784 if ( stateMask
& wxLIST_STATE_SELECTED
)
3786 bool on
= (state
& wxLIST_STATE_SELECTED
) != 0;
3788 if ( IsSingleSel() )
3792 // selecting the item also makes it the focused one in the
3794 if ( m_current
!= item
)
3796 ChangeCurrent(item
);
3798 if ( oldCurrent
!= (size_t)-1 )
3800 HighlightLine( oldCurrent
, false );
3801 RefreshLine( oldCurrent
);
3807 // only the current item may be selected anyhow
3808 if ( item
!= m_current
)
3813 if ( HighlightLine(item
, on
) )
3820 int wxListMainWindow::GetItemState( long item
, long stateMask
) const
3822 wxCHECK_MSG( item
>= 0 && (size_t)item
< GetItemCount(), 0,
3823 _T("invalid list ctrl item index in GetItemState()") );
3825 int ret
= wxLIST_STATE_DONTCARE
;
3827 if ( stateMask
& wxLIST_STATE_FOCUSED
)
3829 if ( (size_t)item
== m_current
)
3830 ret
|= wxLIST_STATE_FOCUSED
;
3833 if ( stateMask
& wxLIST_STATE_SELECTED
)
3835 if ( IsHighlighted(item
) )
3836 ret
|= wxLIST_STATE_SELECTED
;
3842 void wxListMainWindow::GetItem( wxListItem
&item
) const
3844 wxCHECK_RET( item
.m_itemId
>= 0 && (size_t)item
.m_itemId
< GetItemCount(),
3845 _T("invalid item index in GetItem") );
3847 wxListLineData
*line
= GetLine((size_t)item
.m_itemId
);
3848 line
->GetItem( item
.m_col
, item
);
3850 // Get item state if user wants it
3851 if ( item
.m_mask
& wxLIST_MASK_STATE
)
3852 item
.m_state
= GetItemState( item
.m_itemId
, wxLIST_STATE_SELECTED
|
3853 wxLIST_STATE_FOCUSED
);
3856 // ----------------------------------------------------------------------------
3858 // ----------------------------------------------------------------------------
3860 size_t wxListMainWindow::GetItemCount() const
3862 return IsVirtual() ? m_countVirt
: m_lines
.GetCount();
3865 void wxListMainWindow::SetItemCount(long count
)
3867 m_selStore
.SetItemCount(count
);
3868 m_countVirt
= count
;
3870 ResetVisibleLinesRange();
3872 // scrollbars must be reset
3876 int wxListMainWindow::GetSelectedItemCount() const
3878 // deal with the quick case first
3879 if ( IsSingleSel() )
3881 return HasCurrent() ? IsHighlighted(m_current
) : false;
3884 // virtual controls remmebers all its selections itself
3886 return m_selStore
.GetSelectedCount();
3888 // TODO: we probably should maintain the number of items selected even for
3889 // non virtual controls as enumerating all lines is really slow...
3890 size_t countSel
= 0;
3891 size_t count
= GetItemCount();
3892 for ( size_t line
= 0; line
< count
; line
++ )
3894 if ( GetLine(line
)->IsHighlighted() )
3901 // ----------------------------------------------------------------------------
3902 // item position/size
3903 // ----------------------------------------------------------------------------
3905 wxRect
wxListMainWindow::GetViewRect() const
3907 wxASSERT_MSG( !HasFlag(wxLC_REPORT
| wxLC_LIST
),
3908 _T("wxListCtrl::GetViewRect() only works in icon mode") );
3910 // we need to find the longest/tallest label
3913 const int count
= GetItemCount();
3916 for ( int i
= 0; i
< count
; i
++ )
3921 wxCoord x
= r
.GetRight(),
3931 // some fudge needed to make it look prettier
3932 xMax
+= 2*EXTRA_BORDER_X
;
3933 yMax
+= 2*EXTRA_BORDER_Y
;
3935 // account for the scrollbars if necessary
3936 const wxSize sizeAll
= GetClientSize();
3937 if ( xMax
> sizeAll
.x
)
3938 yMax
+= wxSystemSettings::GetMetric(wxSYS_HSCROLL_Y
);
3939 if ( yMax
> sizeAll
.y
)
3940 xMax
+= wxSystemSettings::GetMetric(wxSYS_VSCROLL_X
);
3942 return wxRect(0, 0, xMax
, yMax
);
3945 void wxListMainWindow::GetItemRect( long index
, wxRect
&rect
) const
3947 wxCHECK_RET( index
>= 0 && (size_t)index
< GetItemCount(),
3948 _T("invalid index in GetItemRect") );
3950 // ensure that we're laid out, otherwise we could return nonsense
3953 wxConstCast(this, wxListMainWindow
)->
3954 RecalculatePositions(true /* no refresh */);
3957 rect
= GetLineRect((size_t)index
);
3959 CalcScrolledPosition(rect
.x
, rect
.y
, &rect
.x
, &rect
.y
);
3962 bool wxListMainWindow::GetItemPosition(long item
, wxPoint
& pos
) const
3965 GetItemRect(item
, rect
);
3973 // ----------------------------------------------------------------------------
3974 // geometry calculation
3975 // ----------------------------------------------------------------------------
3977 void wxListMainWindow::RecalculatePositions(bool noRefresh
)
3979 wxClientDC
dc( this );
3980 dc
.SetFont( GetFont() );
3982 const size_t count
= GetItemCount();
3985 if ( HasFlag(wxLC_ICON
) )
3986 iconSpacing
= m_normal_spacing
;
3987 else if ( HasFlag(wxLC_SMALL_ICON
) )
3988 iconSpacing
= m_small_spacing
;
3992 // Note that we do not call GetClientSize() here but
3993 // GetSize() and subtract the border size for sunken
3994 // borders manually. This is technically incorrect,
3995 // but we need to know the client area's size WITHOUT
3996 // scrollbars here. Since we don't know if there are
3997 // any scrollbars, we use GetSize() instead. Another
3998 // solution would be to call SetScrollbars() here to
3999 // remove the scrollbars and call GetClientSize() then,
4000 // but this might result in flicker and - worse - will
4001 // reset the scrollbars to 0 which is not good at all
4002 // if you resize a dialog/window, but don't want to
4003 // reset the window scrolling. RR.
4004 // Furthermore, we actually do NOT subtract the border
4005 // width as 2 pixels is just the extra space which we
4006 // need around the actual content in the window. Other-
4007 // wise the text would e.g. touch the upper border. RR.
4010 GetSize( &clientWidth
, &clientHeight
);
4012 const int lineHeight
= GetLineHeight();
4014 if ( InReportView() )
4016 // all lines have the same height and we scroll one line per step
4017 int entireHeight
= count
*lineHeight
+ LINE_SPACING
;
4019 m_linesPerPage
= clientHeight
/ lineHeight
;
4021 ResetVisibleLinesRange();
4023 SetScrollbars( SCROLL_UNIT_X
, lineHeight
,
4024 GetHeaderWidth() / SCROLL_UNIT_X
,
4025 (entireHeight
+ lineHeight
- 1) / lineHeight
,
4026 GetScrollPos(wxHORIZONTAL
),
4027 GetScrollPos(wxVERTICAL
),
4032 // we have 3 different layout strategies: either layout all items
4033 // horizontally/vertically (wxLC_ALIGN_XXX styles explicitly given) or
4034 // to arrange them in top to bottom, left to right (don't ask me why
4035 // not the other way round...) order
4036 if ( HasFlag(wxLC_ALIGN_LEFT
| wxLC_ALIGN_TOP
) )
4038 int x
= EXTRA_BORDER_X
;
4039 int y
= EXTRA_BORDER_Y
;
4041 wxCoord widthMax
= 0;
4044 for ( i
= 0; i
< count
; i
++ )
4046 wxListLineData
*line
= GetLine(i
);
4047 line
->CalculateSize( &dc
, iconSpacing
);
4048 line
->SetPosition( x
, y
, iconSpacing
);
4050 wxSize sizeLine
= GetLineSize(i
);
4052 if ( HasFlag(wxLC_ALIGN_TOP
) )
4054 if ( sizeLine
.x
> widthMax
)
4055 widthMax
= sizeLine
.x
;
4059 else // wxLC_ALIGN_LEFT
4061 x
+= sizeLine
.x
+ MARGIN_BETWEEN_ROWS
;
4065 if ( HasFlag(wxLC_ALIGN_TOP
) )
4067 // traverse the items again and tweak their sizes so that they are
4068 // all the same in a row
4069 for ( i
= 0; i
< count
; i
++ )
4071 wxListLineData
*line
= GetLine(i
);
4072 line
->m_gi
->ExtendWidth(widthMax
);
4081 (x
+ SCROLL_UNIT_X
) / SCROLL_UNIT_X
,
4082 (y
+ lineHeight
) / lineHeight
,
4083 GetScrollPos( wxHORIZONTAL
),
4084 GetScrollPos( wxVERTICAL
),
4088 else // "flowed" arrangement, the most complicated case
4090 // at first we try without any scrollbars, if the items don't fit into
4091 // the window, we recalculate after subtracting the space taken by the
4094 int entireWidth
= 0;
4096 for (int tries
= 0; tries
< 2; tries
++)
4098 entireWidth
= 2*EXTRA_BORDER_X
;
4102 // Now we have decided that the items do not fit into the
4103 // client area, so we need a scrollbar
4104 entireWidth
+= SCROLL_UNIT_X
;
4107 int x
= EXTRA_BORDER_X
;
4108 int y
= EXTRA_BORDER_Y
;
4109 int maxWidthInThisRow
= 0;
4112 int currentlyVisibleLines
= 0;
4114 for (size_t i
= 0; i
< count
; i
++)
4116 currentlyVisibleLines
++;
4117 wxListLineData
*line
= GetLine(i
);
4118 line
->CalculateSize( &dc
, iconSpacing
);
4119 line
->SetPosition( x
, y
, iconSpacing
);
4121 wxSize sizeLine
= GetLineSize(i
);
4123 if ( maxWidthInThisRow
< sizeLine
.x
)
4124 maxWidthInThisRow
= sizeLine
.x
;
4127 if (currentlyVisibleLines
> m_linesPerPage
)
4128 m_linesPerPage
= currentlyVisibleLines
;
4130 if ( y
+ sizeLine
.y
>= clientHeight
)
4132 currentlyVisibleLines
= 0;
4134 maxWidthInThisRow
+= MARGIN_BETWEEN_ROWS
;
4135 x
+= maxWidthInThisRow
;
4136 entireWidth
+= maxWidthInThisRow
;
4137 maxWidthInThisRow
= 0;
4140 // We have reached the last item.
4141 if ( i
== count
- 1 )
4142 entireWidth
+= maxWidthInThisRow
;
4144 if ( (tries
== 0) &&
4145 (entireWidth
+ SCROLL_UNIT_X
> clientWidth
) )
4147 clientHeight
-= wxSystemSettings::
4148 GetMetric(wxSYS_HSCROLL_Y
);
4153 if ( i
== count
- 1 )
4154 tries
= 1; // Everything fits, no second try required.
4162 (entireWidth
+ SCROLL_UNIT_X
) / SCROLL_UNIT_X
,
4164 GetScrollPos( wxHORIZONTAL
),
4173 // FIXME: why should we call it from here?
4180 void wxListMainWindow::RefreshAll()
4185 wxListHeaderWindow
*headerWin
= GetListCtrl()->m_headerWin
;
4186 if ( headerWin
&& headerWin
->m_dirty
)
4188 headerWin
->m_dirty
= false;
4189 headerWin
->Refresh();
4193 void wxListMainWindow::UpdateCurrent()
4195 if ( !HasCurrent() && !IsEmpty() )
4201 long wxListMainWindow::GetNextItem( long item
,
4202 int WXUNUSED(geometry
),
4206 max
= GetItemCount();
4207 wxCHECK_MSG( (ret
== -1) || (ret
< max
), -1,
4208 _T("invalid listctrl index in GetNextItem()") );
4210 // notice that we start with the next item (or the first one if item == -1)
4211 // and this is intentional to allow writing a simple loop to iterate over
4212 // all selected items
4216 // this is not an error because the index was ok initially, just no
4227 size_t count
= GetItemCount();
4228 for ( size_t line
= (size_t)ret
; line
< count
; line
++ )
4230 if ( (state
& wxLIST_STATE_FOCUSED
) && (line
== m_current
) )
4233 if ( (state
& wxLIST_STATE_SELECTED
) && IsHighlighted(line
) )
4240 // ----------------------------------------------------------------------------
4242 // ----------------------------------------------------------------------------
4244 void wxListMainWindow::DeleteItem( long lindex
)
4246 size_t count
= GetItemCount();
4248 wxCHECK_RET( (lindex
>= 0) && ((size_t)lindex
< count
),
4249 _T("invalid item index in DeleteItem") );
4251 size_t index
= (size_t)lindex
;
4253 // we don't need to adjust the index for the previous items
4254 if ( HasCurrent() && m_current
>= index
)
4256 // if the current item is being deleted, we want the next one to
4257 // become selected - unless there is no next one - so don't adjust
4258 // m_current in this case
4259 if ( m_current
!= index
|| m_current
== count
- 1 )
4265 if ( InReportView() )
4267 // mark the Column Max Width cache as dirty if the items in the line
4268 // we're deleting contain the Max Column Width
4269 wxListLineData
* const line
= GetLine(index
);
4270 wxListItemDataList::compatibility_iterator n
;
4271 wxListItemData
*itemData
;
4275 for (size_t i
= 0; i
< m_columns
.GetCount(); i
++)
4277 n
= line
->m_items
.Item( i
);
4278 itemData
= n
->GetData();
4279 itemData
->GetItem(item
);
4281 itemWidth
= GetItemWidthWithImage(&item
);
4283 if (itemWidth
>= m_aColWidths
.Item(i
)->nMaxWidth
)
4284 m_aColWidths
.Item(i
)->bNeedsUpdate
= true;
4287 ResetVisibleLinesRange();
4294 m_selStore
.OnItemDelete(index
);
4298 m_lines
.RemoveAt( index
);
4301 // we need to refresh the (vert) scrollbar as the number of items changed
4304 SendNotify( index
, wxEVT_COMMAND_LIST_DELETE_ITEM
);
4306 RefreshAfter(index
);
4309 void wxListMainWindow::DeleteColumn( int col
)
4311 wxListHeaderDataList::compatibility_iterator node
= m_columns
.Item( col
);
4313 wxCHECK_RET( node
, wxT("invalid column index in DeleteColumn()") );
4316 delete node
->GetData();
4317 m_columns
.Erase( node
);
4321 // update all the items
4322 for ( size_t i
= 0; i
< m_lines
.GetCount(); i
++ )
4324 wxListLineData
* const line
= GetLine(i
);
4325 wxListItemDataList::compatibility_iterator n
= line
->m_items
.Item( col
);
4326 delete n
->GetData();
4327 line
->m_items
.Erase(n
);
4331 if ( InReportView() ) // we only cache max widths when in Report View
4333 delete m_aColWidths
.Item(col
);
4334 m_aColWidths
.RemoveAt(col
);
4337 // invalidate it as it has to be recalculated
4341 void wxListMainWindow::DoDeleteAllItems()
4345 // nothing to do - in particular, don't send the event
4351 // to make the deletion of all items faster, we don't send the
4352 // notifications for each item deletion in this case but only one event
4353 // for all of them: this is compatible with wxMSW and documented in
4354 // DeleteAllItems() description
4356 wxListEvent
event( wxEVT_COMMAND_LIST_DELETE_ALL_ITEMS
, GetParent()->GetId() );
4357 event
.SetEventObject( GetParent() );
4358 GetParent()->GetEventHandler()->ProcessEvent( event
);
4367 if ( InReportView() )
4369 ResetVisibleLinesRange();
4370 for (size_t i
= 0; i
< m_aColWidths
.GetCount(); i
++)
4372 m_aColWidths
.Item(i
)->bNeedsUpdate
= true;
4379 void wxListMainWindow::DeleteAllItems()
4383 RecalculatePositions();
4386 void wxListMainWindow::DeleteEverything()
4388 WX_CLEAR_LIST(wxListHeaderDataList
, m_columns
);
4389 WX_CLEAR_ARRAY(m_aColWidths
);
4394 // ----------------------------------------------------------------------------
4395 // scanning for an item
4396 // ----------------------------------------------------------------------------
4398 void wxListMainWindow::EnsureVisible( long index
)
4400 wxCHECK_RET( index
>= 0 && (size_t)index
< GetItemCount(),
4401 _T("invalid index in EnsureVisible") );
4403 // We have to call this here because the label in question might just have
4404 // been added and its position is not known yet
4407 RecalculatePositions(true /* no refresh */);
4410 MoveToItem((size_t)index
);
4413 long wxListMainWindow::FindItem(long start
, const wxString
& str
, bool WXUNUSED(partial
) )
4420 size_t count
= GetItemCount();
4421 for ( size_t i
= (size_t)pos
; i
< count
; i
++ )
4423 wxListLineData
*line
= GetLine(i
);
4424 if ( line
->GetText(0) == tmp
)
4431 long wxListMainWindow::FindItem(long start
, wxUIntPtr data
)
4437 size_t count
= GetItemCount();
4438 for (size_t i
= (size_t)pos
; i
< count
; i
++)
4440 wxListLineData
*line
= GetLine(i
);
4442 line
->GetItem( 0, item
);
4443 if (item
.m_data
== data
)
4450 long wxListMainWindow::FindItem( const wxPoint
& pt
)
4453 GetVisibleLinesRange(&topItem
, NULL
);
4456 GetItemPosition( GetItemCount()-1, p
);
4459 long id
= (long) floor( pt
.y
*double(GetItemCount()-topItem
-1)/p
.y
+topItem
);
4460 if( id
>= 0 && id
< (long)GetItemCount() )
4466 long wxListMainWindow::HitTest( int x
, int y
, int &flags
)
4468 CalcUnscrolledPosition( x
, y
, &x
, &y
);
4470 size_t count
= GetItemCount();
4472 if ( InReportView() )
4474 size_t current
= y
/ GetLineHeight();
4475 if ( current
< count
)
4477 flags
= HitTestLine(current
, x
, y
);
4484 // TODO: optimize it too! this is less simple than for report view but
4485 // enumerating all items is still not a way to do it!!
4486 for ( size_t current
= 0; current
< count
; current
++ )
4488 flags
= HitTestLine(current
, x
, y
);
4497 // ----------------------------------------------------------------------------
4499 // ----------------------------------------------------------------------------
4501 void wxListMainWindow::InsertItem( wxListItem
&item
)
4503 wxASSERT_MSG( !IsVirtual(), _T("can't be used with virtual control") );
4505 int count
= GetItemCount();
4506 wxCHECK_RET( item
.m_itemId
>= 0, _T("invalid item index") );
4508 if (item
.m_itemId
> count
)
4509 item
.m_itemId
= count
;
4511 size_t id
= item
.m_itemId
;
4515 if ( InReportView() )
4517 ResetVisibleLinesRange();
4519 // calculate the width of the item and adjust the max column width
4520 wxColWidthInfo
*pWidthInfo
= m_aColWidths
.Item(item
.GetColumn());
4521 int width
= GetItemWidthWithImage(&item
);
4522 item
.SetWidth(width
);
4523 if (width
> pWidthInfo
->nMaxWidth
)
4524 pWidthInfo
->nMaxWidth
= width
;
4527 wxListLineData
*line
= new wxListLineData(this);
4529 line
->SetItem( item
.m_col
, item
);
4531 m_lines
.Insert( line
, id
);
4535 // If an item is selected at or below the point of insertion, we need to
4536 // increment the member variables because the current row's index has gone
4538 if ( HasCurrent() && m_current
>= id
)
4543 SendNotify(id
, wxEVT_COMMAND_LIST_INSERT_ITEM
);
4545 RefreshLines(id
, GetItemCount() - 1);
4548 void wxListMainWindow::InsertColumn( long col
, wxListItem
&item
)
4551 if ( InReportView() )
4553 if (item
.m_width
== wxLIST_AUTOSIZE_USEHEADER
)
4554 item
.m_width
= GetTextLength( item
.m_text
);
4556 wxListHeaderData
*column
= new wxListHeaderData( item
);
4557 wxColWidthInfo
*colWidthInfo
= new wxColWidthInfo();
4559 bool insert
= (col
>= 0) && ((size_t)col
< m_columns
.GetCount());
4562 wxListHeaderDataList::compatibility_iterator
4563 node
= m_columns
.Item( col
);
4564 m_columns
.Insert( node
, column
);
4565 m_aColWidths
.Insert( colWidthInfo
, col
);
4569 m_columns
.Append( column
);
4570 m_aColWidths
.Add( colWidthInfo
);
4575 // update all the items
4576 for ( size_t i
= 0; i
< m_lines
.GetCount(); i
++ )
4578 wxListLineData
* const line
= GetLine(i
);
4579 wxListItemData
* const data
= new wxListItemData(this);
4581 line
->m_items
.Insert(col
, data
);
4583 line
->m_items
.Append(data
);
4587 // invalidate it as it has to be recalculated
4592 int wxListMainWindow::GetItemWidthWithImage(wxListItem
* item
)
4595 wxClientDC
dc(this);
4597 dc
.SetFont( GetFont() );
4599 if (item
->GetImage() != -1)
4602 GetImageSize( item
->GetImage(), ix
, iy
);
4606 if (!item
->GetText().empty())
4609 dc
.GetTextExtent( item
->GetText(), &w
, NULL
);
4616 // ----------------------------------------------------------------------------
4618 // ----------------------------------------------------------------------------
4620 wxListCtrlCompare list_ctrl_compare_func_2
;
4621 long list_ctrl_compare_data
;
4623 int LINKAGEMODE
list_ctrl_compare_func_1( wxListLineData
**arg1
, wxListLineData
**arg2
)
4625 wxListLineData
*line1
= *arg1
;
4626 wxListLineData
*line2
= *arg2
;
4628 line1
->GetItem( 0, item
);
4629 wxUIntPtr data1
= item
.m_data
;
4630 line2
->GetItem( 0, item
);
4631 wxUIntPtr data2
= item
.m_data
;
4632 return list_ctrl_compare_func_2( data1
, data2
, list_ctrl_compare_data
);
4635 void wxListMainWindow::SortItems( wxListCtrlCompare fn
, long data
)
4637 list_ctrl_compare_func_2
= fn
;
4638 list_ctrl_compare_data
= data
;
4639 m_lines
.Sort( list_ctrl_compare_func_1
);
4643 // ----------------------------------------------------------------------------
4645 // ----------------------------------------------------------------------------
4647 void wxListMainWindow::OnScroll(wxScrollWinEvent
& event
)
4649 // update our idea of which lines are shown when we redraw the window the
4651 ResetVisibleLinesRange();
4654 #if ( defined(__WXGTK__) || defined(__WXMAC__) ) && !defined(__WXUNIVERSAL__)
4655 wxScrolledWindow::OnScroll(event
);
4657 HandleOnScroll( event
);
4660 if ( event
.GetOrientation() == wxHORIZONTAL
&& HasHeader() )
4662 wxGenericListCtrl
* lc
= GetListCtrl();
4663 wxCHECK_RET( lc
, _T("no listctrl window?") );
4665 lc
->m_headerWin
->Refresh();
4666 lc
->m_headerWin
->Update();
4670 int wxListMainWindow::GetCountPerPage() const
4672 if ( !m_linesPerPage
)
4674 wxConstCast(this, wxListMainWindow
)->
4675 m_linesPerPage
= GetClientSize().y
/ GetLineHeight();
4678 return m_linesPerPage
;
4681 void wxListMainWindow::GetVisibleLinesRange(size_t *from
, size_t *to
)
4683 wxASSERT_MSG( InReportView(), _T("this is for report mode only") );
4685 if ( m_lineFrom
== (size_t)-1 )
4687 size_t count
= GetItemCount();
4690 m_lineFrom
= GetScrollPos(wxVERTICAL
);
4692 // this may happen if SetScrollbars() hadn't been called yet
4693 if ( m_lineFrom
>= count
)
4694 m_lineFrom
= count
- 1;
4696 // we redraw one extra line but this is needed to make the redrawing
4697 // logic work when there is a fractional number of lines on screen
4698 m_lineTo
= m_lineFrom
+ m_linesPerPage
;
4699 if ( m_lineTo
>= count
)
4700 m_lineTo
= count
- 1;
4702 else // empty control
4705 m_lineTo
= (size_t)-1;
4709 wxASSERT_MSG( IsEmpty() ||
4710 (m_lineFrom
<= m_lineTo
&& m_lineTo
< GetItemCount()),
4711 _T("GetVisibleLinesRange() returns incorrect result") );
4719 // -------------------------------------------------------------------------------------
4720 // wxGenericListCtrl
4721 // -------------------------------------------------------------------------------------
4723 IMPLEMENT_DYNAMIC_CLASS(wxGenericListCtrl
, wxControl
)
4725 BEGIN_EVENT_TABLE(wxGenericListCtrl
,wxControl
)
4726 EVT_SIZE(wxGenericListCtrl::OnSize
)
4729 wxGenericListCtrl::wxGenericListCtrl()
4731 m_imageListNormal
= (wxImageListType
*) NULL
;
4732 m_imageListSmall
= (wxImageListType
*) NULL
;
4733 m_imageListState
= (wxImageListType
*) NULL
;
4735 m_ownsImageListNormal
=
4736 m_ownsImageListSmall
=
4737 m_ownsImageListState
= false;
4739 m_mainWin
= (wxListMainWindow
*) NULL
;
4740 m_headerWin
= (wxListHeaderWindow
*) NULL
;
4744 wxGenericListCtrl::~wxGenericListCtrl()
4746 if (m_ownsImageListNormal
)
4747 delete m_imageListNormal
;
4748 if (m_ownsImageListSmall
)
4749 delete m_imageListSmall
;
4750 if (m_ownsImageListState
)
4751 delete m_imageListState
;
4754 void wxGenericListCtrl::CalculateAndSetHeaderHeight()
4760 GetThemeMetric( kThemeMetricListHeaderHeight
, &h
);
4762 // we use 'g' to get the descent, too
4764 m_headerWin
->GetTextExtent(wxT("Hg"), &w
, &h
, &d
);
4765 h
+= d
+ 2 * HEADER_OFFSET_Y
+ EXTRA_HEIGHT
;
4767 // only update if changed
4768 if ( h
!= m_headerHeight
)
4772 m_headerWin
->SetSize(m_headerWin
->GetSize().x
, m_headerHeight
);
4775 ResizeReportView(true);
4780 void wxGenericListCtrl::CreateHeaderWindow()
4782 m_headerWin
= new wxListHeaderWindow
4784 this, wxID_ANY
, m_mainWin
,
4786 wxSize(GetClientSize().x
, m_headerHeight
),
4789 CalculateAndSetHeaderHeight();
4792 bool wxGenericListCtrl::Create(wxWindow
*parent
,
4797 const wxValidator
&validator
,
4798 const wxString
&name
)
4802 m_imageListState
= (wxImageListType
*) NULL
;
4803 m_ownsImageListNormal
=
4804 m_ownsImageListSmall
=
4805 m_ownsImageListState
= false;
4807 m_mainWin
= (wxListMainWindow
*) NULL
;
4808 m_headerWin
= (wxListHeaderWindow
*) NULL
;
4812 if ( !(style
& wxLC_MASK_TYPE
) )
4814 style
= style
| wxLC_LIST
;
4817 if ( !wxControl::Create( parent
, id
, pos
, size
, style
, validator
, name
) )
4820 // don't create the inner window with the border
4821 style
&= ~wxBORDER_MASK
;
4823 m_mainWin
= new wxListMainWindow( this, wxID_ANY
, wxPoint(0,0), size
, style
);
4825 #ifdef __WXMAC_CARBON__
4826 // Human Interface Guidelines ask us for a special font in this case
4827 if ( GetWindowVariant() == wxWINDOW_VARIANT_NORMAL
)
4830 font
.MacCreateThemeFont( kThemeViewsFont
) ;
4834 if ( InReportView() )
4836 CreateHeaderWindow();
4837 #ifdef __WXMAC_CARBON__
4841 font
.MacCreateThemeFont( kThemeSmallSystemFont
) ;
4842 m_headerWin
->SetFont( font
);
4843 CalculateAndSetHeaderHeight();
4846 if ( HasFlag(wxLC_NO_HEADER
) )
4848 // VZ: why do we create it at all then?
4849 m_headerWin
->Show( false );
4858 void wxGenericListCtrl::SetSingleStyle( long style
, bool add
)
4860 wxASSERT_MSG( !(style
& wxLC_VIRTUAL
),
4861 _T("wxLC_VIRTUAL can't be [un]set") );
4863 long flag
= GetWindowStyle();
4867 if (style
& wxLC_MASK_TYPE
)
4868 flag
&= ~(wxLC_MASK_TYPE
| wxLC_VIRTUAL
);
4869 if (style
& wxLC_MASK_ALIGN
)
4870 flag
&= ~wxLC_MASK_ALIGN
;
4871 if (style
& wxLC_MASK_SORT
)
4872 flag
&= ~wxLC_MASK_SORT
;
4884 SetWindowStyleFlag( flag
);
4887 void wxGenericListCtrl::SetWindowStyleFlag( long flag
)
4891 m_mainWin
->DeleteEverything();
4893 // has the header visibility changed?
4894 bool hasHeader
= HasHeader();
4895 bool willHaveHeader
= (flag
& wxLC_REPORT
) && !(flag
& wxLC_NO_HEADER
);
4897 if ( hasHeader
!= willHaveHeader
)
4904 // don't delete, just hide, as we can reuse it later
4905 m_headerWin
->Show(false);
4907 //else: nothing to do
4909 else // must show header
4913 CreateHeaderWindow();
4915 else // already have it, just show
4917 m_headerWin
->Show( true );
4921 ResizeReportView(willHaveHeader
);
4925 wxWindow::SetWindowStyleFlag( flag
);
4928 bool wxGenericListCtrl::GetColumn(int col
, wxListItem
&item
) const
4930 m_mainWin
->GetColumn( col
, item
);
4934 bool wxGenericListCtrl::SetColumn( int col
, wxListItem
& item
)
4936 m_mainWin
->SetColumn( col
, item
);
4940 int wxGenericListCtrl::GetColumnWidth( int col
) const
4942 return m_mainWin
->GetColumnWidth( col
);
4945 bool wxGenericListCtrl::SetColumnWidth( int col
, int width
)
4947 m_mainWin
->SetColumnWidth( col
, width
);
4951 int wxGenericListCtrl::GetCountPerPage() const
4953 return m_mainWin
->GetCountPerPage(); // different from Windows ?
4956 bool wxGenericListCtrl::GetItem( wxListItem
&info
) const
4958 m_mainWin
->GetItem( info
);
4962 bool wxGenericListCtrl::SetItem( wxListItem
&info
)
4964 m_mainWin
->SetItem( info
);
4968 long wxGenericListCtrl::SetItem( long index
, int col
, const wxString
& label
, int imageId
)
4971 info
.m_text
= label
;
4972 info
.m_mask
= wxLIST_MASK_TEXT
;
4973 info
.m_itemId
= index
;
4977 info
.m_image
= imageId
;
4978 info
.m_mask
|= wxLIST_MASK_IMAGE
;
4980 m_mainWin
->SetItem(info
);
4984 int wxGenericListCtrl::GetItemState( long item
, long stateMask
) const
4986 return m_mainWin
->GetItemState( item
, stateMask
);
4989 bool wxGenericListCtrl::SetItemState( long item
, long state
, long stateMask
)
4991 m_mainWin
->SetItemState( item
, state
, stateMask
);
4996 wxGenericListCtrl::SetItemImage( long item
, int image
, int WXUNUSED(selImage
) )
4999 info
.m_image
= image
;
5000 info
.m_mask
= wxLIST_MASK_IMAGE
;
5001 info
.m_itemId
= item
;
5002 m_mainWin
->SetItem( info
);
5006 wxString
wxGenericListCtrl::GetItemText( long item
) const
5008 return m_mainWin
->GetItemText(item
);
5011 void wxGenericListCtrl::SetItemText( long item
, const wxString
& str
)
5013 m_mainWin
->SetItemText(item
, str
);
5016 wxUIntPtr
wxGenericListCtrl::GetItemData( long item
) const
5019 info
.m_mask
= wxLIST_MASK_DATA
;
5020 info
.m_itemId
= item
;
5021 m_mainWin
->GetItem( info
);
5025 bool wxGenericListCtrl::SetItemData( long item
, long data
)
5028 info
.m_mask
= wxLIST_MASK_DATA
;
5029 info
.m_itemId
= item
;
5031 m_mainWin
->SetItem( info
);
5035 wxRect
wxGenericListCtrl::GetViewRect() const
5037 return m_mainWin
->GetViewRect();
5040 bool wxGenericListCtrl::GetItemRect( long item
, wxRect
&rect
, int WXUNUSED(code
) ) const
5042 m_mainWin
->GetItemRect( item
, rect
);
5043 if ( m_mainWin
->HasHeader() )
5044 rect
.y
+= m_headerHeight
+ 1;
5048 bool wxGenericListCtrl::GetItemPosition( long item
, wxPoint
& pos
) const
5050 m_mainWin
->GetItemPosition( item
, pos
);
5054 bool wxGenericListCtrl::SetItemPosition( long WXUNUSED(item
), const wxPoint
& WXUNUSED(pos
) )
5059 int wxGenericListCtrl::GetItemCount() const
5061 return m_mainWin
->GetItemCount();
5064 int wxGenericListCtrl::GetColumnCount() const
5066 return m_mainWin
->GetColumnCount();
5069 void wxGenericListCtrl::SetItemSpacing( int spacing
, bool isSmall
)
5071 m_mainWin
->SetItemSpacing( spacing
, isSmall
);
5074 wxSize
wxGenericListCtrl::GetItemSpacing() const
5076 const int spacing
= m_mainWin
->GetItemSpacing(HasFlag(wxLC_SMALL_ICON
));
5078 return wxSize(spacing
, spacing
);
5081 int wxGenericListCtrl::GetItemSpacing( bool isSmall
) const
5083 return m_mainWin
->GetItemSpacing( isSmall
);
5086 void wxGenericListCtrl::SetItemTextColour( long item
, const wxColour
&col
)
5089 info
.m_itemId
= item
;
5090 info
.SetTextColour( col
);
5091 m_mainWin
->SetItem( info
);
5094 wxColour
wxGenericListCtrl::GetItemTextColour( long item
) const
5097 info
.m_itemId
= item
;
5098 m_mainWin
->GetItem( info
);
5099 return info
.GetTextColour();
5102 void wxGenericListCtrl::SetItemBackgroundColour( long item
, const wxColour
&col
)
5105 info
.m_itemId
= item
;
5106 info
.SetBackgroundColour( col
);
5107 m_mainWin
->SetItem( info
);
5110 wxColour
wxGenericListCtrl::GetItemBackgroundColour( long item
) const
5113 info
.m_itemId
= item
;
5114 m_mainWin
->GetItem( info
);
5115 return info
.GetBackgroundColour();
5118 void wxGenericListCtrl::SetItemFont( long item
, const wxFont
&f
)
5121 info
.m_itemId
= item
;
5123 m_mainWin
->SetItem( info
);
5126 wxFont
wxGenericListCtrl::GetItemFont( long item
) const
5129 info
.m_itemId
= item
;
5130 m_mainWin
->GetItem( info
);
5131 return info
.GetFont();
5134 int wxGenericListCtrl::GetSelectedItemCount() const
5136 return m_mainWin
->GetSelectedItemCount();
5139 wxColour
wxGenericListCtrl::GetTextColour() const
5141 return GetForegroundColour();
5144 void wxGenericListCtrl::SetTextColour(const wxColour
& col
)
5146 SetForegroundColour(col
);
5149 long wxGenericListCtrl::GetTopItem() const
5152 m_mainWin
->GetVisibleLinesRange(&top
, NULL
);
5156 long wxGenericListCtrl::GetNextItem( long item
, int geom
, int state
) const
5158 return m_mainWin
->GetNextItem( item
, geom
, state
);
5161 wxImageListType
*wxGenericListCtrl::GetImageList(int which
) const
5163 if (which
== wxIMAGE_LIST_NORMAL
)
5165 return m_imageListNormal
;
5167 else if (which
== wxIMAGE_LIST_SMALL
)
5169 return m_imageListSmall
;
5171 else if (which
== wxIMAGE_LIST_STATE
)
5173 return m_imageListState
;
5175 return (wxImageListType
*) NULL
;
5178 void wxGenericListCtrl::SetImageList( wxImageListType
*imageList
, int which
)
5180 if ( which
== wxIMAGE_LIST_NORMAL
)
5182 if (m_ownsImageListNormal
) delete m_imageListNormal
;
5183 m_imageListNormal
= imageList
;
5184 m_ownsImageListNormal
= false;
5186 else if ( which
== wxIMAGE_LIST_SMALL
)
5188 if (m_ownsImageListSmall
) delete m_imageListSmall
;
5189 m_imageListSmall
= imageList
;
5190 m_ownsImageListSmall
= false;
5192 else if ( which
== wxIMAGE_LIST_STATE
)
5194 if (m_ownsImageListState
) delete m_imageListState
;
5195 m_imageListState
= imageList
;
5196 m_ownsImageListState
= false;
5199 m_mainWin
->SetImageList( imageList
, which
);
5202 void wxGenericListCtrl::AssignImageList(wxImageListType
*imageList
, int which
)
5204 SetImageList(imageList
, which
);
5205 if ( which
== wxIMAGE_LIST_NORMAL
)
5206 m_ownsImageListNormal
= true;
5207 else if ( which
== wxIMAGE_LIST_SMALL
)
5208 m_ownsImageListSmall
= true;
5209 else if ( which
== wxIMAGE_LIST_STATE
)
5210 m_ownsImageListState
= true;
5213 bool wxGenericListCtrl::Arrange( int WXUNUSED(flag
) )
5218 bool wxGenericListCtrl::DeleteItem( long item
)
5220 m_mainWin
->DeleteItem( item
);
5224 bool wxGenericListCtrl::DeleteAllItems()
5226 m_mainWin
->DeleteAllItems();
5230 bool wxGenericListCtrl::DeleteAllColumns()
5232 size_t count
= m_mainWin
->m_columns
.GetCount();
5233 for ( size_t n
= 0; n
< count
; n
++ )
5239 void wxGenericListCtrl::ClearAll()
5241 m_mainWin
->DeleteEverything();
5244 bool wxGenericListCtrl::DeleteColumn( int col
)
5246 m_mainWin
->DeleteColumn( col
);
5248 // if we don't have the header any longer, we need to relayout the window
5249 if ( !GetColumnCount() )
5251 ResizeReportView(false /* no header */);
5257 void wxGenericListCtrl::Edit( long item
)
5259 m_mainWin
->EditLabel( item
);
5262 bool wxGenericListCtrl::EnsureVisible( long item
)
5264 m_mainWin
->EnsureVisible( item
);
5268 long wxGenericListCtrl::FindItem( long start
, const wxString
& str
, bool partial
)
5270 return m_mainWin
->FindItem( start
, str
, partial
);
5273 long wxGenericListCtrl::FindItem( long start
, wxUIntPtr data
)
5275 return m_mainWin
->FindItem( start
, data
);
5278 long wxGenericListCtrl::FindItem( long WXUNUSED(start
), const wxPoint
& pt
,
5279 int WXUNUSED(direction
))
5281 return m_mainWin
->FindItem( pt
);
5284 long wxGenericListCtrl::HitTest( const wxPoint
&point
, int &flags
)
5286 return m_mainWin
->HitTest( (int)point
.x
, (int)point
.y
, flags
);
5289 long wxGenericListCtrl::InsertItem( wxListItem
& info
)
5291 m_mainWin
->InsertItem( info
);
5292 return info
.m_itemId
;
5295 long wxGenericListCtrl::InsertItem( long index
, const wxString
&label
)
5298 info
.m_text
= label
;
5299 info
.m_mask
= wxLIST_MASK_TEXT
;
5300 info
.m_itemId
= index
;
5301 return InsertItem( info
);
5304 long wxGenericListCtrl::InsertItem( long index
, int imageIndex
)
5307 info
.m_mask
= wxLIST_MASK_IMAGE
;
5308 info
.m_image
= imageIndex
;
5309 info
.m_itemId
= index
;
5310 return InsertItem( info
);
5313 long wxGenericListCtrl::InsertItem( long index
, const wxString
&label
, int imageIndex
)
5316 info
.m_text
= label
;
5317 info
.m_image
= imageIndex
;
5318 info
.m_mask
= wxLIST_MASK_TEXT
| wxLIST_MASK_IMAGE
;
5319 info
.m_itemId
= index
;
5320 return InsertItem( info
);
5323 long wxGenericListCtrl::InsertColumn( long col
, wxListItem
&item
)
5325 wxCHECK_MSG( m_headerWin
, -1, _T("can't add column in non report mode") );
5327 m_mainWin
->InsertColumn( col
, item
);
5329 // if we hadn't had header before and have it now we need to relayout the
5331 if ( GetColumnCount() == 1 && m_mainWin
->HasHeader() )
5333 ResizeReportView(true /* have header */);
5336 m_headerWin
->Refresh();
5341 long wxGenericListCtrl::InsertColumn( long col
, const wxString
&heading
,
5342 int format
, int width
)
5345 item
.m_mask
= wxLIST_MASK_TEXT
| wxLIST_MASK_FORMAT
;
5346 item
.m_text
= heading
;
5349 item
.m_mask
|= wxLIST_MASK_WIDTH
;
5350 item
.m_width
= width
;
5352 item
.m_format
= format
;
5354 return InsertColumn( col
, item
);
5357 bool wxGenericListCtrl::ScrollList( int WXUNUSED(dx
), int WXUNUSED(dy
) )
5363 // fn is a function which takes 3 long arguments: item1, item2, data.
5364 // item1 is the long data associated with a first item (NOT the index).
5365 // item2 is the long data associated with a second item (NOT the index).
5366 // data is the same value as passed to SortItems.
5367 // The return value is a negative number if the first item should precede the second
5368 // item, a positive number of the second item should precede the first,
5369 // or zero if the two items are equivalent.
5370 // data is arbitrary data to be passed to the sort function.
5372 bool wxGenericListCtrl::SortItems( wxListCtrlCompare fn
, long data
)
5374 m_mainWin
->SortItems( fn
, data
);
5378 // ----------------------------------------------------------------------------
5380 // ----------------------------------------------------------------------------
5382 void wxGenericListCtrl::OnSize(wxSizeEvent
& WXUNUSED(event
))
5387 ResizeReportView(m_mainWin
->HasHeader());
5389 m_mainWin
->RecalculatePositions();
5392 void wxGenericListCtrl::ResizeReportView(bool showHeader
)
5395 GetClientSize( &cw
, &ch
);
5399 m_headerWin
->SetSize( 0, 0, cw
, m_headerHeight
);
5400 m_mainWin
->SetSize( 0, m_headerHeight
+ 1, cw
, ch
- m_headerHeight
- 1 );
5402 else // no header window
5404 m_mainWin
->SetSize( 0, 0, cw
, ch
);
5408 void wxGenericListCtrl::OnInternalIdle()
5410 wxWindow::OnInternalIdle();
5412 // do it only if needed
5413 if ( !m_mainWin
->m_dirty
)
5416 m_mainWin
->RecalculatePositions();
5419 // ----------------------------------------------------------------------------
5421 // ----------------------------------------------------------------------------
5423 bool wxGenericListCtrl::SetBackgroundColour( const wxColour
&colour
)
5427 m_mainWin
->SetBackgroundColour( colour
);
5428 m_mainWin
->m_dirty
= true;
5434 bool wxGenericListCtrl::SetForegroundColour( const wxColour
&colour
)
5436 if ( !wxWindow::SetForegroundColour( colour
) )
5441 m_mainWin
->SetForegroundColour( colour
);
5442 m_mainWin
->m_dirty
= true;
5447 m_headerWin
->SetForegroundColour( colour
);
5453 bool wxGenericListCtrl::SetFont( const wxFont
&font
)
5455 if ( !wxWindow::SetFont( font
) )
5460 m_mainWin
->SetFont( font
);
5461 m_mainWin
->m_dirty
= true;
5466 m_headerWin
->SetFont( font
);
5467 CalculateAndSetHeaderHeight();
5478 #include "wx/listbox.h"
5483 wxGenericListCtrl::GetClassDefaultAttributes(wxWindowVariant variant
)
5486 // Use the same color scheme as wxListBox
5487 return wxListBox::GetClassDefaultAttributes(variant
);
5489 wxUnusedVar(variant
);
5490 wxVisualAttributes attr
;
5491 attr
.colFg
= wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT
);
5492 attr
.colBg
= wxSystemSettings::GetColour(wxSYS_COLOUR_LISTBOX
);
5493 attr
.font
= wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT
);
5498 // ----------------------------------------------------------------------------
5499 // methods forwarded to m_mainWin
5500 // ----------------------------------------------------------------------------
5502 #if wxUSE_DRAG_AND_DROP
5504 void wxGenericListCtrl::SetDropTarget( wxDropTarget
*dropTarget
)
5506 m_mainWin
->SetDropTarget( dropTarget
);
5509 wxDropTarget
*wxGenericListCtrl::GetDropTarget() const
5511 return m_mainWin
->GetDropTarget();
5514 #endif // wxUSE_DRAG_AND_DROP
5516 bool wxGenericListCtrl::SetCursor( const wxCursor
&cursor
)
5518 return m_mainWin
? m_mainWin
->wxWindow::SetCursor(cursor
) : false;
5521 wxColour
wxGenericListCtrl::GetBackgroundColour() const
5523 return m_mainWin
? m_mainWin
->GetBackgroundColour() : wxColour();
5526 wxColour
wxGenericListCtrl::GetForegroundColour() const
5528 return m_mainWin
? m_mainWin
->GetForegroundColour() : wxColour();
5531 bool wxGenericListCtrl::DoPopupMenu( wxMenu
*menu
, int x
, int y
)
5534 return m_mainWin
->PopupMenu( menu
, x
, y
);
5537 #endif // wxUSE_MENUS
5540 void wxGenericListCtrl::SetFocus()
5542 /* The test in window.cpp fails as we are a composite
5543 window, so it checks against "this", but not m_mainWin. */
5544 if ( DoFindFocus() != this )
5545 m_mainWin
->SetFocus();
5548 wxSize
wxGenericListCtrl::DoGetBestSize() const
5550 // Something is better than nothing...
5551 // 100x80 is what the MSW version will get from the default
5552 // wxControl::DoGetBestSize
5553 return wxSize(100,80);
5556 // ----------------------------------------------------------------------------
5557 // virtual list control support
5558 // ----------------------------------------------------------------------------
5560 wxString
wxGenericListCtrl::OnGetItemText(long WXUNUSED(item
), long WXUNUSED(col
)) const
5562 // this is a pure virtual function, in fact - which is not really pure
5563 // because the controls which are not virtual don't need to implement it
5564 wxFAIL_MSG( _T("wxGenericListCtrl::OnGetItemText not supposed to be called") );
5566 return wxEmptyString
;
5569 int wxGenericListCtrl::OnGetItemImage(long WXUNUSED(item
)) const
5571 wxCHECK_MSG(!GetImageList(wxIMAGE_LIST_SMALL
),
5573 wxT("List control has an image list, OnGetItemImage should be overridden."));
5578 wxGenericListCtrl::OnGetItemAttr(long WXUNUSED_UNLESS_DEBUG(item
)) const
5580 wxASSERT_MSG( item
>= 0 && item
< GetItemCount(),
5581 _T("invalid item index in OnGetItemAttr()") );
5583 // no attributes by default
5587 void wxGenericListCtrl::SetItemCount(long count
)
5589 wxASSERT_MSG( IsVirtual(), _T("this is for virtual controls only") );
5591 m_mainWin
->SetItemCount(count
);
5594 void wxGenericListCtrl::RefreshItem(long item
)
5596 m_mainWin
->RefreshLine(item
);
5599 void wxGenericListCtrl::RefreshItems(long itemFrom
, long itemTo
)
5601 m_mainWin
->RefreshLines(itemFrom
, itemTo
);
5605 * Generic wxListCtrl is more or less a container for two other
5606 * windows which drawings are done upon. These are namely
5607 * 'm_headerWin' and 'm_mainWin'.
5608 * Here we override 'virtual wxWindow::Refresh()' to mimic the
5609 * behaviour wxListCtrl has under wxMSW.
5611 void wxGenericListCtrl::Refresh(bool eraseBackground
, const wxRect
*rect
)
5615 // The easy case, no rectangle specified.
5617 m_headerWin
->Refresh(eraseBackground
);
5620 m_mainWin
->Refresh(eraseBackground
);
5624 // Refresh the header window
5627 wxRect rectHeader
= m_headerWin
->GetRect();
5628 rectHeader
.Intersect(*rect
);
5629 if (rectHeader
.GetWidth() && rectHeader
.GetHeight())
5632 m_headerWin
->GetPosition(&x
, &y
);
5633 rectHeader
.Offset(-x
, -y
);
5634 m_headerWin
->Refresh(eraseBackground
, &rectHeader
);
5639 // Refresh the main window
5642 wxRect rectMain
= m_mainWin
->GetRect();
5643 rectMain
.Intersect(*rect
);
5644 if (rectMain
.GetWidth() && rectMain
.GetHeight())
5647 m_mainWin
->GetPosition(&x
, &y
);
5648 rectMain
.Offset(-x
, -y
);
5649 m_mainWin
->Refresh(eraseBackground
, &rectMain
);
5655 void wxGenericListCtrl::Freeze()
5657 m_mainWin
->Freeze();
5660 void wxGenericListCtrl::Thaw()
5665 #endif // wxUSE_LISTCTRL