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