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