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 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::ActivateLine( wxListLineData
*line
)
1069 if (!GetParent()) return;
1070 wxListEvent
le( wxEVT_COMMAND_LIST_KEY_DOWN
, GetParent()->GetId() );
1071 le
.SetEventObject( GetParent() );
1073 le
.m_itemIndex
= GetIndexOfLine( line
);
1075 line
->GetItem( 0, le
.m_item
);
1079 void wxListMainWindow::SendNotify( wxListLineData
*line
, wxEventType command
)
1081 if (!GetParent()) return;
1082 wxListEvent
le( command
, GetParent()->GetId() );
1083 le
.SetEventObject( GetParent() );
1085 le
.m_itemIndex
= GetIndexOfLine( line
);
1087 line
->GetItem( 0, le
.m_item
);
1091 void wxListMainWindow::FocusLine( wxListLineData
*WXUNUSED(line
) )
1093 // SendNotify( line, wxEVT_COMMAND_LIST_ITEM_FOCUSSED );
1096 void wxListMainWindow::UnfocusLine( wxListLineData
*WXUNUSED(line
) )
1098 // SendNotify( line, wxEVT_COMMAND_LIST_ITEM_UNFOCUSSED );
1101 void wxListMainWindow::SelectLine( wxListLineData
*line
)
1103 SendNotify( line
, wxEVT_COMMAND_LIST_ITEM_SELECTED
);
1106 void wxListMainWindow::DeselectLine( wxListLineData
*line
)
1108 SendNotify( line
, wxEVT_COMMAND_LIST_ITEM_DESELECTED
);
1111 void wxListMainWindow::DeleteLine( wxListLineData
*line
)
1113 SendNotify( line
, wxEVT_COMMAND_LIST_DELETE_ITEM
);
1116 void wxListMainWindow::StartLabelEdit( wxListLineData
*line
)
1118 SendNotify( line
, wxEVT_COMMAND_LIST_BEGIN_LABEL_EDIT
);
1121 void wxListMainWindow::RenameLine( wxListLineData
*line
, const wxString
&newName
)
1123 if (!GetParent()) return;
1125 wxListEvent
le( wxEVT_COMMAND_LIST_END_LABEL_EDIT
, GetParent()->GetId() );
1126 le
.SetEventObject( GetParent() );
1128 le
.m_itemIndex
= GetIndexOfLine( line
);
1130 line
->GetItem( 0, le
.m_item
);
1131 le
.m_item
.m_text
= newName
;
1135 void wxListMainWindow::OnRenameTimer()
1137 StartLabelEdit( m_current
);
1139 m_current
->GetText( 0, s
);
1144 m_current
->GetLabelExtent( x
, y
, w
, h
);
1146 wxClientDC
dc(this);
1148 x
= dc
.LogicalToDeviceX( x
);
1149 y
= dc
.LogicalToDeviceY( y
);
1151 wxListTextCtrl
*text
= new wxListTextCtrl(
1152 this, -1, &m_renameAccept
, &m_renameRes
, this, s
, wxPoint(x
-4,y
-4), wxSize(w
+11,h
+8) );
1155 m_text->SetSize( x+3, y+3, w+6, h+6 );
1156 m_text->SetValue( s );
1157 m_text->Show( TRUE );
1161 char *res = wxGetTextFromUser( _("Enter new name:"), "", s );
1166 RenameLine( m_current, s );
1171 void wxListMainWindow::OnRenameAccept()
1173 RenameLine( m_current
, m_renameRes
);
1176 void wxListMainWindow::OnMouse( wxMouseEvent
&event
)
1178 if (GetParent()->GetEventHandler()->ProcessEvent( event
)) return;
1180 if (!m_current
) return;
1181 if (m_dirty
) return;
1183 wxClientDC
dc(this);
1185 long x
= dc
.DeviceToLogicalX( (long)event
.GetX() );
1186 long y
= dc
.DeviceToLogicalY( (long)event
.GetY() );
1189 wxNode
*node
= m_lines
.First();
1190 wxListLineData
*line
= (wxListLineData
*) NULL
;
1193 line
= (wxListLineData
*)node
->Data();
1194 hitResult
= line
->IsHit( x
, y
);
1195 if (hitResult
) break;
1196 line
= (wxListLineData
*) NULL
;
1197 node
= node
->Next();
1200 if (!event
.Dragging())
1205 if (event
.Dragging() && (m_dragCount
> 3))
1208 wxListEvent
le( wxEVT_COMMAND_LIST_BEGIN_DRAG
, GetParent()->GetId() );
1209 le
.SetEventObject( this );
1218 if (event
.ButtonDClick())
1221 m_lastOnSame
= FALSE
;
1222 m_renameTimer
->Stop();
1223 ActivateLine( line
);
1227 if (event
.LeftUp() && m_lastOnSame
)
1230 if ((line
== m_current
) &&
1231 (hitResult
== wxLIST_HITTEST_ONITEMLABEL
) &&
1232 // (m_mode & wxLC_ICON) &&
1233 (m_mode
& wxLC_EDIT_LABELS
) )
1235 m_renameTimer
->Start( 100, TRUE
);
1237 m_lastOnSame
= FALSE
;
1241 if (event
.LeftDown())
1244 wxListLineData
*oldCurrent
= m_current
;
1245 if (m_mode
& wxLC_SINGLE_SEL
)
1248 HilightAll( FALSE
);
1249 m_current
->ReverseHilight();
1250 RefreshLine( m_current
);
1254 if (event
.ShiftDown())
1257 m_current
->ReverseHilight();
1258 RefreshLine( m_current
);
1260 else if (event
.ControlDown())
1263 int numOfCurrent
= -1;
1264 node
= m_lines
.First();
1267 wxListLineData
*test_line
= (wxListLineData
*)node
->Data();
1269 if (test_line
== oldCurrent
) break;
1270 node
= node
->Next();
1273 node
= m_lines
.First();
1276 wxListLineData
*test_line
= (wxListLineData
*)node
->Data();
1278 if (test_line
== line
) break;
1279 node
= node
->Next();
1282 if (numOfLine
< numOfCurrent
)
1283 { int i
= numOfLine
; numOfLine
= numOfCurrent
; numOfCurrent
= i
; }
1284 wxNode
*node
= m_lines
.Nth( numOfCurrent
);
1285 for (int i
= 0; i
<= numOfLine
-numOfCurrent
; i
++)
1287 wxListLineData
*test_line
= (wxListLineData
*)node
->Data();
1288 test_line
->Hilight(TRUE
);
1289 RefreshLine( test_line
);
1290 node
= node
->Next();
1296 HilightAll( FALSE
);
1297 m_current
->ReverseHilight();
1298 RefreshLine( m_current
);
1301 if (m_current
!= oldCurrent
)
1303 RefreshLine( oldCurrent
);
1304 UnfocusLine( oldCurrent
);
1305 FocusLine( m_current
);
1307 m_lastOnSame
= (m_current
== oldCurrent
);
1313 void wxListMainWindow::MoveToFocus( void )
1315 if (!m_current
) return;
1321 m_current
->GetExtent( x
, y
, w
, h
);
1324 GetClientSize( &w_p
, &h_p
);
1325 if (m_mode
& wxLC_REPORT
)
1327 if (GetScrollPos( wxHORIZONTAL
) != 0) SetScrollPos( wxHORIZONTAL
, 0);
1328 int y_s
= m_yScroll
*GetScrollPos( wxVERTICAL
);
1329 if ((y
> y_s
) && (y
+h
< y_s
+h_p
)) return;
1330 if (y
-y_s
< 5) SetScrollPos( wxVERTICAL
, (y
-5)/m_yScroll
);
1331 if (y
+h
+5 > y_s
+h_p
) SetScrollPos( wxVERTICAL
, (y
+h
-h_p
+h
+15)/m_yScroll
);
1336 if (GetScrollPos( wxVERTICAL
) != 0) SetScrollPos( wxVERTICAL
, 0);
1337 int x_s
= m_xScroll
*GetScrollPos( wxHORIZONTAL
);
1338 if ((x
> x_s
) && (x
+w
< x_s
+w_p
)) return;
1339 if (x
-x_s
< 5) SetScrollPos( wxHORIZONTAL
, (x
-5)/m_xScroll
);
1340 if (x
+w
-5 > x_s
+w_p
) SetScrollPos( wxHORIZONTAL
, (x
+w
-w_p
+15)/m_xScroll
);
1345 void wxListMainWindow::OnArrowChar( wxListLineData
*newCurrent
, bool shiftDown
)
1347 if ((m_mode
& wxLC_SINGLE_SEL
) || (m_usedKeys
== FALSE
)) m_current
->Hilight( FALSE
);
1348 wxListLineData
*oldCurrent
= m_current
;
1349 m_current
= newCurrent
;
1351 if (shiftDown
|| (m_mode
& wxLC_SINGLE_SEL
)) m_current
->Hilight( TRUE
);
1352 RefreshLine( m_current
);
1353 RefreshLine( oldCurrent
);
1354 FocusLine( m_current
);
1355 UnfocusLine( oldCurrent
);
1358 void wxListMainWindow::OnChar( wxKeyEvent
&event
)
1361 if (event.KeyCode() == WXK_TAB)
1363 if (event.ShiftDown())
1370 if (!m_current
) return;
1371 switch (event
.KeyCode())
1375 wxNode
*node
= m_lines
.Member( m_current
)->Previous();
1376 if (node
) OnArrowChar( (wxListLineData
*)node
->Data(), event
.ShiftDown() );
1381 wxNode
*node
= m_lines
.Member( m_current
)->Next();
1382 if (node
) OnArrowChar( (wxListLineData
*)node
->Data(), event
.ShiftDown() );
1387 wxNode
*node
= m_lines
.Last();
1388 OnArrowChar( (wxListLineData
*)node
->Data(), event
.ShiftDown() );
1393 wxNode
*node
= m_lines
.First();
1394 OnArrowChar( (wxListLineData
*)node
->Data(), event
.ShiftDown() );
1400 if (m_mode
& wxLC_REPORT
) { steps
= m_visibleLines
-1; }
1404 wxNode
*node
= m_lines
.First();
1405 for (;;) { if (m_current
== (wxListLineData
*)node
->Data()) break; pos
++; node
= node
->Next(); }
1406 steps
= pos
% m_visibleLines
;
1408 wxNode
*node
= m_lines
.Member( m_current
);
1409 for (int i
= 0; i
< steps
; i
++) if (node
->Previous()) node
= node
->Previous();
1410 if (node
) OnArrowChar( (wxListLineData
*)node
->Data(), event
.ShiftDown() );
1416 if (m_mode
& wxLC_REPORT
) { steps
= m_visibleLines
-1; }
1419 int pos
= 0; wxNode
*node
= m_lines
.First();
1420 for (;;) { if (m_current
== (wxListLineData
*)node
->Data()) break; pos
++; node
= node
->Next(); }
1421 steps
= m_visibleLines
-(pos
% m_visibleLines
)-1;
1423 wxNode
*node
= m_lines
.Member( m_current
);
1424 for (int i
= 0; i
< steps
; i
++) if (node
->Next()) node
= node
->Next();
1425 if (node
) OnArrowChar( (wxListLineData
*)node
->Data(), event
.ShiftDown() );
1430 if (!(m_mode
& wxLC_REPORT
))
1432 wxNode
*node
= m_lines
.Member( m_current
);
1433 for (int i
= 0; i
<m_visibleLines
; i
++) if (node
->Previous()) node
= node
->Previous();
1434 if (node
) OnArrowChar( (wxListLineData
*)node
->Data(), event
.ShiftDown() );
1440 if (!(m_mode
& wxLC_REPORT
))
1442 wxNode
*node
= m_lines
.Member( m_current
);
1443 for (int i
= 0; i
<m_visibleLines
; i
++) if (node
->Next()) node
= node
->Next();
1444 if (node
) OnArrowChar( (wxListLineData
*)node
->Data(), event
.ShiftDown() );
1450 m_current
->ReverseHilight();
1451 RefreshLine( m_current
);
1456 if (!(m_mode
& wxLC_SINGLE_SEL
))
1458 wxListLineData
*oldCurrent
= m_current
;
1459 m_current
->ReverseHilight();
1460 wxNode
*node
= m_lines
.Member( m_current
)->Next();
1461 if (node
) m_current
= (wxListLineData
*)node
->Data();
1463 RefreshLine( oldCurrent
);
1464 RefreshLine( m_current
);
1465 UnfocusLine( oldCurrent
);
1466 FocusLine( m_current
);
1473 ActivateLine( m_current
);
1485 void wxListMainWindow::OnSetFocus( wxFocusEvent
&WXUNUSED(event
) )
1488 RefreshLine( m_current
);
1490 if (!GetParent()) return;
1492 wxFocusEvent
event( wxEVT_SET_FOCUS
, GetParent()->GetId() );
1493 event
.SetEventObject( GetParent() );
1494 GetParent()->GetEventHandler()->ProcessEvent( event
);
1497 void wxListMainWindow::OnKillFocus( wxFocusEvent
&WXUNUSED(event
) )
1500 RefreshLine( m_current
);
1503 void wxListMainWindow::OnSize( wxSizeEvent
&WXUNUSED(event
) )
1506 We don't even allow the wxScrolledWindow::AdjustScrollbars() call
1508 CalculatePositions();
1509 printf( "OnSize::Refresh.\n" );
1515 void wxListMainWindow::DrawImage( int index
, wxPaintDC
*dc
, int x
, int y
)
1517 if ((m_mode
& wxLC_ICON
) && (m_normal_image_list
))
1519 m_normal_image_list
->Draw( index
, *dc
, x
, y
, wxIMAGELIST_DRAW_TRANSPARENT
);
1522 if ((m_mode
& wxLC_SMALL_ICON
) && (m_small_image_list
))
1524 m_small_image_list
->Draw( index
, *dc
, x
, y
, wxIMAGELIST_DRAW_TRANSPARENT
);
1526 if ((m_mode
& wxLC_REPORT
) && (m_small_image_list
))
1528 m_small_image_list
->Draw( index
, *dc
, x
, y
, wxIMAGELIST_DRAW_TRANSPARENT
);
1533 void wxListMainWindow::GetImageSize( int index
, int &width
, int &height
)
1535 if ((m_mode
& wxLC_ICON
) && (m_normal_image_list
))
1537 m_normal_image_list
->GetSize( index
, width
, height
);
1540 if ((m_mode
& wxLC_SMALL_ICON
) && (m_small_image_list
))
1542 m_small_image_list
->GetSize( index
, width
, height
);
1545 if ((m_mode
& wxLC_REPORT
) && (m_small_image_list
))
1547 m_small_image_list
->GetSize( index
, width
, height
);
1554 int wxListMainWindow::GetTextLength( wxString
&s
)
1556 wxPaintDC
dc( this );
1559 dc
.GetTextExtent( s
, &lw
, &lh
);
1563 int wxListMainWindow::GetIndexOfLine( const wxListLineData
*line
)
1566 wxNode
*node
= m_lines
.First();
1569 if (line
== (wxListLineData
*)node
->Data()) return i
;
1571 node
= node
->Next();
1576 void wxListMainWindow::SetImageList( wxImageList
*imageList
, int which
)
1579 if (which
== wxIMAGE_LIST_NORMAL
) m_normal_image_list
= imageList
;
1580 if (which
== wxIMAGE_LIST_SMALL
) m_small_image_list
= imageList
;
1583 void wxListMainWindow::SetItemSpacing( int spacing
, bool isSmall
)
1588 m_small_spacing
= spacing
;
1592 m_normal_spacing
= spacing
;
1596 int wxListMainWindow::GetItemSpacing( bool isSmall
)
1598 if (isSmall
) return m_small_spacing
; else return m_normal_spacing
;
1601 void wxListMainWindow::SetColumn( int col
, wxListItem
&item
)
1604 wxNode
*node
= m_columns
.Nth( col
);
1607 if (item
.m_width
== wxLIST_AUTOSIZE_USEHEADER
) item
.m_width
= GetTextLength( item
.m_text
)+7;
1608 wxListHeaderData
*column
= (wxListHeaderData
*)node
->Data();
1609 column
->SetItem( item
);
1611 wxListCtrl
*lc
= (wxListCtrl
*) GetParent();
1612 if (lc
->m_headerWin
) lc
->m_headerWin
->Refresh();
1615 void wxListMainWindow::SetColumnWidth( int col
, int width
)
1617 if (!(m_mode
& wxLC_REPORT
)) return;
1621 wxNode
*node
= m_columns
.Nth( col
);
1624 wxListHeaderData
*column
= (wxListHeaderData
*)node
->Data();
1625 column
->SetWidth( width
);
1628 node
= m_lines
.First();
1631 wxListLineData
*line
= (wxListLineData
*)node
->Data();
1632 wxNode
*n
= line
->m_items
.Nth( col
);
1635 wxListItemData
*item
= (wxListItemData
*)n
->Data();
1636 item
->SetSize( width
, -1 );
1638 node
= node
->Next();
1641 wxListCtrl
*lc
= (wxListCtrl
*) GetParent();
1642 if (lc
->m_headerWin
) lc
->m_headerWin
->Refresh();
1645 void wxListMainWindow::GetColumn( int col
, wxListItem
&item
)
1647 wxNode
*node
= m_columns
.Nth( col
);
1650 wxListHeaderData
*column
= (wxListHeaderData
*)node
->Data();
1651 column
->GetItem( item
);
1663 int wxListMainWindow::GetColumnWidth( int col
)
1665 wxNode
*node
= m_columns
.Nth( col
);
1668 wxListHeaderData
*column
= (wxListHeaderData
*)node
->Data();
1669 return column
->GetWidth();
1675 int wxListMainWindow::GetColumnCount( void )
1677 return m_columns
.Number();
1680 int wxListMainWindow::GetCountPerPage( void )
1682 return m_visibleLines
;
1685 void wxListMainWindow::SetItem( wxListItem
&item
)
1688 wxNode
*node
= m_lines
.Nth( item
.m_itemId
);
1691 wxListLineData
*line
= (wxListLineData
*)node
->Data();
1692 if (m_mode
& wxLC_REPORT
) item
.m_width
= GetColumnWidth( item
.m_col
)-3;
1693 line
->SetItem( item
.m_col
, item
);
1697 void wxListMainWindow::SetItemState( long item
, long state
, long stateMask
)
1699 // m_dirty = TRUE; no recalcs needed
1701 wxListLineData
*oldCurrent
= m_current
;
1703 if (stateMask
& wxLIST_STATE_FOCUSED
)
1705 wxNode
*node
= m_lines
.Nth( item
);
1708 wxListLineData
*line
= (wxListLineData
*)node
->Data();
1709 UnfocusLine( m_current
);
1711 FocusLine( m_current
);
1712 RefreshLine( m_current
);
1713 RefreshLine( oldCurrent
);
1717 if (stateMask
& wxLIST_STATE_SELECTED
)
1719 bool on
= state
& wxLIST_STATE_SELECTED
;
1720 if (!on
&& (m_mode
& wxLC_SINGLE_SEL
)) return;
1722 wxNode
*node
= m_lines
.Nth( item
);
1725 wxListLineData
*line
= (wxListLineData
*)node
->Data();
1726 if (m_mode
& wxLC_SINGLE_SEL
)
1728 UnfocusLine( m_current
);
1730 FocusLine( m_current
);
1731 oldCurrent
->Hilight( FALSE
);
1732 RefreshLine( m_current
);
1733 RefreshLine( oldCurrent
);
1735 bool on
= state
& wxLIST_STATE_SELECTED
;
1736 line
->Hilight( on
);
1737 RefreshLine( line
);
1742 int wxListMainWindow::GetItemState( long item
, long stateMask
)
1744 int ret
= wxLIST_STATE_DONTCARE
;
1745 if (stateMask
& wxLIST_STATE_FOCUSED
)
1747 wxNode
*node
= m_lines
.Nth( item
);
1750 wxListLineData
*line
= (wxListLineData
*)node
->Data();
1751 if (line
== m_current
) ret
|= wxLIST_STATE_FOCUSED
;
1754 if (stateMask
& wxLIST_STATE_SELECTED
)
1756 wxNode
*node
= m_lines
.Nth( item
);
1759 wxListLineData
*line
= (wxListLineData
*)node
->Data();
1760 if (line
->IsHilighted()) ret
|= wxLIST_STATE_FOCUSED
;
1766 void wxListMainWindow::GetItem( wxListItem
&item
)
1768 wxNode
*node
= m_lines
.Nth( item
.m_itemId
);
1771 wxListLineData
*line
= (wxListLineData
*)node
->Data();
1772 line
->GetItem( item
.m_col
, item
);
1783 int wxListMainWindow::GetItemCount( void )
1785 return m_lines
.Number();
1788 void wxListMainWindow::GetItemRect( long index
, wxRectangle
&rect
)
1790 wxNode
*node
= m_lines
.Nth( index
);
1793 wxListLineData
*line
= (wxListLineData
*)node
->Data();
1794 line
->GetRect( rect
);
1805 bool wxListMainWindow::GetItemPosition(long item
, wxPoint
& pos
)
1807 wxNode
*node
= m_lines
.Nth( item
);
1811 wxListLineData
*line
= (wxListLineData
*)node
->Data();
1812 line
->GetRect( rect
);
1824 int wxListMainWindow::GetSelectedItemCount( void )
1827 wxNode
*node
= m_lines
.First();
1830 wxListLineData
*line
= (wxListLineData
*)node
->Data();
1831 if (line
->IsHilighted()) ret
++;
1832 node
= node
->Next();
1837 void wxListMainWindow::SetMode( long mode
)
1844 if (m_mode
& wxLC_REPORT
)
1856 long wxListMainWindow::GetMode( void ) const
1861 void wxListMainWindow::CalculatePositions( void )
1863 if (!m_lines
.First()) return;
1865 wxPaintDC
dc( this );
1866 dc
.SetFont( *GetFont() );
1868 int iconSpacing
= 0;
1869 if (m_mode
& wxLC_ICON
) iconSpacing
= m_normal_spacing
;
1870 if (m_mode
& wxLC_SMALL_ICON
) iconSpacing
= m_small_spacing
;
1872 // we take the first line (which also can be an icon or
1873 // an a text item in wxLC_ICON and wxLC_LIST modes) to
1874 // measure the size of the line
1878 int lineSpacing
= 0;
1880 wxListLineData
*line
= (wxListLineData
*)m_lines
.First()->Data();
1881 line
->CalculateSize( &dc
, iconSpacing
);
1883 line
->GetSize( dummy
, lineSpacing
);
1886 int clientWidth
= 0;
1887 int clientHeight
= 0;
1889 if (m_mode
& wxLC_REPORT
)
1893 int entireHeight
= m_lines
.Number() * lineSpacing
+ 10;
1894 int scroll_pos
= GetScrollPos( wxVERTICAL
);
1895 SetScrollbars( m_xScroll
, m_yScroll
, 0, (entireHeight
+10) / m_yScroll
, 0, scroll_pos
, TRUE
);
1896 GetClientSize( &clientWidth
, &clientHeight
);
1898 wxNode
* node
= m_lines
.First();
1901 wxListLineData
*line
= (wxListLineData
*)node
->Data();
1902 line
->CalculateSize( &dc
, iconSpacing
);
1903 line
->SetPosition( &dc
, x
, y
, clientWidth
);
1905 for (int i
= 0; i
< GetColumnCount(); i
++)
1907 line
->SetColumnPosition( i
, col_x
);
1908 col_x
+= GetColumnWidth( i
);
1911 node
= node
->Next();
1916 // at first we try without any scrollbar. if the items don't
1917 // fit into the window, we recalculate after subtracting an
1918 // approximated 15 pt for the horizontal scrollbar
1920 GetSize( &clientWidth
, &clientHeight
);
1922 int entireWidth
= 0;
1924 for (int tries
= 0; tries
< 2; tries
++)
1930 wxNode
*node
= m_lines
.First();
1933 wxListLineData
*line
= (wxListLineData
*)node
->Data();
1934 line
->CalculateSize( &dc
, iconSpacing
);
1935 line
->SetPosition( &dc
, x
, y
, clientWidth
);
1936 line
->GetSize( lineWidth
, lineHeight
);
1937 if (lineWidth
> maxWidth
) maxWidth
= lineWidth
;
1939 if (y
+lineSpacing
-8 > clientHeight
-6)
1943 entireWidth
+= maxWidth
+13;
1946 node
= node
->Next();
1947 if (!node
) entireWidth
+= maxWidth
;
1948 if ((tries
== 0) && (entireWidth
> clientWidth
))
1950 clientHeight
-= 15; // scrollbar height
1953 if (!node
) tries
= 1; // everything fits, no second try required
1956 int scroll_pos
= GetScrollPos( wxHORIZONTAL
);
1957 SetScrollbars( m_xScroll
, m_yScroll
, (entireWidth
+15) / m_xScroll
, 0, scroll_pos
, 0, TRUE
);
1959 m_visibleLines
= (clientHeight
-4) / (lineSpacing
);
1962 void wxListMainWindow::RealizeChanges( void )
1966 wxNode
*node
= m_lines
.First();
1967 if (node
) m_current
= (wxListLineData
*)node
->Data();
1971 FocusLine( m_current
);
1972 if (m_mode
& wxLC_SINGLE_SEL
) m_current
->Hilight( TRUE
);
1976 long wxListMainWindow::GetNextItem( long item
, int WXUNUSED(geometry
), int state
)
1979 if (item
> 0) ret
= item
;
1980 wxNode
*node
= m_lines
.Nth( ret
);
1983 wxListLineData
*line
= (wxListLineData
*)node
->Data();
1984 if ((state
& wxLIST_STATE_FOCUSED
) && (line
== m_current
)) return ret
;
1985 if ((state
& wxLIST_STATE_SELECTED
) && (line
->IsHilighted())) return ret
;
1986 if (!state
) return ret
;
1988 node
= node
->Next();
1993 void wxListMainWindow::DeleteItem( long index
)
1996 wxNode
*node
= m_lines
.Nth( index
);
1999 wxListLineData
*line
= (wxListLineData
*)node
->Data();
2000 if (m_current
== line
) m_current
= (wxListLineData
*) NULL
;
2002 m_lines
.DeleteNode( node
);
2006 void wxListMainWindow::DeleteColumn( int col
)
2008 wxCHECK_RET( col
< (int)m_columns
.GetCount(),
2009 "attempting to delete inexistent column in wxListView" );
2012 wxNode
*node
= m_columns
.Nth( col
);
2013 if (node
) m_columns
.DeleteNode( node
);
2016 void wxListMainWindow::DeleteAllItems( void )
2019 m_current
= (wxListLineData
*) NULL
;
2020 wxNode
*node
= m_lines
.First();
2023 wxListLineData
*line
= (wxListLineData
*)node
->Data();
2025 node
= node
->Next();
2030 void wxListMainWindow::DeleteEverything( void )
2033 m_current
= (wxListLineData
*) NULL
;
2034 wxNode
*node
= m_lines
.First();
2037 wxListLineData
*line
= (wxListLineData
*)node
->Data();
2039 node
= node
->Next();
2042 m_current
= (wxListLineData
*) NULL
;
2046 void wxListMainWindow::EnsureVisible( long index
)
2048 wxListLineData
*oldCurrent
= m_current
;
2049 m_current
= (wxListLineData
*) NULL
;
2051 wxNode
*node
= m_lines
.Nth( i
);
2052 if (node
) m_current
= (wxListLineData
*)node
->Data();
2053 if (m_current
) MoveToFocus();
2054 m_current
= oldCurrent
;
2057 long wxListMainWindow::FindItem(long start
, const wxString
& str
, bool WXUNUSED(partial
) )
2061 if (pos
< 0) pos
= 0;
2062 wxNode
*node
= m_lines
.Nth( pos
);
2065 wxListLineData
*line
= (wxListLineData
*)node
->Data();
2067 line
->GetText( 0, s
);
2068 if (s
== tmp
) return pos
;
2069 node
= node
->Next();
2075 long wxListMainWindow::FindItem(long start
, long data
)
2078 if (pos
< 0) pos
= 0;
2079 wxNode
*node
= m_lines
.Nth( pos
);
2082 wxListLineData
*line
= (wxListLineData
*)node
->Data();
2084 line
->GetItem( 0, item
);
2085 if (item
.m_data
== data
) return pos
;
2086 node
= node
->Next();
2092 long wxListMainWindow::HitTest( int x
, int y
, int &flags
)
2094 wxNode
*node
= m_lines
.First();
2098 wxListLineData
*line
= (wxListLineData
*)node
->Data();
2099 long ret
= line
->IsHit( x
, y
);
2105 node
= node
->Next();
2111 void wxListMainWindow::InsertItem( wxListItem
&item
)
2115 if (m_mode
& wxLC_REPORT
) mode
= wxLC_REPORT
;
2116 else if (m_mode
& wxLC_LIST
) mode
= wxLC_LIST
;
2117 else if (m_mode
& wxLC_ICON
) mode
= wxLC_ICON
;
2118 else if (m_mode
& wxLC_SMALL_ICON
) mode
= wxLC_ICON
; // no typo
2119 wxListLineData
*line
= new wxListLineData( this, mode
, m_hilightBrush
);
2120 if (m_mode
& wxLC_REPORT
)
2122 line
->InitItems( GetColumnCount() );
2123 item
.m_width
= GetColumnWidth( 0 )-3;
2126 line
->InitItems( 1 );
2127 line
->SetItem( 0, item
);
2128 if ((item
.m_itemId
>= 0) && (item
.m_itemId
< (int)m_lines
.GetCount()))
2130 wxNode
*node
= m_lines
.Nth( item
.m_itemId
);
2131 if (node
) m_lines
.Insert( node
, line
);
2135 m_lines
.Append( line
);
2139 void wxListMainWindow::InsertColumn( long col
, wxListItem
&item
)
2142 if (m_mode
& wxLC_REPORT
)
2144 if (item
.m_width
== wxLIST_AUTOSIZE_USEHEADER
) item
.m_width
= GetTextLength( item
.m_text
);
2145 wxListHeaderData
*column
= new wxListHeaderData( item
);
2146 if ((col
>= 0) && (col
< (int)m_columns
.GetCount()))
2148 wxNode
*node
= m_columns
.Nth( col
);
2150 m_columns
.Insert( node
, column
);
2154 m_columns
.Append( column
);
2159 wxListCtrlCompare list_ctrl_compare_func_2
;
2160 long list_ctrl_compare_data
;
2162 int list_ctrl_compare_func_1( const void *arg1
, const void *arg2
)
2164 wxListLineData
*line1
= *((wxListLineData
**)arg1
);
2165 wxListLineData
*line2
= *((wxListLineData
**)arg2
);
2167 line1
->GetItem( 0, item
);
2168 long data1
= item
.m_data
;
2169 line2
->GetItem( 0, item
);
2170 long data2
= item
.m_data
;
2171 return list_ctrl_compare_func_2( data1
, data2
, list_ctrl_compare_data
);
2174 void wxListMainWindow::SortItems( wxListCtrlCompare fn
, long data
)
2176 list_ctrl_compare_func_2
= fn
;
2177 list_ctrl_compare_data
= data
;
2178 m_lines
.Sort( list_ctrl_compare_func_1
);
2181 bool wxListMainWindow::OnListNotify( wxListEvent
&event
)
2183 if (GetParent()) GetParent()->GetEventHandler()->ProcessEvent( event
);
2187 // -------------------------------------------------------------------------------------
2189 // -------------------------------------------------------------------------------------
2191 IMPLEMENT_DYNAMIC_CLASS(wxListItem
, wxObject
)
2193 wxListItem::wxListItem(void)
2202 m_format
= wxLIST_FORMAT_CENTRE
;
2207 // -------------------------------------------------------------------------------------
2209 // -------------------------------------------------------------------------------------
2211 IMPLEMENT_DYNAMIC_CLASS(wxListEvent
, wxCommandEvent
)
2213 wxListEvent::wxListEvent( wxEventType commandType
, int id
):
2214 wxCommandEvent( commandType
, id
)
2219 m_cancelled
= FALSE
;
2222 // -------------------------------------------------------------------------------------
2224 // -------------------------------------------------------------------------------------
2226 IMPLEMENT_DYNAMIC_CLASS(wxListCtrl
, wxControl
)
2228 BEGIN_EVENT_TABLE(wxListCtrl
,wxControl
)
2229 EVT_SIZE (wxListCtrl::OnSize
)
2230 EVT_IDLE (wxListCtrl::OnIdle
)
2233 wxListCtrl::wxListCtrl(void)
2235 m_imageListNormal
= (wxImageList
*) NULL
;
2236 m_imageListSmall
= (wxImageList
*) NULL
;
2237 m_imageListState
= (wxImageList
*) NULL
;
2238 m_mainWin
= (wxListMainWindow
*) NULL
;
2239 m_headerWin
= (wxListHeaderWindow
*) NULL
;
2242 wxListCtrl::~wxListCtrl(void)
2246 bool wxListCtrl::Create( wxWindow
*parent
, wxWindowID id
,
2247 const wxPoint
&pos
, const wxSize
&size
,
2248 long style
, const wxValidator
&validator
,
2249 const wxString
&name
)
2251 m_imageListNormal
= (wxImageList
*) NULL
;
2252 m_imageListSmall
= (wxImageList
*) NULL
;
2253 m_imageListState
= (wxImageList
*) NULL
;
2254 m_mainWin
= (wxListMainWindow
*) NULL
;
2255 m_headerWin
= (wxListHeaderWindow
*) NULL
;
2259 if ((s
& wxLC_REPORT
== 0) &&
2260 (s
& wxLC_LIST
== 0) &&
2261 (s
& wxLC_ICON
== 0))
2264 bool ret
= wxControl::Create( parent
, id
, pos
, size
, s
, name
);
2266 SetValidator( validator
);
2268 if (s
& wxSUNKEN_BORDER
) s
-= wxSUNKEN_BORDER
;
2270 m_mainWin
= new wxListMainWindow( this, -1, wxPoint(0,0), size
, s
);
2272 if (GetWindowStyleFlag() & wxLC_REPORT
)
2273 m_headerWin
= new wxListHeaderWindow( this, -1, m_mainWin
, wxPoint(0,0), wxSize(size
.x
,23) );
2275 m_headerWin
= (wxListHeaderWindow
*) NULL
;
2280 void wxListCtrl::OnSize( wxSizeEvent
&WXUNUSED(event
) )
2282 // handled in OnIdle
2284 if (m_mainWin
) m_mainWin
->m_dirty
= TRUE
;
2287 void wxListCtrl::SetSingleStyle( long style
, bool add
)
2289 long flag
= GetWindowStyleFlag();
2293 if (style
& wxLC_MASK_TYPE
) flag
= flag
& ~wxLC_MASK_TYPE
;
2294 if (style
& wxLC_MASK_ALIGN
) flag
= flag
& ~wxLC_MASK_ALIGN
;
2295 if (style
& wxLC_MASK_SORT
) flag
= flag
& ~wxLC_MASK_SORT
;
2304 if (flag
& style
) flag
-= style
;
2307 SetWindowStyleFlag( flag
);
2310 void wxListCtrl::SetWindowStyleFlag( long flag
)
2312 m_mainWin
->DeleteEverything();
2316 GetClientSize( &width
, &height
);
2318 m_mainWin
->SetMode( flag
);
2320 if (flag
& wxLC_REPORT
)
2322 if (!(GetWindowStyleFlag() & wxLC_REPORT
))
2324 // m_mainWin->SetSize( 0, 24, width, height-24 );
2327 m_headerWin
= new wxListHeaderWindow( this, -1, m_mainWin
, wxPoint(0,0), wxSize(width
,23) );
2331 // m_headerWin->SetSize( 0, 0, width, 23 );
2332 m_headerWin
->Show( TRUE
);
2338 if (GetWindowStyleFlag() & wxLC_REPORT
)
2340 // m_mainWin->SetSize( 0, 0, width, height );
2341 m_headerWin
->Show( FALSE
);
2345 wxWindow::SetWindowStyleFlag( flag
);
2348 bool wxListCtrl::GetColumn(int col
, wxListItem
&item
) const
2350 m_mainWin
->GetColumn( col
, item
);
2354 bool wxListCtrl::SetColumn( int col
, wxListItem
& item
)
2356 m_mainWin
->SetColumn( col
, item
);
2360 int wxListCtrl::GetColumnWidth( int col
) const
2362 return m_mainWin
->GetColumnWidth( col
);
2365 bool wxListCtrl::SetColumnWidth( int col
, int width
)
2367 m_mainWin
->SetColumnWidth( col
, width
);
2371 int wxListCtrl::GetCountPerPage(void) const
2373 return m_mainWin
->GetCountPerPage(); // different from Windows ?
2377 wxText& wxListCtrl::GetEditControl(void) const
2382 bool wxListCtrl::GetItem( wxListItem
&info
) const
2384 m_mainWin
->GetItem( info
);
2388 bool wxListCtrl::SetItem( wxListItem
&info
)
2390 m_mainWin
->SetItem( info
);
2394 long wxListCtrl::SetItem( long index
, int col
, const wxString
& label
, int imageId
)
2397 info
.m_text
= label
;
2398 info
.m_mask
= wxLIST_MASK_TEXT
;
2399 info
.m_itemId
= index
;
2403 info
.m_image
= imageId
;
2404 info
.m_mask
|= wxLIST_MASK_IMAGE
;
2407 m_mainWin
->SetItem(info
);
2411 int wxListCtrl::GetItemState( long item
, long stateMask
) const
2413 return m_mainWin
->GetItemState( item
, stateMask
);
2416 bool wxListCtrl::SetItemState( long item
, long state
, long stateMask
)
2418 m_mainWin
->SetItemState( item
, state
, stateMask
);
2422 bool wxListCtrl::SetItemImage( long item
, int image
, int WXUNUSED(selImage
) )
2425 info
.m_image
= image
;
2426 info
.m_mask
= wxLIST_MASK_IMAGE
;
2427 info
.m_itemId
= item
;
2428 m_mainWin
->SetItem( info
);
2432 wxString
wxListCtrl::GetItemText( long item
) const
2435 info
.m_itemId
= item
;
2436 m_mainWin
->GetItem( info
);
2440 void wxListCtrl::SetItemText( long item
, const wxString
&str
)
2443 info
.m_mask
= wxLIST_MASK_TEXT
;
2444 info
.m_itemId
= item
;
2446 m_mainWin
->SetItem( info
);
2449 long wxListCtrl::GetItemData( long item
) const
2452 info
.m_itemId
= item
;
2453 m_mainWin
->GetItem( info
);
2457 bool wxListCtrl::SetItemData( long item
, long data
)
2460 info
.m_mask
= wxLIST_MASK_DATA
;
2461 info
.m_itemId
= item
;
2463 m_mainWin
->SetItem( info
);
2467 bool wxListCtrl::GetItemRect( long item
, wxRectangle
&rect
, int WXUNUSED(code
) ) const
2469 m_mainWin
->GetItemRect( item
, rect
);
2473 bool wxListCtrl::GetItemPosition( long item
, wxPoint
& pos
) const
2475 m_mainWin
->GetItemPosition( item
, pos
);
2479 bool wxListCtrl::SetItemPosition( long WXUNUSED(item
), const wxPoint
& WXUNUSED(pos
) )
2484 int wxListCtrl::GetItemCount(void) const
2486 return m_mainWin
->GetItemCount();
2489 void wxListCtrl::SetItemSpacing( int spacing
, bool isSmall
)
2491 m_mainWin
->SetItemSpacing( spacing
, isSmall
);
2494 int wxListCtrl::GetItemSpacing( bool isSmall
) const
2496 return m_mainWin
->GetItemSpacing( isSmall
);
2499 int wxListCtrl::GetSelectedItemCount(void) const
2501 return m_mainWin
->GetSelectedItemCount();
2505 wxColour wxListCtrl::GetTextColour(void) const
2509 void wxListCtrl::SetTextColour(const wxColour& WXUNUSED(col))
2514 long wxListCtrl::GetTopItem(void) const
2519 long wxListCtrl::GetNextItem( long item
, int geom
, int state
) const
2521 return m_mainWin
->GetNextItem( item
, geom
, state
);
2524 wxImageList
*wxListCtrl::GetImageList(int which
) const
2526 if (which
== wxIMAGE_LIST_NORMAL
)
2528 return m_imageListNormal
;
2530 else if (which
== wxIMAGE_LIST_SMALL
)
2532 return m_imageListSmall
;
2534 else if (which
== wxIMAGE_LIST_STATE
)
2536 return m_imageListState
;
2538 return (wxImageList
*) NULL
;
2541 void wxListCtrl::SetImageList( wxImageList
*imageList
, int which
)
2543 m_mainWin
->SetImageList( imageList
, which
);
2546 bool wxListCtrl::Arrange( int WXUNUSED(flag
) )
2551 bool wxListCtrl::DeleteItem( long item
)
2553 m_mainWin
->DeleteItem( item
);
2557 bool wxListCtrl::DeleteAllItems(void)
2559 m_mainWin
->DeleteAllItems();
2563 void wxListCtrl::DeleteAllColumns()
2565 for ( size_t n
= 0; n
< m_mainWin
->m_columns
.GetCount(); n
++ )
2569 bool wxListCtrl::DeleteColumn( int col
)
2571 m_mainWin
->DeleteColumn( col
);
2576 wxText& wxListCtrl::Edit( long WXUNUSED(item ) )
2581 bool wxListCtrl::EnsureVisible( long item
)
2583 m_mainWin
->EnsureVisible( item
);
2587 long wxListCtrl::FindItem( long start
, const wxString
& str
, bool partial
)
2589 return m_mainWin
->FindItem( start
, str
, partial
);
2592 long wxListCtrl::FindItem( long start
, long data
)
2594 return m_mainWin
->FindItem( start
, data
);
2597 long wxListCtrl::FindItem( long WXUNUSED(start
), const wxPoint
& WXUNUSED(pt
),
2598 int WXUNUSED(direction
))
2603 long wxListCtrl::HitTest( const wxPoint
&point
, int &flags
)
2605 return m_mainWin
->HitTest( (int)point
.x
, (int)point
.y
, flags
);
2608 long wxListCtrl::InsertItem( wxListItem
& info
)
2610 m_mainWin
->InsertItem( info
);
2614 long wxListCtrl::InsertItem( long index
, const wxString
&label
)
2617 info
.m_text
= label
;
2618 info
.m_mask
= wxLIST_MASK_TEXT
;
2619 info
.m_itemId
= index
;
2620 return InsertItem( info
);
2623 long wxListCtrl::InsertItem( long index
, int imageIndex
)
2626 info
.m_mask
= wxLIST_MASK_IMAGE
;
2627 info
.m_image
= imageIndex
;
2628 info
.m_itemId
= index
;
2629 return InsertItem( info
);
2632 long wxListCtrl::InsertItem( long index
, const wxString
&label
, int imageIndex
)
2635 info
.m_text
= label
;
2636 info
.m_image
= imageIndex
;
2637 info
.m_mask
= wxLIST_MASK_TEXT
| wxLIST_MASK_IMAGE
;
2638 info
.m_itemId
= index
;
2639 return InsertItem( info
);
2642 long wxListCtrl::InsertColumn( long col
, wxListItem
&item
)
2644 m_mainWin
->InsertColumn( col
, item
);
2648 long wxListCtrl::InsertColumn( long col
, const wxString
&heading
,
2649 int format
, int width
)
2652 item
.m_mask
= wxLIST_MASK_TEXT
| wxLIST_MASK_FORMAT
;
2653 item
.m_text
= heading
;
2656 item
.m_mask
|= wxLIST_MASK_WIDTH
;
2657 item
.m_width
= width
;
2660 item
.m_format
= format
;
2662 return InsertColumn( col
, item
);
2665 bool wxListCtrl::ScrollList( int WXUNUSED(dx
), int WXUNUSED(dy
) )
2671 // fn is a function which takes 3 long arguments: item1, item2, data.
2672 // item1 is the long data associated with a first item (NOT the index).
2673 // item2 is the long data associated with a second item (NOT the index).
2674 // data is the same value as passed to SortItems.
2675 // The return value is a negative number if the first item should precede the second
2676 // item, a positive number of the second item should precede the first,
2677 // or zero if the two items are equivalent.
2678 // data is arbitrary data to be passed to the sort function.
2680 bool wxListCtrl::SortItems( wxListCtrlCompare fn
, long data
)
2682 m_mainWin
->SortItems( fn
, data
);
2686 void wxListCtrl::OnIdle( wxIdleEvent
&WXUNUSED(event
) )
2688 if (!m_mainWin
->m_dirty
) return;
2692 GetClientSize( &cw
, &ch
);
2699 if (GetWindowStyleFlag() & wxLC_REPORT
)
2701 m_headerWin
->GetPosition( &x
, &y
);
2702 m_headerWin
->GetSize( &w
, &h
);
2703 if ((x
!= 0) || (y
!= 0) || (w
!= cw
) || (h
!= 23))
2704 m_headerWin
->SetSize( 0, 0, cw
, 23 );
2706 m_mainWin
->GetPosition( &x
, &y
);
2707 m_mainWin
->GetSize( &w
, &h
);
2708 if ((x
!= 0) || (y
!= 24) || (w
!= cw
) || (h
!= ch
-24))
2709 m_mainWin
->SetSize( 0, 24, cw
, ch
-24 );
2713 m_mainWin
->GetPosition( &x
, &y
);
2714 m_mainWin
->GetSize( &w
, &h
);
2715 if ((x
!= 0) || (y
!= 24) || (w
!= cw
) || (h
!= ch
))
2716 m_mainWin
->SetSize( 0, 0, cw
, ch
);
2719 m_mainWin
->CalculatePositions();
2720 m_mainWin
->RealizeChanges();
2721 m_mainWin
->m_dirty
= FALSE
;
2722 m_mainWin
->Refresh();
2725 void wxListCtrl::SetBackgroundColour( const wxColour
&colour
)
2729 m_mainWin
->SetBackgroundColour( colour
);
2730 m_mainWin
->m_dirty
= TRUE
;
2733 m_headerWin
->SetBackgroundColour( colour
);
2736 void wxListCtrl::SetForegroundColour( const wxColour
&colour
)
2740 m_mainWin
->SetForegroundColour( colour
);
2741 m_mainWin
->m_dirty
= TRUE
;
2744 m_headerWin
->SetForegroundColour( colour
);
2747 void wxListCtrl::SetFont( const wxFont
&font
)
2751 m_mainWin
->SetFont( font
);
2752 m_mainWin
->m_dirty
= TRUE
;
2755 m_headerWin
->SetFont( font
);