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