1 /////////////////////////////////////////////////////////////////////////////
2 // Name: generic/listctrl.cpp
3 // Purpose: generic implementation of wxListCtrl
4 // Author: Robert Roebling
5 // Vadim Zeitlin (virtual list control support)
7 // Copyright: (c) 1998 Robert Roebling
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
14 1. we need to implement searching/sorting for virtual controls somehow
15 ?2. when changing selection the lines are refreshed twice
18 // ============================================================================
20 // ============================================================================
22 // ----------------------------------------------------------------------------
24 // ----------------------------------------------------------------------------
27 #pragma implementation "listctrl.h"
28 #pragma implementation "listctrlbase.h"
31 // For compilers that support precompilation, includes "wx.h".
32 #include "wx/wxprec.h"
43 #include "wx/dynarray.h"
45 #include "wx/dcscreen.h"
47 #include "wx/textctrl.h"
50 #include "wx/imaglist.h"
51 #include "wx/listctrl.h"
55 #include "wx/gtk/win_gtk.h"
58 // ----------------------------------------------------------------------------
60 // ----------------------------------------------------------------------------
62 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_BEGIN_DRAG
)
63 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_BEGIN_RDRAG
)
64 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_BEGIN_LABEL_EDIT
)
65 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_END_LABEL_EDIT
)
66 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_DELETE_ITEM
)
67 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_DELETE_ALL_ITEMS
)
68 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_GET_INFO
)
69 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_SET_INFO
)
70 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_ITEM_SELECTED
)
71 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_ITEM_DESELECTED
)
72 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_KEY_DOWN
)
73 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_INSERT_ITEM
)
74 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_COL_CLICK
)
75 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_COL_RIGHT_CLICK
)
76 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_COL_BEGIN_DRAG
)
77 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_COL_DRAGGING
)
78 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_COL_END_DRAG
)
79 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_ITEM_RIGHT_CLICK
)
80 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_ITEM_MIDDLE_CLICK
)
81 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_ITEM_ACTIVATED
)
82 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_ITEM_FOCUSED
)
83 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_CACHE_HINT
)
85 // ----------------------------------------------------------------------------
87 // ----------------------------------------------------------------------------
89 // the height of the header window (FIXME: should depend on its font!)
90 static const int HEADER_HEIGHT
= 23;
92 // the scrollbar units
93 static const int SCROLL_UNIT_X
= 15;
94 static const int SCROLL_UNIT_Y
= 15;
96 // the spacing between the lines (in report mode)
97 static const int LINE_SPACING
= 0;
99 // extra margins around the text label
100 static const int EXTRA_WIDTH
= 3;
101 static const int EXTRA_HEIGHT
= 4;
103 // offset for the header window
104 static const int HEADER_OFFSET_X
= 1;
105 static const int HEADER_OFFSET_Y
= 1;
107 // when autosizing the columns, add some slack
108 static const int AUTOSIZE_COL_MARGIN
= 10;
110 // default and minimal widths for the header columns
111 static const int WIDTH_COL_DEFAULT
= 80;
112 static const int WIDTH_COL_MIN
= 10;
114 // the space between the image and the text in the report mode
115 static const int IMAGE_MARGIN_IN_REPORT_MODE
= 5;
117 // ============================================================================
119 // ============================================================================
121 // ----------------------------------------------------------------------------
123 // ----------------------------------------------------------------------------
125 int CMPFUNC_CONV
wxSizeTCmpFn(size_t n1
, size_t n2
) { return n1
- n2
; }
127 WX_DEFINE_SORTED_EXPORTED_ARRAY(size_t, wxIndexArray
);
129 // this class is used to store the selected items in the virtual list control
130 // (but it is not tied to list control and so can be used with other controls
131 // such as wxListBox in wxUniv)
133 // the idea is to make it really smart later (i.e. store the selections as an
134 // array of ranes + individual items) but, as I don't have time to do it now
135 // (this would require writing code to merge/break ranges and much more) keep
136 // it simple but define a clean interface to it which allows it to be made
138 class WXDLLEXPORT wxSelectionStore
141 wxSelectionStore() : m_itemsSel(wxSizeTCmpFn
) { Init(); }
143 // set the total number of items we handle
144 void SetItemCount(size_t count
) { m_count
= count
; }
146 // special case of SetItemCount(0)
147 void Clear() { m_itemsSel
.Clear(); m_count
= 0; }
149 // must be called when a new item is inserted/added
150 void OnItemAdd(size_t item
) { wxFAIL_MSG( _T("TODO") ); }
152 // must be called when an item is deleted
153 void OnItemDelete(size_t item
);
155 // select one item, use SelectRange() insted if possible!
157 // returns true if the items selection really changed
158 bool SelectItem(size_t item
, bool select
= TRUE
);
160 // select the range of items
162 // return true and fill the itemsChanged array with the indices of items
163 // which have changed state if "few" of them did, otherwise return false
164 // (meaning that too many items changed state to bother counting them
166 bool SelectRange(size_t itemFrom
, size_t itemTo
,
168 wxArrayInt
*itemsChanged
= NULL
);
170 // return true if the given item is selected
171 bool IsSelected(size_t item
) const;
173 // return the total number of selected items
174 size_t GetSelectedCount() const
176 return m_defaultState
? m_count
- m_itemsSel
.GetCount()
177 : m_itemsSel
.GetCount();
182 void Init() { m_defaultState
= FALSE
; }
184 // the total number of items we handle
187 // the default state: normally, FALSE (i.e. off) but maybe set to TRUE if
188 // there are more selected items than non selected ones - this allows to
189 // handle selection of all items efficiently
192 // the array of items whose selection state is different from default
193 wxIndexArray m_itemsSel
;
195 DECLARE_NO_COPY_CLASS(wxSelectionStore
)
198 //-----------------------------------------------------------------------------
199 // wxListItemData (internal)
200 //-----------------------------------------------------------------------------
202 class WXDLLEXPORT wxListItemData
205 wxListItemData(wxListMainWindow
*owner
);
208 void SetItem( const wxListItem
&info
);
209 void SetImage( int image
) { m_image
= image
; }
210 void SetData( long data
) { m_data
= data
; }
211 void SetPosition( int x
, int y
);
212 void SetSize( int width
, int height
);
214 bool HasText() const { return !m_text
.empty(); }
215 const wxString
& GetText() const { return m_text
; }
216 void SetText(const wxString
& text
) { m_text
= text
; }
218 // we can't use empty string for measuring the string width/height, so
219 // always return something
220 wxString
GetTextForMeasuring() const
222 wxString s
= GetText();
229 bool IsHit( int x
, int y
) const;
233 int GetWidth() const;
234 int GetHeight() const;
236 int GetImage() const { return m_image
; }
237 bool HasImage() const { return GetImage() != -1; }
239 void GetItem( wxListItem
&info
) const;
241 void SetAttr(wxListItemAttr
*attr
) { m_attr
= attr
; }
242 wxListItemAttr
*GetAttr() const { return m_attr
; }
245 // the item image or -1
248 // user data associated with the item
251 // the item coordinates are not used in report mode, instead this pointer
252 // is NULL and the owner window is used to retrieve the item position and
256 // the list ctrl we are in
257 wxListMainWindow
*m_owner
;
259 // custom attributes or NULL
260 wxListItemAttr
*m_attr
;
263 // common part of all ctors
269 //-----------------------------------------------------------------------------
270 // wxListHeaderData (internal)
271 //-----------------------------------------------------------------------------
273 class WXDLLEXPORT wxListHeaderData
: public wxObject
277 wxListHeaderData( const wxListItem
&info
);
278 void SetItem( const wxListItem
&item
);
279 void SetPosition( int x
, int y
);
280 void SetWidth( int w
);
281 void SetFormat( int format
);
282 void SetHeight( int h
);
283 bool HasImage() const;
285 bool HasText() const { return !m_text
.empty(); }
286 const wxString
& GetText() const { return m_text
; }
287 void SetText(const wxString
& text
) { m_text
= text
; }
289 void GetItem( wxListItem
&item
);
291 bool IsHit( int x
, int y
) const;
292 int GetImage() const;
293 int GetWidth() const;
294 int GetFormat() const;
310 //-----------------------------------------------------------------------------
311 // wxListLineData (internal)
312 //-----------------------------------------------------------------------------
314 WX_DECLARE_LIST(wxListItemData
, wxListItemDataList
);
315 #include "wx/listimpl.cpp"
316 WX_DEFINE_LIST(wxListItemDataList
);
318 class WXDLLEXPORT wxListLineData
321 // the list of subitems: only may have more than one item in report mode
322 wxListItemDataList m_items
;
324 // this is not used in report view
336 // the part to be highlighted
337 wxRect m_rectHighlight
;
340 // is this item selected? [NB: not used in virtual mode]
343 // back pointer to the list ctrl
344 wxListMainWindow
*m_owner
;
347 wxListLineData(wxListMainWindow
*owner
);
349 ~wxListLineData() { delete m_gi
; }
351 // are we in report mode?
352 inline bool InReportView() const;
354 // are we in virtual report mode?
355 inline bool IsVirtual() const;
357 // these 2 methods shouldn't be called for report view controls, in that
358 // case we determine our position/size ourselves
360 // calculate the size of the line
361 void CalculateSize( wxDC
*dc
, int spacing
);
363 // remember the position this line appears at
364 void SetPosition( int x
, int y
, int window_width
, int spacing
);
368 void SetImage( int image
) { SetImage(0, image
); }
369 int GetImage() const { return GetImage(0); }
370 bool HasImage() const { return GetImage() != -1; }
371 bool HasText() const { return !GetText(0).empty(); }
373 void SetItem( int index
, const wxListItem
&info
);
374 void GetItem( int index
, wxListItem
&info
);
376 wxString
GetText(int index
) const;
377 void SetText( int index
, const wxString s
);
379 wxListItemAttr
*GetAttr() const;
380 void SetAttr(wxListItemAttr
*attr
);
382 // return true if the highlighting really changed
383 bool Highlight( bool on
);
385 void ReverseHighlight();
387 bool IsHighlighted() const
389 wxASSERT_MSG( !IsVirtual(), _T("unexpected call to IsHighlighted") );
391 return m_highlighted
;
394 // draw the line on the given DC in icon/list mode
395 void Draw( wxDC
*dc
);
397 // the same in report mode
398 void DrawInReportMode( wxDC
*dc
,
400 const wxRect
& rectHL
,
404 // set the line to contain num items (only can be > 1 in report mode)
405 void InitItems( int num
);
407 // get the mode (i.e. style) of the list control
408 inline int GetMode() const;
410 // prepare the DC for drawing with these item's attributes, return true if
411 // we need to draw the items background to highlight it, false otherwise
412 bool SetAttributes(wxDC
*dc
,
413 const wxListItemAttr
*attr
,
416 // these are only used by GetImage/SetImage above, we don't support images
417 // with subitems at the public API level yet
418 void SetImage( int index
, int image
);
419 int GetImage( int index
) const;
422 WX_DECLARE_EXPORTED_OBJARRAY(wxListLineData
, wxListLineDataArray
);
423 #include "wx/arrimpl.cpp"
424 WX_DEFINE_OBJARRAY(wxListLineDataArray
);
426 //-----------------------------------------------------------------------------
427 // wxListHeaderWindow (internal)
428 //-----------------------------------------------------------------------------
430 class WXDLLEXPORT wxListHeaderWindow
: public wxWindow
433 wxListMainWindow
*m_owner
;
434 wxCursor
*m_currentCursor
;
435 wxCursor
*m_resizeCursor
;
438 // column being resized
441 // divider line position in logical (unscrolled) coords
444 // minimal position beyond which the divider line can't be dragged in
449 wxListHeaderWindow();
451 wxListHeaderWindow( wxWindow
*win
,
453 wxListMainWindow
*owner
,
454 const wxPoint
&pos
= wxDefaultPosition
,
455 const wxSize
&size
= wxDefaultSize
,
457 const wxString
&name
= "wxlistctrlcolumntitles" );
459 virtual ~wxListHeaderWindow();
461 void DoDrawRect( wxDC
*dc
, int x
, int y
, int w
, int h
);
463 void AdjustDC(wxDC
& dc
);
465 void OnPaint( wxPaintEvent
&event
);
466 void OnMouse( wxMouseEvent
&event
);
467 void OnSetFocus( wxFocusEvent
&event
);
473 // common part of all ctors
476 DECLARE_DYNAMIC_CLASS(wxListHeaderWindow
)
477 DECLARE_EVENT_TABLE()
480 //-----------------------------------------------------------------------------
481 // wxListRenameTimer (internal)
482 //-----------------------------------------------------------------------------
484 class WXDLLEXPORT wxListRenameTimer
: public wxTimer
487 wxListMainWindow
*m_owner
;
490 wxListRenameTimer( wxListMainWindow
*owner
);
494 //-----------------------------------------------------------------------------
495 // wxListTextCtrl (internal)
496 //-----------------------------------------------------------------------------
498 class WXDLLEXPORT wxListTextCtrl
: public wxTextCtrl
503 wxListMainWindow
*m_owner
;
504 wxString m_startValue
;
508 wxListTextCtrl( wxWindow
*parent
, const wxWindowID id
,
509 bool *accept
, wxString
*res
, wxListMainWindow
*owner
,
510 const wxString
&value
= "",
511 const wxPoint
&pos
= wxDefaultPosition
, const wxSize
&size
= wxDefaultSize
,
513 const wxValidator
& validator
= wxDefaultValidator
,
514 const wxString
&name
= "listctrltextctrl" );
515 void OnChar( wxKeyEvent
&event
);
516 void OnKeyUp( wxKeyEvent
&event
);
517 void OnKillFocus( wxFocusEvent
&event
);
520 DECLARE_DYNAMIC_CLASS(wxListTextCtrl
);
521 DECLARE_EVENT_TABLE()
524 //-----------------------------------------------------------------------------
525 // wxListMainWindow (internal)
526 //-----------------------------------------------------------------------------
528 WX_DECLARE_LIST(wxListHeaderData
, wxListHeaderDataList
);
529 #include "wx/listimpl.cpp"
530 WX_DEFINE_LIST(wxListHeaderDataList
);
532 class WXDLLEXPORT wxListMainWindow
: public wxScrolledWindow
536 wxListMainWindow( wxWindow
*parent
,
538 const wxPoint
& pos
= wxDefaultPosition
,
539 const wxSize
& size
= wxDefaultSize
,
541 const wxString
&name
= _T("listctrlmainwindow") );
543 virtual ~wxListMainWindow();
545 bool HasFlag(int flag
) const { return m_parent
->HasFlag(flag
); }
547 // return true if this is a virtual list control
548 bool IsVirtual() const { return HasFlag(wxLC_VIRTUAL
); }
550 // return true if the control is in report mode
551 bool InReportView() const { return HasFlag(wxLC_REPORT
); }
553 // return true if we are in single selection mode, false if multi sel
554 bool IsSingleSel() const { return HasFlag(wxLC_SINGLE_SEL
); }
556 // do we have a header window?
557 bool HasHeader() const
558 { return HasFlag(wxLC_REPORT
) && !HasFlag(wxLC_NO_HEADER
); }
560 void HighlightAll( bool on
);
562 // all these functions only do something if the line is currently visible
564 // change the line "selected" state, return TRUE if it really changed
565 bool HighlightLine( size_t line
, bool highlight
= TRUE
);
567 // as HighlightLine() but do it for the range of lines: this is incredibly
568 // more efficient for virtual list controls!
570 // NB: unlike HighlightLine() this one does refresh the lines on screen
571 void HighlightLines( size_t lineFrom
, size_t lineTo
, bool on
= TRUE
);
573 // toggle the line state and refresh it
574 void ReverseHighlight( size_t line
)
575 { HighlightLine(line
, !IsHighlighted(line
)); RefreshLine(line
); }
577 // return true if the line is highlighted
578 bool IsHighlighted(size_t line
) const;
580 // refresh one or several lines at once
581 void RefreshLine( size_t line
);
582 void RefreshLines( size_t lineFrom
, size_t lineTo
);
584 // refresh all selected items
585 void RefreshSelected();
587 // refresh all lines below the given one: the difference with
588 // RefreshLines() is that the index here might not be a valid one (happens
589 // when the last line is deleted)
590 void RefreshAfter( size_t lineFrom
);
592 // the methods which are forwarded to wxListLineData itself in list/icon
593 // modes but are here because the lines don't store their positions in the
596 // get the bound rect for the entire line
597 wxRect
GetLineRect(size_t line
) const;
599 // get the bound rect of the label
600 wxRect
GetLineLabelRect(size_t line
) const;
602 // get the bound rect of the items icon (only may be called if we do have
604 wxRect
GetLineIconRect(size_t line
) const;
606 // get the rect to be highlighted when the item has focus
607 wxRect
GetLineHighlightRect(size_t line
) const;
609 // get the size of the total line rect
610 wxSize
GetLineSize(size_t line
) const
611 { return GetLineRect(line
).GetSize(); }
613 // return the hit code for the corresponding position (in this line)
614 long HitTestLine(size_t line
, int x
, int y
) const;
616 // bring the selected item into view, scrolling to it if necessary
617 void MoveToItem(size_t item
);
619 // bring the current item into view
620 void MoveToFocus() { MoveToItem(m_current
); }
622 // start editing the label of the given item
623 void EditLabel( long item
);
625 // suspend/resume redrawing the control
629 void OnRenameTimer();
630 void OnRenameAccept();
632 void OnMouse( wxMouseEvent
&event
);
634 // called to switch the selection from the current item to newCurrent,
635 void OnArrowChar( size_t newCurrent
, const wxKeyEvent
& event
);
637 void OnChar( wxKeyEvent
&event
);
638 void OnKeyDown( wxKeyEvent
&event
);
639 void OnSetFocus( wxFocusEvent
&event
);
640 void OnKillFocus( wxFocusEvent
&event
);
641 void OnScroll(wxScrollWinEvent
& event
) ;
643 void OnPaint( wxPaintEvent
&event
);
645 void DrawImage( int index
, wxDC
*dc
, int x
, int y
);
646 void GetImageSize( int index
, int &width
, int &height
) const;
647 int GetTextLength( const wxString
&s
) const;
649 void SetImageList( wxImageList
*imageList
, int which
);
650 void SetItemSpacing( int spacing
, bool isSmall
= FALSE
);
651 int GetItemSpacing( bool isSmall
= FALSE
);
653 void SetColumn( int col
, wxListItem
&item
);
654 void SetColumnWidth( int col
, int width
);
655 void GetColumn( int col
, wxListItem
&item
) const;
656 int GetColumnWidth( int col
) const;
657 int GetColumnCount() const { return m_columns
.GetCount(); }
659 // returns the sum of the heights of all columns
660 int GetHeaderWidth() const;
662 int GetCountPerPage() const;
664 void SetItem( wxListItem
&item
);
665 void GetItem( wxListItem
&item
);
666 void SetItemState( long item
, long state
, long stateMask
);
667 int GetItemState( long item
, long stateMask
);
668 void GetItemRect( long index
, wxRect
&rect
);
669 bool GetItemPosition( long item
, wxPoint
& pos
);
670 int GetSelectedItemCount();
672 // set the scrollbars and update the positions of the items
673 void RecalculatePositions(bool noRefresh
= FALSE
);
675 // refresh the window and the header
678 long GetNextItem( long item
, int geometry
, int state
);
679 void DeleteItem( long index
);
680 void DeleteAllItems();
681 void DeleteColumn( int col
);
682 void DeleteEverything();
683 void EnsureVisible( long index
);
684 long FindItem( long start
, const wxString
& str
, bool partial
= FALSE
);
685 long FindItem( long start
, long data
);
686 long HitTest( int x
, int y
, int &flags
);
687 void InsertItem( wxListItem
&item
);
688 void InsertColumn( long col
, wxListItem
&item
);
689 void SortItems( wxListCtrlCompare fn
, long data
);
691 size_t GetItemCount() const;
692 bool IsEmpty() const { return GetItemCount() == 0; }
693 void SetItemCount(long count
);
695 // change the current (== focused) item, send a notification event
696 void ChangeCurrent(size_t current
);
697 void ResetCurrent() { ChangeCurrent((size_t)-1); }
698 bool HasCurrent() const { return m_current
!= (size_t)-1; }
700 // send out a wxListEvent
701 void SendNotify( size_t line
,
703 wxPoint point
= wxDefaultPosition
);
705 // override base class virtual to reset m_lineHeight when the font changes
706 virtual bool SetFont(const wxFont
& font
)
708 if ( !wxScrolledWindow::SetFont(font
) )
716 // these are for wxListLineData usage only
718 // get the backpointer to the list ctrl
719 wxListCtrl
*GetListCtrl() const
721 return wxStaticCast(GetParent(), wxListCtrl
);
724 // get the height of all lines (assuming they all do have the same height)
725 wxCoord
GetLineHeight() const;
727 // get the y position of the given line (only for report view)
728 wxCoord
GetLineY(size_t line
) const;
730 // get the brush to use for the item highlighting
731 wxBrush
*GetHighlightBrush() const
733 return m_hasFocus
? m_highlightBrush
: m_highlightUnfocusedBrush
;
737 // the array of all line objects for a non virtual list control
738 wxListLineDataArray m_lines
;
740 // the list of column objects
741 wxListHeaderDataList m_columns
;
743 // currently focused item or -1
746 // the item currently being edited or -1
747 size_t m_currentEdit
;
749 // the number of lines per page
752 // this flag is set when something which should result in the window
753 // redrawing happens (i.e. an item was added or deleted, or its appearance
754 // changed) and OnPaint() doesn't redraw the window while it is set which
755 // allows to minimize the number of repaintings when a lot of items are
756 // being added. The real repainting occurs only after the next OnIdle()
760 wxColour
*m_highlightColour
;
763 wxImageList
*m_small_image_list
;
764 wxImageList
*m_normal_image_list
;
766 int m_normal_spacing
;
770 wxTimer
*m_renameTimer
;
772 wxString m_renameRes
;
777 // for double click logic
778 size_t m_lineLastClicked
,
779 m_lineBeforeLastClicked
;
782 // the total count of items in a virtual list control
785 // the object maintaining the items selection state, only used in virtual
787 wxSelectionStore m_selStore
;
789 // common part of all ctors
792 // intiialize m_[xy]Scroll
793 void InitScrolling();
795 // get the line data for the given index
796 wxListLineData
*GetLine(size_t n
) const
798 wxASSERT_MSG( n
!= (size_t)-1, _T("invalid line index") );
802 wxConstCast(this, wxListMainWindow
)->CacheLineData(n
);
810 // get a dummy line which can be used for geometry calculations and such:
811 // you must use GetLine() if you want to really draw the line
812 wxListLineData
*GetDummyLine() const;
814 // cache the line data of the n-th line in m_lines[0]
815 void CacheLineData(size_t line
);
817 // get the range of visible lines
818 void GetVisibleLinesRange(size_t *from
, size_t *to
);
820 // force us to recalculate the range of visible lines
821 void ResetVisibleLinesRange() { m_lineFrom
= (size_t)-1; }
823 // get the colour to be used for drawing the rules
824 wxColour
GetRuleColour() const
829 return wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DLIGHT
);
834 // initialize the current item if needed
835 void UpdateCurrent();
837 // delete all items but don't refresh: called from dtor
838 void DoDeleteAllItems();
840 // the height of one line using the current font
841 wxCoord m_lineHeight
;
843 // the total header width or 0 if not calculated yet
844 wxCoord m_headerWidth
;
846 // the first and last lines being shown on screen right now (inclusive),
847 // both may be -1 if they must be calculated so never access them directly:
848 // use GetVisibleLinesRange() above instead
852 // the brushes to use for item highlighting when we do/don't have focus
853 wxBrush
*m_highlightBrush
,
854 *m_highlightUnfocusedBrush
;
856 // if this is > 0, the control is frozen and doesn't redraw itself
857 size_t m_freezeCount
;
859 DECLARE_DYNAMIC_CLASS(wxListMainWindow
);
860 DECLARE_EVENT_TABLE()
863 // ============================================================================
865 // ============================================================================
867 // ----------------------------------------------------------------------------
869 // ----------------------------------------------------------------------------
871 bool wxSelectionStore::IsSelected(size_t item
) const
873 bool isSel
= m_itemsSel
.Index(item
) != wxNOT_FOUND
;
875 // if the default state is to be selected, being in m_itemsSel means that
876 // the item is not selected, so we have to inverse the logic
877 return m_defaultState
? !isSel
: isSel
;
880 bool wxSelectionStore::SelectItem(size_t item
, bool select
)
882 // search for the item ourselves as like this we get the index where to
883 // insert it later if needed, so we do only one search in the array instead
884 // of two (adding item to a sorted array requires a search)
885 size_t index
= m_itemsSel
.IndexForInsert(item
);
886 bool isSel
= index
< m_itemsSel
.GetCount() && m_itemsSel
[index
] == item
;
888 if ( select
!= m_defaultState
)
892 m_itemsSel
.AddAt(item
, index
);
897 else // reset to default state
901 m_itemsSel
.RemoveAt(index
);
909 bool wxSelectionStore::SelectRange(size_t itemFrom
, size_t itemTo
,
911 wxArrayInt
*itemsChanged
)
913 // 100 is hardcoded but it shouldn't matter much: the important thing is
914 // that we don't refresh everything when really few (e.g. 1 or 2) items
916 static const size_t MANY_ITEMS
= 100;
918 wxASSERT_MSG( itemFrom
<= itemTo
, _T("should be in order") );
920 // are we going to have more [un]selected items than the other ones?
921 if ( itemTo
- itemFrom
> m_count
/2 )
923 if ( select
!= m_defaultState
)
925 // the default state now becomes the same as 'select'
926 m_defaultState
= select
;
928 // so all the old selections (which had state select) shouldn't be
929 // selected any more, but all the other ones should
930 wxIndexArray selOld
= m_itemsSel
;
933 // TODO: it should be possible to optimize the searches a bit
934 // knowing the possible range
937 for ( item
= 0; item
< itemFrom
; item
++ )
939 if ( selOld
.Index(item
) == wxNOT_FOUND
)
940 m_itemsSel
.Add(item
);
943 for ( item
= itemTo
+ 1; item
< m_count
; item
++ )
945 if ( selOld
.Index(item
) == wxNOT_FOUND
)
946 m_itemsSel
.Add(item
);
949 // many items (> half) changed state
952 else // select == m_defaultState
954 // get the inclusive range of items between itemFrom and itemTo
955 size_t count
= m_itemsSel
.GetCount(),
956 start
= m_itemsSel
.IndexForInsert(itemFrom
),
957 end
= m_itemsSel
.IndexForInsert(itemTo
);
959 if ( start
== count
|| m_itemsSel
[start
] < itemFrom
)
964 if ( end
== count
|| m_itemsSel
[end
] > itemTo
)
971 // delete all of them (from end to avoid changing indices)
972 for ( int i
= end
; i
>= (int)start
; i
-- )
976 if ( itemsChanged
->GetCount() > MANY_ITEMS
)
978 // stop counting (see comment below)
982 itemsChanged
->Add(m_itemsSel
[i
]);
985 m_itemsSel
.RemoveAt(i
);
990 else // "few" items change state
994 itemsChanged
->Empty();
997 // just add the items to the selection
998 for ( size_t item
= itemFrom
; item
<= itemTo
; item
++ )
1000 if ( SelectItem(item
, select
) && itemsChanged
)
1002 itemsChanged
->Add(item
);
1004 if ( itemsChanged
->GetCount() > MANY_ITEMS
)
1006 // stop counting them, we'll just eat gobs of memory
1007 // for nothing at all - faster to refresh everything in
1009 itemsChanged
= NULL
;
1015 // we set it to NULL if there are many items changing state
1016 return itemsChanged
!= NULL
;
1019 void wxSelectionStore::OnItemDelete(size_t item
)
1021 size_t count
= m_itemsSel
.GetCount(),
1022 i
= m_itemsSel
.IndexForInsert(item
);
1024 if ( i
< count
&& m_itemsSel
[i
] == item
)
1026 // this item itself was in m_itemsSel, remove it from there
1027 m_itemsSel
.RemoveAt(i
);
1032 // and adjust the index of all which follow it
1035 // all following elements must be greater than the one we deleted
1036 wxASSERT_MSG( m_itemsSel
[i
] > item
, _T("logic error") );
1042 //-----------------------------------------------------------------------------
1044 //-----------------------------------------------------------------------------
1046 wxListItemData::~wxListItemData()
1048 // in the virtual list control the attributes are managed by the main
1049 // program, so don't delete them
1050 if ( !m_owner
->IsVirtual() )
1058 void wxListItemData::Init()
1066 wxListItemData::wxListItemData(wxListMainWindow
*owner
)
1072 if ( owner
->InReportView() )
1078 m_rect
= new wxRect
;
1082 void wxListItemData::SetItem( const wxListItem
&info
)
1084 if ( info
.m_mask
& wxLIST_MASK_TEXT
)
1085 SetText(info
.m_text
);
1086 if ( info
.m_mask
& wxLIST_MASK_IMAGE
)
1087 m_image
= info
.m_image
;
1088 if ( info
.m_mask
& wxLIST_MASK_DATA
)
1089 m_data
= info
.m_data
;
1091 if ( info
.HasAttributes() )
1094 *m_attr
= *info
.GetAttributes();
1096 m_attr
= new wxListItemAttr(*info
.GetAttributes());
1104 m_rect
->width
= info
.m_width
;
1108 void wxListItemData::SetPosition( int x
, int y
)
1110 wxCHECK_RET( m_rect
, _T("unexpected SetPosition() call") );
1116 void wxListItemData::SetSize( int width
, int height
)
1118 wxCHECK_RET( m_rect
, _T("unexpected SetSize() call") );
1121 m_rect
->width
= width
;
1123 m_rect
->height
= height
;
1126 bool wxListItemData::IsHit( int x
, int y
) const
1128 wxCHECK_MSG( m_rect
, FALSE
, _T("can't be called in this mode") );
1130 return wxRect(GetX(), GetY(), GetWidth(), GetHeight()).Inside(x
, y
);
1133 int wxListItemData::GetX() const
1135 wxCHECK_MSG( m_rect
, 0, _T("can't be called in this mode") );
1140 int wxListItemData::GetY() const
1142 wxCHECK_MSG( m_rect
, 0, _T("can't be called in this mode") );
1147 int wxListItemData::GetWidth() const
1149 wxCHECK_MSG( m_rect
, 0, _T("can't be called in this mode") );
1151 return m_rect
->width
;
1154 int wxListItemData::GetHeight() const
1156 wxCHECK_MSG( m_rect
, 0, _T("can't be called in this mode") );
1158 return m_rect
->height
;
1161 void wxListItemData::GetItem( wxListItem
&info
) const
1163 info
.m_text
= m_text
;
1164 info
.m_image
= m_image
;
1165 info
.m_data
= m_data
;
1169 if ( m_attr
->HasTextColour() )
1170 info
.SetTextColour(m_attr
->GetTextColour());
1171 if ( m_attr
->HasBackgroundColour() )
1172 info
.SetBackgroundColour(m_attr
->GetBackgroundColour());
1173 if ( m_attr
->HasFont() )
1174 info
.SetFont(m_attr
->GetFont());
1178 //-----------------------------------------------------------------------------
1180 //-----------------------------------------------------------------------------
1182 void wxListHeaderData::Init()
1193 wxListHeaderData::wxListHeaderData()
1198 wxListHeaderData::wxListHeaderData( const wxListItem
&item
)
1205 void wxListHeaderData::SetItem( const wxListItem
&item
)
1207 m_mask
= item
.m_mask
;
1209 if ( m_mask
& wxLIST_MASK_TEXT
)
1210 m_text
= item
.m_text
;
1212 if ( m_mask
& wxLIST_MASK_IMAGE
)
1213 m_image
= item
.m_image
;
1215 if ( m_mask
& wxLIST_MASK_FORMAT
)
1216 m_format
= item
.m_format
;
1218 if ( m_mask
& wxLIST_MASK_WIDTH
)
1219 SetWidth(item
.m_width
);
1222 void wxListHeaderData::SetPosition( int x
, int y
)
1228 void wxListHeaderData::SetHeight( int h
)
1233 void wxListHeaderData::SetWidth( int w
)
1237 m_width
= WIDTH_COL_DEFAULT
;
1238 else if (m_width
< WIDTH_COL_MIN
)
1239 m_width
= WIDTH_COL_MIN
;
1242 void wxListHeaderData::SetFormat( int format
)
1247 bool wxListHeaderData::HasImage() const
1249 return m_image
!= -1;
1252 bool wxListHeaderData::IsHit( int x
, int y
) const
1254 return ((x
>= m_xpos
) && (x
<= m_xpos
+m_width
) && (y
>= m_ypos
) && (y
<= m_ypos
+m_height
));
1257 void wxListHeaderData::GetItem( wxListItem
& item
)
1259 item
.m_mask
= m_mask
;
1260 item
.m_text
= m_text
;
1261 item
.m_image
= m_image
;
1262 item
.m_format
= m_format
;
1263 item
.m_width
= m_width
;
1266 int wxListHeaderData::GetImage() const
1271 int wxListHeaderData::GetWidth() const
1276 int wxListHeaderData::GetFormat() const
1281 //-----------------------------------------------------------------------------
1283 //-----------------------------------------------------------------------------
1285 inline int wxListLineData::GetMode() const
1287 return m_owner
->GetListCtrl()->GetWindowStyleFlag() & wxLC_MASK_TYPE
;
1290 inline bool wxListLineData::InReportView() const
1292 return m_owner
->HasFlag(wxLC_REPORT
);
1295 inline bool wxListLineData::IsVirtual() const
1297 return m_owner
->IsVirtual();
1300 wxListLineData::wxListLineData( wxListMainWindow
*owner
)
1303 m_items
.DeleteContents( TRUE
);
1305 if ( InReportView() )
1311 m_gi
= new GeometryInfo
;
1314 m_highlighted
= FALSE
;
1316 InitItems( GetMode() == wxLC_REPORT
? m_owner
->GetColumnCount() : 1 );
1319 void wxListLineData::CalculateSize( wxDC
*dc
, int spacing
)
1321 wxListItemDataList::Node
*node
= m_items
.GetFirst();
1322 wxCHECK_RET( node
, _T("no subitems at all??") );
1324 wxListItemData
*item
= node
->GetData();
1326 switch ( GetMode() )
1329 case wxLC_SMALL_ICON
:
1331 m_gi
->m_rectAll
.width
= spacing
;
1333 wxString s
= item
->GetText();
1339 m_gi
->m_rectLabel
.width
=
1340 m_gi
->m_rectLabel
.height
= 0;
1344 dc
->GetTextExtent( s
, &lw
, &lh
);
1345 if (lh
< SCROLL_UNIT_Y
)
1350 m_gi
->m_rectAll
.height
= spacing
+ lh
;
1352 m_gi
->m_rectAll
.width
= lw
;
1354 m_gi
->m_rectLabel
.width
= lw
;
1355 m_gi
->m_rectLabel
.height
= lh
;
1358 if (item
->HasImage())
1361 m_owner
->GetImageSize( item
->GetImage(), w
, h
);
1362 m_gi
->m_rectIcon
.width
= w
+ 8;
1363 m_gi
->m_rectIcon
.height
= h
+ 8;
1365 if ( m_gi
->m_rectIcon
.width
> m_gi
->m_rectAll
.width
)
1366 m_gi
->m_rectAll
.width
= m_gi
->m_rectIcon
.width
;
1367 if ( m_gi
->m_rectIcon
.height
+ lh
> m_gi
->m_rectAll
.height
- 4 )
1368 m_gi
->m_rectAll
.height
= m_gi
->m_rectIcon
.height
+ lh
+ 4;
1371 if ( item
->HasText() )
1373 m_gi
->m_rectHighlight
.width
= m_gi
->m_rectLabel
.width
;
1374 m_gi
->m_rectHighlight
.height
= m_gi
->m_rectLabel
.height
;
1376 else // no text, highlight the icon
1378 m_gi
->m_rectHighlight
.width
= m_gi
->m_rectIcon
.width
;
1379 m_gi
->m_rectHighlight
.height
= m_gi
->m_rectIcon
.height
;
1386 wxString s
= item
->GetTextForMeasuring();
1389 dc
->GetTextExtent( s
, &lw
, &lh
);
1390 if (lh
< SCROLL_UNIT_Y
)
1395 m_gi
->m_rectLabel
.width
= lw
;
1396 m_gi
->m_rectLabel
.height
= lh
;
1398 m_gi
->m_rectAll
.width
= lw
;
1399 m_gi
->m_rectAll
.height
= lh
;
1401 if (item
->HasImage())
1404 m_owner
->GetImageSize( item
->GetImage(), w
, h
);
1405 m_gi
->m_rectIcon
.width
= w
;
1406 m_gi
->m_rectIcon
.height
= h
;
1408 m_gi
->m_rectAll
.width
+= 4 + w
;
1409 if (h
> m_gi
->m_rectAll
.height
)
1410 m_gi
->m_rectAll
.height
= h
;
1413 m_gi
->m_rectHighlight
.width
= m_gi
->m_rectAll
.width
;
1414 m_gi
->m_rectHighlight
.height
= m_gi
->m_rectAll
.height
;
1419 wxFAIL_MSG( _T("unexpected call to SetSize") );
1423 wxFAIL_MSG( _T("unknown mode") );
1427 void wxListLineData::SetPosition( int x
, int y
,
1431 wxListItemDataList::Node
*node
= m_items
.GetFirst();
1432 wxCHECK_RET( node
, _T("no subitems at all??") );
1434 wxListItemData
*item
= node
->GetData();
1436 switch ( GetMode() )
1439 case wxLC_SMALL_ICON
:
1440 m_gi
->m_rectAll
.x
= x
;
1441 m_gi
->m_rectAll
.y
= y
;
1443 if ( item
->HasImage() )
1445 m_gi
->m_rectIcon
.x
= m_gi
->m_rectAll
.x
+ 4
1446 + (spacing
- m_gi
->m_rectIcon
.width
)/2;
1447 m_gi
->m_rectIcon
.y
= m_gi
->m_rectAll
.y
+ 4;
1450 if ( item
->HasText() )
1452 if (m_gi
->m_rectAll
.width
> spacing
)
1453 m_gi
->m_rectLabel
.x
= m_gi
->m_rectAll
.x
+ 2;
1455 m_gi
->m_rectLabel
.x
= m_gi
->m_rectAll
.x
+ 2 + (spacing
/2) - (m_gi
->m_rectLabel
.width
/2);
1456 m_gi
->m_rectLabel
.y
= m_gi
->m_rectAll
.y
+ m_gi
->m_rectAll
.height
+ 2 - m_gi
->m_rectLabel
.height
;
1457 m_gi
->m_rectHighlight
.x
= m_gi
->m_rectLabel
.x
- 2;
1458 m_gi
->m_rectHighlight
.y
= m_gi
->m_rectLabel
.y
- 2;
1460 else // no text, highlight the icon
1462 m_gi
->m_rectHighlight
.x
= m_gi
->m_rectIcon
.x
- 4;
1463 m_gi
->m_rectHighlight
.y
= m_gi
->m_rectIcon
.y
- 4;
1468 m_gi
->m_rectAll
.x
= x
;
1469 m_gi
->m_rectAll
.y
= y
;
1471 m_gi
->m_rectHighlight
.x
= m_gi
->m_rectAll
.x
;
1472 m_gi
->m_rectHighlight
.y
= m_gi
->m_rectAll
.y
;
1473 m_gi
->m_rectLabel
.y
= m_gi
->m_rectAll
.y
+ 2;
1475 if (item
->HasImage())
1477 m_gi
->m_rectIcon
.x
= m_gi
->m_rectAll
.x
+ 2;
1478 m_gi
->m_rectIcon
.y
= m_gi
->m_rectAll
.y
+ 2;
1479 m_gi
->m_rectLabel
.x
= m_gi
->m_rectAll
.x
+ 6 + m_gi
->m_rectIcon
.width
;
1483 m_gi
->m_rectLabel
.x
= m_gi
->m_rectAll
.x
+ 2;
1488 wxFAIL_MSG( _T("unexpected call to SetPosition") );
1492 wxFAIL_MSG( _T("unknown mode") );
1496 void wxListLineData::InitItems( int num
)
1498 for (int i
= 0; i
< num
; i
++)
1499 m_items
.Append( new wxListItemData(m_owner
) );
1502 void wxListLineData::SetItem( int index
, const wxListItem
&info
)
1504 wxListItemDataList::Node
*node
= m_items
.Item( index
);
1505 wxCHECK_RET( node
, _T("invalid column index in SetItem") );
1507 wxListItemData
*item
= node
->GetData();
1508 item
->SetItem( info
);
1511 void wxListLineData::GetItem( int index
, wxListItem
&info
)
1513 wxListItemDataList::Node
*node
= m_items
.Item( index
);
1516 wxListItemData
*item
= node
->GetData();
1517 item
->GetItem( info
);
1521 wxString
wxListLineData::GetText(int index
) const
1525 wxListItemDataList::Node
*node
= m_items
.Item( index
);
1528 wxListItemData
*item
= node
->GetData();
1529 s
= item
->GetText();
1535 void wxListLineData::SetText( int index
, const wxString s
)
1537 wxListItemDataList::Node
*node
= m_items
.Item( index
);
1540 wxListItemData
*item
= node
->GetData();
1545 void wxListLineData::SetImage( int index
, int image
)
1547 wxListItemDataList::Node
*node
= m_items
.Item( index
);
1548 wxCHECK_RET( node
, _T("invalid column index in SetImage()") );
1550 wxListItemData
*item
= node
->GetData();
1551 item
->SetImage(image
);
1554 int wxListLineData::GetImage( int index
) const
1556 wxListItemDataList::Node
*node
= m_items
.Item( index
);
1557 wxCHECK_MSG( node
, -1, _T("invalid column index in GetImage()") );
1559 wxListItemData
*item
= node
->GetData();
1560 return item
->GetImage();
1563 wxListItemAttr
*wxListLineData::GetAttr() const
1565 wxListItemDataList::Node
*node
= m_items
.GetFirst();
1566 wxCHECK_MSG( node
, NULL
, _T("invalid column index in GetAttr()") );
1568 wxListItemData
*item
= node
->GetData();
1569 return item
->GetAttr();
1572 void wxListLineData::SetAttr(wxListItemAttr
*attr
)
1574 wxListItemDataList::Node
*node
= m_items
.GetFirst();
1575 wxCHECK_RET( node
, _T("invalid column index in SetAttr()") );
1577 wxListItemData
*item
= node
->GetData();
1578 item
->SetAttr(attr
);
1581 bool wxListLineData::SetAttributes(wxDC
*dc
,
1582 const wxListItemAttr
*attr
,
1585 wxWindow
*listctrl
= m_owner
->GetParent();
1589 // don't use foreground colour for drawing highlighted items - this might
1590 // make them completely invisible (and there is no way to do bit
1591 // arithmetics on wxColour, unfortunately)
1595 colText
= wxSystemSettings::GetSystemColour(wxSYS_COLOUR_HIGHLIGHTTEXT
);
1599 if ( attr
&& attr
->HasTextColour() )
1601 colText
= attr
->GetTextColour();
1605 colText
= listctrl
->GetForegroundColour();
1609 dc
->SetTextForeground(colText
);
1613 if ( attr
&& attr
->HasFont() )
1615 font
= attr
->GetFont();
1619 font
= listctrl
->GetFont();
1625 bool hasBgCol
= attr
&& attr
->HasBackgroundColour();
1626 if ( highlighted
|| hasBgCol
)
1630 dc
->SetBrush( *m_owner
->GetHighlightBrush() );
1634 dc
->SetBrush(wxBrush(attr
->GetBackgroundColour(), wxSOLID
));
1637 dc
->SetPen( *wxTRANSPARENT_PEN
);
1645 void wxListLineData::Draw( wxDC
*dc
)
1647 wxListItemDataList::Node
*node
= m_items
.GetFirst();
1648 wxCHECK_RET( node
, _T("no subitems at all??") );
1650 bool highlighted
= IsHighlighted();
1652 wxListItemAttr
*attr
= GetAttr();
1654 if ( SetAttributes(dc
, attr
, highlighted
) )
1656 dc
->DrawRectangle( m_gi
->m_rectHighlight
);
1659 wxListItemData
*item
= node
->GetData();
1660 if (item
->HasImage())
1662 wxRect rectIcon
= m_gi
->m_rectIcon
;
1663 m_owner
->DrawImage( item
->GetImage(), dc
,
1664 rectIcon
.x
, rectIcon
.y
);
1667 if (item
->HasText())
1669 wxRect rectLabel
= m_gi
->m_rectLabel
;
1671 wxDCClipper
clipper(*dc
, rectLabel
);
1672 dc
->DrawText( item
->GetText(), rectLabel
.x
, rectLabel
.y
);
1676 void wxListLineData::DrawInReportMode( wxDC
*dc
,
1678 const wxRect
& rectHL
,
1681 // TODO: later we should support setting different attributes for
1682 // different columns - to do it, just add "col" argument to
1683 // GetAttr() and move these lines into the loop below
1684 wxListItemAttr
*attr
= GetAttr();
1685 if ( SetAttributes(dc
, attr
, highlighted
) )
1687 dc
->DrawRectangle( rectHL
);
1690 wxListItemDataList::Node
*node
= m_items
.GetFirst();
1691 wxCHECK_RET( node
, _T("no subitems at all??") );
1694 wxCoord x
= rect
.x
+ HEADER_OFFSET_X
,
1695 y
= rect
.y
+ (LINE_SPACING
+ EXTRA_HEIGHT
) / 2;
1699 wxListItemData
*item
= node
->GetData();
1701 int width
= m_owner
->GetColumnWidth(col
++);
1705 if ( item
->HasImage() )
1708 m_owner
->DrawImage( item
->GetImage(), dc
, xOld
, y
);
1709 m_owner
->GetImageSize( item
->GetImage(), ix
, iy
);
1711 ix
+= IMAGE_MARGIN_IN_REPORT_MODE
;
1717 wxDCClipper
clipper(*dc
, xOld
, y
, width
, rect
.height
);
1719 if ( item
->HasText() )
1721 dc
->DrawText( item
->GetText(), xOld
, y
);
1724 node
= node
->GetNext();
1728 bool wxListLineData::Highlight( bool on
)
1730 wxCHECK_MSG( !m_owner
->IsVirtual(), FALSE
, _T("unexpected call to Highlight") );
1732 if ( on
== m_highlighted
)
1740 void wxListLineData::ReverseHighlight( void )
1742 Highlight(!IsHighlighted());
1745 //-----------------------------------------------------------------------------
1746 // wxListHeaderWindow
1747 //-----------------------------------------------------------------------------
1749 IMPLEMENT_DYNAMIC_CLASS(wxListHeaderWindow
,wxWindow
);
1751 BEGIN_EVENT_TABLE(wxListHeaderWindow
,wxWindow
)
1752 EVT_PAINT (wxListHeaderWindow::OnPaint
)
1753 EVT_MOUSE_EVENTS (wxListHeaderWindow::OnMouse
)
1754 EVT_SET_FOCUS (wxListHeaderWindow::OnSetFocus
)
1757 void wxListHeaderWindow::Init()
1759 m_currentCursor
= (wxCursor
*) NULL
;
1760 m_isDragging
= FALSE
;
1764 wxListHeaderWindow::wxListHeaderWindow()
1768 m_owner
= (wxListMainWindow
*) NULL
;
1769 m_resizeCursor
= (wxCursor
*) NULL
;
1772 wxListHeaderWindow::wxListHeaderWindow( wxWindow
*win
,
1774 wxListMainWindow
*owner
,
1778 const wxString
&name
)
1779 : wxWindow( win
, id
, pos
, size
, style
, name
)
1784 m_resizeCursor
= new wxCursor( wxCURSOR_SIZEWE
);
1786 SetBackgroundColour( wxSystemSettings::GetSystemColour( wxSYS_COLOUR_BTNFACE
) );
1789 wxListHeaderWindow::~wxListHeaderWindow()
1791 delete m_resizeCursor
;
1794 void wxListHeaderWindow::DoDrawRect( wxDC
*dc
, int x
, int y
, int w
, int h
)
1797 GtkStateType state
= m_parent
->IsEnabled() ? GTK_STATE_NORMAL
1798 : GTK_STATE_INSENSITIVE
;
1800 x
= dc
->XLOG2DEV( x
);
1802 gtk_paint_box (m_wxwindow
->style
, GTK_PIZZA(m_wxwindow
)->bin_window
,
1803 state
, GTK_SHADOW_OUT
,
1804 (GdkRectangle
*) NULL
, m_wxwindow
, "button",
1805 x
-1, y
-1, w
+2, h
+2);
1806 #elif defined( __WXMAC__ )
1807 const int m_corner
= 1;
1809 dc
->SetBrush( *wxTRANSPARENT_BRUSH
);
1811 dc
->SetPen( wxPen( wxSystemSettings::GetSystemColour( wxSYS_COLOUR_BTNSHADOW
) , 1 , wxSOLID
) );
1812 dc
->DrawLine( x
+w
-m_corner
+1, y
, x
+w
, y
+h
); // right (outer)
1813 dc
->DrawRectangle( x
, y
+h
, w
+1, 1 ); // bottom (outer)
1815 wxPen
pen( wxColour( 0x88 , 0x88 , 0x88 ), 1, wxSOLID
);
1818 dc
->DrawLine( x
+w
-m_corner
, y
, x
+w
-1, y
+h
); // right (inner)
1819 dc
->DrawRectangle( x
+1, y
+h
-1, w
-2, 1 ); // bottom (inner)
1821 dc
->SetPen( *wxWHITE_PEN
);
1822 dc
->DrawRectangle( x
, y
, w
-m_corner
+1, 1 ); // top (outer)
1823 dc
->DrawRectangle( x
, y
, 1, h
); // left (outer)
1824 dc
->DrawLine( x
, y
+h
-1, x
+1, y
+h
-1 );
1825 dc
->DrawLine( x
+w
-1, y
, x
+w
-1, y
+1 );
1827 const int m_corner
= 1;
1829 dc
->SetBrush( *wxTRANSPARENT_BRUSH
);
1831 dc
->SetPen( *wxBLACK_PEN
);
1832 dc
->DrawLine( x
+w
-m_corner
+1, y
, x
+w
, y
+h
); // right (outer)
1833 dc
->DrawRectangle( x
, y
+h
, w
+1, 1 ); // bottom (outer)
1835 wxPen
pen( wxSystemSettings::GetSystemColour( wxSYS_COLOUR_BTNSHADOW
), 1, wxSOLID
);
1838 dc
->DrawLine( x
+w
-m_corner
, y
, x
+w
-1, y
+h
); // right (inner)
1839 dc
->DrawRectangle( x
+1, y
+h
-1, w
-2, 1 ); // bottom (inner)
1841 dc
->SetPen( *wxWHITE_PEN
);
1842 dc
->DrawRectangle( x
, y
, w
-m_corner
+1, 1 ); // top (outer)
1843 dc
->DrawRectangle( x
, y
, 1, h
); // left (outer)
1844 dc
->DrawLine( x
, y
+h
-1, x
+1, y
+h
-1 );
1845 dc
->DrawLine( x
+w
-1, y
, x
+w
-1, y
+1 );
1849 // shift the DC origin to match the position of the main window horz
1850 // scrollbar: this allows us to always use logical coords
1851 void wxListHeaderWindow::AdjustDC(wxDC
& dc
)
1854 m_owner
->GetScrollPixelsPerUnit( &xpix
, NULL
);
1857 m_owner
->GetViewStart( &x
, NULL
);
1859 // account for the horz scrollbar offset
1860 dc
.SetDeviceOrigin( -x
* xpix
, 0 );
1863 void wxListHeaderWindow::OnPaint( wxPaintEvent
&WXUNUSED(event
) )
1866 wxClientDC
dc( this );
1868 wxPaintDC
dc( this );
1876 dc
.SetFont( GetFont() );
1878 // width and height of the entire header window
1880 GetClientSize( &w
, &h
);
1881 m_owner
->CalcUnscrolledPosition(w
, 0, &w
, NULL
);
1883 dc
.SetBackgroundMode(wxTRANSPARENT
);
1885 // do *not* use the listctrl colour for headers - one day we will have a
1886 // function to set it separately
1887 //dc.SetTextForeground( *wxBLACK );
1888 dc
.SetTextForeground(wxSystemSettings::
1889 GetSystemColour( wxSYS_COLOUR_WINDOWTEXT
));
1891 int x
= HEADER_OFFSET_X
;
1893 int numColumns
= m_owner
->GetColumnCount();
1895 for ( int i
= 0; i
< numColumns
&& x
< w
; i
++ )
1897 m_owner
->GetColumn( i
, item
);
1898 int wCol
= item
.m_width
;
1900 // the width of the rect to draw: make it smaller to fit entirely
1901 // inside the column rect
1904 dc
.SetPen( *wxWHITE_PEN
);
1906 DoDrawRect( &dc
, x
, HEADER_OFFSET_Y
, cw
, h
-2 );
1908 // if we have an image, draw it on the right of the label
1909 int image
= item
.m_image
;
1912 wxImageList
*imageList
= m_owner
->m_small_image_list
;
1916 imageList
->GetSize(image
, ix
, iy
);
1923 HEADER_OFFSET_Y
+ (h
- 4 - iy
)/2,
1924 wxIMAGELIST_DRAW_TRANSPARENT
1929 //else: ignore the column image
1932 // draw the text clipping it so that it doesn't overwrite the column
1934 wxDCClipper
clipper(dc
, x
, HEADER_OFFSET_Y
, cw
, h
- 4 );
1936 dc
.DrawText( item
.GetText(),
1937 x
+ EXTRA_WIDTH
, HEADER_OFFSET_Y
+ EXTRA_HEIGHT
);
1945 void wxListHeaderWindow::DrawCurrent()
1947 int x1
= m_currentX
;
1949 ClientToScreen( &x1
, &y1
);
1951 int x2
= m_currentX
-1;
1953 m_owner
->GetClientSize( NULL
, &y2
);
1954 m_owner
->ClientToScreen( &x2
, &y2
);
1957 dc
.SetLogicalFunction( wxINVERT
);
1958 dc
.SetPen( wxPen( *wxBLACK
, 2, wxSOLID
) );
1959 dc
.SetBrush( *wxTRANSPARENT_BRUSH
);
1963 dc
.DrawLine( x1
, y1
, x2
, y2
);
1965 dc
.SetLogicalFunction( wxCOPY
);
1967 dc
.SetPen( wxNullPen
);
1968 dc
.SetBrush( wxNullBrush
);
1971 void wxListHeaderWindow::OnMouse( wxMouseEvent
&event
)
1973 // we want to work with logical coords
1975 m_owner
->CalcUnscrolledPosition(event
.GetX(), 0, &x
, NULL
);
1976 int y
= event
.GetY();
1980 // we don't draw the line beyond our window, but we allow dragging it
1983 GetClientSize( &w
, NULL
);
1984 m_owner
->CalcUnscrolledPosition(w
, 0, &w
, NULL
);
1987 // erase the line if it was drawn
1988 if ( m_currentX
< w
)
1991 if (event
.ButtonUp())
1994 m_isDragging
= FALSE
;
1996 m_owner
->SetColumnWidth( m_column
, m_currentX
- m_minX
);
2003 m_currentX
= m_minX
+ 7;
2005 // draw in the new location
2006 if ( m_currentX
< w
)
2010 else // not dragging
2013 bool hit_border
= FALSE
;
2015 // end of the current column
2018 // find the column where this event occured
2019 int countCol
= m_owner
->GetColumnCount();
2020 for (int col
= 0; col
< countCol
; col
++)
2022 xpos
+= m_owner
->GetColumnWidth( col
);
2025 if ( (abs(x
-xpos
) < 3) && (y
< 22) )
2027 // near the column border
2034 // inside the column
2041 if (event
.LeftDown() || event
.RightUp())
2043 if (hit_border
&& event
.LeftDown())
2045 m_isDragging
= TRUE
;
2050 else // click on a column
2052 wxWindow
*parent
= GetParent();
2053 wxListEvent
le( event
.LeftDown()
2054 ? wxEVT_COMMAND_LIST_COL_CLICK
2055 : wxEVT_COMMAND_LIST_COL_RIGHT_CLICK
,
2057 le
.SetEventObject( parent
);
2058 le
.m_pointDrag
= event
.GetPosition();
2060 // the position should be relative to the parent window, not
2061 // this one for compatibility with MSW and common sense: the
2062 // user code doesn't know anything at all about this header
2063 // window, so why should it get positions relative to it?
2064 le
.m_pointDrag
.y
-= GetSize().y
;
2066 le
.m_col
= m_column
;
2067 parent
->GetEventHandler()->ProcessEvent( le
);
2070 else if (event
.Moving())
2075 setCursor
= m_currentCursor
== wxSTANDARD_CURSOR
;
2076 m_currentCursor
= m_resizeCursor
;
2080 setCursor
= m_currentCursor
!= wxSTANDARD_CURSOR
;
2081 m_currentCursor
= wxSTANDARD_CURSOR
;
2085 SetCursor(*m_currentCursor
);
2090 void wxListHeaderWindow::OnSetFocus( wxFocusEvent
&WXUNUSED(event
) )
2092 m_owner
->SetFocus();
2095 //-----------------------------------------------------------------------------
2096 // wxListRenameTimer (internal)
2097 //-----------------------------------------------------------------------------
2099 wxListRenameTimer::wxListRenameTimer( wxListMainWindow
*owner
)
2104 void wxListRenameTimer::Notify()
2106 m_owner
->OnRenameTimer();
2109 //-----------------------------------------------------------------------------
2110 // wxListTextCtrl (internal)
2111 //-----------------------------------------------------------------------------
2113 IMPLEMENT_DYNAMIC_CLASS(wxListTextCtrl
,wxTextCtrl
);
2115 BEGIN_EVENT_TABLE(wxListTextCtrl
,wxTextCtrl
)
2116 EVT_CHAR (wxListTextCtrl::OnChar
)
2117 EVT_KEY_UP (wxListTextCtrl::OnKeyUp
)
2118 EVT_KILL_FOCUS (wxListTextCtrl::OnKillFocus
)
2121 wxListTextCtrl::wxListTextCtrl( wxWindow
*parent
,
2122 const wxWindowID id
,
2125 wxListMainWindow
*owner
,
2126 const wxString
&value
,
2130 const wxValidator
& validator
,
2131 const wxString
&name
)
2132 : wxTextCtrl( parent
, id
, value
, pos
, size
, style
, validator
, name
)
2137 (*m_accept
) = FALSE
;
2139 m_startValue
= value
;
2142 void wxListTextCtrl::OnChar( wxKeyEvent
&event
)
2144 if (event
.m_keyCode
== WXK_RETURN
)
2147 (*m_res
) = GetValue();
2149 if (!wxPendingDelete
.Member(this))
2150 wxPendingDelete
.Append(this);
2152 if ((*m_accept
) && ((*m_res
) != m_startValue
))
2153 m_owner
->OnRenameAccept();
2157 if (event
.m_keyCode
== WXK_ESCAPE
)
2159 (*m_accept
) = FALSE
;
2162 if (!wxPendingDelete
.Member(this))
2163 wxPendingDelete
.Append(this);
2171 void wxListTextCtrl::OnKeyUp( wxKeyEvent
&event
)
2173 // auto-grow the textctrl:
2174 wxSize parentSize
= m_owner
->GetSize();
2175 wxPoint myPos
= GetPosition();
2176 wxSize mySize
= GetSize();
2178 GetTextExtent(GetValue() + _T("MM"), &sx
, &sy
); // FIXME: MM??
2179 if (myPos
.x
+ sx
> parentSize
.x
)
2180 sx
= parentSize
.x
- myPos
.x
;
2188 void wxListTextCtrl::OnKillFocus( wxFocusEvent
&WXUNUSED(event
) )
2190 if (!wxPendingDelete
.Member(this))
2191 wxPendingDelete
.Append(this);
2193 if ((*m_accept
) && ((*m_res
) != m_startValue
))
2194 m_owner
->OnRenameAccept();
2197 //-----------------------------------------------------------------------------
2199 //-----------------------------------------------------------------------------
2201 IMPLEMENT_DYNAMIC_CLASS(wxListMainWindow
,wxScrolledWindow
);
2203 BEGIN_EVENT_TABLE(wxListMainWindow
,wxScrolledWindow
)
2204 EVT_PAINT (wxListMainWindow::OnPaint
)
2205 EVT_MOUSE_EVENTS (wxListMainWindow::OnMouse
)
2206 EVT_CHAR (wxListMainWindow::OnChar
)
2207 EVT_KEY_DOWN (wxListMainWindow::OnKeyDown
)
2208 EVT_SET_FOCUS (wxListMainWindow::OnSetFocus
)
2209 EVT_KILL_FOCUS (wxListMainWindow::OnKillFocus
)
2210 EVT_SCROLLWIN (wxListMainWindow::OnScroll
)
2213 void wxListMainWindow::Init()
2215 m_columns
.DeleteContents( TRUE
);
2219 m_lineTo
= (size_t)-1;
2225 m_small_image_list
= (wxImageList
*) NULL
;
2226 m_normal_image_list
= (wxImageList
*) NULL
;
2228 m_small_spacing
= 30;
2229 m_normal_spacing
= 40;
2233 m_isCreated
= FALSE
;
2235 m_lastOnSame
= FALSE
;
2236 m_renameTimer
= new wxListRenameTimer( this );
2237 m_renameAccept
= FALSE
;
2242 m_lineBeforeLastClicked
= (size_t)-1;
2247 void wxListMainWindow::InitScrolling()
2249 if ( HasFlag(wxLC_REPORT
) )
2251 m_xScroll
= SCROLL_UNIT_X
;
2252 m_yScroll
= SCROLL_UNIT_Y
;
2256 m_xScroll
= SCROLL_UNIT_Y
;
2261 wxListMainWindow::wxListMainWindow()
2266 m_highlightUnfocusedBrush
= (wxBrush
*) NULL
;
2272 wxListMainWindow::wxListMainWindow( wxWindow
*parent
,
2277 const wxString
&name
)
2278 : wxScrolledWindow( parent
, id
, pos
, size
,
2279 style
| wxHSCROLL
| wxVSCROLL
, name
)
2283 m_highlightBrush
= new wxBrush
2285 wxSystemSettings::GetSystemColour
2287 wxSYS_COLOUR_HIGHLIGHT
2292 m_highlightUnfocusedBrush
= new wxBrush
2294 wxSystemSettings::GetSystemColour
2296 wxSYS_COLOUR_BTNSHADOW
2305 SetScrollbars( m_xScroll
, m_yScroll
, 0, 0, 0, 0 );
2307 SetBackgroundColour( wxSystemSettings::GetSystemColour( wxSYS_COLOUR_LISTBOX
) );
2310 wxListMainWindow::~wxListMainWindow()
2314 delete m_highlightBrush
;
2315 delete m_highlightUnfocusedBrush
;
2317 delete m_renameTimer
;
2320 void wxListMainWindow::CacheLineData(size_t line
)
2322 wxListCtrl
*listctrl
= GetListCtrl();
2324 wxListLineData
*ld
= GetDummyLine();
2326 size_t countCol
= GetColumnCount();
2327 for ( size_t col
= 0; col
< countCol
; col
++ )
2329 ld
->SetText(col
, listctrl
->OnGetItemText(line
, col
));
2332 ld
->SetImage(listctrl
->OnGetItemImage(line
));
2333 ld
->SetAttr(listctrl
->OnGetItemAttr(line
));
2336 wxListLineData
*wxListMainWindow::GetDummyLine() const
2338 wxASSERT_MSG( !IsEmpty(), _T("invalid line index") );
2340 if ( m_lines
.IsEmpty() )
2342 // normal controls are supposed to have something in m_lines
2343 // already if it's not empty
2344 wxASSERT_MSG( IsVirtual(), _T("logic error") );
2346 wxListMainWindow
*self
= wxConstCast(this, wxListMainWindow
);
2347 wxListLineData
*line
= new wxListLineData(self
);
2348 self
->m_lines
.Add(line
);
2354 // ----------------------------------------------------------------------------
2355 // line geometry (report mode only)
2356 // ----------------------------------------------------------------------------
2358 wxCoord
wxListMainWindow::GetLineHeight() const
2360 wxASSERT_MSG( HasFlag(wxLC_REPORT
), _T("only works in report mode") );
2362 // we cache the line height as calling GetTextExtent() is slow
2363 if ( !m_lineHeight
)
2365 wxListMainWindow
*self
= wxConstCast(this, wxListMainWindow
);
2367 wxClientDC
dc( self
);
2368 dc
.SetFont( GetFont() );
2371 dc
.GetTextExtent(_T("H"), NULL
, &y
);
2373 if ( y
< SCROLL_UNIT_Y
)
2377 self
->m_lineHeight
= y
+ LINE_SPACING
;
2380 return m_lineHeight
;
2383 wxCoord
wxListMainWindow::GetLineY(size_t line
) const
2385 wxASSERT_MSG( HasFlag(wxLC_REPORT
), _T("only works in report mode") );
2387 return LINE_SPACING
+ line
*GetLineHeight();
2390 wxRect
wxListMainWindow::GetLineRect(size_t line
) const
2392 if ( !InReportView() )
2393 return GetLine(line
)->m_gi
->m_rectAll
;
2396 rect
.x
= HEADER_OFFSET_X
;
2397 rect
.y
= GetLineY(line
);
2398 rect
.width
= GetHeaderWidth();
2399 rect
.height
= GetLineHeight();
2404 wxRect
wxListMainWindow::GetLineLabelRect(size_t line
) const
2406 if ( !InReportView() )
2407 return GetLine(line
)->m_gi
->m_rectLabel
;
2410 rect
.x
= HEADER_OFFSET_X
;
2411 rect
.y
= GetLineY(line
);
2412 rect
.width
= GetColumnWidth(0);
2413 rect
.height
= GetLineHeight();
2418 wxRect
wxListMainWindow::GetLineIconRect(size_t line
) const
2420 if ( !InReportView() )
2421 return GetLine(line
)->m_gi
->m_rectIcon
;
2423 wxListLineData
*ld
= GetLine(line
);
2424 wxASSERT_MSG( ld
->HasImage(), _T("should have an image") );
2427 rect
.x
= HEADER_OFFSET_X
;
2428 rect
.y
= GetLineY(line
);
2429 GetImageSize(ld
->GetImage(), rect
.width
, rect
.height
);
2434 wxRect
wxListMainWindow::GetLineHighlightRect(size_t line
) const
2436 return InReportView() ? GetLineRect(line
)
2437 : GetLine(line
)->m_gi
->m_rectHighlight
;
2440 long wxListMainWindow::HitTestLine(size_t line
, int x
, int y
) const
2442 wxASSERT_MSG( line
< GetItemCount(), _T("invalid line in HitTestLine") );
2444 wxListLineData
*ld
= GetLine(line
);
2446 if ( ld
->HasImage() && GetLineIconRect(line
).Inside(x
, y
) )
2447 return wxLIST_HITTEST_ONITEMICON
;
2449 if ( ld
->HasText() )
2451 wxRect rect
= InReportView() ? GetLineRect(line
)
2452 : GetLineLabelRect(line
);
2454 if ( rect
.Inside(x
, y
) )
2455 return wxLIST_HITTEST_ONITEMLABEL
;
2461 // ----------------------------------------------------------------------------
2462 // highlight (selection) handling
2463 // ----------------------------------------------------------------------------
2465 bool wxListMainWindow::IsHighlighted(size_t line
) const
2469 return m_selStore
.IsSelected(line
);
2473 wxListLineData
*ld
= GetLine(line
);
2474 wxCHECK_MSG( ld
, FALSE
, _T("invalid index in IsHighlighted") );
2476 return ld
->IsHighlighted();
2480 void wxListMainWindow::HighlightLines( size_t lineFrom
,
2486 wxArrayInt linesChanged
;
2487 if ( !m_selStore
.SelectRange(lineFrom
, lineTo
, highlight
,
2490 // meny items changed state, refresh everything
2491 RefreshLines(lineFrom
, lineTo
);
2493 else // only a few items changed state, refresh only them
2495 size_t count
= linesChanged
.GetCount();
2496 for ( size_t n
= 0; n
< count
; n
++ )
2498 RefreshLine(linesChanged
[n
]);
2502 else // iterate over all items in non report view
2504 for ( size_t line
= lineFrom
; line
<= lineTo
; line
++ )
2506 if ( HighlightLine(line
, highlight
) )
2514 bool wxListMainWindow::HighlightLine( size_t line
, bool highlight
)
2520 changed
= m_selStore
.SelectItem(line
, highlight
);
2524 wxListLineData
*ld
= GetLine(line
);
2525 wxCHECK_MSG( ld
, FALSE
, _T("invalid index in HighlightLine") );
2527 changed
= ld
->Highlight(highlight
);
2532 SendNotify( line
, highlight
? wxEVT_COMMAND_LIST_ITEM_SELECTED
2533 : wxEVT_COMMAND_LIST_ITEM_DESELECTED
);
2539 void wxListMainWindow::RefreshLine( size_t line
)
2541 if ( HasFlag(wxLC_REPORT
) )
2543 size_t visibleFrom
, visibleTo
;
2544 GetVisibleLinesRange(&visibleFrom
, &visibleTo
);
2546 if ( line
< visibleFrom
|| line
> visibleTo
)
2550 wxRect rect
= GetLineRect(line
);
2552 CalcScrolledPosition( rect
.x
, rect
.y
, &rect
.x
, &rect
.y
);
2553 RefreshRect( rect
);
2556 void wxListMainWindow::RefreshLines( size_t lineFrom
, size_t lineTo
)
2558 // we suppose that they are ordered by caller
2559 wxASSERT_MSG( lineFrom
<= lineTo
, _T("indices in disorder") );
2561 wxASSERT_MSG( lineTo
< GetItemCount(), _T("invalid line range") );
2563 if ( HasFlag(wxLC_REPORT
) )
2565 size_t visibleFrom
, visibleTo
;
2566 GetVisibleLinesRange(&visibleFrom
, &visibleTo
);
2568 if ( lineFrom
< visibleFrom
)
2569 lineFrom
= visibleFrom
;
2570 if ( lineTo
> visibleTo
)
2575 rect
.y
= GetLineY(lineFrom
);
2576 rect
.width
= GetClientSize().x
;
2577 rect
.height
= GetLineY(lineTo
) - rect
.y
+ GetLineHeight();
2579 CalcScrolledPosition( rect
.x
, rect
.y
, &rect
.x
, &rect
.y
);
2580 RefreshRect( rect
);
2584 // TODO: this should be optimized...
2585 for ( size_t line
= lineFrom
; line
<= lineTo
; line
++ )
2592 void wxListMainWindow::RefreshAfter( size_t lineFrom
)
2594 if ( HasFlag(wxLC_REPORT
) )
2597 GetVisibleLinesRange(&visibleFrom
, NULL
);
2599 if ( lineFrom
< visibleFrom
)
2600 lineFrom
= visibleFrom
;
2604 rect
.y
= GetLineY(lineFrom
);
2606 wxSize size
= GetClientSize();
2607 rect
.width
= size
.x
;
2608 // refresh till the bottom of the window
2609 rect
.height
= size
.y
- rect
.y
;
2611 CalcScrolledPosition( rect
.x
, rect
.y
, &rect
.x
, &rect
.y
);
2612 RefreshRect( rect
);
2616 // TODO: how to do it more efficiently?
2621 void wxListMainWindow::RefreshSelected()
2627 if ( InReportView() )
2629 GetVisibleLinesRange(&from
, &to
);
2634 to
= GetItemCount() - 1;
2637 // VZ: this code would work fine if wxGTK wxWindow::Refresh() were
2638 // reasonable, i.e. if it only generated one expose event for
2639 // several calls to it - as it is, each Refresh() results in a
2640 // repaint which provokes flicker too horrible to be seen
2642 // when/if wxGTK is fixed, this code should be restored as normally it
2643 // should generate _less_ flicker than the version below
2645 if ( HasCurrent() && m_current
>= from
&& m_current
<= to
)
2647 RefreshLine(m_current
);
2650 for ( size_t line
= from
; line
<= to
; line
++ )
2652 // NB: the test works as expected even if m_current == -1
2653 if ( line
!= m_current
&& IsHighlighted(line
) )
2659 size_t selMin
= (size_t)-1,
2662 for ( size_t line
= from
; line
<= to
; line
++ )
2664 if ( IsHighlighted(line
) || (line
== m_current
) )
2666 if ( line
< selMin
)
2668 if ( line
> selMax
)
2673 if ( selMin
!= (size_t)-1 )
2675 RefreshLines(selMin
, selMax
);
2677 #endif // !__WXGTK__/__WXGTK__
2680 void wxListMainWindow::Freeze()
2685 void wxListMainWindow::Thaw()
2687 wxCHECK_RET( m_freezeCount
> 0, _T("thawing unfrozen list control?") );
2689 if ( !--m_freezeCount
)
2695 void wxListMainWindow::OnPaint( wxPaintEvent
&WXUNUSED(event
) )
2697 // Note: a wxPaintDC must be constructed even if no drawing is
2698 // done (a Windows requirement).
2699 wxPaintDC
dc( this );
2701 if ( IsEmpty() || m_freezeCount
)
2703 // nothing to draw or not the moment to draw it
2709 // delay the repainting until we calculate all the items positions
2716 CalcScrolledPosition( 0, 0, &dev_x
, &dev_y
);
2720 dc
.SetFont( GetFont() );
2722 if ( HasFlag(wxLC_REPORT
) )
2724 int lineHeight
= GetLineHeight();
2726 size_t visibleFrom
, visibleTo
;
2727 GetVisibleLinesRange(&visibleFrom
, &visibleTo
);
2730 wxCoord xOrig
, yOrig
;
2731 CalcUnscrolledPosition(0, 0, &xOrig
, &yOrig
);
2733 // tell the caller cache to cache the data
2736 wxListEvent
evCache(wxEVT_COMMAND_LIST_CACHE_HINT
,
2737 GetParent()->GetId());
2738 evCache
.SetEventObject( GetParent() );
2739 evCache
.m_oldItemIndex
= visibleFrom
;
2740 evCache
.m_itemIndex
= visibleTo
;
2741 GetParent()->GetEventHandler()->ProcessEvent( evCache
);
2744 for ( size_t line
= visibleFrom
; line
<= visibleTo
; line
++ )
2746 rectLine
= GetLineRect(line
);
2748 if ( !IsExposed(rectLine
.x
- xOrig
, rectLine
.y
- yOrig
,
2749 rectLine
.width
, rectLine
.height
) )
2751 // don't redraw unaffected lines to avoid flicker
2755 GetLine(line
)->DrawInReportMode( &dc
,
2757 GetLineHighlightRect(line
),
2758 IsHighlighted(line
) );
2761 if ( HasFlag(wxLC_HRULES
) )
2763 wxPen
pen(GetRuleColour(), 1, wxSOLID
);
2764 wxSize clientSize
= GetClientSize();
2766 for ( size_t i
= visibleFrom
; i
<= visibleTo
; i
++ )
2769 dc
.SetBrush( *wxTRANSPARENT_BRUSH
);
2770 dc
.DrawLine(0 - dev_x
, i
*lineHeight
,
2771 clientSize
.x
- dev_x
, i
*lineHeight
);
2774 // Draw last horizontal rule
2775 if ( visibleTo
> visibleFrom
)
2778 dc
.SetBrush( *wxTRANSPARENT_BRUSH
);
2779 dc
.DrawLine(0 - dev_x
, m_lineTo
*lineHeight
,
2780 clientSize
.x
- dev_x
, m_lineTo
*lineHeight
);
2784 // Draw vertical rules if required
2785 if ( HasFlag(wxLC_VRULES
) && !IsEmpty() )
2787 wxPen
pen(GetRuleColour(), 1, wxSOLID
);
2790 wxRect firstItemRect
;
2791 wxRect lastItemRect
;
2792 GetItemRect(0, firstItemRect
);
2793 GetItemRect(GetItemCount() - 1, lastItemRect
);
2794 int x
= firstItemRect
.GetX();
2796 dc
.SetBrush(* wxTRANSPARENT_BRUSH
);
2797 for (col
= 0; col
< GetColumnCount(); col
++)
2799 int colWidth
= GetColumnWidth(col
);
2801 dc
.DrawLine(x
- dev_x
, firstItemRect
.GetY() - 1 - dev_y
,
2802 x
- dev_x
, lastItemRect
.GetBottom() + 1 - dev_y
);
2808 size_t count
= GetItemCount();
2809 for ( size_t i
= 0; i
< count
; i
++ )
2811 GetLine(i
)->Draw( &dc
);
2817 // don't draw rect outline under Max if we already have the background
2818 // color but under other platforms only draw it if we do: it is a bit
2819 // silly to draw "focus rect" if we don't have focus!
2824 #endif // __WXMAC__/!__WXMAC__
2826 dc
.SetPen( *wxBLACK_PEN
);
2827 dc
.SetBrush( *wxTRANSPARENT_BRUSH
);
2828 dc
.DrawRectangle( GetLineHighlightRect(m_current
) );
2835 void wxListMainWindow::HighlightAll( bool on
)
2837 if ( IsSingleSel() )
2839 wxASSERT_MSG( !on
, _T("can't do this in a single sel control") );
2841 // we just have one item to turn off
2842 if ( HasCurrent() && IsHighlighted(m_current
) )
2844 HighlightLine(m_current
, FALSE
);
2845 RefreshLine(m_current
);
2850 HighlightLines(0, GetItemCount() - 1, on
);
2854 void wxListMainWindow::SendNotify( size_t line
,
2855 wxEventType command
,
2858 wxListEvent
le( command
, GetParent()->GetId() );
2859 le
.SetEventObject( GetParent() );
2860 le
.m_itemIndex
= line
;
2862 // set only for events which have position
2863 if ( point
!= wxDefaultPosition
)
2864 le
.m_pointDrag
= point
;
2866 // don't try to get the line info for virtual list controls: the main
2867 // program has it anyhow and if we did it would result in accessing all
2868 // the lines, even those which are not visible now and this is precisely
2869 // what we're trying to avoid
2870 if ( !IsVirtual() && (command
!= wxEVT_COMMAND_LIST_DELETE_ITEM
) )
2872 if ( line
!= (size_t)-1 )
2874 GetLine(line
)->GetItem( 0, le
.m_item
);
2876 //else: this happens for wxEVT_COMMAND_LIST_ITEM_FOCUSED event
2878 //else: there may be no more such item
2880 GetParent()->GetEventHandler()->ProcessEvent( le
);
2883 void wxListMainWindow::ChangeCurrent(size_t current
)
2885 m_current
= current
;
2887 SendNotify(current
, wxEVT_COMMAND_LIST_ITEM_FOCUSED
);
2890 void wxListMainWindow::EditLabel( long item
)
2892 wxCHECK_RET( (item
>= 0) && ((size_t)item
< GetItemCount()),
2893 wxT("wrong index in wxListCtrl::EditLabel()") );
2895 m_currentEdit
= (size_t)item
;
2897 wxListEvent
le( wxEVT_COMMAND_LIST_BEGIN_LABEL_EDIT
, GetParent()->GetId() );
2898 le
.SetEventObject( GetParent() );
2899 le
.m_itemIndex
= item
;
2900 wxListLineData
*data
= GetLine(m_currentEdit
);
2901 wxCHECK_RET( data
, _T("invalid index in EditLabel()") );
2902 data
->GetItem( 0, le
.m_item
);
2903 GetParent()->GetEventHandler()->ProcessEvent( le
);
2905 if (!le
.IsAllowed())
2908 // We have to call this here because the label in question might just have
2909 // been added and no screen update taken place.
2913 wxClientDC
dc(this);
2916 wxString s
= data
->GetText(0);
2917 wxRect rectLabel
= GetLineLabelRect(m_currentEdit
);
2919 rectLabel
.x
= dc
.LogicalToDeviceX( rectLabel
.x
);
2920 rectLabel
.y
= dc
.LogicalToDeviceY( rectLabel
.y
);
2922 wxListTextCtrl
*text
= new wxListTextCtrl
2929 wxPoint(rectLabel
.x
-4,rectLabel
.y
-4),
2930 wxSize(rectLabel
.width
+11,rectLabel
.height
+8)
2935 void wxListMainWindow::OnRenameTimer()
2937 wxCHECK_RET( HasCurrent(), wxT("unexpected rename timer") );
2939 EditLabel( m_current
);
2942 void wxListMainWindow::OnRenameAccept()
2944 wxListEvent
le( wxEVT_COMMAND_LIST_END_LABEL_EDIT
, GetParent()->GetId() );
2945 le
.SetEventObject( GetParent() );
2946 le
.m_itemIndex
= m_currentEdit
;
2948 wxListLineData
*data
= GetLine(m_currentEdit
);
2949 wxCHECK_RET( data
, _T("invalid index in OnRenameAccept()") );
2951 data
->GetItem( 0, le
.m_item
);
2952 le
.m_item
.m_text
= m_renameRes
;
2953 GetParent()->GetEventHandler()->ProcessEvent( le
);
2955 if (!le
.IsAllowed()) return;
2958 info
.m_mask
= wxLIST_MASK_TEXT
;
2959 info
.m_itemId
= le
.m_itemIndex
;
2960 info
.m_text
= m_renameRes
;
2961 info
.SetTextColour(le
.m_item
.GetTextColour());
2965 void wxListMainWindow::OnMouse( wxMouseEvent
&event
)
2967 event
.SetEventObject( GetParent() );
2968 if ( GetParent()->GetEventHandler()->ProcessEvent( event
) )
2971 if ( !HasCurrent() || IsEmpty() )
2977 if ( !(event
.Dragging() || event
.ButtonDown() || event
.LeftUp() ||
2978 event
.ButtonDClick()) )
2981 int x
= event
.GetX();
2982 int y
= event
.GetY();
2983 CalcUnscrolledPosition( x
, y
, &x
, &y
);
2985 // where did we hit it (if we did)?
2988 size_t count
= GetItemCount(),
2991 if ( HasFlag(wxLC_REPORT
) )
2993 current
= y
/ GetLineHeight();
2994 if ( current
< count
)
2995 hitResult
= HitTestLine(current
, x
, y
);
2999 // TODO: optimize it too! this is less simple than for report view but
3000 // enumerating all items is still not a way to do it!!
3001 for ( current
= 0; current
< count
; current
++ )
3003 hitResult
= HitTestLine(current
, x
, y
);
3009 if (event
.Dragging())
3011 if (m_dragCount
== 0)
3013 // we have to report the raw, physical coords as we want to be
3014 // able to call HitTest(event.m_pointDrag) from the user code to
3015 // get the item being dragged
3016 m_dragStart
= event
.GetPosition();
3021 if (m_dragCount
!= 3)
3024 int command
= event
.RightIsDown() ? wxEVT_COMMAND_LIST_BEGIN_RDRAG
3025 : wxEVT_COMMAND_LIST_BEGIN_DRAG
;
3027 wxListEvent
le( command
, GetParent()->GetId() );
3028 le
.SetEventObject( GetParent() );
3029 le
.m_pointDrag
= m_dragStart
;
3030 GetParent()->GetEventHandler()->ProcessEvent( le
);
3041 // outside of any item
3045 bool forceClick
= FALSE
;
3046 if (event
.ButtonDClick())
3048 m_renameTimer
->Stop();
3049 m_lastOnSame
= FALSE
;
3051 if ( current
== m_lineBeforeLastClicked
)
3053 SendNotify( current
, wxEVT_COMMAND_LIST_ITEM_ACTIVATED
);
3059 // the first click was on another item, so don't interpret this as
3060 // a double click, but as a simple click instead
3065 if (event
.LeftUp() && m_lastOnSame
)
3067 if ((current
== m_current
) &&
3068 (hitResult
== wxLIST_HITTEST_ONITEMLABEL
) &&
3069 HasFlag(wxLC_EDIT_LABELS
) )
3071 m_renameTimer
->Start( 100, TRUE
);
3073 m_lastOnSame
= FALSE
;
3075 else if (event
.RightDown())
3077 SendNotify( current
, wxEVT_COMMAND_LIST_ITEM_RIGHT_CLICK
,
3078 event
.GetPosition() );
3080 else if (event
.MiddleDown())
3082 SendNotify( current
, wxEVT_COMMAND_LIST_ITEM_MIDDLE_CLICK
);
3084 else if ( event
.LeftDown() || forceClick
)
3086 m_lineBeforeLastClicked
= m_lineLastClicked
;
3087 m_lineLastClicked
= current
;
3089 size_t oldCurrent
= m_current
;
3091 if ( IsSingleSel() || !(event
.ControlDown() || event
.ShiftDown()) )
3093 HighlightAll( FALSE
);
3095 ChangeCurrent(current
);
3097 ReverseHighlight(m_current
);
3099 else // multi sel & either ctrl or shift is down
3101 if (event
.ControlDown())
3103 ChangeCurrent(current
);
3105 ReverseHighlight(m_current
);
3107 else if (event
.ShiftDown())
3109 ChangeCurrent(current
);
3111 size_t lineFrom
= oldCurrent
,
3114 if ( lineTo
< lineFrom
)
3117 lineFrom
= m_current
;
3120 HighlightLines(lineFrom
, lineTo
);
3122 else // !ctrl, !shift
3124 // test in the enclosing if should make it impossible
3125 wxFAIL_MSG( _T("how did we get here?") );
3129 if (m_current
!= oldCurrent
)
3131 RefreshLine( oldCurrent
);
3134 // forceClick is only set if the previous click was on another item
3135 m_lastOnSame
= !forceClick
&& (m_current
== oldCurrent
);
3139 void wxListMainWindow::MoveToItem(size_t item
)
3141 if ( item
== (size_t)-1 )
3144 wxRect rect
= GetLineRect(item
);
3146 int client_w
, client_h
;
3147 GetClientSize( &client_w
, &client_h
);
3149 int view_x
= m_xScroll
*GetScrollPos( wxHORIZONTAL
);
3150 int view_y
= m_yScroll
*GetScrollPos( wxVERTICAL
);
3152 if ( HasFlag(wxLC_REPORT
) )
3154 // the next we need the range of lines shown it might be different, so
3156 ResetVisibleLinesRange();
3158 if (rect
.y
< view_y
)
3159 Scroll( -1, rect
.y
/m_yScroll
);
3160 if (rect
.y
+rect
.height
+5 > view_y
+client_h
)
3161 Scroll( -1, (rect
.y
+rect
.height
-client_h
+SCROLL_UNIT_Y
)/m_yScroll
);
3165 if (rect
.x
-view_x
< 5)
3166 Scroll( (rect
.x
-5)/m_xScroll
, -1 );
3167 if (rect
.x
+rect
.width
-5 > view_x
+client_w
)
3168 Scroll( (rect
.x
+rect
.width
-client_w
+SCROLL_UNIT_X
)/m_xScroll
, -1 );
3172 // ----------------------------------------------------------------------------
3173 // keyboard handling
3174 // ----------------------------------------------------------------------------
3176 void wxListMainWindow::OnArrowChar(size_t newCurrent
, const wxKeyEvent
& event
)
3178 wxCHECK_RET( newCurrent
< (size_t)GetItemCount(),
3179 _T("invalid item index in OnArrowChar()") );
3181 size_t oldCurrent
= m_current
;
3183 // in single selection we just ignore Shift as we can't select several
3185 if ( event
.ShiftDown() && !IsSingleSel() )
3187 ChangeCurrent(newCurrent
);
3189 // select all the items between the old and the new one
3190 if ( oldCurrent
> newCurrent
)
3192 newCurrent
= oldCurrent
;
3193 oldCurrent
= m_current
;
3196 HighlightLines(oldCurrent
, newCurrent
);
3200 // all previously selected items are unselected unless ctrl is held
3201 if ( !event
.ControlDown() )
3202 HighlightAll(FALSE
);
3204 ChangeCurrent(newCurrent
);
3206 HighlightLine( oldCurrent
, FALSE
);
3207 RefreshLine( oldCurrent
);
3209 if ( !event
.ControlDown() )
3211 HighlightLine( m_current
, TRUE
);
3215 RefreshLine( m_current
);
3220 void wxListMainWindow::OnKeyDown( wxKeyEvent
&event
)
3222 wxWindow
*parent
= GetParent();
3224 /* we propagate the key event up */
3225 wxKeyEvent
ke( wxEVT_KEY_DOWN
);
3226 ke
.m_shiftDown
= event
.m_shiftDown
;
3227 ke
.m_controlDown
= event
.m_controlDown
;
3228 ke
.m_altDown
= event
.m_altDown
;
3229 ke
.m_metaDown
= event
.m_metaDown
;
3230 ke
.m_keyCode
= event
.m_keyCode
;
3233 ke
.SetEventObject( parent
);
3234 if (parent
->GetEventHandler()->ProcessEvent( ke
)) return;
3239 void wxListMainWindow::OnChar( wxKeyEvent
&event
)
3241 wxWindow
*parent
= GetParent();
3243 /* we send a list_key event up */
3246 wxListEvent
le( wxEVT_COMMAND_LIST_KEY_DOWN
, GetParent()->GetId() );
3247 le
.m_itemIndex
= m_current
;
3248 GetLine(m_current
)->GetItem( 0, le
.m_item
);
3249 le
.m_code
= (int)event
.KeyCode();
3250 le
.SetEventObject( parent
);
3251 parent
->GetEventHandler()->ProcessEvent( le
);
3254 /* we propagate the char event up */
3255 wxKeyEvent
ke( wxEVT_CHAR
);
3256 ke
.m_shiftDown
= event
.m_shiftDown
;
3257 ke
.m_controlDown
= event
.m_controlDown
;
3258 ke
.m_altDown
= event
.m_altDown
;
3259 ke
.m_metaDown
= event
.m_metaDown
;
3260 ke
.m_keyCode
= event
.m_keyCode
;
3263 ke
.SetEventObject( parent
);
3264 if (parent
->GetEventHandler()->ProcessEvent( ke
)) return;
3266 if (event
.KeyCode() == WXK_TAB
)
3268 wxNavigationKeyEvent nevent
;
3269 nevent
.SetWindowChange( event
.ControlDown() );
3270 nevent
.SetDirection( !event
.ShiftDown() );
3271 nevent
.SetEventObject( GetParent()->GetParent() );
3272 nevent
.SetCurrentFocus( m_parent
);
3273 if (GetParent()->GetParent()->GetEventHandler()->ProcessEvent( nevent
))
3277 /* no item -> nothing to do */
3284 switch (event
.KeyCode())
3287 if ( m_current
> 0 )
3288 OnArrowChar( m_current
- 1, event
);
3292 if ( m_current
< (size_t)GetItemCount() - 1 )
3293 OnArrowChar( m_current
+ 1, event
);
3298 OnArrowChar( GetItemCount() - 1, event
);
3303 OnArrowChar( 0, event
);
3309 if ( HasFlag(wxLC_REPORT
) )
3311 steps
= m_linesPerPage
- 1;
3315 steps
= m_current
% m_linesPerPage
;
3318 int index
= m_current
- steps
;
3322 OnArrowChar( index
, event
);
3329 if ( HasFlag(wxLC_REPORT
) )
3331 steps
= m_linesPerPage
- 1;
3335 steps
= m_linesPerPage
- (m_current
% m_linesPerPage
) - 1;
3338 size_t index
= m_current
+ steps
;
3339 size_t count
= GetItemCount();
3340 if ( index
>= count
)
3343 OnArrowChar( index
, event
);
3348 if ( !HasFlag(wxLC_REPORT
) )
3350 int index
= m_current
- m_linesPerPage
;
3354 OnArrowChar( index
, event
);
3359 if ( !HasFlag(wxLC_REPORT
) )
3361 size_t index
= m_current
+ m_linesPerPage
;
3363 size_t count
= GetItemCount();
3364 if ( index
>= count
)
3367 OnArrowChar( index
, event
);
3372 if ( IsSingleSel() )
3374 SendNotify( m_current
, wxEVT_COMMAND_LIST_ITEM_ACTIVATED
);
3376 if ( IsHighlighted(m_current
) )
3378 // don't unselect the item in single selection mode
3381 //else: select it in ReverseHighlight() below if unselected
3384 ReverseHighlight(m_current
);
3389 SendNotify( m_current
, wxEVT_COMMAND_LIST_ITEM_ACTIVATED
);
3397 // ----------------------------------------------------------------------------
3399 // ----------------------------------------------------------------------------
3402 extern wxWindow
*g_focusWindow
;
3405 void wxListMainWindow::OnSetFocus( wxFocusEvent
&WXUNUSED(event
) )
3407 // wxGTK sends us EVT_SET_FOCUS events even if we had never got
3408 // EVT_KILL_FOCUS before which means that we finish by redrawing the items
3409 // which are already drawn correctly resulting in horrible flicker - avoid
3422 g_focusWindow
= GetParent();
3425 wxFocusEvent
event( wxEVT_SET_FOCUS
, GetParent()->GetId() );
3426 event
.SetEventObject( GetParent() );
3427 GetParent()->GetEventHandler()->ProcessEvent( event
);
3430 void wxListMainWindow::OnKillFocus( wxFocusEvent
&WXUNUSED(event
) )
3437 void wxListMainWindow::DrawImage( int index
, wxDC
*dc
, int x
, int y
)
3439 if ( HasFlag(wxLC_ICON
) && (m_normal_image_list
))
3441 m_normal_image_list
->Draw( index
, *dc
, x
, y
, wxIMAGELIST_DRAW_TRANSPARENT
);
3443 else if ( HasFlag(wxLC_SMALL_ICON
) && (m_small_image_list
))
3445 m_small_image_list
->Draw( index
, *dc
, x
, y
, wxIMAGELIST_DRAW_TRANSPARENT
);
3447 else if ( HasFlag(wxLC_LIST
) && (m_small_image_list
))
3449 m_small_image_list
->Draw( index
, *dc
, x
, y
, wxIMAGELIST_DRAW_TRANSPARENT
);
3451 else if ( HasFlag(wxLC_REPORT
) && (m_small_image_list
))
3453 m_small_image_list
->Draw( index
, *dc
, x
, y
, wxIMAGELIST_DRAW_TRANSPARENT
);
3457 void wxListMainWindow::GetImageSize( int index
, int &width
, int &height
) const
3459 if ( HasFlag(wxLC_ICON
) && m_normal_image_list
)
3461 m_normal_image_list
->GetSize( index
, width
, height
);
3463 else if ( HasFlag(wxLC_SMALL_ICON
) && m_small_image_list
)
3465 m_small_image_list
->GetSize( index
, width
, height
);
3467 else if ( HasFlag(wxLC_LIST
) && m_small_image_list
)
3469 m_small_image_list
->GetSize( index
, width
, height
);
3471 else if ( HasFlag(wxLC_REPORT
) && m_small_image_list
)
3473 m_small_image_list
->GetSize( index
, width
, height
);
3482 int wxListMainWindow::GetTextLength( const wxString
&s
) const
3484 wxClientDC
dc( wxConstCast(this, wxListMainWindow
) );
3485 dc
.SetFont( GetFont() );
3488 dc
.GetTextExtent( s
, &lw
, NULL
);
3490 return lw
+ AUTOSIZE_COL_MARGIN
;
3493 void wxListMainWindow::SetImageList( wxImageList
*imageList
, int which
)
3497 // calc the spacing from the icon size
3500 if ((imageList
) && (imageList
->GetImageCount()) )
3502 imageList
->GetSize(0, width
, height
);
3505 if (which
== wxIMAGE_LIST_NORMAL
)
3507 m_normal_image_list
= imageList
;
3508 m_normal_spacing
= width
+ 8;
3511 if (which
== wxIMAGE_LIST_SMALL
)
3513 m_small_image_list
= imageList
;
3514 m_small_spacing
= width
+ 14;
3518 void wxListMainWindow::SetItemSpacing( int spacing
, bool isSmall
)
3523 m_small_spacing
= spacing
;
3527 m_normal_spacing
= spacing
;
3531 int wxListMainWindow::GetItemSpacing( bool isSmall
)
3533 return isSmall
? m_small_spacing
: m_normal_spacing
;
3536 // ----------------------------------------------------------------------------
3538 // ----------------------------------------------------------------------------
3540 void wxListMainWindow::SetColumn( int col
, wxListItem
&item
)
3542 wxListHeaderDataList::Node
*node
= m_columns
.Item( col
);
3544 wxCHECK_RET( node
, _T("invalid column index in SetColumn") );
3546 if ( item
.m_width
== wxLIST_AUTOSIZE_USEHEADER
)
3547 item
.m_width
= GetTextLength( item
.m_text
);
3549 wxListHeaderData
*column
= node
->GetData();
3550 column
->SetItem( item
);
3552 wxListHeaderWindow
*headerWin
= GetListCtrl()->m_headerWin
;
3554 headerWin
->m_dirty
= TRUE
;
3558 // invalidate it as it has to be recalculated
3562 void wxListMainWindow::SetColumnWidth( int col
, int width
)
3564 wxCHECK_RET( col
>= 0 && col
< GetColumnCount(),
3565 _T("invalid column index") );
3567 wxCHECK_RET( HasFlag(wxLC_REPORT
),
3568 _T("SetColumnWidth() can only be called in report mode.") );
3571 wxListHeaderWindow
*headerWin
= GetListCtrl()->m_headerWin
;
3573 headerWin
->m_dirty
= TRUE
;
3575 wxListHeaderDataList::Node
*node
= m_columns
.Item( col
);
3576 wxCHECK_RET( node
, _T("no column?") );
3578 wxListHeaderData
*column
= node
->GetData();
3580 size_t count
= GetItemCount();
3582 if (width
== wxLIST_AUTOSIZE_USEHEADER
)
3584 width
= GetTextLength(column
->GetText());
3586 else if ( width
== wxLIST_AUTOSIZE
)
3590 // TODO: determine the max width somehow...
3591 width
= WIDTH_COL_DEFAULT
;
3595 wxClientDC
dc(this);
3596 dc
.SetFont( GetFont() );
3598 int max
= AUTOSIZE_COL_MARGIN
;
3600 for ( size_t i
= 0; i
< count
; i
++ )
3602 wxListLineData
*line
= GetLine(i
);
3603 wxListItemDataList::Node
*n
= line
->m_items
.Item( col
);
3605 wxCHECK_RET( n
, _T("no subitem?") );
3607 wxListItemData
*item
= n
->GetData();
3610 if (item
->HasImage())
3613 GetImageSize( item
->GetImage(), ix
, iy
);
3617 if (item
->HasText())
3620 dc
.GetTextExtent( item
->GetText(), &w
, NULL
);
3628 width
= max
+ AUTOSIZE_COL_MARGIN
;
3632 column
->SetWidth( width
);
3634 // invalidate it as it has to be recalculated
3638 int wxListMainWindow::GetHeaderWidth() const
3640 if ( !m_headerWidth
)
3642 wxListMainWindow
*self
= wxConstCast(this, wxListMainWindow
);
3644 size_t count
= GetColumnCount();
3645 for ( size_t col
= 0; col
< count
; col
++ )
3647 self
->m_headerWidth
+= GetColumnWidth(col
);
3651 return m_headerWidth
;
3654 void wxListMainWindow::GetColumn( int col
, wxListItem
&item
) const
3656 wxListHeaderDataList::Node
*node
= m_columns
.Item( col
);
3657 wxCHECK_RET( node
, _T("invalid column index in GetColumn") );
3659 wxListHeaderData
*column
= node
->GetData();
3660 column
->GetItem( item
);
3663 int wxListMainWindow::GetColumnWidth( int col
) const
3665 wxListHeaderDataList::Node
*node
= m_columns
.Item( col
);
3666 wxCHECK_MSG( node
, 0, _T("invalid column index") );
3668 wxListHeaderData
*column
= node
->GetData();
3669 return column
->GetWidth();
3672 // ----------------------------------------------------------------------------
3674 // ----------------------------------------------------------------------------
3676 void wxListMainWindow::SetItem( wxListItem
&item
)
3678 long id
= item
.m_itemId
;
3679 wxCHECK_RET( id
>= 0 && (size_t)id
< GetItemCount(),
3680 _T("invalid item index in SetItem") );
3684 wxListLineData
*line
= GetLine((size_t)id
);
3685 line
->SetItem( item
.m_col
, item
);
3688 if ( InReportView() )
3690 // just refresh the line to show the new value of the text/image
3691 RefreshLine((size_t)id
);
3695 // refresh everything (resulting in horrible flicker - FIXME!)
3700 void wxListMainWindow::SetItemState( long litem
, long state
, long stateMask
)
3702 wxCHECK_RET( litem
>= 0 && (size_t)litem
< GetItemCount(),
3703 _T("invalid list ctrl item index in SetItem") );
3705 size_t oldCurrent
= m_current
;
3706 size_t item
= (size_t)litem
; // safe because of the check above
3708 // do we need to change the focus?
3709 if ( stateMask
& wxLIST_STATE_FOCUSED
)
3711 if ( state
& wxLIST_STATE_FOCUSED
)
3713 // don't do anything if this item is already focused
3714 if ( item
!= m_current
)
3716 ChangeCurrent(item
);
3718 if ( oldCurrent
!= (size_t)-1 )
3720 if ( IsSingleSel() )
3722 HighlightLine(oldCurrent
, FALSE
);
3725 RefreshLine(oldCurrent
);
3728 RefreshLine( m_current
);
3733 // don't do anything if this item is not focused
3734 if ( item
== m_current
)
3738 RefreshLine( oldCurrent
);
3743 // do we need to change the selection state?
3744 if ( stateMask
& wxLIST_STATE_SELECTED
)
3746 bool on
= (state
& wxLIST_STATE_SELECTED
) != 0;
3748 if ( IsSingleSel() )
3752 // selecting the item also makes it the focused one in the
3754 if ( m_current
!= item
)
3756 ChangeCurrent(item
);
3758 if ( oldCurrent
!= (size_t)-1 )
3760 HighlightLine( oldCurrent
, FALSE
);
3761 RefreshLine( oldCurrent
);
3767 // only the current item may be selected anyhow
3768 if ( item
!= m_current
)
3773 if ( HighlightLine(item
, on
) )
3780 int wxListMainWindow::GetItemState( long item
, long stateMask
)
3782 wxCHECK_MSG( item
>= 0 && (size_t)item
< GetItemCount(), 0,
3783 _T("invalid list ctrl item index in GetItemState()") );
3785 int ret
= wxLIST_STATE_DONTCARE
;
3787 if ( stateMask
& wxLIST_STATE_FOCUSED
)
3789 if ( (size_t)item
== m_current
)
3790 ret
|= wxLIST_STATE_FOCUSED
;
3793 if ( stateMask
& wxLIST_STATE_SELECTED
)
3795 if ( IsHighlighted(item
) )
3796 ret
|= wxLIST_STATE_SELECTED
;
3802 void wxListMainWindow::GetItem( wxListItem
&item
)
3804 wxCHECK_RET( item
.m_itemId
>= 0 && (size_t)item
.m_itemId
< GetItemCount(),
3805 _T("invalid item index in GetItem") );
3807 wxListLineData
*line
= GetLine((size_t)item
.m_itemId
);
3808 line
->GetItem( item
.m_col
, item
);
3811 // ----------------------------------------------------------------------------
3813 // ----------------------------------------------------------------------------
3815 size_t wxListMainWindow::GetItemCount() const
3817 return IsVirtual() ? m_countVirt
: m_lines
.GetCount();
3820 void wxListMainWindow::SetItemCount(long count
)
3822 m_selStore
.SetItemCount(count
);
3823 m_countVirt
= count
;
3825 ResetVisibleLinesRange();
3827 // scrollbars must be reset
3831 int wxListMainWindow::GetSelectedItemCount()
3833 // deal with the quick case first
3834 if ( IsSingleSel() )
3836 return HasCurrent() ? IsHighlighted(m_current
) : FALSE
;
3839 // virtual controls remmebers all its selections itself
3841 return m_selStore
.GetSelectedCount();
3843 // TODO: we probably should maintain the number of items selected even for
3844 // non virtual controls as enumerating all lines is really slow...
3845 size_t countSel
= 0;
3846 size_t count
= GetItemCount();
3847 for ( size_t line
= 0; line
< count
; line
++ )
3849 if ( GetLine(line
)->IsHighlighted() )
3856 // ----------------------------------------------------------------------------
3857 // item position/size
3858 // ----------------------------------------------------------------------------
3860 void wxListMainWindow::GetItemRect( long index
, wxRect
&rect
)
3862 wxCHECK_RET( index
>= 0 && (size_t)index
< GetItemCount(),
3863 _T("invalid index in GetItemRect") );
3865 rect
= GetLineRect((size_t)index
);
3867 CalcScrolledPosition(rect
.x
, rect
.y
, &rect
.x
, &rect
.y
);
3870 bool wxListMainWindow::GetItemPosition(long item
, wxPoint
& pos
)
3873 GetItemRect(item
, rect
);
3881 // ----------------------------------------------------------------------------
3882 // geometry calculation
3883 // ----------------------------------------------------------------------------
3885 void wxListMainWindow::RecalculatePositions(bool noRefresh
)
3887 wxClientDC
dc( this );
3888 dc
.SetFont( GetFont() );
3891 if ( HasFlag(wxLC_ICON
) )
3892 iconSpacing
= m_normal_spacing
;
3893 else if ( HasFlag(wxLC_SMALL_ICON
) )
3894 iconSpacing
= m_small_spacing
;
3900 GetClientSize( &clientWidth
, &clientHeight
);
3902 if ( HasFlag(wxLC_REPORT
) )
3904 // all lines have the same height
3905 int lineHeight
= GetLineHeight();
3907 // scroll one line per step
3908 m_yScroll
= lineHeight
;
3910 size_t lineCount
= GetItemCount();
3911 int entireHeight
= lineCount
*lineHeight
+ LINE_SPACING
;
3913 m_linesPerPage
= clientHeight
/ lineHeight
;
3915 ResetVisibleLinesRange();
3917 SetScrollbars( m_xScroll
, m_yScroll
,
3918 (GetHeaderWidth() + m_xScroll
- 1)/m_xScroll
,
3919 (entireHeight
+ m_yScroll
- 1)/m_yScroll
,
3920 GetScrollPos(wxHORIZONTAL
),
3921 GetScrollPos(wxVERTICAL
),
3926 // at first we try without any scrollbar. if the items don't
3927 // fit into the window, we recalculate after subtracting an
3928 // approximated 15 pt for the horizontal scrollbar
3930 clientHeight
-= 4; // sunken frame
3932 int entireWidth
= 0;
3934 for (int tries
= 0; tries
< 2; tries
++)
3941 int currentlyVisibleLines
= 0;
3943 size_t count
= GetItemCount();
3944 for (size_t i
= 0; i
< count
; i
++)
3946 currentlyVisibleLines
++;
3947 wxListLineData
*line
= GetLine(i
);
3948 line
->CalculateSize( &dc
, iconSpacing
);
3949 line
->SetPosition( x
, y
, clientWidth
, iconSpacing
);
3951 wxSize sizeLine
= GetLineSize(i
);
3953 if ( maxWidth
< sizeLine
.x
)
3954 maxWidth
= sizeLine
.x
;
3957 if (currentlyVisibleLines
> m_linesPerPage
)
3958 m_linesPerPage
= currentlyVisibleLines
;
3960 // assume that the size of the next one is the same... (FIXME)
3961 if ( y
+ sizeLine
.y
- 6 >= clientHeight
)
3963 currentlyVisibleLines
= 0;
3966 entireWidth
+= maxWidth
+6;
3969 if ( i
== count
- 1 )
3970 entireWidth
+= maxWidth
;
3971 if ((tries
== 0) && (entireWidth
> clientWidth
))
3973 clientHeight
-= 15; // scrollbar height
3975 currentlyVisibleLines
= 0;
3978 if ( i
== count
- 1 )
3979 tries
= 1; // everything fits, no second try required
3983 int scroll_pos
= GetScrollPos( wxHORIZONTAL
);
3984 SetScrollbars( m_xScroll
, m_yScroll
, (entireWidth
+SCROLL_UNIT_X
) / m_xScroll
, 0, scroll_pos
, 0, TRUE
);
3989 // FIXME: why should we call it from here?
3996 void wxListMainWindow::RefreshAll()
4001 wxListHeaderWindow
*headerWin
= GetListCtrl()->m_headerWin
;
4002 if ( headerWin
&& headerWin
->m_dirty
)
4004 headerWin
->m_dirty
= FALSE
;
4005 headerWin
->Refresh();
4009 void wxListMainWindow::UpdateCurrent()
4011 if ( !HasCurrent() && !IsEmpty() )
4017 long wxListMainWindow::GetNextItem( long item
,
4018 int WXUNUSED(geometry
),
4022 max
= GetItemCount();
4023 wxCHECK_MSG( (ret
== -1) || (ret
< max
), -1,
4024 _T("invalid listctrl index in GetNextItem()") );
4026 // notice that we start with the next item (or the first one if item == -1)
4027 // and this is intentional to allow writing a simple loop to iterate over
4028 // all selected items
4032 // this is not an error because the index was ok initially, just no
4043 size_t count
= GetItemCount();
4044 for ( size_t line
= (size_t)ret
; line
< count
; line
++ )
4046 if ( (state
& wxLIST_STATE_FOCUSED
) && (line
== m_current
) )
4049 if ( (state
& wxLIST_STATE_SELECTED
) && IsHighlighted(line
) )
4056 // ----------------------------------------------------------------------------
4058 // ----------------------------------------------------------------------------
4060 void wxListMainWindow::DeleteItem( long lindex
)
4062 size_t count
= GetItemCount();
4064 wxCHECK_RET( (lindex
>= 0) && ((size_t)lindex
< count
),
4065 _T("invalid item index in DeleteItem") );
4067 size_t index
= (size_t)lindex
;
4069 // we don't need to adjust the index for the previous items
4070 if ( HasCurrent() && m_current
>= index
)
4072 // if the current item is being deleted, we want the next one to
4073 // become selected - unless there is no next one - so don't adjust
4074 // m_current in this case
4075 if ( m_current
!= index
|| m_current
== count
- 1 )
4081 if ( InReportView() )
4083 ResetVisibleLinesRange();
4090 m_selStore
.OnItemDelete(index
);
4094 m_lines
.RemoveAt( index
);
4097 // we need to refresh the (vert) scrollbar as the number of items changed
4100 SendNotify( index
, wxEVT_COMMAND_LIST_DELETE_ITEM
);
4102 RefreshAfter(index
);
4105 void wxListMainWindow::DeleteColumn( int col
)
4107 wxListHeaderDataList::Node
*node
= m_columns
.Item( col
);
4109 wxCHECK_RET( node
, wxT("invalid column index in DeleteColumn()") );
4112 m_columns
.DeleteNode( node
);
4115 void wxListMainWindow::DoDeleteAllItems()
4119 // nothing to do - in particular, don't send the event
4125 // to make the deletion of all items faster, we don't send the
4126 // notifications for each item deletion in this case but only one event
4127 // for all of them: this is compatible with wxMSW and documented in
4128 // DeleteAllItems() description
4130 wxListEvent
event( wxEVT_COMMAND_LIST_DELETE_ALL_ITEMS
, GetParent()->GetId() );
4131 event
.SetEventObject( GetParent() );
4132 GetParent()->GetEventHandler()->ProcessEvent( event
);
4141 if ( InReportView() )
4143 ResetVisibleLinesRange();
4149 void wxListMainWindow::DeleteAllItems()
4153 RecalculatePositions();
4156 void wxListMainWindow::DeleteEverything()
4163 // ----------------------------------------------------------------------------
4164 // scanning for an item
4165 // ----------------------------------------------------------------------------
4167 void wxListMainWindow::EnsureVisible( long index
)
4169 wxCHECK_RET( index
>= 0 && (size_t)index
< GetItemCount(),
4170 _T("invalid index in EnsureVisible") );
4172 // We have to call this here because the label in question might just have
4173 // been added and its position is not known yet
4176 RecalculatePositions(TRUE
/* no refresh */);
4179 MoveToItem((size_t)index
);
4182 long wxListMainWindow::FindItem(long start
, const wxString
& str
, bool WXUNUSED(partial
) )
4189 size_t count
= GetItemCount();
4190 for ( size_t i
= (size_t)pos
; i
< count
; i
++ )
4192 wxListLineData
*line
= GetLine(i
);
4193 if ( line
->GetText(0) == tmp
)
4200 long wxListMainWindow::FindItem(long start
, long data
)
4206 size_t count
= GetItemCount();
4207 for (size_t i
= (size_t)pos
; i
< count
; i
++)
4209 wxListLineData
*line
= GetLine(i
);
4211 line
->GetItem( 0, item
);
4212 if (item
.m_data
== data
)
4219 long wxListMainWindow::HitTest( int x
, int y
, int &flags
)
4221 CalcUnscrolledPosition( x
, y
, &x
, &y
);
4223 size_t count
= GetItemCount();
4225 if ( HasFlag(wxLC_REPORT
) )
4227 size_t current
= y
/ GetLineHeight();
4228 if ( current
< count
)
4230 flags
= HitTestLine(current
, x
, y
);
4237 // TODO: optimize it too! this is less simple than for report view but
4238 // enumerating all items is still not a way to do it!!
4239 for ( size_t current
= 0; current
< count
; current
++ )
4241 flags
= HitTestLine(current
, x
, y
);
4250 // ----------------------------------------------------------------------------
4252 // ----------------------------------------------------------------------------
4254 void wxListMainWindow::InsertItem( wxListItem
&item
)
4256 wxASSERT_MSG( !IsVirtual(), _T("can't be used with virtual control") );
4258 size_t count
= GetItemCount();
4259 wxCHECK_RET( item
.m_itemId
>= 0 && (size_t)item
.m_itemId
<= count
,
4260 _T("invalid item index") );
4262 size_t id
= item
.m_itemId
;
4267 if ( HasFlag(wxLC_REPORT
) )
4269 else if ( HasFlag(wxLC_LIST
) )
4271 else if ( HasFlag(wxLC_ICON
) )
4273 else if ( HasFlag(wxLC_SMALL_ICON
) )
4274 mode
= wxLC_ICON
; // no typo
4277 wxFAIL_MSG( _T("unknown mode") );
4280 wxListLineData
*line
= new wxListLineData(this);
4282 line
->SetItem( 0, item
);
4284 m_lines
.Insert( line
, id
);
4287 RefreshLines(id
, GetItemCount() - 1);
4290 void wxListMainWindow::InsertColumn( long col
, wxListItem
&item
)
4293 if ( HasFlag(wxLC_REPORT
) )
4295 if (item
.m_width
== wxLIST_AUTOSIZE_USEHEADER
)
4296 item
.m_width
= GetTextLength( item
.m_text
);
4297 wxListHeaderData
*column
= new wxListHeaderData( item
);
4298 if ((col
>= 0) && (col
< (int)m_columns
.GetCount()))
4300 wxListHeaderDataList::Node
*node
= m_columns
.Item( col
);
4301 m_columns
.Insert( node
, column
);
4305 m_columns
.Append( column
);
4310 // ----------------------------------------------------------------------------
4312 // ----------------------------------------------------------------------------
4314 wxListCtrlCompare list_ctrl_compare_func_2
;
4315 long list_ctrl_compare_data
;
4317 int LINKAGEMODE
list_ctrl_compare_func_1( wxListLineData
**arg1
, wxListLineData
**arg2
)
4319 wxListLineData
*line1
= *arg1
;
4320 wxListLineData
*line2
= *arg2
;
4322 line1
->GetItem( 0, item
);
4323 long data1
= item
.m_data
;
4324 line2
->GetItem( 0, item
);
4325 long data2
= item
.m_data
;
4326 return list_ctrl_compare_func_2( data1
, data2
, list_ctrl_compare_data
);
4329 void wxListMainWindow::SortItems( wxListCtrlCompare fn
, long data
)
4331 list_ctrl_compare_func_2
= fn
;
4332 list_ctrl_compare_data
= data
;
4333 m_lines
.Sort( list_ctrl_compare_func_1
);
4337 // ----------------------------------------------------------------------------
4339 // ----------------------------------------------------------------------------
4341 void wxListMainWindow::OnScroll(wxScrollWinEvent
& event
)
4343 // update our idea of which lines are shown when we redraw the window the
4345 ResetVisibleLinesRange();
4348 #if defined(__WXGTK__) && !defined(__WXUNIVERSAL__)
4349 wxScrolledWindow::OnScroll(event
);
4351 HandleOnScroll( event
);
4354 if ( event
.GetOrientation() == wxHORIZONTAL
&& HasHeader() )
4356 wxListCtrl
* lc
= GetListCtrl();
4357 wxCHECK_RET( lc
, _T("no listctrl window?") );
4359 lc
->m_headerWin
->Refresh() ;
4361 lc
->m_headerWin
->MacUpdateImmediately() ;
4366 int wxListMainWindow::GetCountPerPage() const
4368 if ( !m_linesPerPage
)
4370 wxConstCast(this, wxListMainWindow
)->
4371 m_linesPerPage
= GetClientSize().y
/ GetLineHeight();
4374 return m_linesPerPage
;
4377 void wxListMainWindow::GetVisibleLinesRange(size_t *from
, size_t *to
)
4379 wxASSERT_MSG( HasFlag(wxLC_REPORT
), _T("this is for report mode only") );
4381 if ( m_lineFrom
== (size_t)-1 )
4383 size_t count
= GetItemCount();
4386 m_lineFrom
= GetScrollPos(wxVERTICAL
);
4388 // this may happen if SetScrollbars() hadn't been called yet
4389 if ( m_lineFrom
>= count
)
4390 m_lineFrom
= count
- 1;
4392 // we redraw one extra line but this is needed to make the redrawing
4393 // logic work when there is a fractional number of lines on screen
4394 m_lineTo
= m_lineFrom
+ m_linesPerPage
;
4395 if ( m_lineTo
>= count
)
4396 m_lineTo
= count
- 1;
4398 else // empty control
4401 m_lineTo
= (size_t)-1;
4405 wxASSERT_MSG( IsEmpty() ||
4406 (m_lineFrom
<= m_lineTo
&& m_lineTo
< GetItemCount()),
4407 _T("GetVisibleLinesRange() returns incorrect result") );
4415 // -------------------------------------------------------------------------------------
4417 // -------------------------------------------------------------------------------------
4419 IMPLEMENT_DYNAMIC_CLASS(wxListItem
, wxObject
)
4421 wxListItem::wxListItem()
4428 void wxListItem::Clear()
4437 m_format
= wxLIST_FORMAT_CENTRE
;
4444 void wxListItem::ClearAttributes()
4453 // -------------------------------------------------------------------------------------
4455 // -------------------------------------------------------------------------------------
4457 IMPLEMENT_DYNAMIC_CLASS(wxListCtrl
, wxControl
)
4458 IMPLEMENT_DYNAMIC_CLASS(wxListView
, wxListCtrl
)
4460 IMPLEMENT_DYNAMIC_CLASS(wxListEvent
, wxNotifyEvent
)
4462 BEGIN_EVENT_TABLE(wxListCtrl
,wxControl
)
4463 EVT_SIZE(wxListCtrl::OnSize
)
4464 EVT_IDLE(wxListCtrl::OnIdle
)
4467 wxListCtrl::wxListCtrl()
4469 m_imageListNormal
= (wxImageList
*) NULL
;
4470 m_imageListSmall
= (wxImageList
*) NULL
;
4471 m_imageListState
= (wxImageList
*) NULL
;
4473 m_ownsImageListNormal
=
4474 m_ownsImageListSmall
=
4475 m_ownsImageListState
= FALSE
;
4477 m_mainWin
= (wxListMainWindow
*) NULL
;
4478 m_headerWin
= (wxListHeaderWindow
*) NULL
;
4481 wxListCtrl::~wxListCtrl()
4483 if (m_ownsImageListNormal
)
4484 delete m_imageListNormal
;
4485 if (m_ownsImageListSmall
)
4486 delete m_imageListSmall
;
4487 if (m_ownsImageListState
)
4488 delete m_imageListState
;
4491 void wxListCtrl::CreateHeaderWindow()
4493 m_headerWin
= new wxListHeaderWindow
4495 this, -1, m_mainWin
,
4497 wxSize(GetClientSize().x
, HEADER_HEIGHT
),
4502 bool wxListCtrl::Create(wxWindow
*parent
,
4507 const wxValidator
&validator
,
4508 const wxString
&name
)
4512 m_imageListState
= (wxImageList
*) NULL
;
4513 m_ownsImageListNormal
=
4514 m_ownsImageListSmall
=
4515 m_ownsImageListState
= FALSE
;
4517 m_mainWin
= (wxListMainWindow
*) NULL
;
4518 m_headerWin
= (wxListHeaderWindow
*) NULL
;
4520 if ( !(style
& wxLC_MASK_TYPE
) )
4522 style
= style
| wxLC_LIST
;
4525 if ( !wxControl::Create( parent
, id
, pos
, size
, style
, validator
, name
) )
4528 // don't create the inner window with the border
4529 style
&= ~wxSUNKEN_BORDER
;
4531 m_mainWin
= new wxListMainWindow( this, -1, wxPoint(0,0), size
, style
);
4533 if ( HasFlag(wxLC_REPORT
) )
4535 CreateHeaderWindow();
4537 if ( HasFlag(wxLC_NO_HEADER
) )
4539 // VZ: why do we create it at all then?
4540 m_headerWin
->Show( FALSE
);
4547 void wxListCtrl::SetSingleStyle( long style
, bool add
)
4549 wxASSERT_MSG( !(style
& wxLC_VIRTUAL
),
4550 _T("wxLC_VIRTUAL can't be [un]set") );
4552 long flag
= GetWindowStyle();
4556 if (style
& wxLC_MASK_TYPE
)
4557 flag
&= ~(wxLC_MASK_TYPE
| wxLC_VIRTUAL
);
4558 if (style
& wxLC_MASK_ALIGN
)
4559 flag
&= ~wxLC_MASK_ALIGN
;
4560 if (style
& wxLC_MASK_SORT
)
4561 flag
&= ~wxLC_MASK_SORT
;
4573 SetWindowStyleFlag( flag
);
4576 void wxListCtrl::SetWindowStyleFlag( long flag
)
4580 m_mainWin
->DeleteEverything();
4582 // has the header visibility changed?
4583 bool hasHeader
= HasFlag(wxLC_REPORT
) && !HasFlag(wxLC_NO_HEADER
),
4584 willHaveHeader
= (flag
& wxLC_REPORT
) && !(flag
& wxLC_NO_HEADER
);
4586 if ( hasHeader
!= willHaveHeader
)
4593 // don't delete, just hide, as we can reuse it later
4594 m_headerWin
->Show(FALSE
);
4596 //else: nothing to do
4598 else // must show header
4602 CreateHeaderWindow();
4604 else // already have it, just show
4606 m_headerWin
->Show( TRUE
);
4610 ResizeReportView(willHaveHeader
);
4614 wxWindow::SetWindowStyleFlag( flag
);
4617 bool wxListCtrl::GetColumn(int col
, wxListItem
&item
) const
4619 m_mainWin
->GetColumn( col
, item
);
4623 bool wxListCtrl::SetColumn( int col
, wxListItem
& item
)
4625 m_mainWin
->SetColumn( col
, item
);
4629 int wxListCtrl::GetColumnWidth( int col
) const
4631 return m_mainWin
->GetColumnWidth( col
);
4634 bool wxListCtrl::SetColumnWidth( int col
, int width
)
4636 m_mainWin
->SetColumnWidth( col
, width
);
4640 int wxListCtrl::GetCountPerPage() const
4642 return m_mainWin
->GetCountPerPage(); // different from Windows ?
4645 bool wxListCtrl::GetItem( wxListItem
&info
) const
4647 m_mainWin
->GetItem( info
);
4651 bool wxListCtrl::SetItem( wxListItem
&info
)
4653 m_mainWin
->SetItem( info
);
4657 long wxListCtrl::SetItem( long index
, int col
, const wxString
& label
, int imageId
)
4660 info
.m_text
= label
;
4661 info
.m_mask
= wxLIST_MASK_TEXT
;
4662 info
.m_itemId
= index
;
4666 info
.m_image
= imageId
;
4667 info
.m_mask
|= wxLIST_MASK_IMAGE
;
4669 m_mainWin
->SetItem(info
);
4673 int wxListCtrl::GetItemState( long item
, long stateMask
) const
4675 return m_mainWin
->GetItemState( item
, stateMask
);
4678 bool wxListCtrl::SetItemState( long item
, long state
, long stateMask
)
4680 m_mainWin
->SetItemState( item
, state
, stateMask
);
4684 bool wxListCtrl::SetItemImage( long item
, int image
, int WXUNUSED(selImage
) )
4687 info
.m_image
= image
;
4688 info
.m_mask
= wxLIST_MASK_IMAGE
;
4689 info
.m_itemId
= item
;
4690 m_mainWin
->SetItem( info
);
4694 wxString
wxListCtrl::GetItemText( long item
) const
4697 info
.m_itemId
= item
;
4698 m_mainWin
->GetItem( info
);
4702 void wxListCtrl::SetItemText( long item
, const wxString
&str
)
4705 info
.m_mask
= wxLIST_MASK_TEXT
;
4706 info
.m_itemId
= item
;
4708 m_mainWin
->SetItem( info
);
4711 long wxListCtrl::GetItemData( long item
) const
4714 info
.m_itemId
= item
;
4715 m_mainWin
->GetItem( info
);
4719 bool wxListCtrl::SetItemData( long item
, long data
)
4722 info
.m_mask
= wxLIST_MASK_DATA
;
4723 info
.m_itemId
= item
;
4725 m_mainWin
->SetItem( info
);
4729 bool wxListCtrl::GetItemRect( long item
, wxRect
&rect
, int WXUNUSED(code
) ) const
4731 m_mainWin
->GetItemRect( item
, rect
);
4735 bool wxListCtrl::GetItemPosition( long item
, wxPoint
& pos
) const
4737 m_mainWin
->GetItemPosition( item
, pos
);
4741 bool wxListCtrl::SetItemPosition( long WXUNUSED(item
), const wxPoint
& WXUNUSED(pos
) )
4746 int wxListCtrl::GetItemCount() const
4748 return m_mainWin
->GetItemCount();
4751 int wxListCtrl::GetColumnCount() const
4753 return m_mainWin
->GetColumnCount();
4756 void wxListCtrl::SetItemSpacing( int spacing
, bool isSmall
)
4758 m_mainWin
->SetItemSpacing( spacing
, isSmall
);
4761 int wxListCtrl::GetItemSpacing( bool isSmall
) const
4763 return m_mainWin
->GetItemSpacing( isSmall
);
4766 int wxListCtrl::GetSelectedItemCount() const
4768 return m_mainWin
->GetSelectedItemCount();
4771 wxColour
wxListCtrl::GetTextColour() const
4773 return GetForegroundColour();
4776 void wxListCtrl::SetTextColour(const wxColour
& col
)
4778 SetForegroundColour(col
);
4781 long wxListCtrl::GetTopItem() const
4786 long wxListCtrl::GetNextItem( long item
, int geom
, int state
) const
4788 return m_mainWin
->GetNextItem( item
, geom
, state
);
4791 wxImageList
*wxListCtrl::GetImageList(int which
) const
4793 if (which
== wxIMAGE_LIST_NORMAL
)
4795 return m_imageListNormal
;
4797 else if (which
== wxIMAGE_LIST_SMALL
)
4799 return m_imageListSmall
;
4801 else if (which
== wxIMAGE_LIST_STATE
)
4803 return m_imageListState
;
4805 return (wxImageList
*) NULL
;
4808 void wxListCtrl::SetImageList( wxImageList
*imageList
, int which
)
4810 if ( which
== wxIMAGE_LIST_NORMAL
)
4812 if (m_ownsImageListNormal
) delete m_imageListNormal
;
4813 m_imageListNormal
= imageList
;
4814 m_ownsImageListNormal
= FALSE
;
4816 else if ( which
== wxIMAGE_LIST_SMALL
)
4818 if (m_ownsImageListSmall
) delete m_imageListSmall
;
4819 m_imageListSmall
= imageList
;
4820 m_ownsImageListSmall
= FALSE
;
4822 else if ( which
== wxIMAGE_LIST_STATE
)
4824 if (m_ownsImageListState
) delete m_imageListState
;
4825 m_imageListState
= imageList
;
4826 m_ownsImageListState
= FALSE
;
4829 m_mainWin
->SetImageList( imageList
, which
);
4832 void wxListCtrl::AssignImageList(wxImageList
*imageList
, int which
)
4834 SetImageList(imageList
, which
);
4835 if ( which
== wxIMAGE_LIST_NORMAL
)
4836 m_ownsImageListNormal
= TRUE
;
4837 else if ( which
== wxIMAGE_LIST_SMALL
)
4838 m_ownsImageListSmall
= TRUE
;
4839 else if ( which
== wxIMAGE_LIST_STATE
)
4840 m_ownsImageListState
= TRUE
;
4843 bool wxListCtrl::Arrange( int WXUNUSED(flag
) )
4848 bool wxListCtrl::DeleteItem( long item
)
4850 m_mainWin
->DeleteItem( item
);
4854 bool wxListCtrl::DeleteAllItems()
4856 m_mainWin
->DeleteAllItems();
4860 bool wxListCtrl::DeleteAllColumns()
4862 size_t count
= m_mainWin
->m_columns
.GetCount();
4863 for ( size_t n
= 0; n
< count
; n
++ )
4869 void wxListCtrl::ClearAll()
4871 m_mainWin
->DeleteEverything();
4874 bool wxListCtrl::DeleteColumn( int col
)
4876 m_mainWin
->DeleteColumn( col
);
4880 void wxListCtrl::Edit( long item
)
4882 m_mainWin
->EditLabel( item
);
4885 bool wxListCtrl::EnsureVisible( long item
)
4887 m_mainWin
->EnsureVisible( item
);
4891 long wxListCtrl::FindItem( long start
, const wxString
& str
, bool partial
)
4893 return m_mainWin
->FindItem( start
, str
, partial
);
4896 long wxListCtrl::FindItem( long start
, long data
)
4898 return m_mainWin
->FindItem( start
, data
);
4901 long wxListCtrl::FindItem( long WXUNUSED(start
), const wxPoint
& WXUNUSED(pt
),
4902 int WXUNUSED(direction
))
4907 long wxListCtrl::HitTest( const wxPoint
&point
, int &flags
)
4909 return m_mainWin
->HitTest( (int)point
.x
, (int)point
.y
, flags
);
4912 long wxListCtrl::InsertItem( wxListItem
& info
)
4914 m_mainWin
->InsertItem( info
);
4915 return info
.m_itemId
;
4918 long wxListCtrl::InsertItem( long index
, const wxString
&label
)
4921 info
.m_text
= label
;
4922 info
.m_mask
= wxLIST_MASK_TEXT
;
4923 info
.m_itemId
= index
;
4924 return InsertItem( info
);
4927 long wxListCtrl::InsertItem( long index
, int imageIndex
)
4930 info
.m_mask
= wxLIST_MASK_IMAGE
;
4931 info
.m_image
= imageIndex
;
4932 info
.m_itemId
= index
;
4933 return InsertItem( info
);
4936 long wxListCtrl::InsertItem( long index
, const wxString
&label
, int imageIndex
)
4939 info
.m_text
= label
;
4940 info
.m_image
= imageIndex
;
4941 info
.m_mask
= wxLIST_MASK_TEXT
| wxLIST_MASK_IMAGE
;
4942 info
.m_itemId
= index
;
4943 return InsertItem( info
);
4946 long wxListCtrl::InsertColumn( long col
, wxListItem
&item
)
4948 wxASSERT( m_headerWin
);
4949 m_mainWin
->InsertColumn( col
, item
);
4950 m_headerWin
->Refresh();
4955 long wxListCtrl::InsertColumn( long col
, const wxString
&heading
,
4956 int format
, int width
)
4959 item
.m_mask
= wxLIST_MASK_TEXT
| wxLIST_MASK_FORMAT
;
4960 item
.m_text
= heading
;
4963 item
.m_mask
|= wxLIST_MASK_WIDTH
;
4964 item
.m_width
= width
;
4966 item
.m_format
= format
;
4968 return InsertColumn( col
, item
);
4971 bool wxListCtrl::ScrollList( int WXUNUSED(dx
), int WXUNUSED(dy
) )
4977 // fn is a function which takes 3 long arguments: item1, item2, data.
4978 // item1 is the long data associated with a first item (NOT the index).
4979 // item2 is the long data associated with a second item (NOT the index).
4980 // data is the same value as passed to SortItems.
4981 // The return value is a negative number if the first item should precede the second
4982 // item, a positive number of the second item should precede the first,
4983 // or zero if the two items are equivalent.
4984 // data is arbitrary data to be passed to the sort function.
4986 bool wxListCtrl::SortItems( wxListCtrlCompare fn
, long data
)
4988 m_mainWin
->SortItems( fn
, data
);
4992 // ----------------------------------------------------------------------------
4994 // ----------------------------------------------------------------------------
4996 void wxListCtrl::OnSize(wxSizeEvent
& event
)
5001 ResizeReportView(m_mainWin
->HasHeader());
5003 m_mainWin
->RecalculatePositions();
5006 void wxListCtrl::ResizeReportView(bool showHeader
)
5009 GetClientSize( &cw
, &ch
);
5013 m_headerWin
->SetSize( 0, 0, cw
, HEADER_HEIGHT
);
5014 m_mainWin
->SetSize( 0, HEADER_HEIGHT
+ 1, cw
, ch
- HEADER_HEIGHT
- 1 );
5016 else // no header window
5018 m_mainWin
->SetSize( 0, 0, cw
, ch
);
5022 void wxListCtrl::OnIdle( wxIdleEvent
& event
)
5026 // do it only if needed
5027 if ( !m_mainWin
->m_dirty
)
5030 m_mainWin
->RecalculatePositions();
5033 // ----------------------------------------------------------------------------
5035 // ----------------------------------------------------------------------------
5037 bool wxListCtrl::SetBackgroundColour( const wxColour
&colour
)
5041 m_mainWin
->SetBackgroundColour( colour
);
5042 m_mainWin
->m_dirty
= TRUE
;
5048 bool wxListCtrl::SetForegroundColour( const wxColour
&colour
)
5050 if ( !wxWindow::SetForegroundColour( colour
) )
5055 m_mainWin
->SetForegroundColour( colour
);
5056 m_mainWin
->m_dirty
= TRUE
;
5061 m_headerWin
->SetForegroundColour( colour
);
5067 bool wxListCtrl::SetFont( const wxFont
&font
)
5069 if ( !wxWindow::SetFont( font
) )
5074 m_mainWin
->SetFont( font
);
5075 m_mainWin
->m_dirty
= TRUE
;
5080 m_headerWin
->SetFont( font
);
5086 // ----------------------------------------------------------------------------
5087 // methods forwarded to m_mainWin
5088 // ----------------------------------------------------------------------------
5090 #if wxUSE_DRAG_AND_DROP
5092 void wxListCtrl::SetDropTarget( wxDropTarget
*dropTarget
)
5094 m_mainWin
->SetDropTarget( dropTarget
);
5097 wxDropTarget
*wxListCtrl::GetDropTarget() const
5099 return m_mainWin
->GetDropTarget();
5102 #endif // wxUSE_DRAG_AND_DROP
5104 bool wxListCtrl::SetCursor( const wxCursor
&cursor
)
5106 return m_mainWin
? m_mainWin
->wxWindow::SetCursor(cursor
) : FALSE
;
5109 wxColour
wxListCtrl::GetBackgroundColour() const
5111 return m_mainWin
? m_mainWin
->GetBackgroundColour() : wxColour();
5114 wxColour
wxListCtrl::GetForegroundColour() const
5116 return m_mainWin
? m_mainWin
->GetForegroundColour() : wxColour();
5119 bool wxListCtrl::DoPopupMenu( wxMenu
*menu
, int x
, int y
)
5122 return m_mainWin
->PopupMenu( menu
, x
, y
);
5125 #endif // wxUSE_MENUS
5128 void wxListCtrl::SetFocus()
5130 /* The test in window.cpp fails as we are a composite
5131 window, so it checks against "this", but not m_mainWin. */
5132 if ( FindFocus() != this )
5133 m_mainWin
->SetFocus();
5136 // ----------------------------------------------------------------------------
5137 // virtual list control support
5138 // ----------------------------------------------------------------------------
5140 wxString
wxListCtrl::OnGetItemText(long item
, long col
) const
5142 // this is a pure virtual function, in fact - which is not really pure
5143 // because the controls which are not virtual don't need to implement it
5144 wxFAIL_MSG( _T("not supposed to be called") );
5146 return wxEmptyString
;
5149 int wxListCtrl::OnGetItemImage(long item
) const
5152 wxFAIL_MSG( _T("not supposed to be called") );
5157 wxListItemAttr
*wxListCtrl::OnGetItemAttr(long item
) const
5159 wxASSERT_MSG( item
>= 0 && item
< GetItemCount(),
5160 _T("invalid item index in OnGetItemAttr()") );
5162 // no attributes by default
5166 void wxListCtrl::SetItemCount(long count
)
5168 wxASSERT_MSG( IsVirtual(), _T("this is for virtual controls only") );
5170 m_mainWin
->SetItemCount(count
);
5173 void wxListCtrl::RefreshItem(long item
)
5175 m_mainWin
->RefreshLine(item
);
5178 void wxListCtrl::RefreshItems(long itemFrom
, long itemTo
)
5180 m_mainWin
->RefreshLines(itemFrom
, itemTo
);
5183 void wxListCtrl::Freeze()
5185 m_mainWin
->Freeze();
5188 void wxListCtrl::Thaw()
5193 #endif // wxUSE_LISTCTRL