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