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
);
679 void wxListHeaderWindow::DoDrawRect( wxPaintDC
*dc
, int x
, int y
, int w
, int h
)
681 const int m_corner
= 1;
683 dc
->SetBrush( *wxTRANSPARENT_BRUSH
);
685 dc
->SetPen( *wxBLACK_PEN
);
686 dc
->DrawLine( x
+w
-m_corner
+1, y
, x
+w
, y
+h
); // right (outer)
687 dc
->DrawRectangle( x
, y
+h
, w
, 1 ); // bottom (outer)
689 dc
->SetPen( *wxMEDIUM_GREY_PEN
);
690 dc
->DrawLine( x
+w
-m_corner
, y
, x
+w
-1, y
+h
); // right (inner)
691 dc
->DrawRectangle( x
+1, y
+h
-1, w
-2, 1 ); // bottom (inner)
693 dc
->SetPen( *wxWHITE_PEN
);
694 dc
->DrawRectangle( x
, y
, w
-m_corner
+1, 1 ); // top (outer)
695 // dc->DrawRectangle( x, y+1, w-m_corner, 1 ); // top (inner)
696 dc
->DrawRectangle( x
, y
, 1, h
); // left (outer)
697 // dc->DrawRectangle( x+1, y, 1, h-1 ); // left (inner)
700 void wxListHeaderWindow::OnPaint( wxPaintEvent
&WXUNUSED(event
) )
702 wxPaintDC
dc( this );
707 dc
.SetFont( m_font
);
713 GetClientSize( &w
, &h
);
715 dc
.SetTextForeground( *wxBLACK
);
716 if (m_foregroundColour
.Ok()) dc
.SetTextForeground( m_foregroundColour
);
720 int numColumns
= m_owner
->GetColumnCount();
722 for (int i
= 0; i
< numColumns
; i
++)
724 m_owner
->GetColumn( i
, item
);
725 int cw
= item
.m_width
-2;
726 if ((i
+1 == numColumns
) || (x
+item
.m_width
> w
-5)) cw
= w
-x
-1;
727 dc
.SetPen( *wxWHITE_PEN
);
729 DoDrawRect( &dc
, x
, y
, cw
, h
-2 );
730 dc
.SetClippingRegion( x
, y
, cw
-5, h
-4 );
731 dc
.DrawText( item
.m_text
, x
+4, y
+3 );
732 dc
.DestroyClippingRegion();
739 void wxListHeaderWindow::DrawCurrent()
743 int x2
= m_currentX
-1;
745 m_owner
->GetClientSize( (int*)NULL
, &y2
);
746 ClientToScreen( &x1
, &y1
);
747 m_owner
->ClientToScreen( &x2
, &y2
);
750 dc
.SetLogicalFunction( wxXOR
);
751 dc
.SetPen( wxPen( *wxBLACK
, 2, wxSOLID
) );
752 dc
.SetBrush( *wxTRANSPARENT_BRUSH
);
754 dc
.DrawLine( x1
, y1
, x2
, y2
);
756 dc
.SetLogicalFunction( wxCOPY
);
758 dc
.SetPen( wxNullPen
);
759 dc
.SetBrush( wxNullBrush
);
762 void wxListHeaderWindow::OnMouse( wxMouseEvent
&event
)
764 int x
= event
.GetX();
765 int y
= event
.GetY();
769 if (event
.ButtonUp())
771 // wxScreenDC::EndDrawingOnTop();
774 m_owner
->SetColumnWidth( m_column
, m_currentX
-m_minX
);
779 GetClientSize( &size_x
, (int*) NULL
);
783 m_currentX
= m_minX
+7;
784 if (m_currentX
> size_x
-7) m_currentX
= size_x
-7;
791 bool hit_border
= FALSE
;
793 for (int j
= 0; j
< m_owner
->GetColumnCount(); j
++)
795 xpos
+= m_owner
->GetColumnWidth( j
);
796 if ((abs(x
-xpos
) < 3) && (y
< 22))
805 if (event
.LeftDown() && hit_border
)
809 // wxScreenDC::StartDrawingOnTop( m_owner );
819 if (m_currentCursor
== wxSTANDARD_CURSOR
) SetCursor( m_resizeCursor
);
820 m_currentCursor
= m_resizeCursor
;
824 if (m_currentCursor
!= wxSTANDARD_CURSOR
) SetCursor( wxSTANDARD_CURSOR
);
825 m_currentCursor
= wxSTANDARD_CURSOR
;
830 void wxListHeaderWindow::OnSetFocus( wxFocusEvent
&WXUNUSED(event
) )
835 //-----------------------------------------------------------------------------
836 // wxListRenameTimer (internal)
837 //-----------------------------------------------------------------------------
839 wxListRenameTimer::wxListRenameTimer( wxListMainWindow
*owner
)
844 void wxListRenameTimer::Notify()
846 m_owner
->OnRenameTimer();
849 //-----------------------------------------------------------------------------
850 // wxListTextCtrl (internal)
851 //-----------------------------------------------------------------------------
853 IMPLEMENT_DYNAMIC_CLASS(wxListTextCtrl
,wxTextCtrl
);
855 BEGIN_EVENT_TABLE(wxListTextCtrl
,wxTextCtrl
)
856 EVT_CHAR (wxListTextCtrl::OnChar
)
857 EVT_KILL_FOCUS (wxListTextCtrl::OnKillFocus
)
860 wxListTextCtrl::wxListTextCtrl( wxWindow
*parent
, const wxWindowID id
,
861 bool *accept
, wxString
*res
, wxListMainWindow
*owner
,
862 const wxString
&value
, const wxPoint
&pos
, const wxSize
&size
,
863 int style
, const wxValidator
& validator
, const wxString
&name
) :
864 wxTextCtrl( parent
, id
, value
, pos
, size
, style
, validator
, name
)
871 void wxListTextCtrl::OnChar( wxKeyEvent
&event
)
873 if (event
.m_keyCode
== WXK_RETURN
)
876 (*m_res
) = GetValue();
877 m_owner
->OnRenameAccept();
882 if (event
.m_keyCode
== WXK_ESCAPE
)
893 void wxListTextCtrl::OnKillFocus( wxFocusEvent
&WXUNUSED(event
) )
902 //-----------------------------------------------------------------------------
904 //-----------------------------------------------------------------------------
906 IMPLEMENT_DYNAMIC_CLASS(wxListMainWindow
,wxScrolledWindow
);
908 BEGIN_EVENT_TABLE(wxListMainWindow
,wxScrolledWindow
)
909 EVT_PAINT (wxListMainWindow::OnPaint
)
910 EVT_SIZE (wxListMainWindow::OnSize
)
911 EVT_MOUSE_EVENTS (wxListMainWindow::OnMouse
)
912 EVT_CHAR (wxListMainWindow::OnChar
)
913 EVT_SET_FOCUS (wxListMainWindow::OnSetFocus
)
914 EVT_KILL_FOCUS (wxListMainWindow::OnKillFocus
)
917 wxListMainWindow::wxListMainWindow( void )
920 m_lines
.DeleteContents( TRUE
);
921 m_columns
.DeleteContents( TRUE
);
922 m_current
= (wxListLineData
*) NULL
;
924 m_hilightBrush
= (wxBrush
*) NULL
;
928 m_small_image_list
= (wxImageList
*) NULL
;
929 m_normal_image_list
= (wxImageList
*) NULL
;
930 m_small_spacing
= 30;
931 m_normal_spacing
= 40;
934 m_lastOnSame
= FALSE
;
935 m_renameTimer
= new wxListRenameTimer( this );
940 wxListMainWindow::wxListMainWindow( wxWindow
*parent
, wxWindowID id
,
941 const wxPoint
&pos
, const wxSize
&size
,
942 long style
, const wxString
&name
) :
943 wxScrolledWindow( parent
, id
, pos
, size
, style
, name
)
946 m_lines
.DeleteContents( TRUE
);
947 m_columns
.DeleteContents( TRUE
);
948 m_current
= (wxListLineData
*) NULL
;
951 m_hilightBrush
= new wxBrush( wxSystemSettings::GetSystemColour(wxSYS_COLOUR_HIGHLIGHT
), wxSOLID
);
952 m_small_image_list
= (wxImageList
*) NULL
;
953 m_normal_image_list
= (wxImageList
*) NULL
;
954 m_small_spacing
= 30;
955 m_normal_spacing
= 40;
956 // AllowDoubleClick( TRUE );
963 if (m_mode
& wxLC_REPORT
)
973 SetScrollbars( m_xScroll
, m_yScroll
, 0, 0, 0, 0 );
976 m_lastOnSame
= FALSE
;
977 m_renameTimer
= new wxListRenameTimer( this );
978 m_renameAccept
= FALSE
;
979 // m_text = new wxRawListTextCtrl( GetParent(), "", &m_renameAccept, &m_renameRes, this, 10, 10, 40, 10 );
980 // m_text->Show( FALSE );
982 SetBackgroundColour( *wxWHITE
);
985 wxListMainWindow::~wxListMainWindow( void )
987 if (m_hilightBrush
) delete m_hilightBrush
;
988 delete m_renameTimer
;
989 // if (m_hilightColour) delete m_hilightColour;
993 void wxListMainWindow::RefreshLine( wxListLineData
*line
)
1001 wxClientDC
dc(this);
1003 line
->GetExtent( x
, y
, w
, h
);
1005 dc
.LogicalToDeviceX(x
-3),
1006 dc
.LogicalToDeviceY(y
-3),
1007 dc
.LogicalToDeviceXRel(w
+6),
1008 dc
.LogicalToDeviceXRel(h
+6) );
1009 Refresh( TRUE
, &rect
);
1013 void wxListMainWindow::OnPaint( wxPaintEvent
&WXUNUSED(event
) )
1015 if (m_dirty
) return;
1017 wxPaintDC
dc( this );
1022 dc
.SetFont( m_font
);
1024 wxNode
*node
= m_lines
.First();
1027 wxListLineData
*line
= (wxListLineData
*)node
->Data();
1029 node
= node
->Next();
1031 if (m_current
) m_current
->DrawRubberBand( &dc
, m_hasFocus
);
1036 void wxListMainWindow::HilightAll( bool on
)
1038 wxNode
*node
= m_lines
.First();
1041 wxListLineData
*line
= (wxListLineData
*)node
->Data();
1042 if (line
->IsHilighted() != on
)
1044 line
->Hilight( on
);
1045 RefreshLine( line
);
1047 node
= node
->Next();
1051 void wxListMainWindow::ActivateLine( wxListLineData
*line
)
1053 if (!GetParent()) return;
1054 wxListEvent
le( wxEVT_COMMAND_LIST_KEY_DOWN
, GetParent()->GetId() );
1055 le
.SetEventObject( GetParent() );
1057 le
.m_itemIndex
= GetIndexOfLine( line
);
1059 line
->GetItem( 0, le
.m_item
);
1063 void wxListMainWindow::SendNotify( wxListLineData
*line
, wxEventType command
)
1065 if (!GetParent()) return;
1066 wxListEvent
le( command
, GetParent()->GetId() );
1067 le
.SetEventObject( GetParent() );
1069 le
.m_itemIndex
= GetIndexOfLine( line
);
1071 line
->GetItem( 0, le
.m_item
);
1075 void wxListMainWindow::FocusLine( wxListLineData
*WXUNUSED(line
) )
1077 // SendNotify( line, wxEVT_COMMAND_LIST_ITEM_FOCUSSED );
1080 void wxListMainWindow::UnfocusLine( wxListLineData
*WXUNUSED(line
) )
1082 // SendNotify( line, wxEVT_COMMAND_LIST_ITEM_UNFOCUSSED );
1085 void wxListMainWindow::SelectLine( wxListLineData
*line
)
1087 SendNotify( line
, wxEVT_COMMAND_LIST_ITEM_SELECTED
);
1090 void wxListMainWindow::DeselectLine( wxListLineData
*line
)
1092 SendNotify( line
, wxEVT_COMMAND_LIST_ITEM_DESELECTED
);
1095 void wxListMainWindow::DeleteLine( wxListLineData
*line
)
1097 SendNotify( line
, wxEVT_COMMAND_LIST_DELETE_ITEM
);
1100 void wxListMainWindow::StartLabelEdit( wxListLineData
*line
)
1102 SendNotify( line
, wxEVT_COMMAND_LIST_BEGIN_LABEL_EDIT
);
1105 void wxListMainWindow::RenameLine( wxListLineData
*line
, const wxString
&newName
)
1107 if (!GetParent()) return;
1109 wxListEvent
le( wxEVT_COMMAND_LIST_END_LABEL_EDIT
, GetParent()->GetId() );
1110 le
.SetEventObject( GetParent() );
1112 le
.m_itemIndex
= GetIndexOfLine( line
);
1114 line
->GetItem( 0, le
.m_item
);
1115 le
.m_item
.m_text
= newName
;
1119 void wxListMainWindow::OnRenameTimer()
1121 StartLabelEdit( m_current
);
1123 m_current
->GetText( 0, s
);
1128 m_current
->GetLabelExtent( x
, y
, w
, h
);
1130 wxClientDC
dc(this);
1132 x
= dc
.LogicalToDeviceX( x
);
1133 y
= dc
.LogicalToDeviceY( y
);
1135 wxListTextCtrl
*text
= new wxListTextCtrl(
1136 this, -1, &m_renameAccept
, &m_renameRes
, this, s
, wxPoint(x
-4,y
-4), wxSize(w
+11,h
+8) );
1139 m_text->SetSize( x+3, y+3, w+6, h+6 );
1140 m_text->SetValue( s );
1141 m_text->Show( TRUE );
1145 char *res = wxGetTextFromUser( _("Enter new name:"), "", s );
1150 RenameLine( m_current, s );
1155 void wxListMainWindow::OnRenameAccept()
1157 RenameLine( m_current
, m_renameRes
);
1160 void wxListMainWindow::OnMouse( wxMouseEvent
&event
)
1162 if (GetParent()->GetEventHandler()->ProcessEvent( event
)) return;
1164 if (!m_current
) return;
1165 if (m_dirty
) return;
1167 wxClientDC
dc(this);
1169 long x
= dc
.DeviceToLogicalX( (long)event
.GetX() );
1170 long y
= dc
.DeviceToLogicalY( (long)event
.GetY() );
1173 wxNode
*node
= m_lines
.First();
1174 wxListLineData
*line
= (wxListLineData
*) NULL
;
1177 line
= (wxListLineData
*)node
->Data();
1178 hitResult
= line
->IsHit( x
, y
);
1179 if (hitResult
) break;
1180 line
= (wxListLineData
*) NULL
;
1181 node
= node
->Next();
1184 if (!event
.Dragging())
1189 if (event
.Dragging() && (m_dragCount
> 3))
1192 wxListEvent
le( wxEVT_COMMAND_LIST_BEGIN_DRAG
, GetParent()->GetId() );
1193 le
.SetEventObject( this );
1202 if (event
.ButtonDClick())
1205 m_lastOnSame
= FALSE
;
1206 m_renameTimer
->Stop();
1207 ActivateLine( line
);
1211 if (event
.LeftUp() && m_lastOnSame
)
1214 if ((line
== m_current
) &&
1215 (hitResult
== wxLIST_HITTEST_ONITEMLABEL
) &&
1216 // (m_mode & wxLC_ICON) &&
1217 (m_mode
& wxLC_EDIT_LABELS
) )
1219 m_renameTimer
->Start( 100, TRUE
);
1221 m_lastOnSame
= FALSE
;
1225 if (event
.LeftDown())
1228 wxListLineData
*oldCurrent
= m_current
;
1229 if (m_mode
& wxLC_SINGLE_SEL
)
1232 HilightAll( FALSE
);
1233 m_current
->ReverseHilight();
1234 RefreshLine( m_current
);
1238 if (event
.ShiftDown())
1241 m_current
->ReverseHilight();
1242 RefreshLine( m_current
);
1244 else if (event
.ControlDown())
1247 int numOfCurrent
= -1;
1248 node
= m_lines
.First();
1251 wxListLineData
*test_line
= (wxListLineData
*)node
->Data();
1253 if (test_line
== oldCurrent
) break;
1254 node
= node
->Next();
1257 node
= m_lines
.First();
1260 wxListLineData
*test_line
= (wxListLineData
*)node
->Data();
1262 if (test_line
== line
) break;
1263 node
= node
->Next();
1266 if (numOfLine
< numOfCurrent
)
1267 { int i
= numOfLine
; numOfLine
= numOfCurrent
; numOfCurrent
= i
; }
1268 wxNode
*node
= m_lines
.Nth( numOfCurrent
);
1269 for (int i
= 0; i
<= numOfLine
-numOfCurrent
; i
++)
1271 wxListLineData
*test_line
= (wxListLineData
*)node
->Data();
1272 test_line
->Hilight(TRUE
);
1273 RefreshLine( test_line
);
1274 node
= node
->Next();
1280 HilightAll( FALSE
);
1281 m_current
->ReverseHilight();
1282 RefreshLine( m_current
);
1285 if (m_current
!= oldCurrent
)
1287 RefreshLine( oldCurrent
);
1288 UnfocusLine( oldCurrent
);
1289 FocusLine( m_current
);
1291 m_lastOnSame
= (m_current
== oldCurrent
);
1297 void wxListMainWindow::MoveToFocus( void )
1299 if (!m_current
) return;
1305 m_current->GetExtent( x, y, w, h );
1308 GetClientSize( &w_p, &h_p );
1309 if (m_mode & wxLC_REPORT)
1311 if (GetScrollPos( wxHORIZONTAL ) != 0) SetScrollPos( wxHORIZONTAL, 0);
1312 int y_s = m_yScroll*GetScrollPos( wxVERTICAL );
1313 if ((y > y_s) && (y+h < y_s+h_p)) return;
1314 if (y-y_s < 5) SetScrollPos( wxVERTICAL, (y-5)/m_yScroll );
1315 if (y+h+5 > y_s+h_p) SetScrollPos( wxVERTICAL, (y+h-h_p+h+5)/m_yScroll );
1319 if (GetScrollPos( wxVERTICAL ) != 0) SetScrollPos( wxVERTICAL, 0);
1320 int x_s = m_xScroll*GetScrollPos( wxHORIZONTAL );
1321 if ((x > x_s) && (x+w < x_s+w_p)) return;
1322 if (x-x_s < 5) SetScrollPos( wxHORIZONTAL, (x-5)/m_xScroll );
1323 if (x+w > x_s+w_p) SetScrollPos( wxHORIZONTAL, (x+w-w_p+5)/m_xScroll );
1328 void wxListMainWindow::OnArrowChar( wxListLineData
*newCurrent
, bool shiftDown
)
1330 if ((m_mode
& wxLC_SINGLE_SEL
) || (m_usedKeys
== FALSE
)) m_current
->Hilight( FALSE
);
1331 wxListLineData
*oldCurrent
= m_current
;
1332 m_current
= newCurrent
;
1334 if (shiftDown
|| (m_mode
& wxLC_SINGLE_SEL
)) m_current
->Hilight( TRUE
);
1335 RefreshLine( m_current
);
1336 RefreshLine( oldCurrent
);
1337 FocusLine( m_current
);
1338 UnfocusLine( oldCurrent
);
1341 void wxListMainWindow::OnChar( wxKeyEvent
&event
)
1344 if (event.KeyCode() == WXK_TAB)
1346 if (event.ShiftDown())
1353 if (!m_current
) return;
1354 switch (event
.KeyCode())
1358 wxNode
*node
= m_lines
.Member( m_current
)->Previous();
1359 if (node
) OnArrowChar( (wxListLineData
*)node
->Data(), event
.ShiftDown() );
1364 wxNode
*node
= m_lines
.Member( m_current
)->Next();
1365 if (node
) OnArrowChar( (wxListLineData
*)node
->Data(), event
.ShiftDown() );
1370 wxNode
*node
= m_lines
.Last();
1371 OnArrowChar( (wxListLineData
*)node
->Data(), event
.ShiftDown() );
1376 wxNode
*node
= m_lines
.First();
1377 OnArrowChar( (wxListLineData
*)node
->Data(), event
.ShiftDown() );
1383 if (m_mode
& wxLC_REPORT
) { steps
= m_visibleLines
-1; }
1387 wxNode
*node
= m_lines
.First();
1388 for (;;) { if (m_current
== (wxListLineData
*)node
->Data()) break; pos
++; node
= node
->Next(); }
1389 steps
= pos
% m_visibleLines
;
1391 wxNode
*node
= m_lines
.Member( m_current
);
1392 for (int i
= 0; i
< steps
; i
++) if (node
->Previous()) node
= node
->Previous();
1393 if (node
) OnArrowChar( (wxListLineData
*)node
->Data(), event
.ShiftDown() );
1399 if (m_mode
& wxLC_REPORT
) { steps
= m_visibleLines
-1; }
1402 int pos
= 0; wxNode
*node
= m_lines
.First();
1403 for (;;) { if (m_current
== (wxListLineData
*)node
->Data()) break; pos
++; node
= node
->Next(); }
1404 steps
= m_visibleLines
-(pos
% m_visibleLines
)-1;
1406 wxNode
*node
= m_lines
.Member( m_current
);
1407 for (int i
= 0; i
< steps
; i
++) if (node
->Next()) node
= node
->Next();
1408 if (node
) OnArrowChar( (wxListLineData
*)node
->Data(), event
.ShiftDown() );
1413 if (!(m_mode
& wxLC_REPORT
))
1415 wxNode
*node
= m_lines
.Member( m_current
);
1416 for (int i
= 0; i
<m_visibleLines
; i
++) if (node
->Previous()) node
= node
->Previous();
1417 if (node
) OnArrowChar( (wxListLineData
*)node
->Data(), event
.ShiftDown() );
1423 if (!(m_mode
& wxLC_REPORT
))
1425 wxNode
*node
= m_lines
.Member( m_current
);
1426 for (int i
= 0; i
<m_visibleLines
; i
++) if (node
->Next()) node
= node
->Next();
1427 if (node
) OnArrowChar( (wxListLineData
*)node
->Data(), event
.ShiftDown() );
1433 m_current
->ReverseHilight();
1434 RefreshLine( m_current
);
1439 if (!(m_mode
& wxLC_SINGLE_SEL
))
1441 wxListLineData
*oldCurrent
= m_current
;
1442 m_current
->ReverseHilight();
1443 wxNode
*node
= m_lines
.Member( m_current
)->Next();
1444 if (node
) m_current
= (wxListLineData
*)node
->Data();
1446 RefreshLine( oldCurrent
);
1447 RefreshLine( m_current
);
1448 UnfocusLine( oldCurrent
);
1449 FocusLine( m_current
);
1456 ActivateLine( m_current
);
1468 void wxListMainWindow::OnSetFocus( wxFocusEvent
&WXUNUSED(event
) )
1471 RefreshLine( m_current
);
1473 if (!GetParent()) return;
1475 wxFocusEvent
event( wxEVT_SET_FOCUS
, GetParent()->GetId() );
1476 event
.SetEventObject( GetParent() );
1477 GetParent()->GetEventHandler()->ProcessEvent( event
);
1480 void wxListMainWindow::OnKillFocus( wxFocusEvent
&WXUNUSED(event
) )
1483 RefreshLine( m_current
);
1486 void wxListMainWindow::OnSize( wxSizeEvent
&WXUNUSED(event
) )
1489 We don't even allow the wxScrolledWindow::AdjustScrollbars() call
1491 CalculatePositions();
1492 printf( "OnSize::Refresh.\n" );
1498 void wxListMainWindow::DrawImage( int index
, wxPaintDC
*dc
, int x
, int y
)
1500 if ((m_mode
& wxLC_ICON
) && (m_normal_image_list
))
1502 m_normal_image_list
->Draw( index
, *dc
, x
, y
, wxIMAGELIST_DRAW_TRANSPARENT
);
1505 if ((m_mode
& wxLC_SMALL_ICON
) && (m_small_image_list
))
1507 m_small_image_list
->Draw( index
, *dc
, x
, y
, wxIMAGELIST_DRAW_TRANSPARENT
);
1509 if ((m_mode
& wxLC_REPORT
) && (m_small_image_list
))
1511 m_small_image_list
->Draw( index
, *dc
, x
, y
, wxIMAGELIST_DRAW_TRANSPARENT
);
1516 void wxListMainWindow::GetImageSize( int index
, int &width
, int &height
)
1518 if ((m_mode
& wxLC_ICON
) && (m_normal_image_list
))
1520 m_normal_image_list
->GetSize( index
, width
, height
);
1523 if ((m_mode
& wxLC_SMALL_ICON
) && (m_small_image_list
))
1525 m_small_image_list
->GetSize( index
, width
, height
);
1528 if ((m_mode
& wxLC_REPORT
) && (m_small_image_list
))
1530 m_small_image_list
->GetSize( index
, width
, height
);
1537 int wxListMainWindow::GetTextLength( wxString
&s
)
1539 wxPaintDC
dc( this );
1542 dc
.GetTextExtent( s
, &lw
, &lh
);
1546 int wxListMainWindow::GetIndexOfLine( const wxListLineData
*line
)
1549 wxNode
*node
= m_lines
.First();
1552 if (line
== (wxListLineData
*)node
->Data()) return i
;
1554 node
= node
->Next();
1559 void wxListMainWindow::SetImageList( wxImageList
*imageList
, int which
)
1562 if (which
== wxIMAGE_LIST_NORMAL
) m_normal_image_list
= imageList
;
1563 if (which
== wxIMAGE_LIST_SMALL
) m_small_image_list
= imageList
;
1566 void wxListMainWindow::SetItemSpacing( int spacing
, bool isSmall
)
1571 m_small_spacing
= spacing
;
1575 m_normal_spacing
= spacing
;
1579 int wxListMainWindow::GetItemSpacing( bool isSmall
)
1581 if (isSmall
) return m_small_spacing
; else return m_normal_spacing
;
1584 void wxListMainWindow::SetColumn( int col
, wxListItem
&item
)
1587 wxNode
*node
= m_columns
.Nth( col
);
1590 if (item
.m_width
== wxLIST_AUTOSIZE_USEHEADER
) item
.m_width
= GetTextLength( item
.m_text
)+7;
1591 wxListHeaderData
*column
= (wxListHeaderData
*)node
->Data();
1592 column
->SetItem( item
);
1594 wxListCtrl
*lc
= (wxListCtrl
*) GetParent();
1595 if (lc
->m_headerWin
) lc
->m_headerWin
->Refresh();
1598 void wxListMainWindow::SetColumnWidth( int col
, int width
)
1600 if (!(m_mode
& wxLC_REPORT
)) return;
1604 wxNode
*node
= m_columns
.Nth( col
);
1607 wxListHeaderData
*column
= (wxListHeaderData
*)node
->Data();
1608 column
->SetWidth( width
);
1611 node
= m_lines
.First();
1614 wxListLineData
*line
= (wxListLineData
*)node
->Data();
1615 wxNode
*n
= line
->m_items
.Nth( col
);
1618 wxListItemData
*item
= (wxListItemData
*)n
->Data();
1619 item
->SetSize( width
, -1 );
1621 node
= node
->Next();
1624 wxListCtrl
*lc
= (wxListCtrl
*) GetParent();
1625 if (lc
->m_headerWin
) lc
->m_headerWin
->Refresh();
1628 void wxListMainWindow::GetColumn( int col
, wxListItem
&item
)
1630 wxNode
*node
= m_columns
.Nth( col
);
1633 wxListHeaderData
*column
= (wxListHeaderData
*)node
->Data();
1634 column
->GetItem( item
);
1646 int wxListMainWindow::GetColumnWidth( int col
)
1648 wxNode
*node
= m_columns
.Nth( col
);
1651 wxListHeaderData
*column
= (wxListHeaderData
*)node
->Data();
1652 return column
->GetWidth();
1658 int wxListMainWindow::GetColumnCount( void )
1660 return m_columns
.Number();
1663 int wxListMainWindow::GetCountPerPage( void )
1665 return m_visibleLines
;
1668 void wxListMainWindow::SetItem( wxListItem
&item
)
1671 wxNode
*node
= m_lines
.Nth( item
.m_itemId
);
1674 wxListLineData
*line
= (wxListLineData
*)node
->Data();
1675 if (m_mode
& wxLC_REPORT
) item
.m_width
= GetColumnWidth( item
.m_col
)-3;
1676 line
->SetItem( item
.m_col
, item
);
1680 void wxListMainWindow::SetItemState( long item
, long state
, long stateMask
)
1682 // m_dirty = TRUE; no recalcs needed
1684 wxListLineData
*oldCurrent
= m_current
;
1686 if (stateMask
& wxLIST_STATE_FOCUSED
)
1688 wxNode
*node
= m_lines
.Nth( item
);
1691 wxListLineData
*line
= (wxListLineData
*)node
->Data();
1692 UnfocusLine( m_current
);
1694 FocusLine( m_current
);
1695 RefreshLine( m_current
);
1696 RefreshLine( oldCurrent
);
1700 if (stateMask
& wxLIST_STATE_SELECTED
)
1702 bool on
= state
& wxLIST_STATE_SELECTED
;
1703 if (!on
&& (m_mode
& wxLC_SINGLE_SEL
)) return;
1705 wxNode
*node
= m_lines
.Nth( item
);
1708 wxListLineData
*line
= (wxListLineData
*)node
->Data();
1709 if (m_mode
& wxLC_SINGLE_SEL
)
1711 UnfocusLine( m_current
);
1713 FocusLine( m_current
);
1714 oldCurrent
->Hilight( FALSE
);
1715 RefreshLine( m_current
);
1716 RefreshLine( oldCurrent
);
1718 bool on
= state
& wxLIST_STATE_SELECTED
;
1719 line
->Hilight( on
);
1720 RefreshLine( line
);
1725 int wxListMainWindow::GetItemState( long item
, long stateMask
)
1727 int ret
= wxLIST_STATE_DONTCARE
;
1728 if (stateMask
& wxLIST_STATE_FOCUSED
)
1730 wxNode
*node
= m_lines
.Nth( item
);
1733 wxListLineData
*line
= (wxListLineData
*)node
->Data();
1734 if (line
== m_current
) ret
|= wxLIST_STATE_FOCUSED
;
1737 if (stateMask
& wxLIST_STATE_SELECTED
)
1739 wxNode
*node
= m_lines
.Nth( item
);
1742 wxListLineData
*line
= (wxListLineData
*)node
->Data();
1743 if (line
->IsHilighted()) ret
|= wxLIST_STATE_FOCUSED
;
1749 void wxListMainWindow::GetItem( wxListItem
&item
)
1751 wxNode
*node
= m_lines
.Nth( item
.m_itemId
);
1754 wxListLineData
*line
= (wxListLineData
*)node
->Data();
1755 line
->GetItem( item
.m_col
, item
);
1766 int wxListMainWindow::GetItemCount( void )
1768 return m_lines
.Number();
1771 void wxListMainWindow::GetItemRect( long index
, wxRectangle
&rect
)
1773 wxNode
*node
= m_lines
.Nth( index
);
1776 wxListLineData
*line
= (wxListLineData
*)node
->Data();
1777 line
->GetRect( rect
);
1788 bool wxListMainWindow::GetItemPosition(long item
, wxPoint
& pos
)
1790 wxNode
*node
= m_lines
.Nth( item
);
1794 wxListLineData
*line
= (wxListLineData
*)node
->Data();
1795 line
->GetRect( rect
);
1807 int wxListMainWindow::GetSelectedItemCount( void )
1810 wxNode
*node
= m_lines
.First();
1813 wxListLineData
*line
= (wxListLineData
*)node
->Data();
1814 if (line
->IsHilighted()) ret
++;
1815 node
= node
->Next();
1820 void wxListMainWindow::SetMode( long mode
)
1827 if (m_mode
& wxLC_REPORT
)
1839 long wxListMainWindow::GetMode( void ) const
1844 void wxListMainWindow::CalculatePositions( void )
1846 wxPaintDC
dc( this );
1847 dc
.SetFont( m_font
);
1849 int iconSpacing
= 0;
1850 if (m_mode
& wxLC_ICON
) iconSpacing
= m_normal_spacing
;
1851 if (m_mode
& wxLC_SMALL_ICON
) iconSpacing
= m_small_spacing
;
1852 wxNode
*node
= m_lines
.First();
1855 wxListLineData
*line
= (wxListLineData
*)node
->Data();
1856 line
->CalculateSize( &dc
, iconSpacing
);
1857 node
= node
->Next();
1862 int lineSpacing
= 0;
1864 node
= m_lines
.First();
1867 wxListLineData
*line
= (wxListLineData
*)node
->Data();
1869 line
->GetSize( dummy
, lineSpacing
);
1875 lineSpacing
= 6 + (int)dc
.GetCharHeight();
1878 int clientWidth
= 0;
1879 int clientHeight
= 0;
1881 if (m_mode
& wxLC_REPORT
)
1885 int entireHeight
= m_lines
.Number() * lineSpacing
+ 10;
1886 SetScrollbars( m_xScroll
, m_yScroll
, 0, (entireHeight
+10) / m_yScroll
, 0, 0, TRUE
);
1887 GetClientSize( &clientWidth
, &clientHeight
);
1888 node
= m_lines
.First();
1891 wxListLineData
*line
= (wxListLineData
*)node
->Data();
1892 line
->SetPosition( &dc
, x
, y
, clientWidth
);
1894 for (int i
= 0; i
< GetColumnCount(); i
++)
1896 line
->SetColumnPosition( i
, col_x
);
1897 col_x
+= GetColumnWidth( i
);
1900 node
= node
->Next();
1905 // At first, we try without any scrollbar
1906 GetSize( &clientWidth
, &clientHeight
);
1908 int entireWidth
= 0;
1910 for (int tries
= 0; tries
< 2; tries
++)
1916 node
= m_lines
.First();
1919 wxListLineData
*line
= (wxListLineData
*)node
->Data();
1920 line
->SetPosition( &dc
, x
, y
, clientWidth
);
1921 line
->GetSize( lineWidth
, lineHeight
);
1922 if (lineWidth
> maxWidth
) maxWidth
= lineWidth
;
1924 if (y
+lineHeight
> clientHeight
-4)
1928 entireWidth
+= maxWidth
+13;
1931 node
= node
->Next();
1932 if (!node
) entireWidth
+= maxWidth
;
1933 if ((tries
== 0) && (entireWidth
> clientWidth
))
1935 clientHeight
-= 14; // scrollbar height
1938 if (!node
) tries
= 1;
1941 SetScrollbars( m_xScroll
, m_yScroll
, (entireWidth
+15) / m_xScroll
, 0, 0, 0, TRUE
);
1943 m_visibleLines
= (clientHeight
-4) / (lineSpacing
);
1946 void wxListMainWindow::RealizeChanges( void )
1950 wxNode
*node
= m_lines
.First();
1951 if (node
) m_current
= (wxListLineData
*)node
->Data();
1955 FocusLine( m_current
);
1956 if (m_mode
& wxLC_SINGLE_SEL
) m_current
->Hilight( TRUE
);
1960 long wxListMainWindow::GetNextItem( long item
, int WXUNUSED(geometry
), int state
)
1963 if (item
> 0) ret
= item
;
1964 wxNode
*node
= m_lines
.Nth( ret
);
1967 wxListLineData
*line
= (wxListLineData
*)node
->Data();
1968 if ((state
& wxLIST_STATE_FOCUSED
) && (line
== m_current
)) return ret
;
1969 if ((state
& wxLIST_STATE_SELECTED
) && (line
->IsHilighted())) return ret
;
1970 if (!state
) return ret
;
1972 node
= node
->Next();
1977 void wxListMainWindow::DeleteItem( long index
)
1980 wxNode
*node
= m_lines
.Nth( index
);
1983 wxListLineData
*line
= (wxListLineData
*)node
->Data();
1984 if (m_current
== line
) m_current
= (wxListLineData
*) NULL
;
1986 m_lines
.DeleteNode( node
);
1990 void wxListMainWindow::DeleteColumn( int col
)
1993 wxNode
*node
= m_columns
.Nth( col
);
1994 if (node
) m_columns
.DeleteNode( node
);
1997 void wxListMainWindow::DeleteAllItems( void )
2000 m_current
= (wxListLineData
*) NULL
;
2001 wxNode
*node
= m_lines
.First();
2004 wxListLineData
*line
= (wxListLineData
*)node
->Data();
2006 node
= node
->Next();
2011 void wxListMainWindow::DeleteEverything( void )
2014 m_current
= (wxListLineData
*) NULL
;
2015 wxNode
*node
= m_lines
.First();
2018 wxListLineData
*line
= (wxListLineData
*)node
->Data();
2020 node
= node
->Next();
2023 m_current
= (wxListLineData
*) NULL
;
2027 void wxListMainWindow::EnsureVisible( long index
)
2029 wxListLineData
*oldCurrent
= m_current
;
2030 m_current
= (wxListLineData
*) NULL
;
2032 wxNode
*node
= m_lines
.Nth( i
);
2033 if (node
) m_current
= (wxListLineData
*)node
->Data();
2034 if (m_current
) MoveToFocus();
2035 m_current
= oldCurrent
;
2038 long wxListMainWindow::FindItem(long start
, const wxString
& str
, bool WXUNUSED(partial
) )
2042 if (pos
< 0) pos
= 0;
2043 wxNode
*node
= m_lines
.Nth( pos
);
2046 wxListLineData
*line
= (wxListLineData
*)node
->Data();
2048 line
->GetText( 0, s
);
2049 if (s
== tmp
) return pos
;
2050 node
= node
->Next();
2056 long wxListMainWindow::FindItem(long start
, long data
)
2059 if (pos
< 0) pos
= 0;
2060 wxNode
*node
= m_lines
.Nth( pos
);
2063 wxListLineData
*line
= (wxListLineData
*)node
->Data();
2065 line
->GetItem( 0, item
);
2066 if (item
.m_data
== data
) return pos
;
2067 node
= node
->Next();
2073 long wxListMainWindow::HitTest( int x
, int y
, int &flags
)
2075 wxNode
*node
= m_lines
.First();
2079 wxListLineData
*line
= (wxListLineData
*)node
->Data();
2080 long ret
= line
->IsHit( x
, y
);
2086 node
= node
->Next();
2092 void wxListMainWindow::InsertItem( wxListItem
&item
)
2096 if (m_mode
& wxLC_REPORT
) mode
= wxLC_REPORT
;
2097 else if (m_mode
& wxLC_LIST
) mode
= wxLC_LIST
;
2098 else if (m_mode
& wxLC_ICON
) mode
= wxLC_ICON
;
2099 else if (m_mode
& wxLC_SMALL_ICON
) mode
= wxLC_ICON
; // no typo
2100 wxListLineData
*line
= new wxListLineData( this, mode
, m_hilightBrush
);
2101 if (m_mode
& wxLC_REPORT
)
2103 line
->InitItems( GetColumnCount() );
2104 item
.m_width
= GetColumnWidth( 0 )-3;
2107 line
->InitItems( 1 );
2108 line
->SetItem( 0, item
);
2109 wxNode
*node
= m_lines
.Nth( item
.m_itemId
);
2111 m_lines
.Insert( node
, line
);
2113 m_lines
.Append( line
);
2116 void wxListMainWindow::InsertColumn( long col
, wxListItem
&item
)
2119 if (m_mode
& wxLC_REPORT
)
2121 if (item
.m_width
== wxLIST_AUTOSIZE_USEHEADER
) item
.m_width
= GetTextLength( item
.m_text
);
2122 wxListHeaderData
*column
= new wxListHeaderData( item
);
2123 wxNode
*node
= m_columns
.Nth( col
);
2125 m_columns
.Insert( node
, column
);
2127 m_columns
.Append( column
);
2131 wxListCtrlCompare list_ctrl_compare_func_2
;
2132 long list_ctrl_compare_data
;
2134 int list_ctrl_compare_func_1( const void *arg1
, const void *arg2
)
2136 wxListLineData
*line1
= *((wxListLineData
**)arg1
);
2137 wxListLineData
*line2
= *((wxListLineData
**)arg2
);
2139 line1
->GetItem( 0, item
);
2140 long data1
= item
.m_data
;
2141 line2
->GetItem( 0, item
);
2142 long data2
= item
.m_data
;
2143 return list_ctrl_compare_func_2( data1
, data2
, list_ctrl_compare_data
);
2146 void wxListMainWindow::SortItems( wxListCtrlCompare fn
, long data
)
2148 list_ctrl_compare_func_2
= fn
;
2149 list_ctrl_compare_data
= data
;
2150 m_lines
.Sort( list_ctrl_compare_func_1
);
2153 bool wxListMainWindow::OnListNotify( wxListEvent
&event
)
2155 if (GetParent()) GetParent()->GetEventHandler()->ProcessEvent( event
);
2159 // -------------------------------------------------------------------------------------
2161 // -------------------------------------------------------------------------------------
2163 IMPLEMENT_DYNAMIC_CLASS(wxListItem
, wxObject
)
2165 wxListItem::wxListItem(void)
2174 m_format
= wxLIST_FORMAT_CENTRE
;
2179 // -------------------------------------------------------------------------------------
2181 // -------------------------------------------------------------------------------------
2183 IMPLEMENT_DYNAMIC_CLASS(wxListEvent
, wxCommandEvent
)
2185 wxListEvent::wxListEvent( wxEventType commandType
, int id
):
2186 wxCommandEvent( commandType
, id
)
2191 m_cancelled
= FALSE
;
2194 // -------------------------------------------------------------------------------------
2196 // -------------------------------------------------------------------------------------
2198 IMPLEMENT_DYNAMIC_CLASS(wxListCtrl
, wxControl
)
2200 BEGIN_EVENT_TABLE(wxListCtrl
,wxControl
)
2201 EVT_SIZE (wxListCtrl::OnSize
)
2202 EVT_IDLE (wxListCtrl::OnIdle
)
2205 wxListCtrl::wxListCtrl(void)
2207 m_imageListNormal
= (wxImageList
*) NULL
;
2208 m_imageListSmall
= (wxImageList
*) NULL
;
2209 m_imageListState
= (wxImageList
*) NULL
;
2212 wxListCtrl::~wxListCtrl(void)
2216 bool wxListCtrl::Create( wxWindow
*parent
, wxWindowID id
,
2217 const wxPoint
&pos
, const wxSize
&size
,
2218 long style
, const wxValidator
&validator
,
2219 const wxString
&name
)
2221 m_imageListNormal
= (wxImageList
*) NULL
;
2222 m_imageListSmall
= (wxImageList
*) NULL
;
2223 m_imageListState
= (wxImageList
*) NULL
;
2227 if ((s
& wxLC_REPORT
== 0) &&
2228 (s
& wxLC_LIST
== 0) &&
2229 (s
& wxLC_ICON
== 0))
2232 bool ret
= wxControl::Create( parent
, id
, pos
, size
, s
, name
);
2234 SetValidator( validator
);
2236 m_mainWin
= new wxListMainWindow( this, -1, wxPoint(0,0), size
, s
);
2238 if (GetWindowStyleFlag() & wxLC_REPORT
)
2239 m_headerWin
= new wxListHeaderWindow( this, -1, m_mainWin
, wxPoint(0,0), wxSize(size
.x
,23) );
2241 m_headerWin
= (wxListHeaderWindow
*) NULL
;
2246 void wxListCtrl::OnSize( wxSizeEvent
&WXUNUSED(event
) )
2248 // handled in OnIdle
2250 if (m_mainWin
) m_mainWin
->m_dirty
= TRUE
;
2253 void wxListCtrl::SetSingleStyle( long style
, bool add
)
2255 long flag
= GetWindowStyleFlag();
2259 if (style
& wxLC_MASK_TYPE
) flag
= flag
& ~wxLC_MASK_TYPE
;
2260 if (style
& wxLC_MASK_ALIGN
) flag
= flag
& ~wxLC_MASK_ALIGN
;
2261 if (style
& wxLC_MASK_SORT
) flag
= flag
& ~wxLC_MASK_SORT
;
2270 if (flag
& style
) flag
-= style
;
2273 SetWindowStyleFlag( flag
);
2276 void wxListCtrl::SetWindowStyleFlag( long flag
)
2278 m_mainWin
->DeleteEverything();
2282 GetClientSize( &width
, &height
);
2284 m_mainWin
->SetMode( flag
);
2286 if (flag
& wxLC_REPORT
)
2288 if (!(GetWindowStyleFlag() & wxLC_REPORT
))
2290 // m_mainWin->SetSize( 0, 24, width, height-24 );
2293 m_headerWin
= new wxListHeaderWindow( this, -1, m_mainWin
, wxPoint(0,0), wxSize(width
,23) );
2297 // m_headerWin->SetSize( 0, 0, width, 23 );
2298 m_headerWin
->Show( TRUE
);
2304 if (GetWindowStyleFlag() & wxLC_REPORT
)
2306 // m_mainWin->SetSize( 0, 0, width, height );
2307 m_headerWin
->Show( FALSE
);
2311 wxWindow::SetWindowStyleFlag( flag
);
2314 bool wxListCtrl::GetColumn(int col
, wxListItem
&item
)
2316 m_mainWin
->GetColumn( col
, item
);
2320 bool wxListCtrl::SetColumn( int col
, wxListItem
& item
)
2322 m_mainWin
->SetColumn( col
, item
);
2326 int wxListCtrl::GetColumnWidth( int col
)
2328 return m_mainWin
->GetColumnWidth( col
);
2331 bool wxListCtrl::SetColumnWidth( int col
, int width
)
2333 m_mainWin
->SetColumnWidth( col
, width
);
2337 int wxListCtrl::GetCountPerPage(void)
2339 return m_mainWin
->GetCountPerPage(); // different from Windows ?
2343 wxText& wxListCtrl::GetEditControl(void) const
2348 bool wxListCtrl::GetItem( wxListItem
&info
)
2350 m_mainWin
->GetItem( info
);
2354 bool wxListCtrl::SetItem( wxListItem
&info
)
2356 m_mainWin
->SetItem( info
);
2360 long wxListCtrl::SetItem( long index
, int col
, const wxString
& label
, int imageId
)
2363 info
.m_text
= label
;
2364 info
.m_mask
= wxLIST_MASK_TEXT
;
2365 info
.m_itemId
= index
;
2369 info
.m_image
= imageId
;
2370 info
.m_mask
|= wxLIST_MASK_IMAGE
;
2373 m_mainWin
->SetItem(info
);
2377 int wxListCtrl::GetItemState( long item
, long stateMask
)
2379 return m_mainWin
->GetItemState( item
, stateMask
);
2382 bool wxListCtrl::SetItemState( long item
, long state
, long stateMask
)
2384 m_mainWin
->SetItemState( item
, state
, stateMask
);
2388 bool wxListCtrl::SetItemImage( long item
, int image
, int WXUNUSED(selImage
) )
2391 info
.m_image
= image
;
2392 info
.m_mask
= wxLIST_MASK_IMAGE
;
2393 info
.m_itemId
= item
;
2394 m_mainWin
->SetItem( info
);
2398 wxString
wxListCtrl::GetItemText( long item
)
2401 info
.m_itemId
= item
;
2402 m_mainWin
->GetItem( info
);
2406 void wxListCtrl::SetItemText( long item
, const wxString
&str
)
2409 info
.m_mask
= wxLIST_MASK_TEXT
;
2410 info
.m_itemId
= item
;
2412 m_mainWin
->SetItem( info
);
2415 long wxListCtrl::GetItemData( long item
)
2418 info
.m_itemId
= item
;
2419 m_mainWin
->GetItem( info
);
2423 bool wxListCtrl::SetItemData( long item
, long data
)
2426 info
.m_mask
= wxLIST_MASK_DATA
;
2427 info
.m_itemId
= item
;
2429 m_mainWin
->SetItem( info
);
2433 bool wxListCtrl::GetItemRect( long item
, wxRectangle
&rect
, int WXUNUSED(code
) )
2435 m_mainWin
->GetItemRect( item
, rect
);
2439 bool wxListCtrl::GetItemPosition( long item
, wxPoint
& pos
)
2441 m_mainWin
->GetItemPosition( item
, pos
);
2445 bool wxListCtrl::SetItemPosition( long WXUNUSED(item
), const wxPoint
& WXUNUSED(pos
) )
2450 int wxListCtrl::GetItemCount(void)
2452 return m_mainWin
->GetItemCount();
2455 void wxListCtrl::SetItemSpacing( int spacing
, bool isSmall
)
2457 m_mainWin
->SetItemSpacing( spacing
, isSmall
);
2460 int wxListCtrl::GetItemSpacing( bool isSmall
)
2462 return m_mainWin
->GetItemSpacing( isSmall
);
2465 int wxListCtrl::GetSelectedItemCount(void)
2467 return m_mainWin
->GetSelectedItemCount();
2471 wxColour wxListCtrl::GetTextColour(void) const
2475 void wxListCtrl::SetTextColour(const wxColour& WXUNUSED(col))
2480 long wxListCtrl::GetTopItem(void)
2485 long wxListCtrl::GetNextItem( long item
, int geom
, int state
) const
2487 return m_mainWin
->GetNextItem( item
, geom
, state
);
2490 wxImageList
*wxListCtrl::GetImageList(int which
)
2492 if (which
== wxIMAGE_LIST_NORMAL
)
2494 return m_imageListNormal
;
2496 else if (which
== wxIMAGE_LIST_SMALL
)
2498 return m_imageListSmall
;
2500 else if (which
== wxIMAGE_LIST_STATE
)
2502 return m_imageListState
;
2504 return (wxImageList
*) NULL
;
2507 void wxListCtrl::SetImageList( wxImageList
*imageList
, int which
)
2509 m_mainWin
->SetImageList( imageList
, which
);
2512 bool wxListCtrl::Arrange( int WXUNUSED(flag
) )
2517 bool wxListCtrl::DeleteItem( long item
)
2519 m_mainWin
->DeleteItem( item
);
2523 bool wxListCtrl::DeleteAllItems(void)
2525 m_mainWin
->DeleteAllItems();
2529 bool wxListCtrl::DeleteColumn( int col
)
2531 m_mainWin
->DeleteColumn( col
);
2536 wxText& wxListCtrl::Edit( long WXUNUSED(item ) )
2541 bool wxListCtrl::EnsureVisible( long item
)
2543 m_mainWin
->EnsureVisible( item
);
2547 long wxListCtrl::FindItem( long start
, const wxString
& str
, bool partial
)
2549 return m_mainWin
->FindItem( start
, str
, partial
);
2552 long wxListCtrl::FindItem( long start
, long data
)
2554 return m_mainWin
->FindItem( start
, data
);
2557 long wxListCtrl::FindItem( long WXUNUSED(start
), const wxPoint
& WXUNUSED(pt
),
2558 int WXUNUSED(direction
))
2563 long wxListCtrl::HitTest( const wxPoint
&point
, int &flags
)
2565 return m_mainWin
->HitTest( (int)point
.x
, (int)point
.y
, flags
);
2568 long wxListCtrl::InsertItem( wxListItem
& info
)
2570 m_mainWin
->InsertItem( info
);
2574 long wxListCtrl::InsertItem( long index
, const wxString
&label
)
2577 info
.m_text
= label
;
2578 info
.m_mask
= wxLIST_MASK_TEXT
;
2579 info
.m_itemId
= index
;
2580 return InsertItem( info
);
2583 long wxListCtrl::InsertItem( long index
, int imageIndex
)
2586 info
.m_mask
= wxLIST_MASK_IMAGE
;
2587 info
.m_image
= imageIndex
;
2588 info
.m_itemId
= index
;
2589 return InsertItem( info
);
2592 long wxListCtrl::InsertItem( long index
, const wxString
&label
, int imageIndex
)
2595 info
.m_text
= label
;
2596 info
.m_image
= imageIndex
;
2597 info
.m_mask
= wxLIST_MASK_TEXT
| wxLIST_MASK_IMAGE
;
2598 info
.m_itemId
= index
;
2599 return InsertItem( info
);
2602 long wxListCtrl::InsertColumn( long col
, wxListItem
&item
)
2604 m_mainWin
->InsertColumn( col
, item
);
2608 long wxListCtrl::InsertColumn( long col
, const wxString
&heading
,
2609 int format
, int width
)
2612 item
.m_mask
= wxLIST_MASK_TEXT
| wxLIST_MASK_FORMAT
;
2613 item
.m_text
= heading
;
2616 item
.m_mask
|= wxLIST_MASK_WIDTH
;
2617 item
.m_width
= width
;
2620 item
.m_format
= format
;
2622 return InsertColumn( col
, item
);
2625 bool wxListCtrl::ScrollList( int WXUNUSED(dx
), int WXUNUSED(dy
) )
2631 // fn is a function which takes 3 long arguments: item1, item2, data.
2632 // item1 is the long data associated with a first item (NOT the index).
2633 // item2 is the long data associated with a second item (NOT the index).
2634 // data is the same value as passed to SortItems.
2635 // The return value is a negative number if the first item should precede the second
2636 // item, a positive number of the second item should precede the first,
2637 // or zero if the two items are equivalent.
2638 // data is arbitrary data to be passed to the sort function.
2640 bool wxListCtrl::SortItems( wxListCtrlCompare fn
, long data
)
2642 m_mainWin
->SortItems( fn
, data
);
2646 void wxListCtrl::OnIdle( wxIdleEvent
&WXUNUSED(event
) )
2648 if (!m_mainWin
->m_dirty
) return;
2652 GetClientSize( &cw
, &ch
);
2659 if (GetWindowStyleFlag() & wxLC_REPORT
)
2661 m_headerWin
->GetPosition( &x
, &y
);
2662 m_headerWin
->GetSize( &w
, &h
);
2663 if ((x
!= 0) || (y
!= 0) || (w
!= cw
) || (h
!= 23))
2664 m_headerWin
->SetSize( 0, 0, cw
, 23 );
2666 m_mainWin
->GetPosition( &x
, &y
);
2667 m_mainWin
->GetSize( &w
, &h
);
2668 if ((x
!= 0) || (y
!= 24) || (w
!= cw
) || (h
!= ch
-24))
2669 m_mainWin
->SetSize( 0, 24, cw
, ch
-24 );
2673 m_mainWin
->GetPosition( &x
, &y
);
2674 m_mainWin
->GetSize( &w
, &h
);
2675 if ((x
!= 0) || (y
!= 24) || (w
!= cw
) || (h
!= ch
))
2676 m_mainWin
->SetSize( 0, 0, cw
, ch
);
2679 m_mainWin
->CalculatePositions();
2680 m_mainWin
->RealizeChanges();
2681 m_mainWin
->m_dirty
= FALSE
;
2682 m_mainWin
->Refresh();
2685 void wxListCtrl::SetBackgroundColour( const wxColour
&colour
)
2687 m_mainWin
->SetBackgroundColour( colour
);
2688 m_headerWin
->SetBackgroundColour( colour
);
2689 m_mainWin
->m_dirty
= TRUE
;
2692 void wxListCtrl::SetForegroundColour( const wxColour
&colour
)
2694 m_mainWin
->SetForegroundColour( colour
);
2695 m_headerWin
->SetForegroundColour( colour
);
2696 m_mainWin
->m_dirty
= TRUE
;
2699 void wxListCtrl::SetFont( const wxFont
&font
)
2701 m_mainWin
->SetFont( font
);
2702 m_headerWin
->SetFont( font
);
2703 m_mainWin
->m_dirty
= TRUE
;