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 // ----------------------------------------------------------------------------
26 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
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 #include "wx/selstore.h"
73 #include "wx/renderer.h"
75 // ----------------------------------------------------------------------------
77 // ----------------------------------------------------------------------------
79 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_BEGIN_DRAG
)
80 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_BEGIN_RDRAG
)
81 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_BEGIN_LABEL_EDIT
)
82 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_END_LABEL_EDIT
)
83 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_DELETE_ITEM
)
84 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_DELETE_ALL_ITEMS
)
85 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_GET_INFO
)
86 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_SET_INFO
)
87 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_ITEM_SELECTED
)
88 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_ITEM_DESELECTED
)
89 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_KEY_DOWN
)
90 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_INSERT_ITEM
)
91 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_COL_CLICK
)
92 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_COL_RIGHT_CLICK
)
93 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_COL_BEGIN_DRAG
)
94 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_COL_DRAGGING
)
95 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_COL_END_DRAG
)
96 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_ITEM_RIGHT_CLICK
)
97 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_ITEM_MIDDLE_CLICK
)
98 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_ITEM_ACTIVATED
)
99 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_ITEM_FOCUSED
)
100 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_CACHE_HINT
)
102 // ----------------------------------------------------------------------------
104 // ----------------------------------------------------------------------------
106 // the height of the header window (FIXME: should depend on its font!)
107 static const int HEADER_HEIGHT
= 23;
109 // the scrollbar units
110 static const int SCROLL_UNIT_X
= 15;
111 static const int SCROLL_UNIT_Y
= 15;
113 // the spacing between the lines (in report mode)
114 static const int LINE_SPACING
= 0;
116 // extra margins around the text label
117 static const int EXTRA_WIDTH
= 3;
118 static const int EXTRA_HEIGHT
= 4;
120 // offset for the header window
121 static const int HEADER_OFFSET_X
= 1;
122 static const int HEADER_OFFSET_Y
= 1;
124 // when autosizing the columns, add some slack
125 static const int AUTOSIZE_COL_MARGIN
= 10;
127 // default and minimal widths for the header columns
128 static const int WIDTH_COL_DEFAULT
= 80;
129 static const int WIDTH_COL_MIN
= 10;
131 // the space between the image and the text in the report mode
132 static const int IMAGE_MARGIN_IN_REPORT_MODE
= 5;
134 // ============================================================================
136 // ============================================================================
138 //-----------------------------------------------------------------------------
139 // wxListItemData (internal)
140 //-----------------------------------------------------------------------------
142 class WXDLLEXPORT wxListItemData
145 wxListItemData(wxListMainWindow
*owner
);
148 void SetItem( const wxListItem
&info
);
149 void SetImage( int image
) { m_image
= image
; }
150 void SetData( long data
) { m_data
= data
; }
151 void SetPosition( int x
, int y
);
152 void SetSize( int width
, int height
);
154 bool HasText() const { return !m_text
.empty(); }
155 const wxString
& GetText() const { return m_text
; }
156 void SetText(const wxString
& text
) { m_text
= text
; }
158 // we can't use empty string for measuring the string width/height, so
159 // always return something
160 wxString
GetTextForMeasuring() const
162 wxString s
= GetText();
169 bool IsHit( int x
, int y
) const;
173 int GetWidth() const;
174 int GetHeight() const;
176 int GetImage() const { return m_image
; }
177 bool HasImage() const { return GetImage() != -1; }
179 void GetItem( wxListItem
&info
) const;
181 void SetAttr(wxListItemAttr
*attr
) { m_attr
= attr
; }
182 wxListItemAttr
*GetAttr() const { return m_attr
; }
185 // the item image or -1
188 // user data associated with the item
191 // the item coordinates are not used in report mode, instead this pointer
192 // is NULL and the owner window is used to retrieve the item position and
196 // the list ctrl we are in
197 wxListMainWindow
*m_owner
;
199 // custom attributes or NULL
200 wxListItemAttr
*m_attr
;
203 // common part of all ctors
209 //-----------------------------------------------------------------------------
210 // wxListHeaderData (internal)
211 //-----------------------------------------------------------------------------
213 class WXDLLEXPORT wxListHeaderData
: public wxObject
217 wxListHeaderData( const wxListItem
&info
);
218 void SetItem( const wxListItem
&item
);
219 void SetPosition( int x
, int y
);
220 void SetWidth( int w
);
221 void SetFormat( int format
);
222 void SetHeight( int h
);
223 bool HasImage() const;
225 bool HasText() const { return !m_text
.empty(); }
226 const wxString
& GetText() const { return m_text
; }
227 void SetText(const wxString
& text
) { m_text
= text
; }
229 void GetItem( wxListItem
&item
);
231 bool IsHit( int x
, int y
) const;
232 int GetImage() const;
233 int GetWidth() const;
234 int GetFormat() const;
250 //-----------------------------------------------------------------------------
251 // wxListLineData (internal)
252 //-----------------------------------------------------------------------------
254 WX_DECLARE_LIST(wxListItemData
, wxListItemDataList
);
255 #include "wx/listimpl.cpp"
256 WX_DEFINE_LIST(wxListItemDataList
);
261 // the list of subitems: only may have more than one item in report mode
262 wxListItemDataList m_items
;
264 // this is not used in report view
276 // the part to be highlighted
277 wxRect m_rectHighlight
;
280 // is this item selected? [NB: not used in virtual mode]
283 // back pointer to the list ctrl
284 wxListMainWindow
*m_owner
;
287 wxListLineData(wxListMainWindow
*owner
);
291 WX_CLEAR_LIST(wxListItemDataList
, m_items
);
295 // are we in report mode?
296 inline bool InReportView() const;
298 // are we in virtual report mode?
299 inline bool IsVirtual() const;
301 // these 2 methods shouldn't be called for report view controls, in that
302 // case we determine our position/size ourselves
304 // calculate the size of the line
305 void CalculateSize( wxDC
*dc
, int spacing
);
307 // remember the position this line appears at
308 void SetPosition( int x
, int y
, int window_width
, int spacing
);
312 void SetImage( int image
) { SetImage(0, image
); }
313 int GetImage() const { return GetImage(0); }
314 bool HasImage() const { return GetImage() != -1; }
315 bool HasText() const { return !GetText(0).empty(); }
317 void SetItem( int index
, const wxListItem
&info
);
318 void GetItem( int index
, wxListItem
&info
);
320 wxString
GetText(int index
) const;
321 void SetText( int index
, const wxString s
);
323 wxListItemAttr
*GetAttr() const;
324 void SetAttr(wxListItemAttr
*attr
);
326 // return true if the highlighting really changed
327 bool Highlight( bool on
);
329 void ReverseHighlight();
331 bool IsHighlighted() const
333 wxASSERT_MSG( !IsVirtual(), _T("unexpected call to IsHighlighted") );
335 return m_highlighted
;
338 // draw the line on the given DC in icon/list mode
339 void Draw( wxDC
*dc
);
341 // the same in report mode
342 void DrawInReportMode( wxDC
*dc
,
344 const wxRect
& rectHL
,
348 // set the line to contain num items (only can be > 1 in report mode)
349 void InitItems( int num
);
351 // get the mode (i.e. style) of the list control
352 inline int GetMode() const;
354 // prepare the DC for drawing with these item's attributes, return true if
355 // we need to draw the items background to highlight it, false otherwise
356 bool SetAttributes(wxDC
*dc
,
357 const wxListItemAttr
*attr
,
360 // draw the text on the DC with the correct justification; also add an
361 // ellipsis if the text is too large to fit in the current width
362 void DrawTextFormatted(wxDC
*dc
, const wxString
&text
, int col
, int x
, int y
, int width
);
364 // these are only used by GetImage/SetImage above, we don't support images
365 // with subitems at the public API level yet
366 void SetImage( int index
, int image
);
367 int GetImage( int index
) const;
370 WX_DECLARE_EXPORTED_OBJARRAY(wxListLineData
, wxListLineDataArray
);
371 #include "wx/arrimpl.cpp"
372 WX_DEFINE_OBJARRAY(wxListLineDataArray
);
374 //-----------------------------------------------------------------------------
375 // wxListHeaderWindow (internal)
376 //-----------------------------------------------------------------------------
378 class WXDLLEXPORT wxListHeaderWindow
: public wxWindow
381 wxListMainWindow
*m_owner
;
382 wxCursor
*m_currentCursor
;
383 wxCursor
*m_resizeCursor
;
386 // column being resized or -1
389 // divider line position in logical (unscrolled) coords
392 // minimal position beyond which the divider line can't be dragged in
397 wxListHeaderWindow();
399 wxListHeaderWindow( wxWindow
*win
,
401 wxListMainWindow
*owner
,
402 const wxPoint
&pos
= wxDefaultPosition
,
403 const wxSize
&size
= wxDefaultSize
,
405 const wxString
&name
= wxT("wxlistctrlcolumntitles") );
407 virtual ~wxListHeaderWindow();
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 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
);
580 void OnRenameCancelled(size_t itemEdit
);
582 void OnMouse( wxMouseEvent
&event
);
584 // called to switch the selection from the current item to newCurrent,
585 void OnArrowChar( size_t newCurrent
, const wxKeyEvent
& event
);
587 void OnChar( wxKeyEvent
&event
);
588 void OnKeyDown( wxKeyEvent
&event
);
589 void OnSetFocus( wxFocusEvent
&event
);
590 void OnKillFocus( wxFocusEvent
&event
);
591 void OnScroll(wxScrollWinEvent
& event
) ;
593 void OnPaint( wxPaintEvent
&event
);
595 void DrawImage( int index
, wxDC
*dc
, int x
, int y
);
596 void GetImageSize( int index
, int &width
, int &height
) const;
597 int GetTextLength( const wxString
&s
) const;
599 void SetImageList( wxImageListType
*imageList
, int which
);
600 void SetItemSpacing( int spacing
, bool isSmall
= FALSE
);
601 int GetItemSpacing( bool isSmall
= FALSE
);
603 void SetColumn( int col
, wxListItem
&item
);
604 void SetColumnWidth( int col
, int width
);
605 void GetColumn( int col
, wxListItem
&item
) const;
606 int GetColumnWidth( int col
) const;
607 int GetColumnCount() const { return m_columns
.GetCount(); }
609 // returns the sum of the heights of all columns
610 int GetHeaderWidth() const;
612 int GetCountPerPage() const;
614 void SetItem( wxListItem
&item
);
615 void GetItem( wxListItem
&item
) const;
616 void SetItemState( long item
, long state
, long stateMask
);
617 int GetItemState( long item
, long stateMask
) const;
618 void GetItemRect( long index
, wxRect
&rect
) const;
619 bool GetItemPosition( long item
, wxPoint
& pos
) const;
620 int GetSelectedItemCount() const;
622 wxString
GetItemText(long item
) const
625 info
.m_itemId
= item
;
630 void SetItemText(long item
, const wxString
& value
)
633 info
.m_mask
= wxLIST_MASK_TEXT
;
634 info
.m_itemId
= item
;
639 // set the scrollbars and update the positions of the items
640 void RecalculatePositions(bool noRefresh
= FALSE
);
642 // refresh the window and the header
645 long GetNextItem( long item
, int geometry
, int state
) const;
646 void DeleteItem( long index
);
647 void DeleteAllItems();
648 void DeleteColumn( int col
);
649 void DeleteEverything();
650 void EnsureVisible( long index
);
651 long FindItem( long start
, const wxString
& str
, bool partial
= FALSE
);
652 long FindItem( long start
, long data
);
653 long HitTest( int x
, int y
, int &flags
);
654 void InsertItem( wxListItem
&item
);
655 void InsertColumn( long col
, wxListItem
&item
);
656 void SortItems( wxListCtrlCompare fn
, long data
);
658 size_t GetItemCount() const;
659 bool IsEmpty() const { return GetItemCount() == 0; }
660 void SetItemCount(long count
);
662 // change the current (== focused) item, send a notification event
663 void ChangeCurrent(size_t current
);
664 void ResetCurrent() { ChangeCurrent((size_t)-1); }
665 bool HasCurrent() const { return m_current
!= (size_t)-1; }
667 // send out a wxListEvent
668 void SendNotify( size_t line
,
670 wxPoint point
= wxDefaultPosition
);
672 // override base class virtual to reset m_lineHeight when the font changes
673 virtual bool SetFont(const wxFont
& font
)
675 if ( !wxScrolledWindow::SetFont(font
) )
683 // these are for wxListLineData usage only
685 // get the backpointer to the list ctrl
686 wxGenericListCtrl
*GetListCtrl() const
688 return wxStaticCast(GetParent(), wxGenericListCtrl
);
691 // get the height of all lines (assuming they all do have the same height)
692 wxCoord
GetLineHeight() const;
694 // get the y position of the given line (only for report view)
695 wxCoord
GetLineY(size_t line
) const;
697 // get the brush to use for the item highlighting
698 wxBrush
*GetHighlightBrush() const
700 return m_hasFocus
? m_highlightBrush
: m_highlightUnfocusedBrush
;
704 // the array of all line objects for a non virtual list control (for the
705 // virtual list control we only ever use m_lines[0])
706 wxListLineDataArray m_lines
;
708 // the list of column objects
709 wxListHeaderDataList m_columns
;
711 // currently focused item or -1
714 // the number of lines per page
717 // this flag is set when something which should result in the window
718 // redrawing happens (i.e. an item was added or deleted, or its appearance
719 // changed) and OnPaint() doesn't redraw the window while it is set which
720 // allows to minimize the number of repaintings when a lot of items are
721 // being added. The real repainting occurs only after the next OnIdle()
725 wxColour
*m_highlightColour
;
728 wxImageListType
*m_small_image_list
;
729 wxImageListType
*m_normal_image_list
;
731 int m_normal_spacing
;
735 wxTimer
*m_renameTimer
;
740 // for double click logic
741 size_t m_lineLastClicked
,
742 m_lineBeforeLastClicked
;
745 // the total count of items in a virtual list control
748 // the object maintaining the items selection state, only used in virtual
750 wxSelectionStore m_selStore
;
752 // common part of all ctors
755 // intiialize m_[xy]Scroll
756 void InitScrolling();
758 // get the line data for the given index
759 wxListLineData
*GetLine(size_t n
) const
761 wxASSERT_MSG( n
!= (size_t)-1, _T("invalid line index") );
765 wxConstCast(this, wxListMainWindow
)->CacheLineData(n
);
773 // get a dummy line which can be used for geometry calculations and such:
774 // you must use GetLine() if you want to really draw the line
775 wxListLineData
*GetDummyLine() const;
777 // cache the line data of the n-th line in m_lines[0]
778 void CacheLineData(size_t line
);
780 // get the range of visible lines
781 void GetVisibleLinesRange(size_t *from
, size_t *to
);
783 // force us to recalculate the range of visible lines
784 void ResetVisibleLinesRange() { m_lineFrom
= (size_t)-1; }
786 // get the colour to be used for drawing the rules
787 wxColour
GetRuleColour() const
792 return wxSystemSettings::GetColour(wxSYS_COLOUR_3DLIGHT
);
797 // initialize the current item if needed
798 void UpdateCurrent();
800 // delete all items but don't refresh: called from dtor
801 void DoDeleteAllItems();
803 // the height of one line using the current font
804 wxCoord m_lineHeight
;
806 // the total header width or 0 if not calculated yet
807 wxCoord m_headerWidth
;
809 // the first and last lines being shown on screen right now (inclusive),
810 // both may be -1 if they must be calculated so never access them directly:
811 // use GetVisibleLinesRange() above instead
815 // the brushes to use for item highlighting when we do/don't have focus
816 wxBrush
*m_highlightBrush
,
817 *m_highlightUnfocusedBrush
;
819 // if this is > 0, the control is frozen and doesn't redraw itself
820 size_t m_freezeCount
;
822 DECLARE_DYNAMIC_CLASS(wxListMainWindow
)
823 DECLARE_EVENT_TABLE()
825 friend class wxGenericListCtrl
;
828 // ============================================================================
830 // ============================================================================
832 //-----------------------------------------------------------------------------
834 //-----------------------------------------------------------------------------
836 wxListItemData::~wxListItemData()
838 // in the virtual list control the attributes are managed by the main
839 // program, so don't delete them
840 if ( !m_owner
->IsVirtual() )
848 void wxListItemData::Init()
856 wxListItemData::wxListItemData(wxListMainWindow
*owner
)
862 if ( owner
->InReportView() )
872 void wxListItemData::SetItem( const wxListItem
&info
)
874 if ( info
.m_mask
& wxLIST_MASK_TEXT
)
875 SetText(info
.m_text
);
876 if ( info
.m_mask
& wxLIST_MASK_IMAGE
)
877 m_image
= info
.m_image
;
878 if ( info
.m_mask
& wxLIST_MASK_DATA
)
879 m_data
= info
.m_data
;
881 if ( info
.HasAttributes() )
884 *m_attr
= *info
.GetAttributes();
886 m_attr
= new wxListItemAttr(*info
.GetAttributes());
894 m_rect
->width
= info
.m_width
;
898 void wxListItemData::SetPosition( int x
, int y
)
900 wxCHECK_RET( m_rect
, _T("unexpected SetPosition() call") );
906 void wxListItemData::SetSize( int width
, int height
)
908 wxCHECK_RET( m_rect
, _T("unexpected SetSize() call") );
911 m_rect
->width
= width
;
913 m_rect
->height
= height
;
916 bool wxListItemData::IsHit( int x
, int y
) const
918 wxCHECK_MSG( m_rect
, FALSE
, _T("can't be called in this mode") );
920 return wxRect(GetX(), GetY(), GetWidth(), GetHeight()).Inside(x
, y
);
923 int wxListItemData::GetX() const
925 wxCHECK_MSG( m_rect
, 0, _T("can't be called in this mode") );
930 int wxListItemData::GetY() const
932 wxCHECK_MSG( m_rect
, 0, _T("can't be called in this mode") );
937 int wxListItemData::GetWidth() const
939 wxCHECK_MSG( m_rect
, 0, _T("can't be called in this mode") );
941 return m_rect
->width
;
944 int wxListItemData::GetHeight() const
946 wxCHECK_MSG( m_rect
, 0, _T("can't be called in this mode") );
948 return m_rect
->height
;
951 void wxListItemData::GetItem( wxListItem
&info
) const
953 info
.m_text
= m_text
;
954 info
.m_image
= m_image
;
955 info
.m_data
= m_data
;
959 if ( m_attr
->HasTextColour() )
960 info
.SetTextColour(m_attr
->GetTextColour());
961 if ( m_attr
->HasBackgroundColour() )
962 info
.SetBackgroundColour(m_attr
->GetBackgroundColour());
963 if ( m_attr
->HasFont() )
964 info
.SetFont(m_attr
->GetFont());
968 //-----------------------------------------------------------------------------
970 //-----------------------------------------------------------------------------
972 void wxListHeaderData::Init()
983 wxListHeaderData::wxListHeaderData()
988 wxListHeaderData::wxListHeaderData( const wxListItem
&item
)
995 void wxListHeaderData::SetItem( const wxListItem
&item
)
997 m_mask
= item
.m_mask
;
999 if ( m_mask
& wxLIST_MASK_TEXT
)
1000 m_text
= item
.m_text
;
1002 if ( m_mask
& wxLIST_MASK_IMAGE
)
1003 m_image
= item
.m_image
;
1005 if ( m_mask
& wxLIST_MASK_FORMAT
)
1006 m_format
= item
.m_format
;
1008 if ( m_mask
& wxLIST_MASK_WIDTH
)
1009 SetWidth(item
.m_width
);
1012 void wxListHeaderData::SetPosition( int x
, int y
)
1018 void wxListHeaderData::SetHeight( int h
)
1023 void wxListHeaderData::SetWidth( int w
)
1027 m_width
= WIDTH_COL_DEFAULT
;
1028 else if (m_width
< WIDTH_COL_MIN
)
1029 m_width
= WIDTH_COL_MIN
;
1032 void wxListHeaderData::SetFormat( int format
)
1037 bool wxListHeaderData::HasImage() const
1039 return m_image
!= -1;
1042 bool wxListHeaderData::IsHit( int x
, int y
) const
1044 return ((x
>= m_xpos
) && (x
<= m_xpos
+m_width
) && (y
>= m_ypos
) && (y
<= m_ypos
+m_height
));
1047 void wxListHeaderData::GetItem( wxListItem
& item
)
1049 item
.m_mask
= m_mask
;
1050 item
.m_text
= m_text
;
1051 item
.m_image
= m_image
;
1052 item
.m_format
= m_format
;
1053 item
.m_width
= m_width
;
1056 int wxListHeaderData::GetImage() const
1061 int wxListHeaderData::GetWidth() const
1066 int wxListHeaderData::GetFormat() const
1071 //-----------------------------------------------------------------------------
1073 //-----------------------------------------------------------------------------
1075 inline int wxListLineData::GetMode() const
1077 return m_owner
->GetListCtrl()->GetWindowStyleFlag() & wxLC_MASK_TYPE
;
1080 inline bool wxListLineData::InReportView() const
1082 return m_owner
->HasFlag(wxLC_REPORT
);
1085 inline bool wxListLineData::IsVirtual() const
1087 return m_owner
->IsVirtual();
1090 wxListLineData::wxListLineData( wxListMainWindow
*owner
)
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::compatibility_iterator 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
,
1217 int WXUNUSED(window_width
),
1220 wxListItemDataList::compatibility_iterator 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::compatibility_iterator 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::compatibility_iterator node
= m_items
.Item( index
);
1305 wxListItemData
*item
= node
->GetData();
1306 item
->GetItem( info
);
1310 wxString
wxListLineData::GetText(int index
) const
1314 wxListItemDataList::compatibility_iterator 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::compatibility_iterator node
= m_items
.Item( index
);
1329 wxListItemData
*item
= node
->GetData();
1334 void wxListLineData::SetImage( int index
, int image
)
1336 wxListItemDataList::compatibility_iterator 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::compatibility_iterator 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::compatibility_iterator 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::compatibility_iterator 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::compatibility_iterator 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::compatibility_iterator 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 // shift the DC origin to match the position of the main window horz
1657 // scrollbar: this allows us to always use logical coords
1658 void wxListHeaderWindow::AdjustDC(wxDC
& dc
)
1661 m_owner
->GetScrollPixelsPerUnit( &xpix
, NULL
);
1664 m_owner
->GetViewStart( &x
, NULL
);
1666 // account for the horz scrollbar offset
1667 dc
.SetDeviceOrigin( -x
* xpix
, 0 );
1670 void wxListHeaderWindow::OnPaint( wxPaintEvent
&WXUNUSED(event
) )
1672 wxPaintDC
dc( this );
1679 dc
.SetFont( GetFont() );
1681 // width and height of the entire header window
1683 GetClientSize( &w
, &h
);
1684 m_owner
->CalcUnscrolledPosition(w
, 0, &w
, NULL
);
1686 dc
.SetBackgroundMode(wxTRANSPARENT
);
1688 // do *not* use the listctrl colour for headers - one day we will have a
1689 // function to set it separately
1690 //dc.SetTextForeground( *wxBLACK );
1691 dc
.SetTextForeground(wxSystemSettings::
1692 GetSystemColour( wxSYS_COLOUR_WINDOWTEXT
));
1694 int x
= HEADER_OFFSET_X
;
1696 int numColumns
= m_owner
->GetColumnCount();
1698 for ( int i
= 0; i
< numColumns
&& x
< w
; i
++ )
1700 m_owner
->GetColumn( i
, item
);
1701 int wCol
= item
.m_width
;
1703 // the width of the rect to draw: make it smaller to fit entirely
1704 // inside the column rect
1707 wxRendererNative::Get().DrawHeaderButton
1711 wxRect(x
, HEADER_OFFSET_Y
, cw
, h
- 2),
1712 m_parent
->IsEnabled() ? 0
1713 : wxCONTROL_DISABLED
1716 // see if we have enough space for the column label
1718 // for this we need the width of the text
1720 dc
.GetTextExtent(item
.GetText(), &wLabel
, NULL
);
1721 wLabel
+= 2*EXTRA_WIDTH
;
1723 // and the width of the icon, if any
1724 static const int MARGIN_BETWEEN_TEXT_AND_ICON
= 2;
1725 int ix
= 0, // init them just to suppress the compiler warnings
1727 const int image
= item
.m_image
;
1728 wxImageListType
*imageList
;
1731 imageList
= m_owner
->m_small_image_list
;
1734 imageList
->GetSize(image
, ix
, iy
);
1735 wLabel
+= ix
+ MARGIN_BETWEEN_TEXT_AND_ICON
;
1743 // ignore alignment if there is not enough space anyhow
1745 switch ( wLabel
< cw
? item
.GetAlign() : wxLIST_FORMAT_LEFT
)
1748 wxFAIL_MSG( _T("unknown list item format") );
1751 case wxLIST_FORMAT_LEFT
:
1755 case wxLIST_FORMAT_RIGHT
:
1756 xAligned
= x
+ cw
- wLabel
;
1759 case wxLIST_FORMAT_CENTER
:
1760 xAligned
= x
+ (cw
- wLabel
) / 2;
1765 // if we have an image, draw it on the right of the label
1772 xAligned
+ wLabel
- ix
- MARGIN_BETWEEN_TEXT_AND_ICON
,
1773 HEADER_OFFSET_Y
+ (h
- 4 - iy
)/2,
1774 wxIMAGELIST_DRAW_TRANSPARENT
1777 cw
-= ix
+ MARGIN_BETWEEN_TEXT_AND_ICON
;
1780 // draw the text clipping it so that it doesn't overwrite the column
1782 wxDCClipper
clipper(dc
, x
, HEADER_OFFSET_Y
, cw
, h
- 4 );
1784 dc
.DrawText( item
.GetText(),
1785 xAligned
+ EXTRA_WIDTH
, HEADER_OFFSET_Y
+ EXTRA_HEIGHT
);
1793 void wxListHeaderWindow::DrawCurrent()
1795 int x1
= m_currentX
;
1797 m_owner
->ClientToScreen( &x1
, &y1
);
1799 int x2
= m_currentX
;
1801 m_owner
->GetClientSize( NULL
, &y2
);
1802 m_owner
->ClientToScreen( &x2
, &y2
);
1805 dc
.SetLogicalFunction( wxINVERT
);
1806 dc
.SetPen( wxPen( *wxBLACK
, 2, wxSOLID
) );
1807 dc
.SetBrush( *wxTRANSPARENT_BRUSH
);
1811 dc
.DrawLine( x1
, y1
, x2
, y2
);
1813 dc
.SetLogicalFunction( wxCOPY
);
1815 dc
.SetPen( wxNullPen
);
1816 dc
.SetBrush( wxNullBrush
);
1819 void wxListHeaderWindow::OnMouse( wxMouseEvent
&event
)
1821 // we want to work with logical coords
1823 m_owner
->CalcUnscrolledPosition(event
.GetX(), 0, &x
, NULL
);
1824 int y
= event
.GetY();
1828 SendListEvent(wxEVT_COMMAND_LIST_COL_DRAGGING
, event
.GetPosition());
1830 // we don't draw the line beyond our window, but we allow dragging it
1833 GetClientSize( &w
, NULL
);
1834 m_owner
->CalcUnscrolledPosition(w
, 0, &w
, NULL
);
1837 // erase the line if it was drawn
1838 if ( m_currentX
< w
)
1841 if (event
.ButtonUp())
1844 m_isDragging
= FALSE
;
1846 m_owner
->SetColumnWidth( m_column
, m_currentX
- m_minX
);
1847 SendListEvent(wxEVT_COMMAND_LIST_COL_END_DRAG
, event
.GetPosition());
1854 m_currentX
= m_minX
+ 7;
1856 // draw in the new location
1857 if ( m_currentX
< w
)
1861 else // not dragging
1864 bool hit_border
= FALSE
;
1866 // end of the current column
1869 // find the column where this event occured
1871 countCol
= m_owner
->GetColumnCount();
1872 for (col
= 0; col
< countCol
; col
++)
1874 xpos
+= m_owner
->GetColumnWidth( col
);
1877 if ( (abs(x
-xpos
) < 3) && (y
< 22) )
1879 // near the column border
1886 // inside the column
1893 if ( col
== countCol
)
1896 if (event
.LeftDown() || event
.RightUp())
1898 if (hit_border
&& event
.LeftDown())
1900 if ( SendListEvent(wxEVT_COMMAND_LIST_COL_BEGIN_DRAG
,
1901 event
.GetPosition()) )
1903 m_isDragging
= TRUE
;
1908 //else: column resizing was vetoed by the user code
1910 else // click on a column
1912 SendListEvent( event
.LeftDown()
1913 ? wxEVT_COMMAND_LIST_COL_CLICK
1914 : wxEVT_COMMAND_LIST_COL_RIGHT_CLICK
,
1915 event
.GetPosition());
1918 else if (event
.Moving())
1923 setCursor
= m_currentCursor
== wxSTANDARD_CURSOR
;
1924 m_currentCursor
= m_resizeCursor
;
1928 setCursor
= m_currentCursor
!= wxSTANDARD_CURSOR
;
1929 m_currentCursor
= wxSTANDARD_CURSOR
;
1933 SetCursor(*m_currentCursor
);
1938 void wxListHeaderWindow::OnSetFocus( wxFocusEvent
&WXUNUSED(event
) )
1940 m_owner
->SetFocus();
1943 bool wxListHeaderWindow::SendListEvent(wxEventType type
, wxPoint pos
)
1945 wxWindow
*parent
= GetParent();
1946 wxListEvent
le( type
, parent
->GetId() );
1947 le
.SetEventObject( parent
);
1948 le
.m_pointDrag
= pos
;
1950 // the position should be relative to the parent window, not
1951 // this one for compatibility with MSW and common sense: the
1952 // user code doesn't know anything at all about this header
1953 // window, so why should it get positions relative to it?
1954 le
.m_pointDrag
.y
-= GetSize().y
;
1956 le
.m_col
= m_column
;
1957 return !parent
->GetEventHandler()->ProcessEvent( le
) || le
.IsAllowed();
1960 //-----------------------------------------------------------------------------
1961 // wxListRenameTimer (internal)
1962 //-----------------------------------------------------------------------------
1964 wxListRenameTimer::wxListRenameTimer( wxListMainWindow
*owner
)
1969 void wxListRenameTimer::Notify()
1971 m_owner
->OnRenameTimer();
1974 //-----------------------------------------------------------------------------
1975 // wxListTextCtrl (internal)
1976 //-----------------------------------------------------------------------------
1978 BEGIN_EVENT_TABLE(wxListTextCtrl
,wxTextCtrl
)
1979 EVT_CHAR (wxListTextCtrl::OnChar
)
1980 EVT_KEY_UP (wxListTextCtrl::OnKeyUp
)
1981 EVT_KILL_FOCUS (wxListTextCtrl::OnKillFocus
)
1984 wxListTextCtrl::wxListTextCtrl(wxListMainWindow
*owner
, size_t itemEdit
)
1985 : m_startValue(owner
->GetItemText(itemEdit
)),
1986 m_itemEdited(itemEdit
)
1991 wxRect rectLabel
= owner
->GetLineLabelRect(itemEdit
);
1993 m_owner
->CalcScrolledPosition(rectLabel
.x
, rectLabel
.y
,
1994 &rectLabel
.x
, &rectLabel
.y
);
1996 (void)Create(owner
, wxID_ANY
, m_startValue
,
1997 wxPoint(rectLabel
.x
-4,rectLabel
.y
-4),
1998 wxSize(rectLabel
.width
+11,rectLabel
.height
+8));
2001 void wxListTextCtrl::Finish()
2005 wxPendingDelete
.Append(this);
2009 m_owner
->SetFocus();
2013 bool wxListTextCtrl::AcceptChanges()
2015 const wxString value
= GetValue();
2017 if ( value
== m_startValue
)
2019 // nothing changed, always accept
2023 if ( !m_owner
->OnRenameAccept(m_itemEdited
, value
) )
2025 // vetoed by the user
2029 // accepted, do rename the item
2030 m_owner
->SetItemText(m_itemEdited
, value
);
2035 void wxListTextCtrl::OnChar( wxKeyEvent
&event
)
2037 switch ( event
.m_keyCode
)
2040 if ( !AcceptChanges() )
2042 // vetoed by the user code
2045 //else: fall through
2049 m_owner
->OnRenameCancelled( m_itemEdited
);
2057 void wxListTextCtrl::OnKeyUp( wxKeyEvent
&event
)
2065 // auto-grow the textctrl:
2066 wxSize parentSize
= m_owner
->GetSize();
2067 wxPoint myPos
= GetPosition();
2068 wxSize mySize
= GetSize();
2070 GetTextExtent(GetValue() + _T("MM"), &sx
, &sy
);
2071 if (myPos
.x
+ sx
> parentSize
.x
)
2072 sx
= parentSize
.x
- myPos
.x
;
2080 void wxListTextCtrl::OnKillFocus( wxFocusEvent
&event
)
2084 // We must finish regardless of success, otherwise we'll get focus problems
2087 if ( !AcceptChanges() )
2088 m_owner
->OnRenameCancelled( m_itemEdited
);
2094 //-----------------------------------------------------------------------------
2096 //-----------------------------------------------------------------------------
2098 IMPLEMENT_DYNAMIC_CLASS(wxListMainWindow
,wxScrolledWindow
)
2100 BEGIN_EVENT_TABLE(wxListMainWindow
,wxScrolledWindow
)
2101 EVT_PAINT (wxListMainWindow::OnPaint
)
2102 EVT_MOUSE_EVENTS (wxListMainWindow::OnMouse
)
2103 EVT_CHAR (wxListMainWindow::OnChar
)
2104 EVT_KEY_DOWN (wxListMainWindow::OnKeyDown
)
2105 EVT_SET_FOCUS (wxListMainWindow::OnSetFocus
)
2106 EVT_KILL_FOCUS (wxListMainWindow::OnKillFocus
)
2107 EVT_SCROLLWIN (wxListMainWindow::OnScroll
)
2110 void wxListMainWindow::Init()
2115 m_lineTo
= (size_t)-1;
2121 m_small_image_list
= (wxImageListType
*) NULL
;
2122 m_normal_image_list
= (wxImageListType
*) NULL
;
2124 m_small_spacing
= 30;
2125 m_normal_spacing
= 40;
2129 m_isCreated
= FALSE
;
2131 m_lastOnSame
= FALSE
;
2132 m_renameTimer
= new wxListRenameTimer( this );
2136 m_lineBeforeLastClicked
= (size_t)-1;
2141 void wxListMainWindow::InitScrolling()
2143 if ( HasFlag(wxLC_REPORT
) )
2145 m_xScroll
= SCROLL_UNIT_X
;
2146 m_yScroll
= SCROLL_UNIT_Y
;
2150 m_xScroll
= SCROLL_UNIT_Y
;
2155 wxListMainWindow::wxListMainWindow()
2160 m_highlightUnfocusedBrush
= (wxBrush
*) NULL
;
2166 wxListMainWindow::wxListMainWindow( wxWindow
*parent
,
2171 const wxString
&name
)
2172 : wxScrolledWindow( parent
, id
, pos
, size
,
2173 style
| wxHSCROLL
| wxVSCROLL
, name
)
2177 m_highlightBrush
= new wxBrush
2179 wxSystemSettings::GetColour
2181 wxSYS_COLOUR_HIGHLIGHT
2186 m_highlightUnfocusedBrush
= new wxBrush
2188 wxSystemSettings::GetColour
2190 wxSYS_COLOUR_BTNSHADOW
2199 SetScrollbars( m_xScroll
, m_yScroll
, 0, 0, 0, 0 );
2201 SetBackgroundColour( wxSystemSettings::GetColour( wxSYS_COLOUR_LISTBOX
) );
2204 wxListMainWindow::~wxListMainWindow()
2207 WX_CLEAR_LIST(wxListHeaderDataList
, m_columns
);
2209 delete m_highlightBrush
;
2210 delete m_highlightUnfocusedBrush
;
2212 delete m_renameTimer
;
2215 void wxListMainWindow::CacheLineData(size_t line
)
2217 wxGenericListCtrl
*listctrl
= GetListCtrl();
2219 wxListLineData
*ld
= GetDummyLine();
2221 size_t countCol
= GetColumnCount();
2222 for ( size_t col
= 0; col
< countCol
; col
++ )
2224 ld
->SetText(col
, listctrl
->OnGetItemText(line
, col
));
2227 ld
->SetImage(listctrl
->OnGetItemImage(line
));
2228 ld
->SetAttr(listctrl
->OnGetItemAttr(line
));
2231 wxListLineData
*wxListMainWindow::GetDummyLine() const
2233 wxASSERT_MSG( !IsEmpty(), _T("invalid line index") );
2235 wxASSERT_MSG( IsVirtual(), _T("GetDummyLine() shouldn't be called") );
2237 wxListMainWindow
*self
= wxConstCast(this, wxListMainWindow
);
2239 // we need to recreate the dummy line if the number of columns in the
2240 // control changed as it would have the incorrect number of fields
2242 if ( !m_lines
.IsEmpty() &&
2243 m_lines
[0].m_items
.GetCount() != (size_t)GetColumnCount() )
2245 self
->m_lines
.Clear();
2248 if ( m_lines
.IsEmpty() )
2250 wxListLineData
*line
= new wxListLineData(self
);
2251 self
->m_lines
.Add(line
);
2253 // don't waste extra memory -- there never going to be anything
2254 // else/more in this array
2255 self
->m_lines
.Shrink();
2261 // ----------------------------------------------------------------------------
2262 // line geometry (report mode only)
2263 // ----------------------------------------------------------------------------
2265 wxCoord
wxListMainWindow::GetLineHeight() const
2267 wxASSERT_MSG( HasFlag(wxLC_REPORT
), _T("only works in report mode") );
2269 // we cache the line height as calling GetTextExtent() is slow
2270 if ( !m_lineHeight
)
2272 wxListMainWindow
*self
= wxConstCast(this, wxListMainWindow
);
2274 wxClientDC
dc( self
);
2275 dc
.SetFont( GetFont() );
2278 dc
.GetTextExtent(_T("H"), NULL
, &y
);
2280 if ( y
< SCROLL_UNIT_Y
)
2283 if ( m_small_image_list
&& m_small_image_list
->GetImageCount() )
2287 m_small_image_list
->GetSize(0, iw
, ih
);
2292 self
->m_lineHeight
= y
+ LINE_SPACING
;
2295 return m_lineHeight
;
2298 wxCoord
wxListMainWindow::GetLineY(size_t line
) const
2300 wxASSERT_MSG( HasFlag(wxLC_REPORT
), _T("only works in report mode") );
2302 return LINE_SPACING
+ line
*GetLineHeight();
2305 wxRect
wxListMainWindow::GetLineRect(size_t line
) const
2307 if ( !InReportView() )
2308 return GetLine(line
)->m_gi
->m_rectAll
;
2311 rect
.x
= HEADER_OFFSET_X
;
2312 rect
.y
= GetLineY(line
);
2313 rect
.width
= GetHeaderWidth();
2314 rect
.height
= GetLineHeight();
2319 wxRect
wxListMainWindow::GetLineLabelRect(size_t line
) const
2321 if ( !InReportView() )
2322 return GetLine(line
)->m_gi
->m_rectLabel
;
2325 rect
.x
= HEADER_OFFSET_X
;
2326 rect
.y
= GetLineY(line
);
2327 rect
.width
= GetColumnWidth(0);
2328 rect
.height
= GetLineHeight();
2333 wxRect
wxListMainWindow::GetLineIconRect(size_t line
) const
2335 if ( !InReportView() )
2336 return GetLine(line
)->m_gi
->m_rectIcon
;
2338 wxListLineData
*ld
= GetLine(line
);
2339 wxASSERT_MSG( ld
->HasImage(), _T("should have an image") );
2342 rect
.x
= HEADER_OFFSET_X
;
2343 rect
.y
= GetLineY(line
);
2344 GetImageSize(ld
->GetImage(), rect
.width
, rect
.height
);
2349 wxRect
wxListMainWindow::GetLineHighlightRect(size_t line
) const
2351 return InReportView() ? GetLineRect(line
)
2352 : GetLine(line
)->m_gi
->m_rectHighlight
;
2355 long wxListMainWindow::HitTestLine(size_t line
, int x
, int y
) const
2357 wxASSERT_MSG( line
< GetItemCount(), _T("invalid line in HitTestLine") );
2359 wxListLineData
*ld
= GetLine(line
);
2361 if ( ld
->HasImage() && GetLineIconRect(line
).Inside(x
, y
) )
2362 return wxLIST_HITTEST_ONITEMICON
;
2364 // VS: Testing for "ld->HasText() || InReportView()" instead of
2365 // "ld->HasText()" is needed to make empty lines in report view
2367 if ( ld
->HasText() || InReportView() )
2369 wxRect rect
= InReportView() ? GetLineRect(line
)
2370 : GetLineLabelRect(line
);
2372 if ( rect
.Inside(x
, y
) )
2373 return wxLIST_HITTEST_ONITEMLABEL
;
2379 // ----------------------------------------------------------------------------
2380 // highlight (selection) handling
2381 // ----------------------------------------------------------------------------
2383 bool wxListMainWindow::IsHighlighted(size_t line
) const
2387 return m_selStore
.IsSelected(line
);
2391 wxListLineData
*ld
= GetLine(line
);
2392 wxCHECK_MSG( ld
, FALSE
, _T("invalid index in IsHighlighted") );
2394 return ld
->IsHighlighted();
2398 void wxListMainWindow::HighlightLines( size_t lineFrom
,
2404 wxArrayInt linesChanged
;
2405 if ( !m_selStore
.SelectRange(lineFrom
, lineTo
, highlight
,
2408 // meny items changed state, refresh everything
2409 RefreshLines(lineFrom
, lineTo
);
2411 else // only a few items changed state, refresh only them
2413 size_t count
= linesChanged
.GetCount();
2414 for ( size_t n
= 0; n
< count
; n
++ )
2416 RefreshLine(linesChanged
[n
]);
2420 else // iterate over all items in non report view
2422 for ( size_t line
= lineFrom
; line
<= lineTo
; line
++ )
2424 if ( HighlightLine(line
, highlight
) )
2432 bool wxListMainWindow::HighlightLine( size_t line
, bool highlight
)
2438 changed
= m_selStore
.SelectItem(line
, highlight
);
2442 wxListLineData
*ld
= GetLine(line
);
2443 wxCHECK_MSG( ld
, FALSE
, _T("invalid index in HighlightLine") );
2445 changed
= ld
->Highlight(highlight
);
2450 SendNotify( line
, highlight
? wxEVT_COMMAND_LIST_ITEM_SELECTED
2451 : wxEVT_COMMAND_LIST_ITEM_DESELECTED
);
2457 void wxListMainWindow::RefreshLine( size_t line
)
2459 if ( HasFlag(wxLC_REPORT
) )
2461 size_t visibleFrom
, visibleTo
;
2462 GetVisibleLinesRange(&visibleFrom
, &visibleTo
);
2464 if ( line
< visibleFrom
|| line
> visibleTo
)
2468 wxRect rect
= GetLineRect(line
);
2470 CalcScrolledPosition( rect
.x
, rect
.y
, &rect
.x
, &rect
.y
);
2471 RefreshRect( rect
);
2474 void wxListMainWindow::RefreshLines( size_t lineFrom
, size_t lineTo
)
2476 // we suppose that they are ordered by caller
2477 wxASSERT_MSG( lineFrom
<= lineTo
, _T("indices in disorder") );
2479 wxASSERT_MSG( lineTo
< GetItemCount(), _T("invalid line range") );
2481 if ( HasFlag(wxLC_REPORT
) )
2483 size_t visibleFrom
, visibleTo
;
2484 GetVisibleLinesRange(&visibleFrom
, &visibleTo
);
2486 if ( lineFrom
< visibleFrom
)
2487 lineFrom
= visibleFrom
;
2488 if ( lineTo
> visibleTo
)
2493 rect
.y
= GetLineY(lineFrom
);
2494 rect
.width
= GetClientSize().x
;
2495 rect
.height
= GetLineY(lineTo
) - rect
.y
+ GetLineHeight();
2497 CalcScrolledPosition( rect
.x
, rect
.y
, &rect
.x
, &rect
.y
);
2498 RefreshRect( rect
);
2502 // TODO: this should be optimized...
2503 for ( size_t line
= lineFrom
; line
<= lineTo
; line
++ )
2510 void wxListMainWindow::RefreshAfter( size_t lineFrom
)
2512 if ( HasFlag(wxLC_REPORT
) )
2514 size_t visibleFrom
, visibleTo
;
2515 GetVisibleLinesRange(&visibleFrom
, &visibleTo
);
2517 if ( lineFrom
< visibleFrom
)
2518 lineFrom
= visibleFrom
;
2519 else if ( lineFrom
> visibleTo
)
2524 rect
.y
= GetLineY(lineFrom
);
2525 CalcScrolledPosition( rect
.x
, rect
.y
, &rect
.x
, &rect
.y
);
2527 wxSize size
= GetClientSize();
2528 rect
.width
= size
.x
;
2529 // refresh till the bottom of the window
2530 rect
.height
= size
.y
- rect
.y
;
2532 RefreshRect( rect
);
2536 // TODO: how to do it more efficiently?
2541 void wxListMainWindow::RefreshSelected()
2547 if ( InReportView() )
2549 GetVisibleLinesRange(&from
, &to
);
2554 to
= GetItemCount() - 1;
2557 if ( HasCurrent() && m_current
>= from
&& m_current
<= to
)
2559 RefreshLine(m_current
);
2562 for ( size_t line
= from
; line
<= to
; line
++ )
2564 // NB: the test works as expected even if m_current == -1
2565 if ( line
!= m_current
&& IsHighlighted(line
) )
2572 void wxListMainWindow::Freeze()
2577 void wxListMainWindow::Thaw()
2579 wxCHECK_RET( m_freezeCount
> 0, _T("thawing unfrozen list control?") );
2581 if ( !--m_freezeCount
)
2587 void wxListMainWindow::OnPaint( wxPaintEvent
&WXUNUSED(event
) )
2589 // Note: a wxPaintDC must be constructed even if no drawing is
2590 // done (a Windows requirement).
2591 wxPaintDC
dc( this );
2593 if ( IsEmpty() || m_freezeCount
)
2595 // nothing to draw or not the moment to draw it
2601 // delay the repainting until we calculate all the items positions
2608 CalcScrolledPosition( 0, 0, &dev_x
, &dev_y
);
2612 dc
.SetFont( GetFont() );
2614 if ( HasFlag(wxLC_REPORT
) )
2616 int lineHeight
= GetLineHeight();
2618 size_t visibleFrom
, visibleTo
;
2619 GetVisibleLinesRange(&visibleFrom
, &visibleTo
);
2622 wxCoord xOrig
, yOrig
;
2623 CalcUnscrolledPosition(0, 0, &xOrig
, &yOrig
);
2625 // tell the caller cache to cache the data
2628 wxListEvent
evCache(wxEVT_COMMAND_LIST_CACHE_HINT
,
2629 GetParent()->GetId());
2630 evCache
.SetEventObject( GetParent() );
2631 evCache
.m_oldItemIndex
= visibleFrom
;
2632 evCache
.m_itemIndex
= visibleTo
;
2633 GetParent()->GetEventHandler()->ProcessEvent( evCache
);
2636 for ( size_t line
= visibleFrom
; line
<= visibleTo
; line
++ )
2638 rectLine
= GetLineRect(line
);
2640 if ( !IsExposed(rectLine
.x
- xOrig
, rectLine
.y
- yOrig
,
2641 rectLine
.width
, rectLine
.height
) )
2643 // don't redraw unaffected lines to avoid flicker
2647 GetLine(line
)->DrawInReportMode( &dc
,
2649 GetLineHighlightRect(line
),
2650 IsHighlighted(line
) );
2653 if ( HasFlag(wxLC_HRULES
) )
2655 wxPen
pen(GetRuleColour(), 1, wxSOLID
);
2656 wxSize clientSize
= GetClientSize();
2658 // Don't draw the first one
2659 for ( size_t i
= visibleFrom
+1; i
<= visibleTo
; i
++ )
2662 dc
.SetBrush( *wxTRANSPARENT_BRUSH
);
2663 dc
.DrawLine(0 - dev_x
, i
*lineHeight
,
2664 clientSize
.x
- dev_x
, i
*lineHeight
);
2667 // Draw last horizontal rule
2668 if ( visibleTo
== GetItemCount() - 1 )
2671 dc
.SetBrush( *wxTRANSPARENT_BRUSH
);
2672 dc
.DrawLine(0 - dev_x
, (m_lineTo
+1)*lineHeight
,
2673 clientSize
.x
- dev_x
, (m_lineTo
+1)*lineHeight
);
2677 // Draw vertical rules if required
2678 if ( HasFlag(wxLC_VRULES
) && !IsEmpty() )
2680 wxPen
pen(GetRuleColour(), 1, wxSOLID
);
2683 wxRect firstItemRect
;
2684 wxRect lastItemRect
;
2685 GetItemRect(visibleFrom
, firstItemRect
);
2686 GetItemRect(visibleTo
, lastItemRect
);
2687 int x
= firstItemRect
.GetX();
2689 dc
.SetBrush(* wxTRANSPARENT_BRUSH
);
2690 for (col
= 0; col
< GetColumnCount(); col
++)
2692 int colWidth
= GetColumnWidth(col
);
2694 dc
.DrawLine(x
- dev_x
- 2, firstItemRect
.GetY() - 1 - dev_y
,
2695 x
- dev_x
- 2, lastItemRect
.GetBottom() + 1 - dev_y
);
2701 size_t count
= GetItemCount();
2702 for ( size_t i
= 0; i
< count
; i
++ )
2704 GetLine(i
)->Draw( &dc
);
2710 // don't draw rect outline under Max if we already have the background
2711 // color but under other platforms only draw it if we do: it is a bit
2712 // silly to draw "focus rect" if we don't have focus!
2717 #endif // __WXMAC__/!__WXMAC__
2719 dc
.SetPen( *wxBLACK_PEN
);
2720 dc
.SetBrush( *wxTRANSPARENT_BRUSH
);
2721 dc
.DrawRectangle( GetLineHighlightRect(m_current
) );
2728 void wxListMainWindow::HighlightAll( bool on
)
2730 if ( IsSingleSel() )
2732 wxASSERT_MSG( !on
, _T("can't do this in a single sel control") );
2734 // we just have one item to turn off
2735 if ( HasCurrent() && IsHighlighted(m_current
) )
2737 HighlightLine(m_current
, FALSE
);
2738 RefreshLine(m_current
);
2743 HighlightLines(0, GetItemCount() - 1, on
);
2747 void wxListMainWindow::SendNotify( size_t line
,
2748 wxEventType command
,
2751 wxListEvent
le( command
, GetParent()->GetId() );
2752 le
.SetEventObject( GetParent() );
2753 le
.m_itemIndex
= line
;
2755 // set only for events which have position
2756 if ( point
!= wxDefaultPosition
)
2757 le
.m_pointDrag
= point
;
2759 // don't try to get the line info for virtual list controls: the main
2760 // program has it anyhow and if we did it would result in accessing all
2761 // the lines, even those which are not visible now and this is precisely
2762 // what we're trying to avoid
2763 if ( !IsVirtual() && (command
!= wxEVT_COMMAND_LIST_DELETE_ITEM
) )
2765 if ( line
!= (size_t)-1 )
2767 GetLine(line
)->GetItem( 0, le
.m_item
);
2769 //else: this happens for wxEVT_COMMAND_LIST_ITEM_FOCUSED event
2771 //else: there may be no more such item
2773 GetParent()->GetEventHandler()->ProcessEvent( le
);
2776 void wxListMainWindow::ChangeCurrent(size_t current
)
2778 m_current
= current
;
2780 SendNotify(current
, wxEVT_COMMAND_LIST_ITEM_FOCUSED
);
2783 void wxListMainWindow::EditLabel( long item
)
2785 wxCHECK_RET( (item
>= 0) && ((size_t)item
< GetItemCount()),
2786 wxT("wrong index in wxGenericListCtrl::EditLabel()") );
2788 size_t itemEdit
= (size_t)item
;
2790 wxListEvent
le( wxEVT_COMMAND_LIST_BEGIN_LABEL_EDIT
, GetParent()->GetId() );
2791 le
.SetEventObject( GetParent() );
2792 le
.m_itemIndex
= item
;
2793 wxListLineData
*data
= GetLine(itemEdit
);
2794 wxCHECK_RET( data
, _T("invalid index in EditLabel()") );
2795 data
->GetItem( 0, le
.m_item
);
2796 if ( GetParent()->GetEventHandler()->ProcessEvent( le
) && !le
.IsAllowed() )
2798 // vetoed by user code
2802 // We have to call this here because the label in question might just have
2803 // been added and no screen update taken place.
2807 wxListTextCtrl
*text
= new wxListTextCtrl(this, itemEdit
);
2812 void wxListMainWindow::OnRenameTimer()
2814 wxCHECK_RET( HasCurrent(), wxT("unexpected rename timer") );
2816 EditLabel( m_current
);
2819 bool wxListMainWindow::OnRenameAccept(size_t itemEdit
, const wxString
& value
)
2821 wxListEvent
le( wxEVT_COMMAND_LIST_END_LABEL_EDIT
, GetParent()->GetId() );
2822 le
.SetEventObject( GetParent() );
2823 le
.m_itemIndex
= itemEdit
;
2825 wxListLineData
*data
= GetLine(itemEdit
);
2826 wxCHECK_MSG( data
, FALSE
, _T("invalid index in OnRenameAccept()") );
2828 data
->GetItem( 0, le
.m_item
);
2829 le
.m_item
.m_text
= value
;
2830 return !GetParent()->GetEventHandler()->ProcessEvent( le
) ||
2834 #ifdef __VMS__ // Ignore unreacheable code
2835 # pragma message disable initnotreach
2838 void wxListMainWindow::OnRenameCancelled(size_t itemEdit
)
2840 // wxMSW seems not to notify the program about
2841 // cancelled label edits.
2844 // let owner know that the edit was cancelled
2845 wxListEvent
le( wxEVT_COMMAND_LIST_END_LABEL_EDIT
, GetParent()->GetId() );
2847 // These only exist for wxTreeCtrl, which should probably be changed
2848 // le.m_editCancelled = TRUE;
2849 // le.m_label = wxEmptyString;
2851 le
.SetEventObject( GetParent() );
2852 le
.m_itemIndex
= itemEdit
;
2854 wxListLineData
*data
= GetLine(itemEdit
);
2855 wxCHECK_RET( data
, _T("invalid index in OnRenameCancelled()") );
2857 data
->GetItem( 0, le
.m_item
);
2859 GetEventHandler()->ProcessEvent( le
);
2862 # pragma message enable initnotreach
2865 void wxListMainWindow::OnMouse( wxMouseEvent
&event
)
2867 event
.SetEventObject( GetParent() );
2868 if ( GetParent()->GetEventHandler()->ProcessEvent( event
) )
2871 if ( !HasCurrent() || IsEmpty() )
2877 if ( !(event
.Dragging() || event
.ButtonDown() || event
.LeftUp() ||
2878 event
.ButtonDClick()) )
2881 int x
= event
.GetX();
2882 int y
= event
.GetY();
2883 CalcUnscrolledPosition( x
, y
, &x
, &y
);
2885 // where did we hit it (if we did)?
2888 size_t count
= GetItemCount(),
2891 if ( HasFlag(wxLC_REPORT
) )
2893 current
= y
/ GetLineHeight();
2894 if ( current
< count
)
2895 hitResult
= HitTestLine(current
, x
, y
);
2899 // TODO: optimize it too! this is less simple than for report view but
2900 // enumerating all items is still not a way to do it!!
2901 for ( current
= 0; current
< count
; current
++ )
2903 hitResult
= HitTestLine(current
, x
, y
);
2909 if (event
.Dragging())
2911 if (m_dragCount
== 0)
2913 // we have to report the raw, physical coords as we want to be
2914 // able to call HitTest(event.m_pointDrag) from the user code to
2915 // get the item being dragged
2916 m_dragStart
= event
.GetPosition();
2921 if (m_dragCount
!= 3)
2924 int command
= event
.RightIsDown() ? wxEVT_COMMAND_LIST_BEGIN_RDRAG
2925 : wxEVT_COMMAND_LIST_BEGIN_DRAG
;
2927 wxListEvent
le( command
, GetParent()->GetId() );
2928 le
.SetEventObject( GetParent() );
2929 le
.m_itemIndex
= current
;
2930 le
.m_pointDrag
= m_dragStart
;
2931 GetParent()->GetEventHandler()->ProcessEvent( le
);
2942 // outside of any item
2946 bool forceClick
= FALSE
;
2947 if (event
.ButtonDClick())
2949 m_renameTimer
->Stop();
2950 m_lastOnSame
= FALSE
;
2952 if ( current
== m_lineLastClicked
)
2954 SendNotify( current
, wxEVT_COMMAND_LIST_ITEM_ACTIVATED
);
2960 // the first click was on another item, so don't interpret this as
2961 // a double click, but as a simple click instead
2966 if (event
.LeftUp() && m_lastOnSame
)
2968 if ((current
== m_current
) &&
2969 (hitResult
== wxLIST_HITTEST_ONITEMLABEL
) &&
2970 HasFlag(wxLC_EDIT_LABELS
) )
2972 m_renameTimer
->Start( 100, TRUE
);
2974 m_lastOnSame
= FALSE
;
2976 else if (event
.RightDown())
2978 SendNotify( current
, wxEVT_COMMAND_LIST_ITEM_RIGHT_CLICK
,
2979 event
.GetPosition() );
2981 else if (event
.MiddleDown())
2983 SendNotify( current
, wxEVT_COMMAND_LIST_ITEM_MIDDLE_CLICK
);
2985 else if ( event
.LeftDown() || forceClick
)
2987 m_lineBeforeLastClicked
= m_lineLastClicked
;
2988 m_lineLastClicked
= current
;
2990 size_t oldCurrent
= m_current
;
2992 if ( IsSingleSel() || !(event
.ControlDown() || event
.ShiftDown()) )
2994 HighlightAll( FALSE
);
2996 ChangeCurrent(current
);
2998 ReverseHighlight(m_current
);
3000 else // multi sel & either ctrl or shift is down
3002 if (event
.ControlDown())
3004 ChangeCurrent(current
);
3006 ReverseHighlight(m_current
);
3008 else if (event
.ShiftDown())
3010 ChangeCurrent(current
);
3012 size_t lineFrom
= oldCurrent
,
3015 if ( lineTo
< lineFrom
)
3018 lineFrom
= m_current
;
3021 HighlightLines(lineFrom
, lineTo
);
3023 else // !ctrl, !shift
3025 // test in the enclosing if should make it impossible
3026 wxFAIL_MSG( _T("how did we get here?") );
3030 if (m_current
!= oldCurrent
)
3032 RefreshLine( oldCurrent
);
3035 // forceClick is only set if the previous click was on another item
3036 m_lastOnSame
= !forceClick
&& (m_current
== oldCurrent
);
3040 void wxListMainWindow::MoveToItem(size_t item
)
3042 if ( item
== (size_t)-1 )
3045 wxRect rect
= GetLineRect(item
);
3047 int client_w
, client_h
;
3048 GetClientSize( &client_w
, &client_h
);
3050 int view_x
= m_xScroll
*GetScrollPos( wxHORIZONTAL
);
3051 int view_y
= m_yScroll
*GetScrollPos( wxVERTICAL
);
3053 if ( HasFlag(wxLC_REPORT
) )
3055 // the next we need the range of lines shown it might be different, so
3057 ResetVisibleLinesRange();
3059 if (rect
.y
< view_y
)
3060 Scroll( -1, rect
.y
/m_yScroll
);
3061 if (rect
.y
+rect
.height
+5 > view_y
+client_h
)
3062 Scroll( -1, (rect
.y
+rect
.height
-client_h
+SCROLL_UNIT_Y
)/m_yScroll
);
3066 if (rect
.x
-view_x
< 5)
3067 Scroll( (rect
.x
-5)/m_xScroll
, -1 );
3068 if (rect
.x
+rect
.width
-5 > view_x
+client_w
)
3069 Scroll( (rect
.x
+rect
.width
-client_w
+SCROLL_UNIT_X
)/m_xScroll
, -1 );
3073 // ----------------------------------------------------------------------------
3074 // keyboard handling
3075 // ----------------------------------------------------------------------------
3077 void wxListMainWindow::OnArrowChar(size_t newCurrent
, const wxKeyEvent
& event
)
3079 wxCHECK_RET( newCurrent
< (size_t)GetItemCount(),
3080 _T("invalid item index in OnArrowChar()") );
3082 size_t oldCurrent
= m_current
;
3084 // in single selection we just ignore Shift as we can't select several
3086 if ( event
.ShiftDown() && !IsSingleSel() )
3088 ChangeCurrent(newCurrent
);
3090 // select all the items between the old and the new one
3091 if ( oldCurrent
> newCurrent
)
3093 newCurrent
= oldCurrent
;
3094 oldCurrent
= m_current
;
3097 HighlightLines(oldCurrent
, newCurrent
);
3101 // all previously selected items are unselected unless ctrl is held
3102 if ( !event
.ControlDown() )
3103 HighlightAll(FALSE
);
3105 ChangeCurrent(newCurrent
);
3107 // refresh the old focus to remove it
3108 RefreshLine( oldCurrent
);
3110 if ( !event
.ControlDown() )
3112 HighlightLine( m_current
, TRUE
);
3116 RefreshLine( m_current
);
3121 void wxListMainWindow::OnKeyDown( wxKeyEvent
&event
)
3123 wxWindow
*parent
= GetParent();
3125 /* we propagate the key event up */
3126 wxKeyEvent
ke( wxEVT_KEY_DOWN
);
3127 ke
.m_shiftDown
= event
.m_shiftDown
;
3128 ke
.m_controlDown
= event
.m_controlDown
;
3129 ke
.m_altDown
= event
.m_altDown
;
3130 ke
.m_metaDown
= event
.m_metaDown
;
3131 ke
.m_keyCode
= event
.m_keyCode
;
3134 ke
.SetEventObject( parent
);
3135 if (parent
->GetEventHandler()->ProcessEvent( ke
)) return;
3140 void wxListMainWindow::OnChar( wxKeyEvent
&event
)
3142 wxWindow
*parent
= GetParent();
3144 /* we send a list_key event up */
3147 wxListEvent
le( wxEVT_COMMAND_LIST_KEY_DOWN
, GetParent()->GetId() );
3148 le
.m_itemIndex
= m_current
;
3149 GetLine(m_current
)->GetItem( 0, le
.m_item
);
3150 le
.m_code
= event
.GetKeyCode();
3151 le
.SetEventObject( parent
);
3152 parent
->GetEventHandler()->ProcessEvent( le
);
3155 /* we propagate the char event up */
3156 wxKeyEvent
ke( wxEVT_CHAR
);
3157 ke
.m_shiftDown
= event
.m_shiftDown
;
3158 ke
.m_controlDown
= event
.m_controlDown
;
3159 ke
.m_altDown
= event
.m_altDown
;
3160 ke
.m_metaDown
= event
.m_metaDown
;
3161 ke
.m_keyCode
= event
.m_keyCode
;
3164 ke
.SetEventObject( parent
);
3165 if (parent
->GetEventHandler()->ProcessEvent( ke
)) return;
3167 if (event
.GetKeyCode() == WXK_TAB
)
3169 wxNavigationKeyEvent nevent
;
3170 nevent
.SetWindowChange( event
.ControlDown() );
3171 nevent
.SetDirection( !event
.ShiftDown() );
3172 nevent
.SetEventObject( GetParent()->GetParent() );
3173 nevent
.SetCurrentFocus( m_parent
);
3174 if (GetParent()->GetParent()->GetEventHandler()->ProcessEvent( nevent
))
3178 /* no item -> nothing to do */
3185 switch (event
.GetKeyCode())
3188 if ( m_current
> 0 )
3189 OnArrowChar( m_current
- 1, event
);
3193 if ( m_current
< (size_t)GetItemCount() - 1 )
3194 OnArrowChar( m_current
+ 1, event
);
3199 OnArrowChar( GetItemCount() - 1, event
);
3204 OnArrowChar( 0, event
);
3210 if ( HasFlag(wxLC_REPORT
) )
3212 steps
= m_linesPerPage
- 1;
3216 steps
= m_current
% m_linesPerPage
;
3219 int index
= m_current
- steps
;
3223 OnArrowChar( index
, event
);
3230 if ( HasFlag(wxLC_REPORT
) )
3232 steps
= m_linesPerPage
- 1;
3236 steps
= m_linesPerPage
- (m_current
% m_linesPerPage
) - 1;
3239 size_t index
= m_current
+ steps
;
3240 size_t count
= GetItemCount();
3241 if ( index
>= count
)
3244 OnArrowChar( index
, event
);
3249 if ( !HasFlag(wxLC_REPORT
) )
3251 int index
= m_current
- m_linesPerPage
;
3255 OnArrowChar( index
, event
);
3260 if ( !HasFlag(wxLC_REPORT
) )
3262 size_t index
= m_current
+ m_linesPerPage
;
3264 size_t count
= GetItemCount();
3265 if ( index
>= count
)
3268 OnArrowChar( index
, event
);
3273 if ( IsSingleSel() )
3275 SendNotify( m_current
, wxEVT_COMMAND_LIST_ITEM_ACTIVATED
);
3277 if ( IsHighlighted(m_current
) )
3279 // don't unselect the item in single selection mode
3282 //else: select it in ReverseHighlight() below if unselected
3285 ReverseHighlight(m_current
);
3290 SendNotify( m_current
, wxEVT_COMMAND_LIST_ITEM_ACTIVATED
);
3298 // ----------------------------------------------------------------------------
3300 // ----------------------------------------------------------------------------
3302 void wxListMainWindow::SetFocus()
3304 // VS: wxListMainWindow derives from wxPanel (via wxScrolledWindow) and wxPanel
3305 // overrides SetFocus in such way that it does never change focus from
3306 // panel's child to the panel itself. Unfortunately, we must be able to change
3307 // focus to the panel from wxListTextCtrl because the text control should
3308 // disappear when the user clicks outside it.
3310 wxWindow
*oldFocus
= FindFocus();
3312 if ( oldFocus
&& oldFocus
->GetParent() == this )
3314 wxWindow::SetFocus();
3318 wxScrolledWindow::SetFocus();
3322 void wxListMainWindow::OnSetFocus( wxFocusEvent
&WXUNUSED(event
) )
3324 // wxGTK sends us EVT_SET_FOCUS events even if we had never got
3325 // EVT_KILL_FOCUS before which means that we finish by redrawing the items
3326 // which are already drawn correctly resulting in horrible flicker - avoid
3338 wxFocusEvent
event( wxEVT_SET_FOCUS
, GetParent()->GetId() );
3339 event
.SetEventObject( GetParent() );
3340 GetParent()->GetEventHandler()->ProcessEvent( event
);
3343 void wxListMainWindow::OnKillFocus( wxFocusEvent
&WXUNUSED(event
) )
3350 void wxListMainWindow::DrawImage( int index
, wxDC
*dc
, int x
, int y
)
3352 if ( HasFlag(wxLC_ICON
) && (m_normal_image_list
))
3354 m_normal_image_list
->Draw( index
, *dc
, x
, y
, wxIMAGELIST_DRAW_TRANSPARENT
);
3356 else if ( HasFlag(wxLC_SMALL_ICON
) && (m_small_image_list
))
3358 m_small_image_list
->Draw( index
, *dc
, x
, y
, wxIMAGELIST_DRAW_TRANSPARENT
);
3360 else if ( HasFlag(wxLC_LIST
) && (m_small_image_list
))
3362 m_small_image_list
->Draw( index
, *dc
, x
, y
, wxIMAGELIST_DRAW_TRANSPARENT
);
3364 else if ( HasFlag(wxLC_REPORT
) && (m_small_image_list
))
3366 m_small_image_list
->Draw( index
, *dc
, x
, y
, wxIMAGELIST_DRAW_TRANSPARENT
);
3370 void wxListMainWindow::GetImageSize( int index
, int &width
, int &height
) const
3372 if ( HasFlag(wxLC_ICON
) && m_normal_image_list
)
3374 m_normal_image_list
->GetSize( index
, width
, height
);
3376 else if ( HasFlag(wxLC_SMALL_ICON
) && m_small_image_list
)
3378 m_small_image_list
->GetSize( index
, width
, height
);
3380 else if ( HasFlag(wxLC_LIST
) && m_small_image_list
)
3382 m_small_image_list
->GetSize( index
, width
, height
);
3384 else if ( HasFlag(wxLC_REPORT
) && m_small_image_list
)
3386 m_small_image_list
->GetSize( index
, width
, height
);
3395 int wxListMainWindow::GetTextLength( const wxString
&s
) const
3397 wxClientDC
dc( wxConstCast(this, wxListMainWindow
) );
3398 dc
.SetFont( GetFont() );
3401 dc
.GetTextExtent( s
, &lw
, NULL
);
3403 return lw
+ AUTOSIZE_COL_MARGIN
;
3406 void wxListMainWindow::SetImageList( wxImageListType
*imageList
, int which
)
3410 // calc the spacing from the icon size
3413 if ((imageList
) && (imageList
->GetImageCount()) )
3415 imageList
->GetSize(0, width
, height
);
3418 if (which
== wxIMAGE_LIST_NORMAL
)
3420 m_normal_image_list
= imageList
;
3421 m_normal_spacing
= width
+ 8;
3424 if (which
== wxIMAGE_LIST_SMALL
)
3426 m_small_image_list
= imageList
;
3427 m_small_spacing
= width
+ 14;
3428 m_lineHeight
= 0; // ensure that the line height will be recalc'd
3432 void wxListMainWindow::SetItemSpacing( int spacing
, bool isSmall
)
3437 m_small_spacing
= spacing
;
3441 m_normal_spacing
= spacing
;
3445 int wxListMainWindow::GetItemSpacing( bool isSmall
)
3447 return isSmall
? m_small_spacing
: m_normal_spacing
;
3450 // ----------------------------------------------------------------------------
3452 // ----------------------------------------------------------------------------
3454 void wxListMainWindow::SetColumn( int col
, wxListItem
&item
)
3456 wxListHeaderDataList::compatibility_iterator node
= m_columns
.Item( col
);
3458 wxCHECK_RET( node
, _T("invalid column index in SetColumn") );
3460 if ( item
.m_width
== wxLIST_AUTOSIZE_USEHEADER
)
3461 item
.m_width
= GetTextLength( item
.m_text
);
3463 wxListHeaderData
*column
= node
->GetData();
3464 column
->SetItem( item
);
3466 wxListHeaderWindow
*headerWin
= GetListCtrl()->m_headerWin
;
3468 headerWin
->m_dirty
= TRUE
;
3472 // invalidate it as it has to be recalculated
3476 void wxListMainWindow::SetColumnWidth( int col
, int width
)
3478 wxCHECK_RET( col
>= 0 && col
< GetColumnCount(),
3479 _T("invalid column index") );
3481 wxCHECK_RET( HasFlag(wxLC_REPORT
),
3482 _T("SetColumnWidth() can only be called in report mode.") );
3485 wxListHeaderWindow
*headerWin
= GetListCtrl()->m_headerWin
;
3487 headerWin
->m_dirty
= TRUE
;
3489 wxListHeaderDataList::compatibility_iterator node
= m_columns
.Item( col
);
3490 wxCHECK_RET( node
, _T("no column?") );
3492 wxListHeaderData
*column
= node
->GetData();
3494 size_t count
= GetItemCount();
3496 if (width
== wxLIST_AUTOSIZE_USEHEADER
)
3498 width
= GetTextLength(column
->GetText());
3500 else if ( width
== wxLIST_AUTOSIZE
)
3504 // TODO: determine the max width somehow...
3505 width
= WIDTH_COL_DEFAULT
;
3509 wxClientDC
dc(this);
3510 dc
.SetFont( GetFont() );
3512 int max
= AUTOSIZE_COL_MARGIN
;
3514 for ( size_t i
= 0; i
< count
; i
++ )
3516 wxListLineData
*line
= GetLine(i
);
3517 wxListItemDataList::compatibility_iterator n
= line
->m_items
.Item( col
);
3519 wxCHECK_RET( n
, _T("no subitem?") );
3521 wxListItemData
*item
= n
->GetData();
3524 if (item
->HasImage())
3527 GetImageSize( item
->GetImage(), ix
, iy
);
3531 if (item
->HasText())
3534 dc
.GetTextExtent( item
->GetText(), &w
, NULL
);
3542 width
= max
+ AUTOSIZE_COL_MARGIN
;
3546 column
->SetWidth( width
);
3548 // invalidate it as it has to be recalculated
3552 int wxListMainWindow::GetHeaderWidth() const
3554 if ( !m_headerWidth
)
3556 wxListMainWindow
*self
= wxConstCast(this, wxListMainWindow
);
3558 size_t count
= GetColumnCount();
3559 for ( size_t col
= 0; col
< count
; col
++ )
3561 self
->m_headerWidth
+= GetColumnWidth(col
);
3565 return m_headerWidth
;
3568 void wxListMainWindow::GetColumn( int col
, wxListItem
&item
) const
3570 wxListHeaderDataList::compatibility_iterator node
= m_columns
.Item( col
);
3571 wxCHECK_RET( node
, _T("invalid column index in GetColumn") );
3573 wxListHeaderData
*column
= node
->GetData();
3574 column
->GetItem( item
);
3577 int wxListMainWindow::GetColumnWidth( int col
) const
3579 wxListHeaderDataList::compatibility_iterator node
= m_columns
.Item( col
);
3580 wxCHECK_MSG( node
, 0, _T("invalid column index") );
3582 wxListHeaderData
*column
= node
->GetData();
3583 return column
->GetWidth();
3586 // ----------------------------------------------------------------------------
3588 // ----------------------------------------------------------------------------
3590 void wxListMainWindow::SetItem( wxListItem
&item
)
3592 long id
= item
.m_itemId
;
3593 wxCHECK_RET( id
>= 0 && (size_t)id
< GetItemCount(),
3594 _T("invalid item index in SetItem") );
3598 wxListLineData
*line
= GetLine((size_t)id
);
3599 line
->SetItem( item
.m_col
, item
);
3602 // update the item on screen
3604 GetItemRect(id
, rectItem
);
3605 RefreshRect(rectItem
);
3608 void wxListMainWindow::SetItemState( long litem
, long state
, long stateMask
)
3610 wxCHECK_RET( litem
>= 0 && (size_t)litem
< GetItemCount(),
3611 _T("invalid list ctrl item index in SetItem") );
3613 size_t oldCurrent
= m_current
;
3614 size_t item
= (size_t)litem
; // safe because of the check above
3616 // do we need to change the focus?
3617 if ( stateMask
& wxLIST_STATE_FOCUSED
)
3619 if ( state
& wxLIST_STATE_FOCUSED
)
3621 // don't do anything if this item is already focused
3622 if ( item
!= m_current
)
3624 ChangeCurrent(item
);
3626 if ( oldCurrent
!= (size_t)-1 )
3628 if ( IsSingleSel() )
3630 HighlightLine(oldCurrent
, FALSE
);
3633 RefreshLine(oldCurrent
);
3636 RefreshLine( m_current
);
3641 // don't do anything if this item is not focused
3642 if ( item
== m_current
)
3646 if ( IsSingleSel() )
3648 // we must unselect the old current item as well or we
3649 // might end up with more than one selected item in a
3650 // single selection control
3651 HighlightLine(oldCurrent
, FALSE
);
3654 RefreshLine( oldCurrent
);
3659 // do we need to change the selection state?
3660 if ( stateMask
& wxLIST_STATE_SELECTED
)
3662 bool on
= (state
& wxLIST_STATE_SELECTED
) != 0;
3664 if ( IsSingleSel() )
3668 // selecting the item also makes it the focused one in the
3670 if ( m_current
!= item
)
3672 ChangeCurrent(item
);
3674 if ( oldCurrent
!= (size_t)-1 )
3676 HighlightLine( oldCurrent
, FALSE
);
3677 RefreshLine( oldCurrent
);
3683 // only the current item may be selected anyhow
3684 if ( item
!= m_current
)
3689 if ( HighlightLine(item
, on
) )
3696 int wxListMainWindow::GetItemState( long item
, long stateMask
) const
3698 wxCHECK_MSG( item
>= 0 && (size_t)item
< GetItemCount(), 0,
3699 _T("invalid list ctrl item index in GetItemState()") );
3701 int ret
= wxLIST_STATE_DONTCARE
;
3703 if ( stateMask
& wxLIST_STATE_FOCUSED
)
3705 if ( (size_t)item
== m_current
)
3706 ret
|= wxLIST_STATE_FOCUSED
;
3709 if ( stateMask
& wxLIST_STATE_SELECTED
)
3711 if ( IsHighlighted(item
) )
3712 ret
|= wxLIST_STATE_SELECTED
;
3718 void wxListMainWindow::GetItem( wxListItem
&item
) const
3720 wxCHECK_RET( item
.m_itemId
>= 0 && (size_t)item
.m_itemId
< GetItemCount(),
3721 _T("invalid item index in GetItem") );
3723 wxListLineData
*line
= GetLine((size_t)item
.m_itemId
);
3724 line
->GetItem( item
.m_col
, item
);
3727 // ----------------------------------------------------------------------------
3729 // ----------------------------------------------------------------------------
3731 size_t wxListMainWindow::GetItemCount() const
3733 return IsVirtual() ? m_countVirt
: m_lines
.GetCount();
3736 void wxListMainWindow::SetItemCount(long count
)
3738 m_selStore
.SetItemCount(count
);
3739 m_countVirt
= count
;
3741 ResetVisibleLinesRange();
3743 // scrollbars must be reset
3747 int wxListMainWindow::GetSelectedItemCount() const
3749 // deal with the quick case first
3750 if ( IsSingleSel() )
3752 return HasCurrent() ? IsHighlighted(m_current
) : FALSE
;
3755 // virtual controls remmebers all its selections itself
3757 return m_selStore
.GetSelectedCount();
3759 // TODO: we probably should maintain the number of items selected even for
3760 // non virtual controls as enumerating all lines is really slow...
3761 size_t countSel
= 0;
3762 size_t count
= GetItemCount();
3763 for ( size_t line
= 0; line
< count
; line
++ )
3765 if ( GetLine(line
)->IsHighlighted() )
3772 // ----------------------------------------------------------------------------
3773 // item position/size
3774 // ----------------------------------------------------------------------------
3776 void wxListMainWindow::GetItemRect( long index
, wxRect
&rect
) const
3778 wxCHECK_RET( index
>= 0 && (size_t)index
< GetItemCount(),
3779 _T("invalid index in GetItemRect") );
3781 // ensure that we're laid out, otherwise we could return nonsense
3784 wxConstCast(this, wxListMainWindow
)->
3785 RecalculatePositions(TRUE
/* no refresh */);
3788 rect
= GetLineRect((size_t)index
);
3790 CalcScrolledPosition(rect
.x
, rect
.y
, &rect
.x
, &rect
.y
);
3793 bool wxListMainWindow::GetItemPosition(long item
, wxPoint
& pos
) const
3796 GetItemRect(item
, rect
);
3804 // ----------------------------------------------------------------------------
3805 // geometry calculation
3806 // ----------------------------------------------------------------------------
3808 void wxListMainWindow::RecalculatePositions(bool noRefresh
)
3810 wxClientDC
dc( this );
3811 dc
.SetFont( GetFont() );
3814 if ( HasFlag(wxLC_ICON
) )
3815 iconSpacing
= m_normal_spacing
;
3816 else if ( HasFlag(wxLC_SMALL_ICON
) )
3817 iconSpacing
= m_small_spacing
;
3821 // Note that we do not call GetClientSize() here but
3822 // GetSize() and substract the border size for sunken
3823 // borders manually. This is technically incorrect,
3824 // but we need to know the client area's size WITHOUT
3825 // scrollbars here. Since we don't know if there are
3826 // any scrollbars, we use GetSize() instead. Another
3827 // solution would be to call SetScrollbars() here to
3828 // remove the scrollbars and call GetClientSize() then,
3829 // but this might result in flicker and - worse - will
3830 // reset the scrollbars to 0 which is not good at all
3831 // if you resize a dialog/window, but don't want to
3832 // reset the window scrolling. RR.
3833 // Furthermore, we actually do NOT subtract the border
3834 // width as 2 pixels is just the extra space which we
3835 // need around the actual content in the window. Other-
3836 // wise the text would e.g. touch the upper border. RR.
3839 GetSize( &clientWidth
, &clientHeight
);
3841 if ( HasFlag(wxLC_REPORT
) )
3843 // all lines have the same height
3844 int lineHeight
= GetLineHeight();
3846 // scroll one line per step
3847 m_yScroll
= lineHeight
;
3849 size_t lineCount
= GetItemCount();
3850 int entireHeight
= lineCount
*lineHeight
+ LINE_SPACING
;
3852 m_linesPerPage
= clientHeight
/ lineHeight
;
3854 ResetVisibleLinesRange();
3856 SetScrollbars( m_xScroll
, m_yScroll
,
3857 GetHeaderWidth() / m_xScroll
,
3858 (entireHeight
+ m_yScroll
- 1)/m_yScroll
,
3859 GetScrollPos(wxHORIZONTAL
),
3860 GetScrollPos(wxVERTICAL
),
3865 // at first we try without any scrollbar. if the items don't
3866 // fit into the window, we recalculate after subtracting an
3867 // approximated 15 pt for the horizontal scrollbar
3869 int entireWidth
= 0;
3871 for (int tries
= 0; tries
< 2; tries
++)
3873 // We start with 4 for the border around all items
3878 // Now we have decided that the items do not fit into the
3879 // client area. Unfortunately, wxWindows sometimes thinks
3880 // that it does fit and therefore NO horizontal scrollbar
3881 // is inserted. This looks ugly, so we fudge here and make
3882 // the calculated width bigger than was actually has been
3883 // calculated. This ensures that wxScrolledWindows puts
3884 // a scrollbar at the bottom of its client area.
3885 entireWidth
+= SCROLL_UNIT_X
;
3888 // Start at 2,2 so the text does not touch the border
3893 int currentlyVisibleLines
= 0;
3895 size_t count
= GetItemCount();
3896 for (size_t i
= 0; i
< count
; i
++)
3898 currentlyVisibleLines
++;
3899 wxListLineData
*line
= GetLine(i
);
3900 line
->CalculateSize( &dc
, iconSpacing
);
3901 line
->SetPosition( x
, y
, clientWidth
, iconSpacing
); // Why clientWidth? (FIXME)
3903 wxSize sizeLine
= GetLineSize(i
);
3905 if ( maxWidth
< sizeLine
.x
)
3906 maxWidth
= sizeLine
.x
;
3909 if (currentlyVisibleLines
> m_linesPerPage
)
3910 m_linesPerPage
= currentlyVisibleLines
;
3912 // Assume that the size of the next one is the same... (FIXME)
3913 if ( y
+ sizeLine
.y
>= clientHeight
)
3915 currentlyVisibleLines
= 0;
3918 entireWidth
+= maxWidth
+6;
3922 // We have reached the last item.
3923 if ( i
== count
- 1 )
3924 entireWidth
+= maxWidth
;
3926 if ( (tries
== 0) && (entireWidth
+SCROLL_UNIT_X
> clientWidth
) )
3928 clientHeight
-= 15; // We guess the scrollbar height. (FIXME)
3930 currentlyVisibleLines
= 0;
3934 if ( i
== count
- 1 )
3935 tries
= 1; // Everything fits, no second try required.
3939 int scroll_pos
= GetScrollPos( wxHORIZONTAL
);
3940 SetScrollbars( m_xScroll
, m_yScroll
, (entireWidth
+SCROLL_UNIT_X
) / m_xScroll
, 0, scroll_pos
, 0, TRUE
);
3945 // FIXME: why should we call it from here?
3952 void wxListMainWindow::RefreshAll()
3957 wxListHeaderWindow
*headerWin
= GetListCtrl()->m_headerWin
;
3958 if ( headerWin
&& headerWin
->m_dirty
)
3960 headerWin
->m_dirty
= FALSE
;
3961 headerWin
->Refresh();
3965 void wxListMainWindow::UpdateCurrent()
3967 if ( !HasCurrent() && !IsEmpty() )
3973 long wxListMainWindow::GetNextItem( long item
,
3974 int WXUNUSED(geometry
),
3978 max
= GetItemCount();
3979 wxCHECK_MSG( (ret
== -1) || (ret
< max
), -1,
3980 _T("invalid listctrl index in GetNextItem()") );
3982 // notice that we start with the next item (or the first one if item == -1)
3983 // and this is intentional to allow writing a simple loop to iterate over
3984 // all selected items
3988 // this is not an error because the index was ok initially, just no
3999 size_t count
= GetItemCount();
4000 for ( size_t line
= (size_t)ret
; line
< count
; line
++ )
4002 if ( (state
& wxLIST_STATE_FOCUSED
) && (line
== m_current
) )
4005 if ( (state
& wxLIST_STATE_SELECTED
) && IsHighlighted(line
) )
4012 // ----------------------------------------------------------------------------
4014 // ----------------------------------------------------------------------------
4016 void wxListMainWindow::DeleteItem( long lindex
)
4018 size_t count
= GetItemCount();
4020 wxCHECK_RET( (lindex
>= 0) && ((size_t)lindex
< count
),
4021 _T("invalid item index in DeleteItem") );
4023 size_t index
= (size_t)lindex
;
4025 // we don't need to adjust the index for the previous items
4026 if ( HasCurrent() && m_current
>= index
)
4028 // if the current item is being deleted, we want the next one to
4029 // become selected - unless there is no next one - so don't adjust
4030 // m_current in this case
4031 if ( m_current
!= index
|| m_current
== count
- 1 )
4037 if ( InReportView() )
4039 ResetVisibleLinesRange();
4046 m_selStore
.OnItemDelete(index
);
4050 m_lines
.RemoveAt( index
);
4053 // we need to refresh the (vert) scrollbar as the number of items changed
4056 SendNotify( index
, wxEVT_COMMAND_LIST_DELETE_ITEM
);
4058 RefreshAfter(index
);
4061 void wxListMainWindow::DeleteColumn( int col
)
4063 wxListHeaderDataList::compatibility_iterator node
= m_columns
.Item( col
);
4065 wxCHECK_RET( node
, wxT("invalid column index in DeleteColumn()") );
4068 delete node
->GetData();
4069 m_columns
.Erase( node
);
4073 // update all the items
4074 for ( size_t i
= 0; i
< m_lines
.GetCount(); i
++ )
4076 wxListLineData
* const line
= GetLine(i
);
4077 wxListItemDataList::compatibility_iterator n
= line
->m_items
.Item( col
);
4078 delete n
->GetData();
4079 line
->m_items
.Erase(n
);
4083 // invalidate it as it has to be recalculated
4087 void wxListMainWindow::DoDeleteAllItems()
4091 // nothing to do - in particular, don't send the event
4097 // to make the deletion of all items faster, we don't send the
4098 // notifications for each item deletion in this case but only one event
4099 // for all of them: this is compatible with wxMSW and documented in
4100 // DeleteAllItems() description
4102 wxListEvent
event( wxEVT_COMMAND_LIST_DELETE_ALL_ITEMS
, GetParent()->GetId() );
4103 event
.SetEventObject( GetParent() );
4104 GetParent()->GetEventHandler()->ProcessEvent( event
);
4113 if ( InReportView() )
4115 ResetVisibleLinesRange();
4121 void wxListMainWindow::DeleteAllItems()
4125 RecalculatePositions();
4128 void wxListMainWindow::DeleteEverything()
4130 WX_CLEAR_LIST(wxListHeaderDataList
, m_columns
);
4135 // ----------------------------------------------------------------------------
4136 // scanning for an item
4137 // ----------------------------------------------------------------------------
4139 void wxListMainWindow::EnsureVisible( long index
)
4141 wxCHECK_RET( index
>= 0 && (size_t)index
< GetItemCount(),
4142 _T("invalid index in EnsureVisible") );
4144 // We have to call this here because the label in question might just have
4145 // been added and its position is not known yet
4148 RecalculatePositions(TRUE
/* no refresh */);
4151 MoveToItem((size_t)index
);
4154 long wxListMainWindow::FindItem(long start
, const wxString
& str
, bool WXUNUSED(partial
) )
4161 size_t count
= GetItemCount();
4162 for ( size_t i
= (size_t)pos
; i
< count
; i
++ )
4164 wxListLineData
*line
= GetLine(i
);
4165 if ( line
->GetText(0) == tmp
)
4172 long wxListMainWindow::FindItem(long start
, long data
)
4178 size_t count
= GetItemCount();
4179 for (size_t i
= (size_t)pos
; i
< count
; i
++)
4181 wxListLineData
*line
= GetLine(i
);
4183 line
->GetItem( 0, item
);
4184 if (item
.m_data
== data
)
4191 long wxListMainWindow::HitTest( int x
, int y
, int &flags
)
4193 CalcUnscrolledPosition( x
, y
, &x
, &y
);
4195 size_t count
= GetItemCount();
4197 if ( HasFlag(wxLC_REPORT
) )
4199 size_t current
= y
/ GetLineHeight();
4200 if ( current
< count
)
4202 flags
= HitTestLine(current
, x
, y
);
4209 // TODO: optimize it too! this is less simple than for report view but
4210 // enumerating all items is still not a way to do it!!
4211 for ( size_t current
= 0; current
< count
; current
++ )
4213 flags
= HitTestLine(current
, x
, y
);
4222 // ----------------------------------------------------------------------------
4224 // ----------------------------------------------------------------------------
4226 void wxListMainWindow::InsertItem( wxListItem
&item
)
4228 wxASSERT_MSG( !IsVirtual(), _T("can't be used with virtual control") );
4230 size_t count
= GetItemCount();
4231 wxCHECK_RET( item
.m_itemId
>= 0 && (size_t)item
.m_itemId
<= count
,
4232 _T("invalid item index") );
4234 size_t id
= item
.m_itemId
;
4239 if ( HasFlag(wxLC_REPORT
) )
4242 ResetVisibleLinesRange();
4244 else if ( HasFlag(wxLC_LIST
) )
4246 else if ( HasFlag(wxLC_ICON
) )
4248 else if ( HasFlag(wxLC_SMALL_ICON
) )
4249 mode
= wxLC_ICON
; // no typo
4252 wxFAIL_MSG( _T("unknown mode") );
4255 wxListLineData
*line
= new wxListLineData(this);
4257 line
->SetItem( 0, item
);
4259 m_lines
.Insert( line
, id
);
4263 SendNotify(id
, wxEVT_COMMAND_LIST_INSERT_ITEM
);
4265 RefreshLines(id
, GetItemCount() - 1);
4268 void wxListMainWindow::InsertColumn( long col
, wxListItem
&item
)
4271 if ( HasFlag(wxLC_REPORT
) )
4273 if (item
.m_width
== wxLIST_AUTOSIZE_USEHEADER
)
4274 item
.m_width
= GetTextLength( item
.m_text
);
4276 wxListHeaderData
*column
= new wxListHeaderData( item
);
4277 bool insert
= (col
>= 0) && ((size_t)col
< m_columns
.GetCount());
4280 wxListHeaderDataList::compatibility_iterator node
= m_columns
.Item( col
);
4281 m_columns
.Insert( node
, column
);
4285 m_columns
.Append( column
);
4290 // update all the items
4291 for ( size_t i
= 0; i
< m_lines
.GetCount(); i
++ )
4293 wxListLineData
* const line
= GetLine(i
);
4294 wxListItemData
* const data
= new wxListItemData(this);
4296 line
->m_items
.Insert(col
, data
);
4298 line
->m_items
.Append(data
);
4302 // invalidate it as it has to be recalculated
4307 // ----------------------------------------------------------------------------
4309 // ----------------------------------------------------------------------------
4311 wxListCtrlCompare list_ctrl_compare_func_2
;
4312 long list_ctrl_compare_data
;
4314 int LINKAGEMODE
list_ctrl_compare_func_1( wxListLineData
**arg1
, wxListLineData
**arg2
)
4316 wxListLineData
*line1
= *arg1
;
4317 wxListLineData
*line2
= *arg2
;
4319 line1
->GetItem( 0, item
);
4320 long data1
= item
.m_data
;
4321 line2
->GetItem( 0, item
);
4322 long data2
= item
.m_data
;
4323 return list_ctrl_compare_func_2( data1
, data2
, list_ctrl_compare_data
);
4326 void wxListMainWindow::SortItems( wxListCtrlCompare fn
, long data
)
4328 list_ctrl_compare_func_2
= fn
;
4329 list_ctrl_compare_data
= data
;
4330 m_lines
.Sort( list_ctrl_compare_func_1
);
4334 // ----------------------------------------------------------------------------
4336 // ----------------------------------------------------------------------------
4338 void wxListMainWindow::OnScroll(wxScrollWinEvent
& event
)
4340 // update our idea of which lines are shown when we redraw the window the
4342 ResetVisibleLinesRange();
4345 #if defined(__WXGTK__) && !defined(__WXUNIVERSAL__)
4346 wxScrolledWindow::OnScroll(event
);
4348 HandleOnScroll( event
);
4351 if ( event
.GetOrientation() == wxHORIZONTAL
&& HasHeader() )
4353 wxGenericListCtrl
* lc
= GetListCtrl();
4354 wxCHECK_RET( lc
, _T("no listctrl window?") );
4356 lc
->m_headerWin
->Refresh();
4357 lc
->m_headerWin
->Update();
4361 int wxListMainWindow::GetCountPerPage() const
4363 if ( !m_linesPerPage
)
4365 wxConstCast(this, wxListMainWindow
)->
4366 m_linesPerPage
= GetClientSize().y
/ GetLineHeight();
4369 return m_linesPerPage
;
4372 void wxListMainWindow::GetVisibleLinesRange(size_t *from
, size_t *to
)
4374 wxASSERT_MSG( HasFlag(wxLC_REPORT
), _T("this is for report mode only") );
4376 if ( m_lineFrom
== (size_t)-1 )
4378 size_t count
= GetItemCount();
4381 m_lineFrom
= GetScrollPos(wxVERTICAL
);
4383 // this may happen if SetScrollbars() hadn't been called yet
4384 if ( m_lineFrom
>= count
)
4385 m_lineFrom
= count
- 1;
4387 // we redraw one extra line but this is needed to make the redrawing
4388 // logic work when there is a fractional number of lines on screen
4389 m_lineTo
= m_lineFrom
+ m_linesPerPage
;
4390 if ( m_lineTo
>= count
)
4391 m_lineTo
= count
- 1;
4393 else // empty control
4396 m_lineTo
= (size_t)-1;
4400 wxASSERT_MSG( IsEmpty() ||
4401 (m_lineFrom
<= m_lineTo
&& m_lineTo
< GetItemCount()),
4402 _T("GetVisibleLinesRange() returns incorrect result") );
4410 // -------------------------------------------------------------------------------------
4411 // wxGenericListCtrl
4412 // -------------------------------------------------------------------------------------
4414 IMPLEMENT_DYNAMIC_CLASS(wxGenericListCtrl
, wxControl
)
4416 BEGIN_EVENT_TABLE(wxGenericListCtrl
,wxControl
)
4417 EVT_SIZE(wxGenericListCtrl::OnSize
)
4420 wxGenericListCtrl::wxGenericListCtrl()
4422 m_imageListNormal
= (wxImageListType
*) NULL
;
4423 m_imageListSmall
= (wxImageListType
*) NULL
;
4424 m_imageListState
= (wxImageListType
*) NULL
;
4426 m_ownsImageListNormal
=
4427 m_ownsImageListSmall
=
4428 m_ownsImageListState
= FALSE
;
4430 m_mainWin
= (wxListMainWindow
*) NULL
;
4431 m_headerWin
= (wxListHeaderWindow
*) NULL
;
4434 wxGenericListCtrl::~wxGenericListCtrl()
4436 if (m_ownsImageListNormal
)
4437 delete m_imageListNormal
;
4438 if (m_ownsImageListSmall
)
4439 delete m_imageListSmall
;
4440 if (m_ownsImageListState
)
4441 delete m_imageListState
;
4444 void wxGenericListCtrl::CreateHeaderWindow()
4446 m_headerWin
= new wxListHeaderWindow
4448 this, -1, m_mainWin
,
4450 wxSize(GetClientSize().x
, HEADER_HEIGHT
),
4455 bool wxGenericListCtrl::Create(wxWindow
*parent
,
4460 const wxValidator
&validator
,
4461 const wxString
&name
)
4465 m_imageListState
= (wxImageListType
*) NULL
;
4466 m_ownsImageListNormal
=
4467 m_ownsImageListSmall
=
4468 m_ownsImageListState
= FALSE
;
4470 m_mainWin
= (wxListMainWindow
*) NULL
;
4471 m_headerWin
= (wxListHeaderWindow
*) NULL
;
4473 if ( !(style
& wxLC_MASK_TYPE
) )
4475 style
= style
| wxLC_LIST
;
4478 if ( !wxControl::Create( parent
, id
, pos
, size
, style
, validator
, name
) )
4481 // don't create the inner window with the border
4482 style
&= ~wxBORDER_MASK
;
4484 m_mainWin
= new wxListMainWindow( this, -1, wxPoint(0,0), size
, style
);
4486 if ( HasFlag(wxLC_REPORT
) )
4488 CreateHeaderWindow();
4490 if ( HasFlag(wxLC_NO_HEADER
) )
4492 // VZ: why do we create it at all then?
4493 m_headerWin
->Show( FALSE
);
4500 void wxGenericListCtrl::SetSingleStyle( long style
, bool add
)
4502 wxASSERT_MSG( !(style
& wxLC_VIRTUAL
),
4503 _T("wxLC_VIRTUAL can't be [un]set") );
4505 long flag
= GetWindowStyle();
4509 if (style
& wxLC_MASK_TYPE
)
4510 flag
&= ~(wxLC_MASK_TYPE
| wxLC_VIRTUAL
);
4511 if (style
& wxLC_MASK_ALIGN
)
4512 flag
&= ~wxLC_MASK_ALIGN
;
4513 if (style
& wxLC_MASK_SORT
)
4514 flag
&= ~wxLC_MASK_SORT
;
4526 SetWindowStyleFlag( flag
);
4529 void wxGenericListCtrl::SetWindowStyleFlag( long flag
)
4533 m_mainWin
->DeleteEverything();
4535 // has the header visibility changed?
4536 bool hasHeader
= HasFlag(wxLC_REPORT
) && !HasFlag(wxLC_NO_HEADER
),
4537 willHaveHeader
= (flag
& wxLC_REPORT
) && !(flag
& wxLC_NO_HEADER
);
4539 if ( hasHeader
!= willHaveHeader
)
4546 // don't delete, just hide, as we can reuse it later
4547 m_headerWin
->Show(FALSE
);
4549 //else: nothing to do
4551 else // must show header
4555 CreateHeaderWindow();
4557 else // already have it, just show
4559 m_headerWin
->Show( TRUE
);
4563 ResizeReportView(willHaveHeader
);
4567 wxWindow::SetWindowStyleFlag( flag
);
4570 bool wxGenericListCtrl::GetColumn(int col
, wxListItem
&item
) const
4572 m_mainWin
->GetColumn( col
, item
);
4576 bool wxGenericListCtrl::SetColumn( int col
, wxListItem
& item
)
4578 m_mainWin
->SetColumn( col
, item
);
4582 int wxGenericListCtrl::GetColumnWidth( int col
) const
4584 return m_mainWin
->GetColumnWidth( col
);
4587 bool wxGenericListCtrl::SetColumnWidth( int col
, int width
)
4589 m_mainWin
->SetColumnWidth( col
, width
);
4593 int wxGenericListCtrl::GetCountPerPage() const
4595 return m_mainWin
->GetCountPerPage(); // different from Windows ?
4598 bool wxGenericListCtrl::GetItem( wxListItem
&info
) const
4600 m_mainWin
->GetItem( info
);
4604 bool wxGenericListCtrl::SetItem( wxListItem
&info
)
4606 m_mainWin
->SetItem( info
);
4610 long wxGenericListCtrl::SetItem( long index
, int col
, const wxString
& label
, int imageId
)
4613 info
.m_text
= label
;
4614 info
.m_mask
= wxLIST_MASK_TEXT
;
4615 info
.m_itemId
= index
;
4619 info
.m_image
= imageId
;
4620 info
.m_mask
|= wxLIST_MASK_IMAGE
;
4622 m_mainWin
->SetItem(info
);
4626 int wxGenericListCtrl::GetItemState( long item
, long stateMask
) const
4628 return m_mainWin
->GetItemState( item
, stateMask
);
4631 bool wxGenericListCtrl::SetItemState( long item
, long state
, long stateMask
)
4633 m_mainWin
->SetItemState( item
, state
, stateMask
);
4637 bool wxGenericListCtrl::SetItemImage( long item
, int image
, int WXUNUSED(selImage
) )
4640 info
.m_image
= image
;
4641 info
.m_mask
= wxLIST_MASK_IMAGE
;
4642 info
.m_itemId
= item
;
4643 m_mainWin
->SetItem( info
);
4647 wxString
wxGenericListCtrl::GetItemText( long item
) const
4649 return m_mainWin
->GetItemText(item
);
4652 void wxGenericListCtrl::SetItemText( long item
, const wxString
& str
)
4654 m_mainWin
->SetItemText(item
, str
);
4657 long wxGenericListCtrl::GetItemData( long item
) const
4660 info
.m_itemId
= item
;
4661 m_mainWin
->GetItem( info
);
4665 bool wxGenericListCtrl::SetItemData( long item
, long data
)
4668 info
.m_mask
= wxLIST_MASK_DATA
;
4669 info
.m_itemId
= item
;
4671 m_mainWin
->SetItem( info
);
4675 bool wxGenericListCtrl::GetItemRect( long item
, wxRect
&rect
, int WXUNUSED(code
) ) const
4677 m_mainWin
->GetItemRect( item
, rect
);
4678 if ( m_mainWin
->HasHeader() )
4679 rect
.y
+= HEADER_HEIGHT
+ 1;
4683 bool wxGenericListCtrl::GetItemPosition( long item
, wxPoint
& pos
) const
4685 m_mainWin
->GetItemPosition( item
, pos
);
4689 bool wxGenericListCtrl::SetItemPosition( long WXUNUSED(item
), const wxPoint
& WXUNUSED(pos
) )
4694 int wxGenericListCtrl::GetItemCount() const
4696 return m_mainWin
->GetItemCount();
4699 int wxGenericListCtrl::GetColumnCount() const
4701 return m_mainWin
->GetColumnCount();
4704 void wxGenericListCtrl::SetItemSpacing( int spacing
, bool isSmall
)
4706 m_mainWin
->SetItemSpacing( spacing
, isSmall
);
4709 int wxGenericListCtrl::GetItemSpacing( bool isSmall
) const
4711 return m_mainWin
->GetItemSpacing( isSmall
);
4714 void wxGenericListCtrl::SetItemTextColour( long item
, const wxColour
&col
)
4717 info
.m_itemId
= item
;
4718 info
.SetTextColour( col
);
4719 m_mainWin
->SetItem( info
);
4722 wxColour
wxGenericListCtrl::GetItemTextColour( long item
) const
4725 info
.m_itemId
= item
;
4726 m_mainWin
->GetItem( info
);
4727 return info
.GetTextColour();
4730 void wxGenericListCtrl::SetItemBackgroundColour( long item
, const wxColour
&col
)
4733 info
.m_itemId
= item
;
4734 info
.SetBackgroundColour( col
);
4735 m_mainWin
->SetItem( info
);
4738 wxColour
wxGenericListCtrl::GetItemBackgroundColour( long item
) const
4741 info
.m_itemId
= item
;
4742 m_mainWin
->GetItem( info
);
4743 return info
.GetBackgroundColour();
4746 int wxGenericListCtrl::GetSelectedItemCount() const
4748 return m_mainWin
->GetSelectedItemCount();
4751 wxColour
wxGenericListCtrl::GetTextColour() const
4753 return GetForegroundColour();
4756 void wxGenericListCtrl::SetTextColour(const wxColour
& col
)
4758 SetForegroundColour(col
);
4761 long wxGenericListCtrl::GetTopItem() const
4764 m_mainWin
->GetVisibleLinesRange(&top
, NULL
);
4768 long wxGenericListCtrl::GetNextItem( long item
, int geom
, int state
) const
4770 return m_mainWin
->GetNextItem( item
, geom
, state
);
4773 wxImageListType
*wxGenericListCtrl::GetImageList(int which
) const
4775 if (which
== wxIMAGE_LIST_NORMAL
)
4777 return m_imageListNormal
;
4779 else if (which
== wxIMAGE_LIST_SMALL
)
4781 return m_imageListSmall
;
4783 else if (which
== wxIMAGE_LIST_STATE
)
4785 return m_imageListState
;
4787 return (wxImageListType
*) NULL
;
4790 void wxGenericListCtrl::SetImageList( wxImageListType
*imageList
, int which
)
4792 if ( which
== wxIMAGE_LIST_NORMAL
)
4794 if (m_ownsImageListNormal
) delete m_imageListNormal
;
4795 m_imageListNormal
= imageList
;
4796 m_ownsImageListNormal
= FALSE
;
4798 else if ( which
== wxIMAGE_LIST_SMALL
)
4800 if (m_ownsImageListSmall
) delete m_imageListSmall
;
4801 m_imageListSmall
= imageList
;
4802 m_ownsImageListSmall
= FALSE
;
4804 else if ( which
== wxIMAGE_LIST_STATE
)
4806 if (m_ownsImageListState
) delete m_imageListState
;
4807 m_imageListState
= imageList
;
4808 m_ownsImageListState
= FALSE
;
4811 m_mainWin
->SetImageList( imageList
, which
);
4814 void wxGenericListCtrl::AssignImageList(wxImageListType
*imageList
, int which
)
4816 SetImageList(imageList
, which
);
4817 if ( which
== wxIMAGE_LIST_NORMAL
)
4818 m_ownsImageListNormal
= TRUE
;
4819 else if ( which
== wxIMAGE_LIST_SMALL
)
4820 m_ownsImageListSmall
= TRUE
;
4821 else if ( which
== wxIMAGE_LIST_STATE
)
4822 m_ownsImageListState
= TRUE
;
4825 bool wxGenericListCtrl::Arrange( int WXUNUSED(flag
) )
4830 bool wxGenericListCtrl::DeleteItem( long item
)
4832 m_mainWin
->DeleteItem( item
);
4836 bool wxGenericListCtrl::DeleteAllItems()
4838 m_mainWin
->DeleteAllItems();
4842 bool wxGenericListCtrl::DeleteAllColumns()
4844 size_t count
= m_mainWin
->m_columns
.GetCount();
4845 for ( size_t n
= 0; n
< count
; n
++ )
4851 void wxGenericListCtrl::ClearAll()
4853 m_mainWin
->DeleteEverything();
4856 bool wxGenericListCtrl::DeleteColumn( int col
)
4858 m_mainWin
->DeleteColumn( col
);
4860 // if we don't have the header any longer, we need to relayout the window
4861 if ( !GetColumnCount() )
4863 ResizeReportView(FALSE
/* no header */);
4869 void wxGenericListCtrl::Edit( long item
)
4871 m_mainWin
->EditLabel( item
);
4874 bool wxGenericListCtrl::EnsureVisible( long item
)
4876 m_mainWin
->EnsureVisible( item
);
4880 long wxGenericListCtrl::FindItem( long start
, const wxString
& str
, bool partial
)
4882 return m_mainWin
->FindItem( start
, str
, partial
);
4885 long wxGenericListCtrl::FindItem( long start
, long data
)
4887 return m_mainWin
->FindItem( start
, data
);
4890 long wxGenericListCtrl::FindItem( long WXUNUSED(start
), const wxPoint
& WXUNUSED(pt
),
4891 int WXUNUSED(direction
))
4896 long wxGenericListCtrl::HitTest( const wxPoint
&point
, int &flags
)
4898 return m_mainWin
->HitTest( (int)point
.x
, (int)point
.y
, flags
);
4901 long wxGenericListCtrl::InsertItem( wxListItem
& info
)
4903 m_mainWin
->InsertItem( info
);
4904 return info
.m_itemId
;
4907 long wxGenericListCtrl::InsertItem( long index
, const wxString
&label
)
4910 info
.m_text
= label
;
4911 info
.m_mask
= wxLIST_MASK_TEXT
;
4912 info
.m_itemId
= index
;
4913 return InsertItem( info
);
4916 long wxGenericListCtrl::InsertItem( long index
, int imageIndex
)
4919 info
.m_mask
= wxLIST_MASK_IMAGE
;
4920 info
.m_image
= imageIndex
;
4921 info
.m_itemId
= index
;
4922 return InsertItem( info
);
4925 long wxGenericListCtrl::InsertItem( long index
, const wxString
&label
, int imageIndex
)
4928 info
.m_text
= label
;
4929 info
.m_image
= imageIndex
;
4930 info
.m_mask
= wxLIST_MASK_TEXT
| wxLIST_MASK_IMAGE
;
4931 info
.m_itemId
= index
;
4932 return InsertItem( info
);
4935 long wxGenericListCtrl::InsertColumn( long col
, wxListItem
&item
)
4937 wxCHECK_MSG( m_headerWin
, -1, _T("can't add column in non report mode") );
4939 m_mainWin
->InsertColumn( col
, item
);
4941 // if we hadn't had header before and have it now we need to relayout the
4943 if ( GetColumnCount() == 1 && m_mainWin
->HasHeader() )
4945 ResizeReportView(TRUE
/* have header */);
4948 m_headerWin
->Refresh();
4953 long wxGenericListCtrl::InsertColumn( long col
, const wxString
&heading
,
4954 int format
, int width
)
4957 item
.m_mask
= wxLIST_MASK_TEXT
| wxLIST_MASK_FORMAT
;
4958 item
.m_text
= heading
;
4961 item
.m_mask
|= wxLIST_MASK_WIDTH
;
4962 item
.m_width
= width
;
4964 item
.m_format
= format
;
4966 return InsertColumn( col
, item
);
4969 bool wxGenericListCtrl::ScrollList( int WXUNUSED(dx
), int WXUNUSED(dy
) )
4975 // fn is a function which takes 3 long arguments: item1, item2, data.
4976 // item1 is the long data associated with a first item (NOT the index).
4977 // item2 is the long data associated with a second item (NOT the index).
4978 // data is the same value as passed to SortItems.
4979 // The return value is a negative number if the first item should precede the second
4980 // item, a positive number of the second item should precede the first,
4981 // or zero if the two items are equivalent.
4982 // data is arbitrary data to be passed to the sort function.
4984 bool wxGenericListCtrl::SortItems( wxListCtrlCompare fn
, long data
)
4986 m_mainWin
->SortItems( fn
, data
);
4990 // ----------------------------------------------------------------------------
4992 // ----------------------------------------------------------------------------
4994 void wxGenericListCtrl::OnSize(wxSizeEvent
& WXUNUSED(event
))
4999 ResizeReportView(m_mainWin
->HasHeader());
5001 m_mainWin
->RecalculatePositions();
5004 void wxGenericListCtrl::ResizeReportView(bool showHeader
)
5007 GetClientSize( &cw
, &ch
);
5011 m_headerWin
->SetSize( 0, 0, cw
, HEADER_HEIGHT
);
5012 m_mainWin
->SetSize( 0, HEADER_HEIGHT
+ 1, cw
, ch
- HEADER_HEIGHT
- 1 );
5014 else // no header window
5016 m_mainWin
->SetSize( 0, 0, cw
, ch
);
5020 void wxGenericListCtrl::OnInternalIdle()
5022 wxWindow::OnInternalIdle();
5024 // do it only if needed
5025 if ( !m_mainWin
->m_dirty
)
5028 m_mainWin
->RecalculatePositions();
5031 // ----------------------------------------------------------------------------
5033 // ----------------------------------------------------------------------------
5035 bool wxGenericListCtrl::SetBackgroundColour( const wxColour
&colour
)
5039 m_mainWin
->SetBackgroundColour( colour
);
5040 m_mainWin
->m_dirty
= TRUE
;
5046 bool wxGenericListCtrl::SetForegroundColour( const wxColour
&colour
)
5048 if ( !wxWindow::SetForegroundColour( colour
) )
5053 m_mainWin
->SetForegroundColour( colour
);
5054 m_mainWin
->m_dirty
= TRUE
;
5059 m_headerWin
->SetForegroundColour( colour
);
5065 bool wxGenericListCtrl::SetFont( const wxFont
&font
)
5067 if ( !wxWindow::SetFont( font
) )
5072 m_mainWin
->SetFont( font
);
5073 m_mainWin
->m_dirty
= TRUE
;
5078 m_headerWin
->SetFont( font
);
5084 // ----------------------------------------------------------------------------
5085 // methods forwarded to m_mainWin
5086 // ----------------------------------------------------------------------------
5088 #if wxUSE_DRAG_AND_DROP
5090 void wxGenericListCtrl::SetDropTarget( wxDropTarget
*dropTarget
)
5092 m_mainWin
->SetDropTarget( dropTarget
);
5095 wxDropTarget
*wxGenericListCtrl::GetDropTarget() const
5097 return m_mainWin
->GetDropTarget();
5100 #endif // wxUSE_DRAG_AND_DROP
5102 bool wxGenericListCtrl::SetCursor( const wxCursor
&cursor
)
5104 return m_mainWin
? m_mainWin
->wxWindow::SetCursor(cursor
) : FALSE
;
5107 wxColour
wxGenericListCtrl::GetBackgroundColour() const
5109 return m_mainWin
? m_mainWin
->GetBackgroundColour() : wxColour();
5112 wxColour
wxGenericListCtrl::GetForegroundColour() const
5114 return m_mainWin
? m_mainWin
->GetForegroundColour() : wxColour();
5117 bool wxGenericListCtrl::DoPopupMenu( wxMenu
*menu
, int x
, int y
)
5120 return m_mainWin
->PopupMenu( menu
, x
, y
);
5123 #endif // wxUSE_MENUS
5126 void wxGenericListCtrl::SetFocus()
5128 /* The test in window.cpp fails as we are a composite
5129 window, so it checks against "this", but not m_mainWin. */
5130 if ( FindFocus() != this )
5131 m_mainWin
->SetFocus();
5134 // ----------------------------------------------------------------------------
5135 // virtual list control support
5136 // ----------------------------------------------------------------------------
5138 wxString
wxGenericListCtrl::OnGetItemText(long WXUNUSED(item
), long WXUNUSED(col
)) const
5140 // this is a pure virtual function, in fact - which is not really pure
5141 // because the controls which are not virtual don't need to implement it
5142 wxFAIL_MSG( _T("wxGenericListCtrl::OnGetItemText not supposed to be called") );
5144 return wxEmptyString
;
5147 int wxGenericListCtrl::OnGetItemImage(long WXUNUSED(item
)) const
5150 wxFAIL_MSG( _T("wxGenericListCtrl::OnGetItemImage not supposed to be called") );
5155 wxListItemAttr
*wxGenericListCtrl::OnGetItemAttr(long item
) const
5157 wxASSERT_MSG( item
>= 0 && item
< GetItemCount(),
5158 _T("invalid item index in OnGetItemAttr()") );
5160 // no attributes by default
5164 void wxGenericListCtrl::SetItemCount(long count
)
5166 wxASSERT_MSG( IsVirtual(), _T("this is for virtual controls only") );
5168 m_mainWin
->SetItemCount(count
);
5171 void wxGenericListCtrl::RefreshItem(long item
)
5173 m_mainWin
->RefreshLine(item
);
5176 void wxGenericListCtrl::RefreshItems(long itemFrom
, long itemTo
)
5178 m_mainWin
->RefreshLines(itemFrom
, itemTo
);
5182 * Generic wxListCtrl is more or less a container for two other
5183 * windows which drawings are done upon. These are namely
5184 * 'm_headerWin' and 'm_mainWin'.
5185 * Here we override 'virtual wxWindow::Refresh()' to mimic the
5186 * behaviour wxListCtrl has under wxMSW.
5188 void wxGenericListCtrl::Refresh(bool eraseBackground
, const wxRect
*rect
)
5192 // The easy case, no rectangle specified.
5194 m_headerWin
->Refresh(eraseBackground
);
5197 m_mainWin
->Refresh(eraseBackground
);
5201 // Refresh the header window
5204 wxRect rectHeader
= m_headerWin
->GetRect();
5205 rectHeader
.Intersect(*rect
);
5206 if (rectHeader
.GetWidth() && rectHeader
.GetHeight())
5209 m_headerWin
->GetPosition(&x
, &y
);
5210 rectHeader
.Offset(-x
, -y
);
5211 m_headerWin
->Refresh(eraseBackground
, &rectHeader
);
5216 // Refresh the main window
5219 wxRect rectMain
= m_mainWin
->GetRect();
5220 rectMain
.Intersect(*rect
);
5221 if (rectMain
.GetWidth() && rectMain
.GetHeight())
5224 m_mainWin
->GetPosition(&x
, &y
);
5225 rectMain
.Offset(-x
, -y
);
5226 m_mainWin
->Refresh(eraseBackground
, &rectMain
);
5232 void wxGenericListCtrl::Freeze()
5234 m_mainWin
->Freeze();
5237 void wxGenericListCtrl::Thaw()
5242 #endif // wxUSE_LISTCTRL