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