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