1 /////////////////////////////////////////////////////////////////////////////
4 // Author: Robert Roebling
6 // Copyright: (c) 1998 Robert Roebling
7 // Licence: wxWindows licence
8 /////////////////////////////////////////////////////////////////////////////
11 #pragma implementation "listctrl.h"
12 #pragma implementation "listctrlbase.h"
15 // For compilers that support precompilation, includes "wx.h".
16 #include "wx/wxprec.h"
22 #include "wx/dcscreen.h"
24 #include "wx/listctrl.h"
25 #include "wx/generic/imaglist.h"
27 #ifndef wxUSE_GENERIC_LIST_EXTENSIONS
28 #define wxUSE_GENERIC_LIST_EXTENSIONS 0
31 //-----------------------------------------------------------------------------
33 //-----------------------------------------------------------------------------
35 IMPLEMENT_DYNAMIC_CLASS(wxListItemData
,wxObject
);
37 wxListItemData::wxListItemData()
48 wxListItemData::wxListItemData( const wxListItem
&info
)
57 void wxListItemData::SetItem( const wxListItem
&info
)
59 if (info
.m_mask
& wxLIST_MASK_TEXT
) m_text
= info
.m_text
;
60 if (info
.m_mask
& wxLIST_MASK_IMAGE
) m_image
= info
.m_image
;
61 if (info
.m_mask
& wxLIST_MASK_DATA
) m_data
= info
.m_data
;
63 if ( info
.HasAttributes() )
66 *m_attr
= *info
.GetAttributes();
68 m_attr
= new wxListItemAttr(*info
.GetAttributes());
73 m_width
= info
.m_width
;
77 void wxListItemData::SetText( const wxString
&s
)
82 void wxListItemData::SetImage( int image
)
87 void wxListItemData::SetData( long data
)
92 void wxListItemData::SetPosition( int x
, int y
)
98 void wxListItemData::SetSize( int width
, int height
)
100 if (width
!= -1) m_width
= width
;
101 if (height
!= -1) m_height
= height
;
104 bool wxListItemData::HasImage() const
106 return (m_image
>= 0);
109 bool wxListItemData::HasText() const
111 return (!m_text
.IsNull());
114 bool wxListItemData::IsHit( int x
, int y
) const
116 return ((x
>= m_xpos
) && (x
<= m_xpos
+m_width
) && (y
>= m_ypos
) && (y
<= m_ypos
+m_height
));
119 void wxListItemData::GetText( wxString
&s
)
124 int wxListItemData::GetX() const
129 int wxListItemData::GetY() const
134 int wxListItemData::GetWidth() const
139 int wxListItemData::GetHeight() const
144 int wxListItemData::GetImage() const
149 void wxListItemData::GetItem( wxListItem
&info
) const
151 info
.m_text
= m_text
;
152 info
.m_image
= m_image
;
153 info
.m_data
= m_data
;
157 if ( m_attr
->HasTextColour() )
158 info
.SetTextColour(m_attr
->GetTextColour());
159 if ( m_attr
->HasBackgroundColour() )
160 info
.SetBackgroundColour(m_attr
->GetBackgroundColour());
161 if ( m_attr
->HasFont() )
162 info
.SetFont(m_attr
->GetFont());
166 //-----------------------------------------------------------------------------
168 //-----------------------------------------------------------------------------
170 IMPLEMENT_DYNAMIC_CLASS(wxListHeaderData
,wxObject
);
172 wxListHeaderData::wxListHeaderData()
183 wxListHeaderData::wxListHeaderData( const wxListItem
&item
)
191 void wxListHeaderData::SetItem( const wxListItem
&item
)
193 m_mask
= item
.m_mask
;
194 m_text
= item
.m_text
;
195 m_image
= item
.m_image
;
196 m_format
= item
.m_format
;
197 m_width
= item
.m_width
;
198 if (m_width
< 0) m_width
= 80;
199 if (m_width
< 6) m_width
= 6;
202 void wxListHeaderData::SetPosition( int x
, int y
)
208 void wxListHeaderData::SetHeight( int h
)
213 void wxListHeaderData::SetWidth( int w
)
216 if (m_width
< 0) m_width
= 80;
217 if (m_width
< 6) m_width
= 6;
220 void wxListHeaderData::SetFormat( int format
)
225 bool wxListHeaderData::HasImage() const
227 return (m_image
!= 0);
230 bool wxListHeaderData::HasText() const
232 return (m_text
.Length() > 0);
235 bool wxListHeaderData::IsHit( int x
, int y
) const
237 return ((x
>= m_xpos
) && (x
<= m_xpos
+m_width
) && (y
>= m_ypos
) && (y
<= m_ypos
+m_height
));
240 void wxListHeaderData::GetItem( wxListItem
&item
)
242 item
.m_mask
= m_mask
;
243 item
.m_text
= m_text
;
244 item
.m_image
= m_image
;
245 item
.m_format
= m_format
;
246 item
.m_width
= m_width
;
249 void wxListHeaderData::GetText( wxString
&s
)
254 int wxListHeaderData::GetImage() const
259 int wxListHeaderData::GetWidth() const
264 int wxListHeaderData::GetFormat() const
269 //-----------------------------------------------------------------------------
271 //-----------------------------------------------------------------------------
273 IMPLEMENT_DYNAMIC_CLASS(wxListLineData
,wxObject
);
275 wxListLineData::wxListLineData( wxListMainWindow
*owner
, int mode
, wxBrush
*hilightBrush
)
280 m_hilightBrush
= hilightBrush
;
281 m_items
.DeleteContents( TRUE
);
285 void wxListLineData::CalculateSize( wxDC
*dc
, int spacing
)
292 m_bound_all
.width
= m_spacing
;
293 m_bound_all
.height
= m_spacing
+13;
294 wxNode
*node
= m_items
.First();
297 wxListItemData
*item
= (wxListItemData
*)node
->Data();
298 wxString s
= item
->GetText();
300 dc
->GetTextExtent( s
, &lw
, &lh
);
301 if (lw
> m_spacing
) m_bound_all
.width
= lw
;
307 wxNode
*node
= m_items
.First();
310 wxListItemData
*item
= (wxListItemData
*)node
->Data();
311 wxString s
= item
->GetText();
313 dc
->GetTextExtent( s
, &lw
, &lh
);
314 m_bound_all
.width
= lw
;
315 m_bound_all
.height
= lh
;
316 if (item
->HasImage())
325 m_owner
->GetImageSize( item
->GetImage(), w
, h
);
326 m_bound_all
.width
+= 4 + w
;
327 if (h
> m_bound_all
.height
) m_bound_all
.height
= h
;
334 m_bound_all
.width
= 0;
335 m_bound_all
.height
= 0;
336 wxNode
*node
= m_items
.First();
339 wxListItemData
*item
= (wxListItemData
*)node
->Data();
342 if (s
.IsNull()) s
= "H";
344 dc
->GetTextExtent( s
, &lw
, &lh
);
345 item
->SetSize( item
->GetWidth(), lh
);
346 m_bound_all
.width
+= lw
;
347 m_bound_all
.height
= lh
;
355 void wxListLineData::SetPosition( wxDC
*dc
, int x
, int y
, int window_width
)
363 AssignRect( m_bound_icon
, 0, 0, 0, 0 );
364 AssignRect( m_bound_label
, 0, 0, 0, 0 );
365 AssignRect( m_bound_hilight
, m_bound_all
);
366 wxNode
*node
= m_items
.First();
369 wxListItemData
*item
= (wxListItemData
*)node
->Data();
370 if (item
->HasImage())
372 wxListItemData
*item
= (wxListItemData
*)node
->Data();
375 m_owner
->GetImageSize( item
->GetImage(), w
, h
);
376 m_bound_icon
.x
= m_bound_all
.x
+ (m_spacing
/2) - (w
/2);
377 m_bound_icon
.y
= m_bound_all
.y
+ m_spacing
- h
- 5;
378 m_bound_icon
.width
= w
;
379 m_bound_icon
.height
= h
;
380 if (!item
->HasText())
382 AssignRect( m_bound_hilight
, m_bound_icon
);
383 m_bound_hilight
.x
-= 5;
384 m_bound_hilight
.y
-= 5;
385 m_bound_hilight
.width
+= 9;
386 m_bound_hilight
.height
+= 9;
394 dc
->GetTextExtent( s
, &lw
, &lh
);
395 if (m_bound_all
.width
> m_spacing
)
396 m_bound_label
.x
= m_bound_all
.x
;
398 m_bound_label
.x
= m_bound_all
.x
+ (m_spacing
/2) - lw
/2;
399 m_bound_label
.y
= m_bound_all
.y
+ m_bound_all
.height
- lh
;
400 m_bound_label
.width
= lw
;
401 m_bound_label
.height
= lh
;
402 AssignRect( m_bound_hilight
, m_bound_label
);
403 m_bound_hilight
.x
-= 2;
404 m_bound_hilight
.y
-= 2;
405 m_bound_hilight
.width
+= 4;
406 m_bound_hilight
.height
+= 4;
413 AssignRect( m_bound_label
, m_bound_all
);
416 m_bound_all
.width
+= 4;
417 m_bound_all
.height
+= 3;
418 AssignRect( m_bound_hilight
, m_bound_all
);
419 AssignRect( m_bound_icon
, 0, 0, 0, 0 );
420 wxNode
*node
= m_items
.First();
423 wxListItemData
*item
= (wxListItemData
*)node
->Data();
424 if (item
->HasImage())
426 m_bound_icon
.x
= m_bound_all
.x
+ 2;
427 m_bound_icon
.y
= m_bound_all
.y
+ 2;
430 m_owner
->GetImageSize( item
->GetImage(), w
, h
);
431 m_bound_icon
.width
= w
;
432 m_bound_icon
.height
= h
;
433 m_bound_label
.x
+= 4 + w
;
434 m_bound_label
.width
-= 4 + w
;
442 dc
->GetTextExtent( "H", &lw
, &lh
);
445 m_bound_all
.height
= lh
+3;
446 m_bound_all
.width
= window_width
;
447 AssignRect( m_bound_hilight
, m_bound_all
);
448 AssignRect( m_bound_label
, m_bound_all
);
449 AssignRect( m_bound_icon
, 0, 0, 0, 0 );
450 wxNode
*node
= m_items
.First();
453 wxListItemData
*item
= (wxListItemData
*)node
->Data();
456 if (s
.IsEmpty()) s
= wxT("H");
458 dc
->GetTextExtent( s
, &lw
, &lh
);
459 m_bound_label
.width
= lw
;
460 m_bound_label
.height
= lh
;
461 if (item
->HasImage())
463 m_bound_icon
.x
= m_bound_all
.x
+ 2;
464 m_bound_icon
.y
= m_bound_all
.y
+ 2;
467 m_owner
->GetImageSize( item
->GetImage(), w
, h
);
468 m_bound_icon
.width
= w
;
469 m_bound_icon
.height
= h
;
470 m_bound_label
.x
+= 4 + w
;
478 void wxListLineData::SetColumnPosition( int index
, int x
)
480 wxNode
*node
= m_items
.Nth( (size_t)index
);
483 wxListItemData
*item
= (wxListItemData
*)node
->Data();
484 item
->SetPosition( x
, m_bound_all
.y
+1 );
488 void wxListLineData::GetSize( int &width
, int &height
)
490 width
= m_bound_all
.width
;
491 height
= m_bound_all
.height
;
494 void wxListLineData::GetExtent( int &x
, int &y
, int &width
, int &height
)
498 width
= m_bound_all
.width
;
499 height
= m_bound_all
.height
;
502 void wxListLineData::GetLabelExtent( int &x
, int &y
, int &width
, int &height
)
506 width
= m_bound_label
.width
;
507 height
= m_bound_label
.height
;
510 void wxListLineData::GetRect( wxRect
&rect
)
512 AssignRect( rect
, m_bound_all
);
515 long wxListLineData::IsHit( int x
, int y
)
517 wxNode
*node
= m_items
.First();
520 wxListItemData
*item
= (wxListItemData
*)node
->Data();
521 if (item
->HasImage() && IsInRect( x
, y
, m_bound_icon
)) return wxLIST_HITTEST_ONITEMICON
;
522 if (item
->HasText() && IsInRect( x
, y
, m_bound_label
)) return wxLIST_HITTEST_ONITEMLABEL
;
523 // if (!(item->HasImage() || item->HasText())) return 0;
525 // if there is no icon or text = empty
526 if (IsInRect( x
, y
, m_bound_all
)) return wxLIST_HITTEST_ONITEMICON
;
530 void wxListLineData::InitItems( int num
)
532 for (int i
= 0; i
< num
; i
++) m_items
.Append( new wxListItemData() );
535 void wxListLineData::SetItem( int index
, const wxListItem
&info
)
537 wxNode
*node
= m_items
.Nth( index
);
540 wxListItemData
*item
= (wxListItemData
*)node
->Data();
541 item
->SetItem( info
);
545 void wxListLineData::GetItem( int index
, wxListItem
&info
)
548 wxNode
*node
= m_items
.Nth( i
);
551 wxListItemData
*item
= (wxListItemData
*)node
->Data();
552 item
->GetItem( info
);
556 void wxListLineData::GetText( int index
, wxString
&s
)
559 wxNode
*node
= m_items
.Nth( i
);
563 wxListItemData
*item
= (wxListItemData
*)node
->Data();
568 void wxListLineData::SetText( int index
, const wxString s
)
571 wxNode
*node
= m_items
.Nth( i
);
574 wxListItemData
*item
= (wxListItemData
*)node
->Data();
579 int wxListLineData::GetImage( int index
)
582 wxNode
*node
= m_items
.Nth( i
);
585 wxListItemData
*item
= (wxListItemData
*)node
->Data();
586 return item
->GetImage();
591 void wxListLineData::SetAttributes(wxDC
*dc
,
592 const wxListItemAttr
*attr
,
593 const wxColour
& colText
,
597 // don't use foregroud colour for drawing highlighted items - this might
598 // make them completely invisible (and there is no way to do bit
599 // arithmetics on wxColour, unfortunately)
600 if ( !hilight
&& attr
&& attr
->HasTextColour() )
602 dc
->SetTextForeground(attr
->GetTextColour());
606 dc
->SetTextForeground(colText
);
609 if ( attr
&& attr
->HasFont() )
611 dc
->SetFont(attr
->GetFont());
619 void wxListLineData::DoDraw( wxDC
*dc
, bool hilight
, bool paintBG
)
623 m_owner
->CalcScrolledPosition( m_bound_all
.x
, m_bound_all
.y
, &dev_x
, &dev_y
);
624 wxCoord dev_w
= m_bound_all
.width
;
625 wxCoord dev_h
= m_bound_all
.height
;
627 if (!m_owner
->IsExposed( dev_x
, dev_y
, dev_w
, dev_h
))
630 wxWindow
*listctrl
= m_owner
->GetParent();
632 // default foreground colour
636 colText
= wxSystemSettings::GetSystemColour( wxSYS_COLOUR_HIGHLIGHTTEXT
);
640 colText
= listctrl
->GetForegroundColour();
644 wxFont font
= listctrl
->GetFont();
646 // VZ: currently we set the colours/fonts only once, but like this (i.e.
647 // using SetAttributes() inside the loop), it will be trivial to
648 // customize the subitems (in report mode) too.
649 wxListItemData
*item
= (wxListItemData
*)m_items
.First()->Data();
650 wxListItemAttr
*attr
= item
->GetAttributes();
651 SetAttributes(dc
, attr
, colText
, font
, hilight
);
653 bool hasBgCol
= attr
&& attr
->HasBackgroundColour();
654 if ( paintBG
|| hasBgCol
)
658 dc
->SetBrush( * m_hilightBrush
);
663 dc
->SetBrush(wxBrush(attr
->GetBackgroundColour(), wxSOLID
));
665 dc
->SetBrush( * wxWHITE_BRUSH
);
668 dc
->SetPen( * wxTRANSPARENT_PEN
);
669 dc
->DrawRectangle( m_bound_hilight
.x
, m_bound_hilight
.y
,
670 m_bound_hilight
.width
, m_bound_hilight
.height
);
673 if (m_mode
== wxLC_REPORT
)
675 wxNode
*node
= m_items
.First();
678 wxListItemData
*item
= (wxListItemData
*)node
->Data();
679 dc
->SetClippingRegion( item
->GetX(), item
->GetY(), item
->GetWidth()-3, item
->GetHeight() );
680 int x
= item
->GetX();
681 if (item
->HasImage())
684 m_owner
->DrawImage( item
->GetImage(), dc
, x
, item
->GetY() );
685 m_owner
->GetImageSize( item
->GetImage(), x
, y
);
686 x
+= item
->GetX() + 5;
690 dc
->DrawText( item
->GetText(), x
, item
->GetY() );
692 dc
->DestroyClippingRegion();
698 wxNode
*node
= m_items
.First();
701 wxListItemData
*item
= (wxListItemData
*)node
->Data();
702 if (item
->HasImage())
704 m_owner
->DrawImage( item
->GetImage(), dc
, m_bound_icon
.x
, m_bound_icon
.y
);
708 dc
->DrawText( item
->GetText(), m_bound_label
.x
, m_bound_label
.y
);
714 void wxListLineData::Hilight( bool on
)
716 if (on
== m_hilighted
) return;
719 m_owner
->SelectLine( this );
721 m_owner
->DeselectLine( this );
724 void wxListLineData::ReverseHilight( void )
726 m_hilighted
= !m_hilighted
;
728 m_owner
->SelectLine( this );
730 m_owner
->DeselectLine( this );
733 void wxListLineData::DrawRubberBand( wxDC
*dc
, bool on
)
737 dc
->SetPen( * wxBLACK_PEN
);
738 dc
->SetBrush( * wxTRANSPARENT_BRUSH
);
739 dc
->DrawRectangle( m_bound_hilight
.x
, m_bound_hilight
.y
,
740 m_bound_hilight
.width
, m_bound_hilight
.height
);
744 void wxListLineData::Draw( wxDC
*dc
)
746 DoDraw( dc
, m_hilighted
, m_hilighted
);
749 bool wxListLineData::IsInRect( int x
, int y
, const wxRect
&rect
)
751 return ((x
>= rect
.x
) && (x
<= rect
.x
+rect
.width
) &&
752 (y
>= rect
.y
) && (y
<= rect
.y
+rect
.height
));
755 bool wxListLineData::IsHilighted( void )
760 void wxListLineData::AssignRect( wxRect
&dest
, int x
, int y
, int width
, int height
)
765 dest
.height
= height
;
768 void wxListLineData::AssignRect( wxRect
&dest
, const wxRect
&source
)
772 dest
.width
= source
.width
;
773 dest
.height
= source
.height
;
776 //-----------------------------------------------------------------------------
777 // wxListHeaderWindow
778 //-----------------------------------------------------------------------------
780 IMPLEMENT_DYNAMIC_CLASS(wxListHeaderWindow
,wxWindow
);
782 BEGIN_EVENT_TABLE(wxListHeaderWindow
,wxWindow
)
783 EVT_PAINT (wxListHeaderWindow::OnPaint
)
784 EVT_MOUSE_EVENTS (wxListHeaderWindow::OnMouse
)
785 EVT_SET_FOCUS (wxListHeaderWindow::OnSetFocus
)
788 wxListHeaderWindow::wxListHeaderWindow( void )
790 m_owner
= (wxListMainWindow
*) NULL
;
791 m_currentCursor
= (wxCursor
*) NULL
;
792 m_resizeCursor
= (wxCursor
*) NULL
;
793 m_isDragging
= FALSE
;
796 wxListHeaderWindow::wxListHeaderWindow( wxWindow
*win
, wxWindowID id
, wxListMainWindow
*owner
,
797 const wxPoint
&pos
, const wxSize
&size
,
798 long style
, const wxString
&name
) :
799 wxWindow( win
, id
, pos
, size
, style
, name
)
802 // m_currentCursor = wxSTANDARD_CURSOR;
803 m_currentCursor
= (wxCursor
*) NULL
;
804 m_resizeCursor
= new wxCursor( wxCURSOR_SIZEWE
);
805 m_isDragging
= FALSE
;
806 SetBackgroundColour( wxSystemSettings::GetSystemColour( wxSYS_COLOUR_BTNFACE
) );
809 wxListHeaderWindow::~wxListHeaderWindow( void )
811 delete m_resizeCursor
;
814 void wxListHeaderWindow::DoDrawRect( wxDC
*dc
, int x
, int y
, int w
, int h
)
816 const int m_corner
= 1;
818 dc
->SetBrush( *wxTRANSPARENT_BRUSH
);
820 dc
->SetPen( *wxBLACK_PEN
);
821 dc
->DrawLine( x
+w
-m_corner
+1, y
, x
+w
, y
+h
); // right (outer)
822 dc
->DrawRectangle( x
, y
+h
, w
+1, 1 ); // bottom (outer)
824 wxPen
pen( wxSystemSettings::GetSystemColour( wxSYS_COLOUR_BTNSHADOW
), 1, wxSOLID
);
827 dc
->DrawLine( x
+w
-m_corner
, y
, x
+w
-1, y
+h
); // right (inner)
828 dc
->DrawRectangle( x
+1, y
+h
-1, w
-2, 1 ); // bottom (inner)
830 dc
->SetPen( *wxWHITE_PEN
);
831 dc
->DrawRectangle( x
, y
, w
-m_corner
+1, 1 ); // top (outer)
832 dc
->DrawRectangle( x
, y
, 1, h
); // left (outer)
833 dc
->DrawLine( x
, y
+h
-1, x
+1, y
+h
-1 );
834 dc
->DrawLine( x
+w
-1, y
, x
+w
-1, y
+1 );
837 void wxListHeaderWindow::OnPaint( wxPaintEvent
&WXUNUSED(event
) )
839 wxPaintDC
dc( this );
841 #if wxUSE_GENERIC_LIST_EXTENSIONS
842 if ( m_owner
->GetMode() & wxLC_REPORT
)
847 m_owner
->GetScrollPixelsPerUnit( &xpix
, &ypix
) ;
848 m_owner
->ViewStart( &x
, &y
) ;
849 dc
.SetDeviceOrigin( -x
* xpix
, 0 );
854 dc
.SetFont( GetFont() );
860 GetClientSize( &w
, &h
);
862 dc
.SetBackgroundMode(wxTRANSPARENT
);
863 dc
.SetTextForeground( *wxBLACK
);
865 // do *not* use the listctrl colour for headers - one day we will have a
866 // function to set it separately
870 int numColumns
= m_owner
->GetColumnCount();
872 for (int i
= 0; i
< numColumns
; i
++)
874 m_owner
->GetColumn( i
, item
);
875 int cw
= item
.m_width
-2;
876 #if wxUSE_GENERIC_LIST_EXTENSIONS
877 if ((i
+1 == numColumns
) || ( dc
.LogicalToDeviceX(x
+item
.m_width
) > w
-5))
878 cw
= dc
.DeviceToLogicalX(w
)-x
-1;
880 if ((i
+1 == numColumns
) || (x
+item
.m_width
> w
-5))
883 dc
.SetPen( *wxWHITE_PEN
);
885 DoDrawRect( &dc
, x
, y
, cw
, h
-2 );
886 // dc.SetClippingRegion( x, y, cw-5, h-4 );
887 dc
.DrawText( item
.m_text
, x
+4, y
+3 );
888 // dc.DestroyClippingRegion();
890 #if wxUSE_GENERIC_LIST_EXTENSIONS
891 if (dc
.LogicalToDeviceX(x
) > w
+5) break;
899 void wxListHeaderWindow::DrawCurrent()
903 int x2
= m_currentX
-1;
906 m_owner
->GetClientSize( &dummy
, &y2
);
907 ClientToScreen( &x1
, &y1
);
908 m_owner
->ClientToScreen( &x2
, &y2
);
911 dc
.SetLogicalFunction( wxINVERT
);
912 dc
.SetPen( wxPen( *wxBLACK
, 2, wxSOLID
) );
913 dc
.SetBrush( *wxTRANSPARENT_BRUSH
);
915 dc
.DrawLine( x1
, y1
, x2
, y2
);
917 dc
.SetLogicalFunction( wxCOPY
);
919 dc
.SetPen( wxNullPen
);
920 dc
.SetBrush( wxNullBrush
);
923 void wxListHeaderWindow::OnMouse( wxMouseEvent
&event
)
925 wxCoord x
= (wxCoord
)event
.GetX();
926 wxCoord y
= (wxCoord
)event
.GetY();
930 if (event
.ButtonUp())
933 m_isDragging
= FALSE
;
934 m_owner
->SetColumnWidth( m_column
, m_currentX
-m_minX
);
940 GetClientSize( &size_x
, & dummy
);
944 m_currentX
= m_minX
+7;
945 if (m_currentX
> size_x
-7) m_currentX
= size_x
-7;
952 bool hit_border
= FALSE
;
954 for (int j
= 0; j
< m_owner
->GetColumnCount(); j
++)
956 xpos
+= m_owner
->GetColumnWidth( j
);
958 if ((abs(x
-xpos
) < 3) && (y
< 22) && (m_column
< m_owner
->GetColumnCount()-1))
970 if (event
.LeftDown())
982 wxListEvent
le( wxEVT_COMMAND_LIST_COL_CLICK
, GetParent()->GetId() );
983 le
.SetEventObject( GetParent() );
985 GetParent()->GetEventHandler()->ProcessEvent( le
);
994 if (m_currentCursor
== wxSTANDARD_CURSOR
) SetCursor( * m_resizeCursor
);
995 m_currentCursor
= m_resizeCursor
;
999 if (m_currentCursor
!= wxSTANDARD_CURSOR
) SetCursor( * wxSTANDARD_CURSOR
);
1000 m_currentCursor
= wxSTANDARD_CURSOR
;
1005 void wxListHeaderWindow::OnSetFocus( wxFocusEvent
&WXUNUSED(event
) )
1007 m_owner
->SetFocus();
1010 //-----------------------------------------------------------------------------
1011 // wxListRenameTimer (internal)
1012 //-----------------------------------------------------------------------------
1014 wxListRenameTimer::wxListRenameTimer( wxListMainWindow
*owner
)
1019 void wxListRenameTimer::Notify()
1021 m_owner
->OnRenameTimer();
1024 //-----------------------------------------------------------------------------
1025 // wxListTextCtrl (internal)
1026 //-----------------------------------------------------------------------------
1028 IMPLEMENT_DYNAMIC_CLASS(wxListTextCtrl
,wxTextCtrl
);
1030 BEGIN_EVENT_TABLE(wxListTextCtrl
,wxTextCtrl
)
1031 EVT_CHAR (wxListTextCtrl::OnChar
)
1032 EVT_KILL_FOCUS (wxListTextCtrl::OnKillFocus
)
1035 wxListTextCtrl::wxListTextCtrl( wxWindow
*parent
,
1036 const wxWindowID id
,
1039 wxListMainWindow
*owner
,
1040 const wxString
&value
,
1044 const wxValidator
& validator
,
1045 const wxString
&name
)
1046 : wxTextCtrl( parent
, id
, value
, pos
, size
, style
, validator
, name
)
1051 (*m_accept
) = FALSE
;
1053 m_startValue
= value
;
1056 void wxListTextCtrl::OnChar( wxKeyEvent
&event
)
1058 if (event
.m_keyCode
== WXK_RETURN
)
1061 (*m_res
) = GetValue();
1063 if (!wxPendingDelete
.Member(this))
1064 wxPendingDelete
.Append(this);
1066 if ((*m_accept
) && ((*m_res
) != m_startValue
))
1067 m_owner
->OnRenameAccept();
1071 if (event
.m_keyCode
== WXK_ESCAPE
)
1073 (*m_accept
) = FALSE
;
1076 if (!wxPendingDelete
.Member(this))
1077 wxPendingDelete
.Append(this);
1085 void wxListTextCtrl::OnKillFocus( wxFocusEvent
&WXUNUSED(event
) )
1087 if (!wxPendingDelete
.Member(this))
1088 wxPendingDelete
.Append(this);
1090 if ((*m_accept
) && ((*m_res
) != m_startValue
))
1091 m_owner
->OnRenameAccept();
1094 //-----------------------------------------------------------------------------
1096 //-----------------------------------------------------------------------------
1098 IMPLEMENT_DYNAMIC_CLASS(wxListMainWindow
,wxScrolledWindow
);
1100 BEGIN_EVENT_TABLE(wxListMainWindow
,wxScrolledWindow
)
1101 EVT_PAINT (wxListMainWindow::OnPaint
)
1102 EVT_SIZE (wxListMainWindow::OnSize
)
1103 EVT_MOUSE_EVENTS (wxListMainWindow::OnMouse
)
1104 EVT_CHAR (wxListMainWindow::OnChar
)
1105 EVT_KEY_DOWN (wxListMainWindow::OnKeyDown
)
1106 EVT_SET_FOCUS (wxListMainWindow::OnSetFocus
)
1107 EVT_KILL_FOCUS (wxListMainWindow::OnKillFocus
)
1108 EVT_SCROLLWIN (wxListMainWindow::OnScroll
)
1111 wxListMainWindow::wxListMainWindow()
1114 m_lines
.DeleteContents( TRUE
);
1115 m_columns
.DeleteContents( TRUE
);
1116 m_current
= (wxListLineData
*) NULL
;
1118 m_hilightBrush
= (wxBrush
*) NULL
;
1122 m_small_image_list
= (wxImageList
*) NULL
;
1123 m_normal_image_list
= (wxImageList
*) NULL
;
1124 m_small_spacing
= 30;
1125 m_normal_spacing
= 40;
1128 m_lastOnSame
= FALSE
;
1129 m_renameTimer
= new wxListRenameTimer( this );
1130 m_isCreated
= FALSE
;
1134 wxListMainWindow::wxListMainWindow( wxWindow
*parent
, wxWindowID id
,
1135 const wxPoint
&pos
, const wxSize
&size
,
1136 long style
, const wxString
&name
) :
1137 wxScrolledWindow( parent
, id
, pos
, size
, style
|wxHSCROLL
|wxVSCROLL
, name
)
1140 m_lines
.DeleteContents( TRUE
);
1141 m_columns
.DeleteContents( TRUE
);
1142 m_current
= (wxListLineData
*) NULL
;
1145 m_hilightBrush
= new wxBrush( wxSystemSettings::GetSystemColour(wxSYS_COLOUR_HIGHLIGHT
), wxSOLID
);
1146 m_small_image_list
= (wxImageList
*) NULL
;
1147 m_normal_image_list
= (wxImageList
*) NULL
;
1148 m_small_spacing
= 30;
1149 m_normal_spacing
= 40;
1152 m_isCreated
= FALSE
;
1156 if (m_mode
& wxLC_REPORT
)
1158 #if wxUSE_GENERIC_LIST_EXTENSIONS
1170 SetScrollbars( m_xScroll
, m_yScroll
, 0, 0, 0, 0 );
1173 m_lastOnSame
= FALSE
;
1174 m_renameTimer
= new wxListRenameTimer( this );
1175 m_renameAccept
= FALSE
;
1177 SetBackgroundColour( wxSystemSettings::GetSystemColour( wxSYS_COLOUR_LISTBOX
) );
1180 wxListMainWindow::~wxListMainWindow()
1184 if (m_hilightBrush
) delete m_hilightBrush
;
1186 delete m_renameTimer
;
1189 void wxListMainWindow::RefreshLine( wxListLineData
*line
)
1191 if (m_dirty
) return;
1199 line
->GetExtent( x
, y
, w
, h
);
1200 CalcScrolledPosition( x
, y
, &x
, &y
);
1201 wxRect
rect( x
, y
, w
, h
);
1202 Refresh( TRUE
, &rect
);
1205 void wxListMainWindow::OnPaint( wxPaintEvent
&WXUNUSED(event
) )
1207 // Note: a wxPaintDC must be constructed even if no drawing is
1208 // done (a Windows requirement).
1209 wxPaintDC
dc( this );
1212 if (m_dirty
) return;
1214 if (m_lines
.GetCount() == 0) return;
1218 dc
.SetFont( GetFont() );
1220 if (m_mode
& wxLC_REPORT
)
1222 int lineSpacing
= 0;
1223 wxListLineData
*line
= (wxListLineData
*)m_lines
.First()->Data();
1225 line
->GetSize( dummy
, lineSpacing
);
1228 int y_s
= m_yScroll
*GetScrollPos( wxVERTICAL
);
1230 wxNode
*node
= m_lines
.Nth( y_s
/ lineSpacing
);
1231 for (int i
= 0; i
< m_visibleLines
+2; i
++)
1235 line
= (wxListLineData
*)node
->Data();
1237 node
= node
->Next();
1242 wxNode
*node
= m_lines
.First();
1245 wxListLineData
*line
= (wxListLineData
*)node
->Data();
1247 node
= node
->Next();
1251 if (m_current
) m_current
->DrawRubberBand( &dc
, m_hasFocus
);
1256 void wxListMainWindow::HilightAll( bool on
)
1258 wxNode
*node
= m_lines
.First();
1261 wxListLineData
*line
= (wxListLineData
*)node
->Data();
1262 if (line
->IsHilighted() != on
)
1264 line
->Hilight( on
);
1265 RefreshLine( line
);
1267 node
= node
->Next();
1271 void wxListMainWindow::SendNotify( wxListLineData
*line
, wxEventType command
)
1273 wxListEvent
le( command
, GetParent()->GetId() );
1274 le
.SetEventObject( GetParent() );
1275 le
.m_itemIndex
= GetIndexOfLine( line
);
1276 line
->GetItem( 0, le
.m_item
);
1277 GetParent()->GetEventHandler()->ProcessEvent( le
);
1278 // GetParent()->GetEventHandler()->AddPendingEvent( le );
1281 void wxListMainWindow::FocusLine( wxListLineData
*WXUNUSED(line
) )
1283 // SendNotify( line, wxEVT_COMMAND_LIST_ITEM_FOCUSSED );
1286 void wxListMainWindow::UnfocusLine( wxListLineData
*WXUNUSED(line
) )
1288 // SendNotify( line, wxEVT_COMMAND_LIST_ITEM_UNFOCUSSED );
1291 void wxListMainWindow::SelectLine( wxListLineData
*line
)
1293 SendNotify( line
, wxEVT_COMMAND_LIST_ITEM_SELECTED
);
1296 void wxListMainWindow::DeselectLine( wxListLineData
*line
)
1298 SendNotify( line
, wxEVT_COMMAND_LIST_ITEM_DESELECTED
);
1301 void wxListMainWindow::DeleteLine( wxListLineData
*line
)
1303 SendNotify( line
, wxEVT_COMMAND_LIST_DELETE_ITEM
);
1308 void wxListMainWindow::EditLabel( long item
)
1310 wxNode
*node
= m_lines
.Nth( (size_t)item
);
1311 wxCHECK_RET( node
, wxT("wrong index in wxListCtrl::Edit()") );
1313 m_currentEdit
= (wxListLineData
*) node
->Data();
1315 wxListEvent
le( wxEVT_COMMAND_LIST_BEGIN_LABEL_EDIT
, GetParent()->GetId() );
1316 le
.SetEventObject( GetParent() );
1317 le
.m_itemIndex
= GetIndexOfLine( m_currentEdit
);
1318 m_currentEdit
->GetItem( 0, le
.m_item
);
1319 GetParent()->GetEventHandler()->ProcessEvent( le
);
1321 if (!le
.IsAllowed())
1324 // We have to call this here because the label in
1325 // question might just have been added and no screen
1326 // update taken place.
1327 if (m_dirty
) wxYield();
1330 m_currentEdit
->GetText( 0, s
);
1335 m_currentEdit
->GetLabelExtent( x
, y
, w
, h
);
1337 wxClientDC
dc(this);
1339 x
= dc
.LogicalToDeviceX( x
);
1340 y
= dc
.LogicalToDeviceY( y
);
1342 wxListTextCtrl
*text
= new wxListTextCtrl(
1343 this, -1, &m_renameAccept
, &m_renameRes
, this, s
, wxPoint(x
-4,y
-4), wxSize(w
+11,h
+8) );
1347 void wxListMainWindow::OnRenameTimer()
1349 wxCHECK_RET( m_current
, wxT("invalid m_current") );
1351 Edit( m_lines
.IndexOf( m_current
) );
1354 void wxListMainWindow::OnRenameAccept()
1356 wxListEvent
le( wxEVT_COMMAND_LIST_END_LABEL_EDIT
, GetParent()->GetId() );
1357 le
.SetEventObject( GetParent() );
1358 le
.m_itemIndex
= GetIndexOfLine( m_currentEdit
);
1359 m_currentEdit
->GetItem( 0, le
.m_item
);
1360 le
.m_item
.m_text
= m_renameRes
;
1361 GetParent()->GetEventHandler()->ProcessEvent( le
);
1363 if (!le
.IsAllowed()) return;
1366 info
.m_mask
= wxLIST_MASK_TEXT
;
1367 info
.m_itemId
= le
.m_itemIndex
;
1368 info
.m_text
= m_renameRes
;
1369 info
.SetTextColour(le
.m_item
.GetTextColour());
1373 void wxListMainWindow::OnMouse( wxMouseEvent
&event
)
1375 if (GetParent()->GetEventHandler()->ProcessEvent( event
)) return;
1377 if (!m_current
) return;
1378 if (m_dirty
) return;
1379 if ( !(event
.Dragging() || event
.ButtonDown() || event
.LeftUp() || event
.ButtonDClick()) ) return;
1381 wxClientDC
dc(this);
1383 wxCoord x
= dc
.DeviceToLogicalX( (wxCoord
)event
.GetX() );
1384 wxCoord y
= dc
.DeviceToLogicalY( (wxCoord
)event
.GetY() );
1386 /* Did we actually hit an item ? */
1388 wxNode
*node
= m_lines
.First();
1389 wxListLineData
*line
= (wxListLineData
*) NULL
;
1392 line
= (wxListLineData
*)node
->Data();
1393 hitResult
= line
->IsHit( x
, y
);
1394 if (hitResult
) break;
1395 line
= (wxListLineData
*) NULL
;
1396 node
= node
->Next();
1399 if (event
.Dragging())
1401 if (m_dragCount
== 0)
1402 m_dragStart
= wxPoint(x
,y
);
1406 if (m_dragCount
!= 3) return;
1408 int command
= wxEVT_COMMAND_LIST_BEGIN_DRAG
;
1409 if (event
.RightIsDown()) command
= wxEVT_COMMAND_LIST_BEGIN_RDRAG
;
1411 wxListEvent
le( command
, GetParent()->GetId() );
1412 le
.SetEventObject( GetParent() );
1413 le
.m_pointDrag
= m_dragStart
;
1414 GetParent()->GetEventHandler()->ProcessEvent( le
);
1425 if (event
.ButtonDClick())
1428 m_lastOnSame
= FALSE
;
1429 m_renameTimer
->Stop();
1431 SendNotify( line
, wxEVT_COMMAND_LIST_ITEM_ACTIVATED
);
1436 if (event
.LeftUp() && m_lastOnSame
)
1439 if ((line
== m_current
) &&
1440 (hitResult
== wxLIST_HITTEST_ONITEMLABEL
) &&
1441 (m_mode
& wxLC_EDIT_LABELS
) )
1443 m_renameTimer
->Start( 100, TRUE
);
1445 m_lastOnSame
= FALSE
;
1449 if (event
.RightDown())
1451 SendNotify( line
, wxEVT_COMMAND_LIST_ITEM_RIGHT_CLICK
);
1455 if (event
.MiddleDown())
1457 SendNotify( line
, wxEVT_COMMAND_LIST_ITEM_MIDDLE_CLICK
);
1461 if (event
.LeftDown())
1464 wxListLineData
*oldCurrent
= m_current
;
1465 if (m_mode
& wxLC_SINGLE_SEL
)
1468 HilightAll( FALSE
);
1469 m_current
->ReverseHilight();
1470 RefreshLine( m_current
);
1474 if (event
.ControlDown())
1477 m_current
->ReverseHilight();
1478 RefreshLine( m_current
);
1480 else if (event
.ShiftDown())
1484 int numOfCurrent
= -1;
1485 node
= m_lines
.First();
1488 wxListLineData
*test_line
= (wxListLineData
*)node
->Data();
1490 if (test_line
== oldCurrent
) break;
1491 node
= node
->Next();
1495 node
= m_lines
.First();
1498 wxListLineData
*test_line
= (wxListLineData
*)node
->Data();
1500 if (test_line
== line
) break;
1501 node
= node
->Next();
1504 if (numOfLine
< numOfCurrent
)
1507 numOfLine
= numOfCurrent
;
1511 wxNode
*node
= m_lines
.Nth( numOfCurrent
);
1512 for (int i
= 0; i
<= numOfLine
-numOfCurrent
; i
++)
1514 wxListLineData
*test_line
= (wxListLineData
*)node
->Data();
1515 test_line
->Hilight(TRUE
);
1516 RefreshLine( test_line
);
1517 node
= node
->Next();
1523 HilightAll( FALSE
);
1524 m_current
->ReverseHilight();
1525 RefreshLine( m_current
);
1528 if (m_current
!= oldCurrent
)
1530 RefreshLine( oldCurrent
);
1531 UnfocusLine( oldCurrent
);
1532 FocusLine( m_current
);
1534 m_lastOnSame
= (m_current
== oldCurrent
);
1539 void wxListMainWindow::MoveToFocus()
1541 if (!m_current
) return;
1547 m_current
->GetExtent( item_x
, item_y
, item_w
, item_h
);
1551 GetClientSize( &client_w
, &client_h
);
1553 int view_x
= m_xScroll
*GetScrollPos( wxHORIZONTAL
);
1554 int view_y
= m_yScroll
*GetScrollPos( wxVERTICAL
);
1556 if (m_mode
& wxLC_REPORT
)
1558 if (item_y
-5 < view_y
)
1559 Scroll( -1, (item_y
-5)/m_yScroll
);
1560 if (item_y
+item_h
+5 > view_y
+client_h
)
1561 Scroll( -1, (item_y
+item_h
-client_h
+15)/m_yScroll
);
1565 if (item_x
-view_x
< 5)
1566 Scroll( (item_x
-5)/m_xScroll
, -1 );
1567 if (item_x
+item_w
-5 > view_x
+client_w
)
1568 Scroll( (item_x
+item_w
-client_w
+15)/m_xScroll
, -1 );
1572 void wxListMainWindow::OnArrowChar( wxListLineData
*newCurrent
, bool shiftDown
)
1574 if ((m_mode
& wxLC_SINGLE_SEL
) || (m_usedKeys
== FALSE
)) m_current
->Hilight( FALSE
);
1575 wxListLineData
*oldCurrent
= m_current
;
1576 m_current
= newCurrent
;
1577 if (shiftDown
|| (m_mode
& wxLC_SINGLE_SEL
)) m_current
->Hilight( TRUE
);
1578 RefreshLine( m_current
);
1579 RefreshLine( oldCurrent
);
1580 FocusLine( m_current
);
1581 UnfocusLine( oldCurrent
);
1585 void wxListMainWindow::OnKeyDown( wxKeyEvent
&event
)
1587 wxWindow
*parent
= GetParent();
1589 /* we propagate the key event up */
1590 wxKeyEvent
ke( wxEVT_KEY_DOWN
);
1591 ke
.m_shiftDown
= event
.m_shiftDown
;
1592 ke
.m_controlDown
= event
.m_controlDown
;
1593 ke
.m_altDown
= event
.m_altDown
;
1594 ke
.m_metaDown
= event
.m_metaDown
;
1595 ke
.m_keyCode
= event
.m_keyCode
;
1598 ke
.SetEventObject( parent
);
1599 if (parent
->GetEventHandler()->ProcessEvent( ke
)) return;
1604 void wxListMainWindow::OnChar( wxKeyEvent
&event
)
1606 wxWindow
*parent
= GetParent();
1608 /* we send a list_key event up */
1609 wxListEvent
le( wxEVT_COMMAND_LIST_KEY_DOWN
, GetParent()->GetId() );
1610 le
.m_code
= (int)event
.KeyCode();
1611 le
.SetEventObject( parent
);
1612 parent
->GetEventHandler()->ProcessEvent( le
);
1614 /* we propagate the char event up */
1615 wxKeyEvent
ke( wxEVT_CHAR
);
1616 ke
.m_shiftDown
= event
.m_shiftDown
;
1617 ke
.m_controlDown
= event
.m_controlDown
;
1618 ke
.m_altDown
= event
.m_altDown
;
1619 ke
.m_metaDown
= event
.m_metaDown
;
1620 ke
.m_keyCode
= event
.m_keyCode
;
1623 ke
.SetEventObject( parent
);
1624 if (parent
->GetEventHandler()->ProcessEvent( ke
)) return;
1626 if (event
.KeyCode() == WXK_TAB
)
1628 wxNavigationKeyEvent nevent
;
1629 nevent
.SetDirection( !event
.ShiftDown() );
1630 nevent
.SetEventObject( GetParent()->GetParent() );
1631 nevent
.SetCurrentFocus( m_parent
);
1632 if (GetParent()->GetParent()->GetEventHandler()->ProcessEvent( nevent
)) return;
1635 /* no item -> nothing to do */
1642 switch (event
.KeyCode())
1646 wxNode
*node
= m_lines
.Member( m_current
)->Previous();
1647 if (node
) OnArrowChar( (wxListLineData
*)node
->Data(), event
.ShiftDown() );
1652 wxNode
*node
= m_lines
.Member( m_current
)->Next();
1653 if (node
) OnArrowChar( (wxListLineData
*)node
->Data(), event
.ShiftDown() );
1658 wxNode
*node
= m_lines
.Last();
1659 OnArrowChar( (wxListLineData
*)node
->Data(), event
.ShiftDown() );
1664 wxNode
*node
= m_lines
.First();
1665 OnArrowChar( (wxListLineData
*)node
->Data(), event
.ShiftDown() );
1671 if (m_mode
& wxLC_REPORT
)
1673 steps
= m_visibleLines
-1;
1678 wxNode
*node
= m_lines
.First();
1679 for (;;) { if (m_current
== (wxListLineData
*)node
->Data()) break; pos
++; node
= node
->Next(); }
1680 steps
= pos
% m_visibleLines
;
1682 wxNode
*node
= m_lines
.Member( m_current
);
1683 for (int i
= 0; i
< steps
; i
++) if (node
->Previous()) node
= node
->Previous();
1684 if (node
) OnArrowChar( (wxListLineData
*)node
->Data(), event
.ShiftDown() );
1690 if (m_mode
& wxLC_REPORT
)
1692 steps
= m_visibleLines
-1;
1696 int pos
= 0; wxNode
*node
= m_lines
.First();
1697 for (;;) { if (m_current
== (wxListLineData
*)node
->Data()) break; pos
++; node
= node
->Next(); }
1698 steps
= m_visibleLines
-(pos
% m_visibleLines
)-1;
1700 wxNode
*node
= m_lines
.Member( m_current
);
1701 for (int i
= 0; i
< steps
; i
++) if (node
->Next()) node
= node
->Next();
1702 if (node
) OnArrowChar( (wxListLineData
*)node
->Data(), event
.ShiftDown() );
1707 if (!(m_mode
& wxLC_REPORT
))
1709 wxNode
*node
= m_lines
.Member( m_current
);
1710 for (int i
= 0; i
<m_visibleLines
; i
++) if (node
->Previous()) node
= node
->Previous();
1711 if (node
) OnArrowChar( (wxListLineData
*)node
->Data(), event
.ShiftDown() );
1717 if (!(m_mode
& wxLC_REPORT
))
1719 wxNode
*node
= m_lines
.Member( m_current
);
1720 for (int i
= 0; i
<m_visibleLines
; i
++) if (node
->Next()) node
= node
->Next();
1721 if (node
) OnArrowChar( (wxListLineData
*)node
->Data(), event
.ShiftDown() );
1727 m_current
->ReverseHilight();
1728 RefreshLine( m_current
);
1733 if (!(m_mode
& wxLC_SINGLE_SEL
))
1735 wxListLineData
*oldCurrent
= m_current
;
1736 m_current
->ReverseHilight();
1737 wxNode
*node
= m_lines
.Member( m_current
)->Next();
1738 if (node
) m_current
= (wxListLineData
*)node
->Data();
1739 RefreshLine( oldCurrent
);
1740 RefreshLine( m_current
);
1741 UnfocusLine( oldCurrent
);
1742 FocusLine( m_current
);
1750 wxListEvent
le( wxEVT_COMMAND_LIST_ITEM_ACTIVATED
, GetParent()->GetId() );
1751 le
.SetEventObject( GetParent() );
1752 le
.m_itemIndex
= GetIndexOfLine( m_current
);
1753 m_current
->GetItem( 0, le
.m_item
);
1754 GetParent()->GetEventHandler()->ProcessEvent( le
);
1767 extern wxWindow
*g_focusWindow
;
1770 void wxListMainWindow::OnSetFocus( wxFocusEvent
&WXUNUSED(event
) )
1773 RefreshLine( m_current
);
1775 if (!GetParent()) return;
1778 g_focusWindow
= GetParent();
1781 wxFocusEvent
event( wxEVT_SET_FOCUS
, GetParent()->GetId() );
1782 event
.SetEventObject( GetParent() );
1783 GetParent()->GetEventHandler()->ProcessEvent( event
);
1786 void wxListMainWindow::OnKillFocus( wxFocusEvent
&WXUNUSED(event
) )
1789 RefreshLine( m_current
);
1792 void wxListMainWindow::OnSize( wxSizeEvent
&WXUNUSED(event
) )
1795 We don't even allow the wxScrolledWindow::AdjustScrollbars() call
1800 void wxListMainWindow::DrawImage( int index
, wxDC
*dc
, int x
, int y
)
1802 if ((m_mode
& wxLC_ICON
) && (m_normal_image_list
))
1804 m_normal_image_list
->Draw( index
, *dc
, x
, y
, wxIMAGELIST_DRAW_TRANSPARENT
);
1807 if ((m_mode
& wxLC_SMALL_ICON
) && (m_small_image_list
))
1809 m_small_image_list
->Draw( index
, *dc
, x
, y
, wxIMAGELIST_DRAW_TRANSPARENT
);
1811 if ((m_mode
& wxLC_LIST
) && (m_small_image_list
))
1813 m_small_image_list
->Draw( index
, *dc
, x
, y
, wxIMAGELIST_DRAW_TRANSPARENT
);
1815 if ((m_mode
& wxLC_REPORT
) && (m_small_image_list
))
1817 m_small_image_list
->Draw( index
, *dc
, x
, y
, wxIMAGELIST_DRAW_TRANSPARENT
);
1822 void wxListMainWindow::GetImageSize( int index
, int &width
, int &height
)
1824 if ((m_mode
& wxLC_ICON
) && (m_normal_image_list
))
1826 m_normal_image_list
->GetSize( index
, width
, height
);
1829 if ((m_mode
& wxLC_SMALL_ICON
) && (m_small_image_list
))
1831 m_small_image_list
->GetSize( index
, width
, height
);
1834 if ((m_mode
& wxLC_LIST
) && (m_small_image_list
))
1836 m_small_image_list
->GetSize( index
, width
, height
);
1839 if ((m_mode
& wxLC_REPORT
) && (m_small_image_list
))
1841 m_small_image_list
->GetSize( index
, width
, height
);
1848 int wxListMainWindow::GetTextLength( wxString
&s
)
1850 wxClientDC
dc( this );
1853 dc
.GetTextExtent( s
, &lw
, &lh
);
1857 int wxListMainWindow::GetIndexOfLine( const wxListLineData
*line
)
1860 wxNode
*node
= m_lines
.First();
1863 if (line
== (wxListLineData
*)node
->Data()) return i
;
1865 node
= node
->Next();
1870 void wxListMainWindow::SetImageList( wxImageList
*imageList
, int which
)
1873 if (which
== wxIMAGE_LIST_NORMAL
) m_normal_image_list
= imageList
;
1874 if (which
== wxIMAGE_LIST_SMALL
) m_small_image_list
= imageList
;
1877 void wxListMainWindow::SetItemSpacing( int spacing
, bool isSmall
)
1882 m_small_spacing
= spacing
;
1886 m_normal_spacing
= spacing
;
1890 int wxListMainWindow::GetItemSpacing( bool isSmall
)
1892 if (isSmall
) return m_small_spacing
; else return m_normal_spacing
;
1895 void wxListMainWindow::SetColumn( int col
, wxListItem
&item
)
1898 wxNode
*node
= m_columns
.Nth( col
);
1901 if (item
.m_width
== wxLIST_AUTOSIZE_USEHEADER
) item
.m_width
= GetTextLength( item
.m_text
)+7;
1902 wxListHeaderData
*column
= (wxListHeaderData
*)node
->Data();
1903 column
->SetItem( item
);
1905 wxListCtrl
*lc
= (wxListCtrl
*) GetParent();
1906 if (lc
->m_headerWin
) lc
->m_headerWin
->Refresh();
1909 void wxListMainWindow::SetColumnWidth( int col
, int width
)
1911 if (!(m_mode
& wxLC_REPORT
)) return;
1915 wxNode
*node
= (wxNode
*) NULL
;
1917 if (width
== wxLIST_AUTOSIZE_USEHEADER
) width
= 80;
1918 if (width
== wxLIST_AUTOSIZE
)
1920 wxClientDC
dc(this);
1921 dc
.SetFont( GetFont() );
1923 node
= m_lines
.First();
1926 wxListLineData
*line
= (wxListLineData
*)node
->Data();
1927 wxNode
*n
= line
->m_items
.Nth( col
);
1930 wxListItemData
*item
= (wxListItemData
*)n
->Data();
1931 int current
= 0, ix
= 0, iy
= 0;
1932 wxCoord lx
= 0, ly
= 0;
1933 if (item
->HasImage())
1935 GetImageSize( item
->GetImage(), ix
, iy
);
1938 if (item
->HasText())
1941 item
->GetText( str
);
1942 dc
.GetTextExtent( str
, &lx
, &ly
);
1945 if (current
> max
) max
= current
;
1947 node
= node
->Next();
1952 node
= m_columns
.Nth( col
);
1955 wxListHeaderData
*column
= (wxListHeaderData
*)node
->Data();
1956 column
->SetWidth( width
);
1959 node
= m_lines
.First();
1962 wxListLineData
*line
= (wxListLineData
*)node
->Data();
1963 wxNode
*n
= line
->m_items
.Nth( col
);
1966 wxListItemData
*item
= (wxListItemData
*)n
->Data();
1967 item
->SetSize( width
, -1 );
1969 node
= node
->Next();
1972 wxListCtrl
*lc
= (wxListCtrl
*) GetParent();
1973 if (lc
->m_headerWin
) lc
->m_headerWin
->Refresh();
1976 void wxListMainWindow::GetColumn( int col
, wxListItem
&item
)
1978 wxNode
*node
= m_columns
.Nth( col
);
1981 wxListHeaderData
*column
= (wxListHeaderData
*)node
->Data();
1982 column
->GetItem( item
);
1994 int wxListMainWindow::GetColumnWidth( int col
)
1996 wxNode
*node
= m_columns
.Nth( col
);
1999 wxListHeaderData
*column
= (wxListHeaderData
*)node
->Data();
2000 return column
->GetWidth();
2008 int wxListMainWindow::GetColumnCount()
2010 return m_columns
.Number();
2013 int wxListMainWindow::GetCountPerPage()
2015 return m_visibleLines
;
2018 void wxListMainWindow::SetItem( wxListItem
&item
)
2021 wxNode
*node
= m_lines
.Nth( (size_t)item
.m_itemId
);
2024 wxListLineData
*line
= (wxListLineData
*)node
->Data();
2025 if (m_mode
& wxLC_REPORT
) item
.m_width
= GetColumnWidth( item
.m_col
)-3;
2026 line
->SetItem( item
.m_col
, item
);
2030 void wxListMainWindow::SetItemState( long item
, long state
, long stateMask
)
2032 // m_dirty = TRUE; no recalcs needed
2034 wxListLineData
*oldCurrent
= m_current
;
2036 if (stateMask
& wxLIST_STATE_FOCUSED
)
2038 wxNode
*node
= m_lines
.Nth( (size_t)item
);
2041 wxListLineData
*line
= (wxListLineData
*)node
->Data();
2042 UnfocusLine( m_current
);
2044 FocusLine( m_current
);
2045 RefreshLine( m_current
);
2046 if (oldCurrent
) RefreshLine( oldCurrent
);
2050 if (stateMask
& wxLIST_STATE_SELECTED
)
2052 bool on
= (state
& wxLIST_STATE_SELECTED
) != 0;
2053 if (!on
&& (m_mode
& wxLC_SINGLE_SEL
)) return;
2055 wxNode
*node
= m_lines
.Nth( (size_t)item
);
2058 wxListLineData
*line
= (wxListLineData
*)node
->Data();
2059 if (m_mode
& wxLC_SINGLE_SEL
)
2061 UnfocusLine( m_current
);
2063 FocusLine( m_current
);
2064 if (oldCurrent
) oldCurrent
->Hilight( FALSE
);
2065 RefreshLine( m_current
);
2066 if (oldCurrent
) RefreshLine( oldCurrent
);
2068 bool on
= (state
& wxLIST_STATE_SELECTED
) != 0;
2069 if (on
!= line
->IsHilighted())
2071 line
->Hilight( on
);
2072 RefreshLine( line
);
2078 int wxListMainWindow::GetItemState( long item
, long stateMask
)
2080 int ret
= wxLIST_STATE_DONTCARE
;
2081 if (stateMask
& wxLIST_STATE_FOCUSED
)
2083 wxNode
*node
= m_lines
.Nth( (size_t)item
);
2086 wxListLineData
*line
= (wxListLineData
*)node
->Data();
2087 if (line
== m_current
) ret
|= wxLIST_STATE_FOCUSED
;
2090 if (stateMask
& wxLIST_STATE_SELECTED
)
2092 wxNode
*node
= m_lines
.Nth( (size_t)item
);
2095 wxListLineData
*line
= (wxListLineData
*)node
->Data();
2096 if (line
->IsHilighted()) ret
|= wxLIST_STATE_FOCUSED
;
2102 void wxListMainWindow::GetItem( wxListItem
&item
)
2104 wxNode
*node
= m_lines
.Nth( (size_t)item
.m_itemId
);
2107 wxListLineData
*line
= (wxListLineData
*)node
->Data();
2108 line
->GetItem( item
.m_col
, item
);
2119 int wxListMainWindow::GetItemCount()
2121 return m_lines
.Number();
2124 void wxListMainWindow::GetItemRect( long index
, wxRect
&rect
)
2126 wxNode
*node
= m_lines
.Nth( (size_t)index
);
2129 wxListLineData
*line
= (wxListLineData
*)node
->Data();
2130 line
->GetRect( rect
);
2141 bool wxListMainWindow::GetItemPosition(long item
, wxPoint
& pos
)
2143 wxNode
*node
= m_lines
.Nth( (size_t)item
);
2147 wxListLineData
*line
= (wxListLineData
*)node
->Data();
2148 line
->GetRect( rect
);
2160 int wxListMainWindow::GetSelectedItemCount()
2163 wxNode
*node
= m_lines
.First();
2166 wxListLineData
*line
= (wxListLineData
*)node
->Data();
2167 if (line
->IsHilighted()) ret
++;
2168 node
= node
->Next();
2173 void wxListMainWindow::SetMode( long mode
)
2180 if (m_mode
& wxLC_REPORT
)
2182 #if wxUSE_GENERIC_LIST_EXTENSIONS
2196 long wxListMainWindow::GetMode() const
2201 void wxListMainWindow::CalculatePositions()
2203 if (!m_lines
.First()) return;
2205 wxClientDC
dc( this );
2206 dc
.SetFont( GetFont() );
2208 int iconSpacing
= 0;
2209 if (m_mode
& wxLC_ICON
) iconSpacing
= m_normal_spacing
;
2210 if (m_mode
& wxLC_SMALL_ICON
) iconSpacing
= m_small_spacing
;
2212 // we take the first line (which also can be an icon or
2213 // an a text item in wxLC_ICON and wxLC_LIST modes) to
2214 // measure the size of the line
2218 int lineSpacing
= 0;
2220 wxListLineData
*line
= (wxListLineData
*)m_lines
.First()->Data();
2221 line
->CalculateSize( &dc
, iconSpacing
);
2223 line
->GetSize( dummy
, lineSpacing
);
2226 int clientWidth
= 0;
2227 int clientHeight
= 0;
2229 if (m_mode
& wxLC_REPORT
)
2233 int entireHeight
= m_lines
.Number() * lineSpacing
+ 2;
2234 int scroll_pos
= GetScrollPos( wxVERTICAL
);
2235 #if wxUSE_GENERIC_LIST_EXTENSIONS
2236 int x_scroll_pos
= GetScrollPos( wxHORIZONTAL
);
2238 SetScrollbars( m_xScroll
, m_yScroll
, 0, (entireHeight
+15) / m_yScroll
, 0, scroll_pos
, TRUE
);
2240 GetClientSize( &clientWidth
, &clientHeight
);
2242 wxNode
* node
= m_lines
.First();
2243 int entireWidth
= 0 ;
2246 wxListLineData
*line
= (wxListLineData
*)node
->Data();
2247 line
->CalculateSize( &dc
, iconSpacing
);
2248 line
->SetPosition( &dc
, x
, y
, clientWidth
);
2250 for (int i
= 0; i
< GetColumnCount(); i
++)
2252 line
->SetColumnPosition( i
, col_x
);
2253 col_x
+= GetColumnWidth( i
);
2255 entireWidth
= wxMax( entireWidth
, col_x
) ;
2256 #if wxUSE_GENERIC_LIST_EXTENSIONS
2257 line
->SetPosition( &dc
, x
, y
, col_x
);
2259 y
+= lineSpacing
; // one pixel blank line between items
2260 node
= node
->Next();
2262 m_visibleLines
= clientHeight
/ lineSpacing
;
2263 #if wxUSE_GENERIC_LIST_EXTENSIONS
2264 SetScrollbars( m_xScroll
, m_yScroll
, entireWidth
/ m_xScroll
, (entireHeight
+15) / m_yScroll
, x_scroll_pos
, scroll_pos
, TRUE
);
2269 // at first we try without any scrollbar. if the items don't
2270 // fit into the window, we recalculate after subtracting an
2271 // approximated 15 pt for the horizontal scrollbar
2273 GetSize( &clientWidth
, &clientHeight
);
2274 clientHeight
-= 4; // sunken frame
2276 int entireWidth
= 0;
2278 for (int tries
= 0; tries
< 2; tries
++)
2281 int x
= 5; // painting is done at x-2
2282 int y
= 5; // painting is done at y-2
2285 int m_currentVisibleLines
= 0;
2286 wxNode
*node
= m_lines
.First();
2289 m_currentVisibleLines
++;
2290 wxListLineData
*line
= (wxListLineData
*)node
->Data();
2291 line
->CalculateSize( &dc
, iconSpacing
);
2292 line
->SetPosition( &dc
, x
, y
, clientWidth
);
2293 line
->GetSize( lineWidth
, lineHeight
);
2294 if (lineWidth
> maxWidth
) maxWidth
= lineWidth
;
2296 if (m_currentVisibleLines
> m_visibleLines
)
2297 m_visibleLines
= m_currentVisibleLines
;
2298 if (y
+lineSpacing
-6 >= clientHeight
) // -6 for earlier "line breaking"
2300 m_currentVisibleLines
= 0;
2303 entireWidth
+= maxWidth
+6;
2306 node
= node
->Next();
2307 if (!node
) entireWidth
+= maxWidth
;
2308 if ((tries
== 0) && (entireWidth
> clientWidth
))
2310 clientHeight
-= 15; // scrollbar height
2312 m_currentVisibleLines
= 0;
2315 if (!node
) tries
= 1; // everything fits, no second try required
2319 int scroll_pos
= GetScrollPos( wxHORIZONTAL
);
2320 SetScrollbars( m_xScroll
, m_yScroll
, (entireWidth
+15) / m_xScroll
, 0, scroll_pos
, 0, TRUE
);
2324 void wxListMainWindow::RealizeChanges( void )
2328 wxNode
*node
= m_lines
.First();
2329 if (node
) m_current
= (wxListLineData
*)node
->Data();
2333 FocusLine( m_current
);
2334 if (m_mode
& wxLC_SINGLE_SEL
) m_current
->Hilight( TRUE
);
2338 long wxListMainWindow::GetNextItem( long item
,
2339 int WXUNUSED(geometry
),
2343 max
= GetItemCount();
2344 wxCHECK_MSG( (ret
== -1) || (ret
< max
), -1,
2345 _T("invalid listctrl index in GetNextItem()") );
2347 // notice that we start with the next item (or the first one if item == -1)
2348 // and this is intentional to allow writing a simple loop to iterate over
2349 // all selected items
2353 // this is not an error because the index was ok initially, just no
2358 wxNode
*node
= m_lines
.Nth( (size_t)ret
);
2361 wxListLineData
*line
= (wxListLineData
*)node
->Data();
2362 if ((state
& wxLIST_STATE_FOCUSED
) && (line
== m_current
))
2364 if ((state
& wxLIST_STATE_SELECTED
) && (line
->IsHilighted()))
2370 node
= node
->Next();
2376 void wxListMainWindow::DeleteItem( long index
)
2379 wxNode
*node
= m_lines
.Nth( (size_t)index
);
2382 wxListLineData
*line
= (wxListLineData
*)node
->Data();
2383 if (m_current
== line
) m_current
= (wxListLineData
*) NULL
;
2385 m_lines
.DeleteNode( node
);
2389 void wxListMainWindow::DeleteColumn( int col
)
2391 wxCHECK_RET( col
< (int)m_columns
.GetCount(),
2392 wxT("attempting to delete inexistent column in wxListView") );
2395 wxNode
*node
= m_columns
.Nth( col
);
2396 if (node
) m_columns
.DeleteNode( node
);
2399 void wxListMainWindow::DeleteAllItems()
2402 m_current
= (wxListLineData
*) NULL
;
2404 // to make the deletion of all items faster, we don't send the
2405 // notifications in this case: this is compatible with wxMSW and
2406 // documented in DeleteAllItems() description
2408 wxListEvent
event( wxEVT_COMMAND_LIST_DELETE_ALL_ITEMS
, GetParent()->GetId() );
2409 event
.SetEventObject( GetParent() );
2410 GetParent()->GetEventHandler()->ProcessEvent( event
);
2415 void wxListMainWindow::DeleteEverything()
2422 void wxListMainWindow::EnsureVisible( long index
)
2424 // We have to call this here because the label in
2425 // question might just have been added and no screen
2426 // update taken place.
2427 if (m_dirty
) wxYield();
2429 wxListLineData
*oldCurrent
= m_current
;
2430 m_current
= (wxListLineData
*) NULL
;
2431 wxNode
*node
= m_lines
.Nth( (size_t)index
);
2432 if (node
) m_current
= (wxListLineData
*)node
->Data();
2433 if (m_current
) MoveToFocus();
2434 m_current
= oldCurrent
;
2437 long wxListMainWindow::FindItem(long start
, const wxString
& str
, bool WXUNUSED(partial
) )
2441 if (pos
< 0) pos
= 0;
2442 wxNode
*node
= m_lines
.Nth( (size_t)pos
);
2445 wxListLineData
*line
= (wxListLineData
*)node
->Data();
2447 line
->GetText( 0, s
);
2448 if (s
== tmp
) return pos
;
2449 node
= node
->Next();
2455 long wxListMainWindow::FindItem(long start
, long data
)
2458 if (pos
< 0) pos
= 0;
2459 wxNode
*node
= m_lines
.Nth( (size_t)pos
);
2462 wxListLineData
*line
= (wxListLineData
*)node
->Data();
2464 line
->GetItem( 0, item
);
2465 if (item
.m_data
== data
) return pos
;
2466 node
= node
->Next();
2472 long wxListMainWindow::HitTest( int x
, int y
, int &flags
)
2474 wxNode
*node
= m_lines
.First();
2478 wxListLineData
*line
= (wxListLineData
*)node
->Data();
2479 long ret
= line
->IsHit( x
, y
);
2485 node
= node
->Next();
2491 void wxListMainWindow::InsertItem( wxListItem
&item
)
2495 if (m_mode
& wxLC_REPORT
) mode
= wxLC_REPORT
;
2496 else if (m_mode
& wxLC_LIST
) mode
= wxLC_LIST
;
2497 else if (m_mode
& wxLC_ICON
) mode
= wxLC_ICON
;
2498 else if (m_mode
& wxLC_SMALL_ICON
) mode
= wxLC_ICON
; // no typo
2500 wxListLineData
*line
= new wxListLineData( this, mode
, m_hilightBrush
);
2502 if (m_mode
& wxLC_REPORT
)
2504 line
->InitItems( GetColumnCount() );
2505 item
.m_width
= GetColumnWidth( 0 )-3;
2509 line
->InitItems( 1 );
2512 line
->SetItem( 0, item
);
2513 if ((item
.m_itemId
>= 0) && (item
.m_itemId
< (int)m_lines
.GetCount()))
2515 wxNode
*node
= m_lines
.Nth( (size_t)item
.m_itemId
);
2516 if (node
) m_lines
.Insert( node
, line
);
2520 m_lines
.Append( line
);
2524 void wxListMainWindow::InsertColumn( long col
, wxListItem
&item
)
2527 if (m_mode
& wxLC_REPORT
)
2529 if (item
.m_width
== wxLIST_AUTOSIZE_USEHEADER
) item
.m_width
= GetTextLength( item
.m_text
);
2530 wxListHeaderData
*column
= new wxListHeaderData( item
);
2531 if ((col
>= 0) && (col
< (int)m_columns
.GetCount()))
2533 wxNode
*node
= m_columns
.Nth( (size_t)col
);
2535 m_columns
.Insert( node
, column
);
2539 m_columns
.Append( column
);
2544 wxListCtrlCompare list_ctrl_compare_func_2
;
2545 long list_ctrl_compare_data
;
2547 int LINKAGEMODE
list_ctrl_compare_func_1( const void *arg1
, const void *arg2
)
2549 wxListLineData
*line1
= *((wxListLineData
**)arg1
);
2550 wxListLineData
*line2
= *((wxListLineData
**)arg2
);
2552 line1
->GetItem( 0, item
);
2553 long data1
= item
.m_data
;
2554 line2
->GetItem( 0, item
);
2555 long data2
= item
.m_data
;
2556 return list_ctrl_compare_func_2( data1
, data2
, list_ctrl_compare_data
);
2559 void wxListMainWindow::SortItems( wxListCtrlCompare fn
, long data
)
2561 list_ctrl_compare_func_2
= fn
;
2562 list_ctrl_compare_data
= data
;
2563 m_lines
.Sort( list_ctrl_compare_func_1
);
2567 void wxListMainWindow::OnScroll(wxScrollWinEvent
& event
)
2569 wxScrolledWindow::OnScroll( event
) ;
2570 #if wxUSE_GENERIC_LIST_EXTENSIONS
2572 if (event
.GetOrientation() == wxHORIZONTAL
&& ( m_mode
& wxLC_REPORT
))
2574 wxListCtrl
* lc
= wxDynamicCast( GetParent() , wxListCtrl
) ;
2577 lc
->m_headerWin
->Refresh() ;
2579 lc
->m_headerWin
->MacUpdateImmediately() ;
2586 // -------------------------------------------------------------------------------------
2588 // -------------------------------------------------------------------------------------
2590 IMPLEMENT_DYNAMIC_CLASS(wxListItem
, wxObject
)
2592 wxListItem::wxListItem()
2601 m_format
= wxLIST_FORMAT_CENTRE
;
2607 void wxListItem::Clear()
2616 m_format
= wxLIST_FORMAT_CENTRE
;
2618 m_text
= wxEmptyString
;
2620 if (m_attr
) delete m_attr
;
2624 void wxListItem::ClearAttributes()
2626 if (m_attr
) delete m_attr
;
2630 // -------------------------------------------------------------------------------------
2632 // -------------------------------------------------------------------------------------
2634 IMPLEMENT_DYNAMIC_CLASS(wxListEvent
, wxNotifyEvent
)
2636 wxListEvent::wxListEvent( wxEventType commandType
, int id
):
2637 wxNotifyEvent( commandType
, id
)
2643 m_cancelled
= FALSE
;
2648 void wxListEvent::CopyObject(wxObject
& object_dest
) const
2650 wxListEvent
*obj
= (wxListEvent
*)&object_dest
;
2652 wxNotifyEvent::CopyObject(object_dest
);
2654 obj
->m_code
= m_code
;
2655 obj
->m_itemIndex
= m_itemIndex
;
2656 obj
->m_oldItemIndex
= m_oldItemIndex
;
2658 obj
->m_cancelled
= m_cancelled
;
2659 obj
->m_pointDrag
= m_pointDrag
;
2660 obj
->m_item
.m_mask
= m_item
.m_mask
;
2661 obj
->m_item
.m_itemId
= m_item
.m_itemId
;
2662 obj
->m_item
.m_col
= m_item
.m_col
;
2663 obj
->m_item
.m_state
= m_item
.m_state
;
2664 obj
->m_item
.m_stateMask
= m_item
.m_stateMask
;
2665 obj
->m_item
.m_text
= m_item
.m_text
;
2666 obj
->m_item
.m_image
= m_item
.m_image
;
2667 obj
->m_item
.m_data
= m_item
.m_data
;
2668 obj
->m_item
.m_format
= m_item
.m_format
;
2669 obj
->m_item
.m_width
= m_item
.m_width
;
2671 if ( m_item
.HasAttributes() )
2673 obj
->m_item
.SetTextColour(m_item
.GetTextColour());
2677 // -------------------------------------------------------------------------------------
2679 // -------------------------------------------------------------------------------------
2681 IMPLEMENT_DYNAMIC_CLASS(wxListCtrl
, wxControl
)
2683 BEGIN_EVENT_TABLE(wxListCtrl
,wxControl
)
2684 EVT_SIZE (wxListCtrl::OnSize
)
2685 EVT_IDLE (wxListCtrl::OnIdle
)
2688 wxListCtrl::wxListCtrl()
2690 m_imageListNormal
= (wxImageList
*) NULL
;
2691 m_imageListSmall
= (wxImageList
*) NULL
;
2692 m_imageListState
= (wxImageList
*) NULL
;
2693 m_mainWin
= (wxListMainWindow
*) NULL
;
2694 m_headerWin
= (wxListHeaderWindow
*) NULL
;
2697 wxListCtrl::~wxListCtrl()
2701 bool wxListCtrl::Create(wxWindow
*parent
,
2706 const wxValidator
&validator
,
2707 const wxString
&name
)
2709 m_imageListNormal
= (wxImageList
*) NULL
;
2710 m_imageListSmall
= (wxImageList
*) NULL
;
2711 m_imageListState
= (wxImageList
*) NULL
;
2712 m_mainWin
= (wxListMainWindow
*) NULL
;
2713 m_headerWin
= (wxListHeaderWindow
*) NULL
;
2715 if ( !(style
& (wxLC_REPORT
| wxLC_LIST
| wxLC_ICON
)) )
2717 style
= style
| wxLC_LIST
;
2720 bool ret
= wxControl::Create( parent
, id
, pos
, size
, style
, validator
, name
);
2723 if (style
& wxSUNKEN_BORDER
)
2724 style
-= wxSUNKEN_BORDER
;
2726 m_mainWin
= new wxListMainWindow( this, -1, wxPoint(0,0), size
, style
);
2728 if (HasFlag(wxLC_REPORT
))
2730 m_headerWin
= new wxListHeaderWindow( this, -1, m_mainWin
, wxPoint(0,0), wxSize(size
.x
,23), wxTAB_TRAVERSAL
);
2731 if (HasFlag(wxLC_NO_HEADER
))
2732 m_headerWin
->Show( FALSE
);
2736 m_headerWin
= (wxListHeaderWindow
*) NULL
;
2739 SetBackgroundColour( wxSystemSettings::GetSystemColour( wxSYS_COLOUR_LISTBOX
) );
2744 void wxListCtrl::OnSize( wxSizeEvent
&WXUNUSED(event
) )
2746 /* handled in OnIdle */
2748 if (m_mainWin
) m_mainWin
->m_dirty
= TRUE
;
2751 void wxListCtrl::SetSingleStyle( long style
, bool add
)
2753 long flag
= GetWindowStyle();
2757 if (style
& wxLC_MASK_TYPE
) flag
= flag
& ~wxLC_MASK_TYPE
;
2758 if (style
& wxLC_MASK_ALIGN
) flag
= flag
& ~wxLC_MASK_ALIGN
;
2759 if (style
& wxLC_MASK_SORT
) flag
= flag
& ~wxLC_MASK_SORT
;
2768 if (flag
& style
) flag
-= style
;
2771 SetWindowStyleFlag( flag
);
2774 void wxListCtrl::SetWindowStyleFlag( long flag
)
2778 m_mainWin
->DeleteEverything();
2782 GetClientSize( &width
, &height
);
2784 m_mainWin
->SetMode( flag
);
2786 if (flag
& wxLC_REPORT
)
2788 if (!HasFlag(wxLC_REPORT
))
2792 m_headerWin
= new wxListHeaderWindow( this, -1, m_mainWin
,
2793 wxPoint(0,0), wxSize(width
,23), wxTAB_TRAVERSAL
);
2794 if (HasFlag(wxLC_NO_HEADER
))
2795 m_headerWin
->Show( FALSE
);
2799 if (flag
& wxLC_NO_HEADER
)
2800 m_headerWin
->Show( FALSE
);
2802 m_headerWin
->Show( TRUE
);
2808 if (HasFlag(wxLC_REPORT
) && !(HasFlag(wxLC_NO_HEADER
)))
2810 m_headerWin
->Show( FALSE
);
2815 wxWindow::SetWindowStyleFlag( flag
);
2818 bool wxListCtrl::GetColumn(int col
, wxListItem
&item
) const
2820 m_mainWin
->GetColumn( col
, item
);
2824 bool wxListCtrl::SetColumn( int col
, wxListItem
& item
)
2826 m_mainWin
->SetColumn( col
, item
);
2830 int wxListCtrl::GetColumnWidth( int col
) const
2832 return m_mainWin
->GetColumnWidth( col
);
2835 bool wxListCtrl::SetColumnWidth( int col
, int width
)
2837 m_mainWin
->SetColumnWidth( col
, width
);
2841 int wxListCtrl::GetCountPerPage() const
2843 return m_mainWin
->GetCountPerPage(); // different from Windows ?
2846 bool wxListCtrl::GetItem( wxListItem
&info
) const
2848 m_mainWin
->GetItem( info
);
2852 bool wxListCtrl::SetItem( wxListItem
&info
)
2854 m_mainWin
->SetItem( info
);
2858 long wxListCtrl::SetItem( long index
, int col
, const wxString
& label
, int imageId
)
2861 info
.m_text
= label
;
2862 info
.m_mask
= wxLIST_MASK_TEXT
;
2863 info
.m_itemId
= index
;
2867 info
.m_image
= imageId
;
2868 info
.m_mask
|= wxLIST_MASK_IMAGE
;
2870 m_mainWin
->SetItem(info
);
2874 int wxListCtrl::GetItemState( long item
, long stateMask
) const
2876 return m_mainWin
->GetItemState( item
, stateMask
);
2879 bool wxListCtrl::SetItemState( long item
, long state
, long stateMask
)
2881 m_mainWin
->SetItemState( item
, state
, stateMask
);
2885 bool wxListCtrl::SetItemImage( long item
, int image
, int WXUNUSED(selImage
) )
2888 info
.m_image
= image
;
2889 info
.m_mask
= wxLIST_MASK_IMAGE
;
2890 info
.m_itemId
= item
;
2891 m_mainWin
->SetItem( info
);
2895 wxString
wxListCtrl::GetItemText( long item
) const
2898 info
.m_itemId
= item
;
2899 m_mainWin
->GetItem( info
);
2903 void wxListCtrl::SetItemText( long item
, const wxString
&str
)
2906 info
.m_mask
= wxLIST_MASK_TEXT
;
2907 info
.m_itemId
= item
;
2909 m_mainWin
->SetItem( info
);
2912 long wxListCtrl::GetItemData( long item
) const
2915 info
.m_itemId
= item
;
2916 m_mainWin
->GetItem( info
);
2920 bool wxListCtrl::SetItemData( long item
, long data
)
2923 info
.m_mask
= wxLIST_MASK_DATA
;
2924 info
.m_itemId
= item
;
2926 m_mainWin
->SetItem( info
);
2930 bool wxListCtrl::GetItemRect( long item
, wxRect
&rect
, int WXUNUSED(code
) ) const
2932 m_mainWin
->GetItemRect( item
, rect
);
2936 bool wxListCtrl::GetItemPosition( long item
, wxPoint
& pos
) const
2938 m_mainWin
->GetItemPosition( item
, pos
);
2942 bool wxListCtrl::SetItemPosition( long WXUNUSED(item
), const wxPoint
& WXUNUSED(pos
) )
2947 int wxListCtrl::GetItemCount() const
2949 return m_mainWin
->GetItemCount();
2952 int wxListCtrl::GetColumnCount() const
2954 return m_mainWin
->GetColumnCount();
2957 void wxListCtrl::SetItemSpacing( int spacing
, bool isSmall
)
2959 m_mainWin
->SetItemSpacing( spacing
, isSmall
);
2962 int wxListCtrl::GetItemSpacing( bool isSmall
) const
2964 return m_mainWin
->GetItemSpacing( isSmall
);
2967 int wxListCtrl::GetSelectedItemCount() const
2969 return m_mainWin
->GetSelectedItemCount();
2972 wxColour
wxListCtrl::GetTextColour() const
2974 return GetForegroundColour();
2977 void wxListCtrl::SetTextColour(const wxColour
& col
)
2979 SetForegroundColour(col
);
2982 long wxListCtrl::GetTopItem() const
2987 long wxListCtrl::GetNextItem( long item
, int geom
, int state
) const
2989 return m_mainWin
->GetNextItem( item
, geom
, state
);
2992 wxImageList
*wxListCtrl::GetImageList(int which
) const
2994 if (which
== wxIMAGE_LIST_NORMAL
)
2996 return m_imageListNormal
;
2998 else if (which
== wxIMAGE_LIST_SMALL
)
3000 return m_imageListSmall
;
3002 else if (which
== wxIMAGE_LIST_STATE
)
3004 return m_imageListState
;
3006 return (wxImageList
*) NULL
;
3009 void wxListCtrl::SetImageList( wxImageList
*imageList
, int which
)
3011 m_mainWin
->SetImageList( imageList
, which
);
3014 bool wxListCtrl::Arrange( int WXUNUSED(flag
) )
3019 bool wxListCtrl::DeleteItem( long item
)
3021 m_mainWin
->DeleteItem( item
);
3025 bool wxListCtrl::DeleteAllItems()
3027 m_mainWin
->DeleteAllItems();
3031 bool wxListCtrl::DeleteAllColumns()
3033 for ( size_t n
= 0; n
< m_mainWin
->m_columns
.GetCount(); n
++ )
3039 void wxListCtrl::ClearAll()
3041 m_mainWin
->DeleteEverything();
3044 bool wxListCtrl::DeleteColumn( int col
)
3046 m_mainWin
->DeleteColumn( col
);
3050 void wxListCtrl::Edit( long item
)
3052 m_mainWin
->Edit( item
);
3055 bool wxListCtrl::EnsureVisible( long item
)
3057 m_mainWin
->EnsureVisible( item
);
3061 long wxListCtrl::FindItem( long start
, const wxString
& str
, bool partial
)
3063 return m_mainWin
->FindItem( start
, str
, partial
);
3066 long wxListCtrl::FindItem( long start
, long data
)
3068 return m_mainWin
->FindItem( start
, data
);
3071 long wxListCtrl::FindItem( long WXUNUSED(start
), const wxPoint
& WXUNUSED(pt
),
3072 int WXUNUSED(direction
))
3077 long wxListCtrl::HitTest( const wxPoint
&point
, int &flags
)
3079 return m_mainWin
->HitTest( (int)point
.x
, (int)point
.y
, flags
);
3082 long wxListCtrl::InsertItem( wxListItem
& info
)
3084 m_mainWin
->InsertItem( info
);
3085 return info
.m_itemId
;
3088 long wxListCtrl::InsertItem( long index
, const wxString
&label
)
3091 info
.m_text
= label
;
3092 info
.m_mask
= wxLIST_MASK_TEXT
;
3093 info
.m_itemId
= index
;
3094 return InsertItem( info
);
3097 long wxListCtrl::InsertItem( long index
, int imageIndex
)
3100 info
.m_mask
= wxLIST_MASK_IMAGE
;
3101 info
.m_image
= imageIndex
;
3102 info
.m_itemId
= index
;
3103 return InsertItem( info
);
3106 long wxListCtrl::InsertItem( long index
, const wxString
&label
, int imageIndex
)
3109 info
.m_text
= label
;
3110 info
.m_image
= imageIndex
;
3111 info
.m_mask
= wxLIST_MASK_TEXT
| wxLIST_MASK_IMAGE
;
3112 info
.m_itemId
= index
;
3113 return InsertItem( info
);
3116 long wxListCtrl::InsertColumn( long col
, wxListItem
&item
)
3118 wxASSERT( m_headerWin
);
3119 m_mainWin
->InsertColumn( col
, item
);
3120 m_headerWin
->Refresh();
3125 long wxListCtrl::InsertColumn( long col
, const wxString
&heading
,
3126 int format
, int width
)
3129 item
.m_mask
= wxLIST_MASK_TEXT
| wxLIST_MASK_FORMAT
;
3130 item
.m_text
= heading
;
3133 item
.m_mask
|= wxLIST_MASK_WIDTH
;
3134 item
.m_width
= width
;
3136 item
.m_format
= format
;
3138 return InsertColumn( col
, item
);
3141 bool wxListCtrl::ScrollList( int WXUNUSED(dx
), int WXUNUSED(dy
) )
3147 // fn is a function which takes 3 long arguments: item1, item2, data.
3148 // item1 is the long data associated with a first item (NOT the index).
3149 // item2 is the long data associated with a second item (NOT the index).
3150 // data is the same value as passed to SortItems.
3151 // The return value is a negative number if the first item should precede the second
3152 // item, a positive number of the second item should precede the first,
3153 // or zero if the two items are equivalent.
3154 // data is arbitrary data to be passed to the sort function.
3156 bool wxListCtrl::SortItems( wxListCtrlCompare fn
, long data
)
3158 m_mainWin
->SortItems( fn
, data
);
3162 void wxListCtrl::OnIdle( wxIdleEvent
&WXUNUSED(event
) )
3164 if (!m_mainWin
->m_dirty
) return;
3168 GetClientSize( &cw
, &ch
);
3175 if (HasFlag(wxLC_REPORT
) && !HasFlag(wxLC_NO_HEADER
))
3177 m_headerWin
->GetPosition( &x
, &y
);
3178 m_headerWin
->GetSize( &w
, &h
);
3179 if ((x
!= 0) || (y
!= 0) || (w
!= cw
) || (h
!= 23))
3180 m_headerWin
->SetSize( 0, 0, cw
, 23 );
3182 m_mainWin
->GetPosition( &x
, &y
);
3183 m_mainWin
->GetSize( &w
, &h
);
3184 if ((x
!= 0) || (y
!= 24) || (w
!= cw
) || (h
!= ch
-24))
3185 m_mainWin
->SetSize( 0, 24, cw
, ch
-24 );
3189 m_mainWin
->GetPosition( &x
, &y
);
3190 m_mainWin
->GetSize( &w
, &h
);
3191 if ((x
!= 0) || (y
!= 24) || (w
!= cw
) || (h
!= ch
))
3192 m_mainWin
->SetSize( 0, 0, cw
, ch
);
3195 m_mainWin
->CalculatePositions();
3196 m_mainWin
->RealizeChanges();
3197 m_mainWin
->m_dirty
= FALSE
;
3198 m_mainWin
->Refresh();
3201 bool wxListCtrl::SetBackgroundColour( const wxColour
&colour
)
3203 if ( !wxWindow::SetBackgroundColour( colour
) )
3208 m_mainWin
->SetBackgroundColour( colour
);
3209 m_mainWin
->m_dirty
= TRUE
;
3214 // m_headerWin->SetBackgroundColour( colour );
3220 bool wxListCtrl::SetForegroundColour( const wxColour
&colour
)
3222 if ( !wxWindow::SetForegroundColour( colour
) )
3227 m_mainWin
->SetForegroundColour( colour
);
3228 m_mainWin
->m_dirty
= TRUE
;
3233 m_headerWin
->SetForegroundColour( colour
);
3239 bool wxListCtrl::SetFont( const wxFont
&font
)
3241 if ( !wxWindow::SetFont( font
) )
3246 m_mainWin
->SetFont( font
);
3247 m_mainWin
->m_dirty
= TRUE
;
3252 m_headerWin
->SetFont( font
);