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();
911 if (!wxPendingDelete
.Member(this)) wxPendingDelete
.Append(this);
914 if (event
.m_keyCode
== WXK_ESCAPE
)
918 if (!wxPendingDelete
.Member(this)) wxPendingDelete
.Append(this);
924 void wxListTextCtrl::OnKillFocus( wxFocusEvent
&WXUNUSED(event
) )
928 if (!wxPendingDelete
.Member(this)) wxPendingDelete
.Append(this);
932 //-----------------------------------------------------------------------------
934 //-----------------------------------------------------------------------------
936 IMPLEMENT_DYNAMIC_CLASS(wxListMainWindow
,wxScrolledWindow
);
938 BEGIN_EVENT_TABLE(wxListMainWindow
,wxScrolledWindow
)
939 EVT_PAINT (wxListMainWindow::OnPaint
)
940 EVT_SIZE (wxListMainWindow::OnSize
)
941 EVT_MOUSE_EVENTS (wxListMainWindow::OnMouse
)
942 EVT_CHAR (wxListMainWindow::OnChar
)
943 EVT_KEY_DOWN (wxListMainWindow::OnKeyDown
)
944 EVT_SET_FOCUS (wxListMainWindow::OnSetFocus
)
945 EVT_KILL_FOCUS (wxListMainWindow::OnKillFocus
)
948 wxListMainWindow::wxListMainWindow( void )
951 m_lines
.DeleteContents( TRUE
);
952 m_columns
.DeleteContents( TRUE
);
953 m_current
= (wxListLineData
*) NULL
;
955 m_hilightBrush
= (wxBrush
*) NULL
;
959 m_small_image_list
= (wxImageList
*) NULL
;
960 m_normal_image_list
= (wxImageList
*) NULL
;
961 m_small_spacing
= 30;
962 m_normal_spacing
= 40;
965 m_lastOnSame
= FALSE
;
966 m_renameTimer
= new wxListRenameTimer( this );
971 wxListMainWindow::wxListMainWindow( wxWindow
*parent
, wxWindowID id
,
972 const wxPoint
&pos
, const wxSize
&size
,
973 long style
, const wxString
&name
) :
974 wxScrolledWindow( parent
, id
, pos
, size
, style
|wxHSCROLL
|wxVSCROLL
, name
)
977 m_lines
.DeleteContents( TRUE
);
978 m_columns
.DeleteContents( TRUE
);
979 m_current
= (wxListLineData
*) NULL
;
982 m_hilightBrush
= new wxBrush( wxSystemSettings::GetSystemColour(wxSYS_COLOUR_HIGHLIGHT
), wxSOLID
);
983 m_small_image_list
= (wxImageList
*) NULL
;
984 m_normal_image_list
= (wxImageList
*) NULL
;
985 m_small_spacing
= 30;
986 m_normal_spacing
= 40;
993 if (m_mode
& wxLC_REPORT
)
1003 SetScrollbars( m_xScroll
, m_yScroll
, 0, 0, 0, 0 );
1006 m_lastOnSame
= FALSE
;
1007 m_renameTimer
= new wxListRenameTimer( this );
1008 m_renameAccept
= FALSE
;
1010 SetBackgroundColour( *wxWHITE
);
1013 wxListMainWindow::~wxListMainWindow( void )
1015 if (m_hilightBrush
) delete m_hilightBrush
;
1017 delete m_renameTimer
;
1020 void wxListMainWindow::RefreshLine( wxListLineData
*line
)
1028 wxClientDC
dc(this);
1030 line
->GetExtent( x
, y
, w
, h
);
1032 dc
.LogicalToDeviceX(x
-3),
1033 dc
.LogicalToDeviceY(y
-3),
1034 dc
.LogicalToDeviceXRel(w
+6),
1035 dc
.LogicalToDeviceXRel(h
+6) );
1036 Refresh( TRUE
, &rect
);
1040 void wxListMainWindow::OnPaint( wxPaintEvent
&WXUNUSED(event
) )
1042 // Note: a wxPaintDC must be constructed even if no drawing is
1043 // done (a Windows requirement).
1044 wxPaintDC
dc( this );
1047 if (m_dirty
) return;
1049 if (m_lines
.GetCount() == 0) return;
1053 dc
.SetFont( GetFont() );
1055 if (m_mode
& wxLC_REPORT
)
1057 int lineSpacing
= 0;
1058 wxListLineData
*line
= (wxListLineData
*)m_lines
.First()->Data();
1060 line
->GetSize( dummy
, lineSpacing
);
1063 int y_s
= m_yScroll
*GetScrollPos( wxVERTICAL
);
1065 wxNode
*node
= m_lines
.Nth( y_s
/ lineSpacing
);
1066 for (int i
= 0; i
< m_visibleLines
+2; i
++)
1070 line
= (wxListLineData
*)node
->Data();
1072 node
= node
->Next();
1077 wxNode
*node
= m_lines
.First();
1080 wxListLineData
*line
= (wxListLineData
*)node
->Data();
1082 node
= node
->Next();
1086 if (m_current
) m_current
->DrawRubberBand( &dc
, m_hasFocus
);
1091 void wxListMainWindow::HilightAll( bool on
)
1093 wxNode
*node
= m_lines
.First();
1096 wxListLineData
*line
= (wxListLineData
*)node
->Data();
1097 if (line
->IsHilighted() != on
)
1099 line
->Hilight( on
);
1100 RefreshLine( line
);
1102 node
= node
->Next();
1106 void wxListMainWindow::SendNotify( wxListLineData
*line
, wxEventType command
)
1108 wxListEvent
le( command
, GetParent()->GetId() );
1109 le
.SetEventObject( GetParent() );
1110 le
.m_itemIndex
= GetIndexOfLine( line
);
1111 line
->GetItem( 0, le
.m_item
);
1112 GetParent()->GetEventHandler()->ProcessEvent( le
);
1115 void wxListMainWindow::FocusLine( wxListLineData
*WXUNUSED(line
) )
1117 // SendNotify( line, wxEVT_COMMAND_LIST_ITEM_FOCUSSED );
1120 void wxListMainWindow::UnfocusLine( wxListLineData
*WXUNUSED(line
) )
1122 // SendNotify( line, wxEVT_COMMAND_LIST_ITEM_UNFOCUSSED );
1125 void wxListMainWindow::SelectLine( wxListLineData
*line
)
1127 SendNotify( line
, wxEVT_COMMAND_LIST_ITEM_SELECTED
);
1130 void wxListMainWindow::DeselectLine( wxListLineData
*line
)
1132 SendNotify( line
, wxEVT_COMMAND_LIST_ITEM_DESELECTED
);
1135 void wxListMainWindow::DeleteLine( wxListLineData
*line
)
1137 SendNotify( line
, wxEVT_COMMAND_LIST_DELETE_ITEM
);
1142 void wxListMainWindow::Edit( long item
)
1144 wxNode
*node
= m_lines
.Nth( item
);
1145 wxCHECK_RET( node
, _T("wrong index in wxListCtrl::Edit()") );
1147 m_currentEdit
= (wxListLineData
*) node
->Data();
1149 wxListEvent
le( wxEVT_COMMAND_LIST_END_LABEL_EDIT
, GetParent()->GetId() );
1150 le
.SetEventObject( GetParent() );
1151 le
.m_itemIndex
= GetIndexOfLine( m_currentEdit
);
1152 m_currentEdit
->GetItem( 0, le
.m_item
);
1153 GetParent()->GetEventHandler()->ProcessEvent( le
);
1155 if (!le
.IsAllowed()) return;
1158 m_currentEdit
->GetText( 0, s
);
1163 m_currentEdit
->GetLabelExtent( x
, y
, w
, h
);
1165 wxClientDC
dc(this);
1167 x
= dc
.LogicalToDeviceX( x
);
1168 y
= dc
.LogicalToDeviceY( y
);
1170 wxListTextCtrl
*text
= new wxListTextCtrl(
1171 this, -1, &m_renameAccept
, &m_renameRes
, this, s
, wxPoint(x
-4,y
-4), wxSize(w
+11,h
+8) );
1175 void wxListMainWindow::OnRenameTimer()
1177 wxCHECK_RET( m_current
, _T("invalid m_current") );
1179 Edit( m_lines
.IndexOf( m_current
) );
1182 void wxListMainWindow::OnRenameAccept()
1184 wxListEvent
le( wxEVT_COMMAND_LIST_END_LABEL_EDIT
, GetParent()->GetId() );
1185 le
.SetEventObject( GetParent() );
1186 le
.m_itemIndex
= GetIndexOfLine( m_currentEdit
);
1187 m_currentEdit
->GetItem( 0, le
.m_item
);
1188 le
.m_item
.m_text
= m_renameRes
;
1189 GetParent()->GetEventHandler()->ProcessEvent( le
);
1191 if (!le
.IsAllowed()) return;
1193 /* DO CHANGE LABEL */
1196 void wxListMainWindow::OnMouse( wxMouseEvent
&event
)
1198 if (GetParent()->GetEventHandler()->ProcessEvent( event
)) return;
1200 if (!m_current
) return;
1201 if (m_dirty
) return;
1203 wxClientDC
dc(this);
1205 long x
= dc
.DeviceToLogicalX( (long)event
.GetX() );
1206 long y
= dc
.DeviceToLogicalY( (long)event
.GetY() );
1208 /* Did we actually hit an item ? */
1210 wxNode
*node
= m_lines
.First();
1211 wxListLineData
*line
= (wxListLineData
*) NULL
;
1214 line
= (wxListLineData
*)node
->Data();
1215 hitResult
= line
->IsHit( x
, y
);
1216 if (hitResult
) break;
1217 line
= (wxListLineData
*) NULL
;
1218 node
= node
->Next();
1221 if (!event
.Dragging())
1226 if (event
.Dragging() && (m_dragCount
> 3))
1230 wxListEvent
le( wxEVT_COMMAND_LIST_BEGIN_DRAG
, GetParent()->GetId() );
1231 le
.SetEventObject( GetParent() );
1232 le
.m_pointDrag
.x
= x
;
1233 le
.m_pointDrag
.y
= y
;
1234 GetParent()->GetEventHandler()->ProcessEvent( le
);
1241 if (event
.ButtonDClick())
1244 m_lastOnSame
= FALSE
;
1245 m_renameTimer
->Stop();
1247 SendNotify( line
, wxEVT_COMMAND_LIST_ITEM_ACTIVATED
);
1252 if (event
.LeftUp() && m_lastOnSame
)
1255 if ((line
== m_current
) &&
1256 (hitResult
== wxLIST_HITTEST_ONITEMLABEL
) &&
1257 (m_mode
& wxLC_EDIT_LABELS
) )
1259 m_renameTimer
->Start( 100, TRUE
);
1261 m_lastOnSame
= FALSE
;
1265 if (event
.RightDown())
1267 SendNotify( line
, wxEVT_COMMAND_LIST_ITEM_RIGHT_CLICK
);
1271 if (event
.MiddleDown())
1273 SendNotify( line
, wxEVT_COMMAND_LIST_ITEM_MIDDLE_CLICK
);
1277 if (event
.LeftDown())
1280 wxListLineData
*oldCurrent
= m_current
;
1281 if (m_mode
& wxLC_SINGLE_SEL
)
1284 HilightAll( FALSE
);
1285 m_current
->ReverseHilight();
1286 RefreshLine( m_current
);
1290 if (event
.ShiftDown())
1293 m_current
->ReverseHilight();
1294 RefreshLine( m_current
);
1296 else if (event
.ControlDown())
1300 int numOfCurrent
= -1;
1301 node
= m_lines
.First();
1304 wxListLineData
*test_line
= (wxListLineData
*)node
->Data();
1306 if (test_line
== oldCurrent
) break;
1307 node
= node
->Next();
1311 node
= m_lines
.First();
1314 wxListLineData
*test_line
= (wxListLineData
*)node
->Data();
1316 if (test_line
== line
) break;
1317 node
= node
->Next();
1320 if (numOfLine
< numOfCurrent
)
1323 numOfLine
= numOfCurrent
;
1327 wxNode
*node
= m_lines
.Nth( numOfCurrent
);
1328 for (int i
= 0; i
<= numOfLine
-numOfCurrent
; i
++)
1330 wxListLineData
*test_line
= (wxListLineData
*)node
->Data();
1331 test_line
->Hilight(TRUE
);
1332 RefreshLine( test_line
);
1333 node
= node
->Next();
1339 HilightAll( FALSE
);
1340 m_current
->ReverseHilight();
1341 RefreshLine( m_current
);
1344 if (m_current
!= oldCurrent
)
1346 RefreshLine( oldCurrent
);
1347 UnfocusLine( oldCurrent
);
1348 FocusLine( m_current
);
1350 m_lastOnSame
= (m_current
== oldCurrent
);
1355 void wxListMainWindow::MoveToFocus()
1357 if (!m_current
) return;
1363 m_current
->GetExtent( x
, y
, w
, h
);
1367 GetClientSize( &w_p
, &h_p
);
1369 if (m_mode
& wxLC_REPORT
)
1371 int y_s
= m_yScroll
*GetScrollPos( wxVERTICAL
);
1372 if ((y
> y_s
) && (y
+h
< y_s
+h_p
)) return;
1373 if (y
-y_s
< 5) { Scroll( -1, (y
-5-h_p
/2)/m_yScroll
); Refresh(); }
1374 if (y
+h
+5 > y_s
+h_p
) { Scroll( -1, (y
+h
-h_p
/2+h
+15)/m_yScroll
); Refresh(); }
1378 int x_s
= m_xScroll
*GetScrollPos( wxHORIZONTAL
);
1379 if ((x
> x_s
) && (x
+w
< x_s
+w_p
)) return;
1380 if (x
-x_s
< 5) { Scroll( (x
-5)/m_xScroll
, -1 ); Refresh(); }
1381 if (x
+w
-5 > x_s
+w_p
) { Scroll( (x
+w
-w_p
+15)/m_xScroll
, -1 ); Refresh(); }
1385 void wxListMainWindow::OnArrowChar( wxListLineData
*newCurrent
, bool shiftDown
)
1387 if ((m_mode
& wxLC_SINGLE_SEL
) || (m_usedKeys
== FALSE
)) m_current
->Hilight( FALSE
);
1388 wxListLineData
*oldCurrent
= m_current
;
1389 m_current
= newCurrent
;
1391 if (shiftDown
|| (m_mode
& wxLC_SINGLE_SEL
)) m_current
->Hilight( TRUE
);
1392 RefreshLine( m_current
);
1393 RefreshLine( oldCurrent
);
1394 FocusLine( m_current
);
1395 UnfocusLine( oldCurrent
);
1398 void wxListMainWindow::OnKeyDown( wxKeyEvent
&event
)
1400 wxWindow
*parent
= GetParent();
1402 /* we propagate the key event up */
1403 wxKeyEvent
ke( wxEVT_KEY_DOWN
);
1404 ke
.m_shiftDown
= event
.m_shiftDown
;
1405 ke
.m_controlDown
= event
.m_controlDown
;
1406 ke
.m_altDown
= event
.m_altDown
;
1407 ke
.m_metaDown
= event
.m_metaDown
;
1408 ke
.m_keyCode
= event
.m_keyCode
;
1411 ke
.SetEventObject( parent
);
1412 if (parent
->GetEventHandler()->ProcessEvent( ke
)) return;
1417 void wxListMainWindow::OnChar( wxKeyEvent
&event
)
1419 wxWindow
*parent
= GetParent();
1421 /* we send a list_key event up */
1422 wxListEvent
le( wxEVT_COMMAND_LIST_KEY_DOWN
, GetParent()->GetId() );
1423 le
.m_code
= event
.KeyCode();
1424 le
.SetEventObject( parent
);
1425 parent
->GetEventHandler()->ProcessEvent( le
);
1427 /* we propagate the char event up */
1428 wxKeyEvent
ke( wxEVT_CHAR
);
1429 ke
.m_shiftDown
= event
.m_shiftDown
;
1430 ke
.m_controlDown
= event
.m_controlDown
;
1431 ke
.m_altDown
= event
.m_altDown
;
1432 ke
.m_metaDown
= event
.m_metaDown
;
1433 ke
.m_keyCode
= event
.m_keyCode
;
1436 ke
.SetEventObject( parent
);
1437 if (parent
->GetEventHandler()->ProcessEvent( ke
)) return;
1439 if (event
.KeyCode() == WXK_TAB
)
1441 wxNavigationKeyEvent nevent
;
1442 nevent
.SetDirection( !event
.ShiftDown() );
1443 nevent
.SetCurrentFocus( m_parent
);
1444 if (m_parent
->GetEventHandler()->ProcessEvent( nevent
)) return;
1447 /* no item -> nothing to do */
1454 switch (event
.KeyCode())
1458 wxNode
*node
= m_lines
.Member( m_current
)->Previous();
1459 if (node
) OnArrowChar( (wxListLineData
*)node
->Data(), event
.ShiftDown() );
1464 wxNode
*node
= m_lines
.Member( m_current
)->Next();
1465 if (node
) OnArrowChar( (wxListLineData
*)node
->Data(), event
.ShiftDown() );
1470 wxNode
*node
= m_lines
.Last();
1471 OnArrowChar( (wxListLineData
*)node
->Data(), event
.ShiftDown() );
1476 wxNode
*node
= m_lines
.First();
1477 OnArrowChar( (wxListLineData
*)node
->Data(), event
.ShiftDown() );
1483 if (m_mode
& wxLC_REPORT
)
1485 steps
= m_visibleLines
-1;
1490 wxNode
*node
= m_lines
.First();
1491 for (;;) { if (m_current
== (wxListLineData
*)node
->Data()) break; pos
++; node
= node
->Next(); }
1492 steps
= pos
% m_visibleLines
;
1494 wxNode
*node
= m_lines
.Member( m_current
);
1495 for (int i
= 0; i
< steps
; i
++) if (node
->Previous()) node
= node
->Previous();
1496 if (node
) OnArrowChar( (wxListLineData
*)node
->Data(), event
.ShiftDown() );
1502 if (m_mode
& wxLC_REPORT
)
1504 steps
= m_visibleLines
-1;
1508 int pos
= 0; wxNode
*node
= m_lines
.First();
1509 for (;;) { if (m_current
== (wxListLineData
*)node
->Data()) break; pos
++; node
= node
->Next(); }
1510 steps
= m_visibleLines
-(pos
% m_visibleLines
)-1;
1512 wxNode
*node
= m_lines
.Member( m_current
);
1513 for (int i
= 0; i
< steps
; i
++) if (node
->Next()) node
= node
->Next();
1514 if (node
) OnArrowChar( (wxListLineData
*)node
->Data(), event
.ShiftDown() );
1519 if (!(m_mode
& wxLC_REPORT
))
1521 wxNode
*node
= m_lines
.Member( m_current
);
1522 for (int i
= 0; i
<m_visibleLines
; i
++) if (node
->Previous()) node
= node
->Previous();
1523 if (node
) OnArrowChar( (wxListLineData
*)node
->Data(), event
.ShiftDown() );
1529 if (!(m_mode
& wxLC_REPORT
))
1531 wxNode
*node
= m_lines
.Member( m_current
);
1532 for (int i
= 0; i
<m_visibleLines
; i
++) if (node
->Next()) node
= node
->Next();
1533 if (node
) OnArrowChar( (wxListLineData
*)node
->Data(), event
.ShiftDown() );
1539 m_current
->ReverseHilight();
1540 RefreshLine( m_current
);
1545 if (!(m_mode
& wxLC_SINGLE_SEL
))
1547 wxListLineData
*oldCurrent
= m_current
;
1548 m_current
->ReverseHilight();
1549 wxNode
*node
= m_lines
.Member( m_current
)->Next();
1550 if (node
) m_current
= (wxListLineData
*)node
->Data();
1552 RefreshLine( oldCurrent
);
1553 RefreshLine( m_current
);
1554 UnfocusLine( oldCurrent
);
1555 FocusLine( m_current
);
1562 wxListEvent
le( wxEVT_COMMAND_LIST_ITEM_ACTIVATED
, GetParent()->GetId() );
1563 le
.SetEventObject( GetParent() );
1564 le
.m_itemIndex
= GetIndexOfLine( m_current
);
1565 m_current
->GetItem( 0, le
.m_item
);
1566 GetParent()->GetEventHandler()->ProcessEvent( le
);
1578 void wxListMainWindow::OnSetFocus( wxFocusEvent
&WXUNUSED(event
) )
1581 RefreshLine( m_current
);
1583 if (!GetParent()) return;
1585 wxFocusEvent
event( wxEVT_SET_FOCUS
, GetParent()->GetId() );
1586 event
.SetEventObject( GetParent() );
1587 GetParent()->GetEventHandler()->ProcessEvent( event
);
1590 void wxListMainWindow::OnKillFocus( wxFocusEvent
&WXUNUSED(event
) )
1593 RefreshLine( m_current
);
1596 void wxListMainWindow::OnSize( wxSizeEvent
&WXUNUSED(event
) )
1599 We don't even allow the wxScrolledWindow::AdjustScrollbars() call
1604 void wxListMainWindow::DrawImage( int index
, wxDC
*dc
, int x
, int y
)
1606 if ((m_mode
& wxLC_ICON
) && (m_normal_image_list
))
1608 m_normal_image_list
->Draw( index
, *dc
, x
, y
, wxIMAGELIST_DRAW_TRANSPARENT
);
1611 if ((m_mode
& wxLC_SMALL_ICON
) && (m_small_image_list
))
1613 m_small_image_list
->Draw( index
, *dc
, x
, y
, wxIMAGELIST_DRAW_TRANSPARENT
);
1615 if ((m_mode
& wxLC_REPORT
) && (m_small_image_list
))
1617 m_small_image_list
->Draw( index
, *dc
, x
, y
, wxIMAGELIST_DRAW_TRANSPARENT
);
1622 void wxListMainWindow::GetImageSize( int index
, int &width
, int &height
)
1624 if ((m_mode
& wxLC_ICON
) && (m_normal_image_list
))
1626 m_normal_image_list
->GetSize( index
, width
, height
);
1629 if ((m_mode
& wxLC_SMALL_ICON
) && (m_small_image_list
))
1631 m_small_image_list
->GetSize( index
, width
, height
);
1634 if ((m_mode
& wxLC_REPORT
) && (m_small_image_list
))
1636 m_small_image_list
->GetSize( index
, width
, height
);
1643 int wxListMainWindow::GetTextLength( wxString
&s
)
1645 wxClientDC
dc( this );
1648 dc
.GetTextExtent( s
, &lw
, &lh
);
1652 int wxListMainWindow::GetIndexOfLine( const wxListLineData
*line
)
1655 wxNode
*node
= m_lines
.First();
1658 if (line
== (wxListLineData
*)node
->Data()) return i
;
1660 node
= node
->Next();
1665 void wxListMainWindow::SetImageList( wxImageList
*imageList
, int which
)
1668 if (which
== wxIMAGE_LIST_NORMAL
) m_normal_image_list
= imageList
;
1669 if (which
== wxIMAGE_LIST_SMALL
) m_small_image_list
= imageList
;
1672 void wxListMainWindow::SetItemSpacing( int spacing
, bool isSmall
)
1677 m_small_spacing
= spacing
;
1681 m_normal_spacing
= spacing
;
1685 int wxListMainWindow::GetItemSpacing( bool isSmall
)
1687 if (isSmall
) return m_small_spacing
; else return m_normal_spacing
;
1690 void wxListMainWindow::SetColumn( int col
, wxListItem
&item
)
1693 wxNode
*node
= m_columns
.Nth( col
);
1696 if (item
.m_width
== wxLIST_AUTOSIZE_USEHEADER
) item
.m_width
= GetTextLength( item
.m_text
)+7;
1697 wxListHeaderData
*column
= (wxListHeaderData
*)node
->Data();
1698 column
->SetItem( item
);
1700 wxListCtrl
*lc
= (wxListCtrl
*) GetParent();
1701 if (lc
->m_headerWin
) lc
->m_headerWin
->Refresh();
1704 void wxListMainWindow::SetColumnWidth( int col
, int width
)
1706 if (!(m_mode
& wxLC_REPORT
)) return;
1710 wxNode
*node
= (wxNode
*) NULL
;
1712 if (width
== wxLIST_AUTOSIZE_USEHEADER
) width
= 80;
1713 if (width
== wxLIST_AUTOSIZE
)
1715 wxClientDC
dc(this);
1716 dc
.SetFont( GetFont() );
1718 node
= m_lines
.First();
1721 wxListLineData
*line
= (wxListLineData
*)node
->Data();
1722 wxNode
*n
= line
->m_items
.Nth( col
);
1725 wxListItemData
*item
= (wxListItemData
*)n
->Data();
1726 int current
= 0, ix
= 0, iy
= 0;
1727 long lx
= 0, ly
= 0;
1728 if (item
->HasImage())
1730 GetImageSize( item
->GetImage(), ix
, iy
);
1733 if (item
->HasText())
1736 item
->GetText( str
);
1737 dc
.GetTextExtent( str
, &lx
, &ly
);
1740 if (current
> max
) max
= current
;
1742 node
= node
->Next();
1747 node
= m_columns
.Nth( col
);
1750 wxListHeaderData
*column
= (wxListHeaderData
*)node
->Data();
1751 column
->SetWidth( width
);
1754 node
= m_lines
.First();
1757 wxListLineData
*line
= (wxListLineData
*)node
->Data();
1758 wxNode
*n
= line
->m_items
.Nth( col
);
1761 wxListItemData
*item
= (wxListItemData
*)n
->Data();
1762 item
->SetSize( width
, -1 );
1764 node
= node
->Next();
1767 wxListCtrl
*lc
= (wxListCtrl
*) GetParent();
1768 if (lc
->m_headerWin
) lc
->m_headerWin
->Refresh();
1771 void wxListMainWindow::GetColumn( int col
, wxListItem
&item
)
1773 wxNode
*node
= m_columns
.Nth( col
);
1776 wxListHeaderData
*column
= (wxListHeaderData
*)node
->Data();
1777 column
->GetItem( item
);
1789 int wxListMainWindow::GetColumnWidth( int col
)
1791 wxNode
*node
= m_columns
.Nth( col
);
1794 wxListHeaderData
*column
= (wxListHeaderData
*)node
->Data();
1795 return column
->GetWidth();
1803 int wxListMainWindow::GetColumnCount()
1805 return m_columns
.Number();
1808 int wxListMainWindow::GetCountPerPage()
1810 return m_visibleLines
;
1813 void wxListMainWindow::SetItem( wxListItem
&item
)
1816 wxNode
*node
= m_lines
.Nth( item
.m_itemId
);
1819 wxListLineData
*line
= (wxListLineData
*)node
->Data();
1820 if (m_mode
& wxLC_REPORT
) item
.m_width
= GetColumnWidth( item
.m_col
)-3;
1821 line
->SetItem( item
.m_col
, item
);
1825 void wxListMainWindow::SetItemState( long item
, long state
, long stateMask
)
1827 // m_dirty = TRUE; no recalcs needed
1829 wxListLineData
*oldCurrent
= m_current
;
1831 if (stateMask
& wxLIST_STATE_FOCUSED
)
1833 wxNode
*node
= m_lines
.Nth( item
);
1836 wxListLineData
*line
= (wxListLineData
*)node
->Data();
1837 UnfocusLine( m_current
);
1839 FocusLine( m_current
);
1840 RefreshLine( m_current
);
1841 if (oldCurrent
) RefreshLine( oldCurrent
);
1845 if (stateMask
& wxLIST_STATE_SELECTED
)
1847 bool on
= state
& wxLIST_STATE_SELECTED
;
1848 if (!on
&& (m_mode
& wxLC_SINGLE_SEL
)) return;
1850 wxNode
*node
= m_lines
.Nth( item
);
1853 wxListLineData
*line
= (wxListLineData
*)node
->Data();
1854 if (m_mode
& wxLC_SINGLE_SEL
)
1856 UnfocusLine( m_current
);
1858 FocusLine( m_current
);
1859 if (oldCurrent
) oldCurrent
->Hilight( FALSE
);
1860 RefreshLine( m_current
);
1861 if (oldCurrent
) RefreshLine( oldCurrent
);
1863 bool on
= state
& wxLIST_STATE_SELECTED
;
1864 if (on
!= line
->IsHilighted())
1866 line
->Hilight( on
);
1867 RefreshLine( line
);
1873 int wxListMainWindow::GetItemState( long item
, long stateMask
)
1875 int ret
= wxLIST_STATE_DONTCARE
;
1876 if (stateMask
& wxLIST_STATE_FOCUSED
)
1878 wxNode
*node
= m_lines
.Nth( item
);
1881 wxListLineData
*line
= (wxListLineData
*)node
->Data();
1882 if (line
== m_current
) ret
|= wxLIST_STATE_FOCUSED
;
1885 if (stateMask
& wxLIST_STATE_SELECTED
)
1887 wxNode
*node
= m_lines
.Nth( item
);
1890 wxListLineData
*line
= (wxListLineData
*)node
->Data();
1891 if (line
->IsHilighted()) ret
|= wxLIST_STATE_FOCUSED
;
1897 void wxListMainWindow::GetItem( wxListItem
&item
)
1899 wxNode
*node
= m_lines
.Nth( item
.m_itemId
);
1902 wxListLineData
*line
= (wxListLineData
*)node
->Data();
1903 line
->GetItem( item
.m_col
, item
);
1914 int wxListMainWindow::GetItemCount()
1916 return m_lines
.Number();
1919 void wxListMainWindow::GetItemRect( long index
, wxRect
&rect
)
1921 wxNode
*node
= m_lines
.Nth( index
);
1924 wxListLineData
*line
= (wxListLineData
*)node
->Data();
1925 line
->GetRect( rect
);
1936 bool wxListMainWindow::GetItemPosition(long item
, wxPoint
& pos
)
1938 wxNode
*node
= m_lines
.Nth( item
);
1942 wxListLineData
*line
= (wxListLineData
*)node
->Data();
1943 line
->GetRect( rect
);
1955 int wxListMainWindow::GetSelectedItemCount()
1958 wxNode
*node
= m_lines
.First();
1961 wxListLineData
*line
= (wxListLineData
*)node
->Data();
1962 if (line
->IsHilighted()) ret
++;
1963 node
= node
->Next();
1968 void wxListMainWindow::SetMode( long mode
)
1975 if (m_mode
& wxLC_REPORT
)
1987 long wxListMainWindow::GetMode() const
1992 void wxListMainWindow::CalculatePositions()
1994 if (!m_lines
.First()) return;
1996 wxClientDC
dc( this );
1997 dc
.SetFont( GetFont() );
1999 int iconSpacing
= 0;
2000 if (m_mode
& wxLC_ICON
) iconSpacing
= m_normal_spacing
;
2001 if (m_mode
& wxLC_SMALL_ICON
) iconSpacing
= m_small_spacing
;
2003 // we take the first line (which also can be an icon or
2004 // an a text item in wxLC_ICON and wxLC_LIST modes) to
2005 // measure the size of the line
2009 int lineSpacing
= 0;
2011 wxListLineData
*line
= (wxListLineData
*)m_lines
.First()->Data();
2012 line
->CalculateSize( &dc
, iconSpacing
);
2014 line
->GetSize( dummy
, lineSpacing
);
2017 int clientWidth
= 0;
2018 int clientHeight
= 0;
2020 if (m_mode
& wxLC_REPORT
)
2024 int entireHeight
= m_lines
.Number() * lineSpacing
+ 2;
2025 int scroll_pos
= GetScrollPos( wxVERTICAL
);
2026 SetScrollbars( m_xScroll
, m_yScroll
, 0, (entireHeight
+15) / m_yScroll
, 0, scroll_pos
, TRUE
);
2027 GetClientSize( &clientWidth
, &clientHeight
);
2029 wxNode
* node
= m_lines
.First();
2032 wxListLineData
*line
= (wxListLineData
*)node
->Data();
2033 line
->CalculateSize( &dc
, iconSpacing
);
2034 line
->SetPosition( &dc
, x
, y
, clientWidth
);
2036 for (int i
= 0; i
< GetColumnCount(); i
++)
2038 line
->SetColumnPosition( i
, col_x
);
2039 col_x
+= GetColumnWidth( i
);
2041 y
+= lineSpacing
; // one pixel blank line between items
2042 node
= node
->Next();
2044 m_visibleLines
= clientHeight
/ lineSpacing
;
2048 // at first we try without any scrollbar. if the items don't
2049 // fit into the window, we recalculate after subtracting an
2050 // approximated 15 pt for the horizontal scrollbar
2052 GetSize( &clientWidth
, &clientHeight
);
2053 clientHeight
-= 4; // sunken frame
2055 int entireWidth
= 0;
2057 for (int tries
= 0; tries
< 2; tries
++)
2060 int x
= 5; // painting is done at x-2
2061 int y
= 5; // painting is done at y-2
2063 wxNode
*node
= m_lines
.First();
2066 wxListLineData
*line
= (wxListLineData
*)node
->Data();
2067 line
->CalculateSize( &dc
, iconSpacing
);
2068 line
->SetPosition( &dc
, x
, y
, clientWidth
);
2069 line
->GetSize( lineWidth
, lineHeight
);
2070 if (lineWidth
> maxWidth
) maxWidth
= lineWidth
;
2072 if (y
+lineSpacing
-6 >= clientHeight
) // -6 for earlier "line breaking"
2076 entireWidth
+= maxWidth
+6;
2079 node
= node
->Next();
2080 if (!node
) entireWidth
+= maxWidth
;
2081 if ((tries
== 0) && (entireWidth
> clientWidth
))
2083 clientHeight
-= 15; // scrollbar height
2086 if (!node
) tries
= 1; // everything fits, no second try required
2089 m_visibleLines
= (clientHeight
+6) / (lineSpacing
); // +6 for earlier "line breaking"
2091 int scroll_pos
= GetScrollPos( wxHORIZONTAL
);
2092 SetScrollbars( m_xScroll
, m_yScroll
, (entireWidth
+15) / m_xScroll
, 0, scroll_pos
, 0, TRUE
);
2096 void wxListMainWindow::RealizeChanges( void )
2100 wxNode
*node
= m_lines
.First();
2101 if (node
) m_current
= (wxListLineData
*)node
->Data();
2105 FocusLine( m_current
);
2106 if (m_mode
& wxLC_SINGLE_SEL
) m_current
->Hilight( TRUE
);
2110 long wxListMainWindow::GetNextItem( long item
, int WXUNUSED(geometry
), int state
)
2113 if (item
> 0) ret
= item
;
2114 if(ret
>= GetItemCount()) return -1;
2115 wxNode
*node
= m_lines
.Nth( ret
);
2118 wxListLineData
*line
= (wxListLineData
*)node
->Data();
2119 if ((state
& wxLIST_STATE_FOCUSED
) && (line
== m_current
)) return ret
;
2120 if ((state
& wxLIST_STATE_SELECTED
) && (line
->IsHilighted())) return ret
;
2121 if (!state
) return ret
;
2123 node
= node
->Next();
2128 void wxListMainWindow::DeleteItem( long index
)
2131 wxNode
*node
= m_lines
.Nth( index
);
2134 wxListLineData
*line
= (wxListLineData
*)node
->Data();
2135 if (m_current
== line
) m_current
= (wxListLineData
*) NULL
;
2137 m_lines
.DeleteNode( node
);
2141 void wxListMainWindow::DeleteColumn( int col
)
2143 wxCHECK_RET( col
< (int)m_columns
.GetCount(),
2144 _T("attempting to delete inexistent column in wxListView") );
2147 wxNode
*node
= m_columns
.Nth( col
);
2148 if (node
) m_columns
.DeleteNode( node
);
2151 void wxListMainWindow::DeleteAllItems( void )
2154 m_current
= (wxListLineData
*) NULL
;
2155 wxNode
*node
= m_lines
.First();
2158 wxListLineData
*line
= (wxListLineData
*)node
->Data();
2160 node
= node
->Next();
2165 void wxListMainWindow::DeleteEverything( void )
2168 m_current
= (wxListLineData
*) NULL
;
2169 wxNode
*node
= m_lines
.First();
2172 wxListLineData
*line
= (wxListLineData
*)node
->Data();
2174 node
= node
->Next();
2177 m_current
= (wxListLineData
*) NULL
;
2181 void wxListMainWindow::EnsureVisible( long index
)
2183 wxListLineData
*oldCurrent
= m_current
;
2184 m_current
= (wxListLineData
*) NULL
;
2186 wxNode
*node
= m_lines
.Nth( i
);
2187 if (node
) m_current
= (wxListLineData
*)node
->Data();
2188 if (m_current
) MoveToFocus();
2189 m_current
= oldCurrent
;
2192 long wxListMainWindow::FindItem(long start
, const wxString
& str
, bool WXUNUSED(partial
) )
2196 if (pos
< 0) pos
= 0;
2197 wxNode
*node
= m_lines
.Nth( pos
);
2200 wxListLineData
*line
= (wxListLineData
*)node
->Data();
2202 line
->GetText( 0, s
);
2203 if (s
== tmp
) return pos
;
2204 node
= node
->Next();
2210 long wxListMainWindow::FindItem(long start
, long data
)
2213 if (pos
< 0) pos
= 0;
2214 wxNode
*node
= m_lines
.Nth( pos
);
2217 wxListLineData
*line
= (wxListLineData
*)node
->Data();
2219 line
->GetItem( 0, item
);
2220 if (item
.m_data
== data
) return pos
;
2221 node
= node
->Next();
2227 long wxListMainWindow::HitTest( int x
, int y
, int &flags
)
2229 wxNode
*node
= m_lines
.First();
2233 wxListLineData
*line
= (wxListLineData
*)node
->Data();
2234 long ret
= line
->IsHit( x
, y
);
2240 node
= node
->Next();
2246 void wxListMainWindow::InsertItem( wxListItem
&item
)
2250 if (m_mode
& wxLC_REPORT
) mode
= wxLC_REPORT
;
2251 else if (m_mode
& wxLC_LIST
) mode
= wxLC_LIST
;
2252 else if (m_mode
& wxLC_ICON
) mode
= wxLC_ICON
;
2253 else if (m_mode
& wxLC_SMALL_ICON
) mode
= wxLC_ICON
; // no typo
2255 wxListLineData
*line
= new wxListLineData( this, mode
, m_hilightBrush
);
2257 if (m_mode
& wxLC_REPORT
)
2259 line
->InitItems( GetColumnCount() );
2260 item
.m_width
= GetColumnWidth( 0 )-3;
2264 line
->InitItems( 1 );
2267 line
->SetItem( 0, item
);
2268 if ((item
.m_itemId
>= 0) && (item
.m_itemId
< (int)m_lines
.GetCount()))
2270 wxNode
*node
= m_lines
.Nth( item
.m_itemId
);
2271 if (node
) m_lines
.Insert( node
, line
);
2275 m_lines
.Append( line
);
2279 void wxListMainWindow::InsertColumn( long col
, wxListItem
&item
)
2282 if (m_mode
& wxLC_REPORT
)
2284 if (item
.m_width
== wxLIST_AUTOSIZE_USEHEADER
) item
.m_width
= GetTextLength( item
.m_text
);
2285 wxListHeaderData
*column
= new wxListHeaderData( item
);
2286 if ((col
>= 0) && (col
< (int)m_columns
.GetCount()))
2288 wxNode
*node
= m_columns
.Nth( col
);
2290 m_columns
.Insert( node
, column
);
2294 m_columns
.Append( column
);
2299 wxListCtrlCompare list_ctrl_compare_func_2
;
2300 long list_ctrl_compare_data
;
2302 int list_ctrl_compare_func_1( const void *arg1
, const void *arg2
)
2304 wxListLineData
*line1
= *((wxListLineData
**)arg1
);
2305 wxListLineData
*line2
= *((wxListLineData
**)arg2
);
2307 line1
->GetItem( 0, item
);
2308 long data1
= item
.m_data
;
2309 line2
->GetItem( 0, item
);
2310 long data2
= item
.m_data
;
2311 return list_ctrl_compare_func_2( data1
, data2
, list_ctrl_compare_data
);
2314 void wxListMainWindow::SortItems( wxListCtrlCompare fn
, long data
)
2316 list_ctrl_compare_func_2
= fn
;
2317 list_ctrl_compare_data
= data
;
2318 m_lines
.Sort( list_ctrl_compare_func_1
);
2321 // -------------------------------------------------------------------------------------
2323 // -------------------------------------------------------------------------------------
2325 IMPLEMENT_DYNAMIC_CLASS(wxListItem
, wxObject
)
2327 wxListItem::wxListItem(void)
2336 m_format
= wxLIST_FORMAT_CENTRE
;
2341 // -------------------------------------------------------------------------------------
2343 // -------------------------------------------------------------------------------------
2345 IMPLEMENT_DYNAMIC_CLASS(wxListEvent
, wxNotifyEvent
)
2347 wxListEvent::wxListEvent( wxEventType commandType
, int id
):
2348 wxNotifyEvent( commandType
, id
)
2354 m_cancelled
= FALSE
;
2359 // -------------------------------------------------------------------------------------
2361 // -------------------------------------------------------------------------------------
2363 IMPLEMENT_DYNAMIC_CLASS(wxListCtrl
, wxControl
)
2365 BEGIN_EVENT_TABLE(wxListCtrl
,wxControl
)
2366 EVT_SIZE (wxListCtrl::OnSize
)
2367 EVT_IDLE (wxListCtrl::OnIdle
)
2370 wxListCtrl::wxListCtrl(void)
2372 m_imageListNormal
= (wxImageList
*) NULL
;
2373 m_imageListSmall
= (wxImageList
*) NULL
;
2374 m_imageListState
= (wxImageList
*) NULL
;
2375 m_mainWin
= (wxListMainWindow
*) NULL
;
2376 m_headerWin
= (wxListHeaderWindow
*) NULL
;
2379 wxListCtrl::~wxListCtrl(void)
2383 bool wxListCtrl::Create( wxWindow
*parent
, wxWindowID id
,
2384 const wxPoint
&pos
, const wxSize
&size
,
2385 long style
, const wxValidator
&validator
,
2386 const wxString
&name
)
2388 m_imageListNormal
= (wxImageList
*) NULL
;
2389 m_imageListSmall
= (wxImageList
*) NULL
;
2390 m_imageListState
= (wxImageList
*) NULL
;
2391 m_mainWin
= (wxListMainWindow
*) NULL
;
2392 m_headerWin
= (wxListHeaderWindow
*) NULL
;
2396 if ((s
& wxLC_REPORT
== 0) &&
2397 (s
& wxLC_LIST
== 0) &&
2398 (s
& wxLC_ICON
== 0))
2403 bool ret
= wxControl::Create( parent
, id
, pos
, size
, s
, name
);
2405 #if wxUSE_VALIDATORS
2406 SetValidator( validator
);
2409 if (s
& wxSUNKEN_BORDER
) s
-= wxSUNKEN_BORDER
;
2411 m_mainWin
= new wxListMainWindow( this, -1, wxPoint(0,0), size
, s
);
2413 if (HasFlag(wxLC_REPORT
))
2414 m_headerWin
= new wxListHeaderWindow( this, -1, m_mainWin
, wxPoint(0,0), wxSize(size
.x
,23), wxTAB_TRAVERSAL
);
2416 m_headerWin
= (wxListHeaderWindow
*) NULL
;
2418 SetBackgroundColour( *wxWHITE
);
2423 void wxListCtrl::OnSize( wxSizeEvent
&WXUNUSED(event
) )
2425 /* handled in OnIdle */
2427 if (m_mainWin
) m_mainWin
->m_dirty
= TRUE
;
2430 void wxListCtrl::SetSingleStyle( long style
, bool add
)
2432 long flag
= GetWindowStyle();
2436 if (style
& wxLC_MASK_TYPE
) flag
= flag
& ~wxLC_MASK_TYPE
;
2437 if (style
& wxLC_MASK_ALIGN
) flag
= flag
& ~wxLC_MASK_ALIGN
;
2438 if (style
& wxLC_MASK_SORT
) flag
= flag
& ~wxLC_MASK_SORT
;
2447 if (flag
& style
) flag
-= style
;
2450 SetWindowStyleFlag( flag
);
2453 void wxListCtrl::SetWindowStyleFlag( long flag
)
2457 m_mainWin
->DeleteEverything();
2461 GetClientSize( &width
, &height
);
2463 m_mainWin
->SetMode( flag
);
2465 if (flag
& wxLC_REPORT
)
2467 if (!HasFlag(wxLC_REPORT
))
2471 m_headerWin
= new wxListHeaderWindow( this, -1, m_mainWin
,
2472 wxPoint(0,0), wxSize(width
,23), wxTAB_TRAVERSAL
);
2476 m_headerWin
->Show( TRUE
);
2482 if (HasFlag(wxLC_REPORT
))
2484 m_headerWin
->Show( FALSE
);
2489 wxWindow::SetWindowStyleFlag( flag
);
2492 bool wxListCtrl::GetColumn(int col
, wxListItem
&item
) const
2494 m_mainWin
->GetColumn( col
, item
);
2498 bool wxListCtrl::SetColumn( int col
, wxListItem
& item
)
2500 m_mainWin
->SetColumn( col
, item
);
2504 int wxListCtrl::GetColumnWidth( int col
) const
2506 return m_mainWin
->GetColumnWidth( col
);
2509 bool wxListCtrl::SetColumnWidth( int col
, int width
)
2511 m_mainWin
->SetColumnWidth( col
, width
);
2515 int wxListCtrl::GetCountPerPage(void) const
2517 return m_mainWin
->GetCountPerPage(); // different from Windows ?
2520 bool wxListCtrl::GetItem( wxListItem
&info
) const
2522 m_mainWin
->GetItem( info
);
2526 bool wxListCtrl::SetItem( wxListItem
&info
)
2528 m_mainWin
->SetItem( info
);
2532 long wxListCtrl::SetItem( long index
, int col
, const wxString
& label
, int imageId
)
2535 info
.m_text
= label
;
2536 info
.m_mask
= wxLIST_MASK_TEXT
;
2537 info
.m_itemId
= index
;
2541 info
.m_image
= imageId
;
2542 info
.m_mask
|= wxLIST_MASK_IMAGE
;
2544 m_mainWin
->SetItem(info
);
2548 int wxListCtrl::GetItemState( long item
, long stateMask
) const
2550 return m_mainWin
->GetItemState( item
, stateMask
);
2553 bool wxListCtrl::SetItemState( long item
, long state
, long stateMask
)
2555 m_mainWin
->SetItemState( item
, state
, stateMask
);
2559 bool wxListCtrl::SetItemImage( long item
, int image
, int WXUNUSED(selImage
) )
2562 info
.m_image
= image
;
2563 info
.m_mask
= wxLIST_MASK_IMAGE
;
2564 info
.m_itemId
= item
;
2565 m_mainWin
->SetItem( info
);
2569 wxString
wxListCtrl::GetItemText( long item
) const
2572 info
.m_itemId
= item
;
2573 m_mainWin
->GetItem( info
);
2577 void wxListCtrl::SetItemText( long item
, const wxString
&str
)
2580 info
.m_mask
= wxLIST_MASK_TEXT
;
2581 info
.m_itemId
= item
;
2583 m_mainWin
->SetItem( info
);
2586 long wxListCtrl::GetItemData( long item
) const
2589 info
.m_itemId
= item
;
2590 m_mainWin
->GetItem( info
);
2594 bool wxListCtrl::SetItemData( long item
, long data
)
2597 info
.m_mask
= wxLIST_MASK_DATA
;
2598 info
.m_itemId
= item
;
2600 m_mainWin
->SetItem( info
);
2604 bool wxListCtrl::GetItemRect( long item
, wxRect
&rect
, int WXUNUSED(code
) ) const
2606 m_mainWin
->GetItemRect( item
, rect
);
2610 bool wxListCtrl::GetItemPosition( long item
, wxPoint
& pos
) const
2612 m_mainWin
->GetItemPosition( item
, pos
);
2616 bool wxListCtrl::SetItemPosition( long WXUNUSED(item
), const wxPoint
& WXUNUSED(pos
) )
2621 int wxListCtrl::GetItemCount(void) const
2623 return m_mainWin
->GetItemCount();
2626 int wxListCtrl::GetColumnCount(void) const
2628 return m_mainWin
->GetColumnCount();
2631 void wxListCtrl::SetItemSpacing( int spacing
, bool isSmall
)
2633 m_mainWin
->SetItemSpacing( spacing
, isSmall
);
2636 int wxListCtrl::GetItemSpacing( bool isSmall
) const
2638 return m_mainWin
->GetItemSpacing( isSmall
);
2641 int wxListCtrl::GetSelectedItemCount(void) const
2643 return m_mainWin
->GetSelectedItemCount();
2647 wxColour wxListCtrl::GetTextColour(void) const
2651 void wxListCtrl::SetTextColour(const wxColour& WXUNUSED(col))
2656 long wxListCtrl::GetTopItem(void) const
2661 long wxListCtrl::GetNextItem( long item
, int geom
, int state
) const
2663 return m_mainWin
->GetNextItem( item
, geom
, state
);
2666 wxImageList
*wxListCtrl::GetImageList(int which
) const
2668 if (which
== wxIMAGE_LIST_NORMAL
)
2670 return m_imageListNormal
;
2672 else if (which
== wxIMAGE_LIST_SMALL
)
2674 return m_imageListSmall
;
2676 else if (which
== wxIMAGE_LIST_STATE
)
2678 return m_imageListState
;
2680 return (wxImageList
*) NULL
;
2683 void wxListCtrl::SetImageList( wxImageList
*imageList
, int which
)
2685 m_mainWin
->SetImageList( imageList
, which
);
2688 bool wxListCtrl::Arrange( int WXUNUSED(flag
) )
2693 bool wxListCtrl::DeleteItem( long item
)
2695 m_mainWin
->DeleteItem( item
);
2699 bool wxListCtrl::DeleteAllItems(void)
2701 m_mainWin
->DeleteAllItems();
2705 bool wxListCtrl::DeleteAllColumns()
2707 for ( size_t n
= 0; n
< m_mainWin
->m_columns
.GetCount(); n
++ )
2713 void wxListCtrl::ClearAll()
2715 m_mainWin
->DeleteEverything();
2718 bool wxListCtrl::DeleteColumn( int col
)
2720 m_mainWin
->DeleteColumn( col
);
2724 void wxListCtrl::Edit( long item
)
2726 m_mainWin
->Edit( item
);
2729 bool wxListCtrl::EnsureVisible( long item
)
2731 m_mainWin
->EnsureVisible( item
);
2735 long wxListCtrl::FindItem( long start
, const wxString
& str
, bool partial
)
2737 return m_mainWin
->FindItem( start
, str
, partial
);
2740 long wxListCtrl::FindItem( long start
, long data
)
2742 return m_mainWin
->FindItem( start
, data
);
2745 long wxListCtrl::FindItem( long WXUNUSED(start
), const wxPoint
& WXUNUSED(pt
),
2746 int WXUNUSED(direction
))
2751 long wxListCtrl::HitTest( const wxPoint
&point
, int &flags
)
2753 return m_mainWin
->HitTest( (int)point
.x
, (int)point
.y
, flags
);
2756 long wxListCtrl::InsertItem( wxListItem
& info
)
2758 m_mainWin
->InsertItem( info
);
2762 long wxListCtrl::InsertItem( long index
, const wxString
&label
)
2765 info
.m_text
= label
;
2766 info
.m_mask
= wxLIST_MASK_TEXT
;
2767 info
.m_itemId
= index
;
2768 return InsertItem( info
);
2771 long wxListCtrl::InsertItem( long index
, int imageIndex
)
2774 info
.m_mask
= wxLIST_MASK_IMAGE
;
2775 info
.m_image
= imageIndex
;
2776 info
.m_itemId
= index
;
2777 return InsertItem( info
);
2780 long wxListCtrl::InsertItem( long index
, const wxString
&label
, int imageIndex
)
2783 info
.m_text
= label
;
2784 info
.m_image
= imageIndex
;
2785 info
.m_mask
= wxLIST_MASK_TEXT
| wxLIST_MASK_IMAGE
;
2786 info
.m_itemId
= index
;
2787 return InsertItem( info
);
2790 long wxListCtrl::InsertColumn( long col
, wxListItem
&item
)
2792 m_mainWin
->InsertColumn( col
, item
);
2796 long wxListCtrl::InsertColumn( long col
, const wxString
&heading
,
2797 int format
, int width
)
2800 item
.m_mask
= wxLIST_MASK_TEXT
| wxLIST_MASK_FORMAT
;
2801 item
.m_text
= heading
;
2804 item
.m_mask
|= wxLIST_MASK_WIDTH
;
2805 item
.m_width
= width
;
2807 item
.m_format
= format
;
2809 return InsertColumn( col
, item
);
2812 bool wxListCtrl::ScrollList( int WXUNUSED(dx
), int WXUNUSED(dy
) )
2818 // fn is a function which takes 3 long arguments: item1, item2, data.
2819 // item1 is the long data associated with a first item (NOT the index).
2820 // item2 is the long data associated with a second item (NOT the index).
2821 // data is the same value as passed to SortItems.
2822 // The return value is a negative number if the first item should precede the second
2823 // item, a positive number of the second item should precede the first,
2824 // or zero if the two items are equivalent.
2825 // data is arbitrary data to be passed to the sort function.
2827 bool wxListCtrl::SortItems( wxListCtrlCompare fn
, long data
)
2829 m_mainWin
->SortItems( fn
, data
);
2833 void wxListCtrl::OnIdle( wxIdleEvent
&WXUNUSED(event
) )
2835 if (!m_mainWin
->m_dirty
) return;
2839 GetClientSize( &cw
, &ch
);
2846 if (HasFlag(wxLC_REPORT
))
2848 m_headerWin
->GetPosition( &x
, &y
);
2849 m_headerWin
->GetSize( &w
, &h
);
2850 if ((x
!= 0) || (y
!= 0) || (w
!= cw
) || (h
!= 23))
2851 m_headerWin
->SetSize( 0, 0, cw
, 23 );
2853 m_mainWin
->GetPosition( &x
, &y
);
2854 m_mainWin
->GetSize( &w
, &h
);
2855 if ((x
!= 0) || (y
!= 24) || (w
!= cw
) || (h
!= ch
-24))
2856 m_mainWin
->SetSize( 0, 24, cw
, ch
-24 );
2860 m_mainWin
->GetPosition( &x
, &y
);
2861 m_mainWin
->GetSize( &w
, &h
);
2862 if ((x
!= 0) || (y
!= 24) || (w
!= cw
) || (h
!= ch
))
2863 m_mainWin
->SetSize( 0, 0, cw
, ch
);
2866 m_mainWin
->CalculatePositions();
2867 m_mainWin
->RealizeChanges();
2868 m_mainWin
->m_dirty
= FALSE
;
2869 m_mainWin
->Refresh();
2872 bool wxListCtrl::SetBackgroundColour( const wxColour
&colour
)
2874 if ( !wxWindow::SetBackgroundColour( colour
) )
2879 m_mainWin
->SetBackgroundColour( colour
);
2880 m_mainWin
->m_dirty
= TRUE
;
2885 // m_headerWin->SetBackgroundColour( colour );
2891 bool wxListCtrl::SetForegroundColour( const wxColour
&colour
)
2893 if ( !wxWindow::SetForegroundColour( colour
) )
2898 m_mainWin
->SetForegroundColour( colour
);
2899 m_mainWin
->m_dirty
= TRUE
;
2904 m_headerWin
->SetForegroundColour( colour
);
2910 bool wxListCtrl::SetFont( const wxFont
&font
)
2912 if ( !wxWindow::SetFont( font
) )
2917 m_mainWin
->SetFont( font
);
2918 m_mainWin
->m_dirty
= TRUE
;
2923 m_headerWin
->SetFont( font
);