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