1 /////////////////////////////////////////////////////////////////////////////
2 // Name: 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"
28 #include "wx/dynarray.h"
29 #include "wx/dcscreen.h"
30 #include "wx/textctrl.h"
33 // under Win32 we always use the native version and also may use the generic
34 // one, however some things should be done only if we use only the generic
36 #if defined(__WIN32__) && !defined(__WXUNIVERSAL__)
37 #define HAVE_NATIVE_LISTCTRL
40 // if we have the native control, wx/listctrl.h declares it and not this one
41 #ifdef HAVE_NATIVE_LISTCTRL
42 #include "wx/generic/listctrl.h"
43 #else // !HAVE_NATIVE_LISTCTRL
44 #include "wx/listctrl.h"
46 // if we have a native version, its implementation file does all this
47 IMPLEMENT_DYNAMIC_CLASS(wxListItem
, wxObject
)
48 IMPLEMENT_DYNAMIC_CLASS(wxListView
, wxListCtrl
)
49 IMPLEMENT_DYNAMIC_CLASS(wxListEvent
, wxNotifyEvent
)
51 IMPLEMENT_DYNAMIC_CLASS(wxListCtrl
, wxGenericListCtrl
)
52 #endif // HAVE_NATIVE_LISTCTRL/!HAVE_NATIVE_LISTCTRL
54 #include "wx/selstore.h"
55 #include "wx/renderer.h"
59 #include "wx/mac/private.h"
63 // NOTE: If using the wxListBox visual attributes works everywhere then this can
64 // be removed, as well as the #else case below.
65 #define _USE_VISATTR 0
68 // ----------------------------------------------------------------------------
70 // ----------------------------------------------------------------------------
72 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_BEGIN_DRAG
)
73 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_BEGIN_RDRAG
)
74 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_BEGIN_LABEL_EDIT
)
75 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_END_LABEL_EDIT
)
76 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_DELETE_ITEM
)
77 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_DELETE_ALL_ITEMS
)
78 #if WXWIN_COMPATIBILITY_2_4
79 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_GET_INFO
)
80 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_SET_INFO
)
82 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_ITEM_SELECTED
)
83 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_ITEM_DESELECTED
)
84 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_KEY_DOWN
)
85 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_INSERT_ITEM
)
86 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_COL_CLICK
)
87 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_COL_RIGHT_CLICK
)
88 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_COL_BEGIN_DRAG
)
89 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_COL_DRAGGING
)
90 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_COL_END_DRAG
)
91 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_ITEM_RIGHT_CLICK
)
92 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_ITEM_MIDDLE_CLICK
)
93 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_ITEM_ACTIVATED
)
94 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_ITEM_FOCUSED
)
95 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_CACHE_HINT
)
97 // ----------------------------------------------------------------------------
99 // ----------------------------------------------------------------------------
101 // // the height of the header window (FIXME: should depend on its font!)
102 // static const int HEADER_HEIGHT = 23;
104 static const int SCROLL_UNIT_X
= 15;
106 // the spacing between the lines (in report mode)
107 static const int LINE_SPACING
= 0;
109 // extra margins around the text label
110 static const int EXTRA_WIDTH
= 4;
111 static const int EXTRA_HEIGHT
= 4;
113 // margin between the window and the items
114 static const int EXTRA_BORDER_X
= 2;
115 static const int EXTRA_BORDER_Y
= 2;
117 // offset for the header window
118 static const int HEADER_OFFSET_X
= 1;
119 static const int HEADER_OFFSET_Y
= 1;
121 // margin between rows of icons in [small] icon view
122 static const int MARGIN_BETWEEN_ROWS
= 6;
124 // when autosizing the columns, add some slack
125 static const int AUTOSIZE_COL_MARGIN
= 10;
127 // default width for the header columns
128 static const int WIDTH_COL_DEFAULT
= 80;
130 // the space between the image and the text in the report mode
131 static const int IMAGE_MARGIN_IN_REPORT_MODE
= 5;
133 // ============================================================================
135 // ============================================================================
137 //-----------------------------------------------------------------------------
138 // wxColWidthInfo (internal)
139 //-----------------------------------------------------------------------------
141 struct wxColWidthInfo
144 bool bNeedsUpdate
; // only set to true when an item whose
145 // width == nMaxWidth is removed
147 wxColWidthInfo(int w
= 0, bool needsUpdate
= false)
150 bNeedsUpdate
= needsUpdate
;
154 WX_DEFINE_ARRAY_PTR(wxColWidthInfo
*, ColWidthArray
);
156 //-----------------------------------------------------------------------------
157 // wxListItemData (internal)
158 //-----------------------------------------------------------------------------
160 class WXDLLEXPORT wxListItemData
163 wxListItemData(wxListMainWindow
*owner
);
166 void SetItem( const wxListItem
&info
);
167 void SetImage( int image
) { m_image
= image
; }
168 void SetData( wxUIntPtr data
) { m_data
= data
; }
169 void SetPosition( int x
, int y
);
170 void SetSize( int width
, int height
);
172 bool HasText() const { return !m_text
.empty(); }
173 const wxString
& GetText() const { return m_text
; }
174 void SetText(const wxString
& text
) { m_text
= text
; }
176 // we can't use empty string for measuring the string width/height, so
177 // always return something
178 wxString
GetTextForMeasuring() const
180 wxString s
= GetText();
187 bool IsHit( int x
, int y
) const;
191 int GetWidth() const;
192 int GetHeight() const;
194 int GetImage() const { return m_image
; }
195 bool HasImage() const { return GetImage() != -1; }
197 void GetItem( wxListItem
&info
) const;
199 void SetAttr(wxListItemAttr
*attr
) { m_attr
= attr
; }
200 wxListItemAttr
*GetAttr() const { return m_attr
; }
203 // the item image or -1
206 // user data associated with the item
209 // the item coordinates are not used in report mode; instead this pointer is
210 // NULL and the owner window is used to retrieve the item position and size
213 // the list ctrl we are in
214 wxListMainWindow
*m_owner
;
216 // custom attributes or NULL
217 wxListItemAttr
*m_attr
;
220 // common part of all ctors
226 //-----------------------------------------------------------------------------
227 // wxListHeaderData (internal)
228 //-----------------------------------------------------------------------------
230 class WXDLLEXPORT wxListHeaderData
: public wxObject
234 wxListHeaderData( const wxListItem
&info
);
235 void SetItem( const wxListItem
&item
);
236 void SetPosition( int x
, int y
);
237 void SetWidth( int w
);
238 void SetFormat( int format
);
239 void SetHeight( int h
);
240 bool HasImage() const;
242 bool HasText() const { return !m_text
.empty(); }
243 const wxString
& GetText() const { return m_text
; }
244 void SetText(const wxString
& text
) { m_text
= text
; }
246 void GetItem( wxListItem
&item
);
248 bool IsHit( int x
, int y
) const;
249 int GetImage() const;
250 int GetWidth() const;
251 int GetFormat() const;
267 //-----------------------------------------------------------------------------
268 // wxListLineData (internal)
269 //-----------------------------------------------------------------------------
271 WX_DECLARE_EXPORTED_LIST(wxListItemData
, wxListItemDataList
);
272 #include "wx/listimpl.cpp"
273 WX_DEFINE_LIST(wxListItemDataList
)
278 // the list of subitems: only may have more than one item in report mode
279 wxListItemDataList m_items
;
281 // this is not used in report view
293 // the part to be highlighted
294 wxRect m_rectHighlight
;
296 // extend all our rects to be centered inside the one of given width
297 void ExtendWidth(wxCoord w
)
299 wxASSERT_MSG( m_rectAll
.width
<= w
,
300 _T("width can only be increased") );
303 m_rectLabel
.x
= m_rectAll
.x
+ (w
- m_rectLabel
.width
) / 2;
304 m_rectIcon
.x
= m_rectAll
.x
+ (w
- m_rectIcon
.width
) / 2;
305 m_rectHighlight
.x
= m_rectAll
.x
+ (w
- m_rectHighlight
.width
) / 2;
310 // is this item selected? [NB: not used in virtual mode]
313 // back pointer to the list ctrl
314 wxListMainWindow
*m_owner
;
317 wxListLineData(wxListMainWindow
*owner
);
321 WX_CLEAR_LIST(wxListItemDataList
, m_items
);
325 // are we in report mode?
326 inline bool InReportView() const;
328 // are we in virtual report mode?
329 inline bool IsVirtual() const;
331 // these 2 methods shouldn't be called for report view controls, in that
332 // case we determine our position/size ourselves
334 // calculate the size of the line
335 void CalculateSize( wxDC
*dc
, int spacing
);
337 // remember the position this line appears at
338 void SetPosition( int x
, int y
, int spacing
);
342 void SetImage( int image
) { SetImage(0, image
); }
343 int GetImage() const { return GetImage(0); }
344 void SetImage( int index
, int image
);
345 int GetImage( int index
) const;
347 bool HasImage() const { return GetImage() != -1; }
348 bool HasText() const { return !GetText(0).empty(); }
350 void SetItem( int index
, const wxListItem
&info
);
351 void GetItem( int index
, wxListItem
&info
);
353 wxString
GetText(int index
) const;
354 void SetText( int index
, const wxString
& s
);
356 wxListItemAttr
*GetAttr() const;
357 void SetAttr(wxListItemAttr
*attr
);
359 // return true if the highlighting really changed
360 bool Highlight( bool on
);
362 void ReverseHighlight();
364 bool IsHighlighted() const
366 wxASSERT_MSG( !IsVirtual(), _T("unexpected call to IsHighlighted") );
368 return m_highlighted
;
371 // draw the line on the given DC in icon/list mode
372 void Draw( wxDC
*dc
);
374 // the same in report mode
375 void DrawInReportMode( wxDC
*dc
,
377 const wxRect
& rectHL
,
381 // set the line to contain num items (only can be > 1 in report mode)
382 void InitItems( int num
);
384 // get the mode (i.e. style) of the list control
385 inline int GetMode() const;
387 // prepare the DC for drawing with these item's attributes, return true if
388 // we need to draw the items background to highlight it, false otherwise
389 bool SetAttributes(wxDC
*dc
,
390 const wxListItemAttr
*attr
,
393 // draw the text on the DC with the correct justification; also add an
394 // ellipsis if the text is too large to fit in the current width
395 void DrawTextFormatted(wxDC
*dc
, const wxString
&text
, int col
, int x
, int y
, int width
);
398 WX_DECLARE_EXPORTED_OBJARRAY(wxListLineData
, wxListLineDataArray
);
399 #include "wx/arrimpl.cpp"
400 WX_DEFINE_OBJARRAY(wxListLineDataArray
)
402 //-----------------------------------------------------------------------------
403 // wxListHeaderWindow (internal)
404 //-----------------------------------------------------------------------------
406 class WXDLLEXPORT wxListHeaderWindow
: public wxWindow
409 wxListMainWindow
*m_owner
;
410 wxCursor
*m_currentCursor
;
411 wxCursor
*m_resizeCursor
;
414 // column being resized or -1
417 // divider line position in logical (unscrolled) coords
420 // minimal position beyond which the divider line
421 // can't be dragged in logical coords
425 wxListHeaderWindow();
427 wxListHeaderWindow( wxWindow
*win
,
429 wxListMainWindow
*owner
,
430 const wxPoint
&pos
= wxDefaultPosition
,
431 const wxSize
&size
= wxDefaultSize
,
433 const wxString
&name
= wxT("wxlistctrlcolumntitles") );
435 virtual ~wxListHeaderWindow();
438 void AdjustDC( wxDC
& dc
);
440 void OnPaint( wxPaintEvent
&event
);
441 void OnMouse( wxMouseEvent
&event
);
442 void OnSetFocus( wxFocusEvent
&event
);
448 // common part of all ctors
451 // generate and process the list event of the given type, return true if
452 // it wasn't vetoed, i.e. if we should proceed
453 bool SendListEvent(wxEventType type
, const wxPoint
& pos
);
455 DECLARE_DYNAMIC_CLASS(wxListHeaderWindow
)
456 DECLARE_EVENT_TABLE()
459 //-----------------------------------------------------------------------------
460 // wxListRenameTimer (internal)
461 //-----------------------------------------------------------------------------
463 class WXDLLEXPORT wxListRenameTimer
: public wxTimer
466 wxListMainWindow
*m_owner
;
469 wxListRenameTimer( wxListMainWindow
*owner
);
473 //-----------------------------------------------------------------------------
474 // wxListTextCtrlWrapper: wraps a wxTextCtrl to make it work for inline editing
475 //-----------------------------------------------------------------------------
477 class WXDLLEXPORT wxListTextCtrlWrapper
: public wxEvtHandler
480 // NB: text must be a valid object but not Create()d yet
481 wxListTextCtrlWrapper(wxListMainWindow
*owner
,
485 wxTextCtrl
*GetText() const { return m_text
; }
487 void AcceptChangesAndFinish();
490 void OnChar( wxKeyEvent
&event
);
491 void OnKeyUp( wxKeyEvent
&event
);
492 void OnKillFocus( wxFocusEvent
&event
);
494 bool AcceptChanges();
498 wxListMainWindow
*m_owner
;
500 wxString m_startValue
;
503 bool m_aboutToFinish
;
505 DECLARE_EVENT_TABLE()
508 //-----------------------------------------------------------------------------
509 // wxListMainWindow (internal)
510 //-----------------------------------------------------------------------------
512 WX_DECLARE_EXPORTED_LIST(wxListHeaderData
, wxListHeaderDataList
);
513 #include "wx/listimpl.cpp"
514 WX_DEFINE_LIST(wxListHeaderDataList
)
516 class wxListMainWindow
: public wxScrolledWindow
520 wxListMainWindow( wxWindow
*parent
,
522 const wxPoint
& pos
= wxDefaultPosition
,
523 const wxSize
& size
= wxDefaultSize
,
525 const wxString
&name
= _T("listctrlmainwindow") );
527 virtual ~wxListMainWindow();
529 bool HasFlag(int flag
) const { return m_parent
->HasFlag(flag
); }
531 // return true if this is a virtual list control
532 bool IsVirtual() const { return HasFlag(wxLC_VIRTUAL
); }
534 // return true if the control is in report mode
535 bool InReportView() const { return HasFlag(wxLC_REPORT
); }
537 // return true if we are in single selection mode, false if multi sel
538 bool IsSingleSel() const { return HasFlag(wxLC_SINGLE_SEL
); }
540 // do we have a header window?
541 bool HasHeader() const
542 { return InReportView() && !HasFlag(wxLC_NO_HEADER
); }
544 void HighlightAll( bool on
);
546 // all these functions only do something if the line is currently visible
548 // change the line "selected" state, return true if it really changed
549 bool HighlightLine( size_t line
, bool highlight
= true);
551 // as HighlightLine() but do it for the range of lines: this is incredibly
552 // more efficient for virtual list controls!
554 // NB: unlike HighlightLine() this one does refresh the lines on screen
555 void HighlightLines( size_t lineFrom
, size_t lineTo
, bool on
= true );
557 // toggle the line state and refresh it
558 void ReverseHighlight( size_t line
)
559 { HighlightLine(line
, !IsHighlighted(line
)); RefreshLine(line
); }
561 // return true if the line is highlighted
562 bool IsHighlighted(size_t line
) const;
564 // refresh one or several lines at once
565 void RefreshLine( size_t line
);
566 void RefreshLines( size_t lineFrom
, size_t lineTo
);
568 // refresh all selected items
569 void RefreshSelected();
571 // refresh all lines below the given one: the difference with
572 // RefreshLines() is that the index here might not be a valid one (happens
573 // when the last line is deleted)
574 void RefreshAfter( size_t lineFrom
);
576 // the methods which are forwarded to wxListLineData itself in list/icon
577 // modes but are here because the lines don't store their positions in the
580 // get the bound rect for the entire line
581 wxRect
GetLineRect(size_t line
) const;
583 // get the bound rect of the label
584 wxRect
GetLineLabelRect(size_t line
) const;
586 // get the bound rect of the items icon (only may be called if we do have
588 wxRect
GetLineIconRect(size_t line
) const;
590 // get the rect to be highlighted when the item has focus
591 wxRect
GetLineHighlightRect(size_t line
) const;
593 // get the size of the total line rect
594 wxSize
GetLineSize(size_t line
) const
595 { return GetLineRect(line
).GetSize(); }
597 // return the hit code for the corresponding position (in this line)
598 long HitTestLine(size_t line
, int x
, int y
) const;
600 // bring the selected item into view, scrolling to it if necessary
601 void MoveToItem(size_t item
);
603 // bring the current item into view
604 void MoveToFocus() { MoveToItem(m_current
); }
606 // start editing the label of the given item
607 wxTextCtrl
*EditLabel(long item
,
608 wxClassInfo
* textControlClass
= CLASSINFO(wxTextCtrl
));
609 wxTextCtrl
*GetEditControl() const
611 return m_textctrlWrapper
? m_textctrlWrapper
->GetText() : NULL
;
614 void FinishEditing(wxTextCtrl
*text
)
617 m_textctrlWrapper
= NULL
;
618 SetFocusIgnoringChildren();
621 // suspend/resume redrawing the control
625 void OnRenameTimer();
626 bool OnRenameAccept(size_t itemEdit
, const wxString
& value
);
627 void OnRenameCancelled(size_t itemEdit
);
629 void OnMouse( wxMouseEvent
&event
);
631 // called to switch the selection from the current item to newCurrent,
632 void OnArrowChar( size_t newCurrent
, const wxKeyEvent
& event
);
634 void OnChar( wxKeyEvent
&event
);
635 void OnKeyDown( wxKeyEvent
&event
);
636 void OnSetFocus( wxFocusEvent
&event
);
637 void OnKillFocus( wxFocusEvent
&event
);
638 void OnScroll( wxScrollWinEvent
& event
);
640 void OnPaint( wxPaintEvent
&event
);
642 void DrawImage( int index
, wxDC
*dc
, int x
, int y
);
643 void GetImageSize( int index
, int &width
, int &height
) const;
644 int GetTextLength( const wxString
&s
) const;
646 void SetImageList( wxImageListType
*imageList
, int which
);
647 void SetItemSpacing( int spacing
, bool isSmall
= false );
648 int GetItemSpacing( bool isSmall
= false );
650 void SetColumn( int col
, wxListItem
&item
);
651 void SetColumnWidth( int col
, int width
);
652 void GetColumn( int col
, wxListItem
&item
) const;
653 int GetColumnWidth( int col
) const;
654 int GetColumnCount() const { return m_columns
.GetCount(); }
656 // returns the sum of the heights of all columns
657 int GetHeaderWidth() const;
659 int GetCountPerPage() const;
661 void SetItem( wxListItem
&item
);
662 void GetItem( wxListItem
&item
) const;
663 void SetItemState( long item
, long state
, long stateMask
);
664 void SetItemStateAll( long state
, long stateMask
);
665 int GetItemState( long item
, long stateMask
) const;
666 void GetItemRect( long index
, wxRect
&rect
) const;
667 wxRect
GetViewRect() const;
668 bool GetItemPosition( long item
, wxPoint
& pos
) const;
669 int GetSelectedItemCount() const;
671 wxString
GetItemText(long item
) const
674 info
.m_mask
= wxLIST_MASK_TEXT
;
675 info
.m_itemId
= item
;
680 void SetItemText(long item
, const wxString
& value
)
683 info
.m_mask
= wxLIST_MASK_TEXT
;
684 info
.m_itemId
= item
;
689 // set the scrollbars and update the positions of the items
690 void RecalculatePositions(bool noRefresh
= false);
692 // refresh the window and the header
695 long GetNextItem( long item
, int geometry
, int state
) const;
696 void DeleteItem( long index
);
697 void DeleteAllItems();
698 void DeleteColumn( int col
);
699 void DeleteEverything();
700 void EnsureVisible( long index
);
701 long FindItem( long start
, const wxString
& str
, bool partial
= false );
702 long FindItem( long start
, wxUIntPtr data
);
703 long FindItem( const wxPoint
& pt
);
704 long HitTest( int x
, int y
, int &flags
);
705 void InsertItem( wxListItem
&item
);
706 void InsertColumn( long col
, wxListItem
&item
);
707 int GetItemWidthWithImage(wxListItem
* item
);
708 void SortItems( wxListCtrlCompare fn
, long data
);
710 size_t GetItemCount() const;
711 bool IsEmpty() const { return GetItemCount() == 0; }
712 void SetItemCount(long count
);
714 // change the current (== focused) item, send a notification event
715 void ChangeCurrent(size_t current
);
716 void ResetCurrent() { ChangeCurrent((size_t)-1); }
717 bool HasCurrent() const { return m_current
!= (size_t)-1; }
719 // send out a wxListEvent
720 void SendNotify( size_t line
,
722 const wxPoint
& point
= wxDefaultPosition
);
724 // override base class virtual to reset m_lineHeight when the font changes
725 virtual bool SetFont(const wxFont
& font
)
727 if ( !wxScrolledWindow::SetFont(font
) )
735 // these are for wxListLineData usage only
737 // get the backpointer to the list ctrl
738 wxGenericListCtrl
*GetListCtrl() const
740 return wxStaticCast(GetParent(), wxGenericListCtrl
);
743 // get the height of all lines (assuming they all do have the same height)
744 wxCoord
GetLineHeight() const;
746 // get the y position of the given line (only for report view)
747 wxCoord
GetLineY(size_t line
) const;
749 // get the brush to use for the item highlighting
750 wxBrush
*GetHighlightBrush() const
752 return m_hasFocus
? m_highlightBrush
: m_highlightUnfocusedBrush
;
756 // the array of all line objects for a non virtual list control (for the
757 // virtual list control we only ever use m_lines[0])
758 wxListLineDataArray m_lines
;
760 // the list of column objects
761 wxListHeaderDataList m_columns
;
763 // currently focused item or -1
766 // the number of lines per page
769 // this flag is set when something which should result in the window
770 // redrawing happens (i.e. an item was added or deleted, or its appearance
771 // changed) and OnPaint() doesn't redraw the window while it is set which
772 // allows to minimize the number of repaintings when a lot of items are
773 // being added. The real repainting occurs only after the next OnIdle()
777 wxColour
*m_highlightColour
;
778 wxImageListType
*m_small_image_list
;
779 wxImageListType
*m_normal_image_list
;
781 int m_normal_spacing
;
785 wxTimer
*m_renameTimer
;
789 ColWidthArray m_aColWidths
;
791 // for double click logic
792 size_t m_lineLastClicked
,
793 m_lineBeforeLastClicked
,
794 m_lineSelectSingleOnUp
;
797 wxWindow
*GetMainWindowOfCompositeControl() { return GetParent(); }
799 // the total count of items in a virtual list control
802 // the object maintaining the items selection state, only used in virtual
804 wxSelectionStore m_selStore
;
806 // common part of all ctors
809 // get the line data for the given index
810 wxListLineData
*GetLine(size_t n
) const
812 wxASSERT_MSG( n
!= (size_t)-1, _T("invalid line index") );
816 wxConstCast(this, wxListMainWindow
)->CacheLineData(n
);
823 // get a dummy line which can be used for geometry calculations and such:
824 // you must use GetLine() if you want to really draw the line
825 wxListLineData
*GetDummyLine() const;
827 // cache the line data of the n-th line in m_lines[0]
828 void CacheLineData(size_t line
);
830 // get the range of visible lines
831 void GetVisibleLinesRange(size_t *from
, size_t *to
);
833 // force us to recalculate the range of visible lines
834 void ResetVisibleLinesRange() { m_lineFrom
= (size_t)-1; }
836 // get the colour to be used for drawing the rules
837 wxColour
GetRuleColour() const
839 return wxSystemSettings::GetColour(wxSYS_COLOUR_3DLIGHT
);
843 // initialize the current item if needed
844 void UpdateCurrent();
846 // delete all items but don't refresh: called from dtor
847 void DoDeleteAllItems();
849 // the height of one line using the current font
850 wxCoord m_lineHeight
;
852 // the total header width or 0 if not calculated yet
853 wxCoord m_headerWidth
;
855 // the first and last lines being shown on screen right now (inclusive),
856 // both may be -1 if they must be calculated so never access them directly:
857 // use GetVisibleLinesRange() above instead
861 // the brushes to use for item highlighting when we do/don't have focus
862 wxBrush
*m_highlightBrush
,
863 *m_highlightUnfocusedBrush
;
865 // if this is > 0, the control is frozen and doesn't redraw itself
866 size_t m_freezeCount
;
868 // wrapper around the text control currently used for in place editing or
869 // NULL if no item is being edited
870 wxListTextCtrlWrapper
*m_textctrlWrapper
;
873 DECLARE_DYNAMIC_CLASS(wxListMainWindow
)
874 DECLARE_EVENT_TABLE()
876 friend class wxGenericListCtrl
;
880 wxListItemData::~wxListItemData()
882 // in the virtual list control the attributes are managed by the main
883 // program, so don't delete them
884 if ( !m_owner
->IsVirtual() )
890 void wxListItemData::Init()
898 wxListItemData::wxListItemData(wxListMainWindow
*owner
)
904 if ( owner
->InReportView() )
910 void wxListItemData::SetItem( const wxListItem
&info
)
912 if ( info
.m_mask
& wxLIST_MASK_TEXT
)
913 SetText(info
.m_text
);
914 if ( info
.m_mask
& wxLIST_MASK_IMAGE
)
915 m_image
= info
.m_image
;
916 if ( info
.m_mask
& wxLIST_MASK_DATA
)
917 m_data
= info
.m_data
;
919 if ( info
.HasAttributes() )
922 *m_attr
= *info
.GetAttributes();
924 m_attr
= new wxListItemAttr(*info
.GetAttributes());
932 m_rect
->width
= info
.m_width
;
936 void wxListItemData::SetPosition( int x
, int y
)
938 wxCHECK_RET( m_rect
, _T("unexpected SetPosition() call") );
944 void wxListItemData::SetSize( int width
, int height
)
946 wxCHECK_RET( m_rect
, _T("unexpected SetSize() call") );
949 m_rect
->width
= width
;
951 m_rect
->height
= height
;
954 bool wxListItemData::IsHit( int x
, int y
) const
956 wxCHECK_MSG( m_rect
, false, _T("can't be called in this mode") );
958 return wxRect(GetX(), GetY(), GetWidth(), GetHeight()).Inside(x
, y
);
961 int wxListItemData::GetX() const
963 wxCHECK_MSG( m_rect
, 0, _T("can't be called in this mode") );
968 int wxListItemData::GetY() const
970 wxCHECK_MSG( m_rect
, 0, _T("can't be called in this mode") );
975 int wxListItemData::GetWidth() const
977 wxCHECK_MSG( m_rect
, 0, _T("can't be called in this mode") );
979 return m_rect
->width
;
982 int wxListItemData::GetHeight() const
984 wxCHECK_MSG( m_rect
, 0, _T("can't be called in this mode") );
986 return m_rect
->height
;
989 void wxListItemData::GetItem( wxListItem
&info
) const
991 long mask
= info
.m_mask
;
993 // by default, get everything for backwards compatibility
996 if ( mask
& wxLIST_MASK_TEXT
)
997 info
.m_text
= m_text
;
998 if ( mask
& wxLIST_MASK_IMAGE
)
999 info
.m_image
= m_image
;
1000 if ( mask
& wxLIST_MASK_DATA
)
1001 info
.m_data
= m_data
;
1005 if ( m_attr
->HasTextColour() )
1006 info
.SetTextColour(m_attr
->GetTextColour());
1007 if ( m_attr
->HasBackgroundColour() )
1008 info
.SetBackgroundColour(m_attr
->GetBackgroundColour());
1009 if ( m_attr
->HasFont() )
1010 info
.SetFont(m_attr
->GetFont());
1014 //-----------------------------------------------------------------------------
1016 //-----------------------------------------------------------------------------
1018 void wxListHeaderData::Init()
1029 wxListHeaderData::wxListHeaderData()
1034 wxListHeaderData::wxListHeaderData( const wxListItem
&item
)
1041 void wxListHeaderData::SetItem( const wxListItem
&item
)
1043 m_mask
= item
.m_mask
;
1045 if ( m_mask
& wxLIST_MASK_TEXT
)
1046 m_text
= item
.m_text
;
1048 if ( m_mask
& wxLIST_MASK_IMAGE
)
1049 m_image
= item
.m_image
;
1051 if ( m_mask
& wxLIST_MASK_FORMAT
)
1052 m_format
= item
.m_format
;
1054 if ( m_mask
& wxLIST_MASK_WIDTH
)
1055 SetWidth(item
.m_width
);
1058 void wxListHeaderData::SetPosition( int x
, int y
)
1064 void wxListHeaderData::SetHeight( int h
)
1069 void wxListHeaderData::SetWidth( int w
)
1071 m_width
= w
< 0 ? WIDTH_COL_DEFAULT
: w
;
1074 void wxListHeaderData::SetFormat( int format
)
1079 bool wxListHeaderData::HasImage() const
1081 return m_image
!= -1;
1084 bool wxListHeaderData::IsHit( int x
, int y
) const
1086 return ((x
>= m_xpos
) && (x
<= m_xpos
+m_width
) && (y
>= m_ypos
) && (y
<= m_ypos
+m_height
));
1089 void wxListHeaderData::GetItem( wxListItem
& item
)
1091 item
.m_mask
= m_mask
;
1092 item
.m_text
= m_text
;
1093 item
.m_image
= m_image
;
1094 item
.m_format
= m_format
;
1095 item
.m_width
= m_width
;
1098 int wxListHeaderData::GetImage() const
1103 int wxListHeaderData::GetWidth() const
1108 int wxListHeaderData::GetFormat() const
1113 //-----------------------------------------------------------------------------
1115 //-----------------------------------------------------------------------------
1117 inline int wxListLineData::GetMode() const
1119 return m_owner
->GetListCtrl()->GetWindowStyleFlag() & wxLC_MASK_TYPE
;
1122 inline bool wxListLineData::InReportView() const
1124 return m_owner
->HasFlag(wxLC_REPORT
);
1127 inline bool wxListLineData::IsVirtual() const
1129 return m_owner
->IsVirtual();
1132 wxListLineData::wxListLineData( wxListMainWindow
*owner
)
1136 if ( InReportView() )
1139 m_gi
= new GeometryInfo
;
1141 m_highlighted
= false;
1143 InitItems( GetMode() == wxLC_REPORT
? m_owner
->GetColumnCount() : 1 );
1146 void wxListLineData::CalculateSize( wxDC
*dc
, int spacing
)
1148 wxListItemDataList::compatibility_iterator node
= m_items
.GetFirst();
1149 wxCHECK_RET( node
, _T("no subitems at all??") );
1151 wxListItemData
*item
= node
->GetData();
1156 switch ( GetMode() )
1159 case wxLC_SMALL_ICON
:
1160 m_gi
->m_rectAll
.width
= spacing
;
1162 s
= item
->GetText();
1167 m_gi
->m_rectLabel
.width
=
1168 m_gi
->m_rectLabel
.height
= 0;
1172 dc
->GetTextExtent( s
, &lw
, &lh
);
1176 m_gi
->m_rectAll
.height
= spacing
+ lh
;
1178 m_gi
->m_rectAll
.width
= lw
;
1180 m_gi
->m_rectLabel
.width
= lw
;
1181 m_gi
->m_rectLabel
.height
= lh
;
1184 if (item
->HasImage())
1187 m_owner
->GetImageSize( item
->GetImage(), w
, h
);
1188 m_gi
->m_rectIcon
.width
= w
+ 8;
1189 m_gi
->m_rectIcon
.height
= h
+ 8;
1191 if ( m_gi
->m_rectIcon
.width
> m_gi
->m_rectAll
.width
)
1192 m_gi
->m_rectAll
.width
= m_gi
->m_rectIcon
.width
;
1193 if ( m_gi
->m_rectIcon
.height
+ lh
> m_gi
->m_rectAll
.height
- 4 )
1194 m_gi
->m_rectAll
.height
= m_gi
->m_rectIcon
.height
+ lh
+ 4;
1197 if ( item
->HasText() )
1199 m_gi
->m_rectHighlight
.width
= m_gi
->m_rectLabel
.width
;
1200 m_gi
->m_rectHighlight
.height
= m_gi
->m_rectLabel
.height
;
1202 else // no text, highlight the icon
1204 m_gi
->m_rectHighlight
.width
= m_gi
->m_rectIcon
.width
;
1205 m_gi
->m_rectHighlight
.height
= m_gi
->m_rectIcon
.height
;
1210 s
= item
->GetTextForMeasuring();
1212 dc
->GetTextExtent( s
, &lw
, &lh
);
1216 m_gi
->m_rectLabel
.width
= lw
;
1217 m_gi
->m_rectLabel
.height
= lh
;
1219 m_gi
->m_rectAll
.width
= lw
;
1220 m_gi
->m_rectAll
.height
= lh
;
1222 if (item
->HasImage())
1225 m_owner
->GetImageSize( item
->GetImage(), w
, h
);
1226 m_gi
->m_rectIcon
.width
= w
;
1227 m_gi
->m_rectIcon
.height
= h
;
1229 m_gi
->m_rectAll
.width
+= 4 + w
;
1230 if (h
> m_gi
->m_rectAll
.height
)
1231 m_gi
->m_rectAll
.height
= h
;
1234 m_gi
->m_rectHighlight
.width
= m_gi
->m_rectAll
.width
;
1235 m_gi
->m_rectHighlight
.height
= m_gi
->m_rectAll
.height
;
1239 wxFAIL_MSG( _T("unexpected call to SetSize") );
1243 wxFAIL_MSG( _T("unknown mode") );
1248 void wxListLineData::SetPosition( int x
, int y
, int spacing
)
1250 wxListItemDataList::compatibility_iterator node
= m_items
.GetFirst();
1251 wxCHECK_RET( node
, _T("no subitems at all??") );
1253 wxListItemData
*item
= node
->GetData();
1255 switch ( GetMode() )
1258 case wxLC_SMALL_ICON
:
1259 m_gi
->m_rectAll
.x
= x
;
1260 m_gi
->m_rectAll
.y
= y
;
1262 if ( item
->HasImage() )
1264 m_gi
->m_rectIcon
.x
= m_gi
->m_rectAll
.x
+ 4 +
1265 (m_gi
->m_rectAll
.width
- m_gi
->m_rectIcon
.width
) / 2;
1266 m_gi
->m_rectIcon
.y
= m_gi
->m_rectAll
.y
+ 4;
1269 if ( item
->HasText() )
1271 if (m_gi
->m_rectAll
.width
> spacing
)
1272 m_gi
->m_rectLabel
.x
= m_gi
->m_rectAll
.x
+ 2;
1274 m_gi
->m_rectLabel
.x
= m_gi
->m_rectAll
.x
+ 2 + (spacing
/ 2) - (m_gi
->m_rectLabel
.width
/ 2);
1275 m_gi
->m_rectLabel
.y
= m_gi
->m_rectAll
.y
+ m_gi
->m_rectAll
.height
+ 2 - m_gi
->m_rectLabel
.height
;
1276 m_gi
->m_rectHighlight
.x
= m_gi
->m_rectLabel
.x
- 2;
1277 m_gi
->m_rectHighlight
.y
= m_gi
->m_rectLabel
.y
- 2;
1279 else // no text, highlight the icon
1281 m_gi
->m_rectHighlight
.x
= m_gi
->m_rectIcon
.x
- 4;
1282 m_gi
->m_rectHighlight
.y
= m_gi
->m_rectIcon
.y
- 4;
1287 m_gi
->m_rectAll
.x
= x
;
1288 m_gi
->m_rectAll
.y
= y
;
1290 m_gi
->m_rectHighlight
.x
= m_gi
->m_rectAll
.x
;
1291 m_gi
->m_rectHighlight
.y
= m_gi
->m_rectAll
.y
;
1292 m_gi
->m_rectLabel
.y
= m_gi
->m_rectAll
.y
+ 2;
1294 if (item
->HasImage())
1296 m_gi
->m_rectIcon
.x
= m_gi
->m_rectAll
.x
+ 2;
1297 m_gi
->m_rectIcon
.y
= m_gi
->m_rectAll
.y
+ 2;
1298 m_gi
->m_rectLabel
.x
= m_gi
->m_rectAll
.x
+ 6 + m_gi
->m_rectIcon
.width
;
1302 m_gi
->m_rectLabel
.x
= m_gi
->m_rectAll
.x
+ 2;
1307 wxFAIL_MSG( _T("unexpected call to SetPosition") );
1311 wxFAIL_MSG( _T("unknown mode") );
1316 void wxListLineData::InitItems( int num
)
1318 for (int i
= 0; i
< num
; i
++)
1319 m_items
.Append( new wxListItemData(m_owner
) );
1322 void wxListLineData::SetItem( int index
, const wxListItem
&info
)
1324 wxListItemDataList::compatibility_iterator node
= m_items
.Item( index
);
1325 wxCHECK_RET( node
, _T("invalid column index in SetItem") );
1327 wxListItemData
*item
= node
->GetData();
1328 item
->SetItem( info
);
1331 void wxListLineData::GetItem( int index
, wxListItem
&info
)
1333 wxListItemDataList::compatibility_iterator node
= m_items
.Item( index
);
1336 wxListItemData
*item
= node
->GetData();
1337 item
->GetItem( info
);
1341 wxString
wxListLineData::GetText(int index
) const
1345 wxListItemDataList::compatibility_iterator node
= m_items
.Item( index
);
1348 wxListItemData
*item
= node
->GetData();
1349 s
= item
->GetText();
1355 void wxListLineData::SetText( int index
, const wxString
& s
)
1357 wxListItemDataList::compatibility_iterator node
= m_items
.Item( index
);
1360 wxListItemData
*item
= node
->GetData();
1365 void wxListLineData::SetImage( int index
, int image
)
1367 wxListItemDataList::compatibility_iterator node
= m_items
.Item( index
);
1368 wxCHECK_RET( node
, _T("invalid column index in SetImage()") );
1370 wxListItemData
*item
= node
->GetData();
1371 item
->SetImage(image
);
1374 int wxListLineData::GetImage( int index
) const
1376 wxListItemDataList::compatibility_iterator node
= m_items
.Item( index
);
1377 wxCHECK_MSG( node
, -1, _T("invalid column index in GetImage()") );
1379 wxListItemData
*item
= node
->GetData();
1380 return item
->GetImage();
1383 wxListItemAttr
*wxListLineData::GetAttr() const
1385 wxListItemDataList::compatibility_iterator node
= m_items
.GetFirst();
1386 wxCHECK_MSG( node
, NULL
, _T("invalid column index in GetAttr()") );
1388 wxListItemData
*item
= node
->GetData();
1389 return item
->GetAttr();
1392 void wxListLineData::SetAttr(wxListItemAttr
*attr
)
1394 wxListItemDataList::compatibility_iterator node
= m_items
.GetFirst();
1395 wxCHECK_RET( node
, _T("invalid column index in SetAttr()") );
1397 wxListItemData
*item
= node
->GetData();
1398 item
->SetAttr(attr
);
1401 bool wxListLineData::SetAttributes(wxDC
*dc
,
1402 const wxListItemAttr
*attr
,
1405 wxWindow
*listctrl
= m_owner
->GetParent();
1409 // don't use foreground colour for drawing highlighted items - this might
1410 // make them completely invisible (and there is no way to do bit
1411 // arithmetics on wxColour, unfortunately)
1414 colText
= wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHTTEXT
);
1415 else if ( attr
&& attr
->HasTextColour() )
1416 colText
= attr
->GetTextColour();
1418 colText
= listctrl
->GetForegroundColour();
1420 dc
->SetTextForeground(colText
);
1424 if ( attr
&& attr
->HasFont() )
1425 font
= attr
->GetFont();
1427 font
= listctrl
->GetFont();
1432 bool hasBgCol
= attr
&& attr
->HasBackgroundColour();
1433 if ( highlighted
|| hasBgCol
)
1436 dc
->SetBrush( *m_owner
->GetHighlightBrush() );
1438 dc
->SetBrush(wxBrush(attr
->GetBackgroundColour(), wxSOLID
));
1440 dc
->SetPen( *wxTRANSPARENT_PEN
);
1448 void wxListLineData::Draw( wxDC
*dc
)
1450 wxListItemDataList::compatibility_iterator node
= m_items
.GetFirst();
1451 wxCHECK_RET( node
, _T("no subitems at all??") );
1453 bool highlighted
= IsHighlighted();
1455 wxListItemAttr
*attr
= GetAttr();
1457 if ( SetAttributes(dc
, attr
, highlighted
) )
1458 dc
->DrawRectangle( m_gi
->m_rectHighlight
);
1460 // just for debugging to better see where the items are
1462 dc
->SetPen(*wxRED_PEN
);
1463 dc
->SetBrush(*wxTRANSPARENT_BRUSH
);
1464 dc
->DrawRectangle( m_gi
->m_rectAll
);
1465 dc
->SetPen(*wxGREEN_PEN
);
1466 dc
->DrawRectangle( m_gi
->m_rectIcon
);
1469 wxListItemData
*item
= node
->GetData();
1470 if (item
->HasImage())
1472 // centre the image inside our rectangle, this looks nicer when items
1473 // ae aligned in a row
1474 const wxRect
& rectIcon
= m_gi
->m_rectIcon
;
1476 m_owner
->DrawImage(item
->GetImage(), dc
, rectIcon
.x
, rectIcon
.y
);
1479 if (item
->HasText())
1481 const wxRect
& rectLabel
= m_gi
->m_rectLabel
;
1483 wxDCClipper
clipper(*dc
, rectLabel
);
1484 dc
->DrawText(item
->GetText(), rectLabel
.x
, rectLabel
.y
);
1488 void wxListLineData::DrawInReportMode( wxDC
*dc
,
1490 const wxRect
& rectHL
,
1493 // TODO: later we should support setting different attributes for
1494 // different columns - to do it, just add "col" argument to
1495 // GetAttr() and move these lines into the loop below
1496 wxListItemAttr
*attr
= GetAttr();
1497 if ( SetAttributes(dc
, attr
, highlighted
) )
1498 dc
->DrawRectangle( rectHL
);
1500 wxCoord x
= rect
.x
+ HEADER_OFFSET_X
,
1501 y
= rect
.y
+ (LINE_SPACING
+ EXTRA_HEIGHT
) / 2;
1504 for ( wxListItemDataList::compatibility_iterator node
= m_items
.GetFirst();
1506 node
= node
->GetNext(), col
++ )
1508 wxListItemData
*item
= node
->GetData();
1510 int width
= m_owner
->GetColumnWidth(col
);
1514 if ( item
->HasImage() )
1517 m_owner
->DrawImage( item
->GetImage(), dc
, xOld
, y
);
1518 m_owner
->GetImageSize( item
->GetImage(), ix
, iy
);
1520 ix
+= IMAGE_MARGIN_IN_REPORT_MODE
;
1526 wxDCClipper
clipper(*dc
, xOld
, y
, width
- 8, rect
.height
);
1528 if ( item
->HasText() )
1529 DrawTextFormatted(dc
, item
->GetText(), col
, xOld
, y
, width
- 8);
1533 void wxListLineData::DrawTextFormatted(wxDC
*dc
,
1534 const wxString
&text
,
1540 wxString drawntext
, ellipsis
;
1541 wxCoord w
, h
, base_w
;
1544 // determine if the string can fit inside the current width
1545 dc
->GetTextExtent(text
, &w
, &h
);
1548 // it can, draw it using the items alignment
1549 m_owner
->GetColumn(col
, item
);
1550 switch ( item
.GetAlign() )
1552 case wxLIST_FORMAT_LEFT
:
1556 case wxLIST_FORMAT_RIGHT
:
1560 case wxLIST_FORMAT_CENTER
:
1561 x
+= (width
- w
) / 2;
1565 wxFAIL_MSG( _T("unknown list item format") );
1569 dc
->DrawText(text
, x
, y
);
1571 else // otherwise, truncate and add an ellipsis if possible
1573 // determine the base width
1574 ellipsis
= wxString(wxT("..."));
1575 dc
->GetTextExtent(ellipsis
, &base_w
, &h
);
1577 // continue until we have enough space or only one character left
1579 size_t len
= text
.Length();
1580 drawntext
= text
.Left(len
);
1583 dc
->GetTextExtent(drawntext
.Last(), &w_c
, &h_c
);
1584 drawntext
.RemoveLast();
1587 if (w
+ base_w
<= width
)
1591 // if still not enough space, remove ellipsis characters
1592 while (ellipsis
.Length() > 0 && w
+ base_w
> width
)
1594 ellipsis
= ellipsis
.Left(ellipsis
.Length() - 1);
1595 dc
->GetTextExtent(ellipsis
, &base_w
, &h
);
1598 // now draw the text
1599 dc
->DrawText(drawntext
, x
, y
);
1600 dc
->DrawText(ellipsis
, x
+ w
, y
);
1604 bool wxListLineData::Highlight( bool on
)
1606 wxCHECK_MSG( !IsVirtual(), false, _T("unexpected call to Highlight") );
1608 if ( on
== m_highlighted
)
1616 void wxListLineData::ReverseHighlight( void )
1618 Highlight(!IsHighlighted());
1621 //-----------------------------------------------------------------------------
1622 // wxListHeaderWindow
1623 //-----------------------------------------------------------------------------
1625 IMPLEMENT_DYNAMIC_CLASS(wxListHeaderWindow
,wxWindow
)
1627 BEGIN_EVENT_TABLE(wxListHeaderWindow
,wxWindow
)
1628 EVT_PAINT (wxListHeaderWindow::OnPaint
)
1629 EVT_MOUSE_EVENTS (wxListHeaderWindow::OnMouse
)
1630 EVT_SET_FOCUS (wxListHeaderWindow::OnSetFocus
)
1633 void wxListHeaderWindow::Init()
1635 m_currentCursor
= (wxCursor
*) NULL
;
1636 m_isDragging
= false;
1640 wxListHeaderWindow::wxListHeaderWindow()
1644 m_owner
= (wxListMainWindow
*) NULL
;
1645 m_resizeCursor
= (wxCursor
*) NULL
;
1648 wxListHeaderWindow::wxListHeaderWindow( wxWindow
*win
,
1650 wxListMainWindow
*owner
,
1654 const wxString
&name
)
1655 : wxWindow( win
, id
, pos
, size
, style
, name
)
1660 m_resizeCursor
= new wxCursor( wxCURSOR_SIZEWE
);
1663 wxVisualAttributes attr
= wxPanel::GetClassDefaultAttributes();
1664 SetOwnForegroundColour( attr
.colFg
);
1665 SetOwnBackgroundColour( attr
.colBg
);
1667 SetOwnFont( attr
.font
);
1669 SetOwnForegroundColour( wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT
));
1670 SetOwnBackgroundColour( wxSystemSettings::GetColour(wxSYS_COLOUR_BTNFACE
));
1672 SetOwnFont( wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT
));
1676 wxListHeaderWindow::~wxListHeaderWindow()
1678 delete m_resizeCursor
;
1681 #ifdef __WXUNIVERSAL__
1682 #include "wx/univ/renderer.h"
1683 #include "wx/univ/theme.h"
1686 // shift the DC origin to match the position of the main window horz
1687 // scrollbar: this allows us to always use logical coords
1688 void wxListHeaderWindow::AdjustDC(wxDC
& dc
)
1691 m_owner
->GetScrollPixelsPerUnit( &xpix
, NULL
);
1694 m_owner
->GetViewStart( &x
, NULL
);
1696 // account for the horz scrollbar offset
1697 dc
.SetDeviceOrigin( -x
* xpix
, 0 );
1700 void wxListHeaderWindow::OnPaint( wxPaintEvent
&WXUNUSED(event
) )
1702 wxPaintDC
dc( this );
1707 dc
.SetFont( GetFont() );
1709 // width and height of the entire header window
1711 GetClientSize( &w
, &h
);
1712 m_owner
->CalcUnscrolledPosition(w
, 0, &w
, NULL
);
1714 dc
.SetBackgroundMode(wxTRANSPARENT
);
1715 dc
.SetTextForeground(GetForegroundColour());
1717 int x
= HEADER_OFFSET_X
;
1718 int numColumns
= m_owner
->GetColumnCount();
1720 for ( int i
= 0; i
< numColumns
&& x
< w
; i
++ )
1722 m_owner
->GetColumn( i
, item
);
1723 int wCol
= item
.m_width
;
1725 // the width of the rect to draw: make it smaller to fit entirely
1726 // inside the column rect
1735 wxRendererNative::Get().DrawHeaderButton
1739 wxRect(x
, HEADER_OFFSET_Y
, cw
, ch
),
1740 m_parent
->IsEnabled() ? 0
1741 : (int)wxCONTROL_DISABLED
1744 // see if we have enough space for the column label
1746 // for this we need the width of the text
1749 dc
.GetTextExtent(item
.GetText(), &wLabel
, &hLabel
);
1750 wLabel
+= 2 * EXTRA_WIDTH
;
1752 // and the width of the icon, if any
1753 static const int MARGIN_BETWEEN_TEXT_AND_ICON
= 2;
1754 int ix
= 0, iy
= 0; // init them just to suppress the compiler warnings
1755 const int image
= item
.m_image
;
1756 wxImageListType
*imageList
;
1759 imageList
= m_owner
->m_small_image_list
;
1762 imageList
->GetSize(image
, ix
, iy
);
1763 wLabel
+= ix
+ MARGIN_BETWEEN_TEXT_AND_ICON
;
1771 // ignore alignment if there is not enough space anyhow
1773 switch ( wLabel
< cw
? item
.GetAlign() : wxLIST_FORMAT_LEFT
)
1776 wxFAIL_MSG( _T("unknown list item format") );
1779 case wxLIST_FORMAT_LEFT
:
1783 case wxLIST_FORMAT_RIGHT
:
1784 xAligned
= x
+ cw
- wLabel
;
1787 case wxLIST_FORMAT_CENTER
:
1788 xAligned
= x
+ (cw
- wLabel
) / 2;
1792 // if we have an image, draw it on the right of the label
1799 xAligned
+ wLabel
- ix
- MARGIN_BETWEEN_TEXT_AND_ICON
,
1800 HEADER_OFFSET_Y
+ (h
- 4 - iy
)/2,
1801 wxIMAGELIST_DRAW_TRANSPARENT
1804 cw
-= ix
+ MARGIN_BETWEEN_TEXT_AND_ICON
;
1807 // draw the text clipping it so that it doesn't overwrite the column
1809 wxDCClipper
clipper(dc
, x
, HEADER_OFFSET_Y
, cw
, h
- 4 );
1811 dc
.DrawText( item
.GetText(),
1812 xAligned
+ EXTRA_WIDTH
, h
/ 2 - hLabel
/ 2 ); //HEADER_OFFSET_Y + EXTRA_HEIGHT );
1818 void wxListHeaderWindow::DrawCurrent()
1820 int x1
= m_currentX
;
1822 m_owner
->ClientToScreen( &x1
, &y1
);
1824 int x2
= m_currentX
;
1826 m_owner
->GetClientSize( NULL
, &y2
);
1827 m_owner
->ClientToScreen( &x2
, &y2
);
1830 dc
.SetLogicalFunction( wxINVERT
);
1831 dc
.SetPen( wxPen( *wxBLACK
, 2, wxSOLID
) );
1832 dc
.SetBrush( *wxTRANSPARENT_BRUSH
);
1836 dc
.DrawLine( x1
, y1
, x2
, y2
);
1838 dc
.SetLogicalFunction( wxCOPY
);
1840 dc
.SetPen( wxNullPen
);
1841 dc
.SetBrush( wxNullBrush
);
1844 void wxListHeaderWindow::OnMouse( wxMouseEvent
&event
)
1846 // we want to work with logical coords
1848 m_owner
->CalcUnscrolledPosition(event
.GetX(), 0, &x
, NULL
);
1849 int y
= event
.GetY();
1853 SendListEvent(wxEVT_COMMAND_LIST_COL_DRAGGING
, event
.GetPosition());
1855 // we don't draw the line beyond our window, but we allow dragging it
1858 GetClientSize( &w
, NULL
);
1859 m_owner
->CalcUnscrolledPosition(w
, 0, &w
, NULL
);
1862 // erase the line if it was drawn
1863 if ( m_currentX
< w
)
1866 if (event
.ButtonUp())
1869 m_isDragging
= false;
1871 m_owner
->SetColumnWidth( m_column
, m_currentX
- m_minX
);
1872 SendListEvent(wxEVT_COMMAND_LIST_COL_END_DRAG
, event
.GetPosition());
1879 m_currentX
= m_minX
+ 7;
1881 // draw in the new location
1882 if ( m_currentX
< w
)
1886 else // not dragging
1889 bool hit_border
= false;
1891 // end of the current column
1894 // find the column where this event occurred
1896 countCol
= m_owner
->GetColumnCount();
1897 for (col
= 0; col
< countCol
; col
++)
1899 xpos
+= m_owner
->GetColumnWidth( col
);
1902 if ( (abs(x
-xpos
) < 3) && (y
< 22) )
1904 // near the column border
1911 // inside the column
1918 if ( col
== countCol
)
1921 if (event
.LeftDown() || event
.RightUp())
1923 if (hit_border
&& event
.LeftDown())
1925 if ( SendListEvent(wxEVT_COMMAND_LIST_COL_BEGIN_DRAG
,
1926 event
.GetPosition()) )
1928 m_isDragging
= true;
1933 //else: column resizing was vetoed by the user code
1935 else // click on a column
1937 SendListEvent( event
.LeftDown()
1938 ? wxEVT_COMMAND_LIST_COL_CLICK
1939 : wxEVT_COMMAND_LIST_COL_RIGHT_CLICK
,
1940 event
.GetPosition());
1943 else if (event
.Moving())
1948 setCursor
= m_currentCursor
== wxSTANDARD_CURSOR
;
1949 m_currentCursor
= m_resizeCursor
;
1953 setCursor
= m_currentCursor
!= wxSTANDARD_CURSOR
;
1954 m_currentCursor
= wxSTANDARD_CURSOR
;
1958 SetCursor(*m_currentCursor
);
1963 void wxListHeaderWindow::OnSetFocus( wxFocusEvent
&WXUNUSED(event
) )
1965 m_owner
->SetFocus();
1969 bool wxListHeaderWindow::SendListEvent(wxEventType type
, const wxPoint
& pos
)
1971 wxWindow
*parent
= GetParent();
1972 wxListEvent
le( type
, parent
->GetId() );
1973 le
.SetEventObject( parent
);
1974 le
.m_pointDrag
= pos
;
1976 // the position should be relative to the parent window, not
1977 // this one for compatibility with MSW and common sense: the
1978 // user code doesn't know anything at all about this header
1979 // window, so why should it get positions relative to it?
1980 le
.m_pointDrag
.y
-= GetSize().y
;
1982 le
.m_col
= m_column
;
1983 return !parent
->GetEventHandler()->ProcessEvent( le
) || le
.IsAllowed();
1986 //-----------------------------------------------------------------------------
1987 // wxListRenameTimer (internal)
1988 //-----------------------------------------------------------------------------
1990 wxListRenameTimer::wxListRenameTimer( wxListMainWindow
*owner
)
1995 void wxListRenameTimer::Notify()
1997 m_owner
->OnRenameTimer();
2000 //-----------------------------------------------------------------------------
2001 // wxListTextCtrlWrapper (internal)
2002 //-----------------------------------------------------------------------------
2004 BEGIN_EVENT_TABLE(wxListTextCtrlWrapper
, wxEvtHandler
)
2005 EVT_CHAR (wxListTextCtrlWrapper::OnChar
)
2006 EVT_KEY_UP (wxListTextCtrlWrapper::OnKeyUp
)
2007 EVT_KILL_FOCUS (wxListTextCtrlWrapper::OnKillFocus
)
2010 wxListTextCtrlWrapper::wxListTextCtrlWrapper(wxListMainWindow
*owner
,
2013 : m_startValue(owner
->GetItemText(itemEdit
)),
2014 m_itemEdited(itemEdit
)
2019 m_aboutToFinish
= false;
2021 wxRect rectLabel
= owner
->GetLineLabelRect(itemEdit
);
2023 m_owner
->CalcScrolledPosition(rectLabel
.x
, rectLabel
.y
,
2024 &rectLabel
.x
, &rectLabel
.y
);
2026 m_text
->Create(owner
, wxID_ANY
, m_startValue
,
2027 wxPoint(rectLabel
.x
-4,rectLabel
.y
-4),
2028 wxSize(rectLabel
.width
+11,rectLabel
.height
+8));
2029 m_text
->PushEventHandler(this);
2032 void wxListTextCtrlWrapper::Finish()
2038 m_text
->PopEventHandler(this);
2039 m_owner
->FinishEditing(m_text
);
2045 bool wxListTextCtrlWrapper::AcceptChanges()
2047 const wxString value
= m_text
->GetValue();
2049 if ( value
== m_startValue
)
2050 // nothing changed, always accept
2053 if ( !m_owner
->OnRenameAccept(m_itemEdited
, value
) )
2054 // vetoed by the user
2057 // accepted, do rename the item
2058 m_owner
->SetItemText(m_itemEdited
, value
);
2063 void wxListTextCtrlWrapper::AcceptChangesAndFinish()
2065 m_aboutToFinish
= true;
2067 // Notify the owner about the changes
2070 // Even if vetoed, close the control (consistent with MSW)
2074 void wxListTextCtrlWrapper::OnChar( wxKeyEvent
&event
)
2076 switch ( event
.m_keyCode
)
2079 AcceptChangesAndFinish();
2084 m_owner
->OnRenameCancelled( m_itemEdited
);
2092 void wxListTextCtrlWrapper::OnKeyUp( wxKeyEvent
&event
)
2100 // auto-grow the textctrl:
2101 wxSize parentSize
= m_owner
->GetSize();
2102 wxPoint myPos
= m_text
->GetPosition();
2103 wxSize mySize
= m_text
->GetSize();
2105 m_text
->GetTextExtent(m_text
->GetValue() + _T("MM"), &sx
, &sy
);
2106 if (myPos
.x
+ sx
> parentSize
.x
)
2107 sx
= parentSize
.x
- myPos
.x
;
2110 m_text
->SetSize(sx
, wxDefaultCoord
);
2115 void wxListTextCtrlWrapper::OnKillFocus( wxFocusEvent
&event
)
2117 if ( !m_finished
&& !m_aboutToFinish
)
2119 // We must finish regardless of success, otherwise we'll get
2123 if ( !AcceptChanges() )
2124 m_owner
->OnRenameCancelled( m_itemEdited
);
2127 // We must let the native text control handle focus, too, otherwise
2128 // it could have problems with the cursor (e.g., in wxGTK).
2132 //-----------------------------------------------------------------------------
2134 //-----------------------------------------------------------------------------
2136 IMPLEMENT_DYNAMIC_CLASS(wxListMainWindow
,wxScrolledWindow
)
2138 BEGIN_EVENT_TABLE(wxListMainWindow
,wxScrolledWindow
)
2139 EVT_PAINT (wxListMainWindow::OnPaint
)
2140 EVT_MOUSE_EVENTS (wxListMainWindow::OnMouse
)
2141 EVT_CHAR (wxListMainWindow::OnChar
)
2142 EVT_KEY_DOWN (wxListMainWindow::OnKeyDown
)
2143 EVT_SET_FOCUS (wxListMainWindow::OnSetFocus
)
2144 EVT_KILL_FOCUS (wxListMainWindow::OnKillFocus
)
2145 EVT_SCROLLWIN (wxListMainWindow::OnScroll
)
2148 void wxListMainWindow::Init()
2153 m_lineTo
= (size_t)-1;
2159 m_small_image_list
= (wxImageListType
*) NULL
;
2160 m_normal_image_list
= (wxImageListType
*) NULL
;
2162 m_small_spacing
= 30;
2163 m_normal_spacing
= 40;
2167 m_isCreated
= false;
2169 m_lastOnSame
= false;
2170 m_renameTimer
= new wxListRenameTimer( this );
2171 m_textctrlWrapper
= NULL
;
2175 m_lineSelectSingleOnUp
=
2176 m_lineBeforeLastClicked
= (size_t)-1;
2181 wxListMainWindow::wxListMainWindow()
2186 m_highlightUnfocusedBrush
= (wxBrush
*) NULL
;
2189 wxListMainWindow::wxListMainWindow( wxWindow
*parent
,
2194 const wxString
&name
)
2195 : wxScrolledWindow( parent
, id
, pos
, size
,
2196 style
| wxHSCROLL
| wxVSCROLL
, name
)
2200 m_highlightBrush
= new wxBrush
2202 wxSystemSettings::GetColour
2204 wxSYS_COLOUR_HIGHLIGHT
2209 m_highlightUnfocusedBrush
= new wxBrush
2211 wxSystemSettings::GetColour
2213 wxSYS_COLOUR_BTNSHADOW
2218 SetScrollbars( 0, 0, 0, 0, 0, 0 );
2220 wxVisualAttributes attr
= wxGenericListCtrl::GetClassDefaultAttributes();
2221 SetOwnForegroundColour( attr
.colFg
);
2222 SetOwnBackgroundColour( attr
.colBg
);
2224 SetOwnFont( attr
.font
);
2227 wxListMainWindow::~wxListMainWindow()
2230 WX_CLEAR_LIST(wxListHeaderDataList
, m_columns
);
2231 WX_CLEAR_ARRAY(m_aColWidths
);
2233 delete m_highlightBrush
;
2234 delete m_highlightUnfocusedBrush
;
2235 delete m_renameTimer
;
2238 void wxListMainWindow::CacheLineData(size_t line
)
2240 wxGenericListCtrl
*listctrl
= GetListCtrl();
2242 wxListLineData
*ld
= GetDummyLine();
2244 size_t countCol
= GetColumnCount();
2245 for ( size_t col
= 0; col
< countCol
; col
++ )
2247 ld
->SetText(col
, listctrl
->OnGetItemText(line
, col
));
2248 ld
->SetImage(col
, listctrl
->OnGetItemColumnImage(line
, col
));
2251 ld
->SetAttr(listctrl
->OnGetItemAttr(line
));
2254 wxListLineData
*wxListMainWindow::GetDummyLine() const
2256 wxASSERT_MSG( !IsEmpty(), _T("invalid line index") );
2257 wxASSERT_MSG( IsVirtual(), _T("GetDummyLine() shouldn't be called") );
2259 wxListMainWindow
*self
= wxConstCast(this, wxListMainWindow
);
2261 // we need to recreate the dummy line if the number of columns in the
2262 // control changed as it would have the incorrect number of fields
2264 if ( !m_lines
.IsEmpty() &&
2265 m_lines
[0].m_items
.GetCount() != (size_t)GetColumnCount() )
2267 self
->m_lines
.Clear();
2270 if ( m_lines
.IsEmpty() )
2272 wxListLineData
*line
= new wxListLineData(self
);
2273 self
->m_lines
.Add(line
);
2275 // don't waste extra memory -- there never going to be anything
2276 // else/more in this array
2277 self
->m_lines
.Shrink();
2283 // ----------------------------------------------------------------------------
2284 // line geometry (report mode only)
2285 // ----------------------------------------------------------------------------
2287 wxCoord
wxListMainWindow::GetLineHeight() const
2289 // we cache the line height as calling GetTextExtent() is slow
2290 if ( !m_lineHeight
)
2292 wxListMainWindow
*self
= wxConstCast(this, wxListMainWindow
);
2294 wxClientDC
dc( self
);
2295 dc
.SetFont( GetFont() );
2298 dc
.GetTextExtent(_T("H"), NULL
, &y
);
2300 if ( m_small_image_list
&& m_small_image_list
->GetImageCount() )
2303 m_small_image_list
->GetSize(0, iw
, ih
);
2308 self
->m_lineHeight
= y
+ LINE_SPACING
;
2311 return m_lineHeight
;
2314 wxCoord
wxListMainWindow::GetLineY(size_t line
) const
2316 wxASSERT_MSG( InReportView(), _T("only works in report mode") );
2318 return LINE_SPACING
+ line
* GetLineHeight();
2321 wxRect
wxListMainWindow::GetLineRect(size_t line
) const
2323 if ( !InReportView() )
2324 return GetLine(line
)->m_gi
->m_rectAll
;
2327 rect
.x
= HEADER_OFFSET_X
;
2328 rect
.y
= GetLineY(line
);
2329 rect
.width
= GetHeaderWidth();
2330 rect
.height
= GetLineHeight();
2335 wxRect
wxListMainWindow::GetLineLabelRect(size_t line
) const
2337 if ( !InReportView() )
2338 return GetLine(line
)->m_gi
->m_rectLabel
;
2341 rect
.x
= HEADER_OFFSET_X
;
2342 rect
.y
= GetLineY(line
);
2343 rect
.width
= GetColumnWidth(0);
2344 rect
.height
= GetLineHeight();
2349 wxRect
wxListMainWindow::GetLineIconRect(size_t line
) const
2351 if ( !InReportView() )
2352 return GetLine(line
)->m_gi
->m_rectIcon
;
2354 wxListLineData
*ld
= GetLine(line
);
2355 wxASSERT_MSG( ld
->HasImage(), _T("should have an image") );
2358 rect
.x
= HEADER_OFFSET_X
;
2359 rect
.y
= GetLineY(line
);
2360 GetImageSize(ld
->GetImage(), rect
.width
, rect
.height
);
2365 wxRect
wxListMainWindow::GetLineHighlightRect(size_t line
) const
2367 return InReportView() ? GetLineRect(line
)
2368 : GetLine(line
)->m_gi
->m_rectHighlight
;
2371 long wxListMainWindow::HitTestLine(size_t line
, int x
, int y
) const
2373 wxASSERT_MSG( line
< GetItemCount(), _T("invalid line in HitTestLine") );
2375 wxListLineData
*ld
= GetLine(line
);
2377 if ( ld
->HasImage() && GetLineIconRect(line
).Inside(x
, y
) )
2378 return wxLIST_HITTEST_ONITEMICON
;
2380 // VS: Testing for "ld->HasText() || InReportView()" instead of
2381 // "ld->HasText()" is needed to make empty lines in report view
2383 if ( ld
->HasText() || InReportView() )
2385 wxRect rect
= InReportView() ? GetLineRect(line
)
2386 : GetLineLabelRect(line
);
2388 if ( rect
.Inside(x
, y
) )
2389 return wxLIST_HITTEST_ONITEMLABEL
;
2395 // ----------------------------------------------------------------------------
2396 // highlight (selection) handling
2397 // ----------------------------------------------------------------------------
2399 bool wxListMainWindow::IsHighlighted(size_t line
) const
2403 return m_selStore
.IsSelected(line
);
2407 wxListLineData
*ld
= GetLine(line
);
2408 wxCHECK_MSG( ld
, false, _T("invalid index in IsHighlighted") );
2410 return ld
->IsHighlighted();
2414 void wxListMainWindow::HighlightLines( size_t lineFrom
,
2420 wxArrayInt linesChanged
;
2421 if ( !m_selStore
.SelectRange(lineFrom
, lineTo
, highlight
,
2424 // meny items changed state, refresh everything
2425 RefreshLines(lineFrom
, lineTo
);
2427 else // only a few items changed state, refresh only them
2429 size_t count
= linesChanged
.GetCount();
2430 for ( size_t n
= 0; n
< count
; n
++ )
2432 RefreshLine(linesChanged
[n
]);
2436 else // iterate over all items in non report view
2438 for ( size_t line
= lineFrom
; line
<= lineTo
; line
++ )
2440 if ( HighlightLine(line
, highlight
) )
2446 bool wxListMainWindow::HighlightLine( size_t line
, bool highlight
)
2452 changed
= m_selStore
.SelectItem(line
, highlight
);
2456 wxListLineData
*ld
= GetLine(line
);
2457 wxCHECK_MSG( ld
, false, _T("invalid index in HighlightLine") );
2459 changed
= ld
->Highlight(highlight
);
2464 SendNotify( line
, highlight
? wxEVT_COMMAND_LIST_ITEM_SELECTED
2465 : wxEVT_COMMAND_LIST_ITEM_DESELECTED
);
2471 void wxListMainWindow::RefreshLine( size_t line
)
2473 if ( InReportView() )
2475 size_t visibleFrom
, visibleTo
;
2476 GetVisibleLinesRange(&visibleFrom
, &visibleTo
);
2478 if ( line
< visibleFrom
|| line
> visibleTo
)
2482 wxRect rect
= GetLineRect(line
);
2484 CalcScrolledPosition( rect
.x
, rect
.y
, &rect
.x
, &rect
.y
);
2485 RefreshRect( rect
);
2488 void wxListMainWindow::RefreshLines( size_t lineFrom
, size_t lineTo
)
2490 // we suppose that they are ordered by caller
2491 wxASSERT_MSG( lineFrom
<= lineTo
, _T("indices in disorder") );
2493 wxASSERT_MSG( lineTo
< GetItemCount(), _T("invalid line range") );
2495 if ( InReportView() )
2497 size_t visibleFrom
, visibleTo
;
2498 GetVisibleLinesRange(&visibleFrom
, &visibleTo
);
2500 if ( lineFrom
< visibleFrom
)
2501 lineFrom
= visibleFrom
;
2502 if ( lineTo
> visibleTo
)
2507 rect
.y
= GetLineY(lineFrom
);
2508 rect
.width
= GetClientSize().x
;
2509 rect
.height
= GetLineY(lineTo
) - rect
.y
+ GetLineHeight();
2511 CalcScrolledPosition( rect
.x
, rect
.y
, &rect
.x
, &rect
.y
);
2512 RefreshRect( rect
);
2516 // TODO: this should be optimized...
2517 for ( size_t line
= lineFrom
; line
<= lineTo
; line
++ )
2524 void wxListMainWindow::RefreshAfter( size_t lineFrom
)
2526 if ( InReportView() )
2528 size_t visibleFrom
, visibleTo
;
2529 GetVisibleLinesRange(&visibleFrom
, &visibleTo
);
2531 if ( lineFrom
< visibleFrom
)
2532 lineFrom
= visibleFrom
;
2533 else if ( lineFrom
> visibleTo
)
2538 rect
.y
= GetLineY(lineFrom
);
2539 CalcScrolledPosition( rect
.x
, rect
.y
, &rect
.x
, &rect
.y
);
2541 wxSize size
= GetClientSize();
2542 rect
.width
= size
.x
;
2544 // refresh till the bottom of the window
2545 rect
.height
= size
.y
- rect
.y
;
2547 RefreshRect( rect
);
2551 // TODO: how to do it more efficiently?
2556 void wxListMainWindow::RefreshSelected()
2562 if ( InReportView() )
2564 GetVisibleLinesRange(&from
, &to
);
2569 to
= GetItemCount() - 1;
2572 if ( HasCurrent() && m_current
>= from
&& m_current
<= to
)
2573 RefreshLine(m_current
);
2575 for ( size_t line
= from
; line
<= to
; line
++ )
2577 // NB: the test works as expected even if m_current == -1
2578 if ( line
!= m_current
&& IsHighlighted(line
) )
2583 void wxListMainWindow::Freeze()
2588 void wxListMainWindow::Thaw()
2590 wxCHECK_RET( m_freezeCount
> 0, _T("thawing unfrozen list control?") );
2592 if ( --m_freezeCount
== 0 )
2596 void wxListMainWindow::OnPaint( wxPaintEvent
&WXUNUSED(event
) )
2598 // Note: a wxPaintDC must be constructed even if no drawing is
2599 // done (a Windows requirement).
2600 wxPaintDC
dc( this );
2602 if ( IsEmpty() || m_freezeCount
)
2603 // nothing to draw or not the moment to draw it
2607 // delay the repainting until we calculate all the items positions
2613 CalcScrolledPosition( 0, 0, &dev_x
, &dev_y
);
2615 dc
.SetFont( GetFont() );
2617 if ( InReportView() )
2619 int lineHeight
= GetLineHeight();
2621 size_t visibleFrom
, visibleTo
;
2622 GetVisibleLinesRange(&visibleFrom
, &visibleTo
);
2625 wxCoord xOrig
, yOrig
;
2626 CalcUnscrolledPosition(0, 0, &xOrig
, &yOrig
);
2628 // tell the caller cache to cache the data
2631 wxListEvent
evCache(wxEVT_COMMAND_LIST_CACHE_HINT
,
2632 GetParent()->GetId());
2633 evCache
.SetEventObject( GetParent() );
2634 evCache
.m_oldItemIndex
= visibleFrom
;
2635 evCache
.m_itemIndex
= visibleTo
;
2636 GetParent()->GetEventHandler()->ProcessEvent( evCache
);
2639 for ( size_t line
= visibleFrom
; line
<= visibleTo
; line
++ )
2641 rectLine
= GetLineRect(line
);
2643 if ( !IsExposed(rectLine
.x
- xOrig
, rectLine
.y
- yOrig
,
2644 rectLine
.width
, rectLine
.height
) )
2646 // don't redraw unaffected lines to avoid flicker
2650 GetLine(line
)->DrawInReportMode( &dc
,
2652 GetLineHighlightRect(line
),
2653 IsHighlighted(line
) );
2656 if ( HasFlag(wxLC_HRULES
) )
2658 wxPen
pen(GetRuleColour(), 1, wxSOLID
);
2659 wxSize clientSize
= GetClientSize();
2661 // Don't draw the first one
2662 for ( size_t i
= visibleFrom
+ 1; i
<= visibleTo
; i
++ )
2665 dc
.SetBrush( *wxTRANSPARENT_BRUSH
);
2666 dc
.DrawLine(0 - dev_x
, i
* lineHeight
,
2667 clientSize
.x
- dev_x
, i
* lineHeight
);
2670 // Draw last horizontal rule
2671 if ( visibleTo
== GetItemCount() - 1 )
2674 dc
.SetBrush( *wxTRANSPARENT_BRUSH
);
2675 dc
.DrawLine(0 - dev_x
, (m_lineTo
+ 1) * lineHeight
,
2676 clientSize
.x
- dev_x
, (m_lineTo
+ 1) * lineHeight
);
2680 // Draw vertical rules if required
2681 if ( HasFlag(wxLC_VRULES
) && !IsEmpty() )
2683 wxPen
pen(GetRuleColour(), 1, wxSOLID
);
2684 wxRect firstItemRect
, lastItemRect
;
2686 GetItemRect(visibleFrom
, firstItemRect
);
2687 GetItemRect(visibleTo
, lastItemRect
);
2688 int x
= firstItemRect
.GetX();
2690 dc
.SetBrush(* wxTRANSPARENT_BRUSH
);
2692 for (int col
= 0; col
< GetColumnCount(); col
++)
2694 int colWidth
= GetColumnWidth(col
);
2696 dc
.DrawLine(x
- dev_x
- 2, firstItemRect
.GetY() - 1 - dev_y
,
2697 x
- dev_x
- 2, lastItemRect
.GetBottom() + 1 - dev_y
);
2703 size_t count
= GetItemCount();
2704 for ( size_t i
= 0; i
< count
; i
++ )
2706 GetLine(i
)->Draw( &dc
);
2711 // Don't draw rect outline under Mac at all.
2716 dc
.SetPen( *wxBLACK_PEN
);
2717 dc
.SetBrush( *wxTRANSPARENT_BRUSH
);
2718 dc
.DrawRectangle( GetLineHighlightRect( m_current
) );
2724 void wxListMainWindow::HighlightAll( bool on
)
2726 if ( IsSingleSel() )
2728 wxASSERT_MSG( !on
, _T("can't do this in a single selection control") );
2730 // we just have one item to turn off
2731 if ( HasCurrent() && IsHighlighted(m_current
) )
2733 HighlightLine(m_current
, false);
2734 RefreshLine(m_current
);
2739 HighlightLines(0, GetItemCount() - 1, on
);
2743 void wxListMainWindow::SendNotify( size_t line
,
2744 wxEventType command
,
2745 const wxPoint
& point
)
2747 wxListEvent
le( command
, GetParent()->GetId() );
2748 le
.SetEventObject( GetParent() );
2749 le
.m_itemIndex
= line
;
2751 // set only for events which have position
2752 if ( point
!= wxDefaultPosition
)
2753 le
.m_pointDrag
= point
;
2755 // don't try to get the line info for virtual list controls: the main
2756 // program has it anyhow and if we did it would result in accessing all
2757 // the lines, even those which are not visible now and this is precisely
2758 // what we're trying to avoid
2759 if ( !IsVirtual() && (command
!= wxEVT_COMMAND_LIST_DELETE_ITEM
) )
2761 if ( line
!= (size_t)-1 )
2763 GetLine(line
)->GetItem( 0, le
.m_item
);
2765 //else: this happens for wxEVT_COMMAND_LIST_ITEM_FOCUSED event
2767 //else: there may be no more such item
2769 GetParent()->GetEventHandler()->ProcessEvent( le
);
2772 void wxListMainWindow::ChangeCurrent(size_t current
)
2774 m_current
= current
;
2776 SendNotify(current
, wxEVT_COMMAND_LIST_ITEM_FOCUSED
);
2779 wxTextCtrl
*wxListMainWindow::EditLabel(long item
, wxClassInfo
* textControlClass
)
2781 wxCHECK_MSG( (item
>= 0) && ((size_t)item
< GetItemCount()), NULL
,
2782 wxT("wrong index in wxGenericListCtrl::EditLabel()") );
2784 wxASSERT_MSG( textControlClass
->IsKindOf(CLASSINFO(wxTextCtrl
)),
2785 wxT("EditLabel() needs a text control") );
2787 size_t itemEdit
= (size_t)item
;
2789 wxListEvent
le( wxEVT_COMMAND_LIST_BEGIN_LABEL_EDIT
, GetParent()->GetId() );
2790 le
.SetEventObject( GetParent() );
2791 le
.m_itemIndex
= item
;
2792 wxListLineData
*data
= GetLine(itemEdit
);
2793 wxCHECK_MSG( data
, NULL
, _T("invalid index in EditLabel()") );
2794 data
->GetItem( 0, le
.m_item
);
2796 if ( GetParent()->GetEventHandler()->ProcessEvent( le
) && !le
.IsAllowed() )
2798 // vetoed by user code
2802 // We have to call this here because the label in question might just have
2803 // been added and no screen update taken place.
2807 wxTextCtrl
* const text
= (wxTextCtrl
*)textControlClass
->CreateObject();
2808 m_textctrlWrapper
= new wxListTextCtrlWrapper(this, text
, item
);
2809 return m_textctrlWrapper
->GetText();
2812 void wxListMainWindow::OnRenameTimer()
2814 wxCHECK_RET( HasCurrent(), wxT("unexpected rename timer") );
2816 EditLabel( m_current
);
2819 bool wxListMainWindow::OnRenameAccept(size_t itemEdit
, const wxString
& value
)
2821 wxListEvent
le( wxEVT_COMMAND_LIST_END_LABEL_EDIT
, GetParent()->GetId() );
2822 le
.SetEventObject( GetParent() );
2823 le
.m_itemIndex
= itemEdit
;
2825 wxListLineData
*data
= GetLine(itemEdit
);
2827 wxCHECK_MSG( data
, false, _T("invalid index in OnRenameAccept()") );
2829 data
->GetItem( 0, le
.m_item
);
2830 le
.m_item
.m_text
= value
;
2831 return !GetParent()->GetEventHandler()->ProcessEvent( le
) ||
2835 void wxListMainWindow::OnRenameCancelled(size_t itemEdit
)
2837 // let owner know that the edit was cancelled
2838 wxListEvent
le( wxEVT_COMMAND_LIST_END_LABEL_EDIT
, GetParent()->GetId() );
2840 le
.SetEditCanceled(true);
2842 le
.SetEventObject( GetParent() );
2843 le
.m_itemIndex
= itemEdit
;
2845 wxListLineData
*data
= GetLine(itemEdit
);
2846 wxCHECK_RET( data
, _T("invalid index in OnRenameCancelled()") );
2848 data
->GetItem( 0, le
.m_item
);
2849 GetEventHandler()->ProcessEvent( le
);
2852 void wxListMainWindow::OnMouse( wxMouseEvent
&event
)
2855 // On wxMac we can't depend on the EVT_KILL_FOCUS event to properly
2856 // shutdown the edit control when the mouse is clicked elsewhere on the
2857 // listctrl because the order of events is different (or something like
2858 // that), so explicitly end the edit if it is active.
2859 if ( event
.LeftDown() && m_textctrlWrapper
)
2860 m_textctrlWrapper
->AcceptChangesAndFinish();
2863 event
.SetEventObject( GetParent() );
2864 if ( GetParent()->GetEventHandler()->ProcessEvent( event
) )
2867 if (event
.GetEventType() == wxEVT_MOUSEWHEEL
)
2869 // let the base handle mouse wheel events.
2874 if ( !HasCurrent() || IsEmpty() )
2880 if ( !(event
.Dragging() || event
.ButtonDown() || event
.LeftUp() ||
2881 event
.ButtonDClick()) )
2884 int x
= event
.GetX();
2885 int y
= event
.GetY();
2886 CalcUnscrolledPosition( x
, y
, &x
, &y
);
2888 // where did we hit it (if we did)?
2891 size_t count
= GetItemCount(),
2894 if ( InReportView() )
2896 current
= y
/ GetLineHeight();
2897 if ( current
< count
)
2898 hitResult
= HitTestLine(current
, x
, y
);
2902 // TODO: optimize it too! this is less simple than for report view but
2903 // enumerating all items is still not a way to do it!!
2904 for ( current
= 0; current
< count
; current
++ )
2906 hitResult
= HitTestLine(current
, x
, y
);
2912 if (event
.Dragging())
2914 if (m_dragCount
== 0)
2916 // we have to report the raw, physical coords as we want to be
2917 // able to call HitTest(event.m_pointDrag) from the user code to
2918 // get the item being dragged
2919 m_dragStart
= event
.GetPosition();
2924 if (m_dragCount
!= 3)
2927 int command
= event
.RightIsDown() ? wxEVT_COMMAND_LIST_BEGIN_RDRAG
2928 : wxEVT_COMMAND_LIST_BEGIN_DRAG
;
2930 wxListEvent
le( command
, GetParent()->GetId() );
2931 le
.SetEventObject( GetParent() );
2932 le
.m_itemIndex
= m_lineLastClicked
;
2933 le
.m_pointDrag
= m_dragStart
;
2934 GetParent()->GetEventHandler()->ProcessEvent( le
);
2945 // outside of any item
2949 bool forceClick
= false;
2950 if (event
.ButtonDClick())
2952 m_renameTimer
->Stop();
2953 m_lastOnSame
= false;
2955 if ( current
== m_lineLastClicked
)
2957 SendNotify( current
, wxEVT_COMMAND_LIST_ITEM_ACTIVATED
);
2963 // The first click was on another item, so don't interpret this as
2964 // a double click, but as a simple click instead
2971 if (m_lineSelectSingleOnUp
!= (size_t)-1)
2973 // select single line
2974 HighlightAll( false );
2975 ReverseHighlight(m_lineSelectSingleOnUp
);
2980 if ((current
== m_current
) &&
2981 (hitResult
== wxLIST_HITTEST_ONITEMLABEL
) &&
2982 HasFlag(wxLC_EDIT_LABELS
) )
2984 m_renameTimer
->Start( 100, true );
2988 m_lastOnSame
= false;
2989 m_lineSelectSingleOnUp
= (size_t)-1;
2993 // This is necessary, because after a DnD operation in
2994 // from and to ourself, the up event is swallowed by the
2995 // DnD code. So on next non-up event (which means here and
2996 // now) m_lineSelectSingleOnUp should be reset.
2997 m_lineSelectSingleOnUp
= (size_t)-1;
2999 if (event
.RightDown())
3001 m_lineBeforeLastClicked
= m_lineLastClicked
;
3002 m_lineLastClicked
= current
;
3004 // If the item is already selected, do not update the selection.
3005 // Multi-selections should not be cleared if a selected item is clicked.
3006 if (!IsHighlighted(current
))
3008 HighlightAll(false);
3009 ChangeCurrent(current
);
3010 ReverseHighlight(m_current
);
3013 SendNotify( current
, wxEVT_COMMAND_LIST_ITEM_RIGHT_CLICK
, event
.GetPosition() );
3015 // Allow generation of context menu event
3018 else if (event
.MiddleDown())
3020 SendNotify( current
, wxEVT_COMMAND_LIST_ITEM_MIDDLE_CLICK
);
3022 else if ( event
.LeftDown() || forceClick
)
3024 m_lineBeforeLastClicked
= m_lineLastClicked
;
3025 m_lineLastClicked
= current
;
3027 size_t oldCurrent
= m_current
;
3028 bool oldWasSelected
= IsHighlighted(m_current
);
3030 bool cmdModifierDown
= event
.CmdDown();
3031 if ( IsSingleSel() || !(cmdModifierDown
|| event
.ShiftDown()) )
3033 if ( IsSingleSel() || !IsHighlighted(current
) )
3035 HighlightAll( false );
3037 ChangeCurrent(current
);
3039 ReverseHighlight(m_current
);
3041 else // multi sel & current is highlighted & no mod keys
3043 m_lineSelectSingleOnUp
= current
;
3044 ChangeCurrent(current
); // change focus
3047 else // multi sel & either ctrl or shift is down
3049 if (cmdModifierDown
)
3051 ChangeCurrent(current
);
3053 ReverseHighlight(m_current
);
3055 else if (event
.ShiftDown())
3057 ChangeCurrent(current
);
3059 size_t lineFrom
= oldCurrent
,
3062 if ( lineTo
< lineFrom
)
3065 lineFrom
= m_current
;
3068 HighlightLines(lineFrom
, lineTo
);
3070 else // !ctrl, !shift
3072 // test in the enclosing if should make it impossible
3073 wxFAIL_MSG( _T("how did we get here?") );
3077 if (m_current
!= oldCurrent
)
3078 RefreshLine( oldCurrent
);
3080 // forceClick is only set if the previous click was on another item
3081 m_lastOnSame
= !forceClick
&& (m_current
== oldCurrent
) && oldWasSelected
;
3085 void wxListMainWindow::MoveToItem(size_t item
)
3087 if ( item
== (size_t)-1 )
3090 wxRect rect
= GetLineRect(item
);
3092 int client_w
, client_h
;
3093 GetClientSize( &client_w
, &client_h
);
3095 const int hLine
= GetLineHeight();
3097 int view_x
= SCROLL_UNIT_X
* GetScrollPos( wxHORIZONTAL
);
3098 int view_y
= hLine
* GetScrollPos( wxVERTICAL
);
3100 if ( InReportView() )
3102 // the next we need the range of lines shown it might be different,
3103 // so recalculate it
3104 ResetVisibleLinesRange();
3106 if (rect
.y
< view_y
)
3107 Scroll( -1, rect
.y
/ hLine
);
3108 if (rect
.y
+ rect
.height
+ 5 > view_y
+ client_h
)
3109 Scroll( -1, (rect
.y
+ rect
.height
- client_h
+ hLine
) / hLine
);
3113 if (rect
.x
-view_x
< 5)
3114 Scroll( (rect
.x
- 5) / SCROLL_UNIT_X
, -1 );
3115 if (rect
.x
+ rect
.width
- 5 > view_x
+ client_w
)
3116 Scroll( (rect
.x
+ rect
.width
- client_w
+ SCROLL_UNIT_X
) / SCROLL_UNIT_X
, -1 );
3120 // ----------------------------------------------------------------------------
3121 // keyboard handling
3122 // ----------------------------------------------------------------------------
3124 void wxListMainWindow::OnArrowChar(size_t newCurrent
, const wxKeyEvent
& event
)
3126 wxCHECK_RET( newCurrent
< (size_t)GetItemCount(),
3127 _T("invalid item index in OnArrowChar()") );
3129 size_t oldCurrent
= m_current
;
3131 // in single selection we just ignore Shift as we can't select several
3133 if ( event
.ShiftDown() && !IsSingleSel() )
3135 ChangeCurrent(newCurrent
);
3137 // refresh the old focus to remove it
3138 RefreshLine( oldCurrent
);
3140 // select all the items between the old and the new one
3141 if ( oldCurrent
> newCurrent
)
3143 newCurrent
= oldCurrent
;
3144 oldCurrent
= m_current
;
3147 HighlightLines(oldCurrent
, newCurrent
);
3151 // all previously selected items are unselected unless ctrl is held
3152 if ( !event
.ControlDown() )
3153 HighlightAll(false);
3155 ChangeCurrent(newCurrent
);
3157 // refresh the old focus to remove it
3158 RefreshLine( oldCurrent
);
3160 if ( !event
.ControlDown() )
3162 HighlightLine( m_current
, true );
3166 RefreshLine( m_current
);
3171 void wxListMainWindow::OnKeyDown( wxKeyEvent
&event
)
3173 wxWindow
*parent
= GetParent();
3175 // propagate the key event upwards
3176 wxKeyEvent
ke( wxEVT_KEY_DOWN
);
3177 ke
.m_shiftDown
= event
.m_shiftDown
;
3178 ke
.m_controlDown
= event
.m_controlDown
;
3179 ke
.m_altDown
= event
.m_altDown
;
3180 ke
.m_metaDown
= event
.m_metaDown
;
3181 ke
.m_keyCode
= event
.m_keyCode
;
3184 ke
.SetEventObject( parent
);
3185 if (parent
->GetEventHandler()->ProcessEvent( ke
)) return;
3190 void wxListMainWindow::OnChar( wxKeyEvent
&event
)
3192 wxWindow
*parent
= GetParent();
3194 // send a list_key event up
3197 wxListEvent
le( wxEVT_COMMAND_LIST_KEY_DOWN
, GetParent()->GetId() );
3198 le
.m_itemIndex
= m_current
;
3199 GetLine(m_current
)->GetItem( 0, le
.m_item
);
3200 le
.m_code
= event
.GetKeyCode();
3201 le
.SetEventObject( parent
);
3202 parent
->GetEventHandler()->ProcessEvent( le
);
3205 // propagate the char event upwards
3206 wxKeyEvent
ke( wxEVT_CHAR
);
3207 ke
.m_shiftDown
= event
.m_shiftDown
;
3208 ke
.m_controlDown
= event
.m_controlDown
;
3209 ke
.m_altDown
= event
.m_altDown
;
3210 ke
.m_metaDown
= event
.m_metaDown
;
3211 ke
.m_keyCode
= event
.m_keyCode
;
3214 ke
.SetEventObject( parent
);
3215 if (parent
->GetEventHandler()->ProcessEvent( ke
)) return;
3217 if (event
.GetKeyCode() == WXK_TAB
)
3219 wxNavigationKeyEvent nevent
;
3220 nevent
.SetWindowChange( event
.ControlDown() );
3221 nevent
.SetDirection( !event
.ShiftDown() );
3222 nevent
.SetEventObject( GetParent()->GetParent() );
3223 nevent
.SetCurrentFocus( m_parent
);
3224 if (GetParent()->GetParent()->GetEventHandler()->ProcessEvent( nevent
))
3228 // no item -> nothing to do
3235 switch (event
.GetKeyCode())
3238 if ( m_current
> 0 )
3239 OnArrowChar( m_current
- 1, event
);
3243 if ( m_current
< (size_t)GetItemCount() - 1 )
3244 OnArrowChar( m_current
+ 1, event
);
3249 OnArrowChar( GetItemCount() - 1, event
);
3254 OnArrowChar( 0, event
);
3259 int steps
= InReportView() ? m_linesPerPage
- 1 : m_current
% m_linesPerPage
;
3261 int index
= m_current
- steps
;
3265 OnArrowChar( index
, event
);
3271 int steps
= InReportView()
3272 ? m_linesPerPage
- 1
3273 : m_linesPerPage
- (m_current
% m_linesPerPage
) - 1;
3275 size_t index
= m_current
+ steps
;
3276 size_t count
= GetItemCount();
3277 if ( index
>= count
)
3280 OnArrowChar( index
, event
);
3285 if ( !InReportView() )
3287 int index
= m_current
- m_linesPerPage
;
3291 OnArrowChar( index
, event
);
3296 if ( !InReportView() )
3298 size_t index
= m_current
+ m_linesPerPage
;
3300 size_t count
= GetItemCount();
3301 if ( index
>= count
)
3304 OnArrowChar( index
, event
);
3309 if ( IsSingleSel() )
3311 SendNotify( m_current
, wxEVT_COMMAND_LIST_ITEM_ACTIVATED
);
3313 if ( IsHighlighted(m_current
) )
3315 // don't unselect the item in single selection mode
3318 //else: select it in ReverseHighlight() below if unselected
3321 ReverseHighlight(m_current
);
3326 SendNotify( m_current
, wxEVT_COMMAND_LIST_ITEM_ACTIVATED
);
3334 // ----------------------------------------------------------------------------
3336 // ----------------------------------------------------------------------------
3338 void wxListMainWindow::OnSetFocus( wxFocusEvent
&WXUNUSED(event
) )
3342 wxFocusEvent
event( wxEVT_SET_FOCUS
, GetParent()->GetId() );
3343 event
.SetEventObject( GetParent() );
3344 if ( GetParent()->GetEventHandler()->ProcessEvent( event
) )
3348 // wxGTK sends us EVT_SET_FOCUS events even if we had never got
3349 // EVT_KILL_FOCUS before which means that we finish by redrawing the items
3350 // which are already drawn correctly resulting in horrible flicker - avoid
3360 void wxListMainWindow::OnKillFocus( wxFocusEvent
&WXUNUSED(event
) )
3364 wxFocusEvent
event( wxEVT_KILL_FOCUS
, GetParent()->GetId() );
3365 event
.SetEventObject( GetParent() );
3366 if ( GetParent()->GetEventHandler()->ProcessEvent( event
) )
3374 void wxListMainWindow::DrawImage( int index
, wxDC
*dc
, int x
, int y
)
3376 if ( HasFlag(wxLC_ICON
) && (m_normal_image_list
))
3378 m_normal_image_list
->Draw( index
, *dc
, x
, y
, wxIMAGELIST_DRAW_TRANSPARENT
);
3380 else if ( HasFlag(wxLC_SMALL_ICON
) && (m_small_image_list
))
3382 m_small_image_list
->Draw( index
, *dc
, x
, y
, wxIMAGELIST_DRAW_TRANSPARENT
);
3384 else if ( HasFlag(wxLC_LIST
) && (m_small_image_list
))
3386 m_small_image_list
->Draw( index
, *dc
, x
, y
, wxIMAGELIST_DRAW_TRANSPARENT
);
3388 else if ( InReportView() && (m_small_image_list
))
3390 m_small_image_list
->Draw( index
, *dc
, x
, y
, wxIMAGELIST_DRAW_TRANSPARENT
);
3394 void wxListMainWindow::GetImageSize( int index
, int &width
, int &height
) const
3396 if ( HasFlag(wxLC_ICON
) && m_normal_image_list
)
3398 m_normal_image_list
->GetSize( index
, width
, height
);
3400 else if ( HasFlag(wxLC_SMALL_ICON
) && m_small_image_list
)
3402 m_small_image_list
->GetSize( index
, width
, height
);
3404 else if ( HasFlag(wxLC_LIST
) && m_small_image_list
)
3406 m_small_image_list
->GetSize( index
, width
, height
);
3408 else if ( InReportView() && m_small_image_list
)
3410 m_small_image_list
->GetSize( index
, width
, height
);
3419 int wxListMainWindow::GetTextLength( const wxString
&s
) const
3421 wxClientDC
dc( wxConstCast(this, wxListMainWindow
) );
3422 dc
.SetFont( GetFont() );
3425 dc
.GetTextExtent( s
, &lw
, NULL
);
3427 return lw
+ AUTOSIZE_COL_MARGIN
;
3430 void wxListMainWindow::SetImageList( wxImageListType
*imageList
, int which
)
3434 // calc the spacing from the icon size
3435 int width
= 0, height
= 0;
3437 if ((imageList
) && (imageList
->GetImageCount()) )
3438 imageList
->GetSize(0, width
, height
);
3440 if (which
== wxIMAGE_LIST_NORMAL
)
3442 m_normal_image_list
= imageList
;
3443 m_normal_spacing
= width
+ 8;
3446 if (which
== wxIMAGE_LIST_SMALL
)
3448 m_small_image_list
= imageList
;
3449 m_small_spacing
= width
+ 14;
3450 m_lineHeight
= 0; // ensure that the line height will be recalc'd
3454 void wxListMainWindow::SetItemSpacing( int spacing
, bool isSmall
)
3458 m_small_spacing
= spacing
;
3460 m_normal_spacing
= spacing
;
3463 int wxListMainWindow::GetItemSpacing( bool isSmall
)
3465 return isSmall
? m_small_spacing
: m_normal_spacing
;
3468 // ----------------------------------------------------------------------------
3470 // ----------------------------------------------------------------------------
3472 void wxListMainWindow::SetColumn( int col
, wxListItem
&item
)
3474 wxListHeaderDataList::compatibility_iterator node
= m_columns
.Item( col
);
3476 wxCHECK_RET( node
, _T("invalid column index in SetColumn") );
3478 if ( item
.m_width
== wxLIST_AUTOSIZE_USEHEADER
)
3479 item
.m_width
= GetTextLength( item
.m_text
);
3481 wxListHeaderData
*column
= node
->GetData();
3482 column
->SetItem( item
);
3484 wxListHeaderWindow
*headerWin
= GetListCtrl()->m_headerWin
;
3486 headerWin
->m_dirty
= true;
3490 // invalidate it as it has to be recalculated
3494 void wxListMainWindow::SetColumnWidth( int col
, int width
)
3496 wxCHECK_RET( col
>= 0 && col
< GetColumnCount(),
3497 _T("invalid column index") );
3499 wxCHECK_RET( InReportView(),
3500 _T("SetColumnWidth() can only be called in report mode.") );
3503 wxListHeaderWindow
*headerWin
= GetListCtrl()->m_headerWin
;
3505 headerWin
->m_dirty
= true;
3507 wxListHeaderDataList::compatibility_iterator node
= m_columns
.Item( col
);
3508 wxCHECK_RET( node
, _T("no column?") );
3510 wxListHeaderData
*column
= node
->GetData();
3512 size_t count
= GetItemCount();
3514 if (width
== wxLIST_AUTOSIZE_USEHEADER
)
3516 width
= GetTextLength(column
->GetText());
3518 else if ( width
== wxLIST_AUTOSIZE
)
3522 // TODO: determine the max width somehow...
3523 width
= WIDTH_COL_DEFAULT
;
3527 wxClientDC
dc(this);
3528 dc
.SetFont( GetFont() );
3530 int max
= AUTOSIZE_COL_MARGIN
;
3532 // if the cached column width isn't valid then recalculate it
3533 if (m_aColWidths
.Item(col
)->bNeedsUpdate
)
3535 for (size_t i
= 0; i
< count
; i
++)
3537 wxListLineData
*line
= GetLine( i
);
3538 wxListItemDataList::compatibility_iterator n
= line
->m_items
.Item( col
);
3540 wxCHECK_RET( n
, _T("no subitem?") );
3542 wxListItemData
*itemData
= n
->GetData();
3545 itemData
->GetItem(item
);
3546 int itemWidth
= GetItemWidthWithImage(&item
);
3547 if (itemWidth
> max
)
3551 m_aColWidths
.Item(col
)->bNeedsUpdate
= false;
3552 m_aColWidths
.Item(col
)->nMaxWidth
= max
;
3555 max
= m_aColWidths
.Item(col
)->nMaxWidth
;
3556 width
= max
+ AUTOSIZE_COL_MARGIN
;
3560 column
->SetWidth( width
);
3562 // invalidate it as it has to be recalculated
3566 int wxListMainWindow::GetHeaderWidth() const
3568 if ( !m_headerWidth
)
3570 wxListMainWindow
*self
= wxConstCast(this, wxListMainWindow
);
3572 size_t count
= GetColumnCount();
3573 for ( size_t col
= 0; col
< count
; col
++ )
3575 self
->m_headerWidth
+= GetColumnWidth(col
);
3579 return m_headerWidth
;
3582 void wxListMainWindow::GetColumn( int col
, wxListItem
&item
) const
3584 wxListHeaderDataList::compatibility_iterator node
= m_columns
.Item( col
);
3585 wxCHECK_RET( node
, _T("invalid column index in GetColumn") );
3587 wxListHeaderData
*column
= node
->GetData();
3588 column
->GetItem( item
);
3591 int wxListMainWindow::GetColumnWidth( int col
) const
3593 wxListHeaderDataList::compatibility_iterator node
= m_columns
.Item( col
);
3594 wxCHECK_MSG( node
, 0, _T("invalid column index") );
3596 wxListHeaderData
*column
= node
->GetData();
3597 return column
->GetWidth();
3600 // ----------------------------------------------------------------------------
3602 // ----------------------------------------------------------------------------
3604 void wxListMainWindow::SetItem( wxListItem
&item
)
3606 long id
= item
.m_itemId
;
3607 wxCHECK_RET( id
>= 0 && (size_t)id
< GetItemCount(),
3608 _T("invalid item index in SetItem") );
3612 wxListLineData
*line
= GetLine((size_t)id
);
3613 line
->SetItem( item
.m_col
, item
);
3615 // Set item state if user wants
3616 if ( item
.m_mask
& wxLIST_MASK_STATE
)
3617 SetItemState( item
.m_itemId
, item
.m_state
, item
.m_state
);
3621 // update the Max Width Cache if needed
3622 int width
= GetItemWidthWithImage(&item
);
3624 if (width
> m_aColWidths
.Item(item
.m_col
)->nMaxWidth
)
3625 m_aColWidths
.Item(item
.m_col
)->nMaxWidth
= width
;
3629 // update the item on screen
3631 GetItemRect(id
, rectItem
);
3632 RefreshRect(rectItem
);
3635 void wxListMainWindow::SetItemStateAll(long state
, long stateMask
)
3640 // first deal with selection
3641 if ( stateMask
& wxLIST_STATE_SELECTED
)
3643 // set/clear select state
3646 // optimized version for virtual listctrl.
3647 m_selStore
.SelectRange(0, GetItemCount() - 1, state
== wxLIST_STATE_SELECTED
);
3650 else if ( state
& wxLIST_STATE_SELECTED
)
3652 const long count
= GetItemCount();
3653 for( long i
= 0; i
< count
; i
++ )
3655 SetItemState( i
, wxLIST_STATE_SELECTED
, wxLIST_STATE_SELECTED
);
3661 // clear for non virtual (somewhat optimized by using GetNextItem())
3663 while ( (i
= GetNextItem(i
, wxLIST_NEXT_ALL
, wxLIST_STATE_SELECTED
)) != -1 )
3665 SetItemState( i
, 0, wxLIST_STATE_SELECTED
);
3670 if ( HasCurrent() && (state
== 0) && (stateMask
& wxLIST_STATE_FOCUSED
) )
3672 // unfocus all: only one item can be focussed, so clearing focus for
3673 // all items is simply clearing focus of the focussed item.
3674 SetItemState(m_current
, state
, stateMask
);
3676 //(setting focus to all items makes no sense, so it is not handled here.)
3679 void wxListMainWindow::SetItemState( long litem
, long state
, long stateMask
)
3683 SetItemStateAll(state
, stateMask
);
3687 wxCHECK_RET( litem
>= 0 && (size_t)litem
< GetItemCount(),
3688 _T("invalid list ctrl item index in SetItem") );
3690 size_t oldCurrent
= m_current
;
3691 size_t item
= (size_t)litem
; // safe because of the check above
3693 // do we need to change the focus?
3694 if ( stateMask
& wxLIST_STATE_FOCUSED
)
3696 if ( state
& wxLIST_STATE_FOCUSED
)
3698 // don't do anything if this item is already focused
3699 if ( item
!= m_current
)
3701 ChangeCurrent(item
);
3703 if ( oldCurrent
!= (size_t)-1 )
3705 if ( IsSingleSel() )
3707 HighlightLine(oldCurrent
, false);
3710 RefreshLine(oldCurrent
);
3713 RefreshLine( m_current
);
3718 // don't do anything if this item is not focused
3719 if ( item
== m_current
)
3723 if ( IsSingleSel() )
3725 // we must unselect the old current item as well or we
3726 // might end up with more than one selected item in a
3727 // single selection control
3728 HighlightLine(oldCurrent
, false);
3731 RefreshLine( oldCurrent
);
3736 // do we need to change the selection state?
3737 if ( stateMask
& wxLIST_STATE_SELECTED
)
3739 bool on
= (state
& wxLIST_STATE_SELECTED
) != 0;
3741 if ( IsSingleSel() )
3745 // selecting the item also makes it the focused one in the
3747 if ( m_current
!= item
)
3749 ChangeCurrent(item
);
3751 if ( oldCurrent
!= (size_t)-1 )
3753 HighlightLine( oldCurrent
, false );
3754 RefreshLine( oldCurrent
);
3760 // only the current item may be selected anyhow
3761 if ( item
!= m_current
)
3766 if ( HighlightLine(item
, on
) )
3773 int wxListMainWindow::GetItemState( long item
, long stateMask
) const
3775 wxCHECK_MSG( item
>= 0 && (size_t)item
< GetItemCount(), 0,
3776 _T("invalid list ctrl item index in GetItemState()") );
3778 int ret
= wxLIST_STATE_DONTCARE
;
3780 if ( stateMask
& wxLIST_STATE_FOCUSED
)
3782 if ( (size_t)item
== m_current
)
3783 ret
|= wxLIST_STATE_FOCUSED
;
3786 if ( stateMask
& wxLIST_STATE_SELECTED
)
3788 if ( IsHighlighted(item
) )
3789 ret
|= wxLIST_STATE_SELECTED
;
3795 void wxListMainWindow::GetItem( wxListItem
&item
) const
3797 wxCHECK_RET( item
.m_itemId
>= 0 && (size_t)item
.m_itemId
< GetItemCount(),
3798 _T("invalid item index in GetItem") );
3800 wxListLineData
*line
= GetLine((size_t)item
.m_itemId
);
3801 line
->GetItem( item
.m_col
, item
);
3803 // Get item state if user wants it
3804 if ( item
.m_mask
& wxLIST_MASK_STATE
)
3805 item
.m_state
= GetItemState( item
.m_itemId
, wxLIST_STATE_SELECTED
|
3806 wxLIST_STATE_FOCUSED
);
3809 // ----------------------------------------------------------------------------
3811 // ----------------------------------------------------------------------------
3813 size_t wxListMainWindow::GetItemCount() const
3815 return IsVirtual() ? m_countVirt
: m_lines
.GetCount();
3818 void wxListMainWindow::SetItemCount(long count
)
3820 m_selStore
.SetItemCount(count
);
3821 m_countVirt
= count
;
3823 ResetVisibleLinesRange();
3825 // scrollbars must be reset
3829 int wxListMainWindow::GetSelectedItemCount() const
3831 // deal with the quick case first
3832 if ( IsSingleSel() )
3833 return HasCurrent() ? IsHighlighted(m_current
) : false;
3835 // virtual controls remmebers all its selections itself
3837 return m_selStore
.GetSelectedCount();
3839 // TODO: we probably should maintain the number of items selected even for
3840 // non virtual controls as enumerating all lines is really slow...
3841 size_t countSel
= 0;
3842 size_t count
= GetItemCount();
3843 for ( size_t line
= 0; line
< count
; line
++ )
3845 if ( GetLine(line
)->IsHighlighted() )
3852 // ----------------------------------------------------------------------------
3853 // item position/size
3854 // ----------------------------------------------------------------------------
3856 wxRect
wxListMainWindow::GetViewRect() const
3858 wxASSERT_MSG( !HasFlag(wxLC_REPORT
| wxLC_LIST
),
3859 _T("wxListCtrl::GetViewRect() only works in icon mode") );
3861 // we need to find the longest/tallest label
3862 wxCoord xMax
= 0, yMax
= 0;
3863 const int count
= GetItemCount();
3866 for ( int i
= 0; i
< count
; i
++ )
3871 wxCoord x
= r
.GetRight(),
3881 // some fudge needed to make it look prettier
3882 xMax
+= 2 * EXTRA_BORDER_X
;
3883 yMax
+= 2 * EXTRA_BORDER_Y
;
3885 // account for the scrollbars if necessary
3886 const wxSize sizeAll
= GetClientSize();
3887 if ( xMax
> sizeAll
.x
)
3888 yMax
+= wxSystemSettings::GetMetric(wxSYS_HSCROLL_Y
);
3889 if ( yMax
> sizeAll
.y
)
3890 xMax
+= wxSystemSettings::GetMetric(wxSYS_VSCROLL_X
);
3892 return wxRect(0, 0, xMax
, yMax
);
3895 void wxListMainWindow::GetItemRect( long index
, wxRect
&rect
) const
3897 wxCHECK_RET( index
>= 0 && (size_t)index
< GetItemCount(),
3898 _T("invalid index in GetItemRect") );
3900 // ensure that we're laid out, otherwise we could return nonsense
3903 wxConstCast(this, wxListMainWindow
)->
3904 RecalculatePositions(true /* no refresh */);
3907 rect
= GetLineRect((size_t)index
);
3909 CalcScrolledPosition(rect
.x
, rect
.y
, &rect
.x
, &rect
.y
);
3912 bool wxListMainWindow::GetItemPosition(long item
, wxPoint
& pos
) const
3915 GetItemRect(item
, rect
);
3923 // ----------------------------------------------------------------------------
3924 // geometry calculation
3925 // ----------------------------------------------------------------------------
3927 void wxListMainWindow::RecalculatePositions(bool noRefresh
)
3929 wxClientDC
dc( this );
3930 dc
.SetFont( GetFont() );
3932 const size_t count
= GetItemCount();
3935 if ( HasFlag(wxLC_ICON
) )
3936 iconSpacing
= m_normal_spacing
;
3937 else if ( HasFlag(wxLC_SMALL_ICON
) )
3938 iconSpacing
= m_small_spacing
;
3942 // Note that we do not call GetClientSize() here but
3943 // GetSize() and subtract the border size for sunken
3944 // borders manually. This is technically incorrect,
3945 // but we need to know the client area's size WITHOUT
3946 // scrollbars here. Since we don't know if there are
3947 // any scrollbars, we use GetSize() instead. Another
3948 // solution would be to call SetScrollbars() here to
3949 // remove the scrollbars and call GetClientSize() then,
3950 // but this might result in flicker and - worse - will
3951 // reset the scrollbars to 0 which is not good at all
3952 // if you resize a dialog/window, but don't want to
3953 // reset the window scrolling. RR.
3954 // Furthermore, we actually do NOT subtract the border
3955 // width as 2 pixels is just the extra space which we
3956 // need around the actual content in the window. Other-
3957 // wise the text would e.g. touch the upper border. RR.
3960 GetSize( &clientWidth
, &clientHeight
);
3962 const int lineHeight
= GetLineHeight();
3964 if ( InReportView() )
3966 // all lines have the same height and we scroll one line per step
3967 int entireHeight
= count
* lineHeight
+ LINE_SPACING
;
3969 m_linesPerPage
= clientHeight
/ lineHeight
;
3971 ResetVisibleLinesRange();
3973 SetScrollbars( SCROLL_UNIT_X
, lineHeight
,
3974 GetHeaderWidth() / SCROLL_UNIT_X
,
3975 (entireHeight
+ lineHeight
- 1) / lineHeight
,
3976 GetScrollPos(wxHORIZONTAL
),
3977 GetScrollPos(wxVERTICAL
),
3982 // we have 3 different layout strategies: either layout all items
3983 // horizontally/vertically (wxLC_ALIGN_XXX styles explicitly given) or
3984 // to arrange them in top to bottom, left to right (don't ask me why
3985 // not the other way round...) order
3986 if ( HasFlag(wxLC_ALIGN_LEFT
| wxLC_ALIGN_TOP
) )
3988 int x
= EXTRA_BORDER_X
;
3989 int y
= EXTRA_BORDER_Y
;
3991 wxCoord widthMax
= 0;
3994 for ( i
= 0; i
< count
; i
++ )
3996 wxListLineData
*line
= GetLine(i
);
3997 line
->CalculateSize( &dc
, iconSpacing
);
3998 line
->SetPosition( x
, y
, iconSpacing
);
4000 wxSize sizeLine
= GetLineSize(i
);
4002 if ( HasFlag(wxLC_ALIGN_TOP
) )
4004 if ( sizeLine
.x
> widthMax
)
4005 widthMax
= sizeLine
.x
;
4009 else // wxLC_ALIGN_LEFT
4011 x
+= sizeLine
.x
+ MARGIN_BETWEEN_ROWS
;
4015 if ( HasFlag(wxLC_ALIGN_TOP
) )
4017 // traverse the items again and tweak their sizes so that they are
4018 // all the same in a row
4019 for ( i
= 0; i
< count
; i
++ )
4021 wxListLineData
*line
= GetLine(i
);
4022 line
->m_gi
->ExtendWidth(widthMax
);
4030 (x
+ SCROLL_UNIT_X
) / SCROLL_UNIT_X
,
4031 (y
+ lineHeight
) / lineHeight
,
4032 GetScrollPos( wxHORIZONTAL
),
4033 GetScrollPos( wxVERTICAL
),
4037 else // "flowed" arrangement, the most complicated case
4039 // at first we try without any scrollbars, if the items don't fit into
4040 // the window, we recalculate after subtracting the space taken by the
4043 int entireWidth
= 0;
4045 for (int tries
= 0; tries
< 2; tries
++)
4047 entireWidth
= 2 * EXTRA_BORDER_X
;
4051 // Now we have decided that the items do not fit into the
4052 // client area, so we need a scrollbar
4053 entireWidth
+= SCROLL_UNIT_X
;
4056 int x
= EXTRA_BORDER_X
;
4057 int y
= EXTRA_BORDER_Y
;
4058 int maxWidthInThisRow
= 0;
4061 int currentlyVisibleLines
= 0;
4063 for (size_t i
= 0; i
< count
; i
++)
4065 currentlyVisibleLines
++;
4066 wxListLineData
*line
= GetLine( i
);
4067 line
->CalculateSize( &dc
, iconSpacing
);
4068 line
->SetPosition( x
, y
, iconSpacing
);
4070 wxSize sizeLine
= GetLineSize( i
);
4072 if ( maxWidthInThisRow
< sizeLine
.x
)
4073 maxWidthInThisRow
= sizeLine
.x
;
4076 if (currentlyVisibleLines
> m_linesPerPage
)
4077 m_linesPerPage
= currentlyVisibleLines
;
4079 if ( y
+ sizeLine
.y
>= clientHeight
)
4081 currentlyVisibleLines
= 0;
4083 maxWidthInThisRow
+= MARGIN_BETWEEN_ROWS
;
4084 x
+= maxWidthInThisRow
;
4085 entireWidth
+= maxWidthInThisRow
;
4086 maxWidthInThisRow
= 0;
4089 // We have reached the last item.
4090 if ( i
== count
- 1 )
4091 entireWidth
+= maxWidthInThisRow
;
4093 if ( (tries
== 0) &&
4094 (entireWidth
+ SCROLL_UNIT_X
> clientWidth
) )
4096 clientHeight
-= wxSystemSettings::
4097 GetMetric(wxSYS_HSCROLL_Y
);
4102 if ( i
== count
- 1 )
4103 tries
= 1; // Everything fits, no second try required.
4111 (entireWidth
+ SCROLL_UNIT_X
) / SCROLL_UNIT_X
,
4113 GetScrollPos( wxHORIZONTAL
),
4122 // FIXME: why should we call it from here?
4129 void wxListMainWindow::RefreshAll()
4134 wxListHeaderWindow
*headerWin
= GetListCtrl()->m_headerWin
;
4135 if ( headerWin
&& headerWin
->m_dirty
)
4137 headerWin
->m_dirty
= false;
4138 headerWin
->Refresh();
4142 void wxListMainWindow::UpdateCurrent()
4144 if ( !HasCurrent() && !IsEmpty() )
4148 long wxListMainWindow::GetNextItem( long item
,
4149 int WXUNUSED(geometry
),
4153 max
= GetItemCount();
4154 wxCHECK_MSG( (ret
== -1) || (ret
< max
), -1,
4155 _T("invalid listctrl index in GetNextItem()") );
4157 // notice that we start with the next item (or the first one if item == -1)
4158 // and this is intentional to allow writing a simple loop to iterate over
4159 // all selected items
4162 // this is not an error because the index was OK initially,
4163 // just no such item
4170 size_t count
= GetItemCount();
4171 for ( size_t line
= (size_t)ret
; line
< count
; line
++ )
4173 if ( (state
& wxLIST_STATE_FOCUSED
) && (line
== m_current
) )
4176 if ( (state
& wxLIST_STATE_SELECTED
) && IsHighlighted(line
) )
4183 // ----------------------------------------------------------------------------
4185 // ----------------------------------------------------------------------------
4187 void wxListMainWindow::DeleteItem( long lindex
)
4189 size_t count
= GetItemCount();
4191 wxCHECK_RET( (lindex
>= 0) && ((size_t)lindex
< count
),
4192 _T("invalid item index in DeleteItem") );
4194 size_t index
= (size_t)lindex
;
4196 // we don't need to adjust the index for the previous items
4197 if ( HasCurrent() && m_current
>= index
)
4199 // if the current item is being deleted, we want the next one to
4200 // become selected - unless there is no next one - so don't adjust
4201 // m_current in this case
4202 if ( m_current
!= index
|| m_current
== count
- 1 )
4206 if ( InReportView() )
4208 // mark the Column Max Width cache as dirty if the items in the line
4209 // we're deleting contain the Max Column Width
4210 wxListLineData
* const line
= GetLine(index
);
4211 wxListItemDataList::compatibility_iterator n
;
4212 wxListItemData
*itemData
;
4216 for (size_t i
= 0; i
< m_columns
.GetCount(); i
++)
4218 n
= line
->m_items
.Item( i
);
4219 itemData
= n
->GetData();
4220 itemData
->GetItem(item
);
4222 itemWidth
= GetItemWidthWithImage(&item
);
4224 if (itemWidth
>= m_aColWidths
.Item(i
)->nMaxWidth
)
4225 m_aColWidths
.Item(i
)->bNeedsUpdate
= true;
4228 ResetVisibleLinesRange();
4234 m_selStore
.OnItemDelete(index
);
4238 m_lines
.RemoveAt( index
);
4241 // we need to refresh the (vert) scrollbar as the number of items changed
4244 SendNotify( index
, wxEVT_COMMAND_LIST_DELETE_ITEM
);
4246 RefreshAfter(index
);
4249 void wxListMainWindow::DeleteColumn( int col
)
4251 wxListHeaderDataList::compatibility_iterator node
= m_columns
.Item( col
);
4253 wxCHECK_RET( node
, wxT("invalid column index in DeleteColumn()") );
4256 delete node
->GetData();
4257 m_columns
.Erase( node
);
4261 // update all the items
4262 for ( size_t i
= 0; i
< m_lines
.GetCount(); i
++ )
4264 wxListLineData
* const line
= GetLine(i
);
4265 wxListItemDataList::compatibility_iterator n
= line
->m_items
.Item( col
);
4266 delete n
->GetData();
4267 line
->m_items
.Erase(n
);
4271 if ( InReportView() ) // we only cache max widths when in Report View
4273 delete m_aColWidths
.Item(col
);
4274 m_aColWidths
.RemoveAt(col
);
4277 // invalidate it as it has to be recalculated
4281 void wxListMainWindow::DoDeleteAllItems()
4284 // nothing to do - in particular, don't send the event
4289 // to make the deletion of all items faster, we don't send the
4290 // notifications for each item deletion in this case but only one event
4291 // for all of them: this is compatible with wxMSW and documented in
4292 // DeleteAllItems() description
4294 wxListEvent
event( wxEVT_COMMAND_LIST_DELETE_ALL_ITEMS
, GetParent()->GetId() );
4295 event
.SetEventObject( GetParent() );
4296 GetParent()->GetEventHandler()->ProcessEvent( event
);
4304 if ( InReportView() )
4306 ResetVisibleLinesRange();
4307 for (size_t i
= 0; i
< m_aColWidths
.GetCount(); i
++)
4309 m_aColWidths
.Item(i
)->bNeedsUpdate
= true;
4316 void wxListMainWindow::DeleteAllItems()
4320 RecalculatePositions();
4323 void wxListMainWindow::DeleteEverything()
4325 WX_CLEAR_LIST(wxListHeaderDataList
, m_columns
);
4326 WX_CLEAR_ARRAY(m_aColWidths
);
4331 // ----------------------------------------------------------------------------
4332 // scanning for an item
4333 // ----------------------------------------------------------------------------
4335 void wxListMainWindow::EnsureVisible( long index
)
4337 wxCHECK_RET( index
>= 0 && (size_t)index
< GetItemCount(),
4338 _T("invalid index in EnsureVisible") );
4340 // We have to call this here because the label in question might just have
4341 // been added and its position is not known yet
4343 RecalculatePositions(true /* no refresh */);
4345 MoveToItem((size_t)index
);
4348 long wxListMainWindow::FindItem(long start
, const wxString
& str
, bool WXUNUSED(partial
) )
4355 size_t count
= GetItemCount();
4356 for ( size_t i
= (size_t)pos
; i
< count
; i
++ )
4358 wxListLineData
*line
= GetLine(i
);
4359 if ( line
->GetText(0) == tmp
)
4366 long wxListMainWindow::FindItem(long start
, wxUIntPtr data
)
4372 size_t count
= GetItemCount();
4373 for (size_t i
= (size_t)pos
; i
< count
; i
++)
4375 wxListLineData
*line
= GetLine(i
);
4377 line
->GetItem( 0, item
);
4378 if (item
.m_data
== data
)
4385 long wxListMainWindow::FindItem( const wxPoint
& pt
)
4388 GetVisibleLinesRange( &topItem
, NULL
);
4391 GetItemPosition( GetItemCount() - 1, p
);
4395 long id
= (long)floor( pt
.y
* double(GetItemCount() - topItem
- 1) / p
.y
+ topItem
);
4396 if ( id
>= 0 && id
< (long)GetItemCount() )
4402 long wxListMainWindow::HitTest( int x
, int y
, int &flags
)
4404 CalcUnscrolledPosition( x
, y
, &x
, &y
);
4406 size_t count
= GetItemCount();
4408 if ( InReportView() )
4410 size_t current
= y
/ GetLineHeight();
4411 if ( current
< count
)
4413 flags
= HitTestLine(current
, x
, y
);
4420 // TODO: optimize it too! this is less simple than for report view but
4421 // enumerating all items is still not a way to do it!!
4422 for ( size_t current
= 0; current
< count
; current
++ )
4424 flags
= HitTestLine(current
, x
, y
);
4433 // ----------------------------------------------------------------------------
4435 // ----------------------------------------------------------------------------
4437 void wxListMainWindow::InsertItem( wxListItem
&item
)
4439 wxASSERT_MSG( !IsVirtual(), _T("can't be used with virtual control") );
4441 int count
= GetItemCount();
4442 wxCHECK_RET( item
.m_itemId
>= 0, _T("invalid item index") );
4444 if (item
.m_itemId
> count
)
4445 item
.m_itemId
= count
;
4447 size_t id
= item
.m_itemId
;
4451 if ( InReportView() )
4453 ResetVisibleLinesRange();
4455 // calculate the width of the item and adjust the max column width
4456 wxColWidthInfo
*pWidthInfo
= m_aColWidths
.Item(item
.GetColumn());
4457 int width
= GetItemWidthWithImage(&item
);
4458 item
.SetWidth(width
);
4459 if (width
> pWidthInfo
->nMaxWidth
)
4460 pWidthInfo
->nMaxWidth
= width
;
4463 wxListLineData
*line
= new wxListLineData(this);
4465 line
->SetItem( item
.m_col
, item
);
4467 m_lines
.Insert( line
, id
);
4471 // If an item is selected at or below the point of insertion, we need to
4472 // increment the member variables because the current row's index has gone
4474 if ( HasCurrent() && m_current
>= id
)
4477 SendNotify(id
, wxEVT_COMMAND_LIST_INSERT_ITEM
);
4479 RefreshLines(id
, GetItemCount() - 1);
4482 void wxListMainWindow::InsertColumn( long col
, wxListItem
&item
)
4485 if ( InReportView() )
4487 if (item
.m_width
== wxLIST_AUTOSIZE_USEHEADER
)
4488 item
.m_width
= GetTextLength( item
.m_text
);
4490 wxListHeaderData
*column
= new wxListHeaderData( item
);
4491 wxColWidthInfo
*colWidthInfo
= new wxColWidthInfo();
4493 bool insert
= (col
>= 0) && ((size_t)col
< m_columns
.GetCount());
4496 wxListHeaderDataList::compatibility_iterator
4497 node
= m_columns
.Item( col
);
4498 m_columns
.Insert( node
, column
);
4499 m_aColWidths
.Insert( colWidthInfo
, col
);
4503 m_columns
.Append( column
);
4504 m_aColWidths
.Add( colWidthInfo
);
4509 // update all the items
4510 for ( size_t i
= 0; i
< m_lines
.GetCount(); i
++ )
4512 wxListLineData
* const line
= GetLine(i
);
4513 wxListItemData
* const data
= new wxListItemData(this);
4515 line
->m_items
.Insert(col
, data
);
4517 line
->m_items
.Append(data
);
4521 // invalidate it as it has to be recalculated
4526 int wxListMainWindow::GetItemWidthWithImage(wxListItem
* item
)
4529 wxClientDC
dc(this);
4531 dc
.SetFont( GetFont() );
4533 if (item
->GetImage() != -1)
4536 GetImageSize( item
->GetImage(), ix
, iy
);
4540 if (!item
->GetText().empty())
4543 dc
.GetTextExtent( item
->GetText(), &w
, NULL
);
4550 // ----------------------------------------------------------------------------
4552 // ----------------------------------------------------------------------------
4554 wxListCtrlCompare list_ctrl_compare_func_2
;
4555 long list_ctrl_compare_data
;
4557 int LINKAGEMODE
list_ctrl_compare_func_1( wxListLineData
**arg1
, wxListLineData
**arg2
)
4559 wxListLineData
*line1
= *arg1
;
4560 wxListLineData
*line2
= *arg2
;
4562 line1
->GetItem( 0, item
);
4563 wxUIntPtr data1
= item
.m_data
;
4564 line2
->GetItem( 0, item
);
4565 wxUIntPtr data2
= item
.m_data
;
4566 return list_ctrl_compare_func_2( data1
, data2
, list_ctrl_compare_data
);
4569 void wxListMainWindow::SortItems( wxListCtrlCompare fn
, long data
)
4571 list_ctrl_compare_func_2
= fn
;
4572 list_ctrl_compare_data
= data
;
4573 m_lines
.Sort( list_ctrl_compare_func_1
);
4577 // ----------------------------------------------------------------------------
4579 // ----------------------------------------------------------------------------
4581 void wxListMainWindow::OnScroll(wxScrollWinEvent
& event
)
4583 // update our idea of which lines are shown when we redraw the window the
4585 ResetVisibleLinesRange();
4588 #if ( defined(__WXGTK__) || defined(__WXMAC__) ) && !defined(__WXUNIVERSAL__)
4589 wxScrolledWindow::OnScroll(event
);
4591 HandleOnScroll( event
);
4594 if ( event
.GetOrientation() == wxHORIZONTAL
&& HasHeader() )
4596 wxGenericListCtrl
* lc
= GetListCtrl();
4597 wxCHECK_RET( lc
, _T("no listctrl window?") );
4599 lc
->m_headerWin
->Refresh();
4600 lc
->m_headerWin
->Update();
4604 int wxListMainWindow::GetCountPerPage() const
4606 if ( !m_linesPerPage
)
4608 wxConstCast(this, wxListMainWindow
)->
4609 m_linesPerPage
= GetClientSize().y
/ GetLineHeight();
4612 return m_linesPerPage
;
4615 void wxListMainWindow::GetVisibleLinesRange(size_t *from
, size_t *to
)
4617 wxASSERT_MSG( InReportView(), _T("this is for report mode only") );
4619 if ( m_lineFrom
== (size_t)-1 )
4621 size_t count
= GetItemCount();
4624 m_lineFrom
= GetScrollPos(wxVERTICAL
);
4626 // this may happen if SetScrollbars() hadn't been called yet
4627 if ( m_lineFrom
>= count
)
4628 m_lineFrom
= count
- 1;
4630 // we redraw one extra line but this is needed to make the redrawing
4631 // logic work when there is a fractional number of lines on screen
4632 m_lineTo
= m_lineFrom
+ m_linesPerPage
;
4633 if ( m_lineTo
>= count
)
4634 m_lineTo
= count
- 1;
4636 else // empty control
4639 m_lineTo
= (size_t)-1;
4643 wxASSERT_MSG( IsEmpty() ||
4644 (m_lineFrom
<= m_lineTo
&& m_lineTo
< GetItemCount()),
4645 _T("GetVisibleLinesRange() returns incorrect result") );
4653 // -------------------------------------------------------------------------------------
4654 // wxGenericListCtrl
4655 // -------------------------------------------------------------------------------------
4657 IMPLEMENT_DYNAMIC_CLASS(wxGenericListCtrl
, wxControl
)
4659 BEGIN_EVENT_TABLE(wxGenericListCtrl
,wxControl
)
4660 EVT_SIZE(wxGenericListCtrl::OnSize
)
4663 wxGenericListCtrl::wxGenericListCtrl()
4665 m_imageListNormal
= (wxImageListType
*) NULL
;
4666 m_imageListSmall
= (wxImageListType
*) NULL
;
4667 m_imageListState
= (wxImageListType
*) NULL
;
4669 m_ownsImageListNormal
=
4670 m_ownsImageListSmall
=
4671 m_ownsImageListState
= false;
4673 m_mainWin
= (wxListMainWindow
*) NULL
;
4674 m_headerWin
= (wxListHeaderWindow
*) NULL
;
4678 wxGenericListCtrl::~wxGenericListCtrl()
4680 if (m_ownsImageListNormal
)
4681 delete m_imageListNormal
;
4682 if (m_ownsImageListSmall
)
4683 delete m_imageListSmall
;
4684 if (m_ownsImageListState
)
4685 delete m_imageListState
;
4688 void wxGenericListCtrl::CalculateAndSetHeaderHeight()
4694 GetThemeMetric( kThemeMetricListHeaderHeight
, &h
);
4696 // we use 'g' to get the descent, too
4698 m_headerWin
->GetTextExtent(wxT("Hg"), &w
, &h
, &d
);
4699 h
+= d
+ 2 * HEADER_OFFSET_Y
+ EXTRA_HEIGHT
;
4702 // only update if changed
4703 if ( h
!= m_headerHeight
)
4708 ResizeReportView(true);
4709 else //why is this needed if it doesn't have a header?
4710 m_headerWin
->SetSize(m_headerWin
->GetSize().x
, m_headerHeight
);
4715 void wxGenericListCtrl::CreateHeaderWindow()
4717 m_headerWin
= new wxListHeaderWindow
4719 this, wxID_ANY
, m_mainWin
,
4721 wxSize(GetClientSize().x
, m_headerHeight
),
4724 CalculateAndSetHeaderHeight();
4727 bool wxGenericListCtrl::Create(wxWindow
*parent
,
4732 const wxValidator
&validator
,
4733 const wxString
&name
)
4737 m_imageListState
= (wxImageListType
*) NULL
;
4738 m_ownsImageListNormal
=
4739 m_ownsImageListSmall
=
4740 m_ownsImageListState
= false;
4742 m_mainWin
= (wxListMainWindow
*) NULL
;
4743 m_headerWin
= (wxListHeaderWindow
*) NULL
;
4747 if ( !(style
& wxLC_MASK_TYPE
) )
4749 style
= style
| wxLC_LIST
;
4752 if ( !wxControl::Create( parent
, id
, pos
, size
, style
, validator
, name
) )
4755 // don't create the inner window with the border
4756 style
&= ~wxBORDER_MASK
;
4758 m_mainWin
= new wxListMainWindow( this, wxID_ANY
, wxPoint(0, 0), size
, style
);
4760 #ifdef __WXMAC_CARBON__
4761 // Human Interface Guidelines ask us for a special font in this case
4762 if ( GetWindowVariant() == wxWINDOW_VARIANT_NORMAL
)
4765 font
.MacCreateThemeFont( kThemeViewsFont
);
4770 if ( InReportView() )
4772 CreateHeaderWindow();
4774 #ifdef __WXMAC_CARBON__
4778 font
.MacCreateThemeFont( kThemeSmallSystemFont
);
4779 m_headerWin
->SetFont( font
);
4780 CalculateAndSetHeaderHeight();
4784 if ( HasFlag(wxLC_NO_HEADER
) )
4785 // VZ: why do we create it at all then?
4786 m_headerWin
->Show( false );
4794 void wxGenericListCtrl::SetSingleStyle( long style
, bool add
)
4796 wxASSERT_MSG( !(style
& wxLC_VIRTUAL
),
4797 _T("wxLC_VIRTUAL can't be [un]set") );
4799 long flag
= GetWindowStyle();
4803 if (style
& wxLC_MASK_TYPE
)
4804 flag
&= ~(wxLC_MASK_TYPE
| wxLC_VIRTUAL
);
4805 if (style
& wxLC_MASK_ALIGN
)
4806 flag
&= ~wxLC_MASK_ALIGN
;
4807 if (style
& wxLC_MASK_SORT
)
4808 flag
&= ~wxLC_MASK_SORT
;
4816 SetWindowStyleFlag( flag
);
4819 void wxGenericListCtrl::SetWindowStyleFlag( long flag
)
4823 m_mainWin
->DeleteEverything();
4825 // has the header visibility changed?
4826 bool hasHeader
= HasHeader();
4827 bool willHaveHeader
= (flag
& wxLC_REPORT
) && !(flag
& wxLC_NO_HEADER
);
4829 if ( hasHeader
!= willHaveHeader
)
4836 // don't delete, just hide, as we can reuse it later
4837 m_headerWin
->Show(false);
4839 //else: nothing to do
4841 else // must show header
4845 CreateHeaderWindow();
4847 else // already have it, just show
4849 m_headerWin
->Show( true );
4853 ResizeReportView(willHaveHeader
);
4857 wxWindow::SetWindowStyleFlag( flag
);
4860 bool wxGenericListCtrl::GetColumn(int col
, wxListItem
&item
) const
4862 m_mainWin
->GetColumn( col
, item
);
4866 bool wxGenericListCtrl::SetColumn( int col
, wxListItem
& item
)
4868 m_mainWin
->SetColumn( col
, item
);
4872 int wxGenericListCtrl::GetColumnWidth( int col
) const
4874 return m_mainWin
->GetColumnWidth( col
);
4877 bool wxGenericListCtrl::SetColumnWidth( int col
, int width
)
4879 m_mainWin
->SetColumnWidth( col
, width
);
4883 int wxGenericListCtrl::GetCountPerPage() const
4885 return m_mainWin
->GetCountPerPage(); // different from Windows ?
4888 bool wxGenericListCtrl::GetItem( wxListItem
&info
) const
4890 m_mainWin
->GetItem( info
);
4894 bool wxGenericListCtrl::SetItem( wxListItem
&info
)
4896 m_mainWin
->SetItem( info
);
4900 long wxGenericListCtrl::SetItem( long index
, int col
, const wxString
& label
, int imageId
)
4903 info
.m_text
= label
;
4904 info
.m_mask
= wxLIST_MASK_TEXT
;
4905 info
.m_itemId
= index
;
4909 info
.m_image
= imageId
;
4910 info
.m_mask
|= wxLIST_MASK_IMAGE
;
4913 m_mainWin
->SetItem(info
);
4917 int wxGenericListCtrl::GetItemState( long item
, long stateMask
) const
4919 return m_mainWin
->GetItemState( item
, stateMask
);
4922 bool wxGenericListCtrl::SetItemState( long item
, long state
, long stateMask
)
4924 m_mainWin
->SetItemState( item
, state
, stateMask
);
4929 wxGenericListCtrl::SetItemImage( long item
, int image
, int WXUNUSED(selImage
) )
4932 info
.m_image
= image
;
4933 info
.m_mask
= wxLIST_MASK_IMAGE
;
4934 info
.m_itemId
= item
;
4935 m_mainWin
->SetItem( info
);
4939 wxString
wxGenericListCtrl::GetItemText( long item
) const
4941 return m_mainWin
->GetItemText(item
);
4944 void wxGenericListCtrl::SetItemText( long item
, const wxString
& str
)
4946 m_mainWin
->SetItemText(item
, str
);
4949 wxUIntPtr
wxGenericListCtrl::GetItemData( long item
) const
4952 info
.m_mask
= wxLIST_MASK_DATA
;
4953 info
.m_itemId
= item
;
4954 m_mainWin
->GetItem( info
);
4958 bool wxGenericListCtrl::SetItemData( long item
, long data
)
4961 info
.m_mask
= wxLIST_MASK_DATA
;
4962 info
.m_itemId
= item
;
4964 m_mainWin
->SetItem( info
);
4968 wxRect
wxGenericListCtrl::GetViewRect() const
4970 return m_mainWin
->GetViewRect();
4973 bool wxGenericListCtrl::GetItemRect( long item
, wxRect
&rect
, int WXUNUSED(code
) ) const
4975 m_mainWin
->GetItemRect( item
, rect
);
4976 if ( m_mainWin
->HasHeader() )
4977 rect
.y
+= m_headerHeight
+ 1;
4981 bool wxGenericListCtrl::GetItemPosition( long item
, wxPoint
& pos
) const
4983 m_mainWin
->GetItemPosition( item
, pos
);
4987 bool wxGenericListCtrl::SetItemPosition( long WXUNUSED(item
), const wxPoint
& WXUNUSED(pos
) )
4992 int wxGenericListCtrl::GetItemCount() const
4994 return m_mainWin
->GetItemCount();
4997 int wxGenericListCtrl::GetColumnCount() const
4999 return m_mainWin
->GetColumnCount();
5002 void wxGenericListCtrl::SetItemSpacing( int spacing
, bool isSmall
)
5004 m_mainWin
->SetItemSpacing( spacing
, isSmall
);
5007 wxSize
wxGenericListCtrl::GetItemSpacing() const
5009 const int spacing
= m_mainWin
->GetItemSpacing(HasFlag(wxLC_SMALL_ICON
));
5011 return wxSize(spacing
, spacing
);
5014 int wxGenericListCtrl::GetItemSpacing( bool isSmall
) const
5016 return m_mainWin
->GetItemSpacing( isSmall
);
5019 void wxGenericListCtrl::SetItemTextColour( long item
, const wxColour
&col
)
5022 info
.m_itemId
= item
;
5023 info
.SetTextColour( col
);
5024 m_mainWin
->SetItem( info
);
5027 wxColour
wxGenericListCtrl::GetItemTextColour( long item
) const
5030 info
.m_itemId
= item
;
5031 m_mainWin
->GetItem( info
);
5032 return info
.GetTextColour();
5035 void wxGenericListCtrl::SetItemBackgroundColour( long item
, const wxColour
&col
)
5038 info
.m_itemId
= item
;
5039 info
.SetBackgroundColour( col
);
5040 m_mainWin
->SetItem( info
);
5043 wxColour
wxGenericListCtrl::GetItemBackgroundColour( long item
) const
5046 info
.m_itemId
= item
;
5047 m_mainWin
->GetItem( info
);
5048 return info
.GetBackgroundColour();
5051 void wxGenericListCtrl::SetItemFont( long item
, const wxFont
&f
)
5054 info
.m_itemId
= item
;
5056 m_mainWin
->SetItem( info
);
5059 wxFont
wxGenericListCtrl::GetItemFont( long item
) const
5062 info
.m_itemId
= item
;
5063 m_mainWin
->GetItem( info
);
5064 return info
.GetFont();
5067 int wxGenericListCtrl::GetSelectedItemCount() const
5069 return m_mainWin
->GetSelectedItemCount();
5072 wxColour
wxGenericListCtrl::GetTextColour() const
5074 return GetForegroundColour();
5077 void wxGenericListCtrl::SetTextColour(const wxColour
& col
)
5079 SetForegroundColour(col
);
5082 long wxGenericListCtrl::GetTopItem() const
5085 m_mainWin
->GetVisibleLinesRange(&top
, NULL
);
5089 long wxGenericListCtrl::GetNextItem( long item
, int geom
, int state
) const
5091 return m_mainWin
->GetNextItem( item
, geom
, state
);
5094 wxImageListType
*wxGenericListCtrl::GetImageList(int which
) const
5096 if (which
== wxIMAGE_LIST_NORMAL
)
5097 return m_imageListNormal
;
5098 else if (which
== wxIMAGE_LIST_SMALL
)
5099 return m_imageListSmall
;
5100 else if (which
== wxIMAGE_LIST_STATE
)
5101 return m_imageListState
;
5103 return (wxImageListType
*) NULL
;
5106 void wxGenericListCtrl::SetImageList( wxImageListType
*imageList
, int which
)
5108 if ( which
== wxIMAGE_LIST_NORMAL
)
5110 if (m_ownsImageListNormal
)
5111 delete m_imageListNormal
;
5112 m_imageListNormal
= imageList
;
5113 m_ownsImageListNormal
= false;
5115 else if ( which
== wxIMAGE_LIST_SMALL
)
5117 if (m_ownsImageListSmall
)
5118 delete m_imageListSmall
;
5119 m_imageListSmall
= imageList
;
5120 m_ownsImageListSmall
= false;
5122 else if ( which
== wxIMAGE_LIST_STATE
)
5124 if (m_ownsImageListState
)
5125 delete m_imageListState
;
5126 m_imageListState
= imageList
;
5127 m_ownsImageListState
= false;
5130 m_mainWin
->SetImageList( imageList
, which
);
5133 void wxGenericListCtrl::AssignImageList(wxImageListType
*imageList
, int which
)
5135 SetImageList(imageList
, which
);
5136 if ( which
== wxIMAGE_LIST_NORMAL
)
5137 m_ownsImageListNormal
= true;
5138 else if ( which
== wxIMAGE_LIST_SMALL
)
5139 m_ownsImageListSmall
= true;
5140 else if ( which
== wxIMAGE_LIST_STATE
)
5141 m_ownsImageListState
= true;
5144 bool wxGenericListCtrl::Arrange( int WXUNUSED(flag
) )
5149 bool wxGenericListCtrl::DeleteItem( long item
)
5151 m_mainWin
->DeleteItem( item
);
5155 bool wxGenericListCtrl::DeleteAllItems()
5157 m_mainWin
->DeleteAllItems();
5161 bool wxGenericListCtrl::DeleteAllColumns()
5163 size_t count
= m_mainWin
->m_columns
.GetCount();
5164 for ( size_t n
= 0; n
< count
; n
++ )
5169 void wxGenericListCtrl::ClearAll()
5171 m_mainWin
->DeleteEverything();
5174 bool wxGenericListCtrl::DeleteColumn( int col
)
5176 m_mainWin
->DeleteColumn( col
);
5178 // if we don't have the header any longer, we need to relayout the window
5179 if ( !GetColumnCount() )
5180 ResizeReportView(false /* no header */);
5184 wxTextCtrl
*wxGenericListCtrl::EditLabel(long item
,
5185 wxClassInfo
* textControlClass
)
5187 return m_mainWin
->EditLabel( item
, textControlClass
);
5190 wxTextCtrl
*wxGenericListCtrl::GetEditControl() const
5192 return m_mainWin
->GetEditControl();
5195 bool wxGenericListCtrl::EnsureVisible( long item
)
5197 m_mainWin
->EnsureVisible( item
);
5201 long wxGenericListCtrl::FindItem( long start
, const wxString
& str
, bool partial
)
5203 return m_mainWin
->FindItem( start
, str
, partial
);
5206 long wxGenericListCtrl::FindItem( long start
, wxUIntPtr data
)
5208 return m_mainWin
->FindItem( start
, data
);
5211 long wxGenericListCtrl::FindItem( long WXUNUSED(start
), const wxPoint
& pt
,
5212 int WXUNUSED(direction
))
5214 return m_mainWin
->FindItem( pt
);
5217 long wxGenericListCtrl::HitTest( const wxPoint
&point
, int &flags
)
5219 return m_mainWin
->HitTest( (int)point
.x
, (int)point
.y
, flags
);
5222 long wxGenericListCtrl::InsertItem( wxListItem
& info
)
5224 m_mainWin
->InsertItem( info
);
5225 return info
.m_itemId
;
5228 long wxGenericListCtrl::InsertItem( long index
, const wxString
&label
)
5231 info
.m_text
= label
;
5232 info
.m_mask
= wxLIST_MASK_TEXT
;
5233 info
.m_itemId
= index
;
5234 return InsertItem( info
);
5237 long wxGenericListCtrl::InsertItem( long index
, int imageIndex
)
5240 info
.m_mask
= wxLIST_MASK_IMAGE
;
5241 info
.m_image
= imageIndex
;
5242 info
.m_itemId
= index
;
5243 return InsertItem( info
);
5246 long wxGenericListCtrl::InsertItem( long index
, const wxString
&label
, int imageIndex
)
5249 info
.m_text
= label
;
5250 info
.m_image
= imageIndex
;
5251 info
.m_mask
= wxLIST_MASK_TEXT
| wxLIST_MASK_IMAGE
;
5252 info
.m_itemId
= index
;
5253 return InsertItem( info
);
5256 long wxGenericListCtrl::InsertColumn( long col
, wxListItem
&item
)
5258 wxCHECK_MSG( m_headerWin
, -1, _T("can't add column in non report mode") );
5260 m_mainWin
->InsertColumn( col
, item
);
5262 // if we hadn't had a header before but have one now
5263 // then we need to relayout the window
5264 if ( GetColumnCount() == 1 && m_mainWin
->HasHeader() )
5265 ResizeReportView(true /* have header */);
5267 m_headerWin
->Refresh();
5272 long wxGenericListCtrl::InsertColumn( long col
, const wxString
&heading
,
5273 int format
, int width
)
5276 item
.m_mask
= wxLIST_MASK_TEXT
| wxLIST_MASK_FORMAT
;
5277 item
.m_text
= heading
;
5280 item
.m_mask
|= wxLIST_MASK_WIDTH
;
5281 item
.m_width
= width
;
5284 item
.m_format
= format
;
5286 return InsertColumn( col
, item
);
5289 bool wxGenericListCtrl::ScrollList( int WXUNUSED(dx
), int WXUNUSED(dy
) )
5295 // fn is a function which takes 3 long arguments: item1, item2, data.
5296 // item1 is the long data associated with a first item (NOT the index).
5297 // item2 is the long data associated with a second item (NOT the index).
5298 // data is the same value as passed to SortItems.
5299 // The return value is a negative number if the first item should precede the second
5300 // item, a positive number of the second item should precede the first,
5301 // or zero if the two items are equivalent.
5302 // data is arbitrary data to be passed to the sort function.
5304 bool wxGenericListCtrl::SortItems( wxListCtrlCompare fn
, long data
)
5306 m_mainWin
->SortItems( fn
, data
);
5310 // ----------------------------------------------------------------------------
5312 // ----------------------------------------------------------------------------
5314 void wxGenericListCtrl::OnSize(wxSizeEvent
& WXUNUSED(event
))
5319 ResizeReportView(m_mainWin
->HasHeader());
5320 m_mainWin
->RecalculatePositions();
5323 void wxGenericListCtrl::ResizeReportView(bool showHeader
)
5326 GetClientSize( &cw
, &ch
);
5330 m_headerWin
->SetSize( 0, 0, cw
, m_headerHeight
);
5331 if(ch
> m_headerHeight
)
5332 m_mainWin
->SetSize( 0, m_headerHeight
+ 1,
5333 cw
, ch
- m_headerHeight
- 1 );
5335 m_mainWin
->SetSize( 0, m_headerHeight
+ 1,
5338 else // no header window
5340 m_mainWin
->SetSize( 0, 0, cw
, ch
);
5344 void wxGenericListCtrl::OnInternalIdle()
5346 wxWindow::OnInternalIdle();
5348 // do it only if needed
5349 if ( !m_mainWin
->m_dirty
)
5352 m_mainWin
->RecalculatePositions();
5355 // ----------------------------------------------------------------------------
5357 // ----------------------------------------------------------------------------
5359 bool wxGenericListCtrl::SetBackgroundColour( const wxColour
&colour
)
5363 m_mainWin
->SetBackgroundColour( colour
);
5364 m_mainWin
->m_dirty
= true;
5370 bool wxGenericListCtrl::SetForegroundColour( const wxColour
&colour
)
5372 if ( !wxWindow::SetForegroundColour( colour
) )
5377 m_mainWin
->SetForegroundColour( colour
);
5378 m_mainWin
->m_dirty
= true;
5382 m_headerWin
->SetForegroundColour( colour
);
5387 bool wxGenericListCtrl::SetFont( const wxFont
&font
)
5389 if ( !wxWindow::SetFont( font
) )
5394 m_mainWin
->SetFont( font
);
5395 m_mainWin
->m_dirty
= true;
5400 m_headerWin
->SetFont( font
);
5401 CalculateAndSetHeaderHeight();
5410 #include "wx/listbox.h"
5415 wxGenericListCtrl::GetClassDefaultAttributes(wxWindowVariant variant
)
5418 // Use the same color scheme as wxListBox
5419 return wxListBox::GetClassDefaultAttributes(variant
);
5421 wxUnusedVar(variant
);
5422 wxVisualAttributes attr
;
5423 attr
.colFg
= wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT
);
5424 attr
.colBg
= wxSystemSettings::GetColour(wxSYS_COLOUR_LISTBOX
);
5425 attr
.font
= wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT
);
5430 // ----------------------------------------------------------------------------
5431 // methods forwarded to m_mainWin
5432 // ----------------------------------------------------------------------------
5434 #if wxUSE_DRAG_AND_DROP
5436 void wxGenericListCtrl::SetDropTarget( wxDropTarget
*dropTarget
)
5438 m_mainWin
->SetDropTarget( dropTarget
);
5441 wxDropTarget
*wxGenericListCtrl::GetDropTarget() const
5443 return m_mainWin
->GetDropTarget();
5448 bool wxGenericListCtrl::SetCursor( const wxCursor
&cursor
)
5450 return m_mainWin
? m_mainWin
->wxWindow::SetCursor(cursor
) : false;
5453 wxColour
wxGenericListCtrl::GetBackgroundColour() const
5455 return m_mainWin
? m_mainWin
->GetBackgroundColour() : wxColour();
5458 wxColour
wxGenericListCtrl::GetForegroundColour() const
5460 return m_mainWin
? m_mainWin
->GetForegroundColour() : wxColour();
5463 bool wxGenericListCtrl::DoPopupMenu( wxMenu
*menu
, int x
, int y
)
5466 return m_mainWin
->PopupMenu( menu
, x
, y
);
5472 void wxGenericListCtrl::DoClientToScreen( int *x
, int *y
) const
5474 return m_mainWin
->DoClientToScreen(x
, y
);
5477 void wxGenericListCtrl::DoScreenToClient( int *x
, int *y
) const
5479 return m_mainWin
->DoScreenToClient(x
, y
);
5482 void wxGenericListCtrl::SetFocus()
5484 // The test in window.cpp fails as we are a composite
5485 // window, so it checks against "this", but not m_mainWin.
5486 if ( DoFindFocus() != this )
5487 m_mainWin
->SetFocus();
5490 wxSize
wxGenericListCtrl::DoGetBestSize() const
5492 // Something is better than nothing...
5493 // 100x80 is what the MSW version will get from the default
5494 // wxControl::DoGetBestSize
5495 return wxSize(100, 80);
5498 // ----------------------------------------------------------------------------
5499 // virtual list control support
5500 // ----------------------------------------------------------------------------
5502 wxString
wxGenericListCtrl::OnGetItemText(long WXUNUSED(item
), long WXUNUSED(col
)) const
5504 // this is a pure virtual function, in fact - which is not really pure
5505 // because the controls which are not virtual don't need to implement it
5506 wxFAIL_MSG( _T("wxGenericListCtrl::OnGetItemText not supposed to be called") );
5508 return wxEmptyString
;
5511 int wxGenericListCtrl::OnGetItemImage(long WXUNUSED(item
)) const
5513 wxCHECK_MSG(!GetImageList(wxIMAGE_LIST_SMALL
),
5515 wxT("List control has an image list, OnGetItemImage or OnGetItemColumnImage should be overridden."));
5519 int wxGenericListCtrl::OnGetItemColumnImage(long item
, long column
) const
5522 return OnGetItemImage(item
);
5528 wxGenericListCtrl::OnGetItemAttr(long WXUNUSED_UNLESS_DEBUG(item
)) const
5530 wxASSERT_MSG( item
>= 0 && item
< GetItemCount(),
5531 _T("invalid item index in OnGetItemAttr()") );
5533 // no attributes by default
5537 void wxGenericListCtrl::SetItemCount(long count
)
5539 wxASSERT_MSG( IsVirtual(), _T("this is for virtual controls only") );
5541 m_mainWin
->SetItemCount(count
);
5544 void wxGenericListCtrl::RefreshItem(long item
)
5546 m_mainWin
->RefreshLine(item
);
5549 void wxGenericListCtrl::RefreshItems(long itemFrom
, long itemTo
)
5551 m_mainWin
->RefreshLines(itemFrom
, itemTo
);
5554 // Generic wxListCtrl is more or less a container for two other
5555 // windows which drawings are done upon. These are namely
5556 // 'm_headerWin' and 'm_mainWin'.
5557 // Here we override 'virtual wxWindow::Refresh()' to mimic the
5558 // behaviour wxListCtrl has under wxMSW.
5560 void wxGenericListCtrl::Refresh(bool eraseBackground
, const wxRect
*rect
)
5564 // The easy case, no rectangle specified.
5566 m_headerWin
->Refresh(eraseBackground
);
5569 m_mainWin
->Refresh(eraseBackground
);
5573 // Refresh the header window
5576 wxRect rectHeader
= m_headerWin
->GetRect();
5577 rectHeader
.Intersect(*rect
);
5578 if (rectHeader
.GetWidth() && rectHeader
.GetHeight())
5581 m_headerWin
->GetPosition(&x
, &y
);
5582 rectHeader
.Offset(-x
, -y
);
5583 m_headerWin
->Refresh(eraseBackground
, &rectHeader
);
5587 // Refresh the main window
5590 wxRect rectMain
= m_mainWin
->GetRect();
5591 rectMain
.Intersect(*rect
);
5592 if (rectMain
.GetWidth() && rectMain
.GetHeight())
5595 m_mainWin
->GetPosition(&x
, &y
);
5596 rectMain
.Offset(-x
, -y
);
5597 m_mainWin
->Refresh(eraseBackground
, &rectMain
);
5603 void wxGenericListCtrl::Freeze()
5605 m_mainWin
->Freeze();
5608 void wxGenericListCtrl::Thaw()
5613 #endif // wxUSE_LISTCTRL