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