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