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