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(__WXMAC__) && wxOSX_USE_CARBON)) || defined(__WXUNIVERSAL__))
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"
45 #include "wx/settings.h"
49 #include "wx/imaglist.h"
50 #include "wx/selstore.h"
51 #include "wx/renderer.h"
54 #include "wx/osx/private.h"
55 // for themeing support
56 #include <Carbon/Carbon.h>
60 // NOTE: If using the wxListBox visual attributes works everywhere then this can
61 // be removed, as well as the #else case below.
62 #define _USE_VISATTR 0
65 // ----------------------------------------------------------------------------
67 // ----------------------------------------------------------------------------
69 // // the height of the header window (FIXME: should depend on its font!)
70 // static const int HEADER_HEIGHT = 23;
72 static const int SCROLL_UNIT_X
= 15;
74 // the spacing between the lines (in report mode)
75 static const int LINE_SPACING
= 0;
77 // extra margins around the text label
79 static const int EXTRA_WIDTH
= 6;
81 static const int EXTRA_WIDTH
= 4;
85 static const int EXTRA_HEIGHT
= 6;
87 static const int EXTRA_HEIGHT
= 4;
90 // margin between the window and the items
91 static const int EXTRA_BORDER_X
= 2;
92 static const int EXTRA_BORDER_Y
= 2;
94 // offset for the header window
95 static const int HEADER_OFFSET_X
= 0;
96 static const int HEADER_OFFSET_Y
= 0;
98 // margin between rows of icons in [small] icon view
99 static const int MARGIN_BETWEEN_ROWS
= 6;
101 // when autosizing the columns, add some slack
102 static const int AUTOSIZE_COL_MARGIN
= 10;
104 // default width for the header columns
105 static const int WIDTH_COL_DEFAULT
= 80;
107 // the space between the image and the text in the report mode
108 static const int IMAGE_MARGIN_IN_REPORT_MODE
= 5;
110 // the space between the image and the text in the report mode in header
111 static const int HEADER_IMAGE_MARGIN_IN_REPORT_MODE
= 2;
113 // ============================================================================
115 // ============================================================================
117 //-----------------------------------------------------------------------------
118 // wxColWidthInfo (internal)
119 //-----------------------------------------------------------------------------
121 struct wxColWidthInfo
124 bool bNeedsUpdate
; // only set to true when an item whose
125 // width == nMaxWidth is removed
127 wxColWidthInfo(int w
= 0, bool needsUpdate
= false)
130 bNeedsUpdate
= needsUpdate
;
134 WX_DEFINE_ARRAY_PTR(wxColWidthInfo
*, ColWidthArray
);
136 //-----------------------------------------------------------------------------
137 // wxListItemData (internal)
138 //-----------------------------------------------------------------------------
143 wxListItemData(wxListMainWindow
*owner
);
146 void SetItem( const wxListItem
&info
);
147 void SetImage( int image
) { m_image
= image
; }
148 void SetData( wxUIntPtr data
) { m_data
= data
; }
149 void SetPosition( int x
, int y
);
150 void SetSize( int width
, int height
);
152 bool HasText() const { return !m_text
.empty(); }
153 const wxString
& GetText() const { return m_text
; }
154 void SetText(const wxString
& text
) { m_text
= text
; }
156 // we can't use empty string for measuring the string width/height, so
157 // always return something
158 wxString
GetTextForMeasuring() const
160 wxString s
= GetText();
167 bool IsHit( int x
, int y
) const;
171 int GetWidth() const;
172 int GetHeight() const;
174 int GetImage() const { return m_image
; }
175 bool HasImage() const { return GetImage() != -1; }
177 void GetItem( wxListItem
&info
) const;
179 void SetAttr(wxListItemAttr
*attr
) { m_attr
= attr
; }
180 wxListItemAttr
*GetAttr() const { return m_attr
; }
183 // the item image or -1
186 // user data associated with the item
189 // the item coordinates are not used in report mode; instead this pointer is
190 // NULL and the owner window is used to retrieve the item position and size
193 // the list ctrl we are in
194 wxListMainWindow
*m_owner
;
196 // custom attributes or NULL
197 wxListItemAttr
*m_attr
;
200 // common part of all ctors
206 //-----------------------------------------------------------------------------
207 // wxListHeaderData (internal)
208 //-----------------------------------------------------------------------------
210 class wxListHeaderData
: public wxObject
214 wxListHeaderData( const wxListItem
&info
);
215 void SetItem( const wxListItem
&item
);
216 void SetPosition( int x
, int y
);
217 void SetWidth( int w
);
218 void SetState( int state
);
219 void SetFormat( int format
);
220 void SetHeight( int h
);
221 bool HasImage() const;
223 bool HasText() const { return !m_text
.empty(); }
224 const wxString
& GetText() const { return m_text
; }
225 void SetText(const wxString
& text
) { m_text
= text
; }
227 void GetItem( wxListItem
&item
);
229 bool IsHit( int x
, int y
) const;
230 int GetImage() const;
231 int GetWidth() const;
232 int GetFormat() const;
233 int GetState() const;
250 //-----------------------------------------------------------------------------
251 // wxListLineData (internal)
252 //-----------------------------------------------------------------------------
254 WX_DECLARE_LIST(wxListItemData
, wxListItemDataList
);
255 #include "wx/listimpl.cpp"
256 WX_DEFINE_LIST(wxListItemDataList
)
261 // the list of subitems: only may have more than one item in report mode
262 wxListItemDataList m_items
;
264 // this is not used in report view
276 // the part to be highlighted
277 wxRect m_rectHighlight
;
279 // extend all our rects to be centered inside the one of given width
280 void ExtendWidth(wxCoord w
)
282 wxASSERT_MSG( m_rectAll
.width
<= w
,
283 _T("width can only be increased") );
286 m_rectLabel
.x
= m_rectAll
.x
+ (w
- m_rectLabel
.width
) / 2;
287 m_rectIcon
.x
= m_rectAll
.x
+ (w
- m_rectIcon
.width
) / 2;
288 m_rectHighlight
.x
= m_rectAll
.x
+ (w
- m_rectHighlight
.width
) / 2;
293 // is this item selected? [NB: not used in virtual mode]
296 // back pointer to the list ctrl
297 wxListMainWindow
*m_owner
;
300 wxListLineData(wxListMainWindow
*owner
);
304 WX_CLEAR_LIST(wxListItemDataList
, m_items
);
308 // are we in report mode?
309 inline bool InReportView() const;
311 // are we in virtual report mode?
312 inline bool IsVirtual() const;
314 // these 2 methods shouldn't be called for report view controls, in that
315 // case we determine our position/size ourselves
317 // calculate the size of the line
318 void CalculateSize( wxDC
*dc
, int spacing
);
320 // remember the position this line appears at
321 void SetPosition( int x
, int y
, int spacing
);
325 void SetImage( int image
) { SetImage(0, image
); }
326 int GetImage() const { return GetImage(0); }
327 void SetImage( int index
, int image
);
328 int GetImage( int index
) const;
330 bool HasImage() const { return GetImage() != -1; }
331 bool HasText() const { return !GetText(0).empty(); }
333 void SetItem( int index
, const wxListItem
&info
);
334 void GetItem( int index
, wxListItem
&info
);
336 wxString
GetText(int index
) const;
337 void SetText( int index
, const wxString
& s
);
339 wxListItemAttr
*GetAttr() const;
340 void SetAttr(wxListItemAttr
*attr
);
342 // return true if the highlighting really changed
343 bool Highlight( bool on
);
345 void ReverseHighlight();
347 bool IsHighlighted() const
349 wxASSERT_MSG( !IsVirtual(), _T("unexpected call to IsHighlighted") );
351 return m_highlighted
;
354 // draw the line on the given DC in icon/list mode
355 void Draw( wxDC
*dc
);
357 // the same in report mode
358 void DrawInReportMode( wxDC
*dc
,
360 const wxRect
& rectHL
,
365 // set the line to contain num items (only can be > 1 in report mode)
366 void InitItems( int num
);
368 // get the mode (i.e. style) of the list control
369 inline int GetMode() const;
371 // prepare the DC for drawing with these item's attributes, return true if
372 // we need to draw the items background to highlight it, false otherwise
373 bool SetAttributes(wxDC
*dc
,
374 const wxListItemAttr
*attr
,
377 // draw the text on the DC with the correct justification; also add an
378 // ellipsis if the text is too large to fit in the current width
379 void DrawTextFormatted(wxDC
*dc
,
380 const wxString
&text
,
383 int yMid
, // this is middle, not top, of the text
387 WX_DECLARE_OBJARRAY(wxListLineData
, wxListLineDataArray
);
388 #include "wx/arrimpl.cpp"
389 WX_DEFINE_OBJARRAY(wxListLineDataArray
)
391 //-----------------------------------------------------------------------------
392 // wxListHeaderWindow (internal)
393 //-----------------------------------------------------------------------------
395 class wxListHeaderWindow
: public wxWindow
398 wxListMainWindow
*m_owner
;
399 const wxCursor
*m_currentCursor
;
400 wxCursor
*m_resizeCursor
;
403 // column being resized or -1
406 // divider line position in logical (unscrolled) coords
409 // minimal position beyond which the divider line
410 // can't be dragged in logical coords
414 wxListHeaderWindow();
416 wxListHeaderWindow( wxWindow
*win
,
418 wxListMainWindow
*owner
,
419 const wxPoint
&pos
= wxDefaultPosition
,
420 const wxSize
&size
= wxDefaultSize
,
422 const wxString
&name
= wxT("wxlistctrlcolumntitles") );
424 virtual ~wxListHeaderWindow();
427 void AdjustDC( wxDC
& dc
);
429 void OnPaint( wxPaintEvent
&event
);
430 void OnMouse( wxMouseEvent
&event
);
431 void OnSetFocus( wxFocusEvent
&event
);
436 // Update main window's column later
437 bool m_sendSetColumnWidth
;
441 virtual void OnInternalIdle();
444 // common part of all ctors
447 // generate and process the list event of the given type, return true if
448 // it wasn't vetoed, i.e. if we should proceed
449 bool SendListEvent(wxEventType type
, const wxPoint
& pos
);
451 DECLARE_EVENT_TABLE()
454 //-----------------------------------------------------------------------------
455 // wxListRenameTimer (internal)
456 //-----------------------------------------------------------------------------
458 class wxListRenameTimer
: public wxTimer
461 wxListMainWindow
*m_owner
;
464 wxListRenameTimer( wxListMainWindow
*owner
);
468 //-----------------------------------------------------------------------------
469 // wxListTextCtrlWrapper: wraps a wxTextCtrl to make it work for inline editing
470 //-----------------------------------------------------------------------------
472 class wxListTextCtrlWrapper
: public wxEvtHandler
475 // NB: text must be a valid object but not Create()d yet
476 wxListTextCtrlWrapper(wxListMainWindow
*owner
,
480 wxTextCtrl
*GetText() const { return m_text
; }
482 void EndEdit( bool discardChanges
);
485 void OnChar( wxKeyEvent
&event
);
486 void OnKeyUp( wxKeyEvent
&event
);
487 void OnKillFocus( wxFocusEvent
&event
);
489 bool AcceptChanges();
490 void Finish( bool setfocus
);
493 wxListMainWindow
*m_owner
;
495 wxString m_startValue
;
497 bool m_aboutToFinish
;
499 DECLARE_EVENT_TABLE()
502 //-----------------------------------------------------------------------------
503 // wxListMainWindow (internal)
504 //-----------------------------------------------------------------------------
506 WX_DECLARE_LIST(wxListHeaderData
, wxListHeaderDataList
);
507 #include "wx/listimpl.cpp"
508 WX_DEFINE_LIST(wxListHeaderDataList
)
510 class wxListMainWindow
: public wxWindow
514 wxListMainWindow( wxWindow
*parent
,
516 const wxPoint
& pos
= wxDefaultPosition
,
517 const wxSize
& size
= wxDefaultSize
,
519 const wxString
&name
= _T("listctrlmainwindow") );
521 virtual ~wxListMainWindow();
523 bool HasFlag(int flag
) const { return m_parent
->HasFlag(flag
); }
525 // return true if this is a virtual list control
526 bool IsVirtual() const { return HasFlag(wxLC_VIRTUAL
); }
528 // return true if the control is in report mode
529 bool InReportView() const { return HasFlag(wxLC_REPORT
); }
531 // return true if we are in single selection mode, false if multi sel
532 bool IsSingleSel() const { return HasFlag(wxLC_SINGLE_SEL
); }
534 // do we have a header window?
535 bool HasHeader() const
536 { return InReportView() && !HasFlag(wxLC_NO_HEADER
); }
538 void HighlightAll( bool on
);
540 // all these functions only do something if the line is currently visible
542 // change the line "selected" state, return true if it really changed
543 bool HighlightLine( size_t line
, bool highlight
= true);
545 // as HighlightLine() but do it for the range of lines: this is incredibly
546 // more efficient for virtual list controls!
548 // NB: unlike HighlightLine() this one does refresh the lines on screen
549 void HighlightLines( size_t lineFrom
, size_t lineTo
, bool on
= true );
551 // toggle the line state and refresh it
552 void ReverseHighlight( size_t line
)
553 { HighlightLine(line
, !IsHighlighted(line
)); RefreshLine(line
); }
555 // return true if the line is highlighted
556 bool IsHighlighted(size_t line
) const;
558 // refresh one or several lines at once
559 void RefreshLine( size_t line
);
560 void RefreshLines( size_t lineFrom
, size_t lineTo
);
562 // refresh all selected items
563 void RefreshSelected();
565 // refresh all lines below the given one: the difference with
566 // RefreshLines() is that the index here might not be a valid one (happens
567 // when the last line is deleted)
568 void RefreshAfter( size_t lineFrom
);
570 // the methods which are forwarded to wxListLineData itself in list/icon
571 // modes but are here because the lines don't store their positions in the
574 // get the bound rect for the entire line
575 wxRect
GetLineRect(size_t line
) const;
577 // get the bound rect of the label
578 wxRect
GetLineLabelRect(size_t line
) const;
580 // get the bound rect of the items icon (only may be called if we do have
582 wxRect
GetLineIconRect(size_t line
) const;
584 // get the rect to be highlighted when the item has focus
585 wxRect
GetLineHighlightRect(size_t line
) const;
587 // get the size of the total line rect
588 wxSize
GetLineSize(size_t line
) const
589 { return GetLineRect(line
).GetSize(); }
591 // return the hit code for the corresponding position (in this line)
592 long HitTestLine(size_t line
, int x
, int y
) const;
594 // bring the selected item into view, scrolling to it if necessary
595 void MoveToItem(size_t item
);
597 bool ScrollList( int WXUNUSED(dx
), int dy
);
599 // bring the current item into view
600 void MoveToFocus() { MoveToItem(m_current
); }
602 // start editing the label of the given item
603 wxTextCtrl
*EditLabel(long item
,
604 wxClassInfo
* textControlClass
= CLASSINFO(wxTextCtrl
));
605 wxTextCtrl
*GetEditControl() const
607 return m_textctrlWrapper
? m_textctrlWrapper
->GetText() : NULL
;
610 void ResetTextControl(wxTextCtrl
*text
)
613 m_textctrlWrapper
= NULL
;
616 void OnRenameTimer();
617 bool OnRenameAccept(size_t itemEdit
, const wxString
& value
);
618 void OnRenameCancelled(size_t itemEdit
);
620 void OnMouse( wxMouseEvent
&event
);
622 // called to switch the selection from the current item to newCurrent,
623 void OnArrowChar( size_t newCurrent
, const wxKeyEvent
& event
);
625 void OnChar( wxKeyEvent
&event
);
626 void OnKeyDown( wxKeyEvent
&event
);
627 void OnKeyUp( wxKeyEvent
&event
);
628 void OnSetFocus( wxFocusEvent
&event
);
629 void OnKillFocus( wxFocusEvent
&event
);
630 void OnScroll( wxScrollWinEvent
& event
);
632 void OnPaint( wxPaintEvent
&event
);
634 void OnChildFocus(wxChildFocusEvent
& event
);
636 void DrawImage( int index
, wxDC
*dc
, int x
, int y
);
637 void GetImageSize( int index
, int &width
, int &height
) const;
638 int GetTextLength( const wxString
&s
) const;
640 void SetImageList( wxImageList
*imageList
, int which
);
641 void SetItemSpacing( int spacing
, bool isSmall
= false );
642 int GetItemSpacing( bool isSmall
= false );
644 void SetColumn( int col
, wxListItem
&item
);
645 void SetColumnWidth( int col
, int width
);
646 void GetColumn( int col
, wxListItem
&item
) const;
647 int GetColumnWidth( int col
) const;
648 int GetColumnCount() const { return m_columns
.GetCount(); }
650 // returns the sum of the heights of all columns
651 int GetHeaderWidth() const;
653 int GetCountPerPage() const;
655 void SetItem( wxListItem
&item
);
656 void GetItem( wxListItem
&item
) const;
657 void SetItemState( long item
, long state
, long stateMask
);
658 void SetItemStateAll( long state
, long stateMask
);
659 int GetItemState( long item
, long stateMask
) const;
660 bool GetItemRect( long item
, wxRect
&rect
) const
662 return GetSubItemRect(item
, wxLIST_GETSUBITEMRECT_WHOLEITEM
, rect
);
664 bool GetSubItemRect( long item
, long subItem
, wxRect
& rect
) const;
665 wxRect
GetViewRect() const;
666 bool GetItemPosition( long item
, wxPoint
& pos
) const;
667 int GetSelectedItemCount() const;
669 wxString
GetItemText(long item
) const
672 info
.m_mask
= wxLIST_MASK_TEXT
;
673 info
.m_itemId
= item
;
678 void SetItemText(long item
, const wxString
& value
)
681 info
.m_mask
= wxLIST_MASK_TEXT
;
682 info
.m_itemId
= item
;
687 // set the scrollbars and update the positions of the items
688 void RecalculatePositions(bool noRefresh
= false);
690 // refresh the window and the header
693 long GetNextItem( long item
, int geometry
, int state
) const;
694 void DeleteItem( long index
);
695 void DeleteAllItems();
696 void DeleteColumn( int col
);
697 void DeleteEverything();
698 void EnsureVisible( long index
);
699 long FindItem( long start
, const wxString
& str
, bool partial
= false );
700 long FindItem( long start
, wxUIntPtr data
);
701 long FindItem( const wxPoint
& pt
);
702 long HitTest( int x
, int y
, int &flags
) const;
703 void InsertItem( wxListItem
&item
);
704 void InsertColumn( long col
, wxListItem
&item
);
705 int GetItemWidthWithImage(wxListItem
* item
);
706 void SortItems( wxListCtrlCompare fn
, long data
);
708 size_t GetItemCount() const;
709 bool IsEmpty() const { return GetItemCount() == 0; }
710 void SetItemCount(long count
);
712 // change the current (== focused) item, send a notification event
713 void ChangeCurrent(size_t current
);
714 void ResetCurrent() { ChangeCurrent((size_t)-1); }
715 bool HasCurrent() const { return m_current
!= (size_t)-1; }
717 // send out a wxListEvent
718 void SendNotify( size_t line
,
720 const wxPoint
& point
= wxDefaultPosition
);
722 // override base class virtual to reset m_lineHeight when the font changes
723 virtual bool SetFont(const wxFont
& font
)
725 if ( !wxWindow::SetFont(font
) )
733 // these are for wxListLineData usage only
735 // get the backpointer to the list ctrl
736 wxGenericListCtrl
*GetListCtrl() const
738 return wxStaticCast(GetParent(), wxGenericListCtrl
);
741 // get the height of all lines (assuming they all do have the same height)
742 wxCoord
GetLineHeight() const;
744 // get the y position of the given line (only for report view)
745 wxCoord
GetLineY(size_t line
) const;
747 // get the brush to use for the item highlighting
748 wxBrush
*GetHighlightBrush() const
750 return m_hasFocus
? m_highlightBrush
: m_highlightUnfocusedBrush
;
753 bool HasFocus() const
759 // the array of all line objects for a non virtual list control (for the
760 // virtual list control we only ever use m_lines[0])
761 wxListLineDataArray m_lines
;
763 // the list of column objects
764 wxListHeaderDataList m_columns
;
766 // currently focused item or -1
769 // the number of lines per page
772 // this flag is set when something which should result in the window
773 // redrawing happens (i.e. an item was added or deleted, or its appearance
774 // changed) and OnPaint() doesn't redraw the window while it is set which
775 // allows to minimize the number of repaintings when a lot of items are
776 // being added. The real repainting occurs only after the next OnIdle()
780 wxColour
*m_highlightColour
;
781 wxImageList
*m_small_image_list
;
782 wxImageList
*m_normal_image_list
;
784 int m_normal_spacing
;
788 wxTimer
*m_renameTimer
;
792 ColWidthArray m_aColWidths
;
794 // for double click logic
795 size_t m_lineLastClicked
,
796 m_lineBeforeLastClicked
,
797 m_lineSelectSingleOnUp
;
800 wxWindow
*GetMainWindowOfCompositeControl() { return GetParent(); }
802 // the total count of items in a virtual list control
805 // the object maintaining the items selection state, only used in virtual
807 wxSelectionStore m_selStore
;
809 // common part of all ctors
812 // get the line data for the given index
813 wxListLineData
*GetLine(size_t n
) const
815 wxASSERT_MSG( n
!= (size_t)-1, _T("invalid line index") );
819 wxConstCast(this, wxListMainWindow
)->CacheLineData(n
);
826 // get a dummy line which can be used for geometry calculations and such:
827 // you must use GetLine() if you want to really draw the line
828 wxListLineData
*GetDummyLine() const;
830 // cache the line data of the n-th line in m_lines[0]
831 void CacheLineData(size_t line
);
833 // get the range of visible lines
834 void GetVisibleLinesRange(size_t *from
, size_t *to
);
836 // force us to recalculate the range of visible lines
837 void ResetVisibleLinesRange() { m_lineFrom
= (size_t)-1; }
839 // get the colour to be used for drawing the rules
840 wxColour
GetRuleColour() const
842 return wxSystemSettings::GetColour(wxSYS_COLOUR_3DLIGHT
);
846 // initialize the current item if needed
847 void UpdateCurrent();
849 // delete all items but don't refresh: called from dtor
850 void DoDeleteAllItems();
852 // the height of one line using the current font
853 wxCoord m_lineHeight
;
855 // the total header width or 0 if not calculated yet
856 wxCoord m_headerWidth
;
858 // the first and last lines being shown on screen right now (inclusive),
859 // both may be -1 if they must be calculated so never access them directly:
860 // use GetVisibleLinesRange() above instead
864 // the brushes to use for item highlighting when we do/don't have focus
865 wxBrush
*m_highlightBrush
,
866 *m_highlightUnfocusedBrush
;
868 // wrapper around the text control currently used for in place editing or
869 // NULL if no item is being edited
870 wxListTextCtrlWrapper
*m_textctrlWrapper
;
873 DECLARE_EVENT_TABLE()
875 friend class wxGenericListCtrl
;
879 wxListItemData::~wxListItemData()
881 // in the virtual list control the attributes are managed by the main
882 // program, so don't delete them
883 if ( !m_owner
->IsVirtual() )
889 void wxListItemData::Init()
897 wxListItemData::wxListItemData(wxListMainWindow
*owner
)
903 if ( owner
->InReportView() )
909 void wxListItemData::SetItem( const wxListItem
&info
)
911 if ( info
.m_mask
& wxLIST_MASK_TEXT
)
912 SetText(info
.m_text
);
913 if ( info
.m_mask
& wxLIST_MASK_IMAGE
)
914 m_image
= info
.m_image
;
915 if ( info
.m_mask
& wxLIST_MASK_DATA
)
916 m_data
= info
.m_data
;
918 if ( info
.HasAttributes() )
921 m_attr
->AssignFrom(*info
.GetAttributes());
923 m_attr
= new wxListItemAttr(*info
.GetAttributes());
931 m_rect
->width
= info
.m_width
;
935 void wxListItemData::SetPosition( int x
, int y
)
937 wxCHECK_RET( m_rect
, _T("unexpected SetPosition() call") );
943 void wxListItemData::SetSize( int width
, int height
)
945 wxCHECK_RET( m_rect
, _T("unexpected SetSize() call") );
948 m_rect
->width
= width
;
950 m_rect
->height
= height
;
953 bool wxListItemData::IsHit( int x
, int y
) const
955 wxCHECK_MSG( m_rect
, false, _T("can't be called in this mode") );
957 return wxRect(GetX(), GetY(), GetWidth(), GetHeight()).Contains(x
, y
);
960 int wxListItemData::GetX() const
962 wxCHECK_MSG( m_rect
, 0, _T("can't be called in this mode") );
967 int wxListItemData::GetY() const
969 wxCHECK_MSG( m_rect
, 0, _T("can't be called in this mode") );
974 int wxListItemData::GetWidth() const
976 wxCHECK_MSG( m_rect
, 0, _T("can't be called in this mode") );
978 return m_rect
->width
;
981 int wxListItemData::GetHeight() const
983 wxCHECK_MSG( m_rect
, 0, _T("can't be called in this mode") );
985 return m_rect
->height
;
988 void wxListItemData::GetItem( wxListItem
&info
) const
990 long mask
= info
.m_mask
;
992 // by default, get everything for backwards compatibility
995 if ( mask
& wxLIST_MASK_TEXT
)
996 info
.m_text
= m_text
;
997 if ( mask
& wxLIST_MASK_IMAGE
)
998 info
.m_image
= m_image
;
999 if ( mask
& wxLIST_MASK_DATA
)
1000 info
.m_data
= m_data
;
1004 if ( m_attr
->HasTextColour() )
1005 info
.SetTextColour(m_attr
->GetTextColour());
1006 if ( m_attr
->HasBackgroundColour() )
1007 info
.SetBackgroundColour(m_attr
->GetBackgroundColour());
1008 if ( m_attr
->HasFont() )
1009 info
.SetFont(m_attr
->GetFont());
1013 //-----------------------------------------------------------------------------
1015 //-----------------------------------------------------------------------------
1017 void wxListHeaderData::Init()
1029 wxListHeaderData::wxListHeaderData()
1034 wxListHeaderData::wxListHeaderData( const wxListItem
&item
)
1041 void wxListHeaderData::SetItem( const wxListItem
&item
)
1043 m_mask
= item
.m_mask
;
1045 if ( m_mask
& wxLIST_MASK_TEXT
)
1046 m_text
= item
.m_text
;
1048 if ( m_mask
& wxLIST_MASK_IMAGE
)
1049 m_image
= item
.m_image
;
1051 if ( m_mask
& wxLIST_MASK_FORMAT
)
1052 m_format
= item
.m_format
;
1054 if ( m_mask
& wxLIST_MASK_WIDTH
)
1055 SetWidth(item
.m_width
);
1057 if ( m_mask
& wxLIST_MASK_STATE
)
1058 SetState(item
.m_state
);
1061 void wxListHeaderData::SetPosition( int x
, int y
)
1067 void wxListHeaderData::SetHeight( int h
)
1072 void wxListHeaderData::SetWidth( int w
)
1074 m_width
= w
< 0 ? WIDTH_COL_DEFAULT
: w
;
1077 void wxListHeaderData::SetState( int flag
)
1082 void wxListHeaderData::SetFormat( int format
)
1087 bool wxListHeaderData::HasImage() const
1089 return m_image
!= -1;
1092 bool wxListHeaderData::IsHit( int x
, int y
) const
1094 return ((x
>= m_xpos
) && (x
<= m_xpos
+m_width
) && (y
>= m_ypos
) && (y
<= m_ypos
+m_height
));
1097 void wxListHeaderData::GetItem( wxListItem
& item
)
1099 item
.m_mask
= m_mask
;
1100 item
.m_text
= m_text
;
1101 item
.m_image
= m_image
;
1102 item
.m_format
= m_format
;
1103 item
.m_width
= m_width
;
1104 item
.m_state
= m_state
;
1107 int wxListHeaderData::GetImage() const
1112 int wxListHeaderData::GetWidth() const
1117 int wxListHeaderData::GetFormat() const
1122 int wxListHeaderData::GetState() const
1127 //-----------------------------------------------------------------------------
1129 //-----------------------------------------------------------------------------
1131 inline int wxListLineData::GetMode() const
1133 return m_owner
->GetListCtrl()->GetWindowStyleFlag() & wxLC_MASK_TYPE
;
1136 inline bool wxListLineData::InReportView() const
1138 return m_owner
->HasFlag(wxLC_REPORT
);
1141 inline bool wxListLineData::IsVirtual() const
1143 return m_owner
->IsVirtual();
1146 wxListLineData::wxListLineData( wxListMainWindow
*owner
)
1150 if ( InReportView() )
1153 m_gi
= new GeometryInfo
;
1155 m_highlighted
= false;
1157 InitItems( GetMode() == wxLC_REPORT
? m_owner
->GetColumnCount() : 1 );
1160 void wxListLineData::CalculateSize( wxDC
*dc
, int spacing
)
1162 wxListItemDataList::compatibility_iterator node
= m_items
.GetFirst();
1163 wxCHECK_RET( node
, _T("no subitems at all??") );
1165 wxListItemData
*item
= node
->GetData();
1170 switch ( GetMode() )
1173 case wxLC_SMALL_ICON
:
1174 m_gi
->m_rectAll
.width
= spacing
;
1176 s
= item
->GetText();
1181 m_gi
->m_rectLabel
.width
=
1182 m_gi
->m_rectLabel
.height
= 0;
1186 dc
->GetTextExtent( s
, &lw
, &lh
);
1190 m_gi
->m_rectAll
.height
= spacing
+ lh
;
1192 m_gi
->m_rectAll
.width
= lw
;
1194 m_gi
->m_rectLabel
.width
= lw
;
1195 m_gi
->m_rectLabel
.height
= lh
;
1198 if (item
->HasImage())
1201 m_owner
->GetImageSize( item
->GetImage(), w
, h
);
1202 m_gi
->m_rectIcon
.width
= w
+ 8;
1203 m_gi
->m_rectIcon
.height
= h
+ 8;
1205 if ( m_gi
->m_rectIcon
.width
> m_gi
->m_rectAll
.width
)
1206 m_gi
->m_rectAll
.width
= m_gi
->m_rectIcon
.width
;
1207 if ( m_gi
->m_rectIcon
.height
+ lh
> m_gi
->m_rectAll
.height
- 4 )
1208 m_gi
->m_rectAll
.height
= m_gi
->m_rectIcon
.height
+ lh
+ 4;
1211 if ( item
->HasText() )
1213 m_gi
->m_rectHighlight
.width
= m_gi
->m_rectLabel
.width
;
1214 m_gi
->m_rectHighlight
.height
= m_gi
->m_rectLabel
.height
;
1216 else // no text, highlight the icon
1218 m_gi
->m_rectHighlight
.width
= m_gi
->m_rectIcon
.width
;
1219 m_gi
->m_rectHighlight
.height
= m_gi
->m_rectIcon
.height
;
1224 s
= item
->GetTextForMeasuring();
1226 dc
->GetTextExtent( s
, &lw
, &lh
);
1230 m_gi
->m_rectLabel
.width
= lw
;
1231 m_gi
->m_rectLabel
.height
= lh
;
1233 m_gi
->m_rectAll
.width
= lw
;
1234 m_gi
->m_rectAll
.height
= lh
;
1236 if (item
->HasImage())
1239 m_owner
->GetImageSize( item
->GetImage(), w
, h
);
1240 m_gi
->m_rectIcon
.width
= w
;
1241 m_gi
->m_rectIcon
.height
= h
;
1243 m_gi
->m_rectAll
.width
+= 4 + w
;
1244 if (h
> m_gi
->m_rectAll
.height
)
1245 m_gi
->m_rectAll
.height
= h
;
1248 m_gi
->m_rectHighlight
.width
= m_gi
->m_rectAll
.width
;
1249 m_gi
->m_rectHighlight
.height
= m_gi
->m_rectAll
.height
;
1253 wxFAIL_MSG( _T("unexpected call to SetSize") );
1257 wxFAIL_MSG( _T("unknown mode") );
1262 void wxListLineData::SetPosition( int x
, int y
, int spacing
)
1264 wxListItemDataList::compatibility_iterator node
= m_items
.GetFirst();
1265 wxCHECK_RET( node
, _T("no subitems at all??") );
1267 wxListItemData
*item
= node
->GetData();
1269 switch ( GetMode() )
1272 case wxLC_SMALL_ICON
:
1273 m_gi
->m_rectAll
.x
= x
;
1274 m_gi
->m_rectAll
.y
= y
;
1276 if ( item
->HasImage() )
1278 m_gi
->m_rectIcon
.x
= m_gi
->m_rectAll
.x
+ 4 +
1279 (m_gi
->m_rectAll
.width
- m_gi
->m_rectIcon
.width
) / 2;
1280 m_gi
->m_rectIcon
.y
= m_gi
->m_rectAll
.y
+ 4;
1283 if ( item
->HasText() )
1285 if (m_gi
->m_rectAll
.width
> spacing
)
1286 m_gi
->m_rectLabel
.x
= m_gi
->m_rectAll
.x
+ (EXTRA_WIDTH
/2);
1288 m_gi
->m_rectLabel
.x
= m_gi
->m_rectAll
.x
+ (EXTRA_WIDTH
/2) + (spacing
/ 2) - (m_gi
->m_rectLabel
.width
/ 2);
1289 m_gi
->m_rectLabel
.y
= m_gi
->m_rectAll
.y
+ m_gi
->m_rectAll
.height
+ 2 - m_gi
->m_rectLabel
.height
;
1290 m_gi
->m_rectHighlight
.x
= m_gi
->m_rectLabel
.x
- 2;
1291 m_gi
->m_rectHighlight
.y
= m_gi
->m_rectLabel
.y
- 2;
1293 else // no text, highlight the icon
1295 m_gi
->m_rectHighlight
.x
= m_gi
->m_rectIcon
.x
- 4;
1296 m_gi
->m_rectHighlight
.y
= m_gi
->m_rectIcon
.y
- 4;
1301 m_gi
->m_rectAll
.x
= x
;
1302 m_gi
->m_rectAll
.y
= y
;
1304 m_gi
->m_rectHighlight
.x
= m_gi
->m_rectAll
.x
;
1305 m_gi
->m_rectHighlight
.y
= m_gi
->m_rectAll
.y
;
1306 m_gi
->m_rectLabel
.y
= m_gi
->m_rectAll
.y
+ 2;
1308 if (item
->HasImage())
1310 m_gi
->m_rectIcon
.x
= m_gi
->m_rectAll
.x
+ 2;
1311 m_gi
->m_rectIcon
.y
= m_gi
->m_rectAll
.y
+ 2;
1312 m_gi
->m_rectLabel
.x
= m_gi
->m_rectAll
.x
+ 4 + (EXTRA_WIDTH
/2) + m_gi
->m_rectIcon
.width
;
1316 m_gi
->m_rectLabel
.x
= m_gi
->m_rectAll
.x
+ (EXTRA_WIDTH
/2);
1321 wxFAIL_MSG( _T("unexpected call to SetPosition") );
1325 wxFAIL_MSG( _T("unknown mode") );
1330 void wxListLineData::InitItems( int num
)
1332 for (int i
= 0; i
< num
; i
++)
1333 m_items
.Append( new wxListItemData(m_owner
) );
1336 void wxListLineData::SetItem( int index
, const wxListItem
&info
)
1338 wxListItemDataList::compatibility_iterator node
= m_items
.Item( index
);
1339 wxCHECK_RET( node
, _T("invalid column index in SetItem") );
1341 wxListItemData
*item
= node
->GetData();
1342 item
->SetItem( info
);
1345 void wxListLineData::GetItem( int index
, wxListItem
&info
)
1347 wxListItemDataList::compatibility_iterator node
= m_items
.Item( index
);
1350 wxListItemData
*item
= node
->GetData();
1351 item
->GetItem( info
);
1355 wxString
wxListLineData::GetText(int index
) const
1359 wxListItemDataList::compatibility_iterator node
= m_items
.Item( index
);
1362 wxListItemData
*item
= node
->GetData();
1363 s
= item
->GetText();
1369 void wxListLineData::SetText( int index
, const wxString
& s
)
1371 wxListItemDataList::compatibility_iterator node
= m_items
.Item( index
);
1374 wxListItemData
*item
= node
->GetData();
1379 void wxListLineData::SetImage( int index
, int image
)
1381 wxListItemDataList::compatibility_iterator node
= m_items
.Item( index
);
1382 wxCHECK_RET( node
, _T("invalid column index in SetImage()") );
1384 wxListItemData
*item
= node
->GetData();
1385 item
->SetImage(image
);
1388 int wxListLineData::GetImage( int index
) const
1390 wxListItemDataList::compatibility_iterator node
= m_items
.Item( index
);
1391 wxCHECK_MSG( node
, -1, _T("invalid column index in GetImage()") );
1393 wxListItemData
*item
= node
->GetData();
1394 return item
->GetImage();
1397 wxListItemAttr
*wxListLineData::GetAttr() const
1399 wxListItemDataList::compatibility_iterator node
= m_items
.GetFirst();
1400 wxCHECK_MSG( node
, NULL
, _T("invalid column index in GetAttr()") );
1402 wxListItemData
*item
= node
->GetData();
1403 return item
->GetAttr();
1406 void wxListLineData::SetAttr(wxListItemAttr
*attr
)
1408 wxListItemDataList::compatibility_iterator node
= m_items
.GetFirst();
1409 wxCHECK_RET( node
, _T("invalid column index in SetAttr()") );
1411 wxListItemData
*item
= node
->GetData();
1412 item
->SetAttr(attr
);
1415 bool wxListLineData::SetAttributes(wxDC
*dc
,
1416 const wxListItemAttr
*attr
,
1419 wxWindow
*listctrl
= m_owner
->GetParent();
1423 // don't use foreground colour for drawing highlighted items - this might
1424 // make them completely invisible (and there is no way to do bit
1425 // arithmetics on wxColour, unfortunately)
1430 if (m_owner
->HasFocus()
1431 #if !defined(__WXUNIVERSAL__) && wxOSX_USE_CARBON
1432 && IsControlActive( (ControlRef
)m_owner
->GetHandle() )
1440 colText
= wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHTTEXT
);
1442 else if ( attr
&& attr
->HasTextColour() )
1443 colText
= attr
->GetTextColour();
1445 colText
= listctrl
->GetForegroundColour();
1447 dc
->SetTextForeground(colText
);
1451 if ( attr
&& attr
->HasFont() )
1452 font
= attr
->GetFont();
1454 font
= listctrl
->GetFont();
1459 bool hasBgCol
= attr
&& attr
->HasBackgroundColour();
1460 if ( highlighted
|| hasBgCol
)
1463 dc
->SetBrush( *m_owner
->GetHighlightBrush() );
1465 dc
->SetBrush(wxBrush(attr
->GetBackgroundColour(), wxBRUSHSTYLE_SOLID
));
1467 dc
->SetPen( *wxTRANSPARENT_PEN
);
1475 void wxListLineData::Draw( wxDC
*dc
)
1477 wxListItemDataList::compatibility_iterator node
= m_items
.GetFirst();
1478 wxCHECK_RET( node
, _T("no subitems at all??") );
1480 bool highlighted
= IsHighlighted();
1482 wxListItemAttr
*attr
= GetAttr();
1484 if ( SetAttributes(dc
, attr
, highlighted
) )
1485 #if ( !defined(__WXGTK20__) && !defined(__WXMAC__) )
1487 dc
->DrawRectangle( m_gi
->m_rectHighlight
);
1493 int flags
= wxCONTROL_SELECTED
;
1494 if (m_owner
->HasFocus()
1495 #if defined( __WXMAC__ ) && !defined(__WXUNIVERSAL__) && wxOSX_USE_CARBON
1496 && IsControlActive( (ControlRef
)m_owner
->GetHandle() )
1499 flags
|= wxCONTROL_FOCUSED
;
1500 wxRendererNative::Get().DrawItemSelectionRect( m_owner
, *dc
, m_gi
->m_rectHighlight
, flags
);
1505 dc
->DrawRectangle( m_gi
->m_rectHighlight
);
1510 // just for debugging to better see where the items are
1512 dc
->SetPen(*wxRED_PEN
);
1513 dc
->SetBrush(*wxTRANSPARENT_BRUSH
);
1514 dc
->DrawRectangle( m_gi
->m_rectAll
);
1515 dc
->SetPen(*wxGREEN_PEN
);
1516 dc
->DrawRectangle( m_gi
->m_rectIcon
);
1519 wxListItemData
*item
= node
->GetData();
1520 if (item
->HasImage())
1522 // centre the image inside our rectangle, this looks nicer when items
1523 // ae aligned in a row
1524 const wxRect
& rectIcon
= m_gi
->m_rectIcon
;
1526 m_owner
->DrawImage(item
->GetImage(), dc
, rectIcon
.x
, rectIcon
.y
);
1529 if (item
->HasText())
1531 const wxRect
& rectLabel
= m_gi
->m_rectLabel
;
1533 wxDCClipper
clipper(*dc
, rectLabel
);
1534 dc
->DrawText(item
->GetText(), rectLabel
.x
, rectLabel
.y
);
1538 void wxListLineData::DrawInReportMode( wxDC
*dc
,
1540 const wxRect
& rectHL
,
1544 // TODO: later we should support setting different attributes for
1545 // different columns - to do it, just add "col" argument to
1546 // GetAttr() and move these lines into the loop below
1547 wxListItemAttr
*attr
= GetAttr();
1548 if ( SetAttributes(dc
, attr
, highlighted
) )
1549 #if ( !defined(__WXGTK20__) && !defined(__WXMAC__) )
1551 dc
->DrawRectangle( rectHL
);
1557 int flags
= wxCONTROL_SELECTED
;
1558 if (m_owner
->HasFocus())
1559 flags
|= wxCONTROL_FOCUSED
;
1561 flags
|= wxCONTROL_CURRENT
;
1562 wxRendererNative::Get().DrawItemSelectionRect( m_owner
, *dc
, rectHL
, flags
);
1566 dc
->DrawRectangle( rectHL
);
1571 wxCoord x
= rect
.x
+ HEADER_OFFSET_X
,
1572 yMid
= rect
.y
+ rect
.height
/2;
1574 // This probably needs to be done
1575 // on all platforms as the icons
1576 // otherwise nearly touch the border
1581 for ( wxListItemDataList::compatibility_iterator node
= m_items
.GetFirst();
1583 node
= node
->GetNext(), col
++ )
1585 wxListItemData
*item
= node
->GetData();
1587 int width
= m_owner
->GetColumnWidth(col
);
1591 const int wText
= width
- 8;
1592 wxDCClipper
clipper(*dc
, xOld
, rect
.y
, wText
, rect
.height
);
1594 if ( item
->HasImage() )
1597 m_owner
->GetImageSize( item
->GetImage(), ix
, iy
);
1598 m_owner
->DrawImage( item
->GetImage(), dc
, xOld
, yMid
- iy
/2 );
1600 ix
+= IMAGE_MARGIN_IN_REPORT_MODE
;
1606 if ( item
->HasText() )
1607 DrawTextFormatted(dc
, item
->GetText(), col
, xOld
, yMid
, wText
);
1611 void wxListLineData::DrawTextFormatted(wxDC
*dc
,
1612 const wxString
& textOrig
,
1618 // we don't support displaying multiple lines currently (and neither does
1619 // wxMSW FWIW) so just merge all the lines
1620 wxString
text(textOrig
);
1621 text
.Replace(_T("\n"), _T(" "));
1624 dc
->GetTextExtent(text
, &w
, &h
);
1626 const wxCoord y
= yMid
- (h
+ 1)/2;
1628 wxDCClipper
clipper(*dc
, x
, y
, width
, h
);
1630 // determine if the string can fit inside the current width
1633 // it can, draw it using the items alignment
1635 m_owner
->GetColumn(col
, item
);
1636 switch ( item
.GetAlign() )
1638 case wxLIST_FORMAT_LEFT
:
1642 case wxLIST_FORMAT_RIGHT
:
1646 case wxLIST_FORMAT_CENTER
:
1647 x
+= (width
- w
) / 2;
1651 wxFAIL_MSG( _T("unknown list item format") );
1655 dc
->DrawText(text
, x
, y
);
1657 else // otherwise, truncate and add an ellipsis if possible
1659 // determine the base width
1660 wxString
ellipsis(wxT("..."));
1662 dc
->GetTextExtent(ellipsis
, &base_w
, &h
);
1664 // continue until we have enough space or only one character left
1666 size_t len
= text
.length();
1667 wxString drawntext
= text
.Left(len
);
1670 dc
->GetTextExtent(drawntext
.Last(), &w_c
, &h_c
);
1671 drawntext
.RemoveLast();
1674 if (w
+ base_w
<= width
)
1678 // if still not enough space, remove ellipsis characters
1679 while (ellipsis
.length() > 0 && w
+ base_w
> width
)
1681 ellipsis
= ellipsis
.Left(ellipsis
.length() - 1);
1682 dc
->GetTextExtent(ellipsis
, &base_w
, &h
);
1685 // now draw the text
1686 dc
->DrawText(drawntext
, x
, y
);
1687 dc
->DrawText(ellipsis
, x
+ w
, y
);
1691 bool wxListLineData::Highlight( bool on
)
1693 wxCHECK_MSG( !IsVirtual(), false, _T("unexpected call to Highlight") );
1695 if ( on
== m_highlighted
)
1703 void wxListLineData::ReverseHighlight( void )
1705 Highlight(!IsHighlighted());
1708 //-----------------------------------------------------------------------------
1709 // wxListHeaderWindow
1710 //-----------------------------------------------------------------------------
1712 BEGIN_EVENT_TABLE(wxListHeaderWindow
,wxWindow
)
1713 EVT_PAINT (wxListHeaderWindow::OnPaint
)
1714 EVT_MOUSE_EVENTS (wxListHeaderWindow::OnMouse
)
1715 EVT_SET_FOCUS (wxListHeaderWindow::OnSetFocus
)
1718 void wxListHeaderWindow::Init()
1720 m_currentCursor
= NULL
;
1721 m_isDragging
= false;
1723 m_sendSetColumnWidth
= false;
1726 wxListHeaderWindow::wxListHeaderWindow()
1731 m_resizeCursor
= NULL
;
1734 wxListHeaderWindow::wxListHeaderWindow( wxWindow
*win
,
1736 wxListMainWindow
*owner
,
1740 const wxString
&name
)
1741 : wxWindow( win
, id
, pos
, size
, style
, name
)
1746 m_resizeCursor
= new wxCursor( wxCURSOR_SIZEWE
);
1749 wxVisualAttributes attr
= wxPanel::GetClassDefaultAttributes();
1750 SetOwnForegroundColour( attr
.colFg
);
1751 SetOwnBackgroundColour( attr
.colBg
);
1753 SetOwnFont( attr
.font
);
1755 SetOwnForegroundColour( wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT
));
1756 SetOwnBackgroundColour( wxSystemSettings::GetColour(wxSYS_COLOUR_BTNFACE
));
1758 SetOwnFont( wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT
));
1762 wxListHeaderWindow::~wxListHeaderWindow()
1764 delete m_resizeCursor
;
1767 #ifdef __WXUNIVERSAL__
1768 #include "wx/univ/renderer.h"
1769 #include "wx/univ/theme.h"
1772 // shift the DC origin to match the position of the main window horz
1773 // scrollbar: this allows us to always use logical coords
1774 void wxListHeaderWindow::AdjustDC(wxDC
& dc
)
1776 wxGenericListCtrl
*parent
= m_owner
->GetListCtrl();
1779 parent
->GetScrollPixelsPerUnit( &xpix
, NULL
);
1782 parent
->GetViewStart( &view_start
, NULL
);
1787 dc
.GetDeviceOrigin( &org_x
, &org_y
);
1789 // account for the horz scrollbar offset
1791 if (GetLayoutDirection() == wxLayout_RightToLeft
)
1793 // Maybe we just have to check for m_signX
1794 // in the DC, but I leave the #ifdef __WXGTK__
1796 dc
.SetDeviceOrigin( org_x
+ (view_start
* xpix
), org_y
);
1800 dc
.SetDeviceOrigin( org_x
- (view_start
* xpix
), org_y
);
1803 void wxListHeaderWindow::OnPaint( wxPaintEvent
&WXUNUSED(event
) )
1805 wxGenericListCtrl
*parent
= m_owner
->GetListCtrl();
1807 wxPaintDC
dc( this );
1811 dc
.SetFont( GetFont() );
1813 // width and height of the entire header window
1815 GetClientSize( &w
, &h
);
1816 parent
->CalcUnscrolledPosition(w
, 0, &w
, NULL
);
1818 dc
.SetBackgroundMode(wxBRUSHSTYLE_TRANSPARENT
);
1819 dc
.SetTextForeground(GetForegroundColour());
1821 int x
= HEADER_OFFSET_X
;
1822 int numColumns
= m_owner
->GetColumnCount();
1824 for ( int i
= 0; i
< numColumns
&& x
< w
; i
++ )
1826 m_owner
->GetColumn( i
, item
);
1827 int wCol
= item
.m_width
;
1833 if (!m_parent
->IsEnabled())
1834 flags
|= wxCONTROL_DISABLED
;
1836 // NB: The code below is not really Mac-specific, but since we are close
1837 // to 2.8 release and I don't have time to test on other platforms, I
1838 // defined this only for wxMac. If this behavior is desired on
1839 // other platforms, please go ahead and revise or remove the #ifdef.
1841 if ( !m_owner
->IsVirtual() && (item
.m_mask
& wxLIST_MASK_STATE
) &&
1842 (item
.m_state
& wxLIST_STATE_SELECTED
) )
1843 flags
|= wxCONTROL_SELECTED
;
1847 flags
|= wxCONTROL_SPECIAL
; // mark as first column
1849 wxRendererNative::Get().DrawHeaderButton
1853 wxRect(x
, HEADER_OFFSET_Y
, cw
, ch
),
1857 // see if we have enough space for the column label
1859 // for this we need the width of the text
1862 dc
.GetTextExtent(item
.GetText(), &wLabel
, &hLabel
);
1863 wLabel
+= 2 * EXTRA_WIDTH
;
1865 // and the width of the icon, if any
1866 int ix
= 0, iy
= 0; // init them just to suppress the compiler warnings
1867 const int image
= item
.m_image
;
1868 wxImageList
*imageList
;
1871 imageList
= m_owner
->m_small_image_list
;
1874 imageList
->GetSize(image
, ix
, iy
);
1875 wLabel
+= ix
+ HEADER_IMAGE_MARGIN_IN_REPORT_MODE
;
1883 // ignore alignment if there is not enough space anyhow
1885 switch ( wLabel
< cw
? item
.GetAlign() : wxLIST_FORMAT_LEFT
)
1888 wxFAIL_MSG( _T("unknown list item format") );
1891 case wxLIST_FORMAT_LEFT
:
1895 case wxLIST_FORMAT_RIGHT
:
1896 xAligned
= x
+ cw
- wLabel
;
1899 case wxLIST_FORMAT_CENTER
:
1900 xAligned
= x
+ (cw
- wLabel
) / 2;
1904 // draw the text and image clipping them so that they
1905 // don't overwrite the column boundary
1906 wxDCClipper
clipper(dc
, x
, HEADER_OFFSET_Y
, cw
, h
- 4 );
1908 // if we have an image, draw it on the right of the label
1915 xAligned
+ wLabel
- ix
- HEADER_IMAGE_MARGIN_IN_REPORT_MODE
,
1916 HEADER_OFFSET_Y
+ (h
- 4 - iy
)/2,
1917 wxIMAGELIST_DRAW_TRANSPARENT
1921 dc
.DrawText( item
.GetText(),
1922 xAligned
+ EXTRA_WIDTH
, h
/ 2 - hLabel
/ 2 ); //HEADER_OFFSET_Y + EXTRA_HEIGHT );
1927 // Fill in what's missing to the right of the columns, otherwise we will
1928 // leave an unpainted area when columns are removed (and it looks better)
1931 wxRendererNative::Get().DrawHeaderButton
1935 wxRect(x
, HEADER_OFFSET_Y
, w
- x
, h
),
1936 wxCONTROL_DIRTY
// mark as last column
1941 void wxListHeaderWindow::OnInternalIdle()
1943 wxWindow::OnInternalIdle();
1945 if (m_sendSetColumnWidth
)
1947 m_owner
->SetColumnWidth( m_colToSend
, m_widthToSend
);
1948 m_sendSetColumnWidth
= false;
1952 void wxListHeaderWindow::DrawCurrent()
1955 // m_owner->SetColumnWidth( m_column, m_currentX - m_minX );
1956 m_sendSetColumnWidth
= true;
1957 m_colToSend
= m_column
;
1958 m_widthToSend
= m_currentX
- m_minX
;
1960 int x1
= m_currentX
;
1962 m_owner
->ClientToScreen( &x1
, &y1
);
1964 int x2
= m_currentX
;
1966 m_owner
->GetClientSize( NULL
, &y2
);
1967 m_owner
->ClientToScreen( &x2
, &y2
);
1970 dc
.SetLogicalFunction( wxINVERT
);
1971 dc
.SetPen( wxPen( *wxBLACK
, 2, wxSOLID
) );
1972 dc
.SetBrush( *wxTRANSPARENT_BRUSH
);
1976 dc
.DrawLine( x1
, y1
, x2
, y2
);
1978 dc
.SetLogicalFunction( wxCOPY
);
1980 dc
.SetPen( wxNullPen
);
1981 dc
.SetBrush( wxNullBrush
);
1985 void wxListHeaderWindow::OnMouse( wxMouseEvent
&event
)
1987 wxGenericListCtrl
*parent
= m_owner
->GetListCtrl();
1989 // we want to work with logical coords
1991 parent
->CalcUnscrolledPosition(event
.GetX(), 0, &x
, NULL
);
1992 int y
= event
.GetY();
1996 SendListEvent(wxEVT_COMMAND_LIST_COL_DRAGGING
, event
.GetPosition());
1998 // we don't draw the line beyond our window, but we allow dragging it
2001 GetClientSize( &w
, NULL
);
2002 parent
->CalcUnscrolledPosition(w
, 0, &w
, NULL
);
2005 // erase the line if it was drawn
2006 if ( m_currentX
< w
)
2009 if (event
.ButtonUp())
2012 m_isDragging
= false;
2014 m_owner
->SetColumnWidth( m_column
, m_currentX
- m_minX
);
2015 SendListEvent(wxEVT_COMMAND_LIST_COL_END_DRAG
, event
.GetPosition());
2022 m_currentX
= m_minX
+ 7;
2024 // draw in the new location
2025 if ( m_currentX
< w
)
2029 else // not dragging
2032 bool hit_border
= false;
2034 // end of the current column
2037 // find the column where this event occurred
2039 countCol
= m_owner
->GetColumnCount();
2040 for (col
= 0; col
< countCol
; col
++)
2042 xpos
+= m_owner
->GetColumnWidth( col
);
2045 if ( (abs(x
-xpos
) < 3) && (y
< 22) )
2047 // near the column border
2054 // inside the column
2061 if ( col
== countCol
)
2064 if (event
.LeftDown() || event
.RightUp())
2066 if (hit_border
&& event
.LeftDown())
2068 if ( SendListEvent(wxEVT_COMMAND_LIST_COL_BEGIN_DRAG
,
2069 event
.GetPosition()) )
2071 m_isDragging
= true;
2076 //else: column resizing was vetoed by the user code
2078 else // click on a column
2080 // record the selected state of the columns
2081 if (event
.LeftDown())
2083 for (int i
=0; i
< m_owner
->GetColumnCount(); i
++)
2086 m_owner
->GetColumn(i
, colItem
);
2087 long state
= colItem
.GetState();
2089 colItem
.SetState(state
| wxLIST_STATE_SELECTED
);
2091 colItem
.SetState(state
& ~wxLIST_STATE_SELECTED
);
2092 m_owner
->SetColumn(i
, colItem
);
2096 SendListEvent( event
.LeftDown()
2097 ? wxEVT_COMMAND_LIST_COL_CLICK
2098 : wxEVT_COMMAND_LIST_COL_RIGHT_CLICK
,
2099 event
.GetPosition());
2102 else if (event
.Moving())
2107 setCursor
= m_currentCursor
== wxSTANDARD_CURSOR
;
2108 m_currentCursor
= m_resizeCursor
;
2112 setCursor
= m_currentCursor
!= wxSTANDARD_CURSOR
;
2113 m_currentCursor
= wxSTANDARD_CURSOR
;
2117 SetCursor(*m_currentCursor
);
2122 void wxListHeaderWindow::OnSetFocus( wxFocusEvent
&WXUNUSED(event
) )
2124 m_owner
->SetFocus();
2128 bool wxListHeaderWindow::SendListEvent(wxEventType type
, const wxPoint
& pos
)
2130 wxWindow
*parent
= GetParent();
2131 wxListEvent
le( type
, parent
->GetId() );
2132 le
.SetEventObject( parent
);
2133 le
.m_pointDrag
= pos
;
2135 // the position should be relative to the parent window, not
2136 // this one for compatibility with MSW and common sense: the
2137 // user code doesn't know anything at all about this header
2138 // window, so why should it get positions relative to it?
2139 le
.m_pointDrag
.y
-= GetSize().y
;
2141 le
.m_col
= m_column
;
2142 return !parent
->GetEventHandler()->ProcessEvent( le
) || le
.IsAllowed();
2145 //-----------------------------------------------------------------------------
2146 // wxListRenameTimer (internal)
2147 //-----------------------------------------------------------------------------
2149 wxListRenameTimer::wxListRenameTimer( wxListMainWindow
*owner
)
2154 void wxListRenameTimer::Notify()
2156 m_owner
->OnRenameTimer();
2159 //-----------------------------------------------------------------------------
2160 // wxListTextCtrlWrapper (internal)
2161 //-----------------------------------------------------------------------------
2163 BEGIN_EVENT_TABLE(wxListTextCtrlWrapper
, wxEvtHandler
)
2164 EVT_CHAR (wxListTextCtrlWrapper::OnChar
)
2165 EVT_KEY_UP (wxListTextCtrlWrapper::OnKeyUp
)
2166 EVT_KILL_FOCUS (wxListTextCtrlWrapper::OnKillFocus
)
2169 wxListTextCtrlWrapper::wxListTextCtrlWrapper(wxListMainWindow
*owner
,
2172 : m_startValue(owner
->GetItemText(itemEdit
)),
2173 m_itemEdited(itemEdit
)
2177 m_aboutToFinish
= false;
2179 wxGenericListCtrl
*parent
= m_owner
->GetListCtrl();
2181 wxRect rectLabel
= owner
->GetLineLabelRect(itemEdit
);
2183 parent
->CalcScrolledPosition(rectLabel
.x
, rectLabel
.y
,
2184 &rectLabel
.x
, &rectLabel
.y
);
2186 m_text
->Create(owner
, wxID_ANY
, m_startValue
,
2187 wxPoint(rectLabel
.x
-4,rectLabel
.y
-4),
2188 wxSize(rectLabel
.width
+11,rectLabel
.height
+8));
2191 m_text
->PushEventHandler(this);
2194 void wxListTextCtrlWrapper::EndEdit(bool discardChanges
)
2196 m_aboutToFinish
= true;
2198 if ( discardChanges
)
2200 m_owner
->OnRenameCancelled(m_itemEdited
);
2206 // Notify the owner about the changes
2209 // Even if vetoed, close the control (consistent with MSW)
2214 void wxListTextCtrlWrapper::Finish( bool setfocus
)
2216 m_text
->RemoveEventHandler(this);
2217 m_owner
->ResetTextControl( m_text
);
2219 wxPendingDelete
.Append( this );
2222 m_owner
->SetFocus();
2225 bool wxListTextCtrlWrapper::AcceptChanges()
2227 const wxString value
= m_text
->GetValue();
2229 // notice that we should always call OnRenameAccept() to generate the "end
2230 // label editing" event, even if the user hasn't really changed anything
2231 if ( !m_owner
->OnRenameAccept(m_itemEdited
, value
) )
2233 // vetoed by the user
2237 // accepted, do rename the item (unless nothing changed)
2238 if ( value
!= m_startValue
)
2239 m_owner
->SetItemText(m_itemEdited
, value
);
2244 void wxListTextCtrlWrapper::OnChar( wxKeyEvent
&event
)
2246 switch ( event
.m_keyCode
)
2261 void wxListTextCtrlWrapper::OnKeyUp( wxKeyEvent
&event
)
2263 if (m_aboutToFinish
)
2265 // auto-grow the textctrl:
2266 wxSize parentSize
= m_owner
->GetSize();
2267 wxPoint myPos
= m_text
->GetPosition();
2268 wxSize mySize
= m_text
->GetSize();
2270 m_text
->GetTextExtent(m_text
->GetValue() + _T("MM"), &sx
, &sy
);
2271 if (myPos
.x
+ sx
> parentSize
.x
)
2272 sx
= parentSize
.x
- myPos
.x
;
2275 m_text
->SetSize(sx
, wxDefaultCoord
);
2281 void wxListTextCtrlWrapper::OnKillFocus( wxFocusEvent
&event
)
2283 if ( !m_aboutToFinish
)
2285 if ( !AcceptChanges() )
2286 m_owner
->OnRenameCancelled( m_itemEdited
);
2291 // We must let the native text control handle focus
2295 //-----------------------------------------------------------------------------
2297 //-----------------------------------------------------------------------------
2299 BEGIN_EVENT_TABLE(wxListMainWindow
,wxScrolledCanvas
)
2300 EVT_PAINT (wxListMainWindow::OnPaint
)
2301 EVT_MOUSE_EVENTS (wxListMainWindow::OnMouse
)
2302 EVT_CHAR (wxListMainWindow::OnChar
)
2303 EVT_KEY_DOWN (wxListMainWindow::OnKeyDown
)
2304 EVT_KEY_UP (wxListMainWindow::OnKeyUp
)
2305 EVT_SET_FOCUS (wxListMainWindow::OnSetFocus
)
2306 EVT_KILL_FOCUS (wxListMainWindow::OnKillFocus
)
2307 EVT_SCROLLWIN (wxListMainWindow::OnScroll
)
2308 EVT_CHILD_FOCUS (wxListMainWindow::OnChildFocus
)
2311 void wxListMainWindow::Init()
2316 m_lineTo
= (size_t)-1;
2322 m_small_image_list
= NULL
;
2323 m_normal_image_list
= NULL
;
2325 m_small_spacing
= 30;
2326 m_normal_spacing
= 40;
2330 m_isCreated
= false;
2332 m_lastOnSame
= false;
2333 m_renameTimer
= new wxListRenameTimer( this );
2334 m_textctrlWrapper
= NULL
;
2338 m_lineSelectSingleOnUp
=
2339 m_lineBeforeLastClicked
= (size_t)-1;
2342 wxListMainWindow::wxListMainWindow()
2347 m_highlightUnfocusedBrush
= NULL
;
2350 wxListMainWindow::wxListMainWindow( wxWindow
*parent
,
2355 const wxString
&name
)
2356 : wxWindow( parent
, id
, pos
, size
, style
, name
)
2360 m_highlightBrush
= new wxBrush
2362 wxSystemSettings::GetColour
2364 wxSYS_COLOUR_HIGHLIGHT
2369 m_highlightUnfocusedBrush
= new wxBrush
2371 wxSystemSettings::GetColour
2373 wxSYS_COLOUR_BTNSHADOW
2378 wxVisualAttributes attr
= wxGenericListCtrl::GetClassDefaultAttributes();
2379 SetOwnForegroundColour( attr
.colFg
);
2380 SetOwnBackgroundColour( attr
.colBg
);
2382 SetOwnFont( attr
.font
);
2385 wxListMainWindow::~wxListMainWindow()
2388 WX_CLEAR_LIST(wxListHeaderDataList
, m_columns
);
2389 WX_CLEAR_ARRAY(m_aColWidths
);
2391 delete m_highlightBrush
;
2392 delete m_highlightUnfocusedBrush
;
2393 delete m_renameTimer
;
2396 void wxListMainWindow::CacheLineData(size_t line
)
2398 wxGenericListCtrl
*listctrl
= GetListCtrl();
2400 wxListLineData
*ld
= GetDummyLine();
2402 size_t countCol
= GetColumnCount();
2403 for ( size_t col
= 0; col
< countCol
; col
++ )
2405 ld
->SetText(col
, listctrl
->OnGetItemText(line
, col
));
2406 ld
->SetImage(col
, listctrl
->OnGetItemColumnImage(line
, col
));
2409 ld
->SetAttr(listctrl
->OnGetItemAttr(line
));
2412 wxListLineData
*wxListMainWindow::GetDummyLine() const
2414 wxASSERT_MSG( !IsEmpty(), _T("invalid line index") );
2415 wxASSERT_MSG( IsVirtual(), _T("GetDummyLine() shouldn't be called") );
2417 wxListMainWindow
*self
= wxConstCast(this, wxListMainWindow
);
2419 // we need to recreate the dummy line if the number of columns in the
2420 // control changed as it would have the incorrect number of fields
2422 if ( !m_lines
.IsEmpty() &&
2423 m_lines
[0].m_items
.GetCount() != (size_t)GetColumnCount() )
2425 self
->m_lines
.Clear();
2428 if ( m_lines
.IsEmpty() )
2430 wxListLineData
*line
= new wxListLineData(self
);
2431 self
->m_lines
.Add(line
);
2433 // don't waste extra memory -- there never going to be anything
2434 // else/more in this array
2435 self
->m_lines
.Shrink();
2441 // ----------------------------------------------------------------------------
2442 // line geometry (report mode only)
2443 // ----------------------------------------------------------------------------
2445 wxCoord
wxListMainWindow::GetLineHeight() const
2447 // we cache the line height as calling GetTextExtent() is slow
2448 if ( !m_lineHeight
)
2450 wxListMainWindow
*self
= wxConstCast(this, wxListMainWindow
);
2452 wxClientDC
dc( self
);
2453 dc
.SetFont( GetFont() );
2456 dc
.GetTextExtent(_T("H"), NULL
, &y
);
2458 if ( m_small_image_list
&& m_small_image_list
->GetImageCount() )
2461 m_small_image_list
->GetSize(0, iw
, ih
);
2466 self
->m_lineHeight
= y
+ LINE_SPACING
;
2469 return m_lineHeight
;
2472 wxCoord
wxListMainWindow::GetLineY(size_t line
) const
2474 wxASSERT_MSG( InReportView(), _T("only works in report mode") );
2476 return LINE_SPACING
+ line
* GetLineHeight();
2479 wxRect
wxListMainWindow::GetLineRect(size_t line
) const
2481 if ( !InReportView() )
2482 return GetLine(line
)->m_gi
->m_rectAll
;
2485 rect
.x
= HEADER_OFFSET_X
;
2486 rect
.y
= GetLineY(line
);
2487 rect
.width
= GetHeaderWidth();
2488 rect
.height
= GetLineHeight();
2493 wxRect
wxListMainWindow::GetLineLabelRect(size_t line
) const
2495 if ( !InReportView() )
2496 return GetLine(line
)->m_gi
->m_rectLabel
;
2499 wxListLineData
*data
= GetLine(line
);
2500 wxListItemDataList::compatibility_iterator node
= data
->m_items
.GetFirst();
2503 wxListItemData
*item
= node
->GetData();
2504 if ( item
->HasImage() )
2507 GetImageSize( item
->GetImage(), ix
, iy
);
2508 image_x
= 3 + ix
+ IMAGE_MARGIN_IN_REPORT_MODE
;
2513 rect
.x
= image_x
+ HEADER_OFFSET_X
;
2514 rect
.y
= GetLineY(line
);
2515 rect
.width
= GetColumnWidth(0) - image_x
;
2516 rect
.height
= GetLineHeight();
2521 wxRect
wxListMainWindow::GetLineIconRect(size_t line
) const
2523 if ( !InReportView() )
2524 return GetLine(line
)->m_gi
->m_rectIcon
;
2526 wxListLineData
*ld
= GetLine(line
);
2527 wxASSERT_MSG( ld
->HasImage(), _T("should have an image") );
2530 rect
.x
= HEADER_OFFSET_X
;
2531 rect
.y
= GetLineY(line
);
2532 GetImageSize(ld
->GetImage(), rect
.width
, rect
.height
);
2537 wxRect
wxListMainWindow::GetLineHighlightRect(size_t line
) const
2539 return InReportView() ? GetLineRect(line
)
2540 : GetLine(line
)->m_gi
->m_rectHighlight
;
2543 long wxListMainWindow::HitTestLine(size_t line
, int x
, int y
) const
2545 wxASSERT_MSG( line
< GetItemCount(), _T("invalid line in HitTestLine") );
2547 wxListLineData
*ld
= GetLine(line
);
2549 if ( ld
->HasImage() && GetLineIconRect(line
).Contains(x
, y
) )
2550 return wxLIST_HITTEST_ONITEMICON
;
2552 // VS: Testing for "ld->HasText() || InReportView()" instead of
2553 // "ld->HasText()" is needed to make empty lines in report view
2555 if ( ld
->HasText() || InReportView() )
2557 wxRect rect
= InReportView() ? GetLineRect(line
)
2558 : GetLineLabelRect(line
);
2560 if ( rect
.Contains(x
, y
) )
2561 return wxLIST_HITTEST_ONITEMLABEL
;
2567 // ----------------------------------------------------------------------------
2568 // highlight (selection) handling
2569 // ----------------------------------------------------------------------------
2571 bool wxListMainWindow::IsHighlighted(size_t line
) const
2575 return m_selStore
.IsSelected(line
);
2579 wxListLineData
*ld
= GetLine(line
);
2580 wxCHECK_MSG( ld
, false, _T("invalid index in IsHighlighted") );
2582 return ld
->IsHighlighted();
2586 void wxListMainWindow::HighlightLines( size_t lineFrom
,
2592 wxArrayInt linesChanged
;
2593 if ( !m_selStore
.SelectRange(lineFrom
, lineTo
, highlight
,
2596 // meny items changed state, refresh everything
2597 RefreshLines(lineFrom
, lineTo
);
2599 else // only a few items changed state, refresh only them
2601 size_t count
= linesChanged
.GetCount();
2602 for ( size_t n
= 0; n
< count
; n
++ )
2604 RefreshLine(linesChanged
[n
]);
2608 else // iterate over all items in non report view
2610 for ( size_t line
= lineFrom
; line
<= lineTo
; line
++ )
2612 if ( HighlightLine(line
, highlight
) )
2618 bool wxListMainWindow::HighlightLine( size_t line
, bool highlight
)
2624 changed
= m_selStore
.SelectItem(line
, highlight
);
2628 wxListLineData
*ld
= GetLine(line
);
2629 wxCHECK_MSG( ld
, false, _T("invalid index in HighlightLine") );
2631 changed
= ld
->Highlight(highlight
);
2636 SendNotify( line
, highlight
? wxEVT_COMMAND_LIST_ITEM_SELECTED
2637 : wxEVT_COMMAND_LIST_ITEM_DESELECTED
);
2643 void wxListMainWindow::RefreshLine( size_t line
)
2645 if ( InReportView() )
2647 size_t visibleFrom
, visibleTo
;
2648 GetVisibleLinesRange(&visibleFrom
, &visibleTo
);
2650 if ( line
< visibleFrom
|| line
> visibleTo
)
2654 wxRect rect
= GetLineRect(line
);
2656 GetListCtrl()->CalcScrolledPosition( rect
.x
, rect
.y
, &rect
.x
, &rect
.y
);
2657 RefreshRect( rect
);
2660 void wxListMainWindow::RefreshLines( size_t lineFrom
, size_t lineTo
)
2662 // we suppose that they are ordered by caller
2663 wxASSERT_MSG( lineFrom
<= lineTo
, _T("indices in disorder") );
2665 wxASSERT_MSG( lineTo
< GetItemCount(), _T("invalid line range") );
2667 if ( InReportView() )
2669 size_t visibleFrom
, visibleTo
;
2670 GetVisibleLinesRange(&visibleFrom
, &visibleTo
);
2672 if ( lineFrom
< visibleFrom
)
2673 lineFrom
= visibleFrom
;
2674 if ( lineTo
> visibleTo
)
2679 rect
.y
= GetLineY(lineFrom
);
2680 rect
.width
= GetClientSize().x
;
2681 rect
.height
= GetLineY(lineTo
) - rect
.y
+ GetLineHeight();
2683 GetListCtrl()->CalcScrolledPosition( rect
.x
, rect
.y
, &rect
.x
, &rect
.y
);
2684 RefreshRect( rect
);
2688 // TODO: this should be optimized...
2689 for ( size_t line
= lineFrom
; line
<= lineTo
; line
++ )
2696 void wxListMainWindow::RefreshAfter( size_t lineFrom
)
2698 if ( InReportView() )
2700 size_t visibleFrom
, visibleTo
;
2701 GetVisibleLinesRange(&visibleFrom
, &visibleTo
);
2703 if ( lineFrom
< visibleFrom
)
2704 lineFrom
= visibleFrom
;
2705 else if ( lineFrom
> visibleTo
)
2710 rect
.y
= GetLineY(lineFrom
);
2711 GetListCtrl()->CalcScrolledPosition( rect
.x
, rect
.y
, &rect
.x
, &rect
.y
);
2713 wxSize size
= GetClientSize();
2714 rect
.width
= size
.x
;
2716 // refresh till the bottom of the window
2717 rect
.height
= size
.y
- rect
.y
;
2719 RefreshRect( rect
);
2723 // TODO: how to do it more efficiently?
2728 void wxListMainWindow::RefreshSelected()
2734 if ( InReportView() )
2736 GetVisibleLinesRange(&from
, &to
);
2741 to
= GetItemCount() - 1;
2744 if ( HasCurrent() && m_current
>= from
&& m_current
<= to
)
2745 RefreshLine(m_current
);
2747 for ( size_t line
= from
; line
<= to
; line
++ )
2749 // NB: the test works as expected even if m_current == -1
2750 if ( line
!= m_current
&& IsHighlighted(line
) )
2755 void wxListMainWindow::OnPaint( wxPaintEvent
&WXUNUSED(event
) )
2757 // Note: a wxPaintDC must be constructed even if no drawing is
2758 // done (a Windows requirement).
2759 wxPaintDC
dc( this );
2763 // nothing to draw or not the moment to draw it
2768 RecalculatePositions( false );
2770 GetListCtrl()->PrepareDC( dc
);
2773 GetListCtrl()->CalcScrolledPosition( 0, 0, &dev_x
, &dev_y
);
2775 dc
.SetFont( GetFont() );
2777 if ( InReportView() )
2779 int lineHeight
= GetLineHeight();
2781 size_t visibleFrom
, visibleTo
;
2782 GetVisibleLinesRange(&visibleFrom
, &visibleTo
);
2785 int xOrig
= dc
.LogicalToDeviceX( 0 );
2786 int yOrig
= dc
.LogicalToDeviceY( 0 );
2788 // tell the caller cache to cache the data
2791 wxListEvent
evCache(wxEVT_COMMAND_LIST_CACHE_HINT
,
2792 GetParent()->GetId());
2793 evCache
.SetEventObject( GetParent() );
2794 evCache
.m_oldItemIndex
= visibleFrom
;
2795 evCache
.m_itemIndex
= visibleTo
;
2796 GetParent()->GetEventHandler()->ProcessEvent( evCache
);
2799 for ( size_t line
= visibleFrom
; line
<= visibleTo
; line
++ )
2801 rectLine
= GetLineRect(line
);
2804 if ( !IsExposed(rectLine
.x
+ xOrig
, rectLine
.y
+ yOrig
,
2805 rectLine
.width
, rectLine
.height
) )
2807 // don't redraw unaffected lines to avoid flicker
2811 GetLine(line
)->DrawInReportMode( &dc
,
2813 GetLineHighlightRect(line
),
2814 IsHighlighted(line
),
2815 line
== m_current
);
2818 if ( HasFlag(wxLC_HRULES
) )
2820 wxPen
pen(GetRuleColour(), 1, wxPENSTYLE_SOLID
);
2821 wxSize clientSize
= GetClientSize();
2823 size_t i
= visibleFrom
;
2824 if (i
== 0) i
= 1; // Don't draw the first one
2825 for ( ; i
<= visibleTo
; i
++ )
2828 dc
.SetBrush( *wxTRANSPARENT_BRUSH
);
2829 dc
.DrawLine(0 - dev_x
, i
* lineHeight
,
2830 clientSize
.x
- dev_x
, i
* lineHeight
);
2833 // Draw last horizontal rule
2834 if ( visibleTo
== GetItemCount() - 1 )
2837 dc
.SetBrush( *wxTRANSPARENT_BRUSH
);
2838 dc
.DrawLine(0 - dev_x
, (m_lineTo
+ 1) * lineHeight
,
2839 clientSize
.x
- dev_x
, (m_lineTo
+ 1) * lineHeight
);
2843 // Draw vertical rules if required
2844 if ( HasFlag(wxLC_VRULES
) && !IsEmpty() )
2846 wxPen
pen(GetRuleColour(), 1, wxPENSTYLE_SOLID
);
2847 wxRect firstItemRect
, lastItemRect
;
2849 GetItemRect(visibleFrom
, firstItemRect
);
2850 GetItemRect(visibleTo
, lastItemRect
);
2851 int x
= firstItemRect
.GetX();
2853 dc
.SetBrush(* wxTRANSPARENT_BRUSH
);
2855 for (int col
= 0; col
< GetColumnCount(); col
++)
2857 int colWidth
= GetColumnWidth(col
);
2859 int x_pos
= x
- dev_x
;
2860 if (col
< GetColumnCount()-1) x_pos
-= 2;
2861 dc
.DrawLine(x_pos
, firstItemRect
.GetY() - 1 - dev_y
,
2862 x_pos
, lastItemRect
.GetBottom() + 1 - dev_y
);
2868 size_t count
= GetItemCount();
2869 for ( size_t i
= 0; i
< count
; i
++ )
2871 GetLine(i
)->Draw( &dc
);
2875 #if !defined( __WXMAC__) && !defined(__WXGTK20__)
2876 // Don't draw rect outline under Mac at all.
2877 // Draw it elsewhere under GTK.
2882 wxRect
rect( GetLineHighlightRect( m_current
) );
2883 dc
.SetPen( *wxBLACK_PEN
);
2884 dc
.SetBrush( *wxTRANSPARENT_BRUSH
);
2885 dc
.DrawRectangle( rect
);
2891 void wxListMainWindow::HighlightAll( bool on
)
2893 if ( IsSingleSel() )
2895 wxASSERT_MSG( !on
, _T("can't do this in a single selection control") );
2897 // we just have one item to turn off
2898 if ( HasCurrent() && IsHighlighted(m_current
) )
2900 HighlightLine(m_current
, false);
2901 RefreshLine(m_current
);
2904 else // multi selection
2907 HighlightLines(0, GetItemCount() - 1, on
);
2911 void wxListMainWindow::OnChildFocus(wxChildFocusEvent
& WXUNUSED(event
))
2913 // Do nothing here. This prevents the default handler in wxScrolledWindow
2914 // from needlessly scrolling the window when the edit control is
2915 // dismissed. See ticket #9563.
2918 void wxListMainWindow::SendNotify( size_t line
,
2919 wxEventType command
,
2920 const wxPoint
& point
)
2922 wxListEvent
le( command
, GetParent()->GetId() );
2923 le
.SetEventObject( GetParent() );
2925 le
.m_itemIndex
= line
;
2927 // set only for events which have position
2928 if ( point
!= wxDefaultPosition
)
2929 le
.m_pointDrag
= point
;
2931 // don't try to get the line info for virtual list controls: the main
2932 // program has it anyhow and if we did it would result in accessing all
2933 // the lines, even those which are not visible now and this is precisely
2934 // what we're trying to avoid
2937 if ( line
!= (size_t)-1 )
2939 GetLine(line
)->GetItem( 0, le
.m_item
);
2941 //else: this happens for wxEVT_COMMAND_LIST_ITEM_FOCUSED event
2943 //else: there may be no more such item
2945 GetParent()->GetEventHandler()->ProcessEvent( le
);
2948 void wxListMainWindow::ChangeCurrent(size_t current
)
2950 m_current
= current
;
2952 // as the current item changed, we shouldn't start editing it when the
2953 // "slow click" timer expires as the click happened on another item
2954 if ( m_renameTimer
->IsRunning() )
2955 m_renameTimer
->Stop();
2957 SendNotify(current
, wxEVT_COMMAND_LIST_ITEM_FOCUSED
);
2960 wxTextCtrl
*wxListMainWindow::EditLabel(long item
, wxClassInfo
* textControlClass
)
2962 wxCHECK_MSG( (item
>= 0) && ((size_t)item
< GetItemCount()), NULL
,
2963 wxT("wrong index in wxGenericListCtrl::EditLabel()") );
2965 wxASSERT_MSG( textControlClass
->IsKindOf(CLASSINFO(wxTextCtrl
)),
2966 wxT("EditLabel() needs a text control") );
2968 size_t itemEdit
= (size_t)item
;
2970 wxListEvent
le( wxEVT_COMMAND_LIST_BEGIN_LABEL_EDIT
, GetParent()->GetId() );
2971 le
.SetEventObject( GetParent() );
2972 le
.m_itemIndex
= item
;
2973 wxListLineData
*data
= GetLine(itemEdit
);
2974 wxCHECK_MSG( data
, NULL
, _T("invalid index in EditLabel()") );
2975 data
->GetItem( 0, le
.m_item
);
2977 if ( GetParent()->GetEventHandler()->ProcessEvent( le
) && !le
.IsAllowed() )
2979 // vetoed by user code
2983 // We have to call this here because the label in question might just have
2984 // been added and no screen update taken place.
2989 // Pending events dispatched by wxSafeYield might have changed the item
2991 if ( (size_t)item
>= GetItemCount() )
2995 wxTextCtrl
* const text
= (wxTextCtrl
*)textControlClass
->CreateObject();
2996 m_textctrlWrapper
= new wxListTextCtrlWrapper(this, text
, item
);
2997 return m_textctrlWrapper
->GetText();
3000 void wxListMainWindow::OnRenameTimer()
3002 wxCHECK_RET( HasCurrent(), wxT("unexpected rename timer") );
3004 EditLabel( m_current
);
3007 bool wxListMainWindow::OnRenameAccept(size_t itemEdit
, const wxString
& value
)
3009 wxListEvent
le( wxEVT_COMMAND_LIST_END_LABEL_EDIT
, GetParent()->GetId() );
3010 le
.SetEventObject( GetParent() );
3011 le
.m_itemIndex
= itemEdit
;
3013 wxListLineData
*data
= GetLine(itemEdit
);
3015 wxCHECK_MSG( data
, false, _T("invalid index in OnRenameAccept()") );
3017 data
->GetItem( 0, le
.m_item
);
3018 le
.m_item
.m_text
= value
;
3019 return !GetParent()->GetEventHandler()->ProcessEvent( le
) ||
3023 void wxListMainWindow::OnRenameCancelled(size_t itemEdit
)
3025 // let owner know that the edit was cancelled
3026 wxListEvent
le( wxEVT_COMMAND_LIST_END_LABEL_EDIT
, GetParent()->GetId() );
3028 le
.SetEditCanceled(true);
3030 le
.SetEventObject( GetParent() );
3031 le
.m_itemIndex
= itemEdit
;
3033 wxListLineData
*data
= GetLine(itemEdit
);
3034 wxCHECK_RET( data
, _T("invalid index in OnRenameCancelled()") );
3036 data
->GetItem( 0, le
.m_item
);
3037 GetEventHandler()->ProcessEvent( le
);
3040 void wxListMainWindow::OnMouse( wxMouseEvent
&event
)
3044 // On wxMac we can't depend on the EVT_KILL_FOCUS event to properly
3045 // shutdown the edit control when the mouse is clicked elsewhere on the
3046 // listctrl because the order of events is different (or something like
3047 // that), so explicitly end the edit if it is active.
3048 if ( event
.LeftDown() && m_textctrlWrapper
)
3049 m_textctrlWrapper
->EndEdit( false );
3052 if ( event
.LeftDown() )
3055 event
.SetEventObject( GetParent() );
3056 if ( GetParent()->GetEventHandler()->ProcessEvent( event
) )
3059 if (event
.GetEventType() == wxEVT_MOUSEWHEEL
)
3061 // let the base handle mouse wheel events.
3066 if ( !HasCurrent() || IsEmpty() )
3068 if (event
.RightDown())
3070 SendNotify( (size_t)-1, wxEVT_COMMAND_LIST_ITEM_RIGHT_CLICK
, event
.GetPosition() );
3072 wxContextMenuEvent
evtCtx(
3074 GetParent()->GetId(),
3075 ClientToScreen(event
.GetPosition()));
3076 evtCtx
.SetEventObject(GetParent());
3077 GetParent()->GetEventHandler()->ProcessEvent(evtCtx
);
3085 if ( !(event
.Dragging() || event
.ButtonDown() || event
.LeftUp() ||
3086 event
.ButtonDClick()) )
3089 int x
= event
.GetX();
3090 int y
= event
.GetY();
3091 GetListCtrl()->CalcUnscrolledPosition( x
, y
, &x
, &y
);
3093 // where did we hit it (if we did)?
3096 size_t count
= GetItemCount(),
3099 if ( InReportView() )
3101 current
= y
/ GetLineHeight();
3102 if ( current
< count
)
3103 hitResult
= HitTestLine(current
, x
, y
);
3107 // TODO: optimize it too! this is less simple than for report view but
3108 // enumerating all items is still not a way to do it!!
3109 for ( current
= 0; current
< count
; current
++ )
3111 hitResult
= HitTestLine(current
, x
, y
);
3117 if (event
.Dragging())
3119 if (m_dragCount
== 0)
3121 // we have to report the raw, physical coords as we want to be
3122 // able to call HitTest(event.m_pointDrag) from the user code to
3123 // get the item being dragged
3124 m_dragStart
= event
.GetPosition();
3129 if (m_dragCount
!= 3)
3132 int command
= event
.RightIsDown() ? wxEVT_COMMAND_LIST_BEGIN_RDRAG
3133 : wxEVT_COMMAND_LIST_BEGIN_DRAG
;
3135 wxListEvent
le( command
, GetParent()->GetId() );
3136 le
.SetEventObject( GetParent() );
3137 le
.m_itemIndex
= m_lineLastClicked
;
3138 le
.m_pointDrag
= m_dragStart
;
3139 GetParent()->GetEventHandler()->ProcessEvent( le
);
3150 // outside of any item
3151 if (event
.RightDown())
3153 SendNotify( (size_t) -1, wxEVT_COMMAND_LIST_ITEM_RIGHT_CLICK
, event
.GetPosition() );
3155 wxContextMenuEvent
evtCtx(
3157 GetParent()->GetId(),
3158 ClientToScreen(event
.GetPosition()));
3159 evtCtx
.SetEventObject(GetParent());
3160 GetParent()->GetEventHandler()->ProcessEvent(evtCtx
);
3164 // reset the selection and bail out
3165 HighlightAll(false);
3171 bool forceClick
= false;
3172 if (event
.ButtonDClick())
3174 if ( m_renameTimer
->IsRunning() )
3175 m_renameTimer
->Stop();
3177 m_lastOnSame
= false;
3179 if ( current
== m_lineLastClicked
)
3181 SendNotify( current
, wxEVT_COMMAND_LIST_ITEM_ACTIVATED
);
3187 // The first click was on another item, so don't interpret this as
3188 // a double click, but as a simple click instead
3195 if (m_lineSelectSingleOnUp
!= (size_t)-1)
3197 // select single line
3198 HighlightAll( false );
3199 ReverseHighlight(m_lineSelectSingleOnUp
);
3204 if ((current
== m_current
) &&
3205 (hitResult
== wxLIST_HITTEST_ONITEMLABEL
) &&
3206 HasFlag(wxLC_EDIT_LABELS
) )
3208 if ( !InReportView() ||
3209 GetLineLabelRect(current
).Contains(x
, y
) )
3211 int dclick
= wxSystemSettings::GetMetric(wxSYS_DCLICK_MSEC
);
3212 m_renameTimer
->Start(dclick
> 0 ? dclick
: 250, true);
3217 m_lastOnSame
= false;
3218 m_lineSelectSingleOnUp
= (size_t)-1;
3222 // This is necessary, because after a DnD operation in
3223 // from and to ourself, the up event is swallowed by the
3224 // DnD code. So on next non-up event (which means here and
3225 // now) m_lineSelectSingleOnUp should be reset.
3226 m_lineSelectSingleOnUp
= (size_t)-1;
3228 if (event
.RightDown())
3230 m_lineBeforeLastClicked
= m_lineLastClicked
;
3231 m_lineLastClicked
= current
;
3233 // If the item is already selected, do not update the selection.
3234 // Multi-selections should not be cleared if a selected item is clicked.
3235 if (!IsHighlighted(current
))
3237 HighlightAll(false);
3238 ChangeCurrent(current
);
3239 ReverseHighlight(m_current
);
3242 SendNotify( current
, wxEVT_COMMAND_LIST_ITEM_RIGHT_CLICK
, event
.GetPosition() );
3244 // Allow generation of context menu event
3247 else if (event
.MiddleDown())
3249 SendNotify( current
, wxEVT_COMMAND_LIST_ITEM_MIDDLE_CLICK
);
3251 else if ( event
.LeftDown() || forceClick
)
3253 m_lineBeforeLastClicked
= m_lineLastClicked
;
3254 m_lineLastClicked
= current
;
3256 size_t oldCurrent
= m_current
;
3257 bool oldWasSelected
= IsHighlighted(m_current
);
3259 bool cmdModifierDown
= event
.CmdDown();
3260 if ( IsSingleSel() || !(cmdModifierDown
|| event
.ShiftDown()) )
3262 if ( IsSingleSel() || !IsHighlighted(current
) )
3264 HighlightAll( false );
3266 ChangeCurrent(current
);
3268 ReverseHighlight(m_current
);
3270 else // multi sel & current is highlighted & no mod keys
3272 m_lineSelectSingleOnUp
= current
;
3273 ChangeCurrent(current
); // change focus
3276 else // multi sel & either ctrl or shift is down
3278 if (cmdModifierDown
)
3280 ChangeCurrent(current
);
3282 ReverseHighlight(m_current
);
3284 else if (event
.ShiftDown())
3286 ChangeCurrent(current
);
3288 size_t lineFrom
= oldCurrent
,
3291 if ( lineTo
< lineFrom
)
3294 lineFrom
= m_current
;
3297 HighlightLines(lineFrom
, lineTo
);
3299 else // !ctrl, !shift
3301 // test in the enclosing if should make it impossible
3302 wxFAIL_MSG( _T("how did we get here?") );
3306 if (m_current
!= oldCurrent
)
3307 RefreshLine( oldCurrent
);
3309 // forceClick is only set if the previous click was on another item
3310 m_lastOnSame
= !forceClick
&& (m_current
== oldCurrent
) && oldWasSelected
;
3314 void wxListMainWindow::MoveToItem(size_t item
)
3316 if ( item
== (size_t)-1 )
3319 wxRect rect
= GetLineRect(item
);
3321 int client_w
, client_h
;
3322 GetClientSize( &client_w
, &client_h
);
3324 const int hLine
= GetLineHeight();
3326 int view_x
= SCROLL_UNIT_X
* GetScrollPos( wxHORIZONTAL
);
3327 int view_y
= hLine
* GetScrollPos( wxVERTICAL
);
3329 if ( InReportView() )
3331 // the next we need the range of lines shown it might be different,
3332 // so recalculate it
3333 ResetVisibleLinesRange();
3335 if (rect
.y
< view_y
)
3336 GetListCtrl()->Scroll( -1, rect
.y
/ hLine
);
3337 if (rect
.y
+ rect
.height
+ 5 > view_y
+ client_h
)
3338 GetListCtrl()->Scroll( -1, (rect
.y
+ rect
.height
- client_h
+ hLine
) / hLine
);
3341 // At least on Mac the visible lines value will get reset inside of
3342 // Scroll *before* it actually scrolls the window because of the
3343 // Update() that happens there, so it will still have the wrong value.
3344 // So let's reset it again and wait for it to be recalculated in the
3345 // next paint event. I would expect this problem to show up in wxGTK
3346 // too but couldn't duplicate it there. Perhaps the order of events
3347 // is different... --Robin
3348 ResetVisibleLinesRange();
3356 if (rect
.x
-view_x
< 5)
3357 sx
= (rect
.x
- 5) / SCROLL_UNIT_X
;
3358 if (rect
.x
+ rect
.width
- 5 > view_x
+ client_w
)
3359 sx
= (rect
.x
+ rect
.width
- client_w
+ SCROLL_UNIT_X
) / SCROLL_UNIT_X
;
3361 if (rect
.y
-view_y
< 5)
3362 sy
= (rect
.y
- 5) / hLine
;
3363 if (rect
.y
+ rect
.height
- 5 > view_y
+ client_h
)
3364 sy
= (rect
.y
+ rect
.height
- client_h
+ hLine
) / hLine
;
3366 GetListCtrl()->Scroll(sx
, sy
);
3370 bool wxListMainWindow::ScrollList(int WXUNUSED(dx
), int dy
)
3372 if ( !InReportView() )
3374 // TODO: this should work in all views but is not implemented now
3379 GetVisibleLinesRange(&top
, &bottom
);
3381 if ( bottom
== (size_t)-1 )
3384 ResetVisibleLinesRange();
3386 int hLine
= GetLineHeight();
3388 GetListCtrl()->Scroll(-1, top
+ dy
/ hLine
);
3391 // see comment in MoveToItem() for why we do this
3392 ResetVisibleLinesRange();
3398 // ----------------------------------------------------------------------------
3399 // keyboard handling
3400 // ----------------------------------------------------------------------------
3402 void wxListMainWindow::OnArrowChar(size_t newCurrent
, const wxKeyEvent
& event
)
3404 wxCHECK_RET( newCurrent
< (size_t)GetItemCount(),
3405 _T("invalid item index in OnArrowChar()") );
3407 size_t oldCurrent
= m_current
;
3409 // in single selection we just ignore Shift as we can't select several
3411 if ( event
.ShiftDown() && !IsSingleSel() )
3413 ChangeCurrent(newCurrent
);
3415 // refresh the old focus to remove it
3416 RefreshLine( oldCurrent
);
3418 // select all the items between the old and the new one
3419 if ( oldCurrent
> newCurrent
)
3421 newCurrent
= oldCurrent
;
3422 oldCurrent
= m_current
;
3425 HighlightLines(oldCurrent
, newCurrent
);
3429 // all previously selected items are unselected unless ctrl is held
3430 // in a multiselection control
3431 if ( !event
.ControlDown() || IsSingleSel() )
3432 HighlightAll(false);
3434 ChangeCurrent(newCurrent
);
3436 // refresh the old focus to remove it
3437 RefreshLine( oldCurrent
);
3439 // in single selection mode we must always have a selected item
3440 if ( !event
.ControlDown() || IsSingleSel() )
3441 HighlightLine( m_current
, true );
3444 RefreshLine( m_current
);
3449 void wxListMainWindow::OnKeyDown( wxKeyEvent
&event
)
3451 wxWindow
*parent
= GetParent();
3453 // propagate the key event upwards
3454 wxKeyEvent
ke(event
);
3455 ke
.SetEventObject( parent
);
3456 if (parent
->GetEventHandler()->ProcessEvent( ke
))
3462 void wxListMainWindow::OnKeyUp( wxKeyEvent
&event
)
3464 wxWindow
*parent
= GetParent();
3466 // propagate the key event upwards
3467 wxKeyEvent
ke(event
);
3468 if (parent
->GetEventHandler()->ProcessEvent( ke
))
3474 void wxListMainWindow::OnChar( wxKeyEvent
&event
)
3476 wxWindow
*parent
= GetParent();
3478 // send a list_key event up
3481 wxListEvent
le( wxEVT_COMMAND_LIST_KEY_DOWN
, GetParent()->GetId() );
3482 le
.m_itemIndex
= m_current
;
3483 GetLine(m_current
)->GetItem( 0, le
.m_item
);
3484 le
.m_code
= event
.GetKeyCode();
3485 le
.SetEventObject( parent
);
3486 parent
->GetEventHandler()->ProcessEvent( le
);
3489 if ( (event
.GetKeyCode() != WXK_UP
) &&
3490 (event
.GetKeyCode() != WXK_DOWN
) &&
3491 (event
.GetKeyCode() != WXK_RIGHT
) &&
3492 (event
.GetKeyCode() != WXK_LEFT
) &&
3493 (event
.GetKeyCode() != WXK_PAGEUP
) &&
3494 (event
.GetKeyCode() != WXK_PAGEDOWN
) &&
3495 (event
.GetKeyCode() != WXK_END
) &&
3496 (event
.GetKeyCode() != WXK_HOME
) )
3498 // propagate the char event upwards
3499 wxKeyEvent
ke(event
);
3500 ke
.SetEventObject( parent
);
3501 if (parent
->GetEventHandler()->ProcessEvent( ke
))
3505 if ( HandleAsNavigationKey(event
) )
3508 // no item -> nothing to do
3515 // don't use m_linesPerPage directly as it might not be computed yet
3516 const int pageSize
= GetCountPerPage();
3517 wxCHECK_RET( pageSize
, _T("should have non zero page size") );
3519 if (GetLayoutDirection() == wxLayout_RightToLeft
)
3521 if (event
.GetKeyCode() == WXK_RIGHT
)
3522 event
.m_keyCode
= WXK_LEFT
;
3523 else if (event
.GetKeyCode() == WXK_LEFT
)
3524 event
.m_keyCode
= WXK_RIGHT
;
3527 switch ( event
.GetKeyCode() )
3530 if ( m_current
> 0 )
3531 OnArrowChar( m_current
- 1, event
);
3535 if ( m_current
< (size_t)GetItemCount() - 1 )
3536 OnArrowChar( m_current
+ 1, event
);
3541 OnArrowChar( GetItemCount() - 1, event
);
3546 OnArrowChar( 0, event
);
3551 int steps
= InReportView() ? pageSize
- 1
3552 : m_current
% pageSize
;
3554 int index
= m_current
- steps
;
3558 OnArrowChar( index
, event
);
3564 int steps
= InReportView()
3566 : pageSize
- (m_current
% pageSize
) - 1;
3568 size_t index
= m_current
+ steps
;
3569 size_t count
= GetItemCount();
3570 if ( index
>= count
)
3573 OnArrowChar( index
, event
);
3578 if ( !InReportView() )
3580 int index
= m_current
- pageSize
;
3584 OnArrowChar( index
, event
);
3589 if ( !InReportView() )
3591 size_t index
= m_current
+ pageSize
;
3593 size_t count
= GetItemCount();
3594 if ( index
>= count
)
3597 OnArrowChar( index
, event
);
3602 if ( IsSingleSel() )
3604 if ( event
.ControlDown() )
3606 ReverseHighlight(m_current
);
3608 else // normal space press
3610 SendNotify( m_current
, wxEVT_COMMAND_LIST_ITEM_ACTIVATED
);
3613 else // multiple selection
3615 ReverseHighlight(m_current
);
3621 SendNotify( m_current
, wxEVT_COMMAND_LIST_ITEM_ACTIVATED
);
3629 // ----------------------------------------------------------------------------
3631 // ----------------------------------------------------------------------------
3633 void wxListMainWindow::OnSetFocus( wxFocusEvent
&WXUNUSED(event
) )
3637 wxFocusEvent
event( wxEVT_SET_FOCUS
, GetParent()->GetId() );
3638 event
.SetEventObject( GetParent() );
3639 if ( GetParent()->GetEventHandler()->ProcessEvent( event
) )
3643 // wxGTK sends us EVT_SET_FOCUS events even if we had never got
3644 // EVT_KILL_FOCUS before which means that we finish by redrawing the items
3645 // which are already drawn correctly resulting in horrible flicker - avoid
3655 void wxListMainWindow::OnKillFocus( wxFocusEvent
&WXUNUSED(event
) )
3659 wxFocusEvent
event( wxEVT_KILL_FOCUS
, GetParent()->GetId() );
3660 event
.SetEventObject( GetParent() );
3661 if ( GetParent()->GetEventHandler()->ProcessEvent( event
) )
3669 void wxListMainWindow::DrawImage( int index
, wxDC
*dc
, int x
, int y
)
3671 if ( HasFlag(wxLC_ICON
) && (m_normal_image_list
))
3673 m_normal_image_list
->Draw( index
, *dc
, x
, y
, wxIMAGELIST_DRAW_TRANSPARENT
);
3675 else if ( HasFlag(wxLC_SMALL_ICON
) && (m_small_image_list
))
3677 m_small_image_list
->Draw( index
, *dc
, x
, y
, wxIMAGELIST_DRAW_TRANSPARENT
);
3679 else if ( HasFlag(wxLC_LIST
) && (m_small_image_list
))
3681 m_small_image_list
->Draw( index
, *dc
, x
, y
, wxIMAGELIST_DRAW_TRANSPARENT
);
3683 else if ( InReportView() && (m_small_image_list
))
3685 m_small_image_list
->Draw( index
, *dc
, x
, y
, wxIMAGELIST_DRAW_TRANSPARENT
);
3689 void wxListMainWindow::GetImageSize( int index
, int &width
, int &height
) const
3691 if ( HasFlag(wxLC_ICON
) && m_normal_image_list
)
3693 m_normal_image_list
->GetSize( index
, width
, height
);
3695 else if ( HasFlag(wxLC_SMALL_ICON
) && m_small_image_list
)
3697 m_small_image_list
->GetSize( index
, width
, height
);
3699 else if ( HasFlag(wxLC_LIST
) && m_small_image_list
)
3701 m_small_image_list
->GetSize( index
, width
, height
);
3703 else if ( InReportView() && m_small_image_list
)
3705 m_small_image_list
->GetSize( index
, width
, height
);
3714 int wxListMainWindow::GetTextLength( const wxString
&s
) const
3716 wxClientDC
dc( wxConstCast(this, wxListMainWindow
) );
3717 dc
.SetFont( GetFont() );
3720 dc
.GetTextExtent( s
, &lw
, NULL
);
3722 return lw
+ AUTOSIZE_COL_MARGIN
;
3725 void wxListMainWindow::SetImageList( wxImageList
*imageList
, int which
)
3729 // calc the spacing from the icon size
3730 int width
= 0, height
= 0;
3732 if ((imageList
) && (imageList
->GetImageCount()) )
3733 imageList
->GetSize(0, width
, height
);
3735 if (which
== wxIMAGE_LIST_NORMAL
)
3737 m_normal_image_list
= imageList
;
3738 m_normal_spacing
= width
+ 8;
3741 if (which
== wxIMAGE_LIST_SMALL
)
3743 m_small_image_list
= imageList
;
3744 m_small_spacing
= width
+ 14;
3745 m_lineHeight
= 0; // ensure that the line height will be recalc'd
3749 void wxListMainWindow::SetItemSpacing( int spacing
, bool isSmall
)
3753 m_small_spacing
= spacing
;
3755 m_normal_spacing
= spacing
;
3758 int wxListMainWindow::GetItemSpacing( bool isSmall
)
3760 return isSmall
? m_small_spacing
: m_normal_spacing
;
3763 // ----------------------------------------------------------------------------
3765 // ----------------------------------------------------------------------------
3767 void wxListMainWindow::SetColumn( int col
, wxListItem
&item
)
3769 wxListHeaderDataList::compatibility_iterator node
= m_columns
.Item( col
);
3771 wxCHECK_RET( node
, _T("invalid column index in SetColumn") );
3773 if ( item
.m_width
== wxLIST_AUTOSIZE_USEHEADER
)
3774 item
.m_width
= GetTextLength( item
.m_text
);
3776 wxListHeaderData
*column
= node
->GetData();
3777 column
->SetItem( item
);
3779 wxListHeaderWindow
*headerWin
= GetListCtrl()->m_headerWin
;
3781 headerWin
->m_dirty
= true;
3785 // invalidate it as it has to be recalculated
3789 void wxListMainWindow::SetColumnWidth( int col
, int width
)
3791 wxCHECK_RET( col
>= 0 && col
< GetColumnCount(),
3792 _T("invalid column index") );
3794 wxCHECK_RET( InReportView(),
3795 _T("SetColumnWidth() can only be called in report mode.") );
3799 wxListHeaderWindow
*headerWin
= GetListCtrl()->m_headerWin
;
3801 headerWin
->m_dirty
= true;
3803 wxListHeaderDataList::compatibility_iterator node
= m_columns
.Item( col
);
3804 wxCHECK_RET( node
, _T("no column?") );
3806 wxListHeaderData
*column
= node
->GetData();
3808 size_t count
= GetItemCount();
3810 if (width
== wxLIST_AUTOSIZE_USEHEADER
)
3812 width
= GetTextLength(column
->GetText());
3813 width
+= 2*EXTRA_WIDTH
;
3815 // check for column header's image availability
3816 const int image
= column
->GetImage();
3819 if ( m_small_image_list
)
3822 m_small_image_list
->GetSize(image
, ix
, iy
);
3823 width
+= ix
+ HEADER_IMAGE_MARGIN_IN_REPORT_MODE
;
3827 else if ( width
== wxLIST_AUTOSIZE
)
3831 // TODO: determine the max width somehow...
3832 width
= WIDTH_COL_DEFAULT
;
3836 wxClientDC
dc(this);
3837 dc
.SetFont( GetFont() );
3839 int max
= AUTOSIZE_COL_MARGIN
;
3841 // if the cached column width isn't valid then recalculate it
3842 if (m_aColWidths
.Item(col
)->bNeedsUpdate
)
3844 for (size_t i
= 0; i
< count
; i
++)
3846 wxListLineData
*line
= GetLine( i
);
3847 wxListItemDataList::compatibility_iterator n
= line
->m_items
.Item( col
);
3849 wxCHECK_RET( n
, _T("no subitem?") );
3851 wxListItemData
*itemData
= n
->GetData();
3854 itemData
->GetItem(item
);
3855 int itemWidth
= GetItemWidthWithImage(&item
);
3856 if (itemWidth
> max
)
3860 m_aColWidths
.Item(col
)->bNeedsUpdate
= false;
3861 m_aColWidths
.Item(col
)->nMaxWidth
= max
;
3864 max
= m_aColWidths
.Item(col
)->nMaxWidth
;
3865 width
= max
+ AUTOSIZE_COL_MARGIN
;
3869 column
->SetWidth( width
);
3871 // invalidate it as it has to be recalculated
3875 int wxListMainWindow::GetHeaderWidth() const
3877 if ( !m_headerWidth
)
3879 wxListMainWindow
*self
= wxConstCast(this, wxListMainWindow
);
3881 size_t count
= GetColumnCount();
3882 for ( size_t col
= 0; col
< count
; col
++ )
3884 self
->m_headerWidth
+= GetColumnWidth(col
);
3888 return m_headerWidth
;
3891 void wxListMainWindow::GetColumn( int col
, wxListItem
&item
) const
3893 wxListHeaderDataList::compatibility_iterator node
= m_columns
.Item( col
);
3894 wxCHECK_RET( node
, _T("invalid column index in GetColumn") );
3896 wxListHeaderData
*column
= node
->GetData();
3897 column
->GetItem( item
);
3900 int wxListMainWindow::GetColumnWidth( int col
) const
3902 wxListHeaderDataList::compatibility_iterator node
= m_columns
.Item( col
);
3903 wxCHECK_MSG( node
, 0, _T("invalid column index") );
3905 wxListHeaderData
*column
= node
->GetData();
3906 return column
->GetWidth();
3909 // ----------------------------------------------------------------------------
3911 // ----------------------------------------------------------------------------
3913 void wxListMainWindow::SetItem( wxListItem
&item
)
3915 long id
= item
.m_itemId
;
3916 wxCHECK_RET( id
>= 0 && (size_t)id
< GetItemCount(),
3917 _T("invalid item index in SetItem") );
3921 wxListLineData
*line
= GetLine((size_t)id
);
3922 line
->SetItem( item
.m_col
, item
);
3924 // Set item state if user wants
3925 if ( item
.m_mask
& wxLIST_MASK_STATE
)
3926 SetItemState( item
.m_itemId
, item
.m_state
, item
.m_state
);
3930 // update the Max Width Cache if needed
3931 int width
= GetItemWidthWithImage(&item
);
3933 if (width
> m_aColWidths
.Item(item
.m_col
)->nMaxWidth
)
3934 m_aColWidths
.Item(item
.m_col
)->nMaxWidth
= width
;
3938 // update the item on screen
3940 GetItemRect(id
, rectItem
);
3941 RefreshRect(rectItem
);
3944 void wxListMainWindow::SetItemStateAll(long state
, long stateMask
)
3949 // first deal with selection
3950 if ( stateMask
& wxLIST_STATE_SELECTED
)
3952 // set/clear select state
3955 // optimized version for virtual listctrl.
3956 m_selStore
.SelectRange(0, GetItemCount() - 1, state
== wxLIST_STATE_SELECTED
);
3959 else if ( state
& wxLIST_STATE_SELECTED
)
3961 const long count
= GetItemCount();
3962 for( long i
= 0; i
< count
; i
++ )
3964 SetItemState( i
, wxLIST_STATE_SELECTED
, wxLIST_STATE_SELECTED
);
3970 // clear for non virtual (somewhat optimized by using GetNextItem())
3972 while ( (i
= GetNextItem(i
, wxLIST_NEXT_ALL
, wxLIST_STATE_SELECTED
)) != -1 )
3974 SetItemState( i
, 0, wxLIST_STATE_SELECTED
);
3979 if ( HasCurrent() && (state
== 0) && (stateMask
& wxLIST_STATE_FOCUSED
) )
3981 // unfocus all: only one item can be focussed, so clearing focus for
3982 // all items is simply clearing focus of the focussed item.
3983 SetItemState(m_current
, state
, stateMask
);
3985 //(setting focus to all items makes no sense, so it is not handled here.)
3988 void wxListMainWindow::SetItemState( long litem
, long state
, long stateMask
)
3992 SetItemStateAll(state
, stateMask
);
3996 wxCHECK_RET( litem
>= 0 && (size_t)litem
< GetItemCount(),
3997 _T("invalid list ctrl item index in SetItem") );
3999 size_t oldCurrent
= m_current
;
4000 size_t item
= (size_t)litem
; // safe because of the check above
4002 // do we need to change the focus?
4003 if ( stateMask
& wxLIST_STATE_FOCUSED
)
4005 if ( state
& wxLIST_STATE_FOCUSED
)
4007 // don't do anything if this item is already focused
4008 if ( item
!= m_current
)
4010 ChangeCurrent(item
);
4012 if ( oldCurrent
!= (size_t)-1 )
4014 if ( IsSingleSel() )
4016 HighlightLine(oldCurrent
, false);
4019 RefreshLine(oldCurrent
);
4022 RefreshLine( m_current
);
4027 // don't do anything if this item is not focused
4028 if ( item
== m_current
)
4032 if ( IsSingleSel() )
4034 // we must unselect the old current item as well or we
4035 // might end up with more than one selected item in a
4036 // single selection control
4037 HighlightLine(oldCurrent
, false);
4040 RefreshLine( oldCurrent
);
4045 // do we need to change the selection state?
4046 if ( stateMask
& wxLIST_STATE_SELECTED
)
4048 bool on
= (state
& wxLIST_STATE_SELECTED
) != 0;
4050 if ( IsSingleSel() )
4054 // selecting the item also makes it the focused one in the
4056 if ( m_current
!= item
)
4058 ChangeCurrent(item
);
4060 if ( oldCurrent
!= (size_t)-1 )
4062 HighlightLine( oldCurrent
, false );
4063 RefreshLine( oldCurrent
);
4069 // only the current item may be selected anyhow
4070 if ( item
!= m_current
)
4075 if ( HighlightLine(item
, on
) )
4082 int wxListMainWindow::GetItemState( long item
, long stateMask
) const
4084 wxCHECK_MSG( item
>= 0 && (size_t)item
< GetItemCount(), 0,
4085 _T("invalid list ctrl item index in GetItemState()") );
4087 int ret
= wxLIST_STATE_DONTCARE
;
4089 if ( stateMask
& wxLIST_STATE_FOCUSED
)
4091 if ( (size_t)item
== m_current
)
4092 ret
|= wxLIST_STATE_FOCUSED
;
4095 if ( stateMask
& wxLIST_STATE_SELECTED
)
4097 if ( IsHighlighted(item
) )
4098 ret
|= wxLIST_STATE_SELECTED
;
4104 void wxListMainWindow::GetItem( wxListItem
&item
) const
4106 wxCHECK_RET( item
.m_itemId
>= 0 && (size_t)item
.m_itemId
< GetItemCount(),
4107 _T("invalid item index in GetItem") );
4109 wxListLineData
*line
= GetLine((size_t)item
.m_itemId
);
4110 line
->GetItem( item
.m_col
, item
);
4112 // Get item state if user wants it
4113 if ( item
.m_mask
& wxLIST_MASK_STATE
)
4114 item
.m_state
= GetItemState( item
.m_itemId
, wxLIST_STATE_SELECTED
|
4115 wxLIST_STATE_FOCUSED
);
4118 // ----------------------------------------------------------------------------
4120 // ----------------------------------------------------------------------------
4122 size_t wxListMainWindow::GetItemCount() const
4124 return IsVirtual() ? m_countVirt
: m_lines
.GetCount();
4127 void wxListMainWindow::SetItemCount(long count
)
4129 m_selStore
.SetItemCount(count
);
4130 m_countVirt
= count
;
4132 ResetVisibleLinesRange();
4134 // scrollbars must be reset
4138 int wxListMainWindow::GetSelectedItemCount() const
4140 // deal with the quick case first
4141 if ( IsSingleSel() )
4142 return HasCurrent() ? IsHighlighted(m_current
) : false;
4144 // virtual controls remmebers all its selections itself
4146 return m_selStore
.GetSelectedCount();
4148 // TODO: we probably should maintain the number of items selected even for
4149 // non virtual controls as enumerating all lines is really slow...
4150 size_t countSel
= 0;
4151 size_t count
= GetItemCount();
4152 for ( size_t line
= 0; line
< count
; line
++ )
4154 if ( GetLine(line
)->IsHighlighted() )
4161 // ----------------------------------------------------------------------------
4162 // item position/size
4163 // ----------------------------------------------------------------------------
4165 wxRect
wxListMainWindow::GetViewRect() const
4167 wxASSERT_MSG( !HasFlag(wxLC_LIST
), "not implemented for list view" );
4169 // we need to find the longest/tallest label
4170 wxCoord xMax
= 0, yMax
= 0;
4171 const int count
= GetItemCount();
4174 for ( int i
= 0; i
< count
; i
++ )
4176 // we need logical, not physical, coordinates here, so use
4177 // GetLineRect() instead of GetItemRect()
4178 wxRect r
= GetLineRect(i
);
4180 wxCoord x
= r
.GetRight(),
4190 // some fudge needed to make it look prettier
4191 xMax
+= 2 * EXTRA_BORDER_X
;
4192 yMax
+= 2 * EXTRA_BORDER_Y
;
4194 // account for the scrollbars if necessary
4195 const wxSize sizeAll
= GetClientSize();
4196 if ( xMax
> sizeAll
.x
)
4197 yMax
+= wxSystemSettings::GetMetric(wxSYS_HSCROLL_Y
);
4198 if ( yMax
> sizeAll
.y
)
4199 xMax
+= wxSystemSettings::GetMetric(wxSYS_VSCROLL_X
);
4201 return wxRect(0, 0, xMax
, yMax
);
4205 wxListMainWindow::GetSubItemRect(long item
, long subItem
, wxRect
& rect
) const
4207 wxCHECK_MSG( subItem
== wxLIST_GETSUBITEMRECT_WHOLEITEM
|| InReportView(),
4209 _T("GetSubItemRect only meaningful in report view") );
4210 wxCHECK_MSG( item
>= 0 && (size_t)item
< GetItemCount(), false,
4211 _T("invalid item in GetSubItemRect") );
4213 // ensure that we're laid out, otherwise we could return nonsense
4216 wxConstCast(this, wxListMainWindow
)->
4217 RecalculatePositions(true /* no refresh */);
4220 rect
= GetLineRect((size_t)item
);
4222 // Adjust rect to specified column
4223 if ( subItem
!= wxLIST_GETSUBITEMRECT_WHOLEITEM
)
4225 wxCHECK_MSG( subItem
>= 0 && subItem
< GetColumnCount(), false,
4226 _T("invalid subItem in GetSubItemRect") );
4228 for (int i
= 0; i
< subItem
; i
++)
4230 rect
.x
+= GetColumnWidth(i
);
4232 rect
.width
= GetColumnWidth(subItem
);
4235 GetListCtrl()->CalcScrolledPosition(rect
.x
, rect
.y
, &rect
.x
, &rect
.y
);
4240 bool wxListMainWindow::GetItemPosition(long item
, wxPoint
& pos
) const
4243 GetItemRect(item
, rect
);
4251 // ----------------------------------------------------------------------------
4252 // geometry calculation
4253 // ----------------------------------------------------------------------------
4255 void wxListMainWindow::RecalculatePositions(bool noRefresh
)
4257 const int lineHeight
= GetLineHeight();
4259 wxClientDC
dc( this );
4260 dc
.SetFont( GetFont() );
4262 const size_t count
= GetItemCount();
4265 if ( HasFlag(wxLC_ICON
) && m_normal_image_list
)
4266 iconSpacing
= m_normal_spacing
;
4267 else if ( HasFlag(wxLC_SMALL_ICON
) && m_small_image_list
)
4268 iconSpacing
= m_small_spacing
;
4272 // Note that we do not call GetClientSize() here but
4273 // GetSize() and subtract the border size for sunken
4274 // borders manually. This is technically incorrect,
4275 // but we need to know the client area's size WITHOUT
4276 // scrollbars here. Since we don't know if there are
4277 // any scrollbars, we use GetSize() instead. Another
4278 // solution would be to call SetScrollbars() here to
4279 // remove the scrollbars and call GetClientSize() then,
4280 // but this might result in flicker and - worse - will
4281 // reset the scrollbars to 0 which is not good at all
4282 // if you resize a dialog/window, but don't want to
4283 // reset the window scrolling. RR.
4284 // Furthermore, we actually do NOT subtract the border
4285 // width as 2 pixels is just the extra space which we
4286 // need around the actual content in the window. Other-
4287 // wise the text would e.g. touch the upper border. RR.
4290 GetSize( &clientWidth
, &clientHeight
);
4292 if ( InReportView() )
4294 // all lines have the same height and we scroll one line per step
4295 int entireHeight
= count
* lineHeight
+ LINE_SPACING
;
4297 m_linesPerPage
= clientHeight
/ lineHeight
;
4299 ResetVisibleLinesRange();
4301 GetListCtrl()->SetScrollbars( SCROLL_UNIT_X
, lineHeight
,
4302 GetHeaderWidth() / SCROLL_UNIT_X
,
4303 (entireHeight
+ lineHeight
- 1) / lineHeight
,
4304 GetListCtrl()->GetScrollPos(wxHORIZONTAL
),
4305 GetListCtrl()->GetScrollPos(wxVERTICAL
),
4310 // we have 3 different layout strategies: either layout all items
4311 // horizontally/vertically (wxLC_ALIGN_XXX styles explicitly given) or
4312 // to arrange them in top to bottom, left to right (don't ask me why
4313 // not the other way round...) order
4314 if ( HasFlag(wxLC_ALIGN_LEFT
| wxLC_ALIGN_TOP
) )
4316 int x
= EXTRA_BORDER_X
;
4317 int y
= EXTRA_BORDER_Y
;
4319 wxCoord widthMax
= 0;
4322 for ( i
= 0; i
< count
; i
++ )
4324 wxListLineData
*line
= GetLine(i
);
4325 line
->CalculateSize( &dc
, iconSpacing
);
4326 line
->SetPosition( x
, y
, iconSpacing
);
4328 wxSize sizeLine
= GetLineSize(i
);
4330 if ( HasFlag(wxLC_ALIGN_TOP
) )
4332 if ( sizeLine
.x
> widthMax
)
4333 widthMax
= sizeLine
.x
;
4337 else // wxLC_ALIGN_LEFT
4339 x
+= sizeLine
.x
+ MARGIN_BETWEEN_ROWS
;
4343 if ( HasFlag(wxLC_ALIGN_TOP
) )
4345 // traverse the items again and tweak their sizes so that they are
4346 // all the same in a row
4347 for ( i
= 0; i
< count
; i
++ )
4349 wxListLineData
*line
= GetLine(i
);
4350 line
->m_gi
->ExtendWidth(widthMax
);
4354 GetListCtrl()->SetScrollbars
4358 (x
+ SCROLL_UNIT_X
) / SCROLL_UNIT_X
,
4359 (y
+ lineHeight
) / lineHeight
,
4360 GetListCtrl()->GetScrollPos( wxHORIZONTAL
),
4361 GetListCtrl()->GetScrollPos( wxVERTICAL
),
4365 else // "flowed" arrangement, the most complicated case
4367 // at first we try without any scrollbars, if the items don't fit into
4368 // the window, we recalculate after subtracting the space taken by the
4371 int entireWidth
= 0;
4373 for (int tries
= 0; tries
< 2; tries
++)
4375 entireWidth
= 2 * EXTRA_BORDER_X
;
4379 // Now we have decided that the items do not fit into the
4380 // client area, so we need a scrollbar
4381 entireWidth
+= SCROLL_UNIT_X
;
4384 int x
= EXTRA_BORDER_X
;
4385 int y
= EXTRA_BORDER_Y
;
4386 int maxWidthInThisRow
= 0;
4389 int currentlyVisibleLines
= 0;
4391 for (size_t i
= 0; i
< count
; i
++)
4393 currentlyVisibleLines
++;
4394 wxListLineData
*line
= GetLine( i
);
4395 line
->CalculateSize( &dc
, iconSpacing
);
4396 line
->SetPosition( x
, y
, iconSpacing
);
4398 wxSize sizeLine
= GetLineSize( i
);
4400 if ( maxWidthInThisRow
< sizeLine
.x
)
4401 maxWidthInThisRow
= sizeLine
.x
;
4404 if (currentlyVisibleLines
> m_linesPerPage
)
4405 m_linesPerPage
= currentlyVisibleLines
;
4407 if ( y
+ sizeLine
.y
>= clientHeight
)
4409 currentlyVisibleLines
= 0;
4411 maxWidthInThisRow
+= MARGIN_BETWEEN_ROWS
;
4412 x
+= maxWidthInThisRow
;
4413 entireWidth
+= maxWidthInThisRow
;
4414 maxWidthInThisRow
= 0;
4417 // We have reached the last item.
4418 if ( i
== count
- 1 )
4419 entireWidth
+= maxWidthInThisRow
;
4421 if ( (tries
== 0) &&
4422 (entireWidth
+ SCROLL_UNIT_X
> clientWidth
) )
4424 clientHeight
-= wxSystemSettings::
4425 GetMetric(wxSYS_HSCROLL_Y
);
4430 if ( i
== count
- 1 )
4431 tries
= 1; // Everything fits, no second try required.
4435 GetListCtrl()->SetScrollbars
4439 (entireWidth
+ SCROLL_UNIT_X
) / SCROLL_UNIT_X
,
4441 GetListCtrl()->GetScrollPos( wxHORIZONTAL
),
4450 // FIXME: why should we call it from here?
4457 void wxListMainWindow::RefreshAll()
4462 wxListHeaderWindow
*headerWin
= GetListCtrl()->m_headerWin
;
4463 if ( headerWin
&& headerWin
->m_dirty
)
4465 headerWin
->m_dirty
= false;
4466 headerWin
->Refresh();
4470 void wxListMainWindow::UpdateCurrent()
4472 if ( !HasCurrent() && !IsEmpty() )
4476 long wxListMainWindow::GetNextItem( long item
,
4477 int WXUNUSED(geometry
),
4481 max
= GetItemCount();
4482 wxCHECK_MSG( (ret
== -1) || (ret
< max
), -1,
4483 _T("invalid listctrl index in GetNextItem()") );
4485 // notice that we start with the next item (or the first one if item == -1)
4486 // and this is intentional to allow writing a simple loop to iterate over
4487 // all selected items
4490 // this is not an error because the index was OK initially,
4491 // just no such item
4498 size_t count
= GetItemCount();
4499 for ( size_t line
= (size_t)ret
; line
< count
; line
++ )
4501 if ( (state
& wxLIST_STATE_FOCUSED
) && (line
== m_current
) )
4504 if ( (state
& wxLIST_STATE_SELECTED
) && IsHighlighted(line
) )
4511 // ----------------------------------------------------------------------------
4513 // ----------------------------------------------------------------------------
4515 void wxListMainWindow::DeleteItem( long lindex
)
4517 size_t count
= GetItemCount();
4519 wxCHECK_RET( (lindex
>= 0) && ((size_t)lindex
< count
),
4520 _T("invalid item index in DeleteItem") );
4522 size_t index
= (size_t)lindex
;
4524 // we don't need to adjust the index for the previous items
4525 if ( HasCurrent() && m_current
>= index
)
4527 // if the current item is being deleted, we want the next one to
4528 // become selected - unless there is no next one - so don't adjust
4529 // m_current in this case
4530 if ( m_current
!= index
|| m_current
== count
- 1 )
4534 if ( InReportView() )
4536 // mark the Column Max Width cache as dirty if the items in the line
4537 // we're deleting contain the Max Column Width
4538 wxListLineData
* const line
= GetLine(index
);
4539 wxListItemDataList::compatibility_iterator n
;
4540 wxListItemData
*itemData
;
4544 for (size_t i
= 0; i
< m_columns
.GetCount(); i
++)
4546 n
= line
->m_items
.Item( i
);
4547 itemData
= n
->GetData();
4548 itemData
->GetItem(item
);
4550 itemWidth
= GetItemWidthWithImage(&item
);
4552 if (itemWidth
>= m_aColWidths
.Item(i
)->nMaxWidth
)
4553 m_aColWidths
.Item(i
)->bNeedsUpdate
= true;
4556 ResetVisibleLinesRange();
4559 SendNotify( index
, wxEVT_COMMAND_LIST_DELETE_ITEM
, wxDefaultPosition
);
4564 m_selStore
.OnItemDelete(index
);
4568 m_lines
.RemoveAt( index
);
4571 // we need to refresh the (vert) scrollbar as the number of items changed
4574 RefreshAfter(index
);
4577 void wxListMainWindow::DeleteColumn( int col
)
4579 wxListHeaderDataList::compatibility_iterator node
= m_columns
.Item( col
);
4581 wxCHECK_RET( node
, wxT("invalid column index in DeleteColumn()") );
4584 delete node
->GetData();
4585 m_columns
.Erase( node
);
4589 // update all the items
4590 for ( size_t i
= 0; i
< m_lines
.GetCount(); i
++ )
4592 wxListLineData
* const line
= GetLine(i
);
4593 wxListItemDataList::compatibility_iterator n
= line
->m_items
.Item( col
);
4594 delete n
->GetData();
4595 line
->m_items
.Erase(n
);
4599 if ( InReportView() ) // we only cache max widths when in Report View
4601 delete m_aColWidths
.Item(col
);
4602 m_aColWidths
.RemoveAt(col
);
4605 // invalidate it as it has to be recalculated
4609 void wxListMainWindow::DoDeleteAllItems()
4612 // nothing to do - in particular, don't send the event
4617 // to make the deletion of all items faster, we don't send the
4618 // notifications for each item deletion in this case but only one event
4619 // for all of them: this is compatible with wxMSW and documented in
4620 // DeleteAllItems() description
4622 wxListEvent
event( wxEVT_COMMAND_LIST_DELETE_ALL_ITEMS
, GetParent()->GetId() );
4623 event
.SetEventObject( GetParent() );
4624 GetParent()->GetEventHandler()->ProcessEvent( event
);
4632 if ( InReportView() )
4634 ResetVisibleLinesRange();
4635 for (size_t i
= 0; i
< m_aColWidths
.GetCount(); i
++)
4637 m_aColWidths
.Item(i
)->bNeedsUpdate
= true;
4644 void wxListMainWindow::DeleteAllItems()
4648 RecalculatePositions();
4651 void wxListMainWindow::DeleteEverything()
4653 WX_CLEAR_LIST(wxListHeaderDataList
, m_columns
);
4654 WX_CLEAR_ARRAY(m_aColWidths
);
4659 // ----------------------------------------------------------------------------
4660 // scanning for an item
4661 // ----------------------------------------------------------------------------
4663 void wxListMainWindow::EnsureVisible( long index
)
4665 wxCHECK_RET( index
>= 0 && (size_t)index
< GetItemCount(),
4666 _T("invalid index in EnsureVisible") );
4668 // We have to call this here because the label in question might just have
4669 // been added and its position is not known yet
4671 RecalculatePositions(true /* no refresh */);
4673 MoveToItem((size_t)index
);
4676 long wxListMainWindow::FindItem(long start
, const wxString
& str
, bool partial
)
4682 wxString str_upper
= str
.Upper();
4686 size_t count
= GetItemCount();
4687 for ( size_t i
= (size_t)pos
; i
< count
; i
++ )
4689 wxListLineData
*line
= GetLine(i
);
4690 wxString line_upper
= line
->GetText(0).Upper();
4693 if (line_upper
== str_upper
)
4698 if (line_upper
.find(str_upper
) == 0)
4706 long wxListMainWindow::FindItem(long start
, wxUIntPtr data
)
4712 size_t count
= GetItemCount();
4713 for (size_t i
= (size_t)pos
; i
< count
; i
++)
4715 wxListLineData
*line
= GetLine(i
);
4717 line
->GetItem( 0, item
);
4718 if (item
.m_data
== data
)
4725 long wxListMainWindow::FindItem( const wxPoint
& pt
)
4728 GetVisibleLinesRange( &topItem
, NULL
);
4731 GetItemPosition( GetItemCount() - 1, p
);
4735 long id
= (long)floor( pt
.y
* double(GetItemCount() - topItem
- 1) / p
.y
+ topItem
);
4736 if ( id
>= 0 && id
< (long)GetItemCount() )
4742 long wxListMainWindow::HitTest( int x
, int y
, int &flags
) const
4744 GetListCtrl()->CalcUnscrolledPosition( x
, y
, &x
, &y
);
4746 size_t count
= GetItemCount();
4748 if ( InReportView() )
4750 size_t current
= y
/ GetLineHeight();
4751 if ( current
< count
)
4753 flags
= HitTestLine(current
, x
, y
);
4760 // TODO: optimize it too! this is less simple than for report view but
4761 // enumerating all items is still not a way to do it!!
4762 for ( size_t current
= 0; current
< count
; current
++ )
4764 flags
= HitTestLine(current
, x
, y
);
4773 // ----------------------------------------------------------------------------
4775 // ----------------------------------------------------------------------------
4777 void wxListMainWindow::InsertItem( wxListItem
&item
)
4779 wxASSERT_MSG( !IsVirtual(), _T("can't be used with virtual control") );
4781 int count
= GetItemCount();
4782 wxCHECK_RET( item
.m_itemId
>= 0, _T("invalid item index") );
4784 if (item
.m_itemId
> count
)
4785 item
.m_itemId
= count
;
4787 size_t id
= item
.m_itemId
;
4791 if ( InReportView() )
4793 ResetVisibleLinesRange();
4795 // calculate the width of the item and adjust the max column width
4796 wxColWidthInfo
*pWidthInfo
= m_aColWidths
.Item(item
.GetColumn());
4797 int width
= GetItemWidthWithImage(&item
);
4798 item
.SetWidth(width
);
4799 if (width
> pWidthInfo
->nMaxWidth
)
4800 pWidthInfo
->nMaxWidth
= width
;
4803 wxListLineData
*line
= new wxListLineData(this);
4805 line
->SetItem( item
.m_col
, item
);
4807 m_lines
.Insert( line
, id
);
4811 // If an item is selected at or below the point of insertion, we need to
4812 // increment the member variables because the current row's index has gone
4814 if ( HasCurrent() && m_current
>= id
)
4817 SendNotify(id
, wxEVT_COMMAND_LIST_INSERT_ITEM
);
4819 RefreshLines(id
, GetItemCount() - 1);
4822 void wxListMainWindow::InsertColumn( long col
, wxListItem
&item
)
4825 if ( InReportView() )
4827 if (item
.m_width
== wxLIST_AUTOSIZE_USEHEADER
)
4828 item
.m_width
= GetTextLength( item
.m_text
);
4830 wxListHeaderData
*column
= new wxListHeaderData( item
);
4831 wxColWidthInfo
*colWidthInfo
= new wxColWidthInfo();
4833 bool insert
= (col
>= 0) && ((size_t)col
< m_columns
.GetCount());
4836 wxListHeaderDataList::compatibility_iterator
4837 node
= m_columns
.Item( col
);
4838 m_columns
.Insert( node
, column
);
4839 m_aColWidths
.Insert( colWidthInfo
, col
);
4843 m_columns
.Append( column
);
4844 m_aColWidths
.Add( colWidthInfo
);
4849 // update all the items
4850 for ( size_t i
= 0; i
< m_lines
.GetCount(); i
++ )
4852 wxListLineData
* const line
= GetLine(i
);
4853 wxListItemData
* const data
= new wxListItemData(this);
4855 line
->m_items
.Insert(col
, data
);
4857 line
->m_items
.Append(data
);
4861 // invalidate it as it has to be recalculated
4866 int wxListMainWindow::GetItemWidthWithImage(wxListItem
* item
)
4869 wxClientDC
dc(this);
4871 dc
.SetFont( GetFont() );
4873 if (item
->GetImage() != -1)
4876 GetImageSize( item
->GetImage(), ix
, iy
);
4880 if (!item
->GetText().empty())
4883 dc
.GetTextExtent( item
->GetText(), &w
, NULL
);
4890 // ----------------------------------------------------------------------------
4892 // ----------------------------------------------------------------------------
4894 static wxListCtrlCompare list_ctrl_compare_func_2
;
4895 static long list_ctrl_compare_data
;
4897 int LINKAGEMODE
list_ctrl_compare_func_1( wxListLineData
**arg1
, wxListLineData
**arg2
)
4899 wxListLineData
*line1
= *arg1
;
4900 wxListLineData
*line2
= *arg2
;
4902 line1
->GetItem( 0, item
);
4903 wxUIntPtr data1
= item
.m_data
;
4904 line2
->GetItem( 0, item
);
4905 wxUIntPtr data2
= item
.m_data
;
4906 return list_ctrl_compare_func_2( data1
, data2
, list_ctrl_compare_data
);
4909 void wxListMainWindow::SortItems( wxListCtrlCompare fn
, long data
)
4911 // selections won't make sense any more after sorting the items so reset
4913 HighlightAll(false);
4916 list_ctrl_compare_func_2
= fn
;
4917 list_ctrl_compare_data
= data
;
4918 m_lines
.Sort( list_ctrl_compare_func_1
);
4922 // ----------------------------------------------------------------------------
4924 // ----------------------------------------------------------------------------
4926 void wxListMainWindow::OnScroll(wxScrollWinEvent
& event
)
4928 // update our idea of which lines are shown when we redraw the window the
4930 ResetVisibleLinesRange();
4932 if ( event
.GetOrientation() == wxHORIZONTAL
&& HasHeader() )
4934 wxGenericListCtrl
* lc
= GetListCtrl();
4935 wxCHECK_RET( lc
, _T("no listctrl window?") );
4937 lc
->m_headerWin
->Refresh();
4938 lc
->m_headerWin
->Update();
4942 int wxListMainWindow::GetCountPerPage() const
4944 if ( !m_linesPerPage
)
4946 wxConstCast(this, wxListMainWindow
)->
4947 m_linesPerPage
= GetClientSize().y
/ GetLineHeight();
4950 return m_linesPerPage
;
4953 void wxListMainWindow::GetVisibleLinesRange(size_t *from
, size_t *to
)
4955 wxASSERT_MSG( InReportView(), _T("this is for report mode only") );
4957 if ( m_lineFrom
== (size_t)-1 )
4959 size_t count
= GetItemCount();
4962 m_lineFrom
= GetScrollPos(wxVERTICAL
);
4964 // this may happen if SetScrollbars() hadn't been called yet
4965 if ( m_lineFrom
>= count
)
4966 m_lineFrom
= count
- 1;
4968 // we redraw one extra line but this is needed to make the redrawing
4969 // logic work when there is a fractional number of lines on screen
4970 m_lineTo
= m_lineFrom
+ m_linesPerPage
;
4971 if ( m_lineTo
>= count
)
4972 m_lineTo
= count
- 1;
4974 else // empty control
4977 m_lineTo
= (size_t)-1;
4981 wxASSERT_MSG( IsEmpty() ||
4982 (m_lineFrom
<= m_lineTo
&& m_lineTo
< GetItemCount()),
4983 _T("GetVisibleLinesRange() returns incorrect result") );
4991 // -------------------------------------------------------------------------------------
4992 // wxGenericListCtrl
4993 // -------------------------------------------------------------------------------------
4995 IMPLEMENT_DYNAMIC_CLASS(wxGenericListCtrl
, wxControl
)
4997 BEGIN_EVENT_TABLE(wxGenericListCtrl
,wxControl
)
4998 EVT_SIZE(wxGenericListCtrl::OnSize
)
4999 EVT_SCROLLWIN(wxGenericListCtrl::OnScroll
)
5002 void wxGenericListCtrl::Init()
5004 m_imageListNormal
= NULL
;
5005 m_imageListSmall
= NULL
;
5006 m_imageListState
= NULL
;
5008 m_ownsImageListNormal
=
5009 m_ownsImageListSmall
=
5010 m_ownsImageListState
= false;
5014 m_headerHeight
= wxRendererNative::Get().GetHeaderButtonHeight(this);
5017 wxGenericListCtrl::~wxGenericListCtrl()
5019 if (m_ownsImageListNormal
)
5020 delete m_imageListNormal
;
5021 if (m_ownsImageListSmall
)
5022 delete m_imageListSmall
;
5023 if (m_ownsImageListState
)
5024 delete m_imageListState
;
5027 void wxGenericListCtrl::CreateOrDestroyHeaderWindowAsNeeded()
5029 bool needs_header
= HasHeader();
5030 bool has_header
= (m_headerWin
!= NULL
);
5032 if (needs_header
== has_header
)
5037 m_headerWin
= new wxListHeaderWindow
5039 this, wxID_ANY
, m_mainWin
,
5041 wxSize(GetClientSize().x
, m_headerHeight
),
5045 #if defined( __WXMAC__ ) && wxOSX_USE_COCOA_OR_CARBON
5047 #if wxOSX_USE_ATSU_TEXT
5048 font
.MacCreateFromThemeFont( kThemeSmallSystemFont
);
5050 font
.MacCreateFromUIFont( kCTFontSystemFontType
);
5052 m_headerWin
->SetFont( font
);
5055 GetSizer()->Prepend( m_headerWin
, 0, wxGROW
);
5059 GetSizer()->Detach( m_headerWin
);
5067 bool wxGenericListCtrl::Create(wxWindow
*parent
,
5072 const wxValidator
&validator
,
5073 const wxString
&name
)
5077 // just like in other ports, an assert will fail if the user doesn't give any type style:
5078 wxASSERT_MSG( (style
& wxLC_MASK_TYPE
),
5079 _T("wxListCtrl style should have exactly one mode bit set") );
5081 if ( !wxControl::Create( parent
, id
, pos
, size
, style
|wxVSCROLL
|wxHSCROLL
, validator
, name
) )
5085 style
&= ~wxBORDER_MASK
;
5086 style
|= wxBORDER_THEME
;
5089 m_mainWin
= new wxListMainWindow( this, wxID_ANY
, wxPoint(0, 0), size
, style
);
5091 SetTargetWindow( m_mainWin
);
5093 wxBoxSizer
*sizer
= new wxBoxSizer( wxVERTICAL
);
5094 sizer
->Add( m_mainWin
, 1, wxGROW
);
5097 CreateOrDestroyHeaderWindowAsNeeded();
5099 SetInitialSize(size
);
5104 wxBorder
wxGenericListCtrl::GetDefaultBorder() const
5106 return wxBORDER_THEME
;
5110 WXLRESULT
wxGenericListCtrl::MSWWindowProc(WXUINT nMsg
,
5114 WXLRESULT rc
= wxControl::MSWWindowProc(nMsg
, wParam
, lParam
);
5117 // we need to process arrows ourselves for scrolling
5118 if ( nMsg
== WM_GETDLGCODE
)
5120 rc
|= DLGC_WANTARROWS
;
5128 wxSize
wxGenericListCtrl::GetSizeAvailableForScrollTarget(const wxSize
& size
)
5130 wxSize newsize
= size
;
5132 newsize
.y
-= m_headerWin
->GetSize().y
;
5137 void wxGenericListCtrl::OnScroll(wxScrollWinEvent
& event
)
5139 // update our idea of which lines are shown when we redraw
5140 // the window the next time
5141 m_mainWin
->ResetVisibleLinesRange();
5143 HandleOnScroll( event
);
5145 if ( event
.GetOrientation() == wxHORIZONTAL
&& HasHeader() )
5147 m_headerWin
->Refresh();
5148 m_headerWin
->Update();
5152 void wxGenericListCtrl::SetSingleStyle( long style
, bool add
)
5154 wxASSERT_MSG( !(style
& wxLC_VIRTUAL
),
5155 _T("wxLC_VIRTUAL can't be [un]set") );
5157 long flag
= GetWindowStyle();
5161 if (style
& wxLC_MASK_TYPE
)
5162 flag
&= ~(wxLC_MASK_TYPE
| wxLC_VIRTUAL
);
5163 if (style
& wxLC_MASK_ALIGN
)
5164 flag
&= ~wxLC_MASK_ALIGN
;
5165 if (style
& wxLC_MASK_SORT
)
5166 flag
&= ~wxLC_MASK_SORT
;
5174 // some styles can be set without recreating everything (as happens in
5175 // SetWindowStyleFlag() which calls wxListMainWindow::DeleteEverything())
5176 if ( !(style
& ~(wxLC_HRULES
| wxLC_VRULES
)) )
5179 wxWindow::SetWindowStyleFlag(flag
);
5183 SetWindowStyleFlag( flag
);
5187 void wxGenericListCtrl::SetWindowStyleFlag( long flag
)
5191 // m_mainWin->DeleteEverything(); wxMSW doesn't do that
5193 CreateOrDestroyHeaderWindowAsNeeded();
5195 GetSizer()->Layout();
5198 wxWindow::SetWindowStyleFlag( flag
);
5201 bool wxGenericListCtrl::GetColumn(int col
, wxListItem
&item
) const
5203 m_mainWin
->GetColumn( col
, item
);
5207 bool wxGenericListCtrl::SetColumn( int col
, wxListItem
& item
)
5209 m_mainWin
->SetColumn( col
, item
);
5213 int wxGenericListCtrl::GetColumnWidth( int col
) const
5215 return m_mainWin
->GetColumnWidth( col
);
5218 bool wxGenericListCtrl::SetColumnWidth( int col
, int width
)
5220 m_mainWin
->SetColumnWidth( col
, width
);
5224 int wxGenericListCtrl::GetCountPerPage() const
5226 return m_mainWin
->GetCountPerPage(); // different from Windows ?
5229 bool wxGenericListCtrl::GetItem( wxListItem
&info
) const
5231 m_mainWin
->GetItem( info
);
5235 bool wxGenericListCtrl::SetItem( wxListItem
&info
)
5237 m_mainWin
->SetItem( info
);
5241 long wxGenericListCtrl::SetItem( long index
, int col
, const wxString
& label
, int imageId
)
5244 info
.m_text
= label
;
5245 info
.m_mask
= wxLIST_MASK_TEXT
;
5246 info
.m_itemId
= index
;
5250 info
.m_image
= imageId
;
5251 info
.m_mask
|= wxLIST_MASK_IMAGE
;
5254 m_mainWin
->SetItem(info
);
5258 int wxGenericListCtrl::GetItemState( long item
, long stateMask
) const
5260 return m_mainWin
->GetItemState( item
, stateMask
);
5263 bool wxGenericListCtrl::SetItemState( long item
, long state
, long stateMask
)
5265 m_mainWin
->SetItemState( item
, state
, stateMask
);
5270 wxGenericListCtrl::SetItemImage( long item
, int image
, int WXUNUSED(selImage
) )
5272 return SetItemColumnImage(item
, 0, image
);
5276 wxGenericListCtrl::SetItemColumnImage( long item
, long column
, int image
)
5279 info
.m_image
= image
;
5280 info
.m_mask
= wxLIST_MASK_IMAGE
;
5281 info
.m_itemId
= item
;
5282 info
.m_col
= column
;
5283 m_mainWin
->SetItem( info
);
5287 wxString
wxGenericListCtrl::GetItemText( long item
) const
5289 return m_mainWin
->GetItemText(item
);
5292 void wxGenericListCtrl::SetItemText( long item
, const wxString
& str
)
5294 m_mainWin
->SetItemText(item
, str
);
5297 wxUIntPtr
wxGenericListCtrl::GetItemData( long item
) const
5300 info
.m_mask
= wxLIST_MASK_DATA
;
5301 info
.m_itemId
= item
;
5302 m_mainWin
->GetItem( info
);
5306 bool wxGenericListCtrl::SetItemPtrData( long item
, wxUIntPtr data
)
5309 info
.m_mask
= wxLIST_MASK_DATA
;
5310 info
.m_itemId
= item
;
5312 m_mainWin
->SetItem( info
);
5316 wxRect
wxGenericListCtrl::GetViewRect() const
5318 return m_mainWin
->GetViewRect();
5321 bool wxGenericListCtrl::GetItemRect(long item
, wxRect
& rect
, int code
) const
5323 return GetSubItemRect(item
, wxLIST_GETSUBITEMRECT_WHOLEITEM
, rect
, code
);
5326 bool wxGenericListCtrl::GetSubItemRect(long item
,
5329 int WXUNUSED(code
)) const
5331 if ( !m_mainWin
->GetSubItemRect( item
, subItem
, rect
) )
5334 if ( m_mainWin
->HasHeader() )
5335 rect
.y
+= m_headerHeight
+ 1;
5340 bool wxGenericListCtrl::GetItemPosition( long item
, wxPoint
& pos
) const
5342 m_mainWin
->GetItemPosition( item
, pos
);
5346 bool wxGenericListCtrl::SetItemPosition( long WXUNUSED(item
), const wxPoint
& WXUNUSED(pos
) )
5351 int wxGenericListCtrl::GetItemCount() const
5353 return m_mainWin
->GetItemCount();
5356 int wxGenericListCtrl::GetColumnCount() const
5358 return m_mainWin
->GetColumnCount();
5361 void wxGenericListCtrl::SetItemSpacing( int spacing
, bool isSmall
)
5363 m_mainWin
->SetItemSpacing( spacing
, isSmall
);
5366 wxSize
wxGenericListCtrl::GetItemSpacing() const
5368 const int spacing
= m_mainWin
->GetItemSpacing(HasFlag(wxLC_SMALL_ICON
));
5370 return wxSize(spacing
, spacing
);
5373 #if WXWIN_COMPATIBILITY_2_6
5374 int wxGenericListCtrl::GetItemSpacing( bool isSmall
) const
5376 return m_mainWin
->GetItemSpacing( isSmall
);
5378 #endif // WXWIN_COMPATIBILITY_2_6
5380 void wxGenericListCtrl::SetItemTextColour( long item
, const wxColour
&col
)
5383 info
.m_itemId
= item
;
5384 info
.SetTextColour( col
);
5385 m_mainWin
->SetItem( info
);
5388 wxColour
wxGenericListCtrl::GetItemTextColour( long item
) const
5391 info
.m_itemId
= item
;
5392 m_mainWin
->GetItem( info
);
5393 return info
.GetTextColour();
5396 void wxGenericListCtrl::SetItemBackgroundColour( long item
, const wxColour
&col
)
5399 info
.m_itemId
= item
;
5400 info
.SetBackgroundColour( col
);
5401 m_mainWin
->SetItem( info
);
5404 wxColour
wxGenericListCtrl::GetItemBackgroundColour( long item
) const
5407 info
.m_itemId
= item
;
5408 m_mainWin
->GetItem( info
);
5409 return info
.GetBackgroundColour();
5412 void wxGenericListCtrl::SetItemFont( long item
, const wxFont
&f
)
5415 info
.m_itemId
= item
;
5417 m_mainWin
->SetItem( info
);
5420 wxFont
wxGenericListCtrl::GetItemFont( long item
) const
5423 info
.m_itemId
= item
;
5424 m_mainWin
->GetItem( info
);
5425 return info
.GetFont();
5428 int wxGenericListCtrl::GetSelectedItemCount() const
5430 return m_mainWin
->GetSelectedItemCount();
5433 wxColour
wxGenericListCtrl::GetTextColour() const
5435 return GetForegroundColour();
5438 void wxGenericListCtrl::SetTextColour(const wxColour
& col
)
5440 SetForegroundColour(col
);
5443 long wxGenericListCtrl::GetTopItem() const
5446 m_mainWin
->GetVisibleLinesRange(&top
, NULL
);
5450 long wxGenericListCtrl::GetNextItem( long item
, int geom
, int state
) const
5452 return m_mainWin
->GetNextItem( item
, geom
, state
);
5455 wxImageList
*wxGenericListCtrl::GetImageList(int which
) const
5457 if (which
== wxIMAGE_LIST_NORMAL
)
5458 return m_imageListNormal
;
5459 else if (which
== wxIMAGE_LIST_SMALL
)
5460 return m_imageListSmall
;
5461 else if (which
== wxIMAGE_LIST_STATE
)
5462 return m_imageListState
;
5467 void wxGenericListCtrl::SetImageList( wxImageList
*imageList
, int which
)
5469 if ( which
== wxIMAGE_LIST_NORMAL
)
5471 if (m_ownsImageListNormal
)
5472 delete m_imageListNormal
;
5473 m_imageListNormal
= imageList
;
5474 m_ownsImageListNormal
= false;
5476 else if ( which
== wxIMAGE_LIST_SMALL
)
5478 if (m_ownsImageListSmall
)
5479 delete m_imageListSmall
;
5480 m_imageListSmall
= imageList
;
5481 m_ownsImageListSmall
= false;
5483 else if ( which
== wxIMAGE_LIST_STATE
)
5485 if (m_ownsImageListState
)
5486 delete m_imageListState
;
5487 m_imageListState
= imageList
;
5488 m_ownsImageListState
= false;
5491 m_mainWin
->SetImageList( imageList
, which
);
5494 void wxGenericListCtrl::AssignImageList(wxImageList
*imageList
, int which
)
5496 SetImageList(imageList
, which
);
5497 if ( which
== wxIMAGE_LIST_NORMAL
)
5498 m_ownsImageListNormal
= true;
5499 else if ( which
== wxIMAGE_LIST_SMALL
)
5500 m_ownsImageListSmall
= true;
5501 else if ( which
== wxIMAGE_LIST_STATE
)
5502 m_ownsImageListState
= true;
5505 bool wxGenericListCtrl::Arrange( int WXUNUSED(flag
) )
5510 bool wxGenericListCtrl::DeleteItem( long item
)
5512 m_mainWin
->DeleteItem( item
);
5516 bool wxGenericListCtrl::DeleteAllItems()
5518 m_mainWin
->DeleteAllItems();
5522 bool wxGenericListCtrl::DeleteAllColumns()
5524 size_t count
= m_mainWin
->m_columns
.GetCount();
5525 for ( size_t n
= 0; n
< count
; n
++ )
5530 void wxGenericListCtrl::ClearAll()
5532 m_mainWin
->DeleteEverything();
5535 bool wxGenericListCtrl::DeleteColumn( int col
)
5537 m_mainWin
->DeleteColumn( col
);
5539 // if we don't have the header any longer, we need to relayout the window
5540 // if ( !GetColumnCount() )
5545 wxTextCtrl
*wxGenericListCtrl::EditLabel(long item
,
5546 wxClassInfo
* textControlClass
)
5548 return m_mainWin
->EditLabel( item
, textControlClass
);
5551 wxTextCtrl
*wxGenericListCtrl::GetEditControl() const
5553 return m_mainWin
->GetEditControl();
5556 bool wxGenericListCtrl::EnsureVisible( long item
)
5558 m_mainWin
->EnsureVisible( item
);
5562 long wxGenericListCtrl::FindItem( long start
, const wxString
& str
, bool partial
)
5564 return m_mainWin
->FindItem( start
, str
, partial
);
5567 long wxGenericListCtrl::FindItem( long start
, wxUIntPtr data
)
5569 return m_mainWin
->FindItem( start
, data
);
5572 long wxGenericListCtrl::FindItem( long WXUNUSED(start
), const wxPoint
& pt
,
5573 int WXUNUSED(direction
))
5575 return m_mainWin
->FindItem( pt
);
5578 // TODO: sub item hit testing
5579 long wxGenericListCtrl::HitTest(const wxPoint
& point
, int& flags
, long *) const
5581 return m_mainWin
->HitTest( (int)point
.x
, (int)point
.y
, flags
);
5584 long wxGenericListCtrl::InsertItem( wxListItem
& info
)
5586 m_mainWin
->InsertItem( info
);
5587 return info
.m_itemId
;
5590 long wxGenericListCtrl::InsertItem( long index
, const wxString
&label
)
5593 info
.m_text
= label
;
5594 info
.m_mask
= wxLIST_MASK_TEXT
;
5595 info
.m_itemId
= index
;
5596 return InsertItem( info
);
5599 long wxGenericListCtrl::InsertItem( long index
, int imageIndex
)
5602 info
.m_mask
= wxLIST_MASK_IMAGE
;
5603 info
.m_image
= imageIndex
;
5604 info
.m_itemId
= index
;
5605 return InsertItem( info
);
5608 long wxGenericListCtrl::InsertItem( long index
, const wxString
&label
, int imageIndex
)
5611 info
.m_text
= label
;
5612 info
.m_image
= imageIndex
;
5613 info
.m_mask
= wxLIST_MASK_TEXT
| wxLIST_MASK_IMAGE
;
5614 info
.m_itemId
= index
;
5615 return InsertItem( info
);
5618 long wxGenericListCtrl::InsertColumn( long col
, wxListItem
&item
)
5620 wxCHECK_MSG( m_headerWin
, -1, _T("can't add column in non report mode") );
5622 m_mainWin
->InsertColumn( col
, item
);
5624 // if we hadn't had a header before but have one now
5625 // then we need to relayout the window
5626 // if ( GetColumnCount() == 1 && m_mainWin->HasHeader() )
5628 m_headerWin
->Refresh();
5633 long wxGenericListCtrl::InsertColumn( long col
, const wxString
&heading
,
5634 int format
, int width
)
5637 item
.m_mask
= wxLIST_MASK_TEXT
| wxLIST_MASK_FORMAT
;
5638 item
.m_text
= heading
;
5641 item
.m_mask
|= wxLIST_MASK_WIDTH
;
5642 item
.m_width
= width
;
5645 item
.m_format
= format
;
5647 return InsertColumn( col
, item
);
5650 bool wxGenericListCtrl::ScrollList( int dx
, int dy
)
5652 return m_mainWin
->ScrollList(dx
, dy
);
5656 // fn is a function which takes 3 long arguments: item1, item2, data.
5657 // item1 is the long data associated with a first item (NOT the index).
5658 // item2 is the long data associated with a second item (NOT the index).
5659 // data is the same value as passed to SortItems.
5660 // The return value is a negative number if the first item should precede the second
5661 // item, a positive number of the second item should precede the first,
5662 // or zero if the two items are equivalent.
5663 // data is arbitrary data to be passed to the sort function.
5665 bool wxGenericListCtrl::SortItems( wxListCtrlCompare fn
, long data
)
5667 m_mainWin
->SortItems( fn
, data
);
5671 // ----------------------------------------------------------------------------
5673 // ----------------------------------------------------------------------------
5675 void wxGenericListCtrl::OnSize(wxSizeEvent
& WXUNUSED(event
))
5677 if (!m_mainWin
) return;
5679 // We need to override OnSize so that our scrolled
5680 // window a) does call Layout() to use sizers for
5681 // positioning the controls but b) does not query
5682 // the sizer for their size and use that for setting
5683 // the scrollable area as set that ourselves by
5684 // calling SetScrollbar() further down.
5688 m_mainWin
->RecalculatePositions();
5693 void wxGenericListCtrl::OnInternalIdle()
5695 wxWindow::OnInternalIdle();
5697 if (m_mainWin
->m_dirty
)
5698 m_mainWin
->RecalculatePositions();
5701 // ----------------------------------------------------------------------------
5703 // ----------------------------------------------------------------------------
5705 bool wxGenericListCtrl::SetBackgroundColour( const wxColour
&colour
)
5709 m_mainWin
->SetBackgroundColour( colour
);
5710 m_mainWin
->m_dirty
= true;
5716 bool wxGenericListCtrl::SetForegroundColour( const wxColour
&colour
)
5718 if ( !wxWindow::SetForegroundColour( colour
) )
5723 m_mainWin
->SetForegroundColour( colour
);
5724 m_mainWin
->m_dirty
= true;
5728 m_headerWin
->SetForegroundColour( colour
);
5733 bool wxGenericListCtrl::SetFont( const wxFont
&font
)
5735 if ( !wxWindow::SetFont( font
) )
5740 m_mainWin
->SetFont( font
);
5741 m_mainWin
->m_dirty
= true;
5746 m_headerWin
->SetFont( font
);
5747 // CalculateAndSetHeaderHeight();
5757 wxGenericListCtrl::GetClassDefaultAttributes(wxWindowVariant variant
)
5760 // Use the same color scheme as wxListBox
5761 return wxListBox::GetClassDefaultAttributes(variant
);
5763 wxUnusedVar(variant
);
5764 wxVisualAttributes attr
;
5765 attr
.colFg
= wxSystemSettings::GetColour(wxSYS_COLOUR_LISTBOXTEXT
);
5766 attr
.colBg
= wxSystemSettings::GetColour(wxSYS_COLOUR_LISTBOX
);
5767 attr
.font
= wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT
);
5772 // ----------------------------------------------------------------------------
5773 // methods forwarded to m_mainWin
5774 // ----------------------------------------------------------------------------
5776 #if wxUSE_DRAG_AND_DROP
5778 void wxGenericListCtrl::SetDropTarget( wxDropTarget
*dropTarget
)
5780 m_mainWin
->SetDropTarget( dropTarget
);
5783 wxDropTarget
*wxGenericListCtrl::GetDropTarget() const
5785 return m_mainWin
->GetDropTarget();
5790 bool wxGenericListCtrl::SetCursor( const wxCursor
&cursor
)
5792 return m_mainWin
? m_mainWin
->wxWindow::SetCursor(cursor
) : false;
5795 wxColour
wxGenericListCtrl::GetBackgroundColour() const
5797 return m_mainWin
? m_mainWin
->GetBackgroundColour() : wxColour();
5800 wxColour
wxGenericListCtrl::GetForegroundColour() const
5802 return m_mainWin
? m_mainWin
->GetForegroundColour() : wxColour();
5805 bool wxGenericListCtrl::DoPopupMenu( wxMenu
*menu
, int x
, int y
)
5808 return m_mainWin
->PopupMenu( menu
, x
, y
);
5814 void wxGenericListCtrl::DoClientToScreen( int *x
, int *y
) const
5816 m_mainWin
->DoClientToScreen(x
, y
);
5819 void wxGenericListCtrl::DoScreenToClient( int *x
, int *y
) const
5821 m_mainWin
->DoScreenToClient(x
, y
);
5824 void wxGenericListCtrl::SetFocus()
5826 // The test in window.cpp fails as we are a composite
5827 // window, so it checks against "this", but not m_mainWin.
5828 if ( DoFindFocus() != this )
5829 m_mainWin
->SetFocus();
5832 wxSize
wxGenericListCtrl::DoGetBestSize() const
5834 // Something is better than nothing...
5835 // 100x80 is what the MSW version will get from the default
5836 // wxControl::DoGetBestSize
5837 return wxSize(100, 80);
5840 // ----------------------------------------------------------------------------
5841 // virtual list control support
5842 // ----------------------------------------------------------------------------
5844 wxString
wxGenericListCtrl::OnGetItemText(long WXUNUSED(item
), long WXUNUSED(col
)) const
5846 // this is a pure virtual function, in fact - which is not really pure
5847 // because the controls which are not virtual don't need to implement it
5848 wxFAIL_MSG( _T("wxGenericListCtrl::OnGetItemText not supposed to be called") );
5850 return wxEmptyString
;
5853 int wxGenericListCtrl::OnGetItemImage(long WXUNUSED(item
)) const
5855 wxCHECK_MSG(!GetImageList(wxIMAGE_LIST_SMALL
),
5857 wxT("List control has an image list, OnGetItemImage or OnGetItemColumnImage should be overridden."));
5861 int wxGenericListCtrl::OnGetItemColumnImage(long item
, long column
) const
5864 return OnGetItemImage(item
);
5870 wxGenericListCtrl::OnGetItemAttr(long WXUNUSED_UNLESS_DEBUG(item
)) const
5872 wxASSERT_MSG( item
>= 0 && item
< GetItemCount(),
5873 _T("invalid item index in OnGetItemAttr()") );
5875 // no attributes by default
5879 void wxGenericListCtrl::SetItemCount(long count
)
5881 wxASSERT_MSG( IsVirtual(), _T("this is for virtual controls only") );
5883 m_mainWin
->SetItemCount(count
);
5886 void wxGenericListCtrl::RefreshItem(long item
)
5888 m_mainWin
->RefreshLine(item
);
5891 void wxGenericListCtrl::RefreshItems(long itemFrom
, long itemTo
)
5893 m_mainWin
->RefreshLines(itemFrom
, itemTo
);
5896 // Generic wxListCtrl is more or less a container for two other
5897 // windows which drawings are done upon. These are namely
5898 // 'm_headerWin' and 'm_mainWin'.
5899 // Here we override 'virtual wxWindow::Refresh()' to mimic the
5900 // behaviour wxListCtrl has under wxMSW.
5902 void wxGenericListCtrl::Refresh(bool eraseBackground
, const wxRect
*rect
)
5906 // The easy case, no rectangle specified.
5908 m_headerWin
->Refresh(eraseBackground
);
5911 m_mainWin
->Refresh(eraseBackground
);
5915 // Refresh the header window
5918 wxRect rectHeader
= m_headerWin
->GetRect();
5919 rectHeader
.Intersect(*rect
);
5920 if (rectHeader
.GetWidth() && rectHeader
.GetHeight())
5923 m_headerWin
->GetPosition(&x
, &y
);
5924 rectHeader
.Offset(-x
, -y
);
5925 m_headerWin
->Refresh(eraseBackground
, &rectHeader
);
5929 // Refresh the main window
5932 wxRect rectMain
= m_mainWin
->GetRect();
5933 rectMain
.Intersect(*rect
);
5934 if (rectMain
.GetWidth() && rectMain
.GetHeight())
5937 m_mainWin
->GetPosition(&x
, &y
);
5938 rectMain
.Offset(-x
, -y
);
5939 m_mainWin
->Refresh(eraseBackground
, &rectMain
);
5945 #endif // wxUSE_LISTCTRL