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 bool wxListHeaderWindow::Create( wxWindow
*win
,
957 wxListMainWindow
*owner
,
961 const wxString
&name
)
963 if ( !wxWindow::Create(win
, id
, pos
, size
, style
, name
) )
969 m_resizeCursor
= new wxCursor( wxCURSOR_SIZEWE
);
972 wxVisualAttributes attr
= wxPanel::GetClassDefaultAttributes();
973 SetOwnForegroundColour( attr
.colFg
);
974 SetOwnBackgroundColour( attr
.colBg
);
976 SetOwnFont( attr
.font
);
978 SetOwnForegroundColour( wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT
));
979 SetOwnBackgroundColour( wxSystemSettings::GetColour(wxSYS_COLOUR_BTNFACE
));
981 SetOwnFont( wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT
));
987 wxListHeaderWindow::~wxListHeaderWindow()
989 delete m_resizeCursor
;
992 #ifdef __WXUNIVERSAL__
993 #include "wx/univ/renderer.h"
994 #include "wx/univ/theme.h"
997 // shift the DC origin to match the position of the main window horz
998 // scrollbar: this allows us to always use logical coords
999 void wxListHeaderWindow::AdjustDC(wxDC
& dc
)
1001 wxGenericListCtrl
*parent
= m_owner
->GetListCtrl();
1004 parent
->GetScrollPixelsPerUnit( &xpix
, NULL
);
1007 parent
->GetViewStart( &view_start
, NULL
);
1012 dc
.GetDeviceOrigin( &org_x
, &org_y
);
1014 // account for the horz scrollbar offset
1016 if (GetLayoutDirection() == wxLayout_RightToLeft
)
1018 // Maybe we just have to check for m_signX
1019 // in the DC, but I leave the #ifdef __WXGTK__
1021 dc
.SetDeviceOrigin( org_x
+ (view_start
* xpix
), org_y
);
1025 dc
.SetDeviceOrigin( org_x
- (view_start
* xpix
), org_y
);
1028 void wxListHeaderWindow::OnPaint( wxPaintEvent
&WXUNUSED(event
) )
1030 wxGenericListCtrl
*parent
= m_owner
->GetListCtrl();
1032 wxPaintDC
dc( this );
1036 dc
.SetFont( GetFont() );
1038 // width and height of the entire header window
1040 GetClientSize( &w
, &h
);
1041 parent
->CalcUnscrolledPosition(w
, 0, &w
, NULL
);
1043 dc
.SetBackgroundMode(wxBRUSHSTYLE_TRANSPARENT
);
1044 dc
.SetTextForeground(GetForegroundColour());
1046 int x
= HEADER_OFFSET_X
;
1047 int numColumns
= m_owner
->GetColumnCount();
1049 for ( int i
= 0; i
< numColumns
&& x
< w
; i
++ )
1051 m_owner
->GetColumn( i
, item
);
1052 int wCol
= item
.m_width
;
1058 if (!m_parent
->IsEnabled())
1059 flags
|= wxCONTROL_DISABLED
;
1061 // NB: The code below is not really Mac-specific, but since we are close
1062 // to 2.8 release and I don't have time to test on other platforms, I
1063 // defined this only for wxMac. If this behaviour is desired on
1064 // other platforms, please go ahead and revise or remove the #ifdef.
1066 if ( !m_owner
->IsVirtual() && (item
.m_mask
& wxLIST_MASK_STATE
) &&
1067 (item
.m_state
& wxLIST_STATE_SELECTED
) )
1068 flags
|= wxCONTROL_SELECTED
;
1072 flags
|= wxCONTROL_SPECIAL
; // mark as first column
1074 wxRendererNative::Get().DrawHeaderButton
1078 wxRect(x
, HEADER_OFFSET_Y
, cw
, ch
),
1082 // see if we have enough space for the column label
1084 // for this we need the width of the text
1087 dc
.GetTextExtent(item
.GetText(), &wLabel
, &hLabel
);
1088 wLabel
+= 2 * EXTRA_WIDTH
;
1090 // and the width of the icon, if any
1091 int ix
= 0, iy
= 0; // init them just to suppress the compiler warnings
1092 const int image
= item
.m_image
;
1093 wxImageList
*imageList
;
1096 imageList
= m_owner
->GetSmallImageList();
1099 imageList
->GetSize(image
, ix
, iy
);
1100 wLabel
+= ix
+ HEADER_IMAGE_MARGIN_IN_REPORT_MODE
;
1108 // ignore alignment if there is not enough space anyhow
1110 switch ( wLabel
< cw
? item
.GetAlign() : wxLIST_FORMAT_LEFT
)
1113 wxFAIL_MSG( wxT("unknown list item format") );
1116 case wxLIST_FORMAT_LEFT
:
1120 case wxLIST_FORMAT_RIGHT
:
1121 xAligned
= x
+ cw
- wLabel
;
1124 case wxLIST_FORMAT_CENTER
:
1125 xAligned
= x
+ (cw
- wLabel
) / 2;
1129 // draw the text and image clipping them so that they
1130 // don't overwrite the column boundary
1131 wxDCClipper
clipper(dc
, x
, HEADER_OFFSET_Y
, cw
, h
);
1133 // if we have an image, draw it on the right of the label
1140 xAligned
+ wLabel
- ix
- HEADER_IMAGE_MARGIN_IN_REPORT_MODE
,
1141 HEADER_OFFSET_Y
+ (h
- iy
)/2,
1142 wxIMAGELIST_DRAW_TRANSPARENT
1146 dc
.DrawText( item
.GetText(),
1147 xAligned
+ EXTRA_WIDTH
, (h
- hLabel
) / 2 );
1152 // Fill in what's missing to the right of the columns, otherwise we will
1153 // leave an unpainted area when columns are removed (and it looks better)
1156 wxRendererNative::Get().DrawHeaderButton
1160 wxRect(x
, HEADER_OFFSET_Y
, w
- x
, h
),
1161 wxCONTROL_DIRTY
// mark as last column
1166 void wxListHeaderWindow::OnInternalIdle()
1168 wxWindow::OnInternalIdle();
1170 if (m_sendSetColumnWidth
)
1172 m_owner
->SetColumnWidth( m_colToSend
, m_widthToSend
);
1173 m_sendSetColumnWidth
= false;
1177 void wxListHeaderWindow::DrawCurrent()
1180 // m_owner->SetColumnWidth( m_column, m_currentX - m_minX );
1181 m_sendSetColumnWidth
= true;
1182 m_colToSend
= m_column
;
1183 m_widthToSend
= m_currentX
- m_minX
;
1185 int x1
= m_currentX
;
1187 m_owner
->ClientToScreen( &x1
, &y1
);
1189 int x2
= m_currentX
;
1191 m_owner
->GetClientSize( NULL
, &y2
);
1192 m_owner
->ClientToScreen( &x2
, &y2
);
1195 dc
.SetLogicalFunction( wxINVERT
);
1196 dc
.SetPen( wxPen(*wxBLACK
, 2) );
1197 dc
.SetBrush( *wxTRANSPARENT_BRUSH
);
1201 dc
.DrawLine( x1
, y1
, x2
, y2
);
1203 dc
.SetLogicalFunction( wxCOPY
);
1205 dc
.SetPen( wxNullPen
);
1206 dc
.SetBrush( wxNullBrush
);
1210 void wxListHeaderWindow::OnMouse( wxMouseEvent
&event
)
1212 wxGenericListCtrl
*parent
= m_owner
->GetListCtrl();
1214 // we want to work with logical coords
1216 parent
->CalcUnscrolledPosition(event
.GetX(), 0, &x
, NULL
);
1217 int y
= event
.GetY();
1221 SendListEvent(wxEVT_LIST_COL_DRAGGING
, event
.GetPosition());
1223 // we don't draw the line beyond our window, but we allow dragging it
1226 GetClientSize( &w
, NULL
);
1227 parent
->CalcUnscrolledPosition(w
, 0, &w
, NULL
);
1230 // erase the line if it was drawn
1231 if ( m_currentX
< w
)
1234 if (event
.ButtonUp())
1237 m_isDragging
= false;
1239 m_owner
->SetColumnWidth( m_column
, m_currentX
- m_minX
);
1240 SendListEvent(wxEVT_LIST_COL_END_DRAG
, event
.GetPosition());
1247 m_currentX
= m_minX
+ 7;
1249 // draw in the new location
1250 if ( m_currentX
< w
)
1254 else // not dragging
1257 bool hit_border
= false;
1259 // end of the current column
1262 // find the column where this event occurred
1264 countCol
= m_owner
->GetColumnCount();
1265 for (col
= 0; col
< countCol
; col
++)
1267 xpos
+= m_owner
->GetColumnWidth( col
);
1270 if ( (abs(x
-xpos
) < 3) && (y
< 22) )
1272 // near the column border
1279 // inside the column
1286 if ( col
== countCol
)
1289 if (event
.LeftDown() || event
.RightUp())
1291 if (hit_border
&& event
.LeftDown())
1293 if ( SendListEvent(wxEVT_LIST_COL_BEGIN_DRAG
,
1294 event
.GetPosition()) )
1296 m_isDragging
= true;
1301 //else: column resizing was vetoed by the user code
1303 else // click on a column
1305 // record the selected state of the columns
1306 if (event
.LeftDown())
1308 for (int i
=0; i
< m_owner
->GetColumnCount(); i
++)
1311 m_owner
->GetColumn(i
, colItem
);
1312 long state
= colItem
.GetState();
1314 colItem
.SetState(state
| wxLIST_STATE_SELECTED
);
1316 colItem
.SetState(state
& ~wxLIST_STATE_SELECTED
);
1317 m_owner
->SetColumn(i
, colItem
);
1321 SendListEvent( event
.LeftDown()
1322 ? wxEVT_LIST_COL_CLICK
1323 : wxEVT_LIST_COL_RIGHT_CLICK
,
1324 event
.GetPosition());
1327 else if (event
.Moving())
1332 setCursor
= m_currentCursor
== wxSTANDARD_CURSOR
;
1333 m_currentCursor
= m_resizeCursor
;
1337 setCursor
= m_currentCursor
!= wxSTANDARD_CURSOR
;
1338 m_currentCursor
= wxSTANDARD_CURSOR
;
1342 SetCursor(*m_currentCursor
);
1347 bool wxListHeaderWindow::SendListEvent(wxEventType type
, const wxPoint
& pos
)
1349 wxWindow
*parent
= GetParent();
1350 wxListEvent
le( type
, parent
->GetId() );
1351 le
.SetEventObject( parent
);
1352 le
.m_pointDrag
= pos
;
1354 // the position should be relative to the parent window, not
1355 // this one for compatibility with MSW and common sense: the
1356 // user code doesn't know anything at all about this header
1357 // window, so why should it get positions relative to it?
1358 le
.m_pointDrag
.y
-= GetSize().y
;
1360 le
.m_col
= m_column
;
1361 return !parent
->GetEventHandler()->ProcessEvent( le
) || le
.IsAllowed();
1364 //-----------------------------------------------------------------------------
1365 // wxListRenameTimer (internal)
1366 //-----------------------------------------------------------------------------
1368 wxListRenameTimer::wxListRenameTimer( wxListMainWindow
*owner
)
1373 void wxListRenameTimer::Notify()
1375 m_owner
->OnRenameTimer();
1378 //-----------------------------------------------------------------------------
1379 // wxListFindTimer (internal)
1380 //-----------------------------------------------------------------------------
1382 void wxListFindTimer::Notify()
1384 m_owner
->OnFindTimer();
1387 //-----------------------------------------------------------------------------
1388 // wxListTextCtrlWrapper (internal)
1389 //-----------------------------------------------------------------------------
1391 BEGIN_EVENT_TABLE(wxListTextCtrlWrapper
, wxEvtHandler
)
1392 EVT_CHAR (wxListTextCtrlWrapper::OnChar
)
1393 EVT_KEY_UP (wxListTextCtrlWrapper::OnKeyUp
)
1394 EVT_KILL_FOCUS (wxListTextCtrlWrapper::OnKillFocus
)
1397 wxListTextCtrlWrapper::wxListTextCtrlWrapper(wxListMainWindow
*owner
,
1400 : m_startValue(owner
->GetItemText(itemEdit
)),
1401 m_itemEdited(itemEdit
)
1405 m_aboutToFinish
= false;
1407 wxGenericListCtrl
*parent
= m_owner
->GetListCtrl();
1409 wxRect rectLabel
= owner
->GetLineLabelRect(itemEdit
);
1411 parent
->CalcScrolledPosition(rectLabel
.x
, rectLabel
.y
,
1412 &rectLabel
.x
, &rectLabel
.y
);
1414 m_text
->Create(owner
, wxID_ANY
, m_startValue
,
1415 wxPoint(rectLabel
.x
-4,rectLabel
.y
-4),
1416 wxSize(rectLabel
.width
+11,rectLabel
.height
+8));
1419 m_text
->PushEventHandler(this);
1422 void wxListTextCtrlWrapper::EndEdit(EndReason reason
)
1424 m_aboutToFinish
= true;
1429 // Notify the owner about the changes
1432 // Even if vetoed, close the control (consistent with MSW)
1437 m_owner
->OnRenameCancelled(m_itemEdited
);
1443 // Don't generate any notifications for the control being destroyed
1444 // and don't set focus to it neither.
1450 void wxListTextCtrlWrapper::Finish( bool setfocus
)
1452 m_text
->RemoveEventHandler(this);
1453 m_owner
->ResetTextControl( m_text
);
1455 wxPendingDelete
.Append( this );
1458 m_owner
->SetFocus();
1461 bool wxListTextCtrlWrapper::AcceptChanges()
1463 const wxString value
= m_text
->GetValue();
1465 // notice that we should always call OnRenameAccept() to generate the "end
1466 // label editing" event, even if the user hasn't really changed anything
1467 if ( !m_owner
->OnRenameAccept(m_itemEdited
, value
) )
1469 // vetoed by the user
1473 // accepted, do rename the item (unless nothing changed)
1474 if ( value
!= m_startValue
)
1475 m_owner
->SetItemText(m_itemEdited
, value
);
1480 void wxListTextCtrlWrapper::OnChar( wxKeyEvent
&event
)
1482 if ( !CheckForEndEditKey(event
) )
1486 bool wxListTextCtrlWrapper::CheckForEndEditKey(const wxKeyEvent
& event
)
1488 switch ( event
.m_keyCode
)
1491 EndEdit( End_Accept
);
1495 EndEdit( End_Discard
);
1505 void wxListTextCtrlWrapper::OnKeyUp( wxKeyEvent
&event
)
1507 if (m_aboutToFinish
)
1509 // auto-grow the textctrl:
1510 wxSize parentSize
= m_owner
->GetSize();
1511 wxPoint myPos
= m_text
->GetPosition();
1512 wxSize mySize
= m_text
->GetSize();
1514 m_text
->GetTextExtent(m_text
->GetValue() + wxT("MM"), &sx
, &sy
);
1515 if (myPos
.x
+ sx
> parentSize
.x
)
1516 sx
= parentSize
.x
- myPos
.x
;
1519 m_text
->SetSize(sx
, wxDefaultCoord
);
1525 void wxListTextCtrlWrapper::OnKillFocus( wxFocusEvent
&event
)
1527 if ( !m_aboutToFinish
)
1529 if ( !AcceptChanges() )
1530 m_owner
->OnRenameCancelled( m_itemEdited
);
1535 // We must let the native text control handle focus
1539 //-----------------------------------------------------------------------------
1541 //-----------------------------------------------------------------------------
1543 BEGIN_EVENT_TABLE(wxListMainWindow
, wxWindow
)
1544 EVT_PAINT (wxListMainWindow::OnPaint
)
1545 EVT_MOUSE_EVENTS (wxListMainWindow::OnMouse
)
1546 EVT_CHAR_HOOK (wxListMainWindow::OnCharHook
)
1547 EVT_CHAR (wxListMainWindow::OnChar
)
1548 EVT_KEY_DOWN (wxListMainWindow::OnKeyDown
)
1549 EVT_KEY_UP (wxListMainWindow::OnKeyUp
)
1550 EVT_SET_FOCUS (wxListMainWindow::OnSetFocus
)
1551 EVT_KILL_FOCUS (wxListMainWindow::OnKillFocus
)
1552 EVT_SCROLLWIN (wxListMainWindow::OnScroll
)
1553 EVT_CHILD_FOCUS (wxListMainWindow::OnChildFocus
)
1556 void wxListMainWindow::Init()
1561 m_lineTo
= (size_t)-1;
1567 m_small_image_list
= NULL
;
1568 m_normal_image_list
= NULL
;
1570 m_small_spacing
= 30;
1571 m_normal_spacing
= 40;
1575 m_isCreated
= false;
1577 m_lastOnSame
= false;
1578 m_renameTimer
= new wxListRenameTimer( this );
1580 m_findBell
= 0; // default is to not ring bell at all
1581 m_textctrlWrapper
= NULL
;
1585 m_lineSelectSingleOnUp
=
1586 m_lineBeforeLastClicked
= (size_t)-1;
1589 wxListMainWindow::wxListMainWindow()
1594 m_highlightUnfocusedBrush
= NULL
;
1597 wxListMainWindow::wxListMainWindow( wxWindow
*parent
,
1600 const wxSize
& size
)
1601 : wxWindow( parent
, id
, pos
, size
,
1602 wxWANTS_CHARS
| wxBORDER_NONE
)
1606 m_highlightBrush
= new wxBrush
1608 wxSystemSettings::GetColour
1610 wxSYS_COLOUR_HIGHLIGHT
1615 m_highlightUnfocusedBrush
= new wxBrush
1617 wxSystemSettings::GetColour
1619 wxSYS_COLOUR_BTNSHADOW
1624 wxVisualAttributes attr
= wxGenericListCtrl::GetClassDefaultAttributes();
1625 SetOwnForegroundColour( attr
.colFg
);
1626 SetOwnBackgroundColour( attr
.colBg
);
1628 SetOwnFont( attr
.font
);
1631 wxListMainWindow::~wxListMainWindow()
1633 if ( m_textctrlWrapper
)
1634 m_textctrlWrapper
->EndEdit(wxListTextCtrlWrapper::End_Destroy
);
1637 WX_CLEAR_LIST(wxListHeaderDataList
, m_columns
);
1638 WX_CLEAR_ARRAY(m_aColWidths
);
1640 delete m_highlightBrush
;
1641 delete m_highlightUnfocusedBrush
;
1642 delete m_renameTimer
;
1646 void wxListMainWindow::SetReportView(bool inReportView
)
1648 const size_t count
= m_lines
.size();
1649 for ( size_t n
= 0; n
< count
; n
++ )
1651 m_lines
[n
].SetReportView(inReportView
);
1655 void wxListMainWindow::CacheLineData(size_t line
)
1657 wxGenericListCtrl
*listctrl
= GetListCtrl();
1659 wxListLineData
*ld
= GetDummyLine();
1661 size_t countCol
= GetColumnCount();
1662 for ( size_t col
= 0; col
< countCol
; col
++ )
1664 ld
->SetText(col
, listctrl
->OnGetItemText(line
, col
));
1665 ld
->SetImage(col
, listctrl
->OnGetItemColumnImage(line
, col
));
1668 ld
->SetAttr(listctrl
->OnGetItemAttr(line
));
1671 wxListLineData
*wxListMainWindow::GetDummyLine() const
1673 wxASSERT_MSG( !IsEmpty(), wxT("invalid line index") );
1674 wxASSERT_MSG( IsVirtual(), wxT("GetDummyLine() shouldn't be called") );
1676 wxListMainWindow
*self
= wxConstCast(this, wxListMainWindow
);
1678 // we need to recreate the dummy line if the number of columns in the
1679 // control changed as it would have the incorrect number of fields
1681 if ( !m_lines
.IsEmpty() &&
1682 m_lines
[0].m_items
.GetCount() != (size_t)GetColumnCount() )
1684 self
->m_lines
.Clear();
1687 if ( m_lines
.IsEmpty() )
1689 wxListLineData
*line
= new wxListLineData(self
);
1690 self
->m_lines
.Add(line
);
1692 // don't waste extra memory -- there never going to be anything
1693 // else/more in this array
1694 self
->m_lines
.Shrink();
1700 // ----------------------------------------------------------------------------
1701 // line geometry (report mode only)
1702 // ----------------------------------------------------------------------------
1704 wxCoord
wxListMainWindow::GetLineHeight() const
1706 // we cache the line height as calling GetTextExtent() is slow
1707 if ( !m_lineHeight
)
1709 wxListMainWindow
*self
= wxConstCast(this, wxListMainWindow
);
1711 wxClientDC
dc( self
);
1712 dc
.SetFont( GetFont() );
1715 dc
.GetTextExtent(wxT("H"), NULL
, &y
);
1717 if ( m_small_image_list
&& m_small_image_list
->GetImageCount() )
1720 m_small_image_list
->GetSize(0, iw
, ih
);
1725 self
->m_lineHeight
= y
+ LINE_SPACING
;
1728 return m_lineHeight
;
1731 wxCoord
wxListMainWindow::GetLineY(size_t line
) const
1733 wxASSERT_MSG( InReportView(), wxT("only works in report mode") );
1735 return LINE_SPACING
+ line
* GetLineHeight();
1738 wxRect
wxListMainWindow::GetLineRect(size_t line
) const
1740 if ( !InReportView() )
1741 return GetLine(line
)->m_gi
->m_rectAll
;
1744 rect
.x
= HEADER_OFFSET_X
;
1745 rect
.y
= GetLineY(line
);
1746 rect
.width
= GetHeaderWidth();
1747 rect
.height
= GetLineHeight();
1752 wxRect
wxListMainWindow::GetLineLabelRect(size_t line
) const
1754 if ( !InReportView() )
1755 return GetLine(line
)->m_gi
->m_rectLabel
;
1758 wxListLineData
*data
= GetLine(line
);
1759 wxListItemDataList::compatibility_iterator node
= data
->m_items
.GetFirst();
1762 wxListItemData
*item
= node
->GetData();
1763 if ( item
->HasImage() )
1766 GetImageSize( item
->GetImage(), ix
, iy
);
1767 image_x
= 3 + ix
+ IMAGE_MARGIN_IN_REPORT_MODE
;
1772 rect
.x
= image_x
+ HEADER_OFFSET_X
;
1773 rect
.y
= GetLineY(line
);
1774 rect
.width
= GetColumnWidth(0) - image_x
;
1775 rect
.height
= GetLineHeight();
1780 wxRect
wxListMainWindow::GetLineIconRect(size_t line
) const
1782 if ( !InReportView() )
1783 return GetLine(line
)->m_gi
->m_rectIcon
;
1785 wxListLineData
*ld
= GetLine(line
);
1786 wxASSERT_MSG( ld
->HasImage(), wxT("should have an image") );
1789 rect
.x
= HEADER_OFFSET_X
;
1790 rect
.y
= GetLineY(line
);
1791 GetImageSize(ld
->GetImage(), rect
.width
, rect
.height
);
1796 wxRect
wxListMainWindow::GetLineHighlightRect(size_t line
) const
1798 return InReportView() ? GetLineRect(line
)
1799 : GetLine(line
)->m_gi
->m_rectHighlight
;
1802 long wxListMainWindow::HitTestLine(size_t line
, int x
, int y
) const
1804 wxASSERT_MSG( line
< GetItemCount(), wxT("invalid line in HitTestLine") );
1806 wxListLineData
*ld
= GetLine(line
);
1808 if ( ld
->HasImage() && GetLineIconRect(line
).Contains(x
, y
) )
1809 return wxLIST_HITTEST_ONITEMICON
;
1811 // VS: Testing for "ld->HasText() || InReportView()" instead of
1812 // "ld->HasText()" is needed to make empty lines in report view
1814 if ( ld
->HasText() || InReportView() )
1816 wxRect rect
= InReportView() ? GetLineRect(line
)
1817 : GetLineLabelRect(line
);
1819 if ( rect
.Contains(x
, y
) )
1820 return wxLIST_HITTEST_ONITEMLABEL
;
1826 // ----------------------------------------------------------------------------
1827 // highlight (selection) handling
1828 // ----------------------------------------------------------------------------
1830 bool wxListMainWindow::IsHighlighted(size_t line
) const
1834 return m_selStore
.IsSelected(line
);
1838 wxListLineData
*ld
= GetLine(line
);
1839 wxCHECK_MSG( ld
, false, wxT("invalid index in IsHighlighted") );
1841 return ld
->IsHighlighted();
1845 void wxListMainWindow::HighlightLines( size_t lineFrom
,
1851 wxArrayInt linesChanged
;
1852 if ( !m_selStore
.SelectRange(lineFrom
, lineTo
, highlight
,
1855 // meny items changed state, refresh everything
1856 RefreshLines(lineFrom
, lineTo
);
1858 else // only a few items changed state, refresh only them
1860 size_t count
= linesChanged
.GetCount();
1861 for ( size_t n
= 0; n
< count
; n
++ )
1863 RefreshLine(linesChanged
[n
]);
1867 else // iterate over all items in non report view
1869 for ( size_t line
= lineFrom
; line
<= lineTo
; line
++ )
1871 if ( HighlightLine(line
, highlight
) )
1877 bool wxListMainWindow::HighlightLine( size_t line
, bool highlight
)
1883 changed
= m_selStore
.SelectItem(line
, highlight
);
1887 wxListLineData
*ld
= GetLine(line
);
1888 wxCHECK_MSG( ld
, false, wxT("invalid index in HighlightLine") );
1890 changed
= ld
->Highlight(highlight
);
1895 SendNotify( line
, highlight
? wxEVT_LIST_ITEM_SELECTED
1896 : wxEVT_LIST_ITEM_DESELECTED
);
1902 void wxListMainWindow::RefreshLine( size_t line
)
1904 if ( InReportView() )
1906 size_t visibleFrom
, visibleTo
;
1907 GetVisibleLinesRange(&visibleFrom
, &visibleTo
);
1909 if ( line
< visibleFrom
|| line
> visibleTo
)
1913 wxRect rect
= GetLineRect(line
);
1915 GetListCtrl()->CalcScrolledPosition( rect
.x
, rect
.y
, &rect
.x
, &rect
.y
);
1916 RefreshRect( rect
);
1919 void wxListMainWindow::RefreshLines( size_t lineFrom
, size_t lineTo
)
1921 // we suppose that they are ordered by caller
1922 wxASSERT_MSG( lineFrom
<= lineTo
, wxT("indices in disorder") );
1924 wxASSERT_MSG( lineTo
< GetItemCount(), wxT("invalid line range") );
1926 if ( InReportView() )
1928 size_t visibleFrom
, visibleTo
;
1929 GetVisibleLinesRange(&visibleFrom
, &visibleTo
);
1931 if ( lineFrom
< visibleFrom
)
1932 lineFrom
= visibleFrom
;
1933 if ( lineTo
> visibleTo
)
1938 rect
.y
= GetLineY(lineFrom
);
1939 rect
.width
= GetClientSize().x
;
1940 rect
.height
= GetLineY(lineTo
) - rect
.y
+ GetLineHeight();
1942 GetListCtrl()->CalcScrolledPosition( rect
.x
, rect
.y
, &rect
.x
, &rect
.y
);
1943 RefreshRect( rect
);
1947 // TODO: this should be optimized...
1948 for ( size_t line
= lineFrom
; line
<= lineTo
; line
++ )
1955 void wxListMainWindow::RefreshAfter( size_t lineFrom
)
1957 if ( InReportView() )
1959 size_t visibleFrom
, visibleTo
;
1960 GetVisibleLinesRange(&visibleFrom
, &visibleTo
);
1962 if ( lineFrom
< visibleFrom
)
1963 lineFrom
= visibleFrom
;
1964 else if ( lineFrom
> visibleTo
)
1969 rect
.y
= GetLineY(lineFrom
);
1970 GetListCtrl()->CalcScrolledPosition( rect
.x
, rect
.y
, &rect
.x
, &rect
.y
);
1972 wxSize size
= GetClientSize();
1973 rect
.width
= size
.x
;
1975 // refresh till the bottom of the window
1976 rect
.height
= size
.y
- rect
.y
;
1978 RefreshRect( rect
);
1982 // TODO: how to do it more efficiently?
1987 void wxListMainWindow::RefreshSelected()
1993 if ( InReportView() )
1995 GetVisibleLinesRange(&from
, &to
);
2000 to
= GetItemCount() - 1;
2003 if ( HasCurrent() && m_current
>= from
&& m_current
<= to
)
2004 RefreshLine(m_current
);
2006 for ( size_t line
= from
; line
<= to
; line
++ )
2008 // NB: the test works as expected even if m_current == -1
2009 if ( line
!= m_current
&& IsHighlighted(line
) )
2014 void wxListMainWindow::OnPaint( wxPaintEvent
&WXUNUSED(event
) )
2016 // Note: a wxPaintDC must be constructed even if no drawing is
2017 // done (a Windows requirement).
2018 wxPaintDC
dc( this );
2022 // nothing to draw or not the moment to draw it
2027 RecalculatePositions( false );
2029 GetListCtrl()->PrepareDC( dc
);
2032 GetListCtrl()->CalcScrolledPosition( 0, 0, &dev_x
, &dev_y
);
2034 dc
.SetFont( GetFont() );
2036 if ( InReportView() )
2038 int lineHeight
= GetLineHeight();
2040 size_t visibleFrom
, visibleTo
;
2041 GetVisibleLinesRange(&visibleFrom
, &visibleTo
);
2044 int xOrig
= dc
.LogicalToDeviceX( 0 );
2045 int yOrig
= dc
.LogicalToDeviceY( 0 );
2047 // tell the caller cache to cache the data
2050 wxListEvent
evCache(wxEVT_LIST_CACHE_HINT
,
2051 GetParent()->GetId());
2052 evCache
.SetEventObject( GetParent() );
2053 evCache
.m_oldItemIndex
= visibleFrom
;
2054 evCache
.m_item
.m_itemId
=
2055 evCache
.m_itemIndex
= visibleTo
;
2056 GetParent()->GetEventHandler()->ProcessEvent( evCache
);
2059 for ( size_t line
= visibleFrom
; line
<= visibleTo
; line
++ )
2061 rectLine
= GetLineRect(line
);
2064 if ( !IsExposed(rectLine
.x
+ xOrig
, rectLine
.y
+ yOrig
,
2065 rectLine
.width
, rectLine
.height
) )
2067 // don't redraw unaffected lines to avoid flicker
2071 GetLine(line
)->DrawInReportMode( &dc
,
2073 GetLineHighlightRect(line
),
2074 IsHighlighted(line
),
2075 line
== m_current
);
2078 if ( HasFlag(wxLC_HRULES
) )
2080 wxPen
pen(GetRuleColour(), 1, wxPENSTYLE_SOLID
);
2081 wxSize clientSize
= GetClientSize();
2083 size_t i
= visibleFrom
;
2084 if (i
== 0) i
= 1; // Don't draw the first one
2085 for ( ; i
<= visibleTo
; i
++ )
2088 dc
.SetBrush( *wxTRANSPARENT_BRUSH
);
2089 dc
.DrawLine(0 - dev_x
, i
* lineHeight
,
2090 clientSize
.x
- dev_x
, i
* lineHeight
);
2093 // Draw last horizontal rule
2094 if ( visibleTo
== GetItemCount() - 1 )
2097 dc
.SetBrush( *wxTRANSPARENT_BRUSH
);
2098 dc
.DrawLine(0 - dev_x
, (m_lineTo
+ 1) * lineHeight
,
2099 clientSize
.x
- dev_x
, (m_lineTo
+ 1) * lineHeight
);
2103 // Draw vertical rules if required
2104 if ( HasFlag(wxLC_VRULES
) && !IsEmpty() )
2106 wxPen
pen(GetRuleColour(), 1, wxPENSTYLE_SOLID
);
2107 wxRect firstItemRect
, lastItemRect
;
2109 GetItemRect(visibleFrom
, firstItemRect
);
2110 GetItemRect(visibleTo
, lastItemRect
);
2111 int x
= firstItemRect
.GetX();
2113 dc
.SetBrush(* wxTRANSPARENT_BRUSH
);
2115 for (int col
= 0; col
< GetColumnCount(); col
++)
2117 int colWidth
= GetColumnWidth(col
);
2119 int x_pos
= x
- dev_x
;
2120 if (col
< GetColumnCount()-1) x_pos
-= 2;
2121 dc
.DrawLine(x_pos
, firstItemRect
.GetY() - 1 - dev_y
,
2122 x_pos
, lastItemRect
.GetBottom() + 1 - dev_y
);
2128 size_t count
= GetItemCount();
2129 for ( size_t i
= 0; i
< count
; i
++ )
2131 GetLine(i
)->Draw( &dc
, i
== m_current
);
2135 // DrawFocusRect() is unusable under Mac, it draws outside of the highlight
2136 // rectangle somehow and so leaves traces when the item is not selected any
2137 // more, see #12229.
2142 if ( IsHighlighted(m_current
) )
2143 flags
|= wxCONTROL_SELECTED
;
2145 wxRendererNative::Get().
2146 DrawFocusRect(this, dc
, GetLineHighlightRect(m_current
), flags
);
2148 #endif // !__WXMAC__
2151 void wxListMainWindow::HighlightAll( bool on
)
2153 if ( IsSingleSel() )
2155 wxASSERT_MSG( !on
, wxT("can't do this in a single selection control") );
2157 // we just have one item to turn off
2158 if ( HasCurrent() && IsHighlighted(m_current
) )
2160 HighlightLine(m_current
, false);
2161 RefreshLine(m_current
);
2164 else // multi selection
2167 HighlightLines(0, GetItemCount() - 1, on
);
2171 void wxListMainWindow::OnChildFocus(wxChildFocusEvent
& WXUNUSED(event
))
2173 // Do nothing here. This prevents the default handler in wxScrolledWindow
2174 // from needlessly scrolling the window when the edit control is
2175 // dismissed. See ticket #9563.
2178 void wxListMainWindow::SendNotify( size_t line
,
2179 wxEventType command
,
2180 const wxPoint
& point
)
2182 wxListEvent
le( command
, GetParent()->GetId() );
2183 le
.SetEventObject( GetParent() );
2185 le
.m_item
.m_itemId
=
2186 le
.m_itemIndex
= line
;
2188 // set only for events which have position
2189 if ( point
!= wxDefaultPosition
)
2190 le
.m_pointDrag
= point
;
2192 // don't try to get the line info for virtual list controls: the main
2193 // program has it anyhow and if we did it would result in accessing all
2194 // the lines, even those which are not visible now and this is precisely
2195 // what we're trying to avoid
2198 if ( line
!= (size_t)-1 )
2200 GetLine(line
)->GetItem( 0, le
.m_item
);
2202 //else: this happens for wxEVT_LIST_ITEM_FOCUSED event
2204 //else: there may be no more such item
2206 GetParent()->GetEventHandler()->ProcessEvent( le
);
2209 void wxListMainWindow::ChangeCurrent(size_t current
)
2211 m_current
= current
;
2213 // as the current item changed, we shouldn't start editing it when the
2214 // "slow click" timer expires as the click happened on another item
2215 if ( m_renameTimer
->IsRunning() )
2216 m_renameTimer
->Stop();
2218 SendNotify(current
, wxEVT_LIST_ITEM_FOCUSED
);
2221 wxTextCtrl
*wxListMainWindow::EditLabel(long item
, wxClassInfo
* textControlClass
)
2223 wxCHECK_MSG( (item
>= 0) && ((size_t)item
< GetItemCount()), NULL
,
2224 wxT("wrong index in wxGenericListCtrl::EditLabel()") );
2226 wxASSERT_MSG( textControlClass
->IsKindOf(wxCLASSINFO(wxTextCtrl
)),
2227 wxT("EditLabel() needs a text control") );
2229 size_t itemEdit
= (size_t)item
;
2231 wxListEvent
le( wxEVT_LIST_BEGIN_LABEL_EDIT
, GetParent()->GetId() );
2232 le
.SetEventObject( GetParent() );
2233 le
.m_item
.m_itemId
=
2234 le
.m_itemIndex
= item
;
2235 wxListLineData
*data
= GetLine(itemEdit
);
2236 wxCHECK_MSG( data
, NULL
, wxT("invalid index in EditLabel()") );
2237 data
->GetItem( 0, le
.m_item
);
2239 if ( GetParent()->GetEventHandler()->ProcessEvent( le
) && !le
.IsAllowed() )
2241 // vetoed by user code
2247 // Ensure the display is updated before we start editing.
2251 wxTextCtrl
* const text
= (wxTextCtrl
*)textControlClass
->CreateObject();
2252 m_textctrlWrapper
= new wxListTextCtrlWrapper(this, text
, item
);
2253 return m_textctrlWrapper
->GetText();
2256 void wxListMainWindow::OnRenameTimer()
2258 wxCHECK_RET( HasCurrent(), wxT("unexpected rename timer") );
2260 EditLabel( m_current
);
2263 bool wxListMainWindow::OnRenameAccept(size_t itemEdit
, const wxString
& value
)
2265 wxListEvent
le( wxEVT_LIST_END_LABEL_EDIT
, GetParent()->GetId() );
2266 le
.SetEventObject( GetParent() );
2267 le
.m_item
.m_itemId
=
2268 le
.m_itemIndex
= itemEdit
;
2270 wxListLineData
*data
= GetLine(itemEdit
);
2272 wxCHECK_MSG( data
, false, wxT("invalid index in OnRenameAccept()") );
2274 data
->GetItem( 0, le
.m_item
);
2275 le
.m_item
.m_text
= value
;
2276 return !GetParent()->GetEventHandler()->ProcessEvent( le
) ||
2280 void wxListMainWindow::OnRenameCancelled(size_t itemEdit
)
2282 // let owner know that the edit was cancelled
2283 wxListEvent
le( wxEVT_LIST_END_LABEL_EDIT
, GetParent()->GetId() );
2285 le
.SetEditCanceled(true);
2287 le
.SetEventObject( GetParent() );
2288 le
.m_item
.m_itemId
=
2289 le
.m_itemIndex
= itemEdit
;
2291 wxListLineData
*data
= GetLine(itemEdit
);
2292 wxCHECK_RET( data
, wxT("invalid index in OnRenameCancelled()") );
2294 data
->GetItem( 0, le
.m_item
);
2295 GetEventHandler()->ProcessEvent( le
);
2298 void wxListMainWindow::OnFindTimer()
2300 m_findPrefix
.clear();
2305 void wxListMainWindow::EnableBellOnNoMatch( bool on
)
2310 void wxListMainWindow::OnMouse( wxMouseEvent
&event
)
2313 // On wxMac we can't depend on the EVT_KILL_FOCUS event to properly
2314 // shutdown the edit control when the mouse is clicked elsewhere on the
2315 // listctrl because the order of events is different (or something like
2316 // that), so explicitly end the edit if it is active.
2317 if ( event
.LeftDown() && m_textctrlWrapper
)
2318 m_textctrlWrapper
->EndEdit(wxListTextCtrlWrapper::End_Accept
);
2321 if ( event
.LeftDown() )
2323 // Ensure we skip the event to let the system set focus to this window.
2327 // Pretend that the event happened in wxListCtrl itself.
2328 wxMouseEvent
me(event
);
2329 me
.SetEventObject( GetParent() );
2330 me
.SetId(GetParent()->GetId());
2331 if ( GetParent()->GetEventHandler()->ProcessEvent( me
))
2334 if (event
.GetEventType() == wxEVT_MOUSEWHEEL
)
2336 // let the base class handle mouse wheel events.
2341 if ( !HasCurrent() || IsEmpty() )
2343 if (event
.RightDown())
2345 SendNotify( (size_t)-1, wxEVT_LIST_ITEM_RIGHT_CLICK
, event
.GetPosition() );
2347 wxContextMenuEvent
evtCtx(wxEVT_CONTEXT_MENU
,
2348 GetParent()->GetId(),
2349 ClientToScreen(event
.GetPosition()));
2350 evtCtx
.SetEventObject(GetParent());
2351 GetParent()->GetEventHandler()->ProcessEvent(evtCtx
);
2359 if ( !(event
.Dragging() || event
.ButtonDown() || event
.LeftUp() ||
2360 event
.ButtonDClick()) )
2363 int x
= event
.GetX();
2364 int y
= event
.GetY();
2365 GetListCtrl()->CalcUnscrolledPosition( x
, y
, &x
, &y
);
2367 // where did we hit it (if we did)?
2370 size_t count
= GetItemCount(),
2373 if ( InReportView() )
2375 current
= y
/ GetLineHeight();
2376 if ( current
< count
)
2377 hitResult
= HitTestLine(current
, x
, y
);
2381 // TODO: optimize it too! this is less simple than for report view but
2382 // enumerating all items is still not a way to do it!!
2383 for ( current
= 0; current
< count
; current
++ )
2385 hitResult
= HitTestLine(current
, x
, y
);
2391 // Update drag events counter first as we must do it even if the mouse is
2392 // not on any item right now as we must keep count in case we started
2393 // dragging from the empty control area but continued to do it over a valid
2394 // item -- in this situation we must not start dragging this item.
2395 if (event
.Dragging())
2400 // The only mouse event that can be generated without any valid item is
2401 // wxEVT_LIST_ITEM_RIGHT_CLICK as it can be useful to have a global
2402 // popup menu for the list control itself which should be shown even when
2403 // the user clicks outside of any item.
2406 // outside of any item
2407 if (event
.RightDown())
2409 SendNotify( (size_t) -1, wxEVT_LIST_ITEM_RIGHT_CLICK
, event
.GetPosition() );
2411 wxContextMenuEvent
evtCtx(
2413 GetParent()->GetId(),
2414 ClientToScreen(event
.GetPosition()));
2415 evtCtx
.SetEventObject(GetParent());
2416 GetParent()->GetEventHandler()->ProcessEvent(evtCtx
);
2420 // reset the selection and bail out
2421 HighlightAll(false);
2427 if ( event
.Dragging() )
2429 if (m_dragCount
== 1)
2431 // we have to report the raw, physical coords as we want to be
2432 // able to call HitTest(event.m_pointDrag) from the user code to
2433 // get the item being dragged
2434 m_dragStart
= event
.GetPosition();
2437 if (m_dragCount
!= 3)
2440 int command
= event
.RightIsDown() ? wxEVT_LIST_BEGIN_RDRAG
2441 : wxEVT_LIST_BEGIN_DRAG
;
2443 SendNotify( m_lineLastClicked
, command
, m_dragStart
);
2448 bool forceClick
= false;
2449 if (event
.ButtonDClick())
2451 if ( m_renameTimer
->IsRunning() )
2452 m_renameTimer
->Stop();
2454 m_lastOnSame
= false;
2456 if ( current
== m_lineLastClicked
)
2458 SendNotify( current
, wxEVT_LIST_ITEM_ACTIVATED
);
2464 // The first click was on another item, so don't interpret this as
2465 // a double click, but as a simple click instead
2472 if (m_lineSelectSingleOnUp
!= (size_t)-1)
2474 // select single line
2475 HighlightAll( false );
2476 ReverseHighlight(m_lineSelectSingleOnUp
);
2481 if ((current
== m_current
) &&
2482 (hitResult
== wxLIST_HITTEST_ONITEMLABEL
) &&
2483 HasFlag(wxLC_EDIT_LABELS
) )
2485 if ( !InReportView() ||
2486 GetLineLabelRect(current
).Contains(x
, y
) )
2488 int dclick
= wxSystemSettings::GetMetric(wxSYS_DCLICK_MSEC
);
2489 m_renameTimer
->Start(dclick
> 0 ? dclick
: 250, true);
2493 m_lastOnSame
= false;
2496 m_lineSelectSingleOnUp
= (size_t)-1;
2500 // This is necessary, because after a DnD operation in
2501 // from and to ourself, the up event is swallowed by the
2502 // DnD code. So on next non-up event (which means here and
2503 // now) m_lineSelectSingleOnUp should be reset.
2504 m_lineSelectSingleOnUp
= (size_t)-1;
2506 if (event
.RightDown())
2508 m_lineBeforeLastClicked
= m_lineLastClicked
;
2509 m_lineLastClicked
= current
;
2511 // If the item is already selected, do not update the selection.
2512 // Multi-selections should not be cleared if a selected item is clicked.
2513 if (!IsHighlighted(current
))
2515 HighlightAll(false);
2516 ChangeCurrent(current
);
2517 ReverseHighlight(m_current
);
2520 SendNotify( current
, wxEVT_LIST_ITEM_RIGHT_CLICK
, event
.GetPosition() );
2522 // Allow generation of context menu event
2525 else if (event
.MiddleDown())
2527 SendNotify( current
, wxEVT_LIST_ITEM_MIDDLE_CLICK
);
2529 else if ( event
.LeftDown() || forceClick
)
2531 m_lineBeforeLastClicked
= m_lineLastClicked
;
2532 m_lineLastClicked
= current
;
2534 size_t oldCurrent
= m_current
;
2535 bool oldWasSelected
= IsHighlighted(m_current
);
2537 bool cmdModifierDown
= event
.CmdDown();
2538 if ( IsSingleSel() || !(cmdModifierDown
|| event
.ShiftDown()) )
2540 if ( IsSingleSel() || !IsHighlighted(current
) )
2542 HighlightAll( false );
2544 ChangeCurrent(current
);
2546 ReverseHighlight(m_current
);
2548 else // multi sel & current is highlighted & no mod keys
2550 m_lineSelectSingleOnUp
= current
;
2551 ChangeCurrent(current
); // change focus
2554 else // multi sel & either ctrl or shift is down
2556 if (cmdModifierDown
)
2558 ChangeCurrent(current
);
2560 ReverseHighlight(m_current
);
2562 else if (event
.ShiftDown())
2564 ChangeCurrent(current
);
2566 size_t lineFrom
= oldCurrent
,
2569 if ( lineTo
< lineFrom
)
2572 lineFrom
= m_current
;
2575 HighlightLines(lineFrom
, lineTo
);
2577 else // !ctrl, !shift
2579 // test in the enclosing if should make it impossible
2580 wxFAIL_MSG( wxT("how did we get here?") );
2584 if (m_current
!= oldCurrent
)
2585 RefreshLine( oldCurrent
);
2587 // Set the flag telling us whether the next click on this item should
2588 // start editing its label. This should happen if we clicked on the
2589 // current item and it was already selected, i.e. if this click was not
2590 // done to select it.
2592 // It should not happen if this was a double click (forceClick is true)
2593 // nor if we hadn't had the focus before as then this click was used to
2594 // give focus to the control.
2595 m_lastOnSame
= (m_current
== oldCurrent
) && oldWasSelected
&&
2596 !forceClick
&& HasFocus();
2600 void wxListMainWindow::MoveToItem(size_t item
)
2602 if ( item
== (size_t)-1 )
2605 wxRect rect
= GetLineRect(item
);
2607 int client_w
, client_h
;
2608 GetClientSize( &client_w
, &client_h
);
2610 const int hLine
= GetLineHeight();
2612 int view_x
= SCROLL_UNIT_X
* GetListCtrl()->GetScrollPos( wxHORIZONTAL
);
2613 int view_y
= hLine
* GetListCtrl()->GetScrollPos( wxVERTICAL
);
2615 if ( InReportView() )
2617 // the next we need the range of lines shown it might be different,
2618 // so recalculate it
2619 ResetVisibleLinesRange();
2621 if (rect
.y
< view_y
)
2622 GetListCtrl()->Scroll( -1, rect
.y
/ hLine
);
2623 if (rect
.y
+ rect
.height
+ 5 > view_y
+ client_h
)
2624 GetListCtrl()->Scroll( -1, (rect
.y
+ rect
.height
- client_h
+ hLine
) / hLine
);
2627 // At least on Mac the visible lines value will get reset inside of
2628 // Scroll *before* it actually scrolls the window because of the
2629 // Update() that happens there, so it will still have the wrong value.
2630 // So let's reset it again and wait for it to be recalculated in the
2631 // next paint event. I would expect this problem to show up in wxGTK
2632 // too but couldn't duplicate it there. Perhaps the order of events
2633 // is different... --Robin
2634 ResetVisibleLinesRange();
2642 if (rect
.x
-view_x
< 5)
2643 sx
= (rect
.x
- 5) / SCROLL_UNIT_X
;
2644 if (rect
.x
+ rect
.width
- 5 > view_x
+ client_w
)
2645 sx
= (rect
.x
+ rect
.width
- client_w
+ SCROLL_UNIT_X
) / SCROLL_UNIT_X
;
2647 if (rect
.y
-view_y
< 5)
2648 sy
= (rect
.y
- 5) / hLine
;
2649 if (rect
.y
+ rect
.height
- 5 > view_y
+ client_h
)
2650 sy
= (rect
.y
+ rect
.height
- client_h
+ hLine
) / hLine
;
2652 GetListCtrl()->Scroll(sx
, sy
);
2656 bool wxListMainWindow::ScrollList(int WXUNUSED(dx
), int dy
)
2658 if ( !InReportView() )
2660 // TODO: this should work in all views but is not implemented now
2665 GetVisibleLinesRange(&top
, &bottom
);
2667 if ( bottom
== (size_t)-1 )
2670 ResetVisibleLinesRange();
2672 int hLine
= GetLineHeight();
2674 GetListCtrl()->Scroll(-1, top
+ dy
/ hLine
);
2677 // see comment in MoveToItem() for why we do this
2678 ResetVisibleLinesRange();
2684 // ----------------------------------------------------------------------------
2685 // keyboard handling
2686 // ----------------------------------------------------------------------------
2688 void wxListMainWindow::OnArrowChar(size_t newCurrent
, const wxKeyEvent
& event
)
2690 wxCHECK_RET( newCurrent
< (size_t)GetItemCount(),
2691 wxT("invalid item index in OnArrowChar()") );
2693 size_t oldCurrent
= m_current
;
2695 // in single selection we just ignore Shift as we can't select several
2697 if ( event
.ShiftDown() && !IsSingleSel() )
2699 ChangeCurrent(newCurrent
);
2701 // refresh the old focus to remove it
2702 RefreshLine( oldCurrent
);
2704 // select all the items between the old and the new one
2705 if ( oldCurrent
> newCurrent
)
2707 newCurrent
= oldCurrent
;
2708 oldCurrent
= m_current
;
2711 HighlightLines(oldCurrent
, newCurrent
);
2715 // all previously selected items are unselected unless ctrl is held
2716 // in a multiselection control
2717 if ( !event
.ControlDown() || IsSingleSel() )
2718 HighlightAll(false);
2720 ChangeCurrent(newCurrent
);
2722 // refresh the old focus to remove it
2723 RefreshLine( oldCurrent
);
2725 // in single selection mode we must always have a selected item
2726 if ( !event
.ControlDown() || IsSingleSel() )
2727 HighlightLine( m_current
, true );
2730 RefreshLine( m_current
);
2735 void wxListMainWindow::OnKeyDown( wxKeyEvent
&event
)
2737 wxWindow
*parent
= GetParent();
2739 // propagate the key event upwards
2740 wxKeyEvent
ke(event
);
2741 ke
.SetEventObject( parent
);
2742 ke
.SetId(GetParent()->GetId());
2743 if (parent
->GetEventHandler()->ProcessEvent( ke
))
2746 // send a list event
2747 wxListEvent
le( wxEVT_LIST_KEY_DOWN
, parent
->GetId() );
2748 le
.m_item
.m_itemId
=
2749 le
.m_itemIndex
= m_current
;
2751 GetLine(m_current
)->GetItem( 0, le
.m_item
);
2752 le
.m_code
= event
.GetKeyCode();
2753 le
.SetEventObject( parent
);
2754 if (parent
->GetEventHandler()->ProcessEvent( le
))
2760 void wxListMainWindow::OnKeyUp( wxKeyEvent
&event
)
2762 wxWindow
*parent
= GetParent();
2764 // propagate the key event upwards
2765 wxKeyEvent
ke(event
);
2766 ke
.SetEventObject( parent
);
2767 ke
.SetId(GetParent()->GetId());
2768 if (parent
->GetEventHandler()->ProcessEvent( ke
))
2774 void wxListMainWindow::OnCharHook( wxKeyEvent
&event
)
2776 if ( m_textctrlWrapper
)
2778 // When an in-place editor is active we should ensure that it always
2779 // gets the key events that are special to it.
2780 if ( m_textctrlWrapper
->CheckForEndEditKey(event
) )
2782 // Skip the call to wxEvent::Skip() below.
2790 void wxListMainWindow::OnChar( wxKeyEvent
&event
)
2792 wxWindow
*parent
= GetParent();
2794 // propagate the char event upwards
2795 wxKeyEvent
ke(event
);
2796 ke
.SetEventObject( parent
);
2797 ke
.SetId(GetParent()->GetId());
2798 if (parent
->GetEventHandler()->ProcessEvent( ke
))
2801 if ( HandleAsNavigationKey(event
) )
2804 // no item -> nothing to do
2811 // don't use m_linesPerPage directly as it might not be computed yet
2812 const int pageSize
= GetCountPerPage();
2813 wxCHECK_RET( pageSize
, wxT("should have non zero page size") );
2815 if (GetLayoutDirection() == wxLayout_RightToLeft
)
2817 if (event
.GetKeyCode() == WXK_RIGHT
)
2818 event
.m_keyCode
= WXK_LEFT
;
2819 else if (event
.GetKeyCode() == WXK_LEFT
)
2820 event
.m_keyCode
= WXK_RIGHT
;
2823 int keyCode
= event
.GetKeyCode();
2827 if ( m_current
> 0 )
2828 OnArrowChar( m_current
- 1, event
);
2832 if ( m_current
< (size_t)GetItemCount() - 1 )
2833 OnArrowChar( m_current
+ 1, event
);
2838 OnArrowChar( GetItemCount() - 1, event
);
2843 OnArrowChar( 0, event
);
2848 int steps
= InReportView() ? pageSize
- 1
2849 : m_current
% pageSize
;
2851 int index
= m_current
- steps
;
2855 OnArrowChar( index
, event
);
2861 int steps
= InReportView()
2863 : pageSize
- (m_current
% pageSize
) - 1;
2865 size_t index
= m_current
+ steps
;
2866 size_t count
= GetItemCount();
2867 if ( index
>= count
)
2870 OnArrowChar( index
, event
);
2875 if ( !InReportView() )
2877 int index
= m_current
- pageSize
;
2881 OnArrowChar( index
, event
);
2886 if ( !InReportView() )
2888 size_t index
= m_current
+ pageSize
;
2890 size_t count
= GetItemCount();
2891 if ( index
>= count
)
2894 OnArrowChar( index
, event
);
2899 if ( IsSingleSel() )
2901 if ( event
.ControlDown() )
2903 ReverseHighlight(m_current
);
2905 else // normal space press
2907 SendNotify( m_current
, wxEVT_LIST_ITEM_ACTIVATED
);
2910 else // multiple selection
2912 ReverseHighlight(m_current
);
2918 SendNotify( m_current
, wxEVT_LIST_ITEM_ACTIVATED
);
2922 if ( !event
.HasModifiers() &&
2923 ((keyCode
>= '0' && keyCode
<= '9') ||
2924 (keyCode
>= 'a' && keyCode
<= 'z') ||
2925 (keyCode
>= 'A' && keyCode
<= 'Z') ||
2931 // find the next item starting with the given prefix
2932 wxChar ch
= (wxChar
)keyCode
;
2935 // if the same character is typed multiple times then go to the
2936 // next entry starting with that character instead of searching
2937 // for an item starting with multiple copies of this character,
2938 // this is more useful and is how it works under Windows.
2939 if ( m_findPrefix
.length() == 1 && m_findPrefix
[0] == ch
)
2941 item
= PrefixFindItem(m_current
, ch
);
2945 const wxString
newPrefix(m_findPrefix
+ ch
);
2946 item
= PrefixFindItem(m_current
, newPrefix
);
2947 if ( item
!= (size_t)-1 )
2948 m_findPrefix
= newPrefix
;
2951 // also start the timer to reset the current prefix if the user
2952 // doesn't press any more alnum keys soon -- we wouldn't want
2953 // to use this prefix for a new item search
2956 m_findTimer
= new wxListFindTimer( this );
2959 // Notice that we should start the timer even if we didn't find
2960 // anything to make sure we reset the search state later.
2961 m_findTimer
->Start(wxListFindTimer::DELAY
, wxTIMER_ONE_SHOT
);
2963 // restart timer even when there's no match so bell get's reset
2964 if ( item
!= (size_t)-1 )
2966 // Select the found item and go to it.
2967 HighlightAll(false);
2969 wxLIST_STATE_FOCUSED
| wxLIST_STATE_SELECTED
,
2970 wxLIST_STATE_FOCUSED
| wxLIST_STATE_SELECTED
);
2972 // Reset the bell flag if it had been temporarily disabled
2977 else // No such item
2979 // Signal it with a bell if enabled.
2980 if ( m_findBell
== 1 )
2984 // Disable it for the next unsuccessful match, we only
2985 // beep once, this is usually enough and continuing to
2986 // do it would be annoying.
2998 // ----------------------------------------------------------------------------
3000 // ----------------------------------------------------------------------------
3002 void wxListMainWindow::OnSetFocus( wxFocusEvent
&WXUNUSED(event
) )
3006 wxFocusEvent
event( wxEVT_SET_FOCUS
, GetParent()->GetId() );
3007 event
.SetEventObject( GetParent() );
3008 if ( GetParent()->GetEventHandler()->ProcessEvent( event
) )
3012 // wxGTK sends us EVT_SET_FOCUS events even if we had never got
3013 // EVT_KILL_FOCUS before which means that we finish by redrawing the items
3014 // which are already drawn correctly resulting in horrible flicker - avoid
3024 void wxListMainWindow::OnKillFocus( wxFocusEvent
&WXUNUSED(event
) )
3028 wxFocusEvent
event( wxEVT_KILL_FOCUS
, GetParent()->GetId() );
3029 event
.SetEventObject( GetParent() );
3030 if ( GetParent()->GetEventHandler()->ProcessEvent( event
) )
3038 void wxListMainWindow::DrawImage( int index
, wxDC
*dc
, int x
, int y
)
3040 if ( HasFlag(wxLC_ICON
) && (m_normal_image_list
))
3042 m_normal_image_list
->Draw( index
, *dc
, x
, y
, wxIMAGELIST_DRAW_TRANSPARENT
);
3044 else if ( HasFlag(wxLC_SMALL_ICON
) && (m_small_image_list
))
3046 m_small_image_list
->Draw( index
, *dc
, x
, y
, wxIMAGELIST_DRAW_TRANSPARENT
);
3048 else if ( HasFlag(wxLC_LIST
) && (m_small_image_list
))
3050 m_small_image_list
->Draw( index
, *dc
, x
, y
, wxIMAGELIST_DRAW_TRANSPARENT
);
3052 else if ( InReportView() && (m_small_image_list
))
3054 m_small_image_list
->Draw( index
, *dc
, x
, y
, wxIMAGELIST_DRAW_TRANSPARENT
);
3058 void wxListMainWindow::GetImageSize( int index
, int &width
, int &height
) const
3060 if ( HasFlag(wxLC_ICON
) && m_normal_image_list
)
3062 m_normal_image_list
->GetSize( index
, width
, height
);
3064 else if ( HasFlag(wxLC_SMALL_ICON
) && m_small_image_list
)
3066 m_small_image_list
->GetSize( index
, width
, height
);
3068 else if ( HasFlag(wxLC_LIST
) && m_small_image_list
)
3070 m_small_image_list
->GetSize( index
, width
, height
);
3072 else if ( InReportView() && m_small_image_list
)
3074 m_small_image_list
->GetSize( index
, width
, height
);
3083 void wxListMainWindow::SetImageList( wxImageList
*imageList
, int which
)
3087 // calc the spacing from the icon size
3088 int width
= 0, height
= 0;
3090 if ((imageList
) && (imageList
->GetImageCount()) )
3091 imageList
->GetSize(0, width
, height
);
3093 if (which
== wxIMAGE_LIST_NORMAL
)
3095 m_normal_image_list
= imageList
;
3096 m_normal_spacing
= width
+ 8;
3099 if (which
== wxIMAGE_LIST_SMALL
)
3101 m_small_image_list
= imageList
;
3102 m_small_spacing
= width
+ 14;
3103 m_lineHeight
= 0; // ensure that the line height will be recalc'd
3107 void wxListMainWindow::SetItemSpacing( int spacing
, bool isSmall
)
3111 m_small_spacing
= spacing
;
3113 m_normal_spacing
= spacing
;
3116 int wxListMainWindow::GetItemSpacing( bool isSmall
)
3118 return isSmall
? m_small_spacing
: m_normal_spacing
;
3121 // ----------------------------------------------------------------------------
3123 // ----------------------------------------------------------------------------
3126 wxListMainWindow::ComputeMinHeaderWidth(const wxListHeaderData
* column
) const
3128 wxClientDC
dc(const_cast<wxListMainWindow
*>(this));
3130 int width
= dc
.GetTextExtent(column
->GetText()).x
+ AUTOSIZE_COL_MARGIN
;
3132 width
+= 2*EXTRA_WIDTH
;
3134 // check for column header's image availability
3135 const int image
= column
->GetImage();
3138 if ( m_small_image_list
)
3141 m_small_image_list
->GetSize(image
, ix
, iy
);
3142 width
+= ix
+ HEADER_IMAGE_MARGIN_IN_REPORT_MODE
;
3149 void wxListMainWindow::SetColumn( int col
, const wxListItem
&item
)
3151 wxListHeaderDataList::compatibility_iterator node
= m_columns
.Item( col
);
3153 wxCHECK_RET( node
, wxT("invalid column index in SetColumn") );
3155 wxListHeaderData
*column
= node
->GetData();
3156 column
->SetItem( item
);
3158 if ( item
.m_width
== wxLIST_AUTOSIZE_USEHEADER
)
3159 column
->SetWidth(ComputeMinHeaderWidth(column
));
3161 wxListHeaderWindow
*headerWin
= GetListCtrl()->m_headerWin
;
3163 headerWin
->m_dirty
= true;
3167 // invalidate it as it has to be recalculated
3171 void wxListMainWindow::SetColumnWidth( int col
, int width
)
3173 wxCHECK_RET( col
>= 0 && col
< GetColumnCount(),
3174 wxT("invalid column index") );
3176 wxCHECK_RET( InReportView(),
3177 wxT("SetColumnWidth() can only be called in report mode.") );
3181 wxListHeaderWindow
*headerWin
= GetListCtrl()->m_headerWin
;
3183 headerWin
->m_dirty
= true;
3185 wxListHeaderDataList::compatibility_iterator node
= m_columns
.Item( col
);
3186 wxCHECK_RET( node
, wxT("no column?") );
3188 wxListHeaderData
*column
= node
->GetData();
3190 size_t count
= GetItemCount();
3192 if (width
== wxLIST_AUTOSIZE_USEHEADER
)
3194 width
= ComputeMinHeaderWidth(column
);
3196 else if ( width
== wxLIST_AUTOSIZE
)
3198 width
= ComputeMinHeaderWidth(column
);
3202 wxClientDC
dc(this);
3203 dc
.SetFont( GetFont() );
3205 int max
= AUTOSIZE_COL_MARGIN
;
3207 // if the cached column width isn't valid then recalculate it
3208 if (m_aColWidths
.Item(col
)->bNeedsUpdate
)
3210 for (size_t i
= 0; i
< count
; i
++)
3212 wxListLineData
*line
= GetLine( i
);
3213 wxListItemDataList::compatibility_iterator n
= line
->m_items
.Item( col
);
3215 wxCHECK_RET( n
, wxT("no subitem?") );
3217 wxListItemData
*itemData
= n
->GetData();
3220 itemData
->GetItem(item
);
3221 int itemWidth
= GetItemWidthWithImage(&item
);
3222 if (itemWidth
> max
)
3226 m_aColWidths
.Item(col
)->bNeedsUpdate
= false;
3227 m_aColWidths
.Item(col
)->nMaxWidth
= max
;
3230 max
= m_aColWidths
.Item(col
)->nMaxWidth
+ AUTOSIZE_COL_MARGIN
;
3236 column
->SetWidth( width
);
3238 // invalidate it as it has to be recalculated
3242 int wxListMainWindow::GetHeaderWidth() const
3244 if ( !m_headerWidth
)
3246 wxListMainWindow
*self
= wxConstCast(this, wxListMainWindow
);
3248 size_t count
= GetColumnCount();
3249 for ( size_t col
= 0; col
< count
; col
++ )
3251 self
->m_headerWidth
+= GetColumnWidth(col
);
3255 return m_headerWidth
;
3258 void wxListMainWindow::GetColumn( int col
, wxListItem
&item
) const
3260 wxListHeaderDataList::compatibility_iterator node
= m_columns
.Item( col
);
3261 wxCHECK_RET( node
, wxT("invalid column index in GetColumn") );
3263 wxListHeaderData
*column
= node
->GetData();
3264 column
->GetItem( item
);
3267 int wxListMainWindow::GetColumnWidth( int col
) const
3269 wxListHeaderDataList::compatibility_iterator node
= m_columns
.Item( col
);
3270 wxCHECK_MSG( node
, 0, wxT("invalid column index") );
3272 wxListHeaderData
*column
= node
->GetData();
3273 return column
->GetWidth();
3276 // ----------------------------------------------------------------------------
3278 // ----------------------------------------------------------------------------
3280 void wxListMainWindow::SetItem( wxListItem
&item
)
3282 long id
= item
.m_itemId
;
3283 wxCHECK_RET( id
>= 0 && (size_t)id
< GetItemCount(),
3284 wxT("invalid item index in SetItem") );
3288 wxListLineData
*line
= GetLine((size_t)id
);
3289 line
->SetItem( item
.m_col
, item
);
3291 // Set item state if user wants
3292 if ( item
.m_mask
& wxLIST_MASK_STATE
)
3293 SetItemState( item
.m_itemId
, item
.m_state
, item
.m_state
);
3297 // update the Max Width Cache if needed
3298 int width
= GetItemWidthWithImage(&item
);
3300 if (width
> m_aColWidths
.Item(item
.m_col
)->nMaxWidth
)
3301 m_aColWidths
.Item(item
.m_col
)->nMaxWidth
= width
;
3305 // update the item on screen unless we're going to update everything soon
3310 GetItemRect(id
, rectItem
);
3311 RefreshRect(rectItem
);
3315 void wxListMainWindow::SetItemStateAll(long state
, long stateMask
)
3320 // first deal with selection
3321 if ( stateMask
& wxLIST_STATE_SELECTED
)
3323 // set/clear select state
3326 // optimized version for virtual listctrl.
3327 m_selStore
.SelectRange(0, GetItemCount() - 1, state
== wxLIST_STATE_SELECTED
);
3330 else if ( state
& wxLIST_STATE_SELECTED
)
3332 const long count
= GetItemCount();
3333 for( long i
= 0; i
< count
; i
++ )
3335 SetItemState( i
, wxLIST_STATE_SELECTED
, wxLIST_STATE_SELECTED
);
3341 // clear for non virtual (somewhat optimized by using GetNextItem())
3343 while ( (i
= GetNextItem(i
, wxLIST_NEXT_ALL
, wxLIST_STATE_SELECTED
)) != -1 )
3345 SetItemState( i
, 0, wxLIST_STATE_SELECTED
);
3350 if ( HasCurrent() && (state
== 0) && (stateMask
& wxLIST_STATE_FOCUSED
) )
3352 // unfocus all: only one item can be focussed, so clearing focus for
3353 // all items is simply clearing focus of the focussed item.
3354 SetItemState(m_current
, state
, stateMask
);
3356 //(setting focus to all items makes no sense, so it is not handled here.)
3359 void wxListMainWindow::SetItemState( long litem
, long state
, long stateMask
)
3363 SetItemStateAll(state
, stateMask
);
3367 wxCHECK_RET( litem
>= 0 && (size_t)litem
< GetItemCount(),
3368 wxT("invalid list ctrl item index in SetItem") );
3370 size_t oldCurrent
= m_current
;
3371 size_t item
= (size_t)litem
; // safe because of the check above
3373 // do we need to change the focus?
3374 if ( stateMask
& wxLIST_STATE_FOCUSED
)
3376 if ( state
& wxLIST_STATE_FOCUSED
)
3378 // don't do anything if this item is already focused
3379 if ( item
!= m_current
)
3381 ChangeCurrent(item
);
3383 if ( oldCurrent
!= (size_t)-1 )
3385 if ( IsSingleSel() )
3387 HighlightLine(oldCurrent
, false);
3390 RefreshLine(oldCurrent
);
3393 RefreshLine( m_current
);
3398 // don't do anything if this item is not focused
3399 if ( item
== m_current
)
3403 if ( IsSingleSel() )
3405 // we must unselect the old current item as well or we
3406 // might end up with more than one selected item in a
3407 // single selection control
3408 HighlightLine(oldCurrent
, false);
3411 RefreshLine( oldCurrent
);
3416 // do we need to change the selection state?
3417 if ( stateMask
& wxLIST_STATE_SELECTED
)
3419 bool on
= (state
& wxLIST_STATE_SELECTED
) != 0;
3421 if ( IsSingleSel() )
3425 // selecting the item also makes it the focused one in the
3427 if ( m_current
!= item
)
3429 ChangeCurrent(item
);
3431 if ( oldCurrent
!= (size_t)-1 )
3433 HighlightLine( oldCurrent
, false );
3434 RefreshLine( oldCurrent
);
3440 // only the current item may be selected anyhow
3441 if ( item
!= m_current
)
3446 if ( HighlightLine(item
, on
) )
3453 int wxListMainWindow::GetItemState( long item
, long stateMask
) const
3455 wxCHECK_MSG( item
>= 0 && (size_t)item
< GetItemCount(), 0,
3456 wxT("invalid list ctrl item index in GetItemState()") );
3458 int ret
= wxLIST_STATE_DONTCARE
;
3460 if ( stateMask
& wxLIST_STATE_FOCUSED
)
3462 if ( (size_t)item
== m_current
)
3463 ret
|= wxLIST_STATE_FOCUSED
;
3466 if ( stateMask
& wxLIST_STATE_SELECTED
)
3468 if ( IsHighlighted(item
) )
3469 ret
|= wxLIST_STATE_SELECTED
;
3475 void wxListMainWindow::GetItem( wxListItem
&item
) const
3477 wxCHECK_RET( item
.m_itemId
>= 0 && (size_t)item
.m_itemId
< GetItemCount(),
3478 wxT("invalid item index in GetItem") );
3480 wxListLineData
*line
= GetLine((size_t)item
.m_itemId
);
3481 line
->GetItem( item
.m_col
, item
);
3483 // Get item state if user wants it
3484 if ( item
.m_mask
& wxLIST_MASK_STATE
)
3485 item
.m_state
= GetItemState( item
.m_itemId
, wxLIST_STATE_SELECTED
|
3486 wxLIST_STATE_FOCUSED
);
3489 // ----------------------------------------------------------------------------
3491 // ----------------------------------------------------------------------------
3493 size_t wxListMainWindow::GetItemCount() const
3495 return IsVirtual() ? m_countVirt
: m_lines
.GetCount();
3498 void wxListMainWindow::SetItemCount(long count
)
3500 m_selStore
.SetItemCount(count
);
3501 m_countVirt
= count
;
3503 ResetVisibleLinesRange();
3505 // scrollbars must be reset
3509 int wxListMainWindow::GetSelectedItemCount() const
3511 // deal with the quick case first
3512 if ( IsSingleSel() )
3513 return HasCurrent() ? IsHighlighted(m_current
) : false;
3515 // virtual controls remmebers all its selections itself
3517 return m_selStore
.GetSelectedCount();
3519 // TODO: we probably should maintain the number of items selected even for
3520 // non virtual controls as enumerating all lines is really slow...
3521 size_t countSel
= 0;
3522 size_t count
= GetItemCount();
3523 for ( size_t line
= 0; line
< count
; line
++ )
3525 if ( GetLine(line
)->IsHighlighted() )
3532 // ----------------------------------------------------------------------------
3533 // item position/size
3534 // ----------------------------------------------------------------------------
3536 wxRect
wxListMainWindow::GetViewRect() const
3538 wxASSERT_MSG( !HasFlag(wxLC_LIST
), "not implemented for list view" );
3540 // we need to find the longest/tallest label
3541 wxCoord xMax
= 0, yMax
= 0;
3542 const int count
= GetItemCount();
3545 for ( int i
= 0; i
< count
; i
++ )
3547 // we need logical, not physical, coordinates here, so use
3548 // GetLineRect() instead of GetItemRect()
3549 wxRect r
= GetLineRect(i
);
3551 wxCoord x
= r
.GetRight(),
3561 // some fudge needed to make it look prettier
3562 xMax
+= 2 * EXTRA_BORDER_X
;
3563 yMax
+= 2 * EXTRA_BORDER_Y
;
3565 // account for the scrollbars if necessary
3566 const wxSize sizeAll
= GetClientSize();
3567 if ( xMax
> sizeAll
.x
)
3568 yMax
+= wxSystemSettings::GetMetric(wxSYS_HSCROLL_Y
);
3569 if ( yMax
> sizeAll
.y
)
3570 xMax
+= wxSystemSettings::GetMetric(wxSYS_VSCROLL_X
);
3572 return wxRect(0, 0, xMax
, yMax
);
3576 wxListMainWindow::GetSubItemRect(long item
, long subItem
, wxRect
& rect
) const
3578 wxCHECK_MSG( subItem
== wxLIST_GETSUBITEMRECT_WHOLEITEM
|| InReportView(),
3580 wxT("GetSubItemRect only meaningful in report view") );
3581 wxCHECK_MSG( item
>= 0 && (size_t)item
< GetItemCount(), false,
3582 wxT("invalid item in GetSubItemRect") );
3584 // ensure that we're laid out, otherwise we could return nonsense
3587 wxConstCast(this, wxListMainWindow
)->
3588 RecalculatePositions(true /* no refresh */);
3591 rect
= GetLineRect((size_t)item
);
3593 // Adjust rect to specified column
3594 if ( subItem
!= wxLIST_GETSUBITEMRECT_WHOLEITEM
)
3596 wxCHECK_MSG( subItem
>= 0 && subItem
< GetColumnCount(), false,
3597 wxT("invalid subItem in GetSubItemRect") );
3599 for (int i
= 0; i
< subItem
; i
++)
3601 rect
.x
+= GetColumnWidth(i
);
3603 rect
.width
= GetColumnWidth(subItem
);
3606 GetListCtrl()->CalcScrolledPosition(rect
.x
, rect
.y
, &rect
.x
, &rect
.y
);
3611 bool wxListMainWindow::GetItemPosition(long item
, wxPoint
& pos
) const
3614 GetItemRect(item
, rect
);
3622 // ----------------------------------------------------------------------------
3623 // geometry calculation
3624 // ----------------------------------------------------------------------------
3626 void wxListMainWindow::RecalculatePositions(bool noRefresh
)
3628 const int lineHeight
= GetLineHeight();
3630 wxClientDC
dc( this );
3631 dc
.SetFont( GetFont() );
3633 const size_t count
= GetItemCount();
3636 if ( HasFlag(wxLC_ICON
) && m_normal_image_list
)
3637 iconSpacing
= m_normal_spacing
;
3638 else if ( HasFlag(wxLC_SMALL_ICON
) && m_small_image_list
)
3639 iconSpacing
= m_small_spacing
;
3643 // Note that we do not call GetClientSize() here but
3644 // GetSize() and subtract the border size for sunken
3645 // borders manually. This is technically incorrect,
3646 // but we need to know the client area's size WITHOUT
3647 // scrollbars here. Since we don't know if there are
3648 // any scrollbars, we use GetSize() instead. Another
3649 // solution would be to call SetScrollbars() here to
3650 // remove the scrollbars and call GetClientSize() then,
3651 // but this might result in flicker and - worse - will
3652 // reset the scrollbars to 0 which is not good at all
3653 // if you resize a dialog/window, but don't want to
3654 // reset the window scrolling. RR.
3655 // Furthermore, we actually do NOT subtract the border
3656 // width as 2 pixels is just the extra space which we
3657 // need around the actual content in the window. Other-
3658 // wise the text would e.g. touch the upper border. RR.
3661 GetSize( &clientWidth
, &clientHeight
);
3663 if ( InReportView() )
3665 // all lines have the same height and we scroll one line per step
3666 int entireHeight
= count
* lineHeight
+ LINE_SPACING
;
3668 m_linesPerPage
= clientHeight
/ lineHeight
;
3670 ResetVisibleLinesRange();
3672 GetListCtrl()->SetScrollbars( SCROLL_UNIT_X
, lineHeight
,
3673 GetHeaderWidth() / SCROLL_UNIT_X
,
3674 (entireHeight
+ lineHeight
- 1) / lineHeight
,
3675 GetListCtrl()->GetScrollPos(wxHORIZONTAL
),
3676 GetListCtrl()->GetScrollPos(wxVERTICAL
),
3681 // we have 3 different layout strategies: either layout all items
3682 // horizontally/vertically (wxLC_ALIGN_XXX styles explicitly given) or
3683 // to arrange them in top to bottom, left to right (don't ask me why
3684 // not the other way round...) order
3685 if ( HasFlag(wxLC_ALIGN_LEFT
| wxLC_ALIGN_TOP
) )
3687 int x
= EXTRA_BORDER_X
;
3688 int y
= EXTRA_BORDER_Y
;
3690 wxCoord widthMax
= 0;
3693 for ( i
= 0; i
< count
; i
++ )
3695 wxListLineData
*line
= GetLine(i
);
3696 line
->CalculateSize( &dc
, iconSpacing
);
3697 line
->SetPosition( x
, y
, iconSpacing
);
3699 wxSize sizeLine
= GetLineSize(i
);
3701 if ( HasFlag(wxLC_ALIGN_TOP
) )
3703 if ( sizeLine
.x
> widthMax
)
3704 widthMax
= sizeLine
.x
;
3708 else // wxLC_ALIGN_LEFT
3710 x
+= sizeLine
.x
+ MARGIN_BETWEEN_ROWS
;
3714 if ( HasFlag(wxLC_ALIGN_TOP
) )
3716 // traverse the items again and tweak their sizes so that they are
3717 // all the same in a row
3718 for ( i
= 0; i
< count
; i
++ )
3720 wxListLineData
*line
= GetLine(i
);
3721 line
->m_gi
->ExtendWidth(widthMax
);
3725 GetListCtrl()->SetScrollbars
3729 (x
+ SCROLL_UNIT_X
) / SCROLL_UNIT_X
,
3730 (y
+ lineHeight
) / lineHeight
,
3731 GetListCtrl()->GetScrollPos( wxHORIZONTAL
),
3732 GetListCtrl()->GetScrollPos( wxVERTICAL
),
3736 else // "flowed" arrangement, the most complicated case
3738 // at first we try without any scrollbars, if the items don't fit into
3739 // the window, we recalculate after subtracting the space taken by the
3742 int entireWidth
= 0;
3744 for (int tries
= 0; tries
< 2; tries
++)
3746 entireWidth
= 2 * EXTRA_BORDER_X
;
3750 // Now we have decided that the items do not fit into the
3751 // client area, so we need a scrollbar
3752 entireWidth
+= SCROLL_UNIT_X
;
3755 int x
= EXTRA_BORDER_X
;
3756 int y
= EXTRA_BORDER_Y
;
3758 // Note that "row" here is vertical, i.e. what is called
3759 // "column" in many other places in wxWidgets.
3760 int maxWidthInThisRow
= 0;
3763 int currentlyVisibleLines
= 0;
3765 for (size_t i
= 0; i
< count
; i
++)
3767 currentlyVisibleLines
++;
3768 wxListLineData
*line
= GetLine( i
);
3769 line
->CalculateSize( &dc
, iconSpacing
);
3770 line
->SetPosition( x
, y
, iconSpacing
);
3772 wxSize sizeLine
= GetLineSize( i
);
3774 if ( maxWidthInThisRow
< sizeLine
.x
)
3775 maxWidthInThisRow
= sizeLine
.x
;
3778 if (currentlyVisibleLines
> m_linesPerPage
)
3779 m_linesPerPage
= currentlyVisibleLines
;
3781 // Have we reached the end of the row either because no
3782 // more items would fit or because there are simply no more
3784 if ( y
+ sizeLine
.y
>= clientHeight
3787 // Adjust all items in this row to have the same
3788 // width to ensure that they all align horizontally in
3790 if ( HasFlag(wxLC_ICON
) || HasFlag(wxLC_SMALL_ICON
) )
3792 size_t firstRowLine
= i
- currentlyVisibleLines
+ 1;
3793 for (size_t j
= firstRowLine
; j
<= i
; j
++)
3795 GetLine(j
)->m_gi
->ExtendWidth(maxWidthInThisRow
);
3799 currentlyVisibleLines
= 0;
3801 maxWidthInThisRow
+= MARGIN_BETWEEN_ROWS
;
3802 x
+= maxWidthInThisRow
;
3803 entireWidth
+= maxWidthInThisRow
;
3804 maxWidthInThisRow
= 0;
3807 if ( (tries
== 0) &&
3808 (entireWidth
+ SCROLL_UNIT_X
> clientWidth
) )
3810 clientHeight
-= wxSystemSettings::
3811 GetMetric(wxSYS_HSCROLL_Y
);
3816 if ( i
== count
- 1 )
3817 tries
= 1; // Everything fits, no second try required.
3821 GetListCtrl()->SetScrollbars
3825 (entireWidth
+ SCROLL_UNIT_X
) / SCROLL_UNIT_X
,
3827 GetListCtrl()->GetScrollPos( wxHORIZONTAL
),
3836 // FIXME: why should we call it from here?
3843 void wxListMainWindow::RefreshAll()
3848 wxListHeaderWindow
*headerWin
= GetListCtrl()->m_headerWin
;
3849 if ( headerWin
&& headerWin
->m_dirty
)
3851 headerWin
->m_dirty
= false;
3852 headerWin
->Refresh();
3856 void wxListMainWindow::UpdateCurrent()
3858 if ( !HasCurrent() && !IsEmpty() )
3862 long wxListMainWindow::GetNextItem( long item
,
3863 int WXUNUSED(geometry
),
3867 max
= GetItemCount();
3868 wxCHECK_MSG( (ret
== -1) || (ret
< max
), -1,
3869 wxT("invalid listctrl index in GetNextItem()") );
3871 // notice that we start with the next item (or the first one if item == -1)
3872 // and this is intentional to allow writing a simple loop to iterate over
3873 // all selected items
3876 // this is not an error because the index was OK initially,
3877 // just no such item
3884 size_t count
= GetItemCount();
3885 for ( size_t line
= (size_t)ret
; line
< count
; line
++ )
3887 if ( (state
& wxLIST_STATE_FOCUSED
) && (line
== m_current
) )
3890 if ( (state
& wxLIST_STATE_SELECTED
) && IsHighlighted(line
) )
3897 // ----------------------------------------------------------------------------
3899 // ----------------------------------------------------------------------------
3901 void wxListMainWindow::DeleteItem( long lindex
)
3903 size_t count
= GetItemCount();
3905 wxCHECK_RET( (lindex
>= 0) && ((size_t)lindex
< count
),
3906 wxT("invalid item index in DeleteItem") );
3908 size_t index
= (size_t)lindex
;
3910 // we don't need to adjust the index for the previous items
3911 if ( HasCurrent() && m_current
>= index
)
3913 // if the current item is being deleted, we want the next one to
3914 // become selected - unless there is no next one - so don't adjust
3915 // m_current in this case
3916 if ( m_current
!= index
|| m_current
== count
- 1 )
3920 if ( InReportView() )
3922 // mark the Column Max Width cache as dirty if the items in the line
3923 // we're deleting contain the Max Column Width
3924 wxListLineData
* const line
= GetLine(index
);
3925 wxListItemDataList::compatibility_iterator n
;
3926 wxListItemData
*itemData
;
3930 for (size_t i
= 0; i
< m_columns
.GetCount(); i
++)
3932 n
= line
->m_items
.Item( i
);
3933 itemData
= n
->GetData();
3934 itemData
->GetItem(item
);
3936 itemWidth
= GetItemWidthWithImage(&item
);
3938 if (itemWidth
>= m_aColWidths
.Item(i
)->nMaxWidth
)
3939 m_aColWidths
.Item(i
)->bNeedsUpdate
= true;
3942 ResetVisibleLinesRange();
3945 SendNotify( index
, wxEVT_LIST_DELETE_ITEM
, wxDefaultPosition
);
3950 m_selStore
.OnItemDelete(index
);
3954 m_lines
.RemoveAt( index
);
3957 // we need to refresh the (vert) scrollbar as the number of items changed
3960 RefreshAfter(index
);
3963 void wxListMainWindow::DeleteColumn( int col
)
3965 wxListHeaderDataList::compatibility_iterator node
= m_columns
.Item( col
);
3967 wxCHECK_RET( node
, wxT("invalid column index in DeleteColumn()") );
3970 delete node
->GetData();
3971 m_columns
.Erase( node
);
3975 // update all the items
3976 for ( size_t i
= 0; i
< m_lines
.GetCount(); i
++ )
3978 wxListLineData
* const line
= GetLine(i
);
3980 // In the following atypical but possible scenario it can be
3981 // legal to call DeleteColumn() but the items may not have any
3983 // 1. In report view, insert a second column.
3984 // 2. Still in report view, add an item with 2 values.
3985 // 3. Switch to an icon (or list) view.
3986 // 4. Add an item -- necessarily with 1 value only.
3987 // 5. Switch back to report view.
3988 // 6. Call DeleteColumn().
3989 // So we need to check for this as otherwise we would simply crash
3991 if ( line
->m_items
.GetCount() <= static_cast<unsigned>(col
) )
3994 wxListItemDataList::compatibility_iterator n
= line
->m_items
.Item( col
);
3995 delete n
->GetData();
3996 line
->m_items
.Erase(n
);
4000 if ( InReportView() ) // we only cache max widths when in Report View
4002 delete m_aColWidths
.Item(col
);
4003 m_aColWidths
.RemoveAt(col
);
4006 // invalidate it as it has to be recalculated
4010 void wxListMainWindow::DoDeleteAllItems()
4013 // nothing to do - in particular, don't send the event
4018 // to make the deletion of all items faster, we don't send the
4019 // notifications for each item deletion in this case but only one event
4020 // for all of them: this is compatible with wxMSW and documented in
4021 // DeleteAllItems() description
4023 wxListEvent
event( wxEVT_LIST_DELETE_ALL_ITEMS
, GetParent()->GetId() );
4024 event
.SetEventObject( GetParent() );
4025 GetParent()->GetEventHandler()->ProcessEvent( event
);
4033 if ( InReportView() )
4035 ResetVisibleLinesRange();
4036 for (size_t i
= 0; i
< m_aColWidths
.GetCount(); i
++)
4038 m_aColWidths
.Item(i
)->bNeedsUpdate
= true;
4045 void wxListMainWindow::DeleteAllItems()
4049 RecalculatePositions();
4052 void wxListMainWindow::DeleteEverything()
4054 WX_CLEAR_LIST(wxListHeaderDataList
, m_columns
);
4055 WX_CLEAR_ARRAY(m_aColWidths
);
4060 // ----------------------------------------------------------------------------
4061 // scanning for an item
4062 // ----------------------------------------------------------------------------
4064 void wxListMainWindow::EnsureVisible( long index
)
4066 wxCHECK_RET( index
>= 0 && (size_t)index
< GetItemCount(),
4067 wxT("invalid index in EnsureVisible") );
4069 // We have to call this here because the label in question might just have
4070 // been added and its position is not known yet
4072 RecalculatePositions(true /* no refresh */);
4074 MoveToItem((size_t)index
);
4077 long wxListMainWindow::FindItem(long start
, const wxString
& str
, bool partial
)
4083 wxString str_upper
= str
.Upper();
4087 size_t count
= GetItemCount();
4088 for ( size_t i
= (size_t)pos
; i
< count
; i
++ )
4090 wxListLineData
*line
= GetLine(i
);
4091 wxString line_upper
= line
->GetText(0).Upper();
4094 if (line_upper
== str_upper
)
4099 if (line_upper
.find(str_upper
) == 0)
4107 long wxListMainWindow::FindItem(long start
, wxUIntPtr data
)
4113 size_t count
= GetItemCount();
4114 for (size_t i
= (size_t)pos
; i
< count
; i
++)
4116 wxListLineData
*line
= GetLine(i
);
4118 line
->GetItem( 0, item
);
4119 if (item
.m_data
== data
)
4126 long wxListMainWindow::FindItem( const wxPoint
& pt
)
4129 GetVisibleLinesRange( &topItem
, NULL
);
4132 GetItemPosition( GetItemCount() - 1, p
);
4136 long id
= (long)floor( pt
.y
* double(GetItemCount() - topItem
- 1) / p
.y
+ topItem
);
4137 if ( id
>= 0 && id
< (long)GetItemCount() )
4143 long wxListMainWindow::HitTest( int x
, int y
, int &flags
) const
4145 GetListCtrl()->CalcUnscrolledPosition( x
, y
, &x
, &y
);
4147 size_t count
= GetItemCount();
4149 if ( InReportView() )
4151 size_t current
= y
/ GetLineHeight();
4152 if ( current
< count
)
4154 flags
= HitTestLine(current
, x
, y
);
4161 // TODO: optimize it too! this is less simple than for report view but
4162 // enumerating all items is still not a way to do it!!
4163 for ( size_t current
= 0; current
< count
; current
++ )
4165 flags
= HitTestLine(current
, x
, y
);
4174 // ----------------------------------------------------------------------------
4176 // ----------------------------------------------------------------------------
4178 void wxListMainWindow::InsertItem( wxListItem
&item
)
4180 wxASSERT_MSG( !IsVirtual(), wxT("can't be used with virtual control") );
4182 int count
= GetItemCount();
4183 wxCHECK_RET( item
.m_itemId
>= 0, wxT("invalid item index") );
4185 if (item
.m_itemId
> count
)
4186 item
.m_itemId
= count
;
4188 size_t id
= item
.m_itemId
;
4192 if ( InReportView() )
4194 ResetVisibleLinesRange();
4196 const unsigned col
= item
.GetColumn();
4197 wxCHECK_RET( col
< m_aColWidths
.size(), "invalid item column" );
4199 // calculate the width of the item and adjust the max column width
4200 wxColWidthInfo
*pWidthInfo
= m_aColWidths
.Item(col
);
4201 int width
= GetItemWidthWithImage(&item
);
4202 item
.SetWidth(width
);
4203 if (width
> pWidthInfo
->nMaxWidth
)
4204 pWidthInfo
->nMaxWidth
= width
;
4207 wxListLineData
*line
= new wxListLineData(this);
4209 line
->SetItem( item
.m_col
, item
);
4210 if ( item
.m_mask
& wxLIST_MASK_IMAGE
)
4212 // Reset the buffered height if it's not big enough for the new image.
4213 int image
= item
.GetImage();
4214 if ( m_small_image_list
&& image
!= -1 && InReportView() )
4216 int imageWidth
, imageHeight
;
4217 m_small_image_list
->GetSize(image
, imageWidth
, imageHeight
);
4219 if ( imageHeight
> m_lineHeight
)
4224 m_lines
.Insert( line
, id
);
4228 // If an item is selected at or below the point of insertion, we need to
4229 // increment the member variables because the current row's index has gone
4231 if ( HasCurrent() && m_current
>= id
)
4234 SendNotify(id
, wxEVT_LIST_INSERT_ITEM
);
4236 RefreshLines(id
, GetItemCount() - 1);
4239 long wxListMainWindow::InsertColumn( long col
, const wxListItem
&item
)
4244 if ( InReportView() )
4246 wxListHeaderData
*column
= new wxListHeaderData( item
);
4247 if (item
.m_width
== wxLIST_AUTOSIZE_USEHEADER
)
4248 column
->SetWidth(ComputeMinHeaderWidth(column
));
4250 wxColWidthInfo
*colWidthInfo
= new wxColWidthInfo();
4252 bool insert
= (col
>= 0) && ((size_t)col
< m_columns
.GetCount());
4255 wxListHeaderDataList::compatibility_iterator
4256 node
= m_columns
.Item( col
);
4257 m_columns
.Insert( node
, column
);
4258 m_aColWidths
.Insert( colWidthInfo
, col
);
4263 idx
= m_aColWidths
.GetCount();
4264 m_columns
.Append( column
);
4265 m_aColWidths
.Add( colWidthInfo
);
4270 // update all the items
4271 for ( size_t i
= 0; i
< m_lines
.GetCount(); i
++ )
4273 wxListLineData
* const line
= GetLine(i
);
4274 wxListItemData
* const data
= new wxListItemData(this);
4276 line
->m_items
.Insert(col
, data
);
4278 line
->m_items
.Append(data
);
4282 // invalidate it as it has to be recalculated
4288 int wxListMainWindow::GetItemWidthWithImage(wxListItem
* item
)
4291 wxClientDC
dc(this);
4293 dc
.SetFont( GetFont() );
4295 if (item
->GetImage() != -1)
4298 GetImageSize( item
->GetImage(), ix
, iy
);
4302 if (!item
->GetText().empty())
4305 dc
.GetTextExtent( item
->GetText(), &w
, NULL
);
4312 // ----------------------------------------------------------------------------
4314 // ----------------------------------------------------------------------------
4316 static wxListCtrlCompare list_ctrl_compare_func_2
;
4317 static wxIntPtr list_ctrl_compare_data
;
4319 int LINKAGEMODE
list_ctrl_compare_func_1( wxListLineData
**arg1
, wxListLineData
**arg2
)
4321 wxListLineData
*line1
= *arg1
;
4322 wxListLineData
*line2
= *arg2
;
4324 line1
->GetItem( 0, item
);
4325 wxUIntPtr data1
= item
.m_data
;
4326 line2
->GetItem( 0, item
);
4327 wxUIntPtr data2
= item
.m_data
;
4328 return list_ctrl_compare_func_2( data1
, data2
, list_ctrl_compare_data
);
4331 void wxListMainWindow::SortItems( wxListCtrlCompare fn
, wxIntPtr data
)
4333 // selections won't make sense any more after sorting the items so reset
4335 HighlightAll(false);
4338 list_ctrl_compare_func_2
= fn
;
4339 list_ctrl_compare_data
= data
;
4340 m_lines
.Sort( list_ctrl_compare_func_1
);
4344 // ----------------------------------------------------------------------------
4346 // ----------------------------------------------------------------------------
4348 void wxListMainWindow::OnScroll(wxScrollWinEvent
& event
)
4350 // update our idea of which lines are shown when we redraw the window the
4352 ResetVisibleLinesRange();
4354 if ( event
.GetOrientation() == wxHORIZONTAL
&& HasHeader() )
4356 wxGenericListCtrl
* lc
= GetListCtrl();
4357 wxCHECK_RET( lc
, wxT("no listctrl window?") );
4359 if (lc
->m_headerWin
) // when we use wxLC_NO_HEADER, m_headerWin==NULL
4361 lc
->m_headerWin
->Refresh();
4362 lc
->m_headerWin
->Update();
4367 int wxListMainWindow::GetCountPerPage() const
4369 if ( !m_linesPerPage
)
4371 wxConstCast(this, wxListMainWindow
)->
4372 m_linesPerPage
= GetClientSize().y
/ GetLineHeight();
4375 return m_linesPerPage
;
4378 void wxListMainWindow::GetVisibleLinesRange(size_t *from
, size_t *to
)
4380 wxASSERT_MSG( InReportView(), wxT("this is for report mode only") );
4382 if ( m_lineFrom
== (size_t)-1 )
4384 size_t count
= GetItemCount();
4387 m_lineFrom
= GetListCtrl()->GetScrollPos(wxVERTICAL
);
4389 // this may happen if SetScrollbars() hadn't been called yet
4390 if ( m_lineFrom
>= count
)
4391 m_lineFrom
= count
- 1;
4393 // we redraw one extra line but this is needed to make the redrawing
4394 // logic work when there is a fractional number of lines on screen
4395 m_lineTo
= m_lineFrom
+ m_linesPerPage
;
4396 if ( m_lineTo
>= count
)
4397 m_lineTo
= count
- 1;
4399 else // empty control
4402 m_lineTo
= (size_t)-1;
4406 wxASSERT_MSG( IsEmpty() ||
4407 (m_lineFrom
<= m_lineTo
&& m_lineTo
< GetItemCount()),
4408 wxT("GetVisibleLinesRange() returns incorrect result") );
4417 wxListMainWindow::PrefixFindItem(size_t idParent
,
4418 const wxString
& prefixOrig
) const
4420 // if no items then just return
4421 if ( idParent
== (size_t)-1 )
4424 // match is case insensitive as this is more convenient to the user: having
4425 // to press Shift-letter to go to the item starting with a capital letter
4426 // would be too bothersome
4427 wxString prefix
= prefixOrig
.Lower();
4429 // determine the starting point: we shouldn't take the current item (this
4430 // allows to switch between two items starting with the same letter just by
4431 // pressing it) but we shouldn't jump to the next one if the user is
4432 // continuing to type as otherwise he might easily skip the item he wanted
4433 size_t itemid
= idParent
;
4434 if ( prefix
.length() == 1 )
4439 // look for the item starting with the given prefix after it
4440 while ( ( itemid
< (size_t)GetItemCount() ) &&
4441 !GetLine(itemid
)->GetText(0).Lower().StartsWith(prefix
) )
4446 // if we haven't found anything...
4447 if ( !( itemid
< (size_t)GetItemCount() ) )
4449 // ... wrap to the beginning
4452 // and try all the items (stop when we get to the one we started from)
4453 while ( ( itemid
< (size_t)GetItemCount() ) && itemid
!= idParent
&&
4454 !GetLine(itemid
)->GetText(0).Lower().StartsWith(prefix
) )
4458 // If we haven't found the item, id will be (size_t)-1, as per
4460 if ( !( itemid
< (size_t)GetItemCount() ) ||
4461 ( ( itemid
== idParent
) &&
4462 !GetLine(itemid
)->GetText(0).Lower().StartsWith(prefix
) ) )
4464 itemid
= (size_t)-1;
4471 // -------------------------------------------------------------------------------------
4472 // wxGenericListCtrl
4473 // -------------------------------------------------------------------------------------
4475 IMPLEMENT_DYNAMIC_CLASS(wxGenericListCtrl
, wxControl
)
4477 BEGIN_EVENT_TABLE(wxGenericListCtrl
,wxListCtrlBase
)
4478 EVT_SIZE(wxGenericListCtrl::OnSize
)
4479 EVT_SCROLLWIN(wxGenericListCtrl::OnScroll
)
4482 void wxGenericListCtrl::Init()
4484 m_imageListNormal
= NULL
;
4485 m_imageListSmall
= NULL
;
4486 m_imageListState
= NULL
;
4488 m_ownsImageListNormal
=
4489 m_ownsImageListSmall
=
4490 m_ownsImageListState
= false;
4496 wxGenericListCtrl::~wxGenericListCtrl()
4498 if (m_ownsImageListNormal
)
4499 delete m_imageListNormal
;
4500 if (m_ownsImageListSmall
)
4501 delete m_imageListSmall
;
4502 if (m_ownsImageListState
)
4503 delete m_imageListState
;
4506 void wxGenericListCtrl::CreateOrDestroyHeaderWindowAsNeeded()
4508 bool needs_header
= HasHeader();
4509 bool has_header
= (m_headerWin
!= NULL
);
4511 if (needs_header
== has_header
)
4516 // Notice that we must initialize m_headerWin first, and create the
4517 // real window only later, so that the test in the beginning of the
4518 // function blocks repeated creation of the header as it could happen
4519 // before via wxNavigationEnabled::AddChild() -> ToggleWindowStyle() ->
4520 // SetWindowStyleFlag().
4521 m_headerWin
= new wxListHeaderWindow();
4524 this, wxID_ANY
, m_mainWin
,
4529 wxRendererNative::Get().GetHeaderButtonHeight(this)
4534 #if defined( __WXMAC__ )
4535 static wxFont
font( wxOSX_SYSTEM_FONT_SMALL
);
4536 m_headerWin
->SetFont( font
);
4539 GetSizer()->Prepend( m_headerWin
, 0, wxGROW
);
4543 GetSizer()->Detach( m_headerWin
);
4545 wxDELETE(m_headerWin
);
4549 bool wxGenericListCtrl::Create(wxWindow
*parent
,
4554 const wxValidator
&validator
,
4555 const wxString
&name
)
4559 // just like in other ports, an assert will fail if the user doesn't give any type style:
4560 wxASSERT_MSG( (style
& wxLC_MASK_TYPE
),
4561 wxT("wxListCtrl style should have exactly one mode bit set") );
4563 if ( !wxListCtrlBase::Create( parent
, id
, pos
, size
,
4564 style
| wxVSCROLL
| wxHSCROLL
,
4568 m_mainWin
= new wxListMainWindow(this, wxID_ANY
, wxPoint(0, 0), size
);
4570 SetTargetWindow( m_mainWin
);
4572 // We use the cursor keys for moving the selection, not scrolling, so call
4573 // this method to ensure wxScrollHelperEvtHandler doesn't catch all
4574 // keyboard events forwarded to us from wxListMainWindow.
4575 DisableKeyboardScrolling();
4577 wxBoxSizer
*sizer
= new wxBoxSizer( wxVERTICAL
);
4578 sizer
->Add( m_mainWin
, 1, wxGROW
);
4581 CreateOrDestroyHeaderWindowAsNeeded();
4583 SetInitialSize(size
);
4588 wxBorder
wxGenericListCtrl::GetDefaultBorder() const
4590 return wxBORDER_THEME
;
4593 #if defined(__WXMSW__) && !defined(__WXWINCE__) && !defined(__WXUNIVERSAL__)
4594 WXLRESULT
wxGenericListCtrl::MSWWindowProc(WXUINT nMsg
,
4598 WXLRESULT rc
= wxListCtrlBase::MSWWindowProc(nMsg
, wParam
, lParam
);
4600 // we need to process arrows ourselves for scrolling
4601 if ( nMsg
== WM_GETDLGCODE
)
4603 rc
|= DLGC_WANTARROWS
;
4610 wxSize
wxGenericListCtrl::GetSizeAvailableForScrollTarget(const wxSize
& size
)
4612 wxSize newsize
= size
;
4614 newsize
.y
-= m_headerWin
->GetSize().y
;
4619 void wxGenericListCtrl::OnScroll(wxScrollWinEvent
& event
)
4621 // update our idea of which lines are shown when we redraw
4622 // the window the next time
4623 m_mainWin
->ResetVisibleLinesRange();
4625 if ( event
.GetOrientation() == wxHORIZONTAL
&& HasHeader() )
4627 m_headerWin
->Refresh();
4628 m_headerWin
->Update();
4631 // Let the window be scrolled as usual by the default handler.
4635 void wxGenericListCtrl::SetSingleStyle( long style
, bool add
)
4637 wxASSERT_MSG( !(style
& wxLC_VIRTUAL
),
4638 wxT("wxLC_VIRTUAL can't be [un]set") );
4640 long flag
= GetWindowStyle();
4644 if (style
& wxLC_MASK_TYPE
)
4645 flag
&= ~(wxLC_MASK_TYPE
| wxLC_VIRTUAL
);
4646 if (style
& wxLC_MASK_ALIGN
)
4647 flag
&= ~wxLC_MASK_ALIGN
;
4648 if (style
& wxLC_MASK_SORT
)
4649 flag
&= ~wxLC_MASK_SORT
;
4657 // some styles can be set without recreating everything (as happens in
4658 // SetWindowStyleFlag() which calls wxListMainWindow::DeleteEverything())
4659 if ( !(style
& ~(wxLC_HRULES
| wxLC_VRULES
)) )
4662 wxWindow::SetWindowStyleFlag(flag
);
4666 SetWindowStyleFlag( flag
);
4670 void wxGenericListCtrl::SetWindowStyleFlag( long flag
)
4672 // we add wxHSCROLL and wxVSCROLL in ctor unconditionally and it never
4673 // makes sense to remove them as we'll always add scrollbars anyhow when
4675 flag
|= wxHSCROLL
| wxVSCROLL
;
4677 const bool wasInReportView
= HasFlag(wxLC_REPORT
);
4679 // update the window style first so that the header is created or destroyed
4680 // corresponding to the new style
4681 wxWindow::SetWindowStyleFlag( flag
);
4685 const bool inReportView
= (flag
& wxLC_REPORT
) != 0;
4686 if ( inReportView
!= wasInReportView
)
4688 // we need to notify the main window about this change as it must
4689 // update its data structures
4690 m_mainWin
->SetReportView(inReportView
);
4693 // m_mainWin->DeleteEverything(); wxMSW doesn't do that
4695 CreateOrDestroyHeaderWindowAsNeeded();
4697 GetSizer()->Layout();
4701 bool wxGenericListCtrl::GetColumn(int col
, wxListItem
&item
) const
4703 m_mainWin
->GetColumn( col
, item
);
4707 bool wxGenericListCtrl::SetColumn( int col
, const wxListItem
& item
)
4709 m_mainWin
->SetColumn( col
, item
);
4713 int wxGenericListCtrl::GetColumnWidth( int col
) const
4715 return m_mainWin
->GetColumnWidth( col
);
4718 bool wxGenericListCtrl::SetColumnWidth( int col
, int width
)
4720 m_mainWin
->SetColumnWidth( col
, width
);
4724 int wxGenericListCtrl::GetCountPerPage() const
4726 return m_mainWin
->GetCountPerPage(); // different from Windows ?
4729 bool wxGenericListCtrl::GetItem( wxListItem
&info
) const
4731 m_mainWin
->GetItem( info
);
4735 bool wxGenericListCtrl::SetItem( wxListItem
&info
)
4737 m_mainWin
->SetItem( info
);
4741 long wxGenericListCtrl::SetItem( long index
, int col
, const wxString
& label
, int imageId
)
4744 info
.m_text
= label
;
4745 info
.m_mask
= wxLIST_MASK_TEXT
;
4746 info
.m_itemId
= index
;
4750 info
.m_image
= imageId
;
4751 info
.m_mask
|= wxLIST_MASK_IMAGE
;
4754 m_mainWin
->SetItem(info
);
4758 int wxGenericListCtrl::GetItemState( long item
, long stateMask
) const
4760 return m_mainWin
->GetItemState( item
, stateMask
);
4763 bool wxGenericListCtrl::SetItemState( long item
, long state
, long stateMask
)
4765 m_mainWin
->SetItemState( item
, state
, stateMask
);
4770 wxGenericListCtrl::SetItemImage( long item
, int image
, int WXUNUSED(selImage
) )
4772 return SetItemColumnImage(item
, 0, image
);
4776 wxGenericListCtrl::SetItemColumnImage( long item
, long column
, int image
)
4779 info
.m_image
= image
;
4780 info
.m_mask
= wxLIST_MASK_IMAGE
;
4781 info
.m_itemId
= item
;
4782 info
.m_col
= column
;
4783 m_mainWin
->SetItem( info
);
4787 wxString
wxGenericListCtrl::GetItemText( long item
, int col
) const
4789 return m_mainWin
->GetItemText(item
, col
);
4792 void wxGenericListCtrl::SetItemText( long item
, const wxString
& str
)
4794 m_mainWin
->SetItemText(item
, str
);
4797 wxUIntPtr
wxGenericListCtrl::GetItemData( long item
) const
4800 info
.m_mask
= wxLIST_MASK_DATA
;
4801 info
.m_itemId
= item
;
4802 m_mainWin
->GetItem( info
);
4806 bool wxGenericListCtrl::SetItemPtrData( long item
, wxUIntPtr data
)
4809 info
.m_mask
= wxLIST_MASK_DATA
;
4810 info
.m_itemId
= item
;
4812 m_mainWin
->SetItem( info
);
4816 wxRect
wxGenericListCtrl::GetViewRect() const
4818 return m_mainWin
->GetViewRect();
4821 bool wxGenericListCtrl::GetItemRect(long item
, wxRect
& rect
, int code
) const
4823 return GetSubItemRect(item
, wxLIST_GETSUBITEMRECT_WHOLEITEM
, rect
, code
);
4826 bool wxGenericListCtrl::GetSubItemRect(long item
,
4829 int WXUNUSED(code
)) const
4831 if ( !m_mainWin
->GetSubItemRect( item
, subItem
, rect
) )
4834 if ( m_mainWin
->HasHeader() )
4835 rect
.y
+= m_headerWin
->GetSize().y
+ 1;
4840 bool wxGenericListCtrl::GetItemPosition( long item
, wxPoint
& pos
) const
4842 m_mainWin
->GetItemPosition( item
, pos
);
4846 bool wxGenericListCtrl::SetItemPosition( long WXUNUSED(item
), const wxPoint
& WXUNUSED(pos
) )
4851 int wxGenericListCtrl::GetItemCount() const
4853 return m_mainWin
->GetItemCount();
4856 int wxGenericListCtrl::GetColumnCount() const
4858 return m_mainWin
->GetColumnCount();
4861 void wxGenericListCtrl::SetItemSpacing( int spacing
, bool isSmall
)
4863 m_mainWin
->SetItemSpacing( spacing
, isSmall
);
4866 wxSize
wxGenericListCtrl::GetItemSpacing() const
4868 const int spacing
= m_mainWin
->GetItemSpacing(HasFlag(wxLC_SMALL_ICON
));
4870 return wxSize(spacing
, spacing
);
4873 #if WXWIN_COMPATIBILITY_2_6
4874 int wxGenericListCtrl::GetItemSpacing( bool isSmall
) const
4876 return m_mainWin
->GetItemSpacing( isSmall
);
4878 #endif // WXWIN_COMPATIBILITY_2_6
4880 void wxGenericListCtrl::SetItemTextColour( long item
, const wxColour
&col
)
4883 info
.m_itemId
= item
;
4884 info
.SetTextColour( col
);
4885 m_mainWin
->SetItem( info
);
4888 wxColour
wxGenericListCtrl::GetItemTextColour( long item
) const
4891 info
.m_itemId
= item
;
4892 m_mainWin
->GetItem( info
);
4893 return info
.GetTextColour();
4896 void wxGenericListCtrl::SetItemBackgroundColour( long item
, const wxColour
&col
)
4899 info
.m_itemId
= item
;
4900 info
.SetBackgroundColour( col
);
4901 m_mainWin
->SetItem( info
);
4904 wxColour
wxGenericListCtrl::GetItemBackgroundColour( long item
) const
4907 info
.m_itemId
= item
;
4908 m_mainWin
->GetItem( info
);
4909 return info
.GetBackgroundColour();
4912 void wxGenericListCtrl::SetItemFont( long item
, const wxFont
&f
)
4915 info
.m_itemId
= item
;
4917 m_mainWin
->SetItem( info
);
4920 wxFont
wxGenericListCtrl::GetItemFont( long item
) const
4923 info
.m_itemId
= item
;
4924 m_mainWin
->GetItem( info
);
4925 return info
.GetFont();
4928 int wxGenericListCtrl::GetSelectedItemCount() const
4930 return m_mainWin
->GetSelectedItemCount();
4933 wxColour
wxGenericListCtrl::GetTextColour() const
4935 return GetForegroundColour();
4938 void wxGenericListCtrl::SetTextColour(const wxColour
& col
)
4940 SetForegroundColour(col
);
4943 long wxGenericListCtrl::GetTopItem() const
4946 m_mainWin
->GetVisibleLinesRange(&top
, NULL
);
4950 long wxGenericListCtrl::GetNextItem( long item
, int geom
, int state
) const
4952 return m_mainWin
->GetNextItem( item
, geom
, state
);
4955 wxImageList
*wxGenericListCtrl::GetImageList(int which
) const
4957 if (which
== wxIMAGE_LIST_NORMAL
)
4958 return m_imageListNormal
;
4959 else if (which
== wxIMAGE_LIST_SMALL
)
4960 return m_imageListSmall
;
4961 else if (which
== wxIMAGE_LIST_STATE
)
4962 return m_imageListState
;
4967 void wxGenericListCtrl::SetImageList( wxImageList
*imageList
, int which
)
4969 if ( which
== wxIMAGE_LIST_NORMAL
)
4971 if (m_ownsImageListNormal
)
4972 delete m_imageListNormal
;
4973 m_imageListNormal
= imageList
;
4974 m_ownsImageListNormal
= false;
4976 else if ( which
== wxIMAGE_LIST_SMALL
)
4978 if (m_ownsImageListSmall
)
4979 delete m_imageListSmall
;
4980 m_imageListSmall
= imageList
;
4981 m_ownsImageListSmall
= false;
4983 else if ( which
== wxIMAGE_LIST_STATE
)
4985 if (m_ownsImageListState
)
4986 delete m_imageListState
;
4987 m_imageListState
= imageList
;
4988 m_ownsImageListState
= false;
4991 m_mainWin
->SetImageList( imageList
, which
);
4994 void wxGenericListCtrl::AssignImageList(wxImageList
*imageList
, int which
)
4996 SetImageList(imageList
, which
);
4997 if ( which
== wxIMAGE_LIST_NORMAL
)
4998 m_ownsImageListNormal
= true;
4999 else if ( which
== wxIMAGE_LIST_SMALL
)
5000 m_ownsImageListSmall
= true;
5001 else if ( which
== wxIMAGE_LIST_STATE
)
5002 m_ownsImageListState
= true;
5005 bool wxGenericListCtrl::Arrange( int WXUNUSED(flag
) )
5010 bool wxGenericListCtrl::DeleteItem( long item
)
5012 m_mainWin
->DeleteItem( item
);
5016 bool wxGenericListCtrl::DeleteAllItems()
5018 m_mainWin
->DeleteAllItems();
5022 bool wxGenericListCtrl::DeleteAllColumns()
5024 size_t count
= m_mainWin
->m_columns
.GetCount();
5025 for ( size_t n
= 0; n
< count
; n
++ )
5030 void wxGenericListCtrl::ClearAll()
5032 m_mainWin
->DeleteEverything();
5035 bool wxGenericListCtrl::DeleteColumn( int col
)
5037 m_mainWin
->DeleteColumn( col
);
5039 // if we don't have the header any longer, we need to relayout the window
5040 // if ( !GetColumnCount() )
5043 // Ensure that the non-existent columns are really removed from display.
5049 wxTextCtrl
*wxGenericListCtrl::EditLabel(long item
,
5050 wxClassInfo
* textControlClass
)
5052 return m_mainWin
->EditLabel( item
, textControlClass
);
5055 wxTextCtrl
*wxGenericListCtrl::GetEditControl() const
5057 return m_mainWin
->GetEditControl();
5060 bool wxGenericListCtrl::EnsureVisible( long item
)
5062 m_mainWin
->EnsureVisible( item
);
5066 long wxGenericListCtrl::FindItem( long start
, const wxString
& str
, bool partial
)
5068 return m_mainWin
->FindItem( start
, str
, partial
);
5071 long wxGenericListCtrl::FindItem( long start
, wxUIntPtr data
)
5073 return m_mainWin
->FindItem( start
, data
);
5076 long wxGenericListCtrl::FindItem( long WXUNUSED(start
), const wxPoint
& pt
,
5077 int WXUNUSED(direction
))
5079 return m_mainWin
->FindItem( pt
);
5082 // TODO: sub item hit testing
5083 long wxGenericListCtrl::HitTest(const wxPoint
& point
, int& flags
, long *) const
5085 return m_mainWin
->HitTest( (int)point
.x
, (int)point
.y
, flags
);
5088 long wxGenericListCtrl::InsertItem( wxListItem
& info
)
5090 m_mainWin
->InsertItem( info
);
5091 return info
.m_itemId
;
5094 long wxGenericListCtrl::InsertItem( long index
, const wxString
&label
)
5097 info
.m_text
= label
;
5098 info
.m_mask
= wxLIST_MASK_TEXT
;
5099 info
.m_itemId
= index
;
5100 return InsertItem( info
);
5103 long wxGenericListCtrl::InsertItem( long index
, int imageIndex
)
5106 info
.m_mask
= wxLIST_MASK_IMAGE
;
5107 info
.m_image
= imageIndex
;
5108 info
.m_itemId
= index
;
5109 return InsertItem( info
);
5112 long wxGenericListCtrl::InsertItem( long index
, const wxString
&label
, int imageIndex
)
5115 info
.m_text
= label
;
5116 info
.m_image
= imageIndex
;
5117 info
.m_mask
= wxLIST_MASK_TEXT
;
5118 if (imageIndex
> -1)
5119 info
.m_mask
|= wxLIST_MASK_IMAGE
;
5120 info
.m_itemId
= index
;
5121 return InsertItem( info
);
5124 long wxGenericListCtrl::DoInsertColumn( long col
, const wxListItem
&item
)
5126 wxCHECK_MSG( InReportView(), -1, wxT("can't add column in non report mode") );
5128 long idx
= m_mainWin
->InsertColumn( col
, item
);
5130 // NOTE: if wxLC_NO_HEADER was given, then we are in report view mode but
5131 // still have m_headerWin==NULL
5133 m_headerWin
->Refresh();
5138 bool wxGenericListCtrl::ScrollList( int dx
, int dy
)
5140 return m_mainWin
->ScrollList(dx
, dy
);
5144 // fn is a function which takes 3 long arguments: item1, item2, data.
5145 // item1 is the long data associated with a first item (NOT the index).
5146 // item2 is the long data associated with a second item (NOT the index).
5147 // data is the same value as passed to SortItems.
5148 // The return value is a negative number if the first item should precede the second
5149 // item, a positive number of the second item should precede the first,
5150 // or zero if the two items are equivalent.
5151 // data is arbitrary data to be passed to the sort function.
5153 bool wxGenericListCtrl::SortItems( wxListCtrlCompare fn
, wxIntPtr data
)
5155 m_mainWin
->SortItems( fn
, data
);
5159 // ----------------------------------------------------------------------------
5161 // ----------------------------------------------------------------------------
5163 void wxGenericListCtrl::OnSize(wxSizeEvent
& WXUNUSED(event
))
5165 if (!m_mainWin
) return;
5167 // We need to override OnSize so that our scrolled
5168 // window a) does call Layout() to use sizers for
5169 // positioning the controls but b) does not query
5170 // the sizer for their size and use that for setting
5171 // the scrollable area as set that ourselves by
5172 // calling SetScrollbar() further down.
5176 m_mainWin
->RecalculatePositions();
5181 void wxGenericListCtrl::OnInternalIdle()
5183 wxWindow::OnInternalIdle();
5185 if (m_mainWin
->m_dirty
)
5186 m_mainWin
->RecalculatePositions();
5189 // ----------------------------------------------------------------------------
5191 // ----------------------------------------------------------------------------
5193 bool wxGenericListCtrl::SetBackgroundColour( const wxColour
&colour
)
5197 m_mainWin
->SetBackgroundColour( colour
);
5198 m_mainWin
->m_dirty
= true;
5204 bool wxGenericListCtrl::SetForegroundColour( const wxColour
&colour
)
5206 if ( !wxWindow::SetForegroundColour( colour
) )
5211 m_mainWin
->SetForegroundColour( colour
);
5212 m_mainWin
->m_dirty
= true;
5216 m_headerWin
->SetForegroundColour( colour
);
5221 bool wxGenericListCtrl::SetFont( const wxFont
&font
)
5223 if ( !wxWindow::SetFont( font
) )
5228 m_mainWin
->SetFont( font
);
5229 m_mainWin
->m_dirty
= true;
5234 m_headerWin
->SetFont( font
);
5235 // CalculateAndSetHeaderHeight();
5245 wxGenericListCtrl::GetClassDefaultAttributes(wxWindowVariant variant
)
5248 // Use the same color scheme as wxListBox
5249 return wxListBox::GetClassDefaultAttributes(variant
);
5251 wxUnusedVar(variant
);
5252 wxVisualAttributes attr
;
5253 attr
.colFg
= wxSystemSettings::GetColour(wxSYS_COLOUR_LISTBOXTEXT
);
5254 attr
.colBg
= wxSystemSettings::GetColour(wxSYS_COLOUR_LISTBOX
);
5255 attr
.font
= wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT
);
5260 // ----------------------------------------------------------------------------
5261 // methods forwarded to m_mainWin
5262 // ----------------------------------------------------------------------------
5264 #if wxUSE_DRAG_AND_DROP
5266 void wxGenericListCtrl::SetDropTarget( wxDropTarget
*dropTarget
)
5268 m_mainWin
->SetDropTarget( dropTarget
);
5271 wxDropTarget
*wxGenericListCtrl::GetDropTarget() const
5273 return m_mainWin
->GetDropTarget();
5278 bool wxGenericListCtrl::SetCursor( const wxCursor
&cursor
)
5280 return m_mainWin
? m_mainWin
->wxWindow::SetCursor(cursor
) : false;
5283 wxColour
wxGenericListCtrl::GetBackgroundColour() const
5285 return m_mainWin
? m_mainWin
->GetBackgroundColour() : wxColour();
5288 wxColour
wxGenericListCtrl::GetForegroundColour() const
5290 return m_mainWin
? m_mainWin
->GetForegroundColour() : wxColour();
5293 bool wxGenericListCtrl::DoPopupMenu( wxMenu
*menu
, int x
, int y
)
5296 return m_mainWin
->PopupMenu( menu
, x
, y
);
5302 wxSize
wxGenericListCtrl::DoGetBestClientSize() const
5304 // The base class version can compute the best size in report view only.
5305 wxSize sizeBest
= wxListCtrlBase::DoGetBestClientSize();
5307 if ( !InReportView() )
5309 // Ensure that our minimal width is at least big enough to show all our
5310 // items. This is important for wxListbook to size itself correctly.
5312 // Remember the offset of the first item: this corresponds to the
5313 // margins around the item so we will add it to the minimal size below
5314 // to ensure that we have equal margins on all sides.
5317 // We can iterate over all items as there shouldn't be too many of them
5318 // in non-report view. If it ever becomes a problem, we could examine
5319 // just the first few items probably, the determination of the best
5320 // size is less important if we will need scrollbars anyhow.
5321 for ( int n
= 0; n
< GetItemCount(); n
++ )
5323 const wxRect itemRect
= m_mainWin
->GetLineRect(n
);
5326 // Remember the position of the first item as all the rest are
5327 // offset by at least this number of pixels too.
5328 ofs
= itemRect
.GetPosition();
5331 sizeBest
.IncTo(itemRect
.GetSize());
5334 sizeBest
.IncBy(2*ofs
);
5337 // If we have the scrollbars we need to account for them too. And to
5338 // make sure the scrollbars status is up to date we need to call this
5339 // function to set them.
5340 m_mainWin
->RecalculatePositions(true /* no refresh */);
5342 // Unfortunately we can't use wxWindow::HasScrollbar() here as we need
5343 // to use m_mainWin client/virtual size for determination of whether we
5344 // use scrollbars and not the size of this window itself. Maybe that
5345 // function should be extended to work correctly in the case when our
5346 // scrollbars manage a different window from this one but currently it
5348 const wxSize sizeClient
= m_mainWin
->GetClientSize();
5349 const wxSize sizeVirt
= m_mainWin
->GetVirtualSize();
5351 if ( sizeVirt
.x
> sizeClient
.x
/* HasScrollbar(wxHORIZONTAL) */ )
5352 sizeBest
.y
+= wxSystemSettings::GetMetric(wxSYS_HSCROLL_Y
);
5354 if ( sizeVirt
.y
> sizeClient
.y
/* HasScrollbar(wxVERTICAL) */ )
5355 sizeBest
.x
+= wxSystemSettings::GetMetric(wxSYS_VSCROLL_X
);
5361 // ----------------------------------------------------------------------------
5362 // virtual list control support
5363 // ----------------------------------------------------------------------------
5365 wxString
wxGenericListCtrl::OnGetItemText(long WXUNUSED(item
), long WXUNUSED(col
)) const
5367 // this is a pure virtual function, in fact - which is not really pure
5368 // because the controls which are not virtual don't need to implement it
5369 wxFAIL_MSG( wxT("wxGenericListCtrl::OnGetItemText not supposed to be called") );
5371 return wxEmptyString
;
5374 int wxGenericListCtrl::OnGetItemImage(long WXUNUSED(item
)) const
5376 wxCHECK_MSG(!GetImageList(wxIMAGE_LIST_SMALL
),
5378 wxT("List control has an image list, OnGetItemImage or OnGetItemColumnImage should be overridden."));
5382 int wxGenericListCtrl::OnGetItemColumnImage(long item
, long column
) const
5385 return OnGetItemImage(item
);
5390 void wxGenericListCtrl::SetItemCount(long count
)
5392 wxASSERT_MSG( IsVirtual(), wxT("this is for virtual controls only") );
5394 m_mainWin
->SetItemCount(count
);
5397 void wxGenericListCtrl::RefreshItem(long item
)
5399 m_mainWin
->RefreshLine(item
);
5402 void wxGenericListCtrl::RefreshItems(long itemFrom
, long itemTo
)
5404 m_mainWin
->RefreshLines(itemFrom
, itemTo
);
5407 void wxGenericListCtrl::EnableBellOnNoMatch( bool on
)
5409 m_mainWin
->EnableBellOnNoMatch(on
);
5412 // Generic wxListCtrl is more or less a container for two other
5413 // windows which drawings are done upon. These are namely
5414 // 'm_headerWin' and 'm_mainWin'.
5415 // Here we override 'virtual wxWindow::Refresh()' to mimic the
5416 // behaviour wxListCtrl has under wxMSW.
5418 void wxGenericListCtrl::Refresh(bool eraseBackground
, const wxRect
*rect
)
5422 // The easy case, no rectangle specified.
5424 m_headerWin
->Refresh(eraseBackground
);
5427 m_mainWin
->Refresh(eraseBackground
);
5431 // Refresh the header window
5434 wxRect rectHeader
= m_headerWin
->GetRect();
5435 rectHeader
.Intersect(*rect
);
5436 if (rectHeader
.GetWidth() && rectHeader
.GetHeight())
5439 m_headerWin
->GetPosition(&x
, &y
);
5440 rectHeader
.Offset(-x
, -y
);
5441 m_headerWin
->Refresh(eraseBackground
, &rectHeader
);
5445 // Refresh the main window
5448 wxRect rectMain
= m_mainWin
->GetRect();
5449 rectMain
.Intersect(*rect
);
5450 if (rectMain
.GetWidth() && rectMain
.GetHeight())
5453 m_mainWin
->GetPosition(&x
, &y
);
5454 rectMain
.Offset(-x
, -y
);
5455 m_mainWin
->Refresh(eraseBackground
, &rectMain
);
5461 void wxGenericListCtrl::Update()
5465 if ( m_mainWin
->m_dirty
)
5466 m_mainWin
->RecalculatePositions();
5468 m_mainWin
->Update();
5472 m_headerWin
->Update();
5475 #endif // wxUSE_LISTCTRL