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