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
,
2684 #if wxUSE_VALIDATORS
2685 const wxValidator
&validator
,
2687 const wxString
&name
)
2689 m_imageListNormal
= (wxImageList
*) NULL
;
2690 m_imageListSmall
= (wxImageList
*) NULL
;
2691 m_imageListState
= (wxImageList
*) NULL
;
2692 m_mainWin
= (wxListMainWindow
*) NULL
;
2693 m_headerWin
= (wxListHeaderWindow
*) NULL
;
2695 if ( !(style
& (wxLC_REPORT
| wxLC_LIST
| wxLC_ICON
)) )
2697 style
= style
| wxLC_LIST
;
2700 bool ret
= wxControl::Create( parent
,
2705 #if wxUSE_VALIDATORS
2710 #if wxUSE_VALIDATORS
2711 SetValidator( validator
);
2714 if (style
& wxSUNKEN_BORDER
)
2715 style
-= wxSUNKEN_BORDER
;
2717 m_mainWin
= new wxListMainWindow( this, -1, wxPoint(0,0), size
, style
);
2719 if (HasFlag(wxLC_REPORT
))
2720 m_headerWin
= new wxListHeaderWindow( this, -1, m_mainWin
, wxPoint(0,0), wxSize(size
.x
,23), wxTAB_TRAVERSAL
);
2722 m_headerWin
= (wxListHeaderWindow
*) NULL
;
2724 SetBackgroundColour( *wxWHITE
);
2729 void wxListCtrl::OnSize( wxSizeEvent
&WXUNUSED(event
) )
2731 /* handled in OnIdle */
2733 if (m_mainWin
) m_mainWin
->m_dirty
= TRUE
;
2736 void wxListCtrl::SetSingleStyle( long style
, bool add
)
2738 long flag
= GetWindowStyle();
2742 if (style
& wxLC_MASK_TYPE
) flag
= flag
& ~wxLC_MASK_TYPE
;
2743 if (style
& wxLC_MASK_ALIGN
) flag
= flag
& ~wxLC_MASK_ALIGN
;
2744 if (style
& wxLC_MASK_SORT
) flag
= flag
& ~wxLC_MASK_SORT
;
2753 if (flag
& style
) flag
-= style
;
2756 SetWindowStyleFlag( flag
);
2759 void wxListCtrl::SetWindowStyleFlag( long flag
)
2763 m_mainWin
->DeleteEverything();
2767 GetClientSize( &width
, &height
);
2769 m_mainWin
->SetMode( flag
);
2771 if (flag
& wxLC_REPORT
)
2773 if (!HasFlag(wxLC_REPORT
))
2777 m_headerWin
= new wxListHeaderWindow( this, -1, m_mainWin
,
2778 wxPoint(0,0), wxSize(width
,23), wxTAB_TRAVERSAL
);
2779 if (HasFlag(wxLC_NO_HEADER
))
2780 m_headerWin
->Show( FALSE
);
2784 if (flag
& wxLC_NO_HEADER
)
2785 m_headerWin
->Show( FALSE
);
2787 m_headerWin
->Show( TRUE
);
2793 if (HasFlag(wxLC_REPORT
) && !(HasFlag(wxLC_NO_HEADER
)))
2795 m_headerWin
->Show( FALSE
);
2800 wxWindow::SetWindowStyleFlag( flag
);
2803 bool wxListCtrl::GetColumn(int col
, wxListItem
&item
) const
2805 m_mainWin
->GetColumn( col
, item
);
2809 bool wxListCtrl::SetColumn( int col
, wxListItem
& item
)
2811 m_mainWin
->SetColumn( col
, item
);
2815 int wxListCtrl::GetColumnWidth( int col
) const
2817 return m_mainWin
->GetColumnWidth( col
);
2820 bool wxListCtrl::SetColumnWidth( int col
, int width
)
2822 m_mainWin
->SetColumnWidth( col
, width
);
2826 int wxListCtrl::GetCountPerPage() const
2828 return m_mainWin
->GetCountPerPage(); // different from Windows ?
2831 bool wxListCtrl::GetItem( wxListItem
&info
) const
2833 m_mainWin
->GetItem( info
);
2837 bool wxListCtrl::SetItem( wxListItem
&info
)
2839 m_mainWin
->SetItem( info
);
2843 long wxListCtrl::SetItem( long index
, int col
, const wxString
& label
, int imageId
)
2846 info
.m_text
= label
;
2847 info
.m_mask
= wxLIST_MASK_TEXT
;
2848 info
.m_itemId
= index
;
2852 info
.m_image
= imageId
;
2853 info
.m_mask
|= wxLIST_MASK_IMAGE
;
2855 m_mainWin
->SetItem(info
);
2859 int wxListCtrl::GetItemState( long item
, long stateMask
) const
2861 return m_mainWin
->GetItemState( item
, stateMask
);
2864 bool wxListCtrl::SetItemState( long item
, long state
, long stateMask
)
2866 m_mainWin
->SetItemState( item
, state
, stateMask
);
2870 bool wxListCtrl::SetItemImage( long item
, int image
, int WXUNUSED(selImage
) )
2873 info
.m_image
= image
;
2874 info
.m_mask
= wxLIST_MASK_IMAGE
;
2875 info
.m_itemId
= item
;
2876 m_mainWin
->SetItem( info
);
2880 wxString
wxListCtrl::GetItemText( long item
) const
2883 info
.m_itemId
= item
;
2884 m_mainWin
->GetItem( info
);
2888 void wxListCtrl::SetItemText( long item
, const wxString
&str
)
2891 info
.m_mask
= wxLIST_MASK_TEXT
;
2892 info
.m_itemId
= item
;
2894 m_mainWin
->SetItem( info
);
2897 long wxListCtrl::GetItemData( long item
) const
2900 info
.m_itemId
= item
;
2901 m_mainWin
->GetItem( info
);
2905 bool wxListCtrl::SetItemData( long item
, long data
)
2908 info
.m_mask
= wxLIST_MASK_DATA
;
2909 info
.m_itemId
= item
;
2911 m_mainWin
->SetItem( info
);
2915 bool wxListCtrl::GetItemRect( long item
, wxRect
&rect
, int WXUNUSED(code
) ) const
2917 m_mainWin
->GetItemRect( item
, rect
);
2921 bool wxListCtrl::GetItemPosition( long item
, wxPoint
& pos
) const
2923 m_mainWin
->GetItemPosition( item
, pos
);
2927 bool wxListCtrl::SetItemPosition( long WXUNUSED(item
), const wxPoint
& WXUNUSED(pos
) )
2932 int wxListCtrl::GetItemCount() const
2934 return m_mainWin
->GetItemCount();
2937 int wxListCtrl::GetColumnCount() const
2939 return m_mainWin
->GetColumnCount();
2942 void wxListCtrl::SetItemSpacing( int spacing
, bool isSmall
)
2944 m_mainWin
->SetItemSpacing( spacing
, isSmall
);
2947 int wxListCtrl::GetItemSpacing( bool isSmall
) const
2949 return m_mainWin
->GetItemSpacing( isSmall
);
2952 int wxListCtrl::GetSelectedItemCount() const
2954 return m_mainWin
->GetSelectedItemCount();
2957 wxColour
wxListCtrl::GetTextColour() const
2959 return GetForegroundColour();
2962 void wxListCtrl::SetTextColour(const wxColour
& col
)
2964 SetForegroundColour(col
);
2967 long wxListCtrl::GetTopItem() const
2972 long wxListCtrl::GetNextItem( long item
, int geom
, int state
) const
2974 return m_mainWin
->GetNextItem( item
, geom
, state
);
2977 wxImageList
*wxListCtrl::GetImageList(int which
) const
2979 if (which
== wxIMAGE_LIST_NORMAL
)
2981 return m_imageListNormal
;
2983 else if (which
== wxIMAGE_LIST_SMALL
)
2985 return m_imageListSmall
;
2987 else if (which
== wxIMAGE_LIST_STATE
)
2989 return m_imageListState
;
2991 return (wxImageList
*) NULL
;
2994 void wxListCtrl::SetImageList( wxImageList
*imageList
, int which
)
2996 m_mainWin
->SetImageList( imageList
, which
);
2999 bool wxListCtrl::Arrange( int WXUNUSED(flag
) )
3004 bool wxListCtrl::DeleteItem( long item
)
3006 m_mainWin
->DeleteItem( item
);
3010 bool wxListCtrl::DeleteAllItems()
3012 m_mainWin
->DeleteAllItems();
3016 bool wxListCtrl::DeleteAllColumns()
3018 for ( size_t n
= 0; n
< m_mainWin
->m_columns
.GetCount(); n
++ )
3024 void wxListCtrl::ClearAll()
3026 m_mainWin
->DeleteEverything();
3029 bool wxListCtrl::DeleteColumn( int col
)
3031 m_mainWin
->DeleteColumn( col
);
3035 void wxListCtrl::Edit( long item
)
3037 m_mainWin
->Edit( item
);
3040 bool wxListCtrl::EnsureVisible( long item
)
3042 m_mainWin
->EnsureVisible( item
);
3046 long wxListCtrl::FindItem( long start
, const wxString
& str
, bool partial
)
3048 return m_mainWin
->FindItem( start
, str
, partial
);
3051 long wxListCtrl::FindItem( long start
, long data
)
3053 return m_mainWin
->FindItem( start
, data
);
3056 long wxListCtrl::FindItem( long WXUNUSED(start
), const wxPoint
& WXUNUSED(pt
),
3057 int WXUNUSED(direction
))
3062 long wxListCtrl::HitTest( const wxPoint
&point
, int &flags
)
3064 return m_mainWin
->HitTest( (int)point
.x
, (int)point
.y
, flags
);
3067 long wxListCtrl::InsertItem( wxListItem
& info
)
3069 m_mainWin
->InsertItem( info
);
3070 return info
.m_itemId
;
3073 long wxListCtrl::InsertItem( long index
, const wxString
&label
)
3076 info
.m_text
= label
;
3077 info
.m_mask
= wxLIST_MASK_TEXT
;
3078 info
.m_itemId
= index
;
3079 return InsertItem( info
);
3082 long wxListCtrl::InsertItem( long index
, int imageIndex
)
3085 info
.m_mask
= wxLIST_MASK_IMAGE
;
3086 info
.m_image
= imageIndex
;
3087 info
.m_itemId
= index
;
3088 return InsertItem( info
);
3091 long wxListCtrl::InsertItem( long index
, const wxString
&label
, int imageIndex
)
3094 info
.m_text
= label
;
3095 info
.m_image
= imageIndex
;
3096 info
.m_mask
= wxLIST_MASK_TEXT
| wxLIST_MASK_IMAGE
;
3097 info
.m_itemId
= index
;
3098 return InsertItem( info
);
3101 long wxListCtrl::InsertColumn( long col
, wxListItem
&item
)
3103 wxASSERT( m_headerWin
);
3104 m_mainWin
->InsertColumn( col
, item
);
3105 m_headerWin
->Refresh();
3110 long wxListCtrl::InsertColumn( long col
, const wxString
&heading
,
3111 int format
, int width
)
3114 item
.m_mask
= wxLIST_MASK_TEXT
| wxLIST_MASK_FORMAT
;
3115 item
.m_text
= heading
;
3118 item
.m_mask
|= wxLIST_MASK_WIDTH
;
3119 item
.m_width
= width
;
3121 item
.m_format
= format
;
3123 return InsertColumn( col
, item
);
3126 bool wxListCtrl::ScrollList( int WXUNUSED(dx
), int WXUNUSED(dy
) )
3132 // fn is a function which takes 3 long arguments: item1, item2, data.
3133 // item1 is the long data associated with a first item (NOT the index).
3134 // item2 is the long data associated with a second item (NOT the index).
3135 // data is the same value as passed to SortItems.
3136 // The return value is a negative number if the first item should precede the second
3137 // item, a positive number of the second item should precede the first,
3138 // or zero if the two items are equivalent.
3139 // data is arbitrary data to be passed to the sort function.
3141 bool wxListCtrl::SortItems( wxListCtrlCompare fn
, long data
)
3143 m_mainWin
->SortItems( fn
, data
);
3147 void wxListCtrl::OnIdle( wxIdleEvent
&WXUNUSED(event
) )
3149 if (!m_mainWin
->m_dirty
) return;
3153 GetClientSize( &cw
, &ch
);
3160 if (HasFlag(wxLC_REPORT
) && !HasFlag(wxLC_NO_HEADER
))
3162 m_headerWin
->GetPosition( &x
, &y
);
3163 m_headerWin
->GetSize( &w
, &h
);
3164 if ((x
!= 0) || (y
!= 0) || (w
!= cw
) || (h
!= 23))
3165 m_headerWin
->SetSize( 0, 0, cw
, 23 );
3167 m_mainWin
->GetPosition( &x
, &y
);
3168 m_mainWin
->GetSize( &w
, &h
);
3169 if ((x
!= 0) || (y
!= 24) || (w
!= cw
) || (h
!= ch
-24))
3170 m_mainWin
->SetSize( 0, 24, cw
, ch
-24 );
3174 m_mainWin
->GetPosition( &x
, &y
);
3175 m_mainWin
->GetSize( &w
, &h
);
3176 if ((x
!= 0) || (y
!= 24) || (w
!= cw
) || (h
!= ch
))
3177 m_mainWin
->SetSize( 0, 0, cw
, ch
);
3180 m_mainWin
->CalculatePositions();
3181 m_mainWin
->RealizeChanges();
3182 m_mainWin
->m_dirty
= FALSE
;
3183 m_mainWin
->Refresh();
3186 bool wxListCtrl::SetBackgroundColour( const wxColour
&colour
)
3188 if ( !wxWindow::SetBackgroundColour( colour
) )
3193 m_mainWin
->SetBackgroundColour( colour
);
3194 m_mainWin
->m_dirty
= TRUE
;
3199 // m_headerWin->SetBackgroundColour( colour );
3205 bool wxListCtrl::SetForegroundColour( const wxColour
&colour
)
3207 if ( !wxWindow::SetForegroundColour( colour
) )
3212 m_mainWin
->SetForegroundColour( colour
);
3213 m_mainWin
->m_dirty
= TRUE
;
3218 m_headerWin
->SetForegroundColour( colour
);
3224 bool wxListCtrl::SetFont( const wxFont
&font
)
3226 if ( !wxWindow::SetFont( font
) )
3231 m_mainWin
->SetFont( font
);
3232 m_mainWin
->m_dirty
= TRUE
;
3237 m_headerWin
->SetFont( font
);