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