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