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)
983 itemsChanged
->Add(m_itemsSel
[i
]);
987 m_itemsSel
.RemoveAt(i
);
992 else // "few" items change state
996 itemsChanged
->Empty();
999 // just add the items to the selection
1000 for ( size_t item
= itemFrom
; item
<= itemTo
; item
++ )
1002 if ( SelectItem(item
, select
) && itemsChanged
)
1004 itemsChanged
->Add(item
);
1006 if ( itemsChanged
->GetCount() > MANY_ITEMS
)
1008 // stop counting them, we'll just eat gobs of memory
1009 // for nothing at all - faster to refresh everything in
1011 itemsChanged
= NULL
;
1017 // we set it to NULL if there are many items changing state
1018 return itemsChanged
!= NULL
;
1021 void wxSelectionStore::OnItemDelete(size_t item
)
1023 size_t count
= m_itemsSel
.GetCount(),
1024 i
= m_itemsSel
.IndexForInsert(item
);
1026 if ( i
< count
&& m_itemsSel
[i
] == item
)
1028 // this item itself was in m_itemsSel, remove it from there
1029 m_itemsSel
.RemoveAt(i
);
1034 // and adjust the index of all which follow it
1037 // all following elements must be greater than the one we deleted
1038 wxASSERT_MSG( m_itemsSel
[i
] > item
, _T("logic error") );
1044 //-----------------------------------------------------------------------------
1046 //-----------------------------------------------------------------------------
1048 wxListItemData::~wxListItemData()
1050 // in the virtual list control the attributes are managed by the main
1051 // program, so don't delete them
1052 if ( !m_owner
->IsVirtual() )
1060 void wxListItemData::Init()
1068 wxListItemData::wxListItemData(wxListMainWindow
*owner
)
1074 if ( owner
->InReportView() )
1080 m_rect
= new wxRect
;
1084 void wxListItemData::SetItem( const wxListItem
&info
)
1086 if ( info
.m_mask
& wxLIST_MASK_TEXT
)
1087 SetText(info
.m_text
);
1088 if ( info
.m_mask
& wxLIST_MASK_IMAGE
)
1089 m_image
= info
.m_image
;
1090 if ( info
.m_mask
& wxLIST_MASK_DATA
)
1091 m_data
= info
.m_data
;
1093 if ( info
.HasAttributes() )
1096 *m_attr
= *info
.GetAttributes();
1098 m_attr
= new wxListItemAttr(*info
.GetAttributes());
1106 m_rect
->width
= info
.m_width
;
1110 void wxListItemData::SetPosition( int x
, int y
)
1112 wxCHECK_RET( m_rect
, _T("unexpected SetPosition() call") );
1118 void wxListItemData::SetSize( int width
, int height
)
1120 wxCHECK_RET( m_rect
, _T("unexpected SetSize() call") );
1123 m_rect
->width
= width
;
1125 m_rect
->height
= height
;
1128 bool wxListItemData::IsHit( int x
, int y
) const
1130 wxCHECK_MSG( m_rect
, FALSE
, _T("can't be called in this mode") );
1132 return wxRect(GetX(), GetY(), GetWidth(), GetHeight()).Inside(x
, y
);
1135 int wxListItemData::GetX() const
1137 wxCHECK_MSG( m_rect
, 0, _T("can't be called in this mode") );
1142 int wxListItemData::GetY() const
1144 wxCHECK_MSG( m_rect
, 0, _T("can't be called in this mode") );
1149 int wxListItemData::GetWidth() const
1151 wxCHECK_MSG( m_rect
, 0, _T("can't be called in this mode") );
1153 return m_rect
->width
;
1156 int wxListItemData::GetHeight() const
1158 wxCHECK_MSG( m_rect
, 0, _T("can't be called in this mode") );
1160 return m_rect
->height
;
1163 void wxListItemData::GetItem( wxListItem
&info
) const
1165 info
.m_text
= m_text
;
1166 info
.m_image
= m_image
;
1167 info
.m_data
= m_data
;
1171 if ( m_attr
->HasTextColour() )
1172 info
.SetTextColour(m_attr
->GetTextColour());
1173 if ( m_attr
->HasBackgroundColour() )
1174 info
.SetBackgroundColour(m_attr
->GetBackgroundColour());
1175 if ( m_attr
->HasFont() )
1176 info
.SetFont(m_attr
->GetFont());
1180 //-----------------------------------------------------------------------------
1182 //-----------------------------------------------------------------------------
1184 void wxListHeaderData::Init()
1195 wxListHeaderData::wxListHeaderData()
1200 wxListHeaderData::wxListHeaderData( const wxListItem
&item
)
1207 void wxListHeaderData::SetItem( const wxListItem
&item
)
1209 m_mask
= item
.m_mask
;
1211 if ( m_mask
& wxLIST_MASK_TEXT
)
1212 m_text
= item
.m_text
;
1214 if ( m_mask
& wxLIST_MASK_IMAGE
)
1215 m_image
= item
.m_image
;
1217 if ( m_mask
& wxLIST_MASK_FORMAT
)
1218 m_format
= item
.m_format
;
1220 if ( m_mask
& wxLIST_MASK_WIDTH
)
1221 SetWidth(item
.m_width
);
1224 void wxListHeaderData::SetPosition( int x
, int y
)
1230 void wxListHeaderData::SetHeight( int h
)
1235 void wxListHeaderData::SetWidth( int w
)
1239 m_width
= WIDTH_COL_DEFAULT
;
1240 else if (m_width
< WIDTH_COL_MIN
)
1241 m_width
= WIDTH_COL_MIN
;
1244 void wxListHeaderData::SetFormat( int format
)
1249 bool wxListHeaderData::HasImage() const
1251 return m_image
!= -1;
1254 bool wxListHeaderData::IsHit( int x
, int y
) const
1256 return ((x
>= m_xpos
) && (x
<= m_xpos
+m_width
) && (y
>= m_ypos
) && (y
<= m_ypos
+m_height
));
1259 void wxListHeaderData::GetItem( wxListItem
& item
)
1261 item
.m_mask
= m_mask
;
1262 item
.m_text
= m_text
;
1263 item
.m_image
= m_image
;
1264 item
.m_format
= m_format
;
1265 item
.m_width
= m_width
;
1268 int wxListHeaderData::GetImage() const
1273 int wxListHeaderData::GetWidth() const
1278 int wxListHeaderData::GetFormat() const
1283 //-----------------------------------------------------------------------------
1285 //-----------------------------------------------------------------------------
1287 inline int wxListLineData::GetMode() const
1289 return m_owner
->GetListCtrl()->GetWindowStyleFlag() & wxLC_MASK_TYPE
;
1292 inline bool wxListLineData::InReportView() const
1294 return m_owner
->HasFlag(wxLC_REPORT
);
1297 inline bool wxListLineData::IsVirtual() const
1299 return m_owner
->IsVirtual();
1302 wxListLineData::wxListLineData( wxListMainWindow
*owner
)
1305 m_items
.DeleteContents( TRUE
);
1307 if ( InReportView() )
1313 m_gi
= new GeometryInfo
;
1316 m_highlighted
= FALSE
;
1318 InitItems( GetMode() == wxLC_REPORT
? m_owner
->GetColumnCount() : 1 );
1321 void wxListLineData::CalculateSize( wxDC
*dc
, int spacing
)
1323 wxListItemDataList::Node
*node
= m_items
.GetFirst();
1324 wxCHECK_RET( node
, _T("no subitems at all??") );
1326 wxListItemData
*item
= node
->GetData();
1328 switch ( GetMode() )
1331 case wxLC_SMALL_ICON
:
1333 m_gi
->m_rectAll
.width
= spacing
;
1335 wxString s
= item
->GetText();
1341 m_gi
->m_rectLabel
.width
=
1342 m_gi
->m_rectLabel
.height
= 0;
1346 dc
->GetTextExtent( s
, &lw
, &lh
);
1347 if (lh
< SCROLL_UNIT_Y
)
1352 m_gi
->m_rectAll
.height
= spacing
+ lh
;
1354 m_gi
->m_rectAll
.width
= lw
;
1356 m_gi
->m_rectLabel
.width
= lw
;
1357 m_gi
->m_rectLabel
.height
= lh
;
1360 if (item
->HasImage())
1363 m_owner
->GetImageSize( item
->GetImage(), w
, h
);
1364 m_gi
->m_rectIcon
.width
= w
+ 8;
1365 m_gi
->m_rectIcon
.height
= h
+ 8;
1367 if ( m_gi
->m_rectIcon
.width
> m_gi
->m_rectAll
.width
)
1368 m_gi
->m_rectAll
.width
= m_gi
->m_rectIcon
.width
;
1369 if ( m_gi
->m_rectIcon
.height
+ lh
> m_gi
->m_rectAll
.height
- 4 )
1370 m_gi
->m_rectAll
.height
= m_gi
->m_rectIcon
.height
+ lh
+ 4;
1373 if ( item
->HasText() )
1375 m_gi
->m_rectHighlight
.width
= m_gi
->m_rectLabel
.width
;
1376 m_gi
->m_rectHighlight
.height
= m_gi
->m_rectLabel
.height
;
1378 else // no text, highlight the icon
1380 m_gi
->m_rectHighlight
.width
= m_gi
->m_rectIcon
.width
;
1381 m_gi
->m_rectHighlight
.height
= m_gi
->m_rectIcon
.height
;
1388 wxString s
= item
->GetTextForMeasuring();
1391 dc
->GetTextExtent( s
, &lw
, &lh
);
1392 if (lh
< SCROLL_UNIT_Y
)
1397 m_gi
->m_rectLabel
.width
= lw
;
1398 m_gi
->m_rectLabel
.height
= lh
;
1400 m_gi
->m_rectAll
.width
= lw
;
1401 m_gi
->m_rectAll
.height
= lh
;
1403 if (item
->HasImage())
1406 m_owner
->GetImageSize( item
->GetImage(), w
, h
);
1407 m_gi
->m_rectIcon
.width
= w
;
1408 m_gi
->m_rectIcon
.height
= h
;
1410 m_gi
->m_rectAll
.width
+= 4 + w
;
1411 if (h
> m_gi
->m_rectAll
.height
)
1412 m_gi
->m_rectAll
.height
= h
;
1415 m_gi
->m_rectHighlight
.width
= m_gi
->m_rectAll
.width
;
1416 m_gi
->m_rectHighlight
.height
= m_gi
->m_rectAll
.height
;
1421 wxFAIL_MSG( _T("unexpected call to SetSize") );
1425 wxFAIL_MSG( _T("unknown mode") );
1429 void wxListLineData::SetPosition( int x
, int y
,
1433 wxListItemDataList::Node
*node
= m_items
.GetFirst();
1434 wxCHECK_RET( node
, _T("no subitems at all??") );
1436 wxListItemData
*item
= node
->GetData();
1438 switch ( GetMode() )
1441 case wxLC_SMALL_ICON
:
1442 m_gi
->m_rectAll
.x
= x
;
1443 m_gi
->m_rectAll
.y
= y
;
1445 if ( item
->HasImage() )
1447 m_gi
->m_rectIcon
.x
= m_gi
->m_rectAll
.x
+ 4
1448 + (spacing
- m_gi
->m_rectIcon
.width
)/2;
1449 m_gi
->m_rectIcon
.y
= m_gi
->m_rectAll
.y
+ 4;
1452 if ( item
->HasText() )
1454 if (m_gi
->m_rectAll
.width
> spacing
)
1455 m_gi
->m_rectLabel
.x
= m_gi
->m_rectAll
.x
+ 2;
1457 m_gi
->m_rectLabel
.x
= m_gi
->m_rectAll
.x
+ 2 + (spacing
/2) - (m_gi
->m_rectLabel
.width
/2);
1458 m_gi
->m_rectLabel
.y
= m_gi
->m_rectAll
.y
+ m_gi
->m_rectAll
.height
+ 2 - m_gi
->m_rectLabel
.height
;
1459 m_gi
->m_rectHighlight
.x
= m_gi
->m_rectLabel
.x
- 2;
1460 m_gi
->m_rectHighlight
.y
= m_gi
->m_rectLabel
.y
- 2;
1462 else // no text, highlight the icon
1464 m_gi
->m_rectHighlight
.x
= m_gi
->m_rectIcon
.x
- 4;
1465 m_gi
->m_rectHighlight
.y
= m_gi
->m_rectIcon
.y
- 4;
1470 m_gi
->m_rectAll
.x
= x
;
1471 m_gi
->m_rectAll
.y
= y
;
1473 m_gi
->m_rectHighlight
.x
= m_gi
->m_rectAll
.x
;
1474 m_gi
->m_rectHighlight
.y
= m_gi
->m_rectAll
.y
;
1475 m_gi
->m_rectLabel
.y
= m_gi
->m_rectAll
.y
+ 2;
1477 if (item
->HasImage())
1479 m_gi
->m_rectIcon
.x
= m_gi
->m_rectAll
.x
+ 2;
1480 m_gi
->m_rectIcon
.y
= m_gi
->m_rectAll
.y
+ 2;
1481 m_gi
->m_rectLabel
.x
= m_gi
->m_rectAll
.x
+ 6 + m_gi
->m_rectIcon
.width
;
1485 m_gi
->m_rectLabel
.x
= m_gi
->m_rectAll
.x
+ 2;
1490 wxFAIL_MSG( _T("unexpected call to SetPosition") );
1494 wxFAIL_MSG( _T("unknown mode") );
1498 void wxListLineData::InitItems( int num
)
1500 for (int i
= 0; i
< num
; i
++)
1501 m_items
.Append( new wxListItemData(m_owner
) );
1504 void wxListLineData::SetItem( int index
, const wxListItem
&info
)
1506 wxListItemDataList::Node
*node
= m_items
.Item( index
);
1507 wxCHECK_RET( node
, _T("invalid column index in SetItem") );
1509 wxListItemData
*item
= node
->GetData();
1510 item
->SetItem( info
);
1513 void wxListLineData::GetItem( int index
, wxListItem
&info
)
1515 wxListItemDataList::Node
*node
= m_items
.Item( index
);
1518 wxListItemData
*item
= node
->GetData();
1519 item
->GetItem( info
);
1523 wxString
wxListLineData::GetText(int index
) const
1527 wxListItemDataList::Node
*node
= m_items
.Item( index
);
1530 wxListItemData
*item
= node
->GetData();
1531 s
= item
->GetText();
1537 void wxListLineData::SetText( int index
, const wxString s
)
1539 wxListItemDataList::Node
*node
= m_items
.Item( index
);
1542 wxListItemData
*item
= node
->GetData();
1547 void wxListLineData::SetImage( int index
, int image
)
1549 wxListItemDataList::Node
*node
= m_items
.Item( index
);
1550 wxCHECK_RET( node
, _T("invalid column index in SetImage()") );
1552 wxListItemData
*item
= node
->GetData();
1553 item
->SetImage(image
);
1556 int wxListLineData::GetImage( int index
) const
1558 wxListItemDataList::Node
*node
= m_items
.Item( index
);
1559 wxCHECK_MSG( node
, -1, _T("invalid column index in GetImage()") );
1561 wxListItemData
*item
= node
->GetData();
1562 return item
->GetImage();
1565 wxListItemAttr
*wxListLineData::GetAttr() const
1567 wxListItemDataList::Node
*node
= m_items
.GetFirst();
1568 wxCHECK_MSG( node
, NULL
, _T("invalid column index in GetAttr()") );
1570 wxListItemData
*item
= node
->GetData();
1571 return item
->GetAttr();
1574 void wxListLineData::SetAttr(wxListItemAttr
*attr
)
1576 wxListItemDataList::Node
*node
= m_items
.GetFirst();
1577 wxCHECK_RET( node
, _T("invalid column index in SetAttr()") );
1579 wxListItemData
*item
= node
->GetData();
1580 item
->SetAttr(attr
);
1583 bool wxListLineData::SetAttributes(wxDC
*dc
,
1584 const wxListItemAttr
*attr
,
1587 wxWindow
*listctrl
= m_owner
->GetParent();
1591 // don't use foreground colour for drawing highlighted items - this might
1592 // make them completely invisible (and there is no way to do bit
1593 // arithmetics on wxColour, unfortunately)
1597 colText
= wxSystemSettings::GetSystemColour(wxSYS_COLOUR_HIGHLIGHTTEXT
);
1601 if ( attr
&& attr
->HasTextColour() )
1603 colText
= attr
->GetTextColour();
1607 colText
= listctrl
->GetForegroundColour();
1611 dc
->SetTextForeground(colText
);
1615 if ( attr
&& attr
->HasFont() )
1617 font
= attr
->GetFont();
1621 font
= listctrl
->GetFont();
1627 bool hasBgCol
= attr
&& attr
->HasBackgroundColour();
1628 if ( highlighted
|| hasBgCol
)
1632 dc
->SetBrush( *m_owner
->GetHighlightBrush() );
1636 dc
->SetBrush(wxBrush(attr
->GetBackgroundColour(), wxSOLID
));
1639 dc
->SetPen( *wxTRANSPARENT_PEN
);
1647 void wxListLineData::Draw( wxDC
*dc
)
1649 wxListItemDataList::Node
*node
= m_items
.GetFirst();
1650 wxCHECK_RET( node
, _T("no subitems at all??") );
1652 bool highlighted
= IsHighlighted();
1654 wxListItemAttr
*attr
= GetAttr();
1656 if ( SetAttributes(dc
, attr
, highlighted
) )
1658 dc
->DrawRectangle( m_gi
->m_rectHighlight
);
1661 wxListItemData
*item
= node
->GetData();
1662 if (item
->HasImage())
1664 wxRect rectIcon
= m_gi
->m_rectIcon
;
1665 m_owner
->DrawImage( item
->GetImage(), dc
,
1666 rectIcon
.x
, rectIcon
.y
);
1669 if (item
->HasText())
1671 wxRect rectLabel
= m_gi
->m_rectLabel
;
1673 wxDCClipper
clipper(*dc
, rectLabel
);
1674 dc
->DrawText( item
->GetText(), rectLabel
.x
, rectLabel
.y
);
1678 void wxListLineData::DrawInReportMode( wxDC
*dc
,
1680 const wxRect
& rectHL
,
1683 // TODO: later we should support setting different attributes for
1684 // different columns - to do it, just add "col" argument to
1685 // GetAttr() and move these lines into the loop below
1686 wxListItemAttr
*attr
= GetAttr();
1687 if ( SetAttributes(dc
, attr
, highlighted
) )
1689 dc
->DrawRectangle( rectHL
);
1692 wxListItemDataList::Node
*node
= m_items
.GetFirst();
1693 wxCHECK_RET( node
, _T("no subitems at all??") );
1696 wxCoord x
= rect
.x
+ HEADER_OFFSET_X
,
1697 y
= rect
.y
+ (LINE_SPACING
+ EXTRA_HEIGHT
) / 2;
1701 wxListItemData
*item
= node
->GetData();
1703 int width
= m_owner
->GetColumnWidth(col
++);
1707 if ( item
->HasImage() )
1710 m_owner
->DrawImage( item
->GetImage(), dc
, xOld
, y
);
1711 m_owner
->GetImageSize( item
->GetImage(), ix
, iy
);
1713 ix
+= IMAGE_MARGIN_IN_REPORT_MODE
;
1719 wxDCClipper
clipper(*dc
, xOld
, y
, width
, rect
.height
);
1721 if ( item
->HasText() )
1723 dc
->DrawText( item
->GetText(), xOld
, y
);
1726 node
= node
->GetNext();
1730 bool wxListLineData::Highlight( bool on
)
1732 wxCHECK_MSG( !m_owner
->IsVirtual(), FALSE
, _T("unexpected call to Highlight") );
1734 if ( on
== m_highlighted
)
1742 void wxListLineData::ReverseHighlight( void )
1744 Highlight(!IsHighlighted());
1747 //-----------------------------------------------------------------------------
1748 // wxListHeaderWindow
1749 //-----------------------------------------------------------------------------
1751 IMPLEMENT_DYNAMIC_CLASS(wxListHeaderWindow
,wxWindow
);
1753 BEGIN_EVENT_TABLE(wxListHeaderWindow
,wxWindow
)
1754 EVT_PAINT (wxListHeaderWindow::OnPaint
)
1755 EVT_MOUSE_EVENTS (wxListHeaderWindow::OnMouse
)
1756 EVT_SET_FOCUS (wxListHeaderWindow::OnSetFocus
)
1759 void wxListHeaderWindow::Init()
1761 m_currentCursor
= (wxCursor
*) NULL
;
1762 m_isDragging
= FALSE
;
1766 wxListHeaderWindow::wxListHeaderWindow()
1770 m_owner
= (wxListMainWindow
*) NULL
;
1771 m_resizeCursor
= (wxCursor
*) NULL
;
1774 wxListHeaderWindow::wxListHeaderWindow( wxWindow
*win
,
1776 wxListMainWindow
*owner
,
1780 const wxString
&name
)
1781 : wxWindow( win
, id
, pos
, size
, style
, name
)
1786 m_resizeCursor
= new wxCursor( wxCURSOR_SIZEWE
);
1788 SetBackgroundColour( wxSystemSettings::GetSystemColour( wxSYS_COLOUR_BTNFACE
) );
1791 wxListHeaderWindow::~wxListHeaderWindow()
1793 delete m_resizeCursor
;
1796 void wxListHeaderWindow::DoDrawRect( wxDC
*dc
, int x
, int y
, int w
, int h
)
1799 GtkStateType state
= m_parent
->IsEnabled() ? GTK_STATE_NORMAL
1800 : GTK_STATE_INSENSITIVE
;
1802 x
= dc
->XLOG2DEV( x
);
1804 gtk_paint_box (m_wxwindow
->style
, GTK_PIZZA(m_wxwindow
)->bin_window
,
1805 state
, GTK_SHADOW_OUT
,
1806 (GdkRectangle
*) NULL
, m_wxwindow
, "button",
1807 x
-1, y
-1, w
+2, h
+2);
1808 #elif defined( __WXMAC__ )
1809 const int m_corner
= 1;
1811 dc
->SetBrush( *wxTRANSPARENT_BRUSH
);
1813 dc
->SetPen( wxPen( wxSystemSettings::GetSystemColour( wxSYS_COLOUR_BTNSHADOW
) , 1 , wxSOLID
) );
1814 dc
->DrawLine( x
+w
-m_corner
+1, y
, x
+w
, y
+h
); // right (outer)
1815 dc
->DrawRectangle( x
, y
+h
, w
+1, 1 ); // bottom (outer)
1817 wxPen
pen( wxColour( 0x88 , 0x88 , 0x88 ), 1, wxSOLID
);
1820 dc
->DrawLine( x
+w
-m_corner
, y
, x
+w
-1, y
+h
); // right (inner)
1821 dc
->DrawRectangle( x
+1, y
+h
-1, w
-2, 1 ); // bottom (inner)
1823 dc
->SetPen( *wxWHITE_PEN
);
1824 dc
->DrawRectangle( x
, y
, w
-m_corner
+1, 1 ); // top (outer)
1825 dc
->DrawRectangle( x
, y
, 1, h
); // left (outer)
1826 dc
->DrawLine( x
, y
+h
-1, x
+1, y
+h
-1 );
1827 dc
->DrawLine( x
+w
-1, y
, x
+w
-1, y
+1 );
1829 const int m_corner
= 1;
1831 dc
->SetBrush( *wxTRANSPARENT_BRUSH
);
1833 dc
->SetPen( *wxBLACK_PEN
);
1834 dc
->DrawLine( x
+w
-m_corner
+1, y
, x
+w
, y
+h
); // right (outer)
1835 dc
->DrawRectangle( x
, y
+h
, w
+1, 1 ); // bottom (outer)
1837 wxPen
pen( wxSystemSettings::GetSystemColour( wxSYS_COLOUR_BTNSHADOW
), 1, wxSOLID
);
1840 dc
->DrawLine( x
+w
-m_corner
, y
, x
+w
-1, y
+h
); // right (inner)
1841 dc
->DrawRectangle( x
+1, y
+h
-1, w
-2, 1 ); // bottom (inner)
1843 dc
->SetPen( *wxWHITE_PEN
);
1844 dc
->DrawRectangle( x
, y
, w
-m_corner
+1, 1 ); // top (outer)
1845 dc
->DrawRectangle( x
, y
, 1, h
); // left (outer)
1846 dc
->DrawLine( x
, y
+h
-1, x
+1, y
+h
-1 );
1847 dc
->DrawLine( x
+w
-1, y
, x
+w
-1, y
+1 );
1851 // shift the DC origin to match the position of the main window horz
1852 // scrollbar: this allows us to always use logical coords
1853 void wxListHeaderWindow::AdjustDC(wxDC
& dc
)
1856 m_owner
->GetScrollPixelsPerUnit( &xpix
, NULL
);
1859 m_owner
->GetViewStart( &x
, NULL
);
1861 // account for the horz scrollbar offset
1862 dc
.SetDeviceOrigin( -x
* xpix
, 0 );
1865 void wxListHeaderWindow::OnPaint( wxPaintEvent
&WXUNUSED(event
) )
1868 wxClientDC
dc( this );
1870 wxPaintDC
dc( this );
1878 dc
.SetFont( GetFont() );
1880 // width and height of the entire header window
1882 GetClientSize( &w
, &h
);
1883 m_owner
->CalcUnscrolledPosition(w
, 0, &w
, NULL
);
1885 dc
.SetBackgroundMode(wxTRANSPARENT
);
1887 // do *not* use the listctrl colour for headers - one day we will have a
1888 // function to set it separately
1889 //dc.SetTextForeground( *wxBLACK );
1890 dc
.SetTextForeground(wxSystemSettings::
1891 GetSystemColour( wxSYS_COLOUR_WINDOWTEXT
));
1893 int x
= HEADER_OFFSET_X
;
1895 int numColumns
= m_owner
->GetColumnCount();
1897 for ( int i
= 0; i
< numColumns
&& x
< w
; i
++ )
1899 m_owner
->GetColumn( i
, item
);
1900 int wCol
= item
.m_width
;
1902 // the width of the rect to draw: make it smaller to fit entirely
1903 // inside the column rect
1906 dc
.SetPen( *wxWHITE_PEN
);
1908 DoDrawRect( &dc
, x
, HEADER_OFFSET_Y
, cw
, h
-2 );
1910 // if we have an image, draw it on the right of the label
1911 int image
= item
.m_image
;
1914 wxImageList
*imageList
= m_owner
->m_small_image_list
;
1918 imageList
->GetSize(image
, ix
, iy
);
1925 HEADER_OFFSET_Y
+ (h
- 4 - iy
)/2,
1926 wxIMAGELIST_DRAW_TRANSPARENT
1931 //else: ignore the column image
1934 // draw the text clipping it so that it doesn't overwrite the column
1936 wxDCClipper
clipper(dc
, x
, HEADER_OFFSET_Y
, cw
, h
- 4 );
1938 dc
.DrawText( item
.GetText(),
1939 x
+ EXTRA_WIDTH
, HEADER_OFFSET_Y
+ EXTRA_HEIGHT
);
1947 void wxListHeaderWindow::DrawCurrent()
1949 int x1
= m_currentX
;
1951 ClientToScreen( &x1
, &y1
);
1953 int x2
= m_currentX
-1;
1955 m_owner
->GetClientSize( NULL
, &y2
);
1956 m_owner
->ClientToScreen( &x2
, &y2
);
1959 dc
.SetLogicalFunction( wxINVERT
);
1960 dc
.SetPen( wxPen( *wxBLACK
, 2, wxSOLID
) );
1961 dc
.SetBrush( *wxTRANSPARENT_BRUSH
);
1965 dc
.DrawLine( x1
, y1
, x2
, y2
);
1967 dc
.SetLogicalFunction( wxCOPY
);
1969 dc
.SetPen( wxNullPen
);
1970 dc
.SetBrush( wxNullBrush
);
1973 void wxListHeaderWindow::OnMouse( wxMouseEvent
&event
)
1975 // we want to work with logical coords
1977 m_owner
->CalcUnscrolledPosition(event
.GetX(), 0, &x
, NULL
);
1978 int y
= event
.GetY();
1982 // we don't draw the line beyond our window, but we allow dragging it
1985 GetClientSize( &w
, NULL
);
1986 m_owner
->CalcUnscrolledPosition(w
, 0, &w
, NULL
);
1989 // erase the line if it was drawn
1990 if ( m_currentX
< w
)
1993 if (event
.ButtonUp())
1996 m_isDragging
= FALSE
;
1998 m_owner
->SetColumnWidth( m_column
, m_currentX
- m_minX
);
2005 m_currentX
= m_minX
+ 7;
2007 // draw in the new location
2008 if ( m_currentX
< w
)
2012 else // not dragging
2015 bool hit_border
= FALSE
;
2017 // end of the current column
2020 // find the column where this event occured
2021 int countCol
= m_owner
->GetColumnCount();
2022 for (int col
= 0; col
< countCol
; col
++)
2024 xpos
+= m_owner
->GetColumnWidth( col
);
2027 if ( (abs(x
-xpos
) < 3) && (y
< 22) )
2029 // near the column border
2036 // inside the column
2043 if (event
.LeftDown() || event
.RightUp())
2045 if (hit_border
&& event
.LeftDown())
2047 m_isDragging
= TRUE
;
2052 else // click on a column
2054 wxWindow
*parent
= GetParent();
2055 wxListEvent
le( event
.LeftDown()
2056 ? wxEVT_COMMAND_LIST_COL_CLICK
2057 : wxEVT_COMMAND_LIST_COL_RIGHT_CLICK
,
2059 le
.SetEventObject( parent
);
2060 le
.m_pointDrag
= event
.GetPosition();
2062 // the position should be relative to the parent window, not
2063 // this one for compatibility with MSW and common sense: the
2064 // user code doesn't know anything at all about this header
2065 // window, so why should it get positions relative to it?
2066 le
.m_pointDrag
.y
-= GetSize().y
;
2068 le
.m_col
= m_column
;
2069 parent
->GetEventHandler()->ProcessEvent( le
);
2072 else if (event
.Moving())
2077 setCursor
= m_currentCursor
== wxSTANDARD_CURSOR
;
2078 m_currentCursor
= m_resizeCursor
;
2082 setCursor
= m_currentCursor
!= wxSTANDARD_CURSOR
;
2083 m_currentCursor
= wxSTANDARD_CURSOR
;
2087 SetCursor(*m_currentCursor
);
2092 void wxListHeaderWindow::OnSetFocus( wxFocusEvent
&WXUNUSED(event
) )
2094 m_owner
->SetFocus();
2097 //-----------------------------------------------------------------------------
2098 // wxListRenameTimer (internal)
2099 //-----------------------------------------------------------------------------
2101 wxListRenameTimer::wxListRenameTimer( wxListMainWindow
*owner
)
2106 void wxListRenameTimer::Notify()
2108 m_owner
->OnRenameTimer();
2111 //-----------------------------------------------------------------------------
2112 // wxListTextCtrl (internal)
2113 //-----------------------------------------------------------------------------
2115 IMPLEMENT_DYNAMIC_CLASS(wxListTextCtrl
,wxTextCtrl
);
2117 BEGIN_EVENT_TABLE(wxListTextCtrl
,wxTextCtrl
)
2118 EVT_CHAR (wxListTextCtrl::OnChar
)
2119 EVT_KEY_UP (wxListTextCtrl::OnKeyUp
)
2120 EVT_KILL_FOCUS (wxListTextCtrl::OnKillFocus
)
2123 wxListTextCtrl::wxListTextCtrl( wxWindow
*parent
,
2124 const wxWindowID id
,
2127 wxListMainWindow
*owner
,
2128 const wxString
&value
,
2132 const wxValidator
& validator
,
2133 const wxString
&name
)
2134 : wxTextCtrl( parent
, id
, value
, pos
, size
, style
, validator
, name
)
2139 (*m_accept
) = FALSE
;
2141 m_startValue
= value
;
2144 void wxListTextCtrl::OnChar( wxKeyEvent
&event
)
2146 if (event
.m_keyCode
== WXK_RETURN
)
2149 (*m_res
) = GetValue();
2151 if (!wxPendingDelete
.Member(this))
2152 wxPendingDelete
.Append(this);
2154 if ((*m_accept
) && ((*m_res
) != m_startValue
))
2155 m_owner
->OnRenameAccept();
2159 if (event
.m_keyCode
== WXK_ESCAPE
)
2161 (*m_accept
) = FALSE
;
2164 if (!wxPendingDelete
.Member(this))
2165 wxPendingDelete
.Append(this);
2173 void wxListTextCtrl::OnKeyUp( wxKeyEvent
&event
)
2175 // auto-grow the textctrl:
2176 wxSize parentSize
= m_owner
->GetSize();
2177 wxPoint myPos
= GetPosition();
2178 wxSize mySize
= GetSize();
2180 GetTextExtent(GetValue() + _T("MM"), &sx
, &sy
); // FIXME: MM??
2181 if (myPos
.x
+ sx
> parentSize
.x
)
2182 sx
= parentSize
.x
- myPos
.x
;
2190 void wxListTextCtrl::OnKillFocus( wxFocusEvent
&WXUNUSED(event
) )
2192 if (!wxPendingDelete
.Member(this))
2193 wxPendingDelete
.Append(this);
2195 if ((*m_accept
) && ((*m_res
) != m_startValue
))
2196 m_owner
->OnRenameAccept();
2199 //-----------------------------------------------------------------------------
2201 //-----------------------------------------------------------------------------
2203 IMPLEMENT_DYNAMIC_CLASS(wxListMainWindow
,wxScrolledWindow
);
2205 BEGIN_EVENT_TABLE(wxListMainWindow
,wxScrolledWindow
)
2206 EVT_PAINT (wxListMainWindow::OnPaint
)
2207 EVT_MOUSE_EVENTS (wxListMainWindow::OnMouse
)
2208 EVT_CHAR (wxListMainWindow::OnChar
)
2209 EVT_KEY_DOWN (wxListMainWindow::OnKeyDown
)
2210 EVT_SET_FOCUS (wxListMainWindow::OnSetFocus
)
2211 EVT_KILL_FOCUS (wxListMainWindow::OnKillFocus
)
2212 EVT_SCROLLWIN (wxListMainWindow::OnScroll
)
2215 void wxListMainWindow::Init()
2217 m_columns
.DeleteContents( TRUE
);
2221 m_lineTo
= (size_t)-1;
2227 m_small_image_list
= (wxImageList
*) NULL
;
2228 m_normal_image_list
= (wxImageList
*) NULL
;
2230 m_small_spacing
= 30;
2231 m_normal_spacing
= 40;
2235 m_isCreated
= FALSE
;
2237 m_lastOnSame
= FALSE
;
2238 m_renameTimer
= new wxListRenameTimer( this );
2239 m_renameAccept
= FALSE
;
2244 m_lineBeforeLastClicked
= (size_t)-1;
2249 void wxListMainWindow::InitScrolling()
2251 if ( HasFlag(wxLC_REPORT
) )
2253 m_xScroll
= SCROLL_UNIT_X
;
2254 m_yScroll
= SCROLL_UNIT_Y
;
2258 m_xScroll
= SCROLL_UNIT_Y
;
2263 wxListMainWindow::wxListMainWindow()
2268 m_highlightUnfocusedBrush
= (wxBrush
*) NULL
;
2274 wxListMainWindow::wxListMainWindow( wxWindow
*parent
,
2279 const wxString
&name
)
2280 : wxScrolledWindow( parent
, id
, pos
, size
,
2281 style
| wxHSCROLL
| wxVSCROLL
, name
)
2285 m_highlightBrush
= new wxBrush
2287 wxSystemSettings::GetSystemColour
2289 wxSYS_COLOUR_HIGHLIGHT
2294 m_highlightUnfocusedBrush
= new wxBrush
2296 wxSystemSettings::GetSystemColour
2298 wxSYS_COLOUR_BTNSHADOW
2307 SetScrollbars( m_xScroll
, m_yScroll
, 0, 0, 0, 0 );
2309 SetBackgroundColour( wxSystemSettings::GetSystemColour( wxSYS_COLOUR_LISTBOX
) );
2312 wxListMainWindow::~wxListMainWindow()
2316 delete m_highlightBrush
;
2317 delete m_highlightUnfocusedBrush
;
2319 delete m_renameTimer
;
2322 void wxListMainWindow::CacheLineData(size_t line
)
2324 wxListCtrl
*listctrl
= GetListCtrl();
2326 wxListLineData
*ld
= GetDummyLine();
2328 size_t countCol
= GetColumnCount();
2329 for ( size_t col
= 0; col
< countCol
; col
++ )
2331 ld
->SetText(col
, listctrl
->OnGetItemText(line
, col
));
2334 ld
->SetImage(listctrl
->OnGetItemImage(line
));
2335 ld
->SetAttr(listctrl
->OnGetItemAttr(line
));
2338 wxListLineData
*wxListMainWindow::GetDummyLine() const
2340 wxASSERT_MSG( !IsEmpty(), _T("invalid line index") );
2342 if ( m_lines
.IsEmpty() )
2344 // normal controls are supposed to have something in m_lines
2345 // already if it's not empty
2346 wxASSERT_MSG( IsVirtual(), _T("logic error") );
2348 wxListMainWindow
*self
= wxConstCast(this, wxListMainWindow
);
2349 wxListLineData
*line
= new wxListLineData(self
);
2350 self
->m_lines
.Add(line
);
2356 // ----------------------------------------------------------------------------
2357 // line geometry (report mode only)
2358 // ----------------------------------------------------------------------------
2360 wxCoord
wxListMainWindow::GetLineHeight() const
2362 wxASSERT_MSG( HasFlag(wxLC_REPORT
), _T("only works in report mode") );
2364 // we cache the line height as calling GetTextExtent() is slow
2365 if ( !m_lineHeight
)
2367 wxListMainWindow
*self
= wxConstCast(this, wxListMainWindow
);
2369 wxClientDC
dc( self
);
2370 dc
.SetFont( GetFont() );
2373 dc
.GetTextExtent(_T("H"), NULL
, &y
);
2375 if ( y
< SCROLL_UNIT_Y
)
2379 self
->m_lineHeight
= y
+ LINE_SPACING
;
2382 return m_lineHeight
;
2385 wxCoord
wxListMainWindow::GetLineY(size_t line
) const
2387 wxASSERT_MSG( HasFlag(wxLC_REPORT
), _T("only works in report mode") );
2389 return LINE_SPACING
+ line
*GetLineHeight();
2392 wxRect
wxListMainWindow::GetLineRect(size_t line
) const
2394 if ( !InReportView() )
2395 return GetLine(line
)->m_gi
->m_rectAll
;
2398 rect
.x
= HEADER_OFFSET_X
;
2399 rect
.y
= GetLineY(line
);
2400 rect
.width
= GetHeaderWidth();
2401 rect
.height
= GetLineHeight();
2406 wxRect
wxListMainWindow::GetLineLabelRect(size_t line
) const
2408 if ( !InReportView() )
2409 return GetLine(line
)->m_gi
->m_rectLabel
;
2412 rect
.x
= HEADER_OFFSET_X
;
2413 rect
.y
= GetLineY(line
);
2414 rect
.width
= GetColumnWidth(0);
2415 rect
.height
= GetLineHeight();
2420 wxRect
wxListMainWindow::GetLineIconRect(size_t line
) const
2422 if ( !InReportView() )
2423 return GetLine(line
)->m_gi
->m_rectIcon
;
2425 wxListLineData
*ld
= GetLine(line
);
2426 wxASSERT_MSG( ld
->HasImage(), _T("should have an image") );
2429 rect
.x
= HEADER_OFFSET_X
;
2430 rect
.y
= GetLineY(line
);
2431 GetImageSize(ld
->GetImage(), rect
.width
, rect
.height
);
2436 wxRect
wxListMainWindow::GetLineHighlightRect(size_t line
) const
2438 return InReportView() ? GetLineRect(line
)
2439 : GetLine(line
)->m_gi
->m_rectHighlight
;
2442 long wxListMainWindow::HitTestLine(size_t line
, int x
, int y
) const
2444 wxASSERT_MSG( line
< GetItemCount(), _T("invalid line in HitTestLine") );
2446 wxListLineData
*ld
= GetLine(line
);
2448 if ( ld
->HasImage() && GetLineIconRect(line
).Inside(x
, y
) )
2449 return wxLIST_HITTEST_ONITEMICON
;
2451 if ( ld
->HasText() )
2453 wxRect rect
= InReportView() ? GetLineRect(line
)
2454 : GetLineLabelRect(line
);
2456 if ( rect
.Inside(x
, y
) )
2457 return wxLIST_HITTEST_ONITEMLABEL
;
2463 // ----------------------------------------------------------------------------
2464 // highlight (selection) handling
2465 // ----------------------------------------------------------------------------
2467 bool wxListMainWindow::IsHighlighted(size_t line
) const
2471 return m_selStore
.IsSelected(line
);
2475 wxListLineData
*ld
= GetLine(line
);
2476 wxCHECK_MSG( ld
, FALSE
, _T("invalid index in IsHighlighted") );
2478 return ld
->IsHighlighted();
2482 void wxListMainWindow::HighlightLines( size_t lineFrom
,
2488 wxArrayInt linesChanged
;
2489 if ( !m_selStore
.SelectRange(lineFrom
, lineTo
, highlight
,
2492 // meny items changed state, refresh everything
2493 RefreshLines(lineFrom
, lineTo
);
2495 else // only a few items changed state, refresh only them
2497 size_t count
= linesChanged
.GetCount();
2498 for ( size_t n
= 0; n
< count
; n
++ )
2500 RefreshLine(linesChanged
[n
]);
2504 else // iterate over all items in non report view
2506 for ( size_t line
= lineFrom
; line
<= lineTo
; line
++ )
2508 if ( HighlightLine(line
, highlight
) )
2516 bool wxListMainWindow::HighlightLine( size_t line
, bool highlight
)
2522 changed
= m_selStore
.SelectItem(line
, highlight
);
2526 wxListLineData
*ld
= GetLine(line
);
2527 wxCHECK_MSG( ld
, FALSE
, _T("invalid index in HighlightLine") );
2529 changed
= ld
->Highlight(highlight
);
2534 SendNotify( line
, highlight
? wxEVT_COMMAND_LIST_ITEM_SELECTED
2535 : wxEVT_COMMAND_LIST_ITEM_DESELECTED
);
2541 void wxListMainWindow::RefreshLine( size_t line
)
2543 if ( HasFlag(wxLC_REPORT
) )
2545 size_t visibleFrom
, visibleTo
;
2546 GetVisibleLinesRange(&visibleFrom
, &visibleTo
);
2548 if ( line
< visibleFrom
|| line
> visibleTo
)
2552 wxRect rect
= GetLineRect(line
);
2554 CalcScrolledPosition( rect
.x
, rect
.y
, &rect
.x
, &rect
.y
);
2555 RefreshRect( rect
);
2558 void wxListMainWindow::RefreshLines( size_t lineFrom
, size_t lineTo
)
2560 // we suppose that they are ordered by caller
2561 wxASSERT_MSG( lineFrom
<= lineTo
, _T("indices in disorder") );
2563 wxASSERT_MSG( lineTo
< GetItemCount(), _T("invalid line range") );
2565 if ( HasFlag(wxLC_REPORT
) )
2567 size_t visibleFrom
, visibleTo
;
2568 GetVisibleLinesRange(&visibleFrom
, &visibleTo
);
2570 if ( lineFrom
< visibleFrom
)
2571 lineFrom
= visibleFrom
;
2572 if ( lineTo
> visibleTo
)
2577 rect
.y
= GetLineY(lineFrom
);
2578 rect
.width
= GetClientSize().x
;
2579 rect
.height
= GetLineY(lineTo
) - rect
.y
+ GetLineHeight();
2581 CalcScrolledPosition( rect
.x
, rect
.y
, &rect
.x
, &rect
.y
);
2582 RefreshRect( rect
);
2586 // TODO: this should be optimized...
2587 for ( size_t line
= lineFrom
; line
<= lineTo
; line
++ )
2594 void wxListMainWindow::RefreshAfter( size_t lineFrom
)
2596 if ( HasFlag(wxLC_REPORT
) )
2599 GetVisibleLinesRange(&visibleFrom
, NULL
);
2601 if ( lineFrom
< visibleFrom
)
2602 lineFrom
= visibleFrom
;
2606 rect
.y
= GetLineY(lineFrom
);
2608 wxSize size
= GetClientSize();
2609 rect
.width
= size
.x
;
2610 // refresh till the bottom of the window
2611 rect
.height
= size
.y
- rect
.y
;
2613 CalcScrolledPosition( rect
.x
, rect
.y
, &rect
.x
, &rect
.y
);
2614 RefreshRect( rect
);
2618 // TODO: how to do it more efficiently?
2623 void wxListMainWindow::RefreshSelected()
2629 if ( InReportView() )
2631 GetVisibleLinesRange(&from
, &to
);
2636 to
= GetItemCount() - 1;
2639 // VZ: this code would work fine if wxGTK wxWindow::Refresh() were
2640 // reasonable, i.e. if it only generated one expose event for
2641 // several calls to it - as it is, each Refresh() results in a
2642 // repaint which provokes flicker too horrible to be seen
2644 // when/if wxGTK is fixed, this code should be restored as normally it
2645 // should generate _less_ flicker than the version below
2647 if ( HasCurrent() && m_current
>= from
&& m_current
<= to
)
2649 RefreshLine(m_current
);
2652 for ( size_t line
= from
; line
<= to
; line
++ )
2654 // NB: the test works as expected even if m_current == -1
2655 if ( line
!= m_current
&& IsHighlighted(line
) )
2661 size_t selMin
= (size_t)-1,
2664 for ( size_t line
= from
; line
<= to
; line
++ )
2666 if ( IsHighlighted(line
) || (line
== m_current
) )
2668 if ( line
< selMin
)
2670 if ( line
> selMax
)
2675 if ( selMin
!= (size_t)-1 )
2677 RefreshLines(selMin
, selMax
);
2679 #endif // !__WXGTK__/__WXGTK__
2682 void wxListMainWindow::Freeze()
2687 void wxListMainWindow::Thaw()
2689 wxCHECK_RET( m_freezeCount
> 0, _T("thawing unfrozen list control?") );
2691 if ( !--m_freezeCount
)
2697 void wxListMainWindow::OnPaint( wxPaintEvent
&WXUNUSED(event
) )
2699 // Note: a wxPaintDC must be constructed even if no drawing is
2700 // done (a Windows requirement).
2701 wxPaintDC
dc( this );
2703 if ( IsEmpty() || m_freezeCount
)
2705 // nothing to draw or not the moment to draw it
2711 // delay the repainting until we calculate all the items positions
2718 CalcScrolledPosition( 0, 0, &dev_x
, &dev_y
);
2722 dc
.SetFont( GetFont() );
2724 if ( HasFlag(wxLC_REPORT
) )
2726 int lineHeight
= GetLineHeight();
2728 size_t visibleFrom
, visibleTo
;
2729 GetVisibleLinesRange(&visibleFrom
, &visibleTo
);
2732 wxCoord xOrig
, yOrig
;
2733 CalcUnscrolledPosition(0, 0, &xOrig
, &yOrig
);
2735 // tell the caller cache to cache the data
2738 wxListEvent
evCache(wxEVT_COMMAND_LIST_CACHE_HINT
,
2739 GetParent()->GetId());
2740 evCache
.SetEventObject( GetParent() );
2741 evCache
.m_oldItemIndex
= visibleFrom
;
2742 evCache
.m_itemIndex
= visibleTo
;
2743 GetParent()->GetEventHandler()->ProcessEvent( evCache
);
2746 for ( size_t line
= visibleFrom
; line
<= visibleTo
; line
++ )
2748 rectLine
= GetLineRect(line
);
2750 if ( !IsExposed(rectLine
.x
- xOrig
, rectLine
.y
- yOrig
,
2751 rectLine
.width
, rectLine
.height
) )
2753 // don't redraw unaffected lines to avoid flicker
2757 GetLine(line
)->DrawInReportMode( &dc
,
2759 GetLineHighlightRect(line
),
2760 IsHighlighted(line
) );
2763 if ( HasFlag(wxLC_HRULES
) )
2765 wxPen
pen(GetRuleColour(), 1, wxSOLID
);
2766 wxSize clientSize
= GetClientSize();
2768 for ( size_t i
= visibleFrom
; i
<= visibleTo
; i
++ )
2771 dc
.SetBrush( *wxTRANSPARENT_BRUSH
);
2772 dc
.DrawLine(0 - dev_x
, i
*lineHeight
,
2773 clientSize
.x
- dev_x
, i
*lineHeight
);
2776 // Draw last horizontal rule
2777 if ( visibleTo
> visibleFrom
)
2780 dc
.SetBrush( *wxTRANSPARENT_BRUSH
);
2781 dc
.DrawLine(0 - dev_x
, m_lineTo
*lineHeight
,
2782 clientSize
.x
- dev_x
, m_lineTo
*lineHeight
);
2786 // Draw vertical rules if required
2787 if ( HasFlag(wxLC_VRULES
) && !IsEmpty() )
2789 wxPen
pen(GetRuleColour(), 1, wxSOLID
);
2792 wxRect firstItemRect
;
2793 wxRect lastItemRect
;
2794 GetItemRect(0, firstItemRect
);
2795 GetItemRect(GetItemCount() - 1, lastItemRect
);
2796 int x
= firstItemRect
.GetX();
2798 dc
.SetBrush(* wxTRANSPARENT_BRUSH
);
2799 for (col
= 0; col
< GetColumnCount(); col
++)
2801 int colWidth
= GetColumnWidth(col
);
2803 dc
.DrawLine(x
- dev_x
, firstItemRect
.GetY() - 1 - dev_y
,
2804 x
- dev_x
, lastItemRect
.GetBottom() + 1 - dev_y
);
2810 size_t count
= GetItemCount();
2811 for ( size_t i
= 0; i
< count
; i
++ )
2813 GetLine(i
)->Draw( &dc
);
2819 // don't draw rect outline under Max if we already have the background
2820 // color but under other platforms only draw it if we do: it is a bit
2821 // silly to draw "focus rect" if we don't have focus!
2826 #endif // __WXMAC__/!__WXMAC__
2828 dc
.SetPen( *wxBLACK_PEN
);
2829 dc
.SetBrush( *wxTRANSPARENT_BRUSH
);
2830 dc
.DrawRectangle( GetLineHighlightRect(m_current
) );
2837 void wxListMainWindow::HighlightAll( bool on
)
2839 if ( IsSingleSel() )
2841 wxASSERT_MSG( !on
, _T("can't do this in a single sel control") );
2843 // we just have one item to turn off
2844 if ( HasCurrent() && IsHighlighted(m_current
) )
2846 HighlightLine(m_current
, FALSE
);
2847 RefreshLine(m_current
);
2852 HighlightLines(0, GetItemCount() - 1, on
);
2856 void wxListMainWindow::SendNotify( size_t line
,
2857 wxEventType command
,
2860 wxListEvent
le( command
, GetParent()->GetId() );
2861 le
.SetEventObject( GetParent() );
2862 le
.m_itemIndex
= line
;
2864 // set only for events which have position
2865 if ( point
!= wxDefaultPosition
)
2866 le
.m_pointDrag
= point
;
2868 // don't try to get the line info for virtual list controls: the main
2869 // program has it anyhow and if we did it would result in accessing all
2870 // the lines, even those which are not visible now and this is precisely
2871 // what we're trying to avoid
2872 if ( !IsVirtual() && (command
!= wxEVT_COMMAND_LIST_DELETE_ITEM
) )
2874 if ( line
!= (size_t)-1 )
2876 GetLine(line
)->GetItem( 0, le
.m_item
);
2878 //else: this happens for wxEVT_COMMAND_LIST_ITEM_FOCUSED event
2880 //else: there may be no more such item
2882 GetParent()->GetEventHandler()->ProcessEvent( le
);
2885 void wxListMainWindow::ChangeCurrent(size_t current
)
2887 m_current
= current
;
2889 SendNotify(current
, wxEVT_COMMAND_LIST_ITEM_FOCUSED
);
2892 void wxListMainWindow::EditLabel( long item
)
2894 wxCHECK_RET( (item
>= 0) && ((size_t)item
< GetItemCount()),
2895 wxT("wrong index in wxListCtrl::EditLabel()") );
2897 m_currentEdit
= (size_t)item
;
2899 wxListEvent
le( wxEVT_COMMAND_LIST_BEGIN_LABEL_EDIT
, GetParent()->GetId() );
2900 le
.SetEventObject( GetParent() );
2901 le
.m_itemIndex
= item
;
2902 wxListLineData
*data
= GetLine(m_currentEdit
);
2903 wxCHECK_RET( data
, _T("invalid index in EditLabel()") );
2904 data
->GetItem( 0, le
.m_item
);
2905 GetParent()->GetEventHandler()->ProcessEvent( le
);
2907 if (!le
.IsAllowed())
2910 // We have to call this here because the label in question might just have
2911 // been added and no screen update taken place.
2915 wxClientDC
dc(this);
2918 wxString s
= data
->GetText(0);
2919 wxRect rectLabel
= GetLineLabelRect(m_currentEdit
);
2921 rectLabel
.x
= dc
.LogicalToDeviceX( rectLabel
.x
);
2922 rectLabel
.y
= dc
.LogicalToDeviceY( rectLabel
.y
);
2924 wxListTextCtrl
*text
= new wxListTextCtrl
2931 wxPoint(rectLabel
.x
-4,rectLabel
.y
-4),
2932 wxSize(rectLabel
.width
+11,rectLabel
.height
+8)
2937 void wxListMainWindow::OnRenameTimer()
2939 wxCHECK_RET( HasCurrent(), wxT("unexpected rename timer") );
2941 EditLabel( m_current
);
2944 void wxListMainWindow::OnRenameAccept()
2946 wxListEvent
le( wxEVT_COMMAND_LIST_END_LABEL_EDIT
, GetParent()->GetId() );
2947 le
.SetEventObject( GetParent() );
2948 le
.m_itemIndex
= m_currentEdit
;
2950 wxListLineData
*data
= GetLine(m_currentEdit
);
2951 wxCHECK_RET( data
, _T("invalid index in OnRenameAccept()") );
2953 data
->GetItem( 0, le
.m_item
);
2954 le
.m_item
.m_text
= m_renameRes
;
2955 GetParent()->GetEventHandler()->ProcessEvent( le
);
2957 if (!le
.IsAllowed()) return;
2960 info
.m_mask
= wxLIST_MASK_TEXT
;
2961 info
.m_itemId
= le
.m_itemIndex
;
2962 info
.m_text
= m_renameRes
;
2963 info
.SetTextColour(le
.m_item
.GetTextColour());
2967 void wxListMainWindow::OnMouse( wxMouseEvent
&event
)
2969 event
.SetEventObject( GetParent() );
2970 if ( GetParent()->GetEventHandler()->ProcessEvent( event
) )
2973 if ( !HasCurrent() || IsEmpty() )
2979 if ( !(event
.Dragging() || event
.ButtonDown() || event
.LeftUp() ||
2980 event
.ButtonDClick()) )
2983 int x
= event
.GetX();
2984 int y
= event
.GetY();
2985 CalcUnscrolledPosition( x
, y
, &x
, &y
);
2987 // where did we hit it (if we did)?
2990 size_t count
= GetItemCount(),
2993 if ( HasFlag(wxLC_REPORT
) )
2995 current
= y
/ GetLineHeight();
2996 if ( current
< count
)
2997 hitResult
= HitTestLine(current
, x
, y
);
3001 // TODO: optimize it too! this is less simple than for report view but
3002 // enumerating all items is still not a way to do it!!
3003 for ( current
= 0; current
< count
; current
++ )
3005 hitResult
= HitTestLine(current
, x
, y
);
3011 if (event
.Dragging())
3013 if (m_dragCount
== 0)
3015 // we have to report the raw, physical coords as we want to be
3016 // able to call HitTest(event.m_pointDrag) from the user code to
3017 // get the item being dragged
3018 m_dragStart
= event
.GetPosition();
3023 if (m_dragCount
!= 3)
3026 int command
= event
.RightIsDown() ? wxEVT_COMMAND_LIST_BEGIN_RDRAG
3027 : wxEVT_COMMAND_LIST_BEGIN_DRAG
;
3029 wxListEvent
le( command
, GetParent()->GetId() );
3030 le
.SetEventObject( GetParent() );
3031 le
.m_pointDrag
= m_dragStart
;
3032 GetParent()->GetEventHandler()->ProcessEvent( le
);
3043 // outside of any item
3047 bool forceClick
= FALSE
;
3048 if (event
.ButtonDClick())
3050 m_renameTimer
->Stop();
3051 m_lastOnSame
= FALSE
;
3053 if ( current
== m_lineBeforeLastClicked
)
3055 SendNotify( current
, wxEVT_COMMAND_LIST_ITEM_ACTIVATED
);
3061 // the first click was on another item, so don't interpret this as
3062 // a double click, but as a simple click instead
3067 if (event
.LeftUp() && m_lastOnSame
)
3069 if ((current
== m_current
) &&
3070 (hitResult
== wxLIST_HITTEST_ONITEMLABEL
) &&
3071 HasFlag(wxLC_EDIT_LABELS
) )
3073 m_renameTimer
->Start( 100, TRUE
);
3075 m_lastOnSame
= FALSE
;
3077 else if (event
.RightDown())
3079 SendNotify( current
, wxEVT_COMMAND_LIST_ITEM_RIGHT_CLICK
,
3080 event
.GetPosition() );
3082 else if (event
.MiddleDown())
3084 SendNotify( current
, wxEVT_COMMAND_LIST_ITEM_MIDDLE_CLICK
);
3086 else if ( event
.LeftDown() || forceClick
)
3088 m_lineBeforeLastClicked
= m_lineLastClicked
;
3089 m_lineLastClicked
= current
;
3091 size_t oldCurrent
= m_current
;
3093 if ( IsSingleSel() || !(event
.ControlDown() || event
.ShiftDown()) )
3095 HighlightAll( FALSE
);
3097 ChangeCurrent(current
);
3099 ReverseHighlight(m_current
);
3101 else // multi sel & either ctrl or shift is down
3103 if (event
.ControlDown())
3105 ChangeCurrent(current
);
3107 ReverseHighlight(m_current
);
3109 else if (event
.ShiftDown())
3111 ChangeCurrent(current
);
3113 size_t lineFrom
= oldCurrent
,
3116 if ( lineTo
< lineFrom
)
3119 lineFrom
= m_current
;
3122 HighlightLines(lineFrom
, lineTo
);
3124 else // !ctrl, !shift
3126 // test in the enclosing if should make it impossible
3127 wxFAIL_MSG( _T("how did we get here?") );
3131 if (m_current
!= oldCurrent
)
3133 RefreshLine( oldCurrent
);
3136 // forceClick is only set if the previous click was on another item
3137 m_lastOnSame
= !forceClick
&& (m_current
== oldCurrent
);
3141 void wxListMainWindow::MoveToItem(size_t item
)
3143 if ( item
== (size_t)-1 )
3146 wxRect rect
= GetLineRect(item
);
3148 int client_w
, client_h
;
3149 GetClientSize( &client_w
, &client_h
);
3151 int view_x
= m_xScroll
*GetScrollPos( wxHORIZONTAL
);
3152 int view_y
= m_yScroll
*GetScrollPos( wxVERTICAL
);
3154 if ( HasFlag(wxLC_REPORT
) )
3156 // the next we need the range of lines shown it might be different, so
3158 ResetVisibleLinesRange();
3160 if (rect
.y
< view_y
)
3161 Scroll( -1, rect
.y
/m_yScroll
);
3162 if (rect
.y
+rect
.height
+5 > view_y
+client_h
)
3163 Scroll( -1, (rect
.y
+rect
.height
-client_h
+SCROLL_UNIT_Y
)/m_yScroll
);
3167 if (rect
.x
-view_x
< 5)
3168 Scroll( (rect
.x
-5)/m_xScroll
, -1 );
3169 if (rect
.x
+rect
.width
-5 > view_x
+client_w
)
3170 Scroll( (rect
.x
+rect
.width
-client_w
+SCROLL_UNIT_X
)/m_xScroll
, -1 );
3174 // ----------------------------------------------------------------------------
3175 // keyboard handling
3176 // ----------------------------------------------------------------------------
3178 void wxListMainWindow::OnArrowChar(size_t newCurrent
, const wxKeyEvent
& event
)
3180 wxCHECK_RET( newCurrent
< (size_t)GetItemCount(),
3181 _T("invalid item index in OnArrowChar()") );
3183 size_t oldCurrent
= m_current
;
3185 // in single selection we just ignore Shift as we can't select several
3187 if ( event
.ShiftDown() && !IsSingleSel() )
3189 ChangeCurrent(newCurrent
);
3191 // select all the items between the old and the new one
3192 if ( oldCurrent
> newCurrent
)
3194 newCurrent
= oldCurrent
;
3195 oldCurrent
= m_current
;
3198 HighlightLines(oldCurrent
, newCurrent
);
3202 // all previously selected items are unselected unless ctrl is held
3203 if ( !event
.ControlDown() )
3204 HighlightAll(FALSE
);
3206 ChangeCurrent(newCurrent
);
3208 HighlightLine( oldCurrent
, FALSE
);
3209 RefreshLine( oldCurrent
);
3211 if ( !event
.ControlDown() )
3213 HighlightLine( m_current
, TRUE
);
3217 RefreshLine( m_current
);
3222 void wxListMainWindow::OnKeyDown( wxKeyEvent
&event
)
3224 wxWindow
*parent
= GetParent();
3226 /* we propagate the key event up */
3227 wxKeyEvent
ke( wxEVT_KEY_DOWN
);
3228 ke
.m_shiftDown
= event
.m_shiftDown
;
3229 ke
.m_controlDown
= event
.m_controlDown
;
3230 ke
.m_altDown
= event
.m_altDown
;
3231 ke
.m_metaDown
= event
.m_metaDown
;
3232 ke
.m_keyCode
= event
.m_keyCode
;
3235 ke
.SetEventObject( parent
);
3236 if (parent
->GetEventHandler()->ProcessEvent( ke
)) return;
3241 void wxListMainWindow::OnChar( wxKeyEvent
&event
)
3243 wxWindow
*parent
= GetParent();
3245 /* we send a list_key event up */
3248 wxListEvent
le( wxEVT_COMMAND_LIST_KEY_DOWN
, GetParent()->GetId() );
3249 le
.m_itemIndex
= m_current
;
3250 GetLine(m_current
)->GetItem( 0, le
.m_item
);
3251 le
.m_code
= (int)event
.KeyCode();
3252 le
.SetEventObject( parent
);
3253 parent
->GetEventHandler()->ProcessEvent( le
);
3256 /* we propagate the char event up */
3257 wxKeyEvent
ke( wxEVT_CHAR
);
3258 ke
.m_shiftDown
= event
.m_shiftDown
;
3259 ke
.m_controlDown
= event
.m_controlDown
;
3260 ke
.m_altDown
= event
.m_altDown
;
3261 ke
.m_metaDown
= event
.m_metaDown
;
3262 ke
.m_keyCode
= event
.m_keyCode
;
3265 ke
.SetEventObject( parent
);
3266 if (parent
->GetEventHandler()->ProcessEvent( ke
)) return;
3268 if (event
.KeyCode() == WXK_TAB
)
3270 wxNavigationKeyEvent nevent
;
3271 nevent
.SetWindowChange( event
.ControlDown() );
3272 nevent
.SetDirection( !event
.ShiftDown() );
3273 nevent
.SetEventObject( GetParent()->GetParent() );
3274 nevent
.SetCurrentFocus( m_parent
);
3275 if (GetParent()->GetParent()->GetEventHandler()->ProcessEvent( nevent
))
3279 /* no item -> nothing to do */
3286 switch (event
.KeyCode())
3289 if ( m_current
> 0 )
3290 OnArrowChar( m_current
- 1, event
);
3294 if ( m_current
< (size_t)GetItemCount() - 1 )
3295 OnArrowChar( m_current
+ 1, event
);
3300 OnArrowChar( GetItemCount() - 1, event
);
3305 OnArrowChar( 0, event
);
3311 if ( HasFlag(wxLC_REPORT
) )
3313 steps
= m_linesPerPage
- 1;
3317 steps
= m_current
% m_linesPerPage
;
3320 int index
= m_current
- steps
;
3324 OnArrowChar( index
, event
);
3331 if ( HasFlag(wxLC_REPORT
) )
3333 steps
= m_linesPerPage
- 1;
3337 steps
= m_linesPerPage
- (m_current
% m_linesPerPage
) - 1;
3340 size_t index
= m_current
+ steps
;
3341 size_t count
= GetItemCount();
3342 if ( index
>= count
)
3345 OnArrowChar( index
, event
);
3350 if ( !HasFlag(wxLC_REPORT
) )
3352 int index
= m_current
- m_linesPerPage
;
3356 OnArrowChar( index
, event
);
3361 if ( !HasFlag(wxLC_REPORT
) )
3363 size_t index
= m_current
+ m_linesPerPage
;
3365 size_t count
= GetItemCount();
3366 if ( index
>= count
)
3369 OnArrowChar( index
, event
);
3374 if ( IsSingleSel() )
3376 SendNotify( m_current
, wxEVT_COMMAND_LIST_ITEM_ACTIVATED
);
3378 if ( IsHighlighted(m_current
) )
3380 // don't unselect the item in single selection mode
3383 //else: select it in ReverseHighlight() below if unselected
3386 ReverseHighlight(m_current
);
3391 SendNotify( m_current
, wxEVT_COMMAND_LIST_ITEM_ACTIVATED
);
3399 // ----------------------------------------------------------------------------
3401 // ----------------------------------------------------------------------------
3404 extern wxWindow
*g_focusWindow
;
3407 void wxListMainWindow::OnSetFocus( wxFocusEvent
&WXUNUSED(event
) )
3409 // wxGTK sends us EVT_SET_FOCUS events even if we had never got
3410 // EVT_KILL_FOCUS before which means that we finish by redrawing the items
3411 // which are already drawn correctly resulting in horrible flicker - avoid
3424 g_focusWindow
= GetParent();
3427 wxFocusEvent
event( wxEVT_SET_FOCUS
, GetParent()->GetId() );
3428 event
.SetEventObject( GetParent() );
3429 GetParent()->GetEventHandler()->ProcessEvent( event
);
3432 void wxListMainWindow::OnKillFocus( wxFocusEvent
&WXUNUSED(event
) )
3439 void wxListMainWindow::DrawImage( int index
, wxDC
*dc
, int x
, int y
)
3441 if ( HasFlag(wxLC_ICON
) && (m_normal_image_list
))
3443 m_normal_image_list
->Draw( index
, *dc
, x
, y
, wxIMAGELIST_DRAW_TRANSPARENT
);
3445 else if ( HasFlag(wxLC_SMALL_ICON
) && (m_small_image_list
))
3447 m_small_image_list
->Draw( index
, *dc
, x
, y
, wxIMAGELIST_DRAW_TRANSPARENT
);
3449 else if ( HasFlag(wxLC_LIST
) && (m_small_image_list
))
3451 m_small_image_list
->Draw( index
, *dc
, x
, y
, wxIMAGELIST_DRAW_TRANSPARENT
);
3453 else if ( HasFlag(wxLC_REPORT
) && (m_small_image_list
))
3455 m_small_image_list
->Draw( index
, *dc
, x
, y
, wxIMAGELIST_DRAW_TRANSPARENT
);
3459 void wxListMainWindow::GetImageSize( int index
, int &width
, int &height
) const
3461 if ( HasFlag(wxLC_ICON
) && m_normal_image_list
)
3463 m_normal_image_list
->GetSize( index
, width
, height
);
3465 else if ( HasFlag(wxLC_SMALL_ICON
) && m_small_image_list
)
3467 m_small_image_list
->GetSize( index
, width
, height
);
3469 else if ( HasFlag(wxLC_LIST
) && m_small_image_list
)
3471 m_small_image_list
->GetSize( index
, width
, height
);
3473 else if ( HasFlag(wxLC_REPORT
) && m_small_image_list
)
3475 m_small_image_list
->GetSize( index
, width
, height
);
3484 int wxListMainWindow::GetTextLength( const wxString
&s
) const
3486 wxClientDC
dc( wxConstCast(this, wxListMainWindow
) );
3487 dc
.SetFont( GetFont() );
3490 dc
.GetTextExtent( s
, &lw
, NULL
);
3492 return lw
+ AUTOSIZE_COL_MARGIN
;
3495 void wxListMainWindow::SetImageList( wxImageList
*imageList
, int which
)
3499 // calc the spacing from the icon size
3502 if ((imageList
) && (imageList
->GetImageCount()) )
3504 imageList
->GetSize(0, width
, height
);
3507 if (which
== wxIMAGE_LIST_NORMAL
)
3509 m_normal_image_list
= imageList
;
3510 m_normal_spacing
= width
+ 8;
3513 if (which
== wxIMAGE_LIST_SMALL
)
3515 m_small_image_list
= imageList
;
3516 m_small_spacing
= width
+ 14;
3520 void wxListMainWindow::SetItemSpacing( int spacing
, bool isSmall
)
3525 m_small_spacing
= spacing
;
3529 m_normal_spacing
= spacing
;
3533 int wxListMainWindow::GetItemSpacing( bool isSmall
)
3535 return isSmall
? m_small_spacing
: m_normal_spacing
;
3538 // ----------------------------------------------------------------------------
3540 // ----------------------------------------------------------------------------
3542 void wxListMainWindow::SetColumn( int col
, wxListItem
&item
)
3544 wxListHeaderDataList::Node
*node
= m_columns
.Item( col
);
3546 wxCHECK_RET( node
, _T("invalid column index in SetColumn") );
3548 if ( item
.m_width
== wxLIST_AUTOSIZE_USEHEADER
)
3549 item
.m_width
= GetTextLength( item
.m_text
);
3551 wxListHeaderData
*column
= node
->GetData();
3552 column
->SetItem( item
);
3554 wxListHeaderWindow
*headerWin
= GetListCtrl()->m_headerWin
;
3556 headerWin
->m_dirty
= TRUE
;
3560 // invalidate it as it has to be recalculated
3564 void wxListMainWindow::SetColumnWidth( int col
, int width
)
3566 wxCHECK_RET( col
>= 0 && col
< GetColumnCount(),
3567 _T("invalid column index") );
3569 wxCHECK_RET( HasFlag(wxLC_REPORT
),
3570 _T("SetColumnWidth() can only be called in report mode.") );
3573 wxListHeaderWindow
*headerWin
= GetListCtrl()->m_headerWin
;
3575 headerWin
->m_dirty
= TRUE
;
3577 wxListHeaderDataList::Node
*node
= m_columns
.Item( col
);
3578 wxCHECK_RET( node
, _T("no column?") );
3580 wxListHeaderData
*column
= node
->GetData();
3582 size_t count
= GetItemCount();
3584 if (width
== wxLIST_AUTOSIZE_USEHEADER
)
3586 width
= GetTextLength(column
->GetText());
3588 else if ( width
== wxLIST_AUTOSIZE
)
3592 // TODO: determine the max width somehow...
3593 width
= WIDTH_COL_DEFAULT
;
3597 wxClientDC
dc(this);
3598 dc
.SetFont( GetFont() );
3600 int max
= AUTOSIZE_COL_MARGIN
;
3602 for ( size_t i
= 0; i
< count
; i
++ )
3604 wxListLineData
*line
= GetLine(i
);
3605 wxListItemDataList::Node
*n
= line
->m_items
.Item( col
);
3607 wxCHECK_RET( n
, _T("no subitem?") );
3609 wxListItemData
*item
= n
->GetData();
3612 if (item
->HasImage())
3615 GetImageSize( item
->GetImage(), ix
, iy
);
3619 if (item
->HasText())
3622 dc
.GetTextExtent( item
->GetText(), &w
, NULL
);
3630 width
= max
+ AUTOSIZE_COL_MARGIN
;
3634 column
->SetWidth( width
);
3636 // invalidate it as it has to be recalculated
3640 int wxListMainWindow::GetHeaderWidth() const
3642 if ( !m_headerWidth
)
3644 wxListMainWindow
*self
= wxConstCast(this, wxListMainWindow
);
3646 size_t count
= GetColumnCount();
3647 for ( size_t col
= 0; col
< count
; col
++ )
3649 self
->m_headerWidth
+= GetColumnWidth(col
);
3653 return m_headerWidth
;
3656 void wxListMainWindow::GetColumn( int col
, wxListItem
&item
) const
3658 wxListHeaderDataList::Node
*node
= m_columns
.Item( col
);
3659 wxCHECK_RET( node
, _T("invalid column index in GetColumn") );
3661 wxListHeaderData
*column
= node
->GetData();
3662 column
->GetItem( item
);
3665 int wxListMainWindow::GetColumnWidth( int col
) const
3667 wxListHeaderDataList::Node
*node
= m_columns
.Item( col
);
3668 wxCHECK_MSG( node
, 0, _T("invalid column index") );
3670 wxListHeaderData
*column
= node
->GetData();
3671 return column
->GetWidth();
3674 // ----------------------------------------------------------------------------
3676 // ----------------------------------------------------------------------------
3678 void wxListMainWindow::SetItem( wxListItem
&item
)
3680 long id
= item
.m_itemId
;
3681 wxCHECK_RET( id
>= 0 && (size_t)id
< GetItemCount(),
3682 _T("invalid item index in SetItem") );
3686 wxListLineData
*line
= GetLine((size_t)id
);
3687 line
->SetItem( item
.m_col
, item
);
3690 if ( InReportView() )
3692 // just refresh the line to show the new value of the text/image
3693 RefreshLine((size_t)id
);
3697 // refresh everything (resulting in horrible flicker - FIXME!)
3702 void wxListMainWindow::SetItemState( long litem
, long state
, long stateMask
)
3704 wxCHECK_RET( litem
>= 0 && (size_t)litem
< GetItemCount(),
3705 _T("invalid list ctrl item index in SetItem") );
3707 size_t oldCurrent
= m_current
;
3708 size_t item
= (size_t)litem
; // safe because of the check above
3710 // do we need to change the focus?
3711 if ( stateMask
& wxLIST_STATE_FOCUSED
)
3713 if ( state
& wxLIST_STATE_FOCUSED
)
3715 // don't do anything if this item is already focused
3716 if ( item
!= m_current
)
3718 ChangeCurrent(item
);
3720 if ( oldCurrent
!= (size_t)-1 )
3722 if ( IsSingleSel() )
3724 HighlightLine(oldCurrent
, FALSE
);
3727 RefreshLine(oldCurrent
);
3730 RefreshLine( m_current
);
3735 // don't do anything if this item is not focused
3736 if ( item
== m_current
)
3740 RefreshLine( oldCurrent
);
3745 // do we need to change the selection state?
3746 if ( stateMask
& wxLIST_STATE_SELECTED
)
3748 bool on
= (state
& wxLIST_STATE_SELECTED
) != 0;
3750 if ( IsSingleSel() )
3754 // selecting the item also makes it the focused one in the
3756 if ( m_current
!= item
)
3758 ChangeCurrent(item
);
3760 if ( oldCurrent
!= (size_t)-1 )
3762 HighlightLine( oldCurrent
, FALSE
);
3763 RefreshLine( oldCurrent
);
3769 // only the current item may be selected anyhow
3770 if ( item
!= m_current
)
3775 if ( HighlightLine(item
, on
) )
3782 int wxListMainWindow::GetItemState( long item
, long stateMask
)
3784 wxCHECK_MSG( item
>= 0 && (size_t)item
< GetItemCount(), 0,
3785 _T("invalid list ctrl item index in GetItemState()") );
3787 int ret
= wxLIST_STATE_DONTCARE
;
3789 if ( stateMask
& wxLIST_STATE_FOCUSED
)
3791 if ( (size_t)item
== m_current
)
3792 ret
|= wxLIST_STATE_FOCUSED
;
3795 if ( stateMask
& wxLIST_STATE_SELECTED
)
3797 if ( IsHighlighted(item
) )
3798 ret
|= wxLIST_STATE_SELECTED
;
3804 void wxListMainWindow::GetItem( wxListItem
&item
)
3806 wxCHECK_RET( item
.m_itemId
>= 0 && (size_t)item
.m_itemId
< GetItemCount(),
3807 _T("invalid item index in GetItem") );
3809 wxListLineData
*line
= GetLine((size_t)item
.m_itemId
);
3810 line
->GetItem( item
.m_col
, item
);
3813 // ----------------------------------------------------------------------------
3815 // ----------------------------------------------------------------------------
3817 size_t wxListMainWindow::GetItemCount() const
3819 return IsVirtual() ? m_countVirt
: m_lines
.GetCount();
3822 void wxListMainWindow::SetItemCount(long count
)
3824 m_selStore
.SetItemCount(count
);
3825 m_countVirt
= count
;
3827 ResetVisibleLinesRange();
3829 // scrollbars must be reset
3833 int wxListMainWindow::GetSelectedItemCount()
3835 // deal with the quick case first
3836 if ( IsSingleSel() )
3838 return HasCurrent() ? IsHighlighted(m_current
) : FALSE
;
3841 // virtual controls remmebers all its selections itself
3843 return m_selStore
.GetSelectedCount();
3845 // TODO: we probably should maintain the number of items selected even for
3846 // non virtual controls as enumerating all lines is really slow...
3847 size_t countSel
= 0;
3848 size_t count
= GetItemCount();
3849 for ( size_t line
= 0; line
< count
; line
++ )
3851 if ( GetLine(line
)->IsHighlighted() )
3858 // ----------------------------------------------------------------------------
3859 // item position/size
3860 // ----------------------------------------------------------------------------
3862 void wxListMainWindow::GetItemRect( long index
, wxRect
&rect
)
3864 wxCHECK_RET( index
>= 0 && (size_t)index
< GetItemCount(),
3865 _T("invalid index in GetItemRect") );
3867 rect
= GetLineRect((size_t)index
);
3869 CalcScrolledPosition(rect
.x
, rect
.y
, &rect
.x
, &rect
.y
);
3872 bool wxListMainWindow::GetItemPosition(long item
, wxPoint
& pos
)
3875 GetItemRect(item
, rect
);
3883 // ----------------------------------------------------------------------------
3884 // geometry calculation
3885 // ----------------------------------------------------------------------------
3887 void wxListMainWindow::RecalculatePositions(bool noRefresh
)
3889 wxClientDC
dc( this );
3890 dc
.SetFont( GetFont() );
3893 if ( HasFlag(wxLC_ICON
) )
3894 iconSpacing
= m_normal_spacing
;
3895 else if ( HasFlag(wxLC_SMALL_ICON
) )
3896 iconSpacing
= m_small_spacing
;
3902 GetClientSize( &clientWidth
, &clientHeight
);
3904 if ( HasFlag(wxLC_REPORT
) )
3906 // all lines have the same height
3907 int lineHeight
= GetLineHeight();
3909 // scroll one line per step
3910 m_yScroll
= lineHeight
;
3912 size_t lineCount
= GetItemCount();
3913 int entireHeight
= lineCount
*lineHeight
+ LINE_SPACING
;
3915 m_linesPerPage
= clientHeight
/ lineHeight
;
3917 ResetVisibleLinesRange();
3919 SetScrollbars( m_xScroll
, m_yScroll
,
3920 (GetHeaderWidth() + m_xScroll
- 1)/m_xScroll
,
3921 (entireHeight
+ m_yScroll
- 1)/m_yScroll
,
3922 GetScrollPos(wxHORIZONTAL
),
3923 GetScrollPos(wxVERTICAL
),
3928 // at first we try without any scrollbar. if the items don't
3929 // fit into the window, we recalculate after subtracting an
3930 // approximated 15 pt for the horizontal scrollbar
3932 clientHeight
-= 4; // sunken frame
3934 int entireWidth
= 0;
3936 for (int tries
= 0; tries
< 2; tries
++)
3943 int currentlyVisibleLines
= 0;
3945 size_t count
= GetItemCount();
3946 for (size_t i
= 0; i
< count
; i
++)
3948 currentlyVisibleLines
++;
3949 wxListLineData
*line
= GetLine(i
);
3950 line
->CalculateSize( &dc
, iconSpacing
);
3951 line
->SetPosition( x
, y
, clientWidth
, iconSpacing
);
3953 wxSize sizeLine
= GetLineSize(i
);
3955 if ( maxWidth
< sizeLine
.x
)
3956 maxWidth
= sizeLine
.x
;
3959 if (currentlyVisibleLines
> m_linesPerPage
)
3960 m_linesPerPage
= currentlyVisibleLines
;
3962 // assume that the size of the next one is the same... (FIXME)
3963 if ( y
+ sizeLine
.y
- 6 >= clientHeight
)
3965 currentlyVisibleLines
= 0;
3968 entireWidth
+= maxWidth
+6;
3971 if ( i
== count
- 1 )
3972 entireWidth
+= maxWidth
;
3973 if ((tries
== 0) && (entireWidth
> clientWidth
))
3975 clientHeight
-= 15; // scrollbar height
3977 currentlyVisibleLines
= 0;
3980 if ( i
== count
- 1 )
3981 tries
= 1; // everything fits, no second try required
3985 int scroll_pos
= GetScrollPos( wxHORIZONTAL
);
3986 SetScrollbars( m_xScroll
, m_yScroll
, (entireWidth
+SCROLL_UNIT_X
) / m_xScroll
, 0, scroll_pos
, 0, TRUE
);
3991 // FIXME: why should we call it from here?
3998 void wxListMainWindow::RefreshAll()
4003 wxListHeaderWindow
*headerWin
= GetListCtrl()->m_headerWin
;
4004 if ( headerWin
&& headerWin
->m_dirty
)
4006 headerWin
->m_dirty
= FALSE
;
4007 headerWin
->Refresh();
4011 void wxListMainWindow::UpdateCurrent()
4013 if ( !HasCurrent() && !IsEmpty() )
4019 long wxListMainWindow::GetNextItem( long item
,
4020 int WXUNUSED(geometry
),
4024 max
= GetItemCount();
4025 wxCHECK_MSG( (ret
== -1) || (ret
< max
), -1,
4026 _T("invalid listctrl index in GetNextItem()") );
4028 // notice that we start with the next item (or the first one if item == -1)
4029 // and this is intentional to allow writing a simple loop to iterate over
4030 // all selected items
4034 // this is not an error because the index was ok initially, just no
4045 size_t count
= GetItemCount();
4046 for ( size_t line
= (size_t)ret
; line
< count
; line
++ )
4048 if ( (state
& wxLIST_STATE_FOCUSED
) && (line
== m_current
) )
4051 if ( (state
& wxLIST_STATE_SELECTED
) && IsHighlighted(line
) )
4058 // ----------------------------------------------------------------------------
4060 // ----------------------------------------------------------------------------
4062 void wxListMainWindow::DeleteItem( long lindex
)
4064 size_t count
= GetItemCount();
4066 wxCHECK_RET( (lindex
>= 0) && ((size_t)lindex
< count
),
4067 _T("invalid item index in DeleteItem") );
4069 size_t index
= (size_t)lindex
;
4071 // we don't need to adjust the index for the previous items
4072 if ( HasCurrent() && m_current
>= index
)
4074 // if the current item is being deleted, we want the next one to
4075 // become selected - unless there is no next one - so don't adjust
4076 // m_current in this case
4077 if ( m_current
!= index
|| m_current
== count
- 1 )
4083 if ( InReportView() )
4085 ResetVisibleLinesRange();
4092 m_selStore
.OnItemDelete(index
);
4096 m_lines
.RemoveAt( index
);
4099 // we need to refresh the (vert) scrollbar as the number of items changed
4102 SendNotify( index
, wxEVT_COMMAND_LIST_DELETE_ITEM
);
4104 RefreshAfter(index
);
4107 void wxListMainWindow::DeleteColumn( int col
)
4109 wxListHeaderDataList::Node
*node
= m_columns
.Item( col
);
4111 wxCHECK_RET( node
, wxT("invalid column index in DeleteColumn()") );
4114 m_columns
.DeleteNode( node
);
4117 void wxListMainWindow::DoDeleteAllItems()
4121 // nothing to do - in particular, don't send the event
4127 // to make the deletion of all items faster, we don't send the
4128 // notifications for each item deletion in this case but only one event
4129 // for all of them: this is compatible with wxMSW and documented in
4130 // DeleteAllItems() description
4132 wxListEvent
event( wxEVT_COMMAND_LIST_DELETE_ALL_ITEMS
, GetParent()->GetId() );
4133 event
.SetEventObject( GetParent() );
4134 GetParent()->GetEventHandler()->ProcessEvent( event
);
4143 if ( InReportView() )
4145 ResetVisibleLinesRange();
4151 void wxListMainWindow::DeleteAllItems()
4155 RecalculatePositions();
4158 void wxListMainWindow::DeleteEverything()
4165 // ----------------------------------------------------------------------------
4166 // scanning for an item
4167 // ----------------------------------------------------------------------------
4169 void wxListMainWindow::EnsureVisible( long index
)
4171 wxCHECK_RET( index
>= 0 && (size_t)index
< GetItemCount(),
4172 _T("invalid index in EnsureVisible") );
4174 // We have to call this here because the label in question might just have
4175 // been added and its position is not known yet
4178 RecalculatePositions(TRUE
/* no refresh */);
4181 MoveToItem((size_t)index
);
4184 long wxListMainWindow::FindItem(long start
, const wxString
& str
, bool WXUNUSED(partial
) )
4191 size_t count
= GetItemCount();
4192 for ( size_t i
= (size_t)pos
; i
< count
; i
++ )
4194 wxListLineData
*line
= GetLine(i
);
4195 if ( line
->GetText(0) == tmp
)
4202 long wxListMainWindow::FindItem(long start
, long data
)
4208 size_t count
= GetItemCount();
4209 for (size_t i
= (size_t)pos
; i
< count
; i
++)
4211 wxListLineData
*line
= GetLine(i
);
4213 line
->GetItem( 0, item
);
4214 if (item
.m_data
== data
)
4221 long wxListMainWindow::HitTest( int x
, int y
, int &flags
)
4223 CalcUnscrolledPosition( x
, y
, &x
, &y
);
4225 size_t count
= GetItemCount();
4227 if ( HasFlag(wxLC_REPORT
) )
4229 size_t current
= y
/ GetLineHeight();
4230 if ( current
< count
)
4232 flags
= HitTestLine(current
, x
, y
);
4239 // TODO: optimize it too! this is less simple than for report view but
4240 // enumerating all items is still not a way to do it!!
4241 for ( size_t current
= 0; current
< count
; current
++ )
4243 flags
= HitTestLine(current
, x
, y
);
4252 // ----------------------------------------------------------------------------
4254 // ----------------------------------------------------------------------------
4256 void wxListMainWindow::InsertItem( wxListItem
&item
)
4258 wxASSERT_MSG( !IsVirtual(), _T("can't be used with virtual control") );
4260 size_t count
= GetItemCount();
4261 wxCHECK_RET( item
.m_itemId
>= 0 && (size_t)item
.m_itemId
<= count
,
4262 _T("invalid item index") );
4264 size_t id
= item
.m_itemId
;
4269 if ( HasFlag(wxLC_REPORT
) )
4271 else if ( HasFlag(wxLC_LIST
) )
4273 else if ( HasFlag(wxLC_ICON
) )
4275 else if ( HasFlag(wxLC_SMALL_ICON
) )
4276 mode
= wxLC_ICON
; // no typo
4279 wxFAIL_MSG( _T("unknown mode") );
4282 wxListLineData
*line
= new wxListLineData(this);
4284 line
->SetItem( 0, item
);
4286 m_lines
.Insert( line
, id
);
4289 RefreshLines(id
, GetItemCount() - 1);
4292 void wxListMainWindow::InsertColumn( long col
, wxListItem
&item
)
4295 if ( HasFlag(wxLC_REPORT
) )
4297 if (item
.m_width
== wxLIST_AUTOSIZE_USEHEADER
)
4298 item
.m_width
= GetTextLength( item
.m_text
);
4299 wxListHeaderData
*column
= new wxListHeaderData( item
);
4300 if ((col
>= 0) && (col
< (int)m_columns
.GetCount()))
4302 wxListHeaderDataList::Node
*node
= m_columns
.Item( col
);
4303 m_columns
.Insert( node
, column
);
4307 m_columns
.Append( column
);
4312 // ----------------------------------------------------------------------------
4314 // ----------------------------------------------------------------------------
4316 wxListCtrlCompare list_ctrl_compare_func_2
;
4317 long list_ctrl_compare_data
;
4319 int LINKAGEMODE
list_ctrl_compare_func_1( wxListLineData
**arg1
, wxListLineData
**arg2
)
4321 wxListLineData
*line1
= *arg1
;
4322 wxListLineData
*line2
= *arg2
;
4324 line1
->GetItem( 0, item
);
4325 long data1
= item
.m_data
;
4326 line2
->GetItem( 0, item
);
4327 long data2
= item
.m_data
;
4328 return list_ctrl_compare_func_2( data1
, data2
, list_ctrl_compare_data
);
4331 void wxListMainWindow::SortItems( wxListCtrlCompare fn
, long data
)
4333 list_ctrl_compare_func_2
= fn
;
4334 list_ctrl_compare_data
= data
;
4335 m_lines
.Sort( list_ctrl_compare_func_1
);
4339 // ----------------------------------------------------------------------------
4341 // ----------------------------------------------------------------------------
4343 void wxListMainWindow::OnScroll(wxScrollWinEvent
& event
)
4345 // update our idea of which lines are shown when we redraw the window the
4347 ResetVisibleLinesRange();
4350 #if defined(__WXGTK__) && !defined(__WXUNIVERSAL__)
4351 wxScrolledWindow::OnScroll(event
);
4353 HandleOnScroll( event
);
4356 if ( event
.GetOrientation() == wxHORIZONTAL
&& HasHeader() )
4358 wxListCtrl
* lc
= GetListCtrl();
4359 wxCHECK_RET( lc
, _T("no listctrl window?") );
4361 lc
->m_headerWin
->Refresh() ;
4363 lc
->m_headerWin
->MacUpdateImmediately() ;
4368 int wxListMainWindow::GetCountPerPage() const
4370 if ( !m_linesPerPage
)
4372 wxConstCast(this, wxListMainWindow
)->
4373 m_linesPerPage
= GetClientSize().y
/ GetLineHeight();
4376 return m_linesPerPage
;
4379 void wxListMainWindow::GetVisibleLinesRange(size_t *from
, size_t *to
)
4381 wxASSERT_MSG( HasFlag(wxLC_REPORT
), _T("this is for report mode only") );
4383 if ( m_lineFrom
== (size_t)-1 )
4385 size_t count
= GetItemCount();
4388 m_lineFrom
= GetScrollPos(wxVERTICAL
);
4390 // this may happen if SetScrollbars() hadn't been called yet
4391 if ( m_lineFrom
>= count
)
4392 m_lineFrom
= count
- 1;
4394 // we redraw one extra line but this is needed to make the redrawing
4395 // logic work when there is a fractional number of lines on screen
4396 m_lineTo
= m_lineFrom
+ m_linesPerPage
;
4397 if ( m_lineTo
>= count
)
4398 m_lineTo
= count
- 1;
4400 else // empty control
4403 m_lineTo
= (size_t)-1;
4407 wxASSERT_MSG( IsEmpty() ||
4408 (m_lineFrom
<= m_lineTo
&& m_lineTo
< GetItemCount()),
4409 _T("GetVisibleLinesRange() returns incorrect result") );
4417 // -------------------------------------------------------------------------------------
4419 // -------------------------------------------------------------------------------------
4421 IMPLEMENT_DYNAMIC_CLASS(wxListItem
, wxObject
)
4423 wxListItem::wxListItem()
4430 void wxListItem::Clear()
4439 m_format
= wxLIST_FORMAT_CENTRE
;
4446 void wxListItem::ClearAttributes()
4455 // -------------------------------------------------------------------------------------
4457 // -------------------------------------------------------------------------------------
4459 IMPLEMENT_DYNAMIC_CLASS(wxListCtrl
, wxControl
)
4460 IMPLEMENT_DYNAMIC_CLASS(wxListView
, wxListCtrl
)
4462 IMPLEMENT_DYNAMIC_CLASS(wxListEvent
, wxNotifyEvent
)
4464 BEGIN_EVENT_TABLE(wxListCtrl
,wxControl
)
4465 EVT_SIZE(wxListCtrl::OnSize
)
4466 EVT_IDLE(wxListCtrl::OnIdle
)
4469 wxListCtrl::wxListCtrl()
4471 m_imageListNormal
= (wxImageList
*) NULL
;
4472 m_imageListSmall
= (wxImageList
*) NULL
;
4473 m_imageListState
= (wxImageList
*) NULL
;
4475 m_ownsImageListNormal
=
4476 m_ownsImageListSmall
=
4477 m_ownsImageListState
= FALSE
;
4479 m_mainWin
= (wxListMainWindow
*) NULL
;
4480 m_headerWin
= (wxListHeaderWindow
*) NULL
;
4483 wxListCtrl::~wxListCtrl()
4485 if (m_ownsImageListNormal
)
4486 delete m_imageListNormal
;
4487 if (m_ownsImageListSmall
)
4488 delete m_imageListSmall
;
4489 if (m_ownsImageListState
)
4490 delete m_imageListState
;
4493 void wxListCtrl::CreateHeaderWindow()
4495 m_headerWin
= new wxListHeaderWindow
4497 this, -1, m_mainWin
,
4499 wxSize(GetClientSize().x
, HEADER_HEIGHT
),
4504 bool wxListCtrl::Create(wxWindow
*parent
,
4509 const wxValidator
&validator
,
4510 const wxString
&name
)
4514 m_imageListState
= (wxImageList
*) NULL
;
4515 m_ownsImageListNormal
=
4516 m_ownsImageListSmall
=
4517 m_ownsImageListState
= FALSE
;
4519 m_mainWin
= (wxListMainWindow
*) NULL
;
4520 m_headerWin
= (wxListHeaderWindow
*) NULL
;
4522 if ( !(style
& wxLC_MASK_TYPE
) )
4524 style
= style
| wxLC_LIST
;
4527 if ( !wxControl::Create( parent
, id
, pos
, size
, style
, validator
, name
) )
4530 // don't create the inner window with the border
4531 style
&= ~wxSUNKEN_BORDER
;
4533 m_mainWin
= new wxListMainWindow( this, -1, wxPoint(0,0), size
, style
);
4535 if ( HasFlag(wxLC_REPORT
) )
4537 CreateHeaderWindow();
4539 if ( HasFlag(wxLC_NO_HEADER
) )
4541 // VZ: why do we create it at all then?
4542 m_headerWin
->Show( FALSE
);
4549 void wxListCtrl::SetSingleStyle( long style
, bool add
)
4551 wxASSERT_MSG( !(style
& wxLC_VIRTUAL
),
4552 _T("wxLC_VIRTUAL can't be [un]set") );
4554 long flag
= GetWindowStyle();
4558 if (style
& wxLC_MASK_TYPE
)
4559 flag
&= ~(wxLC_MASK_TYPE
| wxLC_VIRTUAL
);
4560 if (style
& wxLC_MASK_ALIGN
)
4561 flag
&= ~wxLC_MASK_ALIGN
;
4562 if (style
& wxLC_MASK_SORT
)
4563 flag
&= ~wxLC_MASK_SORT
;
4575 SetWindowStyleFlag( flag
);
4578 void wxListCtrl::SetWindowStyleFlag( long flag
)
4582 m_mainWin
->DeleteEverything();
4584 // has the header visibility changed?
4585 bool hasHeader
= HasFlag(wxLC_REPORT
) && !HasFlag(wxLC_NO_HEADER
),
4586 willHaveHeader
= (flag
& wxLC_REPORT
) && !(flag
& wxLC_NO_HEADER
);
4588 if ( hasHeader
!= willHaveHeader
)
4595 // don't delete, just hide, as we can reuse it later
4596 m_headerWin
->Show(FALSE
);
4598 //else: nothing to do
4600 else // must show header
4604 CreateHeaderWindow();
4606 else // already have it, just show
4608 m_headerWin
->Show( TRUE
);
4612 ResizeReportView(willHaveHeader
);
4616 wxWindow::SetWindowStyleFlag( flag
);
4619 bool wxListCtrl::GetColumn(int col
, wxListItem
&item
) const
4621 m_mainWin
->GetColumn( col
, item
);
4625 bool wxListCtrl::SetColumn( int col
, wxListItem
& item
)
4627 m_mainWin
->SetColumn( col
, item
);
4631 int wxListCtrl::GetColumnWidth( int col
) const
4633 return m_mainWin
->GetColumnWidth( col
);
4636 bool wxListCtrl::SetColumnWidth( int col
, int width
)
4638 m_mainWin
->SetColumnWidth( col
, width
);
4642 int wxListCtrl::GetCountPerPage() const
4644 return m_mainWin
->GetCountPerPage(); // different from Windows ?
4647 bool wxListCtrl::GetItem( wxListItem
&info
) const
4649 m_mainWin
->GetItem( info
);
4653 bool wxListCtrl::SetItem( wxListItem
&info
)
4655 m_mainWin
->SetItem( info
);
4659 long wxListCtrl::SetItem( long index
, int col
, const wxString
& label
, int imageId
)
4662 info
.m_text
= label
;
4663 info
.m_mask
= wxLIST_MASK_TEXT
;
4664 info
.m_itemId
= index
;
4668 info
.m_image
= imageId
;
4669 info
.m_mask
|= wxLIST_MASK_IMAGE
;
4671 m_mainWin
->SetItem(info
);
4675 int wxListCtrl::GetItemState( long item
, long stateMask
) const
4677 return m_mainWin
->GetItemState( item
, stateMask
);
4680 bool wxListCtrl::SetItemState( long item
, long state
, long stateMask
)
4682 m_mainWin
->SetItemState( item
, state
, stateMask
);
4686 bool wxListCtrl::SetItemImage( long item
, int image
, int WXUNUSED(selImage
) )
4689 info
.m_image
= image
;
4690 info
.m_mask
= wxLIST_MASK_IMAGE
;
4691 info
.m_itemId
= item
;
4692 m_mainWin
->SetItem( info
);
4696 wxString
wxListCtrl::GetItemText( long item
) const
4699 info
.m_itemId
= item
;
4700 m_mainWin
->GetItem( info
);
4704 void wxListCtrl::SetItemText( long item
, const wxString
&str
)
4707 info
.m_mask
= wxLIST_MASK_TEXT
;
4708 info
.m_itemId
= item
;
4710 m_mainWin
->SetItem( info
);
4713 long wxListCtrl::GetItemData( long item
) const
4716 info
.m_itemId
= item
;
4717 m_mainWin
->GetItem( info
);
4721 bool wxListCtrl::SetItemData( long item
, long data
)
4724 info
.m_mask
= wxLIST_MASK_DATA
;
4725 info
.m_itemId
= item
;
4727 m_mainWin
->SetItem( info
);
4731 bool wxListCtrl::GetItemRect( long item
, wxRect
&rect
, int WXUNUSED(code
) ) const
4733 m_mainWin
->GetItemRect( item
, rect
);
4737 bool wxListCtrl::GetItemPosition( long item
, wxPoint
& pos
) const
4739 m_mainWin
->GetItemPosition( item
, pos
);
4743 bool wxListCtrl::SetItemPosition( long WXUNUSED(item
), const wxPoint
& WXUNUSED(pos
) )
4748 int wxListCtrl::GetItemCount() const
4750 return m_mainWin
->GetItemCount();
4753 int wxListCtrl::GetColumnCount() const
4755 return m_mainWin
->GetColumnCount();
4758 void wxListCtrl::SetItemSpacing( int spacing
, bool isSmall
)
4760 m_mainWin
->SetItemSpacing( spacing
, isSmall
);
4763 int wxListCtrl::GetItemSpacing( bool isSmall
) const
4765 return m_mainWin
->GetItemSpacing( isSmall
);
4768 int wxListCtrl::GetSelectedItemCount() const
4770 return m_mainWin
->GetSelectedItemCount();
4773 wxColour
wxListCtrl::GetTextColour() const
4775 return GetForegroundColour();
4778 void wxListCtrl::SetTextColour(const wxColour
& col
)
4780 SetForegroundColour(col
);
4783 long wxListCtrl::GetTopItem() const
4788 long wxListCtrl::GetNextItem( long item
, int geom
, int state
) const
4790 return m_mainWin
->GetNextItem( item
, geom
, state
);
4793 wxImageList
*wxListCtrl::GetImageList(int which
) const
4795 if (which
== wxIMAGE_LIST_NORMAL
)
4797 return m_imageListNormal
;
4799 else if (which
== wxIMAGE_LIST_SMALL
)
4801 return m_imageListSmall
;
4803 else if (which
== wxIMAGE_LIST_STATE
)
4805 return m_imageListState
;
4807 return (wxImageList
*) NULL
;
4810 void wxListCtrl::SetImageList( wxImageList
*imageList
, int which
)
4812 if ( which
== wxIMAGE_LIST_NORMAL
)
4814 if (m_ownsImageListNormal
) delete m_imageListNormal
;
4815 m_imageListNormal
= imageList
;
4816 m_ownsImageListNormal
= FALSE
;
4818 else if ( which
== wxIMAGE_LIST_SMALL
)
4820 if (m_ownsImageListSmall
) delete m_imageListSmall
;
4821 m_imageListSmall
= imageList
;
4822 m_ownsImageListSmall
= FALSE
;
4824 else if ( which
== wxIMAGE_LIST_STATE
)
4826 if (m_ownsImageListState
) delete m_imageListState
;
4827 m_imageListState
= imageList
;
4828 m_ownsImageListState
= FALSE
;
4831 m_mainWin
->SetImageList( imageList
, which
);
4834 void wxListCtrl::AssignImageList(wxImageList
*imageList
, int which
)
4836 SetImageList(imageList
, which
);
4837 if ( which
== wxIMAGE_LIST_NORMAL
)
4838 m_ownsImageListNormal
= TRUE
;
4839 else if ( which
== wxIMAGE_LIST_SMALL
)
4840 m_ownsImageListSmall
= TRUE
;
4841 else if ( which
== wxIMAGE_LIST_STATE
)
4842 m_ownsImageListState
= TRUE
;
4845 bool wxListCtrl::Arrange( int WXUNUSED(flag
) )
4850 bool wxListCtrl::DeleteItem( long item
)
4852 m_mainWin
->DeleteItem( item
);
4856 bool wxListCtrl::DeleteAllItems()
4858 m_mainWin
->DeleteAllItems();
4862 bool wxListCtrl::DeleteAllColumns()
4864 size_t count
= m_mainWin
->m_columns
.GetCount();
4865 for ( size_t n
= 0; n
< count
; n
++ )
4871 void wxListCtrl::ClearAll()
4873 m_mainWin
->DeleteEverything();
4876 bool wxListCtrl::DeleteColumn( int col
)
4878 m_mainWin
->DeleteColumn( col
);
4882 void wxListCtrl::Edit( long item
)
4884 m_mainWin
->EditLabel( item
);
4887 bool wxListCtrl::EnsureVisible( long item
)
4889 m_mainWin
->EnsureVisible( item
);
4893 long wxListCtrl::FindItem( long start
, const wxString
& str
, bool partial
)
4895 return m_mainWin
->FindItem( start
, str
, partial
);
4898 long wxListCtrl::FindItem( long start
, long data
)
4900 return m_mainWin
->FindItem( start
, data
);
4903 long wxListCtrl::FindItem( long WXUNUSED(start
), const wxPoint
& WXUNUSED(pt
),
4904 int WXUNUSED(direction
))
4909 long wxListCtrl::HitTest( const wxPoint
&point
, int &flags
)
4911 return m_mainWin
->HitTest( (int)point
.x
, (int)point
.y
, flags
);
4914 long wxListCtrl::InsertItem( wxListItem
& info
)
4916 m_mainWin
->InsertItem( info
);
4917 return info
.m_itemId
;
4920 long wxListCtrl::InsertItem( long index
, const wxString
&label
)
4923 info
.m_text
= label
;
4924 info
.m_mask
= wxLIST_MASK_TEXT
;
4925 info
.m_itemId
= index
;
4926 return InsertItem( info
);
4929 long wxListCtrl::InsertItem( long index
, int imageIndex
)
4932 info
.m_mask
= wxLIST_MASK_IMAGE
;
4933 info
.m_image
= imageIndex
;
4934 info
.m_itemId
= index
;
4935 return InsertItem( info
);
4938 long wxListCtrl::InsertItem( long index
, const wxString
&label
, int imageIndex
)
4941 info
.m_text
= label
;
4942 info
.m_image
= imageIndex
;
4943 info
.m_mask
= wxLIST_MASK_TEXT
| wxLIST_MASK_IMAGE
;
4944 info
.m_itemId
= index
;
4945 return InsertItem( info
);
4948 long wxListCtrl::InsertColumn( long col
, wxListItem
&item
)
4950 wxASSERT( m_headerWin
);
4951 m_mainWin
->InsertColumn( col
, item
);
4952 m_headerWin
->Refresh();
4957 long wxListCtrl::InsertColumn( long col
, const wxString
&heading
,
4958 int format
, int width
)
4961 item
.m_mask
= wxLIST_MASK_TEXT
| wxLIST_MASK_FORMAT
;
4962 item
.m_text
= heading
;
4965 item
.m_mask
|= wxLIST_MASK_WIDTH
;
4966 item
.m_width
= width
;
4968 item
.m_format
= format
;
4970 return InsertColumn( col
, item
);
4973 bool wxListCtrl::ScrollList( int WXUNUSED(dx
), int WXUNUSED(dy
) )
4979 // fn is a function which takes 3 long arguments: item1, item2, data.
4980 // item1 is the long data associated with a first item (NOT the index).
4981 // item2 is the long data associated with a second item (NOT the index).
4982 // data is the same value as passed to SortItems.
4983 // The return value is a negative number if the first item should precede the second
4984 // item, a positive number of the second item should precede the first,
4985 // or zero if the two items are equivalent.
4986 // data is arbitrary data to be passed to the sort function.
4988 bool wxListCtrl::SortItems( wxListCtrlCompare fn
, long data
)
4990 m_mainWin
->SortItems( fn
, data
);
4994 // ----------------------------------------------------------------------------
4996 // ----------------------------------------------------------------------------
4998 void wxListCtrl::OnSize(wxSizeEvent
& event
)
5003 ResizeReportView(m_mainWin
->HasHeader());
5005 m_mainWin
->RecalculatePositions();
5008 void wxListCtrl::ResizeReportView(bool showHeader
)
5011 GetClientSize( &cw
, &ch
);
5015 m_headerWin
->SetSize( 0, 0, cw
, HEADER_HEIGHT
);
5016 m_mainWin
->SetSize( 0, HEADER_HEIGHT
+ 1, cw
, ch
- HEADER_HEIGHT
- 1 );
5018 else // no header window
5020 m_mainWin
->SetSize( 0, 0, cw
, ch
);
5024 void wxListCtrl::OnIdle( wxIdleEvent
& event
)
5028 // do it only if needed
5029 if ( !m_mainWin
->m_dirty
)
5032 m_mainWin
->RecalculatePositions();
5035 // ----------------------------------------------------------------------------
5037 // ----------------------------------------------------------------------------
5039 bool wxListCtrl::SetBackgroundColour( const wxColour
&colour
)
5043 m_mainWin
->SetBackgroundColour( colour
);
5044 m_mainWin
->m_dirty
= TRUE
;
5050 bool wxListCtrl::SetForegroundColour( const wxColour
&colour
)
5052 if ( !wxWindow::SetForegroundColour( colour
) )
5057 m_mainWin
->SetForegroundColour( colour
);
5058 m_mainWin
->m_dirty
= TRUE
;
5063 m_headerWin
->SetForegroundColour( colour
);
5069 bool wxListCtrl::SetFont( const wxFont
&font
)
5071 if ( !wxWindow::SetFont( font
) )
5076 m_mainWin
->SetFont( font
);
5077 m_mainWin
->m_dirty
= TRUE
;
5082 m_headerWin
->SetFont( font
);
5088 // ----------------------------------------------------------------------------
5089 // methods forwarded to m_mainWin
5090 // ----------------------------------------------------------------------------
5092 #if wxUSE_DRAG_AND_DROP
5094 void wxListCtrl::SetDropTarget( wxDropTarget
*dropTarget
)
5096 m_mainWin
->SetDropTarget( dropTarget
);
5099 wxDropTarget
*wxListCtrl::GetDropTarget() const
5101 return m_mainWin
->GetDropTarget();
5104 #endif // wxUSE_DRAG_AND_DROP
5106 bool wxListCtrl::SetCursor( const wxCursor
&cursor
)
5108 return m_mainWin
? m_mainWin
->wxWindow::SetCursor(cursor
) : FALSE
;
5111 wxColour
wxListCtrl::GetBackgroundColour() const
5113 return m_mainWin
? m_mainWin
->GetBackgroundColour() : wxColour();
5116 wxColour
wxListCtrl::GetForegroundColour() const
5118 return m_mainWin
? m_mainWin
->GetForegroundColour() : wxColour();
5121 bool wxListCtrl::DoPopupMenu( wxMenu
*menu
, int x
, int y
)
5124 return m_mainWin
->PopupMenu( menu
, x
, y
);
5127 #endif // wxUSE_MENUS
5130 void wxListCtrl::SetFocus()
5132 /* The test in window.cpp fails as we are a composite
5133 window, so it checks against "this", but not m_mainWin. */
5134 if ( FindFocus() != this )
5135 m_mainWin
->SetFocus();
5138 // ----------------------------------------------------------------------------
5139 // virtual list control support
5140 // ----------------------------------------------------------------------------
5142 wxString
wxListCtrl::OnGetItemText(long item
, long col
) const
5144 // this is a pure virtual function, in fact - which is not really pure
5145 // because the controls which are not virtual don't need to implement it
5146 wxFAIL_MSG( _T("not supposed to be called") );
5148 return wxEmptyString
;
5151 int wxListCtrl::OnGetItemImage(long item
) const
5154 wxFAIL_MSG( _T("not supposed to be called") );
5159 wxListItemAttr
*wxListCtrl::OnGetItemAttr(long item
) const
5161 wxASSERT_MSG( item
>= 0 && item
< GetItemCount(),
5162 _T("invalid item index in OnGetItemAttr()") );
5164 // no attributes by default
5168 void wxListCtrl::SetItemCount(long count
)
5170 wxASSERT_MSG( IsVirtual(), _T("this is for virtual controls only") );
5172 m_mainWin
->SetItemCount(count
);
5175 void wxListCtrl::RefreshItem(long item
)
5177 m_mainWin
->RefreshLine(item
);
5180 void wxListCtrl::RefreshItems(long itemFrom
, long itemTo
)
5182 m_mainWin
->RefreshLines(itemFrom
, itemTo
);
5185 void wxListCtrl::Freeze()
5187 m_mainWin
->Freeze();
5190 void wxListCtrl::Thaw()
5195 #endif // wxUSE_LISTCTRL