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 // the space between the image and the text in the report mode
103 static const int IMAGE_MARGIN_IN_REPORT_MODE
= 5;
105 // ============================================================================
107 // ============================================================================
109 // ----------------------------------------------------------------------------
111 // ----------------------------------------------------------------------------
113 int CMPFUNC_CONV
wxSizeTCmpFn(size_t n1
, size_t n2
) { return n1
- n2
; }
115 WX_DEFINE_SORTED_EXPORTED_ARRAY(size_t, wxIndexArray
);
117 // this class is used to store the selected items in the virtual list control
118 // (but it is not tied to list control and so can be used with other controls
119 // such as wxListBox in wxUniv)
121 // the idea is to make it really smart later (i.e. store the selections as an
122 // array of ranes + individual items) but, as I don't have time to do it now
123 // (this would require writing code to merge/break ranges and much more) keep
124 // it simple but define a clean interface to it which allows it to be made
126 class WXDLLEXPORT wxSelectionStore
129 wxSelectionStore() : m_itemsSel(wxSizeTCmpFn
) { Init(); }
131 // set the total number of items we handle
132 void SetItemCount(size_t count
) { m_count
= count
; }
134 // special case of SetItemCount(0)
135 void Clear() { m_itemsSel
.Clear(); m_count
= 0; }
137 // must be called when a new item is inserted/added
138 void OnItemAdd(size_t item
) { wxFAIL_MSG( _T("TODO") ); }
140 // must be called when an item is deleted
141 void OnItemDelete(size_t item
);
143 // select one item, use SelectRange() insted if possible!
145 // returns true if the items selection really changed
146 bool SelectItem(size_t item
, bool select
= TRUE
);
148 // select the range of items
150 // return true and fill the itemsChanged array with the indices of items
151 // which have changed state if "few" of them did, otherwise return false
152 // (meaning that too many items changed state to bother counting them
154 bool SelectRange(size_t itemFrom
, size_t itemTo
,
156 wxArrayInt
*itemsChanged
= NULL
);
158 // return true if the given item is selected
159 bool IsSelected(size_t item
) const;
161 // return the total number of selected items
162 size_t GetSelectedCount() const
164 return m_defaultState
? m_count
- m_itemsSel
.GetCount()
165 : m_itemsSel
.GetCount();
170 void Init() { m_defaultState
= FALSE
; }
172 // the total number of items we handle
175 // the default state: normally, FALSE (i.e. off) but maybe set to TRUE if
176 // there are more selected items than non selected ones - this allows to
177 // handle selection of all items efficiently
180 // the array of items whose selection state is different from default
181 wxIndexArray m_itemsSel
;
183 DECLARE_NO_COPY_CLASS(wxSelectionStore
)
186 //-----------------------------------------------------------------------------
187 // wxListItemData (internal)
188 //-----------------------------------------------------------------------------
190 class WXDLLEXPORT wxListItemData
193 wxListItemData(wxListMainWindow
*owner
);
196 void SetItem( const wxListItem
&info
);
197 void SetImage( int image
) { m_image
= image
; }
198 void SetData( long data
) { m_data
= data
; }
199 void SetPosition( int x
, int y
);
200 void SetSize( int width
, int height
);
202 bool HasText() const { return !m_text
.empty(); }
203 const wxString
& GetText() const { return m_text
; }
204 void SetText(const wxString
& text
) { m_text
= text
; }
206 // we can't use empty string for measuring the string width/height, so
207 // always return something
208 wxString
GetTextForMeasuring() const
210 wxString s
= GetText();
217 bool IsHit( int x
, int y
) const;
221 int GetWidth() const;
222 int GetHeight() const;
224 int GetImage() const { return m_image
; }
225 bool HasImage() const { return GetImage() != -1; }
227 void GetItem( wxListItem
&info
) const;
229 void SetAttr(wxListItemAttr
*attr
) { m_attr
= attr
; }
230 wxListItemAttr
*GetAttr() const { return m_attr
; }
233 // the item image or -1
236 // user data associated with the item
239 // the item coordinates are not used in report mode, instead this pointer
240 // is NULL and the owner window is used to retrieve the item position and
244 // the list ctrl we are in
245 wxListMainWindow
*m_owner
;
247 // custom attributes or NULL
248 wxListItemAttr
*m_attr
;
251 // common part of all ctors
257 //-----------------------------------------------------------------------------
258 // wxListHeaderData (internal)
259 //-----------------------------------------------------------------------------
261 class WXDLLEXPORT wxListHeaderData
: public wxObject
275 wxListHeaderData( const wxListItem
&info
);
276 void SetItem( const wxListItem
&item
);
277 void SetPosition( int x
, int y
);
278 void SetWidth( int w
);
279 void SetFormat( int format
);
280 void SetHeight( int h
);
281 bool HasImage() const;
283 bool HasText() const { return !m_text
.empty(); }
284 const wxString
& GetText() const { return m_text
; }
285 void SetText(const wxString
& text
) { m_text
= text
; }
287 void GetItem( wxListItem
&item
);
289 bool IsHit( int x
, int y
) const;
290 int GetImage() const;
291 int GetWidth() const;
292 int GetFormat() const;
295 DECLARE_DYNAMIC_CLASS(wxListHeaderData
);
298 //-----------------------------------------------------------------------------
299 // wxListLineData (internal)
300 //-----------------------------------------------------------------------------
302 WX_DECLARE_LIST(wxListItemData
, wxListItemDataList
);
303 #include "wx/listimpl.cpp"
304 WX_DEFINE_LIST(wxListItemDataList
);
306 class WXDLLEXPORT wxListLineData
309 // the list of subitems: only may have more than one item in report mode
310 wxListItemDataList m_items
;
312 // this is not used in report view
324 // the part to be highlighted
325 wxRect m_rectHighlight
;
328 // is this item selected? [NB: not used in virtual mode]
331 // back pointer to the list ctrl
332 wxListMainWindow
*m_owner
;
335 wxListLineData(wxListMainWindow
*owner
);
337 ~wxListLineData() { delete m_gi
; }
339 // are we in report mode?
340 inline bool InReportView() const;
342 // are we in virtual report mode?
343 inline bool IsVirtual() const;
345 // these 2 methods shouldn't be called for report view controls, in that
346 // case we determine our position/size ourselves
348 // calculate the size of the line
349 void CalculateSize( wxDC
*dc
, int spacing
);
351 // remember the position this line appears at
352 void SetPosition( int x
, int y
, int window_width
, int spacing
);
356 void SetImage( int image
) { SetImage(0, image
); }
357 int GetImage() const { return GetImage(0); }
358 bool HasImage() const { return GetImage() != -1; }
359 bool HasText() const { return !GetText(0).empty(); }
361 void SetItem( int index
, const wxListItem
&info
);
362 void GetItem( int index
, wxListItem
&info
);
364 wxString
GetText(int index
) const;
365 void SetText( int index
, const wxString s
);
367 wxListItemAttr
*GetAttr() const;
368 void SetAttr(wxListItemAttr
*attr
);
370 // return true if the highlighting really changed
371 bool Highlight( bool on
);
373 void ReverseHighlight();
375 bool IsHighlighted() const
377 wxASSERT_MSG( !IsVirtual(), _T("unexpected call to IsHighlighted") );
379 return m_highlighted
;
382 // draw the line on the given DC in icon/list mode
383 void Draw( wxDC
*dc
);
385 // the same in report mode
386 void DrawInReportMode( wxDC
*dc
,
388 const wxRect
& rectHL
,
392 // set the line to contain num items (only can be > 1 in report mode)
393 void InitItems( int num
);
395 // get the mode (i.e. style) of the list control
396 inline int GetMode() const;
398 // prepare the DC for drawing with these item's attributes, return true if
399 // we need to draw the items background to highlight it, false otherwise
400 bool SetAttributes(wxDC
*dc
,
401 const wxListItemAttr
*attr
,
404 // these are only used by GetImage/SetImage above, we don't support images
405 // with subitems at the public API level yet
406 void SetImage( int index
, int image
);
407 int GetImage( int index
) const;
410 WX_DECLARE_EXPORTED_OBJARRAY(wxListLineData
, wxListLineDataArray
);
411 #include "wx/arrimpl.cpp"
412 WX_DEFINE_OBJARRAY(wxListLineDataArray
);
414 //-----------------------------------------------------------------------------
415 // wxListHeaderWindow (internal)
416 //-----------------------------------------------------------------------------
418 class WXDLLEXPORT wxListHeaderWindow
: public wxWindow
421 wxListMainWindow
*m_owner
;
422 wxCursor
*m_currentCursor
;
423 wxCursor
*m_resizeCursor
;
426 // column being resized
429 // divider line position in logical (unscrolled) coords
432 // minimal position beyond which the divider line can't be dragged in
437 wxListHeaderWindow();
438 virtual ~wxListHeaderWindow();
440 wxListHeaderWindow( wxWindow
*win
,
442 wxListMainWindow
*owner
,
443 const wxPoint
&pos
= wxDefaultPosition
,
444 const wxSize
&size
= wxDefaultSize
,
446 const wxString
&name
= "wxlistctrlcolumntitles" );
448 void DoDrawRect( wxDC
*dc
, int x
, int y
, int w
, int h
);
450 void AdjustDC(wxDC
& dc
);
452 void OnPaint( wxPaintEvent
&event
);
453 void OnMouse( wxMouseEvent
&event
);
454 void OnSetFocus( wxFocusEvent
&event
);
460 DECLARE_DYNAMIC_CLASS(wxListHeaderWindow
)
461 DECLARE_EVENT_TABLE()
464 //-----------------------------------------------------------------------------
465 // wxListRenameTimer (internal)
466 //-----------------------------------------------------------------------------
468 class WXDLLEXPORT wxListRenameTimer
: public wxTimer
471 wxListMainWindow
*m_owner
;
474 wxListRenameTimer( wxListMainWindow
*owner
);
478 //-----------------------------------------------------------------------------
479 // wxListTextCtrl (internal)
480 //-----------------------------------------------------------------------------
482 class WXDLLEXPORT wxListTextCtrl
: public wxTextCtrl
487 wxListMainWindow
*m_owner
;
488 wxString m_startValue
;
492 wxListTextCtrl( wxWindow
*parent
, const wxWindowID id
,
493 bool *accept
, wxString
*res
, wxListMainWindow
*owner
,
494 const wxString
&value
= "",
495 const wxPoint
&pos
= wxDefaultPosition
, const wxSize
&size
= wxDefaultSize
,
497 const wxValidator
& validator
= wxDefaultValidator
,
498 const wxString
&name
= "listctrltextctrl" );
499 void OnChar( wxKeyEvent
&event
);
500 void OnKeyUp( wxKeyEvent
&event
);
501 void OnKillFocus( wxFocusEvent
&event
);
504 DECLARE_DYNAMIC_CLASS(wxListTextCtrl
);
505 DECLARE_EVENT_TABLE()
508 //-----------------------------------------------------------------------------
509 // wxListMainWindow (internal)
510 //-----------------------------------------------------------------------------
512 WX_DECLARE_LIST(wxListHeaderData
, wxListHeaderDataList
);
513 #include "wx/listimpl.cpp"
514 WX_DEFINE_LIST(wxListHeaderDataList
);
516 class WXDLLEXPORT wxListMainWindow
: public wxScrolledWindow
520 wxListMainWindow( wxWindow
*parent
,
522 const wxPoint
& pos
= wxDefaultPosition
,
523 const wxSize
& size
= wxDefaultSize
,
525 const wxString
&name
= _T("listctrlmainwindow") );
527 virtual ~wxListMainWindow();
529 bool HasFlag(int flag
) const { return m_parent
->HasFlag(flag
); }
531 // return true if this is a virtual list control
532 bool IsVirtual() const { return HasFlag(wxLC_VIRTUAL
); }
534 // return true if the control is in report mode
535 bool InReportView() const { return HasFlag(wxLC_REPORT
); }
537 // return true if we are in single selection mode, false if multi sel
538 bool IsSingleSel() const { return HasFlag(wxLC_SINGLE_SEL
); }
540 // do we have a header window?
541 bool HasHeader() const
542 { return HasFlag(wxLC_REPORT
) && !HasFlag(wxLC_NO_HEADER
); }
544 void HighlightAll( bool on
);
546 // all these functions only do something if the line is currently visible
548 // change the line "selected" state, return TRUE if it really changed
549 bool HighlightLine( size_t line
, bool highlight
= TRUE
);
551 // as HighlightLine() but do it for the range of lines: this is incredibly
552 // more efficient for virtual list controls!
554 // NB: unlike HighlightLine() this one does refresh the lines on screen
555 void HighlightLines( size_t lineFrom
, size_t lineTo
, bool on
= TRUE
);
557 // toggle the line state and refresh it
558 void ReverseHighlight( size_t line
)
559 { HighlightLine(line
, !IsHighlighted(line
)); RefreshLine(line
); }
561 // return true if the line is highlighted
562 bool IsHighlighted(size_t line
) const;
564 // refresh one or several lines at once
565 void RefreshLine( size_t line
);
566 void RefreshLines( size_t lineFrom
, size_t lineTo
);
568 // refresh all lines below the given one: the difference with
569 // RefreshLines() is that the index here might not be a valid one (happens
570 // when the last line is deleted)
571 void RefreshAfter( size_t lineFrom
);
573 // the methods which are forwarded to wxListLineData itself in list/icon
574 // modes but are here because the lines don't store their positions in the
577 // get the bound rect for the entire line
578 wxRect
GetLineRect(size_t line
) const;
580 // get the bound rect of the label
581 wxRect
GetLineLabelRect(size_t line
) const;
583 // get the bound rect of the items icon (only may be called if we do have
585 wxRect
GetLineIconRect(size_t line
) const;
587 // get the rect to be highlighted when the item has focus
588 wxRect
GetLineHighlightRect(size_t line
) const;
590 // get the size of the total line rect
591 wxSize
GetLineSize(size_t line
) const
592 { return GetLineRect(line
).GetSize(); }
594 // return the hit code for the corresponding position (in this line)
595 long HitTestLine(size_t line
, int x
, int y
) const;
597 // bring the selected item into view, scrolling to it if necessary
598 void MoveToItem(size_t item
);
600 // bring the current item into view
601 void MoveToFocus() { MoveToItem(m_current
); }
603 void EditLabel( long item
);
604 void OnRenameTimer();
605 void OnRenameAccept();
607 void OnMouse( wxMouseEvent
&event
);
609 // called to switch the selection from the current item to newCurrent,
610 void OnArrowChar( size_t newCurrent
, const wxKeyEvent
& event
);
612 void OnChar( wxKeyEvent
&event
);
613 void OnKeyDown( wxKeyEvent
&event
);
614 void OnSetFocus( wxFocusEvent
&event
);
615 void OnKillFocus( wxFocusEvent
&event
);
616 void OnScroll(wxScrollWinEvent
& event
) ;
618 void OnPaint( wxPaintEvent
&event
);
620 void DrawImage( int index
, wxDC
*dc
, int x
, int y
);
621 void GetImageSize( int index
, int &width
, int &height
) const;
622 int GetTextLength( const wxString
&s
) const;
624 void SetImageList( wxImageList
*imageList
, int which
);
625 void SetItemSpacing( int spacing
, bool isSmall
= FALSE
);
626 int GetItemSpacing( bool isSmall
= FALSE
);
628 void SetColumn( int col
, wxListItem
&item
);
629 void SetColumnWidth( int col
, int width
);
630 void GetColumn( int col
, wxListItem
&item
) const;
631 int GetColumnWidth( int col
) const;
632 int GetColumnCount() const { return m_columns
.GetCount(); }
634 // returns the sum of the heights of all columns
635 int GetHeaderWidth() const;
637 int GetCountPerPage() const;
639 void SetItem( wxListItem
&item
);
640 void GetItem( wxListItem
&item
);
641 void SetItemState( long item
, long state
, long stateMask
);
642 int GetItemState( long item
, long stateMask
);
643 void GetItemRect( long index
, wxRect
&rect
);
644 bool GetItemPosition( long item
, wxPoint
& pos
);
645 int GetSelectedItemCount();
647 // set the scrollbars and update the positions of the items
648 void RecalculatePositions(bool noRefresh
= FALSE
);
650 // refresh the window and the header
653 long GetNextItem( long item
, int geometry
, int state
);
654 void DeleteItem( long index
);
655 void DeleteAllItems();
656 void DeleteColumn( int col
);
657 void DeleteEverything();
658 void EnsureVisible( long index
);
659 long FindItem( long start
, const wxString
& str
, bool partial
= FALSE
);
660 long FindItem( long start
, long data
);
661 long HitTest( int x
, int y
, int &flags
);
662 void InsertItem( wxListItem
&item
);
663 void InsertColumn( long col
, wxListItem
&item
);
664 void SortItems( wxListCtrlCompare fn
, long data
);
666 size_t GetItemCount() const;
667 bool IsEmpty() const { return GetItemCount() == 0; }
668 void SetItemCount(long count
);
670 void ResetCurrent() { m_current
= (size_t)-1; }
671 bool HasCurrent() const { return m_current
!= (size_t)-1; }
673 // send out a wxListEvent
674 void SendNotify( size_t line
,
676 wxPoint point
= wxDefaultPosition
);
678 // override base class virtual to reset m_lineHeight when the font changes
679 virtual bool SetFont(const wxFont
& font
)
681 if ( !wxScrolledWindow::SetFont(font
) )
689 // these are for wxListLineData usage only
691 // get the backpointer to the list ctrl
692 wxListCtrl
*GetListCtrl() const
694 return wxStaticCast(GetParent(), wxListCtrl
);
697 // get the height of all lines (assuming they all do have the same height)
698 wxCoord
GetLineHeight() const;
700 // get the y position of the given line (only for report view)
701 wxCoord
GetLineY(size_t line
) const;
704 // the array of all line objects for a non virtual list control
705 wxListLineDataArray m_lines
;
707 // the list of column objects
708 wxListHeaderDataList m_columns
;
710 // currently focused item or -1
713 // the item currently being edited or -1
714 size_t m_currentEdit
;
716 // the number of lines per page
719 // this flag is set when something which should result in the window
720 // redrawing happens (i.e. an item was added or deleted, or its appearance
721 // changed) and OnPaint() doesn't redraw the window while it is set which
722 // allows to minimize the number of repaintings when a lot of items are
723 // being added. The real repainting occurs only after the next OnIdle()
727 wxBrush
*m_highlightBrush
;
728 wxColour
*m_highlightColour
;
731 wxImageList
*m_small_image_list
;
732 wxImageList
*m_normal_image_list
;
734 int m_normal_spacing
;
738 wxTimer
*m_renameTimer
;
740 wxString m_renameRes
;
745 // for double click logic
746 size_t m_lineLastClicked
,
747 m_lineBeforeLastClicked
;
750 // the total count of items in a virtual list control
753 // the object maintaining the items selection state, only used in virtual
755 wxSelectionStore m_selStore
;
757 // common part of all ctors
760 // intiialize m_[xy]Scroll
761 void InitScrolling();
763 // get the line data for the given index
764 wxListLineData
*GetLine(size_t n
) const
766 wxASSERT_MSG( n
!= (size_t)-1, _T("invalid line index") );
770 wxConstCast(this, wxListMainWindow
)->CacheLineData(n
);
778 // get a dummy line which can be used for geometry calculations and such:
779 // you must use GetLine() if you want to really draw the line
780 wxListLineData
*GetDummyLine() const;
782 // cache the line data of the n-th line in m_lines[0]
783 void CacheLineData(size_t line
);
785 // get the range of visible lines
786 void GetVisibleLinesRange(size_t *from
, size_t *to
);
788 // force us to recalculate the range of visible lines
789 void ResetVisibleLinesRange() { m_lineFrom
= (size_t)-1; }
791 // get the colour to be used for drawing the rules
792 wxColour
GetRuleColour() const
797 return wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DLIGHT
);
802 // initialize the current item if needed
803 void UpdateCurrent();
805 // delete all items but don't refresh: called from dtor
806 void DoDeleteAllItems();
808 // called when an item is [un]focuded, i.e. becomes [not] current
811 void OnFocusLine( size_t line
);
812 void OnUnfocusLine( size_t line
);
814 // the height of one line using the current font
815 wxCoord m_lineHeight
;
817 // the total header width or 0 if not calculated yet
818 wxCoord m_headerWidth
;
820 // the first and last lines being shown on screen right now (inclusive),
821 // both may be -1 if they must be calculated so never access them directly:
822 // use GetVisibleLinesRange() above instead
826 DECLARE_DYNAMIC_CLASS(wxListMainWindow
);
827 DECLARE_EVENT_TABLE()
830 // ============================================================================
832 // ============================================================================
834 // ----------------------------------------------------------------------------
836 // ----------------------------------------------------------------------------
838 bool wxSelectionStore::IsSelected(size_t item
) const
840 bool isSel
= m_itemsSel
.Index(item
) != wxNOT_FOUND
;
842 // if the default state is to be selected, being in m_itemsSel means that
843 // the item is not selected, so we have to inverse the logic
844 return m_defaultState
? !isSel
: isSel
;
847 bool wxSelectionStore::SelectItem(size_t item
, bool select
)
849 // search for the item ourselves as like this we get the index where to
850 // insert it later if needed, so we do only one search in the array instead
851 // of two (adding item to a sorted array requires a search)
852 size_t index
= m_itemsSel
.IndexForInsert(item
);
853 bool isSel
= index
< m_itemsSel
.GetCount() && m_itemsSel
[index
] == item
;
855 if ( select
!= m_defaultState
)
859 m_itemsSel
.AddAt(item
, index
);
864 else // reset to default state
868 m_itemsSel
.RemoveAt(index
);
876 bool wxSelectionStore::SelectRange(size_t itemFrom
, size_t itemTo
,
878 wxArrayInt
*itemsChanged
)
880 // 100 is hardcoded but it shouldn't matter much: the important thing is
881 // that we don't refresh everything when really few (e.g. 1 or 2) items
883 static const size_t MANY_ITEMS
= 100;
885 wxASSERT_MSG( itemFrom
<= itemTo
, _T("should be in order") );
887 // are we going to have more [un]selected items than the other ones?
888 if ( itemTo
- itemFrom
> m_count
/2 )
890 if ( select
!= m_defaultState
)
892 // the default state now becomes the same as 'select'
893 m_defaultState
= select
;
895 // so all the old selections (which had state select) shouldn't be
896 // selected any more, but all the other ones should
897 wxIndexArray selOld
= m_itemsSel
;
900 // TODO: it should be possible to optimize the searches a bit
901 // knowing the possible range
904 for ( item
= 0; item
< itemFrom
; item
++ )
906 if ( selOld
.Index(item
) == wxNOT_FOUND
)
907 m_itemsSel
.Add(item
);
910 for ( item
= itemTo
+ 1; item
< m_count
; item
++ )
912 if ( selOld
.Index(item
) == wxNOT_FOUND
)
913 m_itemsSel
.Add(item
);
916 // many items (> half) changed state
919 else // select == m_defaultState
921 // get the inclusive range of items between itemFrom and itemTo
922 size_t count
= m_itemsSel
.GetCount(),
923 start
= m_itemsSel
.IndexForInsert(itemFrom
),
924 end
= m_itemsSel
.IndexForInsert(itemTo
);
926 if ( start
== count
|| m_itemsSel
[start
] < itemFrom
)
931 if ( end
== count
|| m_itemsSel
[end
] > itemTo
)
938 // delete all of them (from end to avoid changing indices)
939 for ( int i
= end
; i
>= (int)start
; i
-- )
943 if ( itemsChanged
->GetCount() > MANY_ITEMS
)
945 // stop counting (see comment below)
949 itemsChanged
->Add(m_itemsSel
[i
]);
952 m_itemsSel
.RemoveAt(i
);
957 else // "few" items change state
961 itemsChanged
->Empty();
964 // just add the items to the selection
965 for ( size_t item
= itemFrom
; item
<= itemTo
; item
++ )
967 if ( SelectItem(item
, select
) && itemsChanged
)
969 itemsChanged
->Add(item
);
971 if ( itemsChanged
->GetCount() > MANY_ITEMS
)
973 // stop counting them, we'll just eat gobs of memory
974 // for nothing at all - faster to refresh everything in
982 // we set it to NULL if there are many items changing state
983 return itemsChanged
!= NULL
;
986 void wxSelectionStore::OnItemDelete(size_t item
)
988 size_t count
= m_itemsSel
.GetCount(),
989 i
= m_itemsSel
.IndexForInsert(item
);
991 if ( i
< count
&& m_itemsSel
[i
] == item
)
993 // this item itself was in m_itemsSel, remove it from there
994 m_itemsSel
.RemoveAt(i
);
999 // and adjust the index of all which follow it
1002 // all following elements must be greater than the one we deleted
1003 wxASSERT_MSG( m_itemsSel
[i
] > item
, _T("logic error") );
1009 //-----------------------------------------------------------------------------
1011 //-----------------------------------------------------------------------------
1013 wxListItemData::~wxListItemData()
1015 // in the virtual list control the attributes are managed by the main
1016 // program, so don't delete them
1017 if ( !m_owner
->IsVirtual() )
1025 void wxListItemData::Init()
1033 wxListItemData::wxListItemData(wxListMainWindow
*owner
)
1039 if ( owner
->InReportView() )
1045 m_rect
= new wxRect
;
1049 void wxListItemData::SetItem( const wxListItem
&info
)
1051 if ( info
.m_mask
& wxLIST_MASK_TEXT
)
1052 SetText(info
.m_text
);
1053 if ( info
.m_mask
& wxLIST_MASK_IMAGE
)
1054 m_image
= info
.m_image
;
1055 if ( info
.m_mask
& wxLIST_MASK_DATA
)
1056 m_data
= info
.m_data
;
1058 if ( info
.HasAttributes() )
1061 *m_attr
= *info
.GetAttributes();
1063 m_attr
= new wxListItemAttr(*info
.GetAttributes());
1071 m_rect
->width
= info
.m_width
;
1075 void wxListItemData::SetPosition( int x
, int y
)
1077 wxCHECK_RET( m_rect
, _T("unexpected SetPosition() call") );
1083 void wxListItemData::SetSize( int width
, int height
)
1085 wxCHECK_RET( m_rect
, _T("unexpected SetSize() call") );
1088 m_rect
->width
= width
;
1090 m_rect
->height
= height
;
1093 bool wxListItemData::IsHit( int x
, int y
) const
1095 wxCHECK_MSG( m_rect
, FALSE
, _T("can't be called in this mode") );
1097 return wxRect(GetX(), GetY(), GetWidth(), GetHeight()).Inside(x
, y
);
1100 int wxListItemData::GetX() const
1102 wxCHECK_MSG( m_rect
, 0, _T("can't be called in this mode") );
1107 int wxListItemData::GetY() const
1109 wxCHECK_MSG( m_rect
, 0, _T("can't be called in this mode") );
1114 int wxListItemData::GetWidth() const
1116 wxCHECK_MSG( m_rect
, 0, _T("can't be called in this mode") );
1118 return m_rect
->width
;
1121 int wxListItemData::GetHeight() const
1123 wxCHECK_MSG( m_rect
, 0, _T("can't be called in this mode") );
1125 return m_rect
->height
;
1128 void wxListItemData::GetItem( wxListItem
&info
) const
1130 info
.m_text
= m_text
;
1131 info
.m_image
= m_image
;
1132 info
.m_data
= m_data
;
1136 if ( m_attr
->HasTextColour() )
1137 info
.SetTextColour(m_attr
->GetTextColour());
1138 if ( m_attr
->HasBackgroundColour() )
1139 info
.SetBackgroundColour(m_attr
->GetBackgroundColour());
1140 if ( m_attr
->HasFont() )
1141 info
.SetFont(m_attr
->GetFont());
1145 //-----------------------------------------------------------------------------
1147 //-----------------------------------------------------------------------------
1149 IMPLEMENT_DYNAMIC_CLASS(wxListHeaderData
,wxObject
);
1151 wxListHeaderData::wxListHeaderData()
1162 wxListHeaderData::wxListHeaderData( const wxListItem
&item
)
1170 void wxListHeaderData::SetItem( const wxListItem
&item
)
1172 m_mask
= item
.m_mask
;
1173 m_text
= item
.m_text
;
1174 m_image
= item
.m_image
;
1175 m_format
= item
.m_format
;
1177 SetWidth(item
.m_width
);
1180 void wxListHeaderData::SetPosition( int x
, int y
)
1186 void wxListHeaderData::SetHeight( int h
)
1191 void wxListHeaderData::SetWidth( int w
)
1195 m_width
= WIDTH_COL_DEFAULT
;
1196 if (m_width
< WIDTH_COL_MIN
)
1197 m_width
= WIDTH_COL_MIN
;
1200 void wxListHeaderData::SetFormat( int format
)
1205 bool wxListHeaderData::HasImage() const
1207 return (m_image
!= 0);
1210 bool wxListHeaderData::IsHit( int x
, int y
) const
1212 return ((x
>= m_xpos
) && (x
<= m_xpos
+m_width
) && (y
>= m_ypos
) && (y
<= m_ypos
+m_height
));
1215 void wxListHeaderData::GetItem( wxListItem
&item
)
1217 item
.m_mask
= m_mask
;
1218 item
.m_text
= m_text
;
1219 item
.m_image
= m_image
;
1220 item
.m_format
= m_format
;
1221 item
.m_width
= m_width
;
1224 int wxListHeaderData::GetImage() const
1229 int wxListHeaderData::GetWidth() const
1234 int wxListHeaderData::GetFormat() const
1239 //-----------------------------------------------------------------------------
1241 //-----------------------------------------------------------------------------
1243 inline int wxListLineData::GetMode() const
1245 return m_owner
->GetListCtrl()->GetWindowStyleFlag() & wxLC_MASK_TYPE
;
1248 inline bool wxListLineData::InReportView() const
1250 return m_owner
->HasFlag(wxLC_REPORT
);
1253 inline bool wxListLineData::IsVirtual() const
1255 return m_owner
->IsVirtual();
1258 wxListLineData::wxListLineData( wxListMainWindow
*owner
)
1261 m_items
.DeleteContents( TRUE
);
1263 if ( InReportView() )
1269 m_gi
= new GeometryInfo
;
1272 m_highlighted
= FALSE
;
1274 InitItems( GetMode() == wxLC_REPORT
? m_owner
->GetColumnCount() : 1 );
1277 void wxListLineData::CalculateSize( wxDC
*dc
, int spacing
)
1279 wxListItemDataList::Node
*node
= m_items
.GetFirst();
1280 wxCHECK_RET( node
, _T("no subitems at all??") );
1282 wxListItemData
*item
= node
->GetData();
1284 switch ( GetMode() )
1287 case wxLC_SMALL_ICON
:
1289 m_gi
->m_rectAll
.width
= spacing
;
1291 wxString s
= item
->GetText();
1297 m_gi
->m_rectLabel
.width
=
1298 m_gi
->m_rectLabel
.height
= 0;
1302 dc
->GetTextExtent( s
, &lw
, &lh
);
1303 if (lh
< SCROLL_UNIT_Y
)
1308 m_gi
->m_rectAll
.height
= spacing
+ lh
;
1310 m_gi
->m_rectAll
.width
= lw
;
1312 m_gi
->m_rectLabel
.width
= lw
;
1313 m_gi
->m_rectLabel
.height
= lh
;
1316 if (item
->HasImage())
1319 m_owner
->GetImageSize( item
->GetImage(), w
, h
);
1320 m_gi
->m_rectIcon
.width
= w
+ 8;
1321 m_gi
->m_rectIcon
.height
= h
+ 8;
1323 if ( m_gi
->m_rectIcon
.width
> m_gi
->m_rectAll
.width
)
1324 m_gi
->m_rectAll
.width
= m_gi
->m_rectIcon
.width
;
1325 if ( m_gi
->m_rectIcon
.height
+ lh
> m_gi
->m_rectAll
.height
- 4 )
1326 m_gi
->m_rectAll
.height
= m_gi
->m_rectIcon
.height
+ lh
+ 4;
1329 if ( item
->HasText() )
1331 m_gi
->m_rectHighlight
.width
= m_gi
->m_rectLabel
.width
;
1332 m_gi
->m_rectHighlight
.height
= m_gi
->m_rectLabel
.height
;
1334 else // no text, highlight the icon
1336 m_gi
->m_rectHighlight
.width
= m_gi
->m_rectIcon
.width
;
1337 m_gi
->m_rectHighlight
.height
= m_gi
->m_rectIcon
.height
;
1344 wxString s
= item
->GetTextForMeasuring();
1347 dc
->GetTextExtent( s
, &lw
, &lh
);
1348 if (lh
< SCROLL_UNIT_Y
)
1353 m_gi
->m_rectLabel
.width
= lw
;
1354 m_gi
->m_rectLabel
.height
= lh
;
1356 m_gi
->m_rectAll
.width
= lw
;
1357 m_gi
->m_rectAll
.height
= lh
;
1359 if (item
->HasImage())
1362 m_owner
->GetImageSize( item
->GetImage(), w
, h
);
1363 m_gi
->m_rectIcon
.width
= w
;
1364 m_gi
->m_rectIcon
.height
= h
;
1366 m_gi
->m_rectAll
.width
+= 4 + w
;
1367 if (h
> m_gi
->m_rectAll
.height
)
1368 m_gi
->m_rectAll
.height
= h
;
1371 m_gi
->m_rectHighlight
.width
= m_gi
->m_rectAll
.width
;
1372 m_gi
->m_rectHighlight
.height
= m_gi
->m_rectAll
.height
;
1377 wxFAIL_MSG( _T("unexpected call to SetSize") );
1381 wxFAIL_MSG( _T("unknown mode") );
1385 void wxListLineData::SetPosition( int x
, int y
,
1389 wxListItemDataList::Node
*node
= m_items
.GetFirst();
1390 wxCHECK_RET( node
, _T("no subitems at all??") );
1392 wxListItemData
*item
= node
->GetData();
1394 switch ( GetMode() )
1397 case wxLC_SMALL_ICON
:
1398 m_gi
->m_rectAll
.x
= x
;
1399 m_gi
->m_rectAll
.y
= y
;
1401 if ( item
->HasImage() )
1403 m_gi
->m_rectIcon
.x
= m_gi
->m_rectAll
.x
+ 4
1404 + (spacing
- m_gi
->m_rectIcon
.width
)/2;
1405 m_gi
->m_rectIcon
.y
= m_gi
->m_rectAll
.y
+ 4;
1408 if ( item
->HasText() )
1410 if (m_gi
->m_rectAll
.width
> spacing
)
1411 m_gi
->m_rectLabel
.x
= m_gi
->m_rectAll
.x
+ 2;
1413 m_gi
->m_rectLabel
.x
= m_gi
->m_rectAll
.x
+ 2 + (spacing
/2) - (m_gi
->m_rectLabel
.width
/2);
1414 m_gi
->m_rectLabel
.y
= m_gi
->m_rectAll
.y
+ m_gi
->m_rectAll
.height
+ 2 - m_gi
->m_rectLabel
.height
;
1415 m_gi
->m_rectHighlight
.x
= m_gi
->m_rectLabel
.x
- 2;
1416 m_gi
->m_rectHighlight
.y
= m_gi
->m_rectLabel
.y
- 2;
1418 else // no text, highlight the icon
1420 m_gi
->m_rectHighlight
.x
= m_gi
->m_rectIcon
.x
- 4;
1421 m_gi
->m_rectHighlight
.y
= m_gi
->m_rectIcon
.y
- 4;
1426 m_gi
->m_rectAll
.x
= x
;
1427 m_gi
->m_rectAll
.y
= y
;
1429 m_gi
->m_rectHighlight
.x
= m_gi
->m_rectAll
.x
;
1430 m_gi
->m_rectHighlight
.y
= m_gi
->m_rectAll
.y
;
1431 m_gi
->m_rectLabel
.y
= m_gi
->m_rectAll
.y
+ 2;
1433 if (item
->HasImage())
1435 m_gi
->m_rectIcon
.x
= m_gi
->m_rectAll
.x
+ 2;
1436 m_gi
->m_rectIcon
.y
= m_gi
->m_rectAll
.y
+ 2;
1437 m_gi
->m_rectLabel
.x
= m_gi
->m_rectAll
.x
+ 6 + m_gi
->m_rectIcon
.width
;
1441 m_gi
->m_rectLabel
.x
= m_gi
->m_rectAll
.x
+ 2;
1446 wxFAIL_MSG( _T("unexpected call to SetPosition") );
1450 wxFAIL_MSG( _T("unknown mode") );
1454 void wxListLineData::InitItems( int num
)
1456 for (int i
= 0; i
< num
; i
++)
1457 m_items
.Append( new wxListItemData(m_owner
) );
1460 void wxListLineData::SetItem( int index
, const wxListItem
&info
)
1462 wxListItemDataList::Node
*node
= m_items
.Item( index
);
1463 wxCHECK_RET( node
, _T("invalid column index in SetItem") );
1465 wxListItemData
*item
= node
->GetData();
1466 item
->SetItem( info
);
1469 void wxListLineData::GetItem( int index
, wxListItem
&info
)
1471 wxListItemDataList::Node
*node
= m_items
.Item( index
);
1474 wxListItemData
*item
= node
->GetData();
1475 item
->GetItem( info
);
1479 wxString
wxListLineData::GetText(int index
) const
1483 wxListItemDataList::Node
*node
= m_items
.Item( index
);
1486 wxListItemData
*item
= node
->GetData();
1487 s
= item
->GetText();
1493 void wxListLineData::SetText( int index
, const wxString s
)
1495 wxListItemDataList::Node
*node
= m_items
.Item( index
);
1498 wxListItemData
*item
= node
->GetData();
1503 void wxListLineData::SetImage( int index
, int image
)
1505 wxListItemDataList::Node
*node
= m_items
.Item( index
);
1506 wxCHECK_RET( node
, _T("invalid column index in SetImage()") );
1508 wxListItemData
*item
= node
->GetData();
1509 item
->SetImage(image
);
1512 int wxListLineData::GetImage( int index
) const
1514 wxListItemDataList::Node
*node
= m_items
.Item( index
);
1515 wxCHECK_MSG( node
, -1, _T("invalid column index in GetImage()") );
1517 wxListItemData
*item
= node
->GetData();
1518 return item
->GetImage();
1521 wxListItemAttr
*wxListLineData::GetAttr() const
1523 wxListItemDataList::Node
*node
= m_items
.GetFirst();
1524 wxCHECK_MSG( node
, NULL
, _T("invalid column index in GetAttr()") );
1526 wxListItemData
*item
= node
->GetData();
1527 return item
->GetAttr();
1530 void wxListLineData::SetAttr(wxListItemAttr
*attr
)
1532 wxListItemDataList::Node
*node
= m_items
.GetFirst();
1533 wxCHECK_RET( node
, _T("invalid column index in SetAttr()") );
1535 wxListItemData
*item
= node
->GetData();
1536 item
->SetAttr(attr
);
1539 bool wxListLineData::SetAttributes(wxDC
*dc
,
1540 const wxListItemAttr
*attr
,
1543 wxWindow
*listctrl
= m_owner
->GetParent();
1547 // don't use foreground colour for drawing highlighted items - this might
1548 // make them completely invisible (and there is no way to do bit
1549 // arithmetics on wxColour, unfortunately)
1553 colText
= wxSystemSettings::GetSystemColour(wxSYS_COLOUR_HIGHLIGHTTEXT
);
1557 if ( attr
&& attr
->HasTextColour() )
1559 colText
= attr
->GetTextColour();
1563 colText
= listctrl
->GetForegroundColour();
1567 dc
->SetTextForeground(colText
);
1571 if ( attr
&& attr
->HasFont() )
1573 font
= attr
->GetFont();
1577 font
= listctrl
->GetFont();
1583 bool hasBgCol
= attr
&& attr
->HasBackgroundColour();
1584 if ( highlighted
|| hasBgCol
)
1588 dc
->SetBrush( *m_owner
->m_highlightBrush
);
1592 dc
->SetBrush(wxBrush(attr
->GetBackgroundColour(), wxSOLID
));
1595 dc
->SetPen( *wxTRANSPARENT_PEN
);
1603 void wxListLineData::Draw( wxDC
*dc
)
1605 wxListItemDataList::Node
*node
= m_items
.GetFirst();
1606 wxCHECK_RET( node
, _T("no subitems at all??") );
1608 bool highlighted
= IsHighlighted();
1610 wxListItemAttr
*attr
= GetAttr();
1612 if ( SetAttributes(dc
, attr
, highlighted
) )
1614 dc
->DrawRectangle( m_gi
->m_rectHighlight
);
1617 wxListItemData
*item
= node
->GetData();
1618 if (item
->HasImage())
1620 wxRect rectIcon
= m_gi
->m_rectIcon
;
1621 m_owner
->DrawImage( item
->GetImage(), dc
,
1622 rectIcon
.x
, rectIcon
.y
);
1625 if (item
->HasText())
1627 wxRect rectLabel
= m_gi
->m_rectLabel
;
1629 wxDCClipper
clipper(*dc
, rectLabel
);
1630 dc
->DrawText( item
->GetText(), rectLabel
.x
, rectLabel
.y
);
1634 void wxListLineData::DrawInReportMode( wxDC
*dc
,
1636 const wxRect
& rectHL
,
1639 // TODO: later we should support setting different attributes for
1640 // different columns - to do it, just add "col" argument to
1641 // GetAttr() and move these lines into the loop below
1642 wxListItemAttr
*attr
= GetAttr();
1643 if ( SetAttributes(dc
, attr
, highlighted
) )
1645 dc
->DrawRectangle( rectHL
);
1648 wxListItemDataList::Node
*node
= m_items
.GetFirst();
1649 wxCHECK_RET( node
, _T("no subitems at all??") );
1652 wxCoord x
= rect
.x
+ HEADER_OFFSET_X
,
1653 y
= rect
.y
+ (LINE_SPACING
+ EXTRA_HEIGHT
) / 2;
1657 wxListItemData
*item
= node
->GetData();
1659 int width
= m_owner
->GetColumnWidth(col
++);
1663 if ( item
->HasImage() )
1666 m_owner
->DrawImage( item
->GetImage(), dc
, xOld
, y
);
1667 m_owner
->GetImageSize( item
->GetImage(), ix
, iy
);
1669 ix
+= IMAGE_MARGIN_IN_REPORT_MODE
;
1675 wxDCClipper
clipper(*dc
, xOld
, y
, width
, rect
.height
);
1677 if ( item
->HasText() )
1679 dc
->DrawText( item
->GetText(), xOld
, y
);
1682 node
= node
->GetNext();
1686 bool wxListLineData::Highlight( bool on
)
1688 wxCHECK_MSG( !m_owner
->IsVirtual(), FALSE
, _T("unexpected call to Highlight") );
1690 if ( on
== m_highlighted
)
1698 void wxListLineData::ReverseHighlight( void )
1700 Highlight(!IsHighlighted());
1703 //-----------------------------------------------------------------------------
1704 // wxListHeaderWindow
1705 //-----------------------------------------------------------------------------
1707 IMPLEMENT_DYNAMIC_CLASS(wxListHeaderWindow
,wxWindow
);
1709 BEGIN_EVENT_TABLE(wxListHeaderWindow
,wxWindow
)
1710 EVT_PAINT (wxListHeaderWindow::OnPaint
)
1711 EVT_MOUSE_EVENTS (wxListHeaderWindow::OnMouse
)
1712 EVT_SET_FOCUS (wxListHeaderWindow::OnSetFocus
)
1715 wxListHeaderWindow::wxListHeaderWindow( void )
1717 m_owner
= (wxListMainWindow
*) NULL
;
1718 m_currentCursor
= (wxCursor
*) NULL
;
1719 m_resizeCursor
= (wxCursor
*) NULL
;
1720 m_isDragging
= FALSE
;
1723 wxListHeaderWindow::wxListHeaderWindow( wxWindow
*win
, wxWindowID id
, wxListMainWindow
*owner
,
1724 const wxPoint
&pos
, const wxSize
&size
,
1725 long style
, const wxString
&name
) :
1726 wxWindow( win
, id
, pos
, size
, style
, name
)
1729 // m_currentCursor = wxSTANDARD_CURSOR;
1730 m_currentCursor
= (wxCursor
*) NULL
;
1731 m_resizeCursor
= new wxCursor( wxCURSOR_SIZEWE
);
1732 m_isDragging
= FALSE
;
1735 SetBackgroundColour( wxSystemSettings::GetSystemColour( wxSYS_COLOUR_BTNFACE
) );
1738 wxListHeaderWindow::~wxListHeaderWindow( void )
1740 delete m_resizeCursor
;
1743 void wxListHeaderWindow::DoDrawRect( wxDC
*dc
, int x
, int y
, int w
, int h
)
1746 GtkStateType state
= m_parent
->IsEnabled() ? GTK_STATE_NORMAL
1747 : GTK_STATE_INSENSITIVE
;
1749 x
= dc
->XLOG2DEV( x
);
1751 gtk_paint_box (m_wxwindow
->style
, GTK_PIZZA(m_wxwindow
)->bin_window
,
1752 state
, GTK_SHADOW_OUT
,
1753 (GdkRectangle
*) NULL
, m_wxwindow
, "button",
1754 x
-1, y
-1, w
+2, h
+2);
1755 #elif defined( __WXMAC__ )
1756 const int m_corner
= 1;
1758 dc
->SetBrush( *wxTRANSPARENT_BRUSH
);
1760 dc
->SetPen( wxPen( wxSystemSettings::GetSystemColour( wxSYS_COLOUR_BTNSHADOW
) , 1 , wxSOLID
) );
1761 dc
->DrawLine( x
+w
-m_corner
+1, y
, x
+w
, y
+h
); // right (outer)
1762 dc
->DrawRectangle( x
, y
+h
, w
+1, 1 ); // bottom (outer)
1764 wxPen
pen( wxColour( 0x88 , 0x88 , 0x88 ), 1, wxSOLID
);
1767 dc
->DrawLine( x
+w
-m_corner
, y
, x
+w
-1, y
+h
); // right (inner)
1768 dc
->DrawRectangle( x
+1, y
+h
-1, w
-2, 1 ); // bottom (inner)
1770 dc
->SetPen( *wxWHITE_PEN
);
1771 dc
->DrawRectangle( x
, y
, w
-m_corner
+1, 1 ); // top (outer)
1772 dc
->DrawRectangle( x
, y
, 1, h
); // left (outer)
1773 dc
->DrawLine( x
, y
+h
-1, x
+1, y
+h
-1 );
1774 dc
->DrawLine( x
+w
-1, y
, x
+w
-1, y
+1 );
1776 const int m_corner
= 1;
1778 dc
->SetBrush( *wxTRANSPARENT_BRUSH
);
1780 dc
->SetPen( *wxBLACK_PEN
);
1781 dc
->DrawLine( x
+w
-m_corner
+1, y
, x
+w
, y
+h
); // right (outer)
1782 dc
->DrawRectangle( x
, y
+h
, w
+1, 1 ); // bottom (outer)
1784 wxPen
pen( wxSystemSettings::GetSystemColour( wxSYS_COLOUR_BTNSHADOW
), 1, wxSOLID
);
1787 dc
->DrawLine( x
+w
-m_corner
, y
, x
+w
-1, y
+h
); // right (inner)
1788 dc
->DrawRectangle( x
+1, y
+h
-1, w
-2, 1 ); // bottom (inner)
1790 dc
->SetPen( *wxWHITE_PEN
);
1791 dc
->DrawRectangle( x
, y
, w
-m_corner
+1, 1 ); // top (outer)
1792 dc
->DrawRectangle( x
, y
, 1, h
); // left (outer)
1793 dc
->DrawLine( x
, y
+h
-1, x
+1, y
+h
-1 );
1794 dc
->DrawLine( x
+w
-1, y
, x
+w
-1, y
+1 );
1798 // shift the DC origin to match the position of the main window horz
1799 // scrollbar: this allows us to always use logical coords
1800 void wxListHeaderWindow::AdjustDC(wxDC
& dc
)
1803 m_owner
->GetScrollPixelsPerUnit( &xpix
, NULL
);
1806 m_owner
->GetViewStart( &x
, NULL
);
1808 // account for the horz scrollbar offset
1809 dc
.SetDeviceOrigin( -x
* xpix
, 0 );
1812 void wxListHeaderWindow::OnPaint( wxPaintEvent
&WXUNUSED(event
) )
1815 wxClientDC
dc( this );
1817 wxPaintDC
dc( this );
1825 dc
.SetFont( GetFont() );
1827 // width and height of the entire header window
1829 GetClientSize( &w
, &h
);
1830 m_owner
->CalcUnscrolledPosition(w
, 0, &w
, NULL
);
1832 dc
.SetBackgroundMode(wxTRANSPARENT
);
1834 // do *not* use the listctrl colour for headers - one day we will have a
1835 // function to set it separately
1836 //dc.SetTextForeground( *wxBLACK );
1837 dc
.SetTextForeground(wxSystemSettings::
1838 GetSystemColour( wxSYS_COLOUR_WINDOWTEXT
));
1840 int x
= HEADER_OFFSET_X
;
1842 int numColumns
= m_owner
->GetColumnCount();
1844 for (int i
= 0; i
< numColumns
; i
++)
1846 m_owner
->GetColumn( i
, item
);
1847 int wCol
= item
.m_width
;
1848 int cw
= wCol
- 2; // the width of the rect to draw
1850 int xEnd
= x
+ wCol
;
1852 dc
.SetPen( *wxWHITE_PEN
);
1854 DoDrawRect( &dc
, x
, HEADER_OFFSET_Y
, cw
, h
-2 );
1855 wxDCClipper
clipper(dc
, x
, HEADER_OFFSET_Y
, cw
-5, h
-4 );
1857 dc
.DrawText( item
.GetText(),
1858 x
+ EXTRA_WIDTH
, HEADER_OFFSET_Y
+ EXTRA_HEIGHT
);
1868 void wxListHeaderWindow::DrawCurrent()
1870 int x1
= m_currentX
;
1872 ClientToScreen( &x1
, &y1
);
1874 int x2
= m_currentX
-1;
1876 m_owner
->GetClientSize( NULL
, &y2
);
1877 m_owner
->ClientToScreen( &x2
, &y2
);
1880 dc
.SetLogicalFunction( wxINVERT
);
1881 dc
.SetPen( wxPen( *wxBLACK
, 2, wxSOLID
) );
1882 dc
.SetBrush( *wxTRANSPARENT_BRUSH
);
1886 dc
.DrawLine( x1
, y1
, x2
, y2
);
1888 dc
.SetLogicalFunction( wxCOPY
);
1890 dc
.SetPen( wxNullPen
);
1891 dc
.SetBrush( wxNullBrush
);
1894 void wxListHeaderWindow::OnMouse( wxMouseEvent
&event
)
1896 // we want to work with logical coords
1898 m_owner
->CalcUnscrolledPosition(event
.GetX(), 0, &x
, NULL
);
1899 int y
= event
.GetY();
1903 // we don't draw the line beyond our window, but we allow dragging it
1906 GetClientSize( &w
, NULL
);
1907 m_owner
->CalcUnscrolledPosition(w
, 0, &w
, NULL
);
1910 // erase the line if it was drawn
1911 if ( m_currentX
< w
)
1914 if (event
.ButtonUp())
1917 m_isDragging
= FALSE
;
1919 m_owner
->SetColumnWidth( m_column
, m_currentX
- m_minX
);
1926 m_currentX
= m_minX
+ 7;
1928 // draw in the new location
1929 if ( m_currentX
< w
)
1933 else // not dragging
1936 bool hit_border
= FALSE
;
1938 // end of the current column
1941 // find the column where this event occured
1942 int countCol
= m_owner
->GetColumnCount();
1943 for (int col
= 0; col
< countCol
; col
++)
1945 xpos
+= m_owner
->GetColumnWidth( col
);
1948 if ( (abs(x
-xpos
) < 3) && (y
< 22) )
1950 // near the column border
1957 // inside the column
1964 if (event
.LeftDown())
1968 m_isDragging
= TRUE
;
1975 wxWindow
*parent
= GetParent();
1976 wxListEvent
le( wxEVT_COMMAND_LIST_COL_CLICK
, parent
->GetId() );
1977 le
.SetEventObject( parent
);
1978 le
.m_col
= m_column
;
1979 parent
->GetEventHandler()->ProcessEvent( le
);
1982 else if (event
.Moving())
1987 setCursor
= m_currentCursor
== wxSTANDARD_CURSOR
;
1988 m_currentCursor
= m_resizeCursor
;
1992 setCursor
= m_currentCursor
!= wxSTANDARD_CURSOR
;
1993 m_currentCursor
= wxSTANDARD_CURSOR
;
1997 SetCursor(*m_currentCursor
);
2002 void wxListHeaderWindow::OnSetFocus( wxFocusEvent
&WXUNUSED(event
) )
2004 m_owner
->SetFocus();
2007 //-----------------------------------------------------------------------------
2008 // wxListRenameTimer (internal)
2009 //-----------------------------------------------------------------------------
2011 wxListRenameTimer::wxListRenameTimer( wxListMainWindow
*owner
)
2016 void wxListRenameTimer::Notify()
2018 m_owner
->OnRenameTimer();
2021 //-----------------------------------------------------------------------------
2022 // wxListTextCtrl (internal)
2023 //-----------------------------------------------------------------------------
2025 IMPLEMENT_DYNAMIC_CLASS(wxListTextCtrl
,wxTextCtrl
);
2027 BEGIN_EVENT_TABLE(wxListTextCtrl
,wxTextCtrl
)
2028 EVT_CHAR (wxListTextCtrl::OnChar
)
2029 EVT_KEY_UP (wxListTextCtrl::OnKeyUp
)
2030 EVT_KILL_FOCUS (wxListTextCtrl::OnKillFocus
)
2033 wxListTextCtrl::wxListTextCtrl( wxWindow
*parent
,
2034 const wxWindowID id
,
2037 wxListMainWindow
*owner
,
2038 const wxString
&value
,
2042 const wxValidator
& validator
,
2043 const wxString
&name
)
2044 : wxTextCtrl( parent
, id
, value
, pos
, size
, style
, validator
, name
)
2049 (*m_accept
) = FALSE
;
2051 m_startValue
= value
;
2054 void wxListTextCtrl::OnChar( wxKeyEvent
&event
)
2056 if (event
.m_keyCode
== WXK_RETURN
)
2059 (*m_res
) = GetValue();
2061 if (!wxPendingDelete
.Member(this))
2062 wxPendingDelete
.Append(this);
2064 if ((*m_accept
) && ((*m_res
) != m_startValue
))
2065 m_owner
->OnRenameAccept();
2069 if (event
.m_keyCode
== WXK_ESCAPE
)
2071 (*m_accept
) = FALSE
;
2074 if (!wxPendingDelete
.Member(this))
2075 wxPendingDelete
.Append(this);
2083 void wxListTextCtrl::OnKeyUp( wxKeyEvent
&event
)
2085 // auto-grow the textctrl:
2086 wxSize parentSize
= m_owner
->GetSize();
2087 wxPoint myPos
= GetPosition();
2088 wxSize mySize
= GetSize();
2090 GetTextExtent(GetValue() + _T("MM"), &sx
, &sy
); // FIXME: MM??
2091 if (myPos
.x
+ sx
> parentSize
.x
)
2092 sx
= parentSize
.x
- myPos
.x
;
2100 void wxListTextCtrl::OnKillFocus( wxFocusEvent
&WXUNUSED(event
) )
2102 if (!wxPendingDelete
.Member(this))
2103 wxPendingDelete
.Append(this);
2105 if ((*m_accept
) && ((*m_res
) != m_startValue
))
2106 m_owner
->OnRenameAccept();
2109 //-----------------------------------------------------------------------------
2111 //-----------------------------------------------------------------------------
2113 IMPLEMENT_DYNAMIC_CLASS(wxListMainWindow
,wxScrolledWindow
);
2115 BEGIN_EVENT_TABLE(wxListMainWindow
,wxScrolledWindow
)
2116 EVT_PAINT (wxListMainWindow::OnPaint
)
2117 EVT_MOUSE_EVENTS (wxListMainWindow::OnMouse
)
2118 EVT_CHAR (wxListMainWindow::OnChar
)
2119 EVT_KEY_DOWN (wxListMainWindow::OnKeyDown
)
2120 EVT_SET_FOCUS (wxListMainWindow::OnSetFocus
)
2121 EVT_KILL_FOCUS (wxListMainWindow::OnKillFocus
)
2122 EVT_SCROLLWIN (wxListMainWindow::OnScroll
)
2125 void wxListMainWindow::Init()
2127 m_columns
.DeleteContents( TRUE
);
2131 m_lineTo
= (size_t)-1;
2137 m_small_image_list
= (wxImageList
*) NULL
;
2138 m_normal_image_list
= (wxImageList
*) NULL
;
2140 m_small_spacing
= 30;
2141 m_normal_spacing
= 40;
2145 m_isCreated
= FALSE
;
2147 m_lastOnSame
= FALSE
;
2148 m_renameTimer
= new wxListRenameTimer( this );
2149 m_renameAccept
= FALSE
;
2154 m_lineBeforeLastClicked
= (size_t)-1;
2157 void wxListMainWindow::InitScrolling()
2159 if ( HasFlag(wxLC_REPORT
) )
2161 m_xScroll
= SCROLL_UNIT_X
;
2162 m_yScroll
= SCROLL_UNIT_Y
;
2166 m_xScroll
= SCROLL_UNIT_Y
;
2171 wxListMainWindow::wxListMainWindow()
2175 m_highlightBrush
= (wxBrush
*) NULL
;
2181 wxListMainWindow::wxListMainWindow( wxWindow
*parent
,
2186 const wxString
&name
)
2187 : wxScrolledWindow( parent
, id
, pos
, size
,
2188 style
| wxHSCROLL
| wxVSCROLL
, name
)
2192 m_highlightBrush
= new wxBrush( wxSystemSettings::GetSystemColour(wxSYS_COLOUR_HIGHLIGHT
), wxSOLID
);
2197 SetScrollbars( m_xScroll
, m_yScroll
, 0, 0, 0, 0 );
2199 SetBackgroundColour( wxSystemSettings::GetSystemColour( wxSYS_COLOUR_LISTBOX
) );
2202 wxListMainWindow::~wxListMainWindow()
2206 delete m_highlightBrush
;
2208 delete m_renameTimer
;
2211 void wxListMainWindow::CacheLineData(size_t line
)
2213 wxListCtrl
*listctrl
= GetListCtrl();
2215 wxListLineData
*ld
= GetDummyLine();
2217 size_t countCol
= GetColumnCount();
2218 for ( size_t col
= 0; col
< countCol
; col
++ )
2220 ld
->SetText(col
, listctrl
->OnGetItemText(line
, col
));
2223 ld
->SetImage(listctrl
->OnGetItemImage(line
));
2224 ld
->SetAttr(listctrl
->OnGetItemAttr(line
));
2227 wxListLineData
*wxListMainWindow::GetDummyLine() const
2229 wxASSERT_MSG( !IsEmpty(), _T("invalid line index") );
2231 if ( m_lines
.IsEmpty() )
2233 // normal controls are supposed to have something in m_lines
2234 // already if it's not empty
2235 wxASSERT_MSG( IsVirtual(), _T("logic error") );
2237 wxListMainWindow
*self
= wxConstCast(this, wxListMainWindow
);
2238 wxListLineData
*line
= new wxListLineData(self
);
2239 self
->m_lines
.Add(line
);
2245 // ----------------------------------------------------------------------------
2246 // line geometry (report mode only)
2247 // ----------------------------------------------------------------------------
2249 wxCoord
wxListMainWindow::GetLineHeight() const
2251 wxASSERT_MSG( HasFlag(wxLC_REPORT
), _T("only works in report mode") );
2253 // we cache the line height as calling GetTextExtent() is slow
2254 if ( !m_lineHeight
)
2256 wxListMainWindow
*self
= wxConstCast(this, wxListMainWindow
);
2258 wxClientDC
dc( self
);
2259 dc
.SetFont( GetFont() );
2262 dc
.GetTextExtent(_T("H"), NULL
, &y
);
2264 if ( y
< SCROLL_UNIT_Y
)
2268 self
->m_lineHeight
= y
+ LINE_SPACING
;
2271 return m_lineHeight
;
2274 wxCoord
wxListMainWindow::GetLineY(size_t line
) const
2276 wxASSERT_MSG( HasFlag(wxLC_REPORT
), _T("only works in report mode") );
2278 return LINE_SPACING
+ line
*GetLineHeight();
2281 wxRect
wxListMainWindow::GetLineRect(size_t line
) const
2283 if ( !InReportView() )
2284 return GetLine(line
)->m_gi
->m_rectAll
;
2287 rect
.x
= HEADER_OFFSET_X
;
2288 rect
.y
= GetLineY(line
);
2289 rect
.width
= GetHeaderWidth();
2290 rect
.height
= GetLineHeight();
2295 wxRect
wxListMainWindow::GetLineLabelRect(size_t line
) const
2297 if ( !InReportView() )
2298 return GetLine(line
)->m_gi
->m_rectLabel
;
2301 rect
.x
= HEADER_OFFSET_X
;
2302 rect
.y
= GetLineY(line
);
2303 rect
.width
= GetColumnWidth(0);
2304 rect
.height
= GetLineHeight();
2309 wxRect
wxListMainWindow::GetLineIconRect(size_t line
) const
2311 if ( !InReportView() )
2312 return GetLine(line
)->m_gi
->m_rectIcon
;
2314 wxListLineData
*ld
= GetLine(line
);
2315 wxASSERT_MSG( ld
->HasImage(), _T("should have an image") );
2318 rect
.x
= HEADER_OFFSET_X
;
2319 rect
.y
= GetLineY(line
);
2320 GetImageSize(ld
->GetImage(), rect
.width
, rect
.height
);
2325 wxRect
wxListMainWindow::GetLineHighlightRect(size_t line
) const
2327 return InReportView() ? GetLineRect(line
)
2328 : GetLine(line
)->m_gi
->m_rectHighlight
;
2331 long wxListMainWindow::HitTestLine(size_t line
, int x
, int y
) const
2333 wxListLineData
*ld
= GetLine(line
);
2335 if ( ld
->HasImage() && GetLineIconRect(line
).Inside(x
, y
) )
2336 return wxLIST_HITTEST_ONITEMICON
;
2338 if ( ld
->HasText() )
2340 wxRect rect
= InReportView() ? GetLineRect(line
)
2341 : GetLineLabelRect(line
);
2343 if ( rect
.Inside(x
, y
) )
2344 return wxLIST_HITTEST_ONITEMLABEL
;
2350 // ----------------------------------------------------------------------------
2351 // highlight (selection) handling
2352 // ----------------------------------------------------------------------------
2354 bool wxListMainWindow::IsHighlighted(size_t line
) const
2358 return m_selStore
.IsSelected(line
);
2362 wxListLineData
*ld
= GetLine(line
);
2363 wxCHECK_MSG( ld
, FALSE
, _T("invalid index in IsHighlighted") );
2365 return ld
->IsHighlighted();
2369 void wxListMainWindow::HighlightLines( size_t lineFrom
,
2375 wxArrayInt linesChanged
;
2376 if ( !m_selStore
.SelectRange(lineFrom
, lineTo
, highlight
,
2379 // meny items changed state, refresh everything
2380 RefreshLines(lineFrom
, lineTo
);
2382 else // only a few items changed state, refresh only them
2384 size_t count
= linesChanged
.GetCount();
2385 for ( size_t n
= 0; n
< count
; n
++ )
2387 RefreshLine(linesChanged
[n
]);
2391 else // iterate over all items in non report view
2393 for ( size_t line
= lineFrom
; line
<= lineTo
; line
++ )
2395 if ( HighlightLine(line
, highlight
) )
2403 bool wxListMainWindow::HighlightLine( size_t line
, bool highlight
)
2409 changed
= m_selStore
.SelectItem(line
, highlight
);
2413 wxListLineData
*ld
= GetLine(line
);
2414 wxCHECK_MSG( ld
, FALSE
, _T("invalid index in IsHighlighted") );
2416 changed
= ld
->Highlight(highlight
);
2421 SendNotify( line
, highlight
? wxEVT_COMMAND_LIST_ITEM_SELECTED
2422 : wxEVT_COMMAND_LIST_ITEM_DESELECTED
);
2428 void wxListMainWindow::RefreshLine( size_t line
)
2430 if ( HasFlag(wxLC_REPORT
) )
2432 size_t visibleFrom
, visibleTo
;
2433 GetVisibleLinesRange(&visibleFrom
, &visibleTo
);
2435 if ( line
< visibleFrom
|| line
> visibleTo
)
2439 wxRect rect
= GetLineRect(line
);
2441 CalcScrolledPosition( rect
.x
, rect
.y
, &rect
.x
, &rect
.y
);
2442 RefreshRect( rect
);
2445 void wxListMainWindow::RefreshLines( size_t lineFrom
, size_t lineTo
)
2447 // we suppose that they are ordered by caller
2448 wxASSERT_MSG( lineFrom
<= lineTo
, _T("indices in disorder") );
2450 wxASSERT_MSG( lineTo
< GetItemCount(), _T("invalid line range") );
2452 if ( HasFlag(wxLC_REPORT
) )
2454 size_t visibleFrom
, visibleTo
;
2455 GetVisibleLinesRange(&visibleFrom
, &visibleTo
);
2457 if ( lineFrom
< visibleFrom
)
2458 lineFrom
= visibleFrom
;
2459 if ( lineTo
> visibleTo
)
2464 rect
.y
= GetLineY(lineFrom
);
2465 rect
.width
= GetClientSize().x
;
2466 rect
.height
= GetLineY(lineTo
) - rect
.y
+ GetLineHeight();
2468 CalcScrolledPosition( rect
.x
, rect
.y
, &rect
.x
, &rect
.y
);
2469 RefreshRect( rect
);
2473 // TODO: this should be optimized...
2474 for ( size_t line
= lineFrom
; line
<= lineTo
; line
++ )
2481 void wxListMainWindow::RefreshAfter( size_t lineFrom
)
2483 if ( HasFlag(wxLC_REPORT
) )
2486 GetVisibleLinesRange(&visibleFrom
, NULL
);
2488 if ( lineFrom
< visibleFrom
)
2489 lineFrom
= visibleFrom
;
2493 rect
.y
= GetLineY(lineFrom
);
2495 wxSize size
= GetClientSize();
2496 rect
.width
= size
.x
;
2497 // refresh till the bottom of the window
2498 rect
.height
= size
.y
- rect
.y
;
2500 CalcScrolledPosition( rect
.x
, rect
.y
, &rect
.x
, &rect
.y
);
2501 RefreshRect( rect
);
2505 // TODO: how to do it more efficiently?
2510 void wxListMainWindow::OnPaint( wxPaintEvent
&WXUNUSED(event
) )
2512 // Note: a wxPaintDC must be constructed even if no drawing is
2513 // done (a Windows requirement).
2514 wxPaintDC
dc( this );
2518 // empty control. nothing to draw
2524 // delay the repainting until we calculate all the items positions
2531 CalcScrolledPosition( 0, 0, &dev_x
, &dev_y
);
2535 dc
.SetFont( GetFont() );
2537 if ( HasFlag(wxLC_REPORT
) )
2539 int lineHeight
= GetLineHeight();
2541 size_t visibleFrom
, visibleTo
;
2542 GetVisibleLinesRange(&visibleFrom
, &visibleTo
);
2545 wxCoord xOrig
, yOrig
;
2546 CalcUnscrolledPosition(0, 0, &xOrig
, &yOrig
);
2548 // tell the caller cache to cache the data
2551 wxListEvent
evCache(wxEVT_COMMAND_LIST_CACHE_HINT
,
2552 GetParent()->GetId());
2553 evCache
.SetEventObject( GetParent() );
2554 evCache
.m_oldItemIndex
= visibleFrom
;
2555 evCache
.m_itemIndex
= visibleTo
;
2556 GetParent()->GetEventHandler()->ProcessEvent( evCache
);
2559 for ( size_t line
= visibleFrom
; line
<= visibleTo
; line
++ )
2561 rectLine
= GetLineRect(line
);
2563 if ( !IsExposed(rectLine
.x
- xOrig
, rectLine
.y
- yOrig
,
2564 rectLine
.width
, rectLine
.height
) )
2566 // don't redraw unaffected lines to avoid flicker
2570 GetLine(line
)->DrawInReportMode( &dc
,
2572 GetLineHighlightRect(line
),
2573 m_hasFocus
&& IsHighlighted(line
) );
2576 if ( HasFlag(wxLC_HRULES
) )
2578 wxPen
pen(GetRuleColour(), 1, wxSOLID
);
2579 wxSize clientSize
= GetClientSize();
2581 for ( size_t i
= visibleFrom
; i
<= visibleTo
; i
++ )
2584 dc
.SetBrush( *wxTRANSPARENT_BRUSH
);
2585 dc
.DrawLine(0 - dev_x
, i
*lineHeight
,
2586 clientSize
.x
- dev_x
, i
*lineHeight
);
2589 // Draw last horizontal rule
2590 if ( visibleTo
> visibleFrom
)
2593 dc
.SetBrush( *wxTRANSPARENT_BRUSH
);
2594 dc
.DrawLine(0 - dev_x
, m_lineTo
*lineHeight
,
2595 clientSize
.x
- dev_x
, m_lineTo
*lineHeight
);
2599 // Draw vertical rules if required
2600 if ( HasFlag(wxLC_VRULES
) && !IsEmpty() )
2602 wxPen
pen(GetRuleColour(), 1, wxSOLID
);
2605 wxRect firstItemRect
;
2606 wxRect lastItemRect
;
2607 GetItemRect(0, firstItemRect
);
2608 GetItemRect(GetItemCount() - 1, lastItemRect
);
2609 int x
= firstItemRect
.GetX();
2611 dc
.SetBrush(* wxTRANSPARENT_BRUSH
);
2612 for (col
= 0; col
< GetColumnCount(); col
++)
2614 int colWidth
= GetColumnWidth(col
);
2616 dc
.DrawLine(x
- dev_x
, firstItemRect
.GetY() - 1 - dev_y
,
2617 x
- dev_x
, lastItemRect
.GetBottom() + 1 - dev_y
);
2623 size_t count
= GetItemCount();
2624 for ( size_t i
= 0; i
< count
; i
++ )
2626 GetLine(i
)->Draw( &dc
);
2632 // don't draw rect outline under Max if we already have the background
2636 #endif // !__WXMAC__
2638 dc
.SetPen( *wxBLACK_PEN
);
2639 dc
.SetBrush( *wxTRANSPARENT_BRUSH
);
2640 dc
.DrawRectangle( GetLineHighlightRect(m_current
) );
2647 void wxListMainWindow::HighlightAll( bool on
)
2649 if ( IsSingleSel() )
2651 wxASSERT_MSG( !on
, _T("can't do this in a single sel control") );
2653 // we just have one item to turn off
2654 if ( HasCurrent() && IsHighlighted(m_current
) )
2656 HighlightLine(m_current
, FALSE
);
2657 RefreshLine(m_current
);
2662 HighlightLines(0, GetItemCount() - 1, on
);
2666 void wxListMainWindow::SendNotify( size_t line
,
2667 wxEventType command
,
2670 wxListEvent
le( command
, GetParent()->GetId() );
2671 le
.SetEventObject( GetParent() );
2672 le
.m_itemIndex
= line
;
2674 // set only for events which have position
2675 if ( point
!= wxDefaultPosition
)
2676 le
.m_pointDrag
= point
;
2678 // don't try to get the line info for virtual list controls: the main
2679 // program has it anyhow and if we did it would result in accessing all
2680 // the lines, even those which are not visible now and this is precisely
2681 // what we're trying to avoid
2682 if ( !IsVirtual() && (command
!= wxEVT_COMMAND_LIST_DELETE_ITEM
) )
2684 GetLine(line
)->GetItem( 0, le
.m_item
);
2686 //else: there may be no more such item
2688 GetParent()->GetEventHandler()->ProcessEvent( le
);
2691 void wxListMainWindow::OnFocusLine( size_t WXUNUSED(line
) )
2693 // SendNotify( line, wxEVT_COMMAND_LIST_ITEM_FOCUSSED );
2696 void wxListMainWindow::OnUnfocusLine( size_t WXUNUSED(line
) )
2698 // SendNotify( line, wxEVT_COMMAND_LIST_ITEM_UNFOCUSSED );
2701 void wxListMainWindow::EditLabel( long item
)
2703 wxCHECK_RET( (item
>= 0) && ((size_t)item
< GetItemCount()),
2704 wxT("wrong index in wxListCtrl::EditLabel()") );
2706 m_currentEdit
= (size_t)item
;
2708 wxListEvent
le( wxEVT_COMMAND_LIST_BEGIN_LABEL_EDIT
, GetParent()->GetId() );
2709 le
.SetEventObject( GetParent() );
2710 le
.m_itemIndex
= item
;
2711 wxListLineData
*data
= GetLine(m_currentEdit
);
2712 wxCHECK_RET( data
, _T("invalid index in EditLabel()") );
2713 data
->GetItem( 0, le
.m_item
);
2714 GetParent()->GetEventHandler()->ProcessEvent( le
);
2716 if (!le
.IsAllowed())
2719 // We have to call this here because the label in question might just have
2720 // been added and no screen update taken place.
2724 wxClientDC
dc(this);
2727 wxString s
= data
->GetText(0);
2728 wxRect rectLabel
= GetLineLabelRect(m_currentEdit
);
2730 rectLabel
.x
= dc
.LogicalToDeviceX( rectLabel
.x
);
2731 rectLabel
.y
= dc
.LogicalToDeviceY( rectLabel
.y
);
2733 wxListTextCtrl
*text
= new wxListTextCtrl
2740 wxPoint(rectLabel
.x
-4,rectLabel
.y
-4),
2741 wxSize(rectLabel
.width
+11,rectLabel
.height
+8)
2746 void wxListMainWindow::OnRenameTimer()
2748 wxCHECK_RET( HasCurrent(), wxT("unexpected rename timer") );
2750 EditLabel( m_current
);
2753 void wxListMainWindow::OnRenameAccept()
2755 wxListEvent
le( wxEVT_COMMAND_LIST_END_LABEL_EDIT
, GetParent()->GetId() );
2756 le
.SetEventObject( GetParent() );
2757 le
.m_itemIndex
= m_currentEdit
;
2759 wxListLineData
*data
= GetLine(m_currentEdit
);
2760 wxCHECK_RET( data
, _T("invalid index in OnRenameAccept()") );
2762 data
->GetItem( 0, le
.m_item
);
2763 le
.m_item
.m_text
= m_renameRes
;
2764 GetParent()->GetEventHandler()->ProcessEvent( le
);
2766 if (!le
.IsAllowed()) return;
2769 info
.m_mask
= wxLIST_MASK_TEXT
;
2770 info
.m_itemId
= le
.m_itemIndex
;
2771 info
.m_text
= m_renameRes
;
2772 info
.SetTextColour(le
.m_item
.GetTextColour());
2776 void wxListMainWindow::OnMouse( wxMouseEvent
&event
)
2778 event
.SetEventObject( GetParent() );
2779 if ( GetParent()->GetEventHandler()->ProcessEvent( event
) )
2782 if ( !HasCurrent() || IsEmpty() )
2788 if ( !(event
.Dragging() || event
.ButtonDown() || event
.LeftUp() ||
2789 event
.ButtonDClick()) )
2792 int x
= event
.GetX();
2793 int y
= event
.GetY();
2794 CalcUnscrolledPosition( x
, y
, &x
, &y
);
2796 // where did we hit it (if we did)?
2799 size_t count
= GetItemCount(),
2802 if ( HasFlag(wxLC_REPORT
) )
2804 current
= y
/ GetLineHeight();
2805 if ( current
< count
)
2806 hitResult
= HitTestLine(current
, x
, y
);
2810 // TODO: optimize it too! this is less simple than for report view but
2811 // enumerating all items is still not a way to do it!!
2812 for ( current
= 0; current
< count
; current
++ )
2814 hitResult
= HitTestLine(current
, x
, y
);
2820 if (event
.Dragging())
2822 if (m_dragCount
== 0)
2823 m_dragStart
= wxPoint(x
,y
);
2827 if (m_dragCount
!= 3)
2830 int command
= event
.RightIsDown() ? wxEVT_COMMAND_LIST_BEGIN_RDRAG
2831 : wxEVT_COMMAND_LIST_BEGIN_DRAG
;
2833 wxListEvent
le( command
, GetParent()->GetId() );
2834 le
.SetEventObject( GetParent() );
2835 le
.m_pointDrag
= m_dragStart
;
2836 GetParent()->GetEventHandler()->ProcessEvent( le
);
2847 // outside of any item
2851 bool forceClick
= FALSE
;
2852 if (event
.ButtonDClick())
2854 m_renameTimer
->Stop();
2855 m_lastOnSame
= FALSE
;
2857 if ( current
== m_lineBeforeLastClicked
)
2859 SendNotify( current
, wxEVT_COMMAND_LIST_ITEM_ACTIVATED
);
2865 // the first click was on another item, so don't interpret this as
2866 // a double click, but as a simple click instead
2871 if (event
.LeftUp() && m_lastOnSame
)
2873 if ((current
== m_current
) &&
2874 (hitResult
== wxLIST_HITTEST_ONITEMLABEL
) &&
2875 HasFlag(wxLC_EDIT_LABELS
) )
2877 m_renameTimer
->Start( 100, TRUE
);
2879 m_lastOnSame
= FALSE
;
2881 else if (event
.RightDown())
2883 SendNotify( current
, wxEVT_COMMAND_LIST_ITEM_RIGHT_CLICK
,
2884 event
.GetPosition() );
2886 else if (event
.MiddleDown())
2888 SendNotify( current
, wxEVT_COMMAND_LIST_ITEM_MIDDLE_CLICK
);
2890 else if ( event
.LeftDown() || forceClick
)
2892 m_lineBeforeLastClicked
= m_lineLastClicked
;
2893 m_lineLastClicked
= current
;
2895 size_t oldCurrent
= m_current
;
2897 if ( IsSingleSel() || !(event
.ControlDown() || event
.ShiftDown()) )
2899 HighlightAll( FALSE
);
2900 m_current
= current
;
2902 ReverseHighlight(m_current
);
2904 else // multi sel & either ctrl or shift is down
2906 if (event
.ControlDown())
2908 m_current
= current
;
2910 ReverseHighlight(m_current
);
2912 else if (event
.ShiftDown())
2914 m_current
= current
;
2916 size_t lineFrom
= oldCurrent
,
2919 if ( lineTo
< lineFrom
)
2922 lineFrom
= m_current
;
2925 HighlightLines(lineFrom
, lineTo
);
2927 else // !ctrl, !shift
2929 // test in the enclosing if should make it impossible
2930 wxFAIL_MSG( _T("how did we get here?") );
2934 if (m_current
!= oldCurrent
)
2936 RefreshLine( oldCurrent
);
2937 OnUnfocusLine( oldCurrent
);
2938 OnFocusLine( m_current
);
2941 // forceClick is only set if the previous click was on another item
2942 m_lastOnSame
= !forceClick
&& (m_current
== oldCurrent
);
2946 void wxListMainWindow::MoveToItem(size_t item
)
2948 if ( item
== (size_t)-1 )
2951 wxRect rect
= GetLineRect(item
);
2953 int client_w
, client_h
;
2954 GetClientSize( &client_w
, &client_h
);
2956 int view_x
= m_xScroll
*GetScrollPos( wxHORIZONTAL
);
2957 int view_y
= m_yScroll
*GetScrollPos( wxVERTICAL
);
2959 if ( HasFlag(wxLC_REPORT
) )
2961 // the next we need the range of lines shown it might be different, so
2963 ResetVisibleLinesRange();
2965 if (rect
.y
< view_y
)
2966 Scroll( -1, rect
.y
/m_yScroll
);
2967 if (rect
.y
+rect
.height
+5 > view_y
+client_h
)
2968 Scroll( -1, (rect
.y
+rect
.height
-client_h
+SCROLL_UNIT_Y
)/m_yScroll
);
2972 if (rect
.x
-view_x
< 5)
2973 Scroll( (rect
.x
-5)/m_xScroll
, -1 );
2974 if (rect
.x
+rect
.width
-5 > view_x
+client_w
)
2975 Scroll( (rect
.x
+rect
.width
-client_w
+SCROLL_UNIT_X
)/m_xScroll
, -1 );
2979 // ----------------------------------------------------------------------------
2980 // keyboard handling
2981 // ----------------------------------------------------------------------------
2983 void wxListMainWindow::OnArrowChar(size_t newCurrent
, const wxKeyEvent
& event
)
2985 wxCHECK_RET( newCurrent
< (size_t)GetItemCount(),
2986 _T("invalid item index in OnArrowChar()") );
2988 size_t oldCurrent
= m_current
;
2990 // in single selection we just ignore Shift as we can't select several
2992 if ( event
.ShiftDown() && !IsSingleSel() )
2994 m_current
= newCurrent
;
2996 // select all the items between the old and the new one
2997 if ( oldCurrent
> newCurrent
)
2999 newCurrent
= oldCurrent
;
3000 oldCurrent
= m_current
;
3003 HighlightLines(oldCurrent
, newCurrent
);
3007 // all previously selected items are unselected unless ctrl is held
3008 if ( !event
.ControlDown() )
3009 HighlightAll(FALSE
);
3011 m_current
= newCurrent
;
3013 HighlightLine( oldCurrent
, FALSE
);
3014 RefreshLine( oldCurrent
);
3016 if ( !event
.ControlDown() )
3018 HighlightLine( m_current
, TRUE
);
3022 OnUnfocusLine( oldCurrent
);
3023 OnFocusLine( m_current
);
3024 RefreshLine( m_current
);
3029 void wxListMainWindow::OnKeyDown( wxKeyEvent
&event
)
3031 wxWindow
*parent
= GetParent();
3033 /* we propagate the key event up */
3034 wxKeyEvent
ke( wxEVT_KEY_DOWN
);
3035 ke
.m_shiftDown
= event
.m_shiftDown
;
3036 ke
.m_controlDown
= event
.m_controlDown
;
3037 ke
.m_altDown
= event
.m_altDown
;
3038 ke
.m_metaDown
= event
.m_metaDown
;
3039 ke
.m_keyCode
= event
.m_keyCode
;
3042 ke
.SetEventObject( parent
);
3043 if (parent
->GetEventHandler()->ProcessEvent( ke
)) return;
3048 void wxListMainWindow::OnChar( wxKeyEvent
&event
)
3050 wxWindow
*parent
= GetParent();
3052 /* we send a list_key event up */
3055 wxListEvent
le( wxEVT_COMMAND_LIST_KEY_DOWN
, GetParent()->GetId() );
3056 le
.m_itemIndex
= m_current
;
3057 GetLine(m_current
)->GetItem( 0, le
.m_item
);
3058 le
.m_code
= (int)event
.KeyCode();
3059 le
.SetEventObject( parent
);
3060 parent
->GetEventHandler()->ProcessEvent( le
);
3063 /* we propagate the char event up */
3064 wxKeyEvent
ke( wxEVT_CHAR
);
3065 ke
.m_shiftDown
= event
.m_shiftDown
;
3066 ke
.m_controlDown
= event
.m_controlDown
;
3067 ke
.m_altDown
= event
.m_altDown
;
3068 ke
.m_metaDown
= event
.m_metaDown
;
3069 ke
.m_keyCode
= event
.m_keyCode
;
3072 ke
.SetEventObject( parent
);
3073 if (parent
->GetEventHandler()->ProcessEvent( ke
)) return;
3075 if (event
.KeyCode() == WXK_TAB
)
3077 wxNavigationKeyEvent nevent
;
3078 nevent
.SetWindowChange( event
.ControlDown() );
3079 nevent
.SetDirection( !event
.ShiftDown() );
3080 nevent
.SetEventObject( GetParent()->GetParent() );
3081 nevent
.SetCurrentFocus( m_parent
);
3082 if (GetParent()->GetParent()->GetEventHandler()->ProcessEvent( nevent
)) return;
3085 /* no item -> nothing to do */
3092 switch (event
.KeyCode())
3095 if ( m_current
> 0 )
3096 OnArrowChar( m_current
- 1, event
);
3100 if ( m_current
< (size_t)GetItemCount() - 1 )
3101 OnArrowChar( m_current
+ 1, event
);
3106 OnArrowChar( GetItemCount() - 1, event
);
3111 OnArrowChar( 0, event
);
3117 if ( HasFlag(wxLC_REPORT
) )
3119 steps
= m_linesPerPage
- 1;
3123 steps
= m_current
% m_linesPerPage
;
3126 int index
= m_current
- steps
;
3130 OnArrowChar( index
, event
);
3137 if ( HasFlag(wxLC_REPORT
) )
3139 steps
= m_linesPerPage
- 1;
3143 steps
= m_linesPerPage
- (m_current
% m_linesPerPage
) - 1;
3146 size_t index
= m_current
+ steps
;
3147 size_t count
= GetItemCount();
3148 if ( index
>= count
)
3151 OnArrowChar( index
, event
);
3156 if ( !HasFlag(wxLC_REPORT
) )
3158 int index
= m_current
- m_linesPerPage
;
3162 OnArrowChar( index
, event
);
3167 if ( !HasFlag(wxLC_REPORT
) )
3169 size_t index
= m_current
+ m_linesPerPage
;
3171 size_t count
= GetItemCount();
3172 if ( index
>= count
)
3175 OnArrowChar( index
, event
);
3180 if ( IsSingleSel() )
3182 wxListEvent
le( wxEVT_COMMAND_LIST_ITEM_ACTIVATED
,
3183 GetParent()->GetId() );
3184 le
.SetEventObject( GetParent() );
3185 le
.m_itemIndex
= m_current
;
3186 GetLine(m_current
)->GetItem( 0, le
.m_item
);
3187 GetParent()->GetEventHandler()->ProcessEvent( le
);
3189 if ( IsHighlighted(m_current
) )
3191 // don't unselect the item in single selection mode
3194 //else: select it in ReverseHighlight() below if unselected
3197 ReverseHighlight(m_current
);
3203 wxListEvent
le( wxEVT_COMMAND_LIST_ITEM_ACTIVATED
,
3204 GetParent()->GetId() );
3205 le
.SetEventObject( GetParent() );
3206 le
.m_itemIndex
= m_current
;
3207 GetLine(m_current
)->GetItem( 0, le
.m_item
);
3208 GetParent()->GetEventHandler()->ProcessEvent( le
);
3217 // ----------------------------------------------------------------------------
3219 // ----------------------------------------------------------------------------
3222 extern wxWindow
*g_focusWindow
;
3225 void wxListMainWindow::OnSetFocus( wxFocusEvent
&WXUNUSED(event
) )
3230 RefreshLine( m_current
);
3236 g_focusWindow
= GetParent();
3239 wxFocusEvent
event( wxEVT_SET_FOCUS
, GetParent()->GetId() );
3240 event
.SetEventObject( GetParent() );
3241 GetParent()->GetEventHandler()->ProcessEvent( event
);
3244 void wxListMainWindow::OnKillFocus( wxFocusEvent
&WXUNUSED(event
) )
3249 RefreshLine( m_current
);
3252 void wxListMainWindow::DrawImage( int index
, wxDC
*dc
, int x
, int y
)
3254 if ( HasFlag(wxLC_ICON
) && (m_normal_image_list
))
3256 m_normal_image_list
->Draw( index
, *dc
, x
, y
, wxIMAGELIST_DRAW_TRANSPARENT
);
3258 else if ( HasFlag(wxLC_SMALL_ICON
) && (m_small_image_list
))
3260 m_small_image_list
->Draw( index
, *dc
, x
, y
, wxIMAGELIST_DRAW_TRANSPARENT
);
3262 else if ( HasFlag(wxLC_LIST
) && (m_small_image_list
))
3264 m_small_image_list
->Draw( index
, *dc
, x
, y
, wxIMAGELIST_DRAW_TRANSPARENT
);
3266 else if ( HasFlag(wxLC_REPORT
) && (m_small_image_list
))
3268 m_small_image_list
->Draw( index
, *dc
, x
, y
, wxIMAGELIST_DRAW_TRANSPARENT
);
3272 void wxListMainWindow::GetImageSize( int index
, int &width
, int &height
) const
3274 if ( HasFlag(wxLC_ICON
) && m_normal_image_list
)
3276 m_normal_image_list
->GetSize( index
, width
, height
);
3278 else if ( HasFlag(wxLC_SMALL_ICON
) && m_small_image_list
)
3280 m_small_image_list
->GetSize( index
, width
, height
);
3282 else if ( HasFlag(wxLC_LIST
) && m_small_image_list
)
3284 m_small_image_list
->GetSize( index
, width
, height
);
3286 else if ( HasFlag(wxLC_REPORT
) && m_small_image_list
)
3288 m_small_image_list
->GetSize( index
, width
, height
);
3297 int wxListMainWindow::GetTextLength( const wxString
&s
) const
3299 wxClientDC
dc( wxConstCast(this, wxListMainWindow
) );
3300 dc
.SetFont( GetFont() );
3303 dc
.GetTextExtent( s
, &lw
, NULL
);
3305 return lw
+ AUTOSIZE_COL_MARGIN
;
3308 void wxListMainWindow::SetImageList( wxImageList
*imageList
, int which
)
3312 // calc the spacing from the icon size
3315 if ((imageList
) && (imageList
->GetImageCount()) )
3317 imageList
->GetSize(0, width
, height
);
3320 if (which
== wxIMAGE_LIST_NORMAL
)
3322 m_normal_image_list
= imageList
;
3323 m_normal_spacing
= width
+ 8;
3326 if (which
== wxIMAGE_LIST_SMALL
)
3328 m_small_image_list
= imageList
;
3329 m_small_spacing
= width
+ 14;
3333 void wxListMainWindow::SetItemSpacing( int spacing
, bool isSmall
)
3338 m_small_spacing
= spacing
;
3342 m_normal_spacing
= spacing
;
3346 int wxListMainWindow::GetItemSpacing( bool isSmall
)
3348 return isSmall
? m_small_spacing
: m_normal_spacing
;
3351 // ----------------------------------------------------------------------------
3353 // ----------------------------------------------------------------------------
3355 void wxListMainWindow::SetColumn( int col
, wxListItem
&item
)
3357 wxListHeaderDataList::Node
*node
= m_columns
.Item( col
);
3359 wxCHECK_RET( node
, _T("invalid column index in SetColumn") );
3361 if ( item
.m_width
== wxLIST_AUTOSIZE_USEHEADER
)
3362 item
.m_width
= GetTextLength( item
.m_text
);
3364 wxListHeaderData
*column
= node
->GetData();
3365 column
->SetItem( item
);
3367 wxListHeaderWindow
*headerWin
= GetListCtrl()->m_headerWin
;
3369 headerWin
->m_dirty
= TRUE
;
3373 // invalidate it as it has to be recalculated
3377 void wxListMainWindow::SetColumnWidth( int col
, int width
)
3379 wxCHECK_RET( col
>= 0 && col
< GetColumnCount(),
3380 _T("invalid column index") );
3382 wxCHECK_RET( HasFlag(wxLC_REPORT
),
3383 _T("SetColumnWidth() can only be called in report mode.") );
3387 wxListHeaderDataList::Node
*node
= m_columns
.Item( col
);
3388 wxCHECK_RET( node
, _T("no column?") );
3390 wxListHeaderData
*column
= node
->GetData();
3392 size_t count
= GetItemCount();
3394 if (width
== wxLIST_AUTOSIZE_USEHEADER
)
3396 width
= GetTextLength(column
->GetText());
3398 else if ( width
== wxLIST_AUTOSIZE
)
3402 // TODO: determine the max width somehow...
3403 width
= WIDTH_COL_DEFAULT
;
3407 wxClientDC
dc(this);
3408 dc
.SetFont( GetFont() );
3410 int max
= AUTOSIZE_COL_MARGIN
;
3412 for ( size_t i
= 0; i
< count
; i
++ )
3414 wxListLineData
*line
= GetLine(i
);
3415 wxListItemDataList::Node
*n
= line
->m_items
.Item( col
);
3417 wxCHECK_RET( n
, _T("no subitem?") );
3419 wxListItemData
*item
= n
->GetData();
3422 if (item
->HasImage())
3425 GetImageSize( item
->GetImage(), ix
, iy
);
3429 if (item
->HasText())
3432 dc
.GetTextExtent( item
->GetText(), &w
, NULL
);
3440 width
= max
+ AUTOSIZE_COL_MARGIN
;
3444 column
->SetWidth( width
);
3446 // invalidate it as it has to be recalculated
3450 int wxListMainWindow::GetHeaderWidth() const
3452 if ( !m_headerWidth
)
3454 wxListMainWindow
*self
= wxConstCast(this, wxListMainWindow
);
3456 size_t count
= GetColumnCount();
3457 for ( size_t col
= 0; col
< count
; col
++ )
3459 self
->m_headerWidth
+= GetColumnWidth(col
);
3463 return m_headerWidth
;
3466 void wxListMainWindow::GetColumn( int col
, wxListItem
&item
) const
3468 wxListHeaderDataList::Node
*node
= m_columns
.Item( col
);
3469 wxCHECK_RET( node
, _T("invalid column index in GetColumn") );
3471 wxListHeaderData
*column
= node
->GetData();
3472 column
->GetItem( item
);
3475 int wxListMainWindow::GetColumnWidth( int col
) const
3477 wxListHeaderDataList::Node
*node
= m_columns
.Item( col
);
3478 wxCHECK_MSG( node
, 0, _T("invalid column index") );
3480 wxListHeaderData
*column
= node
->GetData();
3481 return column
->GetWidth();
3484 // ----------------------------------------------------------------------------
3486 // ----------------------------------------------------------------------------
3488 void wxListMainWindow::SetItem( wxListItem
&item
)
3490 long id
= item
.m_itemId
;
3491 wxCHECK_RET( id
>= 0 && (size_t)id
< GetItemCount(),
3492 _T("invalid item index in SetItem") );
3496 wxListLineData
*line
= GetLine((size_t)id
);
3497 line
->SetItem( item
.m_col
, item
);
3500 if ( InReportView() )
3502 // just refresh the line to show the new value of the text/image
3503 RefreshLine((size_t)id
);
3507 // refresh everything (resulting in horrible flicker - FIXME!)
3512 void wxListMainWindow::SetItemState( long litem
, long state
, long stateMask
)
3514 wxCHECK_RET( litem
>= 0 && (size_t)litem
< GetItemCount(),
3515 _T("invalid list ctrl item index in SetItem") );
3517 size_t oldCurrent
= m_current
;
3518 size_t item
= (size_t)litem
; // safe because of the check above
3520 // do we need to change the focus?
3521 if ( stateMask
& wxLIST_STATE_FOCUSED
)
3523 if ( state
& wxLIST_STATE_FOCUSED
)
3525 // don't do anything if this item is already focused
3526 if ( item
!= m_current
)
3528 OnUnfocusLine( m_current
);
3530 OnFocusLine( m_current
);
3532 if ( oldCurrent
!= (size_t)-1 )
3534 if ( IsSingleSel() )
3536 HighlightLine(oldCurrent
, FALSE
);
3539 RefreshLine(oldCurrent
);
3542 RefreshLine( m_current
);
3547 // don't do anything if this item is not focused
3548 if ( item
== m_current
)
3550 OnUnfocusLine( m_current
);
3551 m_current
= (size_t)-1;
3553 RefreshLine( oldCurrent
);
3558 // do we need to change the selection state?
3559 if ( stateMask
& wxLIST_STATE_SELECTED
)
3561 bool on
= (state
& wxLIST_STATE_SELECTED
) != 0;
3563 if ( IsSingleSel() )
3567 // selecting the item also makes it the focused one in the
3569 if ( m_current
!= item
)
3571 OnUnfocusLine( m_current
);
3573 OnFocusLine( m_current
);
3575 if ( oldCurrent
!= (size_t)-1 )
3577 HighlightLine( oldCurrent
, FALSE
);
3578 RefreshLine( oldCurrent
);
3584 // only the current item may be selected anyhow
3585 if ( item
!= m_current
)
3590 if ( HighlightLine(item
, on
) )
3597 int wxListMainWindow::GetItemState( long item
, long stateMask
)
3599 wxCHECK_MSG( item
>= 0 && (size_t)item
< GetItemCount(), 0,
3600 _T("invalid list ctrl item index in GetItemState()") );
3602 int ret
= wxLIST_STATE_DONTCARE
;
3604 if ( stateMask
& wxLIST_STATE_FOCUSED
)
3606 if ( (size_t)item
== m_current
)
3607 ret
|= wxLIST_STATE_FOCUSED
;
3610 if ( stateMask
& wxLIST_STATE_SELECTED
)
3612 if ( IsHighlighted(item
) )
3613 ret
|= wxLIST_STATE_SELECTED
;
3619 void wxListMainWindow::GetItem( wxListItem
&item
)
3621 wxCHECK_RET( item
.m_itemId
>= 0 && (size_t)item
.m_itemId
< GetItemCount(),
3622 _T("invalid item index in GetItem") );
3624 wxListLineData
*line
= GetLine((size_t)item
.m_itemId
);
3625 line
->GetItem( item
.m_col
, item
);
3628 // ----------------------------------------------------------------------------
3630 // ----------------------------------------------------------------------------
3632 size_t wxListMainWindow::GetItemCount() const
3634 return IsVirtual() ? m_countVirt
: m_lines
.GetCount();
3637 void wxListMainWindow::SetItemCount(long count
)
3639 m_selStore
.SetItemCount(count
);
3640 m_countVirt
= count
;
3642 ResetVisibleLinesRange();
3644 // scrollbars must be reset
3648 int wxListMainWindow::GetSelectedItemCount()
3650 // deal with the quick case first
3651 if ( IsSingleSel() )
3653 return HasCurrent() ? IsHighlighted(m_current
) : FALSE
;
3656 // virtual controls remmebers all its selections itself
3658 return m_selStore
.GetSelectedCount();
3660 // TODO: we probably should maintain the number of items selected even for
3661 // non virtual controls as enumerating all lines is really slow...
3662 size_t countSel
= 0;
3663 size_t count
= GetItemCount();
3664 for ( size_t line
= 0; line
< count
; line
++ )
3666 if ( GetLine(line
)->IsHighlighted() )
3673 // ----------------------------------------------------------------------------
3674 // item position/size
3675 // ----------------------------------------------------------------------------
3677 void wxListMainWindow::GetItemRect( long index
, wxRect
&rect
)
3679 wxCHECK_RET( index
>= 0 && (size_t)index
< GetItemCount(),
3680 _T("invalid index in GetItemRect") );
3682 rect
= GetLineRect((size_t)index
);
3684 CalcScrolledPosition(rect
.x
, rect
.y
, &rect
.x
, &rect
.y
);
3687 bool wxListMainWindow::GetItemPosition(long item
, wxPoint
& pos
)
3690 GetItemRect(item
, rect
);
3698 // ----------------------------------------------------------------------------
3699 // geometry calculation
3700 // ----------------------------------------------------------------------------
3702 void wxListMainWindow::RecalculatePositions(bool noRefresh
)
3704 wxClientDC
dc( this );
3705 dc
.SetFont( GetFont() );
3708 if ( HasFlag(wxLC_ICON
) )
3709 iconSpacing
= m_normal_spacing
;
3710 else if ( HasFlag(wxLC_SMALL_ICON
) )
3711 iconSpacing
= m_small_spacing
;
3717 GetClientSize( &clientWidth
, &clientHeight
);
3719 if ( HasFlag(wxLC_REPORT
) )
3721 // all lines have the same height
3722 int lineHeight
= GetLineHeight();
3724 // scroll one line per step
3725 m_yScroll
= lineHeight
;
3727 size_t lineCount
= GetItemCount();
3728 int entireHeight
= lineCount
*lineHeight
+ LINE_SPACING
;
3730 m_linesPerPage
= clientHeight
/ lineHeight
;
3732 ResetVisibleLinesRange();
3734 SetScrollbars( m_xScroll
, m_yScroll
,
3735 (GetHeaderWidth() + m_xScroll
- 1)/m_xScroll
,
3736 (entireHeight
+ m_yScroll
- 1)/m_yScroll
,
3737 GetScrollPos(wxHORIZONTAL
),
3738 GetScrollPos(wxVERTICAL
),
3743 // at first we try without any scrollbar. if the items don't
3744 // fit into the window, we recalculate after subtracting an
3745 // approximated 15 pt for the horizontal scrollbar
3747 clientHeight
-= 4; // sunken frame
3749 int entireWidth
= 0;
3751 for (int tries
= 0; tries
< 2; tries
++)
3758 int currentlyVisibleLines
= 0;
3760 size_t count
= GetItemCount();
3761 for (size_t i
= 0; i
< count
; i
++)
3763 currentlyVisibleLines
++;
3764 wxListLineData
*line
= GetLine(i
);
3765 line
->CalculateSize( &dc
, iconSpacing
);
3766 line
->SetPosition( x
, y
, clientWidth
, iconSpacing
);
3768 wxSize sizeLine
= GetLineSize(i
);
3770 if ( maxWidth
< sizeLine
.x
)
3771 maxWidth
= sizeLine
.x
;
3774 if (currentlyVisibleLines
> m_linesPerPage
)
3775 m_linesPerPage
= currentlyVisibleLines
;
3777 // assume that the size of the next one is the same... (FIXME)
3778 if ( y
+ sizeLine
.y
- 6 >= clientHeight
)
3780 currentlyVisibleLines
= 0;
3783 entireWidth
+= maxWidth
+6;
3786 if ( i
== count
- 1 )
3787 entireWidth
+= maxWidth
;
3788 if ((tries
== 0) && (entireWidth
> clientWidth
))
3790 clientHeight
-= 15; // scrollbar height
3792 currentlyVisibleLines
= 0;
3795 if ( i
== count
- 1 )
3796 tries
= 1; // everything fits, no second try required
3800 int scroll_pos
= GetScrollPos( wxHORIZONTAL
);
3801 SetScrollbars( m_xScroll
, m_yScroll
, (entireWidth
+SCROLL_UNIT_X
) / m_xScroll
, 0, scroll_pos
, 0, TRUE
);
3806 // FIXME: why should we call it from here?
3813 void wxListMainWindow::RefreshAll()
3818 wxListHeaderWindow
*headerWin
= GetListCtrl()->m_headerWin
;
3819 if ( headerWin
&& headerWin
->m_dirty
)
3821 headerWin
->m_dirty
= FALSE
;
3822 headerWin
->Refresh();
3826 void wxListMainWindow::UpdateCurrent()
3828 if ( !HasCurrent() && !IsEmpty() )
3833 if ( m_current
!= (size_t)-1 )
3835 OnFocusLine( m_current
);
3839 long wxListMainWindow::GetNextItem( long item
,
3840 int WXUNUSED(geometry
),
3844 max
= GetItemCount();
3845 wxCHECK_MSG( (ret
== -1) || (ret
< max
), -1,
3846 _T("invalid listctrl index in GetNextItem()") );
3848 // notice that we start with the next item (or the first one if item == -1)
3849 // and this is intentional to allow writing a simple loop to iterate over
3850 // all selected items
3854 // this is not an error because the index was ok initially, just no
3865 size_t count
= GetItemCount();
3866 for ( size_t line
= (size_t)ret
; line
< count
; line
++ )
3868 if ( (state
& wxLIST_STATE_FOCUSED
) && (line
== m_current
) )
3871 if ( (state
& wxLIST_STATE_SELECTED
) && IsHighlighted(line
) )
3878 // ----------------------------------------------------------------------------
3880 // ----------------------------------------------------------------------------
3882 void wxListMainWindow::DeleteItem( long lindex
)
3884 size_t count
= GetItemCount();
3886 wxCHECK_RET( (lindex
>= 0) && ((size_t)lindex
< count
),
3887 _T("invalid item index in DeleteItem") );
3889 size_t index
= (size_t)lindex
;
3891 // we don't need to adjust the index for the previous items
3892 if ( HasCurrent() && m_current
>= index
)
3894 // if the current item is being deleted, we want the next one to
3895 // become selected - unless there is no next one - so don't adjust
3896 // m_current in this case
3897 if ( m_current
!= index
|| m_current
== count
- 1 )
3903 if ( InReportView() )
3905 ResetVisibleLinesRange();
3912 m_selStore
.OnItemDelete(index
);
3916 m_lines
.RemoveAt( index
);
3919 // we need to refresh the (vert) scrollbar as the number of items changed
3922 SendNotify( index
, wxEVT_COMMAND_LIST_DELETE_ITEM
);
3924 RefreshAfter(index
);
3927 void wxListMainWindow::DeleteColumn( int col
)
3929 wxListHeaderDataList::Node
*node
= m_columns
.Item( col
);
3931 wxCHECK_RET( node
, wxT("invalid column index in DeleteColumn()") );
3934 m_columns
.DeleteNode( node
);
3937 void wxListMainWindow::DoDeleteAllItems()
3941 // nothing to do - in particular, don't send the event
3947 // to make the deletion of all items faster, we don't send the
3948 // notifications for each item deletion in this case but only one event
3949 // for all of them: this is compatible with wxMSW and documented in
3950 // DeleteAllItems() description
3952 wxListEvent
event( wxEVT_COMMAND_LIST_DELETE_ALL_ITEMS
, GetParent()->GetId() );
3953 event
.SetEventObject( GetParent() );
3954 GetParent()->GetEventHandler()->ProcessEvent( event
);
3963 if ( InReportView() )
3965 ResetVisibleLinesRange();
3971 void wxListMainWindow::DeleteAllItems()
3975 RecalculatePositions();
3978 void wxListMainWindow::DeleteEverything()
3985 // ----------------------------------------------------------------------------
3986 // scanning for an item
3987 // ----------------------------------------------------------------------------
3989 void wxListMainWindow::EnsureVisible( long index
)
3991 wxCHECK_RET( index
>= 0 && (size_t)index
< GetItemCount(),
3992 _T("invalid index in EnsureVisible") );
3994 // We have to call this here because the label in question might just have
3995 // been added and its position is not known yet
4000 RecalculatePositions(TRUE
/* no refresh */);
4003 MoveToItem((size_t)index
);
4006 long wxListMainWindow::FindItem(long start
, const wxString
& str
, bool WXUNUSED(partial
) )
4013 size_t count
= GetItemCount();
4014 for ( size_t i
= (size_t)pos
; i
< count
; i
++ )
4016 wxListLineData
*line
= GetLine(i
);
4017 if ( line
->GetText(0) == tmp
)
4024 long wxListMainWindow::FindItem(long start
, long data
)
4030 size_t count
= GetItemCount();
4031 for (size_t i
= (size_t)pos
; i
< count
; i
++)
4033 wxListLineData
*line
= GetLine(i
);
4035 line
->GetItem( 0, item
);
4036 if (item
.m_data
== data
)
4043 long wxListMainWindow::HitTest( int x
, int y
, int &flags
)
4045 CalcUnscrolledPosition( x
, y
, &x
, &y
);
4047 if ( HasFlag(wxLC_REPORT
) )
4049 size_t current
= y
/ GetLineHeight();
4050 flags
= HitTestLine(current
, x
, y
);
4056 // TODO: optimize it too! this is less simple than for report view but
4057 // enumerating all items is still not a way to do it!!
4058 size_t count
= GetItemCount();
4059 for ( size_t current
= 0; current
< count
; current
++ )
4061 flags
= HitTestLine(current
, x
, y
);
4070 // ----------------------------------------------------------------------------
4072 // ----------------------------------------------------------------------------
4074 void wxListMainWindow::InsertItem( wxListItem
&item
)
4076 wxASSERT_MSG( !IsVirtual(), _T("can't be used with virtual control") );
4078 size_t count
= GetItemCount();
4079 wxCHECK_RET( item
.m_itemId
>= 0 && (size_t)item
.m_itemId
<= count
,
4080 _T("invalid item index") );
4082 size_t id
= item
.m_itemId
;
4087 if ( HasFlag(wxLC_REPORT
) )
4089 else if ( HasFlag(wxLC_LIST
) )
4091 else if ( HasFlag(wxLC_ICON
) )
4093 else if ( HasFlag(wxLC_SMALL_ICON
) )
4094 mode
= wxLC_ICON
; // no typo
4097 wxFAIL_MSG( _T("unknown mode") );
4100 wxListLineData
*line
= new wxListLineData(this);
4102 line
->SetItem( 0, item
);
4104 m_lines
.Insert( line
, id
);
4107 RefreshLines(id
, GetItemCount() - 1);
4110 void wxListMainWindow::InsertColumn( long col
, wxListItem
&item
)
4113 if ( HasFlag(wxLC_REPORT
) )
4115 if (item
.m_width
== wxLIST_AUTOSIZE_USEHEADER
)
4116 item
.m_width
= GetTextLength( item
.m_text
);
4117 wxListHeaderData
*column
= new wxListHeaderData( item
);
4118 if ((col
>= 0) && (col
< (int)m_columns
.GetCount()))
4120 wxListHeaderDataList::Node
*node
= m_columns
.Item( col
);
4121 m_columns
.Insert( node
, column
);
4125 m_columns
.Append( column
);
4130 // ----------------------------------------------------------------------------
4132 // ----------------------------------------------------------------------------
4134 wxListCtrlCompare list_ctrl_compare_func_2
;
4135 long list_ctrl_compare_data
;
4137 int LINKAGEMODE
list_ctrl_compare_func_1( wxListLineData
**arg1
, wxListLineData
**arg2
)
4139 wxListLineData
*line1
= *arg1
;
4140 wxListLineData
*line2
= *arg2
;
4142 line1
->GetItem( 0, item
);
4143 long data1
= item
.m_data
;
4144 line2
->GetItem( 0, item
);
4145 long data2
= item
.m_data
;
4146 return list_ctrl_compare_func_2( data1
, data2
, list_ctrl_compare_data
);
4149 void wxListMainWindow::SortItems( wxListCtrlCompare fn
, long data
)
4151 list_ctrl_compare_func_2
= fn
;
4152 list_ctrl_compare_data
= data
;
4153 m_lines
.Sort( list_ctrl_compare_func_1
);
4157 // ----------------------------------------------------------------------------
4159 // ----------------------------------------------------------------------------
4161 void wxListMainWindow::OnScroll(wxScrollWinEvent
& event
)
4163 // update our idea of which lines are shown when we redraw the window the
4165 ResetVisibleLinesRange();
4168 #if defined(__WXGTK__) && !defined(__WXUNIVERSAL__)
4169 wxScrolledWindow::OnScroll(event
);
4171 HandleOnScroll( event
);
4174 if ( event
.GetOrientation() == wxHORIZONTAL
&& HasHeader() )
4176 wxListCtrl
* lc
= GetListCtrl();
4177 wxCHECK_RET( lc
, _T("no listctrl window?") );
4179 lc
->m_headerWin
->Refresh() ;
4181 lc
->m_headerWin
->MacUpdateImmediately() ;
4186 int wxListMainWindow::GetCountPerPage() const
4188 if ( !m_linesPerPage
)
4190 wxConstCast(this, wxListMainWindow
)->
4191 m_linesPerPage
= GetClientSize().y
/ GetLineHeight();
4194 return m_linesPerPage
;
4197 void wxListMainWindow::GetVisibleLinesRange(size_t *from
, size_t *to
)
4199 wxASSERT_MSG( HasFlag(wxLC_REPORT
), _T("this is for report mode only") );
4201 if ( m_lineFrom
== (size_t)-1 )
4203 size_t count
= GetItemCount();
4206 m_lineFrom
= GetScrollPos(wxVERTICAL
);
4208 // this may happen if SetScrollbars() hadn't been called yet
4209 if ( m_lineFrom
>= count
)
4210 m_lineFrom
= count
- 1;
4212 // we redraw one extra line but this is needed to make the redrawing
4213 // logic work when there is a fractional number of lines on screen
4214 m_lineTo
= m_lineFrom
+ m_linesPerPage
;
4215 if ( m_lineTo
>= count
)
4216 m_lineTo
= count
- 1;
4218 else // empty control
4221 m_lineTo
= (size_t)-1;
4225 wxASSERT_MSG( IsEmpty() ||
4226 (m_lineFrom
<= m_lineTo
&& m_lineTo
< GetItemCount()),
4227 _T("GetVisibleLinesRange() returns incorrect result") );
4235 // -------------------------------------------------------------------------------------
4237 // -------------------------------------------------------------------------------------
4239 IMPLEMENT_DYNAMIC_CLASS(wxListItem
, wxObject
)
4241 wxListItem::wxListItem()
4250 m_format
= wxLIST_FORMAT_CENTRE
;
4256 void wxListItem::Clear()
4265 m_format
= wxLIST_FORMAT_CENTRE
;
4272 void wxListItem::ClearAttributes()
4281 // -------------------------------------------------------------------------------------
4283 // -------------------------------------------------------------------------------------
4285 IMPLEMENT_DYNAMIC_CLASS(wxListEvent
, wxNotifyEvent
)
4287 wxListEvent::wxListEvent( wxEventType commandType
, int id
)
4288 : wxNotifyEvent( commandType
, id
)
4294 m_cancelled
= FALSE
;
4299 void wxListEvent::CopyObject(wxObject
& object_dest
) const
4301 wxListEvent
*obj
= (wxListEvent
*)&object_dest
;
4303 wxNotifyEvent::CopyObject(object_dest
);
4305 obj
->m_code
= m_code
;
4306 obj
->m_itemIndex
= m_itemIndex
;
4307 obj
->m_oldItemIndex
= m_oldItemIndex
;
4309 obj
->m_cancelled
= m_cancelled
;
4310 obj
->m_pointDrag
= m_pointDrag
;
4311 obj
->m_item
.m_mask
= m_item
.m_mask
;
4312 obj
->m_item
.m_itemId
= m_item
.m_itemId
;
4313 obj
->m_item
.m_col
= m_item
.m_col
;
4314 obj
->m_item
.m_state
= m_item
.m_state
;
4315 obj
->m_item
.m_stateMask
= m_item
.m_stateMask
;
4316 obj
->m_item
.m_text
= m_item
.m_text
;
4317 obj
->m_item
.m_image
= m_item
.m_image
;
4318 obj
->m_item
.m_data
= m_item
.m_data
;
4319 obj
->m_item
.m_format
= m_item
.m_format
;
4320 obj
->m_item
.m_width
= m_item
.m_width
;
4322 if ( m_item
.HasAttributes() )
4324 obj
->m_item
.SetTextColour(m_item
.GetTextColour());
4328 // -------------------------------------------------------------------------------------
4330 // -------------------------------------------------------------------------------------
4332 IMPLEMENT_DYNAMIC_CLASS(wxListCtrl
, wxControl
)
4333 IMPLEMENT_DYNAMIC_CLASS(wxListView
, wxListCtrl
)
4335 BEGIN_EVENT_TABLE(wxListCtrl
,wxControl
)
4336 EVT_SIZE(wxListCtrl::OnSize
)
4337 EVT_IDLE(wxListCtrl::OnIdle
)
4340 wxListCtrl::wxListCtrl()
4342 m_imageListNormal
= (wxImageList
*) NULL
;
4343 m_imageListSmall
= (wxImageList
*) NULL
;
4344 m_imageListState
= (wxImageList
*) NULL
;
4346 m_ownsImageListNormal
=
4347 m_ownsImageListSmall
=
4348 m_ownsImageListState
= FALSE
;
4350 m_mainWin
= (wxListMainWindow
*) NULL
;
4351 m_headerWin
= (wxListHeaderWindow
*) NULL
;
4354 wxListCtrl::~wxListCtrl()
4357 m_mainWin
->ResetCurrent();
4359 if (m_ownsImageListNormal
)
4360 delete m_imageListNormal
;
4361 if (m_ownsImageListSmall
)
4362 delete m_imageListSmall
;
4363 if (m_ownsImageListState
)
4364 delete m_imageListState
;
4367 void wxListCtrl::CreateHeaderWindow()
4369 m_headerWin
= new wxListHeaderWindow
4371 this, -1, m_mainWin
,
4373 wxSize(GetClientSize().x
, HEADER_HEIGHT
),
4378 bool wxListCtrl::Create(wxWindow
*parent
,
4383 const wxValidator
&validator
,
4384 const wxString
&name
)
4388 m_imageListState
= (wxImageList
*) NULL
;
4389 m_ownsImageListNormal
=
4390 m_ownsImageListSmall
=
4391 m_ownsImageListState
= FALSE
;
4393 m_mainWin
= (wxListMainWindow
*) NULL
;
4394 m_headerWin
= (wxListHeaderWindow
*) NULL
;
4396 if ( !(style
& wxLC_MASK_TYPE
) )
4398 style
= style
| wxLC_LIST
;
4401 if ( !wxControl::Create( parent
, id
, pos
, size
, style
, validator
, name
) )
4404 // don't create the inner window with the border
4405 style
&= ~wxSUNKEN_BORDER
;
4407 m_mainWin
= new wxListMainWindow( this, -1, wxPoint(0,0), size
, style
);
4409 if ( HasFlag(wxLC_REPORT
) )
4411 CreateHeaderWindow();
4413 if ( HasFlag(wxLC_NO_HEADER
) )
4415 // VZ: why do we create it at all then?
4416 m_headerWin
->Show( FALSE
);
4423 void wxListCtrl::SetSingleStyle( long style
, bool add
)
4425 wxASSERT_MSG( !(style
& wxLC_VIRTUAL
),
4426 _T("wxLC_VIRTUAL can't be [un]set") );
4428 long flag
= GetWindowStyle();
4432 if (style
& wxLC_MASK_TYPE
)
4433 flag
&= ~(wxLC_MASK_TYPE
| wxLC_VIRTUAL
);
4434 if (style
& wxLC_MASK_ALIGN
)
4435 flag
&= ~wxLC_MASK_ALIGN
;
4436 if (style
& wxLC_MASK_SORT
)
4437 flag
&= ~wxLC_MASK_SORT
;
4449 SetWindowStyleFlag( flag
);
4452 void wxListCtrl::SetWindowStyleFlag( long flag
)
4456 m_mainWin
->DeleteEverything();
4458 // has the header visibility changed?
4459 bool hasHeader
= HasFlag(wxLC_REPORT
) && !HasFlag(wxLC_NO_HEADER
),
4460 willHaveHeader
= (flag
& wxLC_REPORT
) && !(flag
& wxLC_NO_HEADER
);
4462 if ( hasHeader
!= willHaveHeader
)
4469 // don't delete, just hide, as we can reuse it later
4470 m_headerWin
->Show(FALSE
);
4472 //else: nothing to do
4474 else // must show header
4478 CreateHeaderWindow();
4480 else // already have it, just show
4482 m_headerWin
->Show( TRUE
);
4486 ResizeReportView(willHaveHeader
);
4490 wxWindow::SetWindowStyleFlag( flag
);
4493 bool wxListCtrl::GetColumn(int col
, wxListItem
&item
) const
4495 m_mainWin
->GetColumn( col
, item
);
4499 bool wxListCtrl::SetColumn( int col
, wxListItem
& item
)
4501 m_mainWin
->SetColumn( col
, item
);
4505 int wxListCtrl::GetColumnWidth( int col
) const
4507 return m_mainWin
->GetColumnWidth( col
);
4510 bool wxListCtrl::SetColumnWidth( int col
, int width
)
4512 m_mainWin
->SetColumnWidth( col
, width
);
4516 int wxListCtrl::GetCountPerPage() const
4518 return m_mainWin
->GetCountPerPage(); // different from Windows ?
4521 bool wxListCtrl::GetItem( wxListItem
&info
) const
4523 m_mainWin
->GetItem( info
);
4527 bool wxListCtrl::SetItem( wxListItem
&info
)
4529 m_mainWin
->SetItem( info
);
4533 long wxListCtrl::SetItem( long index
, int col
, const wxString
& label
, int imageId
)
4536 info
.m_text
= label
;
4537 info
.m_mask
= wxLIST_MASK_TEXT
;
4538 info
.m_itemId
= index
;
4542 info
.m_image
= imageId
;
4543 info
.m_mask
|= wxLIST_MASK_IMAGE
;
4545 m_mainWin
->SetItem(info
);
4549 int wxListCtrl::GetItemState( long item
, long stateMask
) const
4551 return m_mainWin
->GetItemState( item
, stateMask
);
4554 bool wxListCtrl::SetItemState( long item
, long state
, long stateMask
)
4556 m_mainWin
->SetItemState( item
, state
, stateMask
);
4560 bool wxListCtrl::SetItemImage( long item
, int image
, int WXUNUSED(selImage
) )
4563 info
.m_image
= image
;
4564 info
.m_mask
= wxLIST_MASK_IMAGE
;
4565 info
.m_itemId
= item
;
4566 m_mainWin
->SetItem( info
);
4570 wxString
wxListCtrl::GetItemText( long item
) const
4573 info
.m_itemId
= item
;
4574 m_mainWin
->GetItem( info
);
4578 void wxListCtrl::SetItemText( long item
, const wxString
&str
)
4581 info
.m_mask
= wxLIST_MASK_TEXT
;
4582 info
.m_itemId
= item
;
4584 m_mainWin
->SetItem( info
);
4587 long wxListCtrl::GetItemData( long item
) const
4590 info
.m_itemId
= item
;
4591 m_mainWin
->GetItem( info
);
4595 bool wxListCtrl::SetItemData( long item
, long data
)
4598 info
.m_mask
= wxLIST_MASK_DATA
;
4599 info
.m_itemId
= item
;
4601 m_mainWin
->SetItem( info
);
4605 bool wxListCtrl::GetItemRect( long item
, wxRect
&rect
, int WXUNUSED(code
) ) const
4607 m_mainWin
->GetItemRect( item
, rect
);
4611 bool wxListCtrl::GetItemPosition( long item
, wxPoint
& pos
) const
4613 m_mainWin
->GetItemPosition( item
, pos
);
4617 bool wxListCtrl::SetItemPosition( long WXUNUSED(item
), const wxPoint
& WXUNUSED(pos
) )
4622 int wxListCtrl::GetItemCount() const
4624 return m_mainWin
->GetItemCount();
4627 int wxListCtrl::GetColumnCount() const
4629 return m_mainWin
->GetColumnCount();
4632 void wxListCtrl::SetItemSpacing( int spacing
, bool isSmall
)
4634 m_mainWin
->SetItemSpacing( spacing
, isSmall
);
4637 int wxListCtrl::GetItemSpacing( bool isSmall
) const
4639 return m_mainWin
->GetItemSpacing( isSmall
);
4642 int wxListCtrl::GetSelectedItemCount() const
4644 return m_mainWin
->GetSelectedItemCount();
4647 wxColour
wxListCtrl::GetTextColour() const
4649 return GetForegroundColour();
4652 void wxListCtrl::SetTextColour(const wxColour
& col
)
4654 SetForegroundColour(col
);
4657 long wxListCtrl::GetTopItem() const
4662 long wxListCtrl::GetNextItem( long item
, int geom
, int state
) const
4664 return m_mainWin
->GetNextItem( item
, geom
, state
);
4667 wxImageList
*wxListCtrl::GetImageList(int which
) const
4669 if (which
== wxIMAGE_LIST_NORMAL
)
4671 return m_imageListNormal
;
4673 else if (which
== wxIMAGE_LIST_SMALL
)
4675 return m_imageListSmall
;
4677 else if (which
== wxIMAGE_LIST_STATE
)
4679 return m_imageListState
;
4681 return (wxImageList
*) NULL
;
4684 void wxListCtrl::SetImageList( wxImageList
*imageList
, int which
)
4686 if ( which
== wxIMAGE_LIST_NORMAL
)
4688 if (m_ownsImageListNormal
) delete m_imageListNormal
;
4689 m_imageListNormal
= imageList
;
4690 m_ownsImageListNormal
= FALSE
;
4692 else if ( which
== wxIMAGE_LIST_SMALL
)
4694 if (m_ownsImageListSmall
) delete m_imageListSmall
;
4695 m_imageListSmall
= imageList
;
4696 m_ownsImageListSmall
= FALSE
;
4698 else if ( which
== wxIMAGE_LIST_STATE
)
4700 if (m_ownsImageListState
) delete m_imageListState
;
4701 m_imageListState
= imageList
;
4702 m_ownsImageListState
= FALSE
;
4705 m_mainWin
->SetImageList( imageList
, which
);
4708 void wxListCtrl::AssignImageList(wxImageList
*imageList
, int which
)
4710 SetImageList(imageList
, which
);
4711 if ( which
== wxIMAGE_LIST_NORMAL
)
4712 m_ownsImageListNormal
= TRUE
;
4713 else if ( which
== wxIMAGE_LIST_SMALL
)
4714 m_ownsImageListSmall
= TRUE
;
4715 else if ( which
== wxIMAGE_LIST_STATE
)
4716 m_ownsImageListState
= TRUE
;
4719 bool wxListCtrl::Arrange( int WXUNUSED(flag
) )
4724 bool wxListCtrl::DeleteItem( long item
)
4726 m_mainWin
->DeleteItem( item
);
4730 bool wxListCtrl::DeleteAllItems()
4732 m_mainWin
->DeleteAllItems();
4736 bool wxListCtrl::DeleteAllColumns()
4738 size_t count
= m_mainWin
->m_columns
.GetCount();
4739 for ( size_t n
= 0; n
< count
; n
++ )
4745 void wxListCtrl::ClearAll()
4747 m_mainWin
->DeleteEverything();
4750 bool wxListCtrl::DeleteColumn( int col
)
4752 m_mainWin
->DeleteColumn( col
);
4756 void wxListCtrl::Edit( long item
)
4758 m_mainWin
->EditLabel( item
);
4761 bool wxListCtrl::EnsureVisible( long item
)
4763 m_mainWin
->EnsureVisible( item
);
4767 long wxListCtrl::FindItem( long start
, const wxString
& str
, bool partial
)
4769 return m_mainWin
->FindItem( start
, str
, partial
);
4772 long wxListCtrl::FindItem( long start
, long data
)
4774 return m_mainWin
->FindItem( start
, data
);
4777 long wxListCtrl::FindItem( long WXUNUSED(start
), const wxPoint
& WXUNUSED(pt
),
4778 int WXUNUSED(direction
))
4783 long wxListCtrl::HitTest( const wxPoint
&point
, int &flags
)
4785 return m_mainWin
->HitTest( (int)point
.x
, (int)point
.y
, flags
);
4788 long wxListCtrl::InsertItem( wxListItem
& info
)
4790 m_mainWin
->InsertItem( info
);
4791 return info
.m_itemId
;
4794 long wxListCtrl::InsertItem( long index
, const wxString
&label
)
4797 info
.m_text
= label
;
4798 info
.m_mask
= wxLIST_MASK_TEXT
;
4799 info
.m_itemId
= index
;
4800 return InsertItem( info
);
4803 long wxListCtrl::InsertItem( long index
, int imageIndex
)
4806 info
.m_mask
= wxLIST_MASK_IMAGE
;
4807 info
.m_image
= imageIndex
;
4808 info
.m_itemId
= index
;
4809 return InsertItem( info
);
4812 long wxListCtrl::InsertItem( long index
, const wxString
&label
, int imageIndex
)
4815 info
.m_text
= label
;
4816 info
.m_image
= imageIndex
;
4817 info
.m_mask
= wxLIST_MASK_TEXT
| wxLIST_MASK_IMAGE
;
4818 info
.m_itemId
= index
;
4819 return InsertItem( info
);
4822 long wxListCtrl::InsertColumn( long col
, wxListItem
&item
)
4824 wxASSERT( m_headerWin
);
4825 m_mainWin
->InsertColumn( col
, item
);
4826 m_headerWin
->Refresh();
4831 long wxListCtrl::InsertColumn( long col
, const wxString
&heading
,
4832 int format
, int width
)
4835 item
.m_mask
= wxLIST_MASK_TEXT
| wxLIST_MASK_FORMAT
;
4836 item
.m_text
= heading
;
4839 item
.m_mask
|= wxLIST_MASK_WIDTH
;
4840 item
.m_width
= width
;
4842 item
.m_format
= format
;
4844 return InsertColumn( col
, item
);
4847 bool wxListCtrl::ScrollList( int WXUNUSED(dx
), int WXUNUSED(dy
) )
4853 // fn is a function which takes 3 long arguments: item1, item2, data.
4854 // item1 is the long data associated with a first item (NOT the index).
4855 // item2 is the long data associated with a second item (NOT the index).
4856 // data is the same value as passed to SortItems.
4857 // The return value is a negative number if the first item should precede the second
4858 // item, a positive number of the second item should precede the first,
4859 // or zero if the two items are equivalent.
4860 // data is arbitrary data to be passed to the sort function.
4862 bool wxListCtrl::SortItems( wxListCtrlCompare fn
, long data
)
4864 m_mainWin
->SortItems( fn
, data
);
4868 // ----------------------------------------------------------------------------
4870 // ----------------------------------------------------------------------------
4872 void wxListCtrl::OnSize(wxSizeEvent
& event
)
4877 ResizeReportView(m_mainWin
->HasHeader());
4879 m_mainWin
->RecalculatePositions();
4882 void wxListCtrl::ResizeReportView(bool showHeader
)
4885 GetClientSize( &cw
, &ch
);
4889 m_headerWin
->SetSize( 0, 0, cw
, HEADER_HEIGHT
);
4890 m_mainWin
->SetSize( 0, HEADER_HEIGHT
+ 1, cw
, ch
- HEADER_HEIGHT
- 1 );
4892 else // no header window
4894 m_mainWin
->SetSize( 0, 0, cw
, ch
);
4898 void wxListCtrl::OnIdle( wxIdleEvent
& event
)
4902 // do it only if needed
4903 if ( !m_mainWin
->m_dirty
)
4906 m_mainWin
->RecalculatePositions();
4909 // ----------------------------------------------------------------------------
4911 // ----------------------------------------------------------------------------
4913 bool wxListCtrl::SetBackgroundColour( const wxColour
&colour
)
4917 m_mainWin
->SetBackgroundColour( colour
);
4918 m_mainWin
->m_dirty
= TRUE
;
4924 bool wxListCtrl::SetForegroundColour( const wxColour
&colour
)
4926 if ( !wxWindow::SetForegroundColour( colour
) )
4931 m_mainWin
->SetForegroundColour( colour
);
4932 m_mainWin
->m_dirty
= TRUE
;
4937 m_headerWin
->SetForegroundColour( colour
);
4943 bool wxListCtrl::SetFont( const wxFont
&font
)
4945 if ( !wxWindow::SetFont( font
) )
4950 m_mainWin
->SetFont( font
);
4951 m_mainWin
->m_dirty
= TRUE
;
4956 m_headerWin
->SetFont( font
);
4962 // ----------------------------------------------------------------------------
4963 // methods forwarded to m_mainWin
4964 // ----------------------------------------------------------------------------
4966 #if wxUSE_DRAG_AND_DROP
4968 void wxListCtrl::SetDropTarget( wxDropTarget
*dropTarget
)
4970 m_mainWin
->SetDropTarget( dropTarget
);
4973 wxDropTarget
*wxListCtrl::GetDropTarget() const
4975 return m_mainWin
->GetDropTarget();
4978 #endif // wxUSE_DRAG_AND_DROP
4980 bool wxListCtrl::SetCursor( const wxCursor
&cursor
)
4982 return m_mainWin
? m_mainWin
->wxWindow::SetCursor(cursor
) : FALSE
;
4985 wxColour
wxListCtrl::GetBackgroundColour() const
4987 return m_mainWin
? m_mainWin
->GetBackgroundColour() : wxColour();
4990 wxColour
wxListCtrl::GetForegroundColour() const
4992 return m_mainWin
? m_mainWin
->GetForegroundColour() : wxColour();
4995 bool wxListCtrl::DoPopupMenu( wxMenu
*menu
, int x
, int y
)
4998 return m_mainWin
->PopupMenu( menu
, x
, y
);
5001 #endif // wxUSE_MENUS
5004 void wxListCtrl::SetFocus()
5006 /* The test in window.cpp fails as we are a composite
5007 window, so it checks against "this", but not m_mainWin. */
5008 if ( FindFocus() != this )
5009 m_mainWin
->SetFocus();
5012 // ----------------------------------------------------------------------------
5013 // virtual list control support
5014 // ----------------------------------------------------------------------------
5016 wxString
wxListCtrl::OnGetItemText(long item
, long col
) const
5018 // this is a pure virtual function, in fact - which is not really pure
5019 // because the controls which are not virtual don't need to implement it
5020 wxFAIL_MSG( _T("not supposed to be called") );
5022 return wxEmptyString
;
5025 int wxListCtrl::OnGetItemImage(long item
) const
5028 wxFAIL_MSG( _T("not supposed to be called") );
5033 wxListItemAttr
*wxListCtrl::OnGetItemAttr(long item
) const
5035 wxASSERT_MSG( item
>= 0 && item
< GetItemCount(),
5036 _T("invalid item index in OnGetItemAttr()") );
5038 // no attributes by default
5042 void wxListCtrl::SetItemCount(long count
)
5044 wxASSERT_MSG( IsVirtual(), _T("this is for virtual controls only") );
5046 m_mainWin
->SetItemCount(count
);
5049 void wxListCtrl::RefreshItem(long item
)
5051 m_mainWin
->RefreshLine(item
);
5054 void wxListCtrl::RefreshItems(long itemFrom
, long itemTo
)
5056 m_mainWin
->RefreshLines(itemFrom
, itemTo
);
5059 #endif // wxUSE_LISTCTRL