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