]> git.saurik.com Git - wxWidgets.git/blame - src/generic/listctrl.cpp
workaround for not appearing vertical scrollbar in wxTE_RICH2 controls
[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);
2b5f62a0
VZ
1777 if (w <= width)
1778 {
e1e1272f 1779 // it can, draw it using the items alignment
2b5f62a0 1780 m_owner->GetColumn(col, item);
e1e1272f
VZ
1781 switch ( item.GetAlign() )
1782 {
1783 default:
1784 wxFAIL_MSG( _T("unknown list item format") );
1785 // fall through
1786
1787 case wxLIST_FORMAT_LEFT:
1788 // nothing to do
1789 break;
1790
1791 case wxLIST_FORMAT_RIGHT:
1792 x += width - w;
1793 break;
1794
1795 case wxLIST_FORMAT_CENTER:
1796 x += (width - w) / 2;
1797 break;
1798 }
1799
1800 dc->DrawText(text, x, y);
2b5f62a0
VZ
1801 }
1802 else // otherwise, truncate and add an ellipsis if possible
1803 {
1804 // determine the base width
1805 ellipsis = wxString(wxT("..."));
1806 dc->GetTextExtent(ellipsis, &base_w, &h);
1807
1808 // continue until we have enough space or only one character left
1809 drawntext = text.Left(text.Length() - 1);
1810 while (drawntext.Length() > 1)
1811 {
1812 dc->GetTextExtent(drawntext, &w, &h);
1813 if (w + base_w <= width)
1814 break;
1815 drawntext = drawntext.Left(drawntext.Length() - 1);
1816 }
1817
1818 // if still not enough space, remove ellipsis characters
1819 while (ellipsis.Length() > 0 && w + base_w > width)
1820 {
1821 ellipsis = ellipsis.Left(ellipsis.Length() - 1);
1822 dc->GetTextExtent(ellipsis, &base_w, &h);
5cd89174 1823 }
2b5f62a0
VZ
1824
1825 // now draw the text
1826 dc->DrawText(drawntext, x, y);
1827 dc->DrawText(ellipsis, x + w, y);
e1e955e1 1828 }
e1e955e1 1829}
c801d85f 1830
b54e41c5 1831bool wxListLineData::Highlight( bool on )
c801d85f 1832{
b54e41c5 1833 wxCHECK_MSG( !m_owner->IsVirtual(), FALSE, _T("unexpected call to Highlight") );
c801d85f 1834
b54e41c5 1835 if ( on == m_highlighted )
cf1dfa6b 1836 return FALSE;
c801d85f 1837
b54e41c5 1838 m_highlighted = on;
c801d85f 1839
cf1dfa6b 1840 return TRUE;
e1e955e1 1841}
c801d85f 1842
b54e41c5 1843void wxListLineData::ReverseHighlight( void )
c801d85f 1844{
b54e41c5 1845 Highlight(!IsHighlighted());
e1e955e1 1846}
c801d85f
KB
1847
1848//-----------------------------------------------------------------------------
1849// wxListHeaderWindow
1850//-----------------------------------------------------------------------------
1851
5a1cad6e 1852IMPLEMENT_DYNAMIC_CLASS(wxListHeaderWindow,wxWindow)
c801d85f
KB
1853
1854BEGIN_EVENT_TABLE(wxListHeaderWindow,wxWindow)
63852e78
RR
1855 EVT_PAINT (wxListHeaderWindow::OnPaint)
1856 EVT_MOUSE_EVENTS (wxListHeaderWindow::OnMouse)
1857 EVT_SET_FOCUS (wxListHeaderWindow::OnSetFocus)
c801d85f
KB
1858END_EVENT_TABLE()
1859
0a816d95 1860void wxListHeaderWindow::Init()
c801d85f 1861{
63852e78 1862 m_currentCursor = (wxCursor *) NULL;
cfb50f14 1863 m_isDragging = FALSE;
0a816d95
VZ
1864 m_dirty = FALSE;
1865}
1866
1867wxListHeaderWindow::wxListHeaderWindow()
1868{
1869 Init();
1870
1871 m_owner = (wxListMainWindow *) NULL;
1872 m_resizeCursor = (wxCursor *) NULL;
e1e955e1 1873}
c801d85f 1874
0a816d95
VZ
1875wxListHeaderWindow::wxListHeaderWindow( wxWindow *win,
1876 wxWindowID id,
1877 wxListMainWindow *owner,
1878 const wxPoint& pos,
1879 const wxSize& size,
1880 long style,
1881 const wxString &name )
1882 : wxWindow( win, id, pos, size, style, name )
c801d85f 1883{
0a816d95
VZ
1884 Init();
1885
63852e78 1886 m_owner = owner;
63852e78 1887 m_resizeCursor = new wxCursor( wxCURSOR_SIZEWE );
f6bcfd97 1888
a756f210 1889 SetBackgroundColour( wxSystemSettings::GetColour( wxSYS_COLOUR_BTNFACE ) );
e1e955e1 1890}
c801d85f 1891
0a816d95 1892wxListHeaderWindow::~wxListHeaderWindow()
a367b9b3 1893{
63852e78 1894 delete m_resizeCursor;
a367b9b3
JS
1895}
1896
2b5f62a0
VZ
1897#ifdef __WXUNIVERSAL__
1898#include "wx/univ/renderer.h"
1899#include "wx/univ/theme.h"
1900#endif
1901
1e6d9499 1902void wxListHeaderWindow::DoDrawRect( wxDC *dc, int x, int y, int w, int h )
c801d85f 1903{
f16ba4e6 1904#if defined(__WXGTK__) && !defined(__WXUNIVERSAL__)
b54e41c5
VZ
1905 GtkStateType state = m_parent->IsEnabled() ? GTK_STATE_NORMAL
1906 : GTK_STATE_INSENSITIVE;
2c1f73ee 1907
3fb435df 1908 x = dc->XLOG2DEV( x );
2c1f73ee 1909
b54e41c5
VZ
1910 gtk_paint_box (m_wxwindow->style, GTK_PIZZA(m_wxwindow)->bin_window,
1911 state, GTK_SHADOW_OUT,
90350682
VZ
1912 (GdkRectangle*) NULL, m_wxwindow,
1913 (char *)"button", // const_cast
b54e41c5 1914 x-1, y-1, w+2, h+2);
2b5f62a0
VZ
1915#elif defined(__WXUNIVERSAL__)
1916 wxTheme *theme = wxTheme::Get();
1917 wxRenderer *renderer = theme->GetRenderer();
1918 renderer->DrawBorder( *dc, wxBORDER_RAISED, wxRect(x,y,w,h), 0 );
1919#elif defined(__WXMAC__)
4176fb7d
SC
1920 const int m_corner = 1;
1921
1922 dc->SetBrush( *wxTRANSPARENT_BRUSH );
1923
a756f210 1924 dc->SetPen( wxPen( wxSystemSettings::GetColour( wxSYS_COLOUR_BTNSHADOW ) , 1 , wxSOLID ) );
4176fb7d
SC
1925 dc->DrawLine( x+w-m_corner+1, y, x+w, y+h ); // right (outer)
1926 dc->DrawRectangle( x, y+h, w+1, 1 ); // bottom (outer)
1927
1928 wxPen pen( wxColour( 0x88 , 0x88 , 0x88 ), 1, wxSOLID );
1929
1930 dc->SetPen( pen );
1931 dc->DrawLine( x+w-m_corner, y, x+w-1, y+h ); // right (inner)
1932 dc->DrawRectangle( x+1, y+h-1, w-2, 1 ); // bottom (inner)
1933
1934 dc->SetPen( *wxWHITE_PEN );
1935 dc->DrawRectangle( x, y, w-m_corner+1, 1 ); // top (outer)
1936 dc->DrawRectangle( x, y, 1, h ); // left (outer)
1937 dc->DrawLine( x, y+h-1, x+1, y+h-1 );
1938 dc->DrawLine( x+w-1, y, x+w-1, y+1 );
b54e41c5 1939#else // !GTK, !Mac
63852e78 1940 const int m_corner = 1;
c801d85f 1941
63852e78 1942 dc->SetBrush( *wxTRANSPARENT_BRUSH );
c801d85f 1943
63852e78
RR
1944 dc->SetPen( *wxBLACK_PEN );
1945 dc->DrawLine( x+w-m_corner+1, y, x+w, y+h ); // right (outer)
17867d61 1946 dc->DrawRectangle( x, y+h, w+1, 1 ); // bottom (outer)
bd8289c1 1947
a756f210 1948 wxPen pen( wxSystemSettings::GetColour( wxSYS_COLOUR_BTNSHADOW ), 1, wxSOLID );
004fd0c8 1949
63852e78
RR
1950 dc->SetPen( pen );
1951 dc->DrawLine( x+w-m_corner, y, x+w-1, y+h ); // right (inner)
1952 dc->DrawRectangle( x+1, y+h-1, w-2, 1 ); // bottom (inner)
bd8289c1 1953
63852e78
RR
1954 dc->SetPen( *wxWHITE_PEN );
1955 dc->DrawRectangle( x, y, w-m_corner+1, 1 ); // top (outer)
1956 dc->DrawRectangle( x, y, 1, h ); // left (outer)
1957 dc->DrawLine( x, y+h-1, x+1, y+h-1 );
1958 dc->DrawLine( x+w-1, y, x+w-1, y+1 );
3fb435df 1959#endif
e1e955e1 1960}
c801d85f 1961
f6bcfd97
BP
1962// shift the DC origin to match the position of the main window horz
1963// scrollbar: this allows us to always use logical coords
1964void wxListHeaderWindow::AdjustDC(wxDC& dc)
1965{
f6bcfd97
BP
1966 int xpix;
1967 m_owner->GetScrollPixelsPerUnit( &xpix, NULL );
1968
1969 int x;
1970 m_owner->GetViewStart( &x, NULL );
1971
1972 // account for the horz scrollbar offset
1973 dc.SetDeviceOrigin( -x * xpix, 0 );
f6bcfd97
BP
1974}
1975
c801d85f
KB
1976void wxListHeaderWindow::OnPaint( wxPaintEvent &WXUNUSED(event) )
1977{
f16ba4e6 1978#if defined(__WXGTK__)
10bd0724
JS
1979 wxClientDC dc( this );
1980#else
63852e78 1981 wxPaintDC dc( this );
10bd0724
JS
1982#endif
1983
63852e78 1984 PrepareDC( dc );
f6bcfd97 1985 AdjustDC( dc );
bffa1c77 1986
63852e78 1987 dc.BeginDrawing();
bd8289c1 1988
63852e78 1989 dc.SetFont( GetFont() );
bd8289c1 1990
f6bcfd97
BP
1991 // width and height of the entire header window
1992 int w, h;
63852e78 1993 GetClientSize( &w, &h );
f6bcfd97 1994 m_owner->CalcUnscrolledPosition(w, 0, &w, NULL);
c801d85f 1995
f60d0f94 1996 dc.SetBackgroundMode(wxTRANSPARENT);
70846f0a
VZ
1997
1998 // do *not* use the listctrl colour for headers - one day we will have a
1999 // function to set it separately
37d403aa 2000 //dc.SetTextForeground( *wxBLACK );
cf1dfa6b
VZ
2001 dc.SetTextForeground(wxSystemSettings::
2002 GetSystemColour( wxSYS_COLOUR_WINDOWTEXT ));
2003
2004 int x = HEADER_OFFSET_X;
c801d85f 2005
63852e78
RR
2006 int numColumns = m_owner->GetColumnCount();
2007 wxListItem item;
c5b7bb59 2008 for ( int i = 0; i < numColumns && x < w; i++ )
63852e78
RR
2009 {
2010 m_owner->GetColumn( i, item );
f6bcfd97 2011 int wCol = item.m_width;
f6bcfd97 2012
0a816d95
VZ
2013 // the width of the rect to draw: make it smaller to fit entirely
2014 // inside the column rect
2015 int cw = wCol - 2;
f6bcfd97 2016
63852e78 2017 dc.SetPen( *wxWHITE_PEN );
c801d85f 2018
cf1dfa6b 2019 DoDrawRect( &dc, x, HEADER_OFFSET_Y, cw, h-2 );
0a816d95 2020
e1e1272f
VZ
2021 // see if we have enough space for the column label
2022
2023 // for this we need the width of the text
2024 wxCoord wLabel;
2025 dc.GetTextExtent(item.GetText(), &wLabel, NULL);
2026 wLabel += 2*EXTRA_WIDTH;
2027
2028 // and the width of the icon, if any
2029 static const int MARGIN_BETWEEN_TEXT_AND_ICON = 2;
73795999
VZ
2030 int ix = 0, // init them just to suppress the compiler warnings
2031 iy = 0;
e1e1272f
VZ
2032 const int image = item.m_image;
2033 wxImageListType *imageList;
0a816d95
VZ
2034 if ( image != -1 )
2035 {
e1e1272f 2036 imageList = m_owner->m_small_image_list;
0a816d95
VZ
2037 if ( imageList )
2038 {
0a816d95 2039 imageList->GetSize(image, ix, iy);
e1e1272f
VZ
2040 wLabel += ix + MARGIN_BETWEEN_TEXT_AND_ICON;
2041 }
2042 }
2043 else
2044 {
2045 imageList = NULL;
2046 }
2047
2048 // ignore alignment if there is not enough space anyhow
2049 int xAligned;
2050 switch ( wLabel < cw ? item.GetAlign() : wxLIST_FORMAT_LEFT )
2051 {
2052 default:
2053 wxFAIL_MSG( _T("unknown list item format") );
2054 // fall through
0a816d95 2055
e1e1272f
VZ
2056 case wxLIST_FORMAT_LEFT:
2057 xAligned = x;
2058 break;
0a816d95 2059
e1e1272f
VZ
2060 case wxLIST_FORMAT_RIGHT:
2061 xAligned = x + cw - wLabel;
2062 break;
2063
2064 case wxLIST_FORMAT_CENTER:
2065 xAligned = x + (cw - wLabel) / 2;
2066 break;
2067 }
2068
2069
2070 // if we have an image, draw it on the right of the label
2071 if ( imageList )
2072 {
2073 imageList->Draw
2074 (
2075 image,
2076 dc,
2077 xAligned + wLabel - ix - MARGIN_BETWEEN_TEXT_AND_ICON,
2078 HEADER_OFFSET_Y + (h - 4 - iy)/2,
2079 wxIMAGELIST_DRAW_TRANSPARENT
2080 );
2081
2082 cw -= ix + MARGIN_BETWEEN_TEXT_AND_ICON;
0a816d95
VZ
2083 }
2084
2085 // draw the text clipping it so that it doesn't overwrite the column
2086 // boundary
2087 wxDCClipper clipper(dc, x, HEADER_OFFSET_Y, cw, h - 4 );
06b781c7
VZ
2088
2089 dc.DrawText( item.GetText(),
e1e1272f 2090 xAligned + EXTRA_WIDTH, HEADER_OFFSET_Y + EXTRA_HEIGHT );
06b781c7 2091
0a816d95 2092 x += wCol;
63852e78 2093 }
c5b7bb59 2094
63852e78 2095 dc.EndDrawing();
e1e955e1 2096}
c801d85f 2097
0208334d
RR
2098void wxListHeaderWindow::DrawCurrent()
2099{
63852e78
RR
2100 int x1 = m_currentX;
2101 int y1 = 0;
f16ba4e6 2102 m_owner->ClientToScreen( &x1, &y1 );
f6bcfd97 2103
f16ba4e6 2104 int x2 = m_currentX;
63852e78 2105 int y2 = 0;
f6bcfd97 2106 m_owner->GetClientSize( NULL, &y2 );
63852e78 2107 m_owner->ClientToScreen( &x2, &y2 );
0208334d 2108
63852e78 2109 wxScreenDC dc;
3c679789 2110 dc.SetLogicalFunction( wxINVERT );
63852e78
RR
2111 dc.SetPen( wxPen( *wxBLACK, 2, wxSOLID ) );
2112 dc.SetBrush( *wxTRANSPARENT_BRUSH );
0208334d 2113
f6bcfd97
BP
2114 AdjustDC(dc);
2115
63852e78 2116 dc.DrawLine( x1, y1, x2, y2 );
0208334d 2117
63852e78 2118 dc.SetLogicalFunction( wxCOPY );
0208334d 2119
63852e78
RR
2120 dc.SetPen( wxNullPen );
2121 dc.SetBrush( wxNullBrush );
0208334d
RR
2122}
2123
c801d85f
KB
2124void wxListHeaderWindow::OnMouse( wxMouseEvent &event )
2125{
f6bcfd97 2126 // we want to work with logical coords
3ca6a5f0
BP
2127 int x;
2128 m_owner->CalcUnscrolledPosition(event.GetX(), 0, &x, NULL);
3ca6a5f0 2129 int y = event.GetY();
f6bcfd97 2130
cfb50f14 2131 if (m_isDragging)
0208334d 2132 {
a77ec46d
RD
2133 SendListEvent(wxEVT_COMMAND_LIST_COL_DRAGGING,
2134 event.GetPosition());
2135
f6bcfd97
BP
2136 // we don't draw the line beyond our window, but we allow dragging it
2137 // there
2138 int w = 0;
2139 GetClientSize( &w, NULL );
f6bcfd97 2140 m_owner->CalcUnscrolledPosition(w, 0, &w, NULL);
f6bcfd97
BP
2141 w -= 6;
2142
2143 // erase the line if it was drawn
2144 if ( m_currentX < w )
2145 DrawCurrent();
2146
63852e78
RR
2147 if (event.ButtonUp())
2148 {
2149 ReleaseMouse();
cfb50f14 2150 m_isDragging = FALSE;
f6bcfd97
BP
2151 m_dirty = TRUE;
2152 m_owner->SetColumnWidth( m_column, m_currentX - m_minX );
a77ec46d
RD
2153 SendListEvent(wxEVT_COMMAND_LIST_COL_END_DRAG,
2154 event.GetPosition());
63852e78
RR
2155 }
2156 else
2157 {
f6bcfd97 2158 if (x > m_minX + 7)
63852e78
RR
2159 m_currentX = x;
2160 else
f6bcfd97 2161 m_currentX = m_minX + 7;
bd8289c1 2162
f6bcfd97
BP
2163 // draw in the new location
2164 if ( m_currentX < w )
2165 DrawCurrent();
bffa1c77 2166 }
0208334d 2167 }
f6bcfd97 2168 else // not dragging
c801d85f 2169 {
f6bcfd97
BP
2170 m_minX = 0;
2171 bool hit_border = FALSE;
2172
2173 // end of the current column
2174 int xpos = 0;
2175
2176 // find the column where this event occured
62313c27
VZ
2177 int col,
2178 countCol = m_owner->GetColumnCount();
2179 for (col = 0; col < countCol; col++)
bffa1c77 2180 {
cf1dfa6b
VZ
2181 xpos += m_owner->GetColumnWidth( col );
2182 m_column = col;
f6bcfd97
BP
2183
2184 if ( (abs(x-xpos) < 3) && (y < 22) )
2185 {
2186 // near the column border
2187 hit_border = TRUE;
2188 break;
2189 }
2190
2191 if ( x < xpos )
2192 {
2193 // inside the column
2194 break;
2195 }
2196
2197 m_minX = xpos;
bffa1c77 2198 }
63852e78 2199
62313c27
VZ
2200 if ( col == countCol )
2201 m_column = -1;
2202
11358d39 2203 if (event.LeftDown() || event.RightUp())
63852e78 2204 {
11358d39 2205 if (hit_border && event.LeftDown())
f6bcfd97
BP
2206 {
2207 m_isDragging = TRUE;
2208 m_currentX = x;
2209 DrawCurrent();
2210 CaptureMouse();
a77ec46d
RD
2211 SendListEvent(wxEVT_COMMAND_LIST_COL_BEGIN_DRAG,
2212 event.GetPosition());
f6bcfd97 2213 }
11358d39 2214 else // click on a column
f6bcfd97 2215 {
a77ec46d 2216 SendListEvent( event.LeftDown()
11358d39
VZ
2217 ? wxEVT_COMMAND_LIST_COL_CLICK
2218 : wxEVT_COMMAND_LIST_COL_RIGHT_CLICK,
a77ec46d 2219 event.GetPosition());
f6bcfd97 2220 }
63852e78 2221 }
f6bcfd97 2222 else if (event.Moving())
63852e78 2223 {
f6bcfd97
BP
2224 bool setCursor;
2225 if (hit_border)
2226 {
2227 setCursor = m_currentCursor == wxSTANDARD_CURSOR;
2228 m_currentCursor = m_resizeCursor;
2229 }
2230 else
2231 {
2232 setCursor = m_currentCursor != wxSTANDARD_CURSOR;
2233 m_currentCursor = wxSTANDARD_CURSOR;
2234 }
2235
2236 if ( setCursor )
2237 SetCursor(*m_currentCursor);
63852e78 2238 }
e1e955e1 2239 }
e1e955e1 2240}
c801d85f
KB
2241
2242void wxListHeaderWindow::OnSetFocus( wxFocusEvent &WXUNUSED(event) )
2243{
63852e78 2244 m_owner->SetFocus();
e1e955e1 2245}
c801d85f 2246
a77ec46d
RD
2247void wxListHeaderWindow::SendListEvent(wxEventType type, wxPoint pos)
2248{
2249 wxWindow *parent = GetParent();
2250 wxListEvent le( type, parent->GetId() );
2251 le.SetEventObject( parent );
2252 le.m_pointDrag = pos;
2253
2254 // the position should be relative to the parent window, not
2255 // this one for compatibility with MSW and common sense: the
2256 // user code doesn't know anything at all about this header
2257 // window, so why should it get positions relative to it?
2258 le.m_pointDrag.y -= GetSize().y;
2259
2260 le.m_col = m_column;
2261 parent->GetEventHandler()->ProcessEvent( le );
2262}
2263
c801d85f
KB
2264//-----------------------------------------------------------------------------
2265// wxListRenameTimer (internal)
2266//-----------------------------------------------------------------------------
2267
bd8289c1
VZ
2268wxListRenameTimer::wxListRenameTimer( wxListMainWindow *owner )
2269{
63852e78 2270 m_owner = owner;
e1e955e1 2271}
c801d85f 2272
bd8289c1
VZ
2273void wxListRenameTimer::Notify()
2274{
63852e78 2275 m_owner->OnRenameTimer();
e1e955e1 2276}
c801d85f 2277
ee7ee469
RR
2278//-----------------------------------------------------------------------------
2279// wxListTextCtrl (internal)
2280//-----------------------------------------------------------------------------
2281
ee7ee469 2282BEGIN_EVENT_TABLE(wxListTextCtrl,wxTextCtrl)
63852e78 2283 EVT_CHAR (wxListTextCtrl::OnChar)
2c1f73ee 2284 EVT_KEY_UP (wxListTextCtrl::OnKeyUp)
63852e78 2285 EVT_KILL_FOCUS (wxListTextCtrl::OnKillFocus)
ee7ee469
RR
2286END_EVENT_TABLE()
2287
62d89eb4
VZ
2288wxListTextCtrl::wxListTextCtrl(wxListMainWindow *owner, size_t itemEdit)
2289 : m_startValue(owner->GetItemText(itemEdit)),
2290 m_itemEdited(itemEdit)
2291{
63852e78 2292 m_owner = owner;
dd5a32cc 2293 m_finished = FALSE;
62d89eb4
VZ
2294
2295 wxRect rectLabel = owner->GetLineLabelRect(itemEdit);
2296
2297 m_owner->CalcScrolledPosition(rectLabel.x, rectLabel.y,
2298 &rectLabel.x, &rectLabel.y);
2299
2300 (void)Create(owner, wxID_ANY, m_startValue,
2301 wxPoint(rectLabel.x-4,rectLabel.y-4),
2302 wxSize(rectLabel.width+11,rectLabel.height+8));
ee7ee469
RR
2303}
2304
62d89eb4 2305void wxListTextCtrl::Finish()
ee7ee469 2306{
62d89eb4 2307 if ( !m_finished )
63852e78 2308 {
62d89eb4 2309 wxPendingDelete.Append(this);
f6bcfd97 2310
dd5a32cc 2311 m_finished = TRUE;
62d89eb4 2312
a6d57d03 2313 m_owner->SetFocus();
62d89eb4
VZ
2314 }
2315}
dd5a32cc 2316
62d89eb4
VZ
2317bool wxListTextCtrl::AcceptChanges()
2318{
2319 const wxString value = GetValue();
2320
2321 if ( value == m_startValue )
2322 {
2323 // nothing changed, always accept
2324 return TRUE;
63852e78 2325 }
62d89eb4
VZ
2326
2327 if ( !m_owner->OnRenameAccept(m_itemEdited, value) )
63852e78 2328 {
62d89eb4
VZ
2329 // vetoed by the user
2330 return FALSE;
2331 }
f6bcfd97 2332
62d89eb4
VZ
2333 // accepted, do rename the item
2334 m_owner->SetItemText(m_itemEdited, value);
f6bcfd97 2335
62d89eb4
VZ
2336 return TRUE;
2337}
dd5a32cc 2338
62d89eb4
VZ
2339void wxListTextCtrl::OnChar( wxKeyEvent &event )
2340{
2341 switch ( event.m_keyCode )
2342 {
2343 case WXK_RETURN:
2344 if ( !AcceptChanges() )
2345 {
2346 // vetoed by the user code
2347 break;
2348 }
2349 //else: fall through
f6bcfd97 2350
62d89eb4
VZ
2351 case WXK_ESCAPE:
2352 Finish();
2353 break;
2354
2355 default:
2356 event.Skip();
2357 }
63852e78
RR
2358}
2359
c13cace1
VS
2360void wxListTextCtrl::OnKeyUp( wxKeyEvent &event )
2361{
dd5a32cc
RR
2362 if (m_finished)
2363 {
2364 event.Skip();
2365 return;
2366 }
2367
c13cace1
VS
2368 // auto-grow the textctrl:
2369 wxSize parentSize = m_owner->GetSize();
2370 wxPoint myPos = GetPosition();
2371 wxSize mySize = GetSize();
2372 int sx, sy;
a6d57d03 2373 GetTextExtent(GetValue() + _T("MM"), &sx, &sy);
cf1dfa6b
VZ
2374 if (myPos.x + sx > parentSize.x)
2375 sx = parentSize.x - myPos.x;
2376 if (mySize.x > sx)
2377 sx = mySize.x;
c13cace1 2378 SetSize(sx, -1);
2c1f73ee 2379
c13cace1
VS
2380 event.Skip();
2381}
2382
dd5a32cc 2383void wxListTextCtrl::OnKillFocus( wxFocusEvent &event )
63852e78 2384{
62d89eb4 2385 if ( !m_finished )
dd5a32cc 2386 {
62d89eb4 2387 (void)AcceptChanges();
004fd0c8 2388
62d89eb4
VZ
2389 Finish();
2390 }
a77ec46d 2391
62d89eb4 2392 event.Skip();
ee7ee469
RR
2393}
2394
c801d85f
KB
2395//-----------------------------------------------------------------------------
2396// wxListMainWindow
2397//-----------------------------------------------------------------------------
2398
5a1cad6e 2399IMPLEMENT_DYNAMIC_CLASS(wxListMainWindow,wxScrolledWindow)
bd8289c1 2400
c801d85f
KB
2401BEGIN_EVENT_TABLE(wxListMainWindow,wxScrolledWindow)
2402 EVT_PAINT (wxListMainWindow::OnPaint)
c801d85f
KB
2403 EVT_MOUSE_EVENTS (wxListMainWindow::OnMouse)
2404 EVT_CHAR (wxListMainWindow::OnChar)
3dfb93fd 2405 EVT_KEY_DOWN (wxListMainWindow::OnKeyDown)
c801d85f
KB
2406 EVT_SET_FOCUS (wxListMainWindow::OnSetFocus)
2407 EVT_KILL_FOCUS (wxListMainWindow::OnKillFocus)
2fa7c206 2408 EVT_SCROLLWIN (wxListMainWindow::OnScroll)
c801d85f
KB
2409END_EVENT_TABLE()
2410
1370703e 2411void wxListMainWindow::Init()
c801d85f 2412{
139adb6a 2413 m_columns.DeleteContents( TRUE );
139adb6a 2414 m_dirty = TRUE;
cf1dfa6b
VZ
2415 m_countVirt = 0;
2416 m_lineFrom =
b54e41c5 2417 m_lineTo = (size_t)-1;
cf1dfa6b
VZ
2418 m_linesPerPage = 0;
2419
2420 m_headerWidth =
2421 m_lineHeight = 0;
1370703e 2422
80020b62
JS
2423 m_small_image_list = (wxImageListType *) NULL;
2424 m_normal_image_list = (wxImageListType *) NULL;
1370703e 2425
139adb6a
RR
2426 m_small_spacing = 30;
2427 m_normal_spacing = 40;
1370703e 2428
139adb6a 2429 m_hasFocus = FALSE;
1370703e
VZ
2430 m_dragCount = 0;
2431 m_isCreated = FALSE;
2432
139adb6a
RR
2433 m_lastOnSame = FALSE;
2434 m_renameTimer = new wxListRenameTimer( this );
1370703e 2435
cf1dfa6b 2436 m_current =
efbb7287 2437 m_lineLastClicked =
1370703e 2438 m_lineBeforeLastClicked = (size_t)-1;
c5c528fc
VZ
2439
2440 m_freezeCount = 0;
e1e955e1 2441}
c801d85f 2442
cf1dfa6b
VZ
2443void wxListMainWindow::InitScrolling()
2444{
2445 if ( HasFlag(wxLC_REPORT) )
2446 {
2447 m_xScroll = SCROLL_UNIT_X;
2448 m_yScroll = SCROLL_UNIT_Y;
2449 }
2450 else
2451 {
2452 m_xScroll = SCROLL_UNIT_Y;
2453 m_yScroll = 0;
2454 }
2455}
2456
1370703e 2457wxListMainWindow::wxListMainWindow()
c801d85f 2458{
1370703e
VZ
2459 Init();
2460
49ecb029
VZ
2461 m_highlightBrush =
2462 m_highlightUnfocusedBrush = (wxBrush *) NULL;
1370703e
VZ
2463
2464 m_xScroll =
2465 m_yScroll = 0;
2466}
2467
2468wxListMainWindow::wxListMainWindow( wxWindow *parent,
2469 wxWindowID id,
2470 const wxPoint& pos,
2471 const wxSize& size,
2472 long style,
2473 const wxString &name )
2474 : wxScrolledWindow( parent, id, pos, size,
2475 style | wxHSCROLL | wxVSCROLL, name )
2476{
2477 Init();
2478
49ecb029
VZ
2479 m_highlightBrush = new wxBrush
2480 (
a756f210 2481 wxSystemSettings::GetColour
49ecb029
VZ
2482 (
2483 wxSYS_COLOUR_HIGHLIGHT
2484 ),
2485 wxSOLID
2486 );
2487
2488 m_highlightUnfocusedBrush = new wxBrush
2489 (
a756f210 2490 wxSystemSettings::GetColour
49ecb029
VZ
2491 (
2492 wxSYS_COLOUR_BTNSHADOW
2493 ),
2494 wxSOLID
2495 );
2496
139adb6a
RR
2497 wxSize sz = size;
2498 sz.y = 25;
bd8289c1 2499
cf1dfa6b 2500 InitScrolling();
139adb6a 2501 SetScrollbars( m_xScroll, m_yScroll, 0, 0, 0, 0 );
bd8289c1 2502
a756f210 2503 SetBackgroundColour( wxSystemSettings::GetColour( wxSYS_COLOUR_LISTBOX ) );
e1e955e1 2504}
c801d85f 2505
fd9811b1 2506wxListMainWindow::~wxListMainWindow()
c801d85f 2507{
5fe143df 2508 DoDeleteAllItems();
12c1b46a 2509
b54e41c5 2510 delete m_highlightBrush;
49ecb029 2511 delete m_highlightUnfocusedBrush;
004fd0c8 2512
139adb6a 2513 delete m_renameTimer;
e1e955e1 2514}
c801d85f 2515
cf1dfa6b 2516void wxListMainWindow::CacheLineData(size_t line)
c801d85f 2517{
3cd94a0d 2518 wxGenericListCtrl *listctrl = GetListCtrl();
25e3a937 2519
b54e41c5 2520 wxListLineData *ld = GetDummyLine();
f6bcfd97 2521
cf1dfa6b
VZ
2522 size_t countCol = GetColumnCount();
2523 for ( size_t col = 0; col < countCol; col++ )
2524 {
2525 ld->SetText(col, listctrl->OnGetItemText(line, col));
2526 }
2527
5cd89174 2528 ld->SetImage(listctrl->OnGetItemImage(line));
6c02c329 2529 ld->SetAttr(listctrl->OnGetItemAttr(line));
e1e955e1 2530}
c801d85f 2531
b54e41c5 2532wxListLineData *wxListMainWindow::GetDummyLine() const
c801d85f 2533{
cf1dfa6b 2534 wxASSERT_MSG( !IsEmpty(), _T("invalid line index") );
2c1f73ee 2535
904ccf52
VZ
2536 wxASSERT_MSG( IsVirtual(), _T("GetDummyLine() shouldn't be called") );
2537
2538 wxListMainWindow *self = wxConstCast(this, wxListMainWindow);
2539
2540 // we need to recreate the dummy line if the number of columns in the
2541 // control changed as it would have the incorrect number of fields
2542 // otherwise
2543 if ( !m_lines.IsEmpty() &&
2544 m_lines[0].m_items.GetCount() != (size_t)GetColumnCount() )
2c1f73ee 2545 {
904ccf52
VZ
2546 self->m_lines.Clear();
2547 }
cf1dfa6b 2548
904ccf52
VZ
2549 if ( m_lines.IsEmpty() )
2550 {
5cd89174 2551 wxListLineData *line = new wxListLineData(self);
cf1dfa6b 2552 self->m_lines.Add(line);
904ccf52
VZ
2553
2554 // don't waste extra memory -- there never going to be anything
2555 // else/more in this array
2556 self->m_lines.Shrink();
2c1f73ee
VZ
2557 }
2558
cf1dfa6b
VZ
2559 return &m_lines[0];
2560}
2561
5cd89174
VZ
2562// ----------------------------------------------------------------------------
2563// line geometry (report mode only)
2564// ----------------------------------------------------------------------------
2565
cf1dfa6b
VZ
2566wxCoord wxListMainWindow::GetLineHeight() const
2567{
2568 wxASSERT_MSG( HasFlag(wxLC_REPORT), _T("only works in report mode") );
673dfcfa 2569
cf1dfa6b
VZ
2570 // we cache the line height as calling GetTextExtent() is slow
2571 if ( !m_lineHeight )
2c1f73ee 2572 {
cf1dfa6b 2573 wxListMainWindow *self = wxConstCast(this, wxListMainWindow);
bd8289c1 2574
cf1dfa6b
VZ
2575 wxClientDC dc( self );
2576 dc.SetFont( GetFont() );
c801d85f 2577
cf1dfa6b
VZ
2578 wxCoord y;
2579 dc.GetTextExtent(_T("H"), NULL, &y);
004fd0c8 2580
cf1dfa6b
VZ
2581 if ( y < SCROLL_UNIT_Y )
2582 y = SCROLL_UNIT_Y;
2583 y += EXTRA_HEIGHT;
206b0a67 2584
cf1dfa6b
VZ
2585 self->m_lineHeight = y + LINE_SPACING;
2586 }
bffa1c77 2587
cf1dfa6b
VZ
2588 return m_lineHeight;
2589}
bffa1c77 2590
cf1dfa6b
VZ
2591wxCoord wxListMainWindow::GetLineY(size_t line) const
2592{
2593 wxASSERT_MSG( HasFlag(wxLC_REPORT), _T("only works in report mode") );
1370703e 2594
cf1dfa6b
VZ
2595 return LINE_SPACING + line*GetLineHeight();
2596}
206b0a67 2597
5cd89174
VZ
2598wxRect wxListMainWindow::GetLineRect(size_t line) const
2599{
2600 if ( !InReportView() )
2601 return GetLine(line)->m_gi->m_rectAll;
2602
2603 wxRect rect;
2604 rect.x = HEADER_OFFSET_X;
2605 rect.y = GetLineY(line);
2606 rect.width = GetHeaderWidth();
2607 rect.height = GetLineHeight();
2608
2609 return rect;
2610}
2611
2612wxRect wxListMainWindow::GetLineLabelRect(size_t line) const
2613{
2614 if ( !InReportView() )
2615 return GetLine(line)->m_gi->m_rectLabel;
2616
2617 wxRect rect;
2618 rect.x = HEADER_OFFSET_X;
2619 rect.y = GetLineY(line);
2620 rect.width = GetColumnWidth(0);
2621 rect.height = GetLineHeight();
2622
2623 return rect;
2624}
2625
2626wxRect wxListMainWindow::GetLineIconRect(size_t line) const
2627{
2628 if ( !InReportView() )
2629 return GetLine(line)->m_gi->m_rectIcon;
2630
2631 wxListLineData *ld = GetLine(line);
2632 wxASSERT_MSG( ld->HasImage(), _T("should have an image") );
2633
2634 wxRect rect;
2635 rect.x = HEADER_OFFSET_X;
2636 rect.y = GetLineY(line);
2637 GetImageSize(ld->GetImage(), rect.width, rect.height);
2638
2639 return rect;
2640}
2641
2642wxRect wxListMainWindow::GetLineHighlightRect(size_t line) const
2643{
2644 return InReportView() ? GetLineRect(line)
2645 : GetLine(line)->m_gi->m_rectHighlight;
2646}
2647
2648long wxListMainWindow::HitTestLine(size_t line, int x, int y) const
2649{
fc4f1d5f
VZ
2650 wxASSERT_MSG( line < GetItemCount(), _T("invalid line in HitTestLine") );
2651
5cd89174
VZ
2652 wxListLineData *ld = GetLine(line);
2653
2654 if ( ld->HasImage() && GetLineIconRect(line).Inside(x, y) )
2655 return wxLIST_HITTEST_ONITEMICON;
2656
acf4d858
VS
2657 // VS: Testing for "ld->HasText() || InReportView()" instead of
2658 // "ld->HasText()" is needed to make empty lines in report view
2659 // possible
2660 if ( ld->HasText() || InReportView() )
5cd89174
VZ
2661 {
2662 wxRect rect = InReportView() ? GetLineRect(line)
2663 : GetLineLabelRect(line);
2664
2665 if ( rect.Inside(x, y) )
2666 return wxLIST_HITTEST_ONITEMLABEL;
2667 }
2668
2669 return 0;
2670}
2671
2672// ----------------------------------------------------------------------------
2673// highlight (selection) handling
2674// ----------------------------------------------------------------------------
2675
b54e41c5 2676bool wxListMainWindow::IsHighlighted(size_t line) const
cf1dfa6b
VZ
2677{
2678 if ( IsVirtual() )
2679 {
b54e41c5 2680 return m_selStore.IsSelected(line);
cf1dfa6b
VZ
2681 }
2682 else // !virtual
2683 {
2684 wxListLineData *ld = GetLine(line);
b54e41c5 2685 wxCHECK_MSG( ld, FALSE, _T("invalid index in IsHighlighted") );
cf1dfa6b 2686
b54e41c5 2687 return ld->IsHighlighted();
cf1dfa6b
VZ
2688 }
2689}
2690
68a9ef0e
VZ
2691void wxListMainWindow::HighlightLines( size_t lineFrom,
2692 size_t lineTo,
2693 bool highlight )
cf1dfa6b 2694{
cf1dfa6b
VZ
2695 if ( IsVirtual() )
2696 {
68a9ef0e
VZ
2697 wxArrayInt linesChanged;
2698 if ( !m_selStore.SelectRange(lineFrom, lineTo, highlight,
2699 &linesChanged) )
2700 {
2701 // meny items changed state, refresh everything
2702 RefreshLines(lineFrom, lineTo);
2703 }
2704 else // only a few items changed state, refresh only them
2705 {
2706 size_t count = linesChanged.GetCount();
2707 for ( size_t n = 0; n < count; n++ )
2708 {
2709 RefreshLine(linesChanged[n]);
2710 }
2711 }
b54e41c5 2712 }
68a9ef0e 2713 else // iterate over all items in non report view
b54e41c5 2714 {
b54e41c5 2715 for ( size_t line = lineFrom; line <= lineTo; line++ )
cf1dfa6b 2716 {
b54e41c5 2717 if ( HighlightLine(line, highlight) )
68a9ef0e
VZ
2718 {
2719 RefreshLine(line);
2720 }
cf1dfa6b 2721 }
b54e41c5
VZ
2722 }
2723}
2724
2725bool wxListMainWindow::HighlightLine( size_t line, bool highlight )
2726{
2727 bool changed;
2728
2729 if ( IsVirtual() )
2730 {
2731 changed = m_selStore.SelectItem(line, highlight);
cf1dfa6b
VZ
2732 }
2733 else // !virtual
2734 {
2735 wxListLineData *ld = GetLine(line);
49ecb029 2736 wxCHECK_MSG( ld, FALSE, _T("invalid index in HighlightLine") );
cf1dfa6b 2737
b54e41c5 2738 changed = ld->Highlight(highlight);
cf1dfa6b
VZ
2739 }
2740
2741 if ( changed )
2742 {
b54e41c5 2743 SendNotify( line, highlight ? wxEVT_COMMAND_LIST_ITEM_SELECTED
5cd89174 2744 : wxEVT_COMMAND_LIST_ITEM_DESELECTED );
cf1dfa6b
VZ
2745 }
2746
2747 return changed;
2748}
2749
2750void wxListMainWindow::RefreshLine( size_t line )
2751{
6ea1323a
VZ
2752 if ( HasFlag(wxLC_REPORT) )
2753 {
2754 size_t visibleFrom, visibleTo;
2755 GetVisibleLinesRange(&visibleFrom, &visibleTo);
c1c4c551 2756
6ea1323a
VZ
2757 if ( line < visibleFrom || line > visibleTo )
2758 return;
2759 }
c1c4c551 2760
5cd89174 2761 wxRect rect = GetLineRect(line);
cf1dfa6b
VZ
2762
2763 CalcScrolledPosition( rect.x, rect.y, &rect.x, &rect.y );
2764 RefreshRect( rect );
2765}
2766
2767void wxListMainWindow::RefreshLines( size_t lineFrom, size_t lineTo )
2768{
2769 // we suppose that they are ordered by caller
2770 wxASSERT_MSG( lineFrom <= lineTo, _T("indices in disorder") );
2771
6b4a8d93
VZ
2772 wxASSERT_MSG( lineTo < GetItemCount(), _T("invalid line range") );
2773
cf1dfa6b
VZ
2774 if ( HasFlag(wxLC_REPORT) )
2775 {
b54e41c5
VZ
2776 size_t visibleFrom, visibleTo;
2777 GetVisibleLinesRange(&visibleFrom, &visibleTo);
2778
2779 if ( lineFrom < visibleFrom )
2780 lineFrom = visibleFrom;
2781 if ( lineTo > visibleTo )
2782 lineTo = visibleTo;
cf1dfa6b
VZ
2783
2784 wxRect rect;
2785 rect.x = 0;
2786 rect.y = GetLineY(lineFrom);
2787 rect.width = GetClientSize().x;
91c6cc0e 2788 rect.height = GetLineY(lineTo) - rect.y + GetLineHeight();
cf1dfa6b
VZ
2789
2790 CalcScrolledPosition( rect.x, rect.y, &rect.x, &rect.y );
2791 RefreshRect( rect );
2792 }
2793 else // !report
2794 {
2795 // TODO: this should be optimized...
2796 for ( size_t line = lineFrom; line <= lineTo; line++ )
2797 {
2798 RefreshLine(line);
2799 }
2800 }
2801}
2802
6b4a8d93
VZ
2803void wxListMainWindow::RefreshAfter( size_t lineFrom )
2804{
2805 if ( HasFlag(wxLC_REPORT) )
2806 {
c29582d0
JS
2807 size_t visibleFrom, visibleTo;
2808 GetVisibleLinesRange(&visibleFrom, &visibleTo);
6b4a8d93
VZ
2809
2810 if ( lineFrom < visibleFrom )
2811 lineFrom = visibleFrom;
c29582d0
JS
2812 else if ( lineFrom > visibleTo )
2813 return;
6b4a8d93
VZ
2814
2815 wxRect rect;
2816 rect.x = 0;
2817 rect.y = GetLineY(lineFrom);
c29582d0 2818 CalcScrolledPosition( rect.x, rect.y, &rect.x, &rect.y );
6b4a8d93
VZ
2819
2820 wxSize size = GetClientSize();
2821 rect.width = size.x;
2822 // refresh till the bottom of the window
2823 rect.height = size.y - rect.y;
2824
6b4a8d93 2825 RefreshRect( rect );
6b4a8d93
VZ
2826 }
2827 else // !report
2828 {
2829 // TODO: how to do it more efficiently?
2830 m_dirty = TRUE;
2831 }
2832}
2833
49ecb029
VZ
2834void wxListMainWindow::RefreshSelected()
2835{
2836 if ( IsEmpty() )
2837 return;
2838
2839 size_t from, to;
2840 if ( InReportView() )
2841 {
2842 GetVisibleLinesRange(&from, &to);
2843 }
2844 else // !virtual
2845 {
2846 from = 0;
2847 to = GetItemCount() - 1;
2848 }
2849
cf30ae13 2850 if ( HasCurrent() && m_current >= from && m_current <= to )
49ecb029
VZ
2851 {
2852 RefreshLine(m_current);
2853 }
2854
2855 for ( size_t line = from; line <= to; line++ )
2856 {
2857 // NB: the test works as expected even if m_current == -1
2858 if ( line != m_current && IsHighlighted(line) )
2859 {
2860 RefreshLine(line);
2861 }
2862 }
2863}
2864
c5c528fc
VZ
2865void wxListMainWindow::Freeze()
2866{
2867 m_freezeCount++;
2868}
2869
2870void wxListMainWindow::Thaw()
2871{
2872 wxCHECK_RET( m_freezeCount > 0, _T("thawing unfrozen list control?") );
2873
2874 if ( !--m_freezeCount )
2875 {
2876 Refresh();
2877 }
2878}
2879
cf1dfa6b
VZ
2880void wxListMainWindow::OnPaint( wxPaintEvent &WXUNUSED(event) )
2881{
2882 // Note: a wxPaintDC must be constructed even if no drawing is
2883 // done (a Windows requirement).
2884 wxPaintDC dc( this );
2885
c5c528fc 2886 if ( IsEmpty() || m_freezeCount )
cf1dfa6b 2887 {
c5c528fc 2888 // nothing to draw or not the moment to draw it
cf1dfa6b
VZ
2889 return;
2890 }
2891
1e4d446b
VZ
2892 if ( m_dirty )
2893 {
2894 // delay the repainting until we calculate all the items positions
2895 return;
2896 }
2897
cf1dfa6b
VZ
2898 PrepareDC( dc );
2899
2900 int dev_x, dev_y;
2901 CalcScrolledPosition( 0, 0, &dev_x, &dev_y );
2902
2903 dc.BeginDrawing();
2904
2905 dc.SetFont( GetFont() );
2906
2907 if ( HasFlag(wxLC_REPORT) )
2908 {
b54e41c5 2909 int lineHeight = GetLineHeight();
cf1dfa6b 2910
b54e41c5
VZ
2911 size_t visibleFrom, visibleTo;
2912 GetVisibleLinesRange(&visibleFrom, &visibleTo);
b84839ae
VZ
2913
2914 wxRect rectLine;
2915 wxCoord xOrig, yOrig;
2916 CalcUnscrolledPosition(0, 0, &xOrig, &yOrig);
2917
ff3d11a0 2918 // tell the caller cache to cache the data
91c6cc0e
VZ
2919 if ( IsVirtual() )
2920 {
2921 wxListEvent evCache(wxEVT_COMMAND_LIST_CACHE_HINT,
2922 GetParent()->GetId());
2923 evCache.SetEventObject( GetParent() );
2924 evCache.m_oldItemIndex = visibleFrom;
2925 evCache.m_itemIndex = visibleTo;
2926 GetParent()->GetEventHandler()->ProcessEvent( evCache );
2927 }
ff3d11a0 2928
b54e41c5 2929 for ( size_t line = visibleFrom; line <= visibleTo; line++ )
cf1dfa6b 2930 {
b84839ae
VZ
2931 rectLine = GetLineRect(line);
2932
2933 if ( !IsExposed(rectLine.x - xOrig, rectLine.y - yOrig,
2934 rectLine.width, rectLine.height) )
2935 {
2936 // don't redraw unaffected lines to avoid flicker
2937 continue;
2938 }
2939
5cd89174 2940 GetLine(line)->DrawInReportMode( &dc,
b84839ae 2941 rectLine,
5cd89174 2942 GetLineHighlightRect(line),
49ecb029 2943 IsHighlighted(line) );
cf1dfa6b
VZ
2944 }
2945
2946 if ( HasFlag(wxLC_HRULES) )
2947 {
b54e41c5 2948 wxPen pen(GetRuleColour(), 1, wxSOLID);
cf1dfa6b
VZ
2949 wxSize clientSize = GetClientSize();
2950
e7d073c3
RD
2951 // Don't draw the first one
2952 for ( size_t i = visibleFrom+1; i <= visibleTo; i++ )
cf1dfa6b
VZ
2953 {
2954 dc.SetPen(pen);
2955 dc.SetBrush( *wxTRANSPARENT_BRUSH );
b54e41c5
VZ
2956 dc.DrawLine(0 - dev_x, i*lineHeight,
2957 clientSize.x - dev_x, i*lineHeight);
cf1dfa6b
VZ
2958 }
2959
2960 // Draw last horizontal rule
e7d073c3 2961 if ( visibleTo == GetItemCount() - 1 )
cf1dfa6b
VZ
2962 {
2963 dc.SetPen(pen);
2964 dc.SetBrush( *wxTRANSPARENT_BRUSH );
e7d073c3
RD
2965 dc.DrawLine(0 - dev_x, (m_lineTo+1)*lineHeight,
2966 clientSize.x - dev_x , (m_lineTo+1)*lineHeight );
cf1dfa6b 2967 }
2c1f73ee 2968 }
206b0a67
JS
2969
2970 // Draw vertical rules if required
cf1dfa6b 2971 if ( HasFlag(wxLC_VRULES) && !IsEmpty() )
206b0a67 2972 {
b54e41c5 2973 wxPen pen(GetRuleColour(), 1, wxSOLID);
cf1dfa6b 2974
206b0a67
JS
2975 int col = 0;
2976 wxRect firstItemRect;
2977 wxRect lastItemRect;
e7d073c3
RD
2978 GetItemRect(visibleFrom, firstItemRect);
2979 GetItemRect(visibleTo, lastItemRect);
206b0a67 2980 int x = firstItemRect.GetX();
673dfcfa
JS
2981 dc.SetPen(pen);
2982 dc.SetBrush(* wxTRANSPARENT_BRUSH);
206b0a67
JS
2983 for (col = 0; col < GetColumnCount(); col++)
2984 {
2985 int colWidth = GetColumnWidth(col);
cf1dfa6b 2986 x += colWidth;
e7d073c3
RD
2987 dc.DrawLine(x - dev_x - 2, firstItemRect.GetY() - 1 - dev_y,
2988 x - dev_x - 2, lastItemRect.GetBottom() + 1 - dev_y);
206b0a67 2989 }
d786bf87 2990 }
139adb6a 2991 }
cf1dfa6b 2992 else // !report
139adb6a 2993 {
1370703e 2994 size_t count = GetItemCount();
cf1dfa6b
VZ
2995 for ( size_t i = 0; i < count; i++ )
2996 {
2997 GetLine(i)->Draw( &dc );
2998 }
139adb6a 2999 }
004fd0c8 3000
c25f61f1 3001 if ( HasCurrent() )
cf1dfa6b 3002 {
c25f61f1 3003 // don't draw rect outline under Max if we already have the background
49ecb029
VZ
3004 // color but under other platforms only draw it if we do: it is a bit
3005 // silly to draw "focus rect" if we don't have focus!
4176fb7d 3006#ifdef __WXMAC__
c25f61f1 3007 if ( !m_hasFocus )
49ecb029
VZ
3008#else // !__WXMAC__
3009 if ( m_hasFocus )
3010#endif // __WXMAC__/!__WXMAC__
c25f61f1
VZ
3011 {
3012 dc.SetPen( *wxBLACK_PEN );
3013 dc.SetBrush( *wxTRANSPARENT_BRUSH );
3014 dc.DrawRectangle( GetLineHighlightRect(m_current) );
3015 }
cf1dfa6b 3016 }
c801d85f 3017
139adb6a 3018 dc.EndDrawing();
e1e955e1 3019}
c801d85f 3020
b54e41c5 3021void wxListMainWindow::HighlightAll( bool on )
c801d85f 3022{
b54e41c5 3023 if ( IsSingleSel() )
c801d85f 3024 {
b54e41c5
VZ
3025 wxASSERT_MSG( !on, _T("can't do this in a single sel control") );
3026
3027 // we just have one item to turn off
3028 if ( HasCurrent() && IsHighlighted(m_current) )
139adb6a 3029 {
b54e41c5
VZ
3030 HighlightLine(m_current, FALSE);
3031 RefreshLine(m_current);
139adb6a 3032 }
e1e955e1 3033 }
b54e41c5 3034 else // multi sel
cf1dfa6b 3035 {
b54e41c5 3036 HighlightLines(0, GetItemCount() - 1, on);
cf1dfa6b 3037 }
e1e955e1 3038}
c801d85f 3039
cf1dfa6b 3040void wxListMainWindow::SendNotify( size_t line,
05a7f61d
VZ
3041 wxEventType command,
3042 wxPoint point )
c801d85f 3043{
139adb6a
RR
3044 wxListEvent le( command, GetParent()->GetId() );
3045 le.SetEventObject( GetParent() );
cf1dfa6b 3046 le.m_itemIndex = line;
05a7f61d
VZ
3047
3048 // set only for events which have position
3049 if ( point != wxDefaultPosition )
3050 le.m_pointDrag = point;
3051
c1c4c551
VZ
3052 // don't try to get the line info for virtual list controls: the main
3053 // program has it anyhow and if we did it would result in accessing all
3054 // the lines, even those which are not visible now and this is precisely
3055 // what we're trying to avoid
3056 if ( !IsVirtual() && (command != wxEVT_COMMAND_LIST_DELETE_ITEM) )
91c6cc0e 3057 {
0ddefeb0
VZ
3058 if ( line != (size_t)-1 )
3059 {
3060 GetLine(line)->GetItem( 0, le.m_item );
3061 }
3062 //else: this happens for wxEVT_COMMAND_LIST_ITEM_FOCUSED event
91c6cc0e
VZ
3063 }
3064 //else: there may be no more such item
3065
6e228e42 3066 GetParent()->GetEventHandler()->ProcessEvent( le );
e1e955e1 3067}
c801d85f 3068
0ddefeb0 3069void wxListMainWindow::ChangeCurrent(size_t current)
c801d85f 3070{
0ddefeb0 3071 m_current = current;
c801d85f 3072
0ddefeb0 3073 SendNotify(current, wxEVT_COMMAND_LIST_ITEM_FOCUSED);
e1e955e1 3074}
c801d85f 3075
5f1ea0ee 3076void wxListMainWindow::EditLabel( long item )
c801d85f 3077{
cf1dfa6b 3078 wxCHECK_RET( (item >= 0) && ((size_t)item < GetItemCount()),
3cd94a0d 3079 wxT("wrong index in wxGenericListCtrl::EditLabel()") );
004fd0c8 3080
62d89eb4 3081 size_t itemEdit = (size_t)item;
e179bd65 3082
fd9811b1 3083 wxListEvent le( wxEVT_COMMAND_LIST_BEGIN_LABEL_EDIT, GetParent()->GetId() );
139adb6a 3084 le.SetEventObject( GetParent() );
1370703e 3085 le.m_itemIndex = item;
62d89eb4 3086 wxListLineData *data = GetLine(itemEdit);
1370703e
VZ
3087 wxCHECK_RET( data, _T("invalid index in EditLabel()") );
3088 data->GetItem( 0, le.m_item );
62d89eb4
VZ
3089 if ( GetParent()->GetEventHandler()->ProcessEvent( le ) && !le.IsAllowed() )
3090 {
3091 // vetoed by user code
5f1ea0ee 3092 return;
62d89eb4 3093 }
004fd0c8 3094
cf1dfa6b
VZ
3095 // We have to call this here because the label in question might just have
3096 // been added and no screen update taken place.
62d89eb4 3097 if ( m_dirty )
cf1dfa6b 3098 wxSafeYield();
004fd0c8 3099
62d89eb4
VZ
3100 wxListTextCtrl *text = new wxListTextCtrl(this, itemEdit);
3101
92976ab6 3102 text->SetFocus();
e1e955e1 3103}
c801d85f 3104
e179bd65
RR
3105void wxListMainWindow::OnRenameTimer()
3106{
cf1dfa6b 3107 wxCHECK_RET( HasCurrent(), wxT("unexpected rename timer") );
004fd0c8 3108
cf1dfa6b 3109 EditLabel( m_current );
e179bd65
RR
3110}
3111
62d89eb4 3112bool wxListMainWindow::OnRenameAccept(size_t itemEdit, const wxString& value)
c801d85f 3113{
e179bd65
RR
3114 wxListEvent le( wxEVT_COMMAND_LIST_END_LABEL_EDIT, GetParent()->GetId() );
3115 le.SetEventObject( GetParent() );
62d89eb4 3116 le.m_itemIndex = itemEdit;
1370703e 3117
62d89eb4
VZ
3118 wxListLineData *data = GetLine(itemEdit);
3119 wxCHECK_MSG( data, FALSE, _T("invalid index in OnRenameAccept()") );
1370703e
VZ
3120
3121 data->GetItem( 0, le.m_item );
62d89eb4
VZ
3122 le.m_item.m_text = value;
3123 return !GetParent()->GetEventHandler()->ProcessEvent( le ) ||
3124 le.IsAllowed();
e1e955e1 3125}
c801d85f
KB
3126
3127void wxListMainWindow::OnMouse( wxMouseEvent &event )
3128{
3e1c4e00 3129 event.SetEventObject( GetParent() );
cf1dfa6b
VZ
3130 if ( GetParent()->GetEventHandler()->ProcessEvent( event) )
3131 return;
3132
3133 if ( !HasCurrent() || IsEmpty() )
3134 return;
3135
3136 if (m_dirty)
3137 return;
e3e65dac 3138
cf1dfa6b
VZ
3139 if ( !(event.Dragging() || event.ButtonDown() || event.LeftUp() ||
3140 event.ButtonDClick()) )
3141 return;
c801d85f 3142
aaef15bf
RR
3143 int x = event.GetX();
3144 int y = event.GetY();
3145 CalcUnscrolledPosition( x, y, &x, &y );
004fd0c8 3146
cc734310 3147 // where did we hit it (if we did)?
92976ab6 3148 long hitResult = 0;
1370703e 3149
cf1dfa6b
VZ
3150 size_t count = GetItemCount(),
3151 current;
3152
3153 if ( HasFlag(wxLC_REPORT) )
92976ab6 3154 {
5cd89174 3155 current = y / GetLineHeight();
cc734310
VZ
3156 if ( current < count )
3157 hitResult = HitTestLine(current, x, y);
cf1dfa6b
VZ
3158 }
3159 else // !report
3160 {
3161 // TODO: optimize it too! this is less simple than for report view but
3162 // enumerating all items is still not a way to do it!!
4e3ace65 3163 for ( current = 0; current < count; current++ )
cf1dfa6b 3164 {
5cd89174 3165 hitResult = HitTestLine(current, x, y);
4e3ace65
VZ
3166 if ( hitResult )
3167 break;
cf1dfa6b 3168 }
92976ab6 3169 }
bd8289c1 3170
fd9811b1 3171 if (event.Dragging())
92976ab6 3172 {
fd9811b1 3173 if (m_dragCount == 0)
8d1d2284
VZ
3174 {
3175 // we have to report the raw, physical coords as we want to be
3176 // able to call HitTest(event.m_pointDrag) from the user code to
3177 // get the item being dragged
3178 m_dragStart = event.GetPosition();
3179 }
bffa1c77 3180
fd9811b1 3181 m_dragCount++;
bffa1c77 3182
cf1dfa6b
VZ
3183 if (m_dragCount != 3)
3184 return;
bffa1c77 3185
05a7f61d
VZ
3186 int command = event.RightIsDown() ? wxEVT_COMMAND_LIST_BEGIN_RDRAG
3187 : wxEVT_COMMAND_LIST_BEGIN_DRAG;
bffa1c77 3188
fd9811b1 3189 wxListEvent le( command, GetParent()->GetId() );
92976ab6 3190 le.SetEventObject( GetParent() );
bffa1c77
VZ
3191 le.m_pointDrag = m_dragStart;
3192 GetParent()->GetEventHandler()->ProcessEvent( le );
3193
3194 return;
92976ab6 3195 }
fd9811b1
RR
3196 else
3197 {
3198 m_dragCount = 0;
3199 }
bd8289c1 3200
cf1dfa6b
VZ
3201 if ( !hitResult )
3202 {
3203 // outside of any item
3204 return;
3205 }
bd8289c1 3206
efbb7287 3207 bool forceClick = FALSE;
92976ab6
RR
3208 if (event.ButtonDClick())
3209 {
92976ab6 3210 m_renameTimer->Stop();
efbb7287
VZ
3211 m_lastOnSame = FALSE;
3212
ddba340d 3213 if ( current == m_lineLastClicked )
efbb7287 3214 {
cf1dfa6b 3215 SendNotify( current, wxEVT_COMMAND_LIST_ITEM_ACTIVATED );
004fd0c8 3216
efbb7287
VZ
3217 return;
3218 }
3219 else
3220 {
3221 // the first click was on another item, so don't interpret this as
3222 // a double click, but as a simple click instead
3223 forceClick = TRUE;
3224 }
92976ab6 3225 }
bd8289c1 3226
92976ab6 3227 if (event.LeftUp() && m_lastOnSame)
c801d85f 3228 {
cf1dfa6b 3229 if ((current == m_current) &&
92976ab6 3230 (hitResult == wxLIST_HITTEST_ONITEMLABEL) &&
cf1dfa6b 3231 HasFlag(wxLC_EDIT_LABELS) )
92976ab6
RR
3232 {
3233 m_renameTimer->Start( 100, TRUE );
3234 }
3235 m_lastOnSame = FALSE;
e1e955e1 3236 }
cf1dfa6b 3237 else if (event.RightDown())
b204641e 3238 {
cf1dfa6b 3239 SendNotify( current, wxEVT_COMMAND_LIST_ITEM_RIGHT_CLICK,
05a7f61d 3240 event.GetPosition() );
b204641e 3241 }
cf1dfa6b 3242 else if (event.MiddleDown())
b204641e 3243 {
cf1dfa6b 3244 SendNotify( current, wxEVT_COMMAND_LIST_ITEM_MIDDLE_CLICK );
92976ab6 3245 }
cf1dfa6b 3246 else if ( event.LeftDown() || forceClick )
92976ab6 3247 {
efbb7287 3248 m_lineBeforeLastClicked = m_lineLastClicked;
cf1dfa6b
VZ
3249 m_lineLastClicked = current;
3250
3251 size_t oldCurrent = m_current;
efbb7287 3252
b54e41c5 3253 if ( IsSingleSel() || !(event.ControlDown() || event.ShiftDown()) )
b204641e 3254 {
b54e41c5 3255 HighlightAll( FALSE );
0ddefeb0
VZ
3256
3257 ChangeCurrent(current);
cf1dfa6b 3258
b54e41c5 3259 ReverseHighlight(m_current);
e1e955e1 3260 }
b54e41c5 3261 else // multi sel & either ctrl or shift is down
b204641e 3262 {
473d087e 3263 if (event.ControlDown())
92976ab6 3264 {
0ddefeb0 3265 ChangeCurrent(current);
cf1dfa6b 3266
b54e41c5 3267 ReverseHighlight(m_current);
92976ab6 3268 }
473d087e 3269 else if (event.ShiftDown())
92976ab6 3270 {
0ddefeb0 3271 ChangeCurrent(current);
bffa1c77 3272
cf1dfa6b
VZ
3273 size_t lineFrom = oldCurrent,
3274 lineTo = current;
f6bcfd97 3275
cf1dfa6b 3276 if ( lineTo < lineFrom )
92976ab6 3277 {
cf1dfa6b
VZ
3278 lineTo = lineFrom;
3279 lineFrom = m_current;
92976ab6
RR
3280 }
3281
b54e41c5 3282 HighlightLines(lineFrom, lineTo);
92976ab6 3283 }
cf1dfa6b 3284 else // !ctrl, !shift
92976ab6 3285 {
cf1dfa6b
VZ
3286 // test in the enclosing if should make it impossible
3287 wxFAIL_MSG( _T("how did we get here?") );
92976ab6 3288 }
e1e955e1 3289 }
cf1dfa6b 3290
92976ab6
RR
3291 if (m_current != oldCurrent)
3292 {
3293 RefreshLine( oldCurrent );
92976ab6 3294 }
efbb7287
VZ
3295
3296 // forceClick is only set if the previous click was on another item
3297 m_lastOnSame = !forceClick && (m_current == oldCurrent);
e1e955e1 3298 }
e1e955e1 3299}
c801d85f 3300
34bbbc27 3301void wxListMainWindow::MoveToItem(size_t item)
c801d85f 3302{
34bbbc27 3303 if ( item == (size_t)-1 )
cf1dfa6b 3304 return;
004fd0c8 3305
34bbbc27 3306 wxRect rect = GetLineRect(item);
cf3da716 3307
cf1dfa6b 3308 int client_w, client_h;
cf3da716 3309 GetClientSize( &client_w, &client_h );
f6bcfd97 3310
cf3da716
RR
3311 int view_x = m_xScroll*GetScrollPos( wxHORIZONTAL );
3312 int view_y = m_yScroll*GetScrollPos( wxVERTICAL );
004fd0c8 3313
cf1dfa6b 3314 if ( HasFlag(wxLC_REPORT) )
92976ab6 3315 {
b54e41c5
VZ
3316 // the next we need the range of lines shown it might be different, so
3317 // recalculate it
3318 ResetVisibleLinesRange();
3319
cf1dfa6b
VZ
3320 if (rect.y < view_y )
3321 Scroll( -1, rect.y/m_yScroll );
3322 if (rect.y+rect.height+5 > view_y+client_h)
3323 Scroll( -1, (rect.y+rect.height-client_h+SCROLL_UNIT_Y)/m_yScroll );
92976ab6 3324 }
b54e41c5 3325 else // !report
92976ab6 3326 {
cf1dfa6b
VZ
3327 if (rect.x-view_x < 5)
3328 Scroll( (rect.x-5)/m_xScroll, -1 );
3329 if (rect.x+rect.width-5 > view_x+client_w)
3330 Scroll( (rect.x+rect.width-client_w+SCROLL_UNIT_X)/m_xScroll, -1 );
92976ab6 3331 }
e1e955e1 3332}
c801d85f 3333
cf1dfa6b
VZ
3334// ----------------------------------------------------------------------------
3335// keyboard handling
3336// ----------------------------------------------------------------------------
3337
3338void wxListMainWindow::OnArrowChar(size_t newCurrent, const wxKeyEvent& event)
c801d85f 3339{
cf1dfa6b
VZ
3340 wxCHECK_RET( newCurrent < (size_t)GetItemCount(),
3341 _T("invalid item index in OnArrowChar()") );
3342
3343 size_t oldCurrent = m_current;
3344
3345 // in single selection we just ignore Shift as we can't select several
3346 // items anyhow
b54e41c5 3347 if ( event.ShiftDown() && !IsSingleSel() )
cf1dfa6b 3348 {
0ddefeb0 3349 ChangeCurrent(newCurrent);
cf1dfa6b
VZ
3350
3351 // select all the items between the old and the new one
3352 if ( oldCurrent > newCurrent )
3353 {
3354 newCurrent = oldCurrent;
3355 oldCurrent = m_current;
3356 }
3357
b54e41c5 3358 HighlightLines(oldCurrent, newCurrent);
cf1dfa6b
VZ
3359 }
3360 else // !shift
3361 {
b54e41c5
VZ
3362 // all previously selected items are unselected unless ctrl is held
3363 if ( !event.ControlDown() )
3364 HighlightAll(FALSE);
3365
0ddefeb0 3366 ChangeCurrent(newCurrent);
cf1dfa6b 3367
58c1c096 3368 // refresh the old focus to remove it
cf1dfa6b
VZ
3369 RefreshLine( oldCurrent );
3370
3371 if ( !event.ControlDown() )
3372 {
b54e41c5 3373 HighlightLine( m_current, TRUE );
cf1dfa6b
VZ
3374 }
3375 }
3376
92976ab6 3377 RefreshLine( m_current );
cf1dfa6b 3378
cf3da716 3379 MoveToFocus();
e1e955e1 3380}
c801d85f 3381
3dfb93fd
RR
3382void wxListMainWindow::OnKeyDown( wxKeyEvent &event )
3383{
3384 wxWindow *parent = GetParent();
004fd0c8 3385
3dfb93fd
RR
3386 /* we propagate the key event up */
3387 wxKeyEvent ke( wxEVT_KEY_DOWN );
3388 ke.m_shiftDown = event.m_shiftDown;
3389 ke.m_controlDown = event.m_controlDown;
3390 ke.m_altDown = event.m_altDown;
3391 ke.m_metaDown = event.m_metaDown;
3392 ke.m_keyCode = event.m_keyCode;
3393 ke.m_x = event.m_x;
3394 ke.m_y = event.m_y;
3395 ke.SetEventObject( parent );
3396 if (parent->GetEventHandler()->ProcessEvent( ke )) return;
004fd0c8 3397
3dfb93fd
RR
3398 event.Skip();
3399}
004fd0c8 3400
c801d85f
KB
3401void wxListMainWindow::OnChar( wxKeyEvent &event )
3402{
51cc4dad 3403 wxWindow *parent = GetParent();
004fd0c8 3404
51cc4dad 3405 /* we send a list_key event up */
cf1dfa6b 3406 if ( HasCurrent() )
f6bcfd97
BP
3407 {
3408 wxListEvent le( wxEVT_COMMAND_LIST_KEY_DOWN, GetParent()->GetId() );
cf1dfa6b
VZ
3409 le.m_itemIndex = m_current;
3410 GetLine(m_current)->GetItem( 0, le.m_item );
f6bcfd97
BP
3411 le.m_code = (int)event.KeyCode();
3412 le.SetEventObject( parent );
3413 parent->GetEventHandler()->ProcessEvent( le );
3414 }
51cc4dad 3415
3dfb93fd
RR
3416 /* we propagate the char event up */
3417 wxKeyEvent ke( wxEVT_CHAR );
51cc4dad
RR
3418 ke.m_shiftDown = event.m_shiftDown;
3419 ke.m_controlDown = event.m_controlDown;
3420 ke.m_altDown = event.m_altDown;
3421 ke.m_metaDown = event.m_metaDown;
3422 ke.m_keyCode = event.m_keyCode;
3423 ke.m_x = event.m_x;
3424 ke.m_y = event.m_y;
3425 ke.SetEventObject( parent );
3426 if (parent->GetEventHandler()->ProcessEvent( ke )) return;
004fd0c8 3427
012a03e0
RR
3428 if (event.KeyCode() == WXK_TAB)
3429 {
3430 wxNavigationKeyEvent nevent;
c5145d41 3431 nevent.SetWindowChange( event.ControlDown() );
012a03e0 3432 nevent.SetDirection( !event.ShiftDown() );
8253c7fd 3433 nevent.SetEventObject( GetParent()->GetParent() );
012a03e0 3434 nevent.SetCurrentFocus( m_parent );
87948f22
VZ
3435 if (GetParent()->GetParent()->GetEventHandler()->ProcessEvent( nevent ))
3436 return;
012a03e0 3437 }
004fd0c8 3438
51cc4dad 3439 /* no item -> nothing to do */
cf1dfa6b 3440 if (!HasCurrent())
c801d85f 3441 {
51cc4dad
RR
3442 event.Skip();
3443 return;
e1e955e1 3444 }
51cc4dad
RR
3445
3446 switch (event.KeyCode())
c801d85f 3447 {
51cc4dad 3448 case WXK_UP:
cf1dfa6b
VZ
3449 if ( m_current > 0 )
3450 OnArrowChar( m_current - 1, event );
51cc4dad 3451 break;
cf1dfa6b 3452
51cc4dad 3453 case WXK_DOWN:
cf1dfa6b
VZ
3454 if ( m_current < (size_t)GetItemCount() - 1 )
3455 OnArrowChar( m_current + 1, event );
51cc4dad 3456 break;
cf1dfa6b 3457
51cc4dad 3458 case WXK_END:
1370703e 3459 if (!IsEmpty())
cf1dfa6b 3460 OnArrowChar( GetItemCount() - 1, event );
51cc4dad 3461 break;
cf1dfa6b 3462
51cc4dad 3463 case WXK_HOME:
1370703e 3464 if (!IsEmpty())
cf1dfa6b 3465 OnArrowChar( 0, event );
51cc4dad 3466 break;
cf1dfa6b 3467
51cc4dad 3468 case WXK_PRIOR:
f6bcfd97 3469 {
cf1dfa6b
VZ
3470 int steps = 0;
3471 if ( HasFlag(wxLC_REPORT) )
3472 {
3473 steps = m_linesPerPage - 1;
3474 }
3475 else
3476 {
3477 steps = m_current % m_linesPerPage;
3478 }
3479
3480 int index = m_current - steps;
3481 if (index < 0)
3482 index = 0;
3483
3484 OnArrowChar( index, event );
51cc4dad 3485 }
51cc4dad 3486 break;
cf1dfa6b 3487
51cc4dad 3488 case WXK_NEXT:
bffa1c77 3489 {
cf1dfa6b
VZ
3490 int steps = 0;
3491 if ( HasFlag(wxLC_REPORT) )
3492 {
3493 steps = m_linesPerPage - 1;
3494 }
3495 else
3496 {
3497 steps = m_linesPerPage - (m_current % m_linesPerPage) - 1;
3498 }
f6bcfd97 3499
cf1dfa6b
VZ
3500 size_t index = m_current + steps;
3501 size_t count = GetItemCount();
3502 if ( index >= count )
3503 index = count - 1;
3504
3505 OnArrowChar( index, event );
51cc4dad 3506 }
51cc4dad 3507 break;
cf1dfa6b 3508
51cc4dad 3509 case WXK_LEFT:
cf1dfa6b 3510 if ( !HasFlag(wxLC_REPORT) )
51cc4dad 3511 {
cf1dfa6b
VZ
3512 int index = m_current - m_linesPerPage;
3513 if (index < 0)
3514 index = 0;
3515
3516 OnArrowChar( index, event );
51cc4dad
RR
3517 }
3518 break;
cf1dfa6b 3519
51cc4dad 3520 case WXK_RIGHT:
cf1dfa6b 3521 if ( !HasFlag(wxLC_REPORT) )
51cc4dad 3522 {
cf1dfa6b
VZ
3523 size_t index = m_current + m_linesPerPage;
3524
3525 size_t count = GetItemCount();
3526 if ( index >= count )
3527 index = count - 1;
3528
3529 OnArrowChar( index, event );
51cc4dad
RR
3530 }
3531 break;
cf1dfa6b 3532
51cc4dad 3533 case WXK_SPACE:
b54e41c5 3534 if ( IsSingleSel() )
33d0e17c 3535 {
87948f22 3536 SendNotify( m_current, wxEVT_COMMAND_LIST_ITEM_ACTIVATED );
70541533
VZ
3537
3538 if ( IsHighlighted(m_current) )
3539 {
3540 // don't unselect the item in single selection mode
3541 break;
3542 }
3543 //else: select it in ReverseHighlight() below if unselected
33d0e17c 3544 }
70541533
VZ
3545
3546 ReverseHighlight(m_current);
51cc4dad 3547 break;
cf1dfa6b 3548
51cc4dad
RR
3549 case WXK_RETURN:
3550 case WXK_EXECUTE:
87948f22 3551 SendNotify( m_current, wxEVT_COMMAND_LIST_ITEM_ACTIVATED );
51cc4dad 3552 break;
cf1dfa6b 3553
51cc4dad 3554 default:
51cc4dad 3555 event.Skip();
e1e955e1 3556 }
e1e955e1 3557}
c801d85f 3558
cf1dfa6b
VZ
3559// ----------------------------------------------------------------------------
3560// focus handling
3561// ----------------------------------------------------------------------------
3562
a6d57d03
VS
3563void wxListMainWindow::SetFocus()
3564{
3565 // VS: wxListMainWindow derives from wxPanel (via wxScrolledWindow) and wxPanel
a77ec46d 3566 // overrides SetFocus in such way that it does never change focus from
a6d57d03 3567 // panel's child to the panel itself. Unfortunately, we must be able to change
a77ec46d 3568 // focus to the panel from wxListTextCtrl because the text control should
a6d57d03
VS
3569 // disappear when the user clicks outside it.
3570
3571 wxWindow *oldFocus = FindFocus();
a77ec46d 3572
072da98f 3573 if ( oldFocus && oldFocus->GetParent() == this )
a6d57d03
VS
3574 {
3575 wxWindow::SetFocus();
3576 }
3577 else
3578 {
3579 wxScrolledWindow::SetFocus();
3580 }
3581}
3582
c801d85f
KB
3583void wxListMainWindow::OnSetFocus( wxFocusEvent &WXUNUSED(event) )
3584{
bde9072f
VZ
3585 // wxGTK sends us EVT_SET_FOCUS events even if we had never got
3586 // EVT_KILL_FOCUS before which means that we finish by redrawing the items
3587 // which are already drawn correctly resulting in horrible flicker - avoid
3588 // it
47724389
VZ
3589 if ( !m_hasFocus )
3590 {
3591 m_hasFocus = TRUE;
bde9072f 3592
47724389
VZ
3593 RefreshSelected();
3594 }
bd8289c1 3595
47724389 3596 if ( !GetParent() )
cf1dfa6b 3597 return;
004fd0c8 3598
63852e78
RR
3599 wxFocusEvent event( wxEVT_SET_FOCUS, GetParent()->GetId() );
3600 event.SetEventObject( GetParent() );
3601 GetParent()->GetEventHandler()->ProcessEvent( event );
e1e955e1 3602}
c801d85f
KB
3603
3604void wxListMainWindow::OnKillFocus( wxFocusEvent &WXUNUSED(event) )
3605{
63852e78 3606 m_hasFocus = FALSE;
004fd0c8 3607
49ecb029 3608 RefreshSelected();
e1e955e1 3609}
c801d85f 3610
1e6d9499 3611void wxListMainWindow::DrawImage( int index, wxDC *dc, int x, int y )
c801d85f 3612{
cf1dfa6b 3613 if ( HasFlag(wxLC_ICON) && (m_normal_image_list))
63852e78
RR
3614 {
3615 m_normal_image_list->Draw( index, *dc, x, y, wxIMAGELIST_DRAW_TRANSPARENT );
63852e78 3616 }
cf1dfa6b 3617 else if ( HasFlag(wxLC_SMALL_ICON) && (m_small_image_list))
63852e78
RR
3618 {
3619 m_small_image_list->Draw( index, *dc, x, y, wxIMAGELIST_DRAW_TRANSPARENT );
3620 }
cf1dfa6b 3621 else if ( HasFlag(wxLC_LIST) && (m_small_image_list))
0b855868
RR
3622 {
3623 m_small_image_list->Draw( index, *dc, x, y, wxIMAGELIST_DRAW_TRANSPARENT );
3624 }
cf1dfa6b 3625 else if ( HasFlag(wxLC_REPORT) && (m_small_image_list))
63852e78
RR
3626 {
3627 m_small_image_list->Draw( index, *dc, x, y, wxIMAGELIST_DRAW_TRANSPARENT );
63852e78 3628 }
e1e955e1 3629}
c801d85f 3630
5cd89174 3631void wxListMainWindow::GetImageSize( int index, int &width, int &height ) const
c801d85f 3632{
cf1dfa6b 3633 if ( HasFlag(wxLC_ICON) && m_normal_image_list )
63852e78
RR
3634 {
3635 m_normal_image_list->GetSize( index, width, height );
63852e78 3636 }
cf1dfa6b 3637 else if ( HasFlag(wxLC_SMALL_ICON) && m_small_image_list )
63852e78
RR
3638 {
3639 m_small_image_list->GetSize( index, width, height );
63852e78 3640 }
cf1dfa6b 3641 else if ( HasFlag(wxLC_LIST) && m_small_image_list )
0b855868
RR
3642 {
3643 m_small_image_list->GetSize( index, width, height );
0b855868 3644 }
cf1dfa6b 3645 else if ( HasFlag(wxLC_REPORT) && m_small_image_list )
63852e78
RR
3646 {
3647 m_small_image_list->GetSize( index, width, height );
63852e78 3648 }
cf1dfa6b
VZ
3649 else
3650 {
3651 width =
3652 height = 0;
3653 }
e1e955e1 3654}
c801d85f 3655
5cd89174 3656int wxListMainWindow::GetTextLength( const wxString &s ) const
c801d85f 3657{
5cd89174 3658 wxClientDC dc( wxConstCast(this, wxListMainWindow) );
cf1dfa6b 3659 dc.SetFont( GetFont() );
c801d85f 3660
cf1dfa6b
VZ
3661 wxCoord lw;
3662 dc.GetTextExtent( s, &lw, NULL );
3663
3664 return lw + AUTOSIZE_COL_MARGIN;
e1e955e1 3665}
c801d85f 3666
80020b62 3667void wxListMainWindow::SetImageList( wxImageListType *imageList, int which )
c801d85f 3668{
139adb6a 3669 m_dirty = TRUE;
f6bcfd97
BP
3670
3671 // calc the spacing from the icon size
3672 int width = 0,
3673 height = 0;
3674 if ((imageList) && (imageList->GetImageCount()) )
3675 {
3676 imageList->GetSize(0, width, height);
3677 }
3678
3679 if (which == wxIMAGE_LIST_NORMAL)
3680 {
3681 m_normal_image_list = imageList;
3682 m_normal_spacing = width + 8;
3683 }
3684
3685 if (which == wxIMAGE_LIST_SMALL)
3686 {
3687 m_small_image_list = imageList;
3688 m_small_spacing = width + 14;
3689 }
e1e955e1 3690}
c801d85f 3691
debe6624 3692void wxListMainWindow::SetItemSpacing( int spacing, bool isSmall )
c801d85f 3693{
139adb6a
RR
3694 m_dirty = TRUE;
3695 if (isSmall)
3696 {
3697 m_small_spacing = spacing;
3698 }
3699 else
3700 {
3701 m_normal_spacing = spacing;
3702 }
e1e955e1 3703}
c801d85f 3704
debe6624 3705int wxListMainWindow::GetItemSpacing( bool isSmall )
c801d85f 3706{
f6bcfd97 3707 return isSmall ? m_small_spacing : m_normal_spacing;
e1e955e1 3708}
c801d85f 3709
cf1dfa6b
VZ
3710// ----------------------------------------------------------------------------
3711// columns
3712// ----------------------------------------------------------------------------
3713
debe6624 3714void wxListMainWindow::SetColumn( int col, wxListItem &item )
c801d85f 3715{
24b9f055 3716 wxListHeaderDataList::Node *node = m_columns.Item( col );
f6bcfd97 3717
cf1dfa6b
VZ
3718 wxCHECK_RET( node, _T("invalid column index in SetColumn") );
3719
3720 if ( item.m_width == wxLIST_AUTOSIZE_USEHEADER )
3721 item.m_width = GetTextLength( item.m_text );
3722
3723 wxListHeaderData *column = node->GetData();
3724 column->SetItem( item );
3725
3726 wxListHeaderWindow *headerWin = GetListCtrl()->m_headerWin;
f6bcfd97
BP
3727 if ( headerWin )
3728 headerWin->m_dirty = TRUE;
cf1dfa6b
VZ
3729
3730 m_dirty = TRUE;
3731
3732 // invalidate it as it has to be recalculated
3733 m_headerWidth = 0;
e1e955e1 3734}
c801d85f 3735
debe6624 3736void wxListMainWindow::SetColumnWidth( int col, int width )
c801d85f 3737{
cf1dfa6b
VZ
3738 wxCHECK_RET( col >= 0 && col < GetColumnCount(),
3739 _T("invalid column index") );
3740
3741 wxCHECK_RET( HasFlag(wxLC_REPORT),
f6bcfd97 3742 _T("SetColumnWidth() can only be called in report mode.") );
0208334d 3743
63852e78 3744 m_dirty = TRUE;
abe4a4f1
VS
3745 wxListHeaderWindow *headerWin = GetListCtrl()->m_headerWin;
3746 if ( headerWin )
3747 headerWin->m_dirty = TRUE;
bd8289c1 3748
cf1dfa6b
VZ
3749 wxListHeaderDataList::Node *node = m_columns.Item( col );
3750 wxCHECK_RET( node, _T("no column?") );
3751
3752 wxListHeaderData *column = node->GetData();
3753
3754 size_t count = GetItemCount();
3755
f6bcfd97
BP
3756 if (width == wxLIST_AUTOSIZE_USEHEADER)
3757 {
cf1dfa6b 3758 width = GetTextLength(column->GetText());
f6bcfd97 3759 }
cf1dfa6b 3760 else if ( width == wxLIST_AUTOSIZE )
0180dad6 3761 {
cf1dfa6b
VZ
3762 if ( IsVirtual() )
3763 {
3764 // TODO: determine the max width somehow...
3765 width = WIDTH_COL_DEFAULT;
3766 }
3767 else // !virtual
0180dad6 3768 {
cf1dfa6b
VZ
3769 wxClientDC dc(this);
3770 dc.SetFont( GetFont() );
3771
3772 int max = AUTOSIZE_COL_MARGIN;
3773
3774 for ( size_t i = 0; i < count; i++ )
0180dad6 3775 {
cf1dfa6b
VZ
3776 wxListLineData *line = GetLine(i);
3777 wxListItemDataList::Node *n = line->m_items.Item( col );
3778
3779 wxCHECK_RET( n, _T("no subitem?") );
3780
2c1f73ee 3781 wxListItemData *item = n->GetData();
cf1dfa6b
VZ
3782 int current = 0;
3783
bffa1c77
VZ
3784 if (item->HasImage())
3785 {
cf1dfa6b 3786 int ix, iy;
0180dad6 3787 GetImageSize( item->GetImage(), ix, iy );
cf1dfa6b 3788 current += ix + 5;
bffa1c77 3789 }
cf1dfa6b 3790
bffa1c77
VZ
3791 if (item->HasText())
3792 {
cf1dfa6b
VZ
3793 wxCoord w;
3794 dc.GetTextExtent( item->GetText(), &w, NULL );
3795 current += w;
bffa1c77 3796 }
cf1dfa6b 3797
2c1f73ee
VZ
3798 if (current > max)
3799 max = current;
0180dad6 3800 }
cf1dfa6b
VZ
3801
3802 width = max + AUTOSIZE_COL_MARGIN;
0180dad6 3803 }
0180dad6
RR
3804 }
3805
cf1dfa6b 3806 column->SetWidth( width );
bd8289c1 3807
cf1dfa6b
VZ
3808 // invalidate it as it has to be recalculated
3809 m_headerWidth = 0;
3810}
3811
3812int wxListMainWindow::GetHeaderWidth() const
3813{
3814 if ( !m_headerWidth )
0208334d 3815 {
cf1dfa6b
VZ
3816 wxListMainWindow *self = wxConstCast(this, wxListMainWindow);
3817
3818 size_t count = GetColumnCount();
3819 for ( size_t col = 0; col < count; col++ )
63852e78 3820 {
cf1dfa6b 3821 self->m_headerWidth += GetColumnWidth(col);
63852e78 3822 }
0208334d 3823 }
bd8289c1 3824
cf1dfa6b 3825 return m_headerWidth;
e1e955e1 3826}
c801d85f 3827
cf1dfa6b 3828void wxListMainWindow::GetColumn( int col, wxListItem &item ) const
c801d85f 3829{
24b9f055 3830 wxListHeaderDataList::Node *node = m_columns.Item( col );
cf1dfa6b
VZ
3831 wxCHECK_RET( node, _T("invalid column index in GetColumn") );
3832
3833 wxListHeaderData *column = node->GetData();
3834 column->GetItem( item );
e1e955e1 3835}
c801d85f 3836
cf1dfa6b 3837int wxListMainWindow::GetColumnWidth( int col ) const
c801d85f 3838{
24b9f055
VZ
3839 wxListHeaderDataList::Node *node = m_columns.Item( col );
3840 wxCHECK_MSG( node, 0, _T("invalid column index") );
3841
3842 wxListHeaderData *column = node->GetData();
3843 return column->GetWidth();
e1e955e1 3844}
c801d85f 3845
cf1dfa6b
VZ
3846// ----------------------------------------------------------------------------
3847// item state
3848// ----------------------------------------------------------------------------
c801d85f
KB
3849
3850void wxListMainWindow::SetItem( wxListItem &item )
3851{
cf1dfa6b
VZ
3852 long id = item.m_itemId;
3853 wxCHECK_RET( id >= 0 && (size_t)id < GetItemCount(),
3854 _T("invalid item index in SetItem") );
3855
6c02c329
VZ
3856 if ( !IsVirtual() )
3857 {
3858 wxListLineData *line = GetLine((size_t)id);
3859 line->SetItem( item.m_col, item );
3860 }
3861
285013b3
VZ
3862 // update the item on screen
3863 wxRect rectItem;
3864 GetItemRect(id, rectItem);
3865 RefreshRect(rectItem);
e1e955e1 3866}
c801d85f 3867
cf1dfa6b 3868void wxListMainWindow::SetItemState( long litem, long state, long stateMask )
c801d85f 3869{
cf1dfa6b 3870 wxCHECK_RET( litem >= 0 && (size_t)litem < GetItemCount(),
54442116
VZ
3871 _T("invalid list ctrl item index in SetItem") );
3872
cf1dfa6b 3873 size_t oldCurrent = m_current;
88b792af 3874 size_t item = (size_t)litem; // safe because of the check above
bd8289c1 3875
88b792af 3876 // do we need to change the focus?
54442116 3877 if ( stateMask & wxLIST_STATE_FOCUSED )
c801d85f 3878 {
54442116 3879 if ( state & wxLIST_STATE_FOCUSED )
92976ab6 3880 {
54442116 3881 // don't do anything if this item is already focused
cf1dfa6b 3882 if ( item != m_current )
92976ab6 3883 {
0ddefeb0 3884 ChangeCurrent(item);
cf1dfa6b 3885
88b792af 3886 if ( oldCurrent != (size_t)-1 )
cf1dfa6b 3887 {
88b792af
VZ
3888 if ( IsSingleSel() )
3889 {
3890 HighlightLine(oldCurrent, FALSE);
3891 }
3892
cf1dfa6b
VZ
3893 RefreshLine(oldCurrent);
3894 }
54442116 3895
92976ab6 3896 RefreshLine( m_current );
92976ab6 3897 }
54442116
VZ
3898 }
3899 else // unfocus
3900 {
3901 // don't do anything if this item is not focused
cf1dfa6b 3902 if ( item == m_current )
bffa1c77 3903 {
0ddefeb0 3904 ResetCurrent();
88b792af 3905
943f6ad3
VZ
3906 if ( IsSingleSel() )
3907 {
3908 // we must unselect the old current item as well or we
3909 // might end up with more than one selected item in a
3910 // single selection control
3911 HighlightLine(oldCurrent, FALSE);
3912 }
3913
88b792af 3914 RefreshLine( oldCurrent );
bffa1c77 3915 }
92976ab6 3916 }
e1e955e1 3917 }
54442116 3918
88b792af 3919 // do we need to change the selection state?
54442116
VZ
3920 if ( stateMask & wxLIST_STATE_SELECTED )
3921 {
3922 bool on = (state & wxLIST_STATE_SELECTED) != 0;
54442116 3923
b54e41c5 3924 if ( IsSingleSel() )
54442116 3925 {
cf1dfa6b
VZ
3926 if ( on )
3927 {
3928 // selecting the item also makes it the focused one in the
3929 // single sel mode
3930 if ( m_current != item )
3931 {
0ddefeb0 3932 ChangeCurrent(item);
cf1dfa6b
VZ
3933
3934 if ( oldCurrent != (size_t)-1 )
3935 {
b54e41c5 3936 HighlightLine( oldCurrent, FALSE );
cf1dfa6b
VZ
3937 RefreshLine( oldCurrent );
3938 }
3939 }
3940 }
3941 else // off
3942 {
3943 // only the current item may be selected anyhow
3944 if ( item != m_current )
3945 return;
3946 }
54442116
VZ
3947 }
3948
b54e41c5 3949 if ( HighlightLine(item, on) )
54442116 3950 {
cf1dfa6b 3951 RefreshLine(item);
54442116
VZ
3952 }
3953 }
e1e955e1 3954}
c801d85f 3955
62d89eb4 3956int wxListMainWindow::GetItemState( long item, long stateMask ) const
c801d85f 3957{
cf1dfa6b
VZ
3958 wxCHECK_MSG( item >= 0 && (size_t)item < GetItemCount(), 0,
3959 _T("invalid list ctrl item index in GetItemState()") );
3960
92976ab6 3961 int ret = wxLIST_STATE_DONTCARE;
cf1dfa6b
VZ
3962
3963 if ( stateMask & wxLIST_STATE_FOCUSED )
c801d85f 3964 {
cf1dfa6b
VZ
3965 if ( (size_t)item == m_current )
3966 ret |= wxLIST_STATE_FOCUSED;
e1e955e1 3967 }
cf1dfa6b
VZ
3968
3969 if ( stateMask & wxLIST_STATE_SELECTED )
c801d85f 3970 {
b54e41c5 3971 if ( IsHighlighted(item) )
cf1dfa6b 3972 ret |= wxLIST_STATE_SELECTED;
e1e955e1 3973 }
cf1dfa6b 3974
92976ab6 3975 return ret;
e1e955e1 3976}
c801d85f 3977
62d89eb4 3978void wxListMainWindow::GetItem( wxListItem &item ) const
c801d85f 3979{
cf1dfa6b
VZ
3980 wxCHECK_RET( item.m_itemId >= 0 && (size_t)item.m_itemId < GetItemCount(),
3981 _T("invalid item index in GetItem") );
3982
3983 wxListLineData *line = GetLine((size_t)item.m_itemId);
3984 line->GetItem( item.m_col, item );
e1e955e1 3985}
c801d85f 3986
cf1dfa6b
VZ
3987// ----------------------------------------------------------------------------
3988// item count
3989// ----------------------------------------------------------------------------
3990
3991size_t wxListMainWindow::GetItemCount() const
1370703e
VZ
3992{
3993 return IsVirtual() ? m_countVirt : m_lines.GetCount();
3994}
3995
3996void wxListMainWindow::SetItemCount(long count)
c801d85f 3997{
b54e41c5 3998 m_selStore.SetItemCount(count);
1370703e
VZ
3999 m_countVirt = count;
4000
850ed6e7
VZ
4001 ResetVisibleLinesRange();
4002
5fe143df
VZ
4003 // scrollbars must be reset
4004 m_dirty = TRUE;
e1e955e1 4005}
c801d85f 4006
62d89eb4 4007int wxListMainWindow::GetSelectedItemCount() const
c801d85f 4008{
cf1dfa6b 4009 // deal with the quick case first
b54e41c5 4010 if ( IsSingleSel() )
92976ab6 4011 {
b54e41c5 4012 return HasCurrent() ? IsHighlighted(m_current) : FALSE;
92976ab6 4013 }
cf1dfa6b
VZ
4014
4015 // virtual controls remmebers all its selections itself
4016 if ( IsVirtual() )
b54e41c5 4017 return m_selStore.GetSelectedCount();
cf1dfa6b
VZ
4018
4019 // TODO: we probably should maintain the number of items selected even for
4020 // non virtual controls as enumerating all lines is really slow...
4021 size_t countSel = 0;
4022 size_t count = GetItemCount();
4023 for ( size_t line = 0; line < count; line++ )
92976ab6 4024 {
b54e41c5 4025 if ( GetLine(line)->IsHighlighted() )
cf1dfa6b 4026 countSel++;
92976ab6 4027 }
c801d85f 4028
cf1dfa6b 4029 return countSel;
e1e955e1 4030}
e3e65dac 4031
cf1dfa6b
VZ
4032// ----------------------------------------------------------------------------
4033// item position/size
4034// ----------------------------------------------------------------------------
4035
62d89eb4 4036void wxListMainWindow::GetItemRect( long index, wxRect &rect ) const
c801d85f 4037{
cf1dfa6b
VZ
4038 wxCHECK_RET( index >= 0 && (size_t)index < GetItemCount(),
4039 _T("invalid index in GetItemRect") );
4040
5cd89174 4041 rect = GetLineRect((size_t)index);
b54e41c5 4042
cf1dfa6b 4043 CalcScrolledPosition(rect.x, rect.y, &rect.x, &rect.y);
e1e955e1 4044}
c801d85f 4045
62d89eb4 4046bool wxListMainWindow::GetItemPosition(long item, wxPoint& pos) const
c801d85f 4047{
cf1dfa6b
VZ
4048 wxRect rect;
4049 GetItemRect(item, rect);
bd8289c1 4050
cf1dfa6b
VZ
4051 pos.x = rect.x;
4052 pos.y = rect.y;
bd8289c1 4053
cf1dfa6b 4054 return TRUE;
e1e955e1 4055}
c801d85f 4056
cf1dfa6b
VZ
4057// ----------------------------------------------------------------------------
4058// geometry calculation
4059// ----------------------------------------------------------------------------
4060
34bbbc27 4061void wxListMainWindow::RecalculatePositions(bool noRefresh)
c801d85f 4062{
1e6d9499 4063 wxClientDC dc( this );
92976ab6 4064 dc.SetFont( GetFont() );
c801d85f 4065
cf1dfa6b
VZ
4066 int iconSpacing;
4067 if ( HasFlag(wxLC_ICON) )
4068 iconSpacing = m_normal_spacing;
4069 else if ( HasFlag(wxLC_SMALL_ICON) )
4070 iconSpacing = m_small_spacing;
4071 else
4072 iconSpacing = 0;
004fd0c8 4073
bf632edd
RR
4074 // Note that we do not call GetClientSize() here but
4075 // GetSize() and substract the border size for sunken
4076 // borders manually. This is technically incorrect,
4077 // but we need to know the client area's size WITHOUT
4078 // scrollbars here. Since we don't know if there are
4079 // any scrollbars, we use GetSize() instead. Another
4080 // solution would be to call SetScrollbars() here to
4081 // remove the scrollbars and call GetClientSize() then,
4082 // but this might result in flicker and - worse - will
4083 // reset the scrollbars to 0 which is not good at all
4084 // if you resize a dialog/window, but don't want to
4085 // reset the window scrolling. RR.
4086 // Furthermore, we actually do NOT subtract the border
4087 // width as 2 pixels is just the extra space which we
4088 // need around the actual content in the window. Other-
4089 // wise the text would e.g. touch the upper border. RR.
cf1dfa6b
VZ
4090 int clientWidth,
4091 clientHeight;
bf632edd 4092 GetSize( &clientWidth, &clientHeight );
a77ec46d 4093
cf1dfa6b
VZ
4094 if ( HasFlag(wxLC_REPORT) )
4095 {
4096 // all lines have the same height
b54e41c5 4097 int lineHeight = GetLineHeight();
c801d85f 4098
cf1dfa6b 4099 // scroll one line per step
b54e41c5 4100 m_yScroll = lineHeight;
bd8289c1 4101
cf1dfa6b 4102 size_t lineCount = GetItemCount();
b54e41c5 4103 int entireHeight = lineCount*lineHeight + LINE_SPACING;
bd8289c1 4104
b54e41c5
VZ
4105 m_linesPerPage = clientHeight / lineHeight;
4106
4107 ResetVisibleLinesRange();
2c1f73ee 4108
cf1dfa6b 4109 SetScrollbars( m_xScroll, m_yScroll,
c020c47e 4110 GetHeaderWidth() / m_xScroll,
cf1dfa6b
VZ
4111 (entireHeight + m_yScroll - 1)/m_yScroll,
4112 GetScrollPos(wxHORIZONTAL),
4113 GetScrollPos(wxVERTICAL),
4114 TRUE );
e1e955e1 4115 }
cf1dfa6b 4116 else // !report
92976ab6
RR
4117 {
4118 // at first we try without any scrollbar. if the items don't
4119 // fit into the window, we recalculate after subtracting an
4120 // approximated 15 pt for the horizontal scrollbar
004fd0c8 4121
b54e41c5 4122 int entireWidth = 0;
bd8289c1 4123
92976ab6 4124 for (int tries = 0; tries < 2; tries++)
e487524e 4125 {
5d684756
RR
4126 // We start with 4 for the border around all items
4127 entireWidth = 4;
a77ec46d 4128
5d684756
RR
4129 if (tries == 1)
4130 {
4131 // Now we have decided that the items do not fit into the
4132 // client area. Unfortunately, wxWindows sometimes thinks
4133 // that it does fit and therefore NO horizontal scrollbar
4134 // is inserted. This looks ugly, so we fudge here and make
4135 // the calculated width bigger than was actually has been
4136 // calculated. This ensures that wxScrolledWindows puts
4137 // a scrollbar at the bottom of its client area.
4138 entireWidth += SCROLL_UNIT_X;
4139 }
a77ec46d 4140
bf632edd 4141 // Start at 2,2 so the text does not touch the border
5d25c050
RR
4142 int x = 2;
4143 int y = 2;
92976ab6 4144 int maxWidth = 0;
cf1dfa6b
VZ
4145 m_linesPerPage = 0;
4146 int currentlyVisibleLines = 0;
4147
4148 size_t count = GetItemCount();
4149 for (size_t i = 0; i < count; i++)
92976ab6 4150 {
cf1dfa6b
VZ
4151 currentlyVisibleLines++;
4152 wxListLineData *line = GetLine(i);
92976ab6 4153 line->CalculateSize( &dc, iconSpacing );
5d684756 4154 line->SetPosition( x, y, clientWidth, iconSpacing ); // Why clientWidth? (FIXME)
cf1dfa6b 4155
5cd89174 4156 wxSize sizeLine = GetLineSize(i);
cf1dfa6b
VZ
4157
4158 if ( maxWidth < sizeLine.x )
4159 maxWidth = sizeLine.x;
4160
4161 y += sizeLine.y;
4162 if (currentlyVisibleLines > m_linesPerPage)
4163 m_linesPerPage = currentlyVisibleLines;
4164
5d684756 4165 // Assume that the size of the next one is the same... (FIXME)
bf632edd 4166 if ( y + sizeLine.y >= clientHeight )
92976ab6 4167 {
cf1dfa6b 4168 currentlyVisibleLines = 0;
e1208c31 4169 y = 2;
8b53e5a2
RR
4170 x += maxWidth+6;
4171 entireWidth += maxWidth+6;
92976ab6
RR
4172 maxWidth = 0;
4173 }
a77ec46d 4174
5d684756 4175 // We have reached the last item.
cf1dfa6b
VZ
4176 if ( i == count - 1 )
4177 entireWidth += maxWidth;
a77ec46d 4178
5d684756 4179 if ( (tries == 0) && (entireWidth+SCROLL_UNIT_X > clientWidth) )
92976ab6 4180 {
5d684756 4181 clientHeight -= 15; // We guess the scrollbar height. (FIXME)
cf1dfa6b
VZ
4182 m_linesPerPage = 0;
4183 currentlyVisibleLines = 0;
92976ab6
RR
4184 break;
4185 }
a77ec46d 4186
cf1dfa6b 4187 if ( i == count - 1 )
5d684756 4188 tries = 1; // Everything fits, no second try required.
92976ab6 4189 }
e487524e 4190 }
bffa1c77 4191
92976ab6 4192 int scroll_pos = GetScrollPos( wxHORIZONTAL );
cf1dfa6b 4193 SetScrollbars( m_xScroll, m_yScroll, (entireWidth+SCROLL_UNIT_X) / m_xScroll, 0, scroll_pos, 0, TRUE );
e1e955e1 4194 }
cf1dfa6b 4195
34bbbc27
VZ
4196 if ( !noRefresh )
4197 {
4198 // FIXME: why should we call it from here?
4199 UpdateCurrent();
b54e41c5 4200
34bbbc27
VZ
4201 RefreshAll();
4202 }
b54e41c5
VZ
4203}
4204
4205void wxListMainWindow::RefreshAll()
4206{
4207 m_dirty = FALSE;
4208 Refresh();
4209
4210 wxListHeaderWindow *headerWin = GetListCtrl()->m_headerWin;
70541533 4211 if ( headerWin && headerWin->m_dirty )
b54e41c5
VZ
4212 {
4213 headerWin->m_dirty = FALSE;
4214 headerWin->Refresh();
4215 }
e1e955e1 4216}
c801d85f 4217
cf1dfa6b 4218void wxListMainWindow::UpdateCurrent()
c801d85f 4219{
b54e41c5 4220 if ( !HasCurrent() && !IsEmpty() )
92976ab6 4221 {
0ddefeb0 4222 ChangeCurrent(0);
92976ab6 4223 }
e1e955e1 4224}
c801d85f 4225
19695fbd
VZ
4226long wxListMainWindow::GetNextItem( long item,
4227 int WXUNUSED(geometry),
62d89eb4 4228 int state ) const
c801d85f 4229{
d1022fd6
VZ
4230 long ret = item,
4231 max = GetItemCount();
4232 wxCHECK_MSG( (ret == -1) || (ret < max), -1,
13771c08 4233 _T("invalid listctrl index in GetNextItem()") );
19695fbd
VZ
4234
4235 // notice that we start with the next item (or the first one if item == -1)
4236 // and this is intentional to allow writing a simple loop to iterate over
4237 // all selected items
d1022fd6
VZ
4238 ret++;
4239 if ( ret == max )
4240 {
4241 // this is not an error because the index was ok initially, just no
4242 // such item
4243 return -1;
4244 }
4245
cf1dfa6b
VZ
4246 if ( !state )
4247 {
4248 // any will do
4249 return (size_t)ret;
4250 }
4251
4252 size_t count = GetItemCount();
4253 for ( size_t line = (size_t)ret; line < count; line++ )
63852e78 4254 {
cf1dfa6b
VZ
4255 if ( (state & wxLIST_STATE_FOCUSED) && (line == m_current) )
4256 return line;
4257
b54e41c5 4258 if ( (state & wxLIST_STATE_SELECTED) && IsHighlighted(line) )
cf1dfa6b 4259 return line;
63852e78 4260 }
19695fbd 4261
63852e78 4262 return -1;
e1e955e1 4263}
c801d85f 4264
cf1dfa6b
VZ
4265// ----------------------------------------------------------------------------
4266// deleting stuff
4267// ----------------------------------------------------------------------------
4268
b54e41c5 4269void wxListMainWindow::DeleteItem( long lindex )
c801d85f 4270{
cf1dfa6b
VZ
4271 size_t count = GetItemCount();
4272
b54e41c5 4273 wxCHECK_RET( (lindex >= 0) && ((size_t)lindex < count),
cf1dfa6b
VZ
4274 _T("invalid item index in DeleteItem") );
4275
b54e41c5
VZ
4276 size_t index = (size_t)lindex;
4277
d6ddcd57
VZ
4278 // we don't need to adjust the index for the previous items
4279 if ( HasCurrent() && m_current >= index )
cf1dfa6b 4280 {
d6ddcd57
VZ
4281 // if the current item is being deleted, we want the next one to
4282 // become selected - unless there is no next one - so don't adjust
4283 // m_current in this case
4284 if ( m_current != index || m_current == count - 1 )
4285 {
4286 m_current--;
4287 }
cf1dfa6b
VZ
4288 }
4289
938b652b 4290 if ( InReportView() )
63852e78 4291 {
6b4a8d93 4292 ResetVisibleLinesRange();
938b652b
VZ
4293 }
4294
938b652b
VZ
4295 if ( IsVirtual() )
4296 {
4297 m_countVirt--;
b54e41c5
VZ
4298
4299 m_selStore.OnItemDelete(index);
4300 }
4301 else
4302 {
4303 m_lines.RemoveAt( index );
63852e78 4304 }
6b4a8d93 4305
70541533 4306 // we need to refresh the (vert) scrollbar as the number of items changed
b84839ae 4307 m_dirty = TRUE;
91c6cc0e
VZ
4308
4309 SendNotify( index, wxEVT_COMMAND_LIST_DELETE_ITEM );
4310
6b4a8d93 4311 RefreshAfter(index);
e1e955e1 4312}
c801d85f 4313
debe6624 4314void wxListMainWindow::DeleteColumn( int col )
c801d85f 4315{
24b9f055
VZ
4316 wxListHeaderDataList::Node *node = m_columns.Item( col );
4317
4318 wxCHECK_RET( node, wxT("invalid column index in DeleteColumn()") );
bd8289c1 4319
5b077d48 4320 m_dirty = TRUE;
24b9f055 4321 m_columns.DeleteNode( node );
ae409cb8
VZ
4322
4323 // invalidate it as it has to be recalculated
4324 m_headerWidth = 0;
e1e955e1 4325}
c801d85f 4326
5fe143df 4327void wxListMainWindow::DoDeleteAllItems()
c801d85f 4328{
cf1dfa6b
VZ
4329 if ( IsEmpty() )
4330 {
4331 // nothing to do - in particular, don't send the event
4332 return;
4333 }
4334
b54e41c5 4335 ResetCurrent();
7c0ea335
VZ
4336
4337 // to make the deletion of all items faster, we don't send the
cf1dfa6b
VZ
4338 // notifications for each item deletion in this case but only one event
4339 // for all of them: this is compatible with wxMSW and documented in
4340 // DeleteAllItems() description
bffa1c77 4341
12c1b46a
RR
4342 wxListEvent event( wxEVT_COMMAND_LIST_DELETE_ALL_ITEMS, GetParent()->GetId() );
4343 event.SetEventObject( GetParent() );
4344 GetParent()->GetEventHandler()->ProcessEvent( event );
7c0ea335 4345
b54e41c5
VZ
4346 if ( IsVirtual() )
4347 {
4348 m_countVirt = 0;
4349
850ed6e7 4350 m_selStore.Clear();
b54e41c5
VZ
4351 }
4352
6b4a8d93
VZ
4353 if ( InReportView() )
4354 {
4355 ResetVisibleLinesRange();
4356 }
4357
5b077d48 4358 m_lines.Clear();
5fe143df 4359}
cf1dfa6b 4360
5fe143df
VZ
4361void wxListMainWindow::DeleteAllItems()
4362{
4363 DoDeleteAllItems();
4364
4365 RecalculatePositions();
e1e955e1 4366}
c801d85f 4367
12c1b46a 4368void wxListMainWindow::DeleteEverything()
c801d85f 4369{
5b077d48 4370 m_columns.Clear();
904ccf52
VZ
4371
4372 DeleteAllItems();
e1e955e1 4373}
c801d85f 4374
cf1dfa6b
VZ
4375// ----------------------------------------------------------------------------
4376// scanning for an item
4377// ----------------------------------------------------------------------------
4378
debe6624 4379void wxListMainWindow::EnsureVisible( long index )
c801d85f 4380{
cf1dfa6b
VZ
4381 wxCHECK_RET( index >= 0 && (size_t)index < GetItemCount(),
4382 _T("invalid index in EnsureVisible") );
4383
4384 // We have to call this here because the label in question might just have
34bbbc27
VZ
4385 // been added and its position is not known yet
4386 if ( m_dirty )
4387 {
34bbbc27
VZ
4388 RecalculatePositions(TRUE /* no refresh */);
4389 }
4390
4391 MoveToItem((size_t)index);
e1e955e1 4392}
c801d85f 4393
debe6624 4394long wxListMainWindow::FindItem(long start, const wxString& str, bool WXUNUSED(partial) )
c801d85f 4395{
5b077d48
RR
4396 long pos = start;
4397 wxString tmp = str;
cf1dfa6b
VZ
4398 if (pos < 0)
4399 pos = 0;
54442116 4400
cf1dfa6b
VZ
4401 size_t count = GetItemCount();
4402 for ( size_t i = (size_t)pos; i < count; i++ )
4403 {
4404 wxListLineData *line = GetLine(i);
4405 if ( line->GetText(0) == tmp )
4406 return i;
5b077d48 4407 }
cf1dfa6b
VZ
4408
4409 return wxNOT_FOUND;
e1e955e1 4410}
c801d85f 4411
debe6624 4412long wxListMainWindow::FindItem(long start, long data)
c801d85f 4413{
5b077d48 4414 long pos = start;
cf1dfa6b
VZ
4415 if (pos < 0)
4416 pos = 0;
4417
4418 size_t count = GetItemCount();
4419 for (size_t i = (size_t)pos; i < count; i++)
5b077d48 4420 {
cf1dfa6b 4421 wxListLineData *line = GetLine(i);
5b077d48
RR
4422 wxListItem item;
4423 line->GetItem( 0, item );
cf1dfa6b
VZ
4424 if (item.m_data == data)
4425 return i;
5b077d48 4426 }
cf1dfa6b
VZ
4427
4428 return wxNOT_FOUND;
e1e955e1 4429}
c801d85f 4430
debe6624 4431long wxListMainWindow::HitTest( int x, int y, int &flags )
c801d85f 4432{
aaef15bf 4433 CalcUnscrolledPosition( x, y, &x, &y );
e8741cca 4434
fc4f1d5f
VZ
4435 size_t count = GetItemCount();
4436
5cd89174 4437 if ( HasFlag(wxLC_REPORT) )
c801d85f 4438 {
5cd89174 4439 size_t current = y / GetLineHeight();
fc4f1d5f
VZ
4440 if ( current < count )
4441 {
4442 flags = HitTestLine(current, x, y);
4443 if ( flags )
4444 return current;
4445 }
5cd89174
VZ
4446 }
4447 else // !report
4448 {
4449 // TODO: optimize it too! this is less simple than for report view but
4450 // enumerating all items is still not a way to do it!!
5cd89174 4451 for ( size_t current = 0; current < count; current++ )
5b077d48 4452 {
5cd89174
VZ
4453 flags = HitTestLine(current, x, y);
4454 if ( flags )
4455 return current;
5b077d48 4456 }
e1e955e1 4457 }
cf1dfa6b
VZ
4458
4459 return wxNOT_FOUND;
e1e955e1 4460}
c801d85f 4461
cf1dfa6b
VZ
4462// ----------------------------------------------------------------------------
4463// adding stuff
4464// ----------------------------------------------------------------------------
4465
c801d85f
KB
4466void wxListMainWindow::InsertItem( wxListItem &item )
4467{
cf1dfa6b
VZ
4468 wxASSERT_MSG( !IsVirtual(), _T("can't be used with virtual control") );
4469
4470 size_t count = GetItemCount();
4471 wxCHECK_RET( item.m_itemId >= 0 && (size_t)item.m_itemId <= count,
4472 _T("invalid item index") );
4473
4474 size_t id = item.m_itemId;
4475
5b077d48 4476 m_dirty = TRUE;
cf1dfa6b 4477
5b077d48 4478 int mode = 0;
cf1dfa6b 4479 if ( HasFlag(wxLC_REPORT) )
2b5f62a0 4480 {
1370703e 4481 mode = wxLC_REPORT;
2b5f62a0
VZ
4482 ResetVisibleLinesRange();
4483 }
cf1dfa6b 4484 else if ( HasFlag(wxLC_LIST) )
1370703e 4485 mode = wxLC_LIST;
cf1dfa6b 4486 else if ( HasFlag(wxLC_ICON) )
1370703e 4487 mode = wxLC_ICON;
cf1dfa6b 4488 else if ( HasFlag(wxLC_SMALL_ICON) )
1370703e
VZ
4489 mode = wxLC_ICON; // no typo
4490 else
4491 {
4492 wxFAIL_MSG( _T("unknown mode") );
4493 }
004fd0c8 4494
5cd89174 4495 wxListLineData *line = new wxListLineData(this);
004fd0c8 4496
5b077d48 4497 line->SetItem( 0, item );
cf1dfa6b
VZ
4498
4499 m_lines.Insert( line, id );
5cd89174 4500
b84839ae 4501 m_dirty = TRUE;
5cd89174 4502 RefreshLines(id, GetItemCount() - 1);
e1e955e1 4503}
c801d85f 4504
debe6624 4505void wxListMainWindow::InsertColumn( long col, wxListItem &item )
c801d85f 4506{
5b077d48 4507 m_dirty = TRUE;
cf1dfa6b 4508 if ( HasFlag(wxLC_REPORT) )
3db7be80 4509 {
54442116
VZ
4510 if (item.m_width == wxLIST_AUTOSIZE_USEHEADER)
4511 item.m_width = GetTextLength( item.m_text );
5b077d48
RR
4512 wxListHeaderData *column = new wxListHeaderData( item );
4513 if ((col >= 0) && (col < (int)m_columns.GetCount()))
4514 {
24b9f055
VZ
4515 wxListHeaderDataList::Node *node = m_columns.Item( col );
4516 m_columns.Insert( node, column );
5b077d48
RR
4517 }
4518 else
4519 {
4520 m_columns.Append( column );
4521 }
ae409cb8
VZ
4522
4523 // invalidate it as it has to be recalculated
4524 m_headerWidth = 0;
3db7be80 4525 }
e1e955e1 4526}
c801d85f 4527
cf1dfa6b
VZ
4528// ----------------------------------------------------------------------------
4529// sorting
4530// ----------------------------------------------------------------------------
4531
c801d85f
KB
4532wxListCtrlCompare list_ctrl_compare_func_2;
4533long list_ctrl_compare_data;
4534
f6bcfd97 4535int LINKAGEMODE list_ctrl_compare_func_1( wxListLineData **arg1, wxListLineData **arg2 )
c801d85f 4536{
f6bcfd97
BP
4537 wxListLineData *line1 = *arg1;
4538 wxListLineData *line2 = *arg2;
5b077d48
RR
4539 wxListItem item;
4540 line1->GetItem( 0, item );
4541 long data1 = item.m_data;
4542 line2->GetItem( 0, item );
4543 long data2 = item.m_data;
4544 return list_ctrl_compare_func_2( data1, data2, list_ctrl_compare_data );
e1e955e1 4545}
c801d85f
KB
4546
4547void wxListMainWindow::SortItems( wxListCtrlCompare fn, long data )
4548{
5b077d48
RR
4549 list_ctrl_compare_func_2 = fn;
4550 list_ctrl_compare_data = data;
4551 m_lines.Sort( list_ctrl_compare_func_1 );
af7c1052 4552 m_dirty = TRUE;
e1e955e1 4553}
c801d85f 4554
cf1dfa6b
VZ
4555// ----------------------------------------------------------------------------
4556// scrolling
4557// ----------------------------------------------------------------------------
4558
7c74e7fe
SC
4559void wxListMainWindow::OnScroll(wxScrollWinEvent& event)
4560{
b54e41c5
VZ
4561 // update our idea of which lines are shown when we redraw the window the
4562 // next time
4563 ResetVisibleLinesRange();
cf1dfa6b 4564
29149a64 4565 // FIXME
3a8c693a 4566#if defined(__WXGTK__) && !defined(__WXUNIVERSAL__)
29149a64
VZ
4567 wxScrolledWindow::OnScroll(event);
4568#else
1e6feb95 4569 HandleOnScroll( event );
29149a64 4570#endif
30954328 4571
cf1dfa6b 4572 if ( event.GetOrientation() == wxHORIZONTAL && HasHeader() )
7c74e7fe 4573 {
3cd94a0d 4574 wxGenericListCtrl* lc = GetListCtrl();
cf1dfa6b
VZ
4575 wxCHECK_RET( lc, _T("no listctrl window?") );
4576
afbe906a
RR
4577 lc->m_headerWin->Refresh();
4578 lc->m_headerWin->Update();
7c74e7fe 4579 }
cf1dfa6b
VZ
4580}
4581
5cd89174
VZ
4582int wxListMainWindow::GetCountPerPage() const
4583{
4584 if ( !m_linesPerPage )
4585 {
4586 wxConstCast(this, wxListMainWindow)->
4587 m_linesPerPage = GetClientSize().y / GetLineHeight();
4588 }
4589
4590 return m_linesPerPage;
4591}
4592
b54e41c5 4593void wxListMainWindow::GetVisibleLinesRange(size_t *from, size_t *to)
cf1dfa6b 4594{
b54e41c5 4595 wxASSERT_MSG( HasFlag(wxLC_REPORT), _T("this is for report mode only") );
cf1dfa6b 4596
b54e41c5
VZ
4597 if ( m_lineFrom == (size_t)-1 )
4598 {
b54e41c5 4599 size_t count = GetItemCount();
6522713c
VZ
4600 if ( count )
4601 {
4602 m_lineFrom = GetScrollPos(wxVERTICAL);
cf1dfa6b 4603
152c57f2
VZ
4604 // this may happen if SetScrollbars() hadn't been called yet
4605 if ( m_lineFrom >= count )
bcc0da5c 4606 m_lineFrom = count - 1;
cf1dfa6b 4607
6522713c
VZ
4608 // we redraw one extra line but this is needed to make the redrawing
4609 // logic work when there is a fractional number of lines on screen
4610 m_lineTo = m_lineFrom + m_linesPerPage;
4611 if ( m_lineTo >= count )
4612 m_lineTo = count - 1;
4613 }
4614 else // empty control
4615 {
4616 m_lineFrom = 0;
4617 m_lineTo = (size_t)-1;
4618 }
cf1dfa6b 4619 }
b54e41c5 4620
ae167d2f
VZ
4621 wxASSERT_MSG( IsEmpty() ||
4622 (m_lineFrom <= m_lineTo && m_lineTo < GetItemCount()),
6b4a8d93
VZ
4623 _T("GetVisibleLinesRange() returns incorrect result") );
4624
b54e41c5
VZ
4625 if ( from )
4626 *from = m_lineFrom;
4627 if ( to )
4628 *to = m_lineTo;
7c74e7fe
SC
4629}
4630
c801d85f 4631// -------------------------------------------------------------------------------------
3cd94a0d 4632// wxGenericListCtrl
c801d85f
KB
4633// -------------------------------------------------------------------------------------
4634
3cd94a0d
JS
4635IMPLEMENT_DYNAMIC_CLASS(wxGenericListCtrl, wxControl)
4636
3cd94a0d
JS
4637BEGIN_EVENT_TABLE(wxGenericListCtrl,wxControl)
4638 EVT_SIZE(wxGenericListCtrl::OnSize)
4639 EVT_IDLE(wxGenericListCtrl::OnIdle)
c801d85f
KB
4640END_EVENT_TABLE()
4641
3cd94a0d 4642wxGenericListCtrl::wxGenericListCtrl()
c801d85f 4643{
80020b62
JS
4644 m_imageListNormal = (wxImageListType *) NULL;
4645 m_imageListSmall = (wxImageListType *) NULL;
4646 m_imageListState = (wxImageListType *) NULL;
cf1dfa6b
VZ
4647
4648 m_ownsImageListNormal =
4649 m_ownsImageListSmall =
4650 m_ownsImageListState = FALSE;
4651
5b077d48
RR
4652 m_mainWin = (wxListMainWindow*) NULL;
4653 m_headerWin = (wxListHeaderWindow*) NULL;
c801d85f
KB
4654}
4655
3cd94a0d 4656wxGenericListCtrl::~wxGenericListCtrl()
c801d85f 4657{
cf1dfa6b
VZ
4658 if (m_ownsImageListNormal)
4659 delete m_imageListNormal;
4660 if (m_ownsImageListSmall)
4661 delete m_imageListSmall;
4662 if (m_ownsImageListState)
4663 delete m_imageListState;
4664}
4665
3cd94a0d 4666void wxGenericListCtrl::CreateHeaderWindow()
cf1dfa6b
VZ
4667{
4668 m_headerWin = new wxListHeaderWindow
4669 (
4670 this, -1, m_mainWin,
4671 wxPoint(0, 0),
4672 wxSize(GetClientSize().x, HEADER_HEIGHT),
4673 wxTAB_TRAVERSAL
4674 );
c801d85f
KB
4675}
4676
3cd94a0d 4677bool wxGenericListCtrl::Create(wxWindow *parent,
25e3a937
VZ
4678 wxWindowID id,
4679 const wxPoint &pos,
4680 const wxSize &size,
4681 long style,
25e3a937 4682 const wxValidator &validator,
25e3a937 4683 const wxString &name)
c801d85f 4684{
cf1dfa6b
VZ
4685 m_imageListNormal =
4686 m_imageListSmall =
80020b62 4687 m_imageListState = (wxImageListType *) NULL;
cf1dfa6b
VZ
4688 m_ownsImageListNormal =
4689 m_ownsImageListSmall =
4690 m_ownsImageListState = FALSE;
4691
5b077d48
RR
4692 m_mainWin = (wxListMainWindow*) NULL;
4693 m_headerWin = (wxListHeaderWindow*) NULL;
bd8289c1 4694
b54e41c5 4695 if ( !(style & wxLC_MASK_TYPE) )
5b077d48 4696 {
25e3a937 4697 style = style | wxLC_LIST;
5b077d48 4698 }
f6bcfd97 4699
07215d86 4700 if ( !wxControl::Create( parent, id, pos, size, style, validator, name ) )
cf1dfa6b 4701 return FALSE;
f6bcfd97 4702
b54e41c5
VZ
4703 // don't create the inner window with the border
4704 style &= ~wxSUNKEN_BORDER;
bd8289c1 4705
25e3a937 4706 m_mainWin = new wxListMainWindow( this, -1, wxPoint(0,0), size, style );
bd8289c1 4707
b54e41c5 4708 if ( HasFlag(wxLC_REPORT) )
ea451729 4709 {
cf1dfa6b
VZ
4710 CreateHeaderWindow();
4711
b54e41c5 4712 if ( HasFlag(wxLC_NO_HEADER) )
cf1dfa6b
VZ
4713 {
4714 // VZ: why do we create it at all then?
ea451729 4715 m_headerWin->Show( FALSE );
cf1dfa6b 4716 }
ea451729 4717 }
bd8289c1 4718
cf1dfa6b 4719 return TRUE;
e1e955e1 4720}
c801d85f 4721
3cd94a0d 4722void wxGenericListCtrl::SetSingleStyle( long style, bool add )
c801d85f 4723{
b54e41c5
VZ
4724 wxASSERT_MSG( !(style & wxLC_VIRTUAL),
4725 _T("wxLC_VIRTUAL can't be [un]set") );
4726
f03fc89f 4727 long flag = GetWindowStyle();
bd8289c1 4728
5b077d48
RR
4729 if (add)
4730 {
cf1dfa6b 4731 if (style & wxLC_MASK_TYPE)
b54e41c5 4732 flag &= ~(wxLC_MASK_TYPE | wxLC_VIRTUAL);
cf1dfa6b
VZ
4733 if (style & wxLC_MASK_ALIGN)
4734 flag &= ~wxLC_MASK_ALIGN;
4735 if (style & wxLC_MASK_SORT)
4736 flag &= ~wxLC_MASK_SORT;
5b077d48 4737 }
c801d85f 4738
5b077d48
RR
4739 if (add)
4740 {
4741 flag |= style;
4742 }
4743 else
4744 {
cf1dfa6b 4745 flag &= ~style;
5b077d48 4746 }
bd8289c1 4747
5b077d48 4748 SetWindowStyleFlag( flag );
e1e955e1 4749}
c801d85f 4750
3cd94a0d 4751void wxGenericListCtrl::SetWindowStyleFlag( long flag )
c801d85f 4752{
121a3581
RR
4753 if (m_mainWin)
4754 {
4755 m_mainWin->DeleteEverything();
c801d85f 4756
a95cdab8
VZ
4757 // has the header visibility changed?
4758 bool hasHeader = HasFlag(wxLC_REPORT) && !HasFlag(wxLC_NO_HEADER),
4759 willHaveHeader = (flag & wxLC_REPORT) && !(flag & wxLC_NO_HEADER);
c801d85f 4760
a95cdab8 4761 if ( hasHeader != willHaveHeader )
5b077d48 4762 {
a95cdab8
VZ
4763 // toggle it
4764 if ( hasHeader )
4765 {
4766 if ( m_headerWin )
4767 {
4768 // don't delete, just hide, as we can reuse it later
4769 m_headerWin->Show(FALSE);
4770 }
4771 //else: nothing to do
4772 }
4773 else // must show header
5b077d48 4774 {
121a3581
RR
4775 if (!m_headerWin)
4776 {
cf1dfa6b 4777 CreateHeaderWindow();
121a3581 4778 }
a95cdab8 4779 else // already have it, just show
004fd0c8 4780 {
a95cdab8 4781 m_headerWin->Show( TRUE );
004fd0c8 4782 }
5b077d48 4783 }
a95cdab8
VZ
4784
4785 ResizeReportView(willHaveHeader);
bffa1c77 4786 }
e1e955e1 4787 }
004fd0c8 4788
5b077d48 4789 wxWindow::SetWindowStyleFlag( flag );
e1e955e1 4790}
c801d85f 4791
3cd94a0d 4792bool wxGenericListCtrl::GetColumn(int col, wxListItem &item) const
c801d85f 4793{
5b077d48
RR
4794 m_mainWin->GetColumn( col, item );
4795 return TRUE;
e1e955e1 4796}
c801d85f 4797
3cd94a0d 4798bool wxGenericListCtrl::SetColumn( int col, wxListItem& item )
c801d85f 4799{
5b077d48
RR
4800 m_mainWin->SetColumn( col, item );
4801 return TRUE;
e1e955e1 4802}
c801d85f 4803
3cd94a0d 4804int wxGenericListCtrl::GetColumnWidth( int col ) const
c801d85f 4805{
5b077d48 4806 return m_mainWin->GetColumnWidth( col );
e1e955e1 4807}
c801d85f 4808
3cd94a0d 4809bool wxGenericListCtrl::SetColumnWidth( int col, int width )
c801d85f 4810{
5b077d48
RR
4811 m_mainWin->SetColumnWidth( col, width );
4812 return TRUE;
e1e955e1 4813}
c801d85f 4814
3cd94a0d 4815int wxGenericListCtrl::GetCountPerPage() const
c801d85f
KB
4816{
4817 return m_mainWin->GetCountPerPage(); // different from Windows ?
e1e955e1 4818}
c801d85f 4819
3cd94a0d 4820bool wxGenericListCtrl::GetItem( wxListItem &info ) const
c801d85f 4821{
5b077d48
RR
4822 m_mainWin->GetItem( info );
4823 return TRUE;
e1e955e1 4824}
c801d85f 4825
3cd94a0d 4826bool wxGenericListCtrl::SetItem( wxListItem &info )
c801d85f 4827{
5b077d48
RR
4828 m_mainWin->SetItem( info );
4829 return TRUE;
e1e955e1 4830}
c801d85f 4831
3cd94a0d 4832long wxGenericListCtrl::SetItem( long index, int col, const wxString& label, int imageId )
c801d85f 4833{
5b077d48
RR
4834 wxListItem info;
4835 info.m_text = label;
4836 info.m_mask = wxLIST_MASK_TEXT;
4837 info.m_itemId = index;
4838 info.m_col = col;
4839 if ( imageId > -1 )
4840 {
4841 info.m_image = imageId;
4842 info.m_mask |= wxLIST_MASK_IMAGE;
4843 };
4844 m_mainWin->SetItem(info);
4845 return TRUE;
e1e955e1 4846}
c801d85f 4847
3cd94a0d 4848int wxGenericListCtrl::GetItemState( long item, long stateMask ) const
c801d85f 4849{
5b077d48 4850 return m_mainWin->GetItemState( item, stateMask );
e1e955e1 4851}
c801d85f 4852
3cd94a0d 4853bool wxGenericListCtrl::SetItemState( long item, long state, long stateMask )
c801d85f 4854{
5b077d48
RR
4855 m_mainWin->SetItemState( item, state, stateMask );
4856 return TRUE;
e1e955e1 4857}
c801d85f 4858
3cd94a0d 4859bool wxGenericListCtrl::SetItemImage( long item, int image, int WXUNUSED(selImage) )
c801d85f 4860{
5b077d48
RR
4861 wxListItem info;
4862 info.m_image = image;
4863 info.m_mask = wxLIST_MASK_IMAGE;
4864 info.m_itemId = item;
4865 m_mainWin->SetItem( info );
4866 return TRUE;
e1e955e1 4867}
c801d85f 4868
3cd94a0d 4869wxString wxGenericListCtrl::GetItemText( long item ) const
c801d85f 4870{
62d89eb4 4871 return m_mainWin->GetItemText(item);
e1e955e1 4872}
c801d85f 4873
3cd94a0d 4874void wxGenericListCtrl::SetItemText( long item, const wxString& str )
c801d85f 4875{
62d89eb4 4876 m_mainWin->SetItemText(item, str);
e1e955e1 4877}
c801d85f 4878
3cd94a0d 4879long wxGenericListCtrl::GetItemData( long item ) const
c801d85f 4880{
5b077d48
RR
4881 wxListItem info;
4882 info.m_itemId = item;
4883 m_mainWin->GetItem( info );
4884 return info.m_data;
e1e955e1 4885}
c801d85f 4886
3cd94a0d 4887bool wxGenericListCtrl::SetItemData( long item, long data )
c801d85f 4888{
5b077d48
RR
4889 wxListItem info;
4890 info.m_mask = wxLIST_MASK_DATA;
4891 info.m_itemId = item;
4892 info.m_data = data;
4893 m_mainWin->SetItem( info );
4894 return TRUE;
e1e955e1 4895}
c801d85f 4896
3cd94a0d 4897bool wxGenericListCtrl::GetItemRect( long item, wxRect &rect, int WXUNUSED(code) ) const
c801d85f 4898{
5b077d48
RR
4899 m_mainWin->GetItemRect( item, rect );
4900 return TRUE;
e1e955e1 4901}
c801d85f 4902
3cd94a0d 4903bool wxGenericListCtrl::GetItemPosition( long item, wxPoint& pos ) const
c801d85f 4904{
5b077d48
RR
4905 m_mainWin->GetItemPosition( item, pos );
4906 return TRUE;
e1e955e1 4907}
c801d85f 4908
3cd94a0d 4909bool wxGenericListCtrl::SetItemPosition( long WXUNUSED(item), const wxPoint& WXUNUSED(pos) )
c801d85f 4910{
5b077d48 4911 return 0;
e1e955e1 4912}
c801d85f 4913
3cd94a0d 4914int wxGenericListCtrl::GetItemCount() const
c801d85f 4915{
5b077d48 4916 return m_mainWin->GetItemCount();
e1e955e1 4917}
c801d85f 4918
3cd94a0d 4919int wxGenericListCtrl::GetColumnCount() const
92976ab6 4920{
5b077d48 4921 return m_mainWin->GetColumnCount();
92976ab6
RR
4922}
4923
3cd94a0d 4924void wxGenericListCtrl::SetItemSpacing( int spacing, bool isSmall )
33d0b396 4925{
5b077d48 4926 m_mainWin->SetItemSpacing( spacing, isSmall );
e1e955e1 4927}
33d0b396 4928
3cd94a0d 4929int wxGenericListCtrl::GetItemSpacing( bool isSmall ) const
c801d85f 4930{
5b077d48 4931 return m_mainWin->GetItemSpacing( isSmall );
e1e955e1 4932}
c801d85f 4933
3cd94a0d 4934void wxGenericListCtrl::SetItemTextColour( long item, const wxColour &col )
5b98eb2f
RL
4935{
4936 wxListItem info;
4937 info.m_itemId = item;
4938 info.SetTextColour( col );
4939 m_mainWin->SetItem( info );
4940}
4941
3cd94a0d 4942wxColour wxGenericListCtrl::GetItemTextColour( long item ) const
5b98eb2f
RL
4943{
4944 wxListItem info;
4945 info.m_itemId = item;
4946 m_mainWin->GetItem( info );
4947 return info.GetTextColour();
4948}
4949
3cd94a0d 4950void wxGenericListCtrl::SetItemBackgroundColour( long item, const wxColour &col )
5b98eb2f
RL
4951{
4952 wxListItem info;
4953 info.m_itemId = item;
4954 info.SetBackgroundColour( col );
4955 m_mainWin->SetItem( info );
4956}
4957
3cd94a0d 4958wxColour wxGenericListCtrl::GetItemBackgroundColour( long item ) const
5b98eb2f
RL
4959{
4960 wxListItem info;
4961 info.m_itemId = item;
4962 m_mainWin->GetItem( info );
4963 return info.GetBackgroundColour();
4964}
4965
3cd94a0d 4966int wxGenericListCtrl::GetSelectedItemCount() const
c801d85f 4967{
5b077d48 4968 return m_mainWin->GetSelectedItemCount();
e1e955e1 4969}
c801d85f 4970
3cd94a0d 4971wxColour wxGenericListCtrl::GetTextColour() const
c801d85f 4972{
0530737d 4973 return GetForegroundColour();
e1e955e1 4974}
c801d85f 4975
3cd94a0d 4976void wxGenericListCtrl::SetTextColour(const wxColour& col)
c801d85f 4977{
0530737d 4978 SetForegroundColour(col);
e1e955e1 4979}
c801d85f 4980
3cd94a0d 4981long wxGenericListCtrl::GetTopItem() const
c801d85f 4982{
2b5f62a0
VZ
4983 size_t top;
4984 m_mainWin->GetVisibleLinesRange(&top, NULL);
4985 return (long)top;
e1e955e1 4986}
c801d85f 4987
3cd94a0d 4988long wxGenericListCtrl::GetNextItem( long item, int geom, int state ) const
c801d85f 4989{
5b077d48 4990 return m_mainWin->GetNextItem( item, geom, state );
e1e955e1 4991}
c801d85f 4992
80020b62 4993wxImageListType *wxGenericListCtrl::GetImageList(int which) const
c801d85f 4994{
5b077d48
RR
4995 if (which == wxIMAGE_LIST_NORMAL)
4996 {
4997 return m_imageListNormal;
4998 }
4999 else if (which == wxIMAGE_LIST_SMALL)
5000 {
5001 return m_imageListSmall;
5002 }
5003 else if (which == wxIMAGE_LIST_STATE)
5004 {
5005 return m_imageListState;
5006 }
80020b62 5007 return (wxImageListType *) NULL;
e1e955e1 5008}
c801d85f 5009
80020b62 5010void wxGenericListCtrl::SetImageList( wxImageListType *imageList, int which )
c801d85f 5011{
2e12c11a
VS
5012 if ( which == wxIMAGE_LIST_NORMAL )
5013 {
5014 if (m_ownsImageListNormal) delete m_imageListNormal;
5015 m_imageListNormal = imageList;
5016 m_ownsImageListNormal = FALSE;
5017 }
5018 else if ( which == wxIMAGE_LIST_SMALL )
5019 {
5020 if (m_ownsImageListSmall) delete m_imageListSmall;
5021 m_imageListSmall = imageList;
5022 m_ownsImageListSmall = FALSE;
5023 }
5024 else if ( which == wxIMAGE_LIST_STATE )
5025 {
5026 if (m_ownsImageListState) delete m_imageListState;
5027 m_imageListState = imageList;
5028 m_ownsImageListState = FALSE;
5029 }
5030
5b077d48 5031 m_mainWin->SetImageList( imageList, which );
e1e955e1 5032}
c801d85f 5033
80020b62 5034void wxGenericListCtrl::AssignImageList(wxImageListType *imageList, int which)
2e12c11a
VS
5035{
5036 SetImageList(imageList, which);
5037 if ( which == wxIMAGE_LIST_NORMAL )
5038 m_ownsImageListNormal = TRUE;
5039 else if ( which == wxIMAGE_LIST_SMALL )
5040 m_ownsImageListSmall = TRUE;
5041 else if ( which == wxIMAGE_LIST_STATE )
5042 m_ownsImageListState = TRUE;
5043}
5044
3cd94a0d 5045bool wxGenericListCtrl::Arrange( int WXUNUSED(flag) )
c801d85f 5046{
5b077d48 5047 return 0;
e1e955e1 5048}
c801d85f 5049
3cd94a0d 5050bool wxGenericListCtrl::DeleteItem( long item )
c801d85f 5051{
5b077d48
RR
5052 m_mainWin->DeleteItem( item );
5053 return TRUE;
e1e955e1 5054}
c801d85f 5055
3cd94a0d 5056bool wxGenericListCtrl::DeleteAllItems()
c801d85f 5057{
5b077d48
RR
5058 m_mainWin->DeleteAllItems();
5059 return TRUE;
e1e955e1 5060}
c801d85f 5061
3cd94a0d 5062bool wxGenericListCtrl::DeleteAllColumns()
bd8289c1 5063{
24b9f055
VZ
5064 size_t count = m_mainWin->m_columns.GetCount();
5065 for ( size_t n = 0; n < count; n++ )
85cdcb7a 5066 DeleteColumn(0);
bffa1c77 5067
5b077d48 5068 return TRUE;
4f22cf8d
RR
5069}
5070
3cd94a0d 5071void wxGenericListCtrl::ClearAll()
4f22cf8d 5072{
5b077d48 5073 m_mainWin->DeleteEverything();
bd8289c1
VZ
5074}
5075
3cd94a0d 5076bool wxGenericListCtrl::DeleteColumn( int col )
c801d85f 5077{
5b077d48 5078 m_mainWin->DeleteColumn( col );
40c08808
VZ
5079
5080 // if we don't have the header any longer, we need to relayout the window
5081 if ( !GetColumnCount() )
5082 {
5083 ResizeReportView(FALSE /* no header */);
5084 }
5085
5b077d48 5086 return TRUE;
e1e955e1 5087}
c801d85f 5088
3cd94a0d 5089void wxGenericListCtrl::Edit( long item )
c801d85f 5090{
cf1dfa6b 5091 m_mainWin->EditLabel( item );
e1e955e1 5092}
c801d85f 5093
3cd94a0d 5094bool wxGenericListCtrl::EnsureVisible( long item )
c801d85f 5095{
5b077d48
RR
5096 m_mainWin->EnsureVisible( item );
5097 return TRUE;
e1e955e1 5098}
c801d85f 5099
3cd94a0d 5100long wxGenericListCtrl::FindItem( long start, const wxString& str, bool partial )
c801d85f 5101{
5b077d48 5102 return m_mainWin->FindItem( start, str, partial );
e1e955e1 5103}
c801d85f 5104
3cd94a0d 5105long wxGenericListCtrl::FindItem( long start, long data )
c801d85f 5106{
5b077d48 5107 return m_mainWin->FindItem( start, data );
e1e955e1 5108}
c801d85f 5109
3cd94a0d 5110long wxGenericListCtrl::FindItem( long WXUNUSED(start), const wxPoint& WXUNUSED(pt),
debe6624 5111 int WXUNUSED(direction))
c801d85f 5112{
5b077d48 5113 return 0;
e1e955e1 5114}
c801d85f 5115
3cd94a0d 5116long wxGenericListCtrl::HitTest( const wxPoint &point, int &flags )
c801d85f 5117{
5b077d48 5118 return m_mainWin->HitTest( (int)point.x, (int)point.y, flags );
e1e955e1 5119}
c801d85f 5120
3cd94a0d 5121long wxGenericListCtrl::InsertItem( wxListItem& info )
c801d85f 5122{
5b077d48 5123 m_mainWin->InsertItem( info );
2ebcd5f5 5124 return info.m_itemId;
e1e955e1 5125}
c801d85f 5126
3cd94a0d 5127long wxGenericListCtrl::InsertItem( long index, const wxString &label )
c801d85f 5128{
51cc4dad
RR
5129 wxListItem info;
5130 info.m_text = label;
5131 info.m_mask = wxLIST_MASK_TEXT;
5132 info.m_itemId = index;
5133 return InsertItem( info );
e1e955e1 5134}
c801d85f 5135
3cd94a0d 5136long wxGenericListCtrl::InsertItem( long index, int imageIndex )
c801d85f 5137{
51cc4dad
RR
5138 wxListItem info;
5139 info.m_mask = wxLIST_MASK_IMAGE;
5140 info.m_image = imageIndex;
5141 info.m_itemId = index;
5142 return InsertItem( info );
e1e955e1 5143}
c801d85f 5144
3cd94a0d 5145long wxGenericListCtrl::InsertItem( long index, const wxString &label, int imageIndex )
c801d85f 5146{
51cc4dad
RR
5147 wxListItem info;
5148 info.m_text = label;
5149 info.m_image = imageIndex;
5150 info.m_mask = wxLIST_MASK_TEXT | wxLIST_MASK_IMAGE;
5151 info.m_itemId = index;
5152 return InsertItem( info );
e1e955e1 5153}
c801d85f 5154
3cd94a0d 5155long wxGenericListCtrl::InsertColumn( long col, wxListItem &item )
c801d85f 5156{
40c08808
VZ
5157 wxCHECK_MSG( m_headerWin, -1, _T("can't add column in non report mode") );
5158
51cc4dad 5159 m_mainWin->InsertColumn( col, item );
40c08808
VZ
5160
5161 // if we hadn't had header before and have it now we need to relayout the
5162 // window
5163 if ( GetColumnCount() == 1 )
5164 {
5165 ResizeReportView(TRUE /* have header */);
5166 }
5167
d3e90957 5168 m_headerWin->Refresh();
25e3a937 5169
51cc4dad 5170 return 0;
e1e955e1 5171}
c801d85f 5172
3cd94a0d 5173long wxGenericListCtrl::InsertColumn( long col, const wxString &heading,
debe6624 5174 int format, int width )
c801d85f 5175{
51cc4dad
RR
5176 wxListItem item;
5177 item.m_mask = wxLIST_MASK_TEXT | wxLIST_MASK_FORMAT;
5178 item.m_text = heading;
5179 if (width >= -2)
5180 {
5181 item.m_mask |= wxLIST_MASK_WIDTH;
5182 item.m_width = width;
5183 }
5184 item.m_format = format;
c801d85f 5185
51cc4dad 5186 return InsertColumn( col, item );
e1e955e1 5187}
c801d85f 5188
3cd94a0d 5189bool wxGenericListCtrl::ScrollList( int WXUNUSED(dx), int WXUNUSED(dy) )
c801d85f 5190{
51cc4dad 5191 return 0;
e1e955e1 5192}
c801d85f
KB
5193
5194// Sort items.
5195// fn is a function which takes 3 long arguments: item1, item2, data.
5196// item1 is the long data associated with a first item (NOT the index).
5197// item2 is the long data associated with a second item (NOT the index).
5198// data is the same value as passed to SortItems.
5199// The return value is a negative number if the first item should precede the second
5200// item, a positive number of the second item should precede the first,
5201// or zero if the two items are equivalent.
5202// data is arbitrary data to be passed to the sort function.
5203
3cd94a0d 5204bool wxGenericListCtrl::SortItems( wxListCtrlCompare fn, long data )
c801d85f 5205{
51cc4dad
RR
5206 m_mainWin->SortItems( fn, data );
5207 return TRUE;
e1e955e1 5208}
c801d85f 5209
cf1dfa6b 5210// ----------------------------------------------------------------------------
b54e41c5 5211// event handlers
cf1dfa6b
VZ
5212// ----------------------------------------------------------------------------
5213
3cd94a0d 5214void wxGenericListCtrl::OnSize(wxSizeEvent& WXUNUSED(event))
53010e52 5215{
b54e41c5 5216 if ( !m_mainWin )
cf1dfa6b 5217 return;
53010e52 5218
a95cdab8
VZ
5219 ResizeReportView(m_mainWin->HasHeader());
5220
5221 m_mainWin->RecalculatePositions();
5222}
5223
3cd94a0d 5224void wxGenericListCtrl::ResizeReportView(bool showHeader)
a95cdab8 5225{
b54e41c5 5226 int cw, ch;
51cc4dad 5227 GetClientSize( &cw, &ch );
bd8289c1 5228
a95cdab8 5229 if ( showHeader )
51cc4dad 5230 {
cf1dfa6b
VZ
5231 m_headerWin->SetSize( 0, 0, cw, HEADER_HEIGHT );
5232 m_mainWin->SetSize( 0, HEADER_HEIGHT + 1, cw, ch - HEADER_HEIGHT - 1 );
51cc4dad 5233 }
cf1dfa6b 5234 else // no header window
51cc4dad 5235 {
cf1dfa6b 5236 m_mainWin->SetSize( 0, 0, cw, ch );
51cc4dad 5237 }
b54e41c5 5238}
cf1dfa6b 5239
3cd94a0d 5240void wxGenericListCtrl::OnIdle( wxIdleEvent & event )
b54e41c5
VZ
5241{
5242 event.Skip();
f6bcfd97 5243
b54e41c5
VZ
5244 // do it only if needed
5245 if ( !m_mainWin->m_dirty )
5246 return;
5247
5248 m_mainWin->RecalculatePositions();
e1e955e1 5249}
53010e52 5250
cf1dfa6b
VZ
5251// ----------------------------------------------------------------------------
5252// font/colours
5253// ----------------------------------------------------------------------------
5254
3cd94a0d 5255bool wxGenericListCtrl::SetBackgroundColour( const wxColour &colour )
bd8289c1 5256{
51cc4dad
RR
5257 if (m_mainWin)
5258 {
5259 m_mainWin->SetBackgroundColour( colour );
5260 m_mainWin->m_dirty = TRUE;
5261 }
004fd0c8 5262
f03fc89f 5263 return TRUE;
e4d06860
RR
5264}
5265
3cd94a0d 5266bool wxGenericListCtrl::SetForegroundColour( const wxColour &colour )
bd8289c1 5267{
f03fc89f
VZ
5268 if ( !wxWindow::SetForegroundColour( colour ) )
5269 return FALSE;
004fd0c8 5270
51cc4dad
RR
5271 if (m_mainWin)
5272 {
5273 m_mainWin->SetForegroundColour( colour );
5274 m_mainWin->m_dirty = TRUE;
5275 }
004fd0c8 5276
51cc4dad
RR
5277 if (m_headerWin)
5278 {
5279 m_headerWin->SetForegroundColour( colour );
5280 }
f03fc89f
VZ
5281
5282 return TRUE;
e4d06860 5283}
bd8289c1 5284
3cd94a0d 5285bool wxGenericListCtrl::SetFont( const wxFont &font )
bd8289c1 5286{
f03fc89f
VZ
5287 if ( !wxWindow::SetFont( font ) )
5288 return FALSE;
004fd0c8 5289
51cc4dad
RR
5290 if (m_mainWin)
5291 {
5292 m_mainWin->SetFont( font );
5293 m_mainWin->m_dirty = TRUE;
5294 }
004fd0c8 5295
51cc4dad
RR
5296 if (m_headerWin)
5297 {
5298 m_headerWin->SetFont( font );
5299 }
f03fc89f
VZ
5300
5301 return TRUE;
e4d06860 5302}
c801d85f 5303
cf1dfa6b
VZ
5304// ----------------------------------------------------------------------------
5305// methods forwarded to m_mainWin
5306// ----------------------------------------------------------------------------
5307
efbb7287
VZ
5308#if wxUSE_DRAG_AND_DROP
5309
3cd94a0d 5310void wxGenericListCtrl::SetDropTarget( wxDropTarget *dropTarget )
efbb7287
VZ
5311{
5312 m_mainWin->SetDropTarget( dropTarget );
5313}
5314
3cd94a0d 5315wxDropTarget *wxGenericListCtrl::GetDropTarget() const
efbb7287
VZ
5316{
5317 return m_mainWin->GetDropTarget();
5318}
5319
5320#endif // wxUSE_DRAG_AND_DROP
5321
3cd94a0d 5322bool wxGenericListCtrl::SetCursor( const wxCursor &cursor )
efbb7287
VZ
5323{
5324 return m_mainWin ? m_mainWin->wxWindow::SetCursor(cursor) : FALSE;
5325}
5326
3cd94a0d 5327wxColour wxGenericListCtrl::GetBackgroundColour() const
efbb7287
VZ
5328{
5329 return m_mainWin ? m_mainWin->GetBackgroundColour() : wxColour();
5330}
5331
3cd94a0d 5332wxColour wxGenericListCtrl::GetForegroundColour() const
efbb7287
VZ
5333{
5334 return m_mainWin ? m_mainWin->GetForegroundColour() : wxColour();
5335}
5336
3cd94a0d 5337bool wxGenericListCtrl::DoPopupMenu( wxMenu *menu, int x, int y )
efbb7287 5338{
3a8c693a 5339#if wxUSE_MENUS
efbb7287 5340 return m_mainWin->PopupMenu( menu, x, y );
3a8c693a
VZ
5341#else
5342 return FALSE;
5343#endif // wxUSE_MENUS
efbb7287
VZ
5344}
5345
3cd94a0d 5346void wxGenericListCtrl::SetFocus()
efbb7287
VZ
5347{
5348 /* The test in window.cpp fails as we are a composite
5349 window, so it checks against "this", but not m_mainWin. */
5350 if ( FindFocus() != this )
5351 m_mainWin->SetFocus();
5352}
1e6feb95 5353
2c1f73ee
VZ
5354// ----------------------------------------------------------------------------
5355// virtual list control support
5356// ----------------------------------------------------------------------------
5357
3cd94a0d 5358wxString wxGenericListCtrl::OnGetItemText(long WXUNUSED(item), long WXUNUSED(col)) const
2c1f73ee
VZ
5359{
5360 // this is a pure virtual function, in fact - which is not really pure
5361 // because the controls which are not virtual don't need to implement it
3cd94a0d 5362 wxFAIL_MSG( _T("wxGenericListCtrl::OnGetItemText not supposed to be called") );
2c1f73ee
VZ
5363
5364 return wxEmptyString;
5365}
5366
3cd94a0d 5367int wxGenericListCtrl::OnGetItemImage(long WXUNUSED(item)) const
2c1f73ee
VZ
5368{
5369 // same as above
3cd94a0d 5370 wxFAIL_MSG( _T("wxGenericListCtrl::OnGetItemImage not supposed to be called") );
2c1f73ee
VZ
5371
5372 return -1;
5373}
5374
3cd94a0d 5375wxListItemAttr *wxGenericListCtrl::OnGetItemAttr(long item) const
6c02c329
VZ
5376{
5377 wxASSERT_MSG( item >= 0 && item < GetItemCount(),
5378 _T("invalid item index in OnGetItemAttr()") );
5379
5380 // no attributes by default
5381 return NULL;
5382}
5383
3cd94a0d 5384void wxGenericListCtrl::SetItemCount(long count)
2c1f73ee
VZ
5385{
5386 wxASSERT_MSG( IsVirtual(), _T("this is for virtual controls only") );
5387
5388 m_mainWin->SetItemCount(count);
5389}
5390
3cd94a0d 5391void wxGenericListCtrl::RefreshItem(long item)
1a6cb56f
VZ
5392{
5393 m_mainWin->RefreshLine(item);
5394}
5395
3cd94a0d 5396void wxGenericListCtrl::RefreshItems(long itemFrom, long itemTo)
1a6cb56f
VZ
5397{
5398 m_mainWin->RefreshLines(itemFrom, itemTo);
5399}
5400
3cd94a0d 5401void wxGenericListCtrl::Freeze()
c5c528fc
VZ
5402{
5403 m_mainWin->Freeze();
5404}
5405
3cd94a0d 5406void wxGenericListCtrl::Thaw()
c5c528fc
VZ
5407{
5408 m_mainWin->Thaw();
5409}
5410
1e6feb95 5411#endif // wxUSE_LISTCTRL
5b98eb2f 5412