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
279 wxListHeaderData( const wxListItem
&info
);
280 void SetItem( const wxListItem
&item
);
281 void SetPosition( int x
, int y
);
282 void SetWidth( int w
);
283 void SetFormat( int format
);
284 void SetHeight( int h
);
285 bool HasImage() const;
287 bool HasText() const { return !m_text
.empty(); }
288 const wxString
& GetText() const { return m_text
; }
289 void SetText(const wxString
& text
) { m_text
= text
; }
291 void GetItem( wxListItem
&item
);
293 bool IsHit( int x
, int y
) const;
294 int GetImage() const;
295 int GetWidth() const;
296 int GetFormat() const;
299 DECLARE_DYNAMIC_CLASS(wxListHeaderData
);
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();
442 virtual ~wxListHeaderWindow();
444 wxListHeaderWindow( wxWindow
*win
,
446 wxListMainWindow
*owner
,
447 const wxPoint
&pos
= wxDefaultPosition
,
448 const wxSize
&size
= wxDefaultSize
,
450 const wxString
&name
= "wxlistctrlcolumntitles" );
452 void DoDrawRect( wxDC
*dc
, int x
, int y
, int w
, int h
);
454 void AdjustDC(wxDC
& dc
);
456 void OnPaint( wxPaintEvent
&event
);
457 void OnMouse( wxMouseEvent
&event
);
458 void OnSetFocus( wxFocusEvent
&event
);
464 DECLARE_DYNAMIC_CLASS(wxListHeaderWindow
)
465 DECLARE_EVENT_TABLE()
468 //-----------------------------------------------------------------------------
469 // wxListRenameTimer (internal)
470 //-----------------------------------------------------------------------------
472 class WXDLLEXPORT wxListRenameTimer
: public wxTimer
475 wxListMainWindow
*m_owner
;
478 wxListRenameTimer( wxListMainWindow
*owner
);
482 //-----------------------------------------------------------------------------
483 // wxListTextCtrl (internal)
484 //-----------------------------------------------------------------------------
486 class WXDLLEXPORT wxListTextCtrl
: public wxTextCtrl
491 wxListMainWindow
*m_owner
;
492 wxString m_startValue
;
496 wxListTextCtrl( wxWindow
*parent
, const wxWindowID id
,
497 bool *accept
, wxString
*res
, wxListMainWindow
*owner
,
498 const wxString
&value
= "",
499 const wxPoint
&pos
= wxDefaultPosition
, const wxSize
&size
= wxDefaultSize
,
501 const wxValidator
& validator
= wxDefaultValidator
,
502 const wxString
&name
= "listctrltextctrl" );
503 void OnChar( wxKeyEvent
&event
);
504 void OnKeyUp( wxKeyEvent
&event
);
505 void OnKillFocus( wxFocusEvent
&event
);
508 DECLARE_DYNAMIC_CLASS(wxListTextCtrl
);
509 DECLARE_EVENT_TABLE()
512 //-----------------------------------------------------------------------------
513 // wxListMainWindow (internal)
514 //-----------------------------------------------------------------------------
516 WX_DECLARE_LIST(wxListHeaderData
, wxListHeaderDataList
);
517 #include "wx/listimpl.cpp"
518 WX_DEFINE_LIST(wxListHeaderDataList
);
520 class WXDLLEXPORT wxListMainWindow
: public wxScrolledWindow
524 wxListMainWindow( wxWindow
*parent
,
526 const wxPoint
& pos
= wxDefaultPosition
,
527 const wxSize
& size
= wxDefaultSize
,
529 const wxString
&name
= _T("listctrlmainwindow") );
531 virtual ~wxListMainWindow();
533 bool HasFlag(int flag
) const { return m_parent
->HasFlag(flag
); }
535 // return true if this is a virtual list control
536 bool IsVirtual() const { return HasFlag(wxLC_VIRTUAL
); }
538 // return true if the control is in report mode
539 bool InReportView() const { return HasFlag(wxLC_REPORT
); }
541 // return true if we are in single selection mode, false if multi sel
542 bool IsSingleSel() const { return HasFlag(wxLC_SINGLE_SEL
); }
544 // do we have a header window?
545 bool HasHeader() const
546 { return HasFlag(wxLC_REPORT
) && !HasFlag(wxLC_NO_HEADER
); }
548 void HighlightAll( bool on
);
550 // all these functions only do something if the line is currently visible
552 // change the line "selected" state, return TRUE if it really changed
553 bool HighlightLine( size_t line
, bool highlight
= TRUE
);
555 // as HighlightLine() but do it for the range of lines: this is incredibly
556 // more efficient for virtual list controls!
558 // NB: unlike HighlightLine() this one does refresh the lines on screen
559 void HighlightLines( size_t lineFrom
, size_t lineTo
, bool on
= TRUE
);
561 // toggle the line state and refresh it
562 void ReverseHighlight( size_t line
)
563 { HighlightLine(line
, !IsHighlighted(line
)); RefreshLine(line
); }
565 // return true if the line is highlighted
566 bool IsHighlighted(size_t line
) const;
568 // refresh one or several lines at once
569 void RefreshLine( size_t line
);
570 void RefreshLines( size_t lineFrom
, size_t lineTo
);
572 // refresh all selected items
573 void RefreshSelected();
575 // refresh all lines below the given one: the difference with
576 // RefreshLines() is that the index here might not be a valid one (happens
577 // when the last line is deleted)
578 void RefreshAfter( size_t lineFrom
);
580 // the methods which are forwarded to wxListLineData itself in list/icon
581 // modes but are here because the lines don't store their positions in the
584 // get the bound rect for the entire line
585 wxRect
GetLineRect(size_t line
) const;
587 // get the bound rect of the label
588 wxRect
GetLineLabelRect(size_t line
) const;
590 // get the bound rect of the items icon (only may be called if we do have
592 wxRect
GetLineIconRect(size_t line
) const;
594 // get the rect to be highlighted when the item has focus
595 wxRect
GetLineHighlightRect(size_t line
) const;
597 // get the size of the total line rect
598 wxSize
GetLineSize(size_t line
) const
599 { return GetLineRect(line
).GetSize(); }
601 // return the hit code for the corresponding position (in this line)
602 long HitTestLine(size_t line
, int x
, int y
) const;
604 // bring the selected item into view, scrolling to it if necessary
605 void MoveToItem(size_t item
);
607 // bring the current item into view
608 void MoveToFocus() { MoveToItem(m_current
); }
610 void EditLabel( long item
);
611 void OnRenameTimer();
612 void OnRenameAccept();
614 void OnMouse( wxMouseEvent
&event
);
616 // called to switch the selection from the current item to newCurrent,
617 void OnArrowChar( size_t newCurrent
, const wxKeyEvent
& event
);
619 void OnChar( wxKeyEvent
&event
);
620 void OnKeyDown( wxKeyEvent
&event
);
621 void OnSetFocus( wxFocusEvent
&event
);
622 void OnKillFocus( wxFocusEvent
&event
);
623 void OnScroll(wxScrollWinEvent
& event
) ;
625 void OnPaint( wxPaintEvent
&event
);
627 void DrawImage( int index
, wxDC
*dc
, int x
, int y
);
628 void GetImageSize( int index
, int &width
, int &height
) const;
629 int GetTextLength( const wxString
&s
) const;
631 void SetImageList( wxImageList
*imageList
, int which
);
632 void SetItemSpacing( int spacing
, bool isSmall
= FALSE
);
633 int GetItemSpacing( bool isSmall
= FALSE
);
635 void SetColumn( int col
, wxListItem
&item
);
636 void SetColumnWidth( int col
, int width
);
637 void GetColumn( int col
, wxListItem
&item
) const;
638 int GetColumnWidth( int col
) const;
639 int GetColumnCount() const { return m_columns
.GetCount(); }
641 // returns the sum of the heights of all columns
642 int GetHeaderWidth() const;
644 int GetCountPerPage() const;
646 void SetItem( wxListItem
&item
);
647 void GetItem( wxListItem
&item
);
648 void SetItemState( long item
, long state
, long stateMask
);
649 int GetItemState( long item
, long stateMask
);
650 void GetItemRect( long index
, wxRect
&rect
);
651 bool GetItemPosition( long item
, wxPoint
& pos
);
652 int GetSelectedItemCount();
654 // set the scrollbars and update the positions of the items
655 void RecalculatePositions(bool noRefresh
= FALSE
);
657 // refresh the window and the header
660 long GetNextItem( long item
, int geometry
, int state
);
661 void DeleteItem( long index
);
662 void DeleteAllItems();
663 void DeleteColumn( int col
);
664 void DeleteEverything();
665 void EnsureVisible( long index
);
666 long FindItem( long start
, const wxString
& str
, bool partial
= FALSE
);
667 long FindItem( long start
, long data
);
668 long HitTest( int x
, int y
, int &flags
);
669 void InsertItem( wxListItem
&item
);
670 void InsertColumn( long col
, wxListItem
&item
);
671 void SortItems( wxListCtrlCompare fn
, long data
);
673 size_t GetItemCount() const;
674 bool IsEmpty() const { return GetItemCount() == 0; }
675 void SetItemCount(long count
);
677 void ResetCurrent() { m_current
= (size_t)-1; }
678 bool HasCurrent() const { return m_current
!= (size_t)-1; }
680 // send out a wxListEvent
681 void SendNotify( size_t line
,
683 wxPoint point
= wxDefaultPosition
);
685 // override base class virtual to reset m_lineHeight when the font changes
686 virtual bool SetFont(const wxFont
& font
)
688 if ( !wxScrolledWindow::SetFont(font
) )
696 // these are for wxListLineData usage only
698 // get the backpointer to the list ctrl
699 wxListCtrl
*GetListCtrl() const
701 return wxStaticCast(GetParent(), wxListCtrl
);
704 // get the height of all lines (assuming they all do have the same height)
705 wxCoord
GetLineHeight() const;
707 // get the y position of the given line (only for report view)
708 wxCoord
GetLineY(size_t line
) const;
710 // get the brush to use for the item highlighting
711 wxBrush
*GetHighlightBrush() const
713 return m_hasFocus
? m_highlightBrush
: m_highlightUnfocusedBrush
;
717 // the array of all line objects for a non virtual list control
718 wxListLineDataArray m_lines
;
720 // the list of column objects
721 wxListHeaderDataList m_columns
;
723 // currently focused item or -1
726 // the item currently being edited or -1
727 size_t m_currentEdit
;
729 // the number of lines per page
732 // this flag is set when something which should result in the window
733 // redrawing happens (i.e. an item was added or deleted, or its appearance
734 // changed) and OnPaint() doesn't redraw the window while it is set which
735 // allows to minimize the number of repaintings when a lot of items are
736 // being added. The real repainting occurs only after the next OnIdle()
740 wxColour
*m_highlightColour
;
743 wxImageList
*m_small_image_list
;
744 wxImageList
*m_normal_image_list
;
746 int m_normal_spacing
;
750 wxTimer
*m_renameTimer
;
752 wxString m_renameRes
;
757 // for double click logic
758 size_t m_lineLastClicked
,
759 m_lineBeforeLastClicked
;
762 // the total count of items in a virtual list control
765 // the object maintaining the items selection state, only used in virtual
767 wxSelectionStore m_selStore
;
769 // common part of all ctors
772 // intiialize m_[xy]Scroll
773 void InitScrolling();
775 // get the line data for the given index
776 wxListLineData
*GetLine(size_t n
) const
778 wxASSERT_MSG( n
!= (size_t)-1, _T("invalid line index") );
782 wxConstCast(this, wxListMainWindow
)->CacheLineData(n
);
790 // get a dummy line which can be used for geometry calculations and such:
791 // you must use GetLine() if you want to really draw the line
792 wxListLineData
*GetDummyLine() const;
794 // cache the line data of the n-th line in m_lines[0]
795 void CacheLineData(size_t line
);
797 // get the range of visible lines
798 void GetVisibleLinesRange(size_t *from
, size_t *to
);
800 // force us to recalculate the range of visible lines
801 void ResetVisibleLinesRange() { m_lineFrom
= (size_t)-1; }
803 // get the colour to be used for drawing the rules
804 wxColour
GetRuleColour() const
809 return wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DLIGHT
);
814 // initialize the current item if needed
815 void UpdateCurrent();
817 // delete all items but don't refresh: called from dtor
818 void DoDeleteAllItems();
820 // called when an item is [un]focuded, i.e. becomes [not] current
823 void OnFocusLine( size_t line
);
824 void OnUnfocusLine( size_t line
);
826 // the height of one line using the current font
827 wxCoord m_lineHeight
;
829 // the total header width or 0 if not calculated yet
830 wxCoord m_headerWidth
;
832 // the first and last lines being shown on screen right now (inclusive),
833 // both may be -1 if they must be calculated so never access them directly:
834 // use GetVisibleLinesRange() above instead
838 // the brushes to use for item highlighting when we do/don't have focus
839 wxBrush
*m_highlightBrush
,
840 *m_highlightUnfocusedBrush
;
842 DECLARE_DYNAMIC_CLASS(wxListMainWindow
);
843 DECLARE_EVENT_TABLE()
846 // ============================================================================
848 // ============================================================================
850 // ----------------------------------------------------------------------------
852 // ----------------------------------------------------------------------------
854 bool wxSelectionStore::IsSelected(size_t item
) const
856 bool isSel
= m_itemsSel
.Index(item
) != wxNOT_FOUND
;
858 // if the default state is to be selected, being in m_itemsSel means that
859 // the item is not selected, so we have to inverse the logic
860 return m_defaultState
? !isSel
: isSel
;
863 bool wxSelectionStore::SelectItem(size_t item
, bool select
)
865 // search for the item ourselves as like this we get the index where to
866 // insert it later if needed, so we do only one search in the array instead
867 // of two (adding item to a sorted array requires a search)
868 size_t index
= m_itemsSel
.IndexForInsert(item
);
869 bool isSel
= index
< m_itemsSel
.GetCount() && m_itemsSel
[index
] == item
;
871 if ( select
!= m_defaultState
)
875 m_itemsSel
.AddAt(item
, index
);
880 else // reset to default state
884 m_itemsSel
.RemoveAt(index
);
892 bool wxSelectionStore::SelectRange(size_t itemFrom
, size_t itemTo
,
894 wxArrayInt
*itemsChanged
)
896 // 100 is hardcoded but it shouldn't matter much: the important thing is
897 // that we don't refresh everything when really few (e.g. 1 or 2) items
899 static const size_t MANY_ITEMS
= 100;
901 wxASSERT_MSG( itemFrom
<= itemTo
, _T("should be in order") );
903 // are we going to have more [un]selected items than the other ones?
904 if ( itemTo
- itemFrom
> m_count
/2 )
906 if ( select
!= m_defaultState
)
908 // the default state now becomes the same as 'select'
909 m_defaultState
= select
;
911 // so all the old selections (which had state select) shouldn't be
912 // selected any more, but all the other ones should
913 wxIndexArray selOld
= m_itemsSel
;
916 // TODO: it should be possible to optimize the searches a bit
917 // knowing the possible range
920 for ( item
= 0; item
< itemFrom
; item
++ )
922 if ( selOld
.Index(item
) == wxNOT_FOUND
)
923 m_itemsSel
.Add(item
);
926 for ( item
= itemTo
+ 1; item
< m_count
; item
++ )
928 if ( selOld
.Index(item
) == wxNOT_FOUND
)
929 m_itemsSel
.Add(item
);
932 // many items (> half) changed state
935 else // select == m_defaultState
937 // get the inclusive range of items between itemFrom and itemTo
938 size_t count
= m_itemsSel
.GetCount(),
939 start
= m_itemsSel
.IndexForInsert(itemFrom
),
940 end
= m_itemsSel
.IndexForInsert(itemTo
);
942 if ( start
== count
|| m_itemsSel
[start
] < itemFrom
)
947 if ( end
== count
|| m_itemsSel
[end
] > itemTo
)
954 // delete all of them (from end to avoid changing indices)
955 for ( int i
= end
; i
>= (int)start
; i
-- )
959 if ( itemsChanged
->GetCount() > MANY_ITEMS
)
961 // stop counting (see comment below)
965 itemsChanged
->Add(m_itemsSel
[i
]);
968 m_itemsSel
.RemoveAt(i
);
973 else // "few" items change state
977 itemsChanged
->Empty();
980 // just add the items to the selection
981 for ( size_t item
= itemFrom
; item
<= itemTo
; item
++ )
983 if ( SelectItem(item
, select
) && itemsChanged
)
985 itemsChanged
->Add(item
);
987 if ( itemsChanged
->GetCount() > MANY_ITEMS
)
989 // stop counting them, we'll just eat gobs of memory
990 // for nothing at all - faster to refresh everything in
998 // we set it to NULL if there are many items changing state
999 return itemsChanged
!= NULL
;
1002 void wxSelectionStore::OnItemDelete(size_t item
)
1004 size_t count
= m_itemsSel
.GetCount(),
1005 i
= m_itemsSel
.IndexForInsert(item
);
1007 if ( i
< count
&& m_itemsSel
[i
] == item
)
1009 // this item itself was in m_itemsSel, remove it from there
1010 m_itemsSel
.RemoveAt(i
);
1015 // and adjust the index of all which follow it
1018 // all following elements must be greater than the one we deleted
1019 wxASSERT_MSG( m_itemsSel
[i
] > item
, _T("logic error") );
1025 //-----------------------------------------------------------------------------
1027 //-----------------------------------------------------------------------------
1029 wxListItemData::~wxListItemData()
1031 // in the virtual list control the attributes are managed by the main
1032 // program, so don't delete them
1033 if ( !m_owner
->IsVirtual() )
1041 void wxListItemData::Init()
1049 wxListItemData::wxListItemData(wxListMainWindow
*owner
)
1055 if ( owner
->InReportView() )
1061 m_rect
= new wxRect
;
1065 void wxListItemData::SetItem( const wxListItem
&info
)
1067 if ( info
.m_mask
& wxLIST_MASK_TEXT
)
1068 SetText(info
.m_text
);
1069 if ( info
.m_mask
& wxLIST_MASK_IMAGE
)
1070 m_image
= info
.m_image
;
1071 if ( info
.m_mask
& wxLIST_MASK_DATA
)
1072 m_data
= info
.m_data
;
1074 if ( info
.HasAttributes() )
1077 *m_attr
= *info
.GetAttributes();
1079 m_attr
= new wxListItemAttr(*info
.GetAttributes());
1087 m_rect
->width
= info
.m_width
;
1091 void wxListItemData::SetPosition( int x
, int y
)
1093 wxCHECK_RET( m_rect
, _T("unexpected SetPosition() call") );
1099 void wxListItemData::SetSize( int width
, int height
)
1101 wxCHECK_RET( m_rect
, _T("unexpected SetSize() call") );
1104 m_rect
->width
= width
;
1106 m_rect
->height
= height
;
1109 bool wxListItemData::IsHit( int x
, int y
) const
1111 wxCHECK_MSG( m_rect
, FALSE
, _T("can't be called in this mode") );
1113 return wxRect(GetX(), GetY(), GetWidth(), GetHeight()).Inside(x
, y
);
1116 int wxListItemData::GetX() const
1118 wxCHECK_MSG( m_rect
, 0, _T("can't be called in this mode") );
1123 int wxListItemData::GetY() const
1125 wxCHECK_MSG( m_rect
, 0, _T("can't be called in this mode") );
1130 int wxListItemData::GetWidth() const
1132 wxCHECK_MSG( m_rect
, 0, _T("can't be called in this mode") );
1134 return m_rect
->width
;
1137 int wxListItemData::GetHeight() const
1139 wxCHECK_MSG( m_rect
, 0, _T("can't be called in this mode") );
1141 return m_rect
->height
;
1144 void wxListItemData::GetItem( wxListItem
&info
) const
1146 info
.m_text
= m_text
;
1147 info
.m_image
= m_image
;
1148 info
.m_data
= m_data
;
1152 if ( m_attr
->HasTextColour() )
1153 info
.SetTextColour(m_attr
->GetTextColour());
1154 if ( m_attr
->HasBackgroundColour() )
1155 info
.SetBackgroundColour(m_attr
->GetBackgroundColour());
1156 if ( m_attr
->HasFont() )
1157 info
.SetFont(m_attr
->GetFont());
1161 //-----------------------------------------------------------------------------
1163 //-----------------------------------------------------------------------------
1165 IMPLEMENT_DYNAMIC_CLASS(wxListHeaderData
,wxObject
);
1167 wxListHeaderData::wxListHeaderData()
1178 wxListHeaderData::wxListHeaderData( const wxListItem
&item
)
1186 void wxListHeaderData::SetItem( const wxListItem
&item
)
1188 m_mask
= item
.m_mask
;
1189 m_text
= item
.m_text
;
1190 m_image
= item
.m_image
;
1191 m_format
= item
.m_format
;
1193 SetWidth(item
.m_width
);
1196 void wxListHeaderData::SetPosition( int x
, int y
)
1202 void wxListHeaderData::SetHeight( int h
)
1207 void wxListHeaderData::SetWidth( int w
)
1211 m_width
= WIDTH_COL_DEFAULT
;
1212 if (m_width
< WIDTH_COL_MIN
)
1213 m_width
= WIDTH_COL_MIN
;
1216 void wxListHeaderData::SetFormat( int format
)
1221 bool wxListHeaderData::HasImage() const
1223 return (m_image
!= 0);
1226 bool wxListHeaderData::IsHit( int x
, int y
) const
1228 return ((x
>= m_xpos
) && (x
<= m_xpos
+m_width
) && (y
>= m_ypos
) && (y
<= m_ypos
+m_height
));
1231 void wxListHeaderData::GetItem( wxListItem
&item
)
1233 item
.m_mask
= m_mask
;
1234 item
.m_text
= m_text
;
1235 item
.m_image
= m_image
;
1236 item
.m_format
= m_format
;
1237 item
.m_width
= m_width
;
1240 int wxListHeaderData::GetImage() const
1245 int wxListHeaderData::GetWidth() const
1250 int wxListHeaderData::GetFormat() const
1255 //-----------------------------------------------------------------------------
1257 //-----------------------------------------------------------------------------
1259 inline int wxListLineData::GetMode() const
1261 return m_owner
->GetListCtrl()->GetWindowStyleFlag() & wxLC_MASK_TYPE
;
1264 inline bool wxListLineData::InReportView() const
1266 return m_owner
->HasFlag(wxLC_REPORT
);
1269 inline bool wxListLineData::IsVirtual() const
1271 return m_owner
->IsVirtual();
1274 wxListLineData::wxListLineData( wxListMainWindow
*owner
)
1277 m_items
.DeleteContents( TRUE
);
1279 if ( InReportView() )
1285 m_gi
= new GeometryInfo
;
1288 m_highlighted
= FALSE
;
1290 InitItems( GetMode() == wxLC_REPORT
? m_owner
->GetColumnCount() : 1 );
1293 void wxListLineData::CalculateSize( wxDC
*dc
, int spacing
)
1295 wxListItemDataList::Node
*node
= m_items
.GetFirst();
1296 wxCHECK_RET( node
, _T("no subitems at all??") );
1298 wxListItemData
*item
= node
->GetData();
1300 switch ( GetMode() )
1303 case wxLC_SMALL_ICON
:
1305 m_gi
->m_rectAll
.width
= spacing
;
1307 wxString s
= item
->GetText();
1313 m_gi
->m_rectLabel
.width
=
1314 m_gi
->m_rectLabel
.height
= 0;
1318 dc
->GetTextExtent( s
, &lw
, &lh
);
1319 if (lh
< SCROLL_UNIT_Y
)
1324 m_gi
->m_rectAll
.height
= spacing
+ lh
;
1326 m_gi
->m_rectAll
.width
= lw
;
1328 m_gi
->m_rectLabel
.width
= lw
;
1329 m_gi
->m_rectLabel
.height
= lh
;
1332 if (item
->HasImage())
1335 m_owner
->GetImageSize( item
->GetImage(), w
, h
);
1336 m_gi
->m_rectIcon
.width
= w
+ 8;
1337 m_gi
->m_rectIcon
.height
= h
+ 8;
1339 if ( m_gi
->m_rectIcon
.width
> m_gi
->m_rectAll
.width
)
1340 m_gi
->m_rectAll
.width
= m_gi
->m_rectIcon
.width
;
1341 if ( m_gi
->m_rectIcon
.height
+ lh
> m_gi
->m_rectAll
.height
- 4 )
1342 m_gi
->m_rectAll
.height
= m_gi
->m_rectIcon
.height
+ lh
+ 4;
1345 if ( item
->HasText() )
1347 m_gi
->m_rectHighlight
.width
= m_gi
->m_rectLabel
.width
;
1348 m_gi
->m_rectHighlight
.height
= m_gi
->m_rectLabel
.height
;
1350 else // no text, highlight the icon
1352 m_gi
->m_rectHighlight
.width
= m_gi
->m_rectIcon
.width
;
1353 m_gi
->m_rectHighlight
.height
= m_gi
->m_rectIcon
.height
;
1360 wxString s
= item
->GetTextForMeasuring();
1363 dc
->GetTextExtent( s
, &lw
, &lh
);
1364 if (lh
< SCROLL_UNIT_Y
)
1369 m_gi
->m_rectLabel
.width
= lw
;
1370 m_gi
->m_rectLabel
.height
= lh
;
1372 m_gi
->m_rectAll
.width
= lw
;
1373 m_gi
->m_rectAll
.height
= lh
;
1375 if (item
->HasImage())
1378 m_owner
->GetImageSize( item
->GetImage(), w
, h
);
1379 m_gi
->m_rectIcon
.width
= w
;
1380 m_gi
->m_rectIcon
.height
= h
;
1382 m_gi
->m_rectAll
.width
+= 4 + w
;
1383 if (h
> m_gi
->m_rectAll
.height
)
1384 m_gi
->m_rectAll
.height
= h
;
1387 m_gi
->m_rectHighlight
.width
= m_gi
->m_rectAll
.width
;
1388 m_gi
->m_rectHighlight
.height
= m_gi
->m_rectAll
.height
;
1393 wxFAIL_MSG( _T("unexpected call to SetSize") );
1397 wxFAIL_MSG( _T("unknown mode") );
1401 void wxListLineData::SetPosition( int x
, int y
,
1405 wxListItemDataList::Node
*node
= m_items
.GetFirst();
1406 wxCHECK_RET( node
, _T("no subitems at all??") );
1408 wxListItemData
*item
= node
->GetData();
1410 switch ( GetMode() )
1413 case wxLC_SMALL_ICON
:
1414 m_gi
->m_rectAll
.x
= x
;
1415 m_gi
->m_rectAll
.y
= y
;
1417 if ( item
->HasImage() )
1419 m_gi
->m_rectIcon
.x
= m_gi
->m_rectAll
.x
+ 4
1420 + (spacing
- m_gi
->m_rectIcon
.width
)/2;
1421 m_gi
->m_rectIcon
.y
= m_gi
->m_rectAll
.y
+ 4;
1424 if ( item
->HasText() )
1426 if (m_gi
->m_rectAll
.width
> spacing
)
1427 m_gi
->m_rectLabel
.x
= m_gi
->m_rectAll
.x
+ 2;
1429 m_gi
->m_rectLabel
.x
= m_gi
->m_rectAll
.x
+ 2 + (spacing
/2) - (m_gi
->m_rectLabel
.width
/2);
1430 m_gi
->m_rectLabel
.y
= m_gi
->m_rectAll
.y
+ m_gi
->m_rectAll
.height
+ 2 - m_gi
->m_rectLabel
.height
;
1431 m_gi
->m_rectHighlight
.x
= m_gi
->m_rectLabel
.x
- 2;
1432 m_gi
->m_rectHighlight
.y
= m_gi
->m_rectLabel
.y
- 2;
1434 else // no text, highlight the icon
1436 m_gi
->m_rectHighlight
.x
= m_gi
->m_rectIcon
.x
- 4;
1437 m_gi
->m_rectHighlight
.y
= m_gi
->m_rectIcon
.y
- 4;
1442 m_gi
->m_rectAll
.x
= x
;
1443 m_gi
->m_rectAll
.y
= y
;
1445 m_gi
->m_rectHighlight
.x
= m_gi
->m_rectAll
.x
;
1446 m_gi
->m_rectHighlight
.y
= m_gi
->m_rectAll
.y
;
1447 m_gi
->m_rectLabel
.y
= m_gi
->m_rectAll
.y
+ 2;
1449 if (item
->HasImage())
1451 m_gi
->m_rectIcon
.x
= m_gi
->m_rectAll
.x
+ 2;
1452 m_gi
->m_rectIcon
.y
= m_gi
->m_rectAll
.y
+ 2;
1453 m_gi
->m_rectLabel
.x
= m_gi
->m_rectAll
.x
+ 6 + m_gi
->m_rectIcon
.width
;
1457 m_gi
->m_rectLabel
.x
= m_gi
->m_rectAll
.x
+ 2;
1462 wxFAIL_MSG( _T("unexpected call to SetPosition") );
1466 wxFAIL_MSG( _T("unknown mode") );
1470 void wxListLineData::InitItems( int num
)
1472 for (int i
= 0; i
< num
; i
++)
1473 m_items
.Append( new wxListItemData(m_owner
) );
1476 void wxListLineData::SetItem( int index
, const wxListItem
&info
)
1478 wxListItemDataList::Node
*node
= m_items
.Item( index
);
1479 wxCHECK_RET( node
, _T("invalid column index in SetItem") );
1481 wxListItemData
*item
= node
->GetData();
1482 item
->SetItem( info
);
1485 void wxListLineData::GetItem( int index
, wxListItem
&info
)
1487 wxListItemDataList::Node
*node
= m_items
.Item( index
);
1490 wxListItemData
*item
= node
->GetData();
1491 item
->GetItem( info
);
1495 wxString
wxListLineData::GetText(int index
) const
1499 wxListItemDataList::Node
*node
= m_items
.Item( index
);
1502 wxListItemData
*item
= node
->GetData();
1503 s
= item
->GetText();
1509 void wxListLineData::SetText( int index
, const wxString s
)
1511 wxListItemDataList::Node
*node
= m_items
.Item( index
);
1514 wxListItemData
*item
= node
->GetData();
1519 void wxListLineData::SetImage( int index
, int image
)
1521 wxListItemDataList::Node
*node
= m_items
.Item( index
);
1522 wxCHECK_RET( node
, _T("invalid column index in SetImage()") );
1524 wxListItemData
*item
= node
->GetData();
1525 item
->SetImage(image
);
1528 int wxListLineData::GetImage( int index
) const
1530 wxListItemDataList::Node
*node
= m_items
.Item( index
);
1531 wxCHECK_MSG( node
, -1, _T("invalid column index in GetImage()") );
1533 wxListItemData
*item
= node
->GetData();
1534 return item
->GetImage();
1537 wxListItemAttr
*wxListLineData::GetAttr() const
1539 wxListItemDataList::Node
*node
= m_items
.GetFirst();
1540 wxCHECK_MSG( node
, NULL
, _T("invalid column index in GetAttr()") );
1542 wxListItemData
*item
= node
->GetData();
1543 return item
->GetAttr();
1546 void wxListLineData::SetAttr(wxListItemAttr
*attr
)
1548 wxListItemDataList::Node
*node
= m_items
.GetFirst();
1549 wxCHECK_RET( node
, _T("invalid column index in SetAttr()") );
1551 wxListItemData
*item
= node
->GetData();
1552 item
->SetAttr(attr
);
1555 bool wxListLineData::SetAttributes(wxDC
*dc
,
1556 const wxListItemAttr
*attr
,
1559 wxWindow
*listctrl
= m_owner
->GetParent();
1563 // don't use foreground colour for drawing highlighted items - this might
1564 // make them completely invisible (and there is no way to do bit
1565 // arithmetics on wxColour, unfortunately)
1569 colText
= wxSystemSettings::GetSystemColour(wxSYS_COLOUR_HIGHLIGHTTEXT
);
1573 if ( attr
&& attr
->HasTextColour() )
1575 colText
= attr
->GetTextColour();
1579 colText
= listctrl
->GetForegroundColour();
1583 dc
->SetTextForeground(colText
);
1587 if ( attr
&& attr
->HasFont() )
1589 font
= attr
->GetFont();
1593 font
= listctrl
->GetFont();
1599 bool hasBgCol
= attr
&& attr
->HasBackgroundColour();
1600 if ( highlighted
|| hasBgCol
)
1604 dc
->SetBrush( *m_owner
->GetHighlightBrush() );
1608 dc
->SetBrush(wxBrush(attr
->GetBackgroundColour(), wxSOLID
));
1611 dc
->SetPen( *wxTRANSPARENT_PEN
);
1619 void wxListLineData::Draw( wxDC
*dc
)
1621 wxListItemDataList::Node
*node
= m_items
.GetFirst();
1622 wxCHECK_RET( node
, _T("no subitems at all??") );
1624 bool highlighted
= IsHighlighted();
1626 wxListItemAttr
*attr
= GetAttr();
1628 if ( SetAttributes(dc
, attr
, highlighted
) )
1630 dc
->DrawRectangle( m_gi
->m_rectHighlight
);
1633 wxListItemData
*item
= node
->GetData();
1634 if (item
->HasImage())
1636 wxRect rectIcon
= m_gi
->m_rectIcon
;
1637 m_owner
->DrawImage( item
->GetImage(), dc
,
1638 rectIcon
.x
, rectIcon
.y
);
1641 if (item
->HasText())
1643 wxRect rectLabel
= m_gi
->m_rectLabel
;
1645 wxDCClipper
clipper(*dc
, rectLabel
);
1646 dc
->DrawText( item
->GetText(), rectLabel
.x
, rectLabel
.y
);
1650 void wxListLineData::DrawInReportMode( wxDC
*dc
,
1652 const wxRect
& rectHL
,
1655 // TODO: later we should support setting different attributes for
1656 // different columns - to do it, just add "col" argument to
1657 // GetAttr() and move these lines into the loop below
1658 wxListItemAttr
*attr
= GetAttr();
1659 if ( SetAttributes(dc
, attr
, highlighted
) )
1661 dc
->DrawRectangle( rectHL
);
1664 wxListItemDataList::Node
*node
= m_items
.GetFirst();
1665 wxCHECK_RET( node
, _T("no subitems at all??") );
1668 wxCoord x
= rect
.x
+ HEADER_OFFSET_X
,
1669 y
= rect
.y
+ (LINE_SPACING
+ EXTRA_HEIGHT
) / 2;
1673 wxListItemData
*item
= node
->GetData();
1675 int width
= m_owner
->GetColumnWidth(col
++);
1679 if ( item
->HasImage() )
1682 m_owner
->DrawImage( item
->GetImage(), dc
, xOld
, y
);
1683 m_owner
->GetImageSize( item
->GetImage(), ix
, iy
);
1685 ix
+= IMAGE_MARGIN_IN_REPORT_MODE
;
1691 wxDCClipper
clipper(*dc
, xOld
, y
, width
, rect
.height
);
1693 if ( item
->HasText() )
1695 dc
->DrawText( item
->GetText(), xOld
, y
);
1698 node
= node
->GetNext();
1702 bool wxListLineData::Highlight( bool on
)
1704 wxCHECK_MSG( !m_owner
->IsVirtual(), FALSE
, _T("unexpected call to Highlight") );
1706 if ( on
== m_highlighted
)
1714 void wxListLineData::ReverseHighlight( void )
1716 Highlight(!IsHighlighted());
1719 //-----------------------------------------------------------------------------
1720 // wxListHeaderWindow
1721 //-----------------------------------------------------------------------------
1723 IMPLEMENT_DYNAMIC_CLASS(wxListHeaderWindow
,wxWindow
);
1725 BEGIN_EVENT_TABLE(wxListHeaderWindow
,wxWindow
)
1726 EVT_PAINT (wxListHeaderWindow::OnPaint
)
1727 EVT_MOUSE_EVENTS (wxListHeaderWindow::OnMouse
)
1728 EVT_SET_FOCUS (wxListHeaderWindow::OnSetFocus
)
1731 wxListHeaderWindow::wxListHeaderWindow( void )
1733 m_owner
= (wxListMainWindow
*) NULL
;
1734 m_currentCursor
= (wxCursor
*) NULL
;
1735 m_resizeCursor
= (wxCursor
*) NULL
;
1736 m_isDragging
= FALSE
;
1739 wxListHeaderWindow::wxListHeaderWindow( wxWindow
*win
, wxWindowID id
, wxListMainWindow
*owner
,
1740 const wxPoint
&pos
, const wxSize
&size
,
1741 long style
, const wxString
&name
) :
1742 wxWindow( win
, id
, pos
, size
, style
, name
)
1745 // m_currentCursor = wxSTANDARD_CURSOR;
1746 m_currentCursor
= (wxCursor
*) NULL
;
1747 m_resizeCursor
= new wxCursor( wxCURSOR_SIZEWE
);
1748 m_isDragging
= FALSE
;
1751 SetBackgroundColour( wxSystemSettings::GetSystemColour( wxSYS_COLOUR_BTNFACE
) );
1754 wxListHeaderWindow::~wxListHeaderWindow( void )
1756 delete m_resizeCursor
;
1759 void wxListHeaderWindow::DoDrawRect( wxDC
*dc
, int x
, int y
, int w
, int h
)
1762 GtkStateType state
= m_parent
->IsEnabled() ? GTK_STATE_NORMAL
1763 : GTK_STATE_INSENSITIVE
;
1765 x
= dc
->XLOG2DEV( x
);
1767 gtk_paint_box (m_wxwindow
->style
, GTK_PIZZA(m_wxwindow
)->bin_window
,
1768 state
, GTK_SHADOW_OUT
,
1769 (GdkRectangle
*) NULL
, m_wxwindow
, "button",
1770 x
-1, y
-1, w
+2, h
+2);
1771 #elif defined( __WXMAC__ )
1772 const int m_corner
= 1;
1774 dc
->SetBrush( *wxTRANSPARENT_BRUSH
);
1776 dc
->SetPen( wxPen( wxSystemSettings::GetSystemColour( wxSYS_COLOUR_BTNSHADOW
) , 1 , wxSOLID
) );
1777 dc
->DrawLine( x
+w
-m_corner
+1, y
, x
+w
, y
+h
); // right (outer)
1778 dc
->DrawRectangle( x
, y
+h
, w
+1, 1 ); // bottom (outer)
1780 wxPen
pen( wxColour( 0x88 , 0x88 , 0x88 ), 1, wxSOLID
);
1783 dc
->DrawLine( x
+w
-m_corner
, y
, x
+w
-1, y
+h
); // right (inner)
1784 dc
->DrawRectangle( x
+1, y
+h
-1, w
-2, 1 ); // bottom (inner)
1786 dc
->SetPen( *wxWHITE_PEN
);
1787 dc
->DrawRectangle( x
, y
, w
-m_corner
+1, 1 ); // top (outer)
1788 dc
->DrawRectangle( x
, y
, 1, h
); // left (outer)
1789 dc
->DrawLine( x
, y
+h
-1, x
+1, y
+h
-1 );
1790 dc
->DrawLine( x
+w
-1, y
, x
+w
-1, y
+1 );
1792 const int m_corner
= 1;
1794 dc
->SetBrush( *wxTRANSPARENT_BRUSH
);
1796 dc
->SetPen( *wxBLACK_PEN
);
1797 dc
->DrawLine( x
+w
-m_corner
+1, y
, x
+w
, y
+h
); // right (outer)
1798 dc
->DrawRectangle( x
, y
+h
, w
+1, 1 ); // bottom (outer)
1800 wxPen
pen( wxSystemSettings::GetSystemColour( wxSYS_COLOUR_BTNSHADOW
), 1, wxSOLID
);
1803 dc
->DrawLine( x
+w
-m_corner
, y
, x
+w
-1, y
+h
); // right (inner)
1804 dc
->DrawRectangle( x
+1, y
+h
-1, w
-2, 1 ); // bottom (inner)
1806 dc
->SetPen( *wxWHITE_PEN
);
1807 dc
->DrawRectangle( x
, y
, w
-m_corner
+1, 1 ); // top (outer)
1808 dc
->DrawRectangle( x
, y
, 1, h
); // left (outer)
1809 dc
->DrawLine( x
, y
+h
-1, x
+1, y
+h
-1 );
1810 dc
->DrawLine( x
+w
-1, y
, x
+w
-1, y
+1 );
1814 // shift the DC origin to match the position of the main window horz
1815 // scrollbar: this allows us to always use logical coords
1816 void wxListHeaderWindow::AdjustDC(wxDC
& dc
)
1819 m_owner
->GetScrollPixelsPerUnit( &xpix
, NULL
);
1822 m_owner
->GetViewStart( &x
, NULL
);
1824 // account for the horz scrollbar offset
1825 dc
.SetDeviceOrigin( -x
* xpix
, 0 );
1828 void wxListHeaderWindow::OnPaint( wxPaintEvent
&WXUNUSED(event
) )
1831 wxClientDC
dc( this );
1833 wxPaintDC
dc( this );
1841 dc
.SetFont( GetFont() );
1843 // width and height of the entire header window
1845 GetClientSize( &w
, &h
);
1846 m_owner
->CalcUnscrolledPosition(w
, 0, &w
, NULL
);
1848 dc
.SetBackgroundMode(wxTRANSPARENT
);
1850 // do *not* use the listctrl colour for headers - one day we will have a
1851 // function to set it separately
1852 //dc.SetTextForeground( *wxBLACK );
1853 dc
.SetTextForeground(wxSystemSettings::
1854 GetSystemColour( wxSYS_COLOUR_WINDOWTEXT
));
1856 int x
= HEADER_OFFSET_X
;
1858 int numColumns
= m_owner
->GetColumnCount();
1860 for (int i
= 0; i
< numColumns
; i
++)
1862 m_owner
->GetColumn( i
, item
);
1863 int wCol
= item
.m_width
;
1864 int cw
= wCol
- 2; // the width of the rect to draw
1866 int xEnd
= x
+ wCol
;
1868 dc
.SetPen( *wxWHITE_PEN
);
1870 DoDrawRect( &dc
, x
, HEADER_OFFSET_Y
, cw
, h
-2 );
1871 wxDCClipper
clipper(dc
, x
, HEADER_OFFSET_Y
, cw
-5, h
-4 );
1873 dc
.DrawText( item
.GetText(),
1874 x
+ EXTRA_WIDTH
, HEADER_OFFSET_Y
+ EXTRA_HEIGHT
);
1884 void wxListHeaderWindow::DrawCurrent()
1886 int x1
= m_currentX
;
1888 ClientToScreen( &x1
, &y1
);
1890 int x2
= m_currentX
-1;
1892 m_owner
->GetClientSize( NULL
, &y2
);
1893 m_owner
->ClientToScreen( &x2
, &y2
);
1896 dc
.SetLogicalFunction( wxINVERT
);
1897 dc
.SetPen( wxPen( *wxBLACK
, 2, wxSOLID
) );
1898 dc
.SetBrush( *wxTRANSPARENT_BRUSH
);
1902 dc
.DrawLine( x1
, y1
, x2
, y2
);
1904 dc
.SetLogicalFunction( wxCOPY
);
1906 dc
.SetPen( wxNullPen
);
1907 dc
.SetBrush( wxNullBrush
);
1910 void wxListHeaderWindow::OnMouse( wxMouseEvent
&event
)
1912 // we want to work with logical coords
1914 m_owner
->CalcUnscrolledPosition(event
.GetX(), 0, &x
, NULL
);
1915 int y
= event
.GetY();
1919 // we don't draw the line beyond our window, but we allow dragging it
1922 GetClientSize( &w
, NULL
);
1923 m_owner
->CalcUnscrolledPosition(w
, 0, &w
, NULL
);
1926 // erase the line if it was drawn
1927 if ( m_currentX
< w
)
1930 if (event
.ButtonUp())
1933 m_isDragging
= FALSE
;
1935 m_owner
->SetColumnWidth( m_column
, m_currentX
- m_minX
);
1942 m_currentX
= m_minX
+ 7;
1944 // draw in the new location
1945 if ( m_currentX
< w
)
1949 else // not dragging
1952 bool hit_border
= FALSE
;
1954 // end of the current column
1957 // find the column where this event occured
1958 int countCol
= m_owner
->GetColumnCount();
1959 for (int col
= 0; col
< countCol
; col
++)
1961 xpos
+= m_owner
->GetColumnWidth( col
);
1964 if ( (abs(x
-xpos
) < 3) && (y
< 22) )
1966 // near the column border
1973 // inside the column
1980 if (event
.LeftDown() || event
.RightUp())
1982 if (hit_border
&& event
.LeftDown())
1984 m_isDragging
= TRUE
;
1989 else // click on a column
1991 wxWindow
*parent
= GetParent();
1992 wxListEvent
le( event
.LeftDown()
1993 ? wxEVT_COMMAND_LIST_COL_CLICK
1994 : wxEVT_COMMAND_LIST_COL_RIGHT_CLICK
,
1996 le
.SetEventObject( parent
);
1997 le
.m_col
= m_column
;
1998 parent
->GetEventHandler()->ProcessEvent( le
);
2001 else if (event
.Moving())
2006 setCursor
= m_currentCursor
== wxSTANDARD_CURSOR
;
2007 m_currentCursor
= m_resizeCursor
;
2011 setCursor
= m_currentCursor
!= wxSTANDARD_CURSOR
;
2012 m_currentCursor
= wxSTANDARD_CURSOR
;
2016 SetCursor(*m_currentCursor
);
2021 void wxListHeaderWindow::OnSetFocus( wxFocusEvent
&WXUNUSED(event
) )
2023 m_owner
->SetFocus();
2026 //-----------------------------------------------------------------------------
2027 // wxListRenameTimer (internal)
2028 //-----------------------------------------------------------------------------
2030 wxListRenameTimer::wxListRenameTimer( wxListMainWindow
*owner
)
2035 void wxListRenameTimer::Notify()
2037 m_owner
->OnRenameTimer();
2040 //-----------------------------------------------------------------------------
2041 // wxListTextCtrl (internal)
2042 //-----------------------------------------------------------------------------
2044 IMPLEMENT_DYNAMIC_CLASS(wxListTextCtrl
,wxTextCtrl
);
2046 BEGIN_EVENT_TABLE(wxListTextCtrl
,wxTextCtrl
)
2047 EVT_CHAR (wxListTextCtrl::OnChar
)
2048 EVT_KEY_UP (wxListTextCtrl::OnKeyUp
)
2049 EVT_KILL_FOCUS (wxListTextCtrl::OnKillFocus
)
2052 wxListTextCtrl::wxListTextCtrl( wxWindow
*parent
,
2053 const wxWindowID id
,
2056 wxListMainWindow
*owner
,
2057 const wxString
&value
,
2061 const wxValidator
& validator
,
2062 const wxString
&name
)
2063 : wxTextCtrl( parent
, id
, value
, pos
, size
, style
, validator
, name
)
2068 (*m_accept
) = FALSE
;
2070 m_startValue
= value
;
2073 void wxListTextCtrl::OnChar( wxKeyEvent
&event
)
2075 if (event
.m_keyCode
== WXK_RETURN
)
2078 (*m_res
) = GetValue();
2080 if (!wxPendingDelete
.Member(this))
2081 wxPendingDelete
.Append(this);
2083 if ((*m_accept
) && ((*m_res
) != m_startValue
))
2084 m_owner
->OnRenameAccept();
2088 if (event
.m_keyCode
== WXK_ESCAPE
)
2090 (*m_accept
) = FALSE
;
2093 if (!wxPendingDelete
.Member(this))
2094 wxPendingDelete
.Append(this);
2102 void wxListTextCtrl::OnKeyUp( wxKeyEvent
&event
)
2104 // auto-grow the textctrl:
2105 wxSize parentSize
= m_owner
->GetSize();
2106 wxPoint myPos
= GetPosition();
2107 wxSize mySize
= GetSize();
2109 GetTextExtent(GetValue() + _T("MM"), &sx
, &sy
); // FIXME: MM??
2110 if (myPos
.x
+ sx
> parentSize
.x
)
2111 sx
= parentSize
.x
- myPos
.x
;
2119 void wxListTextCtrl::OnKillFocus( wxFocusEvent
&WXUNUSED(event
) )
2121 if (!wxPendingDelete
.Member(this))
2122 wxPendingDelete
.Append(this);
2124 if ((*m_accept
) && ((*m_res
) != m_startValue
))
2125 m_owner
->OnRenameAccept();
2128 //-----------------------------------------------------------------------------
2130 //-----------------------------------------------------------------------------
2132 IMPLEMENT_DYNAMIC_CLASS(wxListMainWindow
,wxScrolledWindow
);
2134 BEGIN_EVENT_TABLE(wxListMainWindow
,wxScrolledWindow
)
2135 EVT_PAINT (wxListMainWindow::OnPaint
)
2136 EVT_MOUSE_EVENTS (wxListMainWindow::OnMouse
)
2137 EVT_CHAR (wxListMainWindow::OnChar
)
2138 EVT_KEY_DOWN (wxListMainWindow::OnKeyDown
)
2139 EVT_SET_FOCUS (wxListMainWindow::OnSetFocus
)
2140 EVT_KILL_FOCUS (wxListMainWindow::OnKillFocus
)
2141 EVT_SCROLLWIN (wxListMainWindow::OnScroll
)
2144 void wxListMainWindow::Init()
2146 m_columns
.DeleteContents( TRUE
);
2150 m_lineTo
= (size_t)-1;
2156 m_small_image_list
= (wxImageList
*) NULL
;
2157 m_normal_image_list
= (wxImageList
*) NULL
;
2159 m_small_spacing
= 30;
2160 m_normal_spacing
= 40;
2164 m_isCreated
= FALSE
;
2166 m_lastOnSame
= FALSE
;
2167 m_renameTimer
= new wxListRenameTimer( this );
2168 m_renameAccept
= FALSE
;
2173 m_lineBeforeLastClicked
= (size_t)-1;
2176 void wxListMainWindow::InitScrolling()
2178 if ( HasFlag(wxLC_REPORT
) )
2180 m_xScroll
= SCROLL_UNIT_X
;
2181 m_yScroll
= SCROLL_UNIT_Y
;
2185 m_xScroll
= SCROLL_UNIT_Y
;
2190 wxListMainWindow::wxListMainWindow()
2195 m_highlightUnfocusedBrush
= (wxBrush
*) NULL
;
2201 wxListMainWindow::wxListMainWindow( wxWindow
*parent
,
2206 const wxString
&name
)
2207 : wxScrolledWindow( parent
, id
, pos
, size
,
2208 style
| wxHSCROLL
| wxVSCROLL
, name
)
2212 m_highlightBrush
= new wxBrush
2214 wxSystemSettings::GetSystemColour
2216 wxSYS_COLOUR_HIGHLIGHT
2221 m_highlightUnfocusedBrush
= new wxBrush
2223 wxSystemSettings::GetSystemColour
2225 wxSYS_COLOUR_BTNSHADOW
2234 SetScrollbars( m_xScroll
, m_yScroll
, 0, 0, 0, 0 );
2236 SetBackgroundColour( wxSystemSettings::GetSystemColour( wxSYS_COLOUR_LISTBOX
) );
2239 wxListMainWindow::~wxListMainWindow()
2243 delete m_highlightBrush
;
2244 delete m_highlightUnfocusedBrush
;
2246 delete m_renameTimer
;
2249 void wxListMainWindow::CacheLineData(size_t line
)
2251 wxListCtrl
*listctrl
= GetListCtrl();
2253 wxListLineData
*ld
= GetDummyLine();
2255 size_t countCol
= GetColumnCount();
2256 for ( size_t col
= 0; col
< countCol
; col
++ )
2258 ld
->SetText(col
, listctrl
->OnGetItemText(line
, col
));
2261 ld
->SetImage(listctrl
->OnGetItemImage(line
));
2262 ld
->SetAttr(listctrl
->OnGetItemAttr(line
));
2265 wxListLineData
*wxListMainWindow::GetDummyLine() const
2267 wxASSERT_MSG( !IsEmpty(), _T("invalid line index") );
2269 if ( m_lines
.IsEmpty() )
2271 // normal controls are supposed to have something in m_lines
2272 // already if it's not empty
2273 wxASSERT_MSG( IsVirtual(), _T("logic error") );
2275 wxListMainWindow
*self
= wxConstCast(this, wxListMainWindow
);
2276 wxListLineData
*line
= new wxListLineData(self
);
2277 self
->m_lines
.Add(line
);
2283 // ----------------------------------------------------------------------------
2284 // line geometry (report mode only)
2285 // ----------------------------------------------------------------------------
2287 wxCoord
wxListMainWindow::GetLineHeight() const
2289 wxASSERT_MSG( HasFlag(wxLC_REPORT
), _T("only works in report mode") );
2291 // we cache the line height as calling GetTextExtent() is slow
2292 if ( !m_lineHeight
)
2294 wxListMainWindow
*self
= wxConstCast(this, wxListMainWindow
);
2296 wxClientDC
dc( self
);
2297 dc
.SetFont( GetFont() );
2300 dc
.GetTextExtent(_T("H"), NULL
, &y
);
2302 if ( y
< SCROLL_UNIT_Y
)
2306 self
->m_lineHeight
= y
+ LINE_SPACING
;
2309 return m_lineHeight
;
2312 wxCoord
wxListMainWindow::GetLineY(size_t line
) const
2314 wxASSERT_MSG( HasFlag(wxLC_REPORT
), _T("only works in report mode") );
2316 return LINE_SPACING
+ line
*GetLineHeight();
2319 wxRect
wxListMainWindow::GetLineRect(size_t line
) const
2321 if ( !InReportView() )
2322 return GetLine(line
)->m_gi
->m_rectAll
;
2325 rect
.x
= HEADER_OFFSET_X
;
2326 rect
.y
= GetLineY(line
);
2327 rect
.width
= GetHeaderWidth();
2328 rect
.height
= GetLineHeight();
2333 wxRect
wxListMainWindow::GetLineLabelRect(size_t line
) const
2335 if ( !InReportView() )
2336 return GetLine(line
)->m_gi
->m_rectLabel
;
2339 rect
.x
= HEADER_OFFSET_X
;
2340 rect
.y
= GetLineY(line
);
2341 rect
.width
= GetColumnWidth(0);
2342 rect
.height
= GetLineHeight();
2347 wxRect
wxListMainWindow::GetLineIconRect(size_t line
) const
2349 if ( !InReportView() )
2350 return GetLine(line
)->m_gi
->m_rectIcon
;
2352 wxListLineData
*ld
= GetLine(line
);
2353 wxASSERT_MSG( ld
->HasImage(), _T("should have an image") );
2356 rect
.x
= HEADER_OFFSET_X
;
2357 rect
.y
= GetLineY(line
);
2358 GetImageSize(ld
->GetImage(), rect
.width
, rect
.height
);
2363 wxRect
wxListMainWindow::GetLineHighlightRect(size_t line
) const
2365 return InReportView() ? GetLineRect(line
)
2366 : GetLine(line
)->m_gi
->m_rectHighlight
;
2369 long wxListMainWindow::HitTestLine(size_t line
, int x
, int y
) const
2371 wxASSERT_MSG( line
< GetItemCount(), _T("invalid line in HitTestLine") );
2373 wxListLineData
*ld
= GetLine(line
);
2375 if ( ld
->HasImage() && GetLineIconRect(line
).Inside(x
, y
) )
2376 return wxLIST_HITTEST_ONITEMICON
;
2378 if ( ld
->HasText() )
2380 wxRect rect
= InReportView() ? GetLineRect(line
)
2381 : GetLineLabelRect(line
);
2383 if ( rect
.Inside(x
, y
) )
2384 return wxLIST_HITTEST_ONITEMLABEL
;
2390 // ----------------------------------------------------------------------------
2391 // highlight (selection) handling
2392 // ----------------------------------------------------------------------------
2394 bool wxListMainWindow::IsHighlighted(size_t line
) const
2398 return m_selStore
.IsSelected(line
);
2402 wxListLineData
*ld
= GetLine(line
);
2403 wxCHECK_MSG( ld
, FALSE
, _T("invalid index in IsHighlighted") );
2405 return ld
->IsHighlighted();
2409 void wxListMainWindow::HighlightLines( size_t lineFrom
,
2415 wxArrayInt linesChanged
;
2416 if ( !m_selStore
.SelectRange(lineFrom
, lineTo
, highlight
,
2419 // meny items changed state, refresh everything
2420 RefreshLines(lineFrom
, lineTo
);
2422 else // only a few items changed state, refresh only them
2424 size_t count
= linesChanged
.GetCount();
2425 for ( size_t n
= 0; n
< count
; n
++ )
2427 RefreshLine(linesChanged
[n
]);
2431 else // iterate over all items in non report view
2433 for ( size_t line
= lineFrom
; line
<= lineTo
; line
++ )
2435 if ( HighlightLine(line
, highlight
) )
2443 bool wxListMainWindow::HighlightLine( size_t line
, bool highlight
)
2449 changed
= m_selStore
.SelectItem(line
, highlight
);
2453 wxListLineData
*ld
= GetLine(line
);
2454 wxCHECK_MSG( ld
, FALSE
, _T("invalid index in HighlightLine") );
2456 changed
= ld
->Highlight(highlight
);
2461 SendNotify( line
, highlight
? wxEVT_COMMAND_LIST_ITEM_SELECTED
2462 : wxEVT_COMMAND_LIST_ITEM_DESELECTED
);
2468 void wxListMainWindow::RefreshLine( size_t line
)
2470 if ( HasFlag(wxLC_REPORT
) )
2472 size_t visibleFrom
, visibleTo
;
2473 GetVisibleLinesRange(&visibleFrom
, &visibleTo
);
2475 if ( line
< visibleFrom
|| line
> visibleTo
)
2479 wxRect rect
= GetLineRect(line
);
2481 CalcScrolledPosition( rect
.x
, rect
.y
, &rect
.x
, &rect
.y
);
2482 RefreshRect( rect
);
2485 void wxListMainWindow::RefreshLines( size_t lineFrom
, size_t lineTo
)
2487 // we suppose that they are ordered by caller
2488 wxASSERT_MSG( lineFrom
<= lineTo
, _T("indices in disorder") );
2490 wxASSERT_MSG( lineTo
< GetItemCount(), _T("invalid line range") );
2492 if ( HasFlag(wxLC_REPORT
) )
2494 size_t visibleFrom
, visibleTo
;
2495 GetVisibleLinesRange(&visibleFrom
, &visibleTo
);
2497 if ( lineFrom
< visibleFrom
)
2498 lineFrom
= visibleFrom
;
2499 if ( lineTo
> visibleTo
)
2504 rect
.y
= GetLineY(lineFrom
);
2505 rect
.width
= GetClientSize().x
;
2506 rect
.height
= GetLineY(lineTo
) - rect
.y
+ GetLineHeight();
2508 CalcScrolledPosition( rect
.x
, rect
.y
, &rect
.x
, &rect
.y
);
2509 RefreshRect( rect
);
2513 // TODO: this should be optimized...
2514 for ( size_t line
= lineFrom
; line
<= lineTo
; line
++ )
2521 void wxListMainWindow::RefreshAfter( size_t lineFrom
)
2523 if ( HasFlag(wxLC_REPORT
) )
2526 GetVisibleLinesRange(&visibleFrom
, NULL
);
2528 if ( lineFrom
< visibleFrom
)
2529 lineFrom
= visibleFrom
;
2533 rect
.y
= GetLineY(lineFrom
);
2535 wxSize size
= GetClientSize();
2536 rect
.width
= size
.x
;
2537 // refresh till the bottom of the window
2538 rect
.height
= size
.y
- rect
.y
;
2540 CalcScrolledPosition( rect
.x
, rect
.y
, &rect
.x
, &rect
.y
);
2541 RefreshRect( rect
);
2545 // TODO: how to do it more efficiently?
2550 void wxListMainWindow::RefreshSelected()
2556 if ( InReportView() )
2558 GetVisibleLinesRange(&from
, &to
);
2563 to
= GetItemCount() - 1;
2566 if ( HasCurrent() && m_current
>= from
&& m_current
<= to
)
2568 RefreshLine(m_current
);
2571 for ( size_t line
= from
; line
<= to
; line
++ )
2573 // NB: the test works as expected even if m_current == -1
2574 if ( line
!= m_current
&& IsHighlighted(line
) )
2581 void wxListMainWindow::OnPaint( wxPaintEvent
&WXUNUSED(event
) )
2583 // Note: a wxPaintDC must be constructed even if no drawing is
2584 // done (a Windows requirement).
2585 wxPaintDC
dc( this );
2589 // empty control. nothing to draw
2595 // delay the repainting until we calculate all the items positions
2602 CalcScrolledPosition( 0, 0, &dev_x
, &dev_y
);
2606 dc
.SetFont( GetFont() );
2608 if ( HasFlag(wxLC_REPORT
) )
2610 int lineHeight
= GetLineHeight();
2612 size_t visibleFrom
, visibleTo
;
2613 GetVisibleLinesRange(&visibleFrom
, &visibleTo
);
2616 wxCoord xOrig
, yOrig
;
2617 CalcUnscrolledPosition(0, 0, &xOrig
, &yOrig
);
2619 // tell the caller cache to cache the data
2622 wxListEvent
evCache(wxEVT_COMMAND_LIST_CACHE_HINT
,
2623 GetParent()->GetId());
2624 evCache
.SetEventObject( GetParent() );
2625 evCache
.m_oldItemIndex
= visibleFrom
;
2626 evCache
.m_itemIndex
= visibleTo
;
2627 GetParent()->GetEventHandler()->ProcessEvent( evCache
);
2630 for ( size_t line
= visibleFrom
; line
<= visibleTo
; line
++ )
2632 rectLine
= GetLineRect(line
);
2634 if ( !IsExposed(rectLine
.x
- xOrig
, rectLine
.y
- yOrig
,
2635 rectLine
.width
, rectLine
.height
) )
2637 // don't redraw unaffected lines to avoid flicker
2641 GetLine(line
)->DrawInReportMode( &dc
,
2643 GetLineHighlightRect(line
),
2644 IsHighlighted(line
) );
2647 if ( HasFlag(wxLC_HRULES
) )
2649 wxPen
pen(GetRuleColour(), 1, wxSOLID
);
2650 wxSize clientSize
= GetClientSize();
2652 for ( size_t i
= visibleFrom
; i
<= visibleTo
; i
++ )
2655 dc
.SetBrush( *wxTRANSPARENT_BRUSH
);
2656 dc
.DrawLine(0 - dev_x
, i
*lineHeight
,
2657 clientSize
.x
- dev_x
, i
*lineHeight
);
2660 // Draw last horizontal rule
2661 if ( visibleTo
> visibleFrom
)
2664 dc
.SetBrush( *wxTRANSPARENT_BRUSH
);
2665 dc
.DrawLine(0 - dev_x
, m_lineTo
*lineHeight
,
2666 clientSize
.x
- dev_x
, m_lineTo
*lineHeight
);
2670 // Draw vertical rules if required
2671 if ( HasFlag(wxLC_VRULES
) && !IsEmpty() )
2673 wxPen
pen(GetRuleColour(), 1, wxSOLID
);
2676 wxRect firstItemRect
;
2677 wxRect lastItemRect
;
2678 GetItemRect(0, firstItemRect
);
2679 GetItemRect(GetItemCount() - 1, lastItemRect
);
2680 int x
= firstItemRect
.GetX();
2682 dc
.SetBrush(* wxTRANSPARENT_BRUSH
);
2683 for (col
= 0; col
< GetColumnCount(); col
++)
2685 int colWidth
= GetColumnWidth(col
);
2687 dc
.DrawLine(x
- dev_x
, firstItemRect
.GetY() - 1 - dev_y
,
2688 x
- dev_x
, lastItemRect
.GetBottom() + 1 - dev_y
);
2694 size_t count
= GetItemCount();
2695 for ( size_t i
= 0; i
< count
; i
++ )
2697 GetLine(i
)->Draw( &dc
);
2703 // don't draw rect outline under Max if we already have the background
2704 // color but under other platforms only draw it if we do: it is a bit
2705 // silly to draw "focus rect" if we don't have focus!
2710 #endif // __WXMAC__/!__WXMAC__
2712 dc
.SetPen( *wxBLACK_PEN
);
2713 dc
.SetBrush( *wxTRANSPARENT_BRUSH
);
2714 dc
.DrawRectangle( GetLineHighlightRect(m_current
) );
2721 void wxListMainWindow::HighlightAll( bool on
)
2723 if ( IsSingleSel() )
2725 wxASSERT_MSG( !on
, _T("can't do this in a single sel control") );
2727 // we just have one item to turn off
2728 if ( HasCurrent() && IsHighlighted(m_current
) )
2730 HighlightLine(m_current
, FALSE
);
2731 RefreshLine(m_current
);
2736 HighlightLines(0, GetItemCount() - 1, on
);
2740 void wxListMainWindow::SendNotify( size_t line
,
2741 wxEventType command
,
2744 wxListEvent
le( command
, GetParent()->GetId() );
2745 le
.SetEventObject( GetParent() );
2746 le
.m_itemIndex
= line
;
2748 // set only for events which have position
2749 if ( point
!= wxDefaultPosition
)
2750 le
.m_pointDrag
= point
;
2752 // don't try to get the line info for virtual list controls: the main
2753 // program has it anyhow and if we did it would result in accessing all
2754 // the lines, even those which are not visible now and this is precisely
2755 // what we're trying to avoid
2756 if ( !IsVirtual() && (command
!= wxEVT_COMMAND_LIST_DELETE_ITEM
) )
2758 GetLine(line
)->GetItem( 0, le
.m_item
);
2760 //else: there may be no more such item
2762 GetParent()->GetEventHandler()->ProcessEvent( le
);
2765 void wxListMainWindow::OnFocusLine( size_t WXUNUSED(line
) )
2767 // SendNotify( line, wxEVT_COMMAND_LIST_ITEM_FOCUSSED );
2770 void wxListMainWindow::OnUnfocusLine( size_t WXUNUSED(line
) )
2772 // SendNotify( line, wxEVT_COMMAND_LIST_ITEM_UNFOCUSSED );
2775 void wxListMainWindow::EditLabel( long item
)
2777 wxCHECK_RET( (item
>= 0) && ((size_t)item
< GetItemCount()),
2778 wxT("wrong index in wxListCtrl::EditLabel()") );
2780 m_currentEdit
= (size_t)item
;
2782 wxListEvent
le( wxEVT_COMMAND_LIST_BEGIN_LABEL_EDIT
, GetParent()->GetId() );
2783 le
.SetEventObject( GetParent() );
2784 le
.m_itemIndex
= item
;
2785 wxListLineData
*data
= GetLine(m_currentEdit
);
2786 wxCHECK_RET( data
, _T("invalid index in EditLabel()") );
2787 data
->GetItem( 0, le
.m_item
);
2788 GetParent()->GetEventHandler()->ProcessEvent( le
);
2790 if (!le
.IsAllowed())
2793 // We have to call this here because the label in question might just have
2794 // been added and no screen update taken place.
2798 wxClientDC
dc(this);
2801 wxString s
= data
->GetText(0);
2802 wxRect rectLabel
= GetLineLabelRect(m_currentEdit
);
2804 rectLabel
.x
= dc
.LogicalToDeviceX( rectLabel
.x
);
2805 rectLabel
.y
= dc
.LogicalToDeviceY( rectLabel
.y
);
2807 wxListTextCtrl
*text
= new wxListTextCtrl
2814 wxPoint(rectLabel
.x
-4,rectLabel
.y
-4),
2815 wxSize(rectLabel
.width
+11,rectLabel
.height
+8)
2820 void wxListMainWindow::OnRenameTimer()
2822 wxCHECK_RET( HasCurrent(), wxT("unexpected rename timer") );
2824 EditLabel( m_current
);
2827 void wxListMainWindow::OnRenameAccept()
2829 wxListEvent
le( wxEVT_COMMAND_LIST_END_LABEL_EDIT
, GetParent()->GetId() );
2830 le
.SetEventObject( GetParent() );
2831 le
.m_itemIndex
= m_currentEdit
;
2833 wxListLineData
*data
= GetLine(m_currentEdit
);
2834 wxCHECK_RET( data
, _T("invalid index in OnRenameAccept()") );
2836 data
->GetItem( 0, le
.m_item
);
2837 le
.m_item
.m_text
= m_renameRes
;
2838 GetParent()->GetEventHandler()->ProcessEvent( le
);
2840 if (!le
.IsAllowed()) return;
2843 info
.m_mask
= wxLIST_MASK_TEXT
;
2844 info
.m_itemId
= le
.m_itemIndex
;
2845 info
.m_text
= m_renameRes
;
2846 info
.SetTextColour(le
.m_item
.GetTextColour());
2850 void wxListMainWindow::OnMouse( wxMouseEvent
&event
)
2852 event
.SetEventObject( GetParent() );
2853 if ( GetParent()->GetEventHandler()->ProcessEvent( event
) )
2856 if ( !HasCurrent() || IsEmpty() )
2862 if ( !(event
.Dragging() || event
.ButtonDown() || event
.LeftUp() ||
2863 event
.ButtonDClick()) )
2866 int x
= event
.GetX();
2867 int y
= event
.GetY();
2868 CalcUnscrolledPosition( x
, y
, &x
, &y
);
2870 // where did we hit it (if we did)?
2873 size_t count
= GetItemCount(),
2876 if ( HasFlag(wxLC_REPORT
) )
2878 current
= y
/ GetLineHeight();
2879 if ( current
< count
)
2880 hitResult
= HitTestLine(current
, x
, y
);
2884 // TODO: optimize it too! this is less simple than for report view but
2885 // enumerating all items is still not a way to do it!!
2886 for ( current
= 0; current
< count
; current
++ )
2888 hitResult
= HitTestLine(current
, x
, y
);
2894 if (event
.Dragging())
2896 if (m_dragCount
== 0)
2898 // we have to report the raw, physical coords as we want to be
2899 // able to call HitTest(event.m_pointDrag) from the user code to
2900 // get the item being dragged
2901 m_dragStart
= event
.GetPosition();
2906 if (m_dragCount
!= 3)
2909 int command
= event
.RightIsDown() ? wxEVT_COMMAND_LIST_BEGIN_RDRAG
2910 : wxEVT_COMMAND_LIST_BEGIN_DRAG
;
2912 wxListEvent
le( command
, GetParent()->GetId() );
2913 le
.SetEventObject( GetParent() );
2914 le
.m_pointDrag
= m_dragStart
;
2915 GetParent()->GetEventHandler()->ProcessEvent( le
);
2926 // outside of any item
2930 bool forceClick
= FALSE
;
2931 if (event
.ButtonDClick())
2933 m_renameTimer
->Stop();
2934 m_lastOnSame
= FALSE
;
2936 if ( current
== m_lineBeforeLastClicked
)
2938 SendNotify( current
, wxEVT_COMMAND_LIST_ITEM_ACTIVATED
);
2944 // the first click was on another item, so don't interpret this as
2945 // a double click, but as a simple click instead
2950 if (event
.LeftUp() && m_lastOnSame
)
2952 if ((current
== m_current
) &&
2953 (hitResult
== wxLIST_HITTEST_ONITEMLABEL
) &&
2954 HasFlag(wxLC_EDIT_LABELS
) )
2956 m_renameTimer
->Start( 100, TRUE
);
2958 m_lastOnSame
= FALSE
;
2960 else if (event
.RightDown())
2962 SendNotify( current
, wxEVT_COMMAND_LIST_ITEM_RIGHT_CLICK
,
2963 event
.GetPosition() );
2965 else if (event
.MiddleDown())
2967 SendNotify( current
, wxEVT_COMMAND_LIST_ITEM_MIDDLE_CLICK
);
2969 else if ( event
.LeftDown() || forceClick
)
2971 m_lineBeforeLastClicked
= m_lineLastClicked
;
2972 m_lineLastClicked
= current
;
2974 size_t oldCurrent
= m_current
;
2976 if ( IsSingleSel() || !(event
.ControlDown() || event
.ShiftDown()) )
2978 HighlightAll( FALSE
);
2979 m_current
= current
;
2981 ReverseHighlight(m_current
);
2983 else // multi sel & either ctrl or shift is down
2985 if (event
.ControlDown())
2987 m_current
= current
;
2989 ReverseHighlight(m_current
);
2991 else if (event
.ShiftDown())
2993 m_current
= current
;
2995 size_t lineFrom
= oldCurrent
,
2998 if ( lineTo
< lineFrom
)
3001 lineFrom
= m_current
;
3004 HighlightLines(lineFrom
, lineTo
);
3006 else // !ctrl, !shift
3008 // test in the enclosing if should make it impossible
3009 wxFAIL_MSG( _T("how did we get here?") );
3013 if (m_current
!= oldCurrent
)
3015 RefreshLine( oldCurrent
);
3016 OnUnfocusLine( oldCurrent
);
3017 OnFocusLine( m_current
);
3020 // forceClick is only set if the previous click was on another item
3021 m_lastOnSame
= !forceClick
&& (m_current
== oldCurrent
);
3025 void wxListMainWindow::MoveToItem(size_t item
)
3027 if ( item
== (size_t)-1 )
3030 wxRect rect
= GetLineRect(item
);
3032 int client_w
, client_h
;
3033 GetClientSize( &client_w
, &client_h
);
3035 int view_x
= m_xScroll
*GetScrollPos( wxHORIZONTAL
);
3036 int view_y
= m_yScroll
*GetScrollPos( wxVERTICAL
);
3038 if ( HasFlag(wxLC_REPORT
) )
3040 // the next we need the range of lines shown it might be different, so
3042 ResetVisibleLinesRange();
3044 if (rect
.y
< view_y
)
3045 Scroll( -1, rect
.y
/m_yScroll
);
3046 if (rect
.y
+rect
.height
+5 > view_y
+client_h
)
3047 Scroll( -1, (rect
.y
+rect
.height
-client_h
+SCROLL_UNIT_Y
)/m_yScroll
);
3051 if (rect
.x
-view_x
< 5)
3052 Scroll( (rect
.x
-5)/m_xScroll
, -1 );
3053 if (rect
.x
+rect
.width
-5 > view_x
+client_w
)
3054 Scroll( (rect
.x
+rect
.width
-client_w
+SCROLL_UNIT_X
)/m_xScroll
, -1 );
3058 // ----------------------------------------------------------------------------
3059 // keyboard handling
3060 // ----------------------------------------------------------------------------
3062 void wxListMainWindow::OnArrowChar(size_t newCurrent
, const wxKeyEvent
& event
)
3064 wxCHECK_RET( newCurrent
< (size_t)GetItemCount(),
3065 _T("invalid item index in OnArrowChar()") );
3067 size_t oldCurrent
= m_current
;
3069 // in single selection we just ignore Shift as we can't select several
3071 if ( event
.ShiftDown() && !IsSingleSel() )
3073 m_current
= newCurrent
;
3075 // select all the items between the old and the new one
3076 if ( oldCurrent
> newCurrent
)
3078 newCurrent
= oldCurrent
;
3079 oldCurrent
= m_current
;
3082 HighlightLines(oldCurrent
, newCurrent
);
3086 // all previously selected items are unselected unless ctrl is held
3087 if ( !event
.ControlDown() )
3088 HighlightAll(FALSE
);
3090 m_current
= newCurrent
;
3092 HighlightLine( oldCurrent
, FALSE
);
3093 RefreshLine( oldCurrent
);
3095 if ( !event
.ControlDown() )
3097 HighlightLine( m_current
, TRUE
);
3101 OnUnfocusLine( oldCurrent
);
3102 OnFocusLine( m_current
);
3103 RefreshLine( m_current
);
3108 void wxListMainWindow::OnKeyDown( wxKeyEvent
&event
)
3110 wxWindow
*parent
= GetParent();
3112 /* we propagate the key event up */
3113 wxKeyEvent
ke( wxEVT_KEY_DOWN
);
3114 ke
.m_shiftDown
= event
.m_shiftDown
;
3115 ke
.m_controlDown
= event
.m_controlDown
;
3116 ke
.m_altDown
= event
.m_altDown
;
3117 ke
.m_metaDown
= event
.m_metaDown
;
3118 ke
.m_keyCode
= event
.m_keyCode
;
3121 ke
.SetEventObject( parent
);
3122 if (parent
->GetEventHandler()->ProcessEvent( ke
)) return;
3127 void wxListMainWindow::OnChar( wxKeyEvent
&event
)
3129 wxWindow
*parent
= GetParent();
3131 /* we send a list_key event up */
3134 wxListEvent
le( wxEVT_COMMAND_LIST_KEY_DOWN
, GetParent()->GetId() );
3135 le
.m_itemIndex
= m_current
;
3136 GetLine(m_current
)->GetItem( 0, le
.m_item
);
3137 le
.m_code
= (int)event
.KeyCode();
3138 le
.SetEventObject( parent
);
3139 parent
->GetEventHandler()->ProcessEvent( le
);
3142 /* we propagate the char event up */
3143 wxKeyEvent
ke( wxEVT_CHAR
);
3144 ke
.m_shiftDown
= event
.m_shiftDown
;
3145 ke
.m_controlDown
= event
.m_controlDown
;
3146 ke
.m_altDown
= event
.m_altDown
;
3147 ke
.m_metaDown
= event
.m_metaDown
;
3148 ke
.m_keyCode
= event
.m_keyCode
;
3151 ke
.SetEventObject( parent
);
3152 if (parent
->GetEventHandler()->ProcessEvent( ke
)) return;
3154 if (event
.KeyCode() == WXK_TAB
)
3156 wxNavigationKeyEvent nevent
;
3157 nevent
.SetWindowChange( event
.ControlDown() );
3158 nevent
.SetDirection( !event
.ShiftDown() );
3159 nevent
.SetEventObject( GetParent()->GetParent() );
3160 nevent
.SetCurrentFocus( m_parent
);
3161 if (GetParent()->GetParent()->GetEventHandler()->ProcessEvent( nevent
)) return;
3164 /* no item -> nothing to do */
3171 switch (event
.KeyCode())
3174 if ( m_current
> 0 )
3175 OnArrowChar( m_current
- 1, event
);
3179 if ( m_current
< (size_t)GetItemCount() - 1 )
3180 OnArrowChar( m_current
+ 1, event
);
3185 OnArrowChar( GetItemCount() - 1, event
);
3190 OnArrowChar( 0, event
);
3196 if ( HasFlag(wxLC_REPORT
) )
3198 steps
= m_linesPerPage
- 1;
3202 steps
= m_current
% m_linesPerPage
;
3205 int index
= m_current
- steps
;
3209 OnArrowChar( index
, event
);
3216 if ( HasFlag(wxLC_REPORT
) )
3218 steps
= m_linesPerPage
- 1;
3222 steps
= m_linesPerPage
- (m_current
% m_linesPerPage
) - 1;
3225 size_t index
= m_current
+ steps
;
3226 size_t count
= GetItemCount();
3227 if ( index
>= count
)
3230 OnArrowChar( index
, event
);
3235 if ( !HasFlag(wxLC_REPORT
) )
3237 int index
= m_current
- m_linesPerPage
;
3241 OnArrowChar( index
, event
);
3246 if ( !HasFlag(wxLC_REPORT
) )
3248 size_t index
= m_current
+ m_linesPerPage
;
3250 size_t count
= GetItemCount();
3251 if ( index
>= count
)
3254 OnArrowChar( index
, event
);
3259 if ( IsSingleSel() )
3261 wxListEvent
le( wxEVT_COMMAND_LIST_ITEM_ACTIVATED
,
3262 GetParent()->GetId() );
3263 le
.SetEventObject( GetParent() );
3264 le
.m_itemIndex
= m_current
;
3265 GetLine(m_current
)->GetItem( 0, le
.m_item
);
3266 GetParent()->GetEventHandler()->ProcessEvent( le
);
3268 if ( IsHighlighted(m_current
) )
3270 // don't unselect the item in single selection mode
3273 //else: select it in ReverseHighlight() below if unselected
3276 ReverseHighlight(m_current
);
3282 wxListEvent
le( wxEVT_COMMAND_LIST_ITEM_ACTIVATED
,
3283 GetParent()->GetId() );
3284 le
.SetEventObject( GetParent() );
3285 le
.m_itemIndex
= m_current
;
3286 GetLine(m_current
)->GetItem( 0, le
.m_item
);
3287 GetParent()->GetEventHandler()->ProcessEvent( le
);
3296 // ----------------------------------------------------------------------------
3298 // ----------------------------------------------------------------------------
3301 extern wxWindow
*g_focusWindow
;
3304 void wxListMainWindow::OnSetFocus( wxFocusEvent
&WXUNUSED(event
) )
3314 g_focusWindow
= GetParent();
3317 wxFocusEvent
event( wxEVT_SET_FOCUS
, GetParent()->GetId() );
3318 event
.SetEventObject( GetParent() );
3319 GetParent()->GetEventHandler()->ProcessEvent( event
);
3322 void wxListMainWindow::OnKillFocus( wxFocusEvent
&WXUNUSED(event
) )
3329 void wxListMainWindow::DrawImage( int index
, wxDC
*dc
, int x
, int y
)
3331 if ( HasFlag(wxLC_ICON
) && (m_normal_image_list
))
3333 m_normal_image_list
->Draw( index
, *dc
, x
, y
, wxIMAGELIST_DRAW_TRANSPARENT
);
3335 else if ( HasFlag(wxLC_SMALL_ICON
) && (m_small_image_list
))
3337 m_small_image_list
->Draw( index
, *dc
, x
, y
, wxIMAGELIST_DRAW_TRANSPARENT
);
3339 else if ( HasFlag(wxLC_LIST
) && (m_small_image_list
))
3341 m_small_image_list
->Draw( index
, *dc
, x
, y
, wxIMAGELIST_DRAW_TRANSPARENT
);
3343 else if ( HasFlag(wxLC_REPORT
) && (m_small_image_list
))
3345 m_small_image_list
->Draw( index
, *dc
, x
, y
, wxIMAGELIST_DRAW_TRANSPARENT
);
3349 void wxListMainWindow::GetImageSize( int index
, int &width
, int &height
) const
3351 if ( HasFlag(wxLC_ICON
) && m_normal_image_list
)
3353 m_normal_image_list
->GetSize( index
, width
, height
);
3355 else if ( HasFlag(wxLC_SMALL_ICON
) && m_small_image_list
)
3357 m_small_image_list
->GetSize( index
, width
, height
);
3359 else if ( HasFlag(wxLC_LIST
) && m_small_image_list
)
3361 m_small_image_list
->GetSize( index
, width
, height
);
3363 else if ( HasFlag(wxLC_REPORT
) && m_small_image_list
)
3365 m_small_image_list
->GetSize( index
, width
, height
);
3374 int wxListMainWindow::GetTextLength( const wxString
&s
) const
3376 wxClientDC
dc( wxConstCast(this, wxListMainWindow
) );
3377 dc
.SetFont( GetFont() );
3380 dc
.GetTextExtent( s
, &lw
, NULL
);
3382 return lw
+ AUTOSIZE_COL_MARGIN
;
3385 void wxListMainWindow::SetImageList( wxImageList
*imageList
, int which
)
3389 // calc the spacing from the icon size
3392 if ((imageList
) && (imageList
->GetImageCount()) )
3394 imageList
->GetSize(0, width
, height
);
3397 if (which
== wxIMAGE_LIST_NORMAL
)
3399 m_normal_image_list
= imageList
;
3400 m_normal_spacing
= width
+ 8;
3403 if (which
== wxIMAGE_LIST_SMALL
)
3405 m_small_image_list
= imageList
;
3406 m_small_spacing
= width
+ 14;
3410 void wxListMainWindow::SetItemSpacing( int spacing
, bool isSmall
)
3415 m_small_spacing
= spacing
;
3419 m_normal_spacing
= spacing
;
3423 int wxListMainWindow::GetItemSpacing( bool isSmall
)
3425 return isSmall
? m_small_spacing
: m_normal_spacing
;
3428 // ----------------------------------------------------------------------------
3430 // ----------------------------------------------------------------------------
3432 void wxListMainWindow::SetColumn( int col
, wxListItem
&item
)
3434 wxListHeaderDataList::Node
*node
= m_columns
.Item( col
);
3436 wxCHECK_RET( node
, _T("invalid column index in SetColumn") );
3438 if ( item
.m_width
== wxLIST_AUTOSIZE_USEHEADER
)
3439 item
.m_width
= GetTextLength( item
.m_text
);
3441 wxListHeaderData
*column
= node
->GetData();
3442 column
->SetItem( item
);
3444 wxListHeaderWindow
*headerWin
= GetListCtrl()->m_headerWin
;
3446 headerWin
->m_dirty
= TRUE
;
3450 // invalidate it as it has to be recalculated
3454 void wxListMainWindow::SetColumnWidth( int col
, int width
)
3456 wxCHECK_RET( col
>= 0 && col
< GetColumnCount(),
3457 _T("invalid column index") );
3459 wxCHECK_RET( HasFlag(wxLC_REPORT
),
3460 _T("SetColumnWidth() can only be called in report mode.") );
3463 wxListHeaderWindow
*headerWin
= GetListCtrl()->m_headerWin
;
3465 headerWin
->m_dirty
= TRUE
;
3467 wxListHeaderDataList::Node
*node
= m_columns
.Item( col
);
3468 wxCHECK_RET( node
, _T("no column?") );
3470 wxListHeaderData
*column
= node
->GetData();
3472 size_t count
= GetItemCount();
3474 if (width
== wxLIST_AUTOSIZE_USEHEADER
)
3476 width
= GetTextLength(column
->GetText());
3478 else if ( width
== wxLIST_AUTOSIZE
)
3482 // TODO: determine the max width somehow...
3483 width
= WIDTH_COL_DEFAULT
;
3487 wxClientDC
dc(this);
3488 dc
.SetFont( GetFont() );
3490 int max
= AUTOSIZE_COL_MARGIN
;
3492 for ( size_t i
= 0; i
< count
; i
++ )
3494 wxListLineData
*line
= GetLine(i
);
3495 wxListItemDataList::Node
*n
= line
->m_items
.Item( col
);
3497 wxCHECK_RET( n
, _T("no subitem?") );
3499 wxListItemData
*item
= n
->GetData();
3502 if (item
->HasImage())
3505 GetImageSize( item
->GetImage(), ix
, iy
);
3509 if (item
->HasText())
3512 dc
.GetTextExtent( item
->GetText(), &w
, NULL
);
3520 width
= max
+ AUTOSIZE_COL_MARGIN
;
3524 column
->SetWidth( width
);
3526 // invalidate it as it has to be recalculated
3530 int wxListMainWindow::GetHeaderWidth() const
3532 if ( !m_headerWidth
)
3534 wxListMainWindow
*self
= wxConstCast(this, wxListMainWindow
);
3536 size_t count
= GetColumnCount();
3537 for ( size_t col
= 0; col
< count
; col
++ )
3539 self
->m_headerWidth
+= GetColumnWidth(col
);
3543 return m_headerWidth
;
3546 void wxListMainWindow::GetColumn( int col
, wxListItem
&item
) const
3548 wxListHeaderDataList::Node
*node
= m_columns
.Item( col
);
3549 wxCHECK_RET( node
, _T("invalid column index in GetColumn") );
3551 wxListHeaderData
*column
= node
->GetData();
3552 column
->GetItem( item
);
3555 int wxListMainWindow::GetColumnWidth( int col
) const
3557 wxListHeaderDataList::Node
*node
= m_columns
.Item( col
);
3558 wxCHECK_MSG( node
, 0, _T("invalid column index") );
3560 wxListHeaderData
*column
= node
->GetData();
3561 return column
->GetWidth();
3564 // ----------------------------------------------------------------------------
3566 // ----------------------------------------------------------------------------
3568 void wxListMainWindow::SetItem( wxListItem
&item
)
3570 long id
= item
.m_itemId
;
3571 wxCHECK_RET( id
>= 0 && (size_t)id
< GetItemCount(),
3572 _T("invalid item index in SetItem") );
3576 wxListLineData
*line
= GetLine((size_t)id
);
3577 line
->SetItem( item
.m_col
, item
);
3580 if ( InReportView() )
3582 // just refresh the line to show the new value of the text/image
3583 RefreshLine((size_t)id
);
3587 // refresh everything (resulting in horrible flicker - FIXME!)
3592 void wxListMainWindow::SetItemState( long litem
, long state
, long stateMask
)
3594 wxCHECK_RET( litem
>= 0 && (size_t)litem
< GetItemCount(),
3595 _T("invalid list ctrl item index in SetItem") );
3597 size_t oldCurrent
= m_current
;
3598 size_t item
= (size_t)litem
; // safe because of the check above
3600 // do we need to change the focus?
3601 if ( stateMask
& wxLIST_STATE_FOCUSED
)
3603 if ( state
& wxLIST_STATE_FOCUSED
)
3605 // don't do anything if this item is already focused
3606 if ( item
!= m_current
)
3608 OnUnfocusLine( m_current
);
3610 OnFocusLine( m_current
);
3612 if ( oldCurrent
!= (size_t)-1 )
3614 if ( IsSingleSel() )
3616 HighlightLine(oldCurrent
, FALSE
);
3619 RefreshLine(oldCurrent
);
3622 RefreshLine( m_current
);
3627 // don't do anything if this item is not focused
3628 if ( item
== m_current
)
3630 OnUnfocusLine( m_current
);
3631 m_current
= (size_t)-1;
3633 RefreshLine( oldCurrent
);
3638 // do we need to change the selection state?
3639 if ( stateMask
& wxLIST_STATE_SELECTED
)
3641 bool on
= (state
& wxLIST_STATE_SELECTED
) != 0;
3643 if ( IsSingleSel() )
3647 // selecting the item also makes it the focused one in the
3649 if ( m_current
!= item
)
3651 OnUnfocusLine( m_current
);
3653 OnFocusLine( m_current
);
3655 if ( oldCurrent
!= (size_t)-1 )
3657 HighlightLine( oldCurrent
, FALSE
);
3658 RefreshLine( oldCurrent
);
3664 // only the current item may be selected anyhow
3665 if ( item
!= m_current
)
3670 if ( HighlightLine(item
, on
) )
3677 int wxListMainWindow::GetItemState( long item
, long stateMask
)
3679 wxCHECK_MSG( item
>= 0 && (size_t)item
< GetItemCount(), 0,
3680 _T("invalid list ctrl item index in GetItemState()") );
3682 int ret
= wxLIST_STATE_DONTCARE
;
3684 if ( stateMask
& wxLIST_STATE_FOCUSED
)
3686 if ( (size_t)item
== m_current
)
3687 ret
|= wxLIST_STATE_FOCUSED
;
3690 if ( stateMask
& wxLIST_STATE_SELECTED
)
3692 if ( IsHighlighted(item
) )
3693 ret
|= wxLIST_STATE_SELECTED
;
3699 void wxListMainWindow::GetItem( wxListItem
&item
)
3701 wxCHECK_RET( item
.m_itemId
>= 0 && (size_t)item
.m_itemId
< GetItemCount(),
3702 _T("invalid item index in GetItem") );
3704 wxListLineData
*line
= GetLine((size_t)item
.m_itemId
);
3705 line
->GetItem( item
.m_col
, item
);
3708 // ----------------------------------------------------------------------------
3710 // ----------------------------------------------------------------------------
3712 size_t wxListMainWindow::GetItemCount() const
3714 return IsVirtual() ? m_countVirt
: m_lines
.GetCount();
3717 void wxListMainWindow::SetItemCount(long count
)
3719 m_selStore
.SetItemCount(count
);
3720 m_countVirt
= count
;
3722 ResetVisibleLinesRange();
3724 // scrollbars must be reset
3728 int wxListMainWindow::GetSelectedItemCount()
3730 // deal with the quick case first
3731 if ( IsSingleSel() )
3733 return HasCurrent() ? IsHighlighted(m_current
) : FALSE
;
3736 // virtual controls remmebers all its selections itself
3738 return m_selStore
.GetSelectedCount();
3740 // TODO: we probably should maintain the number of items selected even for
3741 // non virtual controls as enumerating all lines is really slow...
3742 size_t countSel
= 0;
3743 size_t count
= GetItemCount();
3744 for ( size_t line
= 0; line
< count
; line
++ )
3746 if ( GetLine(line
)->IsHighlighted() )
3753 // ----------------------------------------------------------------------------
3754 // item position/size
3755 // ----------------------------------------------------------------------------
3757 void wxListMainWindow::GetItemRect( long index
, wxRect
&rect
)
3759 wxCHECK_RET( index
>= 0 && (size_t)index
< GetItemCount(),
3760 _T("invalid index in GetItemRect") );
3762 rect
= GetLineRect((size_t)index
);
3764 CalcScrolledPosition(rect
.x
, rect
.y
, &rect
.x
, &rect
.y
);
3767 bool wxListMainWindow::GetItemPosition(long item
, wxPoint
& pos
)
3770 GetItemRect(item
, rect
);
3778 // ----------------------------------------------------------------------------
3779 // geometry calculation
3780 // ----------------------------------------------------------------------------
3782 void wxListMainWindow::RecalculatePositions(bool noRefresh
)
3784 wxClientDC
dc( this );
3785 dc
.SetFont( GetFont() );
3788 if ( HasFlag(wxLC_ICON
) )
3789 iconSpacing
= m_normal_spacing
;
3790 else if ( HasFlag(wxLC_SMALL_ICON
) )
3791 iconSpacing
= m_small_spacing
;
3797 GetClientSize( &clientWidth
, &clientHeight
);
3799 if ( HasFlag(wxLC_REPORT
) )
3801 // all lines have the same height
3802 int lineHeight
= GetLineHeight();
3804 // scroll one line per step
3805 m_yScroll
= lineHeight
;
3807 size_t lineCount
= GetItemCount();
3808 int entireHeight
= lineCount
*lineHeight
+ LINE_SPACING
;
3810 m_linesPerPage
= clientHeight
/ lineHeight
;
3812 ResetVisibleLinesRange();
3814 SetScrollbars( m_xScroll
, m_yScroll
,
3815 (GetHeaderWidth() + m_xScroll
- 1)/m_xScroll
,
3816 (entireHeight
+ m_yScroll
- 1)/m_yScroll
,
3817 GetScrollPos(wxHORIZONTAL
),
3818 GetScrollPos(wxVERTICAL
),
3823 // at first we try without any scrollbar. if the items don't
3824 // fit into the window, we recalculate after subtracting an
3825 // approximated 15 pt for the horizontal scrollbar
3827 clientHeight
-= 4; // sunken frame
3829 int entireWidth
= 0;
3831 for (int tries
= 0; tries
< 2; tries
++)
3838 int currentlyVisibleLines
= 0;
3840 size_t count
= GetItemCount();
3841 for (size_t i
= 0; i
< count
; i
++)
3843 currentlyVisibleLines
++;
3844 wxListLineData
*line
= GetLine(i
);
3845 line
->CalculateSize( &dc
, iconSpacing
);
3846 line
->SetPosition( x
, y
, clientWidth
, iconSpacing
);
3848 wxSize sizeLine
= GetLineSize(i
);
3850 if ( maxWidth
< sizeLine
.x
)
3851 maxWidth
= sizeLine
.x
;
3854 if (currentlyVisibleLines
> m_linesPerPage
)
3855 m_linesPerPage
= currentlyVisibleLines
;
3857 // assume that the size of the next one is the same... (FIXME)
3858 if ( y
+ sizeLine
.y
- 6 >= clientHeight
)
3860 currentlyVisibleLines
= 0;
3863 entireWidth
+= maxWidth
+6;
3866 if ( i
== count
- 1 )
3867 entireWidth
+= maxWidth
;
3868 if ((tries
== 0) && (entireWidth
> clientWidth
))
3870 clientHeight
-= 15; // scrollbar height
3872 currentlyVisibleLines
= 0;
3875 if ( i
== count
- 1 )
3876 tries
= 1; // everything fits, no second try required
3880 int scroll_pos
= GetScrollPos( wxHORIZONTAL
);
3881 SetScrollbars( m_xScroll
, m_yScroll
, (entireWidth
+SCROLL_UNIT_X
) / m_xScroll
, 0, scroll_pos
, 0, TRUE
);
3886 // FIXME: why should we call it from here?
3893 void wxListMainWindow::RefreshAll()
3898 wxListHeaderWindow
*headerWin
= GetListCtrl()->m_headerWin
;
3899 if ( headerWin
&& headerWin
->m_dirty
)
3901 headerWin
->m_dirty
= FALSE
;
3902 headerWin
->Refresh();
3906 void wxListMainWindow::UpdateCurrent()
3908 if ( !HasCurrent() && !IsEmpty() )
3913 if ( m_current
!= (size_t)-1 )
3915 OnFocusLine( m_current
);
3919 long wxListMainWindow::GetNextItem( long item
,
3920 int WXUNUSED(geometry
),
3924 max
= GetItemCount();
3925 wxCHECK_MSG( (ret
== -1) || (ret
< max
), -1,
3926 _T("invalid listctrl index in GetNextItem()") );
3928 // notice that we start with the next item (or the first one if item == -1)
3929 // and this is intentional to allow writing a simple loop to iterate over
3930 // all selected items
3934 // this is not an error because the index was ok initially, just no
3945 size_t count
= GetItemCount();
3946 for ( size_t line
= (size_t)ret
; line
< count
; line
++ )
3948 if ( (state
& wxLIST_STATE_FOCUSED
) && (line
== m_current
) )
3951 if ( (state
& wxLIST_STATE_SELECTED
) && IsHighlighted(line
) )
3958 // ----------------------------------------------------------------------------
3960 // ----------------------------------------------------------------------------
3962 void wxListMainWindow::DeleteItem( long lindex
)
3964 size_t count
= GetItemCount();
3966 wxCHECK_RET( (lindex
>= 0) && ((size_t)lindex
< count
),
3967 _T("invalid item index in DeleteItem") );
3969 size_t index
= (size_t)lindex
;
3971 // we don't need to adjust the index for the previous items
3972 if ( HasCurrent() && m_current
>= index
)
3974 // if the current item is being deleted, we want the next one to
3975 // become selected - unless there is no next one - so don't adjust
3976 // m_current in this case
3977 if ( m_current
!= index
|| m_current
== count
- 1 )
3983 if ( InReportView() )
3985 ResetVisibleLinesRange();
3992 m_selStore
.OnItemDelete(index
);
3996 m_lines
.RemoveAt( index
);
3999 // we need to refresh the (vert) scrollbar as the number of items changed
4002 SendNotify( index
, wxEVT_COMMAND_LIST_DELETE_ITEM
);
4004 RefreshAfter(index
);
4007 void wxListMainWindow::DeleteColumn( int col
)
4009 wxListHeaderDataList::Node
*node
= m_columns
.Item( col
);
4011 wxCHECK_RET( node
, wxT("invalid column index in DeleteColumn()") );
4014 m_columns
.DeleteNode( node
);
4017 void wxListMainWindow::DoDeleteAllItems()
4021 // nothing to do - in particular, don't send the event
4027 // to make the deletion of all items faster, we don't send the
4028 // notifications for each item deletion in this case but only one event
4029 // for all of them: this is compatible with wxMSW and documented in
4030 // DeleteAllItems() description
4032 wxListEvent
event( wxEVT_COMMAND_LIST_DELETE_ALL_ITEMS
, GetParent()->GetId() );
4033 event
.SetEventObject( GetParent() );
4034 GetParent()->GetEventHandler()->ProcessEvent( event
);
4043 if ( InReportView() )
4045 ResetVisibleLinesRange();
4051 void wxListMainWindow::DeleteAllItems()
4055 RecalculatePositions();
4058 void wxListMainWindow::DeleteEverything()
4065 // ----------------------------------------------------------------------------
4066 // scanning for an item
4067 // ----------------------------------------------------------------------------
4069 void wxListMainWindow::EnsureVisible( long index
)
4071 wxCHECK_RET( index
>= 0 && (size_t)index
< GetItemCount(),
4072 _T("invalid index in EnsureVisible") );
4074 // We have to call this here because the label in question might just have
4075 // been added and its position is not known yet
4078 RecalculatePositions(TRUE
/* no refresh */);
4081 MoveToItem((size_t)index
);
4084 long wxListMainWindow::FindItem(long start
, const wxString
& str
, bool WXUNUSED(partial
) )
4091 size_t count
= GetItemCount();
4092 for ( size_t i
= (size_t)pos
; i
< count
; i
++ )
4094 wxListLineData
*line
= GetLine(i
);
4095 if ( line
->GetText(0) == tmp
)
4102 long wxListMainWindow::FindItem(long start
, long data
)
4108 size_t count
= GetItemCount();
4109 for (size_t i
= (size_t)pos
; i
< count
; i
++)
4111 wxListLineData
*line
= GetLine(i
);
4113 line
->GetItem( 0, item
);
4114 if (item
.m_data
== data
)
4121 long wxListMainWindow::HitTest( int x
, int y
, int &flags
)
4123 CalcUnscrolledPosition( x
, y
, &x
, &y
);
4125 size_t count
= GetItemCount();
4127 if ( HasFlag(wxLC_REPORT
) )
4129 size_t current
= y
/ GetLineHeight();
4130 if ( current
< count
)
4132 flags
= HitTestLine(current
, x
, y
);
4139 // TODO: optimize it too! this is less simple than for report view but
4140 // enumerating all items is still not a way to do it!!
4141 for ( size_t current
= 0; current
< count
; current
++ )
4143 flags
= HitTestLine(current
, x
, y
);
4152 // ----------------------------------------------------------------------------
4154 // ----------------------------------------------------------------------------
4156 void wxListMainWindow::InsertItem( wxListItem
&item
)
4158 wxASSERT_MSG( !IsVirtual(), _T("can't be used with virtual control") );
4160 size_t count
= GetItemCount();
4161 wxCHECK_RET( item
.m_itemId
>= 0 && (size_t)item
.m_itemId
<= count
,
4162 _T("invalid item index") );
4164 size_t id
= item
.m_itemId
;
4169 if ( HasFlag(wxLC_REPORT
) )
4171 else if ( HasFlag(wxLC_LIST
) )
4173 else if ( HasFlag(wxLC_ICON
) )
4175 else if ( HasFlag(wxLC_SMALL_ICON
) )
4176 mode
= wxLC_ICON
; // no typo
4179 wxFAIL_MSG( _T("unknown mode") );
4182 wxListLineData
*line
= new wxListLineData(this);
4184 line
->SetItem( 0, item
);
4186 m_lines
.Insert( line
, id
);
4189 RefreshLines(id
, GetItemCount() - 1);
4192 void wxListMainWindow::InsertColumn( long col
, wxListItem
&item
)
4195 if ( HasFlag(wxLC_REPORT
) )
4197 if (item
.m_width
== wxLIST_AUTOSIZE_USEHEADER
)
4198 item
.m_width
= GetTextLength( item
.m_text
);
4199 wxListHeaderData
*column
= new wxListHeaderData( item
);
4200 if ((col
>= 0) && (col
< (int)m_columns
.GetCount()))
4202 wxListHeaderDataList::Node
*node
= m_columns
.Item( col
);
4203 m_columns
.Insert( node
, column
);
4207 m_columns
.Append( column
);
4212 // ----------------------------------------------------------------------------
4214 // ----------------------------------------------------------------------------
4216 wxListCtrlCompare list_ctrl_compare_func_2
;
4217 long list_ctrl_compare_data
;
4219 int LINKAGEMODE
list_ctrl_compare_func_1( wxListLineData
**arg1
, wxListLineData
**arg2
)
4221 wxListLineData
*line1
= *arg1
;
4222 wxListLineData
*line2
= *arg2
;
4224 line1
->GetItem( 0, item
);
4225 long data1
= item
.m_data
;
4226 line2
->GetItem( 0, item
);
4227 long data2
= item
.m_data
;
4228 return list_ctrl_compare_func_2( data1
, data2
, list_ctrl_compare_data
);
4231 void wxListMainWindow::SortItems( wxListCtrlCompare fn
, long data
)
4233 list_ctrl_compare_func_2
= fn
;
4234 list_ctrl_compare_data
= data
;
4235 m_lines
.Sort( list_ctrl_compare_func_1
);
4239 // ----------------------------------------------------------------------------
4241 // ----------------------------------------------------------------------------
4243 void wxListMainWindow::OnScroll(wxScrollWinEvent
& event
)
4245 // update our idea of which lines are shown when we redraw the window the
4247 ResetVisibleLinesRange();
4250 #if defined(__WXGTK__) && !defined(__WXUNIVERSAL__)
4251 wxScrolledWindow::OnScroll(event
);
4253 HandleOnScroll( event
);
4256 if ( event
.GetOrientation() == wxHORIZONTAL
&& HasHeader() )
4258 wxListCtrl
* lc
= GetListCtrl();
4259 wxCHECK_RET( lc
, _T("no listctrl window?") );
4261 lc
->m_headerWin
->Refresh() ;
4263 lc
->m_headerWin
->MacUpdateImmediately() ;
4268 int wxListMainWindow::GetCountPerPage() const
4270 if ( !m_linesPerPage
)
4272 wxConstCast(this, wxListMainWindow
)->
4273 m_linesPerPage
= GetClientSize().y
/ GetLineHeight();
4276 return m_linesPerPage
;
4279 void wxListMainWindow::GetVisibleLinesRange(size_t *from
, size_t *to
)
4281 wxASSERT_MSG( HasFlag(wxLC_REPORT
), _T("this is for report mode only") );
4283 if ( m_lineFrom
== (size_t)-1 )
4285 size_t count
= GetItemCount();
4288 m_lineFrom
= GetScrollPos(wxVERTICAL
);
4290 // this may happen if SetScrollbars() hadn't been called yet
4291 if ( m_lineFrom
>= count
)
4292 m_lineFrom
= count
- 1;
4294 // we redraw one extra line but this is needed to make the redrawing
4295 // logic work when there is a fractional number of lines on screen
4296 m_lineTo
= m_lineFrom
+ m_linesPerPage
;
4297 if ( m_lineTo
>= count
)
4298 m_lineTo
= count
- 1;
4300 else // empty control
4303 m_lineTo
= (size_t)-1;
4307 wxASSERT_MSG( IsEmpty() ||
4308 (m_lineFrom
<= m_lineTo
&& m_lineTo
< GetItemCount()),
4309 _T("GetVisibleLinesRange() returns incorrect result") );
4317 // -------------------------------------------------------------------------------------
4319 // -------------------------------------------------------------------------------------
4321 IMPLEMENT_DYNAMIC_CLASS(wxListItem
, wxObject
)
4323 wxListItem::wxListItem()
4332 m_format
= wxLIST_FORMAT_CENTRE
;
4338 void wxListItem::Clear()
4347 m_format
= wxLIST_FORMAT_CENTRE
;
4354 void wxListItem::ClearAttributes()
4363 // -------------------------------------------------------------------------------------
4365 // -------------------------------------------------------------------------------------
4367 IMPLEMENT_DYNAMIC_CLASS(wxListEvent
, wxNotifyEvent
)
4369 wxListEvent::wxListEvent( wxEventType commandType
, int id
)
4370 : wxNotifyEvent( commandType
, id
)
4376 m_cancelled
= FALSE
;
4381 void wxListEvent::CopyObject(wxObject
& object_dest
) const
4383 wxListEvent
*obj
= (wxListEvent
*)&object_dest
;
4385 wxNotifyEvent::CopyObject(object_dest
);
4387 obj
->m_code
= m_code
;
4388 obj
->m_itemIndex
= m_itemIndex
;
4389 obj
->m_oldItemIndex
= m_oldItemIndex
;
4391 obj
->m_cancelled
= m_cancelled
;
4392 obj
->m_pointDrag
= m_pointDrag
;
4393 obj
->m_item
.m_mask
= m_item
.m_mask
;
4394 obj
->m_item
.m_itemId
= m_item
.m_itemId
;
4395 obj
->m_item
.m_col
= m_item
.m_col
;
4396 obj
->m_item
.m_state
= m_item
.m_state
;
4397 obj
->m_item
.m_stateMask
= m_item
.m_stateMask
;
4398 obj
->m_item
.m_text
= m_item
.m_text
;
4399 obj
->m_item
.m_image
= m_item
.m_image
;
4400 obj
->m_item
.m_data
= m_item
.m_data
;
4401 obj
->m_item
.m_format
= m_item
.m_format
;
4402 obj
->m_item
.m_width
= m_item
.m_width
;
4404 if ( m_item
.HasAttributes() )
4406 obj
->m_item
.SetTextColour(m_item
.GetTextColour());
4410 // -------------------------------------------------------------------------------------
4412 // -------------------------------------------------------------------------------------
4414 IMPLEMENT_DYNAMIC_CLASS(wxListCtrl
, wxControl
)
4415 IMPLEMENT_DYNAMIC_CLASS(wxListView
, wxListCtrl
)
4417 BEGIN_EVENT_TABLE(wxListCtrl
,wxControl
)
4418 EVT_SIZE(wxListCtrl::OnSize
)
4419 EVT_IDLE(wxListCtrl::OnIdle
)
4422 wxListCtrl::wxListCtrl()
4424 m_imageListNormal
= (wxImageList
*) NULL
;
4425 m_imageListSmall
= (wxImageList
*) NULL
;
4426 m_imageListState
= (wxImageList
*) NULL
;
4428 m_ownsImageListNormal
=
4429 m_ownsImageListSmall
=
4430 m_ownsImageListState
= FALSE
;
4432 m_mainWin
= (wxListMainWindow
*) NULL
;
4433 m_headerWin
= (wxListHeaderWindow
*) NULL
;
4436 wxListCtrl::~wxListCtrl()
4439 m_mainWin
->ResetCurrent();
4441 if (m_ownsImageListNormal
)
4442 delete m_imageListNormal
;
4443 if (m_ownsImageListSmall
)
4444 delete m_imageListSmall
;
4445 if (m_ownsImageListState
)
4446 delete m_imageListState
;
4449 void wxListCtrl::CreateHeaderWindow()
4451 m_headerWin
= new wxListHeaderWindow
4453 this, -1, m_mainWin
,
4455 wxSize(GetClientSize().x
, HEADER_HEIGHT
),
4460 bool wxListCtrl::Create(wxWindow
*parent
,
4465 const wxValidator
&validator
,
4466 const wxString
&name
)
4470 m_imageListState
= (wxImageList
*) NULL
;
4471 m_ownsImageListNormal
=
4472 m_ownsImageListSmall
=
4473 m_ownsImageListState
= FALSE
;
4475 m_mainWin
= (wxListMainWindow
*) NULL
;
4476 m_headerWin
= (wxListHeaderWindow
*) NULL
;
4478 if ( !(style
& wxLC_MASK_TYPE
) )
4480 style
= style
| wxLC_LIST
;
4483 if ( !wxControl::Create( parent
, id
, pos
, size
, style
, validator
, name
) )
4486 // don't create the inner window with the border
4487 style
&= ~wxSUNKEN_BORDER
;
4489 m_mainWin
= new wxListMainWindow( this, -1, wxPoint(0,0), size
, style
);
4491 if ( HasFlag(wxLC_REPORT
) )
4493 CreateHeaderWindow();
4495 if ( HasFlag(wxLC_NO_HEADER
) )
4497 // VZ: why do we create it at all then?
4498 m_headerWin
->Show( FALSE
);
4505 void wxListCtrl::SetSingleStyle( long style
, bool add
)
4507 wxASSERT_MSG( !(style
& wxLC_VIRTUAL
),
4508 _T("wxLC_VIRTUAL can't be [un]set") );
4510 long flag
= GetWindowStyle();
4514 if (style
& wxLC_MASK_TYPE
)
4515 flag
&= ~(wxLC_MASK_TYPE
| wxLC_VIRTUAL
);
4516 if (style
& wxLC_MASK_ALIGN
)
4517 flag
&= ~wxLC_MASK_ALIGN
;
4518 if (style
& wxLC_MASK_SORT
)
4519 flag
&= ~wxLC_MASK_SORT
;
4531 SetWindowStyleFlag( flag
);
4534 void wxListCtrl::SetWindowStyleFlag( long flag
)
4538 m_mainWin
->DeleteEverything();
4540 // has the header visibility changed?
4541 bool hasHeader
= HasFlag(wxLC_REPORT
) && !HasFlag(wxLC_NO_HEADER
),
4542 willHaveHeader
= (flag
& wxLC_REPORT
) && !(flag
& wxLC_NO_HEADER
);
4544 if ( hasHeader
!= willHaveHeader
)
4551 // don't delete, just hide, as we can reuse it later
4552 m_headerWin
->Show(FALSE
);
4554 //else: nothing to do
4556 else // must show header
4560 CreateHeaderWindow();
4562 else // already have it, just show
4564 m_headerWin
->Show( TRUE
);
4568 ResizeReportView(willHaveHeader
);
4572 wxWindow::SetWindowStyleFlag( flag
);
4575 bool wxListCtrl::GetColumn(int col
, wxListItem
&item
) const
4577 m_mainWin
->GetColumn( col
, item
);
4581 bool wxListCtrl::SetColumn( int col
, wxListItem
& item
)
4583 m_mainWin
->SetColumn( col
, item
);
4587 int wxListCtrl::GetColumnWidth( int col
) const
4589 return m_mainWin
->GetColumnWidth( col
);
4592 bool wxListCtrl::SetColumnWidth( int col
, int width
)
4594 m_mainWin
->SetColumnWidth( col
, width
);
4598 int wxListCtrl::GetCountPerPage() const
4600 return m_mainWin
->GetCountPerPage(); // different from Windows ?
4603 bool wxListCtrl::GetItem( wxListItem
&info
) const
4605 m_mainWin
->GetItem( info
);
4609 bool wxListCtrl::SetItem( wxListItem
&info
)
4611 m_mainWin
->SetItem( info
);
4615 long wxListCtrl::SetItem( long index
, int col
, const wxString
& label
, int imageId
)
4618 info
.m_text
= label
;
4619 info
.m_mask
= wxLIST_MASK_TEXT
;
4620 info
.m_itemId
= index
;
4624 info
.m_image
= imageId
;
4625 info
.m_mask
|= wxLIST_MASK_IMAGE
;
4627 m_mainWin
->SetItem(info
);
4631 int wxListCtrl::GetItemState( long item
, long stateMask
) const
4633 return m_mainWin
->GetItemState( item
, stateMask
);
4636 bool wxListCtrl::SetItemState( long item
, long state
, long stateMask
)
4638 m_mainWin
->SetItemState( item
, state
, stateMask
);
4642 bool wxListCtrl::SetItemImage( long item
, int image
, int WXUNUSED(selImage
) )
4645 info
.m_image
= image
;
4646 info
.m_mask
= wxLIST_MASK_IMAGE
;
4647 info
.m_itemId
= item
;
4648 m_mainWin
->SetItem( info
);
4652 wxString
wxListCtrl::GetItemText( long item
) const
4655 info
.m_itemId
= item
;
4656 m_mainWin
->GetItem( info
);
4660 void wxListCtrl::SetItemText( long item
, const wxString
&str
)
4663 info
.m_mask
= wxLIST_MASK_TEXT
;
4664 info
.m_itemId
= item
;
4666 m_mainWin
->SetItem( info
);
4669 long wxListCtrl::GetItemData( long item
) const
4672 info
.m_itemId
= item
;
4673 m_mainWin
->GetItem( info
);
4677 bool wxListCtrl::SetItemData( long item
, long data
)
4680 info
.m_mask
= wxLIST_MASK_DATA
;
4681 info
.m_itemId
= item
;
4683 m_mainWin
->SetItem( info
);
4687 bool wxListCtrl::GetItemRect( long item
, wxRect
&rect
, int WXUNUSED(code
) ) const
4689 m_mainWin
->GetItemRect( item
, rect
);
4693 bool wxListCtrl::GetItemPosition( long item
, wxPoint
& pos
) const
4695 m_mainWin
->GetItemPosition( item
, pos
);
4699 bool wxListCtrl::SetItemPosition( long WXUNUSED(item
), const wxPoint
& WXUNUSED(pos
) )
4704 int wxListCtrl::GetItemCount() const
4706 return m_mainWin
->GetItemCount();
4709 int wxListCtrl::GetColumnCount() const
4711 return m_mainWin
->GetColumnCount();
4714 void wxListCtrl::SetItemSpacing( int spacing
, bool isSmall
)
4716 m_mainWin
->SetItemSpacing( spacing
, isSmall
);
4719 int wxListCtrl::GetItemSpacing( bool isSmall
) const
4721 return m_mainWin
->GetItemSpacing( isSmall
);
4724 int wxListCtrl::GetSelectedItemCount() const
4726 return m_mainWin
->GetSelectedItemCount();
4729 wxColour
wxListCtrl::GetTextColour() const
4731 return GetForegroundColour();
4734 void wxListCtrl::SetTextColour(const wxColour
& col
)
4736 SetForegroundColour(col
);
4739 long wxListCtrl::GetTopItem() const
4744 long wxListCtrl::GetNextItem( long item
, int geom
, int state
) const
4746 return m_mainWin
->GetNextItem( item
, geom
, state
);
4749 wxImageList
*wxListCtrl::GetImageList(int which
) const
4751 if (which
== wxIMAGE_LIST_NORMAL
)
4753 return m_imageListNormal
;
4755 else if (which
== wxIMAGE_LIST_SMALL
)
4757 return m_imageListSmall
;
4759 else if (which
== wxIMAGE_LIST_STATE
)
4761 return m_imageListState
;
4763 return (wxImageList
*) NULL
;
4766 void wxListCtrl::SetImageList( wxImageList
*imageList
, int which
)
4768 if ( which
== wxIMAGE_LIST_NORMAL
)
4770 if (m_ownsImageListNormal
) delete m_imageListNormal
;
4771 m_imageListNormal
= imageList
;
4772 m_ownsImageListNormal
= FALSE
;
4774 else if ( which
== wxIMAGE_LIST_SMALL
)
4776 if (m_ownsImageListSmall
) delete m_imageListSmall
;
4777 m_imageListSmall
= imageList
;
4778 m_ownsImageListSmall
= FALSE
;
4780 else if ( which
== wxIMAGE_LIST_STATE
)
4782 if (m_ownsImageListState
) delete m_imageListState
;
4783 m_imageListState
= imageList
;
4784 m_ownsImageListState
= FALSE
;
4787 m_mainWin
->SetImageList( imageList
, which
);
4790 void wxListCtrl::AssignImageList(wxImageList
*imageList
, int which
)
4792 SetImageList(imageList
, which
);
4793 if ( which
== wxIMAGE_LIST_NORMAL
)
4794 m_ownsImageListNormal
= TRUE
;
4795 else if ( which
== wxIMAGE_LIST_SMALL
)
4796 m_ownsImageListSmall
= TRUE
;
4797 else if ( which
== wxIMAGE_LIST_STATE
)
4798 m_ownsImageListState
= TRUE
;
4801 bool wxListCtrl::Arrange( int WXUNUSED(flag
) )
4806 bool wxListCtrl::DeleteItem( long item
)
4808 m_mainWin
->DeleteItem( item
);
4812 bool wxListCtrl::DeleteAllItems()
4814 m_mainWin
->DeleteAllItems();
4818 bool wxListCtrl::DeleteAllColumns()
4820 size_t count
= m_mainWin
->m_columns
.GetCount();
4821 for ( size_t n
= 0; n
< count
; n
++ )
4827 void wxListCtrl::ClearAll()
4829 m_mainWin
->DeleteEverything();
4832 bool wxListCtrl::DeleteColumn( int col
)
4834 m_mainWin
->DeleteColumn( col
);
4838 void wxListCtrl::Edit( long item
)
4840 m_mainWin
->EditLabel( item
);
4843 bool wxListCtrl::EnsureVisible( long item
)
4845 m_mainWin
->EnsureVisible( item
);
4849 long wxListCtrl::FindItem( long start
, const wxString
& str
, bool partial
)
4851 return m_mainWin
->FindItem( start
, str
, partial
);
4854 long wxListCtrl::FindItem( long start
, long data
)
4856 return m_mainWin
->FindItem( start
, data
);
4859 long wxListCtrl::FindItem( long WXUNUSED(start
), const wxPoint
& WXUNUSED(pt
),
4860 int WXUNUSED(direction
))
4865 long wxListCtrl::HitTest( const wxPoint
&point
, int &flags
)
4867 return m_mainWin
->HitTest( (int)point
.x
, (int)point
.y
, flags
);
4870 long wxListCtrl::InsertItem( wxListItem
& info
)
4872 m_mainWin
->InsertItem( info
);
4873 return info
.m_itemId
;
4876 long wxListCtrl::InsertItem( long index
, const wxString
&label
)
4879 info
.m_text
= label
;
4880 info
.m_mask
= wxLIST_MASK_TEXT
;
4881 info
.m_itemId
= index
;
4882 return InsertItem( info
);
4885 long wxListCtrl::InsertItem( long index
, int imageIndex
)
4888 info
.m_mask
= wxLIST_MASK_IMAGE
;
4889 info
.m_image
= imageIndex
;
4890 info
.m_itemId
= index
;
4891 return InsertItem( info
);
4894 long wxListCtrl::InsertItem( long index
, const wxString
&label
, int imageIndex
)
4897 info
.m_text
= label
;
4898 info
.m_image
= imageIndex
;
4899 info
.m_mask
= wxLIST_MASK_TEXT
| wxLIST_MASK_IMAGE
;
4900 info
.m_itemId
= index
;
4901 return InsertItem( info
);
4904 long wxListCtrl::InsertColumn( long col
, wxListItem
&item
)
4906 wxASSERT( m_headerWin
);
4907 m_mainWin
->InsertColumn( col
, item
);
4908 m_headerWin
->Refresh();
4913 long wxListCtrl::InsertColumn( long col
, const wxString
&heading
,
4914 int format
, int width
)
4917 item
.m_mask
= wxLIST_MASK_TEXT
| wxLIST_MASK_FORMAT
;
4918 item
.m_text
= heading
;
4921 item
.m_mask
|= wxLIST_MASK_WIDTH
;
4922 item
.m_width
= width
;
4924 item
.m_format
= format
;
4926 return InsertColumn( col
, item
);
4929 bool wxListCtrl::ScrollList( int WXUNUSED(dx
), int WXUNUSED(dy
) )
4935 // fn is a function which takes 3 long arguments: item1, item2, data.
4936 // item1 is the long data associated with a first item (NOT the index).
4937 // item2 is the long data associated with a second item (NOT the index).
4938 // data is the same value as passed to SortItems.
4939 // The return value is a negative number if the first item should precede the second
4940 // item, a positive number of the second item should precede the first,
4941 // or zero if the two items are equivalent.
4942 // data is arbitrary data to be passed to the sort function.
4944 bool wxListCtrl::SortItems( wxListCtrlCompare fn
, long data
)
4946 m_mainWin
->SortItems( fn
, data
);
4950 // ----------------------------------------------------------------------------
4952 // ----------------------------------------------------------------------------
4954 void wxListCtrl::OnSize(wxSizeEvent
& event
)
4959 ResizeReportView(m_mainWin
->HasHeader());
4961 m_mainWin
->RecalculatePositions();
4964 void wxListCtrl::ResizeReportView(bool showHeader
)
4967 GetClientSize( &cw
, &ch
);
4971 m_headerWin
->SetSize( 0, 0, cw
, HEADER_HEIGHT
);
4972 m_mainWin
->SetSize( 0, HEADER_HEIGHT
+ 1, cw
, ch
- HEADER_HEIGHT
- 1 );
4974 else // no header window
4976 m_mainWin
->SetSize( 0, 0, cw
, ch
);
4980 void wxListCtrl::OnIdle( wxIdleEvent
& event
)
4984 // do it only if needed
4985 if ( !m_mainWin
->m_dirty
)
4988 m_mainWin
->RecalculatePositions();
4991 // ----------------------------------------------------------------------------
4993 // ----------------------------------------------------------------------------
4995 bool wxListCtrl::SetBackgroundColour( const wxColour
&colour
)
4999 m_mainWin
->SetBackgroundColour( colour
);
5000 m_mainWin
->m_dirty
= TRUE
;
5006 bool wxListCtrl::SetForegroundColour( const wxColour
&colour
)
5008 if ( !wxWindow::SetForegroundColour( colour
) )
5013 m_mainWin
->SetForegroundColour( colour
);
5014 m_mainWin
->m_dirty
= TRUE
;
5019 m_headerWin
->SetForegroundColour( colour
);
5025 bool wxListCtrl::SetFont( const wxFont
&font
)
5027 if ( !wxWindow::SetFont( font
) )
5032 m_mainWin
->SetFont( font
);
5033 m_mainWin
->m_dirty
= TRUE
;
5038 m_headerWin
->SetFont( font
);
5044 // ----------------------------------------------------------------------------
5045 // methods forwarded to m_mainWin
5046 // ----------------------------------------------------------------------------
5048 #if wxUSE_DRAG_AND_DROP
5050 void wxListCtrl::SetDropTarget( wxDropTarget
*dropTarget
)
5052 m_mainWin
->SetDropTarget( dropTarget
);
5055 wxDropTarget
*wxListCtrl::GetDropTarget() const
5057 return m_mainWin
->GetDropTarget();
5060 #endif // wxUSE_DRAG_AND_DROP
5062 bool wxListCtrl::SetCursor( const wxCursor
&cursor
)
5064 return m_mainWin
? m_mainWin
->wxWindow::SetCursor(cursor
) : FALSE
;
5067 wxColour
wxListCtrl::GetBackgroundColour() const
5069 return m_mainWin
? m_mainWin
->GetBackgroundColour() : wxColour();
5072 wxColour
wxListCtrl::GetForegroundColour() const
5074 return m_mainWin
? m_mainWin
->GetForegroundColour() : wxColour();
5077 bool wxListCtrl::DoPopupMenu( wxMenu
*menu
, int x
, int y
)
5080 return m_mainWin
->PopupMenu( menu
, x
, y
);
5083 #endif // wxUSE_MENUS
5086 void wxListCtrl::SetFocus()
5088 /* The test in window.cpp fails as we are a composite
5089 window, so it checks against "this", but not m_mainWin. */
5090 if ( FindFocus() != this )
5091 m_mainWin
->SetFocus();
5094 // ----------------------------------------------------------------------------
5095 // virtual list control support
5096 // ----------------------------------------------------------------------------
5098 wxString
wxListCtrl::OnGetItemText(long item
, long col
) const
5100 // this is a pure virtual function, in fact - which is not really pure
5101 // because the controls which are not virtual don't need to implement it
5102 wxFAIL_MSG( _T("not supposed to be called") );
5104 return wxEmptyString
;
5107 int wxListCtrl::OnGetItemImage(long item
) const
5110 wxFAIL_MSG( _T("not supposed to be called") );
5115 wxListItemAttr
*wxListCtrl::OnGetItemAttr(long item
) const
5117 wxASSERT_MSG( item
>= 0 && item
< GetItemCount(),
5118 _T("invalid item index in OnGetItemAttr()") );
5120 // no attributes by default
5124 void wxListCtrl::SetItemCount(long count
)
5126 wxASSERT_MSG( IsVirtual(), _T("this is for virtual controls only") );
5128 m_mainWin
->SetItemCount(count
);
5131 void wxListCtrl::RefreshItem(long item
)
5133 m_mainWin
->RefreshLine(item
);
5136 void wxListCtrl::RefreshItems(long itemFrom
, long itemTo
)
5138 m_mainWin
->RefreshLines(itemFrom
, itemTo
);
5141 #endif // wxUSE_LISTCTRL