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