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
)
474 wxNode
*node
= m_items
.Nth( (size_t)index
);
477 wxListItemData
*item
= (wxListItemData
*)node
->Data();
478 item
->SetPosition( x
, m_bound_all
.y
+1 );
482 void wxListLineData::GetSize( int &width
, int &height
)
484 width
= m_bound_all
.width
;
485 height
= m_bound_all
.height
;
488 void wxListLineData::GetExtent( int &x
, int &y
, int &width
, int &height
)
492 width
= m_bound_all
.width
;
493 height
= m_bound_all
.height
;
496 void wxListLineData::GetLabelExtent( int &x
, int &y
, int &width
, int &height
)
500 width
= m_bound_label
.width
;
501 height
= m_bound_label
.height
;
504 void wxListLineData::GetRect( wxRect
&rect
)
506 AssignRect( rect
, m_bound_all
);
509 long wxListLineData::IsHit( int x
, int y
)
511 wxNode
*node
= m_items
.First();
514 wxListItemData
*item
= (wxListItemData
*)node
->Data();
515 if (item
->HasImage() && IsInRect( x
, y
, m_bound_icon
)) return wxLIST_HITTEST_ONITEMICON
;
516 if (item
->HasText() && IsInRect( x
, y
, m_bound_label
)) return wxLIST_HITTEST_ONITEMLABEL
;
517 // if (!(item->HasImage() || item->HasText())) return 0;
519 // if there is no icon or text = empty
520 if (IsInRect( x
, y
, m_bound_all
)) return wxLIST_HITTEST_ONITEMICON
;
524 void wxListLineData::InitItems( int num
)
526 for (int i
= 0; i
< num
; i
++) m_items
.Append( new wxListItemData() );
529 void wxListLineData::SetItem( int index
, const wxListItem
&info
)
531 wxNode
*node
= m_items
.Nth( index
);
534 wxListItemData
*item
= (wxListItemData
*)node
->Data();
535 item
->SetItem( info
);
539 void wxListLineData::GetItem( int index
, wxListItem
&info
)
542 wxNode
*node
= m_items
.Nth( i
);
545 wxListItemData
*item
= (wxListItemData
*)node
->Data();
546 item
->GetItem( info
);
550 void wxListLineData::GetText( int index
, wxString
&s
)
553 wxNode
*node
= m_items
.Nth( i
);
557 wxListItemData
*item
= (wxListItemData
*)node
->Data();
562 void wxListLineData::SetText( int index
, const wxString s
)
565 wxNode
*node
= m_items
.Nth( i
);
568 wxListItemData
*item
= (wxListItemData
*)node
->Data();
573 int wxListLineData::GetImage( int index
)
576 wxNode
*node
= m_items
.Nth( i
);
579 wxListItemData
*item
= (wxListItemData
*)node
->Data();
580 return item
->GetImage();
585 void wxListLineData::SetAttributes(wxDC
*dc
,
586 const wxListItemAttr
*attr
,
587 const wxColour
& colText
,
591 // don't use foregroud colour for drawing highlighted items - this might
592 // make them completely invisible (and there is no way to do bit
593 // arithmetics on wxColour, unfortunately)
594 if ( !hilight
&& attr
&& attr
->HasTextColour() )
596 dc
->SetTextForeground(attr
->GetTextColour());
600 dc
->SetTextForeground(colText
);
603 if ( attr
&& attr
->HasFont() )
605 dc
->SetFont(attr
->GetFont());
613 void wxListLineData::DoDraw( wxDC
*dc
, bool hilight
, bool paintBG
)
615 wxCoord dev_x
= dc
->LogicalToDeviceX( m_bound_all
.x
-2 );
616 wxCoord dev_y
= dc
->LogicalToDeviceY( m_bound_all
.y
-2 );
617 wxCoord dev_w
= dc
->LogicalToDeviceXRel( m_bound_all
.width
+4 );
618 wxCoord dev_h
= dc
->LogicalToDeviceYRel( m_bound_all
.height
+4 );
620 if (!m_owner
->IsExposed( dev_x
, dev_y
, dev_w
, dev_h
))
625 wxWindow
*listctrl
= m_owner
->GetParent();
627 // default foreground colour
631 colText
= wxSystemSettings::GetSystemColour( wxSYS_COLOUR_HIGHLIGHTTEXT
);
635 colText
= listctrl
->GetForegroundColour();
639 wxFont font
= listctrl
->GetFont();
641 // VZ: currently we set the colours/fonts only once, but like this (i.e.
642 // using SetAttributes() inside the loop), it will be trivial to
643 // customize the subitems (in report mode) too.
644 wxListItemData
*item
= (wxListItemData
*)m_items
.First()->Data();
645 wxListItemAttr
*attr
= item
->GetAttributes();
646 SetAttributes(dc
, attr
, colText
, font
, hilight
);
648 bool hasBgCol
= attr
&& attr
->HasBackgroundColour();
649 if ( paintBG
|| hasBgCol
)
653 dc
->SetBrush( * m_hilightBrush
);
658 dc
->SetBrush(wxBrush(attr
->GetBackgroundColour(), wxSOLID
));
660 dc
->SetBrush( * wxWHITE_BRUSH
);
663 dc
->SetPen( * wxTRANSPARENT_PEN
);
664 dc
->DrawRectangle( m_bound_hilight
.x
, m_bound_hilight
.y
,
665 m_bound_hilight
.width
, m_bound_hilight
.height
);
668 if (m_mode
== wxLC_REPORT
)
670 wxNode
*node
= m_items
.First();
673 wxListItemData
*item
= (wxListItemData
*)node
->Data();
674 dc
->SetClippingRegion( item
->GetX(), item
->GetY(), item
->GetWidth()-3, item
->GetHeight() );
675 int x
= item
->GetX();
676 if (item
->HasImage())
679 m_owner
->DrawImage( item
->GetImage(), dc
, x
, item
->GetY() );
680 m_owner
->GetImageSize( item
->GetImage(), x
, y
);
681 x
+= item
->GetX() + 5;
685 dc
->DrawText( item
->GetText(), x
, item
->GetY() );
687 dc
->DestroyClippingRegion();
693 wxNode
*node
= m_items
.First();
696 wxListItemData
*item
= (wxListItemData
*)node
->Data();
697 if (item
->HasImage())
699 m_owner
->DrawImage( item
->GetImage(), dc
, m_bound_icon
.x
, m_bound_icon
.y
);
703 dc
->DrawText( item
->GetText(), m_bound_label
.x
, m_bound_label
.y
);
709 void wxListLineData::Hilight( bool on
)
711 if (on
== m_hilighted
) return;
714 m_owner
->SelectLine( this );
716 m_owner
->DeselectLine( this );
719 void wxListLineData::ReverseHilight( void )
721 m_hilighted
= !m_hilighted
;
723 m_owner
->SelectLine( this );
725 m_owner
->DeselectLine( this );
728 void wxListLineData::DrawRubberBand( wxDC
*dc
, bool on
)
732 dc
->SetPen( * wxBLACK_PEN
);
733 dc
->SetBrush( * wxTRANSPARENT_BRUSH
);
734 dc
->DrawRectangle( m_bound_hilight
.x
, m_bound_hilight
.y
,
735 m_bound_hilight
.width
, m_bound_hilight
.height
);
739 void wxListLineData::Draw( wxDC
*dc
)
741 DoDraw( dc
, m_hilighted
, m_hilighted
);
744 bool wxListLineData::IsInRect( int x
, int y
, const wxRect
&rect
)
746 return ((x
>= rect
.x
) && (x
<= rect
.x
+rect
.width
) &&
747 (y
>= rect
.y
) && (y
<= rect
.y
+rect
.height
));
750 bool wxListLineData::IsHilighted( void )
755 void wxListLineData::AssignRect( wxRect
&dest
, int x
, int y
, int width
, int height
)
760 dest
.height
= height
;
763 void wxListLineData::AssignRect( wxRect
&dest
, const wxRect
&source
)
767 dest
.width
= source
.width
;
768 dest
.height
= source
.height
;
771 //-----------------------------------------------------------------------------
772 // wxListHeaderWindow
773 //-----------------------------------------------------------------------------
775 IMPLEMENT_DYNAMIC_CLASS(wxListHeaderWindow
,wxWindow
);
777 BEGIN_EVENT_TABLE(wxListHeaderWindow
,wxWindow
)
778 EVT_PAINT (wxListHeaderWindow::OnPaint
)
779 EVT_MOUSE_EVENTS (wxListHeaderWindow::OnMouse
)
780 EVT_SET_FOCUS (wxListHeaderWindow::OnSetFocus
)
783 wxListHeaderWindow::wxListHeaderWindow( void )
785 m_owner
= (wxListMainWindow
*) NULL
;
786 m_currentCursor
= (wxCursor
*) NULL
;
787 m_resizeCursor
= (wxCursor
*) NULL
;
788 m_isDragging
= FALSE
;
791 wxListHeaderWindow::wxListHeaderWindow( wxWindow
*win
, wxWindowID id
, wxListMainWindow
*owner
,
792 const wxPoint
&pos
, const wxSize
&size
,
793 long style
, const wxString
&name
) :
794 wxWindow( win
, id
, pos
, size
, style
, name
)
797 // m_currentCursor = wxSTANDARD_CURSOR;
798 m_currentCursor
= (wxCursor
*) NULL
;
799 m_resizeCursor
= new wxCursor( wxCURSOR_SIZEWE
);
800 m_isDragging
= FALSE
;
801 SetBackgroundColour( wxSystemSettings::GetSystemColour( wxSYS_COLOUR_BTNFACE
) );
804 wxListHeaderWindow::~wxListHeaderWindow( void )
806 delete m_resizeCursor
;
809 void wxListHeaderWindow::DoDrawRect( wxDC
*dc
, int x
, int y
, int w
, int h
)
811 const int m_corner
= 1;
813 dc
->SetBrush( *wxTRANSPARENT_BRUSH
);
815 dc
->SetPen( *wxBLACK_PEN
);
816 dc
->DrawLine( x
+w
-m_corner
+1, y
, x
+w
, y
+h
); // right (outer)
817 dc
->DrawRectangle( x
, y
+h
, w
+1, 1 ); // bottom (outer)
819 wxPen
pen( wxSystemSettings::GetSystemColour( wxSYS_COLOUR_BTNSHADOW
), 1, wxSOLID
);
822 dc
->DrawLine( x
+w
-m_corner
, y
, x
+w
-1, y
+h
); // right (inner)
823 dc
->DrawRectangle( x
+1, y
+h
-1, w
-2, 1 ); // bottom (inner)
825 dc
->SetPen( *wxWHITE_PEN
);
826 dc
->DrawRectangle( x
, y
, w
-m_corner
+1, 1 ); // top (outer)
827 dc
->DrawRectangle( x
, y
, 1, h
); // left (outer)
828 dc
->DrawLine( x
, y
+h
-1, x
+1, y
+h
-1 );
829 dc
->DrawLine( x
+w
-1, y
, x
+w
-1, y
+1 );
832 void wxListHeaderWindow::OnPaint( wxPaintEvent
&WXUNUSED(event
) )
834 wxPaintDC
dc( this );
836 #if wxUSE_GENERIC_LIST_EXTENSIONS
837 if ( m_owner
->GetMode() & wxLC_REPORT
)
842 m_owner
->GetScrollPixelsPerUnit( &xpix
, &ypix
) ;
843 m_owner
->ViewStart( &x
, &y
) ;
844 dc
.SetDeviceOrigin( -x
* xpix
, 0 );
849 dc
.SetFont( GetFont() );
855 GetClientSize( &w
, &h
);
857 dc
.SetBackgroundMode(wxTRANSPARENT
);
858 dc
.SetTextForeground( *wxBLACK
);
860 // do *not* use the listctrl colour for headers - one day we will have a
861 // function to set it separately
865 int numColumns
= m_owner
->GetColumnCount();
867 for (int i
= 0; i
< numColumns
; i
++)
869 m_owner
->GetColumn( i
, item
);
870 int cw
= item
.m_width
-2;
871 #if wxUSE_GENERIC_LIST_EXTENSIONS
872 if ((i
+1 == numColumns
) || ( dc
.LogicalToDeviceX(x
+item
.m_width
) > w
-5))
873 cw
= dc
.DeviceToLogicalX(w
)-x
-1;
875 if ((i
+1 == numColumns
) || (x
+item
.m_width
> w
-5))
878 dc
.SetPen( *wxWHITE_PEN
);
880 DoDrawRect( &dc
, x
, y
, cw
, h
-2 );
881 dc
.SetClippingRegion( x
, y
, cw
-5, h
-4 );
882 dc
.DrawText( item
.m_text
, x
+4, y
+3 );
883 dc
.DestroyClippingRegion();
885 #if wxUSE_GENERIC_LIST_EXTENSIONS
886 if (dc
.LogicalToDeviceX(x
) > w
+5) break;
894 void wxListHeaderWindow::DrawCurrent()
898 int x2
= m_currentX
-1;
901 m_owner
->GetClientSize( &dummy
, &y2
);
902 ClientToScreen( &x1
, &y1
);
903 m_owner
->ClientToScreen( &x2
, &y2
);
906 dc
.SetLogicalFunction( wxINVERT
);
907 dc
.SetPen( wxPen( *wxBLACK
, 2, wxSOLID
) );
908 dc
.SetBrush( *wxTRANSPARENT_BRUSH
);
910 dc
.DrawLine( x1
, y1
, x2
, y2
);
912 dc
.SetLogicalFunction( wxCOPY
);
914 dc
.SetPen( wxNullPen
);
915 dc
.SetBrush( wxNullBrush
);
918 void wxListHeaderWindow::OnMouse( wxMouseEvent
&event
)
920 wxCoord x
= (wxCoord
)event
.GetX();
921 wxCoord y
= (wxCoord
)event
.GetY();
925 if (event
.ButtonUp())
928 m_isDragging
= FALSE
;
929 m_owner
->SetColumnWidth( m_column
, m_currentX
-m_minX
);
935 GetClientSize( &size_x
, & dummy
);
939 m_currentX
= m_minX
+7;
940 if (m_currentX
> size_x
-7) m_currentX
= size_x
-7;
947 bool hit_border
= FALSE
;
949 for (int j
= 0; j
< m_owner
->GetColumnCount()-1; j
++)
951 xpos
+= m_owner
->GetColumnWidth( j
);
953 if ((abs(x
-xpos
) < 3) && (y
< 22))
965 if (event
.LeftDown())
977 wxListEvent
le( wxEVT_COMMAND_LIST_COL_CLICK
, GetParent()->GetId() );
978 le
.SetEventObject( GetParent() );
980 GetParent()->GetEventHandler()->ProcessEvent( le
);
989 if (m_currentCursor
== wxSTANDARD_CURSOR
) SetCursor( * m_resizeCursor
);
990 m_currentCursor
= m_resizeCursor
;
994 if (m_currentCursor
!= wxSTANDARD_CURSOR
) SetCursor( * wxSTANDARD_CURSOR
);
995 m_currentCursor
= wxSTANDARD_CURSOR
;
1000 void wxListHeaderWindow::OnSetFocus( wxFocusEvent
&WXUNUSED(event
) )
1002 m_owner
->SetFocus();
1005 //-----------------------------------------------------------------------------
1006 // wxListRenameTimer (internal)
1007 //-----------------------------------------------------------------------------
1009 wxListRenameTimer::wxListRenameTimer( wxListMainWindow
*owner
)
1014 void wxListRenameTimer::Notify()
1016 m_owner
->OnRenameTimer();
1019 //-----------------------------------------------------------------------------
1020 // wxListTextCtrl (internal)
1021 //-----------------------------------------------------------------------------
1023 IMPLEMENT_DYNAMIC_CLASS(wxListTextCtrl
,wxTextCtrl
);
1025 BEGIN_EVENT_TABLE(wxListTextCtrl
,wxTextCtrl
)
1026 EVT_CHAR (wxListTextCtrl::OnChar
)
1027 EVT_KILL_FOCUS (wxListTextCtrl::OnKillFocus
)
1030 wxListTextCtrl::wxListTextCtrl( wxWindow
*parent
,
1031 const wxWindowID id
,
1034 wxListMainWindow
*owner
,
1035 const wxString
&value
,
1039 const wxValidator
& validator
,
1040 const wxString
&name
)
1041 : wxTextCtrl( parent
, id
, value
, pos
, size
, style
, validator
, name
)
1046 (*m_accept
) = FALSE
;
1048 m_startValue
= value
;
1051 void wxListTextCtrl::OnChar( wxKeyEvent
&event
)
1053 if (event
.m_keyCode
== WXK_RETURN
)
1056 (*m_res
) = GetValue();
1057 m_owner
->SetFocus();
1060 if (event
.m_keyCode
== WXK_ESCAPE
)
1062 (*m_accept
) = FALSE
;
1064 m_owner
->SetFocus();
1070 void wxListTextCtrl::OnKillFocus( wxFocusEvent
&WXUNUSED(event
) )
1072 if (wxPendingDelete
.Member(this)) return;
1074 wxPendingDelete
.Append(this);
1076 if ((*m_accept
) && ((*m_res
) != m_startValue
))
1077 m_owner
->OnRenameAccept();
1080 //-----------------------------------------------------------------------------
1082 //-----------------------------------------------------------------------------
1084 IMPLEMENT_DYNAMIC_CLASS(wxListMainWindow
,wxScrolledWindow
);
1086 BEGIN_EVENT_TABLE(wxListMainWindow
,wxScrolledWindow
)
1087 EVT_PAINT (wxListMainWindow::OnPaint
)
1088 EVT_SIZE (wxListMainWindow::OnSize
)
1089 EVT_MOUSE_EVENTS (wxListMainWindow::OnMouse
)
1090 EVT_CHAR (wxListMainWindow::OnChar
)
1091 EVT_KEY_DOWN (wxListMainWindow::OnKeyDown
)
1092 EVT_SET_FOCUS (wxListMainWindow::OnSetFocus
)
1093 EVT_KILL_FOCUS (wxListMainWindow::OnKillFocus
)
1094 EVT_SCROLLWIN (wxListMainWindow::OnScroll
)
1097 wxListMainWindow::wxListMainWindow()
1100 m_lines
.DeleteContents( TRUE
);
1101 m_columns
.DeleteContents( TRUE
);
1102 m_current
= (wxListLineData
*) NULL
;
1104 m_hilightBrush
= (wxBrush
*) NULL
;
1108 m_small_image_list
= (wxImageList
*) NULL
;
1109 m_normal_image_list
= (wxImageList
*) NULL
;
1110 m_small_spacing
= 30;
1111 m_normal_spacing
= 40;
1114 m_lastOnSame
= FALSE
;
1115 m_renameTimer
= new wxListRenameTimer( this );
1116 m_isCreated
= FALSE
;
1120 wxListMainWindow::wxListMainWindow( wxWindow
*parent
, wxWindowID id
,
1121 const wxPoint
&pos
, const wxSize
&size
,
1122 long style
, const wxString
&name
) :
1123 wxScrolledWindow( parent
, id
, pos
, size
, style
|wxHSCROLL
|wxVSCROLL
, name
)
1126 m_lines
.DeleteContents( TRUE
);
1127 m_columns
.DeleteContents( TRUE
);
1128 m_current
= (wxListLineData
*) NULL
;
1131 m_hilightBrush
= new wxBrush( wxSystemSettings::GetSystemColour(wxSYS_COLOUR_HIGHLIGHT
), wxSOLID
);
1132 m_small_image_list
= (wxImageList
*) NULL
;
1133 m_normal_image_list
= (wxImageList
*) NULL
;
1134 m_small_spacing
= 30;
1135 m_normal_spacing
= 40;
1138 m_isCreated
= FALSE
;
1142 if (m_mode
& wxLC_REPORT
)
1144 #if wxUSE_GENERIC_LIST_EXTENSIONS
1156 SetScrollbars( m_xScroll
, m_yScroll
, 0, 0, 0, 0 );
1159 m_lastOnSame
= FALSE
;
1160 m_renameTimer
= new wxListRenameTimer( this );
1161 m_renameAccept
= FALSE
;
1163 SetBackgroundColour( *wxWHITE
);
1166 wxListMainWindow::~wxListMainWindow()
1168 if (m_hilightBrush
) delete m_hilightBrush
;
1170 delete m_renameTimer
;
1173 void wxListMainWindow::RefreshLine( wxListLineData
*line
)
1175 if (m_dirty
) return;
1183 wxClientDC
dc(this);
1185 line
->GetExtent( x
, y
, w
, h
);
1187 dc
.LogicalToDeviceX(x
-3),
1188 dc
.LogicalToDeviceY(y
-3),
1189 dc
.LogicalToDeviceXRel(w
+6),
1190 dc
.LogicalToDeviceXRel(h
+6) );
1191 Refresh( TRUE
, &rect
);
1195 void wxListMainWindow::OnPaint( wxPaintEvent
&WXUNUSED(event
) )
1197 // Note: a wxPaintDC must be constructed even if no drawing is
1198 // done (a Windows requirement).
1199 wxPaintDC
dc( this );
1202 if (m_dirty
) return;
1204 if (m_lines
.GetCount() == 0) return;
1208 dc
.SetFont( GetFont() );
1210 if (m_mode
& wxLC_REPORT
)
1212 int lineSpacing
= 0;
1213 wxListLineData
*line
= (wxListLineData
*)m_lines
.First()->Data();
1215 line
->GetSize( dummy
, lineSpacing
);
1218 int y_s
= m_yScroll
*GetScrollPos( wxVERTICAL
);
1220 wxNode
*node
= m_lines
.Nth( y_s
/ lineSpacing
);
1221 for (int i
= 0; i
< m_visibleLines
+2; i
++)
1225 line
= (wxListLineData
*)node
->Data();
1227 node
= node
->Next();
1232 wxNode
*node
= m_lines
.First();
1235 wxListLineData
*line
= (wxListLineData
*)node
->Data();
1237 node
= node
->Next();
1241 if (m_current
) m_current
->DrawRubberBand( &dc
, m_hasFocus
);
1246 void wxListMainWindow::HilightAll( bool on
)
1248 wxNode
*node
= m_lines
.First();
1251 wxListLineData
*line
= (wxListLineData
*)node
->Data();
1252 if (line
->IsHilighted() != on
)
1254 line
->Hilight( on
);
1255 RefreshLine( line
);
1257 node
= node
->Next();
1261 void wxListMainWindow::SendNotify( wxListLineData
*line
, wxEventType command
)
1263 wxListEvent
le( command
, GetParent()->GetId() );
1264 le
.SetEventObject( GetParent() );
1265 le
.m_itemIndex
= GetIndexOfLine( line
);
1266 line
->GetItem( 0, le
.m_item
);
1267 GetParent()->GetEventHandler()->ProcessEvent( le
);
1268 // GetParent()->GetEventHandler()->AddPendingEvent( le );
1271 void wxListMainWindow::FocusLine( wxListLineData
*WXUNUSED(line
) )
1273 // SendNotify( line, wxEVT_COMMAND_LIST_ITEM_FOCUSSED );
1276 void wxListMainWindow::UnfocusLine( wxListLineData
*WXUNUSED(line
) )
1278 // SendNotify( line, wxEVT_COMMAND_LIST_ITEM_UNFOCUSSED );
1281 void wxListMainWindow::SelectLine( wxListLineData
*line
)
1283 SendNotify( line
, wxEVT_COMMAND_LIST_ITEM_SELECTED
);
1286 void wxListMainWindow::DeselectLine( wxListLineData
*line
)
1288 SendNotify( line
, wxEVT_COMMAND_LIST_ITEM_DESELECTED
);
1291 void wxListMainWindow::DeleteLine( wxListLineData
*line
)
1293 SendNotify( line
, wxEVT_COMMAND_LIST_DELETE_ITEM
);
1298 void wxListMainWindow::EditLabel( long item
)
1300 wxNode
*node
= m_lines
.Nth( (size_t)item
);
1301 wxCHECK_RET( node
, wxT("wrong index in wxListCtrl::Edit()") );
1303 m_currentEdit
= (wxListLineData
*) node
->Data();
1305 wxListEvent
le( wxEVT_COMMAND_LIST_BEGIN_LABEL_EDIT
, GetParent()->GetId() );
1306 le
.SetEventObject( GetParent() );
1307 le
.m_itemIndex
= GetIndexOfLine( m_currentEdit
);
1308 m_currentEdit
->GetItem( 0, le
.m_item
);
1309 GetParent()->GetEventHandler()->ProcessEvent( le
);
1311 if (!le
.IsAllowed())
1314 // We have to call this here because the label in
1315 // question might just have been added and no screen
1316 // update taken place.
1317 if (m_dirty
) wxYield();
1320 m_currentEdit
->GetText( 0, s
);
1325 m_currentEdit
->GetLabelExtent( x
, y
, w
, h
);
1327 wxClientDC
dc(this);
1329 x
= dc
.LogicalToDeviceX( x
);
1330 y
= dc
.LogicalToDeviceY( y
);
1332 wxListTextCtrl
*text
= new wxListTextCtrl(
1333 this, -1, &m_renameAccept
, &m_renameRes
, this, s
, wxPoint(x
-4,y
-4), wxSize(w
+11,h
+8) );
1337 void wxListMainWindow::OnRenameTimer()
1339 wxCHECK_RET( m_current
, wxT("invalid m_current") );
1341 Edit( m_lines
.IndexOf( m_current
) );
1344 void wxListMainWindow::OnRenameAccept()
1346 wxListEvent
le( wxEVT_COMMAND_LIST_END_LABEL_EDIT
, GetParent()->GetId() );
1347 le
.SetEventObject( GetParent() );
1348 le
.m_itemIndex
= GetIndexOfLine( m_currentEdit
);
1349 m_currentEdit
->GetItem( 0, le
.m_item
);
1350 le
.m_item
.m_text
= m_renameRes
;
1351 GetParent()->GetEventHandler()->ProcessEvent( le
);
1353 if (!le
.IsAllowed()) return;
1356 info
.m_mask
= wxLIST_MASK_TEXT
;
1357 info
.m_itemId
= le
.m_itemIndex
;
1358 info
.m_text
= m_renameRes
;
1359 info
.SetTextColour(le
.m_item
.GetTextColour());
1363 void wxListMainWindow::OnMouse( wxMouseEvent
&event
)
1365 if (GetParent()->GetEventHandler()->ProcessEvent( event
)) return;
1367 if (!m_current
) return;
1368 if (m_dirty
) return;
1369 if ( !(event
.Dragging() || event
.ButtonDown() || event
.LeftUp() || event
.ButtonDClick()) ) return;
1371 wxClientDC
dc(this);
1373 wxCoord x
= dc
.DeviceToLogicalX( (wxCoord
)event
.GetX() );
1374 wxCoord y
= dc
.DeviceToLogicalY( (wxCoord
)event
.GetY() );
1376 /* Did we actually hit an item ? */
1378 wxNode
*node
= m_lines
.First();
1379 wxListLineData
*line
= (wxListLineData
*) NULL
;
1382 line
= (wxListLineData
*)node
->Data();
1383 hitResult
= line
->IsHit( x
, y
);
1384 if (hitResult
) break;
1385 line
= (wxListLineData
*) NULL
;
1386 node
= node
->Next();
1389 if (event
.Dragging())
1391 if (m_dragCount
== 0)
1392 m_dragStart
= wxPoint(x
,y
);
1396 if (m_dragCount
!= 3) return;
1398 int command
= wxEVT_COMMAND_LIST_BEGIN_DRAG
;
1399 if (event
.RightIsDown()) command
= wxEVT_COMMAND_LIST_BEGIN_RDRAG
;
1401 wxListEvent
le( command
, GetParent()->GetId() );
1402 le
.SetEventObject( GetParent() );
1403 le
.m_pointDrag
= m_dragStart
;
1404 GetParent()->GetEventHandler()->ProcessEvent( le
);
1415 if (event
.ButtonDClick())
1418 m_lastOnSame
= FALSE
;
1419 m_renameTimer
->Stop();
1421 SendNotify( line
, wxEVT_COMMAND_LIST_ITEM_ACTIVATED
);
1426 if (event
.LeftUp() && m_lastOnSame
)
1429 if ((line
== m_current
) &&
1430 (hitResult
== wxLIST_HITTEST_ONITEMLABEL
) &&
1431 (m_mode
& wxLC_EDIT_LABELS
) )
1433 m_renameTimer
->Start( 100, TRUE
);
1435 m_lastOnSame
= FALSE
;
1439 if (event
.RightDown())
1441 SendNotify( line
, wxEVT_COMMAND_LIST_ITEM_RIGHT_CLICK
);
1445 if (event
.MiddleDown())
1447 SendNotify( line
, wxEVT_COMMAND_LIST_ITEM_MIDDLE_CLICK
);
1451 if (event
.LeftDown())
1454 wxListLineData
*oldCurrent
= m_current
;
1455 if (m_mode
& wxLC_SINGLE_SEL
)
1458 HilightAll( FALSE
);
1459 m_current
->ReverseHilight();
1460 RefreshLine( m_current
);
1464 if (event
.ShiftDown())
1467 m_current
->ReverseHilight();
1468 RefreshLine( m_current
);
1470 else if (event
.ControlDown())
1474 int numOfCurrent
= -1;
1475 node
= m_lines
.First();
1478 wxListLineData
*test_line
= (wxListLineData
*)node
->Data();
1480 if (test_line
== oldCurrent
) break;
1481 node
= node
->Next();
1485 node
= m_lines
.First();
1488 wxListLineData
*test_line
= (wxListLineData
*)node
->Data();
1490 if (test_line
== line
) break;
1491 node
= node
->Next();
1494 if (numOfLine
< numOfCurrent
)
1497 numOfLine
= numOfCurrent
;
1501 wxNode
*node
= m_lines
.Nth( numOfCurrent
);
1502 for (int i
= 0; i
<= numOfLine
-numOfCurrent
; i
++)
1504 wxListLineData
*test_line
= (wxListLineData
*)node
->Data();
1505 test_line
->Hilight(TRUE
);
1506 RefreshLine( test_line
);
1507 node
= node
->Next();
1513 HilightAll( FALSE
);
1514 m_current
->ReverseHilight();
1515 RefreshLine( m_current
);
1518 if (m_current
!= oldCurrent
)
1520 RefreshLine( oldCurrent
);
1521 UnfocusLine( oldCurrent
);
1522 FocusLine( m_current
);
1524 m_lastOnSame
= (m_current
== oldCurrent
);
1529 void wxListMainWindow::MoveToFocus()
1531 if (!m_current
) return;
1537 m_current
->GetExtent( x
, y
, w
, h
);
1541 GetClientSize( &w_p
, &h_p
);
1543 if (m_mode
& wxLC_REPORT
)
1545 int y_s
= m_yScroll
*GetScrollPos( wxVERTICAL
);
1546 if ((y
> y_s
) && (y
+h
< y_s
+h_p
)) return;
1547 if (y
-y_s
< 5) { Scroll( -1, (y
-5-h_p
/2)/m_yScroll
); }
1548 if (y
+h
+5 > y_s
+h_p
) { Scroll( -1, (y
+h
-h_p
/2+h
+15)/m_yScroll
); }
1552 int x_s
= m_xScroll
*GetScrollPos( wxHORIZONTAL
);
1553 if ((x
> x_s
) && (x
+w
< x_s
+w_p
)) return;
1554 if (x
-x_s
< 5) { Scroll( (x
-5)/m_xScroll
, -1 ); }
1555 if (x
+w
-5 > x_s
+w_p
) { Scroll( (x
+w
-w_p
+15)/m_xScroll
, -1 ); }
1559 void wxListMainWindow::OnArrowChar( wxListLineData
*newCurrent
, bool shiftDown
)
1561 if ((m_mode
& wxLC_SINGLE_SEL
) || (m_usedKeys
== FALSE
)) m_current
->Hilight( FALSE
);
1562 wxListLineData
*oldCurrent
= m_current
;
1563 m_current
= newCurrent
;
1565 if (shiftDown
|| (m_mode
& wxLC_SINGLE_SEL
)) m_current
->Hilight( TRUE
);
1566 RefreshLine( m_current
);
1567 RefreshLine( oldCurrent
);
1568 FocusLine( m_current
);
1569 UnfocusLine( oldCurrent
);
1572 void wxListMainWindow::OnKeyDown( wxKeyEvent
&event
)
1574 wxWindow
*parent
= GetParent();
1576 /* we propagate the key event up */
1577 wxKeyEvent
ke( wxEVT_KEY_DOWN
);
1578 ke
.m_shiftDown
= event
.m_shiftDown
;
1579 ke
.m_controlDown
= event
.m_controlDown
;
1580 ke
.m_altDown
= event
.m_altDown
;
1581 ke
.m_metaDown
= event
.m_metaDown
;
1582 ke
.m_keyCode
= event
.m_keyCode
;
1585 ke
.SetEventObject( parent
);
1586 if (parent
->GetEventHandler()->ProcessEvent( ke
)) return;
1591 void wxListMainWindow::OnChar( wxKeyEvent
&event
)
1593 wxWindow
*parent
= GetParent();
1595 /* we send a list_key event up */
1596 wxListEvent
le( wxEVT_COMMAND_LIST_KEY_DOWN
, GetParent()->GetId() );
1597 le
.m_code
= (int)event
.KeyCode();
1598 le
.SetEventObject( parent
);
1599 parent
->GetEventHandler()->ProcessEvent( le
);
1601 /* we propagate the char event up */
1602 wxKeyEvent
ke( wxEVT_CHAR
);
1603 ke
.m_shiftDown
= event
.m_shiftDown
;
1604 ke
.m_controlDown
= event
.m_controlDown
;
1605 ke
.m_altDown
= event
.m_altDown
;
1606 ke
.m_metaDown
= event
.m_metaDown
;
1607 ke
.m_keyCode
= event
.m_keyCode
;
1610 ke
.SetEventObject( parent
);
1611 if (parent
->GetEventHandler()->ProcessEvent( ke
)) return;
1613 if (event
.KeyCode() == WXK_TAB
)
1615 wxNavigationKeyEvent nevent
;
1616 nevent
.SetDirection( !event
.ShiftDown() );
1617 nevent
.SetCurrentFocus( m_parent
);
1618 if (m_parent
->GetEventHandler()->ProcessEvent( nevent
)) return;
1621 /* no item -> nothing to do */
1628 switch (event
.KeyCode())
1632 wxNode
*node
= m_lines
.Member( m_current
)->Previous();
1633 if (node
) OnArrowChar( (wxListLineData
*)node
->Data(), event
.ShiftDown() );
1638 wxNode
*node
= m_lines
.Member( m_current
)->Next();
1639 if (node
) OnArrowChar( (wxListLineData
*)node
->Data(), event
.ShiftDown() );
1644 wxNode
*node
= m_lines
.Last();
1645 OnArrowChar( (wxListLineData
*)node
->Data(), event
.ShiftDown() );
1650 wxNode
*node
= m_lines
.First();
1651 OnArrowChar( (wxListLineData
*)node
->Data(), event
.ShiftDown() );
1657 if (m_mode
& wxLC_REPORT
)
1659 steps
= m_visibleLines
-1;
1664 wxNode
*node
= m_lines
.First();
1665 for (;;) { if (m_current
== (wxListLineData
*)node
->Data()) break; pos
++; node
= node
->Next(); }
1666 steps
= pos
% m_visibleLines
;
1668 wxNode
*node
= m_lines
.Member( m_current
);
1669 for (int i
= 0; i
< steps
; i
++) if (node
->Previous()) node
= node
->Previous();
1670 if (node
) OnArrowChar( (wxListLineData
*)node
->Data(), event
.ShiftDown() );
1676 if (m_mode
& wxLC_REPORT
)
1678 steps
= m_visibleLines
-1;
1682 int pos
= 0; wxNode
*node
= m_lines
.First();
1683 for (;;) { if (m_current
== (wxListLineData
*)node
->Data()) break; pos
++; node
= node
->Next(); }
1684 steps
= m_visibleLines
-(pos
% m_visibleLines
)-1;
1686 wxNode
*node
= m_lines
.Member( m_current
);
1687 for (int i
= 0; i
< steps
; i
++) if (node
->Next()) node
= node
->Next();
1688 if (node
) OnArrowChar( (wxListLineData
*)node
->Data(), event
.ShiftDown() );
1693 if (!(m_mode
& wxLC_REPORT
))
1695 wxNode
*node
= m_lines
.Member( m_current
);
1696 for (int i
= 0; i
<m_visibleLines
; i
++) if (node
->Previous()) node
= node
->Previous();
1697 if (node
) OnArrowChar( (wxListLineData
*)node
->Data(), event
.ShiftDown() );
1703 if (!(m_mode
& wxLC_REPORT
))
1705 wxNode
*node
= m_lines
.Member( m_current
);
1706 for (int i
= 0; i
<m_visibleLines
; i
++) if (node
->Next()) node
= node
->Next();
1707 if (node
) OnArrowChar( (wxListLineData
*)node
->Data(), event
.ShiftDown() );
1713 m_current
->ReverseHilight();
1714 RefreshLine( m_current
);
1719 if (!(m_mode
& wxLC_SINGLE_SEL
))
1721 wxListLineData
*oldCurrent
= m_current
;
1722 m_current
->ReverseHilight();
1723 wxNode
*node
= m_lines
.Member( m_current
)->Next();
1724 if (node
) m_current
= (wxListLineData
*)node
->Data();
1726 RefreshLine( oldCurrent
);
1727 RefreshLine( m_current
);
1728 UnfocusLine( oldCurrent
);
1729 FocusLine( m_current
);
1736 wxListEvent
le( wxEVT_COMMAND_LIST_ITEM_ACTIVATED
, GetParent()->GetId() );
1737 le
.SetEventObject( GetParent() );
1738 le
.m_itemIndex
= GetIndexOfLine( m_current
);
1739 m_current
->GetItem( 0, le
.m_item
);
1740 GetParent()->GetEventHandler()->ProcessEvent( le
);
1753 extern wxWindow
*g_focusWindow
;
1756 void wxListMainWindow::OnSetFocus( wxFocusEvent
&WXUNUSED(event
) )
1759 RefreshLine( m_current
);
1761 if (!GetParent()) return;
1764 g_focusWindow
= GetParent();
1767 wxFocusEvent
event( wxEVT_SET_FOCUS
, GetParent()->GetId() );
1768 event
.SetEventObject( GetParent() );
1769 GetParent()->GetEventHandler()->ProcessEvent( event
);
1772 void wxListMainWindow::OnKillFocus( wxFocusEvent
&WXUNUSED(event
) )
1775 RefreshLine( m_current
);
1778 void wxListMainWindow::OnSize( wxSizeEvent
&WXUNUSED(event
) )
1781 We don't even allow the wxScrolledWindow::AdjustScrollbars() call
1786 void wxListMainWindow::DrawImage( int index
, wxDC
*dc
, int x
, int y
)
1788 if ((m_mode
& wxLC_ICON
) && (m_normal_image_list
))
1790 m_normal_image_list
->Draw( index
, *dc
, x
, y
, wxIMAGELIST_DRAW_TRANSPARENT
);
1793 if ((m_mode
& wxLC_SMALL_ICON
) && (m_small_image_list
))
1795 m_small_image_list
->Draw( index
, *dc
, x
, y
, wxIMAGELIST_DRAW_TRANSPARENT
);
1797 if ((m_mode
& wxLC_LIST
) && (m_small_image_list
))
1799 m_small_image_list
->Draw( index
, *dc
, x
, y
, wxIMAGELIST_DRAW_TRANSPARENT
);
1801 if ((m_mode
& wxLC_REPORT
) && (m_small_image_list
))
1803 m_small_image_list
->Draw( index
, *dc
, x
, y
, wxIMAGELIST_DRAW_TRANSPARENT
);
1808 void wxListMainWindow::GetImageSize( int index
, int &width
, int &height
)
1810 if ((m_mode
& wxLC_ICON
) && (m_normal_image_list
))
1812 m_normal_image_list
->GetSize( index
, width
, height
);
1815 if ((m_mode
& wxLC_SMALL_ICON
) && (m_small_image_list
))
1817 m_small_image_list
->GetSize( index
, width
, height
);
1820 if ((m_mode
& wxLC_LIST
) && (m_small_image_list
))
1822 m_small_image_list
->GetSize( index
, width
, height
);
1825 if ((m_mode
& wxLC_REPORT
) && (m_small_image_list
))
1827 m_small_image_list
->GetSize( index
, width
, height
);
1834 int wxListMainWindow::GetTextLength( wxString
&s
)
1836 wxClientDC
dc( this );
1839 dc
.GetTextExtent( s
, &lw
, &lh
);
1843 int wxListMainWindow::GetIndexOfLine( const wxListLineData
*line
)
1846 wxNode
*node
= m_lines
.First();
1849 if (line
== (wxListLineData
*)node
->Data()) return i
;
1851 node
= node
->Next();
1856 void wxListMainWindow::SetImageList( wxImageList
*imageList
, int which
)
1859 if (which
== wxIMAGE_LIST_NORMAL
) m_normal_image_list
= imageList
;
1860 if (which
== wxIMAGE_LIST_SMALL
) m_small_image_list
= imageList
;
1863 void wxListMainWindow::SetItemSpacing( int spacing
, bool isSmall
)
1868 m_small_spacing
= spacing
;
1872 m_normal_spacing
= spacing
;
1876 int wxListMainWindow::GetItemSpacing( bool isSmall
)
1878 if (isSmall
) return m_small_spacing
; else return m_normal_spacing
;
1881 void wxListMainWindow::SetColumn( int col
, wxListItem
&item
)
1884 wxNode
*node
= m_columns
.Nth( col
);
1887 if (item
.m_width
== wxLIST_AUTOSIZE_USEHEADER
) item
.m_width
= GetTextLength( item
.m_text
)+7;
1888 wxListHeaderData
*column
= (wxListHeaderData
*)node
->Data();
1889 column
->SetItem( item
);
1891 wxListCtrl
*lc
= (wxListCtrl
*) GetParent();
1892 if (lc
->m_headerWin
) lc
->m_headerWin
->Refresh();
1895 void wxListMainWindow::SetColumnWidth( int col
, int width
)
1897 if (!(m_mode
& wxLC_REPORT
)) return;
1901 wxNode
*node
= (wxNode
*) NULL
;
1903 if (width
== wxLIST_AUTOSIZE_USEHEADER
) width
= 80;
1904 if (width
== wxLIST_AUTOSIZE
)
1906 wxClientDC
dc(this);
1907 dc
.SetFont( GetFont() );
1909 node
= m_lines
.First();
1912 wxListLineData
*line
= (wxListLineData
*)node
->Data();
1913 wxNode
*n
= line
->m_items
.Nth( col
);
1916 wxListItemData
*item
= (wxListItemData
*)n
->Data();
1917 int current
= 0, ix
= 0, iy
= 0;
1918 wxCoord lx
= 0, ly
= 0;
1919 if (item
->HasImage())
1921 GetImageSize( item
->GetImage(), ix
, iy
);
1924 if (item
->HasText())
1927 item
->GetText( str
);
1928 dc
.GetTextExtent( str
, &lx
, &ly
);
1931 if (current
> max
) max
= current
;
1933 node
= node
->Next();
1938 node
= m_columns
.Nth( col
);
1941 wxListHeaderData
*column
= (wxListHeaderData
*)node
->Data();
1942 column
->SetWidth( width
);
1945 node
= m_lines
.First();
1948 wxListLineData
*line
= (wxListLineData
*)node
->Data();
1949 wxNode
*n
= line
->m_items
.Nth( col
);
1952 wxListItemData
*item
= (wxListItemData
*)n
->Data();
1953 item
->SetSize( width
, -1 );
1955 node
= node
->Next();
1958 wxListCtrl
*lc
= (wxListCtrl
*) GetParent();
1959 if (lc
->m_headerWin
) lc
->m_headerWin
->Refresh();
1962 void wxListMainWindow::GetColumn( int col
, wxListItem
&item
)
1964 wxNode
*node
= m_columns
.Nth( col
);
1967 wxListHeaderData
*column
= (wxListHeaderData
*)node
->Data();
1968 column
->GetItem( item
);
1980 int wxListMainWindow::GetColumnWidth( int col
)
1982 wxNode
*node
= m_columns
.Nth( col
);
1985 wxListHeaderData
*column
= (wxListHeaderData
*)node
->Data();
1986 return column
->GetWidth();
1994 int wxListMainWindow::GetColumnCount()
1996 return m_columns
.Number();
1999 int wxListMainWindow::GetCountPerPage()
2001 return m_visibleLines
;
2004 void wxListMainWindow::SetItem( wxListItem
&item
)
2007 wxNode
*node
= m_lines
.Nth( (size_t)item
.m_itemId
);
2010 wxListLineData
*line
= (wxListLineData
*)node
->Data();
2011 if (m_mode
& wxLC_REPORT
) item
.m_width
= GetColumnWidth( item
.m_col
)-3;
2012 line
->SetItem( item
.m_col
, item
);
2016 void wxListMainWindow::SetItemState( long item
, long state
, long stateMask
)
2018 // m_dirty = TRUE; no recalcs needed
2020 wxListLineData
*oldCurrent
= m_current
;
2022 if (stateMask
& wxLIST_STATE_FOCUSED
)
2024 wxNode
*node
= m_lines
.Nth( (size_t)item
);
2027 wxListLineData
*line
= (wxListLineData
*)node
->Data();
2028 UnfocusLine( m_current
);
2030 FocusLine( m_current
);
2031 RefreshLine( m_current
);
2032 if (oldCurrent
) RefreshLine( oldCurrent
);
2036 if (stateMask
& wxLIST_STATE_SELECTED
)
2038 bool on
= (state
& wxLIST_STATE_SELECTED
) != 0;
2039 if (!on
&& (m_mode
& wxLC_SINGLE_SEL
)) return;
2041 wxNode
*node
= m_lines
.Nth( (size_t)item
);
2044 wxListLineData
*line
= (wxListLineData
*)node
->Data();
2045 if (m_mode
& wxLC_SINGLE_SEL
)
2047 UnfocusLine( m_current
);
2049 FocusLine( m_current
);
2050 if (oldCurrent
) oldCurrent
->Hilight( FALSE
);
2051 RefreshLine( m_current
);
2052 if (oldCurrent
) RefreshLine( oldCurrent
);
2054 bool on
= (state
& wxLIST_STATE_SELECTED
) != 0;
2055 if (on
!= line
->IsHilighted())
2057 line
->Hilight( on
);
2058 RefreshLine( line
);
2064 int wxListMainWindow::GetItemState( long item
, long stateMask
)
2066 int ret
= wxLIST_STATE_DONTCARE
;
2067 if (stateMask
& wxLIST_STATE_FOCUSED
)
2069 wxNode
*node
= m_lines
.Nth( (size_t)item
);
2072 wxListLineData
*line
= (wxListLineData
*)node
->Data();
2073 if (line
== m_current
) ret
|= wxLIST_STATE_FOCUSED
;
2076 if (stateMask
& wxLIST_STATE_SELECTED
)
2078 wxNode
*node
= m_lines
.Nth( (size_t)item
);
2081 wxListLineData
*line
= (wxListLineData
*)node
->Data();
2082 if (line
->IsHilighted()) ret
|= wxLIST_STATE_FOCUSED
;
2088 void wxListMainWindow::GetItem( wxListItem
&item
)
2090 wxNode
*node
= m_lines
.Nth( (size_t)item
.m_itemId
);
2093 wxListLineData
*line
= (wxListLineData
*)node
->Data();
2094 line
->GetItem( item
.m_col
, item
);
2105 int wxListMainWindow::GetItemCount()
2107 return m_lines
.Number();
2110 void wxListMainWindow::GetItemRect( long index
, wxRect
&rect
)
2112 wxNode
*node
= m_lines
.Nth( (size_t)index
);
2115 wxListLineData
*line
= (wxListLineData
*)node
->Data();
2116 line
->GetRect( rect
);
2127 bool wxListMainWindow::GetItemPosition(long item
, wxPoint
& pos
)
2129 wxNode
*node
= m_lines
.Nth( (size_t)item
);
2133 wxListLineData
*line
= (wxListLineData
*)node
->Data();
2134 line
->GetRect( rect
);
2146 int wxListMainWindow::GetSelectedItemCount()
2149 wxNode
*node
= m_lines
.First();
2152 wxListLineData
*line
= (wxListLineData
*)node
->Data();
2153 if (line
->IsHilighted()) ret
++;
2154 node
= node
->Next();
2159 void wxListMainWindow::SetMode( long mode
)
2166 if (m_mode
& wxLC_REPORT
)
2168 #if wxUSE_GENERIC_LIST_EXTENSIONS
2182 long wxListMainWindow::GetMode() const
2187 void wxListMainWindow::CalculatePositions()
2189 if (!m_lines
.First()) return;
2191 wxClientDC
dc( this );
2192 dc
.SetFont( GetFont() );
2194 int iconSpacing
= 0;
2195 if (m_mode
& wxLC_ICON
) iconSpacing
= m_normal_spacing
;
2196 if (m_mode
& wxLC_SMALL_ICON
) iconSpacing
= m_small_spacing
;
2198 // we take the first line (which also can be an icon or
2199 // an a text item in wxLC_ICON and wxLC_LIST modes) to
2200 // measure the size of the line
2204 int lineSpacing
= 0;
2206 wxListLineData
*line
= (wxListLineData
*)m_lines
.First()->Data();
2207 line
->CalculateSize( &dc
, iconSpacing
);
2209 line
->GetSize( dummy
, lineSpacing
);
2212 int clientWidth
= 0;
2213 int clientHeight
= 0;
2215 if (m_mode
& wxLC_REPORT
)
2219 int entireHeight
= m_lines
.Number() * lineSpacing
+ 2;
2220 int scroll_pos
= GetScrollPos( wxVERTICAL
);
2221 #if wxUSE_GENERIC_LIST_EXTENSIONS
2222 int x_scroll_pos
= GetScrollPos( wxHORIZONTAL
);
2224 SetScrollbars( m_xScroll
, m_yScroll
, 0, (entireHeight
+15) / m_yScroll
, 0, scroll_pos
, TRUE
);
2226 GetClientSize( &clientWidth
, &clientHeight
);
2228 wxNode
* node
= m_lines
.First();
2229 int entireWidth
= 0 ;
2232 wxListLineData
*line
= (wxListLineData
*)node
->Data();
2233 line
->CalculateSize( &dc
, iconSpacing
);
2234 line
->SetPosition( &dc
, x
, y
, clientWidth
);
2236 for (int i
= 0; i
< GetColumnCount(); i
++)
2238 line
->SetColumnPosition( i
, col_x
);
2239 col_x
+= GetColumnWidth( i
);
2241 entireWidth
= wxMax( entireWidth
, col_x
) ;
2242 #if wxUSE_GENERIC_LIST_EXTENSIONS
2243 line
->SetPosition( &dc
, x
, y
, col_x
);
2245 y
+= lineSpacing
; // one pixel blank line between items
2246 node
= node
->Next();
2248 m_visibleLines
= clientHeight
/ lineSpacing
;
2249 #if wxUSE_GENERIC_LIST_EXTENSIONS
2250 SetScrollbars( m_xScroll
, m_yScroll
, entireWidth
/ m_xScroll
, (entireHeight
+15) / m_yScroll
, x_scroll_pos
, scroll_pos
, TRUE
);
2255 // at first we try without any scrollbar. if the items don't
2256 // fit into the window, we recalculate after subtracting an
2257 // approximated 15 pt for the horizontal scrollbar
2259 GetSize( &clientWidth
, &clientHeight
);
2260 clientHeight
-= 4; // sunken frame
2262 int entireWidth
= 0;
2264 for (int tries
= 0; tries
< 2; tries
++)
2267 int x
= 5; // painting is done at x-2
2268 int y
= 5; // painting is done at y-2
2271 int m_currentVisibleLines
= 0;
2272 wxNode
*node
= m_lines
.First();
2275 m_currentVisibleLines
++;
2276 wxListLineData
*line
= (wxListLineData
*)node
->Data();
2277 line
->CalculateSize( &dc
, iconSpacing
);
2278 line
->SetPosition( &dc
, x
, y
, clientWidth
);
2279 line
->GetSize( lineWidth
, lineHeight
);
2280 if (lineWidth
> maxWidth
) maxWidth
= lineWidth
;
2282 if (m_currentVisibleLines
> m_visibleLines
)
2283 m_visibleLines
= m_currentVisibleLines
;
2284 if (y
+lineSpacing
-6 >= clientHeight
) // -6 for earlier "line breaking"
2286 m_currentVisibleLines
= 0;
2289 entireWidth
+= maxWidth
+6;
2292 node
= node
->Next();
2293 if (!node
) entireWidth
+= maxWidth
;
2294 if ((tries
== 0) && (entireWidth
> clientWidth
))
2296 clientHeight
-= 15; // scrollbar height
2298 m_currentVisibleLines
= 0;
2301 if (!node
) tries
= 1; // everything fits, no second try required
2305 int scroll_pos
= GetScrollPos( wxHORIZONTAL
);
2306 SetScrollbars( m_xScroll
, m_yScroll
, (entireWidth
+15) / m_xScroll
, 0, scroll_pos
, 0, TRUE
);
2310 void wxListMainWindow::RealizeChanges( void )
2314 wxNode
*node
= m_lines
.First();
2315 if (node
) m_current
= (wxListLineData
*)node
->Data();
2319 FocusLine( m_current
);
2320 if (m_mode
& wxLC_SINGLE_SEL
) m_current
->Hilight( TRUE
);
2324 long wxListMainWindow::GetNextItem( long item
, int WXUNUSED(geometry
), int state
)
2327 if (item
> 0) ret
= item
;
2328 if(ret
>= GetItemCount()) return -1;
2329 wxNode
*node
= m_lines
.Nth( (size_t)ret
);
2332 wxListLineData
*line
= (wxListLineData
*)node
->Data();
2333 if ((state
& wxLIST_STATE_FOCUSED
) && (line
== m_current
)) return ret
;
2334 if ((state
& wxLIST_STATE_SELECTED
) && (line
->IsHilighted())) return ret
;
2335 if (!state
) return ret
;
2337 node
= node
->Next();
2342 void wxListMainWindow::DeleteItem( long index
)
2345 wxNode
*node
= m_lines
.Nth( (size_t)index
);
2348 wxListLineData
*line
= (wxListLineData
*)node
->Data();
2349 if (m_current
== line
) m_current
= (wxListLineData
*) NULL
;
2351 m_lines
.DeleteNode( node
);
2355 void wxListMainWindow::DeleteColumn( int col
)
2357 wxCHECK_RET( col
< (int)m_columns
.GetCount(),
2358 wxT("attempting to delete inexistent column in wxListView") );
2361 wxNode
*node
= m_columns
.Nth( col
);
2362 if (node
) m_columns
.DeleteNode( node
);
2365 void wxListMainWindow::DeleteAllItems( void )
2368 m_current
= (wxListLineData
*) NULL
;
2370 // to make the deletion of all items faster, we don't send the
2371 // notifications in this case: this is compatible with wxMSW and
2372 // documented in DeleteAllItems() description
2374 wxNode
*node
= m_lines
.First();
2377 wxListLineData
*line
= (wxListLineData
*)node
->Data();
2381 node
= node
->Next();
2388 void wxListMainWindow::DeleteEverything( void )
2391 m_current
= (wxListLineData
*) NULL
;
2392 wxNode
*node
= m_lines
.First();
2395 wxListLineData
*line
= (wxListLineData
*)node
->Data();
2397 node
= node
->Next();
2400 m_current
= (wxListLineData
*) NULL
;
2404 void wxListMainWindow::EnsureVisible( long index
)
2406 // We have to call this here because the label in
2407 // question might just have been added and no screen
2408 // update taken place.
2409 if (m_dirty
) wxYield();
2411 wxListLineData
*oldCurrent
= m_current
;
2412 m_current
= (wxListLineData
*) NULL
;
2413 wxNode
*node
= m_lines
.Nth( (size_t)index
);
2414 if (node
) m_current
= (wxListLineData
*)node
->Data();
2415 if (m_current
) MoveToFocus();
2416 m_current
= oldCurrent
;
2419 long wxListMainWindow::FindItem(long start
, const wxString
& str
, bool WXUNUSED(partial
) )
2423 if (pos
< 0) pos
= 0;
2424 wxNode
*node
= m_lines
.Nth( (size_t)pos
);
2427 wxListLineData
*line
= (wxListLineData
*)node
->Data();
2429 line
->GetText( 0, s
);
2430 if (s
== tmp
) return pos
;
2431 node
= node
->Next();
2437 long wxListMainWindow::FindItem(long start
, long data
)
2440 if (pos
< 0) pos
= 0;
2441 wxNode
*node
= m_lines
.Nth( (size_t)pos
);
2444 wxListLineData
*line
= (wxListLineData
*)node
->Data();
2446 line
->GetItem( 0, item
);
2447 if (item
.m_data
== data
) return pos
;
2448 node
= node
->Next();
2454 long wxListMainWindow::HitTest( int x
, int y
, int &flags
)
2456 wxNode
*node
= m_lines
.First();
2460 wxListLineData
*line
= (wxListLineData
*)node
->Data();
2461 long ret
= line
->IsHit( x
, y
);
2467 node
= node
->Next();
2473 void wxListMainWindow::InsertItem( wxListItem
&item
)
2477 if (m_mode
& wxLC_REPORT
) mode
= wxLC_REPORT
;
2478 else if (m_mode
& wxLC_LIST
) mode
= wxLC_LIST
;
2479 else if (m_mode
& wxLC_ICON
) mode
= wxLC_ICON
;
2480 else if (m_mode
& wxLC_SMALL_ICON
) mode
= wxLC_ICON
; // no typo
2482 wxListLineData
*line
= new wxListLineData( this, mode
, m_hilightBrush
);
2484 if (m_mode
& wxLC_REPORT
)
2486 line
->InitItems( GetColumnCount() );
2487 item
.m_width
= GetColumnWidth( 0 )-3;
2491 line
->InitItems( 1 );
2494 line
->SetItem( 0, item
);
2495 if ((item
.m_itemId
>= 0) && (item
.m_itemId
< (int)m_lines
.GetCount()))
2497 wxNode
*node
= m_lines
.Nth( (size_t)item
.m_itemId
);
2498 if (node
) m_lines
.Insert( node
, line
);
2502 m_lines
.Append( line
);
2506 void wxListMainWindow::InsertColumn( long col
, wxListItem
&item
)
2509 if (m_mode
& wxLC_REPORT
)
2511 if (item
.m_width
== wxLIST_AUTOSIZE_USEHEADER
) item
.m_width
= GetTextLength( item
.m_text
);
2512 wxListHeaderData
*column
= new wxListHeaderData( item
);
2513 if ((col
>= 0) && (col
< (int)m_columns
.GetCount()))
2515 wxNode
*node
= m_columns
.Nth( (size_t)col
);
2517 m_columns
.Insert( node
, column
);
2521 m_columns
.Append( column
);
2526 wxListCtrlCompare list_ctrl_compare_func_2
;
2527 long list_ctrl_compare_data
;
2529 int LINKAGEMODE
list_ctrl_compare_func_1( const void *arg1
, const void *arg2
)
2531 wxListLineData
*line1
= *((wxListLineData
**)arg1
);
2532 wxListLineData
*line2
= *((wxListLineData
**)arg2
);
2534 line1
->GetItem( 0, item
);
2535 long data1
= item
.m_data
;
2536 line2
->GetItem( 0, item
);
2537 long data2
= item
.m_data
;
2538 return list_ctrl_compare_func_2( data1
, data2
, list_ctrl_compare_data
);
2541 void wxListMainWindow::SortItems( wxListCtrlCompare fn
, long data
)
2543 list_ctrl_compare_func_2
= fn
;
2544 list_ctrl_compare_data
= data
;
2545 m_lines
.Sort( list_ctrl_compare_func_1
);
2548 void wxListMainWindow::OnScroll(wxScrollWinEvent
& event
)
2550 wxScrolledWindow::OnScroll( event
) ;
2551 #if wxUSE_GENERIC_LIST_EXTENSIONS
2553 if (event
.GetOrientation() == wxHORIZONTAL
&& ( m_mode
& wxLC_REPORT
))
2555 wxListCtrl
* lc
= wxDynamicCast( GetParent() , wxListCtrl
) ;
2558 lc
->m_headerWin
->Refresh() ;
2560 lc
->m_headerWin
->MacUpdateImmediately() ;
2567 // -------------------------------------------------------------------------------------
2569 // -------------------------------------------------------------------------------------
2571 IMPLEMENT_DYNAMIC_CLASS(wxListItem
, wxObject
)
2573 wxListItem::wxListItem()
2582 m_format
= wxLIST_FORMAT_CENTRE
;
2588 void wxListItem::Clear()
2597 m_format
= wxLIST_FORMAT_CENTRE
;
2599 m_text
= wxEmptyString
;
2601 if (m_attr
) delete m_attr
;
2605 void wxListItem::ClearAttributes()
2607 if (m_attr
) delete m_attr
;
2611 // -------------------------------------------------------------------------------------
2613 // -------------------------------------------------------------------------------------
2615 IMPLEMENT_DYNAMIC_CLASS(wxListEvent
, wxNotifyEvent
)
2617 wxListEvent::wxListEvent( wxEventType commandType
, int id
):
2618 wxNotifyEvent( commandType
, id
)
2624 m_cancelled
= FALSE
;
2629 void wxListEvent::CopyObject(wxObject
& object_dest
) const
2631 wxListEvent
*obj
= (wxListEvent
*)&object_dest
;
2633 wxNotifyEvent::CopyObject(object_dest
);
2635 obj
->m_code
= m_code
;
2636 obj
->m_itemIndex
= m_itemIndex
;
2637 obj
->m_oldItemIndex
= m_oldItemIndex
;
2639 obj
->m_cancelled
= m_cancelled
;
2640 obj
->m_pointDrag
= m_pointDrag
;
2641 obj
->m_item
.m_mask
= m_item
.m_mask
;
2642 obj
->m_item
.m_itemId
= m_item
.m_itemId
;
2643 obj
->m_item
.m_col
= m_item
.m_col
;
2644 obj
->m_item
.m_state
= m_item
.m_state
;
2645 obj
->m_item
.m_stateMask
= m_item
.m_stateMask
;
2646 obj
->m_item
.m_text
= m_item
.m_text
;
2647 obj
->m_item
.m_image
= m_item
.m_image
;
2648 obj
->m_item
.m_data
= m_item
.m_data
;
2649 obj
->m_item
.m_format
= m_item
.m_format
;
2650 obj
->m_item
.m_width
= m_item
.m_width
;
2652 if ( m_item
.HasAttributes() )
2654 obj
->m_item
.SetTextColour(m_item
.GetTextColour());
2658 // -------------------------------------------------------------------------------------
2660 // -------------------------------------------------------------------------------------
2662 IMPLEMENT_DYNAMIC_CLASS(wxListCtrl
, wxControl
)
2664 BEGIN_EVENT_TABLE(wxListCtrl
,wxControl
)
2665 EVT_SIZE (wxListCtrl::OnSize
)
2666 EVT_IDLE (wxListCtrl::OnIdle
)
2669 wxListCtrl::wxListCtrl()
2671 m_imageListNormal
= (wxImageList
*) NULL
;
2672 m_imageListSmall
= (wxImageList
*) NULL
;
2673 m_imageListState
= (wxImageList
*) NULL
;
2674 m_mainWin
= (wxListMainWindow
*) NULL
;
2675 m_headerWin
= (wxListHeaderWindow
*) NULL
;
2678 wxListCtrl::~wxListCtrl()
2682 bool wxListCtrl::Create(wxWindow
*parent
,
2687 const wxValidator
&validator
,
2688 const wxString
&name
)
2690 m_imageListNormal
= (wxImageList
*) NULL
;
2691 m_imageListSmall
= (wxImageList
*) NULL
;
2692 m_imageListState
= (wxImageList
*) NULL
;
2693 m_mainWin
= (wxListMainWindow
*) NULL
;
2694 m_headerWin
= (wxListHeaderWindow
*) NULL
;
2696 if ( !(style
& (wxLC_REPORT
| wxLC_LIST
| wxLC_ICON
)) )
2698 style
= style
| wxLC_LIST
;
2701 bool ret
= wxControl::Create( parent
, id
, pos
, size
, style
, validator
, name
);
2704 if (style
& wxSUNKEN_BORDER
)
2705 style
-= wxSUNKEN_BORDER
;
2707 m_mainWin
= new wxListMainWindow( this, -1, wxPoint(0,0), size
, style
);
2709 if (HasFlag(wxLC_REPORT
))
2710 m_headerWin
= new wxListHeaderWindow( this, -1, m_mainWin
, wxPoint(0,0), wxSize(size
.x
,23), wxTAB_TRAVERSAL
);
2712 m_headerWin
= (wxListHeaderWindow
*) NULL
;
2714 SetBackgroundColour( *wxWHITE
);
2719 void wxListCtrl::OnSize( wxSizeEvent
&WXUNUSED(event
) )
2721 /* handled in OnIdle */
2723 if (m_mainWin
) m_mainWin
->m_dirty
= TRUE
;
2726 void wxListCtrl::SetSingleStyle( long style
, bool add
)
2728 long flag
= GetWindowStyle();
2732 if (style
& wxLC_MASK_TYPE
) flag
= flag
& ~wxLC_MASK_TYPE
;
2733 if (style
& wxLC_MASK_ALIGN
) flag
= flag
& ~wxLC_MASK_ALIGN
;
2734 if (style
& wxLC_MASK_SORT
) flag
= flag
& ~wxLC_MASK_SORT
;
2743 if (flag
& style
) flag
-= style
;
2746 SetWindowStyleFlag( flag
);
2749 void wxListCtrl::SetWindowStyleFlag( long flag
)
2753 m_mainWin
->DeleteEverything();
2757 GetClientSize( &width
, &height
);
2759 m_mainWin
->SetMode( flag
);
2761 if (flag
& wxLC_REPORT
)
2763 if (!HasFlag(wxLC_REPORT
))
2767 m_headerWin
= new wxListHeaderWindow( this, -1, m_mainWin
,
2768 wxPoint(0,0), wxSize(width
,23), wxTAB_TRAVERSAL
);
2769 if (HasFlag(wxLC_NO_HEADER
))
2770 m_headerWin
->Show( FALSE
);
2774 if (flag
& wxLC_NO_HEADER
)
2775 m_headerWin
->Show( FALSE
);
2777 m_headerWin
->Show( TRUE
);
2783 if (HasFlag(wxLC_REPORT
) && !(HasFlag(wxLC_NO_HEADER
)))
2785 m_headerWin
->Show( FALSE
);
2790 wxWindow::SetWindowStyleFlag( flag
);
2793 bool wxListCtrl::GetColumn(int col
, wxListItem
&item
) const
2795 m_mainWin
->GetColumn( col
, item
);
2799 bool wxListCtrl::SetColumn( int col
, wxListItem
& item
)
2801 m_mainWin
->SetColumn( col
, item
);
2805 int wxListCtrl::GetColumnWidth( int col
) const
2807 return m_mainWin
->GetColumnWidth( col
);
2810 bool wxListCtrl::SetColumnWidth( int col
, int width
)
2812 m_mainWin
->SetColumnWidth( col
, width
);
2816 int wxListCtrl::GetCountPerPage() const
2818 return m_mainWin
->GetCountPerPage(); // different from Windows ?
2821 bool wxListCtrl::GetItem( wxListItem
&info
) const
2823 m_mainWin
->GetItem( info
);
2827 bool wxListCtrl::SetItem( wxListItem
&info
)
2829 m_mainWin
->SetItem( info
);
2833 long wxListCtrl::SetItem( long index
, int col
, const wxString
& label
, int imageId
)
2836 info
.m_text
= label
;
2837 info
.m_mask
= wxLIST_MASK_TEXT
;
2838 info
.m_itemId
= index
;
2842 info
.m_image
= imageId
;
2843 info
.m_mask
|= wxLIST_MASK_IMAGE
;
2845 m_mainWin
->SetItem(info
);
2849 int wxListCtrl::GetItemState( long item
, long stateMask
) const
2851 return m_mainWin
->GetItemState( item
, stateMask
);
2854 bool wxListCtrl::SetItemState( long item
, long state
, long stateMask
)
2856 m_mainWin
->SetItemState( item
, state
, stateMask
);
2860 bool wxListCtrl::SetItemImage( long item
, int image
, int WXUNUSED(selImage
) )
2863 info
.m_image
= image
;
2864 info
.m_mask
= wxLIST_MASK_IMAGE
;
2865 info
.m_itemId
= item
;
2866 m_mainWin
->SetItem( info
);
2870 wxString
wxListCtrl::GetItemText( long item
) const
2873 info
.m_itemId
= item
;
2874 m_mainWin
->GetItem( info
);
2878 void wxListCtrl::SetItemText( long item
, const wxString
&str
)
2881 info
.m_mask
= wxLIST_MASK_TEXT
;
2882 info
.m_itemId
= item
;
2884 m_mainWin
->SetItem( info
);
2887 long wxListCtrl::GetItemData( long item
) const
2890 info
.m_itemId
= item
;
2891 m_mainWin
->GetItem( info
);
2895 bool wxListCtrl::SetItemData( long item
, long data
)
2898 info
.m_mask
= wxLIST_MASK_DATA
;
2899 info
.m_itemId
= item
;
2901 m_mainWin
->SetItem( info
);
2905 bool wxListCtrl::GetItemRect( long item
, wxRect
&rect
, int WXUNUSED(code
) ) const
2907 m_mainWin
->GetItemRect( item
, rect
);
2911 bool wxListCtrl::GetItemPosition( long item
, wxPoint
& pos
) const
2913 m_mainWin
->GetItemPosition( item
, pos
);
2917 bool wxListCtrl::SetItemPosition( long WXUNUSED(item
), const wxPoint
& WXUNUSED(pos
) )
2922 int wxListCtrl::GetItemCount() const
2924 return m_mainWin
->GetItemCount();
2927 int wxListCtrl::GetColumnCount() const
2929 return m_mainWin
->GetColumnCount();
2932 void wxListCtrl::SetItemSpacing( int spacing
, bool isSmall
)
2934 m_mainWin
->SetItemSpacing( spacing
, isSmall
);
2937 int wxListCtrl::GetItemSpacing( bool isSmall
) const
2939 return m_mainWin
->GetItemSpacing( isSmall
);
2942 int wxListCtrl::GetSelectedItemCount() const
2944 return m_mainWin
->GetSelectedItemCount();
2947 wxColour
wxListCtrl::GetTextColour() const
2949 return GetForegroundColour();
2952 void wxListCtrl::SetTextColour(const wxColour
& col
)
2954 SetForegroundColour(col
);
2957 long wxListCtrl::GetTopItem() const
2962 long wxListCtrl::GetNextItem( long item
, int geom
, int state
) const
2964 return m_mainWin
->GetNextItem( item
, geom
, state
);
2967 wxImageList
*wxListCtrl::GetImageList(int which
) const
2969 if (which
== wxIMAGE_LIST_NORMAL
)
2971 return m_imageListNormal
;
2973 else if (which
== wxIMAGE_LIST_SMALL
)
2975 return m_imageListSmall
;
2977 else if (which
== wxIMAGE_LIST_STATE
)
2979 return m_imageListState
;
2981 return (wxImageList
*) NULL
;
2984 void wxListCtrl::SetImageList( wxImageList
*imageList
, int which
)
2986 m_mainWin
->SetImageList( imageList
, which
);
2989 bool wxListCtrl::Arrange( int WXUNUSED(flag
) )
2994 bool wxListCtrl::DeleteItem( long item
)
2996 m_mainWin
->DeleteItem( item
);
3000 bool wxListCtrl::DeleteAllItems()
3002 m_mainWin
->DeleteAllItems();
3006 bool wxListCtrl::DeleteAllColumns()
3008 for ( size_t n
= 0; n
< m_mainWin
->m_columns
.GetCount(); n
++ )
3014 void wxListCtrl::ClearAll()
3016 m_mainWin
->DeleteEverything();
3019 bool wxListCtrl::DeleteColumn( int col
)
3021 m_mainWin
->DeleteColumn( col
);
3025 void wxListCtrl::Edit( long item
)
3027 m_mainWin
->Edit( item
);
3030 bool wxListCtrl::EnsureVisible( long item
)
3032 m_mainWin
->EnsureVisible( item
);
3036 long wxListCtrl::FindItem( long start
, const wxString
& str
, bool partial
)
3038 return m_mainWin
->FindItem( start
, str
, partial
);
3041 long wxListCtrl::FindItem( long start
, long data
)
3043 return m_mainWin
->FindItem( start
, data
);
3046 long wxListCtrl::FindItem( long WXUNUSED(start
), const wxPoint
& WXUNUSED(pt
),
3047 int WXUNUSED(direction
))
3052 long wxListCtrl::HitTest( const wxPoint
&point
, int &flags
)
3054 return m_mainWin
->HitTest( (int)point
.x
, (int)point
.y
, flags
);
3057 long wxListCtrl::InsertItem( wxListItem
& info
)
3059 m_mainWin
->InsertItem( info
);
3060 return info
.m_itemId
;
3063 long wxListCtrl::InsertItem( long index
, const wxString
&label
)
3066 info
.m_text
= label
;
3067 info
.m_mask
= wxLIST_MASK_TEXT
;
3068 info
.m_itemId
= index
;
3069 return InsertItem( info
);
3072 long wxListCtrl::InsertItem( long index
, int imageIndex
)
3075 info
.m_mask
= wxLIST_MASK_IMAGE
;
3076 info
.m_image
= imageIndex
;
3077 info
.m_itemId
= index
;
3078 return InsertItem( info
);
3081 long wxListCtrl::InsertItem( long index
, const wxString
&label
, int imageIndex
)
3084 info
.m_text
= label
;
3085 info
.m_image
= imageIndex
;
3086 info
.m_mask
= wxLIST_MASK_TEXT
| wxLIST_MASK_IMAGE
;
3087 info
.m_itemId
= index
;
3088 return InsertItem( info
);
3091 long wxListCtrl::InsertColumn( long col
, wxListItem
&item
)
3093 wxASSERT( m_headerWin
);
3094 m_mainWin
->InsertColumn( col
, item
);
3095 m_headerWin
->Refresh();
3100 long wxListCtrl::InsertColumn( long col
, const wxString
&heading
,
3101 int format
, int width
)
3104 item
.m_mask
= wxLIST_MASK_TEXT
| wxLIST_MASK_FORMAT
;
3105 item
.m_text
= heading
;
3108 item
.m_mask
|= wxLIST_MASK_WIDTH
;
3109 item
.m_width
= width
;
3111 item
.m_format
= format
;
3113 return InsertColumn( col
, item
);
3116 bool wxListCtrl::ScrollList( int WXUNUSED(dx
), int WXUNUSED(dy
) )
3122 // fn is a function which takes 3 long arguments: item1, item2, data.
3123 // item1 is the long data associated with a first item (NOT the index).
3124 // item2 is the long data associated with a second item (NOT the index).
3125 // data is the same value as passed to SortItems.
3126 // The return value is a negative number if the first item should precede the second
3127 // item, a positive number of the second item should precede the first,
3128 // or zero if the two items are equivalent.
3129 // data is arbitrary data to be passed to the sort function.
3131 bool wxListCtrl::SortItems( wxListCtrlCompare fn
, long data
)
3133 m_mainWin
->SortItems( fn
, data
);
3137 void wxListCtrl::OnIdle( wxIdleEvent
&WXUNUSED(event
) )
3139 if (!m_mainWin
->m_dirty
) return;
3143 GetClientSize( &cw
, &ch
);
3150 if (HasFlag(wxLC_REPORT
) && !HasFlag(wxLC_NO_HEADER
))
3152 m_headerWin
->GetPosition( &x
, &y
);
3153 m_headerWin
->GetSize( &w
, &h
);
3154 if ((x
!= 0) || (y
!= 0) || (w
!= cw
) || (h
!= 23))
3155 m_headerWin
->SetSize( 0, 0, cw
, 23 );
3157 m_mainWin
->GetPosition( &x
, &y
);
3158 m_mainWin
->GetSize( &w
, &h
);
3159 if ((x
!= 0) || (y
!= 24) || (w
!= cw
) || (h
!= ch
-24))
3160 m_mainWin
->SetSize( 0, 24, cw
, ch
-24 );
3164 m_mainWin
->GetPosition( &x
, &y
);
3165 m_mainWin
->GetSize( &w
, &h
);
3166 if ((x
!= 0) || (y
!= 24) || (w
!= cw
) || (h
!= ch
))
3167 m_mainWin
->SetSize( 0, 0, cw
, ch
);
3170 m_mainWin
->CalculatePositions();
3171 m_mainWin
->RealizeChanges();
3172 m_mainWin
->m_dirty
= FALSE
;
3173 m_mainWin
->Refresh();
3176 bool wxListCtrl::SetBackgroundColour( const wxColour
&colour
)
3178 if ( !wxWindow::SetBackgroundColour( colour
) )
3183 m_mainWin
->SetBackgroundColour( colour
);
3184 m_mainWin
->m_dirty
= TRUE
;
3189 // m_headerWin->SetBackgroundColour( colour );
3195 bool wxListCtrl::SetForegroundColour( const wxColour
&colour
)
3197 if ( !wxWindow::SetForegroundColour( colour
) )
3202 m_mainWin
->SetForegroundColour( colour
);
3203 m_mainWin
->m_dirty
= TRUE
;
3208 m_headerWin
->SetForegroundColour( colour
);
3214 bool wxListCtrl::SetFont( const wxFont
&font
)
3216 if ( !wxWindow::SetFont( font
) )
3221 m_mainWin
->SetFont( font
);
3222 m_mainWin
->m_dirty
= TRUE
;
3227 m_headerWin
->SetFont( font
);