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