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