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