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