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+5)/m_yScroll );
1335 if (GetScrollPos( wxVERTICAL ) != 0) SetScrollPos( wxVERTICAL, 0);
1336 int x_s = m_xScroll*GetScrollPos( wxHORIZONTAL );
1337 if ((x > x_s) && (x+w < x_s+w_p)) return;
1338 if (x-x_s < 5) SetScrollPos( wxHORIZONTAL, (x-5)/m_xScroll );
1339 if (x+w > x_s+w_p) SetScrollPos( wxHORIZONTAL, (x+w-w_p+5)/m_xScroll );
1344 void wxListMainWindow::OnArrowChar( wxListLineData
*newCurrent
, bool shiftDown
)
1346 if ((m_mode
& wxLC_SINGLE_SEL
) || (m_usedKeys
== FALSE
)) m_current
->Hilight( FALSE
);
1347 wxListLineData
*oldCurrent
= m_current
;
1348 m_current
= newCurrent
;
1350 if (shiftDown
|| (m_mode
& wxLC_SINGLE_SEL
)) m_current
->Hilight( TRUE
);
1351 RefreshLine( m_current
);
1352 RefreshLine( oldCurrent
);
1353 FocusLine( m_current
);
1354 UnfocusLine( oldCurrent
);
1357 void wxListMainWindow::OnChar( wxKeyEvent
&event
)
1360 if (event.KeyCode() == WXK_TAB)
1362 if (event.ShiftDown())
1369 if (!m_current
) return;
1370 switch (event
.KeyCode())
1374 wxNode
*node
= m_lines
.Member( m_current
)->Previous();
1375 if (node
) OnArrowChar( (wxListLineData
*)node
->Data(), event
.ShiftDown() );
1380 wxNode
*node
= m_lines
.Member( m_current
)->Next();
1381 if (node
) OnArrowChar( (wxListLineData
*)node
->Data(), event
.ShiftDown() );
1386 wxNode
*node
= m_lines
.Last();
1387 OnArrowChar( (wxListLineData
*)node
->Data(), event
.ShiftDown() );
1392 wxNode
*node
= m_lines
.First();
1393 OnArrowChar( (wxListLineData
*)node
->Data(), event
.ShiftDown() );
1399 if (m_mode
& wxLC_REPORT
) { steps
= m_visibleLines
-1; }
1403 wxNode
*node
= m_lines
.First();
1404 for (;;) { if (m_current
== (wxListLineData
*)node
->Data()) break; pos
++; node
= node
->Next(); }
1405 steps
= pos
% m_visibleLines
;
1407 wxNode
*node
= m_lines
.Member( m_current
);
1408 for (int i
= 0; i
< steps
; i
++) if (node
->Previous()) node
= node
->Previous();
1409 if (node
) OnArrowChar( (wxListLineData
*)node
->Data(), event
.ShiftDown() );
1415 if (m_mode
& wxLC_REPORT
) { steps
= m_visibleLines
-1; }
1418 int pos
= 0; wxNode
*node
= m_lines
.First();
1419 for (;;) { if (m_current
== (wxListLineData
*)node
->Data()) break; pos
++; node
= node
->Next(); }
1420 steps
= m_visibleLines
-(pos
% m_visibleLines
)-1;
1422 wxNode
*node
= m_lines
.Member( m_current
);
1423 for (int i
= 0; i
< steps
; i
++) if (node
->Next()) node
= node
->Next();
1424 if (node
) OnArrowChar( (wxListLineData
*)node
->Data(), event
.ShiftDown() );
1429 if (!(m_mode
& wxLC_REPORT
))
1431 wxNode
*node
= m_lines
.Member( m_current
);
1432 for (int i
= 0; i
<m_visibleLines
; i
++) if (node
->Previous()) node
= node
->Previous();
1433 if (node
) OnArrowChar( (wxListLineData
*)node
->Data(), event
.ShiftDown() );
1439 if (!(m_mode
& wxLC_REPORT
))
1441 wxNode
*node
= m_lines
.Member( m_current
);
1442 for (int i
= 0; i
<m_visibleLines
; i
++) if (node
->Next()) node
= node
->Next();
1443 if (node
) OnArrowChar( (wxListLineData
*)node
->Data(), event
.ShiftDown() );
1449 m_current
->ReverseHilight();
1450 RefreshLine( m_current
);
1455 if (!(m_mode
& wxLC_SINGLE_SEL
))
1457 wxListLineData
*oldCurrent
= m_current
;
1458 m_current
->ReverseHilight();
1459 wxNode
*node
= m_lines
.Member( m_current
)->Next();
1460 if (node
) m_current
= (wxListLineData
*)node
->Data();
1462 RefreshLine( oldCurrent
);
1463 RefreshLine( m_current
);
1464 UnfocusLine( oldCurrent
);
1465 FocusLine( m_current
);
1472 ActivateLine( m_current
);
1484 void wxListMainWindow::OnSetFocus( wxFocusEvent
&WXUNUSED(event
) )
1487 RefreshLine( m_current
);
1489 if (!GetParent()) return;
1491 wxFocusEvent
event( wxEVT_SET_FOCUS
, GetParent()->GetId() );
1492 event
.SetEventObject( GetParent() );
1493 GetParent()->GetEventHandler()->ProcessEvent( event
);
1496 void wxListMainWindow::OnKillFocus( wxFocusEvent
&WXUNUSED(event
) )
1499 RefreshLine( m_current
);
1502 void wxListMainWindow::OnSize( wxSizeEvent
&WXUNUSED(event
) )
1505 We don't even allow the wxScrolledWindow::AdjustScrollbars() call
1507 CalculatePositions();
1508 printf( "OnSize::Refresh.\n" );
1514 void wxListMainWindow::DrawImage( int index
, wxPaintDC
*dc
, int x
, int y
)
1516 if ((m_mode
& wxLC_ICON
) && (m_normal_image_list
))
1518 m_normal_image_list
->Draw( index
, *dc
, x
, y
, wxIMAGELIST_DRAW_TRANSPARENT
);
1521 if ((m_mode
& wxLC_SMALL_ICON
) && (m_small_image_list
))
1523 m_small_image_list
->Draw( index
, *dc
, x
, y
, wxIMAGELIST_DRAW_TRANSPARENT
);
1525 if ((m_mode
& wxLC_REPORT
) && (m_small_image_list
))
1527 m_small_image_list
->Draw( index
, *dc
, x
, y
, wxIMAGELIST_DRAW_TRANSPARENT
);
1532 void wxListMainWindow::GetImageSize( int index
, int &width
, int &height
)
1534 if ((m_mode
& wxLC_ICON
) && (m_normal_image_list
))
1536 m_normal_image_list
->GetSize( index
, width
, height
);
1539 if ((m_mode
& wxLC_SMALL_ICON
) && (m_small_image_list
))
1541 m_small_image_list
->GetSize( index
, width
, height
);
1544 if ((m_mode
& wxLC_REPORT
) && (m_small_image_list
))
1546 m_small_image_list
->GetSize( index
, width
, height
);
1553 int wxListMainWindow::GetTextLength( wxString
&s
)
1555 wxPaintDC
dc( this );
1558 dc
.GetTextExtent( s
, &lw
, &lh
);
1562 int wxListMainWindow::GetIndexOfLine( const wxListLineData
*line
)
1565 wxNode
*node
= m_lines
.First();
1568 if (line
== (wxListLineData
*)node
->Data()) return i
;
1570 node
= node
->Next();
1575 void wxListMainWindow::SetImageList( wxImageList
*imageList
, int which
)
1578 if (which
== wxIMAGE_LIST_NORMAL
) m_normal_image_list
= imageList
;
1579 if (which
== wxIMAGE_LIST_SMALL
) m_small_image_list
= imageList
;
1582 void wxListMainWindow::SetItemSpacing( int spacing
, bool isSmall
)
1587 m_small_spacing
= spacing
;
1591 m_normal_spacing
= spacing
;
1595 int wxListMainWindow::GetItemSpacing( bool isSmall
)
1597 if (isSmall
) return m_small_spacing
; else return m_normal_spacing
;
1600 void wxListMainWindow::SetColumn( int col
, wxListItem
&item
)
1603 wxNode
*node
= m_columns
.Nth( col
);
1606 if (item
.m_width
== wxLIST_AUTOSIZE_USEHEADER
) item
.m_width
= GetTextLength( item
.m_text
)+7;
1607 wxListHeaderData
*column
= (wxListHeaderData
*)node
->Data();
1608 column
->SetItem( item
);
1610 wxListCtrl
*lc
= (wxListCtrl
*) GetParent();
1611 if (lc
->m_headerWin
) lc
->m_headerWin
->Refresh();
1614 void wxListMainWindow::SetColumnWidth( int col
, int width
)
1616 if (!(m_mode
& wxLC_REPORT
)) return;
1620 wxNode
*node
= m_columns
.Nth( col
);
1623 wxListHeaderData
*column
= (wxListHeaderData
*)node
->Data();
1624 column
->SetWidth( width
);
1627 node
= m_lines
.First();
1630 wxListLineData
*line
= (wxListLineData
*)node
->Data();
1631 wxNode
*n
= line
->m_items
.Nth( col
);
1634 wxListItemData
*item
= (wxListItemData
*)n
->Data();
1635 item
->SetSize( width
, -1 );
1637 node
= node
->Next();
1640 wxListCtrl
*lc
= (wxListCtrl
*) GetParent();
1641 if (lc
->m_headerWin
) lc
->m_headerWin
->Refresh();
1644 void wxListMainWindow::GetColumn( int col
, wxListItem
&item
)
1646 wxNode
*node
= m_columns
.Nth( col
);
1649 wxListHeaderData
*column
= (wxListHeaderData
*)node
->Data();
1650 column
->GetItem( item
);
1662 int wxListMainWindow::GetColumnWidth( int col
)
1664 wxNode
*node
= m_columns
.Nth( col
);
1667 wxListHeaderData
*column
= (wxListHeaderData
*)node
->Data();
1668 return column
->GetWidth();
1674 int wxListMainWindow::GetColumnCount( void )
1676 return m_columns
.Number();
1679 int wxListMainWindow::GetCountPerPage( void )
1681 return m_visibleLines
;
1684 void wxListMainWindow::SetItem( wxListItem
&item
)
1687 wxNode
*node
= m_lines
.Nth( item
.m_itemId
);
1690 wxListLineData
*line
= (wxListLineData
*)node
->Data();
1691 if (m_mode
& wxLC_REPORT
) item
.m_width
= GetColumnWidth( item
.m_col
)-3;
1692 line
->SetItem( item
.m_col
, item
);
1696 void wxListMainWindow::SetItemState( long item
, long state
, long stateMask
)
1698 // m_dirty = TRUE; no recalcs needed
1700 wxListLineData
*oldCurrent
= m_current
;
1702 if (stateMask
& wxLIST_STATE_FOCUSED
)
1704 wxNode
*node
= m_lines
.Nth( item
);
1707 wxListLineData
*line
= (wxListLineData
*)node
->Data();
1708 UnfocusLine( m_current
);
1710 FocusLine( m_current
);
1711 RefreshLine( m_current
);
1712 RefreshLine( oldCurrent
);
1716 if (stateMask
& wxLIST_STATE_SELECTED
)
1718 bool on
= state
& wxLIST_STATE_SELECTED
;
1719 if (!on
&& (m_mode
& wxLC_SINGLE_SEL
)) return;
1721 wxNode
*node
= m_lines
.Nth( item
);
1724 wxListLineData
*line
= (wxListLineData
*)node
->Data();
1725 if (m_mode
& wxLC_SINGLE_SEL
)
1727 UnfocusLine( m_current
);
1729 FocusLine( m_current
);
1730 oldCurrent
->Hilight( FALSE
);
1731 RefreshLine( m_current
);
1732 RefreshLine( oldCurrent
);
1734 bool on
= state
& wxLIST_STATE_SELECTED
;
1735 line
->Hilight( on
);
1736 RefreshLine( line
);
1741 int wxListMainWindow::GetItemState( long item
, long stateMask
)
1743 int ret
= wxLIST_STATE_DONTCARE
;
1744 if (stateMask
& wxLIST_STATE_FOCUSED
)
1746 wxNode
*node
= m_lines
.Nth( item
);
1749 wxListLineData
*line
= (wxListLineData
*)node
->Data();
1750 if (line
== m_current
) ret
|= wxLIST_STATE_FOCUSED
;
1753 if (stateMask
& wxLIST_STATE_SELECTED
)
1755 wxNode
*node
= m_lines
.Nth( item
);
1758 wxListLineData
*line
= (wxListLineData
*)node
->Data();
1759 if (line
->IsHilighted()) ret
|= wxLIST_STATE_FOCUSED
;
1765 void wxListMainWindow::GetItem( wxListItem
&item
)
1767 wxNode
*node
= m_lines
.Nth( item
.m_itemId
);
1770 wxListLineData
*line
= (wxListLineData
*)node
->Data();
1771 line
->GetItem( item
.m_col
, item
);
1782 int wxListMainWindow::GetItemCount( void )
1784 return m_lines
.Number();
1787 void wxListMainWindow::GetItemRect( long index
, wxRectangle
&rect
)
1789 wxNode
*node
= m_lines
.Nth( index
);
1792 wxListLineData
*line
= (wxListLineData
*)node
->Data();
1793 line
->GetRect( rect
);
1804 bool wxListMainWindow::GetItemPosition(long item
, wxPoint
& pos
)
1806 wxNode
*node
= m_lines
.Nth( item
);
1810 wxListLineData
*line
= (wxListLineData
*)node
->Data();
1811 line
->GetRect( rect
);
1823 int wxListMainWindow::GetSelectedItemCount( void )
1826 wxNode
*node
= m_lines
.First();
1829 wxListLineData
*line
= (wxListLineData
*)node
->Data();
1830 if (line
->IsHilighted()) ret
++;
1831 node
= node
->Next();
1836 void wxListMainWindow::SetMode( long mode
)
1843 if (m_mode
& wxLC_REPORT
)
1855 long wxListMainWindow::GetMode( void ) const
1860 void wxListMainWindow::CalculatePositions( void )
1862 wxPaintDC
dc( this );
1863 dc
.SetFont( *GetFont() );
1865 int iconSpacing
= 0;
1866 if (m_mode
& wxLC_ICON
) iconSpacing
= m_normal_spacing
;
1867 if (m_mode
& wxLC_SMALL_ICON
) iconSpacing
= m_small_spacing
;
1868 wxNode
*node
= m_lines
.First();
1871 wxListLineData
*line
= (wxListLineData
*)node
->Data();
1872 line
->CalculateSize( &dc
, iconSpacing
);
1873 node
= node
->Next();
1878 int lineSpacing
= 0;
1880 node
= m_lines
.First();
1883 wxListLineData
*line
= (wxListLineData
*)node
->Data();
1885 line
->GetSize( dummy
, lineSpacing
);
1891 lineSpacing
= 4 + (int)dc
.GetCharHeight();
1894 int clientWidth
= 0;
1895 int clientHeight
= 0;
1897 if (m_mode
& wxLC_REPORT
)
1901 int entireHeight
= m_lines
.Number() * lineSpacing
+ 10;
1902 SetScrollbars( m_xScroll
, m_yScroll
, 0, (entireHeight
+10) / m_yScroll
, 0, 0, TRUE
);
1903 GetClientSize( &clientWidth
, &clientHeight
);
1905 node
= m_lines
.First();
1908 wxListLineData
*line
= (wxListLineData
*)node
->Data();
1909 line
->SetPosition( &dc
, x
, y
, clientWidth
);
1911 for (int i
= 0; i
< GetColumnCount(); i
++)
1913 line
->SetColumnPosition( i
, col_x
);
1914 col_x
+= GetColumnWidth( i
);
1917 node
= node
->Next();
1922 // At first, we try without any scrollbar
1923 GetSize( &clientWidth
, &clientHeight
);
1925 int entireWidth
= 0;
1927 for (int tries
= 0; tries
< 2; tries
++)
1933 node
= m_lines
.First();
1936 wxListLineData
*line
= (wxListLineData
*)node
->Data();
1937 line
->SetPosition( &dc
, x
, y
, clientWidth
);
1938 line
->GetSize( lineWidth
, lineHeight
);
1939 if (lineWidth
> maxWidth
) maxWidth
= lineWidth
;
1941 if (y
+lineHeight
> clientHeight
-4)
1945 entireWidth
+= maxWidth
+13;
1948 node
= node
->Next();
1949 if (!node
) entireWidth
+= maxWidth
;
1950 if ((tries
== 0) && (entireWidth
> clientWidth
))
1952 clientHeight
-= 14; // scrollbar height
1955 if (!node
) tries
= 1;
1958 SetScrollbars( m_xScroll
, m_yScroll
, (entireWidth
+15) / m_xScroll
, 0, 0, 0, TRUE
);
1960 m_visibleLines
= (clientHeight
-4) / (lineSpacing
);
1963 void wxListMainWindow::RealizeChanges( void )
1967 wxNode
*node
= m_lines
.First();
1968 if (node
) m_current
= (wxListLineData
*)node
->Data();
1972 FocusLine( m_current
);
1973 if (m_mode
& wxLC_SINGLE_SEL
) m_current
->Hilight( TRUE
);
1977 long wxListMainWindow::GetNextItem( long item
, int WXUNUSED(geometry
), int state
)
1980 if (item
> 0) ret
= item
;
1981 wxNode
*node
= m_lines
.Nth( ret
);
1984 wxListLineData
*line
= (wxListLineData
*)node
->Data();
1985 if ((state
& wxLIST_STATE_FOCUSED
) && (line
== m_current
)) return ret
;
1986 if ((state
& wxLIST_STATE_SELECTED
) && (line
->IsHilighted())) return ret
;
1987 if (!state
) return ret
;
1989 node
= node
->Next();
1994 void wxListMainWindow::DeleteItem( long index
)
1997 wxNode
*node
= m_lines
.Nth( index
);
2000 wxListLineData
*line
= (wxListLineData
*)node
->Data();
2001 if (m_current
== line
) m_current
= (wxListLineData
*) NULL
;
2003 m_lines
.DeleteNode( node
);
2007 void wxListMainWindow::DeleteColumn( int col
)
2009 wxCHECK_RET( col
< (int)m_columns
.GetCount(),
2010 "attempting to delete inexistent column in wxListView" );
2013 wxNode
*node
= m_columns
.Nth( col
);
2014 if (node
) m_columns
.DeleteNode( node
);
2017 void wxListMainWindow::DeleteAllItems( void )
2020 m_current
= (wxListLineData
*) NULL
;
2021 wxNode
*node
= m_lines
.First();
2024 wxListLineData
*line
= (wxListLineData
*)node
->Data();
2026 node
= node
->Next();
2031 void wxListMainWindow::DeleteEverything( void )
2034 m_current
= (wxListLineData
*) NULL
;
2035 wxNode
*node
= m_lines
.First();
2038 wxListLineData
*line
= (wxListLineData
*)node
->Data();
2040 node
= node
->Next();
2043 m_current
= (wxListLineData
*) NULL
;
2047 void wxListMainWindow::EnsureVisible( long index
)
2049 wxListLineData
*oldCurrent
= m_current
;
2050 m_current
= (wxListLineData
*) NULL
;
2052 wxNode
*node
= m_lines
.Nth( i
);
2053 if (node
) m_current
= (wxListLineData
*)node
->Data();
2054 if (m_current
) MoveToFocus();
2055 m_current
= oldCurrent
;
2058 long wxListMainWindow::FindItem(long start
, const wxString
& str
, bool WXUNUSED(partial
) )
2062 if (pos
< 0) pos
= 0;
2063 wxNode
*node
= m_lines
.Nth( pos
);
2066 wxListLineData
*line
= (wxListLineData
*)node
->Data();
2068 line
->GetText( 0, s
);
2069 if (s
== tmp
) return pos
;
2070 node
= node
->Next();
2076 long wxListMainWindow::FindItem(long start
, long data
)
2079 if (pos
< 0) pos
= 0;
2080 wxNode
*node
= m_lines
.Nth( pos
);
2083 wxListLineData
*line
= (wxListLineData
*)node
->Data();
2085 line
->GetItem( 0, item
);
2086 if (item
.m_data
== data
) return pos
;
2087 node
= node
->Next();
2093 long wxListMainWindow::HitTest( int x
, int y
, int &flags
)
2095 wxNode
*node
= m_lines
.First();
2099 wxListLineData
*line
= (wxListLineData
*)node
->Data();
2100 long ret
= line
->IsHit( x
, y
);
2106 node
= node
->Next();
2112 void wxListMainWindow::InsertItem( wxListItem
&item
)
2116 if (m_mode
& wxLC_REPORT
) mode
= wxLC_REPORT
;
2117 else if (m_mode
& wxLC_LIST
) mode
= wxLC_LIST
;
2118 else if (m_mode
& wxLC_ICON
) mode
= wxLC_ICON
;
2119 else if (m_mode
& wxLC_SMALL_ICON
) mode
= wxLC_ICON
; // no typo
2120 wxListLineData
*line
= new wxListLineData( this, mode
, m_hilightBrush
);
2121 if (m_mode
& wxLC_REPORT
)
2123 line
->InitItems( GetColumnCount() );
2124 item
.m_width
= GetColumnWidth( 0 )-3;
2127 line
->InitItems( 1 );
2128 line
->SetItem( 0, item
);
2129 if ((item
.m_itemId
>= 0) && (item
.m_itemId
< (int)m_lines
.GetCount()))
2131 wxNode
*node
= m_lines
.Nth( item
.m_itemId
);
2132 if (node
) m_lines
.Insert( node
, line
);
2136 m_lines
.Append( line
);
2140 void wxListMainWindow::InsertColumn( long col
, wxListItem
&item
)
2143 if (m_mode
& wxLC_REPORT
)
2145 if (item
.m_width
== wxLIST_AUTOSIZE_USEHEADER
) item
.m_width
= GetTextLength( item
.m_text
);
2146 wxListHeaderData
*column
= new wxListHeaderData( item
);
2147 if ((col
>= 0) && (col
< (int)m_columns
.GetCount()))
2149 wxNode
*node
= m_columns
.Nth( col
);
2151 m_columns
.Insert( node
, column
);
2155 m_columns
.Append( column
);
2160 wxListCtrlCompare list_ctrl_compare_func_2
;
2161 long list_ctrl_compare_data
;
2163 int list_ctrl_compare_func_1( const void *arg1
, const void *arg2
)
2165 wxListLineData
*line1
= *((wxListLineData
**)arg1
);
2166 wxListLineData
*line2
= *((wxListLineData
**)arg2
);
2168 line1
->GetItem( 0, item
);
2169 long data1
= item
.m_data
;
2170 line2
->GetItem( 0, item
);
2171 long data2
= item
.m_data
;
2172 return list_ctrl_compare_func_2( data1
, data2
, list_ctrl_compare_data
);
2175 void wxListMainWindow::SortItems( wxListCtrlCompare fn
, long data
)
2177 list_ctrl_compare_func_2
= fn
;
2178 list_ctrl_compare_data
= data
;
2179 m_lines
.Sort( list_ctrl_compare_func_1
);
2182 bool wxListMainWindow::OnListNotify( wxListEvent
&event
)
2184 if (GetParent()) GetParent()->GetEventHandler()->ProcessEvent( event
);
2188 // -------------------------------------------------------------------------------------
2190 // -------------------------------------------------------------------------------------
2192 IMPLEMENT_DYNAMIC_CLASS(wxListItem
, wxObject
)
2194 wxListItem::wxListItem(void)
2203 m_format
= wxLIST_FORMAT_CENTRE
;
2208 // -------------------------------------------------------------------------------------
2210 // -------------------------------------------------------------------------------------
2212 IMPLEMENT_DYNAMIC_CLASS(wxListEvent
, wxCommandEvent
)
2214 wxListEvent::wxListEvent( wxEventType commandType
, int id
):
2215 wxCommandEvent( commandType
, id
)
2220 m_cancelled
= FALSE
;
2223 // -------------------------------------------------------------------------------------
2225 // -------------------------------------------------------------------------------------
2227 IMPLEMENT_DYNAMIC_CLASS(wxListCtrl
, wxControl
)
2229 BEGIN_EVENT_TABLE(wxListCtrl
,wxControl
)
2230 EVT_SIZE (wxListCtrl::OnSize
)
2231 EVT_IDLE (wxListCtrl::OnIdle
)
2234 wxListCtrl::wxListCtrl(void)
2236 m_imageListNormal
= (wxImageList
*) NULL
;
2237 m_imageListSmall
= (wxImageList
*) NULL
;
2238 m_imageListState
= (wxImageList
*) NULL
;
2239 m_mainWin
= (wxListMainWindow
*) NULL
;
2240 m_headerWin
= (wxListHeaderWindow
*) NULL
;
2243 wxListCtrl::~wxListCtrl(void)
2247 bool wxListCtrl::Create( wxWindow
*parent
, wxWindowID id
,
2248 const wxPoint
&pos
, const wxSize
&size
,
2249 long style
, const wxValidator
&validator
,
2250 const wxString
&name
)
2252 m_imageListNormal
= (wxImageList
*) NULL
;
2253 m_imageListSmall
= (wxImageList
*) NULL
;
2254 m_imageListState
= (wxImageList
*) NULL
;
2255 m_mainWin
= (wxListMainWindow
*) NULL
;
2256 m_headerWin
= (wxListHeaderWindow
*) NULL
;
2260 if ((s
& wxLC_REPORT
== 0) &&
2261 (s
& wxLC_LIST
== 0) &&
2262 (s
& wxLC_ICON
== 0))
2265 bool ret
= wxControl::Create( parent
, id
, pos
, size
, s
, name
);
2267 SetValidator( validator
);
2269 if (s
& wxSUNKEN_BORDER
) s
-= wxSUNKEN_BORDER
;
2271 m_mainWin
= new wxListMainWindow( this, -1, wxPoint(0,0), size
, s
);
2273 if (GetWindowStyleFlag() & wxLC_REPORT
)
2274 m_headerWin
= new wxListHeaderWindow( this, -1, m_mainWin
, wxPoint(0,0), wxSize(size
.x
,23) );
2276 m_headerWin
= (wxListHeaderWindow
*) NULL
;
2281 void wxListCtrl::OnSize( wxSizeEvent
&WXUNUSED(event
) )
2283 // handled in OnIdle
2285 if (m_mainWin
) m_mainWin
->m_dirty
= TRUE
;
2288 void wxListCtrl::SetSingleStyle( long style
, bool add
)
2290 long flag
= GetWindowStyleFlag();
2294 if (style
& wxLC_MASK_TYPE
) flag
= flag
& ~wxLC_MASK_TYPE
;
2295 if (style
& wxLC_MASK_ALIGN
) flag
= flag
& ~wxLC_MASK_ALIGN
;
2296 if (style
& wxLC_MASK_SORT
) flag
= flag
& ~wxLC_MASK_SORT
;
2305 if (flag
& style
) flag
-= style
;
2308 SetWindowStyleFlag( flag
);
2311 void wxListCtrl::SetWindowStyleFlag( long flag
)
2313 m_mainWin
->DeleteEverything();
2317 GetClientSize( &width
, &height
);
2319 m_mainWin
->SetMode( flag
);
2321 if (flag
& wxLC_REPORT
)
2323 if (!(GetWindowStyleFlag() & wxLC_REPORT
))
2325 // m_mainWin->SetSize( 0, 24, width, height-24 );
2328 m_headerWin
= new wxListHeaderWindow( this, -1, m_mainWin
, wxPoint(0,0), wxSize(width
,23) );
2332 // m_headerWin->SetSize( 0, 0, width, 23 );
2333 m_headerWin
->Show( TRUE
);
2339 if (GetWindowStyleFlag() & wxLC_REPORT
)
2341 // m_mainWin->SetSize( 0, 0, width, height );
2342 m_headerWin
->Show( FALSE
);
2346 wxWindow::SetWindowStyleFlag( flag
);
2349 bool wxListCtrl::GetColumn(int col
, wxListItem
&item
)
2351 m_mainWin
->GetColumn( col
, item
);
2355 bool wxListCtrl::SetColumn( int col
, wxListItem
& item
)
2357 m_mainWin
->SetColumn( col
, item
);
2361 int wxListCtrl::GetColumnWidth( int col
)
2363 return m_mainWin
->GetColumnWidth( col
);
2366 bool wxListCtrl::SetColumnWidth( int col
, int width
)
2368 m_mainWin
->SetColumnWidth( col
, width
);
2372 int wxListCtrl::GetCountPerPage(void)
2374 return m_mainWin
->GetCountPerPage(); // different from Windows ?
2378 wxText& wxListCtrl::GetEditControl(void) const
2383 bool wxListCtrl::GetItem( wxListItem
&info
)
2385 m_mainWin
->GetItem( info
);
2389 bool wxListCtrl::SetItem( wxListItem
&info
)
2391 m_mainWin
->SetItem( info
);
2395 long wxListCtrl::SetItem( long index
, int col
, const wxString
& label
, int imageId
)
2398 info
.m_text
= label
;
2399 info
.m_mask
= wxLIST_MASK_TEXT
;
2400 info
.m_itemId
= index
;
2404 info
.m_image
= imageId
;
2405 info
.m_mask
|= wxLIST_MASK_IMAGE
;
2408 m_mainWin
->SetItem(info
);
2412 int wxListCtrl::GetItemState( long item
, long stateMask
)
2414 return m_mainWin
->GetItemState( item
, stateMask
);
2417 bool wxListCtrl::SetItemState( long item
, long state
, long stateMask
)
2419 m_mainWin
->SetItemState( item
, state
, stateMask
);
2423 bool wxListCtrl::SetItemImage( long item
, int image
, int WXUNUSED(selImage
) )
2426 info
.m_image
= image
;
2427 info
.m_mask
= wxLIST_MASK_IMAGE
;
2428 info
.m_itemId
= item
;
2429 m_mainWin
->SetItem( info
);
2433 wxString
wxListCtrl::GetItemText( long item
)
2436 info
.m_itemId
= item
;
2437 m_mainWin
->GetItem( info
);
2441 void wxListCtrl::SetItemText( long item
, const wxString
&str
)
2444 info
.m_mask
= wxLIST_MASK_TEXT
;
2445 info
.m_itemId
= item
;
2447 m_mainWin
->SetItem( info
);
2450 long wxListCtrl::GetItemData( long item
)
2453 info
.m_itemId
= item
;
2454 m_mainWin
->GetItem( info
);
2458 bool wxListCtrl::SetItemData( long item
, long data
)
2461 info
.m_mask
= wxLIST_MASK_DATA
;
2462 info
.m_itemId
= item
;
2464 m_mainWin
->SetItem( info
);
2468 bool wxListCtrl::GetItemRect( long item
, wxRectangle
&rect
, int WXUNUSED(code
) )
2470 m_mainWin
->GetItemRect( item
, rect
);
2474 bool wxListCtrl::GetItemPosition( long item
, wxPoint
& pos
)
2476 m_mainWin
->GetItemPosition( item
, pos
);
2480 bool wxListCtrl::SetItemPosition( long WXUNUSED(item
), const wxPoint
& WXUNUSED(pos
) )
2485 int wxListCtrl::GetItemCount(void)
2487 return m_mainWin
->GetItemCount();
2490 void wxListCtrl::SetItemSpacing( int spacing
, bool isSmall
)
2492 m_mainWin
->SetItemSpacing( spacing
, isSmall
);
2495 int wxListCtrl::GetItemSpacing( bool isSmall
)
2497 return m_mainWin
->GetItemSpacing( isSmall
);
2500 int wxListCtrl::GetSelectedItemCount(void)
2502 return m_mainWin
->GetSelectedItemCount();
2506 wxColour wxListCtrl::GetTextColour(void) const
2510 void wxListCtrl::SetTextColour(const wxColour& WXUNUSED(col))
2515 long wxListCtrl::GetTopItem(void)
2520 long wxListCtrl::GetNextItem( long item
, int geom
, int state
) const
2522 return m_mainWin
->GetNextItem( item
, geom
, state
);
2525 wxImageList
*wxListCtrl::GetImageList(int which
)
2527 if (which
== wxIMAGE_LIST_NORMAL
)
2529 return m_imageListNormal
;
2531 else if (which
== wxIMAGE_LIST_SMALL
)
2533 return m_imageListSmall
;
2535 else if (which
== wxIMAGE_LIST_STATE
)
2537 return m_imageListState
;
2539 return (wxImageList
*) NULL
;
2542 void wxListCtrl::SetImageList( wxImageList
*imageList
, int which
)
2544 m_mainWin
->SetImageList( imageList
, which
);
2547 bool wxListCtrl::Arrange( int WXUNUSED(flag
) )
2552 bool wxListCtrl::DeleteItem( long item
)
2554 m_mainWin
->DeleteItem( item
);
2558 bool wxListCtrl::DeleteAllItems(void)
2560 m_mainWin
->DeleteAllItems();
2564 void wxListCtrl::DeleteAllColumns()
2566 for ( size_t n
= 0; n
< m_mainWin
->m_columns
.GetCount(); n
++ )
2570 bool wxListCtrl::DeleteColumn( int col
)
2572 m_mainWin
->DeleteColumn( col
);
2577 wxText& wxListCtrl::Edit( long WXUNUSED(item ) )
2582 bool wxListCtrl::EnsureVisible( long item
)
2584 m_mainWin
->EnsureVisible( item
);
2588 long wxListCtrl::FindItem( long start
, const wxString
& str
, bool partial
)
2590 return m_mainWin
->FindItem( start
, str
, partial
);
2593 long wxListCtrl::FindItem( long start
, long data
)
2595 return m_mainWin
->FindItem( start
, data
);
2598 long wxListCtrl::FindItem( long WXUNUSED(start
), const wxPoint
& WXUNUSED(pt
),
2599 int WXUNUSED(direction
))
2604 long wxListCtrl::HitTest( const wxPoint
&point
, int &flags
)
2606 return m_mainWin
->HitTest( (int)point
.x
, (int)point
.y
, flags
);
2609 long wxListCtrl::InsertItem( wxListItem
& info
)
2611 m_mainWin
->InsertItem( info
);
2615 long wxListCtrl::InsertItem( long index
, const wxString
&label
)
2618 info
.m_text
= label
;
2619 info
.m_mask
= wxLIST_MASK_TEXT
;
2620 info
.m_itemId
= index
;
2621 return InsertItem( info
);
2624 long wxListCtrl::InsertItem( long index
, int imageIndex
)
2627 info
.m_mask
= wxLIST_MASK_IMAGE
;
2628 info
.m_image
= imageIndex
;
2629 info
.m_itemId
= index
;
2630 return InsertItem( info
);
2633 long wxListCtrl::InsertItem( long index
, const wxString
&label
, int imageIndex
)
2636 info
.m_text
= label
;
2637 info
.m_image
= imageIndex
;
2638 info
.m_mask
= wxLIST_MASK_TEXT
| wxLIST_MASK_IMAGE
;
2639 info
.m_itemId
= index
;
2640 return InsertItem( info
);
2643 long wxListCtrl::InsertColumn( long col
, wxListItem
&item
)
2645 m_mainWin
->InsertColumn( col
, item
);
2649 long wxListCtrl::InsertColumn( long col
, const wxString
&heading
,
2650 int format
, int width
)
2653 item
.m_mask
= wxLIST_MASK_TEXT
| wxLIST_MASK_FORMAT
;
2654 item
.m_text
= heading
;
2657 item
.m_mask
|= wxLIST_MASK_WIDTH
;
2658 item
.m_width
= width
;
2661 item
.m_format
= format
;
2663 return InsertColumn( col
, item
);
2666 bool wxListCtrl::ScrollList( int WXUNUSED(dx
), int WXUNUSED(dy
) )
2672 // fn is a function which takes 3 long arguments: item1, item2, data.
2673 // item1 is the long data associated with a first item (NOT the index).
2674 // item2 is the long data associated with a second item (NOT the index).
2675 // data is the same value as passed to SortItems.
2676 // The return value is a negative number if the first item should precede the second
2677 // item, a positive number of the second item should precede the first,
2678 // or zero if the two items are equivalent.
2679 // data is arbitrary data to be passed to the sort function.
2681 bool wxListCtrl::SortItems( wxListCtrlCompare fn
, long data
)
2683 m_mainWin
->SortItems( fn
, data
);
2687 void wxListCtrl::OnIdle( wxIdleEvent
&WXUNUSED(event
) )
2689 if (!m_mainWin
->m_dirty
) return;
2693 GetClientSize( &cw
, &ch
);
2700 if (GetWindowStyleFlag() & wxLC_REPORT
)
2702 m_headerWin
->GetPosition( &x
, &y
);
2703 m_headerWin
->GetSize( &w
, &h
);
2704 if ((x
!= 0) || (y
!= 0) || (w
!= cw
) || (h
!= 23))
2705 m_headerWin
->SetSize( 0, 0, cw
, 23 );
2707 m_mainWin
->GetPosition( &x
, &y
);
2708 m_mainWin
->GetSize( &w
, &h
);
2709 if ((x
!= 0) || (y
!= 24) || (w
!= cw
) || (h
!= ch
-24))
2710 m_mainWin
->SetSize( 0, 24, cw
, ch
-24 );
2714 m_mainWin
->GetPosition( &x
, &y
);
2715 m_mainWin
->GetSize( &w
, &h
);
2716 if ((x
!= 0) || (y
!= 24) || (w
!= cw
) || (h
!= ch
))
2717 m_mainWin
->SetSize( 0, 0, cw
, ch
);
2720 m_mainWin
->CalculatePositions();
2721 m_mainWin
->RealizeChanges();
2722 m_mainWin
->m_dirty
= FALSE
;
2723 m_mainWin
->Refresh();
2726 void wxListCtrl::SetBackgroundColour( const wxColour
&colour
)
2730 m_mainWin
->SetBackgroundColour( colour
);
2731 m_mainWin
->m_dirty
= TRUE
;
2734 m_headerWin
->SetBackgroundColour( colour
);
2737 void wxListCtrl::SetForegroundColour( const wxColour
&colour
)
2741 m_mainWin
->SetForegroundColour( colour
);
2742 m_mainWin
->m_dirty
= TRUE
;
2745 m_headerWin
->SetForegroundColour( colour
);
2748 void wxListCtrl::SetFont( const wxFont
&font
)
2752 m_mainWin
->SetFont( font
);
2753 m_mainWin
->m_dirty
= TRUE
;
2756 m_headerWin
->SetFont( font
);