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