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
+= 3;
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 wxPen
pen( wxSystemSettings::GetSystemColour( wxSYS_COLOUR_BTNSHADOW
), 1, wxSOLID
);
706 dc
->DrawLine( x
+w
-m_corner
, y
, x
+w
-1, y
+h
); // right (inner)
707 dc
->DrawRectangle( x
+1, y
+h
-1, w
-2, 1 ); // bottom (inner)
709 dc
->SetPen( *wxWHITE_PEN
);
710 dc
->DrawRectangle( x
, y
, w
-m_corner
+1, 1 ); // top (outer)
711 dc
->DrawRectangle( x
, y
, 1, h
); // left (outer)
712 dc
->DrawLine( x
, y
+h
-1, x
+1, y
+h
-1 );
713 dc
->DrawLine( x
+w
-1, y
, x
+w
-1, y
+1 );
716 void wxListHeaderWindow::OnPaint( wxPaintEvent
&WXUNUSED(event
) )
718 wxPaintDC
dc( this );
723 dc
.SetFont( GetFont() );
729 GetClientSize( &w
, &h
);
731 dc
.SetTextForeground( *wxBLACK
);
732 if (m_foregroundColour
.Ok()) dc
.SetTextForeground( m_foregroundColour
);
736 int numColumns
= m_owner
->GetColumnCount();
738 for (int i
= 0; i
< numColumns
; i
++)
740 m_owner
->GetColumn( i
, item
);
741 int cw
= item
.m_width
-2;
742 if ((i
+1 == numColumns
) || (x
+item
.m_width
> w
-5)) cw
= w
-x
-1;
743 dc
.SetPen( *wxWHITE_PEN
);
745 DoDrawRect( &dc
, x
, y
, cw
, h
-2 );
746 dc
.SetClippingRegion( x
, y
, cw
-5, h
-4 );
747 dc
.DrawText( item
.m_text
, x
+4, y
+3 );
748 dc
.DestroyClippingRegion();
755 void wxListHeaderWindow::DrawCurrent()
759 int x2
= m_currentX
-1;
762 m_owner
->GetClientSize( &dummy
, &y2
);
763 ClientToScreen( &x1
, &y1
);
764 m_owner
->ClientToScreen( &x2
, &y2
);
767 dc
.SetLogicalFunction( wxXOR
);
768 dc
.SetPen( wxPen( *wxBLACK
, 2, wxSOLID
) );
769 dc
.SetBrush( *wxTRANSPARENT_BRUSH
);
771 dc
.DrawLine( x1
, y1
, x2
, y2
);
773 dc
.SetLogicalFunction( wxCOPY
);
775 dc
.SetPen( wxNullPen
);
776 dc
.SetBrush( wxNullBrush
);
779 void wxListHeaderWindow::OnMouse( wxMouseEvent
&event
)
781 int x
= event
.GetX();
782 int y
= event
.GetY();
786 if (event
.ButtonUp())
790 m_owner
->SetColumnWidth( m_column
, m_currentX
-m_minX
);
796 GetClientSize( &size_x
, & dummy
);
800 m_currentX
= m_minX
+7;
801 if (m_currentX
> size_x
-7) m_currentX
= size_x
-7;
808 bool hit_border
= FALSE
;
810 for (int j
= 0; j
< m_owner
->GetColumnCount(); j
++)
812 xpos
+= m_owner
->GetColumnWidth( j
);
813 if ((abs(x
-xpos
) < 3) && (y
< 22))
822 if (event
.LeftDown() && hit_border
)
835 if (m_currentCursor
== wxSTANDARD_CURSOR
) SetCursor( * m_resizeCursor
);
836 m_currentCursor
= m_resizeCursor
;
840 if (m_currentCursor
!= wxSTANDARD_CURSOR
) SetCursor( * wxSTANDARD_CURSOR
);
841 m_currentCursor
= wxSTANDARD_CURSOR
;
846 void wxListHeaderWindow::OnSetFocus( wxFocusEvent
&WXUNUSED(event
) )
851 //-----------------------------------------------------------------------------
852 // wxListRenameTimer (internal)
853 //-----------------------------------------------------------------------------
855 wxListRenameTimer::wxListRenameTimer( wxListMainWindow
*owner
)
860 void wxListRenameTimer::Notify()
862 m_owner
->OnRenameTimer();
865 //-----------------------------------------------------------------------------
866 // wxListTextCtrl (internal)
867 //-----------------------------------------------------------------------------
869 IMPLEMENT_DYNAMIC_CLASS(wxListTextCtrl
,wxTextCtrl
);
871 BEGIN_EVENT_TABLE(wxListTextCtrl
,wxTextCtrl
)
872 EVT_CHAR (wxListTextCtrl::OnChar
)
873 EVT_KILL_FOCUS (wxListTextCtrl::OnKillFocus
)
876 wxListTextCtrl::wxListTextCtrl( wxWindow
*parent
, const wxWindowID id
,
877 bool *accept
, wxString
*res
, wxListMainWindow
*owner
,
878 const wxString
&value
, const wxPoint
&pos
, const wxSize
&size
,
879 int style
, const wxValidator
& validator
, const wxString
&name
) :
880 wxTextCtrl( parent
, id
, value
, pos
, size
, style
, validator
, name
)
887 void wxListTextCtrl::OnChar( wxKeyEvent
&event
)
889 if (event
.m_keyCode
== WXK_RETURN
)
892 (*m_res
) = GetValue();
893 m_owner
->OnRenameAccept();
898 if (event
.m_keyCode
== WXK_ESCAPE
)
909 void wxListTextCtrl::OnKillFocus( wxFocusEvent
&WXUNUSED(event
) )
918 //-----------------------------------------------------------------------------
920 //-----------------------------------------------------------------------------
922 IMPLEMENT_DYNAMIC_CLASS(wxListMainWindow
,wxScrolledWindow
);
924 BEGIN_EVENT_TABLE(wxListMainWindow
,wxScrolledWindow
)
925 EVT_PAINT (wxListMainWindow::OnPaint
)
926 EVT_SIZE (wxListMainWindow::OnSize
)
927 EVT_MOUSE_EVENTS (wxListMainWindow::OnMouse
)
928 EVT_CHAR (wxListMainWindow::OnChar
)
929 EVT_SET_FOCUS (wxListMainWindow::OnSetFocus
)
930 EVT_KILL_FOCUS (wxListMainWindow::OnKillFocus
)
933 wxListMainWindow::wxListMainWindow( void )
936 m_lines
.DeleteContents( TRUE
);
937 m_columns
.DeleteContents( TRUE
);
938 m_current
= (wxListLineData
*) NULL
;
940 m_hilightBrush
= (wxBrush
*) NULL
;
944 m_small_image_list
= (wxImageList
*) NULL
;
945 m_normal_image_list
= (wxImageList
*) NULL
;
946 m_small_spacing
= 30;
947 m_normal_spacing
= 40;
950 m_lastOnSame
= FALSE
;
951 m_renameTimer
= new wxListRenameTimer( this );
956 wxListMainWindow::wxListMainWindow( wxWindow
*parent
, wxWindowID id
,
957 const wxPoint
&pos
, const wxSize
&size
,
958 long style
, const wxString
&name
) :
959 wxScrolledWindow( parent
, id
, pos
, size
, style
|wxHSCROLL
|wxVSCROLL
, name
)
962 m_lines
.DeleteContents( TRUE
);
963 m_columns
.DeleteContents( TRUE
);
964 m_current
= (wxListLineData
*) NULL
;
967 m_hilightBrush
= new wxBrush( wxSystemSettings::GetSystemColour(wxSYS_COLOUR_HIGHLIGHT
), wxSOLID
);
968 m_small_image_list
= (wxImageList
*) NULL
;
969 m_normal_image_list
= (wxImageList
*) NULL
;
970 m_small_spacing
= 30;
971 m_normal_spacing
= 40;
972 // AllowDoubleClick( TRUE );
979 if (m_mode
& wxLC_REPORT
)
989 SetScrollbars( m_xScroll
, m_yScroll
, 0, 0, 0, 0 );
992 m_lastOnSame
= FALSE
;
993 m_renameTimer
= new wxListRenameTimer( this );
994 m_renameAccept
= FALSE
;
995 // m_text = new wxRawListTextCtrl( GetParent(), "", &m_renameAccept, &m_renameRes, this, 10, 10, 40, 10 );
996 // m_text->Show( FALSE );
998 SetBackgroundColour( *wxWHITE
);
1001 wxListMainWindow::~wxListMainWindow( void )
1003 if (m_hilightBrush
) delete m_hilightBrush
;
1004 delete m_renameTimer
;
1005 // if (m_hilightColour) delete m_hilightColour;
1009 void wxListMainWindow::RefreshLine( wxListLineData
*line
)
1017 wxClientDC
dc(this);
1019 line
->GetExtent( x
, y
, w
, h
);
1021 dc
.LogicalToDeviceX(x
-3),
1022 dc
.LogicalToDeviceY(y
-3),
1023 dc
.LogicalToDeviceXRel(w
+6),
1024 dc
.LogicalToDeviceXRel(h
+6) );
1025 Refresh( TRUE
, &rect
);
1029 void wxListMainWindow::OnPaint( wxPaintEvent
&WXUNUSED(event
) )
1031 if (m_dirty
) return;
1033 wxPaintDC
dc( this );
1038 dc
.SetFont( GetFont() );
1040 wxNode
*node
= m_lines
.First();
1043 wxListLineData
*line
= (wxListLineData
*)node
->Data();
1045 node
= node
->Next();
1047 if (m_current
) m_current
->DrawRubberBand( &dc
, m_hasFocus
);
1052 void wxListMainWindow::HilightAll( bool on
)
1054 wxNode
*node
= m_lines
.First();
1057 wxListLineData
*line
= (wxListLineData
*)node
->Data();
1058 if (line
->IsHilighted() != on
)
1060 line
->Hilight( on
);
1061 RefreshLine( line
);
1063 node
= node
->Next();
1067 void wxListMainWindow::SendNotify( wxListLineData
*line
, wxEventType command
)
1069 wxListEvent
le( command
, GetParent()->GetId() );
1070 le
.SetEventObject( GetParent() );
1071 le
.m_itemIndex
= GetIndexOfLine( line
);
1072 line
->GetItem( 0, le
.m_item
);
1073 GetParent()->GetEventHandler()->ProcessEvent( le
);
1076 void wxListMainWindow::FocusLine( wxListLineData
*WXUNUSED(line
) )
1078 // SendNotify( line, wxEVT_COMMAND_LIST_ITEM_FOCUSSED );
1081 void wxListMainWindow::UnfocusLine( wxListLineData
*WXUNUSED(line
) )
1083 // SendNotify( line, wxEVT_COMMAND_LIST_ITEM_UNFOCUSSED );
1086 void wxListMainWindow::SelectLine( wxListLineData
*line
)
1088 SendNotify( line
, wxEVT_COMMAND_LIST_ITEM_SELECTED
);
1091 void wxListMainWindow::DeselectLine( wxListLineData
*line
)
1093 SendNotify( line
, wxEVT_COMMAND_LIST_ITEM_DESELECTED
);
1096 void wxListMainWindow::DeleteLine( wxListLineData
*line
)
1098 SendNotify( line
, wxEVT_COMMAND_LIST_DELETE_ITEM
);
1101 void wxListMainWindow::StartLabelEdit( wxListLineData
*line
)
1103 SendNotify( line
, wxEVT_COMMAND_LIST_BEGIN_LABEL_EDIT
);
1106 void wxListMainWindow::RenameLine( wxListLineData
*line
, const wxString
&newName
)
1108 wxListEvent
le( wxEVT_COMMAND_LIST_END_LABEL_EDIT
, GetParent()->GetId() );
1109 le
.SetEventObject( GetParent() );
1110 le
.m_itemIndex
= GetIndexOfLine( line
);
1111 line
->GetItem( 0, le
.m_item
);
1112 le
.m_item
.m_text
= newName
;
1113 GetParent()->GetEventHandler()->ProcessEvent( le
);
1116 void wxListMainWindow::OnRenameTimer()
1118 StartLabelEdit( m_current
);
1120 m_current
->GetText( 0, s
);
1125 m_current
->GetLabelExtent( x
, y
, w
, h
);
1127 wxClientDC
dc(this);
1129 x
= dc
.LogicalToDeviceX( x
);
1130 y
= dc
.LogicalToDeviceY( y
);
1132 wxListTextCtrl
*text
= new wxListTextCtrl(
1133 this, -1, &m_renameAccept
, &m_renameRes
, this, s
, wxPoint(x
-4,y
-4), wxSize(w
+11,h
+8) );
1137 void wxListMainWindow::OnRenameAccept()
1139 RenameLine( m_current
, m_renameRes
);
1142 void wxListMainWindow::OnMouse( wxMouseEvent
&event
)
1144 if (GetParent()->GetEventHandler()->ProcessEvent( event
)) return;
1146 if (!m_current
) return;
1147 if (m_dirty
) return;
1149 wxClientDC
dc(this);
1151 long x
= dc
.DeviceToLogicalX( (long)event
.GetX() );
1152 long y
= dc
.DeviceToLogicalY( (long)event
.GetY() );
1154 // Did we actually hit an item ?
1156 wxNode
*node
= m_lines
.First();
1157 wxListLineData
*line
= (wxListLineData
*) NULL
;
1160 line
= (wxListLineData
*)node
->Data();
1161 hitResult
= line
->IsHit( x
, y
);
1162 if (hitResult
) break;
1163 line
= (wxListLineData
*) NULL
;
1164 node
= node
->Next();
1167 if (!event
.Dragging())
1172 if (event
.Dragging() && (m_dragCount
> 3))
1176 wxListEvent
le( wxEVT_COMMAND_LIST_BEGIN_DRAG
, GetParent()->GetId() );
1177 le
.SetEventObject( GetParent() );
1178 le
.m_pointDrag
.x
= x
;
1179 le
.m_pointDrag
.y
= y
;
1180 GetParent()->GetEventHandler()->ProcessEvent( le
);
1187 if (event
.ButtonDClick())
1190 m_lastOnSame
= FALSE
;
1191 m_renameTimer
->Stop();
1193 SendNotify( line
, wxEVT_COMMAND_LIST_KEY_DOWN
);
1198 if (event
.LeftUp() && m_lastOnSame
)
1201 if ((line
== m_current
) &&
1202 (hitResult
== wxLIST_HITTEST_ONITEMLABEL
) &&
1203 (m_mode
& wxLC_EDIT_LABELS
) )
1205 m_renameTimer
->Start( 100, TRUE
);
1207 m_lastOnSame
= FALSE
;
1211 if (event
.RightDown())
1213 SendNotify( line
, wxEVT_COMMAND_LIST_ITEM_RIGHT_CLICK
);
1217 if (event
.MiddleDown())
1219 SendNotify( line
, wxEVT_COMMAND_LIST_ITEM_MIDDLE_CLICK
);
1223 if (event
.LeftDown())
1226 wxListLineData
*oldCurrent
= m_current
;
1227 if (m_mode
& wxLC_SINGLE_SEL
)
1230 HilightAll( FALSE
);
1231 m_current
->ReverseHilight();
1232 RefreshLine( m_current
);
1236 if (event
.ShiftDown())
1239 m_current
->ReverseHilight();
1240 RefreshLine( m_current
);
1242 else if (event
.ControlDown())
1246 int numOfCurrent
= -1;
1247 node
= m_lines
.First();
1250 wxListLineData
*test_line
= (wxListLineData
*)node
->Data();
1252 if (test_line
== oldCurrent
) break;
1253 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
)
1269 numOfLine
= numOfCurrent
;
1273 wxNode
*node
= m_lines
.Nth( numOfCurrent
);
1274 for (int i
= 0; i
<= numOfLine
-numOfCurrent
; i
++)
1276 wxListLineData
*test_line
= (wxListLineData
*)node
->Data();
1277 test_line
->Hilight(TRUE
);
1278 RefreshLine( test_line
);
1279 node
= node
->Next();
1285 HilightAll( FALSE
);
1286 m_current
->ReverseHilight();
1287 RefreshLine( m_current
);
1290 if (m_current
!= oldCurrent
)
1292 RefreshLine( oldCurrent
);
1293 UnfocusLine( oldCurrent
);
1294 FocusLine( m_current
);
1296 m_lastOnSame
= (m_current
== oldCurrent
);
1301 void wxListMainWindow::MoveToFocus( void )
1303 if (!m_current
) return;
1309 m_current
->GetExtent( x
, y
, w
, h
);
1312 GetClientSize( &w_p
, &h_p
);
1313 if (m_mode
& wxLC_REPORT
)
1315 if (GetScrollPos( wxHORIZONTAL
) != 0) SetScrollPos( wxHORIZONTAL
, 0);
1316 int y_s
= m_yScroll
*GetScrollPos( wxVERTICAL
);
1317 if ((y
> y_s
) && (y
+h
< y_s
+h_p
)) return;
1318 if (y
-y_s
< 5) SetScrollPos( wxVERTICAL
, (y
-5-h_p
/2)/m_yScroll
);
1319 if (y
+h
+5 > y_s
+h_p
) SetScrollPos( wxVERTICAL
, (y
+h
-h_p
/2+h
+15)/m_yScroll
);
1324 if (GetScrollPos( wxVERTICAL
) != 0) SetScrollPos( wxVERTICAL
, 0);
1325 int x_s
= m_xScroll
*GetScrollPos( wxHORIZONTAL
);
1326 if ((x
> x_s
) && (x
+w
< x_s
+w_p
)) return;
1327 if (x
-x_s
< 5) SetScrollPos( wxHORIZONTAL
, (x
-5)/m_xScroll
);
1328 if (x
+w
-5 > x_s
+w_p
) SetScrollPos( wxHORIZONTAL
, (x
+w
-w_p
+15)/m_xScroll
);
1333 void wxListMainWindow::OnArrowChar( wxListLineData
*newCurrent
, bool shiftDown
)
1335 if ((m_mode
& wxLC_SINGLE_SEL
) || (m_usedKeys
== FALSE
)) m_current
->Hilight( FALSE
);
1336 wxListLineData
*oldCurrent
= m_current
;
1337 m_current
= newCurrent
;
1339 if (shiftDown
|| (m_mode
& wxLC_SINGLE_SEL
)) m_current
->Hilight( TRUE
);
1340 RefreshLine( m_current
);
1341 RefreshLine( oldCurrent
);
1342 FocusLine( m_current
);
1343 UnfocusLine( oldCurrent
);
1346 void wxListMainWindow::OnChar( wxKeyEvent
&event
)
1349 if (event.KeyCode() == WXK_TAB)
1351 if (event.ShiftDown())
1358 if (!m_current
) return;
1359 switch (event
.KeyCode())
1363 wxNode
*node
= m_lines
.Member( m_current
)->Previous();
1364 if (node
) OnArrowChar( (wxListLineData
*)node
->Data(), event
.ShiftDown() );
1369 wxNode
*node
= m_lines
.Member( m_current
)->Next();
1370 if (node
) OnArrowChar( (wxListLineData
*)node
->Data(), event
.ShiftDown() );
1375 wxNode
*node
= m_lines
.Last();
1376 OnArrowChar( (wxListLineData
*)node
->Data(), event
.ShiftDown() );
1381 wxNode
*node
= m_lines
.First();
1382 OnArrowChar( (wxListLineData
*)node
->Data(), event
.ShiftDown() );
1388 if (m_mode
& wxLC_REPORT
) { steps
= m_visibleLines
-1; }
1392 wxNode
*node
= m_lines
.First();
1393 for (;;) { if (m_current
== (wxListLineData
*)node
->Data()) break; pos
++; node
= node
->Next(); }
1394 steps
= pos
% m_visibleLines
;
1396 wxNode
*node
= m_lines
.Member( m_current
);
1397 for (int i
= 0; i
< steps
; i
++) if (node
->Previous()) node
= node
->Previous();
1398 if (node
) OnArrowChar( (wxListLineData
*)node
->Data(), event
.ShiftDown() );
1404 if (m_mode
& wxLC_REPORT
) { steps
= m_visibleLines
-1; }
1407 int pos
= 0; wxNode
*node
= m_lines
.First();
1408 for (;;) { if (m_current
== (wxListLineData
*)node
->Data()) break; pos
++; node
= node
->Next(); }
1409 steps
= m_visibleLines
-(pos
% m_visibleLines
)-1;
1411 wxNode
*node
= m_lines
.Member( m_current
);
1412 for (int i
= 0; i
< steps
; i
++) if (node
->Next()) node
= node
->Next();
1413 if (node
) OnArrowChar( (wxListLineData
*)node
->Data(), event
.ShiftDown() );
1418 if (!(m_mode
& wxLC_REPORT
))
1420 wxNode
*node
= m_lines
.Member( m_current
);
1421 for (int i
= 0; i
<m_visibleLines
; i
++) if (node
->Previous()) node
= node
->Previous();
1422 if (node
) OnArrowChar( (wxListLineData
*)node
->Data(), event
.ShiftDown() );
1428 if (!(m_mode
& wxLC_REPORT
))
1430 wxNode
*node
= m_lines
.Member( m_current
);
1431 for (int i
= 0; i
<m_visibleLines
; i
++) if (node
->Next()) node
= node
->Next();
1432 if (node
) OnArrowChar( (wxListLineData
*)node
->Data(), event
.ShiftDown() );
1438 m_current
->ReverseHilight();
1439 RefreshLine( m_current
);
1444 if (!(m_mode
& wxLC_SINGLE_SEL
))
1446 wxListLineData
*oldCurrent
= m_current
;
1447 m_current
->ReverseHilight();
1448 wxNode
*node
= m_lines
.Member( m_current
)->Next();
1449 if (node
) m_current
= (wxListLineData
*)node
->Data();
1451 RefreshLine( oldCurrent
);
1452 RefreshLine( m_current
);
1453 UnfocusLine( oldCurrent
);
1454 FocusLine( m_current
);
1461 wxListEvent
le( wxEVT_COMMAND_LIST_KEY_DOWN
, GetParent()->GetId() );
1462 le
.SetEventObject( GetParent() );
1463 le
.m_itemIndex
= GetIndexOfLine( m_current
);
1464 m_current
->GetItem( 0, le
.m_item
);
1465 GetParent()->GetEventHandler()->ProcessEvent( le
);
1477 void wxListMainWindow::OnSetFocus( wxFocusEvent
&WXUNUSED(event
) )
1480 RefreshLine( m_current
);
1482 if (!GetParent()) return;
1484 wxFocusEvent
event( wxEVT_SET_FOCUS
, GetParent()->GetId() );
1485 event
.SetEventObject( GetParent() );
1486 GetParent()->GetEventHandler()->ProcessEvent( event
);
1489 void wxListMainWindow::OnKillFocus( wxFocusEvent
&WXUNUSED(event
) )
1492 RefreshLine( m_current
);
1495 void wxListMainWindow::OnSize( wxSizeEvent
&WXUNUSED(event
) )
1498 We don't even allow the wxScrolledWindow::AdjustScrollbars() call
1500 CalculatePositions();
1501 printf( "OnSize::Refresh.\n" );
1507 void wxListMainWindow::DrawImage( int index
, wxPaintDC
*dc
, int x
, int y
)
1509 if ((m_mode
& wxLC_ICON
) && (m_normal_image_list
))
1511 m_normal_image_list
->Draw( index
, *dc
, x
, y
, wxIMAGELIST_DRAW_TRANSPARENT
);
1514 if ((m_mode
& wxLC_SMALL_ICON
) && (m_small_image_list
))
1516 m_small_image_list
->Draw( index
, *dc
, x
, y
, wxIMAGELIST_DRAW_TRANSPARENT
);
1518 if ((m_mode
& wxLC_REPORT
) && (m_small_image_list
))
1520 m_small_image_list
->Draw( index
, *dc
, x
, y
, wxIMAGELIST_DRAW_TRANSPARENT
);
1525 void wxListMainWindow::GetImageSize( int index
, int &width
, int &height
)
1527 if ((m_mode
& wxLC_ICON
) && (m_normal_image_list
))
1529 m_normal_image_list
->GetSize( index
, width
, height
);
1532 if ((m_mode
& wxLC_SMALL_ICON
) && (m_small_image_list
))
1534 m_small_image_list
->GetSize( index
, width
, height
);
1537 if ((m_mode
& wxLC_REPORT
) && (m_small_image_list
))
1539 m_small_image_list
->GetSize( index
, width
, height
);
1546 int wxListMainWindow::GetTextLength( wxString
&s
)
1548 wxPaintDC
dc( this );
1551 dc
.GetTextExtent( s
, &lw
, &lh
);
1555 int wxListMainWindow::GetIndexOfLine( const wxListLineData
*line
)
1558 wxNode
*node
= m_lines
.First();
1561 if (line
== (wxListLineData
*)node
->Data()) return i
;
1563 node
= node
->Next();
1568 void wxListMainWindow::SetImageList( wxImageList
*imageList
, int which
)
1571 if (which
== wxIMAGE_LIST_NORMAL
) m_normal_image_list
= imageList
;
1572 if (which
== wxIMAGE_LIST_SMALL
) m_small_image_list
= imageList
;
1575 void wxListMainWindow::SetItemSpacing( int spacing
, bool isSmall
)
1580 m_small_spacing
= spacing
;
1584 m_normal_spacing
= spacing
;
1588 int wxListMainWindow::GetItemSpacing( bool isSmall
)
1590 if (isSmall
) return m_small_spacing
; else return m_normal_spacing
;
1593 void wxListMainWindow::SetColumn( int col
, wxListItem
&item
)
1596 wxNode
*node
= m_columns
.Nth( col
);
1599 if (item
.m_width
== wxLIST_AUTOSIZE_USEHEADER
) item
.m_width
= GetTextLength( item
.m_text
)+7;
1600 wxListHeaderData
*column
= (wxListHeaderData
*)node
->Data();
1601 column
->SetItem( item
);
1603 wxListCtrl
*lc
= (wxListCtrl
*) GetParent();
1604 if (lc
->m_headerWin
) lc
->m_headerWin
->Refresh();
1607 void wxListMainWindow::SetColumnWidth( int col
, int width
)
1609 if (!(m_mode
& wxLC_REPORT
)) return;
1613 wxNode
*node
= m_columns
.Nth( col
);
1616 wxListHeaderData
*column
= (wxListHeaderData
*)node
->Data();
1617 column
->SetWidth( width
);
1620 node
= m_lines
.First();
1623 wxListLineData
*line
= (wxListLineData
*)node
->Data();
1624 wxNode
*n
= line
->m_items
.Nth( col
);
1627 wxListItemData
*item
= (wxListItemData
*)n
->Data();
1628 item
->SetSize( width
, -1 );
1630 node
= node
->Next();
1633 wxListCtrl
*lc
= (wxListCtrl
*) GetParent();
1634 if (lc
->m_headerWin
) lc
->m_headerWin
->Refresh();
1637 void wxListMainWindow::GetColumn( int col
, wxListItem
&item
)
1639 wxNode
*node
= m_columns
.Nth( col
);
1642 wxListHeaderData
*column
= (wxListHeaderData
*)node
->Data();
1643 column
->GetItem( item
);
1655 int wxListMainWindow::GetColumnWidth( int col
)
1657 wxNode
*node
= m_columns
.Nth( col
);
1660 wxListHeaderData
*column
= (wxListHeaderData
*)node
->Data();
1661 return column
->GetWidth();
1669 int wxListMainWindow::GetColumnCount( void )
1671 return m_columns
.Number();
1674 int wxListMainWindow::GetCountPerPage( void )
1676 return m_visibleLines
;
1679 void wxListMainWindow::SetItem( wxListItem
&item
)
1682 wxNode
*node
= m_lines
.Nth( item
.m_itemId
);
1685 wxListLineData
*line
= (wxListLineData
*)node
->Data();
1686 if (m_mode
& wxLC_REPORT
) item
.m_width
= GetColumnWidth( item
.m_col
)-3;
1687 line
->SetItem( item
.m_col
, item
);
1691 void wxListMainWindow::SetItemState( long item
, long state
, long stateMask
)
1693 // m_dirty = TRUE; no recalcs needed
1695 wxListLineData
*oldCurrent
= m_current
;
1697 if (stateMask
& wxLIST_STATE_FOCUSED
)
1699 wxNode
*node
= m_lines
.Nth( item
);
1702 wxListLineData
*line
= (wxListLineData
*)node
->Data();
1703 UnfocusLine( m_current
);
1705 FocusLine( m_current
);
1706 RefreshLine( m_current
);
1707 RefreshLine( oldCurrent
);
1711 if (stateMask
& wxLIST_STATE_SELECTED
)
1713 bool on
= state
& wxLIST_STATE_SELECTED
;
1714 if (!on
&& (m_mode
& wxLC_SINGLE_SEL
)) return;
1716 wxNode
*node
= m_lines
.Nth( item
);
1719 wxListLineData
*line
= (wxListLineData
*)node
->Data();
1720 if (m_mode
& wxLC_SINGLE_SEL
)
1722 UnfocusLine( m_current
);
1724 FocusLine( m_current
);
1725 oldCurrent
->Hilight( FALSE
);
1726 RefreshLine( m_current
);
1727 RefreshLine( oldCurrent
);
1729 bool on
= state
& wxLIST_STATE_SELECTED
;
1730 line
->Hilight( on
);
1731 RefreshLine( line
);
1736 int wxListMainWindow::GetItemState( long item
, long stateMask
)
1738 int ret
= wxLIST_STATE_DONTCARE
;
1739 if (stateMask
& wxLIST_STATE_FOCUSED
)
1741 wxNode
*node
= m_lines
.Nth( item
);
1744 wxListLineData
*line
= (wxListLineData
*)node
->Data();
1745 if (line
== m_current
) ret
|= wxLIST_STATE_FOCUSED
;
1748 if (stateMask
& wxLIST_STATE_SELECTED
)
1750 wxNode
*node
= m_lines
.Nth( item
);
1753 wxListLineData
*line
= (wxListLineData
*)node
->Data();
1754 if (line
->IsHilighted()) ret
|= wxLIST_STATE_FOCUSED
;
1760 void wxListMainWindow::GetItem( wxListItem
&item
)
1762 wxNode
*node
= m_lines
.Nth( item
.m_itemId
);
1765 wxListLineData
*line
= (wxListLineData
*)node
->Data();
1766 line
->GetItem( item
.m_col
, item
);
1777 int wxListMainWindow::GetItemCount( void )
1779 return m_lines
.Number();
1782 void wxListMainWindow::GetItemRect( long index
, wxRectangle
&rect
)
1784 wxNode
*node
= m_lines
.Nth( index
);
1787 wxListLineData
*line
= (wxListLineData
*)node
->Data();
1788 line
->GetRect( rect
);
1799 bool wxListMainWindow::GetItemPosition(long item
, wxPoint
& pos
)
1801 wxNode
*node
= m_lines
.Nth( item
);
1805 wxListLineData
*line
= (wxListLineData
*)node
->Data();
1806 line
->GetRect( rect
);
1818 int wxListMainWindow::GetSelectedItemCount( void )
1821 wxNode
*node
= m_lines
.First();
1824 wxListLineData
*line
= (wxListLineData
*)node
->Data();
1825 if (line
->IsHilighted()) ret
++;
1826 node
= node
->Next();
1831 void wxListMainWindow::SetMode( long mode
)
1838 if (m_mode
& wxLC_REPORT
)
1850 long wxListMainWindow::GetMode( void ) const
1855 void wxListMainWindow::CalculatePositions( void )
1857 if (!m_lines
.First()) return;
1859 wxPaintDC
dc( this );
1860 dc
.SetFont( GetFont() );
1862 int iconSpacing
= 0;
1863 if (m_mode
& wxLC_ICON
) iconSpacing
= m_normal_spacing
;
1864 if (m_mode
& wxLC_SMALL_ICON
) iconSpacing
= m_small_spacing
;
1866 // we take the first line (which also can be an icon or
1867 // an a text item in wxLC_ICON and wxLC_LIST modes) to
1868 // measure the size of the line
1872 int lineSpacing
= 0;
1874 wxListLineData
*line
= (wxListLineData
*)m_lines
.First()->Data();
1875 line
->CalculateSize( &dc
, iconSpacing
);
1877 line
->GetSize( dummy
, lineSpacing
);
1880 int clientWidth
= 0;
1881 int clientHeight
= 0;
1883 if (m_mode
& wxLC_REPORT
)
1887 int entireHeight
= m_lines
.Number() * lineSpacing
+ 2;
1888 int scroll_pos
= GetScrollPos( wxVERTICAL
);
1889 SetScrollbars( m_xScroll
, m_yScroll
, 0, (entireHeight
+15-6) / m_yScroll
, 0, scroll_pos
, TRUE
);
1890 GetClientSize( &clientWidth
, &clientHeight
);
1892 wxNode
* node
= m_lines
.First();
1895 wxListLineData
*line
= (wxListLineData
*)node
->Data();
1896 line
->CalculateSize( &dc
, iconSpacing
);
1897 line
->SetPosition( &dc
, x
, y
, clientWidth
);
1899 for (int i
= 0; i
< GetColumnCount(); i
++)
1901 line
->SetColumnPosition( i
, col_x
);
1902 col_x
+= GetColumnWidth( i
);
1904 y
+= lineSpacing
; // one pixel blank line between items
1905 node
= node
->Next();
1907 m_visibleLines
= m_lines
.GetCount();
1911 // at first we try without any scrollbar. if the items don't
1912 // fit into the window, we recalculate after subtracting an
1913 // approximated 15 pt for the horizontal scrollbar
1915 GetSize( &clientWidth
, &clientHeight
);
1916 clientHeight
-= 4; // sunken frame
1918 int entireWidth
= 0;
1920 for (int tries
= 0; tries
< 2; tries
++)
1923 int x
= 5; // painting is done at x-2
1924 int y
= 5; // painting is done at y-2
1926 wxNode
*node
= m_lines
.First();
1929 wxListLineData
*line
= (wxListLineData
*)node
->Data();
1930 line
->CalculateSize( &dc
, iconSpacing
);
1931 line
->SetPosition( &dc
, x
, y
, clientWidth
);
1932 line
->GetSize( lineWidth
, lineHeight
);
1933 if (lineWidth
> maxWidth
) maxWidth
= lineWidth
;
1935 if (y
+lineSpacing
-7 >= clientHeight
) // -7 for earlier "line breaking"
1939 entireWidth
+= maxWidth
+5;
1942 node
= node
->Next();
1943 if (!node
) entireWidth
+= maxWidth
;
1944 if ((tries
== 0) && (entireWidth
> clientWidth
))
1946 clientHeight
-= 15; // scrollbar height
1949 if (!node
) tries
= 1; // everything fits, no second try required
1952 m_visibleLines
= (clientHeight
+7) / (lineSpacing
); // +7 for earlier "line breaking"
1954 int scroll_pos
= GetScrollPos( wxHORIZONTAL
);
1955 SetScrollbars( m_xScroll
, m_yScroll
, (entireWidth
+15) / m_xScroll
, 0, scroll_pos
, 0, TRUE
);
1959 void wxListMainWindow::RealizeChanges( void )
1963 wxNode
*node
= m_lines
.First();
1964 if (node
) m_current
= (wxListLineData
*)node
->Data();
1968 FocusLine( m_current
);
1969 if (m_mode
& wxLC_SINGLE_SEL
) m_current
->Hilight( TRUE
);
1973 long wxListMainWindow::GetNextItem( long item
, int WXUNUSED(geometry
), int state
)
1976 if (item
> 0) ret
= item
;
1977 wxNode
*node
= m_lines
.Nth( ret
);
1980 wxListLineData
*line
= (wxListLineData
*)node
->Data();
1981 if ((state
& wxLIST_STATE_FOCUSED
) && (line
== m_current
)) return ret
;
1982 if ((state
& wxLIST_STATE_SELECTED
) && (line
->IsHilighted())) return ret
;
1983 if (!state
) return ret
;
1985 node
= node
->Next();
1990 void wxListMainWindow::DeleteItem( long index
)
1993 wxNode
*node
= m_lines
.Nth( index
);
1996 wxListLineData
*line
= (wxListLineData
*)node
->Data();
1997 if (m_current
== line
) m_current
= (wxListLineData
*) NULL
;
1999 m_lines
.DeleteNode( node
);
2003 void wxListMainWindow::DeleteColumn( int col
)
2005 wxCHECK_RET( col
< (int)m_columns
.GetCount(),
2006 "attempting to delete inexistent column in wxListView" );
2009 wxNode
*node
= m_columns
.Nth( col
);
2010 if (node
) m_columns
.DeleteNode( node
);
2013 void wxListMainWindow::DeleteAllItems( void )
2016 m_current
= (wxListLineData
*) NULL
;
2017 wxNode
*node
= m_lines
.First();
2020 wxListLineData
*line
= (wxListLineData
*)node
->Data();
2022 node
= node
->Next();
2027 void wxListMainWindow::DeleteEverything( void )
2030 m_current
= (wxListLineData
*) NULL
;
2031 wxNode
*node
= m_lines
.First();
2034 wxListLineData
*line
= (wxListLineData
*)node
->Data();
2036 node
= node
->Next();
2039 m_current
= (wxListLineData
*) NULL
;
2043 void wxListMainWindow::EnsureVisible( long index
)
2045 wxListLineData
*oldCurrent
= m_current
;
2046 m_current
= (wxListLineData
*) NULL
;
2048 wxNode
*node
= m_lines
.Nth( i
);
2049 if (node
) m_current
= (wxListLineData
*)node
->Data();
2050 if (m_current
) MoveToFocus();
2051 m_current
= oldCurrent
;
2054 long wxListMainWindow::FindItem(long start
, const wxString
& str
, bool WXUNUSED(partial
) )
2058 if (pos
< 0) pos
= 0;
2059 wxNode
*node
= m_lines
.Nth( pos
);
2062 wxListLineData
*line
= (wxListLineData
*)node
->Data();
2064 line
->GetText( 0, s
);
2065 if (s
== tmp
) return pos
;
2066 node
= node
->Next();
2072 long wxListMainWindow::FindItem(long start
, long data
)
2075 if (pos
< 0) pos
= 0;
2076 wxNode
*node
= m_lines
.Nth( pos
);
2079 wxListLineData
*line
= (wxListLineData
*)node
->Data();
2081 line
->GetItem( 0, item
);
2082 if (item
.m_data
== data
) return pos
;
2083 node
= node
->Next();
2089 long wxListMainWindow::HitTest( int x
, int y
, int &flags
)
2091 wxNode
*node
= m_lines
.First();
2095 wxListLineData
*line
= (wxListLineData
*)node
->Data();
2096 long ret
= line
->IsHit( x
, y
);
2102 node
= node
->Next();
2108 void wxListMainWindow::InsertItem( wxListItem
&item
)
2112 if (m_mode
& wxLC_REPORT
) mode
= wxLC_REPORT
;
2113 else if (m_mode
& wxLC_LIST
) mode
= wxLC_LIST
;
2114 else if (m_mode
& wxLC_ICON
) mode
= wxLC_ICON
;
2115 else if (m_mode
& wxLC_SMALL_ICON
) mode
= wxLC_ICON
; // no typo
2116 wxListLineData
*line
= new wxListLineData( this, mode
, m_hilightBrush
);
2117 if (m_mode
& wxLC_REPORT
)
2119 line
->InitItems( GetColumnCount() );
2120 item
.m_width
= GetColumnWidth( 0 )-3;
2123 line
->InitItems( 1 );
2124 line
->SetItem( 0, item
);
2125 if ((item
.m_itemId
>= 0) && (item
.m_itemId
< (int)m_lines
.GetCount()))
2127 wxNode
*node
= m_lines
.Nth( item
.m_itemId
);
2128 if (node
) m_lines
.Insert( node
, line
);
2132 m_lines
.Append( line
);
2136 void wxListMainWindow::InsertColumn( long col
, wxListItem
&item
)
2139 if (m_mode
& wxLC_REPORT
)
2141 if (item
.m_width
== wxLIST_AUTOSIZE_USEHEADER
) item
.m_width
= GetTextLength( item
.m_text
);
2142 wxListHeaderData
*column
= new wxListHeaderData( item
);
2143 if ((col
>= 0) && (col
< (int)m_columns
.GetCount()))
2145 wxNode
*node
= m_columns
.Nth( col
);
2147 m_columns
.Insert( node
, column
);
2151 m_columns
.Append( column
);
2156 wxListCtrlCompare list_ctrl_compare_func_2
;
2157 long list_ctrl_compare_data
;
2159 int list_ctrl_compare_func_1( const void *arg1
, const void *arg2
)
2161 wxListLineData
*line1
= *((wxListLineData
**)arg1
);
2162 wxListLineData
*line2
= *((wxListLineData
**)arg2
);
2164 line1
->GetItem( 0, item
);
2165 long data1
= item
.m_data
;
2166 line2
->GetItem( 0, item
);
2167 long data2
= item
.m_data
;
2168 return list_ctrl_compare_func_2( data1
, data2
, list_ctrl_compare_data
);
2171 void wxListMainWindow::SortItems( wxListCtrlCompare fn
, long data
)
2173 list_ctrl_compare_func_2
= fn
;
2174 list_ctrl_compare_data
= data
;
2175 m_lines
.Sort( list_ctrl_compare_func_1
);
2178 // -------------------------------------------------------------------------------------
2180 // -------------------------------------------------------------------------------------
2182 IMPLEMENT_DYNAMIC_CLASS(wxListItem
, wxObject
)
2184 wxListItem::wxListItem(void)
2193 m_format
= wxLIST_FORMAT_CENTRE
;
2198 // -------------------------------------------------------------------------------------
2200 // -------------------------------------------------------------------------------------
2202 IMPLEMENT_DYNAMIC_CLASS(wxListEvent
, wxNotifyEvent
)
2204 wxListEvent::wxListEvent( wxEventType commandType
, int id
):
2205 wxNotifyEvent( commandType
, id
)
2211 m_cancelled
= FALSE
;
2216 // -------------------------------------------------------------------------------------
2218 // -------------------------------------------------------------------------------------
2220 IMPLEMENT_DYNAMIC_CLASS(wxListCtrl
, wxControl
)
2222 BEGIN_EVENT_TABLE(wxListCtrl
,wxControl
)
2223 EVT_SIZE (wxListCtrl::OnSize
)
2224 EVT_IDLE (wxListCtrl::OnIdle
)
2227 wxListCtrl::wxListCtrl(void)
2229 m_imageListNormal
= (wxImageList
*) NULL
;
2230 m_imageListSmall
= (wxImageList
*) NULL
;
2231 m_imageListState
= (wxImageList
*) NULL
;
2232 m_mainWin
= (wxListMainWindow
*) NULL
;
2233 m_headerWin
= (wxListHeaderWindow
*) NULL
;
2236 wxListCtrl::~wxListCtrl(void)
2240 bool wxListCtrl::Create( wxWindow
*parent
, wxWindowID id
,
2241 const wxPoint
&pos
, const wxSize
&size
,
2242 long style
, const wxValidator
&validator
,
2243 const wxString
&name
)
2245 m_imageListNormal
= (wxImageList
*) NULL
;
2246 m_imageListSmall
= (wxImageList
*) NULL
;
2247 m_imageListState
= (wxImageList
*) NULL
;
2248 m_mainWin
= (wxListMainWindow
*) NULL
;
2249 m_headerWin
= (wxListHeaderWindow
*) NULL
;
2253 if ((s
& wxLC_REPORT
== 0) &&
2254 (s
& wxLC_LIST
== 0) &&
2255 (s
& wxLC_ICON
== 0))
2258 bool ret
= wxControl::Create( parent
, id
, pos
, size
, s
, name
);
2260 SetValidator( validator
);
2262 if (s
& wxSUNKEN_BORDER
) s
-= wxSUNKEN_BORDER
;
2264 m_mainWin
= new wxListMainWindow( this, -1, wxPoint(0,0), size
, s
);
2266 if (GetWindowStyleFlag() & wxLC_REPORT
)
2267 m_headerWin
= new wxListHeaderWindow( this, -1, m_mainWin
, wxPoint(0,0), wxSize(size
.x
,23) );
2269 m_headerWin
= (wxListHeaderWindow
*) NULL
;
2274 void wxListCtrl::OnSize( wxSizeEvent
&WXUNUSED(event
) )
2276 // handled in OnIdle
2278 if (m_mainWin
) m_mainWin
->m_dirty
= TRUE
;
2281 void wxListCtrl::SetSingleStyle( long style
, bool add
)
2283 long flag
= GetWindowStyleFlag();
2287 if (style
& wxLC_MASK_TYPE
) flag
= flag
& ~wxLC_MASK_TYPE
;
2288 if (style
& wxLC_MASK_ALIGN
) flag
= flag
& ~wxLC_MASK_ALIGN
;
2289 if (style
& wxLC_MASK_SORT
) flag
= flag
& ~wxLC_MASK_SORT
;
2298 if (flag
& style
) flag
-= style
;
2301 SetWindowStyleFlag( flag
);
2304 void wxListCtrl::SetWindowStyleFlag( long flag
)
2306 m_mainWin
->DeleteEverything();
2310 GetClientSize( &width
, &height
);
2312 m_mainWin
->SetMode( flag
);
2314 if (flag
& wxLC_REPORT
)
2316 if (!(GetWindowStyleFlag() & wxLC_REPORT
))
2318 // m_mainWin->SetSize( 0, 24, width, height-24 );
2321 m_headerWin
= new wxListHeaderWindow( this, -1, m_mainWin
, wxPoint(0,0), wxSize(width
,23) );
2325 // m_headerWin->SetSize( 0, 0, width, 23 );
2326 m_headerWin
->Show( TRUE
);
2332 if (GetWindowStyleFlag() & wxLC_REPORT
)
2334 // m_mainWin->SetSize( 0, 0, width, height );
2335 m_headerWin
->Show( FALSE
);
2339 wxWindow::SetWindowStyleFlag( flag
);
2342 bool wxListCtrl::GetColumn(int col
, wxListItem
&item
) const
2344 m_mainWin
->GetColumn( col
, item
);
2348 bool wxListCtrl::SetColumn( int col
, wxListItem
& item
)
2350 m_mainWin
->SetColumn( col
, item
);
2354 int wxListCtrl::GetColumnWidth( int col
) const
2356 return m_mainWin
->GetColumnWidth( col
);
2359 bool wxListCtrl::SetColumnWidth( int col
, int width
)
2361 m_mainWin
->SetColumnWidth( col
, width
);
2365 int wxListCtrl::GetCountPerPage(void) const
2367 return m_mainWin
->GetCountPerPage(); // different from Windows ?
2371 wxText& wxListCtrl::GetEditControl(void) const
2376 bool wxListCtrl::GetItem( wxListItem
&info
) const
2378 m_mainWin
->GetItem( info
);
2382 bool wxListCtrl::SetItem( wxListItem
&info
)
2384 m_mainWin
->SetItem( info
);
2388 long wxListCtrl::SetItem( long index
, int col
, const wxString
& label
, int imageId
)
2391 info
.m_text
= label
;
2392 info
.m_mask
= wxLIST_MASK_TEXT
;
2393 info
.m_itemId
= index
;
2397 info
.m_image
= imageId
;
2398 info
.m_mask
|= wxLIST_MASK_IMAGE
;
2401 m_mainWin
->SetItem(info
);
2405 int wxListCtrl::GetItemState( long item
, long stateMask
) const
2407 return m_mainWin
->GetItemState( item
, stateMask
);
2410 bool wxListCtrl::SetItemState( long item
, long state
, long stateMask
)
2412 m_mainWin
->SetItemState( item
, state
, stateMask
);
2416 bool wxListCtrl::SetItemImage( long item
, int image
, int WXUNUSED(selImage
) )
2419 info
.m_image
= image
;
2420 info
.m_mask
= wxLIST_MASK_IMAGE
;
2421 info
.m_itemId
= item
;
2422 m_mainWin
->SetItem( info
);
2426 wxString
wxListCtrl::GetItemText( long item
) const
2429 info
.m_itemId
= item
;
2430 m_mainWin
->GetItem( info
);
2434 void wxListCtrl::SetItemText( long item
, const wxString
&str
)
2437 info
.m_mask
= wxLIST_MASK_TEXT
;
2438 info
.m_itemId
= item
;
2440 m_mainWin
->SetItem( info
);
2443 long wxListCtrl::GetItemData( long item
) const
2446 info
.m_itemId
= item
;
2447 m_mainWin
->GetItem( info
);
2451 bool wxListCtrl::SetItemData( long item
, long data
)
2454 info
.m_mask
= wxLIST_MASK_DATA
;
2455 info
.m_itemId
= item
;
2457 m_mainWin
->SetItem( info
);
2461 bool wxListCtrl::GetItemRect( long item
, wxRectangle
&rect
, int WXUNUSED(code
) ) const
2463 m_mainWin
->GetItemRect( item
, rect
);
2467 bool wxListCtrl::GetItemPosition( long item
, wxPoint
& pos
) const
2469 m_mainWin
->GetItemPosition( item
, pos
);
2473 bool wxListCtrl::SetItemPosition( long WXUNUSED(item
), const wxPoint
& WXUNUSED(pos
) )
2478 int wxListCtrl::GetItemCount(void) const
2480 return m_mainWin
->GetItemCount();
2483 int wxListCtrl::GetColumnCount(void) const
2485 return m_mainWin
->GetColumnCount();
2488 void wxListCtrl::SetItemSpacing( int spacing
, bool isSmall
)
2490 m_mainWin
->SetItemSpacing( spacing
, isSmall
);
2493 int wxListCtrl::GetItemSpacing( bool isSmall
) const
2495 return m_mainWin
->GetItemSpacing( isSmall
);
2498 int wxListCtrl::GetSelectedItemCount(void) const
2500 return m_mainWin
->GetSelectedItemCount();
2504 wxColour wxListCtrl::GetTextColour(void) const
2508 void wxListCtrl::SetTextColour(const wxColour& WXUNUSED(col))
2513 long wxListCtrl::GetTopItem(void) const
2518 long wxListCtrl::GetNextItem( long item
, int geom
, int state
) const
2520 return m_mainWin
->GetNextItem( item
, geom
, state
);
2523 wxImageList
*wxListCtrl::GetImageList(int which
) const
2525 if (which
== wxIMAGE_LIST_NORMAL
)
2527 return m_imageListNormal
;
2529 else if (which
== wxIMAGE_LIST_SMALL
)
2531 return m_imageListSmall
;
2533 else if (which
== wxIMAGE_LIST_STATE
)
2535 return m_imageListState
;
2537 return (wxImageList
*) NULL
;
2540 void wxListCtrl::SetImageList( wxImageList
*imageList
, int which
)
2542 m_mainWin
->SetImageList( imageList
, which
);
2545 bool wxListCtrl::Arrange( int WXUNUSED(flag
) )
2550 bool wxListCtrl::DeleteItem( long item
)
2552 m_mainWin
->DeleteItem( item
);
2556 bool wxListCtrl::DeleteAllItems(void)
2558 m_mainWin
->DeleteAllItems();
2562 void wxListCtrl::DeleteAllColumns()
2564 for ( size_t n
= 0; n
< m_mainWin
->m_columns
.GetCount(); n
++ )
2568 bool wxListCtrl::DeleteColumn( int col
)
2570 m_mainWin
->DeleteColumn( col
);
2575 wxText& wxListCtrl::Edit( long WXUNUSED(item ) )
2580 bool wxListCtrl::EnsureVisible( long item
)
2582 m_mainWin
->EnsureVisible( item
);
2586 long wxListCtrl::FindItem( long start
, const wxString
& str
, bool partial
)
2588 return m_mainWin
->FindItem( start
, str
, partial
);
2591 long wxListCtrl::FindItem( long start
, long data
)
2593 return m_mainWin
->FindItem( start
, data
);
2596 long wxListCtrl::FindItem( long WXUNUSED(start
), const wxPoint
& WXUNUSED(pt
),
2597 int WXUNUSED(direction
))
2602 long wxListCtrl::HitTest( const wxPoint
&point
, int &flags
)
2604 return m_mainWin
->HitTest( (int)point
.x
, (int)point
.y
, flags
);
2607 long wxListCtrl::InsertItem( wxListItem
& info
)
2609 m_mainWin
->InsertItem( info
);
2613 long wxListCtrl::InsertItem( long index
, const wxString
&label
)
2616 info
.m_text
= label
;
2617 info
.m_mask
= wxLIST_MASK_TEXT
;
2618 info
.m_itemId
= index
;
2619 return InsertItem( info
);
2622 long wxListCtrl::InsertItem( long index
, int imageIndex
)
2625 info
.m_mask
= wxLIST_MASK_IMAGE
;
2626 info
.m_image
= imageIndex
;
2627 info
.m_itemId
= index
;
2628 return InsertItem( info
);
2631 long wxListCtrl::InsertItem( long index
, const wxString
&label
, int imageIndex
)
2634 info
.m_text
= label
;
2635 info
.m_image
= imageIndex
;
2636 info
.m_mask
= wxLIST_MASK_TEXT
| wxLIST_MASK_IMAGE
;
2637 info
.m_itemId
= index
;
2638 return InsertItem( info
);
2641 long wxListCtrl::InsertColumn( long col
, wxListItem
&item
)
2643 m_mainWin
->InsertColumn( col
, item
);
2647 long wxListCtrl::InsertColumn( long col
, const wxString
&heading
,
2648 int format
, int width
)
2651 item
.m_mask
= wxLIST_MASK_TEXT
| wxLIST_MASK_FORMAT
;
2652 item
.m_text
= heading
;
2655 item
.m_mask
|= wxLIST_MASK_WIDTH
;
2656 item
.m_width
= width
;
2659 item
.m_format
= format
;
2661 return InsertColumn( col
, item
);
2664 bool wxListCtrl::ScrollList( int WXUNUSED(dx
), int WXUNUSED(dy
) )
2670 // fn is a function which takes 3 long arguments: item1, item2, data.
2671 // item1 is the long data associated with a first item (NOT the index).
2672 // item2 is the long data associated with a second item (NOT the index).
2673 // data is the same value as passed to SortItems.
2674 // The return value is a negative number if the first item should precede the second
2675 // item, a positive number of the second item should precede the first,
2676 // or zero if the two items are equivalent.
2677 // data is arbitrary data to be passed to the sort function.
2679 bool wxListCtrl::SortItems( wxListCtrlCompare fn
, long data
)
2681 m_mainWin
->SortItems( fn
, data
);
2685 void wxListCtrl::OnIdle( wxIdleEvent
&WXUNUSED(event
) )
2687 if (!m_mainWin
->m_dirty
) return;
2691 GetClientSize( &cw
, &ch
);
2698 if (GetWindowStyleFlag() & wxLC_REPORT
)
2700 m_headerWin
->GetPosition( &x
, &y
);
2701 m_headerWin
->GetSize( &w
, &h
);
2702 if ((x
!= 0) || (y
!= 0) || (w
!= cw
) || (h
!= 23))
2703 m_headerWin
->SetSize( 0, 0, cw
, 23 );
2705 m_mainWin
->GetPosition( &x
, &y
);
2706 m_mainWin
->GetSize( &w
, &h
);
2707 if ((x
!= 0) || (y
!= 24) || (w
!= cw
) || (h
!= ch
-24))
2708 m_mainWin
->SetSize( 0, 24, cw
, ch
-24 );
2712 m_mainWin
->GetPosition( &x
, &y
);
2713 m_mainWin
->GetSize( &w
, &h
);
2714 if ((x
!= 0) || (y
!= 24) || (w
!= cw
) || (h
!= ch
))
2715 m_mainWin
->SetSize( 0, 0, cw
, ch
);
2718 m_mainWin
->CalculatePositions();
2719 m_mainWin
->RealizeChanges();
2720 m_mainWin
->m_dirty
= FALSE
;
2721 m_mainWin
->Refresh();
2724 void wxListCtrl::SetBackgroundColour( const wxColour
&colour
)
2728 m_mainWin
->SetBackgroundColour( colour
);
2729 m_mainWin
->m_dirty
= TRUE
;
2732 m_headerWin
->SetBackgroundColour( colour
);
2735 void wxListCtrl::SetForegroundColour( const wxColour
&colour
)
2739 m_mainWin
->SetForegroundColour( colour
);
2740 m_mainWin
->m_dirty
= TRUE
;
2743 m_headerWin
->SetForegroundColour( colour
);
2746 void wxListCtrl::SetFont( const wxFont
&font
)
2750 m_mainWin
->SetFont( font
);
2751 m_mainWin
->m_dirty
= TRUE
;
2754 m_headerWin
->SetFont( font
);