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