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
)
939 void wxListHeaderWindow::Init()
941 m_currentCursor
= NULL
;
942 m_isDragging
= false;
944 m_sendSetColumnWidth
= false;
947 wxListHeaderWindow::wxListHeaderWindow()
952 m_resizeCursor
= NULL
;
955 wxListHeaderWindow::wxListHeaderWindow( wxWindow
*win
,
957 wxListMainWindow
*owner
,
961 const wxString
&name
)
962 : wxWindow( win
, id
, pos
, size
, style
, name
)
967 m_resizeCursor
= new wxCursor( wxCURSOR_SIZEWE
);
970 wxVisualAttributes attr
= wxPanel::GetClassDefaultAttributes();
971 SetOwnForegroundColour( attr
.colFg
);
972 SetOwnBackgroundColour( attr
.colBg
);
974 SetOwnFont( attr
.font
);
976 SetOwnForegroundColour( wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT
));
977 SetOwnBackgroundColour( wxSystemSettings::GetColour(wxSYS_COLOUR_BTNFACE
));
979 SetOwnFont( wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT
));
983 wxListHeaderWindow::~wxListHeaderWindow()
985 delete m_resizeCursor
;
988 #ifdef __WXUNIVERSAL__
989 #include "wx/univ/renderer.h"
990 #include "wx/univ/theme.h"
993 // shift the DC origin to match the position of the main window horz
994 // scrollbar: this allows us to always use logical coords
995 void wxListHeaderWindow::AdjustDC(wxDC
& dc
)
997 wxGenericListCtrl
*parent
= m_owner
->GetListCtrl();
1000 parent
->GetScrollPixelsPerUnit( &xpix
, NULL
);
1003 parent
->GetViewStart( &view_start
, NULL
);
1008 dc
.GetDeviceOrigin( &org_x
, &org_y
);
1010 // account for the horz scrollbar offset
1012 if (GetLayoutDirection() == wxLayout_RightToLeft
)
1014 // Maybe we just have to check for m_signX
1015 // in the DC, but I leave the #ifdef __WXGTK__
1017 dc
.SetDeviceOrigin( org_x
+ (view_start
* xpix
), org_y
);
1021 dc
.SetDeviceOrigin( org_x
- (view_start
* xpix
), org_y
);
1024 void wxListHeaderWindow::OnPaint( wxPaintEvent
&WXUNUSED(event
) )
1026 wxGenericListCtrl
*parent
= m_owner
->GetListCtrl();
1028 wxPaintDC
dc( this );
1032 dc
.SetFont( GetFont() );
1034 // width and height of the entire header window
1036 GetClientSize( &w
, &h
);
1037 parent
->CalcUnscrolledPosition(w
, 0, &w
, NULL
);
1039 dc
.SetBackgroundMode(wxBRUSHSTYLE_TRANSPARENT
);
1040 dc
.SetTextForeground(GetForegroundColour());
1042 int x
= HEADER_OFFSET_X
;
1043 int numColumns
= m_owner
->GetColumnCount();
1045 for ( int i
= 0; i
< numColumns
&& x
< w
; i
++ )
1047 m_owner
->GetColumn( i
, item
);
1048 int wCol
= item
.m_width
;
1054 if (!m_parent
->IsEnabled())
1055 flags
|= wxCONTROL_DISABLED
;
1057 // NB: The code below is not really Mac-specific, but since we are close
1058 // to 2.8 release and I don't have time to test on other platforms, I
1059 // defined this only for wxMac. If this behaviour is desired on
1060 // other platforms, please go ahead and revise or remove the #ifdef.
1062 if ( !m_owner
->IsVirtual() && (item
.m_mask
& wxLIST_MASK_STATE
) &&
1063 (item
.m_state
& wxLIST_STATE_SELECTED
) )
1064 flags
|= wxCONTROL_SELECTED
;
1068 flags
|= wxCONTROL_SPECIAL
; // mark as first column
1070 wxRendererNative::Get().DrawHeaderButton
1074 wxRect(x
, HEADER_OFFSET_Y
, cw
, ch
),
1078 // see if we have enough space for the column label
1080 // for this we need the width of the text
1083 dc
.GetTextExtent(item
.GetText(), &wLabel
, &hLabel
);
1084 wLabel
+= 2 * EXTRA_WIDTH
;
1086 // and the width of the icon, if any
1087 int ix
= 0, iy
= 0; // init them just to suppress the compiler warnings
1088 const int image
= item
.m_image
;
1089 wxImageList
*imageList
;
1092 imageList
= m_owner
->GetSmallImageList();
1095 imageList
->GetSize(image
, ix
, iy
);
1096 wLabel
+= ix
+ HEADER_IMAGE_MARGIN_IN_REPORT_MODE
;
1104 // ignore alignment if there is not enough space anyhow
1106 switch ( wLabel
< cw
? item
.GetAlign() : wxLIST_FORMAT_LEFT
)
1109 wxFAIL_MSG( wxT("unknown list item format") );
1112 case wxLIST_FORMAT_LEFT
:
1116 case wxLIST_FORMAT_RIGHT
:
1117 xAligned
= x
+ cw
- wLabel
;
1120 case wxLIST_FORMAT_CENTER
:
1121 xAligned
= x
+ (cw
- wLabel
) / 2;
1125 // draw the text and image clipping them so that they
1126 // don't overwrite the column boundary
1127 wxDCClipper
clipper(dc
, x
, HEADER_OFFSET_Y
, cw
, h
);
1129 // if we have an image, draw it on the right of the label
1136 xAligned
+ wLabel
- ix
- HEADER_IMAGE_MARGIN_IN_REPORT_MODE
,
1137 HEADER_OFFSET_Y
+ (h
- iy
)/2,
1138 wxIMAGELIST_DRAW_TRANSPARENT
1142 dc
.DrawText( item
.GetText(),
1143 xAligned
+ EXTRA_WIDTH
, (h
- hLabel
) / 2 );
1148 // Fill in what's missing to the right of the columns, otherwise we will
1149 // leave an unpainted area when columns are removed (and it looks better)
1152 wxRendererNative::Get().DrawHeaderButton
1156 wxRect(x
, HEADER_OFFSET_Y
, w
- x
, h
),
1157 wxCONTROL_DIRTY
// mark as last column
1162 void wxListHeaderWindow::OnInternalIdle()
1164 wxWindow::OnInternalIdle();
1166 if (m_sendSetColumnWidth
)
1168 m_owner
->SetColumnWidth( m_colToSend
, m_widthToSend
);
1169 m_sendSetColumnWidth
= false;
1173 void wxListHeaderWindow::DrawCurrent()
1176 // m_owner->SetColumnWidth( m_column, m_currentX - m_minX );
1177 m_sendSetColumnWidth
= true;
1178 m_colToSend
= m_column
;
1179 m_widthToSend
= m_currentX
- m_minX
;
1181 int x1
= m_currentX
;
1183 m_owner
->ClientToScreen( &x1
, &y1
);
1185 int x2
= m_currentX
;
1187 m_owner
->GetClientSize( NULL
, &y2
);
1188 m_owner
->ClientToScreen( &x2
, &y2
);
1191 dc
.SetLogicalFunction( wxINVERT
);
1192 dc
.SetPen( wxPen(*wxBLACK
, 2) );
1193 dc
.SetBrush( *wxTRANSPARENT_BRUSH
);
1197 dc
.DrawLine( x1
, y1
, x2
, y2
);
1199 dc
.SetLogicalFunction( wxCOPY
);
1201 dc
.SetPen( wxNullPen
);
1202 dc
.SetBrush( wxNullBrush
);
1206 void wxListHeaderWindow::OnMouse( wxMouseEvent
&event
)
1208 wxGenericListCtrl
*parent
= m_owner
->GetListCtrl();
1210 // we want to work with logical coords
1212 parent
->CalcUnscrolledPosition(event
.GetX(), 0, &x
, NULL
);
1213 int y
= event
.GetY();
1217 SendListEvent(wxEVT_COMMAND_LIST_COL_DRAGGING
, event
.GetPosition());
1219 // we don't draw the line beyond our window, but we allow dragging it
1222 GetClientSize( &w
, NULL
);
1223 parent
->CalcUnscrolledPosition(w
, 0, &w
, NULL
);
1226 // erase the line if it was drawn
1227 if ( m_currentX
< w
)
1230 if (event
.ButtonUp())
1233 m_isDragging
= false;
1235 m_owner
->SetColumnWidth( m_column
, m_currentX
- m_minX
);
1236 SendListEvent(wxEVT_COMMAND_LIST_COL_END_DRAG
, event
.GetPosition());
1243 m_currentX
= m_minX
+ 7;
1245 // draw in the new location
1246 if ( m_currentX
< w
)
1250 else // not dragging
1253 bool hit_border
= false;
1255 // end of the current column
1258 // find the column where this event occurred
1260 countCol
= m_owner
->GetColumnCount();
1261 for (col
= 0; col
< countCol
; col
++)
1263 xpos
+= m_owner
->GetColumnWidth( col
);
1266 if ( (abs(x
-xpos
) < 3) && (y
< 22) )
1268 // near the column border
1275 // inside the column
1282 if ( col
== countCol
)
1285 if (event
.LeftDown() || event
.RightUp())
1287 if (hit_border
&& event
.LeftDown())
1289 if ( SendListEvent(wxEVT_COMMAND_LIST_COL_BEGIN_DRAG
,
1290 event
.GetPosition()) )
1292 m_isDragging
= true;
1297 //else: column resizing was vetoed by the user code
1299 else // click on a column
1301 // record the selected state of the columns
1302 if (event
.LeftDown())
1304 for (int i
=0; i
< m_owner
->GetColumnCount(); i
++)
1307 m_owner
->GetColumn(i
, colItem
);
1308 long state
= colItem
.GetState();
1310 colItem
.SetState(state
| wxLIST_STATE_SELECTED
);
1312 colItem
.SetState(state
& ~wxLIST_STATE_SELECTED
);
1313 m_owner
->SetColumn(i
, colItem
);
1317 SendListEvent( event
.LeftDown()
1318 ? wxEVT_COMMAND_LIST_COL_CLICK
1319 : wxEVT_COMMAND_LIST_COL_RIGHT_CLICK
,
1320 event
.GetPosition());
1323 else if (event
.Moving())
1328 setCursor
= m_currentCursor
== wxSTANDARD_CURSOR
;
1329 m_currentCursor
= m_resizeCursor
;
1333 setCursor
= m_currentCursor
!= wxSTANDARD_CURSOR
;
1334 m_currentCursor
= wxSTANDARD_CURSOR
;
1338 SetCursor(*m_currentCursor
);
1343 bool wxListHeaderWindow::SendListEvent(wxEventType type
, const wxPoint
& pos
)
1345 wxWindow
*parent
= GetParent();
1346 wxListEvent
le( type
, parent
->GetId() );
1347 le
.SetEventObject( parent
);
1348 le
.m_pointDrag
= pos
;
1350 // the position should be relative to the parent window, not
1351 // this one for compatibility with MSW and common sense: the
1352 // user code doesn't know anything at all about this header
1353 // window, so why should it get positions relative to it?
1354 le
.m_pointDrag
.y
-= GetSize().y
;
1356 le
.m_col
= m_column
;
1357 return !parent
->GetEventHandler()->ProcessEvent( le
) || le
.IsAllowed();
1360 //-----------------------------------------------------------------------------
1361 // wxListRenameTimer (internal)
1362 //-----------------------------------------------------------------------------
1364 wxListRenameTimer::wxListRenameTimer( wxListMainWindow
*owner
)
1369 void wxListRenameTimer::Notify()
1371 m_owner
->OnRenameTimer();
1374 //-----------------------------------------------------------------------------
1375 // wxListTextCtrlWrapper (internal)
1376 //-----------------------------------------------------------------------------
1378 BEGIN_EVENT_TABLE(wxListTextCtrlWrapper
, wxEvtHandler
)
1379 EVT_CHAR (wxListTextCtrlWrapper::OnChar
)
1380 EVT_KEY_UP (wxListTextCtrlWrapper::OnKeyUp
)
1381 EVT_KILL_FOCUS (wxListTextCtrlWrapper::OnKillFocus
)
1384 wxListTextCtrlWrapper::wxListTextCtrlWrapper(wxListMainWindow
*owner
,
1387 : m_startValue(owner
->GetItemText(itemEdit
)),
1388 m_itemEdited(itemEdit
)
1392 m_aboutToFinish
= false;
1394 wxGenericListCtrl
*parent
= m_owner
->GetListCtrl();
1396 wxRect rectLabel
= owner
->GetLineLabelRect(itemEdit
);
1398 parent
->CalcScrolledPosition(rectLabel
.x
, rectLabel
.y
,
1399 &rectLabel
.x
, &rectLabel
.y
);
1401 m_text
->Create(owner
, wxID_ANY
, m_startValue
,
1402 wxPoint(rectLabel
.x
-4,rectLabel
.y
-4),
1403 wxSize(rectLabel
.width
+11,rectLabel
.height
+8));
1406 m_text
->PushEventHandler(this);
1409 void wxListTextCtrlWrapper::EndEdit(EndReason reason
)
1411 m_aboutToFinish
= true;
1416 // Notify the owner about the changes
1419 // Even if vetoed, close the control (consistent with MSW)
1424 m_owner
->OnRenameCancelled(m_itemEdited
);
1430 // Don't generate any notifications for the control being destroyed
1431 // and don't set focus to it neither.
1437 void wxListTextCtrlWrapper::Finish( bool setfocus
)
1439 m_text
->RemoveEventHandler(this);
1440 m_owner
->ResetTextControl( m_text
);
1442 wxPendingDelete
.Append( this );
1445 m_owner
->SetFocus();
1448 bool wxListTextCtrlWrapper::AcceptChanges()
1450 const wxString value
= m_text
->GetValue();
1452 // notice that we should always call OnRenameAccept() to generate the "end
1453 // label editing" event, even if the user hasn't really changed anything
1454 if ( !m_owner
->OnRenameAccept(m_itemEdited
, value
) )
1456 // vetoed by the user
1460 // accepted, do rename the item (unless nothing changed)
1461 if ( value
!= m_startValue
)
1462 m_owner
->SetItemText(m_itemEdited
, value
);
1467 void wxListTextCtrlWrapper::OnChar( wxKeyEvent
&event
)
1469 if ( !CheckForEndEditKey(event
) )
1473 bool wxListTextCtrlWrapper::CheckForEndEditKey(const wxKeyEvent
& event
)
1475 switch ( event
.m_keyCode
)
1478 EndEdit( End_Accept
);
1482 EndEdit( End_Discard
);
1492 void wxListTextCtrlWrapper::OnKeyUp( wxKeyEvent
&event
)
1494 if (m_aboutToFinish
)
1496 // auto-grow the textctrl:
1497 wxSize parentSize
= m_owner
->GetSize();
1498 wxPoint myPos
= m_text
->GetPosition();
1499 wxSize mySize
= m_text
->GetSize();
1501 m_text
->GetTextExtent(m_text
->GetValue() + wxT("MM"), &sx
, &sy
);
1502 if (myPos
.x
+ sx
> parentSize
.x
)
1503 sx
= parentSize
.x
- myPos
.x
;
1506 m_text
->SetSize(sx
, wxDefaultCoord
);
1512 void wxListTextCtrlWrapper::OnKillFocus( wxFocusEvent
&event
)
1514 if ( !m_aboutToFinish
)
1516 if ( !AcceptChanges() )
1517 m_owner
->OnRenameCancelled( m_itemEdited
);
1522 // We must let the native text control handle focus
1526 //-----------------------------------------------------------------------------
1528 //-----------------------------------------------------------------------------
1530 BEGIN_EVENT_TABLE(wxListMainWindow
, wxWindow
)
1531 EVT_PAINT (wxListMainWindow::OnPaint
)
1532 EVT_MOUSE_EVENTS (wxListMainWindow::OnMouse
)
1533 EVT_CHAR_HOOK (wxListMainWindow::OnCharHook
)
1534 EVT_CHAR (wxListMainWindow::OnChar
)
1535 EVT_KEY_DOWN (wxListMainWindow::OnKeyDown
)
1536 EVT_KEY_UP (wxListMainWindow::OnKeyUp
)
1537 EVT_SET_FOCUS (wxListMainWindow::OnSetFocus
)
1538 EVT_KILL_FOCUS (wxListMainWindow::OnKillFocus
)
1539 EVT_SCROLLWIN (wxListMainWindow::OnScroll
)
1540 EVT_CHILD_FOCUS (wxListMainWindow::OnChildFocus
)
1543 void wxListMainWindow::Init()
1548 m_lineTo
= (size_t)-1;
1554 m_small_image_list
= NULL
;
1555 m_normal_image_list
= NULL
;
1557 m_small_spacing
= 30;
1558 m_normal_spacing
= 40;
1562 m_isCreated
= false;
1564 m_lastOnSame
= false;
1565 m_renameTimer
= new wxListRenameTimer( this );
1566 m_textctrlWrapper
= NULL
;
1570 m_lineSelectSingleOnUp
=
1571 m_lineBeforeLastClicked
= (size_t)-1;
1574 wxListMainWindow::wxListMainWindow()
1579 m_highlightUnfocusedBrush
= NULL
;
1582 wxListMainWindow::wxListMainWindow( wxWindow
*parent
,
1585 const wxSize
& size
)
1586 : wxWindow( parent
, id
, pos
, size
,
1587 wxWANTS_CHARS
| wxBORDER_NONE
)
1591 m_highlightBrush
= new wxBrush
1593 wxSystemSettings::GetColour
1595 wxSYS_COLOUR_HIGHLIGHT
1600 m_highlightUnfocusedBrush
= new wxBrush
1602 wxSystemSettings::GetColour
1604 wxSYS_COLOUR_BTNSHADOW
1609 wxVisualAttributes attr
= wxGenericListCtrl::GetClassDefaultAttributes();
1610 SetOwnForegroundColour( attr
.colFg
);
1611 SetOwnBackgroundColour( attr
.colBg
);
1613 SetOwnFont( attr
.font
);
1616 wxListMainWindow::~wxListMainWindow()
1618 if ( m_textctrlWrapper
)
1619 m_textctrlWrapper
->EndEdit(wxListTextCtrlWrapper::End_Destroy
);
1622 WX_CLEAR_LIST(wxListHeaderDataList
, m_columns
);
1623 WX_CLEAR_ARRAY(m_aColWidths
);
1625 delete m_highlightBrush
;
1626 delete m_highlightUnfocusedBrush
;
1627 delete m_renameTimer
;
1630 void wxListMainWindow::SetReportView(bool inReportView
)
1632 const size_t count
= m_lines
.size();
1633 for ( size_t n
= 0; n
< count
; n
++ )
1635 m_lines
[n
].SetReportView(inReportView
);
1639 void wxListMainWindow::CacheLineData(size_t line
)
1641 wxGenericListCtrl
*listctrl
= GetListCtrl();
1643 wxListLineData
*ld
= GetDummyLine();
1645 size_t countCol
= GetColumnCount();
1646 for ( size_t col
= 0; col
< countCol
; col
++ )
1648 ld
->SetText(col
, listctrl
->OnGetItemText(line
, col
));
1649 ld
->SetImage(col
, listctrl
->OnGetItemColumnImage(line
, col
));
1652 ld
->SetAttr(listctrl
->OnGetItemAttr(line
));
1655 wxListLineData
*wxListMainWindow::GetDummyLine() const
1657 wxASSERT_MSG( !IsEmpty(), wxT("invalid line index") );
1658 wxASSERT_MSG( IsVirtual(), wxT("GetDummyLine() shouldn't be called") );
1660 wxListMainWindow
*self
= wxConstCast(this, wxListMainWindow
);
1662 // we need to recreate the dummy line if the number of columns in the
1663 // control changed as it would have the incorrect number of fields
1665 if ( !m_lines
.IsEmpty() &&
1666 m_lines
[0].m_items
.GetCount() != (size_t)GetColumnCount() )
1668 self
->m_lines
.Clear();
1671 if ( m_lines
.IsEmpty() )
1673 wxListLineData
*line
= new wxListLineData(self
);
1674 self
->m_lines
.Add(line
);
1676 // don't waste extra memory -- there never going to be anything
1677 // else/more in this array
1678 self
->m_lines
.Shrink();
1684 // ----------------------------------------------------------------------------
1685 // line geometry (report mode only)
1686 // ----------------------------------------------------------------------------
1688 wxCoord
wxListMainWindow::GetLineHeight() const
1690 // we cache the line height as calling GetTextExtent() is slow
1691 if ( !m_lineHeight
)
1693 wxListMainWindow
*self
= wxConstCast(this, wxListMainWindow
);
1695 wxClientDC
dc( self
);
1696 dc
.SetFont( GetFont() );
1699 dc
.GetTextExtent(wxT("H"), NULL
, &y
);
1701 if ( m_small_image_list
&& m_small_image_list
->GetImageCount() )
1704 m_small_image_list
->GetSize(0, iw
, ih
);
1709 self
->m_lineHeight
= y
+ LINE_SPACING
;
1712 return m_lineHeight
;
1715 wxCoord
wxListMainWindow::GetLineY(size_t line
) const
1717 wxASSERT_MSG( InReportView(), wxT("only works in report mode") );
1719 return LINE_SPACING
+ line
* GetLineHeight();
1722 wxRect
wxListMainWindow::GetLineRect(size_t line
) const
1724 if ( !InReportView() )
1725 return GetLine(line
)->m_gi
->m_rectAll
;
1728 rect
.x
= HEADER_OFFSET_X
;
1729 rect
.y
= GetLineY(line
);
1730 rect
.width
= GetHeaderWidth();
1731 rect
.height
= GetLineHeight();
1736 wxRect
wxListMainWindow::GetLineLabelRect(size_t line
) const
1738 if ( !InReportView() )
1739 return GetLine(line
)->m_gi
->m_rectLabel
;
1742 wxListLineData
*data
= GetLine(line
);
1743 wxListItemDataList::compatibility_iterator node
= data
->m_items
.GetFirst();
1746 wxListItemData
*item
= node
->GetData();
1747 if ( item
->HasImage() )
1750 GetImageSize( item
->GetImage(), ix
, iy
);
1751 image_x
= 3 + ix
+ IMAGE_MARGIN_IN_REPORT_MODE
;
1756 rect
.x
= image_x
+ HEADER_OFFSET_X
;
1757 rect
.y
= GetLineY(line
);
1758 rect
.width
= GetColumnWidth(0) - image_x
;
1759 rect
.height
= GetLineHeight();
1764 wxRect
wxListMainWindow::GetLineIconRect(size_t line
) const
1766 if ( !InReportView() )
1767 return GetLine(line
)->m_gi
->m_rectIcon
;
1769 wxListLineData
*ld
= GetLine(line
);
1770 wxASSERT_MSG( ld
->HasImage(), wxT("should have an image") );
1773 rect
.x
= HEADER_OFFSET_X
;
1774 rect
.y
= GetLineY(line
);
1775 GetImageSize(ld
->GetImage(), rect
.width
, rect
.height
);
1780 wxRect
wxListMainWindow::GetLineHighlightRect(size_t line
) const
1782 return InReportView() ? GetLineRect(line
)
1783 : GetLine(line
)->m_gi
->m_rectHighlight
;
1786 long wxListMainWindow::HitTestLine(size_t line
, int x
, int y
) const
1788 wxASSERT_MSG( line
< GetItemCount(), wxT("invalid line in HitTestLine") );
1790 wxListLineData
*ld
= GetLine(line
);
1792 if ( ld
->HasImage() && GetLineIconRect(line
).Contains(x
, y
) )
1793 return wxLIST_HITTEST_ONITEMICON
;
1795 // VS: Testing for "ld->HasText() || InReportView()" instead of
1796 // "ld->HasText()" is needed to make empty lines in report view
1798 if ( ld
->HasText() || InReportView() )
1800 wxRect rect
= InReportView() ? GetLineRect(line
)
1801 : GetLineLabelRect(line
);
1803 if ( rect
.Contains(x
, y
) )
1804 return wxLIST_HITTEST_ONITEMLABEL
;
1810 // ----------------------------------------------------------------------------
1811 // highlight (selection) handling
1812 // ----------------------------------------------------------------------------
1814 bool wxListMainWindow::IsHighlighted(size_t line
) const
1818 return m_selStore
.IsSelected(line
);
1822 wxListLineData
*ld
= GetLine(line
);
1823 wxCHECK_MSG( ld
, false, wxT("invalid index in IsHighlighted") );
1825 return ld
->IsHighlighted();
1829 void wxListMainWindow::HighlightLines( size_t lineFrom
,
1835 wxArrayInt linesChanged
;
1836 if ( !m_selStore
.SelectRange(lineFrom
, lineTo
, highlight
,
1839 // meny items changed state, refresh everything
1840 RefreshLines(lineFrom
, lineTo
);
1842 else // only a few items changed state, refresh only them
1844 size_t count
= linesChanged
.GetCount();
1845 for ( size_t n
= 0; n
< count
; n
++ )
1847 RefreshLine(linesChanged
[n
]);
1851 else // iterate over all items in non report view
1853 for ( size_t line
= lineFrom
; line
<= lineTo
; line
++ )
1855 if ( HighlightLine(line
, highlight
) )
1861 bool wxListMainWindow::HighlightLine( size_t line
, bool highlight
)
1867 changed
= m_selStore
.SelectItem(line
, highlight
);
1871 wxListLineData
*ld
= GetLine(line
);
1872 wxCHECK_MSG( ld
, false, wxT("invalid index in HighlightLine") );
1874 changed
= ld
->Highlight(highlight
);
1879 SendNotify( line
, highlight
? wxEVT_COMMAND_LIST_ITEM_SELECTED
1880 : wxEVT_COMMAND_LIST_ITEM_DESELECTED
);
1886 void wxListMainWindow::RefreshLine( size_t line
)
1888 if ( InReportView() )
1890 size_t visibleFrom
, visibleTo
;
1891 GetVisibleLinesRange(&visibleFrom
, &visibleTo
);
1893 if ( line
< visibleFrom
|| line
> visibleTo
)
1897 wxRect rect
= GetLineRect(line
);
1899 GetListCtrl()->CalcScrolledPosition( rect
.x
, rect
.y
, &rect
.x
, &rect
.y
);
1900 RefreshRect( rect
);
1903 void wxListMainWindow::RefreshLines( size_t lineFrom
, size_t lineTo
)
1905 // we suppose that they are ordered by caller
1906 wxASSERT_MSG( lineFrom
<= lineTo
, wxT("indices in disorder") );
1908 wxASSERT_MSG( lineTo
< GetItemCount(), wxT("invalid line range") );
1910 if ( InReportView() )
1912 size_t visibleFrom
, visibleTo
;
1913 GetVisibleLinesRange(&visibleFrom
, &visibleTo
);
1915 if ( lineFrom
< visibleFrom
)
1916 lineFrom
= visibleFrom
;
1917 if ( lineTo
> visibleTo
)
1922 rect
.y
= GetLineY(lineFrom
);
1923 rect
.width
= GetClientSize().x
;
1924 rect
.height
= GetLineY(lineTo
) - rect
.y
+ GetLineHeight();
1926 GetListCtrl()->CalcScrolledPosition( rect
.x
, rect
.y
, &rect
.x
, &rect
.y
);
1927 RefreshRect( rect
);
1931 // TODO: this should be optimized...
1932 for ( size_t line
= lineFrom
; line
<= lineTo
; line
++ )
1939 void wxListMainWindow::RefreshAfter( size_t lineFrom
)
1941 if ( InReportView() )
1943 size_t visibleFrom
, visibleTo
;
1944 GetVisibleLinesRange(&visibleFrom
, &visibleTo
);
1946 if ( lineFrom
< visibleFrom
)
1947 lineFrom
= visibleFrom
;
1948 else if ( lineFrom
> visibleTo
)
1953 rect
.y
= GetLineY(lineFrom
);
1954 GetListCtrl()->CalcScrolledPosition( rect
.x
, rect
.y
, &rect
.x
, &rect
.y
);
1956 wxSize size
= GetClientSize();
1957 rect
.width
= size
.x
;
1959 // refresh till the bottom of the window
1960 rect
.height
= size
.y
- rect
.y
;
1962 RefreshRect( rect
);
1966 // TODO: how to do it more efficiently?
1971 void wxListMainWindow::RefreshSelected()
1977 if ( InReportView() )
1979 GetVisibleLinesRange(&from
, &to
);
1984 to
= GetItemCount() - 1;
1987 if ( HasCurrent() && m_current
>= from
&& m_current
<= to
)
1988 RefreshLine(m_current
);
1990 for ( size_t line
= from
; line
<= to
; line
++ )
1992 // NB: the test works as expected even if m_current == -1
1993 if ( line
!= m_current
&& IsHighlighted(line
) )
1998 void wxListMainWindow::OnPaint( wxPaintEvent
&WXUNUSED(event
) )
2000 // Note: a wxPaintDC must be constructed even if no drawing is
2001 // done (a Windows requirement).
2002 wxPaintDC
dc( this );
2006 // nothing to draw or not the moment to draw it
2011 RecalculatePositions( false );
2013 GetListCtrl()->PrepareDC( dc
);
2016 GetListCtrl()->CalcScrolledPosition( 0, 0, &dev_x
, &dev_y
);
2018 dc
.SetFont( GetFont() );
2020 if ( InReportView() )
2022 int lineHeight
= GetLineHeight();
2024 size_t visibleFrom
, visibleTo
;
2025 GetVisibleLinesRange(&visibleFrom
, &visibleTo
);
2028 int xOrig
= dc
.LogicalToDeviceX( 0 );
2029 int yOrig
= dc
.LogicalToDeviceY( 0 );
2031 // tell the caller cache to cache the data
2034 wxListEvent
evCache(wxEVT_COMMAND_LIST_CACHE_HINT
,
2035 GetParent()->GetId());
2036 evCache
.SetEventObject( GetParent() );
2037 evCache
.m_oldItemIndex
= visibleFrom
;
2038 evCache
.m_item
.m_itemId
=
2039 evCache
.m_itemIndex
= visibleTo
;
2040 GetParent()->GetEventHandler()->ProcessEvent( evCache
);
2043 for ( size_t line
= visibleFrom
; line
<= visibleTo
; line
++ )
2045 rectLine
= GetLineRect(line
);
2048 if ( !IsExposed(rectLine
.x
+ xOrig
, rectLine
.y
+ yOrig
,
2049 rectLine
.width
, rectLine
.height
) )
2051 // don't redraw unaffected lines to avoid flicker
2055 GetLine(line
)->DrawInReportMode( &dc
,
2057 GetLineHighlightRect(line
),
2058 IsHighlighted(line
),
2059 line
== m_current
);
2062 if ( HasFlag(wxLC_HRULES
) )
2064 wxPen
pen(GetRuleColour(), 1, wxPENSTYLE_SOLID
);
2065 wxSize clientSize
= GetClientSize();
2067 size_t i
= visibleFrom
;
2068 if (i
== 0) i
= 1; // Don't draw the first one
2069 for ( ; i
<= visibleTo
; i
++ )
2072 dc
.SetBrush( *wxTRANSPARENT_BRUSH
);
2073 dc
.DrawLine(0 - dev_x
, i
* lineHeight
,
2074 clientSize
.x
- dev_x
, i
* lineHeight
);
2077 // Draw last horizontal rule
2078 if ( visibleTo
== GetItemCount() - 1 )
2081 dc
.SetBrush( *wxTRANSPARENT_BRUSH
);
2082 dc
.DrawLine(0 - dev_x
, (m_lineTo
+ 1) * lineHeight
,
2083 clientSize
.x
- dev_x
, (m_lineTo
+ 1) * lineHeight
);
2087 // Draw vertical rules if required
2088 if ( HasFlag(wxLC_VRULES
) && !IsEmpty() )
2090 wxPen
pen(GetRuleColour(), 1, wxPENSTYLE_SOLID
);
2091 wxRect firstItemRect
, lastItemRect
;
2093 GetItemRect(visibleFrom
, firstItemRect
);
2094 GetItemRect(visibleTo
, lastItemRect
);
2095 int x
= firstItemRect
.GetX();
2097 dc
.SetBrush(* wxTRANSPARENT_BRUSH
);
2099 for (int col
= 0; col
< GetColumnCount(); col
++)
2101 int colWidth
= GetColumnWidth(col
);
2103 int x_pos
= x
- dev_x
;
2104 if (col
< GetColumnCount()-1) x_pos
-= 2;
2105 dc
.DrawLine(x_pos
, firstItemRect
.GetY() - 1 - dev_y
,
2106 x_pos
, lastItemRect
.GetBottom() + 1 - dev_y
);
2112 size_t count
= GetItemCount();
2113 for ( size_t i
= 0; i
< count
; i
++ )
2115 GetLine(i
)->Draw( &dc
, i
== m_current
);
2119 // DrawFocusRect() is unusable under Mac, it draws outside of the highlight
2120 // rectangle somehow and so leaves traces when the item is not selected any
2121 // more, see #12229.
2126 if ( IsHighlighted(m_current
) )
2127 flags
|= wxCONTROL_SELECTED
;
2129 wxRendererNative::Get().
2130 DrawFocusRect(this, dc
, GetLineHighlightRect(m_current
), flags
);
2132 #endif // !__WXMAC__
2135 void wxListMainWindow::HighlightAll( bool on
)
2137 if ( IsSingleSel() )
2139 wxASSERT_MSG( !on
, wxT("can't do this in a single selection control") );
2141 // we just have one item to turn off
2142 if ( HasCurrent() && IsHighlighted(m_current
) )
2144 HighlightLine(m_current
, false);
2145 RefreshLine(m_current
);
2148 else // multi selection
2151 HighlightLines(0, GetItemCount() - 1, on
);
2155 void wxListMainWindow::OnChildFocus(wxChildFocusEvent
& WXUNUSED(event
))
2157 // Do nothing here. This prevents the default handler in wxScrolledWindow
2158 // from needlessly scrolling the window when the edit control is
2159 // dismissed. See ticket #9563.
2162 void wxListMainWindow::SendNotify( size_t line
,
2163 wxEventType command
,
2164 const wxPoint
& point
)
2166 wxListEvent
le( command
, GetParent()->GetId() );
2167 le
.SetEventObject( GetParent() );
2169 le
.m_item
.m_itemId
=
2170 le
.m_itemIndex
= line
;
2172 // set only for events which have position
2173 if ( point
!= wxDefaultPosition
)
2174 le
.m_pointDrag
= point
;
2176 // don't try to get the line info for virtual list controls: the main
2177 // program has it anyhow and if we did it would result in accessing all
2178 // the lines, even those which are not visible now and this is precisely
2179 // what we're trying to avoid
2182 if ( line
!= (size_t)-1 )
2184 GetLine(line
)->GetItem( 0, le
.m_item
);
2186 //else: this happens for wxEVT_COMMAND_LIST_ITEM_FOCUSED event
2188 //else: there may be no more such item
2190 GetParent()->GetEventHandler()->ProcessEvent( le
);
2193 void wxListMainWindow::ChangeCurrent(size_t current
)
2195 m_current
= current
;
2197 // as the current item changed, we shouldn't start editing it when the
2198 // "slow click" timer expires as the click happened on another item
2199 if ( m_renameTimer
->IsRunning() )
2200 m_renameTimer
->Stop();
2202 SendNotify(current
, wxEVT_COMMAND_LIST_ITEM_FOCUSED
);
2205 wxTextCtrl
*wxListMainWindow::EditLabel(long item
, wxClassInfo
* textControlClass
)
2207 wxCHECK_MSG( (item
>= 0) && ((size_t)item
< GetItemCount()), NULL
,
2208 wxT("wrong index in wxGenericListCtrl::EditLabel()") );
2210 wxASSERT_MSG( textControlClass
->IsKindOf(wxCLASSINFO(wxTextCtrl
)),
2211 wxT("EditLabel() needs a text control") );
2213 size_t itemEdit
= (size_t)item
;
2215 wxListEvent
le( wxEVT_COMMAND_LIST_BEGIN_LABEL_EDIT
, GetParent()->GetId() );
2216 le
.SetEventObject( GetParent() );
2217 le
.m_item
.m_itemId
=
2218 le
.m_itemIndex
= item
;
2219 wxListLineData
*data
= GetLine(itemEdit
);
2220 wxCHECK_MSG( data
, NULL
, wxT("invalid index in EditLabel()") );
2221 data
->GetItem( 0, le
.m_item
);
2223 if ( GetParent()->GetEventHandler()->ProcessEvent( le
) && !le
.IsAllowed() )
2225 // vetoed by user code
2229 // We have to call this here because the label in question might just have
2230 // been added and no screen update taken place.
2233 // TODO: use wxTheApp->SafeYieldFor(NULL, wxEVT_CATEGORY_UI) instead
2234 // so that no pending events may change the item count (see below)
2235 // IMPORTANT: needs to be tested!
2238 // Pending events dispatched by wxSafeYield might have changed the item
2240 if ( (size_t)item
>= GetItemCount() )
2244 wxTextCtrl
* const text
= (wxTextCtrl
*)textControlClass
->CreateObject();
2245 m_textctrlWrapper
= new wxListTextCtrlWrapper(this, text
, item
);
2246 return m_textctrlWrapper
->GetText();
2249 void wxListMainWindow::OnRenameTimer()
2251 wxCHECK_RET( HasCurrent(), wxT("unexpected rename timer") );
2253 EditLabel( m_current
);
2256 bool wxListMainWindow::OnRenameAccept(size_t itemEdit
, const wxString
& value
)
2258 wxListEvent
le( wxEVT_COMMAND_LIST_END_LABEL_EDIT
, GetParent()->GetId() );
2259 le
.SetEventObject( GetParent() );
2260 le
.m_item
.m_itemId
=
2261 le
.m_itemIndex
= itemEdit
;
2263 wxListLineData
*data
= GetLine(itemEdit
);
2265 wxCHECK_MSG( data
, false, wxT("invalid index in OnRenameAccept()") );
2267 data
->GetItem( 0, le
.m_item
);
2268 le
.m_item
.m_text
= value
;
2269 return !GetParent()->GetEventHandler()->ProcessEvent( le
) ||
2273 void wxListMainWindow::OnRenameCancelled(size_t itemEdit
)
2275 // let owner know that the edit was cancelled
2276 wxListEvent
le( wxEVT_COMMAND_LIST_END_LABEL_EDIT
, GetParent()->GetId() );
2278 le
.SetEditCanceled(true);
2280 le
.SetEventObject( GetParent() );
2281 le
.m_item
.m_itemId
=
2282 le
.m_itemIndex
= itemEdit
;
2284 wxListLineData
*data
= GetLine(itemEdit
);
2285 wxCHECK_RET( data
, wxT("invalid index in OnRenameCancelled()") );
2287 data
->GetItem( 0, le
.m_item
);
2288 GetEventHandler()->ProcessEvent( le
);
2291 void wxListMainWindow::OnMouse( wxMouseEvent
&event
)
2294 // On wxMac we can't depend on the EVT_KILL_FOCUS event to properly
2295 // shutdown the edit control when the mouse is clicked elsewhere on the
2296 // listctrl because the order of events is different (or something like
2297 // that), so explicitly end the edit if it is active.
2298 if ( event
.LeftDown() && m_textctrlWrapper
)
2299 m_textctrlWrapper
->EndEdit(wxListTextCtrlWrapper::End_Accept
);
2302 if ( event
.LeftDown() )
2304 // Ensure we skip the event to let the system set focus to this window.
2308 // Pretend that the event happened in wxListCtrl itself.
2309 wxMouseEvent
me(event
);
2310 me
.SetEventObject( GetParent() );
2311 me
.SetId(GetParent()->GetId());
2312 if ( GetParent()->GetEventHandler()->ProcessEvent( me
))
2315 if (event
.GetEventType() == wxEVT_MOUSEWHEEL
)
2317 // let the base class handle mouse wheel events.
2322 if ( !HasCurrent() || IsEmpty() )
2324 if (event
.RightDown())
2326 SendNotify( (size_t)-1, wxEVT_COMMAND_LIST_ITEM_RIGHT_CLICK
, event
.GetPosition() );
2328 wxContextMenuEvent
evtCtx(wxEVT_CONTEXT_MENU
,
2329 GetParent()->GetId(),
2330 ClientToScreen(event
.GetPosition()));
2331 evtCtx
.SetEventObject(GetParent());
2332 GetParent()->GetEventHandler()->ProcessEvent(evtCtx
);
2340 if ( !(event
.Dragging() || event
.ButtonDown() || event
.LeftUp() ||
2341 event
.ButtonDClick()) )
2344 int x
= event
.GetX();
2345 int y
= event
.GetY();
2346 GetListCtrl()->CalcUnscrolledPosition( x
, y
, &x
, &y
);
2348 // where did we hit it (if we did)?
2351 size_t count
= GetItemCount(),
2354 if ( InReportView() )
2356 current
= y
/ GetLineHeight();
2357 if ( current
< count
)
2358 hitResult
= HitTestLine(current
, x
, y
);
2362 // TODO: optimize it too! this is less simple than for report view but
2363 // enumerating all items is still not a way to do it!!
2364 for ( current
= 0; current
< count
; current
++ )
2366 hitResult
= HitTestLine(current
, x
, y
);
2372 // Update drag events counter first as we must do it even if the mouse is
2373 // not on any item right now as we must keep count in case we started
2374 // dragging from the empty control area but continued to do it over a valid
2375 // item -- in this situation we must not start dragging this item.
2376 if (event
.Dragging())
2381 // The only mouse event that can be generated without any valid item is
2382 // wxEVT_COMMAND_LIST_ITEM_RIGHT_CLICK as it can be useful to have a global
2383 // popup menu for the list control itself which should be shown even when
2384 // the user clicks outside of any item.
2387 // outside of any item
2388 if (event
.RightDown())
2390 SendNotify( (size_t) -1, wxEVT_COMMAND_LIST_ITEM_RIGHT_CLICK
, event
.GetPosition() );
2392 wxContextMenuEvent
evtCtx(
2394 GetParent()->GetId(),
2395 ClientToScreen(event
.GetPosition()));
2396 evtCtx
.SetEventObject(GetParent());
2397 GetParent()->GetEventHandler()->ProcessEvent(evtCtx
);
2401 // reset the selection and bail out
2402 HighlightAll(false);
2408 if ( event
.Dragging() )
2410 if (m_dragCount
== 1)
2412 // we have to report the raw, physical coords as we want to be
2413 // able to call HitTest(event.m_pointDrag) from the user code to
2414 // get the item being dragged
2415 m_dragStart
= event
.GetPosition();
2418 if (m_dragCount
!= 3)
2421 int command
= event
.RightIsDown() ? wxEVT_COMMAND_LIST_BEGIN_RDRAG
2422 : wxEVT_COMMAND_LIST_BEGIN_DRAG
;
2424 SendNotify( m_lineLastClicked
, command
, m_dragStart
);
2429 bool forceClick
= false;
2430 if (event
.ButtonDClick())
2432 if ( m_renameTimer
->IsRunning() )
2433 m_renameTimer
->Stop();
2435 m_lastOnSame
= false;
2437 if ( current
== m_lineLastClicked
)
2439 SendNotify( current
, wxEVT_COMMAND_LIST_ITEM_ACTIVATED
);
2445 // The first click was on another item, so don't interpret this as
2446 // a double click, but as a simple click instead
2453 if (m_lineSelectSingleOnUp
!= (size_t)-1)
2455 // select single line
2456 HighlightAll( false );
2457 ReverseHighlight(m_lineSelectSingleOnUp
);
2462 if ((current
== m_current
) &&
2463 (hitResult
== wxLIST_HITTEST_ONITEMLABEL
) &&
2464 HasFlag(wxLC_EDIT_LABELS
) )
2466 if ( !InReportView() ||
2467 GetLineLabelRect(current
).Contains(x
, y
) )
2469 int dclick
= wxSystemSettings::GetMetric(wxSYS_DCLICK_MSEC
);
2470 m_renameTimer
->Start(dclick
> 0 ? dclick
: 250, true);
2474 m_lastOnSame
= false;
2477 m_lineSelectSingleOnUp
= (size_t)-1;
2481 // This is necessary, because after a DnD operation in
2482 // from and to ourself, the up event is swallowed by the
2483 // DnD code. So on next non-up event (which means here and
2484 // now) m_lineSelectSingleOnUp should be reset.
2485 m_lineSelectSingleOnUp
= (size_t)-1;
2487 if (event
.RightDown())
2489 m_lineBeforeLastClicked
= m_lineLastClicked
;
2490 m_lineLastClicked
= current
;
2492 // If the item is already selected, do not update the selection.
2493 // Multi-selections should not be cleared if a selected item is clicked.
2494 if (!IsHighlighted(current
))
2496 HighlightAll(false);
2497 ChangeCurrent(current
);
2498 ReverseHighlight(m_current
);
2501 SendNotify( current
, wxEVT_COMMAND_LIST_ITEM_RIGHT_CLICK
, event
.GetPosition() );
2503 // Allow generation of context menu event
2506 else if (event
.MiddleDown())
2508 SendNotify( current
, wxEVT_COMMAND_LIST_ITEM_MIDDLE_CLICK
);
2510 else if ( event
.LeftDown() || forceClick
)
2512 m_lineBeforeLastClicked
= m_lineLastClicked
;
2513 m_lineLastClicked
= current
;
2515 size_t oldCurrent
= m_current
;
2516 bool oldWasSelected
= IsHighlighted(m_current
);
2518 bool cmdModifierDown
= event
.CmdDown();
2519 if ( IsSingleSel() || !(cmdModifierDown
|| event
.ShiftDown()) )
2521 if ( IsSingleSel() || !IsHighlighted(current
) )
2523 HighlightAll( false );
2525 ChangeCurrent(current
);
2527 ReverseHighlight(m_current
);
2529 else // multi sel & current is highlighted & no mod keys
2531 m_lineSelectSingleOnUp
= current
;
2532 ChangeCurrent(current
); // change focus
2535 else // multi sel & either ctrl or shift is down
2537 if (cmdModifierDown
)
2539 ChangeCurrent(current
);
2541 ReverseHighlight(m_current
);
2543 else if (event
.ShiftDown())
2545 ChangeCurrent(current
);
2547 size_t lineFrom
= oldCurrent
,
2550 if ( lineTo
< lineFrom
)
2553 lineFrom
= m_current
;
2556 HighlightLines(lineFrom
, lineTo
);
2558 else // !ctrl, !shift
2560 // test in the enclosing if should make it impossible
2561 wxFAIL_MSG( wxT("how did we get here?") );
2565 if (m_current
!= oldCurrent
)
2566 RefreshLine( oldCurrent
);
2568 // Set the flag telling us whether the next click on this item should
2569 // start editing its label. This should happen if we clicked on the
2570 // current item and it was already selected, i.e. if this click was not
2571 // done to select it.
2573 // It should not happen if this was a double click (forceClick is true)
2574 // nor if we hadn't had the focus before as then this click was used to
2575 // give focus to the control.
2576 m_lastOnSame
= (m_current
== oldCurrent
) && oldWasSelected
&&
2577 !forceClick
&& HasFocus();
2581 void wxListMainWindow::MoveToItem(size_t item
)
2583 if ( item
== (size_t)-1 )
2586 wxRect rect
= GetLineRect(item
);
2588 int client_w
, client_h
;
2589 GetClientSize( &client_w
, &client_h
);
2591 const int hLine
= GetLineHeight();
2593 int view_x
= SCROLL_UNIT_X
* GetListCtrl()->GetScrollPos( wxHORIZONTAL
);
2594 int view_y
= hLine
* GetListCtrl()->GetScrollPos( wxVERTICAL
);
2596 if ( InReportView() )
2598 // the next we need the range of lines shown it might be different,
2599 // so recalculate it
2600 ResetVisibleLinesRange();
2602 if (rect
.y
< view_y
)
2603 GetListCtrl()->Scroll( -1, rect
.y
/ hLine
);
2604 if (rect
.y
+ rect
.height
+ 5 > view_y
+ client_h
)
2605 GetListCtrl()->Scroll( -1, (rect
.y
+ rect
.height
- client_h
+ hLine
) / hLine
);
2608 // At least on Mac the visible lines value will get reset inside of
2609 // Scroll *before* it actually scrolls the window because of the
2610 // Update() that happens there, so it will still have the wrong value.
2611 // So let's reset it again and wait for it to be recalculated in the
2612 // next paint event. I would expect this problem to show up in wxGTK
2613 // too but couldn't duplicate it there. Perhaps the order of events
2614 // is different... --Robin
2615 ResetVisibleLinesRange();
2623 if (rect
.x
-view_x
< 5)
2624 sx
= (rect
.x
- 5) / SCROLL_UNIT_X
;
2625 if (rect
.x
+ rect
.width
- 5 > view_x
+ client_w
)
2626 sx
= (rect
.x
+ rect
.width
- client_w
+ SCROLL_UNIT_X
) / SCROLL_UNIT_X
;
2628 if (rect
.y
-view_y
< 5)
2629 sy
= (rect
.y
- 5) / hLine
;
2630 if (rect
.y
+ rect
.height
- 5 > view_y
+ client_h
)
2631 sy
= (rect
.y
+ rect
.height
- client_h
+ hLine
) / hLine
;
2633 GetListCtrl()->Scroll(sx
, sy
);
2637 bool wxListMainWindow::ScrollList(int WXUNUSED(dx
), int dy
)
2639 if ( !InReportView() )
2641 // TODO: this should work in all views but is not implemented now
2646 GetVisibleLinesRange(&top
, &bottom
);
2648 if ( bottom
== (size_t)-1 )
2651 ResetVisibleLinesRange();
2653 int hLine
= GetLineHeight();
2655 GetListCtrl()->Scroll(-1, top
+ dy
/ hLine
);
2658 // see comment in MoveToItem() for why we do this
2659 ResetVisibleLinesRange();
2665 // ----------------------------------------------------------------------------
2666 // keyboard handling
2667 // ----------------------------------------------------------------------------
2669 void wxListMainWindow::OnArrowChar(size_t newCurrent
, const wxKeyEvent
& event
)
2671 wxCHECK_RET( newCurrent
< (size_t)GetItemCount(),
2672 wxT("invalid item index in OnArrowChar()") );
2674 size_t oldCurrent
= m_current
;
2676 // in single selection we just ignore Shift as we can't select several
2678 if ( event
.ShiftDown() && !IsSingleSel() )
2680 ChangeCurrent(newCurrent
);
2682 // refresh the old focus to remove it
2683 RefreshLine( oldCurrent
);
2685 // select all the items between the old and the new one
2686 if ( oldCurrent
> newCurrent
)
2688 newCurrent
= oldCurrent
;
2689 oldCurrent
= m_current
;
2692 HighlightLines(oldCurrent
, newCurrent
);
2696 // all previously selected items are unselected unless ctrl is held
2697 // in a multiselection control
2698 if ( !event
.ControlDown() || IsSingleSel() )
2699 HighlightAll(false);
2701 ChangeCurrent(newCurrent
);
2703 // refresh the old focus to remove it
2704 RefreshLine( oldCurrent
);
2706 // in single selection mode we must always have a selected item
2707 if ( !event
.ControlDown() || IsSingleSel() )
2708 HighlightLine( m_current
, true );
2711 RefreshLine( m_current
);
2716 void wxListMainWindow::OnKeyDown( wxKeyEvent
&event
)
2718 wxWindow
*parent
= GetParent();
2720 // propagate the key event upwards
2721 wxKeyEvent
ke(event
);
2722 ke
.SetEventObject( parent
);
2723 ke
.SetId(GetParent()->GetId());
2724 if (parent
->GetEventHandler()->ProcessEvent( ke
))
2727 // send a list event
2728 wxListEvent
le( wxEVT_COMMAND_LIST_KEY_DOWN
, parent
->GetId() );
2729 le
.m_item
.m_itemId
=
2730 le
.m_itemIndex
= m_current
;
2732 GetLine(m_current
)->GetItem( 0, le
.m_item
);
2733 le
.m_code
= event
.GetKeyCode();
2734 le
.SetEventObject( parent
);
2735 if (parent
->GetEventHandler()->ProcessEvent( le
))
2741 void wxListMainWindow::OnKeyUp( wxKeyEvent
&event
)
2743 wxWindow
*parent
= GetParent();
2745 // propagate the key event upwards
2746 wxKeyEvent
ke(event
);
2747 ke
.SetEventObject( parent
);
2748 ke
.SetId(GetParent()->GetId());
2749 if (parent
->GetEventHandler()->ProcessEvent( ke
))
2755 void wxListMainWindow::OnCharHook( wxKeyEvent
&event
)
2757 if ( m_textctrlWrapper
)
2759 // When an in-place editor is active we should ensure that it always
2760 // gets the key events that are special to it.
2761 if ( m_textctrlWrapper
->CheckForEndEditKey(event
) )
2763 // Skip the call to wxEvent::Skip() below.
2771 void wxListMainWindow::OnChar( wxKeyEvent
&event
)
2773 wxWindow
*parent
= GetParent();
2775 // propagate the char event upwards
2776 wxKeyEvent
ke(event
);
2777 ke
.SetEventObject( parent
);
2778 ke
.SetId(GetParent()->GetId());
2779 if (parent
->GetEventHandler()->ProcessEvent( ke
))
2782 if ( HandleAsNavigationKey(event
) )
2785 // no item -> nothing to do
2792 // don't use m_linesPerPage directly as it might not be computed yet
2793 const int pageSize
= GetCountPerPage();
2794 wxCHECK_RET( pageSize
, wxT("should have non zero page size") );
2796 if (GetLayoutDirection() == wxLayout_RightToLeft
)
2798 if (event
.GetKeyCode() == WXK_RIGHT
)
2799 event
.m_keyCode
= WXK_LEFT
;
2800 else if (event
.GetKeyCode() == WXK_LEFT
)
2801 event
.m_keyCode
= WXK_RIGHT
;
2804 switch ( event
.GetKeyCode() )
2807 if ( m_current
> 0 )
2808 OnArrowChar( m_current
- 1, event
);
2812 if ( m_current
< (size_t)GetItemCount() - 1 )
2813 OnArrowChar( m_current
+ 1, event
);
2818 OnArrowChar( GetItemCount() - 1, event
);
2823 OnArrowChar( 0, event
);
2828 int steps
= InReportView() ? pageSize
- 1
2829 : m_current
% pageSize
;
2831 int index
= m_current
- steps
;
2835 OnArrowChar( index
, event
);
2841 int steps
= InReportView()
2843 : pageSize
- (m_current
% pageSize
) - 1;
2845 size_t index
= m_current
+ steps
;
2846 size_t count
= GetItemCount();
2847 if ( index
>= count
)
2850 OnArrowChar( index
, event
);
2855 if ( !InReportView() )
2857 int index
= m_current
- pageSize
;
2861 OnArrowChar( index
, event
);
2866 if ( !InReportView() )
2868 size_t index
= m_current
+ pageSize
;
2870 size_t count
= GetItemCount();
2871 if ( index
>= count
)
2874 OnArrowChar( index
, event
);
2879 if ( IsSingleSel() )
2881 if ( event
.ControlDown() )
2883 ReverseHighlight(m_current
);
2885 else // normal space press
2887 SendNotify( m_current
, wxEVT_COMMAND_LIST_ITEM_ACTIVATED
);
2890 else // multiple selection
2892 ReverseHighlight(m_current
);
2898 SendNotify( m_current
, wxEVT_COMMAND_LIST_ITEM_ACTIVATED
);
2906 // ----------------------------------------------------------------------------
2908 // ----------------------------------------------------------------------------
2910 void wxListMainWindow::OnSetFocus( wxFocusEvent
&WXUNUSED(event
) )
2914 wxFocusEvent
event( wxEVT_SET_FOCUS
, GetParent()->GetId() );
2915 event
.SetEventObject( GetParent() );
2916 if ( GetParent()->GetEventHandler()->ProcessEvent( event
) )
2920 // wxGTK sends us EVT_SET_FOCUS events even if we had never got
2921 // EVT_KILL_FOCUS before which means that we finish by redrawing the items
2922 // which are already drawn correctly resulting in horrible flicker - avoid
2932 void wxListMainWindow::OnKillFocus( wxFocusEvent
&WXUNUSED(event
) )
2936 wxFocusEvent
event( wxEVT_KILL_FOCUS
, GetParent()->GetId() );
2937 event
.SetEventObject( GetParent() );
2938 if ( GetParent()->GetEventHandler()->ProcessEvent( event
) )
2946 void wxListMainWindow::DrawImage( int index
, wxDC
*dc
, int x
, int y
)
2948 if ( HasFlag(wxLC_ICON
) && (m_normal_image_list
))
2950 m_normal_image_list
->Draw( index
, *dc
, x
, y
, wxIMAGELIST_DRAW_TRANSPARENT
);
2952 else if ( HasFlag(wxLC_SMALL_ICON
) && (m_small_image_list
))
2954 m_small_image_list
->Draw( index
, *dc
, x
, y
, wxIMAGELIST_DRAW_TRANSPARENT
);
2956 else if ( HasFlag(wxLC_LIST
) && (m_small_image_list
))
2958 m_small_image_list
->Draw( index
, *dc
, x
, y
, wxIMAGELIST_DRAW_TRANSPARENT
);
2960 else if ( InReportView() && (m_small_image_list
))
2962 m_small_image_list
->Draw( index
, *dc
, x
, y
, wxIMAGELIST_DRAW_TRANSPARENT
);
2966 void wxListMainWindow::GetImageSize( int index
, int &width
, int &height
) const
2968 if ( HasFlag(wxLC_ICON
) && m_normal_image_list
)
2970 m_normal_image_list
->GetSize( index
, width
, height
);
2972 else if ( HasFlag(wxLC_SMALL_ICON
) && m_small_image_list
)
2974 m_small_image_list
->GetSize( index
, width
, height
);
2976 else if ( HasFlag(wxLC_LIST
) && m_small_image_list
)
2978 m_small_image_list
->GetSize( index
, width
, height
);
2980 else if ( InReportView() && m_small_image_list
)
2982 m_small_image_list
->GetSize( index
, width
, height
);
2991 void wxListMainWindow::SetImageList( wxImageList
*imageList
, int which
)
2995 // calc the spacing from the icon size
2996 int width
= 0, height
= 0;
2998 if ((imageList
) && (imageList
->GetImageCount()) )
2999 imageList
->GetSize(0, width
, height
);
3001 if (which
== wxIMAGE_LIST_NORMAL
)
3003 m_normal_image_list
= imageList
;
3004 m_normal_spacing
= width
+ 8;
3007 if (which
== wxIMAGE_LIST_SMALL
)
3009 m_small_image_list
= imageList
;
3010 m_small_spacing
= width
+ 14;
3011 m_lineHeight
= 0; // ensure that the line height will be recalc'd
3015 void wxListMainWindow::SetItemSpacing( int spacing
, bool isSmall
)
3019 m_small_spacing
= spacing
;
3021 m_normal_spacing
= spacing
;
3024 int wxListMainWindow::GetItemSpacing( bool isSmall
)
3026 return isSmall
? m_small_spacing
: m_normal_spacing
;
3029 // ----------------------------------------------------------------------------
3031 // ----------------------------------------------------------------------------
3034 wxListMainWindow::ComputeMinHeaderWidth(const wxListHeaderData
* column
) const
3036 wxClientDC
dc(const_cast<wxListMainWindow
*>(this));
3038 int width
= dc
.GetTextExtent(column
->GetText()).x
+ AUTOSIZE_COL_MARGIN
;
3040 width
+= 2*EXTRA_WIDTH
;
3042 // check for column header's image availability
3043 const int image
= column
->GetImage();
3046 if ( m_small_image_list
)
3049 m_small_image_list
->GetSize(image
, ix
, iy
);
3050 width
+= ix
+ HEADER_IMAGE_MARGIN_IN_REPORT_MODE
;
3057 void wxListMainWindow::SetColumn( int col
, const wxListItem
&item
)
3059 wxListHeaderDataList::compatibility_iterator node
= m_columns
.Item( col
);
3061 wxCHECK_RET( node
, wxT("invalid column index in SetColumn") );
3063 wxListHeaderData
*column
= node
->GetData();
3064 column
->SetItem( item
);
3066 if ( item
.m_width
== wxLIST_AUTOSIZE_USEHEADER
)
3067 column
->SetWidth(ComputeMinHeaderWidth(column
));
3069 wxListHeaderWindow
*headerWin
= GetListCtrl()->m_headerWin
;
3071 headerWin
->m_dirty
= true;
3075 // invalidate it as it has to be recalculated
3079 void wxListMainWindow::SetColumnWidth( int col
, int width
)
3081 wxCHECK_RET( col
>= 0 && col
< GetColumnCount(),
3082 wxT("invalid column index") );
3084 wxCHECK_RET( InReportView(),
3085 wxT("SetColumnWidth() can only be called in report mode.") );
3089 wxListHeaderWindow
*headerWin
= GetListCtrl()->m_headerWin
;
3091 headerWin
->m_dirty
= true;
3093 wxListHeaderDataList::compatibility_iterator node
= m_columns
.Item( col
);
3094 wxCHECK_RET( node
, wxT("no column?") );
3096 wxListHeaderData
*column
= node
->GetData();
3098 size_t count
= GetItemCount();
3100 if (width
== wxLIST_AUTOSIZE_USEHEADER
)
3102 width
= ComputeMinHeaderWidth(column
);
3104 else if ( width
== wxLIST_AUTOSIZE
)
3106 width
= ComputeMinHeaderWidth(column
);
3110 wxClientDC
dc(this);
3111 dc
.SetFont( GetFont() );
3113 int max
= AUTOSIZE_COL_MARGIN
;
3115 // if the cached column width isn't valid then recalculate it
3116 if (m_aColWidths
.Item(col
)->bNeedsUpdate
)
3118 for (size_t i
= 0; i
< count
; i
++)
3120 wxListLineData
*line
= GetLine( i
);
3121 wxListItemDataList::compatibility_iterator n
= line
->m_items
.Item( col
);
3123 wxCHECK_RET( n
, wxT("no subitem?") );
3125 wxListItemData
*itemData
= n
->GetData();
3128 itemData
->GetItem(item
);
3129 int itemWidth
= GetItemWidthWithImage(&item
);
3130 if (itemWidth
> max
)
3134 m_aColWidths
.Item(col
)->bNeedsUpdate
= false;
3135 m_aColWidths
.Item(col
)->nMaxWidth
= max
;
3138 max
= m_aColWidths
.Item(col
)->nMaxWidth
+ AUTOSIZE_COL_MARGIN
;
3144 column
->SetWidth( width
);
3146 // invalidate it as it has to be recalculated
3150 int wxListMainWindow::GetHeaderWidth() const
3152 if ( !m_headerWidth
)
3154 wxListMainWindow
*self
= wxConstCast(this, wxListMainWindow
);
3156 size_t count
= GetColumnCount();
3157 for ( size_t col
= 0; col
< count
; col
++ )
3159 self
->m_headerWidth
+= GetColumnWidth(col
);
3163 return m_headerWidth
;
3166 void wxListMainWindow::GetColumn( int col
, wxListItem
&item
) const
3168 wxListHeaderDataList::compatibility_iterator node
= m_columns
.Item( col
);
3169 wxCHECK_RET( node
, wxT("invalid column index in GetColumn") );
3171 wxListHeaderData
*column
= node
->GetData();
3172 column
->GetItem( item
);
3175 int wxListMainWindow::GetColumnWidth( int col
) const
3177 wxListHeaderDataList::compatibility_iterator node
= m_columns
.Item( col
);
3178 wxCHECK_MSG( node
, 0, wxT("invalid column index") );
3180 wxListHeaderData
*column
= node
->GetData();
3181 return column
->GetWidth();
3184 // ----------------------------------------------------------------------------
3186 // ----------------------------------------------------------------------------
3188 void wxListMainWindow::SetItem( wxListItem
&item
)
3190 long id
= item
.m_itemId
;
3191 wxCHECK_RET( id
>= 0 && (size_t)id
< GetItemCount(),
3192 wxT("invalid item index in SetItem") );
3196 wxListLineData
*line
= GetLine((size_t)id
);
3197 line
->SetItem( item
.m_col
, item
);
3199 // Set item state if user wants
3200 if ( item
.m_mask
& wxLIST_MASK_STATE
)
3201 SetItemState( item
.m_itemId
, item
.m_state
, item
.m_state
);
3205 // update the Max Width Cache if needed
3206 int width
= GetItemWidthWithImage(&item
);
3208 if (width
> m_aColWidths
.Item(item
.m_col
)->nMaxWidth
)
3209 m_aColWidths
.Item(item
.m_col
)->nMaxWidth
= width
;
3213 // update the item on screen unless we're going to update everything soon
3218 GetItemRect(id
, rectItem
);
3219 RefreshRect(rectItem
);
3223 void wxListMainWindow::SetItemStateAll(long state
, long stateMask
)
3228 // first deal with selection
3229 if ( stateMask
& wxLIST_STATE_SELECTED
)
3231 // set/clear select state
3234 // optimized version for virtual listctrl.
3235 m_selStore
.SelectRange(0, GetItemCount() - 1, state
== wxLIST_STATE_SELECTED
);
3238 else if ( state
& wxLIST_STATE_SELECTED
)
3240 const long count
= GetItemCount();
3241 for( long i
= 0; i
< count
; i
++ )
3243 SetItemState( i
, wxLIST_STATE_SELECTED
, wxLIST_STATE_SELECTED
);
3249 // clear for non virtual (somewhat optimized by using GetNextItem())
3251 while ( (i
= GetNextItem(i
, wxLIST_NEXT_ALL
, wxLIST_STATE_SELECTED
)) != -1 )
3253 SetItemState( i
, 0, wxLIST_STATE_SELECTED
);
3258 if ( HasCurrent() && (state
== 0) && (stateMask
& wxLIST_STATE_FOCUSED
) )
3260 // unfocus all: only one item can be focussed, so clearing focus for
3261 // all items is simply clearing focus of the focussed item.
3262 SetItemState(m_current
, state
, stateMask
);
3264 //(setting focus to all items makes no sense, so it is not handled here.)
3267 void wxListMainWindow::SetItemState( long litem
, long state
, long stateMask
)
3271 SetItemStateAll(state
, stateMask
);
3275 wxCHECK_RET( litem
>= 0 && (size_t)litem
< GetItemCount(),
3276 wxT("invalid list ctrl item index in SetItem") );
3278 size_t oldCurrent
= m_current
;
3279 size_t item
= (size_t)litem
; // safe because of the check above
3281 // do we need to change the focus?
3282 if ( stateMask
& wxLIST_STATE_FOCUSED
)
3284 if ( state
& wxLIST_STATE_FOCUSED
)
3286 // don't do anything if this item is already focused
3287 if ( item
!= m_current
)
3289 ChangeCurrent(item
);
3291 if ( oldCurrent
!= (size_t)-1 )
3293 if ( IsSingleSel() )
3295 HighlightLine(oldCurrent
, false);
3298 RefreshLine(oldCurrent
);
3301 RefreshLine( m_current
);
3306 // don't do anything if this item is not focused
3307 if ( item
== m_current
)
3311 if ( IsSingleSel() )
3313 // we must unselect the old current item as well or we
3314 // might end up with more than one selected item in a
3315 // single selection control
3316 HighlightLine(oldCurrent
, false);
3319 RefreshLine( oldCurrent
);
3324 // do we need to change the selection state?
3325 if ( stateMask
& wxLIST_STATE_SELECTED
)
3327 bool on
= (state
& wxLIST_STATE_SELECTED
) != 0;
3329 if ( IsSingleSel() )
3333 // selecting the item also makes it the focused one in the
3335 if ( m_current
!= item
)
3337 ChangeCurrent(item
);
3339 if ( oldCurrent
!= (size_t)-1 )
3341 HighlightLine( oldCurrent
, false );
3342 RefreshLine( oldCurrent
);
3348 // only the current item may be selected anyhow
3349 if ( item
!= m_current
)
3354 if ( HighlightLine(item
, on
) )
3361 int wxListMainWindow::GetItemState( long item
, long stateMask
) const
3363 wxCHECK_MSG( item
>= 0 && (size_t)item
< GetItemCount(), 0,
3364 wxT("invalid list ctrl item index in GetItemState()") );
3366 int ret
= wxLIST_STATE_DONTCARE
;
3368 if ( stateMask
& wxLIST_STATE_FOCUSED
)
3370 if ( (size_t)item
== m_current
)
3371 ret
|= wxLIST_STATE_FOCUSED
;
3374 if ( stateMask
& wxLIST_STATE_SELECTED
)
3376 if ( IsHighlighted(item
) )
3377 ret
|= wxLIST_STATE_SELECTED
;
3383 void wxListMainWindow::GetItem( wxListItem
&item
) const
3385 wxCHECK_RET( item
.m_itemId
>= 0 && (size_t)item
.m_itemId
< GetItemCount(),
3386 wxT("invalid item index in GetItem") );
3388 wxListLineData
*line
= GetLine((size_t)item
.m_itemId
);
3389 line
->GetItem( item
.m_col
, item
);
3391 // Get item state if user wants it
3392 if ( item
.m_mask
& wxLIST_MASK_STATE
)
3393 item
.m_state
= GetItemState( item
.m_itemId
, wxLIST_STATE_SELECTED
|
3394 wxLIST_STATE_FOCUSED
);
3397 // ----------------------------------------------------------------------------
3399 // ----------------------------------------------------------------------------
3401 size_t wxListMainWindow::GetItemCount() const
3403 return IsVirtual() ? m_countVirt
: m_lines
.GetCount();
3406 void wxListMainWindow::SetItemCount(long count
)
3408 m_selStore
.SetItemCount(count
);
3409 m_countVirt
= count
;
3411 ResetVisibleLinesRange();
3413 // scrollbars must be reset
3417 int wxListMainWindow::GetSelectedItemCount() const
3419 // deal with the quick case first
3420 if ( IsSingleSel() )
3421 return HasCurrent() ? IsHighlighted(m_current
) : false;
3423 // virtual controls remmebers all its selections itself
3425 return m_selStore
.GetSelectedCount();
3427 // TODO: we probably should maintain the number of items selected even for
3428 // non virtual controls as enumerating all lines is really slow...
3429 size_t countSel
= 0;
3430 size_t count
= GetItemCount();
3431 for ( size_t line
= 0; line
< count
; line
++ )
3433 if ( GetLine(line
)->IsHighlighted() )
3440 // ----------------------------------------------------------------------------
3441 // item position/size
3442 // ----------------------------------------------------------------------------
3444 wxRect
wxListMainWindow::GetViewRect() const
3446 wxASSERT_MSG( !HasFlag(wxLC_LIST
), "not implemented for list view" );
3448 // we need to find the longest/tallest label
3449 wxCoord xMax
= 0, yMax
= 0;
3450 const int count
= GetItemCount();
3453 for ( int i
= 0; i
< count
; i
++ )
3455 // we need logical, not physical, coordinates here, so use
3456 // GetLineRect() instead of GetItemRect()
3457 wxRect r
= GetLineRect(i
);
3459 wxCoord x
= r
.GetRight(),
3469 // some fudge needed to make it look prettier
3470 xMax
+= 2 * EXTRA_BORDER_X
;
3471 yMax
+= 2 * EXTRA_BORDER_Y
;
3473 // account for the scrollbars if necessary
3474 const wxSize sizeAll
= GetClientSize();
3475 if ( xMax
> sizeAll
.x
)
3476 yMax
+= wxSystemSettings::GetMetric(wxSYS_HSCROLL_Y
);
3477 if ( yMax
> sizeAll
.y
)
3478 xMax
+= wxSystemSettings::GetMetric(wxSYS_VSCROLL_X
);
3480 return wxRect(0, 0, xMax
, yMax
);
3484 wxListMainWindow::GetSubItemRect(long item
, long subItem
, wxRect
& rect
) const
3486 wxCHECK_MSG( subItem
== wxLIST_GETSUBITEMRECT_WHOLEITEM
|| InReportView(),
3488 wxT("GetSubItemRect only meaningful in report view") );
3489 wxCHECK_MSG( item
>= 0 && (size_t)item
< GetItemCount(), false,
3490 wxT("invalid item in GetSubItemRect") );
3492 // ensure that we're laid out, otherwise we could return nonsense
3495 wxConstCast(this, wxListMainWindow
)->
3496 RecalculatePositions(true /* no refresh */);
3499 rect
= GetLineRect((size_t)item
);
3501 // Adjust rect to specified column
3502 if ( subItem
!= wxLIST_GETSUBITEMRECT_WHOLEITEM
)
3504 wxCHECK_MSG( subItem
>= 0 && subItem
< GetColumnCount(), false,
3505 wxT("invalid subItem in GetSubItemRect") );
3507 for (int i
= 0; i
< subItem
; i
++)
3509 rect
.x
+= GetColumnWidth(i
);
3511 rect
.width
= GetColumnWidth(subItem
);
3514 GetListCtrl()->CalcScrolledPosition(rect
.x
, rect
.y
, &rect
.x
, &rect
.y
);
3519 bool wxListMainWindow::GetItemPosition(long item
, wxPoint
& pos
) const
3522 GetItemRect(item
, rect
);
3530 // ----------------------------------------------------------------------------
3531 // geometry calculation
3532 // ----------------------------------------------------------------------------
3534 void wxListMainWindow::RecalculatePositions(bool noRefresh
)
3536 const int lineHeight
= GetLineHeight();
3538 wxClientDC
dc( this );
3539 dc
.SetFont( GetFont() );
3541 const size_t count
= GetItemCount();
3544 if ( HasFlag(wxLC_ICON
) && m_normal_image_list
)
3545 iconSpacing
= m_normal_spacing
;
3546 else if ( HasFlag(wxLC_SMALL_ICON
) && m_small_image_list
)
3547 iconSpacing
= m_small_spacing
;
3551 // Note that we do not call GetClientSize() here but
3552 // GetSize() and subtract the border size for sunken
3553 // borders manually. This is technically incorrect,
3554 // but we need to know the client area's size WITHOUT
3555 // scrollbars here. Since we don't know if there are
3556 // any scrollbars, we use GetSize() instead. Another
3557 // solution would be to call SetScrollbars() here to
3558 // remove the scrollbars and call GetClientSize() then,
3559 // but this might result in flicker and - worse - will
3560 // reset the scrollbars to 0 which is not good at all
3561 // if you resize a dialog/window, but don't want to
3562 // reset the window scrolling. RR.
3563 // Furthermore, we actually do NOT subtract the border
3564 // width as 2 pixels is just the extra space which we
3565 // need around the actual content in the window. Other-
3566 // wise the text would e.g. touch the upper border. RR.
3569 GetSize( &clientWidth
, &clientHeight
);
3571 if ( InReportView() )
3573 // all lines have the same height and we scroll one line per step
3574 int entireHeight
= count
* lineHeight
+ LINE_SPACING
;
3576 m_linesPerPage
= clientHeight
/ lineHeight
;
3578 ResetVisibleLinesRange();
3580 GetListCtrl()->SetScrollbars( SCROLL_UNIT_X
, lineHeight
,
3581 GetHeaderWidth() / SCROLL_UNIT_X
,
3582 (entireHeight
+ lineHeight
- 1) / lineHeight
,
3583 GetListCtrl()->GetScrollPos(wxHORIZONTAL
),
3584 GetListCtrl()->GetScrollPos(wxVERTICAL
),
3589 // we have 3 different layout strategies: either layout all items
3590 // horizontally/vertically (wxLC_ALIGN_XXX styles explicitly given) or
3591 // to arrange them in top to bottom, left to right (don't ask me why
3592 // not the other way round...) order
3593 if ( HasFlag(wxLC_ALIGN_LEFT
| wxLC_ALIGN_TOP
) )
3595 int x
= EXTRA_BORDER_X
;
3596 int y
= EXTRA_BORDER_Y
;
3598 wxCoord widthMax
= 0;
3601 for ( i
= 0; i
< count
; i
++ )
3603 wxListLineData
*line
= GetLine(i
);
3604 line
->CalculateSize( &dc
, iconSpacing
);
3605 line
->SetPosition( x
, y
, iconSpacing
);
3607 wxSize sizeLine
= GetLineSize(i
);
3609 if ( HasFlag(wxLC_ALIGN_TOP
) )
3611 if ( sizeLine
.x
> widthMax
)
3612 widthMax
= sizeLine
.x
;
3616 else // wxLC_ALIGN_LEFT
3618 x
+= sizeLine
.x
+ MARGIN_BETWEEN_ROWS
;
3622 if ( HasFlag(wxLC_ALIGN_TOP
) )
3624 // traverse the items again and tweak their sizes so that they are
3625 // all the same in a row
3626 for ( i
= 0; i
< count
; i
++ )
3628 wxListLineData
*line
= GetLine(i
);
3629 line
->m_gi
->ExtendWidth(widthMax
);
3633 GetListCtrl()->SetScrollbars
3637 (x
+ SCROLL_UNIT_X
) / SCROLL_UNIT_X
,
3638 (y
+ lineHeight
) / lineHeight
,
3639 GetListCtrl()->GetScrollPos( wxHORIZONTAL
),
3640 GetListCtrl()->GetScrollPos( wxVERTICAL
),
3644 else // "flowed" arrangement, the most complicated case
3646 // at first we try without any scrollbars, if the items don't fit into
3647 // the window, we recalculate after subtracting the space taken by the
3650 int entireWidth
= 0;
3652 for (int tries
= 0; tries
< 2; tries
++)
3654 entireWidth
= 2 * EXTRA_BORDER_X
;
3658 // Now we have decided that the items do not fit into the
3659 // client area, so we need a scrollbar
3660 entireWidth
+= SCROLL_UNIT_X
;
3663 int x
= EXTRA_BORDER_X
;
3664 int y
= EXTRA_BORDER_Y
;
3666 // Note that "row" here is vertical, i.e. what is called
3667 // "column" in many other places in wxWidgets.
3668 int maxWidthInThisRow
= 0;
3671 int currentlyVisibleLines
= 0;
3673 for (size_t i
= 0; i
< count
; i
++)
3675 currentlyVisibleLines
++;
3676 wxListLineData
*line
= GetLine( i
);
3677 line
->CalculateSize( &dc
, iconSpacing
);
3678 line
->SetPosition( x
, y
, iconSpacing
);
3680 wxSize sizeLine
= GetLineSize( i
);
3682 if ( maxWidthInThisRow
< sizeLine
.x
)
3683 maxWidthInThisRow
= sizeLine
.x
;
3686 if (currentlyVisibleLines
> m_linesPerPage
)
3687 m_linesPerPage
= currentlyVisibleLines
;
3689 // Have we reached the end of the row either because no
3690 // more items would fit or because there are simply no more
3692 if ( y
+ sizeLine
.y
>= clientHeight
3695 // Adjust all items in this row to have the same
3696 // width to ensure that they all align horizontally in
3698 if ( HasFlag(wxLC_ICON
) || HasFlag(wxLC_SMALL_ICON
) )
3700 size_t firstRowLine
= i
- currentlyVisibleLines
+ 1;
3701 for (size_t j
= firstRowLine
; j
<= i
; j
++)
3703 GetLine(j
)->m_gi
->ExtendWidth(maxWidthInThisRow
);
3707 currentlyVisibleLines
= 0;
3709 maxWidthInThisRow
+= MARGIN_BETWEEN_ROWS
;
3710 x
+= maxWidthInThisRow
;
3711 entireWidth
+= maxWidthInThisRow
;
3712 maxWidthInThisRow
= 0;
3715 if ( (tries
== 0) &&
3716 (entireWidth
+ SCROLL_UNIT_X
> clientWidth
) )
3718 clientHeight
-= wxSystemSettings::
3719 GetMetric(wxSYS_HSCROLL_Y
);
3724 if ( i
== count
- 1 )
3725 tries
= 1; // Everything fits, no second try required.
3729 GetListCtrl()->SetScrollbars
3733 (entireWidth
+ SCROLL_UNIT_X
) / SCROLL_UNIT_X
,
3735 GetListCtrl()->GetScrollPos( wxHORIZONTAL
),
3744 // FIXME: why should we call it from here?
3751 void wxListMainWindow::RefreshAll()
3756 wxListHeaderWindow
*headerWin
= GetListCtrl()->m_headerWin
;
3757 if ( headerWin
&& headerWin
->m_dirty
)
3759 headerWin
->m_dirty
= false;
3760 headerWin
->Refresh();
3764 void wxListMainWindow::UpdateCurrent()
3766 if ( !HasCurrent() && !IsEmpty() )
3770 long wxListMainWindow::GetNextItem( long item
,
3771 int WXUNUSED(geometry
),
3775 max
= GetItemCount();
3776 wxCHECK_MSG( (ret
== -1) || (ret
< max
), -1,
3777 wxT("invalid listctrl index in GetNextItem()") );
3779 // notice that we start with the next item (or the first one if item == -1)
3780 // and this is intentional to allow writing a simple loop to iterate over
3781 // all selected items
3784 // this is not an error because the index was OK initially,
3785 // just no such item
3792 size_t count
= GetItemCount();
3793 for ( size_t line
= (size_t)ret
; line
< count
; line
++ )
3795 if ( (state
& wxLIST_STATE_FOCUSED
) && (line
== m_current
) )
3798 if ( (state
& wxLIST_STATE_SELECTED
) && IsHighlighted(line
) )
3805 // ----------------------------------------------------------------------------
3807 // ----------------------------------------------------------------------------
3809 void wxListMainWindow::DeleteItem( long lindex
)
3811 size_t count
= GetItemCount();
3813 wxCHECK_RET( (lindex
>= 0) && ((size_t)lindex
< count
),
3814 wxT("invalid item index in DeleteItem") );
3816 size_t index
= (size_t)lindex
;
3818 // we don't need to adjust the index for the previous items
3819 if ( HasCurrent() && m_current
>= index
)
3821 // if the current item is being deleted, we want the next one to
3822 // become selected - unless there is no next one - so don't adjust
3823 // m_current in this case
3824 if ( m_current
!= index
|| m_current
== count
- 1 )
3828 if ( InReportView() )
3830 // mark the Column Max Width cache as dirty if the items in the line
3831 // we're deleting contain the Max Column Width
3832 wxListLineData
* const line
= GetLine(index
);
3833 wxListItemDataList::compatibility_iterator n
;
3834 wxListItemData
*itemData
;
3838 for (size_t i
= 0; i
< m_columns
.GetCount(); i
++)
3840 n
= line
->m_items
.Item( i
);
3841 itemData
= n
->GetData();
3842 itemData
->GetItem(item
);
3844 itemWidth
= GetItemWidthWithImage(&item
);
3846 if (itemWidth
>= m_aColWidths
.Item(i
)->nMaxWidth
)
3847 m_aColWidths
.Item(i
)->bNeedsUpdate
= true;
3850 ResetVisibleLinesRange();
3853 SendNotify( index
, wxEVT_COMMAND_LIST_DELETE_ITEM
, wxDefaultPosition
);
3858 m_selStore
.OnItemDelete(index
);
3862 m_lines
.RemoveAt( index
);
3865 // we need to refresh the (vert) scrollbar as the number of items changed
3868 RefreshAfter(index
);
3871 void wxListMainWindow::DeleteColumn( int col
)
3873 wxListHeaderDataList::compatibility_iterator node
= m_columns
.Item( col
);
3875 wxCHECK_RET( node
, wxT("invalid column index in DeleteColumn()") );
3878 delete node
->GetData();
3879 m_columns
.Erase( node
);
3883 // update all the items
3884 for ( size_t i
= 0; i
< m_lines
.GetCount(); i
++ )
3886 wxListLineData
* const line
= GetLine(i
);
3888 // In the following atypical but possible scenario it can be
3889 // legal to call DeleteColumn() but the items may not have any
3891 // 1. In report view, insert a second column.
3892 // 2. Still in report view, add an item with 2 values.
3893 // 3. Switch to an icon (or list) view.
3894 // 4. Add an item -- necessarily with 1 value only.
3895 // 5. Switch back to report view.
3896 // 6. Call DeleteColumn().
3897 // So we need to check for this as otherwise we would simply crash
3899 if ( line
->m_items
.GetCount() <= static_cast<unsigned>(col
) )
3902 wxListItemDataList::compatibility_iterator n
= line
->m_items
.Item( col
);
3903 delete n
->GetData();
3904 line
->m_items
.Erase(n
);
3908 if ( InReportView() ) // we only cache max widths when in Report View
3910 delete m_aColWidths
.Item(col
);
3911 m_aColWidths
.RemoveAt(col
);
3914 // invalidate it as it has to be recalculated
3918 void wxListMainWindow::DoDeleteAllItems()
3921 // nothing to do - in particular, don't send the event
3926 // to make the deletion of all items faster, we don't send the
3927 // notifications for each item deletion in this case but only one event
3928 // for all of them: this is compatible with wxMSW and documented in
3929 // DeleteAllItems() description
3931 wxListEvent
event( wxEVT_COMMAND_LIST_DELETE_ALL_ITEMS
, GetParent()->GetId() );
3932 event
.SetEventObject( GetParent() );
3933 GetParent()->GetEventHandler()->ProcessEvent( event
);
3941 if ( InReportView() )
3943 ResetVisibleLinesRange();
3944 for (size_t i
= 0; i
< m_aColWidths
.GetCount(); i
++)
3946 m_aColWidths
.Item(i
)->bNeedsUpdate
= true;
3953 void wxListMainWindow::DeleteAllItems()
3957 RecalculatePositions();
3960 void wxListMainWindow::DeleteEverything()
3962 WX_CLEAR_LIST(wxListHeaderDataList
, m_columns
);
3963 WX_CLEAR_ARRAY(m_aColWidths
);
3968 // ----------------------------------------------------------------------------
3969 // scanning for an item
3970 // ----------------------------------------------------------------------------
3972 void wxListMainWindow::EnsureVisible( long index
)
3974 wxCHECK_RET( index
>= 0 && (size_t)index
< GetItemCount(),
3975 wxT("invalid index in EnsureVisible") );
3977 // We have to call this here because the label in question might just have
3978 // been added and its position is not known yet
3980 RecalculatePositions(true /* no refresh */);
3982 MoveToItem((size_t)index
);
3985 long wxListMainWindow::FindItem(long start
, const wxString
& str
, bool partial
)
3991 wxString str_upper
= str
.Upper();
3995 size_t count
= GetItemCount();
3996 for ( size_t i
= (size_t)pos
; i
< count
; i
++ )
3998 wxListLineData
*line
= GetLine(i
);
3999 wxString line_upper
= line
->GetText(0).Upper();
4002 if (line_upper
== str_upper
)
4007 if (line_upper
.find(str_upper
) == 0)
4015 long wxListMainWindow::FindItem(long start
, wxUIntPtr data
)
4021 size_t count
= GetItemCount();
4022 for (size_t i
= (size_t)pos
; i
< count
; i
++)
4024 wxListLineData
*line
= GetLine(i
);
4026 line
->GetItem( 0, item
);
4027 if (item
.m_data
== data
)
4034 long wxListMainWindow::FindItem( const wxPoint
& pt
)
4037 GetVisibleLinesRange( &topItem
, NULL
);
4040 GetItemPosition( GetItemCount() - 1, p
);
4044 long id
= (long)floor( pt
.y
* double(GetItemCount() - topItem
- 1) / p
.y
+ topItem
);
4045 if ( id
>= 0 && id
< (long)GetItemCount() )
4051 long wxListMainWindow::HitTest( int x
, int y
, int &flags
) const
4053 GetListCtrl()->CalcUnscrolledPosition( x
, y
, &x
, &y
);
4055 size_t count
= GetItemCount();
4057 if ( InReportView() )
4059 size_t current
= y
/ GetLineHeight();
4060 if ( current
< count
)
4062 flags
= HitTestLine(current
, x
, y
);
4069 // TODO: optimize it too! this is less simple than for report view but
4070 // enumerating all items is still not a way to do it!!
4071 for ( size_t current
= 0; current
< count
; current
++ )
4073 flags
= HitTestLine(current
, x
, y
);
4082 // ----------------------------------------------------------------------------
4084 // ----------------------------------------------------------------------------
4086 void wxListMainWindow::InsertItem( wxListItem
&item
)
4088 wxASSERT_MSG( !IsVirtual(), wxT("can't be used with virtual control") );
4090 int count
= GetItemCount();
4091 wxCHECK_RET( item
.m_itemId
>= 0, wxT("invalid item index") );
4093 if (item
.m_itemId
> count
)
4094 item
.m_itemId
= count
;
4096 size_t id
= item
.m_itemId
;
4100 if ( InReportView() )
4102 ResetVisibleLinesRange();
4104 const unsigned col
= item
.GetColumn();
4105 wxCHECK_RET( col
< m_aColWidths
.size(), "invalid item column" );
4107 // calculate the width of the item and adjust the max column width
4108 wxColWidthInfo
*pWidthInfo
= m_aColWidths
.Item(col
);
4109 int width
= GetItemWidthWithImage(&item
);
4110 item
.SetWidth(width
);
4111 if (width
> pWidthInfo
->nMaxWidth
)
4112 pWidthInfo
->nMaxWidth
= width
;
4115 wxListLineData
*line
= new wxListLineData(this);
4117 line
->SetItem( item
.m_col
, item
);
4118 if ( item
.m_mask
& wxLIST_MASK_IMAGE
)
4120 // Reset the buffered height if it's not big enough for the new image.
4121 int image
= item
.GetImage();
4122 if ( m_small_image_list
&& image
!= -1 && InReportView() )
4124 int imageWidth
, imageHeight
;
4125 m_small_image_list
->GetSize(image
, imageWidth
, imageHeight
);
4127 if ( imageHeight
> m_lineHeight
)
4132 m_lines
.Insert( line
, id
);
4136 // If an item is selected at or below the point of insertion, we need to
4137 // increment the member variables because the current row's index has gone
4139 if ( HasCurrent() && m_current
>= id
)
4142 SendNotify(id
, wxEVT_COMMAND_LIST_INSERT_ITEM
);
4144 RefreshLines(id
, GetItemCount() - 1);
4147 long wxListMainWindow::InsertColumn( long col
, const wxListItem
&item
)
4152 if ( InReportView() )
4154 wxListHeaderData
*column
= new wxListHeaderData( item
);
4155 if (item
.m_width
== wxLIST_AUTOSIZE_USEHEADER
)
4156 column
->SetWidth(ComputeMinHeaderWidth(column
));
4158 wxColWidthInfo
*colWidthInfo
= new wxColWidthInfo();
4160 bool insert
= (col
>= 0) && ((size_t)col
< m_columns
.GetCount());
4163 wxListHeaderDataList::compatibility_iterator
4164 node
= m_columns
.Item( col
);
4165 m_columns
.Insert( node
, column
);
4166 m_aColWidths
.Insert( colWidthInfo
, col
);
4171 idx
= m_aColWidths
.GetCount();
4172 m_columns
.Append( column
);
4173 m_aColWidths
.Add( colWidthInfo
);
4178 // update all the items
4179 for ( size_t i
= 0; i
< m_lines
.GetCount(); i
++ )
4181 wxListLineData
* const line
= GetLine(i
);
4182 wxListItemData
* const data
= new wxListItemData(this);
4184 line
->m_items
.Insert(col
, data
);
4186 line
->m_items
.Append(data
);
4190 // invalidate it as it has to be recalculated
4196 int wxListMainWindow::GetItemWidthWithImage(wxListItem
* item
)
4199 wxClientDC
dc(this);
4201 dc
.SetFont( GetFont() );
4203 if (item
->GetImage() != -1)
4206 GetImageSize( item
->GetImage(), ix
, iy
);
4210 if (!item
->GetText().empty())
4213 dc
.GetTextExtent( item
->GetText(), &w
, NULL
);
4220 // ----------------------------------------------------------------------------
4222 // ----------------------------------------------------------------------------
4224 static wxListCtrlCompare list_ctrl_compare_func_2
;
4225 static wxIntPtr list_ctrl_compare_data
;
4227 int LINKAGEMODE
list_ctrl_compare_func_1( wxListLineData
**arg1
, wxListLineData
**arg2
)
4229 wxListLineData
*line1
= *arg1
;
4230 wxListLineData
*line2
= *arg2
;
4232 line1
->GetItem( 0, item
);
4233 wxUIntPtr data1
= item
.m_data
;
4234 line2
->GetItem( 0, item
);
4235 wxUIntPtr data2
= item
.m_data
;
4236 return list_ctrl_compare_func_2( data1
, data2
, list_ctrl_compare_data
);
4239 void wxListMainWindow::SortItems( wxListCtrlCompare fn
, wxIntPtr data
)
4241 // selections won't make sense any more after sorting the items so reset
4243 HighlightAll(false);
4246 list_ctrl_compare_func_2
= fn
;
4247 list_ctrl_compare_data
= data
;
4248 m_lines
.Sort( list_ctrl_compare_func_1
);
4252 // ----------------------------------------------------------------------------
4254 // ----------------------------------------------------------------------------
4256 void wxListMainWindow::OnScroll(wxScrollWinEvent
& event
)
4258 // update our idea of which lines are shown when we redraw the window the
4260 ResetVisibleLinesRange();
4262 if ( event
.GetOrientation() == wxHORIZONTAL
&& HasHeader() )
4264 wxGenericListCtrl
* lc
= GetListCtrl();
4265 wxCHECK_RET( lc
, wxT("no listctrl window?") );
4267 if (lc
->m_headerWin
) // when we use wxLC_NO_HEADER, m_headerWin==NULL
4269 lc
->m_headerWin
->Refresh();
4270 lc
->m_headerWin
->Update();
4275 int wxListMainWindow::GetCountPerPage() const
4277 if ( !m_linesPerPage
)
4279 wxConstCast(this, wxListMainWindow
)->
4280 m_linesPerPage
= GetClientSize().y
/ GetLineHeight();
4283 return m_linesPerPage
;
4286 void wxListMainWindow::GetVisibleLinesRange(size_t *from
, size_t *to
)
4288 wxASSERT_MSG( InReportView(), wxT("this is for report mode only") );
4290 if ( m_lineFrom
== (size_t)-1 )
4292 size_t count
= GetItemCount();
4295 m_lineFrom
= GetListCtrl()->GetScrollPos(wxVERTICAL
);
4297 // this may happen if SetScrollbars() hadn't been called yet
4298 if ( m_lineFrom
>= count
)
4299 m_lineFrom
= count
- 1;
4301 // we redraw one extra line but this is needed to make the redrawing
4302 // logic work when there is a fractional number of lines on screen
4303 m_lineTo
= m_lineFrom
+ m_linesPerPage
;
4304 if ( m_lineTo
>= count
)
4305 m_lineTo
= count
- 1;
4307 else // empty control
4310 m_lineTo
= (size_t)-1;
4314 wxASSERT_MSG( IsEmpty() ||
4315 (m_lineFrom
<= m_lineTo
&& m_lineTo
< GetItemCount()),
4316 wxT("GetVisibleLinesRange() returns incorrect result") );
4324 // -------------------------------------------------------------------------------------
4325 // wxGenericListCtrl
4326 // -------------------------------------------------------------------------------------
4328 IMPLEMENT_DYNAMIC_CLASS(wxGenericListCtrl
, wxControl
)
4330 BEGIN_EVENT_TABLE(wxGenericListCtrl
,wxListCtrlBase
)
4331 EVT_SIZE(wxGenericListCtrl::OnSize
)
4332 EVT_SCROLLWIN(wxGenericListCtrl::OnScroll
)
4335 void wxGenericListCtrl::Init()
4337 m_imageListNormal
= NULL
;
4338 m_imageListSmall
= NULL
;
4339 m_imageListState
= NULL
;
4341 m_ownsImageListNormal
=
4342 m_ownsImageListSmall
=
4343 m_ownsImageListState
= false;
4349 wxGenericListCtrl::~wxGenericListCtrl()
4351 if (m_ownsImageListNormal
)
4352 delete m_imageListNormal
;
4353 if (m_ownsImageListSmall
)
4354 delete m_imageListSmall
;
4355 if (m_ownsImageListState
)
4356 delete m_imageListState
;
4359 void wxGenericListCtrl::CreateOrDestroyHeaderWindowAsNeeded()
4361 bool needs_header
= HasHeader();
4362 bool has_header
= (m_headerWin
!= NULL
);
4364 if (needs_header
== has_header
)
4369 m_headerWin
= new wxListHeaderWindow
4371 this, wxID_ANY
, m_mainWin
,
4376 wxRendererNative::Get().GetHeaderButtonHeight(this)
4381 #if defined( __WXMAC__ )
4382 static wxFont
font( wxOSX_SYSTEM_FONT_SMALL
);
4383 m_headerWin
->SetFont( font
);
4386 GetSizer()->Prepend( m_headerWin
, 0, wxGROW
);
4390 GetSizer()->Detach( m_headerWin
);
4392 wxDELETE(m_headerWin
);
4396 bool wxGenericListCtrl::Create(wxWindow
*parent
,
4401 const wxValidator
&validator
,
4402 const wxString
&name
)
4406 // just like in other ports, an assert will fail if the user doesn't give any type style:
4407 wxASSERT_MSG( (style
& wxLC_MASK_TYPE
),
4408 wxT("wxListCtrl style should have exactly one mode bit set") );
4410 if ( !wxListCtrlBase::Create( parent
, id
, pos
, size
,
4411 style
| wxVSCROLL
| wxHSCROLL
,
4415 m_mainWin
= new wxListMainWindow(this, wxID_ANY
, wxPoint(0, 0), size
);
4417 SetTargetWindow( m_mainWin
);
4419 // We use the cursor keys for moving the selection, not scrolling, so call
4420 // this method to ensure wxScrollHelperEvtHandler doesn't catch all
4421 // keyboard events forwarded to us from wxListMainWindow.
4422 DisableKeyboardScrolling();
4424 wxBoxSizer
*sizer
= new wxBoxSizer( wxVERTICAL
);
4425 sizer
->Add( m_mainWin
, 1, wxGROW
);
4428 CreateOrDestroyHeaderWindowAsNeeded();
4430 SetInitialSize(size
);
4435 wxBorder
wxGenericListCtrl::GetDefaultBorder() const
4437 return wxBORDER_THEME
;
4440 #if defined(__WXMSW__) && !defined(__WXWINCE__) && !defined(__WXUNIVERSAL__)
4441 WXLRESULT
wxGenericListCtrl::MSWWindowProc(WXUINT nMsg
,
4445 WXLRESULT rc
= wxListCtrlBase::MSWWindowProc(nMsg
, wParam
, lParam
);
4447 // we need to process arrows ourselves for scrolling
4448 if ( nMsg
== WM_GETDLGCODE
)
4450 rc
|= DLGC_WANTARROWS
;
4457 wxSize
wxGenericListCtrl::GetSizeAvailableForScrollTarget(const wxSize
& size
)
4459 wxSize newsize
= size
;
4461 newsize
.y
-= m_headerWin
->GetSize().y
;
4466 void wxGenericListCtrl::OnScroll(wxScrollWinEvent
& event
)
4468 // update our idea of which lines are shown when we redraw
4469 // the window the next time
4470 m_mainWin
->ResetVisibleLinesRange();
4472 HandleOnScroll( event
);
4474 if ( event
.GetOrientation() == wxHORIZONTAL
&& HasHeader() )
4476 m_headerWin
->Refresh();
4477 m_headerWin
->Update();
4481 void wxGenericListCtrl::SetSingleStyle( long style
, bool add
)
4483 wxASSERT_MSG( !(style
& wxLC_VIRTUAL
),
4484 wxT("wxLC_VIRTUAL can't be [un]set") );
4486 long flag
= GetWindowStyle();
4490 if (style
& wxLC_MASK_TYPE
)
4491 flag
&= ~(wxLC_MASK_TYPE
| wxLC_VIRTUAL
);
4492 if (style
& wxLC_MASK_ALIGN
)
4493 flag
&= ~wxLC_MASK_ALIGN
;
4494 if (style
& wxLC_MASK_SORT
)
4495 flag
&= ~wxLC_MASK_SORT
;
4503 // some styles can be set without recreating everything (as happens in
4504 // SetWindowStyleFlag() which calls wxListMainWindow::DeleteEverything())
4505 if ( !(style
& ~(wxLC_HRULES
| wxLC_VRULES
)) )
4508 wxWindow::SetWindowStyleFlag(flag
);
4512 SetWindowStyleFlag( flag
);
4516 void wxGenericListCtrl::SetWindowStyleFlag( long flag
)
4518 // we add wxHSCROLL and wxVSCROLL in ctor unconditionally and it never
4519 // makes sense to remove them as we'll always add scrollbars anyhow when
4521 flag
|= wxHSCROLL
| wxVSCROLL
;
4523 const bool wasInReportView
= HasFlag(wxLC_REPORT
);
4525 // update the window style first so that the header is created or destroyed
4526 // corresponding to the new style
4527 wxWindow::SetWindowStyleFlag( flag
);
4531 const bool inReportView
= (flag
& wxLC_REPORT
) != 0;
4532 if ( inReportView
!= wasInReportView
)
4534 // we need to notify the main window about this change as it must
4535 // update its data structures
4536 m_mainWin
->SetReportView(inReportView
);
4539 // m_mainWin->DeleteEverything(); wxMSW doesn't do that
4541 CreateOrDestroyHeaderWindowAsNeeded();
4543 GetSizer()->Layout();
4547 bool wxGenericListCtrl::GetColumn(int col
, wxListItem
&item
) const
4549 m_mainWin
->GetColumn( col
, item
);
4553 bool wxGenericListCtrl::SetColumn( int col
, const wxListItem
& item
)
4555 m_mainWin
->SetColumn( col
, item
);
4559 int wxGenericListCtrl::GetColumnWidth( int col
) const
4561 return m_mainWin
->GetColumnWidth( col
);
4564 bool wxGenericListCtrl::SetColumnWidth( int col
, int width
)
4566 m_mainWin
->SetColumnWidth( col
, width
);
4570 int wxGenericListCtrl::GetCountPerPage() const
4572 return m_mainWin
->GetCountPerPage(); // different from Windows ?
4575 bool wxGenericListCtrl::GetItem( wxListItem
&info
) const
4577 m_mainWin
->GetItem( info
);
4581 bool wxGenericListCtrl::SetItem( wxListItem
&info
)
4583 m_mainWin
->SetItem( info
);
4587 long wxGenericListCtrl::SetItem( long index
, int col
, const wxString
& label
, int imageId
)
4590 info
.m_text
= label
;
4591 info
.m_mask
= wxLIST_MASK_TEXT
;
4592 info
.m_itemId
= index
;
4596 info
.m_image
= imageId
;
4597 info
.m_mask
|= wxLIST_MASK_IMAGE
;
4600 m_mainWin
->SetItem(info
);
4604 int wxGenericListCtrl::GetItemState( long item
, long stateMask
) const
4606 return m_mainWin
->GetItemState( item
, stateMask
);
4609 bool wxGenericListCtrl::SetItemState( long item
, long state
, long stateMask
)
4611 m_mainWin
->SetItemState( item
, state
, stateMask
);
4616 wxGenericListCtrl::SetItemImage( long item
, int image
, int WXUNUSED(selImage
) )
4618 return SetItemColumnImage(item
, 0, image
);
4622 wxGenericListCtrl::SetItemColumnImage( long item
, long column
, int image
)
4625 info
.m_image
= image
;
4626 info
.m_mask
= wxLIST_MASK_IMAGE
;
4627 info
.m_itemId
= item
;
4628 info
.m_col
= column
;
4629 m_mainWin
->SetItem( info
);
4633 wxString
wxGenericListCtrl::GetItemText( long item
, int col
) const
4635 return m_mainWin
->GetItemText(item
, col
);
4638 void wxGenericListCtrl::SetItemText( long item
, const wxString
& str
)
4640 m_mainWin
->SetItemText(item
, str
);
4643 wxUIntPtr
wxGenericListCtrl::GetItemData( long item
) const
4646 info
.m_mask
= wxLIST_MASK_DATA
;
4647 info
.m_itemId
= item
;
4648 m_mainWin
->GetItem( info
);
4652 bool wxGenericListCtrl::SetItemPtrData( long item
, wxUIntPtr data
)
4655 info
.m_mask
= wxLIST_MASK_DATA
;
4656 info
.m_itemId
= item
;
4658 m_mainWin
->SetItem( info
);
4662 wxRect
wxGenericListCtrl::GetViewRect() const
4664 return m_mainWin
->GetViewRect();
4667 bool wxGenericListCtrl::GetItemRect(long item
, wxRect
& rect
, int code
) const
4669 return GetSubItemRect(item
, wxLIST_GETSUBITEMRECT_WHOLEITEM
, rect
, code
);
4672 bool wxGenericListCtrl::GetSubItemRect(long item
,
4675 int WXUNUSED(code
)) const
4677 if ( !m_mainWin
->GetSubItemRect( item
, subItem
, rect
) )
4680 if ( m_mainWin
->HasHeader() )
4681 rect
.y
+= m_headerWin
->GetSize().y
+ 1;
4686 bool wxGenericListCtrl::GetItemPosition( long item
, wxPoint
& pos
) const
4688 m_mainWin
->GetItemPosition( item
, pos
);
4692 bool wxGenericListCtrl::SetItemPosition( long WXUNUSED(item
), const wxPoint
& WXUNUSED(pos
) )
4697 int wxGenericListCtrl::GetItemCount() const
4699 return m_mainWin
->GetItemCount();
4702 int wxGenericListCtrl::GetColumnCount() const
4704 return m_mainWin
->GetColumnCount();
4707 void wxGenericListCtrl::SetItemSpacing( int spacing
, bool isSmall
)
4709 m_mainWin
->SetItemSpacing( spacing
, isSmall
);
4712 wxSize
wxGenericListCtrl::GetItemSpacing() const
4714 const int spacing
= m_mainWin
->GetItemSpacing(HasFlag(wxLC_SMALL_ICON
));
4716 return wxSize(spacing
, spacing
);
4719 #if WXWIN_COMPATIBILITY_2_6
4720 int wxGenericListCtrl::GetItemSpacing( bool isSmall
) const
4722 return m_mainWin
->GetItemSpacing( isSmall
);
4724 #endif // WXWIN_COMPATIBILITY_2_6
4726 void wxGenericListCtrl::SetItemTextColour( long item
, const wxColour
&col
)
4729 info
.m_itemId
= item
;
4730 info
.SetTextColour( col
);
4731 m_mainWin
->SetItem( info
);
4734 wxColour
wxGenericListCtrl::GetItemTextColour( long item
) const
4737 info
.m_itemId
= item
;
4738 m_mainWin
->GetItem( info
);
4739 return info
.GetTextColour();
4742 void wxGenericListCtrl::SetItemBackgroundColour( long item
, const wxColour
&col
)
4745 info
.m_itemId
= item
;
4746 info
.SetBackgroundColour( col
);
4747 m_mainWin
->SetItem( info
);
4750 wxColour
wxGenericListCtrl::GetItemBackgroundColour( long item
) const
4753 info
.m_itemId
= item
;
4754 m_mainWin
->GetItem( info
);
4755 return info
.GetBackgroundColour();
4758 void wxGenericListCtrl::SetItemFont( long item
, const wxFont
&f
)
4761 info
.m_itemId
= item
;
4763 m_mainWin
->SetItem( info
);
4766 wxFont
wxGenericListCtrl::GetItemFont( long item
) const
4769 info
.m_itemId
= item
;
4770 m_mainWin
->GetItem( info
);
4771 return info
.GetFont();
4774 int wxGenericListCtrl::GetSelectedItemCount() const
4776 return m_mainWin
->GetSelectedItemCount();
4779 wxColour
wxGenericListCtrl::GetTextColour() const
4781 return GetForegroundColour();
4784 void wxGenericListCtrl::SetTextColour(const wxColour
& col
)
4786 SetForegroundColour(col
);
4789 long wxGenericListCtrl::GetTopItem() const
4792 m_mainWin
->GetVisibleLinesRange(&top
, NULL
);
4796 long wxGenericListCtrl::GetNextItem( long item
, int geom
, int state
) const
4798 return m_mainWin
->GetNextItem( item
, geom
, state
);
4801 wxImageList
*wxGenericListCtrl::GetImageList(int which
) const
4803 if (which
== wxIMAGE_LIST_NORMAL
)
4804 return m_imageListNormal
;
4805 else if (which
== wxIMAGE_LIST_SMALL
)
4806 return m_imageListSmall
;
4807 else if (which
== wxIMAGE_LIST_STATE
)
4808 return m_imageListState
;
4813 void wxGenericListCtrl::SetImageList( wxImageList
*imageList
, int which
)
4815 if ( which
== wxIMAGE_LIST_NORMAL
)
4817 if (m_ownsImageListNormal
)
4818 delete m_imageListNormal
;
4819 m_imageListNormal
= imageList
;
4820 m_ownsImageListNormal
= false;
4822 else if ( which
== wxIMAGE_LIST_SMALL
)
4824 if (m_ownsImageListSmall
)
4825 delete m_imageListSmall
;
4826 m_imageListSmall
= imageList
;
4827 m_ownsImageListSmall
= false;
4829 else if ( which
== wxIMAGE_LIST_STATE
)
4831 if (m_ownsImageListState
)
4832 delete m_imageListState
;
4833 m_imageListState
= imageList
;
4834 m_ownsImageListState
= false;
4837 m_mainWin
->SetImageList( imageList
, which
);
4840 void wxGenericListCtrl::AssignImageList(wxImageList
*imageList
, int which
)
4842 SetImageList(imageList
, which
);
4843 if ( which
== wxIMAGE_LIST_NORMAL
)
4844 m_ownsImageListNormal
= true;
4845 else if ( which
== wxIMAGE_LIST_SMALL
)
4846 m_ownsImageListSmall
= true;
4847 else if ( which
== wxIMAGE_LIST_STATE
)
4848 m_ownsImageListState
= true;
4851 bool wxGenericListCtrl::Arrange( int WXUNUSED(flag
) )
4856 bool wxGenericListCtrl::DeleteItem( long item
)
4858 m_mainWin
->DeleteItem( item
);
4862 bool wxGenericListCtrl::DeleteAllItems()
4864 m_mainWin
->DeleteAllItems();
4868 bool wxGenericListCtrl::DeleteAllColumns()
4870 size_t count
= m_mainWin
->m_columns
.GetCount();
4871 for ( size_t n
= 0; n
< count
; n
++ )
4876 void wxGenericListCtrl::ClearAll()
4878 m_mainWin
->DeleteEverything();
4881 bool wxGenericListCtrl::DeleteColumn( int col
)
4883 m_mainWin
->DeleteColumn( col
);
4885 // if we don't have the header any longer, we need to relayout the window
4886 // if ( !GetColumnCount() )
4889 // Ensure that the non-existent columns are really removed from display.
4895 wxTextCtrl
*wxGenericListCtrl::EditLabel(long item
,
4896 wxClassInfo
* textControlClass
)
4898 return m_mainWin
->EditLabel( item
, textControlClass
);
4901 wxTextCtrl
*wxGenericListCtrl::GetEditControl() const
4903 return m_mainWin
->GetEditControl();
4906 bool wxGenericListCtrl::EnsureVisible( long item
)
4908 m_mainWin
->EnsureVisible( item
);
4912 long wxGenericListCtrl::FindItem( long start
, const wxString
& str
, bool partial
)
4914 return m_mainWin
->FindItem( start
, str
, partial
);
4917 long wxGenericListCtrl::FindItem( long start
, wxUIntPtr data
)
4919 return m_mainWin
->FindItem( start
, data
);
4922 long wxGenericListCtrl::FindItem( long WXUNUSED(start
), const wxPoint
& pt
,
4923 int WXUNUSED(direction
))
4925 return m_mainWin
->FindItem( pt
);
4928 // TODO: sub item hit testing
4929 long wxGenericListCtrl::HitTest(const wxPoint
& point
, int& flags
, long *) const
4931 return m_mainWin
->HitTest( (int)point
.x
, (int)point
.y
, flags
);
4934 long wxGenericListCtrl::InsertItem( wxListItem
& info
)
4936 m_mainWin
->InsertItem( info
);
4937 return info
.m_itemId
;
4940 long wxGenericListCtrl::InsertItem( long index
, const wxString
&label
)
4943 info
.m_text
= label
;
4944 info
.m_mask
= wxLIST_MASK_TEXT
;
4945 info
.m_itemId
= index
;
4946 return InsertItem( info
);
4949 long wxGenericListCtrl::InsertItem( long index
, int imageIndex
)
4952 info
.m_mask
= wxLIST_MASK_IMAGE
;
4953 info
.m_image
= imageIndex
;
4954 info
.m_itemId
= index
;
4955 return InsertItem( info
);
4958 long wxGenericListCtrl::InsertItem( long index
, const wxString
&label
, int imageIndex
)
4961 info
.m_text
= label
;
4962 info
.m_image
= imageIndex
;
4963 info
.m_mask
= wxLIST_MASK_TEXT
;
4964 if (imageIndex
> -1)
4965 info
.m_mask
|= wxLIST_MASK_IMAGE
;
4966 info
.m_itemId
= index
;
4967 return InsertItem( info
);
4970 long wxGenericListCtrl::DoInsertColumn( long col
, const wxListItem
&item
)
4972 wxCHECK_MSG( InReportView(), -1, wxT("can't add column in non report mode") );
4974 long idx
= m_mainWin
->InsertColumn( col
, item
);
4976 // NOTE: if wxLC_NO_HEADER was given, then we are in report view mode but
4977 // still have m_headerWin==NULL
4979 m_headerWin
->Refresh();
4984 bool wxGenericListCtrl::ScrollList( int dx
, int dy
)
4986 return m_mainWin
->ScrollList(dx
, dy
);
4990 // fn is a function which takes 3 long arguments: item1, item2, data.
4991 // item1 is the long data associated with a first item (NOT the index).
4992 // item2 is the long data associated with a second item (NOT the index).
4993 // data is the same value as passed to SortItems.
4994 // The return value is a negative number if the first item should precede the second
4995 // item, a positive number of the second item should precede the first,
4996 // or zero if the two items are equivalent.
4997 // data is arbitrary data to be passed to the sort function.
4999 bool wxGenericListCtrl::SortItems( wxListCtrlCompare fn
, wxIntPtr data
)
5001 m_mainWin
->SortItems( fn
, data
);
5005 // ----------------------------------------------------------------------------
5007 // ----------------------------------------------------------------------------
5009 void wxGenericListCtrl::OnSize(wxSizeEvent
& WXUNUSED(event
))
5011 if (!m_mainWin
) return;
5013 // We need to override OnSize so that our scrolled
5014 // window a) does call Layout() to use sizers for
5015 // positioning the controls but b) does not query
5016 // the sizer for their size and use that for setting
5017 // the scrollable area as set that ourselves by
5018 // calling SetScrollbar() further down.
5022 m_mainWin
->RecalculatePositions();
5027 void wxGenericListCtrl::OnInternalIdle()
5029 wxWindow::OnInternalIdle();
5031 if (m_mainWin
->m_dirty
)
5032 m_mainWin
->RecalculatePositions();
5035 // ----------------------------------------------------------------------------
5037 // ----------------------------------------------------------------------------
5039 bool wxGenericListCtrl::SetBackgroundColour( const wxColour
&colour
)
5043 m_mainWin
->SetBackgroundColour( colour
);
5044 m_mainWin
->m_dirty
= true;
5050 bool wxGenericListCtrl::SetForegroundColour( const wxColour
&colour
)
5052 if ( !wxWindow::SetForegroundColour( colour
) )
5057 m_mainWin
->SetForegroundColour( colour
);
5058 m_mainWin
->m_dirty
= true;
5062 m_headerWin
->SetForegroundColour( colour
);
5067 bool wxGenericListCtrl::SetFont( const wxFont
&font
)
5069 if ( !wxWindow::SetFont( font
) )
5074 m_mainWin
->SetFont( font
);
5075 m_mainWin
->m_dirty
= true;
5080 m_headerWin
->SetFont( font
);
5081 // CalculateAndSetHeaderHeight();
5091 wxGenericListCtrl::GetClassDefaultAttributes(wxWindowVariant variant
)
5094 // Use the same color scheme as wxListBox
5095 return wxListBox::GetClassDefaultAttributes(variant
);
5097 wxUnusedVar(variant
);
5098 wxVisualAttributes attr
;
5099 attr
.colFg
= wxSystemSettings::GetColour(wxSYS_COLOUR_LISTBOXTEXT
);
5100 attr
.colBg
= wxSystemSettings::GetColour(wxSYS_COLOUR_LISTBOX
);
5101 attr
.font
= wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT
);
5106 // ----------------------------------------------------------------------------
5107 // methods forwarded to m_mainWin
5108 // ----------------------------------------------------------------------------
5110 #if wxUSE_DRAG_AND_DROP
5112 void wxGenericListCtrl::SetDropTarget( wxDropTarget
*dropTarget
)
5114 m_mainWin
->SetDropTarget( dropTarget
);
5117 wxDropTarget
*wxGenericListCtrl::GetDropTarget() const
5119 return m_mainWin
->GetDropTarget();
5124 bool wxGenericListCtrl::SetCursor( const wxCursor
&cursor
)
5126 return m_mainWin
? m_mainWin
->wxWindow::SetCursor(cursor
) : false;
5129 wxColour
wxGenericListCtrl::GetBackgroundColour() const
5131 return m_mainWin
? m_mainWin
->GetBackgroundColour() : wxColour();
5134 wxColour
wxGenericListCtrl::GetForegroundColour() const
5136 return m_mainWin
? m_mainWin
->GetForegroundColour() : wxColour();
5139 bool wxGenericListCtrl::DoPopupMenu( wxMenu
*menu
, int x
, int y
)
5142 return m_mainWin
->PopupMenu( menu
, x
, y
);
5148 void wxGenericListCtrl::DoClientToScreen( int *x
, int *y
) const
5150 // It's not clear whether this can be called before m_mainWin is created
5151 // but it seems better to be on the safe side and check.
5153 m_mainWin
->DoClientToScreen(x
, y
);
5155 wxListCtrlBase::DoClientToScreen(x
, y
);
5158 void wxGenericListCtrl::DoScreenToClient( int *x
, int *y
) const
5160 // At least in wxGTK/Univ build this method can be called before m_mainWin
5161 // is created so avoid crashes in this case.
5163 m_mainWin
->DoScreenToClient(x
, y
);
5165 wxListCtrlBase::DoScreenToClient(x
, y
);
5168 wxSize
wxGenericListCtrl::DoGetBestClientSize() const
5170 // The base class version can compute the best size in report view only.
5171 wxSize sizeBest
= wxListCtrlBase::DoGetBestClientSize();
5173 if ( !InReportView() )
5175 // Ensure that our minimal width is at least big enough to show all our
5176 // items. This is important for wxListbook to size itself correctly.
5178 // Remember the offset of the first item: this corresponds to the
5179 // margins around the item so we will add it to the minimal size below
5180 // to ensure that we have equal margins on all sides.
5183 // We can iterate over all items as there shouldn't be too many of them
5184 // in non-report view. If it ever becomes a problem, we could examine
5185 // just the first few items probably, the determination of the best
5186 // size is less important if we will need scrollbars anyhow.
5187 for ( int n
= 0; n
< GetItemCount(); n
++ )
5189 const wxRect itemRect
= m_mainWin
->GetLineRect(n
);
5192 // Remember the position of the first item as all the rest are
5193 // offset by at least this number of pixels too.
5194 ofs
= itemRect
.GetPosition();
5197 sizeBest
.IncTo(itemRect
.GetSize());
5200 sizeBest
.IncBy(2*ofs
);
5203 // If we have the scrollbars we need to account for them too. And to
5204 // make sure the scrollbars status is up to date we need to call this
5205 // function to set them.
5206 m_mainWin
->RecalculatePositions(true /* no refresh */);
5208 // Unfortunately we can't use wxWindow::HasScrollbar() here as we need
5209 // to use m_mainWin client/virtual size for determination of whether we
5210 // use scrollbars and not the size of this window itself. Maybe that
5211 // function should be extended to work correctly in the case when our
5212 // scrollbars manage a different window from this one but currently it
5214 const wxSize sizeClient
= m_mainWin
->GetClientSize();
5215 const wxSize sizeVirt
= m_mainWin
->GetVirtualSize();
5217 if ( sizeVirt
.x
> sizeClient
.x
/* HasScrollbar(wxHORIZONTAL) */ )
5218 sizeBest
.y
+= wxSystemSettings::GetMetric(wxSYS_HSCROLL_Y
);
5220 if ( sizeVirt
.y
> sizeClient
.y
/* HasScrollbar(wxVERTICAL) */ )
5221 sizeBest
.x
+= wxSystemSettings::GetMetric(wxSYS_VSCROLL_X
);
5227 // ----------------------------------------------------------------------------
5228 // virtual list control support
5229 // ----------------------------------------------------------------------------
5231 wxString
wxGenericListCtrl::OnGetItemText(long WXUNUSED(item
), long WXUNUSED(col
)) const
5233 // this is a pure virtual function, in fact - which is not really pure
5234 // because the controls which are not virtual don't need to implement it
5235 wxFAIL_MSG( wxT("wxGenericListCtrl::OnGetItemText not supposed to be called") );
5237 return wxEmptyString
;
5240 int wxGenericListCtrl::OnGetItemImage(long WXUNUSED(item
)) const
5242 wxCHECK_MSG(!GetImageList(wxIMAGE_LIST_SMALL
),
5244 wxT("List control has an image list, OnGetItemImage or OnGetItemColumnImage should be overridden."));
5248 int wxGenericListCtrl::OnGetItemColumnImage(long item
, long column
) const
5251 return OnGetItemImage(item
);
5257 wxGenericListCtrl::OnGetItemAttr(long WXUNUSED_UNLESS_DEBUG(item
)) const
5259 wxASSERT_MSG( item
>= 0 && item
< GetItemCount(),
5260 wxT("invalid item index in OnGetItemAttr()") );
5262 // no attributes by default
5266 void wxGenericListCtrl::SetItemCount(long count
)
5268 wxASSERT_MSG( IsVirtual(), wxT("this is for virtual controls only") );
5270 m_mainWin
->SetItemCount(count
);
5273 void wxGenericListCtrl::RefreshItem(long item
)
5275 m_mainWin
->RefreshLine(item
);
5278 void wxGenericListCtrl::RefreshItems(long itemFrom
, long itemTo
)
5280 m_mainWin
->RefreshLines(itemFrom
, itemTo
);
5283 // Generic wxListCtrl is more or less a container for two other
5284 // windows which drawings are done upon. These are namely
5285 // 'm_headerWin' and 'm_mainWin'.
5286 // Here we override 'virtual wxWindow::Refresh()' to mimic the
5287 // behaviour wxListCtrl has under wxMSW.
5289 void wxGenericListCtrl::Refresh(bool eraseBackground
, const wxRect
*rect
)
5293 // The easy case, no rectangle specified.
5295 m_headerWin
->Refresh(eraseBackground
);
5298 m_mainWin
->Refresh(eraseBackground
);
5302 // Refresh the header window
5305 wxRect rectHeader
= m_headerWin
->GetRect();
5306 rectHeader
.Intersect(*rect
);
5307 if (rectHeader
.GetWidth() && rectHeader
.GetHeight())
5310 m_headerWin
->GetPosition(&x
, &y
);
5311 rectHeader
.Offset(-x
, -y
);
5312 m_headerWin
->Refresh(eraseBackground
, &rectHeader
);
5316 // Refresh the main window
5319 wxRect rectMain
= m_mainWin
->GetRect();
5320 rectMain
.Intersect(*rect
);
5321 if (rectMain
.GetWidth() && rectMain
.GetHeight())
5324 m_mainWin
->GetPosition(&x
, &y
);
5325 rectMain
.Offset(-x
, -y
);
5326 m_mainWin
->Refresh(eraseBackground
, &rectMain
);
5332 void wxGenericListCtrl::Update()
5336 if ( m_mainWin
->m_dirty
)
5337 m_mainWin
->RecalculatePositions();
5339 m_mainWin
->Update();
5343 m_headerWin
->Update();
5346 #endif // wxUSE_LISTCTRL