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