1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/generic/listctrl.cpp
3 // Purpose: generic implementation of wxListCtrl
4 // Author: Robert Roebling
5 // Vadim Zeitlin (virtual list control support)
7 // Copyright: (c) 1998 Robert Roebling
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
13 // 1. we need to implement searching/sorting for virtual controls somehow
14 // 2. when changing selection the lines are refreshed twice
17 // For compilers that support precompilation, includes "wx.h".
18 #include "wx/wxprec.h"
26 #include "wx/listctrl.h"
28 #if (!defined(__WXMSW__) || defined(__WXUNIVERSAL__)) && !defined(__WXMAC__)
29 // if we have a native version, its implementation file does all this
30 IMPLEMENT_DYNAMIC_CLASS(wxListItem
, wxObject
)
31 IMPLEMENT_DYNAMIC_CLASS(wxListView
, wxListCtrl
)
32 IMPLEMENT_DYNAMIC_CLASS(wxListEvent
, wxNotifyEvent
)
34 IMPLEMENT_DYNAMIC_CLASS(wxListCtrl
, wxGenericListCtrl
)
38 #include "wx/scrolwin.h"
40 #include "wx/settings.h"
41 #include "wx/dynarray.h"
42 #include "wx/dcclient.h"
43 #include "wx/dcscreen.h"
47 #include "wx/imaglist.h"
48 #include "wx/selstore.h"
49 #include "wx/renderer.h"
52 #include "wx/mac/private.h"
56 #include "wx/gtk/private.h"
57 #include "wx/gtk/win_gtk.h"
62 // NOTE: If using the wxListBox visual attributes works everywhere then this can
63 // be removed, as well as the #else case below.
64 #define _USE_VISATTR 0
67 // ----------------------------------------------------------------------------
69 // ----------------------------------------------------------------------------
71 // // the height of the header window (FIXME: should depend on its font!)
72 // static const int HEADER_HEIGHT = 23;
74 static const int SCROLL_UNIT_X
= 15;
76 // the spacing between the lines (in report mode)
77 static const int LINE_SPACING
= 0;
79 // extra margins around the text label
81 static const int EXTRA_WIDTH
= 6;
83 static const int EXTRA_WIDTH
= 4;
85 static const int EXTRA_HEIGHT
= 4;
87 // margin between the window and the items
88 static const int EXTRA_BORDER_X
= 2;
89 static const int EXTRA_BORDER_Y
= 2;
91 // offset for the header window
92 static const int HEADER_OFFSET_X
= 1;
93 static const int HEADER_OFFSET_Y
= 1;
95 // margin between rows of icons in [small] icon view
96 static const int MARGIN_BETWEEN_ROWS
= 6;
98 // when autosizing the columns, add some slack
99 static const int AUTOSIZE_COL_MARGIN
= 10;
101 // default width for the header columns
102 static const int WIDTH_COL_DEFAULT
= 80;
104 // the space between the image and the text in the report mode
105 static const int IMAGE_MARGIN_IN_REPORT_MODE
= 5;
107 // ============================================================================
109 // ============================================================================
111 //-----------------------------------------------------------------------------
112 // wxColWidthInfo (internal)
113 //-----------------------------------------------------------------------------
115 struct wxColWidthInfo
118 bool bNeedsUpdate
; // only set to true when an item whose
119 // width == nMaxWidth is removed
121 wxColWidthInfo(int w
= 0, bool needsUpdate
= false)
124 bNeedsUpdate
= needsUpdate
;
128 WX_DEFINE_ARRAY_PTR(wxColWidthInfo
*, ColWidthArray
);
130 //-----------------------------------------------------------------------------
131 // wxListItemData (internal)
132 //-----------------------------------------------------------------------------
137 wxListItemData(wxListMainWindow
*owner
);
140 void SetItem( const wxListItem
&info
);
141 void SetImage( int image
) { m_image
= image
; }
142 void SetData( wxUIntPtr data
) { m_data
= data
; }
143 void SetPosition( int x
, int y
);
144 void SetSize( int width
, int height
);
146 bool HasText() const { return !m_text
.empty(); }
147 const wxString
& GetText() const { return m_text
; }
148 void SetText(const wxString
& text
) { m_text
= text
; }
150 // we can't use empty string for measuring the string width/height, so
151 // always return something
152 wxString
GetTextForMeasuring() const
154 wxString s
= GetText();
161 bool IsHit( int x
, int y
) const;
165 int GetWidth() const;
166 int GetHeight() const;
168 int GetImage() const { return m_image
; }
169 bool HasImage() const { return GetImage() != -1; }
171 void GetItem( wxListItem
&info
) const;
173 void SetAttr(wxListItemAttr
*attr
) { m_attr
= attr
; }
174 wxListItemAttr
*GetAttr() const { return m_attr
; }
177 // the item image or -1
180 // user data associated with the item
183 // the item coordinates are not used in report mode; instead this pointer is
184 // NULL and the owner window is used to retrieve the item position and size
187 // the list ctrl we are in
188 wxListMainWindow
*m_owner
;
190 // custom attributes or NULL
191 wxListItemAttr
*m_attr
;
194 // common part of all ctors
200 //-----------------------------------------------------------------------------
201 // wxListHeaderData (internal)
202 //-----------------------------------------------------------------------------
204 class wxListHeaderData
: public wxObject
208 wxListHeaderData( const wxListItem
&info
);
209 void SetItem( const wxListItem
&item
);
210 void SetPosition( int x
, int y
);
211 void SetWidth( int w
);
212 void SetFormat( int format
);
213 void SetHeight( int h
);
214 bool HasImage() const;
216 bool HasText() const { return !m_text
.empty(); }
217 const wxString
& GetText() const { return m_text
; }
218 void SetText(const wxString
& text
) { m_text
= text
; }
220 void GetItem( wxListItem
&item
);
222 bool IsHit( int x
, int y
) const;
223 int GetImage() const;
224 int GetWidth() const;
225 int GetFormat() const;
241 //-----------------------------------------------------------------------------
242 // wxListLineData (internal)
243 //-----------------------------------------------------------------------------
245 WX_DECLARE_EXPORTED_LIST(wxListItemData
, wxListItemDataList
);
246 #include "wx/listimpl.cpp"
247 WX_DEFINE_LIST(wxListItemDataList
)
252 // the list of subitems: only may have more than one item in report mode
253 wxListItemDataList m_items
;
255 // this is not used in report view
267 // the part to be highlighted
268 wxRect m_rectHighlight
;
270 // extend all our rects to be centered inside the one of given width
271 void ExtendWidth(wxCoord w
)
273 wxASSERT_MSG( m_rectAll
.width
<= w
,
274 _T("width can only be increased") );
277 m_rectLabel
.x
= m_rectAll
.x
+ (w
- m_rectLabel
.width
) / 2;
278 m_rectIcon
.x
= m_rectAll
.x
+ (w
- m_rectIcon
.width
) / 2;
279 m_rectHighlight
.x
= m_rectAll
.x
+ (w
- m_rectHighlight
.width
) / 2;
284 // is this item selected? [NB: not used in virtual mode]
287 // back pointer to the list ctrl
288 wxListMainWindow
*m_owner
;
291 wxListLineData(wxListMainWindow
*owner
);
295 WX_CLEAR_LIST(wxListItemDataList
, m_items
);
299 // are we in report mode?
300 inline bool InReportView() const;
302 // are we in virtual report mode?
303 inline bool IsVirtual() const;
305 // these 2 methods shouldn't be called for report view controls, in that
306 // case we determine our position/size ourselves
308 // calculate the size of the line
309 void CalculateSize( wxDC
*dc
, int spacing
);
311 // remember the position this line appears at
312 void SetPosition( int x
, int y
, int spacing
);
316 void SetImage( int image
) { SetImage(0, image
); }
317 int GetImage() const { return GetImage(0); }
318 void SetImage( int index
, int image
);
319 int GetImage( int index
) const;
321 bool HasImage() const { return GetImage() != -1; }
322 bool HasText() const { return !GetText(0).empty(); }
324 void SetItem( int index
, const wxListItem
&info
);
325 void GetItem( int index
, wxListItem
&info
);
327 wxString
GetText(int index
) const;
328 void SetText( int index
, const wxString
& s
);
330 wxListItemAttr
*GetAttr() const;
331 void SetAttr(wxListItemAttr
*attr
);
333 // return true if the highlighting really changed
334 bool Highlight( bool on
);
336 void ReverseHighlight();
338 bool IsHighlighted() const
340 wxASSERT_MSG( !IsVirtual(), _T("unexpected call to IsHighlighted") );
342 return m_highlighted
;
345 // draw the line on the given DC in icon/list mode
346 void Draw( wxDC
*dc
);
348 // the same in report mode
349 void DrawInReportMode( wxDC
*dc
,
351 const wxRect
& rectHL
,
355 // set the line to contain num items (only can be > 1 in report mode)
356 void InitItems( int num
);
358 // get the mode (i.e. style) of the list control
359 inline int GetMode() const;
361 // prepare the DC for drawing with these item's attributes, return true if
362 // we need to draw the items background to highlight it, false otherwise
363 bool SetAttributes(wxDC
*dc
,
364 const wxListItemAttr
*attr
,
367 // draw the text on the DC with the correct justification; also add an
368 // ellipsis if the text is too large to fit in the current width
369 void DrawTextFormatted(wxDC
*dc
,
370 const wxString
&text
,
373 int yMid
, // this is middle, not top, of the text
377 WX_DECLARE_EXPORTED_OBJARRAY(wxListLineData
, wxListLineDataArray
);
378 #include "wx/arrimpl.cpp"
379 WX_DEFINE_OBJARRAY(wxListLineDataArray
)
381 //-----------------------------------------------------------------------------
382 // wxListHeaderWindow (internal)
383 //-----------------------------------------------------------------------------
385 class wxListHeaderWindow
: public wxWindow
388 wxListMainWindow
*m_owner
;
389 const wxCursor
*m_currentCursor
;
390 wxCursor
*m_resizeCursor
;
393 // column being resized or -1
396 // divider line position in logical (unscrolled) coords
399 // minimal position beyond which the divider line
400 // can't be dragged in logical coords
404 wxListHeaderWindow();
406 wxListHeaderWindow( wxWindow
*win
,
408 wxListMainWindow
*owner
,
409 const wxPoint
&pos
= wxDefaultPosition
,
410 const wxSize
&size
= wxDefaultSize
,
412 const wxString
&name
= wxT("wxlistctrlcolumntitles") );
414 virtual ~wxListHeaderWindow();
417 void AdjustDC( wxDC
& dc
);
419 void OnPaint( wxPaintEvent
&event
);
420 void OnMouse( wxMouseEvent
&event
);
421 void OnSetFocus( wxFocusEvent
&event
);
427 // common part of all ctors
430 // generate and process the list event of the given type, return true if
431 // it wasn't vetoed, i.e. if we should proceed
432 bool SendListEvent(wxEventType type
, const wxPoint
& pos
);
434 DECLARE_DYNAMIC_CLASS(wxListHeaderWindow
)
435 DECLARE_EVENT_TABLE()
438 //-----------------------------------------------------------------------------
439 // wxListRenameTimer (internal)
440 //-----------------------------------------------------------------------------
442 class wxListRenameTimer
: public wxTimer
445 wxListMainWindow
*m_owner
;
448 wxListRenameTimer( wxListMainWindow
*owner
);
452 //-----------------------------------------------------------------------------
453 // wxListTextCtrlWrapper: wraps a wxTextCtrl to make it work for inline editing
454 //-----------------------------------------------------------------------------
456 class wxListTextCtrlWrapper
: public wxEvtHandler
459 // NB: text must be a valid object but not Create()d yet
460 wxListTextCtrlWrapper(wxListMainWindow
*owner
,
464 wxTextCtrl
*GetText() const { return m_text
; }
466 void AcceptChangesAndFinish();
469 void OnChar( wxKeyEvent
&event
);
470 void OnKeyUp( wxKeyEvent
&event
);
471 void OnKillFocus( wxFocusEvent
&event
);
473 bool AcceptChanges();
477 wxListMainWindow
*m_owner
;
479 wxString m_startValue
;
482 bool m_aboutToFinish
;
484 DECLARE_EVENT_TABLE()
487 //-----------------------------------------------------------------------------
488 // wxListMainWindow (internal)
489 //-----------------------------------------------------------------------------
491 WX_DECLARE_EXPORTED_LIST(wxListHeaderData
, wxListHeaderDataList
);
492 #include "wx/listimpl.cpp"
493 WX_DEFINE_LIST(wxListHeaderDataList
)
495 class wxListMainWindow
: public wxScrolledWindow
499 wxListMainWindow( wxWindow
*parent
,
501 const wxPoint
& pos
= wxDefaultPosition
,
502 const wxSize
& size
= wxDefaultSize
,
504 const wxString
&name
= _T("listctrlmainwindow") );
506 virtual ~wxListMainWindow();
508 bool HasFlag(int flag
) const { return m_parent
->HasFlag(flag
); }
510 // return true if this is a virtual list control
511 bool IsVirtual() const { return HasFlag(wxLC_VIRTUAL
); }
513 // return true if the control is in report mode
514 bool InReportView() const { return HasFlag(wxLC_REPORT
); }
516 // return true if we are in single selection mode, false if multi sel
517 bool IsSingleSel() const { return HasFlag(wxLC_SINGLE_SEL
); }
519 // do we have a header window?
520 bool HasHeader() const
521 { return InReportView() && !HasFlag(wxLC_NO_HEADER
); }
523 void HighlightAll( bool on
);
525 // all these functions only do something if the line is currently visible
527 // change the line "selected" state, return true if it really changed
528 bool HighlightLine( size_t line
, bool highlight
= true);
530 // as HighlightLine() but do it for the range of lines: this is incredibly
531 // more efficient for virtual list controls!
533 // NB: unlike HighlightLine() this one does refresh the lines on screen
534 void HighlightLines( size_t lineFrom
, size_t lineTo
, bool on
= true );
536 // toggle the line state and refresh it
537 void ReverseHighlight( size_t line
)
538 { HighlightLine(line
, !IsHighlighted(line
)); RefreshLine(line
); }
540 // return true if the line is highlighted
541 bool IsHighlighted(size_t line
) const;
543 // refresh one or several lines at once
544 void RefreshLine( size_t line
);
545 void RefreshLines( size_t lineFrom
, size_t lineTo
);
547 // refresh all selected items
548 void RefreshSelected();
550 // refresh all lines below the given one: the difference with
551 // RefreshLines() is that the index here might not be a valid one (happens
552 // when the last line is deleted)
553 void RefreshAfter( size_t lineFrom
);
555 // the methods which are forwarded to wxListLineData itself in list/icon
556 // modes but are here because the lines don't store their positions in the
559 // get the bound rect for the entire line
560 wxRect
GetLineRect(size_t line
) const;
562 // get the bound rect of the label
563 wxRect
GetLineLabelRect(size_t line
) const;
565 // get the bound rect of the items icon (only may be called if we do have
567 wxRect
GetLineIconRect(size_t line
) const;
569 // get the rect to be highlighted when the item has focus
570 wxRect
GetLineHighlightRect(size_t line
) const;
572 // get the size of the total line rect
573 wxSize
GetLineSize(size_t line
) const
574 { return GetLineRect(line
).GetSize(); }
576 // return the hit code for the corresponding position (in this line)
577 long HitTestLine(size_t line
, int x
, int y
) const;
579 // bring the selected item into view, scrolling to it if necessary
580 void MoveToItem(size_t item
);
582 // bring the current item into view
583 void MoveToFocus() { MoveToItem(m_current
); }
585 // start editing the label of the given item
586 wxTextCtrl
*EditLabel(long item
,
587 wxClassInfo
* textControlClass
= CLASSINFO(wxTextCtrl
));
588 wxTextCtrl
*GetEditControl() const
590 return m_textctrlWrapper
? m_textctrlWrapper
->GetText() : NULL
;
593 void FinishEditing(wxTextCtrl
*text
)
596 m_textctrlWrapper
= NULL
;
597 SetFocusIgnoringChildren();
600 // suspend/resume redrawing the control
604 void OnRenameTimer();
605 bool OnRenameAccept(size_t itemEdit
, const wxString
& value
);
606 void OnRenameCancelled(size_t itemEdit
);
608 void OnMouse( wxMouseEvent
&event
);
610 // called to switch the selection from the current item to newCurrent,
611 void OnArrowChar( size_t newCurrent
, const wxKeyEvent
& event
);
613 void OnChar( wxKeyEvent
&event
);
614 void OnKeyDown( wxKeyEvent
&event
);
615 void OnSetFocus( wxFocusEvent
&event
);
616 void OnKillFocus( wxFocusEvent
&event
);
617 void OnScroll( wxScrollWinEvent
& event
);
619 void OnPaint( wxPaintEvent
&event
);
621 void DrawImage( int index
, wxDC
*dc
, int x
, int y
);
622 void GetImageSize( int index
, int &width
, int &height
) const;
623 int GetTextLength( const wxString
&s
) const;
625 void SetImageList( wxImageList
*imageList
, int which
);
626 void SetItemSpacing( int spacing
, bool isSmall
= false );
627 int GetItemSpacing( bool isSmall
= false );
629 void SetColumn( int col
, wxListItem
&item
);
630 void SetColumnWidth( int col
, int width
);
631 void GetColumn( int col
, wxListItem
&item
) const;
632 int GetColumnWidth( int col
) const;
633 int GetColumnCount() const { return m_columns
.GetCount(); }
635 // returns the sum of the heights of all columns
636 int GetHeaderWidth() const;
638 int GetCountPerPage() const;
640 void SetItem( wxListItem
&item
);
641 void GetItem( wxListItem
&item
) const;
642 void SetItemState( long item
, long state
, long stateMask
);
643 void SetItemStateAll( long state
, long stateMask
);
644 int GetItemState( long item
, long stateMask
) const;
645 void GetItemRect( long index
, wxRect
&rect
) const;
646 wxRect
GetViewRect() const;
647 bool GetItemPosition( long item
, wxPoint
& pos
) const;
648 int GetSelectedItemCount() const;
650 wxString
GetItemText(long item
) const
653 info
.m_mask
= wxLIST_MASK_TEXT
;
654 info
.m_itemId
= item
;
659 void SetItemText(long item
, const wxString
& value
)
662 info
.m_mask
= wxLIST_MASK_TEXT
;
663 info
.m_itemId
= item
;
668 // set the scrollbars and update the positions of the items
669 void RecalculatePositions(bool noRefresh
= false);
671 // refresh the window and the header
674 long GetNextItem( long item
, int geometry
, int state
) const;
675 void DeleteItem( long index
);
676 void DeleteAllItems();
677 void DeleteColumn( int col
);
678 void DeleteEverything();
679 void EnsureVisible( long index
);
680 long FindItem( long start
, const wxString
& str
, bool partial
= false );
681 long FindItem( long start
, wxUIntPtr data
);
682 long FindItem( const wxPoint
& pt
);
683 long HitTest( int x
, int y
, int &flags
) const;
684 void InsertItem( wxListItem
&item
);
685 void InsertColumn( long col
, wxListItem
&item
);
686 int GetItemWidthWithImage(wxListItem
* item
);
687 void SortItems( wxListCtrlCompare fn
, long data
);
689 size_t GetItemCount() const;
690 bool IsEmpty() const { return GetItemCount() == 0; }
691 void SetItemCount(long count
);
693 // change the current (== focused) item, send a notification event
694 void ChangeCurrent(size_t current
);
695 void ResetCurrent() { ChangeCurrent((size_t)-1); }
696 bool HasCurrent() const { return m_current
!= (size_t)-1; }
698 // send out a wxListEvent
699 void SendNotify( size_t line
,
701 const wxPoint
& point
= wxDefaultPosition
);
703 // override base class virtual to reset m_lineHeight when the font changes
704 virtual bool SetFont(const wxFont
& font
)
706 if ( !wxScrolledWindow::SetFont(font
) )
714 // these are for wxListLineData usage only
716 // get the backpointer to the list ctrl
717 wxGenericListCtrl
*GetListCtrl() const
719 return wxStaticCast(GetParent(), wxGenericListCtrl
);
722 // get the height of all lines (assuming they all do have the same height)
723 wxCoord
GetLineHeight() const;
725 // get the y position of the given line (only for report view)
726 wxCoord
GetLineY(size_t line
) const;
728 // get the brush to use for the item highlighting
729 wxBrush
*GetHighlightBrush() const
731 return m_hasFocus
? m_highlightBrush
: m_highlightUnfocusedBrush
;
734 bool HasFocus() const
740 // the array of all line objects for a non virtual list control (for the
741 // virtual list control we only ever use m_lines[0])
742 wxListLineDataArray m_lines
;
744 // the list of column objects
745 wxListHeaderDataList m_columns
;
747 // currently focused item or -1
750 // the number of lines per page
753 // this flag is set when something which should result in the window
754 // redrawing happens (i.e. an item was added or deleted, or its appearance
755 // changed) and OnPaint() doesn't redraw the window while it is set which
756 // allows to minimize the number of repaintings when a lot of items are
757 // being added. The real repainting occurs only after the next OnIdle()
761 wxColour
*m_highlightColour
;
762 wxImageList
*m_small_image_list
;
763 wxImageList
*m_normal_image_list
;
765 int m_normal_spacing
;
769 wxTimer
*m_renameTimer
;
773 ColWidthArray m_aColWidths
;
775 // for double click logic
776 size_t m_lineLastClicked
,
777 m_lineBeforeLastClicked
,
778 m_lineSelectSingleOnUp
;
781 wxWindow
*GetMainWindowOfCompositeControl() { return GetParent(); }
783 // the total count of items in a virtual list control
786 // the object maintaining the items selection state, only used in virtual
788 wxSelectionStore m_selStore
;
790 // common part of all ctors
793 // get the line data for the given index
794 wxListLineData
*GetLine(size_t n
) const
796 wxASSERT_MSG( n
!= (size_t)-1, _T("invalid line index") );
800 wxConstCast(this, wxListMainWindow
)->CacheLineData(n
);
807 // get a dummy line which can be used for geometry calculations and such:
808 // you must use GetLine() if you want to really draw the line
809 wxListLineData
*GetDummyLine() const;
811 // cache the line data of the n-th line in m_lines[0]
812 void CacheLineData(size_t line
);
814 // get the range of visible lines
815 void GetVisibleLinesRange(size_t *from
, size_t *to
);
817 // force us to recalculate the range of visible lines
818 void ResetVisibleLinesRange() { m_lineFrom
= (size_t)-1; }
820 // get the colour to be used for drawing the rules
821 wxColour
GetRuleColour() const
823 return wxSystemSettings::GetColour(wxSYS_COLOUR_3DLIGHT
);
827 // initialize the current item if needed
828 void UpdateCurrent();
830 // delete all items but don't refresh: called from dtor
831 void DoDeleteAllItems();
833 // the height of one line using the current font
834 wxCoord m_lineHeight
;
836 // the total header width or 0 if not calculated yet
837 wxCoord m_headerWidth
;
839 // the first and last lines being shown on screen right now (inclusive),
840 // both may be -1 if they must be calculated so never access them directly:
841 // use GetVisibleLinesRange() above instead
845 // the brushes to use for item highlighting when we do/don't have focus
846 wxBrush
*m_highlightBrush
,
847 *m_highlightUnfocusedBrush
;
849 // if this is > 0, the control is frozen and doesn't redraw itself
850 size_t m_freezeCount
;
852 // wrapper around the text control currently used for in place editing or
853 // NULL if no item is being edited
854 wxListTextCtrlWrapper
*m_textctrlWrapper
;
857 DECLARE_DYNAMIC_CLASS(wxListMainWindow
)
858 DECLARE_EVENT_TABLE()
860 friend class wxGenericListCtrl
;
864 wxListItemData::~wxListItemData()
866 // in the virtual list control the attributes are managed by the main
867 // program, so don't delete them
868 if ( !m_owner
->IsVirtual() )
874 void wxListItemData::Init()
882 wxListItemData::wxListItemData(wxListMainWindow
*owner
)
888 if ( owner
->InReportView() )
894 void wxListItemData::SetItem( const wxListItem
&info
)
896 if ( info
.m_mask
& wxLIST_MASK_TEXT
)
897 SetText(info
.m_text
);
898 if ( info
.m_mask
& wxLIST_MASK_IMAGE
)
899 m_image
= info
.m_image
;
900 if ( info
.m_mask
& wxLIST_MASK_DATA
)
901 m_data
= info
.m_data
;
903 if ( info
.HasAttributes() )
906 m_attr
->AssignFrom(*info
.GetAttributes());
908 m_attr
= new wxListItemAttr(*info
.GetAttributes());
916 m_rect
->width
= info
.m_width
;
920 void wxListItemData::SetPosition( int x
, int y
)
922 wxCHECK_RET( m_rect
, _T("unexpected SetPosition() call") );
928 void wxListItemData::SetSize( int width
, int height
)
930 wxCHECK_RET( m_rect
, _T("unexpected SetSize() call") );
933 m_rect
->width
= width
;
935 m_rect
->height
= height
;
938 bool wxListItemData::IsHit( int x
, int y
) const
940 wxCHECK_MSG( m_rect
, false, _T("can't be called in this mode") );
942 return wxRect(GetX(), GetY(), GetWidth(), GetHeight()).Contains(x
, y
);
945 int wxListItemData::GetX() const
947 wxCHECK_MSG( m_rect
, 0, _T("can't be called in this mode") );
952 int wxListItemData::GetY() const
954 wxCHECK_MSG( m_rect
, 0, _T("can't be called in this mode") );
959 int wxListItemData::GetWidth() const
961 wxCHECK_MSG( m_rect
, 0, _T("can't be called in this mode") );
963 return m_rect
->width
;
966 int wxListItemData::GetHeight() const
968 wxCHECK_MSG( m_rect
, 0, _T("can't be called in this mode") );
970 return m_rect
->height
;
973 void wxListItemData::GetItem( wxListItem
&info
) const
975 long mask
= info
.m_mask
;
977 // by default, get everything for backwards compatibility
980 if ( mask
& wxLIST_MASK_TEXT
)
981 info
.m_text
= m_text
;
982 if ( mask
& wxLIST_MASK_IMAGE
)
983 info
.m_image
= m_image
;
984 if ( mask
& wxLIST_MASK_DATA
)
985 info
.m_data
= m_data
;
989 if ( m_attr
->HasTextColour() )
990 info
.SetTextColour(m_attr
->GetTextColour());
991 if ( m_attr
->HasBackgroundColour() )
992 info
.SetBackgroundColour(m_attr
->GetBackgroundColour());
993 if ( m_attr
->HasFont() )
994 info
.SetFont(m_attr
->GetFont());
998 //-----------------------------------------------------------------------------
1000 //-----------------------------------------------------------------------------
1002 void wxListHeaderData::Init()
1013 wxListHeaderData::wxListHeaderData()
1018 wxListHeaderData::wxListHeaderData( const wxListItem
&item
)
1025 void wxListHeaderData::SetItem( const wxListItem
&item
)
1027 m_mask
= item
.m_mask
;
1029 if ( m_mask
& wxLIST_MASK_TEXT
)
1030 m_text
= item
.m_text
;
1032 if ( m_mask
& wxLIST_MASK_IMAGE
)
1033 m_image
= item
.m_image
;
1035 if ( m_mask
& wxLIST_MASK_FORMAT
)
1036 m_format
= item
.m_format
;
1038 if ( m_mask
& wxLIST_MASK_WIDTH
)
1039 SetWidth(item
.m_width
);
1042 void wxListHeaderData::SetPosition( int x
, int y
)
1048 void wxListHeaderData::SetHeight( int h
)
1053 void wxListHeaderData::SetWidth( int w
)
1055 m_width
= w
< 0 ? WIDTH_COL_DEFAULT
: w
;
1058 void wxListHeaderData::SetFormat( int format
)
1063 bool wxListHeaderData::HasImage() const
1065 return m_image
!= -1;
1068 bool wxListHeaderData::IsHit( int x
, int y
) const
1070 return ((x
>= m_xpos
) && (x
<= m_xpos
+m_width
) && (y
>= m_ypos
) && (y
<= m_ypos
+m_height
));
1073 void wxListHeaderData::GetItem( wxListItem
& item
)
1075 item
.m_mask
= m_mask
;
1076 item
.m_text
= m_text
;
1077 item
.m_image
= m_image
;
1078 item
.m_format
= m_format
;
1079 item
.m_width
= m_width
;
1082 int wxListHeaderData::GetImage() const
1087 int wxListHeaderData::GetWidth() const
1092 int wxListHeaderData::GetFormat() const
1097 //-----------------------------------------------------------------------------
1099 //-----------------------------------------------------------------------------
1101 inline int wxListLineData::GetMode() const
1103 return m_owner
->GetListCtrl()->GetWindowStyleFlag() & wxLC_MASK_TYPE
;
1106 inline bool wxListLineData::InReportView() const
1108 return m_owner
->HasFlag(wxLC_REPORT
);
1111 inline bool wxListLineData::IsVirtual() const
1113 return m_owner
->IsVirtual();
1116 wxListLineData::wxListLineData( wxListMainWindow
*owner
)
1120 if ( InReportView() )
1123 m_gi
= new GeometryInfo
;
1125 m_highlighted
= false;
1127 InitItems( GetMode() == wxLC_REPORT
? m_owner
->GetColumnCount() : 1 );
1130 void wxListLineData::CalculateSize( wxDC
*dc
, int spacing
)
1132 wxListItemDataList::compatibility_iterator node
= m_items
.GetFirst();
1133 wxCHECK_RET( node
, _T("no subitems at all??") );
1135 wxListItemData
*item
= node
->GetData();
1140 switch ( GetMode() )
1143 case wxLC_SMALL_ICON
:
1144 m_gi
->m_rectAll
.width
= spacing
;
1146 s
= item
->GetText();
1151 m_gi
->m_rectLabel
.width
=
1152 m_gi
->m_rectLabel
.height
= 0;
1156 dc
->GetTextExtent( s
, &lw
, &lh
);
1160 m_gi
->m_rectAll
.height
= spacing
+ lh
;
1162 m_gi
->m_rectAll
.width
= lw
;
1164 m_gi
->m_rectLabel
.width
= lw
;
1165 m_gi
->m_rectLabel
.height
= lh
;
1168 if (item
->HasImage())
1171 m_owner
->GetImageSize( item
->GetImage(), w
, h
);
1172 m_gi
->m_rectIcon
.width
= w
+ 8;
1173 m_gi
->m_rectIcon
.height
= h
+ 8;
1175 if ( m_gi
->m_rectIcon
.width
> m_gi
->m_rectAll
.width
)
1176 m_gi
->m_rectAll
.width
= m_gi
->m_rectIcon
.width
;
1177 if ( m_gi
->m_rectIcon
.height
+ lh
> m_gi
->m_rectAll
.height
- 4 )
1178 m_gi
->m_rectAll
.height
= m_gi
->m_rectIcon
.height
+ lh
+ 4;
1181 if ( item
->HasText() )
1183 m_gi
->m_rectHighlight
.width
= m_gi
->m_rectLabel
.width
;
1184 m_gi
->m_rectHighlight
.height
= m_gi
->m_rectLabel
.height
;
1186 else // no text, highlight the icon
1188 m_gi
->m_rectHighlight
.width
= m_gi
->m_rectIcon
.width
;
1189 m_gi
->m_rectHighlight
.height
= m_gi
->m_rectIcon
.height
;
1194 s
= item
->GetTextForMeasuring();
1196 dc
->GetTextExtent( s
, &lw
, &lh
);
1200 m_gi
->m_rectLabel
.width
= lw
;
1201 m_gi
->m_rectLabel
.height
= lh
;
1203 m_gi
->m_rectAll
.width
= lw
;
1204 m_gi
->m_rectAll
.height
= lh
;
1206 if (item
->HasImage())
1209 m_owner
->GetImageSize( item
->GetImage(), w
, h
);
1210 m_gi
->m_rectIcon
.width
= w
;
1211 m_gi
->m_rectIcon
.height
= h
;
1213 m_gi
->m_rectAll
.width
+= 4 + w
;
1214 if (h
> m_gi
->m_rectAll
.height
)
1215 m_gi
->m_rectAll
.height
= h
;
1218 m_gi
->m_rectHighlight
.width
= m_gi
->m_rectAll
.width
;
1219 m_gi
->m_rectHighlight
.height
= m_gi
->m_rectAll
.height
;
1223 wxFAIL_MSG( _T("unexpected call to SetSize") );
1227 wxFAIL_MSG( _T("unknown mode") );
1232 void wxListLineData::SetPosition( int x
, int y
, int spacing
)
1234 wxListItemDataList::compatibility_iterator node
= m_items
.GetFirst();
1235 wxCHECK_RET( node
, _T("no subitems at all??") );
1237 wxListItemData
*item
= node
->GetData();
1239 switch ( GetMode() )
1242 case wxLC_SMALL_ICON
:
1243 m_gi
->m_rectAll
.x
= x
;
1244 m_gi
->m_rectAll
.y
= y
;
1246 if ( item
->HasImage() )
1248 m_gi
->m_rectIcon
.x
= m_gi
->m_rectAll
.x
+ 4 +
1249 (m_gi
->m_rectAll
.width
- m_gi
->m_rectIcon
.width
) / 2;
1250 m_gi
->m_rectIcon
.y
= m_gi
->m_rectAll
.y
+ 4;
1253 if ( item
->HasText() )
1255 if (m_gi
->m_rectAll
.width
> spacing
)
1256 m_gi
->m_rectLabel
.x
= m_gi
->m_rectAll
.x
+ (EXTRA_WIDTH
/2);
1258 m_gi
->m_rectLabel
.x
= m_gi
->m_rectAll
.x
+ (EXTRA_WIDTH
/2) + (spacing
/ 2) - (m_gi
->m_rectLabel
.width
/ 2);
1259 m_gi
->m_rectLabel
.y
= m_gi
->m_rectAll
.y
+ m_gi
->m_rectAll
.height
+ 2 - m_gi
->m_rectLabel
.height
;
1260 m_gi
->m_rectHighlight
.x
= m_gi
->m_rectLabel
.x
- 2;
1261 m_gi
->m_rectHighlight
.y
= m_gi
->m_rectLabel
.y
- 2;
1263 else // no text, highlight the icon
1265 m_gi
->m_rectHighlight
.x
= m_gi
->m_rectIcon
.x
- 4;
1266 m_gi
->m_rectHighlight
.y
= m_gi
->m_rectIcon
.y
- 4;
1271 m_gi
->m_rectAll
.x
= x
;
1272 m_gi
->m_rectAll
.y
= y
;
1274 m_gi
->m_rectHighlight
.x
= m_gi
->m_rectAll
.x
;
1275 m_gi
->m_rectHighlight
.y
= m_gi
->m_rectAll
.y
;
1276 m_gi
->m_rectLabel
.y
= m_gi
->m_rectAll
.y
+ 2;
1278 if (item
->HasImage())
1280 m_gi
->m_rectIcon
.x
= m_gi
->m_rectAll
.x
+ 2;
1281 m_gi
->m_rectIcon
.y
= m_gi
->m_rectAll
.y
+ 2;
1282 m_gi
->m_rectLabel
.x
= m_gi
->m_rectAll
.x
+ 4 + (EXTRA_WIDTH
/2) + m_gi
->m_rectIcon
.width
;
1286 m_gi
->m_rectLabel
.x
= m_gi
->m_rectAll
.x
+ (EXTRA_WIDTH
/2);
1291 wxFAIL_MSG( _T("unexpected call to SetPosition") );
1295 wxFAIL_MSG( _T("unknown mode") );
1300 void wxListLineData::InitItems( int num
)
1302 for (int i
= 0; i
< num
; i
++)
1303 m_items
.Append( new wxListItemData(m_owner
) );
1306 void wxListLineData::SetItem( int index
, const wxListItem
&info
)
1308 wxListItemDataList::compatibility_iterator node
= m_items
.Item( index
);
1309 wxCHECK_RET( node
, _T("invalid column index in SetItem") );
1311 wxListItemData
*item
= node
->GetData();
1312 item
->SetItem( info
);
1315 void wxListLineData::GetItem( int index
, wxListItem
&info
)
1317 wxListItemDataList::compatibility_iterator node
= m_items
.Item( index
);
1320 wxListItemData
*item
= node
->GetData();
1321 item
->GetItem( info
);
1325 wxString
wxListLineData::GetText(int index
) const
1329 wxListItemDataList::compatibility_iterator node
= m_items
.Item( index
);
1332 wxListItemData
*item
= node
->GetData();
1333 s
= item
->GetText();
1339 void wxListLineData::SetText( int index
, const wxString
& s
)
1341 wxListItemDataList::compatibility_iterator node
= m_items
.Item( index
);
1344 wxListItemData
*item
= node
->GetData();
1349 void wxListLineData::SetImage( int index
, int image
)
1351 wxListItemDataList::compatibility_iterator node
= m_items
.Item( index
);
1352 wxCHECK_RET( node
, _T("invalid column index in SetImage()") );
1354 wxListItemData
*item
= node
->GetData();
1355 item
->SetImage(image
);
1358 int wxListLineData::GetImage( int index
) const
1360 wxListItemDataList::compatibility_iterator node
= m_items
.Item( index
);
1361 wxCHECK_MSG( node
, -1, _T("invalid column index in GetImage()") );
1363 wxListItemData
*item
= node
->GetData();
1364 return item
->GetImage();
1367 wxListItemAttr
*wxListLineData::GetAttr() const
1369 wxListItemDataList::compatibility_iterator node
= m_items
.GetFirst();
1370 wxCHECK_MSG( node
, NULL
, _T("invalid column index in GetAttr()") );
1372 wxListItemData
*item
= node
->GetData();
1373 return item
->GetAttr();
1376 void wxListLineData::SetAttr(wxListItemAttr
*attr
)
1378 wxListItemDataList::compatibility_iterator node
= m_items
.GetFirst();
1379 wxCHECK_RET( node
, _T("invalid column index in SetAttr()") );
1381 wxListItemData
*item
= node
->GetData();
1382 item
->SetAttr(attr
);
1385 bool wxListLineData::SetAttributes(wxDC
*dc
,
1386 const wxListItemAttr
*attr
,
1389 wxWindow
*listctrl
= m_owner
->GetParent();
1393 // don't use foreground colour for drawing highlighted items - this might
1394 // make them completely invisible (and there is no way to do bit
1395 // arithmetics on wxColour, unfortunately)
1400 if (m_owner
->HasFocus())
1406 colText
= wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHTTEXT
);
1408 else if ( attr
&& attr
->HasTextColour() )
1409 colText
= attr
->GetTextColour();
1411 colText
= listctrl
->GetForegroundColour();
1413 dc
->SetTextForeground(colText
);
1417 if ( attr
&& attr
->HasFont() )
1418 font
= attr
->GetFont();
1420 font
= listctrl
->GetFont();
1425 bool hasBgCol
= attr
&& attr
->HasBackgroundColour();
1426 if ( highlighted
|| hasBgCol
)
1429 dc
->SetBrush( *m_owner
->GetHighlightBrush() );
1431 dc
->SetBrush(wxBrush(attr
->GetBackgroundColour(), wxSOLID
));
1433 dc
->SetPen( *wxTRANSPARENT_PEN
);
1441 void wxListLineData::Draw( wxDC
*dc
)
1443 wxListItemDataList::compatibility_iterator node
= m_items
.GetFirst();
1444 wxCHECK_RET( node
, _T("no subitems at all??") );
1446 bool highlighted
= IsHighlighted();
1448 wxListItemAttr
*attr
= GetAttr();
1450 if ( SetAttributes(dc
, attr
, highlighted
) )
1453 dc
->DrawRectangle( m_gi
->m_rectHighlight
);
1459 wxRect
rect2( m_gi
->m_rectHighlight
);
1460 m_owner
->CalcScrolledPosition( rect2
.x
, rect2
.y
, &rect2
.x
, &rect2
.y
);
1462 gtk_paint_flat_box( m_owner
->m_widget
->style
,
1463 GTK_PIZZA(m_owner
->m_wxwindow
)->bin_window
,
1467 m_owner
->m_wxwindow
,
1469 rect2
.x
, rect2
.y
, rect2
.width
, rect2
.height
);
1473 dc
->DrawRectangle( m_gi
->m_rectHighlight
);
1478 // just for debugging to better see where the items are
1480 dc
->SetPen(*wxRED_PEN
);
1481 dc
->SetBrush(*wxTRANSPARENT_BRUSH
);
1482 dc
->DrawRectangle( m_gi
->m_rectAll
);
1483 dc
->SetPen(*wxGREEN_PEN
);
1484 dc
->DrawRectangle( m_gi
->m_rectIcon
);
1487 wxListItemData
*item
= node
->GetData();
1488 if (item
->HasImage())
1490 // centre the image inside our rectangle, this looks nicer when items
1491 // ae aligned in a row
1492 const wxRect
& rectIcon
= m_gi
->m_rectIcon
;
1494 m_owner
->DrawImage(item
->GetImage(), dc
, rectIcon
.x
, rectIcon
.y
);
1497 if (item
->HasText())
1499 const wxRect
& rectLabel
= m_gi
->m_rectLabel
;
1501 wxDCClipper
clipper(*dc
, rectLabel
);
1502 dc
->DrawText(item
->GetText(), rectLabel
.x
, rectLabel
.y
);
1506 void wxListLineData::DrawInReportMode( wxDC
*dc
,
1508 const wxRect
& rectHL
,
1511 // TODO: later we should support setting different attributes for
1512 // different columns - to do it, just add "col" argument to
1513 // GetAttr() and move these lines into the loop below
1514 wxListItemAttr
*attr
= GetAttr();
1515 if ( SetAttributes(dc
, attr
, highlighted
) )
1518 dc
->DrawRectangle( rectHL
);
1524 wxRect
rect2( rectHL
);
1525 m_owner
->CalcScrolledPosition( rect2
.x
, rect2
.y
, &rect2
.x
, &rect2
.y
);
1527 gtk_paint_flat_box( m_owner
->m_widget
->style
,
1528 GTK_PIZZA(m_owner
->m_wxwindow
)->bin_window
,
1532 m_owner
->m_wxwindow
,
1534 rect2
.x
, rect2
.y
, rect2
.width
, rect2
.height
);
1538 dc
->DrawRectangle( rectHL
);
1543 wxCoord x
= rect
.x
+ HEADER_OFFSET_X
,
1544 yMid
= rect
.y
+ rect
.height
/2;
1546 // This probably needs to be done
1547 // on all platforms as the icons
1548 // otherwise nearly touch the border
1553 for ( wxListItemDataList::compatibility_iterator node
= m_items
.GetFirst();
1555 node
= node
->GetNext(), col
++ )
1557 wxListItemData
*item
= node
->GetData();
1559 int width
= m_owner
->GetColumnWidth(col
);
1563 if ( item
->HasImage() )
1566 m_owner
->GetImageSize( item
->GetImage(), ix
, iy
);
1567 m_owner
->DrawImage( item
->GetImage(), dc
, xOld
, yMid
- iy
/2 );
1569 ix
+= IMAGE_MARGIN_IN_REPORT_MODE
;
1575 if ( item
->HasText() )
1576 DrawTextFormatted(dc
, item
->GetText(), col
, xOld
, yMid
, width
- 8);
1580 void wxListLineData::DrawTextFormatted(wxDC
*dc
,
1581 const wxString
&text
,
1588 dc
->GetTextExtent(text
, &w
, &h
);
1590 const wxCoord y
= yMid
- (h
+ 1)/2;
1592 wxDCClipper
clipper(*dc
, x
, y
, width
, h
);
1594 // determine if the string can fit inside the current width
1597 // it can, draw it using the items alignment
1599 m_owner
->GetColumn(col
, item
);
1600 switch ( item
.GetAlign() )
1602 case wxLIST_FORMAT_LEFT
:
1606 case wxLIST_FORMAT_RIGHT
:
1610 case wxLIST_FORMAT_CENTER
:
1611 x
+= (width
- w
) / 2;
1615 wxFAIL_MSG( _T("unknown list item format") );
1619 dc
->DrawText(text
, x
, y
);
1621 else // otherwise, truncate and add an ellipsis if possible
1623 // determine the base width
1624 wxString
ellipsis(wxT("..."));
1626 dc
->GetTextExtent(ellipsis
, &base_w
, &h
);
1628 // continue until we have enough space or only one character left
1630 size_t len
= text
.length();
1631 wxString drawntext
= text
.Left(len
);
1634 dc
->GetTextExtent(drawntext
.Last(), &w_c
, &h_c
);
1635 drawntext
.RemoveLast();
1638 if (w
+ base_w
<= width
)
1642 // if still not enough space, remove ellipsis characters
1643 while (ellipsis
.length() > 0 && w
+ base_w
> width
)
1645 ellipsis
= ellipsis
.Left(ellipsis
.length() - 1);
1646 dc
->GetTextExtent(ellipsis
, &base_w
, &h
);
1649 // now draw the text
1650 dc
->DrawText(drawntext
, x
, y
);
1651 dc
->DrawText(ellipsis
, x
+ w
, y
);
1655 bool wxListLineData::Highlight( bool on
)
1657 wxCHECK_MSG( !IsVirtual(), false, _T("unexpected call to Highlight") );
1659 if ( on
== m_highlighted
)
1667 void wxListLineData::ReverseHighlight( void )
1669 Highlight(!IsHighlighted());
1672 //-----------------------------------------------------------------------------
1673 // wxListHeaderWindow
1674 //-----------------------------------------------------------------------------
1676 IMPLEMENT_DYNAMIC_CLASS(wxListHeaderWindow
,wxWindow
)
1678 BEGIN_EVENT_TABLE(wxListHeaderWindow
,wxWindow
)
1679 EVT_PAINT (wxListHeaderWindow::OnPaint
)
1680 EVT_MOUSE_EVENTS (wxListHeaderWindow::OnMouse
)
1681 EVT_SET_FOCUS (wxListHeaderWindow::OnSetFocus
)
1684 void wxListHeaderWindow::Init()
1686 m_currentCursor
= (wxCursor
*) NULL
;
1687 m_isDragging
= false;
1691 wxListHeaderWindow::wxListHeaderWindow()
1695 m_owner
= (wxListMainWindow
*) NULL
;
1696 m_resizeCursor
= (wxCursor
*) NULL
;
1699 wxListHeaderWindow::wxListHeaderWindow( wxWindow
*win
,
1701 wxListMainWindow
*owner
,
1705 const wxString
&name
)
1706 : wxWindow( win
, id
, pos
, size
, style
, name
)
1711 m_resizeCursor
= new wxCursor( wxCURSOR_SIZEWE
);
1714 wxVisualAttributes attr
= wxPanel::GetClassDefaultAttributes();
1715 SetOwnForegroundColour( attr
.colFg
);
1716 SetOwnBackgroundColour( attr
.colBg
);
1718 SetOwnFont( attr
.font
);
1720 SetOwnForegroundColour( wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT
));
1721 SetOwnBackgroundColour( wxSystemSettings::GetColour(wxSYS_COLOUR_BTNFACE
));
1723 SetOwnFont( wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT
));
1727 wxListHeaderWindow::~wxListHeaderWindow()
1729 delete m_resizeCursor
;
1732 #ifdef __WXUNIVERSAL__
1733 #include "wx/univ/renderer.h"
1734 #include "wx/univ/theme.h"
1737 // shift the DC origin to match the position of the main window horz
1738 // scrollbar: this allows us to always use logical coords
1739 void wxListHeaderWindow::AdjustDC(wxDC
& dc
)
1742 m_owner
->GetScrollPixelsPerUnit( &xpix
, NULL
);
1745 m_owner
->GetViewStart( &view_start
, NULL
);
1750 dc
.GetDeviceOrigin( &org_x
, &org_y
);
1752 // account for the horz scrollbar offset
1754 if (GetLayoutDirection() == wxLayout_RightToLeft
)
1756 // Maybe we just have to check for m_signX
1757 // in the DC, but I leave the #ifdef __WXGTK__
1759 dc
.SetDeviceOrigin( org_x
+ (view_start
* xpix
), org_y
);
1763 dc
.SetDeviceOrigin( org_x
- (view_start
* xpix
), org_y
);
1766 void wxListHeaderWindow::OnPaint( wxPaintEvent
&WXUNUSED(event
) )
1768 wxPaintDC
dc( this );
1773 dc
.SetFont( GetFont() );
1775 // width and height of the entire header window
1777 GetClientSize( &w
, &h
);
1778 m_owner
->CalcUnscrolledPosition(w
, 0, &w
, NULL
);
1780 dc
.SetBackgroundMode(wxTRANSPARENT
);
1781 dc
.SetTextForeground(GetForegroundColour());
1783 int x
= HEADER_OFFSET_X
;
1784 int numColumns
= m_owner
->GetColumnCount();
1786 for ( int i
= 0; i
< numColumns
&& x
< w
; i
++ )
1788 m_owner
->GetColumn( i
, item
);
1789 int wCol
= item
.m_width
;
1791 // the width of the rect to draw: make it smaller to fit entirely
1792 // inside the column rect
1801 wxRendererNative::Get().DrawHeaderButton
1805 wxRect(x
, HEADER_OFFSET_Y
, cw
, ch
),
1806 m_parent
->IsEnabled() ? 0
1807 : (int)wxCONTROL_DISABLED
1810 // see if we have enough space for the column label
1812 // for this we need the width of the text
1815 dc
.GetTextExtent(item
.GetText(), &wLabel
, &hLabel
);
1816 wLabel
+= 2 * EXTRA_WIDTH
;
1818 // and the width of the icon, if any
1819 static const int MARGIN_BETWEEN_TEXT_AND_ICON
= 2;
1820 int ix
= 0, iy
= 0; // init them just to suppress the compiler warnings
1821 const int image
= item
.m_image
;
1822 wxImageList
*imageList
;
1825 imageList
= m_owner
->m_small_image_list
;
1828 imageList
->GetSize(image
, ix
, iy
);
1829 wLabel
+= ix
+ MARGIN_BETWEEN_TEXT_AND_ICON
;
1837 // ignore alignment if there is not enough space anyhow
1839 switch ( wLabel
< cw
? item
.GetAlign() : wxLIST_FORMAT_LEFT
)
1842 wxFAIL_MSG( _T("unknown list item format") );
1845 case wxLIST_FORMAT_LEFT
:
1849 case wxLIST_FORMAT_RIGHT
:
1850 xAligned
= x
+ cw
- wLabel
;
1853 case wxLIST_FORMAT_CENTER
:
1854 xAligned
= x
+ (cw
- wLabel
) / 2;
1858 // if we have an image, draw it on the right of the label
1865 xAligned
+ wLabel
- ix
- MARGIN_BETWEEN_TEXT_AND_ICON
,
1866 HEADER_OFFSET_Y
+ (h
- 4 - iy
)/2,
1867 wxIMAGELIST_DRAW_TRANSPARENT
1870 cw
-= ix
+ MARGIN_BETWEEN_TEXT_AND_ICON
;
1873 // draw the text clipping it so that it doesn't overwrite the column
1875 wxDCClipper
clipper(dc
, x
, HEADER_OFFSET_Y
, cw
, h
- 4 );
1877 dc
.DrawText( item
.GetText(),
1878 xAligned
+ EXTRA_WIDTH
, h
/ 2 - hLabel
/ 2 ); //HEADER_OFFSET_Y + EXTRA_HEIGHT );
1884 void wxListHeaderWindow::DrawCurrent()
1886 int x1
= m_currentX
;
1888 m_owner
->ClientToScreen( &x1
, &y1
);
1890 int x2
= m_currentX
;
1892 m_owner
->GetClientSize( NULL
, &y2
);
1893 m_owner
->ClientToScreen( &x2
, &y2
);
1896 dc
.SetLogicalFunction( wxINVERT
);
1897 dc
.SetPen( wxPen( *wxBLACK
, 2, wxSOLID
) );
1898 dc
.SetBrush( *wxTRANSPARENT_BRUSH
);
1902 dc
.DrawLine( x1
, y1
, x2
, y2
);
1904 dc
.SetLogicalFunction( wxCOPY
);
1906 dc
.SetPen( wxNullPen
);
1907 dc
.SetBrush( wxNullBrush
);
1910 void wxListHeaderWindow::OnMouse( wxMouseEvent
&event
)
1912 // we want to work with logical coords
1914 m_owner
->CalcUnscrolledPosition(event
.GetX(), 0, &x
, NULL
);
1915 int y
= event
.GetY();
1919 SendListEvent(wxEVT_COMMAND_LIST_COL_DRAGGING
, event
.GetPosition());
1921 // we don't draw the line beyond our window, but we allow dragging it
1924 GetClientSize( &w
, NULL
);
1925 m_owner
->CalcUnscrolledPosition(w
, 0, &w
, NULL
);
1928 // erase the line if it was drawn
1929 if ( m_currentX
< w
)
1932 if (event
.ButtonUp())
1935 m_isDragging
= false;
1937 m_owner
->SetColumnWidth( m_column
, m_currentX
- m_minX
);
1938 SendListEvent(wxEVT_COMMAND_LIST_COL_END_DRAG
, event
.GetPosition());
1945 m_currentX
= m_minX
+ 7;
1947 // draw in the new location
1948 if ( m_currentX
< w
)
1952 else // not dragging
1955 bool hit_border
= false;
1957 // end of the current column
1960 // find the column where this event occurred
1962 countCol
= m_owner
->GetColumnCount();
1963 for (col
= 0; col
< countCol
; col
++)
1965 xpos
+= m_owner
->GetColumnWidth( col
);
1968 if ( (abs(x
-xpos
) < 3) && (y
< 22) )
1970 // near the column border
1977 // inside the column
1984 if ( col
== countCol
)
1987 if (event
.LeftDown() || event
.RightUp())
1989 if (hit_border
&& event
.LeftDown())
1991 if ( SendListEvent(wxEVT_COMMAND_LIST_COL_BEGIN_DRAG
,
1992 event
.GetPosition()) )
1994 m_isDragging
= true;
1999 //else: column resizing was vetoed by the user code
2001 else // click on a column
2003 SendListEvent( event
.LeftDown()
2004 ? wxEVT_COMMAND_LIST_COL_CLICK
2005 : wxEVT_COMMAND_LIST_COL_RIGHT_CLICK
,
2006 event
.GetPosition());
2009 else if (event
.Moving())
2014 setCursor
= m_currentCursor
== wxSTANDARD_CURSOR
;
2015 m_currentCursor
= m_resizeCursor
;
2019 setCursor
= m_currentCursor
!= wxSTANDARD_CURSOR
;
2020 m_currentCursor
= wxSTANDARD_CURSOR
;
2024 SetCursor(*m_currentCursor
);
2029 void wxListHeaderWindow::OnSetFocus( wxFocusEvent
&WXUNUSED(event
) )
2031 m_owner
->SetFocus();
2035 bool wxListHeaderWindow::SendListEvent(wxEventType type
, const wxPoint
& pos
)
2037 wxWindow
*parent
= GetParent();
2038 wxListEvent
le( type
, parent
->GetId() );
2039 le
.SetEventObject( parent
);
2040 le
.m_pointDrag
= pos
;
2042 // the position should be relative to the parent window, not
2043 // this one for compatibility with MSW and common sense: the
2044 // user code doesn't know anything at all about this header
2045 // window, so why should it get positions relative to it?
2046 le
.m_pointDrag
.y
-= GetSize().y
;
2048 le
.m_col
= m_column
;
2049 return !parent
->GetEventHandler()->ProcessEvent( le
) || le
.IsAllowed();
2052 //-----------------------------------------------------------------------------
2053 // wxListRenameTimer (internal)
2054 //-----------------------------------------------------------------------------
2056 wxListRenameTimer::wxListRenameTimer( wxListMainWindow
*owner
)
2061 void wxListRenameTimer::Notify()
2063 m_owner
->OnRenameTimer();
2066 //-----------------------------------------------------------------------------
2067 // wxListTextCtrlWrapper (internal)
2068 //-----------------------------------------------------------------------------
2070 BEGIN_EVENT_TABLE(wxListTextCtrlWrapper
, wxEvtHandler
)
2071 EVT_CHAR (wxListTextCtrlWrapper::OnChar
)
2072 EVT_KEY_UP (wxListTextCtrlWrapper::OnKeyUp
)
2073 EVT_KILL_FOCUS (wxListTextCtrlWrapper::OnKillFocus
)
2076 wxListTextCtrlWrapper::wxListTextCtrlWrapper(wxListMainWindow
*owner
,
2079 : m_startValue(owner
->GetItemText(itemEdit
)),
2080 m_itemEdited(itemEdit
)
2085 m_aboutToFinish
= false;
2087 wxRect rectLabel
= owner
->GetLineLabelRect(itemEdit
);
2089 m_owner
->CalcScrolledPosition(rectLabel
.x
, rectLabel
.y
,
2090 &rectLabel
.x
, &rectLabel
.y
);
2092 m_text
->Create(owner
, wxID_ANY
, m_startValue
,
2093 wxPoint(rectLabel
.x
-4,rectLabel
.y
-4),
2094 wxSize(rectLabel
.width
+11,rectLabel
.height
+8));
2097 m_text
->PushEventHandler(this);
2100 void wxListTextCtrlWrapper::Finish()
2106 m_text
->RemoveEventHandler(this);
2107 m_owner
->FinishEditing(m_text
);
2109 wxPendingDelete
.Append( this );
2113 bool wxListTextCtrlWrapper::AcceptChanges()
2115 const wxString value
= m_text
->GetValue();
2117 if ( value
== m_startValue
)
2118 // nothing changed, always accept
2121 if ( !m_owner
->OnRenameAccept(m_itemEdited
, value
) )
2122 // vetoed by the user
2125 // accepted, do rename the item
2126 m_owner
->SetItemText(m_itemEdited
, value
);
2131 void wxListTextCtrlWrapper::AcceptChangesAndFinish()
2133 m_aboutToFinish
= true;
2135 // Notify the owner about the changes
2138 // Even if vetoed, close the control (consistent with MSW)
2142 void wxListTextCtrlWrapper::OnChar( wxKeyEvent
&event
)
2144 switch ( event
.m_keyCode
)
2147 AcceptChangesAndFinish();
2151 m_owner
->OnRenameCancelled( m_itemEdited
);
2160 void wxListTextCtrlWrapper::OnKeyUp( wxKeyEvent
&event
)
2168 // auto-grow the textctrl:
2169 wxSize parentSize
= m_owner
->GetSize();
2170 wxPoint myPos
= m_text
->GetPosition();
2171 wxSize mySize
= m_text
->GetSize();
2173 m_text
->GetTextExtent(m_text
->GetValue() + _T("MM"), &sx
, &sy
);
2174 if (myPos
.x
+ sx
> parentSize
.x
)
2175 sx
= parentSize
.x
- myPos
.x
;
2178 m_text
->SetSize(sx
, wxDefaultCoord
);
2183 void wxListTextCtrlWrapper::OnKillFocus( wxFocusEvent
&event
)
2185 if ( !m_finished
&& !m_aboutToFinish
)
2187 if ( !AcceptChanges() )
2188 m_owner
->OnRenameCancelled( m_itemEdited
);
2193 // We must let the native text control handle focus
2197 //-----------------------------------------------------------------------------
2199 //-----------------------------------------------------------------------------
2201 IMPLEMENT_DYNAMIC_CLASS(wxListMainWindow
,wxScrolledWindow
)
2203 BEGIN_EVENT_TABLE(wxListMainWindow
,wxScrolledWindow
)
2204 EVT_PAINT (wxListMainWindow::OnPaint
)
2205 EVT_MOUSE_EVENTS (wxListMainWindow::OnMouse
)
2206 EVT_CHAR (wxListMainWindow::OnChar
)
2207 EVT_KEY_DOWN (wxListMainWindow::OnKeyDown
)
2208 EVT_SET_FOCUS (wxListMainWindow::OnSetFocus
)
2209 EVT_KILL_FOCUS (wxListMainWindow::OnKillFocus
)
2210 EVT_SCROLLWIN (wxListMainWindow::OnScroll
)
2213 void wxListMainWindow::Init()
2218 m_lineTo
= (size_t)-1;
2224 m_small_image_list
= (wxImageList
*) NULL
;
2225 m_normal_image_list
= (wxImageList
*) NULL
;
2227 m_small_spacing
= 30;
2228 m_normal_spacing
= 40;
2232 m_isCreated
= false;
2234 m_lastOnSame
= false;
2235 m_renameTimer
= new wxListRenameTimer( this );
2236 m_textctrlWrapper
= NULL
;
2240 m_lineSelectSingleOnUp
=
2241 m_lineBeforeLastClicked
= (size_t)-1;
2246 wxListMainWindow::wxListMainWindow()
2251 m_highlightUnfocusedBrush
= (wxBrush
*) NULL
;
2254 wxListMainWindow::wxListMainWindow( wxWindow
*parent
,
2259 const wxString
&name
)
2260 : wxScrolledWindow( parent
, id
, pos
, size
,
2261 style
| wxHSCROLL
| wxVSCROLL
, name
)
2267 // OS X sel item highlight color differs from text highlight color, which is
2268 // what wxSYS_COLOUR_HIGHLIGHT returns.
2270 GetThemeBrushAsColor(kThemeBrushAlternatePrimaryHighlightColor
, 32, true, &hilight
);
2271 m_highlightBrush
= new wxBrush( wxColour(hilight
.red
, hilight
.green
, hilight
.blue
), wxSOLID
);
2273 m_highlightBrush
= new wxBrush
2275 wxSystemSettings::GetColour
2277 wxSYS_COLOUR_HIGHLIGHT
2284 // on Mac, this color also differs from the wxSYS_COLOUR_BTNSHADOW, enough to be noticable.
2285 // I don't know if BTNSHADOW is appropriate in other contexts, so I'm just changing it here.
2286 GetThemeBrushAsColor(kThemeBrushSecondaryHighlightColor
, 32, true, &hilight
);
2287 m_highlightUnfocusedBrush
= new wxBrush( wxColour(hilight
.red
, hilight
.green
, hilight
.blue
), wxSOLID
);
2289 m_highlightUnfocusedBrush
= new wxBrush
2291 wxSystemSettings::GetColour
2293 wxSYS_COLOUR_BTNSHADOW
2299 SetScrollbars( 0, 0, 0, 0, 0, 0 );
2301 wxVisualAttributes attr
= wxGenericListCtrl::GetClassDefaultAttributes();
2302 SetOwnForegroundColour( attr
.colFg
);
2303 SetOwnBackgroundColour( attr
.colBg
);
2305 SetOwnFont( attr
.font
);
2308 wxListMainWindow::~wxListMainWindow()
2311 WX_CLEAR_LIST(wxListHeaderDataList
, m_columns
);
2312 WX_CLEAR_ARRAY(m_aColWidths
);
2314 delete m_highlightBrush
;
2315 delete m_highlightUnfocusedBrush
;
2316 delete m_renameTimer
;
2319 void wxListMainWindow::CacheLineData(size_t line
)
2321 wxGenericListCtrl
*listctrl
= GetListCtrl();
2323 wxListLineData
*ld
= GetDummyLine();
2325 size_t countCol
= GetColumnCount();
2326 for ( size_t col
= 0; col
< countCol
; col
++ )
2328 ld
->SetText(col
, listctrl
->OnGetItemText(line
, col
));
2329 ld
->SetImage(col
, listctrl
->OnGetItemColumnImage(line
, col
));
2332 ld
->SetAttr(listctrl
->OnGetItemAttr(line
));
2335 wxListLineData
*wxListMainWindow::GetDummyLine() const
2337 wxASSERT_MSG( !IsEmpty(), _T("invalid line index") );
2338 wxASSERT_MSG( IsVirtual(), _T("GetDummyLine() shouldn't be called") );
2340 wxListMainWindow
*self
= wxConstCast(this, wxListMainWindow
);
2342 // we need to recreate the dummy line if the number of columns in the
2343 // control changed as it would have the incorrect number of fields
2345 if ( !m_lines
.IsEmpty() &&
2346 m_lines
[0].m_items
.GetCount() != (size_t)GetColumnCount() )
2348 self
->m_lines
.Clear();
2351 if ( m_lines
.IsEmpty() )
2353 wxListLineData
*line
= new wxListLineData(self
);
2354 self
->m_lines
.Add(line
);
2356 // don't waste extra memory -- there never going to be anything
2357 // else/more in this array
2358 self
->m_lines
.Shrink();
2364 // ----------------------------------------------------------------------------
2365 // line geometry (report mode only)
2366 // ----------------------------------------------------------------------------
2368 wxCoord
wxListMainWindow::GetLineHeight() const
2370 // we cache the line height as calling GetTextExtent() is slow
2371 if ( !m_lineHeight
)
2373 wxListMainWindow
*self
= wxConstCast(this, wxListMainWindow
);
2375 wxClientDC
dc( self
);
2376 dc
.SetFont( GetFont() );
2379 dc
.GetTextExtent(_T("H"), NULL
, &y
);
2381 if ( m_small_image_list
&& m_small_image_list
->GetImageCount() )
2384 m_small_image_list
->GetSize(0, iw
, ih
);
2389 self
->m_lineHeight
= y
+ LINE_SPACING
;
2392 return m_lineHeight
;
2395 wxCoord
wxListMainWindow::GetLineY(size_t line
) const
2397 wxASSERT_MSG( InReportView(), _T("only works in report mode") );
2399 return LINE_SPACING
+ line
* GetLineHeight();
2402 wxRect
wxListMainWindow::GetLineRect(size_t line
) const
2404 if ( !InReportView() )
2405 return GetLine(line
)->m_gi
->m_rectAll
;
2408 rect
.x
= HEADER_OFFSET_X
;
2409 rect
.y
= GetLineY(line
);
2410 rect
.width
= GetHeaderWidth();
2411 rect
.height
= GetLineHeight();
2416 wxRect
wxListMainWindow::GetLineLabelRect(size_t line
) const
2418 if ( !InReportView() )
2419 return GetLine(line
)->m_gi
->m_rectLabel
;
2422 rect
.x
= HEADER_OFFSET_X
;
2423 rect
.y
= GetLineY(line
);
2424 rect
.width
= GetColumnWidth(0);
2425 rect
.height
= GetLineHeight();
2430 wxRect
wxListMainWindow::GetLineIconRect(size_t line
) const
2432 if ( !InReportView() )
2433 return GetLine(line
)->m_gi
->m_rectIcon
;
2435 wxListLineData
*ld
= GetLine(line
);
2436 wxASSERT_MSG( ld
->HasImage(), _T("should have an image") );
2439 rect
.x
= HEADER_OFFSET_X
;
2440 rect
.y
= GetLineY(line
);
2441 GetImageSize(ld
->GetImage(), rect
.width
, rect
.height
);
2446 wxRect
wxListMainWindow::GetLineHighlightRect(size_t line
) const
2448 return InReportView() ? GetLineRect(line
)
2449 : GetLine(line
)->m_gi
->m_rectHighlight
;
2452 long wxListMainWindow::HitTestLine(size_t line
, int x
, int y
) const
2454 wxASSERT_MSG( line
< GetItemCount(), _T("invalid line in HitTestLine") );
2456 wxListLineData
*ld
= GetLine(line
);
2458 if ( ld
->HasImage() && GetLineIconRect(line
).Contains(x
, y
) )
2459 return wxLIST_HITTEST_ONITEMICON
;
2461 // VS: Testing for "ld->HasText() || InReportView()" instead of
2462 // "ld->HasText()" is needed to make empty lines in report view
2464 if ( ld
->HasText() || InReportView() )
2466 wxRect rect
= InReportView() ? GetLineRect(line
)
2467 : GetLineLabelRect(line
);
2469 if ( rect
.Contains(x
, y
) )
2470 return wxLIST_HITTEST_ONITEMLABEL
;
2476 // ----------------------------------------------------------------------------
2477 // highlight (selection) handling
2478 // ----------------------------------------------------------------------------
2480 bool wxListMainWindow::IsHighlighted(size_t line
) const
2484 return m_selStore
.IsSelected(line
);
2488 wxListLineData
*ld
= GetLine(line
);
2489 wxCHECK_MSG( ld
, false, _T("invalid index in IsHighlighted") );
2491 return ld
->IsHighlighted();
2495 void wxListMainWindow::HighlightLines( size_t lineFrom
,
2501 wxArrayInt linesChanged
;
2502 if ( !m_selStore
.SelectRange(lineFrom
, lineTo
, highlight
,
2505 // meny items changed state, refresh everything
2506 RefreshLines(lineFrom
, lineTo
);
2508 else // only a few items changed state, refresh only them
2510 size_t count
= linesChanged
.GetCount();
2511 for ( size_t n
= 0; n
< count
; n
++ )
2513 RefreshLine(linesChanged
[n
]);
2517 else // iterate over all items in non report view
2519 for ( size_t line
= lineFrom
; line
<= lineTo
; line
++ )
2521 if ( HighlightLine(line
, highlight
) )
2527 bool wxListMainWindow::HighlightLine( size_t line
, bool highlight
)
2533 changed
= m_selStore
.SelectItem(line
, highlight
);
2537 wxListLineData
*ld
= GetLine(line
);
2538 wxCHECK_MSG( ld
, false, _T("invalid index in HighlightLine") );
2540 changed
= ld
->Highlight(highlight
);
2545 SendNotify( line
, highlight
? wxEVT_COMMAND_LIST_ITEM_SELECTED
2546 : wxEVT_COMMAND_LIST_ITEM_DESELECTED
);
2552 void wxListMainWindow::RefreshLine( size_t line
)
2554 if ( InReportView() )
2556 size_t visibleFrom
, visibleTo
;
2557 GetVisibleLinesRange(&visibleFrom
, &visibleTo
);
2559 if ( line
< visibleFrom
|| line
> visibleTo
)
2563 wxRect rect
= GetLineRect(line
);
2565 CalcScrolledPosition( rect
.x
, rect
.y
, &rect
.x
, &rect
.y
);
2566 RefreshRect( rect
);
2569 void wxListMainWindow::RefreshLines( size_t lineFrom
, size_t lineTo
)
2571 // we suppose that they are ordered by caller
2572 wxASSERT_MSG( lineFrom
<= lineTo
, _T("indices in disorder") );
2574 wxASSERT_MSG( lineTo
< GetItemCount(), _T("invalid line range") );
2576 if ( InReportView() )
2578 size_t visibleFrom
, visibleTo
;
2579 GetVisibleLinesRange(&visibleFrom
, &visibleTo
);
2581 if ( lineFrom
< visibleFrom
)
2582 lineFrom
= visibleFrom
;
2583 if ( lineTo
> visibleTo
)
2588 rect
.y
= GetLineY(lineFrom
);
2589 rect
.width
= GetClientSize().x
;
2590 rect
.height
= GetLineY(lineTo
) - rect
.y
+ GetLineHeight();
2592 CalcScrolledPosition( rect
.x
, rect
.y
, &rect
.x
, &rect
.y
);
2593 RefreshRect( rect
);
2597 // TODO: this should be optimized...
2598 for ( size_t line
= lineFrom
; line
<= lineTo
; line
++ )
2605 void wxListMainWindow::RefreshAfter( size_t lineFrom
)
2607 if ( InReportView() )
2609 size_t visibleFrom
, visibleTo
;
2610 GetVisibleLinesRange(&visibleFrom
, &visibleTo
);
2612 if ( lineFrom
< visibleFrom
)
2613 lineFrom
= visibleFrom
;
2614 else if ( lineFrom
> visibleTo
)
2619 rect
.y
= GetLineY(lineFrom
);
2620 CalcScrolledPosition( rect
.x
, rect
.y
, &rect
.x
, &rect
.y
);
2622 wxSize size
= GetClientSize();
2623 rect
.width
= size
.x
;
2625 // refresh till the bottom of the window
2626 rect
.height
= size
.y
- rect
.y
;
2628 RefreshRect( rect
);
2632 // TODO: how to do it more efficiently?
2637 void wxListMainWindow::RefreshSelected()
2643 if ( InReportView() )
2645 GetVisibleLinesRange(&from
, &to
);
2650 to
= GetItemCount() - 1;
2653 if ( HasCurrent() && m_current
>= from
&& m_current
<= to
)
2654 RefreshLine(m_current
);
2656 for ( size_t line
= from
; line
<= to
; line
++ )
2658 // NB: the test works as expected even if m_current == -1
2659 if ( line
!= m_current
&& IsHighlighted(line
) )
2664 void wxListMainWindow::Freeze()
2669 void wxListMainWindow::Thaw()
2671 wxCHECK_RET( m_freezeCount
> 0, _T("thawing unfrozen list control?") );
2673 if ( --m_freezeCount
== 0 )
2677 void wxListMainWindow::OnPaint( wxPaintEvent
&WXUNUSED(event
) )
2679 // Note: a wxPaintDC must be constructed even if no drawing is
2680 // done (a Windows requirement).
2681 wxPaintDC
dc( this );
2683 if ( IsEmpty() || m_freezeCount
)
2684 // nothing to draw or not the moment to draw it
2688 // delay the repainting until we calculate all the items positions
2694 CalcScrolledPosition( 0, 0, &dev_x
, &dev_y
);
2696 dc
.SetFont( GetFont() );
2698 if ( InReportView() )
2700 int lineHeight
= GetLineHeight();
2702 size_t visibleFrom
, visibleTo
;
2703 GetVisibleLinesRange(&visibleFrom
, &visibleTo
);
2706 int xOrig
= dc
.LogicalToDeviceX( 0 );
2707 int yOrig
= dc
.LogicalToDeviceY( 0 );
2709 // tell the caller cache to cache the data
2712 wxListEvent
evCache(wxEVT_COMMAND_LIST_CACHE_HINT
,
2713 GetParent()->GetId());
2714 evCache
.SetEventObject( GetParent() );
2715 evCache
.m_oldItemIndex
= visibleFrom
;
2716 evCache
.m_itemIndex
= visibleTo
;
2717 GetParent()->GetEventHandler()->ProcessEvent( evCache
);
2720 for ( size_t line
= visibleFrom
; line
<= visibleTo
; line
++ )
2722 rectLine
= GetLineRect(line
);
2725 if ( !IsExposed(rectLine
.x
+ xOrig
, rectLine
.y
+ yOrig
,
2726 rectLine
.width
, rectLine
.height
) )
2728 // don't redraw unaffected lines to avoid flicker
2732 GetLine(line
)->DrawInReportMode( &dc
,
2734 GetLineHighlightRect(line
),
2735 IsHighlighted(line
) );
2738 if ( HasFlag(wxLC_HRULES
) )
2740 wxPen
pen(GetRuleColour(), 1, wxSOLID
);
2741 wxSize clientSize
= GetClientSize();
2743 // Don't draw the first one
2744 for ( size_t i
= visibleFrom
+ 1; i
<= visibleTo
; i
++ )
2747 dc
.SetBrush( *wxTRANSPARENT_BRUSH
);
2748 dc
.DrawLine(0 - dev_x
, i
* lineHeight
,
2749 clientSize
.x
- dev_x
, i
* lineHeight
);
2752 // Draw last horizontal rule
2753 if ( visibleTo
== GetItemCount() - 1 )
2756 dc
.SetBrush( *wxTRANSPARENT_BRUSH
);
2757 dc
.DrawLine(0 - dev_x
, (m_lineTo
+ 1) * lineHeight
,
2758 clientSize
.x
- dev_x
, (m_lineTo
+ 1) * lineHeight
);
2762 // Draw vertical rules if required
2763 if ( HasFlag(wxLC_VRULES
) && !IsEmpty() )
2765 wxPen
pen(GetRuleColour(), 1, wxSOLID
);
2766 wxRect firstItemRect
, lastItemRect
;
2768 GetItemRect(visibleFrom
, firstItemRect
);
2769 GetItemRect(visibleTo
, lastItemRect
);
2770 int x
= firstItemRect
.GetX();
2772 dc
.SetBrush(* wxTRANSPARENT_BRUSH
);
2774 for (int col
= 0; col
< GetColumnCount(); col
++)
2776 int colWidth
= GetColumnWidth(col
);
2778 dc
.DrawLine(x
- dev_x
- 2, firstItemRect
.GetY() - 1 - dev_y
,
2779 x
- dev_x
- 2, lastItemRect
.GetBottom() + 1 - dev_y
);
2785 size_t count
= GetItemCount();
2786 for ( size_t i
= 0; i
< count
; i
++ )
2788 GetLine(i
)->Draw( &dc
);
2793 // Don't draw rect outline under Mac at all.
2798 wxRect
rect( GetLineHighlightRect( m_current
) );
2800 dc
.SetPen( *wxBLACK_PEN
);
2801 dc
.SetBrush( *wxTRANSPARENT_BRUSH
);
2802 dc
.DrawRectangle( rect
);
2804 CalcScrolledPosition( rect
.x
, rect
.y
, &rect
.x
, &rect
.y
);
2806 gtk_paint_focus( m_widget
->style
,
2807 GTK_PIZZA(m_wxwindow
)->bin_window
,
2812 rect
.x
, rect
.y
, rect
.width
, rect
.height
);
2820 void wxListMainWindow::HighlightAll( bool on
)
2822 if ( IsSingleSel() )
2824 wxASSERT_MSG( !on
, _T("can't do this in a single selection control") );
2826 // we just have one item to turn off
2827 if ( HasCurrent() && IsHighlighted(m_current
) )
2829 HighlightLine(m_current
, false);
2830 RefreshLine(m_current
);
2835 HighlightLines(0, GetItemCount() - 1, on
);
2839 void wxListMainWindow::SendNotify( size_t line
,
2840 wxEventType command
,
2841 const wxPoint
& point
)
2843 wxListEvent
le( command
, GetParent()->GetId() );
2844 le
.SetEventObject( GetParent() );
2846 le
.m_itemIndex
= line
;
2848 // set only for events which have position
2849 if ( point
!= wxDefaultPosition
)
2850 le
.m_pointDrag
= point
;
2852 // don't try to get the line info for virtual list controls: the main
2853 // program has it anyhow and if we did it would result in accessing all
2854 // the lines, even those which are not visible now and this is precisely
2855 // what we're trying to avoid
2858 if ( line
!= (size_t)-1 )
2860 GetLine(line
)->GetItem( 0, le
.m_item
);
2862 //else: this happens for wxEVT_COMMAND_LIST_ITEM_FOCUSED event
2864 //else: there may be no more such item
2866 GetParent()->GetEventHandler()->ProcessEvent( le
);
2869 void wxListMainWindow::ChangeCurrent(size_t current
)
2871 m_current
= current
;
2873 SendNotify(current
, wxEVT_COMMAND_LIST_ITEM_FOCUSED
);
2876 wxTextCtrl
*wxListMainWindow::EditLabel(long item
, wxClassInfo
* textControlClass
)
2878 wxCHECK_MSG( (item
>= 0) && ((size_t)item
< GetItemCount()), NULL
,
2879 wxT("wrong index in wxGenericListCtrl::EditLabel()") );
2881 wxASSERT_MSG( textControlClass
->IsKindOf(CLASSINFO(wxTextCtrl
)),
2882 wxT("EditLabel() needs a text control") );
2884 size_t itemEdit
= (size_t)item
;
2886 wxListEvent
le( wxEVT_COMMAND_LIST_BEGIN_LABEL_EDIT
, GetParent()->GetId() );
2887 le
.SetEventObject( GetParent() );
2888 le
.m_itemIndex
= item
;
2889 wxListLineData
*data
= GetLine(itemEdit
);
2890 wxCHECK_MSG( data
, NULL
, _T("invalid index in EditLabel()") );
2891 data
->GetItem( 0, le
.m_item
);
2893 if ( GetParent()->GetEventHandler()->ProcessEvent( le
) && !le
.IsAllowed() )
2895 // vetoed by user code
2899 // We have to call this here because the label in question might just have
2900 // been added and no screen update taken place.
2904 wxTextCtrl
* const text
= (wxTextCtrl
*)textControlClass
->CreateObject();
2905 m_textctrlWrapper
= new wxListTextCtrlWrapper(this, text
, item
);
2906 return m_textctrlWrapper
->GetText();
2909 void wxListMainWindow::OnRenameTimer()
2911 wxCHECK_RET( HasCurrent(), wxT("unexpected rename timer") );
2913 EditLabel( m_current
);
2916 bool wxListMainWindow::OnRenameAccept(size_t itemEdit
, const wxString
& value
)
2918 wxListEvent
le( wxEVT_COMMAND_LIST_END_LABEL_EDIT
, GetParent()->GetId() );
2919 le
.SetEventObject( GetParent() );
2920 le
.m_itemIndex
= itemEdit
;
2922 wxListLineData
*data
= GetLine(itemEdit
);
2924 wxCHECK_MSG( data
, false, _T("invalid index in OnRenameAccept()") );
2926 data
->GetItem( 0, le
.m_item
);
2927 le
.m_item
.m_text
= value
;
2928 return !GetParent()->GetEventHandler()->ProcessEvent( le
) ||
2932 void wxListMainWindow::OnRenameCancelled(size_t itemEdit
)
2934 // let owner know that the edit was cancelled
2935 wxListEvent
le( wxEVT_COMMAND_LIST_END_LABEL_EDIT
, GetParent()->GetId() );
2937 le
.SetEditCanceled(true);
2939 le
.SetEventObject( GetParent() );
2940 le
.m_itemIndex
= itemEdit
;
2942 wxListLineData
*data
= GetLine(itemEdit
);
2943 wxCHECK_RET( data
, _T("invalid index in OnRenameCancelled()") );
2945 data
->GetItem( 0, le
.m_item
);
2946 GetEventHandler()->ProcessEvent( le
);
2949 void wxListMainWindow::OnMouse( wxMouseEvent
&event
)
2953 // On wxMac we can't depend on the EVT_KILL_FOCUS event to properly
2954 // shutdown the edit control when the mouse is clicked elsewhere on the
2955 // listctrl because the order of events is different (or something like
2956 // that), so explicitly end the edit if it is active.
2957 if ( event
.LeftDown() && m_textctrlWrapper
)
2958 m_textctrlWrapper
->AcceptChangesAndFinish();
2961 event
.SetEventObject( GetParent() );
2962 if ( GetParent()->GetEventHandler()->ProcessEvent( event
) )
2965 if (event
.GetEventType() == wxEVT_MOUSEWHEEL
)
2967 // let the base handle mouse wheel events.
2972 if ( !HasCurrent() || IsEmpty() )
2974 if (event
.RightDown())
2976 SendNotify( (size_t)-1, wxEVT_COMMAND_LIST_ITEM_RIGHT_CLICK
, event
.GetPosition() );
2977 // Allow generation of context menu event
2986 if ( !(event
.Dragging() || event
.ButtonDown() || event
.LeftUp() ||
2987 event
.ButtonDClick()) )
2990 int x
= event
.GetX();
2991 int y
= event
.GetY();
2992 CalcUnscrolledPosition( x
, y
, &x
, &y
);
2994 // where did we hit it (if we did)?
2997 size_t count
= GetItemCount(),
3000 if ( InReportView() )
3002 current
= y
/ GetLineHeight();
3003 if ( current
< count
)
3004 hitResult
= HitTestLine(current
, x
, y
);
3008 // TODO: optimize it too! this is less simple than for report view but
3009 // enumerating all items is still not a way to do it!!
3010 for ( current
= 0; current
< count
; current
++ )
3012 hitResult
= HitTestLine(current
, x
, y
);
3018 if (event
.Dragging())
3020 if (m_dragCount
== 0)
3022 // we have to report the raw, physical coords as we want to be
3023 // able to call HitTest(event.m_pointDrag) from the user code to
3024 // get the item being dragged
3025 m_dragStart
= event
.GetPosition();
3030 if (m_dragCount
!= 3)
3033 int command
= event
.RightIsDown() ? wxEVT_COMMAND_LIST_BEGIN_RDRAG
3034 : wxEVT_COMMAND_LIST_BEGIN_DRAG
;
3036 wxListEvent
le( command
, GetParent()->GetId() );
3037 le
.SetEventObject( GetParent() );
3038 le
.m_itemIndex
= m_lineLastClicked
;
3039 le
.m_pointDrag
= m_dragStart
;
3040 GetParent()->GetEventHandler()->ProcessEvent( le
);
3051 // outside of any item
3052 if (event
.RightDown())
3054 SendNotify( (size_t) -1, wxEVT_COMMAND_LIST_ITEM_RIGHT_CLICK
, event
.GetPosition() );
3055 // Allow generation of context menu event
3060 // reset the selection and bail out
3061 HighlightAll(false);
3067 bool forceClick
= false;
3068 if (event
.ButtonDClick())
3070 m_renameTimer
->Stop();
3071 m_lastOnSame
= false;
3073 if ( current
== m_lineLastClicked
)
3075 SendNotify( current
, wxEVT_COMMAND_LIST_ITEM_ACTIVATED
);
3081 // The first click was on another item, so don't interpret this as
3082 // a double click, but as a simple click instead
3089 if (m_lineSelectSingleOnUp
!= (size_t)-1)
3091 // select single line
3092 HighlightAll( false );
3093 ReverseHighlight(m_lineSelectSingleOnUp
);
3098 if ((current
== m_current
) &&
3099 (hitResult
== wxLIST_HITTEST_ONITEMLABEL
) &&
3100 HasFlag(wxLC_EDIT_LABELS
) )
3102 m_renameTimer
->Start( 100, true );
3106 m_lastOnSame
= false;
3107 m_lineSelectSingleOnUp
= (size_t)-1;
3111 // This is necessary, because after a DnD operation in
3112 // from and to ourself, the up event is swallowed by the
3113 // DnD code. So on next non-up event (which means here and
3114 // now) m_lineSelectSingleOnUp should be reset.
3115 m_lineSelectSingleOnUp
= (size_t)-1;
3117 if (event
.RightDown())
3119 m_lineBeforeLastClicked
= m_lineLastClicked
;
3120 m_lineLastClicked
= current
;
3122 // If the item is already selected, do not update the selection.
3123 // Multi-selections should not be cleared if a selected item is clicked.
3124 if (!IsHighlighted(current
))
3126 HighlightAll(false);
3127 ChangeCurrent(current
);
3128 ReverseHighlight(m_current
);
3131 SendNotify( current
, wxEVT_COMMAND_LIST_ITEM_RIGHT_CLICK
, event
.GetPosition() );
3133 // Allow generation of context menu event
3136 else if (event
.MiddleDown())
3138 SendNotify( current
, wxEVT_COMMAND_LIST_ITEM_MIDDLE_CLICK
);
3140 else if ( event
.LeftDown() || forceClick
)
3142 m_lineBeforeLastClicked
= m_lineLastClicked
;
3143 m_lineLastClicked
= current
;
3145 size_t oldCurrent
= m_current
;
3146 bool oldWasSelected
= IsHighlighted(m_current
);
3148 bool cmdModifierDown
= event
.CmdDown();
3149 if ( IsSingleSel() || !(cmdModifierDown
|| event
.ShiftDown()) )
3151 if ( IsSingleSel() || !IsHighlighted(current
) )
3153 HighlightAll( false );
3155 ChangeCurrent(current
);
3157 ReverseHighlight(m_current
);
3159 else // multi sel & current is highlighted & no mod keys
3161 m_lineSelectSingleOnUp
= current
;
3162 ChangeCurrent(current
); // change focus
3165 else // multi sel & either ctrl or shift is down
3167 if (cmdModifierDown
)
3169 ChangeCurrent(current
);
3171 ReverseHighlight(m_current
);
3173 else if (event
.ShiftDown())
3175 ChangeCurrent(current
);
3177 size_t lineFrom
= oldCurrent
,
3180 if ( lineTo
< lineFrom
)
3183 lineFrom
= m_current
;
3186 HighlightLines(lineFrom
, lineTo
);
3188 else // !ctrl, !shift
3190 // test in the enclosing if should make it impossible
3191 wxFAIL_MSG( _T("how did we get here?") );
3195 if (m_current
!= oldCurrent
)
3196 RefreshLine( oldCurrent
);
3198 // forceClick is only set if the previous click was on another item
3199 m_lastOnSame
= !forceClick
&& (m_current
== oldCurrent
) && oldWasSelected
;
3203 void wxListMainWindow::MoveToItem(size_t item
)
3205 if ( item
== (size_t)-1 )
3208 wxRect rect
= GetLineRect(item
);
3210 int client_w
, client_h
;
3211 GetClientSize( &client_w
, &client_h
);
3213 const int hLine
= GetLineHeight();
3215 int view_x
= SCROLL_UNIT_X
* GetScrollPos( wxHORIZONTAL
);
3216 int view_y
= hLine
* GetScrollPos( wxVERTICAL
);
3218 if ( InReportView() )
3220 // the next we need the range of lines shown it might be different,
3221 // so recalculate it
3222 ResetVisibleLinesRange();
3224 if (rect
.y
< view_y
)
3225 Scroll( -1, rect
.y
/ hLine
);
3226 if (rect
.y
+ rect
.height
+ 5 > view_y
+ client_h
)
3227 Scroll( -1, (rect
.y
+ rect
.height
- client_h
+ hLine
) / hLine
);
3231 if (rect
.x
-view_x
< 5)
3232 Scroll( (rect
.x
- 5) / SCROLL_UNIT_X
, -1 );
3233 if (rect
.x
+ rect
.width
- 5 > view_x
+ client_w
)
3234 Scroll( (rect
.x
+ rect
.width
- client_w
+ SCROLL_UNIT_X
) / SCROLL_UNIT_X
, -1 );
3238 // ----------------------------------------------------------------------------
3239 // keyboard handling
3240 // ----------------------------------------------------------------------------
3242 void wxListMainWindow::OnArrowChar(size_t newCurrent
, const wxKeyEvent
& event
)
3244 wxCHECK_RET( newCurrent
< (size_t)GetItemCount(),
3245 _T("invalid item index in OnArrowChar()") );
3247 size_t oldCurrent
= m_current
;
3249 // in single selection we just ignore Shift as we can't select several
3251 if ( event
.ShiftDown() && !IsSingleSel() )
3253 ChangeCurrent(newCurrent
);
3255 // refresh the old focus to remove it
3256 RefreshLine( oldCurrent
);
3258 // select all the items between the old and the new one
3259 if ( oldCurrent
> newCurrent
)
3261 newCurrent
= oldCurrent
;
3262 oldCurrent
= m_current
;
3265 HighlightLines(oldCurrent
, newCurrent
);
3269 // all previously selected items are unselected unless ctrl is held
3270 if ( !event
.ControlDown() )
3271 HighlightAll(false);
3273 ChangeCurrent(newCurrent
);
3275 // refresh the old focus to remove it
3276 RefreshLine( oldCurrent
);
3278 if ( !event
.ControlDown() )
3280 HighlightLine( m_current
, true );
3284 RefreshLine( m_current
);
3289 void wxListMainWindow::OnKeyDown( wxKeyEvent
&event
)
3291 wxWindow
*parent
= GetParent();
3293 // propagate the key event upwards
3294 wxKeyEvent
ke( wxEVT_KEY_DOWN
);
3295 ke
.m_shiftDown
= event
.m_shiftDown
;
3296 ke
.m_controlDown
= event
.m_controlDown
;
3297 ke
.m_altDown
= event
.m_altDown
;
3298 ke
.m_metaDown
= event
.m_metaDown
;
3299 ke
.m_keyCode
= event
.m_keyCode
;
3302 ke
.SetEventObject( parent
);
3303 if (parent
->GetEventHandler()->ProcessEvent( ke
)) return;
3308 void wxListMainWindow::OnChar( wxKeyEvent
&event
)
3310 wxWindow
*parent
= GetParent();
3312 // send a list_key event up
3315 wxListEvent
le( wxEVT_COMMAND_LIST_KEY_DOWN
, GetParent()->GetId() );
3316 le
.m_itemIndex
= m_current
;
3317 GetLine(m_current
)->GetItem( 0, le
.m_item
);
3318 le
.m_code
= event
.GetKeyCode();
3319 le
.SetEventObject( parent
);
3320 parent
->GetEventHandler()->ProcessEvent( le
);
3323 // propagate the char event upwards
3324 wxKeyEvent
ke( wxEVT_CHAR
);
3325 ke
.m_shiftDown
= event
.m_shiftDown
;
3326 ke
.m_controlDown
= event
.m_controlDown
;
3327 ke
.m_altDown
= event
.m_altDown
;
3328 ke
.m_metaDown
= event
.m_metaDown
;
3329 ke
.m_keyCode
= event
.m_keyCode
;
3332 ke
.SetEventObject( parent
);
3333 if (parent
->GetEventHandler()->ProcessEvent( ke
)) return;
3335 if (event
.GetKeyCode() == WXK_TAB
)
3337 wxNavigationKeyEvent nevent
;
3338 nevent
.SetWindowChange( event
.ControlDown() );
3339 nevent
.SetDirection( !event
.ShiftDown() );
3340 nevent
.SetEventObject( GetParent()->GetParent() );
3341 nevent
.SetCurrentFocus( m_parent
);
3342 if (GetParent()->GetParent()->GetEventHandler()->ProcessEvent( nevent
))
3346 // no item -> nothing to do
3353 // don't use m_linesPerPage directly as it might not be computed yet
3354 const int pageSize
= GetCountPerPage();
3355 wxCHECK_RET( pageSize
, _T("should have non zero page size") );
3357 if (GetLayoutDirection() == wxLayout_RightToLeft
)
3359 if (event
.GetKeyCode() == WXK_RIGHT
)
3360 event
.m_keyCode
= WXK_LEFT
;
3361 else if (event
.GetKeyCode() == WXK_LEFT
)
3362 event
.m_keyCode
= WXK_RIGHT
;
3365 switch ( event
.GetKeyCode() )
3368 if ( m_current
> 0 )
3369 OnArrowChar( m_current
- 1, event
);
3373 if ( m_current
< (size_t)GetItemCount() - 1 )
3374 OnArrowChar( m_current
+ 1, event
);
3379 OnArrowChar( GetItemCount() - 1, event
);
3384 OnArrowChar( 0, event
);
3389 int steps
= InReportView() ? pageSize
- 1
3390 : m_current
% pageSize
;
3392 int index
= m_current
- steps
;
3396 OnArrowChar( index
, event
);
3402 int steps
= InReportView()
3404 : pageSize
- (m_current
% pageSize
) - 1;
3406 size_t index
= m_current
+ steps
;
3407 size_t count
= GetItemCount();
3408 if ( index
>= count
)
3411 OnArrowChar( index
, event
);
3416 if ( !InReportView() )
3418 int index
= m_current
- pageSize
;
3422 OnArrowChar( index
, event
);
3427 if ( !InReportView() )
3429 size_t index
= m_current
+ pageSize
;
3431 size_t count
= GetItemCount();
3432 if ( index
>= count
)
3435 OnArrowChar( index
, event
);
3440 if ( IsSingleSel() )
3442 SendNotify( m_current
, wxEVT_COMMAND_LIST_ITEM_ACTIVATED
);
3444 if ( IsHighlighted(m_current
) )
3446 // don't unselect the item in single selection mode
3449 //else: select it in ReverseHighlight() below if unselected
3452 ReverseHighlight(m_current
);
3457 SendNotify( m_current
, wxEVT_COMMAND_LIST_ITEM_ACTIVATED
);
3465 // ----------------------------------------------------------------------------
3467 // ----------------------------------------------------------------------------
3469 void wxListMainWindow::OnSetFocus( wxFocusEvent
&WXUNUSED(event
) )
3473 wxFocusEvent
event( wxEVT_SET_FOCUS
, GetParent()->GetId() );
3474 event
.SetEventObject( GetParent() );
3475 if ( GetParent()->GetEventHandler()->ProcessEvent( event
) )
3479 // wxGTK sends us EVT_SET_FOCUS events even if we had never got
3480 // EVT_KILL_FOCUS before which means that we finish by redrawing the items
3481 // which are already drawn correctly resulting in horrible flicker - avoid
3491 void wxListMainWindow::OnKillFocus( wxFocusEvent
&WXUNUSED(event
) )
3495 wxFocusEvent
event( wxEVT_KILL_FOCUS
, GetParent()->GetId() );
3496 event
.SetEventObject( GetParent() );
3497 if ( GetParent()->GetEventHandler()->ProcessEvent( event
) )
3505 void wxListMainWindow::DrawImage( int index
, wxDC
*dc
, int x
, int y
)
3507 if ( HasFlag(wxLC_ICON
) && (m_normal_image_list
))
3509 m_normal_image_list
->Draw( index
, *dc
, x
, y
, wxIMAGELIST_DRAW_TRANSPARENT
);
3511 else if ( HasFlag(wxLC_SMALL_ICON
) && (m_small_image_list
))
3513 m_small_image_list
->Draw( index
, *dc
, x
, y
, wxIMAGELIST_DRAW_TRANSPARENT
);
3515 else if ( HasFlag(wxLC_LIST
) && (m_small_image_list
))
3517 m_small_image_list
->Draw( index
, *dc
, x
, y
, wxIMAGELIST_DRAW_TRANSPARENT
);
3519 else if ( InReportView() && (m_small_image_list
))
3521 m_small_image_list
->Draw( index
, *dc
, x
, y
, wxIMAGELIST_DRAW_TRANSPARENT
);
3525 void wxListMainWindow::GetImageSize( int index
, int &width
, int &height
) const
3527 if ( HasFlag(wxLC_ICON
) && m_normal_image_list
)
3529 m_normal_image_list
->GetSize( index
, width
, height
);
3531 else if ( HasFlag(wxLC_SMALL_ICON
) && m_small_image_list
)
3533 m_small_image_list
->GetSize( index
, width
, height
);
3535 else if ( HasFlag(wxLC_LIST
) && m_small_image_list
)
3537 m_small_image_list
->GetSize( index
, width
, height
);
3539 else if ( InReportView() && m_small_image_list
)
3541 m_small_image_list
->GetSize( index
, width
, height
);
3550 int wxListMainWindow::GetTextLength( const wxString
&s
) const
3552 wxClientDC
dc( wxConstCast(this, wxListMainWindow
) );
3553 dc
.SetFont( GetFont() );
3556 dc
.GetTextExtent( s
, &lw
, NULL
);
3558 return lw
+ AUTOSIZE_COL_MARGIN
;
3561 void wxListMainWindow::SetImageList( wxImageList
*imageList
, int which
)
3565 // calc the spacing from the icon size
3566 int width
= 0, height
= 0;
3568 if ((imageList
) && (imageList
->GetImageCount()) )
3569 imageList
->GetSize(0, width
, height
);
3571 if (which
== wxIMAGE_LIST_NORMAL
)
3573 m_normal_image_list
= imageList
;
3574 m_normal_spacing
= width
+ 8;
3577 if (which
== wxIMAGE_LIST_SMALL
)
3579 m_small_image_list
= imageList
;
3580 m_small_spacing
= width
+ 14;
3581 m_lineHeight
= 0; // ensure that the line height will be recalc'd
3585 void wxListMainWindow::SetItemSpacing( int spacing
, bool isSmall
)
3589 m_small_spacing
= spacing
;
3591 m_normal_spacing
= spacing
;
3594 int wxListMainWindow::GetItemSpacing( bool isSmall
)
3596 return isSmall
? m_small_spacing
: m_normal_spacing
;
3599 // ----------------------------------------------------------------------------
3601 // ----------------------------------------------------------------------------
3603 void wxListMainWindow::SetColumn( int col
, wxListItem
&item
)
3605 wxListHeaderDataList::compatibility_iterator node
= m_columns
.Item( col
);
3607 wxCHECK_RET( node
, _T("invalid column index in SetColumn") );
3609 if ( item
.m_width
== wxLIST_AUTOSIZE_USEHEADER
)
3610 item
.m_width
= GetTextLength( item
.m_text
);
3612 wxListHeaderData
*column
= node
->GetData();
3613 column
->SetItem( item
);
3615 wxListHeaderWindow
*headerWin
= GetListCtrl()->m_headerWin
;
3617 headerWin
->m_dirty
= true;
3621 // invalidate it as it has to be recalculated
3625 void wxListMainWindow::SetColumnWidth( int col
, int width
)
3627 wxCHECK_RET( col
>= 0 && col
< GetColumnCount(),
3628 _T("invalid column index") );
3630 wxCHECK_RET( InReportView(),
3631 _T("SetColumnWidth() can only be called in report mode.") );
3634 wxListHeaderWindow
*headerWin
= GetListCtrl()->m_headerWin
;
3636 headerWin
->m_dirty
= true;
3638 wxListHeaderDataList::compatibility_iterator node
= m_columns
.Item( col
);
3639 wxCHECK_RET( node
, _T("no column?") );
3641 wxListHeaderData
*column
= node
->GetData();
3643 size_t count
= GetItemCount();
3645 if (width
== wxLIST_AUTOSIZE_USEHEADER
)
3647 width
= GetTextLength(column
->GetText());
3649 else if ( width
== wxLIST_AUTOSIZE
)
3653 // TODO: determine the max width somehow...
3654 width
= WIDTH_COL_DEFAULT
;
3658 wxClientDC
dc(this);
3659 dc
.SetFont( GetFont() );
3661 int max
= AUTOSIZE_COL_MARGIN
;
3663 // if the cached column width isn't valid then recalculate it
3664 if (m_aColWidths
.Item(col
)->bNeedsUpdate
)
3666 for (size_t i
= 0; i
< count
; i
++)
3668 wxListLineData
*line
= GetLine( i
);
3669 wxListItemDataList::compatibility_iterator n
= line
->m_items
.Item( col
);
3671 wxCHECK_RET( n
, _T("no subitem?") );
3673 wxListItemData
*itemData
= n
->GetData();
3676 itemData
->GetItem(item
);
3677 int itemWidth
= GetItemWidthWithImage(&item
);
3678 if (itemWidth
> max
)
3682 m_aColWidths
.Item(col
)->bNeedsUpdate
= false;
3683 m_aColWidths
.Item(col
)->nMaxWidth
= max
;
3686 max
= m_aColWidths
.Item(col
)->nMaxWidth
;
3687 width
= max
+ AUTOSIZE_COL_MARGIN
;
3691 column
->SetWidth( width
);
3693 // invalidate it as it has to be recalculated
3697 int wxListMainWindow::GetHeaderWidth() const
3699 if ( !m_headerWidth
)
3701 wxListMainWindow
*self
= wxConstCast(this, wxListMainWindow
);
3703 size_t count
= GetColumnCount();
3704 for ( size_t col
= 0; col
< count
; col
++ )
3706 self
->m_headerWidth
+= GetColumnWidth(col
);
3710 return m_headerWidth
;
3713 void wxListMainWindow::GetColumn( int col
, wxListItem
&item
) const
3715 wxListHeaderDataList::compatibility_iterator node
= m_columns
.Item( col
);
3716 wxCHECK_RET( node
, _T("invalid column index in GetColumn") );
3718 wxListHeaderData
*column
= node
->GetData();
3719 column
->GetItem( item
);
3722 int wxListMainWindow::GetColumnWidth( int col
) const
3724 wxListHeaderDataList::compatibility_iterator node
= m_columns
.Item( col
);
3725 wxCHECK_MSG( node
, 0, _T("invalid column index") );
3727 wxListHeaderData
*column
= node
->GetData();
3728 return column
->GetWidth();
3731 // ----------------------------------------------------------------------------
3733 // ----------------------------------------------------------------------------
3735 void wxListMainWindow::SetItem( wxListItem
&item
)
3737 long id
= item
.m_itemId
;
3738 wxCHECK_RET( id
>= 0 && (size_t)id
< GetItemCount(),
3739 _T("invalid item index in SetItem") );
3743 wxListLineData
*line
= GetLine((size_t)id
);
3744 line
->SetItem( item
.m_col
, item
);
3746 // Set item state if user wants
3747 if ( item
.m_mask
& wxLIST_MASK_STATE
)
3748 SetItemState( item
.m_itemId
, item
.m_state
, item
.m_state
);
3752 // update the Max Width Cache if needed
3753 int width
= GetItemWidthWithImage(&item
);
3755 if (width
> m_aColWidths
.Item(item
.m_col
)->nMaxWidth
)
3756 m_aColWidths
.Item(item
.m_col
)->nMaxWidth
= width
;
3760 // update the item on screen
3762 GetItemRect(id
, rectItem
);
3763 RefreshRect(rectItem
);
3766 void wxListMainWindow::SetItemStateAll(long state
, long stateMask
)
3771 // first deal with selection
3772 if ( stateMask
& wxLIST_STATE_SELECTED
)
3774 // set/clear select state
3777 // optimized version for virtual listctrl.
3778 m_selStore
.SelectRange(0, GetItemCount() - 1, state
== wxLIST_STATE_SELECTED
);
3781 else if ( state
& wxLIST_STATE_SELECTED
)
3783 const long count
= GetItemCount();
3784 for( long i
= 0; i
< count
; i
++ )
3786 SetItemState( i
, wxLIST_STATE_SELECTED
, wxLIST_STATE_SELECTED
);
3792 // clear for non virtual (somewhat optimized by using GetNextItem())
3794 while ( (i
= GetNextItem(i
, wxLIST_NEXT_ALL
, wxLIST_STATE_SELECTED
)) != -1 )
3796 SetItemState( i
, 0, wxLIST_STATE_SELECTED
);
3801 if ( HasCurrent() && (state
== 0) && (stateMask
& wxLIST_STATE_FOCUSED
) )
3803 // unfocus all: only one item can be focussed, so clearing focus for
3804 // all items is simply clearing focus of the focussed item.
3805 SetItemState(m_current
, state
, stateMask
);
3807 //(setting focus to all items makes no sense, so it is not handled here.)
3810 void wxListMainWindow::SetItemState( long litem
, long state
, long stateMask
)
3814 SetItemStateAll(state
, stateMask
);
3818 wxCHECK_RET( litem
>= 0 && (size_t)litem
< GetItemCount(),
3819 _T("invalid list ctrl item index in SetItem") );
3821 size_t oldCurrent
= m_current
;
3822 size_t item
= (size_t)litem
; // safe because of the check above
3824 // do we need to change the focus?
3825 if ( stateMask
& wxLIST_STATE_FOCUSED
)
3827 if ( state
& wxLIST_STATE_FOCUSED
)
3829 // don't do anything if this item is already focused
3830 if ( item
!= m_current
)
3832 ChangeCurrent(item
);
3834 if ( oldCurrent
!= (size_t)-1 )
3836 if ( IsSingleSel() )
3838 HighlightLine(oldCurrent
, false);
3841 RefreshLine(oldCurrent
);
3844 RefreshLine( m_current
);
3849 // don't do anything if this item is not focused
3850 if ( item
== m_current
)
3854 if ( IsSingleSel() )
3856 // we must unselect the old current item as well or we
3857 // might end up with more than one selected item in a
3858 // single selection control
3859 HighlightLine(oldCurrent
, false);
3862 RefreshLine( oldCurrent
);
3867 // do we need to change the selection state?
3868 if ( stateMask
& wxLIST_STATE_SELECTED
)
3870 bool on
= (state
& wxLIST_STATE_SELECTED
) != 0;
3872 if ( IsSingleSel() )
3876 // selecting the item also makes it the focused one in the
3878 if ( m_current
!= item
)
3880 ChangeCurrent(item
);
3882 if ( oldCurrent
!= (size_t)-1 )
3884 HighlightLine( oldCurrent
, false );
3885 RefreshLine( oldCurrent
);
3891 // only the current item may be selected anyhow
3892 if ( item
!= m_current
)
3897 if ( HighlightLine(item
, on
) )
3904 int wxListMainWindow::GetItemState( long item
, long stateMask
) const
3906 wxCHECK_MSG( item
>= 0 && (size_t)item
< GetItemCount(), 0,
3907 _T("invalid list ctrl item index in GetItemState()") );
3909 int ret
= wxLIST_STATE_DONTCARE
;
3911 if ( stateMask
& wxLIST_STATE_FOCUSED
)
3913 if ( (size_t)item
== m_current
)
3914 ret
|= wxLIST_STATE_FOCUSED
;
3917 if ( stateMask
& wxLIST_STATE_SELECTED
)
3919 if ( IsHighlighted(item
) )
3920 ret
|= wxLIST_STATE_SELECTED
;
3926 void wxListMainWindow::GetItem( wxListItem
&item
) const
3928 wxCHECK_RET( item
.m_itemId
>= 0 && (size_t)item
.m_itemId
< GetItemCount(),
3929 _T("invalid item index in GetItem") );
3931 wxListLineData
*line
= GetLine((size_t)item
.m_itemId
);
3932 line
->GetItem( item
.m_col
, item
);
3934 // Get item state if user wants it
3935 if ( item
.m_mask
& wxLIST_MASK_STATE
)
3936 item
.m_state
= GetItemState( item
.m_itemId
, wxLIST_STATE_SELECTED
|
3937 wxLIST_STATE_FOCUSED
);
3940 // ----------------------------------------------------------------------------
3942 // ----------------------------------------------------------------------------
3944 size_t wxListMainWindow::GetItemCount() const
3946 return IsVirtual() ? m_countVirt
: m_lines
.GetCount();
3949 void wxListMainWindow::SetItemCount(long count
)
3951 m_selStore
.SetItemCount(count
);
3952 m_countVirt
= count
;
3954 ResetVisibleLinesRange();
3956 // scrollbars must be reset
3960 int wxListMainWindow::GetSelectedItemCount() const
3962 // deal with the quick case first
3963 if ( IsSingleSel() )
3964 return HasCurrent() ? IsHighlighted(m_current
) : false;
3966 // virtual controls remmebers all its selections itself
3968 return m_selStore
.GetSelectedCount();
3970 // TODO: we probably should maintain the number of items selected even for
3971 // non virtual controls as enumerating all lines is really slow...
3972 size_t countSel
= 0;
3973 size_t count
= GetItemCount();
3974 for ( size_t line
= 0; line
< count
; line
++ )
3976 if ( GetLine(line
)->IsHighlighted() )
3983 // ----------------------------------------------------------------------------
3984 // item position/size
3985 // ----------------------------------------------------------------------------
3987 wxRect
wxListMainWindow::GetViewRect() const
3989 wxASSERT_MSG( !HasFlag(wxLC_REPORT
| wxLC_LIST
),
3990 _T("wxListCtrl::GetViewRect() only works in icon mode") );
3992 // we need to find the longest/tallest label
3993 wxCoord xMax
= 0, yMax
= 0;
3994 const int count
= GetItemCount();
3997 for ( int i
= 0; i
< count
; i
++ )
4002 wxCoord x
= r
.GetRight(),
4012 // some fudge needed to make it look prettier
4013 xMax
+= 2 * EXTRA_BORDER_X
;
4014 yMax
+= 2 * EXTRA_BORDER_Y
;
4016 // account for the scrollbars if necessary
4017 const wxSize sizeAll
= GetClientSize();
4018 if ( xMax
> sizeAll
.x
)
4019 yMax
+= wxSystemSettings::GetMetric(wxSYS_HSCROLL_Y
);
4020 if ( yMax
> sizeAll
.y
)
4021 xMax
+= wxSystemSettings::GetMetric(wxSYS_VSCROLL_X
);
4023 return wxRect(0, 0, xMax
, yMax
);
4026 void wxListMainWindow::GetItemRect( long index
, wxRect
&rect
) const
4028 wxCHECK_RET( index
>= 0 && (size_t)index
< GetItemCount(),
4029 _T("invalid index in GetItemRect") );
4031 // ensure that we're laid out, otherwise we could return nonsense
4034 wxConstCast(this, wxListMainWindow
)->
4035 RecalculatePositions(true /* no refresh */);
4038 rect
= GetLineRect((size_t)index
);
4040 CalcScrolledPosition(rect
.x
, rect
.y
, &rect
.x
, &rect
.y
);
4043 bool wxListMainWindow::GetItemPosition(long item
, wxPoint
& pos
) const
4046 GetItemRect(item
, rect
);
4054 // ----------------------------------------------------------------------------
4055 // geometry calculation
4056 // ----------------------------------------------------------------------------
4058 void wxListMainWindow::RecalculatePositions(bool noRefresh
)
4060 const int lineHeight
= GetLineHeight();
4062 wxClientDC
dc( this );
4063 dc
.SetFont( GetFont() );
4065 const size_t count
= GetItemCount();
4068 if ( HasFlag(wxLC_ICON
) )
4069 iconSpacing
= m_normal_spacing
;
4070 else if ( HasFlag(wxLC_SMALL_ICON
) )
4071 iconSpacing
= m_small_spacing
;
4075 // Note that we do not call GetClientSize() here but
4076 // GetSize() and subtract the border size for sunken
4077 // borders manually. This is technically incorrect,
4078 // but we need to know the client area's size WITHOUT
4079 // scrollbars here. Since we don't know if there are
4080 // any scrollbars, we use GetSize() instead. Another
4081 // solution would be to call SetScrollbars() here to
4082 // remove the scrollbars and call GetClientSize() then,
4083 // but this might result in flicker and - worse - will
4084 // reset the scrollbars to 0 which is not good at all
4085 // if you resize a dialog/window, but don't want to
4086 // reset the window scrolling. RR.
4087 // Furthermore, we actually do NOT subtract the border
4088 // width as 2 pixels is just the extra space which we
4089 // need around the actual content in the window. Other-
4090 // wise the text would e.g. touch the upper border. RR.
4093 GetSize( &clientWidth
, &clientHeight
);
4095 if ( InReportView() )
4097 // all lines have the same height and we scroll one line per step
4098 int entireHeight
= count
* lineHeight
+ LINE_SPACING
;
4100 m_linesPerPage
= clientHeight
/ lineHeight
;
4102 ResetVisibleLinesRange();
4104 SetScrollbars( SCROLL_UNIT_X
, lineHeight
,
4105 GetHeaderWidth() / SCROLL_UNIT_X
,
4106 (entireHeight
+ lineHeight
- 1) / lineHeight
,
4107 GetScrollPos(wxHORIZONTAL
),
4108 GetScrollPos(wxVERTICAL
),
4113 // we have 3 different layout strategies: either layout all items
4114 // horizontally/vertically (wxLC_ALIGN_XXX styles explicitly given) or
4115 // to arrange them in top to bottom, left to right (don't ask me why
4116 // not the other way round...) order
4117 if ( HasFlag(wxLC_ALIGN_LEFT
| wxLC_ALIGN_TOP
) )
4119 int x
= EXTRA_BORDER_X
;
4120 int y
= EXTRA_BORDER_Y
;
4122 wxCoord widthMax
= 0;
4125 for ( i
= 0; i
< count
; i
++ )
4127 wxListLineData
*line
= GetLine(i
);
4128 line
->CalculateSize( &dc
, iconSpacing
);
4129 line
->SetPosition( x
, y
, iconSpacing
);
4131 wxSize sizeLine
= GetLineSize(i
);
4133 if ( HasFlag(wxLC_ALIGN_TOP
) )
4135 if ( sizeLine
.x
> widthMax
)
4136 widthMax
= sizeLine
.x
;
4140 else // wxLC_ALIGN_LEFT
4142 x
+= sizeLine
.x
+ MARGIN_BETWEEN_ROWS
;
4146 if ( HasFlag(wxLC_ALIGN_TOP
) )
4148 // traverse the items again and tweak their sizes so that they are
4149 // all the same in a row
4150 for ( i
= 0; i
< count
; i
++ )
4152 wxListLineData
*line
= GetLine(i
);
4153 line
->m_gi
->ExtendWidth(widthMax
);
4161 (x
+ SCROLL_UNIT_X
) / SCROLL_UNIT_X
,
4162 (y
+ lineHeight
) / lineHeight
,
4163 GetScrollPos( wxHORIZONTAL
),
4164 GetScrollPos( wxVERTICAL
),
4168 else // "flowed" arrangement, the most complicated case
4170 // at first we try without any scrollbars, if the items don't fit into
4171 // the window, we recalculate after subtracting the space taken by the
4174 int entireWidth
= 0;
4176 for (int tries
= 0; tries
< 2; tries
++)
4178 entireWidth
= 2 * EXTRA_BORDER_X
;
4182 // Now we have decided that the items do not fit into the
4183 // client area, so we need a scrollbar
4184 entireWidth
+= SCROLL_UNIT_X
;
4187 int x
= EXTRA_BORDER_X
;
4188 int y
= EXTRA_BORDER_Y
;
4189 int maxWidthInThisRow
= 0;
4192 int currentlyVisibleLines
= 0;
4194 for (size_t i
= 0; i
< count
; i
++)
4196 currentlyVisibleLines
++;
4197 wxListLineData
*line
= GetLine( i
);
4198 line
->CalculateSize( &dc
, iconSpacing
);
4199 line
->SetPosition( x
, y
, iconSpacing
);
4201 wxSize sizeLine
= GetLineSize( i
);
4203 if ( maxWidthInThisRow
< sizeLine
.x
)
4204 maxWidthInThisRow
= sizeLine
.x
;
4207 if (currentlyVisibleLines
> m_linesPerPage
)
4208 m_linesPerPage
= currentlyVisibleLines
;
4210 if ( y
+ sizeLine
.y
>= clientHeight
)
4212 currentlyVisibleLines
= 0;
4214 maxWidthInThisRow
+= MARGIN_BETWEEN_ROWS
;
4215 x
+= maxWidthInThisRow
;
4216 entireWidth
+= maxWidthInThisRow
;
4217 maxWidthInThisRow
= 0;
4220 // We have reached the last item.
4221 if ( i
== count
- 1 )
4222 entireWidth
+= maxWidthInThisRow
;
4224 if ( (tries
== 0) &&
4225 (entireWidth
+ SCROLL_UNIT_X
> clientWidth
) )
4227 clientHeight
-= wxSystemSettings::
4228 GetMetric(wxSYS_HSCROLL_Y
);
4233 if ( i
== count
- 1 )
4234 tries
= 1; // Everything fits, no second try required.
4242 (entireWidth
+ SCROLL_UNIT_X
) / SCROLL_UNIT_X
,
4244 GetScrollPos( wxHORIZONTAL
),
4253 // FIXME: why should we call it from here?
4260 void wxListMainWindow::RefreshAll()
4265 wxListHeaderWindow
*headerWin
= GetListCtrl()->m_headerWin
;
4266 if ( headerWin
&& headerWin
->m_dirty
)
4268 headerWin
->m_dirty
= false;
4269 headerWin
->Refresh();
4273 void wxListMainWindow::UpdateCurrent()
4275 if ( !HasCurrent() && !IsEmpty() )
4279 long wxListMainWindow::GetNextItem( long item
,
4280 int WXUNUSED(geometry
),
4284 max
= GetItemCount();
4285 wxCHECK_MSG( (ret
== -1) || (ret
< max
), -1,
4286 _T("invalid listctrl index in GetNextItem()") );
4288 // notice that we start with the next item (or the first one if item == -1)
4289 // and this is intentional to allow writing a simple loop to iterate over
4290 // all selected items
4293 // this is not an error because the index was OK initially,
4294 // just no such item
4301 size_t count
= GetItemCount();
4302 for ( size_t line
= (size_t)ret
; line
< count
; line
++ )
4304 if ( (state
& wxLIST_STATE_FOCUSED
) && (line
== m_current
) )
4307 if ( (state
& wxLIST_STATE_SELECTED
) && IsHighlighted(line
) )
4314 // ----------------------------------------------------------------------------
4316 // ----------------------------------------------------------------------------
4318 void wxListMainWindow::DeleteItem( long lindex
)
4320 size_t count
= GetItemCount();
4322 wxCHECK_RET( (lindex
>= 0) && ((size_t)lindex
< count
),
4323 _T("invalid item index in DeleteItem") );
4325 size_t index
= (size_t)lindex
;
4327 // we don't need to adjust the index for the previous items
4328 if ( HasCurrent() && m_current
>= index
)
4330 // if the current item is being deleted, we want the next one to
4331 // become selected - unless there is no next one - so don't adjust
4332 // m_current in this case
4333 if ( m_current
!= index
|| m_current
== count
- 1 )
4337 if ( InReportView() )
4339 // mark the Column Max Width cache as dirty if the items in the line
4340 // we're deleting contain the Max Column Width
4341 wxListLineData
* const line
= GetLine(index
);
4342 wxListItemDataList::compatibility_iterator n
;
4343 wxListItemData
*itemData
;
4347 for (size_t i
= 0; i
< m_columns
.GetCount(); i
++)
4349 n
= line
->m_items
.Item( i
);
4350 itemData
= n
->GetData();
4351 itemData
->GetItem(item
);
4353 itemWidth
= GetItemWidthWithImage(&item
);
4355 if (itemWidth
>= m_aColWidths
.Item(i
)->nMaxWidth
)
4356 m_aColWidths
.Item(i
)->bNeedsUpdate
= true;
4359 ResetVisibleLinesRange();
4362 SendNotify( index
, wxEVT_COMMAND_LIST_DELETE_ITEM
, wxDefaultPosition
);
4367 m_selStore
.OnItemDelete(index
);
4371 m_lines
.RemoveAt( index
);
4374 // we need to refresh the (vert) scrollbar as the number of items changed
4377 RefreshAfter(index
);
4380 void wxListMainWindow::DeleteColumn( int col
)
4382 wxListHeaderDataList::compatibility_iterator node
= m_columns
.Item( col
);
4384 wxCHECK_RET( node
, wxT("invalid column index in DeleteColumn()") );
4387 delete node
->GetData();
4388 m_columns
.Erase( node
);
4392 // update all the items
4393 for ( size_t i
= 0; i
< m_lines
.GetCount(); i
++ )
4395 wxListLineData
* const line
= GetLine(i
);
4396 wxListItemDataList::compatibility_iterator n
= line
->m_items
.Item( col
);
4397 delete n
->GetData();
4398 line
->m_items
.Erase(n
);
4402 if ( InReportView() ) // we only cache max widths when in Report View
4404 delete m_aColWidths
.Item(col
);
4405 m_aColWidths
.RemoveAt(col
);
4408 // invalidate it as it has to be recalculated
4412 void wxListMainWindow::DoDeleteAllItems()
4415 // nothing to do - in particular, don't send the event
4420 // to make the deletion of all items faster, we don't send the
4421 // notifications for each item deletion in this case but only one event
4422 // for all of them: this is compatible with wxMSW and documented in
4423 // DeleteAllItems() description
4425 wxListEvent
event( wxEVT_COMMAND_LIST_DELETE_ALL_ITEMS
, GetParent()->GetId() );
4426 event
.SetEventObject( GetParent() );
4427 GetParent()->GetEventHandler()->ProcessEvent( event
);
4435 if ( InReportView() )
4437 ResetVisibleLinesRange();
4438 for (size_t i
= 0; i
< m_aColWidths
.GetCount(); i
++)
4440 m_aColWidths
.Item(i
)->bNeedsUpdate
= true;
4447 void wxListMainWindow::DeleteAllItems()
4451 RecalculatePositions();
4454 void wxListMainWindow::DeleteEverything()
4456 WX_CLEAR_LIST(wxListHeaderDataList
, m_columns
);
4457 WX_CLEAR_ARRAY(m_aColWidths
);
4462 // ----------------------------------------------------------------------------
4463 // scanning for an item
4464 // ----------------------------------------------------------------------------
4466 void wxListMainWindow::EnsureVisible( long index
)
4468 wxCHECK_RET( index
>= 0 && (size_t)index
< GetItemCount(),
4469 _T("invalid index in EnsureVisible") );
4471 // We have to call this here because the label in question might just have
4472 // been added and its position is not known yet
4474 RecalculatePositions(true /* no refresh */);
4476 MoveToItem((size_t)index
);
4479 long wxListMainWindow::FindItem(long start
, const wxString
& str
, bool WXUNUSED(partial
) )
4486 size_t count
= GetItemCount();
4487 for ( size_t i
= (size_t)pos
; i
< count
; i
++ )
4489 wxListLineData
*line
= GetLine(i
);
4490 if ( line
->GetText(0) == tmp
)
4497 long wxListMainWindow::FindItem(long start
, wxUIntPtr data
)
4503 size_t count
= GetItemCount();
4504 for (size_t i
= (size_t)pos
; i
< count
; i
++)
4506 wxListLineData
*line
= GetLine(i
);
4508 line
->GetItem( 0, item
);
4509 if (item
.m_data
== data
)
4516 long wxListMainWindow::FindItem( const wxPoint
& pt
)
4519 GetVisibleLinesRange( &topItem
, NULL
);
4522 GetItemPosition( GetItemCount() - 1, p
);
4526 long id
= (long)floor( pt
.y
* double(GetItemCount() - topItem
- 1) / p
.y
+ topItem
);
4527 if ( id
>= 0 && id
< (long)GetItemCount() )
4533 long wxListMainWindow::HitTest( int x
, int y
, int &flags
) const
4535 CalcUnscrolledPosition( x
, y
, &x
, &y
);
4537 size_t count
= GetItemCount();
4539 if ( InReportView() )
4541 size_t current
= y
/ GetLineHeight();
4542 if ( current
< count
)
4544 flags
= HitTestLine(current
, x
, y
);
4551 // TODO: optimize it too! this is less simple than for report view but
4552 // enumerating all items is still not a way to do it!!
4553 for ( size_t current
= 0; current
< count
; current
++ )
4555 flags
= HitTestLine(current
, x
, y
);
4564 // ----------------------------------------------------------------------------
4566 // ----------------------------------------------------------------------------
4568 void wxListMainWindow::InsertItem( wxListItem
&item
)
4570 wxASSERT_MSG( !IsVirtual(), _T("can't be used with virtual control") );
4572 int count
= GetItemCount();
4573 wxCHECK_RET( item
.m_itemId
>= 0, _T("invalid item index") );
4575 if (item
.m_itemId
> count
)
4576 item
.m_itemId
= count
;
4578 size_t id
= item
.m_itemId
;
4582 if ( InReportView() )
4584 ResetVisibleLinesRange();
4586 // calculate the width of the item and adjust the max column width
4587 wxColWidthInfo
*pWidthInfo
= m_aColWidths
.Item(item
.GetColumn());
4588 int width
= GetItemWidthWithImage(&item
);
4589 item
.SetWidth(width
);
4590 if (width
> pWidthInfo
->nMaxWidth
)
4591 pWidthInfo
->nMaxWidth
= width
;
4594 wxListLineData
*line
= new wxListLineData(this);
4596 line
->SetItem( item
.m_col
, item
);
4598 m_lines
.Insert( line
, id
);
4602 // If an item is selected at or below the point of insertion, we need to
4603 // increment the member variables because the current row's index has gone
4605 if ( HasCurrent() && m_current
>= id
)
4608 SendNotify(id
, wxEVT_COMMAND_LIST_INSERT_ITEM
);
4610 RefreshLines(id
, GetItemCount() - 1);
4613 void wxListMainWindow::InsertColumn( long col
, wxListItem
&item
)
4616 if ( InReportView() )
4618 if (item
.m_width
== wxLIST_AUTOSIZE_USEHEADER
)
4619 item
.m_width
= GetTextLength( item
.m_text
);
4621 wxListHeaderData
*column
= new wxListHeaderData( item
);
4622 wxColWidthInfo
*colWidthInfo
= new wxColWidthInfo();
4624 bool insert
= (col
>= 0) && ((size_t)col
< m_columns
.GetCount());
4627 wxListHeaderDataList::compatibility_iterator
4628 node
= m_columns
.Item( col
);
4629 m_columns
.Insert( node
, column
);
4630 m_aColWidths
.Insert( colWidthInfo
, col
);
4634 m_columns
.Append( column
);
4635 m_aColWidths
.Add( colWidthInfo
);
4640 // update all the items
4641 for ( size_t i
= 0; i
< m_lines
.GetCount(); i
++ )
4643 wxListLineData
* const line
= GetLine(i
);
4644 wxListItemData
* const data
= new wxListItemData(this);
4646 line
->m_items
.Insert(col
, data
);
4648 line
->m_items
.Append(data
);
4652 // invalidate it as it has to be recalculated
4657 int wxListMainWindow::GetItemWidthWithImage(wxListItem
* item
)
4660 wxClientDC
dc(this);
4662 dc
.SetFont( GetFont() );
4664 if (item
->GetImage() != -1)
4667 GetImageSize( item
->GetImage(), ix
, iy
);
4671 if (!item
->GetText().empty())
4674 dc
.GetTextExtent( item
->GetText(), &w
, NULL
);
4681 // ----------------------------------------------------------------------------
4683 // ----------------------------------------------------------------------------
4685 wxListCtrlCompare list_ctrl_compare_func_2
;
4686 long list_ctrl_compare_data
;
4688 int LINKAGEMODE
list_ctrl_compare_func_1( wxListLineData
**arg1
, wxListLineData
**arg2
)
4690 wxListLineData
*line1
= *arg1
;
4691 wxListLineData
*line2
= *arg2
;
4693 line1
->GetItem( 0, item
);
4694 wxUIntPtr data1
= item
.m_data
;
4695 line2
->GetItem( 0, item
);
4696 wxUIntPtr data2
= item
.m_data
;
4697 return list_ctrl_compare_func_2( data1
, data2
, list_ctrl_compare_data
);
4700 void wxListMainWindow::SortItems( wxListCtrlCompare fn
, long data
)
4702 list_ctrl_compare_func_2
= fn
;
4703 list_ctrl_compare_data
= data
;
4704 m_lines
.Sort( list_ctrl_compare_func_1
);
4708 // ----------------------------------------------------------------------------
4710 // ----------------------------------------------------------------------------
4712 void wxListMainWindow::OnScroll(wxScrollWinEvent
& event
)
4714 // update our idea of which lines are shown when we redraw the window the
4716 ResetVisibleLinesRange();
4719 #if ( defined(__WXGTK__) || defined(__WXMAC__) ) && !defined(__WXUNIVERSAL__)
4720 wxScrolledWindow::OnScroll(event
);
4722 HandleOnScroll( event
);
4725 if ( event
.GetOrientation() == wxHORIZONTAL
&& HasHeader() )
4727 wxGenericListCtrl
* lc
= GetListCtrl();
4728 wxCHECK_RET( lc
, _T("no listctrl window?") );
4730 lc
->m_headerWin
->Refresh();
4731 lc
->m_headerWin
->Update();
4735 int wxListMainWindow::GetCountPerPage() const
4737 if ( !m_linesPerPage
)
4739 wxConstCast(this, wxListMainWindow
)->
4740 m_linesPerPage
= GetClientSize().y
/ GetLineHeight();
4743 return m_linesPerPage
;
4746 void wxListMainWindow::GetVisibleLinesRange(size_t *from
, size_t *to
)
4748 wxASSERT_MSG( InReportView(), _T("this is for report mode only") );
4750 if ( m_lineFrom
== (size_t)-1 )
4752 size_t count
= GetItemCount();
4755 m_lineFrom
= GetScrollPos(wxVERTICAL
);
4757 // this may happen if SetScrollbars() hadn't been called yet
4758 if ( m_lineFrom
>= count
)
4759 m_lineFrom
= count
- 1;
4761 // we redraw one extra line but this is needed to make the redrawing
4762 // logic work when there is a fractional number of lines on screen
4763 m_lineTo
= m_lineFrom
+ m_linesPerPage
;
4764 if ( m_lineTo
>= count
)
4765 m_lineTo
= count
- 1;
4767 else // empty control
4770 m_lineTo
= (size_t)-1;
4774 wxASSERT_MSG( IsEmpty() ||
4775 (m_lineFrom
<= m_lineTo
&& m_lineTo
< GetItemCount()),
4776 _T("GetVisibleLinesRange() returns incorrect result") );
4784 // -------------------------------------------------------------------------------------
4785 // wxGenericListCtrl
4786 // -------------------------------------------------------------------------------------
4788 IMPLEMENT_DYNAMIC_CLASS(wxGenericListCtrl
, wxControl
)
4790 BEGIN_EVENT_TABLE(wxGenericListCtrl
,wxControl
)
4791 EVT_SIZE(wxGenericListCtrl::OnSize
)
4794 wxGenericListCtrl::wxGenericListCtrl()
4796 m_imageListNormal
= (wxImageList
*) NULL
;
4797 m_imageListSmall
= (wxImageList
*) NULL
;
4798 m_imageListState
= (wxImageList
*) NULL
;
4800 m_ownsImageListNormal
=
4801 m_ownsImageListSmall
=
4802 m_ownsImageListState
= false;
4804 m_mainWin
= (wxListMainWindow
*) NULL
;
4805 m_headerWin
= (wxListHeaderWindow
*) NULL
;
4809 wxGenericListCtrl::~wxGenericListCtrl()
4811 if (m_ownsImageListNormal
)
4812 delete m_imageListNormal
;
4813 if (m_ownsImageListSmall
)
4814 delete m_imageListSmall
;
4815 if (m_ownsImageListState
)
4816 delete m_imageListState
;
4819 void wxGenericListCtrl::CalculateAndSetHeaderHeight()
4825 GetThemeMetric( kThemeMetricListHeaderHeight
, &h
);
4827 // we use 'g' to get the descent, too
4829 m_headerWin
->GetTextExtent(wxT("Hg"), &w
, &h
, &d
);
4830 h
+= d
+ 2 * HEADER_OFFSET_Y
+ EXTRA_HEIGHT
;
4833 // only update if changed
4834 if ( h
!= m_headerHeight
)
4839 ResizeReportView(true);
4840 else //why is this needed if it doesn't have a header?
4841 m_headerWin
->SetSize(m_headerWin
->GetSize().x
, m_headerHeight
);
4846 void wxGenericListCtrl::CreateHeaderWindow()
4848 m_headerWin
= new wxListHeaderWindow
4850 this, wxID_ANY
, m_mainWin
,
4852 wxSize(GetClientSize().x
, m_headerHeight
),
4855 CalculateAndSetHeaderHeight();
4858 bool wxGenericListCtrl::Create(wxWindow
*parent
,
4863 const wxValidator
&validator
,
4864 const wxString
&name
)
4868 m_imageListState
= (wxImageList
*) NULL
;
4869 m_ownsImageListNormal
=
4870 m_ownsImageListSmall
=
4871 m_ownsImageListState
= false;
4873 m_mainWin
= (wxListMainWindow
*) NULL
;
4874 m_headerWin
= (wxListHeaderWindow
*) NULL
;
4878 if ( !(style
& wxLC_MASK_TYPE
) )
4880 style
= style
| wxLC_LIST
;
4883 if ( !wxControl::Create( parent
, id
, pos
, size
, style
, validator
, name
) )
4886 // don't create the inner window with the border
4887 style
&= ~wxBORDER_MASK
;
4889 m_mainWin
= new wxListMainWindow( this, wxID_ANY
, wxPoint(0, 0), size
, style
);
4891 #ifdef __WXMAC_CARBON__
4892 // Human Interface Guidelines ask us for a special font in this case
4893 if ( GetWindowVariant() == wxWINDOW_VARIANT_NORMAL
)
4896 font
.MacCreateThemeFont( kThemeViewsFont
);
4901 if ( InReportView() )
4903 CreateHeaderWindow();
4905 #ifdef __WXMAC_CARBON__
4909 font
.MacCreateThemeFont( kThemeSmallSystemFont
);
4910 m_headerWin
->SetFont( font
);
4911 CalculateAndSetHeaderHeight();
4915 if ( HasFlag(wxLC_NO_HEADER
) )
4916 // VZ: why do we create it at all then?
4917 m_headerWin
->Show( false );
4920 SetInitialSize(size
);
4925 void wxGenericListCtrl::SetSingleStyle( long style
, bool add
)
4927 wxASSERT_MSG( !(style
& wxLC_VIRTUAL
),
4928 _T("wxLC_VIRTUAL can't be [un]set") );
4930 long flag
= GetWindowStyle();
4934 if (style
& wxLC_MASK_TYPE
)
4935 flag
&= ~(wxLC_MASK_TYPE
| wxLC_VIRTUAL
);
4936 if (style
& wxLC_MASK_ALIGN
)
4937 flag
&= ~wxLC_MASK_ALIGN
;
4938 if (style
& wxLC_MASK_SORT
)
4939 flag
&= ~wxLC_MASK_SORT
;
4947 SetWindowStyleFlag( flag
);
4950 void wxGenericListCtrl::SetWindowStyleFlag( long flag
)
4954 m_mainWin
->DeleteEverything();
4956 // has the header visibility changed?
4957 bool hasHeader
= HasHeader();
4958 bool willHaveHeader
= (flag
& wxLC_REPORT
) && !(flag
& wxLC_NO_HEADER
);
4960 if ( hasHeader
!= willHaveHeader
)
4967 // don't delete, just hide, as we can reuse it later
4968 m_headerWin
->Show(false);
4970 //else: nothing to do
4972 else // must show header
4976 CreateHeaderWindow();
4978 else // already have it, just show
4980 m_headerWin
->Show( true );
4984 ResizeReportView(willHaveHeader
);
4988 wxWindow::SetWindowStyleFlag( flag
);
4991 bool wxGenericListCtrl::GetColumn(int col
, wxListItem
&item
) const
4993 m_mainWin
->GetColumn( col
, item
);
4997 bool wxGenericListCtrl::SetColumn( int col
, wxListItem
& item
)
4999 m_mainWin
->SetColumn( col
, item
);
5003 int wxGenericListCtrl::GetColumnWidth( int col
) const
5005 return m_mainWin
->GetColumnWidth( col
);
5008 bool wxGenericListCtrl::SetColumnWidth( int col
, int width
)
5010 m_mainWin
->SetColumnWidth( col
, width
);
5014 int wxGenericListCtrl::GetCountPerPage() const
5016 return m_mainWin
->GetCountPerPage(); // different from Windows ?
5019 bool wxGenericListCtrl::GetItem( wxListItem
&info
) const
5021 m_mainWin
->GetItem( info
);
5025 bool wxGenericListCtrl::SetItem( wxListItem
&info
)
5027 m_mainWin
->SetItem( info
);
5031 long wxGenericListCtrl::SetItem( long index
, int col
, const wxString
& label
, int imageId
)
5034 info
.m_text
= label
;
5035 info
.m_mask
= wxLIST_MASK_TEXT
;
5036 info
.m_itemId
= index
;
5040 info
.m_image
= imageId
;
5041 info
.m_mask
|= wxLIST_MASK_IMAGE
;
5044 m_mainWin
->SetItem(info
);
5048 int wxGenericListCtrl::GetItemState( long item
, long stateMask
) const
5050 return m_mainWin
->GetItemState( item
, stateMask
);
5053 bool wxGenericListCtrl::SetItemState( long item
, long state
, long stateMask
)
5055 m_mainWin
->SetItemState( item
, state
, stateMask
);
5060 wxGenericListCtrl::SetItemImage( long item
, int image
, int WXUNUSED(selImage
) )
5062 return SetItemColumnImage(item
, 0, image
);
5066 wxGenericListCtrl::SetItemColumnImage( long item
, long column
, int image
)
5069 info
.m_image
= image
;
5070 info
.m_mask
= wxLIST_MASK_IMAGE
;
5071 info
.m_itemId
= item
;
5072 info
.m_col
= column
;
5073 m_mainWin
->SetItem( info
);
5077 wxString
wxGenericListCtrl::GetItemText( long item
) const
5079 return m_mainWin
->GetItemText(item
);
5082 void wxGenericListCtrl::SetItemText( long item
, const wxString
& str
)
5084 m_mainWin
->SetItemText(item
, str
);
5087 wxUIntPtr
wxGenericListCtrl::GetItemData( long item
) const
5090 info
.m_mask
= wxLIST_MASK_DATA
;
5091 info
.m_itemId
= item
;
5092 m_mainWin
->GetItem( info
);
5096 bool wxGenericListCtrl::SetItemData( long item
, long data
)
5099 info
.m_mask
= wxLIST_MASK_DATA
;
5100 info
.m_itemId
= item
;
5102 m_mainWin
->SetItem( info
);
5106 wxRect
wxGenericListCtrl::GetViewRect() const
5108 return m_mainWin
->GetViewRect();
5111 bool wxGenericListCtrl::GetItemRect( long item
, wxRect
&rect
, int WXUNUSED(code
) ) const
5113 m_mainWin
->GetItemRect( item
, rect
);
5114 if ( m_mainWin
->HasHeader() )
5115 rect
.y
+= m_headerHeight
+ 1;
5119 bool wxGenericListCtrl::GetItemPosition( long item
, wxPoint
& pos
) const
5121 m_mainWin
->GetItemPosition( item
, pos
);
5125 bool wxGenericListCtrl::SetItemPosition( long WXUNUSED(item
), const wxPoint
& WXUNUSED(pos
) )
5130 int wxGenericListCtrl::GetItemCount() const
5132 return m_mainWin
->GetItemCount();
5135 int wxGenericListCtrl::GetColumnCount() const
5137 return m_mainWin
->GetColumnCount();
5140 void wxGenericListCtrl::SetItemSpacing( int spacing
, bool isSmall
)
5142 m_mainWin
->SetItemSpacing( spacing
, isSmall
);
5145 wxSize
wxGenericListCtrl::GetItemSpacing() const
5147 const int spacing
= m_mainWin
->GetItemSpacing(HasFlag(wxLC_SMALL_ICON
));
5149 return wxSize(spacing
, spacing
);
5152 #if WXWIN_COMPATIBILITY_2_6
5153 int wxGenericListCtrl::GetItemSpacing( bool isSmall
) const
5155 return m_mainWin
->GetItemSpacing( isSmall
);
5157 #endif // WXWIN_COMPATIBILITY_2_6
5159 void wxGenericListCtrl::SetItemTextColour( long item
, const wxColour
&col
)
5162 info
.m_itemId
= item
;
5163 info
.SetTextColour( col
);
5164 m_mainWin
->SetItem( info
);
5167 wxColour
wxGenericListCtrl::GetItemTextColour( long item
) const
5170 info
.m_itemId
= item
;
5171 m_mainWin
->GetItem( info
);
5172 return info
.GetTextColour();
5175 void wxGenericListCtrl::SetItemBackgroundColour( long item
, const wxColour
&col
)
5178 info
.m_itemId
= item
;
5179 info
.SetBackgroundColour( col
);
5180 m_mainWin
->SetItem( info
);
5183 wxColour
wxGenericListCtrl::GetItemBackgroundColour( long item
) const
5186 info
.m_itemId
= item
;
5187 m_mainWin
->GetItem( info
);
5188 return info
.GetBackgroundColour();
5191 void wxGenericListCtrl::SetItemFont( long item
, const wxFont
&f
)
5194 info
.m_itemId
= item
;
5196 m_mainWin
->SetItem( info
);
5199 wxFont
wxGenericListCtrl::GetItemFont( long item
) const
5202 info
.m_itemId
= item
;
5203 m_mainWin
->GetItem( info
);
5204 return info
.GetFont();
5207 int wxGenericListCtrl::GetSelectedItemCount() const
5209 return m_mainWin
->GetSelectedItemCount();
5212 wxColour
wxGenericListCtrl::GetTextColour() const
5214 return GetForegroundColour();
5217 void wxGenericListCtrl::SetTextColour(const wxColour
& col
)
5219 SetForegroundColour(col
);
5222 long wxGenericListCtrl::GetTopItem() const
5225 m_mainWin
->GetVisibleLinesRange(&top
, NULL
);
5229 long wxGenericListCtrl::GetNextItem( long item
, int geom
, int state
) const
5231 return m_mainWin
->GetNextItem( item
, geom
, state
);
5234 wxImageList
*wxGenericListCtrl::GetImageList(int which
) const
5236 if (which
== wxIMAGE_LIST_NORMAL
)
5237 return m_imageListNormal
;
5238 else if (which
== wxIMAGE_LIST_SMALL
)
5239 return m_imageListSmall
;
5240 else if (which
== wxIMAGE_LIST_STATE
)
5241 return m_imageListState
;
5243 return (wxImageList
*) NULL
;
5246 void wxGenericListCtrl::SetImageList( wxImageList
*imageList
, int which
)
5248 if ( which
== wxIMAGE_LIST_NORMAL
)
5250 if (m_ownsImageListNormal
)
5251 delete m_imageListNormal
;
5252 m_imageListNormal
= imageList
;
5253 m_ownsImageListNormal
= false;
5255 else if ( which
== wxIMAGE_LIST_SMALL
)
5257 if (m_ownsImageListSmall
)
5258 delete m_imageListSmall
;
5259 m_imageListSmall
= imageList
;
5260 m_ownsImageListSmall
= false;
5262 else if ( which
== wxIMAGE_LIST_STATE
)
5264 if (m_ownsImageListState
)
5265 delete m_imageListState
;
5266 m_imageListState
= imageList
;
5267 m_ownsImageListState
= false;
5270 m_mainWin
->SetImageList( imageList
, which
);
5273 void wxGenericListCtrl::AssignImageList(wxImageList
*imageList
, int which
)
5275 SetImageList(imageList
, which
);
5276 if ( which
== wxIMAGE_LIST_NORMAL
)
5277 m_ownsImageListNormal
= true;
5278 else if ( which
== wxIMAGE_LIST_SMALL
)
5279 m_ownsImageListSmall
= true;
5280 else if ( which
== wxIMAGE_LIST_STATE
)
5281 m_ownsImageListState
= true;
5284 bool wxGenericListCtrl::Arrange( int WXUNUSED(flag
) )
5289 bool wxGenericListCtrl::DeleteItem( long item
)
5291 m_mainWin
->DeleteItem( item
);
5295 bool wxGenericListCtrl::DeleteAllItems()
5297 m_mainWin
->DeleteAllItems();
5301 bool wxGenericListCtrl::DeleteAllColumns()
5303 size_t count
= m_mainWin
->m_columns
.GetCount();
5304 for ( size_t n
= 0; n
< count
; n
++ )
5309 void wxGenericListCtrl::ClearAll()
5311 m_mainWin
->DeleteEverything();
5314 bool wxGenericListCtrl::DeleteColumn( int col
)
5316 m_mainWin
->DeleteColumn( col
);
5318 // if we don't have the header any longer, we need to relayout the window
5319 if ( !GetColumnCount() )
5320 ResizeReportView(false /* no header */);
5324 wxTextCtrl
*wxGenericListCtrl::EditLabel(long item
,
5325 wxClassInfo
* textControlClass
)
5327 return m_mainWin
->EditLabel( item
, textControlClass
);
5330 wxTextCtrl
*wxGenericListCtrl::GetEditControl() const
5332 return m_mainWin
->GetEditControl();
5335 bool wxGenericListCtrl::EnsureVisible( long item
)
5337 m_mainWin
->EnsureVisible( item
);
5341 long wxGenericListCtrl::FindItem( long start
, const wxString
& str
, bool partial
)
5343 return m_mainWin
->FindItem( start
, str
, partial
);
5346 long wxGenericListCtrl::FindItem( long start
, wxUIntPtr data
)
5348 return m_mainWin
->FindItem( start
, data
);
5351 long wxGenericListCtrl::FindItem( long WXUNUSED(start
), const wxPoint
& pt
,
5352 int WXUNUSED(direction
))
5354 return m_mainWin
->FindItem( pt
);
5357 // TODO: sub item hit testing
5358 long wxGenericListCtrl::HitTest(const wxPoint
& point
, int& flags
, long *) const
5360 return m_mainWin
->HitTest( (int)point
.x
, (int)point
.y
, flags
);
5363 long wxGenericListCtrl::InsertItem( wxListItem
& info
)
5365 m_mainWin
->InsertItem( info
);
5366 return info
.m_itemId
;
5369 long wxGenericListCtrl::InsertItem( long index
, const wxString
&label
)
5372 info
.m_text
= label
;
5373 info
.m_mask
= wxLIST_MASK_TEXT
;
5374 info
.m_itemId
= index
;
5375 return InsertItem( info
);
5378 long wxGenericListCtrl::InsertItem( long index
, int imageIndex
)
5381 info
.m_mask
= wxLIST_MASK_IMAGE
;
5382 info
.m_image
= imageIndex
;
5383 info
.m_itemId
= index
;
5384 return InsertItem( info
);
5387 long wxGenericListCtrl::InsertItem( long index
, const wxString
&label
, int imageIndex
)
5390 info
.m_text
= label
;
5391 info
.m_image
= imageIndex
;
5392 info
.m_mask
= wxLIST_MASK_TEXT
| wxLIST_MASK_IMAGE
;
5393 info
.m_itemId
= index
;
5394 return InsertItem( info
);
5397 long wxGenericListCtrl::InsertColumn( long col
, wxListItem
&item
)
5399 wxCHECK_MSG( m_headerWin
, -1, _T("can't add column in non report mode") );
5401 m_mainWin
->InsertColumn( col
, item
);
5403 // if we hadn't had a header before but have one now
5404 // then we need to relayout the window
5405 if ( GetColumnCount() == 1 && m_mainWin
->HasHeader() )
5406 ResizeReportView(true /* have header */);
5408 m_headerWin
->Refresh();
5413 long wxGenericListCtrl::InsertColumn( long col
, const wxString
&heading
,
5414 int format
, int width
)
5417 item
.m_mask
= wxLIST_MASK_TEXT
| wxLIST_MASK_FORMAT
;
5418 item
.m_text
= heading
;
5421 item
.m_mask
|= wxLIST_MASK_WIDTH
;
5422 item
.m_width
= width
;
5425 item
.m_format
= format
;
5427 return InsertColumn( col
, item
);
5430 bool wxGenericListCtrl::ScrollList( int WXUNUSED(dx
), int WXUNUSED(dy
) )
5436 // fn is a function which takes 3 long arguments: item1, item2, data.
5437 // item1 is the long data associated with a first item (NOT the index).
5438 // item2 is the long data associated with a second item (NOT the index).
5439 // data is the same value as passed to SortItems.
5440 // The return value is a negative number if the first item should precede the second
5441 // item, a positive number of the second item should precede the first,
5442 // or zero if the two items are equivalent.
5443 // data is arbitrary data to be passed to the sort function.
5445 bool wxGenericListCtrl::SortItems( wxListCtrlCompare fn
, long data
)
5447 m_mainWin
->SortItems( fn
, data
);
5451 // ----------------------------------------------------------------------------
5453 // ----------------------------------------------------------------------------
5455 void wxGenericListCtrl::OnSize(wxSizeEvent
& WXUNUSED(event
))
5460 ResizeReportView(m_mainWin
->HasHeader());
5461 m_mainWin
->RecalculatePositions();
5464 void wxGenericListCtrl::ResizeReportView(bool showHeader
)
5467 GetClientSize( &cw
, &ch
);
5471 m_headerWin
->SetSize( 0, 0, cw
, m_headerHeight
);
5472 if(ch
> m_headerHeight
)
5473 m_mainWin
->SetSize( 0, m_headerHeight
+ 1,
5474 cw
, ch
- m_headerHeight
- 1 );
5476 m_mainWin
->SetSize( 0, m_headerHeight
+ 1,
5479 else // no header window
5481 m_mainWin
->SetSize( 0, 0, cw
, ch
);
5485 void wxGenericListCtrl::OnInternalIdle()
5487 wxWindow::OnInternalIdle();
5489 // do it only if needed
5490 if ( !m_mainWin
->m_dirty
)
5493 m_mainWin
->RecalculatePositions();
5496 // ----------------------------------------------------------------------------
5498 // ----------------------------------------------------------------------------
5500 bool wxGenericListCtrl::SetBackgroundColour( const wxColour
&colour
)
5504 m_mainWin
->SetBackgroundColour( colour
);
5505 m_mainWin
->m_dirty
= true;
5511 bool wxGenericListCtrl::SetForegroundColour( const wxColour
&colour
)
5513 if ( !wxWindow::SetForegroundColour( colour
) )
5518 m_mainWin
->SetForegroundColour( colour
);
5519 m_mainWin
->m_dirty
= true;
5523 m_headerWin
->SetForegroundColour( colour
);
5528 bool wxGenericListCtrl::SetFont( const wxFont
&font
)
5530 if ( !wxWindow::SetFont( font
) )
5535 m_mainWin
->SetFont( font
);
5536 m_mainWin
->m_dirty
= true;
5541 m_headerWin
->SetFont( font
);
5542 CalculateAndSetHeaderHeight();
5552 wxGenericListCtrl::GetClassDefaultAttributes(wxWindowVariant variant
)
5555 // Use the same color scheme as wxListBox
5556 return wxListBox::GetClassDefaultAttributes(variant
);
5558 wxUnusedVar(variant
);
5559 wxVisualAttributes attr
;
5560 attr
.colFg
= wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT
);
5561 attr
.colBg
= wxSystemSettings::GetColour(wxSYS_COLOUR_LISTBOX
);
5562 attr
.font
= wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT
);
5567 // ----------------------------------------------------------------------------
5568 // methods forwarded to m_mainWin
5569 // ----------------------------------------------------------------------------
5571 #if wxUSE_DRAG_AND_DROP
5573 void wxGenericListCtrl::SetDropTarget( wxDropTarget
*dropTarget
)
5575 m_mainWin
->SetDropTarget( dropTarget
);
5578 wxDropTarget
*wxGenericListCtrl::GetDropTarget() const
5580 return m_mainWin
->GetDropTarget();
5585 bool wxGenericListCtrl::SetCursor( const wxCursor
&cursor
)
5587 return m_mainWin
? m_mainWin
->wxWindow::SetCursor(cursor
) : false;
5590 wxColour
wxGenericListCtrl::GetBackgroundColour() const
5592 return m_mainWin
? m_mainWin
->GetBackgroundColour() : wxColour();
5595 wxColour
wxGenericListCtrl::GetForegroundColour() const
5597 return m_mainWin
? m_mainWin
->GetForegroundColour() : wxColour();
5600 bool wxGenericListCtrl::DoPopupMenu( wxMenu
*menu
, int x
, int y
)
5603 return m_mainWin
->PopupMenu( menu
, x
, y
);
5609 void wxGenericListCtrl::DoClientToScreen( int *x
, int *y
) const
5611 m_mainWin
->DoClientToScreen(x
, y
);
5614 void wxGenericListCtrl::DoScreenToClient( int *x
, int *y
) const
5616 m_mainWin
->DoScreenToClient(x
, y
);
5619 void wxGenericListCtrl::SetFocus()
5621 // The test in window.cpp fails as we are a composite
5622 // window, so it checks against "this", but not m_mainWin.
5623 if ( DoFindFocus() != this )
5624 m_mainWin
->SetFocus();
5627 wxSize
wxGenericListCtrl::DoGetBestSize() const
5629 // Something is better than nothing...
5630 // 100x80 is what the MSW version will get from the default
5631 // wxControl::DoGetBestSize
5632 return wxSize(100, 80);
5635 // ----------------------------------------------------------------------------
5636 // virtual list control support
5637 // ----------------------------------------------------------------------------
5639 wxString
wxGenericListCtrl::OnGetItemText(long WXUNUSED(item
), long WXUNUSED(col
)) const
5641 // this is a pure virtual function, in fact - which is not really pure
5642 // because the controls which are not virtual don't need to implement it
5643 wxFAIL_MSG( _T("wxGenericListCtrl::OnGetItemText not supposed to be called") );
5645 return wxEmptyString
;
5648 int wxGenericListCtrl::OnGetItemImage(long WXUNUSED(item
)) const
5650 wxCHECK_MSG(!GetImageList(wxIMAGE_LIST_SMALL
),
5652 wxT("List control has an image list, OnGetItemImage or OnGetItemColumnImage should be overridden."));
5656 int wxGenericListCtrl::OnGetItemColumnImage(long item
, long column
) const
5659 return OnGetItemImage(item
);
5665 wxGenericListCtrl::OnGetItemAttr(long WXUNUSED_UNLESS_DEBUG(item
)) const
5667 wxASSERT_MSG( item
>= 0 && item
< GetItemCount(),
5668 _T("invalid item index in OnGetItemAttr()") );
5670 // no attributes by default
5674 void wxGenericListCtrl::SetItemCount(long count
)
5676 wxASSERT_MSG( IsVirtual(), _T("this is for virtual controls only") );
5678 m_mainWin
->SetItemCount(count
);
5681 void wxGenericListCtrl::RefreshItem(long item
)
5683 m_mainWin
->RefreshLine(item
);
5686 void wxGenericListCtrl::RefreshItems(long itemFrom
, long itemTo
)
5688 m_mainWin
->RefreshLines(itemFrom
, itemTo
);
5691 // Generic wxListCtrl is more or less a container for two other
5692 // windows which drawings are done upon. These are namely
5693 // 'm_headerWin' and 'm_mainWin'.
5694 // Here we override 'virtual wxWindow::Refresh()' to mimic the
5695 // behaviour wxListCtrl has under wxMSW.
5697 void wxGenericListCtrl::Refresh(bool eraseBackground
, const wxRect
*rect
)
5701 // The easy case, no rectangle specified.
5703 m_headerWin
->Refresh(eraseBackground
);
5706 m_mainWin
->Refresh(eraseBackground
);
5710 // Refresh the header window
5713 wxRect rectHeader
= m_headerWin
->GetRect();
5714 rectHeader
.Intersect(*rect
);
5715 if (rectHeader
.GetWidth() && rectHeader
.GetHeight())
5718 m_headerWin
->GetPosition(&x
, &y
);
5719 rectHeader
.Offset(-x
, -y
);
5720 m_headerWin
->Refresh(eraseBackground
, &rectHeader
);
5724 // Refresh the main window
5727 wxRect rectMain
= m_mainWin
->GetRect();
5728 rectMain
.Intersect(*rect
);
5729 if (rectMain
.GetWidth() && rectMain
.GetHeight())
5732 m_mainWin
->GetPosition(&x
, &y
);
5733 rectMain
.Offset(-x
, -y
);
5734 m_mainWin
->Refresh(eraseBackground
, &rectMain
);
5740 void wxGenericListCtrl::Freeze()
5742 m_mainWin
->Freeze();
5745 void wxGenericListCtrl::Thaw()
5750 #endif // wxUSE_LISTCTRL