1 /////////////////////////////////////////////////////////////////////////////
4 // Author: Robert Roebling
6 // Copyright: (c) 1998 Robert Roebling
7 // Licence: wxWindows licence
8 /////////////////////////////////////////////////////////////////////////////
11 #pragma implementation "listctrl.h"
12 #pragma implementation "listctrlbase.h"
15 // For compilers that support precompilation, includes "wx.h".
16 #include "wx/wxprec.h"
22 #include "wx/dcscreen.h"
24 #include "wx/listctrl.h"
25 #include "wx/generic/imaglist.h"
27 #ifndef wxUSE_GENERIC_LIST_EXTENSIONS
28 #define wxUSE_GENERIC_LIST_EXTENSIONS 0
31 //-----------------------------------------------------------------------------
33 //-----------------------------------------------------------------------------
35 IMPLEMENT_DYNAMIC_CLASS(wxListItemData
,wxObject
);
37 wxListItemData::wxListItemData()
48 wxListItemData::wxListItemData( const wxListItem
&info
)
57 void wxListItemData::SetItem( const wxListItem
&info
)
59 if (info
.m_mask
& wxLIST_MASK_TEXT
) m_text
= info
.m_text
;
60 if (info
.m_mask
& wxLIST_MASK_IMAGE
) m_image
= info
.m_image
;
61 if (info
.m_mask
& wxLIST_MASK_DATA
) m_data
= info
.m_data
;
63 if ( info
.HasAttributes() )
66 *m_attr
= *info
.GetAttributes();
68 m_attr
= new wxListItemAttr(*info
.GetAttributes());
73 m_width
= info
.m_width
;
77 void wxListItemData::SetText( const wxString
&s
)
82 void wxListItemData::SetImage( int image
)
87 void wxListItemData::SetData( long data
)
92 void wxListItemData::SetPosition( int x
, int y
)
98 void wxListItemData::SetSize( int width
, int height
)
100 if (width
!= -1) m_width
= width
;
101 if (height
!= -1) m_height
= height
;
104 bool wxListItemData::HasImage() const
106 return (m_image
>= 0);
109 bool wxListItemData::HasText() const
111 return (!m_text
.IsNull());
114 bool wxListItemData::IsHit( int x
, int y
) const
116 return ((x
>= m_xpos
) && (x
<= m_xpos
+m_width
) && (y
>= m_ypos
) && (y
<= m_ypos
+m_height
));
119 void wxListItemData::GetText( wxString
&s
)
124 int wxListItemData::GetX() const
129 int wxListItemData::GetY() const
134 int wxListItemData::GetWidth() const
139 int wxListItemData::GetHeight() const
144 int wxListItemData::GetImage() const
149 void wxListItemData::GetItem( wxListItem
&info
) const
151 info
.m_text
= m_text
;
152 info
.m_image
= m_image
;
153 info
.m_data
= m_data
;
157 if ( m_attr
->HasTextColour() )
158 info
.SetTextColour(m_attr
->GetTextColour());
159 if ( m_attr
->HasBackgroundColour() )
160 info
.SetBackgroundColour(m_attr
->GetBackgroundColour());
161 if ( m_attr
->HasFont() )
162 info
.SetFont(m_attr
->GetFont());
166 //-----------------------------------------------------------------------------
168 //-----------------------------------------------------------------------------
170 IMPLEMENT_DYNAMIC_CLASS(wxListHeaderData
,wxObject
);
172 wxListHeaderData::wxListHeaderData()
183 wxListHeaderData::wxListHeaderData( const wxListItem
&item
)
191 void wxListHeaderData::SetItem( const wxListItem
&item
)
193 m_mask
= item
.m_mask
;
194 m_text
= item
.m_text
;
195 m_image
= item
.m_image
;
196 m_format
= item
.m_format
;
197 m_width
= item
.m_width
;
198 if (m_width
< 0) m_width
= 80;
199 if (m_width
< 6) m_width
= 6;
202 void wxListHeaderData::SetPosition( int x
, int y
)
208 void wxListHeaderData::SetHeight( int h
)
213 void wxListHeaderData::SetWidth( int w
)
216 if (m_width
< 0) m_width
= 80;
217 if (m_width
< 6) m_width
= 6;
220 void wxListHeaderData::SetFormat( int format
)
225 bool wxListHeaderData::HasImage() const
227 return (m_image
!= 0);
230 bool wxListHeaderData::HasText() const
232 return (m_text
.Length() > 0);
235 bool wxListHeaderData::IsHit( int x
, int y
) const
237 return ((x
>= m_xpos
) && (x
<= m_xpos
+m_width
) && (y
>= m_ypos
) && (y
<= m_ypos
+m_height
));
240 void wxListHeaderData::GetItem( wxListItem
&item
)
242 item
.m_mask
= m_mask
;
243 item
.m_text
= m_text
;
244 item
.m_image
= m_image
;
245 item
.m_format
= m_format
;
246 item
.m_width
= m_width
;
249 void wxListHeaderData::GetText( wxString
&s
)
254 int wxListHeaderData::GetImage() const
259 int wxListHeaderData::GetWidth() const
264 int wxListHeaderData::GetFormat() const
269 //-----------------------------------------------------------------------------
271 //-----------------------------------------------------------------------------
273 IMPLEMENT_DYNAMIC_CLASS(wxListLineData
,wxObject
);
275 wxListLineData::wxListLineData( wxListMainWindow
*owner
, int mode
, wxBrush
*hilightBrush
)
280 m_hilightBrush
= hilightBrush
;
281 m_items
.DeleteContents( TRUE
);
285 void wxListLineData::CalculateSize( wxDC
*dc
, int spacing
)
292 m_bound_all
.width
= m_spacing
;
293 m_bound_all
.height
= m_spacing
+13;
294 wxNode
*node
= m_items
.First();
297 wxListItemData
*item
= (wxListItemData
*)node
->Data();
298 wxString s
= item
->GetText();
300 dc
->GetTextExtent( s
, &lw
, &lh
);
301 if (lw
> m_spacing
) m_bound_all
.width
= lw
;
307 wxNode
*node
= m_items
.First();
310 wxListItemData
*item
= (wxListItemData
*)node
->Data();
311 wxString s
= item
->GetText();
313 dc
->GetTextExtent( s
, &lw
, &lh
);
314 m_bound_all
.width
= lw
;
315 m_bound_all
.height
= lh
;
316 if (item
->HasImage())
325 m_owner
->GetImageSize( item
->GetImage(), w
, h
);
326 m_bound_all
.width
+= 4 + w
;
327 if (h
> m_bound_all
.height
) m_bound_all
.height
= h
;
334 m_bound_all
.width
= 0;
335 m_bound_all
.height
= 0;
336 wxNode
*node
= m_items
.First();
339 wxListItemData
*item
= (wxListItemData
*)node
->Data();
342 if (s
.IsNull()) s
= "H";
344 dc
->GetTextExtent( s
, &lw
, &lh
);
345 if (lh
< 15) lh
= 15;
346 item
->SetSize( item
->GetWidth(), lh
);
347 m_bound_all
.width
+= lw
;
348 m_bound_all
.height
= lh
;
356 void wxListLineData::SetPosition( wxDC
*dc
, int x
, int y
, int window_width
)
364 AssignRect( m_bound_icon
, 0, 0, 0, 0 );
365 AssignRect( m_bound_label
, 0, 0, 0, 0 );
366 AssignRect( m_bound_hilight
, m_bound_all
);
367 wxNode
*node
= m_items
.First();
370 wxListItemData
*item
= (wxListItemData
*)node
->Data();
371 if (item
->HasImage())
373 wxListItemData
*item
= (wxListItemData
*)node
->Data();
376 m_owner
->GetImageSize( item
->GetImage(), w
, h
);
377 m_bound_icon
.x
= m_bound_all
.x
+ (m_spacing
/2) - (w
/2);
378 m_bound_icon
.y
= m_bound_all
.y
+ m_spacing
- h
- 5;
379 m_bound_icon
.width
= w
;
380 m_bound_icon
.height
= h
;
381 if (!item
->HasText())
383 AssignRect( m_bound_hilight
, m_bound_icon
);
384 m_bound_hilight
.x
-= 5;
385 m_bound_hilight
.y
-= 5;
386 m_bound_hilight
.width
+= 9;
387 m_bound_hilight
.height
+= 9;
395 dc
->GetTextExtent( s
, &lw
, &lh
);
396 if (m_bound_all
.width
> m_spacing
)
397 m_bound_label
.x
= m_bound_all
.x
;
399 m_bound_label
.x
= m_bound_all
.x
+ (m_spacing
/2) - lw
/2;
400 m_bound_label
.y
= m_bound_all
.y
+ m_bound_all
.height
- lh
;
401 m_bound_label
.width
= lw
;
402 m_bound_label
.height
= lh
;
403 AssignRect( m_bound_hilight
, m_bound_label
);
404 m_bound_hilight
.x
-= 2;
405 m_bound_hilight
.y
-= 2;
406 m_bound_hilight
.width
+= 4;
407 m_bound_hilight
.height
+= 4;
414 AssignRect( m_bound_label
, m_bound_all
);
417 m_bound_all
.width
+= 4;
418 m_bound_all
.height
+= 3;
419 AssignRect( m_bound_hilight
, m_bound_all
);
420 AssignRect( m_bound_icon
, 0, 0, 0, 0 );
421 wxNode
*node
= m_items
.First();
424 wxListItemData
*item
= (wxListItemData
*)node
->Data();
425 if (item
->HasImage())
427 m_bound_icon
.x
= m_bound_all
.x
+ 2;
428 m_bound_icon
.y
= m_bound_all
.y
+ 2;
431 m_owner
->GetImageSize( item
->GetImage(), w
, h
);
432 m_bound_icon
.width
= w
;
433 m_bound_icon
.height
= h
;
434 m_bound_label
.x
+= 4 + w
;
435 m_bound_label
.width
-= 4 + w
;
443 dc
->GetTextExtent( "H", &lw
, &lh
);
444 if (lh
< 15) lh
= 15;
447 m_bound_all
.height
= lh
+3;
448 m_bound_all
.width
= window_width
;
449 AssignRect( m_bound_hilight
, m_bound_all
);
450 AssignRect( m_bound_label
, m_bound_all
);
451 AssignRect( m_bound_icon
, 0, 0, 0, 0 );
452 wxNode
*node
= m_items
.First();
455 wxListItemData
*item
= (wxListItemData
*)node
->Data();
458 if (s
.IsEmpty()) s
= wxT("H");
460 dc
->GetTextExtent( s
, &lw
, &lh
);
461 if (lh
< 15) lh
= 15;
462 m_bound_label
.width
= lw
;
463 m_bound_label
.height
= lh
;
464 if (item
->HasImage())
466 m_bound_icon
.x
= m_bound_all
.x
+ 2;
467 m_bound_icon
.y
= m_bound_all
.y
+ 2;
470 m_owner
->GetImageSize( item
->GetImage(), w
, h
);
471 m_bound_icon
.width
= w
;
472 m_bound_icon
.height
= h
;
473 m_bound_label
.x
+= 4 + w
;
481 void wxListLineData::SetColumnPosition( int index
, int x
)
483 wxNode
*node
= m_items
.Nth( (size_t)index
);
486 wxListItemData
*item
= (wxListItemData
*)node
->Data();
487 item
->SetPosition( x
, m_bound_all
.y
+1 );
491 void wxListLineData::GetSize( int &width
, int &height
)
493 width
= m_bound_all
.width
;
494 height
= m_bound_all
.height
;
497 void wxListLineData::GetExtent( int &x
, int &y
, int &width
, int &height
)
501 width
= m_bound_all
.width
;
502 height
= m_bound_all
.height
;
505 void wxListLineData::GetLabelExtent( int &x
, int &y
, int &width
, int &height
)
509 width
= m_bound_label
.width
;
510 height
= m_bound_label
.height
;
513 void wxListLineData::GetRect( wxRect
&rect
)
515 AssignRect( rect
, m_bound_all
);
518 long wxListLineData::IsHit( int x
, int y
)
520 wxNode
*node
= m_items
.First();
523 wxListItemData
*item
= (wxListItemData
*)node
->Data();
524 if (item
->HasImage() && IsInRect( x
, y
, m_bound_icon
)) return wxLIST_HITTEST_ONITEMICON
;
525 if (item
->HasText() && IsInRect( x
, y
, m_bound_label
)) return wxLIST_HITTEST_ONITEMLABEL
;
526 // if (!(item->HasImage() || item->HasText())) return 0;
528 // if there is no icon or text = empty
529 if (IsInRect( x
, y
, m_bound_all
)) return wxLIST_HITTEST_ONITEMICON
;
533 void wxListLineData::InitItems( int num
)
535 for (int i
= 0; i
< num
; i
++) m_items
.Append( new wxListItemData() );
538 void wxListLineData::SetItem( int index
, const wxListItem
&info
)
540 wxNode
*node
= m_items
.Nth( index
);
543 wxListItemData
*item
= (wxListItemData
*)node
->Data();
544 item
->SetItem( info
);
548 void wxListLineData::GetItem( int index
, wxListItem
&info
)
551 wxNode
*node
= m_items
.Nth( i
);
554 wxListItemData
*item
= (wxListItemData
*)node
->Data();
555 item
->GetItem( info
);
559 void wxListLineData::GetText( int index
, wxString
&s
)
562 wxNode
*node
= m_items
.Nth( i
);
566 wxListItemData
*item
= (wxListItemData
*)node
->Data();
571 void wxListLineData::SetText( int index
, const wxString s
)
574 wxNode
*node
= m_items
.Nth( i
);
577 wxListItemData
*item
= (wxListItemData
*)node
->Data();
582 int wxListLineData::GetImage( int index
)
585 wxNode
*node
= m_items
.Nth( i
);
588 wxListItemData
*item
= (wxListItemData
*)node
->Data();
589 return item
->GetImage();
594 void wxListLineData::SetAttributes(wxDC
*dc
,
595 const wxListItemAttr
*attr
,
596 const wxColour
& colText
,
600 // don't use foregroud colour for drawing highlighted items - this might
601 // make them completely invisible (and there is no way to do bit
602 // arithmetics on wxColour, unfortunately)
603 if ( !hilight
&& attr
&& attr
->HasTextColour() )
605 dc
->SetTextForeground(attr
->GetTextColour());
609 dc
->SetTextForeground(colText
);
612 if ( attr
&& attr
->HasFont() )
614 dc
->SetFont(attr
->GetFont());
622 void wxListLineData::DoDraw( wxDC
*dc
, bool hilight
, bool paintBG
)
626 m_owner
->CalcScrolledPosition( m_bound_all
.x
, m_bound_all
.y
, &dev_x
, &dev_y
);
627 wxCoord dev_w
= m_bound_all
.width
;
628 wxCoord dev_h
= m_bound_all
.height
;
630 if (!m_owner
->IsExposed( dev_x
, dev_y
, dev_w
, dev_h
))
633 wxWindow
*listctrl
= m_owner
->GetParent();
635 // default foreground colour
639 colText
= wxSystemSettings::GetSystemColour( wxSYS_COLOUR_HIGHLIGHTTEXT
);
643 colText
= listctrl
->GetForegroundColour();
647 wxFont font
= listctrl
->GetFont();
649 // VZ: currently we set the colours/fonts only once, but like this (i.e.
650 // using SetAttributes() inside the loop), it will be trivial to
651 // customize the subitems (in report mode) too.
652 wxListItemData
*item
= (wxListItemData
*)m_items
.First()->Data();
653 wxListItemAttr
*attr
= item
->GetAttributes();
654 SetAttributes(dc
, attr
, colText
, font
, hilight
);
656 bool hasBgCol
= attr
&& attr
->HasBackgroundColour();
657 if ( paintBG
|| hasBgCol
)
661 dc
->SetBrush( * m_hilightBrush
);
666 dc
->SetBrush(wxBrush(attr
->GetBackgroundColour(), wxSOLID
));
668 dc
->SetBrush( * wxWHITE_BRUSH
);
671 dc
->SetPen( * wxTRANSPARENT_PEN
);
672 dc
->DrawRectangle( m_bound_hilight
.x
, m_bound_hilight
.y
,
673 m_bound_hilight
.width
, m_bound_hilight
.height
);
676 if (m_mode
== wxLC_REPORT
)
678 wxNode
*node
= m_items
.First();
681 wxListItemData
*item
= (wxListItemData
*)node
->Data();
682 int x
= item
->GetX();
683 if (item
->HasImage())
686 m_owner
->DrawImage( item
->GetImage(), dc
, x
, item
->GetY() );
687 m_owner
->GetImageSize( item
->GetImage(), x
, y
);
688 x
+= item
->GetX() + 5;
690 dc
->SetClippingRegion( item
->GetX(), item
->GetY(), item
->GetWidth()-3, item
->GetHeight() );
693 dc
->DrawText( item
->GetText(), x
, item
->GetY()+1 );
695 dc
->DestroyClippingRegion();
701 wxNode
*node
= m_items
.First();
704 wxListItemData
*item
= (wxListItemData
*)node
->Data();
705 if (item
->HasImage())
707 m_owner
->DrawImage( item
->GetImage(), dc
, m_bound_icon
.x
, m_bound_icon
.y
);
711 dc
->DrawText( item
->GetText(), m_bound_label
.x
, m_bound_label
.y
);
717 void wxListLineData::Hilight( bool on
)
719 if (on
== m_hilighted
) return;
722 m_owner
->SelectLine( this );
724 m_owner
->DeselectLine( this );
727 void wxListLineData::ReverseHilight( void )
729 m_hilighted
= !m_hilighted
;
731 m_owner
->SelectLine( this );
733 m_owner
->DeselectLine( this );
736 void wxListLineData::DrawRubberBand( wxDC
*dc
, bool on
)
740 dc
->SetPen( * wxBLACK_PEN
);
741 dc
->SetBrush( * wxTRANSPARENT_BRUSH
);
742 dc
->DrawRectangle( m_bound_hilight
.x
, m_bound_hilight
.y
,
743 m_bound_hilight
.width
, m_bound_hilight
.height
);
747 void wxListLineData::Draw( wxDC
*dc
)
749 DoDraw( dc
, m_hilighted
, m_hilighted
);
752 bool wxListLineData::IsInRect( int x
, int y
, const wxRect
&rect
)
754 return ((x
>= rect
.x
) && (x
<= rect
.x
+rect
.width
) &&
755 (y
>= rect
.y
) && (y
<= rect
.y
+rect
.height
));
758 bool wxListLineData::IsHilighted( void )
763 void wxListLineData::AssignRect( wxRect
&dest
, int x
, int y
, int width
, int height
)
768 dest
.height
= height
;
771 void wxListLineData::AssignRect( wxRect
&dest
, const wxRect
&source
)
775 dest
.width
= source
.width
;
776 dest
.height
= source
.height
;
779 //-----------------------------------------------------------------------------
780 // wxListHeaderWindow
781 //-----------------------------------------------------------------------------
783 IMPLEMENT_DYNAMIC_CLASS(wxListHeaderWindow
,wxWindow
);
785 BEGIN_EVENT_TABLE(wxListHeaderWindow
,wxWindow
)
786 EVT_PAINT (wxListHeaderWindow::OnPaint
)
787 EVT_MOUSE_EVENTS (wxListHeaderWindow::OnMouse
)
788 EVT_SET_FOCUS (wxListHeaderWindow::OnSetFocus
)
791 wxListHeaderWindow::wxListHeaderWindow( void )
793 m_owner
= (wxListMainWindow
*) NULL
;
794 m_currentCursor
= (wxCursor
*) NULL
;
795 m_resizeCursor
= (wxCursor
*) NULL
;
796 m_isDragging
= FALSE
;
799 wxListHeaderWindow::wxListHeaderWindow( wxWindow
*win
, wxWindowID id
, wxListMainWindow
*owner
,
800 const wxPoint
&pos
, const wxSize
&size
,
801 long style
, const wxString
&name
) :
802 wxWindow( win
, id
, pos
, size
, style
, name
)
805 // m_currentCursor = wxSTANDARD_CURSOR;
806 m_currentCursor
= (wxCursor
*) NULL
;
807 m_resizeCursor
= new wxCursor( wxCURSOR_SIZEWE
);
808 m_isDragging
= FALSE
;
809 SetBackgroundColour( wxSystemSettings::GetSystemColour( wxSYS_COLOUR_BTNFACE
) );
812 wxListHeaderWindow::~wxListHeaderWindow( void )
814 delete m_resizeCursor
;
817 void wxListHeaderWindow::DoDrawRect( wxDC
*dc
, int x
, int y
, int w
, int h
)
819 const int m_corner
= 1;
821 dc
->SetBrush( *wxTRANSPARENT_BRUSH
);
823 dc
->SetPen( *wxBLACK_PEN
);
824 dc
->DrawLine( x
+w
-m_corner
+1, y
, x
+w
, y
+h
); // right (outer)
825 dc
->DrawRectangle( x
, y
+h
, w
+1, 1 ); // bottom (outer)
827 wxPen
pen( wxSystemSettings::GetSystemColour( wxSYS_COLOUR_BTNSHADOW
), 1, wxSOLID
);
830 dc
->DrawLine( x
+w
-m_corner
, y
, x
+w
-1, y
+h
); // right (inner)
831 dc
->DrawRectangle( x
+1, y
+h
-1, w
-2, 1 ); // bottom (inner)
833 dc
->SetPen( *wxWHITE_PEN
);
834 dc
->DrawRectangle( x
, y
, w
-m_corner
+1, 1 ); // top (outer)
835 dc
->DrawRectangle( x
, y
, 1, h
); // left (outer)
836 dc
->DrawLine( x
, y
+h
-1, x
+1, y
+h
-1 );
837 dc
->DrawLine( x
+w
-1, y
, x
+w
-1, y
+1 );
840 void wxListHeaderWindow::OnPaint( wxPaintEvent
&WXUNUSED(event
) )
842 wxPaintDC
dc( this );
844 #if wxUSE_GENERIC_LIST_EXTENSIONS
845 if ( m_owner
->GetMode() & wxLC_REPORT
)
850 m_owner
->GetScrollPixelsPerUnit( &xpix
, &ypix
) ;
851 m_owner
->ViewStart( &x
, &y
) ;
852 dc
.SetDeviceOrigin( -x
* xpix
, 0 );
857 dc
.SetFont( GetFont() );
863 GetClientSize( &w
, &h
);
865 dc
.SetBackgroundMode(wxTRANSPARENT
);
866 dc
.SetTextForeground( *wxBLACK
);
868 // do *not* use the listctrl colour for headers - one day we will have a
869 // function to set it separately
873 int numColumns
= m_owner
->GetColumnCount();
875 for (int i
= 0; i
< numColumns
; i
++)
877 m_owner
->GetColumn( i
, item
);
878 int cw
= item
.m_width
-2;
879 #if wxUSE_GENERIC_LIST_EXTENSIONS
880 if ((i
+1 == numColumns
) || ( dc
.LogicalToDeviceX(x
+item
.m_width
) > w
-5))
881 cw
= dc
.DeviceToLogicalX(w
)-x
-1;
883 if ((i
+1 == numColumns
) || (x
+item
.m_width
> w
-5))
886 dc
.SetPen( *wxWHITE_PEN
);
888 DoDrawRect( &dc
, x
, y
, cw
, h
-2 );
889 dc
.SetClippingRegion( x
, y
, cw
-5, h
-4 );
890 dc
.DrawText( item
.m_text
, x
+4, y
+3 );
891 dc
.DestroyClippingRegion();
893 #if wxUSE_GENERIC_LIST_EXTENSIONS
894 if (dc
.LogicalToDeviceX(x
) > w
+5) break;
902 void wxListHeaderWindow::DrawCurrent()
906 int x2
= m_currentX
-1;
909 m_owner
->GetClientSize( &dummy
, &y2
);
910 ClientToScreen( &x1
, &y1
);
911 m_owner
->ClientToScreen( &x2
, &y2
);
914 dc
.SetLogicalFunction( wxINVERT
);
915 dc
.SetPen( wxPen( *wxBLACK
, 2, wxSOLID
) );
916 dc
.SetBrush( *wxTRANSPARENT_BRUSH
);
918 dc
.DrawLine( x1
, y1
, x2
, y2
);
920 dc
.SetLogicalFunction( wxCOPY
);
922 dc
.SetPen( wxNullPen
);
923 dc
.SetBrush( wxNullBrush
);
926 void wxListHeaderWindow::OnMouse( wxMouseEvent
&event
)
928 wxCoord x
= (wxCoord
)event
.GetX();
929 wxCoord y
= (wxCoord
)event
.GetY();
933 if (event
.ButtonUp())
936 m_isDragging
= FALSE
;
937 m_owner
->SetColumnWidth( m_column
, m_currentX
-m_minX
);
943 GetClientSize( &size_x
, & dummy
);
947 m_currentX
= m_minX
+7;
948 if (m_currentX
> size_x
-7) m_currentX
= size_x
-7;
955 bool hit_border
= FALSE
;
957 for (int j
= 0; j
< m_owner
->GetColumnCount(); j
++)
959 xpos
+= m_owner
->GetColumnWidth( j
);
961 if ((abs(x
-xpos
) < 3) && (y
< 22) && (m_column
< m_owner
->GetColumnCount()-1))
973 if (event
.LeftDown())
985 wxListEvent
le( wxEVT_COMMAND_LIST_COL_CLICK
, GetParent()->GetId() );
986 le
.SetEventObject( GetParent() );
988 GetParent()->GetEventHandler()->ProcessEvent( le
);
997 if (m_currentCursor
== wxSTANDARD_CURSOR
) SetCursor( * m_resizeCursor
);
998 m_currentCursor
= m_resizeCursor
;
1002 if (m_currentCursor
!= wxSTANDARD_CURSOR
) SetCursor( * wxSTANDARD_CURSOR
);
1003 m_currentCursor
= wxSTANDARD_CURSOR
;
1008 void wxListHeaderWindow::OnSetFocus( wxFocusEvent
&WXUNUSED(event
) )
1010 m_owner
->SetFocus();
1013 //-----------------------------------------------------------------------------
1014 // wxListRenameTimer (internal)
1015 //-----------------------------------------------------------------------------
1017 wxListRenameTimer::wxListRenameTimer( wxListMainWindow
*owner
)
1022 void wxListRenameTimer::Notify()
1024 m_owner
->OnRenameTimer();
1027 //-----------------------------------------------------------------------------
1028 // wxListTextCtrl (internal)
1029 //-----------------------------------------------------------------------------
1031 IMPLEMENT_DYNAMIC_CLASS(wxListTextCtrl
,wxTextCtrl
);
1033 BEGIN_EVENT_TABLE(wxListTextCtrl
,wxTextCtrl
)
1034 EVT_CHAR (wxListTextCtrl::OnChar
)
1035 EVT_KILL_FOCUS (wxListTextCtrl::OnKillFocus
)
1038 wxListTextCtrl::wxListTextCtrl( wxWindow
*parent
,
1039 const wxWindowID id
,
1042 wxListMainWindow
*owner
,
1043 const wxString
&value
,
1047 const wxValidator
& validator
,
1048 const wxString
&name
)
1049 : wxTextCtrl( parent
, id
, value
, pos
, size
, style
, validator
, name
)
1054 (*m_accept
) = FALSE
;
1056 m_startValue
= value
;
1059 void wxListTextCtrl::OnChar( wxKeyEvent
&event
)
1061 if (event
.m_keyCode
== WXK_RETURN
)
1064 (*m_res
) = GetValue();
1066 if (!wxPendingDelete
.Member(this))
1067 wxPendingDelete
.Append(this);
1069 if ((*m_accept
) && ((*m_res
) != m_startValue
))
1070 m_owner
->OnRenameAccept();
1074 if (event
.m_keyCode
== WXK_ESCAPE
)
1076 (*m_accept
) = FALSE
;
1079 if (!wxPendingDelete
.Member(this))
1080 wxPendingDelete
.Append(this);
1088 void wxListTextCtrl::OnKillFocus( wxFocusEvent
&WXUNUSED(event
) )
1090 if (!wxPendingDelete
.Member(this))
1091 wxPendingDelete
.Append(this);
1093 if ((*m_accept
) && ((*m_res
) != m_startValue
))
1094 m_owner
->OnRenameAccept();
1097 //-----------------------------------------------------------------------------
1099 //-----------------------------------------------------------------------------
1101 IMPLEMENT_DYNAMIC_CLASS(wxListMainWindow
,wxScrolledWindow
);
1103 BEGIN_EVENT_TABLE(wxListMainWindow
,wxScrolledWindow
)
1104 EVT_PAINT (wxListMainWindow::OnPaint
)
1105 EVT_SIZE (wxListMainWindow::OnSize
)
1106 EVT_MOUSE_EVENTS (wxListMainWindow::OnMouse
)
1107 EVT_CHAR (wxListMainWindow::OnChar
)
1108 EVT_KEY_DOWN (wxListMainWindow::OnKeyDown
)
1109 EVT_SET_FOCUS (wxListMainWindow::OnSetFocus
)
1110 EVT_KILL_FOCUS (wxListMainWindow::OnKillFocus
)
1111 EVT_SCROLLWIN (wxListMainWindow::OnScroll
)
1114 wxListMainWindow::wxListMainWindow()
1117 m_lines
.DeleteContents( TRUE
);
1118 m_columns
.DeleteContents( TRUE
);
1119 m_current
= (wxListLineData
*) NULL
;
1121 m_hilightBrush
= (wxBrush
*) NULL
;
1125 m_small_image_list
= (wxImageList
*) NULL
;
1126 m_normal_image_list
= (wxImageList
*) NULL
;
1127 m_small_spacing
= 30;
1128 m_normal_spacing
= 40;
1131 m_lastOnSame
= FALSE
;
1132 m_renameTimer
= new wxListRenameTimer( this );
1133 m_isCreated
= FALSE
;
1137 wxListMainWindow::wxListMainWindow( wxWindow
*parent
, wxWindowID id
,
1138 const wxPoint
&pos
, const wxSize
&size
,
1139 long style
, const wxString
&name
) :
1140 wxScrolledWindow( parent
, id
, pos
, size
, style
|wxHSCROLL
|wxVSCROLL
, name
)
1143 m_lines
.DeleteContents( TRUE
);
1144 m_columns
.DeleteContents( TRUE
);
1145 m_current
= (wxListLineData
*) NULL
;
1148 m_hilightBrush
= new wxBrush( wxSystemSettings::GetSystemColour(wxSYS_COLOUR_HIGHLIGHT
), wxSOLID
);
1149 m_small_image_list
= (wxImageList
*) NULL
;
1150 m_normal_image_list
= (wxImageList
*) NULL
;
1151 m_small_spacing
= 30;
1152 m_normal_spacing
= 40;
1155 m_isCreated
= FALSE
;
1159 if (m_mode
& wxLC_REPORT
)
1161 #if wxUSE_GENERIC_LIST_EXTENSIONS
1173 SetScrollbars( m_xScroll
, m_yScroll
, 0, 0, 0, 0 );
1176 m_lastOnSame
= FALSE
;
1177 m_renameTimer
= new wxListRenameTimer( this );
1178 m_renameAccept
= FALSE
;
1180 SetBackgroundColour( wxSystemSettings::GetSystemColour( wxSYS_COLOUR_LISTBOX
) );
1183 wxListMainWindow::~wxListMainWindow()
1187 if (m_hilightBrush
) delete m_hilightBrush
;
1189 delete m_renameTimer
;
1192 void wxListMainWindow::RefreshLine( wxListLineData
*line
)
1194 if (m_dirty
) return;
1202 line
->GetExtent( x
, y
, w
, h
);
1203 CalcScrolledPosition( x
, y
, &x
, &y
);
1204 wxRect
rect( x
, y
, w
, h
);
1205 Refresh( TRUE
, &rect
);
1208 void wxListMainWindow::OnPaint( wxPaintEvent
&WXUNUSED(event
) )
1210 // Note: a wxPaintDC must be constructed even if no drawing is
1211 // done (a Windows requirement).
1212 wxPaintDC
dc( this );
1215 if (m_dirty
) return;
1217 if (m_lines
.GetCount() == 0) return;
1221 dc
.SetFont( GetFont() );
1223 if (m_mode
& wxLC_REPORT
)
1225 int lineSpacing
= 0;
1226 wxListLineData
*line
= (wxListLineData
*)m_lines
.First()->Data();
1228 line
->GetSize( dummy
, lineSpacing
);
1231 int y_s
= m_yScroll
*GetScrollPos( wxVERTICAL
);
1233 wxNode
*node
= m_lines
.Nth( y_s
/ lineSpacing
);
1234 for (int i
= 0; i
< m_visibleLines
+2; i
++)
1238 line
= (wxListLineData
*)node
->Data();
1240 node
= node
->Next();
1245 wxNode
*node
= m_lines
.First();
1248 wxListLineData
*line
= (wxListLineData
*)node
->Data();
1250 node
= node
->Next();
1254 if (m_current
) m_current
->DrawRubberBand( &dc
, m_hasFocus
);
1259 void wxListMainWindow::HilightAll( bool on
)
1261 wxNode
*node
= m_lines
.First();
1264 wxListLineData
*line
= (wxListLineData
*)node
->Data();
1265 if (line
->IsHilighted() != on
)
1267 line
->Hilight( on
);
1268 RefreshLine( line
);
1270 node
= node
->Next();
1274 void wxListMainWindow::SendNotify( wxListLineData
*line
, wxEventType command
)
1276 wxListEvent
le( command
, GetParent()->GetId() );
1277 le
.SetEventObject( GetParent() );
1278 le
.m_itemIndex
= GetIndexOfLine( line
);
1279 line
->GetItem( 0, le
.m_item
);
1280 GetParent()->GetEventHandler()->ProcessEvent( le
);
1281 // GetParent()->GetEventHandler()->AddPendingEvent( le );
1284 void wxListMainWindow::FocusLine( wxListLineData
*WXUNUSED(line
) )
1286 // SendNotify( line, wxEVT_COMMAND_LIST_ITEM_FOCUSSED );
1289 void wxListMainWindow::UnfocusLine( wxListLineData
*WXUNUSED(line
) )
1291 // SendNotify( line, wxEVT_COMMAND_LIST_ITEM_UNFOCUSSED );
1294 void wxListMainWindow::SelectLine( wxListLineData
*line
)
1296 SendNotify( line
, wxEVT_COMMAND_LIST_ITEM_SELECTED
);
1299 void wxListMainWindow::DeselectLine( wxListLineData
*line
)
1301 SendNotify( line
, wxEVT_COMMAND_LIST_ITEM_DESELECTED
);
1304 void wxListMainWindow::DeleteLine( wxListLineData
*line
)
1306 SendNotify( line
, wxEVT_COMMAND_LIST_DELETE_ITEM
);
1311 void wxListMainWindow::EditLabel( long item
)
1313 wxNode
*node
= m_lines
.Nth( (size_t)item
);
1314 wxCHECK_RET( node
, wxT("wrong index in wxListCtrl::Edit()") );
1316 m_currentEdit
= (wxListLineData
*) node
->Data();
1318 wxListEvent
le( wxEVT_COMMAND_LIST_BEGIN_LABEL_EDIT
, GetParent()->GetId() );
1319 le
.SetEventObject( GetParent() );
1320 le
.m_itemIndex
= GetIndexOfLine( m_currentEdit
);
1321 m_currentEdit
->GetItem( 0, le
.m_item
);
1322 GetParent()->GetEventHandler()->ProcessEvent( le
);
1324 if (!le
.IsAllowed())
1327 // We have to call this here because the label in
1328 // question might just have been added and no screen
1329 // update taken place.
1330 if (m_dirty
) wxYield();
1333 m_currentEdit
->GetText( 0, s
);
1338 m_currentEdit
->GetLabelExtent( x
, y
, w
, h
);
1340 wxClientDC
dc(this);
1342 x
= dc
.LogicalToDeviceX( x
);
1343 y
= dc
.LogicalToDeviceY( y
);
1345 wxListTextCtrl
*text
= new wxListTextCtrl(
1346 this, -1, &m_renameAccept
, &m_renameRes
, this, s
, wxPoint(x
-4,y
-4), wxSize(w
+11,h
+8) );
1350 void wxListMainWindow::OnRenameTimer()
1352 wxCHECK_RET( m_current
, wxT("invalid m_current") );
1354 Edit( m_lines
.IndexOf( m_current
) );
1357 void wxListMainWindow::OnRenameAccept()
1359 wxListEvent
le( wxEVT_COMMAND_LIST_END_LABEL_EDIT
, GetParent()->GetId() );
1360 le
.SetEventObject( GetParent() );
1361 le
.m_itemIndex
= GetIndexOfLine( m_currentEdit
);
1362 m_currentEdit
->GetItem( 0, le
.m_item
);
1363 le
.m_item
.m_text
= m_renameRes
;
1364 GetParent()->GetEventHandler()->ProcessEvent( le
);
1366 if (!le
.IsAllowed()) return;
1369 info
.m_mask
= wxLIST_MASK_TEXT
;
1370 info
.m_itemId
= le
.m_itemIndex
;
1371 info
.m_text
= m_renameRes
;
1372 info
.SetTextColour(le
.m_item
.GetTextColour());
1376 void wxListMainWindow::OnMouse( wxMouseEvent
&event
)
1378 if (GetParent()->GetEventHandler()->ProcessEvent( event
)) return;
1380 if (!m_current
) return;
1381 if (m_dirty
) return;
1382 if ( !(event
.Dragging() || event
.ButtonDown() || event
.LeftUp() || event
.ButtonDClick()) ) return;
1384 wxClientDC
dc(this);
1386 wxCoord x
= dc
.DeviceToLogicalX( (wxCoord
)event
.GetX() );
1387 wxCoord y
= dc
.DeviceToLogicalY( (wxCoord
)event
.GetY() );
1389 /* Did we actually hit an item ? */
1391 wxNode
*node
= m_lines
.First();
1392 wxListLineData
*line
= (wxListLineData
*) NULL
;
1395 line
= (wxListLineData
*)node
->Data();
1396 hitResult
= line
->IsHit( x
, y
);
1397 if (hitResult
) break;
1398 line
= (wxListLineData
*) NULL
;
1399 node
= node
->Next();
1402 if (event
.Dragging())
1404 if (m_dragCount
== 0)
1405 m_dragStart
= wxPoint(x
,y
);
1409 if (m_dragCount
!= 3) return;
1411 int command
= wxEVT_COMMAND_LIST_BEGIN_DRAG
;
1412 if (event
.RightIsDown()) command
= wxEVT_COMMAND_LIST_BEGIN_RDRAG
;
1414 wxListEvent
le( command
, GetParent()->GetId() );
1415 le
.SetEventObject( GetParent() );
1416 le
.m_pointDrag
= m_dragStart
;
1417 GetParent()->GetEventHandler()->ProcessEvent( le
);
1428 if (event
.ButtonDClick())
1431 m_lastOnSame
= FALSE
;
1432 m_renameTimer
->Stop();
1434 SendNotify( line
, wxEVT_COMMAND_LIST_ITEM_ACTIVATED
);
1439 if (event
.LeftUp() && m_lastOnSame
)
1442 if ((line
== m_current
) &&
1443 (hitResult
== wxLIST_HITTEST_ONITEMLABEL
) &&
1444 (m_mode
& wxLC_EDIT_LABELS
) )
1446 m_renameTimer
->Start( 100, TRUE
);
1448 m_lastOnSame
= FALSE
;
1452 if (event
.RightDown())
1454 SendNotify( line
, wxEVT_COMMAND_LIST_ITEM_RIGHT_CLICK
);
1458 if (event
.MiddleDown())
1460 SendNotify( line
, wxEVT_COMMAND_LIST_ITEM_MIDDLE_CLICK
);
1464 if (event
.LeftDown())
1467 wxListLineData
*oldCurrent
= m_current
;
1468 if (m_mode
& wxLC_SINGLE_SEL
)
1471 HilightAll( FALSE
);
1472 m_current
->ReverseHilight();
1473 RefreshLine( m_current
);
1477 if (event
.ControlDown())
1480 m_current
->ReverseHilight();
1481 RefreshLine( m_current
);
1483 else if (event
.ShiftDown())
1487 int numOfCurrent
= -1;
1488 node
= m_lines
.First();
1491 wxListLineData
*test_line
= (wxListLineData
*)node
->Data();
1493 if (test_line
== oldCurrent
) break;
1494 node
= node
->Next();
1498 node
= m_lines
.First();
1501 wxListLineData
*test_line
= (wxListLineData
*)node
->Data();
1503 if (test_line
== line
) break;
1504 node
= node
->Next();
1507 if (numOfLine
< numOfCurrent
)
1510 numOfLine
= numOfCurrent
;
1514 wxNode
*node
= m_lines
.Nth( numOfCurrent
);
1515 for (int i
= 0; i
<= numOfLine
-numOfCurrent
; i
++)
1517 wxListLineData
*test_line
= (wxListLineData
*)node
->Data();
1518 test_line
->Hilight(TRUE
);
1519 RefreshLine( test_line
);
1520 node
= node
->Next();
1526 HilightAll( FALSE
);
1527 m_current
->ReverseHilight();
1528 RefreshLine( m_current
);
1531 if (m_current
!= oldCurrent
)
1533 RefreshLine( oldCurrent
);
1534 UnfocusLine( oldCurrent
);
1535 FocusLine( m_current
);
1537 m_lastOnSame
= (m_current
== oldCurrent
);
1542 void wxListMainWindow::MoveToFocus()
1544 if (!m_current
) return;
1550 m_current
->GetExtent( item_x
, item_y
, item_w
, item_h
);
1554 GetClientSize( &client_w
, &client_h
);
1556 int view_x
= m_xScroll
*GetScrollPos( wxHORIZONTAL
);
1557 int view_y
= m_yScroll
*GetScrollPos( wxVERTICAL
);
1559 if (m_mode
& wxLC_REPORT
)
1561 if (item_y
-5 < view_y
)
1562 Scroll( -1, (item_y
-5)/m_yScroll
);
1563 if (item_y
+item_h
+5 > view_y
+client_h
)
1564 Scroll( -1, (item_y
+item_h
-client_h
+15)/m_yScroll
);
1568 if (item_x
-view_x
< 5)
1569 Scroll( (item_x
-5)/m_xScroll
, -1 );
1570 if (item_x
+item_w
-5 > view_x
+client_w
)
1571 Scroll( (item_x
+item_w
-client_w
+15)/m_xScroll
, -1 );
1575 void wxListMainWindow::OnArrowChar( wxListLineData
*newCurrent
, bool shiftDown
)
1577 if ((m_mode
& wxLC_SINGLE_SEL
) || (m_usedKeys
== FALSE
)) m_current
->Hilight( FALSE
);
1578 wxListLineData
*oldCurrent
= m_current
;
1579 m_current
= newCurrent
;
1580 if (shiftDown
|| (m_mode
& wxLC_SINGLE_SEL
)) m_current
->Hilight( TRUE
);
1581 RefreshLine( m_current
);
1582 RefreshLine( oldCurrent
);
1583 FocusLine( m_current
);
1584 UnfocusLine( oldCurrent
);
1588 void wxListMainWindow::OnKeyDown( wxKeyEvent
&event
)
1590 wxWindow
*parent
= GetParent();
1592 /* we propagate the key event up */
1593 wxKeyEvent
ke( wxEVT_KEY_DOWN
);
1594 ke
.m_shiftDown
= event
.m_shiftDown
;
1595 ke
.m_controlDown
= event
.m_controlDown
;
1596 ke
.m_altDown
= event
.m_altDown
;
1597 ke
.m_metaDown
= event
.m_metaDown
;
1598 ke
.m_keyCode
= event
.m_keyCode
;
1601 ke
.SetEventObject( parent
);
1602 if (parent
->GetEventHandler()->ProcessEvent( ke
)) return;
1607 void wxListMainWindow::OnChar( wxKeyEvent
&event
)
1609 wxWindow
*parent
= GetParent();
1611 /* we send a list_key event up */
1612 wxListEvent
le( wxEVT_COMMAND_LIST_KEY_DOWN
, GetParent()->GetId() );
1613 le
.m_code
= (int)event
.KeyCode();
1614 le
.SetEventObject( parent
);
1615 parent
->GetEventHandler()->ProcessEvent( le
);
1617 /* we propagate the char event up */
1618 wxKeyEvent
ke( wxEVT_CHAR
);
1619 ke
.m_shiftDown
= event
.m_shiftDown
;
1620 ke
.m_controlDown
= event
.m_controlDown
;
1621 ke
.m_altDown
= event
.m_altDown
;
1622 ke
.m_metaDown
= event
.m_metaDown
;
1623 ke
.m_keyCode
= event
.m_keyCode
;
1626 ke
.SetEventObject( parent
);
1627 if (parent
->GetEventHandler()->ProcessEvent( ke
)) return;
1629 if (event
.KeyCode() == WXK_TAB
)
1631 wxNavigationKeyEvent nevent
;
1632 nevent
.SetDirection( !event
.ShiftDown() );
1633 nevent
.SetEventObject( GetParent()->GetParent() );
1634 nevent
.SetCurrentFocus( m_parent
);
1635 if (GetParent()->GetParent()->GetEventHandler()->ProcessEvent( nevent
)) return;
1638 /* no item -> nothing to do */
1645 switch (event
.KeyCode())
1649 wxNode
*node
= m_lines
.Member( m_current
)->Previous();
1650 if (node
) OnArrowChar( (wxListLineData
*)node
->Data(), event
.ShiftDown() );
1655 wxNode
*node
= m_lines
.Member( m_current
)->Next();
1656 if (node
) OnArrowChar( (wxListLineData
*)node
->Data(), event
.ShiftDown() );
1661 wxNode
*node
= m_lines
.Last();
1662 OnArrowChar( (wxListLineData
*)node
->Data(), event
.ShiftDown() );
1667 wxNode
*node
= m_lines
.First();
1668 OnArrowChar( (wxListLineData
*)node
->Data(), event
.ShiftDown() );
1674 if (m_mode
& wxLC_REPORT
)
1676 steps
= m_visibleLines
-1;
1681 wxNode
*node
= m_lines
.First();
1682 for (;;) { if (m_current
== (wxListLineData
*)node
->Data()) break; pos
++; node
= node
->Next(); }
1683 steps
= pos
% m_visibleLines
;
1685 wxNode
*node
= m_lines
.Member( m_current
);
1686 for (int i
= 0; i
< steps
; i
++) if (node
->Previous()) node
= node
->Previous();
1687 if (node
) OnArrowChar( (wxListLineData
*)node
->Data(), event
.ShiftDown() );
1693 if (m_mode
& wxLC_REPORT
)
1695 steps
= m_visibleLines
-1;
1699 int pos
= 0; wxNode
*node
= m_lines
.First();
1700 for (;;) { if (m_current
== (wxListLineData
*)node
->Data()) break; pos
++; node
= node
->Next(); }
1701 steps
= m_visibleLines
-(pos
% m_visibleLines
)-1;
1703 wxNode
*node
= m_lines
.Member( m_current
);
1704 for (int i
= 0; i
< steps
; i
++) if (node
->Next()) node
= node
->Next();
1705 if (node
) OnArrowChar( (wxListLineData
*)node
->Data(), event
.ShiftDown() );
1710 if (!(m_mode
& wxLC_REPORT
))
1712 wxNode
*node
= m_lines
.Member( m_current
);
1713 for (int i
= 0; i
<m_visibleLines
; i
++) if (node
->Previous()) node
= node
->Previous();
1714 if (node
) OnArrowChar( (wxListLineData
*)node
->Data(), event
.ShiftDown() );
1720 if (!(m_mode
& wxLC_REPORT
))
1722 wxNode
*node
= m_lines
.Member( m_current
);
1723 for (int i
= 0; i
<m_visibleLines
; i
++) if (node
->Next()) node
= node
->Next();
1724 if (node
) OnArrowChar( (wxListLineData
*)node
->Data(), event
.ShiftDown() );
1730 m_current
->ReverseHilight();
1731 RefreshLine( m_current
);
1736 if (!(m_mode
& wxLC_SINGLE_SEL
))
1738 wxListLineData
*oldCurrent
= m_current
;
1739 m_current
->ReverseHilight();
1740 wxNode
*node
= m_lines
.Member( m_current
)->Next();
1741 if (node
) m_current
= (wxListLineData
*)node
->Data();
1742 RefreshLine( oldCurrent
);
1743 RefreshLine( m_current
);
1744 UnfocusLine( oldCurrent
);
1745 FocusLine( m_current
);
1753 wxListEvent
le( wxEVT_COMMAND_LIST_ITEM_ACTIVATED
, GetParent()->GetId() );
1754 le
.SetEventObject( GetParent() );
1755 le
.m_itemIndex
= GetIndexOfLine( m_current
);
1756 m_current
->GetItem( 0, le
.m_item
);
1757 GetParent()->GetEventHandler()->ProcessEvent( le
);
1770 extern wxWindow
*g_focusWindow
;
1773 void wxListMainWindow::OnSetFocus( wxFocusEvent
&WXUNUSED(event
) )
1776 RefreshLine( m_current
);
1778 if (!GetParent()) return;
1781 g_focusWindow
= GetParent();
1784 wxFocusEvent
event( wxEVT_SET_FOCUS
, GetParent()->GetId() );
1785 event
.SetEventObject( GetParent() );
1786 GetParent()->GetEventHandler()->ProcessEvent( event
);
1789 void wxListMainWindow::OnKillFocus( wxFocusEvent
&WXUNUSED(event
) )
1792 RefreshLine( m_current
);
1795 void wxListMainWindow::OnSize( wxSizeEvent
&WXUNUSED(event
) )
1798 We don't even allow the wxScrolledWindow::AdjustScrollbars() call
1803 void wxListMainWindow::DrawImage( int index
, wxDC
*dc
, int x
, int y
)
1805 if ((m_mode
& wxLC_ICON
) && (m_normal_image_list
))
1807 m_normal_image_list
->Draw( index
, *dc
, x
, y
, wxIMAGELIST_DRAW_TRANSPARENT
);
1810 if ((m_mode
& wxLC_SMALL_ICON
) && (m_small_image_list
))
1812 m_small_image_list
->Draw( index
, *dc
, x
, y
, wxIMAGELIST_DRAW_TRANSPARENT
);
1814 if ((m_mode
& wxLC_LIST
) && (m_small_image_list
))
1816 m_small_image_list
->Draw( index
, *dc
, x
, y
, wxIMAGELIST_DRAW_TRANSPARENT
);
1818 if ((m_mode
& wxLC_REPORT
) && (m_small_image_list
))
1820 m_small_image_list
->Draw( index
, *dc
, x
, y
, wxIMAGELIST_DRAW_TRANSPARENT
);
1825 void wxListMainWindow::GetImageSize( int index
, int &width
, int &height
)
1827 if ((m_mode
& wxLC_ICON
) && (m_normal_image_list
))
1829 m_normal_image_list
->GetSize( index
, width
, height
);
1832 if ((m_mode
& wxLC_SMALL_ICON
) && (m_small_image_list
))
1834 m_small_image_list
->GetSize( index
, width
, height
);
1837 if ((m_mode
& wxLC_LIST
) && (m_small_image_list
))
1839 m_small_image_list
->GetSize( index
, width
, height
);
1842 if ((m_mode
& wxLC_REPORT
) && (m_small_image_list
))
1844 m_small_image_list
->GetSize( index
, width
, height
);
1851 int wxListMainWindow::GetTextLength( wxString
&s
)
1853 wxClientDC
dc( this );
1856 dc
.GetTextExtent( s
, &lw
, &lh
);
1860 int wxListMainWindow::GetIndexOfLine( const wxListLineData
*line
)
1863 wxNode
*node
= m_lines
.First();
1866 if (line
== (wxListLineData
*)node
->Data()) return i
;
1868 node
= node
->Next();
1873 void wxListMainWindow::SetImageList( wxImageList
*imageList
, int which
)
1876 if (which
== wxIMAGE_LIST_NORMAL
) m_normal_image_list
= imageList
;
1877 if (which
== wxIMAGE_LIST_SMALL
) m_small_image_list
= imageList
;
1880 void wxListMainWindow::SetItemSpacing( int spacing
, bool isSmall
)
1885 m_small_spacing
= spacing
;
1889 m_normal_spacing
= spacing
;
1893 int wxListMainWindow::GetItemSpacing( bool isSmall
)
1895 if (isSmall
) return m_small_spacing
; else return m_normal_spacing
;
1898 void wxListMainWindow::SetColumn( int col
, wxListItem
&item
)
1901 wxNode
*node
= m_columns
.Nth( col
);
1904 if (item
.m_width
== wxLIST_AUTOSIZE_USEHEADER
) item
.m_width
= GetTextLength( item
.m_text
)+7;
1905 wxListHeaderData
*column
= (wxListHeaderData
*)node
->Data();
1906 column
->SetItem( item
);
1908 wxListCtrl
*lc
= (wxListCtrl
*) GetParent();
1909 if (lc
->m_headerWin
) lc
->m_headerWin
->Refresh();
1912 void wxListMainWindow::SetColumnWidth( int col
, int width
)
1914 if (!(m_mode
& wxLC_REPORT
)) return;
1918 wxNode
*node
= (wxNode
*) NULL
;
1920 if (width
== wxLIST_AUTOSIZE_USEHEADER
) width
= 80;
1921 if (width
== wxLIST_AUTOSIZE
)
1923 wxClientDC
dc(this);
1924 dc
.SetFont( GetFont() );
1926 node
= m_lines
.First();
1929 wxListLineData
*line
= (wxListLineData
*)node
->Data();
1930 wxNode
*n
= line
->m_items
.Nth( col
);
1933 wxListItemData
*item
= (wxListItemData
*)n
->Data();
1934 int current
= 0, ix
= 0, iy
= 0;
1935 wxCoord lx
= 0, ly
= 0;
1936 if (item
->HasImage())
1938 GetImageSize( item
->GetImage(), ix
, iy
);
1941 if (item
->HasText())
1944 item
->GetText( str
);
1945 dc
.GetTextExtent( str
, &lx
, &ly
);
1948 if (current
> max
) max
= current
;
1950 node
= node
->Next();
1955 node
= m_columns
.Nth( col
);
1958 wxListHeaderData
*column
= (wxListHeaderData
*)node
->Data();
1959 column
->SetWidth( width
);
1962 node
= m_lines
.First();
1965 wxListLineData
*line
= (wxListLineData
*)node
->Data();
1966 wxNode
*n
= line
->m_items
.Nth( col
);
1969 wxListItemData
*item
= (wxListItemData
*)n
->Data();
1970 item
->SetSize( width
, -1 );
1972 node
= node
->Next();
1975 wxListCtrl
*lc
= (wxListCtrl
*) GetParent();
1976 if (lc
->m_headerWin
) lc
->m_headerWin
->Refresh();
1979 void wxListMainWindow::GetColumn( int col
, wxListItem
&item
)
1981 wxNode
*node
= m_columns
.Nth( col
);
1984 wxListHeaderData
*column
= (wxListHeaderData
*)node
->Data();
1985 column
->GetItem( item
);
1997 int wxListMainWindow::GetColumnWidth( int col
)
1999 wxNode
*node
= m_columns
.Nth( col
);
2002 wxListHeaderData
*column
= (wxListHeaderData
*)node
->Data();
2003 return column
->GetWidth();
2011 int wxListMainWindow::GetColumnCount()
2013 return m_columns
.Number();
2016 int wxListMainWindow::GetCountPerPage()
2018 return m_visibleLines
;
2021 void wxListMainWindow::SetItem( wxListItem
&item
)
2024 wxNode
*node
= m_lines
.Nth( (size_t)item
.m_itemId
);
2027 wxListLineData
*line
= (wxListLineData
*)node
->Data();
2028 if (m_mode
& wxLC_REPORT
) item
.m_width
= GetColumnWidth( item
.m_col
)-3;
2029 line
->SetItem( item
.m_col
, item
);
2033 void wxListMainWindow::SetItemState( long item
, long state
, long stateMask
)
2035 // m_dirty = TRUE; no recalcs needed
2037 wxListLineData
*oldCurrent
= m_current
;
2039 if (stateMask
& wxLIST_STATE_FOCUSED
)
2041 wxNode
*node
= m_lines
.Nth( (size_t)item
);
2044 wxListLineData
*line
= (wxListLineData
*)node
->Data();
2045 UnfocusLine( m_current
);
2047 FocusLine( m_current
);
2048 RefreshLine( m_current
);
2049 if (oldCurrent
) RefreshLine( oldCurrent
);
2053 if (stateMask
& wxLIST_STATE_SELECTED
)
2055 bool on
= (state
& wxLIST_STATE_SELECTED
) != 0;
2056 if (!on
&& (m_mode
& wxLC_SINGLE_SEL
)) return;
2058 wxNode
*node
= m_lines
.Nth( (size_t)item
);
2061 wxListLineData
*line
= (wxListLineData
*)node
->Data();
2062 if (m_mode
& wxLC_SINGLE_SEL
)
2064 UnfocusLine( m_current
);
2066 FocusLine( m_current
);
2067 if (oldCurrent
) oldCurrent
->Hilight( FALSE
);
2068 RefreshLine( m_current
);
2069 if (oldCurrent
) RefreshLine( oldCurrent
);
2071 bool on
= (state
& wxLIST_STATE_SELECTED
) != 0;
2072 if (on
!= line
->IsHilighted())
2074 line
->Hilight( on
);
2075 RefreshLine( line
);
2081 int wxListMainWindow::GetItemState( long item
, long stateMask
)
2083 int ret
= wxLIST_STATE_DONTCARE
;
2084 if (stateMask
& wxLIST_STATE_FOCUSED
)
2086 wxNode
*node
= m_lines
.Nth( (size_t)item
);
2089 wxListLineData
*line
= (wxListLineData
*)node
->Data();
2090 if (line
== m_current
) ret
|= wxLIST_STATE_FOCUSED
;
2093 if (stateMask
& wxLIST_STATE_SELECTED
)
2095 wxNode
*node
= m_lines
.Nth( (size_t)item
);
2098 wxListLineData
*line
= (wxListLineData
*)node
->Data();
2099 if (line
->IsHilighted()) ret
|= wxLIST_STATE_FOCUSED
;
2105 void wxListMainWindow::GetItem( wxListItem
&item
)
2107 wxNode
*node
= m_lines
.Nth( (size_t)item
.m_itemId
);
2110 wxListLineData
*line
= (wxListLineData
*)node
->Data();
2111 line
->GetItem( item
.m_col
, item
);
2122 int wxListMainWindow::GetItemCount()
2124 return m_lines
.Number();
2127 void wxListMainWindow::GetItemRect( long index
, wxRect
&rect
)
2129 wxNode
*node
= m_lines
.Nth( (size_t)index
);
2132 wxListLineData
*line
= (wxListLineData
*)node
->Data();
2133 line
->GetRect( rect
);
2144 bool wxListMainWindow::GetItemPosition(long item
, wxPoint
& pos
)
2146 wxNode
*node
= m_lines
.Nth( (size_t)item
);
2150 wxListLineData
*line
= (wxListLineData
*)node
->Data();
2151 line
->GetRect( rect
);
2163 int wxListMainWindow::GetSelectedItemCount()
2166 wxNode
*node
= m_lines
.First();
2169 wxListLineData
*line
= (wxListLineData
*)node
->Data();
2170 if (line
->IsHilighted()) ret
++;
2171 node
= node
->Next();
2176 void wxListMainWindow::SetMode( long mode
)
2183 if (m_mode
& wxLC_REPORT
)
2185 #if wxUSE_GENERIC_LIST_EXTENSIONS
2199 long wxListMainWindow::GetMode() const
2204 void wxListMainWindow::CalculatePositions()
2206 if (!m_lines
.First()) return;
2208 wxClientDC
dc( this );
2209 dc
.SetFont( GetFont() );
2211 int iconSpacing
= 0;
2212 if (m_mode
& wxLC_ICON
) iconSpacing
= m_normal_spacing
;
2213 if (m_mode
& wxLC_SMALL_ICON
) iconSpacing
= m_small_spacing
;
2215 // we take the first line (which also can be an icon or
2216 // an a text item in wxLC_ICON and wxLC_LIST modes) to
2217 // measure the size of the line
2221 int lineSpacing
= 0;
2223 wxListLineData
*line
= (wxListLineData
*)m_lines
.First()->Data();
2224 line
->CalculateSize( &dc
, iconSpacing
);
2226 line
->GetSize( dummy
, lineSpacing
);
2229 int clientWidth
= 0;
2230 int clientHeight
= 0;
2232 if (m_mode
& wxLC_REPORT
)
2236 int entireHeight
= m_lines
.Number() * lineSpacing
+ 2;
2237 int scroll_pos
= GetScrollPos( wxVERTICAL
);
2238 #if wxUSE_GENERIC_LIST_EXTENSIONS
2239 int x_scroll_pos
= GetScrollPos( wxHORIZONTAL
);
2241 SetScrollbars( m_xScroll
, m_yScroll
, 0, (entireHeight
+15) / m_yScroll
, 0, scroll_pos
, TRUE
);
2243 GetClientSize( &clientWidth
, &clientHeight
);
2245 wxNode
* node
= m_lines
.First();
2246 int entireWidth
= 0 ;
2249 wxListLineData
*line
= (wxListLineData
*)node
->Data();
2250 line
->CalculateSize( &dc
, iconSpacing
);
2251 line
->SetPosition( &dc
, x
, y
, clientWidth
);
2253 for (int i
= 0; i
< GetColumnCount(); i
++)
2255 line
->SetColumnPosition( i
, col_x
);
2256 col_x
+= GetColumnWidth( i
);
2258 entireWidth
= wxMax( entireWidth
, col_x
) ;
2259 #if wxUSE_GENERIC_LIST_EXTENSIONS
2260 line
->SetPosition( &dc
, x
, y
, col_x
);
2262 y
+= lineSpacing
; // one pixel blank line between items
2263 node
= node
->Next();
2265 m_visibleLines
= clientHeight
/ lineSpacing
;
2266 #if wxUSE_GENERIC_LIST_EXTENSIONS
2267 SetScrollbars( m_xScroll
, m_yScroll
, entireWidth
/ m_xScroll
, (entireHeight
+15) / m_yScroll
, x_scroll_pos
, scroll_pos
, TRUE
);
2272 // at first we try without any scrollbar. if the items don't
2273 // fit into the window, we recalculate after subtracting an
2274 // approximated 15 pt for the horizontal scrollbar
2276 GetSize( &clientWidth
, &clientHeight
);
2277 clientHeight
-= 4; // sunken frame
2279 int entireWidth
= 0;
2281 for (int tries
= 0; tries
< 2; tries
++)
2284 int x
= 5; // painting is done at x-2
2285 int y
= 5; // painting is done at y-2
2288 int m_currentVisibleLines
= 0;
2289 wxNode
*node
= m_lines
.First();
2292 m_currentVisibleLines
++;
2293 wxListLineData
*line
= (wxListLineData
*)node
->Data();
2294 line
->CalculateSize( &dc
, iconSpacing
);
2295 line
->SetPosition( &dc
, x
, y
, clientWidth
);
2296 line
->GetSize( lineWidth
, lineHeight
);
2297 if (lineWidth
> maxWidth
) maxWidth
= lineWidth
;
2299 if (m_currentVisibleLines
> m_visibleLines
)
2300 m_visibleLines
= m_currentVisibleLines
;
2301 if (y
+lineSpacing
-6 >= clientHeight
) // -6 for earlier "line breaking"
2303 m_currentVisibleLines
= 0;
2306 entireWidth
+= maxWidth
+6;
2309 node
= node
->Next();
2310 if (!node
) entireWidth
+= maxWidth
;
2311 if ((tries
== 0) && (entireWidth
> clientWidth
))
2313 clientHeight
-= 15; // scrollbar height
2315 m_currentVisibleLines
= 0;
2318 if (!node
) tries
= 1; // everything fits, no second try required
2322 int scroll_pos
= GetScrollPos( wxHORIZONTAL
);
2323 SetScrollbars( m_xScroll
, m_yScroll
, (entireWidth
+15) / m_xScroll
, 0, scroll_pos
, 0, TRUE
);
2327 void wxListMainWindow::RealizeChanges( void )
2331 wxNode
*node
= m_lines
.First();
2332 if (node
) m_current
= (wxListLineData
*)node
->Data();
2336 FocusLine( m_current
);
2337 if (m_mode
& wxLC_SINGLE_SEL
) m_current
->Hilight( TRUE
);
2341 long wxListMainWindow::GetNextItem( long item
,
2342 int WXUNUSED(geometry
),
2346 max
= GetItemCount();
2347 wxCHECK_MSG( (ret
== -1) || (ret
< max
), -1,
2348 _T("invalid listctrl index in GetNextItem()") );
2350 // notice that we start with the next item (or the first one if item == -1)
2351 // and this is intentional to allow writing a simple loop to iterate over
2352 // all selected items
2356 // this is not an error because the index was ok initially, just no
2361 wxNode
*node
= m_lines
.Nth( (size_t)ret
);
2364 wxListLineData
*line
= (wxListLineData
*)node
->Data();
2365 if ((state
& wxLIST_STATE_FOCUSED
) && (line
== m_current
))
2367 if ((state
& wxLIST_STATE_SELECTED
) && (line
->IsHilighted()))
2373 node
= node
->Next();
2379 void wxListMainWindow::DeleteItem( long index
)
2382 wxNode
*node
= m_lines
.Nth( (size_t)index
);
2385 wxListLineData
*line
= (wxListLineData
*)node
->Data();
2386 if (m_current
== line
) m_current
= (wxListLineData
*) NULL
;
2388 m_lines
.DeleteNode( node
);
2392 void wxListMainWindow::DeleteColumn( int col
)
2394 wxCHECK_RET( col
< (int)m_columns
.GetCount(),
2395 wxT("attempting to delete inexistent column in wxListView") );
2398 wxNode
*node
= m_columns
.Nth( col
);
2399 if (node
) m_columns
.DeleteNode( node
);
2402 void wxListMainWindow::DeleteAllItems()
2405 m_current
= (wxListLineData
*) NULL
;
2407 // to make the deletion of all items faster, we don't send the
2408 // notifications in this case: this is compatible with wxMSW and
2409 // documented in DeleteAllItems() description
2411 wxListEvent
event( wxEVT_COMMAND_LIST_DELETE_ALL_ITEMS
, GetParent()->GetId() );
2412 event
.SetEventObject( GetParent() );
2413 GetParent()->GetEventHandler()->ProcessEvent( event
);
2418 void wxListMainWindow::DeleteEverything()
2425 void wxListMainWindow::EnsureVisible( long index
)
2427 // We have to call this here because the label in
2428 // question might just have been added and no screen
2429 // update taken place.
2430 if (m_dirty
) wxYield();
2432 wxListLineData
*oldCurrent
= m_current
;
2433 m_current
= (wxListLineData
*) NULL
;
2434 wxNode
*node
= m_lines
.Nth( (size_t)index
);
2435 if (node
) m_current
= (wxListLineData
*)node
->Data();
2436 if (m_current
) MoveToFocus();
2437 m_current
= oldCurrent
;
2440 long wxListMainWindow::FindItem(long start
, const wxString
& str
, bool WXUNUSED(partial
) )
2444 if (pos
< 0) pos
= 0;
2445 wxNode
*node
= m_lines
.Nth( (size_t)pos
);
2448 wxListLineData
*line
= (wxListLineData
*)node
->Data();
2450 line
->GetText( 0, s
);
2451 if (s
== tmp
) return pos
;
2452 node
= node
->Next();
2458 long wxListMainWindow::FindItem(long start
, long data
)
2461 if (pos
< 0) pos
= 0;
2462 wxNode
*node
= m_lines
.Nth( (size_t)pos
);
2465 wxListLineData
*line
= (wxListLineData
*)node
->Data();
2467 line
->GetItem( 0, item
);
2468 if (item
.m_data
== data
) return pos
;
2469 node
= node
->Next();
2475 long wxListMainWindow::HitTest( int x
, int y
, int &flags
)
2477 wxNode
*node
= m_lines
.First();
2481 wxListLineData
*line
= (wxListLineData
*)node
->Data();
2482 long ret
= line
->IsHit( x
, y
);
2488 node
= node
->Next();
2494 void wxListMainWindow::InsertItem( wxListItem
&item
)
2498 if (m_mode
& wxLC_REPORT
) mode
= wxLC_REPORT
;
2499 else if (m_mode
& wxLC_LIST
) mode
= wxLC_LIST
;
2500 else if (m_mode
& wxLC_ICON
) mode
= wxLC_ICON
;
2501 else if (m_mode
& wxLC_SMALL_ICON
) mode
= wxLC_ICON
; // no typo
2503 wxListLineData
*line
= new wxListLineData( this, mode
, m_hilightBrush
);
2505 if (m_mode
& wxLC_REPORT
)
2507 line
->InitItems( GetColumnCount() );
2508 item
.m_width
= GetColumnWidth( 0 )-3;
2512 line
->InitItems( 1 );
2515 line
->SetItem( 0, item
);
2516 if ((item
.m_itemId
>= 0) && (item
.m_itemId
< (int)m_lines
.GetCount()))
2518 wxNode
*node
= m_lines
.Nth( (size_t)item
.m_itemId
);
2519 if (node
) m_lines
.Insert( node
, line
);
2523 m_lines
.Append( line
);
2527 void wxListMainWindow::InsertColumn( long col
, wxListItem
&item
)
2530 if (m_mode
& wxLC_REPORT
)
2532 if (item
.m_width
== wxLIST_AUTOSIZE_USEHEADER
) item
.m_width
= GetTextLength( item
.m_text
);
2533 wxListHeaderData
*column
= new wxListHeaderData( item
);
2534 if ((col
>= 0) && (col
< (int)m_columns
.GetCount()))
2536 wxNode
*node
= m_columns
.Nth( (size_t)col
);
2538 m_columns
.Insert( node
, column
);
2542 m_columns
.Append( column
);
2547 wxListCtrlCompare list_ctrl_compare_func_2
;
2548 long list_ctrl_compare_data
;
2550 int LINKAGEMODE
list_ctrl_compare_func_1( const void *arg1
, const void *arg2
)
2552 wxListLineData
*line1
= *((wxListLineData
**)arg1
);
2553 wxListLineData
*line2
= *((wxListLineData
**)arg2
);
2555 line1
->GetItem( 0, item
);
2556 long data1
= item
.m_data
;
2557 line2
->GetItem( 0, item
);
2558 long data2
= item
.m_data
;
2559 return list_ctrl_compare_func_2( data1
, data2
, list_ctrl_compare_data
);
2562 void wxListMainWindow::SortItems( wxListCtrlCompare fn
, long data
)
2564 list_ctrl_compare_func_2
= fn
;
2565 list_ctrl_compare_data
= data
;
2566 m_lines
.Sort( list_ctrl_compare_func_1
);
2570 void wxListMainWindow::OnScroll(wxScrollWinEvent
& event
)
2572 wxScrolledWindow::OnScroll( event
) ;
2573 #if wxUSE_GENERIC_LIST_EXTENSIONS
2575 if (event
.GetOrientation() == wxHORIZONTAL
&& ( m_mode
& wxLC_REPORT
))
2577 wxListCtrl
* lc
= wxDynamicCast( GetParent() , wxListCtrl
) ;
2580 lc
->m_headerWin
->Refresh() ;
2582 lc
->m_headerWin
->MacUpdateImmediately() ;
2589 // -------------------------------------------------------------------------------------
2591 // -------------------------------------------------------------------------------------
2593 IMPLEMENT_DYNAMIC_CLASS(wxListItem
, wxObject
)
2595 wxListItem::wxListItem()
2604 m_format
= wxLIST_FORMAT_CENTRE
;
2610 void wxListItem::Clear()
2619 m_format
= wxLIST_FORMAT_CENTRE
;
2621 m_text
= wxEmptyString
;
2623 if (m_attr
) delete m_attr
;
2627 void wxListItem::ClearAttributes()
2629 if (m_attr
) delete m_attr
;
2633 // -------------------------------------------------------------------------------------
2635 // -------------------------------------------------------------------------------------
2637 IMPLEMENT_DYNAMIC_CLASS(wxListEvent
, wxNotifyEvent
)
2639 wxListEvent::wxListEvent( wxEventType commandType
, int id
):
2640 wxNotifyEvent( commandType
, id
)
2646 m_cancelled
= FALSE
;
2651 void wxListEvent::CopyObject(wxObject
& object_dest
) const
2653 wxListEvent
*obj
= (wxListEvent
*)&object_dest
;
2655 wxNotifyEvent::CopyObject(object_dest
);
2657 obj
->m_code
= m_code
;
2658 obj
->m_itemIndex
= m_itemIndex
;
2659 obj
->m_oldItemIndex
= m_oldItemIndex
;
2661 obj
->m_cancelled
= m_cancelled
;
2662 obj
->m_pointDrag
= m_pointDrag
;
2663 obj
->m_item
.m_mask
= m_item
.m_mask
;
2664 obj
->m_item
.m_itemId
= m_item
.m_itemId
;
2665 obj
->m_item
.m_col
= m_item
.m_col
;
2666 obj
->m_item
.m_state
= m_item
.m_state
;
2667 obj
->m_item
.m_stateMask
= m_item
.m_stateMask
;
2668 obj
->m_item
.m_text
= m_item
.m_text
;
2669 obj
->m_item
.m_image
= m_item
.m_image
;
2670 obj
->m_item
.m_data
= m_item
.m_data
;
2671 obj
->m_item
.m_format
= m_item
.m_format
;
2672 obj
->m_item
.m_width
= m_item
.m_width
;
2674 if ( m_item
.HasAttributes() )
2676 obj
->m_item
.SetTextColour(m_item
.GetTextColour());
2680 // -------------------------------------------------------------------------------------
2682 // -------------------------------------------------------------------------------------
2684 IMPLEMENT_DYNAMIC_CLASS(wxListCtrl
, wxControl
)
2686 BEGIN_EVENT_TABLE(wxListCtrl
,wxControl
)
2687 EVT_SIZE (wxListCtrl::OnSize
)
2688 EVT_IDLE (wxListCtrl::OnIdle
)
2691 wxListCtrl::wxListCtrl()
2693 m_imageListNormal
= (wxImageList
*) NULL
;
2694 m_imageListSmall
= (wxImageList
*) NULL
;
2695 m_imageListState
= (wxImageList
*) NULL
;
2696 m_mainWin
= (wxListMainWindow
*) NULL
;
2697 m_headerWin
= (wxListHeaderWindow
*) NULL
;
2700 wxListCtrl::~wxListCtrl()
2704 bool wxListCtrl::Create(wxWindow
*parent
,
2709 const wxValidator
&validator
,
2710 const wxString
&name
)
2712 m_imageListNormal
= (wxImageList
*) NULL
;
2713 m_imageListSmall
= (wxImageList
*) NULL
;
2714 m_imageListState
= (wxImageList
*) NULL
;
2715 m_mainWin
= (wxListMainWindow
*) NULL
;
2716 m_headerWin
= (wxListHeaderWindow
*) NULL
;
2718 if ( !(style
& (wxLC_REPORT
| wxLC_LIST
| wxLC_ICON
)) )
2720 style
= style
| wxLC_LIST
;
2723 bool ret
= wxControl::Create( parent
, id
, pos
, size
, style
, validator
, name
);
2726 if (style
& wxSUNKEN_BORDER
)
2727 style
-= wxSUNKEN_BORDER
;
2729 m_mainWin
= new wxListMainWindow( this, -1, wxPoint(0,0), size
, style
);
2731 if (HasFlag(wxLC_REPORT
))
2733 m_headerWin
= new wxListHeaderWindow( this, -1, m_mainWin
, wxPoint(0,0), wxSize(size
.x
,23), wxTAB_TRAVERSAL
);
2734 if (HasFlag(wxLC_NO_HEADER
))
2735 m_headerWin
->Show( FALSE
);
2739 m_headerWin
= (wxListHeaderWindow
*) NULL
;
2742 SetBackgroundColour( wxSystemSettings::GetSystemColour( wxSYS_COLOUR_LISTBOX
) );
2747 void wxListCtrl::OnSize( wxSizeEvent
&WXUNUSED(event
) )
2749 /* handled in OnIdle */
2751 if (m_mainWin
) m_mainWin
->m_dirty
= TRUE
;
2754 void wxListCtrl::SetSingleStyle( long style
, bool add
)
2756 long flag
= GetWindowStyle();
2760 if (style
& wxLC_MASK_TYPE
) flag
= flag
& ~wxLC_MASK_TYPE
;
2761 if (style
& wxLC_MASK_ALIGN
) flag
= flag
& ~wxLC_MASK_ALIGN
;
2762 if (style
& wxLC_MASK_SORT
) flag
= flag
& ~wxLC_MASK_SORT
;
2771 if (flag
& style
) flag
-= style
;
2774 SetWindowStyleFlag( flag
);
2777 void wxListCtrl::SetWindowStyleFlag( long flag
)
2781 m_mainWin
->DeleteEverything();
2785 GetClientSize( &width
, &height
);
2787 m_mainWin
->SetMode( flag
);
2789 if (flag
& wxLC_REPORT
)
2791 if (!HasFlag(wxLC_REPORT
))
2795 m_headerWin
= new wxListHeaderWindow( this, -1, m_mainWin
,
2796 wxPoint(0,0), wxSize(width
,23), wxTAB_TRAVERSAL
);
2797 if (HasFlag(wxLC_NO_HEADER
))
2798 m_headerWin
->Show( FALSE
);
2802 if (flag
& wxLC_NO_HEADER
)
2803 m_headerWin
->Show( FALSE
);
2805 m_headerWin
->Show( TRUE
);
2811 if (HasFlag(wxLC_REPORT
) && !(HasFlag(wxLC_NO_HEADER
)))
2813 m_headerWin
->Show( FALSE
);
2818 wxWindow::SetWindowStyleFlag( flag
);
2821 bool wxListCtrl::GetColumn(int col
, wxListItem
&item
) const
2823 m_mainWin
->GetColumn( col
, item
);
2827 bool wxListCtrl::SetColumn( int col
, wxListItem
& item
)
2829 m_mainWin
->SetColumn( col
, item
);
2833 int wxListCtrl::GetColumnWidth( int col
) const
2835 return m_mainWin
->GetColumnWidth( col
);
2838 bool wxListCtrl::SetColumnWidth( int col
, int width
)
2840 m_mainWin
->SetColumnWidth( col
, width
);
2844 int wxListCtrl::GetCountPerPage() const
2846 return m_mainWin
->GetCountPerPage(); // different from Windows ?
2849 bool wxListCtrl::GetItem( wxListItem
&info
) const
2851 m_mainWin
->GetItem( info
);
2855 bool wxListCtrl::SetItem( wxListItem
&info
)
2857 m_mainWin
->SetItem( info
);
2861 long wxListCtrl::SetItem( long index
, int col
, const wxString
& label
, int imageId
)
2864 info
.m_text
= label
;
2865 info
.m_mask
= wxLIST_MASK_TEXT
;
2866 info
.m_itemId
= index
;
2870 info
.m_image
= imageId
;
2871 info
.m_mask
|= wxLIST_MASK_IMAGE
;
2873 m_mainWin
->SetItem(info
);
2877 int wxListCtrl::GetItemState( long item
, long stateMask
) const
2879 return m_mainWin
->GetItemState( item
, stateMask
);
2882 bool wxListCtrl::SetItemState( long item
, long state
, long stateMask
)
2884 m_mainWin
->SetItemState( item
, state
, stateMask
);
2888 bool wxListCtrl::SetItemImage( long item
, int image
, int WXUNUSED(selImage
) )
2891 info
.m_image
= image
;
2892 info
.m_mask
= wxLIST_MASK_IMAGE
;
2893 info
.m_itemId
= item
;
2894 m_mainWin
->SetItem( info
);
2898 wxString
wxListCtrl::GetItemText( long item
) const
2901 info
.m_itemId
= item
;
2902 m_mainWin
->GetItem( info
);
2906 void wxListCtrl::SetItemText( long item
, const wxString
&str
)
2909 info
.m_mask
= wxLIST_MASK_TEXT
;
2910 info
.m_itemId
= item
;
2912 m_mainWin
->SetItem( info
);
2915 long wxListCtrl::GetItemData( long item
) const
2918 info
.m_itemId
= item
;
2919 m_mainWin
->GetItem( info
);
2923 bool wxListCtrl::SetItemData( long item
, long data
)
2926 info
.m_mask
= wxLIST_MASK_DATA
;
2927 info
.m_itemId
= item
;
2929 m_mainWin
->SetItem( info
);
2933 bool wxListCtrl::GetItemRect( long item
, wxRect
&rect
, int WXUNUSED(code
) ) const
2935 m_mainWin
->GetItemRect( item
, rect
);
2939 bool wxListCtrl::GetItemPosition( long item
, wxPoint
& pos
) const
2941 m_mainWin
->GetItemPosition( item
, pos
);
2945 bool wxListCtrl::SetItemPosition( long WXUNUSED(item
), const wxPoint
& WXUNUSED(pos
) )
2950 int wxListCtrl::GetItemCount() const
2952 return m_mainWin
->GetItemCount();
2955 int wxListCtrl::GetColumnCount() const
2957 return m_mainWin
->GetColumnCount();
2960 void wxListCtrl::SetItemSpacing( int spacing
, bool isSmall
)
2962 m_mainWin
->SetItemSpacing( spacing
, isSmall
);
2965 int wxListCtrl::GetItemSpacing( bool isSmall
) const
2967 return m_mainWin
->GetItemSpacing( isSmall
);
2970 int wxListCtrl::GetSelectedItemCount() const
2972 return m_mainWin
->GetSelectedItemCount();
2975 wxColour
wxListCtrl::GetTextColour() const
2977 return GetForegroundColour();
2980 void wxListCtrl::SetTextColour(const wxColour
& col
)
2982 SetForegroundColour(col
);
2985 long wxListCtrl::GetTopItem() const
2990 long wxListCtrl::GetNextItem( long item
, int geom
, int state
) const
2992 return m_mainWin
->GetNextItem( item
, geom
, state
);
2995 wxImageList
*wxListCtrl::GetImageList(int which
) const
2997 if (which
== wxIMAGE_LIST_NORMAL
)
2999 return m_imageListNormal
;
3001 else if (which
== wxIMAGE_LIST_SMALL
)
3003 return m_imageListSmall
;
3005 else if (which
== wxIMAGE_LIST_STATE
)
3007 return m_imageListState
;
3009 return (wxImageList
*) NULL
;
3012 void wxListCtrl::SetImageList( wxImageList
*imageList
, int which
)
3014 m_mainWin
->SetImageList( imageList
, which
);
3017 bool wxListCtrl::Arrange( int WXUNUSED(flag
) )
3022 bool wxListCtrl::DeleteItem( long item
)
3024 m_mainWin
->DeleteItem( item
);
3028 bool wxListCtrl::DeleteAllItems()
3030 m_mainWin
->DeleteAllItems();
3034 bool wxListCtrl::DeleteAllColumns()
3036 for ( size_t n
= 0; n
< m_mainWin
->m_columns
.GetCount(); n
++ )
3042 void wxListCtrl::ClearAll()
3044 m_mainWin
->DeleteEverything();
3047 bool wxListCtrl::DeleteColumn( int col
)
3049 m_mainWin
->DeleteColumn( col
);
3053 void wxListCtrl::Edit( long item
)
3055 m_mainWin
->Edit( item
);
3058 bool wxListCtrl::EnsureVisible( long item
)
3060 m_mainWin
->EnsureVisible( item
);
3064 long wxListCtrl::FindItem( long start
, const wxString
& str
, bool partial
)
3066 return m_mainWin
->FindItem( start
, str
, partial
);
3069 long wxListCtrl::FindItem( long start
, long data
)
3071 return m_mainWin
->FindItem( start
, data
);
3074 long wxListCtrl::FindItem( long WXUNUSED(start
), const wxPoint
& WXUNUSED(pt
),
3075 int WXUNUSED(direction
))
3080 long wxListCtrl::HitTest( const wxPoint
&point
, int &flags
)
3082 return m_mainWin
->HitTest( (int)point
.x
, (int)point
.y
, flags
);
3085 long wxListCtrl::InsertItem( wxListItem
& info
)
3087 m_mainWin
->InsertItem( info
);
3088 return info
.m_itemId
;
3091 long wxListCtrl::InsertItem( long index
, const wxString
&label
)
3094 info
.m_text
= label
;
3095 info
.m_mask
= wxLIST_MASK_TEXT
;
3096 info
.m_itemId
= index
;
3097 return InsertItem( info
);
3100 long wxListCtrl::InsertItem( long index
, int imageIndex
)
3103 info
.m_mask
= wxLIST_MASK_IMAGE
;
3104 info
.m_image
= imageIndex
;
3105 info
.m_itemId
= index
;
3106 return InsertItem( info
);
3109 long wxListCtrl::InsertItem( long index
, const wxString
&label
, int imageIndex
)
3112 info
.m_text
= label
;
3113 info
.m_image
= imageIndex
;
3114 info
.m_mask
= wxLIST_MASK_TEXT
| wxLIST_MASK_IMAGE
;
3115 info
.m_itemId
= index
;
3116 return InsertItem( info
);
3119 long wxListCtrl::InsertColumn( long col
, wxListItem
&item
)
3121 wxASSERT( m_headerWin
);
3122 m_mainWin
->InsertColumn( col
, item
);
3123 m_headerWin
->Refresh();
3128 long wxListCtrl::InsertColumn( long col
, const wxString
&heading
,
3129 int format
, int width
)
3132 item
.m_mask
= wxLIST_MASK_TEXT
| wxLIST_MASK_FORMAT
;
3133 item
.m_text
= heading
;
3136 item
.m_mask
|= wxLIST_MASK_WIDTH
;
3137 item
.m_width
= width
;
3139 item
.m_format
= format
;
3141 return InsertColumn( col
, item
);
3144 bool wxListCtrl::ScrollList( int WXUNUSED(dx
), int WXUNUSED(dy
) )
3150 // fn is a function which takes 3 long arguments: item1, item2, data.
3151 // item1 is the long data associated with a first item (NOT the index).
3152 // item2 is the long data associated with a second item (NOT the index).
3153 // data is the same value as passed to SortItems.
3154 // The return value is a negative number if the first item should precede the second
3155 // item, a positive number of the second item should precede the first,
3156 // or zero if the two items are equivalent.
3157 // data is arbitrary data to be passed to the sort function.
3159 bool wxListCtrl::SortItems( wxListCtrlCompare fn
, long data
)
3161 m_mainWin
->SortItems( fn
, data
);
3165 void wxListCtrl::OnIdle( wxIdleEvent
&WXUNUSED(event
) )
3167 if (!m_mainWin
->m_dirty
) return;
3171 GetClientSize( &cw
, &ch
);
3178 if (HasFlag(wxLC_REPORT
) && !HasFlag(wxLC_NO_HEADER
))
3180 m_headerWin
->GetPosition( &x
, &y
);
3181 m_headerWin
->GetSize( &w
, &h
);
3182 if ((x
!= 0) || (y
!= 0) || (w
!= cw
) || (h
!= 23))
3183 m_headerWin
->SetSize( 0, 0, cw
, 23 );
3185 m_mainWin
->GetPosition( &x
, &y
);
3186 m_mainWin
->GetSize( &w
, &h
);
3187 if ((x
!= 0) || (y
!= 24) || (w
!= cw
) || (h
!= ch
-24))
3188 m_mainWin
->SetSize( 0, 24, cw
, ch
-24 );
3192 m_mainWin
->GetPosition( &x
, &y
);
3193 m_mainWin
->GetSize( &w
, &h
);
3194 if ((x
!= 0) || (y
!= 24) || (w
!= cw
) || (h
!= ch
))
3195 m_mainWin
->SetSize( 0, 0, cw
, ch
);
3198 m_mainWin
->CalculatePositions();
3199 m_mainWin
->RealizeChanges();
3200 m_mainWin
->m_dirty
= FALSE
;
3201 m_mainWin
->Refresh();
3204 bool wxListCtrl::SetBackgroundColour( const wxColour
&colour
)
3206 if ( !wxWindow::SetBackgroundColour( colour
) )
3211 m_mainWin
->SetBackgroundColour( colour
);
3212 m_mainWin
->m_dirty
= TRUE
;
3217 // m_headerWin->SetBackgroundColour( colour );
3223 bool wxListCtrl::SetForegroundColour( const wxColour
&colour
)
3225 if ( !wxWindow::SetForegroundColour( colour
) )
3230 m_mainWin
->SetForegroundColour( colour
);
3231 m_mainWin
->m_dirty
= TRUE
;
3236 m_headerWin
->SetForegroundColour( colour
);
3242 bool wxListCtrl::SetFont( const wxFont
&font
)
3244 if ( !wxWindow::SetFont( font
) )
3249 m_mainWin
->SetFont( font
);
3250 m_mainWin
->m_dirty
= TRUE
;
3255 m_headerWin
->SetFont( font
);