1 /////////////////////////////////////////////////////////////////////////////
2 // Name: generic/listctrl.cpp
3 // Purpose: generic implementation of wxListCtrl
4 // Author: Robert Roebling
5 // Vadim Zeitlin (virtual list control support)
7 // Copyright: (c) 1998 Robert Roebling
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
14 1. we need to implement searching/sorting for virtual controls somehow
15 2. when changing selection the lines are refreshed twice
18 // ============================================================================
20 // ============================================================================
22 // ----------------------------------------------------------------------------
24 // ----------------------------------------------------------------------------
27 #pragma implementation "listctrl.h"
28 #pragma implementation "listctrlbase.h"
31 // For compilers that support precompilation, includes "wx.h".
32 #include "wx/wxprec.h"
40 #include "wx/dcscreen.h"
42 #include "wx/listctrl.h"
43 #include "wx/imaglist.h"
44 #include "wx/dynarray.h"
48 #include "wx/gtk/win_gtk.h"
51 // ----------------------------------------------------------------------------
53 // ----------------------------------------------------------------------------
55 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_BEGIN_DRAG
)
56 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_BEGIN_RDRAG
)
57 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_BEGIN_LABEL_EDIT
)
58 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_END_LABEL_EDIT
)
59 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_DELETE_ITEM
)
60 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_DELETE_ALL_ITEMS
)
61 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_GET_INFO
)
62 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_SET_INFO
)
63 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_ITEM_SELECTED
)
64 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_ITEM_DESELECTED
)
65 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_KEY_DOWN
)
66 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_INSERT_ITEM
)
67 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_COL_CLICK
)
68 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_ITEM_RIGHT_CLICK
)
69 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_ITEM_MIDDLE_CLICK
)
70 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_ITEM_ACTIVATED
)
71 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_CACHE_HINT
)
73 // ----------------------------------------------------------------------------
75 // ----------------------------------------------------------------------------
77 // the height of the header window (FIXME: should depend on its font!)
78 static const int HEADER_HEIGHT
= 23;
80 // the scrollbar units
81 static const int SCROLL_UNIT_X
= 15;
82 static const int SCROLL_UNIT_Y
= 15;
84 // the spacing between the lines (in report mode)
85 static const int LINE_SPACING
= 0;
87 // extra margins around the text label
88 static const int EXTRA_WIDTH
= 3;
89 static const int EXTRA_HEIGHT
= 4;
91 // offset for the header window
92 static const int HEADER_OFFSET_X
= 1;
93 static const int HEADER_OFFSET_Y
= 1;
95 // when autosizing the columns, add some slack
96 static const int AUTOSIZE_COL_MARGIN
= 10;
98 // default and minimal widths for the header columns
99 static const int WIDTH_COL_DEFAULT
= 80;
100 static const int WIDTH_COL_MIN
= 10;
102 // ============================================================================
104 // ============================================================================
106 // ----------------------------------------------------------------------------
108 // ----------------------------------------------------------------------------
110 int CMPFUNC_CONV
wxSizeTCmpFn(size_t n1
, size_t n2
) { return n1
- n2
; }
112 WX_DEFINE_SORTED_EXPORTED_ARRAY(size_t, wxIndexArray
);
114 // this class is used to store the selected items in the virtual list control
115 // (but it is not tied to list control and so can be used with other controls
116 // such as wxListBox in wxUniv)
118 // the idea is to make it really smart later (i.e. store the selections as an
119 // array of ranes + individual items) but, as I don't have time to do it now
120 // (this would require writing code to merge/break ranges and much more) keep
121 // it simple but define a clean interface to it which allows it to be made
123 class WXDLLEXPORT wxSelectionStore
126 wxSelectionStore() : m_itemsSel(wxSizeTCmpFn
) { Init(); }
128 // set the total number of items we handle
129 void SetItemCount(size_t count
) { m_count
= count
; }
131 // special case of SetItemCount(0)
132 void Clear() { m_itemsSel
.Clear(); m_count
= 0; }
134 // must be called when a new item is inserted/added
135 void OnItemAdd(size_t item
) { wxFAIL_MSG( _T("TODO") ); }
137 // must be called when an item is deleted
138 void OnItemDelete(size_t item
);
140 // select one item, use SelectRange() insted if possible!
142 // returns true if the items selection really changed
143 bool SelectItem(size_t item
, bool select
= TRUE
);
145 // select the range of items
147 // return true and fill the itemsChanged array with the indices of items
148 // which have changed state if "few" of them did, otherwise return false
149 // (meaning that too many items changed state to bother counting them
151 bool SelectRange(size_t itemFrom
, size_t itemTo
,
153 wxArrayInt
*itemsChanged
= NULL
);
155 // return true if the given item is selected
156 bool IsSelected(size_t item
) const;
158 // return the total number of selected items
159 size_t GetSelectedCount() const
161 return m_defaultState
? m_count
- m_itemsSel
.GetCount()
162 : m_itemsSel
.GetCount();
167 void Init() { m_defaultState
= FALSE
; }
169 // the total number of items we handle
172 // the default state: normally, FALSE (i.e. off) but maybe set to TRUE if
173 // there are more selected items than non selected ones - this allows to
174 // handle selection of all items efficiently
177 // the array of items whose selection state is different from default
178 wxIndexArray m_itemsSel
;
180 DECLARE_NO_COPY_CLASS(wxSelectionStore
)
183 //-----------------------------------------------------------------------------
184 // wxListItemData (internal)
185 //-----------------------------------------------------------------------------
187 class WXDLLEXPORT wxListItemData
190 wxListItemData(wxListMainWindow
*owner
);
193 void SetItem( const wxListItem
&info
);
194 void SetImage( int image
) { m_image
= image
; }
195 void SetData( long data
) { m_data
= data
; }
196 void SetPosition( int x
, int y
);
197 void SetSize( int width
, int height
);
199 bool HasText() const { return !m_text
.empty(); }
200 const wxString
& GetText() const { return m_text
; }
201 void SetText(const wxString
& text
) { m_text
= text
; }
203 // we can't use empty string for measuring the string width/height, so
204 // always return something
205 wxString
GetTextForMeasuring() const
207 wxString s
= GetText();
214 bool IsHit( int x
, int y
) const;
218 int GetWidth() const;
219 int GetHeight() const;
221 int GetImage() const { return m_image
; }
222 bool HasImage() const { return GetImage() != -1; }
224 void GetItem( wxListItem
&info
) const;
226 void SetAttr(wxListItemAttr
*attr
) { m_attr
= attr
; }
227 wxListItemAttr
*GetAttr() const { return m_attr
; }
230 // the item image or -1
233 // user data associated with the item
236 // the item coordinates are not used in report mode, instead this pointer
237 // is NULL and the owner window is used to retrieve the item position and
241 // the list ctrl we are in
242 wxListMainWindow
*m_owner
;
244 // custom attributes or NULL
245 wxListItemAttr
*m_attr
;
248 // common part of all ctors
254 //-----------------------------------------------------------------------------
255 // wxListHeaderData (internal)
256 //-----------------------------------------------------------------------------
258 class WXDLLEXPORT wxListHeaderData
: public wxObject
272 wxListHeaderData( const wxListItem
&info
);
273 void SetItem( const wxListItem
&item
);
274 void SetPosition( int x
, int y
);
275 void SetWidth( int w
);
276 void SetFormat( int format
);
277 void SetHeight( int h
);
278 bool HasImage() const;
280 bool HasText() const { return !m_text
.empty(); }
281 const wxString
& GetText() const { return m_text
; }
282 void SetText(const wxString
& text
) { m_text
= text
; }
284 void GetItem( wxListItem
&item
);
286 bool IsHit( int x
, int y
) const;
287 int GetImage() const;
288 int GetWidth() const;
289 int GetFormat() const;
292 DECLARE_DYNAMIC_CLASS(wxListHeaderData
);
295 //-----------------------------------------------------------------------------
296 // wxListLineData (internal)
297 //-----------------------------------------------------------------------------
299 WX_DECLARE_LIST(wxListItemData
, wxListItemDataList
);
300 #include "wx/listimpl.cpp"
301 WX_DEFINE_LIST(wxListItemDataList
);
303 class WXDLLEXPORT wxListLineData
306 // the list of subitems: only may have more than one item in report mode
307 wxListItemDataList m_items
;
309 // this is not used in report view
321 // the part to be highlighted
322 wxRect m_rectHighlight
;
325 // is this item selected? [NB: not used in virtual mode]
328 // back pointer to the list ctrl
329 wxListMainWindow
*m_owner
;
332 wxListLineData(wxListMainWindow
*owner
);
334 ~wxListLineData() { delete m_gi
; }
336 // are we in report mode?
337 inline bool InReportView() const;
339 // are we in virtual report mode?
340 inline bool IsVirtual() const;
342 // these 2 methods shouldn't be called for report view controls, in that
343 // case we determine our position/size ourselves
345 // calculate the size of the line
346 void CalculateSize( wxDC
*dc
, int spacing
);
348 // remember the position this line appears at
349 void SetPosition( int x
, int y
, int window_width
, int spacing
);
353 void SetImage( int image
) { SetImage(0, image
); }
354 int GetImage() const { return GetImage(0); }
355 bool HasImage() const { return GetImage() != -1; }
356 bool HasText() const { return !GetText(0).empty(); }
358 void SetItem( int index
, const wxListItem
&info
);
359 void GetItem( int index
, wxListItem
&info
);
361 wxString
GetText(int index
) const;
362 void SetText( int index
, const wxString s
);
364 wxListItemAttr
*GetAttr() const;
365 void SetAttr(wxListItemAttr
*attr
);
367 // return true if the highlighting really changed
368 bool Highlight( bool on
);
370 void ReverseHighlight();
372 bool IsHighlighted() const
374 wxASSERT_MSG( !IsVirtual(), _T("unexpected call to IsHighlighted") );
376 return m_highlighted
;
379 // draw the line on the given DC in icon/list mode
380 void Draw( wxDC
*dc
);
382 // the same in report mode
383 void DrawInReportMode( wxDC
*dc
,
385 const wxRect
& rectHL
,
389 // set the line to contain num items (only can be > 1 in report mode)
390 void InitItems( int num
);
392 // get the mode (i.e. style) of the list control
393 inline int GetMode() const;
395 // prepare the DC for drawing with these item's attributes, return true if
396 // we need to draw the items background to highlight it, false otherwise
397 bool SetAttributes(wxDC
*dc
,
398 const wxListItemAttr
*attr
,
401 // these are only used by GetImage/SetImage above, we don't support images
402 // with subitems at the public API level yet
403 void SetImage( int index
, int image
);
404 int GetImage( int index
) const;
407 WX_DECLARE_EXPORTED_OBJARRAY(wxListLineData
, wxListLineDataArray
);
408 #include "wx/arrimpl.cpp"
409 WX_DEFINE_OBJARRAY(wxListLineDataArray
);
411 //-----------------------------------------------------------------------------
412 // wxListHeaderWindow (internal)
413 //-----------------------------------------------------------------------------
415 class WXDLLEXPORT wxListHeaderWindow
: public wxWindow
418 wxListMainWindow
*m_owner
;
419 wxCursor
*m_currentCursor
;
420 wxCursor
*m_resizeCursor
;
423 // column being resized
426 // divider line position in logical (unscrolled) coords
429 // minimal position beyond which the divider line can't be dragged in
434 wxListHeaderWindow();
435 virtual ~wxListHeaderWindow();
437 wxListHeaderWindow( wxWindow
*win
,
439 wxListMainWindow
*owner
,
440 const wxPoint
&pos
= wxDefaultPosition
,
441 const wxSize
&size
= wxDefaultSize
,
443 const wxString
&name
= "wxlistctrlcolumntitles" );
445 void DoDrawRect( wxDC
*dc
, int x
, int y
, int w
, int h
);
447 void AdjustDC(wxDC
& dc
);
449 void OnPaint( wxPaintEvent
&event
);
450 void OnMouse( wxMouseEvent
&event
);
451 void OnSetFocus( wxFocusEvent
&event
);
457 DECLARE_DYNAMIC_CLASS(wxListHeaderWindow
)
458 DECLARE_EVENT_TABLE()
461 //-----------------------------------------------------------------------------
462 // wxListRenameTimer (internal)
463 //-----------------------------------------------------------------------------
465 class WXDLLEXPORT wxListRenameTimer
: public wxTimer
468 wxListMainWindow
*m_owner
;
471 wxListRenameTimer( wxListMainWindow
*owner
);
475 //-----------------------------------------------------------------------------
476 // wxListTextCtrl (internal)
477 //-----------------------------------------------------------------------------
479 class WXDLLEXPORT wxListTextCtrl
: public wxTextCtrl
484 wxListMainWindow
*m_owner
;
485 wxString m_startValue
;
489 wxListTextCtrl( wxWindow
*parent
, const wxWindowID id
,
490 bool *accept
, wxString
*res
, wxListMainWindow
*owner
,
491 const wxString
&value
= "",
492 const wxPoint
&pos
= wxDefaultPosition
, const wxSize
&size
= wxDefaultSize
,
494 const wxValidator
& validator
= wxDefaultValidator
,
495 const wxString
&name
= "listctrltextctrl" );
496 void OnChar( wxKeyEvent
&event
);
497 void OnKeyUp( wxKeyEvent
&event
);
498 void OnKillFocus( wxFocusEvent
&event
);
501 DECLARE_DYNAMIC_CLASS(wxListTextCtrl
);
502 DECLARE_EVENT_TABLE()
505 //-----------------------------------------------------------------------------
506 // wxListMainWindow (internal)
507 //-----------------------------------------------------------------------------
509 WX_DECLARE_LIST(wxListHeaderData
, wxListHeaderDataList
);
510 #include "wx/listimpl.cpp"
511 WX_DEFINE_LIST(wxListHeaderDataList
);
513 class WXDLLEXPORT wxListMainWindow
: public wxScrolledWindow
517 wxListMainWindow( wxWindow
*parent
,
519 const wxPoint
& pos
= wxDefaultPosition
,
520 const wxSize
& size
= wxDefaultSize
,
522 const wxString
&name
= _T("listctrlmainwindow") );
524 virtual ~wxListMainWindow();
526 bool HasFlag(int flag
) const { return m_parent
->HasFlag(flag
); }
528 // return true if this is a virtual list control
529 bool IsVirtual() const { return HasFlag(wxLC_VIRTUAL
); }
531 // return true if the control is in report mode
532 bool InReportView() const { return HasFlag(wxLC_REPORT
); }
534 // return true if we are in single selection mode, false if multi sel
535 bool IsSingleSel() const { return HasFlag(wxLC_SINGLE_SEL
); }
537 // do we have a header window?
538 bool HasHeader() const
539 { return HasFlag(wxLC_REPORT
) && !HasFlag(wxLC_NO_HEADER
); }
541 void HighlightAll( bool on
);
543 // all these functions only do something if the line is currently visible
545 // change the line "selected" state, return TRUE if it really changed
546 bool HighlightLine( size_t line
, bool highlight
= TRUE
);
548 // as HighlightLine() but do it for the range of lines: this is incredibly
549 // more efficient for virtual list controls!
551 // NB: unlike HighlightLine() this one does refresh the lines on screen
552 void HighlightLines( size_t lineFrom
, size_t lineTo
, bool on
= TRUE
);
554 // toggle the line state and refresh it
555 void ReverseHighlight( size_t line
)
556 { HighlightLine(line
, !IsHighlighted(line
)); RefreshLine(line
); }
558 // return true if the line is highlighted
559 bool IsHighlighted(size_t line
) const;
561 // refresh one or several lines at once
562 void RefreshLine( size_t line
);
563 void RefreshLines( size_t lineFrom
, size_t lineTo
);
565 // refresh all lines below the given one: the difference with
566 // RefreshLines() is that the index here might not be a valid one (happens
567 // when the last line is deleted)
568 void RefreshAfter( size_t lineFrom
);
570 // the methods which are forwarded to wxListLineData itself in list/icon
571 // modes but are here because the lines don't store their positions in the
574 // get the bound rect for the entire line
575 wxRect
GetLineRect(size_t line
) const;
577 // get the bound rect of the label
578 wxRect
GetLineLabelRect(size_t line
) const;
580 // get the bound rect of the items icon (only may be called if we do have
582 wxRect
GetLineIconRect(size_t line
) const;
584 // get the rect to be highlighted when the item has focus
585 wxRect
GetLineHighlightRect(size_t line
) const;
587 // get the size of the total line rect
588 wxSize
GetLineSize(size_t line
) const
589 { return GetLineRect(line
).GetSize(); }
591 // return the hit code for the corresponding position (in this line)
592 long HitTestLine(size_t line
, int x
, int y
) const;
594 // bring the selected item into view, scrolling to it if necessary
595 void MoveToItem(size_t item
);
597 // bring the current item into view
598 void MoveToFocus() { MoveToItem(m_current
); }
600 void EditLabel( long item
);
601 void OnRenameTimer();
602 void OnRenameAccept();
604 void OnMouse( wxMouseEvent
&event
);
606 // called to switch the selection from the current item to newCurrent,
607 void OnArrowChar( size_t newCurrent
, const wxKeyEvent
& event
);
609 void OnChar( wxKeyEvent
&event
);
610 void OnKeyDown( wxKeyEvent
&event
);
611 void OnSetFocus( wxFocusEvent
&event
);
612 void OnKillFocus( wxFocusEvent
&event
);
613 void OnScroll(wxScrollWinEvent
& event
) ;
615 void OnPaint( wxPaintEvent
&event
);
617 void DrawImage( int index
, wxDC
*dc
, int x
, int y
);
618 void GetImageSize( int index
, int &width
, int &height
) const;
619 int GetTextLength( const wxString
&s
) const;
621 void SetImageList( wxImageList
*imageList
, int which
);
622 void SetItemSpacing( int spacing
, bool isSmall
= FALSE
);
623 int GetItemSpacing( bool isSmall
= FALSE
);
625 void SetColumn( int col
, wxListItem
&item
);
626 void SetColumnWidth( int col
, int width
);
627 void GetColumn( int col
, wxListItem
&item
) const;
628 int GetColumnWidth( int col
) const;
629 int GetColumnCount() const { return m_columns
.GetCount(); }
631 // returns the sum of the heights of all columns
632 int GetHeaderWidth() const;
634 int GetCountPerPage() const;
636 void SetItem( wxListItem
&item
);
637 void GetItem( wxListItem
&item
);
638 void SetItemState( long item
, long state
, long stateMask
);
639 int GetItemState( long item
, long stateMask
);
640 void GetItemRect( long index
, wxRect
&rect
);
641 bool GetItemPosition( long item
, wxPoint
& pos
);
642 int GetSelectedItemCount();
644 // set the scrollbars and update the positions of the items
645 void RecalculatePositions(bool noRefresh
= FALSE
);
647 // refresh the window and the header
650 long GetNextItem( long item
, int geometry
, int state
);
651 void DeleteItem( long index
);
652 void DeleteAllItems();
653 void DeleteColumn( int col
);
654 void DeleteEverything();
655 void EnsureVisible( long index
);
656 long FindItem( long start
, const wxString
& str
, bool partial
= FALSE
);
657 long FindItem( long start
, long data
);
658 long HitTest( int x
, int y
, int &flags
);
659 void InsertItem( wxListItem
&item
);
660 void InsertColumn( long col
, wxListItem
&item
);
661 void SortItems( wxListCtrlCompare fn
, long data
);
663 size_t GetItemCount() const;
664 bool IsEmpty() const { return GetItemCount() == 0; }
665 void SetItemCount(long count
);
667 void ResetCurrent() { m_current
= (size_t)-1; }
668 bool HasCurrent() const { return m_current
!= (size_t)-1; }
670 // send out a wxListEvent
671 void SendNotify( size_t line
,
673 wxPoint point
= wxDefaultPosition
);
675 // override base class virtual to reset m_lineHeight when the font changes
676 virtual bool SetFont(const wxFont
& font
)
678 if ( !wxScrolledWindow::SetFont(font
) )
686 // these are for wxListLineData usage only
688 // get the backpointer to the list ctrl
689 wxListCtrl
*GetListCtrl() const
691 return wxStaticCast(GetParent(), wxListCtrl
);
694 // get the height of all lines (assuming they all do have the same height)
695 wxCoord
GetLineHeight() const;
697 // get the y position of the given line (only for report view)
698 wxCoord
GetLineY(size_t line
) const;
701 // the array of all line objects for a non virtual list control
702 wxListLineDataArray m_lines
;
704 // the list of column objects
705 wxListHeaderDataList m_columns
;
707 // currently focused item or -1
710 // the item currently being edited or -1
711 size_t m_currentEdit
;
713 // the number of lines per page
716 // this flag is set when something which should result in the window
717 // redrawing happens (i.e. an item was added or deleted, or its appearance
718 // changed) and OnPaint() doesn't redraw the window while it is set which
719 // allows to minimize the number of repaintings when a lot of items are
720 // being added. The real repainting occurs only after the next OnIdle()
724 wxBrush
*m_highlightBrush
;
725 wxColour
*m_highlightColour
;
728 wxImageList
*m_small_image_list
;
729 wxImageList
*m_normal_image_list
;
731 int m_normal_spacing
;
735 wxTimer
*m_renameTimer
;
737 wxString m_renameRes
;
742 // for double click logic
743 size_t m_lineLastClicked
,
744 m_lineBeforeLastClicked
;
747 // the total count of items in a virtual list control
750 // the object maintaining the items selection state, only used in virtual
752 wxSelectionStore m_selStore
;
754 // common part of all ctors
757 // intiialize m_[xy]Scroll
758 void InitScrolling();
760 // get the line data for the given index
761 wxListLineData
*GetLine(size_t n
) const
763 wxASSERT_MSG( n
!= (size_t)-1, _T("invalid line index") );
767 wxConstCast(this, wxListMainWindow
)->CacheLineData(n
);
775 // get a dummy line which can be used for geometry calculations and such:
776 // you must use GetLine() if you want to really draw the line
777 wxListLineData
*GetDummyLine() const;
779 // cache the line data of the n-th line in m_lines[0]
780 void CacheLineData(size_t line
);
782 // get the range of visible lines
783 void GetVisibleLinesRange(size_t *from
, size_t *to
);
785 // force us to recalculate the range of visible lines
786 void ResetVisibleLinesRange() { m_lineFrom
= (size_t)-1; }
788 // get the colour to be used for drawing the rules
789 wxColour
GetRuleColour() const
794 return wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DLIGHT
);
799 // initialize the current item if needed
800 void UpdateCurrent();
802 // delete all items but don't refresh: called from dtor
803 void DoDeleteAllItems();
805 // called when an item is [un]focuded, i.e. becomes [not] current
808 void OnFocusLine( size_t line
);
809 void OnUnfocusLine( size_t line
);
811 // the height of one line using the current font
812 wxCoord m_lineHeight
;
814 // the total header width or 0 if not calculated yet
815 wxCoord m_headerWidth
;
817 // the first and last lines being shown on screen right now (inclusive),
818 // both may be -1 if they must be calculated so never access them directly:
819 // use GetVisibleLinesRange() above instead
823 DECLARE_DYNAMIC_CLASS(wxListMainWindow
);
824 DECLARE_EVENT_TABLE()
827 // ============================================================================
829 // ============================================================================
831 // ----------------------------------------------------------------------------
833 // ----------------------------------------------------------------------------
835 bool wxSelectionStore::IsSelected(size_t item
) const
837 bool isSel
= m_itemsSel
.Index(item
) != wxNOT_FOUND
;
839 // if the default state is to be selected, being in m_itemsSel means that
840 // the item is not selected, so we have to inverse the logic
841 return m_defaultState
? !isSel
: isSel
;
844 bool wxSelectionStore::SelectItem(size_t item
, bool select
)
846 // search for the item ourselves as like this we get the index where to
847 // insert it later if needed, so we do only one search in the array instead
848 // of two (adding item to a sorted array requires a search)
849 size_t index
= m_itemsSel
.IndexForInsert(item
);
850 bool isSel
= index
< m_itemsSel
.GetCount() && m_itemsSel
[index
] == item
;
852 if ( select
!= m_defaultState
)
856 m_itemsSel
.AddAt(item
, index
);
861 else // reset to default state
865 m_itemsSel
.RemoveAt(index
);
873 bool wxSelectionStore::SelectRange(size_t itemFrom
, size_t itemTo
,
875 wxArrayInt
*itemsChanged
)
877 // 100 is hardcoded but it shouldn't matter much: the important thing is
878 // that we don't refresh everything when really few (e.g. 1 or 2) items
880 static const size_t MANY_ITEMS
= 100;
882 wxASSERT_MSG( itemFrom
<= itemTo
, _T("should be in order") );
884 // are we going to have more [un]selected items than the other ones?
885 if ( itemTo
- itemFrom
> m_count
/2 )
887 if ( select
!= m_defaultState
)
889 // the default state now becomes the same as 'select'
890 m_defaultState
= select
;
892 // so all the old selections (which had state select) shouldn't be
893 // selected any more, but all the other ones should
894 wxIndexArray selOld
= m_itemsSel
;
897 // TODO: it should be possible to optimize the searches a bit
898 // knowing the possible range
901 for ( item
= 0; item
< itemFrom
; item
++ )
903 if ( selOld
.Index(item
) == wxNOT_FOUND
)
904 m_itemsSel
.Add(item
);
907 for ( item
= itemTo
+ 1; item
< m_count
; item
++ )
909 if ( selOld
.Index(item
) == wxNOT_FOUND
)
910 m_itemsSel
.Add(item
);
913 // many items (> half) changed state
916 else // select == m_defaultState
918 // get the inclusive range of items between itemFrom and itemTo
919 size_t count
= m_itemsSel
.GetCount(),
920 start
= m_itemsSel
.IndexForInsert(itemFrom
),
921 end
= m_itemsSel
.IndexForInsert(itemTo
);
923 if ( start
== count
|| m_itemsSel
[start
] < itemFrom
)
928 if ( end
== count
|| m_itemsSel
[end
] > itemTo
)
935 // delete all of them (from end to avoid changing indices)
936 for ( int i
= end
; i
>= (int)start
; i
-- )
940 if ( itemsChanged
->GetCount() > MANY_ITEMS
)
942 // stop counting (see comment below)
946 itemsChanged
->Add(m_itemsSel
[i
]);
949 m_itemsSel
.RemoveAt(i
);
954 else // "few" items change state
958 itemsChanged
->Empty();
961 // just add the items to the selection
962 for ( size_t item
= itemFrom
; item
<= itemTo
; item
++ )
964 if ( SelectItem(item
, select
) && itemsChanged
)
966 itemsChanged
->Add(item
);
968 if ( itemsChanged
->GetCount() > MANY_ITEMS
)
970 // stop counting them, we'll just eat gobs of memory
971 // for nothing at all - faster to refresh everything in
979 // we set it to NULL if there are many items changing state
980 return itemsChanged
!= NULL
;
983 void wxSelectionStore::OnItemDelete(size_t item
)
985 size_t count
= m_itemsSel
.GetCount(),
986 i
= m_itemsSel
.IndexForInsert(item
);
988 if ( i
< count
&& m_itemsSel
[i
] == item
)
990 // this item itself was in m_itemsSel, remove it from there
991 m_itemsSel
.RemoveAt(i
);
996 // and adjust the index of all which follow it
999 // all following elements must be greater than the one we deleted
1000 wxASSERT_MSG( m_itemsSel
[i
] > item
, _T("logic error") );
1006 //-----------------------------------------------------------------------------
1008 //-----------------------------------------------------------------------------
1010 wxListItemData::~wxListItemData()
1012 // in the virtual list control the attributes are managed by the main
1013 // program, so don't delete them
1014 if ( !m_owner
->IsVirtual() )
1022 void wxListItemData::Init()
1030 wxListItemData::wxListItemData(wxListMainWindow
*owner
)
1036 if ( owner
->InReportView() )
1042 m_rect
= new wxRect
;
1046 void wxListItemData::SetItem( const wxListItem
&info
)
1048 if ( info
.m_mask
& wxLIST_MASK_TEXT
)
1049 SetText(info
.m_text
);
1050 if ( info
.m_mask
& wxLIST_MASK_IMAGE
)
1051 m_image
= info
.m_image
;
1052 if ( info
.m_mask
& wxLIST_MASK_DATA
)
1053 m_data
= info
.m_data
;
1055 if ( info
.HasAttributes() )
1058 *m_attr
= *info
.GetAttributes();
1060 m_attr
= new wxListItemAttr(*info
.GetAttributes());
1068 m_rect
->width
= info
.m_width
;
1072 void wxListItemData::SetPosition( int x
, int y
)
1074 wxCHECK_RET( m_rect
, _T("unexpected SetPosition() call") );
1080 void wxListItemData::SetSize( int width
, int height
)
1082 wxCHECK_RET( m_rect
, _T("unexpected SetSize() call") );
1085 m_rect
->width
= width
;
1087 m_rect
->height
= height
;
1090 bool wxListItemData::IsHit( int x
, int y
) const
1092 wxCHECK_MSG( m_rect
, FALSE
, _T("can't be called in this mode") );
1094 return wxRect(GetX(), GetY(), GetWidth(), GetHeight()).Inside(x
, y
);
1097 int wxListItemData::GetX() const
1099 wxCHECK_MSG( m_rect
, 0, _T("can't be called in this mode") );
1104 int wxListItemData::GetY() const
1106 wxCHECK_MSG( m_rect
, 0, _T("can't be called in this mode") );
1111 int wxListItemData::GetWidth() const
1113 wxCHECK_MSG( m_rect
, 0, _T("can't be called in this mode") );
1115 return m_rect
->width
;
1118 int wxListItemData::GetHeight() const
1120 wxCHECK_MSG( m_rect
, 0, _T("can't be called in this mode") );
1122 return m_rect
->height
;
1125 void wxListItemData::GetItem( wxListItem
&info
) const
1127 info
.m_text
= m_text
;
1128 info
.m_image
= m_image
;
1129 info
.m_data
= m_data
;
1133 if ( m_attr
->HasTextColour() )
1134 info
.SetTextColour(m_attr
->GetTextColour());
1135 if ( m_attr
->HasBackgroundColour() )
1136 info
.SetBackgroundColour(m_attr
->GetBackgroundColour());
1137 if ( m_attr
->HasFont() )
1138 info
.SetFont(m_attr
->GetFont());
1142 //-----------------------------------------------------------------------------
1144 //-----------------------------------------------------------------------------
1146 IMPLEMENT_DYNAMIC_CLASS(wxListHeaderData
,wxObject
);
1148 wxListHeaderData::wxListHeaderData()
1159 wxListHeaderData::wxListHeaderData( const wxListItem
&item
)
1167 void wxListHeaderData::SetItem( const wxListItem
&item
)
1169 m_mask
= item
.m_mask
;
1170 m_text
= item
.m_text
;
1171 m_image
= item
.m_image
;
1172 m_format
= item
.m_format
;
1174 SetWidth(item
.m_width
);
1177 void wxListHeaderData::SetPosition( int x
, int y
)
1183 void wxListHeaderData::SetHeight( int h
)
1188 void wxListHeaderData::SetWidth( int w
)
1192 m_width
= WIDTH_COL_DEFAULT
;
1193 if (m_width
< WIDTH_COL_MIN
)
1194 m_width
= WIDTH_COL_MIN
;
1197 void wxListHeaderData::SetFormat( int format
)
1202 bool wxListHeaderData::HasImage() const
1204 return (m_image
!= 0);
1207 bool wxListHeaderData::IsHit( int x
, int y
) const
1209 return ((x
>= m_xpos
) && (x
<= m_xpos
+m_width
) && (y
>= m_ypos
) && (y
<= m_ypos
+m_height
));
1212 void wxListHeaderData::GetItem( wxListItem
&item
)
1214 item
.m_mask
= m_mask
;
1215 item
.m_text
= m_text
;
1216 item
.m_image
= m_image
;
1217 item
.m_format
= m_format
;
1218 item
.m_width
= m_width
;
1221 int wxListHeaderData::GetImage() const
1226 int wxListHeaderData::GetWidth() const
1231 int wxListHeaderData::GetFormat() const
1236 //-----------------------------------------------------------------------------
1238 //-----------------------------------------------------------------------------
1240 inline int wxListLineData::GetMode() const
1242 return m_owner
->GetListCtrl()->GetWindowStyleFlag() & wxLC_MASK_TYPE
;
1245 inline bool wxListLineData::InReportView() const
1247 return m_owner
->HasFlag(wxLC_REPORT
);
1250 inline bool wxListLineData::IsVirtual() const
1252 return m_owner
->IsVirtual();
1255 wxListLineData::wxListLineData( wxListMainWindow
*owner
)
1258 m_items
.DeleteContents( TRUE
);
1260 if ( InReportView() )
1266 m_gi
= new GeometryInfo
;
1269 m_highlighted
= FALSE
;
1271 InitItems( GetMode() == wxLC_REPORT
? m_owner
->GetColumnCount() : 1 );
1274 void wxListLineData::CalculateSize( wxDC
*dc
, int spacing
)
1276 wxListItemDataList::Node
*node
= m_items
.GetFirst();
1277 wxCHECK_RET( node
, _T("no subitems at all??") );
1279 wxListItemData
*item
= node
->GetData();
1281 switch ( GetMode() )
1284 case wxLC_SMALL_ICON
:
1286 m_gi
->m_rectAll
.width
= spacing
;
1288 wxString s
= item
->GetText();
1294 m_gi
->m_rectLabel
.width
=
1295 m_gi
->m_rectLabel
.height
= 0;
1299 dc
->GetTextExtent( s
, &lw
, &lh
);
1300 if (lh
< SCROLL_UNIT_Y
)
1305 m_gi
->m_rectAll
.height
= spacing
+ lh
;
1307 m_gi
->m_rectAll
.width
= lw
;
1309 m_gi
->m_rectLabel
.width
= lw
;
1310 m_gi
->m_rectLabel
.height
= lh
;
1313 if (item
->HasImage())
1316 m_owner
->GetImageSize( item
->GetImage(), w
, h
);
1317 m_gi
->m_rectIcon
.width
= w
+ 8;
1318 m_gi
->m_rectIcon
.height
= h
+ 8;
1320 if ( m_gi
->m_rectIcon
.width
> m_gi
->m_rectAll
.width
)
1321 m_gi
->m_rectAll
.width
= m_gi
->m_rectIcon
.width
;
1322 if ( m_gi
->m_rectIcon
.height
+ lh
> m_gi
->m_rectAll
.height
- 4 )
1323 m_gi
->m_rectAll
.height
= m_gi
->m_rectIcon
.height
+ lh
+ 4;
1326 if ( item
->HasText() )
1328 m_gi
->m_rectHighlight
.width
= m_gi
->m_rectLabel
.width
;
1329 m_gi
->m_rectHighlight
.height
= m_gi
->m_rectLabel
.height
;
1331 else // no text, highlight the icon
1333 m_gi
->m_rectHighlight
.width
= m_gi
->m_rectIcon
.width
;
1334 m_gi
->m_rectHighlight
.height
= m_gi
->m_rectIcon
.height
;
1341 wxString s
= item
->GetTextForMeasuring();
1344 dc
->GetTextExtent( s
, &lw
, &lh
);
1345 if (lh
< SCROLL_UNIT_Y
)
1350 m_gi
->m_rectLabel
.width
= lw
;
1351 m_gi
->m_rectLabel
.height
= lh
;
1353 m_gi
->m_rectAll
.width
= lw
;
1354 m_gi
->m_rectAll
.height
= lh
;
1356 if (item
->HasImage())
1359 m_owner
->GetImageSize( item
->GetImage(), w
, h
);
1360 m_gi
->m_rectIcon
.width
= w
;
1361 m_gi
->m_rectIcon
.height
= h
;
1363 m_gi
->m_rectAll
.width
+= 4 + w
;
1364 if (h
> m_gi
->m_rectAll
.height
)
1365 m_gi
->m_rectAll
.height
= h
;
1368 m_gi
->m_rectHighlight
.width
= m_gi
->m_rectAll
.width
;
1369 m_gi
->m_rectHighlight
.height
= m_gi
->m_rectAll
.height
;
1374 wxFAIL_MSG( _T("unexpected call to SetSize") );
1378 wxFAIL_MSG( _T("unknown mode") );
1382 void wxListLineData::SetPosition( int x
, int y
,
1386 wxListItemDataList::Node
*node
= m_items
.GetFirst();
1387 wxCHECK_RET( node
, _T("no subitems at all??") );
1389 wxListItemData
*item
= node
->GetData();
1391 switch ( GetMode() )
1394 case wxLC_SMALL_ICON
:
1395 m_gi
->m_rectAll
.x
= x
;
1396 m_gi
->m_rectAll
.y
= y
;
1398 if ( item
->HasImage() )
1400 m_gi
->m_rectIcon
.x
= m_gi
->m_rectAll
.x
+ 4
1401 + (spacing
- m_gi
->m_rectIcon
.width
)/2;
1402 m_gi
->m_rectIcon
.y
= m_gi
->m_rectAll
.y
+ 4;
1405 if ( item
->HasText() )
1407 if (m_gi
->m_rectAll
.width
> spacing
)
1408 m_gi
->m_rectLabel
.x
= m_gi
->m_rectAll
.x
+ 2;
1410 m_gi
->m_rectLabel
.x
= m_gi
->m_rectAll
.x
+ 2 + (spacing
/2) - (m_gi
->m_rectLabel
.width
/2);
1411 m_gi
->m_rectLabel
.y
= m_gi
->m_rectAll
.y
+ m_gi
->m_rectAll
.height
+ 2 - m_gi
->m_rectLabel
.height
;
1412 m_gi
->m_rectHighlight
.x
= m_gi
->m_rectLabel
.x
- 2;
1413 m_gi
->m_rectHighlight
.y
= m_gi
->m_rectLabel
.y
- 2;
1415 else // no text, highlight the icon
1417 m_gi
->m_rectHighlight
.x
= m_gi
->m_rectIcon
.x
- 4;
1418 m_gi
->m_rectHighlight
.y
= m_gi
->m_rectIcon
.y
- 4;
1423 m_gi
->m_rectAll
.x
= x
;
1424 m_gi
->m_rectAll
.y
= y
;
1426 m_gi
->m_rectHighlight
.x
= m_gi
->m_rectAll
.x
;
1427 m_gi
->m_rectHighlight
.y
= m_gi
->m_rectAll
.y
;
1428 m_gi
->m_rectLabel
.y
= m_gi
->m_rectAll
.y
+ 2;
1430 if (item
->HasImage())
1432 m_gi
->m_rectIcon
.x
= m_gi
->m_rectAll
.x
+ 2;
1433 m_gi
->m_rectIcon
.y
= m_gi
->m_rectAll
.y
+ 2;
1434 m_gi
->m_rectLabel
.x
= m_gi
->m_rectAll
.x
+ 6 + m_gi
->m_rectIcon
.width
;
1438 m_gi
->m_rectLabel
.x
= m_gi
->m_rectAll
.x
+ 2;
1443 wxFAIL_MSG( _T("unexpected call to SetPosition") );
1447 wxFAIL_MSG( _T("unknown mode") );
1451 void wxListLineData::InitItems( int num
)
1453 for (int i
= 0; i
< num
; i
++)
1454 m_items
.Append( new wxListItemData(m_owner
) );
1457 void wxListLineData::SetItem( int index
, const wxListItem
&info
)
1459 wxListItemDataList::Node
*node
= m_items
.Item( index
);
1460 wxCHECK_RET( node
, _T("invalid column index in SetItem") );
1462 wxListItemData
*item
= node
->GetData();
1463 item
->SetItem( info
);
1466 void wxListLineData::GetItem( int index
, wxListItem
&info
)
1468 wxListItemDataList::Node
*node
= m_items
.Item( index
);
1471 wxListItemData
*item
= node
->GetData();
1472 item
->GetItem( info
);
1476 wxString
wxListLineData::GetText(int index
) const
1480 wxListItemDataList::Node
*node
= m_items
.Item( index
);
1483 wxListItemData
*item
= node
->GetData();
1484 s
= item
->GetText();
1490 void wxListLineData::SetText( int index
, const wxString s
)
1492 wxListItemDataList::Node
*node
= m_items
.Item( index
);
1495 wxListItemData
*item
= node
->GetData();
1500 void wxListLineData::SetImage( int index
, int image
)
1502 wxListItemDataList::Node
*node
= m_items
.Item( index
);
1503 wxCHECK_RET( node
, _T("invalid column index in SetImage()") );
1505 wxListItemData
*item
= node
->GetData();
1506 item
->SetImage(image
);
1509 int wxListLineData::GetImage( int index
) const
1511 wxListItemDataList::Node
*node
= m_items
.Item( index
);
1512 wxCHECK_MSG( node
, -1, _T("invalid column index in GetImage()") );
1514 wxListItemData
*item
= node
->GetData();
1515 return item
->GetImage();
1518 wxListItemAttr
*wxListLineData::GetAttr() const
1520 wxListItemDataList::Node
*node
= m_items
.GetFirst();
1521 wxCHECK_MSG( node
, NULL
, _T("invalid column index in GetAttr()") );
1523 wxListItemData
*item
= node
->GetData();
1524 return item
->GetAttr();
1527 void wxListLineData::SetAttr(wxListItemAttr
*attr
)
1529 wxListItemDataList::Node
*node
= m_items
.GetFirst();
1530 wxCHECK_RET( node
, _T("invalid column index in SetAttr()") );
1532 wxListItemData
*item
= node
->GetData();
1533 item
->SetAttr(attr
);
1536 bool wxListLineData::SetAttributes(wxDC
*dc
,
1537 const wxListItemAttr
*attr
,
1540 wxWindow
*listctrl
= m_owner
->GetParent();
1544 // don't use foreground colour for drawing highlighted items - this might
1545 // make them completely invisible (and there is no way to do bit
1546 // arithmetics on wxColour, unfortunately)
1550 colText
= wxSystemSettings::GetSystemColour(wxSYS_COLOUR_HIGHLIGHTTEXT
);
1554 if ( attr
&& attr
->HasTextColour() )
1556 colText
= attr
->GetTextColour();
1560 colText
= listctrl
->GetForegroundColour();
1564 dc
->SetTextForeground(colText
);
1568 if ( attr
&& attr
->HasFont() )
1570 font
= attr
->GetFont();
1574 font
= listctrl
->GetFont();
1580 bool hasBgCol
= attr
&& attr
->HasBackgroundColour();
1581 if ( highlighted
|| hasBgCol
)
1585 dc
->SetBrush( *m_owner
->m_highlightBrush
);
1589 dc
->SetBrush(wxBrush(attr
->GetBackgroundColour(), wxSOLID
));
1592 dc
->SetPen( *wxTRANSPARENT_PEN
);
1600 void wxListLineData::Draw( wxDC
*dc
)
1602 wxListItemDataList::Node
*node
= m_items
.GetFirst();
1603 wxCHECK_RET( node
, _T("no subitems at all??") );
1605 bool highlighted
= IsHighlighted();
1607 wxListItemAttr
*attr
= GetAttr();
1609 if ( SetAttributes(dc
, attr
, highlighted
) )
1611 dc
->DrawRectangle( m_gi
->m_rectHighlight
);
1614 wxListItemData
*item
= node
->GetData();
1615 if (item
->HasImage())
1617 wxRect rectIcon
= m_gi
->m_rectIcon
;
1618 m_owner
->DrawImage( item
->GetImage(), dc
,
1619 rectIcon
.x
, rectIcon
.y
);
1622 if (item
->HasText())
1624 wxRect rectLabel
= m_gi
->m_rectLabel
;
1625 dc
->DrawText( item
->GetText(), rectLabel
.x
, rectLabel
.y
);
1629 void wxListLineData::DrawInReportMode( wxDC
*dc
,
1631 const wxRect
& rectHL
,
1634 // TODO: later we should support setting different attributes for
1635 // different columns - to do it, just add "col" argument to
1636 // GetAttr() and move these lines into the loop below
1637 wxListItemAttr
*attr
= GetAttr();
1638 if ( SetAttributes(dc
, attr
, highlighted
) )
1640 dc
->DrawRectangle( rectHL
);
1643 wxListItemDataList::Node
*node
= m_items
.GetFirst();
1644 wxCHECK_RET( node
, _T("no subitems at all??") );
1647 wxCoord x
= rect
.x
+ HEADER_OFFSET_X
,
1648 y
= rect
.y
+ (LINE_SPACING
+ EXTRA_HEIGHT
) / 2;
1652 wxListItemData
*item
= node
->GetData();
1656 if ( item
->HasImage() )
1659 m_owner
->DrawImage( item
->GetImage(), dc
, x
, y
);
1660 m_owner
->GetImageSize( item
->GetImage(), ix
, iy
);
1661 x
+= ix
+ 5; // FIXME: what is "5"?
1664 int width
= m_owner
->GetColumnWidth(col
++);
1666 wxDCClipper
clipper(*dc
, x
, y
, width
, rect
.height
);
1668 if ( item
->HasText() )
1670 dc
->DrawText( item
->GetText(), x
, y
);
1675 node
= node
->GetNext();
1679 bool wxListLineData::Highlight( bool on
)
1681 wxCHECK_MSG( !m_owner
->IsVirtual(), FALSE
, _T("unexpected call to Highlight") );
1683 if ( on
== m_highlighted
)
1691 void wxListLineData::ReverseHighlight( void )
1693 Highlight(!IsHighlighted());
1696 //-----------------------------------------------------------------------------
1697 // wxListHeaderWindow
1698 //-----------------------------------------------------------------------------
1700 IMPLEMENT_DYNAMIC_CLASS(wxListHeaderWindow
,wxWindow
);
1702 BEGIN_EVENT_TABLE(wxListHeaderWindow
,wxWindow
)
1703 EVT_PAINT (wxListHeaderWindow::OnPaint
)
1704 EVT_MOUSE_EVENTS (wxListHeaderWindow::OnMouse
)
1705 EVT_SET_FOCUS (wxListHeaderWindow::OnSetFocus
)
1708 wxListHeaderWindow::wxListHeaderWindow( void )
1710 m_owner
= (wxListMainWindow
*) NULL
;
1711 m_currentCursor
= (wxCursor
*) NULL
;
1712 m_resizeCursor
= (wxCursor
*) NULL
;
1713 m_isDragging
= FALSE
;
1716 wxListHeaderWindow::wxListHeaderWindow( wxWindow
*win
, wxWindowID id
, wxListMainWindow
*owner
,
1717 const wxPoint
&pos
, const wxSize
&size
,
1718 long style
, const wxString
&name
) :
1719 wxWindow( win
, id
, pos
, size
, style
, name
)
1722 // m_currentCursor = wxSTANDARD_CURSOR;
1723 m_currentCursor
= (wxCursor
*) NULL
;
1724 m_resizeCursor
= new wxCursor( wxCURSOR_SIZEWE
);
1725 m_isDragging
= FALSE
;
1728 SetBackgroundColour( wxSystemSettings::GetSystemColour( wxSYS_COLOUR_BTNFACE
) );
1731 wxListHeaderWindow::~wxListHeaderWindow( void )
1733 delete m_resizeCursor
;
1736 void wxListHeaderWindow::DoDrawRect( wxDC
*dc
, int x
, int y
, int w
, int h
)
1739 GtkStateType state
= m_parent
->IsEnabled() ? GTK_STATE_NORMAL
1740 : GTK_STATE_INSENSITIVE
;
1742 x
= dc
->XLOG2DEV( x
);
1744 gtk_paint_box (m_wxwindow
->style
, GTK_PIZZA(m_wxwindow
)->bin_window
,
1745 state
, GTK_SHADOW_OUT
,
1746 (GdkRectangle
*) NULL
, m_wxwindow
, "button",
1747 x
-1, y
-1, w
+2, h
+2);
1748 #elif defined( __WXMAC__ )
1749 const int m_corner
= 1;
1751 dc
->SetBrush( *wxTRANSPARENT_BRUSH
);
1753 dc
->SetPen( wxPen( wxSystemSettings::GetSystemColour( wxSYS_COLOUR_BTNSHADOW
) , 1 , wxSOLID
) );
1754 dc
->DrawLine( x
+w
-m_corner
+1, y
, x
+w
, y
+h
); // right (outer)
1755 dc
->DrawRectangle( x
, y
+h
, w
+1, 1 ); // bottom (outer)
1757 wxPen
pen( wxColour( 0x88 , 0x88 , 0x88 ), 1, wxSOLID
);
1760 dc
->DrawLine( x
+w
-m_corner
, y
, x
+w
-1, y
+h
); // right (inner)
1761 dc
->DrawRectangle( x
+1, y
+h
-1, w
-2, 1 ); // bottom (inner)
1763 dc
->SetPen( *wxWHITE_PEN
);
1764 dc
->DrawRectangle( x
, y
, w
-m_corner
+1, 1 ); // top (outer)
1765 dc
->DrawRectangle( x
, y
, 1, h
); // left (outer)
1766 dc
->DrawLine( x
, y
+h
-1, x
+1, y
+h
-1 );
1767 dc
->DrawLine( x
+w
-1, y
, x
+w
-1, y
+1 );
1769 const int m_corner
= 1;
1771 dc
->SetBrush( *wxTRANSPARENT_BRUSH
);
1773 dc
->SetPen( *wxBLACK_PEN
);
1774 dc
->DrawLine( x
+w
-m_corner
+1, y
, x
+w
, y
+h
); // right (outer)
1775 dc
->DrawRectangle( x
, y
+h
, w
+1, 1 ); // bottom (outer)
1777 wxPen
pen( wxSystemSettings::GetSystemColour( wxSYS_COLOUR_BTNSHADOW
), 1, wxSOLID
);
1780 dc
->DrawLine( x
+w
-m_corner
, y
, x
+w
-1, y
+h
); // right (inner)
1781 dc
->DrawRectangle( x
+1, y
+h
-1, w
-2, 1 ); // bottom (inner)
1783 dc
->SetPen( *wxWHITE_PEN
);
1784 dc
->DrawRectangle( x
, y
, w
-m_corner
+1, 1 ); // top (outer)
1785 dc
->DrawRectangle( x
, y
, 1, h
); // left (outer)
1786 dc
->DrawLine( x
, y
+h
-1, x
+1, y
+h
-1 );
1787 dc
->DrawLine( x
+w
-1, y
, x
+w
-1, y
+1 );
1791 // shift the DC origin to match the position of the main window horz
1792 // scrollbar: this allows us to always use logical coords
1793 void wxListHeaderWindow::AdjustDC(wxDC
& dc
)
1796 m_owner
->GetScrollPixelsPerUnit( &xpix
, NULL
);
1799 m_owner
->GetViewStart( &x
, NULL
);
1801 // account for the horz scrollbar offset
1802 dc
.SetDeviceOrigin( -x
* xpix
, 0 );
1805 void wxListHeaderWindow::OnPaint( wxPaintEvent
&WXUNUSED(event
) )
1808 wxClientDC
dc( this );
1810 wxPaintDC
dc( this );
1818 dc
.SetFont( GetFont() );
1820 // width and height of the entire header window
1822 GetClientSize( &w
, &h
);
1823 m_owner
->CalcUnscrolledPosition(w
, 0, &w
, NULL
);
1825 dc
.SetBackgroundMode(wxTRANSPARENT
);
1827 // do *not* use the listctrl colour for headers - one day we will have a
1828 // function to set it separately
1829 //dc.SetTextForeground( *wxBLACK );
1830 dc
.SetTextForeground(wxSystemSettings::
1831 GetSystemColour( wxSYS_COLOUR_WINDOWTEXT
));
1833 int x
= HEADER_OFFSET_X
;
1835 int numColumns
= m_owner
->GetColumnCount();
1837 for (int i
= 0; i
< numColumns
; i
++)
1839 m_owner
->GetColumn( i
, item
);
1840 int wCol
= item
.m_width
;
1841 int cw
= wCol
- 2; // the width of the rect to draw
1843 int xEnd
= x
+ wCol
;
1845 dc
.SetPen( *wxWHITE_PEN
);
1847 DoDrawRect( &dc
, x
, HEADER_OFFSET_Y
, cw
, h
-2 );
1848 dc
.SetClippingRegion( x
, HEADER_OFFSET_Y
, cw
-5, h
-4 );
1849 dc
.DrawText( item
.GetText(), x
+ EXTRA_WIDTH
, HEADER_OFFSET_Y
+ EXTRA_HEIGHT
);
1850 dc
.DestroyClippingRegion();
1859 void wxListHeaderWindow::DrawCurrent()
1861 int x1
= m_currentX
;
1863 ClientToScreen( &x1
, &y1
);
1865 int x2
= m_currentX
-1;
1867 m_owner
->GetClientSize( NULL
, &y2
);
1868 m_owner
->ClientToScreen( &x2
, &y2
);
1871 dc
.SetLogicalFunction( wxINVERT
);
1872 dc
.SetPen( wxPen( *wxBLACK
, 2, wxSOLID
) );
1873 dc
.SetBrush( *wxTRANSPARENT_BRUSH
);
1877 dc
.DrawLine( x1
, y1
, x2
, y2
);
1879 dc
.SetLogicalFunction( wxCOPY
);
1881 dc
.SetPen( wxNullPen
);
1882 dc
.SetBrush( wxNullBrush
);
1885 void wxListHeaderWindow::OnMouse( wxMouseEvent
&event
)
1887 // we want to work with logical coords
1889 m_owner
->CalcUnscrolledPosition(event
.GetX(), 0, &x
, NULL
);
1890 int y
= event
.GetY();
1894 // we don't draw the line beyond our window, but we allow dragging it
1897 GetClientSize( &w
, NULL
);
1898 m_owner
->CalcUnscrolledPosition(w
, 0, &w
, NULL
);
1901 // erase the line if it was drawn
1902 if ( m_currentX
< w
)
1905 if (event
.ButtonUp())
1908 m_isDragging
= FALSE
;
1910 m_owner
->SetColumnWidth( m_column
, m_currentX
- m_minX
);
1917 m_currentX
= m_minX
+ 7;
1919 // draw in the new location
1920 if ( m_currentX
< w
)
1924 else // not dragging
1927 bool hit_border
= FALSE
;
1929 // end of the current column
1932 // find the column where this event occured
1933 int countCol
= m_owner
->GetColumnCount();
1934 for (int col
= 0; col
< countCol
; col
++)
1936 xpos
+= m_owner
->GetColumnWidth( col
);
1939 if ( (abs(x
-xpos
) < 3) && (y
< 22) )
1941 // near the column border
1948 // inside the column
1955 if (event
.LeftDown())
1959 m_isDragging
= TRUE
;
1966 wxWindow
*parent
= GetParent();
1967 wxListEvent
le( wxEVT_COMMAND_LIST_COL_CLICK
, parent
->GetId() );
1968 le
.SetEventObject( parent
);
1969 le
.m_col
= m_column
;
1970 parent
->GetEventHandler()->ProcessEvent( le
);
1973 else if (event
.Moving())
1978 setCursor
= m_currentCursor
== wxSTANDARD_CURSOR
;
1979 m_currentCursor
= m_resizeCursor
;
1983 setCursor
= m_currentCursor
!= wxSTANDARD_CURSOR
;
1984 m_currentCursor
= wxSTANDARD_CURSOR
;
1988 SetCursor(*m_currentCursor
);
1993 void wxListHeaderWindow::OnSetFocus( wxFocusEvent
&WXUNUSED(event
) )
1995 m_owner
->SetFocus();
1998 //-----------------------------------------------------------------------------
1999 // wxListRenameTimer (internal)
2000 //-----------------------------------------------------------------------------
2002 wxListRenameTimer::wxListRenameTimer( wxListMainWindow
*owner
)
2007 void wxListRenameTimer::Notify()
2009 m_owner
->OnRenameTimer();
2012 //-----------------------------------------------------------------------------
2013 // wxListTextCtrl (internal)
2014 //-----------------------------------------------------------------------------
2016 IMPLEMENT_DYNAMIC_CLASS(wxListTextCtrl
,wxTextCtrl
);
2018 BEGIN_EVENT_TABLE(wxListTextCtrl
,wxTextCtrl
)
2019 EVT_CHAR (wxListTextCtrl::OnChar
)
2020 EVT_KEY_UP (wxListTextCtrl::OnKeyUp
)
2021 EVT_KILL_FOCUS (wxListTextCtrl::OnKillFocus
)
2024 wxListTextCtrl::wxListTextCtrl( wxWindow
*parent
,
2025 const wxWindowID id
,
2028 wxListMainWindow
*owner
,
2029 const wxString
&value
,
2033 const wxValidator
& validator
,
2034 const wxString
&name
)
2035 : wxTextCtrl( parent
, id
, value
, pos
, size
, style
, validator
, name
)
2040 (*m_accept
) = FALSE
;
2042 m_startValue
= value
;
2045 void wxListTextCtrl::OnChar( wxKeyEvent
&event
)
2047 if (event
.m_keyCode
== WXK_RETURN
)
2050 (*m_res
) = GetValue();
2052 if (!wxPendingDelete
.Member(this))
2053 wxPendingDelete
.Append(this);
2055 if ((*m_accept
) && ((*m_res
) != m_startValue
))
2056 m_owner
->OnRenameAccept();
2060 if (event
.m_keyCode
== WXK_ESCAPE
)
2062 (*m_accept
) = FALSE
;
2065 if (!wxPendingDelete
.Member(this))
2066 wxPendingDelete
.Append(this);
2074 void wxListTextCtrl::OnKeyUp( wxKeyEvent
&event
)
2076 // auto-grow the textctrl:
2077 wxSize parentSize
= m_owner
->GetSize();
2078 wxPoint myPos
= GetPosition();
2079 wxSize mySize
= GetSize();
2081 GetTextExtent(GetValue() + _T("MM"), &sx
, &sy
); // FIXME: MM??
2082 if (myPos
.x
+ sx
> parentSize
.x
)
2083 sx
= parentSize
.x
- myPos
.x
;
2091 void wxListTextCtrl::OnKillFocus( wxFocusEvent
&WXUNUSED(event
) )
2093 if (!wxPendingDelete
.Member(this))
2094 wxPendingDelete
.Append(this);
2096 if ((*m_accept
) && ((*m_res
) != m_startValue
))
2097 m_owner
->OnRenameAccept();
2100 //-----------------------------------------------------------------------------
2102 //-----------------------------------------------------------------------------
2104 IMPLEMENT_DYNAMIC_CLASS(wxListMainWindow
,wxScrolledWindow
);
2106 BEGIN_EVENT_TABLE(wxListMainWindow
,wxScrolledWindow
)
2107 EVT_PAINT (wxListMainWindow::OnPaint
)
2108 EVT_MOUSE_EVENTS (wxListMainWindow::OnMouse
)
2109 EVT_CHAR (wxListMainWindow::OnChar
)
2110 EVT_KEY_DOWN (wxListMainWindow::OnKeyDown
)
2111 EVT_SET_FOCUS (wxListMainWindow::OnSetFocus
)
2112 EVT_KILL_FOCUS (wxListMainWindow::OnKillFocus
)
2113 EVT_SCROLLWIN (wxListMainWindow::OnScroll
)
2116 void wxListMainWindow::Init()
2118 m_columns
.DeleteContents( TRUE
);
2122 m_lineTo
= (size_t)-1;
2128 m_small_image_list
= (wxImageList
*) NULL
;
2129 m_normal_image_list
= (wxImageList
*) NULL
;
2131 m_small_spacing
= 30;
2132 m_normal_spacing
= 40;
2136 m_isCreated
= FALSE
;
2138 m_lastOnSame
= FALSE
;
2139 m_renameTimer
= new wxListRenameTimer( this );
2140 m_renameAccept
= FALSE
;
2145 m_lineBeforeLastClicked
= (size_t)-1;
2148 void wxListMainWindow::InitScrolling()
2150 if ( HasFlag(wxLC_REPORT
) )
2152 m_xScroll
= SCROLL_UNIT_X
;
2153 m_yScroll
= SCROLL_UNIT_Y
;
2157 m_xScroll
= SCROLL_UNIT_Y
;
2162 wxListMainWindow::wxListMainWindow()
2166 m_highlightBrush
= (wxBrush
*) NULL
;
2172 wxListMainWindow::wxListMainWindow( wxWindow
*parent
,
2177 const wxString
&name
)
2178 : wxScrolledWindow( parent
, id
, pos
, size
,
2179 style
| wxHSCROLL
| wxVSCROLL
, name
)
2183 m_highlightBrush
= new wxBrush( wxSystemSettings::GetSystemColour(wxSYS_COLOUR_HIGHLIGHT
), wxSOLID
);
2188 SetScrollbars( m_xScroll
, m_yScroll
, 0, 0, 0, 0 );
2190 SetBackgroundColour( wxSystemSettings::GetSystemColour( wxSYS_COLOUR_LISTBOX
) );
2193 wxListMainWindow::~wxListMainWindow()
2197 delete m_highlightBrush
;
2199 delete m_renameTimer
;
2202 void wxListMainWindow::CacheLineData(size_t line
)
2204 wxListCtrl
*listctrl
= GetListCtrl();
2206 wxListLineData
*ld
= GetDummyLine();
2208 size_t countCol
= GetColumnCount();
2209 for ( size_t col
= 0; col
< countCol
; col
++ )
2211 ld
->SetText(col
, listctrl
->OnGetItemText(line
, col
));
2214 ld
->SetImage(listctrl
->OnGetItemImage(line
));
2215 ld
->SetAttr(listctrl
->OnGetItemAttr(line
));
2218 wxListLineData
*wxListMainWindow::GetDummyLine() const
2220 wxASSERT_MSG( !IsEmpty(), _T("invalid line index") );
2222 if ( m_lines
.IsEmpty() )
2224 // normal controls are supposed to have something in m_lines
2225 // already if it's not empty
2226 wxASSERT_MSG( IsVirtual(), _T("logic error") );
2228 wxListMainWindow
*self
= wxConstCast(this, wxListMainWindow
);
2229 wxListLineData
*line
= new wxListLineData(self
);
2230 self
->m_lines
.Add(line
);
2236 // ----------------------------------------------------------------------------
2237 // line geometry (report mode only)
2238 // ----------------------------------------------------------------------------
2240 wxCoord
wxListMainWindow::GetLineHeight() const
2242 wxASSERT_MSG( HasFlag(wxLC_REPORT
), _T("only works in report mode") );
2244 // we cache the line height as calling GetTextExtent() is slow
2245 if ( !m_lineHeight
)
2247 wxListMainWindow
*self
= wxConstCast(this, wxListMainWindow
);
2249 wxClientDC
dc( self
);
2250 dc
.SetFont( GetFont() );
2253 dc
.GetTextExtent(_T("H"), NULL
, &y
);
2255 if ( y
< SCROLL_UNIT_Y
)
2259 self
->m_lineHeight
= y
+ LINE_SPACING
;
2262 return m_lineHeight
;
2265 wxCoord
wxListMainWindow::GetLineY(size_t line
) const
2267 wxASSERT_MSG( HasFlag(wxLC_REPORT
), _T("only works in report mode") );
2269 return LINE_SPACING
+ line
*GetLineHeight();
2272 wxRect
wxListMainWindow::GetLineRect(size_t line
) const
2274 if ( !InReportView() )
2275 return GetLine(line
)->m_gi
->m_rectAll
;
2278 rect
.x
= HEADER_OFFSET_X
;
2279 rect
.y
= GetLineY(line
);
2280 rect
.width
= GetHeaderWidth();
2281 rect
.height
= GetLineHeight();
2286 wxRect
wxListMainWindow::GetLineLabelRect(size_t line
) const
2288 if ( !InReportView() )
2289 return GetLine(line
)->m_gi
->m_rectLabel
;
2292 rect
.x
= HEADER_OFFSET_X
;
2293 rect
.y
= GetLineY(line
);
2294 rect
.width
= GetColumnWidth(0);
2295 rect
.height
= GetLineHeight();
2300 wxRect
wxListMainWindow::GetLineIconRect(size_t line
) const
2302 if ( !InReportView() )
2303 return GetLine(line
)->m_gi
->m_rectIcon
;
2305 wxListLineData
*ld
= GetLine(line
);
2306 wxASSERT_MSG( ld
->HasImage(), _T("should have an image") );
2309 rect
.x
= HEADER_OFFSET_X
;
2310 rect
.y
= GetLineY(line
);
2311 GetImageSize(ld
->GetImage(), rect
.width
, rect
.height
);
2316 wxRect
wxListMainWindow::GetLineHighlightRect(size_t line
) const
2318 return InReportView() ? GetLineRect(line
)
2319 : GetLine(line
)->m_gi
->m_rectHighlight
;
2322 long wxListMainWindow::HitTestLine(size_t line
, int x
, int y
) const
2324 wxListLineData
*ld
= GetLine(line
);
2326 if ( ld
->HasImage() && GetLineIconRect(line
).Inside(x
, y
) )
2327 return wxLIST_HITTEST_ONITEMICON
;
2329 if ( ld
->HasText() )
2331 wxRect rect
= InReportView() ? GetLineRect(line
)
2332 : GetLineLabelRect(line
);
2334 if ( rect
.Inside(x
, y
) )
2335 return wxLIST_HITTEST_ONITEMLABEL
;
2341 // ----------------------------------------------------------------------------
2342 // highlight (selection) handling
2343 // ----------------------------------------------------------------------------
2345 bool wxListMainWindow::IsHighlighted(size_t line
) const
2349 return m_selStore
.IsSelected(line
);
2353 wxListLineData
*ld
= GetLine(line
);
2354 wxCHECK_MSG( ld
, FALSE
, _T("invalid index in IsHighlighted") );
2356 return ld
->IsHighlighted();
2360 void wxListMainWindow::HighlightLines( size_t lineFrom
,
2366 wxArrayInt linesChanged
;
2367 if ( !m_selStore
.SelectRange(lineFrom
, lineTo
, highlight
,
2370 // meny items changed state, refresh everything
2371 RefreshLines(lineFrom
, lineTo
);
2373 else // only a few items changed state, refresh only them
2375 size_t count
= linesChanged
.GetCount();
2376 for ( size_t n
= 0; n
< count
; n
++ )
2378 RefreshLine(linesChanged
[n
]);
2382 else // iterate over all items in non report view
2384 for ( size_t line
= lineFrom
; line
<= lineTo
; line
++ )
2386 if ( HighlightLine(line
, highlight
) )
2394 bool wxListMainWindow::HighlightLine( size_t line
, bool highlight
)
2400 changed
= m_selStore
.SelectItem(line
, highlight
);
2404 wxListLineData
*ld
= GetLine(line
);
2405 wxCHECK_MSG( ld
, FALSE
, _T("invalid index in IsHighlighted") );
2407 changed
= ld
->Highlight(highlight
);
2412 SendNotify( line
, highlight
? wxEVT_COMMAND_LIST_ITEM_SELECTED
2413 : wxEVT_COMMAND_LIST_ITEM_DESELECTED
);
2419 void wxListMainWindow::RefreshLine( size_t line
)
2421 if ( HasFlag(wxLC_REPORT
) )
2423 size_t visibleFrom
, visibleTo
;
2424 GetVisibleLinesRange(&visibleFrom
, &visibleTo
);
2426 if ( line
< visibleFrom
|| line
> visibleTo
)
2430 wxRect rect
= GetLineRect(line
);
2432 CalcScrolledPosition( rect
.x
, rect
.y
, &rect
.x
, &rect
.y
);
2433 RefreshRect( rect
);
2436 void wxListMainWindow::RefreshLines( size_t lineFrom
, size_t lineTo
)
2438 // we suppose that they are ordered by caller
2439 wxASSERT_MSG( lineFrom
<= lineTo
, _T("indices in disorder") );
2441 wxASSERT_MSG( lineTo
< GetItemCount(), _T("invalid line range") );
2443 if ( HasFlag(wxLC_REPORT
) )
2445 size_t visibleFrom
, visibleTo
;
2446 GetVisibleLinesRange(&visibleFrom
, &visibleTo
);
2448 if ( lineFrom
< visibleFrom
)
2449 lineFrom
= visibleFrom
;
2450 if ( lineTo
> visibleTo
)
2455 rect
.y
= GetLineY(lineFrom
);
2456 rect
.width
= GetClientSize().x
;
2457 rect
.height
= GetLineY(lineTo
) - rect
.y
+ GetLineHeight();
2459 CalcScrolledPosition( rect
.x
, rect
.y
, &rect
.x
, &rect
.y
);
2460 RefreshRect( rect
);
2464 // TODO: this should be optimized...
2465 for ( size_t line
= lineFrom
; line
<= lineTo
; line
++ )
2472 void wxListMainWindow::RefreshAfter( size_t lineFrom
)
2474 if ( HasFlag(wxLC_REPORT
) )
2477 GetVisibleLinesRange(&visibleFrom
, NULL
);
2479 if ( lineFrom
< visibleFrom
)
2480 lineFrom
= visibleFrom
;
2484 rect
.y
= GetLineY(lineFrom
);
2486 wxSize size
= GetClientSize();
2487 rect
.width
= size
.x
;
2488 // refresh till the bottom of the window
2489 rect
.height
= size
.y
- rect
.y
;
2491 CalcScrolledPosition( rect
.x
, rect
.y
, &rect
.x
, &rect
.y
);
2492 RefreshRect( rect
);
2496 // TODO: how to do it more efficiently?
2501 void wxListMainWindow::OnPaint( wxPaintEvent
&WXUNUSED(event
) )
2503 // Note: a wxPaintDC must be constructed even if no drawing is
2504 // done (a Windows requirement).
2505 wxPaintDC
dc( this );
2509 // empty control. nothing to draw
2515 // delay the repainting until we calculate all the items positions
2522 CalcScrolledPosition( 0, 0, &dev_x
, &dev_y
);
2526 dc
.SetFont( GetFont() );
2528 if ( HasFlag(wxLC_REPORT
) )
2530 int lineHeight
= GetLineHeight();
2532 size_t visibleFrom
, visibleTo
;
2533 GetVisibleLinesRange(&visibleFrom
, &visibleTo
);
2536 wxCoord xOrig
, yOrig
;
2537 CalcUnscrolledPosition(0, 0, &xOrig
, &yOrig
);
2539 // tell the caller cache to cache the data
2542 wxListEvent
evCache(wxEVT_COMMAND_LIST_CACHE_HINT
,
2543 GetParent()->GetId());
2544 evCache
.SetEventObject( GetParent() );
2545 evCache
.m_oldItemIndex
= visibleFrom
;
2546 evCache
.m_itemIndex
= visibleTo
;
2547 GetParent()->GetEventHandler()->ProcessEvent( evCache
);
2550 for ( size_t line
= visibleFrom
; line
<= visibleTo
; line
++ )
2552 rectLine
= GetLineRect(line
);
2554 if ( !IsExposed(rectLine
.x
- xOrig
, rectLine
.y
- yOrig
,
2555 rectLine
.width
, rectLine
.height
) )
2557 // don't redraw unaffected lines to avoid flicker
2561 GetLine(line
)->DrawInReportMode( &dc
,
2563 GetLineHighlightRect(line
),
2564 m_hasFocus
&& IsHighlighted(line
) );
2567 if ( HasFlag(wxLC_HRULES
) )
2569 wxPen
pen(GetRuleColour(), 1, wxSOLID
);
2570 wxSize clientSize
= GetClientSize();
2572 for ( size_t i
= visibleFrom
; i
<= visibleTo
; i
++ )
2575 dc
.SetBrush( *wxTRANSPARENT_BRUSH
);
2576 dc
.DrawLine(0 - dev_x
, i
*lineHeight
,
2577 clientSize
.x
- dev_x
, i
*lineHeight
);
2580 // Draw last horizontal rule
2581 if ( visibleTo
> visibleFrom
)
2584 dc
.SetBrush( *wxTRANSPARENT_BRUSH
);
2585 dc
.DrawLine(0 - dev_x
, m_lineTo
*lineHeight
,
2586 clientSize
.x
- dev_x
, m_lineTo
*lineHeight
);
2590 // Draw vertical rules if required
2591 if ( HasFlag(wxLC_VRULES
) && !IsEmpty() )
2593 wxPen
pen(GetRuleColour(), 1, wxSOLID
);
2596 wxRect firstItemRect
;
2597 wxRect lastItemRect
;
2598 GetItemRect(0, firstItemRect
);
2599 GetItemRect(GetItemCount() - 1, lastItemRect
);
2600 int x
= firstItemRect
.GetX();
2602 dc
.SetBrush(* wxTRANSPARENT_BRUSH
);
2603 for (col
= 0; col
< GetColumnCount(); col
++)
2605 int colWidth
= GetColumnWidth(col
);
2607 dc
.DrawLine(x
- dev_x
, firstItemRect
.GetY() - 1 - dev_y
,
2608 x
- dev_x
, lastItemRect
.GetBottom() + 1 - dev_y
);
2614 size_t count
= GetItemCount();
2615 for ( size_t i
= 0; i
< count
; i
++ )
2617 GetLine(i
)->Draw( &dc
);
2623 // don't draw rect outline under Max if we already have the background
2627 #endif // !__WXMAC__
2629 dc
.SetPen( *wxBLACK_PEN
);
2630 dc
.SetBrush( *wxTRANSPARENT_BRUSH
);
2631 dc
.DrawRectangle( GetLineHighlightRect(m_current
) );
2638 void wxListMainWindow::HighlightAll( bool on
)
2640 if ( IsSingleSel() )
2642 wxASSERT_MSG( !on
, _T("can't do this in a single sel control") );
2644 // we just have one item to turn off
2645 if ( HasCurrent() && IsHighlighted(m_current
) )
2647 HighlightLine(m_current
, FALSE
);
2648 RefreshLine(m_current
);
2653 HighlightLines(0, GetItemCount() - 1, on
);
2657 void wxListMainWindow::SendNotify( size_t line
,
2658 wxEventType command
,
2661 wxListEvent
le( command
, GetParent()->GetId() );
2662 le
.SetEventObject( GetParent() );
2663 le
.m_itemIndex
= line
;
2665 // set only for events which have position
2666 if ( point
!= wxDefaultPosition
)
2667 le
.m_pointDrag
= point
;
2669 // don't try to get the line info for virtual list controls: the main
2670 // program has it anyhow and if we did it would result in accessing all
2671 // the lines, even those which are not visible now and this is precisely
2672 // what we're trying to avoid
2673 if ( !IsVirtual() && (command
!= wxEVT_COMMAND_LIST_DELETE_ITEM
) )
2675 GetLine(line
)->GetItem( 0, le
.m_item
);
2677 //else: there may be no more such item
2679 GetParent()->GetEventHandler()->ProcessEvent( le
);
2682 void wxListMainWindow::OnFocusLine( size_t WXUNUSED(line
) )
2684 // SendNotify( line, wxEVT_COMMAND_LIST_ITEM_FOCUSSED );
2687 void wxListMainWindow::OnUnfocusLine( size_t WXUNUSED(line
) )
2689 // SendNotify( line, wxEVT_COMMAND_LIST_ITEM_UNFOCUSSED );
2692 void wxListMainWindow::EditLabel( long item
)
2694 wxCHECK_RET( (item
>= 0) && ((size_t)item
< GetItemCount()),
2695 wxT("wrong index in wxListCtrl::EditLabel()") );
2697 m_currentEdit
= (size_t)item
;
2699 wxListEvent
le( wxEVT_COMMAND_LIST_BEGIN_LABEL_EDIT
, GetParent()->GetId() );
2700 le
.SetEventObject( GetParent() );
2701 le
.m_itemIndex
= item
;
2702 wxListLineData
*data
= GetLine(m_currentEdit
);
2703 wxCHECK_RET( data
, _T("invalid index in EditLabel()") );
2704 data
->GetItem( 0, le
.m_item
);
2705 GetParent()->GetEventHandler()->ProcessEvent( le
);
2707 if (!le
.IsAllowed())
2710 // We have to call this here because the label in question might just have
2711 // been added and no screen update taken place.
2715 wxClientDC
dc(this);
2718 wxString s
= data
->GetText(0);
2719 wxRect rectLabel
= GetLineLabelRect(m_currentEdit
);
2721 rectLabel
.x
= dc
.LogicalToDeviceX( rectLabel
.x
);
2722 rectLabel
.y
= dc
.LogicalToDeviceY( rectLabel
.y
);
2724 wxListTextCtrl
*text
= new wxListTextCtrl
2731 wxPoint(rectLabel
.x
-4,rectLabel
.y
-4),
2732 wxSize(rectLabel
.width
+11,rectLabel
.height
+8)
2737 void wxListMainWindow::OnRenameTimer()
2739 wxCHECK_RET( HasCurrent(), wxT("unexpected rename timer") );
2741 EditLabel( m_current
);
2744 void wxListMainWindow::OnRenameAccept()
2746 wxListEvent
le( wxEVT_COMMAND_LIST_END_LABEL_EDIT
, GetParent()->GetId() );
2747 le
.SetEventObject( GetParent() );
2748 le
.m_itemIndex
= m_currentEdit
;
2750 wxListLineData
*data
= GetLine(m_currentEdit
);
2751 wxCHECK_RET( data
, _T("invalid index in OnRenameAccept()") );
2753 data
->GetItem( 0, le
.m_item
);
2754 le
.m_item
.m_text
= m_renameRes
;
2755 GetParent()->GetEventHandler()->ProcessEvent( le
);
2757 if (!le
.IsAllowed()) return;
2760 info
.m_mask
= wxLIST_MASK_TEXT
;
2761 info
.m_itemId
= le
.m_itemIndex
;
2762 info
.m_text
= m_renameRes
;
2763 info
.SetTextColour(le
.m_item
.GetTextColour());
2767 void wxListMainWindow::OnMouse( wxMouseEvent
&event
)
2769 event
.SetEventObject( GetParent() );
2770 if ( GetParent()->GetEventHandler()->ProcessEvent( event
) )
2773 if ( !HasCurrent() || IsEmpty() )
2779 if ( !(event
.Dragging() || event
.ButtonDown() || event
.LeftUp() ||
2780 event
.ButtonDClick()) )
2783 int x
= event
.GetX();
2784 int y
= event
.GetY();
2785 CalcUnscrolledPosition( x
, y
, &x
, &y
);
2787 // where did we hit it (if we did)?
2790 size_t count
= GetItemCount(),
2793 if ( HasFlag(wxLC_REPORT
) )
2795 current
= y
/ GetLineHeight();
2796 if ( current
< count
)
2797 hitResult
= HitTestLine(current
, x
, y
);
2801 // TODO: optimize it too! this is less simple than for report view but
2802 // enumerating all items is still not a way to do it!!
2803 for ( current
= 0; current
< count
; current
++ )
2805 hitResult
= HitTestLine(current
, x
, y
);
2811 if (event
.Dragging())
2813 if (m_dragCount
== 0)
2814 m_dragStart
= wxPoint(x
,y
);
2818 if (m_dragCount
!= 3)
2821 int command
= event
.RightIsDown() ? wxEVT_COMMAND_LIST_BEGIN_RDRAG
2822 : wxEVT_COMMAND_LIST_BEGIN_DRAG
;
2824 wxListEvent
le( command
, GetParent()->GetId() );
2825 le
.SetEventObject( GetParent() );
2826 le
.m_pointDrag
= m_dragStart
;
2827 GetParent()->GetEventHandler()->ProcessEvent( le
);
2838 // outside of any item
2842 bool forceClick
= FALSE
;
2843 if (event
.ButtonDClick())
2845 m_renameTimer
->Stop();
2846 m_lastOnSame
= FALSE
;
2848 if ( current
== m_lineBeforeLastClicked
)
2850 SendNotify( current
, wxEVT_COMMAND_LIST_ITEM_ACTIVATED
);
2856 // the first click was on another item, so don't interpret this as
2857 // a double click, but as a simple click instead
2862 if (event
.LeftUp() && m_lastOnSame
)
2864 if ((current
== m_current
) &&
2865 (hitResult
== wxLIST_HITTEST_ONITEMLABEL
) &&
2866 HasFlag(wxLC_EDIT_LABELS
) )
2868 m_renameTimer
->Start( 100, TRUE
);
2870 m_lastOnSame
= FALSE
;
2872 else if (event
.RightDown())
2874 SendNotify( current
, wxEVT_COMMAND_LIST_ITEM_RIGHT_CLICK
,
2875 event
.GetPosition() );
2877 else if (event
.MiddleDown())
2879 SendNotify( current
, wxEVT_COMMAND_LIST_ITEM_MIDDLE_CLICK
);
2881 else if ( event
.LeftDown() || forceClick
)
2883 m_lineBeforeLastClicked
= m_lineLastClicked
;
2884 m_lineLastClicked
= current
;
2886 size_t oldCurrent
= m_current
;
2888 if ( IsSingleSel() || !(event
.ControlDown() || event
.ShiftDown()) )
2890 HighlightAll( FALSE
);
2891 m_current
= current
;
2893 ReverseHighlight(m_current
);
2895 else // multi sel & either ctrl or shift is down
2897 if (event
.ControlDown())
2899 m_current
= current
;
2901 ReverseHighlight(m_current
);
2903 else if (event
.ShiftDown())
2905 m_current
= current
;
2907 size_t lineFrom
= oldCurrent
,
2910 if ( lineTo
< lineFrom
)
2913 lineFrom
= m_current
;
2916 HighlightLines(lineFrom
, lineTo
);
2918 else // !ctrl, !shift
2920 // test in the enclosing if should make it impossible
2921 wxFAIL_MSG( _T("how did we get here?") );
2925 if (m_current
!= oldCurrent
)
2927 RefreshLine( oldCurrent
);
2928 OnUnfocusLine( oldCurrent
);
2929 OnFocusLine( m_current
);
2932 // forceClick is only set if the previous click was on another item
2933 m_lastOnSame
= !forceClick
&& (m_current
== oldCurrent
);
2937 void wxListMainWindow::MoveToItem(size_t item
)
2939 if ( item
== (size_t)-1 )
2942 wxRect rect
= GetLineRect(item
);
2944 int client_w
, client_h
;
2945 GetClientSize( &client_w
, &client_h
);
2947 int view_x
= m_xScroll
*GetScrollPos( wxHORIZONTAL
);
2948 int view_y
= m_yScroll
*GetScrollPos( wxVERTICAL
);
2950 if ( HasFlag(wxLC_REPORT
) )
2952 // the next we need the range of lines shown it might be different, so
2954 ResetVisibleLinesRange();
2956 if (rect
.y
< view_y
)
2957 Scroll( -1, rect
.y
/m_yScroll
);
2958 if (rect
.y
+rect
.height
+5 > view_y
+client_h
)
2959 Scroll( -1, (rect
.y
+rect
.height
-client_h
+SCROLL_UNIT_Y
)/m_yScroll
);
2963 if (rect
.x
-view_x
< 5)
2964 Scroll( (rect
.x
-5)/m_xScroll
, -1 );
2965 if (rect
.x
+rect
.width
-5 > view_x
+client_w
)
2966 Scroll( (rect
.x
+rect
.width
-client_w
+SCROLL_UNIT_X
)/m_xScroll
, -1 );
2970 // ----------------------------------------------------------------------------
2971 // keyboard handling
2972 // ----------------------------------------------------------------------------
2974 void wxListMainWindow::OnArrowChar(size_t newCurrent
, const wxKeyEvent
& event
)
2976 wxCHECK_RET( newCurrent
< (size_t)GetItemCount(),
2977 _T("invalid item index in OnArrowChar()") );
2979 size_t oldCurrent
= m_current
;
2981 // in single selection we just ignore Shift as we can't select several
2983 if ( event
.ShiftDown() && !IsSingleSel() )
2985 m_current
= newCurrent
;
2987 // select all the items between the old and the new one
2988 if ( oldCurrent
> newCurrent
)
2990 newCurrent
= oldCurrent
;
2991 oldCurrent
= m_current
;
2994 HighlightLines(oldCurrent
, newCurrent
);
2998 // all previously selected items are unselected unless ctrl is held
2999 if ( !event
.ControlDown() )
3000 HighlightAll(FALSE
);
3002 m_current
= newCurrent
;
3004 HighlightLine( oldCurrent
, FALSE
);
3005 RefreshLine( oldCurrent
);
3007 if ( !event
.ControlDown() )
3009 HighlightLine( m_current
, TRUE
);
3013 OnUnfocusLine( oldCurrent
);
3014 OnFocusLine( m_current
);
3015 RefreshLine( m_current
);
3020 void wxListMainWindow::OnKeyDown( wxKeyEvent
&event
)
3022 wxWindow
*parent
= GetParent();
3024 /* we propagate the key event up */
3025 wxKeyEvent
ke( wxEVT_KEY_DOWN
);
3026 ke
.m_shiftDown
= event
.m_shiftDown
;
3027 ke
.m_controlDown
= event
.m_controlDown
;
3028 ke
.m_altDown
= event
.m_altDown
;
3029 ke
.m_metaDown
= event
.m_metaDown
;
3030 ke
.m_keyCode
= event
.m_keyCode
;
3033 ke
.SetEventObject( parent
);
3034 if (parent
->GetEventHandler()->ProcessEvent( ke
)) return;
3039 void wxListMainWindow::OnChar( wxKeyEvent
&event
)
3041 wxWindow
*parent
= GetParent();
3043 /* we send a list_key event up */
3046 wxListEvent
le( wxEVT_COMMAND_LIST_KEY_DOWN
, GetParent()->GetId() );
3047 le
.m_itemIndex
= m_current
;
3048 GetLine(m_current
)->GetItem( 0, le
.m_item
);
3049 le
.m_code
= (int)event
.KeyCode();
3050 le
.SetEventObject( parent
);
3051 parent
->GetEventHandler()->ProcessEvent( le
);
3054 /* we propagate the char event up */
3055 wxKeyEvent
ke( wxEVT_CHAR
);
3056 ke
.m_shiftDown
= event
.m_shiftDown
;
3057 ke
.m_controlDown
= event
.m_controlDown
;
3058 ke
.m_altDown
= event
.m_altDown
;
3059 ke
.m_metaDown
= event
.m_metaDown
;
3060 ke
.m_keyCode
= event
.m_keyCode
;
3063 ke
.SetEventObject( parent
);
3064 if (parent
->GetEventHandler()->ProcessEvent( ke
)) return;
3066 if (event
.KeyCode() == WXK_TAB
)
3068 wxNavigationKeyEvent nevent
;
3069 nevent
.SetWindowChange( event
.ControlDown() );
3070 nevent
.SetDirection( !event
.ShiftDown() );
3071 nevent
.SetEventObject( GetParent()->GetParent() );
3072 nevent
.SetCurrentFocus( m_parent
);
3073 if (GetParent()->GetParent()->GetEventHandler()->ProcessEvent( nevent
)) return;
3076 /* no item -> nothing to do */
3083 switch (event
.KeyCode())
3086 if ( m_current
> 0 )
3087 OnArrowChar( m_current
- 1, event
);
3091 if ( m_current
< (size_t)GetItemCount() - 1 )
3092 OnArrowChar( m_current
+ 1, event
);
3097 OnArrowChar( GetItemCount() - 1, event
);
3102 OnArrowChar( 0, event
);
3108 if ( HasFlag(wxLC_REPORT
) )
3110 steps
= m_linesPerPage
- 1;
3114 steps
= m_current
% m_linesPerPage
;
3117 int index
= m_current
- steps
;
3121 OnArrowChar( index
, event
);
3128 if ( HasFlag(wxLC_REPORT
) )
3130 steps
= m_linesPerPage
- 1;
3134 steps
= m_linesPerPage
- (m_current
% m_linesPerPage
) - 1;
3137 size_t index
= m_current
+ steps
;
3138 size_t count
= GetItemCount();
3139 if ( index
>= count
)
3142 OnArrowChar( index
, event
);
3147 if ( !HasFlag(wxLC_REPORT
) )
3149 int index
= m_current
- m_linesPerPage
;
3153 OnArrowChar( index
, event
);
3158 if ( !HasFlag(wxLC_REPORT
) )
3160 size_t index
= m_current
+ m_linesPerPage
;
3162 size_t count
= GetItemCount();
3163 if ( index
>= count
)
3166 OnArrowChar( index
, event
);
3171 if ( IsSingleSel() )
3173 wxListEvent
le( wxEVT_COMMAND_LIST_ITEM_ACTIVATED
,
3174 GetParent()->GetId() );
3175 le
.SetEventObject( GetParent() );
3176 le
.m_itemIndex
= m_current
;
3177 GetLine(m_current
)->GetItem( 0, le
.m_item
);
3178 GetParent()->GetEventHandler()->ProcessEvent( le
);
3180 if ( IsHighlighted(m_current
) )
3182 // don't unselect the item in single selection mode
3185 //else: select it in ReverseHighlight() below if unselected
3188 ReverseHighlight(m_current
);
3194 wxListEvent
le( wxEVT_COMMAND_LIST_ITEM_ACTIVATED
,
3195 GetParent()->GetId() );
3196 le
.SetEventObject( GetParent() );
3197 le
.m_itemIndex
= m_current
;
3198 GetLine(m_current
)->GetItem( 0, le
.m_item
);
3199 GetParent()->GetEventHandler()->ProcessEvent( le
);
3208 // ----------------------------------------------------------------------------
3210 // ----------------------------------------------------------------------------
3213 extern wxWindow
*g_focusWindow
;
3216 void wxListMainWindow::OnSetFocus( wxFocusEvent
&WXUNUSED(event
) )
3221 RefreshLine( m_current
);
3227 g_focusWindow
= GetParent();
3230 wxFocusEvent
event( wxEVT_SET_FOCUS
, GetParent()->GetId() );
3231 event
.SetEventObject( GetParent() );
3232 GetParent()->GetEventHandler()->ProcessEvent( event
);
3235 void wxListMainWindow::OnKillFocus( wxFocusEvent
&WXUNUSED(event
) )
3240 RefreshLine( m_current
);
3243 void wxListMainWindow::DrawImage( int index
, wxDC
*dc
, int x
, int y
)
3245 if ( HasFlag(wxLC_ICON
) && (m_normal_image_list
))
3247 m_normal_image_list
->Draw( index
, *dc
, x
, y
, wxIMAGELIST_DRAW_TRANSPARENT
);
3249 else if ( HasFlag(wxLC_SMALL_ICON
) && (m_small_image_list
))
3251 m_small_image_list
->Draw( index
, *dc
, x
, y
, wxIMAGELIST_DRAW_TRANSPARENT
);
3253 else if ( HasFlag(wxLC_LIST
) && (m_small_image_list
))
3255 m_small_image_list
->Draw( index
, *dc
, x
, y
, wxIMAGELIST_DRAW_TRANSPARENT
);
3257 else if ( HasFlag(wxLC_REPORT
) && (m_small_image_list
))
3259 m_small_image_list
->Draw( index
, *dc
, x
, y
, wxIMAGELIST_DRAW_TRANSPARENT
);
3263 void wxListMainWindow::GetImageSize( int index
, int &width
, int &height
) const
3265 if ( HasFlag(wxLC_ICON
) && m_normal_image_list
)
3267 m_normal_image_list
->GetSize( index
, width
, height
);
3269 else if ( HasFlag(wxLC_SMALL_ICON
) && m_small_image_list
)
3271 m_small_image_list
->GetSize( index
, width
, height
);
3273 else if ( HasFlag(wxLC_LIST
) && m_small_image_list
)
3275 m_small_image_list
->GetSize( index
, width
, height
);
3277 else if ( HasFlag(wxLC_REPORT
) && m_small_image_list
)
3279 m_small_image_list
->GetSize( index
, width
, height
);
3288 int wxListMainWindow::GetTextLength( const wxString
&s
) const
3290 wxClientDC
dc( wxConstCast(this, wxListMainWindow
) );
3291 dc
.SetFont( GetFont() );
3294 dc
.GetTextExtent( s
, &lw
, NULL
);
3296 return lw
+ AUTOSIZE_COL_MARGIN
;
3299 void wxListMainWindow::SetImageList( wxImageList
*imageList
, int which
)
3303 // calc the spacing from the icon size
3306 if ((imageList
) && (imageList
->GetImageCount()) )
3308 imageList
->GetSize(0, width
, height
);
3311 if (which
== wxIMAGE_LIST_NORMAL
)
3313 m_normal_image_list
= imageList
;
3314 m_normal_spacing
= width
+ 8;
3317 if (which
== wxIMAGE_LIST_SMALL
)
3319 m_small_image_list
= imageList
;
3320 m_small_spacing
= width
+ 14;
3324 void wxListMainWindow::SetItemSpacing( int spacing
, bool isSmall
)
3329 m_small_spacing
= spacing
;
3333 m_normal_spacing
= spacing
;
3337 int wxListMainWindow::GetItemSpacing( bool isSmall
)
3339 return isSmall
? m_small_spacing
: m_normal_spacing
;
3342 // ----------------------------------------------------------------------------
3344 // ----------------------------------------------------------------------------
3346 void wxListMainWindow::SetColumn( int col
, wxListItem
&item
)
3348 wxListHeaderDataList::Node
*node
= m_columns
.Item( col
);
3350 wxCHECK_RET( node
, _T("invalid column index in SetColumn") );
3352 if ( item
.m_width
== wxLIST_AUTOSIZE_USEHEADER
)
3353 item
.m_width
= GetTextLength( item
.m_text
);
3355 wxListHeaderData
*column
= node
->GetData();
3356 column
->SetItem( item
);
3358 wxListHeaderWindow
*headerWin
= GetListCtrl()->m_headerWin
;
3360 headerWin
->m_dirty
= TRUE
;
3364 // invalidate it as it has to be recalculated
3368 void wxListMainWindow::SetColumnWidth( int col
, int width
)
3370 wxCHECK_RET( col
>= 0 && col
< GetColumnCount(),
3371 _T("invalid column index") );
3373 wxCHECK_RET( HasFlag(wxLC_REPORT
),
3374 _T("SetColumnWidth() can only be called in report mode.") );
3378 wxListHeaderDataList::Node
*node
= m_columns
.Item( col
);
3379 wxCHECK_RET( node
, _T("no column?") );
3381 wxListHeaderData
*column
= node
->GetData();
3383 size_t count
= GetItemCount();
3385 if (width
== wxLIST_AUTOSIZE_USEHEADER
)
3387 width
= GetTextLength(column
->GetText());
3389 else if ( width
== wxLIST_AUTOSIZE
)
3393 // TODO: determine the max width somehow...
3394 width
= WIDTH_COL_DEFAULT
;
3398 wxClientDC
dc(this);
3399 dc
.SetFont( GetFont() );
3401 int max
= AUTOSIZE_COL_MARGIN
;
3403 for ( size_t i
= 0; i
< count
; i
++ )
3405 wxListLineData
*line
= GetLine(i
);
3406 wxListItemDataList::Node
*n
= line
->m_items
.Item( col
);
3408 wxCHECK_RET( n
, _T("no subitem?") );
3410 wxListItemData
*item
= n
->GetData();
3413 if (item
->HasImage())
3416 GetImageSize( item
->GetImage(), ix
, iy
);
3420 if (item
->HasText())
3423 dc
.GetTextExtent( item
->GetText(), &w
, NULL
);
3431 width
= max
+ AUTOSIZE_COL_MARGIN
;
3435 column
->SetWidth( width
);
3437 // invalidate it as it has to be recalculated
3441 int wxListMainWindow::GetHeaderWidth() const
3443 if ( !m_headerWidth
)
3445 wxListMainWindow
*self
= wxConstCast(this, wxListMainWindow
);
3447 size_t count
= GetColumnCount();
3448 for ( size_t col
= 0; col
< count
; col
++ )
3450 self
->m_headerWidth
+= GetColumnWidth(col
);
3454 return m_headerWidth
;
3457 void wxListMainWindow::GetColumn( int col
, wxListItem
&item
) const
3459 wxListHeaderDataList::Node
*node
= m_columns
.Item( col
);
3460 wxCHECK_RET( node
, _T("invalid column index in GetColumn") );
3462 wxListHeaderData
*column
= node
->GetData();
3463 column
->GetItem( item
);
3466 int wxListMainWindow::GetColumnWidth( int col
) const
3468 wxListHeaderDataList::Node
*node
= m_columns
.Item( col
);
3469 wxCHECK_MSG( node
, 0, _T("invalid column index") );
3471 wxListHeaderData
*column
= node
->GetData();
3472 return column
->GetWidth();
3475 // ----------------------------------------------------------------------------
3477 // ----------------------------------------------------------------------------
3479 void wxListMainWindow::SetItem( wxListItem
&item
)
3481 long id
= item
.m_itemId
;
3482 wxCHECK_RET( id
>= 0 && (size_t)id
< GetItemCount(),
3483 _T("invalid item index in SetItem") );
3487 wxListLineData
*line
= GetLine((size_t)id
);
3488 line
->SetItem( item
.m_col
, item
);
3491 if ( InReportView() )
3493 // just refresh the line to show the new value of the text/image
3494 RefreshLine((size_t)id
);
3498 // refresh everything (resulting in horrible flicker - FIXME!)
3503 void wxListMainWindow::SetItemState( long litem
, long state
, long stateMask
)
3505 wxCHECK_RET( litem
>= 0 && (size_t)litem
< GetItemCount(),
3506 _T("invalid list ctrl item index in SetItem") );
3508 size_t oldCurrent
= m_current
;
3509 size_t item
= (size_t)litem
; // safe because of the check above
3511 // do we need to change the focus?
3512 if ( stateMask
& wxLIST_STATE_FOCUSED
)
3514 if ( state
& wxLIST_STATE_FOCUSED
)
3516 // don't do anything if this item is already focused
3517 if ( item
!= m_current
)
3519 OnUnfocusLine( m_current
);
3521 OnFocusLine( m_current
);
3523 if ( oldCurrent
!= (size_t)-1 )
3525 if ( IsSingleSel() )
3527 HighlightLine(oldCurrent
, FALSE
);
3530 RefreshLine(oldCurrent
);
3533 RefreshLine( m_current
);
3538 // don't do anything if this item is not focused
3539 if ( item
== m_current
)
3541 OnUnfocusLine( m_current
);
3542 m_current
= (size_t)-1;
3544 RefreshLine( oldCurrent
);
3549 // do we need to change the selection state?
3550 if ( stateMask
& wxLIST_STATE_SELECTED
)
3552 bool on
= (state
& wxLIST_STATE_SELECTED
) != 0;
3554 if ( IsSingleSel() )
3558 // selecting the item also makes it the focused one in the
3560 if ( m_current
!= item
)
3562 OnUnfocusLine( m_current
);
3564 OnFocusLine( m_current
);
3566 if ( oldCurrent
!= (size_t)-1 )
3568 HighlightLine( oldCurrent
, FALSE
);
3569 RefreshLine( oldCurrent
);
3575 // only the current item may be selected anyhow
3576 if ( item
!= m_current
)
3581 if ( HighlightLine(item
, on
) )
3588 int wxListMainWindow::GetItemState( long item
, long stateMask
)
3590 wxCHECK_MSG( item
>= 0 && (size_t)item
< GetItemCount(), 0,
3591 _T("invalid list ctrl item index in GetItemState()") );
3593 int ret
= wxLIST_STATE_DONTCARE
;
3595 if ( stateMask
& wxLIST_STATE_FOCUSED
)
3597 if ( (size_t)item
== m_current
)
3598 ret
|= wxLIST_STATE_FOCUSED
;
3601 if ( stateMask
& wxLIST_STATE_SELECTED
)
3603 if ( IsHighlighted(item
) )
3604 ret
|= wxLIST_STATE_SELECTED
;
3610 void wxListMainWindow::GetItem( wxListItem
&item
)
3612 wxCHECK_RET( item
.m_itemId
>= 0 && (size_t)item
.m_itemId
< GetItemCount(),
3613 _T("invalid item index in GetItem") );
3615 wxListLineData
*line
= GetLine((size_t)item
.m_itemId
);
3616 line
->GetItem( item
.m_col
, item
);
3619 // ----------------------------------------------------------------------------
3621 // ----------------------------------------------------------------------------
3623 size_t wxListMainWindow::GetItemCount() const
3625 return IsVirtual() ? m_countVirt
: m_lines
.GetCount();
3628 void wxListMainWindow::SetItemCount(long count
)
3630 m_selStore
.SetItemCount(count
);
3631 m_countVirt
= count
;
3633 ResetVisibleLinesRange();
3635 // scrollbars must be reset
3639 int wxListMainWindow::GetSelectedItemCount()
3641 // deal with the quick case first
3642 if ( IsSingleSel() )
3644 return HasCurrent() ? IsHighlighted(m_current
) : FALSE
;
3647 // virtual controls remmebers all its selections itself
3649 return m_selStore
.GetSelectedCount();
3651 // TODO: we probably should maintain the number of items selected even for
3652 // non virtual controls as enumerating all lines is really slow...
3653 size_t countSel
= 0;
3654 size_t count
= GetItemCount();
3655 for ( size_t line
= 0; line
< count
; line
++ )
3657 if ( GetLine(line
)->IsHighlighted() )
3664 // ----------------------------------------------------------------------------
3665 // item position/size
3666 // ----------------------------------------------------------------------------
3668 void wxListMainWindow::GetItemRect( long index
, wxRect
&rect
)
3670 wxCHECK_RET( index
>= 0 && (size_t)index
< GetItemCount(),
3671 _T("invalid index in GetItemRect") );
3673 rect
= GetLineRect((size_t)index
);
3675 CalcScrolledPosition(rect
.x
, rect
.y
, &rect
.x
, &rect
.y
);
3678 bool wxListMainWindow::GetItemPosition(long item
, wxPoint
& pos
)
3681 GetItemRect(item
, rect
);
3689 // ----------------------------------------------------------------------------
3690 // geometry calculation
3691 // ----------------------------------------------------------------------------
3693 void wxListMainWindow::RecalculatePositions(bool noRefresh
)
3695 wxClientDC
dc( this );
3696 dc
.SetFont( GetFont() );
3699 if ( HasFlag(wxLC_ICON
) )
3700 iconSpacing
= m_normal_spacing
;
3701 else if ( HasFlag(wxLC_SMALL_ICON
) )
3702 iconSpacing
= m_small_spacing
;
3708 GetClientSize( &clientWidth
, &clientHeight
);
3710 if ( HasFlag(wxLC_REPORT
) )
3712 // all lines have the same height
3713 int lineHeight
= GetLineHeight();
3715 // scroll one line per step
3716 m_yScroll
= lineHeight
;
3718 size_t lineCount
= GetItemCount();
3719 int entireHeight
= lineCount
*lineHeight
+ LINE_SPACING
;
3721 m_linesPerPage
= clientHeight
/ lineHeight
;
3723 ResetVisibleLinesRange();
3725 SetScrollbars( m_xScroll
, m_yScroll
,
3726 (GetHeaderWidth() + m_xScroll
- 1)/m_xScroll
,
3727 (entireHeight
+ m_yScroll
- 1)/m_yScroll
,
3728 GetScrollPos(wxHORIZONTAL
),
3729 GetScrollPos(wxVERTICAL
),
3734 // at first we try without any scrollbar. if the items don't
3735 // fit into the window, we recalculate after subtracting an
3736 // approximated 15 pt for the horizontal scrollbar
3738 clientHeight
-= 4; // sunken frame
3740 int entireWidth
= 0;
3742 for (int tries
= 0; tries
< 2; tries
++)
3749 int currentlyVisibleLines
= 0;
3751 size_t count
= GetItemCount();
3752 for (size_t i
= 0; i
< count
; i
++)
3754 currentlyVisibleLines
++;
3755 wxListLineData
*line
= GetLine(i
);
3756 line
->CalculateSize( &dc
, iconSpacing
);
3757 line
->SetPosition( x
, y
, clientWidth
, iconSpacing
);
3759 wxSize sizeLine
= GetLineSize(i
);
3761 if ( maxWidth
< sizeLine
.x
)
3762 maxWidth
= sizeLine
.x
;
3765 if (currentlyVisibleLines
> m_linesPerPage
)
3766 m_linesPerPage
= currentlyVisibleLines
;
3768 // assume that the size of the next one is the same... (FIXME)
3769 if ( y
+ sizeLine
.y
- 6 >= clientHeight
)
3771 currentlyVisibleLines
= 0;
3774 entireWidth
+= maxWidth
+6;
3777 if ( i
== count
- 1 )
3778 entireWidth
+= maxWidth
;
3779 if ((tries
== 0) && (entireWidth
> clientWidth
))
3781 clientHeight
-= 15; // scrollbar height
3783 currentlyVisibleLines
= 0;
3786 if ( i
== count
- 1 )
3787 tries
= 1; // everything fits, no second try required
3791 int scroll_pos
= GetScrollPos( wxHORIZONTAL
);
3792 SetScrollbars( m_xScroll
, m_yScroll
, (entireWidth
+SCROLL_UNIT_X
) / m_xScroll
, 0, scroll_pos
, 0, TRUE
);
3797 // FIXME: why should we call it from here?
3804 void wxListMainWindow::RefreshAll()
3809 wxListHeaderWindow
*headerWin
= GetListCtrl()->m_headerWin
;
3810 if ( headerWin
&& headerWin
->m_dirty
)
3812 headerWin
->m_dirty
= FALSE
;
3813 headerWin
->Refresh();
3817 void wxListMainWindow::UpdateCurrent()
3819 if ( !HasCurrent() && !IsEmpty() )
3824 if ( m_current
!= (size_t)-1 )
3826 OnFocusLine( m_current
);
3830 long wxListMainWindow::GetNextItem( long item
,
3831 int WXUNUSED(geometry
),
3835 max
= GetItemCount();
3836 wxCHECK_MSG( (ret
== -1) || (ret
< max
), -1,
3837 _T("invalid listctrl index in GetNextItem()") );
3839 // notice that we start with the next item (or the first one if item == -1)
3840 // and this is intentional to allow writing a simple loop to iterate over
3841 // all selected items
3845 // this is not an error because the index was ok initially, just no
3856 size_t count
= GetItemCount();
3857 for ( size_t line
= (size_t)ret
; line
< count
; line
++ )
3859 if ( (state
& wxLIST_STATE_FOCUSED
) && (line
== m_current
) )
3862 if ( (state
& wxLIST_STATE_SELECTED
) && IsHighlighted(line
) )
3869 // ----------------------------------------------------------------------------
3871 // ----------------------------------------------------------------------------
3873 void wxListMainWindow::DeleteItem( long lindex
)
3875 size_t count
= GetItemCount();
3877 wxCHECK_RET( (lindex
>= 0) && ((size_t)lindex
< count
),
3878 _T("invalid item index in DeleteItem") );
3880 size_t index
= (size_t)lindex
;
3882 // we don't need to adjust the index for the previous items
3883 if ( HasCurrent() && m_current
>= index
)
3885 // if the current item is being deleted, we want the next one to
3886 // become selected - unless there is no next one - so don't adjust
3887 // m_current in this case
3888 if ( m_current
!= index
|| m_current
== count
- 1 )
3894 if ( InReportView() )
3896 ResetVisibleLinesRange();
3903 m_selStore
.OnItemDelete(index
);
3907 m_lines
.RemoveAt( index
);
3910 // we need to refresh the (vert) scrollbar as the number of items changed
3913 SendNotify( index
, wxEVT_COMMAND_LIST_DELETE_ITEM
);
3915 RefreshAfter(index
);
3918 void wxListMainWindow::DeleteColumn( int col
)
3920 wxListHeaderDataList::Node
*node
= m_columns
.Item( col
);
3922 wxCHECK_RET( node
, wxT("invalid column index in DeleteColumn()") );
3925 m_columns
.DeleteNode( node
);
3928 void wxListMainWindow::DoDeleteAllItems()
3932 // nothing to do - in particular, don't send the event
3938 // to make the deletion of all items faster, we don't send the
3939 // notifications for each item deletion in this case but only one event
3940 // for all of them: this is compatible with wxMSW and documented in
3941 // DeleteAllItems() description
3943 wxListEvent
event( wxEVT_COMMAND_LIST_DELETE_ALL_ITEMS
, GetParent()->GetId() );
3944 event
.SetEventObject( GetParent() );
3945 GetParent()->GetEventHandler()->ProcessEvent( event
);
3954 if ( InReportView() )
3956 ResetVisibleLinesRange();
3962 void wxListMainWindow::DeleteAllItems()
3966 RecalculatePositions();
3969 void wxListMainWindow::DeleteEverything()
3976 // ----------------------------------------------------------------------------
3977 // scanning for an item
3978 // ----------------------------------------------------------------------------
3980 void wxListMainWindow::EnsureVisible( long index
)
3982 wxCHECK_RET( index
>= 0 && (size_t)index
< GetItemCount(),
3983 _T("invalid index in EnsureVisible") );
3985 // We have to call this here because the label in question might just have
3986 // been added and its position is not known yet
3991 RecalculatePositions(TRUE
/* no refresh */);
3994 MoveToItem((size_t)index
);
3997 long wxListMainWindow::FindItem(long start
, const wxString
& str
, bool WXUNUSED(partial
) )
4004 size_t count
= GetItemCount();
4005 for ( size_t i
= (size_t)pos
; i
< count
; i
++ )
4007 wxListLineData
*line
= GetLine(i
);
4008 if ( line
->GetText(0) == tmp
)
4015 long wxListMainWindow::FindItem(long start
, long data
)
4021 size_t count
= GetItemCount();
4022 for (size_t i
= (size_t)pos
; i
< count
; i
++)
4024 wxListLineData
*line
= GetLine(i
);
4026 line
->GetItem( 0, item
);
4027 if (item
.m_data
== data
)
4034 long wxListMainWindow::HitTest( int x
, int y
, int &flags
)
4036 CalcUnscrolledPosition( x
, y
, &x
, &y
);
4038 if ( HasFlag(wxLC_REPORT
) )
4040 size_t current
= y
/ GetLineHeight();
4041 flags
= HitTestLine(current
, x
, y
);
4047 // TODO: optimize it too! this is less simple than for report view but
4048 // enumerating all items is still not a way to do it!!
4049 size_t count
= GetItemCount();
4050 for ( size_t current
= 0; current
< count
; current
++ )
4052 flags
= HitTestLine(current
, x
, y
);
4061 // ----------------------------------------------------------------------------
4063 // ----------------------------------------------------------------------------
4065 void wxListMainWindow::InsertItem( wxListItem
&item
)
4067 wxASSERT_MSG( !IsVirtual(), _T("can't be used with virtual control") );
4069 size_t count
= GetItemCount();
4070 wxCHECK_RET( item
.m_itemId
>= 0 && (size_t)item
.m_itemId
<= count
,
4071 _T("invalid item index") );
4073 size_t id
= item
.m_itemId
;
4078 if ( HasFlag(wxLC_REPORT
) )
4080 else if ( HasFlag(wxLC_LIST
) )
4082 else if ( HasFlag(wxLC_ICON
) )
4084 else if ( HasFlag(wxLC_SMALL_ICON
) )
4085 mode
= wxLC_ICON
; // no typo
4088 wxFAIL_MSG( _T("unknown mode") );
4091 wxListLineData
*line
= new wxListLineData(this);
4093 line
->SetItem( 0, item
);
4095 m_lines
.Insert( line
, id
);
4098 RefreshLines(id
, GetItemCount() - 1);
4101 void wxListMainWindow::InsertColumn( long col
, wxListItem
&item
)
4104 if ( HasFlag(wxLC_REPORT
) )
4106 if (item
.m_width
== wxLIST_AUTOSIZE_USEHEADER
)
4107 item
.m_width
= GetTextLength( item
.m_text
);
4108 wxListHeaderData
*column
= new wxListHeaderData( item
);
4109 if ((col
>= 0) && (col
< (int)m_columns
.GetCount()))
4111 wxListHeaderDataList::Node
*node
= m_columns
.Item( col
);
4112 m_columns
.Insert( node
, column
);
4116 m_columns
.Append( column
);
4121 // ----------------------------------------------------------------------------
4123 // ----------------------------------------------------------------------------
4125 wxListCtrlCompare list_ctrl_compare_func_2
;
4126 long list_ctrl_compare_data
;
4128 int LINKAGEMODE
list_ctrl_compare_func_1( wxListLineData
**arg1
, wxListLineData
**arg2
)
4130 wxListLineData
*line1
= *arg1
;
4131 wxListLineData
*line2
= *arg2
;
4133 line1
->GetItem( 0, item
);
4134 long data1
= item
.m_data
;
4135 line2
->GetItem( 0, item
);
4136 long data2
= item
.m_data
;
4137 return list_ctrl_compare_func_2( data1
, data2
, list_ctrl_compare_data
);
4140 void wxListMainWindow::SortItems( wxListCtrlCompare fn
, long data
)
4142 list_ctrl_compare_func_2
= fn
;
4143 list_ctrl_compare_data
= data
;
4144 m_lines
.Sort( list_ctrl_compare_func_1
);
4148 // ----------------------------------------------------------------------------
4150 // ----------------------------------------------------------------------------
4152 void wxListMainWindow::OnScroll(wxScrollWinEvent
& event
)
4154 // update our idea of which lines are shown when we redraw the window the
4156 ResetVisibleLinesRange();
4159 #if defined(__WXGTK__) && !defined(__WXUNIVERSAL__)
4160 wxScrolledWindow::OnScroll(event
);
4162 HandleOnScroll( event
);
4165 if ( event
.GetOrientation() == wxHORIZONTAL
&& HasHeader() )
4167 wxListCtrl
* lc
= GetListCtrl();
4168 wxCHECK_RET( lc
, _T("no listctrl window?") );
4170 lc
->m_headerWin
->Refresh() ;
4172 lc
->m_headerWin
->MacUpdateImmediately() ;
4177 int wxListMainWindow::GetCountPerPage() const
4179 if ( !m_linesPerPage
)
4181 wxConstCast(this, wxListMainWindow
)->
4182 m_linesPerPage
= GetClientSize().y
/ GetLineHeight();
4185 return m_linesPerPage
;
4188 void wxListMainWindow::GetVisibleLinesRange(size_t *from
, size_t *to
)
4190 wxASSERT_MSG( HasFlag(wxLC_REPORT
), _T("this is for report mode only") );
4192 if ( m_lineFrom
== (size_t)-1 )
4194 size_t count
= GetItemCount();
4197 m_lineFrom
= GetScrollPos(wxVERTICAL
);
4199 // this may happen if SetScrollbars() hadn't been called yet
4200 if ( m_lineFrom
>= count
)
4201 m_lineFrom
= count
- 1;
4203 // we redraw one extra line but this is needed to make the redrawing
4204 // logic work when there is a fractional number of lines on screen
4205 m_lineTo
= m_lineFrom
+ m_linesPerPage
;
4206 if ( m_lineTo
>= count
)
4207 m_lineTo
= count
- 1;
4209 else // empty control
4212 m_lineTo
= (size_t)-1;
4216 wxASSERT_MSG( IsEmpty() ||
4217 (m_lineFrom
<= m_lineTo
&& m_lineTo
< GetItemCount()),
4218 _T("GetVisibleLinesRange() returns incorrect result") );
4226 // -------------------------------------------------------------------------------------
4228 // -------------------------------------------------------------------------------------
4230 IMPLEMENT_DYNAMIC_CLASS(wxListItem
, wxObject
)
4232 wxListItem::wxListItem()
4241 m_format
= wxLIST_FORMAT_CENTRE
;
4247 void wxListItem::Clear()
4256 m_format
= wxLIST_FORMAT_CENTRE
;
4263 void wxListItem::ClearAttributes()
4272 // -------------------------------------------------------------------------------------
4274 // -------------------------------------------------------------------------------------
4276 IMPLEMENT_DYNAMIC_CLASS(wxListEvent
, wxNotifyEvent
)
4278 wxListEvent::wxListEvent( wxEventType commandType
, int id
)
4279 : wxNotifyEvent( commandType
, id
)
4285 m_cancelled
= FALSE
;
4290 void wxListEvent::CopyObject(wxObject
& object_dest
) const
4292 wxListEvent
*obj
= (wxListEvent
*)&object_dest
;
4294 wxNotifyEvent::CopyObject(object_dest
);
4296 obj
->m_code
= m_code
;
4297 obj
->m_itemIndex
= m_itemIndex
;
4298 obj
->m_oldItemIndex
= m_oldItemIndex
;
4300 obj
->m_cancelled
= m_cancelled
;
4301 obj
->m_pointDrag
= m_pointDrag
;
4302 obj
->m_item
.m_mask
= m_item
.m_mask
;
4303 obj
->m_item
.m_itemId
= m_item
.m_itemId
;
4304 obj
->m_item
.m_col
= m_item
.m_col
;
4305 obj
->m_item
.m_state
= m_item
.m_state
;
4306 obj
->m_item
.m_stateMask
= m_item
.m_stateMask
;
4307 obj
->m_item
.m_text
= m_item
.m_text
;
4308 obj
->m_item
.m_image
= m_item
.m_image
;
4309 obj
->m_item
.m_data
= m_item
.m_data
;
4310 obj
->m_item
.m_format
= m_item
.m_format
;
4311 obj
->m_item
.m_width
= m_item
.m_width
;
4313 if ( m_item
.HasAttributes() )
4315 obj
->m_item
.SetTextColour(m_item
.GetTextColour());
4319 // -------------------------------------------------------------------------------------
4321 // -------------------------------------------------------------------------------------
4323 IMPLEMENT_DYNAMIC_CLASS(wxListCtrl
, wxControl
)
4324 IMPLEMENT_DYNAMIC_CLASS(wxListView
, wxListCtrl
)
4326 BEGIN_EVENT_TABLE(wxListCtrl
,wxControl
)
4327 EVT_SIZE(wxListCtrl::OnSize
)
4328 EVT_IDLE(wxListCtrl::OnIdle
)
4331 wxListCtrl::wxListCtrl()
4333 m_imageListNormal
= (wxImageList
*) NULL
;
4334 m_imageListSmall
= (wxImageList
*) NULL
;
4335 m_imageListState
= (wxImageList
*) NULL
;
4337 m_ownsImageListNormal
=
4338 m_ownsImageListSmall
=
4339 m_ownsImageListState
= FALSE
;
4341 m_mainWin
= (wxListMainWindow
*) NULL
;
4342 m_headerWin
= (wxListHeaderWindow
*) NULL
;
4345 wxListCtrl::~wxListCtrl()
4348 m_mainWin
->ResetCurrent();
4350 if (m_ownsImageListNormal
)
4351 delete m_imageListNormal
;
4352 if (m_ownsImageListSmall
)
4353 delete m_imageListSmall
;
4354 if (m_ownsImageListState
)
4355 delete m_imageListState
;
4358 void wxListCtrl::CreateHeaderWindow()
4360 m_headerWin
= new wxListHeaderWindow
4362 this, -1, m_mainWin
,
4364 wxSize(GetClientSize().x
, HEADER_HEIGHT
),
4369 bool wxListCtrl::Create(wxWindow
*parent
,
4374 const wxValidator
&validator
,
4375 const wxString
&name
)
4379 m_imageListState
= (wxImageList
*) NULL
;
4380 m_ownsImageListNormal
=
4381 m_ownsImageListSmall
=
4382 m_ownsImageListState
= FALSE
;
4384 m_mainWin
= (wxListMainWindow
*) NULL
;
4385 m_headerWin
= (wxListHeaderWindow
*) NULL
;
4387 if ( !(style
& wxLC_MASK_TYPE
) )
4389 style
= style
| wxLC_LIST
;
4392 if ( !wxControl::Create( parent
, id
, pos
, size
, style
, validator
, name
) )
4395 // don't create the inner window with the border
4396 style
&= ~wxSUNKEN_BORDER
;
4398 m_mainWin
= new wxListMainWindow( this, -1, wxPoint(0,0), size
, style
);
4400 if ( HasFlag(wxLC_REPORT
) )
4402 CreateHeaderWindow();
4404 if ( HasFlag(wxLC_NO_HEADER
) )
4406 // VZ: why do we create it at all then?
4407 m_headerWin
->Show( FALSE
);
4414 void wxListCtrl::SetSingleStyle( long style
, bool add
)
4416 wxASSERT_MSG( !(style
& wxLC_VIRTUAL
),
4417 _T("wxLC_VIRTUAL can't be [un]set") );
4419 long flag
= GetWindowStyle();
4423 if (style
& wxLC_MASK_TYPE
)
4424 flag
&= ~(wxLC_MASK_TYPE
| wxLC_VIRTUAL
);
4425 if (style
& wxLC_MASK_ALIGN
)
4426 flag
&= ~wxLC_MASK_ALIGN
;
4427 if (style
& wxLC_MASK_SORT
)
4428 flag
&= ~wxLC_MASK_SORT
;
4440 SetWindowStyleFlag( flag
);
4443 void wxListCtrl::SetWindowStyleFlag( long flag
)
4447 m_mainWin
->DeleteEverything();
4449 // has the header visibility changed?
4450 bool hasHeader
= HasFlag(wxLC_REPORT
) && !HasFlag(wxLC_NO_HEADER
),
4451 willHaveHeader
= (flag
& wxLC_REPORT
) && !(flag
& wxLC_NO_HEADER
);
4453 if ( hasHeader
!= willHaveHeader
)
4460 // don't delete, just hide, as we can reuse it later
4461 m_headerWin
->Show(FALSE
);
4463 //else: nothing to do
4465 else // must show header
4469 CreateHeaderWindow();
4471 else // already have it, just show
4473 m_headerWin
->Show( TRUE
);
4477 ResizeReportView(willHaveHeader
);
4481 wxWindow::SetWindowStyleFlag( flag
);
4484 bool wxListCtrl::GetColumn(int col
, wxListItem
&item
) const
4486 m_mainWin
->GetColumn( col
, item
);
4490 bool wxListCtrl::SetColumn( int col
, wxListItem
& item
)
4492 m_mainWin
->SetColumn( col
, item
);
4496 int wxListCtrl::GetColumnWidth( int col
) const
4498 return m_mainWin
->GetColumnWidth( col
);
4501 bool wxListCtrl::SetColumnWidth( int col
, int width
)
4503 m_mainWin
->SetColumnWidth( col
, width
);
4507 int wxListCtrl::GetCountPerPage() const
4509 return m_mainWin
->GetCountPerPage(); // different from Windows ?
4512 bool wxListCtrl::GetItem( wxListItem
&info
) const
4514 m_mainWin
->GetItem( info
);
4518 bool wxListCtrl::SetItem( wxListItem
&info
)
4520 m_mainWin
->SetItem( info
);
4524 long wxListCtrl::SetItem( long index
, int col
, const wxString
& label
, int imageId
)
4527 info
.m_text
= label
;
4528 info
.m_mask
= wxLIST_MASK_TEXT
;
4529 info
.m_itemId
= index
;
4533 info
.m_image
= imageId
;
4534 info
.m_mask
|= wxLIST_MASK_IMAGE
;
4536 m_mainWin
->SetItem(info
);
4540 int wxListCtrl::GetItemState( long item
, long stateMask
) const
4542 return m_mainWin
->GetItemState( item
, stateMask
);
4545 bool wxListCtrl::SetItemState( long item
, long state
, long stateMask
)
4547 m_mainWin
->SetItemState( item
, state
, stateMask
);
4551 bool wxListCtrl::SetItemImage( long item
, int image
, int WXUNUSED(selImage
) )
4554 info
.m_image
= image
;
4555 info
.m_mask
= wxLIST_MASK_IMAGE
;
4556 info
.m_itemId
= item
;
4557 m_mainWin
->SetItem( info
);
4561 wxString
wxListCtrl::GetItemText( long item
) const
4564 info
.m_itemId
= item
;
4565 m_mainWin
->GetItem( info
);
4569 void wxListCtrl::SetItemText( long item
, const wxString
&str
)
4572 info
.m_mask
= wxLIST_MASK_TEXT
;
4573 info
.m_itemId
= item
;
4575 m_mainWin
->SetItem( info
);
4578 long wxListCtrl::GetItemData( long item
) const
4581 info
.m_itemId
= item
;
4582 m_mainWin
->GetItem( info
);
4586 bool wxListCtrl::SetItemData( long item
, long data
)
4589 info
.m_mask
= wxLIST_MASK_DATA
;
4590 info
.m_itemId
= item
;
4592 m_mainWin
->SetItem( info
);
4596 bool wxListCtrl::GetItemRect( long item
, wxRect
&rect
, int WXUNUSED(code
) ) const
4598 m_mainWin
->GetItemRect( item
, rect
);
4602 bool wxListCtrl::GetItemPosition( long item
, wxPoint
& pos
) const
4604 m_mainWin
->GetItemPosition( item
, pos
);
4608 bool wxListCtrl::SetItemPosition( long WXUNUSED(item
), const wxPoint
& WXUNUSED(pos
) )
4613 int wxListCtrl::GetItemCount() const
4615 return m_mainWin
->GetItemCount();
4618 int wxListCtrl::GetColumnCount() const
4620 return m_mainWin
->GetColumnCount();
4623 void wxListCtrl::SetItemSpacing( int spacing
, bool isSmall
)
4625 m_mainWin
->SetItemSpacing( spacing
, isSmall
);
4628 int wxListCtrl::GetItemSpacing( bool isSmall
) const
4630 return m_mainWin
->GetItemSpacing( isSmall
);
4633 int wxListCtrl::GetSelectedItemCount() const
4635 return m_mainWin
->GetSelectedItemCount();
4638 wxColour
wxListCtrl::GetTextColour() const
4640 return GetForegroundColour();
4643 void wxListCtrl::SetTextColour(const wxColour
& col
)
4645 SetForegroundColour(col
);
4648 long wxListCtrl::GetTopItem() const
4653 long wxListCtrl::GetNextItem( long item
, int geom
, int state
) const
4655 return m_mainWin
->GetNextItem( item
, geom
, state
);
4658 wxImageList
*wxListCtrl::GetImageList(int which
) const
4660 if (which
== wxIMAGE_LIST_NORMAL
)
4662 return m_imageListNormal
;
4664 else if (which
== wxIMAGE_LIST_SMALL
)
4666 return m_imageListSmall
;
4668 else if (which
== wxIMAGE_LIST_STATE
)
4670 return m_imageListState
;
4672 return (wxImageList
*) NULL
;
4675 void wxListCtrl::SetImageList( wxImageList
*imageList
, int which
)
4677 if ( which
== wxIMAGE_LIST_NORMAL
)
4679 if (m_ownsImageListNormal
) delete m_imageListNormal
;
4680 m_imageListNormal
= imageList
;
4681 m_ownsImageListNormal
= FALSE
;
4683 else if ( which
== wxIMAGE_LIST_SMALL
)
4685 if (m_ownsImageListSmall
) delete m_imageListSmall
;
4686 m_imageListSmall
= imageList
;
4687 m_ownsImageListSmall
= FALSE
;
4689 else if ( which
== wxIMAGE_LIST_STATE
)
4691 if (m_ownsImageListState
) delete m_imageListState
;
4692 m_imageListState
= imageList
;
4693 m_ownsImageListState
= FALSE
;
4696 m_mainWin
->SetImageList( imageList
, which
);
4699 void wxListCtrl::AssignImageList(wxImageList
*imageList
, int which
)
4701 SetImageList(imageList
, which
);
4702 if ( which
== wxIMAGE_LIST_NORMAL
)
4703 m_ownsImageListNormal
= TRUE
;
4704 else if ( which
== wxIMAGE_LIST_SMALL
)
4705 m_ownsImageListSmall
= TRUE
;
4706 else if ( which
== wxIMAGE_LIST_STATE
)
4707 m_ownsImageListState
= TRUE
;
4710 bool wxListCtrl::Arrange( int WXUNUSED(flag
) )
4715 bool wxListCtrl::DeleteItem( long item
)
4717 m_mainWin
->DeleteItem( item
);
4721 bool wxListCtrl::DeleteAllItems()
4723 m_mainWin
->DeleteAllItems();
4727 bool wxListCtrl::DeleteAllColumns()
4729 size_t count
= m_mainWin
->m_columns
.GetCount();
4730 for ( size_t n
= 0; n
< count
; n
++ )
4736 void wxListCtrl::ClearAll()
4738 m_mainWin
->DeleteEverything();
4741 bool wxListCtrl::DeleteColumn( int col
)
4743 m_mainWin
->DeleteColumn( col
);
4747 void wxListCtrl::Edit( long item
)
4749 m_mainWin
->EditLabel( item
);
4752 bool wxListCtrl::EnsureVisible( long item
)
4754 m_mainWin
->EnsureVisible( item
);
4758 long wxListCtrl::FindItem( long start
, const wxString
& str
, bool partial
)
4760 return m_mainWin
->FindItem( start
, str
, partial
);
4763 long wxListCtrl::FindItem( long start
, long data
)
4765 return m_mainWin
->FindItem( start
, data
);
4768 long wxListCtrl::FindItem( long WXUNUSED(start
), const wxPoint
& WXUNUSED(pt
),
4769 int WXUNUSED(direction
))
4774 long wxListCtrl::HitTest( const wxPoint
&point
, int &flags
)
4776 return m_mainWin
->HitTest( (int)point
.x
, (int)point
.y
, flags
);
4779 long wxListCtrl::InsertItem( wxListItem
& info
)
4781 m_mainWin
->InsertItem( info
);
4782 return info
.m_itemId
;
4785 long wxListCtrl::InsertItem( long index
, const wxString
&label
)
4788 info
.m_text
= label
;
4789 info
.m_mask
= wxLIST_MASK_TEXT
;
4790 info
.m_itemId
= index
;
4791 return InsertItem( info
);
4794 long wxListCtrl::InsertItem( long index
, int imageIndex
)
4797 info
.m_mask
= wxLIST_MASK_IMAGE
;
4798 info
.m_image
= imageIndex
;
4799 info
.m_itemId
= index
;
4800 return InsertItem( info
);
4803 long wxListCtrl::InsertItem( long index
, const wxString
&label
, int imageIndex
)
4806 info
.m_text
= label
;
4807 info
.m_image
= imageIndex
;
4808 info
.m_mask
= wxLIST_MASK_TEXT
| wxLIST_MASK_IMAGE
;
4809 info
.m_itemId
= index
;
4810 return InsertItem( info
);
4813 long wxListCtrl::InsertColumn( long col
, wxListItem
&item
)
4815 wxASSERT( m_headerWin
);
4816 m_mainWin
->InsertColumn( col
, item
);
4817 m_headerWin
->Refresh();
4822 long wxListCtrl::InsertColumn( long col
, const wxString
&heading
,
4823 int format
, int width
)
4826 item
.m_mask
= wxLIST_MASK_TEXT
| wxLIST_MASK_FORMAT
;
4827 item
.m_text
= heading
;
4830 item
.m_mask
|= wxLIST_MASK_WIDTH
;
4831 item
.m_width
= width
;
4833 item
.m_format
= format
;
4835 return InsertColumn( col
, item
);
4838 bool wxListCtrl::ScrollList( int WXUNUSED(dx
), int WXUNUSED(dy
) )
4844 // fn is a function which takes 3 long arguments: item1, item2, data.
4845 // item1 is the long data associated with a first item (NOT the index).
4846 // item2 is the long data associated with a second item (NOT the index).
4847 // data is the same value as passed to SortItems.
4848 // The return value is a negative number if the first item should precede the second
4849 // item, a positive number of the second item should precede the first,
4850 // or zero if the two items are equivalent.
4851 // data is arbitrary data to be passed to the sort function.
4853 bool wxListCtrl::SortItems( wxListCtrlCompare fn
, long data
)
4855 m_mainWin
->SortItems( fn
, data
);
4859 // ----------------------------------------------------------------------------
4861 // ----------------------------------------------------------------------------
4863 void wxListCtrl::OnSize(wxSizeEvent
& event
)
4868 ResizeReportView(m_mainWin
->HasHeader());
4870 m_mainWin
->RecalculatePositions();
4873 void wxListCtrl::ResizeReportView(bool showHeader
)
4876 GetClientSize( &cw
, &ch
);
4880 m_headerWin
->SetSize( 0, 0, cw
, HEADER_HEIGHT
);
4881 m_mainWin
->SetSize( 0, HEADER_HEIGHT
+ 1, cw
, ch
- HEADER_HEIGHT
- 1 );
4883 else // no header window
4885 m_mainWin
->SetSize( 0, 0, cw
, ch
);
4889 void wxListCtrl::OnIdle( wxIdleEvent
& event
)
4893 // do it only if needed
4894 if ( !m_mainWin
->m_dirty
)
4897 m_mainWin
->RecalculatePositions();
4900 // ----------------------------------------------------------------------------
4902 // ----------------------------------------------------------------------------
4904 bool wxListCtrl::SetBackgroundColour( const wxColour
&colour
)
4908 m_mainWin
->SetBackgroundColour( colour
);
4909 m_mainWin
->m_dirty
= TRUE
;
4915 bool wxListCtrl::SetForegroundColour( const wxColour
&colour
)
4917 if ( !wxWindow::SetForegroundColour( colour
) )
4922 m_mainWin
->SetForegroundColour( colour
);
4923 m_mainWin
->m_dirty
= TRUE
;
4928 m_headerWin
->SetForegroundColour( colour
);
4934 bool wxListCtrl::SetFont( const wxFont
&font
)
4936 if ( !wxWindow::SetFont( font
) )
4941 m_mainWin
->SetFont( font
);
4942 m_mainWin
->m_dirty
= TRUE
;
4947 m_headerWin
->SetFont( font
);
4953 // ----------------------------------------------------------------------------
4954 // methods forwarded to m_mainWin
4955 // ----------------------------------------------------------------------------
4957 #if wxUSE_DRAG_AND_DROP
4959 void wxListCtrl::SetDropTarget( wxDropTarget
*dropTarget
)
4961 m_mainWin
->SetDropTarget( dropTarget
);
4964 wxDropTarget
*wxListCtrl::GetDropTarget() const
4966 return m_mainWin
->GetDropTarget();
4969 #endif // wxUSE_DRAG_AND_DROP
4971 bool wxListCtrl::SetCursor( const wxCursor
&cursor
)
4973 return m_mainWin
? m_mainWin
->wxWindow::SetCursor(cursor
) : FALSE
;
4976 wxColour
wxListCtrl::GetBackgroundColour() const
4978 return m_mainWin
? m_mainWin
->GetBackgroundColour() : wxColour();
4981 wxColour
wxListCtrl::GetForegroundColour() const
4983 return m_mainWin
? m_mainWin
->GetForegroundColour() : wxColour();
4986 bool wxListCtrl::DoPopupMenu( wxMenu
*menu
, int x
, int y
)
4989 return m_mainWin
->PopupMenu( menu
, x
, y
);
4992 #endif // wxUSE_MENUS
4995 void wxListCtrl::SetFocus()
4997 /* The test in window.cpp fails as we are a composite
4998 window, so it checks against "this", but not m_mainWin. */
4999 if ( FindFocus() != this )
5000 m_mainWin
->SetFocus();
5003 // ----------------------------------------------------------------------------
5004 // virtual list control support
5005 // ----------------------------------------------------------------------------
5007 wxString
wxListCtrl::OnGetItemText(long item
, long col
) const
5009 // this is a pure virtual function, in fact - which is not really pure
5010 // because the controls which are not virtual don't need to implement it
5011 wxFAIL_MSG( _T("not supposed to be called") );
5013 return wxEmptyString
;
5016 int wxListCtrl::OnGetItemImage(long item
) const
5019 wxFAIL_MSG( _T("not supposed to be called") );
5024 wxListItemAttr
*wxListCtrl::OnGetItemAttr(long item
) const
5026 wxASSERT_MSG( item
>= 0 && item
< GetItemCount(),
5027 _T("invalid item index in OnGetItemAttr()") );
5029 // no attributes by default
5033 void wxListCtrl::SetItemCount(long count
)
5035 wxASSERT_MSG( IsVirtual(), _T("this is for virtual controls only") );
5037 m_mainWin
->SetItemCount(count
);
5040 void wxListCtrl::RefreshItem(long item
)
5042 m_mainWin
->RefreshLine(item
);
5045 void wxListCtrl::RefreshItems(long itemFrom
, long itemTo
)
5047 m_mainWin
->RefreshLines(itemFrom
, itemTo
);
5050 #endif // wxUSE_LISTCTRL