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