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