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 /////////////////////////////////////////////////////////////////////////////
12 TODO for better virtual list control support:
14 1. we need to implement searching/sorting somehow
17 // ============================================================================
19 // ============================================================================
21 // ----------------------------------------------------------------------------
23 // ----------------------------------------------------------------------------
26 #pragma implementation "listctrl.h"
27 #pragma implementation "listctrlbase.h"
30 // For compilers that support precompilation, includes "wx.h".
31 #include "wx/wxprec.h"
39 #include "wx/dcscreen.h"
41 #include "wx/listctrl.h"
42 #include "wx/imaglist.h"
43 #include "wx/dynarray.h"
47 #include "wx/gtk/win_gtk.h"
50 // ----------------------------------------------------------------------------
52 // ----------------------------------------------------------------------------
54 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_BEGIN_DRAG
)
55 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_BEGIN_RDRAG
)
56 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_BEGIN_LABEL_EDIT
)
57 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_END_LABEL_EDIT
)
58 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_DELETE_ITEM
)
59 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_DELETE_ALL_ITEMS
)
60 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_GET_INFO
)
61 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_SET_INFO
)
62 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_ITEM_SELECTED
)
63 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_ITEM_DESELECTED
)
64 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_KEY_DOWN
)
65 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_INSERT_ITEM
)
66 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_COL_CLICK
)
67 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_ITEM_RIGHT_CLICK
)
68 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_ITEM_MIDDLE_CLICK
)
69 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_ITEM_ACTIVATED
)
70 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_CACHE_HINT
)
72 // ----------------------------------------------------------------------------
74 // ----------------------------------------------------------------------------
76 // the height of the header window (FIXME: should depend on its font!)
77 static const int HEADER_HEIGHT
= 23;
79 // the scrollbar units
80 static const int SCROLL_UNIT_X
= 15;
81 static const int SCROLL_UNIT_Y
= 15;
83 // the spacing between the lines (in report mode)
84 static const int LINE_SPACING
= 0;
86 // extra margins around the text label
87 static const int EXTRA_WIDTH
= 3;
88 static const int EXTRA_HEIGHT
= 4;
90 // offset for the header window
91 static const int HEADER_OFFSET_X
= 1;
92 static const int HEADER_OFFSET_Y
= 1;
94 // when autosizing the columns, add some slack
95 static const int AUTOSIZE_COL_MARGIN
= 10;
97 // default and minimal widths for the header columns
98 static const int WIDTH_COL_DEFAULT
= 80;
99 static const int WIDTH_COL_MIN
= 10;
101 // ============================================================================
103 // ============================================================================
105 // ----------------------------------------------------------------------------
107 // ----------------------------------------------------------------------------
109 int CMPFUNC_CONV
wxSizeTCmpFn(size_t n1
, size_t n2
) { return n1
- n2
; }
111 WX_DEFINE_SORTED_EXPORTED_ARRAY(size_t, wxIndexArray
);
113 // this class is used to store the selected items in the virtual list control
114 // (but it is not tied to list control and so can be used with other controls
115 // such as wxListBox in wxUniv)
117 // the idea is to make it really smart later (i.e. store the selections as an
118 // array of ranes + individual items) but, as I don't have time to do it now
119 // (this would require writing code to merge/break ranges and much more) keep
120 // it simple but define a clean interface to it which allows it to be made
122 class WXDLLEXPORT wxSelectionStore
125 wxSelectionStore() : m_itemsSel(wxSizeTCmpFn
) { Init(); }
127 // set the total number of items we handle
128 void SetItemCount(size_t count
) { m_count
= count
; }
130 // special case of SetItemCount(0)
131 void Clear() { m_itemsSel
.Clear(); m_count
= 0; }
133 // must be called when a new item is inserted/added
134 void OnItemAdd(size_t item
) { wxFAIL_MSG( _T("TODO") ); }
136 // must be called when an item is deleted
137 void OnItemDelete(size_t item
);
139 // select one item, use SelectRange() insted if possible!
141 // returns true if the items selection really changed
142 bool SelectItem(size_t item
, bool select
= TRUE
);
144 // select the range of items
146 // return true and fill the itemsChanged array with the indices of items
147 // which have changed state if "few" of them did, otherwise return false
148 // (meaning that too many items changed state to bother counting them
150 bool SelectRange(size_t itemFrom
, size_t itemTo
,
152 wxArrayInt
*itemsChanged
= NULL
);
154 // return true if the given item is selected
155 bool IsSelected(size_t item
) const;
157 // return the total number of selected items
158 size_t GetSelectedCount() const
160 return m_defaultState
? m_count
- m_itemsSel
.GetCount()
161 : m_itemsSel
.GetCount();
166 void Init() { m_defaultState
= FALSE
; }
168 // the total number of items we handle
171 // the default state: normally, FALSE (i.e. off) but maybe set to TRUE if
172 // there are more selected items than non selected ones - this allows to
173 // handle selection of all items efficiently
176 // the array of items whose selection state is different from default
177 wxIndexArray m_itemsSel
;
179 DECLARE_NO_COPY_CLASS(wxSelectionStore
)
182 //-----------------------------------------------------------------------------
183 // wxListItemData (internal)
184 //-----------------------------------------------------------------------------
186 class WXDLLEXPORT wxListItemData
189 wxListItemData(wxListMainWindow
*owner
);
192 void SetItem( const wxListItem
&info
);
193 void SetImage( int image
) { m_image
= image
; }
194 void SetData( long data
) { m_data
= data
; }
195 void SetPosition( int x
, int y
);
196 void SetSize( int width
, int height
);
198 bool HasText() const { return !m_text
.empty(); }
199 const wxString
& GetText() const { return m_text
; }
200 void SetText(const wxString
& text
) { m_text
= text
; }
202 // we can't use empty string for measuring the string width/height, so
203 // always return something
204 wxString
GetTextForMeasuring() const
206 wxString s
= GetText();
213 bool IsHit( int x
, int y
) const;
217 int GetWidth() const;
218 int GetHeight() const;
220 int GetImage() const { return m_image
; }
221 bool HasImage() const { return GetImage() != -1; }
223 void GetItem( wxListItem
&info
) const;
225 void SetAttr(wxListItemAttr
*attr
) { m_attr
= attr
; }
226 wxListItemAttr
*GetAttr() const { return m_attr
; }
229 // the item image or -1
232 // user data associated with the item
235 // the item coordinates are not used in report mode, instead this pointer
236 // is NULL and the owner window is used to retrieve the item position and
240 // the list ctrl we are in
241 wxListMainWindow
*m_owner
;
243 // custom attributes or NULL
244 wxListItemAttr
*m_attr
;
247 // common part of all ctors
253 //-----------------------------------------------------------------------------
254 // wxListHeaderData (internal)
255 //-----------------------------------------------------------------------------
257 class WXDLLEXPORT wxListHeaderData
: public wxObject
271 wxListHeaderData( const wxListItem
&info
);
272 void SetItem( const wxListItem
&item
);
273 void SetPosition( int x
, int y
);
274 void SetWidth( int w
);
275 void SetFormat( int format
);
276 void SetHeight( int h
);
277 bool HasImage() const;
279 bool HasText() const { return !m_text
.empty(); }
280 const wxString
& GetText() const { return m_text
; }
281 void SetText(const wxString
& text
) { m_text
= text
; }
283 void GetItem( wxListItem
&item
);
285 bool IsHit( int x
, int y
) const;
286 int GetImage() const;
287 int GetWidth() const;
288 int GetFormat() const;
291 DECLARE_DYNAMIC_CLASS(wxListHeaderData
);
294 //-----------------------------------------------------------------------------
295 // wxListLineData (internal)
296 //-----------------------------------------------------------------------------
298 WX_DECLARE_LIST(wxListItemData
, wxListItemDataList
);
299 #include "wx/listimpl.cpp"
300 WX_DEFINE_LIST(wxListItemDataList
);
302 class WXDLLEXPORT wxListLineData
305 // the list of subitems: only may have more than one item in report mode
306 wxListItemDataList m_items
;
308 // this is not used in report view
320 // the part to be highlighted
321 wxRect m_rectHighlight
;
324 // is this item selected? [NB: not used in virtual mode]
327 // back pointer to the list ctrl
328 wxListMainWindow
*m_owner
;
331 wxListLineData(wxListMainWindow
*owner
);
333 ~wxListLineData() { delete m_gi
; }
335 // are we in report mode?
336 inline bool InReportView() const;
338 // are we in virtual report mode?
339 inline bool IsVirtual() const;
341 // these 2 methods shouldn't be called for report view controls, in that
342 // case we determine our position/size ourselves
344 // calculate the size of the line
345 void CalculateSize( wxDC
*dc
, int spacing
);
347 // remember the position this line appears at
348 void SetPosition( int x
, int y
, int window_width
, int spacing
);
352 void SetImage( int image
) { SetImage(0, image
); }
353 int GetImage() const { return GetImage(0); }
354 bool HasImage() const { return GetImage() != -1; }
355 bool HasText() const { return !GetText(0).empty(); }
357 void SetItem( int index
, const wxListItem
&info
);
358 void GetItem( int index
, wxListItem
&info
);
360 wxString
GetText(int index
) const;
361 void SetText( int index
, const wxString s
);
363 wxListItemAttr
*GetAttr() const;
364 void SetAttr(wxListItemAttr
*attr
);
366 // return true if the highlighting really changed
367 bool Highlight( bool on
);
369 void ReverseHighlight();
371 bool IsHighlighted() const
373 wxASSERT_MSG( !IsVirtual(), _T("unexpected call to IsHighlighted") );
375 return m_highlighted
;
378 // draw the line on the given DC in icon/list mode
379 void Draw( wxDC
*dc
);
381 // the same in report mode
382 void DrawInReportMode( wxDC
*dc
,
384 const wxRect
& rectHL
,
388 // set the line to contain num items (only can be > 1 in report mode)
389 void InitItems( int num
);
391 // get the mode (i.e. style) of the list control
392 inline int GetMode() const;
394 // prepare the DC for drawing with these item's attributes, return true if
395 // we need to draw the items background to highlight it, false otherwise
396 bool SetAttributes(wxDC
*dc
,
397 const wxListItemAttr
*attr
,
400 // these are only used by GetImage/SetImage above, we don't support images
401 // with subitems at the public API level yet
402 void SetImage( int index
, int image
);
403 int GetImage( int index
) const;
406 WX_DECLARE_EXPORTED_OBJARRAY(wxListLineData
, wxListLineDataArray
);
407 #include "wx/arrimpl.cpp"
408 WX_DEFINE_OBJARRAY(wxListLineDataArray
);
410 //-----------------------------------------------------------------------------
411 // wxListHeaderWindow (internal)
412 //-----------------------------------------------------------------------------
414 class WXDLLEXPORT wxListHeaderWindow
: public wxWindow
417 wxListMainWindow
*m_owner
;
418 wxCursor
*m_currentCursor
;
419 wxCursor
*m_resizeCursor
;
422 // column being resized
425 // divider line position in logical (unscrolled) coords
428 // minimal position beyond which the divider line can't be dragged in
433 wxListHeaderWindow();
434 virtual ~wxListHeaderWindow();
436 wxListHeaderWindow( wxWindow
*win
,
438 wxListMainWindow
*owner
,
439 const wxPoint
&pos
= wxDefaultPosition
,
440 const wxSize
&size
= wxDefaultSize
,
442 const wxString
&name
= "wxlistctrlcolumntitles" );
444 void DoDrawRect( wxDC
*dc
, int x
, int y
, int w
, int h
);
446 void AdjustDC(wxDC
& dc
);
448 void OnPaint( wxPaintEvent
&event
);
449 void OnMouse( wxMouseEvent
&event
);
450 void OnSetFocus( wxFocusEvent
&event
);
456 DECLARE_DYNAMIC_CLASS(wxListHeaderWindow
)
457 DECLARE_EVENT_TABLE()
460 //-----------------------------------------------------------------------------
461 // wxListRenameTimer (internal)
462 //-----------------------------------------------------------------------------
464 class WXDLLEXPORT wxListRenameTimer
: public wxTimer
467 wxListMainWindow
*m_owner
;
470 wxListRenameTimer( wxListMainWindow
*owner
);
474 //-----------------------------------------------------------------------------
475 // wxListTextCtrl (internal)
476 //-----------------------------------------------------------------------------
478 class WXDLLEXPORT wxListTextCtrl
: public wxTextCtrl
483 wxListMainWindow
*m_owner
;
484 wxString m_startValue
;
488 wxListTextCtrl( wxWindow
*parent
, const wxWindowID id
,
489 bool *accept
, wxString
*res
, wxListMainWindow
*owner
,
490 const wxString
&value
= "",
491 const wxPoint
&pos
= wxDefaultPosition
, const wxSize
&size
= wxDefaultSize
,
493 const wxValidator
& validator
= wxDefaultValidator
,
494 const wxString
&name
= "listctrltextctrl" );
495 void OnChar( wxKeyEvent
&event
);
496 void OnKeyUp( wxKeyEvent
&event
);
497 void OnKillFocus( wxFocusEvent
&event
);
500 DECLARE_DYNAMIC_CLASS(wxListTextCtrl
);
501 DECLARE_EVENT_TABLE()
504 //-----------------------------------------------------------------------------
505 // wxListMainWindow (internal)
506 //-----------------------------------------------------------------------------
508 WX_DECLARE_LIST(wxListHeaderData
, wxListHeaderDataList
);
509 #include "wx/listimpl.cpp"
510 WX_DEFINE_LIST(wxListHeaderDataList
);
512 class WXDLLEXPORT wxListMainWindow
: public wxScrolledWindow
516 wxListMainWindow( wxWindow
*parent
,
518 const wxPoint
& pos
= wxDefaultPosition
,
519 const wxSize
& size
= wxDefaultSize
,
521 const wxString
&name
= _T("listctrlmainwindow") );
523 virtual ~wxListMainWindow();
525 bool HasFlag(int flag
) const { return m_parent
->HasFlag(flag
); }
527 // return true if this is a virtual list control
528 bool IsVirtual() const { return HasFlag(wxLC_VIRTUAL
); }
530 // return true if the control is in report mode
531 bool InReportView() const { return HasFlag(wxLC_REPORT
); }
533 // return true if we are in single selection mode, false if multi sel
534 bool IsSingleSel() const { return HasFlag(wxLC_SINGLE_SEL
); }
536 // do we have a header window?
537 bool HasHeader() const
538 { return HasFlag(wxLC_REPORT
) && !HasFlag(wxLC_NO_HEADER
); }
540 void HighlightAll( bool on
);
542 // all these functions only do something if the line is currently visible
544 // change the line "selected" state, return TRUE if it really changed
545 bool HighlightLine( size_t line
, bool highlight
= TRUE
);
547 // as HighlightLine() but do it for the range of lines: this is incredibly
548 // more efficient for virtual list controls!
550 // NB: unlike HighlightLine() this one does refresh the lines on screen
551 void HighlightLines( size_t lineFrom
, size_t lineTo
, bool on
= TRUE
);
553 // toggle the line state and refresh it
554 void ReverseHighlight( size_t line
)
555 { HighlightLine(line
, !IsHighlighted(line
)); RefreshLine(line
); }
557 // return true if the line is highlighted
558 bool IsHighlighted(size_t line
) const;
560 // refresh one or several lines at once
561 void RefreshLine( size_t line
);
562 void RefreshLines( size_t lineFrom
, size_t lineTo
);
564 // refresh all lines below the given one: the difference with
565 // RefreshLines() is that the index here might not be a valid one (happens
566 // when the last line is deleted)
567 void RefreshAfter( size_t lineFrom
);
569 // the methods which are forwarded to wxListLineData itself in list/icon
570 // modes but are here because the lines don't store their positions in the
573 // get the bound rect for the entire line
574 wxRect
GetLineRect(size_t line
) const;
576 // get the bound rect of the label
577 wxRect
GetLineLabelRect(size_t line
) const;
579 // get the bound rect of the items icon (only may be called if we do have
581 wxRect
GetLineIconRect(size_t line
) const;
583 // get the rect to be highlighted when the item has focus
584 wxRect
GetLineHighlightRect(size_t line
) const;
586 // get the size of the total line rect
587 wxSize
GetLineSize(size_t line
) const
588 { return GetLineRect(line
).GetSize(); }
590 // return the hit code for the corresponding position (in this line)
591 long HitTestLine(size_t line
, int x
, int y
) const;
593 // bring the selected item into view, scrolling to it if necessary
594 void MoveToItem(size_t item
);
596 // bring the current item into view
597 void MoveToFocus() { MoveToItem(m_current
); }
599 void EditLabel( long item
);
600 void OnRenameTimer();
601 void OnRenameAccept();
603 void OnMouse( wxMouseEvent
&event
);
605 // called to switch the selection from the current item to newCurrent,
606 void OnArrowChar( size_t newCurrent
, const wxKeyEvent
& event
);
608 void OnChar( wxKeyEvent
&event
);
609 void OnKeyDown( wxKeyEvent
&event
);
610 void OnSetFocus( wxFocusEvent
&event
);
611 void OnKillFocus( wxFocusEvent
&event
);
612 void OnScroll(wxScrollWinEvent
& event
) ;
614 void OnPaint( wxPaintEvent
&event
);
616 void DrawImage( int index
, wxDC
*dc
, int x
, int y
);
617 void GetImageSize( int index
, int &width
, int &height
) const;
618 int GetTextLength( const wxString
&s
) const;
620 void SetImageList( wxImageList
*imageList
, int which
);
621 void SetItemSpacing( int spacing
, bool isSmall
= FALSE
);
622 int GetItemSpacing( bool isSmall
= FALSE
);
624 void SetColumn( int col
, wxListItem
&item
);
625 void SetColumnWidth( int col
, int width
);
626 void GetColumn( int col
, wxListItem
&item
) const;
627 int GetColumnWidth( int col
) const;
628 int GetColumnCount() const { return m_columns
.GetCount(); }
630 // returns the sum of the heights of all columns
631 int GetHeaderWidth() const;
633 int GetCountPerPage() const;
635 void SetItem( wxListItem
&item
);
636 void GetItem( wxListItem
&item
);
637 void SetItemState( long item
, long state
, long stateMask
);
638 int GetItemState( long item
, long stateMask
);
639 void GetItemRect( long index
, wxRect
&rect
);
640 bool GetItemPosition( long item
, wxPoint
& pos
);
641 int GetSelectedItemCount();
643 // set the scrollbars and update the positions of the items
644 void RecalculatePositions(bool noRefresh
= FALSE
);
646 // refresh the window and the header
649 long GetNextItem( long item
, int geometry
, int state
);
650 void DeleteItem( long index
);
651 void DeleteAllItems();
652 void DeleteColumn( int col
);
653 void DeleteEverything();
654 void EnsureVisible( long index
);
655 long FindItem( long start
, const wxString
& str
, bool partial
= FALSE
);
656 long FindItem( long start
, long data
);
657 long HitTest( int x
, int y
, int &flags
);
658 void InsertItem( wxListItem
&item
);
659 void InsertColumn( long col
, wxListItem
&item
);
660 void SortItems( wxListCtrlCompare fn
, long data
);
662 size_t GetItemCount() const;
663 bool IsEmpty() const { return GetItemCount() == 0; }
664 void SetItemCount(long count
);
666 void ResetCurrent() { m_current
= (size_t)-1; }
667 bool HasCurrent() const { return m_current
!= (size_t)-1; }
669 // send out a wxListEvent
670 void SendNotify( size_t line
,
672 wxPoint point
= wxDefaultPosition
);
674 // override base class virtual to reset m_lineHeight when the font changes
675 virtual bool SetFont(const wxFont
& font
)
677 if ( !wxScrolledWindow::SetFont(font
) )
685 // these are for wxListLineData usage only
687 // get the backpointer to the list ctrl
688 wxListCtrl
*GetListCtrl() const
690 return wxStaticCast(GetParent(), wxListCtrl
);
693 // get the height of all lines (assuming they all do have the same height)
694 wxCoord
GetLineHeight() const;
696 // get the y position of the given line (only for report view)
697 wxCoord
GetLineY(size_t line
) const;
700 // the array of all line objects for a non virtual list control
701 wxListLineDataArray m_lines
;
703 // the list of column objects
704 wxListHeaderDataList m_columns
;
706 // currently focused item or -1
709 // the item currently being edited or -1
710 size_t m_currentEdit
;
712 // the number of lines per page
715 // this flag is set when something which should result in the window
716 // redrawing happens (i.e. an item was added or deleted, or its appearance
717 // changed) and OnPaint() doesn't redraw the window while it is set which
718 // allows to minimize the number of repaintings when a lot of items are
719 // being added. The real repainting occurs only after the next OnIdle()
723 wxBrush
*m_highlightBrush
;
724 wxColour
*m_highlightColour
;
727 wxImageList
*m_small_image_list
;
728 wxImageList
*m_normal_image_list
;
730 int m_normal_spacing
;
734 wxTimer
*m_renameTimer
;
736 wxString m_renameRes
;
741 // for double click logic
742 size_t m_lineLastClicked
,
743 m_lineBeforeLastClicked
;
746 // the total count of items in a virtual list control
749 // the object maintaining the items selection state, only used in virtual
751 wxSelectionStore m_selStore
;
753 // common part of all ctors
756 // intiialize m_[xy]Scroll
757 void InitScrolling();
759 // get the line data for the given index
760 wxListLineData
*GetLine(size_t n
) const
762 wxASSERT_MSG( n
!= (size_t)-1, _T("invalid line index") );
766 wxConstCast(this, wxListMainWindow
)->CacheLineData(n
);
774 // get a dummy line which can be used for geometry calculations and such:
775 // you must use GetLine() if you want to really draw the line
776 wxListLineData
*GetDummyLine() const;
778 // cache the line data of the n-th line in m_lines[0]
779 void CacheLineData(size_t line
);
781 // get the range of visible lines
782 void GetVisibleLinesRange(size_t *from
, size_t *to
);
784 // force us to recalculate the range of visible lines
785 void ResetVisibleLinesRange() { m_lineFrom
= (size_t)-1; }
787 // get the colour to be used for drawing the rules
788 wxColour
GetRuleColour() const
793 return wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DLIGHT
);
798 // initialize the current item if needed
799 void UpdateCurrent();
801 // delete all items but don't refresh: called from dtor
802 void DoDeleteAllItems();
804 // called when an item is [un]focuded, i.e. becomes [not] current
807 void OnFocusLine( size_t line
);
808 void OnUnfocusLine( size_t line
);
810 // the height of one line using the current font
811 wxCoord m_lineHeight
;
813 // the total header width or 0 if not calculated yet
814 wxCoord m_headerWidth
;
816 // the first and last lines being shown on screen right now (inclusive),
817 // both may be -1 if they must be calculated so never access them directly:
818 // use GetVisibleLinesRange() above instead
822 DECLARE_DYNAMIC_CLASS(wxListMainWindow
);
823 DECLARE_EVENT_TABLE()
826 // ============================================================================
828 // ============================================================================
830 // ----------------------------------------------------------------------------
832 // ----------------------------------------------------------------------------
834 bool wxSelectionStore::IsSelected(size_t item
) const
836 bool isSel
= m_itemsSel
.Index(item
) != wxNOT_FOUND
;
838 // if the default state is to be selected, being in m_itemsSel means that
839 // the item is not selected, so we have to inverse the logic
840 return m_defaultState
? !isSel
: isSel
;
843 bool wxSelectionStore::SelectItem(size_t item
, bool select
)
845 // search for the item ourselves as like this we get the index where to
846 // insert it later if needed, so we do only one search in the array instead
847 // of two (adding item to a sorted array requires a search)
848 size_t index
= m_itemsSel
.IndexForInsert(item
);
849 bool isSel
= index
< m_itemsSel
.GetCount() && m_itemsSel
[index
] == item
;
851 if ( select
!= m_defaultState
)
855 m_itemsSel
.AddAt(item
, index
);
860 else // reset to default state
864 m_itemsSel
.RemoveAt(index
);
872 bool wxSelectionStore::SelectRange(size_t itemFrom
, size_t itemTo
,
874 wxArrayInt
*itemsChanged
)
876 // 100 is hardcoded but it shouldn't matter much: the important thing is
877 // that we don't refresh everything when really few (e.g. 1 or 2) items
879 static const size_t MANY_ITEMS
= 100;
881 wxASSERT_MSG( itemFrom
<= itemTo
, _T("should be in order") );
883 // are we going to have more [un]selected items than the other ones?
884 if ( itemTo
- itemFrom
> m_count
/2 )
886 if ( select
!= m_defaultState
)
888 // the default state now becomes the same as 'select'
889 m_defaultState
= select
;
891 // so all the old selections (which had state select) shouldn't be
892 // selected any more, but all the other ones should
893 wxIndexArray selOld
= m_itemsSel
;
896 // TODO: it should be possible to optimize the searches a bit
897 // knowing the possible range
900 for ( item
= 0; item
< itemFrom
; item
++ )
902 if ( selOld
.Index(item
) == wxNOT_FOUND
)
903 m_itemsSel
.Add(item
);
906 for ( item
= itemTo
+ 1; item
< m_count
; item
++ )
908 if ( selOld
.Index(item
) == wxNOT_FOUND
)
909 m_itemsSel
.Add(item
);
912 // many items (> half) changed state
915 else // select == m_defaultState
917 // get the inclusive range of items between itemFrom and itemTo
918 size_t count
= m_itemsSel
.GetCount(),
919 start
= m_itemsSel
.IndexForInsert(itemFrom
),
920 end
= m_itemsSel
.IndexForInsert(itemTo
);
922 if ( start
== count
|| m_itemsSel
[start
] < itemFrom
)
927 if ( end
== count
|| m_itemsSel
[end
] > itemTo
)
934 // delete all of them (from end to avoid changing indices)
935 for ( int i
= end
; i
>= (int)start
; i
-- )
939 if ( itemsChanged
->GetCount() > MANY_ITEMS
)
941 // stop counting (see comment below)
945 itemsChanged
->Add(m_itemsSel
[i
]);
948 m_itemsSel
.RemoveAt(i
);
953 else // "few" items change state
957 itemsChanged
->Empty();
960 // just add the items to the selection
961 for ( size_t item
= itemFrom
; item
<= itemTo
; item
++ )
963 if ( SelectItem(item
, select
) && itemsChanged
)
965 itemsChanged
->Add(item
);
967 if ( itemsChanged
->GetCount() > MANY_ITEMS
)
969 // stop counting them, we'll just eat gobs of memory
970 // for nothing at all - faster to refresh everything in
978 // we set it to NULL if there are many items changing state
979 return itemsChanged
!= NULL
;
982 void wxSelectionStore::OnItemDelete(size_t item
)
984 size_t count
= m_itemsSel
.GetCount(),
985 i
= m_itemsSel
.IndexForInsert(item
);
987 if ( i
< count
&& m_itemsSel
[i
] == item
)
989 // this item itself was in m_itemsSel, remove it from there
990 m_itemsSel
.RemoveAt(i
);
995 // and adjust the index of all which follow it
998 // all following elements must be greater than the one we deleted
999 wxASSERT_MSG( m_itemsSel
[i
] > item
, _T("logic error") );
1005 //-----------------------------------------------------------------------------
1007 //-----------------------------------------------------------------------------
1009 wxListItemData::~wxListItemData()
1011 // in the virtual list control the attributes are managed by the main
1012 // program, so don't delete them
1013 if ( !m_owner
->IsVirtual() )
1021 void wxListItemData::Init()
1029 wxListItemData::wxListItemData(wxListMainWindow
*owner
)
1035 if ( owner
->InReportView() )
1041 m_rect
= new wxRect
;
1045 void wxListItemData::SetItem( const wxListItem
&info
)
1047 if ( info
.m_mask
& wxLIST_MASK_TEXT
)
1048 SetText(info
.m_text
);
1049 if ( info
.m_mask
& wxLIST_MASK_IMAGE
)
1050 m_image
= info
.m_image
;
1051 if ( info
.m_mask
& wxLIST_MASK_DATA
)
1052 m_data
= info
.m_data
;
1054 if ( info
.HasAttributes() )
1057 *m_attr
= *info
.GetAttributes();
1059 m_attr
= new wxListItemAttr(*info
.GetAttributes());
1067 m_rect
->width
= info
.m_width
;
1071 void wxListItemData::SetPosition( int x
, int y
)
1073 wxCHECK_RET( m_rect
, _T("unexpected SetPosition() call") );
1079 void wxListItemData::SetSize( int width
, int height
)
1081 wxCHECK_RET( m_rect
, _T("unexpected SetSize() call") );
1084 m_rect
->width
= width
;
1086 m_rect
->height
= height
;
1089 bool wxListItemData::IsHit( int x
, int y
) const
1091 wxCHECK_MSG( m_rect
, FALSE
, _T("can't be called in this mode") );
1093 return wxRect(GetX(), GetY(), GetWidth(), GetHeight()).Inside(x
, y
);
1096 int wxListItemData::GetX() const
1098 wxCHECK_MSG( m_rect
, 0, _T("can't be called in this mode") );
1103 int wxListItemData::GetY() const
1105 wxCHECK_MSG( m_rect
, 0, _T("can't be called in this mode") );
1110 int wxListItemData::GetWidth() const
1112 wxCHECK_MSG( m_rect
, 0, _T("can't be called in this mode") );
1114 return m_rect
->width
;
1117 int wxListItemData::GetHeight() const
1119 wxCHECK_MSG( m_rect
, 0, _T("can't be called in this mode") );
1121 return m_rect
->height
;
1124 void wxListItemData::GetItem( wxListItem
&info
) const
1126 info
.m_text
= m_text
;
1127 info
.m_image
= m_image
;
1128 info
.m_data
= m_data
;
1132 if ( m_attr
->HasTextColour() )
1133 info
.SetTextColour(m_attr
->GetTextColour());
1134 if ( m_attr
->HasBackgroundColour() )
1135 info
.SetBackgroundColour(m_attr
->GetBackgroundColour());
1136 if ( m_attr
->HasFont() )
1137 info
.SetFont(m_attr
->GetFont());
1141 //-----------------------------------------------------------------------------
1143 //-----------------------------------------------------------------------------
1145 IMPLEMENT_DYNAMIC_CLASS(wxListHeaderData
,wxObject
);
1147 wxListHeaderData::wxListHeaderData()
1158 wxListHeaderData::wxListHeaderData( const wxListItem
&item
)
1166 void wxListHeaderData::SetItem( const wxListItem
&item
)
1168 m_mask
= item
.m_mask
;
1169 m_text
= item
.m_text
;
1170 m_image
= item
.m_image
;
1171 m_format
= item
.m_format
;
1173 SetWidth(item
.m_width
);
1176 void wxListHeaderData::SetPosition( int x
, int y
)
1182 void wxListHeaderData::SetHeight( int h
)
1187 void wxListHeaderData::SetWidth( int w
)
1191 m_width
= WIDTH_COL_DEFAULT
;
1192 if (m_width
< WIDTH_COL_MIN
)
1193 m_width
= WIDTH_COL_MIN
;
1196 void wxListHeaderData::SetFormat( int format
)
1201 bool wxListHeaderData::HasImage() const
1203 return (m_image
!= 0);
1206 bool wxListHeaderData::IsHit( int x
, int y
) const
1208 return ((x
>= m_xpos
) && (x
<= m_xpos
+m_width
) && (y
>= m_ypos
) && (y
<= m_ypos
+m_height
));
1211 void wxListHeaderData::GetItem( wxListItem
&item
)
1213 item
.m_mask
= m_mask
;
1214 item
.m_text
= m_text
;
1215 item
.m_image
= m_image
;
1216 item
.m_format
= m_format
;
1217 item
.m_width
= m_width
;
1220 int wxListHeaderData::GetImage() const
1225 int wxListHeaderData::GetWidth() const
1230 int wxListHeaderData::GetFormat() const
1235 //-----------------------------------------------------------------------------
1237 //-----------------------------------------------------------------------------
1239 inline int wxListLineData::GetMode() const
1241 return m_owner
->GetListCtrl()->GetWindowStyleFlag() & wxLC_MASK_TYPE
;
1244 inline bool wxListLineData::InReportView() const
1246 return m_owner
->HasFlag(wxLC_REPORT
);
1249 inline bool wxListLineData::IsVirtual() const
1251 return m_owner
->IsVirtual();
1254 wxListLineData::wxListLineData( wxListMainWindow
*owner
)
1257 m_items
.DeleteContents( TRUE
);
1259 if ( InReportView() )
1265 m_gi
= new GeometryInfo
;
1268 m_highlighted
= FALSE
;
1270 InitItems( GetMode() == wxLC_REPORT
? m_owner
->GetColumnCount() : 1 );
1273 void wxListLineData::CalculateSize( wxDC
*dc
, int spacing
)
1275 wxListItemDataList::Node
*node
= m_items
.GetFirst();
1276 wxCHECK_RET( node
, _T("no subitems at all??") );
1278 wxListItemData
*item
= node
->GetData();
1280 switch ( GetMode() )
1283 case wxLC_SMALL_ICON
:
1285 m_gi
->m_rectAll
.width
= spacing
;
1287 wxString s
= item
->GetText();
1293 m_gi
->m_rectLabel
.width
=
1294 m_gi
->m_rectLabel
.height
= 0;
1298 dc
->GetTextExtent( s
, &lw
, &lh
);
1299 if (lh
< SCROLL_UNIT_Y
)
1304 m_gi
->m_rectAll
.height
= spacing
+ lh
;
1306 m_gi
->m_rectAll
.width
= lw
;
1308 m_gi
->m_rectLabel
.width
= lw
;
1309 m_gi
->m_rectLabel
.height
= lh
;
1312 if (item
->HasImage())
1315 m_owner
->GetImageSize( item
->GetImage(), w
, h
);
1316 m_gi
->m_rectIcon
.width
= w
+ 8;
1317 m_gi
->m_rectIcon
.height
= h
+ 8;
1319 if ( m_gi
->m_rectIcon
.width
> m_gi
->m_rectAll
.width
)
1320 m_gi
->m_rectAll
.width
= m_gi
->m_rectIcon
.width
;
1321 if ( m_gi
->m_rectIcon
.height
+ lh
> m_gi
->m_rectAll
.height
- 4 )
1322 m_gi
->m_rectAll
.height
= m_gi
->m_rectIcon
.height
+ lh
+ 4;
1325 if ( item
->HasText() )
1327 m_gi
->m_rectHighlight
.width
= m_gi
->m_rectLabel
.width
;
1328 m_gi
->m_rectHighlight
.height
= m_gi
->m_rectLabel
.height
;
1330 else // no text, highlight the icon
1332 m_gi
->m_rectHighlight
.width
= m_gi
->m_rectIcon
.width
;
1333 m_gi
->m_rectHighlight
.height
= m_gi
->m_rectIcon
.height
;
1340 wxString s
= item
->GetTextForMeasuring();
1343 dc
->GetTextExtent( s
, &lw
, &lh
);
1344 if (lh
< SCROLL_UNIT_Y
)
1349 m_gi
->m_rectLabel
.width
= lw
;
1350 m_gi
->m_rectLabel
.height
= lh
;
1352 m_gi
->m_rectAll
.width
= lw
;
1353 m_gi
->m_rectAll
.height
= lh
;
1355 if (item
->HasImage())
1358 m_owner
->GetImageSize( item
->GetImage(), w
, h
);
1359 m_gi
->m_rectIcon
.width
= w
;
1360 m_gi
->m_rectIcon
.height
= h
;
1362 m_gi
->m_rectAll
.width
+= 4 + w
;
1363 if (h
> m_gi
->m_rectAll
.height
)
1364 m_gi
->m_rectAll
.height
= h
;
1367 m_gi
->m_rectHighlight
.width
= m_gi
->m_rectAll
.width
;
1368 m_gi
->m_rectHighlight
.height
= m_gi
->m_rectAll
.height
;
1373 wxFAIL_MSG( _T("unexpected call to SetSize") );
1377 wxFAIL_MSG( _T("unknown mode") );
1381 void wxListLineData::SetPosition( int x
, int y
,
1385 wxListItemDataList::Node
*node
= m_items
.GetFirst();
1386 wxCHECK_RET( node
, _T("no subitems at all??") );
1388 wxListItemData
*item
= node
->GetData();
1390 switch ( GetMode() )
1393 case wxLC_SMALL_ICON
:
1394 m_gi
->m_rectAll
.x
= x
;
1395 m_gi
->m_rectAll
.y
= y
;
1397 if ( item
->HasImage() )
1399 m_gi
->m_rectIcon
.x
= m_gi
->m_rectAll
.x
+ 4
1400 + (spacing
- m_gi
->m_rectIcon
.width
)/2;
1401 m_gi
->m_rectIcon
.y
= m_gi
->m_rectAll
.y
+ 4;
1404 if ( item
->HasText() )
1406 if (m_gi
->m_rectAll
.width
> spacing
)
1407 m_gi
->m_rectLabel
.x
= m_gi
->m_rectAll
.x
+ 2;
1409 m_gi
->m_rectLabel
.x
= m_gi
->m_rectAll
.x
+ 2 + (spacing
/2) - (m_gi
->m_rectLabel
.width
/2);
1410 m_gi
->m_rectLabel
.y
= m_gi
->m_rectAll
.y
+ m_gi
->m_rectAll
.height
+ 2 - m_gi
->m_rectLabel
.height
;
1411 m_gi
->m_rectHighlight
.x
= m_gi
->m_rectLabel
.x
- 2;
1412 m_gi
->m_rectHighlight
.y
= m_gi
->m_rectLabel
.y
- 2;
1414 else // no text, highlight the icon
1416 m_gi
->m_rectHighlight
.x
= m_gi
->m_rectIcon
.x
- 4;
1417 m_gi
->m_rectHighlight
.y
= m_gi
->m_rectIcon
.y
- 4;
1422 m_gi
->m_rectAll
.x
= x
;
1423 m_gi
->m_rectAll
.y
= y
;
1425 m_gi
->m_rectHighlight
.x
= m_gi
->m_rectAll
.x
;
1426 m_gi
->m_rectHighlight
.y
= m_gi
->m_rectAll
.y
;
1427 m_gi
->m_rectLabel
.y
= m_gi
->m_rectAll
.y
+ 2;
1429 if (item
->HasImage())
1431 m_gi
->m_rectIcon
.x
= m_gi
->m_rectAll
.x
+ 2;
1432 m_gi
->m_rectIcon
.y
= m_gi
->m_rectAll
.y
+ 2;
1433 m_gi
->m_rectLabel
.x
= m_gi
->m_rectAll
.x
+ 6 + m_gi
->m_rectIcon
.width
;
1437 m_gi
->m_rectLabel
.x
= m_gi
->m_rectAll
.x
+ 2;
1442 wxFAIL_MSG( _T("unexpected call to SetPosition") );
1446 wxFAIL_MSG( _T("unknown mode") );
1450 void wxListLineData::InitItems( int num
)
1452 for (int i
= 0; i
< num
; i
++)
1453 m_items
.Append( new wxListItemData(m_owner
) );
1456 void wxListLineData::SetItem( int index
, const wxListItem
&info
)
1458 wxListItemDataList::Node
*node
= m_items
.Item( index
);
1459 wxCHECK_RET( node
, _T("invalid column index in SetItem") );
1461 wxListItemData
*item
= node
->GetData();
1462 item
->SetItem( info
);
1465 void wxListLineData::GetItem( int index
, wxListItem
&info
)
1467 wxListItemDataList::Node
*node
= m_items
.Item( index
);
1470 wxListItemData
*item
= node
->GetData();
1471 item
->GetItem( info
);
1475 wxString
wxListLineData::GetText(int index
) const
1479 wxListItemDataList::Node
*node
= m_items
.Item( index
);
1482 wxListItemData
*item
= node
->GetData();
1483 s
= item
->GetText();
1489 void wxListLineData::SetText( int index
, const wxString s
)
1491 wxListItemDataList::Node
*node
= m_items
.Item( index
);
1494 wxListItemData
*item
= node
->GetData();
1499 void wxListLineData::SetImage( int index
, int image
)
1501 wxListItemDataList::Node
*node
= m_items
.Item( index
);
1502 wxCHECK_RET( node
, _T("invalid column index in SetImage()") );
1504 wxListItemData
*item
= node
->GetData();
1505 item
->SetImage(image
);
1508 int wxListLineData::GetImage( int index
) const
1510 wxListItemDataList::Node
*node
= m_items
.Item( index
);
1511 wxCHECK_MSG( node
, -1, _T("invalid column index in GetImage()") );
1513 wxListItemData
*item
= node
->GetData();
1514 return item
->GetImage();
1517 wxListItemAttr
*wxListLineData::GetAttr() const
1519 wxListItemDataList::Node
*node
= m_items
.GetFirst();
1520 wxCHECK_MSG( node
, NULL
, _T("invalid column index in GetAttr()") );
1522 wxListItemData
*item
= node
->GetData();
1523 return item
->GetAttr();
1526 void wxListLineData::SetAttr(wxListItemAttr
*attr
)
1528 wxListItemDataList::Node
*node
= m_items
.GetFirst();
1529 wxCHECK_RET( node
, _T("invalid column index in SetAttr()") );
1531 wxListItemData
*item
= node
->GetData();
1532 item
->SetAttr(attr
);
1535 bool wxListLineData::SetAttributes(wxDC
*dc
,
1536 const wxListItemAttr
*attr
,
1539 wxWindow
*listctrl
= m_owner
->GetParent();
1543 // don't use foreground colour for drawing highlighted items - this might
1544 // make them completely invisible (and there is no way to do bit
1545 // arithmetics on wxColour, unfortunately)
1549 colText
= wxSystemSettings::GetSystemColour(wxSYS_COLOUR_HIGHLIGHTTEXT
);
1553 if ( attr
&& attr
->HasTextColour() )
1555 colText
= attr
->GetTextColour();
1559 colText
= listctrl
->GetForegroundColour();
1563 dc
->SetTextForeground(colText
);
1567 if ( attr
&& attr
->HasFont() )
1569 font
= attr
->GetFont();
1573 font
= listctrl
->GetFont();
1579 bool hasBgCol
= attr
&& attr
->HasBackgroundColour();
1580 if ( highlighted
|| hasBgCol
)
1584 dc
->SetBrush( *m_owner
->m_highlightBrush
);
1588 dc
->SetBrush(wxBrush(attr
->GetBackgroundColour(), wxSOLID
));
1591 dc
->SetPen( *wxTRANSPARENT_PEN
);
1599 void wxListLineData::Draw( wxDC
*dc
)
1601 wxListItemDataList::Node
*node
= m_items
.GetFirst();
1602 wxCHECK_RET( node
, _T("no subitems at all??") );
1604 bool highlighted
= IsHighlighted();
1606 wxListItemAttr
*attr
= GetAttr();
1608 if ( SetAttributes(dc
, attr
, highlighted
) )
1610 dc
->DrawRectangle( m_gi
->m_rectHighlight
);
1613 wxListItemData
*item
= node
->GetData();
1614 if (item
->HasImage())
1616 wxRect rectIcon
= m_gi
->m_rectIcon
;
1617 m_owner
->DrawImage( item
->GetImage(), dc
,
1618 rectIcon
.x
, rectIcon
.y
);
1621 if (item
->HasText())
1623 wxRect rectLabel
= m_gi
->m_rectLabel
;
1624 dc
->DrawText( item
->GetText(), rectLabel
.x
, rectLabel
.y
);
1628 void wxListLineData::DrawInReportMode( wxDC
*dc
,
1630 const wxRect
& rectHL
,
1633 // use our own flag if we maintain it
1635 highlighted
= m_highlighted
;
1637 // TODO: later we should support setting different attributes for
1638 // different columns - to do it, just add "col" argument to
1639 // GetAttr() and move these lines into the loop below
1640 wxListItemAttr
*attr
= GetAttr();
1641 if ( SetAttributes(dc
, attr
, highlighted
) )
1643 dc
->DrawRectangle( rectHL
);
1646 wxListItemDataList::Node
*node
= m_items
.GetFirst();
1647 wxCHECK_RET( node
, _T("no subitems at all??") );
1650 wxCoord x
= rect
.x
+ HEADER_OFFSET_X
,
1651 y
= rect
.y
+ (LINE_SPACING
+ EXTRA_HEIGHT
) / 2;
1655 wxListItemData
*item
= node
->GetData();
1659 if ( item
->HasImage() )
1662 m_owner
->DrawImage( item
->GetImage(), dc
, x
, y
);
1663 m_owner
->GetImageSize( item
->GetImage(), ix
, iy
);
1664 x
+= ix
+ 5; // FIXME: what is "5"?
1667 int width
= m_owner
->GetColumnWidth(col
++);
1669 wxDCClipper
clipper(*dc
, x
, y
, width
, rect
.height
);
1671 if ( item
->HasText() )
1673 dc
->DrawText( item
->GetText(), x
, y
);
1678 node
= node
->GetNext();
1682 bool wxListLineData::Highlight( bool on
)
1684 wxCHECK_MSG( !m_owner
->IsVirtual(), FALSE
, _T("unexpected call to Highlight") );
1686 if ( on
== m_highlighted
)
1694 void wxListLineData::ReverseHighlight( void )
1696 Highlight(!IsHighlighted());
1699 //-----------------------------------------------------------------------------
1700 // wxListHeaderWindow
1701 //-----------------------------------------------------------------------------
1703 IMPLEMENT_DYNAMIC_CLASS(wxListHeaderWindow
,wxWindow
);
1705 BEGIN_EVENT_TABLE(wxListHeaderWindow
,wxWindow
)
1706 EVT_PAINT (wxListHeaderWindow::OnPaint
)
1707 EVT_MOUSE_EVENTS (wxListHeaderWindow::OnMouse
)
1708 EVT_SET_FOCUS (wxListHeaderWindow::OnSetFocus
)
1711 wxListHeaderWindow::wxListHeaderWindow( void )
1713 m_owner
= (wxListMainWindow
*) NULL
;
1714 m_currentCursor
= (wxCursor
*) NULL
;
1715 m_resizeCursor
= (wxCursor
*) NULL
;
1716 m_isDragging
= FALSE
;
1719 wxListHeaderWindow::wxListHeaderWindow( wxWindow
*win
, wxWindowID id
, wxListMainWindow
*owner
,
1720 const wxPoint
&pos
, const wxSize
&size
,
1721 long style
, const wxString
&name
) :
1722 wxWindow( win
, id
, pos
, size
, style
, name
)
1725 // m_currentCursor = wxSTANDARD_CURSOR;
1726 m_currentCursor
= (wxCursor
*) NULL
;
1727 m_resizeCursor
= new wxCursor( wxCURSOR_SIZEWE
);
1728 m_isDragging
= FALSE
;
1731 SetBackgroundColour( wxSystemSettings::GetSystemColour( wxSYS_COLOUR_BTNFACE
) );
1734 wxListHeaderWindow::~wxListHeaderWindow( void )
1736 delete m_resizeCursor
;
1739 void wxListHeaderWindow::DoDrawRect( wxDC
*dc
, int x
, int y
, int w
, int h
)
1742 GtkStateType state
= m_parent
->IsEnabled() ? GTK_STATE_NORMAL
1743 : GTK_STATE_INSENSITIVE
;
1745 x
= dc
->XLOG2DEV( x
);
1747 gtk_paint_box (m_wxwindow
->style
, GTK_PIZZA(m_wxwindow
)->bin_window
,
1748 state
, GTK_SHADOW_OUT
,
1749 (GdkRectangle
*) NULL
, m_wxwindow
, "button",
1750 x
-1, y
-1, w
+2, h
+2);
1751 #elif defined( __WXMAC__ )
1752 const int m_corner
= 1;
1754 dc
->SetBrush( *wxTRANSPARENT_BRUSH
);
1756 dc
->SetPen( wxPen( wxSystemSettings::GetSystemColour( wxSYS_COLOUR_BTNSHADOW
) , 1 , wxSOLID
) );
1757 dc
->DrawLine( x
+w
-m_corner
+1, y
, x
+w
, y
+h
); // right (outer)
1758 dc
->DrawRectangle( x
, y
+h
, w
+1, 1 ); // bottom (outer)
1760 wxPen
pen( wxColour( 0x88 , 0x88 , 0x88 ), 1, wxSOLID
);
1763 dc
->DrawLine( x
+w
-m_corner
, y
, x
+w
-1, y
+h
); // right (inner)
1764 dc
->DrawRectangle( x
+1, y
+h
-1, w
-2, 1 ); // bottom (inner)
1766 dc
->SetPen( *wxWHITE_PEN
);
1767 dc
->DrawRectangle( x
, y
, w
-m_corner
+1, 1 ); // top (outer)
1768 dc
->DrawRectangle( x
, y
, 1, h
); // left (outer)
1769 dc
->DrawLine( x
, y
+h
-1, x
+1, y
+h
-1 );
1770 dc
->DrawLine( x
+w
-1, y
, x
+w
-1, y
+1 );
1772 const int m_corner
= 1;
1774 dc
->SetBrush( *wxTRANSPARENT_BRUSH
);
1776 dc
->SetPen( *wxBLACK_PEN
);
1777 dc
->DrawLine( x
+w
-m_corner
+1, y
, x
+w
, y
+h
); // right (outer)
1778 dc
->DrawRectangle( x
, y
+h
, w
+1, 1 ); // bottom (outer)
1780 wxPen
pen( wxSystemSettings::GetSystemColour( wxSYS_COLOUR_BTNSHADOW
), 1, wxSOLID
);
1783 dc
->DrawLine( x
+w
-m_corner
, y
, x
+w
-1, y
+h
); // right (inner)
1784 dc
->DrawRectangle( x
+1, y
+h
-1, w
-2, 1 ); // bottom (inner)
1786 dc
->SetPen( *wxWHITE_PEN
);
1787 dc
->DrawRectangle( x
, y
, w
-m_corner
+1, 1 ); // top (outer)
1788 dc
->DrawRectangle( x
, y
, 1, h
); // left (outer)
1789 dc
->DrawLine( x
, y
+h
-1, x
+1, y
+h
-1 );
1790 dc
->DrawLine( x
+w
-1, y
, x
+w
-1, y
+1 );
1794 // shift the DC origin to match the position of the main window horz
1795 // scrollbar: this allows us to always use logical coords
1796 void wxListHeaderWindow::AdjustDC(wxDC
& dc
)
1799 m_owner
->GetScrollPixelsPerUnit( &xpix
, NULL
);
1802 m_owner
->GetViewStart( &x
, NULL
);
1804 // account for the horz scrollbar offset
1805 dc
.SetDeviceOrigin( -x
* xpix
, 0 );
1808 void wxListHeaderWindow::OnPaint( wxPaintEvent
&WXUNUSED(event
) )
1811 wxClientDC
dc( this );
1813 wxPaintDC
dc( this );
1821 dc
.SetFont( GetFont() );
1823 // width and height of the entire header window
1825 GetClientSize( &w
, &h
);
1826 m_owner
->CalcUnscrolledPosition(w
, 0, &w
, NULL
);
1828 dc
.SetBackgroundMode(wxTRANSPARENT
);
1830 // do *not* use the listctrl colour for headers - one day we will have a
1831 // function to set it separately
1832 //dc.SetTextForeground( *wxBLACK );
1833 dc
.SetTextForeground(wxSystemSettings::
1834 GetSystemColour( wxSYS_COLOUR_WINDOWTEXT
));
1836 int x
= HEADER_OFFSET_X
;
1838 int numColumns
= m_owner
->GetColumnCount();
1840 for (int i
= 0; i
< numColumns
; i
++)
1842 m_owner
->GetColumn( i
, item
);
1843 int wCol
= item
.m_width
;
1844 int cw
= wCol
- 2; // the width of the rect to draw
1846 int xEnd
= x
+ wCol
;
1848 dc
.SetPen( *wxWHITE_PEN
);
1850 DoDrawRect( &dc
, x
, HEADER_OFFSET_Y
, cw
, h
-2 );
1851 dc
.SetClippingRegion( x
, HEADER_OFFSET_Y
, cw
-5, h
-4 );
1852 dc
.DrawText( item
.GetText(), x
+ EXTRA_WIDTH
, HEADER_OFFSET_Y
+ EXTRA_HEIGHT
);
1853 dc
.DestroyClippingRegion();
1862 void wxListHeaderWindow::DrawCurrent()
1864 int x1
= m_currentX
;
1866 ClientToScreen( &x1
, &y1
);
1868 int x2
= m_currentX
-1;
1870 m_owner
->GetClientSize( NULL
, &y2
);
1871 m_owner
->ClientToScreen( &x2
, &y2
);
1874 dc
.SetLogicalFunction( wxINVERT
);
1875 dc
.SetPen( wxPen( *wxBLACK
, 2, wxSOLID
) );
1876 dc
.SetBrush( *wxTRANSPARENT_BRUSH
);
1880 dc
.DrawLine( x1
, y1
, x2
, y2
);
1882 dc
.SetLogicalFunction( wxCOPY
);
1884 dc
.SetPen( wxNullPen
);
1885 dc
.SetBrush( wxNullBrush
);
1888 void wxListHeaderWindow::OnMouse( wxMouseEvent
&event
)
1890 // we want to work with logical coords
1892 m_owner
->CalcUnscrolledPosition(event
.GetX(), 0, &x
, NULL
);
1893 int y
= event
.GetY();
1897 // we don't draw the line beyond our window, but we allow dragging it
1900 GetClientSize( &w
, NULL
);
1901 m_owner
->CalcUnscrolledPosition(w
, 0, &w
, NULL
);
1904 // erase the line if it was drawn
1905 if ( m_currentX
< w
)
1908 if (event
.ButtonUp())
1911 m_isDragging
= FALSE
;
1913 m_owner
->SetColumnWidth( m_column
, m_currentX
- m_minX
);
1920 m_currentX
= m_minX
+ 7;
1922 // draw in the new location
1923 if ( m_currentX
< w
)
1927 else // not dragging
1930 bool hit_border
= FALSE
;
1932 // end of the current column
1935 // find the column where this event occured
1936 int countCol
= m_owner
->GetColumnCount();
1937 for (int col
= 0; col
< countCol
; col
++)
1939 xpos
+= m_owner
->GetColumnWidth( col
);
1942 if ( (abs(x
-xpos
) < 3) && (y
< 22) )
1944 // near the column border
1951 // inside the column
1958 if (event
.LeftDown())
1962 m_isDragging
= TRUE
;
1969 wxWindow
*parent
= GetParent();
1970 wxListEvent
le( wxEVT_COMMAND_LIST_COL_CLICK
, parent
->GetId() );
1971 le
.SetEventObject( parent
);
1972 le
.m_col
= m_column
;
1973 parent
->GetEventHandler()->ProcessEvent( le
);
1976 else if (event
.Moving())
1981 setCursor
= m_currentCursor
== wxSTANDARD_CURSOR
;
1982 m_currentCursor
= m_resizeCursor
;
1986 setCursor
= m_currentCursor
!= wxSTANDARD_CURSOR
;
1987 m_currentCursor
= wxSTANDARD_CURSOR
;
1991 SetCursor(*m_currentCursor
);
1996 void wxListHeaderWindow::OnSetFocus( wxFocusEvent
&WXUNUSED(event
) )
1998 m_owner
->SetFocus();
2001 //-----------------------------------------------------------------------------
2002 // wxListRenameTimer (internal)
2003 //-----------------------------------------------------------------------------
2005 wxListRenameTimer::wxListRenameTimer( wxListMainWindow
*owner
)
2010 void wxListRenameTimer::Notify()
2012 m_owner
->OnRenameTimer();
2015 //-----------------------------------------------------------------------------
2016 // wxListTextCtrl (internal)
2017 //-----------------------------------------------------------------------------
2019 IMPLEMENT_DYNAMIC_CLASS(wxListTextCtrl
,wxTextCtrl
);
2021 BEGIN_EVENT_TABLE(wxListTextCtrl
,wxTextCtrl
)
2022 EVT_CHAR (wxListTextCtrl::OnChar
)
2023 EVT_KEY_UP (wxListTextCtrl::OnKeyUp
)
2024 EVT_KILL_FOCUS (wxListTextCtrl::OnKillFocus
)
2027 wxListTextCtrl::wxListTextCtrl( wxWindow
*parent
,
2028 const wxWindowID id
,
2031 wxListMainWindow
*owner
,
2032 const wxString
&value
,
2036 const wxValidator
& validator
,
2037 const wxString
&name
)
2038 : wxTextCtrl( parent
, id
, value
, pos
, size
, style
, validator
, name
)
2043 (*m_accept
) = FALSE
;
2045 m_startValue
= value
;
2048 void wxListTextCtrl::OnChar( wxKeyEvent
&event
)
2050 if (event
.m_keyCode
== WXK_RETURN
)
2053 (*m_res
) = GetValue();
2055 if (!wxPendingDelete
.Member(this))
2056 wxPendingDelete
.Append(this);
2058 if ((*m_accept
) && ((*m_res
) != m_startValue
))
2059 m_owner
->OnRenameAccept();
2063 if (event
.m_keyCode
== WXK_ESCAPE
)
2065 (*m_accept
) = FALSE
;
2068 if (!wxPendingDelete
.Member(this))
2069 wxPendingDelete
.Append(this);
2077 void wxListTextCtrl::OnKeyUp( wxKeyEvent
&event
)
2079 // auto-grow the textctrl:
2080 wxSize parentSize
= m_owner
->GetSize();
2081 wxPoint myPos
= GetPosition();
2082 wxSize mySize
= GetSize();
2084 GetTextExtent(GetValue() + _T("MM"), &sx
, &sy
); // FIXME: MM??
2085 if (myPos
.x
+ sx
> parentSize
.x
)
2086 sx
= parentSize
.x
- myPos
.x
;
2094 void wxListTextCtrl::OnKillFocus( wxFocusEvent
&WXUNUSED(event
) )
2096 if (!wxPendingDelete
.Member(this))
2097 wxPendingDelete
.Append(this);
2099 if ((*m_accept
) && ((*m_res
) != m_startValue
))
2100 m_owner
->OnRenameAccept();
2103 //-----------------------------------------------------------------------------
2105 //-----------------------------------------------------------------------------
2107 IMPLEMENT_DYNAMIC_CLASS(wxListMainWindow
,wxScrolledWindow
);
2109 BEGIN_EVENT_TABLE(wxListMainWindow
,wxScrolledWindow
)
2110 EVT_PAINT (wxListMainWindow::OnPaint
)
2111 EVT_MOUSE_EVENTS (wxListMainWindow::OnMouse
)
2112 EVT_CHAR (wxListMainWindow::OnChar
)
2113 EVT_KEY_DOWN (wxListMainWindow::OnKeyDown
)
2114 EVT_SET_FOCUS (wxListMainWindow::OnSetFocus
)
2115 EVT_KILL_FOCUS (wxListMainWindow::OnKillFocus
)
2116 EVT_SCROLLWIN (wxListMainWindow::OnScroll
)
2119 void wxListMainWindow::Init()
2121 m_columns
.DeleteContents( TRUE
);
2125 m_lineTo
= (size_t)-1;
2131 m_small_image_list
= (wxImageList
*) NULL
;
2132 m_normal_image_list
= (wxImageList
*) NULL
;
2134 m_small_spacing
= 30;
2135 m_normal_spacing
= 40;
2139 m_isCreated
= FALSE
;
2141 m_lastOnSame
= FALSE
;
2142 m_renameTimer
= new wxListRenameTimer( this );
2143 m_renameAccept
= FALSE
;
2148 m_lineBeforeLastClicked
= (size_t)-1;
2151 void wxListMainWindow::InitScrolling()
2153 if ( HasFlag(wxLC_REPORT
) )
2155 m_xScroll
= SCROLL_UNIT_X
;
2156 m_yScroll
= SCROLL_UNIT_Y
;
2160 m_xScroll
= SCROLL_UNIT_Y
;
2165 wxListMainWindow::wxListMainWindow()
2169 m_highlightBrush
= (wxBrush
*) NULL
;
2175 wxListMainWindow::wxListMainWindow( wxWindow
*parent
,
2180 const wxString
&name
)
2181 : wxScrolledWindow( parent
, id
, pos
, size
,
2182 style
| wxHSCROLL
| wxVSCROLL
, name
)
2186 m_highlightBrush
= new wxBrush( wxSystemSettings::GetSystemColour(wxSYS_COLOUR_HIGHLIGHT
), wxSOLID
);
2191 SetScrollbars( m_xScroll
, m_yScroll
, 0, 0, 0, 0 );
2193 SetBackgroundColour( wxSystemSettings::GetSystemColour( wxSYS_COLOUR_LISTBOX
) );
2196 wxListMainWindow::~wxListMainWindow()
2200 delete m_highlightBrush
;
2202 delete m_renameTimer
;
2205 void wxListMainWindow::CacheLineData(size_t line
)
2207 wxListCtrl
*listctrl
= GetListCtrl();
2209 wxListLineData
*ld
= GetDummyLine();
2211 size_t countCol
= GetColumnCount();
2212 for ( size_t col
= 0; col
< countCol
; col
++ )
2214 ld
->SetText(col
, listctrl
->OnGetItemText(line
, col
));
2217 ld
->SetImage(listctrl
->OnGetItemImage(line
));
2218 ld
->SetAttr(listctrl
->OnGetItemAttr(line
));
2221 wxListLineData
*wxListMainWindow::GetDummyLine() const
2223 wxASSERT_MSG( !IsEmpty(), _T("invalid line index") );
2225 if ( m_lines
.IsEmpty() )
2227 // normal controls are supposed to have something in m_lines
2228 // already if it's not empty
2229 wxASSERT_MSG( IsVirtual(), _T("logic error") );
2231 wxListMainWindow
*self
= wxConstCast(this, wxListMainWindow
);
2232 wxListLineData
*line
= new wxListLineData(self
);
2233 self
->m_lines
.Add(line
);
2239 // ----------------------------------------------------------------------------
2240 // line geometry (report mode only)
2241 // ----------------------------------------------------------------------------
2243 wxCoord
wxListMainWindow::GetLineHeight() const
2245 wxASSERT_MSG( HasFlag(wxLC_REPORT
), _T("only works in report mode") );
2247 // we cache the line height as calling GetTextExtent() is slow
2248 if ( !m_lineHeight
)
2250 wxListMainWindow
*self
= wxConstCast(this, wxListMainWindow
);
2252 wxClientDC
dc( self
);
2253 dc
.SetFont( GetFont() );
2256 dc
.GetTextExtent(_T("H"), NULL
, &y
);
2258 if ( y
< SCROLL_UNIT_Y
)
2262 self
->m_lineHeight
= y
+ LINE_SPACING
;
2265 return m_lineHeight
;
2268 wxCoord
wxListMainWindow::GetLineY(size_t line
) const
2270 wxASSERT_MSG( HasFlag(wxLC_REPORT
), _T("only works in report mode") );
2272 return LINE_SPACING
+ line
*GetLineHeight();
2275 wxRect
wxListMainWindow::GetLineRect(size_t line
) const
2277 if ( !InReportView() )
2278 return GetLine(line
)->m_gi
->m_rectAll
;
2281 rect
.x
= HEADER_OFFSET_X
;
2282 rect
.y
= GetLineY(line
);
2283 rect
.width
= GetHeaderWidth();
2284 rect
.height
= GetLineHeight();
2289 wxRect
wxListMainWindow::GetLineLabelRect(size_t line
) const
2291 if ( !InReportView() )
2292 return GetLine(line
)->m_gi
->m_rectLabel
;
2295 rect
.x
= HEADER_OFFSET_X
;
2296 rect
.y
= GetLineY(line
);
2297 rect
.width
= GetColumnWidth(0);
2298 rect
.height
= GetLineHeight();
2303 wxRect
wxListMainWindow::GetLineIconRect(size_t line
) const
2305 if ( !InReportView() )
2306 return GetLine(line
)->m_gi
->m_rectIcon
;
2308 wxListLineData
*ld
= GetLine(line
);
2309 wxASSERT_MSG( ld
->HasImage(), _T("should have an image") );
2312 rect
.x
= HEADER_OFFSET_X
;
2313 rect
.y
= GetLineY(line
);
2314 GetImageSize(ld
->GetImage(), rect
.width
, rect
.height
);
2319 wxRect
wxListMainWindow::GetLineHighlightRect(size_t line
) const
2321 return InReportView() ? GetLineRect(line
)
2322 : GetLine(line
)->m_gi
->m_rectHighlight
;
2325 long wxListMainWindow::HitTestLine(size_t line
, int x
, int y
) const
2327 wxListLineData
*ld
= GetLine(line
);
2329 if ( ld
->HasImage() && GetLineIconRect(line
).Inside(x
, y
) )
2330 return wxLIST_HITTEST_ONITEMICON
;
2332 if ( ld
->HasText() )
2334 wxRect rect
= InReportView() ? GetLineRect(line
)
2335 : GetLineLabelRect(line
);
2337 if ( rect
.Inside(x
, y
) )
2338 return wxLIST_HITTEST_ONITEMLABEL
;
2344 // ----------------------------------------------------------------------------
2345 // highlight (selection) handling
2346 // ----------------------------------------------------------------------------
2348 bool wxListMainWindow::IsHighlighted(size_t line
) const
2352 return m_selStore
.IsSelected(line
);
2356 wxListLineData
*ld
= GetLine(line
);
2357 wxCHECK_MSG( ld
, FALSE
, _T("invalid index in IsHighlighted") );
2359 return ld
->IsHighlighted();
2363 void wxListMainWindow::HighlightLines( size_t lineFrom
,
2369 wxArrayInt linesChanged
;
2370 if ( !m_selStore
.SelectRange(lineFrom
, lineTo
, highlight
,
2373 // meny items changed state, refresh everything
2374 RefreshLines(lineFrom
, lineTo
);
2376 else // only a few items changed state, refresh only them
2378 size_t count
= linesChanged
.GetCount();
2379 for ( size_t n
= 0; n
< count
; n
++ )
2381 RefreshLine(linesChanged
[n
]);
2385 else // iterate over all items in non report view
2387 for ( size_t line
= lineFrom
; line
<= lineTo
; line
++ )
2389 if ( HighlightLine(line
, highlight
) )
2397 bool wxListMainWindow::HighlightLine( size_t line
, bool highlight
)
2403 changed
= m_selStore
.SelectItem(line
, highlight
);
2407 wxListLineData
*ld
= GetLine(line
);
2408 wxCHECK_MSG( ld
, FALSE
, _T("invalid index in IsHighlighted") );
2410 changed
= ld
->Highlight(highlight
);
2415 SendNotify( line
, highlight
? wxEVT_COMMAND_LIST_ITEM_SELECTED
2416 : wxEVT_COMMAND_LIST_ITEM_DESELECTED
);
2422 void wxListMainWindow::RefreshLine( size_t line
)
2424 wxRect rect
= GetLineRect(line
);
2426 CalcScrolledPosition( rect
.x
, rect
.y
, &rect
.x
, &rect
.y
);
2427 RefreshRect( rect
);
2430 void wxListMainWindow::RefreshLines( size_t lineFrom
, size_t lineTo
)
2432 // we suppose that they are ordered by caller
2433 wxASSERT_MSG( lineFrom
<= lineTo
, _T("indices in disorder") );
2435 wxASSERT_MSG( lineTo
< GetItemCount(), _T("invalid line range") );
2437 if ( HasFlag(wxLC_REPORT
) )
2439 size_t visibleFrom
, visibleTo
;
2440 GetVisibleLinesRange(&visibleFrom
, &visibleTo
);
2442 if ( lineFrom
< visibleFrom
)
2443 lineFrom
= visibleFrom
;
2444 if ( lineTo
> visibleTo
)
2449 rect
.y
= GetLineY(lineFrom
);
2450 rect
.width
= GetClientSize().x
;
2451 rect
.height
= GetLineY(lineTo
) - rect
.y
+ GetLineHeight();
2453 CalcScrolledPosition( rect
.x
, rect
.y
, &rect
.x
, &rect
.y
);
2454 RefreshRect( rect
);
2458 // TODO: this should be optimized...
2459 for ( size_t line
= lineFrom
; line
<= lineTo
; line
++ )
2466 void wxListMainWindow::RefreshAfter( size_t lineFrom
)
2468 if ( HasFlag(wxLC_REPORT
) )
2471 GetVisibleLinesRange(&visibleFrom
, NULL
);
2473 if ( lineFrom
< visibleFrom
)
2474 lineFrom
= visibleFrom
;
2478 rect
.y
= GetLineY(lineFrom
);
2480 wxSize size
= GetClientSize();
2481 rect
.width
= size
.x
;
2482 // refresh till the bottom of the window
2483 rect
.height
= size
.y
- rect
.y
;
2485 CalcScrolledPosition( rect
.x
, rect
.y
, &rect
.x
, &rect
.y
);
2486 RefreshRect( rect
);
2490 // TODO: how to do it more efficiently?
2495 void wxListMainWindow::OnPaint( wxPaintEvent
&WXUNUSED(event
) )
2497 // Note: a wxPaintDC must be constructed even if no drawing is
2498 // done (a Windows requirement).
2499 wxPaintDC
dc( this );
2503 // empty control. nothing to draw
2509 // delay the repainting until we calculate all the items positions
2516 CalcScrolledPosition( 0, 0, &dev_x
, &dev_y
);
2520 dc
.SetFont( GetFont() );
2522 if ( HasFlag(wxLC_REPORT
) )
2524 int lineHeight
= GetLineHeight();
2526 size_t visibleFrom
, visibleTo
;
2527 GetVisibleLinesRange(&visibleFrom
, &visibleTo
);
2530 wxCoord xOrig
, yOrig
;
2531 CalcUnscrolledPosition(0, 0, &xOrig
, &yOrig
);
2533 // tell the caller cache to cache the data
2536 wxListEvent
evCache(wxEVT_COMMAND_LIST_CACHE_HINT
,
2537 GetParent()->GetId());
2538 evCache
.SetEventObject( GetParent() );
2539 evCache
.m_oldItemIndex
= visibleFrom
;
2540 evCache
.m_itemIndex
= visibleTo
;
2541 GetParent()->GetEventHandler()->ProcessEvent( evCache
);
2544 for ( size_t line
= visibleFrom
; line
<= visibleTo
; line
++ )
2546 rectLine
= GetLineRect(line
);
2548 if ( !IsExposed(rectLine
.x
- xOrig
, rectLine
.y
- yOrig
,
2549 rectLine
.width
, rectLine
.height
) )
2551 // don't redraw unaffected lines to avoid flicker
2555 GetLine(line
)->DrawInReportMode( &dc
,
2557 GetLineHighlightRect(line
),
2558 IsHighlighted(line
) );
2561 if ( HasFlag(wxLC_HRULES
) )
2563 wxPen
pen(GetRuleColour(), 1, wxSOLID
);
2564 wxSize clientSize
= GetClientSize();
2566 for ( size_t i
= visibleFrom
; i
<= visibleTo
; i
++ )
2569 dc
.SetBrush( *wxTRANSPARENT_BRUSH
);
2570 dc
.DrawLine(0 - dev_x
, i
*lineHeight
,
2571 clientSize
.x
- dev_x
, i
*lineHeight
);
2574 // Draw last horizontal rule
2575 if ( visibleTo
> visibleFrom
)
2578 dc
.SetBrush( *wxTRANSPARENT_BRUSH
);
2579 dc
.DrawLine(0 - dev_x
, m_lineTo
*lineHeight
,
2580 clientSize
.x
- dev_x
, m_lineTo
*lineHeight
);
2584 // Draw vertical rules if required
2585 if ( HasFlag(wxLC_VRULES
) && !IsEmpty() )
2587 wxPen
pen(GetRuleColour(), 1, wxSOLID
);
2590 wxRect firstItemRect
;
2591 wxRect lastItemRect
;
2592 GetItemRect(0, firstItemRect
);
2593 GetItemRect(GetItemCount() - 1, lastItemRect
);
2594 int x
= firstItemRect
.GetX();
2596 dc
.SetBrush(* wxTRANSPARENT_BRUSH
);
2597 for (col
= 0; col
< GetColumnCount(); col
++)
2599 int colWidth
= GetColumnWidth(col
);
2601 dc
.DrawLine(x
- dev_x
, firstItemRect
.GetY() - 1 - dev_y
,
2602 x
- dev_x
, lastItemRect
.GetBottom() + 1 - dev_y
);
2608 size_t count
= GetItemCount();
2609 for ( size_t i
= 0; i
< count
; i
++ )
2611 GetLine(i
)->Draw( &dc
);
2615 if ( HasCurrent() && m_hasFocus
)
2618 // no rect outline, we already have the background color
2620 dc
.SetPen( *wxBLACK_PEN
);
2621 dc
.SetBrush( *wxTRANSPARENT_BRUSH
);
2622 dc
.DrawRectangle( GetLineHighlightRect(m_current
) );
2629 void wxListMainWindow::HighlightAll( bool on
)
2631 if ( IsSingleSel() )
2633 wxASSERT_MSG( !on
, _T("can't do this in a single sel control") );
2635 // we just have one item to turn off
2636 if ( HasCurrent() && IsHighlighted(m_current
) )
2638 HighlightLine(m_current
, FALSE
);
2639 RefreshLine(m_current
);
2644 HighlightLines(0, GetItemCount() - 1, on
);
2648 void wxListMainWindow::SendNotify( size_t line
,
2649 wxEventType command
,
2652 wxListEvent
le( command
, GetParent()->GetId() );
2653 le
.SetEventObject( GetParent() );
2654 le
.m_itemIndex
= line
;
2656 // set only for events which have position
2657 if ( point
!= wxDefaultPosition
)
2658 le
.m_pointDrag
= point
;
2660 if ( command
!= wxEVT_COMMAND_LIST_DELETE_ITEM
)
2662 GetLine(line
)->GetItem( 0, le
.m_item
);
2664 //else: there may be no more such item
2666 GetParent()->GetEventHandler()->ProcessEvent( le
);
2669 void wxListMainWindow::OnFocusLine( size_t WXUNUSED(line
) )
2671 // SendNotify( line, wxEVT_COMMAND_LIST_ITEM_FOCUSSED );
2674 void wxListMainWindow::OnUnfocusLine( size_t WXUNUSED(line
) )
2676 // SendNotify( line, wxEVT_COMMAND_LIST_ITEM_UNFOCUSSED );
2679 void wxListMainWindow::EditLabel( long item
)
2681 wxCHECK_RET( (item
>= 0) && ((size_t)item
< GetItemCount()),
2682 wxT("wrong index in wxListCtrl::EditLabel()") );
2684 m_currentEdit
= (size_t)item
;
2686 wxListEvent
le( wxEVT_COMMAND_LIST_BEGIN_LABEL_EDIT
, GetParent()->GetId() );
2687 le
.SetEventObject( GetParent() );
2688 le
.m_itemIndex
= item
;
2689 wxListLineData
*data
= GetLine(m_currentEdit
);
2690 wxCHECK_RET( data
, _T("invalid index in EditLabel()") );
2691 data
->GetItem( 0, le
.m_item
);
2692 GetParent()->GetEventHandler()->ProcessEvent( le
);
2694 if (!le
.IsAllowed())
2697 // We have to call this here because the label in question might just have
2698 // been added and no screen update taken place.
2702 wxClientDC
dc(this);
2705 wxString s
= data
->GetText(0);
2706 wxRect rectLabel
= GetLineLabelRect(m_currentEdit
);
2708 rectLabel
.x
= dc
.LogicalToDeviceX( rectLabel
.x
);
2709 rectLabel
.y
= dc
.LogicalToDeviceY( rectLabel
.y
);
2711 wxListTextCtrl
*text
= new wxListTextCtrl
2718 wxPoint(rectLabel
.x
-4,rectLabel
.y
-4),
2719 wxSize(rectLabel
.width
+11,rectLabel
.height
+8)
2724 void wxListMainWindow::OnRenameTimer()
2726 wxCHECK_RET( HasCurrent(), wxT("unexpected rename timer") );
2728 EditLabel( m_current
);
2731 void wxListMainWindow::OnRenameAccept()
2733 wxListEvent
le( wxEVT_COMMAND_LIST_END_LABEL_EDIT
, GetParent()->GetId() );
2734 le
.SetEventObject( GetParent() );
2735 le
.m_itemIndex
= m_currentEdit
;
2737 wxListLineData
*data
= GetLine(m_currentEdit
);
2738 wxCHECK_RET( data
, _T("invalid index in OnRenameAccept()") );
2740 data
->GetItem( 0, le
.m_item
);
2741 le
.m_item
.m_text
= m_renameRes
;
2742 GetParent()->GetEventHandler()->ProcessEvent( le
);
2744 if (!le
.IsAllowed()) return;
2747 info
.m_mask
= wxLIST_MASK_TEXT
;
2748 info
.m_itemId
= le
.m_itemIndex
;
2749 info
.m_text
= m_renameRes
;
2750 info
.SetTextColour(le
.m_item
.GetTextColour());
2754 void wxListMainWindow::OnMouse( wxMouseEvent
&event
)
2756 event
.SetEventObject( GetParent() );
2757 if ( GetParent()->GetEventHandler()->ProcessEvent( event
) )
2760 if ( !HasCurrent() || IsEmpty() )
2766 if ( !(event
.Dragging() || event
.ButtonDown() || event
.LeftUp() ||
2767 event
.ButtonDClick()) )
2770 int x
= event
.GetX();
2771 int y
= event
.GetY();
2772 CalcUnscrolledPosition( x
, y
, &x
, &y
);
2774 // where did we hit it (if we did)?
2777 size_t count
= GetItemCount(),
2780 if ( HasFlag(wxLC_REPORT
) )
2782 current
= y
/ GetLineHeight();
2783 if ( current
< count
)
2784 hitResult
= HitTestLine(current
, x
, y
);
2788 // TODO: optimize it too! this is less simple than for report view but
2789 // enumerating all items is still not a way to do it!!
2790 for ( current
= 0; current
< count
; current
++ )
2792 hitResult
= HitTestLine(current
, x
, y
);
2798 if (event
.Dragging())
2800 if (m_dragCount
== 0)
2801 m_dragStart
= wxPoint(x
,y
);
2805 if (m_dragCount
!= 3)
2808 int command
= event
.RightIsDown() ? wxEVT_COMMAND_LIST_BEGIN_RDRAG
2809 : wxEVT_COMMAND_LIST_BEGIN_DRAG
;
2811 wxListEvent
le( command
, GetParent()->GetId() );
2812 le
.SetEventObject( GetParent() );
2813 le
.m_pointDrag
= m_dragStart
;
2814 GetParent()->GetEventHandler()->ProcessEvent( le
);
2825 // outside of any item
2829 bool forceClick
= FALSE
;
2830 if (event
.ButtonDClick())
2832 m_renameTimer
->Stop();
2833 m_lastOnSame
= FALSE
;
2835 if ( current
== m_lineBeforeLastClicked
)
2837 SendNotify( current
, wxEVT_COMMAND_LIST_ITEM_ACTIVATED
);
2843 // the first click was on another item, so don't interpret this as
2844 // a double click, but as a simple click instead
2849 if (event
.LeftUp() && m_lastOnSame
)
2851 if ((current
== m_current
) &&
2852 (hitResult
== wxLIST_HITTEST_ONITEMLABEL
) &&
2853 HasFlag(wxLC_EDIT_LABELS
) )
2855 m_renameTimer
->Start( 100, TRUE
);
2857 m_lastOnSame
= FALSE
;
2859 else if (event
.RightDown())
2861 SendNotify( current
, wxEVT_COMMAND_LIST_ITEM_RIGHT_CLICK
,
2862 event
.GetPosition() );
2864 else if (event
.MiddleDown())
2866 SendNotify( current
, wxEVT_COMMAND_LIST_ITEM_MIDDLE_CLICK
);
2868 else if ( event
.LeftDown() || forceClick
)
2870 m_lineBeforeLastClicked
= m_lineLastClicked
;
2871 m_lineLastClicked
= current
;
2873 size_t oldCurrent
= m_current
;
2875 if ( IsSingleSel() || !(event
.ControlDown() || event
.ShiftDown()) )
2877 HighlightAll( FALSE
);
2878 m_current
= current
;
2880 ReverseHighlight(m_current
);
2882 else // multi sel & either ctrl or shift is down
2884 if (event
.ControlDown())
2886 m_current
= current
;
2888 ReverseHighlight(m_current
);
2890 else if (event
.ShiftDown())
2892 m_current
= current
;
2894 size_t lineFrom
= oldCurrent
,
2897 if ( lineTo
< lineFrom
)
2900 lineFrom
= m_current
;
2903 HighlightLines(lineFrom
, lineTo
);
2905 else // !ctrl, !shift
2907 // test in the enclosing if should make it impossible
2908 wxFAIL_MSG( _T("how did we get here?") );
2912 if (m_current
!= oldCurrent
)
2914 RefreshLine( oldCurrent
);
2915 OnUnfocusLine( oldCurrent
);
2916 OnFocusLine( m_current
);
2919 // forceClick is only set if the previous click was on another item
2920 m_lastOnSame
= !forceClick
&& (m_current
== oldCurrent
);
2924 void wxListMainWindow::MoveToItem(size_t item
)
2926 if ( item
== (size_t)-1 )
2929 wxRect rect
= GetLineRect(item
);
2931 int client_w
, client_h
;
2932 GetClientSize( &client_w
, &client_h
);
2934 int view_x
= m_xScroll
*GetScrollPos( wxHORIZONTAL
);
2935 int view_y
= m_yScroll
*GetScrollPos( wxVERTICAL
);
2937 if ( HasFlag(wxLC_REPORT
) )
2939 // the next we need the range of lines shown it might be different, so
2941 ResetVisibleLinesRange();
2943 if (rect
.y
< view_y
)
2944 Scroll( -1, rect
.y
/m_yScroll
);
2945 if (rect
.y
+rect
.height
+5 > view_y
+client_h
)
2946 Scroll( -1, (rect
.y
+rect
.height
-client_h
+SCROLL_UNIT_Y
)/m_yScroll
);
2950 if (rect
.x
-view_x
< 5)
2951 Scroll( (rect
.x
-5)/m_xScroll
, -1 );
2952 if (rect
.x
+rect
.width
-5 > view_x
+client_w
)
2953 Scroll( (rect
.x
+rect
.width
-client_w
+SCROLL_UNIT_X
)/m_xScroll
, -1 );
2957 // ----------------------------------------------------------------------------
2958 // keyboard handling
2959 // ----------------------------------------------------------------------------
2961 void wxListMainWindow::OnArrowChar(size_t newCurrent
, const wxKeyEvent
& event
)
2963 wxCHECK_RET( newCurrent
< (size_t)GetItemCount(),
2964 _T("invalid item index in OnArrowChar()") );
2966 size_t oldCurrent
= m_current
;
2968 // in single selection we just ignore Shift as we can't select several
2970 if ( event
.ShiftDown() && !IsSingleSel() )
2972 m_current
= newCurrent
;
2974 // select all the items between the old and the new one
2975 if ( oldCurrent
> newCurrent
)
2977 newCurrent
= oldCurrent
;
2978 oldCurrent
= m_current
;
2981 HighlightLines(oldCurrent
, newCurrent
);
2985 // all previously selected items are unselected unless ctrl is held
2986 if ( !event
.ControlDown() )
2987 HighlightAll(FALSE
);
2989 m_current
= newCurrent
;
2991 HighlightLine( oldCurrent
, FALSE
);
2992 RefreshLine( oldCurrent
);
2994 if ( !event
.ControlDown() )
2996 HighlightLine( m_current
, TRUE
);
3000 OnUnfocusLine( oldCurrent
);
3001 OnFocusLine( m_current
);
3002 RefreshLine( m_current
);
3007 void wxListMainWindow::OnKeyDown( wxKeyEvent
&event
)
3009 wxWindow
*parent
= GetParent();
3011 /* we propagate the key event up */
3012 wxKeyEvent
ke( wxEVT_KEY_DOWN
);
3013 ke
.m_shiftDown
= event
.m_shiftDown
;
3014 ke
.m_controlDown
= event
.m_controlDown
;
3015 ke
.m_altDown
= event
.m_altDown
;
3016 ke
.m_metaDown
= event
.m_metaDown
;
3017 ke
.m_keyCode
= event
.m_keyCode
;
3020 ke
.SetEventObject( parent
);
3021 if (parent
->GetEventHandler()->ProcessEvent( ke
)) return;
3026 void wxListMainWindow::OnChar( wxKeyEvent
&event
)
3028 wxWindow
*parent
= GetParent();
3030 /* we send a list_key event up */
3033 wxListEvent
le( wxEVT_COMMAND_LIST_KEY_DOWN
, GetParent()->GetId() );
3034 le
.m_itemIndex
= m_current
;
3035 GetLine(m_current
)->GetItem( 0, le
.m_item
);
3036 le
.m_code
= (int)event
.KeyCode();
3037 le
.SetEventObject( parent
);
3038 parent
->GetEventHandler()->ProcessEvent( le
);
3041 /* we propagate the char event up */
3042 wxKeyEvent
ke( wxEVT_CHAR
);
3043 ke
.m_shiftDown
= event
.m_shiftDown
;
3044 ke
.m_controlDown
= event
.m_controlDown
;
3045 ke
.m_altDown
= event
.m_altDown
;
3046 ke
.m_metaDown
= event
.m_metaDown
;
3047 ke
.m_keyCode
= event
.m_keyCode
;
3050 ke
.SetEventObject( parent
);
3051 if (parent
->GetEventHandler()->ProcessEvent( ke
)) return;
3053 if (event
.KeyCode() == WXK_TAB
)
3055 wxNavigationKeyEvent nevent
;
3056 nevent
.SetWindowChange( event
.ControlDown() );
3057 nevent
.SetDirection( !event
.ShiftDown() );
3058 nevent
.SetEventObject( GetParent()->GetParent() );
3059 nevent
.SetCurrentFocus( m_parent
);
3060 if (GetParent()->GetParent()->GetEventHandler()->ProcessEvent( nevent
)) return;
3063 /* no item -> nothing to do */
3070 switch (event
.KeyCode())
3073 if ( m_current
> 0 )
3074 OnArrowChar( m_current
- 1, event
);
3078 if ( m_current
< (size_t)GetItemCount() - 1 )
3079 OnArrowChar( m_current
+ 1, event
);
3084 OnArrowChar( GetItemCount() - 1, event
);
3089 OnArrowChar( 0, event
);
3095 if ( HasFlag(wxLC_REPORT
) )
3097 steps
= m_linesPerPage
- 1;
3101 steps
= m_current
% m_linesPerPage
;
3104 int index
= m_current
- steps
;
3108 OnArrowChar( index
, event
);
3115 if ( HasFlag(wxLC_REPORT
) )
3117 steps
= m_linesPerPage
- 1;
3121 steps
= m_linesPerPage
- (m_current
% m_linesPerPage
) - 1;
3124 size_t index
= m_current
+ steps
;
3125 size_t count
= GetItemCount();
3126 if ( index
>= count
)
3129 OnArrowChar( index
, event
);
3134 if ( !HasFlag(wxLC_REPORT
) )
3136 int index
= m_current
- m_linesPerPage
;
3140 OnArrowChar( index
, event
);
3145 if ( !HasFlag(wxLC_REPORT
) )
3147 size_t index
= m_current
+ m_linesPerPage
;
3149 size_t count
= GetItemCount();
3150 if ( index
>= count
)
3153 OnArrowChar( index
, event
);
3158 if ( IsSingleSel() )
3160 wxListEvent
le( wxEVT_COMMAND_LIST_ITEM_ACTIVATED
,
3161 GetParent()->GetId() );
3162 le
.SetEventObject( GetParent() );
3163 le
.m_itemIndex
= m_current
;
3164 GetLine(m_current
)->GetItem( 0, le
.m_item
);
3165 GetParent()->GetEventHandler()->ProcessEvent( le
);
3169 ReverseHighlight(m_current
);
3176 wxListEvent
le( wxEVT_COMMAND_LIST_ITEM_ACTIVATED
,
3177 GetParent()->GetId() );
3178 le
.SetEventObject( GetParent() );
3179 le
.m_itemIndex
= m_current
;
3180 GetLine(m_current
)->GetItem( 0, le
.m_item
);
3181 GetParent()->GetEventHandler()->ProcessEvent( le
);
3190 // ----------------------------------------------------------------------------
3192 // ----------------------------------------------------------------------------
3195 extern wxWindow
*g_focusWindow
;
3198 void wxListMainWindow::OnSetFocus( wxFocusEvent
&WXUNUSED(event
) )
3203 RefreshLine( m_current
);
3209 g_focusWindow
= GetParent();
3212 wxFocusEvent
event( wxEVT_SET_FOCUS
, GetParent()->GetId() );
3213 event
.SetEventObject( GetParent() );
3214 GetParent()->GetEventHandler()->ProcessEvent( event
);
3217 void wxListMainWindow::OnKillFocus( wxFocusEvent
&WXUNUSED(event
) )
3222 RefreshLine( m_current
);
3225 void wxListMainWindow::DrawImage( int index
, wxDC
*dc
, int x
, int y
)
3227 if ( HasFlag(wxLC_ICON
) && (m_normal_image_list
))
3229 m_normal_image_list
->Draw( index
, *dc
, x
, y
, wxIMAGELIST_DRAW_TRANSPARENT
);
3231 else if ( HasFlag(wxLC_SMALL_ICON
) && (m_small_image_list
))
3233 m_small_image_list
->Draw( index
, *dc
, x
, y
, wxIMAGELIST_DRAW_TRANSPARENT
);
3235 else if ( HasFlag(wxLC_LIST
) && (m_small_image_list
))
3237 m_small_image_list
->Draw( index
, *dc
, x
, y
, wxIMAGELIST_DRAW_TRANSPARENT
);
3239 else if ( HasFlag(wxLC_REPORT
) && (m_small_image_list
))
3241 m_small_image_list
->Draw( index
, *dc
, x
, y
, wxIMAGELIST_DRAW_TRANSPARENT
);
3245 void wxListMainWindow::GetImageSize( int index
, int &width
, int &height
) const
3247 if ( HasFlag(wxLC_ICON
) && m_normal_image_list
)
3249 m_normal_image_list
->GetSize( index
, width
, height
);
3251 else if ( HasFlag(wxLC_SMALL_ICON
) && m_small_image_list
)
3253 m_small_image_list
->GetSize( index
, width
, height
);
3255 else if ( HasFlag(wxLC_LIST
) && m_small_image_list
)
3257 m_small_image_list
->GetSize( index
, width
, height
);
3259 else if ( HasFlag(wxLC_REPORT
) && m_small_image_list
)
3261 m_small_image_list
->GetSize( index
, width
, height
);
3270 int wxListMainWindow::GetTextLength( const wxString
&s
) const
3272 wxClientDC
dc( wxConstCast(this, wxListMainWindow
) );
3273 dc
.SetFont( GetFont() );
3276 dc
.GetTextExtent( s
, &lw
, NULL
);
3278 return lw
+ AUTOSIZE_COL_MARGIN
;
3281 void wxListMainWindow::SetImageList( wxImageList
*imageList
, int which
)
3285 // calc the spacing from the icon size
3288 if ((imageList
) && (imageList
->GetImageCount()) )
3290 imageList
->GetSize(0, width
, height
);
3293 if (which
== wxIMAGE_LIST_NORMAL
)
3295 m_normal_image_list
= imageList
;
3296 m_normal_spacing
= width
+ 8;
3299 if (which
== wxIMAGE_LIST_SMALL
)
3301 m_small_image_list
= imageList
;
3302 m_small_spacing
= width
+ 14;
3306 void wxListMainWindow::SetItemSpacing( int spacing
, bool isSmall
)
3311 m_small_spacing
= spacing
;
3315 m_normal_spacing
= spacing
;
3319 int wxListMainWindow::GetItemSpacing( bool isSmall
)
3321 return isSmall
? m_small_spacing
: m_normal_spacing
;
3324 // ----------------------------------------------------------------------------
3326 // ----------------------------------------------------------------------------
3328 void wxListMainWindow::SetColumn( int col
, wxListItem
&item
)
3330 wxListHeaderDataList::Node
*node
= m_columns
.Item( col
);
3332 wxCHECK_RET( node
, _T("invalid column index in SetColumn") );
3334 if ( item
.m_width
== wxLIST_AUTOSIZE_USEHEADER
)
3335 item
.m_width
= GetTextLength( item
.m_text
);
3337 wxListHeaderData
*column
= node
->GetData();
3338 column
->SetItem( item
);
3340 wxListHeaderWindow
*headerWin
= GetListCtrl()->m_headerWin
;
3342 headerWin
->m_dirty
= TRUE
;
3346 // invalidate it as it has to be recalculated
3350 void wxListMainWindow::SetColumnWidth( int col
, int width
)
3352 wxCHECK_RET( col
>= 0 && col
< GetColumnCount(),
3353 _T("invalid column index") );
3355 wxCHECK_RET( HasFlag(wxLC_REPORT
),
3356 _T("SetColumnWidth() can only be called in report mode.") );
3360 wxListHeaderDataList::Node
*node
= m_columns
.Item( col
);
3361 wxCHECK_RET( node
, _T("no column?") );
3363 wxListHeaderData
*column
= node
->GetData();
3365 size_t count
= GetItemCount();
3367 if (width
== wxLIST_AUTOSIZE_USEHEADER
)
3369 width
= GetTextLength(column
->GetText());
3371 else if ( width
== wxLIST_AUTOSIZE
)
3375 // TODO: determine the max width somehow...
3376 width
= WIDTH_COL_DEFAULT
;
3380 wxClientDC
dc(this);
3381 dc
.SetFont( GetFont() );
3383 int max
= AUTOSIZE_COL_MARGIN
;
3385 for ( size_t i
= 0; i
< count
; i
++ )
3387 wxListLineData
*line
= GetLine(i
);
3388 wxListItemDataList::Node
*n
= line
->m_items
.Item( col
);
3390 wxCHECK_RET( n
, _T("no subitem?") );
3392 wxListItemData
*item
= n
->GetData();
3395 if (item
->HasImage())
3398 GetImageSize( item
->GetImage(), ix
, iy
);
3402 if (item
->HasText())
3405 dc
.GetTextExtent( item
->GetText(), &w
, NULL
);
3413 width
= max
+ AUTOSIZE_COL_MARGIN
;
3417 column
->SetWidth( width
);
3419 // invalidate it as it has to be recalculated
3423 int wxListMainWindow::GetHeaderWidth() const
3425 if ( !m_headerWidth
)
3427 wxListMainWindow
*self
= wxConstCast(this, wxListMainWindow
);
3429 size_t count
= GetColumnCount();
3430 for ( size_t col
= 0; col
< count
; col
++ )
3432 self
->m_headerWidth
+= GetColumnWidth(col
);
3436 return m_headerWidth
;
3439 void wxListMainWindow::GetColumn( int col
, wxListItem
&item
) const
3441 wxListHeaderDataList::Node
*node
= m_columns
.Item( col
);
3442 wxCHECK_RET( node
, _T("invalid column index in GetColumn") );
3444 wxListHeaderData
*column
= node
->GetData();
3445 column
->GetItem( item
);
3448 int wxListMainWindow::GetColumnWidth( int col
) const
3450 wxListHeaderDataList::Node
*node
= m_columns
.Item( col
);
3451 wxCHECK_MSG( node
, 0, _T("invalid column index") );
3453 wxListHeaderData
*column
= node
->GetData();
3454 return column
->GetWidth();
3457 // ----------------------------------------------------------------------------
3459 // ----------------------------------------------------------------------------
3461 void wxListMainWindow::SetItem( wxListItem
&item
)
3463 long id
= item
.m_itemId
;
3464 wxCHECK_RET( id
>= 0 && (size_t)id
< GetItemCount(),
3465 _T("invalid item index in SetItem") );
3469 wxListLineData
*line
= GetLine((size_t)id
);
3470 line
->SetItem( item
.m_col
, item
);
3473 if ( InReportView() )
3475 // just refresh the line to show the new value of the text/image
3476 RefreshLine((size_t)id
);
3480 // refresh everything (resulting in horrible flicker - FIXME!)
3485 void wxListMainWindow::SetItemState( long litem
, long state
, long stateMask
)
3487 wxCHECK_RET( litem
>= 0 && (size_t)litem
< GetItemCount(),
3488 _T("invalid list ctrl item index in SetItem") );
3490 size_t oldCurrent
= m_current
;
3491 size_t item
= (size_t)litem
; // sdafe because of the check above
3493 if ( stateMask
& wxLIST_STATE_FOCUSED
)
3495 if ( state
& wxLIST_STATE_FOCUSED
)
3497 // don't do anything if this item is already focused
3498 if ( item
!= m_current
)
3500 OnUnfocusLine( m_current
);
3502 OnFocusLine( m_current
);
3504 if ( IsSingleSel() && (oldCurrent
!= (size_t)-1) )
3506 HighlightLine(oldCurrent
, FALSE
);
3507 RefreshLine(oldCurrent
);
3510 RefreshLine( m_current
);
3515 // don't do anything if this item is not focused
3516 if ( item
== m_current
)
3518 OnUnfocusLine( m_current
);
3519 m_current
= (size_t)-1;
3524 if ( stateMask
& wxLIST_STATE_SELECTED
)
3526 bool on
= (state
& wxLIST_STATE_SELECTED
) != 0;
3528 if ( IsSingleSel() )
3532 // selecting the item also makes it the focused one in the
3534 if ( m_current
!= item
)
3536 OnUnfocusLine( m_current
);
3538 OnFocusLine( m_current
);
3540 if ( oldCurrent
!= (size_t)-1 )
3542 HighlightLine( oldCurrent
, FALSE
);
3543 RefreshLine( oldCurrent
);
3549 // only the current item may be selected anyhow
3550 if ( item
!= m_current
)
3555 if ( HighlightLine(item
, on
) )
3562 int wxListMainWindow::GetItemState( long item
, long stateMask
)
3564 wxCHECK_MSG( item
>= 0 && (size_t)item
< GetItemCount(), 0,
3565 _T("invalid list ctrl item index in GetItemState()") );
3567 int ret
= wxLIST_STATE_DONTCARE
;
3569 if ( stateMask
& wxLIST_STATE_FOCUSED
)
3571 if ( (size_t)item
== m_current
)
3572 ret
|= wxLIST_STATE_FOCUSED
;
3575 if ( stateMask
& wxLIST_STATE_SELECTED
)
3577 if ( IsHighlighted(item
) )
3578 ret
|= wxLIST_STATE_SELECTED
;
3584 void wxListMainWindow::GetItem( wxListItem
&item
)
3586 wxCHECK_RET( item
.m_itemId
>= 0 && (size_t)item
.m_itemId
< GetItemCount(),
3587 _T("invalid item index in GetItem") );
3589 wxListLineData
*line
= GetLine((size_t)item
.m_itemId
);
3590 line
->GetItem( item
.m_col
, item
);
3593 // ----------------------------------------------------------------------------
3595 // ----------------------------------------------------------------------------
3597 size_t wxListMainWindow::GetItemCount() const
3599 return IsVirtual() ? m_countVirt
: m_lines
.GetCount();
3602 void wxListMainWindow::SetItemCount(long count
)
3604 m_selStore
.SetItemCount(count
);
3605 m_countVirt
= count
;
3607 ResetVisibleLinesRange();
3609 // scrollbars must be reset
3613 int wxListMainWindow::GetSelectedItemCount()
3615 // deal with the quick case first
3616 if ( IsSingleSel() )
3618 return HasCurrent() ? IsHighlighted(m_current
) : FALSE
;
3621 // virtual controls remmebers all its selections itself
3623 return m_selStore
.GetSelectedCount();
3625 // TODO: we probably should maintain the number of items selected even for
3626 // non virtual controls as enumerating all lines is really slow...
3627 size_t countSel
= 0;
3628 size_t count
= GetItemCount();
3629 for ( size_t line
= 0; line
< count
; line
++ )
3631 if ( GetLine(line
)->IsHighlighted() )
3638 // ----------------------------------------------------------------------------
3639 // item position/size
3640 // ----------------------------------------------------------------------------
3642 void wxListMainWindow::GetItemRect( long index
, wxRect
&rect
)
3644 wxCHECK_RET( index
>= 0 && (size_t)index
< GetItemCount(),
3645 _T("invalid index in GetItemRect") );
3647 rect
= GetLineRect((size_t)index
);
3649 CalcScrolledPosition(rect
.x
, rect
.y
, &rect
.x
, &rect
.y
);
3652 bool wxListMainWindow::GetItemPosition(long item
, wxPoint
& pos
)
3655 GetItemRect(item
, rect
);
3663 // ----------------------------------------------------------------------------
3664 // geometry calculation
3665 // ----------------------------------------------------------------------------
3667 void wxListMainWindow::RecalculatePositions(bool noRefresh
)
3669 wxClientDC
dc( this );
3670 dc
.SetFont( GetFont() );
3673 if ( HasFlag(wxLC_ICON
) )
3674 iconSpacing
= m_normal_spacing
;
3675 else if ( HasFlag(wxLC_SMALL_ICON
) )
3676 iconSpacing
= m_small_spacing
;
3682 GetClientSize( &clientWidth
, &clientHeight
);
3684 if ( HasFlag(wxLC_REPORT
) )
3686 // all lines have the same height
3687 int lineHeight
= GetLineHeight();
3689 // scroll one line per step
3690 m_yScroll
= lineHeight
;
3692 size_t lineCount
= GetItemCount();
3693 int entireHeight
= lineCount
*lineHeight
+ LINE_SPACING
;
3695 m_linesPerPage
= clientHeight
/ lineHeight
;
3697 ResetVisibleLinesRange();
3699 SetScrollbars( m_xScroll
, m_yScroll
,
3700 (GetHeaderWidth() + m_xScroll
- 1)/m_xScroll
,
3701 (entireHeight
+ m_yScroll
- 1)/m_yScroll
,
3702 GetScrollPos(wxHORIZONTAL
),
3703 GetScrollPos(wxVERTICAL
),
3708 // at first we try without any scrollbar. if the items don't
3709 // fit into the window, we recalculate after subtracting an
3710 // approximated 15 pt for the horizontal scrollbar
3712 clientHeight
-= 4; // sunken frame
3714 int entireWidth
= 0;
3716 for (int tries
= 0; tries
< 2; tries
++)
3723 int currentlyVisibleLines
= 0;
3725 size_t count
= GetItemCount();
3726 for (size_t i
= 0; i
< count
; i
++)
3728 currentlyVisibleLines
++;
3729 wxListLineData
*line
= GetLine(i
);
3730 line
->CalculateSize( &dc
, iconSpacing
);
3731 line
->SetPosition( x
, y
, clientWidth
, iconSpacing
);
3733 wxSize sizeLine
= GetLineSize(i
);
3735 if ( maxWidth
< sizeLine
.x
)
3736 maxWidth
= sizeLine
.x
;
3739 if (currentlyVisibleLines
> m_linesPerPage
)
3740 m_linesPerPage
= currentlyVisibleLines
;
3742 // assume that the size of the next one is the same... (FIXME)
3743 if ( y
+ sizeLine
.y
- 6 >= clientHeight
)
3745 currentlyVisibleLines
= 0;
3748 entireWidth
+= maxWidth
+6;
3751 if ( i
== count
- 1 )
3752 entireWidth
+= maxWidth
;
3753 if ((tries
== 0) && (entireWidth
> clientWidth
))
3755 clientHeight
-= 15; // scrollbar height
3757 currentlyVisibleLines
= 0;
3760 if ( i
== count
- 1 )
3761 tries
= 1; // everything fits, no second try required
3765 int scroll_pos
= GetScrollPos( wxHORIZONTAL
);
3766 SetScrollbars( m_xScroll
, m_yScroll
, (entireWidth
+SCROLL_UNIT_X
) / m_xScroll
, 0, scroll_pos
, 0, TRUE
);
3771 // FIXME: why should we call it from here?
3778 void wxListMainWindow::RefreshAll()
3783 wxListHeaderWindow
*headerWin
= GetListCtrl()->m_headerWin
;
3786 headerWin
->m_dirty
= FALSE
;
3787 headerWin
->Refresh();
3791 void wxListMainWindow::UpdateCurrent()
3793 if ( !HasCurrent() && !IsEmpty() )
3798 if ( m_current
!= (size_t)-1 )
3800 OnFocusLine( m_current
);
3804 long wxListMainWindow::GetNextItem( long item
,
3805 int WXUNUSED(geometry
),
3809 max
= GetItemCount();
3810 wxCHECK_MSG( (ret
== -1) || (ret
< max
), -1,
3811 _T("invalid listctrl index in GetNextItem()") );
3813 // notice that we start with the next item (or the first one if item == -1)
3814 // and this is intentional to allow writing a simple loop to iterate over
3815 // all selected items
3819 // this is not an error because the index was ok initially, just no
3830 size_t count
= GetItemCount();
3831 for ( size_t line
= (size_t)ret
; line
< count
; line
++ )
3833 if ( (state
& wxLIST_STATE_FOCUSED
) && (line
== m_current
) )
3836 if ( (state
& wxLIST_STATE_SELECTED
) && IsHighlighted(line
) )
3843 // ----------------------------------------------------------------------------
3845 // ----------------------------------------------------------------------------
3847 void wxListMainWindow::DeleteItem( long lindex
)
3849 size_t count
= GetItemCount();
3851 wxCHECK_RET( (lindex
>= 0) && ((size_t)lindex
< count
),
3852 _T("invalid item index in DeleteItem") );
3854 size_t index
= (size_t)lindex
;
3856 // we don't need to adjust the index for the previous items
3857 if ( HasCurrent() && m_current
>= index
)
3859 // if the current item is being deleted, we want the next one to
3860 // become selected - unless there is no next one - so don't adjust
3861 // m_current in this case
3862 if ( m_current
!= index
|| m_current
== count
- 1 )
3868 if ( InReportView() )
3870 ResetVisibleLinesRange();
3877 m_selStore
.OnItemDelete(index
);
3881 m_lines
.RemoveAt( index
);
3886 SendNotify( index
, wxEVT_COMMAND_LIST_DELETE_ITEM
);
3888 RefreshAfter(index
);
3891 void wxListMainWindow::DeleteColumn( int col
)
3893 wxListHeaderDataList::Node
*node
= m_columns
.Item( col
);
3895 wxCHECK_RET( node
, wxT("invalid column index in DeleteColumn()") );
3898 m_columns
.DeleteNode( node
);
3901 void wxListMainWindow::DoDeleteAllItems()
3905 // nothing to do - in particular, don't send the event
3911 // to make the deletion of all items faster, we don't send the
3912 // notifications for each item deletion in this case but only one event
3913 // for all of them: this is compatible with wxMSW and documented in
3914 // DeleteAllItems() description
3916 wxListEvent
event( wxEVT_COMMAND_LIST_DELETE_ALL_ITEMS
, GetParent()->GetId() );
3917 event
.SetEventObject( GetParent() );
3918 GetParent()->GetEventHandler()->ProcessEvent( event
);
3927 if ( InReportView() )
3929 ResetVisibleLinesRange();
3935 void wxListMainWindow::DeleteAllItems()
3939 RecalculatePositions();
3942 void wxListMainWindow::DeleteEverything()
3949 // ----------------------------------------------------------------------------
3950 // scanning for an item
3951 // ----------------------------------------------------------------------------
3953 void wxListMainWindow::EnsureVisible( long index
)
3955 wxCHECK_RET( index
>= 0 && (size_t)index
< GetItemCount(),
3956 _T("invalid index in EnsureVisible") );
3958 // We have to call this here because the label in question might just have
3959 // been added and its position is not known yet
3964 RecalculatePositions(TRUE
/* no refresh */);
3967 MoveToItem((size_t)index
);
3970 long wxListMainWindow::FindItem(long start
, const wxString
& str
, bool WXUNUSED(partial
) )
3977 size_t count
= GetItemCount();
3978 for ( size_t i
= (size_t)pos
; i
< count
; i
++ )
3980 wxListLineData
*line
= GetLine(i
);
3981 if ( line
->GetText(0) == tmp
)
3988 long wxListMainWindow::FindItem(long start
, long data
)
3994 size_t count
= GetItemCount();
3995 for (size_t i
= (size_t)pos
; i
< count
; i
++)
3997 wxListLineData
*line
= GetLine(i
);
3999 line
->GetItem( 0, item
);
4000 if (item
.m_data
== data
)
4007 long wxListMainWindow::HitTest( int x
, int y
, int &flags
)
4009 CalcUnscrolledPosition( x
, y
, &x
, &y
);
4011 if ( HasFlag(wxLC_REPORT
) )
4013 size_t current
= y
/ GetLineHeight();
4014 flags
= HitTestLine(current
, x
, y
);
4020 // TODO: optimize it too! this is less simple than for report view but
4021 // enumerating all items is still not a way to do it!!
4022 size_t count
= GetItemCount();
4023 for ( size_t current
= 0; current
< count
; current
++ )
4025 flags
= HitTestLine(current
, x
, y
);
4034 // ----------------------------------------------------------------------------
4036 // ----------------------------------------------------------------------------
4038 void wxListMainWindow::InsertItem( wxListItem
&item
)
4040 wxASSERT_MSG( !IsVirtual(), _T("can't be used with virtual control") );
4042 size_t count
= GetItemCount();
4043 wxCHECK_RET( item
.m_itemId
>= 0 && (size_t)item
.m_itemId
<= count
,
4044 _T("invalid item index") );
4046 size_t id
= item
.m_itemId
;
4051 if ( HasFlag(wxLC_REPORT
) )
4053 else if ( HasFlag(wxLC_LIST
) )
4055 else if ( HasFlag(wxLC_ICON
) )
4057 else if ( HasFlag(wxLC_SMALL_ICON
) )
4058 mode
= wxLC_ICON
; // no typo
4061 wxFAIL_MSG( _T("unknown mode") );
4064 wxListLineData
*line
= new wxListLineData(this);
4066 line
->SetItem( 0, item
);
4068 m_lines
.Insert( line
, id
);
4071 RefreshLines(id
, GetItemCount() - 1);
4074 void wxListMainWindow::InsertColumn( long col
, wxListItem
&item
)
4077 if ( HasFlag(wxLC_REPORT
) )
4079 if (item
.m_width
== wxLIST_AUTOSIZE_USEHEADER
)
4080 item
.m_width
= GetTextLength( item
.m_text
);
4081 wxListHeaderData
*column
= new wxListHeaderData( item
);
4082 if ((col
>= 0) && (col
< (int)m_columns
.GetCount()))
4084 wxListHeaderDataList::Node
*node
= m_columns
.Item( col
);
4085 m_columns
.Insert( node
, column
);
4089 m_columns
.Append( column
);
4094 // ----------------------------------------------------------------------------
4096 // ----------------------------------------------------------------------------
4098 wxListCtrlCompare list_ctrl_compare_func_2
;
4099 long list_ctrl_compare_data
;
4101 int LINKAGEMODE
list_ctrl_compare_func_1( wxListLineData
**arg1
, wxListLineData
**arg2
)
4103 wxListLineData
*line1
= *arg1
;
4104 wxListLineData
*line2
= *arg2
;
4106 line1
->GetItem( 0, item
);
4107 long data1
= item
.m_data
;
4108 line2
->GetItem( 0, item
);
4109 long data2
= item
.m_data
;
4110 return list_ctrl_compare_func_2( data1
, data2
, list_ctrl_compare_data
);
4113 void wxListMainWindow::SortItems( wxListCtrlCompare fn
, long data
)
4115 list_ctrl_compare_func_2
= fn
;
4116 list_ctrl_compare_data
= data
;
4117 m_lines
.Sort( list_ctrl_compare_func_1
);
4121 // ----------------------------------------------------------------------------
4123 // ----------------------------------------------------------------------------
4125 void wxListMainWindow::OnScroll(wxScrollWinEvent
& event
)
4127 // update our idea of which lines are shown when we redraw the window the
4129 ResetVisibleLinesRange();
4132 #if defined(__WXGTK__) && !defined(__WXUNIVERSAL__)
4133 wxScrolledWindow::OnScroll(event
);
4135 HandleOnScroll( event
);
4138 if ( event
.GetOrientation() == wxHORIZONTAL
&& HasHeader() )
4140 wxListCtrl
* lc
= GetListCtrl();
4141 wxCHECK_RET( lc
, _T("no listctrl window?") );
4143 lc
->m_headerWin
->Refresh() ;
4145 lc
->m_headerWin
->MacUpdateImmediately() ;
4150 int wxListMainWindow::GetCountPerPage() const
4152 if ( !m_linesPerPage
)
4154 wxConstCast(this, wxListMainWindow
)->
4155 m_linesPerPage
= GetClientSize().y
/ GetLineHeight();
4158 return m_linesPerPage
;
4161 void wxListMainWindow::GetVisibleLinesRange(size_t *from
, size_t *to
)
4163 wxASSERT_MSG( HasFlag(wxLC_REPORT
), _T("this is for report mode only") );
4165 if ( m_lineFrom
== (size_t)-1 )
4167 size_t count
= GetItemCount();
4170 m_lineFrom
= GetScrollPos(wxVERTICAL
);
4172 // this may happen if SetScrollbars() hadn't been called yet
4173 if ( m_lineFrom
>= count
)
4174 m_lineFrom
= count
- 1;
4176 // we redraw one extra line but this is needed to make the redrawing
4177 // logic work when there is a fractional number of lines on screen
4178 m_lineTo
= m_lineFrom
+ m_linesPerPage
;
4179 if ( m_lineTo
>= count
)
4180 m_lineTo
= count
- 1;
4182 else // empty control
4185 m_lineTo
= (size_t)-1;
4189 wxASSERT_MSG( IsEmpty() ||
4190 (m_lineFrom
<= m_lineTo
&& m_lineTo
< GetItemCount()),
4191 _T("GetVisibleLinesRange() returns incorrect result") );
4199 // -------------------------------------------------------------------------------------
4201 // -------------------------------------------------------------------------------------
4203 IMPLEMENT_DYNAMIC_CLASS(wxListItem
, wxObject
)
4205 wxListItem::wxListItem()
4214 m_format
= wxLIST_FORMAT_CENTRE
;
4220 void wxListItem::Clear()
4229 m_format
= wxLIST_FORMAT_CENTRE
;
4236 void wxListItem::ClearAttributes()
4245 // -------------------------------------------------------------------------------------
4247 // -------------------------------------------------------------------------------------
4249 IMPLEMENT_DYNAMIC_CLASS(wxListEvent
, wxNotifyEvent
)
4251 wxListEvent::wxListEvent( wxEventType commandType
, int id
)
4252 : wxNotifyEvent( commandType
, id
)
4258 m_cancelled
= FALSE
;
4263 void wxListEvent::CopyObject(wxObject
& object_dest
) const
4265 wxListEvent
*obj
= (wxListEvent
*)&object_dest
;
4267 wxNotifyEvent::CopyObject(object_dest
);
4269 obj
->m_code
= m_code
;
4270 obj
->m_itemIndex
= m_itemIndex
;
4271 obj
->m_oldItemIndex
= m_oldItemIndex
;
4273 obj
->m_cancelled
= m_cancelled
;
4274 obj
->m_pointDrag
= m_pointDrag
;
4275 obj
->m_item
.m_mask
= m_item
.m_mask
;
4276 obj
->m_item
.m_itemId
= m_item
.m_itemId
;
4277 obj
->m_item
.m_col
= m_item
.m_col
;
4278 obj
->m_item
.m_state
= m_item
.m_state
;
4279 obj
->m_item
.m_stateMask
= m_item
.m_stateMask
;
4280 obj
->m_item
.m_text
= m_item
.m_text
;
4281 obj
->m_item
.m_image
= m_item
.m_image
;
4282 obj
->m_item
.m_data
= m_item
.m_data
;
4283 obj
->m_item
.m_format
= m_item
.m_format
;
4284 obj
->m_item
.m_width
= m_item
.m_width
;
4286 if ( m_item
.HasAttributes() )
4288 obj
->m_item
.SetTextColour(m_item
.GetTextColour());
4292 // -------------------------------------------------------------------------------------
4294 // -------------------------------------------------------------------------------------
4296 IMPLEMENT_DYNAMIC_CLASS(wxListCtrl
, wxControl
)
4297 IMPLEMENT_DYNAMIC_CLASS(wxListView
, wxListCtrl
)
4299 BEGIN_EVENT_TABLE(wxListCtrl
,wxControl
)
4300 EVT_SIZE(wxListCtrl::OnSize
)
4301 EVT_IDLE(wxListCtrl::OnIdle
)
4304 wxListCtrl::wxListCtrl()
4306 m_imageListNormal
= (wxImageList
*) NULL
;
4307 m_imageListSmall
= (wxImageList
*) NULL
;
4308 m_imageListState
= (wxImageList
*) NULL
;
4310 m_ownsImageListNormal
=
4311 m_ownsImageListSmall
=
4312 m_ownsImageListState
= FALSE
;
4314 m_mainWin
= (wxListMainWindow
*) NULL
;
4315 m_headerWin
= (wxListHeaderWindow
*) NULL
;
4318 wxListCtrl::~wxListCtrl()
4321 m_mainWin
->ResetCurrent();
4323 if (m_ownsImageListNormal
)
4324 delete m_imageListNormal
;
4325 if (m_ownsImageListSmall
)
4326 delete m_imageListSmall
;
4327 if (m_ownsImageListState
)
4328 delete m_imageListState
;
4331 void wxListCtrl::CreateHeaderWindow()
4333 m_headerWin
= new wxListHeaderWindow
4335 this, -1, m_mainWin
,
4337 wxSize(GetClientSize().x
, HEADER_HEIGHT
),
4342 bool wxListCtrl::Create(wxWindow
*parent
,
4347 const wxValidator
&validator
,
4348 const wxString
&name
)
4352 m_imageListState
= (wxImageList
*) NULL
;
4353 m_ownsImageListNormal
=
4354 m_ownsImageListSmall
=
4355 m_ownsImageListState
= FALSE
;
4357 m_mainWin
= (wxListMainWindow
*) NULL
;
4358 m_headerWin
= (wxListHeaderWindow
*) NULL
;
4360 if ( !(style
& wxLC_MASK_TYPE
) )
4362 style
= style
| wxLC_LIST
;
4365 if ( !wxControl::Create( parent
, id
, pos
, size
, style
, validator
, name
) )
4368 // don't create the inner window with the border
4369 style
&= ~wxSUNKEN_BORDER
;
4371 m_mainWin
= new wxListMainWindow( this, -1, wxPoint(0,0), size
, style
);
4373 if ( HasFlag(wxLC_REPORT
) )
4375 CreateHeaderWindow();
4377 if ( HasFlag(wxLC_NO_HEADER
) )
4379 // VZ: why do we create it at all then?
4380 m_headerWin
->Show( FALSE
);
4387 void wxListCtrl::SetSingleStyle( long style
, bool add
)
4389 wxASSERT_MSG( !(style
& wxLC_VIRTUAL
),
4390 _T("wxLC_VIRTUAL can't be [un]set") );
4392 long flag
= GetWindowStyle();
4396 if (style
& wxLC_MASK_TYPE
)
4397 flag
&= ~(wxLC_MASK_TYPE
| wxLC_VIRTUAL
);
4398 if (style
& wxLC_MASK_ALIGN
)
4399 flag
&= ~wxLC_MASK_ALIGN
;
4400 if (style
& wxLC_MASK_SORT
)
4401 flag
&= ~wxLC_MASK_SORT
;
4413 SetWindowStyleFlag( flag
);
4416 void wxListCtrl::SetWindowStyleFlag( long flag
)
4420 m_mainWin
->DeleteEverything();
4422 // has the header visibility changed?
4423 bool hasHeader
= HasFlag(wxLC_REPORT
) && !HasFlag(wxLC_NO_HEADER
),
4424 willHaveHeader
= (flag
& wxLC_REPORT
) && !(flag
& wxLC_NO_HEADER
);
4426 if ( hasHeader
!= willHaveHeader
)
4433 // don't delete, just hide, as we can reuse it later
4434 m_headerWin
->Show(FALSE
);
4436 //else: nothing to do
4438 else // must show header
4442 CreateHeaderWindow();
4444 else // already have it, just show
4446 m_headerWin
->Show( TRUE
);
4450 ResizeReportView(willHaveHeader
);
4454 wxWindow::SetWindowStyleFlag( flag
);
4457 bool wxListCtrl::GetColumn(int col
, wxListItem
&item
) const
4459 m_mainWin
->GetColumn( col
, item
);
4463 bool wxListCtrl::SetColumn( int col
, wxListItem
& item
)
4465 m_mainWin
->SetColumn( col
, item
);
4469 int wxListCtrl::GetColumnWidth( int col
) const
4471 return m_mainWin
->GetColumnWidth( col
);
4474 bool wxListCtrl::SetColumnWidth( int col
, int width
)
4476 m_mainWin
->SetColumnWidth( col
, width
);
4480 int wxListCtrl::GetCountPerPage() const
4482 return m_mainWin
->GetCountPerPage(); // different from Windows ?
4485 bool wxListCtrl::GetItem( wxListItem
&info
) const
4487 m_mainWin
->GetItem( info
);
4491 bool wxListCtrl::SetItem( wxListItem
&info
)
4493 m_mainWin
->SetItem( info
);
4497 long wxListCtrl::SetItem( long index
, int col
, const wxString
& label
, int imageId
)
4500 info
.m_text
= label
;
4501 info
.m_mask
= wxLIST_MASK_TEXT
;
4502 info
.m_itemId
= index
;
4506 info
.m_image
= imageId
;
4507 info
.m_mask
|= wxLIST_MASK_IMAGE
;
4509 m_mainWin
->SetItem(info
);
4513 int wxListCtrl::GetItemState( long item
, long stateMask
) const
4515 return m_mainWin
->GetItemState( item
, stateMask
);
4518 bool wxListCtrl::SetItemState( long item
, long state
, long stateMask
)
4520 m_mainWin
->SetItemState( item
, state
, stateMask
);
4524 bool wxListCtrl::SetItemImage( long item
, int image
, int WXUNUSED(selImage
) )
4527 info
.m_image
= image
;
4528 info
.m_mask
= wxLIST_MASK_IMAGE
;
4529 info
.m_itemId
= item
;
4530 m_mainWin
->SetItem( info
);
4534 wxString
wxListCtrl::GetItemText( long item
) const
4537 info
.m_itemId
= item
;
4538 m_mainWin
->GetItem( info
);
4542 void wxListCtrl::SetItemText( long item
, const wxString
&str
)
4545 info
.m_mask
= wxLIST_MASK_TEXT
;
4546 info
.m_itemId
= item
;
4548 m_mainWin
->SetItem( info
);
4551 long wxListCtrl::GetItemData( long item
) const
4554 info
.m_itemId
= item
;
4555 m_mainWin
->GetItem( info
);
4559 bool wxListCtrl::SetItemData( long item
, long data
)
4562 info
.m_mask
= wxLIST_MASK_DATA
;
4563 info
.m_itemId
= item
;
4565 m_mainWin
->SetItem( info
);
4569 bool wxListCtrl::GetItemRect( long item
, wxRect
&rect
, int WXUNUSED(code
) ) const
4571 m_mainWin
->GetItemRect( item
, rect
);
4575 bool wxListCtrl::GetItemPosition( long item
, wxPoint
& pos
) const
4577 m_mainWin
->GetItemPosition( item
, pos
);
4581 bool wxListCtrl::SetItemPosition( long WXUNUSED(item
), const wxPoint
& WXUNUSED(pos
) )
4586 int wxListCtrl::GetItemCount() const
4588 return m_mainWin
->GetItemCount();
4591 int wxListCtrl::GetColumnCount() const
4593 return m_mainWin
->GetColumnCount();
4596 void wxListCtrl::SetItemSpacing( int spacing
, bool isSmall
)
4598 m_mainWin
->SetItemSpacing( spacing
, isSmall
);
4601 int wxListCtrl::GetItemSpacing( bool isSmall
) const
4603 return m_mainWin
->GetItemSpacing( isSmall
);
4606 int wxListCtrl::GetSelectedItemCount() const
4608 return m_mainWin
->GetSelectedItemCount();
4611 wxColour
wxListCtrl::GetTextColour() const
4613 return GetForegroundColour();
4616 void wxListCtrl::SetTextColour(const wxColour
& col
)
4618 SetForegroundColour(col
);
4621 long wxListCtrl::GetTopItem() const
4626 long wxListCtrl::GetNextItem( long item
, int geom
, int state
) const
4628 return m_mainWin
->GetNextItem( item
, geom
, state
);
4631 wxImageList
*wxListCtrl::GetImageList(int which
) const
4633 if (which
== wxIMAGE_LIST_NORMAL
)
4635 return m_imageListNormal
;
4637 else if (which
== wxIMAGE_LIST_SMALL
)
4639 return m_imageListSmall
;
4641 else if (which
== wxIMAGE_LIST_STATE
)
4643 return m_imageListState
;
4645 return (wxImageList
*) NULL
;
4648 void wxListCtrl::SetImageList( wxImageList
*imageList
, int which
)
4650 if ( which
== wxIMAGE_LIST_NORMAL
)
4652 if (m_ownsImageListNormal
) delete m_imageListNormal
;
4653 m_imageListNormal
= imageList
;
4654 m_ownsImageListNormal
= FALSE
;
4656 else if ( which
== wxIMAGE_LIST_SMALL
)
4658 if (m_ownsImageListSmall
) delete m_imageListSmall
;
4659 m_imageListSmall
= imageList
;
4660 m_ownsImageListSmall
= FALSE
;
4662 else if ( which
== wxIMAGE_LIST_STATE
)
4664 if (m_ownsImageListState
) delete m_imageListState
;
4665 m_imageListState
= imageList
;
4666 m_ownsImageListState
= FALSE
;
4669 m_mainWin
->SetImageList( imageList
, which
);
4672 void wxListCtrl::AssignImageList(wxImageList
*imageList
, int which
)
4674 SetImageList(imageList
, which
);
4675 if ( which
== wxIMAGE_LIST_NORMAL
)
4676 m_ownsImageListNormal
= TRUE
;
4677 else if ( which
== wxIMAGE_LIST_SMALL
)
4678 m_ownsImageListSmall
= TRUE
;
4679 else if ( which
== wxIMAGE_LIST_STATE
)
4680 m_ownsImageListState
= TRUE
;
4683 bool wxListCtrl::Arrange( int WXUNUSED(flag
) )
4688 bool wxListCtrl::DeleteItem( long item
)
4690 m_mainWin
->DeleteItem( item
);
4694 bool wxListCtrl::DeleteAllItems()
4696 m_mainWin
->DeleteAllItems();
4700 bool wxListCtrl::DeleteAllColumns()
4702 size_t count
= m_mainWin
->m_columns
.GetCount();
4703 for ( size_t n
= 0; n
< count
; n
++ )
4709 void wxListCtrl::ClearAll()
4711 m_mainWin
->DeleteEverything();
4714 bool wxListCtrl::DeleteColumn( int col
)
4716 m_mainWin
->DeleteColumn( col
);
4720 void wxListCtrl::Edit( long item
)
4722 m_mainWin
->EditLabel( item
);
4725 bool wxListCtrl::EnsureVisible( long item
)
4727 m_mainWin
->EnsureVisible( item
);
4731 long wxListCtrl::FindItem( long start
, const wxString
& str
, bool partial
)
4733 return m_mainWin
->FindItem( start
, str
, partial
);
4736 long wxListCtrl::FindItem( long start
, long data
)
4738 return m_mainWin
->FindItem( start
, data
);
4741 long wxListCtrl::FindItem( long WXUNUSED(start
), const wxPoint
& WXUNUSED(pt
),
4742 int WXUNUSED(direction
))
4747 long wxListCtrl::HitTest( const wxPoint
&point
, int &flags
)
4749 return m_mainWin
->HitTest( (int)point
.x
, (int)point
.y
, flags
);
4752 long wxListCtrl::InsertItem( wxListItem
& info
)
4754 m_mainWin
->InsertItem( info
);
4755 return info
.m_itemId
;
4758 long wxListCtrl::InsertItem( long index
, const wxString
&label
)
4761 info
.m_text
= label
;
4762 info
.m_mask
= wxLIST_MASK_TEXT
;
4763 info
.m_itemId
= index
;
4764 return InsertItem( info
);
4767 long wxListCtrl::InsertItem( long index
, int imageIndex
)
4770 info
.m_mask
= wxLIST_MASK_IMAGE
;
4771 info
.m_image
= imageIndex
;
4772 info
.m_itemId
= index
;
4773 return InsertItem( info
);
4776 long wxListCtrl::InsertItem( long index
, const wxString
&label
, int imageIndex
)
4779 info
.m_text
= label
;
4780 info
.m_image
= imageIndex
;
4781 info
.m_mask
= wxLIST_MASK_TEXT
| wxLIST_MASK_IMAGE
;
4782 info
.m_itemId
= index
;
4783 return InsertItem( info
);
4786 long wxListCtrl::InsertColumn( long col
, wxListItem
&item
)
4788 wxASSERT( m_headerWin
);
4789 m_mainWin
->InsertColumn( col
, item
);
4790 m_headerWin
->Refresh();
4795 long wxListCtrl::InsertColumn( long col
, const wxString
&heading
,
4796 int format
, int width
)
4799 item
.m_mask
= wxLIST_MASK_TEXT
| wxLIST_MASK_FORMAT
;
4800 item
.m_text
= heading
;
4803 item
.m_mask
|= wxLIST_MASK_WIDTH
;
4804 item
.m_width
= width
;
4806 item
.m_format
= format
;
4808 return InsertColumn( col
, item
);
4811 bool wxListCtrl::ScrollList( int WXUNUSED(dx
), int WXUNUSED(dy
) )
4817 // fn is a function which takes 3 long arguments: item1, item2, data.
4818 // item1 is the long data associated with a first item (NOT the index).
4819 // item2 is the long data associated with a second item (NOT the index).
4820 // data is the same value as passed to SortItems.
4821 // The return value is a negative number if the first item should precede the second
4822 // item, a positive number of the second item should precede the first,
4823 // or zero if the two items are equivalent.
4824 // data is arbitrary data to be passed to the sort function.
4826 bool wxListCtrl::SortItems( wxListCtrlCompare fn
, long data
)
4828 m_mainWin
->SortItems( fn
, data
);
4832 // ----------------------------------------------------------------------------
4834 // ----------------------------------------------------------------------------
4836 void wxListCtrl::OnSize(wxSizeEvent
& event
)
4841 ResizeReportView(m_mainWin
->HasHeader());
4843 m_mainWin
->RecalculatePositions();
4846 void wxListCtrl::ResizeReportView(bool showHeader
)
4849 GetClientSize( &cw
, &ch
);
4853 m_headerWin
->SetSize( 0, 0, cw
, HEADER_HEIGHT
);
4854 m_mainWin
->SetSize( 0, HEADER_HEIGHT
+ 1, cw
, ch
- HEADER_HEIGHT
- 1 );
4856 else // no header window
4858 m_mainWin
->SetSize( 0, 0, cw
, ch
);
4862 void wxListCtrl::OnIdle( wxIdleEvent
& event
)
4866 // do it only if needed
4867 if ( !m_mainWin
->m_dirty
)
4870 m_mainWin
->RecalculatePositions();
4873 // ----------------------------------------------------------------------------
4875 // ----------------------------------------------------------------------------
4877 bool wxListCtrl::SetBackgroundColour( const wxColour
&colour
)
4881 m_mainWin
->SetBackgroundColour( colour
);
4882 m_mainWin
->m_dirty
= TRUE
;
4888 bool wxListCtrl::SetForegroundColour( const wxColour
&colour
)
4890 if ( !wxWindow::SetForegroundColour( colour
) )
4895 m_mainWin
->SetForegroundColour( colour
);
4896 m_mainWin
->m_dirty
= TRUE
;
4901 m_headerWin
->SetForegroundColour( colour
);
4907 bool wxListCtrl::SetFont( const wxFont
&font
)
4909 if ( !wxWindow::SetFont( font
) )
4914 m_mainWin
->SetFont( font
);
4915 m_mainWin
->m_dirty
= TRUE
;
4920 m_headerWin
->SetFont( font
);
4926 // ----------------------------------------------------------------------------
4927 // methods forwarded to m_mainWin
4928 // ----------------------------------------------------------------------------
4930 #if wxUSE_DRAG_AND_DROP
4932 void wxListCtrl::SetDropTarget( wxDropTarget
*dropTarget
)
4934 m_mainWin
->SetDropTarget( dropTarget
);
4937 wxDropTarget
*wxListCtrl::GetDropTarget() const
4939 return m_mainWin
->GetDropTarget();
4942 #endif // wxUSE_DRAG_AND_DROP
4944 bool wxListCtrl::SetCursor( const wxCursor
&cursor
)
4946 return m_mainWin
? m_mainWin
->wxWindow::SetCursor(cursor
) : FALSE
;
4949 wxColour
wxListCtrl::GetBackgroundColour() const
4951 return m_mainWin
? m_mainWin
->GetBackgroundColour() : wxColour();
4954 wxColour
wxListCtrl::GetForegroundColour() const
4956 return m_mainWin
? m_mainWin
->GetForegroundColour() : wxColour();
4959 bool wxListCtrl::DoPopupMenu( wxMenu
*menu
, int x
, int y
)
4962 return m_mainWin
->PopupMenu( menu
, x
, y
);
4965 #endif // wxUSE_MENUS
4968 void wxListCtrl::SetFocus()
4970 /* The test in window.cpp fails as we are a composite
4971 window, so it checks against "this", but not m_mainWin. */
4972 if ( FindFocus() != this )
4973 m_mainWin
->SetFocus();
4976 // ----------------------------------------------------------------------------
4977 // virtual list control support
4978 // ----------------------------------------------------------------------------
4980 wxString
wxListCtrl::OnGetItemText(long item
, long col
) const
4982 // this is a pure virtual function, in fact - which is not really pure
4983 // because the controls which are not virtual don't need to implement it
4984 wxFAIL_MSG( _T("not supposed to be called") );
4986 return wxEmptyString
;
4989 int wxListCtrl::OnGetItemImage(long item
) const
4992 wxFAIL_MSG( _T("not supposed to be called") );
4997 wxListItemAttr
*wxListCtrl::OnGetItemAttr(long item
) const
4999 wxASSERT_MSG( item
>= 0 && item
< GetItemCount(),
5000 _T("invalid item index in OnGetItemAttr()") );
5002 // no attributes by default
5006 void wxListCtrl::SetItemCount(long count
)
5008 wxASSERT_MSG( IsVirtual(), _T("this is for virtual controls only") );
5010 m_mainWin
->SetItemCount(count
);
5013 void wxListCtrl::RefreshItem(long item
)
5015 m_mainWin
->RefreshLine(item
);
5018 void wxListCtrl::RefreshItems(long itemFrom
, long itemTo
)
5020 m_mainWin
->RefreshLines(itemFrom
, itemTo
);
5023 #endif // wxUSE_LISTCTRL