1 /////////////////////////////////////////////////////////////////////////////
4 // Author: Robert Roebling
6 // Copyright: (c) 1998 Robert Roebling
7 // Licence: wxWindows licence
8 /////////////////////////////////////////////////////////////////////////////
11 #pragma implementation "listctrl.h"
14 // For compilers that support precompilation, includes "wx.h".
15 #include "wx/wxprec.h"
21 #include "wx/dcscreen.h"
23 #include "wx/listctrl.h"
24 #include "wx/generic/imaglist.h"
26 #ifndef wxUSE_GENERIC_LIST_EXTENSIONS
27 #define wxUSE_GENERIC_LIST_EXTENSIONS 0
30 //-----------------------------------------------------------------------------
32 //-----------------------------------------------------------------------------
34 IMPLEMENT_DYNAMIC_CLASS(wxListItemData
,wxObject
);
36 wxListItemData::wxListItemData()
47 wxListItemData::wxListItemData( const wxListItem
&info
)
56 void wxListItemData::SetItem( const wxListItem
&info
)
58 if (info
.m_mask
& wxLIST_MASK_TEXT
) m_text
= info
.m_text
;
59 if (info
.m_mask
& wxLIST_MASK_IMAGE
) m_image
= info
.m_image
;
60 if (info
.m_mask
& wxLIST_MASK_DATA
) m_data
= info
.m_data
;
62 if ( info
.HasAttributes() )
65 *m_attr
= *info
.GetAttributes();
67 m_attr
= new wxListItemAttr(*info
.GetAttributes());
72 m_width
= info
.m_width
;
76 void wxListItemData::SetText( const wxString
&s
)
81 void wxListItemData::SetImage( int image
)
86 void wxListItemData::SetData( long data
)
91 void wxListItemData::SetPosition( int x
, int y
)
97 void wxListItemData::SetSize( int width
, int height
)
99 if (width
!= -1) m_width
= width
;
100 if (height
!= -1) m_height
= height
;
103 bool wxListItemData::HasImage() const
105 return (m_image
>= 0);
108 bool wxListItemData::HasText() const
110 return (!m_text
.IsNull());
113 bool wxListItemData::IsHit( int x
, int y
) const
115 return ((x
>= m_xpos
) && (x
<= m_xpos
+m_width
) && (y
>= m_ypos
) && (y
<= m_ypos
+m_height
));
118 void wxListItemData::GetText( wxString
&s
)
123 int wxListItemData::GetX() const
128 int wxListItemData::GetY() const
133 int wxListItemData::GetWidth() const
138 int wxListItemData::GetHeight() const
143 int wxListItemData::GetImage() const
148 void wxListItemData::GetItem( wxListItem
&info
) const
150 info
.m_text
= m_text
;
151 info
.m_image
= m_image
;
152 info
.m_data
= m_data
;
156 if ( m_attr
->HasTextColour() )
157 info
.SetTextColour(m_attr
->GetTextColour());
158 if ( m_attr
->HasBackgroundColour() )
159 info
.SetBackgroundColour(m_attr
->GetBackgroundColour());
160 if ( m_attr
->HasFont() )
161 info
.SetFont(m_attr
->GetFont());
165 //-----------------------------------------------------------------------------
167 //-----------------------------------------------------------------------------
169 IMPLEMENT_DYNAMIC_CLASS(wxListHeaderData
,wxObject
);
171 wxListHeaderData::wxListHeaderData()
182 wxListHeaderData::wxListHeaderData( const wxListItem
&item
)
190 void wxListHeaderData::SetItem( const wxListItem
&item
)
192 m_mask
= item
.m_mask
;
193 m_text
= item
.m_text
;
194 m_image
= item
.m_image
;
195 m_format
= item
.m_format
;
196 m_width
= item
.m_width
;
197 if (m_width
< 0) m_width
= 80;
198 if (m_width
< 6) m_width
= 6;
201 void wxListHeaderData::SetPosition( int x
, int y
)
207 void wxListHeaderData::SetHeight( int h
)
212 void wxListHeaderData::SetWidth( int w
)
215 if (m_width
< 0) m_width
= 80;
216 if (m_width
< 6) m_width
= 6;
219 void wxListHeaderData::SetFormat( int format
)
224 bool wxListHeaderData::HasImage() const
226 return (m_image
!= 0);
229 bool wxListHeaderData::HasText() const
231 return (m_text
.Length() > 0);
234 bool wxListHeaderData::IsHit( int x
, int y
) const
236 return ((x
>= m_xpos
) && (x
<= m_xpos
+m_width
) && (y
>= m_ypos
) && (y
<= m_ypos
+m_height
));
239 void wxListHeaderData::GetItem( wxListItem
&item
)
241 item
.m_mask
= m_mask
;
242 item
.m_text
= m_text
;
243 item
.m_image
= m_image
;
244 item
.m_format
= m_format
;
245 item
.m_width
= m_width
;
248 void wxListHeaderData::GetText( wxString
&s
)
253 int wxListHeaderData::GetImage() const
258 int wxListHeaderData::GetWidth() const
263 int wxListHeaderData::GetFormat() const
268 //-----------------------------------------------------------------------------
270 //-----------------------------------------------------------------------------
272 IMPLEMENT_DYNAMIC_CLASS(wxListLineData
,wxObject
);
274 wxListLineData::wxListLineData( wxListMainWindow
*owner
, int mode
, wxBrush
*hilightBrush
)
279 m_hilightBrush
= hilightBrush
;
280 m_items
.DeleteContents( TRUE
);
284 void wxListLineData::CalculateSize( wxDC
*dc
, int spacing
)
291 m_bound_all
.width
= m_spacing
;
292 m_bound_all
.height
= m_spacing
+13;
293 wxNode
*node
= m_items
.First();
296 wxListItemData
*item
= (wxListItemData
*)node
->Data();
297 wxString s
= item
->GetText();
299 dc
->GetTextExtent( s
, &lw
, &lh
);
300 if (lw
> m_spacing
) m_bound_all
.width
= lw
;
306 wxNode
*node
= m_items
.First();
309 wxListItemData
*item
= (wxListItemData
*)node
->Data();
310 wxString s
= item
->GetText();
312 dc
->GetTextExtent( s
, &lw
, &lh
);
313 m_bound_all
.width
= lw
;
314 m_bound_all
.height
= lh
;
315 if (item
->HasImage())
319 m_owner
->GetImageSize( item
->GetImage(), w
, h
);
320 m_bound_all
.width
+= 4 + w
;
321 if (h
> m_bound_all
.height
) m_bound_all
.height
= h
;
328 m_bound_all
.width
= 0;
329 m_bound_all
.height
= 0;
330 wxNode
*node
= m_items
.First();
333 wxListItemData
*item
= (wxListItemData
*)node
->Data();
336 if (s
.IsNull()) s
= "H";
338 dc
->GetTextExtent( s
, &lw
, &lh
);
339 item
->SetSize( item
->GetWidth(), lh
);
340 m_bound_all
.width
+= lw
;
341 m_bound_all
.height
= lh
;
349 void wxListLineData::SetPosition( wxDC
*dc
, int x
, int y
, int window_width
)
357 AssignRect( m_bound_icon
, 0, 0, 0, 0 );
358 AssignRect( m_bound_label
, 0, 0, 0, 0 );
359 AssignRect( m_bound_hilight
, m_bound_all
);
360 wxNode
*node
= m_items
.First();
363 wxListItemData
*item
= (wxListItemData
*)node
->Data();
364 if (item
->HasImage())
366 wxListItemData
*item
= (wxListItemData
*)node
->Data();
369 m_owner
->GetImageSize( item
->GetImage(), w
, h
);
370 m_bound_icon
.x
= m_bound_all
.x
+ (m_spacing
/2) - (w
/2);
371 m_bound_icon
.y
= m_bound_all
.y
+ m_spacing
- h
- 5;
372 m_bound_icon
.width
= w
;
373 m_bound_icon
.height
= h
;
374 if (!item
->HasText())
376 AssignRect( m_bound_hilight
, m_bound_icon
);
377 m_bound_hilight
.x
-= 5;
378 m_bound_hilight
.y
-= 5;
379 m_bound_hilight
.width
+= 9;
380 m_bound_hilight
.height
+= 9;
388 dc
->GetTextExtent( s
, &lw
, &lh
);
389 if (m_bound_all
.width
> m_spacing
)
390 m_bound_label
.x
= m_bound_all
.x
;
392 m_bound_label
.x
= m_bound_all
.x
+ (m_spacing
/2) - lw
/2;
393 m_bound_label
.y
= m_bound_all
.y
+ m_bound_all
.height
- lh
;
394 m_bound_label
.width
= lw
;
395 m_bound_label
.height
= lh
;
396 AssignRect( m_bound_hilight
, m_bound_label
);
397 m_bound_hilight
.x
-= 2;
398 m_bound_hilight
.y
-= 2;
399 m_bound_hilight
.width
+= 4;
400 m_bound_hilight
.height
+= 4;
407 AssignRect( m_bound_label
, m_bound_all
);
410 m_bound_all
.width
+= 4;
411 m_bound_all
.height
+= 3;
412 AssignRect( m_bound_hilight
, m_bound_all
);
413 AssignRect( m_bound_icon
, 0, 0, 0, 0 );
414 wxNode
*node
= m_items
.First();
417 wxListItemData
*item
= (wxListItemData
*)node
->Data();
418 if (item
->HasImage())
420 m_bound_icon
.x
= m_bound_all
.x
+ 2;
421 m_bound_icon
.y
= m_bound_all
.y
+ 2;
424 m_owner
->GetImageSize( item
->GetImage(), w
, h
);
425 m_bound_icon
.width
= w
;
426 m_bound_icon
.height
= h
;
427 m_bound_label
.x
+= 4 + w
;
428 m_bound_label
.width
-= 4 + w
;
436 dc
->GetTextExtent( "H", &lw
, &lh
);
439 m_bound_all
.height
= lh
+3;
440 m_bound_all
.width
= window_width
;
441 AssignRect( m_bound_hilight
, m_bound_all
);
442 AssignRect( m_bound_label
, m_bound_all
);
443 AssignRect( m_bound_icon
, 0, 0, 0, 0 );
444 wxNode
*node
= m_items
.First();
447 wxListItemData
*item
= (wxListItemData
*)node
->Data();
450 if (s
.IsEmpty()) s
= wxT("H");
452 dc
->GetTextExtent( s
, &lw
, &lh
);
453 m_bound_label
.width
= lw
;
454 m_bound_label
.height
= lh
;
455 if (item
->HasImage())
457 m_bound_icon
.x
= m_bound_all
.x
+ 2;
458 m_bound_icon
.y
= m_bound_all
.y
+ 2;
461 m_owner
->GetImageSize( item
->GetImage(), w
, h
);
462 m_bound_icon
.width
= w
;
463 m_bound_icon
.height
= h
;
464 m_bound_label
.x
+= 4 + w
;
472 void wxListLineData::SetColumnPosition( int index
, int x
)
475 wxNode
*node
= m_items
.Nth( i
);
478 wxListItemData
*item
= (wxListItemData
*)node
->Data();
479 item
->SetPosition( x
, m_bound_all
.y
+1 );
483 void wxListLineData::GetSize( int &width
, int &height
)
485 width
= m_bound_all
.width
;
486 height
= m_bound_all
.height
;
489 void wxListLineData::GetExtent( int &x
, int &y
, int &width
, int &height
)
493 width
= m_bound_all
.width
;
494 height
= m_bound_all
.height
;
497 void wxListLineData::GetLabelExtent( int &x
, int &y
, int &width
, int &height
)
501 width
= m_bound_label
.width
;
502 height
= m_bound_label
.height
;
505 void wxListLineData::GetRect( wxRect
&rect
)
507 AssignRect( rect
, m_bound_all
);
510 long wxListLineData::IsHit( int x
, int y
)
512 wxNode
*node
= m_items
.First();
515 wxListItemData
*item
= (wxListItemData
*)node
->Data();
516 if (item
->HasImage() && IsInRect( x
, y
, m_bound_icon
)) return wxLIST_HITTEST_ONITEMICON
;
517 if (item
->HasText() && IsInRect( x
, y
, m_bound_label
)) return wxLIST_HITTEST_ONITEMLABEL
;
518 // if (!(item->HasImage() || item->HasText())) return 0;
520 // if there is no icon or text = empty
521 if (IsInRect( x
, y
, m_bound_all
)) return wxLIST_HITTEST_ONITEMICON
;
525 void wxListLineData::InitItems( int num
)
527 for (int i
= 0; i
< num
; i
++) m_items
.Append( new wxListItemData() );
530 void wxListLineData::SetItem( int index
, const wxListItem
&info
)
532 wxNode
*node
= m_items
.Nth( index
);
535 wxListItemData
*item
= (wxListItemData
*)node
->Data();
536 item
->SetItem( info
);
540 void wxListLineData::GetItem( int index
, wxListItem
&info
)
543 wxNode
*node
= m_items
.Nth( i
);
546 wxListItemData
*item
= (wxListItemData
*)node
->Data();
547 item
->GetItem( info
);
551 void wxListLineData::GetText( int index
, wxString
&s
)
554 wxNode
*node
= m_items
.Nth( i
);
558 wxListItemData
*item
= (wxListItemData
*)node
->Data();
563 void wxListLineData::SetText( int index
, const wxString s
)
566 wxNode
*node
= m_items
.Nth( i
);
569 wxListItemData
*item
= (wxListItemData
*)node
->Data();
574 int wxListLineData::GetImage( int index
)
577 wxNode
*node
= m_items
.Nth( i
);
580 wxListItemData
*item
= (wxListItemData
*)node
->Data();
581 return item
->GetImage();
586 void wxListLineData::SetAttributes(wxDC
*dc
,
587 const wxListItemAttr
*attr
,
588 const wxColour
& colText
,
592 // don't use foregroud colour for drawing highlighted items - this might
593 // make them completely invisible (and there is no way to do bit
594 // arithmetics on wxColour, unfortunately)
595 if ( !hilight
&& attr
&& attr
->HasTextColour() )
597 dc
->SetTextForeground(attr
->GetTextColour());
601 dc
->SetTextForeground(colText
);
604 if ( attr
&& attr
->HasFont() )
606 dc
->SetFont(attr
->GetFont());
614 void wxListLineData::DoDraw( wxDC
*dc
, bool hilight
, bool paintBG
)
616 long dev_x
= dc
->LogicalToDeviceX( m_bound_all
.x
-2 );
617 long dev_y
= dc
->LogicalToDeviceY( m_bound_all
.y
-2 );
618 long dev_w
= dc
->LogicalToDeviceXRel( m_bound_all
.width
+4 );
619 long dev_h
= dc
->LogicalToDeviceYRel( m_bound_all
.height
+4 );
621 if (!m_owner
->IsExposed( dev_x
, dev_y
, dev_w
, dev_h
))
626 wxWindow
*listctrl
= m_owner
->GetParent();
628 // default foreground colour
632 colText
= wxSystemSettings::GetSystemColour( wxSYS_COLOUR_HIGHLIGHTTEXT
);
636 colText
= listctrl
->GetForegroundColour();
640 wxFont font
= listctrl
->GetFont();
642 // VZ: currently we set the colours/fonts only once, but like this (i.e.
643 // using SetAttributes() inside the loop), it will be trivial to
644 // customize the subitems (in report mode) too.
645 wxListItemData
*item
= (wxListItemData
*)m_items
.First()->Data();
646 wxListItemAttr
*attr
= item
->GetAttributes();
647 SetAttributes(dc
, attr
, colText
, font
, hilight
);
649 bool hasBgCol
= attr
&& attr
->HasBackgroundColour();
650 if ( paintBG
|| hasBgCol
)
654 dc
->SetBrush( * m_hilightBrush
);
659 dc
->SetBrush(wxBrush(attr
->GetBackgroundColour(), wxSOLID
));
661 dc
->SetBrush( * wxWHITE_BRUSH
);
664 dc
->SetPen( * wxTRANSPARENT_PEN
);
665 dc
->DrawRectangle( m_bound_hilight
.x
, m_bound_hilight
.y
,
666 m_bound_hilight
.width
, m_bound_hilight
.height
);
669 if (m_mode
== wxLC_REPORT
)
671 wxNode
*node
= m_items
.First();
674 wxListItemData
*item
= (wxListItemData
*)node
->Data();
675 dc
->SetClippingRegion( item
->GetX(), item
->GetY(), item
->GetWidth()-3, item
->GetHeight() );
676 int x
= item
->GetX();
677 if (item
->HasImage())
680 m_owner
->DrawImage( item
->GetImage(), dc
, x
, item
->GetY() );
681 m_owner
->GetImageSize( item
->GetImage(), x
, y
);
682 x
+= item
->GetX() + 5;
686 dc
->DrawText( item
->GetText(), x
, item
->GetY() );
688 dc
->DestroyClippingRegion();
694 wxNode
*node
= m_items
.First();
697 wxListItemData
*item
= (wxListItemData
*)node
->Data();
698 if (item
->HasImage())
700 m_owner
->DrawImage( item
->GetImage(), dc
, m_bound_icon
.x
, m_bound_icon
.y
);
704 dc
->DrawText( item
->GetText(), m_bound_label
.x
, m_bound_label
.y
);
710 void wxListLineData::Hilight( bool on
)
712 if (on
== m_hilighted
) return;
715 m_owner
->SelectLine( this );
717 m_owner
->DeselectLine( this );
720 void wxListLineData::ReverseHilight( void )
722 m_hilighted
= !m_hilighted
;
724 m_owner
->SelectLine( this );
726 m_owner
->DeselectLine( this );
729 void wxListLineData::DrawRubberBand( wxDC
*dc
, bool on
)
733 dc
->SetPen( * wxBLACK_PEN
);
734 dc
->SetBrush( * wxTRANSPARENT_BRUSH
);
735 dc
->DrawRectangle( m_bound_hilight
.x
, m_bound_hilight
.y
,
736 m_bound_hilight
.width
, m_bound_hilight
.height
);
740 void wxListLineData::Draw( wxDC
*dc
)
742 DoDraw( dc
, m_hilighted
, m_hilighted
);
745 bool wxListLineData::IsInRect( int x
, int y
, const wxRect
&rect
)
747 return ((x
>= rect
.x
) && (x
<= rect
.x
+rect
.width
) &&
748 (y
>= rect
.y
) && (y
<= rect
.y
+rect
.height
));
751 bool wxListLineData::IsHilighted( void )
756 void wxListLineData::AssignRect( wxRect
&dest
, int x
, int y
, int width
, int height
)
761 dest
.height
= height
;
764 void wxListLineData::AssignRect( wxRect
&dest
, const wxRect
&source
)
768 dest
.width
= source
.width
;
769 dest
.height
= source
.height
;
772 //-----------------------------------------------------------------------------
773 // wxListHeaderWindow
774 //-----------------------------------------------------------------------------
776 IMPLEMENT_DYNAMIC_CLASS(wxListHeaderWindow
,wxWindow
);
778 BEGIN_EVENT_TABLE(wxListHeaderWindow
,wxWindow
)
779 EVT_PAINT (wxListHeaderWindow::OnPaint
)
780 EVT_MOUSE_EVENTS (wxListHeaderWindow::OnMouse
)
781 EVT_SET_FOCUS (wxListHeaderWindow::OnSetFocus
)
784 wxListHeaderWindow::wxListHeaderWindow( void )
786 m_owner
= (wxListMainWindow
*) NULL
;
787 m_currentCursor
= (wxCursor
*) NULL
;
788 m_resizeCursor
= (wxCursor
*) NULL
;
789 m_isDragging
= FALSE
;
792 wxListHeaderWindow::wxListHeaderWindow( wxWindow
*win
, wxWindowID id
, wxListMainWindow
*owner
,
793 const wxPoint
&pos
, const wxSize
&size
,
794 long style
, const wxString
&name
) :
795 wxWindow( win
, id
, pos
, size
, style
, name
)
798 // m_currentCursor = wxSTANDARD_CURSOR;
799 m_currentCursor
= (wxCursor
*) NULL
;
800 m_resizeCursor
= new wxCursor( wxCURSOR_SIZEWE
);
801 m_isDragging
= FALSE
;
802 SetBackgroundColour( wxSystemSettings::GetSystemColour( wxSYS_COLOUR_BTNFACE
) );
805 wxListHeaderWindow::~wxListHeaderWindow( void )
807 delete m_resizeCursor
;
810 void wxListHeaderWindow::DoDrawRect( wxDC
*dc
, int x
, int y
, int w
, int h
)
812 const int m_corner
= 1;
814 dc
->SetBrush( *wxTRANSPARENT_BRUSH
);
816 dc
->SetPen( *wxBLACK_PEN
);
817 dc
->DrawLine( x
+w
-m_corner
+1, y
, x
+w
, y
+h
); // right (outer)
818 dc
->DrawRectangle( x
, y
+h
, w
+1, 1 ); // bottom (outer)
820 wxPen
pen( wxSystemSettings::GetSystemColour( wxSYS_COLOUR_BTNSHADOW
), 1, wxSOLID
);
823 dc
->DrawLine( x
+w
-m_corner
, y
, x
+w
-1, y
+h
); // right (inner)
824 dc
->DrawRectangle( x
+1, y
+h
-1, w
-2, 1 ); // bottom (inner)
826 dc
->SetPen( *wxWHITE_PEN
);
827 dc
->DrawRectangle( x
, y
, w
-m_corner
+1, 1 ); // top (outer)
828 dc
->DrawRectangle( x
, y
, 1, h
); // left (outer)
829 dc
->DrawLine( x
, y
+h
-1, x
+1, y
+h
-1 );
830 dc
->DrawLine( x
+w
-1, y
, x
+w
-1, y
+1 );
833 void wxListHeaderWindow::OnPaint( wxPaintEvent
&WXUNUSED(event
) )
835 wxPaintDC
dc( this );
837 #if wxUSE_GENERIC_LIST_EXTENSIONS
838 if ( m_owner
->GetMode() & wxLC_REPORT
)
843 m_owner
->GetScrollPixelsPerUnit( &xpix
, &ypix
) ;
844 m_owner
->ViewStart( &x
, &y
) ;
845 dc
.SetDeviceOrigin( -x
* xpix
, 0 );
850 dc
.SetFont( GetFont() );
856 GetClientSize( &w
, &h
);
858 dc
.SetBackgroundMode(wxTRANSPARENT
);
859 dc
.SetTextForeground( *wxBLACK
);
861 // do *not* use the listctrl colour for headers - one day we will have a
862 // function to set it separately
866 int numColumns
= m_owner
->GetColumnCount();
868 for (int i
= 0; i
< numColumns
; i
++)
870 m_owner
->GetColumn( i
, item
);
871 int cw
= item
.m_width
-2;
872 #if wxUSE_GENERIC_LIST_EXTENSIONS
873 if ((i
+1 == numColumns
) || ( dc
.LogicalToDeviceX(x
+item
.m_width
) > w
-5))
874 cw
= dc
.DeviceToLogicalX(w
)-x
-1;
876 if ((i
+1 == numColumns
) || (x
+item
.m_width
> w
-5))
879 dc
.SetPen( *wxWHITE_PEN
);
881 DoDrawRect( &dc
, x
, y
, cw
, h
-2 );
882 dc
.SetClippingRegion( x
, y
, cw
-5, h
-4 );
883 dc
.DrawText( item
.m_text
, x
+4, y
+3 );
884 dc
.DestroyClippingRegion();
886 #if wxUSE_GENERIC_LIST_EXTENSIONS
887 if (dc
.LogicalToDeviceX(x
) > w
+5) break;
895 void wxListHeaderWindow::DrawCurrent()
899 int x2
= m_currentX
-1;
902 m_owner
->GetClientSize( &dummy
, &y2
);
903 ClientToScreen( &x1
, &y1
);
904 m_owner
->ClientToScreen( &x2
, &y2
);
907 dc
.SetLogicalFunction( wxINVERT
);
908 dc
.SetPen( wxPen( *wxBLACK
, 2, wxSOLID
) );
909 dc
.SetBrush( *wxTRANSPARENT_BRUSH
);
911 dc
.DrawLine( x1
, y1
, x2
, y2
);
913 dc
.SetLogicalFunction( wxCOPY
);
915 dc
.SetPen( wxNullPen
);
916 dc
.SetBrush( wxNullBrush
);
919 void wxListHeaderWindow::OnMouse( wxMouseEvent
&event
)
921 int x
= event
.GetX();
922 int y
= event
.GetY();
926 if (event
.ButtonUp())
929 m_isDragging
= FALSE
;
930 m_owner
->SetColumnWidth( m_column
, m_currentX
-m_minX
);
936 GetClientSize( &size_x
, & dummy
);
940 m_currentX
= m_minX
+7;
941 if (m_currentX
> size_x
-7) m_currentX
= size_x
-7;
948 bool hit_border
= FALSE
;
950 for (int j
= 0; j
< m_owner
->GetColumnCount()-1; j
++)
952 xpos
+= m_owner
->GetColumnWidth( j
);
954 if ((abs(x
-xpos
) < 3) && (y
< 22))
966 if (event
.LeftDown())
978 wxListEvent
le( wxEVT_COMMAND_LIST_COL_CLICK
, GetParent()->GetId() );
979 le
.SetEventObject( GetParent() );
981 GetParent()->GetEventHandler()->ProcessEvent( le
);
990 if (m_currentCursor
== wxSTANDARD_CURSOR
) SetCursor( * m_resizeCursor
);
991 m_currentCursor
= m_resizeCursor
;
995 if (m_currentCursor
!= wxSTANDARD_CURSOR
) SetCursor( * wxSTANDARD_CURSOR
);
996 m_currentCursor
= wxSTANDARD_CURSOR
;
1001 void wxListHeaderWindow::OnSetFocus( wxFocusEvent
&WXUNUSED(event
) )
1003 m_owner
->SetFocus();
1006 //-----------------------------------------------------------------------------
1007 // wxListRenameTimer (internal)
1008 //-----------------------------------------------------------------------------
1010 wxListRenameTimer::wxListRenameTimer( wxListMainWindow
*owner
)
1015 void wxListRenameTimer::Notify()
1017 m_owner
->OnRenameTimer();
1020 //-----------------------------------------------------------------------------
1021 // wxListTextCtrl (internal)
1022 //-----------------------------------------------------------------------------
1024 IMPLEMENT_DYNAMIC_CLASS(wxListTextCtrl
,wxTextCtrl
);
1026 BEGIN_EVENT_TABLE(wxListTextCtrl
,wxTextCtrl
)
1027 EVT_CHAR (wxListTextCtrl::OnChar
)
1028 EVT_KILL_FOCUS (wxListTextCtrl::OnKillFocus
)
1031 wxListTextCtrl::wxListTextCtrl( wxWindow
*parent
, const wxWindowID id
,
1032 bool *accept
, wxString
*res
, wxListMainWindow
*owner
,
1033 const wxString
&value
, const wxPoint
&pos
, const wxSize
&size
,
1034 #if wxUSE_VALIDATORS
1035 int style
, const wxValidator
& validator
, const wxString
&name
) :
1037 wxTextCtrl( parent
, id
, value
, pos
, size
, style
, validator
, name
)
1042 (*m_accept
) = FALSE
;
1044 m_startValue
= value
;
1047 void wxListTextCtrl::OnChar( wxKeyEvent
&event
)
1049 if (event
.m_keyCode
== WXK_RETURN
)
1052 (*m_res
) = GetValue();
1053 m_owner
->SetFocus();
1056 if (event
.m_keyCode
== WXK_ESCAPE
)
1058 (*m_accept
) = FALSE
;
1060 m_owner
->SetFocus();
1066 void wxListTextCtrl::OnKillFocus( wxFocusEvent
&WXUNUSED(event
) )
1068 if (wxPendingDelete
.Member(this)) return;
1070 wxPendingDelete
.Append(this);
1072 if ((*m_accept
) && ((*m_res
) != m_startValue
))
1073 m_owner
->OnRenameAccept();
1076 //-----------------------------------------------------------------------------
1078 //-----------------------------------------------------------------------------
1080 IMPLEMENT_DYNAMIC_CLASS(wxListMainWindow
,wxScrolledWindow
);
1082 BEGIN_EVENT_TABLE(wxListMainWindow
,wxScrolledWindow
)
1083 EVT_PAINT (wxListMainWindow::OnPaint
)
1084 EVT_SIZE (wxListMainWindow::OnSize
)
1085 EVT_MOUSE_EVENTS (wxListMainWindow::OnMouse
)
1086 EVT_CHAR (wxListMainWindow::OnChar
)
1087 EVT_KEY_DOWN (wxListMainWindow::OnKeyDown
)
1088 EVT_SET_FOCUS (wxListMainWindow::OnSetFocus
)
1089 EVT_KILL_FOCUS (wxListMainWindow::OnKillFocus
)
1090 EVT_SCROLLWIN (wxListMainWindow::OnScroll
)
1093 wxListMainWindow::wxListMainWindow()
1096 m_lines
.DeleteContents( TRUE
);
1097 m_columns
.DeleteContents( TRUE
);
1098 m_current
= (wxListLineData
*) NULL
;
1100 m_hilightBrush
= (wxBrush
*) NULL
;
1104 m_small_image_list
= (wxImageList
*) NULL
;
1105 m_normal_image_list
= (wxImageList
*) NULL
;
1106 m_small_spacing
= 30;
1107 m_normal_spacing
= 40;
1110 m_lastOnSame
= FALSE
;
1111 m_renameTimer
= new wxListRenameTimer( this );
1112 m_isCreated
= FALSE
;
1116 wxListMainWindow::wxListMainWindow( wxWindow
*parent
, wxWindowID id
,
1117 const wxPoint
&pos
, const wxSize
&size
,
1118 long style
, const wxString
&name
) :
1119 wxScrolledWindow( parent
, id
, pos
, size
, style
|wxHSCROLL
|wxVSCROLL
, name
)
1122 m_lines
.DeleteContents( TRUE
);
1123 m_columns
.DeleteContents( TRUE
);
1124 m_current
= (wxListLineData
*) NULL
;
1127 m_hilightBrush
= new wxBrush( wxSystemSettings::GetSystemColour(wxSYS_COLOUR_HIGHLIGHT
), wxSOLID
);
1128 m_small_image_list
= (wxImageList
*) NULL
;
1129 m_normal_image_list
= (wxImageList
*) NULL
;
1130 m_small_spacing
= 30;
1131 m_normal_spacing
= 40;
1134 m_isCreated
= FALSE
;
1138 if (m_mode
& wxLC_REPORT
)
1140 #if wxUSE_GENERIC_LIST_EXTENSIONS
1152 SetScrollbars( m_xScroll
, m_yScroll
, 0, 0, 0, 0 );
1155 m_lastOnSame
= FALSE
;
1156 m_renameTimer
= new wxListRenameTimer( this );
1157 m_renameAccept
= FALSE
;
1159 SetBackgroundColour( *wxWHITE
);
1162 wxListMainWindow::~wxListMainWindow()
1164 if (m_hilightBrush
) delete m_hilightBrush
;
1166 delete m_renameTimer
;
1169 void wxListMainWindow::RefreshLine( wxListLineData
*line
)
1171 if (m_dirty
) return;
1179 wxClientDC
dc(this);
1181 line
->GetExtent( x
, y
, w
, h
);
1183 dc
.LogicalToDeviceX(x
-3),
1184 dc
.LogicalToDeviceY(y
-3),
1185 dc
.LogicalToDeviceXRel(w
+6),
1186 dc
.LogicalToDeviceXRel(h
+6) );
1187 Refresh( TRUE
, &rect
);
1191 void wxListMainWindow::OnPaint( wxPaintEvent
&WXUNUSED(event
) )
1193 // Note: a wxPaintDC must be constructed even if no drawing is
1194 // done (a Windows requirement).
1195 wxPaintDC
dc( this );
1198 if (m_dirty
) return;
1200 if (m_lines
.GetCount() == 0) return;
1204 dc
.SetFont( GetFont() );
1206 if (m_mode
& wxLC_REPORT
)
1208 int lineSpacing
= 0;
1209 wxListLineData
*line
= (wxListLineData
*)m_lines
.First()->Data();
1211 line
->GetSize( dummy
, lineSpacing
);
1214 int y_s
= m_yScroll
*GetScrollPos( wxVERTICAL
);
1216 wxNode
*node
= m_lines
.Nth( y_s
/ lineSpacing
);
1217 for (int i
= 0; i
< m_visibleLines
+2; i
++)
1221 line
= (wxListLineData
*)node
->Data();
1223 node
= node
->Next();
1228 wxNode
*node
= m_lines
.First();
1231 wxListLineData
*line
= (wxListLineData
*)node
->Data();
1233 node
= node
->Next();
1237 if (m_current
) m_current
->DrawRubberBand( &dc
, m_hasFocus
);
1242 void wxListMainWindow::HilightAll( bool on
)
1244 wxNode
*node
= m_lines
.First();
1247 wxListLineData
*line
= (wxListLineData
*)node
->Data();
1248 if (line
->IsHilighted() != on
)
1250 line
->Hilight( on
);
1251 RefreshLine( line
);
1253 node
= node
->Next();
1257 void wxListMainWindow::SendNotify( wxListLineData
*line
, wxEventType command
)
1259 wxListEvent
le( command
, GetParent()->GetId() );
1260 le
.SetEventObject( GetParent() );
1261 le
.m_itemIndex
= GetIndexOfLine( line
);
1262 line
->GetItem( 0, le
.m_item
);
1263 GetParent()->GetEventHandler()->ProcessEvent( le
);
1264 // GetParent()->GetEventHandler()->AddPendingEvent( le );
1267 void wxListMainWindow::FocusLine( wxListLineData
*WXUNUSED(line
) )
1269 // SendNotify( line, wxEVT_COMMAND_LIST_ITEM_FOCUSSED );
1272 void wxListMainWindow::UnfocusLine( wxListLineData
*WXUNUSED(line
) )
1274 // SendNotify( line, wxEVT_COMMAND_LIST_ITEM_UNFOCUSSED );
1277 void wxListMainWindow::SelectLine( wxListLineData
*line
)
1279 SendNotify( line
, wxEVT_COMMAND_LIST_ITEM_SELECTED
);
1282 void wxListMainWindow::DeselectLine( wxListLineData
*line
)
1284 SendNotify( line
, wxEVT_COMMAND_LIST_ITEM_DESELECTED
);
1287 void wxListMainWindow::DeleteLine( wxListLineData
*line
)
1289 SendNotify( line
, wxEVT_COMMAND_LIST_DELETE_ITEM
);
1294 void wxListMainWindow::EditLabel( long item
)
1296 wxNode
*node
= m_lines
.Nth( item
);
1297 wxCHECK_RET( node
, wxT("wrong index in wxListCtrl::Edit()") );
1299 m_currentEdit
= (wxListLineData
*) node
->Data();
1301 wxListEvent
le( wxEVT_COMMAND_LIST_BEGIN_LABEL_EDIT
, GetParent()->GetId() );
1302 le
.SetEventObject( GetParent() );
1303 le
.m_itemIndex
= GetIndexOfLine( m_currentEdit
);
1304 m_currentEdit
->GetItem( 0, le
.m_item
);
1305 GetParent()->GetEventHandler()->ProcessEvent( le
);
1307 if (!le
.IsAllowed())
1310 // We have to call this here because the label in
1311 // question might just have been added and no screen
1312 // update taken place.
1313 if (m_dirty
) wxYield();
1316 m_currentEdit
->GetText( 0, s
);
1321 m_currentEdit
->GetLabelExtent( x
, y
, w
, h
);
1323 wxClientDC
dc(this);
1325 x
= dc
.LogicalToDeviceX( x
);
1326 y
= dc
.LogicalToDeviceY( y
);
1328 wxListTextCtrl
*text
= new wxListTextCtrl(
1329 this, -1, &m_renameAccept
, &m_renameRes
, this, s
, wxPoint(x
-4,y
-4), wxSize(w
+11,h
+8) );
1333 void wxListMainWindow::OnRenameTimer()
1335 wxCHECK_RET( m_current
, wxT("invalid m_current") );
1337 Edit( m_lines
.IndexOf( m_current
) );
1340 void wxListMainWindow::OnRenameAccept()
1342 wxListEvent
le( wxEVT_COMMAND_LIST_END_LABEL_EDIT
, GetParent()->GetId() );
1343 le
.SetEventObject( GetParent() );
1344 le
.m_itemIndex
= GetIndexOfLine( m_currentEdit
);
1345 m_currentEdit
->GetItem( 0, le
.m_item
);
1346 le
.m_item
.m_text
= m_renameRes
;
1347 GetParent()->GetEventHandler()->ProcessEvent( le
);
1349 if (!le
.IsAllowed()) return;
1352 info
.m_mask
= wxLIST_MASK_TEXT
;
1353 info
.m_itemId
= le
.m_itemIndex
;
1354 info
.m_text
= m_renameRes
;
1355 info
.SetTextColour(le
.m_item
.GetTextColour());
1359 void wxListMainWindow::OnMouse( wxMouseEvent
&event
)
1361 if (GetParent()->GetEventHandler()->ProcessEvent( event
)) return;
1363 if (!m_current
) return;
1364 if (m_dirty
) return;
1365 if ( !(event
.Dragging() || event
.ButtonDown() || event
.LeftUp() || event
.ButtonDClick()) ) return;
1367 wxClientDC
dc(this);
1369 long x
= dc
.DeviceToLogicalX( (long)event
.GetX() );
1370 long y
= dc
.DeviceToLogicalY( (long)event
.GetY() );
1372 /* Did we actually hit an item ? */
1374 wxNode
*node
= m_lines
.First();
1375 wxListLineData
*line
= (wxListLineData
*) NULL
;
1378 line
= (wxListLineData
*)node
->Data();
1379 hitResult
= line
->IsHit( x
, y
);
1380 if (hitResult
) break;
1381 line
= (wxListLineData
*) NULL
;
1382 node
= node
->Next();
1385 if (event
.Dragging())
1387 if (m_dragCount
== 0)
1388 m_dragStart
= wxPoint(x
,y
);
1392 if (m_dragCount
!= 3) return;
1394 int command
= wxEVT_COMMAND_LIST_BEGIN_DRAG
;
1395 if (event
.RightIsDown()) command
= wxEVT_COMMAND_LIST_BEGIN_RDRAG
;
1397 wxListEvent
le( command
, GetParent()->GetId() );
1398 le
.SetEventObject( GetParent() );
1399 le
.m_pointDrag
= m_dragStart
;
1400 GetParent()->GetEventHandler()->ProcessEvent( le
);
1411 if (event
.ButtonDClick())
1414 m_lastOnSame
= FALSE
;
1415 m_renameTimer
->Stop();
1417 SendNotify( line
, wxEVT_COMMAND_LIST_ITEM_ACTIVATED
);
1422 if (event
.LeftUp() && m_lastOnSame
)
1425 if ((line
== m_current
) &&
1426 (hitResult
== wxLIST_HITTEST_ONITEMLABEL
) &&
1427 (m_mode
& wxLC_EDIT_LABELS
) )
1429 m_renameTimer
->Start( 100, TRUE
);
1431 m_lastOnSame
= FALSE
;
1435 if (event
.RightDown())
1437 SendNotify( line
, wxEVT_COMMAND_LIST_ITEM_RIGHT_CLICK
);
1441 if (event
.MiddleDown())
1443 SendNotify( line
, wxEVT_COMMAND_LIST_ITEM_MIDDLE_CLICK
);
1447 if (event
.LeftDown())
1450 wxListLineData
*oldCurrent
= m_current
;
1451 if (m_mode
& wxLC_SINGLE_SEL
)
1454 HilightAll( FALSE
);
1455 m_current
->ReverseHilight();
1456 RefreshLine( m_current
);
1460 if (event
.ShiftDown())
1463 m_current
->ReverseHilight();
1464 RefreshLine( m_current
);
1466 else if (event
.ControlDown())
1470 int numOfCurrent
= -1;
1471 node
= m_lines
.First();
1474 wxListLineData
*test_line
= (wxListLineData
*)node
->Data();
1476 if (test_line
== oldCurrent
) break;
1477 node
= node
->Next();
1481 node
= m_lines
.First();
1484 wxListLineData
*test_line
= (wxListLineData
*)node
->Data();
1486 if (test_line
== line
) break;
1487 node
= node
->Next();
1490 if (numOfLine
< numOfCurrent
)
1493 numOfLine
= numOfCurrent
;
1497 wxNode
*node
= m_lines
.Nth( numOfCurrent
);
1498 for (int i
= 0; i
<= numOfLine
-numOfCurrent
; i
++)
1500 wxListLineData
*test_line
= (wxListLineData
*)node
->Data();
1501 test_line
->Hilight(TRUE
);
1502 RefreshLine( test_line
);
1503 node
= node
->Next();
1509 HilightAll( FALSE
);
1510 m_current
->ReverseHilight();
1511 RefreshLine( m_current
);
1514 if (m_current
!= oldCurrent
)
1516 RefreshLine( oldCurrent
);
1517 UnfocusLine( oldCurrent
);
1518 FocusLine( m_current
);
1520 m_lastOnSame
= (m_current
== oldCurrent
);
1525 void wxListMainWindow::MoveToFocus()
1527 if (!m_current
) return;
1533 m_current
->GetExtent( x
, y
, w
, h
);
1537 GetClientSize( &w_p
, &h_p
);
1539 if (m_mode
& wxLC_REPORT
)
1541 int y_s
= m_yScroll
*GetScrollPos( wxVERTICAL
);
1542 if ((y
> y_s
) && (y
+h
< y_s
+h_p
)) return;
1543 if (y
-y_s
< 5) { Scroll( -1, (y
-5-h_p
/2)/m_yScroll
); }
1544 if (y
+h
+5 > y_s
+h_p
) { Scroll( -1, (y
+h
-h_p
/2+h
+15)/m_yScroll
); }
1548 int x_s
= m_xScroll
*GetScrollPos( wxHORIZONTAL
);
1549 if ((x
> x_s
) && (x
+w
< x_s
+w_p
)) return;
1550 if (x
-x_s
< 5) { Scroll( (x
-5)/m_xScroll
, -1 ); }
1551 if (x
+w
-5 > x_s
+w_p
) { Scroll( (x
+w
-w_p
+15)/m_xScroll
, -1 ); }
1555 void wxListMainWindow::OnArrowChar( wxListLineData
*newCurrent
, bool shiftDown
)
1557 if ((m_mode
& wxLC_SINGLE_SEL
) || (m_usedKeys
== FALSE
)) m_current
->Hilight( FALSE
);
1558 wxListLineData
*oldCurrent
= m_current
;
1559 m_current
= newCurrent
;
1561 if (shiftDown
|| (m_mode
& wxLC_SINGLE_SEL
)) m_current
->Hilight( TRUE
);
1562 RefreshLine( m_current
);
1563 RefreshLine( oldCurrent
);
1564 FocusLine( m_current
);
1565 UnfocusLine( oldCurrent
);
1568 void wxListMainWindow::OnKeyDown( wxKeyEvent
&event
)
1570 wxWindow
*parent
= GetParent();
1572 /* we propagate the key event up */
1573 wxKeyEvent
ke( wxEVT_KEY_DOWN
);
1574 ke
.m_shiftDown
= event
.m_shiftDown
;
1575 ke
.m_controlDown
= event
.m_controlDown
;
1576 ke
.m_altDown
= event
.m_altDown
;
1577 ke
.m_metaDown
= event
.m_metaDown
;
1578 ke
.m_keyCode
= event
.m_keyCode
;
1581 ke
.SetEventObject( parent
);
1582 if (parent
->GetEventHandler()->ProcessEvent( ke
)) return;
1587 void wxListMainWindow::OnChar( wxKeyEvent
&event
)
1589 wxWindow
*parent
= GetParent();
1591 /* we send a list_key event up */
1592 wxListEvent
le( wxEVT_COMMAND_LIST_KEY_DOWN
, GetParent()->GetId() );
1593 le
.m_code
= event
.KeyCode();
1594 le
.SetEventObject( parent
);
1595 parent
->GetEventHandler()->ProcessEvent( le
);
1597 /* we propagate the char event up */
1598 wxKeyEvent
ke( wxEVT_CHAR
);
1599 ke
.m_shiftDown
= event
.m_shiftDown
;
1600 ke
.m_controlDown
= event
.m_controlDown
;
1601 ke
.m_altDown
= event
.m_altDown
;
1602 ke
.m_metaDown
= event
.m_metaDown
;
1603 ke
.m_keyCode
= event
.m_keyCode
;
1606 ke
.SetEventObject( parent
);
1607 if (parent
->GetEventHandler()->ProcessEvent( ke
)) return;
1609 if (event
.KeyCode() == WXK_TAB
)
1611 wxNavigationKeyEvent nevent
;
1612 nevent
.SetDirection( !event
.ShiftDown() );
1613 nevent
.SetCurrentFocus( m_parent
);
1614 if (m_parent
->GetEventHandler()->ProcessEvent( nevent
)) return;
1617 /* no item -> nothing to do */
1624 switch (event
.KeyCode())
1628 wxNode
*node
= m_lines
.Member( m_current
)->Previous();
1629 if (node
) OnArrowChar( (wxListLineData
*)node
->Data(), event
.ShiftDown() );
1634 wxNode
*node
= m_lines
.Member( m_current
)->Next();
1635 if (node
) OnArrowChar( (wxListLineData
*)node
->Data(), event
.ShiftDown() );
1640 wxNode
*node
= m_lines
.Last();
1641 OnArrowChar( (wxListLineData
*)node
->Data(), event
.ShiftDown() );
1646 wxNode
*node
= m_lines
.First();
1647 OnArrowChar( (wxListLineData
*)node
->Data(), event
.ShiftDown() );
1653 if (m_mode
& wxLC_REPORT
)
1655 steps
= m_visibleLines
-1;
1660 wxNode
*node
= m_lines
.First();
1661 for (;;) { if (m_current
== (wxListLineData
*)node
->Data()) break; pos
++; node
= node
->Next(); }
1662 steps
= pos
% m_visibleLines
;
1664 wxNode
*node
= m_lines
.Member( m_current
);
1665 for (int i
= 0; i
< steps
; i
++) if (node
->Previous()) node
= node
->Previous();
1666 if (node
) OnArrowChar( (wxListLineData
*)node
->Data(), event
.ShiftDown() );
1672 if (m_mode
& wxLC_REPORT
)
1674 steps
= m_visibleLines
-1;
1678 int pos
= 0; wxNode
*node
= m_lines
.First();
1679 for (;;) { if (m_current
== (wxListLineData
*)node
->Data()) break; pos
++; node
= node
->Next(); }
1680 steps
= m_visibleLines
-(pos
% m_visibleLines
)-1;
1682 wxNode
*node
= m_lines
.Member( m_current
);
1683 for (int i
= 0; i
< steps
; i
++) if (node
->Next()) node
= node
->Next();
1684 if (node
) OnArrowChar( (wxListLineData
*)node
->Data(), event
.ShiftDown() );
1689 if (!(m_mode
& wxLC_REPORT
))
1691 wxNode
*node
= m_lines
.Member( m_current
);
1692 for (int i
= 0; i
<m_visibleLines
; i
++) if (node
->Previous()) node
= node
->Previous();
1693 if (node
) OnArrowChar( (wxListLineData
*)node
->Data(), event
.ShiftDown() );
1699 if (!(m_mode
& wxLC_REPORT
))
1701 wxNode
*node
= m_lines
.Member( m_current
);
1702 for (int i
= 0; i
<m_visibleLines
; i
++) if (node
->Next()) node
= node
->Next();
1703 if (node
) OnArrowChar( (wxListLineData
*)node
->Data(), event
.ShiftDown() );
1709 m_current
->ReverseHilight();
1710 RefreshLine( m_current
);
1715 if (!(m_mode
& wxLC_SINGLE_SEL
))
1717 wxListLineData
*oldCurrent
= m_current
;
1718 m_current
->ReverseHilight();
1719 wxNode
*node
= m_lines
.Member( m_current
)->Next();
1720 if (node
) m_current
= (wxListLineData
*)node
->Data();
1722 RefreshLine( oldCurrent
);
1723 RefreshLine( m_current
);
1724 UnfocusLine( oldCurrent
);
1725 FocusLine( m_current
);
1732 wxListEvent
le( wxEVT_COMMAND_LIST_ITEM_ACTIVATED
, GetParent()->GetId() );
1733 le
.SetEventObject( GetParent() );
1734 le
.m_itemIndex
= GetIndexOfLine( m_current
);
1735 m_current
->GetItem( 0, le
.m_item
);
1736 GetParent()->GetEventHandler()->ProcessEvent( le
);
1749 extern wxWindow
*g_focusWindow
;
1752 void wxListMainWindow::OnSetFocus( wxFocusEvent
&WXUNUSED(event
) )
1755 RefreshLine( m_current
);
1757 if (!GetParent()) return;
1760 g_focusWindow
= GetParent();
1763 wxFocusEvent
event( wxEVT_SET_FOCUS
, GetParent()->GetId() );
1764 event
.SetEventObject( GetParent() );
1765 GetParent()->GetEventHandler()->ProcessEvent( event
);
1768 void wxListMainWindow::OnKillFocus( wxFocusEvent
&WXUNUSED(event
) )
1771 RefreshLine( m_current
);
1774 void wxListMainWindow::OnSize( wxSizeEvent
&WXUNUSED(event
) )
1777 We don't even allow the wxScrolledWindow::AdjustScrollbars() call
1782 void wxListMainWindow::DrawImage( int index
, wxDC
*dc
, int x
, int y
)
1784 if ((m_mode
& wxLC_ICON
) && (m_normal_image_list
))
1786 m_normal_image_list
->Draw( index
, *dc
, x
, y
, wxIMAGELIST_DRAW_TRANSPARENT
);
1789 if ((m_mode
& wxLC_SMALL_ICON
) && (m_small_image_list
))
1791 m_small_image_list
->Draw( index
, *dc
, x
, y
, wxIMAGELIST_DRAW_TRANSPARENT
);
1793 if ((m_mode
& wxLC_LIST
) && (m_small_image_list
))
1795 m_small_image_list
->Draw( index
, *dc
, x
, y
, wxIMAGELIST_DRAW_TRANSPARENT
);
1797 if ((m_mode
& wxLC_REPORT
) && (m_small_image_list
))
1799 m_small_image_list
->Draw( index
, *dc
, x
, y
, wxIMAGELIST_DRAW_TRANSPARENT
);
1804 void wxListMainWindow::GetImageSize( int index
, int &width
, int &height
)
1806 if ((m_mode
& wxLC_ICON
) && (m_normal_image_list
))
1808 m_normal_image_list
->GetSize( index
, width
, height
);
1811 if ((m_mode
& wxLC_SMALL_ICON
) && (m_small_image_list
))
1813 m_small_image_list
->GetSize( index
, width
, height
);
1816 if ((m_mode
& wxLC_LIST
) && (m_small_image_list
))
1818 m_small_image_list
->GetSize( index
, width
, height
);
1821 if ((m_mode
& wxLC_REPORT
) && (m_small_image_list
))
1823 m_small_image_list
->GetSize( index
, width
, height
);
1830 int wxListMainWindow::GetTextLength( wxString
&s
)
1832 wxClientDC
dc( this );
1835 dc
.GetTextExtent( s
, &lw
, &lh
);
1839 int wxListMainWindow::GetIndexOfLine( const wxListLineData
*line
)
1842 wxNode
*node
= m_lines
.First();
1845 if (line
== (wxListLineData
*)node
->Data()) return i
;
1847 node
= node
->Next();
1852 void wxListMainWindow::SetImageList( wxImageList
*imageList
, int which
)
1855 if (which
== wxIMAGE_LIST_NORMAL
) m_normal_image_list
= imageList
;
1856 if (which
== wxIMAGE_LIST_SMALL
) m_small_image_list
= imageList
;
1859 void wxListMainWindow::SetItemSpacing( int spacing
, bool isSmall
)
1864 m_small_spacing
= spacing
;
1868 m_normal_spacing
= spacing
;
1872 int wxListMainWindow::GetItemSpacing( bool isSmall
)
1874 if (isSmall
) return m_small_spacing
; else return m_normal_spacing
;
1877 void wxListMainWindow::SetColumn( int col
, wxListItem
&item
)
1880 wxNode
*node
= m_columns
.Nth( col
);
1883 if (item
.m_width
== wxLIST_AUTOSIZE_USEHEADER
) item
.m_width
= GetTextLength( item
.m_text
)+7;
1884 wxListHeaderData
*column
= (wxListHeaderData
*)node
->Data();
1885 column
->SetItem( item
);
1887 wxListCtrl
*lc
= (wxListCtrl
*) GetParent();
1888 if (lc
->m_headerWin
) lc
->m_headerWin
->Refresh();
1891 void wxListMainWindow::SetColumnWidth( int col
, int width
)
1893 if (!(m_mode
& wxLC_REPORT
)) return;
1897 wxNode
*node
= (wxNode
*) NULL
;
1899 if (width
== wxLIST_AUTOSIZE_USEHEADER
) width
= 80;
1900 if (width
== wxLIST_AUTOSIZE
)
1902 wxClientDC
dc(this);
1903 dc
.SetFont( GetFont() );
1905 node
= m_lines
.First();
1908 wxListLineData
*line
= (wxListLineData
*)node
->Data();
1909 wxNode
*n
= line
->m_items
.Nth( col
);
1912 wxListItemData
*item
= (wxListItemData
*)n
->Data();
1913 int current
= 0, ix
= 0, iy
= 0;
1914 wxCoord lx
= 0, ly
= 0;
1915 if (item
->HasImage())
1917 GetImageSize( item
->GetImage(), ix
, iy
);
1920 if (item
->HasText())
1923 item
->GetText( str
);
1924 dc
.GetTextExtent( str
, &lx
, &ly
);
1927 if (current
> max
) max
= current
;
1929 node
= node
->Next();
1934 node
= m_columns
.Nth( col
);
1937 wxListHeaderData
*column
= (wxListHeaderData
*)node
->Data();
1938 column
->SetWidth( width
);
1941 node
= m_lines
.First();
1944 wxListLineData
*line
= (wxListLineData
*)node
->Data();
1945 wxNode
*n
= line
->m_items
.Nth( col
);
1948 wxListItemData
*item
= (wxListItemData
*)n
->Data();
1949 item
->SetSize( width
, -1 );
1951 node
= node
->Next();
1954 wxListCtrl
*lc
= (wxListCtrl
*) GetParent();
1955 if (lc
->m_headerWin
) lc
->m_headerWin
->Refresh();
1958 void wxListMainWindow::GetColumn( int col
, wxListItem
&item
)
1960 wxNode
*node
= m_columns
.Nth( col
);
1963 wxListHeaderData
*column
= (wxListHeaderData
*)node
->Data();
1964 column
->GetItem( item
);
1976 int wxListMainWindow::GetColumnWidth( int col
)
1978 wxNode
*node
= m_columns
.Nth( col
);
1981 wxListHeaderData
*column
= (wxListHeaderData
*)node
->Data();
1982 return column
->GetWidth();
1990 int wxListMainWindow::GetColumnCount()
1992 return m_columns
.Number();
1995 int wxListMainWindow::GetCountPerPage()
1997 return m_visibleLines
;
2000 void wxListMainWindow::SetItem( wxListItem
&item
)
2003 wxNode
*node
= m_lines
.Nth( item
.m_itemId
);
2006 wxListLineData
*line
= (wxListLineData
*)node
->Data();
2007 if (m_mode
& wxLC_REPORT
) item
.m_width
= GetColumnWidth( item
.m_col
)-3;
2008 line
->SetItem( item
.m_col
, item
);
2012 void wxListMainWindow::SetItemState( long item
, long state
, long stateMask
)
2014 // m_dirty = TRUE; no recalcs needed
2016 wxListLineData
*oldCurrent
= m_current
;
2018 if (stateMask
& wxLIST_STATE_FOCUSED
)
2020 wxNode
*node
= m_lines
.Nth( item
);
2023 wxListLineData
*line
= (wxListLineData
*)node
->Data();
2024 UnfocusLine( m_current
);
2026 FocusLine( m_current
);
2027 RefreshLine( m_current
);
2028 if (oldCurrent
) RefreshLine( oldCurrent
);
2032 if (stateMask
& wxLIST_STATE_SELECTED
)
2034 bool on
= state
& wxLIST_STATE_SELECTED
;
2035 if (!on
&& (m_mode
& wxLC_SINGLE_SEL
)) return;
2037 wxNode
*node
= m_lines
.Nth( item
);
2040 wxListLineData
*line
= (wxListLineData
*)node
->Data();
2041 if (m_mode
& wxLC_SINGLE_SEL
)
2043 UnfocusLine( m_current
);
2045 FocusLine( m_current
);
2046 if (oldCurrent
) oldCurrent
->Hilight( FALSE
);
2047 RefreshLine( m_current
);
2048 if (oldCurrent
) RefreshLine( oldCurrent
);
2050 bool on
= state
& wxLIST_STATE_SELECTED
;
2051 if (on
!= line
->IsHilighted())
2053 line
->Hilight( on
);
2054 RefreshLine( line
);
2060 int wxListMainWindow::GetItemState( long item
, long stateMask
)
2062 int ret
= wxLIST_STATE_DONTCARE
;
2063 if (stateMask
& wxLIST_STATE_FOCUSED
)
2065 wxNode
*node
= m_lines
.Nth( item
);
2068 wxListLineData
*line
= (wxListLineData
*)node
->Data();
2069 if (line
== m_current
) ret
|= wxLIST_STATE_FOCUSED
;
2072 if (stateMask
& wxLIST_STATE_SELECTED
)
2074 wxNode
*node
= m_lines
.Nth( item
);
2077 wxListLineData
*line
= (wxListLineData
*)node
->Data();
2078 if (line
->IsHilighted()) ret
|= wxLIST_STATE_FOCUSED
;
2084 void wxListMainWindow::GetItem( wxListItem
&item
)
2086 wxNode
*node
= m_lines
.Nth( item
.m_itemId
);
2089 wxListLineData
*line
= (wxListLineData
*)node
->Data();
2090 line
->GetItem( item
.m_col
, item
);
2101 int wxListMainWindow::GetItemCount()
2103 return m_lines
.Number();
2106 void wxListMainWindow::GetItemRect( long index
, wxRect
&rect
)
2108 wxNode
*node
= m_lines
.Nth( index
);
2111 wxListLineData
*line
= (wxListLineData
*)node
->Data();
2112 line
->GetRect( rect
);
2123 bool wxListMainWindow::GetItemPosition(long item
, wxPoint
& pos
)
2125 wxNode
*node
= m_lines
.Nth( item
);
2129 wxListLineData
*line
= (wxListLineData
*)node
->Data();
2130 line
->GetRect( rect
);
2142 int wxListMainWindow::GetSelectedItemCount()
2145 wxNode
*node
= m_lines
.First();
2148 wxListLineData
*line
= (wxListLineData
*)node
->Data();
2149 if (line
->IsHilighted()) ret
++;
2150 node
= node
->Next();
2155 void wxListMainWindow::SetMode( long mode
)
2162 if (m_mode
& wxLC_REPORT
)
2164 #if wxUSE_GENERIC_LIST_EXTENSIONS
2178 long wxListMainWindow::GetMode() const
2183 void wxListMainWindow::CalculatePositions()
2185 if (!m_lines
.First()) return;
2187 wxClientDC
dc( this );
2188 dc
.SetFont( GetFont() );
2190 int iconSpacing
= 0;
2191 if (m_mode
& wxLC_ICON
) iconSpacing
= m_normal_spacing
;
2192 if (m_mode
& wxLC_SMALL_ICON
) iconSpacing
= m_small_spacing
;
2194 // we take the first line (which also can be an icon or
2195 // an a text item in wxLC_ICON and wxLC_LIST modes) to
2196 // measure the size of the line
2200 int lineSpacing
= 0;
2202 wxListLineData
*line
= (wxListLineData
*)m_lines
.First()->Data();
2203 line
->CalculateSize( &dc
, iconSpacing
);
2205 line
->GetSize( dummy
, lineSpacing
);
2208 int clientWidth
= 0;
2209 int clientHeight
= 0;
2211 if (m_mode
& wxLC_REPORT
)
2215 int entireHeight
= m_lines
.Number() * lineSpacing
+ 2;
2216 int scroll_pos
= GetScrollPos( wxVERTICAL
);
2217 #if wxUSE_GENERIC_LIST_EXTENSIONS
2218 int x_scroll_pos
= GetScrollPos( wxHORIZONTAL
);
2220 SetScrollbars( m_xScroll
, m_yScroll
, 0, (entireHeight
+15) / m_yScroll
, 0, scroll_pos
, TRUE
);
2222 GetClientSize( &clientWidth
, &clientHeight
);
2224 wxNode
* node
= m_lines
.First();
2225 int entireWidth
= 0 ;
2228 wxListLineData
*line
= (wxListLineData
*)node
->Data();
2229 line
->CalculateSize( &dc
, iconSpacing
);
2230 line
->SetPosition( &dc
, x
, y
, clientWidth
);
2232 for (int i
= 0; i
< GetColumnCount(); i
++)
2234 line
->SetColumnPosition( i
, col_x
);
2235 col_x
+= GetColumnWidth( i
);
2237 entireWidth
= wxMax( entireWidth
, col_x
) ;
2238 #if wxUSE_GENERIC_LIST_EXTENSIONS
2239 line
->SetPosition( &dc
, x
, y
, col_x
);
2241 y
+= lineSpacing
; // one pixel blank line between items
2242 node
= node
->Next();
2244 m_visibleLines
= clientHeight
/ lineSpacing
;
2245 #if wxUSE_GENERIC_LIST_EXTENSIONS
2246 SetScrollbars( m_xScroll
, m_yScroll
, entireWidth
/ m_xScroll
, (entireHeight
+15) / m_yScroll
, x_scroll_pos
, scroll_pos
, TRUE
);
2251 // at first we try without any scrollbar. if the items don't
2252 // fit into the window, we recalculate after subtracting an
2253 // approximated 15 pt for the horizontal scrollbar
2255 GetSize( &clientWidth
, &clientHeight
);
2256 clientHeight
-= 4; // sunken frame
2258 int entireWidth
= 0;
2260 for (int tries
= 0; tries
< 2; tries
++)
2263 int x
= 5; // painting is done at x-2
2264 int y
= 5; // painting is done at y-2
2267 int m_currentVisibleLines
= 0;
2268 wxNode
*node
= m_lines
.First();
2271 m_currentVisibleLines
++;
2272 wxListLineData
*line
= (wxListLineData
*)node
->Data();
2273 line
->CalculateSize( &dc
, iconSpacing
);
2274 line
->SetPosition( &dc
, x
, y
, clientWidth
);
2275 line
->GetSize( lineWidth
, lineHeight
);
2276 if (lineWidth
> maxWidth
) maxWidth
= lineWidth
;
2278 if (m_currentVisibleLines
> m_visibleLines
)
2279 m_visibleLines
= m_currentVisibleLines
;
2280 if (y
+lineSpacing
-6 >= clientHeight
) // -6 for earlier "line breaking"
2282 m_currentVisibleLines
= 0;
2285 entireWidth
+= maxWidth
+6;
2288 node
= node
->Next();
2289 if (!node
) entireWidth
+= maxWidth
;
2290 if ((tries
== 0) && (entireWidth
> clientWidth
))
2292 clientHeight
-= 15; // scrollbar height
2294 m_currentVisibleLines
= 0;
2297 if (!node
) tries
= 1; // everything fits, no second try required
2301 int scroll_pos
= GetScrollPos( wxHORIZONTAL
);
2302 SetScrollbars( m_xScroll
, m_yScroll
, (entireWidth
+15) / m_xScroll
, 0, scroll_pos
, 0, TRUE
);
2306 void wxListMainWindow::RealizeChanges( void )
2310 wxNode
*node
= m_lines
.First();
2311 if (node
) m_current
= (wxListLineData
*)node
->Data();
2315 FocusLine( m_current
);
2316 if (m_mode
& wxLC_SINGLE_SEL
) m_current
->Hilight( TRUE
);
2320 long wxListMainWindow::GetNextItem( long item
, int WXUNUSED(geometry
), int state
)
2323 if (item
> 0) ret
= item
;
2324 if(ret
>= GetItemCount()) return -1;
2325 wxNode
*node
= m_lines
.Nth( ret
);
2328 wxListLineData
*line
= (wxListLineData
*)node
->Data();
2329 if ((state
& wxLIST_STATE_FOCUSED
) && (line
== m_current
)) return ret
;
2330 if ((state
& wxLIST_STATE_SELECTED
) && (line
->IsHilighted())) return ret
;
2331 if (!state
) return ret
;
2333 node
= node
->Next();
2338 void wxListMainWindow::DeleteItem( long index
)
2341 wxNode
*node
= m_lines
.Nth( index
);
2344 wxListLineData
*line
= (wxListLineData
*)node
->Data();
2345 if (m_current
== line
) m_current
= (wxListLineData
*) NULL
;
2347 m_lines
.DeleteNode( node
);
2351 void wxListMainWindow::DeleteColumn( int col
)
2353 wxCHECK_RET( col
< (int)m_columns
.GetCount(),
2354 wxT("attempting to delete inexistent column in wxListView") );
2357 wxNode
*node
= m_columns
.Nth( col
);
2358 if (node
) m_columns
.DeleteNode( node
);
2361 void wxListMainWindow::DeleteAllItems( void )
2364 m_current
= (wxListLineData
*) NULL
;
2366 // to make the deletion of all items faster, we don't send the
2367 // notifications in this case: this is compatible with wxMSW and
2368 // documented in DeleteAllItems() description
2370 wxNode
*node
= m_lines
.First();
2373 wxListLineData
*line
= (wxListLineData
*)node
->Data();
2377 node
= node
->Next();
2384 void wxListMainWindow::DeleteEverything( void )
2387 m_current
= (wxListLineData
*) NULL
;
2388 wxNode
*node
= m_lines
.First();
2391 wxListLineData
*line
= (wxListLineData
*)node
->Data();
2393 node
= node
->Next();
2396 m_current
= (wxListLineData
*) NULL
;
2400 void wxListMainWindow::EnsureVisible( long index
)
2402 // We have to call this here because the label in
2403 // question might just have been added and no screen
2404 // update taken place.
2405 if (m_dirty
) wxYield();
2407 wxListLineData
*oldCurrent
= m_current
;
2408 m_current
= (wxListLineData
*) NULL
;
2410 wxNode
*node
= m_lines
.Nth( i
);
2411 if (node
) m_current
= (wxListLineData
*)node
->Data();
2412 if (m_current
) MoveToFocus();
2413 m_current
= oldCurrent
;
2416 long wxListMainWindow::FindItem(long start
, const wxString
& str
, bool WXUNUSED(partial
) )
2420 if (pos
< 0) pos
= 0;
2421 wxNode
*node
= m_lines
.Nth( pos
);
2424 wxListLineData
*line
= (wxListLineData
*)node
->Data();
2426 line
->GetText( 0, s
);
2427 if (s
== tmp
) return pos
;
2428 node
= node
->Next();
2434 long wxListMainWindow::FindItem(long start
, long data
)
2437 if (pos
< 0) pos
= 0;
2438 wxNode
*node
= m_lines
.Nth( pos
);
2441 wxListLineData
*line
= (wxListLineData
*)node
->Data();
2443 line
->GetItem( 0, item
);
2444 if (item
.m_data
== data
) return pos
;
2445 node
= node
->Next();
2451 long wxListMainWindow::HitTest( int x
, int y
, int &flags
)
2453 wxNode
*node
= m_lines
.First();
2457 wxListLineData
*line
= (wxListLineData
*)node
->Data();
2458 long ret
= line
->IsHit( x
, y
);
2464 node
= node
->Next();
2470 void wxListMainWindow::InsertItem( wxListItem
&item
)
2474 if (m_mode
& wxLC_REPORT
) mode
= wxLC_REPORT
;
2475 else if (m_mode
& wxLC_LIST
) mode
= wxLC_LIST
;
2476 else if (m_mode
& wxLC_ICON
) mode
= wxLC_ICON
;
2477 else if (m_mode
& wxLC_SMALL_ICON
) mode
= wxLC_ICON
; // no typo
2479 wxListLineData
*line
= new wxListLineData( this, mode
, m_hilightBrush
);
2481 if (m_mode
& wxLC_REPORT
)
2483 line
->InitItems( GetColumnCount() );
2484 item
.m_width
= GetColumnWidth( 0 )-3;
2488 line
->InitItems( 1 );
2491 line
->SetItem( 0, item
);
2492 if ((item
.m_itemId
>= 0) && (item
.m_itemId
< (int)m_lines
.GetCount()))
2494 wxNode
*node
= m_lines
.Nth( item
.m_itemId
);
2495 if (node
) m_lines
.Insert( node
, line
);
2499 m_lines
.Append( line
);
2503 void wxListMainWindow::InsertColumn( long col
, wxListItem
&item
)
2506 if (m_mode
& wxLC_REPORT
)
2508 if (item
.m_width
== wxLIST_AUTOSIZE_USEHEADER
) item
.m_width
= GetTextLength( item
.m_text
);
2509 wxListHeaderData
*column
= new wxListHeaderData( item
);
2510 if ((col
>= 0) && (col
< (int)m_columns
.GetCount()))
2512 wxNode
*node
= m_columns
.Nth( col
);
2514 m_columns
.Insert( node
, column
);
2518 m_columns
.Append( column
);
2523 wxListCtrlCompare list_ctrl_compare_func_2
;
2524 long list_ctrl_compare_data
;
2526 int LINKAGEMODE
list_ctrl_compare_func_1( const void *arg1
, const void *arg2
)
2528 wxListLineData
*line1
= *((wxListLineData
**)arg1
);
2529 wxListLineData
*line2
= *((wxListLineData
**)arg2
);
2531 line1
->GetItem( 0, item
);
2532 long data1
= item
.m_data
;
2533 line2
->GetItem( 0, item
);
2534 long data2
= item
.m_data
;
2535 return list_ctrl_compare_func_2( data1
, data2
, list_ctrl_compare_data
);
2538 void wxListMainWindow::SortItems( wxListCtrlCompare fn
, long data
)
2540 list_ctrl_compare_func_2
= fn
;
2541 list_ctrl_compare_data
= data
;
2542 m_lines
.Sort( list_ctrl_compare_func_1
);
2545 void wxListMainWindow::OnScroll(wxScrollWinEvent
& event
)
2547 wxScrolledWindow::OnScroll( event
) ;
2548 #if wxUSE_GENERIC_LIST_EXTENSIONS
2550 if (event
.GetOrientation() == wxHORIZONTAL
&& ( m_mode
& wxLC_REPORT
))
2552 wxListCtrl
* lc
= wxDynamicCast( GetParent() , wxListCtrl
) ;
2555 lc
->m_headerWin
->Refresh() ;
2557 lc
->m_headerWin
->MacUpdateImmediately() ;
2564 // -------------------------------------------------------------------------------------
2566 // -------------------------------------------------------------------------------------
2568 IMPLEMENT_DYNAMIC_CLASS(wxListItem
, wxObject
)
2570 wxListItem::wxListItem()
2579 m_format
= wxLIST_FORMAT_CENTRE
;
2585 void wxListItem::Clear()
2594 m_format
= wxLIST_FORMAT_CENTRE
;
2596 m_text
= wxEmptyString
;
2598 if (m_attr
) delete m_attr
;
2602 void wxListItem::ClearAttributes()
2604 if (m_attr
) delete m_attr
;
2608 // -------------------------------------------------------------------------------------
2610 // -------------------------------------------------------------------------------------
2612 IMPLEMENT_DYNAMIC_CLASS(wxListEvent
, wxNotifyEvent
)
2614 wxListEvent::wxListEvent( wxEventType commandType
, int id
):
2615 wxNotifyEvent( commandType
, id
)
2621 m_cancelled
= FALSE
;
2626 void wxListEvent::CopyObject(wxObject
& object_dest
) const
2628 wxListEvent
*obj
= (wxListEvent
*)&object_dest
;
2630 wxNotifyEvent::CopyObject(object_dest
);
2632 obj
->m_code
= m_code
;
2633 obj
->m_itemIndex
= m_itemIndex
;
2634 obj
->m_oldItemIndex
= m_oldItemIndex
;
2636 obj
->m_cancelled
= m_cancelled
;
2637 obj
->m_pointDrag
= m_pointDrag
;
2638 obj
->m_item
.m_mask
= m_item
.m_mask
;
2639 obj
->m_item
.m_itemId
= m_item
.m_itemId
;
2640 obj
->m_item
.m_col
= m_item
.m_col
;
2641 obj
->m_item
.m_state
= m_item
.m_state
;
2642 obj
->m_item
.m_stateMask
= m_item
.m_stateMask
;
2643 obj
->m_item
.m_text
= m_item
.m_text
;
2644 obj
->m_item
.m_image
= m_item
.m_image
;
2645 obj
->m_item
.m_data
= m_item
.m_data
;
2646 obj
->m_item
.m_format
= m_item
.m_format
;
2647 obj
->m_item
.m_width
= m_item
.m_width
;
2649 if ( m_item
.HasAttributes() )
2651 obj
->m_item
.SetTextColour(m_item
.GetTextColour());
2655 // -------------------------------------------------------------------------------------
2657 // -------------------------------------------------------------------------------------
2659 IMPLEMENT_DYNAMIC_CLASS(wxListCtrl
, wxControl
)
2661 BEGIN_EVENT_TABLE(wxListCtrl
,wxControl
)
2662 EVT_SIZE (wxListCtrl::OnSize
)
2663 EVT_IDLE (wxListCtrl::OnIdle
)
2666 wxListCtrl::wxListCtrl()
2668 m_imageListNormal
= (wxImageList
*) NULL
;
2669 m_imageListSmall
= (wxImageList
*) NULL
;
2670 m_imageListState
= (wxImageList
*) NULL
;
2671 m_mainWin
= (wxListMainWindow
*) NULL
;
2672 m_headerWin
= (wxListHeaderWindow
*) NULL
;
2675 wxListCtrl::~wxListCtrl()
2679 bool wxListCtrl::Create( wxWindow
*parent
, wxWindowID id
,
2680 const wxPoint
&pos
, const wxSize
&size
,
2682 #if wxUSE_VALIDATORS
2683 const wxValidator
&validator
,
2685 const wxString
&name
)
2687 m_imageListNormal
= (wxImageList
*) NULL
;
2688 m_imageListSmall
= (wxImageList
*) NULL
;
2689 m_imageListState
= (wxImageList
*) NULL
;
2690 m_mainWin
= (wxListMainWindow
*) NULL
;
2691 m_headerWin
= (wxListHeaderWindow
*) NULL
;
2696 #pragma message disable codcauunr
2697 // VMS reports on this part the warning:
2698 // statement either is unreachable or causes unreachable code
2700 if ((s
& wxLC_REPORT
== 0) &&
2701 (s
& wxLC_LIST
== 0) &&
2702 (s
& wxLC_ICON
== 0))
2707 #pragma message enable codcauunr
2710 bool ret
= wxControl::Create( parent
,
2715 #if wxUSE_VALIDATORS
2720 #if wxUSE_VALIDATORS
2721 SetValidator( validator
);
2724 if (s
& wxSUNKEN_BORDER
) s
-= wxSUNKEN_BORDER
;
2726 m_mainWin
= new wxListMainWindow( this, -1, wxPoint(0,0), size
, s
);
2728 if (HasFlag(wxLC_REPORT
))
2729 m_headerWin
= new wxListHeaderWindow( this, -1, m_mainWin
, wxPoint(0,0), wxSize(size
.x
,23), wxTAB_TRAVERSAL
);
2731 m_headerWin
= (wxListHeaderWindow
*) NULL
;
2733 SetBackgroundColour( *wxWHITE
);
2738 void wxListCtrl::OnSize( wxSizeEvent
&WXUNUSED(event
) )
2740 /* handled in OnIdle */
2742 if (m_mainWin
) m_mainWin
->m_dirty
= TRUE
;
2745 void wxListCtrl::SetSingleStyle( long style
, bool add
)
2747 long flag
= GetWindowStyle();
2751 if (style
& wxLC_MASK_TYPE
) flag
= flag
& ~wxLC_MASK_TYPE
;
2752 if (style
& wxLC_MASK_ALIGN
) flag
= flag
& ~wxLC_MASK_ALIGN
;
2753 if (style
& wxLC_MASK_SORT
) flag
= flag
& ~wxLC_MASK_SORT
;
2762 if (flag
& style
) flag
-= style
;
2765 SetWindowStyleFlag( flag
);
2768 void wxListCtrl::SetWindowStyleFlag( long flag
)
2772 m_mainWin
->DeleteEverything();
2776 GetClientSize( &width
, &height
);
2778 m_mainWin
->SetMode( flag
);
2780 if (flag
& wxLC_REPORT
)
2782 if (!HasFlag(wxLC_REPORT
))
2786 m_headerWin
= new wxListHeaderWindow( this, -1, m_mainWin
,
2787 wxPoint(0,0), wxSize(width
,23), wxTAB_TRAVERSAL
);
2788 if (HasFlag(wxLC_NO_HEADER
))
2789 m_headerWin
->Show( FALSE
);
2793 if (flag
& wxLC_NO_HEADER
)
2794 m_headerWin
->Show( FALSE
);
2796 m_headerWin
->Show( TRUE
);
2802 if (HasFlag(wxLC_REPORT
) && !(HasFlag(wxLC_NO_HEADER
)))
2804 m_headerWin
->Show( FALSE
);
2809 wxWindow::SetWindowStyleFlag( flag
);
2812 bool wxListCtrl::GetColumn(int col
, wxListItem
&item
) const
2814 m_mainWin
->GetColumn( col
, item
);
2818 bool wxListCtrl::SetColumn( int col
, wxListItem
& item
)
2820 m_mainWin
->SetColumn( col
, item
);
2824 int wxListCtrl::GetColumnWidth( int col
) const
2826 return m_mainWin
->GetColumnWidth( col
);
2829 bool wxListCtrl::SetColumnWidth( int col
, int width
)
2831 m_mainWin
->SetColumnWidth( col
, width
);
2835 int wxListCtrl::GetCountPerPage() const
2837 return m_mainWin
->GetCountPerPage(); // different from Windows ?
2840 bool wxListCtrl::GetItem( wxListItem
&info
) const
2842 m_mainWin
->GetItem( info
);
2846 bool wxListCtrl::SetItem( wxListItem
&info
)
2848 m_mainWin
->SetItem( info
);
2852 long wxListCtrl::SetItem( long index
, int col
, const wxString
& label
, int imageId
)
2855 info
.m_text
= label
;
2856 info
.m_mask
= wxLIST_MASK_TEXT
;
2857 info
.m_itemId
= index
;
2861 info
.m_image
= imageId
;
2862 info
.m_mask
|= wxLIST_MASK_IMAGE
;
2864 m_mainWin
->SetItem(info
);
2868 int wxListCtrl::GetItemState( long item
, long stateMask
) const
2870 return m_mainWin
->GetItemState( item
, stateMask
);
2873 bool wxListCtrl::SetItemState( long item
, long state
, long stateMask
)
2875 m_mainWin
->SetItemState( item
, state
, stateMask
);
2879 bool wxListCtrl::SetItemImage( long item
, int image
, int WXUNUSED(selImage
) )
2882 info
.m_image
= image
;
2883 info
.m_mask
= wxLIST_MASK_IMAGE
;
2884 info
.m_itemId
= item
;
2885 m_mainWin
->SetItem( info
);
2889 wxString
wxListCtrl::GetItemText( long item
) const
2892 info
.m_itemId
= item
;
2893 m_mainWin
->GetItem( info
);
2897 void wxListCtrl::SetItemText( long item
, const wxString
&str
)
2900 info
.m_mask
= wxLIST_MASK_TEXT
;
2901 info
.m_itemId
= item
;
2903 m_mainWin
->SetItem( info
);
2906 long wxListCtrl::GetItemData( long item
) const
2909 info
.m_itemId
= item
;
2910 m_mainWin
->GetItem( info
);
2914 bool wxListCtrl::SetItemData( long item
, long data
)
2917 info
.m_mask
= wxLIST_MASK_DATA
;
2918 info
.m_itemId
= item
;
2920 m_mainWin
->SetItem( info
);
2924 bool wxListCtrl::GetItemRect( long item
, wxRect
&rect
, int WXUNUSED(code
) ) const
2926 m_mainWin
->GetItemRect( item
, rect
);
2930 bool wxListCtrl::GetItemPosition( long item
, wxPoint
& pos
) const
2932 m_mainWin
->GetItemPosition( item
, pos
);
2936 bool wxListCtrl::SetItemPosition( long WXUNUSED(item
), const wxPoint
& WXUNUSED(pos
) )
2941 int wxListCtrl::GetItemCount() const
2943 return m_mainWin
->GetItemCount();
2946 int wxListCtrl::GetColumnCount() const
2948 return m_mainWin
->GetColumnCount();
2951 void wxListCtrl::SetItemSpacing( int spacing
, bool isSmall
)
2953 m_mainWin
->SetItemSpacing( spacing
, isSmall
);
2956 int wxListCtrl::GetItemSpacing( bool isSmall
) const
2958 return m_mainWin
->GetItemSpacing( isSmall
);
2961 int wxListCtrl::GetSelectedItemCount() const
2963 return m_mainWin
->GetSelectedItemCount();
2966 wxColour
wxListCtrl::GetTextColour() const
2968 return GetForegroundColour();
2971 void wxListCtrl::SetTextColour(const wxColour
& col
)
2973 SetForegroundColour(col
);
2976 long wxListCtrl::GetTopItem() const
2981 long wxListCtrl::GetNextItem( long item
, int geom
, int state
) const
2983 return m_mainWin
->GetNextItem( item
, geom
, state
);
2986 wxImageList
*wxListCtrl::GetImageList(int which
) const
2988 if (which
== wxIMAGE_LIST_NORMAL
)
2990 return m_imageListNormal
;
2992 else if (which
== wxIMAGE_LIST_SMALL
)
2994 return m_imageListSmall
;
2996 else if (which
== wxIMAGE_LIST_STATE
)
2998 return m_imageListState
;
3000 return (wxImageList
*) NULL
;
3003 void wxListCtrl::SetImageList( wxImageList
*imageList
, int which
)
3005 m_mainWin
->SetImageList( imageList
, which
);
3008 bool wxListCtrl::Arrange( int WXUNUSED(flag
) )
3013 bool wxListCtrl::DeleteItem( long item
)
3015 m_mainWin
->DeleteItem( item
);
3019 bool wxListCtrl::DeleteAllItems()
3021 m_mainWin
->DeleteAllItems();
3025 bool wxListCtrl::DeleteAllColumns()
3027 for ( size_t n
= 0; n
< m_mainWin
->m_columns
.GetCount(); n
++ )
3033 void wxListCtrl::ClearAll()
3035 m_mainWin
->DeleteEverything();
3038 bool wxListCtrl::DeleteColumn( int col
)
3040 m_mainWin
->DeleteColumn( col
);
3044 void wxListCtrl::Edit( long item
)
3046 m_mainWin
->Edit( item
);
3049 bool wxListCtrl::EnsureVisible( long item
)
3051 m_mainWin
->EnsureVisible( item
);
3055 long wxListCtrl::FindItem( long start
, const wxString
& str
, bool partial
)
3057 return m_mainWin
->FindItem( start
, str
, partial
);
3060 long wxListCtrl::FindItem( long start
, long data
)
3062 return m_mainWin
->FindItem( start
, data
);
3065 long wxListCtrl::FindItem( long WXUNUSED(start
), const wxPoint
& WXUNUSED(pt
),
3066 int WXUNUSED(direction
))
3071 long wxListCtrl::HitTest( const wxPoint
&point
, int &flags
)
3073 return m_mainWin
->HitTest( (int)point
.x
, (int)point
.y
, flags
);
3076 long wxListCtrl::InsertItem( wxListItem
& info
)
3078 m_mainWin
->InsertItem( info
);
3079 return info
.m_itemId
;
3082 long wxListCtrl::InsertItem( long index
, const wxString
&label
)
3085 info
.m_text
= label
;
3086 info
.m_mask
= wxLIST_MASK_TEXT
;
3087 info
.m_itemId
= index
;
3088 return InsertItem( info
);
3091 long wxListCtrl::InsertItem( long index
, int imageIndex
)
3094 info
.m_mask
= wxLIST_MASK_IMAGE
;
3095 info
.m_image
= imageIndex
;
3096 info
.m_itemId
= index
;
3097 return InsertItem( info
);
3100 long wxListCtrl::InsertItem( long index
, const wxString
&label
, int imageIndex
)
3103 info
.m_text
= label
;
3104 info
.m_image
= imageIndex
;
3105 info
.m_mask
= wxLIST_MASK_TEXT
| wxLIST_MASK_IMAGE
;
3106 info
.m_itemId
= index
;
3107 return InsertItem( info
);
3110 long wxListCtrl::InsertColumn( long col
, wxListItem
&item
)
3112 wxASSERT( m_headerWin
);
3113 m_mainWin
->InsertColumn( col
, item
);
3114 m_headerWin
->Refresh();
3119 long wxListCtrl::InsertColumn( long col
, const wxString
&heading
,
3120 int format
, int width
)
3123 item
.m_mask
= wxLIST_MASK_TEXT
| wxLIST_MASK_FORMAT
;
3124 item
.m_text
= heading
;
3127 item
.m_mask
|= wxLIST_MASK_WIDTH
;
3128 item
.m_width
= width
;
3130 item
.m_format
= format
;
3132 return InsertColumn( col
, item
);
3135 bool wxListCtrl::ScrollList( int WXUNUSED(dx
), int WXUNUSED(dy
) )
3141 // fn is a function which takes 3 long arguments: item1, item2, data.
3142 // item1 is the long data associated with a first item (NOT the index).
3143 // item2 is the long data associated with a second item (NOT the index).
3144 // data is the same value as passed to SortItems.
3145 // The return value is a negative number if the first item should precede the second
3146 // item, a positive number of the second item should precede the first,
3147 // or zero if the two items are equivalent.
3148 // data is arbitrary data to be passed to the sort function.
3150 bool wxListCtrl::SortItems( wxListCtrlCompare fn
, long data
)
3152 m_mainWin
->SortItems( fn
, data
);
3156 void wxListCtrl::OnIdle( wxIdleEvent
&WXUNUSED(event
) )
3158 if (!m_mainWin
->m_dirty
) return;
3162 GetClientSize( &cw
, &ch
);
3169 if (HasFlag(wxLC_REPORT
) && !HasFlag(wxLC_NO_HEADER
))
3171 m_headerWin
->GetPosition( &x
, &y
);
3172 m_headerWin
->GetSize( &w
, &h
);
3173 if ((x
!= 0) || (y
!= 0) || (w
!= cw
) || (h
!= 23))
3174 m_headerWin
->SetSize( 0, 0, cw
, 23 );
3176 m_mainWin
->GetPosition( &x
, &y
);
3177 m_mainWin
->GetSize( &w
, &h
);
3178 if ((x
!= 0) || (y
!= 24) || (w
!= cw
) || (h
!= ch
-24))
3179 m_mainWin
->SetSize( 0, 24, cw
, ch
-24 );
3183 m_mainWin
->GetPosition( &x
, &y
);
3184 m_mainWin
->GetSize( &w
, &h
);
3185 if ((x
!= 0) || (y
!= 24) || (w
!= cw
) || (h
!= ch
))
3186 m_mainWin
->SetSize( 0, 0, cw
, ch
);
3189 m_mainWin
->CalculatePositions();
3190 m_mainWin
->RealizeChanges();
3191 m_mainWin
->m_dirty
= FALSE
;
3192 m_mainWin
->Refresh();
3195 bool wxListCtrl::SetBackgroundColour( const wxColour
&colour
)
3197 if ( !wxWindow::SetBackgroundColour( colour
) )
3202 m_mainWin
->SetBackgroundColour( colour
);
3203 m_mainWin
->m_dirty
= TRUE
;
3208 // m_headerWin->SetBackgroundColour( colour );
3214 bool wxListCtrl::SetForegroundColour( const wxColour
&colour
)
3216 if ( !wxWindow::SetForegroundColour( colour
) )
3221 m_mainWin
->SetForegroundColour( colour
);
3222 m_mainWin
->m_dirty
= TRUE
;
3227 m_headerWin
->SetForegroundColour( colour
);
3233 bool wxListCtrl::SetFont( const wxFont
&font
)
3235 if ( !wxWindow::SetFont( font
) )
3240 m_mainWin
->SetFont( font
);
3241 m_mainWin
->m_dirty
= TRUE
;
3246 m_headerWin
->SetFont( font
);