1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/generic/listctrl.cpp
3 // Purpose: generic implementation of wxListCtrl
4 // Author: Robert Roebling
5 // Vadim Zeitlin (virtual list control support)
7 // Copyright: (c) 1998 Robert Roebling
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
13 // 1. we need to implement searching/sorting for virtual controls somehow
14 // 2. when changing selection the lines are refreshed twice
17 // For compilers that support precompilation, includes "wx.h".
18 #include "wx/wxprec.h"
26 #include "wx/listctrl.h"
28 #if (!defined(__WXMSW__) || defined(__WXUNIVERSAL__)) && !defined(__WXMAC__)
29 // if we have a native version, its implementation file does all this
30 IMPLEMENT_DYNAMIC_CLASS(wxListItem
, wxObject
)
31 IMPLEMENT_DYNAMIC_CLASS(wxListView
, wxListCtrl
)
32 IMPLEMENT_DYNAMIC_CLASS(wxListEvent
, wxNotifyEvent
)
34 IMPLEMENT_DYNAMIC_CLASS(wxListCtrl
, wxGenericListCtrl
)
38 #include "wx/scrolwin.h"
40 #include "wx/settings.h"
41 #include "wx/dynarray.h"
42 #include "wx/dcclient.h"
43 #include "wx/dcscreen.h"
47 #include "wx/imaglist.h"
48 #include "wx/selstore.h"
49 #include "wx/renderer.h"
52 #include "wx/mac/private.h"
56 // NOTE: If using the wxListBox visual attributes works everywhere then this can
57 // be removed, as well as the #else case below.
58 #define _USE_VISATTR 0
61 // ----------------------------------------------------------------------------
63 // ----------------------------------------------------------------------------
65 // // the height of the header window (FIXME: should depend on its font!)
66 // static const int HEADER_HEIGHT = 23;
68 static const int SCROLL_UNIT_X
= 15;
70 // the spacing between the lines (in report mode)
71 static const int LINE_SPACING
= 0;
73 // extra margins around the text label
75 static const int EXTRA_WIDTH
= 6;
77 static const int EXTRA_WIDTH
= 4;
79 static const int EXTRA_HEIGHT
= 4;
81 // margin between the window and the items
82 static const int EXTRA_BORDER_X
= 2;
83 static const int EXTRA_BORDER_Y
= 2;
85 // offset for the header window
86 static const int HEADER_OFFSET_X
= 1;
87 static const int HEADER_OFFSET_Y
= 1;
89 // margin between rows of icons in [small] icon view
90 static const int MARGIN_BETWEEN_ROWS
= 6;
92 // when autosizing the columns, add some slack
93 static const int AUTOSIZE_COL_MARGIN
= 10;
95 // default width for the header columns
96 static const int WIDTH_COL_DEFAULT
= 80;
98 // the space between the image and the text in the report mode
99 static const int IMAGE_MARGIN_IN_REPORT_MODE
= 5;
101 // ============================================================================
103 // ============================================================================
105 //-----------------------------------------------------------------------------
106 // wxColWidthInfo (internal)
107 //-----------------------------------------------------------------------------
109 struct wxColWidthInfo
112 bool bNeedsUpdate
; // only set to true when an item whose
113 // width == nMaxWidth is removed
115 wxColWidthInfo(int w
= 0, bool needsUpdate
= false)
118 bNeedsUpdate
= needsUpdate
;
122 WX_DEFINE_ARRAY_PTR(wxColWidthInfo
*, ColWidthArray
);
124 //-----------------------------------------------------------------------------
125 // wxListItemData (internal)
126 //-----------------------------------------------------------------------------
131 wxListItemData(wxListMainWindow
*owner
);
134 void SetItem( const wxListItem
&info
);
135 void SetImage( int image
) { m_image
= image
; }
136 void SetData( wxUIntPtr data
) { m_data
= data
; }
137 void SetPosition( int x
, int y
);
138 void SetSize( int width
, int height
);
140 bool HasText() const { return !m_text
.empty(); }
141 const wxString
& GetText() const { return m_text
; }
142 void SetText(const wxString
& text
) { m_text
= text
; }
144 // we can't use empty string for measuring the string width/height, so
145 // always return something
146 wxString
GetTextForMeasuring() const
148 wxString s
= GetText();
155 bool IsHit( int x
, int y
) const;
159 int GetWidth() const;
160 int GetHeight() const;
162 int GetImage() const { return m_image
; }
163 bool HasImage() const { return GetImage() != -1; }
165 void GetItem( wxListItem
&info
) const;
167 void SetAttr(wxListItemAttr
*attr
) { m_attr
= attr
; }
168 wxListItemAttr
*GetAttr() const { return m_attr
; }
171 // the item image or -1
174 // user data associated with the item
177 // the item coordinates are not used in report mode; instead this pointer is
178 // NULL and the owner window is used to retrieve the item position and size
181 // the list ctrl we are in
182 wxListMainWindow
*m_owner
;
184 // custom attributes or NULL
185 wxListItemAttr
*m_attr
;
188 // common part of all ctors
194 //-----------------------------------------------------------------------------
195 // wxListHeaderData (internal)
196 //-----------------------------------------------------------------------------
198 class wxListHeaderData
: public wxObject
202 wxListHeaderData( const wxListItem
&info
);
203 void SetItem( const wxListItem
&item
);
204 void SetPosition( int x
, int y
);
205 void SetWidth( int w
);
206 void SetState( int state
);
207 void SetFormat( int format
);
208 void SetHeight( int h
);
209 bool HasImage() const;
211 bool HasText() const { return !m_text
.empty(); }
212 const wxString
& GetText() const { return m_text
; }
213 void SetText(const wxString
& text
) { m_text
= text
; }
215 void GetItem( wxListItem
&item
);
217 bool IsHit( int x
, int y
) const;
218 int GetImage() const;
219 int GetWidth() const;
220 int GetFormat() const;
221 int GetState() const;
238 //-----------------------------------------------------------------------------
239 // wxListLineData (internal)
240 //-----------------------------------------------------------------------------
242 WX_DECLARE_EXPORTED_LIST(wxListItemData
, wxListItemDataList
);
243 #include "wx/listimpl.cpp"
244 WX_DEFINE_LIST(wxListItemDataList
)
249 // the list of subitems: only may have more than one item in report mode
250 wxListItemDataList m_items
;
252 // this is not used in report view
264 // the part to be highlighted
265 wxRect m_rectHighlight
;
267 // extend all our rects to be centered inside the one of given width
268 void ExtendWidth(wxCoord w
)
270 wxASSERT_MSG( m_rectAll
.width
<= w
,
271 _T("width can only be increased") );
274 m_rectLabel
.x
= m_rectAll
.x
+ (w
- m_rectLabel
.width
) / 2;
275 m_rectIcon
.x
= m_rectAll
.x
+ (w
- m_rectIcon
.width
) / 2;
276 m_rectHighlight
.x
= m_rectAll
.x
+ (w
- m_rectHighlight
.width
) / 2;
281 // is this item selected? [NB: not used in virtual mode]
284 // back pointer to the list ctrl
285 wxListMainWindow
*m_owner
;
288 wxListLineData(wxListMainWindow
*owner
);
292 WX_CLEAR_LIST(wxListItemDataList
, m_items
);
296 // are we in report mode?
297 inline bool InReportView() const;
299 // are we in virtual report mode?
300 inline bool IsVirtual() const;
302 // these 2 methods shouldn't be called for report view controls, in that
303 // case we determine our position/size ourselves
305 // calculate the size of the line
306 void CalculateSize( wxDC
*dc
, int spacing
);
308 // remember the position this line appears at
309 void SetPosition( int x
, int y
, int spacing
);
313 void SetImage( int image
) { SetImage(0, image
); }
314 int GetImage() const { return GetImage(0); }
315 void SetImage( int index
, int image
);
316 int GetImage( int index
) const;
318 bool HasImage() const { return GetImage() != -1; }
319 bool HasText() const { return !GetText(0).empty(); }
321 void SetItem( int index
, const wxListItem
&info
);
322 void GetItem( int index
, wxListItem
&info
);
324 wxString
GetText(int index
) const;
325 void SetText( int index
, const wxString
& s
);
327 wxListItemAttr
*GetAttr() const;
328 void SetAttr(wxListItemAttr
*attr
);
330 // return true if the highlighting really changed
331 bool Highlight( bool on
);
333 void ReverseHighlight();
335 bool IsHighlighted() const
337 wxASSERT_MSG( !IsVirtual(), _T("unexpected call to IsHighlighted") );
339 return m_highlighted
;
342 // draw the line on the given DC in icon/list mode
343 void Draw( wxDC
*dc
);
345 // the same in report mode
346 void DrawInReportMode( wxDC
*dc
,
348 const wxRect
& rectHL
,
352 // set the line to contain num items (only can be > 1 in report mode)
353 void InitItems( int num
);
355 // get the mode (i.e. style) of the list control
356 inline int GetMode() const;
358 // prepare the DC for drawing with these item's attributes, return true if
359 // we need to draw the items background to highlight it, false otherwise
360 bool SetAttributes(wxDC
*dc
,
361 const wxListItemAttr
*attr
,
364 // draw the text on the DC with the correct justification; also add an
365 // ellipsis if the text is too large to fit in the current width
366 void DrawTextFormatted(wxDC
*dc
,
367 const wxString
&text
,
370 int yMid
, // this is middle, not top, of the text
374 WX_DECLARE_EXPORTED_OBJARRAY(wxListLineData
, wxListLineDataArray
);
375 #include "wx/arrimpl.cpp"
376 WX_DEFINE_OBJARRAY(wxListLineDataArray
)
378 //-----------------------------------------------------------------------------
379 // wxListHeaderWindow (internal)
380 //-----------------------------------------------------------------------------
382 class wxListHeaderWindow
: public wxWindow
385 wxListMainWindow
*m_owner
;
386 const wxCursor
*m_currentCursor
;
387 wxCursor
*m_resizeCursor
;
390 // column being resized or -1
393 // divider line position in logical (unscrolled) coords
396 // minimal position beyond which the divider line
397 // can't be dragged in logical coords
401 wxListHeaderWindow();
403 wxListHeaderWindow( wxWindow
*win
,
405 wxListMainWindow
*owner
,
406 const wxPoint
&pos
= wxDefaultPosition
,
407 const wxSize
&size
= wxDefaultSize
,
409 const wxString
&name
= wxT("wxlistctrlcolumntitles") );
411 virtual ~wxListHeaderWindow();
414 void AdjustDC( wxDC
& dc
);
416 void OnPaint( wxPaintEvent
&event
);
417 void OnMouse( wxMouseEvent
&event
);
418 void OnSetFocus( wxFocusEvent
&event
);
424 // common part of all ctors
427 // generate and process the list event of the given type, return true if
428 // it wasn't vetoed, i.e. if we should proceed
429 bool SendListEvent(wxEventType type
, const wxPoint
& pos
);
431 DECLARE_DYNAMIC_CLASS(wxListHeaderWindow
)
432 DECLARE_EVENT_TABLE()
435 //-----------------------------------------------------------------------------
436 // wxListRenameTimer (internal)
437 //-----------------------------------------------------------------------------
439 class wxListRenameTimer
: public wxTimer
442 wxListMainWindow
*m_owner
;
445 wxListRenameTimer( wxListMainWindow
*owner
);
449 //-----------------------------------------------------------------------------
450 // wxListTextCtrlWrapper: wraps a wxTextCtrl to make it work for inline editing
451 //-----------------------------------------------------------------------------
453 class wxListTextCtrlWrapper
: public wxEvtHandler
456 // NB: text must be a valid object but not Create()d yet
457 wxListTextCtrlWrapper(wxListMainWindow
*owner
,
461 wxTextCtrl
*GetText() const { return m_text
; }
463 void AcceptChangesAndFinish();
466 void OnChar( wxKeyEvent
&event
);
467 void OnKeyUp( wxKeyEvent
&event
);
468 void OnKillFocus( wxFocusEvent
&event
);
470 bool AcceptChanges();
474 wxListMainWindow
*m_owner
;
476 wxString m_startValue
;
479 bool m_aboutToFinish
;
481 DECLARE_EVENT_TABLE()
484 //-----------------------------------------------------------------------------
485 // wxListMainWindow (internal)
486 //-----------------------------------------------------------------------------
488 WX_DECLARE_EXPORTED_LIST(wxListHeaderData
, wxListHeaderDataList
);
489 #include "wx/listimpl.cpp"
490 WX_DEFINE_LIST(wxListHeaderDataList
)
492 class wxListMainWindow
: public wxScrolledWindow
496 wxListMainWindow( wxWindow
*parent
,
498 const wxPoint
& pos
= wxDefaultPosition
,
499 const wxSize
& size
= wxDefaultSize
,
501 const wxString
&name
= _T("listctrlmainwindow") );
503 virtual ~wxListMainWindow();
505 bool HasFlag(int flag
) const { return m_parent
->HasFlag(flag
); }
507 // return true if this is a virtual list control
508 bool IsVirtual() const { return HasFlag(wxLC_VIRTUAL
); }
510 // return true if the control is in report mode
511 bool InReportView() const { return HasFlag(wxLC_REPORT
); }
513 // return true if we are in single selection mode, false if multi sel
514 bool IsSingleSel() const { return HasFlag(wxLC_SINGLE_SEL
); }
516 // do we have a header window?
517 bool HasHeader() const
518 { return InReportView() && !HasFlag(wxLC_NO_HEADER
); }
520 void HighlightAll( bool on
);
522 // all these functions only do something if the line is currently visible
524 // change the line "selected" state, return true if it really changed
525 bool HighlightLine( size_t line
, bool highlight
= true);
527 // as HighlightLine() but do it for the range of lines: this is incredibly
528 // more efficient for virtual list controls!
530 // NB: unlike HighlightLine() this one does refresh the lines on screen
531 void HighlightLines( size_t lineFrom
, size_t lineTo
, bool on
= true );
533 // toggle the line state and refresh it
534 void ReverseHighlight( size_t line
)
535 { HighlightLine(line
, !IsHighlighted(line
)); RefreshLine(line
); }
537 // return true if the line is highlighted
538 bool IsHighlighted(size_t line
) const;
540 // refresh one or several lines at once
541 void RefreshLine( size_t line
);
542 void RefreshLines( size_t lineFrom
, size_t lineTo
);
544 // refresh all selected items
545 void RefreshSelected();
547 // refresh all lines below the given one: the difference with
548 // RefreshLines() is that the index here might not be a valid one (happens
549 // when the last line is deleted)
550 void RefreshAfter( size_t lineFrom
);
552 // the methods which are forwarded to wxListLineData itself in list/icon
553 // modes but are here because the lines don't store their positions in the
556 // get the bound rect for the entire line
557 wxRect
GetLineRect(size_t line
) const;
559 // get the bound rect of the label
560 wxRect
GetLineLabelRect(size_t line
) const;
562 // get the bound rect of the items icon (only may be called if we do have
564 wxRect
GetLineIconRect(size_t line
) const;
566 // get the rect to be highlighted when the item has focus
567 wxRect
GetLineHighlightRect(size_t line
) const;
569 // get the size of the total line rect
570 wxSize
GetLineSize(size_t line
) const
571 { return GetLineRect(line
).GetSize(); }
573 // return the hit code for the corresponding position (in this line)
574 long HitTestLine(size_t line
, int x
, int y
) const;
576 // bring the selected item into view, scrolling to it if necessary
577 void MoveToItem(size_t item
);
579 // bring the current item into view
580 void MoveToFocus() { MoveToItem(m_current
); }
582 // start editing the label of the given item
583 wxTextCtrl
*EditLabel(long item
,
584 wxClassInfo
* textControlClass
= CLASSINFO(wxTextCtrl
));
585 wxTextCtrl
*GetEditControl() const
587 return m_textctrlWrapper
? m_textctrlWrapper
->GetText() : NULL
;
590 void FinishEditing(wxTextCtrl
*text
)
593 m_textctrlWrapper
= NULL
;
594 SetFocusIgnoringChildren();
597 // suspend/resume redrawing the control
601 void OnRenameTimer();
602 bool OnRenameAccept(size_t itemEdit
, const wxString
& value
);
603 void OnRenameCancelled(size_t itemEdit
);
605 void OnMouse( wxMouseEvent
&event
);
607 // called to switch the selection from the current item to newCurrent,
608 void OnArrowChar( size_t newCurrent
, const wxKeyEvent
& event
);
610 void OnChar( wxKeyEvent
&event
);
611 void OnKeyDown( wxKeyEvent
&event
);
612 void OnSetFocus( wxFocusEvent
&event
);
613 void OnKillFocus( wxFocusEvent
&event
);
614 void OnScroll( wxScrollWinEvent
& event
);
616 void OnPaint( wxPaintEvent
&event
);
618 void DrawImage( int index
, wxDC
*dc
, int x
, int y
);
619 void GetImageSize( int index
, int &width
, int &height
) const;
620 int GetTextLength( const wxString
&s
) const;
622 void SetImageList( wxImageList
*imageList
, int which
);
623 void SetItemSpacing( int spacing
, bool isSmall
= false );
624 int GetItemSpacing( bool isSmall
= false );
626 void SetColumn( int col
, wxListItem
&item
);
627 void SetColumnWidth( int col
, int width
);
628 void GetColumn( int col
, wxListItem
&item
) const;
629 int GetColumnWidth( int col
) const;
630 int GetColumnCount() const { return m_columns
.GetCount(); }
632 // returns the sum of the heights of all columns
633 int GetHeaderWidth() const;
635 int GetCountPerPage() const;
637 void SetItem( wxListItem
&item
);
638 void GetItem( wxListItem
&item
) const;
639 void SetItemState( long item
, long state
, long stateMask
);
640 void SetItemStateAll( long state
, long stateMask
);
641 int GetItemState( long item
, long stateMask
) const;
642 void GetItemRect( long index
, wxRect
&rect
) const;
643 wxRect
GetViewRect() const;
644 bool GetItemPosition( long item
, wxPoint
& pos
) const;
645 int GetSelectedItemCount() const;
647 wxString
GetItemText(long item
) const
650 info
.m_mask
= wxLIST_MASK_TEXT
;
651 info
.m_itemId
= item
;
656 void SetItemText(long item
, const wxString
& value
)
659 info
.m_mask
= wxLIST_MASK_TEXT
;
660 info
.m_itemId
= item
;
665 // set the scrollbars and update the positions of the items
666 void RecalculatePositions(bool noRefresh
= false);
668 // refresh the window and the header
671 long GetNextItem( long item
, int geometry
, int state
) const;
672 void DeleteItem( long index
);
673 void DeleteAllItems();
674 void DeleteColumn( int col
);
675 void DeleteEverything();
676 void EnsureVisible( long index
);
677 long FindItem( long start
, const wxString
& str
, bool partial
= false );
678 long FindItem( long start
, wxUIntPtr data
);
679 long FindItem( const wxPoint
& pt
);
680 long HitTest( int x
, int y
, int &flags
) const;
681 void InsertItem( wxListItem
&item
);
682 void InsertColumn( long col
, wxListItem
&item
);
683 int GetItemWidthWithImage(wxListItem
* item
);
684 void SortItems( wxListCtrlCompare fn
, long data
);
686 size_t GetItemCount() const;
687 bool IsEmpty() const { return GetItemCount() == 0; }
688 void SetItemCount(long count
);
690 // change the current (== focused) item, send a notification event
691 void ChangeCurrent(size_t current
);
692 void ResetCurrent() { ChangeCurrent((size_t)-1); }
693 bool HasCurrent() const { return m_current
!= (size_t)-1; }
695 // send out a wxListEvent
696 void SendNotify( size_t line
,
698 const wxPoint
& point
= wxDefaultPosition
);
700 // override base class virtual to reset m_lineHeight when the font changes
701 virtual bool SetFont(const wxFont
& font
)
703 if ( !wxScrolledWindow::SetFont(font
) )
711 // these are for wxListLineData usage only
713 // get the backpointer to the list ctrl
714 wxGenericListCtrl
*GetListCtrl() const
716 return wxStaticCast(GetParent(), wxGenericListCtrl
);
719 // get the height of all lines (assuming they all do have the same height)
720 wxCoord
GetLineHeight() const;
722 // get the y position of the given line (only for report view)
723 wxCoord
GetLineY(size_t line
) const;
725 // get the brush to use for the item highlighting
726 wxBrush
*GetHighlightBrush() const
728 return m_hasFocus
? m_highlightBrush
: m_highlightUnfocusedBrush
;
731 bool HasFocus() const
737 // the array of all line objects for a non virtual list control (for the
738 // virtual list control we only ever use m_lines[0])
739 wxListLineDataArray m_lines
;
741 // the list of column objects
742 wxListHeaderDataList m_columns
;
744 // currently focused item or -1
747 // the number of lines per page
750 // this flag is set when something which should result in the window
751 // redrawing happens (i.e. an item was added or deleted, or its appearance
752 // changed) and OnPaint() doesn't redraw the window while it is set which
753 // allows to minimize the number of repaintings when a lot of items are
754 // being added. The real repainting occurs only after the next OnIdle()
758 wxColour
*m_highlightColour
;
759 wxImageList
*m_small_image_list
;
760 wxImageList
*m_normal_image_list
;
762 int m_normal_spacing
;
766 wxTimer
*m_renameTimer
;
770 ColWidthArray m_aColWidths
;
772 // for double click logic
773 size_t m_lineLastClicked
,
774 m_lineBeforeLastClicked
,
775 m_lineSelectSingleOnUp
;
778 wxWindow
*GetMainWindowOfCompositeControl() { return GetParent(); }
780 // the total count of items in a virtual list control
783 // the object maintaining the items selection state, only used in virtual
785 wxSelectionStore m_selStore
;
787 // common part of all ctors
790 // get the line data for the given index
791 wxListLineData
*GetLine(size_t n
) const
793 wxASSERT_MSG( n
!= (size_t)-1, _T("invalid line index") );
797 wxConstCast(this, wxListMainWindow
)->CacheLineData(n
);
804 // get a dummy line which can be used for geometry calculations and such:
805 // you must use GetLine() if you want to really draw the line
806 wxListLineData
*GetDummyLine() const;
808 // cache the line data of the n-th line in m_lines[0]
809 void CacheLineData(size_t line
);
811 // get the range of visible lines
812 void GetVisibleLinesRange(size_t *from
, size_t *to
);
814 // force us to recalculate the range of visible lines
815 void ResetVisibleLinesRange() { m_lineFrom
= (size_t)-1; }
817 // get the colour to be used for drawing the rules
818 wxColour
GetRuleColour() const
820 return wxSystemSettings::GetColour(wxSYS_COLOUR_3DLIGHT
);
824 // initialize the current item if needed
825 void UpdateCurrent();
827 // delete all items but don't refresh: called from dtor
828 void DoDeleteAllItems();
830 // the height of one line using the current font
831 wxCoord m_lineHeight
;
833 // the total header width or 0 if not calculated yet
834 wxCoord m_headerWidth
;
836 // the first and last lines being shown on screen right now (inclusive),
837 // both may be -1 if they must be calculated so never access them directly:
838 // use GetVisibleLinesRange() above instead
842 // the brushes to use for item highlighting when we do/don't have focus
843 wxBrush
*m_highlightBrush
,
844 *m_highlightUnfocusedBrush
;
846 // if this is > 0, the control is frozen and doesn't redraw itself
847 size_t m_freezeCount
;
849 // wrapper around the text control currently used for in place editing or
850 // NULL if no item is being edited
851 wxListTextCtrlWrapper
*m_textctrlWrapper
;
854 DECLARE_DYNAMIC_CLASS(wxListMainWindow
)
855 DECLARE_EVENT_TABLE()
857 friend class wxGenericListCtrl
;
861 wxListItemData::~wxListItemData()
863 // in the virtual list control the attributes are managed by the main
864 // program, so don't delete them
865 if ( !m_owner
->IsVirtual() )
871 void wxListItemData::Init()
879 wxListItemData::wxListItemData(wxListMainWindow
*owner
)
885 if ( owner
->InReportView() )
891 void wxListItemData::SetItem( const wxListItem
&info
)
893 if ( info
.m_mask
& wxLIST_MASK_TEXT
)
894 SetText(info
.m_text
);
895 if ( info
.m_mask
& wxLIST_MASK_IMAGE
)
896 m_image
= info
.m_image
;
897 if ( info
.m_mask
& wxLIST_MASK_DATA
)
898 m_data
= info
.m_data
;
900 if ( info
.HasAttributes() )
903 m_attr
->AssignFrom(*info
.GetAttributes());
905 m_attr
= new wxListItemAttr(*info
.GetAttributes());
913 m_rect
->width
= info
.m_width
;
917 void wxListItemData::SetPosition( int x
, int y
)
919 wxCHECK_RET( m_rect
, _T("unexpected SetPosition() call") );
925 void wxListItemData::SetSize( int width
, int height
)
927 wxCHECK_RET( m_rect
, _T("unexpected SetSize() call") );
930 m_rect
->width
= width
;
932 m_rect
->height
= height
;
935 bool wxListItemData::IsHit( int x
, int y
) const
937 wxCHECK_MSG( m_rect
, false, _T("can't be called in this mode") );
939 return wxRect(GetX(), GetY(), GetWidth(), GetHeight()).Contains(x
, y
);
942 int wxListItemData::GetX() const
944 wxCHECK_MSG( m_rect
, 0, _T("can't be called in this mode") );
949 int wxListItemData::GetY() const
951 wxCHECK_MSG( m_rect
, 0, _T("can't be called in this mode") );
956 int wxListItemData::GetWidth() const
958 wxCHECK_MSG( m_rect
, 0, _T("can't be called in this mode") );
960 return m_rect
->width
;
963 int wxListItemData::GetHeight() const
965 wxCHECK_MSG( m_rect
, 0, _T("can't be called in this mode") );
967 return m_rect
->height
;
970 void wxListItemData::GetItem( wxListItem
&info
) const
972 long mask
= info
.m_mask
;
974 // by default, get everything for backwards compatibility
977 if ( mask
& wxLIST_MASK_TEXT
)
978 info
.m_text
= m_text
;
979 if ( mask
& wxLIST_MASK_IMAGE
)
980 info
.m_image
= m_image
;
981 if ( mask
& wxLIST_MASK_DATA
)
982 info
.m_data
= m_data
;
986 if ( m_attr
->HasTextColour() )
987 info
.SetTextColour(m_attr
->GetTextColour());
988 if ( m_attr
->HasBackgroundColour() )
989 info
.SetBackgroundColour(m_attr
->GetBackgroundColour());
990 if ( m_attr
->HasFont() )
991 info
.SetFont(m_attr
->GetFont());
995 //-----------------------------------------------------------------------------
997 //-----------------------------------------------------------------------------
999 void wxListHeaderData::Init()
1011 wxListHeaderData::wxListHeaderData()
1016 wxListHeaderData::wxListHeaderData( const wxListItem
&item
)
1023 void wxListHeaderData::SetItem( const wxListItem
&item
)
1025 m_mask
= item
.m_mask
;
1027 if ( m_mask
& wxLIST_MASK_TEXT
)
1028 m_text
= item
.m_text
;
1030 if ( m_mask
& wxLIST_MASK_IMAGE
)
1031 m_image
= item
.m_image
;
1033 if ( m_mask
& wxLIST_MASK_FORMAT
)
1034 m_format
= item
.m_format
;
1036 if ( m_mask
& wxLIST_MASK_WIDTH
)
1037 SetWidth(item
.m_width
);
1039 if ( m_mask
& wxLIST_MASK_STATE
)
1040 SetState(item
.m_state
);
1043 void wxListHeaderData::SetPosition( int x
, int y
)
1049 void wxListHeaderData::SetHeight( int h
)
1054 void wxListHeaderData::SetWidth( int w
)
1056 m_width
= w
< 0 ? WIDTH_COL_DEFAULT
: w
;
1059 void wxListHeaderData::SetState( int flag
)
1064 void wxListHeaderData::SetFormat( int format
)
1069 bool wxListHeaderData::HasImage() const
1071 return m_image
!= -1;
1074 bool wxListHeaderData::IsHit( int x
, int y
) const
1076 return ((x
>= m_xpos
) && (x
<= m_xpos
+m_width
) && (y
>= m_ypos
) && (y
<= m_ypos
+m_height
));
1079 void wxListHeaderData::GetItem( wxListItem
& item
)
1081 item
.m_mask
= m_mask
;
1082 item
.m_text
= m_text
;
1083 item
.m_image
= m_image
;
1084 item
.m_format
= m_format
;
1085 item
.m_width
= m_width
;
1086 item
.m_state
= m_state
;
1089 int wxListHeaderData::GetImage() const
1094 int wxListHeaderData::GetWidth() const
1099 int wxListHeaderData::GetFormat() const
1104 int wxListHeaderData::GetState() const
1109 //-----------------------------------------------------------------------------
1111 //-----------------------------------------------------------------------------
1113 inline int wxListLineData::GetMode() const
1115 return m_owner
->GetListCtrl()->GetWindowStyleFlag() & wxLC_MASK_TYPE
;
1118 inline bool wxListLineData::InReportView() const
1120 return m_owner
->HasFlag(wxLC_REPORT
);
1123 inline bool wxListLineData::IsVirtual() const
1125 return m_owner
->IsVirtual();
1128 wxListLineData::wxListLineData( wxListMainWindow
*owner
)
1132 if ( InReportView() )
1135 m_gi
= new GeometryInfo
;
1137 m_highlighted
= false;
1139 InitItems( GetMode() == wxLC_REPORT
? m_owner
->GetColumnCount() : 1 );
1142 void wxListLineData::CalculateSize( wxDC
*dc
, int spacing
)
1144 wxListItemDataList::compatibility_iterator node
= m_items
.GetFirst();
1145 wxCHECK_RET( node
, _T("no subitems at all??") );
1147 wxListItemData
*item
= node
->GetData();
1152 switch ( GetMode() )
1155 case wxLC_SMALL_ICON
:
1156 m_gi
->m_rectAll
.width
= spacing
;
1158 s
= item
->GetText();
1163 m_gi
->m_rectLabel
.width
=
1164 m_gi
->m_rectLabel
.height
= 0;
1168 dc
->GetTextExtent( s
, &lw
, &lh
);
1172 m_gi
->m_rectAll
.height
= spacing
+ lh
;
1174 m_gi
->m_rectAll
.width
= lw
;
1176 m_gi
->m_rectLabel
.width
= lw
;
1177 m_gi
->m_rectLabel
.height
= lh
;
1180 if (item
->HasImage())
1183 m_owner
->GetImageSize( item
->GetImage(), w
, h
);
1184 m_gi
->m_rectIcon
.width
= w
+ 8;
1185 m_gi
->m_rectIcon
.height
= h
+ 8;
1187 if ( m_gi
->m_rectIcon
.width
> m_gi
->m_rectAll
.width
)
1188 m_gi
->m_rectAll
.width
= m_gi
->m_rectIcon
.width
;
1189 if ( m_gi
->m_rectIcon
.height
+ lh
> m_gi
->m_rectAll
.height
- 4 )
1190 m_gi
->m_rectAll
.height
= m_gi
->m_rectIcon
.height
+ lh
+ 4;
1193 if ( item
->HasText() )
1195 m_gi
->m_rectHighlight
.width
= m_gi
->m_rectLabel
.width
;
1196 m_gi
->m_rectHighlight
.height
= m_gi
->m_rectLabel
.height
;
1198 else // no text, highlight the icon
1200 m_gi
->m_rectHighlight
.width
= m_gi
->m_rectIcon
.width
;
1201 m_gi
->m_rectHighlight
.height
= m_gi
->m_rectIcon
.height
;
1206 s
= item
->GetTextForMeasuring();
1208 dc
->GetTextExtent( s
, &lw
, &lh
);
1212 m_gi
->m_rectLabel
.width
= lw
;
1213 m_gi
->m_rectLabel
.height
= lh
;
1215 m_gi
->m_rectAll
.width
= lw
;
1216 m_gi
->m_rectAll
.height
= lh
;
1218 if (item
->HasImage())
1221 m_owner
->GetImageSize( item
->GetImage(), w
, h
);
1222 m_gi
->m_rectIcon
.width
= w
;
1223 m_gi
->m_rectIcon
.height
= h
;
1225 m_gi
->m_rectAll
.width
+= 4 + w
;
1226 if (h
> m_gi
->m_rectAll
.height
)
1227 m_gi
->m_rectAll
.height
= h
;
1230 m_gi
->m_rectHighlight
.width
= m_gi
->m_rectAll
.width
;
1231 m_gi
->m_rectHighlight
.height
= m_gi
->m_rectAll
.height
;
1235 wxFAIL_MSG( _T("unexpected call to SetSize") );
1239 wxFAIL_MSG( _T("unknown mode") );
1244 void wxListLineData::SetPosition( int x
, int y
, int spacing
)
1246 wxListItemDataList::compatibility_iterator node
= m_items
.GetFirst();
1247 wxCHECK_RET( node
, _T("no subitems at all??") );
1249 wxListItemData
*item
= node
->GetData();
1251 switch ( GetMode() )
1254 case wxLC_SMALL_ICON
:
1255 m_gi
->m_rectAll
.x
= x
;
1256 m_gi
->m_rectAll
.y
= y
;
1258 if ( item
->HasImage() )
1260 m_gi
->m_rectIcon
.x
= m_gi
->m_rectAll
.x
+ 4 +
1261 (m_gi
->m_rectAll
.width
- m_gi
->m_rectIcon
.width
) / 2;
1262 m_gi
->m_rectIcon
.y
= m_gi
->m_rectAll
.y
+ 4;
1265 if ( item
->HasText() )
1267 if (m_gi
->m_rectAll
.width
> spacing
)
1268 m_gi
->m_rectLabel
.x
= m_gi
->m_rectAll
.x
+ (EXTRA_WIDTH
/2);
1270 m_gi
->m_rectLabel
.x
= m_gi
->m_rectAll
.x
+ (EXTRA_WIDTH
/2) + (spacing
/ 2) - (m_gi
->m_rectLabel
.width
/ 2);
1271 m_gi
->m_rectLabel
.y
= m_gi
->m_rectAll
.y
+ m_gi
->m_rectAll
.height
+ 2 - m_gi
->m_rectLabel
.height
;
1272 m_gi
->m_rectHighlight
.x
= m_gi
->m_rectLabel
.x
- 2;
1273 m_gi
->m_rectHighlight
.y
= m_gi
->m_rectLabel
.y
- 2;
1275 else // no text, highlight the icon
1277 m_gi
->m_rectHighlight
.x
= m_gi
->m_rectIcon
.x
- 4;
1278 m_gi
->m_rectHighlight
.y
= m_gi
->m_rectIcon
.y
- 4;
1283 m_gi
->m_rectAll
.x
= x
;
1284 m_gi
->m_rectAll
.y
= y
;
1286 m_gi
->m_rectHighlight
.x
= m_gi
->m_rectAll
.x
;
1287 m_gi
->m_rectHighlight
.y
= m_gi
->m_rectAll
.y
;
1288 m_gi
->m_rectLabel
.y
= m_gi
->m_rectAll
.y
+ 2;
1290 if (item
->HasImage())
1292 m_gi
->m_rectIcon
.x
= m_gi
->m_rectAll
.x
+ 2;
1293 m_gi
->m_rectIcon
.y
= m_gi
->m_rectAll
.y
+ 2;
1294 m_gi
->m_rectLabel
.x
= m_gi
->m_rectAll
.x
+ 4 + (EXTRA_WIDTH
/2) + m_gi
->m_rectIcon
.width
;
1298 m_gi
->m_rectLabel
.x
= m_gi
->m_rectAll
.x
+ (EXTRA_WIDTH
/2);
1303 wxFAIL_MSG( _T("unexpected call to SetPosition") );
1307 wxFAIL_MSG( _T("unknown mode") );
1312 void wxListLineData::InitItems( int num
)
1314 for (int i
= 0; i
< num
; i
++)
1315 m_items
.Append( new wxListItemData(m_owner
) );
1318 void wxListLineData::SetItem( int index
, const wxListItem
&info
)
1320 wxListItemDataList::compatibility_iterator node
= m_items
.Item( index
);
1321 wxCHECK_RET( node
, _T("invalid column index in SetItem") );
1323 wxListItemData
*item
= node
->GetData();
1324 item
->SetItem( info
);
1327 void wxListLineData::GetItem( int index
, wxListItem
&info
)
1329 wxListItemDataList::compatibility_iterator node
= m_items
.Item( index
);
1332 wxListItemData
*item
= node
->GetData();
1333 item
->GetItem( info
);
1337 wxString
wxListLineData::GetText(int index
) const
1341 wxListItemDataList::compatibility_iterator node
= m_items
.Item( index
);
1344 wxListItemData
*item
= node
->GetData();
1345 s
= item
->GetText();
1351 void wxListLineData::SetText( int index
, const wxString
& s
)
1353 wxListItemDataList::compatibility_iterator node
= m_items
.Item( index
);
1356 wxListItemData
*item
= node
->GetData();
1361 void wxListLineData::SetImage( int index
, int image
)
1363 wxListItemDataList::compatibility_iterator node
= m_items
.Item( index
);
1364 wxCHECK_RET( node
, _T("invalid column index in SetImage()") );
1366 wxListItemData
*item
= node
->GetData();
1367 item
->SetImage(image
);
1370 int wxListLineData::GetImage( int index
) const
1372 wxListItemDataList::compatibility_iterator node
= m_items
.Item( index
);
1373 wxCHECK_MSG( node
, -1, _T("invalid column index in GetImage()") );
1375 wxListItemData
*item
= node
->GetData();
1376 return item
->GetImage();
1379 wxListItemAttr
*wxListLineData::GetAttr() const
1381 wxListItemDataList::compatibility_iterator node
= m_items
.GetFirst();
1382 wxCHECK_MSG( node
, NULL
, _T("invalid column index in GetAttr()") );
1384 wxListItemData
*item
= node
->GetData();
1385 return item
->GetAttr();
1388 void wxListLineData::SetAttr(wxListItemAttr
*attr
)
1390 wxListItemDataList::compatibility_iterator node
= m_items
.GetFirst();
1391 wxCHECK_RET( node
, _T("invalid column index in SetAttr()") );
1393 wxListItemData
*item
= node
->GetData();
1394 item
->SetAttr(attr
);
1397 bool wxListLineData::SetAttributes(wxDC
*dc
,
1398 const wxListItemAttr
*attr
,
1401 wxWindow
*listctrl
= m_owner
->GetParent();
1405 // don't use foreground colour for drawing highlighted items - this might
1406 // make them completely invisible (and there is no way to do bit
1407 // arithmetics on wxColour, unfortunately)
1412 if (m_owner
->HasFocus())
1418 colText
= wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHTTEXT
);
1420 else if ( attr
&& attr
->HasTextColour() )
1421 colText
= attr
->GetTextColour();
1423 colText
= listctrl
->GetForegroundColour();
1425 dc
->SetTextForeground(colText
);
1429 if ( attr
&& attr
->HasFont() )
1430 font
= attr
->GetFont();
1432 font
= listctrl
->GetFont();
1437 bool hasBgCol
= attr
&& attr
->HasBackgroundColour();
1438 if ( highlighted
|| hasBgCol
)
1441 dc
->SetBrush( *m_owner
->GetHighlightBrush() );
1443 dc
->SetBrush(wxBrush(attr
->GetBackgroundColour(), wxSOLID
));
1445 dc
->SetPen( *wxTRANSPARENT_PEN
);
1453 void wxListLineData::Draw( wxDC
*dc
)
1455 wxListItemDataList::compatibility_iterator node
= m_items
.GetFirst();
1456 wxCHECK_RET( node
, _T("no subitems at all??") );
1458 bool highlighted
= IsHighlighted();
1460 wxListItemAttr
*attr
= GetAttr();
1462 if ( SetAttributes(dc
, attr
, highlighted
) )
1463 #if ( !defined(__WXGTK20__) && !defined(__WXMAC__) )
1465 dc
->DrawRectangle( m_gi
->m_rectHighlight
);
1471 int flags
= wxCONTROL_SELECTED
;
1472 if (m_owner
->HasFocus())
1473 flags
|= wxCONTROL_FOCUSED
;
1474 wxRendererNative::Get().DrawItemSelectionRect( m_owner
, *dc
, m_gi
->m_rectHighlight
, flags
);
1479 dc
->DrawRectangle( m_gi
->m_rectHighlight
);
1484 // just for debugging to better see where the items are
1486 dc
->SetPen(*wxRED_PEN
);
1487 dc
->SetBrush(*wxTRANSPARENT_BRUSH
);
1488 dc
->DrawRectangle( m_gi
->m_rectAll
);
1489 dc
->SetPen(*wxGREEN_PEN
);
1490 dc
->DrawRectangle( m_gi
->m_rectIcon
);
1493 wxListItemData
*item
= node
->GetData();
1494 if (item
->HasImage())
1496 // centre the image inside our rectangle, this looks nicer when items
1497 // ae aligned in a row
1498 const wxRect
& rectIcon
= m_gi
->m_rectIcon
;
1500 m_owner
->DrawImage(item
->GetImage(), dc
, rectIcon
.x
, rectIcon
.y
);
1503 if (item
->HasText())
1505 const wxRect
& rectLabel
= m_gi
->m_rectLabel
;
1507 wxDCClipper
clipper(*dc
, rectLabel
);
1508 dc
->DrawText(item
->GetText(), rectLabel
.x
, rectLabel
.y
);
1512 void wxListLineData::DrawInReportMode( wxDC
*dc
,
1514 const wxRect
& rectHL
,
1517 // TODO: later we should support setting different attributes for
1518 // different columns - to do it, just add "col" argument to
1519 // GetAttr() and move these lines into the loop below
1520 wxListItemAttr
*attr
= GetAttr();
1521 if ( SetAttributes(dc
, attr
, highlighted
) )
1522 #if ( !defined(__WXGTK20__) && !defined(__WXMAC__) )
1524 dc
->DrawRectangle( rectHL
);
1530 int flags
= wxCONTROL_SELECTED
;
1531 if (m_owner
->HasFocus())
1532 flags
|= wxCONTROL_FOCUSED
;
1533 wxRendererNative::Get().DrawItemSelectionRect( m_owner
, *dc
, rectHL
, flags
);
1537 dc
->DrawRectangle( rectHL
);
1542 wxCoord x
= rect
.x
+ HEADER_OFFSET_X
,
1543 yMid
= rect
.y
+ rect
.height
/2;
1545 // This probably needs to be done
1546 // on all platforms as the icons
1547 // otherwise nearly touch the border
1552 for ( wxListItemDataList::compatibility_iterator node
= m_items
.GetFirst();
1554 node
= node
->GetNext(), col
++ )
1556 wxListItemData
*item
= node
->GetData();
1558 int width
= m_owner
->GetColumnWidth(col
);
1562 if ( item
->HasImage() )
1565 m_owner
->GetImageSize( item
->GetImage(), ix
, iy
);
1566 m_owner
->DrawImage( item
->GetImage(), dc
, xOld
, yMid
- iy
/2 );
1568 ix
+= IMAGE_MARGIN_IN_REPORT_MODE
;
1574 if ( item
->HasText() )
1575 DrawTextFormatted(dc
, item
->GetText(), col
, xOld
, yMid
, width
- 8);
1579 void wxListLineData::DrawTextFormatted(wxDC
*dc
,
1580 const wxString
&text
,
1587 dc
->GetTextExtent(text
, &w
, &h
);
1589 const wxCoord y
= yMid
- (h
+ 1)/2;
1591 wxDCClipper
clipper(*dc
, x
, y
, width
, h
);
1593 // determine if the string can fit inside the current width
1596 // it can, draw it using the items alignment
1598 m_owner
->GetColumn(col
, item
);
1599 switch ( item
.GetAlign() )
1601 case wxLIST_FORMAT_LEFT
:
1605 case wxLIST_FORMAT_RIGHT
:
1609 case wxLIST_FORMAT_CENTER
:
1610 x
+= (width
- w
) / 2;
1614 wxFAIL_MSG( _T("unknown list item format") );
1618 dc
->DrawText(text
, x
, y
);
1620 else // otherwise, truncate and add an ellipsis if possible
1622 // determine the base width
1623 wxString
ellipsis(wxT("..."));
1625 dc
->GetTextExtent(ellipsis
, &base_w
, &h
);
1627 // continue until we have enough space or only one character left
1629 size_t len
= text
.length();
1630 wxString drawntext
= text
.Left(len
);
1633 dc
->GetTextExtent(drawntext
.Last(), &w_c
, &h_c
);
1634 drawntext
.RemoveLast();
1637 if (w
+ base_w
<= width
)
1641 // if still not enough space, remove ellipsis characters
1642 while (ellipsis
.length() > 0 && w
+ base_w
> width
)
1644 ellipsis
= ellipsis
.Left(ellipsis
.length() - 1);
1645 dc
->GetTextExtent(ellipsis
, &base_w
, &h
);
1648 // now draw the text
1649 dc
->DrawText(drawntext
, x
, y
);
1650 dc
->DrawText(ellipsis
, x
+ w
, y
);
1654 bool wxListLineData::Highlight( bool on
)
1656 wxCHECK_MSG( !IsVirtual(), false, _T("unexpected call to Highlight") );
1658 if ( on
== m_highlighted
)
1666 void wxListLineData::ReverseHighlight( void )
1668 Highlight(!IsHighlighted());
1671 //-----------------------------------------------------------------------------
1672 // wxListHeaderWindow
1673 //-----------------------------------------------------------------------------
1675 IMPLEMENT_DYNAMIC_CLASS(wxListHeaderWindow
,wxWindow
)
1677 BEGIN_EVENT_TABLE(wxListHeaderWindow
,wxWindow
)
1678 EVT_PAINT (wxListHeaderWindow::OnPaint
)
1679 EVT_MOUSE_EVENTS (wxListHeaderWindow::OnMouse
)
1680 EVT_SET_FOCUS (wxListHeaderWindow::OnSetFocus
)
1683 void wxListHeaderWindow::Init()
1685 m_currentCursor
= (wxCursor
*) NULL
;
1686 m_isDragging
= false;
1690 wxListHeaderWindow::wxListHeaderWindow()
1694 m_owner
= (wxListMainWindow
*) NULL
;
1695 m_resizeCursor
= (wxCursor
*) NULL
;
1698 wxListHeaderWindow::wxListHeaderWindow( wxWindow
*win
,
1700 wxListMainWindow
*owner
,
1704 const wxString
&name
)
1705 : wxWindow( win
, id
, pos
, size
, style
, name
)
1710 m_resizeCursor
= new wxCursor( wxCURSOR_SIZEWE
);
1713 wxVisualAttributes attr
= wxPanel::GetClassDefaultAttributes();
1714 SetOwnForegroundColour( attr
.colFg
);
1715 SetOwnBackgroundColour( attr
.colBg
);
1717 SetOwnFont( attr
.font
);
1719 SetOwnForegroundColour( wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT
));
1720 SetOwnBackgroundColour( wxSystemSettings::GetColour(wxSYS_COLOUR_BTNFACE
));
1722 SetOwnFont( wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT
));
1726 wxListHeaderWindow::~wxListHeaderWindow()
1728 delete m_resizeCursor
;
1731 #ifdef __WXUNIVERSAL__
1732 #include "wx/univ/renderer.h"
1733 #include "wx/univ/theme.h"
1736 // shift the DC origin to match the position of the main window horz
1737 // scrollbar: this allows us to always use logical coords
1738 void wxListHeaderWindow::AdjustDC(wxDC
& dc
)
1741 m_owner
->GetScrollPixelsPerUnit( &xpix
, NULL
);
1744 m_owner
->GetViewStart( &view_start
, NULL
);
1749 dc
.GetDeviceOrigin( &org_x
, &org_y
);
1751 // account for the horz scrollbar offset
1753 if (GetLayoutDirection() == wxLayout_RightToLeft
)
1755 // Maybe we just have to check for m_signX
1756 // in the DC, but I leave the #ifdef __WXGTK__
1758 dc
.SetDeviceOrigin( org_x
+ (view_start
* xpix
), org_y
);
1762 dc
.SetDeviceOrigin( org_x
- (view_start
* xpix
), org_y
);
1765 void wxListHeaderWindow::OnPaint( wxPaintEvent
&WXUNUSED(event
) )
1767 wxPaintDC
dc( this );
1772 dc
.SetFont( GetFont() );
1774 // width and height of the entire header window
1776 GetClientSize( &w
, &h
);
1777 m_owner
->CalcUnscrolledPosition(w
, 0, &w
, NULL
);
1779 dc
.SetBackgroundMode(wxTRANSPARENT
);
1780 dc
.SetTextForeground(GetForegroundColour());
1782 int x
= HEADER_OFFSET_X
;
1783 int numColumns
= m_owner
->GetColumnCount();
1785 for ( int i
= 0; i
< numColumns
&& x
< w
; i
++ )
1787 m_owner
->GetColumn( i
, item
);
1788 int wCol
= item
.m_width
;
1790 // the width of the rect to draw: make it smaller to fit entirely
1791 // inside the column rect
1801 if (!m_parent
->IsEnabled())
1802 flags
|= wxCONTROL_DISABLED
;
1804 // NB: The code below is not really Mac-specific, but since we are close
1805 // to 2.8 release and I don't have time to test on other platforms, I
1806 // defined this only for wxMac. If this behavior is desired on
1807 // other platforms, please go ahead and revise or remove the #ifdef.
1809 if ( !m_owner
->IsVirtual() && (item
.m_mask
& wxLIST_MASK_STATE
) &&
1810 (item
.m_state
& wxLIST_STATE_SELECTED
) )
1811 flags
|= wxCONTROL_SELECTED
;
1814 wxRendererNative::Get().DrawHeaderButton
1818 wxRect(x
, HEADER_OFFSET_Y
, cw
, ch
),
1822 // see if we have enough space for the column label
1824 // for this we need the width of the text
1827 dc
.GetTextExtent(item
.GetText(), &wLabel
, &hLabel
);
1828 wLabel
+= 2 * EXTRA_WIDTH
;
1830 // and the width of the icon, if any
1831 static const int MARGIN_BETWEEN_TEXT_AND_ICON
= 2;
1832 int ix
= 0, iy
= 0; // init them just to suppress the compiler warnings
1833 const int image
= item
.m_image
;
1834 wxImageList
*imageList
;
1837 imageList
= m_owner
->m_small_image_list
;
1840 imageList
->GetSize(image
, ix
, iy
);
1841 wLabel
+= ix
+ MARGIN_BETWEEN_TEXT_AND_ICON
;
1849 // ignore alignment if there is not enough space anyhow
1851 switch ( wLabel
< cw
? item
.GetAlign() : wxLIST_FORMAT_LEFT
)
1854 wxFAIL_MSG( _T("unknown list item format") );
1857 case wxLIST_FORMAT_LEFT
:
1861 case wxLIST_FORMAT_RIGHT
:
1862 xAligned
= x
+ cw
- wLabel
;
1865 case wxLIST_FORMAT_CENTER
:
1866 xAligned
= x
+ (cw
- wLabel
) / 2;
1870 // if we have an image, draw it on the right of the label
1877 xAligned
+ wLabel
- ix
- MARGIN_BETWEEN_TEXT_AND_ICON
,
1878 HEADER_OFFSET_Y
+ (h
- 4 - iy
)/2,
1879 wxIMAGELIST_DRAW_TRANSPARENT
1882 cw
-= ix
+ MARGIN_BETWEEN_TEXT_AND_ICON
;
1885 // draw the text clipping it so that it doesn't overwrite the column
1887 wxDCClipper
clipper(dc
, x
, HEADER_OFFSET_Y
, cw
, h
- 4 );
1889 dc
.DrawText( item
.GetText(),
1890 xAligned
+ EXTRA_WIDTH
, h
/ 2 - hLabel
/ 2 ); //HEADER_OFFSET_Y + EXTRA_HEIGHT );
1896 void wxListHeaderWindow::DrawCurrent()
1898 int x1
= m_currentX
;
1900 m_owner
->ClientToScreen( &x1
, &y1
);
1902 int x2
= m_currentX
;
1904 m_owner
->GetClientSize( NULL
, &y2
);
1905 m_owner
->ClientToScreen( &x2
, &y2
);
1908 dc
.SetLogicalFunction( wxINVERT
);
1909 dc
.SetPen( wxPen( *wxBLACK
, 2, wxSOLID
) );
1910 dc
.SetBrush( *wxTRANSPARENT_BRUSH
);
1914 dc
.DrawLine( x1
, y1
, x2
, y2
);
1916 dc
.SetLogicalFunction( wxCOPY
);
1918 dc
.SetPen( wxNullPen
);
1919 dc
.SetBrush( wxNullBrush
);
1922 void wxListHeaderWindow::OnMouse( wxMouseEvent
&event
)
1924 // we want to work with logical coords
1926 m_owner
->CalcUnscrolledPosition(event
.GetX(), 0, &x
, NULL
);
1927 int y
= event
.GetY();
1931 SendListEvent(wxEVT_COMMAND_LIST_COL_DRAGGING
, event
.GetPosition());
1933 // we don't draw the line beyond our window, but we allow dragging it
1936 GetClientSize( &w
, NULL
);
1937 m_owner
->CalcUnscrolledPosition(w
, 0, &w
, NULL
);
1940 // erase the line if it was drawn
1941 if ( m_currentX
< w
)
1944 if (event
.ButtonUp())
1947 m_isDragging
= false;
1949 m_owner
->SetColumnWidth( m_column
, m_currentX
- m_minX
);
1950 SendListEvent(wxEVT_COMMAND_LIST_COL_END_DRAG
, event
.GetPosition());
1957 m_currentX
= m_minX
+ 7;
1959 // draw in the new location
1960 if ( m_currentX
< w
)
1964 else // not dragging
1967 bool hit_border
= false;
1969 // end of the current column
1972 // find the column where this event occurred
1974 countCol
= m_owner
->GetColumnCount();
1975 for (col
= 0; col
< countCol
; col
++)
1977 xpos
+= m_owner
->GetColumnWidth( col
);
1980 if ( (abs(x
-xpos
) < 3) && (y
< 22) )
1982 // near the column border
1989 // inside the column
1996 if ( col
== countCol
)
1999 if (event
.LeftDown() || event
.RightUp())
2001 if (hit_border
&& event
.LeftDown())
2003 if ( SendListEvent(wxEVT_COMMAND_LIST_COL_BEGIN_DRAG
,
2004 event
.GetPosition()) )
2006 m_isDragging
= true;
2011 //else: column resizing was vetoed by the user code
2013 else // click on a column
2015 // record the selected state of the columns
2016 if (event
.LeftDown())
2018 for (int i
=0; i
< m_owner
->GetColumnCount(); i
++)
2021 m_owner
->GetColumn(i
, colItem
);
2022 long state
= colItem
.GetState();
2024 colItem
.SetState(state
| wxLIST_STATE_SELECTED
);
2026 colItem
.SetState(state
& ~wxLIST_STATE_SELECTED
);
2027 m_owner
->SetColumn(i
, colItem
);
2031 SendListEvent( event
.LeftDown()
2032 ? wxEVT_COMMAND_LIST_COL_CLICK
2033 : wxEVT_COMMAND_LIST_COL_RIGHT_CLICK
,
2034 event
.GetPosition());
2037 else if (event
.Moving())
2042 setCursor
= m_currentCursor
== wxSTANDARD_CURSOR
;
2043 m_currentCursor
= m_resizeCursor
;
2047 setCursor
= m_currentCursor
!= wxSTANDARD_CURSOR
;
2048 m_currentCursor
= wxSTANDARD_CURSOR
;
2052 SetCursor(*m_currentCursor
);
2057 void wxListHeaderWindow::OnSetFocus( wxFocusEvent
&WXUNUSED(event
) )
2059 m_owner
->SetFocus();
2063 bool wxListHeaderWindow::SendListEvent(wxEventType type
, const wxPoint
& pos
)
2065 wxWindow
*parent
= GetParent();
2066 wxListEvent
le( type
, parent
->GetId() );
2067 le
.SetEventObject( parent
);
2068 le
.m_pointDrag
= pos
;
2070 // the position should be relative to the parent window, not
2071 // this one for compatibility with MSW and common sense: the
2072 // user code doesn't know anything at all about this header
2073 // window, so why should it get positions relative to it?
2074 le
.m_pointDrag
.y
-= GetSize().y
;
2076 le
.m_col
= m_column
;
2077 return !parent
->GetEventHandler()->ProcessEvent( le
) || le
.IsAllowed();
2080 //-----------------------------------------------------------------------------
2081 // wxListRenameTimer (internal)
2082 //-----------------------------------------------------------------------------
2084 wxListRenameTimer::wxListRenameTimer( wxListMainWindow
*owner
)
2089 void wxListRenameTimer::Notify()
2091 m_owner
->OnRenameTimer();
2094 //-----------------------------------------------------------------------------
2095 // wxListTextCtrlWrapper (internal)
2096 //-----------------------------------------------------------------------------
2098 BEGIN_EVENT_TABLE(wxListTextCtrlWrapper
, wxEvtHandler
)
2099 EVT_CHAR (wxListTextCtrlWrapper::OnChar
)
2100 EVT_KEY_UP (wxListTextCtrlWrapper::OnKeyUp
)
2101 EVT_KILL_FOCUS (wxListTextCtrlWrapper::OnKillFocus
)
2104 wxListTextCtrlWrapper::wxListTextCtrlWrapper(wxListMainWindow
*owner
,
2107 : m_startValue(owner
->GetItemText(itemEdit
)),
2108 m_itemEdited(itemEdit
)
2113 m_aboutToFinish
= false;
2115 wxRect rectLabel
= owner
->GetLineLabelRect(itemEdit
);
2117 m_owner
->CalcScrolledPosition(rectLabel
.x
, rectLabel
.y
,
2118 &rectLabel
.x
, &rectLabel
.y
);
2120 m_text
->Create(owner
, wxID_ANY
, m_startValue
,
2121 wxPoint(rectLabel
.x
-4,rectLabel
.y
-4),
2122 wxSize(rectLabel
.width
+11,rectLabel
.height
+8));
2125 m_text
->PushEventHandler(this);
2128 void wxListTextCtrlWrapper::Finish()
2134 m_text
->RemoveEventHandler(this);
2135 m_owner
->FinishEditing(m_text
);
2137 wxPendingDelete
.Append( this );
2141 bool wxListTextCtrlWrapper::AcceptChanges()
2143 const wxString value
= m_text
->GetValue();
2145 if ( value
== m_startValue
)
2146 // nothing changed, always accept
2149 if ( !m_owner
->OnRenameAccept(m_itemEdited
, value
) )
2150 // vetoed by the user
2153 // accepted, do rename the item
2154 m_owner
->SetItemText(m_itemEdited
, value
);
2159 void wxListTextCtrlWrapper::AcceptChangesAndFinish()
2161 m_aboutToFinish
= true;
2163 // Notify the owner about the changes
2166 // Even if vetoed, close the control (consistent with MSW)
2170 void wxListTextCtrlWrapper::OnChar( wxKeyEvent
&event
)
2172 switch ( event
.m_keyCode
)
2175 AcceptChangesAndFinish();
2179 m_owner
->OnRenameCancelled( m_itemEdited
);
2188 void wxListTextCtrlWrapper::OnKeyUp( wxKeyEvent
&event
)
2196 // auto-grow the textctrl:
2197 wxSize parentSize
= m_owner
->GetSize();
2198 wxPoint myPos
= m_text
->GetPosition();
2199 wxSize mySize
= m_text
->GetSize();
2201 m_text
->GetTextExtent(m_text
->GetValue() + _T("MM"), &sx
, &sy
);
2202 if (myPos
.x
+ sx
> parentSize
.x
)
2203 sx
= parentSize
.x
- myPos
.x
;
2206 m_text
->SetSize(sx
, wxDefaultCoord
);
2211 void wxListTextCtrlWrapper::OnKillFocus( wxFocusEvent
&event
)
2213 if ( !m_finished
&& !m_aboutToFinish
)
2215 if ( !AcceptChanges() )
2216 m_owner
->OnRenameCancelled( m_itemEdited
);
2221 // We must let the native text control handle focus
2225 //-----------------------------------------------------------------------------
2227 //-----------------------------------------------------------------------------
2229 IMPLEMENT_DYNAMIC_CLASS(wxListMainWindow
,wxScrolledWindow
)
2231 BEGIN_EVENT_TABLE(wxListMainWindow
,wxScrolledWindow
)
2232 EVT_PAINT (wxListMainWindow::OnPaint
)
2233 EVT_MOUSE_EVENTS (wxListMainWindow::OnMouse
)
2234 EVT_CHAR (wxListMainWindow::OnChar
)
2235 EVT_KEY_DOWN (wxListMainWindow::OnKeyDown
)
2236 EVT_SET_FOCUS (wxListMainWindow::OnSetFocus
)
2237 EVT_KILL_FOCUS (wxListMainWindow::OnKillFocus
)
2238 EVT_SCROLLWIN (wxListMainWindow::OnScroll
)
2241 void wxListMainWindow::Init()
2246 m_lineTo
= (size_t)-1;
2252 m_small_image_list
= (wxImageList
*) NULL
;
2253 m_normal_image_list
= (wxImageList
*) NULL
;
2255 m_small_spacing
= 30;
2256 m_normal_spacing
= 40;
2260 m_isCreated
= false;
2262 m_lastOnSame
= false;
2263 m_renameTimer
= new wxListRenameTimer( this );
2264 m_textctrlWrapper
= NULL
;
2268 m_lineSelectSingleOnUp
=
2269 m_lineBeforeLastClicked
= (size_t)-1;
2274 wxListMainWindow::wxListMainWindow()
2279 m_highlightUnfocusedBrush
= (wxBrush
*) NULL
;
2282 wxListMainWindow::wxListMainWindow( wxWindow
*parent
,
2287 const wxString
&name
)
2288 : wxScrolledWindow( parent
, id
, pos
, size
,
2289 style
| wxHSCROLL
| wxVSCROLL
, name
)
2293 m_highlightBrush
= new wxBrush
2295 wxSystemSettings::GetColour
2297 wxSYS_COLOUR_HIGHLIGHT
2302 m_highlightUnfocusedBrush
= new wxBrush
2304 wxSystemSettings::GetColour
2306 wxSYS_COLOUR_BTNSHADOW
2311 SetScrollbars( 0, 0, 0, 0, 0, 0 );
2313 wxVisualAttributes attr
= wxGenericListCtrl::GetClassDefaultAttributes();
2314 SetOwnForegroundColour( attr
.colFg
);
2315 SetOwnBackgroundColour( attr
.colBg
);
2317 SetOwnFont( attr
.font
);
2320 wxListMainWindow::~wxListMainWindow()
2323 WX_CLEAR_LIST(wxListHeaderDataList
, m_columns
);
2324 WX_CLEAR_ARRAY(m_aColWidths
);
2326 delete m_highlightBrush
;
2327 delete m_highlightUnfocusedBrush
;
2328 delete m_renameTimer
;
2331 void wxListMainWindow::CacheLineData(size_t line
)
2333 wxGenericListCtrl
*listctrl
= GetListCtrl();
2335 wxListLineData
*ld
= GetDummyLine();
2337 size_t countCol
= GetColumnCount();
2338 for ( size_t col
= 0; col
< countCol
; col
++ )
2340 ld
->SetText(col
, listctrl
->OnGetItemText(line
, col
));
2341 ld
->SetImage(col
, listctrl
->OnGetItemColumnImage(line
, col
));
2344 ld
->SetAttr(listctrl
->OnGetItemAttr(line
));
2347 wxListLineData
*wxListMainWindow::GetDummyLine() const
2349 wxASSERT_MSG( !IsEmpty(), _T("invalid line index") );
2350 wxASSERT_MSG( IsVirtual(), _T("GetDummyLine() shouldn't be called") );
2352 wxListMainWindow
*self
= wxConstCast(this, wxListMainWindow
);
2354 // we need to recreate the dummy line if the number of columns in the
2355 // control changed as it would have the incorrect number of fields
2357 if ( !m_lines
.IsEmpty() &&
2358 m_lines
[0].m_items
.GetCount() != (size_t)GetColumnCount() )
2360 self
->m_lines
.Clear();
2363 if ( m_lines
.IsEmpty() )
2365 wxListLineData
*line
= new wxListLineData(self
);
2366 self
->m_lines
.Add(line
);
2368 // don't waste extra memory -- there never going to be anything
2369 // else/more in this array
2370 self
->m_lines
.Shrink();
2376 // ----------------------------------------------------------------------------
2377 // line geometry (report mode only)
2378 // ----------------------------------------------------------------------------
2380 wxCoord
wxListMainWindow::GetLineHeight() const
2382 // we cache the line height as calling GetTextExtent() is slow
2383 if ( !m_lineHeight
)
2385 wxListMainWindow
*self
= wxConstCast(this, wxListMainWindow
);
2387 wxClientDC
dc( self
);
2388 dc
.SetFont( GetFont() );
2391 dc
.GetTextExtent(_T("H"), NULL
, &y
);
2393 if ( m_small_image_list
&& m_small_image_list
->GetImageCount() )
2396 m_small_image_list
->GetSize(0, iw
, ih
);
2401 self
->m_lineHeight
= y
+ LINE_SPACING
;
2404 return m_lineHeight
;
2407 wxCoord
wxListMainWindow::GetLineY(size_t line
) const
2409 wxASSERT_MSG( InReportView(), _T("only works in report mode") );
2411 return LINE_SPACING
+ line
* GetLineHeight();
2414 wxRect
wxListMainWindow::GetLineRect(size_t line
) const
2416 if ( !InReportView() )
2417 return GetLine(line
)->m_gi
->m_rectAll
;
2420 rect
.x
= HEADER_OFFSET_X
;
2421 rect
.y
= GetLineY(line
);
2422 rect
.width
= GetHeaderWidth();
2423 rect
.height
= GetLineHeight();
2428 wxRect
wxListMainWindow::GetLineLabelRect(size_t line
) const
2430 if ( !InReportView() )
2431 return GetLine(line
)->m_gi
->m_rectLabel
;
2434 rect
.x
= HEADER_OFFSET_X
;
2435 rect
.y
= GetLineY(line
);
2436 rect
.width
= GetColumnWidth(0);
2437 rect
.height
= GetLineHeight();
2442 wxRect
wxListMainWindow::GetLineIconRect(size_t line
) const
2444 if ( !InReportView() )
2445 return GetLine(line
)->m_gi
->m_rectIcon
;
2447 wxListLineData
*ld
= GetLine(line
);
2448 wxASSERT_MSG( ld
->HasImage(), _T("should have an image") );
2451 rect
.x
= HEADER_OFFSET_X
;
2452 rect
.y
= GetLineY(line
);
2453 GetImageSize(ld
->GetImage(), rect
.width
, rect
.height
);
2458 wxRect
wxListMainWindow::GetLineHighlightRect(size_t line
) const
2460 return InReportView() ? GetLineRect(line
)
2461 : GetLine(line
)->m_gi
->m_rectHighlight
;
2464 long wxListMainWindow::HitTestLine(size_t line
, int x
, int y
) const
2466 wxASSERT_MSG( line
< GetItemCount(), _T("invalid line in HitTestLine") );
2468 wxListLineData
*ld
= GetLine(line
);
2470 if ( ld
->HasImage() && GetLineIconRect(line
).Contains(x
, y
) )
2471 return wxLIST_HITTEST_ONITEMICON
;
2473 // VS: Testing for "ld->HasText() || InReportView()" instead of
2474 // "ld->HasText()" is needed to make empty lines in report view
2476 if ( ld
->HasText() || InReportView() )
2478 wxRect rect
= InReportView() ? GetLineRect(line
)
2479 : GetLineLabelRect(line
);
2481 if ( rect
.Contains(x
, y
) )
2482 return wxLIST_HITTEST_ONITEMLABEL
;
2488 // ----------------------------------------------------------------------------
2489 // highlight (selection) handling
2490 // ----------------------------------------------------------------------------
2492 bool wxListMainWindow::IsHighlighted(size_t line
) const
2496 return m_selStore
.IsSelected(line
);
2500 wxListLineData
*ld
= GetLine(line
);
2501 wxCHECK_MSG( ld
, false, _T("invalid index in IsHighlighted") );
2503 return ld
->IsHighlighted();
2507 void wxListMainWindow::HighlightLines( size_t lineFrom
,
2513 wxArrayInt linesChanged
;
2514 if ( !m_selStore
.SelectRange(lineFrom
, lineTo
, highlight
,
2517 // meny items changed state, refresh everything
2518 RefreshLines(lineFrom
, lineTo
);
2520 else // only a few items changed state, refresh only them
2522 size_t count
= linesChanged
.GetCount();
2523 for ( size_t n
= 0; n
< count
; n
++ )
2525 RefreshLine(linesChanged
[n
]);
2529 else // iterate over all items in non report view
2531 for ( size_t line
= lineFrom
; line
<= lineTo
; line
++ )
2533 if ( HighlightLine(line
, highlight
) )
2539 bool wxListMainWindow::HighlightLine( size_t line
, bool highlight
)
2545 changed
= m_selStore
.SelectItem(line
, highlight
);
2549 wxListLineData
*ld
= GetLine(line
);
2550 wxCHECK_MSG( ld
, false, _T("invalid index in HighlightLine") );
2552 changed
= ld
->Highlight(highlight
);
2557 SendNotify( line
, highlight
? wxEVT_COMMAND_LIST_ITEM_SELECTED
2558 : wxEVT_COMMAND_LIST_ITEM_DESELECTED
);
2564 void wxListMainWindow::RefreshLine( size_t line
)
2566 if ( InReportView() )
2568 size_t visibleFrom
, visibleTo
;
2569 GetVisibleLinesRange(&visibleFrom
, &visibleTo
);
2571 if ( line
< visibleFrom
|| line
> visibleTo
)
2575 wxRect rect
= GetLineRect(line
);
2577 CalcScrolledPosition( rect
.x
, rect
.y
, &rect
.x
, &rect
.y
);
2578 RefreshRect( rect
);
2581 void wxListMainWindow::RefreshLines( size_t lineFrom
, size_t lineTo
)
2583 // we suppose that they are ordered by caller
2584 wxASSERT_MSG( lineFrom
<= lineTo
, _T("indices in disorder") );
2586 wxASSERT_MSG( lineTo
< GetItemCount(), _T("invalid line range") );
2588 if ( InReportView() )
2590 size_t visibleFrom
, visibleTo
;
2591 GetVisibleLinesRange(&visibleFrom
, &visibleTo
);
2593 if ( lineFrom
< visibleFrom
)
2594 lineFrom
= visibleFrom
;
2595 if ( lineTo
> visibleTo
)
2600 rect
.y
= GetLineY(lineFrom
);
2601 rect
.width
= GetClientSize().x
;
2602 rect
.height
= GetLineY(lineTo
) - rect
.y
+ GetLineHeight();
2604 CalcScrolledPosition( rect
.x
, rect
.y
, &rect
.x
, &rect
.y
);
2605 RefreshRect( rect
);
2609 // TODO: this should be optimized...
2610 for ( size_t line
= lineFrom
; line
<= lineTo
; line
++ )
2617 void wxListMainWindow::RefreshAfter( size_t lineFrom
)
2619 if ( InReportView() )
2621 size_t visibleFrom
, visibleTo
;
2622 GetVisibleLinesRange(&visibleFrom
, &visibleTo
);
2624 if ( lineFrom
< visibleFrom
)
2625 lineFrom
= visibleFrom
;
2626 else if ( lineFrom
> visibleTo
)
2631 rect
.y
= GetLineY(lineFrom
);
2632 CalcScrolledPosition( rect
.x
, rect
.y
, &rect
.x
, &rect
.y
);
2634 wxSize size
= GetClientSize();
2635 rect
.width
= size
.x
;
2637 // refresh till the bottom of the window
2638 rect
.height
= size
.y
- rect
.y
;
2640 RefreshRect( rect
);
2644 // TODO: how to do it more efficiently?
2649 void wxListMainWindow::RefreshSelected()
2655 if ( InReportView() )
2657 GetVisibleLinesRange(&from
, &to
);
2662 to
= GetItemCount() - 1;
2665 if ( HasCurrent() && m_current
>= from
&& m_current
<= to
)
2666 RefreshLine(m_current
);
2668 for ( size_t line
= from
; line
<= to
; line
++ )
2670 // NB: the test works as expected even if m_current == -1
2671 if ( line
!= m_current
&& IsHighlighted(line
) )
2676 void wxListMainWindow::Freeze()
2681 void wxListMainWindow::Thaw()
2683 wxCHECK_RET( m_freezeCount
> 0, _T("thawing unfrozen list control?") );
2685 if ( --m_freezeCount
== 0 )
2689 void wxListMainWindow::OnPaint( wxPaintEvent
&WXUNUSED(event
) )
2691 // Note: a wxPaintDC must be constructed even if no drawing is
2692 // done (a Windows requirement).
2693 wxPaintDC
dc( this );
2695 if ( IsEmpty() || m_freezeCount
)
2696 // nothing to draw or not the moment to draw it
2700 // delay the repainting until we calculate all the items positions
2706 CalcScrolledPosition( 0, 0, &dev_x
, &dev_y
);
2708 dc
.SetFont( GetFont() );
2710 if ( InReportView() )
2712 int lineHeight
= GetLineHeight();
2714 size_t visibleFrom
, visibleTo
;
2715 GetVisibleLinesRange(&visibleFrom
, &visibleTo
);
2718 int xOrig
= dc
.LogicalToDeviceX( 0 );
2719 int yOrig
= dc
.LogicalToDeviceY( 0 );
2721 // tell the caller cache to cache the data
2724 wxListEvent
evCache(wxEVT_COMMAND_LIST_CACHE_HINT
,
2725 GetParent()->GetId());
2726 evCache
.SetEventObject( GetParent() );
2727 evCache
.m_oldItemIndex
= visibleFrom
;
2728 evCache
.m_itemIndex
= visibleTo
;
2729 GetParent()->GetEventHandler()->ProcessEvent( evCache
);
2732 for ( size_t line
= visibleFrom
; line
<= visibleTo
; line
++ )
2734 rectLine
= GetLineRect(line
);
2737 if ( !IsExposed(rectLine
.x
+ xOrig
, rectLine
.y
+ yOrig
,
2738 rectLine
.width
, rectLine
.height
) )
2740 // don't redraw unaffected lines to avoid flicker
2744 GetLine(line
)->DrawInReportMode( &dc
,
2746 GetLineHighlightRect(line
),
2747 IsHighlighted(line
) );
2750 if ( HasFlag(wxLC_HRULES
) )
2752 wxPen
pen(GetRuleColour(), 1, wxSOLID
);
2753 wxSize clientSize
= GetClientSize();
2755 // Don't draw the first one
2756 for ( size_t i
= visibleFrom
+ 1; i
<= visibleTo
; i
++ )
2759 dc
.SetBrush( *wxTRANSPARENT_BRUSH
);
2760 dc
.DrawLine(0 - dev_x
, i
* lineHeight
,
2761 clientSize
.x
- dev_x
, i
* lineHeight
);
2764 // Draw last horizontal rule
2765 if ( visibleTo
== GetItemCount() - 1 )
2768 dc
.SetBrush( *wxTRANSPARENT_BRUSH
);
2769 dc
.DrawLine(0 - dev_x
, (m_lineTo
+ 1) * lineHeight
,
2770 clientSize
.x
- dev_x
, (m_lineTo
+ 1) * lineHeight
);
2774 // Draw vertical rules if required
2775 if ( HasFlag(wxLC_VRULES
) && !IsEmpty() )
2777 wxPen
pen(GetRuleColour(), 1, wxSOLID
);
2778 wxRect firstItemRect
, lastItemRect
;
2780 GetItemRect(visibleFrom
, firstItemRect
);
2781 GetItemRect(visibleTo
, lastItemRect
);
2782 int x
= firstItemRect
.GetX();
2784 dc
.SetBrush(* wxTRANSPARENT_BRUSH
);
2786 for (int col
= 0; col
< GetColumnCount(); col
++)
2788 int colWidth
= GetColumnWidth(col
);
2790 dc
.DrawLine(x
- dev_x
- 2, firstItemRect
.GetY() - 1 - dev_y
,
2791 x
- dev_x
- 2, lastItemRect
.GetBottom() + 1 - dev_y
);
2797 size_t count
= GetItemCount();
2798 for ( size_t i
= 0; i
< count
; i
++ )
2800 GetLine(i
)->Draw( &dc
);
2805 // Don't draw rect outline under Mac at all.
2810 wxRect
rect( GetLineHighlightRect( m_current
) );
2812 dc
.SetPen( *wxBLACK_PEN
);
2813 dc
.SetBrush( *wxTRANSPARENT_BRUSH
);
2814 dc
.DrawRectangle( rect
);
2816 wxRendererNative::Get().DrawItemSelectionRect( this, dc
, rect
, wxCONTROL_CURRENT
|wxCONTROL_FOCUSED
);
2824 void wxListMainWindow::HighlightAll( bool on
)
2826 if ( IsSingleSel() )
2828 wxASSERT_MSG( !on
, _T("can't do this in a single selection control") );
2830 // we just have one item to turn off
2831 if ( HasCurrent() && IsHighlighted(m_current
) )
2833 HighlightLine(m_current
, false);
2834 RefreshLine(m_current
);
2839 HighlightLines(0, GetItemCount() - 1, on
);
2843 void wxListMainWindow::SendNotify( size_t line
,
2844 wxEventType command
,
2845 const wxPoint
& point
)
2847 wxListEvent
le( command
, GetParent()->GetId() );
2848 le
.SetEventObject( GetParent() );
2850 le
.m_itemIndex
= line
;
2852 // set only for events which have position
2853 if ( point
!= wxDefaultPosition
)
2854 le
.m_pointDrag
= point
;
2856 // don't try to get the line info for virtual list controls: the main
2857 // program has it anyhow and if we did it would result in accessing all
2858 // the lines, even those which are not visible now and this is precisely
2859 // what we're trying to avoid
2862 if ( line
!= (size_t)-1 )
2864 GetLine(line
)->GetItem( 0, le
.m_item
);
2866 //else: this happens for wxEVT_COMMAND_LIST_ITEM_FOCUSED event
2868 //else: there may be no more such item
2870 GetParent()->GetEventHandler()->ProcessEvent( le
);
2873 void wxListMainWindow::ChangeCurrent(size_t current
)
2875 m_current
= current
;
2877 SendNotify(current
, wxEVT_COMMAND_LIST_ITEM_FOCUSED
);
2880 wxTextCtrl
*wxListMainWindow::EditLabel(long item
, wxClassInfo
* textControlClass
)
2882 wxCHECK_MSG( (item
>= 0) && ((size_t)item
< GetItemCount()), NULL
,
2883 wxT("wrong index in wxGenericListCtrl::EditLabel()") );
2885 wxASSERT_MSG( textControlClass
->IsKindOf(CLASSINFO(wxTextCtrl
)),
2886 wxT("EditLabel() needs a text control") );
2888 size_t itemEdit
= (size_t)item
;
2890 wxListEvent
le( wxEVT_COMMAND_LIST_BEGIN_LABEL_EDIT
, GetParent()->GetId() );
2891 le
.SetEventObject( GetParent() );
2892 le
.m_itemIndex
= item
;
2893 wxListLineData
*data
= GetLine(itemEdit
);
2894 wxCHECK_MSG( data
, NULL
, _T("invalid index in EditLabel()") );
2895 data
->GetItem( 0, le
.m_item
);
2897 if ( GetParent()->GetEventHandler()->ProcessEvent( le
) && !le
.IsAllowed() )
2899 // vetoed by user code
2903 // We have to call this here because the label in question might just have
2904 // been added and no screen update taken place.
2908 wxTextCtrl
* const text
= (wxTextCtrl
*)textControlClass
->CreateObject();
2909 m_textctrlWrapper
= new wxListTextCtrlWrapper(this, text
, item
);
2910 return m_textctrlWrapper
->GetText();
2913 void wxListMainWindow::OnRenameTimer()
2915 wxCHECK_RET( HasCurrent(), wxT("unexpected rename timer") );
2917 EditLabel( m_current
);
2920 bool wxListMainWindow::OnRenameAccept(size_t itemEdit
, const wxString
& value
)
2922 wxListEvent
le( wxEVT_COMMAND_LIST_END_LABEL_EDIT
, GetParent()->GetId() );
2923 le
.SetEventObject( GetParent() );
2924 le
.m_itemIndex
= itemEdit
;
2926 wxListLineData
*data
= GetLine(itemEdit
);
2928 wxCHECK_MSG( data
, false, _T("invalid index in OnRenameAccept()") );
2930 data
->GetItem( 0, le
.m_item
);
2931 le
.m_item
.m_text
= value
;
2932 return !GetParent()->GetEventHandler()->ProcessEvent( le
) ||
2936 void wxListMainWindow::OnRenameCancelled(size_t itemEdit
)
2938 // let owner know that the edit was cancelled
2939 wxListEvent
le( wxEVT_COMMAND_LIST_END_LABEL_EDIT
, GetParent()->GetId() );
2941 le
.SetEditCanceled(true);
2943 le
.SetEventObject( GetParent() );
2944 le
.m_itemIndex
= itemEdit
;
2946 wxListLineData
*data
= GetLine(itemEdit
);
2947 wxCHECK_RET( data
, _T("invalid index in OnRenameCancelled()") );
2949 data
->GetItem( 0, le
.m_item
);
2950 GetEventHandler()->ProcessEvent( le
);
2953 void wxListMainWindow::OnMouse( wxMouseEvent
&event
)
2957 // On wxMac we can't depend on the EVT_KILL_FOCUS event to properly
2958 // shutdown the edit control when the mouse is clicked elsewhere on the
2959 // listctrl because the order of events is different (or something like
2960 // that), so explicitly end the edit if it is active.
2961 if ( event
.LeftDown() && m_textctrlWrapper
)
2962 m_textctrlWrapper
->AcceptChangesAndFinish();
2965 event
.SetEventObject( GetParent() );
2966 if ( GetParent()->GetEventHandler()->ProcessEvent( event
) )
2969 if (event
.GetEventType() == wxEVT_MOUSEWHEEL
)
2971 // let the base handle mouse wheel events.
2976 if ( !HasCurrent() || IsEmpty() )
2978 if (event
.RightDown())
2980 SendNotify( (size_t)-1, wxEVT_COMMAND_LIST_ITEM_RIGHT_CLICK
, event
.GetPosition() );
2981 // Allow generation of context menu event
2990 if ( !(event
.Dragging() || event
.ButtonDown() || event
.LeftUp() ||
2991 event
.ButtonDClick()) )
2994 int x
= event
.GetX();
2995 int y
= event
.GetY();
2996 CalcUnscrolledPosition( x
, y
, &x
, &y
);
2998 // where did we hit it (if we did)?
3001 size_t count
= GetItemCount(),
3004 if ( InReportView() )
3006 current
= y
/ GetLineHeight();
3007 if ( current
< count
)
3008 hitResult
= HitTestLine(current
, x
, y
);
3012 // TODO: optimize it too! this is less simple than for report view but
3013 // enumerating all items is still not a way to do it!!
3014 for ( current
= 0; current
< count
; current
++ )
3016 hitResult
= HitTestLine(current
, x
, y
);
3022 if (event
.Dragging())
3024 if (m_dragCount
== 0)
3026 // we have to report the raw, physical coords as we want to be
3027 // able to call HitTest(event.m_pointDrag) from the user code to
3028 // get the item being dragged
3029 m_dragStart
= event
.GetPosition();
3034 if (m_dragCount
!= 3)
3037 int command
= event
.RightIsDown() ? wxEVT_COMMAND_LIST_BEGIN_RDRAG
3038 : wxEVT_COMMAND_LIST_BEGIN_DRAG
;
3040 wxListEvent
le( command
, GetParent()->GetId() );
3041 le
.SetEventObject( GetParent() );
3042 le
.m_itemIndex
= m_lineLastClicked
;
3043 le
.m_pointDrag
= m_dragStart
;
3044 GetParent()->GetEventHandler()->ProcessEvent( le
);
3055 // outside of any item
3056 if (event
.RightDown())
3058 SendNotify( (size_t) -1, wxEVT_COMMAND_LIST_ITEM_RIGHT_CLICK
, event
.GetPosition() );
3059 // Allow generation of context menu event
3064 // reset the selection and bail out
3065 HighlightAll(false);
3071 bool forceClick
= false;
3072 if (event
.ButtonDClick())
3074 m_renameTimer
->Stop();
3075 m_lastOnSame
= false;
3077 if ( current
== m_lineLastClicked
)
3079 SendNotify( current
, wxEVT_COMMAND_LIST_ITEM_ACTIVATED
);
3085 // The first click was on another item, so don't interpret this as
3086 // a double click, but as a simple click instead
3093 if (m_lineSelectSingleOnUp
!= (size_t)-1)
3095 // select single line
3096 HighlightAll( false );
3097 ReverseHighlight(m_lineSelectSingleOnUp
);
3102 if ((current
== m_current
) &&
3103 (hitResult
== wxLIST_HITTEST_ONITEMLABEL
) &&
3104 HasFlag(wxLC_EDIT_LABELS
) )
3106 m_renameTimer
->Start( 100, true );
3110 m_lastOnSame
= false;
3111 m_lineSelectSingleOnUp
= (size_t)-1;
3115 // This is necessary, because after a DnD operation in
3116 // from and to ourself, the up event is swallowed by the
3117 // DnD code. So on next non-up event (which means here and
3118 // now) m_lineSelectSingleOnUp should be reset.
3119 m_lineSelectSingleOnUp
= (size_t)-1;
3121 if (event
.RightDown())
3123 m_lineBeforeLastClicked
= m_lineLastClicked
;
3124 m_lineLastClicked
= current
;
3126 // If the item is already selected, do not update the selection.
3127 // Multi-selections should not be cleared if a selected item is clicked.
3128 if (!IsHighlighted(current
))
3130 HighlightAll(false);
3131 ChangeCurrent(current
);
3132 ReverseHighlight(m_current
);
3135 SendNotify( current
, wxEVT_COMMAND_LIST_ITEM_RIGHT_CLICK
, event
.GetPosition() );
3137 // Allow generation of context menu event
3140 else if (event
.MiddleDown())
3142 SendNotify( current
, wxEVT_COMMAND_LIST_ITEM_MIDDLE_CLICK
);
3144 else if ( event
.LeftDown() || forceClick
)
3146 m_lineBeforeLastClicked
= m_lineLastClicked
;
3147 m_lineLastClicked
= current
;
3149 size_t oldCurrent
= m_current
;
3150 bool oldWasSelected
= IsHighlighted(m_current
);
3152 bool cmdModifierDown
= event
.CmdDown();
3153 if ( IsSingleSel() || !(cmdModifierDown
|| event
.ShiftDown()) )
3155 if ( IsSingleSel() || !IsHighlighted(current
) )
3157 HighlightAll( false );
3159 ChangeCurrent(current
);
3161 ReverseHighlight(m_current
);
3163 else // multi sel & current is highlighted & no mod keys
3165 m_lineSelectSingleOnUp
= current
;
3166 ChangeCurrent(current
); // change focus
3169 else // multi sel & either ctrl or shift is down
3171 if (cmdModifierDown
)
3173 ChangeCurrent(current
);
3175 ReverseHighlight(m_current
);
3177 else if (event
.ShiftDown())
3179 ChangeCurrent(current
);
3181 size_t lineFrom
= oldCurrent
,
3184 if ( lineTo
< lineFrom
)
3187 lineFrom
= m_current
;
3190 HighlightLines(lineFrom
, lineTo
);
3192 else // !ctrl, !shift
3194 // test in the enclosing if should make it impossible
3195 wxFAIL_MSG( _T("how did we get here?") );
3199 if (m_current
!= oldCurrent
)
3200 RefreshLine( oldCurrent
);
3202 // forceClick is only set if the previous click was on another item
3203 m_lastOnSame
= !forceClick
&& (m_current
== oldCurrent
) && oldWasSelected
;
3207 void wxListMainWindow::MoveToItem(size_t item
)
3209 if ( item
== (size_t)-1 )
3212 wxRect rect
= GetLineRect(item
);
3214 int client_w
, client_h
;
3215 GetClientSize( &client_w
, &client_h
);
3217 const int hLine
= GetLineHeight();
3219 int view_x
= SCROLL_UNIT_X
* GetScrollPos( wxHORIZONTAL
);
3220 int view_y
= hLine
* GetScrollPos( wxVERTICAL
);
3222 if ( InReportView() )
3224 // the next we need the range of lines shown it might be different,
3225 // so recalculate it
3226 ResetVisibleLinesRange();
3228 if (rect
.y
< view_y
)
3229 Scroll( -1, rect
.y
/ hLine
);
3230 if (rect
.y
+ rect
.height
+ 5 > view_y
+ client_h
)
3231 Scroll( -1, (rect
.y
+ rect
.height
- client_h
+ hLine
) / hLine
);
3235 if (rect
.x
-view_x
< 5)
3236 Scroll( (rect
.x
- 5) / SCROLL_UNIT_X
, -1 );
3237 if (rect
.x
+ rect
.width
- 5 > view_x
+ client_w
)
3238 Scroll( (rect
.x
+ rect
.width
- client_w
+ SCROLL_UNIT_X
) / SCROLL_UNIT_X
, -1 );
3242 // ----------------------------------------------------------------------------
3243 // keyboard handling
3244 // ----------------------------------------------------------------------------
3246 void wxListMainWindow::OnArrowChar(size_t newCurrent
, const wxKeyEvent
& event
)
3248 wxCHECK_RET( newCurrent
< (size_t)GetItemCount(),
3249 _T("invalid item index in OnArrowChar()") );
3251 size_t oldCurrent
= m_current
;
3253 // in single selection we just ignore Shift as we can't select several
3255 if ( event
.ShiftDown() && !IsSingleSel() )
3257 ChangeCurrent(newCurrent
);
3259 // refresh the old focus to remove it
3260 RefreshLine( oldCurrent
);
3262 // select all the items between the old and the new one
3263 if ( oldCurrent
> newCurrent
)
3265 newCurrent
= oldCurrent
;
3266 oldCurrent
= m_current
;
3269 HighlightLines(oldCurrent
, newCurrent
);
3273 // all previously selected items are unselected unless ctrl is held
3274 if ( !event
.ControlDown() )
3275 HighlightAll(false);
3277 ChangeCurrent(newCurrent
);
3279 // refresh the old focus to remove it
3280 RefreshLine( oldCurrent
);
3282 if ( !event
.ControlDown() )
3284 HighlightLine( m_current
, true );
3288 RefreshLine( m_current
);
3293 void wxListMainWindow::OnKeyDown( wxKeyEvent
&event
)
3295 wxWindow
*parent
= GetParent();
3297 // propagate the key event upwards
3298 wxKeyEvent
ke( wxEVT_KEY_DOWN
);
3299 ke
.m_shiftDown
= event
.m_shiftDown
;
3300 ke
.m_controlDown
= event
.m_controlDown
;
3301 ke
.m_altDown
= event
.m_altDown
;
3302 ke
.m_metaDown
= event
.m_metaDown
;
3303 ke
.m_keyCode
= event
.m_keyCode
;
3306 ke
.SetEventObject( parent
);
3307 if (parent
->GetEventHandler()->ProcessEvent( ke
)) return;
3312 void wxListMainWindow::OnChar( wxKeyEvent
&event
)
3314 wxWindow
*parent
= GetParent();
3316 // send a list_key event up
3319 wxListEvent
le( wxEVT_COMMAND_LIST_KEY_DOWN
, GetParent()->GetId() );
3320 le
.m_itemIndex
= m_current
;
3321 GetLine(m_current
)->GetItem( 0, le
.m_item
);
3322 le
.m_code
= event
.GetKeyCode();
3323 le
.SetEventObject( parent
);
3324 parent
->GetEventHandler()->ProcessEvent( le
);
3327 // propagate the char event upwards
3328 wxKeyEvent
ke( wxEVT_CHAR
);
3329 ke
.m_shiftDown
= event
.m_shiftDown
;
3330 ke
.m_controlDown
= event
.m_controlDown
;
3331 ke
.m_altDown
= event
.m_altDown
;
3332 ke
.m_metaDown
= event
.m_metaDown
;
3333 ke
.m_keyCode
= event
.m_keyCode
;
3336 ke
.SetEventObject( parent
);
3337 if (parent
->GetEventHandler()->ProcessEvent( ke
)) return;
3339 if (event
.GetKeyCode() == WXK_TAB
)
3341 wxNavigationKeyEvent nevent
;
3342 nevent
.SetWindowChange( event
.ControlDown() );
3343 nevent
.SetDirection( !event
.ShiftDown() );
3344 nevent
.SetEventObject( GetParent()->GetParent() );
3345 nevent
.SetCurrentFocus( m_parent
);
3346 if (GetParent()->GetParent()->GetEventHandler()->ProcessEvent( nevent
))
3350 // no item -> nothing to do
3357 // don't use m_linesPerPage directly as it might not be computed yet
3358 const int pageSize
= GetCountPerPage();
3359 wxCHECK_RET( pageSize
, _T("should have non zero page size") );
3361 if (GetLayoutDirection() == wxLayout_RightToLeft
)
3363 if (event
.GetKeyCode() == WXK_RIGHT
)
3364 event
.m_keyCode
= WXK_LEFT
;
3365 else if (event
.GetKeyCode() == WXK_LEFT
)
3366 event
.m_keyCode
= WXK_RIGHT
;
3369 switch ( event
.GetKeyCode() )
3372 if ( m_current
> 0 )
3373 OnArrowChar( m_current
- 1, event
);
3377 if ( m_current
< (size_t)GetItemCount() - 1 )
3378 OnArrowChar( m_current
+ 1, event
);
3383 OnArrowChar( GetItemCount() - 1, event
);
3388 OnArrowChar( 0, event
);
3393 int steps
= InReportView() ? pageSize
- 1
3394 : m_current
% pageSize
;
3396 int index
= m_current
- steps
;
3400 OnArrowChar( index
, event
);
3406 int steps
= InReportView()
3408 : pageSize
- (m_current
% pageSize
) - 1;
3410 size_t index
= m_current
+ steps
;
3411 size_t count
= GetItemCount();
3412 if ( index
>= count
)
3415 OnArrowChar( index
, event
);
3420 if ( !InReportView() )
3422 int index
= m_current
- pageSize
;
3426 OnArrowChar( index
, event
);
3431 if ( !InReportView() )
3433 size_t index
= m_current
+ pageSize
;
3435 size_t count
= GetItemCount();
3436 if ( index
>= count
)
3439 OnArrowChar( index
, event
);
3444 if ( IsSingleSel() )
3446 SendNotify( m_current
, wxEVT_COMMAND_LIST_ITEM_ACTIVATED
);
3448 if ( IsHighlighted(m_current
) )
3450 // don't unselect the item in single selection mode
3453 //else: select it in ReverseHighlight() below if unselected
3456 ReverseHighlight(m_current
);
3461 SendNotify( m_current
, wxEVT_COMMAND_LIST_ITEM_ACTIVATED
);
3469 // ----------------------------------------------------------------------------
3471 // ----------------------------------------------------------------------------
3473 void wxListMainWindow::OnSetFocus( wxFocusEvent
&WXUNUSED(event
) )
3477 wxFocusEvent
event( wxEVT_SET_FOCUS
, GetParent()->GetId() );
3478 event
.SetEventObject( GetParent() );
3479 if ( GetParent()->GetEventHandler()->ProcessEvent( event
) )
3483 // wxGTK sends us EVT_SET_FOCUS events even if we had never got
3484 // EVT_KILL_FOCUS before which means that we finish by redrawing the items
3485 // which are already drawn correctly resulting in horrible flicker - avoid
3495 void wxListMainWindow::OnKillFocus( wxFocusEvent
&WXUNUSED(event
) )
3499 wxFocusEvent
event( wxEVT_KILL_FOCUS
, GetParent()->GetId() );
3500 event
.SetEventObject( GetParent() );
3501 if ( GetParent()->GetEventHandler()->ProcessEvent( event
) )
3509 void wxListMainWindow::DrawImage( int index
, wxDC
*dc
, int x
, int y
)
3511 if ( HasFlag(wxLC_ICON
) && (m_normal_image_list
))
3513 m_normal_image_list
->Draw( index
, *dc
, x
, y
, wxIMAGELIST_DRAW_TRANSPARENT
);
3515 else if ( HasFlag(wxLC_SMALL_ICON
) && (m_small_image_list
))
3517 m_small_image_list
->Draw( index
, *dc
, x
, y
, wxIMAGELIST_DRAW_TRANSPARENT
);
3519 else if ( HasFlag(wxLC_LIST
) && (m_small_image_list
))
3521 m_small_image_list
->Draw( index
, *dc
, x
, y
, wxIMAGELIST_DRAW_TRANSPARENT
);
3523 else if ( InReportView() && (m_small_image_list
))
3525 m_small_image_list
->Draw( index
, *dc
, x
, y
, wxIMAGELIST_DRAW_TRANSPARENT
);
3529 void wxListMainWindow::GetImageSize( int index
, int &width
, int &height
) const
3531 if ( HasFlag(wxLC_ICON
) && m_normal_image_list
)
3533 m_normal_image_list
->GetSize( index
, width
, height
);
3535 else if ( HasFlag(wxLC_SMALL_ICON
) && m_small_image_list
)
3537 m_small_image_list
->GetSize( index
, width
, height
);
3539 else if ( HasFlag(wxLC_LIST
) && m_small_image_list
)
3541 m_small_image_list
->GetSize( index
, width
, height
);
3543 else if ( InReportView() && m_small_image_list
)
3545 m_small_image_list
->GetSize( index
, width
, height
);
3554 int wxListMainWindow::GetTextLength( const wxString
&s
) const
3556 wxClientDC
dc( wxConstCast(this, wxListMainWindow
) );
3557 dc
.SetFont( GetFont() );
3560 dc
.GetTextExtent( s
, &lw
, NULL
);
3562 return lw
+ AUTOSIZE_COL_MARGIN
;
3565 void wxListMainWindow::SetImageList( wxImageList
*imageList
, int which
)
3569 // calc the spacing from the icon size
3570 int width
= 0, height
= 0;
3572 if ((imageList
) && (imageList
->GetImageCount()) )
3573 imageList
->GetSize(0, width
, height
);
3575 if (which
== wxIMAGE_LIST_NORMAL
)
3577 m_normal_image_list
= imageList
;
3578 m_normal_spacing
= width
+ 8;
3581 if (which
== wxIMAGE_LIST_SMALL
)
3583 m_small_image_list
= imageList
;
3584 m_small_spacing
= width
+ 14;
3585 m_lineHeight
= 0; // ensure that the line height will be recalc'd
3589 void wxListMainWindow::SetItemSpacing( int spacing
, bool isSmall
)
3593 m_small_spacing
= spacing
;
3595 m_normal_spacing
= spacing
;
3598 int wxListMainWindow::GetItemSpacing( bool isSmall
)
3600 return isSmall
? m_small_spacing
: m_normal_spacing
;
3603 // ----------------------------------------------------------------------------
3605 // ----------------------------------------------------------------------------
3607 void wxListMainWindow::SetColumn( int col
, wxListItem
&item
)
3609 wxListHeaderDataList::compatibility_iterator node
= m_columns
.Item( col
);
3611 wxCHECK_RET( node
, _T("invalid column index in SetColumn") );
3613 if ( item
.m_width
== wxLIST_AUTOSIZE_USEHEADER
)
3614 item
.m_width
= GetTextLength( item
.m_text
);
3616 wxListHeaderData
*column
= node
->GetData();
3617 column
->SetItem( item
);
3619 wxListHeaderWindow
*headerWin
= GetListCtrl()->m_headerWin
;
3621 headerWin
->m_dirty
= true;
3625 // invalidate it as it has to be recalculated
3629 void wxListMainWindow::SetColumnWidth( int col
, int width
)
3631 wxCHECK_RET( col
>= 0 && col
< GetColumnCount(),
3632 _T("invalid column index") );
3634 wxCHECK_RET( InReportView(),
3635 _T("SetColumnWidth() can only be called in report mode.") );
3638 wxListHeaderWindow
*headerWin
= GetListCtrl()->m_headerWin
;
3640 headerWin
->m_dirty
= true;
3642 wxListHeaderDataList::compatibility_iterator node
= m_columns
.Item( col
);
3643 wxCHECK_RET( node
, _T("no column?") );
3645 wxListHeaderData
*column
= node
->GetData();
3647 size_t count
= GetItemCount();
3649 if (width
== wxLIST_AUTOSIZE_USEHEADER
)
3651 width
= GetTextLength(column
->GetText());
3653 else if ( width
== wxLIST_AUTOSIZE
)
3657 // TODO: determine the max width somehow...
3658 width
= WIDTH_COL_DEFAULT
;
3662 wxClientDC
dc(this);
3663 dc
.SetFont( GetFont() );
3665 int max
= AUTOSIZE_COL_MARGIN
;
3667 // if the cached column width isn't valid then recalculate it
3668 if (m_aColWidths
.Item(col
)->bNeedsUpdate
)
3670 for (size_t i
= 0; i
< count
; i
++)
3672 wxListLineData
*line
= GetLine( i
);
3673 wxListItemDataList::compatibility_iterator n
= line
->m_items
.Item( col
);
3675 wxCHECK_RET( n
, _T("no subitem?") );
3677 wxListItemData
*itemData
= n
->GetData();
3680 itemData
->GetItem(item
);
3681 int itemWidth
= GetItemWidthWithImage(&item
);
3682 if (itemWidth
> max
)
3686 m_aColWidths
.Item(col
)->bNeedsUpdate
= false;
3687 m_aColWidths
.Item(col
)->nMaxWidth
= max
;
3690 max
= m_aColWidths
.Item(col
)->nMaxWidth
;
3691 width
= max
+ AUTOSIZE_COL_MARGIN
;
3695 column
->SetWidth( width
);
3697 // invalidate it as it has to be recalculated
3701 int wxListMainWindow::GetHeaderWidth() const
3703 if ( !m_headerWidth
)
3705 wxListMainWindow
*self
= wxConstCast(this, wxListMainWindow
);
3707 size_t count
= GetColumnCount();
3708 for ( size_t col
= 0; col
< count
; col
++ )
3710 self
->m_headerWidth
+= GetColumnWidth(col
);
3714 return m_headerWidth
;
3717 void wxListMainWindow::GetColumn( int col
, wxListItem
&item
) const
3719 wxListHeaderDataList::compatibility_iterator node
= m_columns
.Item( col
);
3720 wxCHECK_RET( node
, _T("invalid column index in GetColumn") );
3722 wxListHeaderData
*column
= node
->GetData();
3723 column
->GetItem( item
);
3726 int wxListMainWindow::GetColumnWidth( int col
) const
3728 wxListHeaderDataList::compatibility_iterator node
= m_columns
.Item( col
);
3729 wxCHECK_MSG( node
, 0, _T("invalid column index") );
3731 wxListHeaderData
*column
= node
->GetData();
3732 return column
->GetWidth();
3735 // ----------------------------------------------------------------------------
3737 // ----------------------------------------------------------------------------
3739 void wxListMainWindow::SetItem( wxListItem
&item
)
3741 long id
= item
.m_itemId
;
3742 wxCHECK_RET( id
>= 0 && (size_t)id
< GetItemCount(),
3743 _T("invalid item index in SetItem") );
3747 wxListLineData
*line
= GetLine((size_t)id
);
3748 line
->SetItem( item
.m_col
, item
);
3750 // Set item state if user wants
3751 if ( item
.m_mask
& wxLIST_MASK_STATE
)
3752 SetItemState( item
.m_itemId
, item
.m_state
, item
.m_state
);
3756 // update the Max Width Cache if needed
3757 int width
= GetItemWidthWithImage(&item
);
3759 if (width
> m_aColWidths
.Item(item
.m_col
)->nMaxWidth
)
3760 m_aColWidths
.Item(item
.m_col
)->nMaxWidth
= width
;
3764 // update the item on screen
3766 GetItemRect(id
, rectItem
);
3767 RefreshRect(rectItem
);
3770 void wxListMainWindow::SetItemStateAll(long state
, long stateMask
)
3775 // first deal with selection
3776 if ( stateMask
& wxLIST_STATE_SELECTED
)
3778 // set/clear select state
3781 // optimized version for virtual listctrl.
3782 m_selStore
.SelectRange(0, GetItemCount() - 1, state
== wxLIST_STATE_SELECTED
);
3785 else if ( state
& wxLIST_STATE_SELECTED
)
3787 const long count
= GetItemCount();
3788 for( long i
= 0; i
< count
; i
++ )
3790 SetItemState( i
, wxLIST_STATE_SELECTED
, wxLIST_STATE_SELECTED
);
3796 // clear for non virtual (somewhat optimized by using GetNextItem())
3798 while ( (i
= GetNextItem(i
, wxLIST_NEXT_ALL
, wxLIST_STATE_SELECTED
)) != -1 )
3800 SetItemState( i
, 0, wxLIST_STATE_SELECTED
);
3805 if ( HasCurrent() && (state
== 0) && (stateMask
& wxLIST_STATE_FOCUSED
) )
3807 // unfocus all: only one item can be focussed, so clearing focus for
3808 // all items is simply clearing focus of the focussed item.
3809 SetItemState(m_current
, state
, stateMask
);
3811 //(setting focus to all items makes no sense, so it is not handled here.)
3814 void wxListMainWindow::SetItemState( long litem
, long state
, long stateMask
)
3818 SetItemStateAll(state
, stateMask
);
3822 wxCHECK_RET( litem
>= 0 && (size_t)litem
< GetItemCount(),
3823 _T("invalid list ctrl item index in SetItem") );
3825 size_t oldCurrent
= m_current
;
3826 size_t item
= (size_t)litem
; // safe because of the check above
3828 // do we need to change the focus?
3829 if ( stateMask
& wxLIST_STATE_FOCUSED
)
3831 if ( state
& wxLIST_STATE_FOCUSED
)
3833 // don't do anything if this item is already focused
3834 if ( item
!= m_current
)
3836 ChangeCurrent(item
);
3838 if ( oldCurrent
!= (size_t)-1 )
3840 if ( IsSingleSel() )
3842 HighlightLine(oldCurrent
, false);
3845 RefreshLine(oldCurrent
);
3848 RefreshLine( m_current
);
3853 // don't do anything if this item is not focused
3854 if ( item
== m_current
)
3858 if ( IsSingleSel() )
3860 // we must unselect the old current item as well or we
3861 // might end up with more than one selected item in a
3862 // single selection control
3863 HighlightLine(oldCurrent
, false);
3866 RefreshLine( oldCurrent
);
3871 // do we need to change the selection state?
3872 if ( stateMask
& wxLIST_STATE_SELECTED
)
3874 bool on
= (state
& wxLIST_STATE_SELECTED
) != 0;
3876 if ( IsSingleSel() )
3880 // selecting the item also makes it the focused one in the
3882 if ( m_current
!= item
)
3884 ChangeCurrent(item
);
3886 if ( oldCurrent
!= (size_t)-1 )
3888 HighlightLine( oldCurrent
, false );
3889 RefreshLine( oldCurrent
);
3895 // only the current item may be selected anyhow
3896 if ( item
!= m_current
)
3901 if ( HighlightLine(item
, on
) )
3908 int wxListMainWindow::GetItemState( long item
, long stateMask
) const
3910 wxCHECK_MSG( item
>= 0 && (size_t)item
< GetItemCount(), 0,
3911 _T("invalid list ctrl item index in GetItemState()") );
3913 int ret
= wxLIST_STATE_DONTCARE
;
3915 if ( stateMask
& wxLIST_STATE_FOCUSED
)
3917 if ( (size_t)item
== m_current
)
3918 ret
|= wxLIST_STATE_FOCUSED
;
3921 if ( stateMask
& wxLIST_STATE_SELECTED
)
3923 if ( IsHighlighted(item
) )
3924 ret
|= wxLIST_STATE_SELECTED
;
3930 void wxListMainWindow::GetItem( wxListItem
&item
) const
3932 wxCHECK_RET( item
.m_itemId
>= 0 && (size_t)item
.m_itemId
< GetItemCount(),
3933 _T("invalid item index in GetItem") );
3935 wxListLineData
*line
= GetLine((size_t)item
.m_itemId
);
3936 line
->GetItem( item
.m_col
, item
);
3938 // Get item state if user wants it
3939 if ( item
.m_mask
& wxLIST_MASK_STATE
)
3940 item
.m_state
= GetItemState( item
.m_itemId
, wxLIST_STATE_SELECTED
|
3941 wxLIST_STATE_FOCUSED
);
3944 // ----------------------------------------------------------------------------
3946 // ----------------------------------------------------------------------------
3948 size_t wxListMainWindow::GetItemCount() const
3950 return IsVirtual() ? m_countVirt
: m_lines
.GetCount();
3953 void wxListMainWindow::SetItemCount(long count
)
3955 m_selStore
.SetItemCount(count
);
3956 m_countVirt
= count
;
3958 ResetVisibleLinesRange();
3960 // scrollbars must be reset
3964 int wxListMainWindow::GetSelectedItemCount() const
3966 // deal with the quick case first
3967 if ( IsSingleSel() )
3968 return HasCurrent() ? IsHighlighted(m_current
) : false;
3970 // virtual controls remmebers all its selections itself
3972 return m_selStore
.GetSelectedCount();
3974 // TODO: we probably should maintain the number of items selected even for
3975 // non virtual controls as enumerating all lines is really slow...
3976 size_t countSel
= 0;
3977 size_t count
= GetItemCount();
3978 for ( size_t line
= 0; line
< count
; line
++ )
3980 if ( GetLine(line
)->IsHighlighted() )
3987 // ----------------------------------------------------------------------------
3988 // item position/size
3989 // ----------------------------------------------------------------------------
3991 wxRect
wxListMainWindow::GetViewRect() const
3993 wxASSERT_MSG( !HasFlag(wxLC_REPORT
| wxLC_LIST
),
3994 _T("wxListCtrl::GetViewRect() only works in icon mode") );
3996 // we need to find the longest/tallest label
3997 wxCoord xMax
= 0, yMax
= 0;
3998 const int count
= GetItemCount();
4001 for ( int i
= 0; i
< count
; i
++ )
4006 wxCoord x
= r
.GetRight(),
4016 // some fudge needed to make it look prettier
4017 xMax
+= 2 * EXTRA_BORDER_X
;
4018 yMax
+= 2 * EXTRA_BORDER_Y
;
4020 // account for the scrollbars if necessary
4021 const wxSize sizeAll
= GetClientSize();
4022 if ( xMax
> sizeAll
.x
)
4023 yMax
+= wxSystemSettings::GetMetric(wxSYS_HSCROLL_Y
);
4024 if ( yMax
> sizeAll
.y
)
4025 xMax
+= wxSystemSettings::GetMetric(wxSYS_VSCROLL_X
);
4027 return wxRect(0, 0, xMax
, yMax
);
4030 void wxListMainWindow::GetItemRect( long index
, wxRect
&rect
) const
4032 wxCHECK_RET( index
>= 0 && (size_t)index
< GetItemCount(),
4033 _T("invalid index in GetItemRect") );
4035 // ensure that we're laid out, otherwise we could return nonsense
4038 wxConstCast(this, wxListMainWindow
)->
4039 RecalculatePositions(true /* no refresh */);
4042 rect
= GetLineRect((size_t)index
);
4044 CalcScrolledPosition(rect
.x
, rect
.y
, &rect
.x
, &rect
.y
);
4047 bool wxListMainWindow::GetItemPosition(long item
, wxPoint
& pos
) const
4050 GetItemRect(item
, rect
);
4058 // ----------------------------------------------------------------------------
4059 // geometry calculation
4060 // ----------------------------------------------------------------------------
4062 void wxListMainWindow::RecalculatePositions(bool noRefresh
)
4064 const int lineHeight
= GetLineHeight();
4066 wxClientDC
dc( this );
4067 dc
.SetFont( GetFont() );
4069 const size_t count
= GetItemCount();
4072 if ( HasFlag(wxLC_ICON
) )
4073 iconSpacing
= m_normal_spacing
;
4074 else if ( HasFlag(wxLC_SMALL_ICON
) )
4075 iconSpacing
= m_small_spacing
;
4079 // Note that we do not call GetClientSize() here but
4080 // GetSize() and subtract the border size for sunken
4081 // borders manually. This is technically incorrect,
4082 // but we need to know the client area's size WITHOUT
4083 // scrollbars here. Since we don't know if there are
4084 // any scrollbars, we use GetSize() instead. Another
4085 // solution would be to call SetScrollbars() here to
4086 // remove the scrollbars and call GetClientSize() then,
4087 // but this might result in flicker and - worse - will
4088 // reset the scrollbars to 0 which is not good at all
4089 // if you resize a dialog/window, but don't want to
4090 // reset the window scrolling. RR.
4091 // Furthermore, we actually do NOT subtract the border
4092 // width as 2 pixels is just the extra space which we
4093 // need around the actual content in the window. Other-
4094 // wise the text would e.g. touch the upper border. RR.
4097 GetSize( &clientWidth
, &clientHeight
);
4099 if ( InReportView() )
4101 // all lines have the same height and we scroll one line per step
4102 int entireHeight
= count
* lineHeight
+ LINE_SPACING
;
4104 m_linesPerPage
= clientHeight
/ lineHeight
;
4106 ResetVisibleLinesRange();
4108 SetScrollbars( SCROLL_UNIT_X
, lineHeight
,
4109 GetHeaderWidth() / SCROLL_UNIT_X
,
4110 (entireHeight
+ lineHeight
- 1) / lineHeight
,
4111 GetScrollPos(wxHORIZONTAL
),
4112 GetScrollPos(wxVERTICAL
),
4117 // we have 3 different layout strategies: either layout all items
4118 // horizontally/vertically (wxLC_ALIGN_XXX styles explicitly given) or
4119 // to arrange them in top to bottom, left to right (don't ask me why
4120 // not the other way round...) order
4121 if ( HasFlag(wxLC_ALIGN_LEFT
| wxLC_ALIGN_TOP
) )
4123 int x
= EXTRA_BORDER_X
;
4124 int y
= EXTRA_BORDER_Y
;
4126 wxCoord widthMax
= 0;
4129 for ( i
= 0; i
< count
; i
++ )
4131 wxListLineData
*line
= GetLine(i
);
4132 line
->CalculateSize( &dc
, iconSpacing
);
4133 line
->SetPosition( x
, y
, iconSpacing
);
4135 wxSize sizeLine
= GetLineSize(i
);
4137 if ( HasFlag(wxLC_ALIGN_TOP
) )
4139 if ( sizeLine
.x
> widthMax
)
4140 widthMax
= sizeLine
.x
;
4144 else // wxLC_ALIGN_LEFT
4146 x
+= sizeLine
.x
+ MARGIN_BETWEEN_ROWS
;
4150 if ( HasFlag(wxLC_ALIGN_TOP
) )
4152 // traverse the items again and tweak their sizes so that they are
4153 // all the same in a row
4154 for ( i
= 0; i
< count
; i
++ )
4156 wxListLineData
*line
= GetLine(i
);
4157 line
->m_gi
->ExtendWidth(widthMax
);
4165 (x
+ SCROLL_UNIT_X
) / SCROLL_UNIT_X
,
4166 (y
+ lineHeight
) / lineHeight
,
4167 GetScrollPos( wxHORIZONTAL
),
4168 GetScrollPos( wxVERTICAL
),
4172 else // "flowed" arrangement, the most complicated case
4174 // at first we try without any scrollbars, if the items don't fit into
4175 // the window, we recalculate after subtracting the space taken by the
4178 int entireWidth
= 0;
4180 for (int tries
= 0; tries
< 2; tries
++)
4182 entireWidth
= 2 * EXTRA_BORDER_X
;
4186 // Now we have decided that the items do not fit into the
4187 // client area, so we need a scrollbar
4188 entireWidth
+= SCROLL_UNIT_X
;
4191 int x
= EXTRA_BORDER_X
;
4192 int y
= EXTRA_BORDER_Y
;
4193 int maxWidthInThisRow
= 0;
4196 int currentlyVisibleLines
= 0;
4198 for (size_t i
= 0; i
< count
; i
++)
4200 currentlyVisibleLines
++;
4201 wxListLineData
*line
= GetLine( i
);
4202 line
->CalculateSize( &dc
, iconSpacing
);
4203 line
->SetPosition( x
, y
, iconSpacing
);
4205 wxSize sizeLine
= GetLineSize( i
);
4207 if ( maxWidthInThisRow
< sizeLine
.x
)
4208 maxWidthInThisRow
= sizeLine
.x
;
4211 if (currentlyVisibleLines
> m_linesPerPage
)
4212 m_linesPerPage
= currentlyVisibleLines
;
4214 if ( y
+ sizeLine
.y
>= clientHeight
)
4216 currentlyVisibleLines
= 0;
4218 maxWidthInThisRow
+= MARGIN_BETWEEN_ROWS
;
4219 x
+= maxWidthInThisRow
;
4220 entireWidth
+= maxWidthInThisRow
;
4221 maxWidthInThisRow
= 0;
4224 // We have reached the last item.
4225 if ( i
== count
- 1 )
4226 entireWidth
+= maxWidthInThisRow
;
4228 if ( (tries
== 0) &&
4229 (entireWidth
+ SCROLL_UNIT_X
> clientWidth
) )
4231 clientHeight
-= wxSystemSettings::
4232 GetMetric(wxSYS_HSCROLL_Y
);
4237 if ( i
== count
- 1 )
4238 tries
= 1; // Everything fits, no second try required.
4246 (entireWidth
+ SCROLL_UNIT_X
) / SCROLL_UNIT_X
,
4248 GetScrollPos( wxHORIZONTAL
),
4257 // FIXME: why should we call it from here?
4264 void wxListMainWindow::RefreshAll()
4269 wxListHeaderWindow
*headerWin
= GetListCtrl()->m_headerWin
;
4270 if ( headerWin
&& headerWin
->m_dirty
)
4272 headerWin
->m_dirty
= false;
4273 headerWin
->Refresh();
4277 void wxListMainWindow::UpdateCurrent()
4279 if ( !HasCurrent() && !IsEmpty() )
4283 long wxListMainWindow::GetNextItem( long item
,
4284 int WXUNUSED(geometry
),
4288 max
= GetItemCount();
4289 wxCHECK_MSG( (ret
== -1) || (ret
< max
), -1,
4290 _T("invalid listctrl index in GetNextItem()") );
4292 // notice that we start with the next item (or the first one if item == -1)
4293 // and this is intentional to allow writing a simple loop to iterate over
4294 // all selected items
4297 // this is not an error because the index was OK initially,
4298 // just no such item
4305 size_t count
= GetItemCount();
4306 for ( size_t line
= (size_t)ret
; line
< count
; line
++ )
4308 if ( (state
& wxLIST_STATE_FOCUSED
) && (line
== m_current
) )
4311 if ( (state
& wxLIST_STATE_SELECTED
) && IsHighlighted(line
) )
4318 // ----------------------------------------------------------------------------
4320 // ----------------------------------------------------------------------------
4322 void wxListMainWindow::DeleteItem( long lindex
)
4324 size_t count
= GetItemCount();
4326 wxCHECK_RET( (lindex
>= 0) && ((size_t)lindex
< count
),
4327 _T("invalid item index in DeleteItem") );
4329 size_t index
= (size_t)lindex
;
4331 // we don't need to adjust the index for the previous items
4332 if ( HasCurrent() && m_current
>= index
)
4334 // if the current item is being deleted, we want the next one to
4335 // become selected - unless there is no next one - so don't adjust
4336 // m_current in this case
4337 if ( m_current
!= index
|| m_current
== count
- 1 )
4341 if ( InReportView() )
4343 // mark the Column Max Width cache as dirty if the items in the line
4344 // we're deleting contain the Max Column Width
4345 wxListLineData
* const line
= GetLine(index
);
4346 wxListItemDataList::compatibility_iterator n
;
4347 wxListItemData
*itemData
;
4351 for (size_t i
= 0; i
< m_columns
.GetCount(); i
++)
4353 n
= line
->m_items
.Item( i
);
4354 itemData
= n
->GetData();
4355 itemData
->GetItem(item
);
4357 itemWidth
= GetItemWidthWithImage(&item
);
4359 if (itemWidth
>= m_aColWidths
.Item(i
)->nMaxWidth
)
4360 m_aColWidths
.Item(i
)->bNeedsUpdate
= true;
4363 ResetVisibleLinesRange();
4366 SendNotify( index
, wxEVT_COMMAND_LIST_DELETE_ITEM
, wxDefaultPosition
);
4371 m_selStore
.OnItemDelete(index
);
4375 m_lines
.RemoveAt( index
);
4378 // we need to refresh the (vert) scrollbar as the number of items changed
4381 RefreshAfter(index
);
4384 void wxListMainWindow::DeleteColumn( int col
)
4386 wxListHeaderDataList::compatibility_iterator node
= m_columns
.Item( col
);
4388 wxCHECK_RET( node
, wxT("invalid column index in DeleteColumn()") );
4391 delete node
->GetData();
4392 m_columns
.Erase( node
);
4396 // update all the items
4397 for ( size_t i
= 0; i
< m_lines
.GetCount(); i
++ )
4399 wxListLineData
* const line
= GetLine(i
);
4400 wxListItemDataList::compatibility_iterator n
= line
->m_items
.Item( col
);
4401 delete n
->GetData();
4402 line
->m_items
.Erase(n
);
4406 if ( InReportView() ) // we only cache max widths when in Report View
4408 delete m_aColWidths
.Item(col
);
4409 m_aColWidths
.RemoveAt(col
);
4412 // invalidate it as it has to be recalculated
4416 void wxListMainWindow::DoDeleteAllItems()
4419 // nothing to do - in particular, don't send the event
4424 // to make the deletion of all items faster, we don't send the
4425 // notifications for each item deletion in this case but only one event
4426 // for all of them: this is compatible with wxMSW and documented in
4427 // DeleteAllItems() description
4429 wxListEvent
event( wxEVT_COMMAND_LIST_DELETE_ALL_ITEMS
, GetParent()->GetId() );
4430 event
.SetEventObject( GetParent() );
4431 GetParent()->GetEventHandler()->ProcessEvent( event
);
4439 if ( InReportView() )
4441 ResetVisibleLinesRange();
4442 for (size_t i
= 0; i
< m_aColWidths
.GetCount(); i
++)
4444 m_aColWidths
.Item(i
)->bNeedsUpdate
= true;
4451 void wxListMainWindow::DeleteAllItems()
4455 RecalculatePositions();
4458 void wxListMainWindow::DeleteEverything()
4460 WX_CLEAR_LIST(wxListHeaderDataList
, m_columns
);
4461 WX_CLEAR_ARRAY(m_aColWidths
);
4466 // ----------------------------------------------------------------------------
4467 // scanning for an item
4468 // ----------------------------------------------------------------------------
4470 void wxListMainWindow::EnsureVisible( long index
)
4472 wxCHECK_RET( index
>= 0 && (size_t)index
< GetItemCount(),
4473 _T("invalid index in EnsureVisible") );
4475 // We have to call this here because the label in question might just have
4476 // been added and its position is not known yet
4478 RecalculatePositions(true /* no refresh */);
4480 MoveToItem((size_t)index
);
4483 long wxListMainWindow::FindItem(long start
, const wxString
& str
, bool WXUNUSED(partial
) )
4490 size_t count
= GetItemCount();
4491 for ( size_t i
= (size_t)pos
; i
< count
; i
++ )
4493 wxListLineData
*line
= GetLine(i
);
4494 if ( line
->GetText(0) == tmp
)
4501 long wxListMainWindow::FindItem(long start
, wxUIntPtr data
)
4507 size_t count
= GetItemCount();
4508 for (size_t i
= (size_t)pos
; i
< count
; i
++)
4510 wxListLineData
*line
= GetLine(i
);
4512 line
->GetItem( 0, item
);
4513 if (item
.m_data
== data
)
4520 long wxListMainWindow::FindItem( const wxPoint
& pt
)
4523 GetVisibleLinesRange( &topItem
, NULL
);
4526 GetItemPosition( GetItemCount() - 1, p
);
4530 long id
= (long)floor( pt
.y
* double(GetItemCount() - topItem
- 1) / p
.y
+ topItem
);
4531 if ( id
>= 0 && id
< (long)GetItemCount() )
4537 long wxListMainWindow::HitTest( int x
, int y
, int &flags
) const
4539 CalcUnscrolledPosition( x
, y
, &x
, &y
);
4541 size_t count
= GetItemCount();
4543 if ( InReportView() )
4545 size_t current
= y
/ GetLineHeight();
4546 if ( current
< count
)
4548 flags
= HitTestLine(current
, x
, y
);
4555 // TODO: optimize it too! this is less simple than for report view but
4556 // enumerating all items is still not a way to do it!!
4557 for ( size_t current
= 0; current
< count
; current
++ )
4559 flags
= HitTestLine(current
, x
, y
);
4568 // ----------------------------------------------------------------------------
4570 // ----------------------------------------------------------------------------
4572 void wxListMainWindow::InsertItem( wxListItem
&item
)
4574 wxASSERT_MSG( !IsVirtual(), _T("can't be used with virtual control") );
4576 int count
= GetItemCount();
4577 wxCHECK_RET( item
.m_itemId
>= 0, _T("invalid item index") );
4579 if (item
.m_itemId
> count
)
4580 item
.m_itemId
= count
;
4582 size_t id
= item
.m_itemId
;
4586 if ( InReportView() )
4588 ResetVisibleLinesRange();
4590 // calculate the width of the item and adjust the max column width
4591 wxColWidthInfo
*pWidthInfo
= m_aColWidths
.Item(item
.GetColumn());
4592 int width
= GetItemWidthWithImage(&item
);
4593 item
.SetWidth(width
);
4594 if (width
> pWidthInfo
->nMaxWidth
)
4595 pWidthInfo
->nMaxWidth
= width
;
4598 wxListLineData
*line
= new wxListLineData(this);
4600 line
->SetItem( item
.m_col
, item
);
4602 m_lines
.Insert( line
, id
);
4606 // If an item is selected at or below the point of insertion, we need to
4607 // increment the member variables because the current row's index has gone
4609 if ( HasCurrent() && m_current
>= id
)
4612 SendNotify(id
, wxEVT_COMMAND_LIST_INSERT_ITEM
);
4614 RefreshLines(id
, GetItemCount() - 1);
4617 void wxListMainWindow::InsertColumn( long col
, wxListItem
&item
)
4620 if ( InReportView() )
4622 if (item
.m_width
== wxLIST_AUTOSIZE_USEHEADER
)
4623 item
.m_width
= GetTextLength( item
.m_text
);
4625 wxListHeaderData
*column
= new wxListHeaderData( item
);
4626 wxColWidthInfo
*colWidthInfo
= new wxColWidthInfo();
4628 bool insert
= (col
>= 0) && ((size_t)col
< m_columns
.GetCount());
4631 wxListHeaderDataList::compatibility_iterator
4632 node
= m_columns
.Item( col
);
4633 m_columns
.Insert( node
, column
);
4634 m_aColWidths
.Insert( colWidthInfo
, col
);
4638 m_columns
.Append( column
);
4639 m_aColWidths
.Add( colWidthInfo
);
4644 // update all the items
4645 for ( size_t i
= 0; i
< m_lines
.GetCount(); i
++ )
4647 wxListLineData
* const line
= GetLine(i
);
4648 wxListItemData
* const data
= new wxListItemData(this);
4650 line
->m_items
.Insert(col
, data
);
4652 line
->m_items
.Append(data
);
4656 // invalidate it as it has to be recalculated
4661 int wxListMainWindow::GetItemWidthWithImage(wxListItem
* item
)
4664 wxClientDC
dc(this);
4666 dc
.SetFont( GetFont() );
4668 if (item
->GetImage() != -1)
4671 GetImageSize( item
->GetImage(), ix
, iy
);
4675 if (!item
->GetText().empty())
4678 dc
.GetTextExtent( item
->GetText(), &w
, NULL
);
4685 // ----------------------------------------------------------------------------
4687 // ----------------------------------------------------------------------------
4689 wxListCtrlCompare list_ctrl_compare_func_2
;
4690 long list_ctrl_compare_data
;
4692 int LINKAGEMODE
list_ctrl_compare_func_1( wxListLineData
**arg1
, wxListLineData
**arg2
)
4694 wxListLineData
*line1
= *arg1
;
4695 wxListLineData
*line2
= *arg2
;
4697 line1
->GetItem( 0, item
);
4698 wxUIntPtr data1
= item
.m_data
;
4699 line2
->GetItem( 0, item
);
4700 wxUIntPtr data2
= item
.m_data
;
4701 return list_ctrl_compare_func_2( data1
, data2
, list_ctrl_compare_data
);
4704 void wxListMainWindow::SortItems( wxListCtrlCompare fn
, long data
)
4706 list_ctrl_compare_func_2
= fn
;
4707 list_ctrl_compare_data
= data
;
4708 m_lines
.Sort( list_ctrl_compare_func_1
);
4712 // ----------------------------------------------------------------------------
4714 // ----------------------------------------------------------------------------
4716 void wxListMainWindow::OnScroll(wxScrollWinEvent
& event
)
4718 // update our idea of which lines are shown when we redraw the window the
4720 ResetVisibleLinesRange();
4723 #if ( defined(__WXGTK__) || defined(__WXMAC__) ) && !defined(__WXUNIVERSAL__)
4724 wxScrolledWindow::OnScroll(event
);
4726 HandleOnScroll( event
);
4729 if ( event
.GetOrientation() == wxHORIZONTAL
&& HasHeader() )
4731 wxGenericListCtrl
* lc
= GetListCtrl();
4732 wxCHECK_RET( lc
, _T("no listctrl window?") );
4734 lc
->m_headerWin
->Refresh();
4735 lc
->m_headerWin
->Update();
4739 int wxListMainWindow::GetCountPerPage() const
4741 if ( !m_linesPerPage
)
4743 wxConstCast(this, wxListMainWindow
)->
4744 m_linesPerPage
= GetClientSize().y
/ GetLineHeight();
4747 return m_linesPerPage
;
4750 void wxListMainWindow::GetVisibleLinesRange(size_t *from
, size_t *to
)
4752 wxASSERT_MSG( InReportView(), _T("this is for report mode only") );
4754 if ( m_lineFrom
== (size_t)-1 )
4756 size_t count
= GetItemCount();
4759 m_lineFrom
= GetScrollPos(wxVERTICAL
);
4761 // this may happen if SetScrollbars() hadn't been called yet
4762 if ( m_lineFrom
>= count
)
4763 m_lineFrom
= count
- 1;
4765 // we redraw one extra line but this is needed to make the redrawing
4766 // logic work when there is a fractional number of lines on screen
4767 m_lineTo
= m_lineFrom
+ m_linesPerPage
;
4768 if ( m_lineTo
>= count
)
4769 m_lineTo
= count
- 1;
4771 else // empty control
4774 m_lineTo
= (size_t)-1;
4778 wxASSERT_MSG( IsEmpty() ||
4779 (m_lineFrom
<= m_lineTo
&& m_lineTo
< GetItemCount()),
4780 _T("GetVisibleLinesRange() returns incorrect result") );
4788 // -------------------------------------------------------------------------------------
4789 // wxGenericListCtrl
4790 // -------------------------------------------------------------------------------------
4792 IMPLEMENT_DYNAMIC_CLASS(wxGenericListCtrl
, wxControl
)
4794 BEGIN_EVENT_TABLE(wxGenericListCtrl
,wxControl
)
4795 EVT_SIZE(wxGenericListCtrl::OnSize
)
4798 wxGenericListCtrl::wxGenericListCtrl()
4800 m_imageListNormal
= (wxImageList
*) NULL
;
4801 m_imageListSmall
= (wxImageList
*) NULL
;
4802 m_imageListState
= (wxImageList
*) NULL
;
4804 m_ownsImageListNormal
=
4805 m_ownsImageListSmall
=
4806 m_ownsImageListState
= false;
4808 m_mainWin
= (wxListMainWindow
*) NULL
;
4809 m_headerWin
= (wxListHeaderWindow
*) NULL
;
4813 wxGenericListCtrl::~wxGenericListCtrl()
4815 if (m_ownsImageListNormal
)
4816 delete m_imageListNormal
;
4817 if (m_ownsImageListSmall
)
4818 delete m_imageListSmall
;
4819 if (m_ownsImageListState
)
4820 delete m_imageListState
;
4823 void wxGenericListCtrl::CalculateAndSetHeaderHeight()
4829 GetThemeMetric( kThemeMetricListHeaderHeight
, &h
);
4831 // we use 'g' to get the descent, too
4833 m_headerWin
->GetTextExtent(wxT("Hg"), &w
, &h
, &d
);
4834 h
+= d
+ 2 * HEADER_OFFSET_Y
+ EXTRA_HEIGHT
;
4837 // only update if changed
4838 if ( h
!= m_headerHeight
)
4843 ResizeReportView(true);
4844 else //why is this needed if it doesn't have a header?
4845 m_headerWin
->SetSize(m_headerWin
->GetSize().x
, m_headerHeight
);
4850 void wxGenericListCtrl::CreateHeaderWindow()
4852 m_headerWin
= new wxListHeaderWindow
4854 this, wxID_ANY
, m_mainWin
,
4856 wxSize(GetClientSize().x
, m_headerHeight
),
4859 CalculateAndSetHeaderHeight();
4862 bool wxGenericListCtrl::Create(wxWindow
*parent
,
4867 const wxValidator
&validator
,
4868 const wxString
&name
)
4872 m_imageListState
= (wxImageList
*) NULL
;
4873 m_ownsImageListNormal
=
4874 m_ownsImageListSmall
=
4875 m_ownsImageListState
= false;
4877 m_mainWin
= (wxListMainWindow
*) NULL
;
4878 m_headerWin
= (wxListHeaderWindow
*) NULL
;
4882 if ( !(style
& wxLC_MASK_TYPE
) )
4884 style
= style
| wxLC_LIST
;
4887 if ( !wxControl::Create( parent
, id
, pos
, size
, style
, validator
, name
) )
4890 // don't create the inner window with the border
4891 style
&= ~wxBORDER_MASK
;
4893 m_mainWin
= new wxListMainWindow( this, wxID_ANY
, wxPoint(0, 0), size
, style
);
4895 #ifdef __WXMAC_CARBON__
4896 // Human Interface Guidelines ask us for a special font in this case
4897 if ( GetWindowVariant() == wxWINDOW_VARIANT_NORMAL
)
4900 font
.MacCreateThemeFont( kThemeViewsFont
);
4905 if ( InReportView() )
4907 CreateHeaderWindow();
4909 #ifdef __WXMAC_CARBON__
4913 font
.MacCreateThemeFont( kThemeSmallSystemFont
);
4914 m_headerWin
->SetFont( font
);
4915 CalculateAndSetHeaderHeight();
4919 if ( HasFlag(wxLC_NO_HEADER
) )
4920 // VZ: why do we create it at all then?
4921 m_headerWin
->Show( false );
4924 SetInitialSize(size
);
4929 void wxGenericListCtrl::SetSingleStyle( long style
, bool add
)
4931 wxASSERT_MSG( !(style
& wxLC_VIRTUAL
),
4932 _T("wxLC_VIRTUAL can't be [un]set") );
4934 long flag
= GetWindowStyle();
4938 if (style
& wxLC_MASK_TYPE
)
4939 flag
&= ~(wxLC_MASK_TYPE
| wxLC_VIRTUAL
);
4940 if (style
& wxLC_MASK_ALIGN
)
4941 flag
&= ~wxLC_MASK_ALIGN
;
4942 if (style
& wxLC_MASK_SORT
)
4943 flag
&= ~wxLC_MASK_SORT
;
4951 SetWindowStyleFlag( flag
);
4954 void wxGenericListCtrl::SetWindowStyleFlag( long flag
)
4958 m_mainWin
->DeleteEverything();
4960 // has the header visibility changed?
4961 bool hasHeader
= HasHeader();
4962 bool willHaveHeader
= (flag
& wxLC_REPORT
) && !(flag
& wxLC_NO_HEADER
);
4964 if ( hasHeader
!= willHaveHeader
)
4971 // don't delete, just hide, as we can reuse it later
4972 m_headerWin
->Show(false);
4974 //else: nothing to do
4976 else // must show header
4980 CreateHeaderWindow();
4982 else // already have it, just show
4984 m_headerWin
->Show( true );
4988 ResizeReportView(willHaveHeader
);
4992 wxWindow::SetWindowStyleFlag( flag
);
4995 bool wxGenericListCtrl::GetColumn(int col
, wxListItem
&item
) const
4997 m_mainWin
->GetColumn( col
, item
);
5001 bool wxGenericListCtrl::SetColumn( int col
, wxListItem
& item
)
5003 m_mainWin
->SetColumn( col
, item
);
5007 int wxGenericListCtrl::GetColumnWidth( int col
) const
5009 return m_mainWin
->GetColumnWidth( col
);
5012 bool wxGenericListCtrl::SetColumnWidth( int col
, int width
)
5014 m_mainWin
->SetColumnWidth( col
, width
);
5018 int wxGenericListCtrl::GetCountPerPage() const
5020 return m_mainWin
->GetCountPerPage(); // different from Windows ?
5023 bool wxGenericListCtrl::GetItem( wxListItem
&info
) const
5025 m_mainWin
->GetItem( info
);
5029 bool wxGenericListCtrl::SetItem( wxListItem
&info
)
5031 m_mainWin
->SetItem( info
);
5035 long wxGenericListCtrl::SetItem( long index
, int col
, const wxString
& label
, int imageId
)
5038 info
.m_text
= label
;
5039 info
.m_mask
= wxLIST_MASK_TEXT
;
5040 info
.m_itemId
= index
;
5044 info
.m_image
= imageId
;
5045 info
.m_mask
|= wxLIST_MASK_IMAGE
;
5048 m_mainWin
->SetItem(info
);
5052 int wxGenericListCtrl::GetItemState( long item
, long stateMask
) const
5054 return m_mainWin
->GetItemState( item
, stateMask
);
5057 bool wxGenericListCtrl::SetItemState( long item
, long state
, long stateMask
)
5059 m_mainWin
->SetItemState( item
, state
, stateMask
);
5064 wxGenericListCtrl::SetItemImage( long item
, int image
, int WXUNUSED(selImage
) )
5066 return SetItemColumnImage(item
, 0, image
);
5070 wxGenericListCtrl::SetItemColumnImage( long item
, long column
, int image
)
5073 info
.m_image
= image
;
5074 info
.m_mask
= wxLIST_MASK_IMAGE
;
5075 info
.m_itemId
= item
;
5076 info
.m_col
= column
;
5077 m_mainWin
->SetItem( info
);
5081 wxString
wxGenericListCtrl::GetItemText( long item
) const
5083 return m_mainWin
->GetItemText(item
);
5086 void wxGenericListCtrl::SetItemText( long item
, const wxString
& str
)
5088 m_mainWin
->SetItemText(item
, str
);
5091 wxUIntPtr
wxGenericListCtrl::GetItemData( long item
) const
5094 info
.m_mask
= wxLIST_MASK_DATA
;
5095 info
.m_itemId
= item
;
5096 m_mainWin
->GetItem( info
);
5100 bool wxGenericListCtrl::SetItemData( long item
, long data
)
5103 info
.m_mask
= wxLIST_MASK_DATA
;
5104 info
.m_itemId
= item
;
5106 m_mainWin
->SetItem( info
);
5110 wxRect
wxGenericListCtrl::GetViewRect() const
5112 return m_mainWin
->GetViewRect();
5115 bool wxGenericListCtrl::GetItemRect( long item
, wxRect
&rect
, int WXUNUSED(code
) ) const
5117 m_mainWin
->GetItemRect( item
, rect
);
5118 if ( m_mainWin
->HasHeader() )
5119 rect
.y
+= m_headerHeight
+ 1;
5123 bool wxGenericListCtrl::GetItemPosition( long item
, wxPoint
& pos
) const
5125 m_mainWin
->GetItemPosition( item
, pos
);
5129 bool wxGenericListCtrl::SetItemPosition( long WXUNUSED(item
), const wxPoint
& WXUNUSED(pos
) )
5134 int wxGenericListCtrl::GetItemCount() const
5136 return m_mainWin
->GetItemCount();
5139 int wxGenericListCtrl::GetColumnCount() const
5141 return m_mainWin
->GetColumnCount();
5144 void wxGenericListCtrl::SetItemSpacing( int spacing
, bool isSmall
)
5146 m_mainWin
->SetItemSpacing( spacing
, isSmall
);
5149 wxSize
wxGenericListCtrl::GetItemSpacing() const
5151 const int spacing
= m_mainWin
->GetItemSpacing(HasFlag(wxLC_SMALL_ICON
));
5153 return wxSize(spacing
, spacing
);
5156 #if WXWIN_COMPATIBILITY_2_6
5157 int wxGenericListCtrl::GetItemSpacing( bool isSmall
) const
5159 return m_mainWin
->GetItemSpacing( isSmall
);
5161 #endif // WXWIN_COMPATIBILITY_2_6
5163 void wxGenericListCtrl::SetItemTextColour( long item
, const wxColour
&col
)
5166 info
.m_itemId
= item
;
5167 info
.SetTextColour( col
);
5168 m_mainWin
->SetItem( info
);
5171 wxColour
wxGenericListCtrl::GetItemTextColour( long item
) const
5174 info
.m_itemId
= item
;
5175 m_mainWin
->GetItem( info
);
5176 return info
.GetTextColour();
5179 void wxGenericListCtrl::SetItemBackgroundColour( long item
, const wxColour
&col
)
5182 info
.m_itemId
= item
;
5183 info
.SetBackgroundColour( col
);
5184 m_mainWin
->SetItem( info
);
5187 wxColour
wxGenericListCtrl::GetItemBackgroundColour( long item
) const
5190 info
.m_itemId
= item
;
5191 m_mainWin
->GetItem( info
);
5192 return info
.GetBackgroundColour();
5195 void wxGenericListCtrl::SetItemFont( long item
, const wxFont
&f
)
5198 info
.m_itemId
= item
;
5200 m_mainWin
->SetItem( info
);
5203 wxFont
wxGenericListCtrl::GetItemFont( long item
) const
5206 info
.m_itemId
= item
;
5207 m_mainWin
->GetItem( info
);
5208 return info
.GetFont();
5211 int wxGenericListCtrl::GetSelectedItemCount() const
5213 return m_mainWin
->GetSelectedItemCount();
5216 wxColour
wxGenericListCtrl::GetTextColour() const
5218 return GetForegroundColour();
5221 void wxGenericListCtrl::SetTextColour(const wxColour
& col
)
5223 SetForegroundColour(col
);
5226 long wxGenericListCtrl::GetTopItem() const
5229 m_mainWin
->GetVisibleLinesRange(&top
, NULL
);
5233 long wxGenericListCtrl::GetNextItem( long item
, int geom
, int state
) const
5235 return m_mainWin
->GetNextItem( item
, geom
, state
);
5238 wxImageList
*wxGenericListCtrl::GetImageList(int which
) const
5240 if (which
== wxIMAGE_LIST_NORMAL
)
5241 return m_imageListNormal
;
5242 else if (which
== wxIMAGE_LIST_SMALL
)
5243 return m_imageListSmall
;
5244 else if (which
== wxIMAGE_LIST_STATE
)
5245 return m_imageListState
;
5247 return (wxImageList
*) NULL
;
5250 void wxGenericListCtrl::SetImageList( wxImageList
*imageList
, int which
)
5252 if ( which
== wxIMAGE_LIST_NORMAL
)
5254 if (m_ownsImageListNormal
)
5255 delete m_imageListNormal
;
5256 m_imageListNormal
= imageList
;
5257 m_ownsImageListNormal
= false;
5259 else if ( which
== wxIMAGE_LIST_SMALL
)
5261 if (m_ownsImageListSmall
)
5262 delete m_imageListSmall
;
5263 m_imageListSmall
= imageList
;
5264 m_ownsImageListSmall
= false;
5266 else if ( which
== wxIMAGE_LIST_STATE
)
5268 if (m_ownsImageListState
)
5269 delete m_imageListState
;
5270 m_imageListState
= imageList
;
5271 m_ownsImageListState
= false;
5274 m_mainWin
->SetImageList( imageList
, which
);
5277 void wxGenericListCtrl::AssignImageList(wxImageList
*imageList
, int which
)
5279 SetImageList(imageList
, which
);
5280 if ( which
== wxIMAGE_LIST_NORMAL
)
5281 m_ownsImageListNormal
= true;
5282 else if ( which
== wxIMAGE_LIST_SMALL
)
5283 m_ownsImageListSmall
= true;
5284 else if ( which
== wxIMAGE_LIST_STATE
)
5285 m_ownsImageListState
= true;
5288 bool wxGenericListCtrl::Arrange( int WXUNUSED(flag
) )
5293 bool wxGenericListCtrl::DeleteItem( long item
)
5295 m_mainWin
->DeleteItem( item
);
5299 bool wxGenericListCtrl::DeleteAllItems()
5301 m_mainWin
->DeleteAllItems();
5305 bool wxGenericListCtrl::DeleteAllColumns()
5307 size_t count
= m_mainWin
->m_columns
.GetCount();
5308 for ( size_t n
= 0; n
< count
; n
++ )
5313 void wxGenericListCtrl::ClearAll()
5315 m_mainWin
->DeleteEverything();
5318 bool wxGenericListCtrl::DeleteColumn( int col
)
5320 m_mainWin
->DeleteColumn( col
);
5322 // if we don't have the header any longer, we need to relayout the window
5323 if ( !GetColumnCount() )
5324 ResizeReportView(false /* no header */);
5328 wxTextCtrl
*wxGenericListCtrl::EditLabel(long item
,
5329 wxClassInfo
* textControlClass
)
5331 return m_mainWin
->EditLabel( item
, textControlClass
);
5334 wxTextCtrl
*wxGenericListCtrl::GetEditControl() const
5336 return m_mainWin
->GetEditControl();
5339 bool wxGenericListCtrl::EnsureVisible( long item
)
5341 m_mainWin
->EnsureVisible( item
);
5345 long wxGenericListCtrl::FindItem( long start
, const wxString
& str
, bool partial
)
5347 return m_mainWin
->FindItem( start
, str
, partial
);
5350 long wxGenericListCtrl::FindItem( long start
, wxUIntPtr data
)
5352 return m_mainWin
->FindItem( start
, data
);
5355 long wxGenericListCtrl::FindItem( long WXUNUSED(start
), const wxPoint
& pt
,
5356 int WXUNUSED(direction
))
5358 return m_mainWin
->FindItem( pt
);
5361 // TODO: sub item hit testing
5362 long wxGenericListCtrl::HitTest(const wxPoint
& point
, int& flags
, long *) const
5364 return m_mainWin
->HitTest( (int)point
.x
, (int)point
.y
, flags
);
5367 long wxGenericListCtrl::InsertItem( wxListItem
& info
)
5369 m_mainWin
->InsertItem( info
);
5370 return info
.m_itemId
;
5373 long wxGenericListCtrl::InsertItem( long index
, const wxString
&label
)
5376 info
.m_text
= label
;
5377 info
.m_mask
= wxLIST_MASK_TEXT
;
5378 info
.m_itemId
= index
;
5379 return InsertItem( info
);
5382 long wxGenericListCtrl::InsertItem( long index
, int imageIndex
)
5385 info
.m_mask
= wxLIST_MASK_IMAGE
;
5386 info
.m_image
= imageIndex
;
5387 info
.m_itemId
= index
;
5388 return InsertItem( info
);
5391 long wxGenericListCtrl::InsertItem( long index
, const wxString
&label
, int imageIndex
)
5394 info
.m_text
= label
;
5395 info
.m_image
= imageIndex
;
5396 info
.m_mask
= wxLIST_MASK_TEXT
| wxLIST_MASK_IMAGE
;
5397 info
.m_itemId
= index
;
5398 return InsertItem( info
);
5401 long wxGenericListCtrl::InsertColumn( long col
, wxListItem
&item
)
5403 wxCHECK_MSG( m_headerWin
, -1, _T("can't add column in non report mode") );
5405 m_mainWin
->InsertColumn( col
, item
);
5407 // if we hadn't had a header before but have one now
5408 // then we need to relayout the window
5409 if ( GetColumnCount() == 1 && m_mainWin
->HasHeader() )
5410 ResizeReportView(true /* have header */);
5412 m_headerWin
->Refresh();
5417 long wxGenericListCtrl::InsertColumn( long col
, const wxString
&heading
,
5418 int format
, int width
)
5421 item
.m_mask
= wxLIST_MASK_TEXT
| wxLIST_MASK_FORMAT
;
5422 item
.m_text
= heading
;
5425 item
.m_mask
|= wxLIST_MASK_WIDTH
;
5426 item
.m_width
= width
;
5429 item
.m_format
= format
;
5431 return InsertColumn( col
, item
);
5434 bool wxGenericListCtrl::ScrollList( int WXUNUSED(dx
), int WXUNUSED(dy
) )
5440 // fn is a function which takes 3 long arguments: item1, item2, data.
5441 // item1 is the long data associated with a first item (NOT the index).
5442 // item2 is the long data associated with a second item (NOT the index).
5443 // data is the same value as passed to SortItems.
5444 // The return value is a negative number if the first item should precede the second
5445 // item, a positive number of the second item should precede the first,
5446 // or zero if the two items are equivalent.
5447 // data is arbitrary data to be passed to the sort function.
5449 bool wxGenericListCtrl::SortItems( wxListCtrlCompare fn
, long data
)
5451 m_mainWin
->SortItems( fn
, data
);
5455 // ----------------------------------------------------------------------------
5457 // ----------------------------------------------------------------------------
5459 void wxGenericListCtrl::OnSize(wxSizeEvent
& WXUNUSED(event
))
5464 ResizeReportView(m_mainWin
->HasHeader());
5465 m_mainWin
->RecalculatePositions();
5468 void wxGenericListCtrl::ResizeReportView(bool showHeader
)
5471 GetClientSize( &cw
, &ch
);
5475 m_headerWin
->SetSize( 0, 0, cw
, m_headerHeight
);
5476 if(ch
> m_headerHeight
)
5477 m_mainWin
->SetSize( 0, m_headerHeight
+ 1,
5478 cw
, ch
- m_headerHeight
- 1 );
5480 m_mainWin
->SetSize( 0, m_headerHeight
+ 1,
5483 else // no header window
5485 m_mainWin
->SetSize( 0, 0, cw
, ch
);
5489 void wxGenericListCtrl::OnInternalIdle()
5491 wxWindow::OnInternalIdle();
5493 // do it only if needed
5494 if ( !m_mainWin
->m_dirty
)
5497 m_mainWin
->RecalculatePositions();
5500 // ----------------------------------------------------------------------------
5502 // ----------------------------------------------------------------------------
5504 bool wxGenericListCtrl::SetBackgroundColour( const wxColour
&colour
)
5508 m_mainWin
->SetBackgroundColour( colour
);
5509 m_mainWin
->m_dirty
= true;
5515 bool wxGenericListCtrl::SetForegroundColour( const wxColour
&colour
)
5517 if ( !wxWindow::SetForegroundColour( colour
) )
5522 m_mainWin
->SetForegroundColour( colour
);
5523 m_mainWin
->m_dirty
= true;
5527 m_headerWin
->SetForegroundColour( colour
);
5532 bool wxGenericListCtrl::SetFont( const wxFont
&font
)
5534 if ( !wxWindow::SetFont( font
) )
5539 m_mainWin
->SetFont( font
);
5540 m_mainWin
->m_dirty
= true;
5545 m_headerWin
->SetFont( font
);
5546 CalculateAndSetHeaderHeight();
5556 wxGenericListCtrl::GetClassDefaultAttributes(wxWindowVariant variant
)
5559 // Use the same color scheme as wxListBox
5560 return wxListBox::GetClassDefaultAttributes(variant
);
5562 wxUnusedVar(variant
);
5563 wxVisualAttributes attr
;
5564 attr
.colFg
= wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT
);
5565 attr
.colBg
= wxSystemSettings::GetColour(wxSYS_COLOUR_LISTBOX
);
5566 attr
.font
= wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT
);
5571 // ----------------------------------------------------------------------------
5572 // methods forwarded to m_mainWin
5573 // ----------------------------------------------------------------------------
5575 #if wxUSE_DRAG_AND_DROP
5577 void wxGenericListCtrl::SetDropTarget( wxDropTarget
*dropTarget
)
5579 m_mainWin
->SetDropTarget( dropTarget
);
5582 wxDropTarget
*wxGenericListCtrl::GetDropTarget() const
5584 return m_mainWin
->GetDropTarget();
5589 bool wxGenericListCtrl::SetCursor( const wxCursor
&cursor
)
5591 return m_mainWin
? m_mainWin
->wxWindow::SetCursor(cursor
) : false;
5594 wxColour
wxGenericListCtrl::GetBackgroundColour() const
5596 return m_mainWin
? m_mainWin
->GetBackgroundColour() : wxColour();
5599 wxColour
wxGenericListCtrl::GetForegroundColour() const
5601 return m_mainWin
? m_mainWin
->GetForegroundColour() : wxColour();
5604 bool wxGenericListCtrl::DoPopupMenu( wxMenu
*menu
, int x
, int y
)
5607 return m_mainWin
->PopupMenu( menu
, x
, y
);
5613 void wxGenericListCtrl::DoClientToScreen( int *x
, int *y
) const
5615 m_mainWin
->DoClientToScreen(x
, y
);
5618 void wxGenericListCtrl::DoScreenToClient( int *x
, int *y
) const
5620 m_mainWin
->DoScreenToClient(x
, y
);
5623 void wxGenericListCtrl::SetFocus()
5625 // The test in window.cpp fails as we are a composite
5626 // window, so it checks against "this", but not m_mainWin.
5627 if ( DoFindFocus() != this )
5628 m_mainWin
->SetFocus();
5631 wxSize
wxGenericListCtrl::DoGetBestSize() const
5633 // Something is better than nothing...
5634 // 100x80 is what the MSW version will get from the default
5635 // wxControl::DoGetBestSize
5636 return wxSize(100, 80);
5639 // ----------------------------------------------------------------------------
5640 // virtual list control support
5641 // ----------------------------------------------------------------------------
5643 wxString
wxGenericListCtrl::OnGetItemText(long WXUNUSED(item
), long WXUNUSED(col
)) const
5645 // this is a pure virtual function, in fact - which is not really pure
5646 // because the controls which are not virtual don't need to implement it
5647 wxFAIL_MSG( _T("wxGenericListCtrl::OnGetItemText not supposed to be called") );
5649 return wxEmptyString
;
5652 int wxGenericListCtrl::OnGetItemImage(long WXUNUSED(item
)) const
5654 wxCHECK_MSG(!GetImageList(wxIMAGE_LIST_SMALL
),
5656 wxT("List control has an image list, OnGetItemImage or OnGetItemColumnImage should be overridden."));
5660 int wxGenericListCtrl::OnGetItemColumnImage(long item
, long column
) const
5663 return OnGetItemImage(item
);
5669 wxGenericListCtrl::OnGetItemAttr(long WXUNUSED_UNLESS_DEBUG(item
)) const
5671 wxASSERT_MSG( item
>= 0 && item
< GetItemCount(),
5672 _T("invalid item index in OnGetItemAttr()") );
5674 // no attributes by default
5678 void wxGenericListCtrl::SetItemCount(long count
)
5680 wxASSERT_MSG( IsVirtual(), _T("this is for virtual controls only") );
5682 m_mainWin
->SetItemCount(count
);
5685 void wxGenericListCtrl::RefreshItem(long item
)
5687 m_mainWin
->RefreshLine(item
);
5690 void wxGenericListCtrl::RefreshItems(long itemFrom
, long itemTo
)
5692 m_mainWin
->RefreshLines(itemFrom
, itemTo
);
5695 // Generic wxListCtrl is more or less a container for two other
5696 // windows which drawings are done upon. These are namely
5697 // 'm_headerWin' and 'm_mainWin'.
5698 // Here we override 'virtual wxWindow::Refresh()' to mimic the
5699 // behaviour wxListCtrl has under wxMSW.
5701 void wxGenericListCtrl::Refresh(bool eraseBackground
, const wxRect
*rect
)
5705 // The easy case, no rectangle specified.
5707 m_headerWin
->Refresh(eraseBackground
);
5710 m_mainWin
->Refresh(eraseBackground
);
5714 // Refresh the header window
5717 wxRect rectHeader
= m_headerWin
->GetRect();
5718 rectHeader
.Intersect(*rect
);
5719 if (rectHeader
.GetWidth() && rectHeader
.GetHeight())
5722 m_headerWin
->GetPosition(&x
, &y
);
5723 rectHeader
.Offset(-x
, -y
);
5724 m_headerWin
->Refresh(eraseBackground
, &rectHeader
);
5728 // Refresh the main window
5731 wxRect rectMain
= m_mainWin
->GetRect();
5732 rectMain
.Intersect(*rect
);
5733 if (rectMain
.GetWidth() && rectMain
.GetHeight())
5736 m_mainWin
->GetPosition(&x
, &y
);
5737 rectMain
.Offset(-x
, -y
);
5738 m_mainWin
->Refresh(eraseBackground
, &rectMain
);
5744 void wxGenericListCtrl::Freeze()
5746 m_mainWin
->Freeze();
5749 void wxGenericListCtrl::Thaw()
5754 #endif // wxUSE_LISTCTRL