1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/generic/listctrl.cpp
3 // Purpose: generic implementation of wxListCtrl
4 // Author: Robert Roebling
5 // Vadim Zeitlin (virtual list control support)
7 // Copyright: (c) 1998 Robert Roebling
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
13 // 1. we need to implement searching/sorting for virtual controls somehow
14 // 2. when changing selection the lines are refreshed twice
17 // For compilers that support precompilation, includes "wx.h".
18 #include "wx/wxprec.h"
26 #include "wx/listctrl.h"
28 #if (!defined(__WXMSW__) || defined(__WXUNIVERSAL__)) && !defined(__WXMAC__)
29 // if we have a native version, its implementation file does all this
30 IMPLEMENT_DYNAMIC_CLASS(wxListItem
, wxObject
)
31 IMPLEMENT_DYNAMIC_CLASS(wxListView
, wxListCtrl
)
32 IMPLEMENT_DYNAMIC_CLASS(wxListEvent
, wxNotifyEvent
)
34 IMPLEMENT_DYNAMIC_CLASS(wxListCtrl
, wxGenericListCtrl
)
38 #include "wx/scrolwin.h"
40 #include "wx/settings.h"
41 #include "wx/dynarray.h"
42 #include "wx/dcscreen.h"
46 #include "wx/imaglist.h"
47 #include "wx/selstore.h"
48 #include "wx/renderer.h"
51 #include "wx/mac/private.h"
55 // NOTE: If using the wxListBox visual attributes works everywhere then this can
56 // be removed, as well as the #else case below.
57 #define _USE_VISATTR 0
60 // ----------------------------------------------------------------------------
62 // ----------------------------------------------------------------------------
64 // // the height of the header window (FIXME: should depend on its font!)
65 // static const int HEADER_HEIGHT = 23;
67 static const int SCROLL_UNIT_X
= 15;
69 // the spacing between the lines (in report mode)
70 static const int LINE_SPACING
= 0;
72 // extra margins around the text label
73 static const int EXTRA_WIDTH
= 4;
74 static const int EXTRA_HEIGHT
= 4;
76 // margin between the window and the items
77 static const int EXTRA_BORDER_X
= 2;
78 static const int EXTRA_BORDER_Y
= 2;
80 // offset for the header window
81 static const int HEADER_OFFSET_X
= 1;
82 static const int HEADER_OFFSET_Y
= 1;
84 // margin between rows of icons in [small] icon view
85 static const int MARGIN_BETWEEN_ROWS
= 6;
87 // when autosizing the columns, add some slack
88 static const int AUTOSIZE_COL_MARGIN
= 10;
90 // default width for the header columns
91 static const int WIDTH_COL_DEFAULT
= 80;
93 // the space between the image and the text in the report mode
94 static const int IMAGE_MARGIN_IN_REPORT_MODE
= 5;
96 // ============================================================================
98 // ============================================================================
100 //-----------------------------------------------------------------------------
101 // wxColWidthInfo (internal)
102 //-----------------------------------------------------------------------------
104 struct wxColWidthInfo
107 bool bNeedsUpdate
; // only set to true when an item whose
108 // width == nMaxWidth is removed
110 wxColWidthInfo(int w
= 0, bool needsUpdate
= false)
113 bNeedsUpdate
= needsUpdate
;
117 WX_DEFINE_ARRAY_PTR(wxColWidthInfo
*, ColWidthArray
);
119 //-----------------------------------------------------------------------------
120 // wxListItemData (internal)
121 //-----------------------------------------------------------------------------
123 class WXDLLEXPORT wxListItemData
126 wxListItemData(wxListMainWindow
*owner
);
129 void SetItem( const wxListItem
&info
);
130 void SetImage( int image
) { m_image
= image
; }
131 void SetData( wxUIntPtr data
) { m_data
= data
; }
132 void SetPosition( int x
, int y
);
133 void SetSize( int width
, int height
);
135 bool HasText() const { return !m_text
.empty(); }
136 const wxString
& GetText() const { return m_text
; }
137 void SetText(const wxString
& text
) { m_text
= text
; }
139 // we can't use empty string for measuring the string width/height, so
140 // always return something
141 wxString
GetTextForMeasuring() const
143 wxString s
= GetText();
150 bool IsHit( int x
, int y
) const;
154 int GetWidth() const;
155 int GetHeight() const;
157 int GetImage() const { return m_image
; }
158 bool HasImage() const { return GetImage() != -1; }
160 void GetItem( wxListItem
&info
) const;
162 void SetAttr(wxListItemAttr
*attr
) { m_attr
= attr
; }
163 wxListItemAttr
*GetAttr() const { return m_attr
; }
166 // the item image or -1
169 // user data associated with the item
172 // the item coordinates are not used in report mode; instead this pointer is
173 // NULL and the owner window is used to retrieve the item position and size
176 // the list ctrl we are in
177 wxListMainWindow
*m_owner
;
179 // custom attributes or NULL
180 wxListItemAttr
*m_attr
;
183 // common part of all ctors
189 //-----------------------------------------------------------------------------
190 // wxListHeaderData (internal)
191 //-----------------------------------------------------------------------------
193 class WXDLLEXPORT wxListHeaderData
: public wxObject
197 wxListHeaderData( const wxListItem
&info
);
198 void SetItem( const wxListItem
&item
);
199 void SetPosition( int x
, int y
);
200 void SetWidth( int w
);
201 void SetFormat( int format
);
202 void SetHeight( int h
);
203 bool HasImage() const;
205 bool HasText() const { return !m_text
.empty(); }
206 const wxString
& GetText() const { return m_text
; }
207 void SetText(const wxString
& text
) { m_text
= text
; }
209 void GetItem( wxListItem
&item
);
211 bool IsHit( int x
, int y
) const;
212 int GetImage() const;
213 int GetWidth() const;
214 int GetFormat() const;
230 //-----------------------------------------------------------------------------
231 // wxListLineData (internal)
232 //-----------------------------------------------------------------------------
234 WX_DECLARE_EXPORTED_LIST(wxListItemData
, wxListItemDataList
);
235 #include "wx/listimpl.cpp"
236 WX_DEFINE_LIST(wxListItemDataList
)
241 // the list of subitems: only may have more than one item in report mode
242 wxListItemDataList m_items
;
244 // this is not used in report view
256 // the part to be highlighted
257 wxRect m_rectHighlight
;
259 // extend all our rects to be centered inside the one of given width
260 void ExtendWidth(wxCoord w
)
262 wxASSERT_MSG( m_rectAll
.width
<= w
,
263 _T("width can only be increased") );
266 m_rectLabel
.x
= m_rectAll
.x
+ (w
- m_rectLabel
.width
) / 2;
267 m_rectIcon
.x
= m_rectAll
.x
+ (w
- m_rectIcon
.width
) / 2;
268 m_rectHighlight
.x
= m_rectAll
.x
+ (w
- m_rectHighlight
.width
) / 2;
273 // is this item selected? [NB: not used in virtual mode]
276 // back pointer to the list ctrl
277 wxListMainWindow
*m_owner
;
280 wxListLineData(wxListMainWindow
*owner
);
284 WX_CLEAR_LIST(wxListItemDataList
, m_items
);
288 // are we in report mode?
289 inline bool InReportView() const;
291 // are we in virtual report mode?
292 inline bool IsVirtual() const;
294 // these 2 methods shouldn't be called for report view controls, in that
295 // case we determine our position/size ourselves
297 // calculate the size of the line
298 void CalculateSize( wxDC
*dc
, int spacing
);
300 // remember the position this line appears at
301 void SetPosition( int x
, int y
, int spacing
);
305 void SetImage( int image
) { SetImage(0, image
); }
306 int GetImage() const { return GetImage(0); }
307 void SetImage( int index
, int image
);
308 int GetImage( int index
) const;
310 bool HasImage() const { return GetImage() != -1; }
311 bool HasText() const { return !GetText(0).empty(); }
313 void SetItem( int index
, const wxListItem
&info
);
314 void GetItem( int index
, wxListItem
&info
);
316 wxString
GetText(int index
) const;
317 void SetText( int index
, const wxString
& s
);
319 wxListItemAttr
*GetAttr() const;
320 void SetAttr(wxListItemAttr
*attr
);
322 // return true if the highlighting really changed
323 bool Highlight( bool on
);
325 void ReverseHighlight();
327 bool IsHighlighted() const
329 wxASSERT_MSG( !IsVirtual(), _T("unexpected call to IsHighlighted") );
331 return m_highlighted
;
334 // draw the line on the given DC in icon/list mode
335 void Draw( wxDC
*dc
);
337 // the same in report mode
338 void DrawInReportMode( wxDC
*dc
,
340 const wxRect
& rectHL
,
344 // set the line to contain num items (only can be > 1 in report mode)
345 void InitItems( int num
);
347 // get the mode (i.e. style) of the list control
348 inline int GetMode() const;
350 // prepare the DC for drawing with these item's attributes, return true if
351 // we need to draw the items background to highlight it, false otherwise
352 bool SetAttributes(wxDC
*dc
,
353 const wxListItemAttr
*attr
,
356 // draw the text on the DC with the correct justification; also add an
357 // ellipsis if the text is too large to fit in the current width
358 void DrawTextFormatted(wxDC
*dc
,
359 const wxString
&text
,
362 int yMid
, // this is middle, not top, of the text
366 WX_DECLARE_EXPORTED_OBJARRAY(wxListLineData
, wxListLineDataArray
);
367 #include "wx/arrimpl.cpp"
368 WX_DEFINE_OBJARRAY(wxListLineDataArray
)
370 //-----------------------------------------------------------------------------
371 // wxListHeaderWindow (internal)
372 //-----------------------------------------------------------------------------
374 class WXDLLEXPORT wxListHeaderWindow
: public wxWindow
377 wxListMainWindow
*m_owner
;
378 const wxCursor
*m_currentCursor
;
379 wxCursor
*m_resizeCursor
;
382 // column being resized or -1
385 // divider line position in logical (unscrolled) coords
388 // minimal position beyond which the divider line
389 // can't be dragged in logical coords
393 wxListHeaderWindow();
395 wxListHeaderWindow( wxWindow
*win
,
397 wxListMainWindow
*owner
,
398 const wxPoint
&pos
= wxDefaultPosition
,
399 const wxSize
&size
= wxDefaultSize
,
401 const wxString
&name
= wxT("wxlistctrlcolumntitles") );
403 virtual ~wxListHeaderWindow();
406 void AdjustDC( wxDC
& dc
);
408 void OnPaint( wxPaintEvent
&event
);
409 void OnMouse( wxMouseEvent
&event
);
410 void OnSetFocus( wxFocusEvent
&event
);
416 // common part of all ctors
419 // generate and process the list event of the given type, return true if
420 // it wasn't vetoed, i.e. if we should proceed
421 bool SendListEvent(wxEventType type
, const wxPoint
& pos
);
423 DECLARE_DYNAMIC_CLASS(wxListHeaderWindow
)
424 DECLARE_EVENT_TABLE()
427 //-----------------------------------------------------------------------------
428 // wxListRenameTimer (internal)
429 //-----------------------------------------------------------------------------
431 class WXDLLEXPORT wxListRenameTimer
: public wxTimer
434 wxListMainWindow
*m_owner
;
437 wxListRenameTimer( wxListMainWindow
*owner
);
441 //-----------------------------------------------------------------------------
442 // wxListTextCtrlWrapper: wraps a wxTextCtrl to make it work for inline editing
443 //-----------------------------------------------------------------------------
445 class WXDLLEXPORT wxListTextCtrlWrapper
: public wxEvtHandler
448 // NB: text must be a valid object but not Create()d yet
449 wxListTextCtrlWrapper(wxListMainWindow
*owner
,
453 wxTextCtrl
*GetText() const { return m_text
; }
455 void AcceptChangesAndFinish();
458 void OnChar( wxKeyEvent
&event
);
459 void OnKeyUp( wxKeyEvent
&event
);
460 void OnKillFocus( wxFocusEvent
&event
);
462 bool AcceptChanges();
466 wxListMainWindow
*m_owner
;
468 wxString m_startValue
;
471 bool m_aboutToFinish
;
473 DECLARE_EVENT_TABLE()
476 //-----------------------------------------------------------------------------
477 // wxListMainWindow (internal)
478 //-----------------------------------------------------------------------------
480 WX_DECLARE_EXPORTED_LIST(wxListHeaderData
, wxListHeaderDataList
);
481 #include "wx/listimpl.cpp"
482 WX_DEFINE_LIST(wxListHeaderDataList
)
484 class wxListMainWindow
: public wxScrolledWindow
488 wxListMainWindow( wxWindow
*parent
,
490 const wxPoint
& pos
= wxDefaultPosition
,
491 const wxSize
& size
= wxDefaultSize
,
493 const wxString
&name
= _T("listctrlmainwindow") );
495 virtual ~wxListMainWindow();
497 bool HasFlag(int flag
) const { return m_parent
->HasFlag(flag
); }
499 // return true if this is a virtual list control
500 bool IsVirtual() const { return HasFlag(wxLC_VIRTUAL
); }
502 // return true if the control is in report mode
503 bool InReportView() const { return HasFlag(wxLC_REPORT
); }
505 // return true if we are in single selection mode, false if multi sel
506 bool IsSingleSel() const { return HasFlag(wxLC_SINGLE_SEL
); }
508 // do we have a header window?
509 bool HasHeader() const
510 { return InReportView() && !HasFlag(wxLC_NO_HEADER
); }
512 void HighlightAll( bool on
);
514 // all these functions only do something if the line is currently visible
516 // change the line "selected" state, return true if it really changed
517 bool HighlightLine( size_t line
, bool highlight
= true);
519 // as HighlightLine() but do it for the range of lines: this is incredibly
520 // more efficient for virtual list controls!
522 // NB: unlike HighlightLine() this one does refresh the lines on screen
523 void HighlightLines( size_t lineFrom
, size_t lineTo
, bool on
= true );
525 // toggle the line state and refresh it
526 void ReverseHighlight( size_t line
)
527 { HighlightLine(line
, !IsHighlighted(line
)); RefreshLine(line
); }
529 // return true if the line is highlighted
530 bool IsHighlighted(size_t line
) const;
532 // refresh one or several lines at once
533 void RefreshLine( size_t line
);
534 void RefreshLines( size_t lineFrom
, size_t lineTo
);
536 // refresh all selected items
537 void RefreshSelected();
539 // refresh all lines below the given one: the difference with
540 // RefreshLines() is that the index here might not be a valid one (happens
541 // when the last line is deleted)
542 void RefreshAfter( size_t lineFrom
);
544 // the methods which are forwarded to wxListLineData itself in list/icon
545 // modes but are here because the lines don't store their positions in the
548 // get the bound rect for the entire line
549 wxRect
GetLineRect(size_t line
) const;
551 // get the bound rect of the label
552 wxRect
GetLineLabelRect(size_t line
) const;
554 // get the bound rect of the items icon (only may be called if we do have
556 wxRect
GetLineIconRect(size_t line
) const;
558 // get the rect to be highlighted when the item has focus
559 wxRect
GetLineHighlightRect(size_t line
) const;
561 // get the size of the total line rect
562 wxSize
GetLineSize(size_t line
) const
563 { return GetLineRect(line
).GetSize(); }
565 // return the hit code for the corresponding position (in this line)
566 long HitTestLine(size_t line
, int x
, int y
) const;
568 // bring the selected item into view, scrolling to it if necessary
569 void MoveToItem(size_t item
);
571 // bring the current item into view
572 void MoveToFocus() { MoveToItem(m_current
); }
574 // start editing the label of the given item
575 wxTextCtrl
*EditLabel(long item
,
576 wxClassInfo
* textControlClass
= CLASSINFO(wxTextCtrl
));
577 wxTextCtrl
*GetEditControl() const
579 return m_textctrlWrapper
? m_textctrlWrapper
->GetText() : NULL
;
582 void FinishEditing(wxTextCtrl
*text
)
585 m_textctrlWrapper
= NULL
;
586 SetFocusIgnoringChildren();
589 // suspend/resume redrawing the control
593 void OnRenameTimer();
594 bool OnRenameAccept(size_t itemEdit
, const wxString
& value
);
595 void OnRenameCancelled(size_t itemEdit
);
597 void OnMouse( wxMouseEvent
&event
);
599 // called to switch the selection from the current item to newCurrent,
600 void OnArrowChar( size_t newCurrent
, const wxKeyEvent
& event
);
602 void OnChar( wxKeyEvent
&event
);
603 void OnKeyDown( wxKeyEvent
&event
);
604 void OnSetFocus( wxFocusEvent
&event
);
605 void OnKillFocus( wxFocusEvent
&event
);
606 void OnScroll( wxScrollWinEvent
& event
);
608 void OnPaint( wxPaintEvent
&event
);
610 void DrawImage( int index
, wxDC
*dc
, int x
, int y
);
611 void GetImageSize( int index
, int &width
, int &height
) const;
612 int GetTextLength( const wxString
&s
) const;
614 void SetImageList( wxImageList
*imageList
, int which
);
615 void SetItemSpacing( int spacing
, bool isSmall
= false );
616 int GetItemSpacing( bool isSmall
= false );
618 void SetColumn( int col
, wxListItem
&item
);
619 void SetColumnWidth( int col
, int width
);
620 void GetColumn( int col
, wxListItem
&item
) const;
621 int GetColumnWidth( int col
) const;
622 int GetColumnCount() const { return m_columns
.GetCount(); }
624 // returns the sum of the heights of all columns
625 int GetHeaderWidth() const;
627 int GetCountPerPage() const;
629 void SetItem( wxListItem
&item
);
630 void GetItem( wxListItem
&item
) const;
631 void SetItemState( long item
, long state
, long stateMask
);
632 void SetItemStateAll( long state
, long stateMask
);
633 int GetItemState( long item
, long stateMask
) const;
634 void GetItemRect( long index
, wxRect
&rect
) const;
635 wxRect
GetViewRect() const;
636 bool GetItemPosition( long item
, wxPoint
& pos
) const;
637 int GetSelectedItemCount() const;
639 wxString
GetItemText(long item
) const
642 info
.m_mask
= wxLIST_MASK_TEXT
;
643 info
.m_itemId
= item
;
648 void SetItemText(long item
, const wxString
& value
)
651 info
.m_mask
= wxLIST_MASK_TEXT
;
652 info
.m_itemId
= item
;
657 // set the scrollbars and update the positions of the items
658 void RecalculatePositions(bool noRefresh
= false);
660 // refresh the window and the header
663 long GetNextItem( long item
, int geometry
, int state
) const;
664 void DeleteItem( long index
);
665 void DeleteAllItems();
666 void DeleteColumn( int col
);
667 void DeleteEverything();
668 void EnsureVisible( long index
);
669 long FindItem( long start
, const wxString
& str
, bool partial
= false );
670 long FindItem( long start
, wxUIntPtr data
);
671 long FindItem( const wxPoint
& pt
);
672 long HitTest( int x
, int y
, int &flags
) const;
673 void InsertItem( wxListItem
&item
);
674 void InsertColumn( long col
, wxListItem
&item
);
675 int GetItemWidthWithImage(wxListItem
* item
);
676 void SortItems( wxListCtrlCompare fn
, long data
);
678 size_t GetItemCount() const;
679 bool IsEmpty() const { return GetItemCount() == 0; }
680 void SetItemCount(long count
);
682 // change the current (== focused) item, send a notification event
683 void ChangeCurrent(size_t current
);
684 void ResetCurrent() { ChangeCurrent((size_t)-1); }
685 bool HasCurrent() const { return m_current
!= (size_t)-1; }
687 // send out a wxListEvent
688 void SendNotify( size_t line
,
690 const wxPoint
& point
= wxDefaultPosition
);
692 // override base class virtual to reset m_lineHeight when the font changes
693 virtual bool SetFont(const wxFont
& font
)
695 if ( !wxScrolledWindow::SetFont(font
) )
703 // these are for wxListLineData usage only
705 // get the backpointer to the list ctrl
706 wxGenericListCtrl
*GetListCtrl() const
708 return wxStaticCast(GetParent(), wxGenericListCtrl
);
711 // get the height of all lines (assuming they all do have the same height)
712 wxCoord
GetLineHeight() const;
714 // get the y position of the given line (only for report view)
715 wxCoord
GetLineY(size_t line
) const;
717 // get the brush to use for the item highlighting
718 wxBrush
*GetHighlightBrush() const
720 return m_hasFocus
? m_highlightBrush
: m_highlightUnfocusedBrush
;
724 // the array of all line objects for a non virtual list control (for the
725 // virtual list control we only ever use m_lines[0])
726 wxListLineDataArray m_lines
;
728 // the list of column objects
729 wxListHeaderDataList m_columns
;
731 // currently focused item or -1
734 // the number of lines per page
737 // this flag is set when something which should result in the window
738 // redrawing happens (i.e. an item was added or deleted, or its appearance
739 // changed) and OnPaint() doesn't redraw the window while it is set which
740 // allows to minimize the number of repaintings when a lot of items are
741 // being added. The real repainting occurs only after the next OnIdle()
745 wxColour
*m_highlightColour
;
746 wxImageList
*m_small_image_list
;
747 wxImageList
*m_normal_image_list
;
749 int m_normal_spacing
;
753 wxTimer
*m_renameTimer
;
757 ColWidthArray m_aColWidths
;
759 // for double click logic
760 size_t m_lineLastClicked
,
761 m_lineBeforeLastClicked
,
762 m_lineSelectSingleOnUp
;
765 wxWindow
*GetMainWindowOfCompositeControl() { return GetParent(); }
767 // the total count of items in a virtual list control
770 // the object maintaining the items selection state, only used in virtual
772 wxSelectionStore m_selStore
;
774 // common part of all ctors
777 // get the line data for the given index
778 wxListLineData
*GetLine(size_t n
) const
780 wxASSERT_MSG( n
!= (size_t)-1, _T("invalid line index") );
784 wxConstCast(this, wxListMainWindow
)->CacheLineData(n
);
791 // get a dummy line which can be used for geometry calculations and such:
792 // you must use GetLine() if you want to really draw the line
793 wxListLineData
*GetDummyLine() const;
795 // cache the line data of the n-th line in m_lines[0]
796 void CacheLineData(size_t line
);
798 // get the range of visible lines
799 void GetVisibleLinesRange(size_t *from
, size_t *to
);
801 // force us to recalculate the range of visible lines
802 void ResetVisibleLinesRange() { m_lineFrom
= (size_t)-1; }
804 // get the colour to be used for drawing the rules
805 wxColour
GetRuleColour() const
807 return wxSystemSettings::GetColour(wxSYS_COLOUR_3DLIGHT
);
811 // initialize the current item if needed
812 void UpdateCurrent();
814 // delete all items but don't refresh: called from dtor
815 void DoDeleteAllItems();
817 // the height of one line using the current font
818 wxCoord m_lineHeight
;
820 // the total header width or 0 if not calculated yet
821 wxCoord m_headerWidth
;
823 // the first and last lines being shown on screen right now (inclusive),
824 // both may be -1 if they must be calculated so never access them directly:
825 // use GetVisibleLinesRange() above instead
829 // the brushes to use for item highlighting when we do/don't have focus
830 wxBrush
*m_highlightBrush
,
831 *m_highlightUnfocusedBrush
;
833 // if this is > 0, the control is frozen and doesn't redraw itself
834 size_t m_freezeCount
;
836 // wrapper around the text control currently used for in place editing or
837 // NULL if no item is being edited
838 wxListTextCtrlWrapper
*m_textctrlWrapper
;
841 DECLARE_DYNAMIC_CLASS(wxListMainWindow
)
842 DECLARE_EVENT_TABLE()
844 friend class wxGenericListCtrl
;
848 wxListItemData::~wxListItemData()
850 // in the virtual list control the attributes are managed by the main
851 // program, so don't delete them
852 if ( !m_owner
->IsVirtual() )
858 void wxListItemData::Init()
866 wxListItemData::wxListItemData(wxListMainWindow
*owner
)
872 if ( owner
->InReportView() )
878 void wxListItemData::SetItem( const wxListItem
&info
)
880 if ( info
.m_mask
& wxLIST_MASK_TEXT
)
881 SetText(info
.m_text
);
882 if ( info
.m_mask
& wxLIST_MASK_IMAGE
)
883 m_image
= info
.m_image
;
884 if ( info
.m_mask
& wxLIST_MASK_DATA
)
885 m_data
= info
.m_data
;
887 if ( info
.HasAttributes() )
890 *m_attr
= *info
.GetAttributes();
892 m_attr
= new wxListItemAttr(*info
.GetAttributes());
900 m_rect
->width
= info
.m_width
;
904 void wxListItemData::SetPosition( int x
, int y
)
906 wxCHECK_RET( m_rect
, _T("unexpected SetPosition() call") );
912 void wxListItemData::SetSize( int width
, int height
)
914 wxCHECK_RET( m_rect
, _T("unexpected SetSize() call") );
917 m_rect
->width
= width
;
919 m_rect
->height
= height
;
922 bool wxListItemData::IsHit( int x
, int y
) const
924 wxCHECK_MSG( m_rect
, false, _T("can't be called in this mode") );
926 return wxRect(GetX(), GetY(), GetWidth(), GetHeight()).Contains(x
, y
);
929 int wxListItemData::GetX() const
931 wxCHECK_MSG( m_rect
, 0, _T("can't be called in this mode") );
936 int wxListItemData::GetY() const
938 wxCHECK_MSG( m_rect
, 0, _T("can't be called in this mode") );
943 int wxListItemData::GetWidth() const
945 wxCHECK_MSG( m_rect
, 0, _T("can't be called in this mode") );
947 return m_rect
->width
;
950 int wxListItemData::GetHeight() const
952 wxCHECK_MSG( m_rect
, 0, _T("can't be called in this mode") );
954 return m_rect
->height
;
957 void wxListItemData::GetItem( wxListItem
&info
) const
959 long mask
= info
.m_mask
;
961 // by default, get everything for backwards compatibility
964 if ( mask
& wxLIST_MASK_TEXT
)
965 info
.m_text
= m_text
;
966 if ( mask
& wxLIST_MASK_IMAGE
)
967 info
.m_image
= m_image
;
968 if ( mask
& wxLIST_MASK_DATA
)
969 info
.m_data
= m_data
;
973 if ( m_attr
->HasTextColour() )
974 info
.SetTextColour(m_attr
->GetTextColour());
975 if ( m_attr
->HasBackgroundColour() )
976 info
.SetBackgroundColour(m_attr
->GetBackgroundColour());
977 if ( m_attr
->HasFont() )
978 info
.SetFont(m_attr
->GetFont());
982 //-----------------------------------------------------------------------------
984 //-----------------------------------------------------------------------------
986 void wxListHeaderData::Init()
997 wxListHeaderData::wxListHeaderData()
1002 wxListHeaderData::wxListHeaderData( const wxListItem
&item
)
1009 void wxListHeaderData::SetItem( const wxListItem
&item
)
1011 m_mask
= item
.m_mask
;
1013 if ( m_mask
& wxLIST_MASK_TEXT
)
1014 m_text
= item
.m_text
;
1016 if ( m_mask
& wxLIST_MASK_IMAGE
)
1017 m_image
= item
.m_image
;
1019 if ( m_mask
& wxLIST_MASK_FORMAT
)
1020 m_format
= item
.m_format
;
1022 if ( m_mask
& wxLIST_MASK_WIDTH
)
1023 SetWidth(item
.m_width
);
1026 void wxListHeaderData::SetPosition( int x
, int y
)
1032 void wxListHeaderData::SetHeight( int h
)
1037 void wxListHeaderData::SetWidth( int w
)
1039 m_width
= w
< 0 ? WIDTH_COL_DEFAULT
: w
;
1042 void wxListHeaderData::SetFormat( int format
)
1047 bool wxListHeaderData::HasImage() const
1049 return m_image
!= -1;
1052 bool wxListHeaderData::IsHit( int x
, int y
) const
1054 return ((x
>= m_xpos
) && (x
<= m_xpos
+m_width
) && (y
>= m_ypos
) && (y
<= m_ypos
+m_height
));
1057 void wxListHeaderData::GetItem( wxListItem
& item
)
1059 item
.m_mask
= m_mask
;
1060 item
.m_text
= m_text
;
1061 item
.m_image
= m_image
;
1062 item
.m_format
= m_format
;
1063 item
.m_width
= m_width
;
1066 int wxListHeaderData::GetImage() const
1071 int wxListHeaderData::GetWidth() const
1076 int wxListHeaderData::GetFormat() const
1081 //-----------------------------------------------------------------------------
1083 //-----------------------------------------------------------------------------
1085 inline int wxListLineData::GetMode() const
1087 return m_owner
->GetListCtrl()->GetWindowStyleFlag() & wxLC_MASK_TYPE
;
1090 inline bool wxListLineData::InReportView() const
1092 return m_owner
->HasFlag(wxLC_REPORT
);
1095 inline bool wxListLineData::IsVirtual() const
1097 return m_owner
->IsVirtual();
1100 wxListLineData::wxListLineData( wxListMainWindow
*owner
)
1104 if ( InReportView() )
1107 m_gi
= new GeometryInfo
;
1109 m_highlighted
= false;
1111 InitItems( GetMode() == wxLC_REPORT
? m_owner
->GetColumnCount() : 1 );
1114 void wxListLineData::CalculateSize( wxDC
*dc
, int spacing
)
1116 wxListItemDataList::compatibility_iterator node
= m_items
.GetFirst();
1117 wxCHECK_RET( node
, _T("no subitems at all??") );
1119 wxListItemData
*item
= node
->GetData();
1124 switch ( GetMode() )
1127 case wxLC_SMALL_ICON
:
1128 m_gi
->m_rectAll
.width
= spacing
;
1130 s
= item
->GetText();
1135 m_gi
->m_rectLabel
.width
=
1136 m_gi
->m_rectLabel
.height
= 0;
1140 dc
->GetTextExtent( s
, &lw
, &lh
);
1144 m_gi
->m_rectAll
.height
= spacing
+ lh
;
1146 m_gi
->m_rectAll
.width
= lw
;
1148 m_gi
->m_rectLabel
.width
= lw
;
1149 m_gi
->m_rectLabel
.height
= lh
;
1152 if (item
->HasImage())
1155 m_owner
->GetImageSize( item
->GetImage(), w
, h
);
1156 m_gi
->m_rectIcon
.width
= w
+ 8;
1157 m_gi
->m_rectIcon
.height
= h
+ 8;
1159 if ( m_gi
->m_rectIcon
.width
> m_gi
->m_rectAll
.width
)
1160 m_gi
->m_rectAll
.width
= m_gi
->m_rectIcon
.width
;
1161 if ( m_gi
->m_rectIcon
.height
+ lh
> m_gi
->m_rectAll
.height
- 4 )
1162 m_gi
->m_rectAll
.height
= m_gi
->m_rectIcon
.height
+ lh
+ 4;
1165 if ( item
->HasText() )
1167 m_gi
->m_rectHighlight
.width
= m_gi
->m_rectLabel
.width
;
1168 m_gi
->m_rectHighlight
.height
= m_gi
->m_rectLabel
.height
;
1170 else // no text, highlight the icon
1172 m_gi
->m_rectHighlight
.width
= m_gi
->m_rectIcon
.width
;
1173 m_gi
->m_rectHighlight
.height
= m_gi
->m_rectIcon
.height
;
1178 s
= item
->GetTextForMeasuring();
1180 dc
->GetTextExtent( s
, &lw
, &lh
);
1184 m_gi
->m_rectLabel
.width
= lw
;
1185 m_gi
->m_rectLabel
.height
= lh
;
1187 m_gi
->m_rectAll
.width
= lw
;
1188 m_gi
->m_rectAll
.height
= lh
;
1190 if (item
->HasImage())
1193 m_owner
->GetImageSize( item
->GetImage(), w
, h
);
1194 m_gi
->m_rectIcon
.width
= w
;
1195 m_gi
->m_rectIcon
.height
= h
;
1197 m_gi
->m_rectAll
.width
+= 4 + w
;
1198 if (h
> m_gi
->m_rectAll
.height
)
1199 m_gi
->m_rectAll
.height
= h
;
1202 m_gi
->m_rectHighlight
.width
= m_gi
->m_rectAll
.width
;
1203 m_gi
->m_rectHighlight
.height
= m_gi
->m_rectAll
.height
;
1207 wxFAIL_MSG( _T("unexpected call to SetSize") );
1211 wxFAIL_MSG( _T("unknown mode") );
1216 void wxListLineData::SetPosition( int x
, int y
, int spacing
)
1218 wxListItemDataList::compatibility_iterator node
= m_items
.GetFirst();
1219 wxCHECK_RET( node
, _T("no subitems at all??") );
1221 wxListItemData
*item
= node
->GetData();
1223 switch ( GetMode() )
1226 case wxLC_SMALL_ICON
:
1227 m_gi
->m_rectAll
.x
= x
;
1228 m_gi
->m_rectAll
.y
= y
;
1230 if ( item
->HasImage() )
1232 m_gi
->m_rectIcon
.x
= m_gi
->m_rectAll
.x
+ 4 +
1233 (m_gi
->m_rectAll
.width
- m_gi
->m_rectIcon
.width
) / 2;
1234 m_gi
->m_rectIcon
.y
= m_gi
->m_rectAll
.y
+ 4;
1237 if ( item
->HasText() )
1239 if (m_gi
->m_rectAll
.width
> spacing
)
1240 m_gi
->m_rectLabel
.x
= m_gi
->m_rectAll
.x
+ 2;
1242 m_gi
->m_rectLabel
.x
= m_gi
->m_rectAll
.x
+ 2 + (spacing
/ 2) - (m_gi
->m_rectLabel
.width
/ 2);
1243 m_gi
->m_rectLabel
.y
= m_gi
->m_rectAll
.y
+ m_gi
->m_rectAll
.height
+ 2 - m_gi
->m_rectLabel
.height
;
1244 m_gi
->m_rectHighlight
.x
= m_gi
->m_rectLabel
.x
- 2;
1245 m_gi
->m_rectHighlight
.y
= m_gi
->m_rectLabel
.y
- 2;
1247 else // no text, highlight the icon
1249 m_gi
->m_rectHighlight
.x
= m_gi
->m_rectIcon
.x
- 4;
1250 m_gi
->m_rectHighlight
.y
= m_gi
->m_rectIcon
.y
- 4;
1255 m_gi
->m_rectAll
.x
= x
;
1256 m_gi
->m_rectAll
.y
= y
;
1258 m_gi
->m_rectHighlight
.x
= m_gi
->m_rectAll
.x
;
1259 m_gi
->m_rectHighlight
.y
= m_gi
->m_rectAll
.y
;
1260 m_gi
->m_rectLabel
.y
= m_gi
->m_rectAll
.y
+ 2;
1262 if (item
->HasImage())
1264 m_gi
->m_rectIcon
.x
= m_gi
->m_rectAll
.x
+ 2;
1265 m_gi
->m_rectIcon
.y
= m_gi
->m_rectAll
.y
+ 2;
1266 m_gi
->m_rectLabel
.x
= m_gi
->m_rectAll
.x
+ 6 + m_gi
->m_rectIcon
.width
;
1270 m_gi
->m_rectLabel
.x
= m_gi
->m_rectAll
.x
+ 2;
1275 wxFAIL_MSG( _T("unexpected call to SetPosition") );
1279 wxFAIL_MSG( _T("unknown mode") );
1284 void wxListLineData::InitItems( int num
)
1286 for (int i
= 0; i
< num
; i
++)
1287 m_items
.Append( new wxListItemData(m_owner
) );
1290 void wxListLineData::SetItem( int index
, const wxListItem
&info
)
1292 wxListItemDataList::compatibility_iterator node
= m_items
.Item( index
);
1293 wxCHECK_RET( node
, _T("invalid column index in SetItem") );
1295 wxListItemData
*item
= node
->GetData();
1296 item
->SetItem( info
);
1299 void wxListLineData::GetItem( int index
, wxListItem
&info
)
1301 wxListItemDataList::compatibility_iterator node
= m_items
.Item( index
);
1304 wxListItemData
*item
= node
->GetData();
1305 item
->GetItem( info
);
1309 wxString
wxListLineData::GetText(int index
) const
1313 wxListItemDataList::compatibility_iterator node
= m_items
.Item( index
);
1316 wxListItemData
*item
= node
->GetData();
1317 s
= item
->GetText();
1323 void wxListLineData::SetText( int index
, const wxString
& s
)
1325 wxListItemDataList::compatibility_iterator node
= m_items
.Item( index
);
1328 wxListItemData
*item
= node
->GetData();
1333 void wxListLineData::SetImage( int index
, int image
)
1335 wxListItemDataList::compatibility_iterator node
= m_items
.Item( index
);
1336 wxCHECK_RET( node
, _T("invalid column index in SetImage()") );
1338 wxListItemData
*item
= node
->GetData();
1339 item
->SetImage(image
);
1342 int wxListLineData::GetImage( int index
) const
1344 wxListItemDataList::compatibility_iterator node
= m_items
.Item( index
);
1345 wxCHECK_MSG( node
, -1, _T("invalid column index in GetImage()") );
1347 wxListItemData
*item
= node
->GetData();
1348 return item
->GetImage();
1351 wxListItemAttr
*wxListLineData::GetAttr() const
1353 wxListItemDataList::compatibility_iterator node
= m_items
.GetFirst();
1354 wxCHECK_MSG( node
, NULL
, _T("invalid column index in GetAttr()") );
1356 wxListItemData
*item
= node
->GetData();
1357 return item
->GetAttr();
1360 void wxListLineData::SetAttr(wxListItemAttr
*attr
)
1362 wxListItemDataList::compatibility_iterator node
= m_items
.GetFirst();
1363 wxCHECK_RET( node
, _T("invalid column index in SetAttr()") );
1365 wxListItemData
*item
= node
->GetData();
1366 item
->SetAttr(attr
);
1369 bool wxListLineData::SetAttributes(wxDC
*dc
,
1370 const wxListItemAttr
*attr
,
1373 wxWindow
*listctrl
= m_owner
->GetParent();
1377 // don't use foreground colour for drawing highlighted items - this might
1378 // make them completely invisible (and there is no way to do bit
1379 // arithmetics on wxColour, unfortunately)
1382 colText
= wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHTTEXT
);
1383 else if ( attr
&& attr
->HasTextColour() )
1384 colText
= attr
->GetTextColour();
1386 colText
= listctrl
->GetForegroundColour();
1388 dc
->SetTextForeground(colText
);
1392 if ( attr
&& attr
->HasFont() )
1393 font
= attr
->GetFont();
1395 font
= listctrl
->GetFont();
1400 bool hasBgCol
= attr
&& attr
->HasBackgroundColour();
1401 if ( highlighted
|| hasBgCol
)
1404 dc
->SetBrush( *m_owner
->GetHighlightBrush() );
1406 dc
->SetBrush(wxBrush(attr
->GetBackgroundColour(), wxSOLID
));
1408 dc
->SetPen( *wxTRANSPARENT_PEN
);
1416 void wxListLineData::Draw( wxDC
*dc
)
1418 wxListItemDataList::compatibility_iterator node
= m_items
.GetFirst();
1419 wxCHECK_RET( node
, _T("no subitems at all??") );
1421 bool highlighted
= IsHighlighted();
1423 wxListItemAttr
*attr
= GetAttr();
1425 if ( SetAttributes(dc
, attr
, highlighted
) )
1426 dc
->DrawRectangle( m_gi
->m_rectHighlight
);
1428 // just for debugging to better see where the items are
1430 dc
->SetPen(*wxRED_PEN
);
1431 dc
->SetBrush(*wxTRANSPARENT_BRUSH
);
1432 dc
->DrawRectangle( m_gi
->m_rectAll
);
1433 dc
->SetPen(*wxGREEN_PEN
);
1434 dc
->DrawRectangle( m_gi
->m_rectIcon
);
1437 wxListItemData
*item
= node
->GetData();
1438 if (item
->HasImage())
1440 // centre the image inside our rectangle, this looks nicer when items
1441 // ae aligned in a row
1442 const wxRect
& rectIcon
= m_gi
->m_rectIcon
;
1444 m_owner
->DrawImage(item
->GetImage(), dc
, rectIcon
.x
, rectIcon
.y
);
1447 if (item
->HasText())
1449 const wxRect
& rectLabel
= m_gi
->m_rectLabel
;
1451 wxDCClipper
clipper(*dc
, rectLabel
);
1452 dc
->DrawText(item
->GetText(), rectLabel
.x
, rectLabel
.y
);
1456 void wxListLineData::DrawInReportMode( wxDC
*dc
,
1458 const wxRect
& rectHL
,
1461 // TODO: later we should support setting different attributes for
1462 // different columns - to do it, just add "col" argument to
1463 // GetAttr() and move these lines into the loop below
1464 wxListItemAttr
*attr
= GetAttr();
1465 if ( SetAttributes(dc
, attr
, highlighted
) )
1466 dc
->DrawRectangle( rectHL
);
1468 wxCoord x
= rect
.x
+ HEADER_OFFSET_X
,
1469 yMid
= rect
.y
+ rect
.height
/2;
1472 for ( wxListItemDataList::compatibility_iterator node
= m_items
.GetFirst();
1474 node
= node
->GetNext(), col
++ )
1476 wxListItemData
*item
= node
->GetData();
1478 int width
= m_owner
->GetColumnWidth(col
);
1482 if ( item
->HasImage() )
1485 m_owner
->GetImageSize( item
->GetImage(), ix
, iy
);
1486 m_owner
->DrawImage( item
->GetImage(), dc
, xOld
, yMid
- iy
/2 );
1488 ix
+= IMAGE_MARGIN_IN_REPORT_MODE
;
1494 if ( item
->HasText() )
1495 DrawTextFormatted(dc
, item
->GetText(), col
, xOld
, yMid
, width
- 8);
1499 void wxListLineData::DrawTextFormatted(wxDC
*dc
,
1500 const wxString
&text
,
1507 dc
->GetTextExtent(text
, &w
, &h
);
1509 const wxCoord y
= yMid
- (h
+ 1)/2;
1511 wxDCClipper
clipper(*dc
, x
, y
, width
, h
);
1513 // determine if the string can fit inside the current width
1516 // it can, draw it using the items alignment
1518 m_owner
->GetColumn(col
, item
);
1519 switch ( item
.GetAlign() )
1521 case wxLIST_FORMAT_LEFT
:
1525 case wxLIST_FORMAT_RIGHT
:
1529 case wxLIST_FORMAT_CENTER
:
1530 x
+= (width
- w
) / 2;
1534 wxFAIL_MSG( _T("unknown list item format") );
1538 dc
->DrawText(text
, x
, y
);
1540 else // otherwise, truncate and add an ellipsis if possible
1542 // determine the base width
1543 wxString
ellipsis(wxT("..."));
1545 dc
->GetTextExtent(ellipsis
, &base_w
, &h
);
1547 // continue until we have enough space or only one character left
1549 size_t len
= text
.length();
1550 wxString drawntext
= text
.Left(len
);
1553 dc
->GetTextExtent(drawntext
.Last(), &w_c
, &h_c
);
1554 drawntext
.RemoveLast();
1557 if (w
+ base_w
<= width
)
1561 // if still not enough space, remove ellipsis characters
1562 while (ellipsis
.length() > 0 && w
+ base_w
> width
)
1564 ellipsis
= ellipsis
.Left(ellipsis
.length() - 1);
1565 dc
->GetTextExtent(ellipsis
, &base_w
, &h
);
1568 // now draw the text
1569 dc
->DrawText(drawntext
, x
, y
);
1570 dc
->DrawText(ellipsis
, x
+ w
, y
);
1574 bool wxListLineData::Highlight( bool on
)
1576 wxCHECK_MSG( !IsVirtual(), false, _T("unexpected call to Highlight") );
1578 if ( on
== m_highlighted
)
1586 void wxListLineData::ReverseHighlight( void )
1588 Highlight(!IsHighlighted());
1591 //-----------------------------------------------------------------------------
1592 // wxListHeaderWindow
1593 //-----------------------------------------------------------------------------
1595 IMPLEMENT_DYNAMIC_CLASS(wxListHeaderWindow
,wxWindow
)
1597 BEGIN_EVENT_TABLE(wxListHeaderWindow
,wxWindow
)
1598 EVT_PAINT (wxListHeaderWindow::OnPaint
)
1599 EVT_MOUSE_EVENTS (wxListHeaderWindow::OnMouse
)
1600 EVT_SET_FOCUS (wxListHeaderWindow::OnSetFocus
)
1603 void wxListHeaderWindow::Init()
1605 m_currentCursor
= (wxCursor
*) NULL
;
1606 m_isDragging
= false;
1610 wxListHeaderWindow::wxListHeaderWindow()
1614 m_owner
= (wxListMainWindow
*) NULL
;
1615 m_resizeCursor
= (wxCursor
*) NULL
;
1618 wxListHeaderWindow::wxListHeaderWindow( wxWindow
*win
,
1620 wxListMainWindow
*owner
,
1624 const wxString
&name
)
1625 : wxWindow( win
, id
, pos
, size
, style
, name
)
1630 m_resizeCursor
= new wxCursor( wxCURSOR_SIZEWE
);
1633 wxVisualAttributes attr
= wxPanel::GetClassDefaultAttributes();
1634 SetOwnForegroundColour( attr
.colFg
);
1635 SetOwnBackgroundColour( attr
.colBg
);
1637 SetOwnFont( attr
.font
);
1639 SetOwnForegroundColour( wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT
));
1640 SetOwnBackgroundColour( wxSystemSettings::GetColour(wxSYS_COLOUR_BTNFACE
));
1642 SetOwnFont( wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT
));
1646 wxListHeaderWindow::~wxListHeaderWindow()
1648 delete m_resizeCursor
;
1651 #ifdef __WXUNIVERSAL__
1652 #include "wx/univ/renderer.h"
1653 #include "wx/univ/theme.h"
1656 // shift the DC origin to match the position of the main window horz
1657 // scrollbar: this allows us to always use logical coords
1658 void wxListHeaderWindow::AdjustDC(wxDC
& dc
)
1661 m_owner
->GetScrollPixelsPerUnit( &xpix
, NULL
);
1664 m_owner
->GetViewStart( &view_start
, NULL
);
1669 dc
.GetDeviceOrigin( &org_x
, &org_y
);
1671 // account for the horz scrollbar offset
1673 if (GetLayoutDirection() == wxLayout_RightToLeft
)
1675 // Maybe we just have to check for m_signX
1676 // in the DC, but I leave the #ifdef __WXGTK__
1678 dc
.SetDeviceOrigin( org_x
+ (view_start
* xpix
), org_y
);
1682 dc
.SetDeviceOrigin( org_x
- (view_start
* xpix
), org_y
);
1685 void wxListHeaderWindow::OnPaint( wxPaintEvent
&WXUNUSED(event
) )
1687 wxPaintDC
dc( this );
1692 dc
.SetFont( GetFont() );
1694 // width and height of the entire header window
1696 GetClientSize( &w
, &h
);
1697 m_owner
->CalcUnscrolledPosition(w
, 0, &w
, NULL
);
1699 dc
.SetBackgroundMode(wxTRANSPARENT
);
1700 dc
.SetTextForeground(GetForegroundColour());
1702 int x
= HEADER_OFFSET_X
;
1703 int numColumns
= m_owner
->GetColumnCount();
1705 for ( int i
= 0; i
< numColumns
&& x
< w
; i
++ )
1707 m_owner
->GetColumn( i
, item
);
1708 int wCol
= item
.m_width
;
1710 // the width of the rect to draw: make it smaller to fit entirely
1711 // inside the column rect
1720 wxRendererNative::Get().DrawHeaderButton
1724 wxRect(x
, HEADER_OFFSET_Y
, cw
, ch
),
1725 m_parent
->IsEnabled() ? 0
1726 : (int)wxCONTROL_DISABLED
1729 // see if we have enough space for the column label
1731 // for this we need the width of the text
1734 dc
.GetTextExtent(item
.GetText(), &wLabel
, &hLabel
);
1735 wLabel
+= 2 * EXTRA_WIDTH
;
1737 // and the width of the icon, if any
1738 static const int MARGIN_BETWEEN_TEXT_AND_ICON
= 2;
1739 int ix
= 0, iy
= 0; // init them just to suppress the compiler warnings
1740 const int image
= item
.m_image
;
1741 wxImageList
*imageList
;
1744 imageList
= m_owner
->m_small_image_list
;
1747 imageList
->GetSize(image
, ix
, iy
);
1748 wLabel
+= ix
+ MARGIN_BETWEEN_TEXT_AND_ICON
;
1756 // ignore alignment if there is not enough space anyhow
1758 switch ( wLabel
< cw
? item
.GetAlign() : wxLIST_FORMAT_LEFT
)
1761 wxFAIL_MSG( _T("unknown list item format") );
1764 case wxLIST_FORMAT_LEFT
:
1768 case wxLIST_FORMAT_RIGHT
:
1769 xAligned
= x
+ cw
- wLabel
;
1772 case wxLIST_FORMAT_CENTER
:
1773 xAligned
= x
+ (cw
- wLabel
) / 2;
1777 // if we have an image, draw it on the right of the label
1784 xAligned
+ wLabel
- ix
- MARGIN_BETWEEN_TEXT_AND_ICON
,
1785 HEADER_OFFSET_Y
+ (h
- 4 - iy
)/2,
1786 wxIMAGELIST_DRAW_TRANSPARENT
1789 cw
-= ix
+ MARGIN_BETWEEN_TEXT_AND_ICON
;
1792 // draw the text clipping it so that it doesn't overwrite the column
1794 wxDCClipper
clipper(dc
, x
, HEADER_OFFSET_Y
, cw
, h
- 4 );
1796 dc
.DrawText( item
.GetText(),
1797 xAligned
+ EXTRA_WIDTH
, h
/ 2 - hLabel
/ 2 ); //HEADER_OFFSET_Y + EXTRA_HEIGHT );
1803 void wxListHeaderWindow::DrawCurrent()
1805 int x1
= m_currentX
;
1807 m_owner
->ClientToScreen( &x1
, &y1
);
1809 int x2
= m_currentX
;
1811 m_owner
->GetClientSize( NULL
, &y2
);
1812 m_owner
->ClientToScreen( &x2
, &y2
);
1815 dc
.SetLogicalFunction( wxINVERT
);
1816 dc
.SetPen( wxPen( *wxBLACK
, 2, wxSOLID
) );
1817 dc
.SetBrush( *wxTRANSPARENT_BRUSH
);
1821 dc
.DrawLine( x1
, y1
, x2
, y2
);
1823 dc
.SetLogicalFunction( wxCOPY
);
1825 dc
.SetPen( wxNullPen
);
1826 dc
.SetBrush( wxNullBrush
);
1829 void wxListHeaderWindow::OnMouse( wxMouseEvent
&event
)
1831 // we want to work with logical coords
1833 m_owner
->CalcUnscrolledPosition(event
.GetX(), 0, &x
, NULL
);
1834 int y
= event
.GetY();
1838 SendListEvent(wxEVT_COMMAND_LIST_COL_DRAGGING
, event
.GetPosition());
1840 // we don't draw the line beyond our window, but we allow dragging it
1843 GetClientSize( &w
, NULL
);
1844 m_owner
->CalcUnscrolledPosition(w
, 0, &w
, NULL
);
1847 // erase the line if it was drawn
1848 if ( m_currentX
< w
)
1851 if (event
.ButtonUp())
1854 m_isDragging
= false;
1856 m_owner
->SetColumnWidth( m_column
, m_currentX
- m_minX
);
1857 SendListEvent(wxEVT_COMMAND_LIST_COL_END_DRAG
, event
.GetPosition());
1864 m_currentX
= m_minX
+ 7;
1866 // draw in the new location
1867 if ( m_currentX
< w
)
1871 else // not dragging
1874 bool hit_border
= false;
1876 // end of the current column
1879 // find the column where this event occurred
1881 countCol
= m_owner
->GetColumnCount();
1882 for (col
= 0; col
< countCol
; col
++)
1884 xpos
+= m_owner
->GetColumnWidth( col
);
1887 if ( (abs(x
-xpos
) < 3) && (y
< 22) )
1889 // near the column border
1896 // inside the column
1903 if ( col
== countCol
)
1906 if (event
.LeftDown() || event
.RightUp())
1908 if (hit_border
&& event
.LeftDown())
1910 if ( SendListEvent(wxEVT_COMMAND_LIST_COL_BEGIN_DRAG
,
1911 event
.GetPosition()) )
1913 m_isDragging
= true;
1918 //else: column resizing was vetoed by the user code
1920 else // click on a column
1922 SendListEvent( event
.LeftDown()
1923 ? wxEVT_COMMAND_LIST_COL_CLICK
1924 : wxEVT_COMMAND_LIST_COL_RIGHT_CLICK
,
1925 event
.GetPosition());
1928 else if (event
.Moving())
1933 setCursor
= m_currentCursor
== wxSTANDARD_CURSOR
;
1934 m_currentCursor
= m_resizeCursor
;
1938 setCursor
= m_currentCursor
!= wxSTANDARD_CURSOR
;
1939 m_currentCursor
= wxSTANDARD_CURSOR
;
1943 SetCursor(*m_currentCursor
);
1948 void wxListHeaderWindow::OnSetFocus( wxFocusEvent
&WXUNUSED(event
) )
1950 m_owner
->SetFocus();
1954 bool wxListHeaderWindow::SendListEvent(wxEventType type
, const wxPoint
& pos
)
1956 wxWindow
*parent
= GetParent();
1957 wxListEvent
le( type
, parent
->GetId() );
1958 le
.SetEventObject( parent
);
1959 le
.m_pointDrag
= pos
;
1961 // the position should be relative to the parent window, not
1962 // this one for compatibility with MSW and common sense: the
1963 // user code doesn't know anything at all about this header
1964 // window, so why should it get positions relative to it?
1965 le
.m_pointDrag
.y
-= GetSize().y
;
1967 le
.m_col
= m_column
;
1968 return !parent
->GetEventHandler()->ProcessEvent( le
) || le
.IsAllowed();
1971 //-----------------------------------------------------------------------------
1972 // wxListRenameTimer (internal)
1973 //-----------------------------------------------------------------------------
1975 wxListRenameTimer::wxListRenameTimer( wxListMainWindow
*owner
)
1980 void wxListRenameTimer::Notify()
1982 m_owner
->OnRenameTimer();
1985 //-----------------------------------------------------------------------------
1986 // wxListTextCtrlWrapper (internal)
1987 //-----------------------------------------------------------------------------
1989 BEGIN_EVENT_TABLE(wxListTextCtrlWrapper
, wxEvtHandler
)
1990 EVT_CHAR (wxListTextCtrlWrapper::OnChar
)
1991 EVT_KEY_UP (wxListTextCtrlWrapper::OnKeyUp
)
1992 EVT_KILL_FOCUS (wxListTextCtrlWrapper::OnKillFocus
)
1995 wxListTextCtrlWrapper::wxListTextCtrlWrapper(wxListMainWindow
*owner
,
1998 : m_startValue(owner
->GetItemText(itemEdit
)),
1999 m_itemEdited(itemEdit
)
2004 m_aboutToFinish
= false;
2006 wxRect rectLabel
= owner
->GetLineLabelRect(itemEdit
);
2008 m_owner
->CalcScrolledPosition(rectLabel
.x
, rectLabel
.y
,
2009 &rectLabel
.x
, &rectLabel
.y
);
2011 m_text
->Create(owner
, wxID_ANY
, m_startValue
,
2012 wxPoint(rectLabel
.x
-4,rectLabel
.y
-4),
2013 wxSize(rectLabel
.width
+11,rectLabel
.height
+8));
2016 m_text
->PushEventHandler(this);
2019 void wxListTextCtrlWrapper::Finish()
2025 m_text
->RemoveEventHandler(this);
2026 m_owner
->FinishEditing(m_text
);
2028 wxPendingDelete
.Append( this );
2032 bool wxListTextCtrlWrapper::AcceptChanges()
2034 const wxString value
= m_text
->GetValue();
2036 if ( value
== m_startValue
)
2037 // nothing changed, always accept
2040 if ( !m_owner
->OnRenameAccept(m_itemEdited
, value
) )
2041 // vetoed by the user
2044 // accepted, do rename the item
2045 m_owner
->SetItemText(m_itemEdited
, value
);
2050 void wxListTextCtrlWrapper::AcceptChangesAndFinish()
2052 m_aboutToFinish
= true;
2054 // Notify the owner about the changes
2057 // Even if vetoed, close the control (consistent with MSW)
2061 void wxListTextCtrlWrapper::OnChar( wxKeyEvent
&event
)
2063 switch ( event
.m_keyCode
)
2066 AcceptChangesAndFinish();
2070 m_owner
->OnRenameCancelled( m_itemEdited
);
2079 void wxListTextCtrlWrapper::OnKeyUp( wxKeyEvent
&event
)
2087 // auto-grow the textctrl:
2088 wxSize parentSize
= m_owner
->GetSize();
2089 wxPoint myPos
= m_text
->GetPosition();
2090 wxSize mySize
= m_text
->GetSize();
2092 m_text
->GetTextExtent(m_text
->GetValue() + _T("MM"), &sx
, &sy
);
2093 if (myPos
.x
+ sx
> parentSize
.x
)
2094 sx
= parentSize
.x
- myPos
.x
;
2097 m_text
->SetSize(sx
, wxDefaultCoord
);
2102 void wxListTextCtrlWrapper::OnKillFocus( wxFocusEvent
&event
)
2104 if ( !m_finished
&& !m_aboutToFinish
)
2106 if ( !AcceptChanges() )
2107 m_owner
->OnRenameCancelled( m_itemEdited
);
2112 // We must let the native text control handle focus
2116 //-----------------------------------------------------------------------------
2118 //-----------------------------------------------------------------------------
2120 IMPLEMENT_DYNAMIC_CLASS(wxListMainWindow
,wxScrolledWindow
)
2122 BEGIN_EVENT_TABLE(wxListMainWindow
,wxScrolledWindow
)
2123 EVT_PAINT (wxListMainWindow::OnPaint
)
2124 EVT_MOUSE_EVENTS (wxListMainWindow::OnMouse
)
2125 EVT_CHAR (wxListMainWindow::OnChar
)
2126 EVT_KEY_DOWN (wxListMainWindow::OnKeyDown
)
2127 EVT_SET_FOCUS (wxListMainWindow::OnSetFocus
)
2128 EVT_KILL_FOCUS (wxListMainWindow::OnKillFocus
)
2129 EVT_SCROLLWIN (wxListMainWindow::OnScroll
)
2132 void wxListMainWindow::Init()
2137 m_lineTo
= (size_t)-1;
2143 m_small_image_list
= (wxImageList
*) NULL
;
2144 m_normal_image_list
= (wxImageList
*) NULL
;
2146 m_small_spacing
= 30;
2147 m_normal_spacing
= 40;
2151 m_isCreated
= false;
2153 m_lastOnSame
= false;
2154 m_renameTimer
= new wxListRenameTimer( this );
2155 m_textctrlWrapper
= NULL
;
2159 m_lineSelectSingleOnUp
=
2160 m_lineBeforeLastClicked
= (size_t)-1;
2165 wxListMainWindow::wxListMainWindow()
2170 m_highlightUnfocusedBrush
= (wxBrush
*) NULL
;
2173 wxListMainWindow::wxListMainWindow( wxWindow
*parent
,
2178 const wxString
&name
)
2179 : wxScrolledWindow( parent
, id
, pos
, size
,
2180 style
| wxHSCROLL
| wxVSCROLL
, name
)
2184 m_highlightBrush
= new wxBrush
2186 wxSystemSettings::GetColour
2188 wxSYS_COLOUR_HIGHLIGHT
2193 m_highlightUnfocusedBrush
= new wxBrush
2195 wxSystemSettings::GetColour
2197 wxSYS_COLOUR_BTNSHADOW
2202 SetScrollbars( 0, 0, 0, 0, 0, 0 );
2204 wxVisualAttributes attr
= wxGenericListCtrl::GetClassDefaultAttributes();
2205 SetOwnForegroundColour( attr
.colFg
);
2206 SetOwnBackgroundColour( attr
.colBg
);
2208 SetOwnFont( attr
.font
);
2211 wxListMainWindow::~wxListMainWindow()
2214 WX_CLEAR_LIST(wxListHeaderDataList
, m_columns
);
2215 WX_CLEAR_ARRAY(m_aColWidths
);
2217 delete m_highlightBrush
;
2218 delete m_highlightUnfocusedBrush
;
2219 delete m_renameTimer
;
2222 void wxListMainWindow::CacheLineData(size_t line
)
2224 wxGenericListCtrl
*listctrl
= GetListCtrl();
2226 wxListLineData
*ld
= GetDummyLine();
2228 size_t countCol
= GetColumnCount();
2229 for ( size_t col
= 0; col
< countCol
; col
++ )
2231 ld
->SetText(col
, listctrl
->OnGetItemText(line
, col
));
2232 ld
->SetImage(col
, listctrl
->OnGetItemColumnImage(line
, col
));
2235 ld
->SetAttr(listctrl
->OnGetItemAttr(line
));
2238 wxListLineData
*wxListMainWindow::GetDummyLine() const
2240 wxASSERT_MSG( !IsEmpty(), _T("invalid line index") );
2241 wxASSERT_MSG( IsVirtual(), _T("GetDummyLine() shouldn't be called") );
2243 wxListMainWindow
*self
= wxConstCast(this, wxListMainWindow
);
2245 // we need to recreate the dummy line if the number of columns in the
2246 // control changed as it would have the incorrect number of fields
2248 if ( !m_lines
.IsEmpty() &&
2249 m_lines
[0].m_items
.GetCount() != (size_t)GetColumnCount() )
2251 self
->m_lines
.Clear();
2254 if ( m_lines
.IsEmpty() )
2256 wxListLineData
*line
= new wxListLineData(self
);
2257 self
->m_lines
.Add(line
);
2259 // don't waste extra memory -- there never going to be anything
2260 // else/more in this array
2261 self
->m_lines
.Shrink();
2267 // ----------------------------------------------------------------------------
2268 // line geometry (report mode only)
2269 // ----------------------------------------------------------------------------
2271 wxCoord
wxListMainWindow::GetLineHeight() const
2273 // we cache the line height as calling GetTextExtent() is slow
2274 if ( !m_lineHeight
)
2276 wxListMainWindow
*self
= wxConstCast(this, wxListMainWindow
);
2278 wxClientDC
dc( self
);
2279 dc
.SetFont( GetFont() );
2282 dc
.GetTextExtent(_T("H"), NULL
, &y
);
2284 if ( m_small_image_list
&& m_small_image_list
->GetImageCount() )
2287 m_small_image_list
->GetSize(0, iw
, ih
);
2292 self
->m_lineHeight
= y
+ LINE_SPACING
;
2295 return m_lineHeight
;
2298 wxCoord
wxListMainWindow::GetLineY(size_t line
) const
2300 wxASSERT_MSG( InReportView(), _T("only works in report mode") );
2302 return LINE_SPACING
+ line
* GetLineHeight();
2305 wxRect
wxListMainWindow::GetLineRect(size_t line
) const
2307 if ( !InReportView() )
2308 return GetLine(line
)->m_gi
->m_rectAll
;
2311 rect
.x
= HEADER_OFFSET_X
;
2312 rect
.y
= GetLineY(line
);
2313 rect
.width
= GetHeaderWidth();
2314 rect
.height
= GetLineHeight();
2319 wxRect
wxListMainWindow::GetLineLabelRect(size_t line
) const
2321 if ( !InReportView() )
2322 return GetLine(line
)->m_gi
->m_rectLabel
;
2325 rect
.x
= HEADER_OFFSET_X
;
2326 rect
.y
= GetLineY(line
);
2327 rect
.width
= GetColumnWidth(0);
2328 rect
.height
= GetLineHeight();
2333 wxRect
wxListMainWindow::GetLineIconRect(size_t line
) const
2335 if ( !InReportView() )
2336 return GetLine(line
)->m_gi
->m_rectIcon
;
2338 wxListLineData
*ld
= GetLine(line
);
2339 wxASSERT_MSG( ld
->HasImage(), _T("should have an image") );
2342 rect
.x
= HEADER_OFFSET_X
;
2343 rect
.y
= GetLineY(line
);
2344 GetImageSize(ld
->GetImage(), rect
.width
, rect
.height
);
2349 wxRect
wxListMainWindow::GetLineHighlightRect(size_t line
) const
2351 return InReportView() ? GetLineRect(line
)
2352 : GetLine(line
)->m_gi
->m_rectHighlight
;
2355 long wxListMainWindow::HitTestLine(size_t line
, int x
, int y
) const
2357 wxASSERT_MSG( line
< GetItemCount(), _T("invalid line in HitTestLine") );
2359 wxListLineData
*ld
= GetLine(line
);
2361 if ( ld
->HasImage() && GetLineIconRect(line
).Contains(x
, y
) )
2362 return wxLIST_HITTEST_ONITEMICON
;
2364 // VS: Testing for "ld->HasText() || InReportView()" instead of
2365 // "ld->HasText()" is needed to make empty lines in report view
2367 if ( ld
->HasText() || InReportView() )
2369 wxRect rect
= InReportView() ? GetLineRect(line
)
2370 : GetLineLabelRect(line
);
2372 if ( rect
.Contains(x
, y
) )
2373 return wxLIST_HITTEST_ONITEMLABEL
;
2379 // ----------------------------------------------------------------------------
2380 // highlight (selection) handling
2381 // ----------------------------------------------------------------------------
2383 bool wxListMainWindow::IsHighlighted(size_t line
) const
2387 return m_selStore
.IsSelected(line
);
2391 wxListLineData
*ld
= GetLine(line
);
2392 wxCHECK_MSG( ld
, false, _T("invalid index in IsHighlighted") );
2394 return ld
->IsHighlighted();
2398 void wxListMainWindow::HighlightLines( size_t lineFrom
,
2404 wxArrayInt linesChanged
;
2405 if ( !m_selStore
.SelectRange(lineFrom
, lineTo
, highlight
,
2408 // meny items changed state, refresh everything
2409 RefreshLines(lineFrom
, lineTo
);
2411 else // only a few items changed state, refresh only them
2413 size_t count
= linesChanged
.GetCount();
2414 for ( size_t n
= 0; n
< count
; n
++ )
2416 RefreshLine(linesChanged
[n
]);
2420 else // iterate over all items in non report view
2422 for ( size_t line
= lineFrom
; line
<= lineTo
; line
++ )
2424 if ( HighlightLine(line
, highlight
) )
2430 bool wxListMainWindow::HighlightLine( size_t line
, bool highlight
)
2436 changed
= m_selStore
.SelectItem(line
, highlight
);
2440 wxListLineData
*ld
= GetLine(line
);
2441 wxCHECK_MSG( ld
, false, _T("invalid index in HighlightLine") );
2443 changed
= ld
->Highlight(highlight
);
2448 SendNotify( line
, highlight
? wxEVT_COMMAND_LIST_ITEM_SELECTED
2449 : wxEVT_COMMAND_LIST_ITEM_DESELECTED
);
2455 void wxListMainWindow::RefreshLine( size_t line
)
2457 if ( InReportView() )
2459 size_t visibleFrom
, visibleTo
;
2460 GetVisibleLinesRange(&visibleFrom
, &visibleTo
);
2462 if ( line
< visibleFrom
|| line
> visibleTo
)
2466 wxRect rect
= GetLineRect(line
);
2468 CalcScrolledPosition( rect
.x
, rect
.y
, &rect
.x
, &rect
.y
);
2469 RefreshRect( rect
);
2472 void wxListMainWindow::RefreshLines( size_t lineFrom
, size_t lineTo
)
2474 // we suppose that they are ordered by caller
2475 wxASSERT_MSG( lineFrom
<= lineTo
, _T("indices in disorder") );
2477 wxASSERT_MSG( lineTo
< GetItemCount(), _T("invalid line range") );
2479 if ( InReportView() )
2481 size_t visibleFrom
, visibleTo
;
2482 GetVisibleLinesRange(&visibleFrom
, &visibleTo
);
2484 if ( lineFrom
< visibleFrom
)
2485 lineFrom
= visibleFrom
;
2486 if ( lineTo
> visibleTo
)
2491 rect
.y
= GetLineY(lineFrom
);
2492 rect
.width
= GetClientSize().x
;
2493 rect
.height
= GetLineY(lineTo
) - rect
.y
+ GetLineHeight();
2495 CalcScrolledPosition( rect
.x
, rect
.y
, &rect
.x
, &rect
.y
);
2496 RefreshRect( rect
);
2500 // TODO: this should be optimized...
2501 for ( size_t line
= lineFrom
; line
<= lineTo
; line
++ )
2508 void wxListMainWindow::RefreshAfter( size_t lineFrom
)
2510 if ( InReportView() )
2512 size_t visibleFrom
, visibleTo
;
2513 GetVisibleLinesRange(&visibleFrom
, &visibleTo
);
2515 if ( lineFrom
< visibleFrom
)
2516 lineFrom
= visibleFrom
;
2517 else if ( lineFrom
> visibleTo
)
2522 rect
.y
= GetLineY(lineFrom
);
2523 CalcScrolledPosition( rect
.x
, rect
.y
, &rect
.x
, &rect
.y
);
2525 wxSize size
= GetClientSize();
2526 rect
.width
= size
.x
;
2528 // refresh till the bottom of the window
2529 rect
.height
= size
.y
- rect
.y
;
2531 RefreshRect( rect
);
2535 // TODO: how to do it more efficiently?
2540 void wxListMainWindow::RefreshSelected()
2546 if ( InReportView() )
2548 GetVisibleLinesRange(&from
, &to
);
2553 to
= GetItemCount() - 1;
2556 if ( HasCurrent() && m_current
>= from
&& m_current
<= to
)
2557 RefreshLine(m_current
);
2559 for ( size_t line
= from
; line
<= to
; line
++ )
2561 // NB: the test works as expected even if m_current == -1
2562 if ( line
!= m_current
&& IsHighlighted(line
) )
2567 void wxListMainWindow::Freeze()
2572 void wxListMainWindow::Thaw()
2574 wxCHECK_RET( m_freezeCount
> 0, _T("thawing unfrozen list control?") );
2576 if ( --m_freezeCount
== 0 )
2580 void wxListMainWindow::OnPaint( wxPaintEvent
&WXUNUSED(event
) )
2582 // Note: a wxPaintDC must be constructed even if no drawing is
2583 // done (a Windows requirement).
2584 wxPaintDC
dc( this );
2586 if ( IsEmpty() || m_freezeCount
)
2587 // nothing to draw or not the moment to draw it
2591 // delay the repainting until we calculate all the items positions
2597 CalcScrolledPosition( 0, 0, &dev_x
, &dev_y
);
2599 dc
.SetFont( GetFont() );
2601 if ( InReportView() )
2603 int lineHeight
= GetLineHeight();
2605 size_t visibleFrom
, visibleTo
;
2606 GetVisibleLinesRange(&visibleFrom
, &visibleTo
);
2609 int xOrig
= dc
.LogicalToDeviceX( 0 );
2610 int yOrig
= dc
.LogicalToDeviceY( 0 );
2612 // tell the caller cache to cache the data
2615 wxListEvent
evCache(wxEVT_COMMAND_LIST_CACHE_HINT
,
2616 GetParent()->GetId());
2617 evCache
.SetEventObject( GetParent() );
2618 evCache
.m_oldItemIndex
= visibleFrom
;
2619 evCache
.m_itemIndex
= visibleTo
;
2620 GetParent()->GetEventHandler()->ProcessEvent( evCache
);
2623 for ( size_t line
= visibleFrom
; line
<= visibleTo
; line
++ )
2625 rectLine
= GetLineRect(line
);
2628 if ( !IsExposed(rectLine
.x
+ xOrig
, rectLine
.y
+ yOrig
,
2629 rectLine
.width
, rectLine
.height
) )
2631 // don't redraw unaffected lines to avoid flicker
2635 GetLine(line
)->DrawInReportMode( &dc
,
2637 GetLineHighlightRect(line
),
2638 IsHighlighted(line
) );
2641 if ( HasFlag(wxLC_HRULES
) )
2643 wxPen
pen(GetRuleColour(), 1, wxSOLID
);
2644 wxSize clientSize
= GetClientSize();
2646 // Don't draw the first one
2647 for ( size_t i
= visibleFrom
+ 1; i
<= visibleTo
; i
++ )
2650 dc
.SetBrush( *wxTRANSPARENT_BRUSH
);
2651 dc
.DrawLine(0 - dev_x
, i
* lineHeight
,
2652 clientSize
.x
- dev_x
, i
* lineHeight
);
2655 // Draw last horizontal rule
2656 if ( visibleTo
== GetItemCount() - 1 )
2659 dc
.SetBrush( *wxTRANSPARENT_BRUSH
);
2660 dc
.DrawLine(0 - dev_x
, (m_lineTo
+ 1) * lineHeight
,
2661 clientSize
.x
- dev_x
, (m_lineTo
+ 1) * lineHeight
);
2665 // Draw vertical rules if required
2666 if ( HasFlag(wxLC_VRULES
) && !IsEmpty() )
2668 wxPen
pen(GetRuleColour(), 1, wxSOLID
);
2669 wxRect firstItemRect
, lastItemRect
;
2671 GetItemRect(visibleFrom
, firstItemRect
);
2672 GetItemRect(visibleTo
, lastItemRect
);
2673 int x
= firstItemRect
.GetX();
2675 dc
.SetBrush(* wxTRANSPARENT_BRUSH
);
2677 for (int col
= 0; col
< GetColumnCount(); col
++)
2679 int colWidth
= GetColumnWidth(col
);
2681 dc
.DrawLine(x
- dev_x
- 2, firstItemRect
.GetY() - 1 - dev_y
,
2682 x
- dev_x
- 2, lastItemRect
.GetBottom() + 1 - dev_y
);
2688 size_t count
= GetItemCount();
2689 for ( size_t i
= 0; i
< count
; i
++ )
2691 GetLine(i
)->Draw( &dc
);
2696 // Don't draw rect outline under Mac at all.
2701 dc
.SetPen( *wxBLACK_PEN
);
2702 dc
.SetBrush( *wxTRANSPARENT_BRUSH
);
2703 dc
.DrawRectangle( GetLineHighlightRect( m_current
) );
2709 void wxListMainWindow::HighlightAll( bool on
)
2711 if ( IsSingleSel() )
2713 wxASSERT_MSG( !on
, _T("can't do this in a single selection control") );
2715 // we just have one item to turn off
2716 if ( HasCurrent() && IsHighlighted(m_current
) )
2718 HighlightLine(m_current
, false);
2719 RefreshLine(m_current
);
2724 HighlightLines(0, GetItemCount() - 1, on
);
2728 void wxListMainWindow::SendNotify( size_t line
,
2729 wxEventType command
,
2730 const wxPoint
& point
)
2732 wxListEvent
le( command
, GetParent()->GetId() );
2733 le
.SetEventObject( GetParent() );
2734 le
.m_itemIndex
= line
;
2736 // set only for events which have position
2737 if ( point
!= wxDefaultPosition
)
2738 le
.m_pointDrag
= point
;
2740 // don't try to get the line info for virtual list controls: the main
2741 // program has it anyhow and if we did it would result in accessing all
2742 // the lines, even those which are not visible now and this is precisely
2743 // what we're trying to avoid
2744 if ( !IsVirtual() && (command
!= wxEVT_COMMAND_LIST_DELETE_ITEM
) )
2746 if ( line
!= (size_t)-1 )
2748 GetLine(line
)->GetItem( 0, le
.m_item
);
2750 //else: this happens for wxEVT_COMMAND_LIST_ITEM_FOCUSED event
2752 //else: there may be no more such item
2754 GetParent()->GetEventHandler()->ProcessEvent( le
);
2757 void wxListMainWindow::ChangeCurrent(size_t current
)
2759 m_current
= current
;
2761 SendNotify(current
, wxEVT_COMMAND_LIST_ITEM_FOCUSED
);
2764 wxTextCtrl
*wxListMainWindow::EditLabel(long item
, wxClassInfo
* textControlClass
)
2766 wxCHECK_MSG( (item
>= 0) && ((size_t)item
< GetItemCount()), NULL
,
2767 wxT("wrong index in wxGenericListCtrl::EditLabel()") );
2769 wxASSERT_MSG( textControlClass
->IsKindOf(CLASSINFO(wxTextCtrl
)),
2770 wxT("EditLabel() needs a text control") );
2772 size_t itemEdit
= (size_t)item
;
2774 wxListEvent
le( wxEVT_COMMAND_LIST_BEGIN_LABEL_EDIT
, GetParent()->GetId() );
2775 le
.SetEventObject( GetParent() );
2776 le
.m_itemIndex
= item
;
2777 wxListLineData
*data
= GetLine(itemEdit
);
2778 wxCHECK_MSG( data
, NULL
, _T("invalid index in EditLabel()") );
2779 data
->GetItem( 0, le
.m_item
);
2781 if ( GetParent()->GetEventHandler()->ProcessEvent( le
) && !le
.IsAllowed() )
2783 // vetoed by user code
2787 // We have to call this here because the label in question might just have
2788 // been added and no screen update taken place.
2792 wxTextCtrl
* const text
= (wxTextCtrl
*)textControlClass
->CreateObject();
2793 m_textctrlWrapper
= new wxListTextCtrlWrapper(this, text
, item
);
2794 return m_textctrlWrapper
->GetText();
2797 void wxListMainWindow::OnRenameTimer()
2799 wxCHECK_RET( HasCurrent(), wxT("unexpected rename timer") );
2801 EditLabel( m_current
);
2804 bool wxListMainWindow::OnRenameAccept(size_t itemEdit
, const wxString
& value
)
2806 wxListEvent
le( wxEVT_COMMAND_LIST_END_LABEL_EDIT
, GetParent()->GetId() );
2807 le
.SetEventObject( GetParent() );
2808 le
.m_itemIndex
= itemEdit
;
2810 wxListLineData
*data
= GetLine(itemEdit
);
2812 wxCHECK_MSG( data
, false, _T("invalid index in OnRenameAccept()") );
2814 data
->GetItem( 0, le
.m_item
);
2815 le
.m_item
.m_text
= value
;
2816 return !GetParent()->GetEventHandler()->ProcessEvent( le
) ||
2820 void wxListMainWindow::OnRenameCancelled(size_t itemEdit
)
2822 // let owner know that the edit was cancelled
2823 wxListEvent
le( wxEVT_COMMAND_LIST_END_LABEL_EDIT
, GetParent()->GetId() );
2825 le
.SetEditCanceled(true);
2827 le
.SetEventObject( GetParent() );
2828 le
.m_itemIndex
= itemEdit
;
2830 wxListLineData
*data
= GetLine(itemEdit
);
2831 wxCHECK_RET( data
, _T("invalid index in OnRenameCancelled()") );
2833 data
->GetItem( 0, le
.m_item
);
2834 GetEventHandler()->ProcessEvent( le
);
2837 void wxListMainWindow::OnMouse( wxMouseEvent
&event
)
2841 // On wxMac we can't depend on the EVT_KILL_FOCUS event to properly
2842 // shutdown the edit control when the mouse is clicked elsewhere on the
2843 // listctrl because the order of events is different (or something like
2844 // that), so explicitly end the edit if it is active.
2845 if ( event
.LeftDown() && m_textctrlWrapper
)
2846 m_textctrlWrapper
->AcceptChangesAndFinish();
2849 event
.SetEventObject( GetParent() );
2850 if ( GetParent()->GetEventHandler()->ProcessEvent( event
) )
2853 if (event
.GetEventType() == wxEVT_MOUSEWHEEL
)
2855 // let the base handle mouse wheel events.
2860 if ( !HasCurrent() || IsEmpty() )
2862 if (event
.RightDown())
2864 SendNotify( (size_t)-1, wxEVT_COMMAND_LIST_ITEM_RIGHT_CLICK
, event
.GetPosition() );
2865 // Allow generation of context menu event
2874 if ( !(event
.Dragging() || event
.ButtonDown() || event
.LeftUp() ||
2875 event
.ButtonDClick()) )
2878 int x
= event
.GetX();
2879 int y
= event
.GetY();
2880 CalcUnscrolledPosition( x
, y
, &x
, &y
);
2882 // where did we hit it (if we did)?
2885 size_t count
= GetItemCount(),
2888 if ( InReportView() )
2890 current
= y
/ GetLineHeight();
2891 if ( current
< count
)
2892 hitResult
= HitTestLine(current
, x
, y
);
2896 // TODO: optimize it too! this is less simple than for report view but
2897 // enumerating all items is still not a way to do it!!
2898 for ( current
= 0; current
< count
; current
++ )
2900 hitResult
= HitTestLine(current
, x
, y
);
2906 if (event
.Dragging())
2908 if (m_dragCount
== 0)
2910 // we have to report the raw, physical coords as we want to be
2911 // able to call HitTest(event.m_pointDrag) from the user code to
2912 // get the item being dragged
2913 m_dragStart
= event
.GetPosition();
2918 if (m_dragCount
!= 3)
2921 int command
= event
.RightIsDown() ? wxEVT_COMMAND_LIST_BEGIN_RDRAG
2922 : wxEVT_COMMAND_LIST_BEGIN_DRAG
;
2924 wxListEvent
le( command
, GetParent()->GetId() );
2925 le
.SetEventObject( GetParent() );
2926 le
.m_itemIndex
= m_lineLastClicked
;
2927 le
.m_pointDrag
= m_dragStart
;
2928 GetParent()->GetEventHandler()->ProcessEvent( le
);
2939 // outside of any item
2940 if (event
.RightDown())
2942 SendNotify( (size_t) -1, wxEVT_COMMAND_LIST_ITEM_RIGHT_CLICK
, event
.GetPosition() );
2943 // Allow generation of context menu event
2948 // reset the selection and bail out
2949 HighlightAll(false);
2955 bool forceClick
= false;
2956 if (event
.ButtonDClick())
2958 m_renameTimer
->Stop();
2959 m_lastOnSame
= false;
2961 if ( current
== m_lineLastClicked
)
2963 SendNotify( current
, wxEVT_COMMAND_LIST_ITEM_ACTIVATED
);
2969 // The first click was on another item, so don't interpret this as
2970 // a double click, but as a simple click instead
2977 if (m_lineSelectSingleOnUp
!= (size_t)-1)
2979 // select single line
2980 HighlightAll( false );
2981 ReverseHighlight(m_lineSelectSingleOnUp
);
2986 if ((current
== m_current
) &&
2987 (hitResult
== wxLIST_HITTEST_ONITEMLABEL
) &&
2988 HasFlag(wxLC_EDIT_LABELS
) )
2990 m_renameTimer
->Start( 100, true );
2994 m_lastOnSame
= false;
2995 m_lineSelectSingleOnUp
= (size_t)-1;
2999 // This is necessary, because after a DnD operation in
3000 // from and to ourself, the up event is swallowed by the
3001 // DnD code. So on next non-up event (which means here and
3002 // now) m_lineSelectSingleOnUp should be reset.
3003 m_lineSelectSingleOnUp
= (size_t)-1;
3005 if (event
.RightDown())
3007 m_lineBeforeLastClicked
= m_lineLastClicked
;
3008 m_lineLastClicked
= current
;
3010 // If the item is already selected, do not update the selection.
3011 // Multi-selections should not be cleared if a selected item is clicked.
3012 if (!IsHighlighted(current
))
3014 HighlightAll(false);
3015 ChangeCurrent(current
);
3016 ReverseHighlight(m_current
);
3019 SendNotify( current
, wxEVT_COMMAND_LIST_ITEM_RIGHT_CLICK
, event
.GetPosition() );
3021 // Allow generation of context menu event
3024 else if (event
.MiddleDown())
3026 SendNotify( current
, wxEVT_COMMAND_LIST_ITEM_MIDDLE_CLICK
);
3028 else if ( event
.LeftDown() || forceClick
)
3030 m_lineBeforeLastClicked
= m_lineLastClicked
;
3031 m_lineLastClicked
= current
;
3033 size_t oldCurrent
= m_current
;
3034 bool oldWasSelected
= IsHighlighted(m_current
);
3036 bool cmdModifierDown
= event
.CmdDown();
3037 if ( IsSingleSel() || !(cmdModifierDown
|| event
.ShiftDown()) )
3039 if ( IsSingleSel() || !IsHighlighted(current
) )
3041 HighlightAll( false );
3043 ChangeCurrent(current
);
3045 ReverseHighlight(m_current
);
3047 else // multi sel & current is highlighted & no mod keys
3049 m_lineSelectSingleOnUp
= current
;
3050 ChangeCurrent(current
); // change focus
3053 else // multi sel & either ctrl or shift is down
3055 if (cmdModifierDown
)
3057 ChangeCurrent(current
);
3059 ReverseHighlight(m_current
);
3061 else if (event
.ShiftDown())
3063 ChangeCurrent(current
);
3065 size_t lineFrom
= oldCurrent
,
3068 if ( lineTo
< lineFrom
)
3071 lineFrom
= m_current
;
3074 HighlightLines(lineFrom
, lineTo
);
3076 else // !ctrl, !shift
3078 // test in the enclosing if should make it impossible
3079 wxFAIL_MSG( _T("how did we get here?") );
3083 if (m_current
!= oldCurrent
)
3084 RefreshLine( oldCurrent
);
3086 // forceClick is only set if the previous click was on another item
3087 m_lastOnSame
= !forceClick
&& (m_current
== oldCurrent
) && oldWasSelected
;
3091 void wxListMainWindow::MoveToItem(size_t item
)
3093 if ( item
== (size_t)-1 )
3096 wxRect rect
= GetLineRect(item
);
3098 int client_w
, client_h
;
3099 GetClientSize( &client_w
, &client_h
);
3101 const int hLine
= GetLineHeight();
3103 int view_x
= SCROLL_UNIT_X
* GetScrollPos( wxHORIZONTAL
);
3104 int view_y
= hLine
* GetScrollPos( wxVERTICAL
);
3106 if ( InReportView() )
3108 // the next we need the range of lines shown it might be different,
3109 // so recalculate it
3110 ResetVisibleLinesRange();
3112 if (rect
.y
< view_y
)
3113 Scroll( -1, rect
.y
/ hLine
);
3114 if (rect
.y
+ rect
.height
+ 5 > view_y
+ client_h
)
3115 Scroll( -1, (rect
.y
+ rect
.height
- client_h
+ hLine
) / hLine
);
3119 if (rect
.x
-view_x
< 5)
3120 Scroll( (rect
.x
- 5) / SCROLL_UNIT_X
, -1 );
3121 if (rect
.x
+ rect
.width
- 5 > view_x
+ client_w
)
3122 Scroll( (rect
.x
+ rect
.width
- client_w
+ SCROLL_UNIT_X
) / SCROLL_UNIT_X
, -1 );
3126 // ----------------------------------------------------------------------------
3127 // keyboard handling
3128 // ----------------------------------------------------------------------------
3130 void wxListMainWindow::OnArrowChar(size_t newCurrent
, const wxKeyEvent
& event
)
3132 wxCHECK_RET( newCurrent
< (size_t)GetItemCount(),
3133 _T("invalid item index in OnArrowChar()") );
3135 size_t oldCurrent
= m_current
;
3137 // in single selection we just ignore Shift as we can't select several
3139 if ( event
.ShiftDown() && !IsSingleSel() )
3141 ChangeCurrent(newCurrent
);
3143 // refresh the old focus to remove it
3144 RefreshLine( oldCurrent
);
3146 // select all the items between the old and the new one
3147 if ( oldCurrent
> newCurrent
)
3149 newCurrent
= oldCurrent
;
3150 oldCurrent
= m_current
;
3153 HighlightLines(oldCurrent
, newCurrent
);
3157 // all previously selected items are unselected unless ctrl is held
3158 if ( !event
.ControlDown() )
3159 HighlightAll(false);
3161 ChangeCurrent(newCurrent
);
3163 // refresh the old focus to remove it
3164 RefreshLine( oldCurrent
);
3166 if ( !event
.ControlDown() )
3168 HighlightLine( m_current
, true );
3172 RefreshLine( m_current
);
3177 void wxListMainWindow::OnKeyDown( wxKeyEvent
&event
)
3179 wxWindow
*parent
= GetParent();
3181 // propagate the key event upwards
3182 wxKeyEvent
ke( wxEVT_KEY_DOWN
);
3183 ke
.m_shiftDown
= event
.m_shiftDown
;
3184 ke
.m_controlDown
= event
.m_controlDown
;
3185 ke
.m_altDown
= event
.m_altDown
;
3186 ke
.m_metaDown
= event
.m_metaDown
;
3187 ke
.m_keyCode
= event
.m_keyCode
;
3190 ke
.SetEventObject( parent
);
3191 if (parent
->GetEventHandler()->ProcessEvent( ke
)) return;
3196 void wxListMainWindow::OnChar( wxKeyEvent
&event
)
3198 wxWindow
*parent
= GetParent();
3200 // send a list_key event up
3203 wxListEvent
le( wxEVT_COMMAND_LIST_KEY_DOWN
, GetParent()->GetId() );
3204 le
.m_itemIndex
= m_current
;
3205 GetLine(m_current
)->GetItem( 0, le
.m_item
);
3206 le
.m_code
= event
.GetKeyCode();
3207 le
.SetEventObject( parent
);
3208 parent
->GetEventHandler()->ProcessEvent( le
);
3211 // propagate the char event upwards
3212 wxKeyEvent
ke( wxEVT_CHAR
);
3213 ke
.m_shiftDown
= event
.m_shiftDown
;
3214 ke
.m_controlDown
= event
.m_controlDown
;
3215 ke
.m_altDown
= event
.m_altDown
;
3216 ke
.m_metaDown
= event
.m_metaDown
;
3217 ke
.m_keyCode
= event
.m_keyCode
;
3220 ke
.SetEventObject( parent
);
3221 if (parent
->GetEventHandler()->ProcessEvent( ke
)) return;
3223 if (event
.GetKeyCode() == WXK_TAB
)
3225 wxNavigationKeyEvent nevent
;
3226 nevent
.SetWindowChange( event
.ControlDown() );
3227 nevent
.SetDirection( !event
.ShiftDown() );
3228 nevent
.SetEventObject( GetParent()->GetParent() );
3229 nevent
.SetCurrentFocus( m_parent
);
3230 if (GetParent()->GetParent()->GetEventHandler()->ProcessEvent( nevent
))
3234 // no item -> nothing to do
3241 // don't use m_linesPerPage directly as it might not be computed yet
3242 const int pageSize
= GetCountPerPage();
3243 wxCHECK_RET( pageSize
, _T("should have non zero page size") );
3245 if (GetLayoutDirection() == wxLayout_RightToLeft
)
3247 if (event
.GetKeyCode() == WXK_RIGHT
)
3248 event
.m_keyCode
= WXK_LEFT
;
3249 else if (event
.GetKeyCode() == WXK_LEFT
)
3250 event
.m_keyCode
= WXK_RIGHT
;
3253 switch ( event
.GetKeyCode() )
3256 if ( m_current
> 0 )
3257 OnArrowChar( m_current
- 1, event
);
3261 if ( m_current
< (size_t)GetItemCount() - 1 )
3262 OnArrowChar( m_current
+ 1, event
);
3267 OnArrowChar( GetItemCount() - 1, event
);
3272 OnArrowChar( 0, event
);
3277 int steps
= InReportView() ? pageSize
- 1
3278 : m_current
% pageSize
;
3280 int index
= m_current
- steps
;
3284 OnArrowChar( index
, event
);
3290 int steps
= InReportView()
3292 : pageSize
- (m_current
% pageSize
) - 1;
3294 size_t index
= m_current
+ steps
;
3295 size_t count
= GetItemCount();
3296 if ( index
>= count
)
3299 OnArrowChar( index
, event
);
3304 if ( !InReportView() )
3306 int index
= m_current
- pageSize
;
3310 OnArrowChar( index
, event
);
3315 if ( !InReportView() )
3317 size_t index
= m_current
+ pageSize
;
3319 size_t count
= GetItemCount();
3320 if ( index
>= count
)
3323 OnArrowChar( index
, event
);
3328 if ( IsSingleSel() )
3330 SendNotify( m_current
, wxEVT_COMMAND_LIST_ITEM_ACTIVATED
);
3332 if ( IsHighlighted(m_current
) )
3334 // don't unselect the item in single selection mode
3337 //else: select it in ReverseHighlight() below if unselected
3340 ReverseHighlight(m_current
);
3345 SendNotify( m_current
, wxEVT_COMMAND_LIST_ITEM_ACTIVATED
);
3353 // ----------------------------------------------------------------------------
3355 // ----------------------------------------------------------------------------
3357 void wxListMainWindow::OnSetFocus( wxFocusEvent
&WXUNUSED(event
) )
3361 wxFocusEvent
event( wxEVT_SET_FOCUS
, GetParent()->GetId() );
3362 event
.SetEventObject( GetParent() );
3363 if ( GetParent()->GetEventHandler()->ProcessEvent( event
) )
3367 // wxGTK sends us EVT_SET_FOCUS events even if we had never got
3368 // EVT_KILL_FOCUS before which means that we finish by redrawing the items
3369 // which are already drawn correctly resulting in horrible flicker - avoid
3379 void wxListMainWindow::OnKillFocus( wxFocusEvent
&WXUNUSED(event
) )
3383 wxFocusEvent
event( wxEVT_KILL_FOCUS
, GetParent()->GetId() );
3384 event
.SetEventObject( GetParent() );
3385 if ( GetParent()->GetEventHandler()->ProcessEvent( event
) )
3393 void wxListMainWindow::DrawImage( int index
, wxDC
*dc
, int x
, int y
)
3395 if ( HasFlag(wxLC_ICON
) && (m_normal_image_list
))
3397 m_normal_image_list
->Draw( index
, *dc
, x
, y
, wxIMAGELIST_DRAW_TRANSPARENT
);
3399 else if ( HasFlag(wxLC_SMALL_ICON
) && (m_small_image_list
))
3401 m_small_image_list
->Draw( index
, *dc
, x
, y
, wxIMAGELIST_DRAW_TRANSPARENT
);
3403 else if ( HasFlag(wxLC_LIST
) && (m_small_image_list
))
3405 m_small_image_list
->Draw( index
, *dc
, x
, y
, wxIMAGELIST_DRAW_TRANSPARENT
);
3407 else if ( InReportView() && (m_small_image_list
))
3409 m_small_image_list
->Draw( index
, *dc
, x
, y
, wxIMAGELIST_DRAW_TRANSPARENT
);
3413 void wxListMainWindow::GetImageSize( int index
, int &width
, int &height
) const
3415 if ( HasFlag(wxLC_ICON
) && m_normal_image_list
)
3417 m_normal_image_list
->GetSize( index
, width
, height
);
3419 else if ( HasFlag(wxLC_SMALL_ICON
) && m_small_image_list
)
3421 m_small_image_list
->GetSize( index
, width
, height
);
3423 else if ( HasFlag(wxLC_LIST
) && m_small_image_list
)
3425 m_small_image_list
->GetSize( index
, width
, height
);
3427 else if ( InReportView() && m_small_image_list
)
3429 m_small_image_list
->GetSize( index
, width
, height
);
3438 int wxListMainWindow::GetTextLength( const wxString
&s
) const
3440 wxClientDC
dc( wxConstCast(this, wxListMainWindow
) );
3441 dc
.SetFont( GetFont() );
3444 dc
.GetTextExtent( s
, &lw
, NULL
);
3446 return lw
+ AUTOSIZE_COL_MARGIN
;
3449 void wxListMainWindow::SetImageList( wxImageList
*imageList
, int which
)
3453 // calc the spacing from the icon size
3454 int width
= 0, height
= 0;
3456 if ((imageList
) && (imageList
->GetImageCount()) )
3457 imageList
->GetSize(0, width
, height
);
3459 if (which
== wxIMAGE_LIST_NORMAL
)
3461 m_normal_image_list
= imageList
;
3462 m_normal_spacing
= width
+ 8;
3465 if (which
== wxIMAGE_LIST_SMALL
)
3467 m_small_image_list
= imageList
;
3468 m_small_spacing
= width
+ 14;
3469 m_lineHeight
= 0; // ensure that the line height will be recalc'd
3473 void wxListMainWindow::SetItemSpacing( int spacing
, bool isSmall
)
3477 m_small_spacing
= spacing
;
3479 m_normal_spacing
= spacing
;
3482 int wxListMainWindow::GetItemSpacing( bool isSmall
)
3484 return isSmall
? m_small_spacing
: m_normal_spacing
;
3487 // ----------------------------------------------------------------------------
3489 // ----------------------------------------------------------------------------
3491 void wxListMainWindow::SetColumn( int col
, wxListItem
&item
)
3493 wxListHeaderDataList::compatibility_iterator node
= m_columns
.Item( col
);
3495 wxCHECK_RET( node
, _T("invalid column index in SetColumn") );
3497 if ( item
.m_width
== wxLIST_AUTOSIZE_USEHEADER
)
3498 item
.m_width
= GetTextLength( item
.m_text
);
3500 wxListHeaderData
*column
= node
->GetData();
3501 column
->SetItem( item
);
3503 wxListHeaderWindow
*headerWin
= GetListCtrl()->m_headerWin
;
3505 headerWin
->m_dirty
= true;
3509 // invalidate it as it has to be recalculated
3513 void wxListMainWindow::SetColumnWidth( int col
, int width
)
3515 wxCHECK_RET( col
>= 0 && col
< GetColumnCount(),
3516 _T("invalid column index") );
3518 wxCHECK_RET( InReportView(),
3519 _T("SetColumnWidth() can only be called in report mode.") );
3522 wxListHeaderWindow
*headerWin
= GetListCtrl()->m_headerWin
;
3524 headerWin
->m_dirty
= true;
3526 wxListHeaderDataList::compatibility_iterator node
= m_columns
.Item( col
);
3527 wxCHECK_RET( node
, _T("no column?") );
3529 wxListHeaderData
*column
= node
->GetData();
3531 size_t count
= GetItemCount();
3533 if (width
== wxLIST_AUTOSIZE_USEHEADER
)
3535 width
= GetTextLength(column
->GetText());
3537 else if ( width
== wxLIST_AUTOSIZE
)
3541 // TODO: determine the max width somehow...
3542 width
= WIDTH_COL_DEFAULT
;
3546 wxClientDC
dc(this);
3547 dc
.SetFont( GetFont() );
3549 int max
= AUTOSIZE_COL_MARGIN
;
3551 // if the cached column width isn't valid then recalculate it
3552 if (m_aColWidths
.Item(col
)->bNeedsUpdate
)
3554 for (size_t i
= 0; i
< count
; i
++)
3556 wxListLineData
*line
= GetLine( i
);
3557 wxListItemDataList::compatibility_iterator n
= line
->m_items
.Item( col
);
3559 wxCHECK_RET( n
, _T("no subitem?") );
3561 wxListItemData
*itemData
= n
->GetData();
3564 itemData
->GetItem(item
);
3565 int itemWidth
= GetItemWidthWithImage(&item
);
3566 if (itemWidth
> max
)
3570 m_aColWidths
.Item(col
)->bNeedsUpdate
= false;
3571 m_aColWidths
.Item(col
)->nMaxWidth
= max
;
3574 max
= m_aColWidths
.Item(col
)->nMaxWidth
;
3575 width
= max
+ AUTOSIZE_COL_MARGIN
;
3579 column
->SetWidth( width
);
3581 // invalidate it as it has to be recalculated
3585 int wxListMainWindow::GetHeaderWidth() const
3587 if ( !m_headerWidth
)
3589 wxListMainWindow
*self
= wxConstCast(this, wxListMainWindow
);
3591 size_t count
= GetColumnCount();
3592 for ( size_t col
= 0; col
< count
; col
++ )
3594 self
->m_headerWidth
+= GetColumnWidth(col
);
3598 return m_headerWidth
;
3601 void wxListMainWindow::GetColumn( int col
, wxListItem
&item
) const
3603 wxListHeaderDataList::compatibility_iterator node
= m_columns
.Item( col
);
3604 wxCHECK_RET( node
, _T("invalid column index in GetColumn") );
3606 wxListHeaderData
*column
= node
->GetData();
3607 column
->GetItem( item
);
3610 int wxListMainWindow::GetColumnWidth( int col
) const
3612 wxListHeaderDataList::compatibility_iterator node
= m_columns
.Item( col
);
3613 wxCHECK_MSG( node
, 0, _T("invalid column index") );
3615 wxListHeaderData
*column
= node
->GetData();
3616 return column
->GetWidth();
3619 // ----------------------------------------------------------------------------
3621 // ----------------------------------------------------------------------------
3623 void wxListMainWindow::SetItem( wxListItem
&item
)
3625 long id
= item
.m_itemId
;
3626 wxCHECK_RET( id
>= 0 && (size_t)id
< GetItemCount(),
3627 _T("invalid item index in SetItem") );
3631 wxListLineData
*line
= GetLine((size_t)id
);
3632 line
->SetItem( item
.m_col
, item
);
3634 // Set item state if user wants
3635 if ( item
.m_mask
& wxLIST_MASK_STATE
)
3636 SetItemState( item
.m_itemId
, item
.m_state
, item
.m_state
);
3640 // update the Max Width Cache if needed
3641 int width
= GetItemWidthWithImage(&item
);
3643 if (width
> m_aColWidths
.Item(item
.m_col
)->nMaxWidth
)
3644 m_aColWidths
.Item(item
.m_col
)->nMaxWidth
= width
;
3648 // update the item on screen
3650 GetItemRect(id
, rectItem
);
3651 RefreshRect(rectItem
);
3654 void wxListMainWindow::SetItemStateAll(long state
, long stateMask
)
3659 // first deal with selection
3660 if ( stateMask
& wxLIST_STATE_SELECTED
)
3662 // set/clear select state
3665 // optimized version for virtual listctrl.
3666 m_selStore
.SelectRange(0, GetItemCount() - 1, state
== wxLIST_STATE_SELECTED
);
3669 else if ( state
& wxLIST_STATE_SELECTED
)
3671 const long count
= GetItemCount();
3672 for( long i
= 0; i
< count
; i
++ )
3674 SetItemState( i
, wxLIST_STATE_SELECTED
, wxLIST_STATE_SELECTED
);
3680 // clear for non virtual (somewhat optimized by using GetNextItem())
3682 while ( (i
= GetNextItem(i
, wxLIST_NEXT_ALL
, wxLIST_STATE_SELECTED
)) != -1 )
3684 SetItemState( i
, 0, wxLIST_STATE_SELECTED
);
3689 if ( HasCurrent() && (state
== 0) && (stateMask
& wxLIST_STATE_FOCUSED
) )
3691 // unfocus all: only one item can be focussed, so clearing focus for
3692 // all items is simply clearing focus of the focussed item.
3693 SetItemState(m_current
, state
, stateMask
);
3695 //(setting focus to all items makes no sense, so it is not handled here.)
3698 void wxListMainWindow::SetItemState( long litem
, long state
, long stateMask
)
3702 SetItemStateAll(state
, stateMask
);
3706 wxCHECK_RET( litem
>= 0 && (size_t)litem
< GetItemCount(),
3707 _T("invalid list ctrl item index in SetItem") );
3709 size_t oldCurrent
= m_current
;
3710 size_t item
= (size_t)litem
; // safe because of the check above
3712 // do we need to change the focus?
3713 if ( stateMask
& wxLIST_STATE_FOCUSED
)
3715 if ( state
& wxLIST_STATE_FOCUSED
)
3717 // don't do anything if this item is already focused
3718 if ( item
!= m_current
)
3720 ChangeCurrent(item
);
3722 if ( oldCurrent
!= (size_t)-1 )
3724 if ( IsSingleSel() )
3726 HighlightLine(oldCurrent
, false);
3729 RefreshLine(oldCurrent
);
3732 RefreshLine( m_current
);
3737 // don't do anything if this item is not focused
3738 if ( item
== m_current
)
3742 if ( IsSingleSel() )
3744 // we must unselect the old current item as well or we
3745 // might end up with more than one selected item in a
3746 // single selection control
3747 HighlightLine(oldCurrent
, false);
3750 RefreshLine( oldCurrent
);
3755 // do we need to change the selection state?
3756 if ( stateMask
& wxLIST_STATE_SELECTED
)
3758 bool on
= (state
& wxLIST_STATE_SELECTED
) != 0;
3760 if ( IsSingleSel() )
3764 // selecting the item also makes it the focused one in the
3766 if ( m_current
!= item
)
3768 ChangeCurrent(item
);
3770 if ( oldCurrent
!= (size_t)-1 )
3772 HighlightLine( oldCurrent
, false );
3773 RefreshLine( oldCurrent
);
3779 // only the current item may be selected anyhow
3780 if ( item
!= m_current
)
3785 if ( HighlightLine(item
, on
) )
3792 int wxListMainWindow::GetItemState( long item
, long stateMask
) const
3794 wxCHECK_MSG( item
>= 0 && (size_t)item
< GetItemCount(), 0,
3795 _T("invalid list ctrl item index in GetItemState()") );
3797 int ret
= wxLIST_STATE_DONTCARE
;
3799 if ( stateMask
& wxLIST_STATE_FOCUSED
)
3801 if ( (size_t)item
== m_current
)
3802 ret
|= wxLIST_STATE_FOCUSED
;
3805 if ( stateMask
& wxLIST_STATE_SELECTED
)
3807 if ( IsHighlighted(item
) )
3808 ret
|= wxLIST_STATE_SELECTED
;
3814 void wxListMainWindow::GetItem( wxListItem
&item
) const
3816 wxCHECK_RET( item
.m_itemId
>= 0 && (size_t)item
.m_itemId
< GetItemCount(),
3817 _T("invalid item index in GetItem") );
3819 wxListLineData
*line
= GetLine((size_t)item
.m_itemId
);
3820 line
->GetItem( item
.m_col
, item
);
3822 // Get item state if user wants it
3823 if ( item
.m_mask
& wxLIST_MASK_STATE
)
3824 item
.m_state
= GetItemState( item
.m_itemId
, wxLIST_STATE_SELECTED
|
3825 wxLIST_STATE_FOCUSED
);
3828 // ----------------------------------------------------------------------------
3830 // ----------------------------------------------------------------------------
3832 size_t wxListMainWindow::GetItemCount() const
3834 return IsVirtual() ? m_countVirt
: m_lines
.GetCount();
3837 void wxListMainWindow::SetItemCount(long count
)
3839 m_selStore
.SetItemCount(count
);
3840 m_countVirt
= count
;
3842 ResetVisibleLinesRange();
3844 // scrollbars must be reset
3848 int wxListMainWindow::GetSelectedItemCount() const
3850 // deal with the quick case first
3851 if ( IsSingleSel() )
3852 return HasCurrent() ? IsHighlighted(m_current
) : false;
3854 // virtual controls remmebers all its selections itself
3856 return m_selStore
.GetSelectedCount();
3858 // TODO: we probably should maintain the number of items selected even for
3859 // non virtual controls as enumerating all lines is really slow...
3860 size_t countSel
= 0;
3861 size_t count
= GetItemCount();
3862 for ( size_t line
= 0; line
< count
; line
++ )
3864 if ( GetLine(line
)->IsHighlighted() )
3871 // ----------------------------------------------------------------------------
3872 // item position/size
3873 // ----------------------------------------------------------------------------
3875 wxRect
wxListMainWindow::GetViewRect() const
3877 wxASSERT_MSG( !HasFlag(wxLC_REPORT
| wxLC_LIST
),
3878 _T("wxListCtrl::GetViewRect() only works in icon mode") );
3880 // we need to find the longest/tallest label
3881 wxCoord xMax
= 0, yMax
= 0;
3882 const int count
= GetItemCount();
3885 for ( int i
= 0; i
< count
; i
++ )
3890 wxCoord x
= r
.GetRight(),
3900 // some fudge needed to make it look prettier
3901 xMax
+= 2 * EXTRA_BORDER_X
;
3902 yMax
+= 2 * EXTRA_BORDER_Y
;
3904 // account for the scrollbars if necessary
3905 const wxSize sizeAll
= GetClientSize();
3906 if ( xMax
> sizeAll
.x
)
3907 yMax
+= wxSystemSettings::GetMetric(wxSYS_HSCROLL_Y
);
3908 if ( yMax
> sizeAll
.y
)
3909 xMax
+= wxSystemSettings::GetMetric(wxSYS_VSCROLL_X
);
3911 return wxRect(0, 0, xMax
, yMax
);
3914 void wxListMainWindow::GetItemRect( long index
, wxRect
&rect
) const
3916 wxCHECK_RET( index
>= 0 && (size_t)index
< GetItemCount(),
3917 _T("invalid index in GetItemRect") );
3919 // ensure that we're laid out, otherwise we could return nonsense
3922 wxConstCast(this, wxListMainWindow
)->
3923 RecalculatePositions(true /* no refresh */);
3926 rect
= GetLineRect((size_t)index
);
3928 CalcScrolledPosition(rect
.x
, rect
.y
, &rect
.x
, &rect
.y
);
3931 bool wxListMainWindow::GetItemPosition(long item
, wxPoint
& pos
) const
3934 GetItemRect(item
, rect
);
3942 // ----------------------------------------------------------------------------
3943 // geometry calculation
3944 // ----------------------------------------------------------------------------
3946 void wxListMainWindow::RecalculatePositions(bool noRefresh
)
3948 wxClientDC
dc( this );
3949 dc
.SetFont( GetFont() );
3951 const size_t count
= GetItemCount();
3954 if ( HasFlag(wxLC_ICON
) )
3955 iconSpacing
= m_normal_spacing
;
3956 else if ( HasFlag(wxLC_SMALL_ICON
) )
3957 iconSpacing
= m_small_spacing
;
3961 // Note that we do not call GetClientSize() here but
3962 // GetSize() and subtract the border size for sunken
3963 // borders manually. This is technically incorrect,
3964 // but we need to know the client area's size WITHOUT
3965 // scrollbars here. Since we don't know if there are
3966 // any scrollbars, we use GetSize() instead. Another
3967 // solution would be to call SetScrollbars() here to
3968 // remove the scrollbars and call GetClientSize() then,
3969 // but this might result in flicker and - worse - will
3970 // reset the scrollbars to 0 which is not good at all
3971 // if you resize a dialog/window, but don't want to
3972 // reset the window scrolling. RR.
3973 // Furthermore, we actually do NOT subtract the border
3974 // width as 2 pixels is just the extra space which we
3975 // need around the actual content in the window. Other-
3976 // wise the text would e.g. touch the upper border. RR.
3979 GetSize( &clientWidth
, &clientHeight
);
3981 const int lineHeight
= GetLineHeight();
3983 if ( InReportView() )
3985 // all lines have the same height and we scroll one line per step
3986 int entireHeight
= count
* lineHeight
+ LINE_SPACING
;
3988 m_linesPerPage
= clientHeight
/ lineHeight
;
3990 ResetVisibleLinesRange();
3992 SetScrollbars( SCROLL_UNIT_X
, lineHeight
,
3993 GetHeaderWidth() / SCROLL_UNIT_X
,
3994 (entireHeight
+ lineHeight
- 1) / lineHeight
,
3995 GetScrollPos(wxHORIZONTAL
),
3996 GetScrollPos(wxVERTICAL
),
4001 // we have 3 different layout strategies: either layout all items
4002 // horizontally/vertically (wxLC_ALIGN_XXX styles explicitly given) or
4003 // to arrange them in top to bottom, left to right (don't ask me why
4004 // not the other way round...) order
4005 if ( HasFlag(wxLC_ALIGN_LEFT
| wxLC_ALIGN_TOP
) )
4007 int x
= EXTRA_BORDER_X
;
4008 int y
= EXTRA_BORDER_Y
;
4010 wxCoord widthMax
= 0;
4013 for ( i
= 0; i
< count
; i
++ )
4015 wxListLineData
*line
= GetLine(i
);
4016 line
->CalculateSize( &dc
, iconSpacing
);
4017 line
->SetPosition( x
, y
, iconSpacing
);
4019 wxSize sizeLine
= GetLineSize(i
);
4021 if ( HasFlag(wxLC_ALIGN_TOP
) )
4023 if ( sizeLine
.x
> widthMax
)
4024 widthMax
= sizeLine
.x
;
4028 else // wxLC_ALIGN_LEFT
4030 x
+= sizeLine
.x
+ MARGIN_BETWEEN_ROWS
;
4034 if ( HasFlag(wxLC_ALIGN_TOP
) )
4036 // traverse the items again and tweak their sizes so that they are
4037 // all the same in a row
4038 for ( i
= 0; i
< count
; i
++ )
4040 wxListLineData
*line
= GetLine(i
);
4041 line
->m_gi
->ExtendWidth(widthMax
);
4049 (x
+ SCROLL_UNIT_X
) / SCROLL_UNIT_X
,
4050 (y
+ lineHeight
) / lineHeight
,
4051 GetScrollPos( wxHORIZONTAL
),
4052 GetScrollPos( wxVERTICAL
),
4056 else // "flowed" arrangement, the most complicated case
4058 // at first we try without any scrollbars, if the items don't fit into
4059 // the window, we recalculate after subtracting the space taken by the
4062 int entireWidth
= 0;
4064 for (int tries
= 0; tries
< 2; tries
++)
4066 entireWidth
= 2 * EXTRA_BORDER_X
;
4070 // Now we have decided that the items do not fit into the
4071 // client area, so we need a scrollbar
4072 entireWidth
+= SCROLL_UNIT_X
;
4075 int x
= EXTRA_BORDER_X
;
4076 int y
= EXTRA_BORDER_Y
;
4077 int maxWidthInThisRow
= 0;
4080 int currentlyVisibleLines
= 0;
4082 for (size_t i
= 0; i
< count
; i
++)
4084 currentlyVisibleLines
++;
4085 wxListLineData
*line
= GetLine( i
);
4086 line
->CalculateSize( &dc
, iconSpacing
);
4087 line
->SetPosition( x
, y
, iconSpacing
);
4089 wxSize sizeLine
= GetLineSize( i
);
4091 if ( maxWidthInThisRow
< sizeLine
.x
)
4092 maxWidthInThisRow
= sizeLine
.x
;
4095 if (currentlyVisibleLines
> m_linesPerPage
)
4096 m_linesPerPage
= currentlyVisibleLines
;
4098 if ( y
+ sizeLine
.y
>= clientHeight
)
4100 currentlyVisibleLines
= 0;
4102 maxWidthInThisRow
+= MARGIN_BETWEEN_ROWS
;
4103 x
+= maxWidthInThisRow
;
4104 entireWidth
+= maxWidthInThisRow
;
4105 maxWidthInThisRow
= 0;
4108 // We have reached the last item.
4109 if ( i
== count
- 1 )
4110 entireWidth
+= maxWidthInThisRow
;
4112 if ( (tries
== 0) &&
4113 (entireWidth
+ SCROLL_UNIT_X
> clientWidth
) )
4115 clientHeight
-= wxSystemSettings::
4116 GetMetric(wxSYS_HSCROLL_Y
);
4121 if ( i
== count
- 1 )
4122 tries
= 1; // Everything fits, no second try required.
4130 (entireWidth
+ SCROLL_UNIT_X
) / SCROLL_UNIT_X
,
4132 GetScrollPos( wxHORIZONTAL
),
4141 // FIXME: why should we call it from here?
4148 void wxListMainWindow::RefreshAll()
4153 wxListHeaderWindow
*headerWin
= GetListCtrl()->m_headerWin
;
4154 if ( headerWin
&& headerWin
->m_dirty
)
4156 headerWin
->m_dirty
= false;
4157 headerWin
->Refresh();
4161 void wxListMainWindow::UpdateCurrent()
4163 if ( !HasCurrent() && !IsEmpty() )
4167 long wxListMainWindow::GetNextItem( long item
,
4168 int WXUNUSED(geometry
),
4172 max
= GetItemCount();
4173 wxCHECK_MSG( (ret
== -1) || (ret
< max
), -1,
4174 _T("invalid listctrl index in GetNextItem()") );
4176 // notice that we start with the next item (or the first one if item == -1)
4177 // and this is intentional to allow writing a simple loop to iterate over
4178 // all selected items
4181 // this is not an error because the index was OK initially,
4182 // just no such item
4189 size_t count
= GetItemCount();
4190 for ( size_t line
= (size_t)ret
; line
< count
; line
++ )
4192 if ( (state
& wxLIST_STATE_FOCUSED
) && (line
== m_current
) )
4195 if ( (state
& wxLIST_STATE_SELECTED
) && IsHighlighted(line
) )
4202 // ----------------------------------------------------------------------------
4204 // ----------------------------------------------------------------------------
4206 void wxListMainWindow::DeleteItem( long lindex
)
4208 size_t count
= GetItemCount();
4210 wxCHECK_RET( (lindex
>= 0) && ((size_t)lindex
< count
),
4211 _T("invalid item index in DeleteItem") );
4213 size_t index
= (size_t)lindex
;
4215 // we don't need to adjust the index for the previous items
4216 if ( HasCurrent() && m_current
>= index
)
4218 // if the current item is being deleted, we want the next one to
4219 // become selected - unless there is no next one - so don't adjust
4220 // m_current in this case
4221 if ( m_current
!= index
|| m_current
== count
- 1 )
4225 if ( InReportView() )
4227 // mark the Column Max Width cache as dirty if the items in the line
4228 // we're deleting contain the Max Column Width
4229 wxListLineData
* const line
= GetLine(index
);
4230 wxListItemDataList::compatibility_iterator n
;
4231 wxListItemData
*itemData
;
4235 for (size_t i
= 0; i
< m_columns
.GetCount(); i
++)
4237 n
= line
->m_items
.Item( i
);
4238 itemData
= n
->GetData();
4239 itemData
->GetItem(item
);
4241 itemWidth
= GetItemWidthWithImage(&item
);
4243 if (itemWidth
>= m_aColWidths
.Item(i
)->nMaxWidth
)
4244 m_aColWidths
.Item(i
)->bNeedsUpdate
= true;
4247 ResetVisibleLinesRange();
4253 m_selStore
.OnItemDelete(index
);
4257 m_lines
.RemoveAt( index
);
4260 // we need to refresh the (vert) scrollbar as the number of items changed
4263 SendNotify( index
, wxEVT_COMMAND_LIST_DELETE_ITEM
);
4265 RefreshAfter(index
);
4268 void wxListMainWindow::DeleteColumn( int col
)
4270 wxListHeaderDataList::compatibility_iterator node
= m_columns
.Item( col
);
4272 wxCHECK_RET( node
, wxT("invalid column index in DeleteColumn()") );
4275 delete node
->GetData();
4276 m_columns
.Erase( node
);
4280 // update all the items
4281 for ( size_t i
= 0; i
< m_lines
.GetCount(); i
++ )
4283 wxListLineData
* const line
= GetLine(i
);
4284 wxListItemDataList::compatibility_iterator n
= line
->m_items
.Item( col
);
4285 delete n
->GetData();
4286 line
->m_items
.Erase(n
);
4290 if ( InReportView() ) // we only cache max widths when in Report View
4292 delete m_aColWidths
.Item(col
);
4293 m_aColWidths
.RemoveAt(col
);
4296 // invalidate it as it has to be recalculated
4300 void wxListMainWindow::DoDeleteAllItems()
4303 // nothing to do - in particular, don't send the event
4308 // to make the deletion of all items faster, we don't send the
4309 // notifications for each item deletion in this case but only one event
4310 // for all of them: this is compatible with wxMSW and documented in
4311 // DeleteAllItems() description
4313 wxListEvent
event( wxEVT_COMMAND_LIST_DELETE_ALL_ITEMS
, GetParent()->GetId() );
4314 event
.SetEventObject( GetParent() );
4315 GetParent()->GetEventHandler()->ProcessEvent( event
);
4323 if ( InReportView() )
4325 ResetVisibleLinesRange();
4326 for (size_t i
= 0; i
< m_aColWidths
.GetCount(); i
++)
4328 m_aColWidths
.Item(i
)->bNeedsUpdate
= true;
4335 void wxListMainWindow::DeleteAllItems()
4339 RecalculatePositions();
4342 void wxListMainWindow::DeleteEverything()
4344 WX_CLEAR_LIST(wxListHeaderDataList
, m_columns
);
4345 WX_CLEAR_ARRAY(m_aColWidths
);
4350 // ----------------------------------------------------------------------------
4351 // scanning for an item
4352 // ----------------------------------------------------------------------------
4354 void wxListMainWindow::EnsureVisible( long index
)
4356 wxCHECK_RET( index
>= 0 && (size_t)index
< GetItemCount(),
4357 _T("invalid index in EnsureVisible") );
4359 // We have to call this here because the label in question might just have
4360 // been added and its position is not known yet
4362 RecalculatePositions(true /* no refresh */);
4364 MoveToItem((size_t)index
);
4367 long wxListMainWindow::FindItem(long start
, const wxString
& str
, bool WXUNUSED(partial
) )
4374 size_t count
= GetItemCount();
4375 for ( size_t i
= (size_t)pos
; i
< count
; i
++ )
4377 wxListLineData
*line
= GetLine(i
);
4378 if ( line
->GetText(0) == tmp
)
4385 long wxListMainWindow::FindItem(long start
, wxUIntPtr data
)
4391 size_t count
= GetItemCount();
4392 for (size_t i
= (size_t)pos
; i
< count
; i
++)
4394 wxListLineData
*line
= GetLine(i
);
4396 line
->GetItem( 0, item
);
4397 if (item
.m_data
== data
)
4404 long wxListMainWindow::FindItem( const wxPoint
& pt
)
4407 GetVisibleLinesRange( &topItem
, NULL
);
4410 GetItemPosition( GetItemCount() - 1, p
);
4414 long id
= (long)floor( pt
.y
* double(GetItemCount() - topItem
- 1) / p
.y
+ topItem
);
4415 if ( id
>= 0 && id
< (long)GetItemCount() )
4421 long wxListMainWindow::HitTest( int x
, int y
, int &flags
) const
4423 CalcUnscrolledPosition( x
, y
, &x
, &y
);
4425 size_t count
= GetItemCount();
4427 if ( InReportView() )
4429 size_t current
= y
/ GetLineHeight();
4430 if ( current
< count
)
4432 flags
= HitTestLine(current
, x
, y
);
4439 // TODO: optimize it too! this is less simple than for report view but
4440 // enumerating all items is still not a way to do it!!
4441 for ( size_t current
= 0; current
< count
; current
++ )
4443 flags
= HitTestLine(current
, x
, y
);
4452 // ----------------------------------------------------------------------------
4454 // ----------------------------------------------------------------------------
4456 void wxListMainWindow::InsertItem( wxListItem
&item
)
4458 wxASSERT_MSG( !IsVirtual(), _T("can't be used with virtual control") );
4460 int count
= GetItemCount();
4461 wxCHECK_RET( item
.m_itemId
>= 0, _T("invalid item index") );
4463 if (item
.m_itemId
> count
)
4464 item
.m_itemId
= count
;
4466 size_t id
= item
.m_itemId
;
4470 if ( InReportView() )
4472 ResetVisibleLinesRange();
4474 // calculate the width of the item and adjust the max column width
4475 wxColWidthInfo
*pWidthInfo
= m_aColWidths
.Item(item
.GetColumn());
4476 int width
= GetItemWidthWithImage(&item
);
4477 item
.SetWidth(width
);
4478 if (width
> pWidthInfo
->nMaxWidth
)
4479 pWidthInfo
->nMaxWidth
= width
;
4482 wxListLineData
*line
= new wxListLineData(this);
4484 line
->SetItem( item
.m_col
, item
);
4486 m_lines
.Insert( line
, id
);
4490 // If an item is selected at or below the point of insertion, we need to
4491 // increment the member variables because the current row's index has gone
4493 if ( HasCurrent() && m_current
>= id
)
4496 SendNotify(id
, wxEVT_COMMAND_LIST_INSERT_ITEM
);
4498 RefreshLines(id
, GetItemCount() - 1);
4501 void wxListMainWindow::InsertColumn( long col
, wxListItem
&item
)
4504 if ( InReportView() )
4506 if (item
.m_width
== wxLIST_AUTOSIZE_USEHEADER
)
4507 item
.m_width
= GetTextLength( item
.m_text
);
4509 wxListHeaderData
*column
= new wxListHeaderData( item
);
4510 wxColWidthInfo
*colWidthInfo
= new wxColWidthInfo();
4512 bool insert
= (col
>= 0) && ((size_t)col
< m_columns
.GetCount());
4515 wxListHeaderDataList::compatibility_iterator
4516 node
= m_columns
.Item( col
);
4517 m_columns
.Insert( node
, column
);
4518 m_aColWidths
.Insert( colWidthInfo
, col
);
4522 m_columns
.Append( column
);
4523 m_aColWidths
.Add( colWidthInfo
);
4528 // update all the items
4529 for ( size_t i
= 0; i
< m_lines
.GetCount(); i
++ )
4531 wxListLineData
* const line
= GetLine(i
);
4532 wxListItemData
* const data
= new wxListItemData(this);
4534 line
->m_items
.Insert(col
, data
);
4536 line
->m_items
.Append(data
);
4540 // invalidate it as it has to be recalculated
4545 int wxListMainWindow::GetItemWidthWithImage(wxListItem
* item
)
4548 wxClientDC
dc(this);
4550 dc
.SetFont( GetFont() );
4552 if (item
->GetImage() != -1)
4555 GetImageSize( item
->GetImage(), ix
, iy
);
4559 if (!item
->GetText().empty())
4562 dc
.GetTextExtent( item
->GetText(), &w
, NULL
);
4569 // ----------------------------------------------------------------------------
4571 // ----------------------------------------------------------------------------
4573 wxListCtrlCompare list_ctrl_compare_func_2
;
4574 long list_ctrl_compare_data
;
4576 int LINKAGEMODE
list_ctrl_compare_func_1( wxListLineData
**arg1
, wxListLineData
**arg2
)
4578 wxListLineData
*line1
= *arg1
;
4579 wxListLineData
*line2
= *arg2
;
4581 line1
->GetItem( 0, item
);
4582 wxUIntPtr data1
= item
.m_data
;
4583 line2
->GetItem( 0, item
);
4584 wxUIntPtr data2
= item
.m_data
;
4585 return list_ctrl_compare_func_2( data1
, data2
, list_ctrl_compare_data
);
4588 void wxListMainWindow::SortItems( wxListCtrlCompare fn
, long data
)
4590 list_ctrl_compare_func_2
= fn
;
4591 list_ctrl_compare_data
= data
;
4592 m_lines
.Sort( list_ctrl_compare_func_1
);
4596 // ----------------------------------------------------------------------------
4598 // ----------------------------------------------------------------------------
4600 void wxListMainWindow::OnScroll(wxScrollWinEvent
& event
)
4602 // update our idea of which lines are shown when we redraw the window the
4604 ResetVisibleLinesRange();
4607 #if ( defined(__WXGTK__) || defined(__WXMAC__) ) && !defined(__WXUNIVERSAL__)
4608 wxScrolledWindow::OnScroll(event
);
4610 HandleOnScroll( event
);
4613 if ( event
.GetOrientation() == wxHORIZONTAL
&& HasHeader() )
4615 wxGenericListCtrl
* lc
= GetListCtrl();
4616 wxCHECK_RET( lc
, _T("no listctrl window?") );
4618 lc
->m_headerWin
->Refresh();
4619 lc
->m_headerWin
->Update();
4623 int wxListMainWindow::GetCountPerPage() const
4625 if ( !m_linesPerPage
)
4627 wxConstCast(this, wxListMainWindow
)->
4628 m_linesPerPage
= GetClientSize().y
/ GetLineHeight();
4631 return m_linesPerPage
;
4634 void wxListMainWindow::GetVisibleLinesRange(size_t *from
, size_t *to
)
4636 wxASSERT_MSG( InReportView(), _T("this is for report mode only") );
4638 if ( m_lineFrom
== (size_t)-1 )
4640 size_t count
= GetItemCount();
4643 m_lineFrom
= GetScrollPos(wxVERTICAL
);
4645 // this may happen if SetScrollbars() hadn't been called yet
4646 if ( m_lineFrom
>= count
)
4647 m_lineFrom
= count
- 1;
4649 // we redraw one extra line but this is needed to make the redrawing
4650 // logic work when there is a fractional number of lines on screen
4651 m_lineTo
= m_lineFrom
+ m_linesPerPage
;
4652 if ( m_lineTo
>= count
)
4653 m_lineTo
= count
- 1;
4655 else // empty control
4658 m_lineTo
= (size_t)-1;
4662 wxASSERT_MSG( IsEmpty() ||
4663 (m_lineFrom
<= m_lineTo
&& m_lineTo
< GetItemCount()),
4664 _T("GetVisibleLinesRange() returns incorrect result") );
4672 // -------------------------------------------------------------------------------------
4673 // wxGenericListCtrl
4674 // -------------------------------------------------------------------------------------
4676 IMPLEMENT_DYNAMIC_CLASS(wxGenericListCtrl
, wxControl
)
4678 BEGIN_EVENT_TABLE(wxGenericListCtrl
,wxControl
)
4679 EVT_SIZE(wxGenericListCtrl::OnSize
)
4682 wxGenericListCtrl::wxGenericListCtrl()
4684 m_imageListNormal
= (wxImageList
*) NULL
;
4685 m_imageListSmall
= (wxImageList
*) NULL
;
4686 m_imageListState
= (wxImageList
*) NULL
;
4688 m_ownsImageListNormal
=
4689 m_ownsImageListSmall
=
4690 m_ownsImageListState
= false;
4692 m_mainWin
= (wxListMainWindow
*) NULL
;
4693 m_headerWin
= (wxListHeaderWindow
*) NULL
;
4697 wxGenericListCtrl::~wxGenericListCtrl()
4699 if (m_ownsImageListNormal
)
4700 delete m_imageListNormal
;
4701 if (m_ownsImageListSmall
)
4702 delete m_imageListSmall
;
4703 if (m_ownsImageListState
)
4704 delete m_imageListState
;
4707 void wxGenericListCtrl::CalculateAndSetHeaderHeight()
4713 GetThemeMetric( kThemeMetricListHeaderHeight
, &h
);
4715 // we use 'g' to get the descent, too
4717 m_headerWin
->GetTextExtent(wxT("Hg"), &w
, &h
, &d
);
4718 h
+= d
+ 2 * HEADER_OFFSET_Y
+ EXTRA_HEIGHT
;
4721 // only update if changed
4722 if ( h
!= m_headerHeight
)
4727 ResizeReportView(true);
4728 else //why is this needed if it doesn't have a header?
4729 m_headerWin
->SetSize(m_headerWin
->GetSize().x
, m_headerHeight
);
4734 void wxGenericListCtrl::CreateHeaderWindow()
4736 m_headerWin
= new wxListHeaderWindow
4738 this, wxID_ANY
, m_mainWin
,
4740 wxSize(GetClientSize().x
, m_headerHeight
),
4743 CalculateAndSetHeaderHeight();
4746 bool wxGenericListCtrl::Create(wxWindow
*parent
,
4751 const wxValidator
&validator
,
4752 const wxString
&name
)
4756 m_imageListState
= (wxImageList
*) NULL
;
4757 m_ownsImageListNormal
=
4758 m_ownsImageListSmall
=
4759 m_ownsImageListState
= false;
4761 m_mainWin
= (wxListMainWindow
*) NULL
;
4762 m_headerWin
= (wxListHeaderWindow
*) NULL
;
4766 if ( !(style
& wxLC_MASK_TYPE
) )
4768 style
= style
| wxLC_LIST
;
4771 if ( !wxControl::Create( parent
, id
, pos
, size
, style
, validator
, name
) )
4774 // don't create the inner window with the border
4775 style
&= ~wxBORDER_MASK
;
4777 m_mainWin
= new wxListMainWindow( this, wxID_ANY
, wxPoint(0, 0), size
, style
);
4779 #ifdef __WXMAC_CARBON__
4780 // Human Interface Guidelines ask us for a special font in this case
4781 if ( GetWindowVariant() == wxWINDOW_VARIANT_NORMAL
)
4784 font
.MacCreateThemeFont( kThemeViewsFont
);
4789 if ( InReportView() )
4791 CreateHeaderWindow();
4793 #ifdef __WXMAC_CARBON__
4797 font
.MacCreateThemeFont( kThemeSmallSystemFont
);
4798 m_headerWin
->SetFont( font
);
4799 CalculateAndSetHeaderHeight();
4803 if ( HasFlag(wxLC_NO_HEADER
) )
4804 // VZ: why do we create it at all then?
4805 m_headerWin
->Show( false );
4813 void wxGenericListCtrl::SetSingleStyle( long style
, bool add
)
4815 wxASSERT_MSG( !(style
& wxLC_VIRTUAL
),
4816 _T("wxLC_VIRTUAL can't be [un]set") );
4818 long flag
= GetWindowStyle();
4822 if (style
& wxLC_MASK_TYPE
)
4823 flag
&= ~(wxLC_MASK_TYPE
| wxLC_VIRTUAL
);
4824 if (style
& wxLC_MASK_ALIGN
)
4825 flag
&= ~wxLC_MASK_ALIGN
;
4826 if (style
& wxLC_MASK_SORT
)
4827 flag
&= ~wxLC_MASK_SORT
;
4835 SetWindowStyleFlag( flag
);
4838 void wxGenericListCtrl::SetWindowStyleFlag( long flag
)
4842 m_mainWin
->DeleteEverything();
4844 // has the header visibility changed?
4845 bool hasHeader
= HasHeader();
4846 bool willHaveHeader
= (flag
& wxLC_REPORT
) && !(flag
& wxLC_NO_HEADER
);
4848 if ( hasHeader
!= willHaveHeader
)
4855 // don't delete, just hide, as we can reuse it later
4856 m_headerWin
->Show(false);
4858 //else: nothing to do
4860 else // must show header
4864 CreateHeaderWindow();
4866 else // already have it, just show
4868 m_headerWin
->Show( true );
4872 ResizeReportView(willHaveHeader
);
4876 wxWindow::SetWindowStyleFlag( flag
);
4879 bool wxGenericListCtrl::GetColumn(int col
, wxListItem
&item
) const
4881 m_mainWin
->GetColumn( col
, item
);
4885 bool wxGenericListCtrl::SetColumn( int col
, wxListItem
& item
)
4887 m_mainWin
->SetColumn( col
, item
);
4891 int wxGenericListCtrl::GetColumnWidth( int col
) const
4893 return m_mainWin
->GetColumnWidth( col
);
4896 bool wxGenericListCtrl::SetColumnWidth( int col
, int width
)
4898 m_mainWin
->SetColumnWidth( col
, width
);
4902 int wxGenericListCtrl::GetCountPerPage() const
4904 return m_mainWin
->GetCountPerPage(); // different from Windows ?
4907 bool wxGenericListCtrl::GetItem( wxListItem
&info
) const
4909 m_mainWin
->GetItem( info
);
4913 bool wxGenericListCtrl::SetItem( wxListItem
&info
)
4915 m_mainWin
->SetItem( info
);
4919 long wxGenericListCtrl::SetItem( long index
, int col
, const wxString
& label
, int imageId
)
4922 info
.m_text
= label
;
4923 info
.m_mask
= wxLIST_MASK_TEXT
;
4924 info
.m_itemId
= index
;
4928 info
.m_image
= imageId
;
4929 info
.m_mask
|= wxLIST_MASK_IMAGE
;
4932 m_mainWin
->SetItem(info
);
4936 int wxGenericListCtrl::GetItemState( long item
, long stateMask
) const
4938 return m_mainWin
->GetItemState( item
, stateMask
);
4941 bool wxGenericListCtrl::SetItemState( long item
, long state
, long stateMask
)
4943 m_mainWin
->SetItemState( item
, state
, stateMask
);
4948 wxGenericListCtrl::SetItemImage( long item
, int image
, int WXUNUSED(selImage
) )
4950 return SetItemColumnImage(item
, 0, image
);
4954 wxGenericListCtrl::SetItemColumnImage( long item
, long column
, int image
)
4957 info
.m_image
= image
;
4958 info
.m_mask
= wxLIST_MASK_IMAGE
;
4959 info
.m_itemId
= item
;
4960 info
.m_col
= column
;
4961 m_mainWin
->SetItem( info
);
4965 wxString
wxGenericListCtrl::GetItemText( long item
) const
4967 return m_mainWin
->GetItemText(item
);
4970 void wxGenericListCtrl::SetItemText( long item
, const wxString
& str
)
4972 m_mainWin
->SetItemText(item
, str
);
4975 wxUIntPtr
wxGenericListCtrl::GetItemData( long item
) const
4978 info
.m_mask
= wxLIST_MASK_DATA
;
4979 info
.m_itemId
= item
;
4980 m_mainWin
->GetItem( info
);
4984 bool wxGenericListCtrl::SetItemData( long item
, long data
)
4987 info
.m_mask
= wxLIST_MASK_DATA
;
4988 info
.m_itemId
= item
;
4990 m_mainWin
->SetItem( info
);
4994 wxRect
wxGenericListCtrl::GetViewRect() const
4996 return m_mainWin
->GetViewRect();
4999 bool wxGenericListCtrl::GetItemRect( long item
, wxRect
&rect
, int WXUNUSED(code
) ) const
5001 m_mainWin
->GetItemRect( item
, rect
);
5002 if ( m_mainWin
->HasHeader() )
5003 rect
.y
+= m_headerHeight
+ 1;
5007 bool wxGenericListCtrl::GetItemPosition( long item
, wxPoint
& pos
) const
5009 m_mainWin
->GetItemPosition( item
, pos
);
5013 bool wxGenericListCtrl::SetItemPosition( long WXUNUSED(item
), const wxPoint
& WXUNUSED(pos
) )
5018 int wxGenericListCtrl::GetItemCount() const
5020 return m_mainWin
->GetItemCount();
5023 int wxGenericListCtrl::GetColumnCount() const
5025 return m_mainWin
->GetColumnCount();
5028 void wxGenericListCtrl::SetItemSpacing( int spacing
, bool isSmall
)
5030 m_mainWin
->SetItemSpacing( spacing
, isSmall
);
5033 wxSize
wxGenericListCtrl::GetItemSpacing() const
5035 const int spacing
= m_mainWin
->GetItemSpacing(HasFlag(wxLC_SMALL_ICON
));
5037 return wxSize(spacing
, spacing
);
5040 #if WXWIN_COMPATIBILITY_2_6
5041 int wxGenericListCtrl::GetItemSpacing( bool isSmall
) const
5043 return m_mainWin
->GetItemSpacing( isSmall
);
5045 #endif // WXWIN_COMPATIBILITY_2_6
5047 void wxGenericListCtrl::SetItemTextColour( long item
, const wxColour
&col
)
5050 info
.m_itemId
= item
;
5051 info
.SetTextColour( col
);
5052 m_mainWin
->SetItem( info
);
5055 wxColour
wxGenericListCtrl::GetItemTextColour( long item
) const
5058 info
.m_itemId
= item
;
5059 m_mainWin
->GetItem( info
);
5060 return info
.GetTextColour();
5063 void wxGenericListCtrl::SetItemBackgroundColour( long item
, const wxColour
&col
)
5066 info
.m_itemId
= item
;
5067 info
.SetBackgroundColour( col
);
5068 m_mainWin
->SetItem( info
);
5071 wxColour
wxGenericListCtrl::GetItemBackgroundColour( long item
) const
5074 info
.m_itemId
= item
;
5075 m_mainWin
->GetItem( info
);
5076 return info
.GetBackgroundColour();
5079 void wxGenericListCtrl::SetItemFont( long item
, const wxFont
&f
)
5082 info
.m_itemId
= item
;
5084 m_mainWin
->SetItem( info
);
5087 wxFont
wxGenericListCtrl::GetItemFont( long item
) const
5090 info
.m_itemId
= item
;
5091 m_mainWin
->GetItem( info
);
5092 return info
.GetFont();
5095 int wxGenericListCtrl::GetSelectedItemCount() const
5097 return m_mainWin
->GetSelectedItemCount();
5100 wxColour
wxGenericListCtrl::GetTextColour() const
5102 return GetForegroundColour();
5105 void wxGenericListCtrl::SetTextColour(const wxColour
& col
)
5107 SetForegroundColour(col
);
5110 long wxGenericListCtrl::GetTopItem() const
5113 m_mainWin
->GetVisibleLinesRange(&top
, NULL
);
5117 long wxGenericListCtrl::GetNextItem( long item
, int geom
, int state
) const
5119 return m_mainWin
->GetNextItem( item
, geom
, state
);
5122 wxImageList
*wxGenericListCtrl::GetImageList(int which
) const
5124 if (which
== wxIMAGE_LIST_NORMAL
)
5125 return m_imageListNormal
;
5126 else if (which
== wxIMAGE_LIST_SMALL
)
5127 return m_imageListSmall
;
5128 else if (which
== wxIMAGE_LIST_STATE
)
5129 return m_imageListState
;
5131 return (wxImageList
*) NULL
;
5134 void wxGenericListCtrl::SetImageList( wxImageList
*imageList
, int which
)
5136 if ( which
== wxIMAGE_LIST_NORMAL
)
5138 if (m_ownsImageListNormal
)
5139 delete m_imageListNormal
;
5140 m_imageListNormal
= imageList
;
5141 m_ownsImageListNormal
= false;
5143 else if ( which
== wxIMAGE_LIST_SMALL
)
5145 if (m_ownsImageListSmall
)
5146 delete m_imageListSmall
;
5147 m_imageListSmall
= imageList
;
5148 m_ownsImageListSmall
= false;
5150 else if ( which
== wxIMAGE_LIST_STATE
)
5152 if (m_ownsImageListState
)
5153 delete m_imageListState
;
5154 m_imageListState
= imageList
;
5155 m_ownsImageListState
= false;
5158 m_mainWin
->SetImageList( imageList
, which
);
5161 void wxGenericListCtrl::AssignImageList(wxImageList
*imageList
, int which
)
5163 SetImageList(imageList
, which
);
5164 if ( which
== wxIMAGE_LIST_NORMAL
)
5165 m_ownsImageListNormal
= true;
5166 else if ( which
== wxIMAGE_LIST_SMALL
)
5167 m_ownsImageListSmall
= true;
5168 else if ( which
== wxIMAGE_LIST_STATE
)
5169 m_ownsImageListState
= true;
5172 bool wxGenericListCtrl::Arrange( int WXUNUSED(flag
) )
5177 bool wxGenericListCtrl::DeleteItem( long item
)
5179 m_mainWin
->DeleteItem( item
);
5183 bool wxGenericListCtrl::DeleteAllItems()
5185 m_mainWin
->DeleteAllItems();
5189 bool wxGenericListCtrl::DeleteAllColumns()
5191 size_t count
= m_mainWin
->m_columns
.GetCount();
5192 for ( size_t n
= 0; n
< count
; n
++ )
5197 void wxGenericListCtrl::ClearAll()
5199 m_mainWin
->DeleteEverything();
5202 bool wxGenericListCtrl::DeleteColumn( int col
)
5204 m_mainWin
->DeleteColumn( col
);
5206 // if we don't have the header any longer, we need to relayout the window
5207 if ( !GetColumnCount() )
5208 ResizeReportView(false /* no header */);
5212 wxTextCtrl
*wxGenericListCtrl::EditLabel(long item
,
5213 wxClassInfo
* textControlClass
)
5215 return m_mainWin
->EditLabel( item
, textControlClass
);
5218 wxTextCtrl
*wxGenericListCtrl::GetEditControl() const
5220 return m_mainWin
->GetEditControl();
5223 bool wxGenericListCtrl::EnsureVisible( long item
)
5225 m_mainWin
->EnsureVisible( item
);
5229 long wxGenericListCtrl::FindItem( long start
, const wxString
& str
, bool partial
)
5231 return m_mainWin
->FindItem( start
, str
, partial
);
5234 long wxGenericListCtrl::FindItem( long start
, wxUIntPtr data
)
5236 return m_mainWin
->FindItem( start
, data
);
5239 long wxGenericListCtrl::FindItem( long WXUNUSED(start
), const wxPoint
& pt
,
5240 int WXUNUSED(direction
))
5242 return m_mainWin
->FindItem( pt
);
5245 // TODO: sub item hit testing
5246 long wxGenericListCtrl::HitTest(const wxPoint
& point
, int& flags
, long *) const
5248 return m_mainWin
->HitTest( (int)point
.x
, (int)point
.y
, flags
);
5251 long wxGenericListCtrl::InsertItem( wxListItem
& info
)
5253 m_mainWin
->InsertItem( info
);
5254 return info
.m_itemId
;
5257 long wxGenericListCtrl::InsertItem( long index
, const wxString
&label
)
5260 info
.m_text
= label
;
5261 info
.m_mask
= wxLIST_MASK_TEXT
;
5262 info
.m_itemId
= index
;
5263 return InsertItem( info
);
5266 long wxGenericListCtrl::InsertItem( long index
, int imageIndex
)
5269 info
.m_mask
= wxLIST_MASK_IMAGE
;
5270 info
.m_image
= imageIndex
;
5271 info
.m_itemId
= index
;
5272 return InsertItem( info
);
5275 long wxGenericListCtrl::InsertItem( long index
, const wxString
&label
, int imageIndex
)
5278 info
.m_text
= label
;
5279 info
.m_image
= imageIndex
;
5280 info
.m_mask
= wxLIST_MASK_TEXT
| wxLIST_MASK_IMAGE
;
5281 info
.m_itemId
= index
;
5282 return InsertItem( info
);
5285 long wxGenericListCtrl::InsertColumn( long col
, wxListItem
&item
)
5287 wxCHECK_MSG( m_headerWin
, -1, _T("can't add column in non report mode") );
5289 m_mainWin
->InsertColumn( col
, item
);
5291 // if we hadn't had a header before but have one now
5292 // then we need to relayout the window
5293 if ( GetColumnCount() == 1 && m_mainWin
->HasHeader() )
5294 ResizeReportView(true /* have header */);
5296 m_headerWin
->Refresh();
5301 long wxGenericListCtrl::InsertColumn( long col
, const wxString
&heading
,
5302 int format
, int width
)
5305 item
.m_mask
= wxLIST_MASK_TEXT
| wxLIST_MASK_FORMAT
;
5306 item
.m_text
= heading
;
5309 item
.m_mask
|= wxLIST_MASK_WIDTH
;
5310 item
.m_width
= width
;
5313 item
.m_format
= format
;
5315 return InsertColumn( col
, item
);
5318 bool wxGenericListCtrl::ScrollList( int WXUNUSED(dx
), int WXUNUSED(dy
) )
5324 // fn is a function which takes 3 long arguments: item1, item2, data.
5325 // item1 is the long data associated with a first item (NOT the index).
5326 // item2 is the long data associated with a second item (NOT the index).
5327 // data is the same value as passed to SortItems.
5328 // The return value is a negative number if the first item should precede the second
5329 // item, a positive number of the second item should precede the first,
5330 // or zero if the two items are equivalent.
5331 // data is arbitrary data to be passed to the sort function.
5333 bool wxGenericListCtrl::SortItems( wxListCtrlCompare fn
, long data
)
5335 m_mainWin
->SortItems( fn
, data
);
5339 // ----------------------------------------------------------------------------
5341 // ----------------------------------------------------------------------------
5343 void wxGenericListCtrl::OnSize(wxSizeEvent
& WXUNUSED(event
))
5348 ResizeReportView(m_mainWin
->HasHeader());
5349 m_mainWin
->RecalculatePositions();
5352 void wxGenericListCtrl::ResizeReportView(bool showHeader
)
5355 GetClientSize( &cw
, &ch
);
5359 m_headerWin
->SetSize( 0, 0, cw
, m_headerHeight
);
5360 if(ch
> m_headerHeight
)
5361 m_mainWin
->SetSize( 0, m_headerHeight
+ 1,
5362 cw
, ch
- m_headerHeight
- 1 );
5364 m_mainWin
->SetSize( 0, m_headerHeight
+ 1,
5367 else // no header window
5369 m_mainWin
->SetSize( 0, 0, cw
, ch
);
5373 void wxGenericListCtrl::OnInternalIdle()
5375 wxWindow::OnInternalIdle();
5377 // do it only if needed
5378 if ( !m_mainWin
->m_dirty
)
5381 m_mainWin
->RecalculatePositions();
5384 // ----------------------------------------------------------------------------
5386 // ----------------------------------------------------------------------------
5388 bool wxGenericListCtrl::SetBackgroundColour( const wxColour
&colour
)
5392 m_mainWin
->SetBackgroundColour( colour
);
5393 m_mainWin
->m_dirty
= true;
5399 bool wxGenericListCtrl::SetForegroundColour( const wxColour
&colour
)
5401 if ( !wxWindow::SetForegroundColour( colour
) )
5406 m_mainWin
->SetForegroundColour( colour
);
5407 m_mainWin
->m_dirty
= true;
5411 m_headerWin
->SetForegroundColour( colour
);
5416 bool wxGenericListCtrl::SetFont( const wxFont
&font
)
5418 if ( !wxWindow::SetFont( font
) )
5423 m_mainWin
->SetFont( font
);
5424 m_mainWin
->m_dirty
= true;
5429 m_headerWin
->SetFont( font
);
5430 CalculateAndSetHeaderHeight();
5440 wxGenericListCtrl::GetClassDefaultAttributes(wxWindowVariant variant
)
5443 // Use the same color scheme as wxListBox
5444 return wxListBox::GetClassDefaultAttributes(variant
);
5446 wxUnusedVar(variant
);
5447 wxVisualAttributes attr
;
5448 attr
.colFg
= wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT
);
5449 attr
.colBg
= wxSystemSettings::GetColour(wxSYS_COLOUR_LISTBOX
);
5450 attr
.font
= wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT
);
5455 // ----------------------------------------------------------------------------
5456 // methods forwarded to m_mainWin
5457 // ----------------------------------------------------------------------------
5459 #if wxUSE_DRAG_AND_DROP
5461 void wxGenericListCtrl::SetDropTarget( wxDropTarget
*dropTarget
)
5463 m_mainWin
->SetDropTarget( dropTarget
);
5466 wxDropTarget
*wxGenericListCtrl::GetDropTarget() const
5468 return m_mainWin
->GetDropTarget();
5473 bool wxGenericListCtrl::SetCursor( const wxCursor
&cursor
)
5475 return m_mainWin
? m_mainWin
->wxWindow::SetCursor(cursor
) : false;
5478 wxColour
wxGenericListCtrl::GetBackgroundColour() const
5480 return m_mainWin
? m_mainWin
->GetBackgroundColour() : wxColour();
5483 wxColour
wxGenericListCtrl::GetForegroundColour() const
5485 return m_mainWin
? m_mainWin
->GetForegroundColour() : wxColour();
5488 bool wxGenericListCtrl::DoPopupMenu( wxMenu
*menu
, int x
, int y
)
5491 return m_mainWin
->PopupMenu( menu
, x
, y
);
5497 void wxGenericListCtrl::DoClientToScreen( int *x
, int *y
) const
5499 m_mainWin
->DoClientToScreen(x
, y
);
5502 void wxGenericListCtrl::DoScreenToClient( int *x
, int *y
) const
5504 m_mainWin
->DoScreenToClient(x
, y
);
5507 void wxGenericListCtrl::SetFocus()
5509 // The test in window.cpp fails as we are a composite
5510 // window, so it checks against "this", but not m_mainWin.
5511 if ( DoFindFocus() != this )
5512 m_mainWin
->SetFocus();
5515 wxSize
wxGenericListCtrl::DoGetBestSize() const
5517 // Something is better than nothing...
5518 // 100x80 is what the MSW version will get from the default
5519 // wxControl::DoGetBestSize
5520 return wxSize(100, 80);
5523 // ----------------------------------------------------------------------------
5524 // virtual list control support
5525 // ----------------------------------------------------------------------------
5527 wxString
wxGenericListCtrl::OnGetItemText(long WXUNUSED(item
), long WXUNUSED(col
)) const
5529 // this is a pure virtual function, in fact - which is not really pure
5530 // because the controls which are not virtual don't need to implement it
5531 wxFAIL_MSG( _T("wxGenericListCtrl::OnGetItemText not supposed to be called") );
5533 return wxEmptyString
;
5536 int wxGenericListCtrl::OnGetItemImage(long WXUNUSED(item
)) const
5538 wxCHECK_MSG(!GetImageList(wxIMAGE_LIST_SMALL
),
5540 wxT("List control has an image list, OnGetItemImage or OnGetItemColumnImage should be overridden."));
5544 int wxGenericListCtrl::OnGetItemColumnImage(long item
, long column
) const
5547 return OnGetItemImage(item
);
5553 wxGenericListCtrl::OnGetItemAttr(long WXUNUSED_UNLESS_DEBUG(item
)) const
5555 wxASSERT_MSG( item
>= 0 && item
< GetItemCount(),
5556 _T("invalid item index in OnGetItemAttr()") );
5558 // no attributes by default
5562 void wxGenericListCtrl::SetItemCount(long count
)
5564 wxASSERT_MSG( IsVirtual(), _T("this is for virtual controls only") );
5566 m_mainWin
->SetItemCount(count
);
5569 void wxGenericListCtrl::RefreshItem(long item
)
5571 m_mainWin
->RefreshLine(item
);
5574 void wxGenericListCtrl::RefreshItems(long itemFrom
, long itemTo
)
5576 m_mainWin
->RefreshLines(itemFrom
, itemTo
);
5579 // Generic wxListCtrl is more or less a container for two other
5580 // windows which drawings are done upon. These are namely
5581 // 'm_headerWin' and 'm_mainWin'.
5582 // Here we override 'virtual wxWindow::Refresh()' to mimic the
5583 // behaviour wxListCtrl has under wxMSW.
5585 void wxGenericListCtrl::Refresh(bool eraseBackground
, const wxRect
*rect
)
5589 // The easy case, no rectangle specified.
5591 m_headerWin
->Refresh(eraseBackground
);
5594 m_mainWin
->Refresh(eraseBackground
);
5598 // Refresh the header window
5601 wxRect rectHeader
= m_headerWin
->GetRect();
5602 rectHeader
.Intersect(*rect
);
5603 if (rectHeader
.GetWidth() && rectHeader
.GetHeight())
5606 m_headerWin
->GetPosition(&x
, &y
);
5607 rectHeader
.Offset(-x
, -y
);
5608 m_headerWin
->Refresh(eraseBackground
, &rectHeader
);
5612 // Refresh the main window
5615 wxRect rectMain
= m_mainWin
->GetRect();
5616 rectMain
.Intersect(*rect
);
5617 if (rectMain
.GetWidth() && rectMain
.GetHeight())
5620 m_mainWin
->GetPosition(&x
, &y
);
5621 rectMain
.Offset(-x
, -y
);
5622 m_mainWin
->Refresh(eraseBackground
, &rectMain
);
5628 void wxGenericListCtrl::Freeze()
5630 m_mainWin
->Freeze();
5633 void wxGenericListCtrl::Thaw()
5638 #endif // wxUSE_LISTCTRL