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