]> git.saurik.com Git - wxWidgets.git/blame - src/generic/listctrl.cpp
Smartphone specific resource files.
[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
537 // change the line "selected" state, return TRUE if it really changed
b54e41c5
VZ
538 bool HighlightLine( size_t line, bool highlight = TRUE);
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
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 );
efbb7287
VZ
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
34bbbc27 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 );
678 long FindItem( long start, const wxString& str, bool partial = FALSE );
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) )
703 return FALSE;
704
705 m_lineHeight = 0;
706
707 return TRUE;
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{
cf1dfa6b
VZ
940 wxCHECK_MSG( m_rect, FALSE, _T("can't be called in this mode") );
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
b54e41c5 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
1441 return TRUE;
1442 }
1443
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{
b5d43d1d 1611 wxCHECK_MSG( !IsVirtual(), FALSE, _T("unexpected call to Highlight") );
c801d85f 1612
b54e41c5 1613 if ( on == m_highlighted )
cf1dfa6b 1614 return FALSE;
c801d85f 1615
b54e41c5 1616 m_highlighted = on;
c801d85f 1617
cf1dfa6b 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;
cfb50f14 1641 m_isDragging = FALSE;
0a816d95
VZ
1642 m_dirty = FALSE;
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
RD
1667#if _USE_VISATTR
1668 wxVisualAttributes attr = wxPanel::GetClassDefaultAttributes();
1669 SetDefaultForegroundColour( attr.colFg );
1670 SetDefaultBackgroundColour( attr.colBg );
1671 SetDefaultFont( attr.font );
1672#else
1673 SetDefaultForegroundColour( wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT));
1674 SetDefaultBackgroundColour( wxSystemSettings::GetColour(wxSYS_COLOUR_BTNFACE));
1675 SetDefaultFont( wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT ));
1676#endif
e1e955e1 1677}
c801d85f 1678
0a816d95 1679wxListHeaderWindow::~wxListHeaderWindow()
a367b9b3 1680{
63852e78 1681 delete m_resizeCursor;
a367b9b3
JS
1682}
1683
2b5f62a0
VZ
1684#ifdef __WXUNIVERSAL__
1685#include "wx/univ/renderer.h"
1686#include "wx/univ/theme.h"
1687#endif
1688
f6bcfd97
BP
1689// shift the DC origin to match the position of the main window horz
1690// scrollbar: this allows us to always use logical coords
1691void wxListHeaderWindow::AdjustDC(wxDC& dc)
1692{
f6bcfd97
BP
1693 int xpix;
1694 m_owner->GetScrollPixelsPerUnit( &xpix, NULL );
1695
1696 int x;
1697 m_owner->GetViewStart( &x, NULL );
1698
1699 // account for the horz scrollbar offset
1700 dc.SetDeviceOrigin( -x * xpix, 0 );
f6bcfd97
BP
1701}
1702
c801d85f
KB
1703void wxListHeaderWindow::OnPaint( wxPaintEvent &WXUNUSED(event) )
1704{
63852e78 1705 wxPaintDC dc( this );
10bd0724 1706
63852e78 1707 PrepareDC( dc );
f6bcfd97 1708 AdjustDC( dc );
bffa1c77 1709
63852e78 1710 dc.BeginDrawing();
bd8289c1 1711
63852e78 1712 dc.SetFont( GetFont() );
bd8289c1 1713
f6bcfd97
BP
1714 // width and height of the entire header window
1715 int w, h;
63852e78 1716 GetClientSize( &w, &h );
f6bcfd97 1717 m_owner->CalcUnscrolledPosition(w, 0, &w, NULL);
c801d85f 1718
f60d0f94 1719 dc.SetBackgroundMode(wxTRANSPARENT);
70846f0a 1720
35d4c967
RD
1721 dc.SetTextForeground(GetForegroundColour());
1722
cf1dfa6b 1723 int x = HEADER_OFFSET_X;
c801d85f 1724
63852e78
RR
1725 int numColumns = m_owner->GetColumnCount();
1726 wxListItem item;
c5b7bb59 1727 for ( int i = 0; i < numColumns && x < w; i++ )
63852e78
RR
1728 {
1729 m_owner->GetColumn( i, item );
f6bcfd97 1730 int wCol = item.m_width;
f6bcfd97 1731
0a816d95
VZ
1732 // the width of the rect to draw: make it smaller to fit entirely
1733 // inside the column rect
1734 int cw = wCol - 2;
f6bcfd97 1735
9c7f49f5
VZ
1736 wxRendererNative::Get().DrawHeaderButton
1737 (
1738 this,
1739 dc,
1740 wxRect(x, HEADER_OFFSET_Y, cw, h - 2),
1741 m_parent->IsEnabled() ? 0
1742 : wxCONTROL_DISABLED
1743 );
0a816d95 1744
e1e1272f
VZ
1745 // see if we have enough space for the column label
1746
1747 // for this we need the width of the text
1748 wxCoord wLabel;
cabeffb0
RR
1749 wxCoord hLabel;
1750 dc.GetTextExtent(item.GetText(), &wLabel, &hLabel);
e1e1272f
VZ
1751 wLabel += 2*EXTRA_WIDTH;
1752
1753 // and the width of the icon, if any
1754 static const int MARGIN_BETWEEN_TEXT_AND_ICON = 2;
73795999
VZ
1755 int ix = 0, // init them just to suppress the compiler warnings
1756 iy = 0;
e1e1272f
VZ
1757 const int image = item.m_image;
1758 wxImageListType *imageList;
0a816d95
VZ
1759 if ( image != -1 )
1760 {
e1e1272f 1761 imageList = m_owner->m_small_image_list;
0a816d95
VZ
1762 if ( imageList )
1763 {
0a816d95 1764 imageList->GetSize(image, ix, iy);
e1e1272f
VZ
1765 wLabel += ix + MARGIN_BETWEEN_TEXT_AND_ICON;
1766 }
1767 }
1768 else
1769 {
1770 imageList = NULL;
1771 }
1772
1773 // ignore alignment if there is not enough space anyhow
1774 int xAligned;
1775 switch ( wLabel < cw ? item.GetAlign() : wxLIST_FORMAT_LEFT )
1776 {
1777 default:
1778 wxFAIL_MSG( _T("unknown list item format") );
1779 // fall through
0a816d95 1780
e1e1272f
VZ
1781 case wxLIST_FORMAT_LEFT:
1782 xAligned = x;
1783 break;
0a816d95 1784
e1e1272f
VZ
1785 case wxLIST_FORMAT_RIGHT:
1786 xAligned = x + cw - wLabel;
1787 break;
1788
1789 case wxLIST_FORMAT_CENTER:
1790 xAligned = x + (cw - wLabel) / 2;
1791 break;
1792 }
1793
1794
1795 // if we have an image, draw it on the right of the label
1796 if ( imageList )
1797 {
1798 imageList->Draw
1799 (
1800 image,
1801 dc,
1802 xAligned + wLabel - ix - MARGIN_BETWEEN_TEXT_AND_ICON,
1803 HEADER_OFFSET_Y + (h - 4 - iy)/2,
1804 wxIMAGELIST_DRAW_TRANSPARENT
1805 );
1806
1807 cw -= ix + MARGIN_BETWEEN_TEXT_AND_ICON;
0a816d95
VZ
1808 }
1809
1810 // draw the text clipping it so that it doesn't overwrite the column
1811 // boundary
1812 wxDCClipper clipper(dc, x, HEADER_OFFSET_Y, cw, h - 4 );
06b781c7
VZ
1813
1814 dc.DrawText( item.GetText(),
cabeffb0 1815 xAligned + EXTRA_WIDTH, h / 2 - hLabel / 2 ); //HEADER_OFFSET_Y + EXTRA_HEIGHT );
06b781c7 1816
0a816d95 1817 x += wCol;
63852e78 1818 }
c5b7bb59 1819
63852e78 1820 dc.EndDrawing();
e1e955e1 1821}
c801d85f 1822
0208334d
RR
1823void wxListHeaderWindow::DrawCurrent()
1824{
63852e78
RR
1825 int x1 = m_currentX;
1826 int y1 = 0;
f16ba4e6 1827 m_owner->ClientToScreen( &x1, &y1 );
f6bcfd97 1828
f16ba4e6 1829 int x2 = m_currentX;
63852e78 1830 int y2 = 0;
f6bcfd97 1831 m_owner->GetClientSize( NULL, &y2 );
63852e78 1832 m_owner->ClientToScreen( &x2, &y2 );
0208334d 1833
63852e78 1834 wxScreenDC dc;
3c679789 1835 dc.SetLogicalFunction( wxINVERT );
63852e78
RR
1836 dc.SetPen( wxPen( *wxBLACK, 2, wxSOLID ) );
1837 dc.SetBrush( *wxTRANSPARENT_BRUSH );
0208334d 1838
f6bcfd97
BP
1839 AdjustDC(dc);
1840
63852e78 1841 dc.DrawLine( x1, y1, x2, y2 );
0208334d 1842
63852e78 1843 dc.SetLogicalFunction( wxCOPY );
0208334d 1844
63852e78
RR
1845 dc.SetPen( wxNullPen );
1846 dc.SetBrush( wxNullBrush );
0208334d
RR
1847}
1848
c801d85f
KB
1849void wxListHeaderWindow::OnMouse( wxMouseEvent &event )
1850{
f6bcfd97 1851 // we want to work with logical coords
3ca6a5f0
BP
1852 int x;
1853 m_owner->CalcUnscrolledPosition(event.GetX(), 0, &x, NULL);
3ca6a5f0 1854 int y = event.GetY();
f6bcfd97 1855
cfb50f14 1856 if (m_isDragging)
0208334d 1857 {
355f2407 1858 SendListEvent(wxEVT_COMMAND_LIST_COL_DRAGGING, event.GetPosition());
a77ec46d 1859
f6bcfd97
BP
1860 // we don't draw the line beyond our window, but we allow dragging it
1861 // there
1862 int w = 0;
1863 GetClientSize( &w, NULL );
f6bcfd97 1864 m_owner->CalcUnscrolledPosition(w, 0, &w, NULL);
f6bcfd97
BP
1865 w -= 6;
1866
1867 // erase the line if it was drawn
1868 if ( m_currentX < w )
1869 DrawCurrent();
1870
63852e78
RR
1871 if (event.ButtonUp())
1872 {
1873 ReleaseMouse();
cfb50f14 1874 m_isDragging = FALSE;
f6bcfd97
BP
1875 m_dirty = TRUE;
1876 m_owner->SetColumnWidth( m_column, m_currentX - m_minX );
355f2407 1877 SendListEvent(wxEVT_COMMAND_LIST_COL_END_DRAG, event.GetPosition());
63852e78
RR
1878 }
1879 else
1880 {
f6bcfd97 1881 if (x > m_minX + 7)
63852e78
RR
1882 m_currentX = x;
1883 else
f6bcfd97 1884 m_currentX = m_minX + 7;
bd8289c1 1885
f6bcfd97
BP
1886 // draw in the new location
1887 if ( m_currentX < w )
1888 DrawCurrent();
bffa1c77 1889 }
0208334d 1890 }
f6bcfd97 1891 else // not dragging
c801d85f 1892 {
f6bcfd97
BP
1893 m_minX = 0;
1894 bool hit_border = FALSE;
1895
1896 // end of the current column
1897 int xpos = 0;
1898
1899 // find the column where this event occured
62313c27
VZ
1900 int col,
1901 countCol = m_owner->GetColumnCount();
1902 for (col = 0; col < countCol; col++)
bffa1c77 1903 {
cf1dfa6b
VZ
1904 xpos += m_owner->GetColumnWidth( col );
1905 m_column = col;
f6bcfd97
BP
1906
1907 if ( (abs(x-xpos) < 3) && (y < 22) )
1908 {
1909 // near the column border
1910 hit_border = TRUE;
1911 break;
1912 }
1913
1914 if ( x < xpos )
1915 {
1916 // inside the column
1917 break;
1918 }
1919
1920 m_minX = xpos;
bffa1c77 1921 }
63852e78 1922
62313c27
VZ
1923 if ( col == countCol )
1924 m_column = -1;
1925
11358d39 1926 if (event.LeftDown() || event.RightUp())
63852e78 1927 {
11358d39 1928 if (hit_border && event.LeftDown())
f6bcfd97 1929 {
355f2407
VZ
1930 if ( SendListEvent(wxEVT_COMMAND_LIST_COL_BEGIN_DRAG,
1931 event.GetPosition()) )
1932 {
1933 m_isDragging = TRUE;
1934 m_currentX = x;
355f2407 1935 CaptureMouse();
03eccb83 1936 DrawCurrent();
355f2407
VZ
1937 }
1938 //else: column resizing was vetoed by the user code
f6bcfd97 1939 }
11358d39 1940 else // click on a column
f6bcfd97 1941 {
a77ec46d 1942 SendListEvent( event.LeftDown()
11358d39
VZ
1943 ? wxEVT_COMMAND_LIST_COL_CLICK
1944 : wxEVT_COMMAND_LIST_COL_RIGHT_CLICK,
a77ec46d 1945 event.GetPosition());
f6bcfd97 1946 }
63852e78 1947 }
f6bcfd97 1948 else if (event.Moving())
63852e78 1949 {
f6bcfd97
BP
1950 bool setCursor;
1951 if (hit_border)
1952 {
1953 setCursor = m_currentCursor == wxSTANDARD_CURSOR;
1954 m_currentCursor = m_resizeCursor;
1955 }
1956 else
1957 {
1958 setCursor = m_currentCursor != wxSTANDARD_CURSOR;
1959 m_currentCursor = wxSTANDARD_CURSOR;
1960 }
1961
1962 if ( setCursor )
1963 SetCursor(*m_currentCursor);
63852e78 1964 }
e1e955e1 1965 }
e1e955e1 1966}
c801d85f
KB
1967
1968void wxListHeaderWindow::OnSetFocus( wxFocusEvent &WXUNUSED(event) )
1969{
63852e78 1970 m_owner->SetFocus();
03eccb83 1971 m_owner->Update();
e1e955e1 1972}
c801d85f 1973
355f2407 1974bool wxListHeaderWindow::SendListEvent(wxEventType type, wxPoint pos)
a77ec46d
RD
1975{
1976 wxWindow *parent = GetParent();
1977 wxListEvent le( type, parent->GetId() );
1978 le.SetEventObject( parent );
1979 le.m_pointDrag = pos;
1980
1981 // the position should be relative to the parent window, not
1982 // this one for compatibility with MSW and common sense: the
1983 // user code doesn't know anything at all about this header
1984 // window, so why should it get positions relative to it?
1985 le.m_pointDrag.y -= GetSize().y;
1986
1987 le.m_col = m_column;
355f2407 1988 return !parent->GetEventHandler()->ProcessEvent( le ) || le.IsAllowed();
a77ec46d
RD
1989}
1990
c801d85f
KB
1991//-----------------------------------------------------------------------------
1992// wxListRenameTimer (internal)
1993//-----------------------------------------------------------------------------
1994
bd8289c1
VZ
1995wxListRenameTimer::wxListRenameTimer( wxListMainWindow *owner )
1996{
63852e78 1997 m_owner = owner;
e1e955e1 1998}
c801d85f 1999
bd8289c1
VZ
2000void wxListRenameTimer::Notify()
2001{
63852e78 2002 m_owner->OnRenameTimer();
e1e955e1 2003}
c801d85f 2004
ee7ee469
RR
2005//-----------------------------------------------------------------------------
2006// wxListTextCtrl (internal)
2007//-----------------------------------------------------------------------------
2008
ee7ee469 2009BEGIN_EVENT_TABLE(wxListTextCtrl,wxTextCtrl)
63852e78 2010 EVT_CHAR (wxListTextCtrl::OnChar)
2c1f73ee 2011 EVT_KEY_UP (wxListTextCtrl::OnKeyUp)
63852e78 2012 EVT_KILL_FOCUS (wxListTextCtrl::OnKillFocus)
ee7ee469
RR
2013END_EVENT_TABLE()
2014
62d89eb4
VZ
2015wxListTextCtrl::wxListTextCtrl(wxListMainWindow *owner, size_t itemEdit)
2016 : m_startValue(owner->GetItemText(itemEdit)),
2017 m_itemEdited(itemEdit)
2018{
63852e78 2019 m_owner = owner;
dd5a32cc 2020 m_finished = FALSE;
62d89eb4
VZ
2021
2022 wxRect rectLabel = owner->GetLineLabelRect(itemEdit);
2023
2024 m_owner->CalcScrolledPosition(rectLabel.x, rectLabel.y,
2025 &rectLabel.x, &rectLabel.y);
2026
2027 (void)Create(owner, wxID_ANY, m_startValue,
2028 wxPoint(rectLabel.x-4,rectLabel.y-4),
2029 wxSize(rectLabel.width+11,rectLabel.height+8));
ee7ee469
RR
2030}
2031
62d89eb4 2032void wxListTextCtrl::Finish()
ee7ee469 2033{
62d89eb4 2034 if ( !m_finished )
63852e78 2035 {
62d89eb4 2036 wxPendingDelete.Append(this);
f6bcfd97 2037
dd5a32cc 2038 m_finished = TRUE;
62d89eb4 2039
a6d57d03 2040 m_owner->SetFocus();
62d89eb4
VZ
2041 }
2042}
dd5a32cc 2043
62d89eb4
VZ
2044bool wxListTextCtrl::AcceptChanges()
2045{
2046 const wxString value = GetValue();
2047
2048 if ( value == m_startValue )
2049 {
2050 // nothing changed, always accept
2051 return TRUE;
63852e78 2052 }
62d89eb4
VZ
2053
2054 if ( !m_owner->OnRenameAccept(m_itemEdited, value) )
63852e78 2055 {
62d89eb4
VZ
2056 // vetoed by the user
2057 return FALSE;
2058 }
f6bcfd97 2059
62d89eb4
VZ
2060 // accepted, do rename the item
2061 m_owner->SetItemText(m_itemEdited, value);
f6bcfd97 2062
62d89eb4
VZ
2063 return TRUE;
2064}
dd5a32cc 2065
62d89eb4
VZ
2066void wxListTextCtrl::OnChar( wxKeyEvent &event )
2067{
2068 switch ( event.m_keyCode )
2069 {
2070 case WXK_RETURN:
2071 if ( !AcceptChanges() )
2072 {
2073 // vetoed by the user code
2074 break;
2075 }
2076 //else: fall through
f6bcfd97 2077
62d89eb4
VZ
2078 case WXK_ESCAPE:
2079 Finish();
86586459 2080 m_owner->OnRenameCancelled( m_itemEdited );
62d89eb4
VZ
2081 break;
2082
2083 default:
2084 event.Skip();
2085 }
63852e78
RR
2086}
2087
c13cace1
VS
2088void wxListTextCtrl::OnKeyUp( wxKeyEvent &event )
2089{
dd5a32cc
RR
2090 if (m_finished)
2091 {
2092 event.Skip();
2093 return;
2094 }
2095
c13cace1
VS
2096 // auto-grow the textctrl:
2097 wxSize parentSize = m_owner->GetSize();
2098 wxPoint myPos = GetPosition();
2099 wxSize mySize = GetSize();
2100 int sx, sy;
a6d57d03 2101 GetTextExtent(GetValue() + _T("MM"), &sx, &sy);
cf1dfa6b
VZ
2102 if (myPos.x + sx > parentSize.x)
2103 sx = parentSize.x - myPos.x;
2104 if (mySize.x > sx)
2105 sx = mySize.x;
c13cace1 2106 SetSize(sx, -1);
2c1f73ee 2107
c13cace1
VS
2108 event.Skip();
2109}
2110
dd5a32cc 2111void wxListTextCtrl::OnKillFocus( wxFocusEvent &event )
63852e78 2112{
62d89eb4 2113 if ( !m_finished )
dd5a32cc 2114 {
86586459 2115 // We must finish regardless of success, otherwise we'll get focus problems
62d89eb4 2116 Finish();
86351e4a 2117
86586459
RR
2118 if ( !AcceptChanges() )
2119 m_owner->OnRenameCancelled( m_itemEdited );
62d89eb4 2120 }
86351e4a 2121
62d89eb4 2122 event.Skip();
ee7ee469
RR
2123}
2124
c801d85f
KB
2125//-----------------------------------------------------------------------------
2126// wxListMainWindow
2127//-----------------------------------------------------------------------------
2128
5a1cad6e 2129IMPLEMENT_DYNAMIC_CLASS(wxListMainWindow,wxScrolledWindow)
bd8289c1 2130
c801d85f
KB
2131BEGIN_EVENT_TABLE(wxListMainWindow,wxScrolledWindow)
2132 EVT_PAINT (wxListMainWindow::OnPaint)
c801d85f
KB
2133 EVT_MOUSE_EVENTS (wxListMainWindow::OnMouse)
2134 EVT_CHAR (wxListMainWindow::OnChar)
3dfb93fd 2135 EVT_KEY_DOWN (wxListMainWindow::OnKeyDown)
c801d85f
KB
2136 EVT_SET_FOCUS (wxListMainWindow::OnSetFocus)
2137 EVT_KILL_FOCUS (wxListMainWindow::OnKillFocus)
2fa7c206 2138 EVT_SCROLLWIN (wxListMainWindow::OnScroll)
c801d85f
KB
2139END_EVENT_TABLE()
2140
1370703e 2141void wxListMainWindow::Init()
c801d85f 2142{
139adb6a 2143 m_dirty = TRUE;
cf1dfa6b
VZ
2144 m_countVirt = 0;
2145 m_lineFrom =
b54e41c5 2146 m_lineTo = (size_t)-1;
cf1dfa6b
VZ
2147 m_linesPerPage = 0;
2148
2149 m_headerWidth =
2150 m_lineHeight = 0;
1370703e 2151
80020b62
JS
2152 m_small_image_list = (wxImageListType *) NULL;
2153 m_normal_image_list = (wxImageListType *) NULL;
1370703e 2154
139adb6a
RR
2155 m_small_spacing = 30;
2156 m_normal_spacing = 40;
1370703e 2157
139adb6a 2158 m_hasFocus = FALSE;
1370703e
VZ
2159 m_dragCount = 0;
2160 m_isCreated = FALSE;
2161
139adb6a
RR
2162 m_lastOnSame = FALSE;
2163 m_renameTimer = new wxListRenameTimer( this );
1370703e 2164
cf1dfa6b 2165 m_current =
efbb7287 2166 m_lineLastClicked =
1370703e 2167 m_lineBeforeLastClicked = (size_t)-1;
c5c528fc
VZ
2168
2169 m_freezeCount = 0;
e1e955e1 2170}
c801d85f 2171
1370703e 2172wxListMainWindow::wxListMainWindow()
c801d85f 2173{
1370703e
VZ
2174 Init();
2175
49ecb029
VZ
2176 m_highlightBrush =
2177 m_highlightUnfocusedBrush = (wxBrush *) NULL;
1370703e
VZ
2178}
2179
2180wxListMainWindow::wxListMainWindow( wxWindow *parent,
2181 wxWindowID id,
2182 const wxPoint& pos,
2183 const wxSize& size,
2184 long style,
2185 const wxString &name )
2186 : wxScrolledWindow( parent, id, pos, size,
2187 style | wxHSCROLL | wxVSCROLL, name )
2188{
2189 Init();
2190
49ecb029
VZ
2191 m_highlightBrush = new wxBrush
2192 (
a756f210 2193 wxSystemSettings::GetColour
49ecb029
VZ
2194 (
2195 wxSYS_COLOUR_HIGHLIGHT
2196 ),
2197 wxSOLID
2198 );
2199
2200 m_highlightUnfocusedBrush = new wxBrush
2201 (
a756f210 2202 wxSystemSettings::GetColour
49ecb029
VZ
2203 (
2204 wxSYS_COLOUR_BTNSHADOW
2205 ),
2206 wxSOLID
2207 );
2208
139adb6a
RR
2209 wxSize sz = size;
2210 sz.y = 25;
bd8289c1 2211
6d78bbe6 2212 SetScrollbars( 0, 0, 0, 0, 0, 0 );
bd8289c1 2213
35d4c967
RD
2214 wxVisualAttributes attr = wxGenericListCtrl::GetClassDefaultAttributes();
2215 SetDefaultForegroundColour( attr.colFg );
2216 SetDefaultBackgroundColour( attr.colBg );
2217 SetDefaultFont( attr.font );
e1e955e1 2218}
c801d85f 2219
fd9811b1 2220wxListMainWindow::~wxListMainWindow()
c801d85f 2221{
5fe143df 2222 DoDeleteAllItems();
222ed1d6 2223 WX_CLEAR_LIST(wxListHeaderDataList, m_columns);
12c1b46a 2224
b54e41c5 2225 delete m_highlightBrush;
49ecb029 2226 delete m_highlightUnfocusedBrush;
004fd0c8 2227
139adb6a 2228 delete m_renameTimer;
e1e955e1 2229}
c801d85f 2230
cf1dfa6b 2231void wxListMainWindow::CacheLineData(size_t line)
c801d85f 2232{
3cd94a0d 2233 wxGenericListCtrl *listctrl = GetListCtrl();
25e3a937 2234
b54e41c5 2235 wxListLineData *ld = GetDummyLine();
f6bcfd97 2236
cf1dfa6b
VZ
2237 size_t countCol = GetColumnCount();
2238 for ( size_t col = 0; col < countCol; col++ )
2239 {
2240 ld->SetText(col, listctrl->OnGetItemText(line, col));
2241 }
2242
5cd89174 2243 ld->SetImage(listctrl->OnGetItemImage(line));
6c02c329 2244 ld->SetAttr(listctrl->OnGetItemAttr(line));
e1e955e1 2245}
c801d85f 2246
b54e41c5 2247wxListLineData *wxListMainWindow::GetDummyLine() const
c801d85f 2248{
cf1dfa6b 2249 wxASSERT_MSG( !IsEmpty(), _T("invalid line index") );
2c1f73ee 2250
904ccf52
VZ
2251 wxASSERT_MSG( IsVirtual(), _T("GetDummyLine() shouldn't be called") );
2252
2253 wxListMainWindow *self = wxConstCast(this, wxListMainWindow);
2254
2255 // we need to recreate the dummy line if the number of columns in the
2256 // control changed as it would have the incorrect number of fields
2257 // otherwise
2258 if ( !m_lines.IsEmpty() &&
2259 m_lines[0].m_items.GetCount() != (size_t)GetColumnCount() )
2c1f73ee 2260 {
904ccf52
VZ
2261 self->m_lines.Clear();
2262 }
cf1dfa6b 2263
904ccf52
VZ
2264 if ( m_lines.IsEmpty() )
2265 {
5cd89174 2266 wxListLineData *line = new wxListLineData(self);
cf1dfa6b 2267 self->m_lines.Add(line);
904ccf52
VZ
2268
2269 // don't waste extra memory -- there never going to be anything
2270 // else/more in this array
2271 self->m_lines.Shrink();
2c1f73ee
VZ
2272 }
2273
cf1dfa6b
VZ
2274 return &m_lines[0];
2275}
2276
5cd89174
VZ
2277// ----------------------------------------------------------------------------
2278// line geometry (report mode only)
2279// ----------------------------------------------------------------------------
2280
cf1dfa6b
VZ
2281wxCoord wxListMainWindow::GetLineHeight() const
2282{
cf1dfa6b
VZ
2283 // we cache the line height as calling GetTextExtent() is slow
2284 if ( !m_lineHeight )
2c1f73ee 2285 {
cf1dfa6b 2286 wxListMainWindow *self = wxConstCast(this, wxListMainWindow);
bd8289c1 2287
cf1dfa6b
VZ
2288 wxClientDC dc( self );
2289 dc.SetFont( GetFont() );
c801d85f 2290
cf1dfa6b
VZ
2291 wxCoord y;
2292 dc.GetTextExtent(_T("H"), NULL, &y);
004fd0c8 2293
ca7353de
RD
2294 if ( m_small_image_list && m_small_image_list->GetImageCount() )
2295 {
2296 int iw = 0;
2297 int ih = 0;
2298 m_small_image_list->GetSize(0, iw, ih);
2299 y = wxMax(y, ih);
2300 }
2301
2302 y += EXTRA_HEIGHT;
cf1dfa6b
VZ
2303 self->m_lineHeight = y + LINE_SPACING;
2304 }
bffa1c77 2305
cf1dfa6b
VZ
2306 return m_lineHeight;
2307}
bffa1c77 2308
cf1dfa6b
VZ
2309wxCoord wxListMainWindow::GetLineY(size_t line) const
2310{
b5d43d1d 2311 wxASSERT_MSG( InReportView(), _T("only works in report mode") );
1370703e 2312
cf1dfa6b
VZ
2313 return LINE_SPACING + line*GetLineHeight();
2314}
206b0a67 2315
5cd89174
VZ
2316wxRect wxListMainWindow::GetLineRect(size_t line) const
2317{
2318 if ( !InReportView() )
2319 return GetLine(line)->m_gi->m_rectAll;
2320
2321 wxRect rect;
2322 rect.x = HEADER_OFFSET_X;
2323 rect.y = GetLineY(line);
2324 rect.width = GetHeaderWidth();
2325 rect.height = GetLineHeight();
2326
2327 return rect;
2328}
2329
2330wxRect wxListMainWindow::GetLineLabelRect(size_t line) const
2331{
2332 if ( !InReportView() )
2333 return GetLine(line)->m_gi->m_rectLabel;
2334
2335 wxRect rect;
2336 rect.x = HEADER_OFFSET_X;
2337 rect.y = GetLineY(line);
2338 rect.width = GetColumnWidth(0);
2339 rect.height = GetLineHeight();
2340
2341 return rect;
2342}
2343
2344wxRect wxListMainWindow::GetLineIconRect(size_t line) const
2345{
2346 if ( !InReportView() )
2347 return GetLine(line)->m_gi->m_rectIcon;
2348
2349 wxListLineData *ld = GetLine(line);
2350 wxASSERT_MSG( ld->HasImage(), _T("should have an image") );
2351
2352 wxRect rect;
2353 rect.x = HEADER_OFFSET_X;
2354 rect.y = GetLineY(line);
2355 GetImageSize(ld->GetImage(), rect.width, rect.height);
2356
2357 return rect;
2358}
2359
2360wxRect wxListMainWindow::GetLineHighlightRect(size_t line) const
2361{
2362 return InReportView() ? GetLineRect(line)
2363 : GetLine(line)->m_gi->m_rectHighlight;
2364}
2365
2366long wxListMainWindow::HitTestLine(size_t line, int x, int y) const
2367{
fc4f1d5f
VZ
2368 wxASSERT_MSG( line < GetItemCount(), _T("invalid line in HitTestLine") );
2369
5cd89174
VZ
2370 wxListLineData *ld = GetLine(line);
2371
2372 if ( ld->HasImage() && GetLineIconRect(line).Inside(x, y) )
2373 return wxLIST_HITTEST_ONITEMICON;
2374
acf4d858
VS
2375 // VS: Testing for "ld->HasText() || InReportView()" instead of
2376 // "ld->HasText()" is needed to make empty lines in report view
2377 // possible
2378 if ( ld->HasText() || InReportView() )
5cd89174
VZ
2379 {
2380 wxRect rect = InReportView() ? GetLineRect(line)
2381 : GetLineLabelRect(line);
2382
2383 if ( rect.Inside(x, y) )
2384 return wxLIST_HITTEST_ONITEMLABEL;
2385 }
2386
2387 return 0;
2388}
2389
2390// ----------------------------------------------------------------------------
2391// highlight (selection) handling
2392// ----------------------------------------------------------------------------
2393
b54e41c5 2394bool wxListMainWindow::IsHighlighted(size_t line) const
cf1dfa6b
VZ
2395{
2396 if ( IsVirtual() )
2397 {
b54e41c5 2398 return m_selStore.IsSelected(line);
cf1dfa6b
VZ
2399 }
2400 else // !virtual
2401 {
2402 wxListLineData *ld = GetLine(line);
b54e41c5 2403 wxCHECK_MSG( ld, FALSE, _T("invalid index in IsHighlighted") );
cf1dfa6b 2404
b54e41c5 2405 return ld->IsHighlighted();
cf1dfa6b
VZ
2406 }
2407}
2408
68a9ef0e
VZ
2409void wxListMainWindow::HighlightLines( size_t lineFrom,
2410 size_t lineTo,
2411 bool highlight )
cf1dfa6b 2412{
cf1dfa6b
VZ
2413 if ( IsVirtual() )
2414 {
68a9ef0e
VZ
2415 wxArrayInt linesChanged;
2416 if ( !m_selStore.SelectRange(lineFrom, lineTo, highlight,
2417 &linesChanged) )
2418 {
2419 // meny items changed state, refresh everything
2420 RefreshLines(lineFrom, lineTo);
2421 }
2422 else // only a few items changed state, refresh only them
2423 {
2424 size_t count = linesChanged.GetCount();
2425 for ( size_t n = 0; n < count; n++ )
2426 {
2427 RefreshLine(linesChanged[n]);
2428 }
2429 }
b54e41c5 2430 }
68a9ef0e 2431 else // iterate over all items in non report view
b54e41c5 2432 {
b54e41c5 2433 for ( size_t line = lineFrom; line <= lineTo; line++ )
cf1dfa6b 2434 {
b54e41c5 2435 if ( HighlightLine(line, highlight) )
68a9ef0e
VZ
2436 {
2437 RefreshLine(line);
2438 }
cf1dfa6b 2439 }
b54e41c5
VZ
2440 }
2441}
2442
2443bool wxListMainWindow::HighlightLine( size_t line, bool highlight )
2444{
2445 bool changed;
2446
2447 if ( IsVirtual() )
2448 {
2449 changed = m_selStore.SelectItem(line, highlight);
cf1dfa6b
VZ
2450 }
2451 else // !virtual
2452 {
2453 wxListLineData *ld = GetLine(line);
49ecb029 2454 wxCHECK_MSG( ld, FALSE, _T("invalid index in HighlightLine") );
cf1dfa6b 2455
b54e41c5 2456 changed = ld->Highlight(highlight);
cf1dfa6b
VZ
2457 }
2458
2459 if ( changed )
2460 {
b54e41c5 2461 SendNotify( line, highlight ? wxEVT_COMMAND_LIST_ITEM_SELECTED
5cd89174 2462 : wxEVT_COMMAND_LIST_ITEM_DESELECTED );
cf1dfa6b
VZ
2463 }
2464
2465 return changed;
2466}
2467
2468void wxListMainWindow::RefreshLine( size_t line )
2469{
b5d43d1d 2470 if ( InReportView() )
6ea1323a
VZ
2471 {
2472 size_t visibleFrom, visibleTo;
2473 GetVisibleLinesRange(&visibleFrom, &visibleTo);
c1c4c551 2474
6ea1323a
VZ
2475 if ( line < visibleFrom || line > visibleTo )
2476 return;
2477 }
c1c4c551 2478
5cd89174 2479 wxRect rect = GetLineRect(line);
cf1dfa6b
VZ
2480
2481 CalcScrolledPosition( rect.x, rect.y, &rect.x, &rect.y );
2482 RefreshRect( rect );
2483}
2484
2485void wxListMainWindow::RefreshLines( size_t lineFrom, size_t lineTo )
2486{
2487 // we suppose that they are ordered by caller
2488 wxASSERT_MSG( lineFrom <= lineTo, _T("indices in disorder") );
2489
6b4a8d93
VZ
2490 wxASSERT_MSG( lineTo < GetItemCount(), _T("invalid line range") );
2491
b5d43d1d 2492 if ( InReportView() )
cf1dfa6b 2493 {
b54e41c5
VZ
2494 size_t visibleFrom, visibleTo;
2495 GetVisibleLinesRange(&visibleFrom, &visibleTo);
2496
2497 if ( lineFrom < visibleFrom )
2498 lineFrom = visibleFrom;
2499 if ( lineTo > visibleTo )
2500 lineTo = visibleTo;
cf1dfa6b
VZ
2501
2502 wxRect rect;
2503 rect.x = 0;
2504 rect.y = GetLineY(lineFrom);
2505 rect.width = GetClientSize().x;
91c6cc0e 2506 rect.height = GetLineY(lineTo) - rect.y + GetLineHeight();
cf1dfa6b
VZ
2507
2508 CalcScrolledPosition( rect.x, rect.y, &rect.x, &rect.y );
2509 RefreshRect( rect );
2510 }
2511 else // !report
2512 {
2513 // TODO: this should be optimized...
2514 for ( size_t line = lineFrom; line <= lineTo; line++ )
2515 {
2516 RefreshLine(line);
2517 }
2518 }
2519}
2520
6b4a8d93
VZ
2521void wxListMainWindow::RefreshAfter( size_t lineFrom )
2522{
b5d43d1d 2523 if ( InReportView() )
6b4a8d93 2524 {
c29582d0
JS
2525 size_t visibleFrom, visibleTo;
2526 GetVisibleLinesRange(&visibleFrom, &visibleTo);
6b4a8d93
VZ
2527
2528 if ( lineFrom < visibleFrom )
2529 lineFrom = visibleFrom;
c29582d0
JS
2530 else if ( lineFrom > visibleTo )
2531 return;
6b4a8d93
VZ
2532
2533 wxRect rect;
2534 rect.x = 0;
2535 rect.y = GetLineY(lineFrom);
c29582d0 2536 CalcScrolledPosition( rect.x, rect.y, &rect.x, &rect.y );
6b4a8d93
VZ
2537
2538 wxSize size = GetClientSize();
2539 rect.width = size.x;
2540 // refresh till the bottom of the window
2541 rect.height = size.y - rect.y;
2542
6b4a8d93 2543 RefreshRect( rect );
6b4a8d93
VZ
2544 }
2545 else // !report
2546 {
2547 // TODO: how to do it more efficiently?
2548 m_dirty = TRUE;
2549 }
2550}
2551
49ecb029
VZ
2552void wxListMainWindow::RefreshSelected()
2553{
2554 if ( IsEmpty() )
2555 return;
2556
2557 size_t from, to;
2558 if ( InReportView() )
2559 {
2560 GetVisibleLinesRange(&from, &to);
2561 }
2562 else // !virtual
2563 {
2564 from = 0;
2565 to = GetItemCount() - 1;
2566 }
2567
cf30ae13 2568 if ( HasCurrent() && m_current >= from && m_current <= to )
49ecb029
VZ
2569 {
2570 RefreshLine(m_current);
2571 }
2572
2573 for ( size_t line = from; line <= to; line++ )
2574 {
2575 // NB: the test works as expected even if m_current == -1
2576 if ( line != m_current && IsHighlighted(line) )
2577 {
2578 RefreshLine(line);
2579 }
2580 }
2581}
2582
c5c528fc
VZ
2583void wxListMainWindow::Freeze()
2584{
2585 m_freezeCount++;
2586}
2587
2588void wxListMainWindow::Thaw()
2589{
2590 wxCHECK_RET( m_freezeCount > 0, _T("thawing unfrozen list control?") );
2591
2592 if ( !--m_freezeCount )
2593 {
2594 Refresh();
2595 }
2596}
2597
cf1dfa6b
VZ
2598void wxListMainWindow::OnPaint( wxPaintEvent &WXUNUSED(event) )
2599{
2600 // Note: a wxPaintDC must be constructed even if no drawing is
2601 // done (a Windows requirement).
2602 wxPaintDC dc( this );
2603
c5c528fc 2604 if ( IsEmpty() || m_freezeCount )
cf1dfa6b 2605 {
c5c528fc 2606 // nothing to draw or not the moment to draw it
cf1dfa6b
VZ
2607 return;
2608 }
2609
1e4d446b
VZ
2610 if ( m_dirty )
2611 {
2612 // delay the repainting until we calculate all the items positions
2613 return;
2614 }
2615
cf1dfa6b
VZ
2616 PrepareDC( dc );
2617
2618 int dev_x, dev_y;
2619 CalcScrolledPosition( 0, 0, &dev_x, &dev_y );
2620
2621 dc.BeginDrawing();
2622
2623 dc.SetFont( GetFont() );
2624
b5d43d1d 2625 if ( InReportView() )
cf1dfa6b 2626 {
b54e41c5 2627 int lineHeight = GetLineHeight();
cf1dfa6b 2628
b54e41c5
VZ
2629 size_t visibleFrom, visibleTo;
2630 GetVisibleLinesRange(&visibleFrom, &visibleTo);
b84839ae
VZ
2631
2632 wxRect rectLine;
2633 wxCoord xOrig, yOrig;
2634 CalcUnscrolledPosition(0, 0, &xOrig, &yOrig);
2635
ff3d11a0 2636 // tell the caller cache to cache the data
91c6cc0e
VZ
2637 if ( IsVirtual() )
2638 {
2639 wxListEvent evCache(wxEVT_COMMAND_LIST_CACHE_HINT,
2640 GetParent()->GetId());
2641 evCache.SetEventObject( GetParent() );
2642 evCache.m_oldItemIndex = visibleFrom;
2643 evCache.m_itemIndex = visibleTo;
2644 GetParent()->GetEventHandler()->ProcessEvent( evCache );
2645 }
ff3d11a0 2646
b54e41c5 2647 for ( size_t line = visibleFrom; line <= visibleTo; line++ )
cf1dfa6b 2648 {
b84839ae
VZ
2649 rectLine = GetLineRect(line);
2650
2651 if ( !IsExposed(rectLine.x - xOrig, rectLine.y - yOrig,
2652 rectLine.width, rectLine.height) )
2653 {
2654 // don't redraw unaffected lines to avoid flicker
2655 continue;
2656 }
2657
5cd89174 2658 GetLine(line)->DrawInReportMode( &dc,
b84839ae 2659 rectLine,
5cd89174 2660 GetLineHighlightRect(line),
49ecb029 2661 IsHighlighted(line) );
cf1dfa6b
VZ
2662 }
2663
2664 if ( HasFlag(wxLC_HRULES) )
2665 {
b54e41c5 2666 wxPen pen(GetRuleColour(), 1, wxSOLID);
cf1dfa6b
VZ
2667 wxSize clientSize = GetClientSize();
2668
e7d073c3
RD
2669 // Don't draw the first one
2670 for ( size_t i = visibleFrom+1; i <= visibleTo; i++ )
cf1dfa6b
VZ
2671 {
2672 dc.SetPen(pen);
2673 dc.SetBrush( *wxTRANSPARENT_BRUSH );
b54e41c5
VZ
2674 dc.DrawLine(0 - dev_x, i*lineHeight,
2675 clientSize.x - dev_x, i*lineHeight);
cf1dfa6b
VZ
2676 }
2677
2678 // Draw last horizontal rule
e7d073c3 2679 if ( visibleTo == GetItemCount() - 1 )
cf1dfa6b
VZ
2680 {
2681 dc.SetPen(pen);
2682 dc.SetBrush( *wxTRANSPARENT_BRUSH );
e7d073c3
RD
2683 dc.DrawLine(0 - dev_x, (m_lineTo+1)*lineHeight,
2684 clientSize.x - dev_x , (m_lineTo+1)*lineHeight );
cf1dfa6b 2685 }
2c1f73ee 2686 }
206b0a67
JS
2687
2688 // Draw vertical rules if required
cf1dfa6b 2689 if ( HasFlag(wxLC_VRULES) && !IsEmpty() )
206b0a67 2690 {
b54e41c5 2691 wxPen pen(GetRuleColour(), 1, wxSOLID);
cf1dfa6b 2692
206b0a67
JS
2693 wxRect firstItemRect;
2694 wxRect lastItemRect;
e7d073c3
RD
2695 GetItemRect(visibleFrom, firstItemRect);
2696 GetItemRect(visibleTo, lastItemRect);
206b0a67 2697 int x = firstItemRect.GetX();
673dfcfa
JS
2698 dc.SetPen(pen);
2699 dc.SetBrush(* wxTRANSPARENT_BRUSH);
999836aa 2700 for (int col = 0; col < GetColumnCount(); col++)
206b0a67
JS
2701 {
2702 int colWidth = GetColumnWidth(col);
cf1dfa6b 2703 x += colWidth;
e7d073c3
RD
2704 dc.DrawLine(x - dev_x - 2, firstItemRect.GetY() - 1 - dev_y,
2705 x - dev_x - 2, lastItemRect.GetBottom() + 1 - dev_y);
206b0a67 2706 }
d786bf87 2707 }
139adb6a 2708 }
cf1dfa6b 2709 else // !report
139adb6a 2710 {
1370703e 2711 size_t count = GetItemCount();
cf1dfa6b
VZ
2712 for ( size_t i = 0; i < count; i++ )
2713 {
2714 GetLine(i)->Draw( &dc );
2715 }
139adb6a 2716 }
004fd0c8 2717
65a1f350
RR
2718#ifndef __WXMAC__
2719 // Don't draw rect outline under Mac at all.
c25f61f1 2720 if ( HasCurrent() )
cf1dfa6b 2721 {
49ecb029 2722 if ( m_hasFocus )
c25f61f1
VZ
2723 {
2724 dc.SetPen( *wxBLACK_PEN );
2725 dc.SetBrush( *wxTRANSPARENT_BRUSH );
2726 dc.DrawRectangle( GetLineHighlightRect(m_current) );
2727 }
cf1dfa6b 2728 }
65a1f350 2729#endif
c801d85f 2730
139adb6a 2731 dc.EndDrawing();
e1e955e1 2732}
c801d85f 2733
b54e41c5 2734void wxListMainWindow::HighlightAll( bool on )
c801d85f 2735{
b54e41c5 2736 if ( IsSingleSel() )
c801d85f 2737 {
b54e41c5
VZ
2738 wxASSERT_MSG( !on, _T("can't do this in a single sel control") );
2739
2740 // we just have one item to turn off
2741 if ( HasCurrent() && IsHighlighted(m_current) )
139adb6a 2742 {
b54e41c5
VZ
2743 HighlightLine(m_current, FALSE);
2744 RefreshLine(m_current);
139adb6a 2745 }
e1e955e1 2746 }
b54e41c5 2747 else // multi sel
cf1dfa6b 2748 {
b54e41c5 2749 HighlightLines(0, GetItemCount() - 1, on);
cf1dfa6b 2750 }
e1e955e1 2751}
c801d85f 2752
cf1dfa6b 2753void wxListMainWindow::SendNotify( size_t line,
05a7f61d
VZ
2754 wxEventType command,
2755 wxPoint point )
c801d85f 2756{
139adb6a
RR
2757 wxListEvent le( command, GetParent()->GetId() );
2758 le.SetEventObject( GetParent() );
cf1dfa6b 2759 le.m_itemIndex = line;
05a7f61d
VZ
2760
2761 // set only for events which have position
2762 if ( point != wxDefaultPosition )
2763 le.m_pointDrag = point;
2764
c1c4c551
VZ
2765 // don't try to get the line info for virtual list controls: the main
2766 // program has it anyhow and if we did it would result in accessing all
2767 // the lines, even those which are not visible now and this is precisely
2768 // what we're trying to avoid
2769 if ( !IsVirtual() && (command != wxEVT_COMMAND_LIST_DELETE_ITEM) )
91c6cc0e 2770 {
0ddefeb0
VZ
2771 if ( line != (size_t)-1 )
2772 {
2773 GetLine(line)->GetItem( 0, le.m_item );
2774 }
2775 //else: this happens for wxEVT_COMMAND_LIST_ITEM_FOCUSED event
91c6cc0e
VZ
2776 }
2777 //else: there may be no more such item
2778
6e228e42 2779 GetParent()->GetEventHandler()->ProcessEvent( le );
e1e955e1 2780}
c801d85f 2781
0ddefeb0 2782void wxListMainWindow::ChangeCurrent(size_t current)
c801d85f 2783{
0ddefeb0 2784 m_current = current;
c801d85f 2785
0ddefeb0 2786 SendNotify(current, wxEVT_COMMAND_LIST_ITEM_FOCUSED);
e1e955e1 2787}
c801d85f 2788
5f1ea0ee 2789void wxListMainWindow::EditLabel( long item )
c801d85f 2790{
cf1dfa6b 2791 wxCHECK_RET( (item >= 0) && ((size_t)item < GetItemCount()),
3cd94a0d 2792 wxT("wrong index in wxGenericListCtrl::EditLabel()") );
004fd0c8 2793
62d89eb4 2794 size_t itemEdit = (size_t)item;
e179bd65 2795
fd9811b1 2796 wxListEvent le( wxEVT_COMMAND_LIST_BEGIN_LABEL_EDIT, GetParent()->GetId() );
139adb6a 2797 le.SetEventObject( GetParent() );
1370703e 2798 le.m_itemIndex = item;
62d89eb4 2799 wxListLineData *data = GetLine(itemEdit);
1370703e
VZ
2800 wxCHECK_RET( data, _T("invalid index in EditLabel()") );
2801 data->GetItem( 0, le.m_item );
62d89eb4
VZ
2802 if ( GetParent()->GetEventHandler()->ProcessEvent( le ) && !le.IsAllowed() )
2803 {
2804 // vetoed by user code
5f1ea0ee 2805 return;
62d89eb4 2806 }
004fd0c8 2807
cf1dfa6b
VZ
2808 // We have to call this here because the label in question might just have
2809 // been added and no screen update taken place.
62d89eb4 2810 if ( m_dirty )
cf1dfa6b 2811 wxSafeYield();
004fd0c8 2812
62d89eb4
VZ
2813 wxListTextCtrl *text = new wxListTextCtrl(this, itemEdit);
2814
92976ab6 2815 text->SetFocus();
e1e955e1 2816}
c801d85f 2817
e179bd65
RR
2818void wxListMainWindow::OnRenameTimer()
2819{
cf1dfa6b 2820 wxCHECK_RET( HasCurrent(), wxT("unexpected rename timer") );
004fd0c8 2821
cf1dfa6b 2822 EditLabel( m_current );
e179bd65
RR
2823}
2824
62d89eb4 2825bool wxListMainWindow::OnRenameAccept(size_t itemEdit, const wxString& value)
c801d85f 2826{
e179bd65
RR
2827 wxListEvent le( wxEVT_COMMAND_LIST_END_LABEL_EDIT, GetParent()->GetId() );
2828 le.SetEventObject( GetParent() );
62d89eb4 2829 le.m_itemIndex = itemEdit;
1370703e 2830
62d89eb4
VZ
2831 wxListLineData *data = GetLine(itemEdit);
2832 wxCHECK_MSG( data, FALSE, _T("invalid index in OnRenameAccept()") );
1370703e
VZ
2833
2834 data->GetItem( 0, le.m_item );
62d89eb4
VZ
2835 le.m_item.m_text = value;
2836 return !GetParent()->GetEventHandler()->ProcessEvent( le ) ||
2837 le.IsAllowed();
e1e955e1 2838}
c801d85f 2839
18dd54e3 2840void wxListMainWindow::OnRenameCancelled(size_t itemEdit)
86586459 2841{
86586459
RR
2842 // let owner know that the edit was cancelled
2843 wxListEvent le( wxEVT_COMMAND_LIST_END_LABEL_EDIT, GetParent()->GetId() );
86351e4a 2844
d2ed74b9 2845 le.SetEditCanceled(TRUE);
86351e4a 2846
86586459
RR
2847 le.SetEventObject( GetParent() );
2848 le.m_itemIndex = itemEdit;
2849
2850 wxListLineData *data = GetLine(itemEdit);
2851 wxCHECK_RET( data, _T("invalid index in OnRenameCancelled()") );
2852
2853 data->GetItem( 0, le.m_item );
2854
2855 GetEventHandler()->ProcessEvent( le );
2856}
2857
c801d85f
KB
2858void wxListMainWindow::OnMouse( wxMouseEvent &event )
2859{
3e1c4e00 2860 event.SetEventObject( GetParent() );
cf1dfa6b
VZ
2861 if ( GetParent()->GetEventHandler()->ProcessEvent( event) )
2862 return;
2863
2864 if ( !HasCurrent() || IsEmpty() )
2865 return;
2866
2867 if (m_dirty)
2868 return;
e3e65dac 2869
cf1dfa6b
VZ
2870 if ( !(event.Dragging() || event.ButtonDown() || event.LeftUp() ||
2871 event.ButtonDClick()) )
2872 return;
c801d85f 2873
aaef15bf
RR
2874 int x = event.GetX();
2875 int y = event.GetY();
2876 CalcUnscrolledPosition( x, y, &x, &y );
004fd0c8 2877
cc734310 2878 // where did we hit it (if we did)?
92976ab6 2879 long hitResult = 0;
1370703e 2880
cf1dfa6b
VZ
2881 size_t count = GetItemCount(),
2882 current;
2883
b5d43d1d 2884 if ( InReportView() )
92976ab6 2885 {
5cd89174 2886 current = y / GetLineHeight();
cc734310
VZ
2887 if ( current < count )
2888 hitResult = HitTestLine(current, x, y);
cf1dfa6b
VZ
2889 }
2890 else // !report
2891 {
2892 // TODO: optimize it too! this is less simple than for report view but
2893 // enumerating all items is still not a way to do it!!
4e3ace65 2894 for ( current = 0; current < count; current++ )
cf1dfa6b 2895 {
5cd89174 2896 hitResult = HitTestLine(current, x, y);
4e3ace65
VZ
2897 if ( hitResult )
2898 break;
cf1dfa6b 2899 }
92976ab6 2900 }
bd8289c1 2901
fd9811b1 2902 if (event.Dragging())
92976ab6 2903 {
fd9811b1 2904 if (m_dragCount == 0)
8d1d2284
VZ
2905 {
2906 // we have to report the raw, physical coords as we want to be
2907 // able to call HitTest(event.m_pointDrag) from the user code to
2908 // get the item being dragged
2909 m_dragStart = event.GetPosition();
2910 }
bffa1c77 2911
fd9811b1 2912 m_dragCount++;
bffa1c77 2913
cf1dfa6b
VZ
2914 if (m_dragCount != 3)
2915 return;
bffa1c77 2916
05a7f61d
VZ
2917 int command = event.RightIsDown() ? wxEVT_COMMAND_LIST_BEGIN_RDRAG
2918 : wxEVT_COMMAND_LIST_BEGIN_DRAG;
bffa1c77 2919
fd9811b1 2920 wxListEvent le( command, GetParent()->GetId() );
92976ab6 2921 le.SetEventObject( GetParent() );
e8c6a69c 2922 le.m_itemIndex = current;
bffa1c77
VZ
2923 le.m_pointDrag = m_dragStart;
2924 GetParent()->GetEventHandler()->ProcessEvent( le );
2925
2926 return;
92976ab6 2927 }
fd9811b1
RR
2928 else
2929 {
2930 m_dragCount = 0;
2931 }
bd8289c1 2932
cf1dfa6b
VZ
2933 if ( !hitResult )
2934 {
2935 // outside of any item
2936 return;
2937 }
bd8289c1 2938
efbb7287 2939 bool forceClick = FALSE;
92976ab6
RR
2940 if (event.ButtonDClick())
2941 {
92976ab6 2942 m_renameTimer->Stop();
efbb7287
VZ
2943 m_lastOnSame = FALSE;
2944
ddba340d 2945 if ( current == m_lineLastClicked )
efbb7287 2946 {
cf1dfa6b 2947 SendNotify( current, wxEVT_COMMAND_LIST_ITEM_ACTIVATED );
004fd0c8 2948
efbb7287
VZ
2949 return;
2950 }
2951 else
2952 {
2953 // the first click was on another item, so don't interpret this as
2954 // a double click, but as a simple click instead
2955 forceClick = TRUE;
2956 }
92976ab6 2957 }
bd8289c1 2958
92976ab6 2959 if (event.LeftUp() && m_lastOnSame)
c801d85f 2960 {
cf1dfa6b 2961 if ((current == m_current) &&
92976ab6 2962 (hitResult == wxLIST_HITTEST_ONITEMLABEL) &&
cf1dfa6b 2963 HasFlag(wxLC_EDIT_LABELS) )
92976ab6
RR
2964 {
2965 m_renameTimer->Start( 100, TRUE );
2966 }
2967 m_lastOnSame = FALSE;
e1e955e1 2968 }
cf1dfa6b 2969 else if (event.RightDown())
b204641e 2970 {
cf1dfa6b 2971 SendNotify( current, wxEVT_COMMAND_LIST_ITEM_RIGHT_CLICK,
05a7f61d 2972 event.GetPosition() );
b204641e 2973 }
cf1dfa6b 2974 else if (event.MiddleDown())
b204641e 2975 {
cf1dfa6b 2976 SendNotify( current, wxEVT_COMMAND_LIST_ITEM_MIDDLE_CLICK );
92976ab6 2977 }
cf1dfa6b 2978 else if ( event.LeftDown() || forceClick )
92976ab6 2979 {
efbb7287 2980 m_lineBeforeLastClicked = m_lineLastClicked;
cf1dfa6b
VZ
2981 m_lineLastClicked = current;
2982
2983 size_t oldCurrent = m_current;
efbb7287 2984
b54e41c5 2985 if ( IsSingleSel() || !(event.ControlDown() || event.ShiftDown()) )
b204641e 2986 {
b54e41c5 2987 HighlightAll( FALSE );
0ddefeb0
VZ
2988
2989 ChangeCurrent(current);
cf1dfa6b 2990
b54e41c5 2991 ReverseHighlight(m_current);
e1e955e1 2992 }
b54e41c5 2993 else // multi sel & either ctrl or shift is down
b204641e 2994 {
473d087e 2995 if (event.ControlDown())
92976ab6 2996 {
0ddefeb0 2997 ChangeCurrent(current);
cf1dfa6b 2998
b54e41c5 2999 ReverseHighlight(m_current);
92976ab6 3000 }
473d087e 3001 else if (event.ShiftDown())
92976ab6 3002 {
0ddefeb0 3003 ChangeCurrent(current);
bffa1c77 3004
cf1dfa6b
VZ
3005 size_t lineFrom = oldCurrent,
3006 lineTo = current;
f6bcfd97 3007
cf1dfa6b 3008 if ( lineTo < lineFrom )
92976ab6 3009 {
cf1dfa6b
VZ
3010 lineTo = lineFrom;
3011 lineFrom = m_current;
92976ab6
RR
3012 }
3013
b54e41c5 3014 HighlightLines(lineFrom, lineTo);
92976ab6 3015 }
cf1dfa6b 3016 else // !ctrl, !shift
92976ab6 3017 {
cf1dfa6b
VZ
3018 // test in the enclosing if should make it impossible
3019 wxFAIL_MSG( _T("how did we get here?") );
92976ab6 3020 }
e1e955e1 3021 }
cf1dfa6b 3022
92976ab6
RR
3023 if (m_current != oldCurrent)
3024 {
3025 RefreshLine( oldCurrent );
92976ab6 3026 }
efbb7287
VZ
3027
3028 // forceClick is only set if the previous click was on another item
3029 m_lastOnSame = !forceClick && (m_current == oldCurrent);
e1e955e1 3030 }
e1e955e1 3031}
c801d85f 3032
34bbbc27 3033void wxListMainWindow::MoveToItem(size_t item)
c801d85f 3034{
34bbbc27 3035 if ( item == (size_t)-1 )
cf1dfa6b 3036 return;
004fd0c8 3037
34bbbc27 3038 wxRect rect = GetLineRect(item);
cf3da716 3039
cf1dfa6b 3040 int client_w, client_h;
cf3da716 3041 GetClientSize( &client_w, &client_h );
f6bcfd97 3042
6d78bbe6
VZ
3043 const int hLine = GetLineHeight();
3044
13602ebd 3045 int view_x = SCROLL_UNIT_X*GetScrollPos( wxHORIZONTAL );
6d78bbe6 3046 int view_y = hLine*GetScrollPos( wxVERTICAL );
004fd0c8 3047
b5d43d1d 3048 if ( InReportView() )
92976ab6 3049 {
b54e41c5
VZ
3050 // the next we need the range of lines shown it might be different, so
3051 // recalculate it
3052 ResetVisibleLinesRange();
3053
cf1dfa6b 3054 if (rect.y < view_y )
6d78bbe6 3055 Scroll( -1, rect.y/hLine );
cf1dfa6b 3056 if (rect.y+rect.height+5 > view_y+client_h)
6d78bbe6 3057 Scroll( -1, (rect.y+rect.height-client_h+hLine)/hLine );
92976ab6 3058 }
b54e41c5 3059 else // !report
92976ab6 3060 {
cf1dfa6b 3061 if (rect.x-view_x < 5)
13602ebd 3062 Scroll( (rect.x-5)/SCROLL_UNIT_X, -1 );
cf1dfa6b 3063 if (rect.x+rect.width-5 > view_x+client_w)
13602ebd 3064 Scroll( (rect.x+rect.width-client_w+SCROLL_UNIT_X)/SCROLL_UNIT_X, -1 );
92976ab6 3065 }
e1e955e1 3066}
c801d85f 3067
cf1dfa6b
VZ
3068// ----------------------------------------------------------------------------
3069// keyboard handling
3070// ----------------------------------------------------------------------------
3071
3072void wxListMainWindow::OnArrowChar(size_t newCurrent, const wxKeyEvent& event)
c801d85f 3073{
cf1dfa6b
VZ
3074 wxCHECK_RET( newCurrent < (size_t)GetItemCount(),
3075 _T("invalid item index in OnArrowChar()") );
3076
3077 size_t oldCurrent = m_current;
3078
3079 // in single selection we just ignore Shift as we can't select several
3080 // items anyhow
b54e41c5 3081 if ( event.ShiftDown() && !IsSingleSel() )
cf1dfa6b 3082 {
0ddefeb0 3083 ChangeCurrent(newCurrent);
cf1dfa6b 3084
65a1f350
RR
3085 // refresh the old focus to remove it
3086 RefreshLine( oldCurrent );
3087
cf1dfa6b
VZ
3088 // select all the items between the old and the new one
3089 if ( oldCurrent > newCurrent )
3090 {
3091 newCurrent = oldCurrent;
3092 oldCurrent = m_current;
3093 }
3094
b54e41c5 3095 HighlightLines(oldCurrent, newCurrent);
cf1dfa6b
VZ
3096 }
3097 else // !shift
3098 {
b54e41c5
VZ
3099 // all previously selected items are unselected unless ctrl is held
3100 if ( !event.ControlDown() )
3101 HighlightAll(FALSE);
3102
0ddefeb0 3103 ChangeCurrent(newCurrent);
65a1f350
RR
3104
3105 // refresh the old focus to remove it
3106 RefreshLine( oldCurrent );
cf1dfa6b
VZ
3107
3108 if ( !event.ControlDown() )
3109 {
b54e41c5 3110 HighlightLine( m_current, TRUE );
cf1dfa6b
VZ
3111 }
3112 }
518c3939 3113
92976ab6 3114 RefreshLine( m_current );
cf1dfa6b 3115
cf3da716 3116 MoveToFocus();
e1e955e1 3117}
c801d85f 3118
3dfb93fd
RR
3119void wxListMainWindow::OnKeyDown( wxKeyEvent &event )
3120{
3121 wxWindow *parent = GetParent();
004fd0c8 3122
3dfb93fd
RR
3123 /* we propagate the key event up */
3124 wxKeyEvent ke( wxEVT_KEY_DOWN );
3125 ke.m_shiftDown = event.m_shiftDown;
3126 ke.m_controlDown = event.m_controlDown;
3127 ke.m_altDown = event.m_altDown;
3128 ke.m_metaDown = event.m_metaDown;
3129 ke.m_keyCode = event.m_keyCode;
3130 ke.m_x = event.m_x;
3131 ke.m_y = event.m_y;
3132 ke.SetEventObject( parent );
3133 if (parent->GetEventHandler()->ProcessEvent( ke )) return;
004fd0c8 3134
3dfb93fd
RR
3135 event.Skip();
3136}
004fd0c8 3137
c801d85f
KB
3138void wxListMainWindow::OnChar( wxKeyEvent &event )
3139{
51cc4dad 3140 wxWindow *parent = GetParent();
004fd0c8 3141
51cc4dad 3142 /* we send a list_key event up */
cf1dfa6b 3143 if ( HasCurrent() )
f6bcfd97
BP
3144 {
3145 wxListEvent le( wxEVT_COMMAND_LIST_KEY_DOWN, GetParent()->GetId() );
cf1dfa6b
VZ
3146 le.m_itemIndex = m_current;
3147 GetLine(m_current)->GetItem( 0, le.m_item );
12a3f227 3148 le.m_code = event.GetKeyCode();
f6bcfd97
BP
3149 le.SetEventObject( parent );
3150 parent->GetEventHandler()->ProcessEvent( le );
3151 }
51cc4dad 3152
3dfb93fd
RR
3153 /* we propagate the char event up */
3154 wxKeyEvent ke( wxEVT_CHAR );
51cc4dad
RR
3155 ke.m_shiftDown = event.m_shiftDown;
3156 ke.m_controlDown = event.m_controlDown;
3157 ke.m_altDown = event.m_altDown;
3158 ke.m_metaDown = event.m_metaDown;
3159 ke.m_keyCode = event.m_keyCode;
3160 ke.m_x = event.m_x;
3161 ke.m_y = event.m_y;
3162 ke.SetEventObject( parent );
3163 if (parent->GetEventHandler()->ProcessEvent( ke )) return;
004fd0c8 3164
12a3f227 3165 if (event.GetKeyCode() == WXK_TAB)
012a03e0
RR
3166 {
3167 wxNavigationKeyEvent nevent;
c5145d41 3168 nevent.SetWindowChange( event.ControlDown() );
012a03e0 3169 nevent.SetDirection( !event.ShiftDown() );
8253c7fd 3170 nevent.SetEventObject( GetParent()->GetParent() );
012a03e0 3171 nevent.SetCurrentFocus( m_parent );
87948f22
VZ
3172 if (GetParent()->GetParent()->GetEventHandler()->ProcessEvent( nevent ))
3173 return;
012a03e0 3174 }
004fd0c8 3175
51cc4dad 3176 /* no item -> nothing to do */
cf1dfa6b 3177 if (!HasCurrent())
c801d85f 3178 {
51cc4dad
RR
3179 event.Skip();
3180 return;
e1e955e1 3181 }
51cc4dad 3182
12a3f227 3183 switch (event.GetKeyCode())
c801d85f 3184 {
51cc4dad 3185 case WXK_UP:
cf1dfa6b
VZ
3186 if ( m_current > 0 )
3187 OnArrowChar( m_current - 1, event );
51cc4dad 3188 break;
cf1dfa6b 3189
51cc4dad 3190 case WXK_DOWN:
cf1dfa6b
VZ
3191 if ( m_current < (size_t)GetItemCount() - 1 )
3192 OnArrowChar( m_current + 1, event );
51cc4dad 3193 break;
cf1dfa6b 3194
51cc4dad 3195 case WXK_END:
1370703e 3196 if (!IsEmpty())
cf1dfa6b 3197 OnArrowChar( GetItemCount() - 1, event );
51cc4dad 3198 break;
cf1dfa6b 3199
51cc4dad 3200 case WXK_HOME:
1370703e 3201 if (!IsEmpty())
cf1dfa6b 3202 OnArrowChar( 0, event );
51cc4dad 3203 break;
cf1dfa6b 3204
51cc4dad 3205 case WXK_PRIOR:
f6bcfd97 3206 {
b5d43d1d 3207 int steps = InReportView() ? m_linesPerPage - 1 : m_current % m_linesPerPage;
cf1dfa6b
VZ
3208
3209 int index = m_current - steps;
3210 if (index < 0)
3211 index = 0;
3212
3213 OnArrowChar( index, event );
51cc4dad 3214 }
51cc4dad 3215 break;
cf1dfa6b 3216
51cc4dad 3217 case WXK_NEXT:
bffa1c77 3218 {
b5d43d1d 3219 int steps = InReportView()
999836aa
VZ
3220 ? m_linesPerPage - 1
3221 : m_linesPerPage - (m_current % m_linesPerPage) - 1;
f6bcfd97 3222
cf1dfa6b
VZ
3223 size_t index = m_current + steps;
3224 size_t count = GetItemCount();
3225 if ( index >= count )
3226 index = count - 1;
3227
3228 OnArrowChar( index, event );
51cc4dad 3229 }
51cc4dad 3230 break;
cf1dfa6b 3231
51cc4dad 3232 case WXK_LEFT:
b5d43d1d 3233 if ( !InReportView() )
51cc4dad 3234 {
cf1dfa6b
VZ
3235 int index = m_current - m_linesPerPage;
3236 if (index < 0)
3237 index = 0;
3238
3239 OnArrowChar( index, event );
51cc4dad
RR
3240 }
3241 break;
cf1dfa6b 3242
51cc4dad 3243 case WXK_RIGHT:
b5d43d1d 3244 if ( !InReportView() )
51cc4dad 3245 {
cf1dfa6b
VZ
3246 size_t index = m_current + m_linesPerPage;
3247
3248 size_t count = GetItemCount();
3249 if ( index >= count )
3250 index = count - 1;
3251
3252 OnArrowChar( index, event );
51cc4dad
RR
3253 }
3254 break;
cf1dfa6b 3255
51cc4dad 3256 case WXK_SPACE:
b54e41c5 3257 if ( IsSingleSel() )
33d0e17c 3258 {
87948f22 3259 SendNotify( m_current, wxEVT_COMMAND_LIST_ITEM_ACTIVATED );
70541533
VZ
3260
3261 if ( IsHighlighted(m_current) )
3262 {
3263 // don't unselect the item in single selection mode
3264 break;
3265 }
3266 //else: select it in ReverseHighlight() below if unselected
33d0e17c 3267 }
70541533
VZ
3268
3269 ReverseHighlight(m_current);
51cc4dad 3270 break;
cf1dfa6b 3271
51cc4dad
RR
3272 case WXK_RETURN:
3273 case WXK_EXECUTE:
87948f22 3274 SendNotify( m_current, wxEVT_COMMAND_LIST_ITEM_ACTIVATED );
51cc4dad 3275 break;
cf1dfa6b 3276
51cc4dad 3277 default:
51cc4dad 3278 event.Skip();
e1e955e1 3279 }
e1e955e1 3280}
c801d85f 3281
cf1dfa6b
VZ
3282// ----------------------------------------------------------------------------
3283// focus handling
3284// ----------------------------------------------------------------------------
3285
a6d57d03
VS
3286void wxListMainWindow::SetFocus()
3287{
3288 // VS: wxListMainWindow derives from wxPanel (via wxScrolledWindow) and wxPanel
a77ec46d 3289 // overrides SetFocus in such way that it does never change focus from
a6d57d03 3290 // panel's child to the panel itself. Unfortunately, we must be able to change
a77ec46d 3291 // focus to the panel from wxListTextCtrl because the text control should
a6d57d03
VS
3292 // disappear when the user clicks outside it.
3293
3294 wxWindow *oldFocus = FindFocus();
a77ec46d 3295
072da98f 3296 if ( oldFocus && oldFocus->GetParent() == this )
a6d57d03
VS
3297 {
3298 wxWindow::SetFocus();
3299 }
3300 else
3301 {
3302 wxScrolledWindow::SetFocus();
3303 }
3304}
3305
c801d85f
KB
3306void wxListMainWindow::OnSetFocus( wxFocusEvent &WXUNUSED(event) )
3307{
dc76287d
RD
3308 if ( GetParent() )
3309 {
3310 wxFocusEvent event( wxEVT_SET_FOCUS, GetParent()->GetId() );
3311 event.SetEventObject( GetParent() );
3312 if ( GetParent()->GetEventHandler()->ProcessEvent( event) )
3313 return;
3314 }
3315
bde9072f
VZ
3316 // wxGTK sends us EVT_SET_FOCUS events even if we had never got
3317 // EVT_KILL_FOCUS before which means that we finish by redrawing the items
3318 // which are already drawn correctly resulting in horrible flicker - avoid
3319 // it
47724389
VZ
3320 if ( !m_hasFocus )
3321 {
3322 m_hasFocus = TRUE;
bde9072f 3323
47724389
VZ
3324 RefreshSelected();
3325 }
e1e955e1 3326}
c801d85f
KB
3327
3328void wxListMainWindow::OnKillFocus( wxFocusEvent &WXUNUSED(event) )
3329{
dc76287d
RD
3330 if ( GetParent() )
3331 {
3332 wxFocusEvent event( wxEVT_KILL_FOCUS, GetParent()->GetId() );
3333 event.SetEventObject( GetParent() );
3334 if ( GetParent()->GetEventHandler()->ProcessEvent( event) )
3335 return;
3336 }
63852e78 3337 m_hasFocus = FALSE;
49ecb029 3338 RefreshSelected();
e1e955e1 3339}
c801d85f 3340
1e6d9499 3341void wxListMainWindow::DrawImage( int index, wxDC *dc, int x, int y )
c801d85f 3342{
cf1dfa6b 3343 if ( HasFlag(wxLC_ICON) && (m_normal_image_list))
63852e78
RR
3344 {
3345 m_normal_image_list->Draw( index, *dc, x, y, wxIMAGELIST_DRAW_TRANSPARENT );
63852e78 3346 }
cf1dfa6b 3347 else if ( HasFlag(wxLC_SMALL_ICON) && (m_small_image_list))
63852e78
RR
3348 {
3349 m_small_image_list->Draw( index, *dc, x, y, wxIMAGELIST_DRAW_TRANSPARENT );
3350 }
cf1dfa6b 3351 else if ( HasFlag(wxLC_LIST) && (m_small_image_list))
0b855868
RR
3352 {
3353 m_small_image_list->Draw( index, *dc, x, y, wxIMAGELIST_DRAW_TRANSPARENT );
3354 }
b5d43d1d 3355 else if ( InReportView() && (m_small_image_list))
63852e78
RR
3356 {
3357 m_small_image_list->Draw( index, *dc, x, y, wxIMAGELIST_DRAW_TRANSPARENT );
63852e78 3358 }
e1e955e1 3359}
c801d85f 3360
5cd89174 3361void wxListMainWindow::GetImageSize( int index, int &width, int &height ) const
c801d85f 3362{
cf1dfa6b 3363 if ( HasFlag(wxLC_ICON) && m_normal_image_list )
63852e78
RR
3364 {
3365 m_normal_image_list->GetSize( index, width, height );
63852e78 3366 }
cf1dfa6b 3367 else if ( HasFlag(wxLC_SMALL_ICON) && m_small_image_list )
63852e78
RR
3368 {
3369 m_small_image_list->GetSize( index, width, height );
63852e78 3370 }
cf1dfa6b 3371 else if ( HasFlag(wxLC_LIST) && m_small_image_list )
0b855868
RR
3372 {
3373 m_small_image_list->GetSize( index, width, height );
0b855868 3374 }
b5d43d1d 3375 else if ( InReportView() && m_small_image_list )
63852e78
RR
3376 {
3377 m_small_image_list->GetSize( index, width, height );
63852e78 3378 }
cf1dfa6b
VZ
3379 else
3380 {
3381 width =
3382 height = 0;
3383 }
e1e955e1 3384}
c801d85f 3385
5cd89174 3386int wxListMainWindow::GetTextLength( const wxString &s ) const
c801d85f 3387{
5cd89174 3388 wxClientDC dc( wxConstCast(this, wxListMainWindow) );
cf1dfa6b 3389 dc.SetFont( GetFont() );
c801d85f 3390
cf1dfa6b
VZ
3391 wxCoord lw;
3392 dc.GetTextExtent( s, &lw, NULL );
3393
3394 return lw + AUTOSIZE_COL_MARGIN;
e1e955e1 3395}
c801d85f 3396
80020b62 3397void wxListMainWindow::SetImageList( wxImageListType *imageList, int which )
c801d85f 3398{
139adb6a 3399 m_dirty = TRUE;
f6bcfd97
BP
3400
3401 // calc the spacing from the icon size
3402 int width = 0,
3403 height = 0;
3404 if ((imageList) && (imageList->GetImageCount()) )
3405 {
3406 imageList->GetSize(0, width, height);
3407 }
3408
3409 if (which == wxIMAGE_LIST_NORMAL)
3410 {
3411 m_normal_image_list = imageList;
3412 m_normal_spacing = width + 8;
3413 }
3414
3415 if (which == wxIMAGE_LIST_SMALL)
3416 {
3417 m_small_image_list = imageList;
3418 m_small_spacing = width + 14;
ca7353de 3419 m_lineHeight = 0; // ensure that the line height will be recalc'd
f6bcfd97 3420 }
e1e955e1 3421}
c801d85f 3422
debe6624 3423void wxListMainWindow::SetItemSpacing( int spacing, bool isSmall )
c801d85f 3424{
139adb6a
RR
3425 m_dirty = TRUE;
3426 if (isSmall)
3427 {
3428 m_small_spacing = spacing;
3429 }
3430 else
3431 {
3432 m_normal_spacing = spacing;
3433 }
e1e955e1 3434}
c801d85f 3435
debe6624 3436int wxListMainWindow::GetItemSpacing( bool isSmall )
c801d85f 3437{
f6bcfd97 3438 return isSmall ? m_small_spacing : m_normal_spacing;
e1e955e1 3439}
c801d85f 3440
cf1dfa6b
VZ
3441// ----------------------------------------------------------------------------
3442// columns
3443// ----------------------------------------------------------------------------
3444
debe6624 3445void wxListMainWindow::SetColumn( int col, wxListItem &item )
c801d85f 3446{
222ed1d6 3447 wxListHeaderDataList::compatibility_iterator node = m_columns.Item( col );
f6bcfd97 3448
cf1dfa6b
VZ
3449 wxCHECK_RET( node, _T("invalid column index in SetColumn") );
3450
3451 if ( item.m_width == wxLIST_AUTOSIZE_USEHEADER )
3452 item.m_width = GetTextLength( item.m_text );
3453
3454 wxListHeaderData *column = node->GetData();
3455 column->SetItem( item );
3456
3457 wxListHeaderWindow *headerWin = GetListCtrl()->m_headerWin;
f6bcfd97
BP
3458 if ( headerWin )
3459 headerWin->m_dirty = TRUE;
cf1dfa6b
VZ
3460
3461 m_dirty = TRUE;
3462
3463 // invalidate it as it has to be recalculated
3464 m_headerWidth = 0;
e1e955e1 3465}
c801d85f 3466
debe6624 3467void wxListMainWindow::SetColumnWidth( int col, int width )
c801d85f 3468{
cf1dfa6b
VZ
3469 wxCHECK_RET( col >= 0 && col < GetColumnCount(),
3470 _T("invalid column index") );
3471
b5d43d1d 3472 wxCHECK_RET( InReportView(),
f6bcfd97 3473 _T("SetColumnWidth() can only be called in report mode.") );
0208334d 3474
63852e78 3475 m_dirty = TRUE;
abe4a4f1
VS
3476 wxListHeaderWindow *headerWin = GetListCtrl()->m_headerWin;
3477 if ( headerWin )
3478 headerWin->m_dirty = TRUE;
bd8289c1 3479
222ed1d6 3480 wxListHeaderDataList::compatibility_iterator node = m_columns.Item( col );
cf1dfa6b
VZ
3481 wxCHECK_RET( node, _T("no column?") );
3482
3483 wxListHeaderData *column = node->GetData();
3484
3485 size_t count = GetItemCount();
3486
f6bcfd97
BP
3487 if (width == wxLIST_AUTOSIZE_USEHEADER)
3488 {
cf1dfa6b 3489 width = GetTextLength(column->GetText());
f6bcfd97 3490 }
cf1dfa6b 3491 else if ( width == wxLIST_AUTOSIZE )
0180dad6 3492 {
cf1dfa6b
VZ
3493 if ( IsVirtual() )
3494 {
3495 // TODO: determine the max width somehow...
3496 width = WIDTH_COL_DEFAULT;
3497 }
3498 else // !virtual
0180dad6 3499 {
cf1dfa6b
VZ
3500 wxClientDC dc(this);
3501 dc.SetFont( GetFont() );
3502
3503 int max = AUTOSIZE_COL_MARGIN;
3504
3505 for ( size_t i = 0; i < count; i++ )
0180dad6 3506 {
cf1dfa6b 3507 wxListLineData *line = GetLine(i);
222ed1d6 3508 wxListItemDataList::compatibility_iterator n = line->m_items.Item( col );
cf1dfa6b
VZ
3509
3510 wxCHECK_RET( n, _T("no subitem?") );
3511
2c1f73ee 3512 wxListItemData *item = n->GetData();
cf1dfa6b
VZ
3513 int current = 0;
3514
bffa1c77
VZ
3515 if (item->HasImage())
3516 {
cf1dfa6b 3517 int ix, iy;
0180dad6 3518 GetImageSize( item->GetImage(), ix, iy );
cf1dfa6b 3519 current += ix + 5;
bffa1c77 3520 }
cf1dfa6b 3521
bffa1c77
VZ
3522 if (item->HasText())
3523 {
cf1dfa6b
VZ
3524 wxCoord w;
3525 dc.GetTextExtent( item->GetText(), &w, NULL );
3526 current += w;
bffa1c77 3527 }
cf1dfa6b 3528
2c1f73ee
VZ
3529 if (current > max)
3530 max = current;
0180dad6 3531 }
cf1dfa6b
VZ
3532
3533 width = max + AUTOSIZE_COL_MARGIN;
0180dad6 3534 }
0180dad6
RR
3535 }
3536
cf1dfa6b 3537 column->SetWidth( width );
bd8289c1 3538
cf1dfa6b
VZ
3539 // invalidate it as it has to be recalculated
3540 m_headerWidth = 0;
3541}
3542
3543int wxListMainWindow::GetHeaderWidth() const
3544{
3545 if ( !m_headerWidth )
0208334d 3546 {
cf1dfa6b
VZ
3547 wxListMainWindow *self = wxConstCast(this, wxListMainWindow);
3548
3549 size_t count = GetColumnCount();
3550 for ( size_t col = 0; col < count; col++ )
63852e78 3551 {
cf1dfa6b 3552 self->m_headerWidth += GetColumnWidth(col);
63852e78 3553 }
0208334d 3554 }
bd8289c1 3555
cf1dfa6b 3556 return m_headerWidth;
e1e955e1 3557}
c801d85f 3558
cf1dfa6b 3559void wxListMainWindow::GetColumn( int col, wxListItem &item ) const
c801d85f 3560{
222ed1d6 3561 wxListHeaderDataList::compatibility_iterator node = m_columns.Item( col );
cf1dfa6b
VZ
3562 wxCHECK_RET( node, _T("invalid column index in GetColumn") );
3563
3564 wxListHeaderData *column = node->GetData();
3565 column->GetItem( item );
e1e955e1 3566}
c801d85f 3567
cf1dfa6b 3568int wxListMainWindow::GetColumnWidth( int col ) const
c801d85f 3569{
222ed1d6 3570 wxListHeaderDataList::compatibility_iterator node = m_columns.Item( col );
24b9f055
VZ
3571 wxCHECK_MSG( node, 0, _T("invalid column index") );
3572
3573 wxListHeaderData *column = node->GetData();
3574 return column->GetWidth();
e1e955e1 3575}
c801d85f 3576
cf1dfa6b
VZ
3577// ----------------------------------------------------------------------------
3578// item state
3579// ----------------------------------------------------------------------------
c801d85f
KB
3580
3581void wxListMainWindow::SetItem( wxListItem &item )
3582{
cf1dfa6b
VZ
3583 long id = item.m_itemId;
3584 wxCHECK_RET( id >= 0 && (size_t)id < GetItemCount(),
3585 _T("invalid item index in SetItem") );
3586
6c02c329
VZ
3587 if ( !IsVirtual() )
3588 {
3589 wxListLineData *line = GetLine((size_t)id);
3590 line->SetItem( item.m_col, item );
3591 }
3592
285013b3
VZ
3593 // update the item on screen
3594 wxRect rectItem;
3595 GetItemRect(id, rectItem);
3596 RefreshRect(rectItem);
e1e955e1 3597}
c801d85f 3598
cf1dfa6b 3599void wxListMainWindow::SetItemState( long litem, long state, long stateMask )
c801d85f 3600{
cf1dfa6b 3601 wxCHECK_RET( litem >= 0 && (size_t)litem < GetItemCount(),
54442116
VZ
3602 _T("invalid list ctrl item index in SetItem") );
3603
cf1dfa6b 3604 size_t oldCurrent = m_current;
88b792af 3605 size_t item = (size_t)litem; // safe because of the check above
bd8289c1 3606
88b792af 3607 // do we need to change the focus?
54442116 3608 if ( stateMask & wxLIST_STATE_FOCUSED )
c801d85f 3609 {
54442116 3610 if ( state & wxLIST_STATE_FOCUSED )
92976ab6 3611 {
54442116 3612 // don't do anything if this item is already focused
cf1dfa6b 3613 if ( item != m_current )
92976ab6 3614 {
0ddefeb0 3615 ChangeCurrent(item);
cf1dfa6b 3616
88b792af 3617 if ( oldCurrent != (size_t)-1 )
cf1dfa6b 3618 {
88b792af
VZ
3619 if ( IsSingleSel() )
3620 {
3621 HighlightLine(oldCurrent, FALSE);
3622 }
3623
cf1dfa6b
VZ
3624 RefreshLine(oldCurrent);
3625 }
54442116 3626
92976ab6 3627 RefreshLine( m_current );
92976ab6 3628 }
54442116
VZ
3629 }
3630 else // unfocus
3631 {
3632 // don't do anything if this item is not focused
cf1dfa6b 3633 if ( item == m_current )
bffa1c77 3634 {
0ddefeb0 3635 ResetCurrent();
88b792af 3636
943f6ad3
VZ
3637 if ( IsSingleSel() )
3638 {
3639 // we must unselect the old current item as well or we
3640 // might end up with more than one selected item in a
3641 // single selection control
3642 HighlightLine(oldCurrent, FALSE);
3643 }
3644
88b792af 3645 RefreshLine( oldCurrent );
bffa1c77 3646 }
92976ab6 3647 }
e1e955e1 3648 }
54442116 3649
88b792af 3650 // do we need to change the selection state?
54442116
VZ
3651 if ( stateMask & wxLIST_STATE_SELECTED )
3652 {
3653 bool on = (state & wxLIST_STATE_SELECTED) != 0;
54442116 3654
b54e41c5 3655 if ( IsSingleSel() )
54442116 3656 {
cf1dfa6b
VZ
3657 if ( on )
3658 {
3659 // selecting the item also makes it the focused one in the
3660 // single sel mode
3661 if ( m_current != item )
3662 {
0ddefeb0 3663 ChangeCurrent(item);
cf1dfa6b
VZ
3664
3665 if ( oldCurrent != (size_t)-1 )
3666 {
b54e41c5 3667 HighlightLine( oldCurrent, FALSE );
cf1dfa6b
VZ
3668 RefreshLine( oldCurrent );
3669 }
3670 }
3671 }
3672 else // off
3673 {
3674 // only the current item may be selected anyhow
3675 if ( item != m_current )
3676 return;
3677 }
54442116
VZ
3678 }
3679
b54e41c5 3680 if ( HighlightLine(item, on) )
54442116 3681 {
cf1dfa6b 3682 RefreshLine(item);
54442116
VZ
3683 }
3684 }
e1e955e1 3685}
c801d85f 3686
62d89eb4 3687int wxListMainWindow::GetItemState( long item, long stateMask ) const
c801d85f 3688{
cf1dfa6b
VZ
3689 wxCHECK_MSG( item >= 0 && (size_t)item < GetItemCount(), 0,
3690 _T("invalid list ctrl item index in GetItemState()") );
3691
92976ab6 3692 int ret = wxLIST_STATE_DONTCARE;
cf1dfa6b
VZ
3693
3694 if ( stateMask & wxLIST_STATE_FOCUSED )
c801d85f 3695 {
cf1dfa6b
VZ
3696 if ( (size_t)item == m_current )
3697 ret |= wxLIST_STATE_FOCUSED;
e1e955e1 3698 }
cf1dfa6b
VZ
3699
3700 if ( stateMask & wxLIST_STATE_SELECTED )
c801d85f 3701 {
b54e41c5 3702 if ( IsHighlighted(item) )
cf1dfa6b 3703 ret |= wxLIST_STATE_SELECTED;
e1e955e1 3704 }
cf1dfa6b 3705
92976ab6 3706 return ret;
e1e955e1 3707}
c801d85f 3708
62d89eb4 3709void wxListMainWindow::GetItem( wxListItem &item ) const
c801d85f 3710{
cf1dfa6b
VZ
3711 wxCHECK_RET( item.m_itemId >= 0 && (size_t)item.m_itemId < GetItemCount(),
3712 _T("invalid item index in GetItem") );
3713
3714 wxListLineData *line = GetLine((size_t)item.m_itemId);
3715 line->GetItem( item.m_col, item );
e1e955e1 3716}
c801d85f 3717
cf1dfa6b
VZ
3718// ----------------------------------------------------------------------------
3719// item count
3720// ----------------------------------------------------------------------------
3721
3722size_t wxListMainWindow::GetItemCount() const
1370703e
VZ
3723{
3724 return IsVirtual() ? m_countVirt : m_lines.GetCount();
3725}
3726
3727void wxListMainWindow::SetItemCount(long count)
c801d85f 3728{
b54e41c5 3729 m_selStore.SetItemCount(count);
1370703e
VZ
3730 m_countVirt = count;
3731
850ed6e7
VZ
3732 ResetVisibleLinesRange();
3733
5fe143df
VZ
3734 // scrollbars must be reset
3735 m_dirty = TRUE;
e1e955e1 3736}
c801d85f 3737
62d89eb4 3738int wxListMainWindow::GetSelectedItemCount() const
c801d85f 3739{
cf1dfa6b 3740 // deal with the quick case first
b54e41c5 3741 if ( IsSingleSel() )
92976ab6 3742 {
b54e41c5 3743 return HasCurrent() ? IsHighlighted(m_current) : FALSE;
92976ab6 3744 }
cf1dfa6b
VZ
3745
3746 // virtual controls remmebers all its selections itself
3747 if ( IsVirtual() )
b54e41c5 3748 return m_selStore.GetSelectedCount();
cf1dfa6b
VZ
3749
3750 // TODO: we probably should maintain the number of items selected even for
3751 // non virtual controls as enumerating all lines is really slow...
3752 size_t countSel = 0;
3753 size_t count = GetItemCount();
3754 for ( size_t line = 0; line < count; line++ )
92976ab6 3755 {
b54e41c5 3756 if ( GetLine(line)->IsHighlighted() )
cf1dfa6b 3757 countSel++;
92976ab6 3758 }
c801d85f 3759
cf1dfa6b 3760 return countSel;
e1e955e1 3761}
e3e65dac 3762
cf1dfa6b
VZ
3763// ----------------------------------------------------------------------------
3764// item position/size
3765// ----------------------------------------------------------------------------
3766
11ebea16
VZ
3767wxRect wxListMainWindow::GetViewRect() const
3768{
3769 wxASSERT_MSG( !HasFlag(wxLC_REPORT | wxLC_LIST),
3770 _T("wxListCtrl::GetViewRect() only works in icon mode") );
3771
3772 // we need to find the longest/tallest label
3773 wxCoord xMax = 0,
3774 yMax = 0;
3775 const int count = GetItemCount();
3776 if ( count )
3777 {
3778 for ( int i = 0; i < count; i++ )
3779 {
3780 wxRect r;
3781 GetItemRect(i, r);
3782
3783 wxCoord x = r.GetRight(),
3784 y = r.GetBottom();
3785
3786 if ( x > xMax )
3787 xMax = x;
3788 if ( y > yMax )
3789 yMax = y;
3790 }
3791 }
3792
eb6c4508 3793 // some fudge needed to make it look prettier
13602ebd
VZ
3794 xMax += 2*EXTRA_BORDER_X;
3795 yMax += 2*EXTRA_BORDER_Y;
eb6c4508
VZ
3796
3797 // account for the scrollbars if necessary
3798 const wxSize sizeAll = GetClientSize();
3799 if ( xMax > sizeAll.x )
3800 yMax += wxSystemSettings::GetMetric(wxSYS_HSCROLL_Y);
3801 if ( yMax > sizeAll.y )
3802 xMax += wxSystemSettings::GetMetric(wxSYS_VSCROLL_X);
11ebea16
VZ
3803
3804 return wxRect(0, 0, xMax, yMax);
3805}
3806
62d89eb4 3807void wxListMainWindow::GetItemRect( long index, wxRect &rect ) const
c801d85f 3808{
cf1dfa6b
VZ
3809 wxCHECK_RET( index >= 0 && (size_t)index < GetItemCount(),
3810 _T("invalid index in GetItemRect") );
3811
1e54be64
VZ
3812 // ensure that we're laid out, otherwise we could return nonsense
3813 if ( m_dirty )
3814 {
3815 wxConstCast(this, wxListMainWindow)->
3816 RecalculatePositions(TRUE /* no refresh */);
3817 }
3818
5cd89174 3819 rect = GetLineRect((size_t)index);
b54e41c5 3820
cf1dfa6b 3821 CalcScrolledPosition(rect.x, rect.y, &rect.x, &rect.y);
e1e955e1 3822}
c801d85f 3823
62d89eb4 3824bool wxListMainWindow::GetItemPosition(long item, wxPoint& pos) const
c801d85f 3825{
cf1dfa6b
VZ
3826 wxRect rect;
3827 GetItemRect(item, rect);
bd8289c1 3828
cf1dfa6b
VZ
3829 pos.x = rect.x;
3830 pos.y = rect.y;
bd8289c1 3831
cf1dfa6b 3832 return TRUE;
e1e955e1 3833}
c801d85f 3834
cf1dfa6b
VZ
3835// ----------------------------------------------------------------------------
3836// geometry calculation
3837// ----------------------------------------------------------------------------
3838
34bbbc27 3839void wxListMainWindow::RecalculatePositions(bool noRefresh)
c801d85f 3840{
1e6d9499 3841 wxClientDC dc( this );
92976ab6 3842 dc.SetFont( GetFont() );
c801d85f 3843
13602ebd
VZ
3844 const size_t count = GetItemCount();
3845
cf1dfa6b
VZ
3846 int iconSpacing;
3847 if ( HasFlag(wxLC_ICON) )
3848 iconSpacing = m_normal_spacing;
3849 else if ( HasFlag(wxLC_SMALL_ICON) )
3850 iconSpacing = m_small_spacing;
3851 else
3852 iconSpacing = 0;
004fd0c8 3853
bf632edd
RR
3854 // Note that we do not call GetClientSize() here but
3855 // GetSize() and substract the border size for sunken
3856 // borders manually. This is technically incorrect,
3857 // but we need to know the client area's size WITHOUT
3858 // scrollbars here. Since we don't know if there are
3859 // any scrollbars, we use GetSize() instead. Another
3860 // solution would be to call SetScrollbars() here to
3861 // remove the scrollbars and call GetClientSize() then,
3862 // but this might result in flicker and - worse - will
3863 // reset the scrollbars to 0 which is not good at all
3864 // if you resize a dialog/window, but don't want to
3865 // reset the window scrolling. RR.
3866 // Furthermore, we actually do NOT subtract the border
3867 // width as 2 pixels is just the extra space which we
3868 // need around the actual content in the window. Other-
3869 // wise the text would e.g. touch the upper border. RR.
cf1dfa6b
VZ
3870 int clientWidth,
3871 clientHeight;
bf632edd 3872 GetSize( &clientWidth, &clientHeight );
a77ec46d 3873
6d78bbe6
VZ
3874 const int lineHeight = GetLineHeight();
3875
b5d43d1d 3876 if ( InReportView() )
cf1dfa6b 3877 {
13602ebd 3878 // all lines have the same height and we scroll one line per step
13602ebd 3879 int entireHeight = count*lineHeight + LINE_SPACING;
bd8289c1 3880
b54e41c5
VZ
3881 m_linesPerPage = clientHeight / lineHeight;
3882
3883 ResetVisibleLinesRange();
2c1f73ee 3884
13602ebd
VZ
3885 SetScrollbars( SCROLL_UNIT_X, lineHeight,
3886 GetHeaderWidth() / SCROLL_UNIT_X,
3887 (entireHeight + lineHeight - 1) / lineHeight,
cf1dfa6b
VZ
3888 GetScrollPos(wxHORIZONTAL),
3889 GetScrollPos(wxVERTICAL),
3890 TRUE );
e1e955e1 3891 }
cf1dfa6b 3892 else // !report
92976ab6 3893 {
13602ebd
VZ
3894 // we have 3 different layout strategies: either layout all items
3895 // horizontally/vertically (wxLC_ALIGN_XXX styles explicitly given) or
3896 // to arrange them in top to bottom, left to right (don't ask me why
3897 // not the other way round...) order
3898 if ( HasFlag(wxLC_ALIGN_LEFT | wxLC_ALIGN_TOP) )
e487524e 3899 {
13602ebd
VZ
3900 int x = EXTRA_BORDER_X;
3901 int y = EXTRA_BORDER_Y;
cf1dfa6b 3902
94dd23ae
VZ
3903 wxCoord widthMax = 0;
3904
3905 size_t i;
3906 for ( i = 0; i < count; i++ )
92976ab6 3907 {
cf1dfa6b 3908 wxListLineData *line = GetLine(i);
92976ab6 3909 line->CalculateSize( &dc, iconSpacing );
13602ebd 3910 line->SetPosition( x, y, iconSpacing );
cf1dfa6b 3911
5cd89174 3912 wxSize sizeLine = GetLineSize(i);
cf1dfa6b 3913
13602ebd
VZ
3914 if ( HasFlag(wxLC_ALIGN_TOP) )
3915 {
94dd23ae
VZ
3916 if ( sizeLine.x > widthMax )
3917 widthMax = sizeLine.x;
3918
13602ebd
VZ
3919 y += sizeLine.y;
3920 }
3921 else // wxLC_ALIGN_LEFT
3922 {
3923 x += sizeLine.x + MARGIN_BETWEEN_ROWS;
3924 }
3925 }
3926
94dd23ae
VZ
3927 if ( HasFlag(wxLC_ALIGN_TOP) )
3928 {
3929 // traverse the items again and tweak their sizes so that they are
3930 // all the same in a row
3931 for ( i = 0; i < count; i++ )
3932 {
3933 wxListLineData *line = GetLine(i);
3934 line->m_gi->ExtendWidth(widthMax);
3935 }
3936 }
3937
3938
13602ebd
VZ
3939 SetScrollbars
3940 (
3941 SCROLL_UNIT_X,
6d78bbe6 3942 lineHeight,
13602ebd 3943 (x + SCROLL_UNIT_X) / SCROLL_UNIT_X,
6d78bbe6 3944 (y + lineHeight) / lineHeight,
13602ebd
VZ
3945 GetScrollPos( wxHORIZONTAL ),
3946 GetScrollPos( wxVERTICAL ),
3947 TRUE
3948 );
3949 }
3950 else // "flowed" arrangement, the most complicated case
3951 {
3952 // at first we try without any scrollbars, if the items don't fit into
3953 // the window, we recalculate after subtracting the space taken by the
3954 // scrollbar
3955
8a39593e 3956 int entireWidth = 0;
cf1dfa6b 3957
13602ebd
VZ
3958 for (int tries = 0; tries < 2; tries++)
3959 {
3960 entireWidth = 2*EXTRA_BORDER_X;
cf1dfa6b 3961
13602ebd 3962 if (tries == 1)
92976ab6 3963 {
13602ebd
VZ
3964 // Now we have decided that the items do not fit into the
3965 // client area, so we need a scrollbar
3966 entireWidth += SCROLL_UNIT_X;
92976ab6 3967 }
a77ec46d 3968
13602ebd
VZ
3969 int x = EXTRA_BORDER_X;
3970 int y = EXTRA_BORDER_Y;
3971 int maxWidthInThisRow = 0;
3972
3973 m_linesPerPage = 0;
3974 int currentlyVisibleLines = 0;
a77ec46d 3975
13602ebd 3976 for (size_t i = 0; i < count; i++)
92976ab6 3977 {
13602ebd
VZ
3978 currentlyVisibleLines++;
3979 wxListLineData *line = GetLine(i);
3980 line->CalculateSize( &dc, iconSpacing );
3981 line->SetPosition( x, y, iconSpacing );
3982
3983 wxSize sizeLine = GetLineSize(i);
a77ec46d 3984
13602ebd
VZ
3985 if ( maxWidthInThisRow < sizeLine.x )
3986 maxWidthInThisRow = sizeLine.x;
3987
3988 y += sizeLine.y;
3989 if (currentlyVisibleLines > m_linesPerPage)
3990 m_linesPerPage = currentlyVisibleLines;
3991
3992 if ( y + sizeLine.y >= clientHeight )
3993 {
3994 currentlyVisibleLines = 0;
3995 y = EXTRA_BORDER_Y;
3996 maxWidthInThisRow += MARGIN_BETWEEN_ROWS;
3997 x += maxWidthInThisRow;
3998 entireWidth += maxWidthInThisRow;
3999 maxWidthInThisRow = 0;
4000 }
4001
4002 // We have reached the last item.
4003 if ( i == count - 1 )
4004 entireWidth += maxWidthInThisRow;
4005
4006 if ( (tries == 0) &&
4007 (entireWidth + SCROLL_UNIT_X > clientWidth) )
4008 {
4009 clientHeight -= wxSystemSettings::
4010 GetMetric(wxSYS_HSCROLL_Y);
4011 m_linesPerPage = 0;
13602ebd
VZ
4012 break;
4013 }
4014
4015 if ( i == count - 1 )
4016 tries = 1; // Everything fits, no second try required.
4017 }
92976ab6 4018 }
bffa1c77 4019
13602ebd
VZ
4020 SetScrollbars
4021 (
4022 SCROLL_UNIT_X,
6d78bbe6 4023 lineHeight,
13602ebd
VZ
4024 (entireWidth + SCROLL_UNIT_X) / SCROLL_UNIT_X,
4025 0,
4026 GetScrollPos( wxHORIZONTAL ),
4027 0,
4028 TRUE
4029 );
4030 }
e1e955e1 4031 }
cf1dfa6b 4032
34bbbc27
VZ
4033 if ( !noRefresh )
4034 {
4035 // FIXME: why should we call it from here?
4036 UpdateCurrent();
b54e41c5 4037
34bbbc27
VZ
4038 RefreshAll();
4039 }
b54e41c5
VZ
4040}
4041
4042void wxListMainWindow::RefreshAll()
4043{
4044 m_dirty = FALSE;
4045 Refresh();
4046
4047 wxListHeaderWindow *headerWin = GetListCtrl()->m_headerWin;
70541533 4048 if ( headerWin && headerWin->m_dirty )
b54e41c5
VZ
4049 {
4050 headerWin->m_dirty = FALSE;
4051 headerWin->Refresh();
4052 }
e1e955e1 4053}
c801d85f 4054
cf1dfa6b 4055void wxListMainWindow::UpdateCurrent()
c801d85f 4056{
b54e41c5 4057 if ( !HasCurrent() && !IsEmpty() )
92976ab6 4058 {
0ddefeb0 4059 ChangeCurrent(0);
92976ab6 4060 }
e1e955e1 4061}
c801d85f 4062
19695fbd
VZ
4063long wxListMainWindow::GetNextItem( long item,
4064 int WXUNUSED(geometry),
62d89eb4 4065 int state ) const
c801d85f 4066{
d1022fd6
VZ
4067 long ret = item,
4068 max = GetItemCount();
4069 wxCHECK_MSG( (ret == -1) || (ret < max), -1,
13771c08 4070 _T("invalid listctrl index in GetNextItem()") );
19695fbd
VZ
4071
4072 // notice that we start with the next item (or the first one if item == -1)
4073 // and this is intentional to allow writing a simple loop to iterate over
4074 // all selected items
d1022fd6
VZ
4075 ret++;
4076 if ( ret == max )
4077 {
4078 // this is not an error because the index was ok initially, just no
4079 // such item
4080 return -1;
4081 }
4082
cf1dfa6b
VZ
4083 if ( !state )
4084 {
4085 // any will do
4086 return (size_t)ret;
4087 }
4088
4089 size_t count = GetItemCount();
4090 for ( size_t line = (size_t)ret; line < count; line++ )
63852e78 4091 {
cf1dfa6b
VZ
4092 if ( (state & wxLIST_STATE_FOCUSED) && (line == m_current) )
4093 return line;
4094
b54e41c5 4095 if ( (state & wxLIST_STATE_SELECTED) && IsHighlighted(line) )
cf1dfa6b 4096 return line;
63852e78 4097 }
19695fbd 4098
63852e78 4099 return -1;
e1e955e1 4100}
c801d85f 4101
cf1dfa6b
VZ
4102// ----------------------------------------------------------------------------
4103// deleting stuff
4104// ----------------------------------------------------------------------------
4105
b54e41c5 4106void wxListMainWindow::DeleteItem( long lindex )
c801d85f 4107{
cf1dfa6b
VZ
4108 size_t count = GetItemCount();
4109
b54e41c5 4110 wxCHECK_RET( (lindex >= 0) && ((size_t)lindex < count),
cf1dfa6b
VZ
4111 _T("invalid item index in DeleteItem") );
4112
b54e41c5
VZ
4113 size_t index = (size_t)lindex;
4114
d6ddcd57
VZ
4115 // we don't need to adjust the index for the previous items
4116 if ( HasCurrent() && m_current >= index )
cf1dfa6b 4117 {
d6ddcd57
VZ
4118 // if the current item is being deleted, we want the next one to
4119 // become selected - unless there is no next one - so don't adjust
4120 // m_current in this case
4121 if ( m_current != index || m_current == count - 1 )
4122 {
4123 m_current--;
4124 }
cf1dfa6b
VZ
4125 }
4126
938b652b 4127 if ( InReportView() )
63852e78 4128 {
6b4a8d93 4129 ResetVisibleLinesRange();
938b652b
VZ
4130 }
4131
938b652b
VZ
4132 if ( IsVirtual() )
4133 {
4134 m_countVirt--;
b54e41c5
VZ
4135
4136 m_selStore.OnItemDelete(index);
4137 }
4138 else
4139 {
4140 m_lines.RemoveAt( index );
63852e78 4141 }
6b4a8d93 4142
70541533 4143 // we need to refresh the (vert) scrollbar as the number of items changed
b84839ae 4144 m_dirty = TRUE;
91c6cc0e
VZ
4145
4146 SendNotify( index, wxEVT_COMMAND_LIST_DELETE_ITEM );
4147
6b4a8d93 4148 RefreshAfter(index);
e1e955e1 4149}
c801d85f 4150
debe6624 4151void wxListMainWindow::DeleteColumn( int col )
c801d85f 4152{
222ed1d6 4153 wxListHeaderDataList::compatibility_iterator node = m_columns.Item( col );
24b9f055
VZ
4154
4155 wxCHECK_RET( node, wxT("invalid column index in DeleteColumn()") );
bd8289c1 4156
5b077d48 4157 m_dirty = TRUE;
222ed1d6
MB
4158 delete node->GetData();
4159 m_columns.Erase( node );
ae409cb8 4160
df6f82f0
VZ
4161 if ( !IsVirtual() )
4162 {
4163 // update all the items
4164 for ( size_t i = 0; i < m_lines.GetCount(); i++ )
4165 {
4166 wxListLineData * const line = GetLine(i);
222ed1d6
MB
4167 wxListItemDataList::compatibility_iterator n = line->m_items.Item( col );
4168 delete n->GetData();
4169 line->m_items.Erase(n);
df6f82f0
VZ
4170 }
4171 }
4172
ae409cb8
VZ
4173 // invalidate it as it has to be recalculated
4174 m_headerWidth = 0;
e1e955e1 4175}
c801d85f 4176
5fe143df 4177void wxListMainWindow::DoDeleteAllItems()
c801d85f 4178{
cf1dfa6b
VZ
4179 if ( IsEmpty() )
4180 {
4181 // nothing to do - in particular, don't send the event
4182 return;
4183 }
4184
b54e41c5 4185 ResetCurrent();
7c0ea335
VZ
4186
4187 // to make the deletion of all items faster, we don't send the
cf1dfa6b
VZ
4188 // notifications for each item deletion in this case but only one event
4189 // for all of them: this is compatible with wxMSW and documented in
4190 // DeleteAllItems() description
bffa1c77 4191
12c1b46a
RR
4192 wxListEvent event( wxEVT_COMMAND_LIST_DELETE_ALL_ITEMS, GetParent()->GetId() );
4193 event.SetEventObject( GetParent() );
4194 GetParent()->GetEventHandler()->ProcessEvent( event );
7c0ea335 4195
b54e41c5
VZ
4196 if ( IsVirtual() )
4197 {
4198 m_countVirt = 0;
4199
850ed6e7 4200 m_selStore.Clear();
b54e41c5
VZ
4201 }
4202
6b4a8d93
VZ
4203 if ( InReportView() )
4204 {
4205 ResetVisibleLinesRange();
4206 }
4207
5b077d48 4208 m_lines.Clear();
5fe143df 4209}
cf1dfa6b 4210
5fe143df
VZ
4211void wxListMainWindow::DeleteAllItems()
4212{
4213 DoDeleteAllItems();
4214
4215 RecalculatePositions();
e1e955e1 4216}
c801d85f 4217
12c1b46a 4218void wxListMainWindow::DeleteEverything()
c801d85f 4219{
222ed1d6 4220 WX_CLEAR_LIST(wxListHeaderDataList, m_columns);
904ccf52
VZ
4221
4222 DeleteAllItems();
e1e955e1 4223}
c801d85f 4224
cf1dfa6b
VZ
4225// ----------------------------------------------------------------------------
4226// scanning for an item
4227// ----------------------------------------------------------------------------
4228
debe6624 4229void wxListMainWindow::EnsureVisible( long index )
c801d85f 4230{
cf1dfa6b
VZ
4231 wxCHECK_RET( index >= 0 && (size_t)index < GetItemCount(),
4232 _T("invalid index in EnsureVisible") );
4233
4234 // We have to call this here because the label in question might just have
34bbbc27
VZ
4235 // been added and its position is not known yet
4236 if ( m_dirty )
4237 {
34bbbc27
VZ
4238 RecalculatePositions(TRUE /* no refresh */);
4239 }
4240
4241 MoveToItem((size_t)index);
e1e955e1 4242}
c801d85f 4243
debe6624 4244long wxListMainWindow::FindItem(long start, const wxString& str, bool WXUNUSED(partial) )
c801d85f 4245{
5b077d48
RR
4246 long pos = start;
4247 wxString tmp = str;
cf1dfa6b
VZ
4248 if (pos < 0)
4249 pos = 0;
54442116 4250
cf1dfa6b
VZ
4251 size_t count = GetItemCount();
4252 for ( size_t i = (size_t)pos; i < count; i++ )
4253 {
4254 wxListLineData *line = GetLine(i);
4255 if ( line->GetText(0) == tmp )
4256 return i;
5b077d48 4257 }
cf1dfa6b
VZ
4258
4259 return wxNOT_FOUND;
e1e955e1 4260}
c801d85f 4261
debe6624 4262long wxListMainWindow::FindItem(long start, long data)
c801d85f 4263{
5b077d48 4264 long pos = start;
cf1dfa6b
VZ
4265 if (pos < 0)
4266 pos = 0;
4267
4268 size_t count = GetItemCount();
4269 for (size_t i = (size_t)pos; i < count; i++)
5b077d48 4270 {
cf1dfa6b 4271 wxListLineData *line = GetLine(i);
5b077d48
RR
4272 wxListItem item;
4273 line->GetItem( 0, item );
cf1dfa6b
VZ
4274 if (item.m_data == data)
4275 return i;
5b077d48 4276 }
cf1dfa6b
VZ
4277
4278 return wxNOT_FOUND;
e1e955e1 4279}
c801d85f 4280
debe6624 4281long wxListMainWindow::HitTest( int x, int y, int &flags )
c801d85f 4282{
aaef15bf 4283 CalcUnscrolledPosition( x, y, &x, &y );
e8741cca 4284
fc4f1d5f
VZ
4285 size_t count = GetItemCount();
4286
b5d43d1d 4287 if ( InReportView() )
c801d85f 4288 {
5cd89174 4289 size_t current = y / GetLineHeight();
fc4f1d5f
VZ
4290 if ( current < count )
4291 {
4292 flags = HitTestLine(current, x, y);
4293 if ( flags )
4294 return current;
4295 }
5cd89174
VZ
4296 }
4297 else // !report
4298 {
4299 // TODO: optimize it too! this is less simple than for report view but
4300 // enumerating all items is still not a way to do it!!
5cd89174 4301 for ( size_t current = 0; current < count; current++ )
5b077d48 4302 {
5cd89174
VZ
4303 flags = HitTestLine(current, x, y);
4304 if ( flags )
4305 return current;
5b077d48 4306 }
e1e955e1 4307 }
cf1dfa6b
VZ
4308
4309 return wxNOT_FOUND;
e1e955e1 4310}
c801d85f 4311
cf1dfa6b
VZ
4312// ----------------------------------------------------------------------------
4313// adding stuff
4314// ----------------------------------------------------------------------------
4315
c801d85f
KB
4316void wxListMainWindow::InsertItem( wxListItem &item )
4317{
cf1dfa6b
VZ
4318 wxASSERT_MSG( !IsVirtual(), _T("can't be used with virtual control") );
4319
4320 size_t count = GetItemCount();
4321 wxCHECK_RET( item.m_itemId >= 0 && (size_t)item.m_itemId <= count,
4322 _T("invalid item index") );
4323
4324 size_t id = item.m_itemId;
4325
5b077d48 4326 m_dirty = TRUE;
cf1dfa6b 4327
8a39593e
JS
4328 #if 0
4329 // this is unused variable
5b077d48 4330 int mode = 0;
8a39593e 4331 #endif
b5d43d1d 4332 if ( InReportView() )
2b5f62a0 4333 {
8a39593e
JS
4334 #if 0
4335 // this is unused variable
1370703e 4336 mode = wxLC_REPORT;
8a39593e 4337 #endif
2b5f62a0
VZ
4338 ResetVisibleLinesRange();
4339 }
cf1dfa6b 4340 else if ( HasFlag(wxLC_LIST) )
8a39593e
JS
4341 #if 0
4342 // this is unused variable
1370703e 4343 mode = wxLC_LIST;
8a39593e
JS
4344 #else
4345 {}
4346 #endif
cf1dfa6b 4347 else if ( HasFlag(wxLC_ICON) )
8a39593e
JS
4348 #if 0
4349 // this is unused variable
1370703e 4350 mode = wxLC_ICON;
8a39593e
JS
4351 #else
4352 {}
4353 #endif
cf1dfa6b 4354 else if ( HasFlag(wxLC_SMALL_ICON) )
8a39593e
JS
4355 #if 0
4356 // this is unused variable
1370703e 4357 mode = wxLC_ICON; // no typo
8a39593e
JS
4358 #else
4359 {}
4360 #endif
1370703e
VZ
4361 else
4362 {
4363 wxFAIL_MSG( _T("unknown mode") );
4364 }
004fd0c8 4365
5cd89174 4366 wxListLineData *line = new wxListLineData(this);
004fd0c8 4367
5b077d48 4368 line->SetItem( 0, item );
cf1dfa6b
VZ
4369
4370 m_lines.Insert( line, id );
5cd89174 4371
b84839ae 4372 m_dirty = TRUE;
a67e6e54 4373
ab96d680
VZ
4374 // If an item is selected at or below the point of insertion, we need to
4375 // increment the member variables because the current row's index has gone
4376 // up by one
4377 if ( HasCurrent() && m_current >= id )
4378 {
4379 m_current++;
4380 }
4381
a67e6e54
VZ
4382 SendNotify(id, wxEVT_COMMAND_LIST_INSERT_ITEM);
4383
5cd89174 4384 RefreshLines(id, GetItemCount() - 1);
e1e955e1 4385}
c801d85f 4386
debe6624 4387void wxListMainWindow::InsertColumn( long col, wxListItem &item )
c801d85f 4388{
5b077d48 4389 m_dirty = TRUE;
b5d43d1d 4390 if ( InReportView() )
3db7be80 4391 {
54442116
VZ
4392 if (item.m_width == wxLIST_AUTOSIZE_USEHEADER)
4393 item.m_width = GetTextLength( item.m_text );
df6f82f0 4394
5b077d48 4395 wxListHeaderData *column = new wxListHeaderData( item );
df6f82f0
VZ
4396 bool insert = (col >= 0) && ((size_t)col < m_columns.GetCount());
4397 if ( insert )
5b077d48 4398 {
222ed1d6 4399 wxListHeaderDataList::compatibility_iterator node = m_columns.Item( col );
24b9f055 4400 m_columns.Insert( node, column );
5b077d48
RR
4401 }
4402 else
4403 {
4404 m_columns.Append( column );
4405 }
ae409cb8 4406
df6f82f0
VZ
4407 if ( !IsVirtual() )
4408 {
4409 // update all the items
4410 for ( size_t i = 0; i < m_lines.GetCount(); i++ )
4411 {
4412 wxListLineData * const line = GetLine(i);
4413 wxListItemData * const data = new wxListItemData(this);
4414 if ( insert )
4415 line->m_items.Insert(col, data);
4416 else
4417 line->m_items.Append(data);
4418 }
4419 }
4420
ae409cb8
VZ
4421 // invalidate it as it has to be recalculated
4422 m_headerWidth = 0;
3db7be80 4423 }
e1e955e1 4424}
c801d85f 4425
cf1dfa6b
VZ
4426// ----------------------------------------------------------------------------
4427// sorting
4428// ----------------------------------------------------------------------------
4429
c801d85f
KB
4430wxListCtrlCompare list_ctrl_compare_func_2;
4431long list_ctrl_compare_data;
4432
f6bcfd97 4433int LINKAGEMODE list_ctrl_compare_func_1( wxListLineData **arg1, wxListLineData **arg2 )
c801d85f 4434{
f6bcfd97
BP
4435 wxListLineData *line1 = *arg1;
4436 wxListLineData *line2 = *arg2;
5b077d48
RR
4437 wxListItem item;
4438 line1->GetItem( 0, item );
4439 long data1 = item.m_data;
4440 line2->GetItem( 0, item );
4441 long data2 = item.m_data;
4442 return list_ctrl_compare_func_2( data1, data2, list_ctrl_compare_data );
e1e955e1 4443}
c801d85f
KB
4444
4445void wxListMainWindow::SortItems( wxListCtrlCompare fn, long data )
4446{
5b077d48
RR
4447 list_ctrl_compare_func_2 = fn;
4448 list_ctrl_compare_data = data;
4449 m_lines.Sort( list_ctrl_compare_func_1 );
af7c1052 4450 m_dirty = TRUE;
e1e955e1 4451}
c801d85f 4452
cf1dfa6b
VZ
4453// ----------------------------------------------------------------------------
4454// scrolling
4455// ----------------------------------------------------------------------------
4456
7c74e7fe
SC
4457void wxListMainWindow::OnScroll(wxScrollWinEvent& event)
4458{
b54e41c5
VZ
4459 // update our idea of which lines are shown when we redraw the window the
4460 // next time
4461 ResetVisibleLinesRange();
cf1dfa6b 4462
29149a64 4463 // FIXME
3a8c693a 4464#if defined(__WXGTK__) && !defined(__WXUNIVERSAL__)
29149a64
VZ
4465 wxScrolledWindow::OnScroll(event);
4466#else
1e6feb95 4467 HandleOnScroll( event );
29149a64 4468#endif
30954328 4469
cf1dfa6b 4470 if ( event.GetOrientation() == wxHORIZONTAL && HasHeader() )
7c74e7fe 4471 {
3cd94a0d 4472 wxGenericListCtrl* lc = GetListCtrl();
cf1dfa6b
VZ
4473 wxCHECK_RET( lc, _T("no listctrl window?") );
4474
afbe906a
RR
4475 lc->m_headerWin->Refresh();
4476 lc->m_headerWin->Update();
7c74e7fe 4477 }
cf1dfa6b
VZ
4478}
4479
5cd89174
VZ
4480int wxListMainWindow::GetCountPerPage() const
4481{
4482 if ( !m_linesPerPage )
4483 {
4484 wxConstCast(this, wxListMainWindow)->
4485 m_linesPerPage = GetClientSize().y / GetLineHeight();
4486 }
4487
4488 return m_linesPerPage;
4489}
4490
b54e41c5 4491void wxListMainWindow::GetVisibleLinesRange(size_t *from, size_t *to)
cf1dfa6b 4492{
b5d43d1d 4493 wxASSERT_MSG( InReportView(), _T("this is for report mode only") );
cf1dfa6b 4494
b54e41c5
VZ
4495 if ( m_lineFrom == (size_t)-1 )
4496 {
b54e41c5 4497 size_t count = GetItemCount();
6522713c
VZ
4498 if ( count )
4499 {
4500 m_lineFrom = GetScrollPos(wxVERTICAL);
cf1dfa6b 4501
152c57f2
VZ
4502 // this may happen if SetScrollbars() hadn't been called yet
4503 if ( m_lineFrom >= count )
bcc0da5c 4504 m_lineFrom = count - 1;
cf1dfa6b 4505
6522713c
VZ
4506 // we redraw one extra line but this is needed to make the redrawing
4507 // logic work when there is a fractional number of lines on screen
4508 m_lineTo = m_lineFrom + m_linesPerPage;
4509 if ( m_lineTo >= count )
4510 m_lineTo = count - 1;
4511 }
4512 else // empty control
4513 {
4514 m_lineFrom = 0;
4515 m_lineTo = (size_t)-1;
4516 }
cf1dfa6b 4517 }
b54e41c5 4518
ae167d2f
VZ
4519 wxASSERT_MSG( IsEmpty() ||
4520 (m_lineFrom <= m_lineTo && m_lineTo < GetItemCount()),
6b4a8d93
VZ
4521 _T("GetVisibleLinesRange() returns incorrect result") );
4522
b54e41c5
VZ
4523 if ( from )
4524 *from = m_lineFrom;
4525 if ( to )
4526 *to = m_lineTo;
7c74e7fe
SC
4527}
4528
c801d85f 4529// -------------------------------------------------------------------------------------
3cd94a0d 4530// wxGenericListCtrl
c801d85f
KB
4531// -------------------------------------------------------------------------------------
4532
3cd94a0d
JS
4533IMPLEMENT_DYNAMIC_CLASS(wxGenericListCtrl, wxControl)
4534
3cd94a0d
JS
4535BEGIN_EVENT_TABLE(wxGenericListCtrl,wxControl)
4536 EVT_SIZE(wxGenericListCtrl::OnSize)
c801d85f
KB
4537END_EVENT_TABLE()
4538
3cd94a0d 4539wxGenericListCtrl::wxGenericListCtrl()
c801d85f 4540{
80020b62
JS
4541 m_imageListNormal = (wxImageListType *) NULL;
4542 m_imageListSmall = (wxImageListType *) NULL;
4543 m_imageListState = (wxImageListType *) NULL;
cf1dfa6b
VZ
4544
4545 m_ownsImageListNormal =
4546 m_ownsImageListSmall =
4547 m_ownsImageListState = FALSE;
4548
5b077d48
RR
4549 m_mainWin = (wxListMainWindow*) NULL;
4550 m_headerWin = (wxListHeaderWindow*) NULL;
f8252483 4551 m_headerHeight = 0;
c801d85f
KB
4552}
4553
3cd94a0d 4554wxGenericListCtrl::~wxGenericListCtrl()
c801d85f 4555{
cf1dfa6b
VZ
4556 if (m_ownsImageListNormal)
4557 delete m_imageListNormal;
4558 if (m_ownsImageListSmall)
4559 delete m_imageListSmall;
4560 if (m_ownsImageListState)
4561 delete m_imageListState;
4562}
4563
f8252483
JS
4564void wxGenericListCtrl::CalculateAndSetHeaderHeight()
4565{
86351e4a
VZ
4566 if ( m_headerWin )
4567 {
4568 // we use 'g' to get the descent, too
4569 int w, h, d;
4570 m_headerWin->GetTextExtent(wxT("Hg"), &w, &h, &d);
4571 h += d + 2 * HEADER_OFFSET_Y + EXTRA_HEIGHT;
4572
8b1ed8d9
VZ
4573 // only update if changed
4574 if ( h != m_headerHeight )
86351e4a
VZ
4575 {
4576 m_headerHeight = h;
4577
4578 m_headerWin->SetSize(m_headerWin->GetSize().x, m_headerHeight);
4579
b5d43d1d 4580 if ( HasHeader() )
86351e4a
VZ
4581 ResizeReportView(TRUE);
4582 }
4583 }
f8252483
JS
4584}
4585
3cd94a0d 4586void wxGenericListCtrl::CreateHeaderWindow()
cf1dfa6b
VZ
4587{
4588 m_headerWin = new wxListHeaderWindow
4589 (
4590 this, -1, m_mainWin,
4591 wxPoint(0, 0),
f8252483 4592 wxSize(GetClientSize().x, m_headerHeight),
cf1dfa6b
VZ
4593 wxTAB_TRAVERSAL
4594 );
f8252483 4595 CalculateAndSetHeaderHeight();
c801d85f
KB
4596}
4597
3cd94a0d 4598bool wxGenericListCtrl::Create(wxWindow *parent,
25e3a937
VZ
4599 wxWindowID id,
4600 const wxPoint &pos,
4601 const wxSize &size,
4602 long style,
25e3a937 4603 const wxValidator &validator,
25e3a937 4604 const wxString &name)
c801d85f 4605{
cf1dfa6b
VZ
4606 m_imageListNormal =
4607 m_imageListSmall =
80020b62 4608 m_imageListState = (wxImageListType *) NULL;
cf1dfa6b
VZ
4609 m_ownsImageListNormal =
4610 m_ownsImageListSmall =
4611 m_ownsImageListState = FALSE;
4612
5b077d48
RR
4613 m_mainWin = (wxListMainWindow*) NULL;
4614 m_headerWin = (wxListHeaderWindow*) NULL;
bd8289c1 4615
3fc93ebd
JS
4616 m_headerHeight = 0;
4617
b54e41c5 4618 if ( !(style & wxLC_MASK_TYPE) )
5b077d48 4619 {
25e3a937 4620 style = style | wxLC_LIST;
5b077d48 4621 }
f6bcfd97 4622
07215d86 4623 if ( !wxControl::Create( parent, id, pos, size, style, validator, name ) )
cf1dfa6b 4624 return FALSE;
f6bcfd97 4625
b54e41c5 4626 // don't create the inner window with the border
6d460f76 4627 style &= ~wxBORDER_MASK;
bd8289c1 4628
25e3a937 4629 m_mainWin = new wxListMainWindow( this, -1, wxPoint(0,0), size, style );
bd8289c1 4630
f89d65ea
SC
4631#if defined( __WXMAC__ ) && __WXMAC_CARBON__
4632 wxFont font ;
4633 font.MacCreateThemeFont( kThemeViewsFont ) ;
4634 SetFont( font ) ;
4635#endif
b5d43d1d 4636 if ( InReportView() )
ea451729 4637 {
cf1dfa6b
VZ
4638 CreateHeaderWindow();
4639
b54e41c5 4640 if ( HasFlag(wxLC_NO_HEADER) )
cf1dfa6b
VZ
4641 {
4642 // VZ: why do we create it at all then?
ea451729 4643 m_headerWin->Show( FALSE );
cf1dfa6b 4644 }
ea451729 4645 }
bd8289c1 4646
35d4c967
RD
4647 SetBestSize(size);
4648
cf1dfa6b 4649 return TRUE;
e1e955e1 4650}
c801d85f 4651
3cd94a0d 4652void wxGenericListCtrl::SetSingleStyle( long style, bool add )
c801d85f 4653{
b54e41c5
VZ
4654 wxASSERT_MSG( !(style & wxLC_VIRTUAL),
4655 _T("wxLC_VIRTUAL can't be [un]set") );
4656
f03fc89f 4657 long flag = GetWindowStyle();
bd8289c1 4658
5b077d48
RR
4659 if (add)
4660 {
cf1dfa6b 4661 if (style & wxLC_MASK_TYPE)
b54e41c5 4662 flag &= ~(wxLC_MASK_TYPE | wxLC_VIRTUAL);
cf1dfa6b
VZ
4663 if (style & wxLC_MASK_ALIGN)
4664 flag &= ~wxLC_MASK_ALIGN;
4665 if (style & wxLC_MASK_SORT)
4666 flag &= ~wxLC_MASK_SORT;
5b077d48 4667 }
c801d85f 4668
5b077d48
RR
4669 if (add)
4670 {
4671 flag |= style;
4672 }
4673 else
4674 {
cf1dfa6b 4675 flag &= ~style;
5b077d48 4676 }
bd8289c1 4677
5b077d48 4678 SetWindowStyleFlag( flag );
e1e955e1 4679}
c801d85f 4680
3cd94a0d 4681void wxGenericListCtrl::SetWindowStyleFlag( long flag )
c801d85f 4682{
121a3581
RR
4683 if (m_mainWin)
4684 {
4685 m_mainWin->DeleteEverything();
c801d85f 4686
a95cdab8 4687 // has the header visibility changed?
b5d43d1d
VZ
4688 bool hasHeader = HasHeader();
4689 bool willHaveHeader = (flag & wxLC_REPORT) && !(flag & wxLC_NO_HEADER);
c801d85f 4690
a95cdab8 4691 if ( hasHeader != willHaveHeader )
5b077d48 4692 {
a95cdab8
VZ
4693 // toggle it
4694 if ( hasHeader )
4695 {
4696 if ( m_headerWin )
4697 {
4698 // don't delete, just hide, as we can reuse it later
4699 m_headerWin->Show(FALSE);
4700 }
4701 //else: nothing to do
4702 }
4703 else // must show header
5b077d48 4704 {
121a3581
RR
4705 if (!m_headerWin)
4706 {
cf1dfa6b 4707 CreateHeaderWindow();
121a3581 4708 }
a95cdab8 4709 else // already have it, just show
004fd0c8 4710 {
a95cdab8 4711 m_headerWin->Show( TRUE );
004fd0c8 4712 }
5b077d48 4713 }
a95cdab8
VZ
4714
4715 ResizeReportView(willHaveHeader);
bffa1c77 4716 }
e1e955e1 4717 }
004fd0c8 4718
5b077d48 4719 wxWindow::SetWindowStyleFlag( flag );
e1e955e1 4720}
c801d85f 4721
3cd94a0d 4722bool wxGenericListCtrl::GetColumn(int col, wxListItem &item) const
c801d85f 4723{
5b077d48
RR
4724 m_mainWin->GetColumn( col, item );
4725 return TRUE;
e1e955e1 4726}
c801d85f 4727
3cd94a0d 4728bool wxGenericListCtrl::SetColumn( int col, wxListItem& item )
c801d85f 4729{
5b077d48
RR
4730 m_mainWin->SetColumn( col, item );
4731 return TRUE;
e1e955e1 4732}
c801d85f 4733
3cd94a0d 4734int wxGenericListCtrl::GetColumnWidth( int col ) const
c801d85f 4735{
5b077d48 4736 return m_mainWin->GetColumnWidth( col );
e1e955e1 4737}
c801d85f 4738
3cd94a0d 4739bool wxGenericListCtrl::SetColumnWidth( int col, int width )
c801d85f 4740{
5b077d48
RR
4741 m_mainWin->SetColumnWidth( col, width );
4742 return TRUE;
e1e955e1 4743}
c801d85f 4744
3cd94a0d 4745int wxGenericListCtrl::GetCountPerPage() const
c801d85f
KB
4746{
4747 return m_mainWin->GetCountPerPage(); // different from Windows ?
e1e955e1 4748}
c801d85f 4749
3cd94a0d 4750bool wxGenericListCtrl::GetItem( wxListItem &info ) const
c801d85f 4751{
5b077d48
RR
4752 m_mainWin->GetItem( info );
4753 return TRUE;
e1e955e1 4754}
c801d85f 4755
3cd94a0d 4756bool wxGenericListCtrl::SetItem( wxListItem &info )
c801d85f 4757{
5b077d48
RR
4758 m_mainWin->SetItem( info );
4759 return TRUE;
e1e955e1 4760}
c801d85f 4761
3cd94a0d 4762long wxGenericListCtrl::SetItem( long index, int col, const wxString& label, int imageId )
c801d85f 4763{
5b077d48
RR
4764 wxListItem info;
4765 info.m_text = label;
4766 info.m_mask = wxLIST_MASK_TEXT;
4767 info.m_itemId = index;
4768 info.m_col = col;
4769 if ( imageId > -1 )
4770 {
4771 info.m_image = imageId;
4772 info.m_mask |= wxLIST_MASK_IMAGE;
4773 };
4774 m_mainWin->SetItem(info);
4775 return TRUE;
e1e955e1 4776}
c801d85f 4777
3cd94a0d 4778int wxGenericListCtrl::GetItemState( long item, long stateMask ) const
c801d85f 4779{
5b077d48 4780 return m_mainWin->GetItemState( item, stateMask );
e1e955e1 4781}
c801d85f 4782
3cd94a0d 4783bool wxGenericListCtrl::SetItemState( long item, long state, long stateMask )
c801d85f 4784{
5b077d48
RR
4785 m_mainWin->SetItemState( item, state, stateMask );
4786 return TRUE;
e1e955e1 4787}
c801d85f 4788
3cd94a0d 4789bool wxGenericListCtrl::SetItemImage( long item, int image, int WXUNUSED(selImage) )
c801d85f 4790{
5b077d48
RR
4791 wxListItem info;
4792 info.m_image = image;
4793 info.m_mask = wxLIST_MASK_IMAGE;
4794 info.m_itemId = item;
4795 m_mainWin->SetItem( info );
4796 return TRUE;
e1e955e1 4797}
c801d85f 4798
3cd94a0d 4799wxString wxGenericListCtrl::GetItemText( long item ) const
c801d85f 4800{
62d89eb4 4801 return m_mainWin->GetItemText(item);
e1e955e1 4802}
c801d85f 4803
3cd94a0d 4804void wxGenericListCtrl::SetItemText( long item, const wxString& str )
c801d85f 4805{
62d89eb4 4806 m_mainWin->SetItemText(item, str);
e1e955e1 4807}
c801d85f 4808
3cd94a0d 4809long wxGenericListCtrl::GetItemData( long item ) const
c801d85f 4810{
5b077d48
RR
4811 wxListItem info;
4812 info.m_itemId = item;
4813 m_mainWin->GetItem( info );
4814 return info.m_data;
e1e955e1 4815}
c801d85f 4816
3cd94a0d 4817bool wxGenericListCtrl::SetItemData( long item, long data )
c801d85f 4818{
5b077d48
RR
4819 wxListItem info;
4820 info.m_mask = wxLIST_MASK_DATA;
4821 info.m_itemId = item;
4822 info.m_data = data;
4823 m_mainWin->SetItem( info );
4824 return TRUE;
e1e955e1 4825}
c801d85f 4826
11ebea16
VZ
4827wxRect wxGenericListCtrl::GetViewRect() const
4828{
4829 return m_mainWin->GetViewRect();
4830}
4831
3cd94a0d 4832bool wxGenericListCtrl::GetItemRect( long item, wxRect &rect, int WXUNUSED(code) ) const
c801d85f 4833{
5b077d48 4834 m_mainWin->GetItemRect( item, rect );
7e6874c0 4835 if ( m_mainWin->HasHeader() )
f8252483 4836 rect.y += m_headerHeight + 1;
5b077d48 4837 return TRUE;
e1e955e1 4838}
c801d85f 4839
3cd94a0d 4840bool wxGenericListCtrl::GetItemPosition( long item, wxPoint& pos ) const
c801d85f 4841{
5b077d48
RR
4842 m_mainWin->GetItemPosition( item, pos );
4843 return TRUE;
e1e955e1 4844}
c801d85f 4845
3cd94a0d 4846bool wxGenericListCtrl::SetItemPosition( long WXUNUSED(item), const wxPoint& WXUNUSED(pos) )
c801d85f 4847{
5b077d48 4848 return 0;
e1e955e1 4849}
c801d85f 4850
3cd94a0d 4851int wxGenericListCtrl::GetItemCount() const
c801d85f 4852{
5b077d48 4853 return m_mainWin->GetItemCount();
e1e955e1 4854}
c801d85f 4855
3cd94a0d 4856int wxGenericListCtrl::GetColumnCount() const
92976ab6 4857{
5b077d48 4858 return m_mainWin->GetColumnCount();
92976ab6
RR
4859}
4860
3cd94a0d 4861void wxGenericListCtrl::SetItemSpacing( int spacing, bool isSmall )
33d0b396 4862{
5b077d48 4863 m_mainWin->SetItemSpacing( spacing, isSmall );
e1e955e1 4864}
33d0b396 4865
5db8d758
VZ
4866wxSize wxGenericListCtrl::GetItemSpacing() const
4867{
f58fc140 4868 const int spacing = m_mainWin->GetItemSpacing(HasFlag(wxLC_SMALL_ICON));
5db8d758
VZ
4869
4870 return wxSize(spacing, spacing);
4871}
4872
3cd94a0d 4873int wxGenericListCtrl::GetItemSpacing( bool isSmall ) const
c801d85f 4874{
5b077d48 4875 return m_mainWin->GetItemSpacing( isSmall );
e1e955e1 4876}
c801d85f 4877
3cd94a0d 4878void wxGenericListCtrl::SetItemTextColour( long item, const wxColour &col )
5b98eb2f
RL
4879{
4880 wxListItem info;
4881 info.m_itemId = item;
4882 info.SetTextColour( col );
4883 m_mainWin->SetItem( info );
4884}
4885
3cd94a0d 4886wxColour wxGenericListCtrl::GetItemTextColour( long item ) const
5b98eb2f
RL
4887{
4888 wxListItem info;
4889 info.m_itemId = item;
4890 m_mainWin->GetItem( info );
4891 return info.GetTextColour();
4892}
4893
3cd94a0d 4894void wxGenericListCtrl::SetItemBackgroundColour( long item, const wxColour &col )
5b98eb2f
RL
4895{
4896 wxListItem info;
4897 info.m_itemId = item;
4898 info.SetBackgroundColour( col );
4899 m_mainWin->SetItem( info );
4900}
4901
3cd94a0d 4902wxColour wxGenericListCtrl::GetItemBackgroundColour( long item ) const
5b98eb2f
RL
4903{
4904 wxListItem info;
4905 info.m_itemId = item;
4906 m_mainWin->GetItem( info );
4907 return info.GetBackgroundColour();
4908}
4909
3cd94a0d 4910int wxGenericListCtrl::GetSelectedItemCount() const
c801d85f 4911{
5b077d48 4912 return m_mainWin->GetSelectedItemCount();
e1e955e1 4913}
c801d85f 4914
3cd94a0d 4915wxColour wxGenericListCtrl::GetTextColour() const
c801d85f 4916{
0530737d 4917 return GetForegroundColour();
e1e955e1 4918}
c801d85f 4919
3cd94a0d 4920void wxGenericListCtrl::SetTextColour(const wxColour& col)
c801d85f 4921{
0530737d 4922 SetForegroundColour(col);
e1e955e1 4923}
c801d85f 4924
3cd94a0d 4925long wxGenericListCtrl::GetTopItem() const
c801d85f 4926{
2b5f62a0
VZ
4927 size_t top;
4928 m_mainWin->GetVisibleLinesRange(&top, NULL);
4929 return (long)top;
e1e955e1 4930}
c801d85f 4931
3cd94a0d 4932long wxGenericListCtrl::GetNextItem( long item, int geom, int state ) const
c801d85f 4933{
5b077d48 4934 return m_mainWin->GetNextItem( item, geom, state );
e1e955e1 4935}
c801d85f 4936
80020b62 4937wxImageListType *wxGenericListCtrl::GetImageList(int which) const
c801d85f 4938{
5b077d48
RR
4939 if (which == wxIMAGE_LIST_NORMAL)
4940 {
4941 return m_imageListNormal;
4942 }
4943 else if (which == wxIMAGE_LIST_SMALL)
4944 {
4945 return m_imageListSmall;
4946 }
4947 else if (which == wxIMAGE_LIST_STATE)
4948 {
4949 return m_imageListState;
4950 }
80020b62 4951 return (wxImageListType *) NULL;
e1e955e1 4952}
c801d85f 4953
80020b62 4954void wxGenericListCtrl::SetImageList( wxImageListType *imageList, int which )
c801d85f 4955{
2e12c11a
VS
4956 if ( which == wxIMAGE_LIST_NORMAL )
4957 {
4958 if (m_ownsImageListNormal) delete m_imageListNormal;
4959 m_imageListNormal = imageList;
4960 m_ownsImageListNormal = FALSE;
4961 }
4962 else if ( which == wxIMAGE_LIST_SMALL )
4963 {
4964 if (m_ownsImageListSmall) delete m_imageListSmall;
4965 m_imageListSmall = imageList;
4966 m_ownsImageListSmall = FALSE;
4967 }
4968 else if ( which == wxIMAGE_LIST_STATE )
4969 {
4970 if (m_ownsImageListState) delete m_imageListState;
4971 m_imageListState = imageList;
4972 m_ownsImageListState = FALSE;
4973 }
4974
5b077d48 4975 m_mainWin->SetImageList( imageList, which );
e1e955e1 4976}
c801d85f 4977
80020b62 4978void wxGenericListCtrl::AssignImageList(wxImageListType *imageList, int which)
2e12c11a
VS
4979{
4980 SetImageList(imageList, which);
4981 if ( which == wxIMAGE_LIST_NORMAL )
4982 m_ownsImageListNormal = TRUE;
4983 else if ( which == wxIMAGE_LIST_SMALL )
4984 m_ownsImageListSmall = TRUE;
4985 else if ( which == wxIMAGE_LIST_STATE )
4986 m_ownsImageListState = TRUE;
4987}
4988
3cd94a0d 4989bool wxGenericListCtrl::Arrange( int WXUNUSED(flag) )
c801d85f 4990{
5b077d48 4991 return 0;
e1e955e1 4992}
c801d85f 4993
3cd94a0d 4994bool wxGenericListCtrl::DeleteItem( long item )
c801d85f 4995{
5b077d48
RR
4996 m_mainWin->DeleteItem( item );
4997 return TRUE;
e1e955e1 4998}
c801d85f 4999
3cd94a0d 5000bool wxGenericListCtrl::DeleteAllItems()
c801d85f 5001{
5b077d48
RR
5002 m_mainWin->DeleteAllItems();
5003 return TRUE;
e1e955e1 5004}
c801d85f 5005
3cd94a0d 5006bool wxGenericListCtrl::DeleteAllColumns()
bd8289c1 5007{
24b9f055
VZ
5008 size_t count = m_mainWin->m_columns.GetCount();
5009 for ( size_t n = 0; n < count; n++ )
85cdcb7a 5010 DeleteColumn(0);
bffa1c77 5011
5b077d48 5012 return TRUE;
4f22cf8d
RR
5013}
5014
3cd94a0d 5015void wxGenericListCtrl::ClearAll()
4f22cf8d 5016{
5b077d48 5017 m_mainWin->DeleteEverything();
bd8289c1
VZ
5018}
5019
3cd94a0d 5020bool wxGenericListCtrl::DeleteColumn( int col )
c801d85f 5021{
5b077d48 5022 m_mainWin->DeleteColumn( col );
40c08808
VZ
5023
5024 // if we don't have the header any longer, we need to relayout the window
5025 if ( !GetColumnCount() )
5026 {
5027 ResizeReportView(FALSE /* no header */);
5028 }
5029
5b077d48 5030 return TRUE;
e1e955e1 5031}
c801d85f 5032
3cd94a0d 5033void wxGenericListCtrl::Edit( long item )
c801d85f 5034{
cf1dfa6b 5035 m_mainWin->EditLabel( item );
e1e955e1 5036}
c801d85f 5037
3cd94a0d 5038bool wxGenericListCtrl::EnsureVisible( long item )
c801d85f 5039{
5b077d48
RR
5040 m_mainWin->EnsureVisible( item );
5041 return TRUE;
e1e955e1 5042}
c801d85f 5043
3cd94a0d 5044long wxGenericListCtrl::FindItem( long start, const wxString& str, bool partial )
c801d85f 5045{
5b077d48 5046 return m_mainWin->FindItem( start, str, partial );
e1e955e1 5047}
c801d85f 5048
3cd94a0d 5049long wxGenericListCtrl::FindItem( long start, long data )
c801d85f 5050{
5b077d48 5051 return m_mainWin->FindItem( start, data );
e1e955e1 5052}
c801d85f 5053
3cd94a0d 5054long wxGenericListCtrl::FindItem( long WXUNUSED(start), const wxPoint& WXUNUSED(pt),
debe6624 5055 int WXUNUSED(direction))
c801d85f 5056{
5b077d48 5057 return 0;
e1e955e1 5058}
c801d85f 5059
3cd94a0d 5060long wxGenericListCtrl::HitTest( const wxPoint &point, int &flags )
c801d85f 5061{
5b077d48 5062 return m_mainWin->HitTest( (int)point.x, (int)point.y, flags );
e1e955e1 5063}
c801d85f 5064
3cd94a0d 5065long wxGenericListCtrl::InsertItem( wxListItem& info )
c801d85f 5066{
5b077d48 5067 m_mainWin->InsertItem( info );
2ebcd5f5 5068 return info.m_itemId;
e1e955e1 5069}
c801d85f 5070
3cd94a0d 5071long wxGenericListCtrl::InsertItem( long index, const wxString &label )
c801d85f 5072{
51cc4dad
RR
5073 wxListItem info;
5074 info.m_text = label;
5075 info.m_mask = wxLIST_MASK_TEXT;
5076 info.m_itemId = index;
5077 return InsertItem( info );
e1e955e1 5078}
c801d85f 5079
3cd94a0d 5080long wxGenericListCtrl::InsertItem( long index, int imageIndex )
c801d85f 5081{
51cc4dad
RR
5082 wxListItem info;
5083 info.m_mask = wxLIST_MASK_IMAGE;
5084 info.m_image = imageIndex;
5085 info.m_itemId = index;
5086 return InsertItem( info );
e1e955e1 5087}
c801d85f 5088
3cd94a0d 5089long wxGenericListCtrl::InsertItem( long index, const wxString &label, int imageIndex )
c801d85f 5090{
51cc4dad
RR
5091 wxListItem info;
5092 info.m_text = label;
5093 info.m_image = imageIndex;
5094 info.m_mask = wxLIST_MASK_TEXT | wxLIST_MASK_IMAGE;
5095 info.m_itemId = index;
5096 return InsertItem( info );
e1e955e1 5097}
c801d85f 5098
3cd94a0d 5099long wxGenericListCtrl::InsertColumn( long col, wxListItem &item )
c801d85f 5100{
40c08808
VZ
5101 wxCHECK_MSG( m_headerWin, -1, _T("can't add column in non report mode") );
5102
51cc4dad 5103 m_mainWin->InsertColumn( col, item );
40c08808
VZ
5104
5105 // if we hadn't had header before and have it now we need to relayout the
5106 // window
ac53090c 5107 if ( GetColumnCount() == 1 && m_mainWin->HasHeader() )
40c08808
VZ
5108 {
5109 ResizeReportView(TRUE /* have header */);
5110 }
5111
d3e90957 5112 m_headerWin->Refresh();
25e3a937 5113
51cc4dad 5114 return 0;
e1e955e1 5115}
c801d85f 5116
3cd94a0d 5117long wxGenericListCtrl::InsertColumn( long col, const wxString &heading,
debe6624 5118 int format, int width )
c801d85f 5119{
51cc4dad
RR
5120 wxListItem item;
5121 item.m_mask = wxLIST_MASK_TEXT | wxLIST_MASK_FORMAT;
5122 item.m_text = heading;
5123 if (width >= -2)
5124 {
5125 item.m_mask |= wxLIST_MASK_WIDTH;
5126 item.m_width = width;
5127 }
5128 item.m_format = format;
c801d85f 5129
51cc4dad 5130 return InsertColumn( col, item );
e1e955e1 5131}
c801d85f 5132
3cd94a0d 5133bool wxGenericListCtrl::ScrollList( int WXUNUSED(dx), int WXUNUSED(dy) )
c801d85f 5134{
51cc4dad 5135 return 0;
e1e955e1 5136}
c801d85f
KB
5137
5138// Sort items.
5139// fn is a function which takes 3 long arguments: item1, item2, data.
5140// item1 is the long data associated with a first item (NOT the index).
5141// item2 is the long data associated with a second item (NOT the index).
5142// data is the same value as passed to SortItems.
5143// The return value is a negative number if the first item should precede the second
5144// item, a positive number of the second item should precede the first,
5145// or zero if the two items are equivalent.
5146// data is arbitrary data to be passed to the sort function.
5147
3cd94a0d 5148bool wxGenericListCtrl::SortItems( wxListCtrlCompare fn, long data )
c801d85f 5149{
51cc4dad
RR
5150 m_mainWin->SortItems( fn, data );
5151 return TRUE;
e1e955e1 5152}
c801d85f 5153
cf1dfa6b 5154// ----------------------------------------------------------------------------
b54e41c5 5155// event handlers
cf1dfa6b
VZ
5156// ----------------------------------------------------------------------------
5157
3cd94a0d 5158void wxGenericListCtrl::OnSize(wxSizeEvent& WXUNUSED(event))
53010e52 5159{
b54e41c5 5160 if ( !m_mainWin )
cf1dfa6b 5161 return;
53010e52 5162
a95cdab8
VZ
5163 ResizeReportView(m_mainWin->HasHeader());
5164
5165 m_mainWin->RecalculatePositions();
5166}
5167
3cd94a0d 5168void wxGenericListCtrl::ResizeReportView(bool showHeader)
a95cdab8 5169{
b54e41c5 5170 int cw, ch;
51cc4dad 5171 GetClientSize( &cw, &ch );
bd8289c1 5172
a95cdab8 5173 if ( showHeader )
51cc4dad 5174 {
f8252483
JS
5175 m_headerWin->SetSize( 0, 0, cw, m_headerHeight );
5176 m_mainWin->SetSize( 0, m_headerHeight + 1, cw, ch - m_headerHeight - 1 );
51cc4dad 5177 }
cf1dfa6b 5178 else // no header window
51cc4dad 5179 {
cf1dfa6b 5180 m_mainWin->SetSize( 0, 0, cw, ch );
51cc4dad 5181 }
b54e41c5 5182}
cf1dfa6b 5183
5180055b 5184void wxGenericListCtrl::OnInternalIdle()
b54e41c5 5185{
5180055b 5186 wxWindow::OnInternalIdle();
86351e4a 5187
b54e41c5
VZ
5188 // do it only if needed
5189 if ( !m_mainWin->m_dirty )
5190 return;
5191
5192 m_mainWin->RecalculatePositions();
e1e955e1 5193}
53010e52 5194
cf1dfa6b
VZ
5195// ----------------------------------------------------------------------------
5196// font/colours
5197// ----------------------------------------------------------------------------
5198
3cd94a0d 5199bool wxGenericListCtrl::SetBackgroundColour( const wxColour &colour )
bd8289c1 5200{
51cc4dad
RR
5201 if (m_mainWin)
5202 {
5203 m_mainWin->SetBackgroundColour( colour );
5204 m_mainWin->m_dirty = TRUE;
5205 }
004fd0c8 5206
f03fc89f 5207 return TRUE;
e4d06860
RR
5208}
5209
3cd94a0d 5210bool wxGenericListCtrl::SetForegroundColour( const wxColour &colour )
bd8289c1 5211{
f03fc89f
VZ
5212 if ( !wxWindow::SetForegroundColour( colour ) )
5213 return FALSE;
004fd0c8 5214
51cc4dad
RR
5215 if (m_mainWin)
5216 {
5217 m_mainWin->SetForegroundColour( colour );
5218 m_mainWin->m_dirty = TRUE;
5219 }
004fd0c8 5220
51cc4dad
RR
5221 if (m_headerWin)
5222 {
5223 m_headerWin->SetForegroundColour( colour );
5224 }
f03fc89f
VZ
5225
5226 return TRUE;
e4d06860 5227}
bd8289c1 5228
3cd94a0d 5229bool wxGenericListCtrl::SetFont( const wxFont &font )
bd8289c1 5230{
f03fc89f
VZ
5231 if ( !wxWindow::SetFont( font ) )
5232 return FALSE;
004fd0c8 5233
51cc4dad
RR
5234 if (m_mainWin)
5235 {
5236 m_mainWin->SetFont( font );
5237 m_mainWin->m_dirty = TRUE;
5238 }
004fd0c8 5239
51cc4dad
RR
5240 if (m_headerWin)
5241 {
5242 m_headerWin->SetFont( font );
f8252483 5243 CalculateAndSetHeaderHeight();
51cc4dad 5244 }
f03fc89f 5245
f8252483
JS
5246 Refresh();
5247
f03fc89f 5248 return TRUE;
e4d06860 5249}
c801d85f 5250
35d4c967 5251
35d4c967 5252
944b1f5e 5253#if _USE_VISATTR
35d4c967 5254#include "wx/listbox.h"
944b1f5e 5255#endif
35d4c967
RD
5256
5257//static
5258wxVisualAttributes
5259wxGenericListCtrl::GetClassDefaultAttributes(wxWindowVariant variant)
5260{
5261#if _USE_VISATTR
5262 // Use the same color scheme as wxListBox
5263 return wxListBox::GetClassDefaultAttributes(variant);
5264#else
e7045784 5265 wxUnusedVar(variant);
35d4c967
RD
5266 wxVisualAttributes attr;
5267 attr.colFg = wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT);
5268 attr.colBg = wxSystemSettings::GetColour(wxSYS_COLOUR_LISTBOX);
5269 attr.font = wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT);
5270 return attr;
5271#endif
5272}
5273
cf1dfa6b
VZ
5274// ----------------------------------------------------------------------------
5275// methods forwarded to m_mainWin
5276// ----------------------------------------------------------------------------
5277
efbb7287
VZ
5278#if wxUSE_DRAG_AND_DROP
5279
3cd94a0d 5280void wxGenericListCtrl::SetDropTarget( wxDropTarget *dropTarget )
efbb7287
VZ
5281{
5282 m_mainWin->SetDropTarget( dropTarget );
5283}
5284
3cd94a0d 5285wxDropTarget *wxGenericListCtrl::GetDropTarget() const
efbb7287
VZ
5286{
5287 return m_mainWin->GetDropTarget();
5288}
5289
5290#endif // wxUSE_DRAG_AND_DROP
5291
3cd94a0d 5292bool wxGenericListCtrl::SetCursor( const wxCursor &cursor )
efbb7287
VZ
5293{
5294 return m_mainWin ? m_mainWin->wxWindow::SetCursor(cursor) : FALSE;
5295}
5296
3cd94a0d 5297wxColour wxGenericListCtrl::GetBackgroundColour() const
efbb7287
VZ
5298{
5299 return m_mainWin ? m_mainWin->GetBackgroundColour() : wxColour();
5300}
5301
3cd94a0d 5302wxColour wxGenericListCtrl::GetForegroundColour() const
efbb7287
VZ
5303{
5304 return m_mainWin ? m_mainWin->GetForegroundColour() : wxColour();
5305}
5306
3cd94a0d 5307bool wxGenericListCtrl::DoPopupMenu( wxMenu *menu, int x, int y )
efbb7287 5308{
3a8c693a 5309#if wxUSE_MENUS
efbb7287 5310 return m_mainWin->PopupMenu( menu, x, y );
3a8c693a
VZ
5311#else
5312 return FALSE;
5313#endif // wxUSE_MENUS
efbb7287
VZ
5314}
5315
3cd94a0d 5316void wxGenericListCtrl::SetFocus()
efbb7287
VZ
5317{
5318 /* The test in window.cpp fails as we are a composite
5319 window, so it checks against "this", but not m_mainWin. */
5320 if ( FindFocus() != this )
5321 m_mainWin->SetFocus();
5322}
1e6feb95 5323
2c1f73ee
VZ
5324// ----------------------------------------------------------------------------
5325// virtual list control support
5326// ----------------------------------------------------------------------------
5327
3cd94a0d 5328wxString wxGenericListCtrl::OnGetItemText(long WXUNUSED(item), long WXUNUSED(col)) const
2c1f73ee
VZ
5329{
5330 // this is a pure virtual function, in fact - which is not really pure
5331 // because the controls which are not virtual don't need to implement it
3cd94a0d 5332 wxFAIL_MSG( _T("wxGenericListCtrl::OnGetItemText not supposed to be called") );
2c1f73ee
VZ
5333
5334 return wxEmptyString;
5335}
5336
3cd94a0d 5337int wxGenericListCtrl::OnGetItemImage(long WXUNUSED(item)) const
2c1f73ee
VZ
5338{
5339 // same as above
3cd94a0d 5340 wxFAIL_MSG( _T("wxGenericListCtrl::OnGetItemImage not supposed to be called") );
2c1f73ee
VZ
5341
5342 return -1;
5343}
5344
999836aa
VZ
5345wxListItemAttr *
5346wxGenericListCtrl::OnGetItemAttr(long WXUNUSED_UNLESS_DEBUG(item)) const
6c02c329
VZ
5347{
5348 wxASSERT_MSG( item >= 0 && item < GetItemCount(),
5349 _T("invalid item index in OnGetItemAttr()") );
5350
5351 // no attributes by default
5352 return NULL;
5353}
5354
3cd94a0d 5355void wxGenericListCtrl::SetItemCount(long count)
2c1f73ee
VZ
5356{
5357 wxASSERT_MSG( IsVirtual(), _T("this is for virtual controls only") );
5358
5359 m_mainWin->SetItemCount(count);
5360}
5361
3cd94a0d 5362void wxGenericListCtrl::RefreshItem(long item)
1a6cb56f
VZ
5363{
5364 m_mainWin->RefreshLine(item);
5365}
5366
3cd94a0d 5367void wxGenericListCtrl::RefreshItems(long itemFrom, long itemTo)
1a6cb56f
VZ
5368{
5369 m_mainWin->RefreshLines(itemFrom, itemTo);
5370}
5371
2f1e3c46
VZ
5372/*
5373 * Generic wxListCtrl is more or less a container for two other
5374 * windows which drawings are done upon. These are namely
5375 * 'm_headerWin' and 'm_mainWin'.
5376 * Here we override 'virtual wxWindow::Refresh()' to mimic the
5377 * behaviour wxListCtrl has under wxMSW.
5378 */
5379void wxGenericListCtrl::Refresh(bool eraseBackground, const wxRect *rect)
5380{
5381 if (!rect)
5382 {
5383 // The easy case, no rectangle specified.
5384 if (m_headerWin)
5385 m_headerWin->Refresh(eraseBackground);
5386
5387 if (m_mainWin)
5388 m_mainWin->Refresh(eraseBackground);
5389 }
5390 else
5391 {
5392 // Refresh the header window
5393 if (m_headerWin)
5394 {
5395 wxRect rectHeader = m_headerWin->GetRect();
5396 rectHeader.Intersect(*rect);
5397 if (rectHeader.GetWidth() && rectHeader.GetHeight())
5398 {
5399 int x, y;
5400 m_headerWin->GetPosition(&x, &y);
5401 rectHeader.Offset(-x, -y);
5402 m_headerWin->Refresh(eraseBackground, &rectHeader);
5403 }
5404
5405 }
5406
5407 // Refresh the main window
5408 if (m_mainWin)
5409 {
5410 wxRect rectMain = m_mainWin->GetRect();
5411 rectMain.Intersect(*rect);
5412 if (rectMain.GetWidth() && rectMain.GetHeight())
5413 {
5414 int x, y;
5415 m_mainWin->GetPosition(&x, &y);
5416 rectMain.Offset(-x, -y);
5417 m_mainWin->Refresh(eraseBackground, &rectMain);
5418 }
5419 }
5420 }
5421}
5422
3cd94a0d 5423void wxGenericListCtrl::Freeze()
c5c528fc
VZ
5424{
5425 m_mainWin->Freeze();
5426}
5427
3cd94a0d 5428void wxGenericListCtrl::Thaw()
c5c528fc
VZ
5429{
5430 m_mainWin->Thaw();
5431}
5432
1e6feb95 5433#endif // wxUSE_LISTCTRL
5b98eb2f 5434