1 /////////////////////////////////////////////////////////////////////////////
2 // Name: generic/listctrl.cpp
3 // Purpose: generic implementation of wxListCtrl
4 // Author: Robert Roebling
5 // Vadim Zeitlin (virtual list control support)
7 // Copyright: (c) 1998 Robert Roebling
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
14 1. we need to implement searching/sorting for virtual controls somehow
15 ?2. when changing selection the lines are refreshed twice
18 // ============================================================================
20 // ============================================================================
22 // ----------------------------------------------------------------------------
24 // ----------------------------------------------------------------------------
27 #pragma implementation "listctrl.h"
28 #pragma implementation "listctrlbase.h"
31 // For compilers that support precompilation, includes "wx.h".
32 #include "wx/wxprec.h"
40 #include "wx/dcscreen.h"
42 #include "wx/listctrl.h"
43 #include "wx/imaglist.h"
44 #include "wx/dynarray.h"
48 #include "wx/gtk/win_gtk.h"
51 // ----------------------------------------------------------------------------
53 // ----------------------------------------------------------------------------
55 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_BEGIN_DRAG
)
56 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_BEGIN_RDRAG
)
57 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_BEGIN_LABEL_EDIT
)
58 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_END_LABEL_EDIT
)
59 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_DELETE_ITEM
)
60 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_DELETE_ALL_ITEMS
)
61 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_GET_INFO
)
62 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_SET_INFO
)
63 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_ITEM_SELECTED
)
64 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_ITEM_DESELECTED
)
65 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_KEY_DOWN
)
66 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_INSERT_ITEM
)
67 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_COL_CLICK
)
68 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_COL_RIGHT_CLICK
)
69 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_COL_BEGIN_DRAG
)
70 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_COL_DRAGGING
)
71 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_COL_END_DRAG
)
72 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_ITEM_RIGHT_CLICK
)
73 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_ITEM_MIDDLE_CLICK
)
74 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_ITEM_ACTIVATED
)
75 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_CACHE_HINT
)
77 // ----------------------------------------------------------------------------
79 // ----------------------------------------------------------------------------
81 // the height of the header window (FIXME: should depend on its font!)
82 static const int HEADER_HEIGHT
= 23;
84 // the scrollbar units
85 static const int SCROLL_UNIT_X
= 15;
86 static const int SCROLL_UNIT_Y
= 15;
88 // the spacing between the lines (in report mode)
89 static const int LINE_SPACING
= 0;
91 // extra margins around the text label
92 static const int EXTRA_WIDTH
= 3;
93 static const int EXTRA_HEIGHT
= 4;
95 // offset for the header window
96 static const int HEADER_OFFSET_X
= 1;
97 static const int HEADER_OFFSET_Y
= 1;
99 // when autosizing the columns, add some slack
100 static const int AUTOSIZE_COL_MARGIN
= 10;
102 // default and minimal widths for the header columns
103 static const int WIDTH_COL_DEFAULT
= 80;
104 static const int WIDTH_COL_MIN
= 10;
106 // the space between the image and the text in the report mode
107 static const int IMAGE_MARGIN_IN_REPORT_MODE
= 5;
109 // ============================================================================
111 // ============================================================================
113 // ----------------------------------------------------------------------------
115 // ----------------------------------------------------------------------------
117 int CMPFUNC_CONV
wxSizeTCmpFn(size_t n1
, size_t n2
) { return n1
- n2
; }
119 WX_DEFINE_SORTED_EXPORTED_ARRAY(size_t, wxIndexArray
);
121 // this class is used to store the selected items in the virtual list control
122 // (but it is not tied to list control and so can be used with other controls
123 // such as wxListBox in wxUniv)
125 // the idea is to make it really smart later (i.e. store the selections as an
126 // array of ranes + individual items) but, as I don't have time to do it now
127 // (this would require writing code to merge/break ranges and much more) keep
128 // it simple but define a clean interface to it which allows it to be made
130 class WXDLLEXPORT wxSelectionStore
133 wxSelectionStore() : m_itemsSel(wxSizeTCmpFn
) { Init(); }
135 // set the total number of items we handle
136 void SetItemCount(size_t count
) { m_count
= count
; }
138 // special case of SetItemCount(0)
139 void Clear() { m_itemsSel
.Clear(); m_count
= 0; }
141 // must be called when a new item is inserted/added
142 void OnItemAdd(size_t item
) { wxFAIL_MSG( _T("TODO") ); }
144 // must be called when an item is deleted
145 void OnItemDelete(size_t item
);
147 // select one item, use SelectRange() insted if possible!
149 // returns true if the items selection really changed
150 bool SelectItem(size_t item
, bool select
= TRUE
);
152 // select the range of items
154 // return true and fill the itemsChanged array with the indices of items
155 // which have changed state if "few" of them did, otherwise return false
156 // (meaning that too many items changed state to bother counting them
158 bool SelectRange(size_t itemFrom
, size_t itemTo
,
160 wxArrayInt
*itemsChanged
= NULL
);
162 // return true if the given item is selected
163 bool IsSelected(size_t item
) const;
165 // return the total number of selected items
166 size_t GetSelectedCount() const
168 return m_defaultState
? m_count
- m_itemsSel
.GetCount()
169 : m_itemsSel
.GetCount();
174 void Init() { m_defaultState
= FALSE
; }
176 // the total number of items we handle
179 // the default state: normally, FALSE (i.e. off) but maybe set to TRUE if
180 // there are more selected items than non selected ones - this allows to
181 // handle selection of all items efficiently
184 // the array of items whose selection state is different from default
185 wxIndexArray m_itemsSel
;
187 DECLARE_NO_COPY_CLASS(wxSelectionStore
)
190 //-----------------------------------------------------------------------------
191 // wxListItemData (internal)
192 //-----------------------------------------------------------------------------
194 class WXDLLEXPORT wxListItemData
197 wxListItemData(wxListMainWindow
*owner
);
200 void SetItem( const wxListItem
&info
);
201 void SetImage( int image
) { m_image
= image
; }
202 void SetData( long data
) { m_data
= data
; }
203 void SetPosition( int x
, int y
);
204 void SetSize( int width
, int height
);
206 bool HasText() const { return !m_text
.empty(); }
207 const wxString
& GetText() const { return m_text
; }
208 void SetText(const wxString
& text
) { m_text
= text
; }
210 // we can't use empty string for measuring the string width/height, so
211 // always return something
212 wxString
GetTextForMeasuring() const
214 wxString s
= GetText();
221 bool IsHit( int x
, int y
) const;
225 int GetWidth() const;
226 int GetHeight() const;
228 int GetImage() const { return m_image
; }
229 bool HasImage() const { return GetImage() != -1; }
231 void GetItem( wxListItem
&info
) const;
233 void SetAttr(wxListItemAttr
*attr
) { m_attr
= attr
; }
234 wxListItemAttr
*GetAttr() const { return m_attr
; }
237 // the item image or -1
240 // user data associated with the item
243 // the item coordinates are not used in report mode, instead this pointer
244 // is NULL and the owner window is used to retrieve the item position and
248 // the list ctrl we are in
249 wxListMainWindow
*m_owner
;
251 // custom attributes or NULL
252 wxListItemAttr
*m_attr
;
255 // common part of all ctors
261 //-----------------------------------------------------------------------------
262 // wxListHeaderData (internal)
263 //-----------------------------------------------------------------------------
265 class WXDLLEXPORT wxListHeaderData
: public wxObject
269 wxListHeaderData( const wxListItem
&info
);
270 void SetItem( const wxListItem
&item
);
271 void SetPosition( int x
, int y
);
272 void SetWidth( int w
);
273 void SetFormat( int format
);
274 void SetHeight( int h
);
275 bool HasImage() const;
277 bool HasText() const { return !m_text
.empty(); }
278 const wxString
& GetText() const { return m_text
; }
279 void SetText(const wxString
& text
) { m_text
= text
; }
281 void GetItem( wxListItem
&item
);
283 bool IsHit( int x
, int y
) const;
284 int GetImage() const;
285 int GetWidth() const;
286 int GetFormat() const;
302 //-----------------------------------------------------------------------------
303 // wxListLineData (internal)
304 //-----------------------------------------------------------------------------
306 WX_DECLARE_LIST(wxListItemData
, wxListItemDataList
);
307 #include "wx/listimpl.cpp"
308 WX_DEFINE_LIST(wxListItemDataList
);
310 class WXDLLEXPORT wxListLineData
313 // the list of subitems: only may have more than one item in report mode
314 wxListItemDataList m_items
;
316 // this is not used in report view
328 // the part to be highlighted
329 wxRect m_rectHighlight
;
332 // is this item selected? [NB: not used in virtual mode]
335 // back pointer to the list ctrl
336 wxListMainWindow
*m_owner
;
339 wxListLineData(wxListMainWindow
*owner
);
341 ~wxListLineData() { delete m_gi
; }
343 // are we in report mode?
344 inline bool InReportView() const;
346 // are we in virtual report mode?
347 inline bool IsVirtual() const;
349 // these 2 methods shouldn't be called for report view controls, in that
350 // case we determine our position/size ourselves
352 // calculate the size of the line
353 void CalculateSize( wxDC
*dc
, int spacing
);
355 // remember the position this line appears at
356 void SetPosition( int x
, int y
, int window_width
, int spacing
);
360 void SetImage( int image
) { SetImage(0, image
); }
361 int GetImage() const { return GetImage(0); }
362 bool HasImage() const { return GetImage() != -1; }
363 bool HasText() const { return !GetText(0).empty(); }
365 void SetItem( int index
, const wxListItem
&info
);
366 void GetItem( int index
, wxListItem
&info
);
368 wxString
GetText(int index
) const;
369 void SetText( int index
, const wxString s
);
371 wxListItemAttr
*GetAttr() const;
372 void SetAttr(wxListItemAttr
*attr
);
374 // return true if the highlighting really changed
375 bool Highlight( bool on
);
377 void ReverseHighlight();
379 bool IsHighlighted() const
381 wxASSERT_MSG( !IsVirtual(), _T("unexpected call to IsHighlighted") );
383 return m_highlighted
;
386 // draw the line on the given DC in icon/list mode
387 void Draw( wxDC
*dc
);
389 // the same in report mode
390 void DrawInReportMode( wxDC
*dc
,
392 const wxRect
& rectHL
,
396 // set the line to contain num items (only can be > 1 in report mode)
397 void InitItems( int num
);
399 // get the mode (i.e. style) of the list control
400 inline int GetMode() const;
402 // prepare the DC for drawing with these item's attributes, return true if
403 // we need to draw the items background to highlight it, false otherwise
404 bool SetAttributes(wxDC
*dc
,
405 const wxListItemAttr
*attr
,
408 // these are only used by GetImage/SetImage above, we don't support images
409 // with subitems at the public API level yet
410 void SetImage( int index
, int image
);
411 int GetImage( int index
) const;
414 WX_DECLARE_EXPORTED_OBJARRAY(wxListLineData
, wxListLineDataArray
);
415 #include "wx/arrimpl.cpp"
416 WX_DEFINE_OBJARRAY(wxListLineDataArray
);
418 //-----------------------------------------------------------------------------
419 // wxListHeaderWindow (internal)
420 //-----------------------------------------------------------------------------
422 class WXDLLEXPORT wxListHeaderWindow
: public wxWindow
425 wxListMainWindow
*m_owner
;
426 wxCursor
*m_currentCursor
;
427 wxCursor
*m_resizeCursor
;
430 // column being resized
433 // divider line position in logical (unscrolled) coords
436 // minimal position beyond which the divider line can't be dragged in
441 wxListHeaderWindow();
443 wxListHeaderWindow( wxWindow
*win
,
445 wxListMainWindow
*owner
,
446 const wxPoint
&pos
= wxDefaultPosition
,
447 const wxSize
&size
= wxDefaultSize
,
449 const wxString
&name
= "wxlistctrlcolumntitles" );
451 virtual ~wxListHeaderWindow();
453 void DoDrawRect( wxDC
*dc
, int x
, int y
, int w
, int h
);
455 void AdjustDC(wxDC
& dc
);
457 void OnPaint( wxPaintEvent
&event
);
458 void OnMouse( wxMouseEvent
&event
);
459 void OnSetFocus( wxFocusEvent
&event
);
465 // common part of all ctors
468 DECLARE_DYNAMIC_CLASS(wxListHeaderWindow
)
469 DECLARE_EVENT_TABLE()
472 //-----------------------------------------------------------------------------
473 // wxListRenameTimer (internal)
474 //-----------------------------------------------------------------------------
476 class WXDLLEXPORT wxListRenameTimer
: public wxTimer
479 wxListMainWindow
*m_owner
;
482 wxListRenameTimer( wxListMainWindow
*owner
);
486 //-----------------------------------------------------------------------------
487 // wxListTextCtrl (internal)
488 //-----------------------------------------------------------------------------
490 class WXDLLEXPORT wxListTextCtrl
: public wxTextCtrl
495 wxListMainWindow
*m_owner
;
496 wxString m_startValue
;
500 wxListTextCtrl( wxWindow
*parent
, const wxWindowID id
,
501 bool *accept
, wxString
*res
, wxListMainWindow
*owner
,
502 const wxString
&value
= "",
503 const wxPoint
&pos
= wxDefaultPosition
, const wxSize
&size
= wxDefaultSize
,
505 const wxValidator
& validator
= wxDefaultValidator
,
506 const wxString
&name
= "listctrltextctrl" );
507 void OnChar( wxKeyEvent
&event
);
508 void OnKeyUp( wxKeyEvent
&event
);
509 void OnKillFocus( wxFocusEvent
&event
);
512 DECLARE_DYNAMIC_CLASS(wxListTextCtrl
);
513 DECLARE_EVENT_TABLE()
516 //-----------------------------------------------------------------------------
517 // wxListMainWindow (internal)
518 //-----------------------------------------------------------------------------
520 WX_DECLARE_LIST(wxListHeaderData
, wxListHeaderDataList
);
521 #include "wx/listimpl.cpp"
522 WX_DEFINE_LIST(wxListHeaderDataList
);
524 class WXDLLEXPORT wxListMainWindow
: public wxScrolledWindow
528 wxListMainWindow( wxWindow
*parent
,
530 const wxPoint
& pos
= wxDefaultPosition
,
531 const wxSize
& size
= wxDefaultSize
,
533 const wxString
&name
= _T("listctrlmainwindow") );
535 virtual ~wxListMainWindow();
537 bool HasFlag(int flag
) const { return m_parent
->HasFlag(flag
); }
539 // return true if this is a virtual list control
540 bool IsVirtual() const { return HasFlag(wxLC_VIRTUAL
); }
542 // return true if the control is in report mode
543 bool InReportView() const { return HasFlag(wxLC_REPORT
); }
545 // return true if we are in single selection mode, false if multi sel
546 bool IsSingleSel() const { return HasFlag(wxLC_SINGLE_SEL
); }
548 // do we have a header window?
549 bool HasHeader() const
550 { return HasFlag(wxLC_REPORT
) && !HasFlag(wxLC_NO_HEADER
); }
552 void HighlightAll( bool on
);
554 // all these functions only do something if the line is currently visible
556 // change the line "selected" state, return TRUE if it really changed
557 bool HighlightLine( size_t line
, bool highlight
= TRUE
);
559 // as HighlightLine() but do it for the range of lines: this is incredibly
560 // more efficient for virtual list controls!
562 // NB: unlike HighlightLine() this one does refresh the lines on screen
563 void HighlightLines( size_t lineFrom
, size_t lineTo
, bool on
= TRUE
);
565 // toggle the line state and refresh it
566 void ReverseHighlight( size_t line
)
567 { HighlightLine(line
, !IsHighlighted(line
)); RefreshLine(line
); }
569 // return true if the line is highlighted
570 bool IsHighlighted(size_t line
) const;
572 // refresh one or several lines at once
573 void RefreshLine( size_t line
);
574 void RefreshLines( size_t lineFrom
, size_t lineTo
);
576 // refresh all selected items
577 void RefreshSelected();
579 // refresh all lines below the given one: the difference with
580 // RefreshLines() is that the index here might not be a valid one (happens
581 // when the last line is deleted)
582 void RefreshAfter( size_t lineFrom
);
584 // the methods which are forwarded to wxListLineData itself in list/icon
585 // modes but are here because the lines don't store their positions in the
588 // get the bound rect for the entire line
589 wxRect
GetLineRect(size_t line
) const;
591 // get the bound rect of the label
592 wxRect
GetLineLabelRect(size_t line
) const;
594 // get the bound rect of the items icon (only may be called if we do have
596 wxRect
GetLineIconRect(size_t line
) const;
598 // get the rect to be highlighted when the item has focus
599 wxRect
GetLineHighlightRect(size_t line
) const;
601 // get the size of the total line rect
602 wxSize
GetLineSize(size_t line
) const
603 { return GetLineRect(line
).GetSize(); }
605 // return the hit code for the corresponding position (in this line)
606 long HitTestLine(size_t line
, int x
, int y
) const;
608 // bring the selected item into view, scrolling to it if necessary
609 void MoveToItem(size_t item
);
611 // bring the current item into view
612 void MoveToFocus() { MoveToItem(m_current
); }
614 void EditLabel( long item
);
615 void OnRenameTimer();
616 void OnRenameAccept();
618 void OnMouse( wxMouseEvent
&event
);
620 // called to switch the selection from the current item to newCurrent,
621 void OnArrowChar( size_t newCurrent
, const wxKeyEvent
& event
);
623 void OnChar( wxKeyEvent
&event
);
624 void OnKeyDown( wxKeyEvent
&event
);
625 void OnSetFocus( wxFocusEvent
&event
);
626 void OnKillFocus( wxFocusEvent
&event
);
627 void OnScroll(wxScrollWinEvent
& event
) ;
629 void OnPaint( wxPaintEvent
&event
);
631 void DrawImage( int index
, wxDC
*dc
, int x
, int y
);
632 void GetImageSize( int index
, int &width
, int &height
) const;
633 int GetTextLength( const wxString
&s
) const;
635 void SetImageList( wxImageList
*imageList
, int which
);
636 void SetItemSpacing( int spacing
, bool isSmall
= FALSE
);
637 int GetItemSpacing( bool isSmall
= FALSE
);
639 void SetColumn( int col
, wxListItem
&item
);
640 void SetColumnWidth( int col
, int width
);
641 void GetColumn( int col
, wxListItem
&item
) const;
642 int GetColumnWidth( int col
) const;
643 int GetColumnCount() const { return m_columns
.GetCount(); }
645 // returns the sum of the heights of all columns
646 int GetHeaderWidth() const;
648 int GetCountPerPage() const;
650 void SetItem( wxListItem
&item
);
651 void GetItem( wxListItem
&item
);
652 void SetItemState( long item
, long state
, long stateMask
);
653 int GetItemState( long item
, long stateMask
);
654 void GetItemRect( long index
, wxRect
&rect
);
655 bool GetItemPosition( long item
, wxPoint
& pos
);
656 int GetSelectedItemCount();
658 // set the scrollbars and update the positions of the items
659 void RecalculatePositions(bool noRefresh
= FALSE
);
661 // refresh the window and the header
664 long GetNextItem( long item
, int geometry
, int state
);
665 void DeleteItem( long index
);
666 void DeleteAllItems();
667 void DeleteColumn( int col
);
668 void DeleteEverything();
669 void EnsureVisible( long index
);
670 long FindItem( long start
, const wxString
& str
, bool partial
= FALSE
);
671 long FindItem( long start
, long data
);
672 long HitTest( int x
, int y
, int &flags
);
673 void InsertItem( wxListItem
&item
);
674 void InsertColumn( long col
, wxListItem
&item
);
675 void SortItems( wxListCtrlCompare fn
, long data
);
677 size_t GetItemCount() const;
678 bool IsEmpty() const { return GetItemCount() == 0; }
679 void SetItemCount(long count
);
681 void ResetCurrent() { m_current
= (size_t)-1; }
682 bool HasCurrent() const { return m_current
!= (size_t)-1; }
684 // send out a wxListEvent
685 void SendNotify( size_t line
,
687 wxPoint point
= wxDefaultPosition
);
689 // override base class virtual to reset m_lineHeight when the font changes
690 virtual bool SetFont(const wxFont
& font
)
692 if ( !wxScrolledWindow::SetFont(font
) )
700 // these are for wxListLineData usage only
702 // get the backpointer to the list ctrl
703 wxListCtrl
*GetListCtrl() const
705 return wxStaticCast(GetParent(), wxListCtrl
);
708 // get the height of all lines (assuming they all do have the same height)
709 wxCoord
GetLineHeight() const;
711 // get the y position of the given line (only for report view)
712 wxCoord
GetLineY(size_t line
) const;
714 // get the brush to use for the item highlighting
715 wxBrush
*GetHighlightBrush() const
717 return m_hasFocus
? m_highlightBrush
: m_highlightUnfocusedBrush
;
721 // the array of all line objects for a non virtual list control
722 wxListLineDataArray m_lines
;
724 // the list of column objects
725 wxListHeaderDataList m_columns
;
727 // currently focused item or -1
730 // the item currently being edited or -1
731 size_t m_currentEdit
;
733 // the number of lines per page
736 // this flag is set when something which should result in the window
737 // redrawing happens (i.e. an item was added or deleted, or its appearance
738 // changed) and OnPaint() doesn't redraw the window while it is set which
739 // allows to minimize the number of repaintings when a lot of items are
740 // being added. The real repainting occurs only after the next OnIdle()
744 wxColour
*m_highlightColour
;
747 wxImageList
*m_small_image_list
;
748 wxImageList
*m_normal_image_list
;
750 int m_normal_spacing
;
754 wxTimer
*m_renameTimer
;
756 wxString m_renameRes
;
761 // for double click logic
762 size_t m_lineLastClicked
,
763 m_lineBeforeLastClicked
;
766 // the total count of items in a virtual list control
769 // the object maintaining the items selection state, only used in virtual
771 wxSelectionStore m_selStore
;
773 // common part of all ctors
776 // intiialize m_[xy]Scroll
777 void InitScrolling();
779 // get the line data for the given index
780 wxListLineData
*GetLine(size_t n
) const
782 wxASSERT_MSG( n
!= (size_t)-1, _T("invalid line index") );
786 wxConstCast(this, wxListMainWindow
)->CacheLineData(n
);
794 // get a dummy line which can be used for geometry calculations and such:
795 // you must use GetLine() if you want to really draw the line
796 wxListLineData
*GetDummyLine() const;
798 // cache the line data of the n-th line in m_lines[0]
799 void CacheLineData(size_t line
);
801 // get the range of visible lines
802 void GetVisibleLinesRange(size_t *from
, size_t *to
);
804 // force us to recalculate the range of visible lines
805 void ResetVisibleLinesRange() { m_lineFrom
= (size_t)-1; }
807 // get the colour to be used for drawing the rules
808 wxColour
GetRuleColour() const
813 return wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DLIGHT
);
818 // initialize the current item if needed
819 void UpdateCurrent();
821 // delete all items but don't refresh: called from dtor
822 void DoDeleteAllItems();
824 // called when an item is [un]focuded, i.e. becomes [not] current
827 void OnFocusLine( size_t line
);
828 void OnUnfocusLine( size_t line
);
830 // the height of one line using the current font
831 wxCoord m_lineHeight
;
833 // the total header width or 0 if not calculated yet
834 wxCoord m_headerWidth
;
836 // the first and last lines being shown on screen right now (inclusive),
837 // both may be -1 if they must be calculated so never access them directly:
838 // use GetVisibleLinesRange() above instead
842 // the brushes to use for item highlighting when we do/don't have focus
843 wxBrush
*m_highlightBrush
,
844 *m_highlightUnfocusedBrush
;
846 DECLARE_DYNAMIC_CLASS(wxListMainWindow
);
847 DECLARE_EVENT_TABLE()
850 // ============================================================================
852 // ============================================================================
854 // ----------------------------------------------------------------------------
856 // ----------------------------------------------------------------------------
858 bool wxSelectionStore::IsSelected(size_t item
) const
860 bool isSel
= m_itemsSel
.Index(item
) != wxNOT_FOUND
;
862 // if the default state is to be selected, being in m_itemsSel means that
863 // the item is not selected, so we have to inverse the logic
864 return m_defaultState
? !isSel
: isSel
;
867 bool wxSelectionStore::SelectItem(size_t item
, bool select
)
869 // search for the item ourselves as like this we get the index where to
870 // insert it later if needed, so we do only one search in the array instead
871 // of two (adding item to a sorted array requires a search)
872 size_t index
= m_itemsSel
.IndexForInsert(item
);
873 bool isSel
= index
< m_itemsSel
.GetCount() && m_itemsSel
[index
] == item
;
875 if ( select
!= m_defaultState
)
879 m_itemsSel
.AddAt(item
, index
);
884 else // reset to default state
888 m_itemsSel
.RemoveAt(index
);
896 bool wxSelectionStore::SelectRange(size_t itemFrom
, size_t itemTo
,
898 wxArrayInt
*itemsChanged
)
900 // 100 is hardcoded but it shouldn't matter much: the important thing is
901 // that we don't refresh everything when really few (e.g. 1 or 2) items
903 static const size_t MANY_ITEMS
= 100;
905 wxASSERT_MSG( itemFrom
<= itemTo
, _T("should be in order") );
907 // are we going to have more [un]selected items than the other ones?
908 if ( itemTo
- itemFrom
> m_count
/2 )
910 if ( select
!= m_defaultState
)
912 // the default state now becomes the same as 'select'
913 m_defaultState
= select
;
915 // so all the old selections (which had state select) shouldn't be
916 // selected any more, but all the other ones should
917 wxIndexArray selOld
= m_itemsSel
;
920 // TODO: it should be possible to optimize the searches a bit
921 // knowing the possible range
924 for ( item
= 0; item
< itemFrom
; item
++ )
926 if ( selOld
.Index(item
) == wxNOT_FOUND
)
927 m_itemsSel
.Add(item
);
930 for ( item
= itemTo
+ 1; item
< m_count
; item
++ )
932 if ( selOld
.Index(item
) == wxNOT_FOUND
)
933 m_itemsSel
.Add(item
);
936 // many items (> half) changed state
939 else // select == m_defaultState
941 // get the inclusive range of items between itemFrom and itemTo
942 size_t count
= m_itemsSel
.GetCount(),
943 start
= m_itemsSel
.IndexForInsert(itemFrom
),
944 end
= m_itemsSel
.IndexForInsert(itemTo
);
946 if ( start
== count
|| m_itemsSel
[start
] < itemFrom
)
951 if ( end
== count
|| m_itemsSel
[end
] > itemTo
)
958 // delete all of them (from end to avoid changing indices)
959 for ( int i
= end
; i
>= (int)start
; i
-- )
963 if ( itemsChanged
->GetCount() > MANY_ITEMS
)
965 // stop counting (see comment below)
969 itemsChanged
->Add(m_itemsSel
[i
]);
972 m_itemsSel
.RemoveAt(i
);
977 else // "few" items change state
981 itemsChanged
->Empty();
984 // just add the items to the selection
985 for ( size_t item
= itemFrom
; item
<= itemTo
; item
++ )
987 if ( SelectItem(item
, select
) && itemsChanged
)
989 itemsChanged
->Add(item
);
991 if ( itemsChanged
->GetCount() > MANY_ITEMS
)
993 // stop counting them, we'll just eat gobs of memory
994 // for nothing at all - faster to refresh everything in
1002 // we set it to NULL if there are many items changing state
1003 return itemsChanged
!= NULL
;
1006 void wxSelectionStore::OnItemDelete(size_t item
)
1008 size_t count
= m_itemsSel
.GetCount(),
1009 i
= m_itemsSel
.IndexForInsert(item
);
1011 if ( i
< count
&& m_itemsSel
[i
] == item
)
1013 // this item itself was in m_itemsSel, remove it from there
1014 m_itemsSel
.RemoveAt(i
);
1019 // and adjust the index of all which follow it
1022 // all following elements must be greater than the one we deleted
1023 wxASSERT_MSG( m_itemsSel
[i
] > item
, _T("logic error") );
1029 //-----------------------------------------------------------------------------
1031 //-----------------------------------------------------------------------------
1033 wxListItemData::~wxListItemData()
1035 // in the virtual list control the attributes are managed by the main
1036 // program, so don't delete them
1037 if ( !m_owner
->IsVirtual() )
1045 void wxListItemData::Init()
1053 wxListItemData::wxListItemData(wxListMainWindow
*owner
)
1059 if ( owner
->InReportView() )
1065 m_rect
= new wxRect
;
1069 void wxListItemData::SetItem( const wxListItem
&info
)
1071 if ( info
.m_mask
& wxLIST_MASK_TEXT
)
1072 SetText(info
.m_text
);
1073 if ( info
.m_mask
& wxLIST_MASK_IMAGE
)
1074 m_image
= info
.m_image
;
1075 if ( info
.m_mask
& wxLIST_MASK_DATA
)
1076 m_data
= info
.m_data
;
1078 if ( info
.HasAttributes() )
1081 *m_attr
= *info
.GetAttributes();
1083 m_attr
= new wxListItemAttr(*info
.GetAttributes());
1091 m_rect
->width
= info
.m_width
;
1095 void wxListItemData::SetPosition( int x
, int y
)
1097 wxCHECK_RET( m_rect
, _T("unexpected SetPosition() call") );
1103 void wxListItemData::SetSize( int width
, int height
)
1105 wxCHECK_RET( m_rect
, _T("unexpected SetSize() call") );
1108 m_rect
->width
= width
;
1110 m_rect
->height
= height
;
1113 bool wxListItemData::IsHit( int x
, int y
) const
1115 wxCHECK_MSG( m_rect
, FALSE
, _T("can't be called in this mode") );
1117 return wxRect(GetX(), GetY(), GetWidth(), GetHeight()).Inside(x
, y
);
1120 int wxListItemData::GetX() const
1122 wxCHECK_MSG( m_rect
, 0, _T("can't be called in this mode") );
1127 int wxListItemData::GetY() const
1129 wxCHECK_MSG( m_rect
, 0, _T("can't be called in this mode") );
1134 int wxListItemData::GetWidth() const
1136 wxCHECK_MSG( m_rect
, 0, _T("can't be called in this mode") );
1138 return m_rect
->width
;
1141 int wxListItemData::GetHeight() const
1143 wxCHECK_MSG( m_rect
, 0, _T("can't be called in this mode") );
1145 return m_rect
->height
;
1148 void wxListItemData::GetItem( wxListItem
&info
) const
1150 info
.m_text
= m_text
;
1151 info
.m_image
= m_image
;
1152 info
.m_data
= m_data
;
1156 if ( m_attr
->HasTextColour() )
1157 info
.SetTextColour(m_attr
->GetTextColour());
1158 if ( m_attr
->HasBackgroundColour() )
1159 info
.SetBackgroundColour(m_attr
->GetBackgroundColour());
1160 if ( m_attr
->HasFont() )
1161 info
.SetFont(m_attr
->GetFont());
1165 //-----------------------------------------------------------------------------
1167 //-----------------------------------------------------------------------------
1169 void wxListHeaderData::Init()
1180 wxListHeaderData::wxListHeaderData()
1185 wxListHeaderData::wxListHeaderData( const wxListItem
&item
)
1192 void wxListHeaderData::SetItem( const wxListItem
&item
)
1194 m_mask
= item
.m_mask
;
1196 if ( m_mask
& wxLIST_MASK_TEXT
)
1197 m_text
= item
.m_text
;
1199 if ( m_mask
& wxLIST_MASK_IMAGE
)
1200 m_image
= item
.m_image
;
1202 if ( m_mask
& wxLIST_MASK_FORMAT
)
1203 m_format
= item
.m_format
;
1205 if ( m_mask
& wxLIST_MASK_WIDTH
)
1206 SetWidth(item
.m_width
);
1209 void wxListHeaderData::SetPosition( int x
, int y
)
1215 void wxListHeaderData::SetHeight( int h
)
1220 void wxListHeaderData::SetWidth( int w
)
1224 m_width
= WIDTH_COL_DEFAULT
;
1225 else if (m_width
< WIDTH_COL_MIN
)
1226 m_width
= WIDTH_COL_MIN
;
1229 void wxListHeaderData::SetFormat( int format
)
1234 bool wxListHeaderData::HasImage() const
1236 return m_image
!= -1;
1239 bool wxListHeaderData::IsHit( int x
, int y
) const
1241 return ((x
>= m_xpos
) && (x
<= m_xpos
+m_width
) && (y
>= m_ypos
) && (y
<= m_ypos
+m_height
));
1244 void wxListHeaderData::GetItem( wxListItem
& item
)
1246 item
.m_mask
= m_mask
;
1247 item
.m_text
= m_text
;
1248 item
.m_image
= m_image
;
1249 item
.m_format
= m_format
;
1250 item
.m_width
= m_width
;
1253 int wxListHeaderData::GetImage() const
1258 int wxListHeaderData::GetWidth() const
1263 int wxListHeaderData::GetFormat() const
1268 //-----------------------------------------------------------------------------
1270 //-----------------------------------------------------------------------------
1272 inline int wxListLineData::GetMode() const
1274 return m_owner
->GetListCtrl()->GetWindowStyleFlag() & wxLC_MASK_TYPE
;
1277 inline bool wxListLineData::InReportView() const
1279 return m_owner
->HasFlag(wxLC_REPORT
);
1282 inline bool wxListLineData::IsVirtual() const
1284 return m_owner
->IsVirtual();
1287 wxListLineData::wxListLineData( wxListMainWindow
*owner
)
1290 m_items
.DeleteContents( TRUE
);
1292 if ( InReportView() )
1298 m_gi
= new GeometryInfo
;
1301 m_highlighted
= FALSE
;
1303 InitItems( GetMode() == wxLC_REPORT
? m_owner
->GetColumnCount() : 1 );
1306 void wxListLineData::CalculateSize( wxDC
*dc
, int spacing
)
1308 wxListItemDataList::Node
*node
= m_items
.GetFirst();
1309 wxCHECK_RET( node
, _T("no subitems at all??") );
1311 wxListItemData
*item
= node
->GetData();
1313 switch ( GetMode() )
1316 case wxLC_SMALL_ICON
:
1318 m_gi
->m_rectAll
.width
= spacing
;
1320 wxString s
= item
->GetText();
1326 m_gi
->m_rectLabel
.width
=
1327 m_gi
->m_rectLabel
.height
= 0;
1331 dc
->GetTextExtent( s
, &lw
, &lh
);
1332 if (lh
< SCROLL_UNIT_Y
)
1337 m_gi
->m_rectAll
.height
= spacing
+ lh
;
1339 m_gi
->m_rectAll
.width
= lw
;
1341 m_gi
->m_rectLabel
.width
= lw
;
1342 m_gi
->m_rectLabel
.height
= lh
;
1345 if (item
->HasImage())
1348 m_owner
->GetImageSize( item
->GetImage(), w
, h
);
1349 m_gi
->m_rectIcon
.width
= w
+ 8;
1350 m_gi
->m_rectIcon
.height
= h
+ 8;
1352 if ( m_gi
->m_rectIcon
.width
> m_gi
->m_rectAll
.width
)
1353 m_gi
->m_rectAll
.width
= m_gi
->m_rectIcon
.width
;
1354 if ( m_gi
->m_rectIcon
.height
+ lh
> m_gi
->m_rectAll
.height
- 4 )
1355 m_gi
->m_rectAll
.height
= m_gi
->m_rectIcon
.height
+ lh
+ 4;
1358 if ( item
->HasText() )
1360 m_gi
->m_rectHighlight
.width
= m_gi
->m_rectLabel
.width
;
1361 m_gi
->m_rectHighlight
.height
= m_gi
->m_rectLabel
.height
;
1363 else // no text, highlight the icon
1365 m_gi
->m_rectHighlight
.width
= m_gi
->m_rectIcon
.width
;
1366 m_gi
->m_rectHighlight
.height
= m_gi
->m_rectIcon
.height
;
1373 wxString s
= item
->GetTextForMeasuring();
1376 dc
->GetTextExtent( s
, &lw
, &lh
);
1377 if (lh
< SCROLL_UNIT_Y
)
1382 m_gi
->m_rectLabel
.width
= lw
;
1383 m_gi
->m_rectLabel
.height
= lh
;
1385 m_gi
->m_rectAll
.width
= lw
;
1386 m_gi
->m_rectAll
.height
= lh
;
1388 if (item
->HasImage())
1391 m_owner
->GetImageSize( item
->GetImage(), w
, h
);
1392 m_gi
->m_rectIcon
.width
= w
;
1393 m_gi
->m_rectIcon
.height
= h
;
1395 m_gi
->m_rectAll
.width
+= 4 + w
;
1396 if (h
> m_gi
->m_rectAll
.height
)
1397 m_gi
->m_rectAll
.height
= h
;
1400 m_gi
->m_rectHighlight
.width
= m_gi
->m_rectAll
.width
;
1401 m_gi
->m_rectHighlight
.height
= m_gi
->m_rectAll
.height
;
1406 wxFAIL_MSG( _T("unexpected call to SetSize") );
1410 wxFAIL_MSG( _T("unknown mode") );
1414 void wxListLineData::SetPosition( int x
, int y
,
1418 wxListItemDataList::Node
*node
= m_items
.GetFirst();
1419 wxCHECK_RET( node
, _T("no subitems at all??") );
1421 wxListItemData
*item
= node
->GetData();
1423 switch ( GetMode() )
1426 case wxLC_SMALL_ICON
:
1427 m_gi
->m_rectAll
.x
= x
;
1428 m_gi
->m_rectAll
.y
= y
;
1430 if ( item
->HasImage() )
1432 m_gi
->m_rectIcon
.x
= m_gi
->m_rectAll
.x
+ 4
1433 + (spacing
- m_gi
->m_rectIcon
.width
)/2;
1434 m_gi
->m_rectIcon
.y
= m_gi
->m_rectAll
.y
+ 4;
1437 if ( item
->HasText() )
1439 if (m_gi
->m_rectAll
.width
> spacing
)
1440 m_gi
->m_rectLabel
.x
= m_gi
->m_rectAll
.x
+ 2;
1442 m_gi
->m_rectLabel
.x
= m_gi
->m_rectAll
.x
+ 2 + (spacing
/2) - (m_gi
->m_rectLabel
.width
/2);
1443 m_gi
->m_rectLabel
.y
= m_gi
->m_rectAll
.y
+ m_gi
->m_rectAll
.height
+ 2 - m_gi
->m_rectLabel
.height
;
1444 m_gi
->m_rectHighlight
.x
= m_gi
->m_rectLabel
.x
- 2;
1445 m_gi
->m_rectHighlight
.y
= m_gi
->m_rectLabel
.y
- 2;
1447 else // no text, highlight the icon
1449 m_gi
->m_rectHighlight
.x
= m_gi
->m_rectIcon
.x
- 4;
1450 m_gi
->m_rectHighlight
.y
= m_gi
->m_rectIcon
.y
- 4;
1455 m_gi
->m_rectAll
.x
= x
;
1456 m_gi
->m_rectAll
.y
= y
;
1458 m_gi
->m_rectHighlight
.x
= m_gi
->m_rectAll
.x
;
1459 m_gi
->m_rectHighlight
.y
= m_gi
->m_rectAll
.y
;
1460 m_gi
->m_rectLabel
.y
= m_gi
->m_rectAll
.y
+ 2;
1462 if (item
->HasImage())
1464 m_gi
->m_rectIcon
.x
= m_gi
->m_rectAll
.x
+ 2;
1465 m_gi
->m_rectIcon
.y
= m_gi
->m_rectAll
.y
+ 2;
1466 m_gi
->m_rectLabel
.x
= m_gi
->m_rectAll
.x
+ 6 + m_gi
->m_rectIcon
.width
;
1470 m_gi
->m_rectLabel
.x
= m_gi
->m_rectAll
.x
+ 2;
1475 wxFAIL_MSG( _T("unexpected call to SetPosition") );
1479 wxFAIL_MSG( _T("unknown mode") );
1483 void wxListLineData::InitItems( int num
)
1485 for (int i
= 0; i
< num
; i
++)
1486 m_items
.Append( new wxListItemData(m_owner
) );
1489 void wxListLineData::SetItem( int index
, const wxListItem
&info
)
1491 wxListItemDataList::Node
*node
= m_items
.Item( index
);
1492 wxCHECK_RET( node
, _T("invalid column index in SetItem") );
1494 wxListItemData
*item
= node
->GetData();
1495 item
->SetItem( info
);
1498 void wxListLineData::GetItem( int index
, wxListItem
&info
)
1500 wxListItemDataList::Node
*node
= m_items
.Item( index
);
1503 wxListItemData
*item
= node
->GetData();
1504 item
->GetItem( info
);
1508 wxString
wxListLineData::GetText(int index
) const
1512 wxListItemDataList::Node
*node
= m_items
.Item( index
);
1515 wxListItemData
*item
= node
->GetData();
1516 s
= item
->GetText();
1522 void wxListLineData::SetText( int index
, const wxString s
)
1524 wxListItemDataList::Node
*node
= m_items
.Item( index
);
1527 wxListItemData
*item
= node
->GetData();
1532 void wxListLineData::SetImage( int index
, int image
)
1534 wxListItemDataList::Node
*node
= m_items
.Item( index
);
1535 wxCHECK_RET( node
, _T("invalid column index in SetImage()") );
1537 wxListItemData
*item
= node
->GetData();
1538 item
->SetImage(image
);
1541 int wxListLineData::GetImage( int index
) const
1543 wxListItemDataList::Node
*node
= m_items
.Item( index
);
1544 wxCHECK_MSG( node
, -1, _T("invalid column index in GetImage()") );
1546 wxListItemData
*item
= node
->GetData();
1547 return item
->GetImage();
1550 wxListItemAttr
*wxListLineData::GetAttr() const
1552 wxListItemDataList::Node
*node
= m_items
.GetFirst();
1553 wxCHECK_MSG( node
, NULL
, _T("invalid column index in GetAttr()") );
1555 wxListItemData
*item
= node
->GetData();
1556 return item
->GetAttr();
1559 void wxListLineData::SetAttr(wxListItemAttr
*attr
)
1561 wxListItemDataList::Node
*node
= m_items
.GetFirst();
1562 wxCHECK_RET( node
, _T("invalid column index in SetAttr()") );
1564 wxListItemData
*item
= node
->GetData();
1565 item
->SetAttr(attr
);
1568 bool wxListLineData::SetAttributes(wxDC
*dc
,
1569 const wxListItemAttr
*attr
,
1572 wxWindow
*listctrl
= m_owner
->GetParent();
1576 // don't use foreground colour for drawing highlighted items - this might
1577 // make them completely invisible (and there is no way to do bit
1578 // arithmetics on wxColour, unfortunately)
1582 colText
= wxSystemSettings::GetSystemColour(wxSYS_COLOUR_HIGHLIGHTTEXT
);
1586 if ( attr
&& attr
->HasTextColour() )
1588 colText
= attr
->GetTextColour();
1592 colText
= listctrl
->GetForegroundColour();
1596 dc
->SetTextForeground(colText
);
1600 if ( attr
&& attr
->HasFont() )
1602 font
= attr
->GetFont();
1606 font
= listctrl
->GetFont();
1612 bool hasBgCol
= attr
&& attr
->HasBackgroundColour();
1613 if ( highlighted
|| hasBgCol
)
1617 dc
->SetBrush( *m_owner
->GetHighlightBrush() );
1621 dc
->SetBrush(wxBrush(attr
->GetBackgroundColour(), wxSOLID
));
1624 dc
->SetPen( *wxTRANSPARENT_PEN
);
1632 void wxListLineData::Draw( wxDC
*dc
)
1634 wxListItemDataList::Node
*node
= m_items
.GetFirst();
1635 wxCHECK_RET( node
, _T("no subitems at all??") );
1637 bool highlighted
= IsHighlighted();
1639 wxListItemAttr
*attr
= GetAttr();
1641 if ( SetAttributes(dc
, attr
, highlighted
) )
1643 dc
->DrawRectangle( m_gi
->m_rectHighlight
);
1646 wxListItemData
*item
= node
->GetData();
1647 if (item
->HasImage())
1649 wxRect rectIcon
= m_gi
->m_rectIcon
;
1650 m_owner
->DrawImage( item
->GetImage(), dc
,
1651 rectIcon
.x
, rectIcon
.y
);
1654 if (item
->HasText())
1656 wxRect rectLabel
= m_gi
->m_rectLabel
;
1658 wxDCClipper
clipper(*dc
, rectLabel
);
1659 dc
->DrawText( item
->GetText(), rectLabel
.x
, rectLabel
.y
);
1663 void wxListLineData::DrawInReportMode( wxDC
*dc
,
1665 const wxRect
& rectHL
,
1668 // TODO: later we should support setting different attributes for
1669 // different columns - to do it, just add "col" argument to
1670 // GetAttr() and move these lines into the loop below
1671 wxListItemAttr
*attr
= GetAttr();
1672 if ( SetAttributes(dc
, attr
, highlighted
) )
1674 dc
->DrawRectangle( rectHL
);
1677 wxListItemDataList::Node
*node
= m_items
.GetFirst();
1678 wxCHECK_RET( node
, _T("no subitems at all??") );
1681 wxCoord x
= rect
.x
+ HEADER_OFFSET_X
,
1682 y
= rect
.y
+ (LINE_SPACING
+ EXTRA_HEIGHT
) / 2;
1686 wxListItemData
*item
= node
->GetData();
1688 int width
= m_owner
->GetColumnWidth(col
++);
1692 if ( item
->HasImage() )
1695 m_owner
->DrawImage( item
->GetImage(), dc
, xOld
, y
);
1696 m_owner
->GetImageSize( item
->GetImage(), ix
, iy
);
1698 ix
+= IMAGE_MARGIN_IN_REPORT_MODE
;
1704 wxDCClipper
clipper(*dc
, xOld
, y
, width
, rect
.height
);
1706 if ( item
->HasText() )
1708 dc
->DrawText( item
->GetText(), xOld
, y
);
1711 node
= node
->GetNext();
1715 bool wxListLineData::Highlight( bool on
)
1717 wxCHECK_MSG( !m_owner
->IsVirtual(), FALSE
, _T("unexpected call to Highlight") );
1719 if ( on
== m_highlighted
)
1727 void wxListLineData::ReverseHighlight( void )
1729 Highlight(!IsHighlighted());
1732 //-----------------------------------------------------------------------------
1733 // wxListHeaderWindow
1734 //-----------------------------------------------------------------------------
1736 IMPLEMENT_DYNAMIC_CLASS(wxListHeaderWindow
,wxWindow
);
1738 BEGIN_EVENT_TABLE(wxListHeaderWindow
,wxWindow
)
1739 EVT_PAINT (wxListHeaderWindow::OnPaint
)
1740 EVT_MOUSE_EVENTS (wxListHeaderWindow::OnMouse
)
1741 EVT_SET_FOCUS (wxListHeaderWindow::OnSetFocus
)
1744 void wxListHeaderWindow::Init()
1746 m_currentCursor
= (wxCursor
*) NULL
;
1747 m_isDragging
= FALSE
;
1751 wxListHeaderWindow::wxListHeaderWindow()
1755 m_owner
= (wxListMainWindow
*) NULL
;
1756 m_resizeCursor
= (wxCursor
*) NULL
;
1759 wxListHeaderWindow::wxListHeaderWindow( wxWindow
*win
,
1761 wxListMainWindow
*owner
,
1765 const wxString
&name
)
1766 : wxWindow( win
, id
, pos
, size
, style
, name
)
1771 m_resizeCursor
= new wxCursor( wxCURSOR_SIZEWE
);
1773 SetBackgroundColour( wxSystemSettings::GetSystemColour( wxSYS_COLOUR_BTNFACE
) );
1776 wxListHeaderWindow::~wxListHeaderWindow()
1778 delete m_resizeCursor
;
1781 void wxListHeaderWindow::DoDrawRect( wxDC
*dc
, int x
, int y
, int w
, int h
)
1784 GtkStateType state
= m_parent
->IsEnabled() ? GTK_STATE_NORMAL
1785 : GTK_STATE_INSENSITIVE
;
1787 x
= dc
->XLOG2DEV( x
);
1789 gtk_paint_box (m_wxwindow
->style
, GTK_PIZZA(m_wxwindow
)->bin_window
,
1790 state
, GTK_SHADOW_OUT
,
1791 (GdkRectangle
*) NULL
, m_wxwindow
, "button",
1792 x
-1, y
-1, w
+2, h
+2);
1793 #elif defined( __WXMAC__ )
1794 const int m_corner
= 1;
1796 dc
->SetBrush( *wxTRANSPARENT_BRUSH
);
1798 dc
->SetPen( wxPen( wxSystemSettings::GetSystemColour( wxSYS_COLOUR_BTNSHADOW
) , 1 , wxSOLID
) );
1799 dc
->DrawLine( x
+w
-m_corner
+1, y
, x
+w
, y
+h
); // right (outer)
1800 dc
->DrawRectangle( x
, y
+h
, w
+1, 1 ); // bottom (outer)
1802 wxPen
pen( wxColour( 0x88 , 0x88 , 0x88 ), 1, wxSOLID
);
1805 dc
->DrawLine( x
+w
-m_corner
, y
, x
+w
-1, y
+h
); // right (inner)
1806 dc
->DrawRectangle( x
+1, y
+h
-1, w
-2, 1 ); // bottom (inner)
1808 dc
->SetPen( *wxWHITE_PEN
);
1809 dc
->DrawRectangle( x
, y
, w
-m_corner
+1, 1 ); // top (outer)
1810 dc
->DrawRectangle( x
, y
, 1, h
); // left (outer)
1811 dc
->DrawLine( x
, y
+h
-1, x
+1, y
+h
-1 );
1812 dc
->DrawLine( x
+w
-1, y
, x
+w
-1, y
+1 );
1814 const int m_corner
= 1;
1816 dc
->SetBrush( *wxTRANSPARENT_BRUSH
);
1818 dc
->SetPen( *wxBLACK_PEN
);
1819 dc
->DrawLine( x
+w
-m_corner
+1, y
, x
+w
, y
+h
); // right (outer)
1820 dc
->DrawRectangle( x
, y
+h
, w
+1, 1 ); // bottom (outer)
1822 wxPen
pen( wxSystemSettings::GetSystemColour( wxSYS_COLOUR_BTNSHADOW
), 1, wxSOLID
);
1825 dc
->DrawLine( x
+w
-m_corner
, y
, x
+w
-1, y
+h
); // right (inner)
1826 dc
->DrawRectangle( x
+1, y
+h
-1, w
-2, 1 ); // bottom (inner)
1828 dc
->SetPen( *wxWHITE_PEN
);
1829 dc
->DrawRectangle( x
, y
, w
-m_corner
+1, 1 ); // top (outer)
1830 dc
->DrawRectangle( x
, y
, 1, h
); // left (outer)
1831 dc
->DrawLine( x
, y
+h
-1, x
+1, y
+h
-1 );
1832 dc
->DrawLine( x
+w
-1, y
, x
+w
-1, y
+1 );
1836 // shift the DC origin to match the position of the main window horz
1837 // scrollbar: this allows us to always use logical coords
1838 void wxListHeaderWindow::AdjustDC(wxDC
& dc
)
1841 m_owner
->GetScrollPixelsPerUnit( &xpix
, NULL
);
1844 m_owner
->GetViewStart( &x
, NULL
);
1846 // account for the horz scrollbar offset
1847 dc
.SetDeviceOrigin( -x
* xpix
, 0 );
1850 void wxListHeaderWindow::OnPaint( wxPaintEvent
&WXUNUSED(event
) )
1853 wxClientDC
dc( this );
1855 wxPaintDC
dc( this );
1863 dc
.SetFont( GetFont() );
1865 // width and height of the entire header window
1867 GetClientSize( &w
, &h
);
1868 m_owner
->CalcUnscrolledPosition(w
, 0, &w
, NULL
);
1870 dc
.SetBackgroundMode(wxTRANSPARENT
);
1872 // do *not* use the listctrl colour for headers - one day we will have a
1873 // function to set it separately
1874 //dc.SetTextForeground( *wxBLACK );
1875 dc
.SetTextForeground(wxSystemSettings::
1876 GetSystemColour( wxSYS_COLOUR_WINDOWTEXT
));
1878 int x
= HEADER_OFFSET_X
;
1880 int numColumns
= m_owner
->GetColumnCount();
1882 for (int i
= 0; i
< numColumns
; i
++)
1884 m_owner
->GetColumn( i
, item
);
1885 int wCol
= item
.m_width
;
1887 // the width of the rect to draw: make it smaller to fit entirely
1888 // inside the column rect
1891 dc
.SetPen( *wxWHITE_PEN
);
1893 DoDrawRect( &dc
, x
, HEADER_OFFSET_Y
, cw
, h
-2 );
1895 // if we have an image, draw it on the right of the label
1896 int image
= item
.m_image
;
1899 wxImageList
*imageList
= m_owner
->m_small_image_list
;
1903 imageList
->GetSize(image
, ix
, iy
);
1910 HEADER_OFFSET_Y
+ (h
- 4 - iy
)/2,
1911 wxIMAGELIST_DRAW_TRANSPARENT
1916 //else: ignore the column image
1919 // draw the text clipping it so that it doesn't overwrite the column
1921 wxDCClipper
clipper(dc
, x
, HEADER_OFFSET_Y
, cw
, h
- 4 );
1923 dc
.DrawText( item
.GetText(),
1924 x
+ EXTRA_WIDTH
, HEADER_OFFSET_Y
+ EXTRA_HEIGHT
);
1926 if ( x
> w
- wCol
+ 5 )
1934 void wxListHeaderWindow::DrawCurrent()
1936 int x1
= m_currentX
;
1938 ClientToScreen( &x1
, &y1
);
1940 int x2
= m_currentX
-1;
1942 m_owner
->GetClientSize( NULL
, &y2
);
1943 m_owner
->ClientToScreen( &x2
, &y2
);
1946 dc
.SetLogicalFunction( wxINVERT
);
1947 dc
.SetPen( wxPen( *wxBLACK
, 2, wxSOLID
) );
1948 dc
.SetBrush( *wxTRANSPARENT_BRUSH
);
1952 dc
.DrawLine( x1
, y1
, x2
, y2
);
1954 dc
.SetLogicalFunction( wxCOPY
);
1956 dc
.SetPen( wxNullPen
);
1957 dc
.SetBrush( wxNullBrush
);
1960 void wxListHeaderWindow::OnMouse( wxMouseEvent
&event
)
1962 // we want to work with logical coords
1964 m_owner
->CalcUnscrolledPosition(event
.GetX(), 0, &x
, NULL
);
1965 int y
= event
.GetY();
1969 // we don't draw the line beyond our window, but we allow dragging it
1972 GetClientSize( &w
, NULL
);
1973 m_owner
->CalcUnscrolledPosition(w
, 0, &w
, NULL
);
1976 // erase the line if it was drawn
1977 if ( m_currentX
< w
)
1980 if (event
.ButtonUp())
1983 m_isDragging
= FALSE
;
1985 m_owner
->SetColumnWidth( m_column
, m_currentX
- m_minX
);
1992 m_currentX
= m_minX
+ 7;
1994 // draw in the new location
1995 if ( m_currentX
< w
)
1999 else // not dragging
2002 bool hit_border
= FALSE
;
2004 // end of the current column
2007 // find the column where this event occured
2008 int countCol
= m_owner
->GetColumnCount();
2009 for (int col
= 0; col
< countCol
; col
++)
2011 xpos
+= m_owner
->GetColumnWidth( col
);
2014 if ( (abs(x
-xpos
) < 3) && (y
< 22) )
2016 // near the column border
2023 // inside the column
2030 if (event
.LeftDown() || event
.RightUp())
2032 if (hit_border
&& event
.LeftDown())
2034 m_isDragging
= TRUE
;
2039 else // click on a column
2041 wxWindow
*parent
= GetParent();
2042 wxListEvent
le( event
.LeftDown()
2043 ? wxEVT_COMMAND_LIST_COL_CLICK
2044 : wxEVT_COMMAND_LIST_COL_RIGHT_CLICK
,
2046 le
.SetEventObject( parent
);
2047 le
.m_col
= m_column
;
2048 parent
->GetEventHandler()->ProcessEvent( le
);
2051 else if (event
.Moving())
2056 setCursor
= m_currentCursor
== wxSTANDARD_CURSOR
;
2057 m_currentCursor
= m_resizeCursor
;
2061 setCursor
= m_currentCursor
!= wxSTANDARD_CURSOR
;
2062 m_currentCursor
= wxSTANDARD_CURSOR
;
2066 SetCursor(*m_currentCursor
);
2071 void wxListHeaderWindow::OnSetFocus( wxFocusEvent
&WXUNUSED(event
) )
2073 m_owner
->SetFocus();
2076 //-----------------------------------------------------------------------------
2077 // wxListRenameTimer (internal)
2078 //-----------------------------------------------------------------------------
2080 wxListRenameTimer::wxListRenameTimer( wxListMainWindow
*owner
)
2085 void wxListRenameTimer::Notify()
2087 m_owner
->OnRenameTimer();
2090 //-----------------------------------------------------------------------------
2091 // wxListTextCtrl (internal)
2092 //-----------------------------------------------------------------------------
2094 IMPLEMENT_DYNAMIC_CLASS(wxListTextCtrl
,wxTextCtrl
);
2096 BEGIN_EVENT_TABLE(wxListTextCtrl
,wxTextCtrl
)
2097 EVT_CHAR (wxListTextCtrl::OnChar
)
2098 EVT_KEY_UP (wxListTextCtrl::OnKeyUp
)
2099 EVT_KILL_FOCUS (wxListTextCtrl::OnKillFocus
)
2102 wxListTextCtrl::wxListTextCtrl( wxWindow
*parent
,
2103 const wxWindowID id
,
2106 wxListMainWindow
*owner
,
2107 const wxString
&value
,
2111 const wxValidator
& validator
,
2112 const wxString
&name
)
2113 : wxTextCtrl( parent
, id
, value
, pos
, size
, style
, validator
, name
)
2118 (*m_accept
) = FALSE
;
2120 m_startValue
= value
;
2123 void wxListTextCtrl::OnChar( wxKeyEvent
&event
)
2125 if (event
.m_keyCode
== WXK_RETURN
)
2128 (*m_res
) = GetValue();
2130 if (!wxPendingDelete
.Member(this))
2131 wxPendingDelete
.Append(this);
2133 if ((*m_accept
) && ((*m_res
) != m_startValue
))
2134 m_owner
->OnRenameAccept();
2138 if (event
.m_keyCode
== WXK_ESCAPE
)
2140 (*m_accept
) = FALSE
;
2143 if (!wxPendingDelete
.Member(this))
2144 wxPendingDelete
.Append(this);
2152 void wxListTextCtrl::OnKeyUp( wxKeyEvent
&event
)
2154 // auto-grow the textctrl:
2155 wxSize parentSize
= m_owner
->GetSize();
2156 wxPoint myPos
= GetPosition();
2157 wxSize mySize
= GetSize();
2159 GetTextExtent(GetValue() + _T("MM"), &sx
, &sy
); // FIXME: MM??
2160 if (myPos
.x
+ sx
> parentSize
.x
)
2161 sx
= parentSize
.x
- myPos
.x
;
2169 void wxListTextCtrl::OnKillFocus( wxFocusEvent
&WXUNUSED(event
) )
2171 if (!wxPendingDelete
.Member(this))
2172 wxPendingDelete
.Append(this);
2174 if ((*m_accept
) && ((*m_res
) != m_startValue
))
2175 m_owner
->OnRenameAccept();
2178 //-----------------------------------------------------------------------------
2180 //-----------------------------------------------------------------------------
2182 IMPLEMENT_DYNAMIC_CLASS(wxListMainWindow
,wxScrolledWindow
);
2184 BEGIN_EVENT_TABLE(wxListMainWindow
,wxScrolledWindow
)
2185 EVT_PAINT (wxListMainWindow::OnPaint
)
2186 EVT_MOUSE_EVENTS (wxListMainWindow::OnMouse
)
2187 EVT_CHAR (wxListMainWindow::OnChar
)
2188 EVT_KEY_DOWN (wxListMainWindow::OnKeyDown
)
2189 EVT_SET_FOCUS (wxListMainWindow::OnSetFocus
)
2190 EVT_KILL_FOCUS (wxListMainWindow::OnKillFocus
)
2191 EVT_SCROLLWIN (wxListMainWindow::OnScroll
)
2194 void wxListMainWindow::Init()
2196 m_columns
.DeleteContents( TRUE
);
2200 m_lineTo
= (size_t)-1;
2206 m_small_image_list
= (wxImageList
*) NULL
;
2207 m_normal_image_list
= (wxImageList
*) NULL
;
2209 m_small_spacing
= 30;
2210 m_normal_spacing
= 40;
2214 m_isCreated
= FALSE
;
2216 m_lastOnSame
= FALSE
;
2217 m_renameTimer
= new wxListRenameTimer( this );
2218 m_renameAccept
= FALSE
;
2223 m_lineBeforeLastClicked
= (size_t)-1;
2226 void wxListMainWindow::InitScrolling()
2228 if ( HasFlag(wxLC_REPORT
) )
2230 m_xScroll
= SCROLL_UNIT_X
;
2231 m_yScroll
= SCROLL_UNIT_Y
;
2235 m_xScroll
= SCROLL_UNIT_Y
;
2240 wxListMainWindow::wxListMainWindow()
2245 m_highlightUnfocusedBrush
= (wxBrush
*) NULL
;
2251 wxListMainWindow::wxListMainWindow( wxWindow
*parent
,
2256 const wxString
&name
)
2257 : wxScrolledWindow( parent
, id
, pos
, size
,
2258 style
| wxHSCROLL
| wxVSCROLL
, name
)
2262 m_highlightBrush
= new wxBrush
2264 wxSystemSettings::GetSystemColour
2266 wxSYS_COLOUR_HIGHLIGHT
2271 m_highlightUnfocusedBrush
= new wxBrush
2273 wxSystemSettings::GetSystemColour
2275 wxSYS_COLOUR_BTNSHADOW
2284 SetScrollbars( m_xScroll
, m_yScroll
, 0, 0, 0, 0 );
2286 SetBackgroundColour( wxSystemSettings::GetSystemColour( wxSYS_COLOUR_LISTBOX
) );
2289 wxListMainWindow::~wxListMainWindow()
2293 delete m_highlightBrush
;
2294 delete m_highlightUnfocusedBrush
;
2296 delete m_renameTimer
;
2299 void wxListMainWindow::CacheLineData(size_t line
)
2301 wxListCtrl
*listctrl
= GetListCtrl();
2303 wxListLineData
*ld
= GetDummyLine();
2305 size_t countCol
= GetColumnCount();
2306 for ( size_t col
= 0; col
< countCol
; col
++ )
2308 ld
->SetText(col
, listctrl
->OnGetItemText(line
, col
));
2311 ld
->SetImage(listctrl
->OnGetItemImage(line
));
2312 ld
->SetAttr(listctrl
->OnGetItemAttr(line
));
2315 wxListLineData
*wxListMainWindow::GetDummyLine() const
2317 wxASSERT_MSG( !IsEmpty(), _T("invalid line index") );
2319 if ( m_lines
.IsEmpty() )
2321 // normal controls are supposed to have something in m_lines
2322 // already if it's not empty
2323 wxASSERT_MSG( IsVirtual(), _T("logic error") );
2325 wxListMainWindow
*self
= wxConstCast(this, wxListMainWindow
);
2326 wxListLineData
*line
= new wxListLineData(self
);
2327 self
->m_lines
.Add(line
);
2333 // ----------------------------------------------------------------------------
2334 // line geometry (report mode only)
2335 // ----------------------------------------------------------------------------
2337 wxCoord
wxListMainWindow::GetLineHeight() const
2339 wxASSERT_MSG( HasFlag(wxLC_REPORT
), _T("only works in report mode") );
2341 // we cache the line height as calling GetTextExtent() is slow
2342 if ( !m_lineHeight
)
2344 wxListMainWindow
*self
= wxConstCast(this, wxListMainWindow
);
2346 wxClientDC
dc( self
);
2347 dc
.SetFont( GetFont() );
2350 dc
.GetTextExtent(_T("H"), NULL
, &y
);
2352 if ( y
< SCROLL_UNIT_Y
)
2356 self
->m_lineHeight
= y
+ LINE_SPACING
;
2359 return m_lineHeight
;
2362 wxCoord
wxListMainWindow::GetLineY(size_t line
) const
2364 wxASSERT_MSG( HasFlag(wxLC_REPORT
), _T("only works in report mode") );
2366 return LINE_SPACING
+ line
*GetLineHeight();
2369 wxRect
wxListMainWindow::GetLineRect(size_t line
) const
2371 if ( !InReportView() )
2372 return GetLine(line
)->m_gi
->m_rectAll
;
2375 rect
.x
= HEADER_OFFSET_X
;
2376 rect
.y
= GetLineY(line
);
2377 rect
.width
= GetHeaderWidth();
2378 rect
.height
= GetLineHeight();
2383 wxRect
wxListMainWindow::GetLineLabelRect(size_t line
) const
2385 if ( !InReportView() )
2386 return GetLine(line
)->m_gi
->m_rectLabel
;
2389 rect
.x
= HEADER_OFFSET_X
;
2390 rect
.y
= GetLineY(line
);
2391 rect
.width
= GetColumnWidth(0);
2392 rect
.height
= GetLineHeight();
2397 wxRect
wxListMainWindow::GetLineIconRect(size_t line
) const
2399 if ( !InReportView() )
2400 return GetLine(line
)->m_gi
->m_rectIcon
;
2402 wxListLineData
*ld
= GetLine(line
);
2403 wxASSERT_MSG( ld
->HasImage(), _T("should have an image") );
2406 rect
.x
= HEADER_OFFSET_X
;
2407 rect
.y
= GetLineY(line
);
2408 GetImageSize(ld
->GetImage(), rect
.width
, rect
.height
);
2413 wxRect
wxListMainWindow::GetLineHighlightRect(size_t line
) const
2415 return InReportView() ? GetLineRect(line
)
2416 : GetLine(line
)->m_gi
->m_rectHighlight
;
2419 long wxListMainWindow::HitTestLine(size_t line
, int x
, int y
) const
2421 wxASSERT_MSG( line
< GetItemCount(), _T("invalid line in HitTestLine") );
2423 wxListLineData
*ld
= GetLine(line
);
2425 if ( ld
->HasImage() && GetLineIconRect(line
).Inside(x
, y
) )
2426 return wxLIST_HITTEST_ONITEMICON
;
2428 if ( ld
->HasText() )
2430 wxRect rect
= InReportView() ? GetLineRect(line
)
2431 : GetLineLabelRect(line
);
2433 if ( rect
.Inside(x
, y
) )
2434 return wxLIST_HITTEST_ONITEMLABEL
;
2440 // ----------------------------------------------------------------------------
2441 // highlight (selection) handling
2442 // ----------------------------------------------------------------------------
2444 bool wxListMainWindow::IsHighlighted(size_t line
) const
2448 return m_selStore
.IsSelected(line
);
2452 wxListLineData
*ld
= GetLine(line
);
2453 wxCHECK_MSG( ld
, FALSE
, _T("invalid index in IsHighlighted") );
2455 return ld
->IsHighlighted();
2459 void wxListMainWindow::HighlightLines( size_t lineFrom
,
2465 wxArrayInt linesChanged
;
2466 if ( !m_selStore
.SelectRange(lineFrom
, lineTo
, highlight
,
2469 // meny items changed state, refresh everything
2470 RefreshLines(lineFrom
, lineTo
);
2472 else // only a few items changed state, refresh only them
2474 size_t count
= linesChanged
.GetCount();
2475 for ( size_t n
= 0; n
< count
; n
++ )
2477 RefreshLine(linesChanged
[n
]);
2481 else // iterate over all items in non report view
2483 for ( size_t line
= lineFrom
; line
<= lineTo
; line
++ )
2485 if ( HighlightLine(line
, highlight
) )
2493 bool wxListMainWindow::HighlightLine( size_t line
, bool highlight
)
2499 changed
= m_selStore
.SelectItem(line
, highlight
);
2503 wxListLineData
*ld
= GetLine(line
);
2504 wxCHECK_MSG( ld
, FALSE
, _T("invalid index in HighlightLine") );
2506 changed
= ld
->Highlight(highlight
);
2511 SendNotify( line
, highlight
? wxEVT_COMMAND_LIST_ITEM_SELECTED
2512 : wxEVT_COMMAND_LIST_ITEM_DESELECTED
);
2518 void wxListMainWindow::RefreshLine( size_t line
)
2520 if ( HasFlag(wxLC_REPORT
) )
2522 size_t visibleFrom
, visibleTo
;
2523 GetVisibleLinesRange(&visibleFrom
, &visibleTo
);
2525 if ( line
< visibleFrom
|| line
> visibleTo
)
2529 wxRect rect
= GetLineRect(line
);
2531 CalcScrolledPosition( rect
.x
, rect
.y
, &rect
.x
, &rect
.y
);
2532 RefreshRect( rect
);
2535 void wxListMainWindow::RefreshLines( size_t lineFrom
, size_t lineTo
)
2537 // we suppose that they are ordered by caller
2538 wxASSERT_MSG( lineFrom
<= lineTo
, _T("indices in disorder") );
2540 wxASSERT_MSG( lineTo
< GetItemCount(), _T("invalid line range") );
2542 if ( HasFlag(wxLC_REPORT
) )
2544 size_t visibleFrom
, visibleTo
;
2545 GetVisibleLinesRange(&visibleFrom
, &visibleTo
);
2547 if ( lineFrom
< visibleFrom
)
2548 lineFrom
= visibleFrom
;
2549 if ( lineTo
> visibleTo
)
2554 rect
.y
= GetLineY(lineFrom
);
2555 rect
.width
= GetClientSize().x
;
2556 rect
.height
= GetLineY(lineTo
) - rect
.y
+ GetLineHeight();
2558 CalcScrolledPosition( rect
.x
, rect
.y
, &rect
.x
, &rect
.y
);
2559 RefreshRect( rect
);
2563 // TODO: this should be optimized...
2564 for ( size_t line
= lineFrom
; line
<= lineTo
; line
++ )
2571 void wxListMainWindow::RefreshAfter( size_t lineFrom
)
2573 if ( HasFlag(wxLC_REPORT
) )
2576 GetVisibleLinesRange(&visibleFrom
, NULL
);
2578 if ( lineFrom
< visibleFrom
)
2579 lineFrom
= visibleFrom
;
2583 rect
.y
= GetLineY(lineFrom
);
2585 wxSize size
= GetClientSize();
2586 rect
.width
= size
.x
;
2587 // refresh till the bottom of the window
2588 rect
.height
= size
.y
- rect
.y
;
2590 CalcScrolledPosition( rect
.x
, rect
.y
, &rect
.x
, &rect
.y
);
2591 RefreshRect( rect
);
2595 // TODO: how to do it more efficiently?
2600 void wxListMainWindow::RefreshSelected()
2606 if ( InReportView() )
2608 GetVisibleLinesRange(&from
, &to
);
2613 to
= GetItemCount() - 1;
2616 if ( HasCurrent() && m_current
>= from
&& m_current
<= to
)
2618 RefreshLine(m_current
);
2621 for ( size_t line
= from
; line
<= to
; line
++ )
2623 // NB: the test works as expected even if m_current == -1
2624 if ( line
!= m_current
&& IsHighlighted(line
) )
2631 void wxListMainWindow::OnPaint( wxPaintEvent
&WXUNUSED(event
) )
2633 // Note: a wxPaintDC must be constructed even if no drawing is
2634 // done (a Windows requirement).
2635 wxPaintDC
dc( this );
2639 // empty control. nothing to draw
2645 // delay the repainting until we calculate all the items positions
2652 CalcScrolledPosition( 0, 0, &dev_x
, &dev_y
);
2656 dc
.SetFont( GetFont() );
2658 if ( HasFlag(wxLC_REPORT
) )
2660 int lineHeight
= GetLineHeight();
2662 size_t visibleFrom
, visibleTo
;
2663 GetVisibleLinesRange(&visibleFrom
, &visibleTo
);
2666 wxCoord xOrig
, yOrig
;
2667 CalcUnscrolledPosition(0, 0, &xOrig
, &yOrig
);
2669 // tell the caller cache to cache the data
2672 wxListEvent
evCache(wxEVT_COMMAND_LIST_CACHE_HINT
,
2673 GetParent()->GetId());
2674 evCache
.SetEventObject( GetParent() );
2675 evCache
.m_oldItemIndex
= visibleFrom
;
2676 evCache
.m_itemIndex
= visibleTo
;
2677 GetParent()->GetEventHandler()->ProcessEvent( evCache
);
2680 for ( size_t line
= visibleFrom
; line
<= visibleTo
; line
++ )
2682 rectLine
= GetLineRect(line
);
2684 if ( !IsExposed(rectLine
.x
- xOrig
, rectLine
.y
- yOrig
,
2685 rectLine
.width
, rectLine
.height
) )
2687 // don't redraw unaffected lines to avoid flicker
2691 GetLine(line
)->DrawInReportMode( &dc
,
2693 GetLineHighlightRect(line
),
2694 IsHighlighted(line
) );
2697 if ( HasFlag(wxLC_HRULES
) )
2699 wxPen
pen(GetRuleColour(), 1, wxSOLID
);
2700 wxSize clientSize
= GetClientSize();
2702 for ( size_t i
= visibleFrom
; i
<= visibleTo
; i
++ )
2705 dc
.SetBrush( *wxTRANSPARENT_BRUSH
);
2706 dc
.DrawLine(0 - dev_x
, i
*lineHeight
,
2707 clientSize
.x
- dev_x
, i
*lineHeight
);
2710 // Draw last horizontal rule
2711 if ( visibleTo
> visibleFrom
)
2714 dc
.SetBrush( *wxTRANSPARENT_BRUSH
);
2715 dc
.DrawLine(0 - dev_x
, m_lineTo
*lineHeight
,
2716 clientSize
.x
- dev_x
, m_lineTo
*lineHeight
);
2720 // Draw vertical rules if required
2721 if ( HasFlag(wxLC_VRULES
) && !IsEmpty() )
2723 wxPen
pen(GetRuleColour(), 1, wxSOLID
);
2726 wxRect firstItemRect
;
2727 wxRect lastItemRect
;
2728 GetItemRect(0, firstItemRect
);
2729 GetItemRect(GetItemCount() - 1, lastItemRect
);
2730 int x
= firstItemRect
.GetX();
2732 dc
.SetBrush(* wxTRANSPARENT_BRUSH
);
2733 for (col
= 0; col
< GetColumnCount(); col
++)
2735 int colWidth
= GetColumnWidth(col
);
2737 dc
.DrawLine(x
- dev_x
, firstItemRect
.GetY() - 1 - dev_y
,
2738 x
- dev_x
, lastItemRect
.GetBottom() + 1 - dev_y
);
2744 size_t count
= GetItemCount();
2745 for ( size_t i
= 0; i
< count
; i
++ )
2747 GetLine(i
)->Draw( &dc
);
2753 // don't draw rect outline under Max if we already have the background
2754 // color but under other platforms only draw it if we do: it is a bit
2755 // silly to draw "focus rect" if we don't have focus!
2760 #endif // __WXMAC__/!__WXMAC__
2762 dc
.SetPen( *wxBLACK_PEN
);
2763 dc
.SetBrush( *wxTRANSPARENT_BRUSH
);
2764 dc
.DrawRectangle( GetLineHighlightRect(m_current
) );
2771 void wxListMainWindow::HighlightAll( bool on
)
2773 if ( IsSingleSel() )
2775 wxASSERT_MSG( !on
, _T("can't do this in a single sel control") );
2777 // we just have one item to turn off
2778 if ( HasCurrent() && IsHighlighted(m_current
) )
2780 HighlightLine(m_current
, FALSE
);
2781 RefreshLine(m_current
);
2786 HighlightLines(0, GetItemCount() - 1, on
);
2790 void wxListMainWindow::SendNotify( size_t line
,
2791 wxEventType command
,
2794 wxListEvent
le( command
, GetParent()->GetId() );
2795 le
.SetEventObject( GetParent() );
2796 le
.m_itemIndex
= line
;
2798 // set only for events which have position
2799 if ( point
!= wxDefaultPosition
)
2800 le
.m_pointDrag
= point
;
2802 // don't try to get the line info for virtual list controls: the main
2803 // program has it anyhow and if we did it would result in accessing all
2804 // the lines, even those which are not visible now and this is precisely
2805 // what we're trying to avoid
2806 if ( !IsVirtual() && (command
!= wxEVT_COMMAND_LIST_DELETE_ITEM
) )
2808 GetLine(line
)->GetItem( 0, le
.m_item
);
2810 //else: there may be no more such item
2812 GetParent()->GetEventHandler()->ProcessEvent( le
);
2815 void wxListMainWindow::OnFocusLine( size_t WXUNUSED(line
) )
2817 // SendNotify( line, wxEVT_COMMAND_LIST_ITEM_FOCUSSED );
2820 void wxListMainWindow::OnUnfocusLine( size_t WXUNUSED(line
) )
2822 // SendNotify( line, wxEVT_COMMAND_LIST_ITEM_UNFOCUSSED );
2825 void wxListMainWindow::EditLabel( long item
)
2827 wxCHECK_RET( (item
>= 0) && ((size_t)item
< GetItemCount()),
2828 wxT("wrong index in wxListCtrl::EditLabel()") );
2830 m_currentEdit
= (size_t)item
;
2832 wxListEvent
le( wxEVT_COMMAND_LIST_BEGIN_LABEL_EDIT
, GetParent()->GetId() );
2833 le
.SetEventObject( GetParent() );
2834 le
.m_itemIndex
= item
;
2835 wxListLineData
*data
= GetLine(m_currentEdit
);
2836 wxCHECK_RET( data
, _T("invalid index in EditLabel()") );
2837 data
->GetItem( 0, le
.m_item
);
2838 GetParent()->GetEventHandler()->ProcessEvent( le
);
2840 if (!le
.IsAllowed())
2843 // We have to call this here because the label in question might just have
2844 // been added and no screen update taken place.
2848 wxClientDC
dc(this);
2851 wxString s
= data
->GetText(0);
2852 wxRect rectLabel
= GetLineLabelRect(m_currentEdit
);
2854 rectLabel
.x
= dc
.LogicalToDeviceX( rectLabel
.x
);
2855 rectLabel
.y
= dc
.LogicalToDeviceY( rectLabel
.y
);
2857 wxListTextCtrl
*text
= new wxListTextCtrl
2864 wxPoint(rectLabel
.x
-4,rectLabel
.y
-4),
2865 wxSize(rectLabel
.width
+11,rectLabel
.height
+8)
2870 void wxListMainWindow::OnRenameTimer()
2872 wxCHECK_RET( HasCurrent(), wxT("unexpected rename timer") );
2874 EditLabel( m_current
);
2877 void wxListMainWindow::OnRenameAccept()
2879 wxListEvent
le( wxEVT_COMMAND_LIST_END_LABEL_EDIT
, GetParent()->GetId() );
2880 le
.SetEventObject( GetParent() );
2881 le
.m_itemIndex
= m_currentEdit
;
2883 wxListLineData
*data
= GetLine(m_currentEdit
);
2884 wxCHECK_RET( data
, _T("invalid index in OnRenameAccept()") );
2886 data
->GetItem( 0, le
.m_item
);
2887 le
.m_item
.m_text
= m_renameRes
;
2888 GetParent()->GetEventHandler()->ProcessEvent( le
);
2890 if (!le
.IsAllowed()) return;
2893 info
.m_mask
= wxLIST_MASK_TEXT
;
2894 info
.m_itemId
= le
.m_itemIndex
;
2895 info
.m_text
= m_renameRes
;
2896 info
.SetTextColour(le
.m_item
.GetTextColour());
2900 void wxListMainWindow::OnMouse( wxMouseEvent
&event
)
2902 event
.SetEventObject( GetParent() );
2903 if ( GetParent()->GetEventHandler()->ProcessEvent( event
) )
2906 if ( !HasCurrent() || IsEmpty() )
2912 if ( !(event
.Dragging() || event
.ButtonDown() || event
.LeftUp() ||
2913 event
.ButtonDClick()) )
2916 int x
= event
.GetX();
2917 int y
= event
.GetY();
2918 CalcUnscrolledPosition( x
, y
, &x
, &y
);
2920 // where did we hit it (if we did)?
2923 size_t count
= GetItemCount(),
2926 if ( HasFlag(wxLC_REPORT
) )
2928 current
= y
/ GetLineHeight();
2929 if ( current
< count
)
2930 hitResult
= HitTestLine(current
, x
, y
);
2934 // TODO: optimize it too! this is less simple than for report view but
2935 // enumerating all items is still not a way to do it!!
2936 for ( current
= 0; current
< count
; current
++ )
2938 hitResult
= HitTestLine(current
, x
, y
);
2944 if (event
.Dragging())
2946 if (m_dragCount
== 0)
2948 // we have to report the raw, physical coords as we want to be
2949 // able to call HitTest(event.m_pointDrag) from the user code to
2950 // get the item being dragged
2951 m_dragStart
= event
.GetPosition();
2956 if (m_dragCount
!= 3)
2959 int command
= event
.RightIsDown() ? wxEVT_COMMAND_LIST_BEGIN_RDRAG
2960 : wxEVT_COMMAND_LIST_BEGIN_DRAG
;
2962 wxListEvent
le( command
, GetParent()->GetId() );
2963 le
.SetEventObject( GetParent() );
2964 le
.m_pointDrag
= m_dragStart
;
2965 GetParent()->GetEventHandler()->ProcessEvent( le
);
2976 // outside of any item
2980 bool forceClick
= FALSE
;
2981 if (event
.ButtonDClick())
2983 m_renameTimer
->Stop();
2984 m_lastOnSame
= FALSE
;
2986 if ( current
== m_lineBeforeLastClicked
)
2988 SendNotify( current
, wxEVT_COMMAND_LIST_ITEM_ACTIVATED
);
2994 // the first click was on another item, so don't interpret this as
2995 // a double click, but as a simple click instead
3000 if (event
.LeftUp() && m_lastOnSame
)
3002 if ((current
== m_current
) &&
3003 (hitResult
== wxLIST_HITTEST_ONITEMLABEL
) &&
3004 HasFlag(wxLC_EDIT_LABELS
) )
3006 m_renameTimer
->Start( 100, TRUE
);
3008 m_lastOnSame
= FALSE
;
3010 else if (event
.RightDown())
3012 SendNotify( current
, wxEVT_COMMAND_LIST_ITEM_RIGHT_CLICK
,
3013 event
.GetPosition() );
3015 else if (event
.MiddleDown())
3017 SendNotify( current
, wxEVT_COMMAND_LIST_ITEM_MIDDLE_CLICK
);
3019 else if ( event
.LeftDown() || forceClick
)
3021 m_lineBeforeLastClicked
= m_lineLastClicked
;
3022 m_lineLastClicked
= current
;
3024 size_t oldCurrent
= m_current
;
3026 if ( IsSingleSel() || !(event
.ControlDown() || event
.ShiftDown()) )
3028 HighlightAll( FALSE
);
3029 m_current
= current
;
3031 ReverseHighlight(m_current
);
3033 else // multi sel & either ctrl or shift is down
3035 if (event
.ControlDown())
3037 m_current
= current
;
3039 ReverseHighlight(m_current
);
3041 else if (event
.ShiftDown())
3043 m_current
= current
;
3045 size_t lineFrom
= oldCurrent
,
3048 if ( lineTo
< lineFrom
)
3051 lineFrom
= m_current
;
3054 HighlightLines(lineFrom
, lineTo
);
3056 else // !ctrl, !shift
3058 // test in the enclosing if should make it impossible
3059 wxFAIL_MSG( _T("how did we get here?") );
3063 if (m_current
!= oldCurrent
)
3065 RefreshLine( oldCurrent
);
3066 OnUnfocusLine( oldCurrent
);
3067 OnFocusLine( m_current
);
3070 // forceClick is only set if the previous click was on another item
3071 m_lastOnSame
= !forceClick
&& (m_current
== oldCurrent
);
3075 void wxListMainWindow::MoveToItem(size_t item
)
3077 if ( item
== (size_t)-1 )
3080 wxRect rect
= GetLineRect(item
);
3082 int client_w
, client_h
;
3083 GetClientSize( &client_w
, &client_h
);
3085 int view_x
= m_xScroll
*GetScrollPos( wxHORIZONTAL
);
3086 int view_y
= m_yScroll
*GetScrollPos( wxVERTICAL
);
3088 if ( HasFlag(wxLC_REPORT
) )
3090 // the next we need the range of lines shown it might be different, so
3092 ResetVisibleLinesRange();
3094 if (rect
.y
< view_y
)
3095 Scroll( -1, rect
.y
/m_yScroll
);
3096 if (rect
.y
+rect
.height
+5 > view_y
+client_h
)
3097 Scroll( -1, (rect
.y
+rect
.height
-client_h
+SCROLL_UNIT_Y
)/m_yScroll
);
3101 if (rect
.x
-view_x
< 5)
3102 Scroll( (rect
.x
-5)/m_xScroll
, -1 );
3103 if (rect
.x
+rect
.width
-5 > view_x
+client_w
)
3104 Scroll( (rect
.x
+rect
.width
-client_w
+SCROLL_UNIT_X
)/m_xScroll
, -1 );
3108 // ----------------------------------------------------------------------------
3109 // keyboard handling
3110 // ----------------------------------------------------------------------------
3112 void wxListMainWindow::OnArrowChar(size_t newCurrent
, const wxKeyEvent
& event
)
3114 wxCHECK_RET( newCurrent
< (size_t)GetItemCount(),
3115 _T("invalid item index in OnArrowChar()") );
3117 size_t oldCurrent
= m_current
;
3119 // in single selection we just ignore Shift as we can't select several
3121 if ( event
.ShiftDown() && !IsSingleSel() )
3123 m_current
= newCurrent
;
3125 // select all the items between the old and the new one
3126 if ( oldCurrent
> newCurrent
)
3128 newCurrent
= oldCurrent
;
3129 oldCurrent
= m_current
;
3132 HighlightLines(oldCurrent
, newCurrent
);
3136 // all previously selected items are unselected unless ctrl is held
3137 if ( !event
.ControlDown() )
3138 HighlightAll(FALSE
);
3140 m_current
= newCurrent
;
3142 HighlightLine( oldCurrent
, FALSE
);
3143 RefreshLine( oldCurrent
);
3145 if ( !event
.ControlDown() )
3147 HighlightLine( m_current
, TRUE
);
3151 OnUnfocusLine( oldCurrent
);
3152 OnFocusLine( m_current
);
3153 RefreshLine( m_current
);
3158 void wxListMainWindow::OnKeyDown( wxKeyEvent
&event
)
3160 wxWindow
*parent
= GetParent();
3162 /* we propagate the key event up */
3163 wxKeyEvent
ke( wxEVT_KEY_DOWN
);
3164 ke
.m_shiftDown
= event
.m_shiftDown
;
3165 ke
.m_controlDown
= event
.m_controlDown
;
3166 ke
.m_altDown
= event
.m_altDown
;
3167 ke
.m_metaDown
= event
.m_metaDown
;
3168 ke
.m_keyCode
= event
.m_keyCode
;
3171 ke
.SetEventObject( parent
);
3172 if (parent
->GetEventHandler()->ProcessEvent( ke
)) return;
3177 void wxListMainWindow::OnChar( wxKeyEvent
&event
)
3179 wxWindow
*parent
= GetParent();
3181 /* we send a list_key event up */
3184 wxListEvent
le( wxEVT_COMMAND_LIST_KEY_DOWN
, GetParent()->GetId() );
3185 le
.m_itemIndex
= m_current
;
3186 GetLine(m_current
)->GetItem( 0, le
.m_item
);
3187 le
.m_code
= (int)event
.KeyCode();
3188 le
.SetEventObject( parent
);
3189 parent
->GetEventHandler()->ProcessEvent( le
);
3192 /* we propagate the char event up */
3193 wxKeyEvent
ke( wxEVT_CHAR
);
3194 ke
.m_shiftDown
= event
.m_shiftDown
;
3195 ke
.m_controlDown
= event
.m_controlDown
;
3196 ke
.m_altDown
= event
.m_altDown
;
3197 ke
.m_metaDown
= event
.m_metaDown
;
3198 ke
.m_keyCode
= event
.m_keyCode
;
3201 ke
.SetEventObject( parent
);
3202 if (parent
->GetEventHandler()->ProcessEvent( ke
)) return;
3204 if (event
.KeyCode() == WXK_TAB
)
3206 wxNavigationKeyEvent nevent
;
3207 nevent
.SetWindowChange( event
.ControlDown() );
3208 nevent
.SetDirection( !event
.ShiftDown() );
3209 nevent
.SetEventObject( GetParent()->GetParent() );
3210 nevent
.SetCurrentFocus( m_parent
);
3211 if (GetParent()->GetParent()->GetEventHandler()->ProcessEvent( nevent
)) return;
3214 /* no item -> nothing to do */
3221 switch (event
.KeyCode())
3224 if ( m_current
> 0 )
3225 OnArrowChar( m_current
- 1, event
);
3229 if ( m_current
< (size_t)GetItemCount() - 1 )
3230 OnArrowChar( m_current
+ 1, event
);
3235 OnArrowChar( GetItemCount() - 1, event
);
3240 OnArrowChar( 0, event
);
3246 if ( HasFlag(wxLC_REPORT
) )
3248 steps
= m_linesPerPage
- 1;
3252 steps
= m_current
% m_linesPerPage
;
3255 int index
= m_current
- steps
;
3259 OnArrowChar( index
, event
);
3266 if ( HasFlag(wxLC_REPORT
) )
3268 steps
= m_linesPerPage
- 1;
3272 steps
= m_linesPerPage
- (m_current
% m_linesPerPage
) - 1;
3275 size_t index
= m_current
+ steps
;
3276 size_t count
= GetItemCount();
3277 if ( index
>= count
)
3280 OnArrowChar( index
, event
);
3285 if ( !HasFlag(wxLC_REPORT
) )
3287 int index
= m_current
- m_linesPerPage
;
3291 OnArrowChar( index
, event
);
3296 if ( !HasFlag(wxLC_REPORT
) )
3298 size_t index
= m_current
+ m_linesPerPage
;
3300 size_t count
= GetItemCount();
3301 if ( index
>= count
)
3304 OnArrowChar( index
, event
);
3309 if ( IsSingleSel() )
3311 wxListEvent
le( wxEVT_COMMAND_LIST_ITEM_ACTIVATED
,
3312 GetParent()->GetId() );
3313 le
.SetEventObject( GetParent() );
3314 le
.m_itemIndex
= m_current
;
3315 GetLine(m_current
)->GetItem( 0, le
.m_item
);
3316 GetParent()->GetEventHandler()->ProcessEvent( le
);
3318 if ( IsHighlighted(m_current
) )
3320 // don't unselect the item in single selection mode
3323 //else: select it in ReverseHighlight() below if unselected
3326 ReverseHighlight(m_current
);
3332 wxListEvent
le( wxEVT_COMMAND_LIST_ITEM_ACTIVATED
,
3333 GetParent()->GetId() );
3334 le
.SetEventObject( GetParent() );
3335 le
.m_itemIndex
= m_current
;
3336 GetLine(m_current
)->GetItem( 0, le
.m_item
);
3337 GetParent()->GetEventHandler()->ProcessEvent( le
);
3346 // ----------------------------------------------------------------------------
3348 // ----------------------------------------------------------------------------
3351 extern wxWindow
*g_focusWindow
;
3354 void wxListMainWindow::OnSetFocus( wxFocusEvent
&WXUNUSED(event
) )
3364 g_focusWindow
= GetParent();
3367 wxFocusEvent
event( wxEVT_SET_FOCUS
, GetParent()->GetId() );
3368 event
.SetEventObject( GetParent() );
3369 GetParent()->GetEventHandler()->ProcessEvent( event
);
3372 void wxListMainWindow::OnKillFocus( wxFocusEvent
&WXUNUSED(event
) )
3379 void wxListMainWindow::DrawImage( int index
, wxDC
*dc
, int x
, int y
)
3381 if ( HasFlag(wxLC_ICON
) && (m_normal_image_list
))
3383 m_normal_image_list
->Draw( index
, *dc
, x
, y
, wxIMAGELIST_DRAW_TRANSPARENT
);
3385 else if ( HasFlag(wxLC_SMALL_ICON
) && (m_small_image_list
))
3387 m_small_image_list
->Draw( index
, *dc
, x
, y
, wxIMAGELIST_DRAW_TRANSPARENT
);
3389 else if ( HasFlag(wxLC_LIST
) && (m_small_image_list
))
3391 m_small_image_list
->Draw( index
, *dc
, x
, y
, wxIMAGELIST_DRAW_TRANSPARENT
);
3393 else if ( HasFlag(wxLC_REPORT
) && (m_small_image_list
))
3395 m_small_image_list
->Draw( index
, *dc
, x
, y
, wxIMAGELIST_DRAW_TRANSPARENT
);
3399 void wxListMainWindow::GetImageSize( int index
, int &width
, int &height
) const
3401 if ( HasFlag(wxLC_ICON
) && m_normal_image_list
)
3403 m_normal_image_list
->GetSize( index
, width
, height
);
3405 else if ( HasFlag(wxLC_SMALL_ICON
) && m_small_image_list
)
3407 m_small_image_list
->GetSize( index
, width
, height
);
3409 else if ( HasFlag(wxLC_LIST
) && m_small_image_list
)
3411 m_small_image_list
->GetSize( index
, width
, height
);
3413 else if ( HasFlag(wxLC_REPORT
) && m_small_image_list
)
3415 m_small_image_list
->GetSize( index
, width
, height
);
3424 int wxListMainWindow::GetTextLength( const wxString
&s
) const
3426 wxClientDC
dc( wxConstCast(this, wxListMainWindow
) );
3427 dc
.SetFont( GetFont() );
3430 dc
.GetTextExtent( s
, &lw
, NULL
);
3432 return lw
+ AUTOSIZE_COL_MARGIN
;
3435 void wxListMainWindow::SetImageList( wxImageList
*imageList
, int which
)
3439 // calc the spacing from the icon size
3442 if ((imageList
) && (imageList
->GetImageCount()) )
3444 imageList
->GetSize(0, width
, height
);
3447 if (which
== wxIMAGE_LIST_NORMAL
)
3449 m_normal_image_list
= imageList
;
3450 m_normal_spacing
= width
+ 8;
3453 if (which
== wxIMAGE_LIST_SMALL
)
3455 m_small_image_list
= imageList
;
3456 m_small_spacing
= width
+ 14;
3460 void wxListMainWindow::SetItemSpacing( int spacing
, bool isSmall
)
3465 m_small_spacing
= spacing
;
3469 m_normal_spacing
= spacing
;
3473 int wxListMainWindow::GetItemSpacing( bool isSmall
)
3475 return isSmall
? m_small_spacing
: m_normal_spacing
;
3478 // ----------------------------------------------------------------------------
3480 // ----------------------------------------------------------------------------
3482 void wxListMainWindow::SetColumn( int col
, wxListItem
&item
)
3484 wxListHeaderDataList::Node
*node
= m_columns
.Item( col
);
3486 wxCHECK_RET( node
, _T("invalid column index in SetColumn") );
3488 if ( item
.m_width
== wxLIST_AUTOSIZE_USEHEADER
)
3489 item
.m_width
= GetTextLength( item
.m_text
);
3491 wxListHeaderData
*column
= node
->GetData();
3492 column
->SetItem( item
);
3494 wxListHeaderWindow
*headerWin
= GetListCtrl()->m_headerWin
;
3496 headerWin
->m_dirty
= TRUE
;
3500 // invalidate it as it has to be recalculated
3504 void wxListMainWindow::SetColumnWidth( int col
, int width
)
3506 wxCHECK_RET( col
>= 0 && col
< GetColumnCount(),
3507 _T("invalid column index") );
3509 wxCHECK_RET( HasFlag(wxLC_REPORT
),
3510 _T("SetColumnWidth() can only be called in report mode.") );
3513 wxListHeaderWindow
*headerWin
= GetListCtrl()->m_headerWin
;
3515 headerWin
->m_dirty
= TRUE
;
3517 wxListHeaderDataList::Node
*node
= m_columns
.Item( col
);
3518 wxCHECK_RET( node
, _T("no column?") );
3520 wxListHeaderData
*column
= node
->GetData();
3522 size_t count
= GetItemCount();
3524 if (width
== wxLIST_AUTOSIZE_USEHEADER
)
3526 width
= GetTextLength(column
->GetText());
3528 else if ( width
== wxLIST_AUTOSIZE
)
3532 // TODO: determine the max width somehow...
3533 width
= WIDTH_COL_DEFAULT
;
3537 wxClientDC
dc(this);
3538 dc
.SetFont( GetFont() );
3540 int max
= AUTOSIZE_COL_MARGIN
;
3542 for ( size_t i
= 0; i
< count
; i
++ )
3544 wxListLineData
*line
= GetLine(i
);
3545 wxListItemDataList::Node
*n
= line
->m_items
.Item( col
);
3547 wxCHECK_RET( n
, _T("no subitem?") );
3549 wxListItemData
*item
= n
->GetData();
3552 if (item
->HasImage())
3555 GetImageSize( item
->GetImage(), ix
, iy
);
3559 if (item
->HasText())
3562 dc
.GetTextExtent( item
->GetText(), &w
, NULL
);
3570 width
= max
+ AUTOSIZE_COL_MARGIN
;
3574 column
->SetWidth( width
);
3576 // invalidate it as it has to be recalculated
3580 int wxListMainWindow::GetHeaderWidth() const
3582 if ( !m_headerWidth
)
3584 wxListMainWindow
*self
= wxConstCast(this, wxListMainWindow
);
3586 size_t count
= GetColumnCount();
3587 for ( size_t col
= 0; col
< count
; col
++ )
3589 self
->m_headerWidth
+= GetColumnWidth(col
);
3593 return m_headerWidth
;
3596 void wxListMainWindow::GetColumn( int col
, wxListItem
&item
) const
3598 wxListHeaderDataList::Node
*node
= m_columns
.Item( col
);
3599 wxCHECK_RET( node
, _T("invalid column index in GetColumn") );
3601 wxListHeaderData
*column
= node
->GetData();
3602 column
->GetItem( item
);
3605 int wxListMainWindow::GetColumnWidth( int col
) const
3607 wxListHeaderDataList::Node
*node
= m_columns
.Item( col
);
3608 wxCHECK_MSG( node
, 0, _T("invalid column index") );
3610 wxListHeaderData
*column
= node
->GetData();
3611 return column
->GetWidth();
3614 // ----------------------------------------------------------------------------
3616 // ----------------------------------------------------------------------------
3618 void wxListMainWindow::SetItem( wxListItem
&item
)
3620 long id
= item
.m_itemId
;
3621 wxCHECK_RET( id
>= 0 && (size_t)id
< GetItemCount(),
3622 _T("invalid item index in SetItem") );
3626 wxListLineData
*line
= GetLine((size_t)id
);
3627 line
->SetItem( item
.m_col
, item
);
3630 if ( InReportView() )
3632 // just refresh the line to show the new value of the text/image
3633 RefreshLine((size_t)id
);
3637 // refresh everything (resulting in horrible flicker - FIXME!)
3642 void wxListMainWindow::SetItemState( long litem
, long state
, long stateMask
)
3644 wxCHECK_RET( litem
>= 0 && (size_t)litem
< GetItemCount(),
3645 _T("invalid list ctrl item index in SetItem") );
3647 size_t oldCurrent
= m_current
;
3648 size_t item
= (size_t)litem
; // safe because of the check above
3650 // do we need to change the focus?
3651 if ( stateMask
& wxLIST_STATE_FOCUSED
)
3653 if ( state
& wxLIST_STATE_FOCUSED
)
3655 // don't do anything if this item is already focused
3656 if ( item
!= m_current
)
3658 OnUnfocusLine( m_current
);
3660 OnFocusLine( m_current
);
3662 if ( oldCurrent
!= (size_t)-1 )
3664 if ( IsSingleSel() )
3666 HighlightLine(oldCurrent
, FALSE
);
3669 RefreshLine(oldCurrent
);
3672 RefreshLine( m_current
);
3677 // don't do anything if this item is not focused
3678 if ( item
== m_current
)
3680 OnUnfocusLine( m_current
);
3681 m_current
= (size_t)-1;
3683 RefreshLine( oldCurrent
);
3688 // do we need to change the selection state?
3689 if ( stateMask
& wxLIST_STATE_SELECTED
)
3691 bool on
= (state
& wxLIST_STATE_SELECTED
) != 0;
3693 if ( IsSingleSel() )
3697 // selecting the item also makes it the focused one in the
3699 if ( m_current
!= item
)
3701 OnUnfocusLine( m_current
);
3703 OnFocusLine( m_current
);
3705 if ( oldCurrent
!= (size_t)-1 )
3707 HighlightLine( oldCurrent
, FALSE
);
3708 RefreshLine( oldCurrent
);
3714 // only the current item may be selected anyhow
3715 if ( item
!= m_current
)
3720 if ( HighlightLine(item
, on
) )
3727 int wxListMainWindow::GetItemState( long item
, long stateMask
)
3729 wxCHECK_MSG( item
>= 0 && (size_t)item
< GetItemCount(), 0,
3730 _T("invalid list ctrl item index in GetItemState()") );
3732 int ret
= wxLIST_STATE_DONTCARE
;
3734 if ( stateMask
& wxLIST_STATE_FOCUSED
)
3736 if ( (size_t)item
== m_current
)
3737 ret
|= wxLIST_STATE_FOCUSED
;
3740 if ( stateMask
& wxLIST_STATE_SELECTED
)
3742 if ( IsHighlighted(item
) )
3743 ret
|= wxLIST_STATE_SELECTED
;
3749 void wxListMainWindow::GetItem( wxListItem
&item
)
3751 wxCHECK_RET( item
.m_itemId
>= 0 && (size_t)item
.m_itemId
< GetItemCount(),
3752 _T("invalid item index in GetItem") );
3754 wxListLineData
*line
= GetLine((size_t)item
.m_itemId
);
3755 line
->GetItem( item
.m_col
, item
);
3758 // ----------------------------------------------------------------------------
3760 // ----------------------------------------------------------------------------
3762 size_t wxListMainWindow::GetItemCount() const
3764 return IsVirtual() ? m_countVirt
: m_lines
.GetCount();
3767 void wxListMainWindow::SetItemCount(long count
)
3769 m_selStore
.SetItemCount(count
);
3770 m_countVirt
= count
;
3772 ResetVisibleLinesRange();
3774 // scrollbars must be reset
3778 int wxListMainWindow::GetSelectedItemCount()
3780 // deal with the quick case first
3781 if ( IsSingleSel() )
3783 return HasCurrent() ? IsHighlighted(m_current
) : FALSE
;
3786 // virtual controls remmebers all its selections itself
3788 return m_selStore
.GetSelectedCount();
3790 // TODO: we probably should maintain the number of items selected even for
3791 // non virtual controls as enumerating all lines is really slow...
3792 size_t countSel
= 0;
3793 size_t count
= GetItemCount();
3794 for ( size_t line
= 0; line
< count
; line
++ )
3796 if ( GetLine(line
)->IsHighlighted() )
3803 // ----------------------------------------------------------------------------
3804 // item position/size
3805 // ----------------------------------------------------------------------------
3807 void wxListMainWindow::GetItemRect( long index
, wxRect
&rect
)
3809 wxCHECK_RET( index
>= 0 && (size_t)index
< GetItemCount(),
3810 _T("invalid index in GetItemRect") );
3812 rect
= GetLineRect((size_t)index
);
3814 CalcScrolledPosition(rect
.x
, rect
.y
, &rect
.x
, &rect
.y
);
3817 bool wxListMainWindow::GetItemPosition(long item
, wxPoint
& pos
)
3820 GetItemRect(item
, rect
);
3828 // ----------------------------------------------------------------------------
3829 // geometry calculation
3830 // ----------------------------------------------------------------------------
3832 void wxListMainWindow::RecalculatePositions(bool noRefresh
)
3834 wxClientDC
dc( this );
3835 dc
.SetFont( GetFont() );
3838 if ( HasFlag(wxLC_ICON
) )
3839 iconSpacing
= m_normal_spacing
;
3840 else if ( HasFlag(wxLC_SMALL_ICON
) )
3841 iconSpacing
= m_small_spacing
;
3847 GetClientSize( &clientWidth
, &clientHeight
);
3849 if ( HasFlag(wxLC_REPORT
) )
3851 // all lines have the same height
3852 int lineHeight
= GetLineHeight();
3854 // scroll one line per step
3855 m_yScroll
= lineHeight
;
3857 size_t lineCount
= GetItemCount();
3858 int entireHeight
= lineCount
*lineHeight
+ LINE_SPACING
;
3860 m_linesPerPage
= clientHeight
/ lineHeight
;
3862 ResetVisibleLinesRange();
3864 SetScrollbars( m_xScroll
, m_yScroll
,
3865 (GetHeaderWidth() + m_xScroll
- 1)/m_xScroll
,
3866 (entireHeight
+ m_yScroll
- 1)/m_yScroll
,
3867 GetScrollPos(wxHORIZONTAL
),
3868 GetScrollPos(wxVERTICAL
),
3873 // at first we try without any scrollbar. if the items don't
3874 // fit into the window, we recalculate after subtracting an
3875 // approximated 15 pt for the horizontal scrollbar
3877 clientHeight
-= 4; // sunken frame
3879 int entireWidth
= 0;
3881 for (int tries
= 0; tries
< 2; tries
++)
3888 int currentlyVisibleLines
= 0;
3890 size_t count
= GetItemCount();
3891 for (size_t i
= 0; i
< count
; i
++)
3893 currentlyVisibleLines
++;
3894 wxListLineData
*line
= GetLine(i
);
3895 line
->CalculateSize( &dc
, iconSpacing
);
3896 line
->SetPosition( x
, y
, clientWidth
, iconSpacing
);
3898 wxSize sizeLine
= GetLineSize(i
);
3900 if ( maxWidth
< sizeLine
.x
)
3901 maxWidth
= sizeLine
.x
;
3904 if (currentlyVisibleLines
> m_linesPerPage
)
3905 m_linesPerPage
= currentlyVisibleLines
;
3907 // assume that the size of the next one is the same... (FIXME)
3908 if ( y
+ sizeLine
.y
- 6 >= clientHeight
)
3910 currentlyVisibleLines
= 0;
3913 entireWidth
+= maxWidth
+6;
3916 if ( i
== count
- 1 )
3917 entireWidth
+= maxWidth
;
3918 if ((tries
== 0) && (entireWidth
> clientWidth
))
3920 clientHeight
-= 15; // scrollbar height
3922 currentlyVisibleLines
= 0;
3925 if ( i
== count
- 1 )
3926 tries
= 1; // everything fits, no second try required
3930 int scroll_pos
= GetScrollPos( wxHORIZONTAL
);
3931 SetScrollbars( m_xScroll
, m_yScroll
, (entireWidth
+SCROLL_UNIT_X
) / m_xScroll
, 0, scroll_pos
, 0, TRUE
);
3936 // FIXME: why should we call it from here?
3943 void wxListMainWindow::RefreshAll()
3948 wxListHeaderWindow
*headerWin
= GetListCtrl()->m_headerWin
;
3949 if ( headerWin
&& headerWin
->m_dirty
)
3951 headerWin
->m_dirty
= FALSE
;
3952 headerWin
->Refresh();
3956 void wxListMainWindow::UpdateCurrent()
3958 if ( !HasCurrent() && !IsEmpty() )
3963 if ( m_current
!= (size_t)-1 )
3965 OnFocusLine( m_current
);
3969 long wxListMainWindow::GetNextItem( long item
,
3970 int WXUNUSED(geometry
),
3974 max
= GetItemCount();
3975 wxCHECK_MSG( (ret
== -1) || (ret
< max
), -1,
3976 _T("invalid listctrl index in GetNextItem()") );
3978 // notice that we start with the next item (or the first one if item == -1)
3979 // and this is intentional to allow writing a simple loop to iterate over
3980 // all selected items
3984 // this is not an error because the index was ok initially, just no
3995 size_t count
= GetItemCount();
3996 for ( size_t line
= (size_t)ret
; line
< count
; line
++ )
3998 if ( (state
& wxLIST_STATE_FOCUSED
) && (line
== m_current
) )
4001 if ( (state
& wxLIST_STATE_SELECTED
) && IsHighlighted(line
) )
4008 // ----------------------------------------------------------------------------
4010 // ----------------------------------------------------------------------------
4012 void wxListMainWindow::DeleteItem( long lindex
)
4014 size_t count
= GetItemCount();
4016 wxCHECK_RET( (lindex
>= 0) && ((size_t)lindex
< count
),
4017 _T("invalid item index in DeleteItem") );
4019 size_t index
= (size_t)lindex
;
4021 // we don't need to adjust the index for the previous items
4022 if ( HasCurrent() && m_current
>= index
)
4024 // if the current item is being deleted, we want the next one to
4025 // become selected - unless there is no next one - so don't adjust
4026 // m_current in this case
4027 if ( m_current
!= index
|| m_current
== count
- 1 )
4033 if ( InReportView() )
4035 ResetVisibleLinesRange();
4042 m_selStore
.OnItemDelete(index
);
4046 m_lines
.RemoveAt( index
);
4049 // we need to refresh the (vert) scrollbar as the number of items changed
4052 SendNotify( index
, wxEVT_COMMAND_LIST_DELETE_ITEM
);
4054 RefreshAfter(index
);
4057 void wxListMainWindow::DeleteColumn( int col
)
4059 wxListHeaderDataList::Node
*node
= m_columns
.Item( col
);
4061 wxCHECK_RET( node
, wxT("invalid column index in DeleteColumn()") );
4064 m_columns
.DeleteNode( node
);
4067 void wxListMainWindow::DoDeleteAllItems()
4071 // nothing to do - in particular, don't send the event
4077 // to make the deletion of all items faster, we don't send the
4078 // notifications for each item deletion in this case but only one event
4079 // for all of them: this is compatible with wxMSW and documented in
4080 // DeleteAllItems() description
4082 wxListEvent
event( wxEVT_COMMAND_LIST_DELETE_ALL_ITEMS
, GetParent()->GetId() );
4083 event
.SetEventObject( GetParent() );
4084 GetParent()->GetEventHandler()->ProcessEvent( event
);
4093 if ( InReportView() )
4095 ResetVisibleLinesRange();
4101 void wxListMainWindow::DeleteAllItems()
4105 RecalculatePositions();
4108 void wxListMainWindow::DeleteEverything()
4115 // ----------------------------------------------------------------------------
4116 // scanning for an item
4117 // ----------------------------------------------------------------------------
4119 void wxListMainWindow::EnsureVisible( long index
)
4121 wxCHECK_RET( index
>= 0 && (size_t)index
< GetItemCount(),
4122 _T("invalid index in EnsureVisible") );
4124 // We have to call this here because the label in question might just have
4125 // been added and its position is not known yet
4128 RecalculatePositions(TRUE
/* no refresh */);
4131 MoveToItem((size_t)index
);
4134 long wxListMainWindow::FindItem(long start
, const wxString
& str
, bool WXUNUSED(partial
) )
4141 size_t count
= GetItemCount();
4142 for ( size_t i
= (size_t)pos
; i
< count
; i
++ )
4144 wxListLineData
*line
= GetLine(i
);
4145 if ( line
->GetText(0) == tmp
)
4152 long wxListMainWindow::FindItem(long start
, long data
)
4158 size_t count
= GetItemCount();
4159 for (size_t i
= (size_t)pos
; i
< count
; i
++)
4161 wxListLineData
*line
= GetLine(i
);
4163 line
->GetItem( 0, item
);
4164 if (item
.m_data
== data
)
4171 long wxListMainWindow::HitTest( int x
, int y
, int &flags
)
4173 CalcUnscrolledPosition( x
, y
, &x
, &y
);
4175 size_t count
= GetItemCount();
4177 if ( HasFlag(wxLC_REPORT
) )
4179 size_t current
= y
/ GetLineHeight();
4180 if ( current
< count
)
4182 flags
= HitTestLine(current
, x
, y
);
4189 // TODO: optimize it too! this is less simple than for report view but
4190 // enumerating all items is still not a way to do it!!
4191 for ( size_t current
= 0; current
< count
; current
++ )
4193 flags
= HitTestLine(current
, x
, y
);
4202 // ----------------------------------------------------------------------------
4204 // ----------------------------------------------------------------------------
4206 void wxListMainWindow::InsertItem( wxListItem
&item
)
4208 wxASSERT_MSG( !IsVirtual(), _T("can't be used with virtual control") );
4210 size_t count
= GetItemCount();
4211 wxCHECK_RET( item
.m_itemId
>= 0 && (size_t)item
.m_itemId
<= count
,
4212 _T("invalid item index") );
4214 size_t id
= item
.m_itemId
;
4219 if ( HasFlag(wxLC_REPORT
) )
4221 else if ( HasFlag(wxLC_LIST
) )
4223 else if ( HasFlag(wxLC_ICON
) )
4225 else if ( HasFlag(wxLC_SMALL_ICON
) )
4226 mode
= wxLC_ICON
; // no typo
4229 wxFAIL_MSG( _T("unknown mode") );
4232 wxListLineData
*line
= new wxListLineData(this);
4234 line
->SetItem( 0, item
);
4236 m_lines
.Insert( line
, id
);
4239 RefreshLines(id
, GetItemCount() - 1);
4242 void wxListMainWindow::InsertColumn( long col
, wxListItem
&item
)
4245 if ( HasFlag(wxLC_REPORT
) )
4247 if (item
.m_width
== wxLIST_AUTOSIZE_USEHEADER
)
4248 item
.m_width
= GetTextLength( item
.m_text
);
4249 wxListHeaderData
*column
= new wxListHeaderData( item
);
4250 if ((col
>= 0) && (col
< (int)m_columns
.GetCount()))
4252 wxListHeaderDataList::Node
*node
= m_columns
.Item( col
);
4253 m_columns
.Insert( node
, column
);
4257 m_columns
.Append( column
);
4262 // ----------------------------------------------------------------------------
4264 // ----------------------------------------------------------------------------
4266 wxListCtrlCompare list_ctrl_compare_func_2
;
4267 long list_ctrl_compare_data
;
4269 int LINKAGEMODE
list_ctrl_compare_func_1( wxListLineData
**arg1
, wxListLineData
**arg2
)
4271 wxListLineData
*line1
= *arg1
;
4272 wxListLineData
*line2
= *arg2
;
4274 line1
->GetItem( 0, item
);
4275 long data1
= item
.m_data
;
4276 line2
->GetItem( 0, item
);
4277 long data2
= item
.m_data
;
4278 return list_ctrl_compare_func_2( data1
, data2
, list_ctrl_compare_data
);
4281 void wxListMainWindow::SortItems( wxListCtrlCompare fn
, long data
)
4283 list_ctrl_compare_func_2
= fn
;
4284 list_ctrl_compare_data
= data
;
4285 m_lines
.Sort( list_ctrl_compare_func_1
);
4289 // ----------------------------------------------------------------------------
4291 // ----------------------------------------------------------------------------
4293 void wxListMainWindow::OnScroll(wxScrollWinEvent
& event
)
4295 // update our idea of which lines are shown when we redraw the window the
4297 ResetVisibleLinesRange();
4300 #if defined(__WXGTK__) && !defined(__WXUNIVERSAL__)
4301 wxScrolledWindow::OnScroll(event
);
4303 HandleOnScroll( event
);
4306 if ( event
.GetOrientation() == wxHORIZONTAL
&& HasHeader() )
4308 wxListCtrl
* lc
= GetListCtrl();
4309 wxCHECK_RET( lc
, _T("no listctrl window?") );
4311 lc
->m_headerWin
->Refresh() ;
4313 lc
->m_headerWin
->MacUpdateImmediately() ;
4318 int wxListMainWindow::GetCountPerPage() const
4320 if ( !m_linesPerPage
)
4322 wxConstCast(this, wxListMainWindow
)->
4323 m_linesPerPage
= GetClientSize().y
/ GetLineHeight();
4326 return m_linesPerPage
;
4329 void wxListMainWindow::GetVisibleLinesRange(size_t *from
, size_t *to
)
4331 wxASSERT_MSG( HasFlag(wxLC_REPORT
), _T("this is for report mode only") );
4333 if ( m_lineFrom
== (size_t)-1 )
4335 size_t count
= GetItemCount();
4338 m_lineFrom
= GetScrollPos(wxVERTICAL
);
4340 // this may happen if SetScrollbars() hadn't been called yet
4341 if ( m_lineFrom
>= count
)
4342 m_lineFrom
= count
- 1;
4344 // we redraw one extra line but this is needed to make the redrawing
4345 // logic work when there is a fractional number of lines on screen
4346 m_lineTo
= m_lineFrom
+ m_linesPerPage
;
4347 if ( m_lineTo
>= count
)
4348 m_lineTo
= count
- 1;
4350 else // empty control
4353 m_lineTo
= (size_t)-1;
4357 wxASSERT_MSG( IsEmpty() ||
4358 (m_lineFrom
<= m_lineTo
&& m_lineTo
< GetItemCount()),
4359 _T("GetVisibleLinesRange() returns incorrect result") );
4367 // -------------------------------------------------------------------------------------
4369 // -------------------------------------------------------------------------------------
4371 IMPLEMENT_DYNAMIC_CLASS(wxListItem
, wxObject
)
4373 wxListItem::wxListItem()
4380 void wxListItem::Clear()
4389 m_format
= wxLIST_FORMAT_CENTRE
;
4396 void wxListItem::ClearAttributes()
4405 // -------------------------------------------------------------------------------------
4407 // -------------------------------------------------------------------------------------
4409 IMPLEMENT_DYNAMIC_CLASS(wxListEvent
, wxNotifyEvent
)
4411 wxListEvent::wxListEvent( wxEventType commandType
, int id
)
4412 : wxNotifyEvent( commandType
, id
)
4418 m_cancelled
= FALSE
;
4423 void wxListEvent::CopyObject(wxObject
& object_dest
) const
4425 wxListEvent
*obj
= (wxListEvent
*)&object_dest
;
4427 wxNotifyEvent::CopyObject(object_dest
);
4429 obj
->m_code
= m_code
;
4430 obj
->m_itemIndex
= m_itemIndex
;
4431 obj
->m_oldItemIndex
= m_oldItemIndex
;
4433 obj
->m_cancelled
= m_cancelled
;
4434 obj
->m_pointDrag
= m_pointDrag
;
4435 obj
->m_item
.m_mask
= m_item
.m_mask
;
4436 obj
->m_item
.m_itemId
= m_item
.m_itemId
;
4437 obj
->m_item
.m_col
= m_item
.m_col
;
4438 obj
->m_item
.m_state
= m_item
.m_state
;
4439 obj
->m_item
.m_stateMask
= m_item
.m_stateMask
;
4440 obj
->m_item
.m_text
= m_item
.m_text
;
4441 obj
->m_item
.m_image
= m_item
.m_image
;
4442 obj
->m_item
.m_data
= m_item
.m_data
;
4443 obj
->m_item
.m_format
= m_item
.m_format
;
4444 obj
->m_item
.m_width
= m_item
.m_width
;
4446 if ( m_item
.HasAttributes() )
4448 obj
->m_item
.SetTextColour(m_item
.GetTextColour());
4452 // -------------------------------------------------------------------------------------
4454 // -------------------------------------------------------------------------------------
4456 IMPLEMENT_DYNAMIC_CLASS(wxListCtrl
, wxControl
)
4457 IMPLEMENT_DYNAMIC_CLASS(wxListView
, wxListCtrl
)
4459 BEGIN_EVENT_TABLE(wxListCtrl
,wxControl
)
4460 EVT_SIZE(wxListCtrl::OnSize
)
4461 EVT_IDLE(wxListCtrl::OnIdle
)
4464 wxListCtrl::wxListCtrl()
4466 m_imageListNormal
= (wxImageList
*) NULL
;
4467 m_imageListSmall
= (wxImageList
*) NULL
;
4468 m_imageListState
= (wxImageList
*) NULL
;
4470 m_ownsImageListNormal
=
4471 m_ownsImageListSmall
=
4472 m_ownsImageListState
= FALSE
;
4474 m_mainWin
= (wxListMainWindow
*) NULL
;
4475 m_headerWin
= (wxListHeaderWindow
*) NULL
;
4478 wxListCtrl::~wxListCtrl()
4481 m_mainWin
->ResetCurrent();
4483 if (m_ownsImageListNormal
)
4484 delete m_imageListNormal
;
4485 if (m_ownsImageListSmall
)
4486 delete m_imageListSmall
;
4487 if (m_ownsImageListState
)
4488 delete m_imageListState
;
4491 void wxListCtrl::CreateHeaderWindow()
4493 m_headerWin
= new wxListHeaderWindow
4495 this, -1, m_mainWin
,
4497 wxSize(GetClientSize().x
, HEADER_HEIGHT
),
4502 bool wxListCtrl::Create(wxWindow
*parent
,
4507 const wxValidator
&validator
,
4508 const wxString
&name
)
4512 m_imageListState
= (wxImageList
*) NULL
;
4513 m_ownsImageListNormal
=
4514 m_ownsImageListSmall
=
4515 m_ownsImageListState
= FALSE
;
4517 m_mainWin
= (wxListMainWindow
*) NULL
;
4518 m_headerWin
= (wxListHeaderWindow
*) NULL
;
4520 if ( !(style
& wxLC_MASK_TYPE
) )
4522 style
= style
| wxLC_LIST
;
4525 if ( !wxControl::Create( parent
, id
, pos
, size
, style
, validator
, name
) )
4528 // don't create the inner window with the border
4529 style
&= ~wxSUNKEN_BORDER
;
4531 m_mainWin
= new wxListMainWindow( this, -1, wxPoint(0,0), size
, style
);
4533 if ( HasFlag(wxLC_REPORT
) )
4535 CreateHeaderWindow();
4537 if ( HasFlag(wxLC_NO_HEADER
) )
4539 // VZ: why do we create it at all then?
4540 m_headerWin
->Show( FALSE
);
4547 void wxListCtrl::SetSingleStyle( long style
, bool add
)
4549 wxASSERT_MSG( !(style
& wxLC_VIRTUAL
),
4550 _T("wxLC_VIRTUAL can't be [un]set") );
4552 long flag
= GetWindowStyle();
4556 if (style
& wxLC_MASK_TYPE
)
4557 flag
&= ~(wxLC_MASK_TYPE
| wxLC_VIRTUAL
);
4558 if (style
& wxLC_MASK_ALIGN
)
4559 flag
&= ~wxLC_MASK_ALIGN
;
4560 if (style
& wxLC_MASK_SORT
)
4561 flag
&= ~wxLC_MASK_SORT
;
4573 SetWindowStyleFlag( flag
);
4576 void wxListCtrl::SetWindowStyleFlag( long flag
)
4580 m_mainWin
->DeleteEverything();
4582 // has the header visibility changed?
4583 bool hasHeader
= HasFlag(wxLC_REPORT
) && !HasFlag(wxLC_NO_HEADER
),
4584 willHaveHeader
= (flag
& wxLC_REPORT
) && !(flag
& wxLC_NO_HEADER
);
4586 if ( hasHeader
!= willHaveHeader
)
4593 // don't delete, just hide, as we can reuse it later
4594 m_headerWin
->Show(FALSE
);
4596 //else: nothing to do
4598 else // must show header
4602 CreateHeaderWindow();
4604 else // already have it, just show
4606 m_headerWin
->Show( TRUE
);
4610 ResizeReportView(willHaveHeader
);
4614 wxWindow::SetWindowStyleFlag( flag
);
4617 bool wxListCtrl::GetColumn(int col
, wxListItem
&item
) const
4619 m_mainWin
->GetColumn( col
, item
);
4623 bool wxListCtrl::SetColumn( int col
, wxListItem
& item
)
4625 m_mainWin
->SetColumn( col
, item
);
4629 int wxListCtrl::GetColumnWidth( int col
) const
4631 return m_mainWin
->GetColumnWidth( col
);
4634 bool wxListCtrl::SetColumnWidth( int col
, int width
)
4636 m_mainWin
->SetColumnWidth( col
, width
);
4640 int wxListCtrl::GetCountPerPage() const
4642 return m_mainWin
->GetCountPerPage(); // different from Windows ?
4645 bool wxListCtrl::GetItem( wxListItem
&info
) const
4647 m_mainWin
->GetItem( info
);
4651 bool wxListCtrl::SetItem( wxListItem
&info
)
4653 m_mainWin
->SetItem( info
);
4657 long wxListCtrl::SetItem( long index
, int col
, const wxString
& label
, int imageId
)
4660 info
.m_text
= label
;
4661 info
.m_mask
= wxLIST_MASK_TEXT
;
4662 info
.m_itemId
= index
;
4666 info
.m_image
= imageId
;
4667 info
.m_mask
|= wxLIST_MASK_IMAGE
;
4669 m_mainWin
->SetItem(info
);
4673 int wxListCtrl::GetItemState( long item
, long stateMask
) const
4675 return m_mainWin
->GetItemState( item
, stateMask
);
4678 bool wxListCtrl::SetItemState( long item
, long state
, long stateMask
)
4680 m_mainWin
->SetItemState( item
, state
, stateMask
);
4684 bool wxListCtrl::SetItemImage( long item
, int image
, int WXUNUSED(selImage
) )
4687 info
.m_image
= image
;
4688 info
.m_mask
= wxLIST_MASK_IMAGE
;
4689 info
.m_itemId
= item
;
4690 m_mainWin
->SetItem( info
);
4694 wxString
wxListCtrl::GetItemText( long item
) const
4697 info
.m_itemId
= item
;
4698 m_mainWin
->GetItem( info
);
4702 void wxListCtrl::SetItemText( long item
, const wxString
&str
)
4705 info
.m_mask
= wxLIST_MASK_TEXT
;
4706 info
.m_itemId
= item
;
4708 m_mainWin
->SetItem( info
);
4711 long wxListCtrl::GetItemData( long item
) const
4714 info
.m_itemId
= item
;
4715 m_mainWin
->GetItem( info
);
4719 bool wxListCtrl::SetItemData( long item
, long data
)
4722 info
.m_mask
= wxLIST_MASK_DATA
;
4723 info
.m_itemId
= item
;
4725 m_mainWin
->SetItem( info
);
4729 bool wxListCtrl::GetItemRect( long item
, wxRect
&rect
, int WXUNUSED(code
) ) const
4731 m_mainWin
->GetItemRect( item
, rect
);
4735 bool wxListCtrl::GetItemPosition( long item
, wxPoint
& pos
) const
4737 m_mainWin
->GetItemPosition( item
, pos
);
4741 bool wxListCtrl::SetItemPosition( long WXUNUSED(item
), const wxPoint
& WXUNUSED(pos
) )
4746 int wxListCtrl::GetItemCount() const
4748 return m_mainWin
->GetItemCount();
4751 int wxListCtrl::GetColumnCount() const
4753 return m_mainWin
->GetColumnCount();
4756 void wxListCtrl::SetItemSpacing( int spacing
, bool isSmall
)
4758 m_mainWin
->SetItemSpacing( spacing
, isSmall
);
4761 int wxListCtrl::GetItemSpacing( bool isSmall
) const
4763 return m_mainWin
->GetItemSpacing( isSmall
);
4766 int wxListCtrl::GetSelectedItemCount() const
4768 return m_mainWin
->GetSelectedItemCount();
4771 wxColour
wxListCtrl::GetTextColour() const
4773 return GetForegroundColour();
4776 void wxListCtrl::SetTextColour(const wxColour
& col
)
4778 SetForegroundColour(col
);
4781 long wxListCtrl::GetTopItem() const
4786 long wxListCtrl::GetNextItem( long item
, int geom
, int state
) const
4788 return m_mainWin
->GetNextItem( item
, geom
, state
);
4791 wxImageList
*wxListCtrl::GetImageList(int which
) const
4793 if (which
== wxIMAGE_LIST_NORMAL
)
4795 return m_imageListNormal
;
4797 else if (which
== wxIMAGE_LIST_SMALL
)
4799 return m_imageListSmall
;
4801 else if (which
== wxIMAGE_LIST_STATE
)
4803 return m_imageListState
;
4805 return (wxImageList
*) NULL
;
4808 void wxListCtrl::SetImageList( wxImageList
*imageList
, int which
)
4810 if ( which
== wxIMAGE_LIST_NORMAL
)
4812 if (m_ownsImageListNormal
) delete m_imageListNormal
;
4813 m_imageListNormal
= imageList
;
4814 m_ownsImageListNormal
= FALSE
;
4816 else if ( which
== wxIMAGE_LIST_SMALL
)
4818 if (m_ownsImageListSmall
) delete m_imageListSmall
;
4819 m_imageListSmall
= imageList
;
4820 m_ownsImageListSmall
= FALSE
;
4822 else if ( which
== wxIMAGE_LIST_STATE
)
4824 if (m_ownsImageListState
) delete m_imageListState
;
4825 m_imageListState
= imageList
;
4826 m_ownsImageListState
= FALSE
;
4829 m_mainWin
->SetImageList( imageList
, which
);
4832 void wxListCtrl::AssignImageList(wxImageList
*imageList
, int which
)
4834 SetImageList(imageList
, which
);
4835 if ( which
== wxIMAGE_LIST_NORMAL
)
4836 m_ownsImageListNormal
= TRUE
;
4837 else if ( which
== wxIMAGE_LIST_SMALL
)
4838 m_ownsImageListSmall
= TRUE
;
4839 else if ( which
== wxIMAGE_LIST_STATE
)
4840 m_ownsImageListState
= TRUE
;
4843 bool wxListCtrl::Arrange( int WXUNUSED(flag
) )
4848 bool wxListCtrl::DeleteItem( long item
)
4850 m_mainWin
->DeleteItem( item
);
4854 bool wxListCtrl::DeleteAllItems()
4856 m_mainWin
->DeleteAllItems();
4860 bool wxListCtrl::DeleteAllColumns()
4862 size_t count
= m_mainWin
->m_columns
.GetCount();
4863 for ( size_t n
= 0; n
< count
; n
++ )
4869 void wxListCtrl::ClearAll()
4871 m_mainWin
->DeleteEverything();
4874 bool wxListCtrl::DeleteColumn( int col
)
4876 m_mainWin
->DeleteColumn( col
);
4880 void wxListCtrl::Edit( long item
)
4882 m_mainWin
->EditLabel( item
);
4885 bool wxListCtrl::EnsureVisible( long item
)
4887 m_mainWin
->EnsureVisible( item
);
4891 long wxListCtrl::FindItem( long start
, const wxString
& str
, bool partial
)
4893 return m_mainWin
->FindItem( start
, str
, partial
);
4896 long wxListCtrl::FindItem( long start
, long data
)
4898 return m_mainWin
->FindItem( start
, data
);
4901 long wxListCtrl::FindItem( long WXUNUSED(start
), const wxPoint
& WXUNUSED(pt
),
4902 int WXUNUSED(direction
))
4907 long wxListCtrl::HitTest( const wxPoint
&point
, int &flags
)
4909 return m_mainWin
->HitTest( (int)point
.x
, (int)point
.y
, flags
);
4912 long wxListCtrl::InsertItem( wxListItem
& info
)
4914 m_mainWin
->InsertItem( info
);
4915 return info
.m_itemId
;
4918 long wxListCtrl::InsertItem( long index
, const wxString
&label
)
4921 info
.m_text
= label
;
4922 info
.m_mask
= wxLIST_MASK_TEXT
;
4923 info
.m_itemId
= index
;
4924 return InsertItem( info
);
4927 long wxListCtrl::InsertItem( long index
, int imageIndex
)
4930 info
.m_mask
= wxLIST_MASK_IMAGE
;
4931 info
.m_image
= imageIndex
;
4932 info
.m_itemId
= index
;
4933 return InsertItem( info
);
4936 long wxListCtrl::InsertItem( long index
, const wxString
&label
, int imageIndex
)
4939 info
.m_text
= label
;
4940 info
.m_image
= imageIndex
;
4941 info
.m_mask
= wxLIST_MASK_TEXT
| wxLIST_MASK_IMAGE
;
4942 info
.m_itemId
= index
;
4943 return InsertItem( info
);
4946 long wxListCtrl::InsertColumn( long col
, wxListItem
&item
)
4948 wxASSERT( m_headerWin
);
4949 m_mainWin
->InsertColumn( col
, item
);
4950 m_headerWin
->Refresh();
4955 long wxListCtrl::InsertColumn( long col
, const wxString
&heading
,
4956 int format
, int width
)
4959 item
.m_mask
= wxLIST_MASK_TEXT
| wxLIST_MASK_FORMAT
;
4960 item
.m_text
= heading
;
4963 item
.m_mask
|= wxLIST_MASK_WIDTH
;
4964 item
.m_width
= width
;
4966 item
.m_format
= format
;
4968 return InsertColumn( col
, item
);
4971 bool wxListCtrl::ScrollList( int WXUNUSED(dx
), int WXUNUSED(dy
) )
4977 // fn is a function which takes 3 long arguments: item1, item2, data.
4978 // item1 is the long data associated with a first item (NOT the index).
4979 // item2 is the long data associated with a second item (NOT the index).
4980 // data is the same value as passed to SortItems.
4981 // The return value is a negative number if the first item should precede the second
4982 // item, a positive number of the second item should precede the first,
4983 // or zero if the two items are equivalent.
4984 // data is arbitrary data to be passed to the sort function.
4986 bool wxListCtrl::SortItems( wxListCtrlCompare fn
, long data
)
4988 m_mainWin
->SortItems( fn
, data
);
4992 // ----------------------------------------------------------------------------
4994 // ----------------------------------------------------------------------------
4996 void wxListCtrl::OnSize(wxSizeEvent
& event
)
5001 ResizeReportView(m_mainWin
->HasHeader());
5003 m_mainWin
->RecalculatePositions();
5006 void wxListCtrl::ResizeReportView(bool showHeader
)
5009 GetClientSize( &cw
, &ch
);
5013 m_headerWin
->SetSize( 0, 0, cw
, HEADER_HEIGHT
);
5014 m_mainWin
->SetSize( 0, HEADER_HEIGHT
+ 1, cw
, ch
- HEADER_HEIGHT
- 1 );
5016 else // no header window
5018 m_mainWin
->SetSize( 0, 0, cw
, ch
);
5022 void wxListCtrl::OnIdle( wxIdleEvent
& event
)
5026 // do it only if needed
5027 if ( !m_mainWin
->m_dirty
)
5030 m_mainWin
->RecalculatePositions();
5033 // ----------------------------------------------------------------------------
5035 // ----------------------------------------------------------------------------
5037 bool wxListCtrl::SetBackgroundColour( const wxColour
&colour
)
5041 m_mainWin
->SetBackgroundColour( colour
);
5042 m_mainWin
->m_dirty
= TRUE
;
5048 bool wxListCtrl::SetForegroundColour( const wxColour
&colour
)
5050 if ( !wxWindow::SetForegroundColour( colour
) )
5055 m_mainWin
->SetForegroundColour( colour
);
5056 m_mainWin
->m_dirty
= TRUE
;
5061 m_headerWin
->SetForegroundColour( colour
);
5067 bool wxListCtrl::SetFont( const wxFont
&font
)
5069 if ( !wxWindow::SetFont( font
) )
5074 m_mainWin
->SetFont( font
);
5075 m_mainWin
->m_dirty
= TRUE
;
5080 m_headerWin
->SetFont( font
);
5086 // ----------------------------------------------------------------------------
5087 // methods forwarded to m_mainWin
5088 // ----------------------------------------------------------------------------
5090 #if wxUSE_DRAG_AND_DROP
5092 void wxListCtrl::SetDropTarget( wxDropTarget
*dropTarget
)
5094 m_mainWin
->SetDropTarget( dropTarget
);
5097 wxDropTarget
*wxListCtrl::GetDropTarget() const
5099 return m_mainWin
->GetDropTarget();
5102 #endif // wxUSE_DRAG_AND_DROP
5104 bool wxListCtrl::SetCursor( const wxCursor
&cursor
)
5106 return m_mainWin
? m_mainWin
->wxWindow::SetCursor(cursor
) : FALSE
;
5109 wxColour
wxListCtrl::GetBackgroundColour() const
5111 return m_mainWin
? m_mainWin
->GetBackgroundColour() : wxColour();
5114 wxColour
wxListCtrl::GetForegroundColour() const
5116 return m_mainWin
? m_mainWin
->GetForegroundColour() : wxColour();
5119 bool wxListCtrl::DoPopupMenu( wxMenu
*menu
, int x
, int y
)
5122 return m_mainWin
->PopupMenu( menu
, x
, y
);
5125 #endif // wxUSE_MENUS
5128 void wxListCtrl::SetFocus()
5130 /* The test in window.cpp fails as we are a composite
5131 window, so it checks against "this", but not m_mainWin. */
5132 if ( FindFocus() != this )
5133 m_mainWin
->SetFocus();
5136 // ----------------------------------------------------------------------------
5137 // virtual list control support
5138 // ----------------------------------------------------------------------------
5140 wxString
wxListCtrl::OnGetItemText(long item
, long col
) const
5142 // this is a pure virtual function, in fact - which is not really pure
5143 // because the controls which are not virtual don't need to implement it
5144 wxFAIL_MSG( _T("not supposed to be called") );
5146 return wxEmptyString
;
5149 int wxListCtrl::OnGetItemImage(long item
) const
5152 wxFAIL_MSG( _T("not supposed to be called") );
5157 wxListItemAttr
*wxListCtrl::OnGetItemAttr(long item
) const
5159 wxASSERT_MSG( item
>= 0 && item
< GetItemCount(),
5160 _T("invalid item index in OnGetItemAttr()") );
5162 // no attributes by default
5166 void wxListCtrl::SetItemCount(long count
)
5168 wxASSERT_MSG( IsVirtual(), _T("this is for virtual controls only") );
5170 m_mainWin
->SetItemCount(count
);
5173 void wxListCtrl::RefreshItem(long item
)
5175 m_mainWin
->RefreshLine(item
);
5178 void wxListCtrl::RefreshItems(long itemFrom
, long itemTo
)
5180 m_mainWin
->RefreshLines(itemFrom
, itemTo
);
5183 #endif // wxUSE_LISTCTRL