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())
324 m_owner
->GetImageSize( item
->GetImage(), w
, h
);
325 m_bound_all
.width
+= 4 + w
;
326 if (h
> m_bound_all
.height
) m_bound_all
.height
= h
;
333 m_bound_all
.width
= 0;
334 m_bound_all
.height
= 0;
335 wxNode
*node
= m_items
.First();
338 wxListItemData
*item
= (wxListItemData
*)node
->Data();
341 if (s
.IsNull()) s
= "H";
343 dc
->GetTextExtent( s
, &lw
, &lh
);
344 item
->SetSize( item
->GetWidth(), lh
);
345 m_bound_all
.width
+= lw
;
346 m_bound_all
.height
= lh
;
354 void wxListLineData::SetPosition( wxDC
*dc
, int x
, int y
, int window_width
)
362 AssignRect( m_bound_icon
, 0, 0, 0, 0 );
363 AssignRect( m_bound_label
, 0, 0, 0, 0 );
364 AssignRect( m_bound_hilight
, m_bound_all
);
365 wxNode
*node
= m_items
.First();
368 wxListItemData
*item
= (wxListItemData
*)node
->Data();
369 if (item
->HasImage())
371 wxListItemData
*item
= (wxListItemData
*)node
->Data();
374 m_owner
->GetImageSize( item
->GetImage(), w
, h
);
375 m_bound_icon
.x
= m_bound_all
.x
+ (m_spacing
/2) - (w
/2);
376 m_bound_icon
.y
= m_bound_all
.y
+ m_spacing
- h
- 5;
377 m_bound_icon
.width
= w
;
378 m_bound_icon
.height
= h
;
379 if (!item
->HasText())
381 AssignRect( m_bound_hilight
, m_bound_icon
);
382 m_bound_hilight
.x
-= 5;
383 m_bound_hilight
.y
-= 5;
384 m_bound_hilight
.width
+= 9;
385 m_bound_hilight
.height
+= 9;
393 dc
->GetTextExtent( s
, &lw
, &lh
);
394 if (m_bound_all
.width
> m_spacing
)
395 m_bound_label
.x
= m_bound_all
.x
;
397 m_bound_label
.x
= m_bound_all
.x
+ (m_spacing
/2) - lw
/2;
398 m_bound_label
.y
= m_bound_all
.y
+ m_bound_all
.height
- lh
;
399 m_bound_label
.width
= lw
;
400 m_bound_label
.height
= lh
;
401 AssignRect( m_bound_hilight
, m_bound_label
);
402 m_bound_hilight
.x
-= 2;
403 m_bound_hilight
.y
-= 2;
404 m_bound_hilight
.width
+= 4;
405 m_bound_hilight
.height
+= 4;
412 AssignRect( m_bound_label
, m_bound_all
);
415 m_bound_all
.width
+= 4;
416 m_bound_all
.height
+= 3;
417 AssignRect( m_bound_hilight
, m_bound_all
);
418 AssignRect( m_bound_icon
, 0, 0, 0, 0 );
419 wxNode
*node
= m_items
.First();
422 wxListItemData
*item
= (wxListItemData
*)node
->Data();
423 if (item
->HasImage())
425 m_bound_icon
.x
= m_bound_all
.x
+ 2;
426 m_bound_icon
.y
= m_bound_all
.y
+ 2;
429 m_owner
->GetImageSize( item
->GetImage(), w
, h
);
430 m_bound_icon
.width
= w
;
431 m_bound_icon
.height
= h
;
432 m_bound_label
.x
+= 4 + w
;
433 m_bound_label
.width
-= 4 + w
;
441 dc
->GetTextExtent( "H", &lw
, &lh
);
444 m_bound_all
.height
= lh
+3;
445 m_bound_all
.width
= window_width
;
446 AssignRect( m_bound_hilight
, m_bound_all
);
447 AssignRect( m_bound_label
, m_bound_all
);
448 AssignRect( m_bound_icon
, 0, 0, 0, 0 );
449 wxNode
*node
= m_items
.First();
452 wxListItemData
*item
= (wxListItemData
*)node
->Data();
455 if (s
.IsEmpty()) s
= wxT("H");
457 dc
->GetTextExtent( s
, &lw
, &lh
);
458 m_bound_label
.width
= lw
;
459 m_bound_label
.height
= lh
;
460 if (item
->HasImage())
462 m_bound_icon
.x
= m_bound_all
.x
+ 2;
463 m_bound_icon
.y
= m_bound_all
.y
+ 2;
466 m_owner
->GetImageSize( item
->GetImage(), w
, h
);
467 m_bound_icon
.width
= w
;
468 m_bound_icon
.height
= h
;
469 m_bound_label
.x
+= 4 + w
;
477 void wxListLineData::SetColumnPosition( int index
, int x
)
479 wxNode
*node
= m_items
.Nth( (size_t)index
);
482 wxListItemData
*item
= (wxListItemData
*)node
->Data();
483 item
->SetPosition( x
, m_bound_all
.y
+1 );
487 void wxListLineData::GetSize( int &width
, int &height
)
489 width
= m_bound_all
.width
;
490 height
= m_bound_all
.height
;
493 void wxListLineData::GetExtent( int &x
, int &y
, int &width
, int &height
)
497 width
= m_bound_all
.width
;
498 height
= m_bound_all
.height
;
501 void wxListLineData::GetLabelExtent( int &x
, int &y
, int &width
, int &height
)
505 width
= m_bound_label
.width
;
506 height
= m_bound_label
.height
;
509 void wxListLineData::GetRect( wxRect
&rect
)
511 AssignRect( rect
, m_bound_all
);
514 long wxListLineData::IsHit( int x
, int y
)
516 wxNode
*node
= m_items
.First();
519 wxListItemData
*item
= (wxListItemData
*)node
->Data();
520 if (item
->HasImage() && IsInRect( x
, y
, m_bound_icon
)) return wxLIST_HITTEST_ONITEMICON
;
521 if (item
->HasText() && IsInRect( x
, y
, m_bound_label
)) return wxLIST_HITTEST_ONITEMLABEL
;
522 // if (!(item->HasImage() || item->HasText())) return 0;
524 // if there is no icon or text = empty
525 if (IsInRect( x
, y
, m_bound_all
)) return wxLIST_HITTEST_ONITEMICON
;
529 void wxListLineData::InitItems( int num
)
531 for (int i
= 0; i
< num
; i
++) m_items
.Append( new wxListItemData() );
534 void wxListLineData::SetItem( int index
, const wxListItem
&info
)
536 wxNode
*node
= m_items
.Nth( index
);
539 wxListItemData
*item
= (wxListItemData
*)node
->Data();
540 item
->SetItem( info
);
544 void wxListLineData::GetItem( int index
, wxListItem
&info
)
547 wxNode
*node
= m_items
.Nth( i
);
550 wxListItemData
*item
= (wxListItemData
*)node
->Data();
551 item
->GetItem( info
);
555 void wxListLineData::GetText( int index
, wxString
&s
)
558 wxNode
*node
= m_items
.Nth( i
);
562 wxListItemData
*item
= (wxListItemData
*)node
->Data();
567 void wxListLineData::SetText( int index
, const wxString s
)
570 wxNode
*node
= m_items
.Nth( i
);
573 wxListItemData
*item
= (wxListItemData
*)node
->Data();
578 int wxListLineData::GetImage( int index
)
581 wxNode
*node
= m_items
.Nth( i
);
584 wxListItemData
*item
= (wxListItemData
*)node
->Data();
585 return item
->GetImage();
590 void wxListLineData::SetAttributes(wxDC
*dc
,
591 const wxListItemAttr
*attr
,
592 const wxColour
& colText
,
596 // don't use foregroud colour for drawing highlighted items - this might
597 // make them completely invisible (and there is no way to do bit
598 // arithmetics on wxColour, unfortunately)
599 if ( !hilight
&& attr
&& attr
->HasTextColour() )
601 dc
->SetTextForeground(attr
->GetTextColour());
605 dc
->SetTextForeground(colText
);
608 if ( attr
&& attr
->HasFont() )
610 dc
->SetFont(attr
->GetFont());
618 void wxListLineData::DoDraw( wxDC
*dc
, bool hilight
, bool paintBG
)
620 wxCoord dev_x
= dc
->LogicalToDeviceX( m_bound_all
.x
-2 );
621 wxCoord dev_y
= dc
->LogicalToDeviceY( m_bound_all
.y
-2 );
622 wxCoord dev_w
= dc
->LogicalToDeviceXRel( m_bound_all
.width
+4 );
623 wxCoord dev_h
= dc
->LogicalToDeviceYRel( m_bound_all
.height
+4 );
625 if (!m_owner
->IsExposed( dev_x
, dev_y
, dev_w
, dev_h
))
630 wxWindow
*listctrl
= m_owner
->GetParent();
632 // default foreground colour
636 colText
= wxSystemSettings::GetSystemColour( wxSYS_COLOUR_HIGHLIGHTTEXT
);
640 colText
= listctrl
->GetForegroundColour();
644 wxFont font
= listctrl
->GetFont();
646 // VZ: currently we set the colours/fonts only once, but like this (i.e.
647 // using SetAttributes() inside the loop), it will be trivial to
648 // customize the subitems (in report mode) too.
649 wxListItemData
*item
= (wxListItemData
*)m_items
.First()->Data();
650 wxListItemAttr
*attr
= item
->GetAttributes();
651 SetAttributes(dc
, attr
, colText
, font
, hilight
);
653 bool hasBgCol
= attr
&& attr
->HasBackgroundColour();
654 if ( paintBG
|| hasBgCol
)
658 dc
->SetBrush( * m_hilightBrush
);
663 dc
->SetBrush(wxBrush(attr
->GetBackgroundColour(), wxSOLID
));
665 dc
->SetBrush( * wxWHITE_BRUSH
);
668 dc
->SetPen( * wxTRANSPARENT_PEN
);
669 dc
->DrawRectangle( m_bound_hilight
.x
, m_bound_hilight
.y
,
670 m_bound_hilight
.width
, m_bound_hilight
.height
);
673 if (m_mode
== wxLC_REPORT
)
675 wxNode
*node
= m_items
.First();
678 wxListItemData
*item
= (wxListItemData
*)node
->Data();
679 dc
->SetClippingRegion( item
->GetX(), item
->GetY(), item
->GetWidth()-3, item
->GetHeight() );
680 int x
= item
->GetX();
681 if (item
->HasImage())
684 m_owner
->DrawImage( item
->GetImage(), dc
, x
, item
->GetY() );
685 m_owner
->GetImageSize( item
->GetImage(), x
, y
);
686 x
+= item
->GetX() + 5;
690 dc
->DrawText( item
->GetText(), x
, item
->GetY() );
692 dc
->DestroyClippingRegion();
698 wxNode
*node
= m_items
.First();
701 wxListItemData
*item
= (wxListItemData
*)node
->Data();
702 if (item
->HasImage())
704 m_owner
->DrawImage( item
->GetImage(), dc
, m_bound_icon
.x
, m_bound_icon
.y
);
708 dc
->DrawText( item
->GetText(), m_bound_label
.x
, m_bound_label
.y
);
714 void wxListLineData::Hilight( bool on
)
716 if (on
== m_hilighted
) return;
719 m_owner
->SelectLine( this );
721 m_owner
->DeselectLine( this );
724 void wxListLineData::ReverseHilight( void )
726 m_hilighted
= !m_hilighted
;
728 m_owner
->SelectLine( this );
730 m_owner
->DeselectLine( this );
733 void wxListLineData::DrawRubberBand( wxDC
*dc
, bool on
)
737 dc
->SetPen( * wxBLACK_PEN
);
738 dc
->SetBrush( * wxTRANSPARENT_BRUSH
);
739 dc
->DrawRectangle( m_bound_hilight
.x
, m_bound_hilight
.y
,
740 m_bound_hilight
.width
, m_bound_hilight
.height
);
744 void wxListLineData::Draw( wxDC
*dc
)
746 DoDraw( dc
, m_hilighted
, m_hilighted
);
749 bool wxListLineData::IsInRect( int x
, int y
, const wxRect
&rect
)
751 return ((x
>= rect
.x
) && (x
<= rect
.x
+rect
.width
) &&
752 (y
>= rect
.y
) && (y
<= rect
.y
+rect
.height
));
755 bool wxListLineData::IsHilighted( void )
760 void wxListLineData::AssignRect( wxRect
&dest
, int x
, int y
, int width
, int height
)
765 dest
.height
= height
;
768 void wxListLineData::AssignRect( wxRect
&dest
, const wxRect
&source
)
772 dest
.width
= source
.width
;
773 dest
.height
= source
.height
;
776 //-----------------------------------------------------------------------------
777 // wxListHeaderWindow
778 //-----------------------------------------------------------------------------
780 IMPLEMENT_DYNAMIC_CLASS(wxListHeaderWindow
,wxWindow
);
782 BEGIN_EVENT_TABLE(wxListHeaderWindow
,wxWindow
)
783 EVT_PAINT (wxListHeaderWindow::OnPaint
)
784 EVT_MOUSE_EVENTS (wxListHeaderWindow::OnMouse
)
785 EVT_SET_FOCUS (wxListHeaderWindow::OnSetFocus
)
788 wxListHeaderWindow::wxListHeaderWindow( void )
790 m_owner
= (wxListMainWindow
*) NULL
;
791 m_currentCursor
= (wxCursor
*) NULL
;
792 m_resizeCursor
= (wxCursor
*) NULL
;
793 m_isDragging
= FALSE
;
796 wxListHeaderWindow::wxListHeaderWindow( wxWindow
*win
, wxWindowID id
, wxListMainWindow
*owner
,
797 const wxPoint
&pos
, const wxSize
&size
,
798 long style
, const wxString
&name
) :
799 wxWindow( win
, id
, pos
, size
, style
, name
)
802 // m_currentCursor = wxSTANDARD_CURSOR;
803 m_currentCursor
= (wxCursor
*) NULL
;
804 m_resizeCursor
= new wxCursor( wxCURSOR_SIZEWE
);
805 m_isDragging
= FALSE
;
806 SetBackgroundColour( wxSystemSettings::GetSystemColour( wxSYS_COLOUR_BTNFACE
) );
809 wxListHeaderWindow::~wxListHeaderWindow( void )
811 delete m_resizeCursor
;
814 void wxListHeaderWindow::DoDrawRect( wxDC
*dc
, int x
, int y
, int w
, int h
)
816 const int m_corner
= 1;
818 dc
->SetBrush( *wxTRANSPARENT_BRUSH
);
820 dc
->SetPen( *wxBLACK_PEN
);
821 dc
->DrawLine( x
+w
-m_corner
+1, y
, x
+w
, y
+h
); // right (outer)
822 dc
->DrawRectangle( x
, y
+h
, w
+1, 1 ); // bottom (outer)
824 wxPen
pen( wxSystemSettings::GetSystemColour( wxSYS_COLOUR_BTNSHADOW
), 1, wxSOLID
);
827 dc
->DrawLine( x
+w
-m_corner
, y
, x
+w
-1, y
+h
); // right (inner)
828 dc
->DrawRectangle( x
+1, y
+h
-1, w
-2, 1 ); // bottom (inner)
830 dc
->SetPen( *wxWHITE_PEN
);
831 dc
->DrawRectangle( x
, y
, w
-m_corner
+1, 1 ); // top (outer)
832 dc
->DrawRectangle( x
, y
, 1, h
); // left (outer)
833 dc
->DrawLine( x
, y
+h
-1, x
+1, y
+h
-1 );
834 dc
->DrawLine( x
+w
-1, y
, x
+w
-1, y
+1 );
837 void wxListHeaderWindow::OnPaint( wxPaintEvent
&WXUNUSED(event
) )
839 wxPaintDC
dc( this );
841 #if wxUSE_GENERIC_LIST_EXTENSIONS
842 if ( m_owner
->GetMode() & wxLC_REPORT
)
847 m_owner
->GetScrollPixelsPerUnit( &xpix
, &ypix
) ;
848 m_owner
->ViewStart( &x
, &y
) ;
849 dc
.SetDeviceOrigin( -x
* xpix
, 0 );
854 dc
.SetFont( GetFont() );
860 GetClientSize( &w
, &h
);
862 dc
.SetBackgroundMode(wxTRANSPARENT
);
863 dc
.SetTextForeground( *wxBLACK
);
865 // do *not* use the listctrl colour for headers - one day we will have a
866 // function to set it separately
870 int numColumns
= m_owner
->GetColumnCount();
872 for (int i
= 0; i
< numColumns
; i
++)
874 m_owner
->GetColumn( i
, item
);
875 int cw
= item
.m_width
-2;
876 #if wxUSE_GENERIC_LIST_EXTENSIONS
877 if ((i
+1 == numColumns
) || ( dc
.LogicalToDeviceX(x
+item
.m_width
) > w
-5))
878 cw
= dc
.DeviceToLogicalX(w
)-x
-1;
880 if ((i
+1 == numColumns
) || (x
+item
.m_width
> w
-5))
883 dc
.SetPen( *wxWHITE_PEN
);
885 DoDrawRect( &dc
, x
, y
, cw
, h
-2 );
886 dc
.SetClippingRegion( x
, y
, cw
-5, h
-4 );
887 dc
.DrawText( item
.m_text
, x
+4, y
+3 );
888 dc
.DestroyClippingRegion();
890 #if wxUSE_GENERIC_LIST_EXTENSIONS
891 if (dc
.LogicalToDeviceX(x
) > w
+5) break;
899 void wxListHeaderWindow::DrawCurrent()
903 int x2
= m_currentX
-1;
906 m_owner
->GetClientSize( &dummy
, &y2
);
907 ClientToScreen( &x1
, &y1
);
908 m_owner
->ClientToScreen( &x2
, &y2
);
911 dc
.SetLogicalFunction( wxINVERT
);
912 dc
.SetPen( wxPen( *wxBLACK
, 2, wxSOLID
) );
913 dc
.SetBrush( *wxTRANSPARENT_BRUSH
);
915 dc
.DrawLine( x1
, y1
, x2
, y2
);
917 dc
.SetLogicalFunction( wxCOPY
);
919 dc
.SetPen( wxNullPen
);
920 dc
.SetBrush( wxNullBrush
);
923 void wxListHeaderWindow::OnMouse( wxMouseEvent
&event
)
925 wxCoord x
= (wxCoord
)event
.GetX();
926 wxCoord y
= (wxCoord
)event
.GetY();
930 if (event
.ButtonUp())
933 m_isDragging
= FALSE
;
934 m_owner
->SetColumnWidth( m_column
, m_currentX
-m_minX
);
940 GetClientSize( &size_x
, & dummy
);
944 m_currentX
= m_minX
+7;
945 if (m_currentX
> size_x
-7) m_currentX
= size_x
-7;
952 bool hit_border
= FALSE
;
954 for (int j
= 0; j
< m_owner
->GetColumnCount()-1; j
++)
956 xpos
+= m_owner
->GetColumnWidth( j
);
958 if ((abs(x
-xpos
) < 3) && (y
< 22))
970 if (event
.LeftDown())
982 wxListEvent
le( wxEVT_COMMAND_LIST_COL_CLICK
, GetParent()->GetId() );
983 le
.SetEventObject( GetParent() );
985 GetParent()->GetEventHandler()->ProcessEvent( le
);
994 if (m_currentCursor
== wxSTANDARD_CURSOR
) SetCursor( * m_resizeCursor
);
995 m_currentCursor
= m_resizeCursor
;
999 if (m_currentCursor
!= wxSTANDARD_CURSOR
) SetCursor( * wxSTANDARD_CURSOR
);
1000 m_currentCursor
= wxSTANDARD_CURSOR
;
1005 void wxListHeaderWindow::OnSetFocus( wxFocusEvent
&WXUNUSED(event
) )
1007 m_owner
->SetFocus();
1010 //-----------------------------------------------------------------------------
1011 // wxListRenameTimer (internal)
1012 //-----------------------------------------------------------------------------
1014 wxListRenameTimer::wxListRenameTimer( wxListMainWindow
*owner
)
1019 void wxListRenameTimer::Notify()
1021 m_owner
->OnRenameTimer();
1024 //-----------------------------------------------------------------------------
1025 // wxListTextCtrl (internal)
1026 //-----------------------------------------------------------------------------
1028 IMPLEMENT_DYNAMIC_CLASS(wxListTextCtrl
,wxTextCtrl
);
1030 BEGIN_EVENT_TABLE(wxListTextCtrl
,wxTextCtrl
)
1031 EVT_CHAR (wxListTextCtrl::OnChar
)
1032 EVT_KILL_FOCUS (wxListTextCtrl::OnKillFocus
)
1035 wxListTextCtrl::wxListTextCtrl( wxWindow
*parent
,
1036 const wxWindowID id
,
1039 wxListMainWindow
*owner
,
1040 const wxString
&value
,
1044 const wxValidator
& validator
,
1045 const wxString
&name
)
1046 : wxTextCtrl( parent
, id
, value
, pos
, size
, style
, validator
, name
)
1051 (*m_accept
) = FALSE
;
1053 m_startValue
= value
;
1056 void wxListTextCtrl::OnChar( wxKeyEvent
&event
)
1058 if (event
.m_keyCode
== WXK_RETURN
)
1061 (*m_res
) = GetValue();
1062 m_owner
->SetFocus();
1065 if (event
.m_keyCode
== WXK_ESCAPE
)
1067 (*m_accept
) = FALSE
;
1069 m_owner
->SetFocus();
1075 void wxListTextCtrl::OnKillFocus( wxFocusEvent
&WXUNUSED(event
) )
1077 if (wxPendingDelete
.Member(this)) return;
1079 wxPendingDelete
.Append(this);
1081 if ((*m_accept
) && ((*m_res
) != m_startValue
))
1082 m_owner
->OnRenameAccept();
1085 //-----------------------------------------------------------------------------
1087 //-----------------------------------------------------------------------------
1089 IMPLEMENT_DYNAMIC_CLASS(wxListMainWindow
,wxScrolledWindow
);
1091 BEGIN_EVENT_TABLE(wxListMainWindow
,wxScrolledWindow
)
1092 EVT_PAINT (wxListMainWindow::OnPaint
)
1093 EVT_SIZE (wxListMainWindow::OnSize
)
1094 EVT_MOUSE_EVENTS (wxListMainWindow::OnMouse
)
1095 EVT_CHAR (wxListMainWindow::OnChar
)
1096 EVT_KEY_DOWN (wxListMainWindow::OnKeyDown
)
1097 EVT_SET_FOCUS (wxListMainWindow::OnSetFocus
)
1098 EVT_KILL_FOCUS (wxListMainWindow::OnKillFocus
)
1099 EVT_SCROLLWIN (wxListMainWindow::OnScroll
)
1102 wxListMainWindow::wxListMainWindow()
1105 m_lines
.DeleteContents( TRUE
);
1106 m_columns
.DeleteContents( TRUE
);
1107 m_current
= (wxListLineData
*) NULL
;
1109 m_hilightBrush
= (wxBrush
*) NULL
;
1113 m_small_image_list
= (wxImageList
*) NULL
;
1114 m_normal_image_list
= (wxImageList
*) NULL
;
1115 m_small_spacing
= 30;
1116 m_normal_spacing
= 40;
1119 m_lastOnSame
= FALSE
;
1120 m_renameTimer
= new wxListRenameTimer( this );
1121 m_isCreated
= FALSE
;
1125 wxListMainWindow::wxListMainWindow( wxWindow
*parent
, wxWindowID id
,
1126 const wxPoint
&pos
, const wxSize
&size
,
1127 long style
, const wxString
&name
) :
1128 wxScrolledWindow( parent
, id
, pos
, size
, style
|wxHSCROLL
|wxVSCROLL
, name
)
1131 m_lines
.DeleteContents( TRUE
);
1132 m_columns
.DeleteContents( TRUE
);
1133 m_current
= (wxListLineData
*) NULL
;
1136 m_hilightBrush
= new wxBrush( wxSystemSettings::GetSystemColour(wxSYS_COLOUR_HIGHLIGHT
), wxSOLID
);
1137 m_small_image_list
= (wxImageList
*) NULL
;
1138 m_normal_image_list
= (wxImageList
*) NULL
;
1139 m_small_spacing
= 30;
1140 m_normal_spacing
= 40;
1143 m_isCreated
= FALSE
;
1147 if (m_mode
& wxLC_REPORT
)
1149 #if wxUSE_GENERIC_LIST_EXTENSIONS
1161 SetScrollbars( m_xScroll
, m_yScroll
, 0, 0, 0, 0 );
1164 m_lastOnSame
= FALSE
;
1165 m_renameTimer
= new wxListRenameTimer( this );
1166 m_renameAccept
= FALSE
;
1168 SetBackgroundColour( *wxWHITE
);
1171 wxListMainWindow::~wxListMainWindow()
1173 if (m_hilightBrush
) delete m_hilightBrush
;
1175 delete m_renameTimer
;
1178 void wxListMainWindow::RefreshLine( wxListLineData
*line
)
1180 if (m_dirty
) return;
1188 wxClientDC
dc(this);
1190 line
->GetExtent( x
, y
, w
, h
);
1192 dc
.LogicalToDeviceX(x
-3),
1193 dc
.LogicalToDeviceY(y
-3),
1194 dc
.LogicalToDeviceXRel(w
+6),
1195 dc
.LogicalToDeviceXRel(h
+6) );
1196 Refresh( TRUE
, &rect
);
1200 void wxListMainWindow::OnPaint( wxPaintEvent
&WXUNUSED(event
) )
1202 // Note: a wxPaintDC must be constructed even if no drawing is
1203 // done (a Windows requirement).
1204 wxPaintDC
dc( this );
1207 if (m_dirty
) return;
1209 if (m_lines
.GetCount() == 0) return;
1213 dc
.SetFont( GetFont() );
1215 if (m_mode
& wxLC_REPORT
)
1217 int lineSpacing
= 0;
1218 wxListLineData
*line
= (wxListLineData
*)m_lines
.First()->Data();
1220 line
->GetSize( dummy
, lineSpacing
);
1223 int y_s
= m_yScroll
*GetScrollPos( wxVERTICAL
);
1225 wxNode
*node
= m_lines
.Nth( y_s
/ lineSpacing
);
1226 for (int i
= 0; i
< m_visibleLines
+2; i
++)
1230 line
= (wxListLineData
*)node
->Data();
1232 node
= node
->Next();
1237 wxNode
*node
= m_lines
.First();
1240 wxListLineData
*line
= (wxListLineData
*)node
->Data();
1242 node
= node
->Next();
1246 if (m_current
) m_current
->DrawRubberBand( &dc
, m_hasFocus
);
1251 void wxListMainWindow::HilightAll( bool on
)
1253 wxNode
*node
= m_lines
.First();
1256 wxListLineData
*line
= (wxListLineData
*)node
->Data();
1257 if (line
->IsHilighted() != on
)
1259 line
->Hilight( on
);
1260 RefreshLine( line
);
1262 node
= node
->Next();
1266 void wxListMainWindow::SendNotify( wxListLineData
*line
, wxEventType command
)
1268 wxListEvent
le( command
, GetParent()->GetId() );
1269 le
.SetEventObject( GetParent() );
1270 le
.m_itemIndex
= GetIndexOfLine( line
);
1271 line
->GetItem( 0, le
.m_item
);
1272 GetParent()->GetEventHandler()->ProcessEvent( le
);
1273 // GetParent()->GetEventHandler()->AddPendingEvent( le );
1276 void wxListMainWindow::FocusLine( wxListLineData
*WXUNUSED(line
) )
1278 // SendNotify( line, wxEVT_COMMAND_LIST_ITEM_FOCUSSED );
1281 void wxListMainWindow::UnfocusLine( wxListLineData
*WXUNUSED(line
) )
1283 // SendNotify( line, wxEVT_COMMAND_LIST_ITEM_UNFOCUSSED );
1286 void wxListMainWindow::SelectLine( wxListLineData
*line
)
1288 SendNotify( line
, wxEVT_COMMAND_LIST_ITEM_SELECTED
);
1291 void wxListMainWindow::DeselectLine( wxListLineData
*line
)
1293 SendNotify( line
, wxEVT_COMMAND_LIST_ITEM_DESELECTED
);
1296 void wxListMainWindow::DeleteLine( wxListLineData
*line
)
1298 SendNotify( line
, wxEVT_COMMAND_LIST_DELETE_ITEM
);
1303 void wxListMainWindow::EditLabel( long item
)
1305 wxNode
*node
= m_lines
.Nth( (size_t)item
);
1306 wxCHECK_RET( node
, wxT("wrong index in wxListCtrl::Edit()") );
1308 m_currentEdit
= (wxListLineData
*) node
->Data();
1310 wxListEvent
le( wxEVT_COMMAND_LIST_BEGIN_LABEL_EDIT
, GetParent()->GetId() );
1311 le
.SetEventObject( GetParent() );
1312 le
.m_itemIndex
= GetIndexOfLine( m_currentEdit
);
1313 m_currentEdit
->GetItem( 0, le
.m_item
);
1314 GetParent()->GetEventHandler()->ProcessEvent( le
);
1316 if (!le
.IsAllowed())
1319 // We have to call this here because the label in
1320 // question might just have been added and no screen
1321 // update taken place.
1322 if (m_dirty
) wxYield();
1325 m_currentEdit
->GetText( 0, s
);
1330 m_currentEdit
->GetLabelExtent( x
, y
, w
, h
);
1332 wxClientDC
dc(this);
1334 x
= dc
.LogicalToDeviceX( x
);
1335 y
= dc
.LogicalToDeviceY( y
);
1337 wxListTextCtrl
*text
= new wxListTextCtrl(
1338 this, -1, &m_renameAccept
, &m_renameRes
, this, s
, wxPoint(x
-4,y
-4), wxSize(w
+11,h
+8) );
1342 void wxListMainWindow::OnRenameTimer()
1344 wxCHECK_RET( m_current
, wxT("invalid m_current") );
1346 Edit( m_lines
.IndexOf( m_current
) );
1349 void wxListMainWindow::OnRenameAccept()
1351 wxListEvent
le( wxEVT_COMMAND_LIST_END_LABEL_EDIT
, GetParent()->GetId() );
1352 le
.SetEventObject( GetParent() );
1353 le
.m_itemIndex
= GetIndexOfLine( m_currentEdit
);
1354 m_currentEdit
->GetItem( 0, le
.m_item
);
1355 le
.m_item
.m_text
= m_renameRes
;
1356 GetParent()->GetEventHandler()->ProcessEvent( le
);
1358 if (!le
.IsAllowed()) return;
1361 info
.m_mask
= wxLIST_MASK_TEXT
;
1362 info
.m_itemId
= le
.m_itemIndex
;
1363 info
.m_text
= m_renameRes
;
1364 info
.SetTextColour(le
.m_item
.GetTextColour());
1368 void wxListMainWindow::OnMouse( wxMouseEvent
&event
)
1370 if (GetParent()->GetEventHandler()->ProcessEvent( event
)) return;
1372 if (!m_current
) return;
1373 if (m_dirty
) return;
1374 if ( !(event
.Dragging() || event
.ButtonDown() || event
.LeftUp() || event
.ButtonDClick()) ) return;
1376 wxClientDC
dc(this);
1378 wxCoord x
= dc
.DeviceToLogicalX( (wxCoord
)event
.GetX() );
1379 wxCoord y
= dc
.DeviceToLogicalY( (wxCoord
)event
.GetY() );
1381 /* Did we actually hit an item ? */
1383 wxNode
*node
= m_lines
.First();
1384 wxListLineData
*line
= (wxListLineData
*) NULL
;
1387 line
= (wxListLineData
*)node
->Data();
1388 hitResult
= line
->IsHit( x
, y
);
1389 if (hitResult
) break;
1390 line
= (wxListLineData
*) NULL
;
1391 node
= node
->Next();
1394 if (event
.Dragging())
1396 if (m_dragCount
== 0)
1397 m_dragStart
= wxPoint(x
,y
);
1401 if (m_dragCount
!= 3) return;
1403 int command
= wxEVT_COMMAND_LIST_BEGIN_DRAG
;
1404 if (event
.RightIsDown()) command
= wxEVT_COMMAND_LIST_BEGIN_RDRAG
;
1406 wxListEvent
le( command
, GetParent()->GetId() );
1407 le
.SetEventObject( GetParent() );
1408 le
.m_pointDrag
= m_dragStart
;
1409 GetParent()->GetEventHandler()->ProcessEvent( le
);
1420 if (event
.ButtonDClick())
1423 m_lastOnSame
= FALSE
;
1424 m_renameTimer
->Stop();
1426 SendNotify( line
, wxEVT_COMMAND_LIST_ITEM_ACTIVATED
);
1431 if (event
.LeftUp() && m_lastOnSame
)
1434 if ((line
== m_current
) &&
1435 (hitResult
== wxLIST_HITTEST_ONITEMLABEL
) &&
1436 (m_mode
& wxLC_EDIT_LABELS
) )
1438 m_renameTimer
->Start( 100, TRUE
);
1440 m_lastOnSame
= FALSE
;
1444 if (event
.RightDown())
1446 SendNotify( line
, wxEVT_COMMAND_LIST_ITEM_RIGHT_CLICK
);
1450 if (event
.MiddleDown())
1452 SendNotify( line
, wxEVT_COMMAND_LIST_ITEM_MIDDLE_CLICK
);
1456 if (event
.LeftDown())
1459 wxListLineData
*oldCurrent
= m_current
;
1460 if (m_mode
& wxLC_SINGLE_SEL
)
1463 HilightAll( FALSE
);
1464 m_current
->ReverseHilight();
1465 RefreshLine( m_current
);
1469 if (event
.ShiftDown())
1472 m_current
->ReverseHilight();
1473 RefreshLine( m_current
);
1475 else if (event
.ControlDown())
1479 int numOfCurrent
= -1;
1480 node
= m_lines
.First();
1483 wxListLineData
*test_line
= (wxListLineData
*)node
->Data();
1485 if (test_line
== oldCurrent
) break;
1486 node
= node
->Next();
1490 node
= m_lines
.First();
1493 wxListLineData
*test_line
= (wxListLineData
*)node
->Data();
1495 if (test_line
== line
) break;
1496 node
= node
->Next();
1499 if (numOfLine
< numOfCurrent
)
1502 numOfLine
= numOfCurrent
;
1506 wxNode
*node
= m_lines
.Nth( numOfCurrent
);
1507 for (int i
= 0; i
<= numOfLine
-numOfCurrent
; i
++)
1509 wxListLineData
*test_line
= (wxListLineData
*)node
->Data();
1510 test_line
->Hilight(TRUE
);
1511 RefreshLine( test_line
);
1512 node
= node
->Next();
1518 HilightAll( FALSE
);
1519 m_current
->ReverseHilight();
1520 RefreshLine( m_current
);
1523 if (m_current
!= oldCurrent
)
1525 RefreshLine( oldCurrent
);
1526 UnfocusLine( oldCurrent
);
1527 FocusLine( m_current
);
1529 m_lastOnSame
= (m_current
== oldCurrent
);
1534 void wxListMainWindow::MoveToFocus()
1536 if (!m_current
) return;
1542 m_current
->GetExtent( item_x
, item_y
, item_w
, item_h
);
1546 GetClientSize( &client_w
, &client_h
);
1548 int view_x
= m_xScroll
*GetScrollPos( wxHORIZONTAL
);
1549 int view_y
= m_yScroll
*GetScrollPos( wxVERTICAL
);
1551 if (m_mode
& wxLC_REPORT
)
1553 if (item_y
-5 < view_y
)
1554 Scroll( -1, (item_y
-5)/m_yScroll
);
1555 if (item_y
+item_h
+5 > view_y
+client_h
)
1556 Scroll( -1, (item_y
+item_h
-client_h
+15)/m_yScroll
);
1560 if (item_x
-view_x
< 5)
1561 Scroll( (item_x
-5)/m_xScroll
, -1 );
1562 if (item_x
+item_w
-5 > view_x
+client_w
)
1563 Scroll( (item_x
+item_w
-client_w
+15)/m_xScroll
, -1 );
1567 void wxListMainWindow::OnArrowChar( wxListLineData
*newCurrent
, bool shiftDown
)
1569 if ((m_mode
& wxLC_SINGLE_SEL
) || (m_usedKeys
== FALSE
)) m_current
->Hilight( FALSE
);
1570 wxListLineData
*oldCurrent
= m_current
;
1571 m_current
= newCurrent
;
1572 if (shiftDown
|| (m_mode
& wxLC_SINGLE_SEL
)) m_current
->Hilight( TRUE
);
1573 RefreshLine( m_current
);
1574 RefreshLine( oldCurrent
);
1575 FocusLine( m_current
);
1576 UnfocusLine( oldCurrent
);
1580 void wxListMainWindow::OnKeyDown( wxKeyEvent
&event
)
1582 wxWindow
*parent
= GetParent();
1584 /* we propagate the key event up */
1585 wxKeyEvent
ke( wxEVT_KEY_DOWN
);
1586 ke
.m_shiftDown
= event
.m_shiftDown
;
1587 ke
.m_controlDown
= event
.m_controlDown
;
1588 ke
.m_altDown
= event
.m_altDown
;
1589 ke
.m_metaDown
= event
.m_metaDown
;
1590 ke
.m_keyCode
= event
.m_keyCode
;
1593 ke
.SetEventObject( parent
);
1594 if (parent
->GetEventHandler()->ProcessEvent( ke
)) return;
1599 void wxListMainWindow::OnChar( wxKeyEvent
&event
)
1601 wxWindow
*parent
= GetParent();
1603 /* we send a list_key event up */
1604 wxListEvent
le( wxEVT_COMMAND_LIST_KEY_DOWN
, GetParent()->GetId() );
1605 le
.m_code
= (int)event
.KeyCode();
1606 le
.SetEventObject( parent
);
1607 parent
->GetEventHandler()->ProcessEvent( le
);
1609 /* we propagate the char event up */
1610 wxKeyEvent
ke( wxEVT_CHAR
);
1611 ke
.m_shiftDown
= event
.m_shiftDown
;
1612 ke
.m_controlDown
= event
.m_controlDown
;
1613 ke
.m_altDown
= event
.m_altDown
;
1614 ke
.m_metaDown
= event
.m_metaDown
;
1615 ke
.m_keyCode
= event
.m_keyCode
;
1618 ke
.SetEventObject( parent
);
1619 if (parent
->GetEventHandler()->ProcessEvent( ke
)) return;
1621 if (event
.KeyCode() == WXK_TAB
)
1623 wxNavigationKeyEvent nevent
;
1624 nevent
.SetDirection( !event
.ShiftDown() );
1625 nevent
.SetCurrentFocus( m_parent
);
1626 if (m_parent
->GetEventHandler()->ProcessEvent( nevent
)) return;
1629 /* no item -> nothing to do */
1636 switch (event
.KeyCode())
1640 wxNode
*node
= m_lines
.Member( m_current
)->Previous();
1641 if (node
) OnArrowChar( (wxListLineData
*)node
->Data(), event
.ShiftDown() );
1646 wxNode
*node
= m_lines
.Member( m_current
)->Next();
1647 if (node
) OnArrowChar( (wxListLineData
*)node
->Data(), event
.ShiftDown() );
1652 wxNode
*node
= m_lines
.Last();
1653 OnArrowChar( (wxListLineData
*)node
->Data(), event
.ShiftDown() );
1658 wxNode
*node
= m_lines
.First();
1659 OnArrowChar( (wxListLineData
*)node
->Data(), event
.ShiftDown() );
1665 if (m_mode
& wxLC_REPORT
)
1667 steps
= m_visibleLines
-1;
1672 wxNode
*node
= m_lines
.First();
1673 for (;;) { if (m_current
== (wxListLineData
*)node
->Data()) break; pos
++; node
= node
->Next(); }
1674 steps
= pos
% m_visibleLines
;
1676 wxNode
*node
= m_lines
.Member( m_current
);
1677 for (int i
= 0; i
< steps
; i
++) if (node
->Previous()) node
= node
->Previous();
1678 if (node
) OnArrowChar( (wxListLineData
*)node
->Data(), event
.ShiftDown() );
1684 if (m_mode
& wxLC_REPORT
)
1686 steps
= m_visibleLines
-1;
1690 int pos
= 0; wxNode
*node
= m_lines
.First();
1691 for (;;) { if (m_current
== (wxListLineData
*)node
->Data()) break; pos
++; node
= node
->Next(); }
1692 steps
= m_visibleLines
-(pos
% m_visibleLines
)-1;
1694 wxNode
*node
= m_lines
.Member( m_current
);
1695 for (int i
= 0; i
< steps
; i
++) if (node
->Next()) node
= node
->Next();
1696 if (node
) OnArrowChar( (wxListLineData
*)node
->Data(), event
.ShiftDown() );
1701 if (!(m_mode
& wxLC_REPORT
))
1703 wxNode
*node
= m_lines
.Member( m_current
);
1704 for (int i
= 0; i
<m_visibleLines
; i
++) if (node
->Previous()) node
= node
->Previous();
1705 if (node
) OnArrowChar( (wxListLineData
*)node
->Data(), event
.ShiftDown() );
1711 if (!(m_mode
& wxLC_REPORT
))
1713 wxNode
*node
= m_lines
.Member( m_current
);
1714 for (int i
= 0; i
<m_visibleLines
; i
++) if (node
->Next()) node
= node
->Next();
1715 if (node
) OnArrowChar( (wxListLineData
*)node
->Data(), event
.ShiftDown() );
1721 m_current
->ReverseHilight();
1722 RefreshLine( m_current
);
1727 if (!(m_mode
& wxLC_SINGLE_SEL
))
1729 wxListLineData
*oldCurrent
= m_current
;
1730 m_current
->ReverseHilight();
1731 wxNode
*node
= m_lines
.Member( m_current
)->Next();
1732 if (node
) m_current
= (wxListLineData
*)node
->Data();
1733 RefreshLine( oldCurrent
);
1734 RefreshLine( m_current
);
1735 UnfocusLine( oldCurrent
);
1736 FocusLine( m_current
);
1744 wxListEvent
le( wxEVT_COMMAND_LIST_ITEM_ACTIVATED
, GetParent()->GetId() );
1745 le
.SetEventObject( GetParent() );
1746 le
.m_itemIndex
= GetIndexOfLine( m_current
);
1747 m_current
->GetItem( 0, le
.m_item
);
1748 GetParent()->GetEventHandler()->ProcessEvent( le
);
1761 extern wxWindow
*g_focusWindow
;
1764 void wxListMainWindow::OnSetFocus( wxFocusEvent
&WXUNUSED(event
) )
1767 RefreshLine( m_current
);
1769 if (!GetParent()) return;
1772 g_focusWindow
= GetParent();
1775 wxFocusEvent
event( wxEVT_SET_FOCUS
, GetParent()->GetId() );
1776 event
.SetEventObject( GetParent() );
1777 GetParent()->GetEventHandler()->ProcessEvent( event
);
1780 void wxListMainWindow::OnKillFocus( wxFocusEvent
&WXUNUSED(event
) )
1783 RefreshLine( m_current
);
1786 void wxListMainWindow::OnSize( wxSizeEvent
&WXUNUSED(event
) )
1789 We don't even allow the wxScrolledWindow::AdjustScrollbars() call
1794 void wxListMainWindow::DrawImage( int index
, wxDC
*dc
, int x
, int y
)
1796 if ((m_mode
& wxLC_ICON
) && (m_normal_image_list
))
1798 m_normal_image_list
->Draw( index
, *dc
, x
, y
, wxIMAGELIST_DRAW_TRANSPARENT
);
1801 if ((m_mode
& wxLC_SMALL_ICON
) && (m_small_image_list
))
1803 m_small_image_list
->Draw( index
, *dc
, x
, y
, wxIMAGELIST_DRAW_TRANSPARENT
);
1805 if ((m_mode
& wxLC_LIST
) && (m_small_image_list
))
1807 m_small_image_list
->Draw( index
, *dc
, x
, y
, wxIMAGELIST_DRAW_TRANSPARENT
);
1809 if ((m_mode
& wxLC_REPORT
) && (m_small_image_list
))
1811 m_small_image_list
->Draw( index
, *dc
, x
, y
, wxIMAGELIST_DRAW_TRANSPARENT
);
1816 void wxListMainWindow::GetImageSize( int index
, int &width
, int &height
)
1818 if ((m_mode
& wxLC_ICON
) && (m_normal_image_list
))
1820 m_normal_image_list
->GetSize( index
, width
, height
);
1823 if ((m_mode
& wxLC_SMALL_ICON
) && (m_small_image_list
))
1825 m_small_image_list
->GetSize( index
, width
, height
);
1828 if ((m_mode
& wxLC_LIST
) && (m_small_image_list
))
1830 m_small_image_list
->GetSize( index
, width
, height
);
1833 if ((m_mode
& wxLC_REPORT
) && (m_small_image_list
))
1835 m_small_image_list
->GetSize( index
, width
, height
);
1842 int wxListMainWindow::GetTextLength( wxString
&s
)
1844 wxClientDC
dc( this );
1847 dc
.GetTextExtent( s
, &lw
, &lh
);
1851 int wxListMainWindow::GetIndexOfLine( const wxListLineData
*line
)
1854 wxNode
*node
= m_lines
.First();
1857 if (line
== (wxListLineData
*)node
->Data()) return i
;
1859 node
= node
->Next();
1864 void wxListMainWindow::SetImageList( wxImageList
*imageList
, int which
)
1867 if (which
== wxIMAGE_LIST_NORMAL
) m_normal_image_list
= imageList
;
1868 if (which
== wxIMAGE_LIST_SMALL
) m_small_image_list
= imageList
;
1871 void wxListMainWindow::SetItemSpacing( int spacing
, bool isSmall
)
1876 m_small_spacing
= spacing
;
1880 m_normal_spacing
= spacing
;
1884 int wxListMainWindow::GetItemSpacing( bool isSmall
)
1886 if (isSmall
) return m_small_spacing
; else return m_normal_spacing
;
1889 void wxListMainWindow::SetColumn( int col
, wxListItem
&item
)
1892 wxNode
*node
= m_columns
.Nth( col
);
1895 if (item
.m_width
== wxLIST_AUTOSIZE_USEHEADER
) item
.m_width
= GetTextLength( item
.m_text
)+7;
1896 wxListHeaderData
*column
= (wxListHeaderData
*)node
->Data();
1897 column
->SetItem( item
);
1899 wxListCtrl
*lc
= (wxListCtrl
*) GetParent();
1900 if (lc
->m_headerWin
) lc
->m_headerWin
->Refresh();
1903 void wxListMainWindow::SetColumnWidth( int col
, int width
)
1905 if (!(m_mode
& wxLC_REPORT
)) return;
1909 wxNode
*node
= (wxNode
*) NULL
;
1911 if (width
== wxLIST_AUTOSIZE_USEHEADER
) width
= 80;
1912 if (width
== wxLIST_AUTOSIZE
)
1914 wxClientDC
dc(this);
1915 dc
.SetFont( GetFont() );
1917 node
= m_lines
.First();
1920 wxListLineData
*line
= (wxListLineData
*)node
->Data();
1921 wxNode
*n
= line
->m_items
.Nth( col
);
1924 wxListItemData
*item
= (wxListItemData
*)n
->Data();
1925 int current
= 0, ix
= 0, iy
= 0;
1926 wxCoord lx
= 0, ly
= 0;
1927 if (item
->HasImage())
1929 GetImageSize( item
->GetImage(), ix
, iy
);
1932 if (item
->HasText())
1935 item
->GetText( str
);
1936 dc
.GetTextExtent( str
, &lx
, &ly
);
1939 if (current
> max
) max
= current
;
1941 node
= node
->Next();
1946 node
= m_columns
.Nth( col
);
1949 wxListHeaderData
*column
= (wxListHeaderData
*)node
->Data();
1950 column
->SetWidth( width
);
1953 node
= m_lines
.First();
1956 wxListLineData
*line
= (wxListLineData
*)node
->Data();
1957 wxNode
*n
= line
->m_items
.Nth( col
);
1960 wxListItemData
*item
= (wxListItemData
*)n
->Data();
1961 item
->SetSize( width
, -1 );
1963 node
= node
->Next();
1966 wxListCtrl
*lc
= (wxListCtrl
*) GetParent();
1967 if (lc
->m_headerWin
) lc
->m_headerWin
->Refresh();
1970 void wxListMainWindow::GetColumn( int col
, wxListItem
&item
)
1972 wxNode
*node
= m_columns
.Nth( col
);
1975 wxListHeaderData
*column
= (wxListHeaderData
*)node
->Data();
1976 column
->GetItem( item
);
1988 int wxListMainWindow::GetColumnWidth( int col
)
1990 wxNode
*node
= m_columns
.Nth( col
);
1993 wxListHeaderData
*column
= (wxListHeaderData
*)node
->Data();
1994 return column
->GetWidth();
2002 int wxListMainWindow::GetColumnCount()
2004 return m_columns
.Number();
2007 int wxListMainWindow::GetCountPerPage()
2009 return m_visibleLines
;
2012 void wxListMainWindow::SetItem( wxListItem
&item
)
2015 wxNode
*node
= m_lines
.Nth( (size_t)item
.m_itemId
);
2018 wxListLineData
*line
= (wxListLineData
*)node
->Data();
2019 if (m_mode
& wxLC_REPORT
) item
.m_width
= GetColumnWidth( item
.m_col
)-3;
2020 line
->SetItem( item
.m_col
, item
);
2024 void wxListMainWindow::SetItemState( long item
, long state
, long stateMask
)
2026 // m_dirty = TRUE; no recalcs needed
2028 wxListLineData
*oldCurrent
= m_current
;
2030 if (stateMask
& wxLIST_STATE_FOCUSED
)
2032 wxNode
*node
= m_lines
.Nth( (size_t)item
);
2035 wxListLineData
*line
= (wxListLineData
*)node
->Data();
2036 UnfocusLine( m_current
);
2038 FocusLine( m_current
);
2039 RefreshLine( m_current
);
2040 if (oldCurrent
) RefreshLine( oldCurrent
);
2044 if (stateMask
& wxLIST_STATE_SELECTED
)
2046 bool on
= (state
& wxLIST_STATE_SELECTED
) != 0;
2047 if (!on
&& (m_mode
& wxLC_SINGLE_SEL
)) return;
2049 wxNode
*node
= m_lines
.Nth( (size_t)item
);
2052 wxListLineData
*line
= (wxListLineData
*)node
->Data();
2053 if (m_mode
& wxLC_SINGLE_SEL
)
2055 UnfocusLine( m_current
);
2057 FocusLine( m_current
);
2058 if (oldCurrent
) oldCurrent
->Hilight( FALSE
);
2059 RefreshLine( m_current
);
2060 if (oldCurrent
) RefreshLine( oldCurrent
);
2062 bool on
= (state
& wxLIST_STATE_SELECTED
) != 0;
2063 if (on
!= line
->IsHilighted())
2065 line
->Hilight( on
);
2066 RefreshLine( line
);
2072 int wxListMainWindow::GetItemState( long item
, long stateMask
)
2074 int ret
= wxLIST_STATE_DONTCARE
;
2075 if (stateMask
& wxLIST_STATE_FOCUSED
)
2077 wxNode
*node
= m_lines
.Nth( (size_t)item
);
2080 wxListLineData
*line
= (wxListLineData
*)node
->Data();
2081 if (line
== m_current
) ret
|= wxLIST_STATE_FOCUSED
;
2084 if (stateMask
& wxLIST_STATE_SELECTED
)
2086 wxNode
*node
= m_lines
.Nth( (size_t)item
);
2089 wxListLineData
*line
= (wxListLineData
*)node
->Data();
2090 if (line
->IsHilighted()) ret
|= wxLIST_STATE_FOCUSED
;
2096 void wxListMainWindow::GetItem( wxListItem
&item
)
2098 wxNode
*node
= m_lines
.Nth( (size_t)item
.m_itemId
);
2101 wxListLineData
*line
= (wxListLineData
*)node
->Data();
2102 line
->GetItem( item
.m_col
, item
);
2113 int wxListMainWindow::GetItemCount()
2115 return m_lines
.Number();
2118 void wxListMainWindow::GetItemRect( long index
, wxRect
&rect
)
2120 wxNode
*node
= m_lines
.Nth( (size_t)index
);
2123 wxListLineData
*line
= (wxListLineData
*)node
->Data();
2124 line
->GetRect( rect
);
2135 bool wxListMainWindow::GetItemPosition(long item
, wxPoint
& pos
)
2137 wxNode
*node
= m_lines
.Nth( (size_t)item
);
2141 wxListLineData
*line
= (wxListLineData
*)node
->Data();
2142 line
->GetRect( rect
);
2154 int wxListMainWindow::GetSelectedItemCount()
2157 wxNode
*node
= m_lines
.First();
2160 wxListLineData
*line
= (wxListLineData
*)node
->Data();
2161 if (line
->IsHilighted()) ret
++;
2162 node
= node
->Next();
2167 void wxListMainWindow::SetMode( long mode
)
2174 if (m_mode
& wxLC_REPORT
)
2176 #if wxUSE_GENERIC_LIST_EXTENSIONS
2190 long wxListMainWindow::GetMode() const
2195 void wxListMainWindow::CalculatePositions()
2197 if (!m_lines
.First()) return;
2199 wxClientDC
dc( this );
2200 dc
.SetFont( GetFont() );
2202 int iconSpacing
= 0;
2203 if (m_mode
& wxLC_ICON
) iconSpacing
= m_normal_spacing
;
2204 if (m_mode
& wxLC_SMALL_ICON
) iconSpacing
= m_small_spacing
;
2206 // we take the first line (which also can be an icon or
2207 // an a text item in wxLC_ICON and wxLC_LIST modes) to
2208 // measure the size of the line
2212 int lineSpacing
= 0;
2214 wxListLineData
*line
= (wxListLineData
*)m_lines
.First()->Data();
2215 line
->CalculateSize( &dc
, iconSpacing
);
2217 line
->GetSize( dummy
, lineSpacing
);
2220 int clientWidth
= 0;
2221 int clientHeight
= 0;
2223 if (m_mode
& wxLC_REPORT
)
2227 int entireHeight
= m_lines
.Number() * lineSpacing
+ 2;
2228 int scroll_pos
= GetScrollPos( wxVERTICAL
);
2229 #if wxUSE_GENERIC_LIST_EXTENSIONS
2230 int x_scroll_pos
= GetScrollPos( wxHORIZONTAL
);
2232 SetScrollbars( m_xScroll
, m_yScroll
, 0, (entireHeight
+15) / m_yScroll
, 0, scroll_pos
, TRUE
);
2234 GetClientSize( &clientWidth
, &clientHeight
);
2236 wxNode
* node
= m_lines
.First();
2237 int entireWidth
= 0 ;
2240 wxListLineData
*line
= (wxListLineData
*)node
->Data();
2241 line
->CalculateSize( &dc
, iconSpacing
);
2242 line
->SetPosition( &dc
, x
, y
, clientWidth
);
2244 for (int i
= 0; i
< GetColumnCount(); i
++)
2246 line
->SetColumnPosition( i
, col_x
);
2247 col_x
+= GetColumnWidth( i
);
2249 entireWidth
= wxMax( entireWidth
, col_x
) ;
2250 #if wxUSE_GENERIC_LIST_EXTENSIONS
2251 line
->SetPosition( &dc
, x
, y
, col_x
);
2253 y
+= lineSpacing
; // one pixel blank line between items
2254 node
= node
->Next();
2256 m_visibleLines
= clientHeight
/ lineSpacing
;
2257 #if wxUSE_GENERIC_LIST_EXTENSIONS
2258 SetScrollbars( m_xScroll
, m_yScroll
, entireWidth
/ m_xScroll
, (entireHeight
+15) / m_yScroll
, x_scroll_pos
, scroll_pos
, TRUE
);
2263 // at first we try without any scrollbar. if the items don't
2264 // fit into the window, we recalculate after subtracting an
2265 // approximated 15 pt for the horizontal scrollbar
2267 GetSize( &clientWidth
, &clientHeight
);
2268 clientHeight
-= 4; // sunken frame
2270 int entireWidth
= 0;
2272 for (int tries
= 0; tries
< 2; tries
++)
2275 int x
= 5; // painting is done at x-2
2276 int y
= 5; // painting is done at y-2
2279 int m_currentVisibleLines
= 0;
2280 wxNode
*node
= m_lines
.First();
2283 m_currentVisibleLines
++;
2284 wxListLineData
*line
= (wxListLineData
*)node
->Data();
2285 line
->CalculateSize( &dc
, iconSpacing
);
2286 line
->SetPosition( &dc
, x
, y
, clientWidth
);
2287 line
->GetSize( lineWidth
, lineHeight
);
2288 if (lineWidth
> maxWidth
) maxWidth
= lineWidth
;
2290 if (m_currentVisibleLines
> m_visibleLines
)
2291 m_visibleLines
= m_currentVisibleLines
;
2292 if (y
+lineSpacing
-6 >= clientHeight
) // -6 for earlier "line breaking"
2294 m_currentVisibleLines
= 0;
2297 entireWidth
+= maxWidth
+6;
2300 node
= node
->Next();
2301 if (!node
) entireWidth
+= maxWidth
;
2302 if ((tries
== 0) && (entireWidth
> clientWidth
))
2304 clientHeight
-= 15; // scrollbar height
2306 m_currentVisibleLines
= 0;
2309 if (!node
) tries
= 1; // everything fits, no second try required
2313 int scroll_pos
= GetScrollPos( wxHORIZONTAL
);
2314 SetScrollbars( m_xScroll
, m_yScroll
, (entireWidth
+15) / m_xScroll
, 0, scroll_pos
, 0, TRUE
);
2318 void wxListMainWindow::RealizeChanges( void )
2322 wxNode
*node
= m_lines
.First();
2323 if (node
) m_current
= (wxListLineData
*)node
->Data();
2327 FocusLine( m_current
);
2328 if (m_mode
& wxLC_SINGLE_SEL
) m_current
->Hilight( TRUE
);
2332 long wxListMainWindow::GetNextItem( long item
, int WXUNUSED(geometry
), int state
)
2335 if (item
> 0) ret
= item
;
2336 if(ret
>= GetItemCount()) return -1;
2337 wxNode
*node
= m_lines
.Nth( (size_t)ret
);
2340 wxListLineData
*line
= (wxListLineData
*)node
->Data();
2341 if ((state
& wxLIST_STATE_FOCUSED
) && (line
== m_current
)) return ret
;
2342 if ((state
& wxLIST_STATE_SELECTED
) && (line
->IsHilighted())) return ret
;
2343 if (!state
) return ret
;
2345 node
= node
->Next();
2350 void wxListMainWindow::DeleteItem( long index
)
2353 wxNode
*node
= m_lines
.Nth( (size_t)index
);
2356 wxListLineData
*line
= (wxListLineData
*)node
->Data();
2357 if (m_current
== line
) m_current
= (wxListLineData
*) NULL
;
2359 m_lines
.DeleteNode( node
);
2363 void wxListMainWindow::DeleteColumn( int col
)
2365 wxCHECK_RET( col
< (int)m_columns
.GetCount(),
2366 wxT("attempting to delete inexistent column in wxListView") );
2369 wxNode
*node
= m_columns
.Nth( col
);
2370 if (node
) m_columns
.DeleteNode( node
);
2373 void wxListMainWindow::DeleteAllItems( void )
2376 m_current
= (wxListLineData
*) NULL
;
2378 // to make the deletion of all items faster, we don't send the
2379 // notifications in this case: this is compatible with wxMSW and
2380 // documented in DeleteAllItems() description
2382 wxNode
*node
= m_lines
.First();
2385 wxListLineData
*line
= (wxListLineData
*)node
->Data();
2389 node
= node
->Next();
2396 void wxListMainWindow::DeleteEverything( void )
2399 m_current
= (wxListLineData
*) NULL
;
2400 wxNode
*node
= m_lines
.First();
2403 wxListLineData
*line
= (wxListLineData
*)node
->Data();
2405 node
= node
->Next();
2408 m_current
= (wxListLineData
*) NULL
;
2412 void wxListMainWindow::EnsureVisible( long index
)
2414 // We have to call this here because the label in
2415 // question might just have been added and no screen
2416 // update taken place.
2417 if (m_dirty
) wxYield();
2419 wxListLineData
*oldCurrent
= m_current
;
2420 m_current
= (wxListLineData
*) NULL
;
2421 wxNode
*node
= m_lines
.Nth( (size_t)index
);
2422 if (node
) m_current
= (wxListLineData
*)node
->Data();
2423 if (m_current
) MoveToFocus();
2424 m_current
= oldCurrent
;
2427 long wxListMainWindow::FindItem(long start
, const wxString
& str
, bool WXUNUSED(partial
) )
2431 if (pos
< 0) pos
= 0;
2432 wxNode
*node
= m_lines
.Nth( (size_t)pos
);
2435 wxListLineData
*line
= (wxListLineData
*)node
->Data();
2437 line
->GetText( 0, s
);
2438 if (s
== tmp
) return pos
;
2439 node
= node
->Next();
2445 long wxListMainWindow::FindItem(long start
, long data
)
2448 if (pos
< 0) pos
= 0;
2449 wxNode
*node
= m_lines
.Nth( (size_t)pos
);
2452 wxListLineData
*line
= (wxListLineData
*)node
->Data();
2454 line
->GetItem( 0, item
);
2455 if (item
.m_data
== data
) return pos
;
2456 node
= node
->Next();
2462 long wxListMainWindow::HitTest( int x
, int y
, int &flags
)
2464 wxNode
*node
= m_lines
.First();
2468 wxListLineData
*line
= (wxListLineData
*)node
->Data();
2469 long ret
= line
->IsHit( x
, y
);
2475 node
= node
->Next();
2481 void wxListMainWindow::InsertItem( wxListItem
&item
)
2485 if (m_mode
& wxLC_REPORT
) mode
= wxLC_REPORT
;
2486 else if (m_mode
& wxLC_LIST
) mode
= wxLC_LIST
;
2487 else if (m_mode
& wxLC_ICON
) mode
= wxLC_ICON
;
2488 else if (m_mode
& wxLC_SMALL_ICON
) mode
= wxLC_ICON
; // no typo
2490 wxListLineData
*line
= new wxListLineData( this, mode
, m_hilightBrush
);
2492 if (m_mode
& wxLC_REPORT
)
2494 line
->InitItems( GetColumnCount() );
2495 item
.m_width
= GetColumnWidth( 0 )-3;
2499 line
->InitItems( 1 );
2502 line
->SetItem( 0, item
);
2503 if ((item
.m_itemId
>= 0) && (item
.m_itemId
< (int)m_lines
.GetCount()))
2505 wxNode
*node
= m_lines
.Nth( (size_t)item
.m_itemId
);
2506 if (node
) m_lines
.Insert( node
, line
);
2510 m_lines
.Append( line
);
2514 void wxListMainWindow::InsertColumn( long col
, wxListItem
&item
)
2517 if (m_mode
& wxLC_REPORT
)
2519 if (item
.m_width
== wxLIST_AUTOSIZE_USEHEADER
) item
.m_width
= GetTextLength( item
.m_text
);
2520 wxListHeaderData
*column
= new wxListHeaderData( item
);
2521 if ((col
>= 0) && (col
< (int)m_columns
.GetCount()))
2523 wxNode
*node
= m_columns
.Nth( (size_t)col
);
2525 m_columns
.Insert( node
, column
);
2529 m_columns
.Append( column
);
2534 wxListCtrlCompare list_ctrl_compare_func_2
;
2535 long list_ctrl_compare_data
;
2537 int LINKAGEMODE
list_ctrl_compare_func_1( const void *arg1
, const void *arg2
)
2539 wxListLineData
*line1
= *((wxListLineData
**)arg1
);
2540 wxListLineData
*line2
= *((wxListLineData
**)arg2
);
2542 line1
->GetItem( 0, item
);
2543 long data1
= item
.m_data
;
2544 line2
->GetItem( 0, item
);
2545 long data2
= item
.m_data
;
2546 return list_ctrl_compare_func_2( data1
, data2
, list_ctrl_compare_data
);
2549 void wxListMainWindow::SortItems( wxListCtrlCompare fn
, long data
)
2551 list_ctrl_compare_func_2
= fn
;
2552 list_ctrl_compare_data
= data
;
2553 m_lines
.Sort( list_ctrl_compare_func_1
);
2556 void wxListMainWindow::OnScroll(wxScrollWinEvent
& event
)
2558 wxScrolledWindow::OnScroll( event
) ;
2559 #if wxUSE_GENERIC_LIST_EXTENSIONS
2561 if (event
.GetOrientation() == wxHORIZONTAL
&& ( m_mode
& wxLC_REPORT
))
2563 wxListCtrl
* lc
= wxDynamicCast( GetParent() , wxListCtrl
) ;
2566 lc
->m_headerWin
->Refresh() ;
2568 lc
->m_headerWin
->MacUpdateImmediately() ;
2575 // -------------------------------------------------------------------------------------
2577 // -------------------------------------------------------------------------------------
2579 IMPLEMENT_DYNAMIC_CLASS(wxListItem
, wxObject
)
2581 wxListItem::wxListItem()
2590 m_format
= wxLIST_FORMAT_CENTRE
;
2596 void wxListItem::Clear()
2605 m_format
= wxLIST_FORMAT_CENTRE
;
2607 m_text
= wxEmptyString
;
2609 if (m_attr
) delete m_attr
;
2613 void wxListItem::ClearAttributes()
2615 if (m_attr
) delete m_attr
;
2619 // -------------------------------------------------------------------------------------
2621 // -------------------------------------------------------------------------------------
2623 IMPLEMENT_DYNAMIC_CLASS(wxListEvent
, wxNotifyEvent
)
2625 wxListEvent::wxListEvent( wxEventType commandType
, int id
):
2626 wxNotifyEvent( commandType
, id
)
2632 m_cancelled
= FALSE
;
2637 void wxListEvent::CopyObject(wxObject
& object_dest
) const
2639 wxListEvent
*obj
= (wxListEvent
*)&object_dest
;
2641 wxNotifyEvent::CopyObject(object_dest
);
2643 obj
->m_code
= m_code
;
2644 obj
->m_itemIndex
= m_itemIndex
;
2645 obj
->m_oldItemIndex
= m_oldItemIndex
;
2647 obj
->m_cancelled
= m_cancelled
;
2648 obj
->m_pointDrag
= m_pointDrag
;
2649 obj
->m_item
.m_mask
= m_item
.m_mask
;
2650 obj
->m_item
.m_itemId
= m_item
.m_itemId
;
2651 obj
->m_item
.m_col
= m_item
.m_col
;
2652 obj
->m_item
.m_state
= m_item
.m_state
;
2653 obj
->m_item
.m_stateMask
= m_item
.m_stateMask
;
2654 obj
->m_item
.m_text
= m_item
.m_text
;
2655 obj
->m_item
.m_image
= m_item
.m_image
;
2656 obj
->m_item
.m_data
= m_item
.m_data
;
2657 obj
->m_item
.m_format
= m_item
.m_format
;
2658 obj
->m_item
.m_width
= m_item
.m_width
;
2660 if ( m_item
.HasAttributes() )
2662 obj
->m_item
.SetTextColour(m_item
.GetTextColour());
2666 // -------------------------------------------------------------------------------------
2668 // -------------------------------------------------------------------------------------
2670 IMPLEMENT_DYNAMIC_CLASS(wxListCtrl
, wxControl
)
2672 BEGIN_EVENT_TABLE(wxListCtrl
,wxControl
)
2673 EVT_SIZE (wxListCtrl::OnSize
)
2674 EVT_IDLE (wxListCtrl::OnIdle
)
2677 wxListCtrl::wxListCtrl()
2679 m_imageListNormal
= (wxImageList
*) NULL
;
2680 m_imageListSmall
= (wxImageList
*) NULL
;
2681 m_imageListState
= (wxImageList
*) NULL
;
2682 m_mainWin
= (wxListMainWindow
*) NULL
;
2683 m_headerWin
= (wxListHeaderWindow
*) NULL
;
2686 wxListCtrl::~wxListCtrl()
2690 bool wxListCtrl::Create(wxWindow
*parent
,
2695 const wxValidator
&validator
,
2696 const wxString
&name
)
2698 m_imageListNormal
= (wxImageList
*) NULL
;
2699 m_imageListSmall
= (wxImageList
*) NULL
;
2700 m_imageListState
= (wxImageList
*) NULL
;
2701 m_mainWin
= (wxListMainWindow
*) NULL
;
2702 m_headerWin
= (wxListHeaderWindow
*) NULL
;
2704 if ( !(style
& (wxLC_REPORT
| wxLC_LIST
| wxLC_ICON
)) )
2706 style
= style
| wxLC_LIST
;
2709 bool ret
= wxControl::Create( parent
, id
, pos
, size
, style
, validator
, name
);
2712 if (style
& wxSUNKEN_BORDER
)
2713 style
-= wxSUNKEN_BORDER
;
2715 m_mainWin
= new wxListMainWindow( this, -1, wxPoint(0,0), size
, style
);
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 wxASSERT( m_headerWin
);
3102 m_mainWin
->InsertColumn( col
, item
);
3103 m_headerWin
->Refresh();
3108 long wxListCtrl::InsertColumn( long col
, const wxString
&heading
,
3109 int format
, int width
)
3112 item
.m_mask
= wxLIST_MASK_TEXT
| wxLIST_MASK_FORMAT
;
3113 item
.m_text
= heading
;
3116 item
.m_mask
|= wxLIST_MASK_WIDTH
;
3117 item
.m_width
= width
;
3119 item
.m_format
= format
;
3121 return InsertColumn( col
, item
);
3124 bool wxListCtrl::ScrollList( int WXUNUSED(dx
), int WXUNUSED(dy
) )
3130 // fn is a function which takes 3 long arguments: item1, item2, data.
3131 // item1 is the long data associated with a first item (NOT the index).
3132 // item2 is the long data associated with a second item (NOT the index).
3133 // data is the same value as passed to SortItems.
3134 // The return value is a negative number if the first item should precede the second
3135 // item, a positive number of the second item should precede the first,
3136 // or zero if the two items are equivalent.
3137 // data is arbitrary data to be passed to the sort function.
3139 bool wxListCtrl::SortItems( wxListCtrlCompare fn
, long data
)
3141 m_mainWin
->SortItems( fn
, data
);
3145 void wxListCtrl::OnIdle( wxIdleEvent
&WXUNUSED(event
) )
3147 if (!m_mainWin
->m_dirty
) return;
3151 GetClientSize( &cw
, &ch
);
3158 if (HasFlag(wxLC_REPORT
) && !HasFlag(wxLC_NO_HEADER
))
3160 m_headerWin
->GetPosition( &x
, &y
);
3161 m_headerWin
->GetSize( &w
, &h
);
3162 if ((x
!= 0) || (y
!= 0) || (w
!= cw
) || (h
!= 23))
3163 m_headerWin
->SetSize( 0, 0, cw
, 23 );
3165 m_mainWin
->GetPosition( &x
, &y
);
3166 m_mainWin
->GetSize( &w
, &h
);
3167 if ((x
!= 0) || (y
!= 24) || (w
!= cw
) || (h
!= ch
-24))
3168 m_mainWin
->SetSize( 0, 24, cw
, ch
-24 );
3172 m_mainWin
->GetPosition( &x
, &y
);
3173 m_mainWin
->GetSize( &w
, &h
);
3174 if ((x
!= 0) || (y
!= 24) || (w
!= cw
) || (h
!= ch
))
3175 m_mainWin
->SetSize( 0, 0, cw
, ch
);
3178 m_mainWin
->CalculatePositions();
3179 m_mainWin
->RealizeChanges();
3180 m_mainWin
->m_dirty
= FALSE
;
3181 m_mainWin
->Refresh();
3184 bool wxListCtrl::SetBackgroundColour( const wxColour
&colour
)
3186 if ( !wxWindow::SetBackgroundColour( colour
) )
3191 m_mainWin
->SetBackgroundColour( colour
);
3192 m_mainWin
->m_dirty
= TRUE
;
3197 // m_headerWin->SetBackgroundColour( colour );
3203 bool wxListCtrl::SetForegroundColour( const wxColour
&colour
)
3205 if ( !wxWindow::SetForegroundColour( colour
) )
3210 m_mainWin
->SetForegroundColour( colour
);
3211 m_mainWin
->m_dirty
= TRUE
;
3216 m_headerWin
->SetForegroundColour( colour
);
3222 bool wxListCtrl::SetFont( const wxFont
&font
)
3224 if ( !wxWindow::SetFont( font
) )
3229 m_mainWin
->SetFont( font
);
3230 m_mainWin
->m_dirty
= TRUE
;
3235 m_headerWin
->SetFont( font
);