1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/generic/listctrl.cpp
3 // Purpose: generic implementation of wxListCtrl
4 // Author: Robert Roebling
5 // Vadim Zeitlin (virtual list control support)
7 // Copyright: (c) 1998 Robert Roebling
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
13 // 1. we need to implement searching/sorting for virtual controls somehow
14 // 2. when changing selection the lines are refreshed twice
17 // For compilers that support precompilation, includes "wx.h".
18 #include "wx/wxprec.h"
26 #include "wx/listctrl.h"
29 #include "wx/scrolwin.h"
31 #include "wx/settings.h"
32 #include "wx/dynarray.h"
33 #include "wx/dcclient.h"
34 #include "wx/dcscreen.h"
36 #include "wx/settings.h"
40 #include "wx/imaglist.h"
41 #include "wx/renderer.h"
42 #include "wx/generic/private/listctrl.h"
45 #include "wx/osx/private.h"
48 #if defined(__WXMSW__) && !defined(__WXWINCE__) && !defined(__WXUNIVERSAL__)
49 #define "wx/msw/wrapwin.h"
52 // NOTE: If using the wxListBox visual attributes works everywhere then this can
53 // be removed, as well as the #else case below.
54 #define _USE_VISATTR 0
57 // ----------------------------------------------------------------------------
59 // ----------------------------------------------------------------------------
61 // // the height of the header window (FIXME: should depend on its font!)
62 // static const int HEADER_HEIGHT = 23;
64 static const int SCROLL_UNIT_X
= 15;
66 // the spacing between the lines (in report mode)
67 static const int LINE_SPACING
= 0;
69 // extra margins around the text label
71 static const int EXTRA_WIDTH
= 6;
73 static const int EXTRA_WIDTH
= 4;
77 static const int EXTRA_HEIGHT
= 6;
79 static const int EXTRA_HEIGHT
= 4;
82 // margin between the window and the items
83 static const int EXTRA_BORDER_X
= 2;
84 static const int EXTRA_BORDER_Y
= 2;
86 // offset for the header window
87 static const int HEADER_OFFSET_X
= 0;
88 static const int HEADER_OFFSET_Y
= 0;
90 // margin between rows of icons in [small] icon view
91 static const int MARGIN_BETWEEN_ROWS
= 6;
93 // when autosizing the columns, add some slack
94 static const int AUTOSIZE_COL_MARGIN
= 10;
96 // default width for the header columns
97 static const int WIDTH_COL_DEFAULT
= 80;
99 // the space between the image and the text in the report mode
100 static const int IMAGE_MARGIN_IN_REPORT_MODE
= 5;
102 // the space between the image and the text in the report mode in header
103 static const int HEADER_IMAGE_MARGIN_IN_REPORT_MODE
= 2;
107 // ----------------------------------------------------------------------------
108 // arrays/list implementations
109 // ----------------------------------------------------------------------------
111 #include "wx/listimpl.cpp"
112 WX_DEFINE_LIST(wxListItemDataList
)
114 #include "wx/arrimpl.cpp"
115 WX_DEFINE_OBJARRAY(wxListLineDataArray
)
117 #include "wx/listimpl.cpp"
118 WX_DEFINE_LIST(wxListHeaderDataList
)
121 // ----------------------------------------------------------------------------
123 // ----------------------------------------------------------------------------
125 wxListItemData::~wxListItemData()
127 // in the virtual list control the attributes are managed by the main
128 // program, so don't delete them
129 if ( !m_owner
->IsVirtual() )
135 void wxListItemData::Init()
143 wxListItemData::wxListItemData(wxListMainWindow
*owner
)
149 if ( owner
->InReportView() )
155 void wxListItemData::SetItem( const wxListItem
&info
)
157 if ( info
.m_mask
& wxLIST_MASK_TEXT
)
158 SetText(info
.m_text
);
159 if ( info
.m_mask
& wxLIST_MASK_IMAGE
)
160 m_image
= info
.m_image
;
161 if ( info
.m_mask
& wxLIST_MASK_DATA
)
162 m_data
= info
.m_data
;
164 if ( info
.HasAttributes() )
167 m_attr
->AssignFrom(*info
.GetAttributes());
169 m_attr
= new wxListItemAttr(*info
.GetAttributes());
177 m_rect
->width
= info
.m_width
;
181 void wxListItemData::SetPosition( int x
, int y
)
183 wxCHECK_RET( m_rect
, wxT("unexpected SetPosition() call") );
189 void wxListItemData::SetSize( int width
, int height
)
191 wxCHECK_RET( m_rect
, wxT("unexpected SetSize() call") );
194 m_rect
->width
= width
;
196 m_rect
->height
= height
;
199 bool wxListItemData::IsHit( int x
, int y
) const
201 wxCHECK_MSG( m_rect
, false, wxT("can't be called in this mode") );
203 return wxRect(GetX(), GetY(), GetWidth(), GetHeight()).Contains(x
, y
);
206 int wxListItemData::GetX() const
208 wxCHECK_MSG( m_rect
, 0, wxT("can't be called in this mode") );
213 int wxListItemData::GetY() const
215 wxCHECK_MSG( m_rect
, 0, wxT("can't be called in this mode") );
220 int wxListItemData::GetWidth() const
222 wxCHECK_MSG( m_rect
, 0, wxT("can't be called in this mode") );
224 return m_rect
->width
;
227 int wxListItemData::GetHeight() const
229 wxCHECK_MSG( m_rect
, 0, wxT("can't be called in this mode") );
231 return m_rect
->height
;
234 void wxListItemData::GetItem( wxListItem
&info
) const
236 long mask
= info
.m_mask
;
238 // by default, get everything for backwards compatibility
241 if ( mask
& wxLIST_MASK_TEXT
)
242 info
.m_text
= m_text
;
243 if ( mask
& wxLIST_MASK_IMAGE
)
244 info
.m_image
= m_image
;
245 if ( mask
& wxLIST_MASK_DATA
)
246 info
.m_data
= m_data
;
250 if ( m_attr
->HasTextColour() )
251 info
.SetTextColour(m_attr
->GetTextColour());
252 if ( m_attr
->HasBackgroundColour() )
253 info
.SetBackgroundColour(m_attr
->GetBackgroundColour());
254 if ( m_attr
->HasFont() )
255 info
.SetFont(m_attr
->GetFont());
259 //-----------------------------------------------------------------------------
261 //-----------------------------------------------------------------------------
263 void wxListHeaderData::Init()
275 wxListHeaderData::wxListHeaderData()
280 wxListHeaderData::wxListHeaderData( const wxListItem
&item
)
287 void wxListHeaderData::SetItem( const wxListItem
&item
)
289 m_mask
= item
.m_mask
;
291 if ( m_mask
& wxLIST_MASK_TEXT
)
292 m_text
= item
.m_text
;
294 if ( m_mask
& wxLIST_MASK_IMAGE
)
295 m_image
= item
.m_image
;
297 if ( m_mask
& wxLIST_MASK_FORMAT
)
298 m_format
= item
.m_format
;
300 if ( m_mask
& wxLIST_MASK_WIDTH
)
301 SetWidth(item
.m_width
);
303 if ( m_mask
& wxLIST_MASK_STATE
)
304 SetState(item
.m_state
);
307 void wxListHeaderData::SetPosition( int x
, int y
)
313 void wxListHeaderData::SetHeight( int h
)
318 void wxListHeaderData::SetWidth( int w
)
320 m_width
= w
< 0 ? WIDTH_COL_DEFAULT
: w
;
323 void wxListHeaderData::SetState( int flag
)
328 void wxListHeaderData::SetFormat( int format
)
333 bool wxListHeaderData::HasImage() const
335 return m_image
!= -1;
338 bool wxListHeaderData::IsHit( int x
, int y
) const
340 return ((x
>= m_xpos
) && (x
<= m_xpos
+m_width
) && (y
>= m_ypos
) && (y
<= m_ypos
+m_height
));
343 void wxListHeaderData::GetItem( wxListItem
& item
)
345 long mask
= item
.m_mask
;
348 // by default, get everything for backwards compatibility
352 if ( mask
& wxLIST_MASK_STATE
)
353 item
.m_state
= m_state
;
354 if ( mask
& wxLIST_MASK_TEXT
)
355 item
.m_text
= m_text
;
356 if ( mask
& wxLIST_MASK_IMAGE
)
357 item
.m_image
= m_image
;
358 if ( mask
& wxLIST_MASK_WIDTH
)
359 item
.m_width
= m_width
;
360 if ( mask
& wxLIST_MASK_FORMAT
)
361 item
.m_format
= m_format
;
364 int wxListHeaderData::GetImage() const
369 int wxListHeaderData::GetWidth() const
374 int wxListHeaderData::GetFormat() const
379 int wxListHeaderData::GetState() const
384 //-----------------------------------------------------------------------------
386 //-----------------------------------------------------------------------------
388 inline int wxListLineData::GetMode() const
390 return m_owner
->GetListCtrl()->GetWindowStyleFlag() & wxLC_MASK_TYPE
;
393 inline bool wxListLineData::InReportView() const
395 return m_owner
->HasFlag(wxLC_REPORT
);
398 inline bool wxListLineData::IsVirtual() const
400 return m_owner
->IsVirtual();
403 wxListLineData::wxListLineData( wxListMainWindow
*owner
)
407 if ( InReportView() )
410 m_gi
= new GeometryInfo
;
412 m_highlighted
= false;
414 InitItems( GetMode() == wxLC_REPORT
? m_owner
->GetColumnCount() : 1 );
417 void wxListLineData::CalculateSize( wxDC
*dc
, int spacing
)
419 wxListItemDataList::compatibility_iterator node
= m_items
.GetFirst();
420 wxCHECK_RET( node
, wxT("no subitems at all??") );
422 wxListItemData
*item
= node
->GetData();
430 case wxLC_SMALL_ICON
:
431 m_gi
->m_rectAll
.width
= spacing
;
438 m_gi
->m_rectLabel
.width
=
439 m_gi
->m_rectLabel
.height
= 0;
443 dc
->GetTextExtent( s
, &lw
, &lh
);
447 m_gi
->m_rectAll
.height
= spacing
+ lh
;
449 m_gi
->m_rectAll
.width
= lw
;
451 m_gi
->m_rectLabel
.width
= lw
;
452 m_gi
->m_rectLabel
.height
= lh
;
455 if (item
->HasImage())
458 m_owner
->GetImageSize( item
->GetImage(), w
, h
);
459 m_gi
->m_rectIcon
.width
= w
+ 8;
460 m_gi
->m_rectIcon
.height
= h
+ 8;
462 if ( m_gi
->m_rectIcon
.width
> m_gi
->m_rectAll
.width
)
463 m_gi
->m_rectAll
.width
= m_gi
->m_rectIcon
.width
;
464 if ( m_gi
->m_rectIcon
.height
+ lh
> m_gi
->m_rectAll
.height
- 4 )
465 m_gi
->m_rectAll
.height
= m_gi
->m_rectIcon
.height
+ lh
+ 4;
468 if ( item
->HasText() )
470 m_gi
->m_rectHighlight
.width
= m_gi
->m_rectLabel
.width
;
471 m_gi
->m_rectHighlight
.height
= m_gi
->m_rectLabel
.height
;
473 else // no text, highlight the icon
475 m_gi
->m_rectHighlight
.width
= m_gi
->m_rectIcon
.width
;
476 m_gi
->m_rectHighlight
.height
= m_gi
->m_rectIcon
.height
;
481 s
= item
->GetTextForMeasuring();
483 dc
->GetTextExtent( s
, &lw
, &lh
);
487 m_gi
->m_rectLabel
.width
= lw
;
488 m_gi
->m_rectLabel
.height
= lh
;
490 m_gi
->m_rectAll
.width
= lw
;
491 m_gi
->m_rectAll
.height
= lh
;
493 if (item
->HasImage())
496 m_owner
->GetImageSize( item
->GetImage(), w
, h
);
497 m_gi
->m_rectIcon
.width
= w
;
498 m_gi
->m_rectIcon
.height
= h
;
500 m_gi
->m_rectAll
.width
+= 4 + w
;
501 if (h
> m_gi
->m_rectAll
.height
)
502 m_gi
->m_rectAll
.height
= h
;
505 m_gi
->m_rectHighlight
.width
= m_gi
->m_rectAll
.width
;
506 m_gi
->m_rectHighlight
.height
= m_gi
->m_rectAll
.height
;
510 wxFAIL_MSG( wxT("unexpected call to SetSize") );
514 wxFAIL_MSG( wxT("unknown mode") );
519 void wxListLineData::SetPosition( int x
, int y
, int spacing
)
521 wxListItemDataList::compatibility_iterator node
= m_items
.GetFirst();
522 wxCHECK_RET( node
, wxT("no subitems at all??") );
524 wxListItemData
*item
= node
->GetData();
529 case wxLC_SMALL_ICON
:
530 m_gi
->m_rectAll
.x
= x
;
531 m_gi
->m_rectAll
.y
= y
;
533 if ( item
->HasImage() )
535 m_gi
->m_rectIcon
.x
= m_gi
->m_rectAll
.x
+ 4 +
536 (m_gi
->m_rectAll
.width
- m_gi
->m_rectIcon
.width
) / 2;
537 m_gi
->m_rectIcon
.y
= m_gi
->m_rectAll
.y
+ 4;
540 if ( item
->HasText() )
542 if (m_gi
->m_rectAll
.width
> spacing
)
543 m_gi
->m_rectLabel
.x
= m_gi
->m_rectAll
.x
+ (EXTRA_WIDTH
/2);
545 m_gi
->m_rectLabel
.x
= m_gi
->m_rectAll
.x
+ (EXTRA_WIDTH
/2) + (spacing
/ 2) - (m_gi
->m_rectLabel
.width
/ 2);
546 m_gi
->m_rectLabel
.y
= m_gi
->m_rectAll
.y
+ m_gi
->m_rectAll
.height
+ 2 - m_gi
->m_rectLabel
.height
;
547 m_gi
->m_rectHighlight
.x
= m_gi
->m_rectLabel
.x
- 2;
548 m_gi
->m_rectHighlight
.y
= m_gi
->m_rectLabel
.y
- 2;
550 else // no text, highlight the icon
552 m_gi
->m_rectHighlight
.x
= m_gi
->m_rectIcon
.x
- 4;
553 m_gi
->m_rectHighlight
.y
= m_gi
->m_rectIcon
.y
- 4;
558 m_gi
->m_rectAll
.x
= x
;
559 m_gi
->m_rectAll
.y
= y
;
561 m_gi
->m_rectHighlight
.x
= m_gi
->m_rectAll
.x
;
562 m_gi
->m_rectHighlight
.y
= m_gi
->m_rectAll
.y
;
563 m_gi
->m_rectLabel
.y
= m_gi
->m_rectAll
.y
+ 2;
565 if (item
->HasImage())
567 m_gi
->m_rectIcon
.x
= m_gi
->m_rectAll
.x
+ 2;
568 m_gi
->m_rectIcon
.y
= m_gi
->m_rectAll
.y
+ 2;
569 m_gi
->m_rectLabel
.x
= m_gi
->m_rectAll
.x
+ 4 + (EXTRA_WIDTH
/2) + m_gi
->m_rectIcon
.width
;
573 m_gi
->m_rectLabel
.x
= m_gi
->m_rectAll
.x
+ (EXTRA_WIDTH
/2);
578 wxFAIL_MSG( wxT("unexpected call to SetPosition") );
582 wxFAIL_MSG( wxT("unknown mode") );
587 void wxListLineData::InitItems( int num
)
589 for (int i
= 0; i
< num
; i
++)
590 m_items
.Append( new wxListItemData(m_owner
) );
593 void wxListLineData::SetItem( int index
, const wxListItem
&info
)
595 wxListItemDataList::compatibility_iterator node
= m_items
.Item( index
);
596 wxCHECK_RET( node
, wxT("invalid column index in SetItem") );
598 wxListItemData
*item
= node
->GetData();
599 item
->SetItem( info
);
602 void wxListLineData::GetItem( int index
, wxListItem
&info
)
604 wxListItemDataList::compatibility_iterator node
= m_items
.Item( index
);
607 wxListItemData
*item
= node
->GetData();
608 item
->GetItem( info
);
612 wxString
wxListLineData::GetText(int index
) const
616 wxListItemDataList::compatibility_iterator node
= m_items
.Item( index
);
619 wxListItemData
*item
= node
->GetData();
626 void wxListLineData::SetText( int index
, const wxString
& s
)
628 wxListItemDataList::compatibility_iterator node
= m_items
.Item( index
);
631 wxListItemData
*item
= node
->GetData();
636 void wxListLineData::SetImage( int index
, int image
)
638 wxListItemDataList::compatibility_iterator node
= m_items
.Item( index
);
639 wxCHECK_RET( node
, wxT("invalid column index in SetImage()") );
641 wxListItemData
*item
= node
->GetData();
642 item
->SetImage(image
);
645 int wxListLineData::GetImage( int index
) const
647 wxListItemDataList::compatibility_iterator node
= m_items
.Item( index
);
648 wxCHECK_MSG( node
, -1, wxT("invalid column index in GetImage()") );
650 wxListItemData
*item
= node
->GetData();
651 return item
->GetImage();
654 wxListItemAttr
*wxListLineData::GetAttr() const
656 wxListItemDataList::compatibility_iterator node
= m_items
.GetFirst();
657 wxCHECK_MSG( node
, NULL
, wxT("invalid column index in GetAttr()") );
659 wxListItemData
*item
= node
->GetData();
660 return item
->GetAttr();
663 void wxListLineData::SetAttr(wxListItemAttr
*attr
)
665 wxListItemDataList::compatibility_iterator node
= m_items
.GetFirst();
666 wxCHECK_RET( node
, wxT("invalid column index in SetAttr()") );
668 wxListItemData
*item
= node
->GetData();
672 void wxListLineData::ApplyAttributes(wxDC
*dc
,
673 const wxRect
& rectHL
,
677 const wxListItemAttr
* const attr
= GetAttr();
679 wxWindow
* const listctrl
= m_owner
->GetParent();
681 const bool hasFocus
= listctrl
->HasFocus()
682 #if defined(__WXMAC__) && !defined(__WXUNIVERSAL__) && wxOSX_USE_CARBON
683 && IsControlActive( (ControlRef
)listctrl
->GetHandle() )
689 // don't use foreground colour for drawing highlighted items - this might
690 // make them completely invisible (and there is no way to do bit
691 // arithmetics on wxColour, unfortunately)
702 colText
= wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHTTEXT
);
704 colText
= wxSystemSettings::GetColour(wxSYS_COLOUR_LISTBOXHIGHLIGHTTEXT
);
707 else if ( attr
&& attr
->HasTextColour() )
708 colText
= attr
->GetTextColour();
710 colText
= listctrl
->GetForegroundColour();
712 dc
->SetTextForeground(colText
);
716 if ( attr
&& attr
->HasFont() )
717 font
= attr
->GetFont();
719 font
= listctrl
->GetFont();
726 // Use the renderer method to ensure that the selected items use the
728 int flags
= wxCONTROL_SELECTED
;
730 flags
|= wxCONTROL_FOCUSED
;
732 flags
|= wxCONTROL_CURRENT
;
733 wxRendererNative::Get().
734 DrawItemSelectionRect( m_owner
, *dc
, rectHL
, flags
);
736 else if ( attr
&& attr
->HasBackgroundColour() )
738 // Draw the background using the items custom background colour.
739 dc
->SetBrush(attr
->GetBackgroundColour());
740 dc
->SetPen(*wxTRANSPARENT_PEN
);
741 dc
->DrawRectangle(rectHL
);
744 // just for debugging to better see where the items are
746 dc
->SetPen(*wxRED_PEN
);
747 dc
->SetBrush(*wxTRANSPARENT_BRUSH
);
748 dc
->DrawRectangle( m_gi
->m_rectAll
);
749 dc
->SetPen(*wxGREEN_PEN
);
750 dc
->DrawRectangle( m_gi
->m_rectIcon
);
754 void wxListLineData::Draw(wxDC
*dc
, bool current
)
756 wxListItemDataList::compatibility_iterator node
= m_items
.GetFirst();
757 wxCHECK_RET( node
, wxT("no subitems at all??") );
759 ApplyAttributes(dc
, m_gi
->m_rectHighlight
, IsHighlighted(), current
);
761 wxListItemData
*item
= node
->GetData();
762 if (item
->HasImage())
764 // centre the image inside our rectangle, this looks nicer when items
765 // ae aligned in a row
766 const wxRect
& rectIcon
= m_gi
->m_rectIcon
;
768 m_owner
->DrawImage(item
->GetImage(), dc
, rectIcon
.x
, rectIcon
.y
);
773 const wxRect
& rectLabel
= m_gi
->m_rectLabel
;
775 wxDCClipper
clipper(*dc
, rectLabel
);
776 dc
->DrawText(item
->GetText(), rectLabel
.x
, rectLabel
.y
);
780 void wxListLineData::DrawInReportMode( wxDC
*dc
,
782 const wxRect
& rectHL
,
786 // TODO: later we should support setting different attributes for
787 // different columns - to do it, just add "col" argument to
788 // GetAttr() and move these lines into the loop below
790 ApplyAttributes(dc
, rectHL
, highlighted
, current
);
792 wxCoord x
= rect
.x
+ HEADER_OFFSET_X
,
793 yMid
= rect
.y
+ rect
.height
/2;
795 // This probably needs to be done
796 // on all platforms as the icons
797 // otherwise nearly touch the border
802 for ( wxListItemDataList::compatibility_iterator node
= m_items
.GetFirst();
804 node
= node
->GetNext(), col
++ )
806 wxListItemData
*item
= node
->GetData();
808 int width
= m_owner
->GetColumnWidth(col
);
813 const int wText
= width
;
814 wxDCClipper
clipper(*dc
, xOld
, rect
.y
, wText
, rect
.height
);
816 if ( item
->HasImage() )
819 m_owner
->GetImageSize( item
->GetImage(), ix
, iy
);
820 m_owner
->DrawImage( item
->GetImage(), dc
, xOld
, yMid
- iy
/2 );
822 ix
+= IMAGE_MARGIN_IN_REPORT_MODE
;
828 if ( item
->HasText() )
829 DrawTextFormatted(dc
, item
->GetText(), col
, xOld
, yMid
, width
);
833 void wxListLineData::DrawTextFormatted(wxDC
*dc
,
834 const wxString
& textOrig
,
840 // we don't support displaying multiple lines currently (and neither does
841 // wxMSW FWIW) so just merge all the lines
842 wxString
text(textOrig
);
843 text
.Replace(wxT("\n"), wxT(" "));
846 dc
->GetTextExtent(text
, &w
, &h
);
848 const wxCoord y
= yMid
- (h
+ 1)/2;
850 wxDCClipper
clipper(*dc
, x
, y
, width
, h
);
852 // determine if the string can fit inside the current width
855 // it can, draw it using the items alignment
857 m_owner
->GetColumn(col
, item
);
858 switch ( item
.GetAlign() )
860 case wxLIST_FORMAT_LEFT
:
864 case wxLIST_FORMAT_RIGHT
:
868 case wxLIST_FORMAT_CENTER
:
869 x
+= (width
- w
) / 2;
873 wxFAIL_MSG( wxT("unknown list item format") );
877 dc
->DrawText(text
, x
, y
);
879 else // otherwise, truncate and add an ellipsis if possible
881 // determine the base width
882 wxString
ellipsis(wxT("..."));
884 dc
->GetTextExtent(ellipsis
, &base_w
, &h
);
886 // continue until we have enough space or only one character left
888 size_t len
= text
.length();
889 wxString drawntext
= text
.Left(len
);
892 dc
->GetTextExtent(drawntext
.Last(), &w_c
, &h_c
);
893 drawntext
.RemoveLast();
896 if (w
+ base_w
<= width
)
900 // if still not enough space, remove ellipsis characters
901 while (ellipsis
.length() > 0 && w
+ base_w
> width
)
903 ellipsis
= ellipsis
.Left(ellipsis
.length() - 1);
904 dc
->GetTextExtent(ellipsis
, &base_w
, &h
);
908 dc
->DrawText(drawntext
, x
, y
);
909 dc
->DrawText(ellipsis
, x
+ w
, y
);
913 bool wxListLineData::Highlight( bool on
)
915 wxCHECK_MSG( !IsVirtual(), false, wxT("unexpected call to Highlight") );
917 if ( on
== m_highlighted
)
925 void wxListLineData::ReverseHighlight( void )
927 Highlight(!IsHighlighted());
930 //-----------------------------------------------------------------------------
931 // wxListHeaderWindow
932 //-----------------------------------------------------------------------------
934 BEGIN_EVENT_TABLE(wxListHeaderWindow
,wxWindow
)
935 EVT_PAINT (wxListHeaderWindow::OnPaint
)
936 EVT_MOUSE_EVENTS (wxListHeaderWindow::OnMouse
)
939 void wxListHeaderWindow::Init()
941 m_currentCursor
= NULL
;
942 m_isDragging
= false;
944 m_sendSetColumnWidth
= false;
947 wxListHeaderWindow::wxListHeaderWindow()
952 m_resizeCursor
= NULL
;
955 wxListHeaderWindow::wxListHeaderWindow( wxWindow
*win
,
957 wxListMainWindow
*owner
,
961 const wxString
&name
)
962 : wxWindow( win
, id
, pos
, size
, style
, name
)
967 m_resizeCursor
= new wxCursor( wxCURSOR_SIZEWE
);
970 wxVisualAttributes attr
= wxPanel::GetClassDefaultAttributes();
971 SetOwnForegroundColour( attr
.colFg
);
972 SetOwnBackgroundColour( attr
.colBg
);
974 SetOwnFont( attr
.font
);
976 SetOwnForegroundColour( wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT
));
977 SetOwnBackgroundColour( wxSystemSettings::GetColour(wxSYS_COLOUR_BTNFACE
));
979 SetOwnFont( wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT
));
983 wxListHeaderWindow::~wxListHeaderWindow()
985 delete m_resizeCursor
;
988 #ifdef __WXUNIVERSAL__
989 #include "wx/univ/renderer.h"
990 #include "wx/univ/theme.h"
993 // shift the DC origin to match the position of the main window horz
994 // scrollbar: this allows us to always use logical coords
995 void wxListHeaderWindow::AdjustDC(wxDC
& dc
)
997 wxGenericListCtrl
*parent
= m_owner
->GetListCtrl();
1000 parent
->GetScrollPixelsPerUnit( &xpix
, NULL
);
1003 parent
->GetViewStart( &view_start
, NULL
);
1008 dc
.GetDeviceOrigin( &org_x
, &org_y
);
1010 // account for the horz scrollbar offset
1012 if (GetLayoutDirection() == wxLayout_RightToLeft
)
1014 // Maybe we just have to check for m_signX
1015 // in the DC, but I leave the #ifdef __WXGTK__
1017 dc
.SetDeviceOrigin( org_x
+ (view_start
* xpix
), org_y
);
1021 dc
.SetDeviceOrigin( org_x
- (view_start
* xpix
), org_y
);
1024 void wxListHeaderWindow::OnPaint( wxPaintEvent
&WXUNUSED(event
) )
1026 wxGenericListCtrl
*parent
= m_owner
->GetListCtrl();
1028 wxPaintDC
dc( this );
1032 dc
.SetFont( GetFont() );
1034 // width and height of the entire header window
1036 GetClientSize( &w
, &h
);
1037 parent
->CalcUnscrolledPosition(w
, 0, &w
, NULL
);
1039 dc
.SetBackgroundMode(wxBRUSHSTYLE_TRANSPARENT
);
1040 dc
.SetTextForeground(GetForegroundColour());
1042 int x
= HEADER_OFFSET_X
;
1043 int numColumns
= m_owner
->GetColumnCount();
1045 for ( int i
= 0; i
< numColumns
&& x
< w
; i
++ )
1047 m_owner
->GetColumn( i
, item
);
1048 int wCol
= item
.m_width
;
1054 if (!m_parent
->IsEnabled())
1055 flags
|= wxCONTROL_DISABLED
;
1057 // NB: The code below is not really Mac-specific, but since we are close
1058 // to 2.8 release and I don't have time to test on other platforms, I
1059 // defined this only for wxMac. If this behaviour is desired on
1060 // other platforms, please go ahead and revise or remove the #ifdef.
1062 if ( !m_owner
->IsVirtual() && (item
.m_mask
& wxLIST_MASK_STATE
) &&
1063 (item
.m_state
& wxLIST_STATE_SELECTED
) )
1064 flags
|= wxCONTROL_SELECTED
;
1068 flags
|= wxCONTROL_SPECIAL
; // mark as first column
1070 wxRendererNative::Get().DrawHeaderButton
1074 wxRect(x
, HEADER_OFFSET_Y
, cw
, ch
),
1078 // see if we have enough space for the column label
1080 // for this we need the width of the text
1083 dc
.GetTextExtent(item
.GetText(), &wLabel
, &hLabel
);
1084 wLabel
+= 2 * EXTRA_WIDTH
;
1086 // and the width of the icon, if any
1087 int ix
= 0, iy
= 0; // init them just to suppress the compiler warnings
1088 const int image
= item
.m_image
;
1089 wxImageList
*imageList
;
1092 imageList
= m_owner
->GetSmallImageList();
1095 imageList
->GetSize(image
, ix
, iy
);
1096 wLabel
+= ix
+ HEADER_IMAGE_MARGIN_IN_REPORT_MODE
;
1104 // ignore alignment if there is not enough space anyhow
1106 switch ( wLabel
< cw
? item
.GetAlign() : wxLIST_FORMAT_LEFT
)
1109 wxFAIL_MSG( wxT("unknown list item format") );
1112 case wxLIST_FORMAT_LEFT
:
1116 case wxLIST_FORMAT_RIGHT
:
1117 xAligned
= x
+ cw
- wLabel
;
1120 case wxLIST_FORMAT_CENTER
:
1121 xAligned
= x
+ (cw
- wLabel
) / 2;
1125 // draw the text and image clipping them so that they
1126 // don't overwrite the column boundary
1127 wxDCClipper
clipper(dc
, x
, HEADER_OFFSET_Y
, cw
, h
);
1129 // if we have an image, draw it on the right of the label
1136 xAligned
+ wLabel
- ix
- HEADER_IMAGE_MARGIN_IN_REPORT_MODE
,
1137 HEADER_OFFSET_Y
+ (h
- iy
)/2,
1138 wxIMAGELIST_DRAW_TRANSPARENT
1142 dc
.DrawText( item
.GetText(),
1143 xAligned
+ EXTRA_WIDTH
, (h
- hLabel
) / 2 );
1148 // Fill in what's missing to the right of the columns, otherwise we will
1149 // leave an unpainted area when columns are removed (and it looks better)
1152 wxRendererNative::Get().DrawHeaderButton
1156 wxRect(x
, HEADER_OFFSET_Y
, w
- x
, h
),
1157 wxCONTROL_DIRTY
// mark as last column
1162 void wxListHeaderWindow::OnInternalIdle()
1164 wxWindow::OnInternalIdle();
1166 if (m_sendSetColumnWidth
)
1168 m_owner
->SetColumnWidth( m_colToSend
, m_widthToSend
);
1169 m_sendSetColumnWidth
= false;
1173 void wxListHeaderWindow::DrawCurrent()
1176 // m_owner->SetColumnWidth( m_column, m_currentX - m_minX );
1177 m_sendSetColumnWidth
= true;
1178 m_colToSend
= m_column
;
1179 m_widthToSend
= m_currentX
- m_minX
;
1181 int x1
= m_currentX
;
1183 m_owner
->ClientToScreen( &x1
, &y1
);
1185 int x2
= m_currentX
;
1187 m_owner
->GetClientSize( NULL
, &y2
);
1188 m_owner
->ClientToScreen( &x2
, &y2
);
1191 dc
.SetLogicalFunction( wxINVERT
);
1192 dc
.SetPen( wxPen(*wxBLACK
, 2) );
1193 dc
.SetBrush( *wxTRANSPARENT_BRUSH
);
1197 dc
.DrawLine( x1
, y1
, x2
, y2
);
1199 dc
.SetLogicalFunction( wxCOPY
);
1201 dc
.SetPen( wxNullPen
);
1202 dc
.SetBrush( wxNullBrush
);
1206 void wxListHeaderWindow::OnMouse( wxMouseEvent
&event
)
1208 wxGenericListCtrl
*parent
= m_owner
->GetListCtrl();
1210 // we want to work with logical coords
1212 parent
->CalcUnscrolledPosition(event
.GetX(), 0, &x
, NULL
);
1213 int y
= event
.GetY();
1217 SendListEvent(wxEVT_COMMAND_LIST_COL_DRAGGING
, event
.GetPosition());
1219 // we don't draw the line beyond our window, but we allow dragging it
1222 GetClientSize( &w
, NULL
);
1223 parent
->CalcUnscrolledPosition(w
, 0, &w
, NULL
);
1226 // erase the line if it was drawn
1227 if ( m_currentX
< w
)
1230 if (event
.ButtonUp())
1233 m_isDragging
= false;
1235 m_owner
->SetColumnWidth( m_column
, m_currentX
- m_minX
);
1236 SendListEvent(wxEVT_COMMAND_LIST_COL_END_DRAG
, event
.GetPosition());
1243 m_currentX
= m_minX
+ 7;
1245 // draw in the new location
1246 if ( m_currentX
< w
)
1250 else // not dragging
1253 bool hit_border
= false;
1255 // end of the current column
1258 // find the column where this event occurred
1260 countCol
= m_owner
->GetColumnCount();
1261 for (col
= 0; col
< countCol
; col
++)
1263 xpos
+= m_owner
->GetColumnWidth( col
);
1266 if ( (abs(x
-xpos
) < 3) && (y
< 22) )
1268 // near the column border
1275 // inside the column
1282 if ( col
== countCol
)
1285 if (event
.LeftDown() || event
.RightUp())
1287 if (hit_border
&& event
.LeftDown())
1289 if ( SendListEvent(wxEVT_COMMAND_LIST_COL_BEGIN_DRAG
,
1290 event
.GetPosition()) )
1292 m_isDragging
= true;
1297 //else: column resizing was vetoed by the user code
1299 else // click on a column
1301 // record the selected state of the columns
1302 if (event
.LeftDown())
1304 for (int i
=0; i
< m_owner
->GetColumnCount(); i
++)
1307 m_owner
->GetColumn(i
, colItem
);
1308 long state
= colItem
.GetState();
1310 colItem
.SetState(state
| wxLIST_STATE_SELECTED
);
1312 colItem
.SetState(state
& ~wxLIST_STATE_SELECTED
);
1313 m_owner
->SetColumn(i
, colItem
);
1317 SendListEvent( event
.LeftDown()
1318 ? wxEVT_COMMAND_LIST_COL_CLICK
1319 : wxEVT_COMMAND_LIST_COL_RIGHT_CLICK
,
1320 event
.GetPosition());
1323 else if (event
.Moving())
1328 setCursor
= m_currentCursor
== wxSTANDARD_CURSOR
;
1329 m_currentCursor
= m_resizeCursor
;
1333 setCursor
= m_currentCursor
!= wxSTANDARD_CURSOR
;
1334 m_currentCursor
= wxSTANDARD_CURSOR
;
1338 SetCursor(*m_currentCursor
);
1343 bool wxListHeaderWindow::SendListEvent(wxEventType type
, const wxPoint
& pos
)
1345 wxWindow
*parent
= GetParent();
1346 wxListEvent
le( type
, parent
->GetId() );
1347 le
.SetEventObject( parent
);
1348 le
.m_pointDrag
= pos
;
1350 // the position should be relative to the parent window, not
1351 // this one for compatibility with MSW and common sense: the
1352 // user code doesn't know anything at all about this header
1353 // window, so why should it get positions relative to it?
1354 le
.m_pointDrag
.y
-= GetSize().y
;
1356 le
.m_col
= m_column
;
1357 return !parent
->GetEventHandler()->ProcessEvent( le
) || le
.IsAllowed();
1360 //-----------------------------------------------------------------------------
1361 // wxListRenameTimer (internal)
1362 //-----------------------------------------------------------------------------
1364 wxListRenameTimer::wxListRenameTimer( wxListMainWindow
*owner
)
1369 void wxListRenameTimer::Notify()
1371 m_owner
->OnRenameTimer();
1374 //-----------------------------------------------------------------------------
1375 // wxListFindTimer (internal)
1376 //-----------------------------------------------------------------------------
1378 void wxListFindTimer::Notify()
1380 m_owner
->OnFindTimer();
1383 //-----------------------------------------------------------------------------
1384 // wxListTextCtrlWrapper (internal)
1385 //-----------------------------------------------------------------------------
1387 BEGIN_EVENT_TABLE(wxListTextCtrlWrapper
, wxEvtHandler
)
1388 EVT_CHAR (wxListTextCtrlWrapper::OnChar
)
1389 EVT_KEY_UP (wxListTextCtrlWrapper::OnKeyUp
)
1390 EVT_KILL_FOCUS (wxListTextCtrlWrapper::OnKillFocus
)
1393 wxListTextCtrlWrapper::wxListTextCtrlWrapper(wxListMainWindow
*owner
,
1396 : m_startValue(owner
->GetItemText(itemEdit
)),
1397 m_itemEdited(itemEdit
)
1401 m_aboutToFinish
= false;
1403 wxGenericListCtrl
*parent
= m_owner
->GetListCtrl();
1405 wxRect rectLabel
= owner
->GetLineLabelRect(itemEdit
);
1407 parent
->CalcScrolledPosition(rectLabel
.x
, rectLabel
.y
,
1408 &rectLabel
.x
, &rectLabel
.y
);
1410 m_text
->Create(owner
, wxID_ANY
, m_startValue
,
1411 wxPoint(rectLabel
.x
-4,rectLabel
.y
-4),
1412 wxSize(rectLabel
.width
+11,rectLabel
.height
+8));
1415 m_text
->PushEventHandler(this);
1418 void wxListTextCtrlWrapper::EndEdit(EndReason reason
)
1420 m_aboutToFinish
= true;
1425 // Notify the owner about the changes
1428 // Even if vetoed, close the control (consistent with MSW)
1433 m_owner
->OnRenameCancelled(m_itemEdited
);
1439 // Don't generate any notifications for the control being destroyed
1440 // and don't set focus to it neither.
1446 void wxListTextCtrlWrapper::Finish( bool setfocus
)
1448 m_text
->RemoveEventHandler(this);
1449 m_owner
->ResetTextControl( m_text
);
1451 wxPendingDelete
.Append( this );
1454 m_owner
->SetFocus();
1457 bool wxListTextCtrlWrapper::AcceptChanges()
1459 const wxString value
= m_text
->GetValue();
1461 // notice that we should always call OnRenameAccept() to generate the "end
1462 // label editing" event, even if the user hasn't really changed anything
1463 if ( !m_owner
->OnRenameAccept(m_itemEdited
, value
) )
1465 // vetoed by the user
1469 // accepted, do rename the item (unless nothing changed)
1470 if ( value
!= m_startValue
)
1471 m_owner
->SetItemText(m_itemEdited
, value
);
1476 void wxListTextCtrlWrapper::OnChar( wxKeyEvent
&event
)
1478 if ( !CheckForEndEditKey(event
) )
1482 bool wxListTextCtrlWrapper::CheckForEndEditKey(const wxKeyEvent
& event
)
1484 switch ( event
.m_keyCode
)
1487 EndEdit( End_Accept
);
1491 EndEdit( End_Discard
);
1501 void wxListTextCtrlWrapper::OnKeyUp( wxKeyEvent
&event
)
1503 if (m_aboutToFinish
)
1505 // auto-grow the textctrl:
1506 wxSize parentSize
= m_owner
->GetSize();
1507 wxPoint myPos
= m_text
->GetPosition();
1508 wxSize mySize
= m_text
->GetSize();
1510 m_text
->GetTextExtent(m_text
->GetValue() + wxT("MM"), &sx
, &sy
);
1511 if (myPos
.x
+ sx
> parentSize
.x
)
1512 sx
= parentSize
.x
- myPos
.x
;
1515 m_text
->SetSize(sx
, wxDefaultCoord
);
1521 void wxListTextCtrlWrapper::OnKillFocus( wxFocusEvent
&event
)
1523 if ( !m_aboutToFinish
)
1525 if ( !AcceptChanges() )
1526 m_owner
->OnRenameCancelled( m_itemEdited
);
1531 // We must let the native text control handle focus
1535 //-----------------------------------------------------------------------------
1537 //-----------------------------------------------------------------------------
1539 BEGIN_EVENT_TABLE(wxListMainWindow
, wxWindow
)
1540 EVT_PAINT (wxListMainWindow::OnPaint
)
1541 EVT_MOUSE_EVENTS (wxListMainWindow::OnMouse
)
1542 EVT_CHAR_HOOK (wxListMainWindow::OnCharHook
)
1543 EVT_CHAR (wxListMainWindow::OnChar
)
1544 EVT_KEY_DOWN (wxListMainWindow::OnKeyDown
)
1545 EVT_KEY_UP (wxListMainWindow::OnKeyUp
)
1546 EVT_SET_FOCUS (wxListMainWindow::OnSetFocus
)
1547 EVT_KILL_FOCUS (wxListMainWindow::OnKillFocus
)
1548 EVT_SCROLLWIN (wxListMainWindow::OnScroll
)
1549 EVT_CHILD_FOCUS (wxListMainWindow::OnChildFocus
)
1552 void wxListMainWindow::Init()
1557 m_lineTo
= (size_t)-1;
1563 m_small_image_list
= NULL
;
1564 m_normal_image_list
= NULL
;
1566 m_small_spacing
= 30;
1567 m_normal_spacing
= 40;
1571 m_isCreated
= false;
1573 m_lastOnSame
= false;
1574 m_renameTimer
= new wxListRenameTimer( this );
1576 m_findBell
= 0; // default is to not ring bell at all
1577 m_textctrlWrapper
= NULL
;
1581 m_lineSelectSingleOnUp
=
1582 m_lineBeforeLastClicked
= (size_t)-1;
1585 wxListMainWindow::wxListMainWindow()
1590 m_highlightUnfocusedBrush
= NULL
;
1593 wxListMainWindow::wxListMainWindow( wxWindow
*parent
,
1596 const wxSize
& size
)
1597 : wxWindow( parent
, id
, pos
, size
,
1598 wxWANTS_CHARS
| wxBORDER_NONE
)
1602 m_highlightBrush
= new wxBrush
1604 wxSystemSettings::GetColour
1606 wxSYS_COLOUR_HIGHLIGHT
1611 m_highlightUnfocusedBrush
= new wxBrush
1613 wxSystemSettings::GetColour
1615 wxSYS_COLOUR_BTNSHADOW
1620 wxVisualAttributes attr
= wxGenericListCtrl::GetClassDefaultAttributes();
1621 SetOwnForegroundColour( attr
.colFg
);
1622 SetOwnBackgroundColour( attr
.colBg
);
1624 SetOwnFont( attr
.font
);
1627 wxListMainWindow::~wxListMainWindow()
1629 if ( m_textctrlWrapper
)
1630 m_textctrlWrapper
->EndEdit(wxListTextCtrlWrapper::End_Destroy
);
1633 WX_CLEAR_LIST(wxListHeaderDataList
, m_columns
);
1634 WX_CLEAR_ARRAY(m_aColWidths
);
1636 delete m_highlightBrush
;
1637 delete m_highlightUnfocusedBrush
;
1638 delete m_renameTimer
;
1642 void wxListMainWindow::SetReportView(bool inReportView
)
1644 const size_t count
= m_lines
.size();
1645 for ( size_t n
= 0; n
< count
; n
++ )
1647 m_lines
[n
].SetReportView(inReportView
);
1651 void wxListMainWindow::CacheLineData(size_t line
)
1653 wxGenericListCtrl
*listctrl
= GetListCtrl();
1655 wxListLineData
*ld
= GetDummyLine();
1657 size_t countCol
= GetColumnCount();
1658 for ( size_t col
= 0; col
< countCol
; col
++ )
1660 ld
->SetText(col
, listctrl
->OnGetItemText(line
, col
));
1661 ld
->SetImage(col
, listctrl
->OnGetItemColumnImage(line
, col
));
1664 ld
->SetAttr(listctrl
->OnGetItemAttr(line
));
1667 wxListLineData
*wxListMainWindow::GetDummyLine() const
1669 wxASSERT_MSG( !IsEmpty(), wxT("invalid line index") );
1670 wxASSERT_MSG( IsVirtual(), wxT("GetDummyLine() shouldn't be called") );
1672 wxListMainWindow
*self
= wxConstCast(this, wxListMainWindow
);
1674 // we need to recreate the dummy line if the number of columns in the
1675 // control changed as it would have the incorrect number of fields
1677 if ( !m_lines
.IsEmpty() &&
1678 m_lines
[0].m_items
.GetCount() != (size_t)GetColumnCount() )
1680 self
->m_lines
.Clear();
1683 if ( m_lines
.IsEmpty() )
1685 wxListLineData
*line
= new wxListLineData(self
);
1686 self
->m_lines
.Add(line
);
1688 // don't waste extra memory -- there never going to be anything
1689 // else/more in this array
1690 self
->m_lines
.Shrink();
1696 // ----------------------------------------------------------------------------
1697 // line geometry (report mode only)
1698 // ----------------------------------------------------------------------------
1700 wxCoord
wxListMainWindow::GetLineHeight() const
1702 // we cache the line height as calling GetTextExtent() is slow
1703 if ( !m_lineHeight
)
1705 wxListMainWindow
*self
= wxConstCast(this, wxListMainWindow
);
1707 wxClientDC
dc( self
);
1708 dc
.SetFont( GetFont() );
1711 dc
.GetTextExtent(wxT("H"), NULL
, &y
);
1713 if ( m_small_image_list
&& m_small_image_list
->GetImageCount() )
1716 m_small_image_list
->GetSize(0, iw
, ih
);
1721 self
->m_lineHeight
= y
+ LINE_SPACING
;
1724 return m_lineHeight
;
1727 wxCoord
wxListMainWindow::GetLineY(size_t line
) const
1729 wxASSERT_MSG( InReportView(), wxT("only works in report mode") );
1731 return LINE_SPACING
+ line
* GetLineHeight();
1734 wxRect
wxListMainWindow::GetLineRect(size_t line
) const
1736 if ( !InReportView() )
1737 return GetLine(line
)->m_gi
->m_rectAll
;
1740 rect
.x
= HEADER_OFFSET_X
;
1741 rect
.y
= GetLineY(line
);
1742 rect
.width
= GetHeaderWidth();
1743 rect
.height
= GetLineHeight();
1748 wxRect
wxListMainWindow::GetLineLabelRect(size_t line
) const
1750 if ( !InReportView() )
1751 return GetLine(line
)->m_gi
->m_rectLabel
;
1754 wxListLineData
*data
= GetLine(line
);
1755 wxListItemDataList::compatibility_iterator node
= data
->m_items
.GetFirst();
1758 wxListItemData
*item
= node
->GetData();
1759 if ( item
->HasImage() )
1762 GetImageSize( item
->GetImage(), ix
, iy
);
1763 image_x
= 3 + ix
+ IMAGE_MARGIN_IN_REPORT_MODE
;
1768 rect
.x
= image_x
+ HEADER_OFFSET_X
;
1769 rect
.y
= GetLineY(line
);
1770 rect
.width
= GetColumnWidth(0) - image_x
;
1771 rect
.height
= GetLineHeight();
1776 wxRect
wxListMainWindow::GetLineIconRect(size_t line
) const
1778 if ( !InReportView() )
1779 return GetLine(line
)->m_gi
->m_rectIcon
;
1781 wxListLineData
*ld
= GetLine(line
);
1782 wxASSERT_MSG( ld
->HasImage(), wxT("should have an image") );
1785 rect
.x
= HEADER_OFFSET_X
;
1786 rect
.y
= GetLineY(line
);
1787 GetImageSize(ld
->GetImage(), rect
.width
, rect
.height
);
1792 wxRect
wxListMainWindow::GetLineHighlightRect(size_t line
) const
1794 return InReportView() ? GetLineRect(line
)
1795 : GetLine(line
)->m_gi
->m_rectHighlight
;
1798 long wxListMainWindow::HitTestLine(size_t line
, int x
, int y
) const
1800 wxASSERT_MSG( line
< GetItemCount(), wxT("invalid line in HitTestLine") );
1802 wxListLineData
*ld
= GetLine(line
);
1804 if ( ld
->HasImage() && GetLineIconRect(line
).Contains(x
, y
) )
1805 return wxLIST_HITTEST_ONITEMICON
;
1807 // VS: Testing for "ld->HasText() || InReportView()" instead of
1808 // "ld->HasText()" is needed to make empty lines in report view
1810 if ( ld
->HasText() || InReportView() )
1812 wxRect rect
= InReportView() ? GetLineRect(line
)
1813 : GetLineLabelRect(line
);
1815 if ( rect
.Contains(x
, y
) )
1816 return wxLIST_HITTEST_ONITEMLABEL
;
1822 // ----------------------------------------------------------------------------
1823 // highlight (selection) handling
1824 // ----------------------------------------------------------------------------
1826 bool wxListMainWindow::IsHighlighted(size_t line
) const
1830 return m_selStore
.IsSelected(line
);
1834 wxListLineData
*ld
= GetLine(line
);
1835 wxCHECK_MSG( ld
, false, wxT("invalid index in IsHighlighted") );
1837 return ld
->IsHighlighted();
1841 void wxListMainWindow::HighlightLines( size_t lineFrom
,
1847 wxArrayInt linesChanged
;
1848 if ( !m_selStore
.SelectRange(lineFrom
, lineTo
, highlight
,
1851 // meny items changed state, refresh everything
1852 RefreshLines(lineFrom
, lineTo
);
1854 else // only a few items changed state, refresh only them
1856 size_t count
= linesChanged
.GetCount();
1857 for ( size_t n
= 0; n
< count
; n
++ )
1859 RefreshLine(linesChanged
[n
]);
1863 else // iterate over all items in non report view
1865 for ( size_t line
= lineFrom
; line
<= lineTo
; line
++ )
1867 if ( HighlightLine(line
, highlight
) )
1873 bool wxListMainWindow::HighlightLine( size_t line
, bool highlight
)
1879 changed
= m_selStore
.SelectItem(line
, highlight
);
1883 wxListLineData
*ld
= GetLine(line
);
1884 wxCHECK_MSG( ld
, false, wxT("invalid index in HighlightLine") );
1886 changed
= ld
->Highlight(highlight
);
1891 SendNotify( line
, highlight
? wxEVT_COMMAND_LIST_ITEM_SELECTED
1892 : wxEVT_COMMAND_LIST_ITEM_DESELECTED
);
1898 void wxListMainWindow::RefreshLine( size_t line
)
1900 if ( InReportView() )
1902 size_t visibleFrom
, visibleTo
;
1903 GetVisibleLinesRange(&visibleFrom
, &visibleTo
);
1905 if ( line
< visibleFrom
|| line
> visibleTo
)
1909 wxRect rect
= GetLineRect(line
);
1911 GetListCtrl()->CalcScrolledPosition( rect
.x
, rect
.y
, &rect
.x
, &rect
.y
);
1912 RefreshRect( rect
);
1915 void wxListMainWindow::RefreshLines( size_t lineFrom
, size_t lineTo
)
1917 // we suppose that they are ordered by caller
1918 wxASSERT_MSG( lineFrom
<= lineTo
, wxT("indices in disorder") );
1920 wxASSERT_MSG( lineTo
< GetItemCount(), wxT("invalid line range") );
1922 if ( InReportView() )
1924 size_t visibleFrom
, visibleTo
;
1925 GetVisibleLinesRange(&visibleFrom
, &visibleTo
);
1927 if ( lineFrom
< visibleFrom
)
1928 lineFrom
= visibleFrom
;
1929 if ( lineTo
> visibleTo
)
1934 rect
.y
= GetLineY(lineFrom
);
1935 rect
.width
= GetClientSize().x
;
1936 rect
.height
= GetLineY(lineTo
) - rect
.y
+ GetLineHeight();
1938 GetListCtrl()->CalcScrolledPosition( rect
.x
, rect
.y
, &rect
.x
, &rect
.y
);
1939 RefreshRect( rect
);
1943 // TODO: this should be optimized...
1944 for ( size_t line
= lineFrom
; line
<= lineTo
; line
++ )
1951 void wxListMainWindow::RefreshAfter( size_t lineFrom
)
1953 if ( InReportView() )
1955 size_t visibleFrom
, visibleTo
;
1956 GetVisibleLinesRange(&visibleFrom
, &visibleTo
);
1958 if ( lineFrom
< visibleFrom
)
1959 lineFrom
= visibleFrom
;
1960 else if ( lineFrom
> visibleTo
)
1965 rect
.y
= GetLineY(lineFrom
);
1966 GetListCtrl()->CalcScrolledPosition( rect
.x
, rect
.y
, &rect
.x
, &rect
.y
);
1968 wxSize size
= GetClientSize();
1969 rect
.width
= size
.x
;
1971 // refresh till the bottom of the window
1972 rect
.height
= size
.y
- rect
.y
;
1974 RefreshRect( rect
);
1978 // TODO: how to do it more efficiently?
1983 void wxListMainWindow::RefreshSelected()
1989 if ( InReportView() )
1991 GetVisibleLinesRange(&from
, &to
);
1996 to
= GetItemCount() - 1;
1999 if ( HasCurrent() && m_current
>= from
&& m_current
<= to
)
2000 RefreshLine(m_current
);
2002 for ( size_t line
= from
; line
<= to
; line
++ )
2004 // NB: the test works as expected even if m_current == -1
2005 if ( line
!= m_current
&& IsHighlighted(line
) )
2010 void wxListMainWindow::OnPaint( wxPaintEvent
&WXUNUSED(event
) )
2012 // Note: a wxPaintDC must be constructed even if no drawing is
2013 // done (a Windows requirement).
2014 wxPaintDC
dc( this );
2018 // nothing to draw or not the moment to draw it
2023 RecalculatePositions( false );
2025 GetListCtrl()->PrepareDC( dc
);
2028 GetListCtrl()->CalcScrolledPosition( 0, 0, &dev_x
, &dev_y
);
2030 dc
.SetFont( GetFont() );
2032 if ( InReportView() )
2034 int lineHeight
= GetLineHeight();
2036 size_t visibleFrom
, visibleTo
;
2037 GetVisibleLinesRange(&visibleFrom
, &visibleTo
);
2040 int xOrig
= dc
.LogicalToDeviceX( 0 );
2041 int yOrig
= dc
.LogicalToDeviceY( 0 );
2043 // tell the caller cache to cache the data
2046 wxListEvent
evCache(wxEVT_COMMAND_LIST_CACHE_HINT
,
2047 GetParent()->GetId());
2048 evCache
.SetEventObject( GetParent() );
2049 evCache
.m_oldItemIndex
= visibleFrom
;
2050 evCache
.m_item
.m_itemId
=
2051 evCache
.m_itemIndex
= visibleTo
;
2052 GetParent()->GetEventHandler()->ProcessEvent( evCache
);
2055 for ( size_t line
= visibleFrom
; line
<= visibleTo
; line
++ )
2057 rectLine
= GetLineRect(line
);
2060 if ( !IsExposed(rectLine
.x
+ xOrig
, rectLine
.y
+ yOrig
,
2061 rectLine
.width
, rectLine
.height
) )
2063 // don't redraw unaffected lines to avoid flicker
2067 GetLine(line
)->DrawInReportMode( &dc
,
2069 GetLineHighlightRect(line
),
2070 IsHighlighted(line
),
2071 line
== m_current
);
2074 if ( HasFlag(wxLC_HRULES
) )
2076 wxPen
pen(GetRuleColour(), 1, wxPENSTYLE_SOLID
);
2077 wxSize clientSize
= GetClientSize();
2079 size_t i
= visibleFrom
;
2080 if (i
== 0) i
= 1; // Don't draw the first one
2081 for ( ; i
<= visibleTo
; i
++ )
2084 dc
.SetBrush( *wxTRANSPARENT_BRUSH
);
2085 dc
.DrawLine(0 - dev_x
, i
* lineHeight
,
2086 clientSize
.x
- dev_x
, i
* lineHeight
);
2089 // Draw last horizontal rule
2090 if ( visibleTo
== GetItemCount() - 1 )
2093 dc
.SetBrush( *wxTRANSPARENT_BRUSH
);
2094 dc
.DrawLine(0 - dev_x
, (m_lineTo
+ 1) * lineHeight
,
2095 clientSize
.x
- dev_x
, (m_lineTo
+ 1) * lineHeight
);
2099 // Draw vertical rules if required
2100 if ( HasFlag(wxLC_VRULES
) && !IsEmpty() )
2102 wxPen
pen(GetRuleColour(), 1, wxPENSTYLE_SOLID
);
2103 wxRect firstItemRect
, lastItemRect
;
2105 GetItemRect(visibleFrom
, firstItemRect
);
2106 GetItemRect(visibleTo
, lastItemRect
);
2107 int x
= firstItemRect
.GetX();
2109 dc
.SetBrush(* wxTRANSPARENT_BRUSH
);
2111 for (int col
= 0; col
< GetColumnCount(); col
++)
2113 int colWidth
= GetColumnWidth(col
);
2115 int x_pos
= x
- dev_x
;
2116 if (col
< GetColumnCount()-1) x_pos
-= 2;
2117 dc
.DrawLine(x_pos
, firstItemRect
.GetY() - 1 - dev_y
,
2118 x_pos
, lastItemRect
.GetBottom() + 1 - dev_y
);
2124 size_t count
= GetItemCount();
2125 for ( size_t i
= 0; i
< count
; i
++ )
2127 GetLine(i
)->Draw( &dc
, i
== m_current
);
2131 // DrawFocusRect() is unusable under Mac, it draws outside of the highlight
2132 // rectangle somehow and so leaves traces when the item is not selected any
2133 // more, see #12229.
2138 if ( IsHighlighted(m_current
) )
2139 flags
|= wxCONTROL_SELECTED
;
2141 wxRendererNative::Get().
2142 DrawFocusRect(this, dc
, GetLineHighlightRect(m_current
), flags
);
2144 #endif // !__WXMAC__
2147 void wxListMainWindow::HighlightAll( bool on
)
2149 if ( IsSingleSel() )
2151 wxASSERT_MSG( !on
, wxT("can't do this in a single selection control") );
2153 // we just have one item to turn off
2154 if ( HasCurrent() && IsHighlighted(m_current
) )
2156 HighlightLine(m_current
, false);
2157 RefreshLine(m_current
);
2160 else // multi selection
2163 HighlightLines(0, GetItemCount() - 1, on
);
2167 void wxListMainWindow::OnChildFocus(wxChildFocusEvent
& WXUNUSED(event
))
2169 // Do nothing here. This prevents the default handler in wxScrolledWindow
2170 // from needlessly scrolling the window when the edit control is
2171 // dismissed. See ticket #9563.
2174 void wxListMainWindow::SendNotify( size_t line
,
2175 wxEventType command
,
2176 const wxPoint
& point
)
2178 wxListEvent
le( command
, GetParent()->GetId() );
2179 le
.SetEventObject( GetParent() );
2181 le
.m_item
.m_itemId
=
2182 le
.m_itemIndex
= line
;
2184 // set only for events which have position
2185 if ( point
!= wxDefaultPosition
)
2186 le
.m_pointDrag
= point
;
2188 // don't try to get the line info for virtual list controls: the main
2189 // program has it anyhow and if we did it would result in accessing all
2190 // the lines, even those which are not visible now and this is precisely
2191 // what we're trying to avoid
2194 if ( line
!= (size_t)-1 )
2196 GetLine(line
)->GetItem( 0, le
.m_item
);
2198 //else: this happens for wxEVT_COMMAND_LIST_ITEM_FOCUSED event
2200 //else: there may be no more such item
2202 GetParent()->GetEventHandler()->ProcessEvent( le
);
2205 void wxListMainWindow::ChangeCurrent(size_t current
)
2207 m_current
= current
;
2209 // as the current item changed, we shouldn't start editing it when the
2210 // "slow click" timer expires as the click happened on another item
2211 if ( m_renameTimer
->IsRunning() )
2212 m_renameTimer
->Stop();
2214 SendNotify(current
, wxEVT_COMMAND_LIST_ITEM_FOCUSED
);
2217 wxTextCtrl
*wxListMainWindow::EditLabel(long item
, wxClassInfo
* textControlClass
)
2219 wxCHECK_MSG( (item
>= 0) && ((size_t)item
< GetItemCount()), NULL
,
2220 wxT("wrong index in wxGenericListCtrl::EditLabel()") );
2222 wxASSERT_MSG( textControlClass
->IsKindOf(wxCLASSINFO(wxTextCtrl
)),
2223 wxT("EditLabel() needs a text control") );
2225 size_t itemEdit
= (size_t)item
;
2227 wxListEvent
le( wxEVT_COMMAND_LIST_BEGIN_LABEL_EDIT
, GetParent()->GetId() );
2228 le
.SetEventObject( GetParent() );
2229 le
.m_item
.m_itemId
=
2230 le
.m_itemIndex
= item
;
2231 wxListLineData
*data
= GetLine(itemEdit
);
2232 wxCHECK_MSG( data
, NULL
, wxT("invalid index in EditLabel()") );
2233 data
->GetItem( 0, le
.m_item
);
2235 if ( GetParent()->GetEventHandler()->ProcessEvent( le
) && !le
.IsAllowed() )
2237 // vetoed by user code
2243 // Ensure the display is updated before we start editing.
2247 wxTextCtrl
* const text
= (wxTextCtrl
*)textControlClass
->CreateObject();
2248 m_textctrlWrapper
= new wxListTextCtrlWrapper(this, text
, item
);
2249 return m_textctrlWrapper
->GetText();
2252 void wxListMainWindow::OnRenameTimer()
2254 wxCHECK_RET( HasCurrent(), wxT("unexpected rename timer") );
2256 EditLabel( m_current
);
2259 bool wxListMainWindow::OnRenameAccept(size_t itemEdit
, const wxString
& value
)
2261 wxListEvent
le( wxEVT_COMMAND_LIST_END_LABEL_EDIT
, GetParent()->GetId() );
2262 le
.SetEventObject( GetParent() );
2263 le
.m_item
.m_itemId
=
2264 le
.m_itemIndex
= itemEdit
;
2266 wxListLineData
*data
= GetLine(itemEdit
);
2268 wxCHECK_MSG( data
, false, wxT("invalid index in OnRenameAccept()") );
2270 data
->GetItem( 0, le
.m_item
);
2271 le
.m_item
.m_text
= value
;
2272 return !GetParent()->GetEventHandler()->ProcessEvent( le
) ||
2276 void wxListMainWindow::OnRenameCancelled(size_t itemEdit
)
2278 // let owner know that the edit was cancelled
2279 wxListEvent
le( wxEVT_COMMAND_LIST_END_LABEL_EDIT
, GetParent()->GetId() );
2281 le
.SetEditCanceled(true);
2283 le
.SetEventObject( GetParent() );
2284 le
.m_item
.m_itemId
=
2285 le
.m_itemIndex
= itemEdit
;
2287 wxListLineData
*data
= GetLine(itemEdit
);
2288 wxCHECK_RET( data
, wxT("invalid index in OnRenameCancelled()") );
2290 data
->GetItem( 0, le
.m_item
);
2291 GetEventHandler()->ProcessEvent( le
);
2294 void wxListMainWindow::OnFindTimer()
2296 m_findPrefix
.clear();
2301 void wxListMainWindow::EnableBellOnNoMatch( bool on
)
2306 void wxListMainWindow::OnMouse( wxMouseEvent
&event
)
2309 // On wxMac we can't depend on the EVT_KILL_FOCUS event to properly
2310 // shutdown the edit control when the mouse is clicked elsewhere on the
2311 // listctrl because the order of events is different (or something like
2312 // that), so explicitly end the edit if it is active.
2313 if ( event
.LeftDown() && m_textctrlWrapper
)
2314 m_textctrlWrapper
->EndEdit(wxListTextCtrlWrapper::End_Accept
);
2317 if ( event
.LeftDown() )
2319 // Ensure we skip the event to let the system set focus to this window.
2323 // Pretend that the event happened in wxListCtrl itself.
2324 wxMouseEvent
me(event
);
2325 me
.SetEventObject( GetParent() );
2326 me
.SetId(GetParent()->GetId());
2327 if ( GetParent()->GetEventHandler()->ProcessEvent( me
))
2330 if (event
.GetEventType() == wxEVT_MOUSEWHEEL
)
2332 // let the base class handle mouse wheel events.
2337 if ( !HasCurrent() || IsEmpty() )
2339 if (event
.RightDown())
2341 SendNotify( (size_t)-1, wxEVT_COMMAND_LIST_ITEM_RIGHT_CLICK
, event
.GetPosition() );
2343 wxContextMenuEvent
evtCtx(wxEVT_CONTEXT_MENU
,
2344 GetParent()->GetId(),
2345 ClientToScreen(event
.GetPosition()));
2346 evtCtx
.SetEventObject(GetParent());
2347 GetParent()->GetEventHandler()->ProcessEvent(evtCtx
);
2355 if ( !(event
.Dragging() || event
.ButtonDown() || event
.LeftUp() ||
2356 event
.ButtonDClick()) )
2359 int x
= event
.GetX();
2360 int y
= event
.GetY();
2361 GetListCtrl()->CalcUnscrolledPosition( x
, y
, &x
, &y
);
2363 // where did we hit it (if we did)?
2366 size_t count
= GetItemCount(),
2369 if ( InReportView() )
2371 current
= y
/ GetLineHeight();
2372 if ( current
< count
)
2373 hitResult
= HitTestLine(current
, x
, y
);
2377 // TODO: optimize it too! this is less simple than for report view but
2378 // enumerating all items is still not a way to do it!!
2379 for ( current
= 0; current
< count
; current
++ )
2381 hitResult
= HitTestLine(current
, x
, y
);
2387 // Update drag events counter first as we must do it even if the mouse is
2388 // not on any item right now as we must keep count in case we started
2389 // dragging from the empty control area but continued to do it over a valid
2390 // item -- in this situation we must not start dragging this item.
2391 if (event
.Dragging())
2396 // The only mouse event that can be generated without any valid item is
2397 // wxEVT_COMMAND_LIST_ITEM_RIGHT_CLICK as it can be useful to have a global
2398 // popup menu for the list control itself which should be shown even when
2399 // the user clicks outside of any item.
2402 // outside of any item
2403 if (event
.RightDown())
2405 SendNotify( (size_t) -1, wxEVT_COMMAND_LIST_ITEM_RIGHT_CLICK
, event
.GetPosition() );
2407 wxContextMenuEvent
evtCtx(
2409 GetParent()->GetId(),
2410 ClientToScreen(event
.GetPosition()));
2411 evtCtx
.SetEventObject(GetParent());
2412 GetParent()->GetEventHandler()->ProcessEvent(evtCtx
);
2416 // reset the selection and bail out
2417 HighlightAll(false);
2423 if ( event
.Dragging() )
2425 if (m_dragCount
== 1)
2427 // we have to report the raw, physical coords as we want to be
2428 // able to call HitTest(event.m_pointDrag) from the user code to
2429 // get the item being dragged
2430 m_dragStart
= event
.GetPosition();
2433 if (m_dragCount
!= 3)
2436 int command
= event
.RightIsDown() ? wxEVT_COMMAND_LIST_BEGIN_RDRAG
2437 : wxEVT_COMMAND_LIST_BEGIN_DRAG
;
2439 SendNotify( m_lineLastClicked
, command
, m_dragStart
);
2444 bool forceClick
= false;
2445 if (event
.ButtonDClick())
2447 if ( m_renameTimer
->IsRunning() )
2448 m_renameTimer
->Stop();
2450 m_lastOnSame
= false;
2452 if ( current
== m_lineLastClicked
)
2454 SendNotify( current
, wxEVT_COMMAND_LIST_ITEM_ACTIVATED
);
2460 // The first click was on another item, so don't interpret this as
2461 // a double click, but as a simple click instead
2468 if (m_lineSelectSingleOnUp
!= (size_t)-1)
2470 // select single line
2471 HighlightAll( false );
2472 ReverseHighlight(m_lineSelectSingleOnUp
);
2477 if ((current
== m_current
) &&
2478 (hitResult
== wxLIST_HITTEST_ONITEMLABEL
) &&
2479 HasFlag(wxLC_EDIT_LABELS
) )
2481 if ( !InReportView() ||
2482 GetLineLabelRect(current
).Contains(x
, y
) )
2484 int dclick
= wxSystemSettings::GetMetric(wxSYS_DCLICK_MSEC
);
2485 m_renameTimer
->Start(dclick
> 0 ? dclick
: 250, true);
2489 m_lastOnSame
= false;
2492 m_lineSelectSingleOnUp
= (size_t)-1;
2496 // This is necessary, because after a DnD operation in
2497 // from and to ourself, the up event is swallowed by the
2498 // DnD code. So on next non-up event (which means here and
2499 // now) m_lineSelectSingleOnUp should be reset.
2500 m_lineSelectSingleOnUp
= (size_t)-1;
2502 if (event
.RightDown())
2504 m_lineBeforeLastClicked
= m_lineLastClicked
;
2505 m_lineLastClicked
= current
;
2507 // If the item is already selected, do not update the selection.
2508 // Multi-selections should not be cleared if a selected item is clicked.
2509 if (!IsHighlighted(current
))
2511 HighlightAll(false);
2512 ChangeCurrent(current
);
2513 ReverseHighlight(m_current
);
2516 SendNotify( current
, wxEVT_COMMAND_LIST_ITEM_RIGHT_CLICK
, event
.GetPosition() );
2518 // Allow generation of context menu event
2521 else if (event
.MiddleDown())
2523 SendNotify( current
, wxEVT_COMMAND_LIST_ITEM_MIDDLE_CLICK
);
2525 else if ( event
.LeftDown() || forceClick
)
2527 m_lineBeforeLastClicked
= m_lineLastClicked
;
2528 m_lineLastClicked
= current
;
2530 size_t oldCurrent
= m_current
;
2531 bool oldWasSelected
= IsHighlighted(m_current
);
2533 bool cmdModifierDown
= event
.CmdDown();
2534 if ( IsSingleSel() || !(cmdModifierDown
|| event
.ShiftDown()) )
2536 if ( IsSingleSel() || !IsHighlighted(current
) )
2538 HighlightAll( false );
2540 ChangeCurrent(current
);
2542 ReverseHighlight(m_current
);
2544 else // multi sel & current is highlighted & no mod keys
2546 m_lineSelectSingleOnUp
= current
;
2547 ChangeCurrent(current
); // change focus
2550 else // multi sel & either ctrl or shift is down
2552 if (cmdModifierDown
)
2554 ChangeCurrent(current
);
2556 ReverseHighlight(m_current
);
2558 else if (event
.ShiftDown())
2560 ChangeCurrent(current
);
2562 size_t lineFrom
= oldCurrent
,
2565 if ( lineTo
< lineFrom
)
2568 lineFrom
= m_current
;
2571 HighlightLines(lineFrom
, lineTo
);
2573 else // !ctrl, !shift
2575 // test in the enclosing if should make it impossible
2576 wxFAIL_MSG( wxT("how did we get here?") );
2580 if (m_current
!= oldCurrent
)
2581 RefreshLine( oldCurrent
);
2583 // Set the flag telling us whether the next click on this item should
2584 // start editing its label. This should happen if we clicked on the
2585 // current item and it was already selected, i.e. if this click was not
2586 // done to select it.
2588 // It should not happen if this was a double click (forceClick is true)
2589 // nor if we hadn't had the focus before as then this click was used to
2590 // give focus to the control.
2591 m_lastOnSame
= (m_current
== oldCurrent
) && oldWasSelected
&&
2592 !forceClick
&& HasFocus();
2596 void wxListMainWindow::MoveToItem(size_t item
)
2598 if ( item
== (size_t)-1 )
2601 wxRect rect
= GetLineRect(item
);
2603 int client_w
, client_h
;
2604 GetClientSize( &client_w
, &client_h
);
2606 const int hLine
= GetLineHeight();
2608 int view_x
= SCROLL_UNIT_X
* GetListCtrl()->GetScrollPos( wxHORIZONTAL
);
2609 int view_y
= hLine
* GetListCtrl()->GetScrollPos( wxVERTICAL
);
2611 if ( InReportView() )
2613 // the next we need the range of lines shown it might be different,
2614 // so recalculate it
2615 ResetVisibleLinesRange();
2617 if (rect
.y
< view_y
)
2618 GetListCtrl()->Scroll( -1, rect
.y
/ hLine
);
2619 if (rect
.y
+ rect
.height
+ 5 > view_y
+ client_h
)
2620 GetListCtrl()->Scroll( -1, (rect
.y
+ rect
.height
- client_h
+ hLine
) / hLine
);
2623 // At least on Mac the visible lines value will get reset inside of
2624 // Scroll *before* it actually scrolls the window because of the
2625 // Update() that happens there, so it will still have the wrong value.
2626 // So let's reset it again and wait for it to be recalculated in the
2627 // next paint event. I would expect this problem to show up in wxGTK
2628 // too but couldn't duplicate it there. Perhaps the order of events
2629 // is different... --Robin
2630 ResetVisibleLinesRange();
2638 if (rect
.x
-view_x
< 5)
2639 sx
= (rect
.x
- 5) / SCROLL_UNIT_X
;
2640 if (rect
.x
+ rect
.width
- 5 > view_x
+ client_w
)
2641 sx
= (rect
.x
+ rect
.width
- client_w
+ SCROLL_UNIT_X
) / SCROLL_UNIT_X
;
2643 if (rect
.y
-view_y
< 5)
2644 sy
= (rect
.y
- 5) / hLine
;
2645 if (rect
.y
+ rect
.height
- 5 > view_y
+ client_h
)
2646 sy
= (rect
.y
+ rect
.height
- client_h
+ hLine
) / hLine
;
2648 GetListCtrl()->Scroll(sx
, sy
);
2652 bool wxListMainWindow::ScrollList(int WXUNUSED(dx
), int dy
)
2654 if ( !InReportView() )
2656 // TODO: this should work in all views but is not implemented now
2661 GetVisibleLinesRange(&top
, &bottom
);
2663 if ( bottom
== (size_t)-1 )
2666 ResetVisibleLinesRange();
2668 int hLine
= GetLineHeight();
2670 GetListCtrl()->Scroll(-1, top
+ dy
/ hLine
);
2673 // see comment in MoveToItem() for why we do this
2674 ResetVisibleLinesRange();
2680 // ----------------------------------------------------------------------------
2681 // keyboard handling
2682 // ----------------------------------------------------------------------------
2684 void wxListMainWindow::OnArrowChar(size_t newCurrent
, const wxKeyEvent
& event
)
2686 wxCHECK_RET( newCurrent
< (size_t)GetItemCount(),
2687 wxT("invalid item index in OnArrowChar()") );
2689 size_t oldCurrent
= m_current
;
2691 // in single selection we just ignore Shift as we can't select several
2693 if ( event
.ShiftDown() && !IsSingleSel() )
2695 ChangeCurrent(newCurrent
);
2697 // refresh the old focus to remove it
2698 RefreshLine( oldCurrent
);
2700 // select all the items between the old and the new one
2701 if ( oldCurrent
> newCurrent
)
2703 newCurrent
= oldCurrent
;
2704 oldCurrent
= m_current
;
2707 HighlightLines(oldCurrent
, newCurrent
);
2711 // all previously selected items are unselected unless ctrl is held
2712 // in a multiselection control
2713 if ( !event
.ControlDown() || IsSingleSel() )
2714 HighlightAll(false);
2716 ChangeCurrent(newCurrent
);
2718 // refresh the old focus to remove it
2719 RefreshLine( oldCurrent
);
2721 // in single selection mode we must always have a selected item
2722 if ( !event
.ControlDown() || IsSingleSel() )
2723 HighlightLine( m_current
, true );
2726 RefreshLine( m_current
);
2731 void wxListMainWindow::OnKeyDown( wxKeyEvent
&event
)
2733 wxWindow
*parent
= GetParent();
2735 // propagate the key event upwards
2736 wxKeyEvent
ke(event
);
2737 ke
.SetEventObject( parent
);
2738 ke
.SetId(GetParent()->GetId());
2739 if (parent
->GetEventHandler()->ProcessEvent( ke
))
2742 // send a list event
2743 wxListEvent
le( wxEVT_COMMAND_LIST_KEY_DOWN
, parent
->GetId() );
2744 le
.m_item
.m_itemId
=
2745 le
.m_itemIndex
= m_current
;
2747 GetLine(m_current
)->GetItem( 0, le
.m_item
);
2748 le
.m_code
= event
.GetKeyCode();
2749 le
.SetEventObject( parent
);
2750 if (parent
->GetEventHandler()->ProcessEvent( le
))
2756 void wxListMainWindow::OnKeyUp( wxKeyEvent
&event
)
2758 wxWindow
*parent
= GetParent();
2760 // propagate the key event upwards
2761 wxKeyEvent
ke(event
);
2762 ke
.SetEventObject( parent
);
2763 ke
.SetId(GetParent()->GetId());
2764 if (parent
->GetEventHandler()->ProcessEvent( ke
))
2770 void wxListMainWindow::OnCharHook( wxKeyEvent
&event
)
2772 if ( m_textctrlWrapper
)
2774 // When an in-place editor is active we should ensure that it always
2775 // gets the key events that are special to it.
2776 if ( m_textctrlWrapper
->CheckForEndEditKey(event
) )
2778 // Skip the call to wxEvent::Skip() below.
2786 void wxListMainWindow::OnChar( wxKeyEvent
&event
)
2788 wxWindow
*parent
= GetParent();
2790 // propagate the char event upwards
2791 wxKeyEvent
ke(event
);
2792 ke
.SetEventObject( parent
);
2793 ke
.SetId(GetParent()->GetId());
2794 if (parent
->GetEventHandler()->ProcessEvent( ke
))
2797 if ( HandleAsNavigationKey(event
) )
2800 // no item -> nothing to do
2807 // don't use m_linesPerPage directly as it might not be computed yet
2808 const int pageSize
= GetCountPerPage();
2809 wxCHECK_RET( pageSize
, wxT("should have non zero page size") );
2811 if (GetLayoutDirection() == wxLayout_RightToLeft
)
2813 if (event
.GetKeyCode() == WXK_RIGHT
)
2814 event
.m_keyCode
= WXK_LEFT
;
2815 else if (event
.GetKeyCode() == WXK_LEFT
)
2816 event
.m_keyCode
= WXK_RIGHT
;
2819 int keyCode
= event
.GetKeyCode();
2823 if ( m_current
> 0 )
2824 OnArrowChar( m_current
- 1, event
);
2828 if ( m_current
< (size_t)GetItemCount() - 1 )
2829 OnArrowChar( m_current
+ 1, event
);
2834 OnArrowChar( GetItemCount() - 1, event
);
2839 OnArrowChar( 0, event
);
2844 int steps
= InReportView() ? pageSize
- 1
2845 : m_current
% pageSize
;
2847 int index
= m_current
- steps
;
2851 OnArrowChar( index
, event
);
2857 int steps
= InReportView()
2859 : pageSize
- (m_current
% pageSize
) - 1;
2861 size_t index
= m_current
+ steps
;
2862 size_t count
= GetItemCount();
2863 if ( index
>= count
)
2866 OnArrowChar( index
, event
);
2871 if ( !InReportView() )
2873 int index
= m_current
- pageSize
;
2877 OnArrowChar( index
, event
);
2882 if ( !InReportView() )
2884 size_t index
= m_current
+ pageSize
;
2886 size_t count
= GetItemCount();
2887 if ( index
>= count
)
2890 OnArrowChar( index
, event
);
2895 if ( IsSingleSel() )
2897 if ( event
.ControlDown() )
2899 ReverseHighlight(m_current
);
2901 else // normal space press
2903 SendNotify( m_current
, wxEVT_COMMAND_LIST_ITEM_ACTIVATED
);
2906 else // multiple selection
2908 ReverseHighlight(m_current
);
2914 SendNotify( m_current
, wxEVT_COMMAND_LIST_ITEM_ACTIVATED
);
2918 if ( !event
.HasModifiers() &&
2919 ((keyCode
>= '0' && keyCode
<= '9') ||
2920 (keyCode
>= 'a' && keyCode
<= 'z') ||
2921 (keyCode
>= 'A' && keyCode
<= 'Z') ||
2927 // find the next item starting with the given prefix
2928 wxChar ch
= (wxChar
)keyCode
;
2931 // if the same character is typed multiple times then go to the
2932 // next entry starting with that character instead of searching
2933 // for an item starting with multiple copies of this character,
2934 // this is more useful and is how it works under Windows.
2935 if ( m_findPrefix
.length() == 1 && m_findPrefix
[0] == ch
)
2937 item
= PrefixFindItem(m_current
, ch
);
2941 const wxString
newPrefix(m_findPrefix
+ ch
);
2942 item
= PrefixFindItem(m_current
, newPrefix
);
2943 if ( item
!= (size_t)-1 )
2944 m_findPrefix
= newPrefix
;
2947 // also start the timer to reset the current prefix if the user
2948 // doesn't press any more alnum keys soon -- we wouldn't want
2949 // to use this prefix for a new item search
2952 m_findTimer
= new wxListFindTimer( this );
2955 // Notice that we should start the timer even if we didn't find
2956 // anything to make sure we reset the search state later.
2957 m_findTimer
->Start(wxListFindTimer::DELAY
, wxTIMER_ONE_SHOT
);
2959 // restart timer even when there's no match so bell get's reset
2960 if ( item
!= (size_t)-1 )
2962 // Select the found item and go to it.
2963 HighlightAll(false);
2965 wxLIST_STATE_FOCUSED
| wxLIST_STATE_SELECTED
,
2966 wxLIST_STATE_FOCUSED
| wxLIST_STATE_SELECTED
);
2968 // Reset the bell flag if it had been temporarily disabled
2973 else // No such item
2975 // Signal it with a bell if enabled.
2976 if ( m_findBell
== 1 )
2980 // Disable it for the next unsuccessful match, we only
2981 // beep once, this is usually enough and continuing to
2982 // do it would be annoying.
2994 // ----------------------------------------------------------------------------
2996 // ----------------------------------------------------------------------------
2998 void wxListMainWindow::OnSetFocus( wxFocusEvent
&WXUNUSED(event
) )
3002 wxFocusEvent
event( wxEVT_SET_FOCUS
, GetParent()->GetId() );
3003 event
.SetEventObject( GetParent() );
3004 if ( GetParent()->GetEventHandler()->ProcessEvent( event
) )
3008 // wxGTK sends us EVT_SET_FOCUS events even if we had never got
3009 // EVT_KILL_FOCUS before which means that we finish by redrawing the items
3010 // which are already drawn correctly resulting in horrible flicker - avoid
3020 void wxListMainWindow::OnKillFocus( wxFocusEvent
&WXUNUSED(event
) )
3024 wxFocusEvent
event( wxEVT_KILL_FOCUS
, GetParent()->GetId() );
3025 event
.SetEventObject( GetParent() );
3026 if ( GetParent()->GetEventHandler()->ProcessEvent( event
) )
3034 void wxListMainWindow::DrawImage( int index
, wxDC
*dc
, int x
, int y
)
3036 if ( HasFlag(wxLC_ICON
) && (m_normal_image_list
))
3038 m_normal_image_list
->Draw( index
, *dc
, x
, y
, wxIMAGELIST_DRAW_TRANSPARENT
);
3040 else if ( HasFlag(wxLC_SMALL_ICON
) && (m_small_image_list
))
3042 m_small_image_list
->Draw( index
, *dc
, x
, y
, wxIMAGELIST_DRAW_TRANSPARENT
);
3044 else if ( HasFlag(wxLC_LIST
) && (m_small_image_list
))
3046 m_small_image_list
->Draw( index
, *dc
, x
, y
, wxIMAGELIST_DRAW_TRANSPARENT
);
3048 else if ( InReportView() && (m_small_image_list
))
3050 m_small_image_list
->Draw( index
, *dc
, x
, y
, wxIMAGELIST_DRAW_TRANSPARENT
);
3054 void wxListMainWindow::GetImageSize( int index
, int &width
, int &height
) const
3056 if ( HasFlag(wxLC_ICON
) && m_normal_image_list
)
3058 m_normal_image_list
->GetSize( index
, width
, height
);
3060 else if ( HasFlag(wxLC_SMALL_ICON
) && m_small_image_list
)
3062 m_small_image_list
->GetSize( index
, width
, height
);
3064 else if ( HasFlag(wxLC_LIST
) && m_small_image_list
)
3066 m_small_image_list
->GetSize( index
, width
, height
);
3068 else if ( InReportView() && m_small_image_list
)
3070 m_small_image_list
->GetSize( index
, width
, height
);
3079 void wxListMainWindow::SetImageList( wxImageList
*imageList
, int which
)
3083 // calc the spacing from the icon size
3084 int width
= 0, height
= 0;
3086 if ((imageList
) && (imageList
->GetImageCount()) )
3087 imageList
->GetSize(0, width
, height
);
3089 if (which
== wxIMAGE_LIST_NORMAL
)
3091 m_normal_image_list
= imageList
;
3092 m_normal_spacing
= width
+ 8;
3095 if (which
== wxIMAGE_LIST_SMALL
)
3097 m_small_image_list
= imageList
;
3098 m_small_spacing
= width
+ 14;
3099 m_lineHeight
= 0; // ensure that the line height will be recalc'd
3103 void wxListMainWindow::SetItemSpacing( int spacing
, bool isSmall
)
3107 m_small_spacing
= spacing
;
3109 m_normal_spacing
= spacing
;
3112 int wxListMainWindow::GetItemSpacing( bool isSmall
)
3114 return isSmall
? m_small_spacing
: m_normal_spacing
;
3117 // ----------------------------------------------------------------------------
3119 // ----------------------------------------------------------------------------
3122 wxListMainWindow::ComputeMinHeaderWidth(const wxListHeaderData
* column
) const
3124 wxClientDC
dc(const_cast<wxListMainWindow
*>(this));
3126 int width
= dc
.GetTextExtent(column
->GetText()).x
+ AUTOSIZE_COL_MARGIN
;
3128 width
+= 2*EXTRA_WIDTH
;
3130 // check for column header's image availability
3131 const int image
= column
->GetImage();
3134 if ( m_small_image_list
)
3137 m_small_image_list
->GetSize(image
, ix
, iy
);
3138 width
+= ix
+ HEADER_IMAGE_MARGIN_IN_REPORT_MODE
;
3145 void wxListMainWindow::SetColumn( int col
, const wxListItem
&item
)
3147 wxListHeaderDataList::compatibility_iterator node
= m_columns
.Item( col
);
3149 wxCHECK_RET( node
, wxT("invalid column index in SetColumn") );
3151 wxListHeaderData
*column
= node
->GetData();
3152 column
->SetItem( item
);
3154 if ( item
.m_width
== wxLIST_AUTOSIZE_USEHEADER
)
3155 column
->SetWidth(ComputeMinHeaderWidth(column
));
3157 wxListHeaderWindow
*headerWin
= GetListCtrl()->m_headerWin
;
3159 headerWin
->m_dirty
= true;
3163 // invalidate it as it has to be recalculated
3167 void wxListMainWindow::SetColumnWidth( int col
, int width
)
3169 wxCHECK_RET( col
>= 0 && col
< GetColumnCount(),
3170 wxT("invalid column index") );
3172 wxCHECK_RET( InReportView(),
3173 wxT("SetColumnWidth() can only be called in report mode.") );
3177 wxListHeaderWindow
*headerWin
= GetListCtrl()->m_headerWin
;
3179 headerWin
->m_dirty
= true;
3181 wxListHeaderDataList::compatibility_iterator node
= m_columns
.Item( col
);
3182 wxCHECK_RET( node
, wxT("no column?") );
3184 wxListHeaderData
*column
= node
->GetData();
3186 size_t count
= GetItemCount();
3188 if (width
== wxLIST_AUTOSIZE_USEHEADER
)
3190 width
= ComputeMinHeaderWidth(column
);
3192 else if ( width
== wxLIST_AUTOSIZE
)
3194 width
= ComputeMinHeaderWidth(column
);
3198 wxClientDC
dc(this);
3199 dc
.SetFont( GetFont() );
3201 int max
= AUTOSIZE_COL_MARGIN
;
3203 // if the cached column width isn't valid then recalculate it
3204 if (m_aColWidths
.Item(col
)->bNeedsUpdate
)
3206 for (size_t i
= 0; i
< count
; i
++)
3208 wxListLineData
*line
= GetLine( i
);
3209 wxListItemDataList::compatibility_iterator n
= line
->m_items
.Item( col
);
3211 wxCHECK_RET( n
, wxT("no subitem?") );
3213 wxListItemData
*itemData
= n
->GetData();
3216 itemData
->GetItem(item
);
3217 int itemWidth
= GetItemWidthWithImage(&item
);
3218 if (itemWidth
> max
)
3222 m_aColWidths
.Item(col
)->bNeedsUpdate
= false;
3223 m_aColWidths
.Item(col
)->nMaxWidth
= max
;
3226 max
= m_aColWidths
.Item(col
)->nMaxWidth
+ AUTOSIZE_COL_MARGIN
;
3232 column
->SetWidth( width
);
3234 // invalidate it as it has to be recalculated
3238 int wxListMainWindow::GetHeaderWidth() const
3240 if ( !m_headerWidth
)
3242 wxListMainWindow
*self
= wxConstCast(this, wxListMainWindow
);
3244 size_t count
= GetColumnCount();
3245 for ( size_t col
= 0; col
< count
; col
++ )
3247 self
->m_headerWidth
+= GetColumnWidth(col
);
3251 return m_headerWidth
;
3254 void wxListMainWindow::GetColumn( int col
, wxListItem
&item
) const
3256 wxListHeaderDataList::compatibility_iterator node
= m_columns
.Item( col
);
3257 wxCHECK_RET( node
, wxT("invalid column index in GetColumn") );
3259 wxListHeaderData
*column
= node
->GetData();
3260 column
->GetItem( item
);
3263 int wxListMainWindow::GetColumnWidth( int col
) const
3265 wxListHeaderDataList::compatibility_iterator node
= m_columns
.Item( col
);
3266 wxCHECK_MSG( node
, 0, wxT("invalid column index") );
3268 wxListHeaderData
*column
= node
->GetData();
3269 return column
->GetWidth();
3272 // ----------------------------------------------------------------------------
3274 // ----------------------------------------------------------------------------
3276 void wxListMainWindow::SetItem( wxListItem
&item
)
3278 long id
= item
.m_itemId
;
3279 wxCHECK_RET( id
>= 0 && (size_t)id
< GetItemCount(),
3280 wxT("invalid item index in SetItem") );
3284 wxListLineData
*line
= GetLine((size_t)id
);
3285 line
->SetItem( item
.m_col
, item
);
3287 // Set item state if user wants
3288 if ( item
.m_mask
& wxLIST_MASK_STATE
)
3289 SetItemState( item
.m_itemId
, item
.m_state
, item
.m_state
);
3293 // update the Max Width Cache if needed
3294 int width
= GetItemWidthWithImage(&item
);
3296 if (width
> m_aColWidths
.Item(item
.m_col
)->nMaxWidth
)
3297 m_aColWidths
.Item(item
.m_col
)->nMaxWidth
= width
;
3301 // update the item on screen unless we're going to update everything soon
3306 GetItemRect(id
, rectItem
);
3307 RefreshRect(rectItem
);
3311 void wxListMainWindow::SetItemStateAll(long state
, long stateMask
)
3316 // first deal with selection
3317 if ( stateMask
& wxLIST_STATE_SELECTED
)
3319 // set/clear select state
3322 // optimized version for virtual listctrl.
3323 m_selStore
.SelectRange(0, GetItemCount() - 1, state
== wxLIST_STATE_SELECTED
);
3326 else if ( state
& wxLIST_STATE_SELECTED
)
3328 const long count
= GetItemCount();
3329 for( long i
= 0; i
< count
; i
++ )
3331 SetItemState( i
, wxLIST_STATE_SELECTED
, wxLIST_STATE_SELECTED
);
3337 // clear for non virtual (somewhat optimized by using GetNextItem())
3339 while ( (i
= GetNextItem(i
, wxLIST_NEXT_ALL
, wxLIST_STATE_SELECTED
)) != -1 )
3341 SetItemState( i
, 0, wxLIST_STATE_SELECTED
);
3346 if ( HasCurrent() && (state
== 0) && (stateMask
& wxLIST_STATE_FOCUSED
) )
3348 // unfocus all: only one item can be focussed, so clearing focus for
3349 // all items is simply clearing focus of the focussed item.
3350 SetItemState(m_current
, state
, stateMask
);
3352 //(setting focus to all items makes no sense, so it is not handled here.)
3355 void wxListMainWindow::SetItemState( long litem
, long state
, long stateMask
)
3359 SetItemStateAll(state
, stateMask
);
3363 wxCHECK_RET( litem
>= 0 && (size_t)litem
< GetItemCount(),
3364 wxT("invalid list ctrl item index in SetItem") );
3366 size_t oldCurrent
= m_current
;
3367 size_t item
= (size_t)litem
; // safe because of the check above
3369 // do we need to change the focus?
3370 if ( stateMask
& wxLIST_STATE_FOCUSED
)
3372 if ( state
& wxLIST_STATE_FOCUSED
)
3374 // don't do anything if this item is already focused
3375 if ( item
!= m_current
)
3377 ChangeCurrent(item
);
3379 if ( oldCurrent
!= (size_t)-1 )
3381 if ( IsSingleSel() )
3383 HighlightLine(oldCurrent
, false);
3386 RefreshLine(oldCurrent
);
3389 RefreshLine( m_current
);
3394 // don't do anything if this item is not focused
3395 if ( item
== m_current
)
3399 if ( IsSingleSel() )
3401 // we must unselect the old current item as well or we
3402 // might end up with more than one selected item in a
3403 // single selection control
3404 HighlightLine(oldCurrent
, false);
3407 RefreshLine( oldCurrent
);
3412 // do we need to change the selection state?
3413 if ( stateMask
& wxLIST_STATE_SELECTED
)
3415 bool on
= (state
& wxLIST_STATE_SELECTED
) != 0;
3417 if ( IsSingleSel() )
3421 // selecting the item also makes it the focused one in the
3423 if ( m_current
!= item
)
3425 ChangeCurrent(item
);
3427 if ( oldCurrent
!= (size_t)-1 )
3429 HighlightLine( oldCurrent
, false );
3430 RefreshLine( oldCurrent
);
3436 // only the current item may be selected anyhow
3437 if ( item
!= m_current
)
3442 if ( HighlightLine(item
, on
) )
3449 int wxListMainWindow::GetItemState( long item
, long stateMask
) const
3451 wxCHECK_MSG( item
>= 0 && (size_t)item
< GetItemCount(), 0,
3452 wxT("invalid list ctrl item index in GetItemState()") );
3454 int ret
= wxLIST_STATE_DONTCARE
;
3456 if ( stateMask
& wxLIST_STATE_FOCUSED
)
3458 if ( (size_t)item
== m_current
)
3459 ret
|= wxLIST_STATE_FOCUSED
;
3462 if ( stateMask
& wxLIST_STATE_SELECTED
)
3464 if ( IsHighlighted(item
) )
3465 ret
|= wxLIST_STATE_SELECTED
;
3471 void wxListMainWindow::GetItem( wxListItem
&item
) const
3473 wxCHECK_RET( item
.m_itemId
>= 0 && (size_t)item
.m_itemId
< GetItemCount(),
3474 wxT("invalid item index in GetItem") );
3476 wxListLineData
*line
= GetLine((size_t)item
.m_itemId
);
3477 line
->GetItem( item
.m_col
, item
);
3479 // Get item state if user wants it
3480 if ( item
.m_mask
& wxLIST_MASK_STATE
)
3481 item
.m_state
= GetItemState( item
.m_itemId
, wxLIST_STATE_SELECTED
|
3482 wxLIST_STATE_FOCUSED
);
3485 // ----------------------------------------------------------------------------
3487 // ----------------------------------------------------------------------------
3489 size_t wxListMainWindow::GetItemCount() const
3491 return IsVirtual() ? m_countVirt
: m_lines
.GetCount();
3494 void wxListMainWindow::SetItemCount(long count
)
3496 m_selStore
.SetItemCount(count
);
3497 m_countVirt
= count
;
3499 ResetVisibleLinesRange();
3501 // scrollbars must be reset
3505 int wxListMainWindow::GetSelectedItemCount() const
3507 // deal with the quick case first
3508 if ( IsSingleSel() )
3509 return HasCurrent() ? IsHighlighted(m_current
) : false;
3511 // virtual controls remmebers all its selections itself
3513 return m_selStore
.GetSelectedCount();
3515 // TODO: we probably should maintain the number of items selected even for
3516 // non virtual controls as enumerating all lines is really slow...
3517 size_t countSel
= 0;
3518 size_t count
= GetItemCount();
3519 for ( size_t line
= 0; line
< count
; line
++ )
3521 if ( GetLine(line
)->IsHighlighted() )
3528 // ----------------------------------------------------------------------------
3529 // item position/size
3530 // ----------------------------------------------------------------------------
3532 wxRect
wxListMainWindow::GetViewRect() const
3534 wxASSERT_MSG( !HasFlag(wxLC_LIST
), "not implemented for list view" );
3536 // we need to find the longest/tallest label
3537 wxCoord xMax
= 0, yMax
= 0;
3538 const int count
= GetItemCount();
3541 for ( int i
= 0; i
< count
; i
++ )
3543 // we need logical, not physical, coordinates here, so use
3544 // GetLineRect() instead of GetItemRect()
3545 wxRect r
= GetLineRect(i
);
3547 wxCoord x
= r
.GetRight(),
3557 // some fudge needed to make it look prettier
3558 xMax
+= 2 * EXTRA_BORDER_X
;
3559 yMax
+= 2 * EXTRA_BORDER_Y
;
3561 // account for the scrollbars if necessary
3562 const wxSize sizeAll
= GetClientSize();
3563 if ( xMax
> sizeAll
.x
)
3564 yMax
+= wxSystemSettings::GetMetric(wxSYS_HSCROLL_Y
);
3565 if ( yMax
> sizeAll
.y
)
3566 xMax
+= wxSystemSettings::GetMetric(wxSYS_VSCROLL_X
);
3568 return wxRect(0, 0, xMax
, yMax
);
3572 wxListMainWindow::GetSubItemRect(long item
, long subItem
, wxRect
& rect
) const
3574 wxCHECK_MSG( subItem
== wxLIST_GETSUBITEMRECT_WHOLEITEM
|| InReportView(),
3576 wxT("GetSubItemRect only meaningful in report view") );
3577 wxCHECK_MSG( item
>= 0 && (size_t)item
< GetItemCount(), false,
3578 wxT("invalid item in GetSubItemRect") );
3580 // ensure that we're laid out, otherwise we could return nonsense
3583 wxConstCast(this, wxListMainWindow
)->
3584 RecalculatePositions(true /* no refresh */);
3587 rect
= GetLineRect((size_t)item
);
3589 // Adjust rect to specified column
3590 if ( subItem
!= wxLIST_GETSUBITEMRECT_WHOLEITEM
)
3592 wxCHECK_MSG( subItem
>= 0 && subItem
< GetColumnCount(), false,
3593 wxT("invalid subItem in GetSubItemRect") );
3595 for (int i
= 0; i
< subItem
; i
++)
3597 rect
.x
+= GetColumnWidth(i
);
3599 rect
.width
= GetColumnWidth(subItem
);
3602 GetListCtrl()->CalcScrolledPosition(rect
.x
, rect
.y
, &rect
.x
, &rect
.y
);
3607 bool wxListMainWindow::GetItemPosition(long item
, wxPoint
& pos
) const
3610 GetItemRect(item
, rect
);
3618 // ----------------------------------------------------------------------------
3619 // geometry calculation
3620 // ----------------------------------------------------------------------------
3622 void wxListMainWindow::RecalculatePositions(bool noRefresh
)
3624 const int lineHeight
= GetLineHeight();
3626 wxClientDC
dc( this );
3627 dc
.SetFont( GetFont() );
3629 const size_t count
= GetItemCount();
3632 if ( HasFlag(wxLC_ICON
) && m_normal_image_list
)
3633 iconSpacing
= m_normal_spacing
;
3634 else if ( HasFlag(wxLC_SMALL_ICON
) && m_small_image_list
)
3635 iconSpacing
= m_small_spacing
;
3639 // Note that we do not call GetClientSize() here but
3640 // GetSize() and subtract the border size for sunken
3641 // borders manually. This is technically incorrect,
3642 // but we need to know the client area's size WITHOUT
3643 // scrollbars here. Since we don't know if there are
3644 // any scrollbars, we use GetSize() instead. Another
3645 // solution would be to call SetScrollbars() here to
3646 // remove the scrollbars and call GetClientSize() then,
3647 // but this might result in flicker and - worse - will
3648 // reset the scrollbars to 0 which is not good at all
3649 // if you resize a dialog/window, but don't want to
3650 // reset the window scrolling. RR.
3651 // Furthermore, we actually do NOT subtract the border
3652 // width as 2 pixels is just the extra space which we
3653 // need around the actual content in the window. Other-
3654 // wise the text would e.g. touch the upper border. RR.
3657 GetSize( &clientWidth
, &clientHeight
);
3659 if ( InReportView() )
3661 // all lines have the same height and we scroll one line per step
3662 int entireHeight
= count
* lineHeight
+ LINE_SPACING
;
3664 m_linesPerPage
= clientHeight
/ lineHeight
;
3666 ResetVisibleLinesRange();
3668 GetListCtrl()->SetScrollbars( SCROLL_UNIT_X
, lineHeight
,
3669 GetHeaderWidth() / SCROLL_UNIT_X
,
3670 (entireHeight
+ lineHeight
- 1) / lineHeight
,
3671 GetListCtrl()->GetScrollPos(wxHORIZONTAL
),
3672 GetListCtrl()->GetScrollPos(wxVERTICAL
),
3677 // we have 3 different layout strategies: either layout all items
3678 // horizontally/vertically (wxLC_ALIGN_XXX styles explicitly given) or
3679 // to arrange them in top to bottom, left to right (don't ask me why
3680 // not the other way round...) order
3681 if ( HasFlag(wxLC_ALIGN_LEFT
| wxLC_ALIGN_TOP
) )
3683 int x
= EXTRA_BORDER_X
;
3684 int y
= EXTRA_BORDER_Y
;
3686 wxCoord widthMax
= 0;
3689 for ( i
= 0; i
< count
; i
++ )
3691 wxListLineData
*line
= GetLine(i
);
3692 line
->CalculateSize( &dc
, iconSpacing
);
3693 line
->SetPosition( x
, y
, iconSpacing
);
3695 wxSize sizeLine
= GetLineSize(i
);
3697 if ( HasFlag(wxLC_ALIGN_TOP
) )
3699 if ( sizeLine
.x
> widthMax
)
3700 widthMax
= sizeLine
.x
;
3704 else // wxLC_ALIGN_LEFT
3706 x
+= sizeLine
.x
+ MARGIN_BETWEEN_ROWS
;
3710 if ( HasFlag(wxLC_ALIGN_TOP
) )
3712 // traverse the items again and tweak their sizes so that they are
3713 // all the same in a row
3714 for ( i
= 0; i
< count
; i
++ )
3716 wxListLineData
*line
= GetLine(i
);
3717 line
->m_gi
->ExtendWidth(widthMax
);
3721 GetListCtrl()->SetScrollbars
3725 (x
+ SCROLL_UNIT_X
) / SCROLL_UNIT_X
,
3726 (y
+ lineHeight
) / lineHeight
,
3727 GetListCtrl()->GetScrollPos( wxHORIZONTAL
),
3728 GetListCtrl()->GetScrollPos( wxVERTICAL
),
3732 else // "flowed" arrangement, the most complicated case
3734 // at first we try without any scrollbars, if the items don't fit into
3735 // the window, we recalculate after subtracting the space taken by the
3738 int entireWidth
= 0;
3740 for (int tries
= 0; tries
< 2; tries
++)
3742 entireWidth
= 2 * EXTRA_BORDER_X
;
3746 // Now we have decided that the items do not fit into the
3747 // client area, so we need a scrollbar
3748 entireWidth
+= SCROLL_UNIT_X
;
3751 int x
= EXTRA_BORDER_X
;
3752 int y
= EXTRA_BORDER_Y
;
3754 // Note that "row" here is vertical, i.e. what is called
3755 // "column" in many other places in wxWidgets.
3756 int maxWidthInThisRow
= 0;
3759 int currentlyVisibleLines
= 0;
3761 for (size_t i
= 0; i
< count
; i
++)
3763 currentlyVisibleLines
++;
3764 wxListLineData
*line
= GetLine( i
);
3765 line
->CalculateSize( &dc
, iconSpacing
);
3766 line
->SetPosition( x
, y
, iconSpacing
);
3768 wxSize sizeLine
= GetLineSize( i
);
3770 if ( maxWidthInThisRow
< sizeLine
.x
)
3771 maxWidthInThisRow
= sizeLine
.x
;
3774 if (currentlyVisibleLines
> m_linesPerPage
)
3775 m_linesPerPage
= currentlyVisibleLines
;
3777 // Have we reached the end of the row either because no
3778 // more items would fit or because there are simply no more
3780 if ( y
+ sizeLine
.y
>= clientHeight
3783 // Adjust all items in this row to have the same
3784 // width to ensure that they all align horizontally in
3786 if ( HasFlag(wxLC_ICON
) || HasFlag(wxLC_SMALL_ICON
) )
3788 size_t firstRowLine
= i
- currentlyVisibleLines
+ 1;
3789 for (size_t j
= firstRowLine
; j
<= i
; j
++)
3791 GetLine(j
)->m_gi
->ExtendWidth(maxWidthInThisRow
);
3795 currentlyVisibleLines
= 0;
3797 maxWidthInThisRow
+= MARGIN_BETWEEN_ROWS
;
3798 x
+= maxWidthInThisRow
;
3799 entireWidth
+= maxWidthInThisRow
;
3800 maxWidthInThisRow
= 0;
3803 if ( (tries
== 0) &&
3804 (entireWidth
+ SCROLL_UNIT_X
> clientWidth
) )
3806 clientHeight
-= wxSystemSettings::
3807 GetMetric(wxSYS_HSCROLL_Y
);
3812 if ( i
== count
- 1 )
3813 tries
= 1; // Everything fits, no second try required.
3817 GetListCtrl()->SetScrollbars
3821 (entireWidth
+ SCROLL_UNIT_X
) / SCROLL_UNIT_X
,
3823 GetListCtrl()->GetScrollPos( wxHORIZONTAL
),
3832 // FIXME: why should we call it from here?
3839 void wxListMainWindow::RefreshAll()
3844 wxListHeaderWindow
*headerWin
= GetListCtrl()->m_headerWin
;
3845 if ( headerWin
&& headerWin
->m_dirty
)
3847 headerWin
->m_dirty
= false;
3848 headerWin
->Refresh();
3852 void wxListMainWindow::UpdateCurrent()
3854 if ( !HasCurrent() && !IsEmpty() )
3858 long wxListMainWindow::GetNextItem( long item
,
3859 int WXUNUSED(geometry
),
3863 max
= GetItemCount();
3864 wxCHECK_MSG( (ret
== -1) || (ret
< max
), -1,
3865 wxT("invalid listctrl index in GetNextItem()") );
3867 // notice that we start with the next item (or the first one if item == -1)
3868 // and this is intentional to allow writing a simple loop to iterate over
3869 // all selected items
3872 // this is not an error because the index was OK initially,
3873 // just no such item
3880 size_t count
= GetItemCount();
3881 for ( size_t line
= (size_t)ret
; line
< count
; line
++ )
3883 if ( (state
& wxLIST_STATE_FOCUSED
) && (line
== m_current
) )
3886 if ( (state
& wxLIST_STATE_SELECTED
) && IsHighlighted(line
) )
3893 // ----------------------------------------------------------------------------
3895 // ----------------------------------------------------------------------------
3897 void wxListMainWindow::DeleteItem( long lindex
)
3899 size_t count
= GetItemCount();
3901 wxCHECK_RET( (lindex
>= 0) && ((size_t)lindex
< count
),
3902 wxT("invalid item index in DeleteItem") );
3904 size_t index
= (size_t)lindex
;
3906 // we don't need to adjust the index for the previous items
3907 if ( HasCurrent() && m_current
>= index
)
3909 // if the current item is being deleted, we want the next one to
3910 // become selected - unless there is no next one - so don't adjust
3911 // m_current in this case
3912 if ( m_current
!= index
|| m_current
== count
- 1 )
3916 if ( InReportView() )
3918 // mark the Column Max Width cache as dirty if the items in the line
3919 // we're deleting contain the Max Column Width
3920 wxListLineData
* const line
= GetLine(index
);
3921 wxListItemDataList::compatibility_iterator n
;
3922 wxListItemData
*itemData
;
3926 for (size_t i
= 0; i
< m_columns
.GetCount(); i
++)
3928 n
= line
->m_items
.Item( i
);
3929 itemData
= n
->GetData();
3930 itemData
->GetItem(item
);
3932 itemWidth
= GetItemWidthWithImage(&item
);
3934 if (itemWidth
>= m_aColWidths
.Item(i
)->nMaxWidth
)
3935 m_aColWidths
.Item(i
)->bNeedsUpdate
= true;
3938 ResetVisibleLinesRange();
3941 SendNotify( index
, wxEVT_COMMAND_LIST_DELETE_ITEM
, wxDefaultPosition
);
3946 m_selStore
.OnItemDelete(index
);
3950 m_lines
.RemoveAt( index
);
3953 // we need to refresh the (vert) scrollbar as the number of items changed
3956 RefreshAfter(index
);
3959 void wxListMainWindow::DeleteColumn( int col
)
3961 wxListHeaderDataList::compatibility_iterator node
= m_columns
.Item( col
);
3963 wxCHECK_RET( node
, wxT("invalid column index in DeleteColumn()") );
3966 delete node
->GetData();
3967 m_columns
.Erase( node
);
3971 // update all the items
3972 for ( size_t i
= 0; i
< m_lines
.GetCount(); i
++ )
3974 wxListLineData
* const line
= GetLine(i
);
3976 // In the following atypical but possible scenario it can be
3977 // legal to call DeleteColumn() but the items may not have any
3979 // 1. In report view, insert a second column.
3980 // 2. Still in report view, add an item with 2 values.
3981 // 3. Switch to an icon (or list) view.
3982 // 4. Add an item -- necessarily with 1 value only.
3983 // 5. Switch back to report view.
3984 // 6. Call DeleteColumn().
3985 // So we need to check for this as otherwise we would simply crash
3987 if ( line
->m_items
.GetCount() <= static_cast<unsigned>(col
) )
3990 wxListItemDataList::compatibility_iterator n
= line
->m_items
.Item( col
);
3991 delete n
->GetData();
3992 line
->m_items
.Erase(n
);
3996 if ( InReportView() ) // we only cache max widths when in Report View
3998 delete m_aColWidths
.Item(col
);
3999 m_aColWidths
.RemoveAt(col
);
4002 // invalidate it as it has to be recalculated
4006 void wxListMainWindow::DoDeleteAllItems()
4009 // nothing to do - in particular, don't send the event
4014 // to make the deletion of all items faster, we don't send the
4015 // notifications for each item deletion in this case but only one event
4016 // for all of them: this is compatible with wxMSW and documented in
4017 // DeleteAllItems() description
4019 wxListEvent
event( wxEVT_COMMAND_LIST_DELETE_ALL_ITEMS
, GetParent()->GetId() );
4020 event
.SetEventObject( GetParent() );
4021 GetParent()->GetEventHandler()->ProcessEvent( event
);
4029 if ( InReportView() )
4031 ResetVisibleLinesRange();
4032 for (size_t i
= 0; i
< m_aColWidths
.GetCount(); i
++)
4034 m_aColWidths
.Item(i
)->bNeedsUpdate
= true;
4041 void wxListMainWindow::DeleteAllItems()
4045 RecalculatePositions();
4048 void wxListMainWindow::DeleteEverything()
4050 WX_CLEAR_LIST(wxListHeaderDataList
, m_columns
);
4051 WX_CLEAR_ARRAY(m_aColWidths
);
4056 // ----------------------------------------------------------------------------
4057 // scanning for an item
4058 // ----------------------------------------------------------------------------
4060 void wxListMainWindow::EnsureVisible( long index
)
4062 wxCHECK_RET( index
>= 0 && (size_t)index
< GetItemCount(),
4063 wxT("invalid index in EnsureVisible") );
4065 // We have to call this here because the label in question might just have
4066 // been added and its position is not known yet
4068 RecalculatePositions(true /* no refresh */);
4070 MoveToItem((size_t)index
);
4073 long wxListMainWindow::FindItem(long start
, const wxString
& str
, bool partial
)
4079 wxString str_upper
= str
.Upper();
4083 size_t count
= GetItemCount();
4084 for ( size_t i
= (size_t)pos
; i
< count
; i
++ )
4086 wxListLineData
*line
= GetLine(i
);
4087 wxString line_upper
= line
->GetText(0).Upper();
4090 if (line_upper
== str_upper
)
4095 if (line_upper
.find(str_upper
) == 0)
4103 long wxListMainWindow::FindItem(long start
, wxUIntPtr data
)
4109 size_t count
= GetItemCount();
4110 for (size_t i
= (size_t)pos
; i
< count
; i
++)
4112 wxListLineData
*line
= GetLine(i
);
4114 line
->GetItem( 0, item
);
4115 if (item
.m_data
== data
)
4122 long wxListMainWindow::FindItem( const wxPoint
& pt
)
4125 GetVisibleLinesRange( &topItem
, NULL
);
4128 GetItemPosition( GetItemCount() - 1, p
);
4132 long id
= (long)floor( pt
.y
* double(GetItemCount() - topItem
- 1) / p
.y
+ topItem
);
4133 if ( id
>= 0 && id
< (long)GetItemCount() )
4139 long wxListMainWindow::HitTest( int x
, int y
, int &flags
) const
4141 GetListCtrl()->CalcUnscrolledPosition( x
, y
, &x
, &y
);
4143 size_t count
= GetItemCount();
4145 if ( InReportView() )
4147 size_t current
= y
/ GetLineHeight();
4148 if ( current
< count
)
4150 flags
= HitTestLine(current
, x
, y
);
4157 // TODO: optimize it too! this is less simple than for report view but
4158 // enumerating all items is still not a way to do it!!
4159 for ( size_t current
= 0; current
< count
; current
++ )
4161 flags
= HitTestLine(current
, x
, y
);
4170 // ----------------------------------------------------------------------------
4172 // ----------------------------------------------------------------------------
4174 void wxListMainWindow::InsertItem( wxListItem
&item
)
4176 wxASSERT_MSG( !IsVirtual(), wxT("can't be used with virtual control") );
4178 int count
= GetItemCount();
4179 wxCHECK_RET( item
.m_itemId
>= 0, wxT("invalid item index") );
4181 if (item
.m_itemId
> count
)
4182 item
.m_itemId
= count
;
4184 size_t id
= item
.m_itemId
;
4188 if ( InReportView() )
4190 ResetVisibleLinesRange();
4192 const unsigned col
= item
.GetColumn();
4193 wxCHECK_RET( col
< m_aColWidths
.size(), "invalid item column" );
4195 // calculate the width of the item and adjust the max column width
4196 wxColWidthInfo
*pWidthInfo
= m_aColWidths
.Item(col
);
4197 int width
= GetItemWidthWithImage(&item
);
4198 item
.SetWidth(width
);
4199 if (width
> pWidthInfo
->nMaxWidth
)
4200 pWidthInfo
->nMaxWidth
= width
;
4203 wxListLineData
*line
= new wxListLineData(this);
4205 line
->SetItem( item
.m_col
, item
);
4206 if ( item
.m_mask
& wxLIST_MASK_IMAGE
)
4208 // Reset the buffered height if it's not big enough for the new image.
4209 int image
= item
.GetImage();
4210 if ( m_small_image_list
&& image
!= -1 && InReportView() )
4212 int imageWidth
, imageHeight
;
4213 m_small_image_list
->GetSize(image
, imageWidth
, imageHeight
);
4215 if ( imageHeight
> m_lineHeight
)
4220 m_lines
.Insert( line
, id
);
4224 // If an item is selected at or below the point of insertion, we need to
4225 // increment the member variables because the current row's index has gone
4227 if ( HasCurrent() && m_current
>= id
)
4230 SendNotify(id
, wxEVT_COMMAND_LIST_INSERT_ITEM
);
4232 RefreshLines(id
, GetItemCount() - 1);
4235 long wxListMainWindow::InsertColumn( long col
, const wxListItem
&item
)
4240 if ( InReportView() )
4242 wxListHeaderData
*column
= new wxListHeaderData( item
);
4243 if (item
.m_width
== wxLIST_AUTOSIZE_USEHEADER
)
4244 column
->SetWidth(ComputeMinHeaderWidth(column
));
4246 wxColWidthInfo
*colWidthInfo
= new wxColWidthInfo();
4248 bool insert
= (col
>= 0) && ((size_t)col
< m_columns
.GetCount());
4251 wxListHeaderDataList::compatibility_iterator
4252 node
= m_columns
.Item( col
);
4253 m_columns
.Insert( node
, column
);
4254 m_aColWidths
.Insert( colWidthInfo
, col
);
4259 idx
= m_aColWidths
.GetCount();
4260 m_columns
.Append( column
);
4261 m_aColWidths
.Add( colWidthInfo
);
4266 // update all the items
4267 for ( size_t i
= 0; i
< m_lines
.GetCount(); i
++ )
4269 wxListLineData
* const line
= GetLine(i
);
4270 wxListItemData
* const data
= new wxListItemData(this);
4272 line
->m_items
.Insert(col
, data
);
4274 line
->m_items
.Append(data
);
4278 // invalidate it as it has to be recalculated
4284 int wxListMainWindow::GetItemWidthWithImage(wxListItem
* item
)
4287 wxClientDC
dc(this);
4289 dc
.SetFont( GetFont() );
4291 if (item
->GetImage() != -1)
4294 GetImageSize( item
->GetImage(), ix
, iy
);
4298 if (!item
->GetText().empty())
4301 dc
.GetTextExtent( item
->GetText(), &w
, NULL
);
4308 // ----------------------------------------------------------------------------
4310 // ----------------------------------------------------------------------------
4312 static wxListCtrlCompare list_ctrl_compare_func_2
;
4313 static wxIntPtr list_ctrl_compare_data
;
4315 int LINKAGEMODE
list_ctrl_compare_func_1( wxListLineData
**arg1
, wxListLineData
**arg2
)
4317 wxListLineData
*line1
= *arg1
;
4318 wxListLineData
*line2
= *arg2
;
4320 line1
->GetItem( 0, item
);
4321 wxUIntPtr data1
= item
.m_data
;
4322 line2
->GetItem( 0, item
);
4323 wxUIntPtr data2
= item
.m_data
;
4324 return list_ctrl_compare_func_2( data1
, data2
, list_ctrl_compare_data
);
4327 void wxListMainWindow::SortItems( wxListCtrlCompare fn
, wxIntPtr data
)
4329 // selections won't make sense any more after sorting the items so reset
4331 HighlightAll(false);
4334 list_ctrl_compare_func_2
= fn
;
4335 list_ctrl_compare_data
= data
;
4336 m_lines
.Sort( list_ctrl_compare_func_1
);
4340 // ----------------------------------------------------------------------------
4342 // ----------------------------------------------------------------------------
4344 void wxListMainWindow::OnScroll(wxScrollWinEvent
& event
)
4346 // update our idea of which lines are shown when we redraw the window the
4348 ResetVisibleLinesRange();
4350 if ( event
.GetOrientation() == wxHORIZONTAL
&& HasHeader() )
4352 wxGenericListCtrl
* lc
= GetListCtrl();
4353 wxCHECK_RET( lc
, wxT("no listctrl window?") );
4355 if (lc
->m_headerWin
) // when we use wxLC_NO_HEADER, m_headerWin==NULL
4357 lc
->m_headerWin
->Refresh();
4358 lc
->m_headerWin
->Update();
4363 int wxListMainWindow::GetCountPerPage() const
4365 if ( !m_linesPerPage
)
4367 wxConstCast(this, wxListMainWindow
)->
4368 m_linesPerPage
= GetClientSize().y
/ GetLineHeight();
4371 return m_linesPerPage
;
4374 void wxListMainWindow::GetVisibleLinesRange(size_t *from
, size_t *to
)
4376 wxASSERT_MSG( InReportView(), wxT("this is for report mode only") );
4378 if ( m_lineFrom
== (size_t)-1 )
4380 size_t count
= GetItemCount();
4383 m_lineFrom
= GetListCtrl()->GetScrollPos(wxVERTICAL
);
4385 // this may happen if SetScrollbars() hadn't been called yet
4386 if ( m_lineFrom
>= count
)
4387 m_lineFrom
= count
- 1;
4389 // we redraw one extra line but this is needed to make the redrawing
4390 // logic work when there is a fractional number of lines on screen
4391 m_lineTo
= m_lineFrom
+ m_linesPerPage
;
4392 if ( m_lineTo
>= count
)
4393 m_lineTo
= count
- 1;
4395 else // empty control
4398 m_lineTo
= (size_t)-1;
4402 wxASSERT_MSG( IsEmpty() ||
4403 (m_lineFrom
<= m_lineTo
&& m_lineTo
< GetItemCount()),
4404 wxT("GetVisibleLinesRange() returns incorrect result") );
4413 wxListMainWindow::PrefixFindItem(size_t idParent
,
4414 const wxString
& prefixOrig
) const
4416 // if no items then just return
4417 if ( idParent
== (size_t)-1 )
4420 // match is case insensitive as this is more convenient to the user: having
4421 // to press Shift-letter to go to the item starting with a capital letter
4422 // would be too bothersome
4423 wxString prefix
= prefixOrig
.Lower();
4425 // determine the starting point: we shouldn't take the current item (this
4426 // allows to switch between two items starting with the same letter just by
4427 // pressing it) but we shouldn't jump to the next one if the user is
4428 // continuing to type as otherwise he might easily skip the item he wanted
4429 size_t itemid
= idParent
;
4430 if ( prefix
.length() == 1 )
4435 // look for the item starting with the given prefix after it
4436 while ( ( itemid
< (size_t)GetItemCount() ) &&
4437 !GetLine(itemid
)->GetText(0).Lower().StartsWith(prefix
) )
4442 // if we haven't found anything...
4443 if ( !( itemid
< (size_t)GetItemCount() ) )
4445 // ... wrap to the beginning
4448 // and try all the items (stop when we get to the one we started from)
4449 while ( ( itemid
< (size_t)GetItemCount() ) && itemid
!= idParent
&&
4450 !GetLine(itemid
)->GetText(0).Lower().StartsWith(prefix
) )
4454 // If we haven't found the item, id will be (size_t)-1, as per
4456 if ( !( itemid
< (size_t)GetItemCount() ) ||
4457 ( ( itemid
== idParent
) &&
4458 !GetLine(itemid
)->GetText(0).Lower().StartsWith(prefix
) ) )
4460 itemid
= (size_t)-1;
4467 // -------------------------------------------------------------------------------------
4468 // wxGenericListCtrl
4469 // -------------------------------------------------------------------------------------
4471 IMPLEMENT_DYNAMIC_CLASS(wxGenericListCtrl
, wxControl
)
4473 BEGIN_EVENT_TABLE(wxGenericListCtrl
,wxListCtrlBase
)
4474 EVT_SIZE(wxGenericListCtrl::OnSize
)
4475 EVT_SCROLLWIN(wxGenericListCtrl::OnScroll
)
4478 void wxGenericListCtrl::Init()
4480 m_imageListNormal
= NULL
;
4481 m_imageListSmall
= NULL
;
4482 m_imageListState
= NULL
;
4484 m_ownsImageListNormal
=
4485 m_ownsImageListSmall
=
4486 m_ownsImageListState
= false;
4492 wxGenericListCtrl::~wxGenericListCtrl()
4494 if (m_ownsImageListNormal
)
4495 delete m_imageListNormal
;
4496 if (m_ownsImageListSmall
)
4497 delete m_imageListSmall
;
4498 if (m_ownsImageListState
)
4499 delete m_imageListState
;
4502 void wxGenericListCtrl::CreateOrDestroyHeaderWindowAsNeeded()
4504 bool needs_header
= HasHeader();
4505 bool has_header
= (m_headerWin
!= NULL
);
4507 if (needs_header
== has_header
)
4512 m_headerWin
= new wxListHeaderWindow
4514 this, wxID_ANY
, m_mainWin
,
4519 wxRendererNative::Get().GetHeaderButtonHeight(this)
4524 #if defined( __WXMAC__ )
4525 static wxFont
font( wxOSX_SYSTEM_FONT_SMALL
);
4526 m_headerWin
->SetFont( font
);
4529 GetSizer()->Prepend( m_headerWin
, 0, wxGROW
);
4533 GetSizer()->Detach( m_headerWin
);
4535 wxDELETE(m_headerWin
);
4539 bool wxGenericListCtrl::Create(wxWindow
*parent
,
4544 const wxValidator
&validator
,
4545 const wxString
&name
)
4549 // just like in other ports, an assert will fail if the user doesn't give any type style:
4550 wxASSERT_MSG( (style
& wxLC_MASK_TYPE
),
4551 wxT("wxListCtrl style should have exactly one mode bit set") );
4553 if ( !wxListCtrlBase::Create( parent
, id
, pos
, size
,
4554 style
| wxVSCROLL
| wxHSCROLL
,
4558 m_mainWin
= new wxListMainWindow(this, wxID_ANY
, wxPoint(0, 0), size
);
4560 SetTargetWindow( m_mainWin
);
4562 // We use the cursor keys for moving the selection, not scrolling, so call
4563 // this method to ensure wxScrollHelperEvtHandler doesn't catch all
4564 // keyboard events forwarded to us from wxListMainWindow.
4565 DisableKeyboardScrolling();
4567 wxBoxSizer
*sizer
= new wxBoxSizer( wxVERTICAL
);
4568 sizer
->Add( m_mainWin
, 1, wxGROW
);
4571 CreateOrDestroyHeaderWindowAsNeeded();
4573 SetInitialSize(size
);
4578 wxBorder
wxGenericListCtrl::GetDefaultBorder() const
4580 return wxBORDER_THEME
;
4583 #if defined(__WXMSW__) && !defined(__WXWINCE__) && !defined(__WXUNIVERSAL__)
4584 WXLRESULT
wxGenericListCtrl::MSWWindowProc(WXUINT nMsg
,
4588 WXLRESULT rc
= wxListCtrlBase::MSWWindowProc(nMsg
, wParam
, lParam
);
4590 // we need to process arrows ourselves for scrolling
4591 if ( nMsg
== WM_GETDLGCODE
)
4593 rc
|= DLGC_WANTARROWS
;
4600 wxSize
wxGenericListCtrl::GetSizeAvailableForScrollTarget(const wxSize
& size
)
4602 wxSize newsize
= size
;
4604 newsize
.y
-= m_headerWin
->GetSize().y
;
4609 void wxGenericListCtrl::OnScroll(wxScrollWinEvent
& event
)
4611 // update our idea of which lines are shown when we redraw
4612 // the window the next time
4613 m_mainWin
->ResetVisibleLinesRange();
4615 HandleOnScroll( event
);
4617 if ( event
.GetOrientation() == wxHORIZONTAL
&& HasHeader() )
4619 m_headerWin
->Refresh();
4620 m_headerWin
->Update();
4624 void wxGenericListCtrl::SetSingleStyle( long style
, bool add
)
4626 wxASSERT_MSG( !(style
& wxLC_VIRTUAL
),
4627 wxT("wxLC_VIRTUAL can't be [un]set") );
4629 long flag
= GetWindowStyle();
4633 if (style
& wxLC_MASK_TYPE
)
4634 flag
&= ~(wxLC_MASK_TYPE
| wxLC_VIRTUAL
);
4635 if (style
& wxLC_MASK_ALIGN
)
4636 flag
&= ~wxLC_MASK_ALIGN
;
4637 if (style
& wxLC_MASK_SORT
)
4638 flag
&= ~wxLC_MASK_SORT
;
4646 // some styles can be set without recreating everything (as happens in
4647 // SetWindowStyleFlag() which calls wxListMainWindow::DeleteEverything())
4648 if ( !(style
& ~(wxLC_HRULES
| wxLC_VRULES
)) )
4651 wxWindow::SetWindowStyleFlag(flag
);
4655 SetWindowStyleFlag( flag
);
4659 void wxGenericListCtrl::SetWindowStyleFlag( long flag
)
4661 // we add wxHSCROLL and wxVSCROLL in ctor unconditionally and it never
4662 // makes sense to remove them as we'll always add scrollbars anyhow when
4664 flag
|= wxHSCROLL
| wxVSCROLL
;
4666 const bool wasInReportView
= HasFlag(wxLC_REPORT
);
4668 // update the window style first so that the header is created or destroyed
4669 // corresponding to the new style
4670 wxWindow::SetWindowStyleFlag( flag
);
4674 const bool inReportView
= (flag
& wxLC_REPORT
) != 0;
4675 if ( inReportView
!= wasInReportView
)
4677 // we need to notify the main window about this change as it must
4678 // update its data structures
4679 m_mainWin
->SetReportView(inReportView
);
4682 // m_mainWin->DeleteEverything(); wxMSW doesn't do that
4684 CreateOrDestroyHeaderWindowAsNeeded();
4686 GetSizer()->Layout();
4690 bool wxGenericListCtrl::GetColumn(int col
, wxListItem
&item
) const
4692 m_mainWin
->GetColumn( col
, item
);
4696 bool wxGenericListCtrl::SetColumn( int col
, const wxListItem
& item
)
4698 m_mainWin
->SetColumn( col
, item
);
4702 int wxGenericListCtrl::GetColumnWidth( int col
) const
4704 return m_mainWin
->GetColumnWidth( col
);
4707 bool wxGenericListCtrl::SetColumnWidth( int col
, int width
)
4709 m_mainWin
->SetColumnWidth( col
, width
);
4713 int wxGenericListCtrl::GetCountPerPage() const
4715 return m_mainWin
->GetCountPerPage(); // different from Windows ?
4718 bool wxGenericListCtrl::GetItem( wxListItem
&info
) const
4720 m_mainWin
->GetItem( info
);
4724 bool wxGenericListCtrl::SetItem( wxListItem
&info
)
4726 m_mainWin
->SetItem( info
);
4730 long wxGenericListCtrl::SetItem( long index
, int col
, const wxString
& label
, int imageId
)
4733 info
.m_text
= label
;
4734 info
.m_mask
= wxLIST_MASK_TEXT
;
4735 info
.m_itemId
= index
;
4739 info
.m_image
= imageId
;
4740 info
.m_mask
|= wxLIST_MASK_IMAGE
;
4743 m_mainWin
->SetItem(info
);
4747 int wxGenericListCtrl::GetItemState( long item
, long stateMask
) const
4749 return m_mainWin
->GetItemState( item
, stateMask
);
4752 bool wxGenericListCtrl::SetItemState( long item
, long state
, long stateMask
)
4754 m_mainWin
->SetItemState( item
, state
, stateMask
);
4759 wxGenericListCtrl::SetItemImage( long item
, int image
, int WXUNUSED(selImage
) )
4761 return SetItemColumnImage(item
, 0, image
);
4765 wxGenericListCtrl::SetItemColumnImage( long item
, long column
, int image
)
4768 info
.m_image
= image
;
4769 info
.m_mask
= wxLIST_MASK_IMAGE
;
4770 info
.m_itemId
= item
;
4771 info
.m_col
= column
;
4772 m_mainWin
->SetItem( info
);
4776 wxString
wxGenericListCtrl::GetItemText( long item
, int col
) const
4778 return m_mainWin
->GetItemText(item
, col
);
4781 void wxGenericListCtrl::SetItemText( long item
, const wxString
& str
)
4783 m_mainWin
->SetItemText(item
, str
);
4786 wxUIntPtr
wxGenericListCtrl::GetItemData( long item
) const
4789 info
.m_mask
= wxLIST_MASK_DATA
;
4790 info
.m_itemId
= item
;
4791 m_mainWin
->GetItem( info
);
4795 bool wxGenericListCtrl::SetItemPtrData( long item
, wxUIntPtr data
)
4798 info
.m_mask
= wxLIST_MASK_DATA
;
4799 info
.m_itemId
= item
;
4801 m_mainWin
->SetItem( info
);
4805 wxRect
wxGenericListCtrl::GetViewRect() const
4807 return m_mainWin
->GetViewRect();
4810 bool wxGenericListCtrl::GetItemRect(long item
, wxRect
& rect
, int code
) const
4812 return GetSubItemRect(item
, wxLIST_GETSUBITEMRECT_WHOLEITEM
, rect
, code
);
4815 bool wxGenericListCtrl::GetSubItemRect(long item
,
4818 int WXUNUSED(code
)) const
4820 if ( !m_mainWin
->GetSubItemRect( item
, subItem
, rect
) )
4823 if ( m_mainWin
->HasHeader() )
4824 rect
.y
+= m_headerWin
->GetSize().y
+ 1;
4829 bool wxGenericListCtrl::GetItemPosition( long item
, wxPoint
& pos
) const
4831 m_mainWin
->GetItemPosition( item
, pos
);
4835 bool wxGenericListCtrl::SetItemPosition( long WXUNUSED(item
), const wxPoint
& WXUNUSED(pos
) )
4840 int wxGenericListCtrl::GetItemCount() const
4842 return m_mainWin
->GetItemCount();
4845 int wxGenericListCtrl::GetColumnCount() const
4847 return m_mainWin
->GetColumnCount();
4850 void wxGenericListCtrl::SetItemSpacing( int spacing
, bool isSmall
)
4852 m_mainWin
->SetItemSpacing( spacing
, isSmall
);
4855 wxSize
wxGenericListCtrl::GetItemSpacing() const
4857 const int spacing
= m_mainWin
->GetItemSpacing(HasFlag(wxLC_SMALL_ICON
));
4859 return wxSize(spacing
, spacing
);
4862 #if WXWIN_COMPATIBILITY_2_6
4863 int wxGenericListCtrl::GetItemSpacing( bool isSmall
) const
4865 return m_mainWin
->GetItemSpacing( isSmall
);
4867 #endif // WXWIN_COMPATIBILITY_2_6
4869 void wxGenericListCtrl::SetItemTextColour( long item
, const wxColour
&col
)
4872 info
.m_itemId
= item
;
4873 info
.SetTextColour( col
);
4874 m_mainWin
->SetItem( info
);
4877 wxColour
wxGenericListCtrl::GetItemTextColour( long item
) const
4880 info
.m_itemId
= item
;
4881 m_mainWin
->GetItem( info
);
4882 return info
.GetTextColour();
4885 void wxGenericListCtrl::SetItemBackgroundColour( long item
, const wxColour
&col
)
4888 info
.m_itemId
= item
;
4889 info
.SetBackgroundColour( col
);
4890 m_mainWin
->SetItem( info
);
4893 wxColour
wxGenericListCtrl::GetItemBackgroundColour( long item
) const
4896 info
.m_itemId
= item
;
4897 m_mainWin
->GetItem( info
);
4898 return info
.GetBackgroundColour();
4901 void wxGenericListCtrl::SetItemFont( long item
, const wxFont
&f
)
4904 info
.m_itemId
= item
;
4906 m_mainWin
->SetItem( info
);
4909 wxFont
wxGenericListCtrl::GetItemFont( long item
) const
4912 info
.m_itemId
= item
;
4913 m_mainWin
->GetItem( info
);
4914 return info
.GetFont();
4917 int wxGenericListCtrl::GetSelectedItemCount() const
4919 return m_mainWin
->GetSelectedItemCount();
4922 wxColour
wxGenericListCtrl::GetTextColour() const
4924 return GetForegroundColour();
4927 void wxGenericListCtrl::SetTextColour(const wxColour
& col
)
4929 SetForegroundColour(col
);
4932 long wxGenericListCtrl::GetTopItem() const
4935 m_mainWin
->GetVisibleLinesRange(&top
, NULL
);
4939 long wxGenericListCtrl::GetNextItem( long item
, int geom
, int state
) const
4941 return m_mainWin
->GetNextItem( item
, geom
, state
);
4944 wxImageList
*wxGenericListCtrl::GetImageList(int which
) const
4946 if (which
== wxIMAGE_LIST_NORMAL
)
4947 return m_imageListNormal
;
4948 else if (which
== wxIMAGE_LIST_SMALL
)
4949 return m_imageListSmall
;
4950 else if (which
== wxIMAGE_LIST_STATE
)
4951 return m_imageListState
;
4956 void wxGenericListCtrl::SetImageList( wxImageList
*imageList
, int which
)
4958 if ( which
== wxIMAGE_LIST_NORMAL
)
4960 if (m_ownsImageListNormal
)
4961 delete m_imageListNormal
;
4962 m_imageListNormal
= imageList
;
4963 m_ownsImageListNormal
= false;
4965 else if ( which
== wxIMAGE_LIST_SMALL
)
4967 if (m_ownsImageListSmall
)
4968 delete m_imageListSmall
;
4969 m_imageListSmall
= imageList
;
4970 m_ownsImageListSmall
= false;
4972 else if ( which
== wxIMAGE_LIST_STATE
)
4974 if (m_ownsImageListState
)
4975 delete m_imageListState
;
4976 m_imageListState
= imageList
;
4977 m_ownsImageListState
= false;
4980 m_mainWin
->SetImageList( imageList
, which
);
4983 void wxGenericListCtrl::AssignImageList(wxImageList
*imageList
, int which
)
4985 SetImageList(imageList
, which
);
4986 if ( which
== wxIMAGE_LIST_NORMAL
)
4987 m_ownsImageListNormal
= true;
4988 else if ( which
== wxIMAGE_LIST_SMALL
)
4989 m_ownsImageListSmall
= true;
4990 else if ( which
== wxIMAGE_LIST_STATE
)
4991 m_ownsImageListState
= true;
4994 bool wxGenericListCtrl::Arrange( int WXUNUSED(flag
) )
4999 bool wxGenericListCtrl::DeleteItem( long item
)
5001 m_mainWin
->DeleteItem( item
);
5005 bool wxGenericListCtrl::DeleteAllItems()
5007 m_mainWin
->DeleteAllItems();
5011 bool wxGenericListCtrl::DeleteAllColumns()
5013 size_t count
= m_mainWin
->m_columns
.GetCount();
5014 for ( size_t n
= 0; n
< count
; n
++ )
5019 void wxGenericListCtrl::ClearAll()
5021 m_mainWin
->DeleteEverything();
5024 bool wxGenericListCtrl::DeleteColumn( int col
)
5026 m_mainWin
->DeleteColumn( col
);
5028 // if we don't have the header any longer, we need to relayout the window
5029 // if ( !GetColumnCount() )
5032 // Ensure that the non-existent columns are really removed from display.
5038 wxTextCtrl
*wxGenericListCtrl::EditLabel(long item
,
5039 wxClassInfo
* textControlClass
)
5041 return m_mainWin
->EditLabel( item
, textControlClass
);
5044 wxTextCtrl
*wxGenericListCtrl::GetEditControl() const
5046 return m_mainWin
->GetEditControl();
5049 bool wxGenericListCtrl::EnsureVisible( long item
)
5051 m_mainWin
->EnsureVisible( item
);
5055 long wxGenericListCtrl::FindItem( long start
, const wxString
& str
, bool partial
)
5057 return m_mainWin
->FindItem( start
, str
, partial
);
5060 long wxGenericListCtrl::FindItem( long start
, wxUIntPtr data
)
5062 return m_mainWin
->FindItem( start
, data
);
5065 long wxGenericListCtrl::FindItem( long WXUNUSED(start
), const wxPoint
& pt
,
5066 int WXUNUSED(direction
))
5068 return m_mainWin
->FindItem( pt
);
5071 // TODO: sub item hit testing
5072 long wxGenericListCtrl::HitTest(const wxPoint
& point
, int& flags
, long *) const
5074 return m_mainWin
->HitTest( (int)point
.x
, (int)point
.y
, flags
);
5077 long wxGenericListCtrl::InsertItem( wxListItem
& info
)
5079 m_mainWin
->InsertItem( info
);
5080 return info
.m_itemId
;
5083 long wxGenericListCtrl::InsertItem( long index
, const wxString
&label
)
5086 info
.m_text
= label
;
5087 info
.m_mask
= wxLIST_MASK_TEXT
;
5088 info
.m_itemId
= index
;
5089 return InsertItem( info
);
5092 long wxGenericListCtrl::InsertItem( long index
, int imageIndex
)
5095 info
.m_mask
= wxLIST_MASK_IMAGE
;
5096 info
.m_image
= imageIndex
;
5097 info
.m_itemId
= index
;
5098 return InsertItem( info
);
5101 long wxGenericListCtrl::InsertItem( long index
, const wxString
&label
, int imageIndex
)
5104 info
.m_text
= label
;
5105 info
.m_image
= imageIndex
;
5106 info
.m_mask
= wxLIST_MASK_TEXT
;
5107 if (imageIndex
> -1)
5108 info
.m_mask
|= wxLIST_MASK_IMAGE
;
5109 info
.m_itemId
= index
;
5110 return InsertItem( info
);
5113 long wxGenericListCtrl::DoInsertColumn( long col
, const wxListItem
&item
)
5115 wxCHECK_MSG( InReportView(), -1, wxT("can't add column in non report mode") );
5117 long idx
= m_mainWin
->InsertColumn( col
, item
);
5119 // NOTE: if wxLC_NO_HEADER was given, then we are in report view mode but
5120 // still have m_headerWin==NULL
5122 m_headerWin
->Refresh();
5127 bool wxGenericListCtrl::ScrollList( int dx
, int dy
)
5129 return m_mainWin
->ScrollList(dx
, dy
);
5133 // fn is a function which takes 3 long arguments: item1, item2, data.
5134 // item1 is the long data associated with a first item (NOT the index).
5135 // item2 is the long data associated with a second item (NOT the index).
5136 // data is the same value as passed to SortItems.
5137 // The return value is a negative number if the first item should precede the second
5138 // item, a positive number of the second item should precede the first,
5139 // or zero if the two items are equivalent.
5140 // data is arbitrary data to be passed to the sort function.
5142 bool wxGenericListCtrl::SortItems( wxListCtrlCompare fn
, wxIntPtr data
)
5144 m_mainWin
->SortItems( fn
, data
);
5148 // ----------------------------------------------------------------------------
5150 // ----------------------------------------------------------------------------
5152 void wxGenericListCtrl::OnSize(wxSizeEvent
& WXUNUSED(event
))
5154 if (!m_mainWin
) return;
5156 // We need to override OnSize so that our scrolled
5157 // window a) does call Layout() to use sizers for
5158 // positioning the controls but b) does not query
5159 // the sizer for their size and use that for setting
5160 // the scrollable area as set that ourselves by
5161 // calling SetScrollbar() further down.
5165 m_mainWin
->RecalculatePositions();
5170 void wxGenericListCtrl::OnInternalIdle()
5172 wxWindow::OnInternalIdle();
5174 if (m_mainWin
->m_dirty
)
5175 m_mainWin
->RecalculatePositions();
5178 // ----------------------------------------------------------------------------
5180 // ----------------------------------------------------------------------------
5182 bool wxGenericListCtrl::SetBackgroundColour( const wxColour
&colour
)
5186 m_mainWin
->SetBackgroundColour( colour
);
5187 m_mainWin
->m_dirty
= true;
5193 bool wxGenericListCtrl::SetForegroundColour( const wxColour
&colour
)
5195 if ( !wxWindow::SetForegroundColour( colour
) )
5200 m_mainWin
->SetForegroundColour( colour
);
5201 m_mainWin
->m_dirty
= true;
5205 m_headerWin
->SetForegroundColour( colour
);
5210 bool wxGenericListCtrl::SetFont( const wxFont
&font
)
5212 if ( !wxWindow::SetFont( font
) )
5217 m_mainWin
->SetFont( font
);
5218 m_mainWin
->m_dirty
= true;
5223 m_headerWin
->SetFont( font
);
5224 // CalculateAndSetHeaderHeight();
5234 wxGenericListCtrl::GetClassDefaultAttributes(wxWindowVariant variant
)
5237 // Use the same color scheme as wxListBox
5238 return wxListBox::GetClassDefaultAttributes(variant
);
5240 wxUnusedVar(variant
);
5241 wxVisualAttributes attr
;
5242 attr
.colFg
= wxSystemSettings::GetColour(wxSYS_COLOUR_LISTBOXTEXT
);
5243 attr
.colBg
= wxSystemSettings::GetColour(wxSYS_COLOUR_LISTBOX
);
5244 attr
.font
= wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT
);
5249 // ----------------------------------------------------------------------------
5250 // methods forwarded to m_mainWin
5251 // ----------------------------------------------------------------------------
5253 #if wxUSE_DRAG_AND_DROP
5255 void wxGenericListCtrl::SetDropTarget( wxDropTarget
*dropTarget
)
5257 m_mainWin
->SetDropTarget( dropTarget
);
5260 wxDropTarget
*wxGenericListCtrl::GetDropTarget() const
5262 return m_mainWin
->GetDropTarget();
5267 bool wxGenericListCtrl::SetCursor( const wxCursor
&cursor
)
5269 return m_mainWin
? m_mainWin
->wxWindow::SetCursor(cursor
) : false;
5272 wxColour
wxGenericListCtrl::GetBackgroundColour() const
5274 return m_mainWin
? m_mainWin
->GetBackgroundColour() : wxColour();
5277 wxColour
wxGenericListCtrl::GetForegroundColour() const
5279 return m_mainWin
? m_mainWin
->GetForegroundColour() : wxColour();
5282 bool wxGenericListCtrl::DoPopupMenu( wxMenu
*menu
, int x
, int y
)
5285 return m_mainWin
->PopupMenu( menu
, x
, y
);
5291 void wxGenericListCtrl::DoClientToScreen( int *x
, int *y
) const
5293 // It's not clear whether this can be called before m_mainWin is created
5294 // but it seems better to be on the safe side and check.
5296 m_mainWin
->DoClientToScreen(x
, y
);
5298 wxListCtrlBase::DoClientToScreen(x
, y
);
5301 void wxGenericListCtrl::DoScreenToClient( int *x
, int *y
) const
5303 // At least in wxGTK/Univ build this method can be called before m_mainWin
5304 // is created so avoid crashes in this case.
5306 m_mainWin
->DoScreenToClient(x
, y
);
5308 wxListCtrlBase::DoScreenToClient(x
, y
);
5311 wxSize
wxGenericListCtrl::DoGetBestClientSize() const
5313 // The base class version can compute the best size in report view only.
5314 wxSize sizeBest
= wxListCtrlBase::DoGetBestClientSize();
5316 if ( !InReportView() )
5318 // Ensure that our minimal width is at least big enough to show all our
5319 // items. This is important for wxListbook to size itself correctly.
5321 // Remember the offset of the first item: this corresponds to the
5322 // margins around the item so we will add it to the minimal size below
5323 // to ensure that we have equal margins on all sides.
5326 // We can iterate over all items as there shouldn't be too many of them
5327 // in non-report view. If it ever becomes a problem, we could examine
5328 // just the first few items probably, the determination of the best
5329 // size is less important if we will need scrollbars anyhow.
5330 for ( int n
= 0; n
< GetItemCount(); n
++ )
5332 const wxRect itemRect
= m_mainWin
->GetLineRect(n
);
5335 // Remember the position of the first item as all the rest are
5336 // offset by at least this number of pixels too.
5337 ofs
= itemRect
.GetPosition();
5340 sizeBest
.IncTo(itemRect
.GetSize());
5343 sizeBest
.IncBy(2*ofs
);
5346 // If we have the scrollbars we need to account for them too. And to
5347 // make sure the scrollbars status is up to date we need to call this
5348 // function to set them.
5349 m_mainWin
->RecalculatePositions(true /* no refresh */);
5351 // Unfortunately we can't use wxWindow::HasScrollbar() here as we need
5352 // to use m_mainWin client/virtual size for determination of whether we
5353 // use scrollbars and not the size of this window itself. Maybe that
5354 // function should be extended to work correctly in the case when our
5355 // scrollbars manage a different window from this one but currently it
5357 const wxSize sizeClient
= m_mainWin
->GetClientSize();
5358 const wxSize sizeVirt
= m_mainWin
->GetVirtualSize();
5360 if ( sizeVirt
.x
> sizeClient
.x
/* HasScrollbar(wxHORIZONTAL) */ )
5361 sizeBest
.y
+= wxSystemSettings::GetMetric(wxSYS_HSCROLL_Y
);
5363 if ( sizeVirt
.y
> sizeClient
.y
/* HasScrollbar(wxVERTICAL) */ )
5364 sizeBest
.x
+= wxSystemSettings::GetMetric(wxSYS_VSCROLL_X
);
5370 // ----------------------------------------------------------------------------
5371 // virtual list control support
5372 // ----------------------------------------------------------------------------
5374 wxString
wxGenericListCtrl::OnGetItemText(long WXUNUSED(item
), long WXUNUSED(col
)) const
5376 // this is a pure virtual function, in fact - which is not really pure
5377 // because the controls which are not virtual don't need to implement it
5378 wxFAIL_MSG( wxT("wxGenericListCtrl::OnGetItemText not supposed to be called") );
5380 return wxEmptyString
;
5383 int wxGenericListCtrl::OnGetItemImage(long WXUNUSED(item
)) const
5385 wxCHECK_MSG(!GetImageList(wxIMAGE_LIST_SMALL
),
5387 wxT("List control has an image list, OnGetItemImage or OnGetItemColumnImage should be overridden."));
5391 int wxGenericListCtrl::OnGetItemColumnImage(long item
, long column
) const
5394 return OnGetItemImage(item
);
5400 wxGenericListCtrl::OnGetItemAttr(long WXUNUSED_UNLESS_DEBUG(item
)) const
5402 wxASSERT_MSG( item
>= 0 && item
< GetItemCount(),
5403 wxT("invalid item index in OnGetItemAttr()") );
5405 // no attributes by default
5409 void wxGenericListCtrl::SetItemCount(long count
)
5411 wxASSERT_MSG( IsVirtual(), wxT("this is for virtual controls only") );
5413 m_mainWin
->SetItemCount(count
);
5416 void wxGenericListCtrl::RefreshItem(long item
)
5418 m_mainWin
->RefreshLine(item
);
5421 void wxGenericListCtrl::RefreshItems(long itemFrom
, long itemTo
)
5423 m_mainWin
->RefreshLines(itemFrom
, itemTo
);
5426 void wxGenericListCtrl::EnableBellOnNoMatch( bool on
)
5428 m_mainWin
->EnableBellOnNoMatch(on
);
5431 // Generic wxListCtrl is more or less a container for two other
5432 // windows which drawings are done upon. These are namely
5433 // 'm_headerWin' and 'm_mainWin'.
5434 // Here we override 'virtual wxWindow::Refresh()' to mimic the
5435 // behaviour wxListCtrl has under wxMSW.
5437 void wxGenericListCtrl::Refresh(bool eraseBackground
, const wxRect
*rect
)
5441 // The easy case, no rectangle specified.
5443 m_headerWin
->Refresh(eraseBackground
);
5446 m_mainWin
->Refresh(eraseBackground
);
5450 // Refresh the header window
5453 wxRect rectHeader
= m_headerWin
->GetRect();
5454 rectHeader
.Intersect(*rect
);
5455 if (rectHeader
.GetWidth() && rectHeader
.GetHeight())
5458 m_headerWin
->GetPosition(&x
, &y
);
5459 rectHeader
.Offset(-x
, -y
);
5460 m_headerWin
->Refresh(eraseBackground
, &rectHeader
);
5464 // Refresh the main window
5467 wxRect rectMain
= m_mainWin
->GetRect();
5468 rectMain
.Intersect(*rect
);
5469 if (rectMain
.GetWidth() && rectMain
.GetHeight())
5472 m_mainWin
->GetPosition(&x
, &y
);
5473 rectMain
.Offset(-x
, -y
);
5474 m_mainWin
->Refresh(eraseBackground
, &rectMain
);
5480 void wxGenericListCtrl::Update()
5484 if ( m_mainWin
->m_dirty
)
5485 m_mainWin
->RecalculatePositions();
5487 m_mainWin
->Update();
5491 m_headerWin
->Update();
5494 #endif // wxUSE_LISTCTRL