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 // For compilers that support precompilation, includes "wx.h".
27 #include "wx/wxprec.h"
38 #include "wx/dynarray.h"
40 #include "wx/dcscreen.h"
42 #include "wx/textctrl.h"
45 // under Win32 we always use the native version and also may use the generic
46 // one, however some things should be done only if we use only the generic
48 #if defined(__WIN32__) && !defined(__WXUNIVERSAL__)
49 #define HAVE_NATIVE_LISTCTRL
52 // if we have the native control, wx/listctrl.h declares it and not this one
53 #ifdef HAVE_NATIVE_LISTCTRL
54 #include "wx/generic/listctrl.h"
55 #else // !HAVE_NATIVE_LISTCTRL
56 #include "wx/listctrl.h"
58 // if we have a native version, its implementation file does all this
59 IMPLEMENT_DYNAMIC_CLASS(wxListItem
, wxObject
)
60 IMPLEMENT_DYNAMIC_CLASS(wxListView
, wxListCtrl
)
61 IMPLEMENT_DYNAMIC_CLASS(wxListEvent
, wxNotifyEvent
)
63 IMPLEMENT_DYNAMIC_CLASS(wxListCtrl
, wxGenericListCtrl
)
64 #endif // HAVE_NATIVE_LISTCTRL/!HAVE_NATIVE_LISTCTRL
66 #include "wx/selstore.h"
67 #include "wx/renderer.h"
71 #include "wx/mac/private.h"
76 // NOTE: If using the wxListBox visual attributes works everywhere then this can
77 // be removed, as well as the #else case below.
78 #define _USE_VISATTR 0
81 // ----------------------------------------------------------------------------
83 // ----------------------------------------------------------------------------
85 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_BEGIN_DRAG
)
86 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_BEGIN_RDRAG
)
87 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_BEGIN_LABEL_EDIT
)
88 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_END_LABEL_EDIT
)
89 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_DELETE_ITEM
)
90 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_DELETE_ALL_ITEMS
)
91 #if WXWIN_COMPATIBILITY_2_4
92 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_GET_INFO
)
93 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_SET_INFO
)
95 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_ITEM_SELECTED
)
96 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_ITEM_DESELECTED
)
97 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_KEY_DOWN
)
98 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_INSERT_ITEM
)
99 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_COL_CLICK
)
100 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_COL_RIGHT_CLICK
)
101 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_COL_BEGIN_DRAG
)
102 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_COL_DRAGGING
)
103 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_COL_END_DRAG
)
104 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_ITEM_RIGHT_CLICK
)
105 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_ITEM_MIDDLE_CLICK
)
106 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_ITEM_ACTIVATED
)
107 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_ITEM_FOCUSED
)
108 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_CACHE_HINT
)
110 // ----------------------------------------------------------------------------
112 // ----------------------------------------------------------------------------
114 // // the height of the header window (FIXME: should depend on its font!)
115 // static const int HEADER_HEIGHT = 23;
117 static const int SCROLL_UNIT_X
= 15;
119 // the spacing between the lines (in report mode)
120 static const int LINE_SPACING
= 0;
122 // extra margins around the text label
123 static const int EXTRA_WIDTH
= 4;
124 static const int EXTRA_HEIGHT
= 4;
126 // margin between the window and the items
127 static const int EXTRA_BORDER_X
= 2;
128 static const int EXTRA_BORDER_Y
= 2;
130 // offset for the header window
131 static const int HEADER_OFFSET_X
= 1;
132 static const int HEADER_OFFSET_Y
= 1;
134 // margin between rows of icons in [small] icon view
135 static const int MARGIN_BETWEEN_ROWS
= 6;
137 // when autosizing the columns, add some slack
138 static const int AUTOSIZE_COL_MARGIN
= 10;
140 // default width for the header columns
141 static const int WIDTH_COL_DEFAULT
= 80;
143 // the space between the image and the text in the report mode
144 static const int IMAGE_MARGIN_IN_REPORT_MODE
= 5;
146 // ============================================================================
148 // ============================================================================
150 //-----------------------------------------------------------------------------
151 // wxColWidthInfo (internal)
152 //-----------------------------------------------------------------------------
154 struct wxColWidthInfo
157 bool bNeedsUpdate
; // only set to true when an item whose
158 // width == nMaxWidth is removed
160 wxColWidthInfo(int w
= 0, bool needsUpdate
= false)
163 bNeedsUpdate
= needsUpdate
;
167 WX_DEFINE_ARRAY_PTR(wxColWidthInfo
*, ColWidthArray
);
169 //-----------------------------------------------------------------------------
170 // wxListItemData (internal)
171 //-----------------------------------------------------------------------------
173 class WXDLLEXPORT wxListItemData
176 wxListItemData(wxListMainWindow
*owner
);
179 void SetItem( const wxListItem
&info
);
180 void SetImage( int image
) { m_image
= image
; }
181 void SetData( wxUIntPtr data
) { m_data
= data
; }
182 void SetPosition( int x
, int y
);
183 void SetSize( int width
, int height
);
185 bool HasText() const { return !m_text
.empty(); }
186 const wxString
& GetText() const { return m_text
; }
187 void SetText(const wxString
& text
) { m_text
= text
; }
189 // we can't use empty string for measuring the string width/height, so
190 // always return something
191 wxString
GetTextForMeasuring() const
193 wxString s
= GetText();
200 bool IsHit( int x
, int y
) const;
204 int GetWidth() const;
205 int GetHeight() const;
207 int GetImage() const { return m_image
; }
208 bool HasImage() const { return GetImage() != -1; }
210 void GetItem( wxListItem
&info
) const;
212 void SetAttr(wxListItemAttr
*attr
) { m_attr
= attr
; }
213 wxListItemAttr
*GetAttr() const { return m_attr
; }
216 // the item image or -1
219 // user data associated with the item
222 // the item coordinates are not used in report mode, instead this pointer
223 // is NULL and the owner window is used to retrieve the item position and
227 // the list ctrl we are in
228 wxListMainWindow
*m_owner
;
230 // custom attributes or NULL
231 wxListItemAttr
*m_attr
;
234 // common part of all ctors
240 //-----------------------------------------------------------------------------
241 // wxListHeaderData (internal)
242 //-----------------------------------------------------------------------------
244 class WXDLLEXPORT wxListHeaderData
: public wxObject
248 wxListHeaderData( const wxListItem
&info
);
249 void SetItem( const wxListItem
&item
);
250 void SetPosition( int x
, int y
);
251 void SetWidth( int w
);
252 void SetFormat( int format
);
253 void SetHeight( int h
);
254 bool HasImage() const;
256 bool HasText() const { return !m_text
.empty(); }
257 const wxString
& GetText() const { return m_text
; }
258 void SetText(const wxString
& text
) { m_text
= text
; }
260 void GetItem( wxListItem
&item
);
262 bool IsHit( int x
, int y
) const;
263 int GetImage() const;
264 int GetWidth() const;
265 int GetFormat() const;
281 //-----------------------------------------------------------------------------
282 // wxListLineData (internal)
283 //-----------------------------------------------------------------------------
285 WX_DECLARE_LIST(wxListItemData
, wxListItemDataList
);
286 #include "wx/listimpl.cpp"
287 WX_DEFINE_LIST(wxListItemDataList
)
292 // the list of subitems: only may have more than one item in report mode
293 wxListItemDataList m_items
;
295 // this is not used in report view
307 // the part to be highlighted
308 wxRect m_rectHighlight
;
310 // extend all our rects to be centered inside the one of given width
311 void ExtendWidth(wxCoord w
)
313 wxASSERT_MSG( m_rectAll
.width
<= w
,
314 _T("width can only be increased") );
317 m_rectLabel
.x
= m_rectAll
.x
+ (w
- m_rectLabel
.width
)/2;
318 m_rectIcon
.x
= m_rectAll
.x
+ (w
- m_rectIcon
.width
)/2;
319 m_rectHighlight
.x
= m_rectAll
.x
+ (w
- m_rectHighlight
.width
)/2;
323 // is this item selected? [NB: not used in virtual mode]
326 // back pointer to the list ctrl
327 wxListMainWindow
*m_owner
;
330 wxListLineData(wxListMainWindow
*owner
);
334 WX_CLEAR_LIST(wxListItemDataList
, m_items
);
338 // are we in report mode?
339 inline bool InReportView() const;
341 // are we in virtual report mode?
342 inline bool IsVirtual() const;
344 // these 2 methods shouldn't be called for report view controls, in that
345 // case we determine our position/size ourselves
347 // calculate the size of the line
348 void CalculateSize( wxDC
*dc
, int spacing
);
350 // remember the position this line appears at
351 void SetPosition( int x
, int y
, int spacing
);
355 void SetImage( int image
) { SetImage(0, image
); }
356 int GetImage() const { return GetImage(0); }
357 bool HasImage() const { return GetImage() != -1; }
358 bool HasText() const { return !GetText(0).empty(); }
360 void SetItem( int index
, const wxListItem
&info
);
361 void GetItem( int index
, wxListItem
&info
);
363 wxString
GetText(int index
) const;
364 void SetText( int index
, const wxString
& s
);
366 wxListItemAttr
*GetAttr() const;
367 void SetAttr(wxListItemAttr
*attr
);
369 // return true if the highlighting really changed
370 bool Highlight( bool on
);
372 void ReverseHighlight();
374 bool IsHighlighted() const
376 wxASSERT_MSG( !IsVirtual(), _T("unexpected call to IsHighlighted") );
378 return m_highlighted
;
381 // draw the line on the given DC in icon/list mode
382 void Draw( wxDC
*dc
);
384 // the same in report mode
385 void DrawInReportMode( wxDC
*dc
,
387 const wxRect
& rectHL
,
391 // set the line to contain num items (only can be > 1 in report mode)
392 void InitItems( int num
);
394 // get the mode (i.e. style) of the list control
395 inline int GetMode() const;
397 // prepare the DC for drawing with these item's attributes, return true if
398 // we need to draw the items background to highlight it, false otherwise
399 bool SetAttributes(wxDC
*dc
,
400 const wxListItemAttr
*attr
,
403 // draw the text on the DC with the correct justification; also add an
404 // ellipsis if the text is too large to fit in the current width
405 void DrawTextFormatted(wxDC
*dc
, const wxString
&text
, int col
, int x
, int y
, int width
);
407 // these are only used by GetImage/SetImage above, we don't support images
408 // with subitems at the public API level yet
409 void SetImage( int index
, int image
);
410 int GetImage( int index
) const;
413 WX_DECLARE_EXPORTED_OBJARRAY(wxListLineData
, wxListLineDataArray
);
414 #include "wx/arrimpl.cpp"
415 WX_DEFINE_OBJARRAY(wxListLineDataArray
)
417 //-----------------------------------------------------------------------------
418 // wxListHeaderWindow (internal)
419 //-----------------------------------------------------------------------------
421 class WXDLLEXPORT wxListHeaderWindow
: public wxWindow
424 wxListMainWindow
*m_owner
;
425 wxCursor
*m_currentCursor
;
426 wxCursor
*m_resizeCursor
;
429 // column being resized or -1
432 // divider line position in logical (unscrolled) coords
435 // minimal position beyond which the divider line can't be dragged in
440 wxListHeaderWindow();
442 wxListHeaderWindow( wxWindow
*win
,
444 wxListMainWindow
*owner
,
445 const wxPoint
&pos
= wxDefaultPosition
,
446 const wxSize
&size
= wxDefaultSize
,
448 const wxString
&name
= wxT("wxlistctrlcolumntitles") );
450 virtual ~wxListHeaderWindow();
453 void AdjustDC(wxDC
& dc
);
455 void OnPaint( wxPaintEvent
&event
);
456 void OnMouse( wxMouseEvent
&event
);
457 void OnSetFocus( wxFocusEvent
&event
);
463 // common part of all ctors
466 // generate and process the list event of the given type, return true if
467 // it wasn't vetoed, i.e. if we should proceed
468 bool SendListEvent(wxEventType type
, const wxPoint
& pos
);
470 DECLARE_DYNAMIC_CLASS(wxListHeaderWindow
)
471 DECLARE_EVENT_TABLE()
474 //-----------------------------------------------------------------------------
475 // wxListRenameTimer (internal)
476 //-----------------------------------------------------------------------------
478 class WXDLLEXPORT wxListRenameTimer
: public wxTimer
481 wxListMainWindow
*m_owner
;
484 wxListRenameTimer( wxListMainWindow
*owner
);
488 //-----------------------------------------------------------------------------
489 // wxListTextCtrl (internal)
490 //-----------------------------------------------------------------------------
492 class WXDLLEXPORT wxListTextCtrl
: public wxTextCtrl
495 wxListTextCtrl(wxListMainWindow
*owner
, size_t itemEdit
);
498 void OnChar( wxKeyEvent
&event
);
499 void OnKeyUp( wxKeyEvent
&event
);
500 void OnKillFocus( wxFocusEvent
&event
);
502 bool AcceptChanges();
506 wxListMainWindow
*m_owner
;
507 wxString m_startValue
;
510 bool m_aboutToFinish
;
512 DECLARE_EVENT_TABLE()
515 //-----------------------------------------------------------------------------
516 // wxListMainWindow (internal)
517 //-----------------------------------------------------------------------------
519 WX_DECLARE_LIST(wxListHeaderData
, wxListHeaderDataList
);
520 #include "wx/listimpl.cpp"
521 WX_DEFINE_LIST(wxListHeaderDataList
)
523 class wxListMainWindow
: public wxScrolledWindow
527 wxListMainWindow( wxWindow
*parent
,
529 const wxPoint
& pos
= wxDefaultPosition
,
530 const wxSize
& size
= wxDefaultSize
,
532 const wxString
&name
= _T("listctrlmainwindow") );
534 virtual ~wxListMainWindow();
536 wxWindow
*GetMainWindowOfCompositeControl() { return GetParent(); }
538 bool HasFlag(int flag
) const { return m_parent
->HasFlag(flag
); }
540 // return true if this is a virtual list control
541 bool IsVirtual() const { return HasFlag(wxLC_VIRTUAL
); }
543 // return true if the control is in report mode
544 bool InReportView() const { return HasFlag(wxLC_REPORT
); }
546 // return true if we are in single selection mode, false if multi sel
547 bool IsSingleSel() const { return HasFlag(wxLC_SINGLE_SEL
); }
549 // do we have a header window?
550 bool HasHeader() const
551 { return InReportView() && !HasFlag(wxLC_NO_HEADER
); }
553 void HighlightAll( bool on
);
555 // all these functions only do something if the line is currently visible
557 // change the line "selected" state, return true if it really changed
558 bool HighlightLine( size_t line
, bool highlight
= true);
560 // as HighlightLine() but do it for the range of lines: this is incredibly
561 // more efficient for virtual list controls!
563 // NB: unlike HighlightLine() this one does refresh the lines on screen
564 void HighlightLines( size_t lineFrom
, size_t lineTo
, bool on
= true );
566 // toggle the line state and refresh it
567 void ReverseHighlight( size_t line
)
568 { HighlightLine(line
, !IsHighlighted(line
)); RefreshLine(line
); }
570 // return true if the line is highlighted
571 bool IsHighlighted(size_t line
) const;
573 // refresh one or several lines at once
574 void RefreshLine( size_t line
);
575 void RefreshLines( size_t lineFrom
, size_t lineTo
);
577 // refresh all selected items
578 void RefreshSelected();
580 // refresh all lines below the given one: the difference with
581 // RefreshLines() is that the index here might not be a valid one (happens
582 // when the last line is deleted)
583 void RefreshAfter( size_t lineFrom
);
585 // the methods which are forwarded to wxListLineData itself in list/icon
586 // modes but are here because the lines don't store their positions in the
589 // get the bound rect for the entire line
590 wxRect
GetLineRect(size_t line
) const;
592 // get the bound rect of the label
593 wxRect
GetLineLabelRect(size_t line
) const;
595 // get the bound rect of the items icon (only may be called if we do have
597 wxRect
GetLineIconRect(size_t line
) const;
599 // get the rect to be highlighted when the item has focus
600 wxRect
GetLineHighlightRect(size_t line
) const;
602 // get the size of the total line rect
603 wxSize
GetLineSize(size_t line
) const
604 { return GetLineRect(line
).GetSize(); }
606 // return the hit code for the corresponding position (in this line)
607 long HitTestLine(size_t line
, int x
, int y
) const;
609 // bring the selected item into view, scrolling to it if necessary
610 void MoveToItem(size_t item
);
612 // bring the current item into view
613 void MoveToFocus() { MoveToItem(m_current
); }
615 // start editing the label of the given item
616 void EditLabel( long item
);
618 // suspend/resume redrawing the control
622 void OnRenameTimer();
623 bool OnRenameAccept(size_t itemEdit
, const wxString
& value
);
624 void OnRenameCancelled(size_t itemEdit
);
626 void OnMouse( wxMouseEvent
&event
);
628 // called to switch the selection from the current item to newCurrent,
629 void OnArrowChar( size_t newCurrent
, const wxKeyEvent
& event
);
631 void OnChar( wxKeyEvent
&event
);
632 void OnKeyDown( wxKeyEvent
&event
);
633 void OnSetFocus( wxFocusEvent
&event
);
634 void OnKillFocus( wxFocusEvent
&event
);
635 void OnScroll(wxScrollWinEvent
& event
) ;
637 void OnPaint( wxPaintEvent
&event
);
639 void DrawImage( int index
, wxDC
*dc
, int x
, int y
);
640 void GetImageSize( int index
, int &width
, int &height
) const;
641 int GetTextLength( const wxString
&s
) const;
643 void SetImageList( wxImageListType
*imageList
, int which
);
644 void SetItemSpacing( int spacing
, bool isSmall
= false );
645 int GetItemSpacing( bool isSmall
= false );
647 void SetColumn( int col
, wxListItem
&item
);
648 void SetColumnWidth( int col
, int width
);
649 void GetColumn( int col
, wxListItem
&item
) const;
650 int GetColumnWidth( int col
) const;
651 int GetColumnCount() const { return m_columns
.GetCount(); }
653 // returns the sum of the heights of all columns
654 int GetHeaderWidth() const;
656 int GetCountPerPage() const;
658 void SetItem( wxListItem
&item
);
659 void GetItem( wxListItem
&item
) const;
660 void SetItemState( long item
, long state
, long stateMask
);
661 void SetItemStateAll( long state
, long stateMask
);
662 int GetItemState( long item
, long stateMask
) const;
663 void GetItemRect( long index
, wxRect
&rect
) const;
664 wxRect
GetViewRect() const;
665 bool GetItemPosition( long item
, wxPoint
& pos
) const;
666 int GetSelectedItemCount() const;
668 wxString
GetItemText(long item
) const
671 info
.m_mask
= wxLIST_MASK_TEXT
;
672 info
.m_itemId
= item
;
677 void SetItemText(long item
, const wxString
& value
)
680 info
.m_mask
= wxLIST_MASK_TEXT
;
681 info
.m_itemId
= item
;
686 // set the scrollbars and update the positions of the items
687 void RecalculatePositions(bool noRefresh
= false);
689 // refresh the window and the header
692 long GetNextItem( long item
, int geometry
, int state
) const;
693 void DeleteItem( long index
);
694 void DeleteAllItems();
695 void DeleteColumn( int col
);
696 void DeleteEverything();
697 void EnsureVisible( long index
);
698 long FindItem( long start
, const wxString
& str
, bool partial
= false );
699 long FindItem( long start
, wxUIntPtr data
);
700 long FindItem( const wxPoint
& pt
);
701 long HitTest( int x
, int y
, int &flags
);
702 void InsertItem( wxListItem
&item
);
703 void InsertColumn( long col
, wxListItem
&item
);
704 int GetItemWidthWithImage(wxListItem
* item
);
705 void SortItems( wxListCtrlCompare fn
, long data
);
707 size_t GetItemCount() const;
708 bool IsEmpty() const { return GetItemCount() == 0; }
709 void SetItemCount(long count
);
711 // change the current (== focused) item, send a notification event
712 void ChangeCurrent(size_t current
);
713 void ResetCurrent() { ChangeCurrent((size_t)-1); }
714 bool HasCurrent() const { return m_current
!= (size_t)-1; }
716 // send out a wxListEvent
717 void SendNotify( size_t line
,
719 const wxPoint
& point
= wxDefaultPosition
);
721 // override base class virtual to reset m_lineHeight when the font changes
722 virtual bool SetFont(const wxFont
& font
)
724 if ( !wxScrolledWindow::SetFont(font
) )
732 // these are for wxListLineData usage only
734 // get the backpointer to the list ctrl
735 wxGenericListCtrl
*GetListCtrl() const
737 return wxStaticCast(GetParent(), wxGenericListCtrl
);
740 // get the height of all lines (assuming they all do have the same height)
741 wxCoord
GetLineHeight() const;
743 // get the y position of the given line (only for report view)
744 wxCoord
GetLineY(size_t line
) const;
746 // get the brush to use for the item highlighting
747 wxBrush
*GetHighlightBrush() const
749 return m_hasFocus
? m_highlightBrush
: m_highlightUnfocusedBrush
;
753 // the array of all line objects for a non virtual list control (for the
754 // virtual list control we only ever use m_lines[0])
755 wxListLineDataArray m_lines
;
757 // the list of column objects
758 wxListHeaderDataList m_columns
;
760 // currently focused item or -1
763 // the number of lines per page
766 // this flag is set when something which should result in the window
767 // redrawing happens (i.e. an item was added or deleted, or its appearance
768 // changed) and OnPaint() doesn't redraw the window while it is set which
769 // allows to minimize the number of repaintings when a lot of items are
770 // being added. The real repainting occurs only after the next OnIdle()
774 wxColour
*m_highlightColour
;
775 wxImageListType
*m_small_image_list
;
776 wxImageListType
*m_normal_image_list
;
778 int m_normal_spacing
;
782 wxTimer
*m_renameTimer
;
786 ColWidthArray m_aColWidths
;
788 // for double click logic
789 size_t m_lineLastClicked
,
790 m_lineBeforeLastClicked
,
791 m_lineSelectSingleOnUp
;
794 // the total count of items in a virtual list control
797 // the object maintaining the items selection state, only used in virtual
799 wxSelectionStore m_selStore
;
801 // common part of all ctors
804 // get the line data for the given index
805 wxListLineData
*GetLine(size_t n
) const
807 wxASSERT_MSG( n
!= (size_t)-1, _T("invalid line index") );
811 wxConstCast(this, wxListMainWindow
)->CacheLineData(n
);
819 // get a dummy line which can be used for geometry calculations and such:
820 // you must use GetLine() if you want to really draw the line
821 wxListLineData
*GetDummyLine() const;
823 // cache the line data of the n-th line in m_lines[0]
824 void CacheLineData(size_t line
);
826 // get the range of visible lines
827 void GetVisibleLinesRange(size_t *from
, size_t *to
);
829 // force us to recalculate the range of visible lines
830 void ResetVisibleLinesRange() { m_lineFrom
= (size_t)-1; }
832 // get the colour to be used for drawing the rules
833 wxColour
GetRuleColour() const
835 return wxSystemSettings::GetColour(wxSYS_COLOUR_3DLIGHT
);
839 // initialize the current item if needed
840 void UpdateCurrent();
842 // delete all items but don't refresh: called from dtor
843 void DoDeleteAllItems();
845 // the height of one line using the current font
846 wxCoord m_lineHeight
;
848 // the total header width or 0 if not calculated yet
849 wxCoord m_headerWidth
;
851 // the first and last lines being shown on screen right now (inclusive),
852 // both may be -1 if they must be calculated so never access them directly:
853 // use GetVisibleLinesRange() above instead
857 // the brushes to use for item highlighting when we do/don't have focus
858 wxBrush
*m_highlightBrush
,
859 *m_highlightUnfocusedBrush
;
861 // if this is > 0, the control is frozen and doesn't redraw itself
862 size_t m_freezeCount
;
864 DECLARE_DYNAMIC_CLASS(wxListMainWindow
)
865 DECLARE_EVENT_TABLE()
867 friend class wxGenericListCtrl
;
870 // ============================================================================
872 // ============================================================================
874 //-----------------------------------------------------------------------------
876 //-----------------------------------------------------------------------------
878 wxListItemData::~wxListItemData()
880 // in the virtual list control the attributes are managed by the main
881 // program, so don't delete them
882 if ( !m_owner
->IsVirtual() )
890 void wxListItemData::Init()
898 wxListItemData::wxListItemData(wxListMainWindow
*owner
)
904 if ( owner
->InReportView() )
914 void wxListItemData::SetItem( const wxListItem
&info
)
916 if ( info
.m_mask
& wxLIST_MASK_TEXT
)
917 SetText(info
.m_text
);
918 if ( info
.m_mask
& wxLIST_MASK_IMAGE
)
919 m_image
= info
.m_image
;
920 if ( info
.m_mask
& wxLIST_MASK_DATA
)
921 m_data
= info
.m_data
;
923 if ( info
.HasAttributes() )
926 *m_attr
= *info
.GetAttributes();
928 m_attr
= new wxListItemAttr(*info
.GetAttributes());
936 m_rect
->width
= info
.m_width
;
940 void wxListItemData::SetPosition( int x
, int y
)
942 wxCHECK_RET( m_rect
, _T("unexpected SetPosition() call") );
948 void wxListItemData::SetSize( int width
, int height
)
950 wxCHECK_RET( m_rect
, _T("unexpected SetSize() call") );
953 m_rect
->width
= width
;
955 m_rect
->height
= height
;
958 bool wxListItemData::IsHit( int x
, int y
) const
960 wxCHECK_MSG( m_rect
, false, _T("can't be called in this mode") );
962 return wxRect(GetX(), GetY(), GetWidth(), GetHeight()).Inside(x
, y
);
965 int wxListItemData::GetX() const
967 wxCHECK_MSG( m_rect
, 0, _T("can't be called in this mode") );
972 int wxListItemData::GetY() const
974 wxCHECK_MSG( m_rect
, 0, _T("can't be called in this mode") );
979 int wxListItemData::GetWidth() const
981 wxCHECK_MSG( m_rect
, 0, _T("can't be called in this mode") );
983 return m_rect
->width
;
986 int wxListItemData::GetHeight() const
988 wxCHECK_MSG( m_rect
, 0, _T("can't be called in this mode") );
990 return m_rect
->height
;
993 void wxListItemData::GetItem( wxListItem
&info
) const
995 long mask
= info
.m_mask
;
998 // by default, get everything for backwards compatibility
1002 if ( mask
& wxLIST_MASK_TEXT
)
1003 info
.m_text
= m_text
;
1004 if ( mask
& wxLIST_MASK_IMAGE
)
1005 info
.m_image
= m_image
;
1006 if ( mask
& wxLIST_MASK_DATA
)
1007 info
.m_data
= m_data
;
1011 if ( m_attr
->HasTextColour() )
1012 info
.SetTextColour(m_attr
->GetTextColour());
1013 if ( m_attr
->HasBackgroundColour() )
1014 info
.SetBackgroundColour(m_attr
->GetBackgroundColour());
1015 if ( m_attr
->HasFont() )
1016 info
.SetFont(m_attr
->GetFont());
1020 //-----------------------------------------------------------------------------
1022 //-----------------------------------------------------------------------------
1024 void wxListHeaderData::Init()
1035 wxListHeaderData::wxListHeaderData()
1040 wxListHeaderData::wxListHeaderData( const wxListItem
&item
)
1047 void wxListHeaderData::SetItem( const wxListItem
&item
)
1049 m_mask
= item
.m_mask
;
1051 if ( m_mask
& wxLIST_MASK_TEXT
)
1052 m_text
= item
.m_text
;
1054 if ( m_mask
& wxLIST_MASK_IMAGE
)
1055 m_image
= item
.m_image
;
1057 if ( m_mask
& wxLIST_MASK_FORMAT
)
1058 m_format
= item
.m_format
;
1060 if ( m_mask
& wxLIST_MASK_WIDTH
)
1061 SetWidth(item
.m_width
);
1064 void wxListHeaderData::SetPosition( int x
, int y
)
1070 void wxListHeaderData::SetHeight( int h
)
1075 void wxListHeaderData::SetWidth( int w
)
1077 m_width
= w
< 0 ? WIDTH_COL_DEFAULT
: w
;
1080 void wxListHeaderData::SetFormat( int format
)
1085 bool wxListHeaderData::HasImage() const
1087 return m_image
!= -1;
1090 bool wxListHeaderData::IsHit( int x
, int y
) const
1092 return ((x
>= m_xpos
) && (x
<= m_xpos
+m_width
) && (y
>= m_ypos
) && (y
<= m_ypos
+m_height
));
1095 void wxListHeaderData::GetItem( wxListItem
& item
)
1097 item
.m_mask
= m_mask
;
1098 item
.m_text
= m_text
;
1099 item
.m_image
= m_image
;
1100 item
.m_format
= m_format
;
1101 item
.m_width
= m_width
;
1104 int wxListHeaderData::GetImage() const
1109 int wxListHeaderData::GetWidth() const
1114 int wxListHeaderData::GetFormat() const
1119 //-----------------------------------------------------------------------------
1121 //-----------------------------------------------------------------------------
1123 inline int wxListLineData::GetMode() const
1125 return m_owner
->GetListCtrl()->GetWindowStyleFlag() & wxLC_MASK_TYPE
;
1128 inline bool wxListLineData::InReportView() const
1130 return m_owner
->HasFlag(wxLC_REPORT
);
1133 inline bool wxListLineData::IsVirtual() const
1135 return m_owner
->IsVirtual();
1138 wxListLineData::wxListLineData( wxListMainWindow
*owner
)
1142 if ( InReportView() )
1148 m_gi
= new GeometryInfo
;
1151 m_highlighted
= false;
1153 InitItems( GetMode() == wxLC_REPORT
? m_owner
->GetColumnCount() : 1 );
1156 void wxListLineData::CalculateSize( wxDC
*dc
, int spacing
)
1158 wxListItemDataList::compatibility_iterator node
= m_items
.GetFirst();
1159 wxCHECK_RET( node
, _T("no subitems at all??") );
1161 wxListItemData
*item
= node
->GetData();
1166 switch ( GetMode() )
1169 case wxLC_SMALL_ICON
:
1170 m_gi
->m_rectAll
.width
= spacing
;
1172 s
= item
->GetText();
1177 m_gi
->m_rectLabel
.width
=
1178 m_gi
->m_rectLabel
.height
= 0;
1182 dc
->GetTextExtent( s
, &lw
, &lh
);
1186 m_gi
->m_rectAll
.height
= spacing
+ lh
;
1188 m_gi
->m_rectAll
.width
= lw
;
1190 m_gi
->m_rectLabel
.width
= lw
;
1191 m_gi
->m_rectLabel
.height
= lh
;
1194 if (item
->HasImage())
1197 m_owner
->GetImageSize( item
->GetImage(), w
, h
);
1198 m_gi
->m_rectIcon
.width
= w
+ 8;
1199 m_gi
->m_rectIcon
.height
= h
+ 8;
1201 if ( m_gi
->m_rectIcon
.width
> m_gi
->m_rectAll
.width
)
1202 m_gi
->m_rectAll
.width
= m_gi
->m_rectIcon
.width
;
1203 if ( m_gi
->m_rectIcon
.height
+ lh
> m_gi
->m_rectAll
.height
- 4 )
1204 m_gi
->m_rectAll
.height
= m_gi
->m_rectIcon
.height
+ lh
+ 4;
1207 if ( item
->HasText() )
1209 m_gi
->m_rectHighlight
.width
= m_gi
->m_rectLabel
.width
;
1210 m_gi
->m_rectHighlight
.height
= m_gi
->m_rectLabel
.height
;
1212 else // no text, highlight the icon
1214 m_gi
->m_rectHighlight
.width
= m_gi
->m_rectIcon
.width
;
1215 m_gi
->m_rectHighlight
.height
= m_gi
->m_rectIcon
.height
;
1220 s
= item
->GetTextForMeasuring();
1222 dc
->GetTextExtent( s
, &lw
, &lh
);
1226 m_gi
->m_rectLabel
.width
= lw
;
1227 m_gi
->m_rectLabel
.height
= lh
;
1229 m_gi
->m_rectAll
.width
= lw
;
1230 m_gi
->m_rectAll
.height
= lh
;
1232 if (item
->HasImage())
1235 m_owner
->GetImageSize( item
->GetImage(), w
, h
);
1236 m_gi
->m_rectIcon
.width
= w
;
1237 m_gi
->m_rectIcon
.height
= h
;
1239 m_gi
->m_rectAll
.width
+= 4 + w
;
1240 if (h
> m_gi
->m_rectAll
.height
)
1241 m_gi
->m_rectAll
.height
= h
;
1244 m_gi
->m_rectHighlight
.width
= m_gi
->m_rectAll
.width
;
1245 m_gi
->m_rectHighlight
.height
= m_gi
->m_rectAll
.height
;
1249 wxFAIL_MSG( _T("unexpected call to SetSize") );
1253 wxFAIL_MSG( _T("unknown mode") );
1257 void wxListLineData::SetPosition( int x
, int y
, int spacing
)
1259 wxListItemDataList::compatibility_iterator node
= m_items
.GetFirst();
1260 wxCHECK_RET( node
, _T("no subitems at all??") );
1262 wxListItemData
*item
= node
->GetData();
1264 switch ( GetMode() )
1267 case wxLC_SMALL_ICON
:
1268 m_gi
->m_rectAll
.x
= x
;
1269 m_gi
->m_rectAll
.y
= y
;
1271 if ( item
->HasImage() )
1273 m_gi
->m_rectIcon
.x
= m_gi
->m_rectAll
.x
+ 4 +
1274 (m_gi
->m_rectAll
.width
- m_gi
->m_rectIcon
.width
) / 2;
1275 m_gi
->m_rectIcon
.y
= m_gi
->m_rectAll
.y
+ 4;
1278 if ( item
->HasText() )
1280 if (m_gi
->m_rectAll
.width
> spacing
)
1281 m_gi
->m_rectLabel
.x
= m_gi
->m_rectAll
.x
+ 2;
1283 m_gi
->m_rectLabel
.x
= m_gi
->m_rectAll
.x
+ 2 + (spacing
/2) - (m_gi
->m_rectLabel
.width
/2);
1284 m_gi
->m_rectLabel
.y
= m_gi
->m_rectAll
.y
+ m_gi
->m_rectAll
.height
+ 2 - m_gi
->m_rectLabel
.height
;
1285 m_gi
->m_rectHighlight
.x
= m_gi
->m_rectLabel
.x
- 2;
1286 m_gi
->m_rectHighlight
.y
= m_gi
->m_rectLabel
.y
- 2;
1288 else // no text, highlight the icon
1290 m_gi
->m_rectHighlight
.x
= m_gi
->m_rectIcon
.x
- 4;
1291 m_gi
->m_rectHighlight
.y
= m_gi
->m_rectIcon
.y
- 4;
1296 m_gi
->m_rectAll
.x
= x
;
1297 m_gi
->m_rectAll
.y
= y
;
1299 m_gi
->m_rectHighlight
.x
= m_gi
->m_rectAll
.x
;
1300 m_gi
->m_rectHighlight
.y
= m_gi
->m_rectAll
.y
;
1301 m_gi
->m_rectLabel
.y
= m_gi
->m_rectAll
.y
+ 2;
1303 if (item
->HasImage())
1305 m_gi
->m_rectIcon
.x
= m_gi
->m_rectAll
.x
+ 2;
1306 m_gi
->m_rectIcon
.y
= m_gi
->m_rectAll
.y
+ 2;
1307 m_gi
->m_rectLabel
.x
= m_gi
->m_rectAll
.x
+ 6 + m_gi
->m_rectIcon
.width
;
1311 m_gi
->m_rectLabel
.x
= m_gi
->m_rectAll
.x
+ 2;
1316 wxFAIL_MSG( _T("unexpected call to SetPosition") );
1320 wxFAIL_MSG( _T("unknown mode") );
1324 void wxListLineData::InitItems( int num
)
1326 for (int i
= 0; i
< num
; i
++)
1327 m_items
.Append( new wxListItemData(m_owner
) );
1330 void wxListLineData::SetItem( int index
, const wxListItem
&info
)
1332 wxListItemDataList::compatibility_iterator node
= m_items
.Item( index
);
1333 wxCHECK_RET( node
, _T("invalid column index in SetItem") );
1335 wxListItemData
*item
= node
->GetData();
1336 item
->SetItem( info
);
1339 void wxListLineData::GetItem( int index
, wxListItem
&info
)
1341 wxListItemDataList::compatibility_iterator node
= m_items
.Item( index
);
1344 wxListItemData
*item
= node
->GetData();
1345 item
->GetItem( info
);
1349 wxString
wxListLineData::GetText(int index
) const
1353 wxListItemDataList::compatibility_iterator node
= m_items
.Item( index
);
1356 wxListItemData
*item
= node
->GetData();
1357 s
= item
->GetText();
1363 void wxListLineData::SetText( int index
, const wxString
& s
)
1365 wxListItemDataList::compatibility_iterator node
= m_items
.Item( index
);
1368 wxListItemData
*item
= node
->GetData();
1373 void wxListLineData::SetImage( int index
, int image
)
1375 wxListItemDataList::compatibility_iterator node
= m_items
.Item( index
);
1376 wxCHECK_RET( node
, _T("invalid column index in SetImage()") );
1378 wxListItemData
*item
= node
->GetData();
1379 item
->SetImage(image
);
1382 int wxListLineData::GetImage( int index
) const
1384 wxListItemDataList::compatibility_iterator node
= m_items
.Item( index
);
1385 wxCHECK_MSG( node
, -1, _T("invalid column index in GetImage()") );
1387 wxListItemData
*item
= node
->GetData();
1388 return item
->GetImage();
1391 wxListItemAttr
*wxListLineData::GetAttr() const
1393 wxListItemDataList::compatibility_iterator node
= m_items
.GetFirst();
1394 wxCHECK_MSG( node
, NULL
, _T("invalid column index in GetAttr()") );
1396 wxListItemData
*item
= node
->GetData();
1397 return item
->GetAttr();
1400 void wxListLineData::SetAttr(wxListItemAttr
*attr
)
1402 wxListItemDataList::compatibility_iterator node
= m_items
.GetFirst();
1403 wxCHECK_RET( node
, _T("invalid column index in SetAttr()") );
1405 wxListItemData
*item
= node
->GetData();
1406 item
->SetAttr(attr
);
1409 bool wxListLineData::SetAttributes(wxDC
*dc
,
1410 const wxListItemAttr
*attr
,
1413 wxWindow
*listctrl
= m_owner
->GetParent();
1417 // don't use foreground colour for drawing highlighted items - this might
1418 // make them completely invisible (and there is no way to do bit
1419 // arithmetics on wxColour, unfortunately)
1423 colText
= wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHTTEXT
);
1427 if ( attr
&& attr
->HasTextColour() )
1429 colText
= attr
->GetTextColour();
1433 colText
= listctrl
->GetForegroundColour();
1437 dc
->SetTextForeground(colText
);
1441 if ( attr
&& attr
->HasFont() )
1443 font
= attr
->GetFont();
1447 font
= listctrl
->GetFont();
1453 bool hasBgCol
= attr
&& attr
->HasBackgroundColour();
1454 if ( highlighted
|| hasBgCol
)
1458 dc
->SetBrush( *m_owner
->GetHighlightBrush() );
1462 dc
->SetBrush(wxBrush(attr
->GetBackgroundColour(), wxSOLID
));
1465 dc
->SetPen( *wxTRANSPARENT_PEN
);
1473 void wxListLineData::Draw( wxDC
*dc
)
1475 wxListItemDataList::compatibility_iterator node
= m_items
.GetFirst();
1476 wxCHECK_RET( node
, _T("no subitems at all??") );
1478 bool highlighted
= IsHighlighted();
1480 wxListItemAttr
*attr
= GetAttr();
1482 if ( SetAttributes(dc
, attr
, highlighted
) )
1484 dc
->DrawRectangle( m_gi
->m_rectHighlight
);
1487 // just for debugging to better see where the items are
1489 dc
->SetPen(*wxRED_PEN
);
1490 dc
->SetBrush(*wxTRANSPARENT_BRUSH
);
1491 dc
->DrawRectangle( m_gi
->m_rectAll
);
1492 dc
->SetPen(*wxGREEN_PEN
);
1493 dc
->DrawRectangle( m_gi
->m_rectIcon
);
1496 wxListItemData
*item
= node
->GetData();
1497 if (item
->HasImage())
1499 // centre the image inside our rectangle, this looks nicer when items
1500 // ae aligned in a row
1501 const wxRect
& rectIcon
= m_gi
->m_rectIcon
;
1503 m_owner
->DrawImage(item
->GetImage(), dc
, rectIcon
.x
, rectIcon
.y
);
1506 if (item
->HasText())
1508 const wxRect
& rectLabel
= m_gi
->m_rectLabel
;
1510 wxDCClipper
clipper(*dc
, rectLabel
);
1511 dc
->DrawText(item
->GetText(), rectLabel
.x
, rectLabel
.y
);
1515 void wxListLineData::DrawInReportMode( wxDC
*dc
,
1517 const wxRect
& rectHL
,
1520 // TODO: later we should support setting different attributes for
1521 // different columns - to do it, just add "col" argument to
1522 // GetAttr() and move these lines into the loop below
1523 wxListItemAttr
*attr
= GetAttr();
1524 if ( SetAttributes(dc
, attr
, highlighted
) )
1526 dc
->DrawRectangle( rectHL
);
1529 wxCoord x
= rect
.x
+ HEADER_OFFSET_X
,
1530 y
= rect
.y
+ (LINE_SPACING
+ EXTRA_HEIGHT
) / 2;
1533 for ( wxListItemDataList::compatibility_iterator node
= m_items
.GetFirst();
1535 node
= node
->GetNext(), col
++ )
1537 wxListItemData
*item
= node
->GetData();
1539 int width
= m_owner
->GetColumnWidth(col
);
1543 if ( item
->HasImage() )
1546 m_owner
->DrawImage( item
->GetImage(), dc
, xOld
, y
);
1547 m_owner
->GetImageSize( item
->GetImage(), ix
, iy
);
1549 ix
+= IMAGE_MARGIN_IN_REPORT_MODE
;
1555 wxDCClipper
clipper(*dc
, xOld
, y
, width
- 8, rect
.height
);
1557 if ( item
->HasText() )
1559 DrawTextFormatted(dc
, item
->GetText(), col
, xOld
, y
, width
- 8);
1564 void wxListLineData::DrawTextFormatted(wxDC
*dc
,
1565 const wxString
&text
,
1571 wxString drawntext
, ellipsis
;
1572 wxCoord w
, h
, base_w
;
1575 // determine if the string can fit inside the current width
1576 dc
->GetTextExtent(text
, &w
, &h
);
1579 // it can, draw it using the items alignment
1580 m_owner
->GetColumn(col
, item
);
1581 switch ( item
.GetAlign() )
1584 wxFAIL_MSG( _T("unknown list item format") );
1587 case wxLIST_FORMAT_LEFT
:
1591 case wxLIST_FORMAT_RIGHT
:
1595 case wxLIST_FORMAT_CENTER
:
1596 x
+= (width
- w
) / 2;
1600 dc
->DrawText(text
, x
, y
);
1602 else // otherwise, truncate and add an ellipsis if possible
1604 // determine the base width
1605 ellipsis
= wxString(wxT("..."));
1606 dc
->GetTextExtent(ellipsis
, &base_w
, &h
);
1608 // continue until we have enough space or only one character left
1610 size_t len
= text
.Length();
1611 drawntext
= text
.Left(len
);
1614 dc
->GetTextExtent(drawntext
.Last(), &w_c
, &h_c
);
1615 drawntext
.RemoveLast();
1618 if (w
+ base_w
<= width
)
1622 // if still not enough space, remove ellipsis characters
1623 while (ellipsis
.Length() > 0 && w
+ base_w
> width
)
1625 ellipsis
= ellipsis
.Left(ellipsis
.Length() - 1);
1626 dc
->GetTextExtent(ellipsis
, &base_w
, &h
);
1629 // now draw the text
1630 dc
->DrawText(drawntext
, x
, y
);
1631 dc
->DrawText(ellipsis
, x
+ w
, y
);
1635 bool wxListLineData::Highlight( bool on
)
1637 wxCHECK_MSG( !IsVirtual(), false, _T("unexpected call to Highlight") );
1639 if ( on
== m_highlighted
)
1647 void wxListLineData::ReverseHighlight( void )
1649 Highlight(!IsHighlighted());
1652 //-----------------------------------------------------------------------------
1653 // wxListHeaderWindow
1654 //-----------------------------------------------------------------------------
1656 IMPLEMENT_DYNAMIC_CLASS(wxListHeaderWindow
,wxWindow
)
1658 BEGIN_EVENT_TABLE(wxListHeaderWindow
,wxWindow
)
1659 EVT_PAINT (wxListHeaderWindow::OnPaint
)
1660 EVT_MOUSE_EVENTS (wxListHeaderWindow::OnMouse
)
1661 EVT_SET_FOCUS (wxListHeaderWindow::OnSetFocus
)
1664 void wxListHeaderWindow::Init()
1666 m_currentCursor
= (wxCursor
*) NULL
;
1667 m_isDragging
= false;
1671 wxListHeaderWindow::wxListHeaderWindow()
1675 m_owner
= (wxListMainWindow
*) NULL
;
1676 m_resizeCursor
= (wxCursor
*) NULL
;
1679 wxListHeaderWindow::wxListHeaderWindow( wxWindow
*win
,
1681 wxListMainWindow
*owner
,
1685 const wxString
&name
)
1686 : wxWindow( win
, id
, pos
, size
, style
, name
)
1691 m_resizeCursor
= new wxCursor( wxCURSOR_SIZEWE
);
1694 wxVisualAttributes attr
= wxPanel::GetClassDefaultAttributes();
1695 SetOwnForegroundColour( attr
.colFg
);
1696 SetOwnBackgroundColour( attr
.colBg
);
1698 SetOwnFont( attr
.font
);
1700 SetOwnForegroundColour( wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT
));
1701 SetOwnBackgroundColour( wxSystemSettings::GetColour(wxSYS_COLOUR_BTNFACE
));
1703 SetOwnFont( wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT
));
1707 wxListHeaderWindow::~wxListHeaderWindow()
1709 delete m_resizeCursor
;
1712 #ifdef __WXUNIVERSAL__
1713 #include "wx/univ/renderer.h"
1714 #include "wx/univ/theme.h"
1717 // shift the DC origin to match the position of the main window horz
1718 // scrollbar: this allows us to always use logical coords
1719 void wxListHeaderWindow::AdjustDC(wxDC
& dc
)
1722 m_owner
->GetScrollPixelsPerUnit( &xpix
, NULL
);
1725 m_owner
->GetViewStart( &x
, NULL
);
1727 // account for the horz scrollbar offset
1728 dc
.SetDeviceOrigin( -x
* xpix
, 0 );
1731 void wxListHeaderWindow::OnPaint( wxPaintEvent
&WXUNUSED(event
) )
1733 wxPaintDC
dc( this );
1740 dc
.SetFont( GetFont() );
1742 // width and height of the entire header window
1744 GetClientSize( &w
, &h
);
1745 m_owner
->CalcUnscrolledPosition(w
, 0, &w
, NULL
);
1747 dc
.SetBackgroundMode(wxTRANSPARENT
);
1749 dc
.SetTextForeground(GetForegroundColour());
1751 int x
= HEADER_OFFSET_X
;
1753 int numColumns
= m_owner
->GetColumnCount();
1755 for ( int i
= 0; i
< numColumns
&& x
< w
; i
++ )
1757 m_owner
->GetColumn( i
, item
);
1758 int wCol
= item
.m_width
;
1760 // the width of the rect to draw: make it smaller to fit entirely
1761 // inside the column rect
1769 wxRendererNative::Get().DrawHeaderButton
1773 wxRect(x
, HEADER_OFFSET_Y
, cw
, ch
),
1774 m_parent
->IsEnabled() ? 0
1775 : (int)wxCONTROL_DISABLED
1778 // see if we have enough space for the column label
1780 // for this we need the width of the text
1783 dc
.GetTextExtent(item
.GetText(), &wLabel
, &hLabel
);
1784 wLabel
+= 2*EXTRA_WIDTH
;
1786 // and the width of the icon, if any
1787 static const int MARGIN_BETWEEN_TEXT_AND_ICON
= 2;
1788 int ix
= 0, // init them just to suppress the compiler warnings
1790 const int image
= item
.m_image
;
1791 wxImageListType
*imageList
;
1794 imageList
= m_owner
->m_small_image_list
;
1797 imageList
->GetSize(image
, ix
, iy
);
1798 wLabel
+= ix
+ MARGIN_BETWEEN_TEXT_AND_ICON
;
1806 // ignore alignment if there is not enough space anyhow
1808 switch ( wLabel
< cw
? item
.GetAlign() : wxLIST_FORMAT_LEFT
)
1811 wxFAIL_MSG( _T("unknown list item format") );
1814 case wxLIST_FORMAT_LEFT
:
1818 case wxLIST_FORMAT_RIGHT
:
1819 xAligned
= x
+ cw
- wLabel
;
1822 case wxLIST_FORMAT_CENTER
:
1823 xAligned
= x
+ (cw
- wLabel
) / 2;
1828 // if we have an image, draw it on the right of the label
1835 xAligned
+ wLabel
- ix
- MARGIN_BETWEEN_TEXT_AND_ICON
,
1836 HEADER_OFFSET_Y
+ (h
- 4 - iy
)/2,
1837 wxIMAGELIST_DRAW_TRANSPARENT
1840 cw
-= ix
+ MARGIN_BETWEEN_TEXT_AND_ICON
;
1843 // draw the text clipping it so that it doesn't overwrite the column
1845 wxDCClipper
clipper(dc
, x
, HEADER_OFFSET_Y
, cw
, h
- 4 );
1847 dc
.DrawText( item
.GetText(),
1848 xAligned
+ EXTRA_WIDTH
, h
/ 2 - hLabel
/ 2 ); //HEADER_OFFSET_Y + EXTRA_HEIGHT );
1856 void wxListHeaderWindow::DrawCurrent()
1858 int x1
= m_currentX
;
1860 m_owner
->ClientToScreen( &x1
, &y1
);
1862 int x2
= m_currentX
;
1864 m_owner
->GetClientSize( NULL
, &y2
);
1865 m_owner
->ClientToScreen( &x2
, &y2
);
1868 dc
.SetLogicalFunction( wxINVERT
);
1869 dc
.SetPen( wxPen( *wxBLACK
, 2, wxSOLID
) );
1870 dc
.SetBrush( *wxTRANSPARENT_BRUSH
);
1874 dc
.DrawLine( x1
, y1
, x2
, y2
);
1876 dc
.SetLogicalFunction( wxCOPY
);
1878 dc
.SetPen( wxNullPen
);
1879 dc
.SetBrush( wxNullBrush
);
1882 void wxListHeaderWindow::OnMouse( wxMouseEvent
&event
)
1884 // we want to work with logical coords
1886 m_owner
->CalcUnscrolledPosition(event
.GetX(), 0, &x
, NULL
);
1887 int y
= event
.GetY();
1891 SendListEvent(wxEVT_COMMAND_LIST_COL_DRAGGING
, event
.GetPosition());
1893 // we don't draw the line beyond our window, but we allow dragging it
1896 GetClientSize( &w
, NULL
);
1897 m_owner
->CalcUnscrolledPosition(w
, 0, &w
, NULL
);
1900 // erase the line if it was drawn
1901 if ( m_currentX
< w
)
1904 if (event
.ButtonUp())
1907 m_isDragging
= false;
1909 m_owner
->SetColumnWidth( m_column
, m_currentX
- m_minX
);
1910 SendListEvent(wxEVT_COMMAND_LIST_COL_END_DRAG
, event
.GetPosition());
1917 m_currentX
= m_minX
+ 7;
1919 // draw in the new location
1920 if ( m_currentX
< w
)
1924 else // not dragging
1927 bool hit_border
= false;
1929 // end of the current column
1932 // find the column where this event occurred
1934 countCol
= m_owner
->GetColumnCount();
1935 for (col
= 0; col
< countCol
; col
++)
1937 xpos
+= m_owner
->GetColumnWidth( col
);
1940 if ( (abs(x
-xpos
) < 3) && (y
< 22) )
1942 // near the column border
1949 // inside the column
1956 if ( col
== countCol
)
1959 if (event
.LeftDown() || event
.RightUp())
1961 if (hit_border
&& event
.LeftDown())
1963 if ( SendListEvent(wxEVT_COMMAND_LIST_COL_BEGIN_DRAG
,
1964 event
.GetPosition()) )
1966 m_isDragging
= true;
1971 //else: column resizing was vetoed by the user code
1973 else // click on a column
1975 SendListEvent( event
.LeftDown()
1976 ? wxEVT_COMMAND_LIST_COL_CLICK
1977 : wxEVT_COMMAND_LIST_COL_RIGHT_CLICK
,
1978 event
.GetPosition());
1981 else if (event
.Moving())
1986 setCursor
= m_currentCursor
== wxSTANDARD_CURSOR
;
1987 m_currentCursor
= m_resizeCursor
;
1991 setCursor
= m_currentCursor
!= wxSTANDARD_CURSOR
;
1992 m_currentCursor
= wxSTANDARD_CURSOR
;
1996 SetCursor(*m_currentCursor
);
2001 void wxListHeaderWindow::OnSetFocus( wxFocusEvent
&WXUNUSED(event
) )
2003 m_owner
->SetFocus();
2007 bool wxListHeaderWindow::SendListEvent(wxEventType type
, const wxPoint
& pos
)
2009 wxWindow
*parent
= GetParent();
2010 wxListEvent
le( type
, parent
->GetId() );
2011 le
.SetEventObject( parent
);
2012 le
.m_pointDrag
= pos
;
2014 // the position should be relative to the parent window, not
2015 // this one for compatibility with MSW and common sense: the
2016 // user code doesn't know anything at all about this header
2017 // window, so why should it get positions relative to it?
2018 le
.m_pointDrag
.y
-= GetSize().y
;
2020 le
.m_col
= m_column
;
2021 return !parent
->GetEventHandler()->ProcessEvent( le
) || le
.IsAllowed();
2024 //-----------------------------------------------------------------------------
2025 // wxListRenameTimer (internal)
2026 //-----------------------------------------------------------------------------
2028 wxListRenameTimer::wxListRenameTimer( wxListMainWindow
*owner
)
2033 void wxListRenameTimer::Notify()
2035 m_owner
->OnRenameTimer();
2038 //-----------------------------------------------------------------------------
2039 // wxListTextCtrl (internal)
2040 //-----------------------------------------------------------------------------
2042 BEGIN_EVENT_TABLE(wxListTextCtrl
,wxTextCtrl
)
2043 EVT_CHAR (wxListTextCtrl::OnChar
)
2044 EVT_KEY_UP (wxListTextCtrl::OnKeyUp
)
2045 EVT_KILL_FOCUS (wxListTextCtrl::OnKillFocus
)
2048 wxListTextCtrl::wxListTextCtrl(wxListMainWindow
*owner
, size_t itemEdit
)
2049 : m_startValue(owner
->GetItemText(itemEdit
)),
2050 m_itemEdited(itemEdit
)
2054 m_aboutToFinish
= false;
2056 wxRect rectLabel
= owner
->GetLineLabelRect(itemEdit
);
2058 m_owner
->CalcScrolledPosition(rectLabel
.x
, rectLabel
.y
,
2059 &rectLabel
.x
, &rectLabel
.y
);
2061 (void)Create(owner
, wxID_ANY
, m_startValue
,
2062 wxPoint(rectLabel
.x
-4,rectLabel
.y
-4),
2063 wxSize(rectLabel
.width
+11,rectLabel
.height
+8));
2066 void wxListTextCtrl::Finish()
2070 wxPendingDelete
.Append(this);
2074 m_owner
->SetFocusIgnoringChildren();
2078 bool wxListTextCtrl::AcceptChanges()
2080 const wxString value
= GetValue();
2082 if ( value
== m_startValue
)
2084 // nothing changed, always accept
2088 if ( !m_owner
->OnRenameAccept(m_itemEdited
, value
) )
2090 // vetoed by the user
2094 // accepted, do rename the item
2095 m_owner
->SetItemText(m_itemEdited
, value
);
2100 void wxListTextCtrl::OnChar( wxKeyEvent
&event
)
2102 switch ( event
.m_keyCode
)
2105 m_aboutToFinish
= true;
2106 // Notify the owner about the changes
2108 // Even if vetoed, close the control (consistent with MSW)
2114 m_owner
->OnRenameCancelled( m_itemEdited
);
2122 void wxListTextCtrl::OnKeyUp( wxKeyEvent
&event
)
2130 // auto-grow the textctrl:
2131 wxSize parentSize
= m_owner
->GetSize();
2132 wxPoint myPos
= GetPosition();
2133 wxSize mySize
= GetSize();
2135 GetTextExtent(GetValue() + _T("MM"), &sx
, &sy
);
2136 if (myPos
.x
+ sx
> parentSize
.x
)
2137 sx
= parentSize
.x
- myPos
.x
;
2140 SetSize(sx
, wxDefaultCoord
);
2145 void wxListTextCtrl::OnKillFocus( wxFocusEvent
&event
)
2147 if ( !m_finished
&& !m_aboutToFinish
)
2149 // We must finish regardless of success, otherwise we'll get
2153 if ( !AcceptChanges() )
2154 m_owner
->OnRenameCancelled( m_itemEdited
);
2157 // We must let the native text control handle focus, too, otherwise
2158 // it could have problems with the cursor (e.g., in wxGTK).
2162 //-----------------------------------------------------------------------------
2164 //-----------------------------------------------------------------------------
2166 IMPLEMENT_DYNAMIC_CLASS(wxListMainWindow
,wxScrolledWindow
)
2168 BEGIN_EVENT_TABLE(wxListMainWindow
,wxScrolledWindow
)
2169 EVT_PAINT (wxListMainWindow::OnPaint
)
2170 EVT_MOUSE_EVENTS (wxListMainWindow::OnMouse
)
2171 EVT_CHAR (wxListMainWindow::OnChar
)
2172 EVT_KEY_DOWN (wxListMainWindow::OnKeyDown
)
2173 EVT_SET_FOCUS (wxListMainWindow::OnSetFocus
)
2174 EVT_KILL_FOCUS (wxListMainWindow::OnKillFocus
)
2175 EVT_SCROLLWIN (wxListMainWindow::OnScroll
)
2178 void wxListMainWindow::Init()
2183 m_lineTo
= (size_t)-1;
2189 m_small_image_list
= (wxImageListType
*) NULL
;
2190 m_normal_image_list
= (wxImageListType
*) NULL
;
2192 m_small_spacing
= 30;
2193 m_normal_spacing
= 40;
2197 m_isCreated
= false;
2199 m_lastOnSame
= false;
2200 m_renameTimer
= new wxListRenameTimer( this );
2204 m_lineSelectSingleOnUp
=
2205 m_lineBeforeLastClicked
= (size_t)-1;
2210 wxListMainWindow::wxListMainWindow()
2215 m_highlightUnfocusedBrush
= (wxBrush
*) NULL
;
2218 wxListMainWindow::wxListMainWindow( wxWindow
*parent
,
2223 const wxString
&name
)
2224 : wxScrolledWindow( parent
, id
, pos
, size
,
2225 style
| wxHSCROLL
| wxVSCROLL
, name
)
2229 m_highlightBrush
= new wxBrush
2231 wxSystemSettings::GetColour
2233 wxSYS_COLOUR_HIGHLIGHT
2238 m_highlightUnfocusedBrush
= new wxBrush
2240 wxSystemSettings::GetColour
2242 wxSYS_COLOUR_BTNSHADOW
2247 SetScrollbars( 0, 0, 0, 0, 0, 0 );
2249 wxVisualAttributes attr
= wxGenericListCtrl::GetClassDefaultAttributes();
2250 SetOwnForegroundColour( attr
.colFg
);
2251 SetOwnBackgroundColour( attr
.colBg
);
2253 SetOwnFont( attr
.font
);
2256 wxListMainWindow::~wxListMainWindow()
2259 WX_CLEAR_LIST(wxListHeaderDataList
, m_columns
);
2260 WX_CLEAR_ARRAY(m_aColWidths
);
2262 delete m_highlightBrush
;
2263 delete m_highlightUnfocusedBrush
;
2265 delete m_renameTimer
;
2268 void wxListMainWindow::CacheLineData(size_t line
)
2270 wxGenericListCtrl
*listctrl
= GetListCtrl();
2272 wxListLineData
*ld
= GetDummyLine();
2274 size_t countCol
= GetColumnCount();
2275 for ( size_t col
= 0; col
< countCol
; col
++ )
2277 ld
->SetText(col
, listctrl
->OnGetItemText(line
, col
));
2280 ld
->SetImage(listctrl
->OnGetItemImage(line
));
2281 ld
->SetAttr(listctrl
->OnGetItemAttr(line
));
2284 wxListLineData
*wxListMainWindow::GetDummyLine() const
2286 wxASSERT_MSG( !IsEmpty(), _T("invalid line index") );
2288 wxASSERT_MSG( IsVirtual(), _T("GetDummyLine() shouldn't be called") );
2290 wxListMainWindow
*self
= wxConstCast(this, wxListMainWindow
);
2292 // we need to recreate the dummy line if the number of columns in the
2293 // control changed as it would have the incorrect number of fields
2295 if ( !m_lines
.IsEmpty() &&
2296 m_lines
[0].m_items
.GetCount() != (size_t)GetColumnCount() )
2298 self
->m_lines
.Clear();
2301 if ( m_lines
.IsEmpty() )
2303 wxListLineData
*line
= new wxListLineData(self
);
2304 self
->m_lines
.Add(line
);
2306 // don't waste extra memory -- there never going to be anything
2307 // else/more in this array
2308 self
->m_lines
.Shrink();
2314 // ----------------------------------------------------------------------------
2315 // line geometry (report mode only)
2316 // ----------------------------------------------------------------------------
2318 wxCoord
wxListMainWindow::GetLineHeight() const
2320 // we cache the line height as calling GetTextExtent() is slow
2321 if ( !m_lineHeight
)
2323 wxListMainWindow
*self
= wxConstCast(this, wxListMainWindow
);
2325 wxClientDC
dc( self
);
2326 dc
.SetFont( GetFont() );
2329 dc
.GetTextExtent(_T("H"), NULL
, &y
);
2331 if ( m_small_image_list
&& m_small_image_list
->GetImageCount() )
2335 m_small_image_list
->GetSize(0, iw
, ih
);
2340 self
->m_lineHeight
= y
+ LINE_SPACING
;
2343 return m_lineHeight
;
2346 wxCoord
wxListMainWindow::GetLineY(size_t line
) const
2348 wxASSERT_MSG( InReportView(), _T("only works in report mode") );
2350 return LINE_SPACING
+ line
*GetLineHeight();
2353 wxRect
wxListMainWindow::GetLineRect(size_t line
) const
2355 if ( !InReportView() )
2356 return GetLine(line
)->m_gi
->m_rectAll
;
2359 rect
.x
= HEADER_OFFSET_X
;
2360 rect
.y
= GetLineY(line
);
2361 rect
.width
= GetHeaderWidth();
2362 rect
.height
= GetLineHeight();
2367 wxRect
wxListMainWindow::GetLineLabelRect(size_t line
) const
2369 if ( !InReportView() )
2370 return GetLine(line
)->m_gi
->m_rectLabel
;
2373 rect
.x
= HEADER_OFFSET_X
;
2374 rect
.y
= GetLineY(line
);
2375 rect
.width
= GetColumnWidth(0);
2376 rect
.height
= GetLineHeight();
2381 wxRect
wxListMainWindow::GetLineIconRect(size_t line
) const
2383 if ( !InReportView() )
2384 return GetLine(line
)->m_gi
->m_rectIcon
;
2386 wxListLineData
*ld
= GetLine(line
);
2387 wxASSERT_MSG( ld
->HasImage(), _T("should have an image") );
2390 rect
.x
= HEADER_OFFSET_X
;
2391 rect
.y
= GetLineY(line
);
2392 GetImageSize(ld
->GetImage(), rect
.width
, rect
.height
);
2397 wxRect
wxListMainWindow::GetLineHighlightRect(size_t line
) const
2399 return InReportView() ? GetLineRect(line
)
2400 : GetLine(line
)->m_gi
->m_rectHighlight
;
2403 long wxListMainWindow::HitTestLine(size_t line
, int x
, int y
) const
2405 wxASSERT_MSG( line
< GetItemCount(), _T("invalid line in HitTestLine") );
2407 wxListLineData
*ld
= GetLine(line
);
2409 if ( ld
->HasImage() && GetLineIconRect(line
).Inside(x
, y
) )
2410 return wxLIST_HITTEST_ONITEMICON
;
2412 // VS: Testing for "ld->HasText() || InReportView()" instead of
2413 // "ld->HasText()" is needed to make empty lines in report view
2415 if ( ld
->HasText() || InReportView() )
2417 wxRect rect
= InReportView() ? GetLineRect(line
)
2418 : GetLineLabelRect(line
);
2420 if ( rect
.Inside(x
, y
) )
2421 return wxLIST_HITTEST_ONITEMLABEL
;
2427 // ----------------------------------------------------------------------------
2428 // highlight (selection) handling
2429 // ----------------------------------------------------------------------------
2431 bool wxListMainWindow::IsHighlighted(size_t line
) const
2435 return m_selStore
.IsSelected(line
);
2439 wxListLineData
*ld
= GetLine(line
);
2440 wxCHECK_MSG( ld
, false, _T("invalid index in IsHighlighted") );
2442 return ld
->IsHighlighted();
2446 void wxListMainWindow::HighlightLines( size_t lineFrom
,
2452 wxArrayInt linesChanged
;
2453 if ( !m_selStore
.SelectRange(lineFrom
, lineTo
, highlight
,
2456 // meny items changed state, refresh everything
2457 RefreshLines(lineFrom
, lineTo
);
2459 else // only a few items changed state, refresh only them
2461 size_t count
= linesChanged
.GetCount();
2462 for ( size_t n
= 0; n
< count
; n
++ )
2464 RefreshLine(linesChanged
[n
]);
2468 else // iterate over all items in non report view
2470 for ( size_t line
= lineFrom
; line
<= lineTo
; line
++ )
2472 if ( HighlightLine(line
, highlight
) )
2480 bool wxListMainWindow::HighlightLine( size_t line
, bool highlight
)
2486 changed
= m_selStore
.SelectItem(line
, highlight
);
2490 wxListLineData
*ld
= GetLine(line
);
2491 wxCHECK_MSG( ld
, false, _T("invalid index in HighlightLine") );
2493 changed
= ld
->Highlight(highlight
);
2498 SendNotify( line
, highlight
? wxEVT_COMMAND_LIST_ITEM_SELECTED
2499 : wxEVT_COMMAND_LIST_ITEM_DESELECTED
);
2505 void wxListMainWindow::RefreshLine( size_t line
)
2507 if ( InReportView() )
2509 size_t visibleFrom
, visibleTo
;
2510 GetVisibleLinesRange(&visibleFrom
, &visibleTo
);
2512 if ( line
< visibleFrom
|| line
> visibleTo
)
2516 wxRect rect
= GetLineRect(line
);
2518 CalcScrolledPosition( rect
.x
, rect
.y
, &rect
.x
, &rect
.y
);
2519 RefreshRect( rect
);
2522 void wxListMainWindow::RefreshLines( size_t lineFrom
, size_t lineTo
)
2524 // we suppose that they are ordered by caller
2525 wxASSERT_MSG( lineFrom
<= lineTo
, _T("indices in disorder") );
2527 wxASSERT_MSG( lineTo
< GetItemCount(), _T("invalid line range") );
2529 if ( InReportView() )
2531 size_t visibleFrom
, visibleTo
;
2532 GetVisibleLinesRange(&visibleFrom
, &visibleTo
);
2534 if ( lineFrom
< visibleFrom
)
2535 lineFrom
= visibleFrom
;
2536 if ( lineTo
> visibleTo
)
2541 rect
.y
= GetLineY(lineFrom
);
2542 rect
.width
= GetClientSize().x
;
2543 rect
.height
= GetLineY(lineTo
) - rect
.y
+ GetLineHeight();
2545 CalcScrolledPosition( rect
.x
, rect
.y
, &rect
.x
, &rect
.y
);
2546 RefreshRect( rect
);
2550 // TODO: this should be optimized...
2551 for ( size_t line
= lineFrom
; line
<= lineTo
; line
++ )
2558 void wxListMainWindow::RefreshAfter( size_t lineFrom
)
2560 if ( InReportView() )
2562 size_t visibleFrom
, visibleTo
;
2563 GetVisibleLinesRange(&visibleFrom
, &visibleTo
);
2565 if ( lineFrom
< visibleFrom
)
2566 lineFrom
= visibleFrom
;
2567 else if ( lineFrom
> visibleTo
)
2572 rect
.y
= GetLineY(lineFrom
);
2573 CalcScrolledPosition( rect
.x
, rect
.y
, &rect
.x
, &rect
.y
);
2575 wxSize size
= GetClientSize();
2576 rect
.width
= size
.x
;
2577 // refresh till the bottom of the window
2578 rect
.height
= size
.y
- rect
.y
;
2580 RefreshRect( rect
);
2584 // TODO: how to do it more efficiently?
2589 void wxListMainWindow::RefreshSelected()
2595 if ( InReportView() )
2597 GetVisibleLinesRange(&from
, &to
);
2602 to
= GetItemCount() - 1;
2605 if ( HasCurrent() && m_current
>= from
&& m_current
<= to
)
2607 RefreshLine(m_current
);
2610 for ( size_t line
= from
; line
<= to
; line
++ )
2612 // NB: the test works as expected even if m_current == -1
2613 if ( line
!= m_current
&& IsHighlighted(line
) )
2620 void wxListMainWindow::Freeze()
2625 void wxListMainWindow::Thaw()
2627 wxCHECK_RET( m_freezeCount
> 0, _T("thawing unfrozen list control?") );
2629 if ( !--m_freezeCount
)
2635 void wxListMainWindow::OnPaint( wxPaintEvent
&WXUNUSED(event
) )
2637 // Note: a wxPaintDC must be constructed even if no drawing is
2638 // done (a Windows requirement).
2639 wxPaintDC
dc( this );
2641 if ( IsEmpty() || m_freezeCount
)
2643 // nothing to draw or not the moment to draw it
2649 // delay the repainting until we calculate all the items positions
2656 CalcScrolledPosition( 0, 0, &dev_x
, &dev_y
);
2660 dc
.SetFont( GetFont() );
2662 if ( InReportView() )
2664 int lineHeight
= GetLineHeight();
2666 size_t visibleFrom
, visibleTo
;
2667 GetVisibleLinesRange(&visibleFrom
, &visibleTo
);
2670 wxCoord xOrig
, yOrig
;
2671 CalcUnscrolledPosition(0, 0, &xOrig
, &yOrig
);
2673 // tell the caller cache to cache the data
2676 wxListEvent
evCache(wxEVT_COMMAND_LIST_CACHE_HINT
,
2677 GetParent()->GetId());
2678 evCache
.SetEventObject( GetParent() );
2679 evCache
.m_oldItemIndex
= visibleFrom
;
2680 evCache
.m_itemIndex
= visibleTo
;
2681 GetParent()->GetEventHandler()->ProcessEvent( evCache
);
2684 for ( size_t line
= visibleFrom
; line
<= visibleTo
; line
++ )
2686 rectLine
= GetLineRect(line
);
2688 if ( !IsExposed(rectLine
.x
- xOrig
, rectLine
.y
- yOrig
,
2689 rectLine
.width
, rectLine
.height
) )
2691 // don't redraw unaffected lines to avoid flicker
2695 GetLine(line
)->DrawInReportMode( &dc
,
2697 GetLineHighlightRect(line
),
2698 IsHighlighted(line
) );
2701 if ( HasFlag(wxLC_HRULES
) )
2703 wxPen
pen(GetRuleColour(), 1, wxSOLID
);
2704 wxSize clientSize
= GetClientSize();
2706 // Don't draw the first one
2707 for ( size_t i
= visibleFrom
+1; i
<= visibleTo
; i
++ )
2710 dc
.SetBrush( *wxTRANSPARENT_BRUSH
);
2711 dc
.DrawLine(0 - dev_x
, i
*lineHeight
,
2712 clientSize
.x
- dev_x
, i
*lineHeight
);
2715 // Draw last horizontal rule
2716 if ( visibleTo
== GetItemCount() - 1 )
2719 dc
.SetBrush( *wxTRANSPARENT_BRUSH
);
2720 dc
.DrawLine(0 - dev_x
, (m_lineTo
+1)*lineHeight
,
2721 clientSize
.x
- dev_x
, (m_lineTo
+1)*lineHeight
);
2725 // Draw vertical rules if required
2726 if ( HasFlag(wxLC_VRULES
) && !IsEmpty() )
2728 wxPen
pen(GetRuleColour(), 1, wxSOLID
);
2730 wxRect firstItemRect
;
2731 wxRect lastItemRect
;
2732 GetItemRect(visibleFrom
, firstItemRect
);
2733 GetItemRect(visibleTo
, lastItemRect
);
2734 int x
= firstItemRect
.GetX();
2736 dc
.SetBrush(* wxTRANSPARENT_BRUSH
);
2737 for (int col
= 0; col
< GetColumnCount(); col
++)
2739 int colWidth
= GetColumnWidth(col
);
2741 dc
.DrawLine(x
- dev_x
- 2, firstItemRect
.GetY() - 1 - dev_y
,
2742 x
- dev_x
- 2, lastItemRect
.GetBottom() + 1 - dev_y
);
2748 size_t count
= GetItemCount();
2749 for ( size_t i
= 0; i
< count
; i
++ )
2751 GetLine(i
)->Draw( &dc
);
2756 // Don't draw rect outline under Mac at all.
2761 dc
.SetPen( *wxBLACK_PEN
);
2762 dc
.SetBrush( *wxTRANSPARENT_BRUSH
);
2763 dc
.DrawRectangle( GetLineHighlightRect(m_current
) );
2771 void wxListMainWindow::HighlightAll( bool on
)
2773 if ( IsSingleSel() )
2775 wxASSERT_MSG( !on
, _T("can't do this in a single sel control") );
2777 // we just have one item to turn off
2778 if ( HasCurrent() && IsHighlighted(m_current
) )
2780 HighlightLine(m_current
, false);
2781 RefreshLine(m_current
);
2786 HighlightLines(0, GetItemCount() - 1, on
);
2790 void wxListMainWindow::SendNotify( size_t line
,
2791 wxEventType command
,
2792 const wxPoint
& point
)
2794 wxListEvent
le( command
, GetParent()->GetId() );
2795 le
.SetEventObject( GetParent() );
2796 le
.m_itemIndex
= line
;
2798 // set only for events which have position
2799 if ( point
!= wxDefaultPosition
)
2800 le
.m_pointDrag
= point
;
2802 // don't try to get the line info for virtual list controls: the main
2803 // program has it anyhow and if we did it would result in accessing all
2804 // the lines, even those which are not visible now and this is precisely
2805 // what we're trying to avoid
2806 if ( !IsVirtual() && (command
!= wxEVT_COMMAND_LIST_DELETE_ITEM
) )
2808 if ( line
!= (size_t)-1 )
2810 GetLine(line
)->GetItem( 0, le
.m_item
);
2812 //else: this happens for wxEVT_COMMAND_LIST_ITEM_FOCUSED event
2814 //else: there may be no more such item
2816 GetParent()->GetEventHandler()->ProcessEvent( le
);
2819 void wxListMainWindow::ChangeCurrent(size_t current
)
2821 m_current
= current
;
2823 SendNotify(current
, wxEVT_COMMAND_LIST_ITEM_FOCUSED
);
2826 void wxListMainWindow::EditLabel( long item
)
2828 wxCHECK_RET( (item
>= 0) && ((size_t)item
< GetItemCount()),
2829 wxT("wrong index in wxGenericListCtrl::EditLabel()") );
2831 size_t itemEdit
= (size_t)item
;
2833 wxListEvent
le( wxEVT_COMMAND_LIST_BEGIN_LABEL_EDIT
, GetParent()->GetId() );
2834 le
.SetEventObject( GetParent() );
2835 le
.m_itemIndex
= item
;
2836 wxListLineData
*data
= GetLine(itemEdit
);
2837 wxCHECK_RET( data
, _T("invalid index in EditLabel()") );
2838 data
->GetItem( 0, le
.m_item
);
2839 if ( GetParent()->GetEventHandler()->ProcessEvent( le
) && !le
.IsAllowed() )
2841 // vetoed by user code
2845 // We have to call this here because the label in question might just have
2846 // been added and no screen update taken place.
2850 wxListTextCtrl
*text
= new wxListTextCtrl(this, itemEdit
);
2855 void wxListMainWindow::OnRenameTimer()
2857 wxCHECK_RET( HasCurrent(), wxT("unexpected rename timer") );
2859 EditLabel( m_current
);
2862 bool wxListMainWindow::OnRenameAccept(size_t itemEdit
, const wxString
& value
)
2864 wxListEvent
le( wxEVT_COMMAND_LIST_END_LABEL_EDIT
, GetParent()->GetId() );
2865 le
.SetEventObject( GetParent() );
2866 le
.m_itemIndex
= itemEdit
;
2868 wxListLineData
*data
= GetLine(itemEdit
);
2869 wxCHECK_MSG( data
, false, _T("invalid index in OnRenameAccept()") );
2871 data
->GetItem( 0, le
.m_item
);
2872 le
.m_item
.m_text
= value
;
2873 return !GetParent()->GetEventHandler()->ProcessEvent( le
) ||
2877 void wxListMainWindow::OnRenameCancelled(size_t itemEdit
)
2879 // let owner know that the edit was cancelled
2880 wxListEvent
le( wxEVT_COMMAND_LIST_END_LABEL_EDIT
, GetParent()->GetId() );
2882 le
.SetEditCanceled(true);
2884 le
.SetEventObject( GetParent() );
2885 le
.m_itemIndex
= itemEdit
;
2887 wxListLineData
*data
= GetLine(itemEdit
);
2888 wxCHECK_RET( data
, _T("invalid index in OnRenameCancelled()") );
2890 data
->GetItem( 0, le
.m_item
);
2892 GetEventHandler()->ProcessEvent( le
);
2895 void wxListMainWindow::OnMouse( wxMouseEvent
&event
)
2897 event
.SetEventObject( GetParent() );
2898 if ( GetParent()->GetEventHandler()->ProcessEvent( event
) )
2901 if (event
.GetEventType() == wxEVT_MOUSEWHEEL
)
2903 // let the base handle mouse wheel events.
2908 if ( !HasCurrent() || IsEmpty() )
2914 if ( !(event
.Dragging() || event
.ButtonDown() || event
.LeftUp() ||
2915 event
.ButtonDClick()) )
2918 int x
= event
.GetX();
2919 int y
= event
.GetY();
2920 CalcUnscrolledPosition( x
, y
, &x
, &y
);
2922 // where did we hit it (if we did)?
2925 size_t count
= GetItemCount(),
2928 if ( InReportView() )
2930 current
= y
/ GetLineHeight();
2931 if ( current
< count
)
2932 hitResult
= HitTestLine(current
, x
, y
);
2936 // TODO: optimize it too! this is less simple than for report view but
2937 // enumerating all items is still not a way to do it!!
2938 for ( current
= 0; current
< count
; current
++ )
2940 hitResult
= HitTestLine(current
, x
, y
);
2946 if (event
.Dragging())
2948 if (m_dragCount
== 0)
2950 // we have to report the raw, physical coords as we want to be
2951 // able to call HitTest(event.m_pointDrag) from the user code to
2952 // get the item being dragged
2953 m_dragStart
= event
.GetPosition();
2958 if (m_dragCount
!= 3)
2961 int command
= event
.RightIsDown() ? wxEVT_COMMAND_LIST_BEGIN_RDRAG
2962 : wxEVT_COMMAND_LIST_BEGIN_DRAG
;
2964 wxListEvent
le( command
, GetParent()->GetId() );
2965 le
.SetEventObject( GetParent() );
2966 le
.m_itemIndex
= m_lineLastClicked
;
2967 le
.m_pointDrag
= m_dragStart
;
2968 GetParent()->GetEventHandler()->ProcessEvent( le
);
2979 // outside of any item
2983 bool forceClick
= false;
2984 if (event
.ButtonDClick())
2986 m_renameTimer
->Stop();
2987 m_lastOnSame
= false;
2989 if ( current
== m_lineLastClicked
)
2991 SendNotify( current
, wxEVT_COMMAND_LIST_ITEM_ACTIVATED
);
2997 // The first click was on another item, so don't interpret this as
2998 // a double click, but as a simple click instead
3005 if(m_lineSelectSingleOnUp
!= (size_t) -1)
3007 // select single line
3008 HighlightAll( false );
3009 ReverseHighlight(m_lineSelectSingleOnUp
);
3013 if ((current
== m_current
) &&
3014 (hitResult
== wxLIST_HITTEST_ONITEMLABEL
) &&
3015 HasFlag(wxLC_EDIT_LABELS
) )
3017 m_renameTimer
->Start( 100, true );
3020 m_lastOnSame
= false;
3021 m_lineSelectSingleOnUp
= (size_t) -1;
3025 // This is necessary, because after a DnD operation in
3026 // from and to ourself, the up event is swallowed by the
3027 // DnD code. So on next non-up event (which means here and
3028 // now) m_lineSelectSingleOnUp should be reset.
3029 m_lineSelectSingleOnUp
= (size_t) -1;
3031 if (event
.RightDown())
3033 m_lineBeforeLastClicked
= m_lineLastClicked
;
3034 m_lineLastClicked
= current
;
3035 // If the item is already selected, do not update the selection.
3036 // Multi-selections should not be cleared if a selected item is clicked.
3037 if (!IsHighlighted(current
))
3039 HighlightAll(false);
3040 ChangeCurrent(current
);
3041 ReverseHighlight(m_current
);
3043 SendNotify( current
, wxEVT_COMMAND_LIST_ITEM_RIGHT_CLICK
,
3044 event
.GetPosition() );
3045 // Allow generation of context menu event
3048 else if (event
.MiddleDown())
3050 SendNotify( current
, wxEVT_COMMAND_LIST_ITEM_MIDDLE_CLICK
);
3052 else if ( event
.LeftDown() || forceClick
)
3054 m_lineBeforeLastClicked
= m_lineLastClicked
;
3055 m_lineLastClicked
= current
;
3057 size_t oldCurrent
= m_current
;
3058 bool oldWasSelected
= IsHighlighted(m_current
);
3060 bool cmdModifierDown
= event
.CmdDown();
3061 if ( IsSingleSel() || !(cmdModifierDown
|| event
.ShiftDown()) )
3063 if( IsSingleSel() || !IsHighlighted(current
) )
3065 HighlightAll( false );
3067 ChangeCurrent(current
);
3069 ReverseHighlight(m_current
);
3071 else // multi sel & current is highlighted & no mod keys
3073 m_lineSelectSingleOnUp
= current
;
3074 ChangeCurrent(current
); // change focus
3077 else // multi sel & either ctrl or shift is down
3079 if (cmdModifierDown
)
3081 ChangeCurrent(current
);
3083 ReverseHighlight(m_current
);
3085 else if (event
.ShiftDown())
3087 ChangeCurrent(current
);
3089 size_t lineFrom
= oldCurrent
,
3092 if ( lineTo
< lineFrom
)
3095 lineFrom
= m_current
;
3098 HighlightLines(lineFrom
, lineTo
);
3100 else // !ctrl, !shift
3102 // test in the enclosing if should make it impossible
3103 wxFAIL_MSG( _T("how did we get here?") );
3107 if (m_current
!= oldCurrent
)
3109 RefreshLine( oldCurrent
);
3112 // forceClick is only set if the previous click was on another item
3113 m_lastOnSame
= !forceClick
&& (m_current
== oldCurrent
) && oldWasSelected
;
3117 void wxListMainWindow::MoveToItem(size_t item
)
3119 if ( item
== (size_t)-1 )
3122 wxRect rect
= GetLineRect(item
);
3124 int client_w
, client_h
;
3125 GetClientSize( &client_w
, &client_h
);
3127 const int hLine
= GetLineHeight();
3129 int view_x
= SCROLL_UNIT_X
*GetScrollPos( wxHORIZONTAL
);
3130 int view_y
= hLine
*GetScrollPos( wxVERTICAL
);
3132 if ( InReportView() )
3134 // the next we need the range of lines shown it might be different, so
3136 ResetVisibleLinesRange();
3138 if (rect
.y
< view_y
)
3139 Scroll( -1, rect
.y
/hLine
);
3140 if (rect
.y
+rect
.height
+5 > view_y
+client_h
)
3141 Scroll( -1, (rect
.y
+rect
.height
-client_h
+hLine
)/hLine
);
3145 if (rect
.x
-view_x
< 5)
3146 Scroll( (rect
.x
-5)/SCROLL_UNIT_X
, -1 );
3147 if (rect
.x
+rect
.width
-5 > view_x
+client_w
)
3148 Scroll( (rect
.x
+rect
.width
-client_w
+SCROLL_UNIT_X
)/SCROLL_UNIT_X
, -1 );
3152 // ----------------------------------------------------------------------------
3153 // keyboard handling
3154 // ----------------------------------------------------------------------------
3156 void wxListMainWindow::OnArrowChar(size_t newCurrent
, const wxKeyEvent
& event
)
3158 wxCHECK_RET( newCurrent
< (size_t)GetItemCount(),
3159 _T("invalid item index in OnArrowChar()") );
3161 size_t oldCurrent
= m_current
;
3163 // in single selection we just ignore Shift as we can't select several
3165 if ( event
.ShiftDown() && !IsSingleSel() )
3167 ChangeCurrent(newCurrent
);
3169 // refresh the old focus to remove it
3170 RefreshLine( oldCurrent
);
3172 // select all the items between the old and the new one
3173 if ( oldCurrent
> newCurrent
)
3175 newCurrent
= oldCurrent
;
3176 oldCurrent
= m_current
;
3179 HighlightLines(oldCurrent
, newCurrent
);
3183 // all previously selected items are unselected unless ctrl is held
3184 if ( !event
.ControlDown() )
3185 HighlightAll(false);
3187 ChangeCurrent(newCurrent
);
3189 // refresh the old focus to remove it
3190 RefreshLine( oldCurrent
);
3192 if ( !event
.ControlDown() )
3194 HighlightLine( m_current
, true );
3198 RefreshLine( m_current
);
3203 void wxListMainWindow::OnKeyDown( wxKeyEvent
&event
)
3205 wxWindow
*parent
= GetParent();
3207 /* we propagate the key event up */
3208 wxKeyEvent
ke( wxEVT_KEY_DOWN
);
3209 ke
.m_shiftDown
= event
.m_shiftDown
;
3210 ke
.m_controlDown
= event
.m_controlDown
;
3211 ke
.m_altDown
= event
.m_altDown
;
3212 ke
.m_metaDown
= event
.m_metaDown
;
3213 ke
.m_keyCode
= event
.m_keyCode
;
3216 ke
.SetEventObject( parent
);
3217 if (parent
->GetEventHandler()->ProcessEvent( ke
)) return;
3222 void wxListMainWindow::OnChar( wxKeyEvent
&event
)
3224 wxWindow
*parent
= GetParent();
3226 /* we send a list_key event up */
3229 wxListEvent
le( wxEVT_COMMAND_LIST_KEY_DOWN
, GetParent()->GetId() );
3230 le
.m_itemIndex
= m_current
;
3231 GetLine(m_current
)->GetItem( 0, le
.m_item
);
3232 le
.m_code
= event
.GetKeyCode();
3233 le
.SetEventObject( parent
);
3234 parent
->GetEventHandler()->ProcessEvent( le
);
3237 /* we propagate the char event up */
3238 wxKeyEvent
ke( wxEVT_CHAR
);
3239 ke
.m_shiftDown
= event
.m_shiftDown
;
3240 ke
.m_controlDown
= event
.m_controlDown
;
3241 ke
.m_altDown
= event
.m_altDown
;
3242 ke
.m_metaDown
= event
.m_metaDown
;
3243 ke
.m_keyCode
= event
.m_keyCode
;
3246 ke
.SetEventObject( parent
);
3247 if (parent
->GetEventHandler()->ProcessEvent( ke
)) return;
3249 if (event
.GetKeyCode() == WXK_TAB
)
3251 wxNavigationKeyEvent nevent
;
3252 nevent
.SetWindowChange( event
.ControlDown() );
3253 nevent
.SetDirection( !event
.ShiftDown() );
3254 nevent
.SetEventObject( GetParent()->GetParent() );
3255 nevent
.SetCurrentFocus( m_parent
);
3256 if (GetParent()->GetParent()->GetEventHandler()->ProcessEvent( nevent
))
3260 /* no item -> nothing to do */
3267 switch (event
.GetKeyCode())
3270 if ( m_current
> 0 )
3271 OnArrowChar( m_current
- 1, event
);
3275 if ( m_current
< (size_t)GetItemCount() - 1 )
3276 OnArrowChar( m_current
+ 1, event
);
3281 OnArrowChar( GetItemCount() - 1, event
);
3286 OnArrowChar( 0, event
);
3291 int steps
= InReportView() ? m_linesPerPage
- 1 : m_current
% m_linesPerPage
;
3293 int index
= m_current
- steps
;
3297 OnArrowChar( index
, event
);
3303 int steps
= InReportView()
3304 ? m_linesPerPage
- 1
3305 : m_linesPerPage
- (m_current
% m_linesPerPage
) - 1;
3307 size_t index
= m_current
+ steps
;
3308 size_t count
= GetItemCount();
3309 if ( index
>= count
)
3312 OnArrowChar( index
, event
);
3317 if ( !InReportView() )
3319 int index
= m_current
- m_linesPerPage
;
3323 OnArrowChar( index
, event
);
3328 if ( !InReportView() )
3330 size_t index
= m_current
+ m_linesPerPage
;
3332 size_t count
= GetItemCount();
3333 if ( index
>= count
)
3336 OnArrowChar( index
, event
);
3341 if ( IsSingleSel() )
3343 SendNotify( m_current
, wxEVT_COMMAND_LIST_ITEM_ACTIVATED
);
3345 if ( IsHighlighted(m_current
) )
3347 // don't unselect the item in single selection mode
3350 //else: select it in ReverseHighlight() below if unselected
3353 ReverseHighlight(m_current
);
3358 SendNotify( m_current
, wxEVT_COMMAND_LIST_ITEM_ACTIVATED
);
3366 // ----------------------------------------------------------------------------
3368 // ----------------------------------------------------------------------------
3370 void wxListMainWindow::OnSetFocus( wxFocusEvent
&WXUNUSED(event
) )
3374 wxFocusEvent
event( wxEVT_SET_FOCUS
, GetParent()->GetId() );
3375 event
.SetEventObject( GetParent() );
3376 if ( GetParent()->GetEventHandler()->ProcessEvent( event
) )
3380 // wxGTK sends us EVT_SET_FOCUS events even if we had never got
3381 // EVT_KILL_FOCUS before which means that we finish by redrawing the items
3382 // which are already drawn correctly resulting in horrible flicker - avoid
3392 void wxListMainWindow::OnKillFocus( wxFocusEvent
&WXUNUSED(event
) )
3396 wxFocusEvent
event( wxEVT_KILL_FOCUS
, GetParent()->GetId() );
3397 event
.SetEventObject( GetParent() );
3398 if ( GetParent()->GetEventHandler()->ProcessEvent( event
) )
3405 void wxListMainWindow::DrawImage( int index
, wxDC
*dc
, int x
, int y
)
3407 if ( HasFlag(wxLC_ICON
) && (m_normal_image_list
))
3409 m_normal_image_list
->Draw( index
, *dc
, x
, y
, wxIMAGELIST_DRAW_TRANSPARENT
);
3411 else if ( HasFlag(wxLC_SMALL_ICON
) && (m_small_image_list
))
3413 m_small_image_list
->Draw( index
, *dc
, x
, y
, wxIMAGELIST_DRAW_TRANSPARENT
);
3415 else if ( HasFlag(wxLC_LIST
) && (m_small_image_list
))
3417 m_small_image_list
->Draw( index
, *dc
, x
, y
, wxIMAGELIST_DRAW_TRANSPARENT
);
3419 else if ( InReportView() && (m_small_image_list
))
3421 m_small_image_list
->Draw( index
, *dc
, x
, y
, wxIMAGELIST_DRAW_TRANSPARENT
);
3425 void wxListMainWindow::GetImageSize( int index
, int &width
, int &height
) const
3427 if ( HasFlag(wxLC_ICON
) && m_normal_image_list
)
3429 m_normal_image_list
->GetSize( index
, width
, height
);
3431 else if ( HasFlag(wxLC_SMALL_ICON
) && m_small_image_list
)
3433 m_small_image_list
->GetSize( index
, width
, height
);
3435 else if ( HasFlag(wxLC_LIST
) && m_small_image_list
)
3437 m_small_image_list
->GetSize( index
, width
, height
);
3439 else if ( InReportView() && m_small_image_list
)
3441 m_small_image_list
->GetSize( index
, width
, height
);
3450 int wxListMainWindow::GetTextLength( const wxString
&s
) const
3452 wxClientDC
dc( wxConstCast(this, wxListMainWindow
) );
3453 dc
.SetFont( GetFont() );
3456 dc
.GetTextExtent( s
, &lw
, NULL
);
3458 return lw
+ AUTOSIZE_COL_MARGIN
;
3461 void wxListMainWindow::SetImageList( wxImageListType
*imageList
, int which
)
3465 // calc the spacing from the icon size
3468 if ((imageList
) && (imageList
->GetImageCount()) )
3470 imageList
->GetSize(0, width
, height
);
3473 if (which
== wxIMAGE_LIST_NORMAL
)
3475 m_normal_image_list
= imageList
;
3476 m_normal_spacing
= width
+ 8;
3479 if (which
== wxIMAGE_LIST_SMALL
)
3481 m_small_image_list
= imageList
;
3482 m_small_spacing
= width
+ 14;
3483 m_lineHeight
= 0; // ensure that the line height will be recalc'd
3487 void wxListMainWindow::SetItemSpacing( int spacing
, bool isSmall
)
3492 m_small_spacing
= spacing
;
3496 m_normal_spacing
= spacing
;
3500 int wxListMainWindow::GetItemSpacing( bool isSmall
)
3502 return isSmall
? m_small_spacing
: m_normal_spacing
;
3505 // ----------------------------------------------------------------------------
3507 // ----------------------------------------------------------------------------
3509 void wxListMainWindow::SetColumn( int col
, wxListItem
&item
)
3511 wxListHeaderDataList::compatibility_iterator node
= m_columns
.Item( col
);
3513 wxCHECK_RET( node
, _T("invalid column index in SetColumn") );
3515 if ( item
.m_width
== wxLIST_AUTOSIZE_USEHEADER
)
3516 item
.m_width
= GetTextLength( item
.m_text
);
3518 wxListHeaderData
*column
= node
->GetData();
3519 column
->SetItem( item
);
3521 wxListHeaderWindow
*headerWin
= GetListCtrl()->m_headerWin
;
3523 headerWin
->m_dirty
= true;
3527 // invalidate it as it has to be recalculated
3531 void wxListMainWindow::SetColumnWidth( int col
, int width
)
3533 wxCHECK_RET( col
>= 0 && col
< GetColumnCount(),
3534 _T("invalid column index") );
3536 wxCHECK_RET( InReportView(),
3537 _T("SetColumnWidth() can only be called in report mode.") );
3540 wxListHeaderWindow
*headerWin
= GetListCtrl()->m_headerWin
;
3542 headerWin
->m_dirty
= true;
3544 wxListHeaderDataList::compatibility_iterator node
= m_columns
.Item( col
);
3545 wxCHECK_RET( node
, _T("no column?") );
3547 wxListHeaderData
*column
= node
->GetData();
3549 size_t count
= GetItemCount();
3551 if (width
== wxLIST_AUTOSIZE_USEHEADER
)
3553 width
= GetTextLength(column
->GetText());
3555 else if ( width
== wxLIST_AUTOSIZE
)
3559 // TODO: determine the max width somehow...
3560 width
= WIDTH_COL_DEFAULT
;
3564 wxClientDC
dc(this);
3565 dc
.SetFont( GetFont() );
3567 int max
= AUTOSIZE_COL_MARGIN
;
3569 // if the cached column width isn't valid then recalculate it
3570 if (m_aColWidths
.Item(col
)->bNeedsUpdate
)
3572 for (size_t i
= 0; i
< count
; i
++)
3574 wxListLineData
*line
= GetLine(i
);
3575 wxListItemDataList::compatibility_iterator n
= line
->m_items
.Item( col
);
3577 wxCHECK_RET( n
, _T("no subitem?") );
3579 wxListItemData
*itemData
= n
->GetData();
3582 itemData
->GetItem(item
);
3583 int itemWidth
= GetItemWidthWithImage(&item
);
3584 if (itemWidth
> max
)
3588 m_aColWidths
.Item(col
)->bNeedsUpdate
= false;
3589 m_aColWidths
.Item(col
)->nMaxWidth
= max
;
3592 max
= m_aColWidths
.Item(col
)->nMaxWidth
;
3593 width
= max
+ AUTOSIZE_COL_MARGIN
;
3597 column
->SetWidth( width
);
3599 // invalidate it as it has to be recalculated
3603 int wxListMainWindow::GetHeaderWidth() const
3605 if ( !m_headerWidth
)
3607 wxListMainWindow
*self
= wxConstCast(this, wxListMainWindow
);
3609 size_t count
= GetColumnCount();
3610 for ( size_t col
= 0; col
< count
; col
++ )
3612 self
->m_headerWidth
+= GetColumnWidth(col
);
3616 return m_headerWidth
;
3619 void wxListMainWindow::GetColumn( int col
, wxListItem
&item
) const
3621 wxListHeaderDataList::compatibility_iterator node
= m_columns
.Item( col
);
3622 wxCHECK_RET( node
, _T("invalid column index in GetColumn") );
3624 wxListHeaderData
*column
= node
->GetData();
3625 column
->GetItem( item
);
3628 int wxListMainWindow::GetColumnWidth( int col
) const
3630 wxListHeaderDataList::compatibility_iterator node
= m_columns
.Item( col
);
3631 wxCHECK_MSG( node
, 0, _T("invalid column index") );
3633 wxListHeaderData
*column
= node
->GetData();
3634 return column
->GetWidth();
3637 // ----------------------------------------------------------------------------
3639 // ----------------------------------------------------------------------------
3641 void wxListMainWindow::SetItem( wxListItem
&item
)
3643 long id
= item
.m_itemId
;
3644 wxCHECK_RET( id
>= 0 && (size_t)id
< GetItemCount(),
3645 _T("invalid item index in SetItem") );
3649 wxListLineData
*line
= GetLine((size_t)id
);
3650 line
->SetItem( item
.m_col
, item
);
3652 // Set item state if user wants
3653 if ( item
.m_mask
& wxLIST_MASK_STATE
)
3654 SetItemState( item
.m_itemId
, item
.m_state
, item
.m_state
);
3658 // update the Max Width Cache if needed
3659 int width
= GetItemWidthWithImage(&item
);
3661 if (width
> m_aColWidths
.Item(item
.m_col
)->nMaxWidth
)
3662 m_aColWidths
.Item(item
.m_col
)->nMaxWidth
= width
;
3666 // update the item on screen
3668 GetItemRect(id
, rectItem
);
3669 RefreshRect(rectItem
);
3672 void wxListMainWindow::SetItemStateAll(long state
, long stateMask
)
3677 // first deal with selection
3678 if ( stateMask
& wxLIST_STATE_SELECTED
)
3680 // set/clear select state
3683 // optimized version for virtual listctrl.
3684 m_selStore
.SelectRange(0, GetItemCount() - 1, state
== wxLIST_STATE_SELECTED
);
3687 else if ( state
& wxLIST_STATE_SELECTED
)
3689 const long count
= GetItemCount();
3690 for( long i
= 0; i
< count
; i
++ )
3692 SetItemState( i
, wxLIST_STATE_SELECTED
, wxLIST_STATE_SELECTED
);
3698 // clear for non virtual (somewhat optimized by using GetNextItem())
3700 while ( (i
= GetNextItem(i
, wxLIST_NEXT_ALL
, wxLIST_STATE_SELECTED
)) != -1 )
3702 SetItemState( i
, 0, wxLIST_STATE_SELECTED
);
3707 if ( HasCurrent() && (state
== 0) && (stateMask
& wxLIST_STATE_FOCUSED
) )
3709 // unfocus all: only one item can be focussed, so clearing focus for
3710 // all items is simply clearing focus of the focussed item.
3711 SetItemState(m_current
, state
, stateMask
);
3713 //(setting focus to all items makes no sense, so it is not handled here.)
3716 void wxListMainWindow::SetItemState( long litem
, long state
, long stateMask
)
3720 SetItemStateAll(state
, stateMask
);
3724 wxCHECK_RET( litem
>= 0 && (size_t)litem
< GetItemCount(),
3725 _T("invalid list ctrl item index in SetItem") );
3727 size_t oldCurrent
= m_current
;
3728 size_t item
= (size_t)litem
; // safe because of the check above
3730 // do we need to change the focus?
3731 if ( stateMask
& wxLIST_STATE_FOCUSED
)
3733 if ( state
& wxLIST_STATE_FOCUSED
)
3735 // don't do anything if this item is already focused
3736 if ( item
!= m_current
)
3738 ChangeCurrent(item
);
3740 if ( oldCurrent
!= (size_t)-1 )
3742 if ( IsSingleSel() )
3744 HighlightLine(oldCurrent
, false);
3747 RefreshLine(oldCurrent
);
3750 RefreshLine( m_current
);
3755 // don't do anything if this item is not focused
3756 if ( item
== m_current
)
3760 if ( IsSingleSel() )
3762 // we must unselect the old current item as well or we
3763 // might end up with more than one selected item in a
3764 // single selection control
3765 HighlightLine(oldCurrent
, false);
3768 RefreshLine( oldCurrent
);
3773 // do we need to change the selection state?
3774 if ( stateMask
& wxLIST_STATE_SELECTED
)
3776 bool on
= (state
& wxLIST_STATE_SELECTED
) != 0;
3778 if ( IsSingleSel() )
3782 // selecting the item also makes it the focused one in the
3784 if ( m_current
!= item
)
3786 ChangeCurrent(item
);
3788 if ( oldCurrent
!= (size_t)-1 )
3790 HighlightLine( oldCurrent
, false );
3791 RefreshLine( oldCurrent
);
3797 // only the current item may be selected anyhow
3798 if ( item
!= m_current
)
3803 if ( HighlightLine(item
, on
) )
3810 int wxListMainWindow::GetItemState( long item
, long stateMask
) const
3812 wxCHECK_MSG( item
>= 0 && (size_t)item
< GetItemCount(), 0,
3813 _T("invalid list ctrl item index in GetItemState()") );
3815 int ret
= wxLIST_STATE_DONTCARE
;
3817 if ( stateMask
& wxLIST_STATE_FOCUSED
)
3819 if ( (size_t)item
== m_current
)
3820 ret
|= wxLIST_STATE_FOCUSED
;
3823 if ( stateMask
& wxLIST_STATE_SELECTED
)
3825 if ( IsHighlighted(item
) )
3826 ret
|= wxLIST_STATE_SELECTED
;
3832 void wxListMainWindow::GetItem( wxListItem
&item
) const
3834 wxCHECK_RET( item
.m_itemId
>= 0 && (size_t)item
.m_itemId
< GetItemCount(),
3835 _T("invalid item index in GetItem") );
3837 wxListLineData
*line
= GetLine((size_t)item
.m_itemId
);
3838 line
->GetItem( item
.m_col
, item
);
3840 // Get item state if user wants it
3841 if ( item
.m_mask
& wxLIST_MASK_STATE
)
3842 item
.m_state
= GetItemState( item
.m_itemId
, wxLIST_STATE_SELECTED
|
3843 wxLIST_STATE_FOCUSED
);
3846 // ----------------------------------------------------------------------------
3848 // ----------------------------------------------------------------------------
3850 size_t wxListMainWindow::GetItemCount() const
3852 return IsVirtual() ? m_countVirt
: m_lines
.GetCount();
3855 void wxListMainWindow::SetItemCount(long count
)
3857 m_selStore
.SetItemCount(count
);
3858 m_countVirt
= count
;
3860 ResetVisibleLinesRange();
3862 // scrollbars must be reset
3866 int wxListMainWindow::GetSelectedItemCount() const
3868 // deal with the quick case first
3869 if ( IsSingleSel() )
3871 return HasCurrent() ? IsHighlighted(m_current
) : false;
3874 // virtual controls remmebers all its selections itself
3876 return m_selStore
.GetSelectedCount();
3878 // TODO: we probably should maintain the number of items selected even for
3879 // non virtual controls as enumerating all lines is really slow...
3880 size_t countSel
= 0;
3881 size_t count
= GetItemCount();
3882 for ( size_t line
= 0; line
< count
; line
++ )
3884 if ( GetLine(line
)->IsHighlighted() )
3891 // ----------------------------------------------------------------------------
3892 // item position/size
3893 // ----------------------------------------------------------------------------
3895 wxRect
wxListMainWindow::GetViewRect() const
3897 wxASSERT_MSG( !HasFlag(wxLC_REPORT
| wxLC_LIST
),
3898 _T("wxListCtrl::GetViewRect() only works in icon mode") );
3900 // we need to find the longest/tallest label
3903 const int count
= GetItemCount();
3906 for ( int i
= 0; i
< count
; i
++ )
3911 wxCoord x
= r
.GetRight(),
3921 // some fudge needed to make it look prettier
3922 xMax
+= 2*EXTRA_BORDER_X
;
3923 yMax
+= 2*EXTRA_BORDER_Y
;
3925 // account for the scrollbars if necessary
3926 const wxSize sizeAll
= GetClientSize();
3927 if ( xMax
> sizeAll
.x
)
3928 yMax
+= wxSystemSettings::GetMetric(wxSYS_HSCROLL_Y
);
3929 if ( yMax
> sizeAll
.y
)
3930 xMax
+= wxSystemSettings::GetMetric(wxSYS_VSCROLL_X
);
3932 return wxRect(0, 0, xMax
, yMax
);
3935 void wxListMainWindow::GetItemRect( long index
, wxRect
&rect
) const
3937 wxCHECK_RET( index
>= 0 && (size_t)index
< GetItemCount(),
3938 _T("invalid index in GetItemRect") );
3940 // ensure that we're laid out, otherwise we could return nonsense
3943 wxConstCast(this, wxListMainWindow
)->
3944 RecalculatePositions(true /* no refresh */);
3947 rect
= GetLineRect((size_t)index
);
3949 CalcScrolledPosition(rect
.x
, rect
.y
, &rect
.x
, &rect
.y
);
3952 bool wxListMainWindow::GetItemPosition(long item
, wxPoint
& pos
) const
3955 GetItemRect(item
, rect
);
3963 // ----------------------------------------------------------------------------
3964 // geometry calculation
3965 // ----------------------------------------------------------------------------
3967 void wxListMainWindow::RecalculatePositions(bool noRefresh
)
3969 wxClientDC
dc( this );
3970 dc
.SetFont( GetFont() );
3972 const size_t count
= GetItemCount();
3975 if ( HasFlag(wxLC_ICON
) )
3976 iconSpacing
= m_normal_spacing
;
3977 else if ( HasFlag(wxLC_SMALL_ICON
) )
3978 iconSpacing
= m_small_spacing
;
3982 // Note that we do not call GetClientSize() here but
3983 // GetSize() and subtract the border size for sunken
3984 // borders manually. This is technically incorrect,
3985 // but we need to know the client area's size WITHOUT
3986 // scrollbars here. Since we don't know if there are
3987 // any scrollbars, we use GetSize() instead. Another
3988 // solution would be to call SetScrollbars() here to
3989 // remove the scrollbars and call GetClientSize() then,
3990 // but this might result in flicker and - worse - will
3991 // reset the scrollbars to 0 which is not good at all
3992 // if you resize a dialog/window, but don't want to
3993 // reset the window scrolling. RR.
3994 // Furthermore, we actually do NOT subtract the border
3995 // width as 2 pixels is just the extra space which we
3996 // need around the actual content in the window. Other-
3997 // wise the text would e.g. touch the upper border. RR.
4000 GetSize( &clientWidth
, &clientHeight
);
4002 const int lineHeight
= GetLineHeight();
4004 if ( InReportView() )
4006 // all lines have the same height and we scroll one line per step
4007 int entireHeight
= count
*lineHeight
+ LINE_SPACING
;
4009 m_linesPerPage
= clientHeight
/ lineHeight
;
4011 ResetVisibleLinesRange();
4013 SetScrollbars( SCROLL_UNIT_X
, lineHeight
,
4014 GetHeaderWidth() / SCROLL_UNIT_X
,
4015 (entireHeight
+ lineHeight
- 1) / lineHeight
,
4016 GetScrollPos(wxHORIZONTAL
),
4017 GetScrollPos(wxVERTICAL
),
4022 // we have 3 different layout strategies: either layout all items
4023 // horizontally/vertically (wxLC_ALIGN_XXX styles explicitly given) or
4024 // to arrange them in top to bottom, left to right (don't ask me why
4025 // not the other way round...) order
4026 if ( HasFlag(wxLC_ALIGN_LEFT
| wxLC_ALIGN_TOP
) )
4028 int x
= EXTRA_BORDER_X
;
4029 int y
= EXTRA_BORDER_Y
;
4031 wxCoord widthMax
= 0;
4034 for ( i
= 0; i
< count
; i
++ )
4036 wxListLineData
*line
= GetLine(i
);
4037 line
->CalculateSize( &dc
, iconSpacing
);
4038 line
->SetPosition( x
, y
, iconSpacing
);
4040 wxSize sizeLine
= GetLineSize(i
);
4042 if ( HasFlag(wxLC_ALIGN_TOP
) )
4044 if ( sizeLine
.x
> widthMax
)
4045 widthMax
= sizeLine
.x
;
4049 else // wxLC_ALIGN_LEFT
4051 x
+= sizeLine
.x
+ MARGIN_BETWEEN_ROWS
;
4055 if ( HasFlag(wxLC_ALIGN_TOP
) )
4057 // traverse the items again and tweak their sizes so that they are
4058 // all the same in a row
4059 for ( i
= 0; i
< count
; i
++ )
4061 wxListLineData
*line
= GetLine(i
);
4062 line
->m_gi
->ExtendWidth(widthMax
);
4071 (x
+ SCROLL_UNIT_X
) / SCROLL_UNIT_X
,
4072 (y
+ lineHeight
) / lineHeight
,
4073 GetScrollPos( wxHORIZONTAL
),
4074 GetScrollPos( wxVERTICAL
),
4078 else // "flowed" arrangement, the most complicated case
4080 // at first we try without any scrollbars, if the items don't fit into
4081 // the window, we recalculate after subtracting the space taken by the
4084 int entireWidth
= 0;
4086 for (int tries
= 0; tries
< 2; tries
++)
4088 entireWidth
= 2*EXTRA_BORDER_X
;
4092 // Now we have decided that the items do not fit into the
4093 // client area, so we need a scrollbar
4094 entireWidth
+= SCROLL_UNIT_X
;
4097 int x
= EXTRA_BORDER_X
;
4098 int y
= EXTRA_BORDER_Y
;
4099 int maxWidthInThisRow
= 0;
4102 int currentlyVisibleLines
= 0;
4104 for (size_t i
= 0; i
< count
; i
++)
4106 currentlyVisibleLines
++;
4107 wxListLineData
*line
= GetLine(i
);
4108 line
->CalculateSize( &dc
, iconSpacing
);
4109 line
->SetPosition( x
, y
, iconSpacing
);
4111 wxSize sizeLine
= GetLineSize(i
);
4113 if ( maxWidthInThisRow
< sizeLine
.x
)
4114 maxWidthInThisRow
= sizeLine
.x
;
4117 if (currentlyVisibleLines
> m_linesPerPage
)
4118 m_linesPerPage
= currentlyVisibleLines
;
4120 if ( y
+ sizeLine
.y
>= clientHeight
)
4122 currentlyVisibleLines
= 0;
4124 maxWidthInThisRow
+= MARGIN_BETWEEN_ROWS
;
4125 x
+= maxWidthInThisRow
;
4126 entireWidth
+= maxWidthInThisRow
;
4127 maxWidthInThisRow
= 0;
4130 // We have reached the last item.
4131 if ( i
== count
- 1 )
4132 entireWidth
+= maxWidthInThisRow
;
4134 if ( (tries
== 0) &&
4135 (entireWidth
+ SCROLL_UNIT_X
> clientWidth
) )
4137 clientHeight
-= wxSystemSettings::
4138 GetMetric(wxSYS_HSCROLL_Y
);
4143 if ( i
== count
- 1 )
4144 tries
= 1; // Everything fits, no second try required.
4152 (entireWidth
+ SCROLL_UNIT_X
) / SCROLL_UNIT_X
,
4154 GetScrollPos( wxHORIZONTAL
),
4163 // FIXME: why should we call it from here?
4170 void wxListMainWindow::RefreshAll()
4175 wxListHeaderWindow
*headerWin
= GetListCtrl()->m_headerWin
;
4176 if ( headerWin
&& headerWin
->m_dirty
)
4178 headerWin
->m_dirty
= false;
4179 headerWin
->Refresh();
4183 void wxListMainWindow::UpdateCurrent()
4185 if ( !HasCurrent() && !IsEmpty() )
4191 long wxListMainWindow::GetNextItem( long item
,
4192 int WXUNUSED(geometry
),
4196 max
= GetItemCount();
4197 wxCHECK_MSG( (ret
== -1) || (ret
< max
), -1,
4198 _T("invalid listctrl index in GetNextItem()") );
4200 // notice that we start with the next item (or the first one if item == -1)
4201 // and this is intentional to allow writing a simple loop to iterate over
4202 // all selected items
4206 // this is not an error because the index was ok initially, just no
4217 size_t count
= GetItemCount();
4218 for ( size_t line
= (size_t)ret
; line
< count
; line
++ )
4220 if ( (state
& wxLIST_STATE_FOCUSED
) && (line
== m_current
) )
4223 if ( (state
& wxLIST_STATE_SELECTED
) && IsHighlighted(line
) )
4230 // ----------------------------------------------------------------------------
4232 // ----------------------------------------------------------------------------
4234 void wxListMainWindow::DeleteItem( long lindex
)
4236 size_t count
= GetItemCount();
4238 wxCHECK_RET( (lindex
>= 0) && ((size_t)lindex
< count
),
4239 _T("invalid item index in DeleteItem") );
4241 size_t index
= (size_t)lindex
;
4243 // we don't need to adjust the index for the previous items
4244 if ( HasCurrent() && m_current
>= index
)
4246 // if the current item is being deleted, we want the next one to
4247 // become selected - unless there is no next one - so don't adjust
4248 // m_current in this case
4249 if ( m_current
!= index
|| m_current
== count
- 1 )
4255 if ( InReportView() )
4257 // mark the Column Max Width cache as dirty if the items in the line
4258 // we're deleting contain the Max Column Width
4259 wxListLineData
* const line
= GetLine(index
);
4260 wxListItemDataList::compatibility_iterator n
;
4261 wxListItemData
*itemData
;
4265 for (size_t i
= 0; i
< m_columns
.GetCount(); i
++)
4267 n
= line
->m_items
.Item( i
);
4268 itemData
= n
->GetData();
4269 itemData
->GetItem(item
);
4271 itemWidth
= GetItemWidthWithImage(&item
);
4273 if (itemWidth
>= m_aColWidths
.Item(i
)->nMaxWidth
)
4274 m_aColWidths
.Item(i
)->bNeedsUpdate
= true;
4277 ResetVisibleLinesRange();
4284 m_selStore
.OnItemDelete(index
);
4288 m_lines
.RemoveAt( index
);
4291 // we need to refresh the (vert) scrollbar as the number of items changed
4294 SendNotify( index
, wxEVT_COMMAND_LIST_DELETE_ITEM
);
4296 RefreshAfter(index
);
4299 void wxListMainWindow::DeleteColumn( int col
)
4301 wxListHeaderDataList::compatibility_iterator node
= m_columns
.Item( col
);
4303 wxCHECK_RET( node
, wxT("invalid column index in DeleteColumn()") );
4306 delete node
->GetData();
4307 m_columns
.Erase( node
);
4311 // update all the items
4312 for ( size_t i
= 0; i
< m_lines
.GetCount(); i
++ )
4314 wxListLineData
* const line
= GetLine(i
);
4315 wxListItemDataList::compatibility_iterator n
= line
->m_items
.Item( col
);
4316 delete n
->GetData();
4317 line
->m_items
.Erase(n
);
4321 if ( InReportView() ) // we only cache max widths when in Report View
4323 delete m_aColWidths
.Item(col
);
4324 m_aColWidths
.RemoveAt(col
);
4327 // invalidate it as it has to be recalculated
4331 void wxListMainWindow::DoDeleteAllItems()
4335 // nothing to do - in particular, don't send the event
4341 // to make the deletion of all items faster, we don't send the
4342 // notifications for each item deletion in this case but only one event
4343 // for all of them: this is compatible with wxMSW and documented in
4344 // DeleteAllItems() description
4346 wxListEvent
event( wxEVT_COMMAND_LIST_DELETE_ALL_ITEMS
, GetParent()->GetId() );
4347 event
.SetEventObject( GetParent() );
4348 GetParent()->GetEventHandler()->ProcessEvent( event
);
4357 if ( InReportView() )
4359 ResetVisibleLinesRange();
4360 for (size_t i
= 0; i
< m_aColWidths
.GetCount(); i
++)
4362 m_aColWidths
.Item(i
)->bNeedsUpdate
= true;
4369 void wxListMainWindow::DeleteAllItems()
4373 RecalculatePositions();
4376 void wxListMainWindow::DeleteEverything()
4378 WX_CLEAR_LIST(wxListHeaderDataList
, m_columns
);
4379 WX_CLEAR_ARRAY(m_aColWidths
);
4384 // ----------------------------------------------------------------------------
4385 // scanning for an item
4386 // ----------------------------------------------------------------------------
4388 void wxListMainWindow::EnsureVisible( long index
)
4390 wxCHECK_RET( index
>= 0 && (size_t)index
< GetItemCount(),
4391 _T("invalid index in EnsureVisible") );
4393 // We have to call this here because the label in question might just have
4394 // been added and its position is not known yet
4397 RecalculatePositions(true /* no refresh */);
4400 MoveToItem((size_t)index
);
4403 long wxListMainWindow::FindItem(long start
, const wxString
& str
, bool WXUNUSED(partial
) )
4410 size_t count
= GetItemCount();
4411 for ( size_t i
= (size_t)pos
; i
< count
; i
++ )
4413 wxListLineData
*line
= GetLine(i
);
4414 if ( line
->GetText(0) == tmp
)
4421 long wxListMainWindow::FindItem(long start
, wxUIntPtr data
)
4427 size_t count
= GetItemCount();
4428 for (size_t i
= (size_t)pos
; i
< count
; i
++)
4430 wxListLineData
*line
= GetLine(i
);
4432 line
->GetItem( 0, item
);
4433 if (item
.m_data
== data
)
4440 long wxListMainWindow::FindItem( const wxPoint
& pt
)
4443 GetVisibleLinesRange(&topItem
, NULL
);
4446 GetItemPosition( GetItemCount()-1, p
);
4449 long id
= (long) floor( pt
.y
*double(GetItemCount()-topItem
-1)/p
.y
+topItem
);
4450 if( id
>= 0 && id
< (long)GetItemCount() )
4456 long wxListMainWindow::HitTest( int x
, int y
, int &flags
)
4458 CalcUnscrolledPosition( x
, y
, &x
, &y
);
4460 size_t count
= GetItemCount();
4462 if ( InReportView() )
4464 size_t current
= y
/ GetLineHeight();
4465 if ( current
< count
)
4467 flags
= HitTestLine(current
, x
, y
);
4474 // TODO: optimize it too! this is less simple than for report view but
4475 // enumerating all items is still not a way to do it!!
4476 for ( size_t current
= 0; current
< count
; current
++ )
4478 flags
= HitTestLine(current
, x
, y
);
4487 // ----------------------------------------------------------------------------
4489 // ----------------------------------------------------------------------------
4491 void wxListMainWindow::InsertItem( wxListItem
&item
)
4493 wxASSERT_MSG( !IsVirtual(), _T("can't be used with virtual control") );
4495 int count
= GetItemCount();
4496 wxCHECK_RET( item
.m_itemId
>= 0, _T("invalid item index") );
4498 if (item
.m_itemId
> count
)
4499 item
.m_itemId
= count
;
4501 size_t id
= item
.m_itemId
;
4505 if ( InReportView() )
4507 ResetVisibleLinesRange();
4509 // calculate the width of the item and adjust the max column width
4510 wxColWidthInfo
*pWidthInfo
= m_aColWidths
.Item(item
.GetColumn());
4511 int width
= GetItemWidthWithImage(&item
);
4512 item
.SetWidth(width
);
4513 if (width
> pWidthInfo
->nMaxWidth
)
4514 pWidthInfo
->nMaxWidth
= width
;
4517 wxListLineData
*line
= new wxListLineData(this);
4519 line
->SetItem( item
.m_col
, item
);
4521 m_lines
.Insert( line
, id
);
4525 // If an item is selected at or below the point of insertion, we need to
4526 // increment the member variables because the current row's index has gone
4528 if ( HasCurrent() && m_current
>= id
)
4533 SendNotify(id
, wxEVT_COMMAND_LIST_INSERT_ITEM
);
4535 RefreshLines(id
, GetItemCount() - 1);
4538 void wxListMainWindow::InsertColumn( long col
, wxListItem
&item
)
4541 if ( InReportView() )
4543 if (item
.m_width
== wxLIST_AUTOSIZE_USEHEADER
)
4544 item
.m_width
= GetTextLength( item
.m_text
);
4546 wxListHeaderData
*column
= new wxListHeaderData( item
);
4547 wxColWidthInfo
*colWidthInfo
= new wxColWidthInfo();
4549 bool insert
= (col
>= 0) && ((size_t)col
< m_columns
.GetCount());
4552 wxListHeaderDataList::compatibility_iterator
4553 node
= m_columns
.Item( col
);
4554 m_columns
.Insert( node
, column
);
4555 m_aColWidths
.Insert( colWidthInfo
, col
);
4559 m_columns
.Append( column
);
4560 m_aColWidths
.Add( colWidthInfo
);
4565 // update all the items
4566 for ( size_t i
= 0; i
< m_lines
.GetCount(); i
++ )
4568 wxListLineData
* const line
= GetLine(i
);
4569 wxListItemData
* const data
= new wxListItemData(this);
4571 line
->m_items
.Insert(col
, data
);
4573 line
->m_items
.Append(data
);
4577 // invalidate it as it has to be recalculated
4582 int wxListMainWindow::GetItemWidthWithImage(wxListItem
* item
)
4585 wxClientDC
dc(this);
4587 dc
.SetFont( GetFont() );
4589 if (item
->GetImage() != -1)
4592 GetImageSize( item
->GetImage(), ix
, iy
);
4596 if (!item
->GetText().empty())
4599 dc
.GetTextExtent( item
->GetText(), &w
, NULL
);
4606 // ----------------------------------------------------------------------------
4608 // ----------------------------------------------------------------------------
4610 wxListCtrlCompare list_ctrl_compare_func_2
;
4611 long list_ctrl_compare_data
;
4613 int LINKAGEMODE
list_ctrl_compare_func_1( wxListLineData
**arg1
, wxListLineData
**arg2
)
4615 wxListLineData
*line1
= *arg1
;
4616 wxListLineData
*line2
= *arg2
;
4618 line1
->GetItem( 0, item
);
4619 wxUIntPtr data1
= item
.m_data
;
4620 line2
->GetItem( 0, item
);
4621 wxUIntPtr data2
= item
.m_data
;
4622 return list_ctrl_compare_func_2( data1
, data2
, list_ctrl_compare_data
);
4625 void wxListMainWindow::SortItems( wxListCtrlCompare fn
, long data
)
4627 list_ctrl_compare_func_2
= fn
;
4628 list_ctrl_compare_data
= data
;
4629 m_lines
.Sort( list_ctrl_compare_func_1
);
4633 // ----------------------------------------------------------------------------
4635 // ----------------------------------------------------------------------------
4637 void wxListMainWindow::OnScroll(wxScrollWinEvent
& event
)
4639 // update our idea of which lines are shown when we redraw the window the
4641 ResetVisibleLinesRange();
4644 #if ( defined(__WXGTK__) || defined(__WXMAC__) ) && !defined(__WXUNIVERSAL__)
4645 wxScrolledWindow::OnScroll(event
);
4647 HandleOnScroll( event
);
4650 if ( event
.GetOrientation() == wxHORIZONTAL
&& HasHeader() )
4652 wxGenericListCtrl
* lc
= GetListCtrl();
4653 wxCHECK_RET( lc
, _T("no listctrl window?") );
4655 lc
->m_headerWin
->Refresh();
4656 lc
->m_headerWin
->Update();
4660 int wxListMainWindow::GetCountPerPage() const
4662 if ( !m_linesPerPage
)
4664 wxConstCast(this, wxListMainWindow
)->
4665 m_linesPerPage
= GetClientSize().y
/ GetLineHeight();
4668 return m_linesPerPage
;
4671 void wxListMainWindow::GetVisibleLinesRange(size_t *from
, size_t *to
)
4673 wxASSERT_MSG( InReportView(), _T("this is for report mode only") );
4675 if ( m_lineFrom
== (size_t)-1 )
4677 size_t count
= GetItemCount();
4680 m_lineFrom
= GetScrollPos(wxVERTICAL
);
4682 // this may happen if SetScrollbars() hadn't been called yet
4683 if ( m_lineFrom
>= count
)
4684 m_lineFrom
= count
- 1;
4686 // we redraw one extra line but this is needed to make the redrawing
4687 // logic work when there is a fractional number of lines on screen
4688 m_lineTo
= m_lineFrom
+ m_linesPerPage
;
4689 if ( m_lineTo
>= count
)
4690 m_lineTo
= count
- 1;
4692 else // empty control
4695 m_lineTo
= (size_t)-1;
4699 wxASSERT_MSG( IsEmpty() ||
4700 (m_lineFrom
<= m_lineTo
&& m_lineTo
< GetItemCount()),
4701 _T("GetVisibleLinesRange() returns incorrect result") );
4709 // -------------------------------------------------------------------------------------
4710 // wxGenericListCtrl
4711 // -------------------------------------------------------------------------------------
4713 IMPLEMENT_DYNAMIC_CLASS(wxGenericListCtrl
, wxControl
)
4715 BEGIN_EVENT_TABLE(wxGenericListCtrl
,wxControl
)
4716 EVT_SIZE(wxGenericListCtrl::OnSize
)
4719 wxGenericListCtrl::wxGenericListCtrl()
4721 m_imageListNormal
= (wxImageListType
*) NULL
;
4722 m_imageListSmall
= (wxImageListType
*) NULL
;
4723 m_imageListState
= (wxImageListType
*) NULL
;
4725 m_ownsImageListNormal
=
4726 m_ownsImageListSmall
=
4727 m_ownsImageListState
= false;
4729 m_mainWin
= (wxListMainWindow
*) NULL
;
4730 m_headerWin
= (wxListHeaderWindow
*) NULL
;
4734 wxGenericListCtrl::~wxGenericListCtrl()
4736 if (m_ownsImageListNormal
)
4737 delete m_imageListNormal
;
4738 if (m_ownsImageListSmall
)
4739 delete m_imageListSmall
;
4740 if (m_ownsImageListState
)
4741 delete m_imageListState
;
4744 void wxGenericListCtrl::CalculateAndSetHeaderHeight()
4750 GetThemeMetric( kThemeMetricListHeaderHeight
, &h
);
4752 // we use 'g' to get the descent, too
4754 m_headerWin
->GetTextExtent(wxT("Hg"), &w
, &h
, &d
);
4755 h
+= d
+ 2 * HEADER_OFFSET_Y
+ EXTRA_HEIGHT
;
4757 // only update if changed
4758 if ( h
!= m_headerHeight
)
4762 m_headerWin
->SetSize(m_headerWin
->GetSize().x
, m_headerHeight
);
4765 ResizeReportView(true);
4770 void wxGenericListCtrl::CreateHeaderWindow()
4772 m_headerWin
= new wxListHeaderWindow
4774 this, wxID_ANY
, m_mainWin
,
4776 wxSize(GetClientSize().x
, m_headerHeight
),
4779 CalculateAndSetHeaderHeight();
4782 bool wxGenericListCtrl::Create(wxWindow
*parent
,
4787 const wxValidator
&validator
,
4788 const wxString
&name
)
4792 m_imageListState
= (wxImageListType
*) NULL
;
4793 m_ownsImageListNormal
=
4794 m_ownsImageListSmall
=
4795 m_ownsImageListState
= false;
4797 m_mainWin
= (wxListMainWindow
*) NULL
;
4798 m_headerWin
= (wxListHeaderWindow
*) NULL
;
4802 if ( !(style
& wxLC_MASK_TYPE
) )
4804 style
= style
| wxLC_LIST
;
4807 if ( !wxControl::Create( parent
, id
, pos
, size
, style
, validator
, name
) )
4810 // don't create the inner window with the border
4811 style
&= ~wxBORDER_MASK
;
4813 m_mainWin
= new wxListMainWindow( this, wxID_ANY
, wxPoint(0,0), size
, style
);
4815 #ifdef __WXMAC_CARBON__
4816 // Human Interface Guidelines ask us for a special font in this case
4817 if ( GetWindowVariant() == wxWINDOW_VARIANT_NORMAL
)
4820 font
.MacCreateThemeFont( kThemeViewsFont
) ;
4824 if ( InReportView() )
4826 CreateHeaderWindow();
4827 #ifdef __WXMAC_CARBON__
4831 font
.MacCreateThemeFont( kThemeSmallSystemFont
) ;
4832 m_headerWin
->SetFont( font
);
4833 CalculateAndSetHeaderHeight();
4836 if ( HasFlag(wxLC_NO_HEADER
) )
4838 // VZ: why do we create it at all then?
4839 m_headerWin
->Show( false );
4848 void wxGenericListCtrl::SetSingleStyle( long style
, bool add
)
4850 wxASSERT_MSG( !(style
& wxLC_VIRTUAL
),
4851 _T("wxLC_VIRTUAL can't be [un]set") );
4853 long flag
= GetWindowStyle();
4857 if (style
& wxLC_MASK_TYPE
)
4858 flag
&= ~(wxLC_MASK_TYPE
| wxLC_VIRTUAL
);
4859 if (style
& wxLC_MASK_ALIGN
)
4860 flag
&= ~wxLC_MASK_ALIGN
;
4861 if (style
& wxLC_MASK_SORT
)
4862 flag
&= ~wxLC_MASK_SORT
;
4874 SetWindowStyleFlag( flag
);
4877 void wxGenericListCtrl::SetWindowStyleFlag( long flag
)
4881 m_mainWin
->DeleteEverything();
4883 // has the header visibility changed?
4884 bool hasHeader
= HasHeader();
4885 bool willHaveHeader
= (flag
& wxLC_REPORT
) && !(flag
& wxLC_NO_HEADER
);
4887 if ( hasHeader
!= willHaveHeader
)
4894 // don't delete, just hide, as we can reuse it later
4895 m_headerWin
->Show(false);
4897 //else: nothing to do
4899 else // must show header
4903 CreateHeaderWindow();
4905 else // already have it, just show
4907 m_headerWin
->Show( true );
4911 ResizeReportView(willHaveHeader
);
4915 wxWindow::SetWindowStyleFlag( flag
);
4918 bool wxGenericListCtrl::GetColumn(int col
, wxListItem
&item
) const
4920 m_mainWin
->GetColumn( col
, item
);
4924 bool wxGenericListCtrl::SetColumn( int col
, wxListItem
& item
)
4926 m_mainWin
->SetColumn( col
, item
);
4930 int wxGenericListCtrl::GetColumnWidth( int col
) const
4932 return m_mainWin
->GetColumnWidth( col
);
4935 bool wxGenericListCtrl::SetColumnWidth( int col
, int width
)
4937 m_mainWin
->SetColumnWidth( col
, width
);
4941 int wxGenericListCtrl::GetCountPerPage() const
4943 return m_mainWin
->GetCountPerPage(); // different from Windows ?
4946 bool wxGenericListCtrl::GetItem( wxListItem
&info
) const
4948 m_mainWin
->GetItem( info
);
4952 bool wxGenericListCtrl::SetItem( wxListItem
&info
)
4954 m_mainWin
->SetItem( info
);
4958 long wxGenericListCtrl::SetItem( long index
, int col
, const wxString
& label
, int imageId
)
4961 info
.m_text
= label
;
4962 info
.m_mask
= wxLIST_MASK_TEXT
;
4963 info
.m_itemId
= index
;
4967 info
.m_image
= imageId
;
4968 info
.m_mask
|= wxLIST_MASK_IMAGE
;
4970 m_mainWin
->SetItem(info
);
4974 int wxGenericListCtrl::GetItemState( long item
, long stateMask
) const
4976 return m_mainWin
->GetItemState( item
, stateMask
);
4979 bool wxGenericListCtrl::SetItemState( long item
, long state
, long stateMask
)
4981 m_mainWin
->SetItemState( item
, state
, stateMask
);
4986 wxGenericListCtrl::SetItemImage( long item
, int image
, int WXUNUSED(selImage
) )
4989 info
.m_image
= image
;
4990 info
.m_mask
= wxLIST_MASK_IMAGE
;
4991 info
.m_itemId
= item
;
4992 m_mainWin
->SetItem( info
);
4996 wxString
wxGenericListCtrl::GetItemText( long item
) const
4998 return m_mainWin
->GetItemText(item
);
5001 void wxGenericListCtrl::SetItemText( long item
, const wxString
& str
)
5003 m_mainWin
->SetItemText(item
, str
);
5006 wxUIntPtr
wxGenericListCtrl::GetItemData( long item
) const
5009 info
.m_mask
= wxLIST_MASK_DATA
;
5010 info
.m_itemId
= item
;
5011 m_mainWin
->GetItem( info
);
5015 bool wxGenericListCtrl::SetItemData( long item
, long data
)
5018 info
.m_mask
= wxLIST_MASK_DATA
;
5019 info
.m_itemId
= item
;
5021 m_mainWin
->SetItem( info
);
5025 wxRect
wxGenericListCtrl::GetViewRect() const
5027 return m_mainWin
->GetViewRect();
5030 bool wxGenericListCtrl::GetItemRect( long item
, wxRect
&rect
, int WXUNUSED(code
) ) const
5032 m_mainWin
->GetItemRect( item
, rect
);
5033 if ( m_mainWin
->HasHeader() )
5034 rect
.y
+= m_headerHeight
+ 1;
5038 bool wxGenericListCtrl::GetItemPosition( long item
, wxPoint
& pos
) const
5040 m_mainWin
->GetItemPosition( item
, pos
);
5044 bool wxGenericListCtrl::SetItemPosition( long WXUNUSED(item
), const wxPoint
& WXUNUSED(pos
) )
5049 int wxGenericListCtrl::GetItemCount() const
5051 return m_mainWin
->GetItemCount();
5054 int wxGenericListCtrl::GetColumnCount() const
5056 return m_mainWin
->GetColumnCount();
5059 void wxGenericListCtrl::SetItemSpacing( int spacing
, bool isSmall
)
5061 m_mainWin
->SetItemSpacing( spacing
, isSmall
);
5064 wxSize
wxGenericListCtrl::GetItemSpacing() const
5066 const int spacing
= m_mainWin
->GetItemSpacing(HasFlag(wxLC_SMALL_ICON
));
5068 return wxSize(spacing
, spacing
);
5071 int wxGenericListCtrl::GetItemSpacing( bool isSmall
) const
5073 return m_mainWin
->GetItemSpacing( isSmall
);
5076 void wxGenericListCtrl::SetItemTextColour( long item
, const wxColour
&col
)
5079 info
.m_itemId
= item
;
5080 info
.SetTextColour( col
);
5081 m_mainWin
->SetItem( info
);
5084 wxColour
wxGenericListCtrl::GetItemTextColour( long item
) const
5087 info
.m_itemId
= item
;
5088 m_mainWin
->GetItem( info
);
5089 return info
.GetTextColour();
5092 void wxGenericListCtrl::SetItemBackgroundColour( long item
, const wxColour
&col
)
5095 info
.m_itemId
= item
;
5096 info
.SetBackgroundColour( col
);
5097 m_mainWin
->SetItem( info
);
5100 wxColour
wxGenericListCtrl::GetItemBackgroundColour( long item
) const
5103 info
.m_itemId
= item
;
5104 m_mainWin
->GetItem( info
);
5105 return info
.GetBackgroundColour();
5108 void wxGenericListCtrl::SetItemFont( long item
, const wxFont
&f
)
5111 info
.m_itemId
= item
;
5113 m_mainWin
->SetItem( info
);
5116 wxFont
wxGenericListCtrl::GetItemFont( long item
) const
5119 info
.m_itemId
= item
;
5120 m_mainWin
->GetItem( info
);
5121 return info
.GetFont();
5124 int wxGenericListCtrl::GetSelectedItemCount() const
5126 return m_mainWin
->GetSelectedItemCount();
5129 wxColour
wxGenericListCtrl::GetTextColour() const
5131 return GetForegroundColour();
5134 void wxGenericListCtrl::SetTextColour(const wxColour
& col
)
5136 SetForegroundColour(col
);
5139 long wxGenericListCtrl::GetTopItem() const
5142 m_mainWin
->GetVisibleLinesRange(&top
, NULL
);
5146 long wxGenericListCtrl::GetNextItem( long item
, int geom
, int state
) const
5148 return m_mainWin
->GetNextItem( item
, geom
, state
);
5151 wxImageListType
*wxGenericListCtrl::GetImageList(int which
) const
5153 if (which
== wxIMAGE_LIST_NORMAL
)
5155 return m_imageListNormal
;
5157 else if (which
== wxIMAGE_LIST_SMALL
)
5159 return m_imageListSmall
;
5161 else if (which
== wxIMAGE_LIST_STATE
)
5163 return m_imageListState
;
5165 return (wxImageListType
*) NULL
;
5168 void wxGenericListCtrl::SetImageList( wxImageListType
*imageList
, int which
)
5170 if ( which
== wxIMAGE_LIST_NORMAL
)
5172 if (m_ownsImageListNormal
) delete m_imageListNormal
;
5173 m_imageListNormal
= imageList
;
5174 m_ownsImageListNormal
= false;
5176 else if ( which
== wxIMAGE_LIST_SMALL
)
5178 if (m_ownsImageListSmall
) delete m_imageListSmall
;
5179 m_imageListSmall
= imageList
;
5180 m_ownsImageListSmall
= false;
5182 else if ( which
== wxIMAGE_LIST_STATE
)
5184 if (m_ownsImageListState
) delete m_imageListState
;
5185 m_imageListState
= imageList
;
5186 m_ownsImageListState
= false;
5189 m_mainWin
->SetImageList( imageList
, which
);
5192 void wxGenericListCtrl::AssignImageList(wxImageListType
*imageList
, int which
)
5194 SetImageList(imageList
, which
);
5195 if ( which
== wxIMAGE_LIST_NORMAL
)
5196 m_ownsImageListNormal
= true;
5197 else if ( which
== wxIMAGE_LIST_SMALL
)
5198 m_ownsImageListSmall
= true;
5199 else if ( which
== wxIMAGE_LIST_STATE
)
5200 m_ownsImageListState
= true;
5203 bool wxGenericListCtrl::Arrange( int WXUNUSED(flag
) )
5208 bool wxGenericListCtrl::DeleteItem( long item
)
5210 m_mainWin
->DeleteItem( item
);
5214 bool wxGenericListCtrl::DeleteAllItems()
5216 m_mainWin
->DeleteAllItems();
5220 bool wxGenericListCtrl::DeleteAllColumns()
5222 size_t count
= m_mainWin
->m_columns
.GetCount();
5223 for ( size_t n
= 0; n
< count
; n
++ )
5229 void wxGenericListCtrl::ClearAll()
5231 m_mainWin
->DeleteEverything();
5234 bool wxGenericListCtrl::DeleteColumn( int col
)
5236 m_mainWin
->DeleteColumn( col
);
5238 // if we don't have the header any longer, we need to relayout the window
5239 if ( !GetColumnCount() )
5241 ResizeReportView(false /* no header */);
5247 void wxGenericListCtrl::Edit( long item
)
5249 m_mainWin
->EditLabel( item
);
5252 bool wxGenericListCtrl::EnsureVisible( long item
)
5254 m_mainWin
->EnsureVisible( item
);
5258 long wxGenericListCtrl::FindItem( long start
, const wxString
& str
, bool partial
)
5260 return m_mainWin
->FindItem( start
, str
, partial
);
5263 long wxGenericListCtrl::FindItem( long start
, wxUIntPtr data
)
5265 return m_mainWin
->FindItem( start
, data
);
5268 long wxGenericListCtrl::FindItem( long WXUNUSED(start
), const wxPoint
& pt
,
5269 int WXUNUSED(direction
))
5271 return m_mainWin
->FindItem( pt
);
5274 long wxGenericListCtrl::HitTest( const wxPoint
&point
, int &flags
)
5276 return m_mainWin
->HitTest( (int)point
.x
, (int)point
.y
, flags
);
5279 long wxGenericListCtrl::InsertItem( wxListItem
& info
)
5281 m_mainWin
->InsertItem( info
);
5282 return info
.m_itemId
;
5285 long wxGenericListCtrl::InsertItem( long index
, const wxString
&label
)
5288 info
.m_text
= label
;
5289 info
.m_mask
= wxLIST_MASK_TEXT
;
5290 info
.m_itemId
= index
;
5291 return InsertItem( info
);
5294 long wxGenericListCtrl::InsertItem( long index
, int imageIndex
)
5297 info
.m_mask
= wxLIST_MASK_IMAGE
;
5298 info
.m_image
= imageIndex
;
5299 info
.m_itemId
= index
;
5300 return InsertItem( info
);
5303 long wxGenericListCtrl::InsertItem( long index
, const wxString
&label
, int imageIndex
)
5306 info
.m_text
= label
;
5307 info
.m_image
= imageIndex
;
5308 info
.m_mask
= wxLIST_MASK_TEXT
| wxLIST_MASK_IMAGE
;
5309 info
.m_itemId
= index
;
5310 return InsertItem( info
);
5313 long wxGenericListCtrl::InsertColumn( long col
, wxListItem
&item
)
5315 wxCHECK_MSG( m_headerWin
, -1, _T("can't add column in non report mode") );
5317 m_mainWin
->InsertColumn( col
, item
);
5319 // if we hadn't had header before and have it now we need to relayout the
5321 if ( GetColumnCount() == 1 && m_mainWin
->HasHeader() )
5323 ResizeReportView(true /* have header */);
5326 m_headerWin
->Refresh();
5331 long wxGenericListCtrl::InsertColumn( long col
, const wxString
&heading
,
5332 int format
, int width
)
5335 item
.m_mask
= wxLIST_MASK_TEXT
| wxLIST_MASK_FORMAT
;
5336 item
.m_text
= heading
;
5339 item
.m_mask
|= wxLIST_MASK_WIDTH
;
5340 item
.m_width
= width
;
5342 item
.m_format
= format
;
5344 return InsertColumn( col
, item
);
5347 bool wxGenericListCtrl::ScrollList( int WXUNUSED(dx
), int WXUNUSED(dy
) )
5353 // fn is a function which takes 3 long arguments: item1, item2, data.
5354 // item1 is the long data associated with a first item (NOT the index).
5355 // item2 is the long data associated with a second item (NOT the index).
5356 // data is the same value as passed to SortItems.
5357 // The return value is a negative number if the first item should precede the second
5358 // item, a positive number of the second item should precede the first,
5359 // or zero if the two items are equivalent.
5360 // data is arbitrary data to be passed to the sort function.
5362 bool wxGenericListCtrl::SortItems( wxListCtrlCompare fn
, long data
)
5364 m_mainWin
->SortItems( fn
, data
);
5368 // ----------------------------------------------------------------------------
5370 // ----------------------------------------------------------------------------
5372 void wxGenericListCtrl::OnSize(wxSizeEvent
& WXUNUSED(event
))
5377 ResizeReportView(m_mainWin
->HasHeader());
5379 m_mainWin
->RecalculatePositions();
5382 void wxGenericListCtrl::ResizeReportView(bool showHeader
)
5385 GetClientSize( &cw
, &ch
);
5389 m_headerWin
->SetSize( 0, 0, cw
, m_headerHeight
);
5390 m_mainWin
->SetSize( 0, m_headerHeight
+ 1, cw
, ch
- m_headerHeight
- 1 );
5392 else // no header window
5394 m_mainWin
->SetSize( 0, 0, cw
, ch
);
5398 void wxGenericListCtrl::OnInternalIdle()
5400 wxWindow::OnInternalIdle();
5402 // do it only if needed
5403 if ( !m_mainWin
->m_dirty
)
5406 m_mainWin
->RecalculatePositions();
5409 // ----------------------------------------------------------------------------
5411 // ----------------------------------------------------------------------------
5413 bool wxGenericListCtrl::SetBackgroundColour( const wxColour
&colour
)
5417 m_mainWin
->SetBackgroundColour( colour
);
5418 m_mainWin
->m_dirty
= true;
5424 bool wxGenericListCtrl::SetForegroundColour( const wxColour
&colour
)
5426 if ( !wxWindow::SetForegroundColour( colour
) )
5431 m_mainWin
->SetForegroundColour( colour
);
5432 m_mainWin
->m_dirty
= true;
5437 m_headerWin
->SetForegroundColour( colour
);
5443 bool wxGenericListCtrl::SetFont( const wxFont
&font
)
5445 if ( !wxWindow::SetFont( font
) )
5450 m_mainWin
->SetFont( font
);
5451 m_mainWin
->m_dirty
= true;
5456 m_headerWin
->SetFont( font
);
5457 CalculateAndSetHeaderHeight();
5468 #include "wx/listbox.h"
5473 wxGenericListCtrl::GetClassDefaultAttributes(wxWindowVariant variant
)
5476 // Use the same color scheme as wxListBox
5477 return wxListBox::GetClassDefaultAttributes(variant
);
5479 wxUnusedVar(variant
);
5480 wxVisualAttributes attr
;
5481 attr
.colFg
= wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT
);
5482 attr
.colBg
= wxSystemSettings::GetColour(wxSYS_COLOUR_LISTBOX
);
5483 attr
.font
= wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT
);
5488 // ----------------------------------------------------------------------------
5489 // methods forwarded to m_mainWin
5490 // ----------------------------------------------------------------------------
5492 #if wxUSE_DRAG_AND_DROP
5494 void wxGenericListCtrl::SetDropTarget( wxDropTarget
*dropTarget
)
5496 m_mainWin
->SetDropTarget( dropTarget
);
5499 wxDropTarget
*wxGenericListCtrl::GetDropTarget() const
5501 return m_mainWin
->GetDropTarget();
5504 #endif // wxUSE_DRAG_AND_DROP
5506 bool wxGenericListCtrl::SetCursor( const wxCursor
&cursor
)
5508 return m_mainWin
? m_mainWin
->wxWindow::SetCursor(cursor
) : false;
5511 wxColour
wxGenericListCtrl::GetBackgroundColour() const
5513 return m_mainWin
? m_mainWin
->GetBackgroundColour() : wxColour();
5516 wxColour
wxGenericListCtrl::GetForegroundColour() const
5518 return m_mainWin
? m_mainWin
->GetForegroundColour() : wxColour();
5521 bool wxGenericListCtrl::DoPopupMenu( wxMenu
*menu
, int x
, int y
)
5524 return m_mainWin
->PopupMenu( menu
, x
, y
);
5527 #endif // wxUSE_MENUS
5530 void wxGenericListCtrl::SetFocus()
5532 /* The test in window.cpp fails as we are a composite
5533 window, so it checks against "this", but not m_mainWin. */
5534 if ( DoFindFocus() != this )
5535 m_mainWin
->SetFocus();
5538 wxSize
wxGenericListCtrl::DoGetBestSize() const
5540 // Something is better than nothing...
5541 // 100x80 is what the MSW version will get from the default
5542 // wxControl::DoGetBestSize
5543 return wxSize(100,80);
5546 // ----------------------------------------------------------------------------
5547 // virtual list control support
5548 // ----------------------------------------------------------------------------
5550 wxString
wxGenericListCtrl::OnGetItemText(long WXUNUSED(item
), long WXUNUSED(col
)) const
5552 // this is a pure virtual function, in fact - which is not really pure
5553 // because the controls which are not virtual don't need to implement it
5554 wxFAIL_MSG( _T("wxGenericListCtrl::OnGetItemText not supposed to be called") );
5556 return wxEmptyString
;
5559 int wxGenericListCtrl::OnGetItemImage(long WXUNUSED(item
)) const
5561 wxCHECK_MSG(!GetImageList(wxIMAGE_LIST_SMALL
),
5563 wxT("List control has an image list, OnGetItemImage should be overridden."));
5568 wxGenericListCtrl::OnGetItemAttr(long WXUNUSED_UNLESS_DEBUG(item
)) const
5570 wxASSERT_MSG( item
>= 0 && item
< GetItemCount(),
5571 _T("invalid item index in OnGetItemAttr()") );
5573 // no attributes by default
5577 void wxGenericListCtrl::SetItemCount(long count
)
5579 wxASSERT_MSG( IsVirtual(), _T("this is for virtual controls only") );
5581 m_mainWin
->SetItemCount(count
);
5584 void wxGenericListCtrl::RefreshItem(long item
)
5586 m_mainWin
->RefreshLine(item
);
5589 void wxGenericListCtrl::RefreshItems(long itemFrom
, long itemTo
)
5591 m_mainWin
->RefreshLines(itemFrom
, itemTo
);
5595 * Generic wxListCtrl is more or less a container for two other
5596 * windows which drawings are done upon. These are namely
5597 * 'm_headerWin' and 'm_mainWin'.
5598 * Here we override 'virtual wxWindow::Refresh()' to mimic the
5599 * behaviour wxListCtrl has under wxMSW.
5601 void wxGenericListCtrl::Refresh(bool eraseBackground
, const wxRect
*rect
)
5605 // The easy case, no rectangle specified.
5607 m_headerWin
->Refresh(eraseBackground
);
5610 m_mainWin
->Refresh(eraseBackground
);
5614 // Refresh the header window
5617 wxRect rectHeader
= m_headerWin
->GetRect();
5618 rectHeader
.Intersect(*rect
);
5619 if (rectHeader
.GetWidth() && rectHeader
.GetHeight())
5622 m_headerWin
->GetPosition(&x
, &y
);
5623 rectHeader
.Offset(-x
, -y
);
5624 m_headerWin
->Refresh(eraseBackground
, &rectHeader
);
5629 // Refresh the main window
5632 wxRect rectMain
= m_mainWin
->GetRect();
5633 rectMain
.Intersect(*rect
);
5634 if (rectMain
.GetWidth() && rectMain
.GetHeight())
5637 m_mainWin
->GetPosition(&x
, &y
);
5638 rectMain
.Offset(-x
, -y
);
5639 m_mainWin
->Refresh(eraseBackground
, &rectMain
);
5645 void wxGenericListCtrl::Freeze()
5647 m_mainWin
->Freeze();
5650 void wxGenericListCtrl::Thaw()
5655 #endif // wxUSE_LISTCTRL