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() );
2845 le
.m_itemIndex
= line
;
2847 // set only for events which have position
2848 if ( point
!= wxDefaultPosition
)
2849 le
.m_pointDrag
= point
;
2851 // don't try to get the line info for virtual list controls: the main
2852 // program has it anyhow and if we did it would result in accessing all
2853 // the lines, even those which are not visible now and this is precisely
2854 // what we're trying to avoid
2855 if ( !IsVirtual() && (command
!= wxEVT_COMMAND_LIST_DELETE_ITEM
) )
2857 if ( line
!= (size_t)-1 )
2859 GetLine(line
)->GetItem( 0, le
.m_item
);
2861 //else: this happens for wxEVT_COMMAND_LIST_ITEM_FOCUSED event
2863 //else: there may be no more such item
2865 GetParent()->GetEventHandler()->ProcessEvent( le
);
2868 void wxListMainWindow::ChangeCurrent(size_t current
)
2870 m_current
= current
;
2872 SendNotify(current
, wxEVT_COMMAND_LIST_ITEM_FOCUSED
);
2875 wxTextCtrl
*wxListMainWindow::EditLabel(long item
, wxClassInfo
* textControlClass
)
2877 wxCHECK_MSG( (item
>= 0) && ((size_t)item
< GetItemCount()), NULL
,
2878 wxT("wrong index in wxGenericListCtrl::EditLabel()") );
2880 wxASSERT_MSG( textControlClass
->IsKindOf(CLASSINFO(wxTextCtrl
)),
2881 wxT("EditLabel() needs a text control") );
2883 size_t itemEdit
= (size_t)item
;
2885 wxListEvent
le( wxEVT_COMMAND_LIST_BEGIN_LABEL_EDIT
, GetParent()->GetId() );
2886 le
.SetEventObject( GetParent() );
2887 le
.m_itemIndex
= item
;
2888 wxListLineData
*data
= GetLine(itemEdit
);
2889 wxCHECK_MSG( data
, NULL
, _T("invalid index in EditLabel()") );
2890 data
->GetItem( 0, le
.m_item
);
2892 if ( GetParent()->GetEventHandler()->ProcessEvent( le
) && !le
.IsAllowed() )
2894 // vetoed by user code
2898 // We have to call this here because the label in question might just have
2899 // been added and no screen update taken place.
2903 wxTextCtrl
* const text
= (wxTextCtrl
*)textControlClass
->CreateObject();
2904 m_textctrlWrapper
= new wxListTextCtrlWrapper(this, text
, item
);
2905 return m_textctrlWrapper
->GetText();
2908 void wxListMainWindow::OnRenameTimer()
2910 wxCHECK_RET( HasCurrent(), wxT("unexpected rename timer") );
2912 EditLabel( m_current
);
2915 bool wxListMainWindow::OnRenameAccept(size_t itemEdit
, const wxString
& value
)
2917 wxListEvent
le( wxEVT_COMMAND_LIST_END_LABEL_EDIT
, GetParent()->GetId() );
2918 le
.SetEventObject( GetParent() );
2919 le
.m_itemIndex
= itemEdit
;
2921 wxListLineData
*data
= GetLine(itemEdit
);
2923 wxCHECK_MSG( data
, false, _T("invalid index in OnRenameAccept()") );
2925 data
->GetItem( 0, le
.m_item
);
2926 le
.m_item
.m_text
= value
;
2927 return !GetParent()->GetEventHandler()->ProcessEvent( le
) ||
2931 void wxListMainWindow::OnRenameCancelled(size_t itemEdit
)
2933 // let owner know that the edit was cancelled
2934 wxListEvent
le( wxEVT_COMMAND_LIST_END_LABEL_EDIT
, GetParent()->GetId() );
2936 le
.SetEditCanceled(true);
2938 le
.SetEventObject( GetParent() );
2939 le
.m_itemIndex
= itemEdit
;
2941 wxListLineData
*data
= GetLine(itemEdit
);
2942 wxCHECK_RET( data
, _T("invalid index in OnRenameCancelled()") );
2944 data
->GetItem( 0, le
.m_item
);
2945 GetEventHandler()->ProcessEvent( le
);
2948 void wxListMainWindow::OnMouse( wxMouseEvent
&event
)
2952 // On wxMac we can't depend on the EVT_KILL_FOCUS event to properly
2953 // shutdown the edit control when the mouse is clicked elsewhere on the
2954 // listctrl because the order of events is different (or something like
2955 // that), so explicitly end the edit if it is active.
2956 if ( event
.LeftDown() && m_textctrlWrapper
)
2957 m_textctrlWrapper
->AcceptChangesAndFinish();
2960 event
.SetEventObject( GetParent() );
2961 if ( GetParent()->GetEventHandler()->ProcessEvent( event
) )
2964 if (event
.GetEventType() == wxEVT_MOUSEWHEEL
)
2966 // let the base handle mouse wheel events.
2971 if ( !HasCurrent() || IsEmpty() )
2973 if (event
.RightDown())
2975 SendNotify( (size_t)-1, wxEVT_COMMAND_LIST_ITEM_RIGHT_CLICK
, event
.GetPosition() );
2976 // Allow generation of context menu event
2985 if ( !(event
.Dragging() || event
.ButtonDown() || event
.LeftUp() ||
2986 event
.ButtonDClick()) )
2989 int x
= event
.GetX();
2990 int y
= event
.GetY();
2991 CalcUnscrolledPosition( x
, y
, &x
, &y
);
2993 // where did we hit it (if we did)?
2996 size_t count
= GetItemCount(),
2999 if ( InReportView() )
3001 current
= y
/ GetLineHeight();
3002 if ( current
< count
)
3003 hitResult
= HitTestLine(current
, x
, y
);
3007 // TODO: optimize it too! this is less simple than for report view but
3008 // enumerating all items is still not a way to do it!!
3009 for ( current
= 0; current
< count
; current
++ )
3011 hitResult
= HitTestLine(current
, x
, y
);
3017 if (event
.Dragging())
3019 if (m_dragCount
== 0)
3021 // we have to report the raw, physical coords as we want to be
3022 // able to call HitTest(event.m_pointDrag) from the user code to
3023 // get the item being dragged
3024 m_dragStart
= event
.GetPosition();
3029 if (m_dragCount
!= 3)
3032 int command
= event
.RightIsDown() ? wxEVT_COMMAND_LIST_BEGIN_RDRAG
3033 : wxEVT_COMMAND_LIST_BEGIN_DRAG
;
3035 wxListEvent
le( command
, GetParent()->GetId() );
3036 le
.SetEventObject( GetParent() );
3037 le
.m_itemIndex
= m_lineLastClicked
;
3038 le
.m_pointDrag
= m_dragStart
;
3039 GetParent()->GetEventHandler()->ProcessEvent( le
);
3050 // outside of any item
3051 if (event
.RightDown())
3053 SendNotify( (size_t) -1, wxEVT_COMMAND_LIST_ITEM_RIGHT_CLICK
, event
.GetPosition() );
3054 // Allow generation of context menu event
3059 // reset the selection and bail out
3060 HighlightAll(false);
3066 bool forceClick
= false;
3067 if (event
.ButtonDClick())
3069 m_renameTimer
->Stop();
3070 m_lastOnSame
= false;
3072 if ( current
== m_lineLastClicked
)
3074 SendNotify( current
, wxEVT_COMMAND_LIST_ITEM_ACTIVATED
);
3080 // The first click was on another item, so don't interpret this as
3081 // a double click, but as a simple click instead
3088 if (m_lineSelectSingleOnUp
!= (size_t)-1)
3090 // select single line
3091 HighlightAll( false );
3092 ReverseHighlight(m_lineSelectSingleOnUp
);
3097 if ((current
== m_current
) &&
3098 (hitResult
== wxLIST_HITTEST_ONITEMLABEL
) &&
3099 HasFlag(wxLC_EDIT_LABELS
) )
3101 m_renameTimer
->Start( 100, true );
3105 m_lastOnSame
= false;
3106 m_lineSelectSingleOnUp
= (size_t)-1;
3110 // This is necessary, because after a DnD operation in
3111 // from and to ourself, the up event is swallowed by the
3112 // DnD code. So on next non-up event (which means here and
3113 // now) m_lineSelectSingleOnUp should be reset.
3114 m_lineSelectSingleOnUp
= (size_t)-1;
3116 if (event
.RightDown())
3118 m_lineBeforeLastClicked
= m_lineLastClicked
;
3119 m_lineLastClicked
= current
;
3121 // If the item is already selected, do not update the selection.
3122 // Multi-selections should not be cleared if a selected item is clicked.
3123 if (!IsHighlighted(current
))
3125 HighlightAll(false);
3126 ChangeCurrent(current
);
3127 ReverseHighlight(m_current
);
3130 SendNotify( current
, wxEVT_COMMAND_LIST_ITEM_RIGHT_CLICK
, event
.GetPosition() );
3132 // Allow generation of context menu event
3135 else if (event
.MiddleDown())
3137 SendNotify( current
, wxEVT_COMMAND_LIST_ITEM_MIDDLE_CLICK
);
3139 else if ( event
.LeftDown() || forceClick
)
3141 m_lineBeforeLastClicked
= m_lineLastClicked
;
3142 m_lineLastClicked
= current
;
3144 size_t oldCurrent
= m_current
;
3145 bool oldWasSelected
= IsHighlighted(m_current
);
3147 bool cmdModifierDown
= event
.CmdDown();
3148 if ( IsSingleSel() || !(cmdModifierDown
|| event
.ShiftDown()) )
3150 if ( IsSingleSel() || !IsHighlighted(current
) )
3152 HighlightAll( false );
3154 ChangeCurrent(current
);
3156 ReverseHighlight(m_current
);
3158 else // multi sel & current is highlighted & no mod keys
3160 m_lineSelectSingleOnUp
= current
;
3161 ChangeCurrent(current
); // change focus
3164 else // multi sel & either ctrl or shift is down
3166 if (cmdModifierDown
)
3168 ChangeCurrent(current
);
3170 ReverseHighlight(m_current
);
3172 else if (event
.ShiftDown())
3174 ChangeCurrent(current
);
3176 size_t lineFrom
= oldCurrent
,
3179 if ( lineTo
< lineFrom
)
3182 lineFrom
= m_current
;
3185 HighlightLines(lineFrom
, lineTo
);
3187 else // !ctrl, !shift
3189 // test in the enclosing if should make it impossible
3190 wxFAIL_MSG( _T("how did we get here?") );
3194 if (m_current
!= oldCurrent
)
3195 RefreshLine( oldCurrent
);
3197 // forceClick is only set if the previous click was on another item
3198 m_lastOnSame
= !forceClick
&& (m_current
== oldCurrent
) && oldWasSelected
;
3202 void wxListMainWindow::MoveToItem(size_t item
)
3204 if ( item
== (size_t)-1 )
3207 wxRect rect
= GetLineRect(item
);
3209 int client_w
, client_h
;
3210 GetClientSize( &client_w
, &client_h
);
3212 const int hLine
= GetLineHeight();
3214 int view_x
= SCROLL_UNIT_X
* GetScrollPos( wxHORIZONTAL
);
3215 int view_y
= hLine
* GetScrollPos( wxVERTICAL
);
3217 if ( InReportView() )
3219 // the next we need the range of lines shown it might be different,
3220 // so recalculate it
3221 ResetVisibleLinesRange();
3223 if (rect
.y
< view_y
)
3224 Scroll( -1, rect
.y
/ hLine
);
3225 if (rect
.y
+ rect
.height
+ 5 > view_y
+ client_h
)
3226 Scroll( -1, (rect
.y
+ rect
.height
- client_h
+ hLine
) / hLine
);
3230 if (rect
.x
-view_x
< 5)
3231 Scroll( (rect
.x
- 5) / SCROLL_UNIT_X
, -1 );
3232 if (rect
.x
+ rect
.width
- 5 > view_x
+ client_w
)
3233 Scroll( (rect
.x
+ rect
.width
- client_w
+ SCROLL_UNIT_X
) / SCROLL_UNIT_X
, -1 );
3237 // ----------------------------------------------------------------------------
3238 // keyboard handling
3239 // ----------------------------------------------------------------------------
3241 void wxListMainWindow::OnArrowChar(size_t newCurrent
, const wxKeyEvent
& event
)
3243 wxCHECK_RET( newCurrent
< (size_t)GetItemCount(),
3244 _T("invalid item index in OnArrowChar()") );
3246 size_t oldCurrent
= m_current
;
3248 // in single selection we just ignore Shift as we can't select several
3250 if ( event
.ShiftDown() && !IsSingleSel() )
3252 ChangeCurrent(newCurrent
);
3254 // refresh the old focus to remove it
3255 RefreshLine( oldCurrent
);
3257 // select all the items between the old and the new one
3258 if ( oldCurrent
> newCurrent
)
3260 newCurrent
= oldCurrent
;
3261 oldCurrent
= m_current
;
3264 HighlightLines(oldCurrent
, newCurrent
);
3268 // all previously selected items are unselected unless ctrl is held
3269 if ( !event
.ControlDown() )
3270 HighlightAll(false);
3272 ChangeCurrent(newCurrent
);
3274 // refresh the old focus to remove it
3275 RefreshLine( oldCurrent
);
3277 if ( !event
.ControlDown() )
3279 HighlightLine( m_current
, true );
3283 RefreshLine( m_current
);
3288 void wxListMainWindow::OnKeyDown( wxKeyEvent
&event
)
3290 wxWindow
*parent
= GetParent();
3292 // propagate the key event upwards
3293 wxKeyEvent
ke( wxEVT_KEY_DOWN
);
3294 ke
.m_shiftDown
= event
.m_shiftDown
;
3295 ke
.m_controlDown
= event
.m_controlDown
;
3296 ke
.m_altDown
= event
.m_altDown
;
3297 ke
.m_metaDown
= event
.m_metaDown
;
3298 ke
.m_keyCode
= event
.m_keyCode
;
3301 ke
.SetEventObject( parent
);
3302 if (parent
->GetEventHandler()->ProcessEvent( ke
)) return;
3307 void wxListMainWindow::OnChar( wxKeyEvent
&event
)
3309 wxWindow
*parent
= GetParent();
3311 // send a list_key event up
3314 wxListEvent
le( wxEVT_COMMAND_LIST_KEY_DOWN
, GetParent()->GetId() );
3315 le
.m_itemIndex
= m_current
;
3316 GetLine(m_current
)->GetItem( 0, le
.m_item
);
3317 le
.m_code
= event
.GetKeyCode();
3318 le
.SetEventObject( parent
);
3319 parent
->GetEventHandler()->ProcessEvent( le
);
3322 // propagate the char event upwards
3323 wxKeyEvent
ke( wxEVT_CHAR
);
3324 ke
.m_shiftDown
= event
.m_shiftDown
;
3325 ke
.m_controlDown
= event
.m_controlDown
;
3326 ke
.m_altDown
= event
.m_altDown
;
3327 ke
.m_metaDown
= event
.m_metaDown
;
3328 ke
.m_keyCode
= event
.m_keyCode
;
3331 ke
.SetEventObject( parent
);
3332 if (parent
->GetEventHandler()->ProcessEvent( ke
)) return;
3334 if (event
.GetKeyCode() == WXK_TAB
)
3336 wxNavigationKeyEvent nevent
;
3337 nevent
.SetWindowChange( event
.ControlDown() );
3338 nevent
.SetDirection( !event
.ShiftDown() );
3339 nevent
.SetEventObject( GetParent()->GetParent() );
3340 nevent
.SetCurrentFocus( m_parent
);
3341 if (GetParent()->GetParent()->GetEventHandler()->ProcessEvent( nevent
))
3345 // no item -> nothing to do
3352 // don't use m_linesPerPage directly as it might not be computed yet
3353 const int pageSize
= GetCountPerPage();
3354 wxCHECK_RET( pageSize
, _T("should have non zero page size") );
3356 if (GetLayoutDirection() == wxLayout_RightToLeft
)
3358 if (event
.GetKeyCode() == WXK_RIGHT
)
3359 event
.m_keyCode
= WXK_LEFT
;
3360 else if (event
.GetKeyCode() == WXK_LEFT
)
3361 event
.m_keyCode
= WXK_RIGHT
;
3364 switch ( event
.GetKeyCode() )
3367 if ( m_current
> 0 )
3368 OnArrowChar( m_current
- 1, event
);
3372 if ( m_current
< (size_t)GetItemCount() - 1 )
3373 OnArrowChar( m_current
+ 1, event
);
3378 OnArrowChar( GetItemCount() - 1, event
);
3383 OnArrowChar( 0, event
);
3388 int steps
= InReportView() ? pageSize
- 1
3389 : m_current
% pageSize
;
3391 int index
= m_current
- steps
;
3395 OnArrowChar( index
, event
);
3401 int steps
= InReportView()
3403 : pageSize
- (m_current
% pageSize
) - 1;
3405 size_t index
= m_current
+ steps
;
3406 size_t count
= GetItemCount();
3407 if ( index
>= count
)
3410 OnArrowChar( index
, event
);
3415 if ( !InReportView() )
3417 int index
= m_current
- pageSize
;
3421 OnArrowChar( index
, event
);
3426 if ( !InReportView() )
3428 size_t index
= m_current
+ pageSize
;
3430 size_t count
= GetItemCount();
3431 if ( index
>= count
)
3434 OnArrowChar( index
, event
);
3439 if ( IsSingleSel() )
3441 SendNotify( m_current
, wxEVT_COMMAND_LIST_ITEM_ACTIVATED
);
3443 if ( IsHighlighted(m_current
) )
3445 // don't unselect the item in single selection mode
3448 //else: select it in ReverseHighlight() below if unselected
3451 ReverseHighlight(m_current
);
3456 SendNotify( m_current
, wxEVT_COMMAND_LIST_ITEM_ACTIVATED
);
3464 // ----------------------------------------------------------------------------
3466 // ----------------------------------------------------------------------------
3468 void wxListMainWindow::OnSetFocus( wxFocusEvent
&WXUNUSED(event
) )
3472 wxFocusEvent
event( wxEVT_SET_FOCUS
, GetParent()->GetId() );
3473 event
.SetEventObject( GetParent() );
3474 if ( GetParent()->GetEventHandler()->ProcessEvent( event
) )
3478 // wxGTK sends us EVT_SET_FOCUS events even if we had never got
3479 // EVT_KILL_FOCUS before which means that we finish by redrawing the items
3480 // which are already drawn correctly resulting in horrible flicker - avoid
3490 void wxListMainWindow::OnKillFocus( wxFocusEvent
&WXUNUSED(event
) )
3494 wxFocusEvent
event( wxEVT_KILL_FOCUS
, GetParent()->GetId() );
3495 event
.SetEventObject( GetParent() );
3496 if ( GetParent()->GetEventHandler()->ProcessEvent( event
) )
3504 void wxListMainWindow::DrawImage( int index
, wxDC
*dc
, int x
, int y
)
3506 if ( HasFlag(wxLC_ICON
) && (m_normal_image_list
))
3508 m_normal_image_list
->Draw( index
, *dc
, x
, y
, wxIMAGELIST_DRAW_TRANSPARENT
);
3510 else if ( HasFlag(wxLC_SMALL_ICON
) && (m_small_image_list
))
3512 m_small_image_list
->Draw( index
, *dc
, x
, y
, wxIMAGELIST_DRAW_TRANSPARENT
);
3514 else if ( HasFlag(wxLC_LIST
) && (m_small_image_list
))
3516 m_small_image_list
->Draw( index
, *dc
, x
, y
, wxIMAGELIST_DRAW_TRANSPARENT
);
3518 else if ( InReportView() && (m_small_image_list
))
3520 m_small_image_list
->Draw( index
, *dc
, x
, y
, wxIMAGELIST_DRAW_TRANSPARENT
);
3524 void wxListMainWindow::GetImageSize( int index
, int &width
, int &height
) const
3526 if ( HasFlag(wxLC_ICON
) && m_normal_image_list
)
3528 m_normal_image_list
->GetSize( index
, width
, height
);
3530 else if ( HasFlag(wxLC_SMALL_ICON
) && m_small_image_list
)
3532 m_small_image_list
->GetSize( index
, width
, height
);
3534 else if ( HasFlag(wxLC_LIST
) && m_small_image_list
)
3536 m_small_image_list
->GetSize( index
, width
, height
);
3538 else if ( InReportView() && m_small_image_list
)
3540 m_small_image_list
->GetSize( index
, width
, height
);
3549 int wxListMainWindow::GetTextLength( const wxString
&s
) const
3551 wxClientDC
dc( wxConstCast(this, wxListMainWindow
) );
3552 dc
.SetFont( GetFont() );
3555 dc
.GetTextExtent( s
, &lw
, NULL
);
3557 return lw
+ AUTOSIZE_COL_MARGIN
;
3560 void wxListMainWindow::SetImageList( wxImageList
*imageList
, int which
)
3564 // calc the spacing from the icon size
3565 int width
= 0, height
= 0;
3567 if ((imageList
) && (imageList
->GetImageCount()) )
3568 imageList
->GetSize(0, width
, height
);
3570 if (which
== wxIMAGE_LIST_NORMAL
)
3572 m_normal_image_list
= imageList
;
3573 m_normal_spacing
= width
+ 8;
3576 if (which
== wxIMAGE_LIST_SMALL
)
3578 m_small_image_list
= imageList
;
3579 m_small_spacing
= width
+ 14;
3580 m_lineHeight
= 0; // ensure that the line height will be recalc'd
3584 void wxListMainWindow::SetItemSpacing( int spacing
, bool isSmall
)
3588 m_small_spacing
= spacing
;
3590 m_normal_spacing
= spacing
;
3593 int wxListMainWindow::GetItemSpacing( bool isSmall
)
3595 return isSmall
? m_small_spacing
: m_normal_spacing
;
3598 // ----------------------------------------------------------------------------
3600 // ----------------------------------------------------------------------------
3602 void wxListMainWindow::SetColumn( int col
, wxListItem
&item
)
3604 wxListHeaderDataList::compatibility_iterator node
= m_columns
.Item( col
);
3606 wxCHECK_RET( node
, _T("invalid column index in SetColumn") );
3608 if ( item
.m_width
== wxLIST_AUTOSIZE_USEHEADER
)
3609 item
.m_width
= GetTextLength( item
.m_text
);
3611 wxListHeaderData
*column
= node
->GetData();
3612 column
->SetItem( item
);
3614 wxListHeaderWindow
*headerWin
= GetListCtrl()->m_headerWin
;
3616 headerWin
->m_dirty
= true;
3620 // invalidate it as it has to be recalculated
3624 void wxListMainWindow::SetColumnWidth( int col
, int width
)
3626 wxCHECK_RET( col
>= 0 && col
< GetColumnCount(),
3627 _T("invalid column index") );
3629 wxCHECK_RET( InReportView(),
3630 _T("SetColumnWidth() can only be called in report mode.") );
3633 wxListHeaderWindow
*headerWin
= GetListCtrl()->m_headerWin
;
3635 headerWin
->m_dirty
= true;
3637 wxListHeaderDataList::compatibility_iterator node
= m_columns
.Item( col
);
3638 wxCHECK_RET( node
, _T("no column?") );
3640 wxListHeaderData
*column
= node
->GetData();
3642 size_t count
= GetItemCount();
3644 if (width
== wxLIST_AUTOSIZE_USEHEADER
)
3646 width
= GetTextLength(column
->GetText());
3648 else if ( width
== wxLIST_AUTOSIZE
)
3652 // TODO: determine the max width somehow...
3653 width
= WIDTH_COL_DEFAULT
;
3657 wxClientDC
dc(this);
3658 dc
.SetFont( GetFont() );
3660 int max
= AUTOSIZE_COL_MARGIN
;
3662 // if the cached column width isn't valid then recalculate it
3663 if (m_aColWidths
.Item(col
)->bNeedsUpdate
)
3665 for (size_t i
= 0; i
< count
; i
++)
3667 wxListLineData
*line
= GetLine( i
);
3668 wxListItemDataList::compatibility_iterator n
= line
->m_items
.Item( col
);
3670 wxCHECK_RET( n
, _T("no subitem?") );
3672 wxListItemData
*itemData
= n
->GetData();
3675 itemData
->GetItem(item
);
3676 int itemWidth
= GetItemWidthWithImage(&item
);
3677 if (itemWidth
> max
)
3681 m_aColWidths
.Item(col
)->bNeedsUpdate
= false;
3682 m_aColWidths
.Item(col
)->nMaxWidth
= max
;
3685 max
= m_aColWidths
.Item(col
)->nMaxWidth
;
3686 width
= max
+ AUTOSIZE_COL_MARGIN
;
3690 column
->SetWidth( width
);
3692 // invalidate it as it has to be recalculated
3696 int wxListMainWindow::GetHeaderWidth() const
3698 if ( !m_headerWidth
)
3700 wxListMainWindow
*self
= wxConstCast(this, wxListMainWindow
);
3702 size_t count
= GetColumnCount();
3703 for ( size_t col
= 0; col
< count
; col
++ )
3705 self
->m_headerWidth
+= GetColumnWidth(col
);
3709 return m_headerWidth
;
3712 void wxListMainWindow::GetColumn( int col
, wxListItem
&item
) const
3714 wxListHeaderDataList::compatibility_iterator node
= m_columns
.Item( col
);
3715 wxCHECK_RET( node
, _T("invalid column index in GetColumn") );
3717 wxListHeaderData
*column
= node
->GetData();
3718 column
->GetItem( item
);
3721 int wxListMainWindow::GetColumnWidth( int col
) const
3723 wxListHeaderDataList::compatibility_iterator node
= m_columns
.Item( col
);
3724 wxCHECK_MSG( node
, 0, _T("invalid column index") );
3726 wxListHeaderData
*column
= node
->GetData();
3727 return column
->GetWidth();
3730 // ----------------------------------------------------------------------------
3732 // ----------------------------------------------------------------------------
3734 void wxListMainWindow::SetItem( wxListItem
&item
)
3736 long id
= item
.m_itemId
;
3737 wxCHECK_RET( id
>= 0 && (size_t)id
< GetItemCount(),
3738 _T("invalid item index in SetItem") );
3742 wxListLineData
*line
= GetLine((size_t)id
);
3743 line
->SetItem( item
.m_col
, item
);
3745 // Set item state if user wants
3746 if ( item
.m_mask
& wxLIST_MASK_STATE
)
3747 SetItemState( item
.m_itemId
, item
.m_state
, item
.m_state
);
3751 // update the Max Width Cache if needed
3752 int width
= GetItemWidthWithImage(&item
);
3754 if (width
> m_aColWidths
.Item(item
.m_col
)->nMaxWidth
)
3755 m_aColWidths
.Item(item
.m_col
)->nMaxWidth
= width
;
3759 // update the item on screen
3761 GetItemRect(id
, rectItem
);
3762 RefreshRect(rectItem
);
3765 void wxListMainWindow::SetItemStateAll(long state
, long stateMask
)
3770 // first deal with selection
3771 if ( stateMask
& wxLIST_STATE_SELECTED
)
3773 // set/clear select state
3776 // optimized version for virtual listctrl.
3777 m_selStore
.SelectRange(0, GetItemCount() - 1, state
== wxLIST_STATE_SELECTED
);
3780 else if ( state
& wxLIST_STATE_SELECTED
)
3782 const long count
= GetItemCount();
3783 for( long i
= 0; i
< count
; i
++ )
3785 SetItemState( i
, wxLIST_STATE_SELECTED
, wxLIST_STATE_SELECTED
);
3791 // clear for non virtual (somewhat optimized by using GetNextItem())
3793 while ( (i
= GetNextItem(i
, wxLIST_NEXT_ALL
, wxLIST_STATE_SELECTED
)) != -1 )
3795 SetItemState( i
, 0, wxLIST_STATE_SELECTED
);
3800 if ( HasCurrent() && (state
== 0) && (stateMask
& wxLIST_STATE_FOCUSED
) )
3802 // unfocus all: only one item can be focussed, so clearing focus for
3803 // all items is simply clearing focus of the focussed item.
3804 SetItemState(m_current
, state
, stateMask
);
3806 //(setting focus to all items makes no sense, so it is not handled here.)
3809 void wxListMainWindow::SetItemState( long litem
, long state
, long stateMask
)
3813 SetItemStateAll(state
, stateMask
);
3817 wxCHECK_RET( litem
>= 0 && (size_t)litem
< GetItemCount(),
3818 _T("invalid list ctrl item index in SetItem") );
3820 size_t oldCurrent
= m_current
;
3821 size_t item
= (size_t)litem
; // safe because of the check above
3823 // do we need to change the focus?
3824 if ( stateMask
& wxLIST_STATE_FOCUSED
)
3826 if ( state
& wxLIST_STATE_FOCUSED
)
3828 // don't do anything if this item is already focused
3829 if ( item
!= m_current
)
3831 ChangeCurrent(item
);
3833 if ( oldCurrent
!= (size_t)-1 )
3835 if ( IsSingleSel() )
3837 HighlightLine(oldCurrent
, false);
3840 RefreshLine(oldCurrent
);
3843 RefreshLine( m_current
);
3848 // don't do anything if this item is not focused
3849 if ( item
== m_current
)
3853 if ( IsSingleSel() )
3855 // we must unselect the old current item as well or we
3856 // might end up with more than one selected item in a
3857 // single selection control
3858 HighlightLine(oldCurrent
, false);
3861 RefreshLine( oldCurrent
);
3866 // do we need to change the selection state?
3867 if ( stateMask
& wxLIST_STATE_SELECTED
)
3869 bool on
= (state
& wxLIST_STATE_SELECTED
) != 0;
3871 if ( IsSingleSel() )
3875 // selecting the item also makes it the focused one in the
3877 if ( m_current
!= item
)
3879 ChangeCurrent(item
);
3881 if ( oldCurrent
!= (size_t)-1 )
3883 HighlightLine( oldCurrent
, false );
3884 RefreshLine( oldCurrent
);
3890 // only the current item may be selected anyhow
3891 if ( item
!= m_current
)
3896 if ( HighlightLine(item
, on
) )
3903 int wxListMainWindow::GetItemState( long item
, long stateMask
) const
3905 wxCHECK_MSG( item
>= 0 && (size_t)item
< GetItemCount(), 0,
3906 _T("invalid list ctrl item index in GetItemState()") );
3908 int ret
= wxLIST_STATE_DONTCARE
;
3910 if ( stateMask
& wxLIST_STATE_FOCUSED
)
3912 if ( (size_t)item
== m_current
)
3913 ret
|= wxLIST_STATE_FOCUSED
;
3916 if ( stateMask
& wxLIST_STATE_SELECTED
)
3918 if ( IsHighlighted(item
) )
3919 ret
|= wxLIST_STATE_SELECTED
;
3925 void wxListMainWindow::GetItem( wxListItem
&item
) const
3927 wxCHECK_RET( item
.m_itemId
>= 0 && (size_t)item
.m_itemId
< GetItemCount(),
3928 _T("invalid item index in GetItem") );
3930 wxListLineData
*line
= GetLine((size_t)item
.m_itemId
);
3931 line
->GetItem( item
.m_col
, item
);
3933 // Get item state if user wants it
3934 if ( item
.m_mask
& wxLIST_MASK_STATE
)
3935 item
.m_state
= GetItemState( item
.m_itemId
, wxLIST_STATE_SELECTED
|
3936 wxLIST_STATE_FOCUSED
);
3939 // ----------------------------------------------------------------------------
3941 // ----------------------------------------------------------------------------
3943 size_t wxListMainWindow::GetItemCount() const
3945 return IsVirtual() ? m_countVirt
: m_lines
.GetCount();
3948 void wxListMainWindow::SetItemCount(long count
)
3950 m_selStore
.SetItemCount(count
);
3951 m_countVirt
= count
;
3953 ResetVisibleLinesRange();
3955 // scrollbars must be reset
3959 int wxListMainWindow::GetSelectedItemCount() const
3961 // deal with the quick case first
3962 if ( IsSingleSel() )
3963 return HasCurrent() ? IsHighlighted(m_current
) : false;
3965 // virtual controls remmebers all its selections itself
3967 return m_selStore
.GetSelectedCount();
3969 // TODO: we probably should maintain the number of items selected even for
3970 // non virtual controls as enumerating all lines is really slow...
3971 size_t countSel
= 0;
3972 size_t count
= GetItemCount();
3973 for ( size_t line
= 0; line
< count
; line
++ )
3975 if ( GetLine(line
)->IsHighlighted() )
3982 // ----------------------------------------------------------------------------
3983 // item position/size
3984 // ----------------------------------------------------------------------------
3986 wxRect
wxListMainWindow::GetViewRect() const
3988 wxASSERT_MSG( !HasFlag(wxLC_REPORT
| wxLC_LIST
),
3989 _T("wxListCtrl::GetViewRect() only works in icon mode") );
3991 // we need to find the longest/tallest label
3992 wxCoord xMax
= 0, yMax
= 0;
3993 const int count
= GetItemCount();
3996 for ( int i
= 0; i
< count
; i
++ )
4001 wxCoord x
= r
.GetRight(),
4011 // some fudge needed to make it look prettier
4012 xMax
+= 2 * EXTRA_BORDER_X
;
4013 yMax
+= 2 * EXTRA_BORDER_Y
;
4015 // account for the scrollbars if necessary
4016 const wxSize sizeAll
= GetClientSize();
4017 if ( xMax
> sizeAll
.x
)
4018 yMax
+= wxSystemSettings::GetMetric(wxSYS_HSCROLL_Y
);
4019 if ( yMax
> sizeAll
.y
)
4020 xMax
+= wxSystemSettings::GetMetric(wxSYS_VSCROLL_X
);
4022 return wxRect(0, 0, xMax
, yMax
);
4025 void wxListMainWindow::GetItemRect( long index
, wxRect
&rect
) const
4027 wxCHECK_RET( index
>= 0 && (size_t)index
< GetItemCount(),
4028 _T("invalid index in GetItemRect") );
4030 // ensure that we're laid out, otherwise we could return nonsense
4033 wxConstCast(this, wxListMainWindow
)->
4034 RecalculatePositions(true /* no refresh */);
4037 rect
= GetLineRect((size_t)index
);
4039 CalcScrolledPosition(rect
.x
, rect
.y
, &rect
.x
, &rect
.y
);
4042 bool wxListMainWindow::GetItemPosition(long item
, wxPoint
& pos
) const
4045 GetItemRect(item
, rect
);
4053 // ----------------------------------------------------------------------------
4054 // geometry calculation
4055 // ----------------------------------------------------------------------------
4057 void wxListMainWindow::RecalculatePositions(bool noRefresh
)
4059 const int lineHeight
= GetLineHeight();
4061 wxClientDC
dc( this );
4062 dc
.SetFont( GetFont() );
4064 const size_t count
= GetItemCount();
4067 if ( HasFlag(wxLC_ICON
) )
4068 iconSpacing
= m_normal_spacing
;
4069 else if ( HasFlag(wxLC_SMALL_ICON
) )
4070 iconSpacing
= m_small_spacing
;
4074 // Note that we do not call GetClientSize() here but
4075 // GetSize() and subtract the border size for sunken
4076 // borders manually. This is technically incorrect,
4077 // but we need to know the client area's size WITHOUT
4078 // scrollbars here. Since we don't know if there are
4079 // any scrollbars, we use GetSize() instead. Another
4080 // solution would be to call SetScrollbars() here to
4081 // remove the scrollbars and call GetClientSize() then,
4082 // but this might result in flicker and - worse - will
4083 // reset the scrollbars to 0 which is not good at all
4084 // if you resize a dialog/window, but don't want to
4085 // reset the window scrolling. RR.
4086 // Furthermore, we actually do NOT subtract the border
4087 // width as 2 pixels is just the extra space which we
4088 // need around the actual content in the window. Other-
4089 // wise the text would e.g. touch the upper border. RR.
4092 GetSize( &clientWidth
, &clientHeight
);
4094 if ( InReportView() )
4096 // all lines have the same height and we scroll one line per step
4097 int entireHeight
= count
* lineHeight
+ LINE_SPACING
;
4099 m_linesPerPage
= clientHeight
/ lineHeight
;
4101 ResetVisibleLinesRange();
4103 SetScrollbars( SCROLL_UNIT_X
, lineHeight
,
4104 GetHeaderWidth() / SCROLL_UNIT_X
,
4105 (entireHeight
+ lineHeight
- 1) / lineHeight
,
4106 GetScrollPos(wxHORIZONTAL
),
4107 GetScrollPos(wxVERTICAL
),
4112 // we have 3 different layout strategies: either layout all items
4113 // horizontally/vertically (wxLC_ALIGN_XXX styles explicitly given) or
4114 // to arrange them in top to bottom, left to right (don't ask me why
4115 // not the other way round...) order
4116 if ( HasFlag(wxLC_ALIGN_LEFT
| wxLC_ALIGN_TOP
) )
4118 int x
= EXTRA_BORDER_X
;
4119 int y
= EXTRA_BORDER_Y
;
4121 wxCoord widthMax
= 0;
4124 for ( i
= 0; i
< count
; i
++ )
4126 wxListLineData
*line
= GetLine(i
);
4127 line
->CalculateSize( &dc
, iconSpacing
);
4128 line
->SetPosition( x
, y
, iconSpacing
);
4130 wxSize sizeLine
= GetLineSize(i
);
4132 if ( HasFlag(wxLC_ALIGN_TOP
) )
4134 if ( sizeLine
.x
> widthMax
)
4135 widthMax
= sizeLine
.x
;
4139 else // wxLC_ALIGN_LEFT
4141 x
+= sizeLine
.x
+ MARGIN_BETWEEN_ROWS
;
4145 if ( HasFlag(wxLC_ALIGN_TOP
) )
4147 // traverse the items again and tweak their sizes so that they are
4148 // all the same in a row
4149 for ( i
= 0; i
< count
; i
++ )
4151 wxListLineData
*line
= GetLine(i
);
4152 line
->m_gi
->ExtendWidth(widthMax
);
4160 (x
+ SCROLL_UNIT_X
) / SCROLL_UNIT_X
,
4161 (y
+ lineHeight
) / lineHeight
,
4162 GetScrollPos( wxHORIZONTAL
),
4163 GetScrollPos( wxVERTICAL
),
4167 else // "flowed" arrangement, the most complicated case
4169 // at first we try without any scrollbars, if the items don't fit into
4170 // the window, we recalculate after subtracting the space taken by the
4173 int entireWidth
= 0;
4175 for (int tries
= 0; tries
< 2; tries
++)
4177 entireWidth
= 2 * EXTRA_BORDER_X
;
4181 // Now we have decided that the items do not fit into the
4182 // client area, so we need a scrollbar
4183 entireWidth
+= SCROLL_UNIT_X
;
4186 int x
= EXTRA_BORDER_X
;
4187 int y
= EXTRA_BORDER_Y
;
4188 int maxWidthInThisRow
= 0;
4191 int currentlyVisibleLines
= 0;
4193 for (size_t i
= 0; i
< count
; i
++)
4195 currentlyVisibleLines
++;
4196 wxListLineData
*line
= GetLine( i
);
4197 line
->CalculateSize( &dc
, iconSpacing
);
4198 line
->SetPosition( x
, y
, iconSpacing
);
4200 wxSize sizeLine
= GetLineSize( i
);
4202 if ( maxWidthInThisRow
< sizeLine
.x
)
4203 maxWidthInThisRow
= sizeLine
.x
;
4206 if (currentlyVisibleLines
> m_linesPerPage
)
4207 m_linesPerPage
= currentlyVisibleLines
;
4209 if ( y
+ sizeLine
.y
>= clientHeight
)
4211 currentlyVisibleLines
= 0;
4213 maxWidthInThisRow
+= MARGIN_BETWEEN_ROWS
;
4214 x
+= maxWidthInThisRow
;
4215 entireWidth
+= maxWidthInThisRow
;
4216 maxWidthInThisRow
= 0;
4219 // We have reached the last item.
4220 if ( i
== count
- 1 )
4221 entireWidth
+= maxWidthInThisRow
;
4223 if ( (tries
== 0) &&
4224 (entireWidth
+ SCROLL_UNIT_X
> clientWidth
) )
4226 clientHeight
-= wxSystemSettings::
4227 GetMetric(wxSYS_HSCROLL_Y
);
4232 if ( i
== count
- 1 )
4233 tries
= 1; // Everything fits, no second try required.
4241 (entireWidth
+ SCROLL_UNIT_X
) / SCROLL_UNIT_X
,
4243 GetScrollPos( wxHORIZONTAL
),
4252 // FIXME: why should we call it from here?
4259 void wxListMainWindow::RefreshAll()
4264 wxListHeaderWindow
*headerWin
= GetListCtrl()->m_headerWin
;
4265 if ( headerWin
&& headerWin
->m_dirty
)
4267 headerWin
->m_dirty
= false;
4268 headerWin
->Refresh();
4272 void wxListMainWindow::UpdateCurrent()
4274 if ( !HasCurrent() && !IsEmpty() )
4278 long wxListMainWindow::GetNextItem( long item
,
4279 int WXUNUSED(geometry
),
4283 max
= GetItemCount();
4284 wxCHECK_MSG( (ret
== -1) || (ret
< max
), -1,
4285 _T("invalid listctrl index in GetNextItem()") );
4287 // notice that we start with the next item (or the first one if item == -1)
4288 // and this is intentional to allow writing a simple loop to iterate over
4289 // all selected items
4292 // this is not an error because the index was OK initially,
4293 // just no such item
4300 size_t count
= GetItemCount();
4301 for ( size_t line
= (size_t)ret
; line
< count
; line
++ )
4303 if ( (state
& wxLIST_STATE_FOCUSED
) && (line
== m_current
) )
4306 if ( (state
& wxLIST_STATE_SELECTED
) && IsHighlighted(line
) )
4313 // ----------------------------------------------------------------------------
4315 // ----------------------------------------------------------------------------
4317 void wxListMainWindow::DeleteItem( long lindex
)
4319 size_t count
= GetItemCount();
4321 wxCHECK_RET( (lindex
>= 0) && ((size_t)lindex
< count
),
4322 _T("invalid item index in DeleteItem") );
4324 size_t index
= (size_t)lindex
;
4326 // we don't need to adjust the index for the previous items
4327 if ( HasCurrent() && m_current
>= index
)
4329 // if the current item is being deleted, we want the next one to
4330 // become selected - unless there is no next one - so don't adjust
4331 // m_current in this case
4332 if ( m_current
!= index
|| m_current
== count
- 1 )
4336 if ( InReportView() )
4338 // mark the Column Max Width cache as dirty if the items in the line
4339 // we're deleting contain the Max Column Width
4340 wxListLineData
* const line
= GetLine(index
);
4341 wxListItemDataList::compatibility_iterator n
;
4342 wxListItemData
*itemData
;
4346 for (size_t i
= 0; i
< m_columns
.GetCount(); i
++)
4348 n
= line
->m_items
.Item( i
);
4349 itemData
= n
->GetData();
4350 itemData
->GetItem(item
);
4352 itemWidth
= GetItemWidthWithImage(&item
);
4354 if (itemWidth
>= m_aColWidths
.Item(i
)->nMaxWidth
)
4355 m_aColWidths
.Item(i
)->bNeedsUpdate
= true;
4358 ResetVisibleLinesRange();
4364 m_selStore
.OnItemDelete(index
);
4368 m_lines
.RemoveAt( index
);
4371 // we need to refresh the (vert) scrollbar as the number of items changed
4374 SendNotify( index
, wxEVT_COMMAND_LIST_DELETE_ITEM
);
4376 RefreshAfter(index
);
4379 void wxListMainWindow::DeleteColumn( int col
)
4381 wxListHeaderDataList::compatibility_iterator node
= m_columns
.Item( col
);
4383 wxCHECK_RET( node
, wxT("invalid column index in DeleteColumn()") );
4386 delete node
->GetData();
4387 m_columns
.Erase( node
);
4391 // update all the items
4392 for ( size_t i
= 0; i
< m_lines
.GetCount(); i
++ )
4394 wxListLineData
* const line
= GetLine(i
);
4395 wxListItemDataList::compatibility_iterator n
= line
->m_items
.Item( col
);
4396 delete n
->GetData();
4397 line
->m_items
.Erase(n
);
4401 if ( InReportView() ) // we only cache max widths when in Report View
4403 delete m_aColWidths
.Item(col
);
4404 m_aColWidths
.RemoveAt(col
);
4407 // invalidate it as it has to be recalculated
4411 void wxListMainWindow::DoDeleteAllItems()
4414 // nothing to do - in particular, don't send the event
4419 // to make the deletion of all items faster, we don't send the
4420 // notifications for each item deletion in this case but only one event
4421 // for all of them: this is compatible with wxMSW and documented in
4422 // DeleteAllItems() description
4424 wxListEvent
event( wxEVT_COMMAND_LIST_DELETE_ALL_ITEMS
, GetParent()->GetId() );
4425 event
.SetEventObject( GetParent() );
4426 GetParent()->GetEventHandler()->ProcessEvent( event
);
4434 if ( InReportView() )
4436 ResetVisibleLinesRange();
4437 for (size_t i
= 0; i
< m_aColWidths
.GetCount(); i
++)
4439 m_aColWidths
.Item(i
)->bNeedsUpdate
= true;
4446 void wxListMainWindow::DeleteAllItems()
4450 RecalculatePositions();
4453 void wxListMainWindow::DeleteEverything()
4455 WX_CLEAR_LIST(wxListHeaderDataList
, m_columns
);
4456 WX_CLEAR_ARRAY(m_aColWidths
);
4461 // ----------------------------------------------------------------------------
4462 // scanning for an item
4463 // ----------------------------------------------------------------------------
4465 void wxListMainWindow::EnsureVisible( long index
)
4467 wxCHECK_RET( index
>= 0 && (size_t)index
< GetItemCount(),
4468 _T("invalid index in EnsureVisible") );
4470 // We have to call this here because the label in question might just have
4471 // been added and its position is not known yet
4473 RecalculatePositions(true /* no refresh */);
4475 MoveToItem((size_t)index
);
4478 long wxListMainWindow::FindItem(long start
, const wxString
& str
, bool WXUNUSED(partial
) )
4485 size_t count
= GetItemCount();
4486 for ( size_t i
= (size_t)pos
; i
< count
; i
++ )
4488 wxListLineData
*line
= GetLine(i
);
4489 if ( line
->GetText(0) == tmp
)
4496 long wxListMainWindow::FindItem(long start
, wxUIntPtr data
)
4502 size_t count
= GetItemCount();
4503 for (size_t i
= (size_t)pos
; i
< count
; i
++)
4505 wxListLineData
*line
= GetLine(i
);
4507 line
->GetItem( 0, item
);
4508 if (item
.m_data
== data
)
4515 long wxListMainWindow::FindItem( const wxPoint
& pt
)
4518 GetVisibleLinesRange( &topItem
, NULL
);
4521 GetItemPosition( GetItemCount() - 1, p
);
4525 long id
= (long)floor( pt
.y
* double(GetItemCount() - topItem
- 1) / p
.y
+ topItem
);
4526 if ( id
>= 0 && id
< (long)GetItemCount() )
4532 long wxListMainWindow::HitTest( int x
, int y
, int &flags
) const
4534 CalcUnscrolledPosition( x
, y
, &x
, &y
);
4536 size_t count
= GetItemCount();
4538 if ( InReportView() )
4540 size_t current
= y
/ GetLineHeight();
4541 if ( current
< count
)
4543 flags
= HitTestLine(current
, x
, y
);
4550 // TODO: optimize it too! this is less simple than for report view but
4551 // enumerating all items is still not a way to do it!!
4552 for ( size_t current
= 0; current
< count
; current
++ )
4554 flags
= HitTestLine(current
, x
, y
);
4563 // ----------------------------------------------------------------------------
4565 // ----------------------------------------------------------------------------
4567 void wxListMainWindow::InsertItem( wxListItem
&item
)
4569 wxASSERT_MSG( !IsVirtual(), _T("can't be used with virtual control") );
4571 int count
= GetItemCount();
4572 wxCHECK_RET( item
.m_itemId
>= 0, _T("invalid item index") );
4574 if (item
.m_itemId
> count
)
4575 item
.m_itemId
= count
;
4577 size_t id
= item
.m_itemId
;
4581 if ( InReportView() )
4583 ResetVisibleLinesRange();
4585 // calculate the width of the item and adjust the max column width
4586 wxColWidthInfo
*pWidthInfo
= m_aColWidths
.Item(item
.GetColumn());
4587 int width
= GetItemWidthWithImage(&item
);
4588 item
.SetWidth(width
);
4589 if (width
> pWidthInfo
->nMaxWidth
)
4590 pWidthInfo
->nMaxWidth
= width
;
4593 wxListLineData
*line
= new wxListLineData(this);
4595 line
->SetItem( item
.m_col
, item
);
4597 m_lines
.Insert( line
, id
);
4601 // If an item is selected at or below the point of insertion, we need to
4602 // increment the member variables because the current row's index has gone
4604 if ( HasCurrent() && m_current
>= id
)
4607 SendNotify(id
, wxEVT_COMMAND_LIST_INSERT_ITEM
);
4609 RefreshLines(id
, GetItemCount() - 1);
4612 void wxListMainWindow::InsertColumn( long col
, wxListItem
&item
)
4615 if ( InReportView() )
4617 if (item
.m_width
== wxLIST_AUTOSIZE_USEHEADER
)
4618 item
.m_width
= GetTextLength( item
.m_text
);
4620 wxListHeaderData
*column
= new wxListHeaderData( item
);
4621 wxColWidthInfo
*colWidthInfo
= new wxColWidthInfo();
4623 bool insert
= (col
>= 0) && ((size_t)col
< m_columns
.GetCount());
4626 wxListHeaderDataList::compatibility_iterator
4627 node
= m_columns
.Item( col
);
4628 m_columns
.Insert( node
, column
);
4629 m_aColWidths
.Insert( colWidthInfo
, col
);
4633 m_columns
.Append( column
);
4634 m_aColWidths
.Add( colWidthInfo
);
4639 // update all the items
4640 for ( size_t i
= 0; i
< m_lines
.GetCount(); i
++ )
4642 wxListLineData
* const line
= GetLine(i
);
4643 wxListItemData
* const data
= new wxListItemData(this);
4645 line
->m_items
.Insert(col
, data
);
4647 line
->m_items
.Append(data
);
4651 // invalidate it as it has to be recalculated
4656 int wxListMainWindow::GetItemWidthWithImage(wxListItem
* item
)
4659 wxClientDC
dc(this);
4661 dc
.SetFont( GetFont() );
4663 if (item
->GetImage() != -1)
4666 GetImageSize( item
->GetImage(), ix
, iy
);
4670 if (!item
->GetText().empty())
4673 dc
.GetTextExtent( item
->GetText(), &w
, NULL
);
4680 // ----------------------------------------------------------------------------
4682 // ----------------------------------------------------------------------------
4684 wxListCtrlCompare list_ctrl_compare_func_2
;
4685 long list_ctrl_compare_data
;
4687 int LINKAGEMODE
list_ctrl_compare_func_1( wxListLineData
**arg1
, wxListLineData
**arg2
)
4689 wxListLineData
*line1
= *arg1
;
4690 wxListLineData
*line2
= *arg2
;
4692 line1
->GetItem( 0, item
);
4693 wxUIntPtr data1
= item
.m_data
;
4694 line2
->GetItem( 0, item
);
4695 wxUIntPtr data2
= item
.m_data
;
4696 return list_ctrl_compare_func_2( data1
, data2
, list_ctrl_compare_data
);
4699 void wxListMainWindow::SortItems( wxListCtrlCompare fn
, long data
)
4701 list_ctrl_compare_func_2
= fn
;
4702 list_ctrl_compare_data
= data
;
4703 m_lines
.Sort( list_ctrl_compare_func_1
);
4707 // ----------------------------------------------------------------------------
4709 // ----------------------------------------------------------------------------
4711 void wxListMainWindow::OnScroll(wxScrollWinEvent
& event
)
4713 // update our idea of which lines are shown when we redraw the window the
4715 ResetVisibleLinesRange();
4718 #if ( defined(__WXGTK__) || defined(__WXMAC__) ) && !defined(__WXUNIVERSAL__)
4719 wxScrolledWindow::OnScroll(event
);
4721 HandleOnScroll( event
);
4724 if ( event
.GetOrientation() == wxHORIZONTAL
&& HasHeader() )
4726 wxGenericListCtrl
* lc
= GetListCtrl();
4727 wxCHECK_RET( lc
, _T("no listctrl window?") );
4729 lc
->m_headerWin
->Refresh();
4730 lc
->m_headerWin
->Update();
4734 int wxListMainWindow::GetCountPerPage() const
4736 if ( !m_linesPerPage
)
4738 wxConstCast(this, wxListMainWindow
)->
4739 m_linesPerPage
= GetClientSize().y
/ GetLineHeight();
4742 return m_linesPerPage
;
4745 void wxListMainWindow::GetVisibleLinesRange(size_t *from
, size_t *to
)
4747 wxASSERT_MSG( InReportView(), _T("this is for report mode only") );
4749 if ( m_lineFrom
== (size_t)-1 )
4751 size_t count
= GetItemCount();
4754 m_lineFrom
= GetScrollPos(wxVERTICAL
);
4756 // this may happen if SetScrollbars() hadn't been called yet
4757 if ( m_lineFrom
>= count
)
4758 m_lineFrom
= count
- 1;
4760 // we redraw one extra line but this is needed to make the redrawing
4761 // logic work when there is a fractional number of lines on screen
4762 m_lineTo
= m_lineFrom
+ m_linesPerPage
;
4763 if ( m_lineTo
>= count
)
4764 m_lineTo
= count
- 1;
4766 else // empty control
4769 m_lineTo
= (size_t)-1;
4773 wxASSERT_MSG( IsEmpty() ||
4774 (m_lineFrom
<= m_lineTo
&& m_lineTo
< GetItemCount()),
4775 _T("GetVisibleLinesRange() returns incorrect result") );
4783 // -------------------------------------------------------------------------------------
4784 // wxGenericListCtrl
4785 // -------------------------------------------------------------------------------------
4787 IMPLEMENT_DYNAMIC_CLASS(wxGenericListCtrl
, wxControl
)
4789 BEGIN_EVENT_TABLE(wxGenericListCtrl
,wxControl
)
4790 EVT_SIZE(wxGenericListCtrl::OnSize
)
4793 wxGenericListCtrl::wxGenericListCtrl()
4795 m_imageListNormal
= (wxImageList
*) NULL
;
4796 m_imageListSmall
= (wxImageList
*) NULL
;
4797 m_imageListState
= (wxImageList
*) NULL
;
4799 m_ownsImageListNormal
=
4800 m_ownsImageListSmall
=
4801 m_ownsImageListState
= false;
4803 m_mainWin
= (wxListMainWindow
*) NULL
;
4804 m_headerWin
= (wxListHeaderWindow
*) NULL
;
4808 wxGenericListCtrl::~wxGenericListCtrl()
4810 if (m_ownsImageListNormal
)
4811 delete m_imageListNormal
;
4812 if (m_ownsImageListSmall
)
4813 delete m_imageListSmall
;
4814 if (m_ownsImageListState
)
4815 delete m_imageListState
;
4818 void wxGenericListCtrl::CalculateAndSetHeaderHeight()
4824 GetThemeMetric( kThemeMetricListHeaderHeight
, &h
);
4826 // we use 'g' to get the descent, too
4828 m_headerWin
->GetTextExtent(wxT("Hg"), &w
, &h
, &d
);
4829 h
+= d
+ 2 * HEADER_OFFSET_Y
+ EXTRA_HEIGHT
;
4832 // only update if changed
4833 if ( h
!= m_headerHeight
)
4838 ResizeReportView(true);
4839 else //why is this needed if it doesn't have a header?
4840 m_headerWin
->SetSize(m_headerWin
->GetSize().x
, m_headerHeight
);
4845 void wxGenericListCtrl::CreateHeaderWindow()
4847 m_headerWin
= new wxListHeaderWindow
4849 this, wxID_ANY
, m_mainWin
,
4851 wxSize(GetClientSize().x
, m_headerHeight
),
4854 CalculateAndSetHeaderHeight();
4857 bool wxGenericListCtrl::Create(wxWindow
*parent
,
4862 const wxValidator
&validator
,
4863 const wxString
&name
)
4867 m_imageListState
= (wxImageList
*) NULL
;
4868 m_ownsImageListNormal
=
4869 m_ownsImageListSmall
=
4870 m_ownsImageListState
= false;
4872 m_mainWin
= (wxListMainWindow
*) NULL
;
4873 m_headerWin
= (wxListHeaderWindow
*) NULL
;
4877 if ( !(style
& wxLC_MASK_TYPE
) )
4879 style
= style
| wxLC_LIST
;
4882 if ( !wxControl::Create( parent
, id
, pos
, size
, style
, validator
, name
) )
4885 // don't create the inner window with the border
4886 style
&= ~wxBORDER_MASK
;
4888 m_mainWin
= new wxListMainWindow( this, wxID_ANY
, wxPoint(0, 0), size
, style
);
4890 #ifdef __WXMAC_CARBON__
4891 // Human Interface Guidelines ask us for a special font in this case
4892 if ( GetWindowVariant() == wxWINDOW_VARIANT_NORMAL
)
4895 font
.MacCreateThemeFont( kThemeViewsFont
);
4900 if ( InReportView() )
4902 CreateHeaderWindow();
4904 #ifdef __WXMAC_CARBON__
4908 font
.MacCreateThemeFont( kThemeSmallSystemFont
);
4909 m_headerWin
->SetFont( font
);
4910 CalculateAndSetHeaderHeight();
4914 if ( HasFlag(wxLC_NO_HEADER
) )
4915 // VZ: why do we create it at all then?
4916 m_headerWin
->Show( false );
4919 SetInitialSize(size
);
4924 void wxGenericListCtrl::SetSingleStyle( long style
, bool add
)
4926 wxASSERT_MSG( !(style
& wxLC_VIRTUAL
),
4927 _T("wxLC_VIRTUAL can't be [un]set") );
4929 long flag
= GetWindowStyle();
4933 if (style
& wxLC_MASK_TYPE
)
4934 flag
&= ~(wxLC_MASK_TYPE
| wxLC_VIRTUAL
);
4935 if (style
& wxLC_MASK_ALIGN
)
4936 flag
&= ~wxLC_MASK_ALIGN
;
4937 if (style
& wxLC_MASK_SORT
)
4938 flag
&= ~wxLC_MASK_SORT
;
4946 SetWindowStyleFlag( flag
);
4949 void wxGenericListCtrl::SetWindowStyleFlag( long flag
)
4953 m_mainWin
->DeleteEverything();
4955 // has the header visibility changed?
4956 bool hasHeader
= HasHeader();
4957 bool willHaveHeader
= (flag
& wxLC_REPORT
) && !(flag
& wxLC_NO_HEADER
);
4959 if ( hasHeader
!= willHaveHeader
)
4966 // don't delete, just hide, as we can reuse it later
4967 m_headerWin
->Show(false);
4969 //else: nothing to do
4971 else // must show header
4975 CreateHeaderWindow();
4977 else // already have it, just show
4979 m_headerWin
->Show( true );
4983 ResizeReportView(willHaveHeader
);
4987 wxWindow::SetWindowStyleFlag( flag
);
4990 bool wxGenericListCtrl::GetColumn(int col
, wxListItem
&item
) const
4992 m_mainWin
->GetColumn( col
, item
);
4996 bool wxGenericListCtrl::SetColumn( int col
, wxListItem
& item
)
4998 m_mainWin
->SetColumn( col
, item
);
5002 int wxGenericListCtrl::GetColumnWidth( int col
) const
5004 return m_mainWin
->GetColumnWidth( col
);
5007 bool wxGenericListCtrl::SetColumnWidth( int col
, int width
)
5009 m_mainWin
->SetColumnWidth( col
, width
);
5013 int wxGenericListCtrl::GetCountPerPage() const
5015 return m_mainWin
->GetCountPerPage(); // different from Windows ?
5018 bool wxGenericListCtrl::GetItem( wxListItem
&info
) const
5020 m_mainWin
->GetItem( info
);
5024 bool wxGenericListCtrl::SetItem( wxListItem
&info
)
5026 m_mainWin
->SetItem( info
);
5030 long wxGenericListCtrl::SetItem( long index
, int col
, const wxString
& label
, int imageId
)
5033 info
.m_text
= label
;
5034 info
.m_mask
= wxLIST_MASK_TEXT
;
5035 info
.m_itemId
= index
;
5039 info
.m_image
= imageId
;
5040 info
.m_mask
|= wxLIST_MASK_IMAGE
;
5043 m_mainWin
->SetItem(info
);
5047 int wxGenericListCtrl::GetItemState( long item
, long stateMask
) const
5049 return m_mainWin
->GetItemState( item
, stateMask
);
5052 bool wxGenericListCtrl::SetItemState( long item
, long state
, long stateMask
)
5054 m_mainWin
->SetItemState( item
, state
, stateMask
);
5059 wxGenericListCtrl::SetItemImage( long item
, int image
, int WXUNUSED(selImage
) )
5061 return SetItemColumnImage(item
, 0, image
);
5065 wxGenericListCtrl::SetItemColumnImage( long item
, long column
, int image
)
5068 info
.m_image
= image
;
5069 info
.m_mask
= wxLIST_MASK_IMAGE
;
5070 info
.m_itemId
= item
;
5071 info
.m_col
= column
;
5072 m_mainWin
->SetItem( info
);
5076 wxString
wxGenericListCtrl::GetItemText( long item
) const
5078 return m_mainWin
->GetItemText(item
);
5081 void wxGenericListCtrl::SetItemText( long item
, const wxString
& str
)
5083 m_mainWin
->SetItemText(item
, str
);
5086 wxUIntPtr
wxGenericListCtrl::GetItemData( long item
) const
5089 info
.m_mask
= wxLIST_MASK_DATA
;
5090 info
.m_itemId
= item
;
5091 m_mainWin
->GetItem( info
);
5095 bool wxGenericListCtrl::SetItemData( long item
, long data
)
5098 info
.m_mask
= wxLIST_MASK_DATA
;
5099 info
.m_itemId
= item
;
5101 m_mainWin
->SetItem( info
);
5105 wxRect
wxGenericListCtrl::GetViewRect() const
5107 return m_mainWin
->GetViewRect();
5110 bool wxGenericListCtrl::GetItemRect( long item
, wxRect
&rect
, int WXUNUSED(code
) ) const
5112 m_mainWin
->GetItemRect( item
, rect
);
5113 if ( m_mainWin
->HasHeader() )
5114 rect
.y
+= m_headerHeight
+ 1;
5118 bool wxGenericListCtrl::GetItemPosition( long item
, wxPoint
& pos
) const
5120 m_mainWin
->GetItemPosition( item
, pos
);
5124 bool wxGenericListCtrl::SetItemPosition( long WXUNUSED(item
), const wxPoint
& WXUNUSED(pos
) )
5129 int wxGenericListCtrl::GetItemCount() const
5131 return m_mainWin
->GetItemCount();
5134 int wxGenericListCtrl::GetColumnCount() const
5136 return m_mainWin
->GetColumnCount();
5139 void wxGenericListCtrl::SetItemSpacing( int spacing
, bool isSmall
)
5141 m_mainWin
->SetItemSpacing( spacing
, isSmall
);
5144 wxSize
wxGenericListCtrl::GetItemSpacing() const
5146 const int spacing
= m_mainWin
->GetItemSpacing(HasFlag(wxLC_SMALL_ICON
));
5148 return wxSize(spacing
, spacing
);
5151 #if WXWIN_COMPATIBILITY_2_6
5152 int wxGenericListCtrl::GetItemSpacing( bool isSmall
) const
5154 return m_mainWin
->GetItemSpacing( isSmall
);
5156 #endif // WXWIN_COMPATIBILITY_2_6
5158 void wxGenericListCtrl::SetItemTextColour( long item
, const wxColour
&col
)
5161 info
.m_itemId
= item
;
5162 info
.SetTextColour( col
);
5163 m_mainWin
->SetItem( info
);
5166 wxColour
wxGenericListCtrl::GetItemTextColour( long item
) const
5169 info
.m_itemId
= item
;
5170 m_mainWin
->GetItem( info
);
5171 return info
.GetTextColour();
5174 void wxGenericListCtrl::SetItemBackgroundColour( long item
, const wxColour
&col
)
5177 info
.m_itemId
= item
;
5178 info
.SetBackgroundColour( col
);
5179 m_mainWin
->SetItem( info
);
5182 wxColour
wxGenericListCtrl::GetItemBackgroundColour( long item
) const
5185 info
.m_itemId
= item
;
5186 m_mainWin
->GetItem( info
);
5187 return info
.GetBackgroundColour();
5190 void wxGenericListCtrl::SetItemFont( long item
, const wxFont
&f
)
5193 info
.m_itemId
= item
;
5195 m_mainWin
->SetItem( info
);
5198 wxFont
wxGenericListCtrl::GetItemFont( long item
) const
5201 info
.m_itemId
= item
;
5202 m_mainWin
->GetItem( info
);
5203 return info
.GetFont();
5206 int wxGenericListCtrl::GetSelectedItemCount() const
5208 return m_mainWin
->GetSelectedItemCount();
5211 wxColour
wxGenericListCtrl::GetTextColour() const
5213 return GetForegroundColour();
5216 void wxGenericListCtrl::SetTextColour(const wxColour
& col
)
5218 SetForegroundColour(col
);
5221 long wxGenericListCtrl::GetTopItem() const
5224 m_mainWin
->GetVisibleLinesRange(&top
, NULL
);
5228 long wxGenericListCtrl::GetNextItem( long item
, int geom
, int state
) const
5230 return m_mainWin
->GetNextItem( item
, geom
, state
);
5233 wxImageList
*wxGenericListCtrl::GetImageList(int which
) const
5235 if (which
== wxIMAGE_LIST_NORMAL
)
5236 return m_imageListNormal
;
5237 else if (which
== wxIMAGE_LIST_SMALL
)
5238 return m_imageListSmall
;
5239 else if (which
== wxIMAGE_LIST_STATE
)
5240 return m_imageListState
;
5242 return (wxImageList
*) NULL
;
5245 void wxGenericListCtrl::SetImageList( wxImageList
*imageList
, int which
)
5247 if ( which
== wxIMAGE_LIST_NORMAL
)
5249 if (m_ownsImageListNormal
)
5250 delete m_imageListNormal
;
5251 m_imageListNormal
= imageList
;
5252 m_ownsImageListNormal
= false;
5254 else if ( which
== wxIMAGE_LIST_SMALL
)
5256 if (m_ownsImageListSmall
)
5257 delete m_imageListSmall
;
5258 m_imageListSmall
= imageList
;
5259 m_ownsImageListSmall
= false;
5261 else if ( which
== wxIMAGE_LIST_STATE
)
5263 if (m_ownsImageListState
)
5264 delete m_imageListState
;
5265 m_imageListState
= imageList
;
5266 m_ownsImageListState
= false;
5269 m_mainWin
->SetImageList( imageList
, which
);
5272 void wxGenericListCtrl::AssignImageList(wxImageList
*imageList
, int which
)
5274 SetImageList(imageList
, which
);
5275 if ( which
== wxIMAGE_LIST_NORMAL
)
5276 m_ownsImageListNormal
= true;
5277 else if ( which
== wxIMAGE_LIST_SMALL
)
5278 m_ownsImageListSmall
= true;
5279 else if ( which
== wxIMAGE_LIST_STATE
)
5280 m_ownsImageListState
= true;
5283 bool wxGenericListCtrl::Arrange( int WXUNUSED(flag
) )
5288 bool wxGenericListCtrl::DeleteItem( long item
)
5290 m_mainWin
->DeleteItem( item
);
5294 bool wxGenericListCtrl::DeleteAllItems()
5296 m_mainWin
->DeleteAllItems();
5300 bool wxGenericListCtrl::DeleteAllColumns()
5302 size_t count
= m_mainWin
->m_columns
.GetCount();
5303 for ( size_t n
= 0; n
< count
; n
++ )
5308 void wxGenericListCtrl::ClearAll()
5310 m_mainWin
->DeleteEverything();
5313 bool wxGenericListCtrl::DeleteColumn( int col
)
5315 m_mainWin
->DeleteColumn( col
);
5317 // if we don't have the header any longer, we need to relayout the window
5318 if ( !GetColumnCount() )
5319 ResizeReportView(false /* no header */);
5323 wxTextCtrl
*wxGenericListCtrl::EditLabel(long item
,
5324 wxClassInfo
* textControlClass
)
5326 return m_mainWin
->EditLabel( item
, textControlClass
);
5329 wxTextCtrl
*wxGenericListCtrl::GetEditControl() const
5331 return m_mainWin
->GetEditControl();
5334 bool wxGenericListCtrl::EnsureVisible( long item
)
5336 m_mainWin
->EnsureVisible( item
);
5340 long wxGenericListCtrl::FindItem( long start
, const wxString
& str
, bool partial
)
5342 return m_mainWin
->FindItem( start
, str
, partial
);
5345 long wxGenericListCtrl::FindItem( long start
, wxUIntPtr data
)
5347 return m_mainWin
->FindItem( start
, data
);
5350 long wxGenericListCtrl::FindItem( long WXUNUSED(start
), const wxPoint
& pt
,
5351 int WXUNUSED(direction
))
5353 return m_mainWin
->FindItem( pt
);
5356 // TODO: sub item hit testing
5357 long wxGenericListCtrl::HitTest(const wxPoint
& point
, int& flags
, long *) const
5359 return m_mainWin
->HitTest( (int)point
.x
, (int)point
.y
, flags
);
5362 long wxGenericListCtrl::InsertItem( wxListItem
& info
)
5364 m_mainWin
->InsertItem( info
);
5365 return info
.m_itemId
;
5368 long wxGenericListCtrl::InsertItem( long index
, const wxString
&label
)
5371 info
.m_text
= label
;
5372 info
.m_mask
= wxLIST_MASK_TEXT
;
5373 info
.m_itemId
= index
;
5374 return InsertItem( info
);
5377 long wxGenericListCtrl::InsertItem( long index
, int imageIndex
)
5380 info
.m_mask
= wxLIST_MASK_IMAGE
;
5381 info
.m_image
= imageIndex
;
5382 info
.m_itemId
= index
;
5383 return InsertItem( info
);
5386 long wxGenericListCtrl::InsertItem( long index
, const wxString
&label
, int imageIndex
)
5389 info
.m_text
= label
;
5390 info
.m_image
= imageIndex
;
5391 info
.m_mask
= wxLIST_MASK_TEXT
| wxLIST_MASK_IMAGE
;
5392 info
.m_itemId
= index
;
5393 return InsertItem( info
);
5396 long wxGenericListCtrl::InsertColumn( long col
, wxListItem
&item
)
5398 wxCHECK_MSG( m_headerWin
, -1, _T("can't add column in non report mode") );
5400 m_mainWin
->InsertColumn( col
, item
);
5402 // if we hadn't had a header before but have one now
5403 // then we need to relayout the window
5404 if ( GetColumnCount() == 1 && m_mainWin
->HasHeader() )
5405 ResizeReportView(true /* have header */);
5407 m_headerWin
->Refresh();
5412 long wxGenericListCtrl::InsertColumn( long col
, const wxString
&heading
,
5413 int format
, int width
)
5416 item
.m_mask
= wxLIST_MASK_TEXT
| wxLIST_MASK_FORMAT
;
5417 item
.m_text
= heading
;
5420 item
.m_mask
|= wxLIST_MASK_WIDTH
;
5421 item
.m_width
= width
;
5424 item
.m_format
= format
;
5426 return InsertColumn( col
, item
);
5429 bool wxGenericListCtrl::ScrollList( int WXUNUSED(dx
), int WXUNUSED(dy
) )
5435 // fn is a function which takes 3 long arguments: item1, item2, data.
5436 // item1 is the long data associated with a first item (NOT the index).
5437 // item2 is the long data associated with a second item (NOT the index).
5438 // data is the same value as passed to SortItems.
5439 // The return value is a negative number if the first item should precede the second
5440 // item, a positive number of the second item should precede the first,
5441 // or zero if the two items are equivalent.
5442 // data is arbitrary data to be passed to the sort function.
5444 bool wxGenericListCtrl::SortItems( wxListCtrlCompare fn
, long data
)
5446 m_mainWin
->SortItems( fn
, data
);
5450 // ----------------------------------------------------------------------------
5452 // ----------------------------------------------------------------------------
5454 void wxGenericListCtrl::OnSize(wxSizeEvent
& WXUNUSED(event
))
5459 ResizeReportView(m_mainWin
->HasHeader());
5460 m_mainWin
->RecalculatePositions();
5463 void wxGenericListCtrl::ResizeReportView(bool showHeader
)
5466 GetClientSize( &cw
, &ch
);
5470 m_headerWin
->SetSize( 0, 0, cw
, m_headerHeight
);
5471 if(ch
> m_headerHeight
)
5472 m_mainWin
->SetSize( 0, m_headerHeight
+ 1,
5473 cw
, ch
- m_headerHeight
- 1 );
5475 m_mainWin
->SetSize( 0, m_headerHeight
+ 1,
5478 else // no header window
5480 m_mainWin
->SetSize( 0, 0, cw
, ch
);
5484 void wxGenericListCtrl::OnInternalIdle()
5486 wxWindow::OnInternalIdle();
5488 // do it only if needed
5489 if ( !m_mainWin
->m_dirty
)
5492 m_mainWin
->RecalculatePositions();
5495 // ----------------------------------------------------------------------------
5497 // ----------------------------------------------------------------------------
5499 bool wxGenericListCtrl::SetBackgroundColour( const wxColour
&colour
)
5503 m_mainWin
->SetBackgroundColour( colour
);
5504 m_mainWin
->m_dirty
= true;
5510 bool wxGenericListCtrl::SetForegroundColour( const wxColour
&colour
)
5512 if ( !wxWindow::SetForegroundColour( colour
) )
5517 m_mainWin
->SetForegroundColour( colour
);
5518 m_mainWin
->m_dirty
= true;
5522 m_headerWin
->SetForegroundColour( colour
);
5527 bool wxGenericListCtrl::SetFont( const wxFont
&font
)
5529 if ( !wxWindow::SetFont( font
) )
5534 m_mainWin
->SetFont( font
);
5535 m_mainWin
->m_dirty
= true;
5540 m_headerWin
->SetFont( font
);
5541 CalculateAndSetHeaderHeight();
5551 wxGenericListCtrl::GetClassDefaultAttributes(wxWindowVariant variant
)
5554 // Use the same color scheme as wxListBox
5555 return wxListBox::GetClassDefaultAttributes(variant
);
5557 wxUnusedVar(variant
);
5558 wxVisualAttributes attr
;
5559 attr
.colFg
= wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT
);
5560 attr
.colBg
= wxSystemSettings::GetColour(wxSYS_COLOUR_LISTBOX
);
5561 attr
.font
= wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT
);
5566 // ----------------------------------------------------------------------------
5567 // methods forwarded to m_mainWin
5568 // ----------------------------------------------------------------------------
5570 #if wxUSE_DRAG_AND_DROP
5572 void wxGenericListCtrl::SetDropTarget( wxDropTarget
*dropTarget
)
5574 m_mainWin
->SetDropTarget( dropTarget
);
5577 wxDropTarget
*wxGenericListCtrl::GetDropTarget() const
5579 return m_mainWin
->GetDropTarget();
5584 bool wxGenericListCtrl::SetCursor( const wxCursor
&cursor
)
5586 return m_mainWin
? m_mainWin
->wxWindow::SetCursor(cursor
) : false;
5589 wxColour
wxGenericListCtrl::GetBackgroundColour() const
5591 return m_mainWin
? m_mainWin
->GetBackgroundColour() : wxColour();
5594 wxColour
wxGenericListCtrl::GetForegroundColour() const
5596 return m_mainWin
? m_mainWin
->GetForegroundColour() : wxColour();
5599 bool wxGenericListCtrl::DoPopupMenu( wxMenu
*menu
, int x
, int y
)
5602 return m_mainWin
->PopupMenu( menu
, x
, y
);
5608 void wxGenericListCtrl::DoClientToScreen( int *x
, int *y
) const
5610 m_mainWin
->DoClientToScreen(x
, y
);
5613 void wxGenericListCtrl::DoScreenToClient( int *x
, int *y
) const
5615 m_mainWin
->DoScreenToClient(x
, y
);
5618 void wxGenericListCtrl::SetFocus()
5620 // The test in window.cpp fails as we are a composite
5621 // window, so it checks against "this", but not m_mainWin.
5622 if ( DoFindFocus() != this )
5623 m_mainWin
->SetFocus();
5626 wxSize
wxGenericListCtrl::DoGetBestSize() const
5628 // Something is better than nothing...
5629 // 100x80 is what the MSW version will get from the default
5630 // wxControl::DoGetBestSize
5631 return wxSize(100, 80);
5634 // ----------------------------------------------------------------------------
5635 // virtual list control support
5636 // ----------------------------------------------------------------------------
5638 wxString
wxGenericListCtrl::OnGetItemText(long WXUNUSED(item
), long WXUNUSED(col
)) const
5640 // this is a pure virtual function, in fact - which is not really pure
5641 // because the controls which are not virtual don't need to implement it
5642 wxFAIL_MSG( _T("wxGenericListCtrl::OnGetItemText not supposed to be called") );
5644 return wxEmptyString
;
5647 int wxGenericListCtrl::OnGetItemImage(long WXUNUSED(item
)) const
5649 wxCHECK_MSG(!GetImageList(wxIMAGE_LIST_SMALL
),
5651 wxT("List control has an image list, OnGetItemImage or OnGetItemColumnImage should be overridden."));
5655 int wxGenericListCtrl::OnGetItemColumnImage(long item
, long column
) const
5658 return OnGetItemImage(item
);
5664 wxGenericListCtrl::OnGetItemAttr(long WXUNUSED_UNLESS_DEBUG(item
)) const
5666 wxASSERT_MSG( item
>= 0 && item
< GetItemCount(),
5667 _T("invalid item index in OnGetItemAttr()") );
5669 // no attributes by default
5673 void wxGenericListCtrl::SetItemCount(long count
)
5675 wxASSERT_MSG( IsVirtual(), _T("this is for virtual controls only") );
5677 m_mainWin
->SetItemCount(count
);
5680 void wxGenericListCtrl::RefreshItem(long item
)
5682 m_mainWin
->RefreshLine(item
);
5685 void wxGenericListCtrl::RefreshItems(long itemFrom
, long itemTo
)
5687 m_mainWin
->RefreshLines(itemFrom
, itemTo
);
5690 // Generic wxListCtrl is more or less a container for two other
5691 // windows which drawings are done upon. These are namely
5692 // 'm_headerWin' and 'm_mainWin'.
5693 // Here we override 'virtual wxWindow::Refresh()' to mimic the
5694 // behaviour wxListCtrl has under wxMSW.
5696 void wxGenericListCtrl::Refresh(bool eraseBackground
, const wxRect
*rect
)
5700 // The easy case, no rectangle specified.
5702 m_headerWin
->Refresh(eraseBackground
);
5705 m_mainWin
->Refresh(eraseBackground
);
5709 // Refresh the header window
5712 wxRect rectHeader
= m_headerWin
->GetRect();
5713 rectHeader
.Intersect(*rect
);
5714 if (rectHeader
.GetWidth() && rectHeader
.GetHeight())
5717 m_headerWin
->GetPosition(&x
, &y
);
5718 rectHeader
.Offset(-x
, -y
);
5719 m_headerWin
->Refresh(eraseBackground
, &rectHeader
);
5723 // Refresh the main window
5726 wxRect rectMain
= m_mainWin
->GetRect();
5727 rectMain
.Intersect(*rect
);
5728 if (rectMain
.GetWidth() && rectMain
.GetHeight())
5731 m_mainWin
->GetPosition(&x
, &y
);
5732 rectMain
.Offset(-x
, -y
);
5733 m_mainWin
->Refresh(eraseBackground
, &rectMain
);
5739 void wxGenericListCtrl::Freeze()
5741 m_mainWin
->Freeze();
5744 void wxGenericListCtrl::Thaw()
5749 #endif // wxUSE_LISTCTRL