]> git.saurik.com Git - wxWidgets.git/blame - src/generic/listctrl.cpp
Fixed compile error on Wine due to type mismatch
[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
6cd53379 55#ifdef __WXGTK20__
ccdbdc89
RR
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,
a95d5751 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) )
6cd53379 1451#ifndef __WXGTK20__
ccdbdc89 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) )
6cd53379 1516#ifndef __WXGTK20__
ccdbdc89 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 2798 wxRect rect( GetLineHighlightRect( m_current ) );
6cd53379 2799#ifndef __WXGTK20__
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() );
a95d5751 2845
cf1dfa6b 2846 le.m_itemIndex = line;
05a7f61d
VZ
2847
2848 // set only for events which have position
2849 if ( point != wxDefaultPosition )
2850 le.m_pointDrag = point;
2851
c1c4c551
VZ
2852 // don't try to get the line info for virtual list controls: the main
2853 // program has it anyhow and if we did it would result in accessing all
2854 // the lines, even those which are not visible now and this is precisely
2855 // what we're trying to avoid
a95d5751 2856 if ( !IsVirtual() )
91c6cc0e 2857 {
0ddefeb0
VZ
2858 if ( line != (size_t)-1 )
2859 {
2860 GetLine(line)->GetItem( 0, le.m_item );
2861 }
2862 //else: this happens for wxEVT_COMMAND_LIST_ITEM_FOCUSED event
91c6cc0e
VZ
2863 }
2864 //else: there may be no more such item
2865
6e228e42 2866 GetParent()->GetEventHandler()->ProcessEvent( le );
e1e955e1 2867}
c801d85f 2868
0ddefeb0 2869void wxListMainWindow::ChangeCurrent(size_t current)
c801d85f 2870{
0ddefeb0 2871 m_current = current;
c801d85f 2872
0ddefeb0 2873 SendNotify(current, wxEVT_COMMAND_LIST_ITEM_FOCUSED);
e1e955e1 2874}
c801d85f 2875
26e8da41 2876wxTextCtrl *wxListMainWindow::EditLabel(long item, wxClassInfo* textControlClass)
c801d85f 2877{
26e8da41 2878 wxCHECK_MSG( (item >= 0) && ((size_t)item < GetItemCount()), NULL,
3cd94a0d 2879 wxT("wrong index in wxGenericListCtrl::EditLabel()") );
004fd0c8 2880
26e8da41
VZ
2881 wxASSERT_MSG( textControlClass->IsKindOf(CLASSINFO(wxTextCtrl)),
2882 wxT("EditLabel() needs a text control") );
2883
62d89eb4 2884 size_t itemEdit = (size_t)item;
e179bd65 2885
fd9811b1 2886 wxListEvent le( wxEVT_COMMAND_LIST_BEGIN_LABEL_EDIT, GetParent()->GetId() );
139adb6a 2887 le.SetEventObject( GetParent() );
1370703e 2888 le.m_itemIndex = item;
62d89eb4 2889 wxListLineData *data = GetLine(itemEdit);
26e8da41 2890 wxCHECK_MSG( data, NULL, _T("invalid index in EditLabel()") );
1370703e 2891 data->GetItem( 0, le.m_item );
277ea1b4 2892
62d89eb4 2893 if ( GetParent()->GetEventHandler()->ProcessEvent( le ) && !le.IsAllowed() )
26e8da41 2894 {
62d89eb4 2895 // vetoed by user code
26e8da41
VZ
2896 return NULL;
2897 }
004fd0c8 2898
cf1dfa6b
VZ
2899 // We have to call this here because the label in question might just have
2900 // been added and no screen update taken place.
62d89eb4 2901 if ( m_dirty )
cf1dfa6b 2902 wxSafeYield();
004fd0c8 2903
26e8da41
VZ
2904 wxTextCtrl * const text = (wxTextCtrl *)textControlClass->CreateObject();
2905 m_textctrlWrapper = new wxListTextCtrlWrapper(this, text, item);
2906 return m_textctrlWrapper->GetText();
e1e955e1 2907}
c801d85f 2908
e179bd65
RR
2909void wxListMainWindow::OnRenameTimer()
2910{
cf1dfa6b 2911 wxCHECK_RET( HasCurrent(), wxT("unexpected rename timer") );
004fd0c8 2912
cf1dfa6b 2913 EditLabel( m_current );
e179bd65
RR
2914}
2915
62d89eb4 2916bool wxListMainWindow::OnRenameAccept(size_t itemEdit, const wxString& value)
c801d85f 2917{
e179bd65
RR
2918 wxListEvent le( wxEVT_COMMAND_LIST_END_LABEL_EDIT, GetParent()->GetId() );
2919 le.SetEventObject( GetParent() );
62d89eb4 2920 le.m_itemIndex = itemEdit;
1370703e 2921
62d89eb4 2922 wxListLineData *data = GetLine(itemEdit);
277ea1b4 2923
ca65c044 2924 wxCHECK_MSG( data, false, _T("invalid index in OnRenameAccept()") );
1370703e
VZ
2925
2926 data->GetItem( 0, le.m_item );
62d89eb4
VZ
2927 le.m_item.m_text = value;
2928 return !GetParent()->GetEventHandler()->ProcessEvent( le ) ||
2929 le.IsAllowed();
e1e955e1 2930}
c801d85f 2931
18dd54e3 2932void wxListMainWindow::OnRenameCancelled(size_t itemEdit)
86586459 2933{
86586459
RR
2934 // let owner know that the edit was cancelled
2935 wxListEvent le( wxEVT_COMMAND_LIST_END_LABEL_EDIT, GetParent()->GetId() );
86351e4a 2936
ca65c044 2937 le.SetEditCanceled(true);
86351e4a 2938
86586459
RR
2939 le.SetEventObject( GetParent() );
2940 le.m_itemIndex = itemEdit;
2941
2942 wxListLineData *data = GetLine(itemEdit);
2943 wxCHECK_RET( data, _T("invalid index in OnRenameCancelled()") );
2944
2945 data->GetItem( 0, le.m_item );
86586459
RR
2946 GetEventHandler()->ProcessEvent( le );
2947}
2948
c801d85f
KB
2949void wxListMainWindow::OnMouse( wxMouseEvent &event )
2950{
8b1464af 2951
b6bc47ef
RD
2952#ifdef __WXMAC__
2953 // On wxMac we can't depend on the EVT_KILL_FOCUS event to properly
2954 // shutdown the edit control when the mouse is clicked elsewhere on the
2955 // listctrl because the order of events is different (or something like
277ea1b4 2956 // that), so explicitly end the edit if it is active.
26e8da41
VZ
2957 if ( event.LeftDown() && m_textctrlWrapper )
2958 m_textctrlWrapper->AcceptChangesAndFinish();
2959#endif // __WXMAC__
277ea1b4 2960
3e1c4e00 2961 event.SetEventObject( GetParent() );
cf1dfa6b
VZ
2962 if ( GetParent()->GetEventHandler()->ProcessEvent( event) )
2963 return;
2964
185f6036
RD
2965 if (event.GetEventType() == wxEVT_MOUSEWHEEL)
2966 {
2967 // let the base handle mouse wheel events.
2968 event.Skip();
2969 return;
2970 }
2ac08aeb 2971
cf1dfa6b 2972 if ( !HasCurrent() || IsEmpty() )
8b1464af
RR
2973 {
2974 if (event.RightDown())
2975 {
2976 SendNotify( (size_t)-1, wxEVT_COMMAND_LIST_ITEM_RIGHT_CLICK, event.GetPosition() );
2977 // Allow generation of context menu event
2978 event.Skip();
2979 }
cf1dfa6b 2980 return;
8b1464af 2981 }
cf1dfa6b
VZ
2982
2983 if (m_dirty)
2984 return;
e3e65dac 2985
cf1dfa6b
VZ
2986 if ( !(event.Dragging() || event.ButtonDown() || event.LeftUp() ||
2987 event.ButtonDClick()) )
2988 return;
c801d85f 2989
aaef15bf
RR
2990 int x = event.GetX();
2991 int y = event.GetY();
2992 CalcUnscrolledPosition( x, y, &x, &y );
004fd0c8 2993
cc734310 2994 // where did we hit it (if we did)?
92976ab6 2995 long hitResult = 0;
1370703e 2996
cf1dfa6b
VZ
2997 size_t count = GetItemCount(),
2998 current;
2999
b5d43d1d 3000 if ( InReportView() )
92976ab6 3001 {
5cd89174 3002 current = y / GetLineHeight();
cc734310
VZ
3003 if ( current < count )
3004 hitResult = HitTestLine(current, x, y);
cf1dfa6b
VZ
3005 }
3006 else // !report
3007 {
3008 // TODO: optimize it too! this is less simple than for report view but
3009 // enumerating all items is still not a way to do it!!
4e3ace65 3010 for ( current = 0; current < count; current++ )
cf1dfa6b 3011 {
5cd89174 3012 hitResult = HitTestLine(current, x, y);
4e3ace65
VZ
3013 if ( hitResult )
3014 break;
cf1dfa6b 3015 }
92976ab6 3016 }
bd8289c1 3017
fd9811b1 3018 if (event.Dragging())
92976ab6 3019 {
fd9811b1 3020 if (m_dragCount == 0)
8d1d2284
VZ
3021 {
3022 // we have to report the raw, physical coords as we want to be
3023 // able to call HitTest(event.m_pointDrag) from the user code to
3024 // get the item being dragged
3025 m_dragStart = event.GetPosition();
3026 }
bffa1c77 3027
fd9811b1 3028 m_dragCount++;
bffa1c77 3029
cf1dfa6b
VZ
3030 if (m_dragCount != 3)
3031 return;
bffa1c77 3032
05a7f61d
VZ
3033 int command = event.RightIsDown() ? wxEVT_COMMAND_LIST_BEGIN_RDRAG
3034 : wxEVT_COMMAND_LIST_BEGIN_DRAG;
bffa1c77 3035
fd9811b1 3036 wxListEvent le( command, GetParent()->GetId() );
92976ab6 3037 le.SetEventObject( GetParent() );
8df44392 3038 le.m_itemIndex = m_lineLastClicked;
bffa1c77
VZ
3039 le.m_pointDrag = m_dragStart;
3040 GetParent()->GetEventHandler()->ProcessEvent( le );
3041
3042 return;
92976ab6 3043 }
fd9811b1
RR
3044 else
3045 {
3046 m_dragCount = 0;
3047 }
bd8289c1 3048
cf1dfa6b
VZ
3049 if ( !hitResult )
3050 {
8b1464af
RR
3051 // outside of any item
3052 if (event.RightDown())
3053 {
3054 SendNotify( (size_t) -1, wxEVT_COMMAND_LIST_ITEM_RIGHT_CLICK, event.GetPosition() );
3055 // Allow generation of context menu event
3056 event.Skip();
3057 }
3058 else
3059 {
3060 // reset the selection and bail out
3061 HighlightAll(false);
3062 }
cf76cd4e 3063
cf1dfa6b
VZ
3064 return;
3065 }
bd8289c1 3066
ca65c044 3067 bool forceClick = false;
92976ab6
RR
3068 if (event.ButtonDClick())
3069 {
92976ab6 3070 m_renameTimer->Stop();
ca65c044 3071 m_lastOnSame = false;
efbb7287 3072
ddba340d 3073 if ( current == m_lineLastClicked )
efbb7287 3074 {
cf1dfa6b 3075 SendNotify( current, wxEVT_COMMAND_LIST_ITEM_ACTIVATED );
004fd0c8 3076
efbb7287
VZ
3077 return;
3078 }
3079 else
3080 {
8df44392 3081 // The first click was on another item, so don't interpret this as
efbb7287 3082 // a double click, but as a simple click instead
ca65c044 3083 forceClick = true;
efbb7287 3084 }
92976ab6 3085 }
bd8289c1 3086
8df44392 3087 if (event.LeftUp())
c801d85f 3088 {
277ea1b4 3089 if (m_lineSelectSingleOnUp != (size_t)-1)
92976ab6 3090 {
8df44392
RR
3091 // select single line
3092 HighlightAll( false );
3093 ReverseHighlight(m_lineSelectSingleOnUp);
3094 }
277ea1b4 3095
2cb1f3da 3096 if (m_lastOnSame)
8df44392
RR
3097 {
3098 if ((current == m_current) &&
3099 (hitResult == wxLIST_HITTEST_ONITEMLABEL) &&
2cb1f3da 3100 HasFlag(wxLC_EDIT_LABELS) )
8df44392
RR
3101 {
3102 m_renameTimer->Start( 100, true );
3103 }
92976ab6 3104 }
277ea1b4 3105
ca65c044 3106 m_lastOnSame = false;
277ea1b4 3107 m_lineSelectSingleOnUp = (size_t)-1;
8df44392
RR
3108 }
3109 else
3110 {
3103e8a9 3111 // This is necessary, because after a DnD operation in
2997ca30 3112 // from and to ourself, the up event is swallowed by the
8df44392
RR
3113 // DnD code. So on next non-up event (which means here and
3114 // now) m_lineSelectSingleOnUp should be reset.
277ea1b4 3115 m_lineSelectSingleOnUp = (size_t)-1;
e1e955e1 3116 }
8df44392 3117 if (event.RightDown())
b204641e 3118 {
8df44392
RR
3119 m_lineBeforeLastClicked = m_lineLastClicked;
3120 m_lineLastClicked = current;
277ea1b4 3121
eaefbb88
KH
3122 // If the item is already selected, do not update the selection.
3123 // Multi-selections should not be cleared if a selected item is clicked.
3124 if (!IsHighlighted(current))
3125 {
3126 HighlightAll(false);
3127 ChangeCurrent(current);
3128 ReverseHighlight(m_current);
3129 }
277ea1b4
DS
3130
3131 SendNotify( current, wxEVT_COMMAND_LIST_ITEM_RIGHT_CLICK, event.GetPosition() );
3132
18216ae3
RR
3133 // Allow generation of context menu event
3134 event.Skip();
b204641e 3135 }
cf1dfa6b 3136 else if (event.MiddleDown())
b204641e 3137 {
cf1dfa6b 3138 SendNotify( current, wxEVT_COMMAND_LIST_ITEM_MIDDLE_CLICK );
92976ab6 3139 }
cf1dfa6b 3140 else if ( event.LeftDown() || forceClick )
92976ab6 3141 {
efbb7287 3142 m_lineBeforeLastClicked = m_lineLastClicked;
cf1dfa6b
VZ
3143 m_lineLastClicked = current;
3144
3145 size_t oldCurrent = m_current;
2cb1f3da
JS
3146 bool oldWasSelected = IsHighlighted(m_current);
3147
39e39d39 3148 bool cmdModifierDown = event.CmdDown();
2fe417e4 3149 if ( IsSingleSel() || !(cmdModifierDown || event.ShiftDown()) )
8df44392 3150 {
277ea1b4 3151 if ( IsSingleSel() || !IsHighlighted(current) )
eb3d60a2
KH
3152 {
3153 HighlightAll( false );
0ddefeb0 3154
eb3d60a2 3155 ChangeCurrent(current);
cf1dfa6b 3156
eb3d60a2
KH
3157 ReverseHighlight(m_current);
3158 }
3159 else // multi sel & current is highlighted & no mod keys
8df44392 3160 {
2997ca30 3161 m_lineSelectSingleOnUp = current;
8df44392
RR
3162 ChangeCurrent(current); // change focus
3163 }
e1e955e1 3164 }
b54e41c5 3165 else // multi sel & either ctrl or shift is down
b204641e 3166 {
015fd9ef 3167 if (cmdModifierDown)
92976ab6 3168 {
0ddefeb0 3169 ChangeCurrent(current);
cf1dfa6b 3170
b54e41c5 3171 ReverseHighlight(m_current);
92976ab6 3172 }
473d087e 3173 else if (event.ShiftDown())
92976ab6 3174 {
0ddefeb0 3175 ChangeCurrent(current);
bffa1c77 3176
cf1dfa6b
VZ
3177 size_t lineFrom = oldCurrent,
3178 lineTo = current;
f6bcfd97 3179
cf1dfa6b 3180 if ( lineTo < lineFrom )
92976ab6 3181 {
cf1dfa6b
VZ
3182 lineTo = lineFrom;
3183 lineFrom = m_current;
92976ab6
RR
3184 }
3185
b54e41c5 3186 HighlightLines(lineFrom, lineTo);
92976ab6 3187 }
cf1dfa6b 3188 else // !ctrl, !shift
92976ab6 3189 {
cf1dfa6b
VZ
3190 // test in the enclosing if should make it impossible
3191 wxFAIL_MSG( _T("how did we get here?") );
92976ab6 3192 }
e1e955e1 3193 }
cf1dfa6b 3194
92976ab6 3195 if (m_current != oldCurrent)
92976ab6 3196 RefreshLine( oldCurrent );
efbb7287
VZ
3197
3198 // forceClick is only set if the previous click was on another item
2cb1f3da 3199 m_lastOnSame = !forceClick && (m_current == oldCurrent) && oldWasSelected;
e1e955e1 3200 }
e1e955e1 3201}
c801d85f 3202
34bbbc27 3203void wxListMainWindow::MoveToItem(size_t item)
c801d85f 3204{
34bbbc27 3205 if ( item == (size_t)-1 )
cf1dfa6b 3206 return;
004fd0c8 3207
34bbbc27 3208 wxRect rect = GetLineRect(item);
cf3da716 3209
cf1dfa6b 3210 int client_w, client_h;
cf3da716 3211 GetClientSize( &client_w, &client_h );
f6bcfd97 3212
6d78bbe6
VZ
3213 const int hLine = GetLineHeight();
3214
277ea1b4
DS
3215 int view_x = SCROLL_UNIT_X * GetScrollPos( wxHORIZONTAL );
3216 int view_y = hLine * GetScrollPos( wxVERTICAL );
004fd0c8 3217
b5d43d1d 3218 if ( InReportView() )
92976ab6 3219 {
277ea1b4
DS
3220 // the next we need the range of lines shown it might be different,
3221 // so recalculate it
b54e41c5
VZ
3222 ResetVisibleLinesRange();
3223
277ea1b4
DS
3224 if (rect.y < view_y)
3225 Scroll( -1, rect.y / hLine );
3226 if (rect.y + rect.height + 5 > view_y + client_h)
3227 Scroll( -1, (rect.y + rect.height - client_h + hLine) / hLine );
92976ab6 3228 }
b54e41c5 3229 else // !report
92976ab6 3230 {
807a572e
RR
3231 if (rect.x-view_x < 5)
3232 Scroll( (rect.x - 5) / SCROLL_UNIT_X, -1 );
3233 if (rect.x + rect.width - 5 > view_x + client_w)
3234 Scroll( (rect.x + rect.width - client_w + SCROLL_UNIT_X) / SCROLL_UNIT_X, -1 );
92976ab6 3235 }
e1e955e1 3236}
c801d85f 3237
cf1dfa6b
VZ
3238// ----------------------------------------------------------------------------
3239// keyboard handling
3240// ----------------------------------------------------------------------------
3241
3242void wxListMainWindow::OnArrowChar(size_t newCurrent, const wxKeyEvent& event)
c801d85f 3243{
cf1dfa6b
VZ
3244 wxCHECK_RET( newCurrent < (size_t)GetItemCount(),
3245 _T("invalid item index in OnArrowChar()") );
3246
3247 size_t oldCurrent = m_current;
3248
3249 // in single selection we just ignore Shift as we can't select several
3250 // items anyhow
b54e41c5 3251 if ( event.ShiftDown() && !IsSingleSel() )
cf1dfa6b 3252 {
0ddefeb0 3253 ChangeCurrent(newCurrent);
cf1dfa6b 3254
65a1f350
RR
3255 // refresh the old focus to remove it
3256 RefreshLine( oldCurrent );
3257
cf1dfa6b
VZ
3258 // select all the items between the old and the new one
3259 if ( oldCurrent > newCurrent )
3260 {
3261 newCurrent = oldCurrent;
3262 oldCurrent = m_current;
3263 }
3264
b54e41c5 3265 HighlightLines(oldCurrent, newCurrent);
cf1dfa6b
VZ
3266 }
3267 else // !shift
3268 {
b54e41c5
VZ
3269 // all previously selected items are unselected unless ctrl is held
3270 if ( !event.ControlDown() )
ca65c044 3271 HighlightAll(false);
b54e41c5 3272
0ddefeb0 3273 ChangeCurrent(newCurrent);
ca65c044 3274
65a1f350
RR
3275 // refresh the old focus to remove it
3276 RefreshLine( oldCurrent );
cf1dfa6b
VZ
3277
3278 if ( !event.ControlDown() )
3279 {
ca65c044 3280 HighlightLine( m_current, true );
cf1dfa6b
VZ
3281 }
3282 }
ca65c044 3283
92976ab6 3284 RefreshLine( m_current );
cf1dfa6b 3285
cf3da716 3286 MoveToFocus();
e1e955e1 3287}
c801d85f 3288
3dfb93fd
RR
3289void wxListMainWindow::OnKeyDown( wxKeyEvent &event )
3290{
3291 wxWindow *parent = GetParent();
004fd0c8 3292
277ea1b4 3293 // propagate the key event upwards
3dfb93fd
RR
3294 wxKeyEvent ke( wxEVT_KEY_DOWN );
3295 ke.m_shiftDown = event.m_shiftDown;
3296 ke.m_controlDown = event.m_controlDown;
3297 ke.m_altDown = event.m_altDown;
3298 ke.m_metaDown = event.m_metaDown;
3299 ke.m_keyCode = event.m_keyCode;
3300 ke.m_x = event.m_x;
3301 ke.m_y = event.m_y;
3302 ke.SetEventObject( parent );
3303 if (parent->GetEventHandler()->ProcessEvent( ke )) return;
004fd0c8 3304
3dfb93fd
RR
3305 event.Skip();
3306}
004fd0c8 3307
c801d85f
KB
3308void wxListMainWindow::OnChar( wxKeyEvent &event )
3309{
51cc4dad 3310 wxWindow *parent = GetParent();
004fd0c8 3311
277ea1b4 3312 // send a list_key event up
cf1dfa6b 3313 if ( HasCurrent() )
f6bcfd97
BP
3314 {
3315 wxListEvent le( wxEVT_COMMAND_LIST_KEY_DOWN, GetParent()->GetId() );
cf1dfa6b
VZ
3316 le.m_itemIndex = m_current;
3317 GetLine(m_current)->GetItem( 0, le.m_item );
12a3f227 3318 le.m_code = event.GetKeyCode();
f6bcfd97
BP
3319 le.SetEventObject( parent );
3320 parent->GetEventHandler()->ProcessEvent( le );
3321 }
51cc4dad 3322
277ea1b4 3323 // propagate the char event upwards
3dfb93fd 3324 wxKeyEvent ke( wxEVT_CHAR );
51cc4dad
RR
3325 ke.m_shiftDown = event.m_shiftDown;
3326 ke.m_controlDown = event.m_controlDown;
3327 ke.m_altDown = event.m_altDown;
3328 ke.m_metaDown = event.m_metaDown;
3329 ke.m_keyCode = event.m_keyCode;
3330 ke.m_x = event.m_x;
3331 ke.m_y = event.m_y;
3332 ke.SetEventObject( parent );
3333 if (parent->GetEventHandler()->ProcessEvent( ke )) return;
004fd0c8 3334
12a3f227 3335 if (event.GetKeyCode() == WXK_TAB)
012a03e0
RR
3336 {
3337 wxNavigationKeyEvent nevent;
c5145d41 3338 nevent.SetWindowChange( event.ControlDown() );
012a03e0 3339 nevent.SetDirection( !event.ShiftDown() );
8253c7fd 3340 nevent.SetEventObject( GetParent()->GetParent() );
012a03e0 3341 nevent.SetCurrentFocus( m_parent );
87948f22
VZ
3342 if (GetParent()->GetParent()->GetEventHandler()->ProcessEvent( nevent ))
3343 return;
012a03e0 3344 }
004fd0c8 3345
277ea1b4 3346 // no item -> nothing to do
cf1dfa6b 3347 if (!HasCurrent())
c801d85f 3348 {
51cc4dad
RR
3349 event.Skip();
3350 return;
e1e955e1 3351 }
51cc4dad 3352
cf76cd4e
VZ
3353 // don't use m_linesPerPage directly as it might not be computed yet
3354 const int pageSize = GetCountPerPage();
3355 wxCHECK_RET( pageSize, _T("should have non zero page size") );
3356
03703fc0
RR
3357 if (GetLayoutDirection() == wxLayout_RightToLeft)
3358 {
3359 if (event.GetKeyCode() == WXK_RIGHT)
3360 event.m_keyCode = WXK_LEFT;
3361 else if (event.GetKeyCode() == WXK_LEFT)
3362 event.m_keyCode = WXK_RIGHT;
3363 }
3364
cf76cd4e 3365 switch ( event.GetKeyCode() )
c801d85f 3366 {
51cc4dad 3367 case WXK_UP:
cf1dfa6b
VZ
3368 if ( m_current > 0 )
3369 OnArrowChar( m_current - 1, event );
51cc4dad 3370 break;
cf1dfa6b 3371
51cc4dad 3372 case WXK_DOWN:
cf1dfa6b
VZ
3373 if ( m_current < (size_t)GetItemCount() - 1 )
3374 OnArrowChar( m_current + 1, event );
51cc4dad 3375 break;
cf1dfa6b 3376
51cc4dad 3377 case WXK_END:
1370703e 3378 if (!IsEmpty())
cf1dfa6b 3379 OnArrowChar( GetItemCount() - 1, event );
51cc4dad 3380 break;
cf1dfa6b 3381
51cc4dad 3382 case WXK_HOME:
1370703e 3383 if (!IsEmpty())
cf1dfa6b 3384 OnArrowChar( 0, event );
51cc4dad 3385 break;
cf1dfa6b 3386
faa94f3e 3387 case WXK_PAGEUP:
f6bcfd97 3388 {
cf76cd4e
VZ
3389 int steps = InReportView() ? pageSize - 1
3390 : m_current % pageSize;
cf1dfa6b
VZ
3391
3392 int index = m_current - steps;
3393 if (index < 0)
3394 index = 0;
3395
3396 OnArrowChar( index, event );
51cc4dad 3397 }
51cc4dad 3398 break;
cf1dfa6b 3399
faa94f3e 3400 case WXK_PAGEDOWN:
bffa1c77 3401 {
b5d43d1d 3402 int steps = InReportView()
cf76cd4e
VZ
3403 ? pageSize - 1
3404 : pageSize - (m_current % pageSize) - 1;
f6bcfd97 3405
cf1dfa6b
VZ
3406 size_t index = m_current + steps;
3407 size_t count = GetItemCount();
3408 if ( index >= count )
3409 index = count - 1;
3410
3411 OnArrowChar( index, event );
51cc4dad 3412 }
51cc4dad 3413 break;
cf1dfa6b 3414
51cc4dad 3415 case WXK_LEFT:
b5d43d1d 3416 if ( !InReportView() )
51cc4dad 3417 {
cf76cd4e 3418 int index = m_current - pageSize;
cf1dfa6b
VZ
3419 if (index < 0)
3420 index = 0;
3421
3422 OnArrowChar( index, event );
51cc4dad
RR
3423 }
3424 break;
cf1dfa6b 3425
51cc4dad 3426 case WXK_RIGHT:
b5d43d1d 3427 if ( !InReportView() )
51cc4dad 3428 {
cf76cd4e 3429 size_t index = m_current + pageSize;
cf1dfa6b
VZ
3430
3431 size_t count = GetItemCount();
3432 if ( index >= count )
3433 index = count - 1;
3434
3435 OnArrowChar( index, event );
51cc4dad
RR
3436 }
3437 break;
cf1dfa6b 3438
51cc4dad 3439 case WXK_SPACE:
b54e41c5 3440 if ( IsSingleSel() )
33d0e17c 3441 {
87948f22 3442 SendNotify( m_current, wxEVT_COMMAND_LIST_ITEM_ACTIVATED );
70541533
VZ
3443
3444 if ( IsHighlighted(m_current) )
3445 {
3446 // don't unselect the item in single selection mode
3447 break;
3448 }
3449 //else: select it in ReverseHighlight() below if unselected
33d0e17c 3450 }
70541533
VZ
3451
3452 ReverseHighlight(m_current);
51cc4dad 3453 break;
cf1dfa6b 3454
51cc4dad
RR
3455 case WXK_RETURN:
3456 case WXK_EXECUTE:
87948f22 3457 SendNotify( m_current, wxEVT_COMMAND_LIST_ITEM_ACTIVATED );
51cc4dad 3458 break;
cf1dfa6b 3459
51cc4dad 3460 default:
51cc4dad 3461 event.Skip();
e1e955e1 3462 }
e1e955e1 3463}
c801d85f 3464
cf1dfa6b
VZ
3465// ----------------------------------------------------------------------------
3466// focus handling
3467// ----------------------------------------------------------------------------
3468
c801d85f
KB
3469void wxListMainWindow::OnSetFocus( wxFocusEvent &WXUNUSED(event) )
3470{
dc76287d
RD
3471 if ( GetParent() )
3472 {
3473 wxFocusEvent event( wxEVT_SET_FOCUS, GetParent()->GetId() );
3474 event.SetEventObject( GetParent() );
3475 if ( GetParent()->GetEventHandler()->ProcessEvent( event) )
3476 return;
3477 }
3478
bde9072f
VZ
3479 // wxGTK sends us EVT_SET_FOCUS events even if we had never got
3480 // EVT_KILL_FOCUS before which means that we finish by redrawing the items
3481 // which are already drawn correctly resulting in horrible flicker - avoid
3482 // it
47724389
VZ
3483 if ( !m_hasFocus )
3484 {
ca65c044 3485 m_hasFocus = true;
bde9072f 3486
47724389
VZ
3487 RefreshSelected();
3488 }
e1e955e1 3489}
c801d85f
KB
3490
3491void wxListMainWindow::OnKillFocus( wxFocusEvent &WXUNUSED(event) )
3492{
dc76287d
RD
3493 if ( GetParent() )
3494 {
3495 wxFocusEvent event( wxEVT_KILL_FOCUS, GetParent()->GetId() );
3496 event.SetEventObject( GetParent() );
3497 if ( GetParent()->GetEventHandler()->ProcessEvent( event) )
3498 return;
3499 }
277ea1b4 3500
ca65c044 3501 m_hasFocus = false;
49ecb029 3502 RefreshSelected();
e1e955e1 3503}
c801d85f 3504
1e6d9499 3505void wxListMainWindow::DrawImage( int index, wxDC *dc, int x, int y )
c801d85f 3506{
cf1dfa6b 3507 if ( HasFlag(wxLC_ICON) && (m_normal_image_list))
63852e78
RR
3508 {
3509 m_normal_image_list->Draw( index, *dc, x, y, wxIMAGELIST_DRAW_TRANSPARENT );
63852e78 3510 }
cf1dfa6b 3511 else if ( HasFlag(wxLC_SMALL_ICON) && (m_small_image_list))
63852e78
RR
3512 {
3513 m_small_image_list->Draw( index, *dc, x, y, wxIMAGELIST_DRAW_TRANSPARENT );
3514 }
cf1dfa6b 3515 else if ( HasFlag(wxLC_LIST) && (m_small_image_list))
0b855868
RR
3516 {
3517 m_small_image_list->Draw( index, *dc, x, y, wxIMAGELIST_DRAW_TRANSPARENT );
3518 }
b5d43d1d 3519 else if ( InReportView() && (m_small_image_list))
63852e78
RR
3520 {
3521 m_small_image_list->Draw( index, *dc, x, y, wxIMAGELIST_DRAW_TRANSPARENT );
63852e78 3522 }
e1e955e1 3523}
c801d85f 3524
5cd89174 3525void wxListMainWindow::GetImageSize( int index, int &width, int &height ) const
c801d85f 3526{
cf1dfa6b 3527 if ( HasFlag(wxLC_ICON) && m_normal_image_list )
63852e78
RR
3528 {
3529 m_normal_image_list->GetSize( index, width, height );
63852e78 3530 }
cf1dfa6b 3531 else if ( HasFlag(wxLC_SMALL_ICON) && m_small_image_list )
63852e78
RR
3532 {
3533 m_small_image_list->GetSize( index, width, height );
63852e78 3534 }
cf1dfa6b 3535 else if ( HasFlag(wxLC_LIST) && m_small_image_list )
0b855868
RR
3536 {
3537 m_small_image_list->GetSize( index, width, height );
0b855868 3538 }
b5d43d1d 3539 else if ( InReportView() && m_small_image_list )
63852e78
RR
3540 {
3541 m_small_image_list->GetSize( index, width, height );
63852e78 3542 }
cf1dfa6b
VZ
3543 else
3544 {
3545 width =
3546 height = 0;
3547 }
e1e955e1 3548}
c801d85f 3549
5cd89174 3550int wxListMainWindow::GetTextLength( const wxString &s ) const
c801d85f 3551{
5cd89174 3552 wxClientDC dc( wxConstCast(this, wxListMainWindow) );
cf1dfa6b 3553 dc.SetFont( GetFont() );
c801d85f 3554
cf1dfa6b
VZ
3555 wxCoord lw;
3556 dc.GetTextExtent( s, &lw, NULL );
3557
3558 return lw + AUTOSIZE_COL_MARGIN;
e1e955e1 3559}
c801d85f 3560
8a3e173a 3561void wxListMainWindow::SetImageList( wxImageList *imageList, int which )
c801d85f 3562{
ca65c044 3563 m_dirty = true;
f6bcfd97
BP
3564
3565 // calc the spacing from the icon size
277ea1b4
DS
3566 int width = 0, height = 0;
3567
f6bcfd97 3568 if ((imageList) && (imageList->GetImageCount()) )
f6bcfd97 3569 imageList->GetSize(0, width, height);
f6bcfd97
BP
3570
3571 if (which == wxIMAGE_LIST_NORMAL)
3572 {
3573 m_normal_image_list = imageList;
3574 m_normal_spacing = width + 8;
3575 }
3576
3577 if (which == wxIMAGE_LIST_SMALL)
3578 {
3579 m_small_image_list = imageList;
3580 m_small_spacing = width + 14;
ca7353de 3581 m_lineHeight = 0; // ensure that the line height will be recalc'd
f6bcfd97 3582 }
e1e955e1 3583}
c801d85f 3584
debe6624 3585void wxListMainWindow::SetItemSpacing( int spacing, bool isSmall )
c801d85f 3586{
ca65c044 3587 m_dirty = true;
139adb6a 3588 if (isSmall)
139adb6a 3589 m_small_spacing = spacing;
139adb6a 3590 else
139adb6a 3591 m_normal_spacing = spacing;
e1e955e1 3592}
c801d85f 3593
debe6624 3594int wxListMainWindow::GetItemSpacing( bool isSmall )
c801d85f 3595{
f6bcfd97 3596 return isSmall ? m_small_spacing : m_normal_spacing;
e1e955e1 3597}
c801d85f 3598
cf1dfa6b
VZ
3599// ----------------------------------------------------------------------------
3600// columns
3601// ----------------------------------------------------------------------------
3602
debe6624 3603void wxListMainWindow::SetColumn( int col, wxListItem &item )
c801d85f 3604{
222ed1d6 3605 wxListHeaderDataList::compatibility_iterator node = m_columns.Item( col );
f6bcfd97 3606
cf1dfa6b
VZ
3607 wxCHECK_RET( node, _T("invalid column index in SetColumn") );
3608
3609 if ( item.m_width == wxLIST_AUTOSIZE_USEHEADER )
3610 item.m_width = GetTextLength( item.m_text );
3611
3612 wxListHeaderData *column = node->GetData();
3613 column->SetItem( item );
3614
3615 wxListHeaderWindow *headerWin = GetListCtrl()->m_headerWin;
f6bcfd97 3616 if ( headerWin )
ca65c044 3617 headerWin->m_dirty = true;
cf1dfa6b 3618
ca65c044 3619 m_dirty = true;
cf1dfa6b
VZ
3620
3621 // invalidate it as it has to be recalculated
3622 m_headerWidth = 0;
e1e955e1 3623}
c801d85f 3624
debe6624 3625void wxListMainWindow::SetColumnWidth( int col, int width )
c801d85f 3626{
cf1dfa6b
VZ
3627 wxCHECK_RET( col >= 0 && col < GetColumnCount(),
3628 _T("invalid column index") );
3629
b5d43d1d 3630 wxCHECK_RET( InReportView(),
f6bcfd97 3631 _T("SetColumnWidth() can only be called in report mode.") );
0208334d 3632
ca65c044 3633 m_dirty = true;
abe4a4f1
VS
3634 wxListHeaderWindow *headerWin = GetListCtrl()->m_headerWin;
3635 if ( headerWin )
ca65c044 3636 headerWin->m_dirty = true;
bd8289c1 3637
222ed1d6 3638 wxListHeaderDataList::compatibility_iterator node = m_columns.Item( col );
cf1dfa6b
VZ
3639 wxCHECK_RET( node, _T("no column?") );
3640
3641 wxListHeaderData *column = node->GetData();
3642
3643 size_t count = GetItemCount();
3644
f6bcfd97
BP
3645 if (width == wxLIST_AUTOSIZE_USEHEADER)
3646 {
cf1dfa6b 3647 width = GetTextLength(column->GetText());
f6bcfd97 3648 }
cf1dfa6b 3649 else if ( width == wxLIST_AUTOSIZE )
0180dad6 3650 {
cf1dfa6b
VZ
3651 if ( IsVirtual() )
3652 {
3653 // TODO: determine the max width somehow...
3654 width = WIDTH_COL_DEFAULT;
3655 }
3656 else // !virtual
0180dad6 3657 {
cf1dfa6b
VZ
3658 wxClientDC dc(this);
3659 dc.SetFont( GetFont() );
3660
3661 int max = AUTOSIZE_COL_MARGIN;
3662
7d4813a0
VZ
3663 // if the cached column width isn't valid then recalculate it
3664 if (m_aColWidths.Item(col)->bNeedsUpdate)
0180dad6 3665 {
7d4813a0
VZ
3666 for (size_t i = 0; i < count; i++)
3667 {
277ea1b4 3668 wxListLineData *line = GetLine( i );
7d4813a0 3669 wxListItemDataList::compatibility_iterator n = line->m_items.Item( col );
cf1dfa6b 3670
7d4813a0 3671 wxCHECK_RET( n, _T("no subitem?") );
cf1dfa6b 3672
7d4813a0
VZ
3673 wxListItemData *itemData = n->GetData();
3674 wxListItem item;
cf1dfa6b 3675
7d4813a0
VZ
3676 itemData->GetItem(item);
3677 int itemWidth = GetItemWidthWithImage(&item);
3678 if (itemWidth > max)
3679 max = itemWidth;
bffa1c77 3680 }
cf1dfa6b 3681
7d4813a0
VZ
3682 m_aColWidths.Item(col)->bNeedsUpdate = false;
3683 m_aColWidths.Item(col)->nMaxWidth = max;
0180dad6 3684 }
cf1dfa6b 3685
7d4813a0 3686 max = m_aColWidths.Item(col)->nMaxWidth;
cf1dfa6b 3687 width = max + AUTOSIZE_COL_MARGIN;
0180dad6 3688 }
0180dad6
RR
3689 }
3690
cf1dfa6b 3691 column->SetWidth( width );
bd8289c1 3692
cf1dfa6b
VZ
3693 // invalidate it as it has to be recalculated
3694 m_headerWidth = 0;
3695}
3696
3697int wxListMainWindow::GetHeaderWidth() const
3698{
3699 if ( !m_headerWidth )
0208334d 3700 {
cf1dfa6b
VZ
3701 wxListMainWindow *self = wxConstCast(this, wxListMainWindow);
3702
3703 size_t count = GetColumnCount();
3704 for ( size_t col = 0; col < count; col++ )
63852e78 3705 {
cf1dfa6b 3706 self->m_headerWidth += GetColumnWidth(col);
63852e78 3707 }
0208334d 3708 }
bd8289c1 3709
cf1dfa6b 3710 return m_headerWidth;
e1e955e1 3711}
c801d85f 3712
cf1dfa6b 3713void wxListMainWindow::GetColumn( int col, wxListItem &item ) const
c801d85f 3714{
222ed1d6 3715 wxListHeaderDataList::compatibility_iterator node = m_columns.Item( col );
cf1dfa6b
VZ
3716 wxCHECK_RET( node, _T("invalid column index in GetColumn") );
3717
3718 wxListHeaderData *column = node->GetData();
3719 column->GetItem( item );
e1e955e1 3720}
c801d85f 3721
cf1dfa6b 3722int wxListMainWindow::GetColumnWidth( int col ) const
c801d85f 3723{
222ed1d6 3724 wxListHeaderDataList::compatibility_iterator node = m_columns.Item( col );
24b9f055
VZ
3725 wxCHECK_MSG( node, 0, _T("invalid column index") );
3726
3727 wxListHeaderData *column = node->GetData();
3728 return column->GetWidth();
e1e955e1 3729}
c801d85f 3730
cf1dfa6b
VZ
3731// ----------------------------------------------------------------------------
3732// item state
3733// ----------------------------------------------------------------------------
c801d85f
KB
3734
3735void wxListMainWindow::SetItem( wxListItem &item )
3736{
cf1dfa6b
VZ
3737 long id = item.m_itemId;
3738 wxCHECK_RET( id >= 0 && (size_t)id < GetItemCount(),
3739 _T("invalid item index in SetItem") );
3740
6c02c329
VZ
3741 if ( !IsVirtual() )
3742 {
3743 wxListLineData *line = GetLine((size_t)id);
3744 line->SetItem( item.m_col, item );
7d4813a0 3745
39a7f085
VZ
3746 // Set item state if user wants
3747 if ( item.m_mask & wxLIST_MASK_STATE )
3748 SetItemState( item.m_itemId, item.m_state, item.m_state );
3749
7d4813a0
VZ
3750 if (InReportView())
3751 {
3752 // update the Max Width Cache if needed
3753 int width = GetItemWidthWithImage(&item);
3754
3755 if (width > m_aColWidths.Item(item.m_col)->nMaxWidth)
3756 m_aColWidths.Item(item.m_col)->nMaxWidth = width;
3757 }
6c02c329
VZ
3758 }
3759
285013b3
VZ
3760 // update the item on screen
3761 wxRect rectItem;
3762 GetItemRect(id, rectItem);
3763 RefreshRect(rectItem);
e1e955e1 3764}
c801d85f 3765
0afa5859
VZ
3766void wxListMainWindow::SetItemStateAll(long state, long stateMask)
3767{
3768 if ( IsEmpty() )
3769 return;
3770
3771 // first deal with selection
3772 if ( stateMask & wxLIST_STATE_SELECTED )
3773 {
3774 // set/clear select state
3775 if ( IsVirtual() )
3776 {
3777 // optimized version for virtual listctrl.
3778 m_selStore.SelectRange(0, GetItemCount() - 1, state == wxLIST_STATE_SELECTED);
3779 Refresh();
3780 }
3781 else if ( state & wxLIST_STATE_SELECTED )
3782 {
3783 const long count = GetItemCount();
3784 for( long i = 0; i < count; i++ )
3785 {
3786 SetItemState( i, wxLIST_STATE_SELECTED, wxLIST_STATE_SELECTED );
3787 }
3788
3789 }
3790 else
3791 {
3792 // clear for non virtual (somewhat optimized by using GetNextItem())
3793 long i = -1;
3794 while ( (i = GetNextItem(i, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED)) != -1 )
3795 {
3796 SetItemState( i, 0, wxLIST_STATE_SELECTED );
3797 }
3798 }
3799 }
3800
3801 if ( HasCurrent() && (state == 0) && (stateMask & wxLIST_STATE_FOCUSED) )
3802 {
3803 // unfocus all: only one item can be focussed, so clearing focus for
3804 // all items is simply clearing focus of the focussed item.
3805 SetItemState(m_current, state, stateMask);
3806 }
3807 //(setting focus to all items makes no sense, so it is not handled here.)
3808}
3809
cf1dfa6b 3810void wxListMainWindow::SetItemState( long litem, long state, long stateMask )
c801d85f 3811{
0afa5859
VZ
3812 if ( litem == -1 )
3813 {
3814 SetItemStateAll(state, stateMask);
3815 return;
3816 }
3817
7448de8d
WS
3818 wxCHECK_RET( litem >= 0 && (size_t)litem < GetItemCount(),
3819 _T("invalid list ctrl item index in SetItem") );
54442116 3820
cf1dfa6b 3821 size_t oldCurrent = m_current;
88b792af 3822 size_t item = (size_t)litem; // safe because of the check above
bd8289c1 3823
88b792af 3824 // do we need to change the focus?
54442116 3825 if ( stateMask & wxLIST_STATE_FOCUSED )
c801d85f 3826 {
54442116 3827 if ( state & wxLIST_STATE_FOCUSED )
92976ab6 3828 {
54442116 3829 // don't do anything if this item is already focused
cf1dfa6b 3830 if ( item != m_current )
92976ab6 3831 {
0ddefeb0 3832 ChangeCurrent(item);
cf1dfa6b 3833
88b792af 3834 if ( oldCurrent != (size_t)-1 )
cf1dfa6b 3835 {
88b792af
VZ
3836 if ( IsSingleSel() )
3837 {
ca65c044 3838 HighlightLine(oldCurrent, false);
88b792af
VZ
3839 }
3840
cf1dfa6b
VZ
3841 RefreshLine(oldCurrent);
3842 }
54442116 3843
92976ab6 3844 RefreshLine( m_current );
92976ab6 3845 }
54442116
VZ
3846 }
3847 else // unfocus
3848 {
3849 // don't do anything if this item is not focused
cf1dfa6b 3850 if ( item == m_current )
bffa1c77 3851 {
0ddefeb0 3852 ResetCurrent();
88b792af 3853
943f6ad3
VZ
3854 if ( IsSingleSel() )
3855 {
3856 // we must unselect the old current item as well or we
3857 // might end up with more than one selected item in a
3858 // single selection control
ca65c044 3859 HighlightLine(oldCurrent, false);
943f6ad3
VZ
3860 }
3861
88b792af 3862 RefreshLine( oldCurrent );
bffa1c77 3863 }
92976ab6 3864 }
e1e955e1 3865 }
54442116 3866
88b792af 3867 // do we need to change the selection state?
54442116
VZ
3868 if ( stateMask & wxLIST_STATE_SELECTED )
3869 {
3870 bool on = (state & wxLIST_STATE_SELECTED) != 0;
54442116 3871
b54e41c5 3872 if ( IsSingleSel() )
54442116 3873 {
cf1dfa6b
VZ
3874 if ( on )
3875 {
3876 // selecting the item also makes it the focused one in the
3877 // single sel mode
3878 if ( m_current != item )
3879 {
0ddefeb0 3880 ChangeCurrent(item);
cf1dfa6b
VZ
3881
3882 if ( oldCurrent != (size_t)-1 )
3883 {
ca65c044 3884 HighlightLine( oldCurrent, false );
cf1dfa6b
VZ
3885 RefreshLine( oldCurrent );
3886 }
3887 }
3888 }
3889 else // off
3890 {
3891 // only the current item may be selected anyhow
3892 if ( item != m_current )
3893 return;
3894 }
54442116
VZ
3895 }
3896
b54e41c5 3897 if ( HighlightLine(item, on) )
54442116 3898 {
cf1dfa6b 3899 RefreshLine(item);
54442116
VZ
3900 }
3901 }
e1e955e1 3902}
c801d85f 3903
62d89eb4 3904int wxListMainWindow::GetItemState( long item, long stateMask ) const
c801d85f 3905{
cf1dfa6b
VZ
3906 wxCHECK_MSG( item >= 0 && (size_t)item < GetItemCount(), 0,
3907 _T("invalid list ctrl item index in GetItemState()") );
3908
92976ab6 3909 int ret = wxLIST_STATE_DONTCARE;
cf1dfa6b
VZ
3910
3911 if ( stateMask & wxLIST_STATE_FOCUSED )
c801d85f 3912 {
cf1dfa6b
VZ
3913 if ( (size_t)item == m_current )
3914 ret |= wxLIST_STATE_FOCUSED;
e1e955e1 3915 }
cf1dfa6b
VZ
3916
3917 if ( stateMask & wxLIST_STATE_SELECTED )
c801d85f 3918 {
b54e41c5 3919 if ( IsHighlighted(item) )
cf1dfa6b 3920 ret |= wxLIST_STATE_SELECTED;
e1e955e1 3921 }
cf1dfa6b 3922
92976ab6 3923 return ret;
e1e955e1 3924}
c801d85f 3925
62d89eb4 3926void wxListMainWindow::GetItem( wxListItem &item ) const
c801d85f 3927{
cf1dfa6b
VZ
3928 wxCHECK_RET( item.m_itemId >= 0 && (size_t)item.m_itemId < GetItemCount(),
3929 _T("invalid item index in GetItem") );
3930
3931 wxListLineData *line = GetLine((size_t)item.m_itemId);
3932 line->GetItem( item.m_col, item );
39a7f085
VZ
3933
3934 // Get item state if user wants it
3935 if ( item.m_mask & wxLIST_MASK_STATE )
3936 item.m_state = GetItemState( item.m_itemId, wxLIST_STATE_SELECTED |
3937 wxLIST_STATE_FOCUSED );
e1e955e1 3938}
c801d85f 3939
cf1dfa6b
VZ
3940// ----------------------------------------------------------------------------
3941// item count
3942// ----------------------------------------------------------------------------
3943
3944size_t wxListMainWindow::GetItemCount() const
1370703e
VZ
3945{
3946 return IsVirtual() ? m_countVirt : m_lines.GetCount();
3947}
3948
3949void wxListMainWindow::SetItemCount(long count)
c801d85f 3950{
b54e41c5 3951 m_selStore.SetItemCount(count);
1370703e
VZ
3952 m_countVirt = count;
3953
850ed6e7
VZ
3954 ResetVisibleLinesRange();
3955
5fe143df 3956 // scrollbars must be reset
ca65c044 3957 m_dirty = true;
e1e955e1 3958}
c801d85f 3959
62d89eb4 3960int wxListMainWindow::GetSelectedItemCount() const
c801d85f 3961{
cf1dfa6b 3962 // deal with the quick case first
b54e41c5 3963 if ( IsSingleSel() )
ca65c044 3964 return HasCurrent() ? IsHighlighted(m_current) : false;
cf1dfa6b
VZ
3965
3966 // virtual controls remmebers all its selections itself
3967 if ( IsVirtual() )
b54e41c5 3968 return m_selStore.GetSelectedCount();
cf1dfa6b
VZ
3969
3970 // TODO: we probably should maintain the number of items selected even for
3971 // non virtual controls as enumerating all lines is really slow...
3972 size_t countSel = 0;
3973 size_t count = GetItemCount();
3974 for ( size_t line = 0; line < count; line++ )
92976ab6 3975 {
b54e41c5 3976 if ( GetLine(line)->IsHighlighted() )
cf1dfa6b 3977 countSel++;
92976ab6 3978 }
c801d85f 3979
cf1dfa6b 3980 return countSel;
e1e955e1 3981}
e3e65dac 3982
cf1dfa6b
VZ
3983// ----------------------------------------------------------------------------
3984// item position/size
3985// ----------------------------------------------------------------------------
3986
11ebea16
VZ
3987wxRect wxListMainWindow::GetViewRect() const
3988{
3989 wxASSERT_MSG( !HasFlag(wxLC_REPORT | wxLC_LIST),
3990 _T("wxListCtrl::GetViewRect() only works in icon mode") );
3991
3992 // we need to find the longest/tallest label
277ea1b4 3993 wxCoord xMax = 0, yMax = 0;
11ebea16
VZ
3994 const int count = GetItemCount();
3995 if ( count )
3996 {
3997 for ( int i = 0; i < count; i++ )
3998 {
3999 wxRect r;
4000 GetItemRect(i, r);
4001
4002 wxCoord x = r.GetRight(),
4003 y = r.GetBottom();
4004
4005 if ( x > xMax )
4006 xMax = x;
4007 if ( y > yMax )
4008 yMax = y;
4009 }
4010 }
4011
eb6c4508 4012 // some fudge needed to make it look prettier
277ea1b4
DS
4013 xMax += 2 * EXTRA_BORDER_X;
4014 yMax += 2 * EXTRA_BORDER_Y;
eb6c4508
VZ
4015
4016 // account for the scrollbars if necessary
4017 const wxSize sizeAll = GetClientSize();
4018 if ( xMax > sizeAll.x )
4019 yMax += wxSystemSettings::GetMetric(wxSYS_HSCROLL_Y);
4020 if ( yMax > sizeAll.y )
4021 xMax += wxSystemSettings::GetMetric(wxSYS_VSCROLL_X);
11ebea16
VZ
4022
4023 return wxRect(0, 0, xMax, yMax);
4024}
4025
62d89eb4 4026void wxListMainWindow::GetItemRect( long index, wxRect &rect ) const
c801d85f 4027{
cf1dfa6b
VZ
4028 wxCHECK_RET( index >= 0 && (size_t)index < GetItemCount(),
4029 _T("invalid index in GetItemRect") );
4030
1e54be64
VZ
4031 // ensure that we're laid out, otherwise we could return nonsense
4032 if ( m_dirty )
4033 {
4034 wxConstCast(this, wxListMainWindow)->
ca65c044 4035 RecalculatePositions(true /* no refresh */);
1e54be64
VZ
4036 }
4037
5cd89174 4038 rect = GetLineRect((size_t)index);
b54e41c5 4039
cf1dfa6b 4040 CalcScrolledPosition(rect.x, rect.y, &rect.x, &rect.y);
e1e955e1 4041}
c801d85f 4042
62d89eb4 4043bool wxListMainWindow::GetItemPosition(long item, wxPoint& pos) const
c801d85f 4044{
cf1dfa6b
VZ
4045 wxRect rect;
4046 GetItemRect(item, rect);
bd8289c1 4047
cf1dfa6b
VZ
4048 pos.x = rect.x;
4049 pos.y = rect.y;
bd8289c1 4050
ca65c044 4051 return true;
e1e955e1 4052}
c801d85f 4053
cf1dfa6b
VZ
4054// ----------------------------------------------------------------------------
4055// geometry calculation
4056// ----------------------------------------------------------------------------
4057
34bbbc27 4058void wxListMainWindow::RecalculatePositions(bool noRefresh)
c801d85f 4059{
6d6d86a6
RD
4060 const int lineHeight = GetLineHeight();
4061
1e6d9499 4062 wxClientDC dc( this );
92976ab6 4063 dc.SetFont( GetFont() );
c801d85f 4064
13602ebd
VZ
4065 const size_t count = GetItemCount();
4066
cf1dfa6b
VZ
4067 int iconSpacing;
4068 if ( HasFlag(wxLC_ICON) )
4069 iconSpacing = m_normal_spacing;
4070 else if ( HasFlag(wxLC_SMALL_ICON) )
4071 iconSpacing = m_small_spacing;
4072 else
4073 iconSpacing = 0;
004fd0c8 4074
bf632edd 4075 // Note that we do not call GetClientSize() here but
34621cc5 4076 // GetSize() and subtract the border size for sunken
bf632edd
RR
4077 // borders manually. This is technically incorrect,
4078 // but we need to know the client area's size WITHOUT
4079 // scrollbars here. Since we don't know if there are
4080 // any scrollbars, we use GetSize() instead. Another
4081 // solution would be to call SetScrollbars() here to
4082 // remove the scrollbars and call GetClientSize() then,
4083 // but this might result in flicker and - worse - will
4084 // reset the scrollbars to 0 which is not good at all
4085 // if you resize a dialog/window, but don't want to
4086 // reset the window scrolling. RR.
4087 // Furthermore, we actually do NOT subtract the border
4088 // width as 2 pixels is just the extra space which we
4089 // need around the actual content in the window. Other-
4090 // wise the text would e.g. touch the upper border. RR.
cf1dfa6b
VZ
4091 int clientWidth,
4092 clientHeight;
bf632edd 4093 GetSize( &clientWidth, &clientHeight );
a77ec46d 4094
b5d43d1d 4095 if ( InReportView() )
cf1dfa6b 4096 {
13602ebd 4097 // all lines have the same height and we scroll one line per step
277ea1b4 4098 int entireHeight = count * lineHeight + LINE_SPACING;
bd8289c1 4099
b54e41c5
VZ
4100 m_linesPerPage = clientHeight / lineHeight;
4101
4102 ResetVisibleLinesRange();
2c1f73ee 4103
13602ebd
VZ
4104 SetScrollbars( SCROLL_UNIT_X, lineHeight,
4105 GetHeaderWidth() / SCROLL_UNIT_X,
4106 (entireHeight + lineHeight - 1) / lineHeight,
cf1dfa6b
VZ
4107 GetScrollPos(wxHORIZONTAL),
4108 GetScrollPos(wxVERTICAL),
ca65c044 4109 true );
e1e955e1 4110 }
cf1dfa6b 4111 else // !report
92976ab6 4112 {
13602ebd
VZ
4113 // we have 3 different layout strategies: either layout all items
4114 // horizontally/vertically (wxLC_ALIGN_XXX styles explicitly given) or
4115 // to arrange them in top to bottom, left to right (don't ask me why
4116 // not the other way round...) order
4117 if ( HasFlag(wxLC_ALIGN_LEFT | wxLC_ALIGN_TOP) )
e487524e 4118 {
13602ebd
VZ
4119 int x = EXTRA_BORDER_X;
4120 int y = EXTRA_BORDER_Y;
cf1dfa6b 4121
94dd23ae
VZ
4122 wxCoord widthMax = 0;
4123
4124 size_t i;
4125 for ( i = 0; i < count; i++ )
92976ab6 4126 {
cf1dfa6b 4127 wxListLineData *line = GetLine(i);
92976ab6 4128 line->CalculateSize( &dc, iconSpacing );
13602ebd 4129 line->SetPosition( x, y, iconSpacing );
cf1dfa6b 4130
5cd89174 4131 wxSize sizeLine = GetLineSize(i);
cf1dfa6b 4132
13602ebd
VZ
4133 if ( HasFlag(wxLC_ALIGN_TOP) )
4134 {
94dd23ae
VZ
4135 if ( sizeLine.x > widthMax )
4136 widthMax = sizeLine.x;
4137
13602ebd
VZ
4138 y += sizeLine.y;
4139 }
4140 else // wxLC_ALIGN_LEFT
4141 {
4142 x += sizeLine.x + MARGIN_BETWEEN_ROWS;
4143 }
4144 }
4145
94dd23ae
VZ
4146 if ( HasFlag(wxLC_ALIGN_TOP) )
4147 {
4148 // traverse the items again and tweak their sizes so that they are
4149 // all the same in a row
4150 for ( i = 0; i < count; i++ )
4151 {
4152 wxListLineData *line = GetLine(i);
4153 line->m_gi->ExtendWidth(widthMax);
4154 }
4155 }
4156
13602ebd
VZ
4157 SetScrollbars
4158 (
4159 SCROLL_UNIT_X,
6d78bbe6 4160 lineHeight,
13602ebd 4161 (x + SCROLL_UNIT_X) / SCROLL_UNIT_X,
6d78bbe6 4162 (y + lineHeight) / lineHeight,
13602ebd
VZ
4163 GetScrollPos( wxHORIZONTAL ),
4164 GetScrollPos( wxVERTICAL ),
ca65c044 4165 true
13602ebd
VZ
4166 );
4167 }
4168 else // "flowed" arrangement, the most complicated case
4169 {
4170 // at first we try without any scrollbars, if the items don't fit into
4171 // the window, we recalculate after subtracting the space taken by the
4172 // scrollbar
4173
8a39593e 4174 int entireWidth = 0;
cf1dfa6b 4175
13602ebd
VZ
4176 for (int tries = 0; tries < 2; tries++)
4177 {
277ea1b4 4178 entireWidth = 2 * EXTRA_BORDER_X;
cf1dfa6b 4179
13602ebd 4180 if (tries == 1)
92976ab6 4181 {
13602ebd
VZ
4182 // Now we have decided that the items do not fit into the
4183 // client area, so we need a scrollbar
4184 entireWidth += SCROLL_UNIT_X;
92976ab6 4185 }
a77ec46d 4186
13602ebd
VZ
4187 int x = EXTRA_BORDER_X;
4188 int y = EXTRA_BORDER_Y;
4189 int maxWidthInThisRow = 0;
4190
4191 m_linesPerPage = 0;
4192 int currentlyVisibleLines = 0;
a77ec46d 4193
13602ebd 4194 for (size_t i = 0; i < count; i++)
92976ab6 4195 {
13602ebd 4196 currentlyVisibleLines++;
277ea1b4 4197 wxListLineData *line = GetLine( i );
13602ebd
VZ
4198 line->CalculateSize( &dc, iconSpacing );
4199 line->SetPosition( x, y, iconSpacing );
4200
277ea1b4 4201 wxSize sizeLine = GetLineSize( i );
a77ec46d 4202
13602ebd
VZ
4203 if ( maxWidthInThisRow < sizeLine.x )
4204 maxWidthInThisRow = sizeLine.x;
4205
4206 y += sizeLine.y;
4207 if (currentlyVisibleLines > m_linesPerPage)
4208 m_linesPerPage = currentlyVisibleLines;
4209
4210 if ( y + sizeLine.y >= clientHeight )
4211 {
4212 currentlyVisibleLines = 0;
4213 y = EXTRA_BORDER_Y;
4214 maxWidthInThisRow += MARGIN_BETWEEN_ROWS;
4215 x += maxWidthInThisRow;
4216 entireWidth += maxWidthInThisRow;
4217 maxWidthInThisRow = 0;
4218 }
4219
4220 // We have reached the last item.
4221 if ( i == count - 1 )
4222 entireWidth += maxWidthInThisRow;
4223
4224 if ( (tries == 0) &&
4225 (entireWidth + SCROLL_UNIT_X > clientWidth) )
4226 {
4227 clientHeight -= wxSystemSettings::
4228 GetMetric(wxSYS_HSCROLL_Y);
4229 m_linesPerPage = 0;
13602ebd
VZ
4230 break;
4231 }
4232
4233 if ( i == count - 1 )
4234 tries = 1; // Everything fits, no second try required.
4235 }
92976ab6 4236 }
bffa1c77 4237
13602ebd
VZ
4238 SetScrollbars
4239 (
4240 SCROLL_UNIT_X,
6d78bbe6 4241 lineHeight,
13602ebd
VZ
4242 (entireWidth + SCROLL_UNIT_X) / SCROLL_UNIT_X,
4243 0,
4244 GetScrollPos( wxHORIZONTAL ),
4245 0,
ca65c044 4246 true
13602ebd
VZ
4247 );
4248 }
e1e955e1 4249 }
cf1dfa6b 4250
34bbbc27
VZ
4251 if ( !noRefresh )
4252 {
4253 // FIXME: why should we call it from here?
4254 UpdateCurrent();
b54e41c5 4255
34bbbc27
VZ
4256 RefreshAll();
4257 }
b54e41c5
VZ
4258}
4259
4260void wxListMainWindow::RefreshAll()
4261{
ca65c044 4262 m_dirty = false;
b54e41c5
VZ
4263 Refresh();
4264
4265 wxListHeaderWindow *headerWin = GetListCtrl()->m_headerWin;
70541533 4266 if ( headerWin && headerWin->m_dirty )
b54e41c5 4267 {
ca65c044 4268 headerWin->m_dirty = false;
b54e41c5
VZ
4269 headerWin->Refresh();
4270 }
e1e955e1 4271}
c801d85f 4272
cf1dfa6b 4273void wxListMainWindow::UpdateCurrent()
c801d85f 4274{
b54e41c5 4275 if ( !HasCurrent() && !IsEmpty() )
0ddefeb0 4276 ChangeCurrent(0);
e1e955e1 4277}
c801d85f 4278
19695fbd
VZ
4279long wxListMainWindow::GetNextItem( long item,
4280 int WXUNUSED(geometry),
62d89eb4 4281 int state ) const
c801d85f 4282{
d1022fd6
VZ
4283 long ret = item,
4284 max = GetItemCount();
4285 wxCHECK_MSG( (ret == -1) || (ret < max), -1,
13771c08 4286 _T("invalid listctrl index in GetNextItem()") );
19695fbd
VZ
4287
4288 // notice that we start with the next item (or the first one if item == -1)
4289 // and this is intentional to allow writing a simple loop to iterate over
4290 // all selected items
d1022fd6
VZ
4291 ret++;
4292 if ( ret == max )
277ea1b4
DS
4293 // this is not an error because the index was OK initially,
4294 // just no such item
d1022fd6 4295 return -1;
d1022fd6 4296
cf1dfa6b 4297 if ( !state )
cf1dfa6b
VZ
4298 // any will do
4299 return (size_t)ret;
cf1dfa6b
VZ
4300
4301 size_t count = GetItemCount();
4302 for ( size_t line = (size_t)ret; line < count; line++ )
63852e78 4303 {
cf1dfa6b
VZ
4304 if ( (state & wxLIST_STATE_FOCUSED) && (line == m_current) )
4305 return line;
4306
b54e41c5 4307 if ( (state & wxLIST_STATE_SELECTED) && IsHighlighted(line) )
cf1dfa6b 4308 return line;
63852e78 4309 }
19695fbd 4310
63852e78 4311 return -1;
e1e955e1 4312}
c801d85f 4313
cf1dfa6b
VZ
4314// ----------------------------------------------------------------------------
4315// deleting stuff
4316// ----------------------------------------------------------------------------
4317
b54e41c5 4318void wxListMainWindow::DeleteItem( long lindex )
c801d85f 4319{
cf1dfa6b
VZ
4320 size_t count = GetItemCount();
4321
b54e41c5 4322 wxCHECK_RET( (lindex >= 0) && ((size_t)lindex < count),
cf1dfa6b
VZ
4323 _T("invalid item index in DeleteItem") );
4324
b54e41c5
VZ
4325 size_t index = (size_t)lindex;
4326
d6ddcd57
VZ
4327 // we don't need to adjust the index for the previous items
4328 if ( HasCurrent() && m_current >= index )
cf1dfa6b 4329 {
d6ddcd57
VZ
4330 // if the current item is being deleted, we want the next one to
4331 // become selected - unless there is no next one - so don't adjust
4332 // m_current in this case
4333 if ( m_current != index || m_current == count - 1 )
d6ddcd57 4334 m_current--;
cf1dfa6b 4335 }
a95d5751 4336
938b652b 4337 if ( InReportView() )
63852e78 4338 {
a95d5751
RR
4339 // mark the Column Max Width cache as dirty if the items in the line
4340 // we're deleting contain the Max Column Width
7d4813a0
VZ
4341 wxListLineData * const line = GetLine(index);
4342 wxListItemDataList::compatibility_iterator n;
4343 wxListItemData *itemData;
4344 wxListItem item;
4345 int itemWidth;
4346
4347 for (size_t i = 0; i < m_columns.GetCount(); i++)
4348 {
4349 n = line->m_items.Item( i );
4350 itemData = n->GetData();
4351 itemData->GetItem(item);
4352
4353 itemWidth = GetItemWidthWithImage(&item);
4354
4355 if (itemWidth >= m_aColWidths.Item(i)->nMaxWidth)
4356 m_aColWidths.Item(i)->bNeedsUpdate = true;
4357 }
4358
6b4a8d93 4359 ResetVisibleLinesRange();
938b652b
VZ
4360 }
4361
a95d5751
RR
4362 SendNotify( index, wxEVT_COMMAND_LIST_DELETE_ITEM, wxDefaultPosition );
4363
938b652b
VZ
4364 if ( IsVirtual() )
4365 {
4366 m_countVirt--;
b54e41c5
VZ
4367 m_selStore.OnItemDelete(index);
4368 }
4369 else
4370 {
4371 m_lines.RemoveAt( index );
63852e78 4372 }
6b4a8d93 4373
70541533 4374 // we need to refresh the (vert) scrollbar as the number of items changed
ca65c044 4375 m_dirty = true;
91c6cc0e 4376
6b4a8d93 4377 RefreshAfter(index);
e1e955e1 4378}
c801d85f 4379
debe6624 4380void wxListMainWindow::DeleteColumn( int col )
c801d85f 4381{
222ed1d6 4382 wxListHeaderDataList::compatibility_iterator node = m_columns.Item( col );
24b9f055
VZ
4383
4384 wxCHECK_RET( node, wxT("invalid column index in DeleteColumn()") );
bd8289c1 4385
ca65c044 4386 m_dirty = true;
222ed1d6
MB
4387 delete node->GetData();
4388 m_columns.Erase( node );
ae409cb8 4389
df6f82f0
VZ
4390 if ( !IsVirtual() )
4391 {
4392 // update all the items
4393 for ( size_t i = 0; i < m_lines.GetCount(); i++ )
4394 {
4395 wxListLineData * const line = GetLine(i);
222ed1d6
MB
4396 wxListItemDataList::compatibility_iterator n = line->m_items.Item( col );
4397 delete n->GetData();
4398 line->m_items.Erase(n);
df6f82f0
VZ
4399 }
4400 }
4401
7d4813a0
VZ
4402 if ( InReportView() ) // we only cache max widths when in Report View
4403 {
4404 delete m_aColWidths.Item(col);
4405 m_aColWidths.RemoveAt(col);
4406 }
4407
ae409cb8
VZ
4408 // invalidate it as it has to be recalculated
4409 m_headerWidth = 0;
e1e955e1 4410}
c801d85f 4411
5fe143df 4412void wxListMainWindow::DoDeleteAllItems()
c801d85f 4413{
cf1dfa6b 4414 if ( IsEmpty() )
cf1dfa6b
VZ
4415 // nothing to do - in particular, don't send the event
4416 return;
cf1dfa6b 4417
b54e41c5 4418 ResetCurrent();
7c0ea335
VZ
4419
4420 // to make the deletion of all items faster, we don't send the
cf1dfa6b
VZ
4421 // notifications for each item deletion in this case but only one event
4422 // for all of them: this is compatible with wxMSW and documented in
4423 // DeleteAllItems() description
bffa1c77 4424
12c1b46a
RR
4425 wxListEvent event( wxEVT_COMMAND_LIST_DELETE_ALL_ITEMS, GetParent()->GetId() );
4426 event.SetEventObject( GetParent() );
4427 GetParent()->GetEventHandler()->ProcessEvent( event );
7c0ea335 4428
b54e41c5
VZ
4429 if ( IsVirtual() )
4430 {
4431 m_countVirt = 0;
850ed6e7 4432 m_selStore.Clear();
b54e41c5
VZ
4433 }
4434
6b4a8d93
VZ
4435 if ( InReportView() )
4436 {
4437 ResetVisibleLinesRange();
7d4813a0
VZ
4438 for (size_t i = 0; i < m_aColWidths.GetCount(); i++)
4439 {
8d36b216 4440 m_aColWidths.Item(i)->bNeedsUpdate = true;
7d4813a0 4441 }
6b4a8d93
VZ
4442 }
4443
5b077d48 4444 m_lines.Clear();
5fe143df 4445}
cf1dfa6b 4446
5fe143df
VZ
4447void wxListMainWindow::DeleteAllItems()
4448{
4449 DoDeleteAllItems();
4450
4451 RecalculatePositions();
e1e955e1 4452}
c801d85f 4453
12c1b46a 4454void wxListMainWindow::DeleteEverything()
c801d85f 4455{
222ed1d6 4456 WX_CLEAR_LIST(wxListHeaderDataList, m_columns);
8d36b216 4457 WX_CLEAR_ARRAY(m_aColWidths);
904ccf52
VZ
4458
4459 DeleteAllItems();
e1e955e1 4460}
c801d85f 4461
cf1dfa6b
VZ
4462// ----------------------------------------------------------------------------
4463// scanning for an item
4464// ----------------------------------------------------------------------------
4465
debe6624 4466void wxListMainWindow::EnsureVisible( long index )
c801d85f 4467{
cf1dfa6b
VZ
4468 wxCHECK_RET( index >= 0 && (size_t)index < GetItemCount(),
4469 _T("invalid index in EnsureVisible") );
4470
4471 // We have to call this here because the label in question might just have
34bbbc27
VZ
4472 // been added and its position is not known yet
4473 if ( m_dirty )
ca65c044 4474 RecalculatePositions(true /* no refresh */);
34bbbc27
VZ
4475
4476 MoveToItem((size_t)index);
e1e955e1 4477}
c801d85f 4478
debe6624 4479long wxListMainWindow::FindItem(long start, const wxString& str, bool WXUNUSED(partial) )
c801d85f 4480{
5b077d48
RR
4481 long pos = start;
4482 wxString tmp = str;
cf1dfa6b
VZ
4483 if (pos < 0)
4484 pos = 0;
54442116 4485
cf1dfa6b
VZ
4486 size_t count = GetItemCount();
4487 for ( size_t i = (size_t)pos; i < count; i++ )
4488 {
4489 wxListLineData *line = GetLine(i);
4490 if ( line->GetText(0) == tmp )
4491 return i;
5b077d48 4492 }
cf1dfa6b
VZ
4493
4494 return wxNOT_FOUND;
e1e955e1 4495}
c801d85f 4496
81ce36aa 4497long wxListMainWindow::FindItem(long start, wxUIntPtr data)
c801d85f 4498{
5b077d48 4499 long pos = start;
cf1dfa6b
VZ
4500 if (pos < 0)
4501 pos = 0;
4502
4503 size_t count = GetItemCount();
4504 for (size_t i = (size_t)pos; i < count; i++)
5b077d48 4505 {
cf1dfa6b 4506 wxListLineData *line = GetLine(i);
5b077d48
RR
4507 wxListItem item;
4508 line->GetItem( 0, item );
cf1dfa6b
VZ
4509 if (item.m_data == data)
4510 return i;
5b077d48 4511 }
cf1dfa6b
VZ
4512
4513 return wxNOT_FOUND;
e1e955e1 4514}
c801d85f 4515
8158e0e1
VZ
4516long wxListMainWindow::FindItem( const wxPoint& pt )
4517{
e6bf9573 4518 size_t topItem;
277ea1b4 4519 GetVisibleLinesRange( &topItem, NULL );
8158e0e1 4520
e6bf9573 4521 wxPoint p;
277ea1b4
DS
4522 GetItemPosition( GetItemCount() - 1, p );
4523 if ( p.y == 0 )
e6bf9573 4524 return topItem;
277ea1b4
DS
4525
4526 long id = (long)floor( pt.y * double(GetItemCount() - topItem - 1) / p.y + topItem );
4527 if ( id >= 0 && id < (long)GetItemCount() )
e6bf9573 4528 return id;
8158e0e1 4529
e6bf9573 4530 return wxNOT_FOUND;
8158e0e1
VZ
4531}
4532
be0e5d69 4533long wxListMainWindow::HitTest( int x, int y, int &flags ) const
c801d85f 4534{
aaef15bf 4535 CalcUnscrolledPosition( x, y, &x, &y );
e8741cca 4536
fc4f1d5f
VZ
4537 size_t count = GetItemCount();
4538
b5d43d1d 4539 if ( InReportView() )
c801d85f 4540 {
5cd89174 4541 size_t current = y / GetLineHeight();
fc4f1d5f
VZ
4542 if ( current < count )
4543 {
4544 flags = HitTestLine(current, x, y);
4545 if ( flags )
4546 return current;
4547 }
5cd89174
VZ
4548 }
4549 else // !report
4550 {
4551 // TODO: optimize it too! this is less simple than for report view but
4552 // enumerating all items is still not a way to do it!!
5cd89174 4553 for ( size_t current = 0; current < count; current++ )
5b077d48 4554 {
5cd89174
VZ
4555 flags = HitTestLine(current, x, y);
4556 if ( flags )
4557 return current;
5b077d48 4558 }
e1e955e1 4559 }
cf1dfa6b
VZ
4560
4561 return wxNOT_FOUND;
e1e955e1 4562}
c801d85f 4563
cf1dfa6b
VZ
4564// ----------------------------------------------------------------------------
4565// adding stuff
4566// ----------------------------------------------------------------------------
4567
c801d85f
KB
4568void wxListMainWindow::InsertItem( wxListItem &item )
4569{
cf1dfa6b
VZ
4570 wxASSERT_MSG( !IsVirtual(), _T("can't be used with virtual control") );
4571
c7cf7a78 4572 int count = GetItemCount();
33c956e6 4573 wxCHECK_RET( item.m_itemId >= 0, _T("invalid item index") );
cf1dfa6b 4574
33c956e6
RD
4575 if (item.m_itemId > count)
4576 item.m_itemId = count;
b713f891 4577
cf1dfa6b
VZ
4578 size_t id = item.m_itemId;
4579
ca65c044 4580 m_dirty = true;
cf1dfa6b 4581
b5d43d1d 4582 if ( InReportView() )
2b5f62a0 4583 {
2b5f62a0 4584 ResetVisibleLinesRange();
7d4813a0
VZ
4585
4586 // calculate the width of the item and adjust the max column width
4587 wxColWidthInfo *pWidthInfo = m_aColWidths.Item(item.GetColumn());
f5c479cc 4588 int width = GetItemWidthWithImage(&item);
7d4813a0
VZ
4589 item.SetWidth(width);
4590 if (width > pWidthInfo->nMaxWidth)
4591 pWidthInfo->nMaxWidth = width;
1370703e 4592 }
004fd0c8 4593
5cd89174 4594 wxListLineData *line = new wxListLineData(this);
004fd0c8 4595
1e6601c7 4596 line->SetItem( item.m_col, item );
cf1dfa6b
VZ
4597
4598 m_lines.Insert( line, id );
5cd89174 4599
ca65c044 4600 m_dirty = true;
a67e6e54 4601
ab96d680
VZ
4602 // If an item is selected at or below the point of insertion, we need to
4603 // increment the member variables because the current row's index has gone
4604 // up by one
4605 if ( HasCurrent() && m_current >= id )
ab96d680 4606 m_current++;
ab96d680 4607
a67e6e54
VZ
4608 SendNotify(id, wxEVT_COMMAND_LIST_INSERT_ITEM);
4609
5cd89174 4610 RefreshLines(id, GetItemCount() - 1);
e1e955e1 4611}
c801d85f 4612
debe6624 4613void wxListMainWindow::InsertColumn( long col, wxListItem &item )
c801d85f 4614{
ca65c044 4615 m_dirty = true;
b5d43d1d 4616 if ( InReportView() )
3db7be80 4617 {
54442116
VZ
4618 if (item.m_width == wxLIST_AUTOSIZE_USEHEADER)
4619 item.m_width = GetTextLength( item.m_text );
df6f82f0 4620
5b077d48 4621 wxListHeaderData *column = new wxListHeaderData( item );
7d4813a0
VZ
4622 wxColWidthInfo *colWidthInfo = new wxColWidthInfo();
4623
df6f82f0
VZ
4624 bool insert = (col >= 0) && ((size_t)col < m_columns.GetCount());
4625 if ( insert )
5b077d48 4626 {
7d4813a0
VZ
4627 wxListHeaderDataList::compatibility_iterator
4628 node = m_columns.Item( col );
24b9f055 4629 m_columns.Insert( node, column );
7d4813a0 4630 m_aColWidths.Insert( colWidthInfo, col );
5b077d48
RR
4631 }
4632 else
4633 {
4634 m_columns.Append( column );
7d4813a0 4635 m_aColWidths.Add( colWidthInfo );
5b077d48 4636 }
ae409cb8 4637
df6f82f0
VZ
4638 if ( !IsVirtual() )
4639 {
4640 // update all the items
4641 for ( size_t i = 0; i < m_lines.GetCount(); i++ )
4642 {
4643 wxListLineData * const line = GetLine(i);
4644 wxListItemData * const data = new wxListItemData(this);
4645 if ( insert )
4646 line->m_items.Insert(col, data);
4647 else
4648 line->m_items.Append(data);
4649 }
4650 }
4651
ae409cb8
VZ
4652 // invalidate it as it has to be recalculated
4653 m_headerWidth = 0;
3db7be80 4654 }
e1e955e1 4655}
c801d85f 4656
7d4813a0
VZ
4657int wxListMainWindow::GetItemWidthWithImage(wxListItem * item)
4658{
4659 int width = 0;
4660 wxClientDC dc(this);
4661
4662 dc.SetFont( GetFont() );
4663
4664 if (item->GetImage() != -1)
4665 {
4666 int ix, iy;
4667 GetImageSize( item->GetImage(), ix, iy );
4668 width += ix + 5;
4669 }
4670
4671 if (!item->GetText().empty())
4672 {
4673 wxCoord w;
4674 dc.GetTextExtent( item->GetText(), &w, NULL );
4675 width += w;
4676 }
4677
4678 return width;
4679}
4680
cf1dfa6b
VZ
4681// ----------------------------------------------------------------------------
4682// sorting
4683// ----------------------------------------------------------------------------
4684
c801d85f
KB
4685wxListCtrlCompare list_ctrl_compare_func_2;
4686long list_ctrl_compare_data;
4687
f6bcfd97 4688int LINKAGEMODE list_ctrl_compare_func_1( wxListLineData **arg1, wxListLineData **arg2 )
c801d85f 4689{
f6bcfd97
BP
4690 wxListLineData *line1 = *arg1;
4691 wxListLineData *line2 = *arg2;
5b077d48
RR
4692 wxListItem item;
4693 line1->GetItem( 0, item );
81ce36aa 4694 wxUIntPtr data1 = item.m_data;
5b077d48 4695 line2->GetItem( 0, item );
81ce36aa 4696 wxUIntPtr data2 = item.m_data;
5b077d48 4697 return list_ctrl_compare_func_2( data1, data2, list_ctrl_compare_data );
e1e955e1 4698}
c801d85f
KB
4699
4700void wxListMainWindow::SortItems( wxListCtrlCompare fn, long data )
4701{
5b077d48
RR
4702 list_ctrl_compare_func_2 = fn;
4703 list_ctrl_compare_data = data;
4704 m_lines.Sort( list_ctrl_compare_func_1 );
ca65c044 4705 m_dirty = true;
e1e955e1 4706}
c801d85f 4707
cf1dfa6b
VZ
4708// ----------------------------------------------------------------------------
4709// scrolling
4710// ----------------------------------------------------------------------------
4711
7c74e7fe
SC
4712void wxListMainWindow::OnScroll(wxScrollWinEvent& event)
4713{
cf76cd4e 4714 // update our idea of which lines are shown when we redraw the window the
b54e41c5
VZ
4715 // next time
4716 ResetVisibleLinesRange();
cf1dfa6b 4717
29149a64 4718 // FIXME
4e6b6f21 4719#if ( defined(__WXGTK__) || defined(__WXMAC__) ) && !defined(__WXUNIVERSAL__)
29149a64
VZ
4720 wxScrolledWindow::OnScroll(event);
4721#else
1e6feb95 4722 HandleOnScroll( event );
29149a64 4723#endif
30954328 4724
cf1dfa6b 4725 if ( event.GetOrientation() == wxHORIZONTAL && HasHeader() )
7c74e7fe 4726 {
3cd94a0d 4727 wxGenericListCtrl* lc = GetListCtrl();
cf1dfa6b
VZ
4728 wxCHECK_RET( lc, _T("no listctrl window?") );
4729
afbe906a
RR
4730 lc->m_headerWin->Refresh();
4731 lc->m_headerWin->Update();
7c74e7fe 4732 }
cf1dfa6b
VZ
4733}
4734
5cd89174
VZ
4735int wxListMainWindow::GetCountPerPage() const
4736{
4737 if ( !m_linesPerPage )
4738 {
4739 wxConstCast(this, wxListMainWindow)->
4740 m_linesPerPage = GetClientSize().y / GetLineHeight();
4741 }
4742
4743 return m_linesPerPage;
4744}
4745
b54e41c5 4746void wxListMainWindow::GetVisibleLinesRange(size_t *from, size_t *to)
cf1dfa6b 4747{
b5d43d1d 4748 wxASSERT_MSG( InReportView(), _T("this is for report mode only") );
cf1dfa6b 4749
b54e41c5
VZ
4750 if ( m_lineFrom == (size_t)-1 )
4751 {
b54e41c5 4752 size_t count = GetItemCount();
6522713c
VZ
4753 if ( count )
4754 {
4755 m_lineFrom = GetScrollPos(wxVERTICAL);
cf1dfa6b 4756
152c57f2
VZ
4757 // this may happen if SetScrollbars() hadn't been called yet
4758 if ( m_lineFrom >= count )
bcc0da5c 4759 m_lineFrom = count - 1;
cf1dfa6b 4760
6522713c
VZ
4761 // we redraw one extra line but this is needed to make the redrawing
4762 // logic work when there is a fractional number of lines on screen
4763 m_lineTo = m_lineFrom + m_linesPerPage;
4764 if ( m_lineTo >= count )
4765 m_lineTo = count - 1;
4766 }
4767 else // empty control
4768 {
4769 m_lineFrom = 0;
4770 m_lineTo = (size_t)-1;
4771 }
cf1dfa6b 4772 }
b54e41c5 4773
ae167d2f
VZ
4774 wxASSERT_MSG( IsEmpty() ||
4775 (m_lineFrom <= m_lineTo && m_lineTo < GetItemCount()),
6b4a8d93
VZ
4776 _T("GetVisibleLinesRange() returns incorrect result") );
4777
b54e41c5
VZ
4778 if ( from )
4779 *from = m_lineFrom;
4780 if ( to )
4781 *to = m_lineTo;
7c74e7fe
SC
4782}
4783
c801d85f 4784// -------------------------------------------------------------------------------------
3cd94a0d 4785// wxGenericListCtrl
c801d85f
KB
4786// -------------------------------------------------------------------------------------
4787
3cd94a0d
JS
4788IMPLEMENT_DYNAMIC_CLASS(wxGenericListCtrl, wxControl)
4789
3cd94a0d
JS
4790BEGIN_EVENT_TABLE(wxGenericListCtrl,wxControl)
4791 EVT_SIZE(wxGenericListCtrl::OnSize)
c801d85f
KB
4792END_EVENT_TABLE()
4793
3cd94a0d 4794wxGenericListCtrl::wxGenericListCtrl()
c801d85f 4795{
8a3e173a
KO
4796 m_imageListNormal = (wxImageList *) NULL;
4797 m_imageListSmall = (wxImageList *) NULL;
4798 m_imageListState = (wxImageList *) NULL;
cf1dfa6b
VZ
4799
4800 m_ownsImageListNormal =
4801 m_ownsImageListSmall =
ca65c044 4802 m_ownsImageListState = false;
cf1dfa6b 4803
5b077d48
RR
4804 m_mainWin = (wxListMainWindow*) NULL;
4805 m_headerWin = (wxListHeaderWindow*) NULL;
f8252483 4806 m_headerHeight = 0;
c801d85f
KB
4807}
4808
3cd94a0d 4809wxGenericListCtrl::~wxGenericListCtrl()
c801d85f 4810{
cf1dfa6b
VZ
4811 if (m_ownsImageListNormal)
4812 delete m_imageListNormal;
4813 if (m_ownsImageListSmall)
4814 delete m_imageListSmall;
4815 if (m_ownsImageListState)
4816 delete m_imageListState;
4817}
4818
f8252483
JS
4819void wxGenericListCtrl::CalculateAndSetHeaderHeight()
4820{
86351e4a
VZ
4821 if ( m_headerWin )
4822 {
fec8346a 4823#ifdef __WXMAC__
277ea1b4 4824 SInt32 h;
0afa5859 4825 GetThemeMetric( kThemeMetricListHeaderHeight, &h );
fec8346a 4826#else
86351e4a
VZ
4827 // we use 'g' to get the descent, too
4828 int w, h, d;
4829 m_headerWin->GetTextExtent(wxT("Hg"), &w, &h, &d);
4830 h += d + 2 * HEADER_OFFSET_Y + EXTRA_HEIGHT;
fec8346a 4831#endif
277ea1b4 4832
8b1ed8d9
VZ
4833 // only update if changed
4834 if ( h != m_headerHeight )
86351e4a
VZ
4835 {
4836 m_headerHeight = h;
4837
b5d43d1d 4838 if ( HasHeader() )
ca65c044 4839 ResizeReportView(true);
2ae226dd
JS
4840 else //why is this needed if it doesn't have a header?
4841 m_headerWin->SetSize(m_headerWin->GetSize().x, m_headerHeight);
86351e4a
VZ
4842 }
4843 }
f8252483
JS
4844}
4845
3cd94a0d 4846void wxGenericListCtrl::CreateHeaderWindow()
cf1dfa6b
VZ
4847{
4848 m_headerWin = new wxListHeaderWindow
4849 (
ca65c044 4850 this, wxID_ANY, m_mainWin,
c47addef 4851 wxPoint(0,0),
f8252483 4852 wxSize(GetClientSize().x, m_headerHeight),
cf1dfa6b
VZ
4853 wxTAB_TRAVERSAL
4854 );
f8252483 4855 CalculateAndSetHeaderHeight();
c801d85f
KB
4856}
4857
3cd94a0d 4858bool wxGenericListCtrl::Create(wxWindow *parent,
25e3a937
VZ
4859 wxWindowID id,
4860 const wxPoint &pos,
4861 const wxSize &size,
4862 long style,
25e3a937 4863 const wxValidator &validator,
25e3a937 4864 const wxString &name)
c801d85f 4865{
cf1dfa6b
VZ
4866 m_imageListNormal =
4867 m_imageListSmall =
8a3e173a 4868 m_imageListState = (wxImageList *) NULL;
cf1dfa6b
VZ
4869 m_ownsImageListNormal =
4870 m_ownsImageListSmall =
ca65c044 4871 m_ownsImageListState = false;
cf1dfa6b 4872
5b077d48
RR
4873 m_mainWin = (wxListMainWindow*) NULL;
4874 m_headerWin = (wxListHeaderWindow*) NULL;
bd8289c1 4875
3fc93ebd
JS
4876 m_headerHeight = 0;
4877
b54e41c5 4878 if ( !(style & wxLC_MASK_TYPE) )
5b077d48 4879 {
25e3a937 4880 style = style | wxLC_LIST;
5b077d48 4881 }
f6bcfd97 4882
07215d86 4883 if ( !wxControl::Create( parent, id, pos, size, style, validator, name ) )
ca65c044 4884 return false;
f6bcfd97 4885
b54e41c5 4886 // don't create the inner window with the border
6d460f76 4887 style &= ~wxBORDER_MASK;
bd8289c1 4888
277ea1b4 4889 m_mainWin = new wxListMainWindow( this, wxID_ANY, wxPoint(0, 0), size, style );
bd8289c1 4890
b713f891 4891#ifdef __WXMAC_CARBON__
309e4c14
SC
4892 // Human Interface Guidelines ask us for a special font in this case
4893 if ( GetWindowVariant() == wxWINDOW_VARIANT_NORMAL )
4894 {
277ea1b4
DS
4895 wxFont font;
4896 font.MacCreateThemeFont( kThemeViewsFont );
4897 SetFont( font );
309e4c14 4898 }
f89d65ea 4899#endif
277ea1b4 4900
b5d43d1d 4901 if ( InReportView() )
ea451729 4902 {
cf1dfa6b 4903 CreateHeaderWindow();
277ea1b4 4904
d108f236
SC
4905#ifdef __WXMAC_CARBON__
4906 if (m_headerWin)
4907 {
277ea1b4
DS
4908 wxFont font;
4909 font.MacCreateThemeFont( kThemeSmallSystemFont );
d108f236
SC
4910 m_headerWin->SetFont( font );
4911 CalculateAndSetHeaderHeight();
4912 }
4913#endif
277ea1b4 4914
b54e41c5 4915 if ( HasFlag(wxLC_NO_HEADER) )
cf1dfa6b 4916 // VZ: why do we create it at all then?
ca65c044 4917 m_headerWin->Show( false );
ea451729 4918 }
bd8289c1 4919
170acdc9 4920 SetInitialSize(size);
ca65c044
WS
4921
4922 return true;
e1e955e1 4923}
c801d85f 4924
3cd94a0d 4925void wxGenericListCtrl::SetSingleStyle( long style, bool add )
c801d85f 4926{
b54e41c5
VZ
4927 wxASSERT_MSG( !(style & wxLC_VIRTUAL),
4928 _T("wxLC_VIRTUAL can't be [un]set") );
4929
f03fc89f 4930 long flag = GetWindowStyle();
bd8289c1 4931
5b077d48
RR
4932 if (add)
4933 {
cf1dfa6b 4934 if (style & wxLC_MASK_TYPE)
b54e41c5 4935 flag &= ~(wxLC_MASK_TYPE | wxLC_VIRTUAL);
cf1dfa6b
VZ
4936 if (style & wxLC_MASK_ALIGN)
4937 flag &= ~wxLC_MASK_ALIGN;
4938 if (style & wxLC_MASK_SORT)
4939 flag &= ~wxLC_MASK_SORT;
5b077d48 4940 }
c801d85f 4941
5b077d48 4942 if (add)
5b077d48 4943 flag |= style;
5b077d48 4944 else
cf1dfa6b 4945 flag &= ~style;
bd8289c1 4946
5b077d48 4947 SetWindowStyleFlag( flag );
e1e955e1 4948}
c801d85f 4949
3cd94a0d 4950void wxGenericListCtrl::SetWindowStyleFlag( long flag )
c801d85f 4951{
121a3581
RR
4952 if (m_mainWin)
4953 {
4954 m_mainWin->DeleteEverything();
c801d85f 4955
a95cdab8 4956 // has the header visibility changed?
b5d43d1d
VZ
4957 bool hasHeader = HasHeader();
4958 bool willHaveHeader = (flag & wxLC_REPORT) && !(flag & wxLC_NO_HEADER);
c801d85f 4959
a95cdab8 4960 if ( hasHeader != willHaveHeader )
5b077d48 4961 {
a95cdab8
VZ
4962 // toggle it
4963 if ( hasHeader )
4964 {
4965 if ( m_headerWin )
4966 {
4967 // don't delete, just hide, as we can reuse it later
ca65c044 4968 m_headerWin->Show(false);
a95cdab8
VZ
4969 }
4970 //else: nothing to do
4971 }
4972 else // must show header
5b077d48 4973 {
121a3581
RR
4974 if (!m_headerWin)
4975 {
cf1dfa6b 4976 CreateHeaderWindow();
121a3581 4977 }
a95cdab8 4978 else // already have it, just show
004fd0c8 4979 {
ca65c044 4980 m_headerWin->Show( true );
004fd0c8 4981 }
5b077d48 4982 }
a95cdab8
VZ
4983
4984 ResizeReportView(willHaveHeader);
bffa1c77 4985 }
e1e955e1 4986 }
004fd0c8 4987
5b077d48 4988 wxWindow::SetWindowStyleFlag( flag );
e1e955e1 4989}
c801d85f 4990
3cd94a0d 4991bool wxGenericListCtrl::GetColumn(int col, wxListItem &item) const
c801d85f 4992{
5b077d48 4993 m_mainWin->GetColumn( col, item );
ca65c044 4994 return true;
e1e955e1 4995}
c801d85f 4996
3cd94a0d 4997bool wxGenericListCtrl::SetColumn( int col, wxListItem& item )
c801d85f 4998{
5b077d48 4999 m_mainWin->SetColumn( col, item );
ca65c044 5000 return true;
e1e955e1 5001}
c801d85f 5002
3cd94a0d 5003int wxGenericListCtrl::GetColumnWidth( int col ) const
c801d85f 5004{
5b077d48 5005 return m_mainWin->GetColumnWidth( col );
e1e955e1 5006}
c801d85f 5007
3cd94a0d 5008bool wxGenericListCtrl::SetColumnWidth( int col, int width )
c801d85f 5009{
5b077d48 5010 m_mainWin->SetColumnWidth( col, width );
ca65c044 5011 return true;
e1e955e1 5012}
c801d85f 5013
3cd94a0d 5014int wxGenericListCtrl::GetCountPerPage() const
c801d85f
KB
5015{
5016 return m_mainWin->GetCountPerPage(); // different from Windows ?
e1e955e1 5017}
c801d85f 5018
3cd94a0d 5019bool wxGenericListCtrl::GetItem( wxListItem &info ) const
c801d85f 5020{
5b077d48 5021 m_mainWin->GetItem( info );
ca65c044 5022 return true;
e1e955e1 5023}
c801d85f 5024
3cd94a0d 5025bool wxGenericListCtrl::SetItem( wxListItem &info )
c801d85f 5026{
5b077d48 5027 m_mainWin->SetItem( info );
ca65c044 5028 return true;
e1e955e1 5029}
c801d85f 5030
3cd94a0d 5031long wxGenericListCtrl::SetItem( long index, int col, const wxString& label, int imageId )
c801d85f 5032{
5b077d48
RR
5033 wxListItem info;
5034 info.m_text = label;
5035 info.m_mask = wxLIST_MASK_TEXT;
5036 info.m_itemId = index;
5037 info.m_col = col;
5038 if ( imageId > -1 )
5039 {
5040 info.m_image = imageId;
5041 info.m_mask |= wxLIST_MASK_IMAGE;
277ea1b4
DS
5042 }
5043
5b077d48 5044 m_mainWin->SetItem(info);
ca65c044 5045 return true;
e1e955e1 5046}
c801d85f 5047
3cd94a0d 5048int wxGenericListCtrl::GetItemState( long item, long stateMask ) const
c801d85f 5049{
5b077d48 5050 return m_mainWin->GetItemState( item, stateMask );
e1e955e1 5051}
c801d85f 5052
3cd94a0d 5053bool wxGenericListCtrl::SetItemState( long item, long state, long stateMask )
c801d85f 5054{
5b077d48 5055 m_mainWin->SetItemState( item, state, stateMask );
ca65c044 5056 return true;
e1e955e1 5057}
c801d85f 5058
aba3d35e
VZ
5059bool
5060wxGenericListCtrl::SetItemImage( long item, int image, int WXUNUSED(selImage) )
06db67bc
RD
5061{
5062 return SetItemColumnImage(item, 0, image);
5063}
5064
5065bool
5066wxGenericListCtrl::SetItemColumnImage( long item, long column, int image )
c3627a00
JS
5067{
5068 wxListItem info;
5069 info.m_image = image;
5070 info.m_mask = wxLIST_MASK_IMAGE;
5071 info.m_itemId = item;
06db67bc 5072 info.m_col = column;
c3627a00
JS
5073 m_mainWin->SetItem( info );
5074 return true;
5075}
c801d85f 5076
3cd94a0d 5077wxString wxGenericListCtrl::GetItemText( long item ) const
c801d85f 5078{
62d89eb4 5079 return m_mainWin->GetItemText(item);
e1e955e1 5080}
c801d85f 5081
3cd94a0d 5082void wxGenericListCtrl::SetItemText( long item, const wxString& str )
c801d85f 5083{
62d89eb4 5084 m_mainWin->SetItemText(item, str);
e1e955e1 5085}
c801d85f 5086
81ce36aa 5087wxUIntPtr wxGenericListCtrl::GetItemData( long item ) const
c801d85f 5088{
5b077d48 5089 wxListItem info;
39a7f085 5090 info.m_mask = wxLIST_MASK_DATA;
5b077d48
RR
5091 info.m_itemId = item;
5092 m_mainWin->GetItem( info );
5093 return info.m_data;
e1e955e1 5094}
c801d85f 5095
3cd94a0d 5096bool wxGenericListCtrl::SetItemData( long item, long data )
c801d85f 5097{
5b077d48
RR
5098 wxListItem info;
5099 info.m_mask = wxLIST_MASK_DATA;
5100 info.m_itemId = item;
5101 info.m_data = data;
5102 m_mainWin->SetItem( info );
ca65c044 5103 return true;
e1e955e1 5104}
c801d85f 5105
11ebea16
VZ
5106wxRect wxGenericListCtrl::GetViewRect() const
5107{
5108 return m_mainWin->GetViewRect();
5109}
5110
277ea1b4 5111bool wxGenericListCtrl::GetItemRect( long item, wxRect &rect, int WXUNUSED(code) ) const
c801d85f 5112{
5b077d48 5113 m_mainWin->GetItemRect( item, rect );
7e6874c0 5114 if ( m_mainWin->HasHeader() )
f8252483 5115 rect.y += m_headerHeight + 1;
ca65c044 5116 return true;
e1e955e1 5117}
c801d85f 5118
3cd94a0d 5119bool wxGenericListCtrl::GetItemPosition( long item, wxPoint& pos ) const
c801d85f 5120{
5b077d48 5121 m_mainWin->GetItemPosition( item, pos );
ca65c044 5122 return true;
e1e955e1 5123}
c801d85f 5124
3cd94a0d 5125bool wxGenericListCtrl::SetItemPosition( long WXUNUSED(item), const wxPoint& WXUNUSED(pos) )
c801d85f 5126{
5b077d48 5127 return 0;
e1e955e1 5128}
c801d85f 5129
3cd94a0d 5130int wxGenericListCtrl::GetItemCount() const
c801d85f 5131{
5b077d48 5132 return m_mainWin->GetItemCount();
e1e955e1 5133}
c801d85f 5134
3cd94a0d 5135int wxGenericListCtrl::GetColumnCount() const
92976ab6 5136{
5b077d48 5137 return m_mainWin->GetColumnCount();
92976ab6
RR
5138}
5139
3cd94a0d 5140void wxGenericListCtrl::SetItemSpacing( int spacing, bool isSmall )
33d0b396 5141{
5b077d48 5142 m_mainWin->SetItemSpacing( spacing, isSmall );
e1e955e1 5143}
33d0b396 5144
5db8d758
VZ
5145wxSize wxGenericListCtrl::GetItemSpacing() const
5146{
f58fc140 5147 const int spacing = m_mainWin->GetItemSpacing(HasFlag(wxLC_SMALL_ICON));
5db8d758
VZ
5148
5149 return wxSize(spacing, spacing);
5150}
5151
82d492f1 5152#if WXWIN_COMPATIBILITY_2_6
3cd94a0d 5153int wxGenericListCtrl::GetItemSpacing( bool isSmall ) const
c801d85f 5154{
5b077d48 5155 return m_mainWin->GetItemSpacing( isSmall );
e1e955e1 5156}
82d492f1 5157#endif // WXWIN_COMPATIBILITY_2_6
c801d85f 5158
3cd94a0d 5159void wxGenericListCtrl::SetItemTextColour( long item, const wxColour &col )
5b98eb2f
RL
5160{
5161 wxListItem info;
5162 info.m_itemId = item;
5163 info.SetTextColour( col );
5164 m_mainWin->SetItem( info );
5165}
5166
3cd94a0d 5167wxColour wxGenericListCtrl::GetItemTextColour( long item ) const
5b98eb2f
RL
5168{
5169 wxListItem info;
5170 info.m_itemId = item;
5171 m_mainWin->GetItem( info );
5172 return info.GetTextColour();
5173}
5174
3cd94a0d 5175void wxGenericListCtrl::SetItemBackgroundColour( long item, const wxColour &col )
5b98eb2f
RL
5176{
5177 wxListItem info;
5178 info.m_itemId = item;
5179 info.SetBackgroundColour( col );
5180 m_mainWin->SetItem( info );
5181}
5182
3cd94a0d 5183wxColour wxGenericListCtrl::GetItemBackgroundColour( long item ) const
5b98eb2f
RL
5184{
5185 wxListItem info;
5186 info.m_itemId = item;
5187 m_mainWin->GetItem( info );
5188 return info.GetBackgroundColour();
5189}
5190
35c2acd4
MW
5191void wxGenericListCtrl::SetItemFont( long item, const wxFont &f )
5192{
5193 wxListItem info;
5194 info.m_itemId = item;
5195 info.SetFont( f );
5196 m_mainWin->SetItem( info );
5197}
5198
5199wxFont wxGenericListCtrl::GetItemFont( long item ) const
5200{
5201 wxListItem info;
5202 info.m_itemId = item;
5203 m_mainWin->GetItem( info );
5204 return info.GetFont();
5205}
5206
3cd94a0d 5207int wxGenericListCtrl::GetSelectedItemCount() const
c801d85f 5208{
5b077d48 5209 return m_mainWin->GetSelectedItemCount();
e1e955e1 5210}
c801d85f 5211
3cd94a0d 5212wxColour wxGenericListCtrl::GetTextColour() const
c801d85f 5213{
0530737d 5214 return GetForegroundColour();
e1e955e1 5215}
c801d85f 5216
3cd94a0d 5217void wxGenericListCtrl::SetTextColour(const wxColour& col)
c801d85f 5218{
0530737d 5219 SetForegroundColour(col);
e1e955e1 5220}
c801d85f 5221
3cd94a0d 5222long wxGenericListCtrl::GetTopItem() const
c801d85f 5223{
2b5f62a0
VZ
5224 size_t top;
5225 m_mainWin->GetVisibleLinesRange(&top, NULL);
5226 return (long)top;
e1e955e1 5227}
c801d85f 5228
3cd94a0d 5229long wxGenericListCtrl::GetNextItem( long item, int geom, int state ) const
c801d85f 5230{
5b077d48 5231 return m_mainWin->GetNextItem( item, geom, state );
e1e955e1 5232}
c801d85f 5233
8a3e173a 5234wxImageList *wxGenericListCtrl::GetImageList(int which) const
c801d85f 5235{
5b077d48 5236 if (which == wxIMAGE_LIST_NORMAL)
5b077d48 5237 return m_imageListNormal;
5b077d48 5238 else if (which == wxIMAGE_LIST_SMALL)
5b077d48 5239 return m_imageListSmall;
5b077d48 5240 else if (which == wxIMAGE_LIST_STATE)
5b077d48 5241 return m_imageListState;
277ea1b4 5242
8a3e173a 5243 return (wxImageList *) NULL;
e1e955e1 5244}
c801d85f 5245
8a3e173a 5246void wxGenericListCtrl::SetImageList( wxImageList *imageList, int which )
c801d85f 5247{
2e12c11a
VS
5248 if ( which == wxIMAGE_LIST_NORMAL )
5249 {
277ea1b4
DS
5250 if (m_ownsImageListNormal)
5251 delete m_imageListNormal;
2e12c11a 5252 m_imageListNormal = imageList;
ca65c044 5253 m_ownsImageListNormal = false;
2e12c11a
VS
5254 }
5255 else if ( which == wxIMAGE_LIST_SMALL )
5256 {
277ea1b4
DS
5257 if (m_ownsImageListSmall)
5258 delete m_imageListSmall;
2e12c11a 5259 m_imageListSmall = imageList;
ca65c044 5260 m_ownsImageListSmall = false;
2e12c11a
VS
5261 }
5262 else if ( which == wxIMAGE_LIST_STATE )
5263 {
277ea1b4
DS
5264 if (m_ownsImageListState)
5265 delete m_imageListState;
2e12c11a 5266 m_imageListState = imageList;
ca65c044 5267 m_ownsImageListState = false;
2e12c11a
VS
5268 }
5269
5b077d48 5270 m_mainWin->SetImageList( imageList, which );
e1e955e1 5271}
c801d85f 5272
8a3e173a 5273void wxGenericListCtrl::AssignImageList(wxImageList *imageList, int which)
2e12c11a
VS
5274{
5275 SetImageList(imageList, which);
5276 if ( which == wxIMAGE_LIST_NORMAL )
ca65c044 5277 m_ownsImageListNormal = true;
2e12c11a 5278 else if ( which == wxIMAGE_LIST_SMALL )
ca65c044 5279 m_ownsImageListSmall = true;
2e12c11a 5280 else if ( which == wxIMAGE_LIST_STATE )
ca65c044 5281 m_ownsImageListState = true;
2e12c11a
VS
5282}
5283
3cd94a0d 5284bool wxGenericListCtrl::Arrange( int WXUNUSED(flag) )
c801d85f 5285{
5b077d48 5286 return 0;
e1e955e1 5287}
c801d85f 5288
3cd94a0d 5289bool wxGenericListCtrl::DeleteItem( long item )
c801d85f 5290{
5b077d48 5291 m_mainWin->DeleteItem( item );
ca65c044 5292 return true;
e1e955e1 5293}
c801d85f 5294
3cd94a0d 5295bool wxGenericListCtrl::DeleteAllItems()
c801d85f 5296{
5b077d48 5297 m_mainWin->DeleteAllItems();
ca65c044 5298 return true;
e1e955e1 5299}
c801d85f 5300
3cd94a0d 5301bool wxGenericListCtrl::DeleteAllColumns()
bd8289c1 5302{
24b9f055
VZ
5303 size_t count = m_mainWin->m_columns.GetCount();
5304 for ( size_t n = 0; n < count; n++ )
277ea1b4 5305 DeleteColumn( 0 );
ca65c044 5306 return true;
4f22cf8d
RR
5307}
5308
3cd94a0d 5309void wxGenericListCtrl::ClearAll()
4f22cf8d 5310{
5b077d48 5311 m_mainWin->DeleteEverything();
bd8289c1
VZ
5312}
5313
3cd94a0d 5314bool wxGenericListCtrl::DeleteColumn( int col )
c801d85f 5315{
5b077d48 5316 m_mainWin->DeleteColumn( col );
40c08808
VZ
5317
5318 // if we don't have the header any longer, we need to relayout the window
5319 if ( !GetColumnCount() )
ca65c044 5320 ResizeReportView(false /* no header */);
ca65c044 5321 return true;
e1e955e1 5322}
c801d85f 5323
26e8da41
VZ
5324wxTextCtrl *wxGenericListCtrl::EditLabel(long item,
5325 wxClassInfo* textControlClass)
5326{
5327 return m_mainWin->EditLabel( item, textControlClass );
5328}
5329
5330wxTextCtrl *wxGenericListCtrl::GetEditControl() const
c801d85f 5331{
26e8da41 5332 return m_mainWin->GetEditControl();
e1e955e1 5333}
c801d85f 5334
3cd94a0d 5335bool wxGenericListCtrl::EnsureVisible( long item )
c801d85f 5336{
5b077d48 5337 m_mainWin->EnsureVisible( item );
ca65c044 5338 return true;
e1e955e1 5339}
c801d85f 5340
277ea1b4 5341long wxGenericListCtrl::FindItem( long start, const wxString& str, bool partial )
c801d85f 5342{
5b077d48 5343 return m_mainWin->FindItem( start, str, partial );
e1e955e1 5344}
c801d85f 5345
81ce36aa 5346long wxGenericListCtrl::FindItem( long start, wxUIntPtr data )
c801d85f 5347{
5b077d48 5348 return m_mainWin->FindItem( start, data );
e1e955e1 5349}
c801d85f 5350
8158e0e1 5351long wxGenericListCtrl::FindItem( long WXUNUSED(start), const wxPoint& pt,
debe6624 5352 int WXUNUSED(direction))
c801d85f 5353{
8158e0e1 5354 return m_mainWin->FindItem( pt );
e1e955e1 5355}
c801d85f 5356
164a7972 5357// TODO: sub item hit testing
be0e5d69 5358long wxGenericListCtrl::HitTest(const wxPoint& point, int& flags, long *) const
c801d85f 5359{
5b077d48 5360 return m_mainWin->HitTest( (int)point.x, (int)point.y, flags );
e1e955e1 5361}
c801d85f 5362
3cd94a0d 5363long wxGenericListCtrl::InsertItem( wxListItem& info )
c801d85f 5364{
5b077d48 5365 m_mainWin->InsertItem( info );
2ebcd5f5 5366 return info.m_itemId;
e1e955e1 5367}
c801d85f 5368
3cd94a0d 5369long wxGenericListCtrl::InsertItem( long index, const wxString &label )
c801d85f 5370{
51cc4dad
RR
5371 wxListItem info;
5372 info.m_text = label;
5373 info.m_mask = wxLIST_MASK_TEXT;
5374 info.m_itemId = index;
5375 return InsertItem( info );
e1e955e1 5376}
c801d85f 5377
3cd94a0d 5378long wxGenericListCtrl::InsertItem( long index, int imageIndex )
c801d85f 5379{
51cc4dad
RR
5380 wxListItem info;
5381 info.m_mask = wxLIST_MASK_IMAGE;
5382 info.m_image = imageIndex;
5383 info.m_itemId = index;
5384 return InsertItem( info );
e1e955e1 5385}
c801d85f 5386
3cd94a0d 5387long wxGenericListCtrl::InsertItem( long index, const wxString &label, int imageIndex )
c801d85f 5388{
51cc4dad
RR
5389 wxListItem info;
5390 info.m_text = label;
5391 info.m_image = imageIndex;
5392 info.m_mask = wxLIST_MASK_TEXT | wxLIST_MASK_IMAGE;
5393 info.m_itemId = index;
5394 return InsertItem( info );
e1e955e1 5395}
c801d85f 5396
3cd94a0d 5397long wxGenericListCtrl::InsertColumn( long col, wxListItem &item )
c801d85f 5398{
40c08808
VZ
5399 wxCHECK_MSG( m_headerWin, -1, _T("can't add column in non report mode") );
5400
51cc4dad 5401 m_mainWin->InsertColumn( col, item );
40c08808 5402
277ea1b4
DS
5403 // if we hadn't had a header before but have one now
5404 // then we need to relayout the window
ac53090c 5405 if ( GetColumnCount() == 1 && m_mainWin->HasHeader() )
ca65c044 5406 ResizeReportView(true /* have header */);
40c08808 5407
d3e90957 5408 m_headerWin->Refresh();
25e3a937 5409
51cc4dad 5410 return 0;
e1e955e1 5411}
c801d85f 5412
3cd94a0d 5413long wxGenericListCtrl::InsertColumn( long col, const wxString &heading,
debe6624 5414 int format, int width )
c801d85f 5415{
51cc4dad
RR
5416 wxListItem item;
5417 item.m_mask = wxLIST_MASK_TEXT | wxLIST_MASK_FORMAT;
5418 item.m_text = heading;
5419 if (width >= -2)
5420 {
5421 item.m_mask |= wxLIST_MASK_WIDTH;
5422 item.m_width = width;
5423 }
277ea1b4 5424
51cc4dad 5425 item.m_format = format;
c801d85f 5426
51cc4dad 5427 return InsertColumn( col, item );
e1e955e1 5428}
c801d85f 5429
3cd94a0d 5430bool wxGenericListCtrl::ScrollList( int WXUNUSED(dx), int WXUNUSED(dy) )
c801d85f 5431{
51cc4dad 5432 return 0;
e1e955e1 5433}
c801d85f
KB
5434
5435// Sort items.
5436// fn is a function which takes 3 long arguments: item1, item2, data.
5437// item1 is the long data associated with a first item (NOT the index).
5438// item2 is the long data associated with a second item (NOT the index).
5439// data is the same value as passed to SortItems.
5440// The return value is a negative number if the first item should precede the second
5441// item, a positive number of the second item should precede the first,
5442// or zero if the two items are equivalent.
5443// data is arbitrary data to be passed to the sort function.
5444
3cd94a0d 5445bool wxGenericListCtrl::SortItems( wxListCtrlCompare fn, long data )
c801d85f 5446{
51cc4dad 5447 m_mainWin->SortItems( fn, data );
ca65c044 5448 return true;
e1e955e1 5449}
c801d85f 5450
cf1dfa6b 5451// ----------------------------------------------------------------------------
b54e41c5 5452// event handlers
cf1dfa6b
VZ
5453// ----------------------------------------------------------------------------
5454
3cd94a0d 5455void wxGenericListCtrl::OnSize(wxSizeEvent& WXUNUSED(event))
53010e52 5456{
b54e41c5 5457 if ( !m_mainWin )
cf1dfa6b 5458 return;
53010e52 5459
a95cdab8 5460 ResizeReportView(m_mainWin->HasHeader());
a95cdab8
VZ
5461 m_mainWin->RecalculatePositions();
5462}
5463
3cd94a0d 5464void wxGenericListCtrl::ResizeReportView(bool showHeader)
a95cdab8 5465{
b54e41c5 5466 int cw, ch;
51cc4dad 5467 GetClientSize( &cw, &ch );
bd8289c1 5468
a95cdab8 5469 if ( showHeader )
51cc4dad 5470 {
f8252483 5471 m_headerWin->SetSize( 0, 0, cw, m_headerHeight );
2ae226dd 5472 if(ch > m_headerHeight)
faa94f3e 5473 m_mainWin->SetSize( 0, m_headerHeight + 1,
2ae226dd
JS
5474 cw, ch - m_headerHeight - 1 );
5475 else
faa94f3e 5476 m_mainWin->SetSize( 0, m_headerHeight + 1,
2ae226dd 5477 cw, 0);
51cc4dad 5478 }
cf1dfa6b 5479 else // no header window
51cc4dad 5480 {
cf1dfa6b 5481 m_mainWin->SetSize( 0, 0, cw, ch );
51cc4dad 5482 }
b54e41c5 5483}
cf1dfa6b 5484
5180055b 5485void wxGenericListCtrl::OnInternalIdle()
b54e41c5 5486{
5180055b 5487 wxWindow::OnInternalIdle();
86351e4a 5488
b54e41c5
VZ
5489 // do it only if needed
5490 if ( !m_mainWin->m_dirty )
5491 return;
5492
5493 m_mainWin->RecalculatePositions();
e1e955e1 5494}
53010e52 5495
cf1dfa6b
VZ
5496// ----------------------------------------------------------------------------
5497// font/colours
5498// ----------------------------------------------------------------------------
5499
3cd94a0d 5500bool wxGenericListCtrl::SetBackgroundColour( const wxColour &colour )
bd8289c1 5501{
51cc4dad
RR
5502 if (m_mainWin)
5503 {
5504 m_mainWin->SetBackgroundColour( colour );
ca65c044 5505 m_mainWin->m_dirty = true;
51cc4dad 5506 }
004fd0c8 5507
ca65c044 5508 return true;
e4d06860
RR
5509}
5510
3cd94a0d 5511bool wxGenericListCtrl::SetForegroundColour( const wxColour &colour )
bd8289c1 5512{
f03fc89f 5513 if ( !wxWindow::SetForegroundColour( colour ) )
ca65c044 5514 return false;
004fd0c8 5515
51cc4dad
RR
5516 if (m_mainWin)
5517 {
5518 m_mainWin->SetForegroundColour( colour );
ca65c044 5519 m_mainWin->m_dirty = true;
51cc4dad 5520 }
004fd0c8 5521
51cc4dad 5522 if (m_headerWin)
51cc4dad 5523 m_headerWin->SetForegroundColour( colour );
f03fc89f 5524
ca65c044 5525 return true;
e4d06860 5526}
bd8289c1 5527
3cd94a0d 5528bool wxGenericListCtrl::SetFont( const wxFont &font )
bd8289c1 5529{
f03fc89f 5530 if ( !wxWindow::SetFont( font ) )
ca65c044 5531 return false;
004fd0c8 5532
51cc4dad
RR
5533 if (m_mainWin)
5534 {
5535 m_mainWin->SetFont( font );
ca65c044 5536 m_mainWin->m_dirty = true;
51cc4dad 5537 }
004fd0c8 5538
51cc4dad
RR
5539 if (m_headerWin)
5540 {
5541 m_headerWin->SetFont( font );
f8252483 5542 CalculateAndSetHeaderHeight();
51cc4dad 5543 }
f03fc89f 5544
f8252483
JS
5545 Refresh();
5546
ca65c044 5547 return true;
e4d06860 5548}
c801d85f 5549
277ea1b4 5550// static
35d4c967
RD
5551wxVisualAttributes
5552wxGenericListCtrl::GetClassDefaultAttributes(wxWindowVariant variant)
5553{
5554#if _USE_VISATTR
5555 // Use the same color scheme as wxListBox
5556 return wxListBox::GetClassDefaultAttributes(variant);
5557#else
e7045784 5558 wxUnusedVar(variant);
35d4c967
RD
5559 wxVisualAttributes attr;
5560 attr.colFg = wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT);
5561 attr.colBg = wxSystemSettings::GetColour(wxSYS_COLOUR_LISTBOX);
5562 attr.font = wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT);
5563 return attr;
5564#endif
5565}
5566
cf1dfa6b
VZ
5567// ----------------------------------------------------------------------------
5568// methods forwarded to m_mainWin
5569// ----------------------------------------------------------------------------
5570
efbb7287
VZ
5571#if wxUSE_DRAG_AND_DROP
5572
3cd94a0d 5573void wxGenericListCtrl::SetDropTarget( wxDropTarget *dropTarget )
efbb7287
VZ
5574{
5575 m_mainWin->SetDropTarget( dropTarget );
5576}
5577
3cd94a0d 5578wxDropTarget *wxGenericListCtrl::GetDropTarget() const
efbb7287
VZ
5579{
5580 return m_mainWin->GetDropTarget();
5581}
5582
277ea1b4 5583#endif
efbb7287 5584
3cd94a0d 5585bool wxGenericListCtrl::SetCursor( const wxCursor &cursor )
efbb7287 5586{
ca65c044 5587 return m_mainWin ? m_mainWin->wxWindow::SetCursor(cursor) : false;
efbb7287
VZ
5588}
5589
3cd94a0d 5590wxColour wxGenericListCtrl::GetBackgroundColour() const
efbb7287
VZ
5591{
5592 return m_mainWin ? m_mainWin->GetBackgroundColour() : wxColour();
5593}
5594
3cd94a0d 5595wxColour wxGenericListCtrl::GetForegroundColour() const
efbb7287
VZ
5596{
5597 return m_mainWin ? m_mainWin->GetForegroundColour() : wxColour();
5598}
5599
3cd94a0d 5600bool wxGenericListCtrl::DoPopupMenu( wxMenu *menu, int x, int y )
efbb7287 5601{
3a8c693a 5602#if wxUSE_MENUS
efbb7287 5603 return m_mainWin->PopupMenu( menu, x, y );
3a8c693a 5604#else
ca65c044 5605 return false;
277ea1b4 5606#endif
efbb7287
VZ
5607}
5608
7447bdd7
VZ
5609void wxGenericListCtrl::DoClientToScreen( int *x, int *y ) const
5610{
5d584acb 5611 m_mainWin->DoClientToScreen(x, y);
7447bdd7
VZ
5612}
5613
5614void wxGenericListCtrl::DoScreenToClient( int *x, int *y ) const
5615{
5d584acb 5616 m_mainWin->DoScreenToClient(x, y);
7447bdd7
VZ
5617}
5618
3cd94a0d 5619void wxGenericListCtrl::SetFocus()
efbb7287 5620{
277ea1b4
DS
5621 // The test in window.cpp fails as we are a composite
5622 // window, so it checks against "this", but not m_mainWin.
66370e38 5623 if ( DoFindFocus() != this )
efbb7287
VZ
5624 m_mainWin->SetFocus();
5625}
1e6feb95 5626
3872d96d
RD
5627wxSize wxGenericListCtrl::DoGetBestSize() const
5628{
5629 // Something is better than nothing...
5630 // 100x80 is what the MSW version will get from the default
5631 // wxControl::DoGetBestSize
277ea1b4 5632 return wxSize(100, 80);
3872d96d
RD
5633}
5634
2c1f73ee
VZ
5635// ----------------------------------------------------------------------------
5636// virtual list control support
5637// ----------------------------------------------------------------------------
5638
3cd94a0d 5639wxString wxGenericListCtrl::OnGetItemText(long WXUNUSED(item), long WXUNUSED(col)) const
2c1f73ee
VZ
5640{
5641 // this is a pure virtual function, in fact - which is not really pure
5642 // because the controls which are not virtual don't need to implement it
3cd94a0d 5643 wxFAIL_MSG( _T("wxGenericListCtrl::OnGetItemText not supposed to be called") );
2c1f73ee
VZ
5644
5645 return wxEmptyString;
5646}
5647
3cd94a0d 5648int wxGenericListCtrl::OnGetItemImage(long WXUNUSED(item)) const
2c1f73ee 5649{
611a725e
RD
5650 wxCHECK_MSG(!GetImageList(wxIMAGE_LIST_SMALL),
5651 -1,
208458a7 5652 wxT("List control has an image list, OnGetItemImage or OnGetItemColumnImage should be overridden."));
2c1f73ee
VZ
5653 return -1;
5654}
5655
208458a7
RD
5656int wxGenericListCtrl::OnGetItemColumnImage(long item, long column) const
5657{
5658 if (!column)
5659 return OnGetItemImage(item);
5660
5661 return -1;
08a175ce 5662}
208458a7 5663
999836aa
VZ
5664wxListItemAttr *
5665wxGenericListCtrl::OnGetItemAttr(long WXUNUSED_UNLESS_DEBUG(item)) const
6c02c329
VZ
5666{
5667 wxASSERT_MSG( item >= 0 && item < GetItemCount(),
5668 _T("invalid item index in OnGetItemAttr()") );
5669
5670 // no attributes by default
5671 return NULL;
5672}
5673
3cd94a0d 5674void wxGenericListCtrl::SetItemCount(long count)
2c1f73ee
VZ
5675{
5676 wxASSERT_MSG( IsVirtual(), _T("this is for virtual controls only") );
5677
5678 m_mainWin->SetItemCount(count);
5679}
5680
3cd94a0d 5681void wxGenericListCtrl::RefreshItem(long item)
1a6cb56f
VZ
5682{
5683 m_mainWin->RefreshLine(item);
5684}
5685
3cd94a0d 5686void wxGenericListCtrl::RefreshItems(long itemFrom, long itemTo)
1a6cb56f
VZ
5687{
5688 m_mainWin->RefreshLines(itemFrom, itemTo);
5689}
5690
277ea1b4
DS
5691// Generic wxListCtrl is more or less a container for two other
5692// windows which drawings are done upon. These are namely
5693// 'm_headerWin' and 'm_mainWin'.
5694// Here we override 'virtual wxWindow::Refresh()' to mimic the
5695// behaviour wxListCtrl has under wxMSW.
5696//
2f1e3c46
VZ
5697void wxGenericListCtrl::Refresh(bool eraseBackground, const wxRect *rect)
5698{
5699 if (!rect)
5700 {
5701 // The easy case, no rectangle specified.
5702 if (m_headerWin)
5703 m_headerWin->Refresh(eraseBackground);
5704
5705 if (m_mainWin)
5706 m_mainWin->Refresh(eraseBackground);
5707 }
5708 else
5709 {
5710 // Refresh the header window
5711 if (m_headerWin)
5712 {
5713 wxRect rectHeader = m_headerWin->GetRect();
5714 rectHeader.Intersect(*rect);
5715 if (rectHeader.GetWidth() && rectHeader.GetHeight())
5716 {
5717 int x, y;
5718 m_headerWin->GetPosition(&x, &y);
5719 rectHeader.Offset(-x, -y);
5720 m_headerWin->Refresh(eraseBackground, &rectHeader);
5721 }
2f1e3c46
VZ
5722 }
5723
5724 // Refresh the main window
5725 if (m_mainWin)
5726 {
5727 wxRect rectMain = m_mainWin->GetRect();
5728 rectMain.Intersect(*rect);
5729 if (rectMain.GetWidth() && rectMain.GetHeight())
5730 {
5731 int x, y;
5732 m_mainWin->GetPosition(&x, &y);
5733 rectMain.Offset(-x, -y);
5734 m_mainWin->Refresh(eraseBackground, &rectMain);
5735 }
5736 }
5737 }
5738}
5739
3cd94a0d 5740void wxGenericListCtrl::Freeze()
c5c528fc
VZ
5741{
5742 m_mainWin->Freeze();
5743}
5744
3cd94a0d 5745void wxGenericListCtrl::Thaw()
c5c528fc
VZ
5746{
5747 m_mainWin->Thaw();
5748}
5749
1e6feb95 5750#endif // wxUSE_LISTCTRL