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