1 /////////////////////////////////////////////////////////////////////////////
2 // Name: generic/listctrl.cpp
3 // Purpose: generic implementation of wxListCtrl
4 // Author: Robert Roebling
5 // Vadim Zeitlin (virtual list control support)
7 // Copyright: (c) 1998 Robert Roebling
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
14 1. we need to implement searching/sorting for virtual controls somehow
15 ?2. when changing selection the lines are refreshed twice
18 // ============================================================================
20 // ============================================================================
22 // ----------------------------------------------------------------------------
24 // ----------------------------------------------------------------------------
27 #pragma implementation "listctrl.h"
28 #pragma implementation "listctrlbase.h"
31 // For compilers that support precompilation, includes "wx.h".
32 #include "wx/wxprec.h"
43 #include "wx/dynarray.h"
45 #include "wx/dcscreen.h"
47 #include "wx/textctrl.h"
50 // under Win32 we always use the native version and also may use the generic
51 // one, however some things should be done only if we use only the generic
53 #if defined(__WIN32__) && !defined(__WXUNIVERSAL__)
54 #define HAVE_NATIVE_LISTCTRL
57 // if we have the native control, wx/listctrl.h declares it and not this one
58 #ifdef HAVE_NATIVE_LISTCTRL
59 #include "wx/generic/listctrl.h"
60 #else // !HAVE_NATIVE_LISTCTRL
61 #include "wx/listctrl.h"
63 // if we have a native version, its implementation file does all this
64 IMPLEMENT_DYNAMIC_CLASS(wxListItem
, wxObject
)
65 IMPLEMENT_DYNAMIC_CLASS(wxListView
, wxListCtrl
)
66 IMPLEMENT_DYNAMIC_CLASS(wxListEvent
, wxNotifyEvent
)
68 IMPLEMENT_DYNAMIC_CLASS(wxListCtrl
, wxGenericListCtrl
)
69 #endif // HAVE_NATIVE_LISTCTRL/!HAVE_NATIVE_LISTCTRL
71 #if defined(__WXGTK__)
73 #include "wx/gtk/win_gtk.h"
76 #include "wx/selstore.h"
78 // ----------------------------------------------------------------------------
80 // ----------------------------------------------------------------------------
82 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_BEGIN_DRAG
)
83 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_BEGIN_RDRAG
)
84 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_BEGIN_LABEL_EDIT
)
85 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_END_LABEL_EDIT
)
86 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_DELETE_ITEM
)
87 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_DELETE_ALL_ITEMS
)
88 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_GET_INFO
)
89 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_SET_INFO
)
90 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_ITEM_SELECTED
)
91 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_ITEM_DESELECTED
)
92 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_KEY_DOWN
)
93 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_INSERT_ITEM
)
94 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_COL_CLICK
)
95 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_COL_RIGHT_CLICK
)
96 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_COL_BEGIN_DRAG
)
97 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_COL_DRAGGING
)
98 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_COL_END_DRAG
)
99 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_ITEM_RIGHT_CLICK
)
100 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_ITEM_MIDDLE_CLICK
)
101 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_ITEM_ACTIVATED
)
102 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_ITEM_FOCUSED
)
103 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_CACHE_HINT
)
105 // ----------------------------------------------------------------------------
107 // ----------------------------------------------------------------------------
109 // the height of the header window (FIXME: should depend on its font!)
110 static const int HEADER_HEIGHT
= 23;
112 // the scrollbar units
113 static const int SCROLL_UNIT_X
= 15;
114 static const int SCROLL_UNIT_Y
= 15;
116 // the spacing between the lines (in report mode)
117 static const int LINE_SPACING
= 0;
119 // extra margins around the text label
120 static const int EXTRA_WIDTH
= 3;
121 static const int EXTRA_HEIGHT
= 4;
123 // offset for the header window
124 static const int HEADER_OFFSET_X
= 1;
125 static const int HEADER_OFFSET_Y
= 1;
127 // when autosizing the columns, add some slack
128 static const int AUTOSIZE_COL_MARGIN
= 10;
130 // default and minimal widths for the header columns
131 static const int WIDTH_COL_DEFAULT
= 80;
132 static const int WIDTH_COL_MIN
= 10;
134 // the space between the image and the text in the report mode
135 static const int IMAGE_MARGIN_IN_REPORT_MODE
= 5;
137 // ============================================================================
139 // ============================================================================
141 //-----------------------------------------------------------------------------
142 // wxListItemData (internal)
143 //-----------------------------------------------------------------------------
145 class WXDLLEXPORT wxListItemData
148 wxListItemData(wxListMainWindow
*owner
);
151 void SetItem( const wxListItem
&info
);
152 void SetImage( int image
) { m_image
= image
; }
153 void SetData( long data
) { m_data
= data
; }
154 void SetPosition( int x
, int y
);
155 void SetSize( int width
, int height
);
157 bool HasText() const { return !m_text
.empty(); }
158 const wxString
& GetText() const { return m_text
; }
159 void SetText(const wxString
& text
) { m_text
= text
; }
161 // we can't use empty string for measuring the string width/height, so
162 // always return something
163 wxString
GetTextForMeasuring() const
165 wxString s
= GetText();
172 bool IsHit( int x
, int y
) const;
176 int GetWidth() const;
177 int GetHeight() const;
179 int GetImage() const { return m_image
; }
180 bool HasImage() const { return GetImage() != -1; }
182 void GetItem( wxListItem
&info
) const;
184 void SetAttr(wxListItemAttr
*attr
) { m_attr
= attr
; }
185 wxListItemAttr
*GetAttr() const { return m_attr
; }
188 // the item image or -1
191 // user data associated with the item
194 // the item coordinates are not used in report mode, instead this pointer
195 // is NULL and the owner window is used to retrieve the item position and
199 // the list ctrl we are in
200 wxListMainWindow
*m_owner
;
202 // custom attributes or NULL
203 wxListItemAttr
*m_attr
;
206 // common part of all ctors
212 //-----------------------------------------------------------------------------
213 // wxListHeaderData (internal)
214 //-----------------------------------------------------------------------------
216 class WXDLLEXPORT wxListHeaderData
: public wxObject
220 wxListHeaderData( const wxListItem
&info
);
221 void SetItem( const wxListItem
&item
);
222 void SetPosition( int x
, int y
);
223 void SetWidth( int w
);
224 void SetFormat( int format
);
225 void SetHeight( int h
);
226 bool HasImage() const;
228 bool HasText() const { return !m_text
.empty(); }
229 const wxString
& GetText() const { return m_text
; }
230 void SetText(const wxString
& text
) { m_text
= text
; }
232 void GetItem( wxListItem
&item
);
234 bool IsHit( int x
, int y
) const;
235 int GetImage() const;
236 int GetWidth() const;
237 int GetFormat() const;
253 //-----------------------------------------------------------------------------
254 // wxListLineData (internal)
255 //-----------------------------------------------------------------------------
257 WX_DECLARE_LIST(wxListItemData
, wxListItemDataList
);
258 #include "wx/listimpl.cpp"
259 WX_DEFINE_LIST(wxListItemDataList
);
261 class WXDLLEXPORT wxListLineData
264 // the list of subitems: only may have more than one item in report mode
265 wxListItemDataList m_items
;
267 // this is not used in report view
279 // the part to be highlighted
280 wxRect m_rectHighlight
;
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
);
292 ~wxListLineData() { delete m_gi
; }
294 // are we in report mode?
295 inline bool InReportView() const;
297 // are we in virtual report mode?
298 inline bool IsVirtual() const;
300 // these 2 methods shouldn't be called for report view controls, in that
301 // case we determine our position/size ourselves
303 // calculate the size of the line
304 void CalculateSize( wxDC
*dc
, int spacing
);
306 // remember the position this line appears at
307 void SetPosition( int x
, int y
, int window_width
, int spacing
);
311 void SetImage( int image
) { SetImage(0, image
); }
312 int GetImage() const { return GetImage(0); }
313 bool HasImage() const { return GetImage() != -1; }
314 bool HasText() const { return !GetText(0).empty(); }
316 void SetItem( int index
, const wxListItem
&info
);
317 void GetItem( int index
, wxListItem
&info
);
319 wxString
GetText(int index
) const;
320 void SetText( int index
, const wxString s
);
322 wxListItemAttr
*GetAttr() const;
323 void SetAttr(wxListItemAttr
*attr
);
325 // return true if the highlighting really changed
326 bool Highlight( bool on
);
328 void ReverseHighlight();
330 bool IsHighlighted() const
332 wxASSERT_MSG( !IsVirtual(), _T("unexpected call to IsHighlighted") );
334 return m_highlighted
;
337 // draw the line on the given DC in icon/list mode
338 void Draw( wxDC
*dc
);
340 // the same in report mode
341 void DrawInReportMode( wxDC
*dc
,
343 const wxRect
& rectHL
,
347 // set the line to contain num items (only can be > 1 in report mode)
348 void InitItems( int num
);
350 // get the mode (i.e. style) of the list control
351 inline int GetMode() const;
353 // prepare the DC for drawing with these item's attributes, return true if
354 // we need to draw the items background to highlight it, false otherwise
355 bool SetAttributes(wxDC
*dc
,
356 const wxListItemAttr
*attr
,
359 // draw the text on the DC with the correct justification; also add an
360 // ellipsis if the text is too large to fit in the current width
361 void DrawTextFormatted(wxDC
*dc
, const wxString
&text
, int col
, int x
, int y
, int width
);
363 // these are only used by GetImage/SetImage above, we don't support images
364 // with subitems at the public API level yet
365 void SetImage( int index
, int image
);
366 int GetImage( int index
) const;
369 WX_DECLARE_EXPORTED_OBJARRAY(wxListLineData
, wxListLineDataArray
);
370 #include "wx/arrimpl.cpp"
371 WX_DEFINE_OBJARRAY(wxListLineDataArray
);
373 //-----------------------------------------------------------------------------
374 // wxListHeaderWindow (internal)
375 //-----------------------------------------------------------------------------
377 class WXDLLEXPORT wxListHeaderWindow
: public wxWindow
380 wxListMainWindow
*m_owner
;
381 wxCursor
*m_currentCursor
;
382 wxCursor
*m_resizeCursor
;
385 // column being resized or -1
388 // divider line position in logical (unscrolled) coords
391 // minimal position beyond which the divider line can't be dragged in
396 wxListHeaderWindow();
398 wxListHeaderWindow( wxWindow
*win
,
400 wxListMainWindow
*owner
,
401 const wxPoint
&pos
= wxDefaultPosition
,
402 const wxSize
&size
= wxDefaultSize
,
404 const wxString
&name
= wxT("wxlistctrlcolumntitles") );
406 virtual ~wxListHeaderWindow();
408 void DoDrawRect( wxDC
*dc
, int x
, int y
, int w
, int h
);
410 void AdjustDC(wxDC
& dc
);
412 void OnPaint( wxPaintEvent
&event
);
413 void OnMouse( wxMouseEvent
&event
);
414 void OnSetFocus( wxFocusEvent
&event
);
420 // common part of all ctors
423 // generate and process the list event of the given type, return true if
424 // it wasn't vetoed, i.e. if we should proceed
425 bool SendListEvent(wxEventType type
, wxPoint pos
);
427 DECLARE_DYNAMIC_CLASS(wxListHeaderWindow
)
428 DECLARE_EVENT_TABLE()
431 //-----------------------------------------------------------------------------
432 // wxListRenameTimer (internal)
433 //-----------------------------------------------------------------------------
435 class WXDLLEXPORT wxListRenameTimer
: public wxTimer
438 wxListMainWindow
*m_owner
;
441 wxListRenameTimer( wxListMainWindow
*owner
);
445 //-----------------------------------------------------------------------------
446 // wxListTextCtrl (internal)
447 //-----------------------------------------------------------------------------
449 class WXDLLEXPORT wxListTextCtrl
: public wxTextCtrl
452 wxListTextCtrl(wxListMainWindow
*owner
, size_t itemEdit
);
455 void OnChar( wxKeyEvent
&event
);
456 void OnKeyUp( wxKeyEvent
&event
);
457 void OnKillFocus( wxFocusEvent
&event
);
459 bool AcceptChanges();
463 wxListMainWindow
*m_owner
;
464 wxString m_startValue
;
468 DECLARE_EVENT_TABLE()
471 //-----------------------------------------------------------------------------
472 // wxListMainWindow (internal)
473 //-----------------------------------------------------------------------------
475 WX_DECLARE_LIST(wxListHeaderData
, wxListHeaderDataList
);
476 #include "wx/listimpl.cpp"
477 WX_DEFINE_LIST(wxListHeaderDataList
);
479 class WXDLLEXPORT wxListMainWindow
: public wxScrolledWindow
483 wxListMainWindow( wxWindow
*parent
,
485 const wxPoint
& pos
= wxDefaultPosition
,
486 const wxSize
& size
= wxDefaultSize
,
488 const wxString
&name
= _T("listctrlmainwindow") );
490 virtual ~wxListMainWindow();
492 bool HasFlag(int flag
) const { return m_parent
->HasFlag(flag
); }
494 // return true if this is a virtual list control
495 bool IsVirtual() const { return HasFlag(wxLC_VIRTUAL
); }
497 // return true if the control is in report mode
498 bool InReportView() const { return HasFlag(wxLC_REPORT
); }
500 // return true if we are in single selection mode, false if multi sel
501 bool IsSingleSel() const { return HasFlag(wxLC_SINGLE_SEL
); }
503 // do we have a header window?
504 bool HasHeader() const
505 { return HasFlag(wxLC_REPORT
) && !HasFlag(wxLC_NO_HEADER
); }
507 void HighlightAll( bool on
);
509 // all these functions only do something if the line is currently visible
511 // change the line "selected" state, return TRUE if it really changed
512 bool HighlightLine( size_t line
, bool highlight
= TRUE
);
514 // as HighlightLine() but do it for the range of lines: this is incredibly
515 // more efficient for virtual list controls!
517 // NB: unlike HighlightLine() this one does refresh the lines on screen
518 void HighlightLines( size_t lineFrom
, size_t lineTo
, bool on
= TRUE
);
520 // toggle the line state and refresh it
521 void ReverseHighlight( size_t line
)
522 { HighlightLine(line
, !IsHighlighted(line
)); RefreshLine(line
); }
524 // return true if the line is highlighted
525 bool IsHighlighted(size_t line
) const;
527 // refresh one or several lines at once
528 void RefreshLine( size_t line
);
529 void RefreshLines( size_t lineFrom
, size_t lineTo
);
531 // refresh all selected items
532 void RefreshSelected();
534 // refresh all lines below the given one: the difference with
535 // RefreshLines() is that the index here might not be a valid one (happens
536 // when the last line is deleted)
537 void RefreshAfter( size_t lineFrom
);
539 // the methods which are forwarded to wxListLineData itself in list/icon
540 // modes but are here because the lines don't store their positions in the
543 // get the bound rect for the entire line
544 wxRect
GetLineRect(size_t line
) const;
546 // get the bound rect of the label
547 wxRect
GetLineLabelRect(size_t line
) const;
549 // get the bound rect of the items icon (only may be called if we do have
551 wxRect
GetLineIconRect(size_t line
) const;
553 // get the rect to be highlighted when the item has focus
554 wxRect
GetLineHighlightRect(size_t line
) const;
556 // get the size of the total line rect
557 wxSize
GetLineSize(size_t line
) const
558 { return GetLineRect(line
).GetSize(); }
560 // return the hit code for the corresponding position (in this line)
561 long HitTestLine(size_t line
, int x
, int y
) const;
563 // bring the selected item into view, scrolling to it if necessary
564 void MoveToItem(size_t item
);
566 // bring the current item into view
567 void MoveToFocus() { MoveToItem(m_current
); }
569 // start editing the label of the given item
570 void EditLabel( long item
);
572 // suspend/resume redrawing the control
578 void OnRenameTimer();
579 bool OnRenameAccept(size_t itemEdit
, const wxString
& value
);
581 void OnMouse( wxMouseEvent
&event
);
583 // called to switch the selection from the current item to newCurrent,
584 void OnArrowChar( size_t newCurrent
, const wxKeyEvent
& event
);
586 void OnChar( wxKeyEvent
&event
);
587 void OnKeyDown( wxKeyEvent
&event
);
588 void OnSetFocus( wxFocusEvent
&event
);
589 void OnKillFocus( wxFocusEvent
&event
);
590 void OnScroll(wxScrollWinEvent
& event
) ;
592 void OnPaint( wxPaintEvent
&event
);
594 void DrawImage( int index
, wxDC
*dc
, int x
, int y
);
595 void GetImageSize( int index
, int &width
, int &height
) const;
596 int GetTextLength( const wxString
&s
) const;
598 void SetImageList( wxImageListType
*imageList
, int which
);
599 void SetItemSpacing( int spacing
, bool isSmall
= FALSE
);
600 int GetItemSpacing( bool isSmall
= FALSE
);
602 void SetColumn( int col
, wxListItem
&item
);
603 void SetColumnWidth( int col
, int width
);
604 void GetColumn( int col
, wxListItem
&item
) const;
605 int GetColumnWidth( int col
) const;
606 int GetColumnCount() const { return m_columns
.GetCount(); }
608 // returns the sum of the heights of all columns
609 int GetHeaderWidth() const;
611 int GetCountPerPage() const;
613 void SetItem( wxListItem
&item
);
614 void GetItem( wxListItem
&item
) const;
615 void SetItemState( long item
, long state
, long stateMask
);
616 int GetItemState( long item
, long stateMask
) const;
617 void GetItemRect( long index
, wxRect
&rect
) const;
618 bool GetItemPosition( long item
, wxPoint
& pos
) const;
619 int GetSelectedItemCount() const;
621 wxString
GetItemText(long item
) const
624 info
.m_itemId
= item
;
629 void SetItemText(long item
, const wxString
& value
)
632 info
.m_mask
= wxLIST_MASK_TEXT
;
633 info
.m_itemId
= item
;
638 // set the scrollbars and update the positions of the items
639 void RecalculatePositions(bool noRefresh
= FALSE
);
641 // refresh the window and the header
644 long GetNextItem( long item
, int geometry
, int state
) const;
645 void DeleteItem( long index
);
646 void DeleteAllItems();
647 void DeleteColumn( int col
);
648 void DeleteEverything();
649 void EnsureVisible( long index
);
650 long FindItem( long start
, const wxString
& str
, bool partial
= FALSE
);
651 long FindItem( long start
, long data
);
652 long HitTest( int x
, int y
, int &flags
);
653 void InsertItem( wxListItem
&item
);
654 void InsertColumn( long col
, wxListItem
&item
);
655 void SortItems( wxListCtrlCompare fn
, long data
);
657 size_t GetItemCount() const;
658 bool IsEmpty() const { return GetItemCount() == 0; }
659 void SetItemCount(long count
);
661 // change the current (== focused) item, send a notification event
662 void ChangeCurrent(size_t current
);
663 void ResetCurrent() { ChangeCurrent((size_t)-1); }
664 bool HasCurrent() const { return m_current
!= (size_t)-1; }
666 // send out a wxListEvent
667 void SendNotify( size_t line
,
669 wxPoint point
= wxDefaultPosition
);
671 // override base class virtual to reset m_lineHeight when the font changes
672 virtual bool SetFont(const wxFont
& font
)
674 if ( !wxScrolledWindow::SetFont(font
) )
682 // these are for wxListLineData usage only
684 // get the backpointer to the list ctrl
685 wxGenericListCtrl
*GetListCtrl() const
687 return wxStaticCast(GetParent(), wxGenericListCtrl
);
690 // get the height of all lines (assuming they all do have the same height)
691 wxCoord
GetLineHeight() const;
693 // get the y position of the given line (only for report view)
694 wxCoord
GetLineY(size_t line
) const;
696 // get the brush to use for the item highlighting
697 wxBrush
*GetHighlightBrush() const
699 return m_hasFocus
? m_highlightBrush
: m_highlightUnfocusedBrush
;
703 // the array of all line objects for a non virtual list control (for the
704 // virtual list control we only ever use m_lines[0])
705 wxListLineDataArray m_lines
;
707 // the list of column objects
708 wxListHeaderDataList m_columns
;
710 // currently focused item or -1
713 // the number of lines per page
716 // this flag is set when something which should result in the window
717 // redrawing happens (i.e. an item was added or deleted, or its appearance
718 // changed) and OnPaint() doesn't redraw the window while it is set which
719 // allows to minimize the number of repaintings when a lot of items are
720 // being added. The real repainting occurs only after the next OnIdle()
724 wxColour
*m_highlightColour
;
727 wxImageListType
*m_small_image_list
;
728 wxImageListType
*m_normal_image_list
;
730 int m_normal_spacing
;
734 wxTimer
*m_renameTimer
;
739 // for double click logic
740 size_t m_lineLastClicked
,
741 m_lineBeforeLastClicked
;
744 // the total count of items in a virtual list control
747 // the object maintaining the items selection state, only used in virtual
749 wxSelectionStore m_selStore
;
751 // common part of all ctors
754 // intiialize m_[xy]Scroll
755 void InitScrolling();
757 // get the line data for the given index
758 wxListLineData
*GetLine(size_t n
) const
760 wxASSERT_MSG( n
!= (size_t)-1, _T("invalid line index") );
764 wxConstCast(this, wxListMainWindow
)->CacheLineData(n
);
772 // get a dummy line which can be used for geometry calculations and such:
773 // you must use GetLine() if you want to really draw the line
774 wxListLineData
*GetDummyLine() const;
776 // cache the line data of the n-th line in m_lines[0]
777 void CacheLineData(size_t line
);
779 // get the range of visible lines
780 void GetVisibleLinesRange(size_t *from
, size_t *to
);
782 // force us to recalculate the range of visible lines
783 void ResetVisibleLinesRange() { m_lineFrom
= (size_t)-1; }
785 // get the colour to be used for drawing the rules
786 wxColour
GetRuleColour() const
791 return wxSystemSettings::GetColour(wxSYS_COLOUR_3DLIGHT
);
796 // initialize the current item if needed
797 void UpdateCurrent();
799 // delete all items but don't refresh: called from dtor
800 void DoDeleteAllItems();
802 // the height of one line using the current font
803 wxCoord m_lineHeight
;
805 // the total header width or 0 if not calculated yet
806 wxCoord m_headerWidth
;
808 // the first and last lines being shown on screen right now (inclusive),
809 // both may be -1 if they must be calculated so never access them directly:
810 // use GetVisibleLinesRange() above instead
814 // the brushes to use for item highlighting when we do/don't have focus
815 wxBrush
*m_highlightBrush
,
816 *m_highlightUnfocusedBrush
;
818 // if this is > 0, the control is frozen and doesn't redraw itself
819 size_t m_freezeCount
;
821 DECLARE_DYNAMIC_CLASS(wxListMainWindow
)
822 DECLARE_EVENT_TABLE()
824 friend class wxGenericListCtrl
;
827 // ============================================================================
829 // ============================================================================
831 //-----------------------------------------------------------------------------
833 //-----------------------------------------------------------------------------
835 wxListItemData::~wxListItemData()
837 // in the virtual list control the attributes are managed by the main
838 // program, so don't delete them
839 if ( !m_owner
->IsVirtual() )
847 void wxListItemData::Init()
855 wxListItemData::wxListItemData(wxListMainWindow
*owner
)
861 if ( owner
->InReportView() )
871 void wxListItemData::SetItem( const wxListItem
&info
)
873 if ( info
.m_mask
& wxLIST_MASK_TEXT
)
874 SetText(info
.m_text
);
875 if ( info
.m_mask
& wxLIST_MASK_IMAGE
)
876 m_image
= info
.m_image
;
877 if ( info
.m_mask
& wxLIST_MASK_DATA
)
878 m_data
= info
.m_data
;
880 if ( info
.HasAttributes() )
883 *m_attr
= *info
.GetAttributes();
885 m_attr
= new wxListItemAttr(*info
.GetAttributes());
893 m_rect
->width
= info
.m_width
;
897 void wxListItemData::SetPosition( int x
, int y
)
899 wxCHECK_RET( m_rect
, _T("unexpected SetPosition() call") );
905 void wxListItemData::SetSize( int width
, int height
)
907 wxCHECK_RET( m_rect
, _T("unexpected SetSize() call") );
910 m_rect
->width
= width
;
912 m_rect
->height
= height
;
915 bool wxListItemData::IsHit( int x
, int y
) const
917 wxCHECK_MSG( m_rect
, FALSE
, _T("can't be called in this mode") );
919 return wxRect(GetX(), GetY(), GetWidth(), GetHeight()).Inside(x
, y
);
922 int wxListItemData::GetX() const
924 wxCHECK_MSG( m_rect
, 0, _T("can't be called in this mode") );
929 int wxListItemData::GetY() const
931 wxCHECK_MSG( m_rect
, 0, _T("can't be called in this mode") );
936 int wxListItemData::GetWidth() const
938 wxCHECK_MSG( m_rect
, 0, _T("can't be called in this mode") );
940 return m_rect
->width
;
943 int wxListItemData::GetHeight() const
945 wxCHECK_MSG( m_rect
, 0, _T("can't be called in this mode") );
947 return m_rect
->height
;
950 void wxListItemData::GetItem( wxListItem
&info
) const
952 info
.m_text
= m_text
;
953 info
.m_image
= m_image
;
954 info
.m_data
= m_data
;
958 if ( m_attr
->HasTextColour() )
959 info
.SetTextColour(m_attr
->GetTextColour());
960 if ( m_attr
->HasBackgroundColour() )
961 info
.SetBackgroundColour(m_attr
->GetBackgroundColour());
962 if ( m_attr
->HasFont() )
963 info
.SetFont(m_attr
->GetFont());
967 //-----------------------------------------------------------------------------
969 //-----------------------------------------------------------------------------
971 void wxListHeaderData::Init()
982 wxListHeaderData::wxListHeaderData()
987 wxListHeaderData::wxListHeaderData( const wxListItem
&item
)
994 void wxListHeaderData::SetItem( const wxListItem
&item
)
996 m_mask
= item
.m_mask
;
998 if ( m_mask
& wxLIST_MASK_TEXT
)
999 m_text
= item
.m_text
;
1001 if ( m_mask
& wxLIST_MASK_IMAGE
)
1002 m_image
= item
.m_image
;
1004 if ( m_mask
& wxLIST_MASK_FORMAT
)
1005 m_format
= item
.m_format
;
1007 if ( m_mask
& wxLIST_MASK_WIDTH
)
1008 SetWidth(item
.m_width
);
1011 void wxListHeaderData::SetPosition( int x
, int y
)
1017 void wxListHeaderData::SetHeight( int h
)
1022 void wxListHeaderData::SetWidth( int w
)
1026 m_width
= WIDTH_COL_DEFAULT
;
1027 else if (m_width
< WIDTH_COL_MIN
)
1028 m_width
= WIDTH_COL_MIN
;
1031 void wxListHeaderData::SetFormat( int format
)
1036 bool wxListHeaderData::HasImage() const
1038 return m_image
!= -1;
1041 bool wxListHeaderData::IsHit( int x
, int y
) const
1043 return ((x
>= m_xpos
) && (x
<= m_xpos
+m_width
) && (y
>= m_ypos
) && (y
<= m_ypos
+m_height
));
1046 void wxListHeaderData::GetItem( wxListItem
& item
)
1048 item
.m_mask
= m_mask
;
1049 item
.m_text
= m_text
;
1050 item
.m_image
= m_image
;
1051 item
.m_format
= m_format
;
1052 item
.m_width
= m_width
;
1055 int wxListHeaderData::GetImage() const
1060 int wxListHeaderData::GetWidth() const
1065 int wxListHeaderData::GetFormat() const
1070 //-----------------------------------------------------------------------------
1072 //-----------------------------------------------------------------------------
1074 inline int wxListLineData::GetMode() const
1076 return m_owner
->GetListCtrl()->GetWindowStyleFlag() & wxLC_MASK_TYPE
;
1079 inline bool wxListLineData::InReportView() const
1081 return m_owner
->HasFlag(wxLC_REPORT
);
1084 inline bool wxListLineData::IsVirtual() const
1086 return m_owner
->IsVirtual();
1089 wxListLineData::wxListLineData( wxListMainWindow
*owner
)
1092 m_items
.DeleteContents( TRUE
);
1094 if ( InReportView() )
1100 m_gi
= new GeometryInfo
;
1103 m_highlighted
= FALSE
;
1105 InitItems( GetMode() == wxLC_REPORT
? m_owner
->GetColumnCount() : 1 );
1108 void wxListLineData::CalculateSize( wxDC
*dc
, int spacing
)
1110 wxListItemDataList::Node
*node
= m_items
.GetFirst();
1111 wxCHECK_RET( node
, _T("no subitems at all??") );
1113 wxListItemData
*item
= node
->GetData();
1115 switch ( GetMode() )
1118 case wxLC_SMALL_ICON
:
1120 m_gi
->m_rectAll
.width
= spacing
;
1122 wxString s
= item
->GetText();
1128 m_gi
->m_rectLabel
.width
=
1129 m_gi
->m_rectLabel
.height
= 0;
1133 dc
->GetTextExtent( s
, &lw
, &lh
);
1134 if (lh
< SCROLL_UNIT_Y
)
1139 m_gi
->m_rectAll
.height
= spacing
+ lh
;
1141 m_gi
->m_rectAll
.width
= lw
;
1143 m_gi
->m_rectLabel
.width
= lw
;
1144 m_gi
->m_rectLabel
.height
= lh
;
1147 if (item
->HasImage())
1150 m_owner
->GetImageSize( item
->GetImage(), w
, h
);
1151 m_gi
->m_rectIcon
.width
= w
+ 8;
1152 m_gi
->m_rectIcon
.height
= h
+ 8;
1154 if ( m_gi
->m_rectIcon
.width
> m_gi
->m_rectAll
.width
)
1155 m_gi
->m_rectAll
.width
= m_gi
->m_rectIcon
.width
;
1156 if ( m_gi
->m_rectIcon
.height
+ lh
> m_gi
->m_rectAll
.height
- 4 )
1157 m_gi
->m_rectAll
.height
= m_gi
->m_rectIcon
.height
+ lh
+ 4;
1160 if ( item
->HasText() )
1162 m_gi
->m_rectHighlight
.width
= m_gi
->m_rectLabel
.width
;
1163 m_gi
->m_rectHighlight
.height
= m_gi
->m_rectLabel
.height
;
1165 else // no text, highlight the icon
1167 m_gi
->m_rectHighlight
.width
= m_gi
->m_rectIcon
.width
;
1168 m_gi
->m_rectHighlight
.height
= m_gi
->m_rectIcon
.height
;
1175 wxString s
= item
->GetTextForMeasuring();
1178 dc
->GetTextExtent( s
, &lw
, &lh
);
1179 if (lh
< SCROLL_UNIT_Y
)
1184 m_gi
->m_rectLabel
.width
= lw
;
1185 m_gi
->m_rectLabel
.height
= lh
;
1187 m_gi
->m_rectAll
.width
= lw
;
1188 m_gi
->m_rectAll
.height
= lh
;
1190 if (item
->HasImage())
1193 m_owner
->GetImageSize( item
->GetImage(), w
, h
);
1194 m_gi
->m_rectIcon
.width
= w
;
1195 m_gi
->m_rectIcon
.height
= h
;
1197 m_gi
->m_rectAll
.width
+= 4 + w
;
1198 if (h
> m_gi
->m_rectAll
.height
)
1199 m_gi
->m_rectAll
.height
= h
;
1202 m_gi
->m_rectHighlight
.width
= m_gi
->m_rectAll
.width
;
1203 m_gi
->m_rectHighlight
.height
= m_gi
->m_rectAll
.height
;
1208 wxFAIL_MSG( _T("unexpected call to SetSize") );
1212 wxFAIL_MSG( _T("unknown mode") );
1216 void wxListLineData::SetPosition( int x
, int y
,
1220 wxListItemDataList::Node
*node
= m_items
.GetFirst();
1221 wxCHECK_RET( node
, _T("no subitems at all??") );
1223 wxListItemData
*item
= node
->GetData();
1225 switch ( GetMode() )
1228 case wxLC_SMALL_ICON
:
1229 m_gi
->m_rectAll
.x
= x
;
1230 m_gi
->m_rectAll
.y
= y
;
1232 if ( item
->HasImage() )
1234 m_gi
->m_rectIcon
.x
= m_gi
->m_rectAll
.x
+ 4 +
1235 (m_gi
->m_rectAll
.width
- m_gi
->m_rectIcon
.width
) / 2;
1236 m_gi
->m_rectIcon
.y
= m_gi
->m_rectAll
.y
+ 4;
1239 if ( item
->HasText() )
1241 if (m_gi
->m_rectAll
.width
> spacing
)
1242 m_gi
->m_rectLabel
.x
= m_gi
->m_rectAll
.x
+ 2;
1244 m_gi
->m_rectLabel
.x
= m_gi
->m_rectAll
.x
+ 2 + (spacing
/2) - (m_gi
->m_rectLabel
.width
/2);
1245 m_gi
->m_rectLabel
.y
= m_gi
->m_rectAll
.y
+ m_gi
->m_rectAll
.height
+ 2 - m_gi
->m_rectLabel
.height
;
1246 m_gi
->m_rectHighlight
.x
= m_gi
->m_rectLabel
.x
- 2;
1247 m_gi
->m_rectHighlight
.y
= m_gi
->m_rectLabel
.y
- 2;
1249 else // no text, highlight the icon
1251 m_gi
->m_rectHighlight
.x
= m_gi
->m_rectIcon
.x
- 4;
1252 m_gi
->m_rectHighlight
.y
= m_gi
->m_rectIcon
.y
- 4;
1257 m_gi
->m_rectAll
.x
= x
;
1258 m_gi
->m_rectAll
.y
= y
;
1260 m_gi
->m_rectHighlight
.x
= m_gi
->m_rectAll
.x
;
1261 m_gi
->m_rectHighlight
.y
= m_gi
->m_rectAll
.y
;
1262 m_gi
->m_rectLabel
.y
= m_gi
->m_rectAll
.y
+ 2;
1264 if (item
->HasImage())
1266 m_gi
->m_rectIcon
.x
= m_gi
->m_rectAll
.x
+ 2;
1267 m_gi
->m_rectIcon
.y
= m_gi
->m_rectAll
.y
+ 2;
1268 m_gi
->m_rectLabel
.x
= m_gi
->m_rectAll
.x
+ 6 + m_gi
->m_rectIcon
.width
;
1272 m_gi
->m_rectLabel
.x
= m_gi
->m_rectAll
.x
+ 2;
1277 wxFAIL_MSG( _T("unexpected call to SetPosition") );
1281 wxFAIL_MSG( _T("unknown mode") );
1285 void wxListLineData::InitItems( int num
)
1287 for (int i
= 0; i
< num
; i
++)
1288 m_items
.Append( new wxListItemData(m_owner
) );
1291 void wxListLineData::SetItem( int index
, const wxListItem
&info
)
1293 wxListItemDataList::Node
*node
= m_items
.Item( index
);
1294 wxCHECK_RET( node
, _T("invalid column index in SetItem") );
1296 wxListItemData
*item
= node
->GetData();
1297 item
->SetItem( info
);
1300 void wxListLineData::GetItem( int index
, wxListItem
&info
)
1302 wxListItemDataList::Node
*node
= m_items
.Item( index
);
1305 wxListItemData
*item
= node
->GetData();
1306 item
->GetItem( info
);
1310 wxString
wxListLineData::GetText(int index
) const
1314 wxListItemDataList::Node
*node
= m_items
.Item( index
);
1317 wxListItemData
*item
= node
->GetData();
1318 s
= item
->GetText();
1324 void wxListLineData::SetText( int index
, const wxString s
)
1326 wxListItemDataList::Node
*node
= m_items
.Item( index
);
1329 wxListItemData
*item
= node
->GetData();
1334 void wxListLineData::SetImage( int index
, int image
)
1336 wxListItemDataList::Node
*node
= m_items
.Item( index
);
1337 wxCHECK_RET( node
, _T("invalid column index in SetImage()") );
1339 wxListItemData
*item
= node
->GetData();
1340 item
->SetImage(image
);
1343 int wxListLineData::GetImage( int index
) const
1345 wxListItemDataList::Node
*node
= m_items
.Item( index
);
1346 wxCHECK_MSG( node
, -1, _T("invalid column index in GetImage()") );
1348 wxListItemData
*item
= node
->GetData();
1349 return item
->GetImage();
1352 wxListItemAttr
*wxListLineData::GetAttr() const
1354 wxListItemDataList::Node
*node
= m_items
.GetFirst();
1355 wxCHECK_MSG( node
, NULL
, _T("invalid column index in GetAttr()") );
1357 wxListItemData
*item
= node
->GetData();
1358 return item
->GetAttr();
1361 void wxListLineData::SetAttr(wxListItemAttr
*attr
)
1363 wxListItemDataList::Node
*node
= m_items
.GetFirst();
1364 wxCHECK_RET( node
, _T("invalid column index in SetAttr()") );
1366 wxListItemData
*item
= node
->GetData();
1367 item
->SetAttr(attr
);
1370 bool wxListLineData::SetAttributes(wxDC
*dc
,
1371 const wxListItemAttr
*attr
,
1374 wxWindow
*listctrl
= m_owner
->GetParent();
1378 // don't use foreground colour for drawing highlighted items - this might
1379 // make them completely invisible (and there is no way to do bit
1380 // arithmetics on wxColour, unfortunately)
1384 colText
= wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHTTEXT
);
1388 if ( attr
&& attr
->HasTextColour() )
1390 colText
= attr
->GetTextColour();
1394 colText
= listctrl
->GetForegroundColour();
1398 dc
->SetTextForeground(colText
);
1402 if ( attr
&& attr
->HasFont() )
1404 font
= attr
->GetFont();
1408 font
= listctrl
->GetFont();
1414 bool hasBgCol
= attr
&& attr
->HasBackgroundColour();
1415 if ( highlighted
|| hasBgCol
)
1419 dc
->SetBrush( *m_owner
->GetHighlightBrush() );
1423 dc
->SetBrush(wxBrush(attr
->GetBackgroundColour(), wxSOLID
));
1426 dc
->SetPen( *wxTRANSPARENT_PEN
);
1434 void wxListLineData::Draw( wxDC
*dc
)
1436 wxListItemDataList::Node
*node
= m_items
.GetFirst();
1437 wxCHECK_RET( node
, _T("no subitems at all??") );
1439 bool highlighted
= IsHighlighted();
1441 wxListItemAttr
*attr
= GetAttr();
1443 if ( SetAttributes(dc
, attr
, highlighted
) )
1445 dc
->DrawRectangle( m_gi
->m_rectHighlight
);
1448 wxListItemData
*item
= node
->GetData();
1449 if (item
->HasImage())
1451 wxRect rectIcon
= m_gi
->m_rectIcon
;
1452 m_owner
->DrawImage( item
->GetImage(), dc
,
1453 rectIcon
.x
, rectIcon
.y
);
1456 if (item
->HasText())
1458 wxRect rectLabel
= m_gi
->m_rectLabel
;
1460 wxDCClipper
clipper(*dc
, rectLabel
);
1461 dc
->DrawText( item
->GetText(), rectLabel
.x
, rectLabel
.y
);
1465 void wxListLineData::DrawInReportMode( wxDC
*dc
,
1467 const wxRect
& rectHL
,
1470 // TODO: later we should support setting different attributes for
1471 // different columns - to do it, just add "col" argument to
1472 // GetAttr() and move these lines into the loop below
1473 wxListItemAttr
*attr
= GetAttr();
1474 if ( SetAttributes(dc
, attr
, highlighted
) )
1476 dc
->DrawRectangle( rectHL
);
1479 wxCoord x
= rect
.x
+ HEADER_OFFSET_X
,
1480 y
= rect
.y
+ (LINE_SPACING
+ EXTRA_HEIGHT
) / 2;
1483 for ( wxListItemDataList::Node
*node
= m_items
.GetFirst();
1485 node
= node
->GetNext(), col
++ )
1487 wxListItemData
*item
= node
->GetData();
1489 int width
= m_owner
->GetColumnWidth(col
);
1493 if ( item
->HasImage() )
1496 m_owner
->DrawImage( item
->GetImage(), dc
, xOld
, y
);
1497 m_owner
->GetImageSize( item
->GetImage(), ix
, iy
);
1499 ix
+= IMAGE_MARGIN_IN_REPORT_MODE
;
1505 wxDCClipper
clipper(*dc
, xOld
, y
, width
- 8, rect
.height
);
1507 if ( item
->HasText() )
1509 DrawTextFormatted(dc
, item
->GetText(), col
, xOld
, y
, width
- 8);
1514 void wxListLineData::DrawTextFormatted(wxDC
*dc
,
1515 const wxString
&text
,
1521 wxString drawntext
, ellipsis
;
1522 wxCoord w
, h
, base_w
;
1525 // determine if the string can fit inside the current width
1526 dc
->GetTextExtent(text
, &w
, &h
);
1529 // it can, draw it using the items alignment
1530 m_owner
->GetColumn(col
, item
);
1531 switch ( item
.GetAlign() )
1534 wxFAIL_MSG( _T("unknown list item format") );
1537 case wxLIST_FORMAT_LEFT
:
1541 case wxLIST_FORMAT_RIGHT
:
1545 case wxLIST_FORMAT_CENTER
:
1546 x
+= (width
- w
) / 2;
1550 dc
->DrawText(text
, x
, y
);
1552 else // otherwise, truncate and add an ellipsis if possible
1554 // determine the base width
1555 ellipsis
= wxString(wxT("..."));
1556 dc
->GetTextExtent(ellipsis
, &base_w
, &h
);
1558 // continue until we have enough space or only one character left
1560 size_t len
= text
.Length();
1561 drawntext
= text
.Left(len
);
1564 dc
->GetTextExtent(drawntext
.Last(), &w_c
, &h_c
);
1565 drawntext
.RemoveLast();
1568 if (w
+ base_w
<= width
)
1572 // if still not enough space, remove ellipsis characters
1573 while (ellipsis
.Length() > 0 && w
+ base_w
> width
)
1575 ellipsis
= ellipsis
.Left(ellipsis
.Length() - 1);
1576 dc
->GetTextExtent(ellipsis
, &base_w
, &h
);
1579 // now draw the text
1580 dc
->DrawText(drawntext
, x
, y
);
1581 dc
->DrawText(ellipsis
, x
+ w
, y
);
1585 bool wxListLineData::Highlight( bool on
)
1587 wxCHECK_MSG( !m_owner
->IsVirtual(), FALSE
, _T("unexpected call to Highlight") );
1589 if ( on
== m_highlighted
)
1597 void wxListLineData::ReverseHighlight( void )
1599 Highlight(!IsHighlighted());
1602 //-----------------------------------------------------------------------------
1603 // wxListHeaderWindow
1604 //-----------------------------------------------------------------------------
1606 IMPLEMENT_DYNAMIC_CLASS(wxListHeaderWindow
,wxWindow
)
1608 BEGIN_EVENT_TABLE(wxListHeaderWindow
,wxWindow
)
1609 EVT_PAINT (wxListHeaderWindow::OnPaint
)
1610 EVT_MOUSE_EVENTS (wxListHeaderWindow::OnMouse
)
1611 EVT_SET_FOCUS (wxListHeaderWindow::OnSetFocus
)
1614 void wxListHeaderWindow::Init()
1616 m_currentCursor
= (wxCursor
*) NULL
;
1617 m_isDragging
= FALSE
;
1621 wxListHeaderWindow::wxListHeaderWindow()
1625 m_owner
= (wxListMainWindow
*) NULL
;
1626 m_resizeCursor
= (wxCursor
*) NULL
;
1629 wxListHeaderWindow::wxListHeaderWindow( wxWindow
*win
,
1631 wxListMainWindow
*owner
,
1635 const wxString
&name
)
1636 : wxWindow( win
, id
, pos
, size
, style
, name
)
1641 m_resizeCursor
= new wxCursor( wxCURSOR_SIZEWE
);
1643 SetBackgroundColour( wxSystemSettings::GetColour( wxSYS_COLOUR_BTNFACE
) );
1646 wxListHeaderWindow::~wxListHeaderWindow()
1648 delete m_resizeCursor
;
1651 #ifdef __WXUNIVERSAL__
1652 #include "wx/univ/renderer.h"
1653 #include "wx/univ/theme.h"
1656 void wxListHeaderWindow::DoDrawRect( wxDC
*dc
, int x
, int y
, int w
, int h
)
1658 #if defined(__WXGTK__) && !defined(__WXUNIVERSAL__)
1659 GtkStateType state
= m_parent
->IsEnabled() ? GTK_STATE_NORMAL
1660 : GTK_STATE_INSENSITIVE
;
1662 x
= dc
->XLOG2DEV( x
);
1664 gtk_paint_box (m_wxwindow
->style
, GTK_PIZZA(m_wxwindow
)->bin_window
,
1665 state
, GTK_SHADOW_OUT
,
1666 (GdkRectangle
*) NULL
, m_wxwindow
,
1667 (char *)"button", // const_cast
1668 x
-1, y
-1, w
+2, h
+2);
1669 #elif defined(__WXUNIVERSAL__)
1670 wxTheme
*theme
= wxTheme::Get();
1671 wxRenderer
*renderer
= theme
->GetRenderer();
1672 renderer
->DrawBorder( *dc
, wxBORDER_RAISED
, wxRect(x
,y
,w
,h
), 0 );
1673 #elif defined(__WXMAC__)
1674 const int m_corner
= 1;
1676 dc
->SetBrush( *wxTRANSPARENT_BRUSH
);
1678 dc
->SetPen( wxPen( wxSystemSettings::GetColour( wxSYS_COLOUR_BTNSHADOW
) , 1 , wxSOLID
) );
1679 dc
->DrawLine( x
+w
-m_corner
+1, y
, x
+w
, y
+h
); // right (outer)
1680 dc
->DrawRectangle( x
, y
+h
, w
+1, 1 ); // bottom (outer)
1682 wxPen
pen( wxColour( 0x88 , 0x88 , 0x88 ), 1, wxSOLID
);
1685 dc
->DrawLine( x
+w
-m_corner
, y
, x
+w
-1, y
+h
); // right (inner)
1686 dc
->DrawRectangle( x
+1, y
+h
-1, w
-2, 1 ); // bottom (inner)
1688 dc
->SetPen( *wxWHITE_PEN
);
1689 dc
->DrawRectangle( x
, y
, w
-m_corner
+1, 1 ); // top (outer)
1690 dc
->DrawRectangle( x
, y
, 1, h
); // left (outer)
1691 dc
->DrawLine( x
, y
+h
-1, x
+1, y
+h
-1 );
1692 dc
->DrawLine( x
+w
-1, y
, x
+w
-1, y
+1 );
1694 const int m_corner
= 1;
1696 dc
->SetBrush( *wxTRANSPARENT_BRUSH
);
1698 dc
->SetPen( *wxBLACK_PEN
);
1699 dc
->DrawLine( x
+w
-m_corner
+1, y
, x
+w
, y
+h
); // right (outer)
1700 dc
->DrawRectangle( x
, y
+h
, w
+1, 1 ); // bottom (outer)
1702 wxPen
pen( wxSystemSettings::GetColour( wxSYS_COLOUR_BTNSHADOW
), 1, wxSOLID
);
1705 dc
->DrawLine( x
+w
-m_corner
, y
, x
+w
-1, y
+h
); // right (inner)
1706 dc
->DrawRectangle( x
+1, y
+h
-1, w
-2, 1 ); // bottom (inner)
1708 dc
->SetPen( *wxWHITE_PEN
);
1709 dc
->DrawRectangle( x
, y
, w
-m_corner
+1, 1 ); // top (outer)
1710 dc
->DrawRectangle( x
, y
, 1, h
); // left (outer)
1711 dc
->DrawLine( x
, y
+h
-1, x
+1, y
+h
-1 );
1712 dc
->DrawLine( x
+w
-1, y
, x
+w
-1, y
+1 );
1716 // shift the DC origin to match the position of the main window horz
1717 // scrollbar: this allows us to always use logical coords
1718 void wxListHeaderWindow::AdjustDC(wxDC
& dc
)
1721 m_owner
->GetScrollPixelsPerUnit( &xpix
, NULL
);
1724 m_owner
->GetViewStart( &x
, NULL
);
1726 // account for the horz scrollbar offset
1727 dc
.SetDeviceOrigin( -x
* xpix
, 0 );
1730 void wxListHeaderWindow::OnPaint( wxPaintEvent
&WXUNUSED(event
) )
1732 #if defined(__WXGTK__)
1733 wxClientDC
dc( this );
1735 wxPaintDC
dc( this );
1743 dc
.SetFont( GetFont() );
1745 // width and height of the entire header window
1747 GetClientSize( &w
, &h
);
1748 m_owner
->CalcUnscrolledPosition(w
, 0, &w
, NULL
);
1750 dc
.SetBackgroundMode(wxTRANSPARENT
);
1752 // do *not* use the listctrl colour for headers - one day we will have a
1753 // function to set it separately
1754 //dc.SetTextForeground( *wxBLACK );
1755 dc
.SetTextForeground(wxSystemSettings::
1756 GetSystemColour( wxSYS_COLOUR_WINDOWTEXT
));
1758 int x
= HEADER_OFFSET_X
;
1760 int numColumns
= m_owner
->GetColumnCount();
1762 for ( int i
= 0; i
< numColumns
&& x
< w
; i
++ )
1764 m_owner
->GetColumn( i
, item
);
1765 int wCol
= item
.m_width
;
1767 // the width of the rect to draw: make it smaller to fit entirely
1768 // inside the column rect
1771 dc
.SetPen( *wxWHITE_PEN
);
1773 DoDrawRect( &dc
, x
, HEADER_OFFSET_Y
, cw
, h
-2 );
1775 // see if we have enough space for the column label
1777 // for this we need the width of the text
1779 dc
.GetTextExtent(item
.GetText(), &wLabel
, NULL
);
1780 wLabel
+= 2*EXTRA_WIDTH
;
1782 // and the width of the icon, if any
1783 static const int MARGIN_BETWEEN_TEXT_AND_ICON
= 2;
1784 int ix
= 0, // init them just to suppress the compiler warnings
1786 const int image
= item
.m_image
;
1787 wxImageListType
*imageList
;
1790 imageList
= m_owner
->m_small_image_list
;
1793 imageList
->GetSize(image
, ix
, iy
);
1794 wLabel
+= ix
+ MARGIN_BETWEEN_TEXT_AND_ICON
;
1802 // ignore alignment if there is not enough space anyhow
1804 switch ( wLabel
< cw
? item
.GetAlign() : wxLIST_FORMAT_LEFT
)
1807 wxFAIL_MSG( _T("unknown list item format") );
1810 case wxLIST_FORMAT_LEFT
:
1814 case wxLIST_FORMAT_RIGHT
:
1815 xAligned
= x
+ cw
- wLabel
;
1818 case wxLIST_FORMAT_CENTER
:
1819 xAligned
= x
+ (cw
- wLabel
) / 2;
1824 // if we have an image, draw it on the right of the label
1831 xAligned
+ wLabel
- ix
- MARGIN_BETWEEN_TEXT_AND_ICON
,
1832 HEADER_OFFSET_Y
+ (h
- 4 - iy
)/2,
1833 wxIMAGELIST_DRAW_TRANSPARENT
1836 cw
-= ix
+ MARGIN_BETWEEN_TEXT_AND_ICON
;
1839 // draw the text clipping it so that it doesn't overwrite the column
1841 wxDCClipper
clipper(dc
, x
, HEADER_OFFSET_Y
, cw
, h
- 4 );
1843 dc
.DrawText( item
.GetText(),
1844 xAligned
+ EXTRA_WIDTH
, HEADER_OFFSET_Y
+ EXTRA_HEIGHT
);
1852 void wxListHeaderWindow::DrawCurrent()
1854 int x1
= m_currentX
;
1856 m_owner
->ClientToScreen( &x1
, &y1
);
1858 int x2
= m_currentX
;
1860 m_owner
->GetClientSize( NULL
, &y2
);
1861 m_owner
->ClientToScreen( &x2
, &y2
);
1864 dc
.SetLogicalFunction( wxINVERT
);
1865 dc
.SetPen( wxPen( *wxBLACK
, 2, wxSOLID
) );
1866 dc
.SetBrush( *wxTRANSPARENT_BRUSH
);
1870 dc
.DrawLine( x1
, y1
, x2
, y2
);
1872 dc
.SetLogicalFunction( wxCOPY
);
1874 dc
.SetPen( wxNullPen
);
1875 dc
.SetBrush( wxNullBrush
);
1878 void wxListHeaderWindow::OnMouse( wxMouseEvent
&event
)
1880 // we want to work with logical coords
1882 m_owner
->CalcUnscrolledPosition(event
.GetX(), 0, &x
, NULL
);
1883 int y
= event
.GetY();
1887 SendListEvent(wxEVT_COMMAND_LIST_COL_DRAGGING
, event
.GetPosition());
1889 // we don't draw the line beyond our window, but we allow dragging it
1892 GetClientSize( &w
, NULL
);
1893 m_owner
->CalcUnscrolledPosition(w
, 0, &w
, NULL
);
1896 // erase the line if it was drawn
1897 if ( m_currentX
< w
)
1900 if (event
.ButtonUp())
1903 m_isDragging
= FALSE
;
1905 m_owner
->SetColumnWidth( m_column
, m_currentX
- m_minX
);
1906 SendListEvent(wxEVT_COMMAND_LIST_COL_END_DRAG
, event
.GetPosition());
1913 m_currentX
= m_minX
+ 7;
1915 // draw in the new location
1916 if ( m_currentX
< w
)
1920 else // not dragging
1923 bool hit_border
= FALSE
;
1925 // end of the current column
1928 // find the column where this event occured
1930 countCol
= m_owner
->GetColumnCount();
1931 for (col
= 0; col
< countCol
; col
++)
1933 xpos
+= m_owner
->GetColumnWidth( col
);
1936 if ( (abs(x
-xpos
) < 3) && (y
< 22) )
1938 // near the column border
1945 // inside the column
1952 if ( col
== countCol
)
1955 if (event
.LeftDown() || event
.RightUp())
1957 if (hit_border
&& event
.LeftDown())
1959 if ( SendListEvent(wxEVT_COMMAND_LIST_COL_BEGIN_DRAG
,
1960 event
.GetPosition()) )
1962 m_isDragging
= TRUE
;
1967 //else: column resizing was vetoed by the user code
1969 else // click on a column
1971 SendListEvent( event
.LeftDown()
1972 ? wxEVT_COMMAND_LIST_COL_CLICK
1973 : wxEVT_COMMAND_LIST_COL_RIGHT_CLICK
,
1974 event
.GetPosition());
1977 else if (event
.Moving())
1982 setCursor
= m_currentCursor
== wxSTANDARD_CURSOR
;
1983 m_currentCursor
= m_resizeCursor
;
1987 setCursor
= m_currentCursor
!= wxSTANDARD_CURSOR
;
1988 m_currentCursor
= wxSTANDARD_CURSOR
;
1992 SetCursor(*m_currentCursor
);
1997 void wxListHeaderWindow::OnSetFocus( wxFocusEvent
&WXUNUSED(event
) )
1999 m_owner
->SetFocus();
2002 bool wxListHeaderWindow::SendListEvent(wxEventType type
, wxPoint pos
)
2004 wxWindow
*parent
= GetParent();
2005 wxListEvent
le( type
, parent
->GetId() );
2006 le
.SetEventObject( parent
);
2007 le
.m_pointDrag
= pos
;
2009 // the position should be relative to the parent window, not
2010 // this one for compatibility with MSW and common sense: the
2011 // user code doesn't know anything at all about this header
2012 // window, so why should it get positions relative to it?
2013 le
.m_pointDrag
.y
-= GetSize().y
;
2015 le
.m_col
= m_column
;
2016 return !parent
->GetEventHandler()->ProcessEvent( le
) || le
.IsAllowed();
2019 //-----------------------------------------------------------------------------
2020 // wxListRenameTimer (internal)
2021 //-----------------------------------------------------------------------------
2023 wxListRenameTimer::wxListRenameTimer( wxListMainWindow
*owner
)
2028 void wxListRenameTimer::Notify()
2030 m_owner
->OnRenameTimer();
2033 //-----------------------------------------------------------------------------
2034 // wxListTextCtrl (internal)
2035 //-----------------------------------------------------------------------------
2037 BEGIN_EVENT_TABLE(wxListTextCtrl
,wxTextCtrl
)
2038 EVT_CHAR (wxListTextCtrl::OnChar
)
2039 EVT_KEY_UP (wxListTextCtrl::OnKeyUp
)
2040 EVT_KILL_FOCUS (wxListTextCtrl::OnKillFocus
)
2043 wxListTextCtrl::wxListTextCtrl(wxListMainWindow
*owner
, size_t itemEdit
)
2044 : m_startValue(owner
->GetItemText(itemEdit
)),
2045 m_itemEdited(itemEdit
)
2050 wxRect rectLabel
= owner
->GetLineLabelRect(itemEdit
);
2052 m_owner
->CalcScrolledPosition(rectLabel
.x
, rectLabel
.y
,
2053 &rectLabel
.x
, &rectLabel
.y
);
2055 (void)Create(owner
, wxID_ANY
, m_startValue
,
2056 wxPoint(rectLabel
.x
-4,rectLabel
.y
-4),
2057 wxSize(rectLabel
.width
+11,rectLabel
.height
+8));
2060 void wxListTextCtrl::Finish()
2064 wxPendingDelete
.Append(this);
2068 m_owner
->SetFocus();
2072 bool wxListTextCtrl::AcceptChanges()
2074 const wxString value
= GetValue();
2076 if ( value
== m_startValue
)
2078 // nothing changed, always accept
2082 if ( !m_owner
->OnRenameAccept(m_itemEdited
, value
) )
2084 // vetoed by the user
2088 // accepted, do rename the item
2089 m_owner
->SetItemText(m_itemEdited
, value
);
2094 void wxListTextCtrl::OnChar( wxKeyEvent
&event
)
2096 switch ( event
.m_keyCode
)
2099 if ( !AcceptChanges() )
2101 // vetoed by the user code
2104 //else: fall through
2115 void wxListTextCtrl::OnKeyUp( wxKeyEvent
&event
)
2123 // auto-grow the textctrl:
2124 wxSize parentSize
= m_owner
->GetSize();
2125 wxPoint myPos
= GetPosition();
2126 wxSize mySize
= GetSize();
2128 GetTextExtent(GetValue() + _T("MM"), &sx
, &sy
);
2129 if (myPos
.x
+ sx
> parentSize
.x
)
2130 sx
= parentSize
.x
- myPos
.x
;
2138 void wxListTextCtrl::OnKillFocus( wxFocusEvent
&event
)
2142 (void)AcceptChanges();
2150 //-----------------------------------------------------------------------------
2152 //-----------------------------------------------------------------------------
2154 IMPLEMENT_DYNAMIC_CLASS(wxListMainWindow
,wxScrolledWindow
)
2156 BEGIN_EVENT_TABLE(wxListMainWindow
,wxScrolledWindow
)
2157 EVT_PAINT (wxListMainWindow::OnPaint
)
2158 EVT_MOUSE_EVENTS (wxListMainWindow::OnMouse
)
2159 EVT_CHAR (wxListMainWindow::OnChar
)
2160 EVT_KEY_DOWN (wxListMainWindow::OnKeyDown
)
2161 EVT_SET_FOCUS (wxListMainWindow::OnSetFocus
)
2162 EVT_KILL_FOCUS (wxListMainWindow::OnKillFocus
)
2163 EVT_SCROLLWIN (wxListMainWindow::OnScroll
)
2166 void wxListMainWindow::Init()
2168 m_columns
.DeleteContents( TRUE
);
2172 m_lineTo
= (size_t)-1;
2178 m_small_image_list
= (wxImageListType
*) NULL
;
2179 m_normal_image_list
= (wxImageListType
*) NULL
;
2181 m_small_spacing
= 30;
2182 m_normal_spacing
= 40;
2186 m_isCreated
= FALSE
;
2188 m_lastOnSame
= FALSE
;
2189 m_renameTimer
= new wxListRenameTimer( this );
2193 m_lineBeforeLastClicked
= (size_t)-1;
2198 void wxListMainWindow::InitScrolling()
2200 if ( HasFlag(wxLC_REPORT
) )
2202 m_xScroll
= SCROLL_UNIT_X
;
2203 m_yScroll
= SCROLL_UNIT_Y
;
2207 m_xScroll
= SCROLL_UNIT_Y
;
2212 wxListMainWindow::wxListMainWindow()
2217 m_highlightUnfocusedBrush
= (wxBrush
*) NULL
;
2223 wxListMainWindow::wxListMainWindow( wxWindow
*parent
,
2228 const wxString
&name
)
2229 : wxScrolledWindow( parent
, id
, pos
, size
,
2230 style
| wxHSCROLL
| wxVSCROLL
, name
)
2234 m_highlightBrush
= new wxBrush
2236 wxSystemSettings::GetColour
2238 wxSYS_COLOUR_HIGHLIGHT
2243 m_highlightUnfocusedBrush
= new wxBrush
2245 wxSystemSettings::GetColour
2247 wxSYS_COLOUR_BTNSHADOW
2256 SetScrollbars( m_xScroll
, m_yScroll
, 0, 0, 0, 0 );
2258 SetBackgroundColour( wxSystemSettings::GetColour( wxSYS_COLOUR_LISTBOX
) );
2261 wxListMainWindow::~wxListMainWindow()
2265 delete m_highlightBrush
;
2266 delete m_highlightUnfocusedBrush
;
2268 delete m_renameTimer
;
2271 void wxListMainWindow::CacheLineData(size_t line
)
2273 wxGenericListCtrl
*listctrl
= GetListCtrl();
2275 wxListLineData
*ld
= GetDummyLine();
2277 size_t countCol
= GetColumnCount();
2278 for ( size_t col
= 0; col
< countCol
; col
++ )
2280 ld
->SetText(col
, listctrl
->OnGetItemText(line
, col
));
2283 ld
->SetImage(listctrl
->OnGetItemImage(line
));
2284 ld
->SetAttr(listctrl
->OnGetItemAttr(line
));
2287 wxListLineData
*wxListMainWindow::GetDummyLine() const
2289 wxASSERT_MSG( !IsEmpty(), _T("invalid line index") );
2291 wxASSERT_MSG( IsVirtual(), _T("GetDummyLine() shouldn't be called") );
2293 wxListMainWindow
*self
= wxConstCast(this, wxListMainWindow
);
2295 // we need to recreate the dummy line if the number of columns in the
2296 // control changed as it would have the incorrect number of fields
2298 if ( !m_lines
.IsEmpty() &&
2299 m_lines
[0].m_items
.GetCount() != (size_t)GetColumnCount() )
2301 self
->m_lines
.Clear();
2304 if ( m_lines
.IsEmpty() )
2306 wxListLineData
*line
= new wxListLineData(self
);
2307 self
->m_lines
.Add(line
);
2309 // don't waste extra memory -- there never going to be anything
2310 // else/more in this array
2311 self
->m_lines
.Shrink();
2317 // ----------------------------------------------------------------------------
2318 // line geometry (report mode only)
2319 // ----------------------------------------------------------------------------
2321 wxCoord
wxListMainWindow::GetLineHeight() const
2323 wxASSERT_MSG( HasFlag(wxLC_REPORT
), _T("only works in report mode") );
2325 // we cache the line height as calling GetTextExtent() is slow
2326 if ( !m_lineHeight
)
2328 wxListMainWindow
*self
= wxConstCast(this, wxListMainWindow
);
2330 wxClientDC
dc( self
);
2331 dc
.SetFont( GetFont() );
2334 dc
.GetTextExtent(_T("H"), NULL
, &y
);
2336 if ( y
< SCROLL_UNIT_Y
)
2339 if ( m_small_image_list
&& m_small_image_list
->GetImageCount() )
2343 m_small_image_list
->GetSize(0, iw
, ih
);
2348 self
->m_lineHeight
= y
+ LINE_SPACING
;
2351 return m_lineHeight
;
2354 wxCoord
wxListMainWindow::GetLineY(size_t line
) const
2356 wxASSERT_MSG( HasFlag(wxLC_REPORT
), _T("only works in report mode") );
2358 return LINE_SPACING
+ line
*GetLineHeight();
2361 wxRect
wxListMainWindow::GetLineRect(size_t line
) const
2363 if ( !InReportView() )
2364 return GetLine(line
)->m_gi
->m_rectAll
;
2367 rect
.x
= HEADER_OFFSET_X
;
2368 rect
.y
= GetLineY(line
);
2369 rect
.width
= GetHeaderWidth();
2370 rect
.height
= GetLineHeight();
2375 wxRect
wxListMainWindow::GetLineLabelRect(size_t line
) const
2377 if ( !InReportView() )
2378 return GetLine(line
)->m_gi
->m_rectLabel
;
2381 rect
.x
= HEADER_OFFSET_X
;
2382 rect
.y
= GetLineY(line
);
2383 rect
.width
= GetColumnWidth(0);
2384 rect
.height
= GetLineHeight();
2389 wxRect
wxListMainWindow::GetLineIconRect(size_t line
) const
2391 if ( !InReportView() )
2392 return GetLine(line
)->m_gi
->m_rectIcon
;
2394 wxListLineData
*ld
= GetLine(line
);
2395 wxASSERT_MSG( ld
->HasImage(), _T("should have an image") );
2398 rect
.x
= HEADER_OFFSET_X
;
2399 rect
.y
= GetLineY(line
);
2400 GetImageSize(ld
->GetImage(), rect
.width
, rect
.height
);
2405 wxRect
wxListMainWindow::GetLineHighlightRect(size_t line
) const
2407 return InReportView() ? GetLineRect(line
)
2408 : GetLine(line
)->m_gi
->m_rectHighlight
;
2411 long wxListMainWindow::HitTestLine(size_t line
, int x
, int y
) const
2413 wxASSERT_MSG( line
< GetItemCount(), _T("invalid line in HitTestLine") );
2415 wxListLineData
*ld
= GetLine(line
);
2417 if ( ld
->HasImage() && GetLineIconRect(line
).Inside(x
, y
) )
2418 return wxLIST_HITTEST_ONITEMICON
;
2420 // VS: Testing for "ld->HasText() || InReportView()" instead of
2421 // "ld->HasText()" is needed to make empty lines in report view
2423 if ( ld
->HasText() || InReportView() )
2425 wxRect rect
= InReportView() ? GetLineRect(line
)
2426 : GetLineLabelRect(line
);
2428 if ( rect
.Inside(x
, y
) )
2429 return wxLIST_HITTEST_ONITEMLABEL
;
2435 // ----------------------------------------------------------------------------
2436 // highlight (selection) handling
2437 // ----------------------------------------------------------------------------
2439 bool wxListMainWindow::IsHighlighted(size_t line
) const
2443 return m_selStore
.IsSelected(line
);
2447 wxListLineData
*ld
= GetLine(line
);
2448 wxCHECK_MSG( ld
, FALSE
, _T("invalid index in IsHighlighted") );
2450 return ld
->IsHighlighted();
2454 void wxListMainWindow::HighlightLines( size_t lineFrom
,
2460 wxArrayInt linesChanged
;
2461 if ( !m_selStore
.SelectRange(lineFrom
, lineTo
, highlight
,
2464 // meny items changed state, refresh everything
2465 RefreshLines(lineFrom
, lineTo
);
2467 else // only a few items changed state, refresh only them
2469 size_t count
= linesChanged
.GetCount();
2470 for ( size_t n
= 0; n
< count
; n
++ )
2472 RefreshLine(linesChanged
[n
]);
2476 else // iterate over all items in non report view
2478 for ( size_t line
= lineFrom
; line
<= lineTo
; line
++ )
2480 if ( HighlightLine(line
, highlight
) )
2488 bool wxListMainWindow::HighlightLine( size_t line
, bool highlight
)
2494 changed
= m_selStore
.SelectItem(line
, highlight
);
2498 wxListLineData
*ld
= GetLine(line
);
2499 wxCHECK_MSG( ld
, FALSE
, _T("invalid index in HighlightLine") );
2501 changed
= ld
->Highlight(highlight
);
2506 SendNotify( line
, highlight
? wxEVT_COMMAND_LIST_ITEM_SELECTED
2507 : wxEVT_COMMAND_LIST_ITEM_DESELECTED
);
2513 void wxListMainWindow::RefreshLine( size_t line
)
2515 if ( HasFlag(wxLC_REPORT
) )
2517 size_t visibleFrom
, visibleTo
;
2518 GetVisibleLinesRange(&visibleFrom
, &visibleTo
);
2520 if ( line
< visibleFrom
|| line
> visibleTo
)
2524 wxRect rect
= GetLineRect(line
);
2526 CalcScrolledPosition( rect
.x
, rect
.y
, &rect
.x
, &rect
.y
);
2527 RefreshRect( rect
);
2530 void wxListMainWindow::RefreshLines( size_t lineFrom
, size_t lineTo
)
2532 // we suppose that they are ordered by caller
2533 wxASSERT_MSG( lineFrom
<= lineTo
, _T("indices in disorder") );
2535 wxASSERT_MSG( lineTo
< GetItemCount(), _T("invalid line range") );
2537 if ( HasFlag(wxLC_REPORT
) )
2539 size_t visibleFrom
, visibleTo
;
2540 GetVisibleLinesRange(&visibleFrom
, &visibleTo
);
2542 if ( lineFrom
< visibleFrom
)
2543 lineFrom
= visibleFrom
;
2544 if ( lineTo
> visibleTo
)
2549 rect
.y
= GetLineY(lineFrom
);
2550 rect
.width
= GetClientSize().x
;
2551 rect
.height
= GetLineY(lineTo
) - rect
.y
+ GetLineHeight();
2553 CalcScrolledPosition( rect
.x
, rect
.y
, &rect
.x
, &rect
.y
);
2554 RefreshRect( rect
);
2558 // TODO: this should be optimized...
2559 for ( size_t line
= lineFrom
; line
<= lineTo
; line
++ )
2566 void wxListMainWindow::RefreshAfter( size_t lineFrom
)
2568 if ( HasFlag(wxLC_REPORT
) )
2570 size_t visibleFrom
, visibleTo
;
2571 GetVisibleLinesRange(&visibleFrom
, &visibleTo
);
2573 if ( lineFrom
< visibleFrom
)
2574 lineFrom
= visibleFrom
;
2575 else if ( lineFrom
> visibleTo
)
2580 rect
.y
= GetLineY(lineFrom
);
2581 CalcScrolledPosition( rect
.x
, rect
.y
, &rect
.x
, &rect
.y
);
2583 wxSize size
= GetClientSize();
2584 rect
.width
= size
.x
;
2585 // refresh till the bottom of the window
2586 rect
.height
= size
.y
- rect
.y
;
2588 RefreshRect( rect
);
2592 // TODO: how to do it more efficiently?
2597 void wxListMainWindow::RefreshSelected()
2603 if ( InReportView() )
2605 GetVisibleLinesRange(&from
, &to
);
2610 to
= GetItemCount() - 1;
2613 if ( HasCurrent() && m_current
>= from
&& m_current
<= to
)
2615 RefreshLine(m_current
);
2618 for ( size_t line
= from
; line
<= to
; line
++ )
2620 // NB: the test works as expected even if m_current == -1
2621 if ( line
!= m_current
&& IsHighlighted(line
) )
2628 void wxListMainWindow::Freeze()
2633 void wxListMainWindow::Thaw()
2635 wxCHECK_RET( m_freezeCount
> 0, _T("thawing unfrozen list control?") );
2637 if ( !--m_freezeCount
)
2643 void wxListMainWindow::OnPaint( wxPaintEvent
&WXUNUSED(event
) )
2645 // Note: a wxPaintDC must be constructed even if no drawing is
2646 // done (a Windows requirement).
2647 wxPaintDC
dc( this );
2649 if ( IsEmpty() || m_freezeCount
)
2651 // nothing to draw or not the moment to draw it
2657 // delay the repainting until we calculate all the items positions
2664 CalcScrolledPosition( 0, 0, &dev_x
, &dev_y
);
2668 dc
.SetFont( GetFont() );
2670 if ( HasFlag(wxLC_REPORT
) )
2672 int lineHeight
= GetLineHeight();
2674 size_t visibleFrom
, visibleTo
;
2675 GetVisibleLinesRange(&visibleFrom
, &visibleTo
);
2678 wxCoord xOrig
, yOrig
;
2679 CalcUnscrolledPosition(0, 0, &xOrig
, &yOrig
);
2681 // tell the caller cache to cache the data
2684 wxListEvent
evCache(wxEVT_COMMAND_LIST_CACHE_HINT
,
2685 GetParent()->GetId());
2686 evCache
.SetEventObject( GetParent() );
2687 evCache
.m_oldItemIndex
= visibleFrom
;
2688 evCache
.m_itemIndex
= visibleTo
;
2689 GetParent()->GetEventHandler()->ProcessEvent( evCache
);
2692 for ( size_t line
= visibleFrom
; line
<= visibleTo
; line
++ )
2694 rectLine
= GetLineRect(line
);
2696 if ( !IsExposed(rectLine
.x
- xOrig
, rectLine
.y
- yOrig
,
2697 rectLine
.width
, rectLine
.height
) )
2699 // don't redraw unaffected lines to avoid flicker
2703 GetLine(line
)->DrawInReportMode( &dc
,
2705 GetLineHighlightRect(line
),
2706 IsHighlighted(line
) );
2709 if ( HasFlag(wxLC_HRULES
) )
2711 wxPen
pen(GetRuleColour(), 1, wxSOLID
);
2712 wxSize clientSize
= GetClientSize();
2714 // Don't draw the first one
2715 for ( size_t i
= visibleFrom
+1; i
<= visibleTo
; i
++ )
2718 dc
.SetBrush( *wxTRANSPARENT_BRUSH
);
2719 dc
.DrawLine(0 - dev_x
, i
*lineHeight
,
2720 clientSize
.x
- dev_x
, i
*lineHeight
);
2723 // Draw last horizontal rule
2724 if ( visibleTo
== GetItemCount() - 1 )
2727 dc
.SetBrush( *wxTRANSPARENT_BRUSH
);
2728 dc
.DrawLine(0 - dev_x
, (m_lineTo
+1)*lineHeight
,
2729 clientSize
.x
- dev_x
, (m_lineTo
+1)*lineHeight
);
2733 // Draw vertical rules if required
2734 if ( HasFlag(wxLC_VRULES
) && !IsEmpty() )
2736 wxPen
pen(GetRuleColour(), 1, wxSOLID
);
2739 wxRect firstItemRect
;
2740 wxRect lastItemRect
;
2741 GetItemRect(visibleFrom
, firstItemRect
);
2742 GetItemRect(visibleTo
, lastItemRect
);
2743 int x
= firstItemRect
.GetX();
2745 dc
.SetBrush(* wxTRANSPARENT_BRUSH
);
2746 for (col
= 0; col
< GetColumnCount(); col
++)
2748 int colWidth
= GetColumnWidth(col
);
2750 dc
.DrawLine(x
- dev_x
- 2, firstItemRect
.GetY() - 1 - dev_y
,
2751 x
- dev_x
- 2, lastItemRect
.GetBottom() + 1 - dev_y
);
2757 size_t count
= GetItemCount();
2758 for ( size_t i
= 0; i
< count
; i
++ )
2760 GetLine(i
)->Draw( &dc
);
2766 // don't draw rect outline under Max if we already have the background
2767 // color but under other platforms only draw it if we do: it is a bit
2768 // silly to draw "focus rect" if we don't have focus!
2773 #endif // __WXMAC__/!__WXMAC__
2775 dc
.SetPen( *wxBLACK_PEN
);
2776 dc
.SetBrush( *wxTRANSPARENT_BRUSH
);
2777 dc
.DrawRectangle( GetLineHighlightRect(m_current
) );
2784 void wxListMainWindow::HighlightAll( bool on
)
2786 if ( IsSingleSel() )
2788 wxASSERT_MSG( !on
, _T("can't do this in a single sel control") );
2790 // we just have one item to turn off
2791 if ( HasCurrent() && IsHighlighted(m_current
) )
2793 HighlightLine(m_current
, FALSE
);
2794 RefreshLine(m_current
);
2799 HighlightLines(0, GetItemCount() - 1, on
);
2803 void wxListMainWindow::SendNotify( size_t line
,
2804 wxEventType command
,
2807 wxListEvent
le( command
, GetParent()->GetId() );
2808 le
.SetEventObject( GetParent() );
2809 le
.m_itemIndex
= line
;
2811 // set only for events which have position
2812 if ( point
!= wxDefaultPosition
)
2813 le
.m_pointDrag
= point
;
2815 // don't try to get the line info for virtual list controls: the main
2816 // program has it anyhow and if we did it would result in accessing all
2817 // the lines, even those which are not visible now and this is precisely
2818 // what we're trying to avoid
2819 if ( !IsVirtual() && (command
!= wxEVT_COMMAND_LIST_DELETE_ITEM
) )
2821 if ( line
!= (size_t)-1 )
2823 GetLine(line
)->GetItem( 0, le
.m_item
);
2825 //else: this happens for wxEVT_COMMAND_LIST_ITEM_FOCUSED event
2827 //else: there may be no more such item
2829 GetParent()->GetEventHandler()->ProcessEvent( le
);
2832 void wxListMainWindow::ChangeCurrent(size_t current
)
2834 m_current
= current
;
2836 SendNotify(current
, wxEVT_COMMAND_LIST_ITEM_FOCUSED
);
2839 void wxListMainWindow::EditLabel( long item
)
2841 wxCHECK_RET( (item
>= 0) && ((size_t)item
< GetItemCount()),
2842 wxT("wrong index in wxGenericListCtrl::EditLabel()") );
2844 size_t itemEdit
= (size_t)item
;
2846 wxListEvent
le( wxEVT_COMMAND_LIST_BEGIN_LABEL_EDIT
, GetParent()->GetId() );
2847 le
.SetEventObject( GetParent() );
2848 le
.m_itemIndex
= item
;
2849 wxListLineData
*data
= GetLine(itemEdit
);
2850 wxCHECK_RET( data
, _T("invalid index in EditLabel()") );
2851 data
->GetItem( 0, le
.m_item
);
2852 if ( GetParent()->GetEventHandler()->ProcessEvent( le
) && !le
.IsAllowed() )
2854 // vetoed by user code
2858 // We have to call this here because the label in question might just have
2859 // been added and no screen update taken place.
2863 wxListTextCtrl
*text
= new wxListTextCtrl(this, itemEdit
);
2868 void wxListMainWindow::OnRenameTimer()
2870 wxCHECK_RET( HasCurrent(), wxT("unexpected rename timer") );
2872 EditLabel( m_current
);
2875 bool wxListMainWindow::OnRenameAccept(size_t itemEdit
, const wxString
& value
)
2877 wxListEvent
le( wxEVT_COMMAND_LIST_END_LABEL_EDIT
, GetParent()->GetId() );
2878 le
.SetEventObject( GetParent() );
2879 le
.m_itemIndex
= itemEdit
;
2881 wxListLineData
*data
= GetLine(itemEdit
);
2882 wxCHECK_MSG( data
, FALSE
, _T("invalid index in OnRenameAccept()") );
2884 data
->GetItem( 0, le
.m_item
);
2885 le
.m_item
.m_text
= value
;
2886 return !GetParent()->GetEventHandler()->ProcessEvent( le
) ||
2890 void wxListMainWindow::OnMouse( wxMouseEvent
&event
)
2892 event
.SetEventObject( GetParent() );
2893 if ( GetParent()->GetEventHandler()->ProcessEvent( event
) )
2896 if ( !HasCurrent() || IsEmpty() )
2902 if ( !(event
.Dragging() || event
.ButtonDown() || event
.LeftUp() ||
2903 event
.ButtonDClick()) )
2906 int x
= event
.GetX();
2907 int y
= event
.GetY();
2908 CalcUnscrolledPosition( x
, y
, &x
, &y
);
2910 // where did we hit it (if we did)?
2913 size_t count
= GetItemCount(),
2916 if ( HasFlag(wxLC_REPORT
) )
2918 current
= y
/ GetLineHeight();
2919 if ( current
< count
)
2920 hitResult
= HitTestLine(current
, x
, y
);
2924 // TODO: optimize it too! this is less simple than for report view but
2925 // enumerating all items is still not a way to do it!!
2926 for ( current
= 0; current
< count
; current
++ )
2928 hitResult
= HitTestLine(current
, x
, y
);
2934 if (event
.Dragging())
2936 if (m_dragCount
== 0)
2938 // we have to report the raw, physical coords as we want to be
2939 // able to call HitTest(event.m_pointDrag) from the user code to
2940 // get the item being dragged
2941 m_dragStart
= event
.GetPosition();
2946 if (m_dragCount
!= 3)
2949 int command
= event
.RightIsDown() ? wxEVT_COMMAND_LIST_BEGIN_RDRAG
2950 : wxEVT_COMMAND_LIST_BEGIN_DRAG
;
2952 wxListEvent
le( command
, GetParent()->GetId() );
2953 le
.SetEventObject( GetParent() );
2954 le
.m_itemIndex
= current
;
2955 le
.m_pointDrag
= m_dragStart
;
2956 GetParent()->GetEventHandler()->ProcessEvent( le
);
2967 // outside of any item
2971 bool forceClick
= FALSE
;
2972 if (event
.ButtonDClick())
2974 m_renameTimer
->Stop();
2975 m_lastOnSame
= FALSE
;
2977 if ( current
== m_lineLastClicked
)
2979 SendNotify( current
, wxEVT_COMMAND_LIST_ITEM_ACTIVATED
);
2985 // the first click was on another item, so don't interpret this as
2986 // a double click, but as a simple click instead
2991 if (event
.LeftUp() && m_lastOnSame
)
2993 if ((current
== m_current
) &&
2994 (hitResult
== wxLIST_HITTEST_ONITEMLABEL
) &&
2995 HasFlag(wxLC_EDIT_LABELS
) )
2997 m_renameTimer
->Start( 100, TRUE
);
2999 m_lastOnSame
= FALSE
;
3001 else if (event
.RightDown())
3003 SendNotify( current
, wxEVT_COMMAND_LIST_ITEM_RIGHT_CLICK
,
3004 event
.GetPosition() );
3006 else if (event
.MiddleDown())
3008 SendNotify( current
, wxEVT_COMMAND_LIST_ITEM_MIDDLE_CLICK
);
3010 else if ( event
.LeftDown() || forceClick
)
3012 m_lineBeforeLastClicked
= m_lineLastClicked
;
3013 m_lineLastClicked
= current
;
3015 size_t oldCurrent
= m_current
;
3017 if ( IsSingleSel() || !(event
.ControlDown() || event
.ShiftDown()) )
3019 HighlightAll( FALSE
);
3021 ChangeCurrent(current
);
3023 ReverseHighlight(m_current
);
3025 else // multi sel & either ctrl or shift is down
3027 if (event
.ControlDown())
3029 ChangeCurrent(current
);
3031 ReverseHighlight(m_current
);
3033 else if (event
.ShiftDown())
3035 ChangeCurrent(current
);
3037 size_t lineFrom
= oldCurrent
,
3040 if ( lineTo
< lineFrom
)
3043 lineFrom
= m_current
;
3046 HighlightLines(lineFrom
, lineTo
);
3048 else // !ctrl, !shift
3050 // test in the enclosing if should make it impossible
3051 wxFAIL_MSG( _T("how did we get here?") );
3055 if (m_current
!= oldCurrent
)
3057 RefreshLine( oldCurrent
);
3060 // forceClick is only set if the previous click was on another item
3061 m_lastOnSame
= !forceClick
&& (m_current
== oldCurrent
);
3065 void wxListMainWindow::MoveToItem(size_t item
)
3067 if ( item
== (size_t)-1 )
3070 wxRect rect
= GetLineRect(item
);
3072 int client_w
, client_h
;
3073 GetClientSize( &client_w
, &client_h
);
3075 int view_x
= m_xScroll
*GetScrollPos( wxHORIZONTAL
);
3076 int view_y
= m_yScroll
*GetScrollPos( wxVERTICAL
);
3078 if ( HasFlag(wxLC_REPORT
) )
3080 // the next we need the range of lines shown it might be different, so
3082 ResetVisibleLinesRange();
3084 if (rect
.y
< view_y
)
3085 Scroll( -1, rect
.y
/m_yScroll
);
3086 if (rect
.y
+rect
.height
+5 > view_y
+client_h
)
3087 Scroll( -1, (rect
.y
+rect
.height
-client_h
+SCROLL_UNIT_Y
)/m_yScroll
);
3091 if (rect
.x
-view_x
< 5)
3092 Scroll( (rect
.x
-5)/m_xScroll
, -1 );
3093 if (rect
.x
+rect
.width
-5 > view_x
+client_w
)
3094 Scroll( (rect
.x
+rect
.width
-client_w
+SCROLL_UNIT_X
)/m_xScroll
, -1 );
3098 // ----------------------------------------------------------------------------
3099 // keyboard handling
3100 // ----------------------------------------------------------------------------
3102 void wxListMainWindow::OnArrowChar(size_t newCurrent
, const wxKeyEvent
& event
)
3104 wxCHECK_RET( newCurrent
< (size_t)GetItemCount(),
3105 _T("invalid item index in OnArrowChar()") );
3107 size_t oldCurrent
= m_current
;
3109 // in single selection we just ignore Shift as we can't select several
3111 if ( event
.ShiftDown() && !IsSingleSel() )
3113 ChangeCurrent(newCurrent
);
3115 // select all the items between the old and the new one
3116 if ( oldCurrent
> newCurrent
)
3118 newCurrent
= oldCurrent
;
3119 oldCurrent
= m_current
;
3122 HighlightLines(oldCurrent
, newCurrent
);
3126 // all previously selected items are unselected unless ctrl is held
3127 if ( !event
.ControlDown() )
3128 HighlightAll(FALSE
);
3130 ChangeCurrent(newCurrent
);
3132 // refresh the old focus to remove it
3133 RefreshLine( oldCurrent
);
3135 if ( !event
.ControlDown() )
3137 HighlightLine( m_current
, TRUE
);
3141 RefreshLine( m_current
);
3146 void wxListMainWindow::OnKeyDown( wxKeyEvent
&event
)
3148 wxWindow
*parent
= GetParent();
3150 /* we propagate the key event up */
3151 wxKeyEvent
ke( wxEVT_KEY_DOWN
);
3152 ke
.m_shiftDown
= event
.m_shiftDown
;
3153 ke
.m_controlDown
= event
.m_controlDown
;
3154 ke
.m_altDown
= event
.m_altDown
;
3155 ke
.m_metaDown
= event
.m_metaDown
;
3156 ke
.m_keyCode
= event
.m_keyCode
;
3159 ke
.SetEventObject( parent
);
3160 if (parent
->GetEventHandler()->ProcessEvent( ke
)) return;
3165 void wxListMainWindow::OnChar( wxKeyEvent
&event
)
3167 wxWindow
*parent
= GetParent();
3169 /* we send a list_key event up */
3172 wxListEvent
le( wxEVT_COMMAND_LIST_KEY_DOWN
, GetParent()->GetId() );
3173 le
.m_itemIndex
= m_current
;
3174 GetLine(m_current
)->GetItem( 0, le
.m_item
);
3175 le
.m_code
= event
.GetKeyCode();
3176 le
.SetEventObject( parent
);
3177 parent
->GetEventHandler()->ProcessEvent( le
);
3180 /* we propagate the char event up */
3181 wxKeyEvent
ke( wxEVT_CHAR
);
3182 ke
.m_shiftDown
= event
.m_shiftDown
;
3183 ke
.m_controlDown
= event
.m_controlDown
;
3184 ke
.m_altDown
= event
.m_altDown
;
3185 ke
.m_metaDown
= event
.m_metaDown
;
3186 ke
.m_keyCode
= event
.m_keyCode
;
3189 ke
.SetEventObject( parent
);
3190 if (parent
->GetEventHandler()->ProcessEvent( ke
)) return;
3192 if (event
.GetKeyCode() == WXK_TAB
)
3194 wxNavigationKeyEvent nevent
;
3195 nevent
.SetWindowChange( event
.ControlDown() );
3196 nevent
.SetDirection( !event
.ShiftDown() );
3197 nevent
.SetEventObject( GetParent()->GetParent() );
3198 nevent
.SetCurrentFocus( m_parent
);
3199 if (GetParent()->GetParent()->GetEventHandler()->ProcessEvent( nevent
))
3203 /* no item -> nothing to do */
3210 switch (event
.GetKeyCode())
3213 if ( m_current
> 0 )
3214 OnArrowChar( m_current
- 1, event
);
3218 if ( m_current
< (size_t)GetItemCount() - 1 )
3219 OnArrowChar( m_current
+ 1, event
);
3224 OnArrowChar( GetItemCount() - 1, event
);
3229 OnArrowChar( 0, event
);
3235 if ( HasFlag(wxLC_REPORT
) )
3237 steps
= m_linesPerPage
- 1;
3241 steps
= m_current
% m_linesPerPage
;
3244 int index
= m_current
- steps
;
3248 OnArrowChar( index
, event
);
3255 if ( HasFlag(wxLC_REPORT
) )
3257 steps
= m_linesPerPage
- 1;
3261 steps
= m_linesPerPage
- (m_current
% m_linesPerPage
) - 1;
3264 size_t index
= m_current
+ steps
;
3265 size_t count
= GetItemCount();
3266 if ( index
>= count
)
3269 OnArrowChar( index
, event
);
3274 if ( !HasFlag(wxLC_REPORT
) )
3276 int index
= m_current
- m_linesPerPage
;
3280 OnArrowChar( index
, event
);
3285 if ( !HasFlag(wxLC_REPORT
) )
3287 size_t index
= m_current
+ m_linesPerPage
;
3289 size_t count
= GetItemCount();
3290 if ( index
>= count
)
3293 OnArrowChar( index
, event
);
3298 if ( IsSingleSel() )
3300 SendNotify( m_current
, wxEVT_COMMAND_LIST_ITEM_ACTIVATED
);
3302 if ( IsHighlighted(m_current
) )
3304 // don't unselect the item in single selection mode
3307 //else: select it in ReverseHighlight() below if unselected
3310 ReverseHighlight(m_current
);
3315 SendNotify( m_current
, wxEVT_COMMAND_LIST_ITEM_ACTIVATED
);
3323 // ----------------------------------------------------------------------------
3325 // ----------------------------------------------------------------------------
3327 void wxListMainWindow::SetFocus()
3329 // VS: wxListMainWindow derives from wxPanel (via wxScrolledWindow) and wxPanel
3330 // overrides SetFocus in such way that it does never change focus from
3331 // panel's child to the panel itself. Unfortunately, we must be able to change
3332 // focus to the panel from wxListTextCtrl because the text control should
3333 // disappear when the user clicks outside it.
3335 wxWindow
*oldFocus
= FindFocus();
3337 if ( oldFocus
&& oldFocus
->GetParent() == this )
3339 wxWindow::SetFocus();
3343 wxScrolledWindow::SetFocus();
3347 void wxListMainWindow::OnSetFocus( wxFocusEvent
&WXUNUSED(event
) )
3349 // wxGTK sends us EVT_SET_FOCUS events even if we had never got
3350 // EVT_KILL_FOCUS before which means that we finish by redrawing the items
3351 // which are already drawn correctly resulting in horrible flicker - avoid
3363 wxFocusEvent
event( wxEVT_SET_FOCUS
, GetParent()->GetId() );
3364 event
.SetEventObject( GetParent() );
3365 GetParent()->GetEventHandler()->ProcessEvent( event
);
3368 void wxListMainWindow::OnKillFocus( wxFocusEvent
&WXUNUSED(event
) )
3375 void wxListMainWindow::DrawImage( int index
, wxDC
*dc
, int x
, int y
)
3377 if ( HasFlag(wxLC_ICON
) && (m_normal_image_list
))
3379 m_normal_image_list
->Draw( index
, *dc
, x
, y
, wxIMAGELIST_DRAW_TRANSPARENT
);
3381 else if ( HasFlag(wxLC_SMALL_ICON
) && (m_small_image_list
))
3383 m_small_image_list
->Draw( index
, *dc
, x
, y
, wxIMAGELIST_DRAW_TRANSPARENT
);
3385 else if ( HasFlag(wxLC_LIST
) && (m_small_image_list
))
3387 m_small_image_list
->Draw( index
, *dc
, x
, y
, wxIMAGELIST_DRAW_TRANSPARENT
);
3389 else if ( HasFlag(wxLC_REPORT
) && (m_small_image_list
))
3391 m_small_image_list
->Draw( index
, *dc
, x
, y
, wxIMAGELIST_DRAW_TRANSPARENT
);
3395 void wxListMainWindow::GetImageSize( int index
, int &width
, int &height
) const
3397 if ( HasFlag(wxLC_ICON
) && m_normal_image_list
)
3399 m_normal_image_list
->GetSize( index
, width
, height
);
3401 else if ( HasFlag(wxLC_SMALL_ICON
) && m_small_image_list
)
3403 m_small_image_list
->GetSize( index
, width
, height
);
3405 else if ( HasFlag(wxLC_LIST
) && m_small_image_list
)
3407 m_small_image_list
->GetSize( index
, width
, height
);
3409 else if ( HasFlag(wxLC_REPORT
) && m_small_image_list
)
3411 m_small_image_list
->GetSize( index
, width
, height
);
3420 int wxListMainWindow::GetTextLength( const wxString
&s
) const
3422 wxClientDC
dc( wxConstCast(this, wxListMainWindow
) );
3423 dc
.SetFont( GetFont() );
3426 dc
.GetTextExtent( s
, &lw
, NULL
);
3428 return lw
+ AUTOSIZE_COL_MARGIN
;
3431 void wxListMainWindow::SetImageList( wxImageListType
*imageList
, int which
)
3435 // calc the spacing from the icon size
3438 if ((imageList
) && (imageList
->GetImageCount()) )
3440 imageList
->GetSize(0, width
, height
);
3443 if (which
== wxIMAGE_LIST_NORMAL
)
3445 m_normal_image_list
= imageList
;
3446 m_normal_spacing
= width
+ 8;
3449 if (which
== wxIMAGE_LIST_SMALL
)
3451 m_small_image_list
= imageList
;
3452 m_small_spacing
= width
+ 14;
3453 m_lineHeight
= 0; // ensure that the line height will be recalc'd
3457 void wxListMainWindow::SetItemSpacing( int spacing
, bool isSmall
)
3462 m_small_spacing
= spacing
;
3466 m_normal_spacing
= spacing
;
3470 int wxListMainWindow::GetItemSpacing( bool isSmall
)
3472 return isSmall
? m_small_spacing
: m_normal_spacing
;
3475 // ----------------------------------------------------------------------------
3477 // ----------------------------------------------------------------------------
3479 void wxListMainWindow::SetColumn( int col
, wxListItem
&item
)
3481 wxListHeaderDataList::Node
*node
= m_columns
.Item( col
);
3483 wxCHECK_RET( node
, _T("invalid column index in SetColumn") );
3485 if ( item
.m_width
== wxLIST_AUTOSIZE_USEHEADER
)
3486 item
.m_width
= GetTextLength( item
.m_text
);
3488 wxListHeaderData
*column
= node
->GetData();
3489 column
->SetItem( item
);
3491 wxListHeaderWindow
*headerWin
= GetListCtrl()->m_headerWin
;
3493 headerWin
->m_dirty
= TRUE
;
3497 // invalidate it as it has to be recalculated
3501 void wxListMainWindow::SetColumnWidth( int col
, int width
)
3503 wxCHECK_RET( col
>= 0 && col
< GetColumnCount(),
3504 _T("invalid column index") );
3506 wxCHECK_RET( HasFlag(wxLC_REPORT
),
3507 _T("SetColumnWidth() can only be called in report mode.") );
3510 wxListHeaderWindow
*headerWin
= GetListCtrl()->m_headerWin
;
3512 headerWin
->m_dirty
= TRUE
;
3514 wxListHeaderDataList::Node
*node
= m_columns
.Item( col
);
3515 wxCHECK_RET( node
, _T("no column?") );
3517 wxListHeaderData
*column
= node
->GetData();
3519 size_t count
= GetItemCount();
3521 if (width
== wxLIST_AUTOSIZE_USEHEADER
)
3523 width
= GetTextLength(column
->GetText());
3525 else if ( width
== wxLIST_AUTOSIZE
)
3529 // TODO: determine the max width somehow...
3530 width
= WIDTH_COL_DEFAULT
;
3534 wxClientDC
dc(this);
3535 dc
.SetFont( GetFont() );
3537 int max
= AUTOSIZE_COL_MARGIN
;
3539 for ( size_t i
= 0; i
< count
; i
++ )
3541 wxListLineData
*line
= GetLine(i
);
3542 wxListItemDataList::Node
*n
= line
->m_items
.Item( col
);
3544 wxCHECK_RET( n
, _T("no subitem?") );
3546 wxListItemData
*item
= n
->GetData();
3549 if (item
->HasImage())
3552 GetImageSize( item
->GetImage(), ix
, iy
);
3556 if (item
->HasText())
3559 dc
.GetTextExtent( item
->GetText(), &w
, NULL
);
3567 width
= max
+ AUTOSIZE_COL_MARGIN
;
3571 column
->SetWidth( width
);
3573 // invalidate it as it has to be recalculated
3577 int wxListMainWindow::GetHeaderWidth() const
3579 if ( !m_headerWidth
)
3581 wxListMainWindow
*self
= wxConstCast(this, wxListMainWindow
);
3583 size_t count
= GetColumnCount();
3584 for ( size_t col
= 0; col
< count
; col
++ )
3586 self
->m_headerWidth
+= GetColumnWidth(col
);
3590 return m_headerWidth
;
3593 void wxListMainWindow::GetColumn( int col
, wxListItem
&item
) const
3595 wxListHeaderDataList::Node
*node
= m_columns
.Item( col
);
3596 wxCHECK_RET( node
, _T("invalid column index in GetColumn") );
3598 wxListHeaderData
*column
= node
->GetData();
3599 column
->GetItem( item
);
3602 int wxListMainWindow::GetColumnWidth( int col
) const
3604 wxListHeaderDataList::Node
*node
= m_columns
.Item( col
);
3605 wxCHECK_MSG( node
, 0, _T("invalid column index") );
3607 wxListHeaderData
*column
= node
->GetData();
3608 return column
->GetWidth();
3611 // ----------------------------------------------------------------------------
3613 // ----------------------------------------------------------------------------
3615 void wxListMainWindow::SetItem( wxListItem
&item
)
3617 long id
= item
.m_itemId
;
3618 wxCHECK_RET( id
>= 0 && (size_t)id
< GetItemCount(),
3619 _T("invalid item index in SetItem") );
3623 wxListLineData
*line
= GetLine((size_t)id
);
3624 line
->SetItem( item
.m_col
, item
);
3627 // update the item on screen
3629 GetItemRect(id
, rectItem
);
3630 RefreshRect(rectItem
);
3633 void wxListMainWindow::SetItemState( long litem
, long state
, long stateMask
)
3635 wxCHECK_RET( litem
>= 0 && (size_t)litem
< GetItemCount(),
3636 _T("invalid list ctrl item index in SetItem") );
3638 size_t oldCurrent
= m_current
;
3639 size_t item
= (size_t)litem
; // safe because of the check above
3641 // do we need to change the focus?
3642 if ( stateMask
& wxLIST_STATE_FOCUSED
)
3644 if ( state
& wxLIST_STATE_FOCUSED
)
3646 // don't do anything if this item is already focused
3647 if ( item
!= m_current
)
3649 ChangeCurrent(item
);
3651 if ( oldCurrent
!= (size_t)-1 )
3653 if ( IsSingleSel() )
3655 HighlightLine(oldCurrent
, FALSE
);
3658 RefreshLine(oldCurrent
);
3661 RefreshLine( m_current
);
3666 // don't do anything if this item is not focused
3667 if ( item
== m_current
)
3671 if ( IsSingleSel() )
3673 // we must unselect the old current item as well or we
3674 // might end up with more than one selected item in a
3675 // single selection control
3676 HighlightLine(oldCurrent
, FALSE
);
3679 RefreshLine( oldCurrent
);
3684 // do we need to change the selection state?
3685 if ( stateMask
& wxLIST_STATE_SELECTED
)
3687 bool on
= (state
& wxLIST_STATE_SELECTED
) != 0;
3689 if ( IsSingleSel() )
3693 // selecting the item also makes it the focused one in the
3695 if ( m_current
!= item
)
3697 ChangeCurrent(item
);
3699 if ( oldCurrent
!= (size_t)-1 )
3701 HighlightLine( oldCurrent
, FALSE
);
3702 RefreshLine( oldCurrent
);
3708 // only the current item may be selected anyhow
3709 if ( item
!= m_current
)
3714 if ( HighlightLine(item
, on
) )
3721 int wxListMainWindow::GetItemState( long item
, long stateMask
) const
3723 wxCHECK_MSG( item
>= 0 && (size_t)item
< GetItemCount(), 0,
3724 _T("invalid list ctrl item index in GetItemState()") );
3726 int ret
= wxLIST_STATE_DONTCARE
;
3728 if ( stateMask
& wxLIST_STATE_FOCUSED
)
3730 if ( (size_t)item
== m_current
)
3731 ret
|= wxLIST_STATE_FOCUSED
;
3734 if ( stateMask
& wxLIST_STATE_SELECTED
)
3736 if ( IsHighlighted(item
) )
3737 ret
|= wxLIST_STATE_SELECTED
;
3743 void wxListMainWindow::GetItem( wxListItem
&item
) const
3745 wxCHECK_RET( item
.m_itemId
>= 0 && (size_t)item
.m_itemId
< GetItemCount(),
3746 _T("invalid item index in GetItem") );
3748 wxListLineData
*line
= GetLine((size_t)item
.m_itemId
);
3749 line
->GetItem( item
.m_col
, item
);
3752 // ----------------------------------------------------------------------------
3754 // ----------------------------------------------------------------------------
3756 size_t wxListMainWindow::GetItemCount() const
3758 return IsVirtual() ? m_countVirt
: m_lines
.GetCount();
3761 void wxListMainWindow::SetItemCount(long count
)
3763 m_selStore
.SetItemCount(count
);
3764 m_countVirt
= count
;
3766 ResetVisibleLinesRange();
3768 // scrollbars must be reset
3772 int wxListMainWindow::GetSelectedItemCount() const
3774 // deal with the quick case first
3775 if ( IsSingleSel() )
3777 return HasCurrent() ? IsHighlighted(m_current
) : FALSE
;
3780 // virtual controls remmebers all its selections itself
3782 return m_selStore
.GetSelectedCount();
3784 // TODO: we probably should maintain the number of items selected even for
3785 // non virtual controls as enumerating all lines is really slow...
3786 size_t countSel
= 0;
3787 size_t count
= GetItemCount();
3788 for ( size_t line
= 0; line
< count
; line
++ )
3790 if ( GetLine(line
)->IsHighlighted() )
3797 // ----------------------------------------------------------------------------
3798 // item position/size
3799 // ----------------------------------------------------------------------------
3801 void wxListMainWindow::GetItemRect( long index
, wxRect
&rect
) const
3803 wxCHECK_RET( index
>= 0 && (size_t)index
< GetItemCount(),
3804 _T("invalid index in GetItemRect") );
3806 rect
= GetLineRect((size_t)index
);
3808 CalcScrolledPosition(rect
.x
, rect
.y
, &rect
.x
, &rect
.y
);
3811 bool wxListMainWindow::GetItemPosition(long item
, wxPoint
& pos
) const
3814 GetItemRect(item
, rect
);
3822 // ----------------------------------------------------------------------------
3823 // geometry calculation
3824 // ----------------------------------------------------------------------------
3826 void wxListMainWindow::RecalculatePositions(bool noRefresh
)
3828 wxClientDC
dc( this );
3829 dc
.SetFont( GetFont() );
3832 if ( HasFlag(wxLC_ICON
) )
3833 iconSpacing
= m_normal_spacing
;
3834 else if ( HasFlag(wxLC_SMALL_ICON
) )
3835 iconSpacing
= m_small_spacing
;
3839 // Note that we do not call GetClientSize() here but
3840 // GetSize() and substract the border size for sunken
3841 // borders manually. This is technically incorrect,
3842 // but we need to know the client area's size WITHOUT
3843 // scrollbars here. Since we don't know if there are
3844 // any scrollbars, we use GetSize() instead. Another
3845 // solution would be to call SetScrollbars() here to
3846 // remove the scrollbars and call GetClientSize() then,
3847 // but this might result in flicker and - worse - will
3848 // reset the scrollbars to 0 which is not good at all
3849 // if you resize a dialog/window, but don't want to
3850 // reset the window scrolling. RR.
3851 // Furthermore, we actually do NOT subtract the border
3852 // width as 2 pixels is just the extra space which we
3853 // need around the actual content in the window. Other-
3854 // wise the text would e.g. touch the upper border. RR.
3857 GetSize( &clientWidth
, &clientHeight
);
3859 if ( HasFlag(wxLC_REPORT
) )
3861 // all lines have the same height
3862 int lineHeight
= GetLineHeight();
3864 // scroll one line per step
3865 m_yScroll
= lineHeight
;
3867 size_t lineCount
= GetItemCount();
3868 int entireHeight
= lineCount
*lineHeight
+ LINE_SPACING
;
3870 m_linesPerPage
= clientHeight
/ lineHeight
;
3872 ResetVisibleLinesRange();
3874 SetScrollbars( m_xScroll
, m_yScroll
,
3875 GetHeaderWidth() / m_xScroll
,
3876 (entireHeight
+ m_yScroll
- 1)/m_yScroll
,
3877 GetScrollPos(wxHORIZONTAL
),
3878 GetScrollPos(wxVERTICAL
),
3883 // at first we try without any scrollbar. if the items don't
3884 // fit into the window, we recalculate after subtracting an
3885 // approximated 15 pt for the horizontal scrollbar
3887 int entireWidth
= 0;
3889 for (int tries
= 0; tries
< 2; tries
++)
3891 // We start with 4 for the border around all items
3896 // Now we have decided that the items do not fit into the
3897 // client area. Unfortunately, wxWindows sometimes thinks
3898 // that it does fit and therefore NO horizontal scrollbar
3899 // is inserted. This looks ugly, so we fudge here and make
3900 // the calculated width bigger than was actually has been
3901 // calculated. This ensures that wxScrolledWindows puts
3902 // a scrollbar at the bottom of its client area.
3903 entireWidth
+= SCROLL_UNIT_X
;
3906 // Start at 2,2 so the text does not touch the border
3911 int currentlyVisibleLines
= 0;
3913 size_t count
= GetItemCount();
3914 for (size_t i
= 0; i
< count
; i
++)
3916 currentlyVisibleLines
++;
3917 wxListLineData
*line
= GetLine(i
);
3918 line
->CalculateSize( &dc
, iconSpacing
);
3919 line
->SetPosition( x
, y
, clientWidth
, iconSpacing
); // Why clientWidth? (FIXME)
3921 wxSize sizeLine
= GetLineSize(i
);
3923 if ( maxWidth
< sizeLine
.x
)
3924 maxWidth
= sizeLine
.x
;
3927 if (currentlyVisibleLines
> m_linesPerPage
)
3928 m_linesPerPage
= currentlyVisibleLines
;
3930 // Assume that the size of the next one is the same... (FIXME)
3931 if ( y
+ sizeLine
.y
>= clientHeight
)
3933 currentlyVisibleLines
= 0;
3936 entireWidth
+= maxWidth
+6;
3940 // We have reached the last item.
3941 if ( i
== count
- 1 )
3942 entireWidth
+= maxWidth
;
3944 if ( (tries
== 0) && (entireWidth
+SCROLL_UNIT_X
> clientWidth
) )
3946 clientHeight
-= 15; // We guess the scrollbar height. (FIXME)
3948 currentlyVisibleLines
= 0;
3952 if ( i
== count
- 1 )
3953 tries
= 1; // Everything fits, no second try required.
3957 int scroll_pos
= GetScrollPos( wxHORIZONTAL
);
3958 SetScrollbars( m_xScroll
, m_yScroll
, (entireWidth
+SCROLL_UNIT_X
) / m_xScroll
, 0, scroll_pos
, 0, TRUE
);
3963 // FIXME: why should we call it from here?
3970 void wxListMainWindow::RefreshAll()
3975 wxListHeaderWindow
*headerWin
= GetListCtrl()->m_headerWin
;
3976 if ( headerWin
&& headerWin
->m_dirty
)
3978 headerWin
->m_dirty
= FALSE
;
3979 headerWin
->Refresh();
3983 void wxListMainWindow::UpdateCurrent()
3985 if ( !HasCurrent() && !IsEmpty() )
3991 long wxListMainWindow::GetNextItem( long item
,
3992 int WXUNUSED(geometry
),
3996 max
= GetItemCount();
3997 wxCHECK_MSG( (ret
== -1) || (ret
< max
), -1,
3998 _T("invalid listctrl index in GetNextItem()") );
4000 // notice that we start with the next item (or the first one if item == -1)
4001 // and this is intentional to allow writing a simple loop to iterate over
4002 // all selected items
4006 // this is not an error because the index was ok initially, just no
4017 size_t count
= GetItemCount();
4018 for ( size_t line
= (size_t)ret
; line
< count
; line
++ )
4020 if ( (state
& wxLIST_STATE_FOCUSED
) && (line
== m_current
) )
4023 if ( (state
& wxLIST_STATE_SELECTED
) && IsHighlighted(line
) )
4030 // ----------------------------------------------------------------------------
4032 // ----------------------------------------------------------------------------
4034 void wxListMainWindow::DeleteItem( long lindex
)
4036 size_t count
= GetItemCount();
4038 wxCHECK_RET( (lindex
>= 0) && ((size_t)lindex
< count
),
4039 _T("invalid item index in DeleteItem") );
4041 size_t index
= (size_t)lindex
;
4043 // we don't need to adjust the index for the previous items
4044 if ( HasCurrent() && m_current
>= index
)
4046 // if the current item is being deleted, we want the next one to
4047 // become selected - unless there is no next one - so don't adjust
4048 // m_current in this case
4049 if ( m_current
!= index
|| m_current
== count
- 1 )
4055 if ( InReportView() )
4057 ResetVisibleLinesRange();
4064 m_selStore
.OnItemDelete(index
);
4068 m_lines
.RemoveAt( index
);
4071 // we need to refresh the (vert) scrollbar as the number of items changed
4074 SendNotify( index
, wxEVT_COMMAND_LIST_DELETE_ITEM
);
4076 RefreshAfter(index
);
4079 void wxListMainWindow::DeleteColumn( int col
)
4081 wxListHeaderDataList::Node
*node
= m_columns
.Item( col
);
4083 wxCHECK_RET( node
, wxT("invalid column index in DeleteColumn()") );
4086 m_columns
.DeleteNode( node
);
4088 // invalidate it as it has to be recalculated
4092 void wxListMainWindow::DoDeleteAllItems()
4096 // nothing to do - in particular, don't send the event
4102 // to make the deletion of all items faster, we don't send the
4103 // notifications for each item deletion in this case but only one event
4104 // for all of them: this is compatible with wxMSW and documented in
4105 // DeleteAllItems() description
4107 wxListEvent
event( wxEVT_COMMAND_LIST_DELETE_ALL_ITEMS
, GetParent()->GetId() );
4108 event
.SetEventObject( GetParent() );
4109 GetParent()->GetEventHandler()->ProcessEvent( event
);
4118 if ( InReportView() )
4120 ResetVisibleLinesRange();
4126 void wxListMainWindow::DeleteAllItems()
4130 RecalculatePositions();
4133 void wxListMainWindow::DeleteEverything()
4140 // ----------------------------------------------------------------------------
4141 // scanning for an item
4142 // ----------------------------------------------------------------------------
4144 void wxListMainWindow::EnsureVisible( long index
)
4146 wxCHECK_RET( index
>= 0 && (size_t)index
< GetItemCount(),
4147 _T("invalid index in EnsureVisible") );
4149 // We have to call this here because the label in question might just have
4150 // been added and its position is not known yet
4153 RecalculatePositions(TRUE
/* no refresh */);
4156 MoveToItem((size_t)index
);
4159 long wxListMainWindow::FindItem(long start
, const wxString
& str
, bool WXUNUSED(partial
) )
4166 size_t count
= GetItemCount();
4167 for ( size_t i
= (size_t)pos
; i
< count
; i
++ )
4169 wxListLineData
*line
= GetLine(i
);
4170 if ( line
->GetText(0) == tmp
)
4177 long wxListMainWindow::FindItem(long start
, long data
)
4183 size_t count
= GetItemCount();
4184 for (size_t i
= (size_t)pos
; i
< count
; i
++)
4186 wxListLineData
*line
= GetLine(i
);
4188 line
->GetItem( 0, item
);
4189 if (item
.m_data
== data
)
4196 long wxListMainWindow::HitTest( int x
, int y
, int &flags
)
4198 CalcUnscrolledPosition( x
, y
, &x
, &y
);
4200 size_t count
= GetItemCount();
4202 if ( HasFlag(wxLC_REPORT
) )
4204 size_t current
= y
/ GetLineHeight();
4205 if ( current
< count
)
4207 flags
= HitTestLine(current
, x
, y
);
4214 // TODO: optimize it too! this is less simple than for report view but
4215 // enumerating all items is still not a way to do it!!
4216 for ( size_t current
= 0; current
< count
; current
++ )
4218 flags
= HitTestLine(current
, x
, y
);
4227 // ----------------------------------------------------------------------------
4229 // ----------------------------------------------------------------------------
4231 void wxListMainWindow::InsertItem( wxListItem
&item
)
4233 wxASSERT_MSG( !IsVirtual(), _T("can't be used with virtual control") );
4235 size_t count
= GetItemCount();
4236 wxCHECK_RET( item
.m_itemId
>= 0 && (size_t)item
.m_itemId
<= count
,
4237 _T("invalid item index") );
4239 size_t id
= item
.m_itemId
;
4244 if ( HasFlag(wxLC_REPORT
) )
4247 ResetVisibleLinesRange();
4249 else if ( HasFlag(wxLC_LIST
) )
4251 else if ( HasFlag(wxLC_ICON
) )
4253 else if ( HasFlag(wxLC_SMALL_ICON
) )
4254 mode
= wxLC_ICON
; // no typo
4257 wxFAIL_MSG( _T("unknown mode") );
4260 wxListLineData
*line
= new wxListLineData(this);
4262 line
->SetItem( 0, item
);
4264 m_lines
.Insert( line
, id
);
4268 SendNotify(id
, wxEVT_COMMAND_LIST_INSERT_ITEM
);
4270 RefreshLines(id
, GetItemCount() - 1);
4273 void wxListMainWindow::InsertColumn( long col
, wxListItem
&item
)
4276 if ( HasFlag(wxLC_REPORT
) )
4278 if (item
.m_width
== wxLIST_AUTOSIZE_USEHEADER
)
4279 item
.m_width
= GetTextLength( item
.m_text
);
4280 wxListHeaderData
*column
= new wxListHeaderData( item
);
4281 if ((col
>= 0) && (col
< (int)m_columns
.GetCount()))
4283 wxListHeaderDataList::Node
*node
= m_columns
.Item( col
);
4284 m_columns
.Insert( node
, column
);
4288 m_columns
.Append( column
);
4291 // invalidate it as it has to be recalculated
4296 // ----------------------------------------------------------------------------
4298 // ----------------------------------------------------------------------------
4300 wxListCtrlCompare list_ctrl_compare_func_2
;
4301 long list_ctrl_compare_data
;
4303 int LINKAGEMODE
list_ctrl_compare_func_1( wxListLineData
**arg1
, wxListLineData
**arg2
)
4305 wxListLineData
*line1
= *arg1
;
4306 wxListLineData
*line2
= *arg2
;
4308 line1
->GetItem( 0, item
);
4309 long data1
= item
.m_data
;
4310 line2
->GetItem( 0, item
);
4311 long data2
= item
.m_data
;
4312 return list_ctrl_compare_func_2( data1
, data2
, list_ctrl_compare_data
);
4315 void wxListMainWindow::SortItems( wxListCtrlCompare fn
, long data
)
4317 list_ctrl_compare_func_2
= fn
;
4318 list_ctrl_compare_data
= data
;
4319 m_lines
.Sort( list_ctrl_compare_func_1
);
4323 // ----------------------------------------------------------------------------
4325 // ----------------------------------------------------------------------------
4327 void wxListMainWindow::OnScroll(wxScrollWinEvent
& event
)
4329 // update our idea of which lines are shown when we redraw the window the
4331 ResetVisibleLinesRange();
4334 #if defined(__WXGTK__) && !defined(__WXUNIVERSAL__)
4335 wxScrolledWindow::OnScroll(event
);
4337 HandleOnScroll( event
);
4340 if ( event
.GetOrientation() == wxHORIZONTAL
&& HasHeader() )
4342 wxGenericListCtrl
* lc
= GetListCtrl();
4343 wxCHECK_RET( lc
, _T("no listctrl window?") );
4345 lc
->m_headerWin
->Refresh();
4346 lc
->m_headerWin
->Update();
4350 int wxListMainWindow::GetCountPerPage() const
4352 if ( !m_linesPerPage
)
4354 wxConstCast(this, wxListMainWindow
)->
4355 m_linesPerPage
= GetClientSize().y
/ GetLineHeight();
4358 return m_linesPerPage
;
4361 void wxListMainWindow::GetVisibleLinesRange(size_t *from
, size_t *to
)
4363 wxASSERT_MSG( HasFlag(wxLC_REPORT
), _T("this is for report mode only") );
4365 if ( m_lineFrom
== (size_t)-1 )
4367 size_t count
= GetItemCount();
4370 m_lineFrom
= GetScrollPos(wxVERTICAL
);
4372 // this may happen if SetScrollbars() hadn't been called yet
4373 if ( m_lineFrom
>= count
)
4374 m_lineFrom
= count
- 1;
4376 // we redraw one extra line but this is needed to make the redrawing
4377 // logic work when there is a fractional number of lines on screen
4378 m_lineTo
= m_lineFrom
+ m_linesPerPage
;
4379 if ( m_lineTo
>= count
)
4380 m_lineTo
= count
- 1;
4382 else // empty control
4385 m_lineTo
= (size_t)-1;
4389 wxASSERT_MSG( IsEmpty() ||
4390 (m_lineFrom
<= m_lineTo
&& m_lineTo
< GetItemCount()),
4391 _T("GetVisibleLinesRange() returns incorrect result") );
4399 // -------------------------------------------------------------------------------------
4400 // wxGenericListCtrl
4401 // -------------------------------------------------------------------------------------
4403 IMPLEMENT_DYNAMIC_CLASS(wxGenericListCtrl
, wxControl
)
4405 BEGIN_EVENT_TABLE(wxGenericListCtrl
,wxControl
)
4406 EVT_SIZE(wxGenericListCtrl::OnSize
)
4407 EVT_IDLE(wxGenericListCtrl::OnIdle
)
4410 wxGenericListCtrl::wxGenericListCtrl()
4412 m_imageListNormal
= (wxImageListType
*) NULL
;
4413 m_imageListSmall
= (wxImageListType
*) NULL
;
4414 m_imageListState
= (wxImageListType
*) NULL
;
4416 m_ownsImageListNormal
=
4417 m_ownsImageListSmall
=
4418 m_ownsImageListState
= FALSE
;
4420 m_mainWin
= (wxListMainWindow
*) NULL
;
4421 m_headerWin
= (wxListHeaderWindow
*) NULL
;
4424 wxGenericListCtrl::~wxGenericListCtrl()
4426 if (m_ownsImageListNormal
)
4427 delete m_imageListNormal
;
4428 if (m_ownsImageListSmall
)
4429 delete m_imageListSmall
;
4430 if (m_ownsImageListState
)
4431 delete m_imageListState
;
4434 void wxGenericListCtrl::CreateHeaderWindow()
4436 m_headerWin
= new wxListHeaderWindow
4438 this, -1, m_mainWin
,
4440 wxSize(GetClientSize().x
, HEADER_HEIGHT
),
4445 bool wxGenericListCtrl::Create(wxWindow
*parent
,
4450 const wxValidator
&validator
,
4451 const wxString
&name
)
4455 m_imageListState
= (wxImageListType
*) NULL
;
4456 m_ownsImageListNormal
=
4457 m_ownsImageListSmall
=
4458 m_ownsImageListState
= FALSE
;
4460 m_mainWin
= (wxListMainWindow
*) NULL
;
4461 m_headerWin
= (wxListHeaderWindow
*) NULL
;
4463 if ( !(style
& wxLC_MASK_TYPE
) )
4465 style
= style
| wxLC_LIST
;
4468 if ( !wxControl::Create( parent
, id
, pos
, size
, style
, validator
, name
) )
4471 // don't create the inner window with the border
4472 style
&= ~wxBORDER_MASK
;
4474 m_mainWin
= new wxListMainWindow( this, -1, wxPoint(0,0), size
, style
);
4476 if ( HasFlag(wxLC_REPORT
) )
4478 CreateHeaderWindow();
4480 if ( HasFlag(wxLC_NO_HEADER
) )
4482 // VZ: why do we create it at all then?
4483 m_headerWin
->Show( FALSE
);
4490 void wxGenericListCtrl::SetSingleStyle( long style
, bool add
)
4492 wxASSERT_MSG( !(style
& wxLC_VIRTUAL
),
4493 _T("wxLC_VIRTUAL can't be [un]set") );
4495 long flag
= GetWindowStyle();
4499 if (style
& wxLC_MASK_TYPE
)
4500 flag
&= ~(wxLC_MASK_TYPE
| wxLC_VIRTUAL
);
4501 if (style
& wxLC_MASK_ALIGN
)
4502 flag
&= ~wxLC_MASK_ALIGN
;
4503 if (style
& wxLC_MASK_SORT
)
4504 flag
&= ~wxLC_MASK_SORT
;
4516 SetWindowStyleFlag( flag
);
4519 void wxGenericListCtrl::SetWindowStyleFlag( long flag
)
4523 m_mainWin
->DeleteEverything();
4525 // has the header visibility changed?
4526 bool hasHeader
= HasFlag(wxLC_REPORT
) && !HasFlag(wxLC_NO_HEADER
),
4527 willHaveHeader
= (flag
& wxLC_REPORT
) && !(flag
& wxLC_NO_HEADER
);
4529 if ( hasHeader
!= willHaveHeader
)
4536 // don't delete, just hide, as we can reuse it later
4537 m_headerWin
->Show(FALSE
);
4539 //else: nothing to do
4541 else // must show header
4545 CreateHeaderWindow();
4547 else // already have it, just show
4549 m_headerWin
->Show( TRUE
);
4553 ResizeReportView(willHaveHeader
);
4557 wxWindow::SetWindowStyleFlag( flag
);
4560 bool wxGenericListCtrl::GetColumn(int col
, wxListItem
&item
) const
4562 m_mainWin
->GetColumn( col
, item
);
4566 bool wxGenericListCtrl::SetColumn( int col
, wxListItem
& item
)
4568 m_mainWin
->SetColumn( col
, item
);
4572 int wxGenericListCtrl::GetColumnWidth( int col
) const
4574 return m_mainWin
->GetColumnWidth( col
);
4577 bool wxGenericListCtrl::SetColumnWidth( int col
, int width
)
4579 m_mainWin
->SetColumnWidth( col
, width
);
4583 int wxGenericListCtrl::GetCountPerPage() const
4585 return m_mainWin
->GetCountPerPage(); // different from Windows ?
4588 bool wxGenericListCtrl::GetItem( wxListItem
&info
) const
4590 m_mainWin
->GetItem( info
);
4594 bool wxGenericListCtrl::SetItem( wxListItem
&info
)
4596 m_mainWin
->SetItem( info
);
4600 long wxGenericListCtrl::SetItem( long index
, int col
, const wxString
& label
, int imageId
)
4603 info
.m_text
= label
;
4604 info
.m_mask
= wxLIST_MASK_TEXT
;
4605 info
.m_itemId
= index
;
4609 info
.m_image
= imageId
;
4610 info
.m_mask
|= wxLIST_MASK_IMAGE
;
4612 m_mainWin
->SetItem(info
);
4616 int wxGenericListCtrl::GetItemState( long item
, long stateMask
) const
4618 return m_mainWin
->GetItemState( item
, stateMask
);
4621 bool wxGenericListCtrl::SetItemState( long item
, long state
, long stateMask
)
4623 m_mainWin
->SetItemState( item
, state
, stateMask
);
4627 bool wxGenericListCtrl::SetItemImage( long item
, int image
, int WXUNUSED(selImage
) )
4630 info
.m_image
= image
;
4631 info
.m_mask
= wxLIST_MASK_IMAGE
;
4632 info
.m_itemId
= item
;
4633 m_mainWin
->SetItem( info
);
4637 wxString
wxGenericListCtrl::GetItemText( long item
) const
4639 return m_mainWin
->GetItemText(item
);
4642 void wxGenericListCtrl::SetItemText( long item
, const wxString
& str
)
4644 m_mainWin
->SetItemText(item
, str
);
4647 long wxGenericListCtrl::GetItemData( long item
) const
4650 info
.m_itemId
= item
;
4651 m_mainWin
->GetItem( info
);
4655 bool wxGenericListCtrl::SetItemData( long item
, long data
)
4658 info
.m_mask
= wxLIST_MASK_DATA
;
4659 info
.m_itemId
= item
;
4661 m_mainWin
->SetItem( info
);
4665 bool wxGenericListCtrl::GetItemRect( long item
, wxRect
&rect
, int WXUNUSED(code
) ) const
4667 m_mainWin
->GetItemRect( item
, rect
);
4668 if ( m_mainWin
->HasHeader() )
4669 rect
.y
+= HEADER_HEIGHT
+ 1;
4673 bool wxGenericListCtrl::GetItemPosition( long item
, wxPoint
& pos
) const
4675 m_mainWin
->GetItemPosition( item
, pos
);
4679 bool wxGenericListCtrl::SetItemPosition( long WXUNUSED(item
), const wxPoint
& WXUNUSED(pos
) )
4684 int wxGenericListCtrl::GetItemCount() const
4686 return m_mainWin
->GetItemCount();
4689 int wxGenericListCtrl::GetColumnCount() const
4691 return m_mainWin
->GetColumnCount();
4694 void wxGenericListCtrl::SetItemSpacing( int spacing
, bool isSmall
)
4696 m_mainWin
->SetItemSpacing( spacing
, isSmall
);
4699 int wxGenericListCtrl::GetItemSpacing( bool isSmall
) const
4701 return m_mainWin
->GetItemSpacing( isSmall
);
4704 void wxGenericListCtrl::SetItemTextColour( long item
, const wxColour
&col
)
4707 info
.m_itemId
= item
;
4708 info
.SetTextColour( col
);
4709 m_mainWin
->SetItem( info
);
4712 wxColour
wxGenericListCtrl::GetItemTextColour( long item
) const
4715 info
.m_itemId
= item
;
4716 m_mainWin
->GetItem( info
);
4717 return info
.GetTextColour();
4720 void wxGenericListCtrl::SetItemBackgroundColour( long item
, const wxColour
&col
)
4723 info
.m_itemId
= item
;
4724 info
.SetBackgroundColour( col
);
4725 m_mainWin
->SetItem( info
);
4728 wxColour
wxGenericListCtrl::GetItemBackgroundColour( long item
) const
4731 info
.m_itemId
= item
;
4732 m_mainWin
->GetItem( info
);
4733 return info
.GetBackgroundColour();
4736 int wxGenericListCtrl::GetSelectedItemCount() const
4738 return m_mainWin
->GetSelectedItemCount();
4741 wxColour
wxGenericListCtrl::GetTextColour() const
4743 return GetForegroundColour();
4746 void wxGenericListCtrl::SetTextColour(const wxColour
& col
)
4748 SetForegroundColour(col
);
4751 long wxGenericListCtrl::GetTopItem() const
4754 m_mainWin
->GetVisibleLinesRange(&top
, NULL
);
4758 long wxGenericListCtrl::GetNextItem( long item
, int geom
, int state
) const
4760 return m_mainWin
->GetNextItem( item
, geom
, state
);
4763 wxImageListType
*wxGenericListCtrl::GetImageList(int which
) const
4765 if (which
== wxIMAGE_LIST_NORMAL
)
4767 return m_imageListNormal
;
4769 else if (which
== wxIMAGE_LIST_SMALL
)
4771 return m_imageListSmall
;
4773 else if (which
== wxIMAGE_LIST_STATE
)
4775 return m_imageListState
;
4777 return (wxImageListType
*) NULL
;
4780 void wxGenericListCtrl::SetImageList( wxImageListType
*imageList
, int which
)
4782 if ( which
== wxIMAGE_LIST_NORMAL
)
4784 if (m_ownsImageListNormal
) delete m_imageListNormal
;
4785 m_imageListNormal
= imageList
;
4786 m_ownsImageListNormal
= FALSE
;
4788 else if ( which
== wxIMAGE_LIST_SMALL
)
4790 if (m_ownsImageListSmall
) delete m_imageListSmall
;
4791 m_imageListSmall
= imageList
;
4792 m_ownsImageListSmall
= FALSE
;
4794 else if ( which
== wxIMAGE_LIST_STATE
)
4796 if (m_ownsImageListState
) delete m_imageListState
;
4797 m_imageListState
= imageList
;
4798 m_ownsImageListState
= FALSE
;
4801 m_mainWin
->SetImageList( imageList
, which
);
4804 void wxGenericListCtrl::AssignImageList(wxImageListType
*imageList
, int which
)
4806 SetImageList(imageList
, which
);
4807 if ( which
== wxIMAGE_LIST_NORMAL
)
4808 m_ownsImageListNormal
= TRUE
;
4809 else if ( which
== wxIMAGE_LIST_SMALL
)
4810 m_ownsImageListSmall
= TRUE
;
4811 else if ( which
== wxIMAGE_LIST_STATE
)
4812 m_ownsImageListState
= TRUE
;
4815 bool wxGenericListCtrl::Arrange( int WXUNUSED(flag
) )
4820 bool wxGenericListCtrl::DeleteItem( long item
)
4822 m_mainWin
->DeleteItem( item
);
4826 bool wxGenericListCtrl::DeleteAllItems()
4828 m_mainWin
->DeleteAllItems();
4832 bool wxGenericListCtrl::DeleteAllColumns()
4834 size_t count
= m_mainWin
->m_columns
.GetCount();
4835 for ( size_t n
= 0; n
< count
; n
++ )
4841 void wxGenericListCtrl::ClearAll()
4843 m_mainWin
->DeleteEverything();
4846 bool wxGenericListCtrl::DeleteColumn( int col
)
4848 m_mainWin
->DeleteColumn( col
);
4850 // if we don't have the header any longer, we need to relayout the window
4851 if ( !GetColumnCount() )
4853 ResizeReportView(FALSE
/* no header */);
4859 void wxGenericListCtrl::Edit( long item
)
4861 m_mainWin
->EditLabel( item
);
4864 bool wxGenericListCtrl::EnsureVisible( long item
)
4866 m_mainWin
->EnsureVisible( item
);
4870 long wxGenericListCtrl::FindItem( long start
, const wxString
& str
, bool partial
)
4872 return m_mainWin
->FindItem( start
, str
, partial
);
4875 long wxGenericListCtrl::FindItem( long start
, long data
)
4877 return m_mainWin
->FindItem( start
, data
);
4880 long wxGenericListCtrl::FindItem( long WXUNUSED(start
), const wxPoint
& WXUNUSED(pt
),
4881 int WXUNUSED(direction
))
4886 long wxGenericListCtrl::HitTest( const wxPoint
&point
, int &flags
)
4888 return m_mainWin
->HitTest( (int)point
.x
, (int)point
.y
, flags
);
4891 long wxGenericListCtrl::InsertItem( wxListItem
& info
)
4893 m_mainWin
->InsertItem( info
);
4894 return info
.m_itemId
;
4897 long wxGenericListCtrl::InsertItem( long index
, const wxString
&label
)
4900 info
.m_text
= label
;
4901 info
.m_mask
= wxLIST_MASK_TEXT
;
4902 info
.m_itemId
= index
;
4903 return InsertItem( info
);
4906 long wxGenericListCtrl::InsertItem( long index
, int imageIndex
)
4909 info
.m_mask
= wxLIST_MASK_IMAGE
;
4910 info
.m_image
= imageIndex
;
4911 info
.m_itemId
= index
;
4912 return InsertItem( info
);
4915 long wxGenericListCtrl::InsertItem( long index
, const wxString
&label
, int imageIndex
)
4918 info
.m_text
= label
;
4919 info
.m_image
= imageIndex
;
4920 info
.m_mask
= wxLIST_MASK_TEXT
| wxLIST_MASK_IMAGE
;
4921 info
.m_itemId
= index
;
4922 return InsertItem( info
);
4925 long wxGenericListCtrl::InsertColumn( long col
, wxListItem
&item
)
4927 wxCHECK_MSG( m_headerWin
, -1, _T("can't add column in non report mode") );
4929 m_mainWin
->InsertColumn( col
, item
);
4931 // if we hadn't had header before and have it now we need to relayout the
4933 if ( GetColumnCount() == 1 && m_mainWin
->HasHeader() )
4935 ResizeReportView(TRUE
/* have header */);
4938 m_headerWin
->Refresh();
4943 long wxGenericListCtrl::InsertColumn( long col
, const wxString
&heading
,
4944 int format
, int width
)
4947 item
.m_mask
= wxLIST_MASK_TEXT
| wxLIST_MASK_FORMAT
;
4948 item
.m_text
= heading
;
4951 item
.m_mask
|= wxLIST_MASK_WIDTH
;
4952 item
.m_width
= width
;
4954 item
.m_format
= format
;
4956 return InsertColumn( col
, item
);
4959 bool wxGenericListCtrl::ScrollList( int WXUNUSED(dx
), int WXUNUSED(dy
) )
4965 // fn is a function which takes 3 long arguments: item1, item2, data.
4966 // item1 is the long data associated with a first item (NOT the index).
4967 // item2 is the long data associated with a second item (NOT the index).
4968 // data is the same value as passed to SortItems.
4969 // The return value is a negative number if the first item should precede the second
4970 // item, a positive number of the second item should precede the first,
4971 // or zero if the two items are equivalent.
4972 // data is arbitrary data to be passed to the sort function.
4974 bool wxGenericListCtrl::SortItems( wxListCtrlCompare fn
, long data
)
4976 m_mainWin
->SortItems( fn
, data
);
4980 // ----------------------------------------------------------------------------
4982 // ----------------------------------------------------------------------------
4984 void wxGenericListCtrl::OnSize(wxSizeEvent
& WXUNUSED(event
))
4989 ResizeReportView(m_mainWin
->HasHeader());
4991 m_mainWin
->RecalculatePositions();
4994 void wxGenericListCtrl::ResizeReportView(bool showHeader
)
4997 GetClientSize( &cw
, &ch
);
5001 m_headerWin
->SetSize( 0, 0, cw
, HEADER_HEIGHT
);
5002 m_mainWin
->SetSize( 0, HEADER_HEIGHT
+ 1, cw
, ch
- HEADER_HEIGHT
- 1 );
5004 else // no header window
5006 m_mainWin
->SetSize( 0, 0, cw
, ch
);
5010 void wxGenericListCtrl::OnIdle( wxIdleEvent
& event
)
5014 // do it only if needed
5015 if ( !m_mainWin
->m_dirty
)
5018 m_mainWin
->RecalculatePositions();
5021 // ----------------------------------------------------------------------------
5023 // ----------------------------------------------------------------------------
5025 bool wxGenericListCtrl::SetBackgroundColour( const wxColour
&colour
)
5029 m_mainWin
->SetBackgroundColour( colour
);
5030 m_mainWin
->m_dirty
= TRUE
;
5036 bool wxGenericListCtrl::SetForegroundColour( const wxColour
&colour
)
5038 if ( !wxWindow::SetForegroundColour( colour
) )
5043 m_mainWin
->SetForegroundColour( colour
);
5044 m_mainWin
->m_dirty
= TRUE
;
5049 m_headerWin
->SetForegroundColour( colour
);
5055 bool wxGenericListCtrl::SetFont( const wxFont
&font
)
5057 if ( !wxWindow::SetFont( font
) )
5062 m_mainWin
->SetFont( font
);
5063 m_mainWin
->m_dirty
= TRUE
;
5068 m_headerWin
->SetFont( font
);
5074 // ----------------------------------------------------------------------------
5075 // methods forwarded to m_mainWin
5076 // ----------------------------------------------------------------------------
5078 #if wxUSE_DRAG_AND_DROP
5080 void wxGenericListCtrl::SetDropTarget( wxDropTarget
*dropTarget
)
5082 m_mainWin
->SetDropTarget( dropTarget
);
5085 wxDropTarget
*wxGenericListCtrl::GetDropTarget() const
5087 return m_mainWin
->GetDropTarget();
5090 #endif // wxUSE_DRAG_AND_DROP
5092 bool wxGenericListCtrl::SetCursor( const wxCursor
&cursor
)
5094 return m_mainWin
? m_mainWin
->wxWindow::SetCursor(cursor
) : FALSE
;
5097 wxColour
wxGenericListCtrl::GetBackgroundColour() const
5099 return m_mainWin
? m_mainWin
->GetBackgroundColour() : wxColour();
5102 wxColour
wxGenericListCtrl::GetForegroundColour() const
5104 return m_mainWin
? m_mainWin
->GetForegroundColour() : wxColour();
5107 bool wxGenericListCtrl::DoPopupMenu( wxMenu
*menu
, int x
, int y
)
5110 return m_mainWin
->PopupMenu( menu
, x
, y
);
5113 #endif // wxUSE_MENUS
5116 void wxGenericListCtrl::SetFocus()
5118 /* The test in window.cpp fails as we are a composite
5119 window, so it checks against "this", but not m_mainWin. */
5120 if ( FindFocus() != this )
5121 m_mainWin
->SetFocus();
5124 // ----------------------------------------------------------------------------
5125 // virtual list control support
5126 // ----------------------------------------------------------------------------
5128 wxString
wxGenericListCtrl::OnGetItemText(long WXUNUSED(item
), long WXUNUSED(col
)) const
5130 // this is a pure virtual function, in fact - which is not really pure
5131 // because the controls which are not virtual don't need to implement it
5132 wxFAIL_MSG( _T("wxGenericListCtrl::OnGetItemText not supposed to be called") );
5134 return wxEmptyString
;
5137 int wxGenericListCtrl::OnGetItemImage(long WXUNUSED(item
)) const
5140 wxFAIL_MSG( _T("wxGenericListCtrl::OnGetItemImage not supposed to be called") );
5145 wxListItemAttr
*wxGenericListCtrl::OnGetItemAttr(long item
) const
5147 wxASSERT_MSG( item
>= 0 && item
< GetItemCount(),
5148 _T("invalid item index in OnGetItemAttr()") );
5150 // no attributes by default
5154 void wxGenericListCtrl::SetItemCount(long count
)
5156 wxASSERT_MSG( IsVirtual(), _T("this is for virtual controls only") );
5158 m_mainWin
->SetItemCount(count
);
5161 void wxGenericListCtrl::RefreshItem(long item
)
5163 m_mainWin
->RefreshLine(item
);
5166 void wxGenericListCtrl::RefreshItems(long itemFrom
, long itemTo
)
5168 m_mainWin
->RefreshLines(itemFrom
, itemTo
);
5171 void wxGenericListCtrl::Freeze()
5173 m_mainWin
->Freeze();
5176 void wxGenericListCtrl::Thaw()
5181 #endif // wxUSE_LISTCTRL