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
)
1177 wxClientDC
dc(this);
1179 line
->GetExtent( x
, y
, w
, h
);
1181 dc
.LogicalToDeviceX(x
-3),
1182 dc
.LogicalToDeviceY(y
-3),
1183 dc
.LogicalToDeviceXRel(w
+6),
1184 dc
.LogicalToDeviceXRel(h
+6) );
1185 Refresh( TRUE
, &rect
);
1189 void wxListMainWindow::OnPaint( wxPaintEvent
&WXUNUSED(event
) )
1191 // Note: a wxPaintDC must be constructed even if no drawing is
1192 // done (a Windows requirement).
1193 wxPaintDC
dc( this );
1196 if (m_dirty
) return;
1198 if (m_lines
.GetCount() == 0) return;
1202 dc
.SetFont( GetFont() );
1204 if (m_mode
& wxLC_REPORT
)
1206 int lineSpacing
= 0;
1207 wxListLineData
*line
= (wxListLineData
*)m_lines
.First()->Data();
1209 line
->GetSize( dummy
, lineSpacing
);
1212 int y_s
= m_yScroll
*GetScrollPos( wxVERTICAL
);
1214 wxNode
*node
= m_lines
.Nth( y_s
/ lineSpacing
);
1215 for (int i
= 0; i
< m_visibleLines
+2; i
++)
1219 line
= (wxListLineData
*)node
->Data();
1221 node
= node
->Next();
1226 wxNode
*node
= m_lines
.First();
1229 wxListLineData
*line
= (wxListLineData
*)node
->Data();
1231 node
= node
->Next();
1235 if (m_current
) m_current
->DrawRubberBand( &dc
, m_hasFocus
);
1240 void wxListMainWindow::HilightAll( bool on
)
1242 wxNode
*node
= m_lines
.First();
1245 wxListLineData
*line
= (wxListLineData
*)node
->Data();
1246 if (line
->IsHilighted() != on
)
1248 line
->Hilight( on
);
1249 RefreshLine( line
);
1251 node
= node
->Next();
1255 void wxListMainWindow::SendNotify( wxListLineData
*line
, wxEventType command
)
1257 wxListEvent
le( command
, GetParent()->GetId() );
1258 le
.SetEventObject( GetParent() );
1259 le
.m_itemIndex
= GetIndexOfLine( line
);
1260 line
->GetItem( 0, le
.m_item
);
1261 GetParent()->GetEventHandler()->ProcessEvent( le
);
1262 // GetParent()->GetEventHandler()->AddPendingEvent( le );
1265 void wxListMainWindow::FocusLine( wxListLineData
*WXUNUSED(line
) )
1267 // SendNotify( line, wxEVT_COMMAND_LIST_ITEM_FOCUSSED );
1270 void wxListMainWindow::UnfocusLine( wxListLineData
*WXUNUSED(line
) )
1272 // SendNotify( line, wxEVT_COMMAND_LIST_ITEM_UNFOCUSSED );
1275 void wxListMainWindow::SelectLine( wxListLineData
*line
)
1277 SendNotify( line
, wxEVT_COMMAND_LIST_ITEM_SELECTED
);
1280 void wxListMainWindow::DeselectLine( wxListLineData
*line
)
1282 SendNotify( line
, wxEVT_COMMAND_LIST_ITEM_DESELECTED
);
1285 void wxListMainWindow::DeleteLine( wxListLineData
*line
)
1287 SendNotify( line
, wxEVT_COMMAND_LIST_DELETE_ITEM
);
1292 void wxListMainWindow::EditLabel( long item
)
1294 wxNode
*node
= m_lines
.Nth( item
);
1295 wxCHECK_RET( node
, wxT("wrong index in wxListCtrl::Edit()") );
1297 m_currentEdit
= (wxListLineData
*) node
->Data();
1299 wxListEvent
le( wxEVT_COMMAND_LIST_BEGIN_LABEL_EDIT
, GetParent()->GetId() );
1300 le
.SetEventObject( GetParent() );
1301 le
.m_itemIndex
= GetIndexOfLine( m_currentEdit
);
1302 m_currentEdit
->GetItem( 0, le
.m_item
);
1303 GetParent()->GetEventHandler()->ProcessEvent( le
);
1305 if (!le
.IsAllowed())
1308 // We have to call this here because the label in
1309 // question might just have been added and no screen
1310 // update taken place.
1311 if (m_dirty
) wxYield();
1314 m_currentEdit
->GetText( 0, s
);
1319 m_currentEdit
->GetLabelExtent( x
, y
, w
, h
);
1321 wxClientDC
dc(this);
1323 x
= dc
.LogicalToDeviceX( x
);
1324 y
= dc
.LogicalToDeviceY( y
);
1326 wxListTextCtrl
*text
= new wxListTextCtrl(
1327 this, -1, &m_renameAccept
, &m_renameRes
, this, s
, wxPoint(x
-4,y
-4), wxSize(w
+11,h
+8) );
1331 void wxListMainWindow::OnRenameTimer()
1333 wxCHECK_RET( m_current
, wxT("invalid m_current") );
1335 Edit( m_lines
.IndexOf( m_current
) );
1338 void wxListMainWindow::OnRenameAccept()
1340 wxListEvent
le( wxEVT_COMMAND_LIST_END_LABEL_EDIT
, GetParent()->GetId() );
1341 le
.SetEventObject( GetParent() );
1342 le
.m_itemIndex
= GetIndexOfLine( m_currentEdit
);
1343 m_currentEdit
->GetItem( 0, le
.m_item
);
1344 le
.m_item
.m_text
= m_renameRes
;
1345 GetParent()->GetEventHandler()->ProcessEvent( le
);
1347 if (!le
.IsAllowed()) return;
1350 info
.m_mask
= wxLIST_MASK_TEXT
;
1351 info
.m_itemId
= le
.m_itemIndex
;
1352 info
.m_text
= m_renameRes
;
1353 info
.SetTextColour(le
.m_item
.GetTextColour());
1357 void wxListMainWindow::OnMouse( wxMouseEvent
&event
)
1359 if (GetParent()->GetEventHandler()->ProcessEvent( event
)) return;
1361 if (!m_current
) return;
1362 if (m_dirty
) return;
1363 if ( !(event
.Dragging() || event
.ButtonDown() || event
.LeftUp() || event
.ButtonDClick()) ) return;
1365 wxClientDC
dc(this);
1367 long x
= dc
.DeviceToLogicalX( (long)event
.GetX() );
1368 long y
= dc
.DeviceToLogicalY( (long)event
.GetY() );
1370 /* Did we actually hit an item ? */
1372 wxNode
*node
= m_lines
.First();
1373 wxListLineData
*line
= (wxListLineData
*) NULL
;
1376 line
= (wxListLineData
*)node
->Data();
1377 hitResult
= line
->IsHit( x
, y
);
1378 if (hitResult
) break;
1379 line
= (wxListLineData
*) NULL
;
1380 node
= node
->Next();
1383 if (event
.Dragging())
1385 if (m_dragCount
== 0)
1386 m_dragStart
= wxPoint(x
,y
);
1390 if (m_dragCount
!= 3) return;
1392 int command
= wxEVT_COMMAND_LIST_BEGIN_DRAG
;
1393 if (event
.RightIsDown()) command
= wxEVT_COMMAND_LIST_BEGIN_RDRAG
;
1395 wxListEvent
le( command
, GetParent()->GetId() );
1396 le
.SetEventObject( GetParent() );
1397 le
.m_pointDrag
= m_dragStart
;
1398 GetParent()->GetEventHandler()->ProcessEvent( le
);
1409 if (event
.ButtonDClick())
1412 m_lastOnSame
= FALSE
;
1413 m_renameTimer
->Stop();
1415 SendNotify( line
, wxEVT_COMMAND_LIST_ITEM_ACTIVATED
);
1420 if (event
.LeftUp() && m_lastOnSame
)
1423 if ((line
== m_current
) &&
1424 (hitResult
== wxLIST_HITTEST_ONITEMLABEL
) &&
1425 (m_mode
& wxLC_EDIT_LABELS
) )
1427 m_renameTimer
->Start( 100, TRUE
);
1429 m_lastOnSame
= FALSE
;
1433 if (event
.RightDown())
1435 SendNotify( line
, wxEVT_COMMAND_LIST_ITEM_RIGHT_CLICK
);
1439 if (event
.MiddleDown())
1441 SendNotify( line
, wxEVT_COMMAND_LIST_ITEM_MIDDLE_CLICK
);
1445 if (event
.LeftDown())
1448 wxListLineData
*oldCurrent
= m_current
;
1449 if (m_mode
& wxLC_SINGLE_SEL
)
1452 HilightAll( FALSE
);
1453 m_current
->ReverseHilight();
1454 RefreshLine( m_current
);
1458 if (event
.ShiftDown())
1461 m_current
->ReverseHilight();
1462 RefreshLine( m_current
);
1464 else if (event
.ControlDown())
1468 int numOfCurrent
= -1;
1469 node
= m_lines
.First();
1472 wxListLineData
*test_line
= (wxListLineData
*)node
->Data();
1474 if (test_line
== oldCurrent
) break;
1475 node
= node
->Next();
1479 node
= m_lines
.First();
1482 wxListLineData
*test_line
= (wxListLineData
*)node
->Data();
1484 if (test_line
== line
) break;
1485 node
= node
->Next();
1488 if (numOfLine
< numOfCurrent
)
1491 numOfLine
= numOfCurrent
;
1495 wxNode
*node
= m_lines
.Nth( numOfCurrent
);
1496 for (int i
= 0; i
<= numOfLine
-numOfCurrent
; i
++)
1498 wxListLineData
*test_line
= (wxListLineData
*)node
->Data();
1499 test_line
->Hilight(TRUE
);
1500 RefreshLine( test_line
);
1501 node
= node
->Next();
1507 HilightAll( FALSE
);
1508 m_current
->ReverseHilight();
1509 RefreshLine( m_current
);
1512 if (m_current
!= oldCurrent
)
1514 RefreshLine( oldCurrent
);
1515 UnfocusLine( oldCurrent
);
1516 FocusLine( m_current
);
1518 m_lastOnSame
= (m_current
== oldCurrent
);
1523 void wxListMainWindow::MoveToFocus()
1525 if (!m_current
) return;
1531 m_current
->GetExtent( x
, y
, w
, h
);
1535 GetClientSize( &w_p
, &h_p
);
1537 if (m_mode
& wxLC_REPORT
)
1539 int y_s
= m_yScroll
*GetScrollPos( wxVERTICAL
);
1540 if ((y
> y_s
) && (y
+h
< y_s
+h_p
)) return;
1541 if (y
-y_s
< 5) { Scroll( -1, (y
-5-h_p
/2)/m_yScroll
); }
1542 if (y
+h
+5 > y_s
+h_p
) { Scroll( -1, (y
+h
-h_p
/2+h
+15)/m_yScroll
); }
1546 int x_s
= m_xScroll
*GetScrollPos( wxHORIZONTAL
);
1547 if ((x
> x_s
) && (x
+w
< x_s
+w_p
)) return;
1548 if (x
-x_s
< 5) { Scroll( (x
-5)/m_xScroll
, -1 ); }
1549 if (x
+w
-5 > x_s
+w_p
) { Scroll( (x
+w
-w_p
+15)/m_xScroll
, -1 ); }
1553 void wxListMainWindow::OnArrowChar( wxListLineData
*newCurrent
, bool shiftDown
)
1555 if ((m_mode
& wxLC_SINGLE_SEL
) || (m_usedKeys
== FALSE
)) m_current
->Hilight( FALSE
);
1556 wxListLineData
*oldCurrent
= m_current
;
1557 m_current
= newCurrent
;
1559 if (shiftDown
|| (m_mode
& wxLC_SINGLE_SEL
)) m_current
->Hilight( TRUE
);
1560 RefreshLine( m_current
);
1561 RefreshLine( oldCurrent
);
1562 FocusLine( m_current
);
1563 UnfocusLine( oldCurrent
);
1566 void wxListMainWindow::OnKeyDown( wxKeyEvent
&event
)
1568 wxWindow
*parent
= GetParent();
1570 /* we propagate the key event up */
1571 wxKeyEvent
ke( wxEVT_KEY_DOWN
);
1572 ke
.m_shiftDown
= event
.m_shiftDown
;
1573 ke
.m_controlDown
= event
.m_controlDown
;
1574 ke
.m_altDown
= event
.m_altDown
;
1575 ke
.m_metaDown
= event
.m_metaDown
;
1576 ke
.m_keyCode
= event
.m_keyCode
;
1579 ke
.SetEventObject( parent
);
1580 if (parent
->GetEventHandler()->ProcessEvent( ke
)) return;
1585 void wxListMainWindow::OnChar( wxKeyEvent
&event
)
1587 wxWindow
*parent
= GetParent();
1589 /* we send a list_key event up */
1590 wxListEvent
le( wxEVT_COMMAND_LIST_KEY_DOWN
, GetParent()->GetId() );
1591 le
.m_code
= event
.KeyCode();
1592 le
.SetEventObject( parent
);
1593 parent
->GetEventHandler()->ProcessEvent( le
);
1595 /* we propagate the char event up */
1596 wxKeyEvent
ke( wxEVT_CHAR
);
1597 ke
.m_shiftDown
= event
.m_shiftDown
;
1598 ke
.m_controlDown
= event
.m_controlDown
;
1599 ke
.m_altDown
= event
.m_altDown
;
1600 ke
.m_metaDown
= event
.m_metaDown
;
1601 ke
.m_keyCode
= event
.m_keyCode
;
1604 ke
.SetEventObject( parent
);
1605 if (parent
->GetEventHandler()->ProcessEvent( ke
)) return;
1607 if (event
.KeyCode() == WXK_TAB
)
1609 wxNavigationKeyEvent nevent
;
1610 nevent
.SetDirection( !event
.ShiftDown() );
1611 nevent
.SetCurrentFocus( m_parent
);
1612 if (m_parent
->GetEventHandler()->ProcessEvent( nevent
)) return;
1615 /* no item -> nothing to do */
1622 switch (event
.KeyCode())
1626 wxNode
*node
= m_lines
.Member( m_current
)->Previous();
1627 if (node
) OnArrowChar( (wxListLineData
*)node
->Data(), event
.ShiftDown() );
1632 wxNode
*node
= m_lines
.Member( m_current
)->Next();
1633 if (node
) OnArrowChar( (wxListLineData
*)node
->Data(), event
.ShiftDown() );
1638 wxNode
*node
= m_lines
.Last();
1639 OnArrowChar( (wxListLineData
*)node
->Data(), event
.ShiftDown() );
1644 wxNode
*node
= m_lines
.First();
1645 OnArrowChar( (wxListLineData
*)node
->Data(), event
.ShiftDown() );
1651 if (m_mode
& wxLC_REPORT
)
1653 steps
= m_visibleLines
-1;
1658 wxNode
*node
= m_lines
.First();
1659 for (;;) { if (m_current
== (wxListLineData
*)node
->Data()) break; pos
++; node
= node
->Next(); }
1660 steps
= pos
% m_visibleLines
;
1662 wxNode
*node
= m_lines
.Member( m_current
);
1663 for (int i
= 0; i
< steps
; i
++) if (node
->Previous()) node
= node
->Previous();
1664 if (node
) OnArrowChar( (wxListLineData
*)node
->Data(), event
.ShiftDown() );
1670 if (m_mode
& wxLC_REPORT
)
1672 steps
= m_visibleLines
-1;
1676 int pos
= 0; wxNode
*node
= m_lines
.First();
1677 for (;;) { if (m_current
== (wxListLineData
*)node
->Data()) break; pos
++; node
= node
->Next(); }
1678 steps
= m_visibleLines
-(pos
% m_visibleLines
)-1;
1680 wxNode
*node
= m_lines
.Member( m_current
);
1681 for (int i
= 0; i
< steps
; i
++) if (node
->Next()) node
= node
->Next();
1682 if (node
) OnArrowChar( (wxListLineData
*)node
->Data(), event
.ShiftDown() );
1687 if (!(m_mode
& wxLC_REPORT
))
1689 wxNode
*node
= m_lines
.Member( m_current
);
1690 for (int i
= 0; i
<m_visibleLines
; i
++) if (node
->Previous()) node
= node
->Previous();
1691 if (node
) OnArrowChar( (wxListLineData
*)node
->Data(), event
.ShiftDown() );
1697 if (!(m_mode
& wxLC_REPORT
))
1699 wxNode
*node
= m_lines
.Member( m_current
);
1700 for (int i
= 0; i
<m_visibleLines
; i
++) if (node
->Next()) node
= node
->Next();
1701 if (node
) OnArrowChar( (wxListLineData
*)node
->Data(), event
.ShiftDown() );
1707 m_current
->ReverseHilight();
1708 RefreshLine( m_current
);
1713 if (!(m_mode
& wxLC_SINGLE_SEL
))
1715 wxListLineData
*oldCurrent
= m_current
;
1716 m_current
->ReverseHilight();
1717 wxNode
*node
= m_lines
.Member( m_current
)->Next();
1718 if (node
) m_current
= (wxListLineData
*)node
->Data();
1720 RefreshLine( oldCurrent
);
1721 RefreshLine( m_current
);
1722 UnfocusLine( oldCurrent
);
1723 FocusLine( m_current
);
1730 wxListEvent
le( wxEVT_COMMAND_LIST_ITEM_ACTIVATED
, GetParent()->GetId() );
1731 le
.SetEventObject( GetParent() );
1732 le
.m_itemIndex
= GetIndexOfLine( m_current
);
1733 m_current
->GetItem( 0, le
.m_item
);
1734 GetParent()->GetEventHandler()->ProcessEvent( le
);
1747 extern wxWindow
*g_focusWindow
;
1750 void wxListMainWindow::OnSetFocus( wxFocusEvent
&WXUNUSED(event
) )
1753 RefreshLine( m_current
);
1755 if (!GetParent()) return;
1758 g_focusWindow
= GetParent();
1761 wxFocusEvent
event( wxEVT_SET_FOCUS
, GetParent()->GetId() );
1762 event
.SetEventObject( GetParent() );
1763 GetParent()->GetEventHandler()->ProcessEvent( event
);
1766 void wxListMainWindow::OnKillFocus( wxFocusEvent
&WXUNUSED(event
) )
1769 RefreshLine( m_current
);
1772 void wxListMainWindow::OnSize( wxSizeEvent
&WXUNUSED(event
) )
1775 We don't even allow the wxScrolledWindow::AdjustScrollbars() call
1780 void wxListMainWindow::DrawImage( int index
, wxDC
*dc
, int x
, int y
)
1782 if ((m_mode
& wxLC_ICON
) && (m_normal_image_list
))
1784 m_normal_image_list
->Draw( index
, *dc
, x
, y
, wxIMAGELIST_DRAW_TRANSPARENT
);
1787 if ((m_mode
& wxLC_SMALL_ICON
) && (m_small_image_list
))
1789 m_small_image_list
->Draw( index
, *dc
, x
, y
, wxIMAGELIST_DRAW_TRANSPARENT
);
1791 if ((m_mode
& wxLC_LIST
) && (m_small_image_list
))
1793 m_small_image_list
->Draw( index
, *dc
, x
, y
, wxIMAGELIST_DRAW_TRANSPARENT
);
1795 if ((m_mode
& wxLC_REPORT
) && (m_small_image_list
))
1797 m_small_image_list
->Draw( index
, *dc
, x
, y
, wxIMAGELIST_DRAW_TRANSPARENT
);
1802 void wxListMainWindow::GetImageSize( int index
, int &width
, int &height
)
1804 if ((m_mode
& wxLC_ICON
) && (m_normal_image_list
))
1806 m_normal_image_list
->GetSize( index
, width
, height
);
1809 if ((m_mode
& wxLC_SMALL_ICON
) && (m_small_image_list
))
1811 m_small_image_list
->GetSize( index
, width
, height
);
1814 if ((m_mode
& wxLC_LIST
) && (m_small_image_list
))
1816 m_small_image_list
->GetSize( index
, width
, height
);
1819 if ((m_mode
& wxLC_REPORT
) && (m_small_image_list
))
1821 m_small_image_list
->GetSize( index
, width
, height
);
1828 int wxListMainWindow::GetTextLength( wxString
&s
)
1830 wxClientDC
dc( this );
1833 dc
.GetTextExtent( s
, &lw
, &lh
);
1837 int wxListMainWindow::GetIndexOfLine( const wxListLineData
*line
)
1840 wxNode
*node
= m_lines
.First();
1843 if (line
== (wxListLineData
*)node
->Data()) return i
;
1845 node
= node
->Next();
1850 void wxListMainWindow::SetImageList( wxImageList
*imageList
, int which
)
1853 if (which
== wxIMAGE_LIST_NORMAL
) m_normal_image_list
= imageList
;
1854 if (which
== wxIMAGE_LIST_SMALL
) m_small_image_list
= imageList
;
1857 void wxListMainWindow::SetItemSpacing( int spacing
, bool isSmall
)
1862 m_small_spacing
= spacing
;
1866 m_normal_spacing
= spacing
;
1870 int wxListMainWindow::GetItemSpacing( bool isSmall
)
1872 if (isSmall
) return m_small_spacing
; else return m_normal_spacing
;
1875 void wxListMainWindow::SetColumn( int col
, wxListItem
&item
)
1878 wxNode
*node
= m_columns
.Nth( col
);
1881 if (item
.m_width
== wxLIST_AUTOSIZE_USEHEADER
) item
.m_width
= GetTextLength( item
.m_text
)+7;
1882 wxListHeaderData
*column
= (wxListHeaderData
*)node
->Data();
1883 column
->SetItem( item
);
1885 wxListCtrl
*lc
= (wxListCtrl
*) GetParent();
1886 if (lc
->m_headerWin
) lc
->m_headerWin
->Refresh();
1889 void wxListMainWindow::SetColumnWidth( int col
, int width
)
1891 if (!(m_mode
& wxLC_REPORT
)) return;
1895 wxNode
*node
= (wxNode
*) NULL
;
1897 if (width
== wxLIST_AUTOSIZE_USEHEADER
) width
= 80;
1898 if (width
== wxLIST_AUTOSIZE
)
1900 wxClientDC
dc(this);
1901 dc
.SetFont( GetFont() );
1903 node
= m_lines
.First();
1906 wxListLineData
*line
= (wxListLineData
*)node
->Data();
1907 wxNode
*n
= line
->m_items
.Nth( col
);
1910 wxListItemData
*item
= (wxListItemData
*)n
->Data();
1911 int current
= 0, ix
= 0, iy
= 0;
1912 wxCoord lx
= 0, ly
= 0;
1913 if (item
->HasImage())
1915 GetImageSize( item
->GetImage(), ix
, iy
);
1918 if (item
->HasText())
1921 item
->GetText( str
);
1922 dc
.GetTextExtent( str
, &lx
, &ly
);
1925 if (current
> max
) max
= current
;
1927 node
= node
->Next();
1932 node
= m_columns
.Nth( col
);
1935 wxListHeaderData
*column
= (wxListHeaderData
*)node
->Data();
1936 column
->SetWidth( width
);
1939 node
= m_lines
.First();
1942 wxListLineData
*line
= (wxListLineData
*)node
->Data();
1943 wxNode
*n
= line
->m_items
.Nth( col
);
1946 wxListItemData
*item
= (wxListItemData
*)n
->Data();
1947 item
->SetSize( width
, -1 );
1949 node
= node
->Next();
1952 wxListCtrl
*lc
= (wxListCtrl
*) GetParent();
1953 if (lc
->m_headerWin
) lc
->m_headerWin
->Refresh();
1956 void wxListMainWindow::GetColumn( int col
, wxListItem
&item
)
1958 wxNode
*node
= m_columns
.Nth( col
);
1961 wxListHeaderData
*column
= (wxListHeaderData
*)node
->Data();
1962 column
->GetItem( item
);
1974 int wxListMainWindow::GetColumnWidth( int col
)
1976 wxNode
*node
= m_columns
.Nth( col
);
1979 wxListHeaderData
*column
= (wxListHeaderData
*)node
->Data();
1980 return column
->GetWidth();
1988 int wxListMainWindow::GetColumnCount()
1990 return m_columns
.Number();
1993 int wxListMainWindow::GetCountPerPage()
1995 return m_visibleLines
;
1998 void wxListMainWindow::SetItem( wxListItem
&item
)
2001 wxNode
*node
= m_lines
.Nth( item
.m_itemId
);
2004 wxListLineData
*line
= (wxListLineData
*)node
->Data();
2005 if (m_mode
& wxLC_REPORT
) item
.m_width
= GetColumnWidth( item
.m_col
)-3;
2006 line
->SetItem( item
.m_col
, item
);
2010 void wxListMainWindow::SetItemState( long item
, long state
, long stateMask
)
2012 // m_dirty = TRUE; no recalcs needed
2014 wxListLineData
*oldCurrent
= m_current
;
2016 if (stateMask
& wxLIST_STATE_FOCUSED
)
2018 wxNode
*node
= m_lines
.Nth( item
);
2021 wxListLineData
*line
= (wxListLineData
*)node
->Data();
2022 UnfocusLine( m_current
);
2024 FocusLine( m_current
);
2025 RefreshLine( m_current
);
2026 if (oldCurrent
) RefreshLine( oldCurrent
);
2030 if (stateMask
& wxLIST_STATE_SELECTED
)
2032 bool on
= state
& wxLIST_STATE_SELECTED
;
2033 if (!on
&& (m_mode
& wxLC_SINGLE_SEL
)) return;
2035 wxNode
*node
= m_lines
.Nth( item
);
2038 wxListLineData
*line
= (wxListLineData
*)node
->Data();
2039 if (m_mode
& wxLC_SINGLE_SEL
)
2041 UnfocusLine( m_current
);
2043 FocusLine( m_current
);
2044 if (oldCurrent
) oldCurrent
->Hilight( FALSE
);
2045 RefreshLine( m_current
);
2046 if (oldCurrent
) RefreshLine( oldCurrent
);
2048 bool on
= state
& wxLIST_STATE_SELECTED
;
2049 if (on
!= line
->IsHilighted())
2051 line
->Hilight( on
);
2052 RefreshLine( line
);
2058 int wxListMainWindow::GetItemState( long item
, long stateMask
)
2060 int ret
= wxLIST_STATE_DONTCARE
;
2061 if (stateMask
& wxLIST_STATE_FOCUSED
)
2063 wxNode
*node
= m_lines
.Nth( item
);
2066 wxListLineData
*line
= (wxListLineData
*)node
->Data();
2067 if (line
== m_current
) ret
|= wxLIST_STATE_FOCUSED
;
2070 if (stateMask
& wxLIST_STATE_SELECTED
)
2072 wxNode
*node
= m_lines
.Nth( item
);
2075 wxListLineData
*line
= (wxListLineData
*)node
->Data();
2076 if (line
->IsHilighted()) ret
|= wxLIST_STATE_FOCUSED
;
2082 void wxListMainWindow::GetItem( wxListItem
&item
)
2084 wxNode
*node
= m_lines
.Nth( item
.m_itemId
);
2087 wxListLineData
*line
= (wxListLineData
*)node
->Data();
2088 line
->GetItem( item
.m_col
, item
);
2099 int wxListMainWindow::GetItemCount()
2101 return m_lines
.Number();
2104 void wxListMainWindow::GetItemRect( long index
, wxRect
&rect
)
2106 wxNode
*node
= m_lines
.Nth( index
);
2109 wxListLineData
*line
= (wxListLineData
*)node
->Data();
2110 line
->GetRect( rect
);
2121 bool wxListMainWindow::GetItemPosition(long item
, wxPoint
& pos
)
2123 wxNode
*node
= m_lines
.Nth( item
);
2127 wxListLineData
*line
= (wxListLineData
*)node
->Data();
2128 line
->GetRect( rect
);
2140 int wxListMainWindow::GetSelectedItemCount()
2143 wxNode
*node
= m_lines
.First();
2146 wxListLineData
*line
= (wxListLineData
*)node
->Data();
2147 if (line
->IsHilighted()) ret
++;
2148 node
= node
->Next();
2153 void wxListMainWindow::SetMode( long mode
)
2160 if (m_mode
& wxLC_REPORT
)
2162 #if wxUSE_GENERIC_LIST_EXTENSIONS
2176 long wxListMainWindow::GetMode() const
2181 void wxListMainWindow::CalculatePositions()
2183 if (!m_lines
.First()) return;
2185 wxClientDC
dc( this );
2186 dc
.SetFont( GetFont() );
2188 int iconSpacing
= 0;
2189 if (m_mode
& wxLC_ICON
) iconSpacing
= m_normal_spacing
;
2190 if (m_mode
& wxLC_SMALL_ICON
) iconSpacing
= m_small_spacing
;
2192 // we take the first line (which also can be an icon or
2193 // an a text item in wxLC_ICON and wxLC_LIST modes) to
2194 // measure the size of the line
2198 int lineSpacing
= 0;
2200 wxListLineData
*line
= (wxListLineData
*)m_lines
.First()->Data();
2201 line
->CalculateSize( &dc
, iconSpacing
);
2203 line
->GetSize( dummy
, lineSpacing
);
2206 int clientWidth
= 0;
2207 int clientHeight
= 0;
2209 if (m_mode
& wxLC_REPORT
)
2213 int entireHeight
= m_lines
.Number() * lineSpacing
+ 2;
2214 int scroll_pos
= GetScrollPos( wxVERTICAL
);
2215 #if wxUSE_GENERIC_LIST_EXTENSIONS
2216 int x_scroll_pos
= GetScrollPos( wxHORIZONTAL
);
2218 SetScrollbars( m_xScroll
, m_yScroll
, 0, (entireHeight
+15) / m_yScroll
, 0, scroll_pos
, TRUE
);
2220 GetClientSize( &clientWidth
, &clientHeight
);
2222 wxNode
* node
= m_lines
.First();
2223 int entireWidth
= 0 ;
2226 wxListLineData
*line
= (wxListLineData
*)node
->Data();
2227 line
->CalculateSize( &dc
, iconSpacing
);
2228 line
->SetPosition( &dc
, x
, y
, clientWidth
);
2230 for (int i
= 0; i
< GetColumnCount(); i
++)
2232 line
->SetColumnPosition( i
, col_x
);
2233 col_x
+= GetColumnWidth( i
);
2235 entireWidth
= wxMax( entireWidth
, col_x
) ;
2236 #if wxUSE_GENERIC_LIST_EXTENSIONS
2237 line
->SetPosition( &dc
, x
, y
, col_x
);
2239 y
+= lineSpacing
; // one pixel blank line between items
2240 node
= node
->Next();
2242 m_visibleLines
= clientHeight
/ lineSpacing
;
2243 #if wxUSE_GENERIC_LIST_EXTENSIONS
2244 SetScrollbars( m_xScroll
, m_yScroll
, entireWidth
/ m_xScroll
, (entireHeight
+15) / m_yScroll
, x_scroll_pos
, scroll_pos
, TRUE
);
2249 // at first we try without any scrollbar. if the items don't
2250 // fit into the window, we recalculate after subtracting an
2251 // approximated 15 pt for the horizontal scrollbar
2253 GetSize( &clientWidth
, &clientHeight
);
2254 clientHeight
-= 4; // sunken frame
2256 int entireWidth
= 0;
2258 for (int tries
= 0; tries
< 2; tries
++)
2261 int x
= 5; // painting is done at x-2
2262 int y
= 5; // painting is done at y-2
2265 int m_currentVisibleLines
= 0;
2266 wxNode
*node
= m_lines
.First();
2269 m_currentVisibleLines
++;
2270 wxListLineData
*line
= (wxListLineData
*)node
->Data();
2271 line
->CalculateSize( &dc
, iconSpacing
);
2272 line
->SetPosition( &dc
, x
, y
, clientWidth
);
2273 line
->GetSize( lineWidth
, lineHeight
);
2274 if (lineWidth
> maxWidth
) maxWidth
= lineWidth
;
2276 if (m_currentVisibleLines
> m_visibleLines
)
2277 m_visibleLines
= m_currentVisibleLines
;
2278 if (y
+lineSpacing
-6 >= clientHeight
) // -6 for earlier "line breaking"
2280 m_currentVisibleLines
= 0;
2283 entireWidth
+= maxWidth
+6;
2286 node
= node
->Next();
2287 if (!node
) entireWidth
+= maxWidth
;
2288 if ((tries
== 0) && (entireWidth
> clientWidth
))
2290 clientHeight
-= 15; // scrollbar height
2292 m_currentVisibleLines
= 0;
2295 if (!node
) tries
= 1; // everything fits, no second try required
2299 int scroll_pos
= GetScrollPos( wxHORIZONTAL
);
2300 SetScrollbars( m_xScroll
, m_yScroll
, (entireWidth
+15) / m_xScroll
, 0, scroll_pos
, 0, TRUE
);
2304 void wxListMainWindow::RealizeChanges( void )
2308 wxNode
*node
= m_lines
.First();
2309 if (node
) m_current
= (wxListLineData
*)node
->Data();
2313 FocusLine( m_current
);
2314 if (m_mode
& wxLC_SINGLE_SEL
) m_current
->Hilight( TRUE
);
2318 long wxListMainWindow::GetNextItem( long item
, int WXUNUSED(geometry
), int state
)
2321 if (item
> 0) ret
= item
;
2322 if(ret
>= GetItemCount()) return -1;
2323 wxNode
*node
= m_lines
.Nth( ret
);
2326 wxListLineData
*line
= (wxListLineData
*)node
->Data();
2327 if ((state
& wxLIST_STATE_FOCUSED
) && (line
== m_current
)) return ret
;
2328 if ((state
& wxLIST_STATE_SELECTED
) && (line
->IsHilighted())) return ret
;
2329 if (!state
) return ret
;
2331 node
= node
->Next();
2336 void wxListMainWindow::DeleteItem( long index
)
2339 wxNode
*node
= m_lines
.Nth( index
);
2342 wxListLineData
*line
= (wxListLineData
*)node
->Data();
2343 if (m_current
== line
) m_current
= (wxListLineData
*) NULL
;
2345 m_lines
.DeleteNode( node
);
2349 void wxListMainWindow::DeleteColumn( int col
)
2351 wxCHECK_RET( col
< (int)m_columns
.GetCount(),
2352 wxT("attempting to delete inexistent column in wxListView") );
2355 wxNode
*node
= m_columns
.Nth( col
);
2356 if (node
) m_columns
.DeleteNode( node
);
2359 void wxListMainWindow::DeleteAllItems( void )
2362 m_current
= (wxListLineData
*) NULL
;
2364 // to make the deletion of all items faster, we don't send the
2365 // notifications in this case: this is compatible with wxMSW and
2366 // documented in DeleteAllItems() description
2368 wxNode
*node
= m_lines
.First();
2371 wxListLineData
*line
= (wxListLineData
*)node
->Data();
2375 node
= node
->Next();
2382 void wxListMainWindow::DeleteEverything( void )
2385 m_current
= (wxListLineData
*) NULL
;
2386 wxNode
*node
= m_lines
.First();
2389 wxListLineData
*line
= (wxListLineData
*)node
->Data();
2391 node
= node
->Next();
2394 m_current
= (wxListLineData
*) NULL
;
2398 void wxListMainWindow::EnsureVisible( long index
)
2400 // We have to call this here because the label in
2401 // question might just have been added and no screen
2402 // update taken place.
2403 if (m_dirty
) wxYield();
2405 wxListLineData
*oldCurrent
= m_current
;
2406 m_current
= (wxListLineData
*) NULL
;
2408 wxNode
*node
= m_lines
.Nth( i
);
2409 if (node
) m_current
= (wxListLineData
*)node
->Data();
2410 if (m_current
) MoveToFocus();
2411 m_current
= oldCurrent
;
2414 long wxListMainWindow::FindItem(long start
, const wxString
& str
, bool WXUNUSED(partial
) )
2418 if (pos
< 0) pos
= 0;
2419 wxNode
*node
= m_lines
.Nth( pos
);
2422 wxListLineData
*line
= (wxListLineData
*)node
->Data();
2424 line
->GetText( 0, s
);
2425 if (s
== tmp
) return pos
;
2426 node
= node
->Next();
2432 long wxListMainWindow::FindItem(long start
, long data
)
2435 if (pos
< 0) pos
= 0;
2436 wxNode
*node
= m_lines
.Nth( pos
);
2439 wxListLineData
*line
= (wxListLineData
*)node
->Data();
2441 line
->GetItem( 0, item
);
2442 if (item
.m_data
== data
) return pos
;
2443 node
= node
->Next();
2449 long wxListMainWindow::HitTest( int x
, int y
, int &flags
)
2451 wxNode
*node
= m_lines
.First();
2455 wxListLineData
*line
= (wxListLineData
*)node
->Data();
2456 long ret
= line
->IsHit( x
, y
);
2462 node
= node
->Next();
2468 void wxListMainWindow::InsertItem( wxListItem
&item
)
2472 if (m_mode
& wxLC_REPORT
) mode
= wxLC_REPORT
;
2473 else if (m_mode
& wxLC_LIST
) mode
= wxLC_LIST
;
2474 else if (m_mode
& wxLC_ICON
) mode
= wxLC_ICON
;
2475 else if (m_mode
& wxLC_SMALL_ICON
) mode
= wxLC_ICON
; // no typo
2477 wxListLineData
*line
= new wxListLineData( this, mode
, m_hilightBrush
);
2479 if (m_mode
& wxLC_REPORT
)
2481 line
->InitItems( GetColumnCount() );
2482 item
.m_width
= GetColumnWidth( 0 )-3;
2486 line
->InitItems( 1 );
2489 line
->SetItem( 0, item
);
2490 if ((item
.m_itemId
>= 0) && (item
.m_itemId
< (int)m_lines
.GetCount()))
2492 wxNode
*node
= m_lines
.Nth( item
.m_itemId
);
2493 if (node
) m_lines
.Insert( node
, line
);
2497 m_lines
.Append( line
);
2501 void wxListMainWindow::InsertColumn( long col
, wxListItem
&item
)
2504 if (m_mode
& wxLC_REPORT
)
2506 if (item
.m_width
== wxLIST_AUTOSIZE_USEHEADER
) item
.m_width
= GetTextLength( item
.m_text
);
2507 wxListHeaderData
*column
= new wxListHeaderData( item
);
2508 if ((col
>= 0) && (col
< (int)m_columns
.GetCount()))
2510 wxNode
*node
= m_columns
.Nth( col
);
2512 m_columns
.Insert( node
, column
);
2516 m_columns
.Append( column
);
2521 wxListCtrlCompare list_ctrl_compare_func_2
;
2522 long list_ctrl_compare_data
;
2524 int LINKAGEMODE
list_ctrl_compare_func_1( const void *arg1
, const void *arg2
)
2526 wxListLineData
*line1
= *((wxListLineData
**)arg1
);
2527 wxListLineData
*line2
= *((wxListLineData
**)arg2
);
2529 line1
->GetItem( 0, item
);
2530 long data1
= item
.m_data
;
2531 line2
->GetItem( 0, item
);
2532 long data2
= item
.m_data
;
2533 return list_ctrl_compare_func_2( data1
, data2
, list_ctrl_compare_data
);
2536 void wxListMainWindow::SortItems( wxListCtrlCompare fn
, long data
)
2538 list_ctrl_compare_func_2
= fn
;
2539 list_ctrl_compare_data
= data
;
2540 m_lines
.Sort( list_ctrl_compare_func_1
);
2543 void wxListMainWindow::OnScroll(wxScrollWinEvent
& event
)
2545 wxScrolledWindow::OnScroll( event
) ;
2546 #if wxUSE_GENERIC_LIST_EXTENSIONS
2548 if (event
.GetOrientation() == wxHORIZONTAL
&& ( m_mode
& wxLC_REPORT
))
2550 wxListCtrl
* lc
= wxDynamicCast( GetParent() , wxListCtrl
) ;
2553 lc
->m_headerWin
->Refresh() ;
2555 lc
->m_headerWin
->MacUpdateImmediately() ;
2562 // -------------------------------------------------------------------------------------
2564 // -------------------------------------------------------------------------------------
2566 IMPLEMENT_DYNAMIC_CLASS(wxListItem
, wxObject
)
2568 wxListItem::wxListItem()
2577 m_format
= wxLIST_FORMAT_CENTRE
;
2583 void wxListItem::Clear()
2592 m_format
= wxLIST_FORMAT_CENTRE
;
2594 m_text
= wxEmptyString
;
2596 if (m_attr
) delete m_attr
;
2600 void wxListItem::ClearAttributes()
2602 if (m_attr
) delete m_attr
;
2606 // -------------------------------------------------------------------------------------
2608 // -------------------------------------------------------------------------------------
2610 IMPLEMENT_DYNAMIC_CLASS(wxListEvent
, wxNotifyEvent
)
2612 wxListEvent::wxListEvent( wxEventType commandType
, int id
):
2613 wxNotifyEvent( commandType
, id
)
2619 m_cancelled
= FALSE
;
2624 void wxListEvent::CopyObject(wxObject
& object_dest
) const
2626 wxListEvent
*obj
= (wxListEvent
*)&object_dest
;
2628 wxNotifyEvent::CopyObject(object_dest
);
2630 obj
->m_code
= m_code
;
2631 obj
->m_itemIndex
= m_itemIndex
;
2632 obj
->m_oldItemIndex
= m_oldItemIndex
;
2634 obj
->m_cancelled
= m_cancelled
;
2635 obj
->m_pointDrag
= m_pointDrag
;
2636 obj
->m_item
.m_mask
= m_item
.m_mask
;
2637 obj
->m_item
.m_itemId
= m_item
.m_itemId
;
2638 obj
->m_item
.m_col
= m_item
.m_col
;
2639 obj
->m_item
.m_state
= m_item
.m_state
;
2640 obj
->m_item
.m_stateMask
= m_item
.m_stateMask
;
2641 obj
->m_item
.m_text
= m_item
.m_text
;
2642 obj
->m_item
.m_image
= m_item
.m_image
;
2643 obj
->m_item
.m_data
= m_item
.m_data
;
2644 obj
->m_item
.m_format
= m_item
.m_format
;
2645 obj
->m_item
.m_width
= m_item
.m_width
;
2647 if ( m_item
.HasAttributes() )
2649 obj
->m_item
.SetTextColour(m_item
.GetTextColour());
2653 // -------------------------------------------------------------------------------------
2655 // -------------------------------------------------------------------------------------
2657 IMPLEMENT_DYNAMIC_CLASS(wxListCtrl
, wxControl
)
2659 BEGIN_EVENT_TABLE(wxListCtrl
,wxControl
)
2660 EVT_SIZE (wxListCtrl::OnSize
)
2661 EVT_IDLE (wxListCtrl::OnIdle
)
2664 wxListCtrl::wxListCtrl()
2666 m_imageListNormal
= (wxImageList
*) NULL
;
2667 m_imageListSmall
= (wxImageList
*) NULL
;
2668 m_imageListState
= (wxImageList
*) NULL
;
2669 m_mainWin
= (wxListMainWindow
*) NULL
;
2670 m_headerWin
= (wxListHeaderWindow
*) NULL
;
2673 wxListCtrl::~wxListCtrl()
2677 bool wxListCtrl::Create( wxWindow
*parent
, wxWindowID id
,
2678 const wxPoint
&pos
, const wxSize
&size
,
2679 #if wxUSE_VALIDATORS
2680 long style
, const wxValidator
&validator
,
2682 const wxString
&name
)
2684 m_imageListNormal
= (wxImageList
*) NULL
;
2685 m_imageListSmall
= (wxImageList
*) NULL
;
2686 m_imageListState
= (wxImageList
*) NULL
;
2687 m_mainWin
= (wxListMainWindow
*) NULL
;
2688 m_headerWin
= (wxListHeaderWindow
*) NULL
;
2693 #pragma message disable codcauunr
2694 // VMS reports on this part the warning:
2695 // statement either is unreachable or causes unreachable code
2697 if ((s
& wxLC_REPORT
== 0) &&
2698 (s
& wxLC_LIST
== 0) &&
2699 (s
& wxLC_ICON
== 0))
2704 #pragma message enable codcauunr
2707 bool ret
= wxControl::Create( parent
, id
, pos
, size
, s
, name
);
2709 #if wxUSE_VALIDATORS
2710 SetValidator( validator
);
2713 if (s
& wxSUNKEN_BORDER
) s
-= wxSUNKEN_BORDER
;
2715 m_mainWin
= new wxListMainWindow( this, -1, wxPoint(0,0), size
, s
);
2717 if (HasFlag(wxLC_REPORT
))
2718 m_headerWin
= new wxListHeaderWindow( this, -1, m_mainWin
, wxPoint(0,0), wxSize(size
.x
,23), wxTAB_TRAVERSAL
);
2720 m_headerWin
= (wxListHeaderWindow
*) NULL
;
2722 SetBackgroundColour( *wxWHITE
);
2727 void wxListCtrl::OnSize( wxSizeEvent
&WXUNUSED(event
) )
2729 /* handled in OnIdle */
2731 if (m_mainWin
) m_mainWin
->m_dirty
= TRUE
;
2734 void wxListCtrl::SetSingleStyle( long style
, bool add
)
2736 long flag
= GetWindowStyle();
2740 if (style
& wxLC_MASK_TYPE
) flag
= flag
& ~wxLC_MASK_TYPE
;
2741 if (style
& wxLC_MASK_ALIGN
) flag
= flag
& ~wxLC_MASK_ALIGN
;
2742 if (style
& wxLC_MASK_SORT
) flag
= flag
& ~wxLC_MASK_SORT
;
2751 if (flag
& style
) flag
-= style
;
2754 SetWindowStyleFlag( flag
);
2757 void wxListCtrl::SetWindowStyleFlag( long flag
)
2761 m_mainWin
->DeleteEverything();
2765 GetClientSize( &width
, &height
);
2767 m_mainWin
->SetMode( flag
);
2769 if (flag
& wxLC_REPORT
)
2771 if (!HasFlag(wxLC_REPORT
))
2775 m_headerWin
= new wxListHeaderWindow( this, -1, m_mainWin
,
2776 wxPoint(0,0), wxSize(width
,23), wxTAB_TRAVERSAL
);
2777 if (HasFlag(wxLC_NO_HEADER
))
2778 m_headerWin
->Show( FALSE
);
2782 if (flag
& wxLC_NO_HEADER
)
2783 m_headerWin
->Show( FALSE
);
2785 m_headerWin
->Show( TRUE
);
2791 if (HasFlag(wxLC_REPORT
) && !(HasFlag(wxLC_NO_HEADER
)))
2793 m_headerWin
->Show( FALSE
);
2798 wxWindow::SetWindowStyleFlag( flag
);
2801 bool wxListCtrl::GetColumn(int col
, wxListItem
&item
) const
2803 m_mainWin
->GetColumn( col
, item
);
2807 bool wxListCtrl::SetColumn( int col
, wxListItem
& item
)
2809 m_mainWin
->SetColumn( col
, item
);
2813 int wxListCtrl::GetColumnWidth( int col
) const
2815 return m_mainWin
->GetColumnWidth( col
);
2818 bool wxListCtrl::SetColumnWidth( int col
, int width
)
2820 m_mainWin
->SetColumnWidth( col
, width
);
2824 int wxListCtrl::GetCountPerPage() const
2826 return m_mainWin
->GetCountPerPage(); // different from Windows ?
2829 bool wxListCtrl::GetItem( wxListItem
&info
) const
2831 m_mainWin
->GetItem( info
);
2835 bool wxListCtrl::SetItem( wxListItem
&info
)
2837 m_mainWin
->SetItem( info
);
2841 long wxListCtrl::SetItem( long index
, int col
, const wxString
& label
, int imageId
)
2844 info
.m_text
= label
;
2845 info
.m_mask
= wxLIST_MASK_TEXT
;
2846 info
.m_itemId
= index
;
2850 info
.m_image
= imageId
;
2851 info
.m_mask
|= wxLIST_MASK_IMAGE
;
2853 m_mainWin
->SetItem(info
);
2857 int wxListCtrl::GetItemState( long item
, long stateMask
) const
2859 return m_mainWin
->GetItemState( item
, stateMask
);
2862 bool wxListCtrl::SetItemState( long item
, long state
, long stateMask
)
2864 m_mainWin
->SetItemState( item
, state
, stateMask
);
2868 bool wxListCtrl::SetItemImage( long item
, int image
, int WXUNUSED(selImage
) )
2871 info
.m_image
= image
;
2872 info
.m_mask
= wxLIST_MASK_IMAGE
;
2873 info
.m_itemId
= item
;
2874 m_mainWin
->SetItem( info
);
2878 wxString
wxListCtrl::GetItemText( long item
) const
2881 info
.m_itemId
= item
;
2882 m_mainWin
->GetItem( info
);
2886 void wxListCtrl::SetItemText( long item
, const wxString
&str
)
2889 info
.m_mask
= wxLIST_MASK_TEXT
;
2890 info
.m_itemId
= item
;
2892 m_mainWin
->SetItem( info
);
2895 long wxListCtrl::GetItemData( long item
) const
2898 info
.m_itemId
= item
;
2899 m_mainWin
->GetItem( info
);
2903 bool wxListCtrl::SetItemData( long item
, long data
)
2906 info
.m_mask
= wxLIST_MASK_DATA
;
2907 info
.m_itemId
= item
;
2909 m_mainWin
->SetItem( info
);
2913 bool wxListCtrl::GetItemRect( long item
, wxRect
&rect
, int WXUNUSED(code
) ) const
2915 m_mainWin
->GetItemRect( item
, rect
);
2919 bool wxListCtrl::GetItemPosition( long item
, wxPoint
& pos
) const
2921 m_mainWin
->GetItemPosition( item
, pos
);
2925 bool wxListCtrl::SetItemPosition( long WXUNUSED(item
), const wxPoint
& WXUNUSED(pos
) )
2930 int wxListCtrl::GetItemCount() const
2932 return m_mainWin
->GetItemCount();
2935 int wxListCtrl::GetColumnCount() const
2937 return m_mainWin
->GetColumnCount();
2940 void wxListCtrl::SetItemSpacing( int spacing
, bool isSmall
)
2942 m_mainWin
->SetItemSpacing( spacing
, isSmall
);
2945 int wxListCtrl::GetItemSpacing( bool isSmall
) const
2947 return m_mainWin
->GetItemSpacing( isSmall
);
2950 int wxListCtrl::GetSelectedItemCount() const
2952 return m_mainWin
->GetSelectedItemCount();
2955 wxColour
wxListCtrl::GetTextColour() const
2957 return GetForegroundColour();
2960 void wxListCtrl::SetTextColour(const wxColour
& col
)
2962 SetForegroundColour(col
);
2965 long wxListCtrl::GetTopItem() const
2970 long wxListCtrl::GetNextItem( long item
, int geom
, int state
) const
2972 return m_mainWin
->GetNextItem( item
, geom
, state
);
2975 wxImageList
*wxListCtrl::GetImageList(int which
) const
2977 if (which
== wxIMAGE_LIST_NORMAL
)
2979 return m_imageListNormal
;
2981 else if (which
== wxIMAGE_LIST_SMALL
)
2983 return m_imageListSmall
;
2985 else if (which
== wxIMAGE_LIST_STATE
)
2987 return m_imageListState
;
2989 return (wxImageList
*) NULL
;
2992 void wxListCtrl::SetImageList( wxImageList
*imageList
, int which
)
2994 m_mainWin
->SetImageList( imageList
, which
);
2997 bool wxListCtrl::Arrange( int WXUNUSED(flag
) )
3002 bool wxListCtrl::DeleteItem( long item
)
3004 m_mainWin
->DeleteItem( item
);
3008 bool wxListCtrl::DeleteAllItems()
3010 m_mainWin
->DeleteAllItems();
3014 bool wxListCtrl::DeleteAllColumns()
3016 for ( size_t n
= 0; n
< m_mainWin
->m_columns
.GetCount(); n
++ )
3022 void wxListCtrl::ClearAll()
3024 m_mainWin
->DeleteEverything();
3027 bool wxListCtrl::DeleteColumn( int col
)
3029 m_mainWin
->DeleteColumn( col
);
3033 void wxListCtrl::Edit( long item
)
3035 m_mainWin
->Edit( item
);
3038 bool wxListCtrl::EnsureVisible( long item
)
3040 m_mainWin
->EnsureVisible( item
);
3044 long wxListCtrl::FindItem( long start
, const wxString
& str
, bool partial
)
3046 return m_mainWin
->FindItem( start
, str
, partial
);
3049 long wxListCtrl::FindItem( long start
, long data
)
3051 return m_mainWin
->FindItem( start
, data
);
3054 long wxListCtrl::FindItem( long WXUNUSED(start
), const wxPoint
& WXUNUSED(pt
),
3055 int WXUNUSED(direction
))
3060 long wxListCtrl::HitTest( const wxPoint
&point
, int &flags
)
3062 return m_mainWin
->HitTest( (int)point
.x
, (int)point
.y
, flags
);
3065 long wxListCtrl::InsertItem( wxListItem
& info
)
3067 m_mainWin
->InsertItem( info
);
3068 return info
.m_itemId
;
3071 long wxListCtrl::InsertItem( long index
, const wxString
&label
)
3074 info
.m_text
= label
;
3075 info
.m_mask
= wxLIST_MASK_TEXT
;
3076 info
.m_itemId
= index
;
3077 return InsertItem( info
);
3080 long wxListCtrl::InsertItem( long index
, int imageIndex
)
3083 info
.m_mask
= wxLIST_MASK_IMAGE
;
3084 info
.m_image
= imageIndex
;
3085 info
.m_itemId
= index
;
3086 return InsertItem( info
);
3089 long wxListCtrl::InsertItem( long index
, const wxString
&label
, int imageIndex
)
3092 info
.m_text
= label
;
3093 info
.m_image
= imageIndex
;
3094 info
.m_mask
= wxLIST_MASK_TEXT
| wxLIST_MASK_IMAGE
;
3095 info
.m_itemId
= index
;
3096 return InsertItem( info
);
3099 long wxListCtrl::InsertColumn( long col
, wxListItem
&item
)
3101 m_mainWin
->InsertColumn( col
, item
);
3105 long wxListCtrl::InsertColumn( long col
, const wxString
&heading
,
3106 int format
, int width
)
3109 item
.m_mask
= wxLIST_MASK_TEXT
| wxLIST_MASK_FORMAT
;
3110 item
.m_text
= heading
;
3113 item
.m_mask
|= wxLIST_MASK_WIDTH
;
3114 item
.m_width
= width
;
3116 item
.m_format
= format
;
3118 return InsertColumn( col
, item
);
3121 bool wxListCtrl::ScrollList( int WXUNUSED(dx
), int WXUNUSED(dy
) )
3127 // fn is a function which takes 3 long arguments: item1, item2, data.
3128 // item1 is the long data associated with a first item (NOT the index).
3129 // item2 is the long data associated with a second item (NOT the index).
3130 // data is the same value as passed to SortItems.
3131 // The return value is a negative number if the first item should precede the second
3132 // item, a positive number of the second item should precede the first,
3133 // or zero if the two items are equivalent.
3134 // data is arbitrary data to be passed to the sort function.
3136 bool wxListCtrl::SortItems( wxListCtrlCompare fn
, long data
)
3138 m_mainWin
->SortItems( fn
, data
);
3142 void wxListCtrl::OnIdle( wxIdleEvent
&WXUNUSED(event
) )
3144 if (!m_mainWin
->m_dirty
) return;
3148 GetClientSize( &cw
, &ch
);
3155 if (HasFlag(wxLC_REPORT
) && !HasFlag(wxLC_NO_HEADER
))
3157 m_headerWin
->GetPosition( &x
, &y
);
3158 m_headerWin
->GetSize( &w
, &h
);
3159 if ((x
!= 0) || (y
!= 0) || (w
!= cw
) || (h
!= 23))
3160 m_headerWin
->SetSize( 0, 0, cw
, 23 );
3162 m_mainWin
->GetPosition( &x
, &y
);
3163 m_mainWin
->GetSize( &w
, &h
);
3164 if ((x
!= 0) || (y
!= 24) || (w
!= cw
) || (h
!= ch
-24))
3165 m_mainWin
->SetSize( 0, 24, cw
, ch
-24 );
3169 m_mainWin
->GetPosition( &x
, &y
);
3170 m_mainWin
->GetSize( &w
, &h
);
3171 if ((x
!= 0) || (y
!= 24) || (w
!= cw
) || (h
!= ch
))
3172 m_mainWin
->SetSize( 0, 0, cw
, ch
);
3175 m_mainWin
->CalculatePositions();
3176 m_mainWin
->RealizeChanges();
3177 m_mainWin
->m_dirty
= FALSE
;
3178 m_mainWin
->Refresh();
3181 bool wxListCtrl::SetBackgroundColour( const wxColour
&colour
)
3183 if ( !wxWindow::SetBackgroundColour( colour
) )
3188 m_mainWin
->SetBackgroundColour( colour
);
3189 m_mainWin
->m_dirty
= TRUE
;
3194 // m_headerWin->SetBackgroundColour( colour );
3200 bool wxListCtrl::SetForegroundColour( const wxColour
&colour
)
3202 if ( !wxWindow::SetForegroundColour( colour
) )
3207 m_mainWin
->SetForegroundColour( colour
);
3208 m_mainWin
->m_dirty
= TRUE
;
3213 m_headerWin
->SetForegroundColour( colour
);
3219 bool wxListCtrl::SetFont( const wxFont
&font
)
3221 if ( !wxWindow::SetFont( font
) )
3226 m_mainWin
->SetFont( font
);
3227 m_mainWin
->m_dirty
= TRUE
;
3232 m_headerWin
->SetFont( font
);