1 /////////////////////////////////////////////////////////////////////////////
4 // Author: Robert Roebling
6 // Copyright: (c) 1998 Robert Roebling
7 // Licence: wxWindows licence
8 /////////////////////////////////////////////////////////////////////////////
11 #pragma implementation "listctrl.h"
14 #include "wx/dcscreen.h"
16 #include "wx/listctrl.h"
18 //-----------------------------------------------------------------------------
20 //-----------------------------------------------------------------------------
22 IMPLEMENT_DYNAMIC_CLASS(wxListItemData
,wxObject
);
24 wxListItemData::wxListItemData(void)
35 wxListItemData::wxListItemData( const wxListItem
&info
)
39 m_colour
= info
.m_colour
;
43 void wxListItemData::SetItem( const wxListItem
&info
)
45 if (info
.m_mask
& wxLIST_MASK_TEXT
) m_text
= info
.m_text
;
46 if (info
.m_mask
& wxLIST_MASK_IMAGE
) m_image
= info
.m_image
;
47 if (info
.m_mask
& wxLIST_MASK_DATA
) m_data
= info
.m_data
;
48 m_colour
= info
.m_colour
;
51 m_width
= info
.m_width
;
55 void wxListItemData::SetText( const wxString
&s
)
60 void wxListItemData::SetImage( int image
)
65 void wxListItemData::SetData( long data
)
70 void wxListItemData::SetPosition( int x
, int y
)
76 void wxListItemData::SetSize( int const width
, int height
)
78 if (width
!= -1) m_width
= width
;
79 if (height
!= -1) m_height
= height
;
82 void wxListItemData::SetColour( wxColour
*col
)
87 bool wxListItemData::HasImage(void) const
89 return (m_image
>= 0);
92 bool wxListItemData::HasText(void) const
94 return (!m_text
.IsNull());
97 bool wxListItemData::IsHit( int x
, int y
) const
99 return ((x
>= m_xpos
) && (x
<= m_xpos
+m_width
) && (y
>= m_ypos
) && (y
<= m_ypos
+m_height
));
102 void wxListItemData::GetText( wxString
&s
)
107 int wxListItemData::GetX( void ) const
112 int wxListItemData::GetY( void ) const
117 int wxListItemData::GetWidth(void) const
122 int wxListItemData::GetHeight(void) const
127 int wxListItemData::GetImage(void) const
132 void wxListItemData::GetItem( wxListItem
&info
)
134 info
.m_text
= m_text
;
135 info
.m_image
= m_image
;
136 info
.m_data
= m_data
;
139 wxColour
*wxListItemData::GetColour(void)
144 //-----------------------------------------------------------------------------
146 //-----------------------------------------------------------------------------
148 IMPLEMENT_DYNAMIC_CLASS(wxListHeaderData
,wxObject
);
150 wxListHeaderData::wxListHeaderData(void)
161 wxListHeaderData::wxListHeaderData( const wxListItem
&item
)
169 void wxListHeaderData::SetItem( const wxListItem
&item
)
171 m_mask
= item
.m_mask
;
172 m_text
= item
.m_text
;
173 m_image
= item
.m_image
;
174 m_format
= item
.m_format
;
175 m_width
= item
.m_width
;
176 if (m_width
< 0) m_width
= 80;
177 if (m_width
< 6) m_width
= 6;
180 void wxListHeaderData::SetPosition( int x
, int y
)
186 void wxListHeaderData::SetHeight( int h
)
191 void wxListHeaderData::SetWidth( int w
)
194 if (m_width
< 0) m_width
= 80;
195 if (m_width
< 6) m_width
= 6;
198 void wxListHeaderData::SetFormat( int format
)
203 bool wxListHeaderData::HasImage(void) const
205 return (m_image
!= 0);
208 bool wxListHeaderData::HasText(void) const
210 return (m_text
.Length() > 0);
213 bool wxListHeaderData::IsHit( int x
, int y
) const
215 return ((x
>= m_xpos
) && (x
<= m_xpos
+m_width
) && (y
>= m_ypos
) && (y
<= m_ypos
+m_height
));
218 void wxListHeaderData::GetItem( wxListItem
&item
)
220 item
.m_mask
= m_mask
;
221 item
.m_text
= m_text
;
222 item
.m_image
= m_image
;
223 item
.m_format
= m_format
;
224 item
.m_width
= m_width
;
227 void wxListHeaderData::GetText( wxString
&s
)
232 int wxListHeaderData::GetImage(void) const
237 int wxListHeaderData::GetWidth(void) const
242 int wxListHeaderData::GetFormat(void) const
247 //-----------------------------------------------------------------------------
249 //-----------------------------------------------------------------------------
251 IMPLEMENT_DYNAMIC_CLASS(wxListLineData
,wxObject
);
253 wxListLineData::wxListLineData( wxListMainWindow
*owner
, int mode
, wxBrush
*hilightBrush
)
258 m_hilightBrush
= hilightBrush
;
259 m_items
.DeleteContents( TRUE
);
263 void wxListLineData::CalculateSize( wxPaintDC
*dc
, int spacing
)
270 m_bound_all
.width
= m_spacing
;
271 m_bound_all
.height
= m_spacing
+13;
272 wxNode
*node
= m_items
.First();
275 wxListItemData
*item
= (wxListItemData
*)node
->Data();
279 dc
->GetTextExtent( s
, &lw
, &lh
);
280 if (lw
> m_spacing
) m_bound_all
.width
= lw
;
286 wxNode
*node
= m_items
.First();
289 wxListItemData
*item
= (wxListItemData
*)node
->Data();
293 dc
->GetTextExtent( s
, &lw
, &lh
);
294 m_bound_all
.width
= lw
;
295 m_bound_all
.height
= lh
;
301 m_bound_all
.width
= 0;
302 m_bound_all
.height
= 0;
303 wxNode
*node
= m_items
.First();
306 wxListItemData
*item
= (wxListItemData
*)node
->Data();
309 if (s
.IsNull()) s
= "H";
311 dc
->GetTextExtent( s
, &lw
, &lh
);
312 item
->SetSize( item
->GetWidth(), lh
);
313 m_bound_all
.width
+= lw
;
314 m_bound_all
.height
= lh
;
322 void wxListLineData::SetPosition( wxPaintDC
*dc
, int x
, int y
, int window_width
)
330 AssignRect( m_bound_icon
, 0, 0, 0, 0 );
331 AssignRect( m_bound_label
, 0, 0, 0, 0 );
332 AssignRect( m_bound_hilight
, m_bound_all
);
333 wxNode
*node
= m_items
.First();
336 wxListItemData
*item
= (wxListItemData
*)node
->Data();
337 if (item
->HasImage())
339 wxListItemData
*item
= (wxListItemData
*)node
->Data();
342 m_owner
->GetImageSize( item
->GetImage(), w
, h
);
343 m_bound_icon
.x
= m_bound_all
.x
+ (m_spacing
/2) - (w
/2);
344 m_bound_icon
.y
= m_bound_all
.y
+ m_spacing
- h
- 5;
345 m_bound_icon
.width
= w
;
346 m_bound_icon
.height
= h
;
347 if (!item
->HasText())
349 AssignRect( m_bound_hilight
, m_bound_icon
);
350 m_bound_hilight
.x
-= 3;
351 m_bound_hilight
.y
-= 3;
352 m_bound_hilight
.width
+= 7;
353 m_bound_hilight
.height
+= 7;
361 dc
->GetTextExtent( s
, &lw
, &lh
);
362 if (m_bound_all
.width
> m_spacing
)
363 m_bound_label
.x
= m_bound_all
.x
;
365 m_bound_label
.x
= m_bound_all
.x
+ (m_spacing
/2) - lw
/2;
366 m_bound_label
.y
= m_bound_all
.y
+ m_bound_all
.height
- lh
;
367 m_bound_label
.width
= lw
;
368 m_bound_label
.height
= lh
;
369 AssignRect( m_bound_hilight
, m_bound_label
);
376 AssignRect( m_bound_label
, m_bound_all
);
377 AssignRect( m_bound_hilight
, m_bound_all
);
378 AssignRect( m_bound_icon
, 0, 0, 0, 0 );
384 dc
->GetTextExtent( "H", &lw
, &lh
);
385 m_bound_all
.height
= lh
;
386 m_bound_all
.width
= window_width
;
387 AssignRect( m_bound_label
, m_bound_all
);
388 AssignRect( m_bound_hilight
, m_bound_all
);
389 AssignRect( m_bound_icon
, 0, 0, 0, 0 );
390 m_bound_hilight
.width
= window_width
-10;
391 m_bound_label
.width
= window_width
-10;
397 void wxListLineData::SetColumnPosition( int index
, int x
)
400 wxNode
*node
= m_items
.Nth( i
);
403 wxListItemData
*item
= (wxListItemData
*)node
->Data();
404 item
->SetPosition( x
, m_bound_all
.y
);
408 void wxListLineData::GetSize( int &width
, int &height
)
410 width
= m_bound_all
.width
;
411 height
= m_bound_all
.height
;
414 void wxListLineData::GetExtent( int &x
, int &y
, int &width
, int &height
)
418 width
= m_bound_all
.width
;
419 height
= m_bound_all
.height
;
422 void wxListLineData::GetLabelExtent( int &x
, int &y
, int &width
, int &height
)
426 width
= m_bound_label
.width
;
427 height
= m_bound_label
.height
;
430 void wxListLineData::GetRect( wxRectangle
&rect
)
432 AssignRect( rect
, m_bound_all
);
435 long wxListLineData::IsHit( int x
, int y
)
437 wxNode
*node
= m_items
.First();
440 wxListItemData
*item
= (wxListItemData
*)node
->Data();
441 if (item
->HasImage() && IsInRect( x
, y
, m_bound_icon
)) return wxLIST_HITTEST_ONITEMICON
;
442 if (item
->HasText() && IsInRect( x
, y
, m_bound_label
)) return wxLIST_HITTEST_ONITEMLABEL
;
443 // if (!(item->HasImage() || item->HasText())) return 0;
445 // if there is no icon or text = empty
446 if (IsInRect( x
, y
, m_bound_all
)) return wxLIST_HITTEST_ONITEMICON
;
450 void wxListLineData::InitItems( int num
)
452 for (int i
= 0; i
< num
; i
++) m_items
.Append( new wxListItemData() );
455 void wxListLineData::SetItem( int index
, const wxListItem
&info
)
457 wxNode
*node
= m_items
.Nth( index
);
460 wxListItemData
*item
= (wxListItemData
*)node
->Data();
461 item
->SetItem( info
);
465 void wxListLineData::GetItem( int const index
, wxListItem
&info
)
468 wxNode
*node
= m_items
.Nth( i
);
471 wxListItemData
*item
= (wxListItemData
*)node
->Data();
472 item
->GetItem( info
);
476 void wxListLineData::GetText( int index
, wxString
&s
)
479 wxNode
*node
= m_items
.Nth( i
);
483 wxListItemData
*item
= (wxListItemData
*)node
->Data();
488 void wxListLineData::SetText( int index
, const wxString s
)
491 wxNode
*node
= m_items
.Nth( i
);
494 wxListItemData
*item
= (wxListItemData
*)node
->Data();
499 int wxListLineData::GetImage( int index
)
502 wxNode
*node
= m_items
.Nth( i
);
505 wxListItemData
*item
= (wxListItemData
*)node
->Data();
506 return item
->GetImage();
511 void wxListLineData::DoDraw( wxPaintDC
*dc
, bool hilight
, bool paintBG
)
513 long dev_x
= dc
->LogicalToDeviceX( m_bound_all
.x
-2 );
514 long dev_y
= dc
->LogicalToDeviceY( m_bound_all
.y
-2 );
515 long dev_w
= dc
->LogicalToDeviceXRel( m_bound_all
.width
+4 );
516 long dev_h
= dc
->LogicalToDeviceYRel( m_bound_all
.height
+4 );
517 if (!m_owner
->IsExposed( dev_x
, dev_y
, dev_w
, dev_h
) ) return;
523 dc
->SetBrush( m_hilightBrush
);
524 dc
->SetPen( wxTRANSPARENT_PEN
);
528 dc
->SetBrush( wxWHITE_BRUSH
);
529 dc
->SetPen( wxTRANSPARENT_PEN
);
531 dc
->DrawRectangle( m_bound_hilight
.x
-2, m_bound_hilight
.y
-2,
532 m_bound_hilight
.width
+4, m_bound_hilight
.height
+4 );
534 if (m_mode
== wxLC_REPORT
)
537 wxNode
*node
= m_items
.First();
540 wxListItemData
*item
= (wxListItemData
*)node
->Data();
541 dc
->SetClippingRegion( item
->GetX(), item
->GetY(), item
->GetWidth()-3, item
->GetHeight() );
542 int x
= item
->GetX();
543 if (item
->HasImage())
546 m_owner
->DrawImage( item
->GetImage(), dc
, x
, item
->GetY() );
547 m_owner
->GetImageSize( item
->GetImage(), x
, y
);
548 x
+= item
->GetX() + 5;
554 dc
->SetTextForeground( wxSystemSettings::GetSystemColour( wxSYS_COLOUR_HIGHLIGHTTEXT
) );
556 dc
->SetTextForeground( *item
->GetColour() );
557 dc
->DrawText( s
, x
, item
->GetY() );
559 dc
->DestroyClippingRegion();
565 wxNode
*node
= m_items
.First();
568 wxListItemData
*item
= (wxListItemData
*)node
->Data();
569 if (item
->HasImage())
571 m_owner
->DrawImage( item
->GetImage(), dc
, m_bound_icon
.x
, m_bound_icon
.y
);
578 dc
->SetTextForeground( wxSystemSettings::GetSystemColour( wxSYS_COLOUR_HIGHLIGHTTEXT
) );
580 dc
->SetTextForeground( * item
->GetColour() );
581 dc
->DrawText( s
, m_bound_label
.x
, m_bound_label
.y
);
587 void wxListLineData::Hilight( bool on
)
589 if (on
== m_hilighted
) return;
591 m_owner
->SelectLine( this );
593 m_owner
->DeselectLine( this );
597 void wxListLineData::ReverseHilight( void )
599 m_hilighted
= !m_hilighted
;
601 m_owner
->SelectLine( this );
603 m_owner
->DeselectLine( this );
606 void wxListLineData::DrawRubberBand( wxPaintDC
*dc
, bool on
)
610 dc
->SetPen( wxBLACK_PEN
);
611 dc
->SetBrush( wxTRANSPARENT_BRUSH
);
612 dc
->DrawRectangle( m_bound_hilight
.x
-2, m_bound_hilight
.y
-2,
613 m_bound_hilight
.width
+4, m_bound_hilight
.height
+4 );
617 void wxListLineData::Draw( wxPaintDC
*dc
)
619 DoDraw( dc
, m_hilighted
, m_hilighted
);
622 bool wxListLineData::IsInRect( int x
, int y
, const wxRectangle
&rect
)
624 return ((x
>= rect
.x
) && (x
<= rect
.x
+rect
.width
) && (y
>= rect
.y
) && (y
<= rect
.y
+rect
.height
));
627 bool wxListLineData::IsHilighted( void )
632 void wxListLineData::AssignRect( wxRectangle
&dest
, int x
, int y
, int width
, int height
)
637 dest
.height
= height
;
640 void wxListLineData::AssignRect( wxRectangle
&dest
, const wxRectangle
&source
)
644 dest
.width
= source
.width
;
645 dest
.height
= source
.height
;
648 //-----------------------------------------------------------------------------
649 // wxListHeaderWindow
650 //-----------------------------------------------------------------------------
652 IMPLEMENT_DYNAMIC_CLASS(wxListHeaderWindow
,wxWindow
);
654 BEGIN_EVENT_TABLE(wxListHeaderWindow
,wxWindow
)
655 EVT_PAINT (wxListHeaderWindow::OnPaint
)
656 EVT_MOUSE_EVENTS (wxListHeaderWindow::OnMouse
)
657 EVT_SET_FOCUS (wxListHeaderWindow::OnSetFocus
)
660 wxListHeaderWindow::wxListHeaderWindow( void )
662 m_owner
= (wxListMainWindow
*) NULL
;
663 m_currentCursor
= (wxCursor
*) NULL
;
664 m_resizeCursor
= (wxCursor
*) NULL
;
668 wxListHeaderWindow::wxListHeaderWindow( wxWindow
*win
, wxWindowID id
, wxListMainWindow
*owner
,
669 const wxPoint
&pos
, const wxSize
&size
,
670 long style
, const wxString
&name
) :
671 wxWindow( win
, id
, pos
, size
, style
, name
)
674 // m_currentCursor = wxSTANDARD_CURSOR;
675 m_currentCursor
= (wxCursor
*) NULL
;
676 m_resizeCursor
= new wxCursor( wxCURSOR_SIZEWE
);
680 void wxListHeaderWindow::DoDrawRect( wxPaintDC
*dc
, int x
, int y
, int w
, int h
)
682 const int m_corner
= 1;
684 dc
->SetBrush( *wxTRANSPARENT_BRUSH
);
686 dc
->SetPen( *wxBLACK_PEN
);
687 dc
->DrawLine( x
+w
-m_corner
+1, y
, x
+w
, y
+h
); // right (outer)
688 dc
->DrawRectangle( x
, y
+h
, w
, 1 ); // bottom (outer)
690 dc
->SetPen( *wxMEDIUM_GREY_PEN
);
691 dc
->DrawLine( x
+w
-m_corner
, y
, x
+w
-1, y
+h
); // right (inner)
692 dc
->DrawRectangle( x
+1, y
+h
-1, w
-2, 1 ); // bottom (inner)
694 dc
->SetPen( *wxWHITE_PEN
);
695 dc
->DrawRectangle( x
, y
, w
-m_corner
+1, 1 ); // top (outer)
696 // dc->DrawRectangle( x, y+1, w-m_corner, 1 ); // top (inner)
697 dc
->DrawRectangle( x
, y
, 1, h
); // left (outer)
698 // dc->DrawRectangle( x+1, y, 1, h-1 ); // left (inner)
701 void wxListHeaderWindow::OnPaint( wxPaintEvent
&WXUNUSED(event
) )
703 wxPaintDC
dc( this );
708 dc
.SetFont( *GetFont() );
714 GetClientSize( &w
, &h
);
716 dc
.SetTextForeground( *wxBLACK
);
717 if (m_foregroundColour
.Ok()) dc
.SetTextForeground( m_foregroundColour
);
721 int numColumns
= m_owner
->GetColumnCount();
723 for (int i
= 0; i
< numColumns
; i
++)
725 m_owner
->GetColumn( i
, item
);
726 int cw
= item
.m_width
-2;
727 if ((i
+1 == numColumns
) || (x
+item
.m_width
> w
-5)) cw
= w
-x
-1;
728 dc
.SetPen( *wxWHITE_PEN
);
730 DoDrawRect( &dc
, x
, y
, cw
, h
-2 );
731 dc
.SetClippingRegion( x
, y
, cw
-5, h
-4 );
732 dc
.DrawText( item
.m_text
, x
+4, y
+3 );
733 dc
.DestroyClippingRegion();
740 void wxListHeaderWindow::DrawCurrent()
744 int x2
= m_currentX
-1;
746 m_owner
->GetClientSize( (int*)NULL
, &y2
);
747 ClientToScreen( &x1
, &y1
);
748 m_owner
->ClientToScreen( &x2
, &y2
);
751 dc
.SetLogicalFunction( wxXOR
);
752 dc
.SetPen( wxPen( *wxBLACK
, 2, wxSOLID
) );
753 dc
.SetBrush( *wxTRANSPARENT_BRUSH
);
755 dc
.DrawLine( x1
, y1
, x2
, y2
);
757 dc
.SetLogicalFunction( wxCOPY
);
759 dc
.SetPen( wxNullPen
);
760 dc
.SetBrush( wxNullBrush
);
763 void wxListHeaderWindow::OnMouse( wxMouseEvent
&event
)
765 int x
= event
.GetX();
766 int y
= event
.GetY();
770 if (event
.ButtonUp())
772 // wxScreenDC::EndDrawingOnTop();
775 m_owner
->SetColumnWidth( m_column
, m_currentX
-m_minX
);
780 GetClientSize( &size_x
, (int*) NULL
);
784 m_currentX
= m_minX
+7;
785 if (m_currentX
> size_x
-7) m_currentX
= size_x
-7;
792 bool hit_border
= FALSE
;
794 for (int j
= 0; j
< m_owner
->GetColumnCount(); j
++)
796 xpos
+= m_owner
->GetColumnWidth( j
);
797 if ((abs(x
-xpos
) < 3) && (y
< 22))
806 if (event
.LeftDown() && hit_border
)
810 // wxScreenDC::StartDrawingOnTop( m_owner );
820 if (m_currentCursor
== wxSTANDARD_CURSOR
) SetCursor( m_resizeCursor
);
821 m_currentCursor
= m_resizeCursor
;
825 if (m_currentCursor
!= wxSTANDARD_CURSOR
) SetCursor( wxSTANDARD_CURSOR
);
826 m_currentCursor
= wxSTANDARD_CURSOR
;
831 void wxListHeaderWindow::OnSetFocus( wxFocusEvent
&WXUNUSED(event
) )
836 //-----------------------------------------------------------------------------
837 // wxListRenameTimer (internal)
838 //-----------------------------------------------------------------------------
840 wxListRenameTimer::wxListRenameTimer( wxListMainWindow
*owner
)
845 void wxListRenameTimer::Notify()
847 m_owner
->OnRenameTimer();
850 //-----------------------------------------------------------------------------
851 // wxListTextCtrl (internal)
852 //-----------------------------------------------------------------------------
854 IMPLEMENT_DYNAMIC_CLASS(wxListTextCtrl
,wxTextCtrl
);
856 BEGIN_EVENT_TABLE(wxListTextCtrl
,wxTextCtrl
)
857 EVT_CHAR (wxListTextCtrl::OnChar
)
858 EVT_KILL_FOCUS (wxListTextCtrl::OnKillFocus
)
861 wxListTextCtrl::wxListTextCtrl( wxWindow
*parent
, const wxWindowID id
,
862 bool *accept
, wxString
*res
, wxListMainWindow
*owner
,
863 const wxString
&value
, const wxPoint
&pos
, const wxSize
&size
,
864 int style
, const wxValidator
& validator
, const wxString
&name
) :
865 wxTextCtrl( parent
, id
, value
, pos
, size
, style
, validator
, name
)
872 void wxListTextCtrl::OnChar( wxKeyEvent
&event
)
874 if (event
.m_keyCode
== WXK_RETURN
)
877 (*m_res
) = GetValue();
878 m_owner
->OnRenameAccept();
883 if (event
.m_keyCode
== WXK_ESCAPE
)
894 void wxListTextCtrl::OnKillFocus( wxFocusEvent
&WXUNUSED(event
) )
903 //-----------------------------------------------------------------------------
905 //-----------------------------------------------------------------------------
907 IMPLEMENT_DYNAMIC_CLASS(wxListMainWindow
,wxScrolledWindow
);
909 BEGIN_EVENT_TABLE(wxListMainWindow
,wxScrolledWindow
)
910 EVT_PAINT (wxListMainWindow::OnPaint
)
911 EVT_SIZE (wxListMainWindow::OnSize
)
912 EVT_MOUSE_EVENTS (wxListMainWindow::OnMouse
)
913 EVT_CHAR (wxListMainWindow::OnChar
)
914 EVT_SET_FOCUS (wxListMainWindow::OnSetFocus
)
915 EVT_KILL_FOCUS (wxListMainWindow::OnKillFocus
)
918 wxListMainWindow::wxListMainWindow( void )
921 m_lines
.DeleteContents( TRUE
);
922 m_columns
.DeleteContents( TRUE
);
923 m_current
= (wxListLineData
*) NULL
;
925 m_hilightBrush
= (wxBrush
*) NULL
;
929 m_small_image_list
= (wxImageList
*) NULL
;
930 m_normal_image_list
= (wxImageList
*) NULL
;
931 m_small_spacing
= 30;
932 m_normal_spacing
= 40;
935 m_lastOnSame
= FALSE
;
936 m_renameTimer
= new wxListRenameTimer( this );
941 wxListMainWindow::wxListMainWindow( wxWindow
*parent
, wxWindowID id
,
942 const wxPoint
&pos
, const wxSize
&size
,
943 long style
, const wxString
&name
) :
944 wxScrolledWindow( parent
, id
, pos
, size
, style
, name
)
947 m_lines
.DeleteContents( TRUE
);
948 m_columns
.DeleteContents( TRUE
);
949 m_current
= (wxListLineData
*) NULL
;
952 m_hilightBrush
= new wxBrush( wxSystemSettings::GetSystemColour(wxSYS_COLOUR_HIGHLIGHT
), wxSOLID
);
953 m_small_image_list
= (wxImageList
*) NULL
;
954 m_normal_image_list
= (wxImageList
*) NULL
;
955 m_small_spacing
= 30;
956 m_normal_spacing
= 40;
957 // AllowDoubleClick( TRUE );
964 if (m_mode
& wxLC_REPORT
)
974 SetScrollbars( m_xScroll
, m_yScroll
, 0, 0, 0, 0 );
977 m_lastOnSame
= FALSE
;
978 m_renameTimer
= new wxListRenameTimer( this );
979 m_renameAccept
= FALSE
;
980 // m_text = new wxRawListTextCtrl( GetParent(), "", &m_renameAccept, &m_renameRes, this, 10, 10, 40, 10 );
981 // m_text->Show( FALSE );
983 SetBackgroundColour( *wxWHITE
);
986 wxListMainWindow::~wxListMainWindow( void )
988 if (m_hilightBrush
) delete m_hilightBrush
;
989 delete m_renameTimer
;
990 // if (m_hilightColour) delete m_hilightColour;
994 void wxListMainWindow::RefreshLine( wxListLineData
*line
)
1002 wxClientDC
dc(this);
1004 line
->GetExtent( x
, y
, w
, h
);
1006 dc
.LogicalToDeviceX(x
-3),
1007 dc
.LogicalToDeviceY(y
-3),
1008 dc
.LogicalToDeviceXRel(w
+6),
1009 dc
.LogicalToDeviceXRel(h
+6) );
1010 Refresh( TRUE
, &rect
);
1014 void wxListMainWindow::OnPaint( wxPaintEvent
&WXUNUSED(event
) )
1016 if (m_dirty
) return;
1018 wxPaintDC
dc( this );
1023 dc
.SetFont( *GetFont() );
1025 wxNode
*node
= m_lines
.First();
1028 wxListLineData
*line
= (wxListLineData
*)node
->Data();
1030 node
= node
->Next();
1032 if (m_current
) m_current
->DrawRubberBand( &dc
, m_hasFocus
);
1037 void wxListMainWindow::HilightAll( bool on
)
1039 wxNode
*node
= m_lines
.First();
1042 wxListLineData
*line
= (wxListLineData
*)node
->Data();
1043 if (line
->IsHilighted() != on
)
1045 line
->Hilight( on
);
1046 RefreshLine( line
);
1048 node
= node
->Next();
1052 void wxListMainWindow::ActivateLine( wxListLineData
*line
)
1054 if (!GetParent()) return;
1055 wxListEvent
le( wxEVT_COMMAND_LIST_KEY_DOWN
, GetParent()->GetId() );
1056 le
.SetEventObject( GetParent() );
1058 le
.m_itemIndex
= GetIndexOfLine( line
);
1060 line
->GetItem( 0, le
.m_item
);
1064 void wxListMainWindow::SendNotify( wxListLineData
*line
, wxEventType command
)
1066 if (!GetParent()) return;
1067 wxListEvent
le( command
, GetParent()->GetId() );
1068 le
.SetEventObject( GetParent() );
1070 le
.m_itemIndex
= GetIndexOfLine( line
);
1072 line
->GetItem( 0, le
.m_item
);
1076 void wxListMainWindow::FocusLine( wxListLineData
*WXUNUSED(line
) )
1078 // SendNotify( line, wxEVT_COMMAND_LIST_ITEM_FOCUSSED );
1081 void wxListMainWindow::UnfocusLine( wxListLineData
*WXUNUSED(line
) )
1083 // SendNotify( line, wxEVT_COMMAND_LIST_ITEM_UNFOCUSSED );
1086 void wxListMainWindow::SelectLine( wxListLineData
*line
)
1088 SendNotify( line
, wxEVT_COMMAND_LIST_ITEM_SELECTED
);
1091 void wxListMainWindow::DeselectLine( wxListLineData
*line
)
1093 SendNotify( line
, wxEVT_COMMAND_LIST_ITEM_DESELECTED
);
1096 void wxListMainWindow::DeleteLine( wxListLineData
*line
)
1098 SendNotify( line
, wxEVT_COMMAND_LIST_DELETE_ITEM
);
1101 void wxListMainWindow::StartLabelEdit( wxListLineData
*line
)
1103 SendNotify( line
, wxEVT_COMMAND_LIST_BEGIN_LABEL_EDIT
);
1106 void wxListMainWindow::RenameLine( wxListLineData
*line
, const wxString
&newName
)
1108 if (!GetParent()) return;
1110 wxListEvent
le( wxEVT_COMMAND_LIST_END_LABEL_EDIT
, GetParent()->GetId() );
1111 le
.SetEventObject( GetParent() );
1113 le
.m_itemIndex
= GetIndexOfLine( line
);
1115 line
->GetItem( 0, le
.m_item
);
1116 le
.m_item
.m_text
= newName
;
1120 void wxListMainWindow::OnRenameTimer()
1122 StartLabelEdit( m_current
);
1124 m_current
->GetText( 0, s
);
1129 m_current
->GetLabelExtent( x
, y
, w
, h
);
1131 wxClientDC
dc(this);
1133 x
= dc
.LogicalToDeviceX( x
);
1134 y
= dc
.LogicalToDeviceY( y
);
1136 wxListTextCtrl
*text
= new wxListTextCtrl(
1137 this, -1, &m_renameAccept
, &m_renameRes
, this, s
, wxPoint(x
-4,y
-4), wxSize(w
+11,h
+8) );
1140 m_text->SetSize( x+3, y+3, w+6, h+6 );
1141 m_text->SetValue( s );
1142 m_text->Show( TRUE );
1146 char *res = wxGetTextFromUser( _("Enter new name:"), "", s );
1151 RenameLine( m_current, s );
1156 void wxListMainWindow::OnRenameAccept()
1158 RenameLine( m_current
, m_renameRes
);
1161 void wxListMainWindow::OnMouse( wxMouseEvent
&event
)
1163 if (GetParent()->GetEventHandler()->ProcessEvent( event
)) return;
1165 if (!m_current
) return;
1166 if (m_dirty
) return;
1168 wxClientDC
dc(this);
1170 long x
= dc
.DeviceToLogicalX( (long)event
.GetX() );
1171 long y
= dc
.DeviceToLogicalY( (long)event
.GetY() );
1174 wxNode
*node
= m_lines
.First();
1175 wxListLineData
*line
= (wxListLineData
*) NULL
;
1178 line
= (wxListLineData
*)node
->Data();
1179 hitResult
= line
->IsHit( x
, y
);
1180 if (hitResult
) break;
1181 line
= (wxListLineData
*) NULL
;
1182 node
= node
->Next();
1185 if (!event
.Dragging())
1190 if (event
.Dragging() && (m_dragCount
> 3))
1193 wxListEvent
le( wxEVT_COMMAND_LIST_BEGIN_DRAG
, GetParent()->GetId() );
1194 le
.SetEventObject( this );
1203 if (event
.ButtonDClick())
1206 m_lastOnSame
= FALSE
;
1207 m_renameTimer
->Stop();
1208 ActivateLine( line
);
1212 if (event
.LeftUp() && m_lastOnSame
)
1215 if ((line
== m_current
) &&
1216 (hitResult
== wxLIST_HITTEST_ONITEMLABEL
) &&
1217 // (m_mode & wxLC_ICON) &&
1218 (m_mode
& wxLC_EDIT_LABELS
) )
1220 m_renameTimer
->Start( 100, TRUE
);
1222 m_lastOnSame
= FALSE
;
1226 if (event
.LeftDown())
1229 wxListLineData
*oldCurrent
= m_current
;
1230 if (m_mode
& wxLC_SINGLE_SEL
)
1233 HilightAll( FALSE
);
1234 m_current
->ReverseHilight();
1235 RefreshLine( m_current
);
1239 if (event
.ShiftDown())
1242 m_current
->ReverseHilight();
1243 RefreshLine( m_current
);
1245 else if (event
.ControlDown())
1248 int numOfCurrent
= -1;
1249 node
= m_lines
.First();
1252 wxListLineData
*test_line
= (wxListLineData
*)node
->Data();
1254 if (test_line
== oldCurrent
) break;
1255 node
= node
->Next();
1258 node
= m_lines
.First();
1261 wxListLineData
*test_line
= (wxListLineData
*)node
->Data();
1263 if (test_line
== line
) break;
1264 node
= node
->Next();
1267 if (numOfLine
< numOfCurrent
)
1268 { int i
= numOfLine
; numOfLine
= numOfCurrent
; numOfCurrent
= i
; }
1269 wxNode
*node
= m_lines
.Nth( numOfCurrent
);
1270 for (int i
= 0; i
<= numOfLine
-numOfCurrent
; i
++)
1272 wxListLineData
*test_line
= (wxListLineData
*)node
->Data();
1273 test_line
->Hilight(TRUE
);
1274 RefreshLine( test_line
);
1275 node
= node
->Next();
1281 HilightAll( FALSE
);
1282 m_current
->ReverseHilight();
1283 RefreshLine( m_current
);
1286 if (m_current
!= oldCurrent
)
1288 RefreshLine( oldCurrent
);
1289 UnfocusLine( oldCurrent
);
1290 FocusLine( m_current
);
1292 m_lastOnSame
= (m_current
== oldCurrent
);
1298 void wxListMainWindow::MoveToFocus( void )
1300 if (!m_current
) return;
1306 m_current->GetExtent( x, y, w, h );
1309 GetClientSize( &w_p, &h_p );
1310 if (m_mode & wxLC_REPORT)
1312 if (GetScrollPos( wxHORIZONTAL ) != 0) SetScrollPos( wxHORIZONTAL, 0);
1313 int y_s = m_yScroll*GetScrollPos( wxVERTICAL );
1314 if ((y > y_s) && (y+h < y_s+h_p)) return;
1315 if (y-y_s < 5) SetScrollPos( wxVERTICAL, (y-5)/m_yScroll );
1316 if (y+h+5 > y_s+h_p) SetScrollPos( wxVERTICAL, (y+h-h_p+h+5)/m_yScroll );
1320 if (GetScrollPos( wxVERTICAL ) != 0) SetScrollPos( wxVERTICAL, 0);
1321 int x_s = m_xScroll*GetScrollPos( wxHORIZONTAL );
1322 if ((x > x_s) && (x+w < x_s+w_p)) return;
1323 if (x-x_s < 5) SetScrollPos( wxHORIZONTAL, (x-5)/m_xScroll );
1324 if (x+w > x_s+w_p) SetScrollPos( wxHORIZONTAL, (x+w-w_p+5)/m_xScroll );
1329 void wxListMainWindow::OnArrowChar( wxListLineData
*newCurrent
, bool shiftDown
)
1331 if ((m_mode
& wxLC_SINGLE_SEL
) || (m_usedKeys
== FALSE
)) m_current
->Hilight( FALSE
);
1332 wxListLineData
*oldCurrent
= m_current
;
1333 m_current
= newCurrent
;
1335 if (shiftDown
|| (m_mode
& wxLC_SINGLE_SEL
)) m_current
->Hilight( TRUE
);
1336 RefreshLine( m_current
);
1337 RefreshLine( oldCurrent
);
1338 FocusLine( m_current
);
1339 UnfocusLine( oldCurrent
);
1342 void wxListMainWindow::OnChar( wxKeyEvent
&event
)
1345 if (event.KeyCode() == WXK_TAB)
1347 if (event.ShiftDown())
1354 if (!m_current
) return;
1355 switch (event
.KeyCode())
1359 wxNode
*node
= m_lines
.Member( m_current
)->Previous();
1360 if (node
) OnArrowChar( (wxListLineData
*)node
->Data(), event
.ShiftDown() );
1365 wxNode
*node
= m_lines
.Member( m_current
)->Next();
1366 if (node
) OnArrowChar( (wxListLineData
*)node
->Data(), event
.ShiftDown() );
1371 wxNode
*node
= m_lines
.Last();
1372 OnArrowChar( (wxListLineData
*)node
->Data(), event
.ShiftDown() );
1377 wxNode
*node
= m_lines
.First();
1378 OnArrowChar( (wxListLineData
*)node
->Data(), event
.ShiftDown() );
1384 if (m_mode
& wxLC_REPORT
) { steps
= m_visibleLines
-1; }
1388 wxNode
*node
= m_lines
.First();
1389 for (;;) { if (m_current
== (wxListLineData
*)node
->Data()) break; pos
++; node
= node
->Next(); }
1390 steps
= pos
% m_visibleLines
;
1392 wxNode
*node
= m_lines
.Member( m_current
);
1393 for (int i
= 0; i
< steps
; i
++) if (node
->Previous()) node
= node
->Previous();
1394 if (node
) OnArrowChar( (wxListLineData
*)node
->Data(), event
.ShiftDown() );
1400 if (m_mode
& wxLC_REPORT
) { steps
= m_visibleLines
-1; }
1403 int pos
= 0; wxNode
*node
= m_lines
.First();
1404 for (;;) { if (m_current
== (wxListLineData
*)node
->Data()) break; pos
++; node
= node
->Next(); }
1405 steps
= m_visibleLines
-(pos
% m_visibleLines
)-1;
1407 wxNode
*node
= m_lines
.Member( m_current
);
1408 for (int i
= 0; i
< steps
; i
++) if (node
->Next()) node
= node
->Next();
1409 if (node
) OnArrowChar( (wxListLineData
*)node
->Data(), event
.ShiftDown() );
1414 if (!(m_mode
& wxLC_REPORT
))
1416 wxNode
*node
= m_lines
.Member( m_current
);
1417 for (int i
= 0; i
<m_visibleLines
; i
++) if (node
->Previous()) node
= node
->Previous();
1418 if (node
) OnArrowChar( (wxListLineData
*)node
->Data(), event
.ShiftDown() );
1424 if (!(m_mode
& wxLC_REPORT
))
1426 wxNode
*node
= m_lines
.Member( m_current
);
1427 for (int i
= 0; i
<m_visibleLines
; i
++) if (node
->Next()) node
= node
->Next();
1428 if (node
) OnArrowChar( (wxListLineData
*)node
->Data(), event
.ShiftDown() );
1434 m_current
->ReverseHilight();
1435 RefreshLine( m_current
);
1440 if (!(m_mode
& wxLC_SINGLE_SEL
))
1442 wxListLineData
*oldCurrent
= m_current
;
1443 m_current
->ReverseHilight();
1444 wxNode
*node
= m_lines
.Member( m_current
)->Next();
1445 if (node
) m_current
= (wxListLineData
*)node
->Data();
1447 RefreshLine( oldCurrent
);
1448 RefreshLine( m_current
);
1449 UnfocusLine( oldCurrent
);
1450 FocusLine( m_current
);
1457 ActivateLine( m_current
);
1469 void wxListMainWindow::OnSetFocus( wxFocusEvent
&WXUNUSED(event
) )
1472 RefreshLine( m_current
);
1474 if (!GetParent()) return;
1476 wxFocusEvent
event( wxEVT_SET_FOCUS
, GetParent()->GetId() );
1477 event
.SetEventObject( GetParent() );
1478 GetParent()->GetEventHandler()->ProcessEvent( event
);
1481 void wxListMainWindow::OnKillFocus( wxFocusEvent
&WXUNUSED(event
) )
1484 RefreshLine( m_current
);
1487 void wxListMainWindow::OnSize( wxSizeEvent
&WXUNUSED(event
) )
1490 We don't even allow the wxScrolledWindow::AdjustScrollbars() call
1492 CalculatePositions();
1493 printf( "OnSize::Refresh.\n" );
1499 void wxListMainWindow::DrawImage( int index
, wxPaintDC
*dc
, int x
, int y
)
1501 if ((m_mode
& wxLC_ICON
) && (m_normal_image_list
))
1503 m_normal_image_list
->Draw( index
, *dc
, x
, y
, wxIMAGELIST_DRAW_TRANSPARENT
);
1506 if ((m_mode
& wxLC_SMALL_ICON
) && (m_small_image_list
))
1508 m_small_image_list
->Draw( index
, *dc
, x
, y
, wxIMAGELIST_DRAW_TRANSPARENT
);
1510 if ((m_mode
& wxLC_REPORT
) && (m_small_image_list
))
1512 m_small_image_list
->Draw( index
, *dc
, x
, y
, wxIMAGELIST_DRAW_TRANSPARENT
);
1517 void wxListMainWindow::GetImageSize( int index
, int &width
, int &height
)
1519 if ((m_mode
& wxLC_ICON
) && (m_normal_image_list
))
1521 m_normal_image_list
->GetSize( index
, width
, height
);
1524 if ((m_mode
& wxLC_SMALL_ICON
) && (m_small_image_list
))
1526 m_small_image_list
->GetSize( index
, width
, height
);
1529 if ((m_mode
& wxLC_REPORT
) && (m_small_image_list
))
1531 m_small_image_list
->GetSize( index
, width
, height
);
1538 int wxListMainWindow::GetTextLength( wxString
&s
)
1540 wxPaintDC
dc( this );
1543 dc
.GetTextExtent( s
, &lw
, &lh
);
1547 int wxListMainWindow::GetIndexOfLine( const wxListLineData
*line
)
1550 wxNode
*node
= m_lines
.First();
1553 if (line
== (wxListLineData
*)node
->Data()) return i
;
1555 node
= node
->Next();
1560 void wxListMainWindow::SetImageList( wxImageList
*imageList
, int which
)
1563 if (which
== wxIMAGE_LIST_NORMAL
) m_normal_image_list
= imageList
;
1564 if (which
== wxIMAGE_LIST_SMALL
) m_small_image_list
= imageList
;
1567 void wxListMainWindow::SetItemSpacing( int spacing
, bool isSmall
)
1572 m_small_spacing
= spacing
;
1576 m_normal_spacing
= spacing
;
1580 int wxListMainWindow::GetItemSpacing( bool isSmall
)
1582 if (isSmall
) return m_small_spacing
; else return m_normal_spacing
;
1585 void wxListMainWindow::SetColumn( int col
, wxListItem
&item
)
1588 wxNode
*node
= m_columns
.Nth( col
);
1591 if (item
.m_width
== wxLIST_AUTOSIZE_USEHEADER
) item
.m_width
= GetTextLength( item
.m_text
)+7;
1592 wxListHeaderData
*column
= (wxListHeaderData
*)node
->Data();
1593 column
->SetItem( item
);
1595 wxListCtrl
*lc
= (wxListCtrl
*) GetParent();
1596 if (lc
->m_headerWin
) lc
->m_headerWin
->Refresh();
1599 void wxListMainWindow::SetColumnWidth( int col
, int width
)
1601 if (!(m_mode
& wxLC_REPORT
)) return;
1605 wxNode
*node
= m_columns
.Nth( col
);
1608 wxListHeaderData
*column
= (wxListHeaderData
*)node
->Data();
1609 column
->SetWidth( width
);
1612 node
= m_lines
.First();
1615 wxListLineData
*line
= (wxListLineData
*)node
->Data();
1616 wxNode
*n
= line
->m_items
.Nth( col
);
1619 wxListItemData
*item
= (wxListItemData
*)n
->Data();
1620 item
->SetSize( width
, -1 );
1622 node
= node
->Next();
1625 wxListCtrl
*lc
= (wxListCtrl
*) GetParent();
1626 if (lc
->m_headerWin
) lc
->m_headerWin
->Refresh();
1629 void wxListMainWindow::GetColumn( int col
, wxListItem
&item
)
1631 wxNode
*node
= m_columns
.Nth( col
);
1634 wxListHeaderData
*column
= (wxListHeaderData
*)node
->Data();
1635 column
->GetItem( item
);
1647 int wxListMainWindow::GetColumnWidth( int col
)
1649 wxNode
*node
= m_columns
.Nth( col
);
1652 wxListHeaderData
*column
= (wxListHeaderData
*)node
->Data();
1653 return column
->GetWidth();
1659 int wxListMainWindow::GetColumnCount( void )
1661 return m_columns
.Number();
1664 int wxListMainWindow::GetCountPerPage( void )
1666 return m_visibleLines
;
1669 void wxListMainWindow::SetItem( wxListItem
&item
)
1672 wxNode
*node
= m_lines
.Nth( item
.m_itemId
);
1675 wxListLineData
*line
= (wxListLineData
*)node
->Data();
1676 if (m_mode
& wxLC_REPORT
) item
.m_width
= GetColumnWidth( item
.m_col
)-3;
1677 line
->SetItem( item
.m_col
, item
);
1681 void wxListMainWindow::SetItemState( long item
, long state
, long stateMask
)
1683 // m_dirty = TRUE; no recalcs needed
1685 wxListLineData
*oldCurrent
= m_current
;
1687 if (stateMask
& wxLIST_STATE_FOCUSED
)
1689 wxNode
*node
= m_lines
.Nth( item
);
1692 wxListLineData
*line
= (wxListLineData
*)node
->Data();
1693 UnfocusLine( m_current
);
1695 FocusLine( m_current
);
1696 RefreshLine( m_current
);
1697 RefreshLine( oldCurrent
);
1701 if (stateMask
& wxLIST_STATE_SELECTED
)
1703 bool on
= state
& wxLIST_STATE_SELECTED
;
1704 if (!on
&& (m_mode
& wxLC_SINGLE_SEL
)) return;
1706 wxNode
*node
= m_lines
.Nth( item
);
1709 wxListLineData
*line
= (wxListLineData
*)node
->Data();
1710 if (m_mode
& wxLC_SINGLE_SEL
)
1712 UnfocusLine( m_current
);
1714 FocusLine( m_current
);
1715 oldCurrent
->Hilight( FALSE
);
1716 RefreshLine( m_current
);
1717 RefreshLine( oldCurrent
);
1719 bool on
= state
& wxLIST_STATE_SELECTED
;
1720 line
->Hilight( on
);
1721 RefreshLine( line
);
1726 int wxListMainWindow::GetItemState( long item
, long stateMask
)
1728 int ret
= wxLIST_STATE_DONTCARE
;
1729 if (stateMask
& wxLIST_STATE_FOCUSED
)
1731 wxNode
*node
= m_lines
.Nth( item
);
1734 wxListLineData
*line
= (wxListLineData
*)node
->Data();
1735 if (line
== m_current
) ret
|= wxLIST_STATE_FOCUSED
;
1738 if (stateMask
& wxLIST_STATE_SELECTED
)
1740 wxNode
*node
= m_lines
.Nth( item
);
1743 wxListLineData
*line
= (wxListLineData
*)node
->Data();
1744 if (line
->IsHilighted()) ret
|= wxLIST_STATE_FOCUSED
;
1750 void wxListMainWindow::GetItem( wxListItem
&item
)
1752 wxNode
*node
= m_lines
.Nth( item
.m_itemId
);
1755 wxListLineData
*line
= (wxListLineData
*)node
->Data();
1756 line
->GetItem( item
.m_col
, item
);
1767 int wxListMainWindow::GetItemCount( void )
1769 return m_lines
.Number();
1772 void wxListMainWindow::GetItemRect( long index
, wxRectangle
&rect
)
1774 wxNode
*node
= m_lines
.Nth( index
);
1777 wxListLineData
*line
= (wxListLineData
*)node
->Data();
1778 line
->GetRect( rect
);
1789 bool wxListMainWindow::GetItemPosition(long item
, wxPoint
& pos
)
1791 wxNode
*node
= m_lines
.Nth( item
);
1795 wxListLineData
*line
= (wxListLineData
*)node
->Data();
1796 line
->GetRect( rect
);
1808 int wxListMainWindow::GetSelectedItemCount( void )
1811 wxNode
*node
= m_lines
.First();
1814 wxListLineData
*line
= (wxListLineData
*)node
->Data();
1815 if (line
->IsHilighted()) ret
++;
1816 node
= node
->Next();
1821 void wxListMainWindow::SetMode( long mode
)
1828 if (m_mode
& wxLC_REPORT
)
1840 long wxListMainWindow::GetMode( void ) const
1845 void wxListMainWindow::CalculatePositions( void )
1847 wxPaintDC
dc( this );
1848 dc
.SetFont( *GetFont() );
1850 int iconSpacing
= 0;
1851 if (m_mode
& wxLC_ICON
) iconSpacing
= m_normal_spacing
;
1852 if (m_mode
& wxLC_SMALL_ICON
) iconSpacing
= m_small_spacing
;
1853 wxNode
*node
= m_lines
.First();
1856 wxListLineData
*line
= (wxListLineData
*)node
->Data();
1857 line
->CalculateSize( &dc
, iconSpacing
);
1858 node
= node
->Next();
1863 int lineSpacing
= 0;
1865 node
= m_lines
.First();
1868 wxListLineData
*line
= (wxListLineData
*)node
->Data();
1870 line
->GetSize( dummy
, lineSpacing
);
1876 lineSpacing
= 6 + (int)dc
.GetCharHeight();
1879 int clientWidth
= 0;
1880 int clientHeight
= 0;
1882 if (m_mode
& wxLC_REPORT
)
1886 int entireHeight
= m_lines
.Number() * lineSpacing
+ 10;
1887 SetScrollbars( m_xScroll
, m_yScroll
, 0, (entireHeight
+10) / m_yScroll
, 0, 0, TRUE
);
1888 GetClientSize( &clientWidth
, &clientHeight
);
1889 node
= m_lines
.First();
1892 wxListLineData
*line
= (wxListLineData
*)node
->Data();
1893 line
->SetPosition( &dc
, x
, y
, clientWidth
);
1895 for (int i
= 0; i
< GetColumnCount(); i
++)
1897 line
->SetColumnPosition( i
, col_x
);
1898 col_x
+= GetColumnWidth( i
);
1901 node
= node
->Next();
1906 // At first, we try without any scrollbar
1907 GetSize( &clientWidth
, &clientHeight
);
1909 int entireWidth
= 0;
1911 for (int tries
= 0; tries
< 2; tries
++)
1917 node
= m_lines
.First();
1920 wxListLineData
*line
= (wxListLineData
*)node
->Data();
1921 line
->SetPosition( &dc
, x
, y
, clientWidth
);
1922 line
->GetSize( lineWidth
, lineHeight
);
1923 if (lineWidth
> maxWidth
) maxWidth
= lineWidth
;
1925 if (y
+lineHeight
> clientHeight
-4)
1929 entireWidth
+= maxWidth
+13;
1932 node
= node
->Next();
1933 if (!node
) entireWidth
+= maxWidth
;
1934 if ((tries
== 0) && (entireWidth
> clientWidth
))
1936 clientHeight
-= 14; // scrollbar height
1939 if (!node
) tries
= 1;
1942 SetScrollbars( m_xScroll
, m_yScroll
, (entireWidth
+15) / m_xScroll
, 0, 0, 0, TRUE
);
1944 m_visibleLines
= (clientHeight
-4) / (lineSpacing
);
1947 void wxListMainWindow::RealizeChanges( void )
1951 wxNode
*node
= m_lines
.First();
1952 if (node
) m_current
= (wxListLineData
*)node
->Data();
1956 FocusLine( m_current
);
1957 if (m_mode
& wxLC_SINGLE_SEL
) m_current
->Hilight( TRUE
);
1961 long wxListMainWindow::GetNextItem( long item
, int WXUNUSED(geometry
), int state
)
1964 if (item
> 0) ret
= item
;
1965 wxNode
*node
= m_lines
.Nth( ret
);
1968 wxListLineData
*line
= (wxListLineData
*)node
->Data();
1969 if ((state
& wxLIST_STATE_FOCUSED
) && (line
== m_current
)) return ret
;
1970 if ((state
& wxLIST_STATE_SELECTED
) && (line
->IsHilighted())) return ret
;
1971 if (!state
) return ret
;
1973 node
= node
->Next();
1978 void wxListMainWindow::DeleteItem( long index
)
1981 wxNode
*node
= m_lines
.Nth( index
);
1984 wxListLineData
*line
= (wxListLineData
*)node
->Data();
1985 if (m_current
== line
) m_current
= (wxListLineData
*) NULL
;
1987 m_lines
.DeleteNode( node
);
1991 void wxListMainWindow::DeleteColumn( int col
)
1994 wxNode
*node
= m_columns
.Nth( col
);
1995 if (node
) m_columns
.DeleteNode( node
);
1998 void wxListMainWindow::DeleteAllItems( void )
2001 m_current
= (wxListLineData
*) NULL
;
2002 wxNode
*node
= m_lines
.First();
2005 wxListLineData
*line
= (wxListLineData
*)node
->Data();
2007 node
= node
->Next();
2012 void wxListMainWindow::DeleteEverything( void )
2015 m_current
= (wxListLineData
*) NULL
;
2016 wxNode
*node
= m_lines
.First();
2019 wxListLineData
*line
= (wxListLineData
*)node
->Data();
2021 node
= node
->Next();
2024 m_current
= (wxListLineData
*) NULL
;
2028 void wxListMainWindow::EnsureVisible( long index
)
2030 wxListLineData
*oldCurrent
= m_current
;
2031 m_current
= (wxListLineData
*) NULL
;
2033 wxNode
*node
= m_lines
.Nth( i
);
2034 if (node
) m_current
= (wxListLineData
*)node
->Data();
2035 if (m_current
) MoveToFocus();
2036 m_current
= oldCurrent
;
2039 long wxListMainWindow::FindItem(long start
, const wxString
& str
, bool WXUNUSED(partial
) )
2043 if (pos
< 0) pos
= 0;
2044 wxNode
*node
= m_lines
.Nth( pos
);
2047 wxListLineData
*line
= (wxListLineData
*)node
->Data();
2049 line
->GetText( 0, s
);
2050 if (s
== tmp
) return pos
;
2051 node
= node
->Next();
2057 long wxListMainWindow::FindItem(long start
, long data
)
2060 if (pos
< 0) pos
= 0;
2061 wxNode
*node
= m_lines
.Nth( pos
);
2064 wxListLineData
*line
= (wxListLineData
*)node
->Data();
2066 line
->GetItem( 0, item
);
2067 if (item
.m_data
== data
) return pos
;
2068 node
= node
->Next();
2074 long wxListMainWindow::HitTest( int x
, int y
, int &flags
)
2076 wxNode
*node
= m_lines
.First();
2080 wxListLineData
*line
= (wxListLineData
*)node
->Data();
2081 long ret
= line
->IsHit( x
, y
);
2087 node
= node
->Next();
2093 void wxListMainWindow::InsertItem( wxListItem
&item
)
2097 if (m_mode
& wxLC_REPORT
) mode
= wxLC_REPORT
;
2098 else if (m_mode
& wxLC_LIST
) mode
= wxLC_LIST
;
2099 else if (m_mode
& wxLC_ICON
) mode
= wxLC_ICON
;
2100 else if (m_mode
& wxLC_SMALL_ICON
) mode
= wxLC_ICON
; // no typo
2101 wxListLineData
*line
= new wxListLineData( this, mode
, m_hilightBrush
);
2102 if (m_mode
& wxLC_REPORT
)
2104 line
->InitItems( GetColumnCount() );
2105 item
.m_width
= GetColumnWidth( 0 )-3;
2108 line
->InitItems( 1 );
2109 line
->SetItem( 0, item
);
2110 wxNode
*node
= m_lines
.Nth( item
.m_itemId
);
2112 m_lines
.Insert( node
, line
);
2114 m_lines
.Append( line
);
2117 void wxListMainWindow::InsertColumn( long col
, wxListItem
&item
)
2120 if (m_mode
& wxLC_REPORT
)
2122 if (item
.m_width
== wxLIST_AUTOSIZE_USEHEADER
) item
.m_width
= GetTextLength( item
.m_text
);
2123 wxListHeaderData
*column
= new wxListHeaderData( item
);
2124 wxNode
*node
= m_columns
.Nth( col
);
2126 m_columns
.Insert( node
, column
);
2128 m_columns
.Append( column
);
2132 wxListCtrlCompare list_ctrl_compare_func_2
;
2133 long list_ctrl_compare_data
;
2135 int list_ctrl_compare_func_1( const void *arg1
, const void *arg2
)
2137 wxListLineData
*line1
= *((wxListLineData
**)arg1
);
2138 wxListLineData
*line2
= *((wxListLineData
**)arg2
);
2140 line1
->GetItem( 0, item
);
2141 long data1
= item
.m_data
;
2142 line2
->GetItem( 0, item
);
2143 long data2
= item
.m_data
;
2144 return list_ctrl_compare_func_2( data1
, data2
, list_ctrl_compare_data
);
2147 void wxListMainWindow::SortItems( wxListCtrlCompare fn
, long data
)
2149 list_ctrl_compare_func_2
= fn
;
2150 list_ctrl_compare_data
= data
;
2151 m_lines
.Sort( list_ctrl_compare_func_1
);
2154 bool wxListMainWindow::OnListNotify( wxListEvent
&event
)
2156 if (GetParent()) GetParent()->GetEventHandler()->ProcessEvent( event
);
2160 // -------------------------------------------------------------------------------------
2162 // -------------------------------------------------------------------------------------
2164 IMPLEMENT_DYNAMIC_CLASS(wxListItem
, wxObject
)
2166 wxListItem::wxListItem(void)
2175 m_format
= wxLIST_FORMAT_CENTRE
;
2180 // -------------------------------------------------------------------------------------
2182 // -------------------------------------------------------------------------------------
2184 IMPLEMENT_DYNAMIC_CLASS(wxListEvent
, wxCommandEvent
)
2186 wxListEvent::wxListEvent( wxEventType commandType
, int id
):
2187 wxCommandEvent( commandType
, id
)
2192 m_cancelled
= FALSE
;
2195 // -------------------------------------------------------------------------------------
2197 // -------------------------------------------------------------------------------------
2199 IMPLEMENT_DYNAMIC_CLASS(wxListCtrl
, wxControl
)
2201 BEGIN_EVENT_TABLE(wxListCtrl
,wxControl
)
2202 EVT_SIZE (wxListCtrl::OnSize
)
2203 EVT_IDLE (wxListCtrl::OnIdle
)
2206 wxListCtrl::wxListCtrl(void)
2208 m_imageListNormal
= (wxImageList
*) NULL
;
2209 m_imageListSmall
= (wxImageList
*) NULL
;
2210 m_imageListState
= (wxImageList
*) NULL
;
2213 wxListCtrl::~wxListCtrl(void)
2217 bool wxListCtrl::Create( wxWindow
*parent
, wxWindowID id
,
2218 const wxPoint
&pos
, const wxSize
&size
,
2219 long style
, const wxValidator
&validator
,
2220 const wxString
&name
)
2222 m_imageListNormal
= (wxImageList
*) NULL
;
2223 m_imageListSmall
= (wxImageList
*) NULL
;
2224 m_imageListState
= (wxImageList
*) NULL
;
2228 if ((s
& wxLC_REPORT
== 0) &&
2229 (s
& wxLC_LIST
== 0) &&
2230 (s
& wxLC_ICON
== 0))
2233 bool ret
= wxControl::Create( parent
, id
, pos
, size
, s
, name
);
2235 SetValidator( validator
);
2237 m_mainWin
= new wxListMainWindow( this, -1, wxPoint(0,0), size
, s
);
2239 if (GetWindowStyleFlag() & wxLC_REPORT
)
2240 m_headerWin
= new wxListHeaderWindow( this, -1, m_mainWin
, wxPoint(0,0), wxSize(size
.x
,23) );
2242 m_headerWin
= (wxListHeaderWindow
*) NULL
;
2247 void wxListCtrl::OnSize( wxSizeEvent
&WXUNUSED(event
) )
2249 // handled in OnIdle
2251 if (m_mainWin
) m_mainWin
->m_dirty
= TRUE
;
2254 void wxListCtrl::SetSingleStyle( long style
, bool add
)
2256 long flag
= GetWindowStyleFlag();
2260 if (style
& wxLC_MASK_TYPE
) flag
= flag
& ~wxLC_MASK_TYPE
;
2261 if (style
& wxLC_MASK_ALIGN
) flag
= flag
& ~wxLC_MASK_ALIGN
;
2262 if (style
& wxLC_MASK_SORT
) flag
= flag
& ~wxLC_MASK_SORT
;
2271 if (flag
& style
) flag
-= style
;
2274 SetWindowStyleFlag( flag
);
2277 void wxListCtrl::SetWindowStyleFlag( long flag
)
2279 m_mainWin
->DeleteEverything();
2283 GetClientSize( &width
, &height
);
2285 m_mainWin
->SetMode( flag
);
2287 if (flag
& wxLC_REPORT
)
2289 if (!(GetWindowStyleFlag() & wxLC_REPORT
))
2291 // m_mainWin->SetSize( 0, 24, width, height-24 );
2294 m_headerWin
= new wxListHeaderWindow( this, -1, m_mainWin
, wxPoint(0,0), wxSize(width
,23) );
2298 // m_headerWin->SetSize( 0, 0, width, 23 );
2299 m_headerWin
->Show( TRUE
);
2305 if (GetWindowStyleFlag() & wxLC_REPORT
)
2307 // m_mainWin->SetSize( 0, 0, width, height );
2308 m_headerWin
->Show( FALSE
);
2312 wxWindow::SetWindowStyleFlag( flag
);
2315 bool wxListCtrl::GetColumn(int col
, wxListItem
&item
)
2317 m_mainWin
->GetColumn( col
, item
);
2321 bool wxListCtrl::SetColumn( int col
, wxListItem
& item
)
2323 m_mainWin
->SetColumn( col
, item
);
2327 int wxListCtrl::GetColumnWidth( int col
)
2329 return m_mainWin
->GetColumnWidth( col
);
2332 bool wxListCtrl::SetColumnWidth( int col
, int width
)
2334 m_mainWin
->SetColumnWidth( col
, width
);
2338 int wxListCtrl::GetCountPerPage(void)
2340 return m_mainWin
->GetCountPerPage(); // different from Windows ?
2344 wxText& wxListCtrl::GetEditControl(void) const
2349 bool wxListCtrl::GetItem( wxListItem
&info
)
2351 m_mainWin
->GetItem( info
);
2355 bool wxListCtrl::SetItem( wxListItem
&info
)
2357 m_mainWin
->SetItem( info
);
2361 long wxListCtrl::SetItem( long index
, int col
, const wxString
& label
, int imageId
)
2364 info
.m_text
= label
;
2365 info
.m_mask
= wxLIST_MASK_TEXT
;
2366 info
.m_itemId
= index
;
2370 info
.m_image
= imageId
;
2371 info
.m_mask
|= wxLIST_MASK_IMAGE
;
2374 m_mainWin
->SetItem(info
);
2378 int wxListCtrl::GetItemState( long item
, long stateMask
)
2380 return m_mainWin
->GetItemState( item
, stateMask
);
2383 bool wxListCtrl::SetItemState( long item
, long state
, long stateMask
)
2385 m_mainWin
->SetItemState( item
, state
, stateMask
);
2389 bool wxListCtrl::SetItemImage( long item
, int image
, int WXUNUSED(selImage
) )
2392 info
.m_image
= image
;
2393 info
.m_mask
= wxLIST_MASK_IMAGE
;
2394 info
.m_itemId
= item
;
2395 m_mainWin
->SetItem( info
);
2399 wxString
wxListCtrl::GetItemText( long item
)
2402 info
.m_itemId
= item
;
2403 m_mainWin
->GetItem( info
);
2407 void wxListCtrl::SetItemText( long item
, const wxString
&str
)
2410 info
.m_mask
= wxLIST_MASK_TEXT
;
2411 info
.m_itemId
= item
;
2413 m_mainWin
->SetItem( info
);
2416 long wxListCtrl::GetItemData( long item
)
2419 info
.m_itemId
= item
;
2420 m_mainWin
->GetItem( info
);
2424 bool wxListCtrl::SetItemData( long item
, long data
)
2427 info
.m_mask
= wxLIST_MASK_DATA
;
2428 info
.m_itemId
= item
;
2430 m_mainWin
->SetItem( info
);
2434 bool wxListCtrl::GetItemRect( long item
, wxRectangle
&rect
, int WXUNUSED(code
) )
2436 m_mainWin
->GetItemRect( item
, rect
);
2440 bool wxListCtrl::GetItemPosition( long item
, wxPoint
& pos
)
2442 m_mainWin
->GetItemPosition( item
, pos
);
2446 bool wxListCtrl::SetItemPosition( long WXUNUSED(item
), const wxPoint
& WXUNUSED(pos
) )
2451 int wxListCtrl::GetItemCount(void)
2453 return m_mainWin
->GetItemCount();
2456 void wxListCtrl::SetItemSpacing( int spacing
, bool isSmall
)
2458 m_mainWin
->SetItemSpacing( spacing
, isSmall
);
2461 int wxListCtrl::GetItemSpacing( bool isSmall
)
2463 return m_mainWin
->GetItemSpacing( isSmall
);
2466 int wxListCtrl::GetSelectedItemCount(void)
2468 return m_mainWin
->GetSelectedItemCount();
2472 wxColour wxListCtrl::GetTextColour(void) const
2476 void wxListCtrl::SetTextColour(const wxColour& WXUNUSED(col))
2481 long wxListCtrl::GetTopItem(void)
2486 long wxListCtrl::GetNextItem( long item
, int geom
, int state
) const
2488 return m_mainWin
->GetNextItem( item
, geom
, state
);
2491 wxImageList
*wxListCtrl::GetImageList(int which
)
2493 if (which
== wxIMAGE_LIST_NORMAL
)
2495 return m_imageListNormal
;
2497 else if (which
== wxIMAGE_LIST_SMALL
)
2499 return m_imageListSmall
;
2501 else if (which
== wxIMAGE_LIST_STATE
)
2503 return m_imageListState
;
2505 return (wxImageList
*) NULL
;
2508 void wxListCtrl::SetImageList( wxImageList
*imageList
, int which
)
2510 m_mainWin
->SetImageList( imageList
, which
);
2513 bool wxListCtrl::Arrange( int WXUNUSED(flag
) )
2518 bool wxListCtrl::DeleteItem( long item
)
2520 m_mainWin
->DeleteItem( item
);
2524 bool wxListCtrl::DeleteAllItems(void)
2526 m_mainWin
->DeleteAllItems();
2530 bool wxListCtrl::DeleteColumn( int col
)
2532 m_mainWin
->DeleteColumn( col
);
2537 wxText& wxListCtrl::Edit( long WXUNUSED(item ) )
2542 bool wxListCtrl::EnsureVisible( long item
)
2544 m_mainWin
->EnsureVisible( item
);
2548 long wxListCtrl::FindItem( long start
, const wxString
& str
, bool partial
)
2550 return m_mainWin
->FindItem( start
, str
, partial
);
2553 long wxListCtrl::FindItem( long start
, long data
)
2555 return m_mainWin
->FindItem( start
, data
);
2558 long wxListCtrl::FindItem( long WXUNUSED(start
), const wxPoint
& WXUNUSED(pt
),
2559 int WXUNUSED(direction
))
2564 long wxListCtrl::HitTest( const wxPoint
&point
, int &flags
)
2566 return m_mainWin
->HitTest( (int)point
.x
, (int)point
.y
, flags
);
2569 long wxListCtrl::InsertItem( wxListItem
& info
)
2571 m_mainWin
->InsertItem( info
);
2575 long wxListCtrl::InsertItem( long index
, const wxString
&label
)
2578 info
.m_text
= label
;
2579 info
.m_mask
= wxLIST_MASK_TEXT
;
2580 info
.m_itemId
= index
;
2581 return InsertItem( info
);
2584 long wxListCtrl::InsertItem( long index
, int imageIndex
)
2587 info
.m_mask
= wxLIST_MASK_IMAGE
;
2588 info
.m_image
= imageIndex
;
2589 info
.m_itemId
= index
;
2590 return InsertItem( info
);
2593 long wxListCtrl::InsertItem( long index
, const wxString
&label
, int imageIndex
)
2596 info
.m_text
= label
;
2597 info
.m_image
= imageIndex
;
2598 info
.m_mask
= wxLIST_MASK_TEXT
| wxLIST_MASK_IMAGE
;
2599 info
.m_itemId
= index
;
2600 return InsertItem( info
);
2603 long wxListCtrl::InsertColumn( long col
, wxListItem
&item
)
2605 m_mainWin
->InsertColumn( col
, item
);
2609 long wxListCtrl::InsertColumn( long col
, const wxString
&heading
,
2610 int format
, int width
)
2613 item
.m_mask
= wxLIST_MASK_TEXT
| wxLIST_MASK_FORMAT
;
2614 item
.m_text
= heading
;
2617 item
.m_mask
|= wxLIST_MASK_WIDTH
;
2618 item
.m_width
= width
;
2621 item
.m_format
= format
;
2623 return InsertColumn( col
, item
);
2626 bool wxListCtrl::ScrollList( int WXUNUSED(dx
), int WXUNUSED(dy
) )
2632 // fn is a function which takes 3 long arguments: item1, item2, data.
2633 // item1 is the long data associated with a first item (NOT the index).
2634 // item2 is the long data associated with a second item (NOT the index).
2635 // data is the same value as passed to SortItems.
2636 // The return value is a negative number if the first item should precede the second
2637 // item, a positive number of the second item should precede the first,
2638 // or zero if the two items are equivalent.
2639 // data is arbitrary data to be passed to the sort function.
2641 bool wxListCtrl::SortItems( wxListCtrlCompare fn
, long data
)
2643 m_mainWin
->SortItems( fn
, data
);
2647 void wxListCtrl::OnIdle( wxIdleEvent
&WXUNUSED(event
) )
2649 if (!m_mainWin
->m_dirty
) return;
2653 GetClientSize( &cw
, &ch
);
2660 if (GetWindowStyleFlag() & wxLC_REPORT
)
2662 m_headerWin
->GetPosition( &x
, &y
);
2663 m_headerWin
->GetSize( &w
, &h
);
2664 if ((x
!= 0) || (y
!= 0) || (w
!= cw
) || (h
!= 23))
2665 m_headerWin
->SetSize( 0, 0, cw
, 23 );
2667 m_mainWin
->GetPosition( &x
, &y
);
2668 m_mainWin
->GetSize( &w
, &h
);
2669 if ((x
!= 0) || (y
!= 24) || (w
!= cw
) || (h
!= ch
-24))
2670 m_mainWin
->SetSize( 0, 24, cw
, ch
-24 );
2674 m_mainWin
->GetPosition( &x
, &y
);
2675 m_mainWin
->GetSize( &w
, &h
);
2676 if ((x
!= 0) || (y
!= 24) || (w
!= cw
) || (h
!= ch
))
2677 m_mainWin
->SetSize( 0, 0, cw
, ch
);
2680 m_mainWin
->CalculatePositions();
2681 m_mainWin
->RealizeChanges();
2682 m_mainWin
->m_dirty
= FALSE
;
2683 m_mainWin
->Refresh();
2686 void wxListCtrl::SetBackgroundColour( const wxColour
&colour
)
2688 m_mainWin
->SetBackgroundColour( colour
);
2689 m_headerWin
->SetBackgroundColour( colour
);
2690 m_mainWin
->m_dirty
= TRUE
;
2693 void wxListCtrl::SetForegroundColour( const wxColour
&colour
)
2695 m_mainWin
->SetForegroundColour( colour
);
2696 m_headerWin
->SetForegroundColour( colour
);
2697 m_mainWin
->m_dirty
= TRUE
;
2700 void wxListCtrl::SetFont( const wxFont
&font
)
2702 m_mainWin
->SetFont( font
);
2703 m_headerWin
->SetFont( font
);
2704 m_mainWin
->m_dirty
= TRUE
;