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/generic/listctrl.h"
24 #include "wx/generic/imaglist.h"
26 //-----------------------------------------------------------------------------
28 //-----------------------------------------------------------------------------
30 IMPLEMENT_DYNAMIC_CLASS(wxListItemData
,wxObject
);
32 wxListItemData::wxListItemData(void)
43 wxListItemData::wxListItemData( const wxListItem
&info
)
47 m_colour
= info
.m_colour
;
51 void wxListItemData::SetItem( const wxListItem
&info
)
53 if (info
.m_mask
& wxLIST_MASK_TEXT
) m_text
= info
.m_text
;
54 if (info
.m_mask
& wxLIST_MASK_IMAGE
) m_image
= info
.m_image
;
55 if (info
.m_mask
& wxLIST_MASK_DATA
) m_data
= info
.m_data
;
56 m_colour
= info
.m_colour
;
59 m_width
= info
.m_width
;
63 void wxListItemData::SetText( const wxString
&s
)
68 void wxListItemData::SetImage( int image
)
73 void wxListItemData::SetData( long data
)
78 void wxListItemData::SetPosition( int x
, int y
)
84 void wxListItemData::SetSize( int width
, int height
)
86 if (width
!= -1) m_width
= width
;
87 if (height
!= -1) m_height
= height
;
90 void wxListItemData::SetColour( wxColour
*col
)
95 bool wxListItemData::HasImage(void) const
97 return (m_image
>= 0);
100 bool wxListItemData::HasText(void) const
102 return (!m_text
.IsNull());
105 bool wxListItemData::IsHit( int x
, int y
) const
107 return ((x
>= m_xpos
) && (x
<= m_xpos
+m_width
) && (y
>= m_ypos
) && (y
<= m_ypos
+m_height
));
110 void wxListItemData::GetText( wxString
&s
)
115 int wxListItemData::GetX( void ) const
120 int wxListItemData::GetY( void ) const
125 int wxListItemData::GetWidth(void) const
130 int wxListItemData::GetHeight(void) const
135 int wxListItemData::GetImage(void) const
140 void wxListItemData::GetItem( wxListItem
&info
)
142 info
.m_text
= m_text
;
143 info
.m_image
= m_image
;
144 info
.m_data
= m_data
;
147 wxColour
*wxListItemData::GetColour(void)
152 //-----------------------------------------------------------------------------
154 //-----------------------------------------------------------------------------
156 IMPLEMENT_DYNAMIC_CLASS(wxListHeaderData
,wxObject
);
158 wxListHeaderData::wxListHeaderData(void)
169 wxListHeaderData::wxListHeaderData( const wxListItem
&item
)
177 void wxListHeaderData::SetItem( const wxListItem
&item
)
179 m_mask
= item
.m_mask
;
180 m_text
= item
.m_text
;
181 m_image
= item
.m_image
;
182 m_format
= item
.m_format
;
183 m_width
= item
.m_width
;
184 if (m_width
< 0) m_width
= 80;
185 if (m_width
< 6) m_width
= 6;
188 void wxListHeaderData::SetPosition( int x
, int y
)
194 void wxListHeaderData::SetHeight( int h
)
199 void wxListHeaderData::SetWidth( int w
)
202 if (m_width
< 0) m_width
= 80;
203 if (m_width
< 6) m_width
= 6;
206 void wxListHeaderData::SetFormat( int format
)
211 bool wxListHeaderData::HasImage(void) const
213 return (m_image
!= 0);
216 bool wxListHeaderData::HasText(void) const
218 return (m_text
.Length() > 0);
221 bool wxListHeaderData::IsHit( int x
, int y
) const
223 return ((x
>= m_xpos
) && (x
<= m_xpos
+m_width
) && (y
>= m_ypos
) && (y
<= m_ypos
+m_height
));
226 void wxListHeaderData::GetItem( wxListItem
&item
)
228 item
.m_mask
= m_mask
;
229 item
.m_text
= m_text
;
230 item
.m_image
= m_image
;
231 item
.m_format
= m_format
;
232 item
.m_width
= m_width
;
235 void wxListHeaderData::GetText( wxString
&s
)
240 int wxListHeaderData::GetImage(void) const
245 int wxListHeaderData::GetWidth(void) const
250 int wxListHeaderData::GetFormat(void) const
255 //-----------------------------------------------------------------------------
257 //-----------------------------------------------------------------------------
259 IMPLEMENT_DYNAMIC_CLASS(wxListLineData
,wxObject
);
261 wxListLineData::wxListLineData( wxListMainWindow
*owner
, int mode
, wxBrush
*hilightBrush
)
266 m_hilightBrush
= hilightBrush
;
267 m_items
.DeleteContents( TRUE
);
271 void wxListLineData::CalculateSize( wxDC
*dc
, int spacing
)
278 m_bound_all
.width
= m_spacing
;
279 m_bound_all
.height
= m_spacing
+13;
280 wxNode
*node
= m_items
.First();
283 wxListItemData
*item
= (wxListItemData
*)node
->Data();
287 dc
->GetTextExtent( s
, &lw
, &lh
);
288 if (lw
> m_spacing
) m_bound_all
.width
= lw
;
294 wxNode
*node
= m_items
.First();
297 wxListItemData
*item
= (wxListItemData
*)node
->Data();
301 dc
->GetTextExtent( s
, &lw
, &lh
);
302 m_bound_all
.width
= lw
;
303 m_bound_all
.height
= lh
;
309 m_bound_all
.width
= 0;
310 m_bound_all
.height
= 0;
311 wxNode
*node
= m_items
.First();
314 wxListItemData
*item
= (wxListItemData
*)node
->Data();
317 if (s
.IsNull()) s
= "H";
319 dc
->GetTextExtent( s
, &lw
, &lh
);
320 item
->SetSize( item
->GetWidth(), lh
);
321 m_bound_all
.width
+= lw
;
322 m_bound_all
.height
= lh
;
330 void wxListLineData::SetPosition( wxDC
*dc
, int x
, int y
, int window_width
)
338 AssignRect( m_bound_icon
, 0, 0, 0, 0 );
339 AssignRect( m_bound_label
, 0, 0, 0, 0 );
340 AssignRect( m_bound_hilight
, m_bound_all
);
341 wxNode
*node
= m_items
.First();
344 wxListItemData
*item
= (wxListItemData
*)node
->Data();
345 if (item
->HasImage())
347 wxListItemData
*item
= (wxListItemData
*)node
->Data();
350 m_owner
->GetImageSize( item
->GetImage(), w
, h
);
351 m_bound_icon
.x
= m_bound_all
.x
+ (m_spacing
/2) - (w
/2);
352 m_bound_icon
.y
= m_bound_all
.y
+ m_spacing
- h
- 5;
353 m_bound_icon
.width
= w
;
354 m_bound_icon
.height
= h
;
355 if (!item
->HasText())
357 AssignRect( m_bound_hilight
, m_bound_icon
);
358 m_bound_hilight
.x
-= 5;
359 m_bound_hilight
.y
-= 5;
360 m_bound_hilight
.width
+= 9;
361 m_bound_hilight
.height
+= 9;
369 dc
->GetTextExtent( s
, &lw
, &lh
);
370 if (m_bound_all
.width
> m_spacing
)
371 m_bound_label
.x
= m_bound_all
.x
;
373 m_bound_label
.x
= m_bound_all
.x
+ (m_spacing
/2) - lw
/2;
374 m_bound_label
.y
= m_bound_all
.y
+ m_bound_all
.height
- lh
;
375 m_bound_label
.width
= lw
;
376 m_bound_label
.height
= lh
;
377 AssignRect( m_bound_hilight
, m_bound_label
);
378 m_bound_hilight
.x
-= 2;
379 m_bound_hilight
.y
-= 2;
380 m_bound_hilight
.width
+= 4;
381 m_bound_hilight
.height
+= 4;
388 AssignRect( m_bound_label
, m_bound_all
);
391 m_bound_all
.width
+= 4;
392 m_bound_all
.height
+= 3;
393 AssignRect( m_bound_hilight
, m_bound_all
);
394 AssignRect( m_bound_icon
, 0, 0, 0, 0 );
400 dc
->GetTextExtent( "H", &lw
, &lh
);
403 m_bound_all
.height
= lh
+3;
404 m_bound_all
.width
= window_width
;
405 AssignRect( m_bound_hilight
, m_bound_all
);
406 AssignRect( m_bound_label
, 0, 0, 0 ,0 );
407 AssignRect( m_bound_icon
, 0, 0, 0, 0 );
413 void wxListLineData::SetColumnPosition( int index
, int x
)
416 wxNode
*node
= m_items
.Nth( i
);
419 wxListItemData
*item
= (wxListItemData
*)node
->Data();
420 item
->SetPosition( x
, m_bound_all
.y
+1 );
424 void wxListLineData::GetSize( int &width
, int &height
)
426 width
= m_bound_all
.width
;
427 height
= m_bound_all
.height
;
430 void wxListLineData::GetExtent( int &x
, int &y
, int &width
, int &height
)
434 width
= m_bound_all
.width
;
435 height
= m_bound_all
.height
;
438 void wxListLineData::GetLabelExtent( int &x
, int &y
, int &width
, int &height
)
442 width
= m_bound_label
.width
;
443 height
= m_bound_label
.height
;
446 void wxListLineData::GetRect( wxRect
&rect
)
448 AssignRect( rect
, m_bound_all
);
451 long wxListLineData::IsHit( int x
, int y
)
453 wxNode
*node
= m_items
.First();
456 wxListItemData
*item
= (wxListItemData
*)node
->Data();
457 if (item
->HasImage() && IsInRect( x
, y
, m_bound_icon
)) return wxLIST_HITTEST_ONITEMICON
;
458 if (item
->HasText() && IsInRect( x
, y
, m_bound_label
)) return wxLIST_HITTEST_ONITEMLABEL
;
459 // if (!(item->HasImage() || item->HasText())) return 0;
461 // if there is no icon or text = empty
462 if (IsInRect( x
, y
, m_bound_all
)) return wxLIST_HITTEST_ONITEMICON
;
466 void wxListLineData::InitItems( int num
)
468 for (int i
= 0; i
< num
; i
++) m_items
.Append( new wxListItemData() );
471 void wxListLineData::SetItem( int index
, const wxListItem
&info
)
473 wxNode
*node
= m_items
.Nth( index
);
476 wxListItemData
*item
= (wxListItemData
*)node
->Data();
477 item
->SetItem( info
);
481 void wxListLineData::GetItem( int index
, wxListItem
&info
)
484 wxNode
*node
= m_items
.Nth( i
);
487 wxListItemData
*item
= (wxListItemData
*)node
->Data();
488 item
->GetItem( info
);
492 void wxListLineData::GetText( int index
, wxString
&s
)
495 wxNode
*node
= m_items
.Nth( i
);
499 wxListItemData
*item
= (wxListItemData
*)node
->Data();
504 void wxListLineData::SetText( int index
, const wxString s
)
507 wxNode
*node
= m_items
.Nth( i
);
510 wxListItemData
*item
= (wxListItemData
*)node
->Data();
515 int wxListLineData::GetImage( int index
)
518 wxNode
*node
= m_items
.Nth( i
);
521 wxListItemData
*item
= (wxListItemData
*)node
->Data();
522 return item
->GetImage();
527 void wxListLineData::DoDraw( wxDC
*dc
, bool hilight
, bool paintBG
)
529 long dev_x
= dc
->LogicalToDeviceX( m_bound_all
.x
-2 );
530 long dev_y
= dc
->LogicalToDeviceY( m_bound_all
.y
-2 );
531 long dev_w
= dc
->LogicalToDeviceXRel( m_bound_all
.width
+4 );
532 long dev_h
= dc
->LogicalToDeviceYRel( m_bound_all
.height
+4 );
534 if (!m_owner
->IsExposed( dev_x
, dev_y
, dev_w
, dev_h
))
543 dc
->SetBrush( * m_hilightBrush
);
544 dc
->SetPen( * wxTRANSPARENT_PEN
);
548 dc
->SetBrush( * wxWHITE_BRUSH
);
549 dc
->SetPen( * wxTRANSPARENT_PEN
);
551 dc
->DrawRectangle( m_bound_hilight
.x
, m_bound_hilight
.y
,
552 m_bound_hilight
.width
, m_bound_hilight
.height
);
555 dc
->SetBackgroundMode(wxTRANSPARENT
);
556 if (m_mode
== wxLC_REPORT
)
559 wxNode
*node
= m_items
.First();
562 wxListItemData
*item
= (wxListItemData
*)node
->Data();
563 dc
->SetClippingRegion( item
->GetX(), item
->GetY(), item
->GetWidth()-3, item
->GetHeight() );
564 int x
= item
->GetX();
565 if (item
->HasImage())
568 m_owner
->DrawImage( item
->GetImage(), dc
, x
, item
->GetY() );
569 m_owner
->GetImageSize( item
->GetImage(), x
, y
);
570 x
+= item
->GetX() + 5;
576 dc
->SetTextForeground( wxSystemSettings::GetSystemColour( wxSYS_COLOUR_HIGHLIGHTTEXT
) );
578 dc
->SetTextForeground( *item
->GetColour() );
579 dc
->DrawText( s
, x
, item
->GetY() );
581 dc
->DestroyClippingRegion();
587 wxNode
*node
= m_items
.First();
590 wxListItemData
*item
= (wxListItemData
*)node
->Data();
591 if (item
->HasImage())
593 m_owner
->DrawImage( item
->GetImage(), dc
, m_bound_icon
.x
, m_bound_icon
.y
);
600 dc
->SetTextForeground( wxSystemSettings::GetSystemColour( wxSYS_COLOUR_HIGHLIGHTTEXT
) );
602 dc
->SetTextForeground( * item
->GetColour() );
603 dc
->DrawText( s
, m_bound_label
.x
, m_bound_label
.y
);
609 void wxListLineData::Hilight( bool on
)
611 if (on
== m_hilighted
) return;
613 m_owner
->SelectLine( this );
615 m_owner
->DeselectLine( this );
619 void wxListLineData::ReverseHilight( void )
621 m_hilighted
= !m_hilighted
;
623 m_owner
->SelectLine( this );
625 m_owner
->DeselectLine( this );
628 void wxListLineData::DrawRubberBand( wxDC
*dc
, bool on
)
632 dc
->SetPen( * wxBLACK_PEN
);
633 dc
->SetBrush( * wxTRANSPARENT_BRUSH
);
634 dc
->DrawRectangle( m_bound_hilight
.x
, m_bound_hilight
.y
,
635 m_bound_hilight
.width
, m_bound_hilight
.height
);
639 void wxListLineData::Draw( wxDC
*dc
)
641 DoDraw( dc
, m_hilighted
, m_hilighted
);
644 bool wxListLineData::IsInRect( int x
, int y
, const wxRect
&rect
)
646 return ((x
>= rect
.x
) && (x
<= rect
.x
+rect
.width
) &&
647 (y
>= rect
.y
) && (y
<= rect
.y
+rect
.height
));
650 bool wxListLineData::IsHilighted( void )
655 void wxListLineData::AssignRect( wxRect
&dest
, int x
, int y
, int width
, int height
)
660 dest
.height
= height
;
663 void wxListLineData::AssignRect( wxRect
&dest
, const wxRect
&source
)
667 dest
.width
= source
.width
;
668 dest
.height
= source
.height
;
671 //-----------------------------------------------------------------------------
672 // wxListHeaderWindow
673 //-----------------------------------------------------------------------------
675 IMPLEMENT_DYNAMIC_CLASS(wxListHeaderWindow
,wxWindow
);
677 BEGIN_EVENT_TABLE(wxListHeaderWindow
,wxWindow
)
678 EVT_PAINT (wxListHeaderWindow::OnPaint
)
679 EVT_MOUSE_EVENTS (wxListHeaderWindow::OnMouse
)
680 EVT_SET_FOCUS (wxListHeaderWindow::OnSetFocus
)
683 wxListHeaderWindow::wxListHeaderWindow( void )
685 m_owner
= (wxListMainWindow
*) NULL
;
686 m_currentCursor
= (wxCursor
*) NULL
;
687 m_resizeCursor
= (wxCursor
*) NULL
;
688 m_isDragging
= FALSE
;
691 wxListHeaderWindow::wxListHeaderWindow( wxWindow
*win
, wxWindowID id
, wxListMainWindow
*owner
,
692 const wxPoint
&pos
, const wxSize
&size
,
693 long style
, const wxString
&name
) :
694 wxWindow( win
, id
, pos
, size
, style
, name
)
697 // m_currentCursor = wxSTANDARD_CURSOR;
698 m_currentCursor
= (wxCursor
*) NULL
;
699 m_resizeCursor
= new wxCursor( wxCURSOR_SIZEWE
);
700 m_isDragging
= FALSE
;
701 SetBackgroundColour( wxSystemSettings::GetSystemColour( wxSYS_COLOUR_BTNFACE
) );
704 wxListHeaderWindow::~wxListHeaderWindow( void )
706 delete m_resizeCursor
;
709 void wxListHeaderWindow::DoDrawRect( wxDC
*dc
, int x
, int y
, int w
, int h
)
711 const int m_corner
= 1;
713 dc
->SetBrush( *wxTRANSPARENT_BRUSH
);
715 dc
->SetPen( *wxBLACK_PEN
);
716 dc
->DrawLine( x
+w
-m_corner
+1, y
, x
+w
, y
+h
); // right (outer)
717 dc
->DrawRectangle( x
, y
+h
, w
+1, 1 ); // bottom (outer)
719 wxPen
pen( wxSystemSettings::GetSystemColour( wxSYS_COLOUR_BTNSHADOW
), 1, wxSOLID
);
722 dc
->DrawLine( x
+w
-m_corner
, y
, x
+w
-1, y
+h
); // right (inner)
723 dc
->DrawRectangle( x
+1, y
+h
-1, w
-2, 1 ); // bottom (inner)
725 dc
->SetPen( *wxWHITE_PEN
);
726 dc
->DrawRectangle( x
, y
, w
-m_corner
+1, 1 ); // top (outer)
727 dc
->DrawRectangle( x
, y
, 1, h
); // left (outer)
728 dc
->DrawLine( x
, y
+h
-1, x
+1, y
+h
-1 );
729 dc
->DrawLine( x
+w
-1, y
, x
+w
-1, y
+1 );
732 void wxListHeaderWindow::OnPaint( wxPaintEvent
&WXUNUSED(event
) )
734 wxPaintDC
dc( this );
739 dc
.SetFont( GetFont() );
745 GetClientSize( &w
, &h
);
747 dc
.SetBackgroundMode(wxTRANSPARENT
);
748 dc
.SetTextForeground( *wxBLACK
);
749 if (m_foregroundColour
.Ok()) dc
.SetTextForeground( m_foregroundColour
);
753 int numColumns
= m_owner
->GetColumnCount();
755 for (int i
= 0; i
< numColumns
; i
++)
757 m_owner
->GetColumn( i
, item
);
758 int cw
= item
.m_width
-2;
759 if ((i
+1 == numColumns
) || (x
+item
.m_width
> w
-5)) cw
= w
-x
-1;
760 dc
.SetPen( *wxWHITE_PEN
);
762 DoDrawRect( &dc
, x
, y
, cw
, h
-2 );
763 dc
.SetClippingRegion( x
, y
, cw
-5, h
-4 );
764 dc
.DrawText( item
.m_text
, x
+4, y
+3 );
765 dc
.DestroyClippingRegion();
772 void wxListHeaderWindow::DrawCurrent()
776 int x2
= m_currentX
-1;
779 m_owner
->GetClientSize( &dummy
, &y2
);
780 ClientToScreen( &x1
, &y1
);
781 m_owner
->ClientToScreen( &x2
, &y2
);
784 dc
.SetLogicalFunction( wxINVERT
);
785 dc
.SetPen( wxPen( *wxBLACK
, 2, wxSOLID
) );
786 dc
.SetBrush( *wxTRANSPARENT_BRUSH
);
788 dc
.DrawLine( x1
, y1
, x2
, y2
);
790 dc
.SetLogicalFunction( wxCOPY
);
792 dc
.SetPen( wxNullPen
);
793 dc
.SetBrush( wxNullBrush
);
796 void wxListHeaderWindow::OnMouse( wxMouseEvent
&event
)
798 int x
= event
.GetX();
799 int y
= event
.GetY();
803 if (event
.ButtonUp())
806 m_isDragging
= FALSE
;
807 m_owner
->SetColumnWidth( m_column
, m_currentX
-m_minX
);
813 GetClientSize( &size_x
, & dummy
);
817 m_currentX
= m_minX
+7;
818 if (m_currentX
> size_x
-7) m_currentX
= size_x
-7;
825 bool hit_border
= FALSE
;
827 for (int j
= 0; j
< m_owner
->GetColumnCount(); j
++)
829 xpos
+= m_owner
->GetColumnWidth( j
);
830 if ((abs(x
-xpos
) < 3) && (y
< 22))
839 if (event
.LeftDown() && hit_border
)
852 if (m_currentCursor
== wxSTANDARD_CURSOR
) SetCursor( * m_resizeCursor
);
853 m_currentCursor
= m_resizeCursor
;
857 if (m_currentCursor
!= wxSTANDARD_CURSOR
) SetCursor( * wxSTANDARD_CURSOR
);
858 m_currentCursor
= wxSTANDARD_CURSOR
;
863 void wxListHeaderWindow::OnSetFocus( wxFocusEvent
&WXUNUSED(event
) )
868 //-----------------------------------------------------------------------------
869 // wxListRenameTimer (internal)
870 //-----------------------------------------------------------------------------
872 wxListRenameTimer::wxListRenameTimer( wxListMainWindow
*owner
)
877 void wxListRenameTimer::Notify()
879 m_owner
->OnRenameTimer();
882 //-----------------------------------------------------------------------------
883 // wxListTextCtrl (internal)
884 //-----------------------------------------------------------------------------
886 IMPLEMENT_DYNAMIC_CLASS(wxListTextCtrl
,wxTextCtrl
);
888 BEGIN_EVENT_TABLE(wxListTextCtrl
,wxTextCtrl
)
889 EVT_CHAR (wxListTextCtrl::OnChar
)
890 EVT_KILL_FOCUS (wxListTextCtrl::OnKillFocus
)
893 wxListTextCtrl::wxListTextCtrl( wxWindow
*parent
, const wxWindowID id
,
894 bool *accept
, wxString
*res
, wxListMainWindow
*owner
,
895 const wxString
&value
, const wxPoint
&pos
, const wxSize
&size
,
896 int style
, const wxValidator
& validator
, const wxString
&name
) :
897 wxTextCtrl( parent
, id
, value
, pos
, size
, style
, validator
, name
)
904 void wxListTextCtrl::OnChar( wxKeyEvent
&event
)
906 if (event
.m_keyCode
== WXK_RETURN
)
909 (*m_res
) = GetValue();
910 m_owner
->OnRenameAccept();
915 if (event
.m_keyCode
== WXK_ESCAPE
)
926 void wxListTextCtrl::OnKillFocus( wxFocusEvent
&WXUNUSED(event
) )
935 //-----------------------------------------------------------------------------
937 //-----------------------------------------------------------------------------
939 IMPLEMENT_DYNAMIC_CLASS(wxListMainWindow
,wxScrolledWindow
);
941 BEGIN_EVENT_TABLE(wxListMainWindow
,wxScrolledWindow
)
942 EVT_PAINT (wxListMainWindow::OnPaint
)
943 EVT_SIZE (wxListMainWindow::OnSize
)
944 EVT_MOUSE_EVENTS (wxListMainWindow::OnMouse
)
945 EVT_CHAR (wxListMainWindow::OnChar
)
946 EVT_KEY_DOWN (wxListMainWindow::OnKeyDown
)
947 EVT_SET_FOCUS (wxListMainWindow::OnSetFocus
)
948 EVT_KILL_FOCUS (wxListMainWindow::OnKillFocus
)
951 wxListMainWindow::wxListMainWindow( void )
954 m_lines
.DeleteContents( TRUE
);
955 m_columns
.DeleteContents( TRUE
);
956 m_current
= (wxListLineData
*) NULL
;
958 m_hilightBrush
= (wxBrush
*) NULL
;
962 m_small_image_list
= (wxImageList
*) NULL
;
963 m_normal_image_list
= (wxImageList
*) NULL
;
964 m_small_spacing
= 30;
965 m_normal_spacing
= 40;
968 m_lastOnSame
= FALSE
;
969 m_renameTimer
= new wxListRenameTimer( this );
974 wxListMainWindow::wxListMainWindow( wxWindow
*parent
, wxWindowID id
,
975 const wxPoint
&pos
, const wxSize
&size
,
976 long style
, const wxString
&name
) :
977 wxScrolledWindow( parent
, id
, pos
, size
, style
|wxHSCROLL
|wxVSCROLL
, name
)
980 m_lines
.DeleteContents( TRUE
);
981 m_columns
.DeleteContents( TRUE
);
982 m_current
= (wxListLineData
*) NULL
;
985 m_hilightBrush
= new wxBrush( wxSystemSettings::GetSystemColour(wxSYS_COLOUR_HIGHLIGHT
), wxSOLID
);
986 m_small_image_list
= (wxImageList
*) NULL
;
987 m_normal_image_list
= (wxImageList
*) NULL
;
988 m_small_spacing
= 30;
989 m_normal_spacing
= 40;
996 if (m_mode
& wxLC_REPORT
)
1006 SetScrollbars( m_xScroll
, m_yScroll
, 0, 0, 0, 0 );
1009 m_lastOnSame
= FALSE
;
1010 m_renameTimer
= new wxListRenameTimer( this );
1011 m_renameAccept
= FALSE
;
1013 SetBackgroundColour( *wxWHITE
);
1016 wxListMainWindow::~wxListMainWindow( void )
1018 if (m_hilightBrush
) delete m_hilightBrush
;
1020 delete m_renameTimer
;
1023 void wxListMainWindow::RefreshLine( wxListLineData
*line
)
1031 wxClientDC
dc(this);
1033 line
->GetExtent( x
, y
, w
, h
);
1035 dc
.LogicalToDeviceX(x
-3),
1036 dc
.LogicalToDeviceY(y
-3),
1037 dc
.LogicalToDeviceXRel(w
+6),
1038 dc
.LogicalToDeviceXRel(h
+6) );
1039 Refresh( TRUE
, &rect
);
1043 void wxListMainWindow::OnPaint( wxPaintEvent
&WXUNUSED(event
) )
1045 // Note: a wxPaintDC must be constructed even if no drawing is
1046 // done (a Windows requirement).
1047 wxPaintDC
dc( this );
1050 if (m_dirty
) return;
1052 if (m_lines
.GetCount() == 0) return;
1056 dc
.SetFont( GetFont() );
1058 if (m_mode
& wxLC_REPORT
)
1060 int lineSpacing
= 0;
1061 wxListLineData
*line
= (wxListLineData
*)m_lines
.First()->Data();
1063 line
->GetSize( dummy
, lineSpacing
);
1066 int y_s
= m_yScroll
*GetScrollPos( wxVERTICAL
);
1068 wxNode
*node
= m_lines
.Nth( y_s
/ lineSpacing
);
1069 for (int i
= 0; i
< m_visibleLines
+2; i
++)
1073 line
= (wxListLineData
*)node
->Data();
1075 node
= node
->Next();
1080 wxNode
*node
= m_lines
.First();
1083 wxListLineData
*line
= (wxListLineData
*)node
->Data();
1085 node
= node
->Next();
1089 if (m_current
) m_current
->DrawRubberBand( &dc
, m_hasFocus
);
1094 void wxListMainWindow::HilightAll( bool on
)
1096 wxNode
*node
= m_lines
.First();
1099 wxListLineData
*line
= (wxListLineData
*)node
->Data();
1100 if (line
->IsHilighted() != on
)
1102 line
->Hilight( on
);
1103 RefreshLine( line
);
1105 node
= node
->Next();
1109 void wxListMainWindow::SendNotify( wxListLineData
*line
, wxEventType command
)
1111 wxListEvent
le( command
, GetParent()->GetId() );
1112 le
.SetEventObject( GetParent() );
1113 le
.m_itemIndex
= GetIndexOfLine( line
);
1114 line
->GetItem( 0, le
.m_item
);
1115 GetParent()->GetEventHandler()->ProcessEvent( le
);
1118 void wxListMainWindow::FocusLine( wxListLineData
*WXUNUSED(line
) )
1120 // SendNotify( line, wxEVT_COMMAND_LIST_ITEM_FOCUSSED );
1123 void wxListMainWindow::UnfocusLine( wxListLineData
*WXUNUSED(line
) )
1125 // SendNotify( line, wxEVT_COMMAND_LIST_ITEM_UNFOCUSSED );
1128 void wxListMainWindow::SelectLine( wxListLineData
*line
)
1130 SendNotify( line
, wxEVT_COMMAND_LIST_ITEM_SELECTED
);
1133 void wxListMainWindow::DeselectLine( wxListLineData
*line
)
1135 SendNotify( line
, wxEVT_COMMAND_LIST_ITEM_DESELECTED
);
1138 void wxListMainWindow::DeleteLine( wxListLineData
*line
)
1140 SendNotify( line
, wxEVT_COMMAND_LIST_DELETE_ITEM
);
1143 void wxListMainWindow::StartLabelEdit( wxListLineData
*line
)
1145 SendNotify( line
, wxEVT_COMMAND_LIST_BEGIN_LABEL_EDIT
);
1148 void wxListMainWindow::RenameLine( wxListLineData
*line
, const wxString
&newName
)
1150 wxListEvent
le( wxEVT_COMMAND_LIST_END_LABEL_EDIT
, GetParent()->GetId() );
1151 le
.SetEventObject( GetParent() );
1152 le
.m_itemIndex
= GetIndexOfLine( line
);
1153 line
->GetItem( 0, le
.m_item
);
1154 le
.m_item
.m_text
= newName
;
1155 GetParent()->GetEventHandler()->ProcessEvent( le
);
1158 void wxListMainWindow::OnRenameTimer()
1160 StartLabelEdit( m_current
);
1162 m_current
->GetText( 0, s
);
1167 m_current
->GetLabelExtent( x
, y
, w
, h
);
1169 wxClientDC
dc(this);
1171 x
= dc
.LogicalToDeviceX( x
);
1172 y
= dc
.LogicalToDeviceY( y
);
1174 wxListTextCtrl
*text
= new wxListTextCtrl(
1175 this, -1, &m_renameAccept
, &m_renameRes
, this, s
, wxPoint(x
-4,y
-4), wxSize(w
+11,h
+8) );
1179 void wxListMainWindow::OnRenameAccept()
1181 RenameLine( m_current
, m_renameRes
);
1184 void wxListMainWindow::OnMouse( wxMouseEvent
&event
)
1186 if (GetParent()->GetEventHandler()->ProcessEvent( event
)) return;
1188 if (!m_current
) return;
1189 if (m_dirty
) return;
1191 wxClientDC
dc(this);
1193 long x
= dc
.DeviceToLogicalX( (long)event
.GetX() );
1194 long y
= dc
.DeviceToLogicalY( (long)event
.GetY() );
1196 /* Did we actually hit an item ? */
1198 wxNode
*node
= m_lines
.First();
1199 wxListLineData
*line
= (wxListLineData
*) NULL
;
1202 line
= (wxListLineData
*)node
->Data();
1203 hitResult
= line
->IsHit( x
, y
);
1204 if (hitResult
) break;
1205 line
= (wxListLineData
*) NULL
;
1206 node
= node
->Next();
1209 if (!event
.Dragging())
1214 if (event
.Dragging() && (m_dragCount
> 3))
1218 wxListEvent
le( wxEVT_COMMAND_LIST_BEGIN_DRAG
, GetParent()->GetId() );
1219 le
.SetEventObject( GetParent() );
1220 le
.m_pointDrag
.x
= x
;
1221 le
.m_pointDrag
.y
= y
;
1222 GetParent()->GetEventHandler()->ProcessEvent( le
);
1229 if (event
.ButtonDClick())
1232 m_lastOnSame
= FALSE
;
1233 m_renameTimer
->Stop();
1235 SendNotify( line
, wxEVT_COMMAND_LIST_ITEM_ACTIVATED
);
1240 if (event
.LeftUp() && m_lastOnSame
)
1243 if ((line
== m_current
) &&
1244 (hitResult
== wxLIST_HITTEST_ONITEMLABEL
) &&
1245 (m_mode
& wxLC_EDIT_LABELS
) )
1247 m_renameTimer
->Start( 100, TRUE
);
1249 m_lastOnSame
= FALSE
;
1253 if (event
.RightDown())
1255 SendNotify( line
, wxEVT_COMMAND_LIST_ITEM_RIGHT_CLICK
);
1259 if (event
.MiddleDown())
1261 SendNotify( line
, wxEVT_COMMAND_LIST_ITEM_MIDDLE_CLICK
);
1265 if (event
.LeftDown())
1268 wxListLineData
*oldCurrent
= m_current
;
1269 if (m_mode
& wxLC_SINGLE_SEL
)
1272 HilightAll( FALSE
);
1273 m_current
->ReverseHilight();
1274 RefreshLine( m_current
);
1278 if (event
.ShiftDown())
1281 m_current
->ReverseHilight();
1282 RefreshLine( m_current
);
1284 else if (event
.ControlDown())
1288 int numOfCurrent
= -1;
1289 node
= m_lines
.First();
1292 wxListLineData
*test_line
= (wxListLineData
*)node
->Data();
1294 if (test_line
== oldCurrent
) break;
1295 node
= node
->Next();
1299 node
= m_lines
.First();
1302 wxListLineData
*test_line
= (wxListLineData
*)node
->Data();
1304 if (test_line
== line
) break;
1305 node
= node
->Next();
1308 if (numOfLine
< numOfCurrent
)
1311 numOfLine
= numOfCurrent
;
1315 wxNode
*node
= m_lines
.Nth( numOfCurrent
);
1316 for (int i
= 0; i
<= numOfLine
-numOfCurrent
; i
++)
1318 wxListLineData
*test_line
= (wxListLineData
*)node
->Data();
1319 test_line
->Hilight(TRUE
);
1320 RefreshLine( test_line
);
1321 node
= node
->Next();
1327 HilightAll( FALSE
);
1328 m_current
->ReverseHilight();
1329 RefreshLine( m_current
);
1332 if (m_current
!= oldCurrent
)
1334 RefreshLine( oldCurrent
);
1335 UnfocusLine( oldCurrent
);
1336 FocusLine( m_current
);
1338 m_lastOnSame
= (m_current
== oldCurrent
);
1343 void wxListMainWindow::MoveToFocus( void )
1345 if (!m_current
) return;
1351 m_current
->GetExtent( x
, y
, w
, h
);
1355 GetClientSize( &w_p
, &h_p
);
1357 if (m_mode
& wxLC_REPORT
)
1359 int y_s
= m_yScroll
*GetScrollPos( wxVERTICAL
);
1360 if ((y
> y_s
) && (y
+h
< y_s
+h_p
)) return;
1361 if (y
-y_s
< 5) { Scroll( -1, (y
-5-h_p
/2)/m_yScroll
); Refresh(); }
1362 if (y
+h
+5 > y_s
+h_p
) { Scroll( -1, (y
+h
-h_p
/2+h
+15)/m_yScroll
); Refresh(); }
1366 int x_s
= m_xScroll
*GetScrollPos( wxHORIZONTAL
);
1367 if ((x
> x_s
) && (x
+w
< x_s
+w_p
)) return;
1368 if (x
-x_s
< 5) { Scroll( (x
-5)/m_xScroll
, -1 ); Refresh(); }
1369 if (x
+w
-5 > x_s
+w_p
) { Scroll( (x
+w
-w_p
+15)/m_xScroll
, -1 ); Refresh(); }
1373 void wxListMainWindow::OnArrowChar( wxListLineData
*newCurrent
, bool shiftDown
)
1375 if ((m_mode
& wxLC_SINGLE_SEL
) || (m_usedKeys
== FALSE
)) m_current
->Hilight( FALSE
);
1376 wxListLineData
*oldCurrent
= m_current
;
1377 m_current
= newCurrent
;
1379 if (shiftDown
|| (m_mode
& wxLC_SINGLE_SEL
)) m_current
->Hilight( TRUE
);
1380 RefreshLine( m_current
);
1381 RefreshLine( oldCurrent
);
1382 FocusLine( m_current
);
1383 UnfocusLine( oldCurrent
);
1386 void wxListMainWindow::OnKeyDown( wxKeyEvent
&event
)
1388 wxWindow
*parent
= GetParent();
1390 /* we propagate the key event up */
1391 wxKeyEvent
ke( wxEVT_KEY_DOWN
);
1392 ke
.m_shiftDown
= event
.m_shiftDown
;
1393 ke
.m_controlDown
= event
.m_controlDown
;
1394 ke
.m_altDown
= event
.m_altDown
;
1395 ke
.m_metaDown
= event
.m_metaDown
;
1396 ke
.m_keyCode
= event
.m_keyCode
;
1399 ke
.SetEventObject( parent
);
1400 if (parent
->GetEventHandler()->ProcessEvent( ke
)) return;
1405 void wxListMainWindow::OnChar( wxKeyEvent
&event
)
1407 wxWindow
*parent
= GetParent();
1409 /* we send a list_key event up */
1410 wxListEvent
le( wxEVT_COMMAND_LIST_KEY_DOWN
, GetParent()->GetId() );
1411 le
.m_code
= event
.KeyCode();
1412 le
.SetEventObject( parent
);
1413 parent
->GetEventHandler()->ProcessEvent( le
);
1415 /* we propagate the char event up */
1416 wxKeyEvent
ke( wxEVT_CHAR
);
1417 ke
.m_shiftDown
= event
.m_shiftDown
;
1418 ke
.m_controlDown
= event
.m_controlDown
;
1419 ke
.m_altDown
= event
.m_altDown
;
1420 ke
.m_metaDown
= event
.m_metaDown
;
1421 ke
.m_keyCode
= event
.m_keyCode
;
1424 ke
.SetEventObject( parent
);
1425 if (parent
->GetEventHandler()->ProcessEvent( ke
)) return;
1427 if (event
.KeyCode() == WXK_TAB
)
1429 wxNavigationKeyEvent nevent
;
1430 nevent
.SetDirection( !event
.ShiftDown() );
1431 nevent
.SetCurrentFocus( m_parent
);
1432 if (m_parent
->GetEventHandler()->ProcessEvent( nevent
)) return;
1435 /* no item -> nothing to do */
1442 switch (event
.KeyCode())
1446 wxNode
*node
= m_lines
.Member( m_current
)->Previous();
1447 if (node
) OnArrowChar( (wxListLineData
*)node
->Data(), event
.ShiftDown() );
1452 wxNode
*node
= m_lines
.Member( m_current
)->Next();
1453 if (node
) OnArrowChar( (wxListLineData
*)node
->Data(), event
.ShiftDown() );
1458 wxNode
*node
= m_lines
.Last();
1459 OnArrowChar( (wxListLineData
*)node
->Data(), event
.ShiftDown() );
1464 wxNode
*node
= m_lines
.First();
1465 OnArrowChar( (wxListLineData
*)node
->Data(), event
.ShiftDown() );
1471 if (m_mode
& wxLC_REPORT
)
1473 steps
= m_visibleLines
-1;
1478 wxNode
*node
= m_lines
.First();
1479 for (;;) { if (m_current
== (wxListLineData
*)node
->Data()) break; pos
++; node
= node
->Next(); }
1480 steps
= pos
% m_visibleLines
;
1482 wxNode
*node
= m_lines
.Member( m_current
);
1483 for (int i
= 0; i
< steps
; i
++) if (node
->Previous()) node
= node
->Previous();
1484 if (node
) OnArrowChar( (wxListLineData
*)node
->Data(), event
.ShiftDown() );
1490 if (m_mode
& wxLC_REPORT
)
1492 steps
= m_visibleLines
-1;
1496 int pos
= 0; wxNode
*node
= m_lines
.First();
1497 for (;;) { if (m_current
== (wxListLineData
*)node
->Data()) break; pos
++; node
= node
->Next(); }
1498 steps
= m_visibleLines
-(pos
% m_visibleLines
)-1;
1500 wxNode
*node
= m_lines
.Member( m_current
);
1501 for (int i
= 0; i
< steps
; i
++) if (node
->Next()) node
= node
->Next();
1502 if (node
) OnArrowChar( (wxListLineData
*)node
->Data(), event
.ShiftDown() );
1507 if (!(m_mode
& wxLC_REPORT
))
1509 wxNode
*node
= m_lines
.Member( m_current
);
1510 for (int i
= 0; i
<m_visibleLines
; i
++) if (node
->Previous()) node
= node
->Previous();
1511 if (node
) OnArrowChar( (wxListLineData
*)node
->Data(), event
.ShiftDown() );
1517 if (!(m_mode
& wxLC_REPORT
))
1519 wxNode
*node
= m_lines
.Member( m_current
);
1520 for (int i
= 0; i
<m_visibleLines
; i
++) if (node
->Next()) node
= node
->Next();
1521 if (node
) OnArrowChar( (wxListLineData
*)node
->Data(), event
.ShiftDown() );
1527 m_current
->ReverseHilight();
1528 RefreshLine( m_current
);
1533 if (!(m_mode
& wxLC_SINGLE_SEL
))
1535 wxListLineData
*oldCurrent
= m_current
;
1536 m_current
->ReverseHilight();
1537 wxNode
*node
= m_lines
.Member( m_current
)->Next();
1538 if (node
) m_current
= (wxListLineData
*)node
->Data();
1540 RefreshLine( oldCurrent
);
1541 RefreshLine( m_current
);
1542 UnfocusLine( oldCurrent
);
1543 FocusLine( m_current
);
1550 wxListEvent
le( wxEVT_COMMAND_LIST_ITEM_ACTIVATED
, GetParent()->GetId() );
1551 le
.SetEventObject( GetParent() );
1552 le
.m_itemIndex
= GetIndexOfLine( m_current
);
1553 m_current
->GetItem( 0, le
.m_item
);
1554 GetParent()->GetEventHandler()->ProcessEvent( le
);
1566 void wxListMainWindow::OnSetFocus( wxFocusEvent
&WXUNUSED(event
) )
1569 RefreshLine( m_current
);
1571 if (!GetParent()) return;
1573 wxFocusEvent
event( wxEVT_SET_FOCUS
, GetParent()->GetId() );
1574 event
.SetEventObject( GetParent() );
1575 GetParent()->GetEventHandler()->ProcessEvent( event
);
1578 void wxListMainWindow::OnKillFocus( wxFocusEvent
&WXUNUSED(event
) )
1581 RefreshLine( m_current
);
1584 void wxListMainWindow::OnSize( wxSizeEvent
&WXUNUSED(event
) )
1587 We don't even allow the wxScrolledWindow::AdjustScrollbars() call
1592 void wxListMainWindow::DrawImage( int index
, wxDC
*dc
, int x
, int y
)
1594 if ((m_mode
& wxLC_ICON
) && (m_normal_image_list
))
1596 m_normal_image_list
->Draw( index
, *dc
, x
, y
, wxIMAGELIST_DRAW_TRANSPARENT
);
1599 if ((m_mode
& wxLC_SMALL_ICON
) && (m_small_image_list
))
1601 m_small_image_list
->Draw( index
, *dc
, x
, y
, wxIMAGELIST_DRAW_TRANSPARENT
);
1603 if ((m_mode
& wxLC_REPORT
) && (m_small_image_list
))
1605 m_small_image_list
->Draw( index
, *dc
, x
, y
, wxIMAGELIST_DRAW_TRANSPARENT
);
1610 void wxListMainWindow::GetImageSize( int index
, int &width
, int &height
)
1612 if ((m_mode
& wxLC_ICON
) && (m_normal_image_list
))
1614 m_normal_image_list
->GetSize( index
, width
, height
);
1617 if ((m_mode
& wxLC_SMALL_ICON
) && (m_small_image_list
))
1619 m_small_image_list
->GetSize( index
, width
, height
);
1622 if ((m_mode
& wxLC_REPORT
) && (m_small_image_list
))
1624 m_small_image_list
->GetSize( index
, width
, height
);
1631 int wxListMainWindow::GetTextLength( wxString
&s
)
1633 wxClientDC
dc( this );
1636 dc
.GetTextExtent( s
, &lw
, &lh
);
1640 int wxListMainWindow::GetIndexOfLine( const wxListLineData
*line
)
1643 wxNode
*node
= m_lines
.First();
1646 if (line
== (wxListLineData
*)node
->Data()) return i
;
1648 node
= node
->Next();
1653 void wxListMainWindow::SetImageList( wxImageList
*imageList
, int which
)
1656 if (which
== wxIMAGE_LIST_NORMAL
) m_normal_image_list
= imageList
;
1657 if (which
== wxIMAGE_LIST_SMALL
) m_small_image_list
= imageList
;
1660 void wxListMainWindow::SetItemSpacing( int spacing
, bool isSmall
)
1665 m_small_spacing
= spacing
;
1669 m_normal_spacing
= spacing
;
1673 int wxListMainWindow::GetItemSpacing( bool isSmall
)
1675 if (isSmall
) return m_small_spacing
; else return m_normal_spacing
;
1678 void wxListMainWindow::SetColumn( int col
, wxListItem
&item
)
1681 wxNode
*node
= m_columns
.Nth( col
);
1684 if (item
.m_width
== wxLIST_AUTOSIZE_USEHEADER
) item
.m_width
= GetTextLength( item
.m_text
)+7;
1685 wxListHeaderData
*column
= (wxListHeaderData
*)node
->Data();
1686 column
->SetItem( item
);
1688 wxListCtrl
*lc
= (wxListCtrl
*) GetParent();
1689 if (lc
->m_headerWin
) lc
->m_headerWin
->Refresh();
1692 void wxListMainWindow::SetColumnWidth( int col
, int width
)
1694 if (!(m_mode
& wxLC_REPORT
)) return;
1698 wxNode
*node
= (wxNode
*) NULL
;
1700 if (width
== wxLIST_AUTOSIZE_USEHEADER
) width
= 80;
1701 if (width
== wxLIST_AUTOSIZE
)
1703 wxClientDC
dc(this);
1704 dc
.SetFont( GetFont() );
1706 node
= m_lines
.First();
1709 wxListLineData
*line
= (wxListLineData
*)node
->Data();
1710 wxNode
*n
= line
->m_items
.Nth( col
);
1713 wxListItemData
*item
= (wxListItemData
*)n
->Data();
1714 int current
= 0, ix
= 0, iy
= 0;
1715 long lx
= 0, ly
= 0;
1716 if (item
->HasImage())
1718 GetImageSize( item
->GetImage(), ix
, iy
);
1721 if (item
->HasText())
1724 item
->GetText( str
);
1725 dc
.GetTextExtent( str
, &lx
, &ly
);
1728 if (current
> max
) max
= current
;
1730 node
= node
->Next();
1735 node
= m_columns
.Nth( col
);
1738 wxListHeaderData
*column
= (wxListHeaderData
*)node
->Data();
1739 column
->SetWidth( width
);
1742 node
= m_lines
.First();
1745 wxListLineData
*line
= (wxListLineData
*)node
->Data();
1746 wxNode
*n
= line
->m_items
.Nth( col
);
1749 wxListItemData
*item
= (wxListItemData
*)n
->Data();
1750 item
->SetSize( width
, -1 );
1752 node
= node
->Next();
1755 wxListCtrl
*lc
= (wxListCtrl
*) GetParent();
1756 if (lc
->m_headerWin
) lc
->m_headerWin
->Refresh();
1759 void wxListMainWindow::GetColumn( int col
, wxListItem
&item
)
1761 wxNode
*node
= m_columns
.Nth( col
);
1764 wxListHeaderData
*column
= (wxListHeaderData
*)node
->Data();
1765 column
->GetItem( item
);
1777 int wxListMainWindow::GetColumnWidth( int col
)
1779 wxNode
*node
= m_columns
.Nth( col
);
1782 wxListHeaderData
*column
= (wxListHeaderData
*)node
->Data();
1783 return column
->GetWidth();
1791 int wxListMainWindow::GetColumnCount( void )
1793 return m_columns
.Number();
1796 int wxListMainWindow::GetCountPerPage( void )
1798 return m_visibleLines
;
1801 void wxListMainWindow::SetItem( wxListItem
&item
)
1804 wxNode
*node
= m_lines
.Nth( item
.m_itemId
);
1807 wxListLineData
*line
= (wxListLineData
*)node
->Data();
1808 if (m_mode
& wxLC_REPORT
) item
.m_width
= GetColumnWidth( item
.m_col
)-3;
1809 line
->SetItem( item
.m_col
, item
);
1813 void wxListMainWindow::SetItemState( long item
, long state
, long stateMask
)
1815 // m_dirty = TRUE; no recalcs needed
1817 wxListLineData
*oldCurrent
= m_current
;
1819 if (stateMask
& wxLIST_STATE_FOCUSED
)
1821 wxNode
*node
= m_lines
.Nth( item
);
1824 wxListLineData
*line
= (wxListLineData
*)node
->Data();
1825 UnfocusLine( m_current
);
1827 FocusLine( m_current
);
1828 RefreshLine( m_current
);
1829 if (oldCurrent
) RefreshLine( oldCurrent
);
1833 if (stateMask
& wxLIST_STATE_SELECTED
)
1835 bool on
= state
& wxLIST_STATE_SELECTED
;
1836 if (!on
&& (m_mode
& wxLC_SINGLE_SEL
)) return;
1838 wxNode
*node
= m_lines
.Nth( item
);
1841 wxListLineData
*line
= (wxListLineData
*)node
->Data();
1842 if (m_mode
& wxLC_SINGLE_SEL
)
1844 UnfocusLine( m_current
);
1846 FocusLine( m_current
);
1847 if (oldCurrent
) oldCurrent
->Hilight( FALSE
);
1848 RefreshLine( m_current
);
1849 if (oldCurrent
) RefreshLine( oldCurrent
);
1851 bool on
= state
& wxLIST_STATE_SELECTED
;
1852 if (on
!= line
->IsHilighted())
1854 line
->Hilight( on
);
1855 RefreshLine( line
);
1861 int wxListMainWindow::GetItemState( long item
, long stateMask
)
1863 int ret
= wxLIST_STATE_DONTCARE
;
1864 if (stateMask
& wxLIST_STATE_FOCUSED
)
1866 wxNode
*node
= m_lines
.Nth( item
);
1869 wxListLineData
*line
= (wxListLineData
*)node
->Data();
1870 if (line
== m_current
) ret
|= wxLIST_STATE_FOCUSED
;
1873 if (stateMask
& wxLIST_STATE_SELECTED
)
1875 wxNode
*node
= m_lines
.Nth( item
);
1878 wxListLineData
*line
= (wxListLineData
*)node
->Data();
1879 if (line
->IsHilighted()) ret
|= wxLIST_STATE_FOCUSED
;
1885 void wxListMainWindow::GetItem( wxListItem
&item
)
1887 wxNode
*node
= m_lines
.Nth( item
.m_itemId
);
1890 wxListLineData
*line
= (wxListLineData
*)node
->Data();
1891 line
->GetItem( item
.m_col
, item
);
1902 int wxListMainWindow::GetItemCount( void )
1904 return m_lines
.Number();
1907 void wxListMainWindow::GetItemRect( long index
, wxRect
&rect
)
1909 wxNode
*node
= m_lines
.Nth( index
);
1912 wxListLineData
*line
= (wxListLineData
*)node
->Data();
1913 line
->GetRect( rect
);
1924 bool wxListMainWindow::GetItemPosition(long item
, wxPoint
& pos
)
1926 wxNode
*node
= m_lines
.Nth( item
);
1930 wxListLineData
*line
= (wxListLineData
*)node
->Data();
1931 line
->GetRect( rect
);
1943 int wxListMainWindow::GetSelectedItemCount( void )
1946 wxNode
*node
= m_lines
.First();
1949 wxListLineData
*line
= (wxListLineData
*)node
->Data();
1950 if (line
->IsHilighted()) ret
++;
1951 node
= node
->Next();
1956 void wxListMainWindow::SetMode( long mode
)
1963 if (m_mode
& wxLC_REPORT
)
1975 long wxListMainWindow::GetMode( void ) const
1980 void wxListMainWindow::CalculatePositions( void )
1982 if (!m_lines
.First()) return;
1984 wxClientDC
dc( this );
1985 dc
.SetFont( GetFont() );
1987 int iconSpacing
= 0;
1988 if (m_mode
& wxLC_ICON
) iconSpacing
= m_normal_spacing
;
1989 if (m_mode
& wxLC_SMALL_ICON
) iconSpacing
= m_small_spacing
;
1991 // we take the first line (which also can be an icon or
1992 // an a text item in wxLC_ICON and wxLC_LIST modes) to
1993 // measure the size of the line
1997 int lineSpacing
= 0;
1999 wxListLineData
*line
= (wxListLineData
*)m_lines
.First()->Data();
2000 line
->CalculateSize( &dc
, iconSpacing
);
2002 line
->GetSize( dummy
, lineSpacing
);
2005 int clientWidth
= 0;
2006 int clientHeight
= 0;
2008 if (m_mode
& wxLC_REPORT
)
2012 int entireHeight
= m_lines
.Number() * lineSpacing
+ 2;
2013 int scroll_pos
= GetScrollPos( wxVERTICAL
);
2014 SetScrollbars( m_xScroll
, m_yScroll
, 0, (entireHeight
+15) / m_yScroll
, 0, scroll_pos
, TRUE
);
2015 GetClientSize( &clientWidth
, &clientHeight
);
2017 wxNode
* node
= m_lines
.First();
2020 wxListLineData
*line
= (wxListLineData
*)node
->Data();
2021 line
->CalculateSize( &dc
, iconSpacing
);
2022 line
->SetPosition( &dc
, x
, y
, clientWidth
);
2024 for (int i
= 0; i
< GetColumnCount(); i
++)
2026 line
->SetColumnPosition( i
, col_x
);
2027 col_x
+= GetColumnWidth( i
);
2029 y
+= lineSpacing
; // one pixel blank line between items
2030 node
= node
->Next();
2032 m_visibleLines
= clientHeight
/ lineSpacing
;
2036 // at first we try without any scrollbar. if the items don't
2037 // fit into the window, we recalculate after subtracting an
2038 // approximated 15 pt for the horizontal scrollbar
2040 GetSize( &clientWidth
, &clientHeight
);
2041 clientHeight
-= 4; // sunken frame
2043 int entireWidth
= 0;
2045 for (int tries
= 0; tries
< 2; tries
++)
2048 int x
= 5; // painting is done at x-2
2049 int y
= 5; // painting is done at y-2
2051 wxNode
*node
= m_lines
.First();
2054 wxListLineData
*line
= (wxListLineData
*)node
->Data();
2055 line
->CalculateSize( &dc
, iconSpacing
);
2056 line
->SetPosition( &dc
, x
, y
, clientWidth
);
2057 line
->GetSize( lineWidth
, lineHeight
);
2058 if (lineWidth
> maxWidth
) maxWidth
= lineWidth
;
2060 if (y
+lineSpacing
-6 >= clientHeight
) // -6 for earlier "line breaking"
2064 entireWidth
+= maxWidth
+6;
2067 node
= node
->Next();
2068 if (!node
) entireWidth
+= maxWidth
;
2069 if ((tries
== 0) && (entireWidth
> clientWidth
))
2071 clientHeight
-= 15; // scrollbar height
2074 if (!node
) tries
= 1; // everything fits, no second try required
2077 m_visibleLines
= (clientHeight
+6) / (lineSpacing
); // +6 for earlier "line breaking"
2079 int scroll_pos
= GetScrollPos( wxHORIZONTAL
);
2080 SetScrollbars( m_xScroll
, m_yScroll
, (entireWidth
+15) / m_xScroll
, 0, scroll_pos
, 0, TRUE
);
2084 void wxListMainWindow::RealizeChanges( void )
2088 wxNode
*node
= m_lines
.First();
2089 if (node
) m_current
= (wxListLineData
*)node
->Data();
2093 FocusLine( m_current
);
2094 if (m_mode
& wxLC_SINGLE_SEL
) m_current
->Hilight( TRUE
);
2098 long wxListMainWindow::GetNextItem( long item
, int WXUNUSED(geometry
), int state
)
2101 if (item
> 0) ret
= item
;
2102 if(ret
>= GetItemCount()) return -1;
2103 wxNode
*node
= m_lines
.Nth( ret
);
2106 wxListLineData
*line
= (wxListLineData
*)node
->Data();
2107 if ((state
& wxLIST_STATE_FOCUSED
) && (line
== m_current
)) return ret
;
2108 if ((state
& wxLIST_STATE_SELECTED
) && (line
->IsHilighted())) return ret
;
2109 if (!state
) return ret
;
2111 node
= node
->Next();
2116 void wxListMainWindow::DeleteItem( long index
)
2119 wxNode
*node
= m_lines
.Nth( index
);
2122 wxListLineData
*line
= (wxListLineData
*)node
->Data();
2123 if (m_current
== line
) m_current
= (wxListLineData
*) NULL
;
2125 m_lines
.DeleteNode( node
);
2129 void wxListMainWindow::DeleteColumn( int col
)
2131 wxCHECK_RET( col
< (int)m_columns
.GetCount(),
2132 _T("attempting to delete inexistent column in wxListView") );
2135 wxNode
*node
= m_columns
.Nth( col
);
2136 if (node
) m_columns
.DeleteNode( node
);
2139 void wxListMainWindow::DeleteAllItems( void )
2142 m_current
= (wxListLineData
*) NULL
;
2143 wxNode
*node
= m_lines
.First();
2146 wxListLineData
*line
= (wxListLineData
*)node
->Data();
2148 node
= node
->Next();
2153 void wxListMainWindow::DeleteEverything( void )
2156 m_current
= (wxListLineData
*) NULL
;
2157 wxNode
*node
= m_lines
.First();
2160 wxListLineData
*line
= (wxListLineData
*)node
->Data();
2162 node
= node
->Next();
2165 m_current
= (wxListLineData
*) NULL
;
2169 void wxListMainWindow::EnsureVisible( long index
)
2171 wxListLineData
*oldCurrent
= m_current
;
2172 m_current
= (wxListLineData
*) NULL
;
2174 wxNode
*node
= m_lines
.Nth( i
);
2175 if (node
) m_current
= (wxListLineData
*)node
->Data();
2176 if (m_current
) MoveToFocus();
2177 m_current
= oldCurrent
;
2180 long wxListMainWindow::FindItem(long start
, const wxString
& str
, bool WXUNUSED(partial
) )
2184 if (pos
< 0) pos
= 0;
2185 wxNode
*node
= m_lines
.Nth( pos
);
2188 wxListLineData
*line
= (wxListLineData
*)node
->Data();
2190 line
->GetText( 0, s
);
2191 if (s
== tmp
) return pos
;
2192 node
= node
->Next();
2198 long wxListMainWindow::FindItem(long start
, long data
)
2201 if (pos
< 0) pos
= 0;
2202 wxNode
*node
= m_lines
.Nth( pos
);
2205 wxListLineData
*line
= (wxListLineData
*)node
->Data();
2207 line
->GetItem( 0, item
);
2208 if (item
.m_data
== data
) return pos
;
2209 node
= node
->Next();
2215 long wxListMainWindow::HitTest( int x
, int y
, int &flags
)
2217 wxNode
*node
= m_lines
.First();
2221 wxListLineData
*line
= (wxListLineData
*)node
->Data();
2222 long ret
= line
->IsHit( x
, y
);
2228 node
= node
->Next();
2234 void wxListMainWindow::InsertItem( wxListItem
&item
)
2238 if (m_mode
& wxLC_REPORT
) mode
= wxLC_REPORT
;
2239 else if (m_mode
& wxLC_LIST
) mode
= wxLC_LIST
;
2240 else if (m_mode
& wxLC_ICON
) mode
= wxLC_ICON
;
2241 else if (m_mode
& wxLC_SMALL_ICON
) mode
= wxLC_ICON
; // no typo
2243 wxListLineData
*line
= new wxListLineData( this, mode
, m_hilightBrush
);
2245 if (m_mode
& wxLC_REPORT
)
2247 line
->InitItems( GetColumnCount() );
2248 item
.m_width
= GetColumnWidth( 0 )-3;
2252 line
->InitItems( 1 );
2255 line
->SetItem( 0, item
);
2256 if ((item
.m_itemId
>= 0) && (item
.m_itemId
< (int)m_lines
.GetCount()))
2258 wxNode
*node
= m_lines
.Nth( item
.m_itemId
);
2259 if (node
) m_lines
.Insert( node
, line
);
2263 m_lines
.Append( line
);
2267 void wxListMainWindow::InsertColumn( long col
, wxListItem
&item
)
2270 if (m_mode
& wxLC_REPORT
)
2272 if (item
.m_width
== wxLIST_AUTOSIZE_USEHEADER
) item
.m_width
= GetTextLength( item
.m_text
);
2273 wxListHeaderData
*column
= new wxListHeaderData( item
);
2274 if ((col
>= 0) && (col
< (int)m_columns
.GetCount()))
2276 wxNode
*node
= m_columns
.Nth( col
);
2278 m_columns
.Insert( node
, column
);
2282 m_columns
.Append( column
);
2287 wxListCtrlCompare list_ctrl_compare_func_2
;
2288 long list_ctrl_compare_data
;
2290 int list_ctrl_compare_func_1( const void *arg1
, const void *arg2
)
2292 wxListLineData
*line1
= *((wxListLineData
**)arg1
);
2293 wxListLineData
*line2
= *((wxListLineData
**)arg2
);
2295 line1
->GetItem( 0, item
);
2296 long data1
= item
.m_data
;
2297 line2
->GetItem( 0, item
);
2298 long data2
= item
.m_data
;
2299 return list_ctrl_compare_func_2( data1
, data2
, list_ctrl_compare_data
);
2302 void wxListMainWindow::SortItems( wxListCtrlCompare fn
, long data
)
2304 list_ctrl_compare_func_2
= fn
;
2305 list_ctrl_compare_data
= data
;
2306 m_lines
.Sort( list_ctrl_compare_func_1
);
2309 // -------------------------------------------------------------------------------------
2311 // -------------------------------------------------------------------------------------
2313 IMPLEMENT_DYNAMIC_CLASS(wxListItem
, wxObject
)
2315 wxListItem::wxListItem(void)
2324 m_format
= wxLIST_FORMAT_CENTRE
;
2329 // -------------------------------------------------------------------------------------
2331 // -------------------------------------------------------------------------------------
2333 IMPLEMENT_DYNAMIC_CLASS(wxListEvent
, wxNotifyEvent
)
2335 wxListEvent::wxListEvent( wxEventType commandType
, int id
):
2336 wxNotifyEvent( commandType
, id
)
2342 m_cancelled
= FALSE
;
2347 // -------------------------------------------------------------------------------------
2349 // -------------------------------------------------------------------------------------
2351 IMPLEMENT_DYNAMIC_CLASS(wxListCtrl
, wxControl
)
2353 BEGIN_EVENT_TABLE(wxListCtrl
,wxControl
)
2354 EVT_SIZE (wxListCtrl::OnSize
)
2355 EVT_IDLE (wxListCtrl::OnIdle
)
2358 wxListCtrl::wxListCtrl(void)
2360 m_imageListNormal
= (wxImageList
*) NULL
;
2361 m_imageListSmall
= (wxImageList
*) NULL
;
2362 m_imageListState
= (wxImageList
*) NULL
;
2363 m_mainWin
= (wxListMainWindow
*) NULL
;
2364 m_headerWin
= (wxListHeaderWindow
*) NULL
;
2367 wxListCtrl::~wxListCtrl(void)
2371 bool wxListCtrl::Create( wxWindow
*parent
, wxWindowID id
,
2372 const wxPoint
&pos
, const wxSize
&size
,
2373 long style
, const wxValidator
&validator
,
2374 const wxString
&name
)
2376 m_imageListNormal
= (wxImageList
*) NULL
;
2377 m_imageListSmall
= (wxImageList
*) NULL
;
2378 m_imageListState
= (wxImageList
*) NULL
;
2379 m_mainWin
= (wxListMainWindow
*) NULL
;
2380 m_headerWin
= (wxListHeaderWindow
*) NULL
;
2384 if ((s
& wxLC_REPORT
== 0) &&
2385 (s
& wxLC_LIST
== 0) &&
2386 (s
& wxLC_ICON
== 0))
2391 bool ret
= wxControl::Create( parent
, id
, pos
, size
, s
, name
);
2393 #if wxUSE_VALIDATORS
2394 SetValidator( validator
);
2397 if (s
& wxSUNKEN_BORDER
) s
-= wxSUNKEN_BORDER
;
2399 m_mainWin
= new wxListMainWindow( this, -1, wxPoint(0,0), size
, s
);
2401 if (HasFlag(wxLC_REPORT
))
2402 m_headerWin
= new wxListHeaderWindow( this, -1, m_mainWin
, wxPoint(0,0), wxSize(size
.x
,23), wxTAB_TRAVERSAL
);
2404 m_headerWin
= (wxListHeaderWindow
*) NULL
;
2406 SetBackgroundColour( *wxWHITE
);
2411 void wxListCtrl::OnSize( wxSizeEvent
&WXUNUSED(event
) )
2413 /* handled in OnIdle */
2415 if (m_mainWin
) m_mainWin
->m_dirty
= TRUE
;
2418 void wxListCtrl::SetSingleStyle( long style
, bool add
)
2420 long flag
= GetWindowStyle();
2424 if (style
& wxLC_MASK_TYPE
) flag
= flag
& ~wxLC_MASK_TYPE
;
2425 if (style
& wxLC_MASK_ALIGN
) flag
= flag
& ~wxLC_MASK_ALIGN
;
2426 if (style
& wxLC_MASK_SORT
) flag
= flag
& ~wxLC_MASK_SORT
;
2435 if (flag
& style
) flag
-= style
;
2438 SetWindowStyleFlag( flag
);
2441 void wxListCtrl::SetWindowStyleFlag( long flag
)
2445 m_mainWin
->DeleteEverything();
2449 GetClientSize( &width
, &height
);
2451 m_mainWin
->SetMode( flag
);
2453 if (flag
& wxLC_REPORT
)
2455 if (!HasFlag(wxLC_REPORT
))
2459 m_headerWin
= new wxListHeaderWindow( this, -1, m_mainWin
,
2460 wxPoint(0,0), wxSize(width
,23), wxTAB_TRAVERSAL
);
2464 m_headerWin
->Show( TRUE
);
2470 if (HasFlag(wxLC_REPORT
))
2472 m_headerWin
->Show( FALSE
);
2477 wxWindow::SetWindowStyleFlag( flag
);
2480 bool wxListCtrl::GetColumn(int col
, wxListItem
&item
) const
2482 m_mainWin
->GetColumn( col
, item
);
2486 bool wxListCtrl::SetColumn( int col
, wxListItem
& item
)
2488 m_mainWin
->SetColumn( col
, item
);
2492 int wxListCtrl::GetColumnWidth( int col
) const
2494 return m_mainWin
->GetColumnWidth( col
);
2497 bool wxListCtrl::SetColumnWidth( int col
, int width
)
2499 m_mainWin
->SetColumnWidth( col
, width
);
2503 int wxListCtrl::GetCountPerPage(void) const
2505 return m_mainWin
->GetCountPerPage(); // different from Windows ?
2509 wxText& wxListCtrl::GetEditControl(void) const
2514 bool wxListCtrl::GetItem( wxListItem
&info
) const
2516 m_mainWin
->GetItem( info
);
2520 bool wxListCtrl::SetItem( wxListItem
&info
)
2522 m_mainWin
->SetItem( info
);
2526 long wxListCtrl::SetItem( long index
, int col
, const wxString
& label
, int imageId
)
2529 info
.m_text
= label
;
2530 info
.m_mask
= wxLIST_MASK_TEXT
;
2531 info
.m_itemId
= index
;
2535 info
.m_image
= imageId
;
2536 info
.m_mask
|= wxLIST_MASK_IMAGE
;
2538 m_mainWin
->SetItem(info
);
2542 int wxListCtrl::GetItemState( long item
, long stateMask
) const
2544 return m_mainWin
->GetItemState( item
, stateMask
);
2547 bool wxListCtrl::SetItemState( long item
, long state
, long stateMask
)
2549 m_mainWin
->SetItemState( item
, state
, stateMask
);
2553 bool wxListCtrl::SetItemImage( long item
, int image
, int WXUNUSED(selImage
) )
2556 info
.m_image
= image
;
2557 info
.m_mask
= wxLIST_MASK_IMAGE
;
2558 info
.m_itemId
= item
;
2559 m_mainWin
->SetItem( info
);
2563 wxString
wxListCtrl::GetItemText( long item
) const
2566 info
.m_itemId
= item
;
2567 m_mainWin
->GetItem( info
);
2571 void wxListCtrl::SetItemText( long item
, const wxString
&str
)
2574 info
.m_mask
= wxLIST_MASK_TEXT
;
2575 info
.m_itemId
= item
;
2577 m_mainWin
->SetItem( info
);
2580 long wxListCtrl::GetItemData( long item
) const
2583 info
.m_itemId
= item
;
2584 m_mainWin
->GetItem( info
);
2588 bool wxListCtrl::SetItemData( long item
, long data
)
2591 info
.m_mask
= wxLIST_MASK_DATA
;
2592 info
.m_itemId
= item
;
2594 m_mainWin
->SetItem( info
);
2598 bool wxListCtrl::GetItemRect( long item
, wxRect
&rect
, int WXUNUSED(code
) ) const
2600 m_mainWin
->GetItemRect( item
, rect
);
2604 bool wxListCtrl::GetItemPosition( long item
, wxPoint
& pos
) const
2606 m_mainWin
->GetItemPosition( item
, pos
);
2610 bool wxListCtrl::SetItemPosition( long WXUNUSED(item
), const wxPoint
& WXUNUSED(pos
) )
2615 int wxListCtrl::GetItemCount(void) const
2617 return m_mainWin
->GetItemCount();
2620 int wxListCtrl::GetColumnCount(void) const
2622 return m_mainWin
->GetColumnCount();
2625 void wxListCtrl::SetItemSpacing( int spacing
, bool isSmall
)
2627 m_mainWin
->SetItemSpacing( spacing
, isSmall
);
2630 int wxListCtrl::GetItemSpacing( bool isSmall
) const
2632 return m_mainWin
->GetItemSpacing( isSmall
);
2635 int wxListCtrl::GetSelectedItemCount(void) const
2637 return m_mainWin
->GetSelectedItemCount();
2641 wxColour wxListCtrl::GetTextColour(void) const
2645 void wxListCtrl::SetTextColour(const wxColour& WXUNUSED(col))
2650 long wxListCtrl::GetTopItem(void) const
2655 long wxListCtrl::GetNextItem( long item
, int geom
, int state
) const
2657 return m_mainWin
->GetNextItem( item
, geom
, state
);
2660 wxImageList
*wxListCtrl::GetImageList(int which
) const
2662 if (which
== wxIMAGE_LIST_NORMAL
)
2664 return m_imageListNormal
;
2666 else if (which
== wxIMAGE_LIST_SMALL
)
2668 return m_imageListSmall
;
2670 else if (which
== wxIMAGE_LIST_STATE
)
2672 return m_imageListState
;
2674 return (wxImageList
*) NULL
;
2677 void wxListCtrl::SetImageList( wxImageList
*imageList
, int which
)
2679 m_mainWin
->SetImageList( imageList
, which
);
2682 bool wxListCtrl::Arrange( int WXUNUSED(flag
) )
2687 bool wxListCtrl::DeleteItem( long item
)
2689 m_mainWin
->DeleteItem( item
);
2693 bool wxListCtrl::DeleteAllItems(void)
2695 m_mainWin
->DeleteAllItems();
2699 bool wxListCtrl::DeleteAllColumns()
2701 for ( size_t n
= 0; n
< m_mainWin
->m_columns
.GetCount(); n
++ )
2707 void wxListCtrl::ClearAll()
2709 m_mainWin
->DeleteEverything();
2712 bool wxListCtrl::DeleteColumn( int col
)
2714 m_mainWin
->DeleteColumn( col
);
2719 wxText& wxListCtrl::Edit( long WXUNUSED(item ) )
2724 bool wxListCtrl::EnsureVisible( long item
)
2726 m_mainWin
->EnsureVisible( item
);
2730 long wxListCtrl::FindItem( long start
, const wxString
& str
, bool partial
)
2732 return m_mainWin
->FindItem( start
, str
, partial
);
2735 long wxListCtrl::FindItem( long start
, long data
)
2737 return m_mainWin
->FindItem( start
, data
);
2740 long wxListCtrl::FindItem( long WXUNUSED(start
), const wxPoint
& WXUNUSED(pt
),
2741 int WXUNUSED(direction
))
2746 long wxListCtrl::HitTest( const wxPoint
&point
, int &flags
)
2748 return m_mainWin
->HitTest( (int)point
.x
, (int)point
.y
, flags
);
2751 long wxListCtrl::InsertItem( wxListItem
& info
)
2753 m_mainWin
->InsertItem( info
);
2757 long wxListCtrl::InsertItem( long index
, const wxString
&label
)
2760 info
.m_text
= label
;
2761 info
.m_mask
= wxLIST_MASK_TEXT
;
2762 info
.m_itemId
= index
;
2763 return InsertItem( info
);
2766 long wxListCtrl::InsertItem( long index
, int imageIndex
)
2769 info
.m_mask
= wxLIST_MASK_IMAGE
;
2770 info
.m_image
= imageIndex
;
2771 info
.m_itemId
= index
;
2772 return InsertItem( info
);
2775 long wxListCtrl::InsertItem( long index
, const wxString
&label
, int imageIndex
)
2778 info
.m_text
= label
;
2779 info
.m_image
= imageIndex
;
2780 info
.m_mask
= wxLIST_MASK_TEXT
| wxLIST_MASK_IMAGE
;
2781 info
.m_itemId
= index
;
2782 return InsertItem( info
);
2785 long wxListCtrl::InsertColumn( long col
, wxListItem
&item
)
2787 m_mainWin
->InsertColumn( col
, item
);
2791 long wxListCtrl::InsertColumn( long col
, const wxString
&heading
,
2792 int format
, int width
)
2795 item
.m_mask
= wxLIST_MASK_TEXT
| wxLIST_MASK_FORMAT
;
2796 item
.m_text
= heading
;
2799 item
.m_mask
|= wxLIST_MASK_WIDTH
;
2800 item
.m_width
= width
;
2802 item
.m_format
= format
;
2804 return InsertColumn( col
, item
);
2807 bool wxListCtrl::ScrollList( int WXUNUSED(dx
), int WXUNUSED(dy
) )
2813 // fn is a function which takes 3 long arguments: item1, item2, data.
2814 // item1 is the long data associated with a first item (NOT the index).
2815 // item2 is the long data associated with a second item (NOT the index).
2816 // data is the same value as passed to SortItems.
2817 // The return value is a negative number if the first item should precede the second
2818 // item, a positive number of the second item should precede the first,
2819 // or zero if the two items are equivalent.
2820 // data is arbitrary data to be passed to the sort function.
2822 bool wxListCtrl::SortItems( wxListCtrlCompare fn
, long data
)
2824 m_mainWin
->SortItems( fn
, data
);
2828 void wxListCtrl::OnIdle( wxIdleEvent
&WXUNUSED(event
) )
2830 if (!m_mainWin
->m_dirty
) return;
2834 GetClientSize( &cw
, &ch
);
2841 if (HasFlag(wxLC_REPORT
))
2843 m_headerWin
->GetPosition( &x
, &y
);
2844 m_headerWin
->GetSize( &w
, &h
);
2845 if ((x
!= 0) || (y
!= 0) || (w
!= cw
) || (h
!= 23))
2846 m_headerWin
->SetSize( 0, 0, cw
, 23 );
2848 m_mainWin
->GetPosition( &x
, &y
);
2849 m_mainWin
->GetSize( &w
, &h
);
2850 if ((x
!= 0) || (y
!= 24) || (w
!= cw
) || (h
!= ch
-24))
2851 m_mainWin
->SetSize( 0, 24, cw
, ch
-24 );
2855 m_mainWin
->GetPosition( &x
, &y
);
2856 m_mainWin
->GetSize( &w
, &h
);
2857 if ((x
!= 0) || (y
!= 24) || (w
!= cw
) || (h
!= ch
))
2858 m_mainWin
->SetSize( 0, 0, cw
, ch
);
2861 m_mainWin
->CalculatePositions();
2862 m_mainWin
->RealizeChanges();
2863 m_mainWin
->m_dirty
= FALSE
;
2864 m_mainWin
->Refresh();
2867 bool wxListCtrl::SetBackgroundColour( const wxColour
&colour
)
2869 if ( !wxWindow::SetBackgroundColour( colour
) )
2874 m_mainWin
->SetBackgroundColour( colour
);
2875 m_mainWin
->m_dirty
= TRUE
;
2880 // m_headerWin->SetBackgroundColour( colour );
2886 bool wxListCtrl::SetForegroundColour( const wxColour
&colour
)
2888 if ( !wxWindow::SetForegroundColour( colour
) )
2893 m_mainWin
->SetForegroundColour( colour
);
2894 m_mainWin
->m_dirty
= TRUE
;
2899 m_headerWin
->SetForegroundColour( colour
);
2905 bool wxListCtrl::SetFont( const wxFont
&font
)
2907 if ( !wxWindow::SetFont( font
) )
2912 m_mainWin
->SetFont( font
);
2913 m_mainWin
->m_dirty
= TRUE
;
2918 m_headerWin
->SetFont( font
);