1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/generic/listctrl.cpp
3 // Purpose: generic implementation of wxListCtrl
4 // Author: Robert Roebling
5 // Vadim Zeitlin (virtual list control support)
7 // Copyright: Copyright (c) 1998-2011 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>
29 #include <wx/scrolwin.h>
31 #include <wx/settings.h>
32 #include <wx/dynarray.h>
33 #include <wx/dcclient.h>
34 #include <wx/dcscreen.h>
38 #include <wx/imaglist.h>
39 #include <wx/selstore.h>
40 #include <wx/renderer.h>
41 #include <wx/dcbuffer.h>
43 #if wxCHECK_VERSION(2, 9, 0)
44 // wxWidgets 2.9+ does not include a mac/private anymore.
46 #if defined( __WXMAC__ ) && !defined(__WXUNIVERSAL__) && (wxOSX_USE_CARBON || TARGET_CARBON)
47 #include <wx/mac/private.h>
52 // NOTE: If using the wxListBox visual attributes works everywhere then this can
53 // be removed, as well as the #else case below.
54 #define _USE_VISATTR 0
56 namespace MuleExtern
{
58 // ----------------------------------------------------------------------------
60 // ----------------------------------------------------------------------------
62 // // the height of the header window (FIXME: should depend on its font!)
63 // static const int HEADER_HEIGHT = 23;
65 static const int SCROLL_UNIT_X
= 15;
67 // the spacing between the lines (in report mode)
68 static const int LINE_SPACING
= 0;
70 // extra margins around the text label
72 static const int EXTRA_WIDTH
= 6;
74 static const int EXTRA_WIDTH
= 4;
76 static const int EXTRA_HEIGHT
= 4;
78 // margin between the window and the items
79 static const int EXTRA_BORDER_X
= 2;
80 static const int EXTRA_BORDER_Y
= 2;
82 // offset for the header window
83 static const int HEADER_OFFSET_X
= 0;
84 static const int HEADER_OFFSET_Y
= 0;
86 // margin between rows of icons in [small] icon view
87 static const int MARGIN_BETWEEN_ROWS
= 6;
89 // when autosizing the columns, add some slack
90 static const int AUTOSIZE_COL_MARGIN
= 10;
92 // default width for the header columns
93 static const int WIDTH_COL_DEFAULT
= 80;
95 // the space between the image and the text in the report mode
96 static const int IMAGE_MARGIN_IN_REPORT_MODE
= 5;
98 // the space between the image and the text in the report mode in header
99 static const int HEADER_IMAGE_MARGIN_IN_REPORT_MODE
= 2;
101 const wxChar wxListCtrlNameStr
[] = wxT("listCtrl");
103 // ============================================================================
105 // ============================================================================
107 //-----------------------------------------------------------------------------
108 // wxColWidthInfo (internal)
109 //-----------------------------------------------------------------------------
111 struct wxColWidthInfo
114 bool bNeedsUpdate
; // only set to true when an item whose
115 // width == nMaxWidth is removed
117 wxColWidthInfo(int w
= 0, bool needsUpdate
= false)
120 bNeedsUpdate
= needsUpdate
;
124 WX_DEFINE_ARRAY_PTR(wxColWidthInfo
*, ColWidthArray
);
126 //-----------------------------------------------------------------------------
127 // wxListItemData (internal)
128 //-----------------------------------------------------------------------------
133 wxListItemData(wxListMainWindow
*owner
);
136 void SetItem( const wxListItem
&info
);
137 void SetImage( int image
) { m_image
= image
; }
138 void SetData( wxUIntPtr data
) { m_data
= data
; }
139 void SetPosition( int x
, int y
);
140 void SetSize( int width
, int height
);
142 bool HasText() const { return !m_text
.empty(); }
143 const wxString
& GetText() const { return m_text
; }
144 void SetText(const wxString
& text
) { m_text
= text
; }
146 // we can't use empty string for measuring the string width/height, so
147 // always return something
148 wxString
GetTextForMeasuring() const
150 wxString s
= GetText();
157 bool IsHit( int x
, int y
) const;
161 int GetWidth() const;
162 int GetHeight() const;
164 int GetImage() const { return m_image
; }
165 bool HasImage() const { return GetImage() != -1; }
167 void GetItem( wxListItem
&info
) const;
169 void SetAttr(wxListItemAttr
*attr
) { m_attr
= attr
; }
170 wxListItemAttr
*GetAttr() const { return m_attr
; }
173 // the item image or -1
176 // user data associated with the item
179 // the item coordinates are not used in report mode; instead this pointer is
180 // NULL and the owner window is used to retrieve the item position and size
183 // the list ctrl we are in
184 wxListMainWindow
*m_owner
;
186 // custom attributes or NULL
187 wxListItemAttr
*m_attr
;
190 // common part of all ctors
196 //-----------------------------------------------------------------------------
197 // wxListHeaderData (internal)
198 //-----------------------------------------------------------------------------
200 class wxListHeaderData
: public wxObject
204 wxListHeaderData( const wxListItem
&info
);
205 void SetItem( const wxListItem
&item
);
206 void SetPosition( int x
, int y
);
207 void SetWidth( int w
);
208 void SetState( int state
);
209 void SetFormat( int format
);
210 void SetHeight( int h
);
211 bool HasImage() const;
213 bool HasText() const { return !m_text
.empty(); }
214 const wxString
& GetText() const { return m_text
; }
215 void SetText(const wxString
& text
) { m_text
= text
; }
217 void GetItem( wxListItem
&item
);
219 bool IsHit( int x
, int y
) const;
220 int GetImage() const;
221 int GetWidth() const;
222 int GetFormat() const;
223 int GetState() const;
240 //-----------------------------------------------------------------------------
241 // wxListLineData (internal)
242 //-----------------------------------------------------------------------------
244 WX_DECLARE_LIST(wxListItemData
, wxListItemDataList
);
245 #include <wx/listimpl.cpp>
246 WX_DEFINE_LIST(wxListItemDataList
)
251 // the list of subitems: only may have more than one item in report mode
252 wxListItemDataList m_items
;
254 // this is not used in report view
266 // the part to be highlighted
267 wxRect m_rectHighlight
;
269 // extend all our rects to be centered inside the one of given width
270 void ExtendWidth(wxCoord w
)
272 wxASSERT_MSG( m_rectAll
.width
<= w
,
273 _T("width can only be increased") );
276 m_rectLabel
.x
= m_rectAll
.x
+ (w
- m_rectLabel
.width
) / 2;
277 m_rectIcon
.x
= m_rectAll
.x
+ (w
- m_rectIcon
.width
) / 2;
278 m_rectHighlight
.x
= m_rectAll
.x
+ (w
- m_rectHighlight
.width
) / 2;
283 // is this item selected? [NB: not used in virtual mode]
286 // back pointer to the list ctrl
287 wxListMainWindow
*m_owner
;
290 wxListLineData(wxListMainWindow
*owner
);
294 WX_CLEAR_LIST(wxListItemDataList
, m_items
);
298 // are we in report mode?
299 inline bool InReportView() const;
301 // are we in virtual report mode?
302 inline bool IsVirtual() const;
304 // these 2 methods shouldn't be called for report view controls, in that
305 // case we determine our position/size ourselves
307 // calculate the size of the line
308 void CalculateSize( wxDC
*dc
, int spacing
);
310 // remember the position this line appears at
311 void SetPosition( int x
, int y
, int spacing
);
315 void SetImage( int image
) { SetImage(0, image
); }
316 int GetImage() const { return GetImage(0); }
317 void SetImage( int index
, int image
);
318 int GetImage( int index
) const;
320 bool HasImage() const { return GetImage() != -1; }
321 bool HasText() const { return !GetText(0).empty(); }
323 void SetItem( int index
, const wxListItem
&info
);
324 void GetItem( int index
, wxListItem
&info
);
326 wxString
GetText(int index
) const;
327 void SetText( int index
, const wxString
& s
);
329 wxListItemAttr
*GetAttr() const;
330 void SetAttr(wxListItemAttr
*attr
);
332 // return true if the highlighting really changed
333 bool Highlight( bool on
);
335 void ReverseHighlight();
337 bool IsHighlighted() const
339 wxASSERT_MSG( !IsVirtual(), _T("unexpected call to IsHighlighted") );
341 return m_highlighted
;
344 // draw the line on the given DC in icon/list mode
345 void Draw( wxDC
*dc
);
347 // the same in report mode
348 void DrawInReportMode( wxDC
*dc
,
350 const wxRect
& rectHL
,
354 // set the line to contain num items (only can be > 1 in report mode)
355 void InitItems( int num
);
357 // get the mode (i.e. style) of the list control
358 inline int GetMode() const;
360 // prepare the DC for drawing with these item's attributes, return true if
361 // we need to draw the items background to highlight it, false otherwise
362 bool SetAttributes(wxDC
*dc
,
363 const wxListItemAttr
*attr
,
366 // draw the text on the DC with the correct justification; also add an
367 // ellipsis if the text is too large to fit in the current width
368 void DrawTextFormatted(wxDC
*dc
,
369 const wxString
&text
,
372 int yMid
, // this is middle, not top, of the text
376 WX_DECLARE_OBJARRAY(wxListLineData
, wxListLineDataArray
);
377 #include <wx/arrimpl.cpp>
378 WX_DEFINE_OBJARRAY(wxListLineDataArray
)
380 //-----------------------------------------------------------------------------
381 // wxListHeaderWindow (internal)
382 //-----------------------------------------------------------------------------
384 class wxListHeaderWindow
: public wxWindow
387 wxListMainWindow
*m_owner
;
388 const wxCursor
*m_currentCursor
;
389 wxCursor
*m_resizeCursor
;
392 // column being resized or -1
395 // divider line position in logical (unscrolled) coords
398 // minimal position beyond which the divider line
399 // can't be dragged in logical coords
403 wxListHeaderWindow();
405 wxListHeaderWindow( wxWindow
*win
,
407 wxListMainWindow
*owner
,
408 const wxPoint
&pos
= wxDefaultPosition
,
409 const wxSize
&size
= wxDefaultSize
,
411 const wxString
&name
= wxT("wxlistctrlcolumntitles") );
413 virtual ~wxListHeaderWindow();
416 void AdjustDC( wxDC
& dc
);
418 void OnPaint( wxPaintEvent
&event
);
419 void OnMouse( wxMouseEvent
&event
);
420 void OnSetFocus( wxFocusEvent
&event
);
426 // common part of all ctors
429 // generate and process the list event of the given type, return true if
430 // it wasn't vetoed, i.e. if we should proceed
431 bool SendListEvent(wxEventType type
, const wxPoint
& pos
);
433 DECLARE_EVENT_TABLE()
436 //-----------------------------------------------------------------------------
437 // wxListRenameTimer (internal)
438 //-----------------------------------------------------------------------------
440 class wxListRenameTimer
: public wxTimer
443 wxListMainWindow
*m_owner
;
446 wxListRenameTimer( wxListMainWindow
*owner
);
450 //-----------------------------------------------------------------------------
451 // wxListTextCtrlWrapper: wraps a wxTextCtrl to make it work for inline editing
452 //-----------------------------------------------------------------------------
454 class wxListTextCtrlWrapper
: public wxEvtHandler
457 // NB: text must be a valid object but not Create()d yet
458 wxListTextCtrlWrapper(wxListMainWindow
*owner
,
462 wxTextCtrl
*GetText() const { return m_text
; }
464 void AcceptChangesAndFinish();
467 void OnChar( wxKeyEvent
&event
);
468 void OnKeyUp( wxKeyEvent
&event
);
469 void OnKillFocus( wxFocusEvent
&event
);
471 bool AcceptChanges();
475 wxListMainWindow
*m_owner
;
477 wxString m_startValue
;
480 bool m_aboutToFinish
;
482 DECLARE_EVENT_TABLE()
485 //-----------------------------------------------------------------------------
486 // wxListMainWindow (internal)
487 //-----------------------------------------------------------------------------
489 WX_DECLARE_LIST(wxListHeaderData
, wxListHeaderDataList
);
490 #include <wx/listimpl.cpp>
491 WX_DEFINE_LIST(wxListHeaderDataList
)
493 class wxListMainWindow
: public wxScrolledWindow
497 wxListMainWindow( wxWindow
*parent
,
499 const wxPoint
& pos
= wxDefaultPosition
,
500 const wxSize
& size
= wxDefaultSize
,
502 const wxString
&name
= _T("listctrlmainwindow") );
504 virtual ~wxListMainWindow();
506 bool HasFlag(int flag
) const { return m_parent
->HasFlag(flag
); }
508 // return true if this is a virtual list control
509 bool IsVirtual() const { return HasFlag(wxLC_VIRTUAL
); }
511 // return true if the control is in report mode
512 bool InReportView() const { return HasFlag(wxLC_REPORT
); }
514 // return true if we are in single selection mode, false if multi sel
515 bool IsSingleSel() const { return HasFlag(wxLC_SINGLE_SEL
); }
517 // do we have a header window?
518 bool HasHeader() const
519 { return InReportView() && !HasFlag(wxLC_NO_HEADER
); }
521 void HighlightAll( bool on
);
523 // all these functions only do something if the line is currently visible
525 // change the line "selected" state, return true if it really changed
526 bool HighlightLine( size_t line
, bool highlight
= true);
528 // as HighlightLine() but do it for the range of lines: this is incredibly
529 // more efficient for virtual list controls!
531 // NB: unlike HighlightLine() this one does refresh the lines on screen
532 void HighlightLines( size_t lineFrom
, size_t lineTo
, bool on
= true );
534 // toggle the line state and refresh it
535 void ReverseHighlight( size_t line
)
536 { HighlightLine(line
, !IsHighlighted(line
)); RefreshLine(line
); }
538 // return true if the line is highlighted
539 bool IsHighlighted(size_t line
) const;
541 // refresh one or several lines at once
542 void RefreshLine( size_t line
);
543 void RefreshLines( size_t lineFrom
, size_t lineTo
);
545 // refresh all selected items
546 void RefreshSelected();
548 // refresh all lines below the given one: the difference with
549 // RefreshLines() is that the index here might not be a valid one (happens
550 // when the last line is deleted)
551 void RefreshAfter( size_t lineFrom
);
553 // the methods which are forwarded to wxListLineData itself in list/icon
554 // modes but are here because the lines don't store their positions in the
557 // get the bound rect for the entire line
558 wxRect
GetLineRect(size_t line
) const;
560 // get the bound rect of the label
561 wxRect
GetLineLabelRect(size_t line
) const;
563 // get the bound rect of the items icon (only may be called if we do have
565 wxRect
GetLineIconRect(size_t line
) const;
567 // get the rect to be highlighted when the item has focus
568 wxRect
GetLineHighlightRect(size_t line
) const;
570 // get the size of the total line rect
571 wxSize
GetLineSize(size_t line
) const
572 { return GetLineRect(line
).GetSize(); }
574 // return the hit code for the corresponding position (in this line)
575 long HitTestLine(size_t line
, int x
, int y
) const;
577 // bring the selected item into view, scrolling to it if necessary
578 void MoveToItem(size_t item
);
580 // bring the current item into view
581 void MoveToFocus() { MoveToItem(m_current
); }
583 // start editing the label of the given item
584 wxTextCtrl
*EditLabel(long item
,
585 wxClassInfo
* textControlClass
= CLASSINFO(wxTextCtrl
));
586 wxTextCtrl
*GetEditControl() const
588 return m_textctrlWrapper
? m_textctrlWrapper
->GetText() : NULL
;
591 void FinishEditing(wxTextCtrl
*text
)
594 m_textctrlWrapper
= NULL
;
595 SetFocusIgnoringChildren();
598 // suspend/resume redrawing the control
602 void OnRenameTimer();
603 bool OnRenameAccept(size_t itemEdit
, const wxString
& value
);
604 void OnRenameCancelled(size_t itemEdit
);
606 void OnMouse( wxMouseEvent
&event
);
608 // called to switch the selection from the current item to newCurrent,
609 void OnArrowChar( size_t newCurrent
, const wxKeyEvent
& event
);
611 void OnChar( wxKeyEvent
&event
);
612 void OnKeyDown( wxKeyEvent
&event
);
613 void OnKeyUp( wxKeyEvent
&event
);
614 void OnSetFocus( wxFocusEvent
&event
);
615 void OnKillFocus( wxFocusEvent
&event
);
616 void OnScroll( wxScrollWinEvent
& event
);
618 void OnPaint( wxPaintEvent
&event
);
619 void OnErase( wxEraseEvent
& event
) {
620 // This is needed to avoid garbage on empty lists.
626 void OnChildFocus(wxChildFocusEvent
& event
);
628 void DrawImage( int index
, wxDC
*dc
, int x
, int y
);
629 void GetImageSize( int index
, int &width
, int &height
) const;
630 int GetTextLength( const wxString
&s
) const;
632 void SetImageList( wxImageList
*imageList
, int which
);
633 void SetItemSpacing( int spacing
, bool isSmall
= false );
634 int GetItemSpacing( bool isSmall
= false );
636 void SetColumn( int col
, wxListItem
&item
);
637 void SetColumnWidth( int col
, int width
);
638 void GetColumn( int col
, wxListItem
&item
) const;
639 int GetColumnWidth( int col
) const;
640 int GetColumnCount() const { return m_columns
.GetCount(); }
642 // returns the sum of the heights of all columns
643 int GetHeaderWidth() const;
645 int GetCountPerPage() const;
647 void SetItem( wxListItem
&item
);
648 void GetItem( wxListItem
&item
) const;
649 void SetItemState( long item
, long state
, long stateMask
);
650 void SetItemStateAll( long state
, long stateMask
);
651 int GetItemState( long item
, long stateMask
) const;
652 void GetItemRect( long index
, wxRect
&rect
) const;
653 wxRect
GetViewRect() const;
654 bool GetItemPosition( long item
, wxPoint
& pos
) const;
655 int GetSelectedItemCount() const;
657 wxString
GetItemText(long item
) const
660 info
.m_mask
= wxLIST_MASK_TEXT
;
661 info
.m_itemId
= item
;
666 void SetItemText(long item
, const wxString
& value
)
669 info
.m_mask
= wxLIST_MASK_TEXT
;
670 info
.m_itemId
= item
;
675 // set the scrollbars and update the positions of the items
676 void RecalculatePositions(bool noRefresh
= false);
678 // refresh the window and the header
681 long GetNextItem( long item
, int geometry
, int state
) const;
682 void DeleteItem( long index
);
683 void DeleteAllItems();
684 void DeleteColumn( int col
);
685 void DeleteEverything();
686 void EnsureVisible( long index
);
687 long FindItem( long start
, const wxString
& str
, bool partial
= false );
688 long FindItem( long start
, wxUIntPtr data
);
689 long FindItem( const wxPoint
& pt
);
690 long HitTest( int x
, int y
, int &flags
) const;
691 void InsertItem( wxListItem
&item
);
692 void InsertColumn( long col
, wxListItem
&item
);
693 int GetItemWidthWithImage(wxListItem
* item
);
694 void SortItems( MuleListCtrlCompare fn
, long data
);
696 size_t GetItemCount() const;
697 bool IsEmpty() const { return GetItemCount() == 0; }
698 void SetItemCount(long count
);
700 // change the current (== focused) item, send a notification event
701 void ChangeCurrent(size_t current
);
702 void ResetCurrent() { ChangeCurrent((size_t)-1); }
703 bool HasCurrent() const { return m_current
!= (size_t)-1; }
705 // send out a wxListEvent
706 void SendNotify( size_t line
,
708 const wxPoint
& point
= wxDefaultPosition
);
710 // override base class virtual to reset m_lineHeight when the font changes
711 virtual bool SetFont(const wxFont
& font
)
713 if ( !wxScrolledWindow::SetFont(font
) )
721 // these are for wxListLineData usage only
723 // get the backpointer to the list ctrl
724 wxGenericListCtrl
*GetListCtrl() const
726 return wxStaticCast(GetParent(), wxGenericListCtrl
);
729 // get the height of all lines (assuming they all do have the same height)
730 wxCoord
GetLineHeight() const;
732 // get the y position of the given line (only for report view)
733 wxCoord
GetLineY(size_t line
) const;
735 // get the brush to use for the item highlighting
736 const wxBrush
& GetHighlightBrush() const
738 return m_hasFocus
? m_highlightBrush
: m_highlightUnfocusedBrush
;
741 bool HasFocus() const
747 // the array of all line objects for a non virtual list control (for the
748 // virtual list control we only ever use m_lines[0])
749 wxListLineDataArray m_lines
;
751 // the list of column objects
752 wxListHeaderDataList m_columns
;
754 // currently focused item or -1
757 // the number of lines per page
760 // this flag is set when something which should result in the window
761 // redrawing happens (i.e. an item was added or deleted, or its appearance
762 // changed) and OnPaint() doesn't redraw the window while it is set which
763 // allows to minimize the number of repaintings when a lot of items are
764 // being added. The real repainting occurs only after the next OnIdle()
768 wxColour
*m_highlightColour
;
769 wxImageList
*m_small_image_list
;
770 wxImageList
*m_normal_image_list
;
772 int m_normal_spacing
;
776 wxTimer
*m_renameTimer
;
780 ColWidthArray m_aColWidths
;
782 // for double click logic
783 size_t m_lineLastClicked
,
784 m_lineBeforeLastClicked
,
785 m_lineSelectSingleOnUp
;
788 wxWindow
*GetMainWindowOfCompositeControl() { return GetParent(); }
790 // the total count of items in a virtual list control
793 // the object maintaining the items selection state, only used in virtual
795 wxSelectionStore m_selStore
;
797 // common part of all ctors
800 // get the line data for the given index
801 wxListLineData
*GetLine(size_t n
) const
803 wxASSERT_MSG( n
!= (size_t)-1, _T("invalid line index") );
807 wxConstCast(this, wxListMainWindow
)->CacheLineData(n
);
814 // get a dummy line which can be used for geometry calculations and such:
815 // you must use GetLine() if you want to really draw the line
816 wxListLineData
*GetDummyLine() const;
818 // cache the line data of the n-th line in m_lines[0]
819 void CacheLineData(size_t line
);
821 // get the range of visible lines
822 void GetVisibleLinesRange(size_t *from
, size_t *to
);
824 // force us to recalculate the range of visible lines
825 void ResetVisibleLinesRange() { m_lineFrom
= (size_t)-1; }
827 // get the colour to be used for drawing the rules
828 wxColour
GetRuleColour() const
830 return wxSystemSettings::GetColour(wxSYS_COLOUR_3DLIGHT
);
834 // initialize the current item if needed
835 void UpdateCurrent();
837 // delete all items but don't refresh: called from dtor
838 void DoDeleteAllItems();
840 // the height of one line using the current font
841 wxCoord m_lineHeight
;
843 // the total header width or 0 if not calculated yet
844 wxCoord m_headerWidth
;
846 // the first and last lines being shown on screen right now (inclusive),
847 // both may be -1 if they must be calculated so never access them directly:
848 // use GetVisibleLinesRange() above instead
852 // the brushes to use for item highlighting when we do/don't have focus
853 wxBrush m_highlightBrush
,
854 m_highlightUnfocusedBrush
;
856 // if this is > 0, the control is frozen and doesn't redraw itself
857 size_t m_freezeCount
;
859 // wrapper around the text control currently used for in place editing or
860 // NULL if no item is being edited
861 wxListTextCtrlWrapper
*m_textctrlWrapper
;
864 DECLARE_EVENT_TABLE()
866 friend class wxGenericListCtrl
;
870 wxListItemData::~wxListItemData()
872 // in the virtual list control the attributes are managed by the main
873 // program, so don't delete them
874 if ( !m_owner
->IsVirtual() )
880 void wxListItemData::Init()
888 wxListItemData::wxListItemData(wxListMainWindow
*owner
)
894 if ( owner
->InReportView() )
900 void wxListItemData::SetItem( const wxListItem
&info
)
902 if ( info
.m_mask
& wxLIST_MASK_TEXT
)
903 SetText(info
.m_text
);
904 if ( info
.m_mask
& wxLIST_MASK_IMAGE
)
905 m_image
= info
.m_image
;
906 if ( info
.m_mask
& wxLIST_MASK_DATA
)
907 m_data
= info
.m_data
;
909 if ( info
.HasAttributes() )
912 m_attr
->AssignFrom(*info
.GetAttributes());
914 m_attr
= new wxListItemAttr(*info
.GetAttributes());
922 m_rect
->width
= info
.m_width
;
926 void wxListItemData::SetPosition( int x
, int y
)
928 wxCHECK_RET( m_rect
, _T("unexpected SetPosition() call") );
934 void wxListItemData::SetSize( int width
, int height
)
936 wxCHECK_RET( m_rect
, _T("unexpected SetSize() call") );
939 m_rect
->width
= width
;
941 m_rect
->height
= height
;
944 bool wxListItemData::IsHit( int x
, int y
) const
946 wxCHECK_MSG( m_rect
, false, _T("can't be called in this mode") );
948 return wxRect(GetX(), GetY(), GetWidth(), GetHeight()).Contains(x
, y
);
951 int wxListItemData::GetX() const
953 wxCHECK_MSG( m_rect
, 0, _T("can't be called in this mode") );
958 int wxListItemData::GetY() const
960 wxCHECK_MSG( m_rect
, 0, _T("can't be called in this mode") );
965 int wxListItemData::GetWidth() const
967 wxCHECK_MSG( m_rect
, 0, _T("can't be called in this mode") );
969 return m_rect
->width
;
972 int wxListItemData::GetHeight() const
974 wxCHECK_MSG( m_rect
, 0, _T("can't be called in this mode") );
976 return m_rect
->height
;
979 void wxListItemData::GetItem( wxListItem
&info
) const
981 long mask
= info
.m_mask
;
983 // by default, get everything for backwards compatibility
986 if ( mask
& wxLIST_MASK_TEXT
)
987 info
.m_text
= m_text
;
988 if ( mask
& wxLIST_MASK_IMAGE
)
989 info
.m_image
= m_image
;
990 if ( mask
& wxLIST_MASK_DATA
)
991 info
.m_data
= m_data
;
995 if ( m_attr
->HasTextColour() )
996 info
.SetTextColour(m_attr
->GetTextColour());
997 if ( m_attr
->HasBackgroundColour() )
998 info
.SetBackgroundColour(m_attr
->GetBackgroundColour());
999 if ( m_attr
->HasFont() )
1000 info
.SetFont(m_attr
->GetFont());
1004 //-----------------------------------------------------------------------------
1006 //-----------------------------------------------------------------------------
1008 void wxListHeaderData::Init()
1020 wxListHeaderData::wxListHeaderData()
1025 wxListHeaderData::wxListHeaderData( const wxListItem
&item
)
1032 void wxListHeaderData::SetItem( const wxListItem
&item
)
1034 m_mask
= item
.m_mask
;
1036 if ( m_mask
& wxLIST_MASK_TEXT
)
1037 m_text
= item
.m_text
;
1039 if ( m_mask
& wxLIST_MASK_IMAGE
)
1040 m_image
= item
.m_image
;
1042 if ( m_mask
& wxLIST_MASK_FORMAT
)
1043 m_format
= item
.m_format
;
1045 if ( m_mask
& wxLIST_MASK_WIDTH
)
1046 SetWidth(item
.m_width
);
1048 if ( m_mask
& wxLIST_MASK_STATE
)
1049 SetState(item
.m_state
);
1052 void wxListHeaderData::SetPosition( int x
, int y
)
1058 void wxListHeaderData::SetHeight( int h
)
1063 void wxListHeaderData::SetWidth( int w
)
1065 m_width
= w
< 0 ? WIDTH_COL_DEFAULT
: w
;
1068 void wxListHeaderData::SetState( int flag
)
1073 void wxListHeaderData::SetFormat( int format
)
1078 bool wxListHeaderData::HasImage() const
1080 return m_image
!= -1;
1083 bool wxListHeaderData::IsHit( int x
, int y
) const
1085 return ((x
>= m_xpos
) && (x
<= m_xpos
+m_width
) && (y
>= m_ypos
) && (y
<= m_ypos
+m_height
));
1088 void wxListHeaderData::GetItem( wxListItem
& item
)
1090 item
.m_mask
= m_mask
;
1091 item
.m_text
= m_text
;
1092 item
.m_image
= m_image
;
1093 item
.m_format
= m_format
;
1094 item
.m_width
= m_width
;
1095 item
.m_state
= m_state
;
1098 int wxListHeaderData::GetImage() const
1103 int wxListHeaderData::GetWidth() const
1108 int wxListHeaderData::GetFormat() const
1113 int wxListHeaderData::GetState() const
1118 //-----------------------------------------------------------------------------
1120 //-----------------------------------------------------------------------------
1122 inline int wxListLineData::GetMode() const
1124 return m_owner
->GetListCtrl()->GetWindowStyleFlag() & wxLC_MASK_TYPE
;
1127 inline bool wxListLineData::InReportView() const
1129 return m_owner
->HasFlag(wxLC_REPORT
);
1132 inline bool wxListLineData::IsVirtual() const
1134 return m_owner
->IsVirtual();
1137 wxListLineData::wxListLineData( wxListMainWindow
*owner
)
1141 if ( InReportView() )
1144 m_gi
= new GeometryInfo
;
1146 m_highlighted
= false;
1148 InitItems( GetMode() == wxLC_REPORT
? m_owner
->GetColumnCount() : 1 );
1151 void wxListLineData::CalculateSize( wxDC
*dc
, int spacing
)
1153 wxListItemDataList::compatibility_iterator node
= m_items
.GetFirst();
1154 wxCHECK_RET( node
, _T("no subitems at all??") );
1156 wxListItemData
*item
= node
->GetData();
1161 switch ( GetMode() )
1164 case wxLC_SMALL_ICON
:
1165 m_gi
->m_rectAll
.width
= spacing
;
1167 s
= item
->GetText();
1172 m_gi
->m_rectLabel
.width
=
1173 m_gi
->m_rectLabel
.height
= 0;
1177 dc
->GetTextExtent( s
, &lw
, &lh
);
1181 m_gi
->m_rectAll
.height
= spacing
+ lh
;
1183 m_gi
->m_rectAll
.width
= lw
;
1185 m_gi
->m_rectLabel
.width
= lw
;
1186 m_gi
->m_rectLabel
.height
= lh
;
1189 if (item
->HasImage())
1192 m_owner
->GetImageSize( item
->GetImage(), w
, h
);
1193 m_gi
->m_rectIcon
.width
= w
+ 8;
1194 m_gi
->m_rectIcon
.height
= h
+ 8;
1196 if ( m_gi
->m_rectIcon
.width
> m_gi
->m_rectAll
.width
)
1197 m_gi
->m_rectAll
.width
= m_gi
->m_rectIcon
.width
;
1198 if ( m_gi
->m_rectIcon
.height
+ lh
> m_gi
->m_rectAll
.height
- 4 )
1199 m_gi
->m_rectAll
.height
= m_gi
->m_rectIcon
.height
+ lh
+ 4;
1202 if ( item
->HasText() )
1204 m_gi
->m_rectHighlight
.width
= m_gi
->m_rectLabel
.width
;
1205 m_gi
->m_rectHighlight
.height
= m_gi
->m_rectLabel
.height
;
1207 else // no text, highlight the icon
1209 m_gi
->m_rectHighlight
.width
= m_gi
->m_rectIcon
.width
;
1210 m_gi
->m_rectHighlight
.height
= m_gi
->m_rectIcon
.height
;
1215 s
= item
->GetTextForMeasuring();
1217 dc
->GetTextExtent( s
, &lw
, &lh
);
1221 m_gi
->m_rectLabel
.width
= lw
;
1222 m_gi
->m_rectLabel
.height
= lh
;
1224 m_gi
->m_rectAll
.width
= lw
;
1225 m_gi
->m_rectAll
.height
= lh
;
1227 if (item
->HasImage())
1230 m_owner
->GetImageSize( item
->GetImage(), w
, h
);
1231 m_gi
->m_rectIcon
.width
= w
;
1232 m_gi
->m_rectIcon
.height
= h
;
1234 m_gi
->m_rectAll
.width
+= 4 + w
;
1235 if (h
> m_gi
->m_rectAll
.height
)
1236 m_gi
->m_rectAll
.height
= h
;
1239 m_gi
->m_rectHighlight
.width
= m_gi
->m_rectAll
.width
;
1240 m_gi
->m_rectHighlight
.height
= m_gi
->m_rectAll
.height
;
1244 wxFAIL_MSG( _T("unexpected call to SetSize") );
1248 wxFAIL_MSG( _T("unknown mode") );
1253 void wxListLineData::SetPosition( int x
, int y
, int spacing
)
1255 wxListItemDataList::compatibility_iterator node
= m_items
.GetFirst();
1256 wxCHECK_RET( node
, _T("no subitems at all??") );
1258 wxListItemData
*item
= node
->GetData();
1260 switch ( GetMode() )
1263 case wxLC_SMALL_ICON
:
1264 m_gi
->m_rectAll
.x
= x
;
1265 m_gi
->m_rectAll
.y
= y
;
1267 if ( item
->HasImage() )
1269 m_gi
->m_rectIcon
.x
= m_gi
->m_rectAll
.x
+ 4 +
1270 (m_gi
->m_rectAll
.width
- m_gi
->m_rectIcon
.width
) / 2;
1271 m_gi
->m_rectIcon
.y
= m_gi
->m_rectAll
.y
+ 4;
1274 if ( item
->HasText() )
1276 if (m_gi
->m_rectAll
.width
> spacing
)
1277 m_gi
->m_rectLabel
.x
= m_gi
->m_rectAll
.x
+ (EXTRA_WIDTH
/2);
1279 m_gi
->m_rectLabel
.x
= m_gi
->m_rectAll
.x
+ (EXTRA_WIDTH
/2) + (spacing
/ 2) - (m_gi
->m_rectLabel
.width
/ 2);
1280 m_gi
->m_rectLabel
.y
= m_gi
->m_rectAll
.y
+ m_gi
->m_rectAll
.height
+ 2 - m_gi
->m_rectLabel
.height
;
1281 m_gi
->m_rectHighlight
.x
= m_gi
->m_rectLabel
.x
- 2;
1282 m_gi
->m_rectHighlight
.y
= m_gi
->m_rectLabel
.y
- 2;
1284 else // no text, highlight the icon
1286 m_gi
->m_rectHighlight
.x
= m_gi
->m_rectIcon
.x
- 4;
1287 m_gi
->m_rectHighlight
.y
= m_gi
->m_rectIcon
.y
- 4;
1292 m_gi
->m_rectAll
.x
= x
;
1293 m_gi
->m_rectAll
.y
= y
;
1295 m_gi
->m_rectHighlight
.x
= m_gi
->m_rectAll
.x
;
1296 m_gi
->m_rectHighlight
.y
= m_gi
->m_rectAll
.y
;
1297 m_gi
->m_rectLabel
.y
= m_gi
->m_rectAll
.y
+ 2;
1299 if (item
->HasImage())
1301 m_gi
->m_rectIcon
.x
= m_gi
->m_rectAll
.x
+ 2;
1302 m_gi
->m_rectIcon
.y
= m_gi
->m_rectAll
.y
+ 2;
1303 m_gi
->m_rectLabel
.x
= m_gi
->m_rectAll
.x
+ 4 + (EXTRA_WIDTH
/2) + m_gi
->m_rectIcon
.width
;
1307 m_gi
->m_rectLabel
.x
= m_gi
->m_rectAll
.x
+ (EXTRA_WIDTH
/2);
1312 wxFAIL_MSG( _T("unexpected call to SetPosition") );
1316 wxFAIL_MSG( _T("unknown mode") );
1321 void wxListLineData::InitItems( int num
)
1323 for (int i
= 0; i
< num
; i
++)
1324 m_items
.Append( new wxListItemData(m_owner
) );
1327 void wxListLineData::SetItem( int index
, const wxListItem
&info
)
1329 wxListItemDataList::compatibility_iterator node
= m_items
.Item( index
);
1330 wxCHECK_RET( node
, _T("invalid column index in SetItem") );
1332 wxListItemData
*item
= node
->GetData();
1333 item
->SetItem( info
);
1336 void wxListLineData::GetItem( int index
, wxListItem
&info
)
1338 wxListItemDataList::compatibility_iterator node
= m_items
.Item( index
);
1341 wxListItemData
*item
= node
->GetData();
1342 item
->GetItem( info
);
1346 wxString
wxListLineData::GetText(int index
) const
1350 wxListItemDataList::compatibility_iterator node
= m_items
.Item( index
);
1353 wxListItemData
*item
= node
->GetData();
1354 s
= item
->GetText();
1360 void wxListLineData::SetText( int index
, const wxString
& s
)
1362 wxListItemDataList::compatibility_iterator node
= m_items
.Item( index
);
1365 wxListItemData
*item
= node
->GetData();
1370 void wxListLineData::SetImage( int index
, int image
)
1372 wxListItemDataList::compatibility_iterator node
= m_items
.Item( index
);
1373 wxCHECK_RET( node
, _T("invalid column index in SetImage()") );
1375 wxListItemData
*item
= node
->GetData();
1376 item
->SetImage(image
);
1379 int wxListLineData::GetImage( int index
) const
1381 wxListItemDataList::compatibility_iterator node
= m_items
.Item( index
);
1382 wxCHECK_MSG( node
, -1, _T("invalid column index in GetImage()") );
1384 wxListItemData
*item
= node
->GetData();
1385 return item
->GetImage();
1388 wxListItemAttr
*wxListLineData::GetAttr() const
1390 wxListItemDataList::compatibility_iterator node
= m_items
.GetFirst();
1391 wxCHECK_MSG( node
, NULL
, _T("invalid column index in GetAttr()") );
1393 wxListItemData
*item
= node
->GetData();
1394 return item
->GetAttr();
1397 void wxListLineData::SetAttr(wxListItemAttr
*attr
)
1399 wxListItemDataList::compatibility_iterator node
= m_items
.GetFirst();
1400 wxCHECK_RET( node
, _T("invalid column index in SetAttr()") );
1402 wxListItemData
*item
= node
->GetData();
1403 item
->SetAttr(attr
);
1406 bool wxListLineData::SetAttributes(wxDC
*dc
,
1407 const wxListItemAttr
*attr
,
1410 wxWindow
*listctrl
= m_owner
->GetParent();
1414 // don't use foreground colour for drawing highlighted items - this might
1415 // make them completely invisible (and there is no way to do bit
1416 // arithmetics on wxColour, unfortunately)
1421 if (m_owner
->HasFocus()
1422 #if defined( __WXMAC__ ) && !defined(__WXUNIVERSAL__) && wxOSX_USE_CARBON
1423 && IsControlActive( (ControlRef
)m_owner
->GetHandle() )
1431 colText
= wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHTTEXT
);
1433 else if ( attr
&& attr
->HasTextColour() )
1434 colText
= attr
->GetTextColour();
1436 colText
= listctrl
->GetForegroundColour();
1438 dc
->SetTextForeground(colText
);
1442 if ( attr
&& attr
->HasFont() )
1443 font
= attr
->GetFont();
1445 font
= listctrl
->GetFont();
1450 bool hasBgCol
= attr
&& attr
->HasBackgroundColour();
1451 if ( highlighted
|| hasBgCol
)
1454 dc
->SetBrush( m_owner
->GetHighlightBrush() );
1456 dc
->SetBrush(*(wxTheBrushList
->FindOrCreateBrush(attr
->GetBackgroundColour(), wxSOLID
)));
1458 dc
->SetPen( *wxTRANSPARENT_PEN
);
1466 void wxListLineData::Draw( wxDC
*dc
)
1468 wxListItemDataList::compatibility_iterator node
= m_items
.GetFirst();
1469 wxCHECK_RET( node
, _T("no subitems at all??") );
1471 bool highlighted
= IsHighlighted();
1473 wxListItemAttr
*attr
= GetAttr();
1475 if ( SetAttributes(dc
, attr
, highlighted
) )
1476 #if ( !defined(__WXGTK20__) && !defined(__WXMAC__) )
1478 dc
->DrawRectangle( m_gi
->m_rectHighlight
);
1484 int flags
= wxCONTROL_SELECTED
;
1485 if (m_owner
->HasFocus()
1486 #if defined( __WXMAC__ ) && !defined(__WXUNIVERSAL__) && wxOSX_USE_CARBON
1487 && IsControlActive( (ControlRef
)m_owner
->GetHandle() )
1490 flags
|= wxCONTROL_FOCUSED
;
1491 wxRendererNative::Get().DrawItemSelectionRect( m_owner
, *dc
, m_gi
->m_rectHighlight
, flags
);
1496 dc
->DrawRectangle( m_gi
->m_rectHighlight
);
1501 // just for debugging to better see where the items are
1503 dc
->SetPen(*wxRED_PEN
);
1504 dc
->SetBrush(*wxTRANSPARENT_BRUSH
);
1505 dc
->DrawRectangle( m_gi
->m_rectAll
);
1506 dc
->SetPen(*wxGREEN_PEN
);
1507 dc
->DrawRectangle( m_gi
->m_rectIcon
);
1510 wxListItemData
*item
= node
->GetData();
1511 if (item
->HasImage())
1513 // centre the image inside our rectangle, this looks nicer when items
1514 // ae aligned in a row
1515 const wxRect
& rectIcon
= m_gi
->m_rectIcon
;
1517 m_owner
->DrawImage(item
->GetImage(), dc
, rectIcon
.x
, rectIcon
.y
);
1520 if (item
->HasText())
1522 const wxRect
& rectLabel
= m_gi
->m_rectLabel
;
1524 wxDCClipper
clipper(*dc
, rectLabel
);
1525 dc
->DrawText(item
->GetText(), rectLabel
.x
, rectLabel
.y
);
1529 void wxListLineData::DrawInReportMode( wxDC
*dc
,
1531 const wxRect
& rectHL
,
1534 // TODO: later we should support setting different attributes for
1535 // different columns - to do it, just add "col" argument to
1536 // GetAttr() and move these lines into the loop below
1537 wxListItemAttr
*attr
= GetAttr();
1538 if ( SetAttributes(dc
, attr
, highlighted
) )
1539 #if ( !defined(__WXGTK20__) && !defined(__WXMAC__) )
1541 dc
->DrawRectangle( rectHL
);
1547 int flags
= wxCONTROL_SELECTED
;
1548 if (m_owner
->HasFocus()
1549 #if defined( __WXMAC__ ) && !defined(__WXUNIVERSAL__) && wxOSX_USE_CARBON
1550 && IsControlActive( (ControlRef
)m_owner
->GetHandle() )
1553 flags
|= wxCONTROL_FOCUSED
;
1554 wxRendererNative::Get().DrawItemSelectionRect( m_owner
, *dc
, rectHL
, flags
);
1558 dc
->DrawRectangle( rectHL
);
1563 wxCoord x
= rect
.x
+ HEADER_OFFSET_X
,
1564 yMid
= rect
.y
+ rect
.height
/2;
1566 // This probably needs to be done
1567 // on all platforms as the icons
1568 // otherwise nearly touch the border
1573 for ( wxListItemDataList::compatibility_iterator node
= m_items
.GetFirst();
1575 node
= node
->GetNext(), col
++ )
1577 wxListItemData
*item
= node
->GetData();
1579 int width
= m_owner
->GetColumnWidth(col
);
1583 if ( item
->HasImage() )
1586 m_owner
->GetImageSize( item
->GetImage(), ix
, iy
);
1587 m_owner
->DrawImage( item
->GetImage(), dc
, xOld
, yMid
- iy
/2 );
1589 ix
+= IMAGE_MARGIN_IN_REPORT_MODE
;
1595 if ( item
->HasText() )
1596 DrawTextFormatted(dc
, item
->GetText(), col
, xOld
, yMid
, width
- 8);
1600 void wxListLineData::DrawTextFormatted(wxDC
*dc
,
1601 const wxString
& textOrig
,
1607 // we don't support displaying multiple lines currently (and neither does
1608 // wxMSW FWIW) so just merge all the lines
1609 wxString
text(textOrig
);
1610 text
.Replace(_T("\n"), _T(" "));
1613 dc
->GetTextExtent(text
, &w
, &h
);
1615 const wxCoord y
= yMid
- (h
+ 1)/2;
1617 wxDCClipper
clipper(*dc
, x
, y
, width
, h
);
1619 // determine if the string can fit inside the current width
1622 // it can, draw it using the items alignment
1624 m_owner
->GetColumn(col
, item
);
1625 switch ( item
.GetAlign() )
1627 case wxLIST_FORMAT_LEFT
:
1631 case wxLIST_FORMAT_RIGHT
:
1635 case wxLIST_FORMAT_CENTER
:
1636 x
+= (width
- w
) / 2;
1640 wxFAIL_MSG( _T("unknown list item format") );
1644 dc
->DrawText(text
, x
, y
);
1646 else // otherwise, truncate and add an ellipsis if possible
1648 // determine the base width
1649 wxString
ellipsis(wxT("..."));
1651 dc
->GetTextExtent(ellipsis
, &base_w
, &h
);
1653 // continue until we have enough space or only one character left
1655 size_t len
= text
.length();
1656 wxString drawntext
= text
.Left(len
);
1659 dc
->GetTextExtent(drawntext
.Last(), &w_c
, &h_c
);
1660 drawntext
.RemoveLast();
1663 if (w
+ base_w
<= width
)
1667 // if still not enough space, remove ellipsis characters
1668 while (ellipsis
.length() > 0 && w
+ base_w
> width
)
1670 ellipsis
= ellipsis
.Left(ellipsis
.length() - 1);
1671 dc
->GetTextExtent(ellipsis
, &base_w
, &h
);
1674 // now draw the text
1675 dc
->DrawText(drawntext
, x
, y
);
1676 dc
->DrawText(ellipsis
, x
+ w
, y
);
1680 bool wxListLineData::Highlight( bool on
)
1682 wxCHECK_MSG( !IsVirtual(), false, _T("unexpected call to Highlight") );
1684 if ( on
== m_highlighted
)
1692 void wxListLineData::ReverseHighlight( void )
1694 Highlight(!IsHighlighted());
1697 //-----------------------------------------------------------------------------
1698 // wxListHeaderWindow
1699 //-----------------------------------------------------------------------------
1701 BEGIN_EVENT_TABLE(wxListHeaderWindow
,wxWindow
)
1702 EVT_PAINT (wxListHeaderWindow::OnPaint
)
1703 EVT_MOUSE_EVENTS (wxListHeaderWindow::OnMouse
)
1704 EVT_SET_FOCUS (wxListHeaderWindow::OnSetFocus
)
1707 void wxListHeaderWindow::Init()
1709 m_currentCursor
= (wxCursor
*) NULL
;
1710 m_isDragging
= false;
1714 wxListHeaderWindow::wxListHeaderWindow()
1718 m_owner
= (wxListMainWindow
*) NULL
;
1719 m_resizeCursor
= (wxCursor
*) NULL
;
1722 wxListHeaderWindow::wxListHeaderWindow( wxWindow
*win
,
1724 wxListMainWindow
*owner
,
1728 const wxString
&name
)
1729 : wxWindow( win
, id
, pos
, size
, style
, name
)
1734 m_resizeCursor
= new wxCursor( wxCURSOR_SIZEWE
);
1737 wxVisualAttributes attr
= wxPanel::GetClassDefaultAttributes();
1738 SetOwnForegroundColour( attr
.colFg
);
1739 SetOwnBackgroundColour( attr
.colBg
);
1741 SetOwnFont( attr
.font
);
1743 SetOwnForegroundColour( wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT
));
1744 SetOwnBackgroundColour( wxSystemSettings::GetColour(wxSYS_COLOUR_BTNFACE
));
1746 SetOwnFont( wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT
));
1750 wxListHeaderWindow::~wxListHeaderWindow()
1752 delete m_resizeCursor
;
1755 #ifdef __WXUNIVERSAL__
1756 #include <wx/univ/renderer.h>
1757 #include <wx/univ/theme.h>
1760 // shift the DC origin to match the position of the main window horz
1761 // scrollbar: this allows us to always use logical coords
1762 void wxListHeaderWindow::AdjustDC(wxDC
& dc
)
1765 m_owner
->GetScrollPixelsPerUnit( &xpix
, NULL
);
1768 m_owner
->GetViewStart( &view_start
, NULL
);
1773 dc
.GetDeviceOrigin( &org_x
, &org_y
);
1775 // account for the horz scrollbar offset
1777 if (GetLayoutDirection() == wxLayout_RightToLeft
)
1779 // Maybe we just have to check for m_signX
1780 // in the DC, but I leave the #ifdef __WXGTK__
1782 dc
.SetDeviceOrigin( org_x
+ (view_start
* xpix
), org_y
);
1786 dc
.SetDeviceOrigin( org_x
- (view_start
* xpix
), org_y
);
1789 void wxListHeaderWindow::OnPaint( wxPaintEvent
&WXUNUSED(event
) )
1791 wxPaintDC
dc( this );
1796 dc
.SetFont( GetFont() );
1798 // width and height of the entire header window
1800 GetClientSize( &w
, &h
);
1801 m_owner
->CalcUnscrolledPosition(w
, 0, &w
, NULL
);
1803 dc
.SetBackgroundMode(wxTRANSPARENT
);
1804 dc
.SetTextForeground(GetForegroundColour());
1806 int x
= HEADER_OFFSET_X
;
1807 int numColumns
= m_owner
->GetColumnCount();
1809 for ( int i
= 0; i
< numColumns
&& x
< w
; i
++ )
1811 m_owner
->GetColumn( i
, item
);
1812 int wCol
= item
.m_width
;
1818 if (!m_parent
->IsEnabled())
1819 flags
|= wxCONTROL_DISABLED
;
1821 // NB: The code below is not really Mac-specific, but since we are close
1822 // to 2.8 release and I don't have time to test on other platforms, I
1823 // defined this only for wxMac. If this behavior is desired on
1824 // other platforms, please go ahead and revise or remove the #ifdef.
1826 if ( !m_owner
->IsVirtual() && (item
.m_mask
& wxLIST_MASK_STATE
) &&
1827 (item
.m_state
& wxLIST_STATE_SELECTED
) )
1828 flags
|= wxCONTROL_SELECTED
;
1831 wxRendererNative::Get().DrawHeaderButton
1835 wxRect(x
, HEADER_OFFSET_Y
, cw
, ch
),
1839 // see if we have enough space for the column label
1841 // for this we need the width of the text
1844 dc
.GetTextExtent(item
.GetText(), &wLabel
, &hLabel
);
1845 wLabel
+= 2 * EXTRA_WIDTH
;
1847 // and the width of the icon, if any
1848 int ix
= 0, iy
= 0; // init them just to suppress the compiler warnings
1849 const int image
= item
.m_image
;
1850 wxImageList
*imageList
;
1853 imageList
= m_owner
->m_small_image_list
;
1856 imageList
->GetSize(image
, ix
, iy
);
1857 wLabel
+= ix
+ HEADER_IMAGE_MARGIN_IN_REPORT_MODE
;
1865 // ignore alignment if there is not enough space anyhow
1867 switch ( wLabel
< cw
? item
.GetAlign() : wxLIST_FORMAT_LEFT
)
1870 wxFAIL_MSG( _T("unknown list item format") );
1873 case wxLIST_FORMAT_LEFT
:
1877 case wxLIST_FORMAT_RIGHT
:
1878 xAligned
= x
+ cw
- wLabel
;
1881 case wxLIST_FORMAT_CENTER
:
1882 xAligned
= x
+ (cw
- wLabel
) / 2;
1886 // draw the text and image clipping them so that they
1887 // don't overwrite the column boundary
1888 wxDCClipper
clipper(dc
, x
, HEADER_OFFSET_Y
, cw
, h
);
1890 // if we have an image, draw it on the right of the label
1897 xAligned
+ wLabel
- ix
- HEADER_IMAGE_MARGIN_IN_REPORT_MODE
,
1898 HEADER_OFFSET_Y
+ (h
- 4 - iy
)/2,
1899 wxIMAGELIST_DRAW_TRANSPARENT
1903 dc
.DrawText( item
.GetText(),
1904 xAligned
+ EXTRA_WIDTH
, h
/ 2 - hLabel
/ 2 ); //HEADER_OFFSET_Y + EXTRA_HEIGHT );
1909 // Fill in what's missing to the right of the columns, otherwise we will
1910 // leave an unpainted area when columns are removed (and it looks better)
1913 wxRendererNative::Get().DrawHeaderButton
1917 wxRect(x
, HEADER_OFFSET_Y
, w
- x
, h
),
1923 void wxListHeaderWindow::DrawCurrent()
1926 m_owner
->SetColumnWidth( m_column
, m_currentX
- m_minX
);
1928 int x1
= m_currentX
;
1930 m_owner
->ClientToScreen( &x1
, &y1
);
1932 int x2
= m_currentX
;
1934 m_owner
->GetClientSize( NULL
, &y2
);
1935 m_owner
->ClientToScreen( &x2
, &y2
);
1938 dc
.SetLogicalFunction( wxINVERT
);
1939 dc
.SetPen( *(wxThePenList
->FindOrCreatePen(*wxBLACK
, 2, wxSOLID
) ));
1940 dc
.SetBrush( *wxTRANSPARENT_BRUSH
);
1944 dc
.DrawLine( x1
, y1
, x2
, y2
);
1946 dc
.SetLogicalFunction( wxCOPY
);
1948 dc
.SetPen( wxNullPen
);
1949 dc
.SetBrush( wxNullBrush
);
1953 void wxListHeaderWindow::OnMouse( wxMouseEvent
&event
)
1955 // we want to work with logical coords
1957 m_owner
->CalcUnscrolledPosition(event
.GetX(), 0, &x
, NULL
);
1958 int y
= event
.GetY();
1962 SendListEvent(wxEVT_COMMAND_LIST_COL_DRAGGING
, event
.GetPosition());
1964 // we don't draw the line beyond our window, but we allow dragging it
1967 GetClientSize( &w
, NULL
);
1968 m_owner
->CalcUnscrolledPosition(w
, 0, &w
, NULL
);
1971 // erase the line if it was drawn
1972 if ( m_currentX
< w
)
1975 if (event
.ButtonUp())
1978 m_isDragging
= false;
1980 m_owner
->SetColumnWidth( m_column
, m_currentX
- m_minX
);
1981 SendListEvent(wxEVT_COMMAND_LIST_COL_END_DRAG
, event
.GetPosition());
1988 m_currentX
= m_minX
+ 7;
1990 // draw in the new location
1991 if ( m_currentX
< w
)
1995 else // not dragging
1998 bool hit_border
= false;
2000 // end of the current column
2003 // find the column where this event occurred
2005 countCol
= m_owner
->GetColumnCount();
2006 for (col
= 0; col
< countCol
; col
++)
2008 xpos
+= m_owner
->GetColumnWidth( col
);
2011 if ( (abs(x
-xpos
) < 3) && (y
< 22) )
2013 // near the column border
2020 // inside the column
2027 if ( col
== countCol
)
2030 if (event
.LeftDown() || event
.RightUp())
2032 if (hit_border
&& event
.LeftDown())
2034 if ( SendListEvent(wxEVT_COMMAND_LIST_COL_BEGIN_DRAG
,
2035 event
.GetPosition()) )
2037 m_isDragging
= true;
2042 //else: column resizing was vetoed by the user code
2044 else // click on a column
2046 // record the selected state of the columns
2047 if (event
.LeftDown())
2049 for (int i
=0; i
< m_owner
->GetColumnCount(); i
++)
2052 m_owner
->GetColumn(i
, colItem
);
2053 long state
= colItem
.GetState();
2055 colItem
.SetState(state
| wxLIST_STATE_SELECTED
);
2057 colItem
.SetState(state
& ~wxLIST_STATE_SELECTED
);
2058 m_owner
->SetColumn(i
, colItem
);
2062 SendListEvent( event
.LeftDown()
2063 ? wxEVT_COMMAND_LIST_COL_CLICK
2064 : wxEVT_COMMAND_LIST_COL_RIGHT_CLICK
,
2065 event
.GetPosition());
2068 else if (event
.Moving())
2073 setCursor
= m_currentCursor
== wxSTANDARD_CURSOR
;
2074 m_currentCursor
= m_resizeCursor
;
2078 setCursor
= m_currentCursor
!= wxSTANDARD_CURSOR
;
2079 m_currentCursor
= wxSTANDARD_CURSOR
;
2083 SetCursor(*m_currentCursor
);
2088 void wxListHeaderWindow::OnSetFocus( wxFocusEvent
&WXUNUSED(event
) )
2090 m_owner
->SetFocus();
2094 bool wxListHeaderWindow::SendListEvent(wxEventType type
, const wxPoint
& pos
)
2096 wxWindow
*parent
= GetParent();
2097 wxListEvent
le( type
, parent
->GetId() );
2098 le
.SetEventObject( parent
);
2099 le
.m_pointDrag
= pos
;
2101 // the position should be relative to the parent window, not
2102 // this one for compatibility with MSW and common sense: the
2103 // user code doesn't know anything at all about this header
2104 // window, so why should it get positions relative to it?
2105 le
.m_pointDrag
.y
-= GetSize().y
;
2107 le
.m_col
= m_column
;
2108 return !parent
->GetEventHandler()->ProcessEvent( le
) || le
.IsAllowed();
2111 //-----------------------------------------------------------------------------
2112 // wxListRenameTimer (internal)
2113 //-----------------------------------------------------------------------------
2115 wxListRenameTimer::wxListRenameTimer( wxListMainWindow
*owner
)
2120 void wxListRenameTimer::Notify()
2122 m_owner
->OnRenameTimer();
2125 //-----------------------------------------------------------------------------
2126 // wxListTextCtrlWrapper (internal)
2127 //-----------------------------------------------------------------------------
2129 BEGIN_EVENT_TABLE(wxListTextCtrlWrapper
, wxEvtHandler
)
2130 EVT_CHAR (wxListTextCtrlWrapper::OnChar
)
2131 EVT_KEY_UP (wxListTextCtrlWrapper::OnKeyUp
)
2132 EVT_KILL_FOCUS (wxListTextCtrlWrapper::OnKillFocus
)
2135 wxListTextCtrlWrapper::wxListTextCtrlWrapper(wxListMainWindow
*owner
,
2138 : m_startValue(owner
->GetItemText(itemEdit
)),
2139 m_itemEdited(itemEdit
)
2144 m_aboutToFinish
= false;
2146 wxRect rectLabel
= owner
->GetLineLabelRect(itemEdit
);
2148 m_owner
->CalcScrolledPosition(rectLabel
.x
, rectLabel
.y
,
2149 &rectLabel
.x
, &rectLabel
.y
);
2151 m_text
->Create(owner
, wxID_ANY
, m_startValue
,
2152 wxPoint(rectLabel
.x
-4,rectLabel
.y
-4),
2153 wxSize(rectLabel
.width
+11,rectLabel
.height
+8));
2156 m_text
->PushEventHandler(this);
2159 void wxListTextCtrlWrapper::Finish()
2165 m_text
->RemoveEventHandler(this);
2166 m_owner
->FinishEditing(m_text
);
2168 wxPendingDelete
.Append( this );
2172 bool wxListTextCtrlWrapper::AcceptChanges()
2174 const wxString value
= m_text
->GetValue();
2176 // notice that we should always call OnRenameAccept() to generate the "end
2177 // label editing" event, even if the user hasn't really changed anything
2178 if ( !m_owner
->OnRenameAccept(m_itemEdited
, value
) )
2180 // vetoed by the user
2184 // accepted, do rename the item (unless nothing changed)
2185 if ( value
!= m_startValue
)
2186 m_owner
->SetItemText(m_itemEdited
, value
);
2191 void wxListTextCtrlWrapper::AcceptChangesAndFinish()
2193 m_aboutToFinish
= true;
2195 // Notify the owner about the changes
2198 // Even if vetoed, close the control (consistent with MSW)
2202 void wxListTextCtrlWrapper::OnChar( wxKeyEvent
&event
)
2204 switch ( event
.m_keyCode
)
2207 AcceptChangesAndFinish();
2211 m_owner
->OnRenameCancelled( m_itemEdited
);
2220 void wxListTextCtrlWrapper::OnKeyUp( wxKeyEvent
&event
)
2228 // auto-grow the textctrl:
2229 wxSize parentSize
= m_owner
->GetSize();
2230 wxPoint myPos
= m_text
->GetPosition();
2231 wxSize mySize
= m_text
->GetSize();
2233 m_text
->GetTextExtent(m_text
->GetValue() + _T("MM"), &sx
, &sy
);
2234 if (myPos
.x
+ sx
> parentSize
.x
)
2235 sx
= parentSize
.x
- myPos
.x
;
2238 m_text
->SetSize(sx
, wxDefaultCoord
);
2243 void wxListTextCtrlWrapper::OnKillFocus( wxFocusEvent
&event
)
2245 if ( !m_finished
&& !m_aboutToFinish
)
2247 if ( !AcceptChanges() )
2248 m_owner
->OnRenameCancelled( m_itemEdited
);
2253 // We must let the native text control handle focus
2257 //-----------------------------------------------------------------------------
2259 //-----------------------------------------------------------------------------
2261 BEGIN_EVENT_TABLE(wxListMainWindow
,wxScrolledWindow
)
2262 EVT_PAINT (wxListMainWindow::OnPaint
)
2263 EVT_ERASE_BACKGROUND (wxListMainWindow::OnErase
)
2264 EVT_MOUSE_EVENTS (wxListMainWindow::OnMouse
)
2265 EVT_CHAR (wxListMainWindow::OnChar
)
2266 EVT_KEY_DOWN (wxListMainWindow::OnKeyDown
)
2267 EVT_KEY_UP (wxListMainWindow::OnKeyUp
)
2268 EVT_SET_FOCUS (wxListMainWindow::OnSetFocus
)
2269 EVT_KILL_FOCUS (wxListMainWindow::OnKillFocus
)
2270 EVT_SCROLLWIN (wxListMainWindow::OnScroll
)
2271 EVT_CHILD_FOCUS (wxListMainWindow::OnChildFocus
)
2274 void wxListMainWindow::Init()
2279 m_lineTo
= (size_t)-1;
2285 m_small_image_list
= (wxImageList
*) NULL
;
2286 m_normal_image_list
= (wxImageList
*) NULL
;
2288 m_small_spacing
= 30;
2289 m_normal_spacing
= 40;
2293 m_isCreated
= false;
2295 m_lastOnSame
= false;
2296 m_renameTimer
= new wxListRenameTimer( this );
2297 m_textctrlWrapper
= NULL
;
2301 m_lineSelectSingleOnUp
=
2302 m_lineBeforeLastClicked
= (size_t)-1;
2307 wxListMainWindow::wxListMainWindow()
2312 wxListMainWindow::wxListMainWindow( wxWindow
*parent
,
2317 const wxString
&name
)
2318 : wxScrolledWindow( parent
, id
, pos
, size
,
2319 style
| wxHSCROLL
| wxVSCROLL
, name
)
2323 m_highlightBrush
= *(wxTheBrushList
->FindOrCreateBrush(
2324 wxSystemSettings::GetColour
2326 wxSYS_COLOUR_HIGHLIGHT
2331 m_highlightUnfocusedBrush
= *(wxTheBrushList
->FindOrCreateBrush(
2332 wxSystemSettings::GetColour
2334 wxSYS_COLOUR_BTNSHADOW
2339 SetScrollbars( 0, 0, 0, 0, 0, 0 );
2341 wxVisualAttributes attr
= wxGenericListCtrl::GetClassDefaultAttributes();
2342 SetOwnForegroundColour( attr
.colFg
);
2343 SetOwnBackgroundColour( attr
.colBg
);
2345 SetOwnFont( attr
.font
);
2348 wxListMainWindow::~wxListMainWindow()
2351 WX_CLEAR_LIST(wxListHeaderDataList
, m_columns
);
2352 WX_CLEAR_ARRAY(m_aColWidths
);
2354 delete m_renameTimer
;
2357 void wxListMainWindow::CacheLineData(size_t line
)
2359 wxGenericListCtrl
*listctrl
= GetListCtrl();
2361 wxListLineData
*ld
= GetDummyLine();
2363 size_t countCol
= GetColumnCount();
2364 for ( size_t col
= 0; col
< countCol
; col
++ )
2366 ld
->SetText(col
, listctrl
->OnGetItemText(line
, col
));
2367 ld
->SetImage(col
, listctrl
->OnGetItemColumnImage(line
, col
));
2370 ld
->SetAttr(listctrl
->OnGetItemAttr(line
));
2373 wxListLineData
*wxListMainWindow::GetDummyLine() const
2375 wxASSERT_MSG( !IsEmpty(), _T("invalid line index") );
2376 wxASSERT_MSG( IsVirtual(), _T("GetDummyLine() shouldn't be called") );
2378 wxListMainWindow
*self
= wxConstCast(this, wxListMainWindow
);
2380 // we need to recreate the dummy line if the number of columns in the
2381 // control changed as it would have the incorrect number of fields
2383 if ( !m_lines
.IsEmpty() &&
2384 m_lines
[0].m_items
.GetCount() != (size_t)GetColumnCount() )
2386 self
->m_lines
.Clear();
2389 if ( m_lines
.IsEmpty() )
2391 wxListLineData
*line
= new wxListLineData(self
);
2392 self
->m_lines
.Add(line
);
2394 // don't waste extra memory -- there never going to be anything
2395 // else/more in this array
2396 self
->m_lines
.Shrink();
2402 // ----------------------------------------------------------------------------
2403 // line geometry (report mode only)
2404 // ----------------------------------------------------------------------------
2406 wxCoord
wxListMainWindow::GetLineHeight() const
2408 // we cache the line height as calling GetTextExtent() is slow
2409 if ( !m_lineHeight
)
2411 wxListMainWindow
*self
= wxConstCast(this, wxListMainWindow
);
2413 wxClientDC
dc( self
);
2414 dc
.SetFont( GetFont() );
2417 dc
.GetTextExtent(_T("H"), NULL
, &y
);
2419 if ( m_small_image_list
&& m_small_image_list
->GetImageCount() )
2422 m_small_image_list
->GetSize(0, iw
, ih
);
2427 self
->m_lineHeight
= y
+ LINE_SPACING
;
2430 return m_lineHeight
;
2433 wxCoord
wxListMainWindow::GetLineY(size_t line
) const
2435 wxASSERT_MSG( InReportView(), _T("only works in report mode") );
2437 return LINE_SPACING
+ line
* GetLineHeight();
2440 wxRect
wxListMainWindow::GetLineRect(size_t line
) const
2442 if ( !InReportView() )
2443 return GetLine(line
)->m_gi
->m_rectAll
;
2446 rect
.x
= HEADER_OFFSET_X
;
2447 rect
.y
= GetLineY(line
);
2448 rect
.width
= GetHeaderWidth();
2449 rect
.height
= GetLineHeight();
2454 wxRect
wxListMainWindow::GetLineLabelRect(size_t line
) const
2456 if ( !InReportView() )
2457 return GetLine(line
)->m_gi
->m_rectLabel
;
2460 wxListLineData
*data
= GetLine(line
);
2461 wxListItemDataList::compatibility_iterator node
= data
->m_items
.GetFirst();
2464 wxListItemData
*item
= node
->GetData();
2465 if ( item
->HasImage() )
2468 GetImageSize( item
->GetImage(), ix
, iy
);
2469 image_x
= 3 + ix
+ IMAGE_MARGIN_IN_REPORT_MODE
;
2474 rect
.x
= image_x
+ HEADER_OFFSET_X
;
2475 rect
.y
= GetLineY(line
);
2476 rect
.width
= GetColumnWidth(0) - image_x
;
2477 rect
.height
= GetLineHeight();
2482 wxRect
wxListMainWindow::GetLineIconRect(size_t line
) const
2484 if ( !InReportView() )
2485 return GetLine(line
)->m_gi
->m_rectIcon
;
2487 wxListLineData
*ld
= GetLine(line
);
2488 wxASSERT_MSG( ld
->HasImage(), _T("should have an image") );
2491 rect
.x
= HEADER_OFFSET_X
;
2492 rect
.y
= GetLineY(line
);
2493 GetImageSize(ld
->GetImage(), rect
.width
, rect
.height
);
2498 wxRect
wxListMainWindow::GetLineHighlightRect(size_t line
) const
2500 return InReportView() ? GetLineRect(line
)
2501 : GetLine(line
)->m_gi
->m_rectHighlight
;
2504 long wxListMainWindow::HitTestLine(size_t line
, int x
, int y
) const
2506 wxASSERT_MSG( line
< GetItemCount(), _T("invalid line in HitTestLine") );
2508 wxListLineData
*ld
= GetLine(line
);
2510 if ( ld
->HasImage() && GetLineIconRect(line
).Contains(x
, y
) )
2511 return wxLIST_HITTEST_ONITEMICON
;
2513 // VS: Testing for "ld->HasText() || InReportView()" instead of
2514 // "ld->HasText()" is needed to make empty lines in report view
2516 if ( ld
->HasText() || InReportView() )
2518 wxRect rect
= InReportView() ? GetLineRect(line
)
2519 : GetLineLabelRect(line
);
2521 if ( rect
.Contains(x
, y
) )
2522 return wxLIST_HITTEST_ONITEMLABEL
;
2528 // ----------------------------------------------------------------------------
2529 // highlight (selection) handling
2530 // ----------------------------------------------------------------------------
2532 bool wxListMainWindow::IsHighlighted(size_t line
) const
2536 return m_selStore
.IsSelected(line
);
2540 wxListLineData
*ld
= GetLine(line
);
2541 wxCHECK_MSG( ld
, false, _T("invalid index in IsHighlighted") );
2543 return ld
->IsHighlighted();
2547 void wxListMainWindow::HighlightLines( size_t lineFrom
,
2553 wxArrayInt linesChanged
;
2554 if ( !m_selStore
.SelectRange(lineFrom
, lineTo
, highlight
,
2557 // meny items changed state, refresh everything
2558 RefreshLines(lineFrom
, lineTo
);
2560 else // only a few items changed state, refresh only them
2562 size_t count
= linesChanged
.GetCount();
2563 for ( size_t n
= 0; n
< count
; n
++ )
2565 RefreshLine(linesChanged
[n
]);
2569 else // iterate over all items in non report view
2571 for ( size_t line
= lineFrom
; line
<= lineTo
; line
++ )
2573 if ( HighlightLine(line
, highlight
) )
2579 bool wxListMainWindow::HighlightLine( size_t line
, bool highlight
)
2585 changed
= m_selStore
.SelectItem(line
, highlight
);
2589 wxListLineData
*ld
= GetLine(line
);
2590 wxCHECK_MSG( ld
, false, _T("invalid index in HighlightLine") );
2592 changed
= ld
->Highlight(highlight
);
2597 SendNotify( line
, highlight
? wxEVT_COMMAND_LIST_ITEM_SELECTED
2598 : wxEVT_COMMAND_LIST_ITEM_DESELECTED
);
2604 void wxListMainWindow::RefreshLine( size_t line
)
2606 if ( InReportView() )
2608 size_t visibleFrom
, visibleTo
;
2609 GetVisibleLinesRange(&visibleFrom
, &visibleTo
);
2611 if ( line
< visibleFrom
|| line
> visibleTo
)
2615 wxRect rect
= GetLineRect(line
);
2617 CalcScrolledPosition( rect
.x
, rect
.y
, &rect
.x
, &rect
.y
);
2618 RefreshRect( rect
);
2621 void wxListMainWindow::RefreshLines( size_t lineFrom
, size_t lineTo
)
2623 // we suppose that they are ordered by caller
2624 wxASSERT_MSG( lineFrom
<= lineTo
, _T("indices in disorder") );
2626 wxASSERT_MSG( lineTo
< GetItemCount(), _T("invalid line range") );
2628 if ( InReportView() )
2630 size_t visibleFrom
, visibleTo
;
2631 GetVisibleLinesRange(&visibleFrom
, &visibleTo
);
2633 if ( lineFrom
< visibleFrom
)
2634 lineFrom
= visibleFrom
;
2635 if ( lineTo
> visibleTo
)
2640 rect
.y
= GetLineY(lineFrom
);
2641 rect
.width
= GetClientSize().x
;
2642 rect
.height
= GetLineY(lineTo
) - rect
.y
+ GetLineHeight();
2644 CalcScrolledPosition( rect
.x
, rect
.y
, &rect
.x
, &rect
.y
);
2645 RefreshRect( rect
);
2649 // TODO: this should be optimized...
2650 for ( size_t line
= lineFrom
; line
<= lineTo
; line
++ )
2657 void wxListMainWindow::RefreshAfter( size_t lineFrom
)
2659 if ( InReportView() )
2661 size_t visibleFrom
, visibleTo
;
2662 GetVisibleLinesRange(&visibleFrom
, &visibleTo
);
2664 if ( lineFrom
< visibleFrom
)
2665 lineFrom
= visibleFrom
;
2666 else if ( lineFrom
> visibleTo
)
2671 rect
.y
= GetLineY(lineFrom
);
2672 CalcScrolledPosition( rect
.x
, rect
.y
, &rect
.x
, &rect
.y
);
2674 wxSize size
= GetClientSize();
2675 rect
.width
= size
.x
;
2677 // refresh till the bottom of the window
2678 rect
.height
= size
.y
- rect
.y
;
2680 RefreshRect( rect
);
2684 // TODO: how to do it more efficiently?
2689 void wxListMainWindow::RefreshSelected()
2695 if ( InReportView() )
2697 GetVisibleLinesRange(&from
, &to
);
2702 to
= GetItemCount() - 1;
2705 if ( HasCurrent() && m_current
>= from
&& m_current
<= to
)
2706 RefreshLine(m_current
);
2708 for ( size_t line
= from
; line
<= to
; line
++ )
2710 // NB: the test works as expected even if m_current == -1
2711 if ( line
!= m_current
&& IsHighlighted(line
) )
2716 void wxListMainWindow::Freeze()
2721 void wxListMainWindow::Thaw()
2723 wxCHECK_RET( m_freezeCount
> 0, _T("thawing unfrozen list control?") );
2725 if ( --m_freezeCount
== 0 )
2729 void wxListMainWindow::OnPaint( wxPaintEvent
&WXUNUSED(event
) )
2731 // Note: a wxPaintDC must be constructed even if no drawing is
2732 // done (a Windows requirement).
2733 wxBufferedPaintDC
dc( this );
2735 // Ensure an uniform background color, as to avoid differences between
2736 // the automatically cleared parts and the rest of the canvas.
2737 dc
.SetBackground(*(wxTheBrushList
->FindOrCreateBrush(wxSystemSettings::GetColour(wxSYS_COLOUR_LISTBOX
), wxSOLID
)));
2739 // We need to clear the DC manually, since we intercept BG-erase events.
2740 // Clearing must be done first thing because caching of the double-buffering causes artifacts otherwise.
2743 if ( m_freezeCount
)
2747 // delay the repainting until we calculate all the items positions
2752 // IsEmpty is checked now, after clearing, to avoid garbage on empty lists.
2758 CalcScrolledPosition( 0, 0, &dev_x
, &dev_y
);
2760 dc
.SetFont( GetFont() );
2762 if ( InReportView() )
2764 int lineHeight
= GetLineHeight();
2766 size_t visibleFrom
, visibleTo
;
2767 GetVisibleLinesRange(&visibleFrom
, &visibleTo
);
2770 int xOrig
= dc
.LogicalToDeviceX( 0 );
2771 int yOrig
= dc
.LogicalToDeviceY( 0 );
2773 // tell the caller cache to cache the data
2776 wxListEvent
evCache(wxEVT_COMMAND_LIST_CACHE_HINT
,
2777 GetParent()->GetId());
2778 evCache
.SetEventObject( GetParent() );
2779 evCache
.m_oldItemIndex
= visibleFrom
;
2780 evCache
.m_itemIndex
= visibleTo
;
2781 GetParent()->GetEventHandler()->ProcessEvent( evCache
);
2784 for ( size_t line
= visibleFrom
; line
<= visibleTo
; line
++ )
2786 rectLine
= GetLineRect(line
);
2789 if ( !IsExposed(rectLine
.x
+ xOrig
, rectLine
.y
+ yOrig
,
2790 rectLine
.width
, rectLine
.height
) )
2792 // don't redraw unaffected lines to avoid flicker
2796 if (HasFlag(wxLC_OWNERDRAW
)) {
2797 ((wxGenericListCtrl
*)m_parent
)->OnDrawItem(line
, &dc
, rectLine
, GetLineHighlightRect(line
), IsHighlighted(line
));
2799 GetLine(line
)->DrawInReportMode( &dc
,
2801 GetLineHighlightRect(line
),
2802 IsHighlighted(line
) );
2806 if ( HasFlag(wxLC_HRULES
) )
2808 wxPen pen
= *(wxThePenList
->FindOrCreatePen(GetRuleColour(), 1, wxSOLID
));
2809 wxSize clientSize
= GetClientSize();
2811 size_t i
= visibleFrom
;
2812 if (i
== 0) i
= 1; // Don't draw the first one
2813 for ( ; i
<= visibleTo
; i
++ )
2816 dc
.SetBrush( *wxTRANSPARENT_BRUSH
);
2817 dc
.DrawLine(0 - dev_x
, i
* lineHeight
,
2818 clientSize
.x
- dev_x
, i
* lineHeight
);
2821 // Draw last horizontal rule
2822 if ( visibleTo
== GetItemCount() - 1 )
2825 dc
.SetBrush( *wxTRANSPARENT_BRUSH
);
2826 dc
.DrawLine(0 - dev_x
, (m_lineTo
+ 1) * lineHeight
,
2827 clientSize
.x
- dev_x
, (m_lineTo
+ 1) * lineHeight
);
2831 // Draw vertical rules if required
2832 if ( HasFlag(wxLC_VRULES
) && !IsEmpty() )
2834 wxPen pen
= *(wxThePenList
->FindOrCreatePen(GetRuleColour(), 1, wxSOLID
));
2835 wxRect firstItemRect
, lastItemRect
;
2837 GetItemRect(visibleFrom
, firstItemRect
);
2838 GetItemRect(visibleTo
, lastItemRect
);
2839 int x
= firstItemRect
.GetX();
2841 dc
.SetBrush(* wxTRANSPARENT_BRUSH
);
2843 for (int col
= 0; col
< GetColumnCount(); col
++)
2845 int colWidth
= GetColumnWidth(col
);
2847 int x_pos
= x
- dev_x
;
2848 if (col
< GetColumnCount()-1) x_pos
-= 2;
2849 dc
.DrawLine(x_pos
, firstItemRect
.GetY() - 1 - dev_y
,
2850 x_pos
, lastItemRect
.GetBottom() + 1 - dev_y
);
2856 size_t count
= GetItemCount();
2857 for ( size_t i
= 0; i
< count
; i
++ )
2859 GetLine(i
)->Draw( &dc
);
2864 // Don't draw rect outline under Mac at all.
2869 wxRect
rect( GetLineHighlightRect( m_current
) );
2871 dc
.SetPen( *wxBLACK_PEN
);
2872 dc
.SetBrush( *wxTRANSPARENT_BRUSH
);
2873 dc
.DrawRectangle( rect
);
2875 wxRendererNative::Get().DrawItemSelectionRect( this, dc
, rect
, wxCONTROL_CURRENT
|wxCONTROL_FOCUSED
);
2883 void wxListMainWindow::HighlightAll( bool on
)
2885 if ( IsSingleSel() )
2887 wxASSERT_MSG( !on
, _T("can't do this in a single selection control") );
2889 // we just have one item to turn off
2890 if ( HasCurrent() && IsHighlighted(m_current
) )
2892 HighlightLine(m_current
, false);
2893 RefreshLine(m_current
);
2896 else // multi selection
2899 HighlightLines(0, GetItemCount() - 1, on
);
2903 void wxListMainWindow::OnChildFocus(wxChildFocusEvent
& WXUNUSED(event
))
2905 // Do nothing here. This prevents the default handler in wxScrolledWindow
2906 // from needlessly scrolling the window when the edit control is
2907 // dismissed. See ticket #9563.
2910 void wxListMainWindow::SendNotify( size_t line
,
2911 wxEventType command
,
2912 const wxPoint
& point
)
2914 wxListEvent
le( command
, GetParent()->GetId() );
2915 le
.SetEventObject( GetParent() );
2917 le
.m_itemIndex
= line
;
2919 // set only for events which have position
2920 if ( point
!= wxDefaultPosition
)
2921 le
.m_pointDrag
= point
;
2923 // don't try to get the line info for virtual list controls: the main
2924 // program has it anyhow and if we did it would result in accessing all
2925 // the lines, even those which are not visible now and this is precisely
2926 // what we're trying to avoid
2929 if ( line
!= (size_t)-1 )
2931 GetLine(line
)->GetItem( 0, le
.m_item
);
2933 //else: this happens for wxEVT_COMMAND_LIST_ITEM_FOCUSED event
2935 //else: there may be no more such item
2937 GetParent()->GetEventHandler()->ProcessEvent( le
);
2940 void wxListMainWindow::ChangeCurrent(size_t current
)
2942 m_current
= current
;
2944 // as the current item changed, we shouldn't start editing it when the
2945 // "slow click" timer expires as the click happened on another item
2946 if ( m_renameTimer
->IsRunning() )
2947 m_renameTimer
->Stop();
2949 SendNotify(current
, wxEVT_COMMAND_LIST_ITEM_FOCUSED
);
2952 wxTextCtrl
*wxListMainWindow::EditLabel(long item
, wxClassInfo
* textControlClass
)
2954 wxCHECK_MSG( (item
>= 0) && ((size_t)item
< GetItemCount()), NULL
,
2955 wxT("wrong index in wxGenericListCtrl::EditLabel()") );
2957 wxASSERT_MSG( textControlClass
->IsKindOf(CLASSINFO(wxTextCtrl
)),
2958 wxT("EditLabel() needs a text control") );
2960 size_t itemEdit
= (size_t)item
;
2962 wxListEvent
le( wxEVT_COMMAND_LIST_BEGIN_LABEL_EDIT
, GetParent()->GetId() );
2963 le
.SetEventObject( GetParent() );
2964 le
.m_itemIndex
= item
;
2965 wxListLineData
*data
= GetLine(itemEdit
);
2966 wxCHECK_MSG( data
, NULL
, _T("invalid index in EditLabel()") );
2967 data
->GetItem( 0, le
.m_item
);
2969 if ( GetParent()->GetEventHandler()->ProcessEvent( le
) && !le
.IsAllowed() )
2971 // vetoed by user code
2975 // We have to call this here because the label in question might just have
2976 // been added and no screen update taken place.
2981 // Pending events dispatched by wxSafeYield might have changed the item
2983 if ( (size_t)item
>= GetItemCount() )
2987 wxTextCtrl
* const text
= (wxTextCtrl
*)textControlClass
->CreateObject();
2988 m_textctrlWrapper
= new wxListTextCtrlWrapper(this, text
, item
);
2989 return m_textctrlWrapper
->GetText();
2992 void wxListMainWindow::OnRenameTimer()
2994 wxCHECK_RET( HasCurrent(), wxT("unexpected rename timer") );
2996 EditLabel( m_current
);
2999 bool wxListMainWindow::OnRenameAccept(size_t itemEdit
, const wxString
& value
)
3001 wxListEvent
le( wxEVT_COMMAND_LIST_END_LABEL_EDIT
, GetParent()->GetId() );
3002 le
.SetEventObject( GetParent() );
3003 le
.m_itemIndex
= itemEdit
;
3005 wxListLineData
*data
= GetLine(itemEdit
);
3007 wxCHECK_MSG( data
, false, _T("invalid index in OnRenameAccept()") );
3009 data
->GetItem( 0, le
.m_item
);
3010 le
.m_item
.m_text
= value
;
3011 return !GetParent()->GetEventHandler()->ProcessEvent( le
) ||
3015 void wxListMainWindow::OnRenameCancelled(size_t itemEdit
)
3017 // let owner know that the edit was cancelled
3018 wxListEvent
le( wxEVT_COMMAND_LIST_END_LABEL_EDIT
, GetParent()->GetId() );
3020 le
.SetEditCanceled(true);
3022 le
.SetEventObject( GetParent() );
3023 le
.m_itemIndex
= itemEdit
;
3025 wxListLineData
*data
= GetLine(itemEdit
);
3026 wxCHECK_RET( data
, _T("invalid index in OnRenameCancelled()") );
3028 data
->GetItem( 0, le
.m_item
);
3029 GetEventHandler()->ProcessEvent( le
);
3032 void wxListMainWindow::OnMouse( wxMouseEvent
&event
)
3036 // On wxMac we can't depend on the EVT_KILL_FOCUS event to properly
3037 // shutdown the edit control when the mouse is clicked elsewhere on the
3038 // listctrl because the order of events is different (or something like
3039 // that), so explicitly end the edit if it is active.
3040 if ( event
.LeftDown() && m_textctrlWrapper
)
3041 m_textctrlWrapper
->AcceptChangesAndFinish();
3044 if ( event
.LeftDown() )
3045 SetFocusIgnoringChildren();
3047 event
.SetEventObject( GetParent() );
3048 if ( GetParent()->GetEventHandler()->ProcessEvent( event
) )
3051 if (event
.GetEventType() == wxEVT_MOUSEWHEEL
)
3053 // let the base handle mouse wheel events.
3058 if ( !HasCurrent() || IsEmpty() )
3060 if (event
.RightDown())
3062 SendNotify( (size_t)-1, wxEVT_COMMAND_LIST_ITEM_RIGHT_CLICK
, event
.GetPosition() );
3063 // Allow generation of context menu event
3072 if ( !(event
.Dragging() || event
.ButtonDown() || event
.LeftUp() ||
3073 event
.ButtonDClick()) )
3076 int x
= event
.GetX();
3077 int y
= event
.GetY();
3078 CalcUnscrolledPosition( x
, y
, &x
, &y
);
3080 // where did we hit it (if we did)?
3083 size_t count
= GetItemCount(),
3086 if ( InReportView() )
3088 current
= y
/ GetLineHeight();
3089 if ( current
< count
)
3090 hitResult
= HitTestLine(current
, x
, y
);
3094 // TODO: optimize it too! this is less simple than for report view but
3095 // enumerating all items is still not a way to do it!!
3096 for ( current
= 0; current
< count
; current
++ )
3098 hitResult
= HitTestLine(current
, x
, y
);
3104 if (event
.Dragging())
3106 if (m_dragCount
== 0)
3108 // we have to report the raw, physical coords as we want to be
3109 // able to call HitTest(event.m_pointDrag) from the user code to
3110 // get the item being dragged
3111 m_dragStart
= event
.GetPosition();
3116 if (m_dragCount
!= 3)
3119 int command
= event
.RightIsDown() ? wxEVT_COMMAND_LIST_BEGIN_RDRAG
3120 : wxEVT_COMMAND_LIST_BEGIN_DRAG
;
3122 wxListEvent
le( command
, GetParent()->GetId() );
3123 le
.SetEventObject( GetParent() );
3124 le
.m_itemIndex
= m_lineLastClicked
;
3125 le
.m_pointDrag
= m_dragStart
;
3126 GetParent()->GetEventHandler()->ProcessEvent( le
);
3137 // outside of any item
3138 if (event
.RightDown())
3140 SendNotify( (size_t) -1, wxEVT_COMMAND_LIST_ITEM_RIGHT_CLICK
, event
.GetPosition() );
3142 wxContextMenuEvent
evtCtx(
3144 GetParent()->GetId(),
3145 ClientToScreen(event
.GetPosition()));
3146 evtCtx
.SetEventObject(GetParent());
3147 GetParent()->GetEventHandler()->ProcessEvent(evtCtx
);
3151 // reset the selection and bail out
3152 HighlightAll(false);
3158 bool forceClick
= false;
3159 if (event
.ButtonDClick())
3161 if ( m_renameTimer
->IsRunning() )
3162 m_renameTimer
->Stop();
3164 m_lastOnSame
= false;
3166 if ( current
== m_lineLastClicked
)
3168 SendNotify( current
, wxEVT_COMMAND_LIST_ITEM_ACTIVATED
);
3174 // The first click was on another item, so don't interpret this as
3175 // a double click, but as a simple click instead
3182 if (m_lineSelectSingleOnUp
!= (size_t)-1)
3184 // select single line
3185 HighlightAll( false );
3186 ReverseHighlight(m_lineSelectSingleOnUp
);
3191 if ((current
== m_current
) &&
3192 (hitResult
== wxLIST_HITTEST_ONITEMLABEL
) &&
3193 HasFlag(wxLC_EDIT_LABELS
) )
3197 wxRect label
= GetLineLabelRect( current
);
3198 if (label
.Contains( x
, y
))
3199 m_renameTimer
->Start( 250, true );
3203 m_renameTimer
->Start( 250, true );
3207 m_lastOnSame
= false;
3208 m_lineSelectSingleOnUp
= (size_t)-1;
3212 // This is necessary, because after a DnD operation in
3213 // from and to ourself, the up event is swallowed by the
3214 // DnD code. So on next non-up event (which means here and
3215 // now) m_lineSelectSingleOnUp should be reset.
3216 m_lineSelectSingleOnUp
= (size_t)-1;
3218 if (event
.RightDown())
3220 m_lineBeforeLastClicked
= m_lineLastClicked
;
3221 m_lineLastClicked
= current
;
3223 // If the item is already selected, do not update the selection.
3224 // Multi-selections should not be cleared if a selected item is clicked.
3225 if (!IsHighlighted(current
))
3227 HighlightAll(false);
3228 ChangeCurrent(current
);
3229 ReverseHighlight(m_current
);
3232 SendNotify( current
, wxEVT_COMMAND_LIST_ITEM_RIGHT_CLICK
, event
.GetPosition() );
3234 wxContextMenuEvent
evtCtx(
3236 GetParent()->GetId(),
3237 ClientToScreen(event
.GetPosition()));
3238 evtCtx
.SetEventObject(GetParent());
3239 GetParent()->GetEventHandler()->ProcessEvent(evtCtx
);
3241 else if (event
.MiddleDown())
3243 SendNotify( current
, wxEVT_COMMAND_LIST_ITEM_MIDDLE_CLICK
);
3245 else if ( event
.LeftDown() || forceClick
)
3247 m_lineBeforeLastClicked
= m_lineLastClicked
;
3248 m_lineLastClicked
= current
;
3250 size_t oldCurrent
= m_current
;
3251 bool oldWasSelected
= IsHighlighted(m_current
);
3253 bool cmdModifierDown
= event
.CmdDown();
3254 if ( IsSingleSel() || !(cmdModifierDown
|| event
.ShiftDown()) )
3256 if ( IsSingleSel() || !IsHighlighted(current
) )
3258 HighlightAll( false );
3260 ChangeCurrent(current
);
3262 ReverseHighlight(m_current
);
3264 else // multi sel & current is highlighted & no mod keys
3266 m_lineSelectSingleOnUp
= current
;
3267 ChangeCurrent(current
); // change focus
3270 else // multi sel & either ctrl or shift is down
3272 if (cmdModifierDown
)
3274 ChangeCurrent(current
);
3276 ReverseHighlight(m_current
);
3278 else if (event
.ShiftDown())
3280 ChangeCurrent(current
);
3282 size_t lineFrom
= oldCurrent
,
3285 if ( lineTo
< lineFrom
)
3288 lineFrom
= m_current
;
3291 HighlightLines(lineFrom
, lineTo
);
3293 else // !ctrl, !shift
3295 // test in the enclosing if should make it impossible
3296 wxFAIL_MSG( _T("how did we get here?") );
3300 if (m_current
!= oldCurrent
)
3301 RefreshLine( oldCurrent
);
3303 // forceClick is only set if the previous click was on another item
3304 m_lastOnSame
= !forceClick
&& (m_current
== oldCurrent
) && oldWasSelected
;
3308 void wxListMainWindow::MoveToItem(size_t item
)
3310 if ( item
== (size_t)-1 )
3313 wxRect rect
= GetLineRect(item
);
3315 int client_w
, client_h
;
3316 GetClientSize( &client_w
, &client_h
);
3318 const int hLine
= GetLineHeight();
3320 int view_x
= SCROLL_UNIT_X
* GetScrollPos( wxHORIZONTAL
);
3321 int view_y
= hLine
* GetScrollPos( wxVERTICAL
);
3323 if ( InReportView() )
3325 // the next we need the range of lines shown it might be different,
3326 // so recalculate it
3327 ResetVisibleLinesRange();
3329 if (rect
.y
< view_y
)
3330 Scroll( -1, rect
.y
/ hLine
);
3331 if (rect
.y
+ rect
.height
+ 5 > view_y
+ client_h
)
3332 Scroll( -1, (rect
.y
+ rect
.height
- client_h
+ hLine
) / hLine
);
3335 // At least on Mac the visible lines value will get reset inside of
3336 // Scroll *before* it actually scrolls the window because of the
3337 // Update() that happens there, so it will still have the wrong value.
3338 // So let's reset it again and wait for it to be recalculated in the
3339 // next paint event. I would expect this problem to show up in wxGTK
3340 // too but couldn't duplicate it there. Perhaps the order of events
3341 // is different... --Robin
3342 ResetVisibleLinesRange();
3347 if (rect
.x
-view_x
< 5)
3348 Scroll( (rect
.x
- 5) / SCROLL_UNIT_X
, -1 );
3349 if (rect
.x
+ rect
.width
- 5 > view_x
+ client_w
)
3350 Scroll( (rect
.x
+ rect
.width
- client_w
+ SCROLL_UNIT_X
) / SCROLL_UNIT_X
, -1 );
3354 // ----------------------------------------------------------------------------
3355 // keyboard handling
3356 // ----------------------------------------------------------------------------
3358 void wxListMainWindow::OnArrowChar(size_t newCurrent
, const wxKeyEvent
& event
)
3360 wxCHECK_RET( newCurrent
< (size_t)GetItemCount(),
3361 _T("invalid item index in OnArrowChar()") );
3363 size_t oldCurrent
= m_current
;
3365 // in single selection we just ignore Shift as we can't select several
3367 if ( event
.ShiftDown() && !IsSingleSel() )
3369 ChangeCurrent(newCurrent
);
3371 // refresh the old focus to remove it
3372 RefreshLine( oldCurrent
);
3374 // select all the items between the old and the new one
3375 if ( oldCurrent
> newCurrent
)
3377 newCurrent
= oldCurrent
;
3378 oldCurrent
= m_current
;
3381 HighlightLines(oldCurrent
, newCurrent
);
3385 // all previously selected items are unselected unless ctrl is held
3386 // in a multiselection control
3387 if ( !event
.ControlDown() || IsSingleSel() )
3388 HighlightAll(false);
3390 ChangeCurrent(newCurrent
);
3392 // refresh the old focus to remove it
3393 RefreshLine( oldCurrent
);
3395 // in single selection mode we must always have a selected item
3396 if ( !event
.ControlDown() || IsSingleSel() )
3397 HighlightLine( m_current
, true );
3400 RefreshLine( m_current
);
3405 void wxListMainWindow::OnKeyDown( wxKeyEvent
&event
)
3407 wxWindow
*parent
= GetParent();
3409 // propagate the key event upwards
3410 wxKeyEvent
ke(event
);
3411 if (parent
->GetEventHandler()->ProcessEvent( ke
))
3417 void wxListMainWindow::OnKeyUp( wxKeyEvent
&event
)
3419 wxWindow
*parent
= GetParent();
3421 // propagate the key event upwards
3422 wxKeyEvent
ke(event
);
3423 ke
.SetEventObject( parent
);
3424 if (parent
->GetEventHandler()->ProcessEvent( ke
))
3430 void wxListMainWindow::OnChar( wxKeyEvent
&event
)
3432 wxWindow
*parent
= GetParent();
3434 // send a list_key event up
3437 wxListEvent
le( wxEVT_COMMAND_LIST_KEY_DOWN
, GetParent()->GetId() );
3438 le
.m_itemIndex
= m_current
;
3439 GetLine(m_current
)->GetItem( 0, le
.m_item
);
3440 le
.m_code
= event
.GetKeyCode();
3441 le
.SetEventObject( parent
);
3442 parent
->GetEventHandler()->ProcessEvent( le
);
3445 // propagate the char event upwards
3446 wxKeyEvent
ke(event
);
3447 if (parent
->GetEventHandler()->ProcessEvent( ke
))
3450 if (event
.GetKeyCode() == WXK_TAB
)
3452 wxNavigationKeyEvent nevent
;
3453 nevent
.SetWindowChange( event
.ControlDown() );
3454 nevent
.SetDirection( !event
.ShiftDown() );
3455 nevent
.SetEventObject( GetParent()->GetParent() );
3456 nevent
.SetCurrentFocus( m_parent
);
3457 if (GetParent()->GetParent()->GetEventHandler()->ProcessEvent( nevent
))
3461 // no item -> nothing to do
3468 // don't use m_linesPerPage directly as it might not be computed yet
3469 const int pageSize
= GetCountPerPage();
3470 wxCHECK_RET( pageSize
, _T("should have non zero page size") );
3472 if (GetLayoutDirection() == wxLayout_RightToLeft
)
3474 if (event
.GetKeyCode() == WXK_RIGHT
)
3475 event
.m_keyCode
= WXK_LEFT
;
3476 else if (event
.GetKeyCode() == WXK_LEFT
)
3477 event
.m_keyCode
= WXK_RIGHT
;
3480 switch ( event
.GetKeyCode() )
3483 if ( m_current
> 0 )
3484 OnArrowChar( m_current
- 1, event
);
3488 if ( m_current
< (size_t)GetItemCount() - 1 )
3489 OnArrowChar( m_current
+ 1, event
);
3494 OnArrowChar( GetItemCount() - 1, event
);
3499 OnArrowChar( 0, event
);
3504 int steps
= InReportView() ? pageSize
- 1
3505 : m_current
% pageSize
;
3507 int index
= m_current
- steps
;
3511 OnArrowChar( index
, event
);
3517 int steps
= InReportView()
3519 : pageSize
- (m_current
% pageSize
) - 1;
3521 size_t index
= m_current
+ steps
;
3522 size_t count
= GetItemCount();
3523 if ( index
>= count
)
3526 OnArrowChar( index
, event
);
3531 if ( !InReportView() )
3533 int index
= m_current
- pageSize
;
3537 OnArrowChar( index
, event
);
3542 if ( !InReportView() )
3544 size_t index
= m_current
+ pageSize
;
3546 size_t count
= GetItemCount();
3547 if ( index
>= count
)
3550 OnArrowChar( index
, event
);
3555 if ( IsSingleSel() )
3557 if ( event
.ControlDown() )
3559 ReverseHighlight(m_current
);
3561 else // normal space press
3563 SendNotify( m_current
, wxEVT_COMMAND_LIST_ITEM_ACTIVATED
);
3566 else // multiple selection
3568 ReverseHighlight(m_current
);
3574 SendNotify( m_current
, wxEVT_COMMAND_LIST_ITEM_ACTIVATED
);
3582 // ----------------------------------------------------------------------------
3584 // ----------------------------------------------------------------------------
3586 void wxListMainWindow::OnSetFocus( wxFocusEvent
&WXUNUSED(event
) )
3590 wxFocusEvent
event( wxEVT_SET_FOCUS
, GetParent()->GetId() );
3591 event
.SetEventObject( GetParent() );
3592 if ( GetParent()->GetEventHandler()->ProcessEvent( event
) )
3596 // wxGTK sends us EVT_SET_FOCUS events even if we had never got
3597 // EVT_KILL_FOCUS before which means that we finish by redrawing the items
3598 // which are already drawn correctly resulting in horrible flicker - avoid
3608 void wxListMainWindow::OnKillFocus( wxFocusEvent
&WXUNUSED(event
) )
3612 wxFocusEvent
event( wxEVT_KILL_FOCUS
, GetParent()->GetId() );
3613 event
.SetEventObject( GetParent() );
3614 if ( GetParent()->GetEventHandler()->ProcessEvent( event
) )
3622 void wxListMainWindow::DrawImage( int index
, wxDC
*dc
, int x
, int y
)
3624 if ( HasFlag(wxLC_ICON
) && (m_normal_image_list
))
3626 m_normal_image_list
->Draw( index
, *dc
, x
, y
, wxIMAGELIST_DRAW_TRANSPARENT
);
3628 else if ( HasFlag(wxLC_SMALL_ICON
) && (m_small_image_list
))
3630 m_small_image_list
->Draw( index
, *dc
, x
, y
, wxIMAGELIST_DRAW_TRANSPARENT
);
3632 else if ( HasFlag(wxLC_LIST
) && (m_small_image_list
))
3634 m_small_image_list
->Draw( index
, *dc
, x
, y
, wxIMAGELIST_DRAW_TRANSPARENT
);
3636 else if ( InReportView() && (m_small_image_list
))
3638 m_small_image_list
->Draw( index
, *dc
, x
, y
, wxIMAGELIST_DRAW_TRANSPARENT
);
3642 void wxListMainWindow::GetImageSize( int index
, int &width
, int &height
) const
3644 if ( HasFlag(wxLC_ICON
) && m_normal_image_list
)
3646 m_normal_image_list
->GetSize( index
, width
, height
);
3648 else if ( HasFlag(wxLC_SMALL_ICON
) && m_small_image_list
)
3650 m_small_image_list
->GetSize( index
, width
, height
);
3652 else if ( HasFlag(wxLC_LIST
) && m_small_image_list
)
3654 m_small_image_list
->GetSize( index
, width
, height
);
3656 else if ( InReportView() && m_small_image_list
)
3658 m_small_image_list
->GetSize( index
, width
, height
);
3667 int wxListMainWindow::GetTextLength( const wxString
&s
) const
3669 wxClientDC
dc( wxConstCast(this, wxListMainWindow
) );
3670 dc
.SetFont( GetFont() );
3673 dc
.GetTextExtent( s
, &lw
, NULL
);
3675 return lw
+ AUTOSIZE_COL_MARGIN
;
3678 void wxListMainWindow::SetImageList( wxImageList
*imageList
, int which
)
3682 // calc the spacing from the icon size
3683 int width
= 0, height
= 0;
3685 if ((imageList
) && (imageList
->GetImageCount()) )
3686 imageList
->GetSize(0, width
, height
);
3688 if (which
== wxIMAGE_LIST_NORMAL
)
3690 m_normal_image_list
= imageList
;
3691 m_normal_spacing
= width
+ 8;
3694 if (which
== wxIMAGE_LIST_SMALL
)
3696 m_small_image_list
= imageList
;
3697 m_small_spacing
= width
+ 14;
3698 m_lineHeight
= 0; // ensure that the line height will be recalc'd
3702 void wxListMainWindow::SetItemSpacing( int spacing
, bool isSmall
)
3706 m_small_spacing
= spacing
;
3708 m_normal_spacing
= spacing
;
3711 int wxListMainWindow::GetItemSpacing( bool isSmall
)
3713 return isSmall
? m_small_spacing
: m_normal_spacing
;
3716 // ----------------------------------------------------------------------------
3718 // ----------------------------------------------------------------------------
3720 void wxListMainWindow::SetColumn( int col
, wxListItem
&item
)
3722 wxListHeaderDataList::compatibility_iterator node
= m_columns
.Item( col
);
3724 wxCHECK_RET( node
, _T("invalid column index in SetColumn") );
3726 if ( item
.m_width
== wxLIST_AUTOSIZE_USEHEADER
)
3727 item
.m_width
= GetTextLength( item
.m_text
);
3729 wxListHeaderData
*column
= node
->GetData();
3730 column
->SetItem( item
);
3732 wxListHeaderWindow
*headerWin
= GetListCtrl()->m_headerWin
;
3734 headerWin
->m_dirty
= true;
3738 // invalidate it as it has to be recalculated
3742 void wxListMainWindow::SetColumnWidth( int col
, int width
)
3744 { wxCHECK_RET( col
>= 0 && col
< GetColumnCount(),
3745 _T("invalid column index") ); }
3747 { wxCHECK_RET( InReportView(),
3748 _T("SetColumnWidth() can only be called in report mode.") ); }
3751 wxListHeaderWindow
*headerWin
= GetListCtrl()->m_headerWin
;
3753 headerWin
->m_dirty
= true;
3755 wxListHeaderDataList::compatibility_iterator node
= m_columns
.Item( col
);
3756 { wxCHECK_RET( node
, _T("no column?") ); }
3758 wxListHeaderData
*column
= node
->GetData();
3760 size_t count
= GetItemCount();
3762 if (width
== wxLIST_AUTOSIZE_USEHEADER
)
3764 width
= GetTextLength(column
->GetText());
3765 width
+= 2*EXTRA_WIDTH
;
3767 // check for column header's image availability
3768 const int image
= column
->GetImage();
3771 if ( m_small_image_list
)
3774 m_small_image_list
->GetSize(image
, ix
, iy
);
3775 width
+= ix
+ HEADER_IMAGE_MARGIN_IN_REPORT_MODE
;
3779 else if ( width
== wxLIST_AUTOSIZE
)
3783 // TODO: determine the max width somehow...
3784 width
= WIDTH_COL_DEFAULT
;
3788 wxClientDC
dc(this);
3789 dc
.SetFont( GetFont() );
3791 int max
= AUTOSIZE_COL_MARGIN
;
3793 // if the cached column width isn't valid then recalculate it
3794 if (m_aColWidths
.Item(col
)->bNeedsUpdate
)
3796 for (size_t i
= 0; i
< count
; i
++)
3798 wxListLineData
*line
= GetLine( i
);
3799 wxListItemDataList::compatibility_iterator n
= line
->m_items
.Item( col
);
3801 wxCHECK_RET( n
, _T("no subitem?") );
3803 wxListItemData
*itemData
= n
->GetData();
3806 itemData
->GetItem(item
);
3807 int itemWidth
= GetItemWidthWithImage(&item
);
3808 if (itemWidth
> max
)
3812 m_aColWidths
.Item(col
)->bNeedsUpdate
= false;
3813 m_aColWidths
.Item(col
)->nMaxWidth
= max
;
3816 max
= m_aColWidths
.Item(col
)->nMaxWidth
;
3817 width
= max
+ AUTOSIZE_COL_MARGIN
;
3821 column
->SetWidth( width
);
3823 // invalidate it as it has to be recalculated
3827 int wxListMainWindow::GetHeaderWidth() const
3829 if ( !m_headerWidth
)
3831 wxListMainWindow
*self
= wxConstCast(this, wxListMainWindow
);
3833 size_t count
= GetColumnCount();
3834 for ( size_t col
= 0; col
< count
; col
++ )
3836 self
->m_headerWidth
+= GetColumnWidth(col
);
3840 return m_headerWidth
;
3843 void wxListMainWindow::GetColumn( int col
, wxListItem
&item
) const
3845 wxListHeaderDataList::compatibility_iterator node
= m_columns
.Item( col
);
3846 wxCHECK_RET( node
, _T("invalid column index in GetColumn") );
3848 wxListHeaderData
*column
= node
->GetData();
3849 column
->GetItem( item
);
3852 int wxListMainWindow::GetColumnWidth( int col
) const
3854 wxListHeaderDataList::compatibility_iterator node
= m_columns
.Item( col
);
3855 wxCHECK_MSG( node
, 0, _T("invalid column index") );
3857 wxListHeaderData
*column
= node
->GetData();
3858 return column
->GetWidth();
3861 // ----------------------------------------------------------------------------
3863 // ----------------------------------------------------------------------------
3865 void wxListMainWindow::SetItem( wxListItem
&item
)
3867 long id
= item
.m_itemId
;
3868 wxCHECK_RET( id
>= 0 && (size_t)id
< GetItemCount(),
3869 _T("invalid item index in SetItem") );
3873 wxListLineData
*line
= GetLine((size_t)id
);
3874 line
->SetItem( item
.m_col
, item
);
3876 // Set item state if user wants
3877 if ( item
.m_mask
& wxLIST_MASK_STATE
)
3878 SetItemState( item
.m_itemId
, item
.m_state
, item
.m_state
);
3882 // update the Max Width Cache if needed
3883 int width
= GetItemWidthWithImage(&item
);
3885 if (width
> m_aColWidths
.Item(item
.m_col
)->nMaxWidth
)
3886 m_aColWidths
.Item(item
.m_col
)->nMaxWidth
= width
;
3890 // update the item on screen
3892 GetItemRect(id
, rectItem
);
3893 RefreshRect(rectItem
);
3896 void wxListMainWindow::SetItemStateAll(long state
, long stateMask
)
3901 // first deal with selection
3902 if ( stateMask
& wxLIST_STATE_SELECTED
)
3904 // set/clear select state
3907 // optimized version for virtual listctrl.
3908 m_selStore
.SelectRange(0, GetItemCount() - 1, state
== wxLIST_STATE_SELECTED
);
3911 else if ( state
& wxLIST_STATE_SELECTED
)
3913 const long count
= GetItemCount();
3914 for( long i
= 0; i
< count
; i
++ )
3916 SetItemState( i
, wxLIST_STATE_SELECTED
, wxLIST_STATE_SELECTED
);
3922 // clear for non virtual (somewhat optimized by using GetNextItem())
3924 while ( (i
= GetNextItem(i
, wxLIST_NEXT_ALL
, wxLIST_STATE_SELECTED
)) != -1 )
3926 SetItemState( i
, 0, wxLIST_STATE_SELECTED
);
3931 if ( HasCurrent() && (state
== 0) && (stateMask
& wxLIST_STATE_FOCUSED
) )
3933 // unfocus all: only one item can be focussed, so clearing focus for
3934 // all items is simply clearing focus of the focussed item.
3935 SetItemState(m_current
, state
, stateMask
);
3937 //(setting focus to all items makes no sense, so it is not handled here.)
3940 void wxListMainWindow::SetItemState( long litem
, long state
, long stateMask
)
3944 SetItemStateAll(state
, stateMask
);
3948 wxCHECK_RET( litem
>= 0 && (size_t)litem
< GetItemCount(),
3949 _T("invalid list ctrl item index in SetItem") );
3951 size_t oldCurrent
= m_current
;
3952 size_t item
= (size_t)litem
; // safe because of the check above
3954 // do we need to change the focus?
3955 if ( stateMask
& wxLIST_STATE_FOCUSED
)
3957 if ( state
& wxLIST_STATE_FOCUSED
)
3959 // don't do anything if this item is already focused
3960 if ( item
!= m_current
)
3962 ChangeCurrent(item
);
3964 if ( oldCurrent
!= (size_t)-1 )
3966 if ( IsSingleSel() )
3968 HighlightLine(oldCurrent
, false);
3971 RefreshLine(oldCurrent
);
3974 RefreshLine( m_current
);
3979 // don't do anything if this item is not focused
3980 if ( item
== m_current
)
3984 if ( IsSingleSel() )
3986 // we must unselect the old current item as well or we
3987 // might end up with more than one selected item in a
3988 // single selection control
3989 HighlightLine(oldCurrent
, false);
3992 RefreshLine( oldCurrent
);
3997 // do we need to change the selection state?
3998 if ( stateMask
& wxLIST_STATE_SELECTED
)
4000 bool on
= (state
& wxLIST_STATE_SELECTED
) != 0;
4002 if ( IsSingleSel() )
4006 // selecting the item also makes it the focused one in the
4008 if ( m_current
!= item
)
4010 ChangeCurrent(item
);
4012 if ( oldCurrent
!= (size_t)-1 )
4014 HighlightLine( oldCurrent
, false );
4015 RefreshLine( oldCurrent
);
4021 // only the current item may be selected anyhow
4022 if ( item
!= m_current
)
4027 if ( HighlightLine(item
, on
) )
4034 int wxListMainWindow::GetItemState( long item
, long stateMask
) const
4036 wxCHECK_MSG( item
>= 0 && (size_t)item
< GetItemCount(), 0,
4037 _T("invalid list ctrl item index in GetItemState()") );
4039 int ret
= wxLIST_STATE_DONTCARE
;
4041 if ( stateMask
& wxLIST_STATE_FOCUSED
)
4043 if ( (size_t)item
== m_current
)
4044 ret
|= wxLIST_STATE_FOCUSED
;
4047 if ( stateMask
& wxLIST_STATE_SELECTED
)
4049 if ( IsHighlighted(item
) )
4050 ret
|= wxLIST_STATE_SELECTED
;
4056 void wxListMainWindow::GetItem( wxListItem
&item
) const
4058 wxCHECK_RET( item
.m_itemId
>= 0 && (size_t)item
.m_itemId
< GetItemCount(),
4059 _T("invalid item index in GetItem") );
4061 wxListLineData
*line
= GetLine((size_t)item
.m_itemId
);
4062 line
->GetItem( item
.m_col
, item
);
4064 // Get item state if user wants it
4065 if ( item
.m_mask
& wxLIST_MASK_STATE
)
4066 item
.m_state
= GetItemState( item
.m_itemId
, wxLIST_STATE_SELECTED
|
4067 wxLIST_STATE_FOCUSED
);
4070 // ----------------------------------------------------------------------------
4072 // ----------------------------------------------------------------------------
4074 size_t wxListMainWindow::GetItemCount() const
4076 return IsVirtual() ? m_countVirt
: m_lines
.GetCount();
4079 void wxListMainWindow::SetItemCount(long count
)
4081 m_selStore
.SetItemCount(count
);
4082 m_countVirt
= count
;
4084 ResetVisibleLinesRange();
4086 // scrollbars must be reset
4090 int wxListMainWindow::GetSelectedItemCount() const
4092 // deal with the quick case first
4093 if ( IsSingleSel() )
4094 return HasCurrent() ? IsHighlighted(m_current
) : false;
4096 // virtual controls remmebers all its selections itself
4098 return m_selStore
.GetSelectedCount();
4100 // TODO: we probably should maintain the number of items selected even for
4101 // non virtual controls as enumerating all lines is really slow...
4102 size_t countSel
= 0;
4103 size_t count
= GetItemCount();
4104 for ( size_t line
= 0; line
< count
; line
++ )
4106 if ( GetLine(line
)->IsHighlighted() )
4113 // ----------------------------------------------------------------------------
4114 // item position/size
4115 // ----------------------------------------------------------------------------
4117 wxRect
wxListMainWindow::GetViewRect() const
4119 wxASSERT_MSG( !HasFlag(wxLC_REPORT
| wxLC_LIST
),
4120 _T("wxListCtrl::GetViewRect() only works in icon mode") );
4122 // we need to find the longest/tallest label
4123 wxCoord xMax
= 0, yMax
= 0;
4124 const int count
= GetItemCount();
4127 for ( int i
= 0; i
< count
; i
++ )
4129 // we need logical, not physical, coordinates here, so use
4130 // GetLineRect() instead of GetItemRect()
4131 wxRect r
= GetLineRect(i
);
4133 wxCoord x
= r
.GetRight(),
4143 // some fudge needed to make it look prettier
4144 xMax
+= 2 * EXTRA_BORDER_X
;
4145 yMax
+= 2 * EXTRA_BORDER_Y
;
4147 // account for the scrollbars if necessary
4148 const wxSize sizeAll
= GetClientSize();
4149 if ( xMax
> sizeAll
.x
)
4150 yMax
+= wxSystemSettings::GetMetric(wxSYS_HSCROLL_Y
);
4151 if ( yMax
> sizeAll
.y
)
4152 xMax
+= wxSystemSettings::GetMetric(wxSYS_VSCROLL_X
);
4154 return wxRect(0, 0, xMax
, yMax
);
4157 void wxListMainWindow::GetItemRect( long index
, wxRect
&rect
) const
4159 wxCHECK_RET( index
>= 0 && (size_t)index
< GetItemCount(),
4160 _T("invalid index in GetItemRect") );
4162 // ensure that we're laid out, otherwise we could return nonsense
4165 wxConstCast(this, wxListMainWindow
)->
4166 RecalculatePositions(true /* no refresh */);
4169 rect
= GetLineRect((size_t)index
);
4171 CalcScrolledPosition(rect
.x
, rect
.y
, &rect
.x
, &rect
.y
);
4174 bool wxListMainWindow::GetItemPosition(long item
, wxPoint
& pos
) const
4177 GetItemRect(item
, rect
);
4185 // ----------------------------------------------------------------------------
4186 // geometry calculation
4187 // ----------------------------------------------------------------------------
4189 void wxListMainWindow::RecalculatePositions(bool noRefresh
)
4191 const int lineHeight
= GetLineHeight();
4193 wxClientDC
dc( this );
4194 dc
.SetFont( GetFont() );
4196 const size_t count
= GetItemCount();
4199 if ( HasFlag(wxLC_ICON
) && m_normal_image_list
)
4200 iconSpacing
= m_normal_spacing
;
4201 else if ( HasFlag(wxLC_SMALL_ICON
) && m_small_image_list
)
4202 iconSpacing
= m_small_spacing
;
4206 // Note that we do not call GetClientSize() here but
4207 // GetSize() and subtract the border size for sunken
4208 // borders manually. This is technically incorrect,
4209 // but we need to know the client area's size WITHOUT
4210 // scrollbars here. Since we don't know if there are
4211 // any scrollbars, we use GetSize() instead. Another
4212 // solution would be to call SetScrollbars() here to
4213 // remove the scrollbars and call GetClientSize() then,
4214 // but this might result in flicker and - worse - will
4215 // reset the scrollbars to 0 which is not good at all
4216 // if you resize a dialog/window, but don't want to
4217 // reset the window scrolling. RR.
4218 // Furthermore, we actually do NOT subtract the border
4219 // width as 2 pixels is just the extra space which we
4220 // need around the actual content in the window. Other-
4221 // wise the text would e.g. touch the upper border. RR.
4224 GetSize( &clientWidth
, &clientHeight
);
4226 if ( InReportView() )
4228 // all lines have the same height and we scroll one line per step
4229 int entireHeight
= count
* lineHeight
+ LINE_SPACING
;
4231 m_linesPerPage
= clientHeight
/ lineHeight
;
4233 ResetVisibleLinesRange();
4235 SetScrollbars( SCROLL_UNIT_X
, lineHeight
,
4236 GetHeaderWidth() / SCROLL_UNIT_X
,
4237 (entireHeight
+ lineHeight
- 1) / lineHeight
,
4238 GetScrollPos(wxHORIZONTAL
),
4239 GetScrollPos(wxVERTICAL
),
4244 // we have 3 different layout strategies: either layout all items
4245 // horizontally/vertically (wxLC_ALIGN_XXX styles explicitly given) or
4246 // to arrange them in top to bottom, left to right (don't ask me why
4247 // not the other way round...) order
4248 if ( HasFlag(wxLC_ALIGN_LEFT
| wxLC_ALIGN_TOP
) )
4250 int x
= EXTRA_BORDER_X
;
4251 int y
= EXTRA_BORDER_Y
;
4253 wxCoord widthMax
= 0;
4256 for ( i
= 0; i
< count
; i
++ )
4258 wxListLineData
*line
= GetLine(i
);
4259 line
->CalculateSize( &dc
, iconSpacing
);
4260 line
->SetPosition( x
, y
, iconSpacing
);
4262 wxSize sizeLine
= GetLineSize(i
);
4264 if ( HasFlag(wxLC_ALIGN_TOP
) )
4266 if ( sizeLine
.x
> widthMax
)
4267 widthMax
= sizeLine
.x
;
4271 else // wxLC_ALIGN_LEFT
4273 x
+= sizeLine
.x
+ MARGIN_BETWEEN_ROWS
;
4277 if ( HasFlag(wxLC_ALIGN_TOP
) )
4279 // traverse the items again and tweak their sizes so that they are
4280 // all the same in a row
4281 for ( i
= 0; i
< count
; i
++ )
4283 wxListLineData
*line
= GetLine(i
);
4284 line
->m_gi
->ExtendWidth(widthMax
);
4292 (x
+ SCROLL_UNIT_X
) / SCROLL_UNIT_X
,
4293 (y
+ lineHeight
) / lineHeight
,
4294 GetScrollPos( wxHORIZONTAL
),
4295 GetScrollPos( wxVERTICAL
),
4299 else // "flowed" arrangement, the most complicated case
4301 // at first we try without any scrollbars, if the items don't fit into
4302 // the window, we recalculate after subtracting the space taken by the
4305 int entireWidth
= 0;
4307 for (int tries
= 0; tries
< 2; tries
++)
4309 entireWidth
= 2 * EXTRA_BORDER_X
;
4313 // Now we have decided that the items do not fit into the
4314 // client area, so we need a scrollbar
4315 entireWidth
+= SCROLL_UNIT_X
;
4318 int x
= EXTRA_BORDER_X
;
4319 int y
= EXTRA_BORDER_Y
;
4320 int maxWidthInThisRow
= 0;
4323 int currentlyVisibleLines
= 0;
4325 for (size_t i
= 0; i
< count
; i
++)
4327 currentlyVisibleLines
++;
4328 wxListLineData
*line
= GetLine( i
);
4329 line
->CalculateSize( &dc
, iconSpacing
);
4330 line
->SetPosition( x
, y
, iconSpacing
);
4332 wxSize sizeLine
= GetLineSize( i
);
4334 if ( maxWidthInThisRow
< sizeLine
.x
)
4335 maxWidthInThisRow
= sizeLine
.x
;
4338 if (currentlyVisibleLines
> m_linesPerPage
)
4339 m_linesPerPage
= currentlyVisibleLines
;
4341 if ( y
+ sizeLine
.y
>= clientHeight
)
4343 currentlyVisibleLines
= 0;
4345 maxWidthInThisRow
+= MARGIN_BETWEEN_ROWS
;
4346 x
+= maxWidthInThisRow
;
4347 entireWidth
+= maxWidthInThisRow
;
4348 maxWidthInThisRow
= 0;
4351 // We have reached the last item.
4352 if ( i
== count
- 1 )
4353 entireWidth
+= maxWidthInThisRow
;
4355 if ( (tries
== 0) &&
4356 (entireWidth
+ SCROLL_UNIT_X
> clientWidth
) )
4358 clientHeight
-= wxSystemSettings::
4359 GetMetric(wxSYS_HSCROLL_Y
);
4364 if ( i
== count
- 1 )
4365 tries
= 1; // Everything fits, no second try required.
4373 (entireWidth
+ SCROLL_UNIT_X
) / SCROLL_UNIT_X
,
4375 GetScrollPos( wxHORIZONTAL
),
4384 // FIXME: why should we call it from here?
4391 void wxListMainWindow::RefreshAll()
4396 wxListHeaderWindow
*headerWin
= GetListCtrl()->m_headerWin
;
4397 if ( headerWin
&& headerWin
->m_dirty
)
4399 headerWin
->m_dirty
= false;
4400 headerWin
->Refresh();
4404 void wxListMainWindow::UpdateCurrent()
4406 if ( !HasCurrent() && !IsEmpty() )
4410 long wxListMainWindow::GetNextItem( long item
,
4411 int WXUNUSED(geometry
),
4415 max
= GetItemCount();
4416 wxCHECK_MSG( (ret
== -1) || (ret
< max
), -1,
4417 _T("invalid listctrl index in GetNextItem()") );
4419 // notice that we start with the next item (or the first one if item == -1)
4420 // and this is intentional to allow writing a simple loop to iterate over
4421 // all selected items
4424 // this is not an error because the index was OK initially,
4425 // just no such item
4432 size_t count
= GetItemCount();
4433 for ( size_t line
= (size_t)ret
; line
< count
; line
++ )
4435 if ( (state
& wxLIST_STATE_FOCUSED
) && (line
== m_current
) )
4438 if ( (state
& wxLIST_STATE_SELECTED
) && IsHighlighted(line
) )
4445 // ----------------------------------------------------------------------------
4447 // ----------------------------------------------------------------------------
4449 void wxListMainWindow::DeleteItem( long lindex
)
4451 size_t count
= GetItemCount();
4453 wxCHECK_RET( (lindex
>= 0) && ((size_t)lindex
< count
),
4454 _T("invalid item index in DeleteItem") );
4456 size_t index
= (size_t)lindex
;
4458 // we don't need to adjust the index for the previous items
4459 if ( HasCurrent() && m_current
>= index
)
4461 // if the current item is being deleted, we want the next one to
4462 // become selected - unless there is no next one - so don't adjust
4463 // m_current in this case
4464 if ( m_current
!= index
|| m_current
== count
- 1 )
4468 if ( InReportView() )
4470 // mark the Column Max Width cache as dirty if the items in the line
4471 // we're deleting contain the Max Column Width
4472 wxListLineData
* const line
= GetLine(index
);
4473 wxListItemDataList::compatibility_iterator n
;
4474 wxListItemData
*itemData
;
4478 for (size_t i
= 0; i
< m_columns
.GetCount(); i
++)
4480 n
= line
->m_items
.Item( i
);
4481 itemData
= n
->GetData();
4482 itemData
->GetItem(item
);
4484 itemWidth
= GetItemWidthWithImage(&item
);
4486 if (itemWidth
>= m_aColWidths
.Item(i
)->nMaxWidth
)
4487 m_aColWidths
.Item(i
)->bNeedsUpdate
= true;
4490 ResetVisibleLinesRange();
4493 SendNotify( index
, wxEVT_COMMAND_LIST_DELETE_ITEM
, wxDefaultPosition
);
4498 m_selStore
.OnItemDelete(index
);
4502 m_lines
.RemoveAt( index
);
4505 // we need to refresh the (vert) scrollbar as the number of items changed
4508 RefreshAfter(index
);
4511 void wxListMainWindow::DeleteColumn( int col
)
4513 wxListHeaderDataList::compatibility_iterator node
= m_columns
.Item( col
);
4515 wxCHECK_RET( node
, wxT("invalid column index in DeleteColumn()") );
4518 delete node
->GetData();
4519 m_columns
.Erase( node
);
4523 // update all the items
4524 for ( size_t i
= 0; i
< m_lines
.GetCount(); i
++ )
4526 wxListLineData
* const line
= GetLine(i
);
4527 wxListItemDataList::compatibility_iterator n
= line
->m_items
.Item( col
);
4528 delete n
->GetData();
4529 line
->m_items
.Erase(n
);
4533 if ( InReportView() ) // we only cache max widths when in Report View
4535 delete m_aColWidths
.Item(col
);
4536 m_aColWidths
.RemoveAt(col
);
4539 // invalidate it as it has to be recalculated
4543 void wxListMainWindow::DoDeleteAllItems()
4546 // nothing to do - in particular, don't send the event
4551 // to make the deletion of all items faster, we don't send the
4552 // notifications for each item deletion in this case but only one event
4553 // for all of them: this is compatible with wxMSW and documented in
4554 // DeleteAllItems() description
4556 wxListEvent
event( wxEVT_COMMAND_LIST_DELETE_ALL_ITEMS
, GetParent()->GetId() );
4557 event
.SetEventObject( GetParent() );
4558 GetParent()->GetEventHandler()->ProcessEvent( event
);
4566 if ( InReportView() )
4568 ResetVisibleLinesRange();
4569 for (size_t i
= 0; i
< m_aColWidths
.GetCount(); i
++)
4571 m_aColWidths
.Item(i
)->bNeedsUpdate
= true;
4578 void wxListMainWindow::DeleteAllItems()
4582 RecalculatePositions();
4585 void wxListMainWindow::DeleteEverything()
4587 WX_CLEAR_LIST(wxListHeaderDataList
, m_columns
);
4588 WX_CLEAR_ARRAY(m_aColWidths
);
4593 // ----------------------------------------------------------------------------
4594 // scanning for an item
4595 // ----------------------------------------------------------------------------
4597 void wxListMainWindow::EnsureVisible( long index
)
4599 wxCHECK_RET( index
>= 0 && (size_t)index
< GetItemCount(),
4600 _T("invalid index in EnsureVisible") );
4602 // We have to call this here because the label in question might just have
4603 // been added and its position is not known yet
4605 RecalculatePositions(true /* no refresh */);
4607 MoveToItem((size_t)index
);
4610 long wxListMainWindow::FindItem(long start
, const wxString
& str
, bool partial
)
4616 wxString str_upper
= str
.Upper();
4620 size_t count
= GetItemCount();
4621 for ( size_t i
= (size_t)pos
; i
< count
; i
++ )
4623 wxListLineData
*line
= GetLine(i
);
4624 wxString line_upper
= line
->GetText(0).Upper();
4627 if (line_upper
== str_upper
)
4632 if (line_upper
.find(str_upper
) == 0)
4640 long wxListMainWindow::FindItem(long start
, wxUIntPtr data
)
4646 size_t count
= GetItemCount();
4647 for (size_t i
= (size_t)pos
; i
< count
; i
++)
4649 wxListLineData
*line
= GetLine(i
);
4651 line
->GetItem( 0, item
);
4652 if (item
.m_data
== data
)
4659 long wxListMainWindow::FindItem( const wxPoint
& pt
)
4662 GetVisibleLinesRange( &topItem
, NULL
);
4665 GetItemPosition( GetItemCount() - 1, p
);
4669 long id
= (long)floor( pt
.y
* double(GetItemCount() - topItem
- 1) / p
.y
+ topItem
);
4670 if ( id
>= 0 && id
< (long)GetItemCount() )
4676 long wxListMainWindow::HitTest( int x
, int y
, int &flags
) const
4678 CalcUnscrolledPosition( x
, y
, &x
, &y
);
4680 size_t count
= GetItemCount();
4682 if ( InReportView() )
4684 size_t current
= y
/ GetLineHeight();
4685 if ( current
< count
)
4687 flags
= HitTestLine(current
, x
, y
);
4694 // TODO: optimize it too! this is less simple than for report view but
4695 // enumerating all items is still not a way to do it!!
4696 for ( size_t current
= 0; current
< count
; current
++ )
4698 flags
= HitTestLine(current
, x
, y
);
4707 // ----------------------------------------------------------------------------
4709 // ----------------------------------------------------------------------------
4711 void wxListMainWindow::InsertItem( wxListItem
&item
)
4713 wxASSERT_MSG( !IsVirtual(), _T("can't be used with virtual control") );
4715 int count
= GetItemCount();
4716 wxCHECK_RET( item
.m_itemId
>= 0, _T("invalid item index") );
4718 if (item
.m_itemId
> count
)
4719 item
.m_itemId
= count
;
4721 size_t id
= item
.m_itemId
;
4725 if ( InReportView() )
4727 ResetVisibleLinesRange();
4729 // calculate the width of the item and adjust the max column width
4730 wxColWidthInfo
*pWidthInfo
= m_aColWidths
.Item(item
.GetColumn());
4731 int width
= GetItemWidthWithImage(&item
);
4732 item
.SetWidth(width
);
4733 if (width
> pWidthInfo
->nMaxWidth
)
4734 pWidthInfo
->nMaxWidth
= width
;
4737 wxListLineData
*line
= new wxListLineData(this);
4739 line
->SetItem( item
.m_col
, item
);
4741 m_lines
.Insert( line
, id
);
4745 // If an item is selected at or below the point of insertion, we need to
4746 // increment the member variables because the current row's index has gone
4748 if ( HasCurrent() && m_current
>= id
)
4751 SendNotify(id
, wxEVT_COMMAND_LIST_INSERT_ITEM
);
4753 RefreshLines(id
, GetItemCount() - 1);
4756 void wxListMainWindow::InsertColumn( long col
, wxListItem
&item
)
4759 if ( InReportView() )
4761 if (item
.m_width
== wxLIST_AUTOSIZE_USEHEADER
)
4762 item
.m_width
= GetTextLength( item
.m_text
);
4764 wxListHeaderData
*column
= new wxListHeaderData( item
);
4765 wxColWidthInfo
*colWidthInfo
= new wxColWidthInfo();
4767 bool insert
= (col
>= 0) && ((size_t)col
< m_columns
.GetCount());
4770 wxListHeaderDataList::compatibility_iterator
4771 node
= m_columns
.Item( col
);
4772 m_columns
.Insert( node
, column
);
4773 m_aColWidths
.Insert( colWidthInfo
, col
);
4777 m_columns
.Append( column
);
4778 m_aColWidths
.Add( colWidthInfo
);
4783 // update all the items
4784 for ( size_t i
= 0; i
< m_lines
.GetCount(); i
++ )
4786 wxListLineData
* const line
= GetLine(i
);
4787 wxListItemData
* const data
= new wxListItemData(this);
4789 line
->m_items
.Insert(col
, data
);
4791 line
->m_items
.Append(data
);
4795 // invalidate it as it has to be recalculated
4800 int wxListMainWindow::GetItemWidthWithImage(wxListItem
* item
)
4803 wxClientDC
dc(this);
4805 dc
.SetFont( GetFont() );
4807 if (item
->GetImage() != -1)
4810 GetImageSize( item
->GetImage(), ix
, iy
);
4814 if (!item
->GetText().empty())
4817 dc
.GetTextExtent( item
->GetText(), &w
, NULL
);
4824 // ----------------------------------------------------------------------------
4826 // ----------------------------------------------------------------------------
4828 MuleListCtrlCompare list_ctrl_compare_func_2
;
4829 long list_ctrl_compare_data
;
4831 int LINKAGEMODE
list_ctrl_compare_func_1( wxListLineData
**arg1
, wxListLineData
**arg2
)
4833 wxListLineData
*line1
= *arg1
;
4834 wxListLineData
*line2
= *arg2
;
4836 line1
->GetItem( 0, item
);
4837 wxUIntPtr data1
= item
.m_data
;
4838 line2
->GetItem( 0, item
);
4839 wxUIntPtr data2
= item
.m_data
;
4840 return list_ctrl_compare_func_2( data1
, data2
, list_ctrl_compare_data
);
4843 void wxListMainWindow::SortItems( MuleListCtrlCompare fn
, long data
)
4845 // selections won't make sense any more after sorting the items so reset
4847 HighlightAll(false);
4850 list_ctrl_compare_func_2
= fn
;
4851 list_ctrl_compare_data
= data
;
4852 m_lines
.Sort( list_ctrl_compare_func_1
);
4856 // ----------------------------------------------------------------------------
4858 // ----------------------------------------------------------------------------
4860 void wxListMainWindow::OnScroll(wxScrollWinEvent
& event
)
4863 #if ( defined(__WXGTK__) || defined(__WXMAC__) ) && !defined(__WXUNIVERSAL__)
4864 wxScrolledWindow::OnScroll(event
);
4866 HandleOnScroll( event
);
4869 // update our idea of which lines are shown when we redraw the window the
4871 ResetVisibleLinesRange();
4873 if ( event
.GetOrientation() == wxHORIZONTAL
&& HasHeader() )
4875 wxGenericListCtrl
* lc
= GetListCtrl();
4876 wxCHECK_RET( lc
, _T("no listctrl window?") );
4878 lc
->m_headerWin
->Refresh();
4879 lc
->m_headerWin
->Update();
4883 int wxListMainWindow::GetCountPerPage() const
4885 if ( !m_linesPerPage
)
4887 wxConstCast(this, wxListMainWindow
)->
4888 m_linesPerPage
= GetClientSize().y
/ GetLineHeight();
4891 return m_linesPerPage
;
4894 void wxListMainWindow::GetVisibleLinesRange(size_t *from
, size_t *to
)
4896 wxASSERT_MSG( InReportView(), _T("this is for report mode only") );
4898 if ( m_lineFrom
== (size_t)-1 )
4900 size_t count
= GetItemCount();
4903 m_lineFrom
= GetScrollPos(wxVERTICAL
);
4905 // this may happen if SetScrollbars() hadn't been called yet
4906 if ( m_lineFrom
>= count
)
4907 m_lineFrom
= count
- 1;
4909 // we redraw one extra line but this is needed to make the redrawing
4910 // logic work when there is a fractional number of lines on screen
4911 m_lineTo
= m_lineFrom
+ m_linesPerPage
;
4912 if ( m_lineTo
>= count
)
4913 m_lineTo
= count
- 1;
4915 else // empty control
4918 m_lineTo
= (size_t)-1;
4922 wxASSERT_MSG( IsEmpty() ||
4923 (m_lineFrom
<= m_lineTo
&& m_lineTo
< GetItemCount()),
4924 _T("GetVisibleLinesRange() returns incorrect result") );
4932 // -------------------------------------------------------------------------------------
4933 // wxGenericListCtrl
4934 // -------------------------------------------------------------------------------------
4936 BEGIN_EVENT_TABLE(wxGenericListCtrl
,wxControl
)
4937 EVT_SIZE(wxGenericListCtrl::OnSize
)
4940 wxGenericListCtrl::wxGenericListCtrl()
4942 m_imageListNormal
= (wxImageList
*) NULL
;
4943 m_imageListSmall
= (wxImageList
*) NULL
;
4944 m_imageListState
= (wxImageList
*) NULL
;
4946 m_ownsImageListNormal
=
4947 m_ownsImageListSmall
=
4948 m_ownsImageListState
= false;
4950 m_mainWin
= (wxListMainWindow
*) NULL
;
4951 m_headerWin
= (wxListHeaderWindow
*) NULL
;
4955 wxGenericListCtrl::~wxGenericListCtrl()
4957 if (m_ownsImageListNormal
)
4958 delete m_imageListNormal
;
4959 if (m_ownsImageListSmall
)
4960 delete m_imageListSmall
;
4961 if (m_ownsImageListState
)
4962 delete m_imageListState
;
4965 void wxGenericListCtrl::CalculateAndSetHeaderHeight()
4969 #if defined( __WXMAC__ ) && !defined(__WXUNIVERSAL__) && wxOSX_USE_CARBON
4971 GetThemeMetric( kThemeMetricListHeaderHeight
, &h
);
4973 // we use 'g' to get the descent, too
4975 m_headerWin
->GetTextExtent(wxT("Hg"), &w
, &h
, &d
);
4976 h
+= d
+ 2 * HEADER_OFFSET_Y
+ EXTRA_HEIGHT
;
4979 // only update if changed
4980 if ( h
!= m_headerHeight
)
4985 ResizeReportView(true);
4986 else //why is this needed if it doesn't have a header?
4987 m_headerWin
->SetSize(m_headerWin
->GetSize().x
, m_headerHeight
);
4992 void wxGenericListCtrl::CreateHeaderWindow()
4994 m_headerWin
= new wxListHeaderWindow
4996 this, wxID_ANY
, m_mainWin
,
4998 wxSize(GetClientSize().x
, m_headerHeight
),
5001 CalculateAndSetHeaderHeight();
5004 bool wxGenericListCtrl::GetFocus()
5006 return m_mainWin
->m_hasFocus
;
5009 bool wxGenericListCtrl::Create(wxWindow
*parent
,
5014 const wxValidator
&validator
,
5015 const wxString
&name
)
5019 m_imageListState
= (wxImageList
*) NULL
;
5020 m_ownsImageListNormal
=
5021 m_ownsImageListSmall
=
5022 m_ownsImageListState
= false;
5024 m_mainWin
= (wxListMainWindow
*) NULL
;
5025 m_headerWin
= (wxListHeaderWindow
*) NULL
;
5029 if ( !(style
& wxLC_MASK_TYPE
) )
5031 style
= style
| wxLC_LIST
;
5034 // add more styles here that should only appear
5035 // in the main window
5036 unsigned long only_main_window_style
= wxALWAYS_SHOW_SB
;
5038 if ( !wxControl::Create( parent
, id
, pos
, size
, style
& ~only_main_window_style
, validator
, name
) )
5041 // don't create the inner window with the border
5042 style
&= ~wxBORDER_MASK
;
5044 m_mainWin
= new wxListMainWindow( this, wxID_ANY
, wxPoint(0, 0), size
, style
);
5046 #ifdef __WXMAC_CARBON__
5047 // Human Interface Guidelines ask us for a special font in this case
5048 if ( GetWindowVariant() == wxWINDOW_VARIANT_NORMAL
)
5051 font
.MacCreateThemeFont( kThemeViewsFont
);
5056 if ( InReportView() )
5058 CreateHeaderWindow();
5060 #ifdef __WXMAC_CARBON__
5064 font
.MacCreateThemeFont( kThemeSmallSystemFont
);
5065 m_headerWin
->SetFont( font
);
5066 CalculateAndSetHeaderHeight();
5070 if ( HasFlag(wxLC_NO_HEADER
) )
5071 // VZ: why do we create it at all then?
5072 m_headerWin
->Show( false );
5075 SetInitialSize(size
);
5080 void wxGenericListCtrl::SetSingleStyle( long style
, bool add
)
5082 wxASSERT_MSG( !(style
& wxLC_VIRTUAL
),
5083 _T("wxLC_VIRTUAL can't be [un]set") );
5085 long flag
= GetWindowStyle();
5089 if (style
& wxLC_MASK_TYPE
)
5090 flag
&= ~(wxLC_MASK_TYPE
| wxLC_VIRTUAL
);
5091 if (style
& wxLC_MASK_ALIGN
)
5092 flag
&= ~wxLC_MASK_ALIGN
;
5093 if (style
& wxLC_MASK_SORT
)
5094 flag
&= ~wxLC_MASK_SORT
;
5102 // some styles can be set without recreating everything (as happens in
5103 // SetWindowStyleFlag() which calls wxListMainWindow::DeleteEverything())
5104 if ( !(style
& ~(wxLC_HRULES
| wxLC_VRULES
)) )
5107 wxWindow::SetWindowStyleFlag(flag
);
5111 SetWindowStyleFlag( flag
);
5115 void wxGenericListCtrl::SetWindowStyleFlag( long flag
)
5119 m_mainWin
->DeleteEverything();
5121 // has the header visibility changed?
5122 bool hasHeader
= HasHeader();
5123 bool willHaveHeader
= (flag
& wxLC_REPORT
) && !(flag
& wxLC_NO_HEADER
);
5125 if ( hasHeader
!= willHaveHeader
)
5132 // don't delete, just hide, as we can reuse it later
5133 m_headerWin
->Show(false);
5135 //else: nothing to do
5137 else // must show header
5141 CreateHeaderWindow();
5143 else // already have it, just show
5145 m_headerWin
->Show( true );
5149 ResizeReportView(willHaveHeader
);
5153 wxWindow::SetWindowStyleFlag( flag
);
5156 bool wxGenericListCtrl::GetColumn(int col
, wxListItem
&item
) const
5158 m_mainWin
->GetColumn( col
, item
);
5162 bool wxGenericListCtrl::SetColumn( int col
, wxListItem
& item
)
5164 m_mainWin
->SetColumn( col
, item
);
5168 int wxGenericListCtrl::GetColumnWidth( int col
) const
5170 return m_mainWin
->GetColumnWidth( col
);
5173 bool wxGenericListCtrl::SetColumnWidth( int col
, int width
)
5175 m_mainWin
->SetColumnWidth( col
, width
);
5179 int wxGenericListCtrl::GetCountPerPage() const
5181 return m_mainWin
->GetCountPerPage(); // different from Windows ?
5184 bool wxGenericListCtrl::GetItem( wxListItem
&info
) const
5186 m_mainWin
->GetItem( info
);
5190 bool wxGenericListCtrl::SetItem( wxListItem
&info
)
5192 m_mainWin
->SetItem( info
);
5196 long wxGenericListCtrl::SetItem( long index
, int col
, const wxString
& label
, int imageId
)
5199 info
.m_text
= label
;
5200 info
.m_mask
= wxLIST_MASK_TEXT
;
5201 info
.m_itemId
= index
;
5205 info
.m_image
= imageId
;
5206 info
.m_mask
|= wxLIST_MASK_IMAGE
;
5209 m_mainWin
->SetItem(info
);
5213 int wxGenericListCtrl::GetItemState( long item
, long stateMask
) const
5215 return m_mainWin
->GetItemState( item
, stateMask
);
5218 bool wxGenericListCtrl::SetItemState( long item
, long state
, long stateMask
)
5220 m_mainWin
->SetItemState( item
, state
, stateMask
);
5225 wxGenericListCtrl::SetItemImage( long item
, int image
, int WXUNUSED(selImage
) )
5227 return SetItemColumnImage(item
, 0, image
);
5231 wxGenericListCtrl::SetItemColumnImage( long item
, long column
, int image
)
5234 info
.m_image
= image
;
5235 info
.m_mask
= wxLIST_MASK_IMAGE
;
5236 info
.m_itemId
= item
;
5237 info
.m_col
= column
;
5238 m_mainWin
->SetItem( info
);
5242 wxString
wxGenericListCtrl::GetItemText( long item
) const
5244 return m_mainWin
->GetItemText(item
);
5247 void wxGenericListCtrl::SetItemText( long item
, const wxString
& str
)
5249 m_mainWin
->SetItemText(item
, str
);
5252 wxUIntPtr
wxGenericListCtrl::GetItemData( long item
) const
5255 info
.m_mask
= wxLIST_MASK_DATA
;
5256 info
.m_itemId
= item
;
5257 m_mainWin
->GetItem( info
);
5261 bool wxGenericListCtrl::SetItemPtrData( long item
, wxUIntPtr data
)
5264 info
.m_mask
= wxLIST_MASK_DATA
;
5265 info
.m_itemId
= item
;
5267 m_mainWin
->SetItem( info
);
5272 bool wxGenericListCtrl::SetItemData(long item
, long data
)
5274 return SetItemPtrData(item
, data
);
5278 wxRect
wxGenericListCtrl::GetViewRect() const
5280 return m_mainWin
->GetViewRect();
5283 bool wxGenericListCtrl::GetItemRect( long item
, wxRect
&rect
, int WXUNUSED(code
) ) const
5285 m_mainWin
->GetItemRect( item
, rect
);
5286 if ( m_mainWin
->HasHeader() )
5287 rect
.y
+= m_headerHeight
+ 1;
5291 bool wxGenericListCtrl::GetItemPosition( long item
, wxPoint
& pos
) const
5293 m_mainWin
->GetItemPosition( item
, pos
);
5297 bool wxGenericListCtrl::SetItemPosition( long WXUNUSED(item
), const wxPoint
& WXUNUSED(pos
) )
5302 int wxGenericListCtrl::GetItemCount() const
5304 return m_mainWin
->GetItemCount();
5307 int wxGenericListCtrl::GetColumnCount() const
5309 return m_mainWin
->GetColumnCount();
5312 void wxGenericListCtrl::SetItemSpacing( int spacing
, bool isSmall
)
5314 m_mainWin
->SetItemSpacing( spacing
, isSmall
);
5317 wxSize
wxGenericListCtrl::GetItemSpacing() const
5319 const int spacing
= m_mainWin
->GetItemSpacing(HasFlag(wxLC_SMALL_ICON
));
5321 return wxSize(spacing
, spacing
);
5324 void wxGenericListCtrl::OnDrawItem(int WXUNUSED(item
), wxDC
* WXUNUSED(dc
), const wxRect
& WXUNUSED(rect
), const wxRect
& WXUNUSED(rectHL
), bool WXUNUSED(highlighted
))
5326 // do nothing here, this is just a stub
5329 void wxGenericListCtrl::SetItemTextColour( long item
, const wxColour
&col
)
5332 info
.m_itemId
= item
;
5333 info
.SetTextColour( col
);
5334 m_mainWin
->SetItem( info
);
5337 wxColour
wxGenericListCtrl::GetItemTextColour( long item
) const
5340 info
.m_itemId
= item
;
5341 m_mainWin
->GetItem( info
);
5342 return info
.GetTextColour();
5345 void wxGenericListCtrl::SetItemBackgroundColour( long item
, const wxColour
&col
)
5348 info
.m_itemId
= item
;
5349 info
.SetBackgroundColour( col
);
5350 m_mainWin
->SetItem( info
);
5353 wxColour
wxGenericListCtrl::GetItemBackgroundColour( long item
) const
5356 info
.m_itemId
= item
;
5357 m_mainWin
->GetItem( info
);
5358 return info
.GetBackgroundColour();
5361 int wxGenericListCtrl::GetScrollPos( int orient
) const
5363 return m_mainWin
->GetScrollPos( orient
);
5366 void wxGenericListCtrl::SetScrollPos( int orient
, int pos
, bool refresh
)
5368 m_mainWin
->SetScrollPos( orient
, pos
, refresh
);
5371 void wxGenericListCtrl::SetItemFont( long item
, const wxFont
&f
)
5374 info
.m_itemId
= item
;
5376 m_mainWin
->SetItem( info
);
5379 wxFont
wxGenericListCtrl::GetItemFont( long item
) const
5382 info
.m_itemId
= item
;
5383 m_mainWin
->GetItem( info
);
5384 return info
.GetFont();
5387 int wxGenericListCtrl::GetSelectedItemCount() const
5389 return m_mainWin
->GetSelectedItemCount();
5392 wxColour
wxGenericListCtrl::GetTextColour() const
5394 return GetForegroundColour();
5397 void wxGenericListCtrl::SetTextColour(const wxColour
& col
)
5399 SetForegroundColour(col
);
5402 long wxGenericListCtrl::GetTopItem() const
5405 m_mainWin
->GetVisibleLinesRange(&top
, NULL
);
5409 void wxGenericListCtrl::GetVisibleLines(long* first
, long* last
)
5413 m_mainWin
->GetVisibleLinesRange(&from
, &to
);
5415 if (first
) *first
= (long)from
;
5416 if (last
) *last
= (long)to
;
5419 long wxGenericListCtrl::GetNextItem( long item
, int geom
, int state
) const
5421 return m_mainWin
->GetNextItem( item
, geom
, state
);
5424 wxImageList
*wxGenericListCtrl::GetImageList(int which
) const
5426 if (which
== wxIMAGE_LIST_NORMAL
)
5427 return m_imageListNormal
;
5428 else if (which
== wxIMAGE_LIST_SMALL
)
5429 return m_imageListSmall
;
5430 else if (which
== wxIMAGE_LIST_STATE
)
5431 return m_imageListState
;
5433 return (wxImageList
*) NULL
;
5436 void wxGenericListCtrl::SetImageList( wxImageList
*imageList
, int which
)
5438 if ( which
== wxIMAGE_LIST_NORMAL
)
5440 if (m_ownsImageListNormal
)
5441 delete m_imageListNormal
;
5442 m_imageListNormal
= imageList
;
5443 m_ownsImageListNormal
= false;
5445 else if ( which
== wxIMAGE_LIST_SMALL
)
5447 if (m_ownsImageListSmall
)
5448 delete m_imageListSmall
;
5449 m_imageListSmall
= imageList
;
5450 m_ownsImageListSmall
= false;
5452 else if ( which
== wxIMAGE_LIST_STATE
)
5454 if (m_ownsImageListState
)
5455 delete m_imageListState
;
5456 m_imageListState
= imageList
;
5457 m_ownsImageListState
= false;
5460 m_mainWin
->SetImageList( imageList
, which
);
5463 void wxGenericListCtrl::AssignImageList(wxImageList
*imageList
, int which
)
5465 SetImageList(imageList
, which
);
5466 if ( which
== wxIMAGE_LIST_NORMAL
)
5467 m_ownsImageListNormal
= true;
5468 else if ( which
== wxIMAGE_LIST_SMALL
)
5469 m_ownsImageListSmall
= true;
5470 else if ( which
== wxIMAGE_LIST_STATE
)
5471 m_ownsImageListState
= true;
5474 bool wxGenericListCtrl::Arrange( int WXUNUSED(flag
) )
5479 bool wxGenericListCtrl::DeleteItem( long item
)
5481 m_mainWin
->DeleteItem( item
);
5485 bool wxGenericListCtrl::DeleteAllItems()
5487 m_mainWin
->DeleteAllItems();
5491 bool wxGenericListCtrl::DeleteAllColumns()
5493 size_t count
= m_mainWin
->m_columns
.GetCount();
5494 for ( size_t n
= 0; n
< count
; n
++ )
5499 void wxGenericListCtrl::ClearAll()
5501 m_mainWin
->DeleteEverything();
5504 bool wxGenericListCtrl::DeleteColumn( int col
)
5506 m_mainWin
->DeleteColumn( col
);
5508 // if we don't have the header any longer, we need to relayout the window
5509 if ( !GetColumnCount() )
5510 ResizeReportView(false /* no header */);
5514 wxTextCtrl
*wxGenericListCtrl::EditLabel(long item
,
5515 wxClassInfo
* textControlClass
)
5517 return m_mainWin
->EditLabel( item
, textControlClass
);
5520 wxTextCtrl
*wxGenericListCtrl::GetEditControl() const
5522 return m_mainWin
->GetEditControl();
5525 bool wxGenericListCtrl::EnsureVisible( long item
)
5527 m_mainWin
->EnsureVisible( item
);
5531 long wxGenericListCtrl::FindItem( long start
, const wxString
& str
, bool partial
)
5533 return m_mainWin
->FindItem( start
, str
, partial
);
5536 long wxGenericListCtrl::FindItem( long start
, wxUIntPtr data
)
5538 return m_mainWin
->FindItem( start
, data
);
5541 long wxGenericListCtrl::FindItem( long WXUNUSED(start
), const wxPoint
& pt
,
5542 int WXUNUSED(direction
))
5544 return m_mainWin
->FindItem( pt
);
5547 // TODO: sub item hit testing
5548 long wxGenericListCtrl::HitTest(const wxPoint
& point
, int& flags
, long *) const
5550 return m_mainWin
->HitTest( (int)point
.x
, (int)point
.y
, flags
);
5553 long wxGenericListCtrl::InsertItem( wxListItem
& info
)
5555 m_mainWin
->InsertItem( info
);
5556 return info
.m_itemId
;
5559 long wxGenericListCtrl::InsertItem( long index
, const wxString
&label
)
5562 info
.m_text
= label
;
5563 info
.m_mask
= wxLIST_MASK_TEXT
;
5564 info
.m_itemId
= index
;
5565 return InsertItem( info
);
5568 long wxGenericListCtrl::InsertItem( long index
, int imageIndex
)
5571 info
.m_mask
= wxLIST_MASK_IMAGE
;
5572 info
.m_image
= imageIndex
;
5573 info
.m_itemId
= index
;
5574 return InsertItem( info
);
5577 long wxGenericListCtrl::InsertItem( long index
, const wxString
&label
, int imageIndex
)
5580 info
.m_text
= label
;
5581 info
.m_image
= imageIndex
;
5582 info
.m_mask
= wxLIST_MASK_TEXT
| wxLIST_MASK_IMAGE
;
5583 info
.m_itemId
= index
;
5584 return InsertItem( info
);
5587 long wxGenericListCtrl::InsertColumn( long col
, wxListItem
&item
)
5589 wxCHECK_MSG( m_headerWin
, -1, _T("can't add column in non report mode") );
5591 m_mainWin
->InsertColumn( col
, item
);
5593 // if we hadn't had a header before but have one now
5594 // then we need to relayout the window
5595 if ( GetColumnCount() == 1 && m_mainWin
->HasHeader() )
5596 ResizeReportView(true /* have header */);
5598 m_headerWin
->Refresh();
5603 long wxGenericListCtrl::InsertColumn( long col
, const wxString
&heading
,
5604 int format
, int width
)
5607 item
.m_mask
= wxLIST_MASK_TEXT
| wxLIST_MASK_FORMAT
;
5608 item
.m_text
= heading
;
5611 item
.m_mask
|= wxLIST_MASK_WIDTH
;
5612 item
.m_width
= width
;
5615 item
.m_format
= format
;
5617 return InsertColumn( col
, item
);
5620 bool wxGenericListCtrl::ScrollList( int WXUNUSED(dx
), int WXUNUSED(dy
) )
5626 // fn is a function which takes 3 long arguments: item1, item2, data.
5627 // item1 is the long data associated with a first item (NOT the index).
5628 // item2 is the long data associated with a second item (NOT the index).
5629 // data is the same value as passed to SortItems.
5630 // The return value is a negative number if the first item should precede the second
5631 // item, a positive number of the second item should precede the first,
5632 // or zero if the two items are equivalent.
5633 // data is arbitrary data to be passed to the sort function.
5635 bool wxGenericListCtrl::SortItems( MuleListCtrlCompare fn
, long data
)
5637 m_mainWin
->SortItems( fn
, data
);
5641 // ----------------------------------------------------------------------------
5643 // ----------------------------------------------------------------------------
5645 void wxGenericListCtrl::OnSize(wxSizeEvent
& WXUNUSED(event
))
5650 ResizeReportView(m_mainWin
->HasHeader());
5651 m_mainWin
->RecalculatePositions();
5654 void wxGenericListCtrl::ResizeReportView(bool showHeader
)
5657 GetClientSize( &cw
, &ch
);
5661 m_headerWin
->SetSize( 0, 0, cw
, m_headerHeight
);
5662 if(ch
> m_headerHeight
)
5663 m_mainWin
->SetSize( 0, m_headerHeight
+ 1,
5664 cw
, ch
- m_headerHeight
- 1 );
5666 m_mainWin
->SetSize( 0, m_headerHeight
+ 1,
5669 else // no header window
5671 m_mainWin
->SetSize( 0, 0, cw
, ch
);
5675 void wxGenericListCtrl::OnInternalIdle()
5677 wxWindow::OnInternalIdle();
5679 // do it only if needed
5680 if ( !m_mainWin
->m_dirty
)
5683 m_mainWin
->RecalculatePositions();
5686 // ----------------------------------------------------------------------------
5688 // ----------------------------------------------------------------------------
5690 bool wxGenericListCtrl::SetBackgroundColour( const wxColour
&colour
)
5694 m_mainWin
->SetBackgroundColour( colour
);
5695 m_mainWin
->m_dirty
= true;
5701 bool wxGenericListCtrl::SetForegroundColour( const wxColour
&colour
)
5703 if ( !wxWindow::SetForegroundColour( colour
) )
5708 m_mainWin
->SetForegroundColour( colour
);
5709 m_mainWin
->m_dirty
= true;
5713 m_headerWin
->SetForegroundColour( colour
);
5718 bool wxGenericListCtrl::SetFont( const wxFont
&font
)
5720 if ( !wxWindow::SetFont( font
) )
5725 m_mainWin
->SetFont( font
);
5726 m_mainWin
->m_dirty
= true;
5731 m_headerWin
->SetFont( font
);
5732 CalculateAndSetHeaderHeight();
5742 wxGenericListCtrl::GetClassDefaultAttributes(wxWindowVariant variant
)
5745 // Use the same color scheme as wxListBox
5746 return wxListBox::GetClassDefaultAttributes(variant
);
5748 wxUnusedVar(variant
);
5749 wxVisualAttributes attr
;
5750 attr
.colFg
= wxSystemSettings::GetColour(wxSYS_COLOUR_LISTBOXTEXT
);
5751 attr
.colBg
= wxSystemSettings::GetColour(wxSYS_COLOUR_LISTBOX
);
5752 attr
.font
= wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT
);
5757 // ----------------------------------------------------------------------------
5758 // methods forwarded to m_mainWin
5759 // ----------------------------------------------------------------------------
5761 #if wxUSE_DRAG_AND_DROP
5763 void wxGenericListCtrl::SetDropTarget( wxDropTarget
*dropTarget
)
5765 m_mainWin
->SetDropTarget( dropTarget
);
5768 wxDropTarget
*wxGenericListCtrl::GetDropTarget() const
5770 return m_mainWin
->GetDropTarget();
5775 bool wxGenericListCtrl::SetCursor( const wxCursor
&cursor
)
5777 return m_mainWin
? m_mainWin
->wxWindow::SetCursor(cursor
) : false;
5780 wxColour
wxGenericListCtrl::GetBackgroundColour() const
5782 return m_mainWin
? m_mainWin
->GetBackgroundColour() : wxColour();
5785 wxColour
wxGenericListCtrl::GetForegroundColour() const
5787 return m_mainWin
? m_mainWin
->GetForegroundColour() : wxColour();
5790 bool wxGenericListCtrl::DoPopupMenu( wxMenu
*menu
, int x
, int y
)
5793 return m_mainWin
->PopupMenu( menu
, x
, y
);
5799 void wxGenericListCtrl::SetFocus()
5801 // The test in window.cpp fails as we are a composite
5802 // window, so it checks against "this", but not m_mainWin.
5803 if ( DoFindFocus() != this )
5804 m_mainWin
->SetFocus();
5807 wxSize
wxGenericListCtrl::DoGetBestSize() const
5809 // Something is better than nothing...
5810 // 100x80 is what the MSW version will get from the default
5811 // wxControl::DoGetBestSize
5812 return wxSize(100, 80);
5815 // ----------------------------------------------------------------------------
5816 // virtual list control support
5817 // ----------------------------------------------------------------------------
5819 wxString
wxGenericListCtrl::OnGetItemText(long WXUNUSED(item
), long WXUNUSED(col
)) const
5821 // this is a pure virtual function, in fact - which is not really pure
5822 // because the controls which are not virtual don't need to implement it
5823 wxFAIL_MSG( _T("wxGenericListCtrl::OnGetItemText not supposed to be called") );
5825 return wxEmptyString
;
5828 int wxGenericListCtrl::OnGetItemImage(long WXUNUSED(item
)) const
5830 wxCHECK_MSG(!GetImageList(wxIMAGE_LIST_SMALL
),
5832 wxT("List control has an image list, OnGetItemImage or OnGetItemColumnImage should be overridden."));
5836 int wxGenericListCtrl::OnGetItemColumnImage(long item
, long column
) const
5839 return OnGetItemImage(item
);
5845 wxGenericListCtrl::OnGetItemAttr(long WXUNUSED_UNLESS_DEBUG(item
)) const
5847 wxASSERT_MSG( item
>= 0 && item
< GetItemCount(),
5848 _T("invalid item index in OnGetItemAttr()") );
5850 // no attributes by default
5854 void wxGenericListCtrl::SetItemCount(long count
)
5856 wxASSERT_MSG( IsVirtual(), _T("this is for virtual controls only") );
5858 m_mainWin
->SetItemCount(count
);
5861 void wxGenericListCtrl::RefreshItem(long item
)
5863 m_mainWin
->RefreshLine(item
);
5866 void wxGenericListCtrl::RefreshItems(long itemFrom
, long itemTo
)
5868 m_mainWin
->RefreshLines(itemFrom
, itemTo
);
5871 // Generic wxListCtrl is more or less a container for two other
5872 // windows which drawings are done upon. These are namely
5873 // 'm_headerWin' and 'm_mainWin'.
5874 // Here we override 'virtual wxWindow::Refresh()' to mimic the
5875 // behaviour wxListCtrl has under wxMSW.
5877 void wxGenericListCtrl::Refresh(bool eraseBackground
, const wxRect
*rect
)
5881 // The easy case, no rectangle specified.
5883 m_headerWin
->Refresh(eraseBackground
);
5886 m_mainWin
->Refresh(eraseBackground
);
5890 // Refresh the header window
5893 wxRect rectHeader
= m_headerWin
->GetRect();
5894 rectHeader
.Intersect(*rect
);
5895 if (rectHeader
.GetWidth() && rectHeader
.GetHeight())
5898 m_headerWin
->GetPosition(&x
, &y
);
5899 rectHeader
.Offset(-x
, -y
);
5900 m_headerWin
->Refresh(eraseBackground
, &rectHeader
);
5904 // Refresh the main window
5907 wxRect rectMain
= m_mainWin
->GetRect();
5908 rectMain
.Intersect(*rect
);
5909 if (rectMain
.GetWidth() && rectMain
.GetHeight())
5912 m_mainWin
->GetPosition(&x
, &y
);
5913 rectMain
.Offset(-x
, -y
);
5914 m_mainWin
->Refresh(eraseBackground
, &rectMain
);
5920 void wxGenericListCtrl::Freeze()
5922 m_mainWin
->Freeze();
5925 void wxGenericListCtrl::Thaw()
5930 } // namespace MuleExtern
5932 #endif // wxUSE_LISTCTRL