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
-= 5;
351 m_bound_hilight
.y
-= 5;
352 m_bound_hilight
.width
+= 9;
353 m_bound_hilight
.height
+= 9;
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
);
370 m_bound_hilight
.x
-= 2;
371 m_bound_hilight
.y
-= 2;
372 m_bound_hilight
.width
+= 4;
373 m_bound_hilight
.height
+= 4;
380 AssignRect( m_bound_label
, m_bound_all
);
383 m_bound_all
.width
+= 4;
384 m_bound_all
.height
+= 4;
385 AssignRect( m_bound_hilight
, m_bound_all
);
386 AssignRect( m_bound_icon
, 0, 0, 0, 0 );
392 dc
->GetTextExtent( "H", &lw
, &lh
);
395 m_bound_all
.height
= lh
+3;
396 m_bound_all
.width
= window_width
;
397 AssignRect( m_bound_hilight
, m_bound_all
);
398 AssignRect( m_bound_label
, 0, 0, 0 ,0 );
399 AssignRect( m_bound_icon
, 0, 0, 0, 0 );
405 void wxListLineData::SetColumnPosition( int index
, int x
)
408 wxNode
*node
= m_items
.Nth( i
);
411 wxListItemData
*item
= (wxListItemData
*)node
->Data();
412 item
->SetPosition( x
, m_bound_all
.y
+1 );
416 void wxListLineData::GetSize( int &width
, int &height
)
418 width
= m_bound_all
.width
;
419 height
= m_bound_all
.height
;
422 void wxListLineData::GetExtent( int &x
, int &y
, int &width
, int &height
)
426 width
= m_bound_all
.width
;
427 height
= m_bound_all
.height
;
430 void wxListLineData::GetLabelExtent( int &x
, int &y
, int &width
, int &height
)
434 width
= m_bound_label
.width
;
435 height
= m_bound_label
.height
;
438 void wxListLineData::GetRect( wxRectangle
&rect
)
440 AssignRect( rect
, m_bound_all
);
443 long wxListLineData::IsHit( int x
, int y
)
445 wxNode
*node
= m_items
.First();
448 wxListItemData
*item
= (wxListItemData
*)node
->Data();
449 if (item
->HasImage() && IsInRect( x
, y
, m_bound_icon
)) return wxLIST_HITTEST_ONITEMICON
;
450 if (item
->HasText() && IsInRect( x
, y
, m_bound_label
)) return wxLIST_HITTEST_ONITEMLABEL
;
451 // if (!(item->HasImage() || item->HasText())) return 0;
453 // if there is no icon or text = empty
454 if (IsInRect( x
, y
, m_bound_all
)) return wxLIST_HITTEST_ONITEMICON
;
458 void wxListLineData::InitItems( int num
)
460 for (int i
= 0; i
< num
; i
++) m_items
.Append( new wxListItemData() );
463 void wxListLineData::SetItem( int index
, const wxListItem
&info
)
465 wxNode
*node
= m_items
.Nth( index
);
468 wxListItemData
*item
= (wxListItemData
*)node
->Data();
469 item
->SetItem( info
);
473 void wxListLineData::GetItem( int const index
, wxListItem
&info
)
476 wxNode
*node
= m_items
.Nth( i
);
479 wxListItemData
*item
= (wxListItemData
*)node
->Data();
480 item
->GetItem( info
);
484 void wxListLineData::GetText( int index
, wxString
&s
)
487 wxNode
*node
= m_items
.Nth( i
);
491 wxListItemData
*item
= (wxListItemData
*)node
->Data();
496 void wxListLineData::SetText( int index
, const wxString s
)
499 wxNode
*node
= m_items
.Nth( i
);
502 wxListItemData
*item
= (wxListItemData
*)node
->Data();
507 int wxListLineData::GetImage( int index
)
510 wxNode
*node
= m_items
.Nth( i
);
513 wxListItemData
*item
= (wxListItemData
*)node
->Data();
514 return item
->GetImage();
519 void wxListLineData::DoDraw( wxPaintDC
*dc
, bool hilight
, bool paintBG
)
521 long dev_x
= dc
->LogicalToDeviceX( m_bound_all
.x
-2 );
522 long dev_y
= dc
->LogicalToDeviceY( m_bound_all
.y
-2 );
523 long dev_w
= dc
->LogicalToDeviceXRel( m_bound_all
.width
+4 );
524 long dev_h
= dc
->LogicalToDeviceYRel( m_bound_all
.height
+4 );
525 if (!m_owner
->IsExposed( dev_x
, dev_y
, dev_w
, dev_h
) ) return;
531 dc
->SetBrush( m_hilightBrush
);
532 dc
->SetPen( wxTRANSPARENT_PEN
);
536 dc
->SetBrush( wxWHITE_BRUSH
);
537 dc
->SetPen( wxTRANSPARENT_PEN
);
539 dc
->DrawRectangle( m_bound_hilight
.x
, m_bound_hilight
.y
,
540 m_bound_hilight
.width
, m_bound_hilight
.height
);
542 if (m_mode
== wxLC_REPORT
)
545 wxNode
*node
= m_items
.First();
548 wxListItemData
*item
= (wxListItemData
*)node
->Data();
549 dc
->SetClippingRegion( item
->GetX(), item
->GetY(), item
->GetWidth()-3, item
->GetHeight() );
550 int x
= item
->GetX();
551 if (item
->HasImage())
554 m_owner
->DrawImage( item
->GetImage(), dc
, x
, item
->GetY() );
555 m_owner
->GetImageSize( item
->GetImage(), x
, y
);
556 x
+= item
->GetX() + 5;
562 dc
->SetTextForeground( wxSystemSettings::GetSystemColour( wxSYS_COLOUR_HIGHLIGHTTEXT
) );
564 dc
->SetTextForeground( *item
->GetColour() );
565 dc
->DrawText( s
, x
, item
->GetY() );
567 dc
->DestroyClippingRegion();
573 wxNode
*node
= m_items
.First();
576 wxListItemData
*item
= (wxListItemData
*)node
->Data();
577 if (item
->HasImage())
579 m_owner
->DrawImage( item
->GetImage(), dc
, m_bound_icon
.x
, m_bound_icon
.y
);
586 dc
->SetTextForeground( wxSystemSettings::GetSystemColour( wxSYS_COLOUR_HIGHLIGHTTEXT
) );
588 dc
->SetTextForeground( * item
->GetColour() );
589 dc
->DrawText( s
, m_bound_label
.x
, m_bound_label
.y
);
595 void wxListLineData::Hilight( bool on
)
597 if (on
== m_hilighted
) return;
599 m_owner
->SelectLine( this );
601 m_owner
->DeselectLine( this );
605 void wxListLineData::ReverseHilight( void )
607 m_hilighted
= !m_hilighted
;
609 m_owner
->SelectLine( this );
611 m_owner
->DeselectLine( this );
614 void wxListLineData::DrawRubberBand( wxPaintDC
*dc
, bool on
)
618 dc
->SetPen( wxBLACK_PEN
);
619 dc
->SetBrush( wxTRANSPARENT_BRUSH
);
620 dc
->DrawRectangle( m_bound_hilight
.x
, m_bound_hilight
.y
,
621 m_bound_hilight
.width
, m_bound_hilight
.height
);
625 void wxListLineData::Draw( wxPaintDC
*dc
)
627 DoDraw( dc
, m_hilighted
, m_hilighted
);
630 bool wxListLineData::IsInRect( int x
, int y
, const wxRectangle
&rect
)
632 return ((x
>= rect
.x
) && (x
<= rect
.x
+rect
.width
) && (y
>= rect
.y
) && (y
<= rect
.y
+rect
.height
));
635 bool wxListLineData::IsHilighted( void )
640 void wxListLineData::AssignRect( wxRectangle
&dest
, int x
, int y
, int width
, int height
)
645 dest
.height
= height
;
648 void wxListLineData::AssignRect( wxRectangle
&dest
, const wxRectangle
&source
)
652 dest
.width
= source
.width
;
653 dest
.height
= source
.height
;
656 //-----------------------------------------------------------------------------
657 // wxListHeaderWindow
658 //-----------------------------------------------------------------------------
660 IMPLEMENT_DYNAMIC_CLASS(wxListHeaderWindow
,wxWindow
);
662 BEGIN_EVENT_TABLE(wxListHeaderWindow
,wxWindow
)
663 EVT_PAINT (wxListHeaderWindow::OnPaint
)
664 EVT_MOUSE_EVENTS (wxListHeaderWindow::OnMouse
)
665 EVT_SET_FOCUS (wxListHeaderWindow::OnSetFocus
)
668 wxListHeaderWindow::wxListHeaderWindow( void )
670 m_owner
= (wxListMainWindow
*) NULL
;
671 m_currentCursor
= (wxCursor
*) NULL
;
672 m_resizeCursor
= (wxCursor
*) NULL
;
676 wxListHeaderWindow::wxListHeaderWindow( wxWindow
*win
, wxWindowID id
, wxListMainWindow
*owner
,
677 const wxPoint
&pos
, const wxSize
&size
,
678 long style
, const wxString
&name
) :
679 wxWindow( win
, id
, pos
, size
, style
, name
)
682 // m_currentCursor = wxSTANDARD_CURSOR;
683 m_currentCursor
= (wxCursor
*) NULL
;
684 m_resizeCursor
= new wxCursor( wxCURSOR_SIZEWE
);
688 wxListHeaderWindow::~wxListHeaderWindow( void )
690 delete m_resizeCursor
;
693 void wxListHeaderWindow::DoDrawRect( wxPaintDC
*dc
, int x
, int y
, int w
, int h
)
695 const int m_corner
= 1;
697 dc
->SetBrush( *wxTRANSPARENT_BRUSH
);
699 dc
->SetPen( *wxBLACK_PEN
);
700 dc
->DrawLine( x
+w
-m_corner
+1, y
, x
+w
, y
+h
); // right (outer)
701 dc
->DrawRectangle( x
, y
+h
, w
, 1 ); // bottom (outer)
703 dc
->SetPen( *wxMEDIUM_GREY_PEN
);
704 dc
->DrawLine( x
+w
-m_corner
, y
, x
+w
-1, y
+h
); // right (inner)
705 dc
->DrawRectangle( x
+1, y
+h
-1, w
-2, 1 ); // bottom (inner)
707 dc
->SetPen( *wxWHITE_PEN
);
708 dc
->DrawRectangle( x
, y
, w
-m_corner
+1, 1 ); // top (outer)
709 // dc->DrawRectangle( x, y+1, w-m_corner, 1 ); // top (inner)
710 dc
->DrawRectangle( x
, y
, 1, h
); // left (outer)
711 // dc->DrawRectangle( x+1, y, 1, h-1 ); // left (inner)
714 void wxListHeaderWindow::OnPaint( wxPaintEvent
&WXUNUSED(event
) )
716 wxPaintDC
dc( this );
721 dc
.SetFont( *GetFont() );
727 GetClientSize( &w
, &h
);
729 dc
.SetTextForeground( *wxBLACK
);
730 if (m_foregroundColour
.Ok()) dc
.SetTextForeground( m_foregroundColour
);
734 int numColumns
= m_owner
->GetColumnCount();
736 for (int i
= 0; i
< numColumns
; i
++)
738 m_owner
->GetColumn( i
, item
);
739 int cw
= item
.m_width
-2;
740 if ((i
+1 == numColumns
) || (x
+item
.m_width
> w
-5)) cw
= w
-x
-1;
741 dc
.SetPen( *wxWHITE_PEN
);
743 DoDrawRect( &dc
, x
, y
, cw
, h
-2 );
744 dc
.SetClippingRegion( x
, y
, cw
-5, h
-4 );
745 dc
.DrawText( item
.m_text
, x
+4, y
+3 );
746 dc
.DestroyClippingRegion();
753 void wxListHeaderWindow::DrawCurrent()
757 int x2
= m_currentX
-1;
760 m_owner
->GetClientSize( &dummy
, &y2
);
761 ClientToScreen( &x1
, &y1
);
762 m_owner
->ClientToScreen( &x2
, &y2
);
765 dc
.SetLogicalFunction( wxXOR
);
766 dc
.SetPen( wxPen( *wxBLACK
, 2, wxSOLID
) );
767 dc
.SetBrush( *wxTRANSPARENT_BRUSH
);
769 dc
.DrawLine( x1
, y1
, x2
, y2
);
771 dc
.SetLogicalFunction( wxCOPY
);
773 dc
.SetPen( wxNullPen
);
774 dc
.SetBrush( wxNullBrush
);
777 void wxListHeaderWindow::OnMouse( wxMouseEvent
&event
)
779 int x
= event
.GetX();
780 int y
= event
.GetY();
784 if (event
.ButtonUp())
788 m_owner
->SetColumnWidth( m_column
, m_currentX
-m_minX
);
794 GetClientSize( &size_x
, & dummy
);
798 m_currentX
= m_minX
+7;
799 if (m_currentX
> size_x
-7) m_currentX
= size_x
-7;
806 bool hit_border
= FALSE
;
808 for (int j
= 0; j
< m_owner
->GetColumnCount(); j
++)
810 xpos
+= m_owner
->GetColumnWidth( j
);
811 if ((abs(x
-xpos
) < 3) && (y
< 22))
820 if (event
.LeftDown() && hit_border
)
833 if (m_currentCursor
== wxSTANDARD_CURSOR
) SetCursor( m_resizeCursor
);
834 m_currentCursor
= m_resizeCursor
;
838 if (m_currentCursor
!= wxSTANDARD_CURSOR
) SetCursor( wxSTANDARD_CURSOR
);
839 m_currentCursor
= wxSTANDARD_CURSOR
;
844 void wxListHeaderWindow::OnSetFocus( wxFocusEvent
&WXUNUSED(event
) )
849 //-----------------------------------------------------------------------------
850 // wxListRenameTimer (internal)
851 //-----------------------------------------------------------------------------
853 wxListRenameTimer::wxListRenameTimer( wxListMainWindow
*owner
)
858 void wxListRenameTimer::Notify()
860 m_owner
->OnRenameTimer();
863 //-----------------------------------------------------------------------------
864 // wxListTextCtrl (internal)
865 //-----------------------------------------------------------------------------
867 IMPLEMENT_DYNAMIC_CLASS(wxListTextCtrl
,wxTextCtrl
);
869 BEGIN_EVENT_TABLE(wxListTextCtrl
,wxTextCtrl
)
870 EVT_CHAR (wxListTextCtrl::OnChar
)
871 EVT_KILL_FOCUS (wxListTextCtrl::OnKillFocus
)
874 wxListTextCtrl::wxListTextCtrl( wxWindow
*parent
, const wxWindowID id
,
875 bool *accept
, wxString
*res
, wxListMainWindow
*owner
,
876 const wxString
&value
, const wxPoint
&pos
, const wxSize
&size
,
877 int style
, const wxValidator
& validator
, const wxString
&name
) :
878 wxTextCtrl( parent
, id
, value
, pos
, size
, style
, validator
, name
)
885 void wxListTextCtrl::OnChar( wxKeyEvent
&event
)
887 if (event
.m_keyCode
== WXK_RETURN
)
890 (*m_res
) = GetValue();
891 m_owner
->OnRenameAccept();
896 if (event
.m_keyCode
== WXK_ESCAPE
)
907 void wxListTextCtrl::OnKillFocus( wxFocusEvent
&WXUNUSED(event
) )
916 //-----------------------------------------------------------------------------
918 //-----------------------------------------------------------------------------
920 IMPLEMENT_DYNAMIC_CLASS(wxListMainWindow
,wxScrolledWindow
);
922 BEGIN_EVENT_TABLE(wxListMainWindow
,wxScrolledWindow
)
923 EVT_PAINT (wxListMainWindow::OnPaint
)
924 EVT_SIZE (wxListMainWindow::OnSize
)
925 EVT_MOUSE_EVENTS (wxListMainWindow::OnMouse
)
926 EVT_CHAR (wxListMainWindow::OnChar
)
927 EVT_SET_FOCUS (wxListMainWindow::OnSetFocus
)
928 EVT_KILL_FOCUS (wxListMainWindow::OnKillFocus
)
931 wxListMainWindow::wxListMainWindow( void )
934 m_lines
.DeleteContents( TRUE
);
935 m_columns
.DeleteContents( TRUE
);
936 m_current
= (wxListLineData
*) NULL
;
938 m_hilightBrush
= (wxBrush
*) NULL
;
942 m_small_image_list
= (wxImageList
*) NULL
;
943 m_normal_image_list
= (wxImageList
*) NULL
;
944 m_small_spacing
= 30;
945 m_normal_spacing
= 40;
948 m_lastOnSame
= FALSE
;
949 m_renameTimer
= new wxListRenameTimer( this );
954 wxListMainWindow::wxListMainWindow( wxWindow
*parent
, wxWindowID id
,
955 const wxPoint
&pos
, const wxSize
&size
,
956 long style
, const wxString
&name
) :
957 wxScrolledWindow( parent
, id
, pos
, size
, style
|wxHSCROLL
|wxVSCROLL
, name
)
960 m_lines
.DeleteContents( TRUE
);
961 m_columns
.DeleteContents( TRUE
);
962 m_current
= (wxListLineData
*) NULL
;
965 m_hilightBrush
= new wxBrush( wxSystemSettings::GetSystemColour(wxSYS_COLOUR_HIGHLIGHT
), wxSOLID
);
966 m_small_image_list
= (wxImageList
*) NULL
;
967 m_normal_image_list
= (wxImageList
*) NULL
;
968 m_small_spacing
= 30;
969 m_normal_spacing
= 40;
970 // AllowDoubleClick( TRUE );
977 if (m_mode
& wxLC_REPORT
)
987 SetScrollbars( m_xScroll
, m_yScroll
, 0, 0, 0, 0 );
990 m_lastOnSame
= FALSE
;
991 m_renameTimer
= new wxListRenameTimer( this );
992 m_renameAccept
= FALSE
;
993 // m_text = new wxRawListTextCtrl( GetParent(), "", &m_renameAccept, &m_renameRes, this, 10, 10, 40, 10 );
994 // m_text->Show( FALSE );
996 SetBackgroundColour( *wxWHITE
);
999 wxListMainWindow::~wxListMainWindow( void )
1001 if (m_hilightBrush
) delete m_hilightBrush
;
1002 delete m_renameTimer
;
1003 // if (m_hilightColour) delete m_hilightColour;
1007 void wxListMainWindow::RefreshLine( wxListLineData
*line
)
1015 wxClientDC
dc(this);
1017 line
->GetExtent( x
, y
, w
, h
);
1019 dc
.LogicalToDeviceX(x
-3),
1020 dc
.LogicalToDeviceY(y
-3),
1021 dc
.LogicalToDeviceXRel(w
+6),
1022 dc
.LogicalToDeviceXRel(h
+6) );
1023 Refresh( TRUE
, &rect
);
1027 void wxListMainWindow::OnPaint( wxPaintEvent
&WXUNUSED(event
) )
1029 if (m_dirty
) return;
1031 wxPaintDC
dc( this );
1036 dc
.SetFont( *GetFont() );
1038 wxNode
*node
= m_lines
.First();
1041 wxListLineData
*line
= (wxListLineData
*)node
->Data();
1043 node
= node
->Next();
1045 if (m_current
) m_current
->DrawRubberBand( &dc
, m_hasFocus
);
1050 void wxListMainWindow::HilightAll( bool on
)
1052 wxNode
*node
= m_lines
.First();
1055 wxListLineData
*line
= (wxListLineData
*)node
->Data();
1056 if (line
->IsHilighted() != on
)
1058 line
->Hilight( on
);
1059 RefreshLine( line
);
1061 node
= node
->Next();
1065 void wxListMainWindow::ActivateLine( wxListLineData
*line
)
1067 if (!GetParent()) return;
1068 wxListEvent
le( wxEVT_COMMAND_LIST_KEY_DOWN
, GetParent()->GetId() );
1069 le
.SetEventObject( GetParent() );
1071 le
.m_itemIndex
= GetIndexOfLine( line
);
1073 line
->GetItem( 0, le
.m_item
);
1077 void wxListMainWindow::SendNotify( wxListLineData
*line
, wxEventType command
)
1079 if (!GetParent()) return;
1080 wxListEvent
le( command
, GetParent()->GetId() );
1081 le
.SetEventObject( GetParent() );
1083 le
.m_itemIndex
= GetIndexOfLine( line
);
1085 line
->GetItem( 0, le
.m_item
);
1089 void wxListMainWindow::FocusLine( wxListLineData
*WXUNUSED(line
) )
1091 // SendNotify( line, wxEVT_COMMAND_LIST_ITEM_FOCUSSED );
1094 void wxListMainWindow::UnfocusLine( wxListLineData
*WXUNUSED(line
) )
1096 // SendNotify( line, wxEVT_COMMAND_LIST_ITEM_UNFOCUSSED );
1099 void wxListMainWindow::SelectLine( wxListLineData
*line
)
1101 SendNotify( line
, wxEVT_COMMAND_LIST_ITEM_SELECTED
);
1104 void wxListMainWindow::DeselectLine( wxListLineData
*line
)
1106 SendNotify( line
, wxEVT_COMMAND_LIST_ITEM_DESELECTED
);
1109 void wxListMainWindow::DeleteLine( wxListLineData
*line
)
1111 SendNotify( line
, wxEVT_COMMAND_LIST_DELETE_ITEM
);
1114 void wxListMainWindow::StartLabelEdit( wxListLineData
*line
)
1116 SendNotify( line
, wxEVT_COMMAND_LIST_BEGIN_LABEL_EDIT
);
1119 void wxListMainWindow::RenameLine( wxListLineData
*line
, const wxString
&newName
)
1121 if (!GetParent()) return;
1123 wxListEvent
le( wxEVT_COMMAND_LIST_END_LABEL_EDIT
, GetParent()->GetId() );
1124 le
.SetEventObject( GetParent() );
1126 le
.m_itemIndex
= GetIndexOfLine( line
);
1128 line
->GetItem( 0, le
.m_item
);
1129 le
.m_item
.m_text
= newName
;
1133 void wxListMainWindow::OnRenameTimer()
1135 StartLabelEdit( m_current
);
1137 m_current
->GetText( 0, s
);
1142 m_current
->GetLabelExtent( x
, y
, w
, h
);
1144 wxClientDC
dc(this);
1146 x
= dc
.LogicalToDeviceX( x
);
1147 y
= dc
.LogicalToDeviceY( y
);
1149 wxListTextCtrl
*text
= new wxListTextCtrl(
1150 this, -1, &m_renameAccept
, &m_renameRes
, this, s
, wxPoint(x
-4,y
-4), wxSize(w
+11,h
+8) );
1153 m_text->SetSize( x+3, y+3, w+6, h+6 );
1154 m_text->SetValue( s );
1155 m_text->Show( TRUE );
1159 char *res = wxGetTextFromUser( _("Enter new name:"), "", s );
1164 RenameLine( m_current, s );
1169 void wxListMainWindow::OnRenameAccept()
1171 RenameLine( m_current
, m_renameRes
);
1174 void wxListMainWindow::OnMouse( wxMouseEvent
&event
)
1176 if (GetParent()->GetEventHandler()->ProcessEvent( event
)) return;
1178 if (!m_current
) return;
1179 if (m_dirty
) return;
1181 wxClientDC
dc(this);
1183 long x
= dc
.DeviceToLogicalX( (long)event
.GetX() );
1184 long y
= dc
.DeviceToLogicalY( (long)event
.GetY() );
1187 wxNode
*node
= m_lines
.First();
1188 wxListLineData
*line
= (wxListLineData
*) NULL
;
1191 line
= (wxListLineData
*)node
->Data();
1192 hitResult
= line
->IsHit( x
, y
);
1193 if (hitResult
) break;
1194 line
= (wxListLineData
*) NULL
;
1195 node
= node
->Next();
1198 if (!event
.Dragging())
1203 if (event
.Dragging() && (m_dragCount
> 3))
1206 wxListEvent
le( wxEVT_COMMAND_LIST_BEGIN_DRAG
, GetParent()->GetId() );
1207 le
.SetEventObject( this );
1216 if (event
.ButtonDClick())
1219 m_lastOnSame
= FALSE
;
1220 m_renameTimer
->Stop();
1221 ActivateLine( line
);
1225 if (event
.LeftUp() && m_lastOnSame
)
1228 if ((line
== m_current
) &&
1229 (hitResult
== wxLIST_HITTEST_ONITEMLABEL
) &&
1230 // (m_mode & wxLC_ICON) &&
1231 (m_mode
& wxLC_EDIT_LABELS
) )
1233 m_renameTimer
->Start( 100, TRUE
);
1235 m_lastOnSame
= FALSE
;
1239 if (event
.LeftDown())
1242 wxListLineData
*oldCurrent
= m_current
;
1243 if (m_mode
& wxLC_SINGLE_SEL
)
1246 HilightAll( FALSE
);
1247 m_current
->ReverseHilight();
1248 RefreshLine( m_current
);
1252 if (event
.ShiftDown())
1255 m_current
->ReverseHilight();
1256 RefreshLine( m_current
);
1258 else if (event
.ControlDown())
1261 int numOfCurrent
= -1;
1262 node
= m_lines
.First();
1265 wxListLineData
*test_line
= (wxListLineData
*)node
->Data();
1267 if (test_line
== oldCurrent
) break;
1268 node
= node
->Next();
1271 node
= m_lines
.First();
1274 wxListLineData
*test_line
= (wxListLineData
*)node
->Data();
1276 if (test_line
== line
) break;
1277 node
= node
->Next();
1280 if (numOfLine
< numOfCurrent
)
1281 { int i
= numOfLine
; numOfLine
= numOfCurrent
; numOfCurrent
= i
; }
1282 wxNode
*node
= m_lines
.Nth( numOfCurrent
);
1283 for (int i
= 0; i
<= numOfLine
-numOfCurrent
; i
++)
1285 wxListLineData
*test_line
= (wxListLineData
*)node
->Data();
1286 test_line
->Hilight(TRUE
);
1287 RefreshLine( test_line
);
1288 node
= node
->Next();
1294 HilightAll( FALSE
);
1295 m_current
->ReverseHilight();
1296 RefreshLine( m_current
);
1299 if (m_current
!= oldCurrent
)
1301 RefreshLine( oldCurrent
);
1302 UnfocusLine( oldCurrent
);
1303 FocusLine( m_current
);
1305 m_lastOnSame
= (m_current
== oldCurrent
);
1311 void wxListMainWindow::MoveToFocus( void )
1313 if (!m_current
) return;
1319 m_current->GetExtent( x, y, w, h );
1322 GetClientSize( &w_p, &h_p );
1323 if (m_mode & wxLC_REPORT)
1325 if (GetScrollPos( wxHORIZONTAL ) != 0) SetScrollPos( wxHORIZONTAL, 0);
1326 int y_s = m_yScroll*GetScrollPos( wxVERTICAL );
1327 if ((y > y_s) && (y+h < y_s+h_p)) return;
1328 if (y-y_s < 5) SetScrollPos( wxVERTICAL, (y-5)/m_yScroll );
1329 if (y+h+5 > y_s+h_p) SetScrollPos( wxVERTICAL, (y+h-h_p+h+5)/m_yScroll );
1333 if (GetScrollPos( wxVERTICAL ) != 0) SetScrollPos( wxVERTICAL, 0);
1334 int x_s = m_xScroll*GetScrollPos( wxHORIZONTAL );
1335 if ((x > x_s) && (x+w < x_s+w_p)) return;
1336 if (x-x_s < 5) SetScrollPos( wxHORIZONTAL, (x-5)/m_xScroll );
1337 if (x+w > x_s+w_p) SetScrollPos( wxHORIZONTAL, (x+w-w_p+5)/m_xScroll );
1342 void wxListMainWindow::OnArrowChar( wxListLineData
*newCurrent
, bool shiftDown
)
1344 if ((m_mode
& wxLC_SINGLE_SEL
) || (m_usedKeys
== FALSE
)) m_current
->Hilight( FALSE
);
1345 wxListLineData
*oldCurrent
= m_current
;
1346 m_current
= newCurrent
;
1348 if (shiftDown
|| (m_mode
& wxLC_SINGLE_SEL
)) m_current
->Hilight( TRUE
);
1349 RefreshLine( m_current
);
1350 RefreshLine( oldCurrent
);
1351 FocusLine( m_current
);
1352 UnfocusLine( oldCurrent
);
1355 void wxListMainWindow::OnChar( wxKeyEvent
&event
)
1358 if (event.KeyCode() == WXK_TAB)
1360 if (event.ShiftDown())
1367 if (!m_current
) return;
1368 switch (event
.KeyCode())
1372 wxNode
*node
= m_lines
.Member( m_current
)->Previous();
1373 if (node
) OnArrowChar( (wxListLineData
*)node
->Data(), event
.ShiftDown() );
1378 wxNode
*node
= m_lines
.Member( m_current
)->Next();
1379 if (node
) OnArrowChar( (wxListLineData
*)node
->Data(), event
.ShiftDown() );
1384 wxNode
*node
= m_lines
.Last();
1385 OnArrowChar( (wxListLineData
*)node
->Data(), event
.ShiftDown() );
1390 wxNode
*node
= m_lines
.First();
1391 OnArrowChar( (wxListLineData
*)node
->Data(), event
.ShiftDown() );
1397 if (m_mode
& wxLC_REPORT
) { steps
= m_visibleLines
-1; }
1401 wxNode
*node
= m_lines
.First();
1402 for (;;) { if (m_current
== (wxListLineData
*)node
->Data()) break; pos
++; node
= node
->Next(); }
1403 steps
= pos
% m_visibleLines
;
1405 wxNode
*node
= m_lines
.Member( m_current
);
1406 for (int i
= 0; i
< steps
; i
++) if (node
->Previous()) node
= node
->Previous();
1407 if (node
) OnArrowChar( (wxListLineData
*)node
->Data(), event
.ShiftDown() );
1413 if (m_mode
& wxLC_REPORT
) { steps
= m_visibleLines
-1; }
1416 int pos
= 0; wxNode
*node
= m_lines
.First();
1417 for (;;) { if (m_current
== (wxListLineData
*)node
->Data()) break; pos
++; node
= node
->Next(); }
1418 steps
= m_visibleLines
-(pos
% m_visibleLines
)-1;
1420 wxNode
*node
= m_lines
.Member( m_current
);
1421 for (int i
= 0; i
< steps
; i
++) if (node
->Next()) node
= node
->Next();
1422 if (node
) OnArrowChar( (wxListLineData
*)node
->Data(), event
.ShiftDown() );
1427 if (!(m_mode
& wxLC_REPORT
))
1429 wxNode
*node
= m_lines
.Member( m_current
);
1430 for (int i
= 0; i
<m_visibleLines
; i
++) if (node
->Previous()) node
= node
->Previous();
1431 if (node
) OnArrowChar( (wxListLineData
*)node
->Data(), event
.ShiftDown() );
1437 if (!(m_mode
& wxLC_REPORT
))
1439 wxNode
*node
= m_lines
.Member( m_current
);
1440 for (int i
= 0; i
<m_visibleLines
; i
++) if (node
->Next()) node
= node
->Next();
1441 if (node
) OnArrowChar( (wxListLineData
*)node
->Data(), event
.ShiftDown() );
1447 m_current
->ReverseHilight();
1448 RefreshLine( m_current
);
1453 if (!(m_mode
& wxLC_SINGLE_SEL
))
1455 wxListLineData
*oldCurrent
= m_current
;
1456 m_current
->ReverseHilight();
1457 wxNode
*node
= m_lines
.Member( m_current
)->Next();
1458 if (node
) m_current
= (wxListLineData
*)node
->Data();
1460 RefreshLine( oldCurrent
);
1461 RefreshLine( m_current
);
1462 UnfocusLine( oldCurrent
);
1463 FocusLine( m_current
);
1470 ActivateLine( m_current
);
1482 void wxListMainWindow::OnSetFocus( wxFocusEvent
&WXUNUSED(event
) )
1485 RefreshLine( m_current
);
1487 if (!GetParent()) return;
1489 wxFocusEvent
event( wxEVT_SET_FOCUS
, GetParent()->GetId() );
1490 event
.SetEventObject( GetParent() );
1491 GetParent()->GetEventHandler()->ProcessEvent( event
);
1494 void wxListMainWindow::OnKillFocus( wxFocusEvent
&WXUNUSED(event
) )
1497 RefreshLine( m_current
);
1500 void wxListMainWindow::OnSize( wxSizeEvent
&WXUNUSED(event
) )
1503 We don't even allow the wxScrolledWindow::AdjustScrollbars() call
1505 CalculatePositions();
1506 printf( "OnSize::Refresh.\n" );
1512 void wxListMainWindow::DrawImage( int index
, wxPaintDC
*dc
, int x
, int y
)
1514 if ((m_mode
& wxLC_ICON
) && (m_normal_image_list
))
1516 m_normal_image_list
->Draw( index
, *dc
, x
, y
, wxIMAGELIST_DRAW_TRANSPARENT
);
1519 if ((m_mode
& wxLC_SMALL_ICON
) && (m_small_image_list
))
1521 m_small_image_list
->Draw( index
, *dc
, x
, y
, wxIMAGELIST_DRAW_TRANSPARENT
);
1523 if ((m_mode
& wxLC_REPORT
) && (m_small_image_list
))
1525 m_small_image_list
->Draw( index
, *dc
, x
, y
, wxIMAGELIST_DRAW_TRANSPARENT
);
1530 void wxListMainWindow::GetImageSize( int index
, int &width
, int &height
)
1532 if ((m_mode
& wxLC_ICON
) && (m_normal_image_list
))
1534 m_normal_image_list
->GetSize( index
, width
, height
);
1537 if ((m_mode
& wxLC_SMALL_ICON
) && (m_small_image_list
))
1539 m_small_image_list
->GetSize( index
, width
, height
);
1542 if ((m_mode
& wxLC_REPORT
) && (m_small_image_list
))
1544 m_small_image_list
->GetSize( index
, width
, height
);
1551 int wxListMainWindow::GetTextLength( wxString
&s
)
1553 wxPaintDC
dc( this );
1556 dc
.GetTextExtent( s
, &lw
, &lh
);
1560 int wxListMainWindow::GetIndexOfLine( const wxListLineData
*line
)
1563 wxNode
*node
= m_lines
.First();
1566 if (line
== (wxListLineData
*)node
->Data()) return i
;
1568 node
= node
->Next();
1573 void wxListMainWindow::SetImageList( wxImageList
*imageList
, int which
)
1576 if (which
== wxIMAGE_LIST_NORMAL
) m_normal_image_list
= imageList
;
1577 if (which
== wxIMAGE_LIST_SMALL
) m_small_image_list
= imageList
;
1580 void wxListMainWindow::SetItemSpacing( int spacing
, bool isSmall
)
1585 m_small_spacing
= spacing
;
1589 m_normal_spacing
= spacing
;
1593 int wxListMainWindow::GetItemSpacing( bool isSmall
)
1595 if (isSmall
) return m_small_spacing
; else return m_normal_spacing
;
1598 void wxListMainWindow::SetColumn( int col
, wxListItem
&item
)
1601 wxNode
*node
= m_columns
.Nth( col
);
1604 if (item
.m_width
== wxLIST_AUTOSIZE_USEHEADER
) item
.m_width
= GetTextLength( item
.m_text
)+7;
1605 wxListHeaderData
*column
= (wxListHeaderData
*)node
->Data();
1606 column
->SetItem( item
);
1608 wxListCtrl
*lc
= (wxListCtrl
*) GetParent();
1609 if (lc
->m_headerWin
) lc
->m_headerWin
->Refresh();
1612 void wxListMainWindow::SetColumnWidth( int col
, int width
)
1614 if (!(m_mode
& wxLC_REPORT
)) return;
1618 wxNode
*node
= m_columns
.Nth( col
);
1621 wxListHeaderData
*column
= (wxListHeaderData
*)node
->Data();
1622 column
->SetWidth( width
);
1625 node
= m_lines
.First();
1628 wxListLineData
*line
= (wxListLineData
*)node
->Data();
1629 wxNode
*n
= line
->m_items
.Nth( col
);
1632 wxListItemData
*item
= (wxListItemData
*)n
->Data();
1633 item
->SetSize( width
, -1 );
1635 node
= node
->Next();
1638 wxListCtrl
*lc
= (wxListCtrl
*) GetParent();
1639 if (lc
->m_headerWin
) lc
->m_headerWin
->Refresh();
1642 void wxListMainWindow::GetColumn( int col
, wxListItem
&item
)
1644 wxNode
*node
= m_columns
.Nth( col
);
1647 wxListHeaderData
*column
= (wxListHeaderData
*)node
->Data();
1648 column
->GetItem( item
);
1660 int wxListMainWindow::GetColumnWidth( int col
)
1662 wxNode
*node
= m_columns
.Nth( col
);
1665 wxListHeaderData
*column
= (wxListHeaderData
*)node
->Data();
1666 return column
->GetWidth();
1672 int wxListMainWindow::GetColumnCount( void )
1674 return m_columns
.Number();
1677 int wxListMainWindow::GetCountPerPage( void )
1679 return m_visibleLines
;
1682 void wxListMainWindow::SetItem( wxListItem
&item
)
1685 wxNode
*node
= m_lines
.Nth( item
.m_itemId
);
1688 wxListLineData
*line
= (wxListLineData
*)node
->Data();
1689 if (m_mode
& wxLC_REPORT
) item
.m_width
= GetColumnWidth( item
.m_col
)-3;
1690 line
->SetItem( item
.m_col
, item
);
1694 void wxListMainWindow::SetItemState( long item
, long state
, long stateMask
)
1696 // m_dirty = TRUE; no recalcs needed
1698 wxListLineData
*oldCurrent
= m_current
;
1700 if (stateMask
& wxLIST_STATE_FOCUSED
)
1702 wxNode
*node
= m_lines
.Nth( item
);
1705 wxListLineData
*line
= (wxListLineData
*)node
->Data();
1706 UnfocusLine( m_current
);
1708 FocusLine( m_current
);
1709 RefreshLine( m_current
);
1710 RefreshLine( oldCurrent
);
1714 if (stateMask
& wxLIST_STATE_SELECTED
)
1716 bool on
= state
& wxLIST_STATE_SELECTED
;
1717 if (!on
&& (m_mode
& wxLC_SINGLE_SEL
)) return;
1719 wxNode
*node
= m_lines
.Nth( item
);
1722 wxListLineData
*line
= (wxListLineData
*)node
->Data();
1723 if (m_mode
& wxLC_SINGLE_SEL
)
1725 UnfocusLine( m_current
);
1727 FocusLine( m_current
);
1728 oldCurrent
->Hilight( FALSE
);
1729 RefreshLine( m_current
);
1730 RefreshLine( oldCurrent
);
1732 bool on
= state
& wxLIST_STATE_SELECTED
;
1733 line
->Hilight( on
);
1734 RefreshLine( line
);
1739 int wxListMainWindow::GetItemState( long item
, long stateMask
)
1741 int ret
= wxLIST_STATE_DONTCARE
;
1742 if (stateMask
& wxLIST_STATE_FOCUSED
)
1744 wxNode
*node
= m_lines
.Nth( item
);
1747 wxListLineData
*line
= (wxListLineData
*)node
->Data();
1748 if (line
== m_current
) ret
|= wxLIST_STATE_FOCUSED
;
1751 if (stateMask
& wxLIST_STATE_SELECTED
)
1753 wxNode
*node
= m_lines
.Nth( item
);
1756 wxListLineData
*line
= (wxListLineData
*)node
->Data();
1757 if (line
->IsHilighted()) ret
|= wxLIST_STATE_FOCUSED
;
1763 void wxListMainWindow::GetItem( wxListItem
&item
)
1765 wxNode
*node
= m_lines
.Nth( item
.m_itemId
);
1768 wxListLineData
*line
= (wxListLineData
*)node
->Data();
1769 line
->GetItem( item
.m_col
, item
);
1780 int wxListMainWindow::GetItemCount( void )
1782 return m_lines
.Number();
1785 void wxListMainWindow::GetItemRect( long index
, wxRectangle
&rect
)
1787 wxNode
*node
= m_lines
.Nth( index
);
1790 wxListLineData
*line
= (wxListLineData
*)node
->Data();
1791 line
->GetRect( rect
);
1802 bool wxListMainWindow::GetItemPosition(long item
, wxPoint
& pos
)
1804 wxNode
*node
= m_lines
.Nth( item
);
1808 wxListLineData
*line
= (wxListLineData
*)node
->Data();
1809 line
->GetRect( rect
);
1821 int wxListMainWindow::GetSelectedItemCount( void )
1824 wxNode
*node
= m_lines
.First();
1827 wxListLineData
*line
= (wxListLineData
*)node
->Data();
1828 if (line
->IsHilighted()) ret
++;
1829 node
= node
->Next();
1834 void wxListMainWindow::SetMode( long mode
)
1841 if (m_mode
& wxLC_REPORT
)
1853 long wxListMainWindow::GetMode( void ) const
1858 void wxListMainWindow::CalculatePositions( void )
1860 wxPaintDC
dc( this );
1861 dc
.SetFont( *GetFont() );
1863 int iconSpacing
= 0;
1864 if (m_mode
& wxLC_ICON
) iconSpacing
= m_normal_spacing
;
1865 if (m_mode
& wxLC_SMALL_ICON
) iconSpacing
= m_small_spacing
;
1866 wxNode
*node
= m_lines
.First();
1869 wxListLineData
*line
= (wxListLineData
*)node
->Data();
1870 line
->CalculateSize( &dc
, iconSpacing
);
1871 node
= node
->Next();
1876 int lineSpacing
= 0;
1878 node
= m_lines
.First();
1881 wxListLineData
*line
= (wxListLineData
*)node
->Data();
1883 line
->GetSize( dummy
, lineSpacing
);
1889 lineSpacing
= 4 + (int)dc
.GetCharHeight();
1892 int clientWidth
= 0;
1893 int clientHeight
= 0;
1895 if (m_mode
& wxLC_REPORT
)
1899 int entireHeight
= m_lines
.Number() * lineSpacing
+ 10;
1900 SetScrollbars( m_xScroll
, m_yScroll
, 0, (entireHeight
+10) / m_yScroll
, 0, 0, TRUE
);
1901 GetClientSize( &clientWidth
, &clientHeight
);
1903 node
= m_lines
.First();
1906 wxListLineData
*line
= (wxListLineData
*)node
->Data();
1907 line
->SetPosition( &dc
, x
, y
, clientWidth
);
1909 for (int i
= 0; i
< GetColumnCount(); i
++)
1911 line
->SetColumnPosition( i
, col_x
);
1912 col_x
+= GetColumnWidth( i
);
1915 node
= node
->Next();
1920 // At first, we try without any scrollbar
1921 GetSize( &clientWidth
, &clientHeight
);
1923 int entireWidth
= 0;
1925 for (int tries
= 0; tries
< 2; tries
++)
1931 node
= m_lines
.First();
1934 wxListLineData
*line
= (wxListLineData
*)node
->Data();
1935 line
->SetPosition( &dc
, x
, y
, clientWidth
);
1936 line
->GetSize( lineWidth
, lineHeight
);
1937 if (lineWidth
> maxWidth
) maxWidth
= lineWidth
;
1939 if (y
+lineHeight
> clientHeight
-4)
1943 entireWidth
+= maxWidth
+13;
1946 node
= node
->Next();
1947 if (!node
) entireWidth
+= maxWidth
;
1948 if ((tries
== 0) && (entireWidth
> clientWidth
))
1950 clientHeight
-= 14; // scrollbar height
1953 if (!node
) tries
= 1;
1956 SetScrollbars( m_xScroll
, m_yScroll
, (entireWidth
+15) / m_xScroll
, 0, 0, 0, TRUE
);
1958 m_visibleLines
= (clientHeight
-4) / (lineSpacing
);
1961 void wxListMainWindow::RealizeChanges( void )
1965 wxNode
*node
= m_lines
.First();
1966 if (node
) m_current
= (wxListLineData
*)node
->Data();
1970 FocusLine( m_current
);
1971 if (m_mode
& wxLC_SINGLE_SEL
) m_current
->Hilight( TRUE
);
1975 long wxListMainWindow::GetNextItem( long item
, int WXUNUSED(geometry
), int state
)
1978 if (item
> 0) ret
= item
;
1979 wxNode
*node
= m_lines
.Nth( ret
);
1982 wxListLineData
*line
= (wxListLineData
*)node
->Data();
1983 if ((state
& wxLIST_STATE_FOCUSED
) && (line
== m_current
)) return ret
;
1984 if ((state
& wxLIST_STATE_SELECTED
) && (line
->IsHilighted())) return ret
;
1985 if (!state
) return ret
;
1987 node
= node
->Next();
1992 void wxListMainWindow::DeleteItem( long index
)
1995 wxNode
*node
= m_lines
.Nth( index
);
1998 wxListLineData
*line
= (wxListLineData
*)node
->Data();
1999 if (m_current
== line
) m_current
= (wxListLineData
*) NULL
;
2001 m_lines
.DeleteNode( node
);
2005 void wxListMainWindow::DeleteColumn( int col
)
2007 wxCHECK_RET( col
< m_columns
.GetCount(),
2008 "attempting to delete inexistent column in wxListView" );
2011 wxNode
*node
= m_columns
.Nth( col
);
2012 if (node
) m_columns
.DeleteNode( node
);
2015 void wxListMainWindow::DeleteAllItems( void )
2018 m_current
= (wxListLineData
*) NULL
;
2019 wxNode
*node
= m_lines
.First();
2022 wxListLineData
*line
= (wxListLineData
*)node
->Data();
2024 node
= node
->Next();
2029 void wxListMainWindow::DeleteEverything( void )
2032 m_current
= (wxListLineData
*) NULL
;
2033 wxNode
*node
= m_lines
.First();
2036 wxListLineData
*line
= (wxListLineData
*)node
->Data();
2038 node
= node
->Next();
2041 m_current
= (wxListLineData
*) NULL
;
2045 void wxListMainWindow::EnsureVisible( long index
)
2047 wxListLineData
*oldCurrent
= m_current
;
2048 m_current
= (wxListLineData
*) NULL
;
2050 wxNode
*node
= m_lines
.Nth( i
);
2051 if (node
) m_current
= (wxListLineData
*)node
->Data();
2052 if (m_current
) MoveToFocus();
2053 m_current
= oldCurrent
;
2056 long wxListMainWindow::FindItem(long start
, const wxString
& str
, bool WXUNUSED(partial
) )
2060 if (pos
< 0) pos
= 0;
2061 wxNode
*node
= m_lines
.Nth( pos
);
2064 wxListLineData
*line
= (wxListLineData
*)node
->Data();
2066 line
->GetText( 0, s
);
2067 if (s
== tmp
) return pos
;
2068 node
= node
->Next();
2074 long wxListMainWindow::FindItem(long start
, long data
)
2077 if (pos
< 0) pos
= 0;
2078 wxNode
*node
= m_lines
.Nth( pos
);
2081 wxListLineData
*line
= (wxListLineData
*)node
->Data();
2083 line
->GetItem( 0, item
);
2084 if (item
.m_data
== data
) return pos
;
2085 node
= node
->Next();
2091 long wxListMainWindow::HitTest( int x
, int y
, int &flags
)
2093 wxNode
*node
= m_lines
.First();
2097 wxListLineData
*line
= (wxListLineData
*)node
->Data();
2098 long ret
= line
->IsHit( x
, y
);
2104 node
= node
->Next();
2110 void wxListMainWindow::InsertItem( wxListItem
&item
)
2114 if (m_mode
& wxLC_REPORT
) mode
= wxLC_REPORT
;
2115 else if (m_mode
& wxLC_LIST
) mode
= wxLC_LIST
;
2116 else if (m_mode
& wxLC_ICON
) mode
= wxLC_ICON
;
2117 else if (m_mode
& wxLC_SMALL_ICON
) mode
= wxLC_ICON
; // no typo
2118 wxListLineData
*line
= new wxListLineData( this, mode
, m_hilightBrush
);
2119 if (m_mode
& wxLC_REPORT
)
2121 line
->InitItems( GetColumnCount() );
2122 item
.m_width
= GetColumnWidth( 0 )-3;
2125 line
->InitItems( 1 );
2126 line
->SetItem( 0, item
);
2127 if ((item
.m_itemId
>= 0) && (item
.m_itemId
< (int)m_lines
.GetCount()))
2129 wxNode
*node
= m_lines
.Nth( item
.m_itemId
);
2130 if (node
) m_lines
.Insert( node
, line
);
2134 m_lines
.Append( line
);
2138 void wxListMainWindow::InsertColumn( long col
, wxListItem
&item
)
2141 if (m_mode
& wxLC_REPORT
)
2143 if (item
.m_width
== wxLIST_AUTOSIZE_USEHEADER
) item
.m_width
= GetTextLength( item
.m_text
);
2144 wxListHeaderData
*column
= new wxListHeaderData( item
);
2145 if ((col
>= 0) && (col
< (int)m_columns
.GetCount()))
2147 wxNode
*node
= m_columns
.Nth( col
);
2149 m_columns
.Insert( node
, column
);
2153 m_columns
.Append( column
);
2158 wxListCtrlCompare list_ctrl_compare_func_2
;
2159 long list_ctrl_compare_data
;
2161 int list_ctrl_compare_func_1( const void *arg1
, const void *arg2
)
2163 wxListLineData
*line1
= *((wxListLineData
**)arg1
);
2164 wxListLineData
*line2
= *((wxListLineData
**)arg2
);
2166 line1
->GetItem( 0, item
);
2167 long data1
= item
.m_data
;
2168 line2
->GetItem( 0, item
);
2169 long data2
= item
.m_data
;
2170 return list_ctrl_compare_func_2( data1
, data2
, list_ctrl_compare_data
);
2173 void wxListMainWindow::SortItems( wxListCtrlCompare fn
, long data
)
2175 list_ctrl_compare_func_2
= fn
;
2176 list_ctrl_compare_data
= data
;
2177 m_lines
.Sort( list_ctrl_compare_func_1
);
2180 bool wxListMainWindow::OnListNotify( wxListEvent
&event
)
2182 if (GetParent()) GetParent()->GetEventHandler()->ProcessEvent( event
);
2186 // -------------------------------------------------------------------------------------
2188 // -------------------------------------------------------------------------------------
2190 IMPLEMENT_DYNAMIC_CLASS(wxListItem
, wxObject
)
2192 wxListItem::wxListItem(void)
2201 m_format
= wxLIST_FORMAT_CENTRE
;
2206 // -------------------------------------------------------------------------------------
2208 // -------------------------------------------------------------------------------------
2210 IMPLEMENT_DYNAMIC_CLASS(wxListEvent
, wxCommandEvent
)
2212 wxListEvent::wxListEvent( wxEventType commandType
, int id
):
2213 wxCommandEvent( commandType
, id
)
2218 m_cancelled
= FALSE
;
2221 // -------------------------------------------------------------------------------------
2223 // -------------------------------------------------------------------------------------
2225 IMPLEMENT_DYNAMIC_CLASS(wxListCtrl
, wxControl
)
2227 BEGIN_EVENT_TABLE(wxListCtrl
,wxControl
)
2228 EVT_SIZE (wxListCtrl::OnSize
)
2229 EVT_IDLE (wxListCtrl::OnIdle
)
2232 wxListCtrl::wxListCtrl(void)
2234 m_imageListNormal
= (wxImageList
*) NULL
;
2235 m_imageListSmall
= (wxImageList
*) NULL
;
2236 m_imageListState
= (wxImageList
*) NULL
;
2237 m_mainWin
= (wxListMainWindow
*) NULL
;
2238 m_headerWin
= (wxListHeaderWindow
*) NULL
;
2241 wxListCtrl::~wxListCtrl(void)
2245 bool wxListCtrl::Create( wxWindow
*parent
, wxWindowID id
,
2246 const wxPoint
&pos
, const wxSize
&size
,
2247 long style
, const wxValidator
&validator
,
2248 const wxString
&name
)
2250 m_imageListNormal
= (wxImageList
*) NULL
;
2251 m_imageListSmall
= (wxImageList
*) NULL
;
2252 m_imageListState
= (wxImageList
*) NULL
;
2253 m_mainWin
= (wxListMainWindow
*) NULL
;
2254 m_headerWin
= (wxListHeaderWindow
*) NULL
;
2258 if ((s
& wxLC_REPORT
== 0) &&
2259 (s
& wxLC_LIST
== 0) &&
2260 (s
& wxLC_ICON
== 0))
2263 bool ret
= wxControl::Create( parent
, id
, pos
, size
, s
, name
);
2265 SetValidator( validator
);
2267 m_mainWin
= new wxListMainWindow( this, -1, wxPoint(0,0), size
, s
);
2269 if (GetWindowStyleFlag() & wxLC_REPORT
)
2270 m_headerWin
= new wxListHeaderWindow( this, -1, m_mainWin
, wxPoint(0,0), wxSize(size
.x
,23) );
2272 m_headerWin
= (wxListHeaderWindow
*) NULL
;
2277 void wxListCtrl::OnSize( wxSizeEvent
&WXUNUSED(event
) )
2279 // handled in OnIdle
2281 if (m_mainWin
) m_mainWin
->m_dirty
= TRUE
;
2284 void wxListCtrl::SetSingleStyle( long style
, bool add
)
2286 long flag
= GetWindowStyleFlag();
2290 if (style
& wxLC_MASK_TYPE
) flag
= flag
& ~wxLC_MASK_TYPE
;
2291 if (style
& wxLC_MASK_ALIGN
) flag
= flag
& ~wxLC_MASK_ALIGN
;
2292 if (style
& wxLC_MASK_SORT
) flag
= flag
& ~wxLC_MASK_SORT
;
2301 if (flag
& style
) flag
-= style
;
2304 SetWindowStyleFlag( flag
);
2307 void wxListCtrl::SetWindowStyleFlag( long flag
)
2309 m_mainWin
->DeleteEverything();
2313 GetClientSize( &width
, &height
);
2315 m_mainWin
->SetMode( flag
);
2317 if (flag
& wxLC_REPORT
)
2319 if (!(GetWindowStyleFlag() & wxLC_REPORT
))
2321 // m_mainWin->SetSize( 0, 24, width, height-24 );
2324 m_headerWin
= new wxListHeaderWindow( this, -1, m_mainWin
, wxPoint(0,0), wxSize(width
,23) );
2328 // m_headerWin->SetSize( 0, 0, width, 23 );
2329 m_headerWin
->Show( TRUE
);
2335 if (GetWindowStyleFlag() & wxLC_REPORT
)
2337 // m_mainWin->SetSize( 0, 0, width, height );
2338 m_headerWin
->Show( FALSE
);
2342 wxWindow::SetWindowStyleFlag( flag
);
2345 bool wxListCtrl::GetColumn(int col
, wxListItem
&item
)
2347 m_mainWin
->GetColumn( col
, item
);
2351 bool wxListCtrl::SetColumn( int col
, wxListItem
& item
)
2353 m_mainWin
->SetColumn( col
, item
);
2357 int wxListCtrl::GetColumnWidth( int col
)
2359 return m_mainWin
->GetColumnWidth( col
);
2362 bool wxListCtrl::SetColumnWidth( int col
, int width
)
2364 m_mainWin
->SetColumnWidth( col
, width
);
2368 int wxListCtrl::GetCountPerPage(void)
2370 return m_mainWin
->GetCountPerPage(); // different from Windows ?
2374 wxText& wxListCtrl::GetEditControl(void) const
2379 bool wxListCtrl::GetItem( wxListItem
&info
)
2381 m_mainWin
->GetItem( info
);
2385 bool wxListCtrl::SetItem( wxListItem
&info
)
2387 m_mainWin
->SetItem( info
);
2391 long wxListCtrl::SetItem( long index
, int col
, const wxString
& label
, int imageId
)
2394 info
.m_text
= label
;
2395 info
.m_mask
= wxLIST_MASK_TEXT
;
2396 info
.m_itemId
= index
;
2400 info
.m_image
= imageId
;
2401 info
.m_mask
|= wxLIST_MASK_IMAGE
;
2404 m_mainWin
->SetItem(info
);
2408 int wxListCtrl::GetItemState( long item
, long stateMask
)
2410 return m_mainWin
->GetItemState( item
, stateMask
);
2413 bool wxListCtrl::SetItemState( long item
, long state
, long stateMask
)
2415 m_mainWin
->SetItemState( item
, state
, stateMask
);
2419 bool wxListCtrl::SetItemImage( long item
, int image
, int WXUNUSED(selImage
) )
2422 info
.m_image
= image
;
2423 info
.m_mask
= wxLIST_MASK_IMAGE
;
2424 info
.m_itemId
= item
;
2425 m_mainWin
->SetItem( info
);
2429 wxString
wxListCtrl::GetItemText( long item
)
2432 info
.m_itemId
= item
;
2433 m_mainWin
->GetItem( info
);
2437 void wxListCtrl::SetItemText( long item
, const wxString
&str
)
2440 info
.m_mask
= wxLIST_MASK_TEXT
;
2441 info
.m_itemId
= item
;
2443 m_mainWin
->SetItem( info
);
2446 long wxListCtrl::GetItemData( long item
)
2449 info
.m_itemId
= item
;
2450 m_mainWin
->GetItem( info
);
2454 bool wxListCtrl::SetItemData( long item
, long data
)
2457 info
.m_mask
= wxLIST_MASK_DATA
;
2458 info
.m_itemId
= item
;
2460 m_mainWin
->SetItem( info
);
2464 bool wxListCtrl::GetItemRect( long item
, wxRectangle
&rect
, int WXUNUSED(code
) )
2466 m_mainWin
->GetItemRect( item
, rect
);
2470 bool wxListCtrl::GetItemPosition( long item
, wxPoint
& pos
)
2472 m_mainWin
->GetItemPosition( item
, pos
);
2476 bool wxListCtrl::SetItemPosition( long WXUNUSED(item
), const wxPoint
& WXUNUSED(pos
) )
2481 int wxListCtrl::GetItemCount(void)
2483 return m_mainWin
->GetItemCount();
2486 void wxListCtrl::SetItemSpacing( int spacing
, bool isSmall
)
2488 m_mainWin
->SetItemSpacing( spacing
, isSmall
);
2491 int wxListCtrl::GetItemSpacing( bool isSmall
)
2493 return m_mainWin
->GetItemSpacing( isSmall
);
2496 int wxListCtrl::GetSelectedItemCount(void)
2498 return m_mainWin
->GetSelectedItemCount();
2502 wxColour wxListCtrl::GetTextColour(void) const
2506 void wxListCtrl::SetTextColour(const wxColour& WXUNUSED(col))
2511 long wxListCtrl::GetTopItem(void)
2516 long wxListCtrl::GetNextItem( long item
, int geom
, int state
) const
2518 return m_mainWin
->GetNextItem( item
, geom
, state
);
2521 wxImageList
*wxListCtrl::GetImageList(int which
)
2523 if (which
== wxIMAGE_LIST_NORMAL
)
2525 return m_imageListNormal
;
2527 else if (which
== wxIMAGE_LIST_SMALL
)
2529 return m_imageListSmall
;
2531 else if (which
== wxIMAGE_LIST_STATE
)
2533 return m_imageListState
;
2535 return (wxImageList
*) NULL
;
2538 void wxListCtrl::SetImageList( wxImageList
*imageList
, int which
)
2540 m_mainWin
->SetImageList( imageList
, which
);
2543 bool wxListCtrl::Arrange( int WXUNUSED(flag
) )
2548 bool wxListCtrl::DeleteItem( long item
)
2550 m_mainWin
->DeleteItem( item
);
2554 bool wxListCtrl::DeleteAllItems(void)
2556 m_mainWin
->DeleteAllItems();
2560 void wxListCtrl::DeleteAllColumns()
2562 for ( size_t n
= 0; n
< m_mainWin
->m_columns
.GetCount(); n
++ )
2566 bool wxListCtrl::DeleteColumn( int col
)
2568 m_mainWin
->DeleteColumn( col
);
2573 wxText& wxListCtrl::Edit( long WXUNUSED(item ) )
2578 bool wxListCtrl::EnsureVisible( long item
)
2580 m_mainWin
->EnsureVisible( item
);
2584 long wxListCtrl::FindItem( long start
, const wxString
& str
, bool partial
)
2586 return m_mainWin
->FindItem( start
, str
, partial
);
2589 long wxListCtrl::FindItem( long start
, long data
)
2591 return m_mainWin
->FindItem( start
, data
);
2594 long wxListCtrl::FindItem( long WXUNUSED(start
), const wxPoint
& WXUNUSED(pt
),
2595 int WXUNUSED(direction
))
2600 long wxListCtrl::HitTest( const wxPoint
&point
, int &flags
)
2602 return m_mainWin
->HitTest( (int)point
.x
, (int)point
.y
, flags
);
2605 long wxListCtrl::InsertItem( wxListItem
& info
)
2607 m_mainWin
->InsertItem( info
);
2611 long wxListCtrl::InsertItem( long index
, const wxString
&label
)
2614 info
.m_text
= label
;
2615 info
.m_mask
= wxLIST_MASK_TEXT
;
2616 info
.m_itemId
= index
;
2617 return InsertItem( info
);
2620 long wxListCtrl::InsertItem( long index
, int imageIndex
)
2623 info
.m_mask
= wxLIST_MASK_IMAGE
;
2624 info
.m_image
= imageIndex
;
2625 info
.m_itemId
= index
;
2626 return InsertItem( info
);
2629 long wxListCtrl::InsertItem( long index
, const wxString
&label
, int imageIndex
)
2632 info
.m_text
= label
;
2633 info
.m_image
= imageIndex
;
2634 info
.m_mask
= wxLIST_MASK_TEXT
| wxLIST_MASK_IMAGE
;
2635 info
.m_itemId
= index
;
2636 return InsertItem( info
);
2639 long wxListCtrl::InsertColumn( long col
, wxListItem
&item
)
2641 m_mainWin
->InsertColumn( col
, item
);
2645 long wxListCtrl::InsertColumn( long col
, const wxString
&heading
,
2646 int format
, int width
)
2649 item
.m_mask
= wxLIST_MASK_TEXT
| wxLIST_MASK_FORMAT
;
2650 item
.m_text
= heading
;
2653 item
.m_mask
|= wxLIST_MASK_WIDTH
;
2654 item
.m_width
= width
;
2657 item
.m_format
= format
;
2659 return InsertColumn( col
, item
);
2662 bool wxListCtrl::ScrollList( int WXUNUSED(dx
), int WXUNUSED(dy
) )
2668 // fn is a function which takes 3 long arguments: item1, item2, data.
2669 // item1 is the long data associated with a first item (NOT the index).
2670 // item2 is the long data associated with a second item (NOT the index).
2671 // data is the same value as passed to SortItems.
2672 // The return value is a negative number if the first item should precede the second
2673 // item, a positive number of the second item should precede the first,
2674 // or zero if the two items are equivalent.
2675 // data is arbitrary data to be passed to the sort function.
2677 bool wxListCtrl::SortItems( wxListCtrlCompare fn
, long data
)
2679 m_mainWin
->SortItems( fn
, data
);
2683 void wxListCtrl::OnIdle( wxIdleEvent
&WXUNUSED(event
) )
2685 if (!m_mainWin
->m_dirty
) return;
2689 GetClientSize( &cw
, &ch
);
2696 if (GetWindowStyleFlag() & wxLC_REPORT
)
2698 m_headerWin
->GetPosition( &x
, &y
);
2699 m_headerWin
->GetSize( &w
, &h
);
2700 if ((x
!= 0) || (y
!= 0) || (w
!= cw
) || (h
!= 23))
2701 m_headerWin
->SetSize( 0, 0, cw
, 23 );
2703 m_mainWin
->GetPosition( &x
, &y
);
2704 m_mainWin
->GetSize( &w
, &h
);
2705 if ((x
!= 0) || (y
!= 24) || (w
!= cw
) || (h
!= ch
-24))
2706 m_mainWin
->SetSize( 0, 24, cw
, ch
-24 );
2710 m_mainWin
->GetPosition( &x
, &y
);
2711 m_mainWin
->GetSize( &w
, &h
);
2712 if ((x
!= 0) || (y
!= 24) || (w
!= cw
) || (h
!= ch
))
2713 m_mainWin
->SetSize( 0, 0, cw
, ch
);
2716 m_mainWin
->CalculatePositions();
2717 m_mainWin
->RealizeChanges();
2718 m_mainWin
->m_dirty
= FALSE
;
2719 m_mainWin
->Refresh();
2722 void wxListCtrl::SetBackgroundColour( const wxColour
&colour
)
2726 m_mainWin
->SetBackgroundColour( colour
);
2727 m_mainWin
->m_dirty
= TRUE
;
2730 m_headerWin
->SetBackgroundColour( colour
);
2733 void wxListCtrl::SetForegroundColour( const wxColour
&colour
)
2737 m_mainWin
->SetForegroundColour( colour
);
2738 m_mainWin
->m_dirty
= TRUE
;
2741 m_headerWin
->SetForegroundColour( colour
);
2744 void wxListCtrl::SetFont( const wxFont
&font
)
2748 m_mainWin
->SetFont( font
);
2749 m_mainWin
->m_dirty
= TRUE
;
2752 m_headerWin
->SetFont( font
);