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