1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/generic/listctrl.cpp
3 // Purpose: generic implementation of wxListCtrl
4 // Author: Robert Roebling
5 // Vadim Zeitlin (virtual list control support)
7 // Copyright: (c) 1998 Robert Roebling
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
13 // 1. we need to implement searching/sorting for virtual controls somehow
14 // 2. when changing selection the lines are refreshed twice
17 // For compilers that support precompilation, includes "wx.h".
18 #include "wx/wxprec.h"
26 #include "wx/listctrl.h"
29 #include "wx/scrolwin.h"
31 #include "wx/settings.h"
32 #include "wx/dynarray.h"
33 #include "wx/dcclient.h"
34 #include "wx/dcscreen.h"
36 #include "wx/settings.h"
40 #include "wx/imaglist.h"
41 #include "wx/renderer.h"
42 #include "wx/generic/private/listctrl.h"
45 #include "wx/osx/private.h"
48 #if defined(__WXMSW__) && !defined(__WXWINCE__) && !defined(__WXUNIVERSAL__)
49 #define "wx/msw/wrapwin.h"
52 // NOTE: If using the wxListBox visual attributes works everywhere then this can
53 // be removed, as well as the #else case below.
54 #define _USE_VISATTR 0
57 // ----------------------------------------------------------------------------
59 // ----------------------------------------------------------------------------
61 // // the height of the header window (FIXME: should depend on its font!)
62 // static const int HEADER_HEIGHT = 23;
64 static const int SCROLL_UNIT_X
= 15;
66 // the spacing between the lines (in report mode)
67 static const int LINE_SPACING
= 0;
69 // extra margins around the text label
71 static const int EXTRA_WIDTH
= 6;
73 static const int EXTRA_WIDTH
= 4;
77 static const int EXTRA_HEIGHT
= 6;
79 static const int EXTRA_HEIGHT
= 4;
82 // margin between the window and the items
83 static const int EXTRA_BORDER_X
= 2;
84 static const int EXTRA_BORDER_Y
= 2;
86 // offset for the header window
87 static const int HEADER_OFFSET_X
= 0;
88 static const int HEADER_OFFSET_Y
= 0;
90 // margin between rows of icons in [small] icon view
91 static const int MARGIN_BETWEEN_ROWS
= 6;
93 // when autosizing the columns, add some slack
94 static const int AUTOSIZE_COL_MARGIN
= 10;
96 // default width for the header columns
97 static const int WIDTH_COL_DEFAULT
= 80;
99 // the space between the image and the text in the report mode
100 static const int IMAGE_MARGIN_IN_REPORT_MODE
= 5;
102 // the space between the image and the text in the report mode in header
103 static const int HEADER_IMAGE_MARGIN_IN_REPORT_MODE
= 2;
107 // ----------------------------------------------------------------------------
108 // arrays/list implementations
109 // ----------------------------------------------------------------------------
111 #include "wx/listimpl.cpp"
112 WX_DEFINE_LIST(wxListItemDataList
)
114 #include "wx/arrimpl.cpp"
115 WX_DEFINE_OBJARRAY(wxListLineDataArray
)
117 #include "wx/listimpl.cpp"
118 WX_DEFINE_LIST(wxListHeaderDataList
)
121 // ----------------------------------------------------------------------------
123 // ----------------------------------------------------------------------------
125 wxListItemData::~wxListItemData()
127 // in the virtual list control the attributes are managed by the main
128 // program, so don't delete them
129 if ( !m_owner
->IsVirtual() )
135 void wxListItemData::Init()
143 wxListItemData::wxListItemData(wxListMainWindow
*owner
)
149 if ( owner
->InReportView() )
155 void wxListItemData::SetItem( const wxListItem
&info
)
157 if ( info
.m_mask
& wxLIST_MASK_TEXT
)
158 SetText(info
.m_text
);
159 if ( info
.m_mask
& wxLIST_MASK_IMAGE
)
160 m_image
= info
.m_image
;
161 if ( info
.m_mask
& wxLIST_MASK_DATA
)
162 m_data
= info
.m_data
;
164 if ( info
.HasAttributes() )
167 m_attr
->AssignFrom(*info
.GetAttributes());
169 m_attr
= new wxListItemAttr(*info
.GetAttributes());
177 m_rect
->width
= info
.m_width
;
181 void wxListItemData::SetPosition( int x
, int y
)
183 wxCHECK_RET( m_rect
, wxT("unexpected SetPosition() call") );
189 void wxListItemData::SetSize( int width
, int height
)
191 wxCHECK_RET( m_rect
, wxT("unexpected SetSize() call") );
194 m_rect
->width
= width
;
196 m_rect
->height
= height
;
199 bool wxListItemData::IsHit( int x
, int y
) const
201 wxCHECK_MSG( m_rect
, false, wxT("can't be called in this mode") );
203 return wxRect(GetX(), GetY(), GetWidth(), GetHeight()).Contains(x
, y
);
206 int wxListItemData::GetX() const
208 wxCHECK_MSG( m_rect
, 0, wxT("can't be called in this mode") );
213 int wxListItemData::GetY() const
215 wxCHECK_MSG( m_rect
, 0, wxT("can't be called in this mode") );
220 int wxListItemData::GetWidth() const
222 wxCHECK_MSG( m_rect
, 0, wxT("can't be called in this mode") );
224 return m_rect
->width
;
227 int wxListItemData::GetHeight() const
229 wxCHECK_MSG( m_rect
, 0, wxT("can't be called in this mode") );
231 return m_rect
->height
;
234 void wxListItemData::GetItem( wxListItem
&info
) const
236 long mask
= info
.m_mask
;
238 // by default, get everything for backwards compatibility
241 if ( mask
& wxLIST_MASK_TEXT
)
242 info
.m_text
= m_text
;
243 if ( mask
& wxLIST_MASK_IMAGE
)
244 info
.m_image
= m_image
;
245 if ( mask
& wxLIST_MASK_DATA
)
246 info
.m_data
= m_data
;
250 if ( m_attr
->HasTextColour() )
251 info
.SetTextColour(m_attr
->GetTextColour());
252 if ( m_attr
->HasBackgroundColour() )
253 info
.SetBackgroundColour(m_attr
->GetBackgroundColour());
254 if ( m_attr
->HasFont() )
255 info
.SetFont(m_attr
->GetFont());
259 //-----------------------------------------------------------------------------
261 //-----------------------------------------------------------------------------
263 void wxListHeaderData::Init()
275 wxListHeaderData::wxListHeaderData()
280 wxListHeaderData::wxListHeaderData( const wxListItem
&item
)
287 void wxListHeaderData::SetItem( const wxListItem
&item
)
289 m_mask
= item
.m_mask
;
291 if ( m_mask
& wxLIST_MASK_TEXT
)
292 m_text
= item
.m_text
;
294 if ( m_mask
& wxLIST_MASK_IMAGE
)
295 m_image
= item
.m_image
;
297 if ( m_mask
& wxLIST_MASK_FORMAT
)
298 m_format
= item
.m_format
;
300 if ( m_mask
& wxLIST_MASK_WIDTH
)
301 SetWidth(item
.m_width
);
303 if ( m_mask
& wxLIST_MASK_STATE
)
304 SetState(item
.m_state
);
307 void wxListHeaderData::SetPosition( int x
, int y
)
313 void wxListHeaderData::SetHeight( int h
)
318 void wxListHeaderData::SetWidth( int w
)
320 m_width
= w
< 0 ? WIDTH_COL_DEFAULT
: w
;
323 void wxListHeaderData::SetState( int flag
)
328 void wxListHeaderData::SetFormat( int format
)
333 bool wxListHeaderData::HasImage() const
335 return m_image
!= -1;
338 bool wxListHeaderData::IsHit( int x
, int y
) const
340 return ((x
>= m_xpos
) && (x
<= m_xpos
+m_width
) && (y
>= m_ypos
) && (y
<= m_ypos
+m_height
));
343 void wxListHeaderData::GetItem( wxListItem
& item
)
345 long mask
= item
.m_mask
;
348 // by default, get everything for backwards compatibility
352 if ( mask
& wxLIST_MASK_STATE
)
353 item
.m_state
= m_state
;
354 if ( mask
& wxLIST_MASK_TEXT
)
355 item
.m_text
= m_text
;
356 if ( mask
& wxLIST_MASK_IMAGE
)
357 item
.m_image
= m_image
;
358 if ( mask
& wxLIST_MASK_WIDTH
)
359 item
.m_width
= m_width
;
360 if ( mask
& wxLIST_MASK_FORMAT
)
361 item
.m_format
= m_format
;
364 int wxListHeaderData::GetImage() const
369 int wxListHeaderData::GetWidth() const
374 int wxListHeaderData::GetFormat() const
379 int wxListHeaderData::GetState() const
384 //-----------------------------------------------------------------------------
386 //-----------------------------------------------------------------------------
388 inline int wxListLineData::GetMode() const
390 return m_owner
->GetListCtrl()->GetWindowStyleFlag() & wxLC_MASK_TYPE
;
393 inline bool wxListLineData::InReportView() const
395 return m_owner
->HasFlag(wxLC_REPORT
);
398 inline bool wxListLineData::IsVirtual() const
400 return m_owner
->IsVirtual();
403 wxListLineData::wxListLineData( wxListMainWindow
*owner
)
407 if ( InReportView() )
410 m_gi
= new GeometryInfo
;
412 m_highlighted
= false;
414 InitItems( GetMode() == wxLC_REPORT
? m_owner
->GetColumnCount() : 1 );
417 void wxListLineData::CalculateSize( wxDC
*dc
, int spacing
)
419 wxListItemDataList::compatibility_iterator node
= m_items
.GetFirst();
420 wxCHECK_RET( node
, wxT("no subitems at all??") );
422 wxListItemData
*item
= node
->GetData();
430 case wxLC_SMALL_ICON
:
431 m_gi
->m_rectAll
.width
= spacing
;
438 m_gi
->m_rectLabel
.width
=
439 m_gi
->m_rectLabel
.height
= 0;
443 dc
->GetTextExtent( s
, &lw
, &lh
);
447 m_gi
->m_rectAll
.height
= spacing
+ lh
;
449 m_gi
->m_rectAll
.width
= lw
;
451 m_gi
->m_rectLabel
.width
= lw
;
452 m_gi
->m_rectLabel
.height
= lh
;
455 if (item
->HasImage())
458 m_owner
->GetImageSize( item
->GetImage(), w
, h
);
459 m_gi
->m_rectIcon
.width
= w
+ 8;
460 m_gi
->m_rectIcon
.height
= h
+ 8;
462 if ( m_gi
->m_rectIcon
.width
> m_gi
->m_rectAll
.width
)
463 m_gi
->m_rectAll
.width
= m_gi
->m_rectIcon
.width
;
464 if ( m_gi
->m_rectIcon
.height
+ lh
> m_gi
->m_rectAll
.height
- 4 )
465 m_gi
->m_rectAll
.height
= m_gi
->m_rectIcon
.height
+ lh
+ 4;
468 if ( item
->HasText() )
470 m_gi
->m_rectHighlight
.width
= m_gi
->m_rectLabel
.width
;
471 m_gi
->m_rectHighlight
.height
= m_gi
->m_rectLabel
.height
;
473 else // no text, highlight the icon
475 m_gi
->m_rectHighlight
.width
= m_gi
->m_rectIcon
.width
;
476 m_gi
->m_rectHighlight
.height
= m_gi
->m_rectIcon
.height
;
481 s
= item
->GetTextForMeasuring();
483 dc
->GetTextExtent( s
, &lw
, &lh
);
487 m_gi
->m_rectLabel
.width
= lw
;
488 m_gi
->m_rectLabel
.height
= lh
;
490 m_gi
->m_rectAll
.width
= lw
;
491 m_gi
->m_rectAll
.height
= lh
;
493 if (item
->HasImage())
496 m_owner
->GetImageSize( item
->GetImage(), w
, h
);
497 m_gi
->m_rectIcon
.width
= w
;
498 m_gi
->m_rectIcon
.height
= h
;
500 m_gi
->m_rectAll
.width
+= 4 + w
;
501 if (h
> m_gi
->m_rectAll
.height
)
502 m_gi
->m_rectAll
.height
= h
;
505 m_gi
->m_rectHighlight
.width
= m_gi
->m_rectAll
.width
;
506 m_gi
->m_rectHighlight
.height
= m_gi
->m_rectAll
.height
;
510 wxFAIL_MSG( wxT("unexpected call to SetSize") );
514 wxFAIL_MSG( wxT("unknown mode") );
519 void wxListLineData::SetPosition( int x
, int y
, int spacing
)
521 wxListItemDataList::compatibility_iterator node
= m_items
.GetFirst();
522 wxCHECK_RET( node
, wxT("no subitems at all??") );
524 wxListItemData
*item
= node
->GetData();
529 case wxLC_SMALL_ICON
:
530 m_gi
->m_rectAll
.x
= x
;
531 m_gi
->m_rectAll
.y
= y
;
533 if ( item
->HasImage() )
535 m_gi
->m_rectIcon
.x
= m_gi
->m_rectAll
.x
+ 4 +
536 (m_gi
->m_rectAll
.width
- m_gi
->m_rectIcon
.width
) / 2;
537 m_gi
->m_rectIcon
.y
= m_gi
->m_rectAll
.y
+ 4;
540 if ( item
->HasText() )
542 if (m_gi
->m_rectAll
.width
> spacing
)
543 m_gi
->m_rectLabel
.x
= m_gi
->m_rectAll
.x
+ (EXTRA_WIDTH
/2);
545 m_gi
->m_rectLabel
.x
= m_gi
->m_rectAll
.x
+ (EXTRA_WIDTH
/2) + (spacing
/ 2) - (m_gi
->m_rectLabel
.width
/ 2);
546 m_gi
->m_rectLabel
.y
= m_gi
->m_rectAll
.y
+ m_gi
->m_rectAll
.height
+ 2 - m_gi
->m_rectLabel
.height
;
547 m_gi
->m_rectHighlight
.x
= m_gi
->m_rectLabel
.x
- 2;
548 m_gi
->m_rectHighlight
.y
= m_gi
->m_rectLabel
.y
- 2;
550 else // no text, highlight the icon
552 m_gi
->m_rectHighlight
.x
= m_gi
->m_rectIcon
.x
- 4;
553 m_gi
->m_rectHighlight
.y
= m_gi
->m_rectIcon
.y
- 4;
558 m_gi
->m_rectAll
.x
= x
;
559 m_gi
->m_rectAll
.y
= y
;
561 m_gi
->m_rectHighlight
.x
= m_gi
->m_rectAll
.x
;
562 m_gi
->m_rectHighlight
.y
= m_gi
->m_rectAll
.y
;
563 m_gi
->m_rectLabel
.y
= m_gi
->m_rectAll
.y
+ 2;
565 if (item
->HasImage())
567 m_gi
->m_rectIcon
.x
= m_gi
->m_rectAll
.x
+ 2;
568 m_gi
->m_rectIcon
.y
= m_gi
->m_rectAll
.y
+ 2;
569 m_gi
->m_rectLabel
.x
= m_gi
->m_rectAll
.x
+ 4 + (EXTRA_WIDTH
/2) + m_gi
->m_rectIcon
.width
;
573 m_gi
->m_rectLabel
.x
= m_gi
->m_rectAll
.x
+ (EXTRA_WIDTH
/2);
578 wxFAIL_MSG( wxT("unexpected call to SetPosition") );
582 wxFAIL_MSG( wxT("unknown mode") );
587 void wxListLineData::InitItems( int num
)
589 for (int i
= 0; i
< num
; i
++)
590 m_items
.Append( new wxListItemData(m_owner
) );
593 void wxListLineData::SetItem( int index
, const wxListItem
&info
)
595 wxListItemDataList::compatibility_iterator node
= m_items
.Item( index
);
596 wxCHECK_RET( node
, wxT("invalid column index in SetItem") );
598 wxListItemData
*item
= node
->GetData();
599 item
->SetItem( info
);
602 void wxListLineData::GetItem( int index
, wxListItem
&info
)
604 wxListItemDataList::compatibility_iterator node
= m_items
.Item( index
);
607 wxListItemData
*item
= node
->GetData();
608 item
->GetItem( info
);
612 wxString
wxListLineData::GetText(int index
) const
616 wxListItemDataList::compatibility_iterator node
= m_items
.Item( index
);
619 wxListItemData
*item
= node
->GetData();
626 void wxListLineData::SetText( int index
, const wxString
& s
)
628 wxListItemDataList::compatibility_iterator node
= m_items
.Item( index
);
631 wxListItemData
*item
= node
->GetData();
636 void wxListLineData::SetImage( int index
, int image
)
638 wxListItemDataList::compatibility_iterator node
= m_items
.Item( index
);
639 wxCHECK_RET( node
, wxT("invalid column index in SetImage()") );
641 wxListItemData
*item
= node
->GetData();
642 item
->SetImage(image
);
645 int wxListLineData::GetImage( int index
) const
647 wxListItemDataList::compatibility_iterator node
= m_items
.Item( index
);
648 wxCHECK_MSG( node
, -1, wxT("invalid column index in GetImage()") );
650 wxListItemData
*item
= node
->GetData();
651 return item
->GetImage();
654 wxListItemAttr
*wxListLineData::GetAttr() const
656 wxListItemDataList::compatibility_iterator node
= m_items
.GetFirst();
657 wxCHECK_MSG( node
, NULL
, wxT("invalid column index in GetAttr()") );
659 wxListItemData
*item
= node
->GetData();
660 return item
->GetAttr();
663 void wxListLineData::SetAttr(wxListItemAttr
*attr
)
665 wxListItemDataList::compatibility_iterator node
= m_items
.GetFirst();
666 wxCHECK_RET( node
, wxT("invalid column index in SetAttr()") );
668 wxListItemData
*item
= node
->GetData();
672 void wxListLineData::ApplyAttributes(wxDC
*dc
,
673 const wxRect
& rectHL
,
677 const wxListItemAttr
* const attr
= GetAttr();
679 wxWindow
* const listctrl
= m_owner
->GetParent();
681 const bool hasFocus
= listctrl
->HasFocus()
682 #if defined(__WXMAC__) && !defined(__WXUNIVERSAL__) && wxOSX_USE_CARBON
683 && IsControlActive( (ControlRef
)listctrl
->GetHandle() )
689 // don't use foreground colour for drawing highlighted items - this might
690 // make them completely invisible (and there is no way to do bit
691 // arithmetics on wxColour, unfortunately)
702 colText
= wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHTTEXT
);
704 colText
= wxSystemSettings::GetColour(wxSYS_COLOUR_LISTBOXHIGHLIGHTTEXT
);
707 else if ( attr
&& attr
->HasTextColour() )
708 colText
= attr
->GetTextColour();
710 colText
= listctrl
->GetForegroundColour();
712 dc
->SetTextForeground(colText
);
716 if ( attr
&& attr
->HasFont() )
717 font
= attr
->GetFont();
719 font
= listctrl
->GetFont();
726 // Use the renderer method to ensure that the selected items use the
728 int flags
= wxCONTROL_SELECTED
;
730 flags
|= wxCONTROL_FOCUSED
;
732 flags
|= wxCONTROL_CURRENT
;
733 wxRendererNative::Get().
734 DrawItemSelectionRect( m_owner
, *dc
, rectHL
, flags
);
736 else if ( attr
&& attr
->HasBackgroundColour() )
738 // Draw the background using the items custom background colour.
739 dc
->SetBrush(attr
->GetBackgroundColour());
740 dc
->SetPen(*wxTRANSPARENT_PEN
);
741 dc
->DrawRectangle(rectHL
);
744 // just for debugging to better see where the items are
746 dc
->SetPen(*wxRED_PEN
);
747 dc
->SetBrush(*wxTRANSPARENT_BRUSH
);
748 dc
->DrawRectangle( m_gi
->m_rectAll
);
749 dc
->SetPen(*wxGREEN_PEN
);
750 dc
->DrawRectangle( m_gi
->m_rectIcon
);
754 void wxListLineData::Draw(wxDC
*dc
, bool current
)
756 wxListItemDataList::compatibility_iterator node
= m_items
.GetFirst();
757 wxCHECK_RET( node
, wxT("no subitems at all??") );
759 ApplyAttributes(dc
, m_gi
->m_rectHighlight
, IsHighlighted(), current
);
761 wxListItemData
*item
= node
->GetData();
762 if (item
->HasImage())
764 // centre the image inside our rectangle, this looks nicer when items
765 // ae aligned in a row
766 const wxRect
& rectIcon
= m_gi
->m_rectIcon
;
768 m_owner
->DrawImage(item
->GetImage(), dc
, rectIcon
.x
, rectIcon
.y
);
773 const wxRect
& rectLabel
= m_gi
->m_rectLabel
;
775 wxDCClipper
clipper(*dc
, rectLabel
);
776 dc
->DrawText(item
->GetText(), rectLabel
.x
, rectLabel
.y
);
780 void wxListLineData::DrawInReportMode( wxDC
*dc
,
782 const wxRect
& rectHL
,
786 // TODO: later we should support setting different attributes for
787 // different columns - to do it, just add "col" argument to
788 // GetAttr() and move these lines into the loop below
790 ApplyAttributes(dc
, rectHL
, highlighted
, current
);
792 wxCoord x
= rect
.x
+ HEADER_OFFSET_X
,
793 yMid
= rect
.y
+ rect
.height
/2;
795 // This probably needs to be done
796 // on all platforms as the icons
797 // otherwise nearly touch the border
802 for ( wxListItemDataList::compatibility_iterator node
= m_items
.GetFirst();
804 node
= node
->GetNext(), col
++ )
806 wxListItemData
*item
= node
->GetData();
808 int width
= m_owner
->GetColumnWidth(col
);
813 const int wText
= width
;
814 wxDCClipper
clipper(*dc
, xOld
, rect
.y
, wText
, rect
.height
);
816 if ( item
->HasImage() )
819 m_owner
->GetImageSize( item
->GetImage(), ix
, iy
);
820 m_owner
->DrawImage( item
->GetImage(), dc
, xOld
, yMid
- iy
/2 );
822 ix
+= IMAGE_MARGIN_IN_REPORT_MODE
;
828 if ( item
->HasText() )
829 DrawTextFormatted(dc
, item
->GetText(), col
, xOld
, yMid
, width
);
833 void wxListLineData::DrawTextFormatted(wxDC
*dc
,
834 const wxString
& textOrig
,
840 // we don't support displaying multiple lines currently (and neither does
841 // wxMSW FWIW) so just merge all the lines
842 wxString
text(textOrig
);
843 text
.Replace(wxT("\n"), wxT(" "));
846 dc
->GetTextExtent(text
, &w
, &h
);
848 const wxCoord y
= yMid
- (h
+ 1)/2;
850 wxDCClipper
clipper(*dc
, x
, y
, width
, h
);
852 // determine if the string can fit inside the current width
855 // it can, draw it using the items alignment
857 m_owner
->GetColumn(col
, item
);
858 switch ( item
.GetAlign() )
860 case wxLIST_FORMAT_LEFT
:
864 case wxLIST_FORMAT_RIGHT
:
868 case wxLIST_FORMAT_CENTER
:
869 x
+= (width
- w
) / 2;
873 wxFAIL_MSG( wxT("unknown list item format") );
877 dc
->DrawText(text
, x
, y
);
879 else // otherwise, truncate and add an ellipsis if possible
881 // determine the base width
882 wxString
ellipsis(wxT("..."));
884 dc
->GetTextExtent(ellipsis
, &base_w
, &h
);
886 // continue until we have enough space or only one character left
888 size_t len
= text
.length();
889 wxString drawntext
= text
.Left(len
);
892 dc
->GetTextExtent(drawntext
.Last(), &w_c
, &h_c
);
893 drawntext
.RemoveLast();
896 if (w
+ base_w
<= width
)
900 // if still not enough space, remove ellipsis characters
901 while (ellipsis
.length() > 0 && w
+ base_w
> width
)
903 ellipsis
= ellipsis
.Left(ellipsis
.length() - 1);
904 dc
->GetTextExtent(ellipsis
, &base_w
, &h
);
908 dc
->DrawText(drawntext
, x
, y
);
909 dc
->DrawText(ellipsis
, x
+ w
, y
);
913 bool wxListLineData::Highlight( bool on
)
915 wxCHECK_MSG( !IsVirtual(), false, wxT("unexpected call to Highlight") );
917 if ( on
== m_highlighted
)
925 void wxListLineData::ReverseHighlight( void )
927 Highlight(!IsHighlighted());
930 //-----------------------------------------------------------------------------
931 // wxListHeaderWindow
932 //-----------------------------------------------------------------------------
934 BEGIN_EVENT_TABLE(wxListHeaderWindow
,wxWindow
)
935 EVT_PAINT (wxListHeaderWindow::OnPaint
)
936 EVT_MOUSE_EVENTS (wxListHeaderWindow::OnMouse
)
937 EVT_SET_FOCUS (wxListHeaderWindow::OnSetFocus
)
940 void wxListHeaderWindow::Init()
942 m_currentCursor
= NULL
;
943 m_isDragging
= false;
945 m_sendSetColumnWidth
= false;
948 wxListHeaderWindow::wxListHeaderWindow()
953 m_resizeCursor
= NULL
;
956 wxListHeaderWindow::wxListHeaderWindow( wxWindow
*win
,
958 wxListMainWindow
*owner
,
962 const wxString
&name
)
963 : wxWindow( win
, id
, pos
, size
, style
, name
)
968 m_resizeCursor
= new wxCursor( wxCURSOR_SIZEWE
);
971 wxVisualAttributes attr
= wxPanel::GetClassDefaultAttributes();
972 SetOwnForegroundColour( attr
.colFg
);
973 SetOwnBackgroundColour( attr
.colBg
);
975 SetOwnFont( attr
.font
);
977 SetOwnForegroundColour( wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT
));
978 SetOwnBackgroundColour( wxSystemSettings::GetColour(wxSYS_COLOUR_BTNFACE
));
980 SetOwnFont( wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT
));
984 wxListHeaderWindow::~wxListHeaderWindow()
986 delete m_resizeCursor
;
989 #ifdef __WXUNIVERSAL__
990 #include "wx/univ/renderer.h"
991 #include "wx/univ/theme.h"
994 // shift the DC origin to match the position of the main window horz
995 // scrollbar: this allows us to always use logical coords
996 void wxListHeaderWindow::AdjustDC(wxDC
& dc
)
998 wxGenericListCtrl
*parent
= m_owner
->GetListCtrl();
1001 parent
->GetScrollPixelsPerUnit( &xpix
, NULL
);
1004 parent
->GetViewStart( &view_start
, NULL
);
1009 dc
.GetDeviceOrigin( &org_x
, &org_y
);
1011 // account for the horz scrollbar offset
1013 if (GetLayoutDirection() == wxLayout_RightToLeft
)
1015 // Maybe we just have to check for m_signX
1016 // in the DC, but I leave the #ifdef __WXGTK__
1018 dc
.SetDeviceOrigin( org_x
+ (view_start
* xpix
), org_y
);
1022 dc
.SetDeviceOrigin( org_x
- (view_start
* xpix
), org_y
);
1025 void wxListHeaderWindow::OnPaint( wxPaintEvent
&WXUNUSED(event
) )
1027 wxGenericListCtrl
*parent
= m_owner
->GetListCtrl();
1029 wxPaintDC
dc( this );
1033 dc
.SetFont( GetFont() );
1035 // width and height of the entire header window
1037 GetClientSize( &w
, &h
);
1038 parent
->CalcUnscrolledPosition(w
, 0, &w
, NULL
);
1040 dc
.SetBackgroundMode(wxBRUSHSTYLE_TRANSPARENT
);
1041 dc
.SetTextForeground(GetForegroundColour());
1043 int x
= HEADER_OFFSET_X
;
1044 int numColumns
= m_owner
->GetColumnCount();
1046 for ( int i
= 0; i
< numColumns
&& x
< w
; i
++ )
1048 m_owner
->GetColumn( i
, item
);
1049 int wCol
= item
.m_width
;
1055 if (!m_parent
->IsEnabled())
1056 flags
|= wxCONTROL_DISABLED
;
1058 // NB: The code below is not really Mac-specific, but since we are close
1059 // to 2.8 release and I don't have time to test on other platforms, I
1060 // defined this only for wxMac. If this behaviour is desired on
1061 // other platforms, please go ahead and revise or remove the #ifdef.
1063 if ( !m_owner
->IsVirtual() && (item
.m_mask
& wxLIST_MASK_STATE
) &&
1064 (item
.m_state
& wxLIST_STATE_SELECTED
) )
1065 flags
|= wxCONTROL_SELECTED
;
1069 flags
|= wxCONTROL_SPECIAL
; // mark as first column
1071 wxRendererNative::Get().DrawHeaderButton
1075 wxRect(x
, HEADER_OFFSET_Y
, cw
, ch
),
1079 // see if we have enough space for the column label
1081 // for this we need the width of the text
1084 dc
.GetTextExtent(item
.GetText(), &wLabel
, &hLabel
);
1085 wLabel
+= 2 * EXTRA_WIDTH
;
1087 // and the width of the icon, if any
1088 int ix
= 0, iy
= 0; // init them just to suppress the compiler warnings
1089 const int image
= item
.m_image
;
1090 wxImageList
*imageList
;
1093 imageList
= m_owner
->GetSmallImageList();
1096 imageList
->GetSize(image
, ix
, iy
);
1097 wLabel
+= ix
+ HEADER_IMAGE_MARGIN_IN_REPORT_MODE
;
1105 // ignore alignment if there is not enough space anyhow
1107 switch ( wLabel
< cw
? item
.GetAlign() : wxLIST_FORMAT_LEFT
)
1110 wxFAIL_MSG( wxT("unknown list item format") );
1113 case wxLIST_FORMAT_LEFT
:
1117 case wxLIST_FORMAT_RIGHT
:
1118 xAligned
= x
+ cw
- wLabel
;
1121 case wxLIST_FORMAT_CENTER
:
1122 xAligned
= x
+ (cw
- wLabel
) / 2;
1126 // draw the text and image clipping them so that they
1127 // don't overwrite the column boundary
1128 wxDCClipper
clipper(dc
, x
, HEADER_OFFSET_Y
, cw
, h
);
1130 // if we have an image, draw it on the right of the label
1137 xAligned
+ wLabel
- ix
- HEADER_IMAGE_MARGIN_IN_REPORT_MODE
,
1138 HEADER_OFFSET_Y
+ (h
- iy
)/2,
1139 wxIMAGELIST_DRAW_TRANSPARENT
1143 dc
.DrawText( item
.GetText(),
1144 xAligned
+ EXTRA_WIDTH
, (h
- hLabel
) / 2 );
1149 // Fill in what's missing to the right of the columns, otherwise we will
1150 // leave an unpainted area when columns are removed (and it looks better)
1153 wxRendererNative::Get().DrawHeaderButton
1157 wxRect(x
, HEADER_OFFSET_Y
, w
- x
, h
),
1158 wxCONTROL_DIRTY
// mark as last column
1163 void wxListHeaderWindow::OnInternalIdle()
1165 wxWindow::OnInternalIdle();
1167 if (m_sendSetColumnWidth
)
1169 m_owner
->SetColumnWidth( m_colToSend
, m_widthToSend
);
1170 m_sendSetColumnWidth
= false;
1174 void wxListHeaderWindow::DrawCurrent()
1177 // m_owner->SetColumnWidth( m_column, m_currentX - m_minX );
1178 m_sendSetColumnWidth
= true;
1179 m_colToSend
= m_column
;
1180 m_widthToSend
= m_currentX
- m_minX
;
1182 int x1
= m_currentX
;
1184 m_owner
->ClientToScreen( &x1
, &y1
);
1186 int x2
= m_currentX
;
1188 m_owner
->GetClientSize( NULL
, &y2
);
1189 m_owner
->ClientToScreen( &x2
, &y2
);
1192 dc
.SetLogicalFunction( wxINVERT
);
1193 dc
.SetPen( wxPen(*wxBLACK
, 2) );
1194 dc
.SetBrush( *wxTRANSPARENT_BRUSH
);
1198 dc
.DrawLine( x1
, y1
, x2
, y2
);
1200 dc
.SetLogicalFunction( wxCOPY
);
1202 dc
.SetPen( wxNullPen
);
1203 dc
.SetBrush( wxNullBrush
);
1207 void wxListHeaderWindow::OnMouse( wxMouseEvent
&event
)
1209 wxGenericListCtrl
*parent
= m_owner
->GetListCtrl();
1211 // we want to work with logical coords
1213 parent
->CalcUnscrolledPosition(event
.GetX(), 0, &x
, NULL
);
1214 int y
= event
.GetY();
1218 SendListEvent(wxEVT_COMMAND_LIST_COL_DRAGGING
, event
.GetPosition());
1220 // we don't draw the line beyond our window, but we allow dragging it
1223 GetClientSize( &w
, NULL
);
1224 parent
->CalcUnscrolledPosition(w
, 0, &w
, NULL
);
1227 // erase the line if it was drawn
1228 if ( m_currentX
< w
)
1231 if (event
.ButtonUp())
1234 m_isDragging
= false;
1236 m_owner
->SetColumnWidth( m_column
, m_currentX
- m_minX
);
1237 SendListEvent(wxEVT_COMMAND_LIST_COL_END_DRAG
, event
.GetPosition());
1244 m_currentX
= m_minX
+ 7;
1246 // draw in the new location
1247 if ( m_currentX
< w
)
1251 else // not dragging
1254 bool hit_border
= false;
1256 // end of the current column
1259 // find the column where this event occurred
1261 countCol
= m_owner
->GetColumnCount();
1262 for (col
= 0; col
< countCol
; col
++)
1264 xpos
+= m_owner
->GetColumnWidth( col
);
1267 if ( (abs(x
-xpos
) < 3) && (y
< 22) )
1269 // near the column border
1276 // inside the column
1283 if ( col
== countCol
)
1286 if (event
.LeftDown() || event
.RightUp())
1288 if (hit_border
&& event
.LeftDown())
1290 if ( SendListEvent(wxEVT_COMMAND_LIST_COL_BEGIN_DRAG
,
1291 event
.GetPosition()) )
1293 m_isDragging
= true;
1298 //else: column resizing was vetoed by the user code
1300 else // click on a column
1302 // record the selected state of the columns
1303 if (event
.LeftDown())
1305 for (int i
=0; i
< m_owner
->GetColumnCount(); i
++)
1308 m_owner
->GetColumn(i
, colItem
);
1309 long state
= colItem
.GetState();
1311 colItem
.SetState(state
| wxLIST_STATE_SELECTED
);
1313 colItem
.SetState(state
& ~wxLIST_STATE_SELECTED
);
1314 m_owner
->SetColumn(i
, colItem
);
1318 SendListEvent( event
.LeftDown()
1319 ? wxEVT_COMMAND_LIST_COL_CLICK
1320 : wxEVT_COMMAND_LIST_COL_RIGHT_CLICK
,
1321 event
.GetPosition());
1324 else if (event
.Moving())
1329 setCursor
= m_currentCursor
== wxSTANDARD_CURSOR
;
1330 m_currentCursor
= m_resizeCursor
;
1334 setCursor
= m_currentCursor
!= wxSTANDARD_CURSOR
;
1335 m_currentCursor
= wxSTANDARD_CURSOR
;
1339 SetCursor(*m_currentCursor
);
1344 void wxListHeaderWindow::OnSetFocus( wxFocusEvent
&WXUNUSED(event
) )
1346 m_owner
->SetFocus();
1350 bool wxListHeaderWindow::SendListEvent(wxEventType type
, const wxPoint
& pos
)
1352 wxWindow
*parent
= GetParent();
1353 wxListEvent
le( type
, parent
->GetId() );
1354 le
.SetEventObject( parent
);
1355 le
.m_pointDrag
= pos
;
1357 // the position should be relative to the parent window, not
1358 // this one for compatibility with MSW and common sense: the
1359 // user code doesn't know anything at all about this header
1360 // window, so why should it get positions relative to it?
1361 le
.m_pointDrag
.y
-= GetSize().y
;
1363 le
.m_col
= m_column
;
1364 return !parent
->GetEventHandler()->ProcessEvent( le
) || le
.IsAllowed();
1367 //-----------------------------------------------------------------------------
1368 // wxListRenameTimer (internal)
1369 //-----------------------------------------------------------------------------
1371 wxListRenameTimer::wxListRenameTimer( wxListMainWindow
*owner
)
1376 void wxListRenameTimer::Notify()
1378 m_owner
->OnRenameTimer();
1381 //-----------------------------------------------------------------------------
1382 // wxListTextCtrlWrapper (internal)
1383 //-----------------------------------------------------------------------------
1385 BEGIN_EVENT_TABLE(wxListTextCtrlWrapper
, wxEvtHandler
)
1386 EVT_CHAR (wxListTextCtrlWrapper::OnChar
)
1387 EVT_KEY_UP (wxListTextCtrlWrapper::OnKeyUp
)
1388 EVT_KILL_FOCUS (wxListTextCtrlWrapper::OnKillFocus
)
1391 wxListTextCtrlWrapper::wxListTextCtrlWrapper(wxListMainWindow
*owner
,
1394 : m_startValue(owner
->GetItemText(itemEdit
)),
1395 m_itemEdited(itemEdit
)
1399 m_aboutToFinish
= false;
1401 wxGenericListCtrl
*parent
= m_owner
->GetListCtrl();
1403 wxRect rectLabel
= owner
->GetLineLabelRect(itemEdit
);
1405 parent
->CalcScrolledPosition(rectLabel
.x
, rectLabel
.y
,
1406 &rectLabel
.x
, &rectLabel
.y
);
1408 m_text
->Create(owner
, wxID_ANY
, m_startValue
,
1409 wxPoint(rectLabel
.x
-4,rectLabel
.y
-4),
1410 wxSize(rectLabel
.width
+11,rectLabel
.height
+8));
1413 m_text
->PushEventHandler(this);
1416 void wxListTextCtrlWrapper::EndEdit(EndReason reason
)
1418 m_aboutToFinish
= true;
1423 // Notify the owner about the changes
1426 // Even if vetoed, close the control (consistent with MSW)
1431 m_owner
->OnRenameCancelled(m_itemEdited
);
1437 // Don't generate any notifications for the control being destroyed
1438 // and don't set focus to it neither.
1444 void wxListTextCtrlWrapper::Finish( bool setfocus
)
1446 m_text
->RemoveEventHandler(this);
1447 m_owner
->ResetTextControl( m_text
);
1449 wxPendingDelete
.Append( this );
1452 m_owner
->SetFocus();
1455 bool wxListTextCtrlWrapper::AcceptChanges()
1457 const wxString value
= m_text
->GetValue();
1459 // notice that we should always call OnRenameAccept() to generate the "end
1460 // label editing" event, even if the user hasn't really changed anything
1461 if ( !m_owner
->OnRenameAccept(m_itemEdited
, value
) )
1463 // vetoed by the user
1467 // accepted, do rename the item (unless nothing changed)
1468 if ( value
!= m_startValue
)
1469 m_owner
->SetItemText(m_itemEdited
, value
);
1474 void wxListTextCtrlWrapper::OnChar( wxKeyEvent
&event
)
1476 if ( !CheckForEndEditKey(event
) )
1480 bool wxListTextCtrlWrapper::CheckForEndEditKey(const wxKeyEvent
& event
)
1482 switch ( event
.m_keyCode
)
1485 EndEdit( End_Accept
);
1489 EndEdit( End_Discard
);
1499 void wxListTextCtrlWrapper::OnKeyUp( wxKeyEvent
&event
)
1501 if (m_aboutToFinish
)
1503 // auto-grow the textctrl:
1504 wxSize parentSize
= m_owner
->GetSize();
1505 wxPoint myPos
= m_text
->GetPosition();
1506 wxSize mySize
= m_text
->GetSize();
1508 m_text
->GetTextExtent(m_text
->GetValue() + wxT("MM"), &sx
, &sy
);
1509 if (myPos
.x
+ sx
> parentSize
.x
)
1510 sx
= parentSize
.x
- myPos
.x
;
1513 m_text
->SetSize(sx
, wxDefaultCoord
);
1519 void wxListTextCtrlWrapper::OnKillFocus( wxFocusEvent
&event
)
1521 if ( !m_aboutToFinish
)
1523 if ( !AcceptChanges() )
1524 m_owner
->OnRenameCancelled( m_itemEdited
);
1529 // We must let the native text control handle focus
1533 //-----------------------------------------------------------------------------
1535 //-----------------------------------------------------------------------------
1537 BEGIN_EVENT_TABLE(wxListMainWindow
, wxWindow
)
1538 EVT_PAINT (wxListMainWindow::OnPaint
)
1539 EVT_MOUSE_EVENTS (wxListMainWindow::OnMouse
)
1540 EVT_CHAR_HOOK (wxListMainWindow::OnCharHook
)
1541 EVT_CHAR (wxListMainWindow::OnChar
)
1542 EVT_KEY_DOWN (wxListMainWindow::OnKeyDown
)
1543 EVT_KEY_UP (wxListMainWindow::OnKeyUp
)
1544 EVT_SET_FOCUS (wxListMainWindow::OnSetFocus
)
1545 EVT_KILL_FOCUS (wxListMainWindow::OnKillFocus
)
1546 EVT_SCROLLWIN (wxListMainWindow::OnScroll
)
1547 EVT_CHILD_FOCUS (wxListMainWindow::OnChildFocus
)
1550 void wxListMainWindow::Init()
1555 m_lineTo
= (size_t)-1;
1561 m_small_image_list
= NULL
;
1562 m_normal_image_list
= NULL
;
1564 m_small_spacing
= 30;
1565 m_normal_spacing
= 40;
1569 m_isCreated
= false;
1571 m_lastOnSame
= false;
1572 m_renameTimer
= new wxListRenameTimer( this );
1573 m_textctrlWrapper
= NULL
;
1577 m_lineSelectSingleOnUp
=
1578 m_lineBeforeLastClicked
= (size_t)-1;
1581 wxListMainWindow::wxListMainWindow()
1586 m_highlightUnfocusedBrush
= NULL
;
1589 wxListMainWindow::wxListMainWindow( wxWindow
*parent
,
1594 const wxString
&name
)
1595 : wxWindow( parent
, id
, pos
, size
, style
, name
)
1599 m_highlightBrush
= new wxBrush
1601 wxSystemSettings::GetColour
1603 wxSYS_COLOUR_HIGHLIGHT
1608 m_highlightUnfocusedBrush
= new wxBrush
1610 wxSystemSettings::GetColour
1612 wxSYS_COLOUR_BTNSHADOW
1617 wxVisualAttributes attr
= wxGenericListCtrl::GetClassDefaultAttributes();
1618 SetOwnForegroundColour( attr
.colFg
);
1619 SetOwnBackgroundColour( attr
.colBg
);
1621 SetOwnFont( attr
.font
);
1624 wxListMainWindow::~wxListMainWindow()
1626 if ( m_textctrlWrapper
)
1627 m_textctrlWrapper
->EndEdit(wxListTextCtrlWrapper::End_Destroy
);
1630 WX_CLEAR_LIST(wxListHeaderDataList
, m_columns
);
1631 WX_CLEAR_ARRAY(m_aColWidths
);
1633 delete m_highlightBrush
;
1634 delete m_highlightUnfocusedBrush
;
1635 delete m_renameTimer
;
1638 void wxListMainWindow::SetReportView(bool inReportView
)
1640 const size_t count
= m_lines
.size();
1641 for ( size_t n
= 0; n
< count
; n
++ )
1643 m_lines
[n
].SetReportView(inReportView
);
1647 void wxListMainWindow::CacheLineData(size_t line
)
1649 wxGenericListCtrl
*listctrl
= GetListCtrl();
1651 wxListLineData
*ld
= GetDummyLine();
1653 size_t countCol
= GetColumnCount();
1654 for ( size_t col
= 0; col
< countCol
; col
++ )
1656 ld
->SetText(col
, listctrl
->OnGetItemText(line
, col
));
1657 ld
->SetImage(col
, listctrl
->OnGetItemColumnImage(line
, col
));
1660 ld
->SetAttr(listctrl
->OnGetItemAttr(line
));
1663 wxListLineData
*wxListMainWindow::GetDummyLine() const
1665 wxASSERT_MSG( !IsEmpty(), wxT("invalid line index") );
1666 wxASSERT_MSG( IsVirtual(), wxT("GetDummyLine() shouldn't be called") );
1668 wxListMainWindow
*self
= wxConstCast(this, wxListMainWindow
);
1670 // we need to recreate the dummy line if the number of columns in the
1671 // control changed as it would have the incorrect number of fields
1673 if ( !m_lines
.IsEmpty() &&
1674 m_lines
[0].m_items
.GetCount() != (size_t)GetColumnCount() )
1676 self
->m_lines
.Clear();
1679 if ( m_lines
.IsEmpty() )
1681 wxListLineData
*line
= new wxListLineData(self
);
1682 self
->m_lines
.Add(line
);
1684 // don't waste extra memory -- there never going to be anything
1685 // else/more in this array
1686 self
->m_lines
.Shrink();
1692 // ----------------------------------------------------------------------------
1693 // line geometry (report mode only)
1694 // ----------------------------------------------------------------------------
1696 wxCoord
wxListMainWindow::GetLineHeight() const
1698 // we cache the line height as calling GetTextExtent() is slow
1699 if ( !m_lineHeight
)
1701 wxListMainWindow
*self
= wxConstCast(this, wxListMainWindow
);
1703 wxClientDC
dc( self
);
1704 dc
.SetFont( GetFont() );
1707 dc
.GetTextExtent(wxT("H"), NULL
, &y
);
1709 if ( m_small_image_list
&& m_small_image_list
->GetImageCount() )
1712 m_small_image_list
->GetSize(0, iw
, ih
);
1717 self
->m_lineHeight
= y
+ LINE_SPACING
;
1720 return m_lineHeight
;
1723 wxCoord
wxListMainWindow::GetLineY(size_t line
) const
1725 wxASSERT_MSG( InReportView(), wxT("only works in report mode") );
1727 return LINE_SPACING
+ line
* GetLineHeight();
1730 wxRect
wxListMainWindow::GetLineRect(size_t line
) const
1732 if ( !InReportView() )
1733 return GetLine(line
)->m_gi
->m_rectAll
;
1736 rect
.x
= HEADER_OFFSET_X
;
1737 rect
.y
= GetLineY(line
);
1738 rect
.width
= GetHeaderWidth();
1739 rect
.height
= GetLineHeight();
1744 wxRect
wxListMainWindow::GetLineLabelRect(size_t line
) const
1746 if ( !InReportView() )
1747 return GetLine(line
)->m_gi
->m_rectLabel
;
1750 wxListLineData
*data
= GetLine(line
);
1751 wxListItemDataList::compatibility_iterator node
= data
->m_items
.GetFirst();
1754 wxListItemData
*item
= node
->GetData();
1755 if ( item
->HasImage() )
1758 GetImageSize( item
->GetImage(), ix
, iy
);
1759 image_x
= 3 + ix
+ IMAGE_MARGIN_IN_REPORT_MODE
;
1764 rect
.x
= image_x
+ HEADER_OFFSET_X
;
1765 rect
.y
= GetLineY(line
);
1766 rect
.width
= GetColumnWidth(0) - image_x
;
1767 rect
.height
= GetLineHeight();
1772 wxRect
wxListMainWindow::GetLineIconRect(size_t line
) const
1774 if ( !InReportView() )
1775 return GetLine(line
)->m_gi
->m_rectIcon
;
1777 wxListLineData
*ld
= GetLine(line
);
1778 wxASSERT_MSG( ld
->HasImage(), wxT("should have an image") );
1781 rect
.x
= HEADER_OFFSET_X
;
1782 rect
.y
= GetLineY(line
);
1783 GetImageSize(ld
->GetImage(), rect
.width
, rect
.height
);
1788 wxRect
wxListMainWindow::GetLineHighlightRect(size_t line
) const
1790 return InReportView() ? GetLineRect(line
)
1791 : GetLine(line
)->m_gi
->m_rectHighlight
;
1794 long wxListMainWindow::HitTestLine(size_t line
, int x
, int y
) const
1796 wxASSERT_MSG( line
< GetItemCount(), wxT("invalid line in HitTestLine") );
1798 wxListLineData
*ld
= GetLine(line
);
1800 if ( ld
->HasImage() && GetLineIconRect(line
).Contains(x
, y
) )
1801 return wxLIST_HITTEST_ONITEMICON
;
1803 // VS: Testing for "ld->HasText() || InReportView()" instead of
1804 // "ld->HasText()" is needed to make empty lines in report view
1806 if ( ld
->HasText() || InReportView() )
1808 wxRect rect
= InReportView() ? GetLineRect(line
)
1809 : GetLineLabelRect(line
);
1811 if ( rect
.Contains(x
, y
) )
1812 return wxLIST_HITTEST_ONITEMLABEL
;
1818 // ----------------------------------------------------------------------------
1819 // highlight (selection) handling
1820 // ----------------------------------------------------------------------------
1822 bool wxListMainWindow::IsHighlighted(size_t line
) const
1826 return m_selStore
.IsSelected(line
);
1830 wxListLineData
*ld
= GetLine(line
);
1831 wxCHECK_MSG( ld
, false, wxT("invalid index in IsHighlighted") );
1833 return ld
->IsHighlighted();
1837 void wxListMainWindow::HighlightLines( size_t lineFrom
,
1843 wxArrayInt linesChanged
;
1844 if ( !m_selStore
.SelectRange(lineFrom
, lineTo
, highlight
,
1847 // meny items changed state, refresh everything
1848 RefreshLines(lineFrom
, lineTo
);
1850 else // only a few items changed state, refresh only them
1852 size_t count
= linesChanged
.GetCount();
1853 for ( size_t n
= 0; n
< count
; n
++ )
1855 RefreshLine(linesChanged
[n
]);
1859 else // iterate over all items in non report view
1861 for ( size_t line
= lineFrom
; line
<= lineTo
; line
++ )
1863 if ( HighlightLine(line
, highlight
) )
1869 bool wxListMainWindow::HighlightLine( size_t line
, bool highlight
)
1875 changed
= m_selStore
.SelectItem(line
, highlight
);
1879 wxListLineData
*ld
= GetLine(line
);
1880 wxCHECK_MSG( ld
, false, wxT("invalid index in HighlightLine") );
1882 changed
= ld
->Highlight(highlight
);
1887 SendNotify( line
, highlight
? wxEVT_COMMAND_LIST_ITEM_SELECTED
1888 : wxEVT_COMMAND_LIST_ITEM_DESELECTED
);
1894 void wxListMainWindow::RefreshLine( size_t line
)
1896 if ( InReportView() )
1898 size_t visibleFrom
, visibleTo
;
1899 GetVisibleLinesRange(&visibleFrom
, &visibleTo
);
1901 if ( line
< visibleFrom
|| line
> visibleTo
)
1905 wxRect rect
= GetLineRect(line
);
1907 GetListCtrl()->CalcScrolledPosition( rect
.x
, rect
.y
, &rect
.x
, &rect
.y
);
1908 RefreshRect( rect
);
1911 void wxListMainWindow::RefreshLines( size_t lineFrom
, size_t lineTo
)
1913 // we suppose that they are ordered by caller
1914 wxASSERT_MSG( lineFrom
<= lineTo
, wxT("indices in disorder") );
1916 wxASSERT_MSG( lineTo
< GetItemCount(), wxT("invalid line range") );
1918 if ( InReportView() )
1920 size_t visibleFrom
, visibleTo
;
1921 GetVisibleLinesRange(&visibleFrom
, &visibleTo
);
1923 if ( lineFrom
< visibleFrom
)
1924 lineFrom
= visibleFrom
;
1925 if ( lineTo
> visibleTo
)
1930 rect
.y
= GetLineY(lineFrom
);
1931 rect
.width
= GetClientSize().x
;
1932 rect
.height
= GetLineY(lineTo
) - rect
.y
+ GetLineHeight();
1934 GetListCtrl()->CalcScrolledPosition( rect
.x
, rect
.y
, &rect
.x
, &rect
.y
);
1935 RefreshRect( rect
);
1939 // TODO: this should be optimized...
1940 for ( size_t line
= lineFrom
; line
<= lineTo
; line
++ )
1947 void wxListMainWindow::RefreshAfter( size_t lineFrom
)
1949 if ( InReportView() )
1951 size_t visibleFrom
, visibleTo
;
1952 GetVisibleLinesRange(&visibleFrom
, &visibleTo
);
1954 if ( lineFrom
< visibleFrom
)
1955 lineFrom
= visibleFrom
;
1956 else if ( lineFrom
> visibleTo
)
1961 rect
.y
= GetLineY(lineFrom
);
1962 GetListCtrl()->CalcScrolledPosition( rect
.x
, rect
.y
, &rect
.x
, &rect
.y
);
1964 wxSize size
= GetClientSize();
1965 rect
.width
= size
.x
;
1967 // refresh till the bottom of the window
1968 rect
.height
= size
.y
- rect
.y
;
1970 RefreshRect( rect
);
1974 // TODO: how to do it more efficiently?
1979 void wxListMainWindow::RefreshSelected()
1985 if ( InReportView() )
1987 GetVisibleLinesRange(&from
, &to
);
1992 to
= GetItemCount() - 1;
1995 if ( HasCurrent() && m_current
>= from
&& m_current
<= to
)
1996 RefreshLine(m_current
);
1998 for ( size_t line
= from
; line
<= to
; line
++ )
2000 // NB: the test works as expected even if m_current == -1
2001 if ( line
!= m_current
&& IsHighlighted(line
) )
2006 void wxListMainWindow::OnPaint( wxPaintEvent
&WXUNUSED(event
) )
2008 // Note: a wxPaintDC must be constructed even if no drawing is
2009 // done (a Windows requirement).
2010 wxPaintDC
dc( this );
2014 // nothing to draw or not the moment to draw it
2019 RecalculatePositions( false );
2021 GetListCtrl()->PrepareDC( dc
);
2024 GetListCtrl()->CalcScrolledPosition( 0, 0, &dev_x
, &dev_y
);
2026 dc
.SetFont( GetFont() );
2028 if ( InReportView() )
2030 int lineHeight
= GetLineHeight();
2032 size_t visibleFrom
, visibleTo
;
2033 GetVisibleLinesRange(&visibleFrom
, &visibleTo
);
2036 int xOrig
= dc
.LogicalToDeviceX( 0 );
2037 int yOrig
= dc
.LogicalToDeviceY( 0 );
2039 // tell the caller cache to cache the data
2042 wxListEvent
evCache(wxEVT_COMMAND_LIST_CACHE_HINT
,
2043 GetParent()->GetId());
2044 evCache
.SetEventObject( GetParent() );
2045 evCache
.m_oldItemIndex
= visibleFrom
;
2046 evCache
.m_item
.m_itemId
=
2047 evCache
.m_itemIndex
= visibleTo
;
2048 GetParent()->GetEventHandler()->ProcessEvent( evCache
);
2051 for ( size_t line
= visibleFrom
; line
<= visibleTo
; line
++ )
2053 rectLine
= GetLineRect(line
);
2056 if ( !IsExposed(rectLine
.x
+ xOrig
, rectLine
.y
+ yOrig
,
2057 rectLine
.width
, rectLine
.height
) )
2059 // don't redraw unaffected lines to avoid flicker
2063 GetLine(line
)->DrawInReportMode( &dc
,
2065 GetLineHighlightRect(line
),
2066 IsHighlighted(line
),
2067 line
== m_current
);
2070 if ( HasFlag(wxLC_HRULES
) )
2072 wxPen
pen(GetRuleColour(), 1, wxPENSTYLE_SOLID
);
2073 wxSize clientSize
= GetClientSize();
2075 size_t i
= visibleFrom
;
2076 if (i
== 0) i
= 1; // Don't draw the first one
2077 for ( ; i
<= visibleTo
; i
++ )
2080 dc
.SetBrush( *wxTRANSPARENT_BRUSH
);
2081 dc
.DrawLine(0 - dev_x
, i
* lineHeight
,
2082 clientSize
.x
- dev_x
, i
* lineHeight
);
2085 // Draw last horizontal rule
2086 if ( visibleTo
== GetItemCount() - 1 )
2089 dc
.SetBrush( *wxTRANSPARENT_BRUSH
);
2090 dc
.DrawLine(0 - dev_x
, (m_lineTo
+ 1) * lineHeight
,
2091 clientSize
.x
- dev_x
, (m_lineTo
+ 1) * lineHeight
);
2095 // Draw vertical rules if required
2096 if ( HasFlag(wxLC_VRULES
) && !IsEmpty() )
2098 wxPen
pen(GetRuleColour(), 1, wxPENSTYLE_SOLID
);
2099 wxRect firstItemRect
, lastItemRect
;
2101 GetItemRect(visibleFrom
, firstItemRect
);
2102 GetItemRect(visibleTo
, lastItemRect
);
2103 int x
= firstItemRect
.GetX();
2105 dc
.SetBrush(* wxTRANSPARENT_BRUSH
);
2107 for (int col
= 0; col
< GetColumnCount(); col
++)
2109 int colWidth
= GetColumnWidth(col
);
2111 int x_pos
= x
- dev_x
;
2112 if (col
< GetColumnCount()-1) x_pos
-= 2;
2113 dc
.DrawLine(x_pos
, firstItemRect
.GetY() - 1 - dev_y
,
2114 x_pos
, lastItemRect
.GetBottom() + 1 - dev_y
);
2120 size_t count
= GetItemCount();
2121 for ( size_t i
= 0; i
< count
; i
++ )
2123 GetLine(i
)->Draw( &dc
, i
== m_current
);
2127 // DrawFocusRect() is unusable under Mac, it draws outside of the highlight
2128 // rectangle somehow and so leaves traces when the item is not selected any
2129 // more, see #12229.
2134 if ( IsHighlighted(m_current
) )
2135 flags
|= wxCONTROL_SELECTED
;
2137 wxRendererNative::Get().
2138 DrawFocusRect(this, dc
, GetLineHighlightRect(m_current
), flags
);
2140 #endif // !__WXMAC__
2143 void wxListMainWindow::HighlightAll( bool on
)
2145 if ( IsSingleSel() )
2147 wxASSERT_MSG( !on
, wxT("can't do this in a single selection control") );
2149 // we just have one item to turn off
2150 if ( HasCurrent() && IsHighlighted(m_current
) )
2152 HighlightLine(m_current
, false);
2153 RefreshLine(m_current
);
2156 else // multi selection
2159 HighlightLines(0, GetItemCount() - 1, on
);
2163 void wxListMainWindow::OnChildFocus(wxChildFocusEvent
& WXUNUSED(event
))
2165 // Do nothing here. This prevents the default handler in wxScrolledWindow
2166 // from needlessly scrolling the window when the edit control is
2167 // dismissed. See ticket #9563.
2170 void wxListMainWindow::SendNotify( size_t line
,
2171 wxEventType command
,
2172 const wxPoint
& point
)
2174 wxListEvent
le( command
, GetParent()->GetId() );
2175 le
.SetEventObject( GetParent() );
2177 le
.m_item
.m_itemId
=
2178 le
.m_itemIndex
= line
;
2180 // set only for events which have position
2181 if ( point
!= wxDefaultPosition
)
2182 le
.m_pointDrag
= point
;
2184 // don't try to get the line info for virtual list controls: the main
2185 // program has it anyhow and if we did it would result in accessing all
2186 // the lines, even those which are not visible now and this is precisely
2187 // what we're trying to avoid
2190 if ( line
!= (size_t)-1 )
2192 GetLine(line
)->GetItem( 0, le
.m_item
);
2194 //else: this happens for wxEVT_COMMAND_LIST_ITEM_FOCUSED event
2196 //else: there may be no more such item
2198 GetParent()->GetEventHandler()->ProcessEvent( le
);
2201 void wxListMainWindow::ChangeCurrent(size_t current
)
2203 m_current
= current
;
2205 // as the current item changed, we shouldn't start editing it when the
2206 // "slow click" timer expires as the click happened on another item
2207 if ( m_renameTimer
->IsRunning() )
2208 m_renameTimer
->Stop();
2210 SendNotify(current
, wxEVT_COMMAND_LIST_ITEM_FOCUSED
);
2213 wxTextCtrl
*wxListMainWindow::EditLabel(long item
, wxClassInfo
* textControlClass
)
2215 wxCHECK_MSG( (item
>= 0) && ((size_t)item
< GetItemCount()), NULL
,
2216 wxT("wrong index in wxGenericListCtrl::EditLabel()") );
2218 wxASSERT_MSG( textControlClass
->IsKindOf(CLASSINFO(wxTextCtrl
)),
2219 wxT("EditLabel() needs a text control") );
2221 size_t itemEdit
= (size_t)item
;
2223 wxListEvent
le( wxEVT_COMMAND_LIST_BEGIN_LABEL_EDIT
, GetParent()->GetId() );
2224 le
.SetEventObject( GetParent() );
2225 le
.m_item
.m_itemId
=
2226 le
.m_itemIndex
= item
;
2227 wxListLineData
*data
= GetLine(itemEdit
);
2228 wxCHECK_MSG( data
, NULL
, wxT("invalid index in EditLabel()") );
2229 data
->GetItem( 0, le
.m_item
);
2231 if ( GetParent()->GetEventHandler()->ProcessEvent( le
) && !le
.IsAllowed() )
2233 // vetoed by user code
2237 // We have to call this here because the label in question might just have
2238 // been added and no screen update taken place.
2241 // TODO: use wxTheApp->SafeYieldFor(NULL, wxEVT_CATEGORY_UI) instead
2242 // so that no pending events may change the item count (see below)
2243 // IMPORTANT: needs to be tested!
2246 // Pending events dispatched by wxSafeYield might have changed the item
2248 if ( (size_t)item
>= GetItemCount() )
2252 wxTextCtrl
* const text
= (wxTextCtrl
*)textControlClass
->CreateObject();
2253 m_textctrlWrapper
= new wxListTextCtrlWrapper(this, text
, item
);
2254 return m_textctrlWrapper
->GetText();
2257 void wxListMainWindow::OnRenameTimer()
2259 wxCHECK_RET( HasCurrent(), wxT("unexpected rename timer") );
2261 EditLabel( m_current
);
2264 bool wxListMainWindow::OnRenameAccept(size_t itemEdit
, const wxString
& value
)
2266 wxListEvent
le( wxEVT_COMMAND_LIST_END_LABEL_EDIT
, GetParent()->GetId() );
2267 le
.SetEventObject( GetParent() );
2268 le
.m_item
.m_itemId
=
2269 le
.m_itemIndex
= itemEdit
;
2271 wxListLineData
*data
= GetLine(itemEdit
);
2273 wxCHECK_MSG( data
, false, wxT("invalid index in OnRenameAccept()") );
2275 data
->GetItem( 0, le
.m_item
);
2276 le
.m_item
.m_text
= value
;
2277 return !GetParent()->GetEventHandler()->ProcessEvent( le
) ||
2281 void wxListMainWindow::OnRenameCancelled(size_t itemEdit
)
2283 // let owner know that the edit was cancelled
2284 wxListEvent
le( wxEVT_COMMAND_LIST_END_LABEL_EDIT
, GetParent()->GetId() );
2286 le
.SetEditCanceled(true);
2288 le
.SetEventObject( GetParent() );
2289 le
.m_item
.m_itemId
=
2290 le
.m_itemIndex
= itemEdit
;
2292 wxListLineData
*data
= GetLine(itemEdit
);
2293 wxCHECK_RET( data
, wxT("invalid index in OnRenameCancelled()") );
2295 data
->GetItem( 0, le
.m_item
);
2296 GetEventHandler()->ProcessEvent( le
);
2299 void wxListMainWindow::OnMouse( wxMouseEvent
&event
)
2302 // On wxMac we can't depend on the EVT_KILL_FOCUS event to properly
2303 // shutdown the edit control when the mouse is clicked elsewhere on the
2304 // listctrl because the order of events is different (or something like
2305 // that), so explicitly end the edit if it is active.
2306 if ( event
.LeftDown() && m_textctrlWrapper
)
2307 m_textctrlWrapper
->EndEdit(wxListTextCtrlWrapper::End_Accept
);
2310 if ( event
.LeftDown() )
2313 event
.SetEventObject( GetParent() );
2314 if ( GetParent()->GetEventHandler()->ProcessEvent( event
) )
2317 if (event
.GetEventType() == wxEVT_MOUSEWHEEL
)
2319 // let the base class handle mouse wheel events.
2324 if ( !HasCurrent() || IsEmpty() )
2326 if (event
.RightDown())
2328 SendNotify( (size_t)-1, wxEVT_COMMAND_LIST_ITEM_RIGHT_CLICK
, event
.GetPosition() );
2330 wxContextMenuEvent
evtCtx(wxEVT_CONTEXT_MENU
,
2331 GetParent()->GetId(),
2332 ClientToScreen(event
.GetPosition()));
2333 evtCtx
.SetEventObject(GetParent());
2334 GetParent()->GetEventHandler()->ProcessEvent(evtCtx
);
2342 if ( !(event
.Dragging() || event
.ButtonDown() || event
.LeftUp() ||
2343 event
.ButtonDClick()) )
2346 int x
= event
.GetX();
2347 int y
= event
.GetY();
2348 GetListCtrl()->CalcUnscrolledPosition( x
, y
, &x
, &y
);
2350 // where did we hit it (if we did)?
2353 size_t count
= GetItemCount(),
2356 if ( InReportView() )
2358 current
= y
/ GetLineHeight();
2359 if ( current
< count
)
2360 hitResult
= HitTestLine(current
, x
, y
);
2364 // TODO: optimize it too! this is less simple than for report view but
2365 // enumerating all items is still not a way to do it!!
2366 for ( current
= 0; current
< count
; current
++ )
2368 hitResult
= HitTestLine(current
, x
, y
);
2374 // Update drag events counter first as we must do it even if the mouse is
2375 // not on any item right now as we must keep count in case we started
2376 // dragging from the empty control area but continued to do it over a valid
2377 // item -- in this situation we must not start dragging this item.
2378 if (event
.Dragging())
2383 // The only mouse event that can be generated without any valid item is
2384 // wxEVT_COMMAND_LIST_ITEM_RIGHT_CLICK as it can be useful to have a global
2385 // popup menu for the list control itself which should be shown even when
2386 // the user clicks outside of any item.
2389 // outside of any item
2390 if (event
.RightDown())
2392 SendNotify( (size_t) -1, wxEVT_COMMAND_LIST_ITEM_RIGHT_CLICK
, event
.GetPosition() );
2394 wxContextMenuEvent
evtCtx(
2396 GetParent()->GetId(),
2397 ClientToScreen(event
.GetPosition()));
2398 evtCtx
.SetEventObject(GetParent());
2399 GetParent()->GetEventHandler()->ProcessEvent(evtCtx
);
2403 // reset the selection and bail out
2404 HighlightAll(false);
2410 if ( event
.Dragging() )
2412 if (m_dragCount
== 1)
2414 // we have to report the raw, physical coords as we want to be
2415 // able to call HitTest(event.m_pointDrag) from the user code to
2416 // get the item being dragged
2417 m_dragStart
= event
.GetPosition();
2420 if (m_dragCount
!= 3)
2423 int command
= event
.RightIsDown() ? wxEVT_COMMAND_LIST_BEGIN_RDRAG
2424 : wxEVT_COMMAND_LIST_BEGIN_DRAG
;
2426 SendNotify( m_lineLastClicked
, command
, m_dragStart
);
2431 bool forceClick
= false;
2432 if (event
.ButtonDClick())
2434 if ( m_renameTimer
->IsRunning() )
2435 m_renameTimer
->Stop();
2437 m_lastOnSame
= false;
2439 if ( current
== m_lineLastClicked
)
2441 SendNotify( current
, wxEVT_COMMAND_LIST_ITEM_ACTIVATED
);
2447 // The first click was on another item, so don't interpret this as
2448 // a double click, but as a simple click instead
2455 if (m_lineSelectSingleOnUp
!= (size_t)-1)
2457 // select single line
2458 HighlightAll( false );
2459 ReverseHighlight(m_lineSelectSingleOnUp
);
2464 if ((current
== m_current
) &&
2465 (hitResult
== wxLIST_HITTEST_ONITEMLABEL
) &&
2466 HasFlag(wxLC_EDIT_LABELS
) )
2468 if ( !InReportView() ||
2469 GetLineLabelRect(current
).Contains(x
, y
) )
2471 int dclick
= wxSystemSettings::GetMetric(wxSYS_DCLICK_MSEC
);
2472 m_renameTimer
->Start(dclick
> 0 ? dclick
: 250, true);
2477 m_lastOnSame
= false;
2478 m_lineSelectSingleOnUp
= (size_t)-1;
2482 // This is necessary, because after a DnD operation in
2483 // from and to ourself, the up event is swallowed by the
2484 // DnD code. So on next non-up event (which means here and
2485 // now) m_lineSelectSingleOnUp should be reset.
2486 m_lineSelectSingleOnUp
= (size_t)-1;
2488 if (event
.RightDown())
2490 m_lineBeforeLastClicked
= m_lineLastClicked
;
2491 m_lineLastClicked
= current
;
2493 // If the item is already selected, do not update the selection.
2494 // Multi-selections should not be cleared if a selected item is clicked.
2495 if (!IsHighlighted(current
))
2497 HighlightAll(false);
2498 ChangeCurrent(current
);
2499 ReverseHighlight(m_current
);
2502 SendNotify( current
, wxEVT_COMMAND_LIST_ITEM_RIGHT_CLICK
, event
.GetPosition() );
2504 // Allow generation of context menu event
2507 else if (event
.MiddleDown())
2509 SendNotify( current
, wxEVT_COMMAND_LIST_ITEM_MIDDLE_CLICK
);
2511 else if ( event
.LeftDown() || forceClick
)
2513 m_lineBeforeLastClicked
= m_lineLastClicked
;
2514 m_lineLastClicked
= current
;
2516 size_t oldCurrent
= m_current
;
2517 bool oldWasSelected
= IsHighlighted(m_current
);
2519 bool cmdModifierDown
= event
.CmdDown();
2520 if ( IsSingleSel() || !(cmdModifierDown
|| event
.ShiftDown()) )
2522 if ( IsSingleSel() || !IsHighlighted(current
) )
2524 HighlightAll( false );
2526 ChangeCurrent(current
);
2528 ReverseHighlight(m_current
);
2530 else // multi sel & current is highlighted & no mod keys
2532 m_lineSelectSingleOnUp
= current
;
2533 ChangeCurrent(current
); // change focus
2536 else // multi sel & either ctrl or shift is down
2538 if (cmdModifierDown
)
2540 ChangeCurrent(current
);
2542 ReverseHighlight(m_current
);
2544 else if (event
.ShiftDown())
2546 ChangeCurrent(current
);
2548 size_t lineFrom
= oldCurrent
,
2551 if ( lineTo
< lineFrom
)
2554 lineFrom
= m_current
;
2557 HighlightLines(lineFrom
, lineTo
);
2559 else // !ctrl, !shift
2561 // test in the enclosing if should make it impossible
2562 wxFAIL_MSG( wxT("how did we get here?") );
2566 if (m_current
!= oldCurrent
)
2567 RefreshLine( oldCurrent
);
2569 // forceClick is only set if the previous click was on another item
2570 m_lastOnSame
= !forceClick
&& (m_current
== oldCurrent
) && oldWasSelected
;
2574 void wxListMainWindow::MoveToItem(size_t item
)
2576 if ( item
== (size_t)-1 )
2579 wxRect rect
= GetLineRect(item
);
2581 int client_w
, client_h
;
2582 GetClientSize( &client_w
, &client_h
);
2584 const int hLine
= GetLineHeight();
2586 int view_x
= SCROLL_UNIT_X
* GetListCtrl()->GetScrollPos( wxHORIZONTAL
);
2587 int view_y
= hLine
* GetListCtrl()->GetScrollPos( wxVERTICAL
);
2589 if ( InReportView() )
2591 // the next we need the range of lines shown it might be different,
2592 // so recalculate it
2593 ResetVisibleLinesRange();
2595 if (rect
.y
< view_y
)
2596 GetListCtrl()->Scroll( -1, rect
.y
/ hLine
);
2597 if (rect
.y
+ rect
.height
+ 5 > view_y
+ client_h
)
2598 GetListCtrl()->Scroll( -1, (rect
.y
+ rect
.height
- client_h
+ hLine
) / hLine
);
2601 // At least on Mac the visible lines value will get reset inside of
2602 // Scroll *before* it actually scrolls the window because of the
2603 // Update() that happens there, so it will still have the wrong value.
2604 // So let's reset it again and wait for it to be recalculated in the
2605 // next paint event. I would expect this problem to show up in wxGTK
2606 // too but couldn't duplicate it there. Perhaps the order of events
2607 // is different... --Robin
2608 ResetVisibleLinesRange();
2616 if (rect
.x
-view_x
< 5)
2617 sx
= (rect
.x
- 5) / SCROLL_UNIT_X
;
2618 if (rect
.x
+ rect
.width
- 5 > view_x
+ client_w
)
2619 sx
= (rect
.x
+ rect
.width
- client_w
+ SCROLL_UNIT_X
) / SCROLL_UNIT_X
;
2621 if (rect
.y
-view_y
< 5)
2622 sy
= (rect
.y
- 5) / hLine
;
2623 if (rect
.y
+ rect
.height
- 5 > view_y
+ client_h
)
2624 sy
= (rect
.y
+ rect
.height
- client_h
+ hLine
) / hLine
;
2626 GetListCtrl()->Scroll(sx
, sy
);
2630 bool wxListMainWindow::ScrollList(int WXUNUSED(dx
), int dy
)
2632 if ( !InReportView() )
2634 // TODO: this should work in all views but is not implemented now
2639 GetVisibleLinesRange(&top
, &bottom
);
2641 if ( bottom
== (size_t)-1 )
2644 ResetVisibleLinesRange();
2646 int hLine
= GetLineHeight();
2648 GetListCtrl()->Scroll(-1, top
+ dy
/ hLine
);
2651 // see comment in MoveToItem() for why we do this
2652 ResetVisibleLinesRange();
2658 // ----------------------------------------------------------------------------
2659 // keyboard handling
2660 // ----------------------------------------------------------------------------
2662 void wxListMainWindow::OnArrowChar(size_t newCurrent
, const wxKeyEvent
& event
)
2664 wxCHECK_RET( newCurrent
< (size_t)GetItemCount(),
2665 wxT("invalid item index in OnArrowChar()") );
2667 size_t oldCurrent
= m_current
;
2669 // in single selection we just ignore Shift as we can't select several
2671 if ( event
.ShiftDown() && !IsSingleSel() )
2673 ChangeCurrent(newCurrent
);
2675 // refresh the old focus to remove it
2676 RefreshLine( oldCurrent
);
2678 // select all the items between the old and the new one
2679 if ( oldCurrent
> newCurrent
)
2681 newCurrent
= oldCurrent
;
2682 oldCurrent
= m_current
;
2685 HighlightLines(oldCurrent
, newCurrent
);
2689 // all previously selected items are unselected unless ctrl is held
2690 // in a multiselection control
2691 if ( !event
.ControlDown() || IsSingleSel() )
2692 HighlightAll(false);
2694 ChangeCurrent(newCurrent
);
2696 // refresh the old focus to remove it
2697 RefreshLine( oldCurrent
);
2699 // in single selection mode we must always have a selected item
2700 if ( !event
.ControlDown() || IsSingleSel() )
2701 HighlightLine( m_current
, true );
2704 RefreshLine( m_current
);
2709 void wxListMainWindow::OnKeyDown( wxKeyEvent
&event
)
2711 wxWindow
*parent
= GetParent();
2713 // propagate the key event upwards
2714 wxKeyEvent
ke(event
);
2715 ke
.SetEventObject( parent
);
2716 if (parent
->GetEventHandler()->ProcessEvent( ke
))
2719 // send a list event
2720 wxListEvent
le( wxEVT_COMMAND_LIST_KEY_DOWN
, parent
->GetId() );
2721 le
.m_item
.m_itemId
=
2722 le
.m_itemIndex
= m_current
;
2724 GetLine(m_current
)->GetItem( 0, le
.m_item
);
2725 le
.m_code
= event
.GetKeyCode();
2726 le
.SetEventObject( parent
);
2727 if (parent
->GetEventHandler()->ProcessEvent( le
))
2733 void wxListMainWindow::OnKeyUp( wxKeyEvent
&event
)
2735 wxWindow
*parent
= GetParent();
2737 // propagate the key event upwards
2738 wxKeyEvent
ke(event
);
2739 if (parent
->GetEventHandler()->ProcessEvent( ke
))
2745 void wxListMainWindow::OnCharHook( wxKeyEvent
&event
)
2747 if ( m_textctrlWrapper
)
2749 // When an in-place editor is active we should ensure that it always
2750 // gets the key events that are special to it.
2751 if ( m_textctrlWrapper
->CheckForEndEditKey(event
) )
2753 // Skip the call to wxEvent::Skip() below.
2761 void wxListMainWindow::OnChar( wxKeyEvent
&event
)
2763 wxWindow
*parent
= GetParent();
2765 // propagate the char event upwards
2766 wxKeyEvent
ke(event
);
2767 ke
.SetEventObject( parent
);
2768 if (parent
->GetEventHandler()->ProcessEvent( ke
))
2771 if ( HandleAsNavigationKey(event
) )
2774 // no item -> nothing to do
2781 // don't use m_linesPerPage directly as it might not be computed yet
2782 const int pageSize
= GetCountPerPage();
2783 wxCHECK_RET( pageSize
, wxT("should have non zero page size") );
2785 if (GetLayoutDirection() == wxLayout_RightToLeft
)
2787 if (event
.GetKeyCode() == WXK_RIGHT
)
2788 event
.m_keyCode
= WXK_LEFT
;
2789 else if (event
.GetKeyCode() == WXK_LEFT
)
2790 event
.m_keyCode
= WXK_RIGHT
;
2793 switch ( event
.GetKeyCode() )
2796 if ( m_current
> 0 )
2797 OnArrowChar( m_current
- 1, event
);
2801 if ( m_current
< (size_t)GetItemCount() - 1 )
2802 OnArrowChar( m_current
+ 1, event
);
2807 OnArrowChar( GetItemCount() - 1, event
);
2812 OnArrowChar( 0, event
);
2817 int steps
= InReportView() ? pageSize
- 1
2818 : m_current
% pageSize
;
2820 int index
= m_current
- steps
;
2824 OnArrowChar( index
, event
);
2830 int steps
= InReportView()
2832 : pageSize
- (m_current
% pageSize
) - 1;
2834 size_t index
= m_current
+ steps
;
2835 size_t count
= GetItemCount();
2836 if ( index
>= count
)
2839 OnArrowChar( index
, event
);
2844 if ( !InReportView() )
2846 int index
= m_current
- pageSize
;
2850 OnArrowChar( index
, event
);
2855 if ( !InReportView() )
2857 size_t index
= m_current
+ pageSize
;
2859 size_t count
= GetItemCount();
2860 if ( index
>= count
)
2863 OnArrowChar( index
, event
);
2868 if ( IsSingleSel() )
2870 if ( event
.ControlDown() )
2872 ReverseHighlight(m_current
);
2874 else // normal space press
2876 SendNotify( m_current
, wxEVT_COMMAND_LIST_ITEM_ACTIVATED
);
2879 else // multiple selection
2881 ReverseHighlight(m_current
);
2887 SendNotify( m_current
, wxEVT_COMMAND_LIST_ITEM_ACTIVATED
);
2895 // ----------------------------------------------------------------------------
2897 // ----------------------------------------------------------------------------
2899 void wxListMainWindow::OnSetFocus( wxFocusEvent
&WXUNUSED(event
) )
2903 wxFocusEvent
event( wxEVT_SET_FOCUS
, GetParent()->GetId() );
2904 event
.SetEventObject( GetParent() );
2905 if ( GetParent()->GetEventHandler()->ProcessEvent( event
) )
2909 // wxGTK sends us EVT_SET_FOCUS events even if we had never got
2910 // EVT_KILL_FOCUS before which means that we finish by redrawing the items
2911 // which are already drawn correctly resulting in horrible flicker - avoid
2921 void wxListMainWindow::OnKillFocus( wxFocusEvent
&WXUNUSED(event
) )
2925 wxFocusEvent
event( wxEVT_KILL_FOCUS
, GetParent()->GetId() );
2926 event
.SetEventObject( GetParent() );
2927 if ( GetParent()->GetEventHandler()->ProcessEvent( event
) )
2935 void wxListMainWindow::DrawImage( int index
, wxDC
*dc
, int x
, int y
)
2937 if ( HasFlag(wxLC_ICON
) && (m_normal_image_list
))
2939 m_normal_image_list
->Draw( index
, *dc
, x
, y
, wxIMAGELIST_DRAW_TRANSPARENT
);
2941 else if ( HasFlag(wxLC_SMALL_ICON
) && (m_small_image_list
))
2943 m_small_image_list
->Draw( index
, *dc
, x
, y
, wxIMAGELIST_DRAW_TRANSPARENT
);
2945 else if ( HasFlag(wxLC_LIST
) && (m_small_image_list
))
2947 m_small_image_list
->Draw( index
, *dc
, x
, y
, wxIMAGELIST_DRAW_TRANSPARENT
);
2949 else if ( InReportView() && (m_small_image_list
))
2951 m_small_image_list
->Draw( index
, *dc
, x
, y
, wxIMAGELIST_DRAW_TRANSPARENT
);
2955 void wxListMainWindow::GetImageSize( int index
, int &width
, int &height
) const
2957 if ( HasFlag(wxLC_ICON
) && m_normal_image_list
)
2959 m_normal_image_list
->GetSize( index
, width
, height
);
2961 else if ( HasFlag(wxLC_SMALL_ICON
) && m_small_image_list
)
2963 m_small_image_list
->GetSize( index
, width
, height
);
2965 else if ( HasFlag(wxLC_LIST
) && m_small_image_list
)
2967 m_small_image_list
->GetSize( index
, width
, height
);
2969 else if ( InReportView() && m_small_image_list
)
2971 m_small_image_list
->GetSize( index
, width
, height
);
2980 void wxListMainWindow::SetImageList( wxImageList
*imageList
, int which
)
2984 // calc the spacing from the icon size
2985 int width
= 0, height
= 0;
2987 if ((imageList
) && (imageList
->GetImageCount()) )
2988 imageList
->GetSize(0, width
, height
);
2990 if (which
== wxIMAGE_LIST_NORMAL
)
2992 m_normal_image_list
= imageList
;
2993 m_normal_spacing
= width
+ 8;
2996 if (which
== wxIMAGE_LIST_SMALL
)
2998 m_small_image_list
= imageList
;
2999 m_small_spacing
= width
+ 14;
3000 m_lineHeight
= 0; // ensure that the line height will be recalc'd
3004 void wxListMainWindow::SetItemSpacing( int spacing
, bool isSmall
)
3008 m_small_spacing
= spacing
;
3010 m_normal_spacing
= spacing
;
3013 int wxListMainWindow::GetItemSpacing( bool isSmall
)
3015 return isSmall
? m_small_spacing
: m_normal_spacing
;
3018 // ----------------------------------------------------------------------------
3020 // ----------------------------------------------------------------------------
3023 wxListMainWindow::ComputeMinHeaderWidth(const wxListHeaderData
* column
) const
3025 wxClientDC
dc(const_cast<wxListMainWindow
*>(this));
3027 int width
= dc
.GetTextExtent(column
->GetText()).x
+ AUTOSIZE_COL_MARGIN
;
3029 width
+= 2*EXTRA_WIDTH
;
3031 // check for column header's image availability
3032 const int image
= column
->GetImage();
3035 if ( m_small_image_list
)
3038 m_small_image_list
->GetSize(image
, ix
, iy
);
3039 width
+= ix
+ HEADER_IMAGE_MARGIN_IN_REPORT_MODE
;
3046 void wxListMainWindow::SetColumn( int col
, const wxListItem
&item
)
3048 wxListHeaderDataList::compatibility_iterator node
= m_columns
.Item( col
);
3050 wxCHECK_RET( node
, wxT("invalid column index in SetColumn") );
3052 wxListHeaderData
*column
= node
->GetData();
3053 column
->SetItem( item
);
3055 if ( item
.m_width
== wxLIST_AUTOSIZE_USEHEADER
)
3056 column
->SetWidth(ComputeMinHeaderWidth(column
));
3058 wxListHeaderWindow
*headerWin
= GetListCtrl()->m_headerWin
;
3060 headerWin
->m_dirty
= true;
3064 // invalidate it as it has to be recalculated
3068 void wxListMainWindow::SetColumnWidth( int col
, int width
)
3070 wxCHECK_RET( col
>= 0 && col
< GetColumnCount(),
3071 wxT("invalid column index") );
3073 wxCHECK_RET( InReportView(),
3074 wxT("SetColumnWidth() can only be called in report mode.") );
3078 wxListHeaderWindow
*headerWin
= GetListCtrl()->m_headerWin
;
3080 headerWin
->m_dirty
= true;
3082 wxListHeaderDataList::compatibility_iterator node
= m_columns
.Item( col
);
3083 wxCHECK_RET( node
, wxT("no column?") );
3085 wxListHeaderData
*column
= node
->GetData();
3087 size_t count
= GetItemCount();
3089 if (width
== wxLIST_AUTOSIZE_USEHEADER
)
3091 width
= ComputeMinHeaderWidth(column
);
3093 else if ( width
== wxLIST_AUTOSIZE
)
3095 width
= ComputeMinHeaderWidth(column
);
3099 wxClientDC
dc(this);
3100 dc
.SetFont( GetFont() );
3102 int max
= AUTOSIZE_COL_MARGIN
;
3104 // if the cached column width isn't valid then recalculate it
3105 if (m_aColWidths
.Item(col
)->bNeedsUpdate
)
3107 for (size_t i
= 0; i
< count
; i
++)
3109 wxListLineData
*line
= GetLine( i
);
3110 wxListItemDataList::compatibility_iterator n
= line
->m_items
.Item( col
);
3112 wxCHECK_RET( n
, wxT("no subitem?") );
3114 wxListItemData
*itemData
= n
->GetData();
3117 itemData
->GetItem(item
);
3118 int itemWidth
= GetItemWidthWithImage(&item
);
3119 if (itemWidth
> max
)
3123 m_aColWidths
.Item(col
)->bNeedsUpdate
= false;
3124 m_aColWidths
.Item(col
)->nMaxWidth
= max
;
3127 max
= m_aColWidths
.Item(col
)->nMaxWidth
+ AUTOSIZE_COL_MARGIN
;
3133 column
->SetWidth( width
);
3135 // invalidate it as it has to be recalculated
3139 int wxListMainWindow::GetHeaderWidth() const
3141 if ( !m_headerWidth
)
3143 wxListMainWindow
*self
= wxConstCast(this, wxListMainWindow
);
3145 size_t count
= GetColumnCount();
3146 for ( size_t col
= 0; col
< count
; col
++ )
3148 self
->m_headerWidth
+= GetColumnWidth(col
);
3152 return m_headerWidth
;
3155 void wxListMainWindow::GetColumn( int col
, wxListItem
&item
) const
3157 wxListHeaderDataList::compatibility_iterator node
= m_columns
.Item( col
);
3158 wxCHECK_RET( node
, wxT("invalid column index in GetColumn") );
3160 wxListHeaderData
*column
= node
->GetData();
3161 column
->GetItem( item
);
3164 int wxListMainWindow::GetColumnWidth( int col
) const
3166 wxListHeaderDataList::compatibility_iterator node
= m_columns
.Item( col
);
3167 wxCHECK_MSG( node
, 0, wxT("invalid column index") );
3169 wxListHeaderData
*column
= node
->GetData();
3170 return column
->GetWidth();
3173 // ----------------------------------------------------------------------------
3175 // ----------------------------------------------------------------------------
3177 void wxListMainWindow::SetItem( wxListItem
&item
)
3179 long id
= item
.m_itemId
;
3180 wxCHECK_RET( id
>= 0 && (size_t)id
< GetItemCount(),
3181 wxT("invalid item index in SetItem") );
3185 wxListLineData
*line
= GetLine((size_t)id
);
3186 line
->SetItem( item
.m_col
, item
);
3188 // Set item state if user wants
3189 if ( item
.m_mask
& wxLIST_MASK_STATE
)
3190 SetItemState( item
.m_itemId
, item
.m_state
, item
.m_state
);
3194 // update the Max Width Cache if needed
3195 int width
= GetItemWidthWithImage(&item
);
3197 if (width
> m_aColWidths
.Item(item
.m_col
)->nMaxWidth
)
3198 m_aColWidths
.Item(item
.m_col
)->nMaxWidth
= width
;
3202 // update the item on screen unless we're going to update everything soon
3207 GetItemRect(id
, rectItem
);
3208 RefreshRect(rectItem
);
3212 void wxListMainWindow::SetItemStateAll(long state
, long stateMask
)
3217 // first deal with selection
3218 if ( stateMask
& wxLIST_STATE_SELECTED
)
3220 // set/clear select state
3223 // optimized version for virtual listctrl.
3224 m_selStore
.SelectRange(0, GetItemCount() - 1, state
== wxLIST_STATE_SELECTED
);
3227 else if ( state
& wxLIST_STATE_SELECTED
)
3229 const long count
= GetItemCount();
3230 for( long i
= 0; i
< count
; i
++ )
3232 SetItemState( i
, wxLIST_STATE_SELECTED
, wxLIST_STATE_SELECTED
);
3238 // clear for non virtual (somewhat optimized by using GetNextItem())
3240 while ( (i
= GetNextItem(i
, wxLIST_NEXT_ALL
, wxLIST_STATE_SELECTED
)) != -1 )
3242 SetItemState( i
, 0, wxLIST_STATE_SELECTED
);
3247 if ( HasCurrent() && (state
== 0) && (stateMask
& wxLIST_STATE_FOCUSED
) )
3249 // unfocus all: only one item can be focussed, so clearing focus for
3250 // all items is simply clearing focus of the focussed item.
3251 SetItemState(m_current
, state
, stateMask
);
3253 //(setting focus to all items makes no sense, so it is not handled here.)
3256 void wxListMainWindow::SetItemState( long litem
, long state
, long stateMask
)
3260 SetItemStateAll(state
, stateMask
);
3264 wxCHECK_RET( litem
>= 0 && (size_t)litem
< GetItemCount(),
3265 wxT("invalid list ctrl item index in SetItem") );
3267 size_t oldCurrent
= m_current
;
3268 size_t item
= (size_t)litem
; // safe because of the check above
3270 // do we need to change the focus?
3271 if ( stateMask
& wxLIST_STATE_FOCUSED
)
3273 if ( state
& wxLIST_STATE_FOCUSED
)
3275 // don't do anything if this item is already focused
3276 if ( item
!= m_current
)
3278 ChangeCurrent(item
);
3280 if ( oldCurrent
!= (size_t)-1 )
3282 if ( IsSingleSel() )
3284 HighlightLine(oldCurrent
, false);
3287 RefreshLine(oldCurrent
);
3290 RefreshLine( m_current
);
3295 // don't do anything if this item is not focused
3296 if ( item
== m_current
)
3300 if ( IsSingleSel() )
3302 // we must unselect the old current item as well or we
3303 // might end up with more than one selected item in a
3304 // single selection control
3305 HighlightLine(oldCurrent
, false);
3308 RefreshLine( oldCurrent
);
3313 // do we need to change the selection state?
3314 if ( stateMask
& wxLIST_STATE_SELECTED
)
3316 bool on
= (state
& wxLIST_STATE_SELECTED
) != 0;
3318 if ( IsSingleSel() )
3322 // selecting the item also makes it the focused one in the
3324 if ( m_current
!= item
)
3326 ChangeCurrent(item
);
3328 if ( oldCurrent
!= (size_t)-1 )
3330 HighlightLine( oldCurrent
, false );
3331 RefreshLine( oldCurrent
);
3337 // only the current item may be selected anyhow
3338 if ( item
!= m_current
)
3343 if ( HighlightLine(item
, on
) )
3350 int wxListMainWindow::GetItemState( long item
, long stateMask
) const
3352 wxCHECK_MSG( item
>= 0 && (size_t)item
< GetItemCount(), 0,
3353 wxT("invalid list ctrl item index in GetItemState()") );
3355 int ret
= wxLIST_STATE_DONTCARE
;
3357 if ( stateMask
& wxLIST_STATE_FOCUSED
)
3359 if ( (size_t)item
== m_current
)
3360 ret
|= wxLIST_STATE_FOCUSED
;
3363 if ( stateMask
& wxLIST_STATE_SELECTED
)
3365 if ( IsHighlighted(item
) )
3366 ret
|= wxLIST_STATE_SELECTED
;
3372 void wxListMainWindow::GetItem( wxListItem
&item
) const
3374 wxCHECK_RET( item
.m_itemId
>= 0 && (size_t)item
.m_itemId
< GetItemCount(),
3375 wxT("invalid item index in GetItem") );
3377 wxListLineData
*line
= GetLine((size_t)item
.m_itemId
);
3378 line
->GetItem( item
.m_col
, item
);
3380 // Get item state if user wants it
3381 if ( item
.m_mask
& wxLIST_MASK_STATE
)
3382 item
.m_state
= GetItemState( item
.m_itemId
, wxLIST_STATE_SELECTED
|
3383 wxLIST_STATE_FOCUSED
);
3386 // ----------------------------------------------------------------------------
3388 // ----------------------------------------------------------------------------
3390 size_t wxListMainWindow::GetItemCount() const
3392 return IsVirtual() ? m_countVirt
: m_lines
.GetCount();
3395 void wxListMainWindow::SetItemCount(long count
)
3397 m_selStore
.SetItemCount(count
);
3398 m_countVirt
= count
;
3400 ResetVisibleLinesRange();
3402 // scrollbars must be reset
3406 int wxListMainWindow::GetSelectedItemCount() const
3408 // deal with the quick case first
3409 if ( IsSingleSel() )
3410 return HasCurrent() ? IsHighlighted(m_current
) : false;
3412 // virtual controls remmebers all its selections itself
3414 return m_selStore
.GetSelectedCount();
3416 // TODO: we probably should maintain the number of items selected even for
3417 // non virtual controls as enumerating all lines is really slow...
3418 size_t countSel
= 0;
3419 size_t count
= GetItemCount();
3420 for ( size_t line
= 0; line
< count
; line
++ )
3422 if ( GetLine(line
)->IsHighlighted() )
3429 // ----------------------------------------------------------------------------
3430 // item position/size
3431 // ----------------------------------------------------------------------------
3433 wxRect
wxListMainWindow::GetViewRect() const
3435 wxASSERT_MSG( !HasFlag(wxLC_LIST
), "not implemented for list view" );
3437 // we need to find the longest/tallest label
3438 wxCoord xMax
= 0, yMax
= 0;
3439 const int count
= GetItemCount();
3442 for ( int i
= 0; i
< count
; i
++ )
3444 // we need logical, not physical, coordinates here, so use
3445 // GetLineRect() instead of GetItemRect()
3446 wxRect r
= GetLineRect(i
);
3448 wxCoord x
= r
.GetRight(),
3458 // some fudge needed to make it look prettier
3459 xMax
+= 2 * EXTRA_BORDER_X
;
3460 yMax
+= 2 * EXTRA_BORDER_Y
;
3462 // account for the scrollbars if necessary
3463 const wxSize sizeAll
= GetClientSize();
3464 if ( xMax
> sizeAll
.x
)
3465 yMax
+= wxSystemSettings::GetMetric(wxSYS_HSCROLL_Y
);
3466 if ( yMax
> sizeAll
.y
)
3467 xMax
+= wxSystemSettings::GetMetric(wxSYS_VSCROLL_X
);
3469 return wxRect(0, 0, xMax
, yMax
);
3473 wxListMainWindow::GetSubItemRect(long item
, long subItem
, wxRect
& rect
) const
3475 wxCHECK_MSG( subItem
== wxLIST_GETSUBITEMRECT_WHOLEITEM
|| InReportView(),
3477 wxT("GetSubItemRect only meaningful in report view") );
3478 wxCHECK_MSG( item
>= 0 && (size_t)item
< GetItemCount(), false,
3479 wxT("invalid item in GetSubItemRect") );
3481 // ensure that we're laid out, otherwise we could return nonsense
3484 wxConstCast(this, wxListMainWindow
)->
3485 RecalculatePositions(true /* no refresh */);
3488 rect
= GetLineRect((size_t)item
);
3490 // Adjust rect to specified column
3491 if ( subItem
!= wxLIST_GETSUBITEMRECT_WHOLEITEM
)
3493 wxCHECK_MSG( subItem
>= 0 && subItem
< GetColumnCount(), false,
3494 wxT("invalid subItem in GetSubItemRect") );
3496 for (int i
= 0; i
< subItem
; i
++)
3498 rect
.x
+= GetColumnWidth(i
);
3500 rect
.width
= GetColumnWidth(subItem
);
3503 GetListCtrl()->CalcScrolledPosition(rect
.x
, rect
.y
, &rect
.x
, &rect
.y
);
3508 bool wxListMainWindow::GetItemPosition(long item
, wxPoint
& pos
) const
3511 GetItemRect(item
, rect
);
3519 // ----------------------------------------------------------------------------
3520 // geometry calculation
3521 // ----------------------------------------------------------------------------
3523 void wxListMainWindow::RecalculatePositions(bool noRefresh
)
3525 const int lineHeight
= GetLineHeight();
3527 wxClientDC
dc( this );
3528 dc
.SetFont( GetFont() );
3530 const size_t count
= GetItemCount();
3533 if ( HasFlag(wxLC_ICON
) && m_normal_image_list
)
3534 iconSpacing
= m_normal_spacing
;
3535 else if ( HasFlag(wxLC_SMALL_ICON
) && m_small_image_list
)
3536 iconSpacing
= m_small_spacing
;
3540 // Note that we do not call GetClientSize() here but
3541 // GetSize() and subtract the border size for sunken
3542 // borders manually. This is technically incorrect,
3543 // but we need to know the client area's size WITHOUT
3544 // scrollbars here. Since we don't know if there are
3545 // any scrollbars, we use GetSize() instead. Another
3546 // solution would be to call SetScrollbars() here to
3547 // remove the scrollbars and call GetClientSize() then,
3548 // but this might result in flicker and - worse - will
3549 // reset the scrollbars to 0 which is not good at all
3550 // if you resize a dialog/window, but don't want to
3551 // reset the window scrolling. RR.
3552 // Furthermore, we actually do NOT subtract the border
3553 // width as 2 pixels is just the extra space which we
3554 // need around the actual content in the window. Other-
3555 // wise the text would e.g. touch the upper border. RR.
3558 GetSize( &clientWidth
, &clientHeight
);
3560 if ( InReportView() )
3562 // all lines have the same height and we scroll one line per step
3563 int entireHeight
= count
* lineHeight
+ LINE_SPACING
;
3565 m_linesPerPage
= clientHeight
/ lineHeight
;
3567 ResetVisibleLinesRange();
3569 GetListCtrl()->SetScrollbars( SCROLL_UNIT_X
, lineHeight
,
3570 GetHeaderWidth() / SCROLL_UNIT_X
,
3571 (entireHeight
+ lineHeight
- 1) / lineHeight
,
3572 GetListCtrl()->GetScrollPos(wxHORIZONTAL
),
3573 GetListCtrl()->GetScrollPos(wxVERTICAL
),
3578 // we have 3 different layout strategies: either layout all items
3579 // horizontally/vertically (wxLC_ALIGN_XXX styles explicitly given) or
3580 // to arrange them in top to bottom, left to right (don't ask me why
3581 // not the other way round...) order
3582 if ( HasFlag(wxLC_ALIGN_LEFT
| wxLC_ALIGN_TOP
) )
3584 int x
= EXTRA_BORDER_X
;
3585 int y
= EXTRA_BORDER_Y
;
3587 wxCoord widthMax
= 0;
3590 for ( i
= 0; i
< count
; i
++ )
3592 wxListLineData
*line
= GetLine(i
);
3593 line
->CalculateSize( &dc
, iconSpacing
);
3594 line
->SetPosition( x
, y
, iconSpacing
);
3596 wxSize sizeLine
= GetLineSize(i
);
3598 if ( HasFlag(wxLC_ALIGN_TOP
) )
3600 if ( sizeLine
.x
> widthMax
)
3601 widthMax
= sizeLine
.x
;
3605 else // wxLC_ALIGN_LEFT
3607 x
+= sizeLine
.x
+ MARGIN_BETWEEN_ROWS
;
3611 if ( HasFlag(wxLC_ALIGN_TOP
) )
3613 // traverse the items again and tweak their sizes so that they are
3614 // all the same in a row
3615 for ( i
= 0; i
< count
; i
++ )
3617 wxListLineData
*line
= GetLine(i
);
3618 line
->m_gi
->ExtendWidth(widthMax
);
3622 GetListCtrl()->SetScrollbars
3626 (x
+ SCROLL_UNIT_X
) / SCROLL_UNIT_X
,
3627 (y
+ lineHeight
) / lineHeight
,
3628 GetListCtrl()->GetScrollPos( wxHORIZONTAL
),
3629 GetListCtrl()->GetScrollPos( wxVERTICAL
),
3633 else // "flowed" arrangement, the most complicated case
3635 // at first we try without any scrollbars, if the items don't fit into
3636 // the window, we recalculate after subtracting the space taken by the
3639 int entireWidth
= 0;
3641 for (int tries
= 0; tries
< 2; tries
++)
3643 entireWidth
= 2 * EXTRA_BORDER_X
;
3647 // Now we have decided that the items do not fit into the
3648 // client area, so we need a scrollbar
3649 entireWidth
+= SCROLL_UNIT_X
;
3652 int x
= EXTRA_BORDER_X
;
3653 int y
= EXTRA_BORDER_Y
;
3655 // Note that "row" here is vertical, i.e. what is called
3656 // "column" in many other places in wxWidgets.
3657 int maxWidthInThisRow
= 0;
3660 int currentlyVisibleLines
= 0;
3662 for (size_t i
= 0; i
< count
; i
++)
3664 currentlyVisibleLines
++;
3665 wxListLineData
*line
= GetLine( i
);
3666 line
->CalculateSize( &dc
, iconSpacing
);
3667 line
->SetPosition( x
, y
, iconSpacing
);
3669 wxSize sizeLine
= GetLineSize( i
);
3671 if ( maxWidthInThisRow
< sizeLine
.x
)
3672 maxWidthInThisRow
= sizeLine
.x
;
3675 if (currentlyVisibleLines
> m_linesPerPage
)
3676 m_linesPerPage
= currentlyVisibleLines
;
3678 // Have we reached the end of the row either because no
3679 // more items would fit or because there are simply no more
3681 if ( y
+ sizeLine
.y
>= clientHeight
3684 // Adjust all items in this row to have the same
3685 // width to ensure that they all align horizontally in
3687 if ( HasFlag(wxLC_ICON
) || HasFlag(wxLC_SMALL_ICON
) )
3689 size_t firstRowLine
= i
- currentlyVisibleLines
+ 1;
3690 for (size_t j
= firstRowLine
; j
<= i
; j
++)
3692 GetLine(j
)->m_gi
->ExtendWidth(maxWidthInThisRow
);
3696 currentlyVisibleLines
= 0;
3698 maxWidthInThisRow
+= MARGIN_BETWEEN_ROWS
;
3699 x
+= maxWidthInThisRow
;
3700 entireWidth
+= maxWidthInThisRow
;
3701 maxWidthInThisRow
= 0;
3704 if ( (tries
== 0) &&
3705 (entireWidth
+ SCROLL_UNIT_X
> clientWidth
) )
3707 clientHeight
-= wxSystemSettings::
3708 GetMetric(wxSYS_HSCROLL_Y
);
3713 if ( i
== count
- 1 )
3714 tries
= 1; // Everything fits, no second try required.
3718 GetListCtrl()->SetScrollbars
3722 (entireWidth
+ SCROLL_UNIT_X
) / SCROLL_UNIT_X
,
3724 GetListCtrl()->GetScrollPos( wxHORIZONTAL
),
3733 // FIXME: why should we call it from here?
3740 void wxListMainWindow::RefreshAll()
3745 wxListHeaderWindow
*headerWin
= GetListCtrl()->m_headerWin
;
3746 if ( headerWin
&& headerWin
->m_dirty
)
3748 headerWin
->m_dirty
= false;
3749 headerWin
->Refresh();
3753 void wxListMainWindow::UpdateCurrent()
3755 if ( !HasCurrent() && !IsEmpty() )
3759 long wxListMainWindow::GetNextItem( long item
,
3760 int WXUNUSED(geometry
),
3764 max
= GetItemCount();
3765 wxCHECK_MSG( (ret
== -1) || (ret
< max
), -1,
3766 wxT("invalid listctrl index in GetNextItem()") );
3768 // notice that we start with the next item (or the first one if item == -1)
3769 // and this is intentional to allow writing a simple loop to iterate over
3770 // all selected items
3773 // this is not an error because the index was OK initially,
3774 // just no such item
3781 size_t count
= GetItemCount();
3782 for ( size_t line
= (size_t)ret
; line
< count
; line
++ )
3784 if ( (state
& wxLIST_STATE_FOCUSED
) && (line
== m_current
) )
3787 if ( (state
& wxLIST_STATE_SELECTED
) && IsHighlighted(line
) )
3794 // ----------------------------------------------------------------------------
3796 // ----------------------------------------------------------------------------
3798 void wxListMainWindow::DeleteItem( long lindex
)
3800 size_t count
= GetItemCount();
3802 wxCHECK_RET( (lindex
>= 0) && ((size_t)lindex
< count
),
3803 wxT("invalid item index in DeleteItem") );
3805 size_t index
= (size_t)lindex
;
3807 // we don't need to adjust the index for the previous items
3808 if ( HasCurrent() && m_current
>= index
)
3810 // if the current item is being deleted, we want the next one to
3811 // become selected - unless there is no next one - so don't adjust
3812 // m_current in this case
3813 if ( m_current
!= index
|| m_current
== count
- 1 )
3817 if ( InReportView() )
3819 // mark the Column Max Width cache as dirty if the items in the line
3820 // we're deleting contain the Max Column Width
3821 wxListLineData
* const line
= GetLine(index
);
3822 wxListItemDataList::compatibility_iterator n
;
3823 wxListItemData
*itemData
;
3827 for (size_t i
= 0; i
< m_columns
.GetCount(); i
++)
3829 n
= line
->m_items
.Item( i
);
3830 itemData
= n
->GetData();
3831 itemData
->GetItem(item
);
3833 itemWidth
= GetItemWidthWithImage(&item
);
3835 if (itemWidth
>= m_aColWidths
.Item(i
)->nMaxWidth
)
3836 m_aColWidths
.Item(i
)->bNeedsUpdate
= true;
3839 ResetVisibleLinesRange();
3842 SendNotify( index
, wxEVT_COMMAND_LIST_DELETE_ITEM
, wxDefaultPosition
);
3847 m_selStore
.OnItemDelete(index
);
3851 m_lines
.RemoveAt( index
);
3854 // we need to refresh the (vert) scrollbar as the number of items changed
3857 RefreshAfter(index
);
3860 void wxListMainWindow::DeleteColumn( int col
)
3862 wxListHeaderDataList::compatibility_iterator node
= m_columns
.Item( col
);
3864 wxCHECK_RET( node
, wxT("invalid column index in DeleteColumn()") );
3867 delete node
->GetData();
3868 m_columns
.Erase( node
);
3872 // update all the items
3873 for ( size_t i
= 0; i
< m_lines
.GetCount(); i
++ )
3875 wxListLineData
* const line
= GetLine(i
);
3877 // In the following atypical but possible scenario it can be
3878 // legal to call DeleteColumn() but the items may not have any
3880 // 1. In report view, insert a second column.
3881 // 2. Still in report view, add an item with 2 values.
3882 // 3. Switch to an icon (or list) view.
3883 // 4. Add an item -- necessarily with 1 value only.
3884 // 5. Switch back to report view.
3885 // 6. Call DeleteColumn().
3886 // So we need to check for this as otherwise we would simply crash
3888 if ( line
->m_items
.GetCount() <= static_cast<unsigned>(col
) )
3891 wxListItemDataList::compatibility_iterator n
= line
->m_items
.Item( col
);
3892 delete n
->GetData();
3893 line
->m_items
.Erase(n
);
3897 if ( InReportView() ) // we only cache max widths when in Report View
3899 delete m_aColWidths
.Item(col
);
3900 m_aColWidths
.RemoveAt(col
);
3903 // invalidate it as it has to be recalculated
3907 void wxListMainWindow::DoDeleteAllItems()
3910 // nothing to do - in particular, don't send the event
3915 // to make the deletion of all items faster, we don't send the
3916 // notifications for each item deletion in this case but only one event
3917 // for all of them: this is compatible with wxMSW and documented in
3918 // DeleteAllItems() description
3920 wxListEvent
event( wxEVT_COMMAND_LIST_DELETE_ALL_ITEMS
, GetParent()->GetId() );
3921 event
.SetEventObject( GetParent() );
3922 GetParent()->GetEventHandler()->ProcessEvent( event
);
3930 if ( InReportView() )
3932 ResetVisibleLinesRange();
3933 for (size_t i
= 0; i
< m_aColWidths
.GetCount(); i
++)
3935 m_aColWidths
.Item(i
)->bNeedsUpdate
= true;
3942 void wxListMainWindow::DeleteAllItems()
3946 RecalculatePositions();
3949 void wxListMainWindow::DeleteEverything()
3951 WX_CLEAR_LIST(wxListHeaderDataList
, m_columns
);
3952 WX_CLEAR_ARRAY(m_aColWidths
);
3957 // ----------------------------------------------------------------------------
3958 // scanning for an item
3959 // ----------------------------------------------------------------------------
3961 void wxListMainWindow::EnsureVisible( long index
)
3963 wxCHECK_RET( index
>= 0 && (size_t)index
< GetItemCount(),
3964 wxT("invalid index in EnsureVisible") );
3966 // We have to call this here because the label in question might just have
3967 // been added and its position is not known yet
3969 RecalculatePositions(true /* no refresh */);
3971 MoveToItem((size_t)index
);
3974 long wxListMainWindow::FindItem(long start
, const wxString
& str
, bool partial
)
3980 wxString str_upper
= str
.Upper();
3984 size_t count
= GetItemCount();
3985 for ( size_t i
= (size_t)pos
; i
< count
; i
++ )
3987 wxListLineData
*line
= GetLine(i
);
3988 wxString line_upper
= line
->GetText(0).Upper();
3991 if (line_upper
== str_upper
)
3996 if (line_upper
.find(str_upper
) == 0)
4004 long wxListMainWindow::FindItem(long start
, wxUIntPtr data
)
4010 size_t count
= GetItemCount();
4011 for (size_t i
= (size_t)pos
; i
< count
; i
++)
4013 wxListLineData
*line
= GetLine(i
);
4015 line
->GetItem( 0, item
);
4016 if (item
.m_data
== data
)
4023 long wxListMainWindow::FindItem( const wxPoint
& pt
)
4026 GetVisibleLinesRange( &topItem
, NULL
);
4029 GetItemPosition( GetItemCount() - 1, p
);
4033 long id
= (long)floor( pt
.y
* double(GetItemCount() - topItem
- 1) / p
.y
+ topItem
);
4034 if ( id
>= 0 && id
< (long)GetItemCount() )
4040 long wxListMainWindow::HitTest( int x
, int y
, int &flags
) const
4042 GetListCtrl()->CalcUnscrolledPosition( x
, y
, &x
, &y
);
4044 size_t count
= GetItemCount();
4046 if ( InReportView() )
4048 size_t current
= y
/ GetLineHeight();
4049 if ( current
< count
)
4051 flags
= HitTestLine(current
, x
, y
);
4058 // TODO: optimize it too! this is less simple than for report view but
4059 // enumerating all items is still not a way to do it!!
4060 for ( size_t current
= 0; current
< count
; current
++ )
4062 flags
= HitTestLine(current
, x
, y
);
4071 // ----------------------------------------------------------------------------
4073 // ----------------------------------------------------------------------------
4075 void wxListMainWindow::InsertItem( wxListItem
&item
)
4077 wxASSERT_MSG( !IsVirtual(), wxT("can't be used with virtual control") );
4079 int count
= GetItemCount();
4080 wxCHECK_RET( item
.m_itemId
>= 0, wxT("invalid item index") );
4082 if (item
.m_itemId
> count
)
4083 item
.m_itemId
= count
;
4085 size_t id
= item
.m_itemId
;
4089 if ( InReportView() )
4091 ResetVisibleLinesRange();
4093 const unsigned col
= item
.GetColumn();
4094 wxCHECK_RET( col
< m_aColWidths
.size(), "invalid item column" );
4096 // calculate the width of the item and adjust the max column width
4097 wxColWidthInfo
*pWidthInfo
= m_aColWidths
.Item(col
);
4098 int width
= GetItemWidthWithImage(&item
);
4099 item
.SetWidth(width
);
4100 if (width
> pWidthInfo
->nMaxWidth
)
4101 pWidthInfo
->nMaxWidth
= width
;
4104 wxListLineData
*line
= new wxListLineData(this);
4106 line
->SetItem( item
.m_col
, item
);
4107 if ( item
.m_mask
& wxLIST_MASK_IMAGE
)
4109 // Reset the buffered height if it's not big enough for the new image.
4110 int image
= item
.GetImage();
4111 if ( m_small_image_list
&& image
!= -1 && InReportView() )
4113 int imageWidth
, imageHeight
;
4114 m_small_image_list
->GetSize(image
, imageWidth
, imageHeight
);
4116 if ( imageHeight
> m_lineHeight
)
4121 m_lines
.Insert( line
, id
);
4125 // If an item is selected at or below the point of insertion, we need to
4126 // increment the member variables because the current row's index has gone
4128 if ( HasCurrent() && m_current
>= id
)
4131 SendNotify(id
, wxEVT_COMMAND_LIST_INSERT_ITEM
);
4133 RefreshLines(id
, GetItemCount() - 1);
4136 void wxListMainWindow::InsertColumn( long col
, const wxListItem
&item
)
4139 if ( InReportView() )
4141 wxListHeaderData
*column
= new wxListHeaderData( item
);
4142 if (item
.m_width
== wxLIST_AUTOSIZE_USEHEADER
)
4143 column
->SetWidth(ComputeMinHeaderWidth(column
));
4145 wxColWidthInfo
*colWidthInfo
= new wxColWidthInfo();
4147 bool insert
= (col
>= 0) && ((size_t)col
< m_columns
.GetCount());
4150 wxListHeaderDataList::compatibility_iterator
4151 node
= m_columns
.Item( col
);
4152 m_columns
.Insert( node
, column
);
4153 m_aColWidths
.Insert( colWidthInfo
, col
);
4157 m_columns
.Append( column
);
4158 m_aColWidths
.Add( colWidthInfo
);
4163 // update all the items
4164 for ( size_t i
= 0; i
< m_lines
.GetCount(); i
++ )
4166 wxListLineData
* const line
= GetLine(i
);
4167 wxListItemData
* const data
= new wxListItemData(this);
4169 line
->m_items
.Insert(col
, data
);
4171 line
->m_items
.Append(data
);
4175 // invalidate it as it has to be recalculated
4180 int wxListMainWindow::GetItemWidthWithImage(wxListItem
* item
)
4183 wxClientDC
dc(this);
4185 dc
.SetFont( GetFont() );
4187 if (item
->GetImage() != -1)
4190 GetImageSize( item
->GetImage(), ix
, iy
);
4194 if (!item
->GetText().empty())
4197 dc
.GetTextExtent( item
->GetText(), &w
, NULL
);
4204 // ----------------------------------------------------------------------------
4206 // ----------------------------------------------------------------------------
4208 static wxListCtrlCompare list_ctrl_compare_func_2
;
4209 static wxIntPtr list_ctrl_compare_data
;
4211 int LINKAGEMODE
list_ctrl_compare_func_1( wxListLineData
**arg1
, wxListLineData
**arg2
)
4213 wxListLineData
*line1
= *arg1
;
4214 wxListLineData
*line2
= *arg2
;
4216 line1
->GetItem( 0, item
);
4217 wxUIntPtr data1
= item
.m_data
;
4218 line2
->GetItem( 0, item
);
4219 wxUIntPtr data2
= item
.m_data
;
4220 return list_ctrl_compare_func_2( data1
, data2
, list_ctrl_compare_data
);
4223 void wxListMainWindow::SortItems( wxListCtrlCompare fn
, wxIntPtr data
)
4225 // selections won't make sense any more after sorting the items so reset
4227 HighlightAll(false);
4230 list_ctrl_compare_func_2
= fn
;
4231 list_ctrl_compare_data
= data
;
4232 m_lines
.Sort( list_ctrl_compare_func_1
);
4236 // ----------------------------------------------------------------------------
4238 // ----------------------------------------------------------------------------
4240 void wxListMainWindow::OnScroll(wxScrollWinEvent
& event
)
4242 // update our idea of which lines are shown when we redraw the window the
4244 ResetVisibleLinesRange();
4246 if ( event
.GetOrientation() == wxHORIZONTAL
&& HasHeader() )
4248 wxGenericListCtrl
* lc
= GetListCtrl();
4249 wxCHECK_RET( lc
, wxT("no listctrl window?") );
4251 if (lc
->m_headerWin
) // when we use wxLC_NO_HEADER, m_headerWin==NULL
4253 lc
->m_headerWin
->Refresh();
4254 lc
->m_headerWin
->Update();
4259 int wxListMainWindow::GetCountPerPage() const
4261 if ( !m_linesPerPage
)
4263 wxConstCast(this, wxListMainWindow
)->
4264 m_linesPerPage
= GetClientSize().y
/ GetLineHeight();
4267 return m_linesPerPage
;
4270 void wxListMainWindow::GetVisibleLinesRange(size_t *from
, size_t *to
)
4272 wxASSERT_MSG( InReportView(), wxT("this is for report mode only") );
4274 if ( m_lineFrom
== (size_t)-1 )
4276 size_t count
= GetItemCount();
4279 m_lineFrom
= GetListCtrl()->GetScrollPos(wxVERTICAL
);
4281 // this may happen if SetScrollbars() hadn't been called yet
4282 if ( m_lineFrom
>= count
)
4283 m_lineFrom
= count
- 1;
4285 // we redraw one extra line but this is needed to make the redrawing
4286 // logic work when there is a fractional number of lines on screen
4287 m_lineTo
= m_lineFrom
+ m_linesPerPage
;
4288 if ( m_lineTo
>= count
)
4289 m_lineTo
= count
- 1;
4291 else // empty control
4294 m_lineTo
= (size_t)-1;
4298 wxASSERT_MSG( IsEmpty() ||
4299 (m_lineFrom
<= m_lineTo
&& m_lineTo
< GetItemCount()),
4300 wxT("GetVisibleLinesRange() returns incorrect result") );
4308 // -------------------------------------------------------------------------------------
4309 // wxGenericListCtrl
4310 // -------------------------------------------------------------------------------------
4312 IMPLEMENT_DYNAMIC_CLASS(wxGenericListCtrl
, wxControl
)
4314 BEGIN_EVENT_TABLE(wxGenericListCtrl
,wxListCtrlBase
)
4315 EVT_SIZE(wxGenericListCtrl::OnSize
)
4316 EVT_SCROLLWIN(wxGenericListCtrl::OnScroll
)
4319 void wxGenericListCtrl::Init()
4321 m_imageListNormal
= NULL
;
4322 m_imageListSmall
= NULL
;
4323 m_imageListState
= NULL
;
4325 m_ownsImageListNormal
=
4326 m_ownsImageListSmall
=
4327 m_ownsImageListState
= false;
4333 wxGenericListCtrl::~wxGenericListCtrl()
4335 if (m_ownsImageListNormal
)
4336 delete m_imageListNormal
;
4337 if (m_ownsImageListSmall
)
4338 delete m_imageListSmall
;
4339 if (m_ownsImageListState
)
4340 delete m_imageListState
;
4343 void wxGenericListCtrl::CreateOrDestroyHeaderWindowAsNeeded()
4345 bool needs_header
= HasHeader();
4346 bool has_header
= (m_headerWin
!= NULL
);
4348 if (needs_header
== has_header
)
4353 m_headerWin
= new wxListHeaderWindow
4355 this, wxID_ANY
, m_mainWin
,
4360 wxRendererNative::Get().GetHeaderButtonHeight(this)
4365 #if defined( __WXMAC__ )
4366 static wxFont
font( wxOSX_SYSTEM_FONT_SMALL
);
4367 m_headerWin
->SetFont( font
);
4370 GetSizer()->Prepend( m_headerWin
, 0, wxGROW
);
4374 GetSizer()->Detach( m_headerWin
);
4376 wxDELETE(m_headerWin
);
4380 bool wxGenericListCtrl::Create(wxWindow
*parent
,
4385 const wxValidator
&validator
,
4386 const wxString
&name
)
4390 // just like in other ports, an assert will fail if the user doesn't give any type style:
4391 wxASSERT_MSG( (style
& wxLC_MASK_TYPE
),
4392 wxT("wxListCtrl style should have exactly one mode bit set") );
4394 if ( !wxListCtrlBase::Create( parent
, id
, pos
, size
,
4395 style
| wxVSCROLL
| wxHSCROLL
,
4400 style
&= ~wxBORDER_MASK
;
4401 style
|= wxBORDER_THEME
;
4404 m_mainWin
= new wxListMainWindow( this, wxID_ANY
, wxPoint(0, 0), size
, style
);
4406 SetTargetWindow( m_mainWin
);
4408 // We use the cursor keys for moving the selection, not scrolling, so call
4409 // this method to ensure wxScrollHelperEvtHandler doesn't catch all
4410 // keyboard events forwarded to us from wxListMainWindow.
4411 DisableKeyboardScrolling();
4413 wxBoxSizer
*sizer
= new wxBoxSizer( wxVERTICAL
);
4414 sizer
->Add( m_mainWin
, 1, wxGROW
);
4417 CreateOrDestroyHeaderWindowAsNeeded();
4419 SetInitialSize(size
);
4424 wxBorder
wxGenericListCtrl::GetDefaultBorder() const
4426 return wxBORDER_THEME
;
4429 #if defined(__WXMSW__) && !defined(__WXWINCE__) && !defined(__WXUNIVERSAL__)
4430 WXLRESULT
wxGenericListCtrl::MSWWindowProc(WXUINT nMsg
,
4434 WXLRESULT rc
= wxListCtrlBase::MSWWindowProc(nMsg
, wParam
, lParam
);
4436 // we need to process arrows ourselves for scrolling
4437 if ( nMsg
== WM_GETDLGCODE
)
4439 rc
|= DLGC_WANTARROWS
;
4446 wxSize
wxGenericListCtrl::GetSizeAvailableForScrollTarget(const wxSize
& size
)
4448 wxSize newsize
= size
;
4450 newsize
.y
-= m_headerWin
->GetSize().y
;
4455 void wxGenericListCtrl::OnScroll(wxScrollWinEvent
& event
)
4457 // update our idea of which lines are shown when we redraw
4458 // the window the next time
4459 m_mainWin
->ResetVisibleLinesRange();
4461 HandleOnScroll( event
);
4463 if ( event
.GetOrientation() == wxHORIZONTAL
&& HasHeader() )
4465 m_headerWin
->Refresh();
4466 m_headerWin
->Update();
4470 void wxGenericListCtrl::SetSingleStyle( long style
, bool add
)
4472 wxASSERT_MSG( !(style
& wxLC_VIRTUAL
),
4473 wxT("wxLC_VIRTUAL can't be [un]set") );
4475 long flag
= GetWindowStyle();
4479 if (style
& wxLC_MASK_TYPE
)
4480 flag
&= ~(wxLC_MASK_TYPE
| wxLC_VIRTUAL
);
4481 if (style
& wxLC_MASK_ALIGN
)
4482 flag
&= ~wxLC_MASK_ALIGN
;
4483 if (style
& wxLC_MASK_SORT
)
4484 flag
&= ~wxLC_MASK_SORT
;
4492 // some styles can be set without recreating everything (as happens in
4493 // SetWindowStyleFlag() which calls wxListMainWindow::DeleteEverything())
4494 if ( !(style
& ~(wxLC_HRULES
| wxLC_VRULES
)) )
4497 wxWindow::SetWindowStyleFlag(flag
);
4501 SetWindowStyleFlag( flag
);
4505 void wxGenericListCtrl::SetWindowStyleFlag( long flag
)
4507 // we add wxHSCROLL and wxVSCROLL in ctor unconditionally and it never
4508 // makes sense to remove them as we'll always add scrollbars anyhow when
4510 flag
|= wxHSCROLL
| wxVSCROLL
;
4512 const bool wasInReportView
= HasFlag(wxLC_REPORT
);
4514 // update the window style first so that the header is created or destroyed
4515 // corresponding to the new style
4516 wxWindow::SetWindowStyleFlag( flag
);
4520 const bool inReportView
= (flag
& wxLC_REPORT
) != 0;
4521 if ( inReportView
!= wasInReportView
)
4523 // we need to notify the main window about this change as it must
4524 // update its data structures
4525 m_mainWin
->SetReportView(inReportView
);
4528 // m_mainWin->DeleteEverything(); wxMSW doesn't do that
4530 CreateOrDestroyHeaderWindowAsNeeded();
4532 GetSizer()->Layout();
4536 bool wxGenericListCtrl::GetColumn(int col
, wxListItem
&item
) const
4538 m_mainWin
->GetColumn( col
, item
);
4542 bool wxGenericListCtrl::SetColumn( int col
, const wxListItem
& item
)
4544 m_mainWin
->SetColumn( col
, item
);
4548 int wxGenericListCtrl::GetColumnWidth( int col
) const
4550 return m_mainWin
->GetColumnWidth( col
);
4553 bool wxGenericListCtrl::SetColumnWidth( int col
, int width
)
4555 m_mainWin
->SetColumnWidth( col
, width
);
4559 int wxGenericListCtrl::GetCountPerPage() const
4561 return m_mainWin
->GetCountPerPage(); // different from Windows ?
4564 bool wxGenericListCtrl::GetItem( wxListItem
&info
) const
4566 m_mainWin
->GetItem( info
);
4570 bool wxGenericListCtrl::SetItem( wxListItem
&info
)
4572 m_mainWin
->SetItem( info
);
4576 long wxGenericListCtrl::SetItem( long index
, int col
, const wxString
& label
, int imageId
)
4579 info
.m_text
= label
;
4580 info
.m_mask
= wxLIST_MASK_TEXT
;
4581 info
.m_itemId
= index
;
4585 info
.m_image
= imageId
;
4586 info
.m_mask
|= wxLIST_MASK_IMAGE
;
4589 m_mainWin
->SetItem(info
);
4593 int wxGenericListCtrl::GetItemState( long item
, long stateMask
) const
4595 return m_mainWin
->GetItemState( item
, stateMask
);
4598 bool wxGenericListCtrl::SetItemState( long item
, long state
, long stateMask
)
4600 m_mainWin
->SetItemState( item
, state
, stateMask
);
4605 wxGenericListCtrl::SetItemImage( long item
, int image
, int WXUNUSED(selImage
) )
4607 return SetItemColumnImage(item
, 0, image
);
4611 wxGenericListCtrl::SetItemColumnImage( long item
, long column
, int image
)
4614 info
.m_image
= image
;
4615 info
.m_mask
= wxLIST_MASK_IMAGE
;
4616 info
.m_itemId
= item
;
4617 info
.m_col
= column
;
4618 m_mainWin
->SetItem( info
);
4622 wxString
wxGenericListCtrl::GetItemText( long item
, int col
) const
4624 return m_mainWin
->GetItemText(item
, col
);
4627 void wxGenericListCtrl::SetItemText( long item
, const wxString
& str
)
4629 m_mainWin
->SetItemText(item
, str
);
4632 wxUIntPtr
wxGenericListCtrl::GetItemData( long item
) const
4635 info
.m_mask
= wxLIST_MASK_DATA
;
4636 info
.m_itemId
= item
;
4637 m_mainWin
->GetItem( info
);
4641 bool wxGenericListCtrl::SetItemPtrData( long item
, wxUIntPtr data
)
4644 info
.m_mask
= wxLIST_MASK_DATA
;
4645 info
.m_itemId
= item
;
4647 m_mainWin
->SetItem( info
);
4651 wxRect
wxGenericListCtrl::GetViewRect() const
4653 return m_mainWin
->GetViewRect();
4656 bool wxGenericListCtrl::GetItemRect(long item
, wxRect
& rect
, int code
) const
4658 return GetSubItemRect(item
, wxLIST_GETSUBITEMRECT_WHOLEITEM
, rect
, code
);
4661 bool wxGenericListCtrl::GetSubItemRect(long item
,
4664 int WXUNUSED(code
)) const
4666 if ( !m_mainWin
->GetSubItemRect( item
, subItem
, rect
) )
4669 if ( m_mainWin
->HasHeader() )
4670 rect
.y
+= m_headerWin
->GetSize().y
+ 1;
4675 bool wxGenericListCtrl::GetItemPosition( long item
, wxPoint
& pos
) const
4677 m_mainWin
->GetItemPosition( item
, pos
);
4681 bool wxGenericListCtrl::SetItemPosition( long WXUNUSED(item
), const wxPoint
& WXUNUSED(pos
) )
4686 int wxGenericListCtrl::GetItemCount() const
4688 return m_mainWin
->GetItemCount();
4691 int wxGenericListCtrl::GetColumnCount() const
4693 return m_mainWin
->GetColumnCount();
4696 void wxGenericListCtrl::SetItemSpacing( int spacing
, bool isSmall
)
4698 m_mainWin
->SetItemSpacing( spacing
, isSmall
);
4701 wxSize
wxGenericListCtrl::GetItemSpacing() const
4703 const int spacing
= m_mainWin
->GetItemSpacing(HasFlag(wxLC_SMALL_ICON
));
4705 return wxSize(spacing
, spacing
);
4708 #if WXWIN_COMPATIBILITY_2_6
4709 int wxGenericListCtrl::GetItemSpacing( bool isSmall
) const
4711 return m_mainWin
->GetItemSpacing( isSmall
);
4713 #endif // WXWIN_COMPATIBILITY_2_6
4715 void wxGenericListCtrl::SetItemTextColour( long item
, const wxColour
&col
)
4718 info
.m_itemId
= item
;
4719 info
.SetTextColour( col
);
4720 m_mainWin
->SetItem( info
);
4723 wxColour
wxGenericListCtrl::GetItemTextColour( long item
) const
4726 info
.m_itemId
= item
;
4727 m_mainWin
->GetItem( info
);
4728 return info
.GetTextColour();
4731 void wxGenericListCtrl::SetItemBackgroundColour( long item
, const wxColour
&col
)
4734 info
.m_itemId
= item
;
4735 info
.SetBackgroundColour( col
);
4736 m_mainWin
->SetItem( info
);
4739 wxColour
wxGenericListCtrl::GetItemBackgroundColour( long item
) const
4742 info
.m_itemId
= item
;
4743 m_mainWin
->GetItem( info
);
4744 return info
.GetBackgroundColour();
4747 void wxGenericListCtrl::SetItemFont( long item
, const wxFont
&f
)
4750 info
.m_itemId
= item
;
4752 m_mainWin
->SetItem( info
);
4755 wxFont
wxGenericListCtrl::GetItemFont( long item
) const
4758 info
.m_itemId
= item
;
4759 m_mainWin
->GetItem( info
);
4760 return info
.GetFont();
4763 int wxGenericListCtrl::GetSelectedItemCount() const
4765 return m_mainWin
->GetSelectedItemCount();
4768 wxColour
wxGenericListCtrl::GetTextColour() const
4770 return GetForegroundColour();
4773 void wxGenericListCtrl::SetTextColour(const wxColour
& col
)
4775 SetForegroundColour(col
);
4778 long wxGenericListCtrl::GetTopItem() const
4781 m_mainWin
->GetVisibleLinesRange(&top
, NULL
);
4785 long wxGenericListCtrl::GetNextItem( long item
, int geom
, int state
) const
4787 return m_mainWin
->GetNextItem( item
, geom
, state
);
4790 wxImageList
*wxGenericListCtrl::GetImageList(int which
) const
4792 if (which
== wxIMAGE_LIST_NORMAL
)
4793 return m_imageListNormal
;
4794 else if (which
== wxIMAGE_LIST_SMALL
)
4795 return m_imageListSmall
;
4796 else if (which
== wxIMAGE_LIST_STATE
)
4797 return m_imageListState
;
4802 void wxGenericListCtrl::SetImageList( wxImageList
*imageList
, int which
)
4804 if ( which
== wxIMAGE_LIST_NORMAL
)
4806 if (m_ownsImageListNormal
)
4807 delete m_imageListNormal
;
4808 m_imageListNormal
= imageList
;
4809 m_ownsImageListNormal
= false;
4811 else if ( which
== wxIMAGE_LIST_SMALL
)
4813 if (m_ownsImageListSmall
)
4814 delete m_imageListSmall
;
4815 m_imageListSmall
= imageList
;
4816 m_ownsImageListSmall
= false;
4818 else if ( which
== wxIMAGE_LIST_STATE
)
4820 if (m_ownsImageListState
)
4821 delete m_imageListState
;
4822 m_imageListState
= imageList
;
4823 m_ownsImageListState
= false;
4826 m_mainWin
->SetImageList( imageList
, which
);
4829 void wxGenericListCtrl::AssignImageList(wxImageList
*imageList
, int which
)
4831 SetImageList(imageList
, which
);
4832 if ( which
== wxIMAGE_LIST_NORMAL
)
4833 m_ownsImageListNormal
= true;
4834 else if ( which
== wxIMAGE_LIST_SMALL
)
4835 m_ownsImageListSmall
= true;
4836 else if ( which
== wxIMAGE_LIST_STATE
)
4837 m_ownsImageListState
= true;
4840 bool wxGenericListCtrl::Arrange( int WXUNUSED(flag
) )
4845 bool wxGenericListCtrl::DeleteItem( long item
)
4847 m_mainWin
->DeleteItem( item
);
4851 bool wxGenericListCtrl::DeleteAllItems()
4853 m_mainWin
->DeleteAllItems();
4857 bool wxGenericListCtrl::DeleteAllColumns()
4859 size_t count
= m_mainWin
->m_columns
.GetCount();
4860 for ( size_t n
= 0; n
< count
; n
++ )
4865 void wxGenericListCtrl::ClearAll()
4867 m_mainWin
->DeleteEverything();
4870 bool wxGenericListCtrl::DeleteColumn( int col
)
4872 m_mainWin
->DeleteColumn( col
);
4874 // if we don't have the header any longer, we need to relayout the window
4875 // if ( !GetColumnCount() )
4878 // Ensure that the non-existent columns are really removed from display.
4884 wxTextCtrl
*wxGenericListCtrl::EditLabel(long item
,
4885 wxClassInfo
* textControlClass
)
4887 return m_mainWin
->EditLabel( item
, textControlClass
);
4890 wxTextCtrl
*wxGenericListCtrl::GetEditControl() const
4892 return m_mainWin
->GetEditControl();
4895 bool wxGenericListCtrl::EnsureVisible( long item
)
4897 m_mainWin
->EnsureVisible( item
);
4901 long wxGenericListCtrl::FindItem( long start
, const wxString
& str
, bool partial
)
4903 return m_mainWin
->FindItem( start
, str
, partial
);
4906 long wxGenericListCtrl::FindItem( long start
, wxUIntPtr data
)
4908 return m_mainWin
->FindItem( start
, data
);
4911 long wxGenericListCtrl::FindItem( long WXUNUSED(start
), const wxPoint
& pt
,
4912 int WXUNUSED(direction
))
4914 return m_mainWin
->FindItem( pt
);
4917 // TODO: sub item hit testing
4918 long wxGenericListCtrl::HitTest(const wxPoint
& point
, int& flags
, long *) const
4920 return m_mainWin
->HitTest( (int)point
.x
, (int)point
.y
, flags
);
4923 long wxGenericListCtrl::InsertItem( wxListItem
& info
)
4925 m_mainWin
->InsertItem( info
);
4926 return info
.m_itemId
;
4929 long wxGenericListCtrl::InsertItem( long index
, const wxString
&label
)
4932 info
.m_text
= label
;
4933 info
.m_mask
= wxLIST_MASK_TEXT
;
4934 info
.m_itemId
= index
;
4935 return InsertItem( info
);
4938 long wxGenericListCtrl::InsertItem( long index
, int imageIndex
)
4941 info
.m_mask
= wxLIST_MASK_IMAGE
;
4942 info
.m_image
= imageIndex
;
4943 info
.m_itemId
= index
;
4944 return InsertItem( info
);
4947 long wxGenericListCtrl::InsertItem( long index
, const wxString
&label
, int imageIndex
)
4950 info
.m_text
= label
;
4951 info
.m_image
= imageIndex
;
4952 info
.m_mask
= wxLIST_MASK_TEXT
;
4953 if (imageIndex
> -1)
4954 info
.m_mask
|= wxLIST_MASK_IMAGE
;
4955 info
.m_itemId
= index
;
4956 return InsertItem( info
);
4959 long wxGenericListCtrl::DoInsertColumn( long col
, const wxListItem
&item
)
4961 wxCHECK_MSG( InReportView(), -1, wxT("can't add column in non report mode") );
4963 m_mainWin
->InsertColumn( col
, item
);
4965 // NOTE: if wxLC_NO_HEADER was given, then we are in report view mode but
4966 // still have m_headerWin==NULL
4968 m_headerWin
->Refresh();
4973 bool wxGenericListCtrl::ScrollList( int dx
, int dy
)
4975 return m_mainWin
->ScrollList(dx
, dy
);
4979 // fn is a function which takes 3 long arguments: item1, item2, data.
4980 // item1 is the long data associated with a first item (NOT the index).
4981 // item2 is the long data associated with a second item (NOT the index).
4982 // data is the same value as passed to SortItems.
4983 // The return value is a negative number if the first item should precede the second
4984 // item, a positive number of the second item should precede the first,
4985 // or zero if the two items are equivalent.
4986 // data is arbitrary data to be passed to the sort function.
4988 bool wxGenericListCtrl::SortItems( wxListCtrlCompare fn
, wxIntPtr data
)
4990 m_mainWin
->SortItems( fn
, data
);
4994 // ----------------------------------------------------------------------------
4996 // ----------------------------------------------------------------------------
4998 void wxGenericListCtrl::OnSize(wxSizeEvent
& WXUNUSED(event
))
5000 if (!m_mainWin
) return;
5002 // We need to override OnSize so that our scrolled
5003 // window a) does call Layout() to use sizers for
5004 // positioning the controls but b) does not query
5005 // the sizer for their size and use that for setting
5006 // the scrollable area as set that ourselves by
5007 // calling SetScrollbar() further down.
5011 m_mainWin
->RecalculatePositions();
5016 void wxGenericListCtrl::OnInternalIdle()
5018 wxWindow::OnInternalIdle();
5020 if (m_mainWin
->m_dirty
)
5021 m_mainWin
->RecalculatePositions();
5024 // ----------------------------------------------------------------------------
5026 // ----------------------------------------------------------------------------
5028 bool wxGenericListCtrl::SetBackgroundColour( const wxColour
&colour
)
5032 m_mainWin
->SetBackgroundColour( colour
);
5033 m_mainWin
->m_dirty
= true;
5039 bool wxGenericListCtrl::SetForegroundColour( const wxColour
&colour
)
5041 if ( !wxWindow::SetForegroundColour( colour
) )
5046 m_mainWin
->SetForegroundColour( colour
);
5047 m_mainWin
->m_dirty
= true;
5051 m_headerWin
->SetForegroundColour( colour
);
5056 bool wxGenericListCtrl::SetFont( const wxFont
&font
)
5058 if ( !wxWindow::SetFont( font
) )
5063 m_mainWin
->SetFont( font
);
5064 m_mainWin
->m_dirty
= true;
5069 m_headerWin
->SetFont( font
);
5070 // CalculateAndSetHeaderHeight();
5080 wxGenericListCtrl::GetClassDefaultAttributes(wxWindowVariant variant
)
5083 // Use the same color scheme as wxListBox
5084 return wxListBox::GetClassDefaultAttributes(variant
);
5086 wxUnusedVar(variant
);
5087 wxVisualAttributes attr
;
5088 attr
.colFg
= wxSystemSettings::GetColour(wxSYS_COLOUR_LISTBOXTEXT
);
5089 attr
.colBg
= wxSystemSettings::GetColour(wxSYS_COLOUR_LISTBOX
);
5090 attr
.font
= wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT
);
5095 // ----------------------------------------------------------------------------
5096 // methods forwarded to m_mainWin
5097 // ----------------------------------------------------------------------------
5099 #if wxUSE_DRAG_AND_DROP
5101 void wxGenericListCtrl::SetDropTarget( wxDropTarget
*dropTarget
)
5103 m_mainWin
->SetDropTarget( dropTarget
);
5106 wxDropTarget
*wxGenericListCtrl::GetDropTarget() const
5108 return m_mainWin
->GetDropTarget();
5113 bool wxGenericListCtrl::SetCursor( const wxCursor
&cursor
)
5115 return m_mainWin
? m_mainWin
->wxWindow::SetCursor(cursor
) : false;
5118 wxColour
wxGenericListCtrl::GetBackgroundColour() const
5120 return m_mainWin
? m_mainWin
->GetBackgroundColour() : wxColour();
5123 wxColour
wxGenericListCtrl::GetForegroundColour() const
5125 return m_mainWin
? m_mainWin
->GetForegroundColour() : wxColour();
5128 bool wxGenericListCtrl::DoPopupMenu( wxMenu
*menu
, int x
, int y
)
5131 return m_mainWin
->PopupMenu( menu
, x
, y
);
5137 void wxGenericListCtrl::DoClientToScreen( int *x
, int *y
) const
5139 // It's not clear whether this can be called before m_mainWin is created
5140 // but it seems better to be on the safe side and check.
5142 m_mainWin
->DoClientToScreen(x
, y
);
5144 wxListCtrlBase::DoClientToScreen(x
, y
);
5147 void wxGenericListCtrl::DoScreenToClient( int *x
, int *y
) const
5149 // At least in wxGTK/Univ build this method can be called before m_mainWin
5150 // is created so avoid crashes in this case.
5152 m_mainWin
->DoScreenToClient(x
, y
);
5154 wxListCtrlBase::DoScreenToClient(x
, y
);
5157 void wxGenericListCtrl::SetFocus()
5159 // The test in window.cpp fails as we are a composite
5160 // window, so it checks against "this", but not m_mainWin.
5161 if ( DoFindFocus() != this )
5162 m_mainWin
->SetFocus();
5165 wxSize
wxGenericListCtrl::DoGetBestClientSize() const
5167 // Something is better than nothing even if this is completely arbitrary.
5168 wxSize
sizeBest(100, 80);
5170 if ( !InReportView() )
5172 // Ensure that our minimal width is at least big enough to show all our
5173 // items. This is important for wxListbook to size itself correctly.
5175 // Remember the offset of the first item: this corresponds to the
5176 // margins around the item so we will add it to the minimal size below
5177 // to ensure that we have equal margins on all sides.
5180 // We can iterate over all items as there shouldn't be too many of them
5181 // in non-report view. If it ever becomes a problem, we could examine
5182 // just the first few items probably, the determination of the best
5183 // size is less important if we will need scrollbars anyhow.
5184 for ( int n
= 0; n
< GetItemCount(); n
++ )
5186 const wxRect itemRect
= m_mainWin
->GetLineRect(n
);
5189 // Remember the position of the first item as all the rest are
5190 // offset by at least this number of pixels too.
5191 ofs
= itemRect
.GetPosition();
5194 sizeBest
.IncTo(itemRect
.GetSize());
5197 sizeBest
.IncBy(2*ofs
);
5200 // If we have the scrollbars we need to account for them too. And to
5201 // make sure the scrollbars status is up to date we need to call this
5202 // function to set them.
5203 m_mainWin
->RecalculatePositions(true /* no refresh */);
5205 // Unfortunately we can't use wxWindow::HasScrollbar() here as we need
5206 // to use m_mainWin client/virtual size for determination of whether we
5207 // use scrollbars and not the size of this window itself. Maybe that
5208 // function should be extended to work correctly in the case when our
5209 // scrollbars manage a different window from this one but currently it
5211 const wxSize sizeClient
= m_mainWin
->GetClientSize();
5212 const wxSize sizeVirt
= m_mainWin
->GetVirtualSize();
5214 if ( sizeVirt
.x
> sizeClient
.x
/* HasScrollbar(wxHORIZONTAL) */ )
5215 sizeBest
.y
+= wxSystemSettings::GetMetric(wxSYS_HSCROLL_Y
);
5217 if ( sizeVirt
.y
> sizeClient
.y
/* HasScrollbar(wxVERTICAL) */ )
5218 sizeBest
.x
+= wxSystemSettings::GetMetric(wxSYS_VSCROLL_X
);
5224 // ----------------------------------------------------------------------------
5225 // virtual list control support
5226 // ----------------------------------------------------------------------------
5228 wxString
wxGenericListCtrl::OnGetItemText(long WXUNUSED(item
), long WXUNUSED(col
)) const
5230 // this is a pure virtual function, in fact - which is not really pure
5231 // because the controls which are not virtual don't need to implement it
5232 wxFAIL_MSG( wxT("wxGenericListCtrl::OnGetItemText not supposed to be called") );
5234 return wxEmptyString
;
5237 int wxGenericListCtrl::OnGetItemImage(long WXUNUSED(item
)) const
5239 wxCHECK_MSG(!GetImageList(wxIMAGE_LIST_SMALL
),
5241 wxT("List control has an image list, OnGetItemImage or OnGetItemColumnImage should be overridden."));
5245 int wxGenericListCtrl::OnGetItemColumnImage(long item
, long column
) const
5248 return OnGetItemImage(item
);
5254 wxGenericListCtrl::OnGetItemAttr(long WXUNUSED_UNLESS_DEBUG(item
)) const
5256 wxASSERT_MSG( item
>= 0 && item
< GetItemCount(),
5257 wxT("invalid item index in OnGetItemAttr()") );
5259 // no attributes by default
5263 void wxGenericListCtrl::SetItemCount(long count
)
5265 wxASSERT_MSG( IsVirtual(), wxT("this is for virtual controls only") );
5267 m_mainWin
->SetItemCount(count
);
5270 void wxGenericListCtrl::RefreshItem(long item
)
5272 m_mainWin
->RefreshLine(item
);
5275 void wxGenericListCtrl::RefreshItems(long itemFrom
, long itemTo
)
5277 m_mainWin
->RefreshLines(itemFrom
, itemTo
);
5280 // Generic wxListCtrl is more or less a container for two other
5281 // windows which drawings are done upon. These are namely
5282 // 'm_headerWin' and 'm_mainWin'.
5283 // Here we override 'virtual wxWindow::Refresh()' to mimic the
5284 // behaviour wxListCtrl has under wxMSW.
5286 void wxGenericListCtrl::Refresh(bool eraseBackground
, const wxRect
*rect
)
5290 // The easy case, no rectangle specified.
5292 m_headerWin
->Refresh(eraseBackground
);
5295 m_mainWin
->Refresh(eraseBackground
);
5299 // Refresh the header window
5302 wxRect rectHeader
= m_headerWin
->GetRect();
5303 rectHeader
.Intersect(*rect
);
5304 if (rectHeader
.GetWidth() && rectHeader
.GetHeight())
5307 m_headerWin
->GetPosition(&x
, &y
);
5308 rectHeader
.Offset(-x
, -y
);
5309 m_headerWin
->Refresh(eraseBackground
, &rectHeader
);
5313 // Refresh the main window
5316 wxRect rectMain
= m_mainWin
->GetRect();
5317 rectMain
.Intersect(*rect
);
5318 if (rectMain
.GetWidth() && rectMain
.GetHeight())
5321 m_mainWin
->GetPosition(&x
, &y
);
5322 rectMain
.Offset(-x
, -y
);
5323 m_mainWin
->Refresh(eraseBackground
, &rectMain
);
5329 void wxGenericListCtrl::Update()
5333 if ( m_mainWin
->m_dirty
)
5334 m_mainWin
->RecalculatePositions();
5336 m_mainWin
->Update();
5340 m_headerWin
->Update();
5343 #endif // wxUSE_LISTCTRL