]> git.saurik.com Git - wxWidgets.git/blame - src/generic/listctrl.cpp
added mac l&f for rules and headers
[wxWidgets.git] / src / generic / listctrl.cpp
CommitLineData
c801d85f 1/////////////////////////////////////////////////////////////////////////////
54442116
VZ
2// Name: generic/listctrl.cpp
3// Purpose: generic implementation of wxListCtrl
c801d85f 4// Author: Robert Roebling
cf1dfa6b 5// Vadim Zeitlin (virtual list control support)
0208334d
RR
6// Id: $Id$
7// Copyright: (c) 1998 Robert Roebling
bd8289c1 8// Licence: wxWindows licence
c801d85f
KB
9/////////////////////////////////////////////////////////////////////////////
10
1370703e
VZ
11// ============================================================================
12// declarations
13// ============================================================================
14
15// ----------------------------------------------------------------------------
16// headers
17// ----------------------------------------------------------------------------
18
c801d85f 19#ifdef __GNUG__
510fc784
RR
20 #pragma implementation "listctrl.h"
21 #pragma implementation "listctrlbase.h"
c801d85f
KB
22#endif
23
cf1dfa6b
VZ
24#if 0
25 #include "listctrl.old.cpp"
26#else
27
1e6d9499
JS
28// For compilers that support precompilation, includes "wx.h".
29#include "wx/wxprec.h"
30
31#ifdef __BORLANDC__
32#pragma hdrstop
33#endif
34
1e6feb95
VZ
35#if wxUSE_LISTCTRL
36
0208334d
RR
37#include "wx/dcscreen.h"
38#include "wx/app.h"
02527779 39#include "wx/listctrl.h"
f60d0f94 40#include "wx/generic/imaglist.h"
f6bcfd97 41#include "wx/dynarray.h"
c801d85f 42
3fb435df
RR
43#ifdef __WXGTK__
44#include <gtk/gtk.h>
45#include "wx/gtk/win_gtk.h"
46#endif
47
2e4df4bf
VZ
48// ----------------------------------------------------------------------------
49// events
50// ----------------------------------------------------------------------------
51
52DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_BEGIN_DRAG)
53DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_BEGIN_RDRAG)
54DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_BEGIN_LABEL_EDIT)
55DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_END_LABEL_EDIT)
56DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_DELETE_ITEM)
57DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_DELETE_ALL_ITEMS)
58DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_GET_INFO)
59DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_SET_INFO)
60DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_ITEM_SELECTED)
61DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_ITEM_DESELECTED)
62DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_KEY_DOWN)
63DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_INSERT_ITEM)
64DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_COL_CLICK)
65DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_ITEM_RIGHT_CLICK)
66DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_ITEM_MIDDLE_CLICK)
67DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_ITEM_ACTIVATED)
68
cf1dfa6b
VZ
69// ----------------------------------------------------------------------------
70// constants
71// ----------------------------------------------------------------------------
72
73// the height of the header window (FIXME: should depend on its font!)
74static const int HEADER_HEIGHT = 23;
75
76// the scrollbar units
77static const int SCROLL_UNIT_X = 15;
78static const int SCROLL_UNIT_Y = 15;
79
80// the spacing between the lines (in report mode)
81static const int LINE_SPACING = 1;
82
83// extra margins around the text label
84static const int EXTRA_WIDTH = 3;
85static const int EXTRA_HEIGHT = 4;
86
87// offset for the header window
88static const int HEADER_OFFSET_X = 1;
89static const int HEADER_OFFSET_Y = 1;
90
91// when autosizing the columns, add some slack
92static const int AUTOSIZE_COL_MARGIN = 10;
93
94// default and minimal widths for the header columns
95static const int WIDTH_COL_DEFAULT = 80;
96static const int WIDTH_COL_MIN = 10;
97
efbb7287
VZ
98// ============================================================================
99// private classes
100// ============================================================================
101
102//-----------------------------------------------------------------------------
103// wxListItemData (internal)
104//-----------------------------------------------------------------------------
105
cf1dfa6b 106class WXDLLEXPORT wxListItemData
efbb7287 107{
efbb7287 108public:
cf1dfa6b
VZ
109 wxListItemData(wxListMainWindow *owner);
110 ~wxListItemData() { delete m_attr; delete m_rect; }
efbb7287 111
efbb7287 112 void SetItem( const wxListItem &info );
cf1dfa6b
VZ
113 void SetImage( int image ) { m_image = image; }
114 void SetData( long data ) { m_data = data; }
efbb7287
VZ
115 void SetPosition( int x, int y );
116 void SetSize( int width, int height );
54442116
VZ
117
118 bool HasText() const { return !m_text.empty(); }
119 const wxString& GetText() const { return m_text; }
120 void SetText(const wxString& text) { m_text = text; }
121
cf1dfa6b
VZ
122 // we can't use empty string for measuring the string width/height, so
123 // always return something
124 wxString GetTextForMeasuring() const
125 {
126 wxString s = GetText();
127 if ( s.empty() )
128 s = _T('H');
129
130 return s;
131 }
132
efbb7287 133 bool IsHit( int x, int y ) const;
54442116 134
cf1dfa6b
VZ
135 int GetX() const;
136 int GetY() const;
efbb7287
VZ
137 int GetWidth() const;
138 int GetHeight() const;
cf1dfa6b
VZ
139
140 int GetImage() const { return m_image; }
141 bool HasImage() const { return GetImage() != -1; }
142
efbb7287
VZ
143 void GetItem( wxListItem &info ) const;
144
145 wxListItemAttr *GetAttributes() const { return m_attr; }
146
54442116 147public:
cf1dfa6b
VZ
148 // the item image or -1
149 int m_image;
150
151 // user data associated with the item
152 long m_data;
54442116 153
cf1dfa6b
VZ
154 // the item coordinates are not used in report mode, instead this pointer
155 // is NULL and the owner window is used to retrieve the item position and
156 // size
157 wxRect *m_rect;
158
159 // the list ctrl we are in
160 wxListMainWindow *m_owner;
161
162 // custom attributes or NULL
54442116
VZ
163 wxListItemAttr *m_attr;
164
165protected:
cf1dfa6b
VZ
166 // common part of all ctors
167 void Init();
54442116 168
cf1dfa6b 169 wxString m_text;
efbb7287
VZ
170};
171
172//-----------------------------------------------------------------------------
173// wxListHeaderData (internal)
174//-----------------------------------------------------------------------------
175
176class WXDLLEXPORT wxListHeaderData : public wxObject
177{
178protected:
179 long m_mask;
180 int m_image;
181 wxString m_text;
182 int m_format;
183 int m_width;
2c1f73ee
VZ
184 int m_xpos,
185 m_ypos;
efbb7287
VZ
186 int m_height;
187
188public:
189 wxListHeaderData();
190 wxListHeaderData( const wxListItem &info );
191 void SetItem( const wxListItem &item );
192 void SetPosition( int x, int y );
193 void SetWidth( int w );
194 void SetFormat( int format );
195 void SetHeight( int h );
196 bool HasImage() const;
54442116
VZ
197
198 bool HasText() const { return !m_text.empty(); }
199 const wxString& GetText() const { return m_text; }
200 void SetText(const wxString& text) { m_text = text; }
201
efbb7287 202 void GetItem( wxListItem &item );
54442116
VZ
203
204 bool IsHit( int x, int y ) const;
efbb7287
VZ
205 int GetImage() const;
206 int GetWidth() const;
207 int GetFormat() const;
f6bcfd97 208
efbb7287
VZ
209private:
210 DECLARE_DYNAMIC_CLASS(wxListHeaderData);
211};
212
213//-----------------------------------------------------------------------------
214// wxListLineData (internal)
215//-----------------------------------------------------------------------------
216
2c1f73ee
VZ
217WX_DECLARE_LIST(wxListItemData, wxListItemDataList);
218#include "wx/listimpl.cpp"
219WX_DEFINE_LIST(wxListItemDataList);
220
cf1dfa6b 221class WXDLLEXPORT wxListLineData
efbb7287
VZ
222{
223public:
cf1dfa6b
VZ
224 // the list of subitems: only may have more than one item in report mode
225 wxListItemDataList m_items;
226
227 // this is not used in report view
228 struct GeometryInfo
229 {
230 // total item rect
231 wxRect m_rectAll;
232
233 // label only
234 wxRect m_rectLabel;
235
236 // icon only
237 wxRect m_rectIcon;
238
239 // the part to be highlighted
240 wxRect m_rectHilight;
241 } *m_gi;
efbb7287 242
cf1dfa6b
VZ
243 // is this item selected? [NB: not used in virtual mode]
244 bool m_hilighted;
245
246 // back pointer to the list ctrl
247 wxListMainWindow *m_owner;
efbb7287
VZ
248
249public:
cf1dfa6b
VZ
250 wxListLineData( wxListMainWindow *owner, size_t line );
251
252 ~wxListLineData() { delete m_gi; }
253
254 // are we in report mode?
255 inline bool InReportView() const;
256
257 // are we in virtual report mode?
258 inline bool IsVirtal() const;
259
260 // these 2 methods shouldn't be called for report view controls, in that
261 // case we determine our position/size ourselves
262
263 // calculate the size of the line
efbb7287 264 void CalculateSize( wxDC *dc, int spacing );
cf1dfa6b
VZ
265
266 // remember the position this line appears at
267 void SetPosition( int x, int y, int window_width, int spacing );
268
efbb7287 269 long IsHit( int x, int y );
cf1dfa6b 270
efbb7287
VZ
271 void SetItem( int index, const wxListItem &info );
272 void GetItem( int index, wxListItem &info );
cf1dfa6b 273
54442116 274 wxString GetText(int index) const;
efbb7287 275 void SetText( int index, const wxString s );
cf1dfa6b
VZ
276
277 void SetImage( int index, int image );
278 int GetImage( int index ) const;
279
280 // get the bound rect of this line
281 wxRect GetRect() const;
282
283 // get the bound rect of the label
284 wxRect GetLabelRect() const;
285
286 // get the bound rect of the items icon (only may be called if we do have
287 // an icon!)
288 wxRect GetIconRect() const;
289
290 // get the rect to be highlighted when the item has focus
291 wxRect GetHighlightRect() const;
292
293 // get the size of the total line rect
294 wxSize GetSize() const { return GetRect().GetSize(); }
295
296 // return true if the highlighting really changed
297 bool Hilight( bool on );
298
efbb7287 299 void ReverseHilight();
cf1dfa6b
VZ
300
301 // draw the line on the given DC
302 void Draw( wxDC *dc, int y = 0, int height = 0, bool highlighted = FALSE );
303
304 bool IsHilighted() const
305 {
306 wxASSERT_MSG( !IsVirtal(), _T("unexpected call to IsHilighted") );
307
308 return m_hilighted;
309 }
310
311 // only for wxListMainWindow::CacheLineData()
312 void SetLineIndex(size_t line) { m_lineIndex = line; }
f6bcfd97 313
efbb7287 314private:
cf1dfa6b
VZ
315 // set the line to contain num items (only can be > 1 in report mode)
316 void InitItems( int num );
317
318 // get the mode (i.e. style) of the list control
319 inline int GetMode() const;
320
efbb7287
VZ
321 void SetAttributes(wxDC *dc,
322 const wxListItemAttr *attr,
cf1dfa6b
VZ
323 const wxColour& colText,
324 const wxFont& font,
efbb7287
VZ
325 bool hilight);
326
cf1dfa6b
VZ
327 // the index of this line (only used in report mode)
328 size_t m_lineIndex;
efbb7287
VZ
329};
330
f6bcfd97
BP
331
332WX_DECLARE_EXPORTED_OBJARRAY(wxListLineData, wxListLineDataArray);
333#include "wx/arrimpl.cpp"
334WX_DEFINE_OBJARRAY(wxListLineDataArray);
335
efbb7287
VZ
336//-----------------------------------------------------------------------------
337// wxListHeaderWindow (internal)
338//-----------------------------------------------------------------------------
339
340class WXDLLEXPORT wxListHeaderWindow : public wxWindow
341{
342protected:
343 wxListMainWindow *m_owner;
344 wxCursor *m_currentCursor;
345 wxCursor *m_resizeCursor;
346 bool m_isDragging;
f6bcfd97
BP
347
348 // column being resized
349 int m_column;
350
351 // divider line position in logical (unscrolled) coords
352 int m_currentX;
353
354 // minimal position beyond which the divider line can't be dragged in
355 // logical coords
356 int m_minX;
efbb7287
VZ
357
358public:
359 wxListHeaderWindow();
f6bcfd97
BP
360 virtual ~wxListHeaderWindow();
361
362 wxListHeaderWindow( wxWindow *win,
363 wxWindowID id,
364 wxListMainWindow *owner,
365 const wxPoint &pos = wxDefaultPosition,
366 const wxSize &size = wxDefaultSize,
367 long style = 0,
368 const wxString &name = "wxlistctrlcolumntitles" );
369
efbb7287 370 void DoDrawRect( wxDC *dc, int x, int y, int w, int h );
efbb7287 371 void DrawCurrent();
f6bcfd97
BP
372 void AdjustDC(wxDC& dc);
373
374 void OnPaint( wxPaintEvent &event );
efbb7287
VZ
375 void OnMouse( wxMouseEvent &event );
376 void OnSetFocus( wxFocusEvent &event );
377
f6bcfd97
BP
378 // needs refresh
379 bool m_dirty;
380
efbb7287
VZ
381private:
382 DECLARE_DYNAMIC_CLASS(wxListHeaderWindow)
383 DECLARE_EVENT_TABLE()
384};
385
386//-----------------------------------------------------------------------------
387// wxListRenameTimer (internal)
388//-----------------------------------------------------------------------------
389
390class WXDLLEXPORT wxListRenameTimer: public wxTimer
391{
392private:
1370703e 393 wxListMainWindow *m_owner;
efbb7287
VZ
394
395public:
396 wxListRenameTimer( wxListMainWindow *owner );
397 void Notify();
398};
399
400//-----------------------------------------------------------------------------
401// wxListTextCtrl (internal)
402//-----------------------------------------------------------------------------
403
404class WXDLLEXPORT wxListTextCtrl: public wxTextCtrl
405{
406private:
407 bool *m_accept;
408 wxString *m_res;
409 wxListMainWindow *m_owner;
410 wxString m_startValue;
411
412public:
413 wxListTextCtrl() {}
414 wxListTextCtrl( wxWindow *parent, const wxWindowID id,
415 bool *accept, wxString *res, wxListMainWindow *owner,
416 const wxString &value = "",
417 const wxPoint &pos = wxDefaultPosition, const wxSize &size = wxDefaultSize,
418 int style = 0,
419 const wxValidator& validator = wxDefaultValidator,
809934d2 420 const wxString &name = "listctrltextctrl" );
efbb7287 421 void OnChar( wxKeyEvent &event );
c13cace1 422 void OnKeyUp( wxKeyEvent &event );
efbb7287
VZ
423 void OnKillFocus( wxFocusEvent &event );
424
425private:
426 DECLARE_DYNAMIC_CLASS(wxListTextCtrl);
427 DECLARE_EVENT_TABLE()
428};
429
430//-----------------------------------------------------------------------------
431// wxListMainWindow (internal)
432//-----------------------------------------------------------------------------
433
24b9f055
VZ
434WX_DECLARE_LIST(wxListHeaderData, wxListHeaderDataList);
435#include "wx/listimpl.cpp"
436WX_DEFINE_LIST(wxListHeaderDataList);
437
cf1dfa6b 438class WXDLLEXPORT wxListMainWindow : public wxScrolledWindow
efbb7287 439{
efbb7287
VZ
440public:
441 wxListMainWindow();
1370703e
VZ
442 wxListMainWindow( wxWindow *parent,
443 wxWindowID id,
444 const wxPoint& pos = wxDefaultPosition,
445 const wxSize& size = wxDefaultSize,
446 long style = 0,
447 const wxString &name = _T("listctrlmainwindow") );
448
449 virtual ~wxListMainWindow();
450
cf1dfa6b
VZ
451 bool HasFlag(int flag) const { return m_parent->HasFlag(flag); }
452
1370703e 453 // return true if this is a virtual list control
cf1dfa6b
VZ
454 bool IsVirtual() const { return HasFlag(wxLC_VIRTUAL); }
455
456 // do we have a header window?
457 bool HasHeader() const
458 { return HasFlag(wxLC_REPORT) && !HasFlag(wxLC_NO_HEADER); }
1370703e 459
efbb7287 460 void HilightAll( bool on );
cf1dfa6b
VZ
461
462 // all these functions only do something if the line is currently visible
463
464 // change the line "selected" state, return TRUE if it really changed
465 bool HilightLine( size_t line, bool hilight = TRUE);
466
467 // toggle the line state and refresh it
468 void ReverseHilight( size_t line )
469 { HilightLine(line, !IsHilighted(line)); RefreshLine(line); }
470
471 // refresh one or several lines at once
472 void RefreshLine( size_t line );
473 void RefreshLines( size_t lineFrom, size_t lineTo );
474
475 // return true if the line is highlighted
476 bool IsHilighted(size_t line) const;
efbb7287
VZ
477
478 void EditLabel( long item );
efbb7287
VZ
479 void OnRenameTimer();
480 void OnRenameAccept();
481
482 void OnMouse( wxMouseEvent &event );
483 void MoveToFocus();
cf1dfa6b
VZ
484
485 // called to switch the selection from the current item to newCurrent,
486 void OnArrowChar( size_t newCurrent, const wxKeyEvent& event );
487
efbb7287
VZ
488 void OnChar( wxKeyEvent &event );
489 void OnKeyDown( wxKeyEvent &event );
490 void OnSetFocus( wxFocusEvent &event );
491 void OnKillFocus( wxFocusEvent &event );
492 void OnSize( wxSizeEvent &event );
493 void OnScroll(wxScrollWinEvent& event) ;
f6bcfd97 494
cf1dfa6b
VZ
495 void OnPaint( wxPaintEvent &event );
496
efbb7287
VZ
497 void DrawImage( int index, wxDC *dc, int x, int y );
498 void GetImageSize( int index, int &width, int &height );
cf1dfa6b 499 int GetTextLength( const wxString &s );
efbb7287
VZ
500
501 void SetImageList( wxImageList *imageList, int which );
502 void SetItemSpacing( int spacing, bool isSmall = FALSE );
503 int GetItemSpacing( bool isSmall = FALSE );
cf1dfa6b 504
efbb7287
VZ
505 void SetColumn( int col, wxListItem &item );
506 void SetColumnWidth( int col, int width );
cf1dfa6b
VZ
507 void GetColumn( int col, wxListItem &item ) const;
508 int GetColumnWidth( int col ) const;
509 int GetColumnCount() const { return m_columns.GetCount(); }
510
511 // returns the sum of the heights of all columns
512 int GetHeaderWidth() const;
513
514 int GetCountPerPage() { return m_linesPerPage; }
515
efbb7287
VZ
516 void SetItem( wxListItem &item );
517 void GetItem( wxListItem &item );
518 void SetItemState( long item, long state, long stateMask );
519 int GetItemState( long item, long stateMask );
efbb7287
VZ
520 void GetItemRect( long index, wxRect &rect );
521 bool GetItemPosition( long item, wxPoint& pos );
522 int GetSelectedItemCount();
cf1dfa6b
VZ
523
524 // set the scrollbars and update the positions of the items
efbb7287 525 void CalculatePositions();
cf1dfa6b 526
efbb7287
VZ
527 long GetNextItem( long item, int geometry, int state );
528 void DeleteItem( long index );
529 void DeleteAllItems();
530 void DeleteColumn( int col );
531 void DeleteEverything();
532 void EnsureVisible( long index );
533 long FindItem( long start, const wxString& str, bool partial = FALSE );
534 long FindItem( long start, long data);
535 long HitTest( int x, int y, int &flags );
536 void InsertItem( wxListItem &item );
efbb7287 537 void InsertColumn( long col, wxListItem &item );
efbb7287
VZ
538 void SortItems( wxListCtrlCompare fn, long data );
539
cf1dfa6b 540 size_t GetItemCount() const;
1370703e 541 bool IsEmpty() const { return GetItemCount() == 0; }
2c1f73ee
VZ
542 void SetItemCount(long count);
543
cf1dfa6b
VZ
544 bool HasCurrent() const { return m_current != (size_t)-1; }
545
546 // send out a wxListEvent
547 void SendNotify( size_t line,
548 wxEventType command,
549 wxPoint point = wxDefaultPosition );
550
551 // called by wxListCtrl when its font changes
552 void OnFontChange() { m_lineHeight = 0; }
553
554 // these are for wxListLineData usage only
555
556 // get the backpointer to the list ctrl
557 wxListCtrl *GetListCtrl() const
558 {
559 return wxStaticCast(GetParent(), wxListCtrl);
560 }
561
562 // get the height of all lines (assuming they all do have the same height)
563 wxCoord GetLineHeight() const;
564
565 // get the y position of the given line (only for report view)
566 wxCoord GetLineY(size_t line) const;
567
568//protected:
569 // the array of all line objects for a non virtual list control
570 wxListLineDataArray m_lines;
571
572 // the list of column objects
573 wxListHeaderDataList m_columns;
574
575 // currently focused item or -1
576 size_t m_current;
577
578 // the item currently being edited or -1
579 size_t m_currentEdit;
580
581 // the number of lines per page
582 int m_linesPerPage;
583
584 // this flag is set when something which should result in the window
585 // redrawing happens (i.e. an item was added or deleted, or its appearance
586 // changed) and OnPaint() doesn't redraw the window while it is set which
587 // allows to minimize the number of repaintings when a lot of items are
588 // being added. The real repainting occurs only after the next OnIdle()
589 // call
590 bool m_dirty;
591
592 wxBrush *m_hilightBrush;
593 wxColour *m_hilightColour;
594 int m_xScroll,
595 m_yScroll;
596 wxImageList *m_small_image_list;
597 wxImageList *m_normal_image_list;
598 int m_small_spacing;
599 int m_normal_spacing;
600 bool m_hasFocus;
601
602 bool m_lastOnSame;
603 wxTimer *m_renameTimer;
604 bool m_renameAccept;
605 wxString m_renameRes;
606 bool m_isCreated;
607 int m_dragCount;
608 wxPoint m_dragStart;
609
610 // for double click logic
611 size_t m_lineLastClicked,
612 m_lineBeforeLastClicked;
613
1370703e 614protected:
cf1dfa6b
VZ
615 // the total count of items in a virtual list control
616 long m_countVirt;
617
618 // the first and last lines being shown on screen right now (inclusive)
619 size_t m_lineFrom,
620 m_lineTo;
621
622 // the array containing the indices of all selected items, only used in
623 // virtual controls
624 wxArrayInt m_selections;
625
1370703e
VZ
626 // common part of all ctors
627 void Init();
628
cf1dfa6b
VZ
629 // intiialize m_[xy]Scroll
630 void InitScrolling();
631
1370703e
VZ
632 // get the line data for the given index
633 wxListLineData *GetLine(size_t n) const
634 {
635 wxASSERT_MSG( n != (size_t)-1, _T("invalid line index") );
636
cf1dfa6b
VZ
637 if ( IsVirtual() )
638 {
639 wxConstCast(this, wxListMainWindow)->CacheLineData(n);
640
641 n = 0;
642 }
643
1370703e
VZ
644 return &m_lines[n];
645 }
646
cf1dfa6b
VZ
647 // get the first line: this one is special as we have it even in virtual
648 // list control (it is useful to cache it as we use it for measuring, hit
649 // testing &c)
650 wxListLineData *GetFirstLine() const;
651
652 // cache the line data of the n-th line in m_lines[0]
653 void CacheLineData(size_t line);
654
655 // update m_lineFrom/To
656 void UpdateShownLinesRange();
657
efbb7287 658private:
cf1dfa6b
VZ
659 // initialize the current item if needed
660 void UpdateCurrent();
661
662 // called when an item is [un]focuded, i.e. becomes [not] current
663 //
664 // currently unused
665 void OnFocusLine( size_t line );
666 void OnUnfocusLine( size_t line );
667
668 // the height of one line using the current font
669 wxCoord m_lineHeight;
670
671 // the total header width or 0 if not calculated yet
672 wxCoord m_headerWidth;
673
efbb7287
VZ
674 DECLARE_DYNAMIC_CLASS(wxListMainWindow);
675 DECLARE_EVENT_TABLE()
676};
677
678// ============================================================================
679// implementation
680// ============================================================================
681
c801d85f
KB
682//-----------------------------------------------------------------------------
683// wxListItemData
684//-----------------------------------------------------------------------------
685
cf1dfa6b 686void wxListItemData::Init()
c801d85f 687{
92976ab6
RR
688 m_image = -1;
689 m_data = 0;
cf1dfa6b 690
0530737d 691 m_attr = NULL;
e1e955e1 692}
c801d85f 693
cf1dfa6b 694wxListItemData::wxListItemData(wxListMainWindow *owner)
c801d85f 695{
cf1dfa6b 696 Init();
0530737d 697
cf1dfa6b
VZ
698 m_owner = owner;
699
700 if ( owner->HasFlag(wxLC_REPORT) )
701 {
702 m_rect = NULL;
703 }
704 else
705 {
706 m_rect = new wxRect;
707 }
e1e955e1 708}
c801d85f
KB
709
710void wxListItemData::SetItem( const wxListItem &info )
711{
cf1dfa6b 712 if ( info.m_mask & wxLIST_MASK_TEXT )
54442116 713 SetText(info.m_text);
cf1dfa6b 714 if ( info.m_mask & wxLIST_MASK_IMAGE )
54442116 715 m_image = info.m_image;
cf1dfa6b 716 if ( info.m_mask & wxLIST_MASK_DATA )
54442116 717 m_data = info.m_data;
0530737d
VZ
718
719 if ( info.HasAttributes() )
720 {
721 if ( m_attr )
722 *m_attr = *info.GetAttributes();
723 else
724 m_attr = new wxListItemAttr(*info.GetAttributes());
725 }
726
cf1dfa6b
VZ
727 if ( m_rect )
728 {
729 m_rect->x =
730 m_rect->y =
731 m_rect->height = 0;
732 m_rect->width = info.m_width;
733 }
e1e955e1 734}
c801d85f 735
debe6624 736void wxListItemData::SetPosition( int x, int y )
c801d85f 737{
cf1dfa6b
VZ
738 wxCHECK_RET( m_rect, _T("unexpected SetPosition() call") );
739
740 m_rect->x = x;
741 m_rect->y = y;
e1e955e1 742}
c801d85f 743
1e6d9499 744void wxListItemData::SetSize( int width, int height )
c801d85f 745{
cf1dfa6b 746 wxCHECK_RET( m_rect, _T("unexpected SetSize() call") );
c801d85f 747
cf1dfa6b
VZ
748 if ( width != -1 )
749 m_rect->width = width;
750 if ( height != -1 )
751 m_rect->height = height;
e1e955e1 752}
c801d85f 753
debe6624 754bool wxListItemData::IsHit( int x, int y ) const
c801d85f 755{
cf1dfa6b
VZ
756 wxCHECK_MSG( m_rect, FALSE, _T("can't be called in this mode") );
757
758 return wxRect(GetX(), GetY(), GetWidth(), GetHeight()).Inside(x, y);
e1e955e1 759}
c801d85f 760
fd9811b1 761int wxListItemData::GetX() const
c801d85f 762{
cf1dfa6b
VZ
763 wxCHECK_MSG( m_rect, 0, _T("can't be called in this mode") );
764
765 return m_rect->x;
e1e955e1 766}
c801d85f 767
fd9811b1 768int wxListItemData::GetY() const
c801d85f 769{
cf1dfa6b
VZ
770 wxCHECK_MSG( m_rect, 0, _T("can't be called in this mode") );
771
772 return m_rect->y;
e1e955e1 773}
c801d85f 774
fd9811b1 775int wxListItemData::GetWidth() const
c801d85f 776{
cf1dfa6b
VZ
777 wxCHECK_MSG( m_rect, 0, _T("can't be called in this mode") );
778
779 return m_rect->width;
e1e955e1 780}
c801d85f 781
fd9811b1 782int wxListItemData::GetHeight() const
c801d85f 783{
cf1dfa6b 784 wxCHECK_MSG( m_rect, 0, _T("can't be called in this mode") );
c801d85f 785
cf1dfa6b 786 return m_rect->height;
e1e955e1 787}
c801d85f 788
0530737d 789void wxListItemData::GetItem( wxListItem &info ) const
c801d85f 790{
92976ab6
RR
791 info.m_text = m_text;
792 info.m_image = m_image;
793 info.m_data = m_data;
c801d85f 794
0530737d
VZ
795 if ( m_attr )
796 {
797 if ( m_attr->HasTextColour() )
798 info.SetTextColour(m_attr->GetTextColour());
799 if ( m_attr->HasBackgroundColour() )
800 info.SetBackgroundColour(m_attr->GetBackgroundColour());
801 if ( m_attr->HasFont() )
802 info.SetFont(m_attr->GetFont());
803 }
e1e955e1 804}
c801d85f
KB
805
806//-----------------------------------------------------------------------------
807// wxListHeaderData
808//-----------------------------------------------------------------------------
809
810IMPLEMENT_DYNAMIC_CLASS(wxListHeaderData,wxObject);
811
fd9811b1 812wxListHeaderData::wxListHeaderData()
c801d85f 813{
92976ab6
RR
814 m_mask = 0;
815 m_image = 0;
816 m_format = 0;
817 m_width = 0;
818 m_xpos = 0;
819 m_ypos = 0;
820 m_height = 0;
e1e955e1 821}
c801d85f
KB
822
823wxListHeaderData::wxListHeaderData( const wxListItem &item )
824{
92976ab6
RR
825 SetItem( item );
826 m_xpos = 0;
827 m_ypos = 0;
828 m_height = 0;
e1e955e1 829}
c801d85f
KB
830
831void wxListHeaderData::SetItem( const wxListItem &item )
832{
92976ab6
RR
833 m_mask = item.m_mask;
834 m_text = item.m_text;
835 m_image = item.m_image;
836 m_format = item.m_format;
cf1dfa6b
VZ
837
838 SetWidth(item.m_width);
e1e955e1 839}
c801d85f 840
debe6624 841void wxListHeaderData::SetPosition( int x, int y )
c801d85f 842{
92976ab6
RR
843 m_xpos = x;
844 m_ypos = y;
e1e955e1 845}
c801d85f 846
debe6624 847void wxListHeaderData::SetHeight( int h )
c801d85f 848{
92976ab6 849 m_height = h;
e1e955e1 850}
c801d85f 851
debe6624 852void wxListHeaderData::SetWidth( int w )
c801d85f 853{
92976ab6 854 m_width = w;
cf1dfa6b
VZ
855 if (m_width < 0)
856 m_width = WIDTH_COL_DEFAULT;
857 if (m_width < WIDTH_COL_MIN)
858 m_width = WIDTH_COL_MIN;
e1e955e1 859}
c801d85f 860
debe6624 861void wxListHeaderData::SetFormat( int format )
c801d85f 862{
92976ab6 863 m_format = format;
e1e955e1 864}
c801d85f 865
fd9811b1 866bool wxListHeaderData::HasImage() const
c801d85f 867{
92976ab6 868 return (m_image != 0);
e1e955e1 869}
c801d85f 870
c801d85f
KB
871bool wxListHeaderData::IsHit( int x, int y ) const
872{
92976ab6 873 return ((x >= m_xpos) && (x <= m_xpos+m_width) && (y >= m_ypos) && (y <= m_ypos+m_height));
e1e955e1 874}
c801d85f
KB
875
876void wxListHeaderData::GetItem( wxListItem &item )
877{
92976ab6
RR
878 item.m_mask = m_mask;
879 item.m_text = m_text;
880 item.m_image = m_image;
881 item.m_format = m_format;
882 item.m_width = m_width;
e1e955e1 883}
c801d85f 884
fd9811b1 885int wxListHeaderData::GetImage() const
c801d85f 886{
92976ab6 887 return m_image;
e1e955e1 888}
c801d85f 889
fd9811b1 890int wxListHeaderData::GetWidth() const
c801d85f 891{
92976ab6 892 return m_width;
e1e955e1 893}
c801d85f 894
fd9811b1 895int wxListHeaderData::GetFormat() const
c801d85f 896{
92976ab6 897 return m_format;
e1e955e1 898}
c801d85f
KB
899
900//-----------------------------------------------------------------------------
901// wxListLineData
902//-----------------------------------------------------------------------------
903
cf1dfa6b
VZ
904inline int wxListLineData::GetMode() const
905{
906 return m_owner->GetListCtrl()->GetWindowStyleFlag() & wxLC_MODE_MASK;
907}
c801d85f 908
cf1dfa6b 909inline bool wxListLineData::InReportView() const
c801d85f 910{
cf1dfa6b 911 return m_owner->HasFlag(wxLC_REPORT);
e1e955e1 912}
c801d85f 913
cf1dfa6b 914inline bool wxListLineData::IsVirtal() const
c801d85f 915{
cf1dfa6b
VZ
916 return m_owner->IsVirtual();
917}
2c1f73ee 918
cf1dfa6b
VZ
919wxListLineData::wxListLineData( wxListMainWindow *owner, size_t line )
920{
921 m_owner = owner;
922 m_items.DeleteContents( TRUE );
2c1f73ee 923
cf1dfa6b 924 SetLineIndex(line);
f6bcfd97 925
cf1dfa6b
VZ
926 if ( InReportView() )
927 {
928 m_gi = NULL;
929 }
930 else // !report
931 {
932 m_gi = new GeometryInfo;
933 }
f6bcfd97 934
cf1dfa6b 935 m_hilighted = FALSE;
f6bcfd97 936
cf1dfa6b
VZ
937 InitItems( GetMode() == wxLC_REPORT ? m_owner->GetColumnCount() : 1 );
938}
f6bcfd97 939
cf1dfa6b
VZ
940wxRect wxListLineData::GetRect() const
941{
942 if ( !InReportView() )
943 return m_gi->m_rectAll;
944
945 wxRect rect;
946 rect.x = HEADER_OFFSET_X;
947 rect.y = m_owner->GetLineY(m_lineIndex);
948 rect.width = m_owner->GetHeaderWidth();
949 rect.height = m_owner->GetLineHeight();
950
951 return rect;
952}
953
954wxRect wxListLineData::GetLabelRect() const
955{
956 if ( !InReportView() )
957 return m_gi->m_rectLabel;
958
959 wxRect rect;
960 rect.x = HEADER_OFFSET_X;
961 rect.y = m_owner->GetLineY(m_lineIndex);
962 rect.width = m_owner->GetColumnWidth(0);
963 rect.height = m_owner->GetLineHeight();
964
965 return rect;
966}
967
968wxRect wxListLineData::GetIconRect() const
969{
970 if ( !InReportView() )
971 return m_gi->m_rectIcon;
972
973 wxRect rect;
974
975 wxListItemDataList::Node *node = m_items.GetFirst();
976 wxCHECK_MSG( node, rect, _T("no subitems at all??") );
977
978 wxListItemData *item = node->GetData();
979 wxASSERT_MSG( item->HasImage(), _T("GetIconRect() called but no image") );
980
981 rect.x = HEADER_OFFSET_X;
982 rect.y = m_owner->GetLineY(m_lineIndex);
983 m_owner->GetImageSize(item->GetImage(), rect.width, rect.height);
984
985 return rect;
986}
987
988wxRect wxListLineData::GetHighlightRect() const
989{
990 return InReportView() ? GetRect() : m_gi->m_rectHilight;
991}
992
993void wxListLineData::CalculateSize( wxDC *dc, int spacing )
994{
995 wxListItemDataList::Node *node = m_items.GetFirst();
996 wxCHECK_RET( node, _T("no subitems at all??") );
997
998 wxListItemData *item = node->GetData();
999
1000 switch ( GetMode() )
1001 {
1002 case wxLC_ICON:
1003 case wxLC_SMALL_ICON:
1004 {
1005 m_gi->m_rectAll.width = spacing;
1006
1007 wxString s = item->GetText();
1008
1009 wxCoord lw, lh;
1010 if ( s.empty() )
5d25c050 1011 {
cf1dfa6b
VZ
1012 lh =
1013 m_gi->m_rectLabel.width =
1014 m_gi->m_rectLabel.height = 0;
5d25c050 1015 }
cf1dfa6b
VZ
1016 else // has label
1017 {
1018 dc->GetTextExtent( s, &lw, &lh );
1019 if (lh < SCROLL_UNIT_Y)
1020 lh = SCROLL_UNIT_Y;
1021 lw += EXTRA_WIDTH;
1022 lh += EXTRA_HEIGHT;
1023
1024 m_gi->m_rectAll.height = spacing + lh;
1025 if (lw > spacing)
1026 m_gi->m_rectAll.width = lw;
1027
1028 m_gi->m_rectLabel.width = lw;
1029 m_gi->m_rectLabel.height = lh;
1030 }
1031
1032 if (item->HasImage())
1033 {
1034 int w, h;
1035 m_owner->GetImageSize( item->GetImage(), w, h );
1036 m_gi->m_rectIcon.width = w + 8;
1037 m_gi->m_rectIcon.height = h + 8;
1038
1039 if ( m_gi->m_rectIcon.width > m_gi->m_rectAll.width )
1040 m_gi->m_rectAll.width = m_gi->m_rectIcon.width;
1041 if ( m_gi->m_rectIcon.height + lh > m_gi->m_rectAll.height - 4 )
1042 m_gi->m_rectAll.height = m_gi->m_rectIcon.height + lh + 4;
1043 }
1044
1045 if ( item->HasText() )
5d25c050 1046 {
cf1dfa6b
VZ
1047 m_gi->m_rectHilight.width = m_gi->m_rectLabel.width;
1048 m_gi->m_rectHilight.height = m_gi->m_rectLabel.height;
1049 }
1050 else // no text, highlight the icon
1051 {
1052 m_gi->m_rectHilight.width = m_gi->m_rectIcon.width;
1053 m_gi->m_rectHilight.height = m_gi->m_rectIcon.height;
5d25c050 1054 }
92976ab6
RR
1055 }
1056 break;
cf1dfa6b 1057
92976ab6 1058 case wxLC_LIST:
92976ab6 1059 {
cf1dfa6b 1060 wxString s = item->GetTextForMeasuring();
2c1f73ee 1061
13111b2a 1062 wxCoord lw,lh;
92976ab6 1063 dc->GetTextExtent( s, &lw, &lh );
cf1dfa6b
VZ
1064 if (lh < SCROLL_UNIT_Y)
1065 lh = SCROLL_UNIT_Y;
1066 lw += EXTRA_WIDTH;
1067 lh += EXTRA_HEIGHT;
2c1f73ee 1068
cf1dfa6b
VZ
1069 m_gi->m_rectLabel.width = lw;
1070 m_gi->m_rectLabel.height = lh;
f6bcfd97 1071
cf1dfa6b
VZ
1072 m_gi->m_rectAll.width = lw;
1073 m_gi->m_rectAll.height = lh;
f6bcfd97 1074
0b855868
RR
1075 if (item->HasImage())
1076 {
cf1dfa6b 1077 int w, h;
0b855868 1078 m_owner->GetImageSize( item->GetImage(), w, h );
cf1dfa6b
VZ
1079 m_gi->m_rectIcon.width = w;
1080 m_gi->m_rectIcon.height = h;
f6bcfd97 1081
cf1dfa6b
VZ
1082 m_gi->m_rectAll.width += 4 + w;
1083 if (h > m_gi->m_rectAll.height)
1084 m_gi->m_rectAll.height = h;
bffa1c77 1085 }
f6bcfd97 1086
cf1dfa6b
VZ
1087 m_gi->m_rectHilight.width = m_gi->m_rectAll.width;
1088 m_gi->m_rectHilight.height = m_gi->m_rectAll.height;
92976ab6
RR
1089 }
1090 break;
2c1f73ee 1091
cf1dfa6b
VZ
1092 case wxLC_REPORT:
1093 wxFAIL_MSG( _T("unexpected call to SetSize") );
92976ab6 1094 break;
cf1dfa6b
VZ
1095
1096 default:
1097 wxFAIL_MSG( _T("unknown mode") );
e1e955e1 1098 }
e1e955e1 1099}
c801d85f 1100
cf1dfa6b
VZ
1101void wxListLineData::SetPosition( int x, int y,
1102 int window_width,
1103 int spacing )
c801d85f 1104{
2c1f73ee 1105 wxListItemDataList::Node *node = m_items.GetFirst();
cf1dfa6b 1106 wxCHECK_RET( node, _T("no subitems at all??") );
2c1f73ee 1107
cf1dfa6b 1108 wxListItemData *item = node->GetData();
2c1f73ee 1109
cf1dfa6b 1110 switch ( GetMode() )
0b855868
RR
1111 {
1112 case wxLC_ICON:
cf1dfa6b
VZ
1113 case wxLC_SMALL_ICON:
1114 m_gi->m_rectAll.x = x;
1115 m_gi->m_rectAll.y = y;
1116
1117 if ( item->HasImage() )
0b855868 1118 {
cf1dfa6b
VZ
1119 m_gi->m_rectIcon.x = m_gi->m_rectAll.x + 4
1120 + (spacing - m_gi->m_rectIcon.width)/2;
1121 m_gi->m_rectIcon.y = m_gi->m_rectAll.y + 4;
0b855868 1122 }
cf1dfa6b
VZ
1123
1124 if ( item->HasText() )
0b855868 1125 {
cf1dfa6b
VZ
1126 if (m_gi->m_rectAll.width > spacing)
1127 m_gi->m_rectLabel.x = m_gi->m_rectAll.x + 2;
5d25c050 1128 else
cf1dfa6b
VZ
1129 m_gi->m_rectLabel.x = m_gi->m_rectAll.x + 2 + (spacing/2) - (m_gi->m_rectLabel.width/2);
1130 m_gi->m_rectLabel.y = m_gi->m_rectAll.y + m_gi->m_rectAll.height + 2 - m_gi->m_rectLabel.height;
1131 m_gi->m_rectHilight.x = m_gi->m_rectLabel.x - 2;
1132 m_gi->m_rectHilight.y = m_gi->m_rectLabel.y - 2;
bffa1c77 1133 }
cf1dfa6b 1134 else // no text, highlight the icon
0b855868 1135 {
cf1dfa6b
VZ
1136 m_gi->m_rectHilight.x = m_gi->m_rectIcon.x - 4;
1137 m_gi->m_rectHilight.y = m_gi->m_rectIcon.y - 4;
bffa1c77 1138 }
0b855868 1139 break;
c801d85f 1140
cf1dfa6b
VZ
1141 case wxLC_LIST:
1142 m_gi->m_rectAll.x = x;
1143 m_gi->m_rectAll.y = y;
c801d85f 1144
cf1dfa6b
VZ
1145 m_gi->m_rectHilight.x = m_gi->m_rectAll.x;
1146 m_gi->m_rectHilight.y = m_gi->m_rectAll.y;
1147 m_gi->m_rectLabel.y = m_gi->m_rectAll.y + 2;
c801d85f 1148
cf1dfa6b
VZ
1149 if (item->HasImage())
1150 {
1151 m_gi->m_rectIcon.x = m_gi->m_rectAll.x + 2;
1152 m_gi->m_rectIcon.y = m_gi->m_rectAll.y + 2;
1153 m_gi->m_rectLabel.x = m_gi->m_rectAll.x + 6 + m_gi->m_rectIcon.width;
1154 }
1155 else
1156 {
1157 m_gi->m_rectLabel.x = m_gi->m_rectAll.x + 2;
1158 }
1159 break;
c801d85f 1160
cf1dfa6b
VZ
1161 case wxLC_REPORT:
1162 wxFAIL_MSG( _T("unexpected call to SetPosition") );
1163 break;
c801d85f 1164
cf1dfa6b
VZ
1165 default:
1166 wxFAIL_MSG( _T("unknown mode") );
1167 }
e1e955e1 1168}
c801d85f 1169
debe6624 1170long wxListLineData::IsHit( int x, int y )
c801d85f 1171{
2c1f73ee 1172 wxListItemDataList::Node *node = m_items.GetFirst();
cf1dfa6b
VZ
1173 wxCHECK_MSG( node, 0, _T("no subitems at all??") );
1174
1175 wxListItemData *item = node->GetData();
1176 if ( item->HasImage() && GetIconRect().Inside(x, y) )
1177 return wxLIST_HITTEST_ONITEMICON;
1178
1179 if ( item->HasText() )
139adb6a 1180 {
cf1dfa6b
VZ
1181 wxRect rect = InReportView() ? GetRect() : GetLabelRect();
1182 if ( rect.Inside(x, y) )
2c1f73ee 1183 return wxLIST_HITTEST_ONITEMLABEL;
139adb6a 1184 }
2c1f73ee 1185
139adb6a 1186 return 0;
e1e955e1 1187}
c801d85f 1188
debe6624 1189void wxListLineData::InitItems( int num )
c801d85f 1190{
2c1f73ee 1191 for (int i = 0; i < num; i++)
cf1dfa6b 1192 m_items.Append( new wxListItemData(m_owner) );
e1e955e1 1193}
c801d85f 1194
debe6624 1195void wxListLineData::SetItem( int index, const wxListItem &info )
c801d85f 1196{
2c1f73ee 1197 wxListItemDataList::Node *node = m_items.Item( index );
1370703e
VZ
1198 wxCHECK_RET( node, _T("invalid column index in SetItem") );
1199
1200 wxListItemData *item = node->GetData();
1201 item->SetItem( info );
e1e955e1 1202}
c801d85f 1203
1e6d9499 1204void wxListLineData::GetItem( int index, wxListItem &info )
c801d85f 1205{
2c1f73ee 1206 wxListItemDataList::Node *node = m_items.Item( index );
139adb6a
RR
1207 if (node)
1208 {
2c1f73ee 1209 wxListItemData *item = node->GetData();
139adb6a
RR
1210 item->GetItem( info );
1211 }
e1e955e1 1212}
c801d85f 1213
54442116 1214wxString wxListLineData::GetText(int index) const
c801d85f 1215{
54442116
VZ
1216 wxString s;
1217
2c1f73ee 1218 wxListItemDataList::Node *node = m_items.Item( index );
139adb6a
RR
1219 if (node)
1220 {
2c1f73ee 1221 wxListItemData *item = node->GetData();
54442116 1222 s = item->GetText();
139adb6a 1223 }
54442116
VZ
1224
1225 return s;
e1e955e1 1226}
c801d85f 1227
debe6624 1228void wxListLineData::SetText( int index, const wxString s )
c801d85f 1229{
2c1f73ee 1230 wxListItemDataList::Node *node = m_items.Item( index );
139adb6a
RR
1231 if (node)
1232 {
2c1f73ee 1233 wxListItemData *item = node->GetData();
139adb6a
RR
1234 item->SetText( s );
1235 }
e1e955e1 1236}
c801d85f 1237
cf1dfa6b 1238void wxListLineData::SetImage( int index, int image )
c801d85f 1239{
2c1f73ee 1240 wxListItemDataList::Node *node = m_items.Item( index );
cf1dfa6b
VZ
1241 wxCHECK_RET( node, _T("invalid column index in SetImage()") );
1242
1243 wxListItemData *item = node->GetData();
1244 item->SetImage(image);
1245}
1246
1247int wxListLineData::GetImage( int index ) const
1248{
1249 wxListItemDataList::Node *node = m_items.Item( index );
1250 wxCHECK_MSG( node, -1, _T("invalid column index in GetImage()") );
1251
1252 wxListItemData *item = node->GetData();
1253 return item->GetImage();
e1e955e1 1254}
c801d85f 1255
0530737d
VZ
1256void wxListLineData::SetAttributes(wxDC *dc,
1257 const wxListItemAttr *attr,
1258 const wxColour& colText,
470caaf9
VZ
1259 const wxFont& font,
1260 bool hilight)
0530737d 1261{
470caaf9
VZ
1262 // don't use foregroud colour for drawing highlighted items - this might
1263 // make them completely invisible (and there is no way to do bit
1264 // arithmetics on wxColour, unfortunately)
1265 if ( !hilight && attr && attr->HasTextColour() )
0530737d
VZ
1266 {
1267 dc->SetTextForeground(attr->GetTextColour());
1268 }
1269 else
1270 {
1271 dc->SetTextForeground(colText);
1272 }
1273
1274 if ( attr && attr->HasFont() )
1275 {
1276 dc->SetFont(attr->GetFont());
1277 }
1278 else
1279 {
1280 dc->SetFont(font);
1281 }
1282}
1283
cf1dfa6b 1284void wxListLineData::Draw( wxDC *dc, int y, int height, bool hilighted )
c801d85f 1285{
cf1dfa6b
VZ
1286 wxRect rect = GetRect();
1287 m_owner->CalcScrolledPosition( rect.x, rect.y, &rect.x, &rect.y );
004fd0c8 1288
cf1dfa6b 1289 if ( !m_owner->IsExposed( rect ) )
139adb6a 1290 return;
bd8289c1 1291
0530737d
VZ
1292 wxWindow *listctrl = m_owner->GetParent();
1293
cf1dfa6b
VZ
1294 // use our own flag if we maintain it
1295 if ( !m_owner->IsVirtual() )
1296 hilighted = m_hilighted;
1297
0530737d
VZ
1298 // default foreground colour
1299 wxColour colText;
cf1dfa6b 1300 if ( hilighted )
0530737d
VZ
1301 {
1302 colText = wxSystemSettings::GetSystemColour( wxSYS_COLOUR_HIGHLIGHTTEXT );
1303 }
1304 else
1305 {
1306 colText = listctrl->GetForegroundColour();
1307 }
1308
1309 // default font
1310 wxFont font = listctrl->GetFont();
1311
1312 // VZ: currently we set the colours/fonts only once, but like this (i.e.
1313 // using SetAttributes() inside the loop), it will be trivial to
1314 // customize the subitems (in report mode) too.
2c1f73ee 1315 wxListItemData *item = m_items.GetFirst()->GetData();
0530737d 1316 wxListItemAttr *attr = item->GetAttributes();
cf1dfa6b 1317 SetAttributes(dc, attr, colText, font, hilighted);
0530737d
VZ
1318
1319 bool hasBgCol = attr && attr->HasBackgroundColour();
cf1dfa6b 1320 if ( hilighted || hasBgCol )
c801d85f 1321 {
cf1dfa6b 1322 if ( hilighted )
63852e78 1323 {
cf1dfa6b 1324 dc->SetBrush( *m_owner->m_hilightBrush );
63852e78
RR
1325 }
1326 else
1327 {
0530737d
VZ
1328 if ( hasBgCol )
1329 dc->SetBrush(wxBrush(attr->GetBackgroundColour(), wxSOLID));
1330 else
1331 dc->SetBrush( * wxWHITE_BRUSH );
63852e78 1332 }
0530737d
VZ
1333
1334 dc->SetPen( * wxTRANSPARENT_PEN );
cf1dfa6b 1335 dc->DrawRectangle( GetHighlightRect() );
e1e955e1 1336 }
004fd0c8 1337
2c1f73ee
VZ
1338 wxListItemDataList::Node *node = m_items.GetFirst();
1339
cf1dfa6b 1340 if ( GetMode() == wxLC_REPORT)
c801d85f 1341 {
cf1dfa6b
VZ
1342 size_t col = 0;
1343 int x = HEADER_OFFSET_X;
1344
1345 y += EXTRA_HEIGHT / 2;
1346
1347 while ( node )
63852e78 1348 {
2c1f73ee 1349 wxListItemData *item = node->GetData();
cf1dfa6b
VZ
1350
1351 int xOld = x;
1352
1353 if ( item->HasImage() )
63852e78 1354 {
cf1dfa6b
VZ
1355 int ix, iy;
1356 m_owner->DrawImage( item->GetImage(), dc, x, y );
1357 m_owner->GetImageSize( item->GetImage(), ix, iy );
1358 x += ix + 5; // FIXME: what is "5"?
63852e78 1359 }
cf1dfa6b
VZ
1360
1361 int width = m_owner->GetColumnWidth(col++);
1362
1363 dc->SetClippingRegion(x, y, width, height);
1364
1365 if ( item->HasText() )
63852e78 1366 {
cf1dfa6b 1367 dc->DrawText( item->GetText(), x, y + 1 );
63852e78 1368 }
cf1dfa6b 1369
63852e78 1370 dc->DestroyClippingRegion();
cf1dfa6b
VZ
1371
1372 x = xOld + width;
1373
2c1f73ee 1374 node = node->GetNext();
63852e78 1375 }
e1e955e1 1376 }
2c1f73ee 1377 else // !report
c801d85f 1378 {
63852e78
RR
1379 if (node)
1380 {
2c1f73ee 1381 wxListItemData *item = node->GetData();
63852e78
RR
1382 if (item->HasImage())
1383 {
cf1dfa6b
VZ
1384 wxRect rectIcon = GetIconRect();
1385 m_owner->DrawImage( item->GetImage(), dc,
1386 rectIcon.x, rectIcon.y );
63852e78 1387 }
cf1dfa6b 1388
63852e78
RR
1389 if (item->HasText())
1390 {
cf1dfa6b
VZ
1391 wxRect rectLabel = GetLabelRect();
1392 dc->DrawText( item->GetText(), rectLabel.x, rectLabel.y );
63852e78
RR
1393 }
1394 }
e1e955e1 1395 }
e1e955e1 1396}
c801d85f 1397
cf1dfa6b 1398bool wxListLineData::Hilight( bool on )
c801d85f 1399{
cf1dfa6b 1400 wxCHECK_MSG( !m_owner->IsVirtual(), FALSE, _T("unexpected call to Hilight") );
c801d85f 1401
cf1dfa6b
VZ
1402 if ( on == m_hilighted )
1403 return FALSE;
c801d85f 1404
cf1dfa6b 1405 m_hilighted = on;
c801d85f 1406
cf1dfa6b 1407 return TRUE;
e1e955e1 1408}
c801d85f 1409
cf1dfa6b 1410void wxListLineData::ReverseHilight( void )
c801d85f 1411{
cf1dfa6b 1412 Hilight(!IsHilighted());
e1e955e1 1413}
c801d85f
KB
1414
1415//-----------------------------------------------------------------------------
1416// wxListHeaderWindow
1417//-----------------------------------------------------------------------------
1418
1419IMPLEMENT_DYNAMIC_CLASS(wxListHeaderWindow,wxWindow);
1420
1421BEGIN_EVENT_TABLE(wxListHeaderWindow,wxWindow)
63852e78
RR
1422 EVT_PAINT (wxListHeaderWindow::OnPaint)
1423 EVT_MOUSE_EVENTS (wxListHeaderWindow::OnMouse)
1424 EVT_SET_FOCUS (wxListHeaderWindow::OnSetFocus)
c801d85f
KB
1425END_EVENT_TABLE()
1426
1427wxListHeaderWindow::wxListHeaderWindow( void )
1428{
63852e78
RR
1429 m_owner = (wxListMainWindow *) NULL;
1430 m_currentCursor = (wxCursor *) NULL;
1431 m_resizeCursor = (wxCursor *) NULL;
cfb50f14 1432 m_isDragging = FALSE;
e1e955e1 1433}
c801d85f 1434
bd8289c1 1435wxListHeaderWindow::wxListHeaderWindow( wxWindow *win, wxWindowID id, wxListMainWindow *owner,
debe6624
JS
1436 const wxPoint &pos, const wxSize &size,
1437 long style, const wxString &name ) :
c801d85f
KB
1438 wxWindow( win, id, pos, size, style, name )
1439{
63852e78 1440 m_owner = owner;
c801d85f 1441// m_currentCursor = wxSTANDARD_CURSOR;
63852e78
RR
1442 m_currentCursor = (wxCursor *) NULL;
1443 m_resizeCursor = new wxCursor( wxCURSOR_SIZEWE );
cfb50f14 1444 m_isDragging = FALSE;
f6bcfd97
BP
1445 m_dirty = FALSE;
1446
cfb50f14 1447 SetBackgroundColour( wxSystemSettings::GetSystemColour( wxSYS_COLOUR_BTNFACE ) );
e1e955e1 1448}
c801d85f 1449
a367b9b3
JS
1450wxListHeaderWindow::~wxListHeaderWindow( void )
1451{
63852e78 1452 delete m_resizeCursor;
a367b9b3
JS
1453}
1454
1e6d9499 1455void wxListHeaderWindow::DoDrawRect( wxDC *dc, int x, int y, int w, int h )
c801d85f 1456{
3fb435df
RR
1457#ifdef __WXGTK__
1458 GtkStateType state = GTK_STATE_NORMAL;
1459 if (!m_parent->IsEnabled()) state = GTK_STATE_INSENSITIVE;
2c1f73ee 1460
3fb435df 1461 x = dc->XLOG2DEV( x );
2c1f73ee 1462
05a7f61d
VZ
1463 gtk_paint_box (m_wxwindow->style, GTK_PIZZA(m_wxwindow)->bin_window, state, GTK_SHADOW_OUT,
1464 (GdkRectangle*) NULL, m_wxwindow, "button", x-1, y-1, w+2, h+2);
4176fb7d
SC
1465#elif defined( __WXMAC__ )
1466 const int m_corner = 1;
1467
1468 dc->SetBrush( *wxTRANSPARENT_BRUSH );
1469
1470 dc->SetPen( wxPen( wxSystemSettings::GetSystemColour( wxSYS_COLOUR_BTNSHADOW ) , 1 , wxSOLID ) );
1471 dc->DrawLine( x+w-m_corner+1, y, x+w, y+h ); // right (outer)
1472 dc->DrawRectangle( x, y+h, w+1, 1 ); // bottom (outer)
1473
1474 wxPen pen( wxColour( 0x88 , 0x88 , 0x88 ), 1, wxSOLID );
1475
1476 dc->SetPen( pen );
1477 dc->DrawLine( x+w-m_corner, y, x+w-1, y+h ); // right (inner)
1478 dc->DrawRectangle( x+1, y+h-1, w-2, 1 ); // bottom (inner)
1479
1480 dc->SetPen( *wxWHITE_PEN );
1481 dc->DrawRectangle( x, y, w-m_corner+1, 1 ); // top (outer)
1482 dc->DrawRectangle( x, y, 1, h ); // left (outer)
1483 dc->DrawLine( x, y+h-1, x+1, y+h-1 );
1484 dc->DrawLine( x+w-1, y, x+w-1, y+1 );
3fb435df 1485#else
63852e78 1486 const int m_corner = 1;
c801d85f 1487
63852e78 1488 dc->SetBrush( *wxTRANSPARENT_BRUSH );
c801d85f 1489
63852e78
RR
1490 dc->SetPen( *wxBLACK_PEN );
1491 dc->DrawLine( x+w-m_corner+1, y, x+w, y+h ); // right (outer)
17867d61 1492 dc->DrawRectangle( x, y+h, w+1, 1 ); // bottom (outer)
bd8289c1 1493
63852e78 1494 wxPen pen( wxSystemSettings::GetSystemColour( wxSYS_COLOUR_BTNSHADOW ), 1, wxSOLID );
004fd0c8 1495
63852e78
RR
1496 dc->SetPen( pen );
1497 dc->DrawLine( x+w-m_corner, y, x+w-1, y+h ); // right (inner)
1498 dc->DrawRectangle( x+1, y+h-1, w-2, 1 ); // bottom (inner)
bd8289c1 1499
63852e78
RR
1500 dc->SetPen( *wxWHITE_PEN );
1501 dc->DrawRectangle( x, y, w-m_corner+1, 1 ); // top (outer)
1502 dc->DrawRectangle( x, y, 1, h ); // left (outer)
1503 dc->DrawLine( x, y+h-1, x+1, y+h-1 );
1504 dc->DrawLine( x+w-1, y, x+w-1, y+1 );
3fb435df 1505#endif
e1e955e1 1506}
c801d85f 1507
f6bcfd97
BP
1508// shift the DC origin to match the position of the main window horz
1509// scrollbar: this allows us to always use logical coords
1510void wxListHeaderWindow::AdjustDC(wxDC& dc)
1511{
f6bcfd97
BP
1512 int xpix;
1513 m_owner->GetScrollPixelsPerUnit( &xpix, NULL );
1514
1515 int x;
1516 m_owner->GetViewStart( &x, NULL );
1517
1518 // account for the horz scrollbar offset
1519 dc.SetDeviceOrigin( -x * xpix, 0 );
f6bcfd97
BP
1520}
1521
c801d85f
KB
1522void wxListHeaderWindow::OnPaint( wxPaintEvent &WXUNUSED(event) )
1523{
10bd0724
JS
1524#ifdef __WXGTK__
1525 wxClientDC dc( this );
1526#else
63852e78 1527 wxPaintDC dc( this );
10bd0724
JS
1528#endif
1529
63852e78 1530 PrepareDC( dc );
f6bcfd97 1531 AdjustDC( dc );
bffa1c77 1532
63852e78 1533 dc.BeginDrawing();
bd8289c1 1534
63852e78 1535 dc.SetFont( GetFont() );
bd8289c1 1536
f6bcfd97
BP
1537 // width and height of the entire header window
1538 int w, h;
63852e78 1539 GetClientSize( &w, &h );
f6bcfd97 1540 m_owner->CalcUnscrolledPosition(w, 0, &w, NULL);
c801d85f 1541
f60d0f94 1542 dc.SetBackgroundMode(wxTRANSPARENT);
70846f0a
VZ
1543
1544 // do *not* use the listctrl colour for headers - one day we will have a
1545 // function to set it separately
37d403aa 1546 //dc.SetTextForeground( *wxBLACK );
cf1dfa6b
VZ
1547 dc.SetTextForeground(wxSystemSettings::
1548 GetSystemColour( wxSYS_COLOUR_WINDOWTEXT ));
1549
1550 int x = HEADER_OFFSET_X;
c801d85f 1551
63852e78
RR
1552 int numColumns = m_owner->GetColumnCount();
1553 wxListItem item;
1554 for (int i = 0; i < numColumns; i++)
1555 {
1556 m_owner->GetColumn( i, item );
f6bcfd97
BP
1557 int wCol = item.m_width;
1558 int cw = wCol - 2; // the width of the rect to draw
1559
1560 int xEnd = x + wCol;
1561
63852e78 1562 dc.SetPen( *wxWHITE_PEN );
c801d85f 1563
cf1dfa6b
VZ
1564 DoDrawRect( &dc, x, HEADER_OFFSET_Y, cw, h-2 );
1565 dc.SetClippingRegion( x, HEADER_OFFSET_Y, cw-5, h-4 );
1566 dc.DrawText( item.GetText(), x + EXTRA_WIDTH, HEADER_OFFSET_Y + EXTRA_HEIGHT );
40c70187 1567 dc.DestroyClippingRegion();
f6bcfd97
BP
1568 x += wCol;
1569
1570 if (xEnd > w+5)
1571 break;
63852e78
RR
1572 }
1573 dc.EndDrawing();
e1e955e1 1574}
c801d85f 1575
0208334d
RR
1576void wxListHeaderWindow::DrawCurrent()
1577{
63852e78
RR
1578 int x1 = m_currentX;
1579 int y1 = 0;
f6bcfd97
BP
1580 ClientToScreen( &x1, &y1 );
1581
63852e78
RR
1582 int x2 = m_currentX-1;
1583 int y2 = 0;
f6bcfd97 1584 m_owner->GetClientSize( NULL, &y2 );
63852e78 1585 m_owner->ClientToScreen( &x2, &y2 );
0208334d 1586
63852e78 1587 wxScreenDC dc;
3c679789 1588 dc.SetLogicalFunction( wxINVERT );
63852e78
RR
1589 dc.SetPen( wxPen( *wxBLACK, 2, wxSOLID ) );
1590 dc.SetBrush( *wxTRANSPARENT_BRUSH );
0208334d 1591
f6bcfd97
BP
1592 AdjustDC(dc);
1593
63852e78 1594 dc.DrawLine( x1, y1, x2, y2 );
0208334d 1595
63852e78 1596 dc.SetLogicalFunction( wxCOPY );
0208334d 1597
63852e78
RR
1598 dc.SetPen( wxNullPen );
1599 dc.SetBrush( wxNullBrush );
0208334d
RR
1600}
1601
c801d85f
KB
1602void wxListHeaderWindow::OnMouse( wxMouseEvent &event )
1603{
f6bcfd97 1604 // we want to work with logical coords
3ca6a5f0
BP
1605 int x;
1606 m_owner->CalcUnscrolledPosition(event.GetX(), 0, &x, NULL);
3ca6a5f0 1607 int y = event.GetY();
f6bcfd97 1608
cfb50f14 1609 if (m_isDragging)
0208334d 1610 {
f6bcfd97
BP
1611 // we don't draw the line beyond our window, but we allow dragging it
1612 // there
1613 int w = 0;
1614 GetClientSize( &w, NULL );
f6bcfd97 1615 m_owner->CalcUnscrolledPosition(w, 0, &w, NULL);
f6bcfd97
BP
1616 w -= 6;
1617
1618 // erase the line if it was drawn
1619 if ( m_currentX < w )
1620 DrawCurrent();
1621
63852e78
RR
1622 if (event.ButtonUp())
1623 {
1624 ReleaseMouse();
cfb50f14 1625 m_isDragging = FALSE;
f6bcfd97
BP
1626 m_dirty = TRUE;
1627 m_owner->SetColumnWidth( m_column, m_currentX - m_minX );
63852e78
RR
1628 }
1629 else
1630 {
f6bcfd97 1631 if (x > m_minX + 7)
63852e78
RR
1632 m_currentX = x;
1633 else
f6bcfd97 1634 m_currentX = m_minX + 7;
bd8289c1 1635
f6bcfd97
BP
1636 // draw in the new location
1637 if ( m_currentX < w )
1638 DrawCurrent();
bffa1c77 1639 }
0208334d 1640 }
f6bcfd97 1641 else // not dragging
c801d85f 1642 {
f6bcfd97
BP
1643 m_minX = 0;
1644 bool hit_border = FALSE;
1645
1646 // end of the current column
1647 int xpos = 0;
1648
1649 // find the column where this event occured
1650 int countCol = m_owner->GetColumnCount();
cf1dfa6b 1651 for (int col = 0; col < countCol; col++)
bffa1c77 1652 {
cf1dfa6b
VZ
1653 xpos += m_owner->GetColumnWidth( col );
1654 m_column = col;
f6bcfd97
BP
1655
1656 if ( (abs(x-xpos) < 3) && (y < 22) )
1657 {
1658 // near the column border
1659 hit_border = TRUE;
1660 break;
1661 }
1662
1663 if ( x < xpos )
1664 {
1665 // inside the column
1666 break;
1667 }
1668
1669 m_minX = xpos;
bffa1c77 1670 }
63852e78 1671
f6bcfd97 1672 if (event.LeftDown())
63852e78 1673 {
f6bcfd97
BP
1674 if (hit_border)
1675 {
1676 m_isDragging = TRUE;
1677 m_currentX = x;
1678 DrawCurrent();
1679 CaptureMouse();
1680 }
1681 else
1682 {
1683 wxWindow *parent = GetParent();
1684 wxListEvent le( wxEVT_COMMAND_LIST_COL_CLICK, parent->GetId() );
1685 le.SetEventObject( parent );
1686 le.m_col = m_column;
1687 parent->GetEventHandler()->ProcessEvent( le );
1688 }
63852e78 1689 }
f6bcfd97 1690 else if (event.Moving())
63852e78 1691 {
f6bcfd97
BP
1692 bool setCursor;
1693 if (hit_border)
1694 {
1695 setCursor = m_currentCursor == wxSTANDARD_CURSOR;
1696 m_currentCursor = m_resizeCursor;
1697 }
1698 else
1699 {
1700 setCursor = m_currentCursor != wxSTANDARD_CURSOR;
1701 m_currentCursor = wxSTANDARD_CURSOR;
1702 }
1703
1704 if ( setCursor )
1705 SetCursor(*m_currentCursor);
63852e78 1706 }
e1e955e1 1707 }
e1e955e1 1708}
c801d85f
KB
1709
1710void wxListHeaderWindow::OnSetFocus( wxFocusEvent &WXUNUSED(event) )
1711{
63852e78 1712 m_owner->SetFocus();
e1e955e1 1713}
c801d85f
KB
1714
1715//-----------------------------------------------------------------------------
1716// wxListRenameTimer (internal)
1717//-----------------------------------------------------------------------------
1718
bd8289c1
VZ
1719wxListRenameTimer::wxListRenameTimer( wxListMainWindow *owner )
1720{
63852e78 1721 m_owner = owner;
e1e955e1 1722}
c801d85f 1723
bd8289c1
VZ
1724void wxListRenameTimer::Notify()
1725{
63852e78 1726 m_owner->OnRenameTimer();
e1e955e1 1727}
c801d85f 1728
ee7ee469
RR
1729//-----------------------------------------------------------------------------
1730// wxListTextCtrl (internal)
1731//-----------------------------------------------------------------------------
1732
1733IMPLEMENT_DYNAMIC_CLASS(wxListTextCtrl,wxTextCtrl);
bd8289c1 1734
ee7ee469 1735BEGIN_EVENT_TABLE(wxListTextCtrl,wxTextCtrl)
63852e78 1736 EVT_CHAR (wxListTextCtrl::OnChar)
2c1f73ee 1737 EVT_KEY_UP (wxListTextCtrl::OnKeyUp)
63852e78 1738 EVT_KILL_FOCUS (wxListTextCtrl::OnKillFocus)
ee7ee469
RR
1739END_EVENT_TABLE()
1740
674ac8b9
VZ
1741wxListTextCtrl::wxListTextCtrl( wxWindow *parent,
1742 const wxWindowID id,
1743 bool *accept,
1744 wxString *res,
1745 wxListMainWindow *owner,
1746 const wxString &value,
1747 const wxPoint &pos,
1748 const wxSize &size,
1749 int style,
1750 const wxValidator& validator,
1751 const wxString &name )
1752 : wxTextCtrl( parent, id, value, pos, size, style, validator, name )
ee7ee469 1753{
63852e78
RR
1754 m_res = res;
1755 m_accept = accept;
1756 m_owner = owner;
5f1ea0ee
RR
1757 (*m_accept) = FALSE;
1758 (*m_res) = "";
1759 m_startValue = value;
ee7ee469
RR
1760}
1761
1762void wxListTextCtrl::OnChar( wxKeyEvent &event )
1763{
63852e78
RR
1764 if (event.m_keyCode == WXK_RETURN)
1765 {
1766 (*m_accept) = TRUE;
1767 (*m_res) = GetValue();
f6bcfd97 1768
bce1406b
RR
1769 if (!wxPendingDelete.Member(this))
1770 wxPendingDelete.Append(this);
1771
1772 if ((*m_accept) && ((*m_res) != m_startValue))
1773 m_owner->OnRenameAccept();
f6bcfd97 1774
63852e78
RR
1775 return;
1776 }
1777 if (event.m_keyCode == WXK_ESCAPE)
1778 {
1779 (*m_accept) = FALSE;
1780 (*m_res) = "";
f6bcfd97 1781
bce1406b
RR
1782 if (!wxPendingDelete.Member(this))
1783 wxPendingDelete.Append(this);
f6bcfd97 1784
63852e78
RR
1785 return;
1786 }
f6bcfd97 1787
63852e78
RR
1788 event.Skip();
1789}
1790
c13cace1
VS
1791void wxListTextCtrl::OnKeyUp( wxKeyEvent &event )
1792{
1793 // auto-grow the textctrl:
1794 wxSize parentSize = m_owner->GetSize();
1795 wxPoint myPos = GetPosition();
1796 wxSize mySize = GetSize();
1797 int sx, sy;
cf1dfa6b
VZ
1798 GetTextExtent(GetValue() + _T("MM"), &sx, &sy); // FIXME: MM??
1799 if (myPos.x + sx > parentSize.x)
1800 sx = parentSize.x - myPos.x;
1801 if (mySize.x > sx)
1802 sx = mySize.x;
c13cace1 1803 SetSize(sx, -1);
2c1f73ee 1804
c13cace1
VS
1805 event.Skip();
1806}
1807
63852e78
RR
1808void wxListTextCtrl::OnKillFocus( wxFocusEvent &WXUNUSED(event) )
1809{
bce1406b
RR
1810 if (!wxPendingDelete.Member(this))
1811 wxPendingDelete.Append(this);
004fd0c8 1812
5f1ea0ee
RR
1813 if ((*m_accept) && ((*m_res) != m_startValue))
1814 m_owner->OnRenameAccept();
ee7ee469
RR
1815}
1816
c801d85f
KB
1817//-----------------------------------------------------------------------------
1818// wxListMainWindow
1819//-----------------------------------------------------------------------------
1820
1821IMPLEMENT_DYNAMIC_CLASS(wxListMainWindow,wxScrolledWindow);
bd8289c1 1822
c801d85f
KB
1823BEGIN_EVENT_TABLE(wxListMainWindow,wxScrolledWindow)
1824 EVT_PAINT (wxListMainWindow::OnPaint)
1825 EVT_SIZE (wxListMainWindow::OnSize)
1826 EVT_MOUSE_EVENTS (wxListMainWindow::OnMouse)
1827 EVT_CHAR (wxListMainWindow::OnChar)
3dfb93fd 1828 EVT_KEY_DOWN (wxListMainWindow::OnKeyDown)
c801d85f
KB
1829 EVT_SET_FOCUS (wxListMainWindow::OnSetFocus)
1830 EVT_KILL_FOCUS (wxListMainWindow::OnKillFocus)
2fa7c206 1831 EVT_SCROLLWIN (wxListMainWindow::OnScroll)
c801d85f
KB
1832END_EVENT_TABLE()
1833
1370703e 1834void wxListMainWindow::Init()
c801d85f 1835{
139adb6a 1836 m_columns.DeleteContents( TRUE );
139adb6a 1837 m_dirty = TRUE;
cf1dfa6b
VZ
1838 m_countVirt = 0;
1839 m_lineFrom =
1840 m_lineTo = 0;
1841 m_linesPerPage = 0;
1842
1843 m_headerWidth =
1844 m_lineHeight = 0;
1370703e 1845
139adb6a
RR
1846 m_small_image_list = (wxImageList *) NULL;
1847 m_normal_image_list = (wxImageList *) NULL;
1370703e 1848
139adb6a
RR
1849 m_small_spacing = 30;
1850 m_normal_spacing = 40;
1370703e 1851
139adb6a 1852 m_hasFocus = FALSE;
1370703e
VZ
1853 m_dragCount = 0;
1854 m_isCreated = FALSE;
1855
139adb6a
RR
1856 m_lastOnSame = FALSE;
1857 m_renameTimer = new wxListRenameTimer( this );
1370703e
VZ
1858 m_renameAccept = FALSE;
1859
cf1dfa6b
VZ
1860 m_current =
1861 m_currentEdit =
efbb7287 1862 m_lineLastClicked =
1370703e 1863 m_lineBeforeLastClicked = (size_t)-1;
e1e955e1 1864}
c801d85f 1865
cf1dfa6b
VZ
1866void wxListMainWindow::InitScrolling()
1867{
1868 if ( HasFlag(wxLC_REPORT) )
1869 {
1870 m_xScroll = SCROLL_UNIT_X;
1871 m_yScroll = SCROLL_UNIT_Y;
1872 }
1873 else
1874 {
1875 m_xScroll = SCROLL_UNIT_Y;
1876 m_yScroll = 0;
1877 }
1878}
1879
1370703e 1880wxListMainWindow::wxListMainWindow()
c801d85f 1881{
1370703e
VZ
1882 Init();
1883
1370703e
VZ
1884 m_hilightBrush = (wxBrush *) NULL;
1885
1886 m_xScroll =
1887 m_yScroll = 0;
1888}
1889
1890wxListMainWindow::wxListMainWindow( wxWindow *parent,
1891 wxWindowID id,
1892 const wxPoint& pos,
1893 const wxSize& size,
1894 long style,
1895 const wxString &name )
1896 : wxScrolledWindow( parent, id, pos, size,
1897 style | wxHSCROLL | wxVSCROLL, name )
1898{
1899 Init();
1900
139adb6a 1901 m_hilightBrush = new wxBrush( wxSystemSettings::GetSystemColour(wxSYS_COLOUR_HIGHLIGHT), wxSOLID );
139adb6a
RR
1902 wxSize sz = size;
1903 sz.y = 25;
bd8289c1 1904
cf1dfa6b 1905 InitScrolling();
139adb6a 1906 SetScrollbars( m_xScroll, m_yScroll, 0, 0, 0, 0 );
bd8289c1 1907
91fc2bdc 1908 SetBackgroundColour( wxSystemSettings::GetSystemColour( wxSYS_COLOUR_LISTBOX ) );
e1e955e1 1909}
c801d85f 1910
fd9811b1 1911wxListMainWindow::~wxListMainWindow()
c801d85f 1912{
12c1b46a
RR
1913 DeleteEverything();
1914
cf1dfa6b 1915 delete m_hilightBrush;
004fd0c8 1916
139adb6a 1917 delete m_renameTimer;
e1e955e1 1918}
c801d85f 1919
cf1dfa6b 1920void wxListMainWindow::CacheLineData(size_t line)
c801d85f 1921{
cf1dfa6b 1922 wxListCtrl *listctrl = GetListCtrl();
25e3a937 1923
cf1dfa6b 1924 wxListLineData *ld = GetFirstLine();
f6bcfd97 1925
cf1dfa6b
VZ
1926 size_t countCol = GetColumnCount();
1927 for ( size_t col = 0; col < countCol; col++ )
1928 {
1929 ld->SetText(col, listctrl->OnGetItemText(line, col));
1930 }
1931
1932 ld->SetImage(0, listctrl->OnGetItemImage(line));
1933 ld->SetLineIndex(line);
e1e955e1 1934}
c801d85f 1935
cf1dfa6b 1936wxListLineData *wxListMainWindow::GetFirstLine() const
c801d85f 1937{
cf1dfa6b 1938 wxASSERT_MSG( !IsEmpty(), _T("invalid line index") );
2c1f73ee 1939
cf1dfa6b 1940 if ( m_lines.IsEmpty() )
2c1f73ee 1941 {
cf1dfa6b
VZ
1942 // normal controls are supposed to have something in m_lines
1943 // already if it's not empty
1944 wxASSERT_MSG( IsVirtual(), _T("logic error") );
1945
1946 wxListMainWindow *self = wxConstCast(this, wxListMainWindow);
1947 wxListLineData *line = new wxListLineData( self, 0 );
1948 self->m_lines.Add(line);
2c1f73ee
VZ
1949 }
1950
cf1dfa6b 1951 m_lines[0].SetLineIndex(0);
f60d0f94 1952
cf1dfa6b
VZ
1953 return &m_lines[0];
1954}
1955
1956wxCoord wxListMainWindow::GetLineHeight() const
1957{
1958 wxASSERT_MSG( HasFlag(wxLC_REPORT), _T("only works in report mode") );
673dfcfa 1959
cf1dfa6b
VZ
1960 // we cache the line height as calling GetTextExtent() is slow
1961 if ( !m_lineHeight )
2c1f73ee 1962 {
cf1dfa6b 1963 wxListMainWindow *self = wxConstCast(this, wxListMainWindow);
bd8289c1 1964
cf1dfa6b
VZ
1965 wxClientDC dc( self );
1966 dc.SetFont( GetFont() );
c801d85f 1967
cf1dfa6b
VZ
1968 wxCoord y;
1969 dc.GetTextExtent(_T("H"), NULL, &y);
004fd0c8 1970
cf1dfa6b
VZ
1971 if ( y < SCROLL_UNIT_Y )
1972 y = SCROLL_UNIT_Y;
1973 y += EXTRA_HEIGHT;
206b0a67 1974
cf1dfa6b
VZ
1975 self->m_lineHeight = y + LINE_SPACING;
1976 }
bffa1c77 1977
cf1dfa6b
VZ
1978 return m_lineHeight;
1979}
bffa1c77 1980
cf1dfa6b
VZ
1981wxCoord wxListMainWindow::GetLineY(size_t line) const
1982{
1983 wxASSERT_MSG( HasFlag(wxLC_REPORT), _T("only works in report mode") );
1370703e 1984
cf1dfa6b
VZ
1985 return LINE_SPACING + line*GetLineHeight();
1986}
206b0a67 1987
cf1dfa6b
VZ
1988bool wxListMainWindow::IsHilighted(size_t line) const
1989{
1990 if ( IsVirtual() )
1991 {
1992 return m_selections.Index(line) != wxNOT_FOUND;
1993 }
1994 else // !virtual
1995 {
1996 wxListLineData *ld = GetLine(line);
1997 wxCHECK_MSG( ld, FALSE, _T("invalid index in IsHilighted") );
1998
1999 return ld->IsHilighted();
2000 }
2001}
2002
2003bool wxListMainWindow::HilightLine( size_t line, bool hilight )
2004{
2005 bool changed;
2006
2007 if ( IsVirtual() )
2008 {
2009 changed = FALSE;
2010
2011 int index = m_selections.Index(line);
2012 if ( hilight )
2013 {
2014 if ( index == wxNOT_FOUND )
2015 {
2016 m_selections.Add(line);
2017 changed = TRUE;
2018 }
2019 }
2020 else // !hilight
2021 {
2022 if ( index != wxNOT_FOUND )
2023 {
2024 m_selections.RemoveAt((size_t)index);
2025 changed = TRUE;
2026 }
2027 }
2028 }
2029 else // !virtual
2030 {
2031 wxListLineData *ld = GetLine(line);
2032 wxCHECK_MSG( ld, FALSE, _T("invalid index in IsHilighted") );
2033
2034 changed = ld->Hilight(hilight);
2035 }
2036
2037 if ( changed )
2038 {
2039 SendNotify( line, hilight ? wxEVT_COMMAND_LIST_ITEM_SELECTED
2040 : wxEVT_COMMAND_LIST_ITEM_DESELECTED );
2041 }
2042
2043 return changed;
2044}
2045
2046void wxListMainWindow::RefreshLine( size_t line )
2047{
2048 wxRect rect = GetLine(line)->GetRect();
2049
2050 CalcScrolledPosition( rect.x, rect.y, &rect.x, &rect.y );
2051 RefreshRect( rect );
2052}
2053
2054void wxListMainWindow::RefreshLines( size_t lineFrom, size_t lineTo )
2055{
2056 // we suppose that they are ordered by caller
2057 wxASSERT_MSG( lineFrom <= lineTo, _T("indices in disorder") );
2058
2059 if ( HasFlag(wxLC_REPORT) )
2060 {
2061 if ( lineFrom < m_lineFrom )
2062 lineFrom = m_lineFrom;
2063 if ( lineTo > m_lineTo )
2064 lineTo = m_lineTo;
2065
2066 wxRect rect;
2067 rect.x = 0;
2068 rect.y = GetLineY(lineFrom);
2069 rect.width = GetClientSize().x;
2070 rect.height = GetLineY(lineTo) - rect.y;
2071
2072 CalcScrolledPosition( rect.x, rect.y, &rect.x, &rect.y );
2073 RefreshRect( rect );
2074 }
2075 else // !report
2076 {
2077 // TODO: this should be optimized...
2078 for ( size_t line = lineFrom; line <= lineTo; line++ )
2079 {
2080 RefreshLine(line);
2081 }
2082 }
2083}
2084
2085void wxListMainWindow::OnPaint( wxPaintEvent &WXUNUSED(event) )
2086{
2087 // Note: a wxPaintDC must be constructed even if no drawing is
2088 // done (a Windows requirement).
2089 wxPaintDC dc( this );
2090
2091 if ( m_dirty )
2092 {
2093 // postpone redrawing until the next OnIdle() call to minimize flicker
2094 return;
2095 }
2096
2097 if ( IsEmpty() )
2098 {
2099 // empty control. nothing to draw
2100 return;
2101 }
2102
2103 PrepareDC( dc );
2104
2105 int dev_x, dev_y;
2106 CalcScrolledPosition( 0, 0, &dev_x, &dev_y );
2107
2108 dc.BeginDrawing();
2109
2110 dc.SetFont( GetFont() );
2111
2112 if ( HasFlag(wxLC_REPORT) )
2113 {
2114 int lineSpacing = GetLineHeight();
2115
2116 for ( size_t line = m_lineFrom; line <= m_lineTo; line++ )
2117 {
2118 GetLine(line)->Draw( &dc,
2119 GetLineY(line),
2120 lineSpacing,
2121 IsHilighted(line) );
2122 }
2123
2124 if ( HasFlag(wxLC_HRULES) )
2125 {
4176fb7d
SC
2126#ifdef __WXMAC__
2127 wxPen pen(wxWHITE, 1, wxSOLID);
2128#else
cf1dfa6b
VZ
2129 wxPen pen(wxSystemSettings::
2130 GetSystemColour(wxSYS_COLOUR_3DLIGHT), 1, wxSOLID);
4176fb7d 2131#endif
cf1dfa6b
VZ
2132 wxSize clientSize = GetClientSize();
2133
2134 for ( size_t i = m_lineFrom; i <= m_lineTo; i++ )
2135 {
2136 dc.SetPen(pen);
2137 dc.SetBrush( *wxTRANSPARENT_BRUSH );
2138 dc.DrawLine(0 - dev_x, i*lineSpacing,
2139 clientSize.x - dev_x, i*lineSpacing);
2140 }
2141
2142 // Draw last horizontal rule
2143 if ( m_lineTo > m_lineFrom )
2144 {
2145 dc.SetPen(pen);
2146 dc.SetBrush( *wxTRANSPARENT_BRUSH );
2147 dc.DrawLine(0 - dev_x, m_lineTo*lineSpacing,
2148 clientSize.x - dev_x , m_lineTo*lineSpacing );
2149 }
2c1f73ee 2150 }
206b0a67
JS
2151
2152 // Draw vertical rules if required
cf1dfa6b 2153 if ( HasFlag(wxLC_VRULES) && !IsEmpty() )
206b0a67 2154 {
4176fb7d
SC
2155#ifdef __WXMAC__
2156 wxPen pen(wxWHITE, 1, wxSOLID);
2157#else
cf1dfa6b
VZ
2158 wxPen pen(wxSystemSettings::
2159 GetSystemColour(wxSYS_COLOUR_3DLIGHT), 1, wxSOLID);
4176fb7d 2160#endif
cf1dfa6b 2161
206b0a67
JS
2162 int col = 0;
2163 wxRect firstItemRect;
2164 wxRect lastItemRect;
2165 GetItemRect(0, firstItemRect);
2166 GetItemRect(GetItemCount() - 1, lastItemRect);
2167 int x = firstItemRect.GetX();
673dfcfa
JS
2168 dc.SetPen(pen);
2169 dc.SetBrush(* wxTRANSPARENT_BRUSH);
206b0a67
JS
2170 for (col = 0; col < GetColumnCount(); col++)
2171 {
2172 int colWidth = GetColumnWidth(col);
cf1dfa6b
VZ
2173 x += colWidth;
2174 dc.DrawLine(x - dev_x, firstItemRect.GetY() - 1 - dev_y,
2175 x - dev_x, lastItemRect.GetBottom() + 1 - dev_y);
206b0a67 2176 }
d786bf87 2177 }
139adb6a 2178 }
cf1dfa6b 2179 else // !report
139adb6a 2180 {
1370703e 2181 size_t count = GetItemCount();
cf1dfa6b
VZ
2182 for ( size_t i = 0; i < count; i++ )
2183 {
2184 GetLine(i)->Draw( &dc );
2185 }
139adb6a 2186 }
004fd0c8 2187
cf1dfa6b
VZ
2188 if ( HasCurrent() && m_hasFocus )
2189 {
2190 wxRect rect;
2191
2192 if ( IsVirtual() )
2193 {
2194 // just offset the rect of the first line to position it correctly
2195 wxListLineData *line = GetFirstLine();
2196 rect = line->GetHighlightRect();
2197 rect.y = GetLineY(m_current);
2198 }
2199 else
2200 {
2201 rect = GetLine(m_current)->GetHighlightRect();
2202 }
4176fb7d
SC
2203#ifdef __WXMAC__
2204 // no rect outline, we already have the background color
2205#else
cf1dfa6b
VZ
2206 dc.SetPen( *wxBLACK_PEN );
2207 dc.SetBrush( *wxTRANSPARENT_BRUSH );
2208 dc.DrawRectangle( rect );
4176fb7d 2209#endif
cf1dfa6b 2210 }
c801d85f 2211
139adb6a 2212 dc.EndDrawing();
e1e955e1 2213}
c801d85f 2214
debe6624 2215void wxListMainWindow::HilightAll( bool on )
c801d85f 2216{
cf1dfa6b
VZ
2217 bool needsRefresh = FALSE;
2218
1370703e 2219 size_t count = GetItemCount();
cf1dfa6b 2220 for ( size_t line = 0; line < count; line++ )
c801d85f 2221 {
cf1dfa6b 2222 if ( HilightLine( line, on ) )
139adb6a 2223 {
cf1dfa6b
VZ
2224 if ( HasFlag(wxLC_REPORT) )
2225 {
2226 needsRefresh = TRUE;
2227 }
2228 else
2229 {
2230 RefreshLine(line);
2231 }
139adb6a 2232 }
e1e955e1 2233 }
cf1dfa6b
VZ
2234
2235 if ( needsRefresh )
2236 {
2237 RefreshLines( 0, count - 1 );
2238 }
e1e955e1 2239}
c801d85f 2240
cf1dfa6b 2241void wxListMainWindow::SendNotify( size_t line,
05a7f61d
VZ
2242 wxEventType command,
2243 wxPoint point )
c801d85f 2244{
139adb6a
RR
2245 wxListEvent le( command, GetParent()->GetId() );
2246 le.SetEventObject( GetParent() );
cf1dfa6b 2247 le.m_itemIndex = line;
05a7f61d
VZ
2248
2249 // set only for events which have position
2250 if ( point != wxDefaultPosition )
2251 le.m_pointDrag = point;
2252
cf1dfa6b 2253 GetLine(line)->GetItem( 0, le.m_item );
6e228e42 2254 GetParent()->GetEventHandler()->ProcessEvent( le );
e1e955e1 2255}
c801d85f 2256
cf1dfa6b 2257void wxListMainWindow::OnFocusLine( size_t WXUNUSED(line) )
c801d85f
KB
2258{
2259// SendNotify( line, wxEVT_COMMAND_LIST_ITEM_FOCUSSED );
e1e955e1 2260}
c801d85f 2261
cf1dfa6b 2262void wxListMainWindow::OnUnfocusLine( size_t WXUNUSED(line) )
c801d85f
KB
2263{
2264// SendNotify( line, wxEVT_COMMAND_LIST_ITEM_UNFOCUSSED );
e1e955e1 2265}
c801d85f 2266
5f1ea0ee 2267void wxListMainWindow::EditLabel( long item )
c801d85f 2268{
cf1dfa6b
VZ
2269 wxCHECK_RET( (item >= 0) && ((size_t)item < GetItemCount()),
2270 wxT("wrong index in wxListCtrl::EditLabel()") );
004fd0c8 2271
1370703e 2272 m_currentEdit = (size_t)item;
e179bd65 2273
fd9811b1 2274 wxListEvent le( wxEVT_COMMAND_LIST_BEGIN_LABEL_EDIT, GetParent()->GetId() );
139adb6a 2275 le.SetEventObject( GetParent() );
1370703e
VZ
2276 le.m_itemIndex = item;
2277 wxListLineData *data = GetLine(m_currentEdit);
2278 wxCHECK_RET( data, _T("invalid index in EditLabel()") );
2279 data->GetItem( 0, le.m_item );
139adb6a 2280 GetParent()->GetEventHandler()->ProcessEvent( le );
004fd0c8 2281
86f975a8 2282 if (!le.IsAllowed())
5f1ea0ee 2283 return;
004fd0c8 2284
cf1dfa6b
VZ
2285 // We have to call this here because the label in question might just have
2286 // been added and no screen update taken place.
2287 if (m_dirty)
2288 wxSafeYield();
004fd0c8 2289
92976ab6
RR
2290 wxClientDC dc(this);
2291 PrepareDC( dc );
bd8289c1 2292
cf1dfa6b
VZ
2293 wxString s = data->GetText(0);
2294 wxRect rectLabel = data->GetLabelRect();
2295
2296 rectLabel.x = dc.LogicalToDeviceX( rectLabel.x );
2297 rectLabel.y = dc.LogicalToDeviceY( rectLabel.y );
2298
2299 wxListTextCtrl *text = new wxListTextCtrl
2300 (
2301 this, -1,
2302 &m_renameAccept,
2303 &m_renameRes,
2304 this,
2305 s,
2306 wxPoint(rectLabel.x-4,rectLabel.y-4),
2307 wxSize(rectLabel.width+11,rectLabel.height+8)
2308 );
92976ab6 2309 text->SetFocus();
e1e955e1 2310}
c801d85f 2311
e179bd65
RR
2312void wxListMainWindow::OnRenameTimer()
2313{
cf1dfa6b 2314 wxCHECK_RET( HasCurrent(), wxT("unexpected rename timer") );
004fd0c8 2315
cf1dfa6b 2316 EditLabel( m_current );
e179bd65
RR
2317}
2318
c801d85f
KB
2319void wxListMainWindow::OnRenameAccept()
2320{
e179bd65
RR
2321 wxListEvent le( wxEVT_COMMAND_LIST_END_LABEL_EDIT, GetParent()->GetId() );
2322 le.SetEventObject( GetParent() );
1370703e
VZ
2323 le.m_itemIndex = m_currentEdit;
2324
2325 wxListLineData *data = GetLine(m_currentEdit);
2326 wxCHECK_RET( data, _T("invalid index in OnRenameAccept()") );
2327
2328 data->GetItem( 0, le.m_item );
e179bd65
RR
2329 le.m_item.m_text = m_renameRes;
2330 GetParent()->GetEventHandler()->ProcessEvent( le );
004fd0c8 2331
e179bd65 2332 if (!le.IsAllowed()) return;
004fd0c8 2333
5f1ea0ee
RR
2334 wxListItem info;
2335 info.m_mask = wxLIST_MASK_TEXT;
2336 info.m_itemId = le.m_itemIndex;
2337 info.m_text = m_renameRes;
aaa37c0d 2338 info.SetTextColour(le.m_item.GetTextColour());
5f1ea0ee 2339 SetItem( info );
e1e955e1 2340}
c801d85f
KB
2341
2342void wxListMainWindow::OnMouse( wxMouseEvent &event )
2343{
3e1c4e00 2344 event.SetEventObject( GetParent() );
cf1dfa6b
VZ
2345 if ( GetParent()->GetEventHandler()->ProcessEvent( event) )
2346 return;
2347
2348 if ( !HasCurrent() || IsEmpty() )
2349 return;
2350
2351 if (m_dirty)
2352 return;
e3e65dac 2353
cf1dfa6b
VZ
2354 if ( !(event.Dragging() || event.ButtonDown() || event.LeftUp() ||
2355 event.ButtonDClick()) )
2356 return;
c801d85f 2357
aaef15bf
RR
2358 int x = event.GetX();
2359 int y = event.GetY();
2360 CalcUnscrolledPosition( x, y, &x, &y );
004fd0c8 2361
51cc4dad 2362 /* Did we actually hit an item ? */
92976ab6 2363 long hitResult = 0;
1370703e 2364
cf1dfa6b
VZ
2365 size_t count = GetItemCount(),
2366 current;
2367
2368 if ( HasFlag(wxLC_REPORT) )
92976ab6 2369 {
cf1dfa6b
VZ
2370 wxCoord lineHeight = GetLineHeight();
2371
2372 current = y / lineHeight;
2373 hitResult = GetFirstLine()->IsHit( x, y % lineHeight );
2374 }
2375 else // !report
2376 {
2377 // TODO: optimize it too! this is less simple than for report view but
2378 // enumerating all items is still not a way to do it!!
2379 for ( current = 0; current < count; current++ )
2380 {
2381 wxListLineData *line = (wxListLineData *) NULL;
2382 line = GetLine(current);
2383 hitResult = line->IsHit( x, y );
2384 if (hitResult)
2385 break;
2386 }
92976ab6 2387 }
bd8289c1 2388
fd9811b1 2389 if (event.Dragging())
92976ab6 2390 {
fd9811b1 2391 if (m_dragCount == 0)
bffa1c77
VZ
2392 m_dragStart = wxPoint(x,y);
2393
fd9811b1 2394 m_dragCount++;
bffa1c77 2395
cf1dfa6b
VZ
2396 if (m_dragCount != 3)
2397 return;
bffa1c77 2398
05a7f61d
VZ
2399 int command = event.RightIsDown() ? wxEVT_COMMAND_LIST_BEGIN_RDRAG
2400 : wxEVT_COMMAND_LIST_BEGIN_DRAG;
bffa1c77 2401
fd9811b1 2402 wxListEvent le( command, GetParent()->GetId() );
92976ab6 2403 le.SetEventObject( GetParent() );
bffa1c77
VZ
2404 le.m_pointDrag = m_dragStart;
2405 GetParent()->GetEventHandler()->ProcessEvent( le );
2406
2407 return;
92976ab6 2408 }
fd9811b1
RR
2409 else
2410 {
2411 m_dragCount = 0;
2412 }
bd8289c1 2413
cf1dfa6b
VZ
2414 if ( !hitResult )
2415 {
2416 // outside of any item
2417 return;
2418 }
bd8289c1 2419
efbb7287 2420 bool forceClick = FALSE;
92976ab6
RR
2421 if (event.ButtonDClick())
2422 {
92976ab6 2423 m_renameTimer->Stop();
efbb7287
VZ
2424 m_lastOnSame = FALSE;
2425
cf1dfa6b 2426 if ( current == m_lineBeforeLastClicked )
efbb7287 2427 {
cf1dfa6b 2428 SendNotify( current, wxEVT_COMMAND_LIST_ITEM_ACTIVATED );
004fd0c8 2429
efbb7287
VZ
2430 return;
2431 }
2432 else
2433 {
2434 // the first click was on another item, so don't interpret this as
2435 // a double click, but as a simple click instead
2436 forceClick = TRUE;
2437 }
92976ab6 2438 }
bd8289c1 2439
92976ab6 2440 if (event.LeftUp() && m_lastOnSame)
c801d85f 2441 {
cf1dfa6b 2442 if ((current == m_current) &&
92976ab6 2443 (hitResult == wxLIST_HITTEST_ONITEMLABEL) &&
cf1dfa6b 2444 HasFlag(wxLC_EDIT_LABELS) )
92976ab6
RR
2445 {
2446 m_renameTimer->Start( 100, TRUE );
2447 }
2448 m_lastOnSame = FALSE;
e1e955e1 2449 }
cf1dfa6b 2450 else if (event.RightDown())
b204641e 2451 {
cf1dfa6b 2452 SendNotify( current, wxEVT_COMMAND_LIST_ITEM_RIGHT_CLICK,
05a7f61d 2453 event.GetPosition() );
b204641e 2454 }
cf1dfa6b 2455 else if (event.MiddleDown())
b204641e 2456 {
cf1dfa6b 2457 SendNotify( current, wxEVT_COMMAND_LIST_ITEM_MIDDLE_CLICK );
92976ab6 2458 }
cf1dfa6b 2459 else if ( event.LeftDown() || forceClick )
92976ab6 2460 {
efbb7287 2461 m_lineBeforeLastClicked = m_lineLastClicked;
cf1dfa6b
VZ
2462 m_lineLastClicked = current;
2463
2464 size_t oldCurrent = m_current;
efbb7287 2465
cf1dfa6b
VZ
2466 if ( HasFlag(wxLC_SINGLE_SEL) ||
2467 !(event.ControlDown() || event.ShiftDown()) )
b204641e 2468 {
cf1dfa6b 2469 m_current = current;
92976ab6 2470 HilightAll( FALSE );
cf1dfa6b
VZ
2471
2472 ReverseHilight(m_current);
e1e955e1 2473 }
cf1dfa6b 2474 else // multi sel
b204641e 2475 {
473d087e 2476 if (event.ControlDown())
92976ab6 2477 {
cf1dfa6b
VZ
2478 m_current = current;
2479
2480 ReverseHilight(m_current);
92976ab6 2481 }
473d087e 2482 else if (event.ShiftDown())
92976ab6 2483 {
cf1dfa6b 2484 m_current = current;
bffa1c77 2485
cf1dfa6b
VZ
2486 size_t lineFrom = oldCurrent,
2487 lineTo = current;
f6bcfd97 2488
cf1dfa6b 2489 if ( lineTo < lineFrom )
92976ab6 2490 {
cf1dfa6b
VZ
2491 lineTo = lineFrom;
2492 lineFrom = m_current;
92976ab6
RR
2493 }
2494
cf1dfa6b
VZ
2495 bool needsRefresh = FALSE;
2496 for ( size_t i = lineFrom; i <= lineTo; i++ )
004fd0c8 2497 {
cf1dfa6b
VZ
2498 if ( HilightLine(i, TRUE) )
2499 needsRefresh = TRUE;
bffa1c77
VZ
2500 }
2501
cf1dfa6b 2502 if ( needsRefresh )
92976ab6 2503 {
cf1dfa6b 2504 RefreshLines(lineFrom, lineTo);
92976ab6
RR
2505 }
2506 }
cf1dfa6b 2507 else // !ctrl, !shift
92976ab6 2508 {
cf1dfa6b
VZ
2509 // test in the enclosing if should make it impossible
2510 wxFAIL_MSG( _T("how did we get here?") );
92976ab6 2511 }
e1e955e1 2512 }
cf1dfa6b 2513
92976ab6
RR
2514 if (m_current != oldCurrent)
2515 {
2516 RefreshLine( oldCurrent );
cf1dfa6b
VZ
2517 OnUnfocusLine( oldCurrent );
2518 OnFocusLine( m_current );
92976ab6 2519 }
efbb7287
VZ
2520
2521 // forceClick is only set if the previous click was on another item
2522 m_lastOnSame = !forceClick && (m_current == oldCurrent);
e1e955e1 2523 }
e1e955e1 2524}
c801d85f 2525
e179bd65 2526void wxListMainWindow::MoveToFocus()
c801d85f 2527{
cf1dfa6b
VZ
2528 if (!HasCurrent())
2529 return;
004fd0c8 2530
cf1dfa6b
VZ
2531 wxListLineData *data = IsVirtual() ? GetFirstLine() : GetLine(m_current);
2532 wxRect rect = data->GetRect();
cf3da716 2533
cf1dfa6b 2534 int client_w, client_h;
cf3da716 2535 GetClientSize( &client_w, &client_h );
f6bcfd97 2536
cf3da716
RR
2537 int view_x = m_xScroll*GetScrollPos( wxHORIZONTAL );
2538 int view_y = m_yScroll*GetScrollPos( wxVERTICAL );
004fd0c8 2539
cf1dfa6b 2540 if ( HasFlag(wxLC_REPORT) )
92976ab6 2541 {
cf1dfa6b
VZ
2542 if (rect.y < view_y )
2543 Scroll( -1, rect.y/m_yScroll );
2544 if (rect.y+rect.height+5 > view_y+client_h)
2545 Scroll( -1, (rect.y+rect.height-client_h+SCROLL_UNIT_Y)/m_yScroll );
2546
2547 UpdateShownLinesRange();
92976ab6
RR
2548 }
2549 else
2550 {
cf1dfa6b
VZ
2551 if (rect.x-view_x < 5)
2552 Scroll( (rect.x-5)/m_xScroll, -1 );
2553 if (rect.x+rect.width-5 > view_x+client_w)
2554 Scroll( (rect.x+rect.width-client_w+SCROLL_UNIT_X)/m_xScroll, -1 );
92976ab6 2555 }
e1e955e1 2556}
c801d85f 2557
cf1dfa6b
VZ
2558// ----------------------------------------------------------------------------
2559// keyboard handling
2560// ----------------------------------------------------------------------------
2561
2562void wxListMainWindow::OnArrowChar(size_t newCurrent, const wxKeyEvent& event)
c801d85f 2563{
cf1dfa6b
VZ
2564 wxCHECK_RET( newCurrent < (size_t)GetItemCount(),
2565 _T("invalid item index in OnArrowChar()") );
2566
2567 size_t oldCurrent = m_current;
2568
2569 // in single selection we just ignore Shift as we can't select several
2570 // items anyhow
2571 if ( event.ShiftDown() && !HasFlag(wxLC_SINGLE_SEL) )
2572 {
2573 m_current = newCurrent;
2574
2575 // select all the items between the old and the new one
2576 if ( oldCurrent > newCurrent )
2577 {
2578 newCurrent = oldCurrent;
2579 oldCurrent = m_current;
2580 }
2581
2582 bool needsRefresh = FALSE;
2583 for ( size_t line = oldCurrent; line <= newCurrent; line++ )
2584 {
2585 if ( HilightLine( line ) )
2586 {
2587 needsRefresh = TRUE;
2588 }
2589 }
2590
2591 if ( needsRefresh )
2592 RefreshLines( oldCurrent, newCurrent );
2593 }
2594 else // !shift
2595 {
2596 m_current = newCurrent;
2597
2598 HilightLine( oldCurrent, FALSE );
2599 RefreshLine( oldCurrent );
2600
2601 if ( !event.ControlDown() )
2602 {
2603 HilightLine( m_current, TRUE );
2604 }
2605 }
2606
2607 OnUnfocusLine( oldCurrent );
2608 OnFocusLine( m_current );
92976ab6 2609 RefreshLine( m_current );
cf1dfa6b 2610
cf3da716 2611 MoveToFocus();
e1e955e1 2612}
c801d85f 2613
3dfb93fd
RR
2614void wxListMainWindow::OnKeyDown( wxKeyEvent &event )
2615{
2616 wxWindow *parent = GetParent();
004fd0c8 2617
3dfb93fd
RR
2618 /* we propagate the key event up */
2619 wxKeyEvent ke( wxEVT_KEY_DOWN );
2620 ke.m_shiftDown = event.m_shiftDown;
2621 ke.m_controlDown = event.m_controlDown;
2622 ke.m_altDown = event.m_altDown;
2623 ke.m_metaDown = event.m_metaDown;
2624 ke.m_keyCode = event.m_keyCode;
2625 ke.m_x = event.m_x;
2626 ke.m_y = event.m_y;
2627 ke.SetEventObject( parent );
2628 if (parent->GetEventHandler()->ProcessEvent( ke )) return;
004fd0c8 2629
3dfb93fd
RR
2630 event.Skip();
2631}
004fd0c8 2632
c801d85f
KB
2633void wxListMainWindow::OnChar( wxKeyEvent &event )
2634{
51cc4dad 2635 wxWindow *parent = GetParent();
004fd0c8 2636
51cc4dad 2637 /* we send a list_key event up */
cf1dfa6b 2638 if ( HasCurrent() )
f6bcfd97
BP
2639 {
2640 wxListEvent le( wxEVT_COMMAND_LIST_KEY_DOWN, GetParent()->GetId() );
cf1dfa6b
VZ
2641 le.m_itemIndex = m_current;
2642 GetLine(m_current)->GetItem( 0, le.m_item );
f6bcfd97
BP
2643 le.m_code = (int)event.KeyCode();
2644 le.SetEventObject( parent );
2645 parent->GetEventHandler()->ProcessEvent( le );
2646 }
51cc4dad 2647
3dfb93fd
RR
2648 /* we propagate the char event up */
2649 wxKeyEvent ke( wxEVT_CHAR );
51cc4dad
RR
2650 ke.m_shiftDown = event.m_shiftDown;
2651 ke.m_controlDown = event.m_controlDown;
2652 ke.m_altDown = event.m_altDown;
2653 ke.m_metaDown = event.m_metaDown;
2654 ke.m_keyCode = event.m_keyCode;
2655 ke.m_x = event.m_x;
2656 ke.m_y = event.m_y;
2657 ke.SetEventObject( parent );
2658 if (parent->GetEventHandler()->ProcessEvent( ke )) return;
004fd0c8 2659
012a03e0
RR
2660 if (event.KeyCode() == WXK_TAB)
2661 {
2662 wxNavigationKeyEvent nevent;
c5145d41 2663 nevent.SetWindowChange( event.ControlDown() );
012a03e0 2664 nevent.SetDirection( !event.ShiftDown() );
8253c7fd 2665 nevent.SetEventObject( GetParent()->GetParent() );
012a03e0 2666 nevent.SetCurrentFocus( m_parent );
8253c7fd 2667 if (GetParent()->GetParent()->GetEventHandler()->ProcessEvent( nevent )) return;
012a03e0 2668 }
004fd0c8 2669
51cc4dad 2670 /* no item -> nothing to do */
cf1dfa6b 2671 if (!HasCurrent())
c801d85f 2672 {
51cc4dad
RR
2673 event.Skip();
2674 return;
e1e955e1 2675 }
51cc4dad
RR
2676
2677 switch (event.KeyCode())
c801d85f 2678 {
51cc4dad 2679 case WXK_UP:
cf1dfa6b
VZ
2680 if ( m_current > 0 )
2681 OnArrowChar( m_current - 1, event );
51cc4dad 2682 break;
cf1dfa6b 2683
51cc4dad 2684 case WXK_DOWN:
cf1dfa6b
VZ
2685 if ( m_current < (size_t)GetItemCount() - 1 )
2686 OnArrowChar( m_current + 1, event );
51cc4dad 2687 break;
cf1dfa6b 2688
51cc4dad 2689 case WXK_END:
1370703e 2690 if (!IsEmpty())
cf1dfa6b 2691 OnArrowChar( GetItemCount() - 1, event );
51cc4dad 2692 break;
cf1dfa6b 2693
51cc4dad 2694 case WXK_HOME:
1370703e 2695 if (!IsEmpty())
cf1dfa6b 2696 OnArrowChar( 0, event );
51cc4dad 2697 break;
cf1dfa6b 2698
51cc4dad 2699 case WXK_PRIOR:
f6bcfd97 2700 {
cf1dfa6b
VZ
2701 int steps = 0;
2702 if ( HasFlag(wxLC_REPORT) )
2703 {
2704 steps = m_linesPerPage - 1;
2705 }
2706 else
2707 {
2708 steps = m_current % m_linesPerPage;
2709 }
2710
2711 int index = m_current - steps;
2712 if (index < 0)
2713 index = 0;
2714
2715 OnArrowChar( index, event );
51cc4dad 2716 }
51cc4dad 2717 break;
cf1dfa6b 2718
51cc4dad 2719 case WXK_NEXT:
bffa1c77 2720 {
cf1dfa6b
VZ
2721 int steps = 0;
2722 if ( HasFlag(wxLC_REPORT) )
2723 {
2724 steps = m_linesPerPage - 1;
2725 }
2726 else
2727 {
2728 steps = m_linesPerPage - (m_current % m_linesPerPage) - 1;
2729 }
f6bcfd97 2730
cf1dfa6b
VZ
2731 size_t index = m_current + steps;
2732 size_t count = GetItemCount();
2733 if ( index >= count )
2734 index = count - 1;
2735
2736 OnArrowChar( index, event );
51cc4dad 2737 }
51cc4dad 2738 break;
cf1dfa6b 2739
51cc4dad 2740 case WXK_LEFT:
cf1dfa6b 2741 if ( !HasFlag(wxLC_REPORT) )
51cc4dad 2742 {
cf1dfa6b
VZ
2743 int index = m_current - m_linesPerPage;
2744 if (index < 0)
2745 index = 0;
2746
2747 OnArrowChar( index, event );
51cc4dad
RR
2748 }
2749 break;
cf1dfa6b 2750
51cc4dad 2751 case WXK_RIGHT:
cf1dfa6b 2752 if ( !HasFlag(wxLC_REPORT) )
51cc4dad 2753 {
cf1dfa6b
VZ
2754 size_t index = m_current + m_linesPerPage;
2755
2756 size_t count = GetItemCount();
2757 if ( index >= count )
2758 index = count - 1;
2759
2760 OnArrowChar( index, event );
51cc4dad
RR
2761 }
2762 break;
cf1dfa6b 2763
51cc4dad 2764 case WXK_SPACE:
cf1dfa6b 2765 if ( HasFlag(wxLC_SINGLE_SEL) )
33d0e17c 2766 {
cf1dfa6b
VZ
2767 wxListEvent le( wxEVT_COMMAND_LIST_ITEM_ACTIVATED,
2768 GetParent()->GetId() );
33d0e17c 2769 le.SetEventObject( GetParent() );
cf1dfa6b
VZ
2770 le.m_itemIndex = m_current;
2771 GetLine(m_current)->GetItem( 0, le.m_item );
33d0e17c
RR
2772 GetParent()->GetEventHandler()->ProcessEvent( le );
2773 }
2774 else
2775 {
cf1dfa6b 2776 ReverseHilight(m_current);
51cc4dad
RR
2777 }
2778 break;
cf1dfa6b 2779
51cc4dad
RR
2780 case WXK_RETURN:
2781 case WXK_EXECUTE:
cf1dfa6b
VZ
2782 {
2783 wxListEvent le( wxEVT_COMMAND_LIST_ITEM_ACTIVATED,
2784 GetParent()->GetId() );
2785 le.SetEventObject( GetParent() );
2786 le.m_itemIndex = m_current;
2787 GetLine(m_current)->GetItem( 0, le.m_item );
2788 GetParent()->GetEventHandler()->ProcessEvent( le );
2789 }
51cc4dad 2790 break;
cf1dfa6b 2791
51cc4dad 2792 default:
51cc4dad 2793 event.Skip();
e1e955e1 2794 }
e1e955e1 2795}
c801d85f 2796
cf1dfa6b
VZ
2797// ----------------------------------------------------------------------------
2798// focus handling
2799// ----------------------------------------------------------------------------
2800
cae5359f
RR
2801#ifdef __WXGTK__
2802extern wxWindow *g_focusWindow;
2803#endif
2804
c801d85f
KB
2805void wxListMainWindow::OnSetFocus( wxFocusEvent &WXUNUSED(event) )
2806{
63852e78 2807 m_hasFocus = TRUE;
bd8289c1 2808
cf1dfa6b
VZ
2809 if ( HasCurrent() )
2810 RefreshLine( m_current );
2811
2812 if (!GetParent())
2813 return;
004fd0c8 2814
cae5359f
RR
2815#ifdef __WXGTK__
2816 g_focusWindow = GetParent();
2817#endif
bd8289c1 2818
63852e78
RR
2819 wxFocusEvent event( wxEVT_SET_FOCUS, GetParent()->GetId() );
2820 event.SetEventObject( GetParent() );
2821 GetParent()->GetEventHandler()->ProcessEvent( event );
e1e955e1 2822}
c801d85f
KB
2823
2824void wxListMainWindow::OnKillFocus( wxFocusEvent &WXUNUSED(event) )
2825{
63852e78 2826 m_hasFocus = FALSE;
004fd0c8 2827
cf1dfa6b
VZ
2828 if ( HasCurrent() )
2829 RefreshLine( m_current );
e1e955e1 2830}
c801d85f 2831
1e6d9499 2832void wxListMainWindow::DrawImage( int index, wxDC *dc, int x, int y )
c801d85f 2833{
cf1dfa6b 2834 if ( HasFlag(wxLC_ICON) && (m_normal_image_list))
63852e78
RR
2835 {
2836 m_normal_image_list->Draw( index, *dc, x, y, wxIMAGELIST_DRAW_TRANSPARENT );
63852e78 2837 }
cf1dfa6b 2838 else if ( HasFlag(wxLC_SMALL_ICON) && (m_small_image_list))
63852e78
RR
2839 {
2840 m_small_image_list->Draw( index, *dc, x, y, wxIMAGELIST_DRAW_TRANSPARENT );
2841 }
cf1dfa6b 2842 else if ( HasFlag(wxLC_LIST) && (m_small_image_list))
0b855868
RR
2843 {
2844 m_small_image_list->Draw( index, *dc, x, y, wxIMAGELIST_DRAW_TRANSPARENT );
2845 }
cf1dfa6b 2846 else if ( HasFlag(wxLC_REPORT) && (m_small_image_list))
63852e78
RR
2847 {
2848 m_small_image_list->Draw( index, *dc, x, y, wxIMAGELIST_DRAW_TRANSPARENT );
63852e78 2849 }
e1e955e1 2850}
c801d85f
KB
2851
2852void wxListMainWindow::GetImageSize( int index, int &width, int &height )
2853{
cf1dfa6b 2854 if ( HasFlag(wxLC_ICON) && m_normal_image_list )
63852e78
RR
2855 {
2856 m_normal_image_list->GetSize( index, width, height );
63852e78 2857 }
cf1dfa6b 2858 else if ( HasFlag(wxLC_SMALL_ICON) && m_small_image_list )
63852e78
RR
2859 {
2860 m_small_image_list->GetSize( index, width, height );
63852e78 2861 }
cf1dfa6b 2862 else if ( HasFlag(wxLC_LIST) && m_small_image_list )
0b855868
RR
2863 {
2864 m_small_image_list->GetSize( index, width, height );
0b855868 2865 }
cf1dfa6b 2866 else if ( HasFlag(wxLC_REPORT) && m_small_image_list )
63852e78
RR
2867 {
2868 m_small_image_list->GetSize( index, width, height );
63852e78 2869 }
cf1dfa6b
VZ
2870 else
2871 {
2872 width =
2873 height = 0;
2874 }
e1e955e1 2875}
c801d85f 2876
cf1dfa6b 2877int wxListMainWindow::GetTextLength( const wxString &s )
c801d85f 2878{
1e6d9499 2879 wxClientDC dc( this );
cf1dfa6b 2880 dc.SetFont( GetFont() );
c801d85f 2881
cf1dfa6b
VZ
2882 wxCoord lw;
2883 dc.GetTextExtent( s, &lw, NULL );
2884
2885 return lw + AUTOSIZE_COL_MARGIN;
e1e955e1 2886}
c801d85f 2887
debe6624 2888void wxListMainWindow::SetImageList( wxImageList *imageList, int which )
c801d85f 2889{
139adb6a 2890 m_dirty = TRUE;
f6bcfd97
BP
2891
2892 // calc the spacing from the icon size
2893 int width = 0,
2894 height = 0;
2895 if ((imageList) && (imageList->GetImageCount()) )
2896 {
2897 imageList->GetSize(0, width, height);
2898 }
2899
2900 if (which == wxIMAGE_LIST_NORMAL)
2901 {
2902 m_normal_image_list = imageList;
2903 m_normal_spacing = width + 8;
2904 }
2905
2906 if (which == wxIMAGE_LIST_SMALL)
2907 {
2908 m_small_image_list = imageList;
2909 m_small_spacing = width + 14;
2910 }
e1e955e1 2911}
c801d85f 2912
debe6624 2913void wxListMainWindow::SetItemSpacing( int spacing, bool isSmall )
c801d85f 2914{
139adb6a
RR
2915 m_dirty = TRUE;
2916 if (isSmall)
2917 {
2918 m_small_spacing = spacing;
2919 }
2920 else
2921 {
2922 m_normal_spacing = spacing;
2923 }
e1e955e1 2924}
c801d85f 2925
debe6624 2926int wxListMainWindow::GetItemSpacing( bool isSmall )
c801d85f 2927{
f6bcfd97 2928 return isSmall ? m_small_spacing : m_normal_spacing;
e1e955e1 2929}
c801d85f 2930
cf1dfa6b
VZ
2931// ----------------------------------------------------------------------------
2932// columns
2933// ----------------------------------------------------------------------------
2934
debe6624 2935void wxListMainWindow::SetColumn( int col, wxListItem &item )
c801d85f 2936{
24b9f055 2937 wxListHeaderDataList::Node *node = m_columns.Item( col );
f6bcfd97 2938
cf1dfa6b
VZ
2939 wxCHECK_RET( node, _T("invalid column index in SetColumn") );
2940
2941 if ( item.m_width == wxLIST_AUTOSIZE_USEHEADER )
2942 item.m_width = GetTextLength( item.m_text );
2943
2944 wxListHeaderData *column = node->GetData();
2945 column->SetItem( item );
2946
2947 wxListHeaderWindow *headerWin = GetListCtrl()->m_headerWin;
f6bcfd97
BP
2948 if ( headerWin )
2949 headerWin->m_dirty = TRUE;
cf1dfa6b
VZ
2950
2951 m_dirty = TRUE;
2952
2953 // invalidate it as it has to be recalculated
2954 m_headerWidth = 0;
e1e955e1 2955}
c801d85f 2956
debe6624 2957void wxListMainWindow::SetColumnWidth( int col, int width )
c801d85f 2958{
cf1dfa6b
VZ
2959 wxCHECK_RET( col >= 0 && col < GetColumnCount(),
2960 _T("invalid column index") );
2961
2962 wxCHECK_RET( HasFlag(wxLC_REPORT),
f6bcfd97 2963 _T("SetColumnWidth() can only be called in report mode.") );
0208334d 2964
63852e78 2965 m_dirty = TRUE;
bd8289c1 2966
cf1dfa6b
VZ
2967 wxListHeaderDataList::Node *node = m_columns.Item( col );
2968 wxCHECK_RET( node, _T("no column?") );
2969
2970 wxListHeaderData *column = node->GetData();
2971
2972 size_t count = GetItemCount();
2973
f6bcfd97
BP
2974 if (width == wxLIST_AUTOSIZE_USEHEADER)
2975 {
cf1dfa6b 2976 width = GetTextLength(column->GetText());
f6bcfd97 2977 }
cf1dfa6b 2978 else if ( width == wxLIST_AUTOSIZE )
0180dad6 2979 {
cf1dfa6b
VZ
2980 if ( IsVirtual() )
2981 {
2982 // TODO: determine the max width somehow...
2983 width = WIDTH_COL_DEFAULT;
2984 }
2985 else // !virtual
0180dad6 2986 {
cf1dfa6b
VZ
2987 wxClientDC dc(this);
2988 dc.SetFont( GetFont() );
2989
2990 int max = AUTOSIZE_COL_MARGIN;
2991
2992 for ( size_t i = 0; i < count; i++ )
0180dad6 2993 {
cf1dfa6b
VZ
2994 wxListLineData *line = GetLine(i);
2995 wxListItemDataList::Node *n = line->m_items.Item( col );
2996
2997 wxCHECK_RET( n, _T("no subitem?") );
2998
2c1f73ee 2999 wxListItemData *item = n->GetData();
cf1dfa6b
VZ
3000 int current = 0;
3001
bffa1c77
VZ
3002 if (item->HasImage())
3003 {
cf1dfa6b 3004 int ix, iy;
0180dad6 3005 GetImageSize( item->GetImage(), ix, iy );
cf1dfa6b 3006 current += ix + 5;
bffa1c77 3007 }
cf1dfa6b 3008
bffa1c77
VZ
3009 if (item->HasText())
3010 {
cf1dfa6b
VZ
3011 wxCoord w;
3012 dc.GetTextExtent( item->GetText(), &w, NULL );
3013 current += w;
bffa1c77 3014 }
cf1dfa6b 3015
2c1f73ee
VZ
3016 if (current > max)
3017 max = current;
0180dad6 3018 }
cf1dfa6b
VZ
3019
3020 width = max + AUTOSIZE_COL_MARGIN;
0180dad6 3021 }
0180dad6
RR
3022 }
3023
cf1dfa6b 3024 column->SetWidth( width );
bd8289c1 3025
cf1dfa6b
VZ
3026 // invalidate it as it has to be recalculated
3027 m_headerWidth = 0;
3028}
3029
3030int wxListMainWindow::GetHeaderWidth() const
3031{
3032 if ( !m_headerWidth )
0208334d 3033 {
cf1dfa6b
VZ
3034 wxListMainWindow *self = wxConstCast(this, wxListMainWindow);
3035
3036 size_t count = GetColumnCount();
3037 for ( size_t col = 0; col < count; col++ )
63852e78 3038 {
cf1dfa6b 3039 self->m_headerWidth += GetColumnWidth(col);
63852e78 3040 }
0208334d 3041 }
bd8289c1 3042
cf1dfa6b 3043 return m_headerWidth;
e1e955e1 3044}
c801d85f 3045
cf1dfa6b 3046void wxListMainWindow::GetColumn( int col, wxListItem &item ) const
c801d85f 3047{
24b9f055 3048 wxListHeaderDataList::Node *node = m_columns.Item( col );
cf1dfa6b
VZ
3049 wxCHECK_RET( node, _T("invalid column index in GetColumn") );
3050
3051 wxListHeaderData *column = node->GetData();
3052 column->GetItem( item );
e1e955e1 3053}
c801d85f 3054
cf1dfa6b 3055int wxListMainWindow::GetColumnWidth( int col ) const
c801d85f 3056{
24b9f055
VZ
3057 wxListHeaderDataList::Node *node = m_columns.Item( col );
3058 wxCHECK_MSG( node, 0, _T("invalid column index") );
3059
3060 wxListHeaderData *column = node->GetData();
3061 return column->GetWidth();
e1e955e1 3062}
c801d85f 3063
cf1dfa6b
VZ
3064// ----------------------------------------------------------------------------
3065// item state
3066// ----------------------------------------------------------------------------
c801d85f
KB
3067
3068void wxListMainWindow::SetItem( wxListItem &item )
3069{
cf1dfa6b
VZ
3070 long id = item.m_itemId;
3071 wxCHECK_RET( id >= 0 && (size_t)id < GetItemCount(),
3072 _T("invalid item index in SetItem") );
3073
3074 if ( IsVirtual() )
3075 {
3076 // just refresh the line to show the new value of the text/image
3077 RefreshLine((size_t)id);
3078 }
3079 else // !virtual
92976ab6 3080 {
cf1dfa6b
VZ
3081 m_dirty = TRUE;
3082
3083 wxListLineData *line = GetLine((size_t)id);
3084 if ( HasFlag(wxLC_REPORT) )
3085 item.m_width = GetColumnWidth( item.m_col );
92976ab6
RR
3086 line->SetItem( item.m_col, item );
3087 }
e1e955e1 3088}
c801d85f 3089
cf1dfa6b 3090void wxListMainWindow::SetItemState( long litem, long state, long stateMask )
c801d85f 3091{
cf1dfa6b 3092 wxCHECK_RET( litem >= 0 && (size_t)litem < GetItemCount(),
54442116
VZ
3093 _T("invalid list ctrl item index in SetItem") );
3094
cf1dfa6b
VZ
3095 size_t oldCurrent = m_current;
3096 size_t item = (size_t)litem; // sdafe because of the check above
bd8289c1 3097
54442116 3098 if ( stateMask & wxLIST_STATE_FOCUSED )
c801d85f 3099 {
54442116 3100 if ( state & wxLIST_STATE_FOCUSED )
92976ab6 3101 {
54442116 3102 // don't do anything if this item is already focused
cf1dfa6b 3103 if ( item != m_current )
92976ab6 3104 {
cf1dfa6b
VZ
3105 OnUnfocusLine( m_current );
3106 m_current = item;
3107 OnFocusLine( m_current );
3108
3109 if ( HasFlag(wxLC_SINGLE_SEL) && (oldCurrent != (size_t)-1) )
3110 {
3111 HilightLine(oldCurrent, FALSE);
3112 RefreshLine(oldCurrent);
3113 }
54442116 3114
92976ab6 3115 RefreshLine( m_current );
92976ab6 3116 }
54442116
VZ
3117 }
3118 else // unfocus
3119 {
3120 // don't do anything if this item is not focused
cf1dfa6b 3121 if ( item == m_current )
bffa1c77 3122 {
cf1dfa6b
VZ
3123 OnUnfocusLine( m_current );
3124 m_current = (size_t)-1;
bffa1c77 3125 }
92976ab6 3126 }
e1e955e1 3127 }
54442116
VZ
3128
3129 if ( stateMask & wxLIST_STATE_SELECTED )
3130 {
3131 bool on = (state & wxLIST_STATE_SELECTED) != 0;
54442116 3132
cf1dfa6b 3133 if ( HasFlag(wxLC_SINGLE_SEL) )
54442116 3134 {
cf1dfa6b
VZ
3135 if ( on )
3136 {
3137 // selecting the item also makes it the focused one in the
3138 // single sel mode
3139 if ( m_current != item )
3140 {
3141 OnUnfocusLine( m_current );
3142 m_current = item;
3143 OnFocusLine( m_current );
3144
3145 if ( oldCurrent != (size_t)-1 )
3146 {
3147 HilightLine( oldCurrent, FALSE );
3148 RefreshLine( oldCurrent );
3149 }
3150 }
3151 }
3152 else // off
3153 {
3154 // only the current item may be selected anyhow
3155 if ( item != m_current )
3156 return;
3157 }
54442116
VZ
3158 }
3159
cf1dfa6b 3160 if ( HilightLine(item, on) )
54442116 3161 {
cf1dfa6b 3162 RefreshLine(item);
54442116
VZ
3163 }
3164 }
e1e955e1 3165}
c801d85f 3166
debe6624 3167int wxListMainWindow::GetItemState( long item, long stateMask )
c801d85f 3168{
cf1dfa6b
VZ
3169 wxCHECK_MSG( item >= 0 && (size_t)item < GetItemCount(), 0,
3170 _T("invalid list ctrl item index in GetItemState()") );
3171
92976ab6 3172 int ret = wxLIST_STATE_DONTCARE;
cf1dfa6b
VZ
3173
3174 if ( stateMask & wxLIST_STATE_FOCUSED )
c801d85f 3175 {
cf1dfa6b
VZ
3176 if ( (size_t)item == m_current )
3177 ret |= wxLIST_STATE_FOCUSED;
e1e955e1 3178 }
cf1dfa6b
VZ
3179
3180 if ( stateMask & wxLIST_STATE_SELECTED )
c801d85f 3181 {
cf1dfa6b
VZ
3182 if ( IsHilighted(item) )
3183 ret |= wxLIST_STATE_SELECTED;
e1e955e1 3184 }
cf1dfa6b 3185
92976ab6 3186 return ret;
e1e955e1 3187}
c801d85f
KB
3188
3189void wxListMainWindow::GetItem( wxListItem &item )
3190{
cf1dfa6b
VZ
3191 wxCHECK_RET( item.m_itemId >= 0 && (size_t)item.m_itemId < GetItemCount(),
3192 _T("invalid item index in GetItem") );
3193
3194 wxListLineData *line = GetLine((size_t)item.m_itemId);
3195 line->GetItem( item.m_col, item );
e1e955e1 3196}
c801d85f 3197
cf1dfa6b
VZ
3198// ----------------------------------------------------------------------------
3199// item count
3200// ----------------------------------------------------------------------------
3201
3202size_t wxListMainWindow::GetItemCount() const
1370703e
VZ
3203{
3204 return IsVirtual() ? m_countVirt : m_lines.GetCount();
3205}
3206
3207void wxListMainWindow::SetItemCount(long count)
c801d85f 3208{
1370703e
VZ
3209 m_countVirt = count;
3210
3211 Refresh();
e1e955e1 3212}
c801d85f 3213
cf1dfa6b 3214int wxListMainWindow::GetSelectedItemCount()
c801d85f 3215{
cf1dfa6b
VZ
3216 // deal with the quick case first
3217 if ( HasFlag(wxLC_SINGLE_SEL) )
92976ab6 3218 {
cf1dfa6b 3219 return m_current == (size_t)-1 ? FALSE : IsHilighted(m_current);
92976ab6 3220 }
cf1dfa6b
VZ
3221
3222 // virtual controls remmebers all its selections itself
3223 if ( IsVirtual() )
3224 return m_selections.GetCount();
3225
3226 // TODO: we probably should maintain the number of items selected even for
3227 // non virtual controls as enumerating all lines is really slow...
3228 size_t countSel = 0;
3229 size_t count = GetItemCount();
3230 for ( size_t line = 0; line < count; line++ )
92976ab6 3231 {
cf1dfa6b
VZ
3232 if ( GetLine(line)->IsHilighted() )
3233 countSel++;
92976ab6 3234 }
c801d85f 3235
cf1dfa6b 3236 return countSel;
e1e955e1 3237}
e3e65dac 3238
cf1dfa6b
VZ
3239// ----------------------------------------------------------------------------
3240// item position/size
3241// ----------------------------------------------------------------------------
3242
3243void wxListMainWindow::GetItemRect( long index, wxRect &rect )
c801d85f 3244{
cf1dfa6b
VZ
3245 wxCHECK_RET( index >= 0 && (size_t)index < GetItemCount(),
3246 _T("invalid index in GetItemRect") );
3247
3248 rect = GetLine((size_t)index)->GetRect();
3249 CalcScrolledPosition(rect.x, rect.y, &rect.x, &rect.y);
e1e955e1 3250}
c801d85f 3251
cf1dfa6b 3252bool wxListMainWindow::GetItemPosition(long item, wxPoint& pos)
c801d85f 3253{
cf1dfa6b
VZ
3254 wxRect rect;
3255 GetItemRect(item, rect);
bd8289c1 3256
cf1dfa6b
VZ
3257 pos.x = rect.x;
3258 pos.y = rect.y;
bd8289c1 3259
cf1dfa6b 3260 return TRUE;
e1e955e1 3261}
c801d85f 3262
cf1dfa6b
VZ
3263// ----------------------------------------------------------------------------
3264// geometry calculation
3265// ----------------------------------------------------------------------------
3266
3267void wxListMainWindow::OnSize( wxSizeEvent &WXUNUSED(event) )
c801d85f 3268{
cf1dfa6b
VZ
3269 // wait for the next OnIdle() with geometry recalculation
3270 m_dirty = TRUE;
e1e955e1 3271}
c801d85f 3272
e179bd65 3273void wxListMainWindow::CalculatePositions()
c801d85f 3274{
1370703e
VZ
3275 if ( IsEmpty() )
3276 return;
e487524e 3277
1e6d9499 3278 wxClientDC dc( this );
92976ab6 3279 dc.SetFont( GetFont() );
c801d85f 3280
cf1dfa6b
VZ
3281 int iconSpacing;
3282 if ( HasFlag(wxLC_ICON) )
3283 iconSpacing = m_normal_spacing;
3284 else if ( HasFlag(wxLC_SMALL_ICON) )
3285 iconSpacing = m_small_spacing;
3286 else
3287 iconSpacing = 0;
004fd0c8 3288
cf1dfa6b
VZ
3289 int clientWidth,
3290 clientHeight;
3291 GetClientSize( &clientWidth, &clientHeight );
004fd0c8 3292
cf1dfa6b
VZ
3293 if ( HasFlag(wxLC_REPORT) )
3294 {
3295 // all lines have the same height
3296 int lineSpacing = GetLineHeight();
c801d85f 3297
cf1dfa6b
VZ
3298 // scroll one line per step
3299 m_yScroll = lineSpacing;
bd8289c1 3300
cf1dfa6b
VZ
3301 size_t lineCount = GetItemCount();
3302 int entireHeight = lineCount*lineSpacing + 2*LINE_SPACING;
bd8289c1 3303
cf1dfa6b 3304 m_linesPerPage = clientHeight / lineSpacing;
2c1f73ee 3305
cf1dfa6b
VZ
3306 SetScrollbars( m_xScroll, m_yScroll,
3307 (GetHeaderWidth() + m_xScroll - 1)/m_xScroll,
3308 (entireHeight + m_yScroll - 1)/m_yScroll,
3309 GetScrollPos(wxHORIZONTAL),
3310 GetScrollPos(wxVERTICAL),
3311 TRUE );
92976ab6 3312
cf1dfa6b 3313 UpdateShownLinesRange();
e1e955e1 3314 }
cf1dfa6b 3315 else // !report
92976ab6
RR
3316 {
3317 // at first we try without any scrollbar. if the items don't
3318 // fit into the window, we recalculate after subtracting an
3319 // approximated 15 pt for the horizontal scrollbar
004fd0c8 3320
bffa1c77 3321 clientHeight -= 4; // sunken frame
bd8289c1 3322
cf1dfa6b 3323 int entireWidth;
bd8289c1 3324
92976ab6 3325 for (int tries = 0; tries < 2; tries++)
e487524e 3326 {
92976ab6 3327 entireWidth = 0;
5d25c050
RR
3328 int x = 2;
3329 int y = 2;
92976ab6 3330 int maxWidth = 0;
cf1dfa6b
VZ
3331 m_linesPerPage = 0;
3332 int currentlyVisibleLines = 0;
3333
3334 size_t count = GetItemCount();
3335 for (size_t i = 0; i < count; i++)
92976ab6 3336 {
cf1dfa6b
VZ
3337 currentlyVisibleLines++;
3338 wxListLineData *line = GetLine(i);
92976ab6 3339 line->CalculateSize( &dc, iconSpacing );
cf1dfa6b
VZ
3340 line->SetPosition( x, y, clientWidth, iconSpacing );
3341
3342 wxSize sizeLine = line->GetSize();
3343
3344 if ( maxWidth < sizeLine.x )
3345 maxWidth = sizeLine.x;
3346
3347 y += sizeLine.y;
3348 if (currentlyVisibleLines > m_linesPerPage)
3349 m_linesPerPage = currentlyVisibleLines;
3350
3351 // assume that the size of the next one is the same... (FIXME)
3352 if ( y + sizeLine.y - 6 >= clientHeight )
92976ab6 3353 {
cf1dfa6b 3354 currentlyVisibleLines = 0;
e1208c31 3355 y = 2;
8b53e5a2
RR
3356 x += maxWidth+6;
3357 entireWidth += maxWidth+6;
92976ab6
RR
3358 maxWidth = 0;
3359 }
cf1dfa6b
VZ
3360 if ( i == count - 1 )
3361 entireWidth += maxWidth;
92976ab6
RR
3362 if ((tries == 0) && (entireWidth > clientWidth))
3363 {
3364 clientHeight -= 15; // scrollbar height
cf1dfa6b
VZ
3365 m_linesPerPage = 0;
3366 currentlyVisibleLines = 0;
92976ab6
RR
3367 break;
3368 }
cf1dfa6b
VZ
3369 if ( i == count - 1 )
3370 tries = 1; // everything fits, no second try required
92976ab6 3371 }
e487524e 3372 }
bffa1c77 3373
92976ab6 3374 int scroll_pos = GetScrollPos( wxHORIZONTAL );
cf1dfa6b 3375 SetScrollbars( m_xScroll, m_yScroll, (entireWidth+SCROLL_UNIT_X) / m_xScroll, 0, scroll_pos, 0, TRUE );
e1e955e1 3376 }
cf1dfa6b
VZ
3377
3378 // FIXME: why should we call it from here?
3379 UpdateCurrent();
e1e955e1 3380}
c801d85f 3381
cf1dfa6b 3382void wxListMainWindow::UpdateCurrent()
c801d85f 3383{
cf1dfa6b 3384 if ( (m_current == (size_t)-1) && !IsEmpty() )
92976ab6 3385 {
cf1dfa6b 3386 m_current = 0;
92976ab6 3387 }
cf1dfa6b
VZ
3388
3389 if ( m_current != (size_t)-1 )
92976ab6 3390 {
cf1dfa6b 3391 OnFocusLine( m_current );
92976ab6 3392 }
e1e955e1 3393}
c801d85f 3394
19695fbd
VZ
3395long wxListMainWindow::GetNextItem( long item,
3396 int WXUNUSED(geometry),
3397 int state )
c801d85f 3398{
d1022fd6
VZ
3399 long ret = item,
3400 max = GetItemCount();
3401 wxCHECK_MSG( (ret == -1) || (ret < max), -1,
13771c08 3402 _T("invalid listctrl index in GetNextItem()") );
19695fbd
VZ
3403
3404 // notice that we start with the next item (or the first one if item == -1)
3405 // and this is intentional to allow writing a simple loop to iterate over
3406 // all selected items
d1022fd6
VZ
3407 ret++;
3408 if ( ret == max )
3409 {
3410 // this is not an error because the index was ok initially, just no
3411 // such item
3412 return -1;
3413 }
3414
cf1dfa6b
VZ
3415 if ( !state )
3416 {
3417 // any will do
3418 return (size_t)ret;
3419 }
3420
3421 size_t count = GetItemCount();
3422 for ( size_t line = (size_t)ret; line < count; line++ )
63852e78 3423 {
cf1dfa6b
VZ
3424 if ( (state & wxLIST_STATE_FOCUSED) && (line == m_current) )
3425 return line;
3426
3427 if ( (state & wxLIST_STATE_SELECTED) && IsHilighted(line) )
3428 return line;
63852e78 3429 }
19695fbd 3430
63852e78 3431 return -1;
e1e955e1 3432}
c801d85f 3433
cf1dfa6b
VZ
3434// ----------------------------------------------------------------------------
3435// deleting stuff
3436// ----------------------------------------------------------------------------
3437
debe6624 3438void wxListMainWindow::DeleteItem( long index )
c801d85f 3439{
cf1dfa6b
VZ
3440 size_t count = GetItemCount();
3441
3442 wxCHECK_RET( (index >= 0) && ((size_t)index < count),
3443 _T("invalid item index in DeleteItem") );
3444
63852e78 3445 m_dirty = TRUE;
cf1dfa6b
VZ
3446
3447 // select the next item when the selected one is deleted
3448 if ( m_current == (size_t)index )
3449 {
3450 // the last valid index after deleting the item will be count-2
3451 if ( ++m_current >= count - 2 )
3452 {
3453 m_current = count - 2;
3454 }
3455 }
3456
3457 SendNotify( (size_t)index, wxEVT_COMMAND_LIST_DELETE_ITEM );
3458
3459 if ( !IsVirtual() )
63852e78 3460 {
f6bcfd97 3461 m_lines.RemoveAt( (size_t)index );
63852e78 3462 }
e1e955e1 3463}
c801d85f 3464
debe6624 3465void wxListMainWindow::DeleteColumn( int col )
c801d85f 3466{
24b9f055
VZ
3467 wxListHeaderDataList::Node *node = m_columns.Item( col );
3468
3469 wxCHECK_RET( node, wxT("invalid column index in DeleteColumn()") );
bd8289c1 3470
5b077d48 3471 m_dirty = TRUE;
24b9f055 3472 m_columns.DeleteNode( node );
e1e955e1 3473}
c801d85f 3474
12c1b46a 3475void wxListMainWindow::DeleteAllItems()
c801d85f 3476{
cf1dfa6b
VZ
3477 if ( IsEmpty() )
3478 {
3479 // nothing to do - in particular, don't send the event
3480 return;
3481 }
3482
5b077d48 3483 m_dirty = TRUE;
cf1dfa6b 3484 m_current = (size_t)-1;
7c0ea335
VZ
3485
3486 // to make the deletion of all items faster, we don't send the
cf1dfa6b
VZ
3487 // notifications for each item deletion in this case but only one event
3488 // for all of them: this is compatible with wxMSW and documented in
3489 // DeleteAllItems() description
bffa1c77 3490
12c1b46a
RR
3491 wxListEvent event( wxEVT_COMMAND_LIST_DELETE_ALL_ITEMS, GetParent()->GetId() );
3492 event.SetEventObject( GetParent() );
3493 GetParent()->GetEventHandler()->ProcessEvent( event );
7c0ea335 3494
5b077d48 3495 m_lines.Clear();
cf1dfa6b
VZ
3496
3497 m_selections.Clear();
e1e955e1 3498}
c801d85f 3499
12c1b46a 3500void wxListMainWindow::DeleteEverything()
c801d85f 3501{
12c1b46a 3502 DeleteAllItems();
f6bcfd97 3503
5b077d48 3504 m_columns.Clear();
e1e955e1 3505}
c801d85f 3506
cf1dfa6b
VZ
3507// ----------------------------------------------------------------------------
3508// scanning for an item
3509// ----------------------------------------------------------------------------
3510
debe6624 3511void wxListMainWindow::EnsureVisible( long index )
c801d85f 3512{
cf1dfa6b
VZ
3513 wxCHECK_RET( index >= 0 && (size_t)index < GetItemCount(),
3514 _T("invalid index in EnsureVisible") );
3515
3516 // We have to call this here because the label in question might just have
3517 // been added and no screen update taken place.
3518 if (m_dirty)
3519 wxSafeYield();
dc6c62a9 3520
cf1dfa6b
VZ
3521 size_t oldCurrent = m_current;
3522 m_current = (size_t)index;
3523 MoveToFocus();
5b077d48 3524 m_current = oldCurrent;
e1e955e1 3525}
c801d85f 3526
debe6624 3527long wxListMainWindow::FindItem(long start, const wxString& str, bool WXUNUSED(partial) )
c801d85f 3528{
5b077d48
RR
3529 long pos = start;
3530 wxString tmp = str;
cf1dfa6b
VZ
3531 if (pos < 0)
3532 pos = 0;
54442116 3533
cf1dfa6b
VZ
3534 size_t count = GetItemCount();
3535 for ( size_t i = (size_t)pos; i < count; i++ )
3536 {
3537 wxListLineData *line = GetLine(i);
3538 if ( line->GetText(0) == tmp )
3539 return i;
5b077d48 3540 }
cf1dfa6b
VZ
3541
3542 return wxNOT_FOUND;
e1e955e1 3543}
c801d85f 3544
debe6624 3545long wxListMainWindow::FindItem(long start, long data)
c801d85f 3546{
5b077d48 3547 long pos = start;
cf1dfa6b
VZ
3548 if (pos < 0)
3549 pos = 0;
3550
3551 size_t count = GetItemCount();
3552 for (size_t i = (size_t)pos; i < count; i++)
5b077d48 3553 {
cf1dfa6b 3554 wxListLineData *line = GetLine(i);
5b077d48
RR
3555 wxListItem item;
3556 line->GetItem( 0, item );
cf1dfa6b
VZ
3557 if (item.m_data == data)
3558 return i;
5b077d48 3559 }
cf1dfa6b
VZ
3560
3561 return wxNOT_FOUND;
e1e955e1 3562}
c801d85f 3563
debe6624 3564long wxListMainWindow::HitTest( int x, int y, int &flags )
c801d85f 3565{
aaef15bf 3566 CalcUnscrolledPosition( x, y, &x, &y );
e8741cca 3567
cf1dfa6b
VZ
3568 size_t count = GetItemCount();
3569 for (size_t i = 0; i < count; i++)
c801d85f 3570 {
cf1dfa6b 3571 wxListLineData *line = GetLine(i);
aaef15bf 3572 long ret = line->IsHit( x, y );
cf1dfa6b 3573 if (ret)
5b077d48 3574 {
6f2a55e3 3575 flags = (int)ret;
cf1dfa6b 3576 return i;
5b077d48 3577 }
e1e955e1 3578 }
cf1dfa6b
VZ
3579
3580 return wxNOT_FOUND;
e1e955e1 3581}
c801d85f 3582
cf1dfa6b
VZ
3583// ----------------------------------------------------------------------------
3584// adding stuff
3585// ----------------------------------------------------------------------------
3586
c801d85f
KB
3587void wxListMainWindow::InsertItem( wxListItem &item )
3588{
cf1dfa6b
VZ
3589 wxASSERT_MSG( !IsVirtual(), _T("can't be used with virtual control") );
3590
3591 size_t count = GetItemCount();
3592 wxCHECK_RET( item.m_itemId >= 0 && (size_t)item.m_itemId <= count,
3593 _T("invalid item index") );
3594
3595 size_t id = item.m_itemId;
3596
5b077d48 3597 m_dirty = TRUE;
cf1dfa6b 3598
5b077d48 3599 int mode = 0;
cf1dfa6b 3600 if ( HasFlag(wxLC_REPORT) )
1370703e 3601 mode = wxLC_REPORT;
cf1dfa6b 3602 else if ( HasFlag(wxLC_LIST) )
1370703e 3603 mode = wxLC_LIST;
cf1dfa6b 3604 else if ( HasFlag(wxLC_ICON) )
1370703e 3605 mode = wxLC_ICON;
cf1dfa6b 3606 else if ( HasFlag(wxLC_SMALL_ICON) )
1370703e
VZ
3607 mode = wxLC_ICON; // no typo
3608 else
3609 {
3610 wxFAIL_MSG( _T("unknown mode") );
3611 }
004fd0c8 3612
cf1dfa6b 3613 wxListLineData *line = new wxListLineData( this, id );
004fd0c8 3614
5b077d48 3615 line->SetItem( 0, item );
cf1dfa6b
VZ
3616
3617 m_lines.Insert( line, id );
e1e955e1 3618}
c801d85f 3619
debe6624 3620void wxListMainWindow::InsertColumn( long col, wxListItem &item )
c801d85f 3621{
5b077d48 3622 m_dirty = TRUE;
cf1dfa6b 3623 if ( HasFlag(wxLC_REPORT) )
3db7be80 3624 {
54442116
VZ
3625 if (item.m_width == wxLIST_AUTOSIZE_USEHEADER)
3626 item.m_width = GetTextLength( item.m_text );
5b077d48
RR
3627 wxListHeaderData *column = new wxListHeaderData( item );
3628 if ((col >= 0) && (col < (int)m_columns.GetCount()))
3629 {
24b9f055
VZ
3630 wxListHeaderDataList::Node *node = m_columns.Item( col );
3631 m_columns.Insert( node, column );
5b077d48
RR
3632 }
3633 else
3634 {
3635 m_columns.Append( column );
3636 }
3db7be80 3637 }
e1e955e1 3638}
c801d85f 3639
cf1dfa6b
VZ
3640// ----------------------------------------------------------------------------
3641// sorting
3642// ----------------------------------------------------------------------------
3643
c801d85f
KB
3644wxListCtrlCompare list_ctrl_compare_func_2;
3645long list_ctrl_compare_data;
3646
f6bcfd97 3647int LINKAGEMODE list_ctrl_compare_func_1( wxListLineData **arg1, wxListLineData **arg2 )
c801d85f 3648{
f6bcfd97
BP
3649 wxListLineData *line1 = *arg1;
3650 wxListLineData *line2 = *arg2;
5b077d48
RR
3651 wxListItem item;
3652 line1->GetItem( 0, item );
3653 long data1 = item.m_data;
3654 line2->GetItem( 0, item );
3655 long data2 = item.m_data;
3656 return list_ctrl_compare_func_2( data1, data2, list_ctrl_compare_data );
e1e955e1 3657}
c801d85f
KB
3658
3659void wxListMainWindow::SortItems( wxListCtrlCompare fn, long data )
3660{
5b077d48
RR
3661 list_ctrl_compare_func_2 = fn;
3662 list_ctrl_compare_data = data;
3663 m_lines.Sort( list_ctrl_compare_func_1 );
af7c1052 3664 m_dirty = TRUE;
e1e955e1 3665}
c801d85f 3666
cf1dfa6b
VZ
3667// ----------------------------------------------------------------------------
3668// scrolling
3669// ----------------------------------------------------------------------------
3670
7c74e7fe
SC
3671void wxListMainWindow::OnScroll(wxScrollWinEvent& event)
3672{
cf1dfa6b
VZ
3673 // update our idea of which lines are shown before scrolling the window
3674 UpdateShownLinesRange();
3675
29149a64 3676 // FIXME
3a8c693a 3677#if defined(__WXGTK__) && !defined(__WXUNIVERSAL__)
29149a64
VZ
3678 wxScrolledWindow::OnScroll(event);
3679#else
1e6feb95 3680 HandleOnScroll( event );
29149a64 3681#endif
30954328 3682
cf1dfa6b 3683 if ( event.GetOrientation() == wxHORIZONTAL && HasHeader() )
7c74e7fe 3684 {
cf1dfa6b
VZ
3685 wxListCtrl* lc = GetListCtrl();
3686 wxCHECK_RET( lc, _T("no listctrl window?") );
3687
3688 lc->m_headerWin->Refresh() ;
7c74e7fe 3689#ifdef __WXMAC__
cf1dfa6b 3690 lc->m_headerWin->MacUpdateImmediately() ;
7c74e7fe 3691#endif
7c74e7fe 3692 }
cf1dfa6b
VZ
3693}
3694
3695void wxListMainWindow::UpdateShownLinesRange()
3696{
3697 // only optimize redrawing for the report view using m_lineFrom/To
3698 if ( !HasFlag(wxLC_REPORT) )
3699 return;
3700
3701 size_t lineFromOld = m_lineFrom,
3702 lineToOld = m_lineTo;
3703
3704 m_lineFrom = GetScrollPos(wxVERTICAL);
3705
3706 size_t count = GetItemCount();
3707
3708 wxASSERT_MSG( m_lineFrom < count, _T("invalid scroll position?") );
3709
3710 m_lineTo = m_lineFrom + m_linesPerPage - 1;
3711 if ( m_lineTo >= count )
3712 m_lineTo = count - 1;
3713
3714 if ( m_lineFrom != lineFromOld || m_lineTo != lineToOld )
3715 {
3716 m_dirty = TRUE;
3717 }
7c74e7fe
SC
3718}
3719
c801d85f
KB
3720// -------------------------------------------------------------------------------------
3721// wxListItem
3722// -------------------------------------------------------------------------------------
3723
3724IMPLEMENT_DYNAMIC_CLASS(wxListItem, wxObject)
3725
fd9811b1 3726wxListItem::wxListItem()
c801d85f 3727{
63852e78
RR
3728 m_mask = 0;
3729 m_itemId = 0;
3730 m_col = 0;
3731 m_state = 0;
3732 m_stateMask = 0;
3733 m_image = 0;
3734 m_data = 0;
3735 m_format = wxLIST_FORMAT_CENTRE;
3736 m_width = 0;
aaa37c0d
VZ
3737
3738 m_attr = NULL;
c801d85f
KB
3739}
3740
9b00bb16
RR
3741void wxListItem::Clear()
3742{
3743 m_mask = 0;
3744 m_itemId = 0;
3745 m_col = 0;
3746 m_state = 0;
3747 m_stateMask = 0;
3748 m_image = 0;
3749 m_data = 0;
3750 m_format = wxLIST_FORMAT_CENTRE;
3751 m_width = 0;
54442116 3752 m_text = _T("");
9b00bb16 3753
cf1dfa6b 3754 ClearAttributes();
9b00bb16
RR
3755}
3756
3757void wxListItem::ClearAttributes()
3758{
cf1dfa6b
VZ
3759 if (m_attr)
3760 {
3761 delete m_attr;
3762 m_attr = NULL;
3763 }
9b00bb16
RR
3764}
3765
c801d85f
KB
3766// -------------------------------------------------------------------------------------
3767// wxListEvent
3768// -------------------------------------------------------------------------------------
3769
92976ab6 3770IMPLEMENT_DYNAMIC_CLASS(wxListEvent, wxNotifyEvent)
c801d85f 3771
cf1dfa6b
VZ
3772wxListEvent::wxListEvent( wxEventType commandType, int id )
3773 : wxNotifyEvent( commandType, id )
c801d85f 3774{
5b077d48
RR
3775 m_code = 0;
3776 m_itemIndex = 0;
3777 m_oldItemIndex = 0;
3778 m_col = 0;
3779 m_cancelled = FALSE;
3780 m_pointDrag.x = 0;
3781 m_pointDrag.y = 0;
e1e955e1 3782}
c801d85f 3783
72a7edf0
RR
3784void wxListEvent::CopyObject(wxObject& object_dest) const
3785{
3786 wxListEvent *obj = (wxListEvent *)&object_dest;
3787
3788 wxNotifyEvent::CopyObject(object_dest);
3789
3790 obj->m_code = m_code;
3791 obj->m_itemIndex = m_itemIndex;
3792 obj->m_oldItemIndex = m_oldItemIndex;
3793 obj->m_col = m_col;
3794 obj->m_cancelled = m_cancelled;
3795 obj->m_pointDrag = m_pointDrag;
3796 obj->m_item.m_mask = m_item.m_mask;
3797 obj->m_item.m_itemId = m_item.m_itemId;
3798 obj->m_item.m_col = m_item.m_col;
3799 obj->m_item.m_state = m_item.m_state;
3800 obj->m_item.m_stateMask = m_item.m_stateMask;
3801 obj->m_item.m_text = m_item.m_text;
3802 obj->m_item.m_image = m_item.m_image;
3803 obj->m_item.m_data = m_item.m_data;
3804 obj->m_item.m_format = m_item.m_format;
3805 obj->m_item.m_width = m_item.m_width;
aaa37c0d
VZ
3806
3807 if ( m_item.HasAttributes() )
3808 {
3809 obj->m_item.SetTextColour(m_item.GetTextColour());
3810 }
72a7edf0
RR
3811}
3812
c801d85f
KB
3813// -------------------------------------------------------------------------------------
3814// wxListCtrl
3815// -------------------------------------------------------------------------------------
3816
3817IMPLEMENT_DYNAMIC_CLASS(wxListCtrl, wxControl)
3818
3819BEGIN_EVENT_TABLE(wxListCtrl,wxControl)
cf1dfa6b
VZ
3820 EVT_SIZE(wxListCtrl::OnSize)
3821 EVT_IDLE(wxListCtrl::OnIdle)
c801d85f
KB
3822END_EVENT_TABLE()
3823
fd9811b1 3824wxListCtrl::wxListCtrl()
c801d85f 3825{
5b077d48
RR
3826 m_imageListNormal = (wxImageList *) NULL;
3827 m_imageListSmall = (wxImageList *) NULL;
3828 m_imageListState = (wxImageList *) NULL;
cf1dfa6b
VZ
3829
3830 m_ownsImageListNormal =
3831 m_ownsImageListSmall =
3832 m_ownsImageListState = FALSE;
3833
5b077d48
RR
3834 m_mainWin = (wxListMainWindow*) NULL;
3835 m_headerWin = (wxListHeaderWindow*) NULL;
c801d85f
KB
3836}
3837
fd9811b1 3838wxListCtrl::~wxListCtrl()
c801d85f 3839{
cf1dfa6b
VZ
3840 if (m_ownsImageListNormal)
3841 delete m_imageListNormal;
3842 if (m_ownsImageListSmall)
3843 delete m_imageListSmall;
3844 if (m_ownsImageListState)
3845 delete m_imageListState;
3846}
3847
3848void wxListCtrl::CreateHeaderWindow()
3849{
3850 m_headerWin = new wxListHeaderWindow
3851 (
3852 this, -1, m_mainWin,
3853 wxPoint(0, 0),
3854 wxSize(GetClientSize().x, HEADER_HEIGHT),
3855 wxTAB_TRAVERSAL
3856 );
c801d85f
KB
3857}
3858
25e3a937
VZ
3859bool wxListCtrl::Create(wxWindow *parent,
3860 wxWindowID id,
3861 const wxPoint &pos,
3862 const wxSize &size,
3863 long style,
25e3a937 3864 const wxValidator &validator,
25e3a937 3865 const wxString &name)
c801d85f 3866{
cf1dfa6b
VZ
3867 m_imageListNormal =
3868 m_imageListSmall =
5b077d48 3869 m_imageListState = (wxImageList *) NULL;
cf1dfa6b
VZ
3870 m_ownsImageListNormal =
3871 m_ownsImageListSmall =
3872 m_ownsImageListState = FALSE;
3873
5b077d48
RR
3874 m_mainWin = (wxListMainWindow*) NULL;
3875 m_headerWin = (wxListHeaderWindow*) NULL;
bd8289c1 3876
25e3a937 3877 if ( !(style & (wxLC_REPORT | wxLC_LIST | wxLC_ICON)) )
5b077d48 3878 {
25e3a937 3879 style = style | wxLC_LIST;
5b077d48 3880 }
f6bcfd97 3881
cf1dfa6b
VZ
3882 if ( !wxControl::Create( parent, id, pos, size, style, validator, name ) )
3883 return FALSE;
f6bcfd97 3884
cf1dfa6b 3885 if ( style & wxSUNKEN_BORDER )
25e3a937 3886 style -= wxSUNKEN_BORDER;
bd8289c1 3887
25e3a937 3888 m_mainWin = new wxListMainWindow( this, -1, wxPoint(0,0), size, style );
bd8289c1 3889
f03fc89f 3890 if (HasFlag(wxLC_REPORT))
ea451729 3891 {
cf1dfa6b
VZ
3892 CreateHeaderWindow();
3893
ea451729 3894 if (HasFlag(wxLC_NO_HEADER))
cf1dfa6b
VZ
3895 {
3896 // VZ: why do we create it at all then?
ea451729 3897 m_headerWin->Show( FALSE );
cf1dfa6b 3898 }
ea451729 3899 }
bd8289c1 3900
cf1dfa6b 3901 return TRUE;
e1e955e1 3902}
c801d85f
KB
3903
3904void wxListCtrl::OnSize( wxSizeEvent &WXUNUSED(event) )
3905{
5b077d48 3906 /* handled in OnIdle */
bd8289c1 3907
5b077d48 3908 if (m_mainWin) m_mainWin->m_dirty = TRUE;
e1e955e1 3909}
c801d85f 3910
debe6624 3911void wxListCtrl::SetSingleStyle( long style, bool add )
c801d85f 3912{
f03fc89f 3913 long flag = GetWindowStyle();
bd8289c1 3914
5b077d48
RR
3915 if (add)
3916 {
cf1dfa6b
VZ
3917 if (style & wxLC_MASK_TYPE)
3918 flag &= ~wxLC_MASK_TYPE;
3919 if (style & wxLC_MASK_ALIGN)
3920 flag &= ~wxLC_MASK_ALIGN;
3921 if (style & wxLC_MASK_SORT)
3922 flag &= ~wxLC_MASK_SORT;
5b077d48 3923 }
c801d85f 3924
5b077d48
RR
3925 if (add)
3926 {
3927 flag |= style;
3928 }
3929 else
3930 {
cf1dfa6b 3931 flag &= ~style;
5b077d48 3932 }
bd8289c1 3933
5b077d48 3934 SetWindowStyleFlag( flag );
e1e955e1 3935}
c801d85f 3936
debe6624 3937void wxListCtrl::SetWindowStyleFlag( long flag )
c801d85f 3938{
121a3581
RR
3939 if (m_mainWin)
3940 {
3941 m_mainWin->DeleteEverything();
c801d85f 3942
121a3581
RR
3943 int width = 0;
3944 int height = 0;
3945 GetClientSize( &width, &height );
c801d85f 3946
121a3581 3947 if (flag & wxLC_REPORT)
5b077d48 3948 {
121a3581 3949 if (!HasFlag(wxLC_REPORT))
5b077d48 3950 {
121a3581
RR
3951 if (!m_headerWin)
3952 {
cf1dfa6b
VZ
3953 CreateHeaderWindow();
3954
bffa1c77
VZ
3955 if (HasFlag(wxLC_NO_HEADER))
3956 m_headerWin->Show( FALSE );
121a3581
RR
3957 }
3958 else
004fd0c8 3959 {
bffa1c77
VZ
3960 if (flag & wxLC_NO_HEADER)
3961 m_headerWin->Show( FALSE );
3962 else
8636aed8 3963 m_headerWin->Show( TRUE );
004fd0c8 3964 }
5b077d48
RR
3965 }
3966 }
cf1dfa6b 3967 else // !report
5b077d48 3968 {
cf1dfa6b 3969 if ( m_mainWin->HasHeader() )
121a3581
RR
3970 {
3971 m_headerWin->Show( FALSE );
3972 }
bffa1c77 3973 }
e1e955e1 3974 }
004fd0c8 3975
5b077d48 3976 wxWindow::SetWindowStyleFlag( flag );
e1e955e1 3977}
c801d85f 3978
e487524e 3979bool wxListCtrl::GetColumn(int col, wxListItem &item) const
c801d85f 3980{
5b077d48
RR
3981 m_mainWin->GetColumn( col, item );
3982 return TRUE;
e1e955e1 3983}
c801d85f 3984
debe6624 3985bool wxListCtrl::SetColumn( int col, wxListItem& item )
c801d85f 3986{
5b077d48
RR
3987 m_mainWin->SetColumn( col, item );
3988 return TRUE;
e1e955e1 3989}
c801d85f 3990
e487524e 3991int wxListCtrl::GetColumnWidth( int col ) const
c801d85f 3992{
5b077d48 3993 return m_mainWin->GetColumnWidth( col );
e1e955e1 3994}
c801d85f 3995
debe6624 3996bool wxListCtrl::SetColumnWidth( int col, int width )
c801d85f 3997{
5b077d48
RR
3998 m_mainWin->SetColumnWidth( col, width );
3999 return TRUE;
e1e955e1 4000}
c801d85f 4001
fd9811b1 4002int wxListCtrl::GetCountPerPage() const
c801d85f
KB
4003{
4004 return m_mainWin->GetCountPerPage(); // different from Windows ?
e1e955e1 4005}
c801d85f 4006
e487524e 4007bool wxListCtrl::GetItem( wxListItem &info ) const
c801d85f 4008{
5b077d48
RR
4009 m_mainWin->GetItem( info );
4010 return TRUE;
e1e955e1 4011}
c801d85f
KB
4012
4013bool wxListCtrl::SetItem( wxListItem &info )
4014{
5b077d48
RR
4015 m_mainWin->SetItem( info );
4016 return TRUE;
e1e955e1 4017}
c801d85f 4018
debe6624 4019long wxListCtrl::SetItem( long index, int col, const wxString& label, int imageId )
c801d85f 4020{
5b077d48
RR
4021 wxListItem info;
4022 info.m_text = label;
4023 info.m_mask = wxLIST_MASK_TEXT;
4024 info.m_itemId = index;
4025 info.m_col = col;
4026 if ( imageId > -1 )
4027 {
4028 info.m_image = imageId;
4029 info.m_mask |= wxLIST_MASK_IMAGE;
4030 };
4031 m_mainWin->SetItem(info);
4032 return TRUE;
e1e955e1 4033}
c801d85f 4034
e487524e 4035int wxListCtrl::GetItemState( long item, long stateMask ) const
c801d85f 4036{
5b077d48 4037 return m_mainWin->GetItemState( item, stateMask );
e1e955e1 4038}
c801d85f 4039
debe6624 4040bool wxListCtrl::SetItemState( long item, long state, long stateMask )
c801d85f 4041{
5b077d48
RR
4042 m_mainWin->SetItemState( item, state, stateMask );
4043 return TRUE;
e1e955e1 4044}
c801d85f 4045
debe6624 4046bool wxListCtrl::SetItemImage( long item, int image, int WXUNUSED(selImage) )
c801d85f 4047{
5b077d48
RR
4048 wxListItem info;
4049 info.m_image = image;
4050 info.m_mask = wxLIST_MASK_IMAGE;
4051 info.m_itemId = item;
4052 m_mainWin->SetItem( info );
4053 return TRUE;
e1e955e1 4054}
c801d85f 4055
e487524e 4056wxString wxListCtrl::GetItemText( long item ) const
c801d85f 4057{
5b077d48
RR
4058 wxListItem info;
4059 info.m_itemId = item;
4060 m_mainWin->GetItem( info );
4061 return info.m_text;
e1e955e1 4062}
c801d85f 4063
debe6624 4064void wxListCtrl::SetItemText( long item, const wxString &str )
c801d85f 4065{
5b077d48
RR
4066 wxListItem info;
4067 info.m_mask = wxLIST_MASK_TEXT;
4068 info.m_itemId = item;
4069 info.m_text = str;
4070 m_mainWin->SetItem( info );
e1e955e1 4071}
c801d85f 4072
e487524e 4073long wxListCtrl::GetItemData( long item ) const
c801d85f 4074{
5b077d48
RR
4075 wxListItem info;
4076 info.m_itemId = item;
4077 m_mainWin->GetItem( info );
4078 return info.m_data;
e1e955e1 4079}
c801d85f 4080
debe6624 4081bool wxListCtrl::SetItemData( long item, long data )
c801d85f 4082{
5b077d48
RR
4083 wxListItem info;
4084 info.m_mask = wxLIST_MASK_DATA;
4085 info.m_itemId = item;
4086 info.m_data = data;
4087 m_mainWin->SetItem( info );
4088 return TRUE;
e1e955e1 4089}
c801d85f 4090
0a240683 4091bool wxListCtrl::GetItemRect( long item, wxRect &rect, int WXUNUSED(code) ) const
c801d85f 4092{
5b077d48
RR
4093 m_mainWin->GetItemRect( item, rect );
4094 return TRUE;
e1e955e1 4095}
c801d85f 4096
e487524e 4097bool wxListCtrl::GetItemPosition( long item, wxPoint& pos ) const
c801d85f 4098{
5b077d48
RR
4099 m_mainWin->GetItemPosition( item, pos );
4100 return TRUE;
e1e955e1 4101}
c801d85f 4102
debe6624 4103bool wxListCtrl::SetItemPosition( long WXUNUSED(item), const wxPoint& WXUNUSED(pos) )
c801d85f 4104{
5b077d48 4105 return 0;
e1e955e1 4106}
c801d85f 4107
fd9811b1 4108int wxListCtrl::GetItemCount() const
c801d85f 4109{
5b077d48 4110 return m_mainWin->GetItemCount();
e1e955e1 4111}
c801d85f 4112
fd9811b1 4113int wxListCtrl::GetColumnCount() const
92976ab6 4114{
5b077d48 4115 return m_mainWin->GetColumnCount();
92976ab6
RR
4116}
4117
33d0b396
RR
4118void wxListCtrl::SetItemSpacing( int spacing, bool isSmall )
4119{
5b077d48 4120 m_mainWin->SetItemSpacing( spacing, isSmall );
e1e955e1 4121}
33d0b396 4122
e487524e 4123int wxListCtrl::GetItemSpacing( bool isSmall ) const
c801d85f 4124{
5b077d48 4125 return m_mainWin->GetItemSpacing( isSmall );
e1e955e1 4126}
c801d85f 4127
fd9811b1 4128int wxListCtrl::GetSelectedItemCount() const
c801d85f 4129{
5b077d48 4130 return m_mainWin->GetSelectedItemCount();
e1e955e1 4131}
c801d85f 4132
fd9811b1 4133wxColour wxListCtrl::GetTextColour() const
c801d85f 4134{
0530737d 4135 return GetForegroundColour();
e1e955e1 4136}
c801d85f 4137
0530737d 4138void wxListCtrl::SetTextColour(const wxColour& col)
c801d85f 4139{
0530737d 4140 SetForegroundColour(col);
e1e955e1 4141}
c801d85f 4142
fd9811b1 4143long wxListCtrl::GetTopItem() const
c801d85f 4144{
5b077d48 4145 return 0;
e1e955e1 4146}
c801d85f 4147
6de97a3b 4148long wxListCtrl::GetNextItem( long item, int geom, int state ) const
c801d85f 4149{
5b077d48 4150 return m_mainWin->GetNextItem( item, geom, state );
e1e955e1 4151}
c801d85f 4152
e487524e 4153wxImageList *wxListCtrl::GetImageList(int which) const
c801d85f 4154{
5b077d48
RR
4155 if (which == wxIMAGE_LIST_NORMAL)
4156 {
4157 return m_imageListNormal;
4158 }
4159 else if (which == wxIMAGE_LIST_SMALL)
4160 {
4161 return m_imageListSmall;
4162 }
4163 else if (which == wxIMAGE_LIST_STATE)
4164 {
4165 return m_imageListState;
4166 }
4167 return (wxImageList *) NULL;
e1e955e1 4168}
c801d85f 4169
debe6624 4170void wxListCtrl::SetImageList( wxImageList *imageList, int which )
c801d85f 4171{
2e12c11a
VS
4172 if ( which == wxIMAGE_LIST_NORMAL )
4173 {
4174 if (m_ownsImageListNormal) delete m_imageListNormal;
4175 m_imageListNormal = imageList;
4176 m_ownsImageListNormal = FALSE;
4177 }
4178 else if ( which == wxIMAGE_LIST_SMALL )
4179 {
4180 if (m_ownsImageListSmall) delete m_imageListSmall;
4181 m_imageListSmall = imageList;
4182 m_ownsImageListSmall = FALSE;
4183 }
4184 else if ( which == wxIMAGE_LIST_STATE )
4185 {
4186 if (m_ownsImageListState) delete m_imageListState;
4187 m_imageListState = imageList;
4188 m_ownsImageListState = FALSE;
4189 }
4190
5b077d48 4191 m_mainWin->SetImageList( imageList, which );
e1e955e1 4192}
c801d85f 4193
2e12c11a
VS
4194void wxListCtrl::AssignImageList(wxImageList *imageList, int which)
4195{
4196 SetImageList(imageList, which);
4197 if ( which == wxIMAGE_LIST_NORMAL )
4198 m_ownsImageListNormal = TRUE;
4199 else if ( which == wxIMAGE_LIST_SMALL )
4200 m_ownsImageListSmall = TRUE;
4201 else if ( which == wxIMAGE_LIST_STATE )
4202 m_ownsImageListState = TRUE;
4203}
4204
debe6624 4205bool wxListCtrl::Arrange( int WXUNUSED(flag) )
c801d85f 4206{
5b077d48 4207 return 0;
e1e955e1 4208}
c801d85f 4209
debe6624 4210bool wxListCtrl::DeleteItem( long item )
c801d85f 4211{
5b077d48
RR
4212 m_mainWin->DeleteItem( item );
4213 return TRUE;
e1e955e1 4214}
c801d85f 4215
fd9811b1 4216bool wxListCtrl::DeleteAllItems()
c801d85f 4217{
5b077d48
RR
4218 m_mainWin->DeleteAllItems();
4219 return TRUE;
e1e955e1 4220}
c801d85f 4221
4f22cf8d 4222bool wxListCtrl::DeleteAllColumns()
bd8289c1 4223{
24b9f055
VZ
4224 size_t count = m_mainWin->m_columns.GetCount();
4225 for ( size_t n = 0; n < count; n++ )
bd8289c1 4226 DeleteColumn(n);
bffa1c77 4227
5b077d48 4228 return TRUE;
4f22cf8d
RR
4229}
4230
4231void wxListCtrl::ClearAll()
4232{
5b077d48 4233 m_mainWin->DeleteEverything();
bd8289c1
VZ
4234}
4235
debe6624 4236bool wxListCtrl::DeleteColumn( int col )
c801d85f 4237{
5b077d48
RR
4238 m_mainWin->DeleteColumn( col );
4239 return TRUE;
e1e955e1 4240}
c801d85f 4241
e179bd65 4242void wxListCtrl::Edit( long item )
c801d85f 4243{
cf1dfa6b 4244 m_mainWin->EditLabel( item );
e1e955e1 4245}
c801d85f 4246
debe6624 4247bool wxListCtrl::EnsureVisible( long item )
c801d85f 4248{
5b077d48
RR
4249 m_mainWin->EnsureVisible( item );
4250 return TRUE;
e1e955e1 4251}
c801d85f 4252
debe6624 4253long wxListCtrl::FindItem( long start, const wxString& str, bool partial )
c801d85f 4254{
5b077d48 4255 return m_mainWin->FindItem( start, str, partial );
e1e955e1 4256}
c801d85f 4257
debe6624 4258long wxListCtrl::FindItem( long start, long data )
c801d85f 4259{
5b077d48 4260 return m_mainWin->FindItem( start, data );
e1e955e1 4261}
c801d85f 4262
bd8289c1 4263long wxListCtrl::FindItem( long WXUNUSED(start), const wxPoint& WXUNUSED(pt),
debe6624 4264 int WXUNUSED(direction))
c801d85f 4265{
5b077d48 4266 return 0;
e1e955e1 4267}
c801d85f
KB
4268
4269long wxListCtrl::HitTest( const wxPoint &point, int &flags )
4270{
5b077d48 4271 return m_mainWin->HitTest( (int)point.x, (int)point.y, flags );
e1e955e1 4272}
c801d85f
KB
4273
4274long wxListCtrl::InsertItem( wxListItem& info )
4275{
5b077d48 4276 m_mainWin->InsertItem( info );
2ebcd5f5 4277 return info.m_itemId;
e1e955e1 4278}
c801d85f 4279
debe6624 4280long wxListCtrl::InsertItem( long index, const wxString &label )
c801d85f 4281{
51cc4dad
RR
4282 wxListItem info;
4283 info.m_text = label;
4284 info.m_mask = wxLIST_MASK_TEXT;
4285 info.m_itemId = index;
4286 return InsertItem( info );
e1e955e1 4287}
c801d85f 4288
debe6624 4289long wxListCtrl::InsertItem( long index, int imageIndex )
c801d85f 4290{
51cc4dad
RR
4291 wxListItem info;
4292 info.m_mask = wxLIST_MASK_IMAGE;
4293 info.m_image = imageIndex;
4294 info.m_itemId = index;
4295 return InsertItem( info );
e1e955e1 4296}
c801d85f 4297
debe6624 4298long wxListCtrl::InsertItem( long index, const wxString &label, int imageIndex )
c801d85f 4299{
51cc4dad
RR
4300 wxListItem info;
4301 info.m_text = label;
4302 info.m_image = imageIndex;
4303 info.m_mask = wxLIST_MASK_TEXT | wxLIST_MASK_IMAGE;
4304 info.m_itemId = index;
4305 return InsertItem( info );
e1e955e1 4306}
c801d85f 4307
debe6624 4308long wxListCtrl::InsertColumn( long col, wxListItem &item )
c801d85f 4309{
d3e90957 4310 wxASSERT( m_headerWin );
51cc4dad 4311 m_mainWin->InsertColumn( col, item );
d3e90957 4312 m_headerWin->Refresh();
25e3a937 4313
51cc4dad 4314 return 0;
e1e955e1 4315}
c801d85f 4316
debe6624
JS
4317long wxListCtrl::InsertColumn( long col, const wxString &heading,
4318 int format, int width )
c801d85f 4319{
51cc4dad
RR
4320 wxListItem item;
4321 item.m_mask = wxLIST_MASK_TEXT | wxLIST_MASK_FORMAT;
4322 item.m_text = heading;
4323 if (width >= -2)
4324 {
4325 item.m_mask |= wxLIST_MASK_WIDTH;
4326 item.m_width = width;
4327 }
4328 item.m_format = format;
c801d85f 4329
51cc4dad 4330 return InsertColumn( col, item );
e1e955e1 4331}
c801d85f 4332
debe6624 4333bool wxListCtrl::ScrollList( int WXUNUSED(dx), int WXUNUSED(dy) )
c801d85f 4334{
51cc4dad 4335 return 0;
e1e955e1 4336}
c801d85f
KB
4337
4338// Sort items.
4339// fn is a function which takes 3 long arguments: item1, item2, data.
4340// item1 is the long data associated with a first item (NOT the index).
4341// item2 is the long data associated with a second item (NOT the index).
4342// data is the same value as passed to SortItems.
4343// The return value is a negative number if the first item should precede the second
4344// item, a positive number of the second item should precede the first,
4345// or zero if the two items are equivalent.
4346// data is arbitrary data to be passed to the sort function.
4347
4348bool wxListCtrl::SortItems( wxListCtrlCompare fn, long data )
4349{
51cc4dad
RR
4350 m_mainWin->SortItems( fn, data );
4351 return TRUE;
e1e955e1 4352}
c801d85f 4353
cf1dfa6b
VZ
4354// ----------------------------------------------------------------------------
4355// OnIdle() handler: this is the place where we redraw the control
4356// ----------------------------------------------------------------------------
4357
4358void wxListCtrl::OnIdle( wxIdleEvent & WXUNUSED(event) )
53010e52 4359{
cf1dfa6b
VZ
4360 // do it only if needed
4361 if ( !m_mainWin->m_dirty )
4362 return;
53010e52 4363
51cc4dad
RR
4364 int cw = 0;
4365 int ch = 0;
4366 GetClientSize( &cw, &ch );
bd8289c1 4367
cf1dfa6b 4368 if ( m_mainWin->HasHeader() )
51cc4dad 4369 {
cf1dfa6b
VZ
4370 m_headerWin->SetSize( 0, 0, cw, HEADER_HEIGHT );
4371 m_mainWin->SetSize( 0, HEADER_HEIGHT + 1, cw, ch - HEADER_HEIGHT - 1 );
51cc4dad 4372 }
cf1dfa6b 4373 else // no header window
51cc4dad 4374 {
cf1dfa6b 4375 m_mainWin->SetSize( 0, 0, cw, ch );
51cc4dad 4376 }
bd8289c1 4377
51cc4dad 4378 m_mainWin->CalculatePositions();
cf1dfa6b 4379
51cc4dad
RR
4380 m_mainWin->m_dirty = FALSE;
4381 m_mainWin->Refresh();
f6bcfd97
BP
4382
4383 if ( m_headerWin && m_headerWin->m_dirty )
4384 {
4385 m_headerWin->m_dirty = FALSE;
4386 m_headerWin->Refresh();
4387 }
e1e955e1 4388}
53010e52 4389
cf1dfa6b
VZ
4390// ----------------------------------------------------------------------------
4391// font/colours
4392// ----------------------------------------------------------------------------
4393
f03fc89f 4394bool wxListCtrl::SetBackgroundColour( const wxColour &colour )
bd8289c1 4395{
51cc4dad
RR
4396 if (m_mainWin)
4397 {
4398 m_mainWin->SetBackgroundColour( colour );
4399 m_mainWin->m_dirty = TRUE;
4400 }
004fd0c8 4401
f03fc89f 4402 return TRUE;
e4d06860
RR
4403}
4404
f03fc89f 4405bool wxListCtrl::SetForegroundColour( const wxColour &colour )
bd8289c1 4406{
f03fc89f
VZ
4407 if ( !wxWindow::SetForegroundColour( colour ) )
4408 return FALSE;
004fd0c8 4409
51cc4dad
RR
4410 if (m_mainWin)
4411 {
4412 m_mainWin->SetForegroundColour( colour );
4413 m_mainWin->m_dirty = TRUE;
4414 }
004fd0c8 4415
51cc4dad
RR
4416 if (m_headerWin)
4417 {
4418 m_headerWin->SetForegroundColour( colour );
4419 }
f03fc89f
VZ
4420
4421 return TRUE;
e4d06860 4422}
bd8289c1 4423
f03fc89f 4424bool wxListCtrl::SetFont( const wxFont &font )
bd8289c1 4425{
f03fc89f
VZ
4426 if ( !wxWindow::SetFont( font ) )
4427 return FALSE;
004fd0c8 4428
51cc4dad
RR
4429 if (m_mainWin)
4430 {
4431 m_mainWin->SetFont( font );
4432 m_mainWin->m_dirty = TRUE;
4433 }
004fd0c8 4434
51cc4dad
RR
4435 if (m_headerWin)
4436 {
4437 m_headerWin->SetFont( font );
4438 }
f03fc89f 4439
cf1dfa6b
VZ
4440 // invalidate it as the font changed
4441 m_mainWin->OnFontChange();
4442
f03fc89f 4443 return TRUE;
e4d06860 4444}
c801d85f 4445
cf1dfa6b
VZ
4446// ----------------------------------------------------------------------------
4447// methods forwarded to m_mainWin
4448// ----------------------------------------------------------------------------
4449
efbb7287
VZ
4450#if wxUSE_DRAG_AND_DROP
4451
4452void wxListCtrl::SetDropTarget( wxDropTarget *dropTarget )
4453{
4454 m_mainWin->SetDropTarget( dropTarget );
4455}
4456
4457wxDropTarget *wxListCtrl::GetDropTarget() const
4458{
4459 return m_mainWin->GetDropTarget();
4460}
4461
4462#endif // wxUSE_DRAG_AND_DROP
4463
4464bool wxListCtrl::SetCursor( const wxCursor &cursor )
4465{
4466 return m_mainWin ? m_mainWin->wxWindow::SetCursor(cursor) : FALSE;
4467}
4468
4469wxColour wxListCtrl::GetBackgroundColour() const
4470{
4471 return m_mainWin ? m_mainWin->GetBackgroundColour() : wxColour();
4472}
4473
4474wxColour wxListCtrl::GetForegroundColour() const
4475{
4476 return m_mainWin ? m_mainWin->GetForegroundColour() : wxColour();
4477}
4478
4479bool wxListCtrl::DoPopupMenu( wxMenu *menu, int x, int y )
4480{
3a8c693a 4481#if wxUSE_MENUS
efbb7287 4482 return m_mainWin->PopupMenu( menu, x, y );
3a8c693a
VZ
4483#else
4484 return FALSE;
4485#endif // wxUSE_MENUS
efbb7287
VZ
4486}
4487
4488void wxListCtrl::SetFocus()
4489{
4490 /* The test in window.cpp fails as we are a composite
4491 window, so it checks against "this", but not m_mainWin. */
4492 if ( FindFocus() != this )
4493 m_mainWin->SetFocus();
4494}
1e6feb95 4495
2c1f73ee
VZ
4496// ----------------------------------------------------------------------------
4497// virtual list control support
4498// ----------------------------------------------------------------------------
4499
4500wxString wxListCtrl::OnGetItemText(long item, long col) const
4501{
4502 // this is a pure virtual function, in fact - which is not really pure
4503 // because the controls which are not virtual don't need to implement it
4504 wxFAIL_MSG( _T("not supposed to be called") );
4505
4506 return wxEmptyString;
4507}
4508
4509int wxListCtrl::OnGetItemImage(long item) const
4510{
4511 // same as above
4512 wxFAIL_MSG( _T("not supposed to be called") );
4513
4514 return -1;
4515}
4516
4517void wxListCtrl::SetItemCount(long count)
4518{
4519 wxASSERT_MSG( IsVirtual(), _T("this is for virtual controls only") );
4520
4521 m_mainWin->SetItemCount(count);
4522}
4523
1e6feb95 4524#endif // wxUSE_LISTCTRL
cf1dfa6b
VZ
4525
4526#endif