1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/generic/listctrl.cpp
3 // Purpose: generic implementation of wxListCtrl
4 // Author: Robert Roebling
5 // Vadim Zeitlin (virtual list control support)
6 // Copyright: (c) 1998 Robert Roebling
7 // Licence: wxWindows licence
8 /////////////////////////////////////////////////////////////////////////////
12 // 1. we need to implement searching/sorting for virtual controls somehow
13 // 2. when changing selection the lines are refreshed twice
16 // For compilers that support precompilation, includes "wx.h".
17 #include "wx/wxprec.h"
25 #include "wx/listctrl.h"
28 #include "wx/scrolwin.h"
30 #include "wx/settings.h"
31 #include "wx/dynarray.h"
32 #include "wx/dcclient.h"
33 #include "wx/dcscreen.h"
35 #include "wx/settings.h"
39 #include "wx/imaglist.h"
40 #include "wx/renderer.h"
41 #include "wx/generic/private/listctrl.h"
44 #include "wx/osx/private.h"
47 #if defined(__WXMSW__) && !defined(__WXWINCE__) && !defined(__WXUNIVERSAL__)
48 #define "wx/msw/wrapwin.h"
51 // NOTE: If using the wxListBox visual attributes works everywhere then this can
52 // be removed, as well as the #else case below.
53 #define _USE_VISATTR 0
56 // ----------------------------------------------------------------------------
58 // ----------------------------------------------------------------------------
60 // // the height of the header window (FIXME: should depend on its font!)
61 // static const int HEADER_HEIGHT = 23;
63 static const int SCROLL_UNIT_X
= 15;
65 // the spacing between the lines (in report mode)
66 static const int LINE_SPACING
= 0;
68 // extra margins around the text label
70 static const int EXTRA_WIDTH
= 6;
72 static const int EXTRA_WIDTH
= 4;
76 static const int EXTRA_HEIGHT
= 6;
78 static const int EXTRA_HEIGHT
= 4;
81 // margin between the window and the items
82 static const int EXTRA_BORDER_X
= 2;
83 static const int EXTRA_BORDER_Y
= 2;
85 // offset for the header window
86 static const int HEADER_OFFSET_X
= 0;
87 static const int HEADER_OFFSET_Y
= 0;
89 // margin between rows of icons in [small] icon view
90 static const int MARGIN_BETWEEN_ROWS
= 6;
92 // when autosizing the columns, add some slack
93 static const int AUTOSIZE_COL_MARGIN
= 10;
95 // default width for the header columns
96 static const int WIDTH_COL_DEFAULT
= 80;
98 // the space between the image and the text in the report mode
99 static const int IMAGE_MARGIN_IN_REPORT_MODE
= 5;
101 // the space between the image and the text in the report mode in header
102 static const int HEADER_IMAGE_MARGIN_IN_REPORT_MODE
= 2;
106 // ----------------------------------------------------------------------------
107 // arrays/list implementations
108 // ----------------------------------------------------------------------------
110 #include "wx/listimpl.cpp"
111 WX_DEFINE_LIST(wxListItemDataList
)
113 #include "wx/arrimpl.cpp"
114 WX_DEFINE_OBJARRAY(wxListLineDataArray
)
116 #include "wx/listimpl.cpp"
117 WX_DEFINE_LIST(wxListHeaderDataList
)
120 // ----------------------------------------------------------------------------
122 // ----------------------------------------------------------------------------
124 wxListItemData::~wxListItemData()
126 // in the virtual list control the attributes are managed by the main
127 // program, so don't delete them
128 if ( !m_owner
->IsVirtual() )
134 void wxListItemData::Init()
142 wxListItemData::wxListItemData(wxListMainWindow
*owner
)
148 if ( owner
->InReportView() )
154 void wxListItemData::SetItem( const wxListItem
&info
)
156 if ( info
.m_mask
& wxLIST_MASK_TEXT
)
157 SetText(info
.m_text
);
158 if ( info
.m_mask
& wxLIST_MASK_IMAGE
)
159 m_image
= info
.m_image
;
160 if ( info
.m_mask
& wxLIST_MASK_DATA
)
161 m_data
= info
.m_data
;
163 if ( info
.HasAttributes() )
166 m_attr
->AssignFrom(*info
.GetAttributes());
168 m_attr
= new wxListItemAttr(*info
.GetAttributes());
176 m_rect
->width
= info
.m_width
;
180 void wxListItemData::SetPosition( int x
, int y
)
182 wxCHECK_RET( m_rect
, wxT("unexpected SetPosition() call") );
188 void wxListItemData::SetSize( int width
, int height
)
190 wxCHECK_RET( m_rect
, wxT("unexpected SetSize() call") );
193 m_rect
->width
= width
;
195 m_rect
->height
= height
;
198 bool wxListItemData::IsHit( int x
, int y
) const
200 wxCHECK_MSG( m_rect
, false, wxT("can't be called in this mode") );
202 return wxRect(GetX(), GetY(), GetWidth(), GetHeight()).Contains(x
, y
);
205 int wxListItemData::GetX() const
207 wxCHECK_MSG( m_rect
, 0, wxT("can't be called in this mode") );
212 int wxListItemData::GetY() const
214 wxCHECK_MSG( m_rect
, 0, wxT("can't be called in this mode") );
219 int wxListItemData::GetWidth() const
221 wxCHECK_MSG( m_rect
, 0, wxT("can't be called in this mode") );
223 return m_rect
->width
;
226 int wxListItemData::GetHeight() const
228 wxCHECK_MSG( m_rect
, 0, wxT("can't be called in this mode") );
230 return m_rect
->height
;
233 void wxListItemData::GetItem( wxListItem
&info
) const
235 long mask
= info
.m_mask
;
237 // by default, get everything for backwards compatibility
240 if ( mask
& wxLIST_MASK_TEXT
)
241 info
.m_text
= m_text
;
242 if ( mask
& wxLIST_MASK_IMAGE
)
243 info
.m_image
= m_image
;
244 if ( mask
& wxLIST_MASK_DATA
)
245 info
.m_data
= m_data
;
249 if ( m_attr
->HasTextColour() )
250 info
.SetTextColour(m_attr
->GetTextColour());
251 if ( m_attr
->HasBackgroundColour() )
252 info
.SetBackgroundColour(m_attr
->GetBackgroundColour());
253 if ( m_attr
->HasFont() )
254 info
.SetFont(m_attr
->GetFont());
258 //-----------------------------------------------------------------------------
260 //-----------------------------------------------------------------------------
262 void wxListHeaderData::Init()
274 wxListHeaderData::wxListHeaderData()
279 wxListHeaderData::wxListHeaderData( const wxListItem
&item
)
286 void wxListHeaderData::SetItem( const wxListItem
&item
)
288 m_mask
= item
.m_mask
;
290 if ( m_mask
& wxLIST_MASK_TEXT
)
291 m_text
= item
.m_text
;
293 if ( m_mask
& wxLIST_MASK_IMAGE
)
294 m_image
= item
.m_image
;
296 if ( m_mask
& wxLIST_MASK_FORMAT
)
297 m_format
= item
.m_format
;
299 if ( m_mask
& wxLIST_MASK_WIDTH
)
300 SetWidth(item
.m_width
);
302 if ( m_mask
& wxLIST_MASK_STATE
)
303 SetState(item
.m_state
);
306 void wxListHeaderData::SetPosition( int x
, int y
)
312 void wxListHeaderData::SetHeight( int h
)
317 void wxListHeaderData::SetWidth( int w
)
319 m_width
= w
< 0 ? WIDTH_COL_DEFAULT
: w
;
322 void wxListHeaderData::SetState( int flag
)
327 void wxListHeaderData::SetFormat( int format
)
332 bool wxListHeaderData::HasImage() const
334 return m_image
!= -1;
337 bool wxListHeaderData::IsHit( int x
, int y
) const
339 return ((x
>= m_xpos
) && (x
<= m_xpos
+m_width
) && (y
>= m_ypos
) && (y
<= m_ypos
+m_height
));
342 void wxListHeaderData::GetItem( wxListItem
& item
)
344 long mask
= item
.m_mask
;
347 // by default, get everything for backwards compatibility
351 if ( mask
& wxLIST_MASK_STATE
)
352 item
.m_state
= m_state
;
353 if ( mask
& wxLIST_MASK_TEXT
)
354 item
.m_text
= m_text
;
355 if ( mask
& wxLIST_MASK_IMAGE
)
356 item
.m_image
= m_image
;
357 if ( mask
& wxLIST_MASK_WIDTH
)
358 item
.m_width
= m_width
;
359 if ( mask
& wxLIST_MASK_FORMAT
)
360 item
.m_format
= m_format
;
363 int wxListHeaderData::GetImage() const
368 int wxListHeaderData::GetWidth() const
373 int wxListHeaderData::GetFormat() const
378 int wxListHeaderData::GetState() const
383 //-----------------------------------------------------------------------------
385 //-----------------------------------------------------------------------------
387 inline int wxListLineData::GetMode() const
389 return m_owner
->GetListCtrl()->GetWindowStyleFlag() & wxLC_MASK_TYPE
;
392 inline bool wxListLineData::InReportView() const
394 return m_owner
->HasFlag(wxLC_REPORT
);
397 inline bool wxListLineData::IsVirtual() const
399 return m_owner
->IsVirtual();
402 wxListLineData::wxListLineData( wxListMainWindow
*owner
)
406 if ( InReportView() )
409 m_gi
= new GeometryInfo
;
411 m_highlighted
= false;
413 InitItems( GetMode() == wxLC_REPORT
? m_owner
->GetColumnCount() : 1 );
416 void wxListLineData::CalculateSize( wxDC
*dc
, int spacing
)
418 wxListItemDataList::compatibility_iterator node
= m_items
.GetFirst();
419 wxCHECK_RET( node
, wxT("no subitems at all??") );
421 wxListItemData
*item
= node
->GetData();
429 case wxLC_SMALL_ICON
:
430 m_gi
->m_rectAll
.width
= spacing
;
437 m_gi
->m_rectLabel
.width
=
438 m_gi
->m_rectLabel
.height
= 0;
442 dc
->GetTextExtent( s
, &lw
, &lh
);
446 m_gi
->m_rectAll
.height
= spacing
+ lh
;
448 m_gi
->m_rectAll
.width
= lw
;
450 m_gi
->m_rectLabel
.width
= lw
;
451 m_gi
->m_rectLabel
.height
= lh
;
454 if (item
->HasImage())
457 m_owner
->GetImageSize( item
->GetImage(), w
, h
);
458 m_gi
->m_rectIcon
.width
= w
+ 8;
459 m_gi
->m_rectIcon
.height
= h
+ 8;
461 if ( m_gi
->m_rectIcon
.width
> m_gi
->m_rectAll
.width
)
462 m_gi
->m_rectAll
.width
= m_gi
->m_rectIcon
.width
;
463 if ( m_gi
->m_rectIcon
.height
+ lh
> m_gi
->m_rectAll
.height
- 4 )
464 m_gi
->m_rectAll
.height
= m_gi
->m_rectIcon
.height
+ lh
+ 4;
467 if ( item
->HasText() )
469 m_gi
->m_rectHighlight
.width
= m_gi
->m_rectLabel
.width
;
470 m_gi
->m_rectHighlight
.height
= m_gi
->m_rectLabel
.height
;
472 else // no text, highlight the icon
474 m_gi
->m_rectHighlight
.width
= m_gi
->m_rectIcon
.width
;
475 m_gi
->m_rectHighlight
.height
= m_gi
->m_rectIcon
.height
;
480 s
= item
->GetTextForMeasuring();
482 dc
->GetTextExtent( s
, &lw
, &lh
);
486 m_gi
->m_rectLabel
.width
= lw
;
487 m_gi
->m_rectLabel
.height
= lh
;
489 m_gi
->m_rectAll
.width
= lw
;
490 m_gi
->m_rectAll
.height
= lh
;
492 if (item
->HasImage())
495 m_owner
->GetImageSize( item
->GetImage(), w
, h
);
496 m_gi
->m_rectIcon
.width
= w
;
497 m_gi
->m_rectIcon
.height
= h
;
499 m_gi
->m_rectAll
.width
+= 4 + w
;
500 if (h
> m_gi
->m_rectAll
.height
)
501 m_gi
->m_rectAll
.height
= h
;
504 m_gi
->m_rectHighlight
.width
= m_gi
->m_rectAll
.width
;
505 m_gi
->m_rectHighlight
.height
= m_gi
->m_rectAll
.height
;
509 wxFAIL_MSG( wxT("unexpected call to SetSize") );
513 wxFAIL_MSG( wxT("unknown mode") );
518 void wxListLineData::SetPosition( int x
, int y
, int spacing
)
520 wxListItemDataList::compatibility_iterator node
= m_items
.GetFirst();
521 wxCHECK_RET( node
, wxT("no subitems at all??") );
523 wxListItemData
*item
= node
->GetData();
528 case wxLC_SMALL_ICON
:
529 m_gi
->m_rectAll
.x
= x
;
530 m_gi
->m_rectAll
.y
= y
;
532 if ( item
->HasImage() )
534 m_gi
->m_rectIcon
.x
= m_gi
->m_rectAll
.x
+ 4 +
535 (m_gi
->m_rectAll
.width
- m_gi
->m_rectIcon
.width
) / 2;
536 m_gi
->m_rectIcon
.y
= m_gi
->m_rectAll
.y
+ 4;
539 if ( item
->HasText() )
541 if (m_gi
->m_rectAll
.width
> spacing
)
542 m_gi
->m_rectLabel
.x
= m_gi
->m_rectAll
.x
+ (EXTRA_WIDTH
/2);
544 m_gi
->m_rectLabel
.x
= m_gi
->m_rectAll
.x
+ (EXTRA_WIDTH
/2) + (spacing
/ 2) - (m_gi
->m_rectLabel
.width
/ 2);
545 m_gi
->m_rectLabel
.y
= m_gi
->m_rectAll
.y
+ m_gi
->m_rectAll
.height
+ 2 - m_gi
->m_rectLabel
.height
;
546 m_gi
->m_rectHighlight
.x
= m_gi
->m_rectLabel
.x
- 2;
547 m_gi
->m_rectHighlight
.y
= m_gi
->m_rectLabel
.y
- 2;
549 else // no text, highlight the icon
551 m_gi
->m_rectHighlight
.x
= m_gi
->m_rectIcon
.x
- 4;
552 m_gi
->m_rectHighlight
.y
= m_gi
->m_rectIcon
.y
- 4;
557 m_gi
->m_rectAll
.x
= x
;
558 m_gi
->m_rectAll
.y
= y
;
560 m_gi
->m_rectHighlight
.x
= m_gi
->m_rectAll
.x
;
561 m_gi
->m_rectHighlight
.y
= m_gi
->m_rectAll
.y
;
562 m_gi
->m_rectLabel
.y
= m_gi
->m_rectAll
.y
+ 2;
564 if (item
->HasImage())
566 m_gi
->m_rectIcon
.x
= m_gi
->m_rectAll
.x
+ 2;
567 m_gi
->m_rectIcon
.y
= m_gi
->m_rectAll
.y
+ 2;
568 m_gi
->m_rectLabel
.x
= m_gi
->m_rectAll
.x
+ 4 + (EXTRA_WIDTH
/2) + m_gi
->m_rectIcon
.width
;
572 m_gi
->m_rectLabel
.x
= m_gi
->m_rectAll
.x
+ (EXTRA_WIDTH
/2);
577 wxFAIL_MSG( wxT("unexpected call to SetPosition") );
581 wxFAIL_MSG( wxT("unknown mode") );
586 void wxListLineData::InitItems( int num
)
588 for (int i
= 0; i
< num
; i
++)
589 m_items
.Append( new wxListItemData(m_owner
) );
592 void wxListLineData::SetItem( int index
, const wxListItem
&info
)
594 wxListItemDataList::compatibility_iterator node
= m_items
.Item( index
);
595 wxCHECK_RET( node
, wxT("invalid column index in SetItem") );
597 wxListItemData
*item
= node
->GetData();
598 item
->SetItem( info
);
601 void wxListLineData::GetItem( int index
, wxListItem
&info
)
603 wxListItemDataList::compatibility_iterator node
= m_items
.Item( index
);
606 wxListItemData
*item
= node
->GetData();
607 item
->GetItem( info
);
611 wxString
wxListLineData::GetText(int index
) const
615 wxListItemDataList::compatibility_iterator node
= m_items
.Item( index
);
618 wxListItemData
*item
= node
->GetData();
625 void wxListLineData::SetText( int index
, const wxString
& s
)
627 wxListItemDataList::compatibility_iterator node
= m_items
.Item( index
);
630 wxListItemData
*item
= node
->GetData();
635 void wxListLineData::SetImage( int index
, int image
)
637 wxListItemDataList::compatibility_iterator node
= m_items
.Item( index
);
638 wxCHECK_RET( node
, wxT("invalid column index in SetImage()") );
640 wxListItemData
*item
= node
->GetData();
641 item
->SetImage(image
);
644 int wxListLineData::GetImage( int index
) const
646 wxListItemDataList::compatibility_iterator node
= m_items
.Item( index
);
647 wxCHECK_MSG( node
, -1, wxT("invalid column index in GetImage()") );
649 wxListItemData
*item
= node
->GetData();
650 return item
->GetImage();
653 wxListItemAttr
*wxListLineData::GetAttr() const
655 wxListItemDataList::compatibility_iterator node
= m_items
.GetFirst();
656 wxCHECK_MSG( node
, NULL
, wxT("invalid column index in GetAttr()") );
658 wxListItemData
*item
= node
->GetData();
659 return item
->GetAttr();
662 void wxListLineData::SetAttr(wxListItemAttr
*attr
)
664 wxListItemDataList::compatibility_iterator node
= m_items
.GetFirst();
665 wxCHECK_RET( node
, wxT("invalid column index in SetAttr()") );
667 wxListItemData
*item
= node
->GetData();
671 void wxListLineData::ApplyAttributes(wxDC
*dc
,
672 const wxRect
& rectHL
,
676 const wxListItemAttr
* const attr
= GetAttr();
678 wxWindow
* const listctrl
= m_owner
->GetParent();
680 const bool hasFocus
= listctrl
->HasFocus()
681 #if defined(__WXMAC__) && !defined(__WXUNIVERSAL__) && wxOSX_USE_CARBON
682 && IsControlActive( (ControlRef
)listctrl
->GetHandle() )
688 // don't use foreground colour for drawing highlighted items - this might
689 // make them completely invisible (and there is no way to do bit
690 // arithmetics on wxColour, unfortunately)
701 colText
= wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHTTEXT
);
703 colText
= wxSystemSettings::GetColour(wxSYS_COLOUR_LISTBOXHIGHLIGHTTEXT
);
706 else if ( attr
&& attr
->HasTextColour() )
707 colText
= attr
->GetTextColour();
709 colText
= listctrl
->GetForegroundColour();
711 dc
->SetTextForeground(colText
);
715 if ( attr
&& attr
->HasFont() )
716 font
= attr
->GetFont();
718 font
= listctrl
->GetFont();
725 // Use the renderer method to ensure that the selected items use the
727 int flags
= wxCONTROL_SELECTED
;
729 flags
|= wxCONTROL_FOCUSED
;
731 flags
|= wxCONTROL_CURRENT
;
732 wxRendererNative::Get().
733 DrawItemSelectionRect( m_owner
, *dc
, rectHL
, flags
);
735 else if ( attr
&& attr
->HasBackgroundColour() )
737 // Draw the background using the items custom background colour.
738 dc
->SetBrush(attr
->GetBackgroundColour());
739 dc
->SetPen(*wxTRANSPARENT_PEN
);
740 dc
->DrawRectangle(rectHL
);
743 // just for debugging to better see where the items are
745 dc
->SetPen(*wxRED_PEN
);
746 dc
->SetBrush(*wxTRANSPARENT_BRUSH
);
747 dc
->DrawRectangle( m_gi
->m_rectAll
);
748 dc
->SetPen(*wxGREEN_PEN
);
749 dc
->DrawRectangle( m_gi
->m_rectIcon
);
753 void wxListLineData::Draw(wxDC
*dc
, bool current
)
755 wxListItemDataList::compatibility_iterator node
= m_items
.GetFirst();
756 wxCHECK_RET( node
, wxT("no subitems at all??") );
758 ApplyAttributes(dc
, m_gi
->m_rectHighlight
, IsHighlighted(), current
);
760 wxListItemData
*item
= node
->GetData();
761 if (item
->HasImage())
763 // centre the image inside our rectangle, this looks nicer when items
764 // ae aligned in a row
765 const wxRect
& rectIcon
= m_gi
->m_rectIcon
;
767 m_owner
->DrawImage(item
->GetImage(), dc
, rectIcon
.x
, rectIcon
.y
);
772 const wxRect
& rectLabel
= m_gi
->m_rectLabel
;
774 wxDCClipper
clipper(*dc
, rectLabel
);
775 dc
->DrawText(item
->GetText(), rectLabel
.x
, rectLabel
.y
);
779 void wxListLineData::DrawInReportMode( wxDC
*dc
,
781 const wxRect
& rectHL
,
785 // TODO: later we should support setting different attributes for
786 // different columns - to do it, just add "col" argument to
787 // GetAttr() and move these lines into the loop below
789 ApplyAttributes(dc
, rectHL
, highlighted
, current
);
791 wxCoord x
= rect
.x
+ HEADER_OFFSET_X
,
792 yMid
= rect
.y
+ rect
.height
/2;
794 // This probably needs to be done
795 // on all platforms as the icons
796 // otherwise nearly touch the border
801 for ( wxListItemDataList::compatibility_iterator node
= m_items
.GetFirst();
803 node
= node
->GetNext(), col
++ )
805 wxListItemData
*item
= node
->GetData();
807 int width
= m_owner
->GetColumnWidth(col
);
812 const int wText
= width
;
813 wxDCClipper
clipper(*dc
, xOld
, rect
.y
, wText
, rect
.height
);
815 if ( item
->HasImage() )
818 m_owner
->GetImageSize( item
->GetImage(), ix
, iy
);
819 m_owner
->DrawImage( item
->GetImage(), dc
, xOld
, yMid
- iy
/2 );
821 ix
+= IMAGE_MARGIN_IN_REPORT_MODE
;
827 if ( item
->HasText() )
828 DrawTextFormatted(dc
, item
->GetText(), col
, xOld
, yMid
, width
);
832 void wxListLineData::DrawTextFormatted(wxDC
*dc
,
833 const wxString
& textOrig
,
839 // we don't support displaying multiple lines currently (and neither does
840 // wxMSW FWIW) so just merge all the lines
841 wxString
text(textOrig
);
842 text
.Replace(wxT("\n"), wxT(" "));
845 dc
->GetTextExtent(text
, &w
, &h
);
847 const wxCoord y
= yMid
- (h
+ 1)/2;
849 wxDCClipper
clipper(*dc
, x
, y
, width
, h
);
851 // determine if the string can fit inside the current width
854 // it can, draw it using the items alignment
856 m_owner
->GetColumn(col
, item
);
857 switch ( item
.GetAlign() )
859 case wxLIST_FORMAT_LEFT
:
863 case wxLIST_FORMAT_RIGHT
:
867 case wxLIST_FORMAT_CENTER
:
868 x
+= (width
- w
) / 2;
872 wxFAIL_MSG( wxT("unknown list item format") );
876 dc
->DrawText(text
, x
, y
);
878 else // otherwise, truncate and add an ellipsis if possible
880 // determine the base width
881 wxString
ellipsis(wxT("..."));
883 dc
->GetTextExtent(ellipsis
, &base_w
, &h
);
885 // continue until we have enough space or only one character left
887 size_t len
= text
.length();
888 wxString drawntext
= text
.Left(len
);
891 dc
->GetTextExtent(drawntext
.Last(), &w_c
, &h_c
);
892 drawntext
.RemoveLast();
895 if (w
+ base_w
<= width
)
899 // if still not enough space, remove ellipsis characters
900 while (ellipsis
.length() > 0 && w
+ base_w
> width
)
902 ellipsis
= ellipsis
.Left(ellipsis
.length() - 1);
903 dc
->GetTextExtent(ellipsis
, &base_w
, &h
);
907 dc
->DrawText(drawntext
, x
, y
);
908 dc
->DrawText(ellipsis
, x
+ w
, y
);
912 bool wxListLineData::Highlight( bool on
)
914 wxCHECK_MSG( !IsVirtual(), false, wxT("unexpected call to Highlight") );
916 if ( on
== m_highlighted
)
924 void wxListLineData::ReverseHighlight( void )
926 Highlight(!IsHighlighted());
929 //-----------------------------------------------------------------------------
930 // wxListHeaderWindow
931 //-----------------------------------------------------------------------------
933 BEGIN_EVENT_TABLE(wxListHeaderWindow
,wxWindow
)
934 EVT_PAINT (wxListHeaderWindow::OnPaint
)
935 EVT_MOUSE_EVENTS (wxListHeaderWindow::OnMouse
)
938 void wxListHeaderWindow::Init()
940 m_currentCursor
= NULL
;
941 m_isDragging
= false;
943 m_sendSetColumnWidth
= false;
946 wxListHeaderWindow::wxListHeaderWindow()
951 m_resizeCursor
= NULL
;
954 bool wxListHeaderWindow::Create( wxWindow
*win
,
956 wxListMainWindow
*owner
,
960 const wxString
&name
)
962 if ( !wxWindow::Create(win
, id
, pos
, size
, style
, name
) )
968 m_resizeCursor
= new wxCursor( wxCURSOR_SIZEWE
);
971 wxVisualAttributes attr
= wxPanel::GetClassDefaultAttributes();
972 SetOwnForegroundColour( attr
.colFg
);
973 SetOwnBackgroundColour( attr
.colBg
);
975 SetOwnFont( attr
.font
);
977 SetOwnForegroundColour( wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT
));
978 SetOwnBackgroundColour( wxSystemSettings::GetColour(wxSYS_COLOUR_BTNFACE
));
980 SetOwnFont( wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT
));
986 wxListHeaderWindow::~wxListHeaderWindow()
988 delete m_resizeCursor
;
991 #ifdef __WXUNIVERSAL__
992 #include "wx/univ/renderer.h"
993 #include "wx/univ/theme.h"
996 // shift the DC origin to match the position of the main window horz
997 // scrollbar: this allows us to always use logical coords
998 void wxListHeaderWindow::AdjustDC(wxDC
& dc
)
1000 wxGenericListCtrl
*parent
= m_owner
->GetListCtrl();
1003 parent
->GetScrollPixelsPerUnit( &xpix
, NULL
);
1006 parent
->GetViewStart( &view_start
, NULL
);
1011 dc
.GetDeviceOrigin( &org_x
, &org_y
);
1013 // account for the horz scrollbar offset
1015 if (GetLayoutDirection() == wxLayout_RightToLeft
)
1017 // Maybe we just have to check for m_signX
1018 // in the DC, but I leave the #ifdef __WXGTK__
1020 dc
.SetDeviceOrigin( org_x
+ (view_start
* xpix
), org_y
);
1024 dc
.SetDeviceOrigin( org_x
- (view_start
* xpix
), org_y
);
1027 void wxListHeaderWindow::OnPaint( wxPaintEvent
&WXUNUSED(event
) )
1029 wxGenericListCtrl
*parent
= m_owner
->GetListCtrl();
1031 wxPaintDC
dc( this );
1035 dc
.SetFont( GetFont() );
1037 // width and height of the entire header window
1039 GetClientSize( &w
, &h
);
1040 parent
->CalcUnscrolledPosition(w
, 0, &w
, NULL
);
1042 dc
.SetBackgroundMode(wxBRUSHSTYLE_TRANSPARENT
);
1043 dc
.SetTextForeground(GetForegroundColour());
1045 int x
= HEADER_OFFSET_X
;
1046 int numColumns
= m_owner
->GetColumnCount();
1048 for ( int i
= 0; i
< numColumns
&& x
< w
; i
++ )
1050 m_owner
->GetColumn( i
, item
);
1051 int wCol
= item
.m_width
;
1057 if (!m_parent
->IsEnabled())
1058 flags
|= wxCONTROL_DISABLED
;
1060 // NB: The code below is not really Mac-specific, but since we are close
1061 // to 2.8 release and I don't have time to test on other platforms, I
1062 // defined this only for wxMac. If this behaviour is desired on
1063 // other platforms, please go ahead and revise or remove the #ifdef.
1065 if ( !m_owner
->IsVirtual() && (item
.m_mask
& wxLIST_MASK_STATE
) &&
1066 (item
.m_state
& wxLIST_STATE_SELECTED
) )
1067 flags
|= wxCONTROL_SELECTED
;
1071 flags
|= wxCONTROL_SPECIAL
; // mark as first column
1073 wxRendererNative::Get().DrawHeaderButton
1077 wxRect(x
, HEADER_OFFSET_Y
, cw
, ch
),
1081 // see if we have enough space for the column label
1083 // for this we need the width of the text
1086 dc
.GetTextExtent(item
.GetText(), &wLabel
, &hLabel
);
1087 wLabel
+= 2 * EXTRA_WIDTH
;
1089 // and the width of the icon, if any
1090 int ix
= 0, iy
= 0; // init them just to suppress the compiler warnings
1091 const int image
= item
.m_image
;
1092 wxImageList
*imageList
;
1095 imageList
= m_owner
->GetSmallImageList();
1098 imageList
->GetSize(image
, ix
, iy
);
1099 wLabel
+= ix
+ HEADER_IMAGE_MARGIN_IN_REPORT_MODE
;
1107 // ignore alignment if there is not enough space anyhow
1109 switch ( wLabel
< cw
? item
.GetAlign() : wxLIST_FORMAT_LEFT
)
1112 wxFAIL_MSG( wxT("unknown list item format") );
1115 case wxLIST_FORMAT_LEFT
:
1119 case wxLIST_FORMAT_RIGHT
:
1120 xAligned
= x
+ cw
- wLabel
;
1123 case wxLIST_FORMAT_CENTER
:
1124 xAligned
= x
+ (cw
- wLabel
) / 2;
1128 // draw the text and image clipping them so that they
1129 // don't overwrite the column boundary
1130 wxDCClipper
clipper(dc
, x
, HEADER_OFFSET_Y
, cw
, h
);
1132 // if we have an image, draw it on the right of the label
1139 xAligned
+ wLabel
- ix
- HEADER_IMAGE_MARGIN_IN_REPORT_MODE
,
1140 HEADER_OFFSET_Y
+ (h
- iy
)/2,
1141 wxIMAGELIST_DRAW_TRANSPARENT
1145 dc
.DrawText( item
.GetText(),
1146 xAligned
+ EXTRA_WIDTH
, (h
- hLabel
) / 2 );
1151 // Fill in what's missing to the right of the columns, otherwise we will
1152 // leave an unpainted area when columns are removed (and it looks better)
1155 wxRendererNative::Get().DrawHeaderButton
1159 wxRect(x
, HEADER_OFFSET_Y
, w
- x
, h
),
1160 wxCONTROL_DIRTY
// mark as last column
1165 void wxListHeaderWindow::OnInternalIdle()
1167 wxWindow::OnInternalIdle();
1169 if (m_sendSetColumnWidth
)
1171 m_owner
->SetColumnWidth( m_colToSend
, m_widthToSend
);
1172 m_sendSetColumnWidth
= false;
1176 void wxListHeaderWindow::DrawCurrent()
1179 // m_owner->SetColumnWidth( m_column, m_currentX - m_minX );
1180 m_sendSetColumnWidth
= true;
1181 m_colToSend
= m_column
;
1182 m_widthToSend
= m_currentX
- m_minX
;
1184 int x1
= m_currentX
;
1186 m_owner
->ClientToScreen( &x1
, &y1
);
1188 int x2
= m_currentX
;
1190 m_owner
->GetClientSize( NULL
, &y2
);
1191 m_owner
->ClientToScreen( &x2
, &y2
);
1194 dc
.SetLogicalFunction( wxINVERT
);
1195 dc
.SetPen( wxPen(*wxBLACK
, 2) );
1196 dc
.SetBrush( *wxTRANSPARENT_BRUSH
);
1200 dc
.DrawLine( x1
, y1
, x2
, y2
);
1202 dc
.SetLogicalFunction( wxCOPY
);
1204 dc
.SetPen( wxNullPen
);
1205 dc
.SetBrush( wxNullBrush
);
1209 void wxListHeaderWindow::OnMouse( wxMouseEvent
&event
)
1211 wxGenericListCtrl
*parent
= m_owner
->GetListCtrl();
1213 // we want to work with logical coords
1215 parent
->CalcUnscrolledPosition(event
.GetX(), 0, &x
, NULL
);
1216 int y
= event
.GetY();
1220 SendListEvent(wxEVT_LIST_COL_DRAGGING
, event
.GetPosition());
1222 // we don't draw the line beyond our window, but we allow dragging it
1225 GetClientSize( &w
, NULL
);
1226 parent
->CalcUnscrolledPosition(w
, 0, &w
, NULL
);
1229 // erase the line if it was drawn
1230 if ( m_currentX
< w
)
1233 if (event
.ButtonUp())
1236 m_isDragging
= false;
1238 m_owner
->SetColumnWidth( m_column
, m_currentX
- m_minX
);
1239 SendListEvent(wxEVT_LIST_COL_END_DRAG
, event
.GetPosition());
1246 m_currentX
= m_minX
+ 7;
1248 // draw in the new location
1249 if ( m_currentX
< w
)
1253 else // not dragging
1256 bool hit_border
= false;
1258 // end of the current column
1261 // find the column where this event occurred
1263 countCol
= m_owner
->GetColumnCount();
1264 for (col
= 0; col
< countCol
; col
++)
1266 xpos
+= m_owner
->GetColumnWidth( col
);
1269 if ( (abs(x
-xpos
) < 3) && (y
< 22) )
1271 // near the column border
1278 // inside the column
1285 if ( col
== countCol
)
1288 if (event
.LeftDown() || event
.RightUp())
1290 if (hit_border
&& event
.LeftDown())
1292 if ( SendListEvent(wxEVT_LIST_COL_BEGIN_DRAG
,
1293 event
.GetPosition()) )
1295 m_isDragging
= true;
1300 //else: column resizing was vetoed by the user code
1302 else // click on a column
1304 // record the selected state of the columns
1305 if (event
.LeftDown())
1307 for (int i
=0; i
< m_owner
->GetColumnCount(); i
++)
1310 m_owner
->GetColumn(i
, colItem
);
1311 long state
= colItem
.GetState();
1313 colItem
.SetState(state
| wxLIST_STATE_SELECTED
);
1315 colItem
.SetState(state
& ~wxLIST_STATE_SELECTED
);
1316 m_owner
->SetColumn(i
, colItem
);
1320 SendListEvent( event
.LeftDown()
1321 ? wxEVT_LIST_COL_CLICK
1322 : wxEVT_LIST_COL_RIGHT_CLICK
,
1323 event
.GetPosition());
1326 else if (event
.Moving())
1331 setCursor
= m_currentCursor
== wxSTANDARD_CURSOR
;
1332 m_currentCursor
= m_resizeCursor
;
1336 setCursor
= m_currentCursor
!= wxSTANDARD_CURSOR
;
1337 m_currentCursor
= wxSTANDARD_CURSOR
;
1341 SetCursor(*m_currentCursor
);
1346 bool wxListHeaderWindow::SendListEvent(wxEventType type
, const wxPoint
& pos
)
1348 wxWindow
*parent
= GetParent();
1349 wxListEvent
le( type
, parent
->GetId() );
1350 le
.SetEventObject( parent
);
1351 le
.m_pointDrag
= pos
;
1353 // the position should be relative to the parent window, not
1354 // this one for compatibility with MSW and common sense: the
1355 // user code doesn't know anything at all about this header
1356 // window, so why should it get positions relative to it?
1357 le
.m_pointDrag
.y
-= GetSize().y
;
1359 le
.m_col
= m_column
;
1360 return !parent
->GetEventHandler()->ProcessEvent( le
) || le
.IsAllowed();
1363 //-----------------------------------------------------------------------------
1364 // wxListRenameTimer (internal)
1365 //-----------------------------------------------------------------------------
1367 wxListRenameTimer::wxListRenameTimer( wxListMainWindow
*owner
)
1372 void wxListRenameTimer::Notify()
1374 m_owner
->OnRenameTimer();
1377 //-----------------------------------------------------------------------------
1378 // wxListFindTimer (internal)
1379 //-----------------------------------------------------------------------------
1381 void wxListFindTimer::Notify()
1383 m_owner
->OnFindTimer();
1386 //-----------------------------------------------------------------------------
1387 // wxListTextCtrlWrapper (internal)
1388 //-----------------------------------------------------------------------------
1390 BEGIN_EVENT_TABLE(wxListTextCtrlWrapper
, wxEvtHandler
)
1391 EVT_CHAR (wxListTextCtrlWrapper::OnChar
)
1392 EVT_KEY_UP (wxListTextCtrlWrapper::OnKeyUp
)
1393 EVT_KILL_FOCUS (wxListTextCtrlWrapper::OnKillFocus
)
1396 wxListTextCtrlWrapper::wxListTextCtrlWrapper(wxListMainWindow
*owner
,
1399 : m_startValue(owner
->GetItemText(itemEdit
)),
1400 m_itemEdited(itemEdit
)
1404 m_aboutToFinish
= false;
1406 wxGenericListCtrl
*parent
= m_owner
->GetListCtrl();
1408 wxRect rectLabel
= owner
->GetLineLabelRect(itemEdit
);
1410 parent
->CalcScrolledPosition(rectLabel
.x
, rectLabel
.y
,
1411 &rectLabel
.x
, &rectLabel
.y
);
1413 m_text
->Create(owner
, wxID_ANY
, m_startValue
,
1414 wxPoint(rectLabel
.x
-4,rectLabel
.y
-4),
1415 wxSize(rectLabel
.width
+11,rectLabel
.height
+8));
1418 m_text
->PushEventHandler(this);
1421 void wxListTextCtrlWrapper::EndEdit(EndReason reason
)
1423 m_aboutToFinish
= true;
1428 // Notify the owner about the changes
1431 // Even if vetoed, close the control (consistent with MSW)
1436 m_owner
->OnRenameCancelled(m_itemEdited
);
1442 // Don't generate any notifications for the control being destroyed
1443 // and don't set focus to it neither.
1449 void wxListTextCtrlWrapper::Finish( bool setfocus
)
1451 m_text
->RemoveEventHandler(this);
1452 m_owner
->ResetTextControl( m_text
);
1454 wxPendingDelete
.Append( this );
1457 m_owner
->SetFocus();
1460 bool wxListTextCtrlWrapper::AcceptChanges()
1462 const wxString value
= m_text
->GetValue();
1464 // notice that we should always call OnRenameAccept() to generate the "end
1465 // label editing" event, even if the user hasn't really changed anything
1466 if ( !m_owner
->OnRenameAccept(m_itemEdited
, value
) )
1468 // vetoed by the user
1472 // accepted, do rename the item (unless nothing changed)
1473 if ( value
!= m_startValue
)
1474 m_owner
->SetItemText(m_itemEdited
, value
);
1479 void wxListTextCtrlWrapper::OnChar( wxKeyEvent
&event
)
1481 if ( !CheckForEndEditKey(event
) )
1485 bool wxListTextCtrlWrapper::CheckForEndEditKey(const wxKeyEvent
& event
)
1487 switch ( event
.m_keyCode
)
1490 EndEdit( End_Accept
);
1494 EndEdit( End_Discard
);
1504 void wxListTextCtrlWrapper::OnKeyUp( wxKeyEvent
&event
)
1506 if (m_aboutToFinish
)
1508 // auto-grow the textctrl:
1509 wxSize parentSize
= m_owner
->GetSize();
1510 wxPoint myPos
= m_text
->GetPosition();
1511 wxSize mySize
= m_text
->GetSize();
1513 m_text
->GetTextExtent(m_text
->GetValue() + wxT("MM"), &sx
, &sy
);
1514 if (myPos
.x
+ sx
> parentSize
.x
)
1515 sx
= parentSize
.x
- myPos
.x
;
1518 m_text
->SetSize(sx
, wxDefaultCoord
);
1524 void wxListTextCtrlWrapper::OnKillFocus( wxFocusEvent
&event
)
1526 if ( !m_aboutToFinish
)
1528 if ( !AcceptChanges() )
1529 m_owner
->OnRenameCancelled( m_itemEdited
);
1534 // We must let the native text control handle focus
1538 //-----------------------------------------------------------------------------
1540 //-----------------------------------------------------------------------------
1542 BEGIN_EVENT_TABLE(wxListMainWindow
, wxWindow
)
1543 EVT_PAINT (wxListMainWindow::OnPaint
)
1544 EVT_MOUSE_EVENTS (wxListMainWindow::OnMouse
)
1545 EVT_CHAR_HOOK (wxListMainWindow::OnCharHook
)
1546 EVT_CHAR (wxListMainWindow::OnChar
)
1547 EVT_KEY_DOWN (wxListMainWindow::OnKeyDown
)
1548 EVT_KEY_UP (wxListMainWindow::OnKeyUp
)
1549 EVT_SET_FOCUS (wxListMainWindow::OnSetFocus
)
1550 EVT_KILL_FOCUS (wxListMainWindow::OnKillFocus
)
1551 EVT_SCROLLWIN (wxListMainWindow::OnScroll
)
1552 EVT_CHILD_FOCUS (wxListMainWindow::OnChildFocus
)
1555 void wxListMainWindow::Init()
1560 m_lineTo
= (size_t)-1;
1566 m_small_image_list
= NULL
;
1567 m_normal_image_list
= NULL
;
1569 m_small_spacing
= 30;
1570 m_normal_spacing
= 40;
1574 m_isCreated
= false;
1576 m_lastOnSame
= false;
1577 m_renameTimer
= new wxListRenameTimer( this );
1579 m_findBell
= 0; // default is to not ring bell at all
1580 m_textctrlWrapper
= NULL
;
1584 m_lineSelectSingleOnUp
=
1585 m_lineBeforeLastClicked
= (size_t)-1;
1588 wxListMainWindow::wxListMainWindow()
1593 m_highlightUnfocusedBrush
= NULL
;
1596 wxListMainWindow::wxListMainWindow( wxWindow
*parent
,
1599 const wxSize
& size
)
1600 : wxWindow( parent
, id
, pos
, size
,
1601 wxWANTS_CHARS
| wxBORDER_NONE
)
1605 m_highlightBrush
= new wxBrush
1607 wxSystemSettings::GetColour
1609 wxSYS_COLOUR_HIGHLIGHT
1614 m_highlightUnfocusedBrush
= new wxBrush
1616 wxSystemSettings::GetColour
1618 wxSYS_COLOUR_BTNSHADOW
1623 wxVisualAttributes attr
= wxGenericListCtrl::GetClassDefaultAttributes();
1624 SetOwnForegroundColour( attr
.colFg
);
1625 SetOwnBackgroundColour( attr
.colBg
);
1627 SetOwnFont( attr
.font
);
1630 wxListMainWindow::~wxListMainWindow()
1632 if ( m_textctrlWrapper
)
1633 m_textctrlWrapper
->EndEdit(wxListTextCtrlWrapper::End_Destroy
);
1636 WX_CLEAR_LIST(wxListHeaderDataList
, m_columns
);
1637 WX_CLEAR_ARRAY(m_aColWidths
);
1639 delete m_highlightBrush
;
1640 delete m_highlightUnfocusedBrush
;
1641 delete m_renameTimer
;
1645 void wxListMainWindow::SetReportView(bool inReportView
)
1647 const size_t count
= m_lines
.size();
1648 for ( size_t n
= 0; n
< count
; n
++ )
1650 m_lines
[n
].SetReportView(inReportView
);
1654 void wxListMainWindow::CacheLineData(size_t line
)
1656 wxGenericListCtrl
*listctrl
= GetListCtrl();
1658 wxListLineData
*ld
= GetDummyLine();
1660 size_t countCol
= GetColumnCount();
1661 for ( size_t col
= 0; col
< countCol
; col
++ )
1663 ld
->SetText(col
, listctrl
->OnGetItemText(line
, col
));
1664 ld
->SetImage(col
, listctrl
->OnGetItemColumnImage(line
, col
));
1667 ld
->SetAttr(listctrl
->OnGetItemAttr(line
));
1670 wxListLineData
*wxListMainWindow::GetDummyLine() const
1672 wxASSERT_MSG( !IsEmpty(), wxT("invalid line index") );
1673 wxASSERT_MSG( IsVirtual(), wxT("GetDummyLine() shouldn't be called") );
1675 wxListMainWindow
*self
= wxConstCast(this, wxListMainWindow
);
1677 // we need to recreate the dummy line if the number of columns in the
1678 // control changed as it would have the incorrect number of fields
1680 if ( !m_lines
.IsEmpty() &&
1681 m_lines
[0].m_items
.GetCount() != (size_t)GetColumnCount() )
1683 self
->m_lines
.Clear();
1686 if ( m_lines
.IsEmpty() )
1688 wxListLineData
*line
= new wxListLineData(self
);
1689 self
->m_lines
.Add(line
);
1691 // don't waste extra memory -- there never going to be anything
1692 // else/more in this array
1693 self
->m_lines
.Shrink();
1699 // ----------------------------------------------------------------------------
1700 // line geometry (report mode only)
1701 // ----------------------------------------------------------------------------
1703 wxCoord
wxListMainWindow::GetLineHeight() const
1705 // we cache the line height as calling GetTextExtent() is slow
1706 if ( !m_lineHeight
)
1708 wxListMainWindow
*self
= wxConstCast(this, wxListMainWindow
);
1710 wxClientDC
dc( self
);
1711 dc
.SetFont( GetFont() );
1714 dc
.GetTextExtent(wxT("H"), NULL
, &y
);
1716 if ( m_small_image_list
&& m_small_image_list
->GetImageCount() )
1719 m_small_image_list
->GetSize(0, iw
, ih
);
1724 self
->m_lineHeight
= y
+ LINE_SPACING
;
1727 return m_lineHeight
;
1730 wxCoord
wxListMainWindow::GetLineY(size_t line
) const
1732 wxASSERT_MSG( InReportView(), wxT("only works in report mode") );
1734 return LINE_SPACING
+ line
* GetLineHeight();
1737 wxRect
wxListMainWindow::GetLineRect(size_t line
) const
1739 if ( !InReportView() )
1740 return GetLine(line
)->m_gi
->m_rectAll
;
1743 rect
.x
= HEADER_OFFSET_X
;
1744 rect
.y
= GetLineY(line
);
1745 rect
.width
= GetHeaderWidth();
1746 rect
.height
= GetLineHeight();
1751 wxRect
wxListMainWindow::GetLineLabelRect(size_t line
) const
1753 if ( !InReportView() )
1754 return GetLine(line
)->m_gi
->m_rectLabel
;
1757 wxListLineData
*data
= GetLine(line
);
1758 wxListItemDataList::compatibility_iterator node
= data
->m_items
.GetFirst();
1761 wxListItemData
*item
= node
->GetData();
1762 if ( item
->HasImage() )
1765 GetImageSize( item
->GetImage(), ix
, iy
);
1766 image_x
= 3 + ix
+ IMAGE_MARGIN_IN_REPORT_MODE
;
1771 rect
.x
= image_x
+ HEADER_OFFSET_X
;
1772 rect
.y
= GetLineY(line
);
1773 rect
.width
= GetColumnWidth(0) - image_x
;
1774 rect
.height
= GetLineHeight();
1779 wxRect
wxListMainWindow::GetLineIconRect(size_t line
) const
1781 if ( !InReportView() )
1782 return GetLine(line
)->m_gi
->m_rectIcon
;
1784 wxListLineData
*ld
= GetLine(line
);
1785 wxASSERT_MSG( ld
->HasImage(), wxT("should have an image") );
1788 rect
.x
= HEADER_OFFSET_X
;
1789 rect
.y
= GetLineY(line
);
1790 GetImageSize(ld
->GetImage(), rect
.width
, rect
.height
);
1795 wxRect
wxListMainWindow::GetLineHighlightRect(size_t line
) const
1797 return InReportView() ? GetLineRect(line
)
1798 : GetLine(line
)->m_gi
->m_rectHighlight
;
1801 long wxListMainWindow::HitTestLine(size_t line
, int x
, int y
) const
1803 wxASSERT_MSG( line
< GetItemCount(), wxT("invalid line in HitTestLine") );
1805 wxListLineData
*ld
= GetLine(line
);
1807 if ( ld
->HasImage() && GetLineIconRect(line
).Contains(x
, y
) )
1808 return wxLIST_HITTEST_ONITEMICON
;
1810 // VS: Testing for "ld->HasText() || InReportView()" instead of
1811 // "ld->HasText()" is needed to make empty lines in report view
1813 if ( ld
->HasText() || InReportView() )
1815 wxRect rect
= InReportView() ? GetLineRect(line
)
1816 : GetLineLabelRect(line
);
1818 if ( rect
.Contains(x
, y
) )
1819 return wxLIST_HITTEST_ONITEMLABEL
;
1825 // ----------------------------------------------------------------------------
1826 // highlight (selection) handling
1827 // ----------------------------------------------------------------------------
1829 bool wxListMainWindow::IsHighlighted(size_t line
) const
1833 return m_selStore
.IsSelected(line
);
1837 wxListLineData
*ld
= GetLine(line
);
1838 wxCHECK_MSG( ld
, false, wxT("invalid index in IsHighlighted") );
1840 return ld
->IsHighlighted();
1844 void wxListMainWindow::HighlightLines( size_t lineFrom
,
1850 wxArrayInt linesChanged
;
1851 if ( !m_selStore
.SelectRange(lineFrom
, lineTo
, highlight
,
1854 // meny items changed state, refresh everything
1855 RefreshLines(lineFrom
, lineTo
);
1857 else // only a few items changed state, refresh only them
1859 size_t count
= linesChanged
.GetCount();
1860 for ( size_t n
= 0; n
< count
; n
++ )
1862 RefreshLine(linesChanged
[n
]);
1866 else // iterate over all items in non report view
1868 for ( size_t line
= lineFrom
; line
<= lineTo
; line
++ )
1870 if ( HighlightLine(line
, highlight
) )
1876 bool wxListMainWindow::HighlightLine( size_t line
, bool highlight
)
1882 changed
= m_selStore
.SelectItem(line
, highlight
);
1886 wxListLineData
*ld
= GetLine(line
);
1887 wxCHECK_MSG( ld
, false, wxT("invalid index in HighlightLine") );
1889 changed
= ld
->Highlight(highlight
);
1894 SendNotify( line
, highlight
? wxEVT_LIST_ITEM_SELECTED
1895 : wxEVT_LIST_ITEM_DESELECTED
);
1901 void wxListMainWindow::RefreshLine( size_t line
)
1903 if ( InReportView() )
1905 size_t visibleFrom
, visibleTo
;
1906 GetVisibleLinesRange(&visibleFrom
, &visibleTo
);
1908 if ( line
< visibleFrom
|| line
> visibleTo
)
1912 wxRect rect
= GetLineRect(line
);
1914 GetListCtrl()->CalcScrolledPosition( rect
.x
, rect
.y
, &rect
.x
, &rect
.y
);
1915 RefreshRect( rect
);
1918 void wxListMainWindow::RefreshLines( size_t lineFrom
, size_t lineTo
)
1920 // we suppose that they are ordered by caller
1921 wxASSERT_MSG( lineFrom
<= lineTo
, wxT("indices in disorder") );
1923 wxASSERT_MSG( lineTo
< GetItemCount(), wxT("invalid line range") );
1925 if ( InReportView() )
1927 size_t visibleFrom
, visibleTo
;
1928 GetVisibleLinesRange(&visibleFrom
, &visibleTo
);
1930 if ( lineFrom
< visibleFrom
)
1931 lineFrom
= visibleFrom
;
1932 if ( lineTo
> visibleTo
)
1937 rect
.y
= GetLineY(lineFrom
);
1938 rect
.width
= GetClientSize().x
;
1939 rect
.height
= GetLineY(lineTo
) - rect
.y
+ GetLineHeight();
1941 GetListCtrl()->CalcScrolledPosition( rect
.x
, rect
.y
, &rect
.x
, &rect
.y
);
1942 RefreshRect( rect
);
1946 // TODO: this should be optimized...
1947 for ( size_t line
= lineFrom
; line
<= lineTo
; line
++ )
1954 void wxListMainWindow::RefreshAfter( size_t lineFrom
)
1956 if ( InReportView() )
1958 size_t visibleFrom
, visibleTo
;
1959 GetVisibleLinesRange(&visibleFrom
, &visibleTo
);
1961 if ( lineFrom
< visibleFrom
)
1962 lineFrom
= visibleFrom
;
1963 else if ( lineFrom
> visibleTo
)
1968 rect
.y
= GetLineY(lineFrom
);
1969 GetListCtrl()->CalcScrolledPosition( rect
.x
, rect
.y
, &rect
.x
, &rect
.y
);
1971 wxSize size
= GetClientSize();
1972 rect
.width
= size
.x
;
1974 // refresh till the bottom of the window
1975 rect
.height
= size
.y
- rect
.y
;
1977 RefreshRect( rect
);
1981 // TODO: how to do it more efficiently?
1986 void wxListMainWindow::RefreshSelected()
1992 if ( InReportView() )
1994 GetVisibleLinesRange(&from
, &to
);
1999 to
= GetItemCount() - 1;
2002 if ( HasCurrent() && m_current
>= from
&& m_current
<= to
)
2003 RefreshLine(m_current
);
2005 for ( size_t line
= from
; line
<= to
; line
++ )
2007 // NB: the test works as expected even if m_current == -1
2008 if ( line
!= m_current
&& IsHighlighted(line
) )
2013 void wxListMainWindow::OnPaint( wxPaintEvent
&WXUNUSED(event
) )
2015 // Note: a wxPaintDC must be constructed even if no drawing is
2016 // done (a Windows requirement).
2017 wxPaintDC
dc( this );
2021 // nothing to draw or not the moment to draw it
2026 RecalculatePositions( false );
2028 GetListCtrl()->PrepareDC( dc
);
2031 GetListCtrl()->CalcScrolledPosition( 0, 0, &dev_x
, &dev_y
);
2033 dc
.SetFont( GetFont() );
2035 if ( InReportView() )
2037 int lineHeight
= GetLineHeight();
2039 size_t visibleFrom
, visibleTo
;
2040 GetVisibleLinesRange(&visibleFrom
, &visibleTo
);
2043 int xOrig
= dc
.LogicalToDeviceX( 0 );
2044 int yOrig
= dc
.LogicalToDeviceY( 0 );
2046 // tell the caller cache to cache the data
2049 wxListEvent
evCache(wxEVT_LIST_CACHE_HINT
,
2050 GetParent()->GetId());
2051 evCache
.SetEventObject( GetParent() );
2052 evCache
.m_oldItemIndex
= visibleFrom
;
2053 evCache
.m_item
.m_itemId
=
2054 evCache
.m_itemIndex
= visibleTo
;
2055 GetParent()->GetEventHandler()->ProcessEvent( evCache
);
2058 for ( size_t line
= visibleFrom
; line
<= visibleTo
; line
++ )
2060 rectLine
= GetLineRect(line
);
2063 if ( !IsExposed(rectLine
.x
+ xOrig
, rectLine
.y
+ yOrig
,
2064 rectLine
.width
, rectLine
.height
) )
2066 // don't redraw unaffected lines to avoid flicker
2070 GetLine(line
)->DrawInReportMode( &dc
,
2072 GetLineHighlightRect(line
),
2073 IsHighlighted(line
),
2074 line
== m_current
);
2077 if ( HasFlag(wxLC_HRULES
) )
2079 wxPen
pen(GetRuleColour(), 1, wxPENSTYLE_SOLID
);
2080 wxSize clientSize
= GetClientSize();
2082 size_t i
= visibleFrom
;
2083 if (i
== 0) i
= 1; // Don't draw the first one
2084 for ( ; i
<= visibleTo
; i
++ )
2087 dc
.SetBrush( *wxTRANSPARENT_BRUSH
);
2088 dc
.DrawLine(0 - dev_x
, i
* lineHeight
,
2089 clientSize
.x
- dev_x
, i
* lineHeight
);
2092 // Draw last horizontal rule
2093 if ( visibleTo
== GetItemCount() - 1 )
2096 dc
.SetBrush( *wxTRANSPARENT_BRUSH
);
2097 dc
.DrawLine(0 - dev_x
, (m_lineTo
+ 1) * lineHeight
,
2098 clientSize
.x
- dev_x
, (m_lineTo
+ 1) * lineHeight
);
2102 // Draw vertical rules if required
2103 if ( HasFlag(wxLC_VRULES
) && !IsEmpty() )
2105 wxPen
pen(GetRuleColour(), 1, wxPENSTYLE_SOLID
);
2106 wxRect firstItemRect
, lastItemRect
;
2108 GetItemRect(visibleFrom
, firstItemRect
);
2109 GetItemRect(visibleTo
, lastItemRect
);
2110 int x
= firstItemRect
.GetX();
2112 dc
.SetBrush(* wxTRANSPARENT_BRUSH
);
2114 for (int col
= 0; col
< GetColumnCount(); col
++)
2116 int colWidth
= GetColumnWidth(col
);
2118 int x_pos
= x
- dev_x
;
2119 if (col
< GetColumnCount()-1) x_pos
-= 2;
2120 dc
.DrawLine(x_pos
, firstItemRect
.GetY() - 1 - dev_y
,
2121 x_pos
, lastItemRect
.GetBottom() + 1 - dev_y
);
2127 size_t count
= GetItemCount();
2128 for ( size_t i
= 0; i
< count
; i
++ )
2130 GetLine(i
)->Draw( &dc
, i
== m_current
);
2134 // DrawFocusRect() is unusable under Mac, it draws outside of the highlight
2135 // rectangle somehow and so leaves traces when the item is not selected any
2136 // more, see #12229.
2141 if ( IsHighlighted(m_current
) )
2142 flags
|= wxCONTROL_SELECTED
;
2144 wxRendererNative::Get().
2145 DrawFocusRect(this, dc
, GetLineHighlightRect(m_current
), flags
);
2147 #endif // !__WXMAC__
2150 void wxListMainWindow::HighlightAll( bool on
)
2152 if ( IsSingleSel() )
2154 wxASSERT_MSG( !on
, wxT("can't do this in a single selection control") );
2156 // we just have one item to turn off
2157 if ( HasCurrent() && IsHighlighted(m_current
) )
2159 HighlightLine(m_current
, false);
2160 RefreshLine(m_current
);
2163 else // multi selection
2166 HighlightLines(0, GetItemCount() - 1, on
);
2170 void wxListMainWindow::OnChildFocus(wxChildFocusEvent
& WXUNUSED(event
))
2172 // Do nothing here. This prevents the default handler in wxScrolledWindow
2173 // from needlessly scrolling the window when the edit control is
2174 // dismissed. See ticket #9563.
2177 void wxListMainWindow::SendNotify( size_t line
,
2178 wxEventType command
,
2179 const wxPoint
& point
)
2181 wxListEvent
le( command
, GetParent()->GetId() );
2182 le
.SetEventObject( GetParent() );
2184 le
.m_item
.m_itemId
=
2185 le
.m_itemIndex
= line
;
2187 // set only for events which have position
2188 if ( point
!= wxDefaultPosition
)
2189 le
.m_pointDrag
= point
;
2191 // don't try to get the line info for virtual list controls: the main
2192 // program has it anyhow and if we did it would result in accessing all
2193 // the lines, even those which are not visible now and this is precisely
2194 // what we're trying to avoid
2197 if ( line
!= (size_t)-1 )
2199 GetLine(line
)->GetItem( 0, le
.m_item
);
2201 //else: this happens for wxEVT_LIST_ITEM_FOCUSED event
2203 //else: there may be no more such item
2205 GetParent()->GetEventHandler()->ProcessEvent( le
);
2208 void wxListMainWindow::ChangeCurrent(size_t current
)
2210 m_current
= current
;
2212 // as the current item changed, we shouldn't start editing it when the
2213 // "slow click" timer expires as the click happened on another item
2214 if ( m_renameTimer
->IsRunning() )
2215 m_renameTimer
->Stop();
2217 SendNotify(current
, wxEVT_LIST_ITEM_FOCUSED
);
2220 wxTextCtrl
*wxListMainWindow::EditLabel(long item
, wxClassInfo
* textControlClass
)
2222 wxCHECK_MSG( (item
>= 0) && ((size_t)item
< GetItemCount()), NULL
,
2223 wxT("wrong index in wxGenericListCtrl::EditLabel()") );
2225 wxASSERT_MSG( textControlClass
->IsKindOf(wxCLASSINFO(wxTextCtrl
)),
2226 wxT("EditLabel() needs a text control") );
2228 size_t itemEdit
= (size_t)item
;
2230 wxListEvent
le( wxEVT_LIST_BEGIN_LABEL_EDIT
, GetParent()->GetId() );
2231 le
.SetEventObject( GetParent() );
2232 le
.m_item
.m_itemId
=
2233 le
.m_itemIndex
= item
;
2234 wxListLineData
*data
= GetLine(itemEdit
);
2235 wxCHECK_MSG( data
, NULL
, wxT("invalid index in EditLabel()") );
2236 data
->GetItem( 0, le
.m_item
);
2238 if ( GetParent()->GetEventHandler()->ProcessEvent( le
) && !le
.IsAllowed() )
2240 // vetoed by user code
2246 // Ensure the display is updated before we start editing.
2250 wxTextCtrl
* const text
= (wxTextCtrl
*)textControlClass
->CreateObject();
2251 m_textctrlWrapper
= new wxListTextCtrlWrapper(this, text
, item
);
2252 return m_textctrlWrapper
->GetText();
2255 void wxListMainWindow::OnRenameTimer()
2257 wxCHECK_RET( HasCurrent(), wxT("unexpected rename timer") );
2259 EditLabel( m_current
);
2262 bool wxListMainWindow::OnRenameAccept(size_t itemEdit
, const wxString
& value
)
2264 wxListEvent
le( wxEVT_LIST_END_LABEL_EDIT
, GetParent()->GetId() );
2265 le
.SetEventObject( GetParent() );
2266 le
.m_item
.m_itemId
=
2267 le
.m_itemIndex
= itemEdit
;
2269 wxListLineData
*data
= GetLine(itemEdit
);
2271 wxCHECK_MSG( data
, false, wxT("invalid index in OnRenameAccept()") );
2273 data
->GetItem( 0, le
.m_item
);
2274 le
.m_item
.m_text
= value
;
2275 return !GetParent()->GetEventHandler()->ProcessEvent( le
) ||
2279 void wxListMainWindow::OnRenameCancelled(size_t itemEdit
)
2281 // let owner know that the edit was cancelled
2282 wxListEvent
le( wxEVT_LIST_END_LABEL_EDIT
, GetParent()->GetId() );
2284 le
.SetEditCanceled(true);
2286 le
.SetEventObject( GetParent() );
2287 le
.m_item
.m_itemId
=
2288 le
.m_itemIndex
= itemEdit
;
2290 wxListLineData
*data
= GetLine(itemEdit
);
2291 wxCHECK_RET( data
, wxT("invalid index in OnRenameCancelled()") );
2293 data
->GetItem( 0, le
.m_item
);
2294 GetEventHandler()->ProcessEvent( le
);
2297 void wxListMainWindow::OnFindTimer()
2299 m_findPrefix
.clear();
2304 void wxListMainWindow::EnableBellOnNoMatch( bool on
)
2309 void wxListMainWindow::OnMouse( wxMouseEvent
&event
)
2312 // On wxMac we can't depend on the EVT_KILL_FOCUS event to properly
2313 // shutdown the edit control when the mouse is clicked elsewhere on the
2314 // listctrl because the order of events is different (or something like
2315 // that), so explicitly end the edit if it is active.
2316 if ( event
.LeftDown() && m_textctrlWrapper
)
2317 m_textctrlWrapper
->EndEdit(wxListTextCtrlWrapper::End_Accept
);
2320 if ( event
.LeftDown() )
2322 // Ensure we skip the event to let the system set focus to this window.
2326 // Pretend that the event happened in wxListCtrl itself.
2327 wxMouseEvent
me(event
);
2328 me
.SetEventObject( GetParent() );
2329 me
.SetId(GetParent()->GetId());
2330 if ( GetParent()->GetEventHandler()->ProcessEvent( me
))
2333 if (event
.GetEventType() == wxEVT_MOUSEWHEEL
)
2335 // let the base class handle mouse wheel events.
2340 if ( !HasCurrent() || IsEmpty() )
2342 if (event
.RightDown())
2344 SendNotify( (size_t)-1, wxEVT_LIST_ITEM_RIGHT_CLICK
, event
.GetPosition() );
2346 wxContextMenuEvent
evtCtx(wxEVT_CONTEXT_MENU
,
2347 GetParent()->GetId(),
2348 ClientToScreen(event
.GetPosition()));
2349 evtCtx
.SetEventObject(GetParent());
2350 GetParent()->GetEventHandler()->ProcessEvent(evtCtx
);
2358 if ( !(event
.Dragging() || event
.ButtonDown() || event
.LeftUp() ||
2359 event
.ButtonDClick()) )
2362 int x
= event
.GetX();
2363 int y
= event
.GetY();
2364 GetListCtrl()->CalcUnscrolledPosition( x
, y
, &x
, &y
);
2366 // where did we hit it (if we did)?
2369 size_t count
= GetItemCount(),
2372 if ( InReportView() )
2374 current
= y
/ GetLineHeight();
2375 if ( current
< count
)
2376 hitResult
= HitTestLine(current
, x
, y
);
2380 // TODO: optimize it too! this is less simple than for report view but
2381 // enumerating all items is still not a way to do it!!
2382 for ( current
= 0; current
< count
; current
++ )
2384 hitResult
= HitTestLine(current
, x
, y
);
2390 // Update drag events counter first as we must do it even if the mouse is
2391 // not on any item right now as we must keep count in case we started
2392 // dragging from the empty control area but continued to do it over a valid
2393 // item -- in this situation we must not start dragging this item.
2394 if (event
.Dragging())
2399 // The only mouse event that can be generated without any valid item is
2400 // wxEVT_LIST_ITEM_RIGHT_CLICK as it can be useful to have a global
2401 // popup menu for the list control itself which should be shown even when
2402 // the user clicks outside of any item.
2405 // outside of any item
2406 if (event
.RightDown())
2408 SendNotify( (size_t) -1, wxEVT_LIST_ITEM_RIGHT_CLICK
, event
.GetPosition() );
2410 wxContextMenuEvent
evtCtx(
2412 GetParent()->GetId(),
2413 ClientToScreen(event
.GetPosition()));
2414 evtCtx
.SetEventObject(GetParent());
2415 GetParent()->GetEventHandler()->ProcessEvent(evtCtx
);
2419 // reset the selection and bail out
2420 HighlightAll(false);
2426 if ( event
.Dragging() )
2428 if (m_dragCount
== 1)
2430 // we have to report the raw, physical coords as we want to be
2431 // able to call HitTest(event.m_pointDrag) from the user code to
2432 // get the item being dragged
2433 m_dragStart
= event
.GetPosition();
2436 if (m_dragCount
!= 3)
2439 int command
= event
.RightIsDown() ? wxEVT_LIST_BEGIN_RDRAG
2440 : wxEVT_LIST_BEGIN_DRAG
;
2442 SendNotify( m_lineLastClicked
, command
, m_dragStart
);
2447 bool forceClick
= false;
2448 if (event
.ButtonDClick())
2450 if ( m_renameTimer
->IsRunning() )
2451 m_renameTimer
->Stop();
2453 m_lastOnSame
= false;
2455 if ( current
== m_lineLastClicked
)
2457 SendNotify( current
, wxEVT_LIST_ITEM_ACTIVATED
);
2463 // The first click was on another item, so don't interpret this as
2464 // a double click, but as a simple click instead
2471 if (m_lineSelectSingleOnUp
!= (size_t)-1)
2473 // select single line
2474 HighlightAll( false );
2475 ReverseHighlight(m_lineSelectSingleOnUp
);
2480 if ((current
== m_current
) &&
2481 (hitResult
== wxLIST_HITTEST_ONITEMLABEL
) &&
2482 HasFlag(wxLC_EDIT_LABELS
) )
2484 if ( !InReportView() ||
2485 GetLineLabelRect(current
).Contains(x
, y
) )
2487 int dclick
= wxSystemSettings::GetMetric(wxSYS_DCLICK_MSEC
);
2488 m_renameTimer
->Start(dclick
> 0 ? dclick
: 250, true);
2492 m_lastOnSame
= false;
2495 m_lineSelectSingleOnUp
= (size_t)-1;
2499 // This is necessary, because after a DnD operation in
2500 // from and to ourself, the up event is swallowed by the
2501 // DnD code. So on next non-up event (which means here and
2502 // now) m_lineSelectSingleOnUp should be reset.
2503 m_lineSelectSingleOnUp
= (size_t)-1;
2505 if (event
.RightDown())
2507 m_lineBeforeLastClicked
= m_lineLastClicked
;
2508 m_lineLastClicked
= current
;
2510 // If the item is already selected, do not update the selection.
2511 // Multi-selections should not be cleared if a selected item is clicked.
2512 if (!IsHighlighted(current
))
2514 HighlightAll(false);
2515 ChangeCurrent(current
);
2516 ReverseHighlight(m_current
);
2519 SendNotify( current
, wxEVT_LIST_ITEM_RIGHT_CLICK
, event
.GetPosition() );
2521 // Allow generation of context menu event
2524 else if (event
.MiddleDown())
2526 SendNotify( current
, wxEVT_LIST_ITEM_MIDDLE_CLICK
);
2528 else if ( event
.LeftDown() || forceClick
)
2530 m_lineBeforeLastClicked
= m_lineLastClicked
;
2531 m_lineLastClicked
= current
;
2533 size_t oldCurrent
= m_current
;
2534 bool oldWasSelected
= IsHighlighted(m_current
);
2536 bool cmdModifierDown
= event
.CmdDown();
2537 if ( IsSingleSel() || !(cmdModifierDown
|| event
.ShiftDown()) )
2539 if ( IsSingleSel() || !IsHighlighted(current
) )
2541 HighlightAll( false );
2543 ChangeCurrent(current
);
2545 ReverseHighlight(m_current
);
2547 else // multi sel & current is highlighted & no mod keys
2549 m_lineSelectSingleOnUp
= current
;
2550 ChangeCurrent(current
); // change focus
2553 else // multi sel & either ctrl or shift is down
2555 if (cmdModifierDown
)
2557 ChangeCurrent(current
);
2559 ReverseHighlight(m_current
);
2561 else if (event
.ShiftDown())
2563 ChangeCurrent(current
);
2565 size_t lineFrom
= oldCurrent
,
2568 if ( lineTo
< lineFrom
)
2571 lineFrom
= m_current
;
2574 HighlightLines(lineFrom
, lineTo
);
2576 else // !ctrl, !shift
2578 // test in the enclosing if should make it impossible
2579 wxFAIL_MSG( wxT("how did we get here?") );
2583 if (m_current
!= oldCurrent
)
2584 RefreshLine( oldCurrent
);
2586 // Set the flag telling us whether the next click on this item should
2587 // start editing its label. This should happen if we clicked on the
2588 // current item and it was already selected, i.e. if this click was not
2589 // done to select it.
2591 // It should not happen if this was a double click (forceClick is true)
2592 // nor if we hadn't had the focus before as then this click was used to
2593 // give focus to the control.
2594 m_lastOnSame
= (m_current
== oldCurrent
) && oldWasSelected
&&
2595 !forceClick
&& HasFocus();
2599 void wxListMainWindow::MoveToItem(size_t item
)
2601 if ( item
== (size_t)-1 )
2604 wxRect rect
= GetLineRect(item
);
2606 int client_w
, client_h
;
2607 GetClientSize( &client_w
, &client_h
);
2609 const int hLine
= GetLineHeight();
2611 int view_x
= SCROLL_UNIT_X
* GetListCtrl()->GetScrollPos( wxHORIZONTAL
);
2612 int view_y
= hLine
* GetListCtrl()->GetScrollPos( wxVERTICAL
);
2614 if ( InReportView() )
2616 // the next we need the range of lines shown it might be different,
2617 // so recalculate it
2618 ResetVisibleLinesRange();
2620 if (rect
.y
< view_y
)
2621 GetListCtrl()->Scroll( -1, rect
.y
/ hLine
);
2622 if (rect
.y
+ rect
.height
+ 5 > view_y
+ client_h
)
2623 GetListCtrl()->Scroll( -1, (rect
.y
+ rect
.height
- client_h
+ hLine
) / hLine
);
2626 // At least on Mac the visible lines value will get reset inside of
2627 // Scroll *before* it actually scrolls the window because of the
2628 // Update() that happens there, so it will still have the wrong value.
2629 // So let's reset it again and wait for it to be recalculated in the
2630 // next paint event. I would expect this problem to show up in wxGTK
2631 // too but couldn't duplicate it there. Perhaps the order of events
2632 // is different... --Robin
2633 ResetVisibleLinesRange();
2641 if (rect
.x
-view_x
< 5)
2642 sx
= (rect
.x
- 5) / SCROLL_UNIT_X
;
2643 if (rect
.x
+ rect
.width
- 5 > view_x
+ client_w
)
2644 sx
= (rect
.x
+ rect
.width
- client_w
+ SCROLL_UNIT_X
) / SCROLL_UNIT_X
;
2646 if (rect
.y
-view_y
< 5)
2647 sy
= (rect
.y
- 5) / hLine
;
2648 if (rect
.y
+ rect
.height
- 5 > view_y
+ client_h
)
2649 sy
= (rect
.y
+ rect
.height
- client_h
+ hLine
) / hLine
;
2651 GetListCtrl()->Scroll(sx
, sy
);
2655 bool wxListMainWindow::ScrollList(int WXUNUSED(dx
), int dy
)
2657 if ( !InReportView() )
2659 // TODO: this should work in all views but is not implemented now
2664 GetVisibleLinesRange(&top
, &bottom
);
2666 if ( bottom
== (size_t)-1 )
2669 ResetVisibleLinesRange();
2671 int hLine
= GetLineHeight();
2673 GetListCtrl()->Scroll(-1, top
+ dy
/ hLine
);
2676 // see comment in MoveToItem() for why we do this
2677 ResetVisibleLinesRange();
2683 // ----------------------------------------------------------------------------
2684 // keyboard handling
2685 // ----------------------------------------------------------------------------
2687 void wxListMainWindow::OnArrowChar(size_t newCurrent
, const wxKeyEvent
& event
)
2689 wxCHECK_RET( newCurrent
< (size_t)GetItemCount(),
2690 wxT("invalid item index in OnArrowChar()") );
2692 size_t oldCurrent
= m_current
;
2694 // in single selection we just ignore Shift as we can't select several
2696 if ( event
.ShiftDown() && !IsSingleSel() )
2698 ChangeCurrent(newCurrent
);
2700 // refresh the old focus to remove it
2701 RefreshLine( oldCurrent
);
2703 // select all the items between the old and the new one
2704 if ( oldCurrent
> newCurrent
)
2706 newCurrent
= oldCurrent
;
2707 oldCurrent
= m_current
;
2710 HighlightLines(oldCurrent
, newCurrent
);
2714 // all previously selected items are unselected unless ctrl is held
2715 // in a multiselection control
2716 if ( !event
.ControlDown() || IsSingleSel() )
2717 HighlightAll(false);
2719 ChangeCurrent(newCurrent
);
2721 // refresh the old focus to remove it
2722 RefreshLine( oldCurrent
);
2724 // in single selection mode we must always have a selected item
2725 if ( !event
.ControlDown() || IsSingleSel() )
2726 HighlightLine( m_current
, true );
2729 RefreshLine( m_current
);
2734 void wxListMainWindow::OnKeyDown( wxKeyEvent
&event
)
2736 wxWindow
*parent
= GetParent();
2738 // propagate the key event upwards
2739 wxKeyEvent
ke(event
);
2740 ke
.SetEventObject( parent
);
2741 ke
.SetId(GetParent()->GetId());
2742 if (parent
->GetEventHandler()->ProcessEvent( ke
))
2745 // send a list event
2746 wxListEvent
le( wxEVT_LIST_KEY_DOWN
, parent
->GetId() );
2747 le
.m_item
.m_itemId
=
2748 le
.m_itemIndex
= m_current
;
2750 GetLine(m_current
)->GetItem( 0, le
.m_item
);
2751 le
.m_code
= event
.GetKeyCode();
2752 le
.SetEventObject( parent
);
2753 if (parent
->GetEventHandler()->ProcessEvent( le
))
2759 void wxListMainWindow::OnKeyUp( wxKeyEvent
&event
)
2761 wxWindow
*parent
= GetParent();
2763 // propagate the key event upwards
2764 wxKeyEvent
ke(event
);
2765 ke
.SetEventObject( parent
);
2766 ke
.SetId(GetParent()->GetId());
2767 if (parent
->GetEventHandler()->ProcessEvent( ke
))
2773 void wxListMainWindow::OnCharHook( wxKeyEvent
&event
)
2775 if ( m_textctrlWrapper
)
2777 // When an in-place editor is active we should ensure that it always
2778 // gets the key events that are special to it.
2779 if ( m_textctrlWrapper
->CheckForEndEditKey(event
) )
2781 // Skip the call to wxEvent::Skip() below.
2789 void wxListMainWindow::OnChar( wxKeyEvent
&event
)
2791 wxWindow
*parent
= GetParent();
2793 // propagate the char event upwards
2794 wxKeyEvent
ke(event
);
2795 ke
.SetEventObject( parent
);
2796 ke
.SetId(GetParent()->GetId());
2797 if (parent
->GetEventHandler()->ProcessEvent( ke
))
2800 if ( HandleAsNavigationKey(event
) )
2803 // no item -> nothing to do
2810 // don't use m_linesPerPage directly as it might not be computed yet
2811 const int pageSize
= GetCountPerPage();
2812 wxCHECK_RET( pageSize
, wxT("should have non zero page size") );
2814 if (GetLayoutDirection() == wxLayout_RightToLeft
)
2816 if (event
.GetKeyCode() == WXK_RIGHT
)
2817 event
.m_keyCode
= WXK_LEFT
;
2818 else if (event
.GetKeyCode() == WXK_LEFT
)
2819 event
.m_keyCode
= WXK_RIGHT
;
2822 int keyCode
= event
.GetKeyCode();
2826 if ( m_current
> 0 )
2827 OnArrowChar( m_current
- 1, event
);
2831 if ( m_current
< (size_t)GetItemCount() - 1 )
2832 OnArrowChar( m_current
+ 1, event
);
2837 OnArrowChar( GetItemCount() - 1, event
);
2842 OnArrowChar( 0, event
);
2847 int steps
= InReportView() ? pageSize
- 1
2848 : m_current
% pageSize
;
2850 int index
= m_current
- steps
;
2854 OnArrowChar( index
, event
);
2860 int steps
= InReportView()
2862 : pageSize
- (m_current
% pageSize
) - 1;
2864 size_t index
= m_current
+ steps
;
2865 size_t count
= GetItemCount();
2866 if ( index
>= count
)
2869 OnArrowChar( index
, event
);
2874 if ( !InReportView() )
2876 int index
= m_current
- pageSize
;
2880 OnArrowChar( index
, event
);
2885 if ( !InReportView() )
2887 size_t index
= m_current
+ pageSize
;
2889 size_t count
= GetItemCount();
2890 if ( index
>= count
)
2893 OnArrowChar( index
, event
);
2898 if ( IsSingleSel() )
2900 if ( event
.ControlDown() )
2902 ReverseHighlight(m_current
);
2904 else // normal space press
2906 SendNotify( m_current
, wxEVT_LIST_ITEM_ACTIVATED
);
2909 else // multiple selection
2911 ReverseHighlight(m_current
);
2917 SendNotify( m_current
, wxEVT_LIST_ITEM_ACTIVATED
);
2921 if ( !event
.HasModifiers() &&
2922 ((keyCode
>= '0' && keyCode
<= '9') ||
2923 (keyCode
>= 'a' && keyCode
<= 'z') ||
2924 (keyCode
>= 'A' && keyCode
<= 'Z') ||
2930 // find the next item starting with the given prefix
2931 wxChar ch
= (wxChar
)keyCode
;
2934 // if the same character is typed multiple times then go to the
2935 // next entry starting with that character instead of searching
2936 // for an item starting with multiple copies of this character,
2937 // this is more useful and is how it works under Windows.
2938 if ( m_findPrefix
.length() == 1 && m_findPrefix
[0] == ch
)
2940 item
= PrefixFindItem(m_current
, ch
);
2944 const wxString
newPrefix(m_findPrefix
+ ch
);
2945 item
= PrefixFindItem(m_current
, newPrefix
);
2946 if ( item
!= (size_t)-1 )
2947 m_findPrefix
= newPrefix
;
2950 // also start the timer to reset the current prefix if the user
2951 // doesn't press any more alnum keys soon -- we wouldn't want
2952 // to use this prefix for a new item search
2955 m_findTimer
= new wxListFindTimer( this );
2958 // Notice that we should start the timer even if we didn't find
2959 // anything to make sure we reset the search state later.
2960 m_findTimer
->Start(wxListFindTimer::DELAY
, wxTIMER_ONE_SHOT
);
2962 // restart timer even when there's no match so bell get's reset
2963 if ( item
!= (size_t)-1 )
2965 // Select the found item and go to it.
2966 HighlightAll(false);
2968 wxLIST_STATE_FOCUSED
| wxLIST_STATE_SELECTED
,
2969 wxLIST_STATE_FOCUSED
| wxLIST_STATE_SELECTED
);
2971 // Reset the bell flag if it had been temporarily disabled
2976 else // No such item
2978 // Signal it with a bell if enabled.
2979 if ( m_findBell
== 1 )
2983 // Disable it for the next unsuccessful match, we only
2984 // beep once, this is usually enough and continuing to
2985 // do it would be annoying.
2997 // ----------------------------------------------------------------------------
2999 // ----------------------------------------------------------------------------
3001 void wxListMainWindow::OnSetFocus( wxFocusEvent
&WXUNUSED(event
) )
3005 wxFocusEvent
event( wxEVT_SET_FOCUS
, GetParent()->GetId() );
3006 event
.SetEventObject( GetParent() );
3007 if ( GetParent()->GetEventHandler()->ProcessEvent( event
) )
3011 // wxGTK sends us EVT_SET_FOCUS events even if we had never got
3012 // EVT_KILL_FOCUS before which means that we finish by redrawing the items
3013 // which are already drawn correctly resulting in horrible flicker - avoid
3023 void wxListMainWindow::OnKillFocus( wxFocusEvent
&WXUNUSED(event
) )
3027 wxFocusEvent
event( wxEVT_KILL_FOCUS
, GetParent()->GetId() );
3028 event
.SetEventObject( GetParent() );
3029 if ( GetParent()->GetEventHandler()->ProcessEvent( event
) )
3037 void wxListMainWindow::DrawImage( int index
, wxDC
*dc
, int x
, int y
)
3039 if ( HasFlag(wxLC_ICON
) && (m_normal_image_list
))
3041 m_normal_image_list
->Draw( index
, *dc
, x
, y
, wxIMAGELIST_DRAW_TRANSPARENT
);
3043 else if ( HasFlag(wxLC_SMALL_ICON
) && (m_small_image_list
))
3045 m_small_image_list
->Draw( index
, *dc
, x
, y
, wxIMAGELIST_DRAW_TRANSPARENT
);
3047 else if ( HasFlag(wxLC_LIST
) && (m_small_image_list
))
3049 m_small_image_list
->Draw( index
, *dc
, x
, y
, wxIMAGELIST_DRAW_TRANSPARENT
);
3051 else if ( InReportView() && (m_small_image_list
))
3053 m_small_image_list
->Draw( index
, *dc
, x
, y
, wxIMAGELIST_DRAW_TRANSPARENT
);
3057 void wxListMainWindow::GetImageSize( int index
, int &width
, int &height
) const
3059 if ( HasFlag(wxLC_ICON
) && m_normal_image_list
)
3061 m_normal_image_list
->GetSize( index
, width
, height
);
3063 else if ( HasFlag(wxLC_SMALL_ICON
) && m_small_image_list
)
3065 m_small_image_list
->GetSize( index
, width
, height
);
3067 else if ( HasFlag(wxLC_LIST
) && m_small_image_list
)
3069 m_small_image_list
->GetSize( index
, width
, height
);
3071 else if ( InReportView() && m_small_image_list
)
3073 m_small_image_list
->GetSize( index
, width
, height
);
3082 void wxListMainWindow::SetImageList( wxImageList
*imageList
, int which
)
3086 // calc the spacing from the icon size
3087 int width
= 0, height
= 0;
3089 if ((imageList
) && (imageList
->GetImageCount()) )
3090 imageList
->GetSize(0, width
, height
);
3092 if (which
== wxIMAGE_LIST_NORMAL
)
3094 m_normal_image_list
= imageList
;
3095 m_normal_spacing
= width
+ 8;
3098 if (which
== wxIMAGE_LIST_SMALL
)
3100 m_small_image_list
= imageList
;
3101 m_small_spacing
= width
+ 14;
3102 m_lineHeight
= 0; // ensure that the line height will be recalc'd
3106 void wxListMainWindow::SetItemSpacing( int spacing
, bool isSmall
)
3110 m_small_spacing
= spacing
;
3112 m_normal_spacing
= spacing
;
3115 int wxListMainWindow::GetItemSpacing( bool isSmall
)
3117 return isSmall
? m_small_spacing
: m_normal_spacing
;
3120 // ----------------------------------------------------------------------------
3122 // ----------------------------------------------------------------------------
3125 wxListMainWindow::ComputeMinHeaderWidth(const wxListHeaderData
* column
) const
3127 wxClientDC
dc(const_cast<wxListMainWindow
*>(this));
3129 int width
= dc
.GetTextExtent(column
->GetText()).x
+ AUTOSIZE_COL_MARGIN
;
3131 width
+= 2*EXTRA_WIDTH
;
3133 // check for column header's image availability
3134 const int image
= column
->GetImage();
3137 if ( m_small_image_list
)
3140 m_small_image_list
->GetSize(image
, ix
, iy
);
3141 width
+= ix
+ HEADER_IMAGE_MARGIN_IN_REPORT_MODE
;
3148 void wxListMainWindow::SetColumn( int col
, const wxListItem
&item
)
3150 wxListHeaderDataList::compatibility_iterator node
= m_columns
.Item( col
);
3152 wxCHECK_RET( node
, wxT("invalid column index in SetColumn") );
3154 wxListHeaderData
*column
= node
->GetData();
3155 column
->SetItem( item
);
3157 if ( item
.m_width
== wxLIST_AUTOSIZE_USEHEADER
)
3158 column
->SetWidth(ComputeMinHeaderWidth(column
));
3160 wxListHeaderWindow
*headerWin
= GetListCtrl()->m_headerWin
;
3162 headerWin
->m_dirty
= true;
3166 // invalidate it as it has to be recalculated
3170 void wxListMainWindow::SetColumnWidth( int col
, int width
)
3172 wxCHECK_RET( col
>= 0 && col
< GetColumnCount(),
3173 wxT("invalid column index") );
3175 wxCHECK_RET( InReportView(),
3176 wxT("SetColumnWidth() can only be called in report mode.") );
3180 wxListHeaderWindow
*headerWin
= GetListCtrl()->m_headerWin
;
3182 headerWin
->m_dirty
= true;
3184 wxListHeaderDataList::compatibility_iterator node
= m_columns
.Item( col
);
3185 wxCHECK_RET( node
, wxT("no column?") );
3187 wxListHeaderData
*column
= node
->GetData();
3189 size_t count
= GetItemCount();
3191 if (width
== wxLIST_AUTOSIZE_USEHEADER
)
3193 width
= ComputeMinHeaderWidth(column
);
3195 else if ( width
== wxLIST_AUTOSIZE
)
3197 width
= ComputeMinHeaderWidth(column
);
3201 wxClientDC
dc(this);
3202 dc
.SetFont( GetFont() );
3204 int max
= AUTOSIZE_COL_MARGIN
;
3206 // if the cached column width isn't valid then recalculate it
3207 if (m_aColWidths
.Item(col
)->bNeedsUpdate
)
3209 for (size_t i
= 0; i
< count
; i
++)
3211 wxListLineData
*line
= GetLine( i
);
3212 wxListItemDataList::compatibility_iterator n
= line
->m_items
.Item( col
);
3214 wxCHECK_RET( n
, wxT("no subitem?") );
3216 wxListItemData
*itemData
= n
->GetData();
3219 itemData
->GetItem(item
);
3220 int itemWidth
= GetItemWidthWithImage(&item
);
3221 if (itemWidth
> max
)
3225 m_aColWidths
.Item(col
)->bNeedsUpdate
= false;
3226 m_aColWidths
.Item(col
)->nMaxWidth
= max
;
3229 max
= m_aColWidths
.Item(col
)->nMaxWidth
+ AUTOSIZE_COL_MARGIN
;
3235 column
->SetWidth( width
);
3237 // invalidate it as it has to be recalculated
3241 int wxListMainWindow::GetHeaderWidth() const
3243 if ( !m_headerWidth
)
3245 wxListMainWindow
*self
= wxConstCast(this, wxListMainWindow
);
3247 size_t count
= GetColumnCount();
3248 for ( size_t col
= 0; col
< count
; col
++ )
3250 self
->m_headerWidth
+= GetColumnWidth(col
);
3254 return m_headerWidth
;
3257 void wxListMainWindow::GetColumn( int col
, wxListItem
&item
) const
3259 wxListHeaderDataList::compatibility_iterator node
= m_columns
.Item( col
);
3260 wxCHECK_RET( node
, wxT("invalid column index in GetColumn") );
3262 wxListHeaderData
*column
= node
->GetData();
3263 column
->GetItem( item
);
3266 int wxListMainWindow::GetColumnWidth( int col
) const
3268 wxListHeaderDataList::compatibility_iterator node
= m_columns
.Item( col
);
3269 wxCHECK_MSG( node
, 0, wxT("invalid column index") );
3271 wxListHeaderData
*column
= node
->GetData();
3272 return column
->GetWidth();
3275 // ----------------------------------------------------------------------------
3277 // ----------------------------------------------------------------------------
3279 void wxListMainWindow::SetItem( wxListItem
&item
)
3281 long id
= item
.m_itemId
;
3282 wxCHECK_RET( id
>= 0 && (size_t)id
< GetItemCount(),
3283 wxT("invalid item index in SetItem") );
3287 wxListLineData
*line
= GetLine((size_t)id
);
3288 line
->SetItem( item
.m_col
, item
);
3290 // Set item state if user wants
3291 if ( item
.m_mask
& wxLIST_MASK_STATE
)
3292 SetItemState( item
.m_itemId
, item
.m_state
, item
.m_state
);
3296 // update the Max Width Cache if needed
3297 int width
= GetItemWidthWithImage(&item
);
3299 if (width
> m_aColWidths
.Item(item
.m_col
)->nMaxWidth
)
3300 m_aColWidths
.Item(item
.m_col
)->nMaxWidth
= width
;
3304 // update the item on screen unless we're going to update everything soon
3309 GetItemRect(id
, rectItem
);
3310 RefreshRect(rectItem
);
3314 void wxListMainWindow::SetItemStateAll(long state
, long stateMask
)
3319 // first deal with selection
3320 if ( stateMask
& wxLIST_STATE_SELECTED
)
3322 // set/clear select state
3325 // optimized version for virtual listctrl.
3326 m_selStore
.SelectRange(0, GetItemCount() - 1, state
== wxLIST_STATE_SELECTED
);
3329 else if ( state
& wxLIST_STATE_SELECTED
)
3331 const long count
= GetItemCount();
3332 for( long i
= 0; i
< count
; i
++ )
3334 SetItemState( i
, wxLIST_STATE_SELECTED
, wxLIST_STATE_SELECTED
);
3340 // clear for non virtual (somewhat optimized by using GetNextItem())
3342 while ( (i
= GetNextItem(i
, wxLIST_NEXT_ALL
, wxLIST_STATE_SELECTED
)) != -1 )
3344 SetItemState( i
, 0, wxLIST_STATE_SELECTED
);
3349 if ( HasCurrent() && (state
== 0) && (stateMask
& wxLIST_STATE_FOCUSED
) )
3351 // unfocus all: only one item can be focussed, so clearing focus for
3352 // all items is simply clearing focus of the focussed item.
3353 SetItemState(m_current
, state
, stateMask
);
3355 //(setting focus to all items makes no sense, so it is not handled here.)
3358 void wxListMainWindow::SetItemState( long litem
, long state
, long stateMask
)
3362 SetItemStateAll(state
, stateMask
);
3366 wxCHECK_RET( litem
>= 0 && (size_t)litem
< GetItemCount(),
3367 wxT("invalid list ctrl item index in SetItem") );
3369 size_t oldCurrent
= m_current
;
3370 size_t item
= (size_t)litem
; // safe because of the check above
3372 // do we need to change the focus?
3373 if ( stateMask
& wxLIST_STATE_FOCUSED
)
3375 if ( state
& wxLIST_STATE_FOCUSED
)
3377 // don't do anything if this item is already focused
3378 if ( item
!= m_current
)
3380 ChangeCurrent(item
);
3382 if ( oldCurrent
!= (size_t)-1 )
3384 if ( IsSingleSel() )
3386 HighlightLine(oldCurrent
, false);
3389 RefreshLine(oldCurrent
);
3392 RefreshLine( m_current
);
3397 // don't do anything if this item is not focused
3398 if ( item
== m_current
)
3402 if ( IsSingleSel() )
3404 // we must unselect the old current item as well or we
3405 // might end up with more than one selected item in a
3406 // single selection control
3407 HighlightLine(oldCurrent
, false);
3410 RefreshLine( oldCurrent
);
3415 // do we need to change the selection state?
3416 if ( stateMask
& wxLIST_STATE_SELECTED
)
3418 bool on
= (state
& wxLIST_STATE_SELECTED
) != 0;
3420 if ( IsSingleSel() )
3424 // selecting the item also makes it the focused one in the
3426 if ( m_current
!= item
)
3428 ChangeCurrent(item
);
3430 if ( oldCurrent
!= (size_t)-1 )
3432 HighlightLine( oldCurrent
, false );
3433 RefreshLine( oldCurrent
);
3439 // only the current item may be selected anyhow
3440 if ( item
!= m_current
)
3445 if ( HighlightLine(item
, on
) )
3452 int wxListMainWindow::GetItemState( long item
, long stateMask
) const
3454 wxCHECK_MSG( item
>= 0 && (size_t)item
< GetItemCount(), 0,
3455 wxT("invalid list ctrl item index in GetItemState()") );
3457 int ret
= wxLIST_STATE_DONTCARE
;
3459 if ( stateMask
& wxLIST_STATE_FOCUSED
)
3461 if ( (size_t)item
== m_current
)
3462 ret
|= wxLIST_STATE_FOCUSED
;
3465 if ( stateMask
& wxLIST_STATE_SELECTED
)
3467 if ( IsHighlighted(item
) )
3468 ret
|= wxLIST_STATE_SELECTED
;
3474 void wxListMainWindow::GetItem( wxListItem
&item
) const
3476 wxCHECK_RET( item
.m_itemId
>= 0 && (size_t)item
.m_itemId
< GetItemCount(),
3477 wxT("invalid item index in GetItem") );
3479 wxListLineData
*line
= GetLine((size_t)item
.m_itemId
);
3480 line
->GetItem( item
.m_col
, item
);
3482 // Get item state if user wants it
3483 if ( item
.m_mask
& wxLIST_MASK_STATE
)
3484 item
.m_state
= GetItemState( item
.m_itemId
, wxLIST_STATE_SELECTED
|
3485 wxLIST_STATE_FOCUSED
);
3488 // ----------------------------------------------------------------------------
3490 // ----------------------------------------------------------------------------
3492 size_t wxListMainWindow::GetItemCount() const
3494 return IsVirtual() ? m_countVirt
: m_lines
.GetCount();
3497 void wxListMainWindow::SetItemCount(long count
)
3499 m_selStore
.SetItemCount(count
);
3500 m_countVirt
= count
;
3502 ResetVisibleLinesRange();
3504 // scrollbars must be reset
3508 int wxListMainWindow::GetSelectedItemCount() const
3510 // deal with the quick case first
3511 if ( IsSingleSel() )
3512 return HasCurrent() ? IsHighlighted(m_current
) : false;
3514 // virtual controls remmebers all its selections itself
3516 return m_selStore
.GetSelectedCount();
3518 // TODO: we probably should maintain the number of items selected even for
3519 // non virtual controls as enumerating all lines is really slow...
3520 size_t countSel
= 0;
3521 size_t count
= GetItemCount();
3522 for ( size_t line
= 0; line
< count
; line
++ )
3524 if ( GetLine(line
)->IsHighlighted() )
3531 // ----------------------------------------------------------------------------
3532 // item position/size
3533 // ----------------------------------------------------------------------------
3535 wxRect
wxListMainWindow::GetViewRect() const
3537 wxASSERT_MSG( !HasFlag(wxLC_LIST
), "not implemented for list view" );
3539 // we need to find the longest/tallest label
3540 wxCoord xMax
= 0, yMax
= 0;
3541 const int count
= GetItemCount();
3544 for ( int i
= 0; i
< count
; i
++ )
3546 // we need logical, not physical, coordinates here, so use
3547 // GetLineRect() instead of GetItemRect()
3548 wxRect r
= GetLineRect(i
);
3550 wxCoord x
= r
.GetRight(),
3560 // some fudge needed to make it look prettier
3561 xMax
+= 2 * EXTRA_BORDER_X
;
3562 yMax
+= 2 * EXTRA_BORDER_Y
;
3564 // account for the scrollbars if necessary
3565 const wxSize sizeAll
= GetClientSize();
3566 if ( xMax
> sizeAll
.x
)
3567 yMax
+= wxSystemSettings::GetMetric(wxSYS_HSCROLL_Y
);
3568 if ( yMax
> sizeAll
.y
)
3569 xMax
+= wxSystemSettings::GetMetric(wxSYS_VSCROLL_X
);
3571 return wxRect(0, 0, xMax
, yMax
);
3575 wxListMainWindow::GetSubItemRect(long item
, long subItem
, wxRect
& rect
) const
3577 wxCHECK_MSG( subItem
== wxLIST_GETSUBITEMRECT_WHOLEITEM
|| InReportView(),
3579 wxT("GetSubItemRect only meaningful in report view") );
3580 wxCHECK_MSG( item
>= 0 && (size_t)item
< GetItemCount(), false,
3581 wxT("invalid item in GetSubItemRect") );
3583 // ensure that we're laid out, otherwise we could return nonsense
3586 wxConstCast(this, wxListMainWindow
)->
3587 RecalculatePositions(true /* no refresh */);
3590 rect
= GetLineRect((size_t)item
);
3592 // Adjust rect to specified column
3593 if ( subItem
!= wxLIST_GETSUBITEMRECT_WHOLEITEM
)
3595 wxCHECK_MSG( subItem
>= 0 && subItem
< GetColumnCount(), false,
3596 wxT("invalid subItem in GetSubItemRect") );
3598 for (int i
= 0; i
< subItem
; i
++)
3600 rect
.x
+= GetColumnWidth(i
);
3602 rect
.width
= GetColumnWidth(subItem
);
3605 GetListCtrl()->CalcScrolledPosition(rect
.x
, rect
.y
, &rect
.x
, &rect
.y
);
3610 bool wxListMainWindow::GetItemPosition(long item
, wxPoint
& pos
) const
3613 GetItemRect(item
, rect
);
3621 // ----------------------------------------------------------------------------
3622 // geometry calculation
3623 // ----------------------------------------------------------------------------
3625 void wxListMainWindow::RecalculatePositions(bool noRefresh
)
3627 const int lineHeight
= GetLineHeight();
3629 wxClientDC
dc( this );
3630 dc
.SetFont( GetFont() );
3632 const size_t count
= GetItemCount();
3635 if ( HasFlag(wxLC_ICON
) && m_normal_image_list
)
3636 iconSpacing
= m_normal_spacing
;
3637 else if ( HasFlag(wxLC_SMALL_ICON
) && m_small_image_list
)
3638 iconSpacing
= m_small_spacing
;
3642 // Note that we do not call GetClientSize() here but
3643 // GetSize() and subtract the border size for sunken
3644 // borders manually. This is technically incorrect,
3645 // but we need to know the client area's size WITHOUT
3646 // scrollbars here. Since we don't know if there are
3647 // any scrollbars, we use GetSize() instead. Another
3648 // solution would be to call SetScrollbars() here to
3649 // remove the scrollbars and call GetClientSize() then,
3650 // but this might result in flicker and - worse - will
3651 // reset the scrollbars to 0 which is not good at all
3652 // if you resize a dialog/window, but don't want to
3653 // reset the window scrolling. RR.
3654 // Furthermore, we actually do NOT subtract the border
3655 // width as 2 pixels is just the extra space which we
3656 // need around the actual content in the window. Other-
3657 // wise the text would e.g. touch the upper border. RR.
3660 GetSize( &clientWidth
, &clientHeight
);
3662 if ( InReportView() )
3664 // all lines have the same height and we scroll one line per step
3665 int entireHeight
= count
* lineHeight
+ LINE_SPACING
;
3667 m_linesPerPage
= clientHeight
/ lineHeight
;
3669 ResetVisibleLinesRange();
3671 GetListCtrl()->SetScrollbars( SCROLL_UNIT_X
, lineHeight
,
3672 GetHeaderWidth() / SCROLL_UNIT_X
,
3673 (entireHeight
+ lineHeight
- 1) / lineHeight
,
3674 GetListCtrl()->GetScrollPos(wxHORIZONTAL
),
3675 GetListCtrl()->GetScrollPos(wxVERTICAL
),
3680 // we have 3 different layout strategies: either layout all items
3681 // horizontally/vertically (wxLC_ALIGN_XXX styles explicitly given) or
3682 // to arrange them in top to bottom, left to right (don't ask me why
3683 // not the other way round...) order
3684 if ( HasFlag(wxLC_ALIGN_LEFT
| wxLC_ALIGN_TOP
) )
3686 int x
= EXTRA_BORDER_X
;
3687 int y
= EXTRA_BORDER_Y
;
3689 wxCoord widthMax
= 0;
3692 for ( i
= 0; i
< count
; i
++ )
3694 wxListLineData
*line
= GetLine(i
);
3695 line
->CalculateSize( &dc
, iconSpacing
);
3696 line
->SetPosition( x
, y
, iconSpacing
);
3698 wxSize sizeLine
= GetLineSize(i
);
3700 if ( HasFlag(wxLC_ALIGN_TOP
) )
3702 if ( sizeLine
.x
> widthMax
)
3703 widthMax
= sizeLine
.x
;
3707 else // wxLC_ALIGN_LEFT
3709 x
+= sizeLine
.x
+ MARGIN_BETWEEN_ROWS
;
3713 if ( HasFlag(wxLC_ALIGN_TOP
) )
3715 // traverse the items again and tweak their sizes so that they are
3716 // all the same in a row
3717 for ( i
= 0; i
< count
; i
++ )
3719 wxListLineData
*line
= GetLine(i
);
3720 line
->m_gi
->ExtendWidth(widthMax
);
3724 GetListCtrl()->SetScrollbars
3728 (x
+ SCROLL_UNIT_X
) / SCROLL_UNIT_X
,
3729 (y
+ lineHeight
) / lineHeight
,
3730 GetListCtrl()->GetScrollPos( wxHORIZONTAL
),
3731 GetListCtrl()->GetScrollPos( wxVERTICAL
),
3735 else // "flowed" arrangement, the most complicated case
3737 // at first we try without any scrollbars, if the items don't fit into
3738 // the window, we recalculate after subtracting the space taken by the
3741 int entireWidth
= 0;
3743 for (int tries
= 0; tries
< 2; tries
++)
3745 entireWidth
= 2 * EXTRA_BORDER_X
;
3749 // Now we have decided that the items do not fit into the
3750 // client area, so we need a scrollbar
3751 entireWidth
+= SCROLL_UNIT_X
;
3754 int x
= EXTRA_BORDER_X
;
3755 int y
= EXTRA_BORDER_Y
;
3757 // Note that "row" here is vertical, i.e. what is called
3758 // "column" in many other places in wxWidgets.
3759 int maxWidthInThisRow
= 0;
3762 int currentlyVisibleLines
= 0;
3764 for (size_t i
= 0; i
< count
; i
++)
3766 currentlyVisibleLines
++;
3767 wxListLineData
*line
= GetLine( i
);
3768 line
->CalculateSize( &dc
, iconSpacing
);
3769 line
->SetPosition( x
, y
, iconSpacing
);
3771 wxSize sizeLine
= GetLineSize( i
);
3773 if ( maxWidthInThisRow
< sizeLine
.x
)
3774 maxWidthInThisRow
= sizeLine
.x
;
3777 if (currentlyVisibleLines
> m_linesPerPage
)
3778 m_linesPerPage
= currentlyVisibleLines
;
3780 // Have we reached the end of the row either because no
3781 // more items would fit or because there are simply no more
3783 if ( y
+ sizeLine
.y
>= clientHeight
3786 // Adjust all items in this row to have the same
3787 // width to ensure that they all align horizontally in
3789 if ( HasFlag(wxLC_ICON
) || HasFlag(wxLC_SMALL_ICON
) )
3791 size_t firstRowLine
= i
- currentlyVisibleLines
+ 1;
3792 for (size_t j
= firstRowLine
; j
<= i
; j
++)
3794 GetLine(j
)->m_gi
->ExtendWidth(maxWidthInThisRow
);
3798 currentlyVisibleLines
= 0;
3800 maxWidthInThisRow
+= MARGIN_BETWEEN_ROWS
;
3801 x
+= maxWidthInThisRow
;
3802 entireWidth
+= maxWidthInThisRow
;
3803 maxWidthInThisRow
= 0;
3806 if ( (tries
== 0) &&
3807 (entireWidth
+ SCROLL_UNIT_X
> clientWidth
) )
3809 clientHeight
-= wxSystemSettings::
3810 GetMetric(wxSYS_HSCROLL_Y
);
3815 if ( i
== count
- 1 )
3816 tries
= 1; // Everything fits, no second try required.
3820 GetListCtrl()->SetScrollbars
3824 (entireWidth
+ SCROLL_UNIT_X
) / SCROLL_UNIT_X
,
3826 GetListCtrl()->GetScrollPos( wxHORIZONTAL
),
3835 // FIXME: why should we call it from here?
3842 void wxListMainWindow::RefreshAll()
3847 wxListHeaderWindow
*headerWin
= GetListCtrl()->m_headerWin
;
3848 if ( headerWin
&& headerWin
->m_dirty
)
3850 headerWin
->m_dirty
= false;
3851 headerWin
->Refresh();
3855 void wxListMainWindow::UpdateCurrent()
3857 if ( !HasCurrent() && !IsEmpty() )
3861 long wxListMainWindow::GetNextItem( long item
,
3862 int WXUNUSED(geometry
),
3866 max
= GetItemCount();
3867 wxCHECK_MSG( (ret
== -1) || (ret
< max
), -1,
3868 wxT("invalid listctrl index in GetNextItem()") );
3870 // notice that we start with the next item (or the first one if item == -1)
3871 // and this is intentional to allow writing a simple loop to iterate over
3872 // all selected items
3875 // this is not an error because the index was OK initially,
3876 // just no such item
3883 size_t count
= GetItemCount();
3884 for ( size_t line
= (size_t)ret
; line
< count
; line
++ )
3886 if ( (state
& wxLIST_STATE_FOCUSED
) && (line
== m_current
) )
3889 if ( (state
& wxLIST_STATE_SELECTED
) && IsHighlighted(line
) )
3896 // ----------------------------------------------------------------------------
3898 // ----------------------------------------------------------------------------
3900 void wxListMainWindow::DeleteItem( long lindex
)
3902 size_t count
= GetItemCount();
3904 wxCHECK_RET( (lindex
>= 0) && ((size_t)lindex
< count
),
3905 wxT("invalid item index in DeleteItem") );
3907 size_t index
= (size_t)lindex
;
3909 // we don't need to adjust the index for the previous items
3910 if ( HasCurrent() && m_current
>= index
)
3912 // if the current item is being deleted, we want the next one to
3913 // become selected - unless there is no next one - so don't adjust
3914 // m_current in this case
3915 if ( m_current
!= index
|| m_current
== count
- 1 )
3919 if ( InReportView() )
3921 // mark the Column Max Width cache as dirty if the items in the line
3922 // we're deleting contain the Max Column Width
3923 wxListLineData
* const line
= GetLine(index
);
3924 wxListItemDataList::compatibility_iterator n
;
3925 wxListItemData
*itemData
;
3929 for (size_t i
= 0; i
< m_columns
.GetCount(); i
++)
3931 n
= line
->m_items
.Item( i
);
3932 itemData
= n
->GetData();
3933 itemData
->GetItem(item
);
3935 itemWidth
= GetItemWidthWithImage(&item
);
3937 if (itemWidth
>= m_aColWidths
.Item(i
)->nMaxWidth
)
3938 m_aColWidths
.Item(i
)->bNeedsUpdate
= true;
3941 ResetVisibleLinesRange();
3944 SendNotify( index
, wxEVT_LIST_DELETE_ITEM
, wxDefaultPosition
);
3949 m_selStore
.OnItemDelete(index
);
3953 m_lines
.RemoveAt( index
);
3956 // we need to refresh the (vert) scrollbar as the number of items changed
3959 RefreshAfter(index
);
3962 void wxListMainWindow::DeleteColumn( int col
)
3964 wxListHeaderDataList::compatibility_iterator node
= m_columns
.Item( col
);
3966 wxCHECK_RET( node
, wxT("invalid column index in DeleteColumn()") );
3969 delete node
->GetData();
3970 m_columns
.Erase( node
);
3974 // update all the items
3975 for ( size_t i
= 0; i
< m_lines
.GetCount(); i
++ )
3977 wxListLineData
* const line
= GetLine(i
);
3979 // In the following atypical but possible scenario it can be
3980 // legal to call DeleteColumn() but the items may not have any
3982 // 1. In report view, insert a second column.
3983 // 2. Still in report view, add an item with 2 values.
3984 // 3. Switch to an icon (or list) view.
3985 // 4. Add an item -- necessarily with 1 value only.
3986 // 5. Switch back to report view.
3987 // 6. Call DeleteColumn().
3988 // So we need to check for this as otherwise we would simply crash
3990 if ( line
->m_items
.GetCount() <= static_cast<unsigned>(col
) )
3993 wxListItemDataList::compatibility_iterator n
= line
->m_items
.Item( col
);
3994 delete n
->GetData();
3995 line
->m_items
.Erase(n
);
3999 if ( InReportView() ) // we only cache max widths when in Report View
4001 delete m_aColWidths
.Item(col
);
4002 m_aColWidths
.RemoveAt(col
);
4005 // invalidate it as it has to be recalculated
4009 void wxListMainWindow::DoDeleteAllItems()
4012 // nothing to do - in particular, don't send the event
4017 // to make the deletion of all items faster, we don't send the
4018 // notifications for each item deletion in this case but only one event
4019 // for all of them: this is compatible with wxMSW and documented in
4020 // DeleteAllItems() description
4022 wxListEvent
event( wxEVT_LIST_DELETE_ALL_ITEMS
, GetParent()->GetId() );
4023 event
.SetEventObject( GetParent() );
4024 GetParent()->GetEventHandler()->ProcessEvent( event
);
4032 if ( InReportView() )
4034 ResetVisibleLinesRange();
4035 for (size_t i
= 0; i
< m_aColWidths
.GetCount(); i
++)
4037 m_aColWidths
.Item(i
)->bNeedsUpdate
= true;
4044 void wxListMainWindow::DeleteAllItems()
4048 RecalculatePositions();
4051 void wxListMainWindow::DeleteEverything()
4053 WX_CLEAR_LIST(wxListHeaderDataList
, m_columns
);
4054 WX_CLEAR_ARRAY(m_aColWidths
);
4059 // ----------------------------------------------------------------------------
4060 // scanning for an item
4061 // ----------------------------------------------------------------------------
4063 void wxListMainWindow::EnsureVisible( long index
)
4065 wxCHECK_RET( index
>= 0 && (size_t)index
< GetItemCount(),
4066 wxT("invalid index in EnsureVisible") );
4068 // We have to call this here because the label in question might just have
4069 // been added and its position is not known yet
4071 RecalculatePositions(true /* no refresh */);
4073 MoveToItem((size_t)index
);
4076 long wxListMainWindow::FindItem(long start
, const wxString
& str
, bool partial
)
4082 wxString str_upper
= str
.Upper();
4086 size_t count
= GetItemCount();
4087 for ( size_t i
= (size_t)pos
; i
< count
; i
++ )
4089 wxListLineData
*line
= GetLine(i
);
4090 wxString line_upper
= line
->GetText(0).Upper();
4093 if (line_upper
== str_upper
)
4098 if (line_upper
.find(str_upper
) == 0)
4106 long wxListMainWindow::FindItem(long start
, wxUIntPtr data
)
4112 size_t count
= GetItemCount();
4113 for (size_t i
= (size_t)pos
; i
< count
; i
++)
4115 wxListLineData
*line
= GetLine(i
);
4117 line
->GetItem( 0, item
);
4118 if (item
.m_data
== data
)
4125 long wxListMainWindow::FindItem( const wxPoint
& pt
)
4128 GetVisibleLinesRange( &topItem
, NULL
);
4131 GetItemPosition( GetItemCount() - 1, p
);
4135 long id
= (long)floor( pt
.y
* double(GetItemCount() - topItem
- 1) / p
.y
+ topItem
);
4136 if ( id
>= 0 && id
< (long)GetItemCount() )
4142 long wxListMainWindow::HitTest( int x
, int y
, int &flags
) const
4144 GetListCtrl()->CalcUnscrolledPosition( x
, y
, &x
, &y
);
4146 size_t count
= GetItemCount();
4148 if ( InReportView() )
4150 size_t current
= y
/ GetLineHeight();
4151 if ( current
< count
)
4153 flags
= HitTestLine(current
, x
, y
);
4160 // TODO: optimize it too! this is less simple than for report view but
4161 // enumerating all items is still not a way to do it!!
4162 for ( size_t current
= 0; current
< count
; current
++ )
4164 flags
= HitTestLine(current
, x
, y
);
4173 // ----------------------------------------------------------------------------
4175 // ----------------------------------------------------------------------------
4177 void wxListMainWindow::InsertItem( wxListItem
&item
)
4179 wxASSERT_MSG( !IsVirtual(), wxT("can't be used with virtual control") );
4181 int count
= GetItemCount();
4182 wxCHECK_RET( item
.m_itemId
>= 0, wxT("invalid item index") );
4184 if (item
.m_itemId
> count
)
4185 item
.m_itemId
= count
;
4187 size_t id
= item
.m_itemId
;
4191 if ( InReportView() )
4193 ResetVisibleLinesRange();
4195 const unsigned col
= item
.GetColumn();
4196 wxCHECK_RET( col
< m_aColWidths
.size(), "invalid item column" );
4198 // calculate the width of the item and adjust the max column width
4199 wxColWidthInfo
*pWidthInfo
= m_aColWidths
.Item(col
);
4200 int width
= GetItemWidthWithImage(&item
);
4201 item
.SetWidth(width
);
4202 if (width
> pWidthInfo
->nMaxWidth
)
4203 pWidthInfo
->nMaxWidth
= width
;
4206 wxListLineData
*line
= new wxListLineData(this);
4208 line
->SetItem( item
.m_col
, item
);
4209 if ( item
.m_mask
& wxLIST_MASK_IMAGE
)
4211 // Reset the buffered height if it's not big enough for the new image.
4212 int image
= item
.GetImage();
4213 if ( m_small_image_list
&& image
!= -1 && InReportView() )
4215 int imageWidth
, imageHeight
;
4216 m_small_image_list
->GetSize(image
, imageWidth
, imageHeight
);
4218 if ( imageHeight
> m_lineHeight
)
4223 m_lines
.Insert( line
, id
);
4227 // If an item is selected at or below the point of insertion, we need to
4228 // increment the member variables because the current row's index has gone
4230 if ( HasCurrent() && m_current
>= id
)
4233 SendNotify(id
, wxEVT_LIST_INSERT_ITEM
);
4235 RefreshLines(id
, GetItemCount() - 1);
4238 long wxListMainWindow::InsertColumn( long col
, const wxListItem
&item
)
4243 if ( InReportView() )
4245 wxListHeaderData
*column
= new wxListHeaderData( item
);
4246 if (item
.m_width
== wxLIST_AUTOSIZE_USEHEADER
)
4247 column
->SetWidth(ComputeMinHeaderWidth(column
));
4249 wxColWidthInfo
*colWidthInfo
= new wxColWidthInfo();
4251 bool insert
= (col
>= 0) && ((size_t)col
< m_columns
.GetCount());
4254 wxListHeaderDataList::compatibility_iterator
4255 node
= m_columns
.Item( col
);
4256 m_columns
.Insert( node
, column
);
4257 m_aColWidths
.Insert( colWidthInfo
, col
);
4262 idx
= m_aColWidths
.GetCount();
4263 m_columns
.Append( column
);
4264 m_aColWidths
.Add( colWidthInfo
);
4269 // update all the items
4270 for ( size_t i
= 0; i
< m_lines
.GetCount(); i
++ )
4272 wxListLineData
* const line
= GetLine(i
);
4273 wxListItemData
* const data
= new wxListItemData(this);
4275 line
->m_items
.Insert(col
, data
);
4277 line
->m_items
.Append(data
);
4281 // invalidate it as it has to be recalculated
4287 int wxListMainWindow::GetItemWidthWithImage(wxListItem
* item
)
4290 wxClientDC
dc(this);
4292 dc
.SetFont( GetFont() );
4294 if (item
->GetImage() != -1)
4297 GetImageSize( item
->GetImage(), ix
, iy
);
4301 if (!item
->GetText().empty())
4304 dc
.GetTextExtent( item
->GetText(), &w
, NULL
);
4311 // ----------------------------------------------------------------------------
4313 // ----------------------------------------------------------------------------
4315 static wxListCtrlCompare list_ctrl_compare_func_2
;
4316 static wxIntPtr list_ctrl_compare_data
;
4318 int LINKAGEMODE
list_ctrl_compare_func_1( wxListLineData
**arg1
, wxListLineData
**arg2
)
4320 wxListLineData
*line1
= *arg1
;
4321 wxListLineData
*line2
= *arg2
;
4323 line1
->GetItem( 0, item
);
4324 wxUIntPtr data1
= item
.m_data
;
4325 line2
->GetItem( 0, item
);
4326 wxUIntPtr data2
= item
.m_data
;
4327 return list_ctrl_compare_func_2( data1
, data2
, list_ctrl_compare_data
);
4330 void wxListMainWindow::SortItems( wxListCtrlCompare fn
, wxIntPtr data
)
4332 // selections won't make sense any more after sorting the items so reset
4334 HighlightAll(false);
4337 list_ctrl_compare_func_2
= fn
;
4338 list_ctrl_compare_data
= data
;
4339 m_lines
.Sort( list_ctrl_compare_func_1
);
4343 // ----------------------------------------------------------------------------
4345 // ----------------------------------------------------------------------------
4347 void wxListMainWindow::OnScroll(wxScrollWinEvent
& event
)
4349 // update our idea of which lines are shown when we redraw the window the
4351 ResetVisibleLinesRange();
4353 if ( event
.GetOrientation() == wxHORIZONTAL
&& HasHeader() )
4355 wxGenericListCtrl
* lc
= GetListCtrl();
4356 wxCHECK_RET( lc
, wxT("no listctrl window?") );
4358 if (lc
->m_headerWin
) // when we use wxLC_NO_HEADER, m_headerWin==NULL
4360 lc
->m_headerWin
->Refresh();
4361 lc
->m_headerWin
->Update();
4366 int wxListMainWindow::GetCountPerPage() const
4368 if ( !m_linesPerPage
)
4370 wxConstCast(this, wxListMainWindow
)->
4371 m_linesPerPage
= GetClientSize().y
/ GetLineHeight();
4374 return m_linesPerPage
;
4377 void wxListMainWindow::GetVisibleLinesRange(size_t *from
, size_t *to
)
4379 wxASSERT_MSG( InReportView(), wxT("this is for report mode only") );
4381 if ( m_lineFrom
== (size_t)-1 )
4383 size_t count
= GetItemCount();
4386 m_lineFrom
= GetListCtrl()->GetScrollPos(wxVERTICAL
);
4388 // this may happen if SetScrollbars() hadn't been called yet
4389 if ( m_lineFrom
>= count
)
4390 m_lineFrom
= count
- 1;
4392 // we redraw one extra line but this is needed to make the redrawing
4393 // logic work when there is a fractional number of lines on screen
4394 m_lineTo
= m_lineFrom
+ m_linesPerPage
;
4395 if ( m_lineTo
>= count
)
4396 m_lineTo
= count
- 1;
4398 else // empty control
4401 m_lineTo
= (size_t)-1;
4405 wxASSERT_MSG( IsEmpty() ||
4406 (m_lineFrom
<= m_lineTo
&& m_lineTo
< GetItemCount()),
4407 wxT("GetVisibleLinesRange() returns incorrect result") );
4416 wxListMainWindow::PrefixFindItem(size_t idParent
,
4417 const wxString
& prefixOrig
) const
4419 // if no items then just return
4420 if ( idParent
== (size_t)-1 )
4423 // match is case insensitive as this is more convenient to the user: having
4424 // to press Shift-letter to go to the item starting with a capital letter
4425 // would be too bothersome
4426 wxString prefix
= prefixOrig
.Lower();
4428 // determine the starting point: we shouldn't take the current item (this
4429 // allows to switch between two items starting with the same letter just by
4430 // pressing it) but we shouldn't jump to the next one if the user is
4431 // continuing to type as otherwise he might easily skip the item he wanted
4432 size_t itemid
= idParent
;
4433 if ( prefix
.length() == 1 )
4438 // look for the item starting with the given prefix after it
4439 while ( ( itemid
< (size_t)GetItemCount() ) &&
4440 !GetLine(itemid
)->GetText(0).Lower().StartsWith(prefix
) )
4445 // if we haven't found anything...
4446 if ( !( itemid
< (size_t)GetItemCount() ) )
4448 // ... wrap to the beginning
4451 // and try all the items (stop when we get to the one we started from)
4452 while ( ( itemid
< (size_t)GetItemCount() ) && itemid
!= idParent
&&
4453 !GetLine(itemid
)->GetText(0).Lower().StartsWith(prefix
) )
4457 // If we haven't found the item, id will be (size_t)-1, as per
4459 if ( !( itemid
< (size_t)GetItemCount() ) ||
4460 ( ( itemid
== idParent
) &&
4461 !GetLine(itemid
)->GetText(0).Lower().StartsWith(prefix
) ) )
4463 itemid
= (size_t)-1;
4470 // -------------------------------------------------------------------------------------
4471 // wxGenericListCtrl
4472 // -------------------------------------------------------------------------------------
4474 IMPLEMENT_DYNAMIC_CLASS(wxGenericListCtrl
, wxControl
)
4476 BEGIN_EVENT_TABLE(wxGenericListCtrl
,wxListCtrlBase
)
4477 EVT_SIZE(wxGenericListCtrl::OnSize
)
4478 EVT_SCROLLWIN(wxGenericListCtrl::OnScroll
)
4481 void wxGenericListCtrl::Init()
4483 m_imageListNormal
= NULL
;
4484 m_imageListSmall
= NULL
;
4485 m_imageListState
= NULL
;
4487 m_ownsImageListNormal
=
4488 m_ownsImageListSmall
=
4489 m_ownsImageListState
= false;
4495 wxGenericListCtrl::~wxGenericListCtrl()
4497 if (m_ownsImageListNormal
)
4498 delete m_imageListNormal
;
4499 if (m_ownsImageListSmall
)
4500 delete m_imageListSmall
;
4501 if (m_ownsImageListState
)
4502 delete m_imageListState
;
4505 void wxGenericListCtrl::CreateOrDestroyHeaderWindowAsNeeded()
4507 bool needs_header
= HasHeader();
4508 bool has_header
= (m_headerWin
!= NULL
);
4510 if (needs_header
== has_header
)
4515 // Notice that we must initialize m_headerWin first, and create the
4516 // real window only later, so that the test in the beginning of the
4517 // function blocks repeated creation of the header as it could happen
4518 // before via wxNavigationEnabled::AddChild() -> ToggleWindowStyle() ->
4519 // SetWindowStyleFlag().
4520 m_headerWin
= new wxListHeaderWindow();
4523 this, wxID_ANY
, m_mainWin
,
4528 wxRendererNative::Get().GetHeaderButtonHeight(this)
4533 #if defined( __WXMAC__ )
4534 static wxFont
font( wxOSX_SYSTEM_FONT_SMALL
);
4535 m_headerWin
->SetFont( font
);
4538 GetSizer()->Prepend( m_headerWin
, 0, wxGROW
);
4542 GetSizer()->Detach( m_headerWin
);
4544 wxDELETE(m_headerWin
);
4548 bool wxGenericListCtrl::Create(wxWindow
*parent
,
4553 const wxValidator
&validator
,
4554 const wxString
&name
)
4558 // just like in other ports, an assert will fail if the user doesn't give any type style:
4559 wxASSERT_MSG( (style
& wxLC_MASK_TYPE
),
4560 wxT("wxListCtrl style should have exactly one mode bit set") );
4562 if ( !wxListCtrlBase::Create( parent
, id
, pos
, size
,
4563 style
| wxVSCROLL
| wxHSCROLL
,
4567 m_mainWin
= new wxListMainWindow(this, wxID_ANY
, wxPoint(0, 0), size
);
4569 SetTargetWindow( m_mainWin
);
4571 // We use the cursor keys for moving the selection, not scrolling, so call
4572 // this method to ensure wxScrollHelperEvtHandler doesn't catch all
4573 // keyboard events forwarded to us from wxListMainWindow.
4574 DisableKeyboardScrolling();
4576 wxBoxSizer
*sizer
= new wxBoxSizer( wxVERTICAL
);
4577 sizer
->Add( m_mainWin
, 1, wxGROW
);
4580 CreateOrDestroyHeaderWindowAsNeeded();
4582 SetInitialSize(size
);
4587 wxBorder
wxGenericListCtrl::GetDefaultBorder() const
4589 return wxBORDER_THEME
;
4592 #if defined(__WXMSW__) && !defined(__WXWINCE__) && !defined(__WXUNIVERSAL__)
4593 WXLRESULT
wxGenericListCtrl::MSWWindowProc(WXUINT nMsg
,
4597 WXLRESULT rc
= wxListCtrlBase::MSWWindowProc(nMsg
, wParam
, lParam
);
4599 // we need to process arrows ourselves for scrolling
4600 if ( nMsg
== WM_GETDLGCODE
)
4602 rc
|= DLGC_WANTARROWS
;
4609 wxSize
wxGenericListCtrl::GetSizeAvailableForScrollTarget(const wxSize
& size
)
4611 wxSize newsize
= size
;
4613 newsize
.y
-= m_headerWin
->GetSize().y
;
4618 void wxGenericListCtrl::OnScroll(wxScrollWinEvent
& event
)
4620 // update our idea of which lines are shown when we redraw
4621 // the window the next time
4622 m_mainWin
->ResetVisibleLinesRange();
4624 if ( event
.GetOrientation() == wxHORIZONTAL
&& HasHeader() )
4626 m_headerWin
->Refresh();
4627 m_headerWin
->Update();
4630 // Let the window be scrolled as usual by the default handler.
4634 void wxGenericListCtrl::SetSingleStyle( long style
, bool add
)
4636 wxASSERT_MSG( !(style
& wxLC_VIRTUAL
),
4637 wxT("wxLC_VIRTUAL can't be [un]set") );
4639 long flag
= GetWindowStyle();
4643 if (style
& wxLC_MASK_TYPE
)
4644 flag
&= ~(wxLC_MASK_TYPE
| wxLC_VIRTUAL
);
4645 if (style
& wxLC_MASK_ALIGN
)
4646 flag
&= ~wxLC_MASK_ALIGN
;
4647 if (style
& wxLC_MASK_SORT
)
4648 flag
&= ~wxLC_MASK_SORT
;
4656 // some styles can be set without recreating everything (as happens in
4657 // SetWindowStyleFlag() which calls wxListMainWindow::DeleteEverything())
4658 if ( !(style
& ~(wxLC_HRULES
| wxLC_VRULES
)) )
4661 wxWindow::SetWindowStyleFlag(flag
);
4665 SetWindowStyleFlag( flag
);
4669 void wxGenericListCtrl::SetWindowStyleFlag( long flag
)
4671 // we add wxHSCROLL and wxVSCROLL in ctor unconditionally and it never
4672 // makes sense to remove them as we'll always add scrollbars anyhow when
4674 flag
|= wxHSCROLL
| wxVSCROLL
;
4676 const bool wasInReportView
= HasFlag(wxLC_REPORT
);
4678 // update the window style first so that the header is created or destroyed
4679 // corresponding to the new style
4680 wxWindow::SetWindowStyleFlag( flag
);
4684 const bool inReportView
= (flag
& wxLC_REPORT
) != 0;
4685 if ( inReportView
!= wasInReportView
)
4687 // we need to notify the main window about this change as it must
4688 // update its data structures
4689 m_mainWin
->SetReportView(inReportView
);
4692 // m_mainWin->DeleteEverything(); wxMSW doesn't do that
4694 CreateOrDestroyHeaderWindowAsNeeded();
4696 GetSizer()->Layout();
4700 bool wxGenericListCtrl::GetColumn(int col
, wxListItem
&item
) const
4702 m_mainWin
->GetColumn( col
, item
);
4706 bool wxGenericListCtrl::SetColumn( int col
, const wxListItem
& item
)
4708 m_mainWin
->SetColumn( col
, item
);
4712 int wxGenericListCtrl::GetColumnWidth( int col
) const
4714 return m_mainWin
->GetColumnWidth( col
);
4717 bool wxGenericListCtrl::SetColumnWidth( int col
, int width
)
4719 m_mainWin
->SetColumnWidth( col
, width
);
4723 int wxGenericListCtrl::GetCountPerPage() const
4725 return m_mainWin
->GetCountPerPage(); // different from Windows ?
4728 bool wxGenericListCtrl::GetItem( wxListItem
&info
) const
4730 m_mainWin
->GetItem( info
);
4734 bool wxGenericListCtrl::SetItem( wxListItem
&info
)
4736 m_mainWin
->SetItem( info
);
4740 long wxGenericListCtrl::SetItem( long index
, int col
, const wxString
& label
, int imageId
)
4743 info
.m_text
= label
;
4744 info
.m_mask
= wxLIST_MASK_TEXT
;
4745 info
.m_itemId
= index
;
4749 info
.m_image
= imageId
;
4750 info
.m_mask
|= wxLIST_MASK_IMAGE
;
4753 m_mainWin
->SetItem(info
);
4757 int wxGenericListCtrl::GetItemState( long item
, long stateMask
) const
4759 return m_mainWin
->GetItemState( item
, stateMask
);
4762 bool wxGenericListCtrl::SetItemState( long item
, long state
, long stateMask
)
4764 m_mainWin
->SetItemState( item
, state
, stateMask
);
4769 wxGenericListCtrl::SetItemImage( long item
, int image
, int WXUNUSED(selImage
) )
4771 return SetItemColumnImage(item
, 0, image
);
4775 wxGenericListCtrl::SetItemColumnImage( long item
, long column
, int image
)
4778 info
.m_image
= image
;
4779 info
.m_mask
= wxLIST_MASK_IMAGE
;
4780 info
.m_itemId
= item
;
4781 info
.m_col
= column
;
4782 m_mainWin
->SetItem( info
);
4786 wxString
wxGenericListCtrl::GetItemText( long item
, int col
) const
4788 return m_mainWin
->GetItemText(item
, col
);
4791 void wxGenericListCtrl::SetItemText( long item
, const wxString
& str
)
4793 m_mainWin
->SetItemText(item
, str
);
4796 wxUIntPtr
wxGenericListCtrl::GetItemData( long item
) const
4799 info
.m_mask
= wxLIST_MASK_DATA
;
4800 info
.m_itemId
= item
;
4801 m_mainWin
->GetItem( info
);
4805 bool wxGenericListCtrl::SetItemPtrData( long item
, wxUIntPtr data
)
4808 info
.m_mask
= wxLIST_MASK_DATA
;
4809 info
.m_itemId
= item
;
4811 m_mainWin
->SetItem( info
);
4815 wxRect
wxGenericListCtrl::GetViewRect() const
4817 return m_mainWin
->GetViewRect();
4820 bool wxGenericListCtrl::GetItemRect(long item
, wxRect
& rect
, int code
) const
4822 return GetSubItemRect(item
, wxLIST_GETSUBITEMRECT_WHOLEITEM
, rect
, code
);
4825 bool wxGenericListCtrl::GetSubItemRect(long item
,
4828 int WXUNUSED(code
)) const
4830 if ( !m_mainWin
->GetSubItemRect( item
, subItem
, rect
) )
4833 if ( m_mainWin
->HasHeader() )
4834 rect
.y
+= m_headerWin
->GetSize().y
+ 1;
4839 bool wxGenericListCtrl::GetItemPosition( long item
, wxPoint
& pos
) const
4841 m_mainWin
->GetItemPosition( item
, pos
);
4845 bool wxGenericListCtrl::SetItemPosition( long WXUNUSED(item
), const wxPoint
& WXUNUSED(pos
) )
4850 int wxGenericListCtrl::GetItemCount() const
4852 return m_mainWin
->GetItemCount();
4855 int wxGenericListCtrl::GetColumnCount() const
4857 return m_mainWin
->GetColumnCount();
4860 void wxGenericListCtrl::SetItemSpacing( int spacing
, bool isSmall
)
4862 m_mainWin
->SetItemSpacing( spacing
, isSmall
);
4865 wxSize
wxGenericListCtrl::GetItemSpacing() const
4867 const int spacing
= m_mainWin
->GetItemSpacing(HasFlag(wxLC_SMALL_ICON
));
4869 return wxSize(spacing
, spacing
);
4872 #if WXWIN_COMPATIBILITY_2_6
4873 int wxGenericListCtrl::GetItemSpacing( bool isSmall
) const
4875 return m_mainWin
->GetItemSpacing( isSmall
);
4877 #endif // WXWIN_COMPATIBILITY_2_6
4879 void wxGenericListCtrl::SetItemTextColour( long item
, const wxColour
&col
)
4882 info
.m_itemId
= item
;
4883 info
.SetTextColour( col
);
4884 m_mainWin
->SetItem( info
);
4887 wxColour
wxGenericListCtrl::GetItemTextColour( long item
) const
4890 info
.m_itemId
= item
;
4891 m_mainWin
->GetItem( info
);
4892 return info
.GetTextColour();
4895 void wxGenericListCtrl::SetItemBackgroundColour( long item
, const wxColour
&col
)
4898 info
.m_itemId
= item
;
4899 info
.SetBackgroundColour( col
);
4900 m_mainWin
->SetItem( info
);
4903 wxColour
wxGenericListCtrl::GetItemBackgroundColour( long item
) const
4906 info
.m_itemId
= item
;
4907 m_mainWin
->GetItem( info
);
4908 return info
.GetBackgroundColour();
4911 void wxGenericListCtrl::SetItemFont( long item
, const wxFont
&f
)
4914 info
.m_itemId
= item
;
4916 m_mainWin
->SetItem( info
);
4919 wxFont
wxGenericListCtrl::GetItemFont( long item
) const
4922 info
.m_itemId
= item
;
4923 m_mainWin
->GetItem( info
);
4924 return info
.GetFont();
4927 int wxGenericListCtrl::GetSelectedItemCount() const
4929 return m_mainWin
->GetSelectedItemCount();
4932 wxColour
wxGenericListCtrl::GetTextColour() const
4934 return GetForegroundColour();
4937 void wxGenericListCtrl::SetTextColour(const wxColour
& col
)
4939 SetForegroundColour(col
);
4942 long wxGenericListCtrl::GetTopItem() const
4945 m_mainWin
->GetVisibleLinesRange(&top
, NULL
);
4949 long wxGenericListCtrl::GetNextItem( long item
, int geom
, int state
) const
4951 return m_mainWin
->GetNextItem( item
, geom
, state
);
4954 wxImageList
*wxGenericListCtrl::GetImageList(int which
) const
4956 if (which
== wxIMAGE_LIST_NORMAL
)
4957 return m_imageListNormal
;
4958 else if (which
== wxIMAGE_LIST_SMALL
)
4959 return m_imageListSmall
;
4960 else if (which
== wxIMAGE_LIST_STATE
)
4961 return m_imageListState
;
4966 void wxGenericListCtrl::SetImageList( wxImageList
*imageList
, int which
)
4968 if ( which
== wxIMAGE_LIST_NORMAL
)
4970 if (m_ownsImageListNormal
)
4971 delete m_imageListNormal
;
4972 m_imageListNormal
= imageList
;
4973 m_ownsImageListNormal
= false;
4975 else if ( which
== wxIMAGE_LIST_SMALL
)
4977 if (m_ownsImageListSmall
)
4978 delete m_imageListSmall
;
4979 m_imageListSmall
= imageList
;
4980 m_ownsImageListSmall
= false;
4982 else if ( which
== wxIMAGE_LIST_STATE
)
4984 if (m_ownsImageListState
)
4985 delete m_imageListState
;
4986 m_imageListState
= imageList
;
4987 m_ownsImageListState
= false;
4990 m_mainWin
->SetImageList( imageList
, which
);
4993 void wxGenericListCtrl::AssignImageList(wxImageList
*imageList
, int which
)
4995 SetImageList(imageList
, which
);
4996 if ( which
== wxIMAGE_LIST_NORMAL
)
4997 m_ownsImageListNormal
= true;
4998 else if ( which
== wxIMAGE_LIST_SMALL
)
4999 m_ownsImageListSmall
= true;
5000 else if ( which
== wxIMAGE_LIST_STATE
)
5001 m_ownsImageListState
= true;
5004 bool wxGenericListCtrl::Arrange( int WXUNUSED(flag
) )
5009 bool wxGenericListCtrl::DeleteItem( long item
)
5011 m_mainWin
->DeleteItem( item
);
5015 bool wxGenericListCtrl::DeleteAllItems()
5017 m_mainWin
->DeleteAllItems();
5021 bool wxGenericListCtrl::DeleteAllColumns()
5023 size_t count
= m_mainWin
->m_columns
.GetCount();
5024 for ( size_t n
= 0; n
< count
; n
++ )
5029 void wxGenericListCtrl::ClearAll()
5031 m_mainWin
->DeleteEverything();
5034 bool wxGenericListCtrl::DeleteColumn( int col
)
5036 m_mainWin
->DeleteColumn( col
);
5038 // if we don't have the header any longer, we need to relayout the window
5039 // if ( !GetColumnCount() )
5042 // Ensure that the non-existent columns are really removed from display.
5048 wxTextCtrl
*wxGenericListCtrl::EditLabel(long item
,
5049 wxClassInfo
* textControlClass
)
5051 return m_mainWin
->EditLabel( item
, textControlClass
);
5054 wxTextCtrl
*wxGenericListCtrl::GetEditControl() const
5056 return m_mainWin
->GetEditControl();
5059 bool wxGenericListCtrl::EnsureVisible( long item
)
5061 m_mainWin
->EnsureVisible( item
);
5065 long wxGenericListCtrl::FindItem( long start
, const wxString
& str
, bool partial
)
5067 return m_mainWin
->FindItem( start
, str
, partial
);
5070 long wxGenericListCtrl::FindItem( long start
, wxUIntPtr data
)
5072 return m_mainWin
->FindItem( start
, data
);
5075 long wxGenericListCtrl::FindItem( long WXUNUSED(start
), const wxPoint
& pt
,
5076 int WXUNUSED(direction
))
5078 return m_mainWin
->FindItem( pt
);
5081 // TODO: sub item hit testing
5082 long wxGenericListCtrl::HitTest(const wxPoint
& point
, int& flags
, long *) const
5084 return m_mainWin
->HitTest( (int)point
.x
, (int)point
.y
, flags
);
5087 long wxGenericListCtrl::InsertItem( wxListItem
& info
)
5089 m_mainWin
->InsertItem( info
);
5090 return info
.m_itemId
;
5093 long wxGenericListCtrl::InsertItem( long index
, const wxString
&label
)
5096 info
.m_text
= label
;
5097 info
.m_mask
= wxLIST_MASK_TEXT
;
5098 info
.m_itemId
= index
;
5099 return InsertItem( info
);
5102 long wxGenericListCtrl::InsertItem( long index
, int imageIndex
)
5105 info
.m_mask
= wxLIST_MASK_IMAGE
;
5106 info
.m_image
= imageIndex
;
5107 info
.m_itemId
= index
;
5108 return InsertItem( info
);
5111 long wxGenericListCtrl::InsertItem( long index
, const wxString
&label
, int imageIndex
)
5114 info
.m_text
= label
;
5115 info
.m_image
= imageIndex
;
5116 info
.m_mask
= wxLIST_MASK_TEXT
;
5117 if (imageIndex
> -1)
5118 info
.m_mask
|= wxLIST_MASK_IMAGE
;
5119 info
.m_itemId
= index
;
5120 return InsertItem( info
);
5123 long wxGenericListCtrl::DoInsertColumn( long col
, const wxListItem
&item
)
5125 wxCHECK_MSG( InReportView(), -1, wxT("can't add column in non report mode") );
5127 long idx
= m_mainWin
->InsertColumn( col
, item
);
5129 // NOTE: if wxLC_NO_HEADER was given, then we are in report view mode but
5130 // still have m_headerWin==NULL
5132 m_headerWin
->Refresh();
5137 bool wxGenericListCtrl::ScrollList( int dx
, int dy
)
5139 return m_mainWin
->ScrollList(dx
, dy
);
5143 // fn is a function which takes 3 long arguments: item1, item2, data.
5144 // item1 is the long data associated with a first item (NOT the index).
5145 // item2 is the long data associated with a second item (NOT the index).
5146 // data is the same value as passed to SortItems.
5147 // The return value is a negative number if the first item should precede the second
5148 // item, a positive number of the second item should precede the first,
5149 // or zero if the two items are equivalent.
5150 // data is arbitrary data to be passed to the sort function.
5152 bool wxGenericListCtrl::SortItems( wxListCtrlCompare fn
, wxIntPtr data
)
5154 m_mainWin
->SortItems( fn
, data
);
5158 // ----------------------------------------------------------------------------
5160 // ----------------------------------------------------------------------------
5162 void wxGenericListCtrl::OnSize(wxSizeEvent
& WXUNUSED(event
))
5164 if (!m_mainWin
) return;
5166 // We need to override OnSize so that our scrolled
5167 // window a) does call Layout() to use sizers for
5168 // positioning the controls but b) does not query
5169 // the sizer for their size and use that for setting
5170 // the scrollable area as set that ourselves by
5171 // calling SetScrollbar() further down.
5175 m_mainWin
->RecalculatePositions();
5180 void wxGenericListCtrl::OnInternalIdle()
5182 wxWindow::OnInternalIdle();
5184 if (m_mainWin
->m_dirty
)
5185 m_mainWin
->RecalculatePositions();
5188 // ----------------------------------------------------------------------------
5190 // ----------------------------------------------------------------------------
5192 bool wxGenericListCtrl::SetBackgroundColour( const wxColour
&colour
)
5196 m_mainWin
->SetBackgroundColour( colour
);
5197 m_mainWin
->m_dirty
= true;
5203 bool wxGenericListCtrl::SetForegroundColour( const wxColour
&colour
)
5205 if ( !wxWindow::SetForegroundColour( colour
) )
5210 m_mainWin
->SetForegroundColour( colour
);
5211 m_mainWin
->m_dirty
= true;
5215 m_headerWin
->SetForegroundColour( colour
);
5220 bool wxGenericListCtrl::SetFont( const wxFont
&font
)
5222 if ( !wxWindow::SetFont( font
) )
5227 m_mainWin
->SetFont( font
);
5228 m_mainWin
->m_dirty
= true;
5233 m_headerWin
->SetFont( font
);
5234 // CalculateAndSetHeaderHeight();
5244 wxGenericListCtrl::GetClassDefaultAttributes(wxWindowVariant variant
)
5247 // Use the same color scheme as wxListBox
5248 return wxListBox::GetClassDefaultAttributes(variant
);
5250 wxUnusedVar(variant
);
5251 wxVisualAttributes attr
;
5252 attr
.colFg
= wxSystemSettings::GetColour(wxSYS_COLOUR_LISTBOXTEXT
);
5253 attr
.colBg
= wxSystemSettings::GetColour(wxSYS_COLOUR_LISTBOX
);
5254 attr
.font
= wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT
);
5259 // ----------------------------------------------------------------------------
5260 // methods forwarded to m_mainWin
5261 // ----------------------------------------------------------------------------
5263 #if wxUSE_DRAG_AND_DROP
5265 void wxGenericListCtrl::SetDropTarget( wxDropTarget
*dropTarget
)
5267 m_mainWin
->SetDropTarget( dropTarget
);
5270 wxDropTarget
*wxGenericListCtrl::GetDropTarget() const
5272 return m_mainWin
->GetDropTarget();
5277 bool wxGenericListCtrl::SetCursor( const wxCursor
&cursor
)
5279 return m_mainWin
? m_mainWin
->wxWindow::SetCursor(cursor
) : false;
5282 wxColour
wxGenericListCtrl::GetBackgroundColour() const
5284 return m_mainWin
? m_mainWin
->GetBackgroundColour() : wxColour();
5287 wxColour
wxGenericListCtrl::GetForegroundColour() const
5289 return m_mainWin
? m_mainWin
->GetForegroundColour() : wxColour();
5292 bool wxGenericListCtrl::DoPopupMenu( wxMenu
*menu
, int x
, int y
)
5295 return m_mainWin
->PopupMenu( menu
, x
, y
);
5301 wxSize
wxGenericListCtrl::DoGetBestClientSize() const
5303 // The base class version can compute the best size in report view only.
5304 wxSize sizeBest
= wxListCtrlBase::DoGetBestClientSize();
5306 if ( !InReportView() )
5308 // Ensure that our minimal width is at least big enough to show all our
5309 // items. This is important for wxListbook to size itself correctly.
5311 // Remember the offset of the first item: this corresponds to the
5312 // margins around the item so we will add it to the minimal size below
5313 // to ensure that we have equal margins on all sides.
5316 // We can iterate over all items as there shouldn't be too many of them
5317 // in non-report view. If it ever becomes a problem, we could examine
5318 // just the first few items probably, the determination of the best
5319 // size is less important if we will need scrollbars anyhow.
5320 for ( int n
= 0; n
< GetItemCount(); n
++ )
5322 const wxRect itemRect
= m_mainWin
->GetLineRect(n
);
5325 // Remember the position of the first item as all the rest are
5326 // offset by at least this number of pixels too.
5327 ofs
= itemRect
.GetPosition();
5330 sizeBest
.IncTo(itemRect
.GetSize());
5333 sizeBest
.IncBy(2*ofs
);
5336 // If we have the scrollbars we need to account for them too. And to
5337 // make sure the scrollbars status is up to date we need to call this
5338 // function to set them.
5339 m_mainWin
->RecalculatePositions(true /* no refresh */);
5341 // Unfortunately we can't use wxWindow::HasScrollbar() here as we need
5342 // to use m_mainWin client/virtual size for determination of whether we
5343 // use scrollbars and not the size of this window itself. Maybe that
5344 // function should be extended to work correctly in the case when our
5345 // scrollbars manage a different window from this one but currently it
5347 const wxSize sizeClient
= m_mainWin
->GetClientSize();
5348 const wxSize sizeVirt
= m_mainWin
->GetVirtualSize();
5350 if ( sizeVirt
.x
> sizeClient
.x
/* HasScrollbar(wxHORIZONTAL) */ )
5351 sizeBest
.y
+= wxSystemSettings::GetMetric(wxSYS_HSCROLL_Y
);
5353 if ( sizeVirt
.y
> sizeClient
.y
/* HasScrollbar(wxVERTICAL) */ )
5354 sizeBest
.x
+= wxSystemSettings::GetMetric(wxSYS_VSCROLL_X
);
5360 // ----------------------------------------------------------------------------
5361 // virtual list control support
5362 // ----------------------------------------------------------------------------
5364 wxString
wxGenericListCtrl::OnGetItemText(long WXUNUSED(item
), long WXUNUSED(col
)) const
5366 // this is a pure virtual function, in fact - which is not really pure
5367 // because the controls which are not virtual don't need to implement it
5368 wxFAIL_MSG( wxT("wxGenericListCtrl::OnGetItemText not supposed to be called") );
5370 return wxEmptyString
;
5373 int wxGenericListCtrl::OnGetItemImage(long WXUNUSED(item
)) const
5375 wxCHECK_MSG(!GetImageList(wxIMAGE_LIST_SMALL
),
5377 wxT("List control has an image list, OnGetItemImage or OnGetItemColumnImage should be overridden."));
5381 int wxGenericListCtrl::OnGetItemColumnImage(long item
, long column
) const
5384 return OnGetItemImage(item
);
5389 void wxGenericListCtrl::SetItemCount(long count
)
5391 wxASSERT_MSG( IsVirtual(), wxT("this is for virtual controls only") );
5393 m_mainWin
->SetItemCount(count
);
5396 void wxGenericListCtrl::RefreshItem(long item
)
5398 m_mainWin
->RefreshLine(item
);
5401 void wxGenericListCtrl::RefreshItems(long itemFrom
, long itemTo
)
5403 m_mainWin
->RefreshLines(itemFrom
, itemTo
);
5406 void wxGenericListCtrl::EnableBellOnNoMatch( bool on
)
5408 m_mainWin
->EnableBellOnNoMatch(on
);
5411 // Generic wxListCtrl is more or less a container for two other
5412 // windows which drawings are done upon. These are namely
5413 // 'm_headerWin' and 'm_mainWin'.
5414 // Here we override 'virtual wxWindow::Refresh()' to mimic the
5415 // behaviour wxListCtrl has under wxMSW.
5417 void wxGenericListCtrl::Refresh(bool eraseBackground
, const wxRect
*rect
)
5421 // The easy case, no rectangle specified.
5423 m_headerWin
->Refresh(eraseBackground
);
5426 m_mainWin
->Refresh(eraseBackground
);
5430 // Refresh the header window
5433 wxRect rectHeader
= m_headerWin
->GetRect();
5434 rectHeader
.Intersect(*rect
);
5435 if (rectHeader
.GetWidth() && rectHeader
.GetHeight())
5438 m_headerWin
->GetPosition(&x
, &y
);
5439 rectHeader
.Offset(-x
, -y
);
5440 m_headerWin
->Refresh(eraseBackground
, &rectHeader
);
5444 // Refresh the main window
5447 wxRect rectMain
= m_mainWin
->GetRect();
5448 rectMain
.Intersect(*rect
);
5449 if (rectMain
.GetWidth() && rectMain
.GetHeight())
5452 m_mainWin
->GetPosition(&x
, &y
);
5453 rectMain
.Offset(-x
, -y
);
5454 m_mainWin
->Refresh(eraseBackground
, &rectMain
);
5460 void wxGenericListCtrl::Update()
5464 if ( m_mainWin
->m_dirty
)
5465 m_mainWin
->RecalculatePositions();
5467 m_mainWin
->Update();
5471 m_headerWin
->Update();
5474 #endif // wxUSE_LISTCTRL