Finally corrected drawing of wxListCtrl selection rect for GTK+
[wxWidgets.git] / src / generic / listctrl.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/generic/listctrl.cpp
3 // Purpose: generic implementation of wxListCtrl
4 // Author: Robert Roebling
5 // Vadim Zeitlin (virtual list control support)
6 // Id: $Id$
7 // Copyright: (c) 1998 Robert Roebling
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
10
11 // TODO
12 //
13 // 1. we need to implement searching/sorting for virtual controls somehow
14 // 2. when changing selection the lines are refreshed twice
15
16
17 // For compilers that support precompilation, includes "wx.h".
18 #include "wx/wxprec.h"
19
20 #ifdef __BORLANDC__
21 #pragma hdrstop
22 #endif
23
24 #if wxUSE_LISTCTRL
25
26 #include "wx/listctrl.h"
27
28 #if ((!defined(__WXMSW__) && !(defined(__WXMAC__) && wxOSX_USE_CARBON)) || defined(__WXUNIVERSAL__))
29 // if we have a native version, its implementation file does all this
30 IMPLEMENT_DYNAMIC_CLASS(wxListItem, wxObject)
31 IMPLEMENT_DYNAMIC_CLASS(wxListView, wxListCtrl)
32 IMPLEMENT_DYNAMIC_CLASS(wxListEvent, wxNotifyEvent)
33
34 IMPLEMENT_DYNAMIC_CLASS(wxListCtrl, wxGenericListCtrl)
35 #endif
36
37 #ifndef WX_PRECOMP
38 #include "wx/scrolwin.h"
39 #include "wx/timer.h"
40 #include "wx/settings.h"
41 #include "wx/dynarray.h"
42 #include "wx/dcclient.h"
43 #include "wx/dcscreen.h"
44 #include "wx/math.h"
45 #include "wx/settings.h"
46 #include "wx/sizer.h"
47 #endif
48
49 #include "wx/imaglist.h"
50 #include "wx/selstore.h"
51 #include "wx/renderer.h"
52
53 #ifdef __WXMAC__
54 #include "wx/osx/private.h"
55 // for themeing support
56 #include <Carbon/Carbon.h>
57 #endif
58
59
60 // NOTE: If using the wxListBox visual attributes works everywhere then this can
61 // be removed, as well as the #else case below.
62 #define _USE_VISATTR 0
63
64
65 // ----------------------------------------------------------------------------
66 // constants
67 // ----------------------------------------------------------------------------
68
69 // // the height of the header window (FIXME: should depend on its font!)
70 // static const int HEADER_HEIGHT = 23;
71
72 static const int SCROLL_UNIT_X = 15;
73
74 // the spacing between the lines (in report mode)
75 static const int LINE_SPACING = 0;
76
77 // extra margins around the text label
78 #ifdef __WXGTK__
79 static const int EXTRA_WIDTH = 6;
80 #else
81 static const int EXTRA_WIDTH = 4;
82 #endif
83
84 #ifdef __WXGTK__
85 static const int EXTRA_HEIGHT = 6;
86 #else
87 static const int EXTRA_HEIGHT = 4;
88 #endif
89
90 // margin between the window and the items
91 static const int EXTRA_BORDER_X = 2;
92 static const int EXTRA_BORDER_Y = 2;
93
94 // offset for the header window
95 static const int HEADER_OFFSET_X = 0;
96 static const int HEADER_OFFSET_Y = 0;
97
98 // margin between rows of icons in [small] icon view
99 static const int MARGIN_BETWEEN_ROWS = 6;
100
101 // when autosizing the columns, add some slack
102 static const int AUTOSIZE_COL_MARGIN = 10;
103
104 // default width for the header columns
105 static const int WIDTH_COL_DEFAULT = 80;
106
107 // the space between the image and the text in the report mode
108 static const int IMAGE_MARGIN_IN_REPORT_MODE = 5;
109
110 // the space between the image and the text in the report mode in header
111 static const int HEADER_IMAGE_MARGIN_IN_REPORT_MODE = 2;
112
113 // ============================================================================
114 // private classes
115 // ============================================================================
116
117 //-----------------------------------------------------------------------------
118 // wxColWidthInfo (internal)
119 //-----------------------------------------------------------------------------
120
121 struct wxColWidthInfo
122 {
123 int nMaxWidth;
124 bool bNeedsUpdate; // only set to true when an item whose
125 // width == nMaxWidth is removed
126
127 wxColWidthInfo(int w = 0, bool needsUpdate = false)
128 {
129 nMaxWidth = w;
130 bNeedsUpdate = needsUpdate;
131 }
132 };
133
134 WX_DEFINE_ARRAY_PTR(wxColWidthInfo *, ColWidthArray);
135
136 //-----------------------------------------------------------------------------
137 // wxListItemData (internal)
138 //-----------------------------------------------------------------------------
139
140 class wxListItemData
141 {
142 public:
143 wxListItemData(wxListMainWindow *owner);
144 ~wxListItemData();
145
146 void SetItem( const wxListItem &info );
147 void SetImage( int image ) { m_image = image; }
148 void SetData( wxUIntPtr data ) { m_data = data; }
149 void SetPosition( int x, int y );
150 void SetSize( int width, int height );
151
152 bool HasText() const { return !m_text.empty(); }
153 const wxString& GetText() const { return m_text; }
154 void SetText(const wxString& text) { m_text = text; }
155
156 // we can't use empty string for measuring the string width/height, so
157 // always return something
158 wxString GetTextForMeasuring() const
159 {
160 wxString s = GetText();
161 if ( s.empty() )
162 s = _T('H');
163
164 return s;
165 }
166
167 bool IsHit( int x, int y ) const;
168
169 int GetX() const;
170 int GetY() const;
171 int GetWidth() const;
172 int GetHeight() const;
173
174 int GetImage() const { return m_image; }
175 bool HasImage() const { return GetImage() != -1; }
176
177 void GetItem( wxListItem &info ) const;
178
179 void SetAttr(wxListItemAttr *attr) { m_attr = attr; }
180 wxListItemAttr *GetAttr() const { return m_attr; }
181
182 public:
183 // the item image or -1
184 int m_image;
185
186 // user data associated with the item
187 wxUIntPtr m_data;
188
189 // the item coordinates are not used in report mode; instead this pointer is
190 // NULL and the owner window is used to retrieve the item position and size
191 wxRect *m_rect;
192
193 // the list ctrl we are in
194 wxListMainWindow *m_owner;
195
196 // custom attributes or NULL
197 wxListItemAttr *m_attr;
198
199 protected:
200 // common part of all ctors
201 void Init();
202
203 wxString m_text;
204 };
205
206 //-----------------------------------------------------------------------------
207 // wxListHeaderData (internal)
208 //-----------------------------------------------------------------------------
209
210 class wxListHeaderData : public wxObject
211 {
212 public:
213 wxListHeaderData();
214 wxListHeaderData( const wxListItem &info );
215 void SetItem( const wxListItem &item );
216 void SetPosition( int x, int y );
217 void SetWidth( int w );
218 void SetState( int state );
219 void SetFormat( int format );
220 void SetHeight( int h );
221 bool HasImage() const;
222
223 bool HasText() const { return !m_text.empty(); }
224 const wxString& GetText() const { return m_text; }
225 void SetText(const wxString& text) { m_text = text; }
226
227 void GetItem( wxListItem &item );
228
229 bool IsHit( int x, int y ) const;
230 int GetImage() const;
231 int GetWidth() const;
232 int GetFormat() const;
233 int GetState() const;
234
235 protected:
236 long m_mask;
237 int m_image;
238 wxString m_text;
239 int m_format;
240 int m_width;
241 int m_xpos,
242 m_ypos;
243 int m_height;
244 int m_state;
245
246 private:
247 void Init();
248 };
249
250 //-----------------------------------------------------------------------------
251 // wxListLineData (internal)
252 //-----------------------------------------------------------------------------
253
254 WX_DECLARE_LIST(wxListItemData, wxListItemDataList);
255 #include "wx/listimpl.cpp"
256 WX_DEFINE_LIST(wxListItemDataList)
257
258 class wxListLineData
259 {
260 public:
261 // the list of subitems: only may have more than one item in report mode
262 wxListItemDataList m_items;
263
264 // this is not used in report view
265 struct GeometryInfo
266 {
267 // total item rect
268 wxRect m_rectAll;
269
270 // label only
271 wxRect m_rectLabel;
272
273 // icon only
274 wxRect m_rectIcon;
275
276 // the part to be highlighted
277 wxRect m_rectHighlight;
278
279 // extend all our rects to be centered inside the one of given width
280 void ExtendWidth(wxCoord w)
281 {
282 wxASSERT_MSG( m_rectAll.width <= w,
283 _T("width can only be increased") );
284
285 m_rectAll.width = w;
286 m_rectLabel.x = m_rectAll.x + (w - m_rectLabel.width) / 2;
287 m_rectIcon.x = m_rectAll.x + (w - m_rectIcon.width) / 2;
288 m_rectHighlight.x = m_rectAll.x + (w - m_rectHighlight.width) / 2;
289 }
290 }
291 *m_gi;
292
293 // is this item selected? [NB: not used in virtual mode]
294 bool m_highlighted;
295
296 // back pointer to the list ctrl
297 wxListMainWindow *m_owner;
298
299 public:
300 wxListLineData(wxListMainWindow *owner);
301
302 ~wxListLineData()
303 {
304 WX_CLEAR_LIST(wxListItemDataList, m_items);
305 delete m_gi;
306 }
307
308 // are we in report mode?
309 inline bool InReportView() const;
310
311 // are we in virtual report mode?
312 inline bool IsVirtual() const;
313
314 // these 2 methods shouldn't be called for report view controls, in that
315 // case we determine our position/size ourselves
316
317 // calculate the size of the line
318 void CalculateSize( wxDC *dc, int spacing );
319
320 // remember the position this line appears at
321 void SetPosition( int x, int y, int spacing );
322
323 // wxListCtrl API
324
325 void SetImage( int image ) { SetImage(0, image); }
326 int GetImage() const { return GetImage(0); }
327 void SetImage( int index, int image );
328 int GetImage( int index ) const;
329
330 bool HasImage() const { return GetImage() != -1; }
331 bool HasText() const { return !GetText(0).empty(); }
332
333 void SetItem( int index, const wxListItem &info );
334 void GetItem( int index, wxListItem &info );
335
336 wxString GetText(int index) const;
337 void SetText( int index, const wxString& s );
338
339 wxListItemAttr *GetAttr() const;
340 void SetAttr(wxListItemAttr *attr);
341
342 // return true if the highlighting really changed
343 bool Highlight( bool on );
344
345 void ReverseHighlight();
346
347 bool IsHighlighted() const
348 {
349 wxASSERT_MSG( !IsVirtual(), _T("unexpected call to IsHighlighted") );
350
351 return m_highlighted;
352 }
353
354 // draw the line on the given DC in icon/list mode
355 void Draw( wxDC *dc );
356
357 // the same in report mode
358 void DrawInReportMode( wxDC *dc,
359 const wxRect& rect,
360 const wxRect& rectHL,
361 bool highlighted,
362 bool current );
363
364 private:
365 // set the line to contain num items (only can be > 1 in report mode)
366 void InitItems( int num );
367
368 // get the mode (i.e. style) of the list control
369 inline int GetMode() const;
370
371 // prepare the DC for drawing with these item's attributes, return true if
372 // we need to draw the items background to highlight it, false otherwise
373 bool SetAttributes(wxDC *dc,
374 const wxListItemAttr *attr,
375 bool highlight);
376
377 // draw the text on the DC with the correct justification; also add an
378 // ellipsis if the text is too large to fit in the current width
379 void DrawTextFormatted(wxDC *dc,
380 const wxString &text,
381 int col,
382 int x,
383 int yMid, // this is middle, not top, of the text
384 int width);
385 };
386
387 WX_DECLARE_OBJARRAY(wxListLineData, wxListLineDataArray);
388 #include "wx/arrimpl.cpp"
389 WX_DEFINE_OBJARRAY(wxListLineDataArray)
390
391 //-----------------------------------------------------------------------------
392 // wxListHeaderWindow (internal)
393 //-----------------------------------------------------------------------------
394
395 class wxListHeaderWindow : public wxWindow
396 {
397 protected:
398 wxListMainWindow *m_owner;
399 const wxCursor *m_currentCursor;
400 wxCursor *m_resizeCursor;
401 bool m_isDragging;
402
403 // column being resized or -1
404 int m_column;
405
406 // divider line position in logical (unscrolled) coords
407 int m_currentX;
408
409 // minimal position beyond which the divider line
410 // can't be dragged in logical coords
411 int m_minX;
412
413 public:
414 wxListHeaderWindow();
415
416 wxListHeaderWindow( wxWindow *win,
417 wxWindowID id,
418 wxListMainWindow *owner,
419 const wxPoint &pos = wxDefaultPosition,
420 const wxSize &size = wxDefaultSize,
421 long style = 0,
422 const wxString &name = wxT("wxlistctrlcolumntitles") );
423
424 virtual ~wxListHeaderWindow();
425
426 void DrawCurrent();
427 void AdjustDC( wxDC& dc );
428
429 void OnPaint( wxPaintEvent &event );
430 void OnMouse( wxMouseEvent &event );
431 void OnSetFocus( wxFocusEvent &event );
432
433 // needs refresh
434 bool m_dirty;
435
436 // Update main window's column later
437 bool m_sendSetColumnWidth;
438 int m_colToSend;
439 int m_widthToSend;
440
441 virtual void OnInternalIdle();
442
443 private:
444 // common part of all ctors
445 void Init();
446
447 // generate and process the list event of the given type, return true if
448 // it wasn't vetoed, i.e. if we should proceed
449 bool SendListEvent(wxEventType type, const wxPoint& pos);
450
451 DECLARE_EVENT_TABLE()
452 };
453
454 //-----------------------------------------------------------------------------
455 // wxListRenameTimer (internal)
456 //-----------------------------------------------------------------------------
457
458 class wxListRenameTimer: public wxTimer
459 {
460 private:
461 wxListMainWindow *m_owner;
462
463 public:
464 wxListRenameTimer( wxListMainWindow *owner );
465 void Notify();
466 };
467
468 //-----------------------------------------------------------------------------
469 // wxListTextCtrlWrapper: wraps a wxTextCtrl to make it work for inline editing
470 //-----------------------------------------------------------------------------
471
472 class wxListTextCtrlWrapper : public wxEvtHandler
473 {
474 public:
475 // NB: text must be a valid object but not Create()d yet
476 wxListTextCtrlWrapper(wxListMainWindow *owner,
477 wxTextCtrl *text,
478 size_t itemEdit);
479
480 wxTextCtrl *GetText() const { return m_text; }
481
482 void EndEdit( bool discardChanges );
483
484 protected:
485 void OnChar( wxKeyEvent &event );
486 void OnKeyUp( wxKeyEvent &event );
487 void OnKillFocus( wxFocusEvent &event );
488
489 bool AcceptChanges();
490 void Finish( bool setfocus );
491
492 private:
493 wxListMainWindow *m_owner;
494 wxTextCtrl *m_text;
495 wxString m_startValue;
496 size_t m_itemEdited;
497 bool m_aboutToFinish;
498
499 DECLARE_EVENT_TABLE()
500 };
501
502 //-----------------------------------------------------------------------------
503 // wxListMainWindow (internal)
504 //-----------------------------------------------------------------------------
505
506 WX_DECLARE_LIST(wxListHeaderData, wxListHeaderDataList);
507 #include "wx/listimpl.cpp"
508 WX_DEFINE_LIST(wxListHeaderDataList)
509
510 class wxListMainWindow : public wxWindow
511 {
512 public:
513 wxListMainWindow();
514 wxListMainWindow( wxWindow *parent,
515 wxWindowID id,
516 const wxPoint& pos = wxDefaultPosition,
517 const wxSize& size = wxDefaultSize,
518 long style = 0,
519 const wxString &name = _T("listctrlmainwindow") );
520
521 virtual ~wxListMainWindow();
522
523 bool HasFlag(int flag) const { return m_parent->HasFlag(flag); }
524
525 // return true if this is a virtual list control
526 bool IsVirtual() const { return HasFlag(wxLC_VIRTUAL); }
527
528 // return true if the control is in report mode
529 bool InReportView() const { return HasFlag(wxLC_REPORT); }
530
531 // return true if we are in single selection mode, false if multi sel
532 bool IsSingleSel() const { return HasFlag(wxLC_SINGLE_SEL); }
533
534 // do we have a header window?
535 bool HasHeader() const
536 { return InReportView() && !HasFlag(wxLC_NO_HEADER); }
537
538 void HighlightAll( bool on );
539
540 // all these functions only do something if the line is currently visible
541
542 // change the line "selected" state, return true if it really changed
543 bool HighlightLine( size_t line, bool highlight = true);
544
545 // as HighlightLine() but do it for the range of lines: this is incredibly
546 // more efficient for virtual list controls!
547 //
548 // NB: unlike HighlightLine() this one does refresh the lines on screen
549 void HighlightLines( size_t lineFrom, size_t lineTo, bool on = true );
550
551 // toggle the line state and refresh it
552 void ReverseHighlight( size_t line )
553 { HighlightLine(line, !IsHighlighted(line)); RefreshLine(line); }
554
555 // return true if the line is highlighted
556 bool IsHighlighted(size_t line) const;
557
558 // refresh one or several lines at once
559 void RefreshLine( size_t line );
560 void RefreshLines( size_t lineFrom, size_t lineTo );
561
562 // refresh all selected items
563 void RefreshSelected();
564
565 // refresh all lines below the given one: the difference with
566 // RefreshLines() is that the index here might not be a valid one (happens
567 // when the last line is deleted)
568 void RefreshAfter( size_t lineFrom );
569
570 // the methods which are forwarded to wxListLineData itself in list/icon
571 // modes but are here because the lines don't store their positions in the
572 // report mode
573
574 // get the bound rect for the entire line
575 wxRect GetLineRect(size_t line) const;
576
577 // get the bound rect of the label
578 wxRect GetLineLabelRect(size_t line) const;
579
580 // get the bound rect of the items icon (only may be called if we do have
581 // an icon!)
582 wxRect GetLineIconRect(size_t line) const;
583
584 // get the rect to be highlighted when the item has focus
585 wxRect GetLineHighlightRect(size_t line) const;
586
587 // get the size of the total line rect
588 wxSize GetLineSize(size_t line) const
589 { return GetLineRect(line).GetSize(); }
590
591 // return the hit code for the corresponding position (in this line)
592 long HitTestLine(size_t line, int x, int y) const;
593
594 // bring the selected item into view, scrolling to it if necessary
595 void MoveToItem(size_t item);
596
597 bool ScrollList( int WXUNUSED(dx), int dy );
598
599 // bring the current item into view
600 void MoveToFocus() { MoveToItem(m_current); }
601
602 // start editing the label of the given item
603 wxTextCtrl *EditLabel(long item,
604 wxClassInfo* textControlClass = CLASSINFO(wxTextCtrl));
605 wxTextCtrl *GetEditControl() const
606 {
607 return m_textctrlWrapper ? m_textctrlWrapper->GetText() : NULL;
608 }
609
610 void ResetTextControl(wxTextCtrl *text)
611 {
612 delete text;
613 m_textctrlWrapper = NULL;
614 }
615
616 void OnRenameTimer();
617 bool OnRenameAccept(size_t itemEdit, const wxString& value);
618 void OnRenameCancelled(size_t itemEdit);
619
620 void OnMouse( wxMouseEvent &event );
621
622 // called to switch the selection from the current item to newCurrent,
623 void OnArrowChar( size_t newCurrent, const wxKeyEvent& event );
624
625 void OnChar( wxKeyEvent &event );
626 void OnKeyDown( wxKeyEvent &event );
627 void OnKeyUp( wxKeyEvent &event );
628 void OnSetFocus( wxFocusEvent &event );
629 void OnKillFocus( wxFocusEvent &event );
630 void OnScroll( wxScrollWinEvent& event );
631
632 void OnPaint( wxPaintEvent &event );
633
634 void OnChildFocus(wxChildFocusEvent& event);
635
636 void DrawImage( int index, wxDC *dc, int x, int y );
637 void GetImageSize( int index, int &width, int &height ) const;
638 int GetTextLength( const wxString &s ) const;
639
640 void SetImageList( wxImageList *imageList, int which );
641 void SetItemSpacing( int spacing, bool isSmall = false );
642 int GetItemSpacing( bool isSmall = false );
643
644 void SetColumn( int col, wxListItem &item );
645 void SetColumnWidth( int col, int width );
646 void GetColumn( int col, wxListItem &item ) const;
647 int GetColumnWidth( int col ) const;
648 int GetColumnCount() const { return m_columns.GetCount(); }
649
650 // returns the sum of the heights of all columns
651 int GetHeaderWidth() const;
652
653 int GetCountPerPage() const;
654
655 void SetItem( wxListItem &item );
656 void GetItem( wxListItem &item ) const;
657 void SetItemState( long item, long state, long stateMask );
658 void SetItemStateAll( long state, long stateMask );
659 int GetItemState( long item, long stateMask ) const;
660 bool GetItemRect( long item, wxRect &rect ) const
661 {
662 return GetSubItemRect(item, wxLIST_GETSUBITEMRECT_WHOLEITEM, rect);
663 }
664 bool GetSubItemRect( long item, long subItem, wxRect& rect ) const;
665 wxRect GetViewRect() const;
666 bool GetItemPosition( long item, wxPoint& pos ) const;
667 int GetSelectedItemCount() const;
668
669 wxString GetItemText(long item) const
670 {
671 wxListItem info;
672 info.m_mask = wxLIST_MASK_TEXT;
673 info.m_itemId = item;
674 GetItem( info );
675 return info.m_text;
676 }
677
678 void SetItemText(long item, const wxString& value)
679 {
680 wxListItem info;
681 info.m_mask = wxLIST_MASK_TEXT;
682 info.m_itemId = item;
683 info.m_text = value;
684 SetItem( info );
685 }
686
687 // set the scrollbars and update the positions of the items
688 void RecalculatePositions(bool noRefresh = false);
689
690 // refresh the window and the header
691 void RefreshAll();
692
693 long GetNextItem( long item, int geometry, int state ) const;
694 void DeleteItem( long index );
695 void DeleteAllItems();
696 void DeleteColumn( int col );
697 void DeleteEverything();
698 void EnsureVisible( long index );
699 long FindItem( long start, const wxString& str, bool partial = false );
700 long FindItem( long start, wxUIntPtr data);
701 long FindItem( const wxPoint& pt );
702 long HitTest( int x, int y, int &flags ) const;
703 void InsertItem( wxListItem &item );
704 void InsertColumn( long col, wxListItem &item );
705 int GetItemWidthWithImage(wxListItem * item);
706 void SortItems( wxListCtrlCompare fn, long data );
707
708 size_t GetItemCount() const;
709 bool IsEmpty() const { return GetItemCount() == 0; }
710 void SetItemCount(long count);
711
712 // change the current (== focused) item, send a notification event
713 void ChangeCurrent(size_t current);
714 void ResetCurrent() { ChangeCurrent((size_t)-1); }
715 bool HasCurrent() const { return m_current != (size_t)-1; }
716
717 // send out a wxListEvent
718 void SendNotify( size_t line,
719 wxEventType command,
720 const wxPoint& point = wxDefaultPosition );
721
722 // override base class virtual to reset m_lineHeight when the font changes
723 virtual bool SetFont(const wxFont& font)
724 {
725 if ( !wxWindow::SetFont(font) )
726 return false;
727
728 m_lineHeight = 0;
729
730 return true;
731 }
732
733 // these are for wxListLineData usage only
734
735 // get the backpointer to the list ctrl
736 wxGenericListCtrl *GetListCtrl() const
737 {
738 return wxStaticCast(GetParent(), wxGenericListCtrl);
739 }
740
741 // get the height of all lines (assuming they all do have the same height)
742 wxCoord GetLineHeight() const;
743
744 // get the y position of the given line (only for report view)
745 wxCoord GetLineY(size_t line) const;
746
747 // get the brush to use for the item highlighting
748 wxBrush *GetHighlightBrush() const
749 {
750 return m_hasFocus ? m_highlightBrush : m_highlightUnfocusedBrush;
751 }
752
753 bool HasFocus() const
754 {
755 return m_hasFocus;
756 }
757
758 //protected:
759 // the array of all line objects for a non virtual list control (for the
760 // virtual list control we only ever use m_lines[0])
761 wxListLineDataArray m_lines;
762
763 // the list of column objects
764 wxListHeaderDataList m_columns;
765
766 // currently focused item or -1
767 size_t m_current;
768
769 // the number of lines per page
770 int m_linesPerPage;
771
772 // this flag is set when something which should result in the window
773 // redrawing happens (i.e. an item was added or deleted, or its appearance
774 // changed) and OnPaint() doesn't redraw the window while it is set which
775 // allows to minimize the number of repaintings when a lot of items are
776 // being added. The real repainting occurs only after the next OnIdle()
777 // call
778 bool m_dirty;
779
780 wxColour *m_highlightColour;
781 wxImageList *m_small_image_list;
782 wxImageList *m_normal_image_list;
783 int m_small_spacing;
784 int m_normal_spacing;
785 bool m_hasFocus;
786
787 bool m_lastOnSame;
788 wxTimer *m_renameTimer;
789 bool m_isCreated;
790 int m_dragCount;
791 wxPoint m_dragStart;
792 ColWidthArray m_aColWidths;
793
794 // for double click logic
795 size_t m_lineLastClicked,
796 m_lineBeforeLastClicked,
797 m_lineSelectSingleOnUp;
798
799 protected:
800 wxWindow *GetMainWindowOfCompositeControl() { return GetParent(); }
801
802 // the total count of items in a virtual list control
803 size_t m_countVirt;
804
805 // the object maintaining the items selection state, only used in virtual
806 // controls
807 wxSelectionStore m_selStore;
808
809 // common part of all ctors
810 void Init();
811
812 // get the line data for the given index
813 wxListLineData *GetLine(size_t n) const
814 {
815 wxASSERT_MSG( n != (size_t)-1, _T("invalid line index") );
816
817 if ( IsVirtual() )
818 {
819 wxConstCast(this, wxListMainWindow)->CacheLineData(n);
820 n = 0;
821 }
822
823 return &m_lines[n];
824 }
825
826 // get a dummy line which can be used for geometry calculations and such:
827 // you must use GetLine() if you want to really draw the line
828 wxListLineData *GetDummyLine() const;
829
830 // cache the line data of the n-th line in m_lines[0]
831 void CacheLineData(size_t line);
832
833 // get the range of visible lines
834 void GetVisibleLinesRange(size_t *from, size_t *to);
835
836 // force us to recalculate the range of visible lines
837 void ResetVisibleLinesRange() { m_lineFrom = (size_t)-1; }
838
839 // get the colour to be used for drawing the rules
840 wxColour GetRuleColour() const
841 {
842 return wxSystemSettings::GetColour(wxSYS_COLOUR_3DLIGHT);
843 }
844
845 private:
846 // initialize the current item if needed
847 void UpdateCurrent();
848
849 // delete all items but don't refresh: called from dtor
850 void DoDeleteAllItems();
851
852 // the height of one line using the current font
853 wxCoord m_lineHeight;
854
855 // the total header width or 0 if not calculated yet
856 wxCoord m_headerWidth;
857
858 // the first and last lines being shown on screen right now (inclusive),
859 // both may be -1 if they must be calculated so never access them directly:
860 // use GetVisibleLinesRange() above instead
861 size_t m_lineFrom,
862 m_lineTo;
863
864 // the brushes to use for item highlighting when we do/don't have focus
865 wxBrush *m_highlightBrush,
866 *m_highlightUnfocusedBrush;
867
868 // wrapper around the text control currently used for in place editing or
869 // NULL if no item is being edited
870 wxListTextCtrlWrapper *m_textctrlWrapper;
871
872
873 DECLARE_EVENT_TABLE()
874
875 friend class wxGenericListCtrl;
876 };
877
878
879 wxListItemData::~wxListItemData()
880 {
881 // in the virtual list control the attributes are managed by the main
882 // program, so don't delete them
883 if ( !m_owner->IsVirtual() )
884 delete m_attr;
885
886 delete m_rect;
887 }
888
889 void wxListItemData::Init()
890 {
891 m_image = -1;
892 m_data = 0;
893
894 m_attr = NULL;
895 }
896
897 wxListItemData::wxListItemData(wxListMainWindow *owner)
898 {
899 Init();
900
901 m_owner = owner;
902
903 if ( owner->InReportView() )
904 m_rect = NULL;
905 else
906 m_rect = new wxRect;
907 }
908
909 void wxListItemData::SetItem( const wxListItem &info )
910 {
911 if ( info.m_mask & wxLIST_MASK_TEXT )
912 SetText(info.m_text);
913 if ( info.m_mask & wxLIST_MASK_IMAGE )
914 m_image = info.m_image;
915 if ( info.m_mask & wxLIST_MASK_DATA )
916 m_data = info.m_data;
917
918 if ( info.HasAttributes() )
919 {
920 if ( m_attr )
921 m_attr->AssignFrom(*info.GetAttributes());
922 else
923 m_attr = new wxListItemAttr(*info.GetAttributes());
924 }
925
926 if ( m_rect )
927 {
928 m_rect->x =
929 m_rect->y =
930 m_rect->height = 0;
931 m_rect->width = info.m_width;
932 }
933 }
934
935 void wxListItemData::SetPosition( int x, int y )
936 {
937 wxCHECK_RET( m_rect, _T("unexpected SetPosition() call") );
938
939 m_rect->x = x;
940 m_rect->y = y;
941 }
942
943 void wxListItemData::SetSize( int width, int height )
944 {
945 wxCHECK_RET( m_rect, _T("unexpected SetSize() call") );
946
947 if ( width != -1 )
948 m_rect->width = width;
949 if ( height != -1 )
950 m_rect->height = height;
951 }
952
953 bool wxListItemData::IsHit( int x, int y ) const
954 {
955 wxCHECK_MSG( m_rect, false, _T("can't be called in this mode") );
956
957 return wxRect(GetX(), GetY(), GetWidth(), GetHeight()).Contains(x, y);
958 }
959
960 int wxListItemData::GetX() const
961 {
962 wxCHECK_MSG( m_rect, 0, _T("can't be called in this mode") );
963
964 return m_rect->x;
965 }
966
967 int wxListItemData::GetY() const
968 {
969 wxCHECK_MSG( m_rect, 0, _T("can't be called in this mode") );
970
971 return m_rect->y;
972 }
973
974 int wxListItemData::GetWidth() const
975 {
976 wxCHECK_MSG( m_rect, 0, _T("can't be called in this mode") );
977
978 return m_rect->width;
979 }
980
981 int wxListItemData::GetHeight() const
982 {
983 wxCHECK_MSG( m_rect, 0, _T("can't be called in this mode") );
984
985 return m_rect->height;
986 }
987
988 void wxListItemData::GetItem( wxListItem &info ) const
989 {
990 long mask = info.m_mask;
991 if ( !mask )
992 // by default, get everything for backwards compatibility
993 mask = -1;
994
995 if ( mask & wxLIST_MASK_TEXT )
996 info.m_text = m_text;
997 if ( mask & wxLIST_MASK_IMAGE )
998 info.m_image = m_image;
999 if ( mask & wxLIST_MASK_DATA )
1000 info.m_data = m_data;
1001
1002 if ( m_attr )
1003 {
1004 if ( m_attr->HasTextColour() )
1005 info.SetTextColour(m_attr->GetTextColour());
1006 if ( m_attr->HasBackgroundColour() )
1007 info.SetBackgroundColour(m_attr->GetBackgroundColour());
1008 if ( m_attr->HasFont() )
1009 info.SetFont(m_attr->GetFont());
1010 }
1011 }
1012
1013 //-----------------------------------------------------------------------------
1014 // wxListHeaderData
1015 //-----------------------------------------------------------------------------
1016
1017 void wxListHeaderData::Init()
1018 {
1019 m_mask = 0;
1020 m_image = -1;
1021 m_format = 0;
1022 m_width = 0;
1023 m_xpos = 0;
1024 m_ypos = 0;
1025 m_height = 0;
1026 m_state = 0;
1027 }
1028
1029 wxListHeaderData::wxListHeaderData()
1030 {
1031 Init();
1032 }
1033
1034 wxListHeaderData::wxListHeaderData( const wxListItem &item )
1035 {
1036 Init();
1037
1038 SetItem( item );
1039 }
1040
1041 void wxListHeaderData::SetItem( const wxListItem &item )
1042 {
1043 m_mask = item.m_mask;
1044
1045 if ( m_mask & wxLIST_MASK_TEXT )
1046 m_text = item.m_text;
1047
1048 if ( m_mask & wxLIST_MASK_IMAGE )
1049 m_image = item.m_image;
1050
1051 if ( m_mask & wxLIST_MASK_FORMAT )
1052 m_format = item.m_format;
1053
1054 if ( m_mask & wxLIST_MASK_WIDTH )
1055 SetWidth(item.m_width);
1056
1057 if ( m_mask & wxLIST_MASK_STATE )
1058 SetState(item.m_state);
1059 }
1060
1061 void wxListHeaderData::SetPosition( int x, int y )
1062 {
1063 m_xpos = x;
1064 m_ypos = y;
1065 }
1066
1067 void wxListHeaderData::SetHeight( int h )
1068 {
1069 m_height = h;
1070 }
1071
1072 void wxListHeaderData::SetWidth( int w )
1073 {
1074 m_width = w < 0 ? WIDTH_COL_DEFAULT : w;
1075 }
1076
1077 void wxListHeaderData::SetState( int flag )
1078 {
1079 m_state = flag;
1080 }
1081
1082 void wxListHeaderData::SetFormat( int format )
1083 {
1084 m_format = format;
1085 }
1086
1087 bool wxListHeaderData::HasImage() const
1088 {
1089 return m_image != -1;
1090 }
1091
1092 bool wxListHeaderData::IsHit( int x, int y ) const
1093 {
1094 return ((x >= m_xpos) && (x <= m_xpos+m_width) && (y >= m_ypos) && (y <= m_ypos+m_height));
1095 }
1096
1097 void wxListHeaderData::GetItem( wxListItem& item )
1098 {
1099 item.m_mask = m_mask;
1100 item.m_text = m_text;
1101 item.m_image = m_image;
1102 item.m_format = m_format;
1103 item.m_width = m_width;
1104 item.m_state = m_state;
1105 }
1106
1107 int wxListHeaderData::GetImage() const
1108 {
1109 return m_image;
1110 }
1111
1112 int wxListHeaderData::GetWidth() const
1113 {
1114 return m_width;
1115 }
1116
1117 int wxListHeaderData::GetFormat() const
1118 {
1119 return m_format;
1120 }
1121
1122 int wxListHeaderData::GetState() const
1123 {
1124 return m_state;
1125 }
1126
1127 //-----------------------------------------------------------------------------
1128 // wxListLineData
1129 //-----------------------------------------------------------------------------
1130
1131 inline int wxListLineData::GetMode() const
1132 {
1133 return m_owner->GetListCtrl()->GetWindowStyleFlag() & wxLC_MASK_TYPE;
1134 }
1135
1136 inline bool wxListLineData::InReportView() const
1137 {
1138 return m_owner->HasFlag(wxLC_REPORT);
1139 }
1140
1141 inline bool wxListLineData::IsVirtual() const
1142 {
1143 return m_owner->IsVirtual();
1144 }
1145
1146 wxListLineData::wxListLineData( wxListMainWindow *owner )
1147 {
1148 m_owner = owner;
1149
1150 if ( InReportView() )
1151 m_gi = NULL;
1152 else // !report
1153 m_gi = new GeometryInfo;
1154
1155 m_highlighted = false;
1156
1157 InitItems( GetMode() == wxLC_REPORT ? m_owner->GetColumnCount() : 1 );
1158 }
1159
1160 void wxListLineData::CalculateSize( wxDC *dc, int spacing )
1161 {
1162 wxListItemDataList::compatibility_iterator node = m_items.GetFirst();
1163 wxCHECK_RET( node, _T("no subitems at all??") );
1164
1165 wxListItemData *item = node->GetData();
1166
1167 wxString s;
1168 wxCoord lw, lh;
1169
1170 switch ( GetMode() )
1171 {
1172 case wxLC_ICON:
1173 case wxLC_SMALL_ICON:
1174 m_gi->m_rectAll.width = spacing;
1175
1176 s = item->GetText();
1177
1178 if ( s.empty() )
1179 {
1180 lh =
1181 m_gi->m_rectLabel.width =
1182 m_gi->m_rectLabel.height = 0;
1183 }
1184 else // has label
1185 {
1186 dc->GetTextExtent( s, &lw, &lh );
1187 lw += EXTRA_WIDTH;
1188 lh += EXTRA_HEIGHT;
1189
1190 m_gi->m_rectAll.height = spacing + lh;
1191 if (lw > spacing)
1192 m_gi->m_rectAll.width = lw;
1193
1194 m_gi->m_rectLabel.width = lw;
1195 m_gi->m_rectLabel.height = lh;
1196 }
1197
1198 if (item->HasImage())
1199 {
1200 int w, h;
1201 m_owner->GetImageSize( item->GetImage(), w, h );
1202 m_gi->m_rectIcon.width = w + 8;
1203 m_gi->m_rectIcon.height = h + 8;
1204
1205 if ( m_gi->m_rectIcon.width > m_gi->m_rectAll.width )
1206 m_gi->m_rectAll.width = m_gi->m_rectIcon.width;
1207 if ( m_gi->m_rectIcon.height + lh > m_gi->m_rectAll.height - 4 )
1208 m_gi->m_rectAll.height = m_gi->m_rectIcon.height + lh + 4;
1209 }
1210
1211 if ( item->HasText() )
1212 {
1213 m_gi->m_rectHighlight.width = m_gi->m_rectLabel.width;
1214 m_gi->m_rectHighlight.height = m_gi->m_rectLabel.height;
1215 }
1216 else // no text, highlight the icon
1217 {
1218 m_gi->m_rectHighlight.width = m_gi->m_rectIcon.width;
1219 m_gi->m_rectHighlight.height = m_gi->m_rectIcon.height;
1220 }
1221 break;
1222
1223 case wxLC_LIST:
1224 s = item->GetTextForMeasuring();
1225
1226 dc->GetTextExtent( s, &lw, &lh );
1227 lw += EXTRA_WIDTH;
1228 lh += EXTRA_HEIGHT;
1229
1230 m_gi->m_rectLabel.width = lw;
1231 m_gi->m_rectLabel.height = lh;
1232
1233 m_gi->m_rectAll.width = lw;
1234 m_gi->m_rectAll.height = lh;
1235
1236 if (item->HasImage())
1237 {
1238 int w, h;
1239 m_owner->GetImageSize( item->GetImage(), w, h );
1240 m_gi->m_rectIcon.width = w;
1241 m_gi->m_rectIcon.height = h;
1242
1243 m_gi->m_rectAll.width += 4 + w;
1244 if (h > m_gi->m_rectAll.height)
1245 m_gi->m_rectAll.height = h;
1246 }
1247
1248 m_gi->m_rectHighlight.width = m_gi->m_rectAll.width;
1249 m_gi->m_rectHighlight.height = m_gi->m_rectAll.height;
1250 break;
1251
1252 case wxLC_REPORT:
1253 wxFAIL_MSG( _T("unexpected call to SetSize") );
1254 break;
1255
1256 default:
1257 wxFAIL_MSG( _T("unknown mode") );
1258 break;
1259 }
1260 }
1261
1262 void wxListLineData::SetPosition( int x, int y, int spacing )
1263 {
1264 wxListItemDataList::compatibility_iterator node = m_items.GetFirst();
1265 wxCHECK_RET( node, _T("no subitems at all??") );
1266
1267 wxListItemData *item = node->GetData();
1268
1269 switch ( GetMode() )
1270 {
1271 case wxLC_ICON:
1272 case wxLC_SMALL_ICON:
1273 m_gi->m_rectAll.x = x;
1274 m_gi->m_rectAll.y = y;
1275
1276 if ( item->HasImage() )
1277 {
1278 m_gi->m_rectIcon.x = m_gi->m_rectAll.x + 4 +
1279 (m_gi->m_rectAll.width - m_gi->m_rectIcon.width) / 2;
1280 m_gi->m_rectIcon.y = m_gi->m_rectAll.y + 4;
1281 }
1282
1283 if ( item->HasText() )
1284 {
1285 if (m_gi->m_rectAll.width > spacing)
1286 m_gi->m_rectLabel.x = m_gi->m_rectAll.x + (EXTRA_WIDTH/2);
1287 else
1288 m_gi->m_rectLabel.x = m_gi->m_rectAll.x + (EXTRA_WIDTH/2) + (spacing / 2) - (m_gi->m_rectLabel.width / 2);
1289 m_gi->m_rectLabel.y = m_gi->m_rectAll.y + m_gi->m_rectAll.height + 2 - m_gi->m_rectLabel.height;
1290 m_gi->m_rectHighlight.x = m_gi->m_rectLabel.x - 2;
1291 m_gi->m_rectHighlight.y = m_gi->m_rectLabel.y - 2;
1292 }
1293 else // no text, highlight the icon
1294 {
1295 m_gi->m_rectHighlight.x = m_gi->m_rectIcon.x - 4;
1296 m_gi->m_rectHighlight.y = m_gi->m_rectIcon.y - 4;
1297 }
1298 break;
1299
1300 case wxLC_LIST:
1301 m_gi->m_rectAll.x = x;
1302 m_gi->m_rectAll.y = y;
1303
1304 m_gi->m_rectHighlight.x = m_gi->m_rectAll.x;
1305 m_gi->m_rectHighlight.y = m_gi->m_rectAll.y;
1306 m_gi->m_rectLabel.y = m_gi->m_rectAll.y + 2;
1307
1308 if (item->HasImage())
1309 {
1310 m_gi->m_rectIcon.x = m_gi->m_rectAll.x + 2;
1311 m_gi->m_rectIcon.y = m_gi->m_rectAll.y + 2;
1312 m_gi->m_rectLabel.x = m_gi->m_rectAll.x + 4 + (EXTRA_WIDTH/2) + m_gi->m_rectIcon.width;
1313 }
1314 else
1315 {
1316 m_gi->m_rectLabel.x = m_gi->m_rectAll.x + (EXTRA_WIDTH/2);
1317 }
1318 break;
1319
1320 case wxLC_REPORT:
1321 wxFAIL_MSG( _T("unexpected call to SetPosition") );
1322 break;
1323
1324 default:
1325 wxFAIL_MSG( _T("unknown mode") );
1326 break;
1327 }
1328 }
1329
1330 void wxListLineData::InitItems( int num )
1331 {
1332 for (int i = 0; i < num; i++)
1333 m_items.Append( new wxListItemData(m_owner) );
1334 }
1335
1336 void wxListLineData::SetItem( int index, const wxListItem &info )
1337 {
1338 wxListItemDataList::compatibility_iterator node = m_items.Item( index );
1339 wxCHECK_RET( node, _T("invalid column index in SetItem") );
1340
1341 wxListItemData *item = node->GetData();
1342 item->SetItem( info );
1343 }
1344
1345 void wxListLineData::GetItem( int index, wxListItem &info )
1346 {
1347 wxListItemDataList::compatibility_iterator node = m_items.Item( index );
1348 if (node)
1349 {
1350 wxListItemData *item = node->GetData();
1351 item->GetItem( info );
1352 }
1353 }
1354
1355 wxString wxListLineData::GetText(int index) const
1356 {
1357 wxString s;
1358
1359 wxListItemDataList::compatibility_iterator node = m_items.Item( index );
1360 if (node)
1361 {
1362 wxListItemData *item = node->GetData();
1363 s = item->GetText();
1364 }
1365
1366 return s;
1367 }
1368
1369 void wxListLineData::SetText( int index, const wxString& s )
1370 {
1371 wxListItemDataList::compatibility_iterator node = m_items.Item( index );
1372 if (node)
1373 {
1374 wxListItemData *item = node->GetData();
1375 item->SetText( s );
1376 }
1377 }
1378
1379 void wxListLineData::SetImage( int index, int image )
1380 {
1381 wxListItemDataList::compatibility_iterator node = m_items.Item( index );
1382 wxCHECK_RET( node, _T("invalid column index in SetImage()") );
1383
1384 wxListItemData *item = node->GetData();
1385 item->SetImage(image);
1386 }
1387
1388 int wxListLineData::GetImage( int index ) const
1389 {
1390 wxListItemDataList::compatibility_iterator node = m_items.Item( index );
1391 wxCHECK_MSG( node, -1, _T("invalid column index in GetImage()") );
1392
1393 wxListItemData *item = node->GetData();
1394 return item->GetImage();
1395 }
1396
1397 wxListItemAttr *wxListLineData::GetAttr() const
1398 {
1399 wxListItemDataList::compatibility_iterator node = m_items.GetFirst();
1400 wxCHECK_MSG( node, NULL, _T("invalid column index in GetAttr()") );
1401
1402 wxListItemData *item = node->GetData();
1403 return item->GetAttr();
1404 }
1405
1406 void wxListLineData::SetAttr(wxListItemAttr *attr)
1407 {
1408 wxListItemDataList::compatibility_iterator node = m_items.GetFirst();
1409 wxCHECK_RET( node, _T("invalid column index in SetAttr()") );
1410
1411 wxListItemData *item = node->GetData();
1412 item->SetAttr(attr);
1413 }
1414
1415 bool wxListLineData::SetAttributes(wxDC *dc,
1416 const wxListItemAttr *attr,
1417 bool highlighted)
1418 {
1419 wxWindow *listctrl = m_owner->GetParent();
1420
1421 // fg colour
1422
1423 // don't use foreground colour for drawing highlighted items - this might
1424 // make them completely invisible (and there is no way to do bit
1425 // arithmetics on wxColour, unfortunately)
1426 wxColour colText;
1427 if ( highlighted )
1428 #ifdef __WXMAC__
1429 {
1430 if (m_owner->HasFocus()
1431 #if !defined(__WXUNIVERSAL__) && wxOSX_USE_CARBON
1432 && IsControlActive( (ControlRef)m_owner->GetHandle() )
1433 #endif
1434 )
1435 colText = *wxWHITE;
1436 else
1437 colText = *wxBLACK;
1438 }
1439 #else
1440 colText = wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHTTEXT);
1441 #endif
1442 else if ( attr && attr->HasTextColour() )
1443 colText = attr->GetTextColour();
1444 else
1445 colText = listctrl->GetForegroundColour();
1446
1447 dc->SetTextForeground(colText);
1448
1449 // font
1450 wxFont font;
1451 if ( attr && attr->HasFont() )
1452 font = attr->GetFont();
1453 else
1454 font = listctrl->GetFont();
1455
1456 dc->SetFont(font);
1457
1458 // bg colour
1459 bool hasBgCol = attr && attr->HasBackgroundColour();
1460 if ( highlighted || hasBgCol )
1461 {
1462 if ( highlighted )
1463 dc->SetBrush( *m_owner->GetHighlightBrush() );
1464 else
1465 dc->SetBrush(wxBrush(attr->GetBackgroundColour(), wxBRUSHSTYLE_SOLID));
1466
1467 dc->SetPen( *wxTRANSPARENT_PEN );
1468
1469 return true;
1470 }
1471
1472 return false;
1473 }
1474
1475 void wxListLineData::Draw( wxDC *dc )
1476 {
1477 wxListItemDataList::compatibility_iterator node = m_items.GetFirst();
1478 wxCHECK_RET( node, _T("no subitems at all??") );
1479
1480 bool highlighted = IsHighlighted();
1481
1482 wxListItemAttr *attr = GetAttr();
1483
1484 if ( SetAttributes(dc, attr, highlighted) )
1485 #if ( !defined(__WXGTK20__) && !defined(__WXMAC__) )
1486 {
1487 dc->DrawRectangle( m_gi->m_rectHighlight );
1488 }
1489 #else
1490 {
1491 if (highlighted)
1492 {
1493 int flags = wxCONTROL_SELECTED;
1494 if (m_owner->HasFocus()
1495 #if defined( __WXMAC__ ) && !defined(__WXUNIVERSAL__) && wxOSX_USE_CARBON
1496 && IsControlActive( (ControlRef)m_owner->GetHandle() )
1497 #endif
1498 )
1499 flags |= wxCONTROL_FOCUSED;
1500 wxRendererNative::Get().DrawItemSelectionRect( m_owner, *dc, m_gi->m_rectHighlight, flags );
1501
1502 }
1503 else
1504 {
1505 dc->DrawRectangle( m_gi->m_rectHighlight );
1506 }
1507 }
1508 #endif
1509
1510 // just for debugging to better see where the items are
1511 #if 0
1512 dc->SetPen(*wxRED_PEN);
1513 dc->SetBrush(*wxTRANSPARENT_BRUSH);
1514 dc->DrawRectangle( m_gi->m_rectAll );
1515 dc->SetPen(*wxGREEN_PEN);
1516 dc->DrawRectangle( m_gi->m_rectIcon );
1517 #endif
1518
1519 wxListItemData *item = node->GetData();
1520 if (item->HasImage())
1521 {
1522 // centre the image inside our rectangle, this looks nicer when items
1523 // ae aligned in a row
1524 const wxRect& rectIcon = m_gi->m_rectIcon;
1525
1526 m_owner->DrawImage(item->GetImage(), dc, rectIcon.x, rectIcon.y);
1527 }
1528
1529 if (item->HasText())
1530 {
1531 const wxRect& rectLabel = m_gi->m_rectLabel;
1532
1533 wxDCClipper clipper(*dc, rectLabel);
1534 dc->DrawText(item->GetText(), rectLabel.x, rectLabel.y);
1535 }
1536 }
1537
1538 void wxListLineData::DrawInReportMode( wxDC *dc,
1539 const wxRect& rect,
1540 const wxRect& rectHL,
1541 bool highlighted,
1542 bool current )
1543 {
1544 // TODO: later we should support setting different attributes for
1545 // different columns - to do it, just add "col" argument to
1546 // GetAttr() and move these lines into the loop below
1547 wxListItemAttr *attr = GetAttr();
1548 if ( SetAttributes(dc, attr, highlighted) )
1549 #if ( !defined(__WXGTK20__) && !defined(__WXMAC__) )
1550 {
1551 dc->DrawRectangle( rectHL );
1552 }
1553 #else
1554 {
1555 if (highlighted)
1556 {
1557 int flags = wxCONTROL_SELECTED;
1558 if (m_owner->HasFocus())
1559 flags |= wxCONTROL_FOCUSED;
1560 if (current)
1561 flags |= wxCONTROL_CURRENT;
1562 wxRendererNative::Get().DrawItemSelectionRect( m_owner, *dc, rectHL, flags );
1563 }
1564 else
1565 {
1566 dc->DrawRectangle( rectHL );
1567 }
1568 }
1569 #endif
1570
1571 wxCoord x = rect.x + HEADER_OFFSET_X,
1572 yMid = rect.y + rect.height/2;
1573 #ifdef __WXGTK__
1574 // This probably needs to be done
1575 // on all platforms as the icons
1576 // otherwise nearly touch the border
1577 x += 2;
1578 #endif
1579
1580 size_t col = 0;
1581 for ( wxListItemDataList::compatibility_iterator node = m_items.GetFirst();
1582 node;
1583 node = node->GetNext(), col++ )
1584 {
1585 wxListItemData *item = node->GetData();
1586
1587 int width = m_owner->GetColumnWidth(col);
1588 int xOld = x;
1589 x += width;
1590
1591 const int wText = width - 8;
1592 wxDCClipper clipper(*dc, xOld, rect.y, wText, rect.height);
1593
1594 if ( item->HasImage() )
1595 {
1596 int ix, iy;
1597 m_owner->GetImageSize( item->GetImage(), ix, iy );
1598 m_owner->DrawImage( item->GetImage(), dc, xOld, yMid - iy/2 );
1599
1600 ix += IMAGE_MARGIN_IN_REPORT_MODE;
1601
1602 xOld += ix;
1603 width -= ix;
1604 }
1605
1606 if ( item->HasText() )
1607 DrawTextFormatted(dc, item->GetText(), col, xOld, yMid, wText);
1608 }
1609 }
1610
1611 void wxListLineData::DrawTextFormatted(wxDC *dc,
1612 const wxString& textOrig,
1613 int col,
1614 int x,
1615 int yMid,
1616 int width)
1617 {
1618 // we don't support displaying multiple lines currently (and neither does
1619 // wxMSW FWIW) so just merge all the lines
1620 wxString text(textOrig);
1621 text.Replace(_T("\n"), _T(" "));
1622
1623 wxCoord w, h;
1624 dc->GetTextExtent(text, &w, &h);
1625
1626 const wxCoord y = yMid - (h + 1)/2;
1627
1628 wxDCClipper clipper(*dc, x, y, width, h);
1629
1630 // determine if the string can fit inside the current width
1631 if (w <= width)
1632 {
1633 // it can, draw it using the items alignment
1634 wxListItem item;
1635 m_owner->GetColumn(col, item);
1636 switch ( item.GetAlign() )
1637 {
1638 case wxLIST_FORMAT_LEFT:
1639 // nothing to do
1640 break;
1641
1642 case wxLIST_FORMAT_RIGHT:
1643 x += width - w;
1644 break;
1645
1646 case wxLIST_FORMAT_CENTER:
1647 x += (width - w) / 2;
1648 break;
1649
1650 default:
1651 wxFAIL_MSG( _T("unknown list item format") );
1652 break;
1653 }
1654
1655 dc->DrawText(text, x, y);
1656 }
1657 else // otherwise, truncate and add an ellipsis if possible
1658 {
1659 // determine the base width
1660 wxString ellipsis(wxT("..."));
1661 wxCoord base_w;
1662 dc->GetTextExtent(ellipsis, &base_w, &h);
1663
1664 // continue until we have enough space or only one character left
1665 wxCoord w_c, h_c;
1666 size_t len = text.length();
1667 wxString drawntext = text.Left(len);
1668 while (len > 1)
1669 {
1670 dc->GetTextExtent(drawntext.Last(), &w_c, &h_c);
1671 drawntext.RemoveLast();
1672 len--;
1673 w -= w_c;
1674 if (w + base_w <= width)
1675 break;
1676 }
1677
1678 // if still not enough space, remove ellipsis characters
1679 while (ellipsis.length() > 0 && w + base_w > width)
1680 {
1681 ellipsis = ellipsis.Left(ellipsis.length() - 1);
1682 dc->GetTextExtent(ellipsis, &base_w, &h);
1683 }
1684
1685 // now draw the text
1686 dc->DrawText(drawntext, x, y);
1687 dc->DrawText(ellipsis, x + w, y);
1688 }
1689 }
1690
1691 bool wxListLineData::Highlight( bool on )
1692 {
1693 wxCHECK_MSG( !IsVirtual(), false, _T("unexpected call to Highlight") );
1694
1695 if ( on == m_highlighted )
1696 return false;
1697
1698 m_highlighted = on;
1699
1700 return true;
1701 }
1702
1703 void wxListLineData::ReverseHighlight( void )
1704 {
1705 Highlight(!IsHighlighted());
1706 }
1707
1708 //-----------------------------------------------------------------------------
1709 // wxListHeaderWindow
1710 //-----------------------------------------------------------------------------
1711
1712 BEGIN_EVENT_TABLE(wxListHeaderWindow,wxWindow)
1713 EVT_PAINT (wxListHeaderWindow::OnPaint)
1714 EVT_MOUSE_EVENTS (wxListHeaderWindow::OnMouse)
1715 EVT_SET_FOCUS (wxListHeaderWindow::OnSetFocus)
1716 END_EVENT_TABLE()
1717
1718 void wxListHeaderWindow::Init()
1719 {
1720 m_currentCursor = NULL;
1721 m_isDragging = false;
1722 m_dirty = false;
1723 m_sendSetColumnWidth = false;
1724 }
1725
1726 wxListHeaderWindow::wxListHeaderWindow()
1727 {
1728 Init();
1729
1730 m_owner = NULL;
1731 m_resizeCursor = NULL;
1732 }
1733
1734 wxListHeaderWindow::wxListHeaderWindow( wxWindow *win,
1735 wxWindowID id,
1736 wxListMainWindow *owner,
1737 const wxPoint& pos,
1738 const wxSize& size,
1739 long style,
1740 const wxString &name )
1741 : wxWindow( win, id, pos, size, style, name )
1742 {
1743 Init();
1744
1745 m_owner = owner;
1746 m_resizeCursor = new wxCursor( wxCURSOR_SIZEWE );
1747
1748 #if _USE_VISATTR
1749 wxVisualAttributes attr = wxPanel::GetClassDefaultAttributes();
1750 SetOwnForegroundColour( attr.colFg );
1751 SetOwnBackgroundColour( attr.colBg );
1752 if (!m_hasFont)
1753 SetOwnFont( attr.font );
1754 #else
1755 SetOwnForegroundColour( wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT));
1756 SetOwnBackgroundColour( wxSystemSettings::GetColour(wxSYS_COLOUR_BTNFACE));
1757 if (!m_hasFont)
1758 SetOwnFont( wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT ));
1759 #endif
1760 }
1761
1762 wxListHeaderWindow::~wxListHeaderWindow()
1763 {
1764 delete m_resizeCursor;
1765 }
1766
1767 #ifdef __WXUNIVERSAL__
1768 #include "wx/univ/renderer.h"
1769 #include "wx/univ/theme.h"
1770 #endif
1771
1772 // shift the DC origin to match the position of the main window horz
1773 // scrollbar: this allows us to always use logical coords
1774 void wxListHeaderWindow::AdjustDC(wxDC& dc)
1775 {
1776 wxGenericListCtrl *parent = m_owner->GetListCtrl();
1777
1778 int xpix;
1779 parent->GetScrollPixelsPerUnit( &xpix, NULL );
1780
1781 int view_start;
1782 parent->GetViewStart( &view_start, NULL );
1783
1784
1785 int org_x = 0;
1786 int org_y = 0;
1787 dc.GetDeviceOrigin( &org_x, &org_y );
1788
1789 // account for the horz scrollbar offset
1790 #ifdef __WXGTK__
1791 if (GetLayoutDirection() == wxLayout_RightToLeft)
1792 {
1793 // Maybe we just have to check for m_signX
1794 // in the DC, but I leave the #ifdef __WXGTK__
1795 // for now
1796 dc.SetDeviceOrigin( org_x + (view_start * xpix), org_y );
1797 }
1798 else
1799 #endif
1800 dc.SetDeviceOrigin( org_x - (view_start * xpix), org_y );
1801 }
1802
1803 void wxListHeaderWindow::OnPaint( wxPaintEvent &WXUNUSED(event) )
1804 {
1805 wxGenericListCtrl *parent = m_owner->GetListCtrl();
1806
1807 wxPaintDC dc( this );
1808
1809 AdjustDC( dc );
1810
1811 dc.SetFont( GetFont() );
1812
1813 // width and height of the entire header window
1814 int w, h;
1815 GetClientSize( &w, &h );
1816 parent->CalcUnscrolledPosition(w, 0, &w, NULL);
1817
1818 dc.SetBackgroundMode(wxBRUSHSTYLE_TRANSPARENT);
1819 dc.SetTextForeground(GetForegroundColour());
1820
1821 int x = HEADER_OFFSET_X;
1822 int numColumns = m_owner->GetColumnCount();
1823 wxListItem item;
1824 for ( int i = 0; i < numColumns && x < w; i++ )
1825 {
1826 m_owner->GetColumn( i, item );
1827 int wCol = item.m_width;
1828
1829 int cw = wCol;
1830 int ch = h;
1831
1832 int flags = 0;
1833 if (!m_parent->IsEnabled())
1834 flags |= wxCONTROL_DISABLED;
1835
1836 // NB: The code below is not really Mac-specific, but since we are close
1837 // to 2.8 release and I don't have time to test on other platforms, I
1838 // defined this only for wxMac. If this behavior is desired on
1839 // other platforms, please go ahead and revise or remove the #ifdef.
1840 #ifdef __WXMAC__
1841 if ( !m_owner->IsVirtual() && (item.m_mask & wxLIST_MASK_STATE) &&
1842 (item.m_state & wxLIST_STATE_SELECTED) )
1843 flags |= wxCONTROL_SELECTED;
1844 #endif
1845
1846 if (i == 0)
1847 flags |= wxCONTROL_SPECIAL; // mark as first column
1848
1849 wxRendererNative::Get().DrawHeaderButton
1850 (
1851 this,
1852 dc,
1853 wxRect(x, HEADER_OFFSET_Y, cw, ch),
1854 flags
1855 );
1856
1857 // see if we have enough space for the column label
1858
1859 // for this we need the width of the text
1860 wxCoord wLabel;
1861 wxCoord hLabel;
1862 dc.GetTextExtent(item.GetText(), &wLabel, &hLabel);
1863 wLabel += 2 * EXTRA_WIDTH;
1864
1865 // and the width of the icon, if any
1866 int ix = 0, iy = 0; // init them just to suppress the compiler warnings
1867 const int image = item.m_image;
1868 wxImageList *imageList;
1869 if ( image != -1 )
1870 {
1871 imageList = m_owner->m_small_image_list;
1872 if ( imageList )
1873 {
1874 imageList->GetSize(image, ix, iy);
1875 wLabel += ix + HEADER_IMAGE_MARGIN_IN_REPORT_MODE;
1876 }
1877 }
1878 else
1879 {
1880 imageList = NULL;
1881 }
1882
1883 // ignore alignment if there is not enough space anyhow
1884 int xAligned;
1885 switch ( wLabel < cw ? item.GetAlign() : wxLIST_FORMAT_LEFT )
1886 {
1887 default:
1888 wxFAIL_MSG( _T("unknown list item format") );
1889 // fall through
1890
1891 case wxLIST_FORMAT_LEFT:
1892 xAligned = x;
1893 break;
1894
1895 case wxLIST_FORMAT_RIGHT:
1896 xAligned = x + cw - wLabel;
1897 break;
1898
1899 case wxLIST_FORMAT_CENTER:
1900 xAligned = x + (cw - wLabel) / 2;
1901 break;
1902 }
1903
1904 // draw the text and image clipping them so that they
1905 // don't overwrite the column boundary
1906 wxDCClipper clipper(dc, x, HEADER_OFFSET_Y, cw, h - 4 );
1907
1908 // if we have an image, draw it on the right of the label
1909 if ( imageList )
1910 {
1911 imageList->Draw
1912 (
1913 image,
1914 dc,
1915 xAligned + wLabel - ix - HEADER_IMAGE_MARGIN_IN_REPORT_MODE,
1916 HEADER_OFFSET_Y + (h - 4 - iy)/2,
1917 wxIMAGELIST_DRAW_TRANSPARENT
1918 );
1919 }
1920
1921 dc.DrawText( item.GetText(),
1922 xAligned + EXTRA_WIDTH, h / 2 - hLabel / 2 ); //HEADER_OFFSET_Y + EXTRA_HEIGHT );
1923
1924 x += wCol;
1925 }
1926
1927 // Fill in what's missing to the right of the columns, otherwise we will
1928 // leave an unpainted area when columns are removed (and it looks better)
1929 if ( x < w )
1930 {
1931 wxRendererNative::Get().DrawHeaderButton
1932 (
1933 this,
1934 dc,
1935 wxRect(x, HEADER_OFFSET_Y, w - x, h),
1936 wxCONTROL_DIRTY // mark as last column
1937 );
1938 }
1939 }
1940
1941 void wxListHeaderWindow::OnInternalIdle()
1942 {
1943 wxWindow::OnInternalIdle();
1944
1945 if (m_sendSetColumnWidth)
1946 {
1947 m_owner->SetColumnWidth( m_colToSend, m_widthToSend );
1948 m_sendSetColumnWidth = false;
1949 }
1950 }
1951
1952 void wxListHeaderWindow::DrawCurrent()
1953 {
1954 #if 1
1955 // m_owner->SetColumnWidth( m_column, m_currentX - m_minX );
1956 m_sendSetColumnWidth = true;
1957 m_colToSend = m_column;
1958 m_widthToSend = m_currentX - m_minX;
1959 #else
1960 int x1 = m_currentX;
1961 int y1 = 0;
1962 m_owner->ClientToScreen( &x1, &y1 );
1963
1964 int x2 = m_currentX;
1965 int y2 = 0;
1966 m_owner->GetClientSize( NULL, &y2 );
1967 m_owner->ClientToScreen( &x2, &y2 );
1968
1969 wxScreenDC dc;
1970 dc.SetLogicalFunction( wxINVERT );
1971 dc.SetPen( wxPen( *wxBLACK, 2, wxSOLID ) );
1972 dc.SetBrush( *wxTRANSPARENT_BRUSH );
1973
1974 AdjustDC(dc);
1975
1976 dc.DrawLine( x1, y1, x2, y2 );
1977
1978 dc.SetLogicalFunction( wxCOPY );
1979
1980 dc.SetPen( wxNullPen );
1981 dc.SetBrush( wxNullBrush );
1982 #endif
1983 }
1984
1985 void wxListHeaderWindow::OnMouse( wxMouseEvent &event )
1986 {
1987 wxGenericListCtrl *parent = m_owner->GetListCtrl();
1988
1989 // we want to work with logical coords
1990 int x;
1991 parent->CalcUnscrolledPosition(event.GetX(), 0, &x, NULL);
1992 int y = event.GetY();
1993
1994 if (m_isDragging)
1995 {
1996 SendListEvent(wxEVT_COMMAND_LIST_COL_DRAGGING, event.GetPosition());
1997
1998 // we don't draw the line beyond our window, but we allow dragging it
1999 // there
2000 int w = 0;
2001 GetClientSize( &w, NULL );
2002 parent->CalcUnscrolledPosition(w, 0, &w, NULL);
2003 w -= 6;
2004
2005 // erase the line if it was drawn
2006 if ( m_currentX < w )
2007 DrawCurrent();
2008
2009 if (event.ButtonUp())
2010 {
2011 ReleaseMouse();
2012 m_isDragging = false;
2013 m_dirty = true;
2014 m_owner->SetColumnWidth( m_column, m_currentX - m_minX );
2015 SendListEvent(wxEVT_COMMAND_LIST_COL_END_DRAG, event.GetPosition());
2016 }
2017 else
2018 {
2019 if (x > m_minX + 7)
2020 m_currentX = x;
2021 else
2022 m_currentX = m_minX + 7;
2023
2024 // draw in the new location
2025 if ( m_currentX < w )
2026 DrawCurrent();
2027 }
2028 }
2029 else // not dragging
2030 {
2031 m_minX = 0;
2032 bool hit_border = false;
2033
2034 // end of the current column
2035 int xpos = 0;
2036
2037 // find the column where this event occurred
2038 int col,
2039 countCol = m_owner->GetColumnCount();
2040 for (col = 0; col < countCol; col++)
2041 {
2042 xpos += m_owner->GetColumnWidth( col );
2043 m_column = col;
2044
2045 if ( (abs(x-xpos) < 3) && (y < 22) )
2046 {
2047 // near the column border
2048 hit_border = true;
2049 break;
2050 }
2051
2052 if ( x < xpos )
2053 {
2054 // inside the column
2055 break;
2056 }
2057
2058 m_minX = xpos;
2059 }
2060
2061 if ( col == countCol )
2062 m_column = -1;
2063
2064 if (event.LeftDown() || event.RightUp())
2065 {
2066 if (hit_border && event.LeftDown())
2067 {
2068 if ( SendListEvent(wxEVT_COMMAND_LIST_COL_BEGIN_DRAG,
2069 event.GetPosition()) )
2070 {
2071 m_isDragging = true;
2072 m_currentX = x;
2073 CaptureMouse();
2074 DrawCurrent();
2075 }
2076 //else: column resizing was vetoed by the user code
2077 }
2078 else // click on a column
2079 {
2080 // record the selected state of the columns
2081 if (event.LeftDown())
2082 {
2083 for (int i=0; i < m_owner->GetColumnCount(); i++)
2084 {
2085 wxListItem colItem;
2086 m_owner->GetColumn(i, colItem);
2087 long state = colItem.GetState();
2088 if (i == m_column)
2089 colItem.SetState(state | wxLIST_STATE_SELECTED);
2090 else
2091 colItem.SetState(state & ~wxLIST_STATE_SELECTED);
2092 m_owner->SetColumn(i, colItem);
2093 }
2094 }
2095
2096 SendListEvent( event.LeftDown()
2097 ? wxEVT_COMMAND_LIST_COL_CLICK
2098 : wxEVT_COMMAND_LIST_COL_RIGHT_CLICK,
2099 event.GetPosition());
2100 }
2101 }
2102 else if (event.Moving())
2103 {
2104 bool setCursor;
2105 if (hit_border)
2106 {
2107 setCursor = m_currentCursor == wxSTANDARD_CURSOR;
2108 m_currentCursor = m_resizeCursor;
2109 }
2110 else
2111 {
2112 setCursor = m_currentCursor != wxSTANDARD_CURSOR;
2113 m_currentCursor = wxSTANDARD_CURSOR;
2114 }
2115
2116 if ( setCursor )
2117 SetCursor(*m_currentCursor);
2118 }
2119 }
2120 }
2121
2122 void wxListHeaderWindow::OnSetFocus( wxFocusEvent &WXUNUSED(event) )
2123 {
2124 m_owner->SetFocus();
2125 m_owner->Update();
2126 }
2127
2128 bool wxListHeaderWindow::SendListEvent(wxEventType type, const wxPoint& pos)
2129 {
2130 wxWindow *parent = GetParent();
2131 wxListEvent le( type, parent->GetId() );
2132 le.SetEventObject( parent );
2133 le.m_pointDrag = pos;
2134
2135 // the position should be relative to the parent window, not
2136 // this one for compatibility with MSW and common sense: the
2137 // user code doesn't know anything at all about this header
2138 // window, so why should it get positions relative to it?
2139 le.m_pointDrag.y -= GetSize().y;
2140
2141 le.m_col = m_column;
2142 return !parent->GetEventHandler()->ProcessEvent( le ) || le.IsAllowed();
2143 }
2144
2145 //-----------------------------------------------------------------------------
2146 // wxListRenameTimer (internal)
2147 //-----------------------------------------------------------------------------
2148
2149 wxListRenameTimer::wxListRenameTimer( wxListMainWindow *owner )
2150 {
2151 m_owner = owner;
2152 }
2153
2154 void wxListRenameTimer::Notify()
2155 {
2156 m_owner->OnRenameTimer();
2157 }
2158
2159 //-----------------------------------------------------------------------------
2160 // wxListTextCtrlWrapper (internal)
2161 //-----------------------------------------------------------------------------
2162
2163 BEGIN_EVENT_TABLE(wxListTextCtrlWrapper, wxEvtHandler)
2164 EVT_CHAR (wxListTextCtrlWrapper::OnChar)
2165 EVT_KEY_UP (wxListTextCtrlWrapper::OnKeyUp)
2166 EVT_KILL_FOCUS (wxListTextCtrlWrapper::OnKillFocus)
2167 END_EVENT_TABLE()
2168
2169 wxListTextCtrlWrapper::wxListTextCtrlWrapper(wxListMainWindow *owner,
2170 wxTextCtrl *text,
2171 size_t itemEdit)
2172 : m_startValue(owner->GetItemText(itemEdit)),
2173 m_itemEdited(itemEdit)
2174 {
2175 m_owner = owner;
2176 m_text = text;
2177 m_aboutToFinish = false;
2178
2179 wxGenericListCtrl *parent = m_owner->GetListCtrl();
2180
2181 wxRect rectLabel = owner->GetLineLabelRect(itemEdit);
2182
2183 parent->CalcScrolledPosition(rectLabel.x, rectLabel.y,
2184 &rectLabel.x, &rectLabel.y);
2185
2186 m_text->Create(owner, wxID_ANY, m_startValue,
2187 wxPoint(rectLabel.x-4,rectLabel.y-4),
2188 wxSize(rectLabel.width+11,rectLabel.height+8));
2189 m_text->SetFocus();
2190
2191 m_text->PushEventHandler(this);
2192 }
2193
2194 void wxListTextCtrlWrapper::EndEdit(bool discardChanges)
2195 {
2196 m_aboutToFinish = true;
2197
2198 if ( discardChanges )
2199 {
2200 m_owner->OnRenameCancelled(m_itemEdited);
2201
2202 Finish( true );
2203 }
2204 else
2205 {
2206 // Notify the owner about the changes
2207 AcceptChanges();
2208
2209 // Even if vetoed, close the control (consistent with MSW)
2210 Finish( true );
2211 }
2212 }
2213
2214 void wxListTextCtrlWrapper::Finish( bool setfocus )
2215 {
2216 m_text->RemoveEventHandler(this);
2217 m_owner->ResetTextControl( m_text );
2218
2219 wxPendingDelete.Append( this );
2220
2221 if (setfocus)
2222 m_owner->SetFocus();
2223 }
2224
2225 bool wxListTextCtrlWrapper::AcceptChanges()
2226 {
2227 const wxString value = m_text->GetValue();
2228
2229 // notice that we should always call OnRenameAccept() to generate the "end
2230 // label editing" event, even if the user hasn't really changed anything
2231 if ( !m_owner->OnRenameAccept(m_itemEdited, value) )
2232 {
2233 // vetoed by the user
2234 return false;
2235 }
2236
2237 // accepted, do rename the item (unless nothing changed)
2238 if ( value != m_startValue )
2239 m_owner->SetItemText(m_itemEdited, value);
2240
2241 return true;
2242 }
2243
2244 void wxListTextCtrlWrapper::OnChar( wxKeyEvent &event )
2245 {
2246 switch ( event.m_keyCode )
2247 {
2248 case WXK_RETURN:
2249 EndEdit( false );
2250 break;
2251
2252 case WXK_ESCAPE:
2253 EndEdit( true );
2254 break;
2255
2256 default:
2257 event.Skip();
2258 }
2259 }
2260
2261 void wxListTextCtrlWrapper::OnKeyUp( wxKeyEvent &event )
2262 {
2263 if (m_aboutToFinish)
2264 {
2265 // auto-grow the textctrl:
2266 wxSize parentSize = m_owner->GetSize();
2267 wxPoint myPos = m_text->GetPosition();
2268 wxSize mySize = m_text->GetSize();
2269 int sx, sy;
2270 m_text->GetTextExtent(m_text->GetValue() + _T("MM"), &sx, &sy);
2271 if (myPos.x + sx > parentSize.x)
2272 sx = parentSize.x - myPos.x;
2273 if (mySize.x > sx)
2274 sx = mySize.x;
2275 m_text->SetSize(sx, wxDefaultCoord);
2276 }
2277
2278 event.Skip();
2279 }
2280
2281 void wxListTextCtrlWrapper::OnKillFocus( wxFocusEvent &event )
2282 {
2283 if ( !m_aboutToFinish )
2284 {
2285 if ( !AcceptChanges() )
2286 m_owner->OnRenameCancelled( m_itemEdited );
2287
2288 Finish( false );
2289 }
2290
2291 // We must let the native text control handle focus
2292 event.Skip();
2293 }
2294
2295 //-----------------------------------------------------------------------------
2296 // wxListMainWindow
2297 //-----------------------------------------------------------------------------
2298
2299 BEGIN_EVENT_TABLE(wxListMainWindow,wxScrolledCanvas)
2300 EVT_PAINT (wxListMainWindow::OnPaint)
2301 EVT_MOUSE_EVENTS (wxListMainWindow::OnMouse)
2302 EVT_CHAR (wxListMainWindow::OnChar)
2303 EVT_KEY_DOWN (wxListMainWindow::OnKeyDown)
2304 EVT_KEY_UP (wxListMainWindow::OnKeyUp)
2305 EVT_SET_FOCUS (wxListMainWindow::OnSetFocus)
2306 EVT_KILL_FOCUS (wxListMainWindow::OnKillFocus)
2307 EVT_SCROLLWIN (wxListMainWindow::OnScroll)
2308 EVT_CHILD_FOCUS (wxListMainWindow::OnChildFocus)
2309 END_EVENT_TABLE()
2310
2311 void wxListMainWindow::Init()
2312 {
2313 m_dirty = true;
2314 m_countVirt = 0;
2315 m_lineFrom =
2316 m_lineTo = (size_t)-1;
2317 m_linesPerPage = 0;
2318
2319 m_headerWidth =
2320 m_lineHeight = 0;
2321
2322 m_small_image_list = NULL;
2323 m_normal_image_list = NULL;
2324
2325 m_small_spacing = 30;
2326 m_normal_spacing = 40;
2327
2328 m_hasFocus = false;
2329 m_dragCount = 0;
2330 m_isCreated = false;
2331
2332 m_lastOnSame = false;
2333 m_renameTimer = new wxListRenameTimer( this );
2334 m_textctrlWrapper = NULL;
2335
2336 m_current =
2337 m_lineLastClicked =
2338 m_lineSelectSingleOnUp =
2339 m_lineBeforeLastClicked = (size_t)-1;
2340 }
2341
2342 wxListMainWindow::wxListMainWindow()
2343 {
2344 Init();
2345
2346 m_highlightBrush =
2347 m_highlightUnfocusedBrush = NULL;
2348 }
2349
2350 wxListMainWindow::wxListMainWindow( wxWindow *parent,
2351 wxWindowID id,
2352 const wxPoint& pos,
2353 const wxSize& size,
2354 long style,
2355 const wxString &name )
2356 : wxWindow( parent, id, pos, size, style, name )
2357 {
2358 Init();
2359
2360 m_highlightBrush = new wxBrush
2361 (
2362 wxSystemSettings::GetColour
2363 (
2364 wxSYS_COLOUR_HIGHLIGHT
2365 ),
2366 wxBRUSHSTYLE_SOLID
2367 );
2368
2369 m_highlightUnfocusedBrush = new wxBrush
2370 (
2371 wxSystemSettings::GetColour
2372 (
2373 wxSYS_COLOUR_BTNSHADOW
2374 ),
2375 wxBRUSHSTYLE_SOLID
2376 );
2377
2378 wxVisualAttributes attr = wxGenericListCtrl::GetClassDefaultAttributes();
2379 SetOwnForegroundColour( attr.colFg );
2380 SetOwnBackgroundColour( attr.colBg );
2381 if (!m_hasFont)
2382 SetOwnFont( attr.font );
2383 }
2384
2385 wxListMainWindow::~wxListMainWindow()
2386 {
2387 DoDeleteAllItems();
2388 WX_CLEAR_LIST(wxListHeaderDataList, m_columns);
2389 WX_CLEAR_ARRAY(m_aColWidths);
2390
2391 delete m_highlightBrush;
2392 delete m_highlightUnfocusedBrush;
2393 delete m_renameTimer;
2394 }
2395
2396 void wxListMainWindow::CacheLineData(size_t line)
2397 {
2398 wxGenericListCtrl *listctrl = GetListCtrl();
2399
2400 wxListLineData *ld = GetDummyLine();
2401
2402 size_t countCol = GetColumnCount();
2403 for ( size_t col = 0; col < countCol; col++ )
2404 {
2405 ld->SetText(col, listctrl->OnGetItemText(line, col));
2406 ld->SetImage(col, listctrl->OnGetItemColumnImage(line, col));
2407 }
2408
2409 ld->SetAttr(listctrl->OnGetItemAttr(line));
2410 }
2411
2412 wxListLineData *wxListMainWindow::GetDummyLine() const
2413 {
2414 wxASSERT_MSG( !IsEmpty(), _T("invalid line index") );
2415 wxASSERT_MSG( IsVirtual(), _T("GetDummyLine() shouldn't be called") );
2416
2417 wxListMainWindow *self = wxConstCast(this, wxListMainWindow);
2418
2419 // we need to recreate the dummy line if the number of columns in the
2420 // control changed as it would have the incorrect number of fields
2421 // otherwise
2422 if ( !m_lines.IsEmpty() &&
2423 m_lines[0].m_items.GetCount() != (size_t)GetColumnCount() )
2424 {
2425 self->m_lines.Clear();
2426 }
2427
2428 if ( m_lines.IsEmpty() )
2429 {
2430 wxListLineData *line = new wxListLineData(self);
2431 self->m_lines.Add(line);
2432
2433 // don't waste extra memory -- there never going to be anything
2434 // else/more in this array
2435 self->m_lines.Shrink();
2436 }
2437
2438 return &m_lines[0];
2439 }
2440
2441 // ----------------------------------------------------------------------------
2442 // line geometry (report mode only)
2443 // ----------------------------------------------------------------------------
2444
2445 wxCoord wxListMainWindow::GetLineHeight() const
2446 {
2447 // we cache the line height as calling GetTextExtent() is slow
2448 if ( !m_lineHeight )
2449 {
2450 wxListMainWindow *self = wxConstCast(this, wxListMainWindow);
2451
2452 wxClientDC dc( self );
2453 dc.SetFont( GetFont() );
2454
2455 wxCoord y;
2456 dc.GetTextExtent(_T("H"), NULL, &y);
2457
2458 if ( m_small_image_list && m_small_image_list->GetImageCount() )
2459 {
2460 int iw = 0, ih = 0;
2461 m_small_image_list->GetSize(0, iw, ih);
2462 y = wxMax(y, ih);
2463 }
2464
2465 y += EXTRA_HEIGHT;
2466 self->m_lineHeight = y + LINE_SPACING;
2467 }
2468
2469 return m_lineHeight;
2470 }
2471
2472 wxCoord wxListMainWindow::GetLineY(size_t line) const
2473 {
2474 wxASSERT_MSG( InReportView(), _T("only works in report mode") );
2475
2476 return LINE_SPACING + line * GetLineHeight();
2477 }
2478
2479 wxRect wxListMainWindow::GetLineRect(size_t line) const
2480 {
2481 if ( !InReportView() )
2482 return GetLine(line)->m_gi->m_rectAll;
2483
2484 wxRect rect;
2485 rect.x = HEADER_OFFSET_X;
2486 rect.y = GetLineY(line);
2487 rect.width = GetHeaderWidth();
2488 rect.height = GetLineHeight();
2489
2490 return rect;
2491 }
2492
2493 wxRect wxListMainWindow::GetLineLabelRect(size_t line) const
2494 {
2495 if ( !InReportView() )
2496 return GetLine(line)->m_gi->m_rectLabel;
2497
2498 int image_x = 0;
2499 wxListLineData *data = GetLine(line);
2500 wxListItemDataList::compatibility_iterator node = data->m_items.GetFirst();
2501 if (node)
2502 {
2503 wxListItemData *item = node->GetData();
2504 if ( item->HasImage() )
2505 {
2506 int ix, iy;
2507 GetImageSize( item->GetImage(), ix, iy );
2508 image_x = 3 + ix + IMAGE_MARGIN_IN_REPORT_MODE;
2509 }
2510 }
2511
2512 wxRect rect;
2513 rect.x = image_x + HEADER_OFFSET_X;
2514 rect.y = GetLineY(line);
2515 rect.width = GetColumnWidth(0) - image_x;
2516 rect.height = GetLineHeight();
2517
2518 return rect;
2519 }
2520
2521 wxRect wxListMainWindow::GetLineIconRect(size_t line) const
2522 {
2523 if ( !InReportView() )
2524 return GetLine(line)->m_gi->m_rectIcon;
2525
2526 wxListLineData *ld = GetLine(line);
2527 wxASSERT_MSG( ld->HasImage(), _T("should have an image") );
2528
2529 wxRect rect;
2530 rect.x = HEADER_OFFSET_X;
2531 rect.y = GetLineY(line);
2532 GetImageSize(ld->GetImage(), rect.width, rect.height);
2533
2534 return rect;
2535 }
2536
2537 wxRect wxListMainWindow::GetLineHighlightRect(size_t line) const
2538 {
2539 return InReportView() ? GetLineRect(line)
2540 : GetLine(line)->m_gi->m_rectHighlight;
2541 }
2542
2543 long wxListMainWindow::HitTestLine(size_t line, int x, int y) const
2544 {
2545 wxASSERT_MSG( line < GetItemCount(), _T("invalid line in HitTestLine") );
2546
2547 wxListLineData *ld = GetLine(line);
2548
2549 if ( ld->HasImage() && GetLineIconRect(line).Contains(x, y) )
2550 return wxLIST_HITTEST_ONITEMICON;
2551
2552 // VS: Testing for "ld->HasText() || InReportView()" instead of
2553 // "ld->HasText()" is needed to make empty lines in report view
2554 // possible
2555 if ( ld->HasText() || InReportView() )
2556 {
2557 wxRect rect = InReportView() ? GetLineRect(line)
2558 : GetLineLabelRect(line);
2559
2560 if ( rect.Contains(x, y) )
2561 return wxLIST_HITTEST_ONITEMLABEL;
2562 }
2563
2564 return 0;
2565 }
2566
2567 // ----------------------------------------------------------------------------
2568 // highlight (selection) handling
2569 // ----------------------------------------------------------------------------
2570
2571 bool wxListMainWindow::IsHighlighted(size_t line) const
2572 {
2573 if ( IsVirtual() )
2574 {
2575 return m_selStore.IsSelected(line);
2576 }
2577 else // !virtual
2578 {
2579 wxListLineData *ld = GetLine(line);
2580 wxCHECK_MSG( ld, false, _T("invalid index in IsHighlighted") );
2581
2582 return ld->IsHighlighted();
2583 }
2584 }
2585
2586 void wxListMainWindow::HighlightLines( size_t lineFrom,
2587 size_t lineTo,
2588 bool highlight )
2589 {
2590 if ( IsVirtual() )
2591 {
2592 wxArrayInt linesChanged;
2593 if ( !m_selStore.SelectRange(lineFrom, lineTo, highlight,
2594 &linesChanged) )
2595 {
2596 // meny items changed state, refresh everything
2597 RefreshLines(lineFrom, lineTo);
2598 }
2599 else // only a few items changed state, refresh only them
2600 {
2601 size_t count = linesChanged.GetCount();
2602 for ( size_t n = 0; n < count; n++ )
2603 {
2604 RefreshLine(linesChanged[n]);
2605 }
2606 }
2607 }
2608 else // iterate over all items in non report view
2609 {
2610 for ( size_t line = lineFrom; line <= lineTo; line++ )
2611 {
2612 if ( HighlightLine(line, highlight) )
2613 RefreshLine(line);
2614 }
2615 }
2616 }
2617
2618 bool wxListMainWindow::HighlightLine( size_t line, bool highlight )
2619 {
2620 bool changed;
2621
2622 if ( IsVirtual() )
2623 {
2624 changed = m_selStore.SelectItem(line, highlight);
2625 }
2626 else // !virtual
2627 {
2628 wxListLineData *ld = GetLine(line);
2629 wxCHECK_MSG( ld, false, _T("invalid index in HighlightLine") );
2630
2631 changed = ld->Highlight(highlight);
2632 }
2633
2634 if ( changed )
2635 {
2636 SendNotify( line, highlight ? wxEVT_COMMAND_LIST_ITEM_SELECTED
2637 : wxEVT_COMMAND_LIST_ITEM_DESELECTED );
2638 }
2639
2640 return changed;
2641 }
2642
2643 void wxListMainWindow::RefreshLine( size_t line )
2644 {
2645 if ( InReportView() )
2646 {
2647 size_t visibleFrom, visibleTo;
2648 GetVisibleLinesRange(&visibleFrom, &visibleTo);
2649
2650 if ( line < visibleFrom || line > visibleTo )
2651 return;
2652 }
2653
2654 wxRect rect = GetLineRect(line);
2655
2656 GetListCtrl()->CalcScrolledPosition( rect.x, rect.y, &rect.x, &rect.y );
2657 RefreshRect( rect );
2658 }
2659
2660 void wxListMainWindow::RefreshLines( size_t lineFrom, size_t lineTo )
2661 {
2662 // we suppose that they are ordered by caller
2663 wxASSERT_MSG( lineFrom <= lineTo, _T("indices in disorder") );
2664
2665 wxASSERT_MSG( lineTo < GetItemCount(), _T("invalid line range") );
2666
2667 if ( InReportView() )
2668 {
2669 size_t visibleFrom, visibleTo;
2670 GetVisibleLinesRange(&visibleFrom, &visibleTo);
2671
2672 if ( lineFrom < visibleFrom )
2673 lineFrom = visibleFrom;
2674 if ( lineTo > visibleTo )
2675 lineTo = visibleTo;
2676
2677 wxRect rect;
2678 rect.x = 0;
2679 rect.y = GetLineY(lineFrom);
2680 rect.width = GetClientSize().x;
2681 rect.height = GetLineY(lineTo) - rect.y + GetLineHeight();
2682
2683 GetListCtrl()->CalcScrolledPosition( rect.x, rect.y, &rect.x, &rect.y );
2684 RefreshRect( rect );
2685 }
2686 else // !report
2687 {
2688 // TODO: this should be optimized...
2689 for ( size_t line = lineFrom; line <= lineTo; line++ )
2690 {
2691 RefreshLine(line);
2692 }
2693 }
2694 }
2695
2696 void wxListMainWindow::RefreshAfter( size_t lineFrom )
2697 {
2698 if ( InReportView() )
2699 {
2700 size_t visibleFrom, visibleTo;
2701 GetVisibleLinesRange(&visibleFrom, &visibleTo);
2702
2703 if ( lineFrom < visibleFrom )
2704 lineFrom = visibleFrom;
2705 else if ( lineFrom > visibleTo )
2706 return;
2707
2708 wxRect rect;
2709 rect.x = 0;
2710 rect.y = GetLineY(lineFrom);
2711 GetListCtrl()->CalcScrolledPosition( rect.x, rect.y, &rect.x, &rect.y );
2712
2713 wxSize size = GetClientSize();
2714 rect.width = size.x;
2715
2716 // refresh till the bottom of the window
2717 rect.height = size.y - rect.y;
2718
2719 RefreshRect( rect );
2720 }
2721 else // !report
2722 {
2723 // TODO: how to do it more efficiently?
2724 m_dirty = true;
2725 }
2726 }
2727
2728 void wxListMainWindow::RefreshSelected()
2729 {
2730 if ( IsEmpty() )
2731 return;
2732
2733 size_t from, to;
2734 if ( InReportView() )
2735 {
2736 GetVisibleLinesRange(&from, &to);
2737 }
2738 else // !virtual
2739 {
2740 from = 0;
2741 to = GetItemCount() - 1;
2742 }
2743
2744 if ( HasCurrent() && m_current >= from && m_current <= to )
2745 RefreshLine(m_current);
2746
2747 for ( size_t line = from; line <= to; line++ )
2748 {
2749 // NB: the test works as expected even if m_current == -1
2750 if ( line != m_current && IsHighlighted(line) )
2751 RefreshLine(line);
2752 }
2753 }
2754
2755 void wxListMainWindow::OnPaint( wxPaintEvent &WXUNUSED(event) )
2756 {
2757 // Note: a wxPaintDC must be constructed even if no drawing is
2758 // done (a Windows requirement).
2759 wxPaintDC dc( this );
2760
2761 if ( IsEmpty() )
2762 {
2763 // nothing to draw or not the moment to draw it
2764 return;
2765 }
2766
2767 if ( m_dirty )
2768 RecalculatePositions( false );
2769
2770 GetListCtrl()->PrepareDC( dc );
2771
2772 int dev_x, dev_y;
2773 GetListCtrl()->CalcScrolledPosition( 0, 0, &dev_x, &dev_y );
2774
2775 dc.SetFont( GetFont() );
2776
2777 if ( InReportView() )
2778 {
2779 int lineHeight = GetLineHeight();
2780
2781 size_t visibleFrom, visibleTo;
2782 GetVisibleLinesRange(&visibleFrom, &visibleTo);
2783
2784 wxRect rectLine;
2785 int xOrig = dc.LogicalToDeviceX( 0 );
2786 int yOrig = dc.LogicalToDeviceY( 0 );
2787
2788 // tell the caller cache to cache the data
2789 if ( IsVirtual() )
2790 {
2791 wxListEvent evCache(wxEVT_COMMAND_LIST_CACHE_HINT,
2792 GetParent()->GetId());
2793 evCache.SetEventObject( GetParent() );
2794 evCache.m_oldItemIndex = visibleFrom;
2795 evCache.m_itemIndex = visibleTo;
2796 GetParent()->GetEventHandler()->ProcessEvent( evCache );
2797 }
2798
2799 for ( size_t line = visibleFrom; line <= visibleTo; line++ )
2800 {
2801 rectLine = GetLineRect(line);
2802
2803
2804 if ( !IsExposed(rectLine.x + xOrig, rectLine.y + yOrig,
2805 rectLine.width, rectLine.height) )
2806 {
2807 // don't redraw unaffected lines to avoid flicker
2808 continue;
2809 }
2810
2811 GetLine(line)->DrawInReportMode( &dc,
2812 rectLine,
2813 GetLineHighlightRect(line),
2814 IsHighlighted(line),
2815 line == m_current );
2816 }
2817
2818 if ( HasFlag(wxLC_HRULES) )
2819 {
2820 wxPen pen(GetRuleColour(), 1, wxPENSTYLE_SOLID);
2821 wxSize clientSize = GetClientSize();
2822
2823 size_t i = visibleFrom;
2824 if (i == 0) i = 1; // Don't draw the first one
2825 for ( ; i <= visibleTo; i++ )
2826 {
2827 dc.SetPen(pen);
2828 dc.SetBrush( *wxTRANSPARENT_BRUSH );
2829 dc.DrawLine(0 - dev_x, i * lineHeight,
2830 clientSize.x - dev_x, i * lineHeight);
2831 }
2832
2833 // Draw last horizontal rule
2834 if ( visibleTo == GetItemCount() - 1 )
2835 {
2836 dc.SetPen( pen );
2837 dc.SetBrush( *wxTRANSPARENT_BRUSH );
2838 dc.DrawLine(0 - dev_x, (m_lineTo + 1) * lineHeight,
2839 clientSize.x - dev_x , (m_lineTo + 1) * lineHeight );
2840 }
2841 }
2842
2843 // Draw vertical rules if required
2844 if ( HasFlag(wxLC_VRULES) && !IsEmpty() )
2845 {
2846 wxPen pen(GetRuleColour(), 1, wxPENSTYLE_SOLID);
2847 wxRect firstItemRect, lastItemRect;
2848
2849 GetItemRect(visibleFrom, firstItemRect);
2850 GetItemRect(visibleTo, lastItemRect);
2851 int x = firstItemRect.GetX();
2852 dc.SetPen(pen);
2853 dc.SetBrush(* wxTRANSPARENT_BRUSH);
2854
2855 for (int col = 0; col < GetColumnCount(); col++)
2856 {
2857 int colWidth = GetColumnWidth(col);
2858 x += colWidth;
2859 int x_pos = x - dev_x;
2860 if (col < GetColumnCount()-1) x_pos -= 2;
2861 dc.DrawLine(x_pos, firstItemRect.GetY() - 1 - dev_y,
2862 x_pos, lastItemRect.GetBottom() + 1 - dev_y);
2863 }
2864 }
2865 }
2866 else // !report
2867 {
2868 size_t count = GetItemCount();
2869 for ( size_t i = 0; i < count; i++ )
2870 {
2871 GetLine(i)->Draw( &dc );
2872 }
2873 }
2874
2875 #if !defined( __WXMAC__) && !defined(__WXGTK20__)
2876 // Don't draw rect outline under Mac at all.
2877 // Draw it elsewhere under GTK.
2878 if ( HasCurrent() )
2879 {
2880 if ( m_hasFocus )
2881 {
2882 wxRect rect( GetLineHighlightRect( m_current ) );
2883 dc.SetPen( *wxBLACK_PEN );
2884 dc.SetBrush( *wxTRANSPARENT_BRUSH );
2885 dc.DrawRectangle( rect );
2886 }
2887 }
2888 #endif
2889 }
2890
2891 void wxListMainWindow::HighlightAll( bool on )
2892 {
2893 if ( IsSingleSel() )
2894 {
2895 wxASSERT_MSG( !on, _T("can't do this in a single selection control") );
2896
2897 // we just have one item to turn off
2898 if ( HasCurrent() && IsHighlighted(m_current) )
2899 {
2900 HighlightLine(m_current, false);
2901 RefreshLine(m_current);
2902 }
2903 }
2904 else // multi selection
2905 {
2906 if ( !IsEmpty() )
2907 HighlightLines(0, GetItemCount() - 1, on);
2908 }
2909 }
2910
2911 void wxListMainWindow::OnChildFocus(wxChildFocusEvent& WXUNUSED(event))
2912 {
2913 // Do nothing here. This prevents the default handler in wxScrolledWindow
2914 // from needlessly scrolling the window when the edit control is
2915 // dismissed. See ticket #9563.
2916 }
2917
2918 void wxListMainWindow::SendNotify( size_t line,
2919 wxEventType command,
2920 const wxPoint& point )
2921 {
2922 wxListEvent le( command, GetParent()->GetId() );
2923 le.SetEventObject( GetParent() );
2924
2925 le.m_itemIndex = line;
2926
2927 // set only for events which have position
2928 if ( point != wxDefaultPosition )
2929 le.m_pointDrag = point;
2930
2931 // don't try to get the line info for virtual list controls: the main
2932 // program has it anyhow and if we did it would result in accessing all
2933 // the lines, even those which are not visible now and this is precisely
2934 // what we're trying to avoid
2935 if ( !IsVirtual() )
2936 {
2937 if ( line != (size_t)-1 )
2938 {
2939 GetLine(line)->GetItem( 0, le.m_item );
2940 }
2941 //else: this happens for wxEVT_COMMAND_LIST_ITEM_FOCUSED event
2942 }
2943 //else: there may be no more such item
2944
2945 GetParent()->GetEventHandler()->ProcessEvent( le );
2946 }
2947
2948 void wxListMainWindow::ChangeCurrent(size_t current)
2949 {
2950 m_current = current;
2951
2952 // as the current item changed, we shouldn't start editing it when the
2953 // "slow click" timer expires as the click happened on another item
2954 if ( m_renameTimer->IsRunning() )
2955 m_renameTimer->Stop();
2956
2957 SendNotify(current, wxEVT_COMMAND_LIST_ITEM_FOCUSED);
2958 }
2959
2960 wxTextCtrl *wxListMainWindow::EditLabel(long item, wxClassInfo* textControlClass)
2961 {
2962 wxCHECK_MSG( (item >= 0) && ((size_t)item < GetItemCount()), NULL,
2963 wxT("wrong index in wxGenericListCtrl::EditLabel()") );
2964
2965 wxASSERT_MSG( textControlClass->IsKindOf(CLASSINFO(wxTextCtrl)),
2966 wxT("EditLabel() needs a text control") );
2967
2968 size_t itemEdit = (size_t)item;
2969
2970 wxListEvent le( wxEVT_COMMAND_LIST_BEGIN_LABEL_EDIT, GetParent()->GetId() );
2971 le.SetEventObject( GetParent() );
2972 le.m_itemIndex = item;
2973 wxListLineData *data = GetLine(itemEdit);
2974 wxCHECK_MSG( data, NULL, _T("invalid index in EditLabel()") );
2975 data->GetItem( 0, le.m_item );
2976
2977 if ( GetParent()->GetEventHandler()->ProcessEvent( le ) && !le.IsAllowed() )
2978 {
2979 // vetoed by user code
2980 return NULL;
2981 }
2982
2983 // We have to call this here because the label in question might just have
2984 // been added and no screen update taken place.
2985 if ( m_dirty )
2986 {
2987 wxSafeYield();
2988
2989 // Pending events dispatched by wxSafeYield might have changed the item
2990 // count
2991 if ( (size_t)item >= GetItemCount() )
2992 return NULL;
2993 }
2994
2995 wxTextCtrl * const text = (wxTextCtrl *)textControlClass->CreateObject();
2996 m_textctrlWrapper = new wxListTextCtrlWrapper(this, text, item);
2997 return m_textctrlWrapper->GetText();
2998 }
2999
3000 void wxListMainWindow::OnRenameTimer()
3001 {
3002 wxCHECK_RET( HasCurrent(), wxT("unexpected rename timer") );
3003
3004 EditLabel( m_current );
3005 }
3006
3007 bool wxListMainWindow::OnRenameAccept(size_t itemEdit, const wxString& value)
3008 {
3009 wxListEvent le( wxEVT_COMMAND_LIST_END_LABEL_EDIT, GetParent()->GetId() );
3010 le.SetEventObject( GetParent() );
3011 le.m_itemIndex = itemEdit;
3012
3013 wxListLineData *data = GetLine(itemEdit);
3014
3015 wxCHECK_MSG( data, false, _T("invalid index in OnRenameAccept()") );
3016
3017 data->GetItem( 0, le.m_item );
3018 le.m_item.m_text = value;
3019 return !GetParent()->GetEventHandler()->ProcessEvent( le ) ||
3020 le.IsAllowed();
3021 }
3022
3023 void wxListMainWindow::OnRenameCancelled(size_t itemEdit)
3024 {
3025 // let owner know that the edit was cancelled
3026 wxListEvent le( wxEVT_COMMAND_LIST_END_LABEL_EDIT, GetParent()->GetId() );
3027
3028 le.SetEditCanceled(true);
3029
3030 le.SetEventObject( GetParent() );
3031 le.m_itemIndex = itemEdit;
3032
3033 wxListLineData *data = GetLine(itemEdit);
3034 wxCHECK_RET( data, _T("invalid index in OnRenameCancelled()") );
3035
3036 data->GetItem( 0, le.m_item );
3037 GetEventHandler()->ProcessEvent( le );
3038 }
3039
3040 void wxListMainWindow::OnMouse( wxMouseEvent &event )
3041 {
3042
3043 #ifdef __WXMAC__
3044 // On wxMac we can't depend on the EVT_KILL_FOCUS event to properly
3045 // shutdown the edit control when the mouse is clicked elsewhere on the
3046 // listctrl because the order of events is different (or something like
3047 // that), so explicitly end the edit if it is active.
3048 if ( event.LeftDown() && m_textctrlWrapper )
3049 m_textctrlWrapper->EndEdit( false );
3050 #endif // __WXMAC__
3051
3052 if ( event.LeftDown() )
3053 SetFocus();
3054
3055 event.SetEventObject( GetParent() );
3056 if ( GetParent()->GetEventHandler()->ProcessEvent( event) )
3057 return;
3058
3059 if (event.GetEventType() == wxEVT_MOUSEWHEEL)
3060 {
3061 // let the base handle mouse wheel events.
3062 event.Skip();
3063 return;
3064 }
3065
3066 if ( !HasCurrent() || IsEmpty() )
3067 {
3068 if (event.RightDown())
3069 {
3070 SendNotify( (size_t)-1, wxEVT_COMMAND_LIST_ITEM_RIGHT_CLICK, event.GetPosition() );
3071
3072 wxContextMenuEvent evtCtx(
3073 wxEVT_CONTEXT_MENU,
3074 GetParent()->GetId(),
3075 ClientToScreen(event.GetPosition()));
3076 evtCtx.SetEventObject(GetParent());
3077 GetParent()->GetEventHandler()->ProcessEvent(evtCtx);
3078 }
3079 return;
3080 }
3081
3082 if (m_dirty)
3083 return;
3084
3085 if ( !(event.Dragging() || event.ButtonDown() || event.LeftUp() ||
3086 event.ButtonDClick()) )
3087 return;
3088
3089 int x = event.GetX();
3090 int y = event.GetY();
3091 GetListCtrl()->CalcUnscrolledPosition( x, y, &x, &y );
3092
3093 // where did we hit it (if we did)?
3094 long hitResult = 0;
3095
3096 size_t count = GetItemCount(),
3097 current;
3098
3099 if ( InReportView() )
3100 {
3101 current = y / GetLineHeight();
3102 if ( current < count )
3103 hitResult = HitTestLine(current, x, y);
3104 }
3105 else // !report
3106 {
3107 // TODO: optimize it too! this is less simple than for report view but
3108 // enumerating all items is still not a way to do it!!
3109 for ( current = 0; current < count; current++ )
3110 {
3111 hitResult = HitTestLine(current, x, y);
3112 if ( hitResult )
3113 break;
3114 }
3115 }
3116
3117 if (event.Dragging())
3118 {
3119 if (m_dragCount == 0)
3120 {
3121 // we have to report the raw, physical coords as we want to be
3122 // able to call HitTest(event.m_pointDrag) from the user code to
3123 // get the item being dragged
3124 m_dragStart = event.GetPosition();
3125 }
3126
3127 m_dragCount++;
3128
3129 if (m_dragCount != 3)
3130 return;
3131
3132 int command = event.RightIsDown() ? wxEVT_COMMAND_LIST_BEGIN_RDRAG
3133 : wxEVT_COMMAND_LIST_BEGIN_DRAG;
3134
3135 wxListEvent le( command, GetParent()->GetId() );
3136 le.SetEventObject( GetParent() );
3137 le.m_itemIndex = m_lineLastClicked;
3138 le.m_pointDrag = m_dragStart;
3139 GetParent()->GetEventHandler()->ProcessEvent( le );
3140
3141 return;
3142 }
3143 else
3144 {
3145 m_dragCount = 0;
3146 }
3147
3148 if ( !hitResult )
3149 {
3150 // outside of any item
3151 if (event.RightDown())
3152 {
3153 SendNotify( (size_t) -1, wxEVT_COMMAND_LIST_ITEM_RIGHT_CLICK, event.GetPosition() );
3154
3155 wxContextMenuEvent evtCtx(
3156 wxEVT_CONTEXT_MENU,
3157 GetParent()->GetId(),
3158 ClientToScreen(event.GetPosition()));
3159 evtCtx.SetEventObject(GetParent());
3160 GetParent()->GetEventHandler()->ProcessEvent(evtCtx);
3161 }
3162 else
3163 {
3164 // reset the selection and bail out
3165 HighlightAll(false);
3166 }
3167
3168 return;
3169 }
3170
3171 bool forceClick = false;
3172 if (event.ButtonDClick())
3173 {
3174 if ( m_renameTimer->IsRunning() )
3175 m_renameTimer->Stop();
3176
3177 m_lastOnSame = false;
3178
3179 if ( current == m_lineLastClicked )
3180 {
3181 SendNotify( current, wxEVT_COMMAND_LIST_ITEM_ACTIVATED );
3182
3183 return;
3184 }
3185 else
3186 {
3187 // The first click was on another item, so don't interpret this as
3188 // a double click, but as a simple click instead
3189 forceClick = true;
3190 }
3191 }
3192
3193 if (event.LeftUp())
3194 {
3195 if (m_lineSelectSingleOnUp != (size_t)-1)
3196 {
3197 // select single line
3198 HighlightAll( false );
3199 ReverseHighlight(m_lineSelectSingleOnUp);
3200 }
3201
3202 if (m_lastOnSame)
3203 {
3204 if ((current == m_current) &&
3205 (hitResult == wxLIST_HITTEST_ONITEMLABEL) &&
3206 HasFlag(wxLC_EDIT_LABELS) )
3207 {
3208 if ( !InReportView() ||
3209 GetLineLabelRect(current).Contains(x, y) )
3210 {
3211 int dclick = wxSystemSettings::GetMetric(wxSYS_DCLICK_MSEC);
3212 m_renameTimer->Start(dclick > 0 ? dclick : 250, true);
3213 }
3214 }
3215 }
3216
3217 m_lastOnSame = false;
3218 m_lineSelectSingleOnUp = (size_t)-1;
3219 }
3220 else
3221 {
3222 // This is necessary, because after a DnD operation in
3223 // from and to ourself, the up event is swallowed by the
3224 // DnD code. So on next non-up event (which means here and
3225 // now) m_lineSelectSingleOnUp should be reset.
3226 m_lineSelectSingleOnUp = (size_t)-1;
3227 }
3228 if (event.RightDown())
3229 {
3230 m_lineBeforeLastClicked = m_lineLastClicked;
3231 m_lineLastClicked = current;
3232
3233 // If the item is already selected, do not update the selection.
3234 // Multi-selections should not be cleared if a selected item is clicked.
3235 if (!IsHighlighted(current))
3236 {
3237 HighlightAll(false);
3238 ChangeCurrent(current);
3239 ReverseHighlight(m_current);
3240 }
3241
3242 SendNotify( current, wxEVT_COMMAND_LIST_ITEM_RIGHT_CLICK, event.GetPosition() );
3243
3244 // Allow generation of context menu event
3245 event.Skip();
3246 }
3247 else if (event.MiddleDown())
3248 {
3249 SendNotify( current, wxEVT_COMMAND_LIST_ITEM_MIDDLE_CLICK );
3250 }
3251 else if ( event.LeftDown() || forceClick )
3252 {
3253 m_lineBeforeLastClicked = m_lineLastClicked;
3254 m_lineLastClicked = current;
3255
3256 size_t oldCurrent = m_current;
3257 bool oldWasSelected = IsHighlighted(m_current);
3258
3259 bool cmdModifierDown = event.CmdDown();
3260 if ( IsSingleSel() || !(cmdModifierDown || event.ShiftDown()) )
3261 {
3262 if ( IsSingleSel() || !IsHighlighted(current) )
3263 {
3264 HighlightAll( false );
3265
3266 ChangeCurrent(current);
3267
3268 ReverseHighlight(m_current);
3269 }
3270 else // multi sel & current is highlighted & no mod keys
3271 {
3272 m_lineSelectSingleOnUp = current;
3273 ChangeCurrent(current); // change focus
3274 }
3275 }
3276 else // multi sel & either ctrl or shift is down
3277 {
3278 if (cmdModifierDown)
3279 {
3280 ChangeCurrent(current);
3281
3282 ReverseHighlight(m_current);
3283 }
3284 else if (event.ShiftDown())
3285 {
3286 ChangeCurrent(current);
3287
3288 size_t lineFrom = oldCurrent,
3289 lineTo = current;
3290
3291 if ( lineTo < lineFrom )
3292 {
3293 lineTo = lineFrom;
3294 lineFrom = m_current;
3295 }
3296
3297 HighlightLines(lineFrom, lineTo);
3298 }
3299 else // !ctrl, !shift
3300 {
3301 // test in the enclosing if should make it impossible
3302 wxFAIL_MSG( _T("how did we get here?") );
3303 }
3304 }
3305
3306 if (m_current != oldCurrent)
3307 RefreshLine( oldCurrent );
3308
3309 // forceClick is only set if the previous click was on another item
3310 m_lastOnSame = !forceClick && (m_current == oldCurrent) && oldWasSelected;
3311 }
3312 }
3313
3314 void wxListMainWindow::MoveToItem(size_t item)
3315 {
3316 if ( item == (size_t)-1 )
3317 return;
3318
3319 wxRect rect = GetLineRect(item);
3320
3321 int client_w, client_h;
3322 GetClientSize( &client_w, &client_h );
3323
3324 const int hLine = GetLineHeight();
3325
3326 int view_x = SCROLL_UNIT_X * GetScrollPos( wxHORIZONTAL );
3327 int view_y = hLine * GetScrollPos( wxVERTICAL );
3328
3329 if ( InReportView() )
3330 {
3331 // the next we need the range of lines shown it might be different,
3332 // so recalculate it
3333 ResetVisibleLinesRange();
3334
3335 if (rect.y < view_y)
3336 GetListCtrl()->Scroll( -1, rect.y / hLine );
3337 if (rect.y + rect.height + 5 > view_y + client_h)
3338 GetListCtrl()->Scroll( -1, (rect.y + rect.height - client_h + hLine) / hLine );
3339
3340 #ifdef __WXMAC__
3341 // At least on Mac the visible lines value will get reset inside of
3342 // Scroll *before* it actually scrolls the window because of the
3343 // Update() that happens there, so it will still have the wrong value.
3344 // So let's reset it again and wait for it to be recalculated in the
3345 // next paint event. I would expect this problem to show up in wxGTK
3346 // too but couldn't duplicate it there. Perhaps the order of events
3347 // is different... --Robin
3348 ResetVisibleLinesRange();
3349 #endif
3350 }
3351 else // !report
3352 {
3353 int sx = -1,
3354 sy = -1;
3355
3356 if (rect.x-view_x < 5)
3357 sx = (rect.x - 5) / SCROLL_UNIT_X;
3358 if (rect.x + rect.width - 5 > view_x + client_w)
3359 sx = (rect.x + rect.width - client_w + SCROLL_UNIT_X) / SCROLL_UNIT_X;
3360
3361 if (rect.y-view_y < 5)
3362 sy = (rect.y - 5) / hLine;
3363 if (rect.y + rect.height - 5 > view_y + client_h)
3364 sy = (rect.y + rect.height - client_h + hLine) / hLine;
3365
3366 GetListCtrl()->Scroll(sx, sy);
3367 }
3368 }
3369
3370 bool wxListMainWindow::ScrollList(int WXUNUSED(dx), int dy)
3371 {
3372 if ( !InReportView() )
3373 {
3374 // TODO: this should work in all views but is not implemented now
3375 return false;
3376 }
3377
3378 size_t top, bottom;
3379 GetVisibleLinesRange(&top, &bottom);
3380
3381 if ( bottom == (size_t)-1 )
3382 return 0;
3383
3384 ResetVisibleLinesRange();
3385
3386 int hLine = GetLineHeight();
3387
3388 GetListCtrl()->Scroll(-1, top + dy / hLine);
3389
3390 #ifdef __WXMAC__
3391 // see comment in MoveToItem() for why we do this
3392 ResetVisibleLinesRange();
3393 #endif
3394
3395 return true;
3396 }
3397
3398 // ----------------------------------------------------------------------------
3399 // keyboard handling
3400 // ----------------------------------------------------------------------------
3401
3402 void wxListMainWindow::OnArrowChar(size_t newCurrent, const wxKeyEvent& event)
3403 {
3404 wxCHECK_RET( newCurrent < (size_t)GetItemCount(),
3405 _T("invalid item index in OnArrowChar()") );
3406
3407 size_t oldCurrent = m_current;
3408
3409 // in single selection we just ignore Shift as we can't select several
3410 // items anyhow
3411 if ( event.ShiftDown() && !IsSingleSel() )
3412 {
3413 ChangeCurrent(newCurrent);
3414
3415 // refresh the old focus to remove it
3416 RefreshLine( oldCurrent );
3417
3418 // select all the items between the old and the new one
3419 if ( oldCurrent > newCurrent )
3420 {
3421 newCurrent = oldCurrent;
3422 oldCurrent = m_current;
3423 }
3424
3425 HighlightLines(oldCurrent, newCurrent);
3426 }
3427 else // !shift
3428 {
3429 // all previously selected items are unselected unless ctrl is held
3430 // in a multiselection control
3431 if ( !event.ControlDown() || IsSingleSel() )
3432 HighlightAll(false);
3433
3434 ChangeCurrent(newCurrent);
3435
3436 // refresh the old focus to remove it
3437 RefreshLine( oldCurrent );
3438
3439 // in single selection mode we must always have a selected item
3440 if ( !event.ControlDown() || IsSingleSel() )
3441 HighlightLine( m_current, true );
3442 }
3443
3444 RefreshLine( m_current );
3445
3446 MoveToFocus();
3447 }
3448
3449 void wxListMainWindow::OnKeyDown( wxKeyEvent &event )
3450 {
3451 wxWindow *parent = GetParent();
3452
3453 // propagate the key event upwards
3454 wxKeyEvent ke(event);
3455 ke.SetEventObject( parent );
3456 if (parent->GetEventHandler()->ProcessEvent( ke ))
3457 return;
3458
3459 event.Skip();
3460 }
3461
3462 void wxListMainWindow::OnKeyUp( wxKeyEvent &event )
3463 {
3464 wxWindow *parent = GetParent();
3465
3466 // propagate the key event upwards
3467 wxKeyEvent ke(event);
3468 if (parent->GetEventHandler()->ProcessEvent( ke ))
3469 return;
3470
3471 event.Skip();
3472 }
3473
3474 void wxListMainWindow::OnChar( wxKeyEvent &event )
3475 {
3476 wxWindow *parent = GetParent();
3477
3478 // send a list_key event up
3479 if ( HasCurrent() )
3480 {
3481 wxListEvent le( wxEVT_COMMAND_LIST_KEY_DOWN, GetParent()->GetId() );
3482 le.m_itemIndex = m_current;
3483 GetLine(m_current)->GetItem( 0, le.m_item );
3484 le.m_code = event.GetKeyCode();
3485 le.SetEventObject( parent );
3486 parent->GetEventHandler()->ProcessEvent( le );
3487 }
3488
3489 if ( (event.GetKeyCode() != WXK_UP) &&
3490 (event.GetKeyCode() != WXK_DOWN) &&
3491 (event.GetKeyCode() != WXK_RIGHT) &&
3492 (event.GetKeyCode() != WXK_LEFT) &&
3493 (event.GetKeyCode() != WXK_PAGEUP) &&
3494 (event.GetKeyCode() != WXK_PAGEDOWN) &&
3495 (event.GetKeyCode() != WXK_END) &&
3496 (event.GetKeyCode() != WXK_HOME) )
3497 {
3498 // propagate the char event upwards
3499 wxKeyEvent ke(event);
3500 ke.SetEventObject( parent );
3501 if (parent->GetEventHandler()->ProcessEvent( ke ))
3502 return;
3503 }
3504
3505 if ( HandleAsNavigationKey(event) )
3506 return;
3507
3508 // no item -> nothing to do
3509 if (!HasCurrent())
3510 {
3511 event.Skip();
3512 return;
3513 }
3514
3515 // don't use m_linesPerPage directly as it might not be computed yet
3516 const int pageSize = GetCountPerPage();
3517 wxCHECK_RET( pageSize, _T("should have non zero page size") );
3518
3519 if (GetLayoutDirection() == wxLayout_RightToLeft)
3520 {
3521 if (event.GetKeyCode() == WXK_RIGHT)
3522 event.m_keyCode = WXK_LEFT;
3523 else if (event.GetKeyCode() == WXK_LEFT)
3524 event.m_keyCode = WXK_RIGHT;
3525 }
3526
3527 switch ( event.GetKeyCode() )
3528 {
3529 case WXK_UP:
3530 if ( m_current > 0 )
3531 OnArrowChar( m_current - 1, event );
3532 break;
3533
3534 case WXK_DOWN:
3535 if ( m_current < (size_t)GetItemCount() - 1 )
3536 OnArrowChar( m_current + 1, event );
3537 break;
3538
3539 case WXK_END:
3540 if (!IsEmpty())
3541 OnArrowChar( GetItemCount() - 1, event );
3542 break;
3543
3544 case WXK_HOME:
3545 if (!IsEmpty())
3546 OnArrowChar( 0, event );
3547 break;
3548
3549 case WXK_PAGEUP:
3550 {
3551 int steps = InReportView() ? pageSize - 1
3552 : m_current % pageSize;
3553
3554 int index = m_current - steps;
3555 if (index < 0)
3556 index = 0;
3557
3558 OnArrowChar( index, event );
3559 }
3560 break;
3561
3562 case WXK_PAGEDOWN:
3563 {
3564 int steps = InReportView()
3565 ? pageSize - 1
3566 : pageSize - (m_current % pageSize) - 1;
3567
3568 size_t index = m_current + steps;
3569 size_t count = GetItemCount();
3570 if ( index >= count )
3571 index = count - 1;
3572
3573 OnArrowChar( index, event );
3574 }
3575 break;
3576
3577 case WXK_LEFT:
3578 if ( !InReportView() )
3579 {
3580 int index = m_current - pageSize;
3581 if (index < 0)
3582 index = 0;
3583
3584 OnArrowChar( index, event );
3585 }
3586 break;
3587
3588 case WXK_RIGHT:
3589 if ( !InReportView() )
3590 {
3591 size_t index = m_current + pageSize;
3592
3593 size_t count = GetItemCount();
3594 if ( index >= count )
3595 index = count - 1;
3596
3597 OnArrowChar( index, event );
3598 }
3599 break;
3600
3601 case WXK_SPACE:
3602 if ( IsSingleSel() )
3603 {
3604 if ( event.ControlDown() )
3605 {
3606 ReverseHighlight(m_current);
3607 }
3608 else // normal space press
3609 {
3610 SendNotify( m_current, wxEVT_COMMAND_LIST_ITEM_ACTIVATED );
3611 }
3612 }
3613 else // multiple selection
3614 {
3615 ReverseHighlight(m_current);
3616 }
3617 break;
3618
3619 case WXK_RETURN:
3620 case WXK_EXECUTE:
3621 SendNotify( m_current, wxEVT_COMMAND_LIST_ITEM_ACTIVATED );
3622 break;
3623
3624 default:
3625 event.Skip();
3626 }
3627 }
3628
3629 // ----------------------------------------------------------------------------
3630 // focus handling
3631 // ----------------------------------------------------------------------------
3632
3633 void wxListMainWindow::OnSetFocus( wxFocusEvent &WXUNUSED(event) )
3634 {
3635 if ( GetParent() )
3636 {
3637 wxFocusEvent event( wxEVT_SET_FOCUS, GetParent()->GetId() );
3638 event.SetEventObject( GetParent() );
3639 if ( GetParent()->GetEventHandler()->ProcessEvent( event) )
3640 return;
3641 }
3642
3643 // wxGTK sends us EVT_SET_FOCUS events even if we had never got
3644 // EVT_KILL_FOCUS before which means that we finish by redrawing the items
3645 // which are already drawn correctly resulting in horrible flicker - avoid
3646 // it
3647 if ( !m_hasFocus )
3648 {
3649 m_hasFocus = true;
3650
3651 RefreshSelected();
3652 }
3653 }
3654
3655 void wxListMainWindow::OnKillFocus( wxFocusEvent &WXUNUSED(event) )
3656 {
3657 if ( GetParent() )
3658 {
3659 wxFocusEvent event( wxEVT_KILL_FOCUS, GetParent()->GetId() );
3660 event.SetEventObject( GetParent() );
3661 if ( GetParent()->GetEventHandler()->ProcessEvent( event) )
3662 return;
3663 }
3664
3665 m_hasFocus = false;
3666 RefreshSelected();
3667 }
3668
3669 void wxListMainWindow::DrawImage( int index, wxDC *dc, int x, int y )
3670 {
3671 if ( HasFlag(wxLC_ICON) && (m_normal_image_list))
3672 {
3673 m_normal_image_list->Draw( index, *dc, x, y, wxIMAGELIST_DRAW_TRANSPARENT );
3674 }
3675 else if ( HasFlag(wxLC_SMALL_ICON) && (m_small_image_list))
3676 {
3677 m_small_image_list->Draw( index, *dc, x, y, wxIMAGELIST_DRAW_TRANSPARENT );
3678 }
3679 else if ( HasFlag(wxLC_LIST) && (m_small_image_list))
3680 {
3681 m_small_image_list->Draw( index, *dc, x, y, wxIMAGELIST_DRAW_TRANSPARENT );
3682 }
3683 else if ( InReportView() && (m_small_image_list))
3684 {
3685 m_small_image_list->Draw( index, *dc, x, y, wxIMAGELIST_DRAW_TRANSPARENT );
3686 }
3687 }
3688
3689 void wxListMainWindow::GetImageSize( int index, int &width, int &height ) const
3690 {
3691 if ( HasFlag(wxLC_ICON) && m_normal_image_list )
3692 {
3693 m_normal_image_list->GetSize( index, width, height );
3694 }
3695 else if ( HasFlag(wxLC_SMALL_ICON) && m_small_image_list )
3696 {
3697 m_small_image_list->GetSize( index, width, height );
3698 }
3699 else if ( HasFlag(wxLC_LIST) && m_small_image_list )
3700 {
3701 m_small_image_list->GetSize( index, width, height );
3702 }
3703 else if ( InReportView() && m_small_image_list )
3704 {
3705 m_small_image_list->GetSize( index, width, height );
3706 }
3707 else
3708 {
3709 width =
3710 height = 0;
3711 }
3712 }
3713
3714 int wxListMainWindow::GetTextLength( const wxString &s ) const
3715 {
3716 wxClientDC dc( wxConstCast(this, wxListMainWindow) );
3717 dc.SetFont( GetFont() );
3718
3719 wxCoord lw;
3720 dc.GetTextExtent( s, &lw, NULL );
3721
3722 return lw + AUTOSIZE_COL_MARGIN;
3723 }
3724
3725 void wxListMainWindow::SetImageList( wxImageList *imageList, int which )
3726 {
3727 m_dirty = true;
3728
3729 // calc the spacing from the icon size
3730 int width = 0, height = 0;
3731
3732 if ((imageList) && (imageList->GetImageCount()) )
3733 imageList->GetSize(0, width, height);
3734
3735 if (which == wxIMAGE_LIST_NORMAL)
3736 {
3737 m_normal_image_list = imageList;
3738 m_normal_spacing = width + 8;
3739 }
3740
3741 if (which == wxIMAGE_LIST_SMALL)
3742 {
3743 m_small_image_list = imageList;
3744 m_small_spacing = width + 14;
3745 m_lineHeight = 0; // ensure that the line height will be recalc'd
3746 }
3747 }
3748
3749 void wxListMainWindow::SetItemSpacing( int spacing, bool isSmall )
3750 {
3751 m_dirty = true;
3752 if (isSmall)
3753 m_small_spacing = spacing;
3754 else
3755 m_normal_spacing = spacing;
3756 }
3757
3758 int wxListMainWindow::GetItemSpacing( bool isSmall )
3759 {
3760 return isSmall ? m_small_spacing : m_normal_spacing;
3761 }
3762
3763 // ----------------------------------------------------------------------------
3764 // columns
3765 // ----------------------------------------------------------------------------
3766
3767 void wxListMainWindow::SetColumn( int col, wxListItem &item )
3768 {
3769 wxListHeaderDataList::compatibility_iterator node = m_columns.Item( col );
3770
3771 wxCHECK_RET( node, _T("invalid column index in SetColumn") );
3772
3773 if ( item.m_width == wxLIST_AUTOSIZE_USEHEADER )
3774 item.m_width = GetTextLength( item.m_text );
3775
3776 wxListHeaderData *column = node->GetData();
3777 column->SetItem( item );
3778
3779 wxListHeaderWindow *headerWin = GetListCtrl()->m_headerWin;
3780 if ( headerWin )
3781 headerWin->m_dirty = true;
3782
3783 m_dirty = true;
3784
3785 // invalidate it as it has to be recalculated
3786 m_headerWidth = 0;
3787 }
3788
3789 void wxListMainWindow::SetColumnWidth( int col, int width )
3790 {
3791 wxCHECK_RET( col >= 0 && col < GetColumnCount(),
3792 _T("invalid column index") );
3793
3794 wxCHECK_RET( InReportView(),
3795 _T("SetColumnWidth() can only be called in report mode.") );
3796
3797 m_dirty = true;
3798
3799 wxListHeaderWindow *headerWin = GetListCtrl()->m_headerWin;
3800 if ( headerWin )
3801 headerWin->m_dirty = true;
3802
3803 wxListHeaderDataList::compatibility_iterator node = m_columns.Item( col );
3804 wxCHECK_RET( node, _T("no column?") );
3805
3806 wxListHeaderData *column = node->GetData();
3807
3808 size_t count = GetItemCount();
3809
3810 if (width == wxLIST_AUTOSIZE_USEHEADER)
3811 {
3812 width = GetTextLength(column->GetText());
3813 width += 2*EXTRA_WIDTH;
3814
3815 // check for column header's image availability
3816 const int image = column->GetImage();
3817 if ( image != -1 )
3818 {
3819 if ( m_small_image_list )
3820 {
3821 int ix = 0, iy = 0;
3822 m_small_image_list->GetSize(image, ix, iy);
3823 width += ix + HEADER_IMAGE_MARGIN_IN_REPORT_MODE;
3824 }
3825 }
3826 }
3827 else if ( width == wxLIST_AUTOSIZE )
3828 {
3829 if ( IsVirtual() )
3830 {
3831 // TODO: determine the max width somehow...
3832 width = WIDTH_COL_DEFAULT;
3833 }
3834 else // !virtual
3835 {
3836 wxClientDC dc(this);
3837 dc.SetFont( GetFont() );
3838
3839 int max = AUTOSIZE_COL_MARGIN;
3840
3841 // if the cached column width isn't valid then recalculate it
3842 if (m_aColWidths.Item(col)->bNeedsUpdate)
3843 {
3844 for (size_t i = 0; i < count; i++)
3845 {
3846 wxListLineData *line = GetLine( i );
3847 wxListItemDataList::compatibility_iterator n = line->m_items.Item( col );
3848
3849 wxCHECK_RET( n, _T("no subitem?") );
3850
3851 wxListItemData *itemData = n->GetData();
3852 wxListItem item;
3853
3854 itemData->GetItem(item);
3855 int itemWidth = GetItemWidthWithImage(&item);
3856 if (itemWidth > max)
3857 max = itemWidth;
3858 }
3859
3860 m_aColWidths.Item(col)->bNeedsUpdate = false;
3861 m_aColWidths.Item(col)->nMaxWidth = max;
3862 }
3863
3864 max = m_aColWidths.Item(col)->nMaxWidth;
3865 width = max + AUTOSIZE_COL_MARGIN;
3866 }
3867 }
3868
3869 column->SetWidth( width );
3870
3871 // invalidate it as it has to be recalculated
3872 m_headerWidth = 0;
3873 }
3874
3875 int wxListMainWindow::GetHeaderWidth() const
3876 {
3877 if ( !m_headerWidth )
3878 {
3879 wxListMainWindow *self = wxConstCast(this, wxListMainWindow);
3880
3881 size_t count = GetColumnCount();
3882 for ( size_t col = 0; col < count; col++ )
3883 {
3884 self->m_headerWidth += GetColumnWidth(col);
3885 }
3886 }
3887
3888 return m_headerWidth;
3889 }
3890
3891 void wxListMainWindow::GetColumn( int col, wxListItem &item ) const
3892 {
3893 wxListHeaderDataList::compatibility_iterator node = m_columns.Item( col );
3894 wxCHECK_RET( node, _T("invalid column index in GetColumn") );
3895
3896 wxListHeaderData *column = node->GetData();
3897 column->GetItem( item );
3898 }
3899
3900 int wxListMainWindow::GetColumnWidth( int col ) const
3901 {
3902 wxListHeaderDataList::compatibility_iterator node = m_columns.Item( col );
3903 wxCHECK_MSG( node, 0, _T("invalid column index") );
3904
3905 wxListHeaderData *column = node->GetData();
3906 return column->GetWidth();
3907 }
3908
3909 // ----------------------------------------------------------------------------
3910 // item state
3911 // ----------------------------------------------------------------------------
3912
3913 void wxListMainWindow::SetItem( wxListItem &item )
3914 {
3915 long id = item.m_itemId;
3916 wxCHECK_RET( id >= 0 && (size_t)id < GetItemCount(),
3917 _T("invalid item index in SetItem") );
3918
3919 if ( !IsVirtual() )
3920 {
3921 wxListLineData *line = GetLine((size_t)id);
3922 line->SetItem( item.m_col, item );
3923
3924 // Set item state if user wants
3925 if ( item.m_mask & wxLIST_MASK_STATE )
3926 SetItemState( item.m_itemId, item.m_state, item.m_state );
3927
3928 if (InReportView())
3929 {
3930 // update the Max Width Cache if needed
3931 int width = GetItemWidthWithImage(&item);
3932
3933 if (width > m_aColWidths.Item(item.m_col)->nMaxWidth)
3934 m_aColWidths.Item(item.m_col)->nMaxWidth = width;
3935 }
3936 }
3937
3938 // update the item on screen
3939 wxRect rectItem;
3940 GetItemRect(id, rectItem);
3941 RefreshRect(rectItem);
3942 }
3943
3944 void wxListMainWindow::SetItemStateAll(long state, long stateMask)
3945 {
3946 if ( IsEmpty() )
3947 return;
3948
3949 // first deal with selection
3950 if ( stateMask & wxLIST_STATE_SELECTED )
3951 {
3952 // set/clear select state
3953 if ( IsVirtual() )
3954 {
3955 // optimized version for virtual listctrl.
3956 m_selStore.SelectRange(0, GetItemCount() - 1, state == wxLIST_STATE_SELECTED);
3957 Refresh();
3958 }
3959 else if ( state & wxLIST_STATE_SELECTED )
3960 {
3961 const long count = GetItemCount();
3962 for( long i = 0; i < count; i++ )
3963 {
3964 SetItemState( i, wxLIST_STATE_SELECTED, wxLIST_STATE_SELECTED );
3965 }
3966
3967 }
3968 else
3969 {
3970 // clear for non virtual (somewhat optimized by using GetNextItem())
3971 long i = -1;
3972 while ( (i = GetNextItem(i, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED)) != -1 )
3973 {
3974 SetItemState( i, 0, wxLIST_STATE_SELECTED );
3975 }
3976 }
3977 }
3978
3979 if ( HasCurrent() && (state == 0) && (stateMask & wxLIST_STATE_FOCUSED) )
3980 {
3981 // unfocus all: only one item can be focussed, so clearing focus for
3982 // all items is simply clearing focus of the focussed item.
3983 SetItemState(m_current, state, stateMask);
3984 }
3985 //(setting focus to all items makes no sense, so it is not handled here.)
3986 }
3987
3988 void wxListMainWindow::SetItemState( long litem, long state, long stateMask )
3989 {
3990 if ( litem == -1 )
3991 {
3992 SetItemStateAll(state, stateMask);
3993 return;
3994 }
3995
3996 wxCHECK_RET( litem >= 0 && (size_t)litem < GetItemCount(),
3997 _T("invalid list ctrl item index in SetItem") );
3998
3999 size_t oldCurrent = m_current;
4000 size_t item = (size_t)litem; // safe because of the check above
4001
4002 // do we need to change the focus?
4003 if ( stateMask & wxLIST_STATE_FOCUSED )
4004 {
4005 if ( state & wxLIST_STATE_FOCUSED )
4006 {
4007 // don't do anything if this item is already focused
4008 if ( item != m_current )
4009 {
4010 ChangeCurrent(item);
4011
4012 if ( oldCurrent != (size_t)-1 )
4013 {
4014 if ( IsSingleSel() )
4015 {
4016 HighlightLine(oldCurrent, false);
4017 }
4018
4019 RefreshLine(oldCurrent);
4020 }
4021
4022 RefreshLine( m_current );
4023 }
4024 }
4025 else // unfocus
4026 {
4027 // don't do anything if this item is not focused
4028 if ( item == m_current )
4029 {
4030 ResetCurrent();
4031
4032 if ( IsSingleSel() )
4033 {
4034 // we must unselect the old current item as well or we
4035 // might end up with more than one selected item in a
4036 // single selection control
4037 HighlightLine(oldCurrent, false);
4038 }
4039
4040 RefreshLine( oldCurrent );
4041 }
4042 }
4043 }
4044
4045 // do we need to change the selection state?
4046 if ( stateMask & wxLIST_STATE_SELECTED )
4047 {
4048 bool on = (state & wxLIST_STATE_SELECTED) != 0;
4049
4050 if ( IsSingleSel() )
4051 {
4052 if ( on )
4053 {
4054 // selecting the item also makes it the focused one in the
4055 // single sel mode
4056 if ( m_current != item )
4057 {
4058 ChangeCurrent(item);
4059
4060 if ( oldCurrent != (size_t)-1 )
4061 {
4062 HighlightLine( oldCurrent, false );
4063 RefreshLine( oldCurrent );
4064 }
4065 }
4066 }
4067 else // off
4068 {
4069 // only the current item may be selected anyhow
4070 if ( item != m_current )
4071 return;
4072 }
4073 }
4074
4075 if ( HighlightLine(item, on) )
4076 {
4077 RefreshLine(item);
4078 }
4079 }
4080 }
4081
4082 int wxListMainWindow::GetItemState( long item, long stateMask ) const
4083 {
4084 wxCHECK_MSG( item >= 0 && (size_t)item < GetItemCount(), 0,
4085 _T("invalid list ctrl item index in GetItemState()") );
4086
4087 int ret = wxLIST_STATE_DONTCARE;
4088
4089 if ( stateMask & wxLIST_STATE_FOCUSED )
4090 {
4091 if ( (size_t)item == m_current )
4092 ret |= wxLIST_STATE_FOCUSED;
4093 }
4094
4095 if ( stateMask & wxLIST_STATE_SELECTED )
4096 {
4097 if ( IsHighlighted(item) )
4098 ret |= wxLIST_STATE_SELECTED;
4099 }
4100
4101 return ret;
4102 }
4103
4104 void wxListMainWindow::GetItem( wxListItem &item ) const
4105 {
4106 wxCHECK_RET( item.m_itemId >= 0 && (size_t)item.m_itemId < GetItemCount(),
4107 _T("invalid item index in GetItem") );
4108
4109 wxListLineData *line = GetLine((size_t)item.m_itemId);
4110 line->GetItem( item.m_col, item );
4111
4112 // Get item state if user wants it
4113 if ( item.m_mask & wxLIST_MASK_STATE )
4114 item.m_state = GetItemState( item.m_itemId, wxLIST_STATE_SELECTED |
4115 wxLIST_STATE_FOCUSED );
4116 }
4117
4118 // ----------------------------------------------------------------------------
4119 // item count
4120 // ----------------------------------------------------------------------------
4121
4122 size_t wxListMainWindow::GetItemCount() const
4123 {
4124 return IsVirtual() ? m_countVirt : m_lines.GetCount();
4125 }
4126
4127 void wxListMainWindow::SetItemCount(long count)
4128 {
4129 m_selStore.SetItemCount(count);
4130 m_countVirt = count;
4131
4132 ResetVisibleLinesRange();
4133
4134 // scrollbars must be reset
4135 m_dirty = true;
4136 }
4137
4138 int wxListMainWindow::GetSelectedItemCount() const
4139 {
4140 // deal with the quick case first
4141 if ( IsSingleSel() )
4142 return HasCurrent() ? IsHighlighted(m_current) : false;
4143
4144 // virtual controls remmebers all its selections itself
4145 if ( IsVirtual() )
4146 return m_selStore.GetSelectedCount();
4147
4148 // TODO: we probably should maintain the number of items selected even for
4149 // non virtual controls as enumerating all lines is really slow...
4150 size_t countSel = 0;
4151 size_t count = GetItemCount();
4152 for ( size_t line = 0; line < count; line++ )
4153 {
4154 if ( GetLine(line)->IsHighlighted() )
4155 countSel++;
4156 }
4157
4158 return countSel;
4159 }
4160
4161 // ----------------------------------------------------------------------------
4162 // item position/size
4163 // ----------------------------------------------------------------------------
4164
4165 wxRect wxListMainWindow::GetViewRect() const
4166 {
4167 wxASSERT_MSG( !HasFlag(wxLC_LIST), "not implemented for list view" );
4168
4169 // we need to find the longest/tallest label
4170 wxCoord xMax = 0, yMax = 0;
4171 const int count = GetItemCount();
4172 if ( count )
4173 {
4174 for ( int i = 0; i < count; i++ )
4175 {
4176 // we need logical, not physical, coordinates here, so use
4177 // GetLineRect() instead of GetItemRect()
4178 wxRect r = GetLineRect(i);
4179
4180 wxCoord x = r.GetRight(),
4181 y = r.GetBottom();
4182
4183 if ( x > xMax )
4184 xMax = x;
4185 if ( y > yMax )
4186 yMax = y;
4187 }
4188 }
4189
4190 // some fudge needed to make it look prettier
4191 xMax += 2 * EXTRA_BORDER_X;
4192 yMax += 2 * EXTRA_BORDER_Y;
4193
4194 // account for the scrollbars if necessary
4195 const wxSize sizeAll = GetClientSize();
4196 if ( xMax > sizeAll.x )
4197 yMax += wxSystemSettings::GetMetric(wxSYS_HSCROLL_Y);
4198 if ( yMax > sizeAll.y )
4199 xMax += wxSystemSettings::GetMetric(wxSYS_VSCROLL_X);
4200
4201 return wxRect(0, 0, xMax, yMax);
4202 }
4203
4204 bool
4205 wxListMainWindow::GetSubItemRect(long item, long subItem, wxRect& rect) const
4206 {
4207 wxCHECK_MSG( subItem == wxLIST_GETSUBITEMRECT_WHOLEITEM || InReportView(),
4208 false,
4209 _T("GetSubItemRect only meaningful in report view") );
4210 wxCHECK_MSG( item >= 0 && (size_t)item < GetItemCount(), false,
4211 _T("invalid item in GetSubItemRect") );
4212
4213 // ensure that we're laid out, otherwise we could return nonsense
4214 if ( m_dirty )
4215 {
4216 wxConstCast(this, wxListMainWindow)->
4217 RecalculatePositions(true /* no refresh */);
4218 }
4219
4220 rect = GetLineRect((size_t)item);
4221
4222 // Adjust rect to specified column
4223 if ( subItem != wxLIST_GETSUBITEMRECT_WHOLEITEM )
4224 {
4225 wxCHECK_MSG( subItem >= 0 && subItem < GetColumnCount(), false,
4226 _T("invalid subItem in GetSubItemRect") );
4227
4228 for (int i = 0; i < subItem; i++)
4229 {
4230 rect.x += GetColumnWidth(i);
4231 }
4232 rect.width = GetColumnWidth(subItem);
4233 }
4234
4235 GetListCtrl()->CalcScrolledPosition(rect.x, rect.y, &rect.x, &rect.y);
4236
4237 return true;
4238 }
4239
4240 bool wxListMainWindow::GetItemPosition(long item, wxPoint& pos) const
4241 {
4242 wxRect rect;
4243 GetItemRect(item, rect);
4244
4245 pos.x = rect.x;
4246 pos.y = rect.y;
4247
4248 return true;
4249 }
4250
4251 // ----------------------------------------------------------------------------
4252 // geometry calculation
4253 // ----------------------------------------------------------------------------
4254
4255 void wxListMainWindow::RecalculatePositions(bool noRefresh)
4256 {
4257 const int lineHeight = GetLineHeight();
4258
4259 wxClientDC dc( this );
4260 dc.SetFont( GetFont() );
4261
4262 const size_t count = GetItemCount();
4263
4264 int iconSpacing;
4265 if ( HasFlag(wxLC_ICON) && m_normal_image_list )
4266 iconSpacing = m_normal_spacing;
4267 else if ( HasFlag(wxLC_SMALL_ICON) && m_small_image_list )
4268 iconSpacing = m_small_spacing;
4269 else
4270 iconSpacing = 0;
4271
4272 // Note that we do not call GetClientSize() here but
4273 // GetSize() and subtract the border size for sunken
4274 // borders manually. This is technically incorrect,
4275 // but we need to know the client area's size WITHOUT
4276 // scrollbars here. Since we don't know if there are
4277 // any scrollbars, we use GetSize() instead. Another
4278 // solution would be to call SetScrollbars() here to
4279 // remove the scrollbars and call GetClientSize() then,
4280 // but this might result in flicker and - worse - will
4281 // reset the scrollbars to 0 which is not good at all
4282 // if you resize a dialog/window, but don't want to
4283 // reset the window scrolling. RR.
4284 // Furthermore, we actually do NOT subtract the border
4285 // width as 2 pixels is just the extra space which we
4286 // need around the actual content in the window. Other-
4287 // wise the text would e.g. touch the upper border. RR.
4288 int clientWidth,
4289 clientHeight;
4290 GetSize( &clientWidth, &clientHeight );
4291
4292 if ( InReportView() )
4293 {
4294 // all lines have the same height and we scroll one line per step
4295 int entireHeight = count * lineHeight + LINE_SPACING;
4296
4297 m_linesPerPage = clientHeight / lineHeight;
4298
4299 ResetVisibleLinesRange();
4300
4301 GetListCtrl()->SetScrollbars( SCROLL_UNIT_X, lineHeight,
4302 GetHeaderWidth() / SCROLL_UNIT_X,
4303 (entireHeight + lineHeight - 1) / lineHeight,
4304 GetListCtrl()->GetScrollPos(wxHORIZONTAL),
4305 GetListCtrl()->GetScrollPos(wxVERTICAL),
4306 true );
4307 }
4308 else // !report
4309 {
4310 // we have 3 different layout strategies: either layout all items
4311 // horizontally/vertically (wxLC_ALIGN_XXX styles explicitly given) or
4312 // to arrange them in top to bottom, left to right (don't ask me why
4313 // not the other way round...) order
4314 if ( HasFlag(wxLC_ALIGN_LEFT | wxLC_ALIGN_TOP) )
4315 {
4316 int x = EXTRA_BORDER_X;
4317 int y = EXTRA_BORDER_Y;
4318
4319 wxCoord widthMax = 0;
4320
4321 size_t i;
4322 for ( i = 0; i < count; i++ )
4323 {
4324 wxListLineData *line = GetLine(i);
4325 line->CalculateSize( &dc, iconSpacing );
4326 line->SetPosition( x, y, iconSpacing );
4327
4328 wxSize sizeLine = GetLineSize(i);
4329
4330 if ( HasFlag(wxLC_ALIGN_TOP) )
4331 {
4332 if ( sizeLine.x > widthMax )
4333 widthMax = sizeLine.x;
4334
4335 y += sizeLine.y;
4336 }
4337 else // wxLC_ALIGN_LEFT
4338 {
4339 x += sizeLine.x + MARGIN_BETWEEN_ROWS;
4340 }
4341 }
4342
4343 if ( HasFlag(wxLC_ALIGN_TOP) )
4344 {
4345 // traverse the items again and tweak their sizes so that they are
4346 // all the same in a row
4347 for ( i = 0; i < count; i++ )
4348 {
4349 wxListLineData *line = GetLine(i);
4350 line->m_gi->ExtendWidth(widthMax);
4351 }
4352 }
4353
4354 GetListCtrl()->SetScrollbars
4355 (
4356 SCROLL_UNIT_X,
4357 lineHeight,
4358 (x + SCROLL_UNIT_X) / SCROLL_UNIT_X,
4359 (y + lineHeight) / lineHeight,
4360 GetListCtrl()->GetScrollPos( wxHORIZONTAL ),
4361 GetListCtrl()->GetScrollPos( wxVERTICAL ),
4362 true
4363 );
4364 }
4365 else // "flowed" arrangement, the most complicated case
4366 {
4367 // at first we try without any scrollbars, if the items don't fit into
4368 // the window, we recalculate after subtracting the space taken by the
4369 // scrollbar
4370
4371 int entireWidth = 0;
4372
4373 for (int tries = 0; tries < 2; tries++)
4374 {
4375 entireWidth = 2 * EXTRA_BORDER_X;
4376
4377 if (tries == 1)
4378 {
4379 // Now we have decided that the items do not fit into the
4380 // client area, so we need a scrollbar
4381 entireWidth += SCROLL_UNIT_X;
4382 }
4383
4384 int x = EXTRA_BORDER_X;
4385 int y = EXTRA_BORDER_Y;
4386 int maxWidthInThisRow = 0;
4387
4388 m_linesPerPage = 0;
4389 int currentlyVisibleLines = 0;
4390
4391 for (size_t i = 0; i < count; i++)
4392 {
4393 currentlyVisibleLines++;
4394 wxListLineData *line = GetLine( i );
4395 line->CalculateSize( &dc, iconSpacing );
4396 line->SetPosition( x, y, iconSpacing );
4397
4398 wxSize sizeLine = GetLineSize( i );
4399
4400 if ( maxWidthInThisRow < sizeLine.x )
4401 maxWidthInThisRow = sizeLine.x;
4402
4403 y += sizeLine.y;
4404 if (currentlyVisibleLines > m_linesPerPage)
4405 m_linesPerPage = currentlyVisibleLines;
4406
4407 if ( y + sizeLine.y >= clientHeight )
4408 {
4409 currentlyVisibleLines = 0;
4410 y = EXTRA_BORDER_Y;
4411 maxWidthInThisRow += MARGIN_BETWEEN_ROWS;
4412 x += maxWidthInThisRow;
4413 entireWidth += maxWidthInThisRow;
4414 maxWidthInThisRow = 0;
4415 }
4416
4417 // We have reached the last item.
4418 if ( i == count - 1 )
4419 entireWidth += maxWidthInThisRow;
4420
4421 if ( (tries == 0) &&
4422 (entireWidth + SCROLL_UNIT_X > clientWidth) )
4423 {
4424 clientHeight -= wxSystemSettings::
4425 GetMetric(wxSYS_HSCROLL_Y);
4426 m_linesPerPage = 0;
4427 break;
4428 }
4429
4430 if ( i == count - 1 )
4431 tries = 1; // Everything fits, no second try required.
4432 }
4433 }
4434
4435 GetListCtrl()->SetScrollbars
4436 (
4437 SCROLL_UNIT_X,
4438 lineHeight,
4439 (entireWidth + SCROLL_UNIT_X) / SCROLL_UNIT_X,
4440 0,
4441 GetListCtrl()->GetScrollPos( wxHORIZONTAL ),
4442 0,
4443 true
4444 );
4445 }
4446 }
4447
4448 if ( !noRefresh )
4449 {
4450 // FIXME: why should we call it from here?
4451 UpdateCurrent();
4452
4453 RefreshAll();
4454 }
4455 }
4456
4457 void wxListMainWindow::RefreshAll()
4458 {
4459 m_dirty = false;
4460 Refresh();
4461
4462 wxListHeaderWindow *headerWin = GetListCtrl()->m_headerWin;
4463 if ( headerWin && headerWin->m_dirty )
4464 {
4465 headerWin->m_dirty = false;
4466 headerWin->Refresh();
4467 }
4468 }
4469
4470 void wxListMainWindow::UpdateCurrent()
4471 {
4472 if ( !HasCurrent() && !IsEmpty() )
4473 ChangeCurrent(0);
4474 }
4475
4476 long wxListMainWindow::GetNextItem( long item,
4477 int WXUNUSED(geometry),
4478 int state ) const
4479 {
4480 long ret = item,
4481 max = GetItemCount();
4482 wxCHECK_MSG( (ret == -1) || (ret < max), -1,
4483 _T("invalid listctrl index in GetNextItem()") );
4484
4485 // notice that we start with the next item (or the first one if item == -1)
4486 // and this is intentional to allow writing a simple loop to iterate over
4487 // all selected items
4488 ret++;
4489 if ( ret == max )
4490 // this is not an error because the index was OK initially,
4491 // just no such item
4492 return -1;
4493
4494 if ( !state )
4495 // any will do
4496 return (size_t)ret;
4497
4498 size_t count = GetItemCount();
4499 for ( size_t line = (size_t)ret; line < count; line++ )
4500 {
4501 if ( (state & wxLIST_STATE_FOCUSED) && (line == m_current) )
4502 return line;
4503
4504 if ( (state & wxLIST_STATE_SELECTED) && IsHighlighted(line) )
4505 return line;
4506 }
4507
4508 return -1;
4509 }
4510
4511 // ----------------------------------------------------------------------------
4512 // deleting stuff
4513 // ----------------------------------------------------------------------------
4514
4515 void wxListMainWindow::DeleteItem( long lindex )
4516 {
4517 size_t count = GetItemCount();
4518
4519 wxCHECK_RET( (lindex >= 0) && ((size_t)lindex < count),
4520 _T("invalid item index in DeleteItem") );
4521
4522 size_t index = (size_t)lindex;
4523
4524 // we don't need to adjust the index for the previous items
4525 if ( HasCurrent() && m_current >= index )
4526 {
4527 // if the current item is being deleted, we want the next one to
4528 // become selected - unless there is no next one - so don't adjust
4529 // m_current in this case
4530 if ( m_current != index || m_current == count - 1 )
4531 m_current--;
4532 }
4533
4534 if ( InReportView() )
4535 {
4536 // mark the Column Max Width cache as dirty if the items in the line
4537 // we're deleting contain the Max Column Width
4538 wxListLineData * const line = GetLine(index);
4539 wxListItemDataList::compatibility_iterator n;
4540 wxListItemData *itemData;
4541 wxListItem item;
4542 int itemWidth;
4543
4544 for (size_t i = 0; i < m_columns.GetCount(); i++)
4545 {
4546 n = line->m_items.Item( i );
4547 itemData = n->GetData();
4548 itemData->GetItem(item);
4549
4550 itemWidth = GetItemWidthWithImage(&item);
4551
4552 if (itemWidth >= m_aColWidths.Item(i)->nMaxWidth)
4553 m_aColWidths.Item(i)->bNeedsUpdate = true;
4554 }
4555
4556 ResetVisibleLinesRange();
4557 }
4558
4559 SendNotify( index, wxEVT_COMMAND_LIST_DELETE_ITEM, wxDefaultPosition );
4560
4561 if ( IsVirtual() )
4562 {
4563 m_countVirt--;
4564 m_selStore.OnItemDelete(index);
4565 }
4566 else
4567 {
4568 m_lines.RemoveAt( index );
4569 }
4570
4571 // we need to refresh the (vert) scrollbar as the number of items changed
4572 m_dirty = true;
4573
4574 RefreshAfter(index);
4575 }
4576
4577 void wxListMainWindow::DeleteColumn( int col )
4578 {
4579 wxListHeaderDataList::compatibility_iterator node = m_columns.Item( col );
4580
4581 wxCHECK_RET( node, wxT("invalid column index in DeleteColumn()") );
4582
4583 m_dirty = true;
4584 delete node->GetData();
4585 m_columns.Erase( node );
4586
4587 if ( !IsVirtual() )
4588 {
4589 // update all the items
4590 for ( size_t i = 0; i < m_lines.GetCount(); i++ )
4591 {
4592 wxListLineData * const line = GetLine(i);
4593 wxListItemDataList::compatibility_iterator n = line->m_items.Item( col );
4594 delete n->GetData();
4595 line->m_items.Erase(n);
4596 }
4597 }
4598
4599 if ( InReportView() ) // we only cache max widths when in Report View
4600 {
4601 delete m_aColWidths.Item(col);
4602 m_aColWidths.RemoveAt(col);
4603 }
4604
4605 // invalidate it as it has to be recalculated
4606 m_headerWidth = 0;
4607 }
4608
4609 void wxListMainWindow::DoDeleteAllItems()
4610 {
4611 if ( IsEmpty() )
4612 // nothing to do - in particular, don't send the event
4613 return;
4614
4615 ResetCurrent();
4616
4617 // to make the deletion of all items faster, we don't send the
4618 // notifications for each item deletion in this case but only one event
4619 // for all of them: this is compatible with wxMSW and documented in
4620 // DeleteAllItems() description
4621
4622 wxListEvent event( wxEVT_COMMAND_LIST_DELETE_ALL_ITEMS, GetParent()->GetId() );
4623 event.SetEventObject( GetParent() );
4624 GetParent()->GetEventHandler()->ProcessEvent( event );
4625
4626 if ( IsVirtual() )
4627 {
4628 m_countVirt = 0;
4629 m_selStore.Clear();
4630 }
4631
4632 if ( InReportView() )
4633 {
4634 ResetVisibleLinesRange();
4635 for (size_t i = 0; i < m_aColWidths.GetCount(); i++)
4636 {
4637 m_aColWidths.Item(i)->bNeedsUpdate = true;
4638 }
4639 }
4640
4641 m_lines.Clear();
4642 }
4643
4644 void wxListMainWindow::DeleteAllItems()
4645 {
4646 DoDeleteAllItems();
4647
4648 RecalculatePositions();
4649 }
4650
4651 void wxListMainWindow::DeleteEverything()
4652 {
4653 WX_CLEAR_LIST(wxListHeaderDataList, m_columns);
4654 WX_CLEAR_ARRAY(m_aColWidths);
4655
4656 DeleteAllItems();
4657 }
4658
4659 // ----------------------------------------------------------------------------
4660 // scanning for an item
4661 // ----------------------------------------------------------------------------
4662
4663 void wxListMainWindow::EnsureVisible( long index )
4664 {
4665 wxCHECK_RET( index >= 0 && (size_t)index < GetItemCount(),
4666 _T("invalid index in EnsureVisible") );
4667
4668 // We have to call this here because the label in question might just have
4669 // been added and its position is not known yet
4670 if ( m_dirty )
4671 RecalculatePositions(true /* no refresh */);
4672
4673 MoveToItem((size_t)index);
4674 }
4675
4676 long wxListMainWindow::FindItem(long start, const wxString& str, bool partial )
4677 {
4678 if (str.empty())
4679 return wxNOT_FOUND;
4680
4681 long pos = start;
4682 wxString str_upper = str.Upper();
4683 if (pos < 0)
4684 pos = 0;
4685
4686 size_t count = GetItemCount();
4687 for ( size_t i = (size_t)pos; i < count; i++ )
4688 {
4689 wxListLineData *line = GetLine(i);
4690 wxString line_upper = line->GetText(0).Upper();
4691 if (!partial)
4692 {
4693 if (line_upper == str_upper )
4694 return i;
4695 }
4696 else
4697 {
4698 if (line_upper.find(str_upper) == 0)
4699 return i;
4700 }
4701 }
4702
4703 return wxNOT_FOUND;
4704 }
4705
4706 long wxListMainWindow::FindItem(long start, wxUIntPtr data)
4707 {
4708 long pos = start;
4709 if (pos < 0)
4710 pos = 0;
4711
4712 size_t count = GetItemCount();
4713 for (size_t i = (size_t)pos; i < count; i++)
4714 {
4715 wxListLineData *line = GetLine(i);
4716 wxListItem item;
4717 line->GetItem( 0, item );
4718 if (item.m_data == data)
4719 return i;
4720 }
4721
4722 return wxNOT_FOUND;
4723 }
4724
4725 long wxListMainWindow::FindItem( const wxPoint& pt )
4726 {
4727 size_t topItem;
4728 GetVisibleLinesRange( &topItem, NULL );
4729
4730 wxPoint p;
4731 GetItemPosition( GetItemCount() - 1, p );
4732 if ( p.y == 0 )
4733 return topItem;
4734
4735 long id = (long)floor( pt.y * double(GetItemCount() - topItem - 1) / p.y + topItem );
4736 if ( id >= 0 && id < (long)GetItemCount() )
4737 return id;
4738
4739 return wxNOT_FOUND;
4740 }
4741
4742 long wxListMainWindow::HitTest( int x, int y, int &flags ) const
4743 {
4744 GetListCtrl()->CalcUnscrolledPosition( x, y, &x, &y );
4745
4746 size_t count = GetItemCount();
4747
4748 if ( InReportView() )
4749 {
4750 size_t current = y / GetLineHeight();
4751 if ( current < count )
4752 {
4753 flags = HitTestLine(current, x, y);
4754 if ( flags )
4755 return current;
4756 }
4757 }
4758 else // !report
4759 {
4760 // TODO: optimize it too! this is less simple than for report view but
4761 // enumerating all items is still not a way to do it!!
4762 for ( size_t current = 0; current < count; current++ )
4763 {
4764 flags = HitTestLine(current, x, y);
4765 if ( flags )
4766 return current;
4767 }
4768 }
4769
4770 return wxNOT_FOUND;
4771 }
4772
4773 // ----------------------------------------------------------------------------
4774 // adding stuff
4775 // ----------------------------------------------------------------------------
4776
4777 void wxListMainWindow::InsertItem( wxListItem &item )
4778 {
4779 wxASSERT_MSG( !IsVirtual(), _T("can't be used with virtual control") );
4780
4781 int count = GetItemCount();
4782 wxCHECK_RET( item.m_itemId >= 0, _T("invalid item index") );
4783
4784 if (item.m_itemId > count)
4785 item.m_itemId = count;
4786
4787 size_t id = item.m_itemId;
4788
4789 m_dirty = true;
4790
4791 if ( InReportView() )
4792 {
4793 ResetVisibleLinesRange();
4794
4795 // calculate the width of the item and adjust the max column width
4796 wxColWidthInfo *pWidthInfo = m_aColWidths.Item(item.GetColumn());
4797 int width = GetItemWidthWithImage(&item);
4798 item.SetWidth(width);
4799 if (width > pWidthInfo->nMaxWidth)
4800 pWidthInfo->nMaxWidth = width;
4801 }
4802
4803 wxListLineData *line = new wxListLineData(this);
4804
4805 line->SetItem( item.m_col, item );
4806
4807 m_lines.Insert( line, id );
4808
4809 m_dirty = true;
4810
4811 // If an item is selected at or below the point of insertion, we need to
4812 // increment the member variables because the current row's index has gone
4813 // up by one
4814 if ( HasCurrent() && m_current >= id )
4815 m_current++;
4816
4817 SendNotify(id, wxEVT_COMMAND_LIST_INSERT_ITEM);
4818
4819 RefreshLines(id, GetItemCount() - 1);
4820 }
4821
4822 void wxListMainWindow::InsertColumn( long col, wxListItem &item )
4823 {
4824 m_dirty = true;
4825 if ( InReportView() )
4826 {
4827 if (item.m_width == wxLIST_AUTOSIZE_USEHEADER)
4828 item.m_width = GetTextLength( item.m_text );
4829
4830 wxListHeaderData *column = new wxListHeaderData( item );
4831 wxColWidthInfo *colWidthInfo = new wxColWidthInfo();
4832
4833 bool insert = (col >= 0) && ((size_t)col < m_columns.GetCount());
4834 if ( insert )
4835 {
4836 wxListHeaderDataList::compatibility_iterator
4837 node = m_columns.Item( col );
4838 m_columns.Insert( node, column );
4839 m_aColWidths.Insert( colWidthInfo, col );
4840 }
4841 else
4842 {
4843 m_columns.Append( column );
4844 m_aColWidths.Add( colWidthInfo );
4845 }
4846
4847 if ( !IsVirtual() )
4848 {
4849 // update all the items
4850 for ( size_t i = 0; i < m_lines.GetCount(); i++ )
4851 {
4852 wxListLineData * const line = GetLine(i);
4853 wxListItemData * const data = new wxListItemData(this);
4854 if ( insert )
4855 line->m_items.Insert(col, data);
4856 else
4857 line->m_items.Append(data);
4858 }
4859 }
4860
4861 // invalidate it as it has to be recalculated
4862 m_headerWidth = 0;
4863 }
4864 }
4865
4866 int wxListMainWindow::GetItemWidthWithImage(wxListItem * item)
4867 {
4868 int width = 0;
4869 wxClientDC dc(this);
4870
4871 dc.SetFont( GetFont() );
4872
4873 if (item->GetImage() != -1)
4874 {
4875 int ix, iy;
4876 GetImageSize( item->GetImage(), ix, iy );
4877 width += ix + 5;
4878 }
4879
4880 if (!item->GetText().empty())
4881 {
4882 wxCoord w;
4883 dc.GetTextExtent( item->GetText(), &w, NULL );
4884 width += w;
4885 }
4886
4887 return width;
4888 }
4889
4890 // ----------------------------------------------------------------------------
4891 // sorting
4892 // ----------------------------------------------------------------------------
4893
4894 static wxListCtrlCompare list_ctrl_compare_func_2;
4895 static long list_ctrl_compare_data;
4896
4897 int LINKAGEMODE list_ctrl_compare_func_1( wxListLineData **arg1, wxListLineData **arg2 )
4898 {
4899 wxListLineData *line1 = *arg1;
4900 wxListLineData *line2 = *arg2;
4901 wxListItem item;
4902 line1->GetItem( 0, item );
4903 wxUIntPtr data1 = item.m_data;
4904 line2->GetItem( 0, item );
4905 wxUIntPtr data2 = item.m_data;
4906 return list_ctrl_compare_func_2( data1, data2, list_ctrl_compare_data );
4907 }
4908
4909 void wxListMainWindow::SortItems( wxListCtrlCompare fn, long data )
4910 {
4911 // selections won't make sense any more after sorting the items so reset
4912 // them
4913 HighlightAll(false);
4914 ResetCurrent();
4915
4916 list_ctrl_compare_func_2 = fn;
4917 list_ctrl_compare_data = data;
4918 m_lines.Sort( list_ctrl_compare_func_1 );
4919 m_dirty = true;
4920 }
4921
4922 // ----------------------------------------------------------------------------
4923 // scrolling
4924 // ----------------------------------------------------------------------------
4925
4926 void wxListMainWindow::OnScroll(wxScrollWinEvent& event)
4927 {
4928 // update our idea of which lines are shown when we redraw the window the
4929 // next time
4930 ResetVisibleLinesRange();
4931
4932 if ( event.GetOrientation() == wxHORIZONTAL && HasHeader() )
4933 {
4934 wxGenericListCtrl* lc = GetListCtrl();
4935 wxCHECK_RET( lc, _T("no listctrl window?") );
4936
4937 lc->m_headerWin->Refresh();
4938 lc->m_headerWin->Update();
4939 }
4940 }
4941
4942 int wxListMainWindow::GetCountPerPage() const
4943 {
4944 if ( !m_linesPerPage )
4945 {
4946 wxConstCast(this, wxListMainWindow)->
4947 m_linesPerPage = GetClientSize().y / GetLineHeight();
4948 }
4949
4950 return m_linesPerPage;
4951 }
4952
4953 void wxListMainWindow::GetVisibleLinesRange(size_t *from, size_t *to)
4954 {
4955 wxASSERT_MSG( InReportView(), _T("this is for report mode only") );
4956
4957 if ( m_lineFrom == (size_t)-1 )
4958 {
4959 size_t count = GetItemCount();
4960 if ( count )
4961 {
4962 m_lineFrom = GetScrollPos(wxVERTICAL);
4963
4964 // this may happen if SetScrollbars() hadn't been called yet
4965 if ( m_lineFrom >= count )
4966 m_lineFrom = count - 1;
4967
4968 // we redraw one extra line but this is needed to make the redrawing
4969 // logic work when there is a fractional number of lines on screen
4970 m_lineTo = m_lineFrom + m_linesPerPage;
4971 if ( m_lineTo >= count )
4972 m_lineTo = count - 1;
4973 }
4974 else // empty control
4975 {
4976 m_lineFrom = 0;
4977 m_lineTo = (size_t)-1;
4978 }
4979 }
4980
4981 wxASSERT_MSG( IsEmpty() ||
4982 (m_lineFrom <= m_lineTo && m_lineTo < GetItemCount()),
4983 _T("GetVisibleLinesRange() returns incorrect result") );
4984
4985 if ( from )
4986 *from = m_lineFrom;
4987 if ( to )
4988 *to = m_lineTo;
4989 }
4990
4991 // -------------------------------------------------------------------------------------
4992 // wxGenericListCtrl
4993 // -------------------------------------------------------------------------------------
4994
4995 IMPLEMENT_DYNAMIC_CLASS(wxGenericListCtrl, wxControl)
4996
4997 BEGIN_EVENT_TABLE(wxGenericListCtrl,wxControl)
4998 EVT_SIZE(wxGenericListCtrl::OnSize)
4999 EVT_SCROLLWIN(wxGenericListCtrl::OnScroll)
5000 END_EVENT_TABLE()
5001
5002 void wxGenericListCtrl::Init()
5003 {
5004 m_imageListNormal = NULL;
5005 m_imageListSmall = NULL;
5006 m_imageListState = NULL;
5007
5008 m_ownsImageListNormal =
5009 m_ownsImageListSmall =
5010 m_ownsImageListState = false;
5011
5012 m_mainWin = NULL;
5013 m_headerWin = NULL;
5014 m_headerHeight = wxRendererNative::Get().GetHeaderButtonHeight(this);
5015 }
5016
5017 wxGenericListCtrl::~wxGenericListCtrl()
5018 {
5019 if (m_ownsImageListNormal)
5020 delete m_imageListNormal;
5021 if (m_ownsImageListSmall)
5022 delete m_imageListSmall;
5023 if (m_ownsImageListState)
5024 delete m_imageListState;
5025 }
5026
5027 void wxGenericListCtrl::CreateOrDestroyHeaderWindowAsNeeded()
5028 {
5029 bool needs_header = HasHeader();
5030 bool has_header = (m_headerWin != NULL);
5031
5032 if (needs_header == has_header)
5033 return;
5034
5035 if (needs_header)
5036 {
5037 m_headerWin = new wxListHeaderWindow
5038 (
5039 this, wxID_ANY, m_mainWin,
5040 wxPoint(0,0),
5041 wxSize(GetClientSize().x, m_headerHeight),
5042 wxTAB_TRAVERSAL
5043 );
5044
5045 #if defined( __WXMAC__ ) && wxOSX_USE_COCOA_OR_CARBON
5046 wxFont font;
5047 #if wxOSX_USE_ATSU_TEXT
5048 font.MacCreateFromThemeFont( kThemeSmallSystemFont );
5049 #else
5050 font.MacCreateFromUIFont( kCTFontSystemFontType );
5051 #endif
5052 m_headerWin->SetFont( font );
5053 #endif
5054
5055 GetSizer()->Prepend( m_headerWin, 0, wxGROW );
5056 }
5057 else
5058 {
5059 GetSizer()->Detach( m_headerWin );
5060
5061 delete m_headerWin;
5062
5063 m_headerWin = NULL;
5064 }
5065 }
5066
5067 bool wxGenericListCtrl::Create(wxWindow *parent,
5068 wxWindowID id,
5069 const wxPoint &pos,
5070 const wxSize &size,
5071 long style,
5072 const wxValidator &validator,
5073 const wxString &name)
5074 {
5075 Init();
5076
5077 // just like in other ports, an assert will fail if the user doesn't give any type style:
5078 wxASSERT_MSG( (style & wxLC_MASK_TYPE),
5079 _T("wxListCtrl style should have exactly one mode bit set") );
5080
5081 if ( !wxControl::Create( parent, id, pos, size, style|wxVSCROLL|wxHSCROLL, validator, name ) )
5082 return false;
5083
5084 #ifdef __WXGTK__
5085 style &= ~wxBORDER_MASK;
5086 style |= wxBORDER_THEME;
5087 #endif
5088
5089 m_mainWin = new wxListMainWindow( this, wxID_ANY, wxPoint(0, 0), size, style );
5090
5091 SetTargetWindow( m_mainWin );
5092
5093 wxBoxSizer *sizer = new wxBoxSizer( wxVERTICAL );
5094 sizer->Add( m_mainWin, 1, wxGROW );
5095 SetSizer( sizer );
5096
5097 CreateOrDestroyHeaderWindowAsNeeded();
5098
5099 SetInitialSize(size);
5100
5101 return true;
5102 }
5103
5104 wxBorder wxGenericListCtrl::GetDefaultBorder() const
5105 {
5106 return wxBORDER_THEME;
5107 }
5108
5109 #ifdef __WXMSW__
5110 WXLRESULT wxGenericListCtrl::MSWWindowProc(WXUINT nMsg,
5111 WXWPARAM wParam,
5112 WXLPARAM lParam)
5113 {
5114 WXLRESULT rc = wxControl::MSWWindowProc(nMsg, wParam, lParam);
5115
5116 #ifndef __WXWINCE__
5117 // we need to process arrows ourselves for scrolling
5118 if ( nMsg == WM_GETDLGCODE )
5119 {
5120 rc |= DLGC_WANTARROWS;
5121 }
5122 #endif
5123
5124 return rc;
5125 }
5126 #endif
5127
5128 wxSize wxGenericListCtrl::GetSizeAvailableForScrollTarget(const wxSize& size)
5129 {
5130 wxSize newsize = size;
5131 if (m_headerWin)
5132 newsize.y -= m_headerWin->GetSize().y;
5133
5134 return newsize;
5135 }
5136
5137 void wxGenericListCtrl::OnScroll(wxScrollWinEvent& event)
5138 {
5139 // update our idea of which lines are shown when we redraw
5140 // the window the next time
5141 m_mainWin->ResetVisibleLinesRange();
5142
5143 HandleOnScroll( event );
5144
5145 if ( event.GetOrientation() == wxHORIZONTAL && HasHeader() )
5146 {
5147 m_headerWin->Refresh();
5148 m_headerWin->Update();
5149 }
5150 }
5151
5152 void wxGenericListCtrl::SetSingleStyle( long style, bool add )
5153 {
5154 wxASSERT_MSG( !(style & wxLC_VIRTUAL),
5155 _T("wxLC_VIRTUAL can't be [un]set") );
5156
5157 long flag = GetWindowStyle();
5158
5159 if (add)
5160 {
5161 if (style & wxLC_MASK_TYPE)
5162 flag &= ~(wxLC_MASK_TYPE | wxLC_VIRTUAL);
5163 if (style & wxLC_MASK_ALIGN)
5164 flag &= ~wxLC_MASK_ALIGN;
5165 if (style & wxLC_MASK_SORT)
5166 flag &= ~wxLC_MASK_SORT;
5167 }
5168
5169 if (add)
5170 flag |= style;
5171 else
5172 flag &= ~style;
5173
5174 // some styles can be set without recreating everything (as happens in
5175 // SetWindowStyleFlag() which calls wxListMainWindow::DeleteEverything())
5176 if ( !(style & ~(wxLC_HRULES | wxLC_VRULES)) )
5177 {
5178 Refresh();
5179 wxWindow::SetWindowStyleFlag(flag);
5180 }
5181 else
5182 {
5183 SetWindowStyleFlag( flag );
5184 }
5185 }
5186
5187 void wxGenericListCtrl::SetWindowStyleFlag( long flag )
5188 {
5189 if (m_mainWin)
5190 {
5191 // m_mainWin->DeleteEverything(); wxMSW doesn't do that
5192
5193 CreateOrDestroyHeaderWindowAsNeeded();
5194
5195 GetSizer()->Layout();
5196 }
5197
5198 wxWindow::SetWindowStyleFlag( flag );
5199 }
5200
5201 bool wxGenericListCtrl::GetColumn(int col, wxListItem &item) const
5202 {
5203 m_mainWin->GetColumn( col, item );
5204 return true;
5205 }
5206
5207 bool wxGenericListCtrl::SetColumn( int col, wxListItem& item )
5208 {
5209 m_mainWin->SetColumn( col, item );
5210 return true;
5211 }
5212
5213 int wxGenericListCtrl::GetColumnWidth( int col ) const
5214 {
5215 return m_mainWin->GetColumnWidth( col );
5216 }
5217
5218 bool wxGenericListCtrl::SetColumnWidth( int col, int width )
5219 {
5220 m_mainWin->SetColumnWidth( col, width );
5221 return true;
5222 }
5223
5224 int wxGenericListCtrl::GetCountPerPage() const
5225 {
5226 return m_mainWin->GetCountPerPage(); // different from Windows ?
5227 }
5228
5229 bool wxGenericListCtrl::GetItem( wxListItem &info ) const
5230 {
5231 m_mainWin->GetItem( info );
5232 return true;
5233 }
5234
5235 bool wxGenericListCtrl::SetItem( wxListItem &info )
5236 {
5237 m_mainWin->SetItem( info );
5238 return true;
5239 }
5240
5241 long wxGenericListCtrl::SetItem( long index, int col, const wxString& label, int imageId )
5242 {
5243 wxListItem info;
5244 info.m_text = label;
5245 info.m_mask = wxLIST_MASK_TEXT;
5246 info.m_itemId = index;
5247 info.m_col = col;
5248 if ( imageId > -1 )
5249 {
5250 info.m_image = imageId;
5251 info.m_mask |= wxLIST_MASK_IMAGE;
5252 }
5253
5254 m_mainWin->SetItem(info);
5255 return true;
5256 }
5257
5258 int wxGenericListCtrl::GetItemState( long item, long stateMask ) const
5259 {
5260 return m_mainWin->GetItemState( item, stateMask );
5261 }
5262
5263 bool wxGenericListCtrl::SetItemState( long item, long state, long stateMask )
5264 {
5265 m_mainWin->SetItemState( item, state, stateMask );
5266 return true;
5267 }
5268
5269 bool
5270 wxGenericListCtrl::SetItemImage( long item, int image, int WXUNUSED(selImage) )
5271 {
5272 return SetItemColumnImage(item, 0, image);
5273 }
5274
5275 bool
5276 wxGenericListCtrl::SetItemColumnImage( long item, long column, int image )
5277 {
5278 wxListItem info;
5279 info.m_image = image;
5280 info.m_mask = wxLIST_MASK_IMAGE;
5281 info.m_itemId = item;
5282 info.m_col = column;
5283 m_mainWin->SetItem( info );
5284 return true;
5285 }
5286
5287 wxString wxGenericListCtrl::GetItemText( long item ) const
5288 {
5289 return m_mainWin->GetItemText(item);
5290 }
5291
5292 void wxGenericListCtrl::SetItemText( long item, const wxString& str )
5293 {
5294 m_mainWin->SetItemText(item, str);
5295 }
5296
5297 wxUIntPtr wxGenericListCtrl::GetItemData( long item ) const
5298 {
5299 wxListItem info;
5300 info.m_mask = wxLIST_MASK_DATA;
5301 info.m_itemId = item;
5302 m_mainWin->GetItem( info );
5303 return info.m_data;
5304 }
5305
5306 bool wxGenericListCtrl::SetItemPtrData( long item, wxUIntPtr data )
5307 {
5308 wxListItem info;
5309 info.m_mask = wxLIST_MASK_DATA;
5310 info.m_itemId = item;
5311 info.m_data = data;
5312 m_mainWin->SetItem( info );
5313 return true;
5314 }
5315
5316 wxRect wxGenericListCtrl::GetViewRect() const
5317 {
5318 return m_mainWin->GetViewRect();
5319 }
5320
5321 bool wxGenericListCtrl::GetItemRect(long item, wxRect& rect, int code) const
5322 {
5323 return GetSubItemRect(item, wxLIST_GETSUBITEMRECT_WHOLEITEM, rect, code);
5324 }
5325
5326 bool wxGenericListCtrl::GetSubItemRect(long item,
5327 long subItem,
5328 wxRect& rect,
5329 int WXUNUSED(code)) const
5330 {
5331 if ( !m_mainWin->GetSubItemRect( item, subItem, rect ) )
5332 return false;
5333
5334 if ( m_mainWin->HasHeader() )
5335 rect.y += m_headerHeight + 1;
5336
5337 return true;
5338 }
5339
5340 bool wxGenericListCtrl::GetItemPosition( long item, wxPoint& pos ) const
5341 {
5342 m_mainWin->GetItemPosition( item, pos );
5343 return true;
5344 }
5345
5346 bool wxGenericListCtrl::SetItemPosition( long WXUNUSED(item), const wxPoint& WXUNUSED(pos) )
5347 {
5348 return false;
5349 }
5350
5351 int wxGenericListCtrl::GetItemCount() const
5352 {
5353 return m_mainWin->GetItemCount();
5354 }
5355
5356 int wxGenericListCtrl::GetColumnCount() const
5357 {
5358 return m_mainWin->GetColumnCount();
5359 }
5360
5361 void wxGenericListCtrl::SetItemSpacing( int spacing, bool isSmall )
5362 {
5363 m_mainWin->SetItemSpacing( spacing, isSmall );
5364 }
5365
5366 wxSize wxGenericListCtrl::GetItemSpacing() const
5367 {
5368 const int spacing = m_mainWin->GetItemSpacing(HasFlag(wxLC_SMALL_ICON));
5369
5370 return wxSize(spacing, spacing);
5371 }
5372
5373 #if WXWIN_COMPATIBILITY_2_6
5374 int wxGenericListCtrl::GetItemSpacing( bool isSmall ) const
5375 {
5376 return m_mainWin->GetItemSpacing( isSmall );
5377 }
5378 #endif // WXWIN_COMPATIBILITY_2_6
5379
5380 void wxGenericListCtrl::SetItemTextColour( long item, const wxColour &col )
5381 {
5382 wxListItem info;
5383 info.m_itemId = item;
5384 info.SetTextColour( col );
5385 m_mainWin->SetItem( info );
5386 }
5387
5388 wxColour wxGenericListCtrl::GetItemTextColour( long item ) const
5389 {
5390 wxListItem info;
5391 info.m_itemId = item;
5392 m_mainWin->GetItem( info );
5393 return info.GetTextColour();
5394 }
5395
5396 void wxGenericListCtrl::SetItemBackgroundColour( long item, const wxColour &col )
5397 {
5398 wxListItem info;
5399 info.m_itemId = item;
5400 info.SetBackgroundColour( col );
5401 m_mainWin->SetItem( info );
5402 }
5403
5404 wxColour wxGenericListCtrl::GetItemBackgroundColour( long item ) const
5405 {
5406 wxListItem info;
5407 info.m_itemId = item;
5408 m_mainWin->GetItem( info );
5409 return info.GetBackgroundColour();
5410 }
5411
5412 void wxGenericListCtrl::SetItemFont( long item, const wxFont &f )
5413 {
5414 wxListItem info;
5415 info.m_itemId = item;
5416 info.SetFont( f );
5417 m_mainWin->SetItem( info );
5418 }
5419
5420 wxFont wxGenericListCtrl::GetItemFont( long item ) const
5421 {
5422 wxListItem info;
5423 info.m_itemId = item;
5424 m_mainWin->GetItem( info );
5425 return info.GetFont();
5426 }
5427
5428 int wxGenericListCtrl::GetSelectedItemCount() const
5429 {
5430 return m_mainWin->GetSelectedItemCount();
5431 }
5432
5433 wxColour wxGenericListCtrl::GetTextColour() const
5434 {
5435 return GetForegroundColour();
5436 }
5437
5438 void wxGenericListCtrl::SetTextColour(const wxColour& col)
5439 {
5440 SetForegroundColour(col);
5441 }
5442
5443 long wxGenericListCtrl::GetTopItem() const
5444 {
5445 size_t top;
5446 m_mainWin->GetVisibleLinesRange(&top, NULL);
5447 return (long)top;
5448 }
5449
5450 long wxGenericListCtrl::GetNextItem( long item, int geom, int state ) const
5451 {
5452 return m_mainWin->GetNextItem( item, geom, state );
5453 }
5454
5455 wxImageList *wxGenericListCtrl::GetImageList(int which) const
5456 {
5457 if (which == wxIMAGE_LIST_NORMAL)
5458 return m_imageListNormal;
5459 else if (which == wxIMAGE_LIST_SMALL)
5460 return m_imageListSmall;
5461 else if (which == wxIMAGE_LIST_STATE)
5462 return m_imageListState;
5463
5464 return NULL;
5465 }
5466
5467 void wxGenericListCtrl::SetImageList( wxImageList *imageList, int which )
5468 {
5469 if ( which == wxIMAGE_LIST_NORMAL )
5470 {
5471 if (m_ownsImageListNormal)
5472 delete m_imageListNormal;
5473 m_imageListNormal = imageList;
5474 m_ownsImageListNormal = false;
5475 }
5476 else if ( which == wxIMAGE_LIST_SMALL )
5477 {
5478 if (m_ownsImageListSmall)
5479 delete m_imageListSmall;
5480 m_imageListSmall = imageList;
5481 m_ownsImageListSmall = false;
5482 }
5483 else if ( which == wxIMAGE_LIST_STATE )
5484 {
5485 if (m_ownsImageListState)
5486 delete m_imageListState;
5487 m_imageListState = imageList;
5488 m_ownsImageListState = false;
5489 }
5490
5491 m_mainWin->SetImageList( imageList, which );
5492 }
5493
5494 void wxGenericListCtrl::AssignImageList(wxImageList *imageList, int which)
5495 {
5496 SetImageList(imageList, which);
5497 if ( which == wxIMAGE_LIST_NORMAL )
5498 m_ownsImageListNormal = true;
5499 else if ( which == wxIMAGE_LIST_SMALL )
5500 m_ownsImageListSmall = true;
5501 else if ( which == wxIMAGE_LIST_STATE )
5502 m_ownsImageListState = true;
5503 }
5504
5505 bool wxGenericListCtrl::Arrange( int WXUNUSED(flag) )
5506 {
5507 return 0;
5508 }
5509
5510 bool wxGenericListCtrl::DeleteItem( long item )
5511 {
5512 m_mainWin->DeleteItem( item );
5513 return true;
5514 }
5515
5516 bool wxGenericListCtrl::DeleteAllItems()
5517 {
5518 m_mainWin->DeleteAllItems();
5519 return true;
5520 }
5521
5522 bool wxGenericListCtrl::DeleteAllColumns()
5523 {
5524 size_t count = m_mainWin->m_columns.GetCount();
5525 for ( size_t n = 0; n < count; n++ )
5526 DeleteColumn( 0 );
5527 return true;
5528 }
5529
5530 void wxGenericListCtrl::ClearAll()
5531 {
5532 m_mainWin->DeleteEverything();
5533 }
5534
5535 bool wxGenericListCtrl::DeleteColumn( int col )
5536 {
5537 m_mainWin->DeleteColumn( col );
5538
5539 // if we don't have the header any longer, we need to relayout the window
5540 // if ( !GetColumnCount() )
5541
5542 return true;
5543 }
5544
5545 wxTextCtrl *wxGenericListCtrl::EditLabel(long item,
5546 wxClassInfo* textControlClass)
5547 {
5548 return m_mainWin->EditLabel( item, textControlClass );
5549 }
5550
5551 wxTextCtrl *wxGenericListCtrl::GetEditControl() const
5552 {
5553 return m_mainWin->GetEditControl();
5554 }
5555
5556 bool wxGenericListCtrl::EnsureVisible( long item )
5557 {
5558 m_mainWin->EnsureVisible( item );
5559 return true;
5560 }
5561
5562 long wxGenericListCtrl::FindItem( long start, const wxString& str, bool partial )
5563 {
5564 return m_mainWin->FindItem( start, str, partial );
5565 }
5566
5567 long wxGenericListCtrl::FindItem( long start, wxUIntPtr data )
5568 {
5569 return m_mainWin->FindItem( start, data );
5570 }
5571
5572 long wxGenericListCtrl::FindItem( long WXUNUSED(start), const wxPoint& pt,
5573 int WXUNUSED(direction))
5574 {
5575 return m_mainWin->FindItem( pt );
5576 }
5577
5578 // TODO: sub item hit testing
5579 long wxGenericListCtrl::HitTest(const wxPoint& point, int& flags, long *) const
5580 {
5581 return m_mainWin->HitTest( (int)point.x, (int)point.y, flags );
5582 }
5583
5584 long wxGenericListCtrl::InsertItem( wxListItem& info )
5585 {
5586 m_mainWin->InsertItem( info );
5587 return info.m_itemId;
5588 }
5589
5590 long wxGenericListCtrl::InsertItem( long index, const wxString &label )
5591 {
5592 wxListItem info;
5593 info.m_text = label;
5594 info.m_mask = wxLIST_MASK_TEXT;
5595 info.m_itemId = index;
5596 return InsertItem( info );
5597 }
5598
5599 long wxGenericListCtrl::InsertItem( long index, int imageIndex )
5600 {
5601 wxListItem info;
5602 info.m_mask = wxLIST_MASK_IMAGE;
5603 info.m_image = imageIndex;
5604 info.m_itemId = index;
5605 return InsertItem( info );
5606 }
5607
5608 long wxGenericListCtrl::InsertItem( long index, const wxString &label, int imageIndex )
5609 {
5610 wxListItem info;
5611 info.m_text = label;
5612 info.m_image = imageIndex;
5613 info.m_mask = wxLIST_MASK_TEXT | wxLIST_MASK_IMAGE;
5614 info.m_itemId = index;
5615 return InsertItem( info );
5616 }
5617
5618 long wxGenericListCtrl::InsertColumn( long col, wxListItem &item )
5619 {
5620 wxCHECK_MSG( m_headerWin, -1, _T("can't add column in non report mode") );
5621
5622 m_mainWin->InsertColumn( col, item );
5623
5624 // if we hadn't had a header before but have one now
5625 // then we need to relayout the window
5626 // if ( GetColumnCount() == 1 && m_mainWin->HasHeader() )
5627
5628 m_headerWin->Refresh();
5629
5630 return 0;
5631 }
5632
5633 long wxGenericListCtrl::InsertColumn( long col, const wxString &heading,
5634 int format, int width )
5635 {
5636 wxListItem item;
5637 item.m_mask = wxLIST_MASK_TEXT | wxLIST_MASK_FORMAT;
5638 item.m_text = heading;
5639 if (width >= -2)
5640 {
5641 item.m_mask |= wxLIST_MASK_WIDTH;
5642 item.m_width = width;
5643 }
5644
5645 item.m_format = format;
5646
5647 return InsertColumn( col, item );
5648 }
5649
5650 bool wxGenericListCtrl::ScrollList( int dx, int dy )
5651 {
5652 return m_mainWin->ScrollList(dx, dy);
5653 }
5654
5655 // Sort items.
5656 // fn is a function which takes 3 long arguments: item1, item2, data.
5657 // item1 is the long data associated with a first item (NOT the index).
5658 // item2 is the long data associated with a second item (NOT the index).
5659 // data is the same value as passed to SortItems.
5660 // The return value is a negative number if the first item should precede the second
5661 // item, a positive number of the second item should precede the first,
5662 // or zero if the two items are equivalent.
5663 // data is arbitrary data to be passed to the sort function.
5664
5665 bool wxGenericListCtrl::SortItems( wxListCtrlCompare fn, long data )
5666 {
5667 m_mainWin->SortItems( fn, data );
5668 return true;
5669 }
5670
5671 // ----------------------------------------------------------------------------
5672 // event handlers
5673 // ----------------------------------------------------------------------------
5674
5675 void wxGenericListCtrl::OnSize(wxSizeEvent& WXUNUSED(event))
5676 {
5677 if (!m_mainWin) return;
5678
5679 // We need to override OnSize so that our scrolled
5680 // window a) does call Layout() to use sizers for
5681 // positioning the controls but b) does not query
5682 // the sizer for their size and use that for setting
5683 // the scrollable area as set that ourselves by
5684 // calling SetScrollbar() further down.
5685
5686 Layout();
5687
5688 m_mainWin->RecalculatePositions();
5689
5690 AdjustScrollbars();
5691 }
5692
5693 void wxGenericListCtrl::OnInternalIdle()
5694 {
5695 wxWindow::OnInternalIdle();
5696
5697 if (m_mainWin->m_dirty)
5698 m_mainWin->RecalculatePositions();
5699 }
5700
5701 // ----------------------------------------------------------------------------
5702 // font/colours
5703 // ----------------------------------------------------------------------------
5704
5705 bool wxGenericListCtrl::SetBackgroundColour( const wxColour &colour )
5706 {
5707 if (m_mainWin)
5708 {
5709 m_mainWin->SetBackgroundColour( colour );
5710 m_mainWin->m_dirty = true;
5711 }
5712
5713 return true;
5714 }
5715
5716 bool wxGenericListCtrl::SetForegroundColour( const wxColour &colour )
5717 {
5718 if ( !wxWindow::SetForegroundColour( colour ) )
5719 return false;
5720
5721 if (m_mainWin)
5722 {
5723 m_mainWin->SetForegroundColour( colour );
5724 m_mainWin->m_dirty = true;
5725 }
5726
5727 if (m_headerWin)
5728 m_headerWin->SetForegroundColour( colour );
5729
5730 return true;
5731 }
5732
5733 bool wxGenericListCtrl::SetFont( const wxFont &font )
5734 {
5735 if ( !wxWindow::SetFont( font ) )
5736 return false;
5737
5738 if (m_mainWin)
5739 {
5740 m_mainWin->SetFont( font );
5741 m_mainWin->m_dirty = true;
5742 }
5743
5744 if (m_headerWin)
5745 {
5746 m_headerWin->SetFont( font );
5747 // CalculateAndSetHeaderHeight();
5748 }
5749
5750 Refresh();
5751
5752 return true;
5753 }
5754
5755 // static
5756 wxVisualAttributes
5757 wxGenericListCtrl::GetClassDefaultAttributes(wxWindowVariant variant)
5758 {
5759 #if _USE_VISATTR
5760 // Use the same color scheme as wxListBox
5761 return wxListBox::GetClassDefaultAttributes(variant);
5762 #else
5763 wxUnusedVar(variant);
5764 wxVisualAttributes attr;
5765 attr.colFg = wxSystemSettings::GetColour(wxSYS_COLOUR_LISTBOXTEXT);
5766 attr.colBg = wxSystemSettings::GetColour(wxSYS_COLOUR_LISTBOX);
5767 attr.font = wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT);
5768 return attr;
5769 #endif
5770 }
5771
5772 // ----------------------------------------------------------------------------
5773 // methods forwarded to m_mainWin
5774 // ----------------------------------------------------------------------------
5775
5776 #if wxUSE_DRAG_AND_DROP
5777
5778 void wxGenericListCtrl::SetDropTarget( wxDropTarget *dropTarget )
5779 {
5780 m_mainWin->SetDropTarget( dropTarget );
5781 }
5782
5783 wxDropTarget *wxGenericListCtrl::GetDropTarget() const
5784 {
5785 return m_mainWin->GetDropTarget();
5786 }
5787
5788 #endif
5789
5790 bool wxGenericListCtrl::SetCursor( const wxCursor &cursor )
5791 {
5792 return m_mainWin ? m_mainWin->wxWindow::SetCursor(cursor) : false;
5793 }
5794
5795 wxColour wxGenericListCtrl::GetBackgroundColour() const
5796 {
5797 return m_mainWin ? m_mainWin->GetBackgroundColour() : wxColour();
5798 }
5799
5800 wxColour wxGenericListCtrl::GetForegroundColour() const
5801 {
5802 return m_mainWin ? m_mainWin->GetForegroundColour() : wxColour();
5803 }
5804
5805 bool wxGenericListCtrl::DoPopupMenu( wxMenu *menu, int x, int y )
5806 {
5807 #if wxUSE_MENUS
5808 return m_mainWin->PopupMenu( menu, x, y );
5809 #else
5810 return false;
5811 #endif
5812 }
5813
5814 void wxGenericListCtrl::DoClientToScreen( int *x, int *y ) const
5815 {
5816 m_mainWin->DoClientToScreen(x, y);
5817 }
5818
5819 void wxGenericListCtrl::DoScreenToClient( int *x, int *y ) const
5820 {
5821 m_mainWin->DoScreenToClient(x, y);
5822 }
5823
5824 void wxGenericListCtrl::SetFocus()
5825 {
5826 // The test in window.cpp fails as we are a composite
5827 // window, so it checks against "this", but not m_mainWin.
5828 if ( DoFindFocus() != this )
5829 m_mainWin->SetFocus();
5830 }
5831
5832 wxSize wxGenericListCtrl::DoGetBestSize() const
5833 {
5834 // Something is better than nothing...
5835 // 100x80 is what the MSW version will get from the default
5836 // wxControl::DoGetBestSize
5837 return wxSize(100, 80);
5838 }
5839
5840 // ----------------------------------------------------------------------------
5841 // virtual list control support
5842 // ----------------------------------------------------------------------------
5843
5844 wxString wxGenericListCtrl::OnGetItemText(long WXUNUSED(item), long WXUNUSED(col)) const
5845 {
5846 // this is a pure virtual function, in fact - which is not really pure
5847 // because the controls which are not virtual don't need to implement it
5848 wxFAIL_MSG( _T("wxGenericListCtrl::OnGetItemText not supposed to be called") );
5849
5850 return wxEmptyString;
5851 }
5852
5853 int wxGenericListCtrl::OnGetItemImage(long WXUNUSED(item)) const
5854 {
5855 wxCHECK_MSG(!GetImageList(wxIMAGE_LIST_SMALL),
5856 -1,
5857 wxT("List control has an image list, OnGetItemImage or OnGetItemColumnImage should be overridden."));
5858 return -1;
5859 }
5860
5861 int wxGenericListCtrl::OnGetItemColumnImage(long item, long column) const
5862 {
5863 if (!column)
5864 return OnGetItemImage(item);
5865
5866 return -1;
5867 }
5868
5869 wxListItemAttr *
5870 wxGenericListCtrl::OnGetItemAttr(long WXUNUSED_UNLESS_DEBUG(item)) const
5871 {
5872 wxASSERT_MSG( item >= 0 && item < GetItemCount(),
5873 _T("invalid item index in OnGetItemAttr()") );
5874
5875 // no attributes by default
5876 return NULL;
5877 }
5878
5879 void wxGenericListCtrl::SetItemCount(long count)
5880 {
5881 wxASSERT_MSG( IsVirtual(), _T("this is for virtual controls only") );
5882
5883 m_mainWin->SetItemCount(count);
5884 }
5885
5886 void wxGenericListCtrl::RefreshItem(long item)
5887 {
5888 m_mainWin->RefreshLine(item);
5889 }
5890
5891 void wxGenericListCtrl::RefreshItems(long itemFrom, long itemTo)
5892 {
5893 m_mainWin->RefreshLines(itemFrom, itemTo);
5894 }
5895
5896 // Generic wxListCtrl is more or less a container for two other
5897 // windows which drawings are done upon. These are namely
5898 // 'm_headerWin' and 'm_mainWin'.
5899 // Here we override 'virtual wxWindow::Refresh()' to mimic the
5900 // behaviour wxListCtrl has under wxMSW.
5901 //
5902 void wxGenericListCtrl::Refresh(bool eraseBackground, const wxRect *rect)
5903 {
5904 if (!rect)
5905 {
5906 // The easy case, no rectangle specified.
5907 if (m_headerWin)
5908 m_headerWin->Refresh(eraseBackground);
5909
5910 if (m_mainWin)
5911 m_mainWin->Refresh(eraseBackground);
5912 }
5913 else
5914 {
5915 // Refresh the header window
5916 if (m_headerWin)
5917 {
5918 wxRect rectHeader = m_headerWin->GetRect();
5919 rectHeader.Intersect(*rect);
5920 if (rectHeader.GetWidth() && rectHeader.GetHeight())
5921 {
5922 int x, y;
5923 m_headerWin->GetPosition(&x, &y);
5924 rectHeader.Offset(-x, -y);
5925 m_headerWin->Refresh(eraseBackground, &rectHeader);
5926 }
5927 }
5928
5929 // Refresh the main window
5930 if (m_mainWin)
5931 {
5932 wxRect rectMain = m_mainWin->GetRect();
5933 rectMain.Intersect(*rect);
5934 if (rectMain.GetWidth() && rectMain.GetHeight())
5935 {
5936 int x, y;
5937 m_mainWin->GetPosition(&x, &y);
5938 rectMain.Offset(-x, -y);
5939 m_mainWin->Refresh(eraseBackground, &rectMain);
5940 }
5941 }
5942 }
5943 }
5944
5945 #endif // wxUSE_LISTCTRL